mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-16 09:04:26 +00:00
feat(coding-agent): add extension compaction helpers
This commit is contained in:
parent
673916f63c
commit
9d3f8117a4
11 changed files with 190 additions and 4 deletions
|
|
@ -28,10 +28,13 @@ export type {
|
|||
BashToolResultEvent,
|
||||
BeforeAgentStartEvent,
|
||||
BeforeAgentStartEventResult,
|
||||
// Context
|
||||
CompactOptions,
|
||||
// Events - Agent
|
||||
ContextEvent,
|
||||
// Event Results
|
||||
ContextEventResult,
|
||||
ContextUsage,
|
||||
CustomToolResultEvent,
|
||||
EditToolResultEvent,
|
||||
ExecOptions,
|
||||
|
|
@ -42,7 +45,6 @@ export type {
|
|||
ExtensionAPI,
|
||||
ExtensionCommandContext,
|
||||
ExtensionCommandContextActions,
|
||||
// Context
|
||||
ExtensionContext,
|
||||
ExtensionContextActions,
|
||||
// Errors
|
||||
|
|
|
|||
|
|
@ -11,8 +11,10 @@ import type { SessionManager } from "../session-manager.js";
|
|||
import type {
|
||||
BeforeAgentStartEvent,
|
||||
BeforeAgentStartEventResult,
|
||||
CompactOptions,
|
||||
ContextEvent,
|
||||
ContextEventResult,
|
||||
ContextUsage,
|
||||
Extension,
|
||||
ExtensionActions,
|
||||
ExtensionCommandContext,
|
||||
|
|
@ -113,6 +115,8 @@ export class ExtensionRunner {
|
|||
private waitForIdleFn: () => Promise<void> = async () => {};
|
||||
private abortFn: () => void = () => {};
|
||||
private hasPendingMessagesFn: () => boolean = () => false;
|
||||
private getContextUsageFn: () => ContextUsage | undefined = () => undefined;
|
||||
private compactFn: (options?: CompactOptions) => void = () => {};
|
||||
private newSessionHandler: NewSessionHandler = async () => ({ cancelled: false });
|
||||
private forkHandler: ForkHandler = async () => ({ cancelled: false });
|
||||
private navigateTreeHandler: NavigateTreeHandler = async () => ({ cancelled: false });
|
||||
|
|
@ -158,6 +162,8 @@ export class ExtensionRunner {
|
|||
this.abortFn = contextActions.abort;
|
||||
this.hasPendingMessagesFn = contextActions.hasPendingMessages;
|
||||
this.shutdownHandler = contextActions.shutdown;
|
||||
this.getContextUsageFn = contextActions.getContextUsage;
|
||||
this.compactFn = contextActions.compact;
|
||||
|
||||
// Command context actions (optional, only for interactive mode)
|
||||
if (commandContextActions) {
|
||||
|
|
@ -337,6 +343,8 @@ export class ExtensionRunner {
|
|||
abort: () => this.abortFn(),
|
||||
hasPendingMessages: () => this.hasPendingMessagesFn(),
|
||||
shutdown: () => this.shutdownHandler(),
|
||||
getContextUsage: () => this.getContextUsageFn(),
|
||||
compact: (options) => this.compactFn(options),
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -193,6 +193,21 @@ export interface ExtensionUIContext {
|
|||
// Extension Context
|
||||
// ============================================================================
|
||||
|
||||
export interface ContextUsage {
|
||||
tokens: number;
|
||||
contextWindow: number;
|
||||
percent: number;
|
||||
usageTokens: number;
|
||||
trailingTokens: number;
|
||||
lastUsageIndex: number | null;
|
||||
}
|
||||
|
||||
export interface CompactOptions {
|
||||
customInstructions?: string;
|
||||
onComplete?: (result: CompactionResult) => void;
|
||||
onError?: (error: Error) => void;
|
||||
}
|
||||
|
||||
/**
|
||||
* Context passed to extension event handlers.
|
||||
*/
|
||||
|
|
@ -217,6 +232,10 @@ export interface ExtensionContext {
|
|||
hasPendingMessages(): boolean;
|
||||
/** Gracefully shutdown pi and exit. Available in all contexts. */
|
||||
shutdown(): void;
|
||||
/** Get current context usage for the active model. */
|
||||
getContextUsage(): ContextUsage | undefined;
|
||||
/** Trigger compaction without awaiting completion. */
|
||||
compact(options?: CompactOptions): void;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -919,6 +938,8 @@ export interface ExtensionContextActions {
|
|||
abort: () => void;
|
||||
hasPendingMessages: () => boolean;
|
||||
shutdown: () => void;
|
||||
getContextUsage: () => ContextUsage | undefined;
|
||||
compact: (options?: CompactOptions) => void;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue