@bastani/atomic 0.8.26-alpha.5 → 0.8.26-alpha.7
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/CHANGELOG.md +24 -0
- package/README.md +7 -4
- package/dist/builtin/intercom/CHANGELOG.md +12 -0
- package/dist/builtin/intercom/package.json +2 -2
- package/dist/builtin/mcp/CHANGELOG.md +12 -0
- package/dist/builtin/mcp/package.json +3 -3
- package/dist/builtin/subagents/CHANGELOG.md +12 -0
- package/dist/builtin/subagents/agents/codebase-online-researcher.md +9 -9
- package/dist/builtin/subagents/agents/debugger.md +6 -6
- package/dist/builtin/subagents/package.json +4 -4
- package/dist/builtin/subagents/prompts/parallel-handoff-plan.md +1 -1
- package/dist/builtin/subagents/skills/browser/EXAMPLES.md +151 -0
- package/dist/builtin/subagents/skills/browser/LICENSE.txt +21 -0
- package/dist/builtin/subagents/skills/browser/REFERENCE.md +451 -0
- package/dist/builtin/subagents/skills/browser/SKILL.md +170 -0
- package/dist/builtin/subagents/skills/subagent/SKILL.md +4 -4
- package/dist/builtin/subagents/src/runs/background/subagent-runner.ts +48 -10
- package/dist/builtin/subagents/src/runs/foreground/execution.ts +30 -9
- package/dist/builtin/subagents/src/runs/shared/final-drain.ts +34 -0
- package/dist/builtin/subagents/src/runs/shared/model-fallback.ts +416 -7
- package/dist/builtin/web-access/CHANGELOG.md +12 -0
- package/dist/builtin/web-access/package.json +2 -2
- package/dist/builtin/workflows/CHANGELOG.md +17 -0
- package/dist/builtin/workflows/builtin/deep-research-codebase.ts +4 -1
- package/dist/builtin/workflows/builtin/goal.ts +127 -99
- package/dist/builtin/workflows/builtin/open-claude-design.ts +224 -147
- package/dist/builtin/workflows/builtin/ralph.ts +160 -197
- package/dist/builtin/workflows/package.json +2 -2
- package/dist/builtin/workflows/skills/research-codebase/SKILL.md +1 -1
- package/dist/builtin/workflows/src/extension/index.ts +10 -2
- package/dist/builtin/workflows/src/extension/runtime.ts +35 -3
- package/dist/builtin/workflows/src/runs/background/status.ts +52 -6
- package/dist/builtin/workflows/src/runs/foreground/executor.ts +441 -15
- package/dist/builtin/workflows/src/runs/foreground/stage-runner.ts +69 -8
- package/dist/builtin/workflows/src/runs/shared/model-fallback.ts +402 -8
- package/dist/builtin/workflows/src/shared/persistence-restore.ts +182 -6
- package/dist/builtin/workflows/src/shared/persistence-session-entries.ts +76 -6
- package/dist/builtin/workflows/src/shared/stage-prompt.ts +33 -2
- package/dist/builtin/workflows/src/shared/store-types.ts +31 -0
- package/dist/builtin/workflows/src/shared/store.ts +99 -11
- package/dist/builtin/workflows/src/shared/workflow-failures.ts +758 -132
- package/dist/builtin/workflows/src/tui/stage-chat-view.ts +9 -0
- package/dist/core/agent-session.d.ts +28 -1
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +110 -28
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/compaction/branch-summarization.d.ts +1 -1
- package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
- package/dist/core/compaction/branch-summarization.js +6 -3
- package/dist/core/compaction/branch-summarization.js.map +1 -1
- package/dist/core/compaction/compaction.d.ts.map +1 -1
- package/dist/core/compaction/compaction.js +23 -10
- package/dist/core/compaction/compaction.js.map +1 -1
- package/dist/core/compaction/context-compaction.d.ts +61 -0
- package/dist/core/compaction/context-compaction.d.ts.map +1 -0
- package/dist/core/compaction/context-compaction.js +602 -0
- package/dist/core/compaction/context-compaction.js.map +1 -0
- package/dist/core/compaction/index.d.ts +1 -0
- package/dist/core/compaction/index.d.ts.map +1 -1
- package/dist/core/compaction/index.js +1 -0
- package/dist/core/compaction/index.js.map +1 -1
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/session-manager.d.ts +41 -1
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +146 -7
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/slash-commands.d.ts.map +1 -1
- package/dist/core/slash-commands.js +1 -0
- package/dist/core/slash-commands.js.map +1 -1
- package/dist/core/tools/ask-user-question/tool/format-answer.d.ts +5 -5
- package/dist/core/tools/ask-user-question/tool/format-answer.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/tool/format-answer.js +5 -5
- package/dist/core/tools/ask-user-question/tool/format-answer.js.map +1 -1
- package/dist/core/tools/ask-user-question/tool/response-envelope.d.ts +16 -3
- package/dist/core/tools/ask-user-question/tool/response-envelope.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/tool/response-envelope.js +21 -3
- package/dist/core/tools/ask-user-question/tool/response-envelope.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/modes/index.d.ts +1 -1
- package/dist/modes/index.d.ts.map +1 -1
- package/dist/modes/index.js.map +1 -1
- package/dist/modes/interactive/components/chat-session-host.d.ts.map +1 -1
- package/dist/modes/interactive/components/chat-session-host.js +17 -0
- package/dist/modes/interactive/components/chat-session-host.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +1 -0
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +74 -0
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-client.d.ts +12 -7
- package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-client.js +8 -1
- package/dist/modes/rpc/rpc-client.js.map +1 -1
- package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-mode.js +4 -0
- package/dist/modes/rpc/rpc-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-types.d.ts +13 -2
- package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-types.js.map +1 -1
- package/docs/compaction.md +42 -23
- package/docs/custom-provider.md +11 -9
- package/docs/extensions.md +35 -35
- package/docs/index.md +1 -8
- package/docs/json.md +14 -11
- package/docs/packages.md +2 -0
- package/docs/providers.md +4 -1
- package/docs/quickstart.md +5 -12
- package/docs/rpc.md +44 -8
- package/docs/sdk.md +1 -8
- package/docs/session-format.md +25 -12
- package/docs/sessions.md +2 -1
- package/docs/skills.md +1 -15
- package/docs/termux.md +9 -10
- package/docs/themes.md +2 -2
- package/docs/tmux.md +3 -3
- package/docs/tui.md +19 -32
- package/docs/usage.md +2 -0
- package/docs/workflows.md +44 -2
- package/package.json +4 -12
- package/dist/builtin/subagents/skills/browser-use/SKILL.md +0 -234
- package/dist/builtin/subagents/skills/browser-use/references/cdp-python.md +0 -76
- package/dist/builtin/subagents/skills/browser-use/references/multi-session.md +0 -92
- package/node_modules/@earendil-works/pi-tui/README.md +0 -779
- package/node_modules/@earendil-works/pi-tui/dist/autocomplete.d.ts +0 -54
- package/node_modules/@earendil-works/pi-tui/dist/autocomplete.d.ts.map +0 -1
- package/node_modules/@earendil-works/pi-tui/dist/autocomplete.js +0 -632
- package/node_modules/@earendil-works/pi-tui/dist/autocomplete.js.map +0 -1
- package/node_modules/@earendil-works/pi-tui/dist/components/box.d.ts +0 -22
- package/node_modules/@earendil-works/pi-tui/dist/components/box.d.ts.map +0 -1
- package/node_modules/@earendil-works/pi-tui/dist/components/box.js +0 -104
- package/node_modules/@earendil-works/pi-tui/dist/components/box.js.map +0 -1
- package/node_modules/@earendil-works/pi-tui/dist/components/cancellable-loader.d.ts +0 -22
- package/node_modules/@earendil-works/pi-tui/dist/components/cancellable-loader.d.ts.map +0 -1
- package/node_modules/@earendil-works/pi-tui/dist/components/cancellable-loader.js +0 -35
- package/node_modules/@earendil-works/pi-tui/dist/components/cancellable-loader.js.map +0 -1
- package/node_modules/@earendil-works/pi-tui/dist/components/editor.d.ts +0 -249
- package/node_modules/@earendil-works/pi-tui/dist/components/editor.d.ts.map +0 -1
- package/node_modules/@earendil-works/pi-tui/dist/components/editor.js +0 -1857
- package/node_modules/@earendil-works/pi-tui/dist/components/editor.js.map +0 -1
- package/node_modules/@earendil-works/pi-tui/dist/components/image.d.ts +0 -28
- package/node_modules/@earendil-works/pi-tui/dist/components/image.d.ts.map +0 -1
- package/node_modules/@earendil-works/pi-tui/dist/components/image.js +0 -89
- package/node_modules/@earendil-works/pi-tui/dist/components/image.js.map +0 -1
- package/node_modules/@earendil-works/pi-tui/dist/components/input.d.ts +0 -37
- package/node_modules/@earendil-works/pi-tui/dist/components/input.d.ts.map +0 -1
- package/node_modules/@earendil-works/pi-tui/dist/components/input.js +0 -378
- package/node_modules/@earendil-works/pi-tui/dist/components/input.js.map +0 -1
- package/node_modules/@earendil-works/pi-tui/dist/components/loader.d.ts +0 -31
- package/node_modules/@earendil-works/pi-tui/dist/components/loader.d.ts.map +0 -1
- package/node_modules/@earendil-works/pi-tui/dist/components/loader.js +0 -69
- package/node_modules/@earendil-works/pi-tui/dist/components/loader.js.map +0 -1
- package/node_modules/@earendil-works/pi-tui/dist/components/markdown.d.ts +0 -96
- package/node_modules/@earendil-works/pi-tui/dist/components/markdown.d.ts.map +0 -1
- package/node_modules/@earendil-works/pi-tui/dist/components/markdown.js +0 -644
- package/node_modules/@earendil-works/pi-tui/dist/components/markdown.js.map +0 -1
- package/node_modules/@earendil-works/pi-tui/dist/components/select-list.d.ts +0 -50
- package/node_modules/@earendil-works/pi-tui/dist/components/select-list.d.ts.map +0 -1
- package/node_modules/@earendil-works/pi-tui/dist/components/select-list.js +0 -159
- package/node_modules/@earendil-works/pi-tui/dist/components/select-list.js.map +0 -1
- package/node_modules/@earendil-works/pi-tui/dist/components/settings-list.d.ts +0 -50
- package/node_modules/@earendil-works/pi-tui/dist/components/settings-list.d.ts.map +0 -1
- package/node_modules/@earendil-works/pi-tui/dist/components/settings-list.js +0 -185
- package/node_modules/@earendil-works/pi-tui/dist/components/settings-list.js.map +0 -1
- package/node_modules/@earendil-works/pi-tui/dist/components/spacer.d.ts +0 -12
- package/node_modules/@earendil-works/pi-tui/dist/components/spacer.d.ts.map +0 -1
- package/node_modules/@earendil-works/pi-tui/dist/components/spacer.js +0 -23
- package/node_modules/@earendil-works/pi-tui/dist/components/spacer.js.map +0 -1
- package/node_modules/@earendil-works/pi-tui/dist/components/text.d.ts +0 -19
- package/node_modules/@earendil-works/pi-tui/dist/components/text.d.ts.map +0 -1
- package/node_modules/@earendil-works/pi-tui/dist/components/text.js +0 -89
- package/node_modules/@earendil-works/pi-tui/dist/components/text.js.map +0 -1
- package/node_modules/@earendil-works/pi-tui/dist/components/truncated-text.d.ts +0 -13
- package/node_modules/@earendil-works/pi-tui/dist/components/truncated-text.d.ts.map +0 -1
- package/node_modules/@earendil-works/pi-tui/dist/components/truncated-text.js +0 -51
- package/node_modules/@earendil-works/pi-tui/dist/components/truncated-text.js.map +0 -1
- package/node_modules/@earendil-works/pi-tui/dist/editor-component.d.ts +0 -39
- package/node_modules/@earendil-works/pi-tui/dist/editor-component.d.ts.map +0 -1
- package/node_modules/@earendil-works/pi-tui/dist/editor-component.js +0 -2
- package/node_modules/@earendil-works/pi-tui/dist/editor-component.js.map +0 -1
- package/node_modules/@earendil-works/pi-tui/dist/fuzzy.d.ts +0 -16
- package/node_modules/@earendil-works/pi-tui/dist/fuzzy.d.ts.map +0 -1
- package/node_modules/@earendil-works/pi-tui/dist/fuzzy.js +0 -110
- package/node_modules/@earendil-works/pi-tui/dist/fuzzy.js.map +0 -1
- package/node_modules/@earendil-works/pi-tui/dist/index.d.ts +0 -23
- package/node_modules/@earendil-works/pi-tui/dist/index.d.ts.map +0 -1
- package/node_modules/@earendil-works/pi-tui/dist/index.js +0 -32
- package/node_modules/@earendil-works/pi-tui/dist/index.js.map +0 -1
- package/node_modules/@earendil-works/pi-tui/dist/keybindings.d.ts +0 -193
- package/node_modules/@earendil-works/pi-tui/dist/keybindings.d.ts.map +0 -1
- package/node_modules/@earendil-works/pi-tui/dist/keybindings.js +0 -174
- package/node_modules/@earendil-works/pi-tui/dist/keybindings.js.map +0 -1
- package/node_modules/@earendil-works/pi-tui/dist/keys.d.ts +0 -184
- package/node_modules/@earendil-works/pi-tui/dist/keys.d.ts.map +0 -1
- package/node_modules/@earendil-works/pi-tui/dist/keys.js +0 -1173
- package/node_modules/@earendil-works/pi-tui/dist/keys.js.map +0 -1
- package/node_modules/@earendil-works/pi-tui/dist/kill-ring.d.ts +0 -28
- package/node_modules/@earendil-works/pi-tui/dist/kill-ring.d.ts.map +0 -1
- package/node_modules/@earendil-works/pi-tui/dist/kill-ring.js +0 -44
- package/node_modules/@earendil-works/pi-tui/dist/kill-ring.js.map +0 -1
- package/node_modules/@earendil-works/pi-tui/dist/native-modifiers.d.ts +0 -3
- package/node_modules/@earendil-works/pi-tui/dist/native-modifiers.d.ts.map +0 -1
- package/node_modules/@earendil-works/pi-tui/dist/native-modifiers.js +0 -53
- package/node_modules/@earendil-works/pi-tui/dist/native-modifiers.js.map +0 -1
- package/node_modules/@earendil-works/pi-tui/dist/stdin-buffer.d.ts +0 -50
- package/node_modules/@earendil-works/pi-tui/dist/stdin-buffer.d.ts.map +0 -1
- package/node_modules/@earendil-works/pi-tui/dist/stdin-buffer.js +0 -361
- package/node_modules/@earendil-works/pi-tui/dist/stdin-buffer.js.map +0 -1
- package/node_modules/@earendil-works/pi-tui/dist/terminal-image.d.ts +0 -90
- package/node_modules/@earendil-works/pi-tui/dist/terminal-image.d.ts.map +0 -1
- package/node_modules/@earendil-works/pi-tui/dist/terminal-image.js +0 -366
- package/node_modules/@earendil-works/pi-tui/dist/terminal-image.js.map +0 -1
- package/node_modules/@earendil-works/pi-tui/dist/terminal.d.ts +0 -113
- package/node_modules/@earendil-works/pi-tui/dist/terminal.d.ts.map +0 -1
- package/node_modules/@earendil-works/pi-tui/dist/terminal.js +0 -472
- package/node_modules/@earendil-works/pi-tui/dist/terminal.js.map +0 -1
- package/node_modules/@earendil-works/pi-tui/dist/tui.d.ts +0 -227
- package/node_modules/@earendil-works/pi-tui/dist/tui.d.ts.map +0 -1
- package/node_modules/@earendil-works/pi-tui/dist/tui.js +0 -1106
- package/node_modules/@earendil-works/pi-tui/dist/tui.js.map +0 -1
- package/node_modules/@earendil-works/pi-tui/dist/undo-stack.d.ts +0 -17
- package/node_modules/@earendil-works/pi-tui/dist/undo-stack.d.ts.map +0 -1
- package/node_modules/@earendil-works/pi-tui/dist/undo-stack.js +0 -25
- package/node_modules/@earendil-works/pi-tui/dist/undo-stack.js.map +0 -1
- package/node_modules/@earendil-works/pi-tui/dist/utils.d.ts +0 -84
- package/node_modules/@earendil-works/pi-tui/dist/utils.d.ts.map +0 -1
- package/node_modules/@earendil-works/pi-tui/dist/utils.js +0 -1029
- package/node_modules/@earendil-works/pi-tui/dist/utils.js.map +0 -1
- package/node_modules/@earendil-works/pi-tui/dist/word-navigation.d.ts +0 -25
- package/node_modules/@earendil-works/pi-tui/dist/word-navigation.d.ts.map +0 -1
- package/node_modules/@earendil-works/pi-tui/dist/word-navigation.js +0 -96
- package/node_modules/@earendil-works/pi-tui/dist/word-navigation.js.map +0 -1
- package/node_modules/@earendil-works/pi-tui/native/darwin/prebuilds/darwin-arm64/darwin-modifiers.node +0 -0
- package/node_modules/@earendil-works/pi-tui/native/darwin/prebuilds/darwin-x64/darwin-modifiers.node +0 -0
- package/node_modules/@earendil-works/pi-tui/native/win32/prebuilds/win32-arm64/win32-console-mode.node +0 -0
- package/node_modules/@earendil-works/pi-tui/native/win32/prebuilds/win32-x64/win32-console-mode.node +0 -0
- package/node_modules/@earendil-works/pi-tui/package.json +0 -47
- package/node_modules/get-east-asian-width/index.d.ts +0 -60
- package/node_modules/get-east-asian-width/index.js +0 -30
- package/node_modules/get-east-asian-width/license +0 -9
- package/node_modules/get-east-asian-width/lookup-data.js +0 -21
- package/node_modules/get-east-asian-width/lookup.js +0 -138
- package/node_modules/get-east-asian-width/package.json +0 -71
- package/node_modules/get-east-asian-width/readme.md +0 -65
- package/node_modules/get-east-asian-width/utilities.js +0 -24
- package/node_modules/marked/LICENSE.md +0 -44
- package/node_modules/marked/README.md +0 -106
- package/node_modules/marked/bin/main.js +0 -282
- package/node_modules/marked/bin/marked.js +0 -15
- package/node_modules/marked/lib/marked.cjs +0 -2211
- package/node_modules/marked/lib/marked.cjs.map +0 -7
- package/node_modules/marked/lib/marked.d.cts +0 -728
- package/node_modules/marked/lib/marked.d.ts +0 -728
- package/node_modules/marked/lib/marked.esm.js +0 -2189
- package/node_modules/marked/lib/marked.esm.js.map +0 -7
- package/node_modules/marked/lib/marked.umd.js +0 -2213
- package/node_modules/marked/lib/marked.umd.js.map +0 -7
- package/node_modules/marked/man/marked.1 +0 -111
- package/node_modules/marked/man/marked.1.md +0 -92
- package/node_modules/marked/marked.min.js +0 -69
- package/node_modules/marked/package.json +0 -111
|
@@ -22,14 +22,14 @@ import { sleep } from "../utils/sleep.js";
|
|
|
22
22
|
import { ATOMIC_GUIDE_COMMAND_NAME, ATOMIC_GUIDE_HELP_CHOICES, atomicGuideModeForChoice, getAtomicGuideMessage, isAtomicGuideHelpChoice, normalizeAtomicGuideMode, } from "./atomic-guide-command.js";
|
|
23
23
|
import { formatNoApiKeyFoundMessage, formatNoModelSelectedMessage } from "./auth-guidance.js";
|
|
24
24
|
import { executeBashWithOperations } from "./bash-executor.js";
|
|
25
|
-
import { calculateContextTokens, collectEntriesForBranchSummary, compact, estimateContextTokens, generateBranchSummary, prepareCompaction, shouldCompact, } from "./compaction/index.js";
|
|
25
|
+
import { calculateContextTokens, collectEntriesForBranchSummary, compact, contextCompact as runContextCompact, estimateContextTokens, generateBranchSummary, prepareCompaction, prepareContextCompaction, shouldCompact, } from "./compaction/index.js";
|
|
26
26
|
import { DEFAULT_THINKING_LEVEL } from "./defaults.js";
|
|
27
27
|
import { exportSessionToHtml } from "./export-html/index.js";
|
|
28
28
|
import { createToolHtmlRenderer } from "./export-html/tool-renderer.js";
|
|
29
29
|
import { ExtensionRunner, wrapRegisteredTools, } from "./extensions/index.js";
|
|
30
30
|
import { emitSessionShutdownEvent } from "./extensions/runner.js";
|
|
31
31
|
import { expandPromptTemplate } from "./prompt-templates.js";
|
|
32
|
-
import { CURRENT_SESSION_VERSION,
|
|
32
|
+
import { CURRENT_SESSION_VERSION, getLatestCompactionBoundaryEntry } from "./session-manager.js";
|
|
33
33
|
import { createSyntheticSourceInfo } from "./source-info.js";
|
|
34
34
|
import { buildSystemPrompt } from "./system-prompt.js";
|
|
35
35
|
import { createLocalBashOperations } from "./tools/bash.js";
|
|
@@ -1587,6 +1587,66 @@ export class AgentSession {
|
|
|
1587
1587
|
this._reconnectToAgent();
|
|
1588
1588
|
}
|
|
1589
1589
|
}
|
|
1590
|
+
/**
|
|
1591
|
+
* Manually compact the session context by applying validated logical deletions.
|
|
1592
|
+
* Retained transcript entries/content blocks stay verbatim; no user prompt text is accepted.
|
|
1593
|
+
*/
|
|
1594
|
+
async contextCompact() {
|
|
1595
|
+
this._disconnectFromAgent();
|
|
1596
|
+
await this.abort();
|
|
1597
|
+
this._compactionAbortController = new AbortController();
|
|
1598
|
+
this._emit({ type: "context_compaction_start", reason: "manual" });
|
|
1599
|
+
try {
|
|
1600
|
+
if (!this.model) {
|
|
1601
|
+
throw new Error(formatNoModelSelectedMessage());
|
|
1602
|
+
}
|
|
1603
|
+
const { apiKey, headers } = await this._getRequiredRequestAuth(this.model);
|
|
1604
|
+
const pathEntries = this.sessionManager.getBranch();
|
|
1605
|
+
const settings = this.settingsManager.getCompactionSettings();
|
|
1606
|
+
const preparation = prepareContextCompaction(pathEntries, settings);
|
|
1607
|
+
if (!preparation) {
|
|
1608
|
+
throw new Error("Nothing to context-compact (session too small)");
|
|
1609
|
+
}
|
|
1610
|
+
const validated = await runContextCompact(preparation, this.model, apiKey, headers, this._compactionAbortController.signal, this.thinkingLevel);
|
|
1611
|
+
if (this._compactionAbortController.signal.aborted) {
|
|
1612
|
+
throw new Error("Compaction cancelled");
|
|
1613
|
+
}
|
|
1614
|
+
const backupPath = this.sessionManager.writeBackupSnapshot("context-compact");
|
|
1615
|
+
this.sessionManager.appendContextCompaction(validated.deletedTargets, validated.protectedEntryIds, validated.stats, backupPath);
|
|
1616
|
+
const sessionContext = this.sessionManager.buildSessionContext();
|
|
1617
|
+
this.agent.state.messages = sessionContext.messages;
|
|
1618
|
+
const result = {
|
|
1619
|
+
...validated,
|
|
1620
|
+
promptVersion: 1,
|
|
1621
|
+
backupPath,
|
|
1622
|
+
};
|
|
1623
|
+
this._emit({
|
|
1624
|
+
type: "context_compaction_end",
|
|
1625
|
+
reason: "manual",
|
|
1626
|
+
result,
|
|
1627
|
+
aborted: false,
|
|
1628
|
+
willRetry: false,
|
|
1629
|
+
});
|
|
1630
|
+
return result;
|
|
1631
|
+
}
|
|
1632
|
+
catch (error) {
|
|
1633
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1634
|
+
const aborted = message === "Compaction cancelled" || (error instanceof Error && error.name === "AbortError");
|
|
1635
|
+
this._emit({
|
|
1636
|
+
type: "context_compaction_end",
|
|
1637
|
+
reason: "manual",
|
|
1638
|
+
result: undefined,
|
|
1639
|
+
aborted,
|
|
1640
|
+
willRetry: false,
|
|
1641
|
+
errorMessage: aborted ? undefined : `Context compaction failed: ${message}`,
|
|
1642
|
+
});
|
|
1643
|
+
throw error;
|
|
1644
|
+
}
|
|
1645
|
+
finally {
|
|
1646
|
+
this._compactionAbortController = undefined;
|
|
1647
|
+
this._reconnectToAgent();
|
|
1648
|
+
}
|
|
1649
|
+
}
|
|
1590
1650
|
/**
|
|
1591
1651
|
* Cancel in-progress compaction (manual or auto).
|
|
1592
1652
|
*/
|
|
@@ -1606,7 +1666,7 @@ export class AgentSession {
|
|
|
1606
1666
|
*
|
|
1607
1667
|
* Two cases:
|
|
1608
1668
|
* 1. Overflow: LLM returned context overflow error, remove error message from agent state, compact, auto-retry
|
|
1609
|
-
* 2. Threshold: Context over threshold, compact,
|
|
1669
|
+
* 2. Threshold: Context over threshold, compact, resume queued active-turn work if present; otherwise wait for user
|
|
1610
1670
|
*
|
|
1611
1671
|
* @param assistantMessage The assistant message to check
|
|
1612
1672
|
* @param skipAbortedCheck If false, include aborted messages (for pre-prompt check). Default: true
|
|
@@ -1627,9 +1687,10 @@ export class AgentSession {
|
|
|
1627
1687
|
// Skip compaction checks if this assistant message is older than the latest
|
|
1628
1688
|
// compaction boundary. This prevents a stale pre-compaction usage/error
|
|
1629
1689
|
// from retriggering compaction on the first prompt after compaction.
|
|
1630
|
-
const
|
|
1631
|
-
const
|
|
1632
|
-
|
|
1690
|
+
const compactionBoundaryEntry = getLatestCompactionBoundaryEntry(this.sessionManager.getBranch());
|
|
1691
|
+
const assistantIsFromBeforeCompactionBoundary = compactionBoundaryEntry !== null &&
|
|
1692
|
+
assistantMessage.timestamp <= new Date(compactionBoundaryEntry.timestamp).getTime();
|
|
1693
|
+
if (assistantIsFromBeforeCompactionBoundary) {
|
|
1633
1694
|
return;
|
|
1634
1695
|
}
|
|
1635
1696
|
// Case 1: Overflow - LLM returned context overflow error
|
|
@@ -1668,9 +1729,9 @@ export class AgentSession {
|
|
|
1668
1729
|
// have stale usage reflecting the old (larger) context and would falsely
|
|
1669
1730
|
// trigger compaction right after one just finished.
|
|
1670
1731
|
const usageMsg = messages[estimate.lastUsageIndex];
|
|
1671
|
-
if (
|
|
1732
|
+
if (compactionBoundaryEntry &&
|
|
1672
1733
|
usageMsg.role === "assistant" &&
|
|
1673
|
-
usageMsg.timestamp <= new Date(
|
|
1734
|
+
usageMsg.timestamp <= new Date(compactionBoundaryEntry.timestamp).getTime()) {
|
|
1674
1735
|
return;
|
|
1675
1736
|
}
|
|
1676
1737
|
contextTokens = estimate.tokens;
|
|
@@ -1682,6 +1743,40 @@ export class AgentSession {
|
|
|
1682
1743
|
await this._runAutoCompaction("threshold", false);
|
|
1683
1744
|
}
|
|
1684
1745
|
}
|
|
1746
|
+
/**
|
|
1747
|
+
* Internal: remove the trailing overflow error from retry context if it is still present.
|
|
1748
|
+
*/
|
|
1749
|
+
_dropTrailingOverflowAssistantErrorIfPresent() {
|
|
1750
|
+
const messages = this.agent.state.messages;
|
|
1751
|
+
const lastMsg = messages[messages.length - 1];
|
|
1752
|
+
if (lastMsg?.role === "assistant" && lastMsg.stopReason === "error") {
|
|
1753
|
+
this.agent.state.messages = messages.slice(0, -1);
|
|
1754
|
+
}
|
|
1755
|
+
}
|
|
1756
|
+
/**
|
|
1757
|
+
* Internal: schedule a live post-event continuation probe after compaction_end listeners can flush queues.
|
|
1758
|
+
*/
|
|
1759
|
+
_schedulePostAutoCompactionContinuationProbe(reason, willRetry) {
|
|
1760
|
+
setTimeout(() => {
|
|
1761
|
+
if (this.isCompacting || this.isStreaming) {
|
|
1762
|
+
return;
|
|
1763
|
+
}
|
|
1764
|
+
if (reason === "overflow" && willRetry) {
|
|
1765
|
+
this._resumeAfterAutoCompaction();
|
|
1766
|
+
return;
|
|
1767
|
+
}
|
|
1768
|
+
if (!this.agent.hasQueuedMessages()) {
|
|
1769
|
+
return;
|
|
1770
|
+
}
|
|
1771
|
+
this._resumeAfterAutoCompaction();
|
|
1772
|
+
}, 100);
|
|
1773
|
+
}
|
|
1774
|
+
/**
|
|
1775
|
+
* Internal: resume generation after successful auto-compaction only when active work remains.
|
|
1776
|
+
*/
|
|
1777
|
+
_resumeAfterAutoCompaction() {
|
|
1778
|
+
this.agent.continue().catch(() => { });
|
|
1779
|
+
}
|
|
1685
1780
|
/**
|
|
1686
1781
|
* Internal: Run auto-compaction with events.
|
|
1687
1782
|
*/
|
|
@@ -1782,6 +1877,9 @@ export class AgentSession {
|
|
|
1782
1877
|
const newEntries = this.sessionManager.getEntries();
|
|
1783
1878
|
const sessionContext = this.sessionManager.buildSessionContext();
|
|
1784
1879
|
this.agent.state.messages = sessionContext.messages;
|
|
1880
|
+
if (reason === "overflow" && willRetry) {
|
|
1881
|
+
this._dropTrailingOverflowAssistantErrorIfPresent();
|
|
1882
|
+
}
|
|
1785
1883
|
// Get the saved compaction entry for the extension event
|
|
1786
1884
|
const savedCompactionEntry = newEntries.find((e) => e.type === "compaction" && e.summary === summary);
|
|
1787
1885
|
if (this._extensionRunner && savedCompactionEntry) {
|
|
@@ -1798,23 +1896,7 @@ export class AgentSession {
|
|
|
1798
1896
|
details,
|
|
1799
1897
|
};
|
|
1800
1898
|
this._emit({ type: "compaction_end", reason, result, aborted: false, willRetry });
|
|
1801
|
-
|
|
1802
|
-
const messages = this.agent.state.messages;
|
|
1803
|
-
const lastMsg = messages[messages.length - 1];
|
|
1804
|
-
if (lastMsg?.role === "assistant" && lastMsg.stopReason === "error") {
|
|
1805
|
-
this.agent.state.messages = messages.slice(0, -1);
|
|
1806
|
-
}
|
|
1807
|
-
setTimeout(() => {
|
|
1808
|
-
this.agent.continue().catch(() => { });
|
|
1809
|
-
}, 100);
|
|
1810
|
-
}
|
|
1811
|
-
else if (this.agent.hasQueuedMessages()) {
|
|
1812
|
-
// Auto-compaction can complete while follow-up/steering/custom messages are waiting.
|
|
1813
|
-
// Kick the loop so queued messages are actually delivered.
|
|
1814
|
-
setTimeout(() => {
|
|
1815
|
-
this.agent.continue().catch(() => { });
|
|
1816
|
-
}, 100);
|
|
1817
|
-
}
|
|
1899
|
+
this._schedulePostAutoCompactionContinuationProbe(reason, willRetry);
|
|
1818
1900
|
}
|
|
1819
1901
|
catch (error) {
|
|
1820
1902
|
const errorMessage = error instanceof Error ? error.message : "compaction failed";
|
|
@@ -2633,10 +2715,10 @@ export class AgentSession {
|
|
|
2633
2715
|
// We can only trust usage from an assistant that responded after the latest compaction.
|
|
2634
2716
|
// If no such assistant exists, context token count is unknown until the next LLM response.
|
|
2635
2717
|
const branchEntries = this.sessionManager.getBranch();
|
|
2636
|
-
const
|
|
2637
|
-
if (
|
|
2718
|
+
const latestCompactionBoundary = getLatestCompactionBoundaryEntry(branchEntries);
|
|
2719
|
+
if (latestCompactionBoundary) {
|
|
2638
2720
|
// Check if there's a valid assistant usage after the compaction boundary
|
|
2639
|
-
const compactionIndex = branchEntries.lastIndexOf(
|
|
2721
|
+
const compactionIndex = branchEntries.lastIndexOf(latestCompactionBoundary);
|
|
2640
2722
|
let hasPostCompactionUsage = false;
|
|
2641
2723
|
for (let i = branchEntries.length - 1; i > compactionIndex; i--) {
|
|
2642
2724
|
const entry = branchEntries[i];
|