mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-20 19:02:10 +00:00
docs(coding-agent): document ctx.compact and ctx.getContextUsage
This commit is contained in:
parent
05ee8e3334
commit
57fe00ced4
1 changed files with 28 additions and 1 deletions
|
|
@ -384,7 +384,7 @@ pi.on("session_compact", async (event, ctx) => {
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
**Examples:** [custom-compaction.ts](../examples/extensions/custom-compaction.ts)
|
**Examples:** [custom-compaction.ts](../examples/extensions/custom-compaction.ts), [trigger-compact.ts](../examples/extensions/trigger-compact.ts)
|
||||||
|
|
||||||
#### session_before_tree / session_tree
|
#### session_before_tree / session_tree
|
||||||
|
|
||||||
|
|
@ -677,6 +677,33 @@ pi.on("tool_call", (event, ctx) => {
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### ctx.getContextUsage()
|
||||||
|
|
||||||
|
Returns current context usage for the active model. Uses last assistant usage when available, then estimates tokens for trailing messages.
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
const usage = ctx.getContextUsage();
|
||||||
|
if (usage && usage.tokens > 100_000) {
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### ctx.compact()
|
||||||
|
|
||||||
|
Trigger compaction without awaiting completion. Use `onComplete` and `onError` for follow-up actions.
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
ctx.compact({
|
||||||
|
customInstructions: "Focus on recent changes",
|
||||||
|
onComplete: (result) => {
|
||||||
|
ctx.ui.notify("Compaction completed", "info");
|
||||||
|
},
|
||||||
|
onError: (error) => {
|
||||||
|
ctx.ui.notify(`Compaction failed: ${error.message}`, "error");
|
||||||
|
},
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
## ExtensionCommandContext
|
## 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.
|
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.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue