gsd-pi 2.34.0-dev.ed0bfbf → 2.35.0-dev.55dcc60
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/resources/extensions/gsd/changelog.js +162 -0
- package/dist/resources/extensions/gsd/commands-bootstrap.js +1 -0
- package/dist/resources/extensions/gsd/commands-inspect.js +10 -3
- package/dist/resources/extensions/gsd/commands-prefs-wizard.js +5 -1
- package/dist/resources/extensions/gsd/commands.js +8 -1
- package/dist/resources/extensions/gsd/docs/preferences-reference.md +10 -0
- package/dist/resources/extensions/gsd/doctor-checks.js +113 -5
- package/dist/resources/extensions/gsd/doctor-proactive.js +22 -0
- package/dist/resources/extensions/gsd/doctor.js +36 -0
- package/dist/resources/extensions/gsd/guided-flow.js +4 -2
- package/dist/resources/extensions/gsd/preferences-validation.js +38 -0
- package/dist/resources/extensions/gsd/preferences.js +2 -0
- package/dist/resources/skills/create-gsd-extension/references/events-reference.md +4 -4
- package/package.json +1 -1
- package/packages/pi-agent-core/dist/agent-loop.d.ts +14 -0
- package/packages/pi-agent-core/dist/agent-loop.d.ts.map +1 -1
- package/packages/pi-agent-core/dist/agent-loop.js +24 -27
- package/packages/pi-agent-core/dist/agent-loop.js.map +1 -1
- package/packages/pi-agent-core/dist/agent.d.ts +1 -0
- package/packages/pi-agent-core/dist/agent.d.ts.map +1 -1
- package/packages/pi-agent-core/dist/agent.js +11 -22
- package/packages/pi-agent-core/dist/agent.js.map +1 -1
- package/packages/pi-agent-core/dist/proxy.d.ts.map +1 -1
- package/packages/pi-agent-core/dist/proxy.js +2 -8
- package/packages/pi-agent-core/dist/proxy.js.map +1 -1
- package/packages/pi-agent-core/src/agent-loop.ts +30 -27
- package/packages/pi-agent-core/src/agent.ts +12 -23
- package/packages/pi-agent-core/src/proxy.ts +2 -8
- package/packages/pi-ai/dist/providers/azure-openai-responses.d.ts.map +1 -1
- package/packages/pi-ai/dist/providers/azure-openai-responses.js +5 -41
- package/packages/pi-ai/dist/providers/azure-openai-responses.js.map +1 -1
- package/packages/pi-ai/dist/providers/openai-completions.d.ts.map +1 -1
- package/packages/pi-ai/dist/providers/openai-completions.js +10 -73
- package/packages/pi-ai/dist/providers/openai-completions.js.map +1 -1
- package/packages/pi-ai/dist/providers/openai-responses.d.ts.map +1 -1
- package/packages/pi-ai/dist/providers/openai-responses.js +8 -79
- package/packages/pi-ai/dist/providers/openai-responses.js.map +1 -1
- package/packages/pi-ai/dist/providers/openai-shared.d.ts +65 -0
- package/packages/pi-ai/dist/providers/openai-shared.d.ts.map +1 -0
- package/packages/pi-ai/dist/providers/openai-shared.js +146 -0
- package/packages/pi-ai/dist/providers/openai-shared.js.map +1 -0
- package/packages/pi-ai/dist/utils/oauth/google-antigravity.d.ts.map +1 -1
- package/packages/pi-ai/dist/utils/oauth/google-antigravity.js +7 -135
- package/packages/pi-ai/dist/utils/oauth/google-antigravity.js.map +1 -1
- package/packages/pi-ai/dist/utils/oauth/google-gemini-cli.d.ts.map +1 -1
- package/packages/pi-ai/dist/utils/oauth/google-gemini-cli.js +7 -135
- package/packages/pi-ai/dist/utils/oauth/google-gemini-cli.js.map +1 -1
- package/packages/pi-ai/dist/utils/oauth/google-oauth-utils.d.ts +46 -0
- package/packages/pi-ai/dist/utils/oauth/google-oauth-utils.d.ts.map +1 -0
- package/packages/pi-ai/dist/utils/oauth/google-oauth-utils.js +160 -0
- package/packages/pi-ai/dist/utils/oauth/google-oauth-utils.js.map +1 -0
- package/packages/pi-ai/src/providers/azure-openai-responses.ts +11 -45
- package/packages/pi-ai/src/providers/openai-completions.ts +16 -86
- package/packages/pi-ai/src/providers/openai-responses.ts +15 -95
- package/packages/pi-ai/src/providers/openai-shared.ts +193 -0
- package/packages/pi-ai/src/utils/oauth/google-antigravity.ts +14 -162
- package/packages/pi-ai/src/utils/oauth/google-gemini-cli.ts +13 -161
- package/packages/pi-ai/src/utils/oauth/google-oauth-utils.ts +201 -0
- package/packages/pi-coding-agent/dist/core/agent-session.d.ts +16 -63
- package/packages/pi-coding-agent/dist/core/agent-session.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/agent-session.js +104 -641
- package/packages/pi-coding-agent/dist/core/agent-session.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/auth-storage.d.ts +0 -1
- package/packages/pi-coding-agent/dist/core/auth-storage.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/auth-storage.js +4 -35
- package/packages/pi-coding-agent/dist/core/auth-storage.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/compaction/branch-summarization.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/compaction/branch-summarization.js +5 -43
- package/packages/pi-coding-agent/dist/core/compaction/branch-summarization.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/compaction/compaction.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/compaction/compaction.js +11 -69
- package/packages/pi-coding-agent/dist/core/compaction/compaction.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/compaction/utils.d.ts +40 -0
- package/packages/pi-coding-agent/dist/core/compaction/utils.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/compaction/utils.js +78 -0
- package/packages/pi-coding-agent/dist/core/compaction/utils.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/compaction-orchestrator.d.ts +77 -0
- package/packages/pi-coding-agent/dist/core/compaction-orchestrator.d.ts.map +1 -0
- package/packages/pi-coding-agent/dist/core/compaction-orchestrator.js +331 -0
- package/packages/pi-coding-agent/dist/core/compaction-orchestrator.js.map +1 -0
- package/packages/pi-coding-agent/dist/core/extensions/index.d.ts +2 -2
- package/packages/pi-coding-agent/dist/core/extensions/index.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/extensions/index.js +1 -1
- package/packages/pi-coding-agent/dist/core/extensions/index.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/extensions/runner.d.ts +15 -0
- package/packages/pi-coding-agent/dist/core/extensions/runner.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/extensions/runner.js +129 -243
- package/packages/pi-coding-agent/dist/core/extensions/runner.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/extensions/types.d.ts +49 -42
- package/packages/pi-coding-agent/dist/core/extensions/types.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/extensions/types.js +2 -21
- package/packages/pi-coding-agent/dist/core/extensions/types.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/lock-utils.d.ts +39 -0
- package/packages/pi-coding-agent/dist/core/lock-utils.d.ts.map +1 -0
- package/packages/pi-coding-agent/dist/core/lock-utils.js +89 -0
- package/packages/pi-coding-agent/dist/core/lock-utils.js.map +1 -0
- package/packages/pi-coding-agent/dist/core/lsp/config.d.ts +2 -0
- package/packages/pi-coding-agent/dist/core/lsp/config.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/lsp/config.js +4 -1
- package/packages/pi-coding-agent/dist/core/lsp/config.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/lsp/index.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/lsp/index.js +52 -107
- package/packages/pi-coding-agent/dist/core/lsp/index.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/lsp/lspmux.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/lsp/lspmux.js +2 -21
- package/packages/pi-coding-agent/dist/core/lsp/lspmux.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/lsp/types.d.ts +0 -1
- package/packages/pi-coding-agent/dist/core/lsp/types.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/lsp/types.js +0 -28
- package/packages/pi-coding-agent/dist/core/lsp/types.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/package-manager.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/package-manager.js +2 -4
- package/packages/pi-coding-agent/dist/core/package-manager.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/resource-loader.d.ts +2 -4
- package/packages/pi-coding-agent/dist/core/resource-loader.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/resource-loader.js +33 -58
- package/packages/pi-coding-agent/dist/core/resource-loader.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/retry-handler.d.ts +87 -0
- package/packages/pi-coding-agent/dist/core/retry-handler.d.ts.map +1 -0
- package/packages/pi-coding-agent/dist/core/retry-handler.js +295 -0
- package/packages/pi-coding-agent/dist/core/retry-handler.js.map +1 -0
- package/packages/pi-coding-agent/dist/core/session-manager.d.ts +0 -1
- package/packages/pi-coding-agent/dist/core/session-manager.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/session-manager.js +3 -28
- package/packages/pi-coding-agent/dist/core/session-manager.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/settings-manager.d.ts +8 -0
- package/packages/pi-coding-agent/dist/core/settings-manager.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/settings-manager.js +76 -166
- package/packages/pi-coding-agent/dist/core/settings-manager.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/skills.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/skills.js +1 -3
- package/packages/pi-coding-agent/dist/core/skills.js.map +1 -1
- package/packages/pi-coding-agent/dist/index.d.ts +1 -1
- package/packages/pi-coding-agent/dist/index.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/index.js +1 -1
- package/packages/pi-coding-agent/dist/index.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/session-selector.d.ts +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/session-selector.js +9 -26
- package/packages/pi-coding-agent/dist/modes/interactive/components/session-selector.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/tool-execution.js +1 -13
- package/packages/pi-coding-agent/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/tree-render-utils.d.ts +44 -0
- package/packages/pi-coding-agent/dist/modes/interactive/components/tree-render-utils.d.ts.map +1 -0
- package/packages/pi-coding-agent/dist/modes/interactive/components/tree-render-utils.js +61 -0
- package/packages/pi-coding-agent/dist/modes/interactive/components/tree-render-utils.js.map +1 -0
- package/packages/pi-coding-agent/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/tree-selector.js +6 -9
- package/packages/pi-coding-agent/dist/modes/interactive/components/tree-selector.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/theme/theme.d.ts +65 -0
- package/packages/pi-coding-agent/dist/modes/interactive/theme/theme.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/theme/theme.js +6 -16
- package/packages/pi-coding-agent/dist/modes/interactive/theme/theme.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/theme/themes.d.ts +12 -0
- package/packages/pi-coding-agent/dist/modes/interactive/theme/themes.d.ts.map +1 -0
- package/packages/pi-coding-agent/dist/modes/interactive/theme/themes.js +175 -0
- package/packages/pi-coding-agent/dist/modes/interactive/theme/themes.js.map +1 -0
- package/packages/pi-coding-agent/dist/modes/interactive/utils/shorten-path.d.ts +6 -0
- package/packages/pi-coding-agent/dist/modes/interactive/utils/shorten-path.d.ts.map +1 -0
- package/packages/pi-coding-agent/dist/modes/interactive/utils/shorten-path.js +15 -0
- package/packages/pi-coding-agent/dist/modes/interactive/utils/shorten-path.js.map +1 -0
- package/packages/pi-coding-agent/dist/modes/print-mode.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/modes/print-mode.js +2 -30
- package/packages/pi-coding-agent/dist/modes/print-mode.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/modes/rpc/rpc-mode.js +2 -28
- package/packages/pi-coding-agent/dist/modes/rpc/rpc-mode.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/shared/command-context-actions.d.ts +19 -0
- package/packages/pi-coding-agent/dist/modes/shared/command-context-actions.d.ts.map +1 -0
- package/packages/pi-coding-agent/dist/modes/shared/command-context-actions.js +45 -0
- package/packages/pi-coding-agent/dist/modes/shared/command-context-actions.js.map +1 -0
- package/packages/pi-coding-agent/dist/utils/error.d.ts +5 -0
- package/packages/pi-coding-agent/dist/utils/error.d.ts.map +1 -0
- package/packages/pi-coding-agent/dist/utils/error.js +7 -0
- package/packages/pi-coding-agent/dist/utils/error.js.map +1 -0
- package/packages/pi-coding-agent/package.json +1 -1
- package/packages/pi-coding-agent/src/core/agent-session.ts +117 -745
- package/packages/pi-coding-agent/src/core/auth-storage.ts +4 -38
- package/packages/pi-coding-agent/src/core/compaction/branch-summarization.ts +7 -53
- package/packages/pi-coding-agent/src/core/compaction/compaction.ts +14 -74
- package/packages/pi-coding-agent/src/core/compaction/utils.ts +100 -0
- package/packages/pi-coding-agent/src/core/compaction-orchestrator.ts +424 -0
- package/packages/pi-coding-agent/src/core/extensions/index.ts +1 -21
- package/packages/pi-coding-agent/src/core/extensions/runner.ts +119 -243
- package/packages/pi-coding-agent/src/core/extensions/types.ts +50 -69
- package/packages/pi-coding-agent/src/core/lock-utils.ts +113 -0
- package/packages/pi-coding-agent/src/core/lsp/config.ts +4 -1
- package/packages/pi-coding-agent/src/core/lsp/index.ts +83 -152
- package/packages/pi-coding-agent/src/core/lsp/lspmux.ts +2 -22
- package/packages/pi-coding-agent/src/core/lsp/types.ts +0 -29
- package/packages/pi-coding-agent/src/core/package-manager.ts +1 -4
- package/packages/pi-coding-agent/src/core/resource-loader.ts +43 -67
- package/packages/pi-coding-agent/src/core/retry-handler.ts +359 -0
- package/packages/pi-coding-agent/src/core/session-manager.ts +3 -30
- package/packages/pi-coding-agent/src/core/settings-manager.ts +85 -164
- package/packages/pi-coding-agent/src/core/skills.ts +1 -4
- package/packages/pi-coding-agent/src/index.ts +1 -7
- package/packages/pi-coding-agent/src/modes/interactive/components/session-selector.ts +17 -29
- package/packages/pi-coding-agent/src/modes/interactive/components/tool-execution.ts +1 -13
- package/packages/pi-coding-agent/src/modes/interactive/components/tree-render-utils.ts +81 -0
- package/packages/pi-coding-agent/src/modes/interactive/components/tree-selector.ts +14 -19
- package/packages/pi-coding-agent/src/modes/interactive/theme/theme.ts +7 -18
- package/packages/pi-coding-agent/src/modes/interactive/theme/themes.ts +196 -0
- package/packages/pi-coding-agent/src/modes/interactive/utils/shorten-path.ts +14 -0
- package/packages/pi-coding-agent/src/modes/print-mode.ts +2 -30
- package/packages/pi-coding-agent/src/modes/rpc/rpc-mode.ts +2 -28
- package/packages/pi-coding-agent/src/modes/shared/command-context-actions.ts +53 -0
- package/packages/pi-coding-agent/src/utils/error.ts +6 -0
- package/packages/pi-tui/dist/components/markdown.d.ts +5 -0
- package/packages/pi-tui/dist/components/markdown.d.ts.map +1 -1
- package/packages/pi-tui/dist/components/markdown.js +25 -31
- package/packages/pi-tui/dist/components/markdown.js.map +1 -1
- package/packages/pi-tui/dist/keys.d.ts +0 -4
- package/packages/pi-tui/dist/keys.d.ts.map +1 -1
- package/packages/pi-tui/dist/keys.js +94 -162
- package/packages/pi-tui/dist/keys.js.map +1 -1
- package/packages/pi-tui/src/components/markdown.ts +25 -29
- package/packages/pi-tui/src/keys.ts +94 -173
- package/pkg/dist/modes/interactive/theme/theme.d.ts +65 -0
- package/pkg/dist/modes/interactive/theme/theme.d.ts.map +1 -1
- package/pkg/dist/modes/interactive/theme/theme.js +6 -16
- package/pkg/dist/modes/interactive/theme/theme.js.map +1 -1
- package/pkg/dist/modes/interactive/theme/themes.d.ts +12 -0
- package/pkg/dist/modes/interactive/theme/themes.d.ts.map +1 -0
- package/pkg/dist/modes/interactive/theme/themes.js +175 -0
- package/pkg/dist/modes/interactive/theme/themes.js.map +1 -0
- package/pkg/package.json +1 -1
- package/src/resources/extensions/gsd/changelog.ts +213 -0
- package/src/resources/extensions/gsd/commands-bootstrap.ts +1 -0
- package/src/resources/extensions/gsd/commands-inspect.ts +10 -3
- package/src/resources/extensions/gsd/commands-prefs-wizard.ts +5 -1
- package/src/resources/extensions/gsd/commands.ts +9 -1
- package/src/resources/extensions/gsd/docs/preferences-reference.md +10 -0
- package/src/resources/extensions/gsd/doctor-checks.ts +107 -5
- package/src/resources/extensions/gsd/doctor-proactive.ts +24 -0
- package/src/resources/extensions/gsd/doctor-types.ts +9 -1
- package/src/resources/extensions/gsd/doctor.ts +35 -0
- package/src/resources/extensions/gsd/guided-flow.ts +4 -2
- package/src/resources/extensions/gsd/preferences-validation.ts +38 -0
- package/src/resources/extensions/gsd/preferences.ts +2 -0
- package/src/resources/extensions/gsd/tests/commands-inspect-open-db.test.ts +46 -0
- package/src/resources/extensions/gsd/tests/doctor-git.test.ts +98 -2
- package/src/resources/extensions/gsd/tests/doctor-runtime.test.ts +59 -3
- package/src/resources/extensions/gsd/tests/preferences.test.ts +28 -0
- package/src/resources/skills/create-gsd-extension/references/events-reference.md +4 -4
- package/packages/pi-coding-agent/dist/modes/interactive/theme/dark.json +0 -85
- package/packages/pi-coding-agent/dist/modes/interactive/theme/light.json +0 -84
- package/packages/pi-coding-agent/dist/modes/interactive/theme/theme-schema.json +0 -335
- package/packages/pi-coding-agent/src/modes/interactive/theme/dark.json +0 -85
- package/packages/pi-coding-agent/src/modes/interactive/theme/light.json +0 -84
- package/packages/pi-coding-agent/src/modes/interactive/theme/theme-schema.json +0 -335
- package/pkg/dist/modes/interactive/theme/dark.json +0 -85
- package/pkg/dist/modes/interactive/theme/light.json +0 -84
- package/pkg/dist/modes/interactive/theme/theme-schema.json +0 -335
|
@@ -0,0 +1,424 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CompactionOrchestrator - Manages manual and automatic context compaction.
|
|
3
|
+
*
|
|
4
|
+
* Handles:
|
|
5
|
+
* - Manual compaction (user-triggered /compact)
|
|
6
|
+
* - Auto-compaction when context exceeds threshold
|
|
7
|
+
* - Overflow recovery when LLM returns context overflow errors
|
|
8
|
+
* - Extension integration for custom compaction providers
|
|
9
|
+
* - Branch summarization abort coordination
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import type { Agent } from "@gsd/pi-agent-core";
|
|
13
|
+
import type { AssistantMessage, Model } from "@gsd/pi-ai";
|
|
14
|
+
import { isContextOverflow } from "@gsd/pi-ai";
|
|
15
|
+
import {
|
|
16
|
+
type CompactionResult,
|
|
17
|
+
calculateContextTokens,
|
|
18
|
+
compact,
|
|
19
|
+
estimateContextTokens,
|
|
20
|
+
prepareCompaction,
|
|
21
|
+
shouldCompact,
|
|
22
|
+
} from "./compaction/index.js";
|
|
23
|
+
import type { ExtensionRunner, SessionBeforeCompactResult } from "./extensions/index.js";
|
|
24
|
+
import type { ModelRegistry } from "./model-registry.js";
|
|
25
|
+
import { getLatestCompactionEntry } from "./session-manager.js";
|
|
26
|
+
import type { CompactionEntry, SessionManager } from "./session-manager.js";
|
|
27
|
+
import type { SettingsManager } from "./settings-manager.js";
|
|
28
|
+
import type { AgentSessionEvent } from "./agent-session.js";
|
|
29
|
+
import { getErrorMessage } from "../utils/error.js";
|
|
30
|
+
|
|
31
|
+
/** Dependencies injected from AgentSession into CompactionOrchestrator */
|
|
32
|
+
export interface CompactionOrchestratorDeps {
|
|
33
|
+
readonly agent: Agent;
|
|
34
|
+
readonly sessionManager: SessionManager;
|
|
35
|
+
readonly settingsManager: SettingsManager;
|
|
36
|
+
readonly modelRegistry: ModelRegistry;
|
|
37
|
+
getModel: () => Model<any> | undefined;
|
|
38
|
+
getSessionId: () => string;
|
|
39
|
+
getExtensionRunner: () => ExtensionRunner | undefined;
|
|
40
|
+
emit: (event: AgentSessionEvent) => void;
|
|
41
|
+
disconnectFromAgent: () => void;
|
|
42
|
+
reconnectToAgent: () => void;
|
|
43
|
+
abort: () => Promise<void>;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export class CompactionOrchestrator {
|
|
47
|
+
private _compactionAbortController: AbortController | undefined = undefined;
|
|
48
|
+
private _autoCompactionAbortController: AbortController | undefined = undefined;
|
|
49
|
+
private _overflowRecoveryAttempted = false;
|
|
50
|
+
private _branchSummaryAbortController: AbortController | undefined = undefined;
|
|
51
|
+
|
|
52
|
+
constructor(private readonly _deps: CompactionOrchestratorDeps) {}
|
|
53
|
+
|
|
54
|
+
/** Whether compaction or branch summarization is currently running */
|
|
55
|
+
get isCompacting(): boolean {
|
|
56
|
+
return (
|
|
57
|
+
this._autoCompactionAbortController !== undefined ||
|
|
58
|
+
this._compactionAbortController !== undefined ||
|
|
59
|
+
this._branchSummaryAbortController !== undefined
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Reset overflow recovery flag (called when a new user message starts) */
|
|
64
|
+
resetOverflowRecovery(): void {
|
|
65
|
+
this._overflowRecoveryAttempted = false;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Mark overflow recovery as not needed (called on successful assistant response) */
|
|
69
|
+
clearOverflowRecovery(): void {
|
|
70
|
+
this._overflowRecoveryAttempted = false;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Get/set the branch summary abort controller (used by navigateTree) */
|
|
74
|
+
get branchSummaryAbortController(): AbortController | undefined {
|
|
75
|
+
return this._branchSummaryAbortController;
|
|
76
|
+
}
|
|
77
|
+
set branchSummaryAbortController(controller: AbortController | undefined) {
|
|
78
|
+
this._branchSummaryAbortController = controller;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Manually compact the session context.
|
|
83
|
+
* Aborts current agent operation first.
|
|
84
|
+
* @param customInstructions Optional instructions for the compaction summary
|
|
85
|
+
*/
|
|
86
|
+
async compact(customInstructions?: string): Promise<CompactionResult> {
|
|
87
|
+
this._deps.disconnectFromAgent();
|
|
88
|
+
await this._deps.abort();
|
|
89
|
+
this._compactionAbortController = new AbortController();
|
|
90
|
+
|
|
91
|
+
try {
|
|
92
|
+
const model = this._deps.getModel();
|
|
93
|
+
if (!model) {
|
|
94
|
+
throw new Error("No model selected");
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const apiKey = await this._deps.modelRegistry.getApiKey(model, this._deps.getSessionId());
|
|
98
|
+
if (!apiKey) {
|
|
99
|
+
throw new Error(`No API key for ${model.provider}`);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const pathEntries = this._deps.sessionManager.getBranch();
|
|
103
|
+
const settings = this._deps.settingsManager.getCompactionSettings();
|
|
104
|
+
|
|
105
|
+
const preparation = prepareCompaction(pathEntries, settings);
|
|
106
|
+
if (!preparation) {
|
|
107
|
+
const lastEntry = pathEntries[pathEntries.length - 1];
|
|
108
|
+
if (lastEntry?.type === "compaction") {
|
|
109
|
+
throw new Error("Already compacted");
|
|
110
|
+
}
|
|
111
|
+
throw new Error("Nothing to compact (session too small)");
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
let extensionCompaction: CompactionResult | undefined;
|
|
115
|
+
let fromExtension = false;
|
|
116
|
+
const extensionRunner = this._deps.getExtensionRunner();
|
|
117
|
+
|
|
118
|
+
if (extensionRunner?.hasHandlers("session_before_compact")) {
|
|
119
|
+
const result = (await extensionRunner.emit({
|
|
120
|
+
type: "session_before_compact",
|
|
121
|
+
preparation,
|
|
122
|
+
branchEntries: pathEntries,
|
|
123
|
+
customInstructions,
|
|
124
|
+
signal: this._compactionAbortController.signal,
|
|
125
|
+
})) as SessionBeforeCompactResult | undefined;
|
|
126
|
+
|
|
127
|
+
if (result?.cancel) {
|
|
128
|
+
throw new Error("Compaction cancelled");
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (result?.compaction) {
|
|
132
|
+
extensionCompaction = result.compaction;
|
|
133
|
+
fromExtension = true;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
let summary: string;
|
|
138
|
+
let firstKeptEntryId: string;
|
|
139
|
+
let tokensBefore: number;
|
|
140
|
+
let details: unknown;
|
|
141
|
+
|
|
142
|
+
if (extensionCompaction) {
|
|
143
|
+
summary = extensionCompaction.summary;
|
|
144
|
+
firstKeptEntryId = extensionCompaction.firstKeptEntryId;
|
|
145
|
+
tokensBefore = extensionCompaction.tokensBefore;
|
|
146
|
+
details = extensionCompaction.details;
|
|
147
|
+
} else {
|
|
148
|
+
const result = await compact(
|
|
149
|
+
preparation,
|
|
150
|
+
model,
|
|
151
|
+
apiKey,
|
|
152
|
+
customInstructions,
|
|
153
|
+
this._compactionAbortController.signal,
|
|
154
|
+
);
|
|
155
|
+
summary = result.summary;
|
|
156
|
+
firstKeptEntryId = result.firstKeptEntryId;
|
|
157
|
+
tokensBefore = result.tokensBefore;
|
|
158
|
+
details = result.details;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if (this._compactionAbortController.signal.aborted) {
|
|
162
|
+
throw new Error("Compaction cancelled");
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
this._deps.sessionManager.appendCompaction(summary, firstKeptEntryId, tokensBefore, details, fromExtension);
|
|
166
|
+
const newEntries = this._deps.sessionManager.getEntries();
|
|
167
|
+
const sessionContext = this._deps.sessionManager.buildSessionContext();
|
|
168
|
+
this._deps.agent.replaceMessages(sessionContext.messages);
|
|
169
|
+
|
|
170
|
+
const savedCompactionEntry = newEntries.find(
|
|
171
|
+
(e) => e.type === "compaction" && e.summary === summary,
|
|
172
|
+
) as CompactionEntry | undefined;
|
|
173
|
+
|
|
174
|
+
if (extensionRunner && savedCompactionEntry) {
|
|
175
|
+
await extensionRunner.emit({
|
|
176
|
+
type: "session_compact",
|
|
177
|
+
compactionEntry: savedCompactionEntry,
|
|
178
|
+
fromExtension,
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
return { summary, firstKeptEntryId, tokensBefore, details };
|
|
183
|
+
} finally {
|
|
184
|
+
this._compactionAbortController = undefined;
|
|
185
|
+
this._deps.reconnectToAgent();
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** Cancel in-progress compaction (manual or auto) */
|
|
190
|
+
abortCompaction(): void {
|
|
191
|
+
this._compactionAbortController?.abort();
|
|
192
|
+
this._autoCompactionAbortController?.abort();
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/** Cancel in-progress branch summarization */
|
|
196
|
+
abortBranchSummary(): void {
|
|
197
|
+
this._branchSummaryAbortController?.abort();
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Check if compaction is needed and run it.
|
|
202
|
+
* Called after agent_end and before prompt submission.
|
|
203
|
+
*
|
|
204
|
+
* Two cases:
|
|
205
|
+
* 1. Overflow: LLM returned context overflow error, remove error message, compact, auto-retry
|
|
206
|
+
* 2. Threshold: Context over threshold, compact, NO auto-retry
|
|
207
|
+
*
|
|
208
|
+
* @param assistantMessage The assistant message to check
|
|
209
|
+
* @param skipAbortedCheck If false, include aborted messages (for pre-prompt check). Default: true
|
|
210
|
+
*/
|
|
211
|
+
async checkCompaction(assistantMessage: AssistantMessage, skipAbortedCheck = true): Promise<void> {
|
|
212
|
+
const settings = this._deps.settingsManager.getCompactionSettings();
|
|
213
|
+
if (!settings.enabled) return;
|
|
214
|
+
|
|
215
|
+
if (skipAbortedCheck && assistantMessage.stopReason === "aborted") return;
|
|
216
|
+
|
|
217
|
+
const model = this._deps.getModel();
|
|
218
|
+
const contextWindow = model?.contextWindow ?? 0;
|
|
219
|
+
|
|
220
|
+
const sameModel =
|
|
221
|
+
model && assistantMessage.provider === model.provider && assistantMessage.model === model.id;
|
|
222
|
+
|
|
223
|
+
const branchEntries = this._deps.sessionManager.getBranch();
|
|
224
|
+
const compactionEntry = getLatestCompactionEntry(branchEntries);
|
|
225
|
+
const assistantIsFromBeforeCompaction =
|
|
226
|
+
compactionEntry !== null && assistantMessage.timestamp <= new Date(compactionEntry.timestamp).getTime();
|
|
227
|
+
if (assistantIsFromBeforeCompaction) return;
|
|
228
|
+
|
|
229
|
+
// Case 1: Overflow - LLM returned context overflow error
|
|
230
|
+
if (sameModel && isContextOverflow(assistantMessage, contextWindow)) {
|
|
231
|
+
if (this._overflowRecoveryAttempted) {
|
|
232
|
+
this._deps.emit({
|
|
233
|
+
type: "auto_compaction_end",
|
|
234
|
+
result: undefined,
|
|
235
|
+
aborted: false,
|
|
236
|
+
willRetry: false,
|
|
237
|
+
errorMessage:
|
|
238
|
+
"Context overflow recovery failed after one compact-and-retry attempt. Try reducing context or switching to a larger-context model.",
|
|
239
|
+
});
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
this._overflowRecoveryAttempted = true;
|
|
244
|
+
const messages = this._deps.agent.state.messages;
|
|
245
|
+
if (messages.length > 0 && messages[messages.length - 1].role === "assistant") {
|
|
246
|
+
this._deps.agent.replaceMessages(messages.slice(0, -1));
|
|
247
|
+
}
|
|
248
|
+
await this._runAutoCompaction("overflow", true);
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// Case 2: Threshold - context is getting large
|
|
253
|
+
let contextTokens: number;
|
|
254
|
+
if (assistantMessage.stopReason === "error") {
|
|
255
|
+
const messages = this._deps.agent.state.messages;
|
|
256
|
+
const estimate = estimateContextTokens(messages);
|
|
257
|
+
if (estimate.lastUsageIndex === null) return;
|
|
258
|
+
const usageMsg = messages[estimate.lastUsageIndex];
|
|
259
|
+
if (
|
|
260
|
+
compactionEntry &&
|
|
261
|
+
usageMsg.role === "assistant" &&
|
|
262
|
+
(usageMsg as AssistantMessage).timestamp <= new Date(compactionEntry.timestamp).getTime()
|
|
263
|
+
) {
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
contextTokens = estimate.tokens;
|
|
267
|
+
} else {
|
|
268
|
+
contextTokens = calculateContextTokens(assistantMessage.usage);
|
|
269
|
+
}
|
|
270
|
+
if (shouldCompact(contextTokens, contextWindow, settings)) {
|
|
271
|
+
await this._runAutoCompaction("threshold", false);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/** Toggle auto-compaction setting */
|
|
276
|
+
setAutoCompactionEnabled(enabled: boolean): void {
|
|
277
|
+
this._deps.settingsManager.setCompactionEnabled(enabled);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/** Whether auto-compaction is enabled */
|
|
281
|
+
get autoCompactionEnabled(): boolean {
|
|
282
|
+
return this._deps.settingsManager.getCompactionEnabled();
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
// =========================================================================
|
|
286
|
+
// Private helpers
|
|
287
|
+
// =========================================================================
|
|
288
|
+
|
|
289
|
+
private async _runAutoCompaction(reason: "overflow" | "threshold", willRetry: boolean): Promise<void> {
|
|
290
|
+
const settings = this._deps.settingsManager.getCompactionSettings();
|
|
291
|
+
|
|
292
|
+
this._deps.emit({ type: "auto_compaction_start", reason });
|
|
293
|
+
this._autoCompactionAbortController = new AbortController();
|
|
294
|
+
|
|
295
|
+
try {
|
|
296
|
+
const model = this._deps.getModel();
|
|
297
|
+
if (!model) {
|
|
298
|
+
this._deps.emit({ type: "auto_compaction_end", result: undefined, aborted: false, willRetry: false });
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
const apiKey = await this._deps.modelRegistry.getApiKey(model, this._deps.getSessionId());
|
|
303
|
+
if (!apiKey) {
|
|
304
|
+
this._deps.emit({ type: "auto_compaction_end", result: undefined, aborted: false, willRetry: false });
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
const pathEntries = this._deps.sessionManager.getBranch();
|
|
309
|
+
const preparation = prepareCompaction(pathEntries, settings);
|
|
310
|
+
if (!preparation) {
|
|
311
|
+
this._deps.emit({ type: "auto_compaction_end", result: undefined, aborted: false, willRetry: false });
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
let extensionCompaction: CompactionResult | undefined;
|
|
316
|
+
let fromExtension = false;
|
|
317
|
+
const extensionRunner = this._deps.getExtensionRunner();
|
|
318
|
+
|
|
319
|
+
if (extensionRunner?.hasHandlers("session_before_compact")) {
|
|
320
|
+
const extensionResult = (await extensionRunner.emit({
|
|
321
|
+
type: "session_before_compact",
|
|
322
|
+
preparation,
|
|
323
|
+
branchEntries: pathEntries,
|
|
324
|
+
customInstructions: undefined,
|
|
325
|
+
signal: this._autoCompactionAbortController.signal,
|
|
326
|
+
})) as SessionBeforeCompactResult | undefined;
|
|
327
|
+
|
|
328
|
+
if (extensionResult?.cancel) {
|
|
329
|
+
this._deps.emit({
|
|
330
|
+
type: "auto_compaction_end",
|
|
331
|
+
result: undefined,
|
|
332
|
+
aborted: true,
|
|
333
|
+
willRetry: false,
|
|
334
|
+
});
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
if (extensionResult?.compaction) {
|
|
339
|
+
extensionCompaction = extensionResult.compaction;
|
|
340
|
+
fromExtension = true;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
let summary: string;
|
|
345
|
+
let firstKeptEntryId: string;
|
|
346
|
+
let tokensBefore: number;
|
|
347
|
+
let details: unknown;
|
|
348
|
+
|
|
349
|
+
if (extensionCompaction) {
|
|
350
|
+
summary = extensionCompaction.summary;
|
|
351
|
+
firstKeptEntryId = extensionCompaction.firstKeptEntryId;
|
|
352
|
+
tokensBefore = extensionCompaction.tokensBefore;
|
|
353
|
+
details = extensionCompaction.details;
|
|
354
|
+
} else {
|
|
355
|
+
const compactResult = await compact(
|
|
356
|
+
preparation,
|
|
357
|
+
model,
|
|
358
|
+
apiKey,
|
|
359
|
+
undefined,
|
|
360
|
+
this._autoCompactionAbortController.signal,
|
|
361
|
+
);
|
|
362
|
+
summary = compactResult.summary;
|
|
363
|
+
firstKeptEntryId = compactResult.firstKeptEntryId;
|
|
364
|
+
tokensBefore = compactResult.tokensBefore;
|
|
365
|
+
details = compactResult.details;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
if (this._autoCompactionAbortController.signal.aborted) {
|
|
369
|
+
this._deps.emit({ type: "auto_compaction_end", result: undefined, aborted: true, willRetry: false });
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
this._deps.sessionManager.appendCompaction(summary, firstKeptEntryId, tokensBefore, details, fromExtension);
|
|
374
|
+
const newEntries = this._deps.sessionManager.getEntries();
|
|
375
|
+
const sessionContext = this._deps.sessionManager.buildSessionContext();
|
|
376
|
+
this._deps.agent.replaceMessages(sessionContext.messages);
|
|
377
|
+
|
|
378
|
+
const savedCompactionEntry = newEntries.find(
|
|
379
|
+
(e) => e.type === "compaction" && e.summary === summary,
|
|
380
|
+
) as CompactionEntry | undefined;
|
|
381
|
+
|
|
382
|
+
if (extensionRunner && savedCompactionEntry) {
|
|
383
|
+
await extensionRunner.emit({
|
|
384
|
+
type: "session_compact",
|
|
385
|
+
compactionEntry: savedCompactionEntry,
|
|
386
|
+
fromExtension,
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
const result: CompactionResult = { summary, firstKeptEntryId, tokensBefore, details };
|
|
391
|
+
this._deps.emit({ type: "auto_compaction_end", result, aborted: false, willRetry });
|
|
392
|
+
|
|
393
|
+
if (willRetry) {
|
|
394
|
+
const messages = this._deps.agent.state.messages;
|
|
395
|
+
const lastMsg = messages[messages.length - 1];
|
|
396
|
+
if (lastMsg?.role === "assistant" && (lastMsg as AssistantMessage).stopReason === "error") {
|
|
397
|
+
this._deps.agent.replaceMessages(messages.slice(0, -1));
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
setTimeout(() => {
|
|
401
|
+
this._deps.agent.continue().catch(() => {});
|
|
402
|
+
}, 100);
|
|
403
|
+
} else if (this._deps.agent.hasQueuedMessages()) {
|
|
404
|
+
setTimeout(() => {
|
|
405
|
+
this._deps.agent.continue().catch(() => {});
|
|
406
|
+
}, 100);
|
|
407
|
+
}
|
|
408
|
+
} catch (error) {
|
|
409
|
+
const errorMessage = getErrorMessage(error);
|
|
410
|
+
this._deps.emit({
|
|
411
|
+
type: "auto_compaction_end",
|
|
412
|
+
result: undefined,
|
|
413
|
+
aborted: false,
|
|
414
|
+
willRetry: false,
|
|
415
|
+
errorMessage:
|
|
416
|
+
reason === "overflow"
|
|
417
|
+
? `Context overflow recovery failed: ${errorMessage}`
|
|
418
|
+
: `Auto-compaction failed: ${errorMessage}`,
|
|
419
|
+
});
|
|
420
|
+
} finally {
|
|
421
|
+
this._autoCompactionAbortController = undefined;
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
}
|
|
@@ -30,7 +30,6 @@ export type {
|
|
|
30
30
|
AgentToolUpdateCallback,
|
|
31
31
|
// App keybindings (for custom editors)
|
|
32
32
|
AppAction,
|
|
33
|
-
AppendEntryHandler,
|
|
34
33
|
// Events - Tool (ToolCallEvent types)
|
|
35
34
|
BashToolCallEvent,
|
|
36
35
|
BashToolResultEvent,
|
|
@@ -73,10 +72,6 @@ export type {
|
|
|
73
72
|
ExtensionWidgetOptions,
|
|
74
73
|
FindToolCallEvent,
|
|
75
74
|
FindToolResultEvent,
|
|
76
|
-
GetActiveToolsHandler,
|
|
77
|
-
GetAllToolsHandler,
|
|
78
|
-
GetCommandsHandler,
|
|
79
|
-
GetThinkingLevelHandler,
|
|
80
75
|
GrepToolCallEvent,
|
|
81
76
|
GrepToolResultEvent,
|
|
82
77
|
// Events - Input
|
|
@@ -107,8 +102,6 @@ export type {
|
|
|
107
102
|
// Events - Resources
|
|
108
103
|
ResourcesDiscoverEvent,
|
|
109
104
|
ResourcesDiscoverResult,
|
|
110
|
-
SendMessageHandler,
|
|
111
|
-
SendUserMessageHandler,
|
|
112
105
|
SessionBeforeCompactEvent,
|
|
113
106
|
SessionBeforeCompactResult,
|
|
114
107
|
SessionBeforeForkEvent,
|
|
@@ -128,10 +121,6 @@ export type {
|
|
|
128
121
|
SessionStartEvent,
|
|
129
122
|
SessionSwitchEvent,
|
|
130
123
|
SessionTreeEvent,
|
|
131
|
-
SetActiveToolsHandler,
|
|
132
|
-
SetLabelHandler,
|
|
133
|
-
SetModelHandler,
|
|
134
|
-
SetThinkingLevelHandler,
|
|
135
124
|
TerminalInputHandler,
|
|
136
125
|
// Events - Tool
|
|
137
126
|
ToolCallEvent,
|
|
@@ -157,16 +146,7 @@ export type {
|
|
|
157
146
|
WriteToolResultEvent,
|
|
158
147
|
} from "./types.js";
|
|
159
148
|
// Type guards
|
|
160
|
-
export {
|
|
161
|
-
isBashToolResult,
|
|
162
|
-
isEditToolResult,
|
|
163
|
-
isFindToolResult,
|
|
164
|
-
isGrepToolResult,
|
|
165
|
-
isLsToolResult,
|
|
166
|
-
isReadToolResult,
|
|
167
|
-
isToolCallEventType,
|
|
168
|
-
isWriteToolResult,
|
|
169
|
-
} from "./types.js";
|
|
149
|
+
export { isToolCallEventType, isToolResultEventType } from "./types.js";
|
|
170
150
|
export {
|
|
171
151
|
wrapRegisteredTool,
|
|
172
152
|
wrapRegisteredTools,
|