feat(coding-agent): make ctx.shutdown() available for extensions (#542)

This commit is contained in:
Kao Félix 2026-01-08 03:30:48 +01:00 committed by GitHub
parent 7f3fa417c4
commit 6845c4b85e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 164 additions and 2 deletions

View file

@ -556,6 +556,24 @@ Access to models and API keys.
Control flow helpers.
### ctx.shutdown()
Request a graceful shutdown of pi.
- **Interactive mode:** Deferred until the agent becomes idle (after processing all queued steering and follow-up messages).
- **RPC mode:** Deferred until the next idle state (after completing the current command response, when waiting for the next command).
- **Print mode:** No-op. The process exits automatically when all prompts are processed.
Emits `session_shutdown` event to all extensions before exiting. Available in all contexts (event handlers, tools, commands, shortcuts).
```typescript
pi.on("tool_call", (event, ctx) => {
if (isFatal(event.input)) {
ctx.shutdown();
}
});
```
## ExtensionCommandContext
Command handlers receive `ExtensionCommandContext`, which extends `ExtensionContext` with session control methods. These are only available in commands because they can deadlock if called from event handlers.