@bastani/atomic 0.8.25 → 0.8.26-alpha.10
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 +84 -0
- package/README.md +5 -5
- package/dist/builtin/intercom/CHANGELOG.md +60 -0
- package/dist/builtin/intercom/index-heavy.ts +1754 -0
- package/dist/builtin/intercom/index.ts +374 -1746
- package/dist/builtin/intercom/package.json +2 -2
- package/dist/builtin/intercom/result-renderers.ts +77 -0
- package/dist/builtin/mcp/CHANGELOG.md +64 -0
- package/dist/builtin/mcp/index.ts +151 -57
- package/dist/builtin/mcp/package.json +3 -3
- package/dist/builtin/subagents/CHANGELOG.md +61 -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 +55 -12
- package/dist/builtin/subagents/src/runs/foreground/execution.ts +71 -12
- package/dist/builtin/subagents/src/runs/shared/acceptance.ts +2 -1
- 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/subagents/src/runs/shared/worktree.ts +2 -2
- package/dist/builtin/web-access/CHANGELOG.md +60 -0
- package/dist/builtin/web-access/index-heavy.ts +2060 -0
- package/dist/builtin/web-access/index.ts +182 -2274
- package/dist/builtin/web-access/package.json +2 -2
- package/dist/builtin/web-access/result-renderers.ts +364 -0
- package/dist/builtin/workflows/CHANGELOG.md +75 -0
- package/dist/builtin/workflows/README.md +10 -8
- package/dist/builtin/workflows/builtin/deep-research-codebase.ts +11 -8
- package/dist/builtin/workflows/builtin/goal.ts +137 -109
- package/dist/builtin/workflows/builtin/index.d.ts +2 -0
- package/dist/builtin/workflows/builtin/open-claude-design.ts +228 -151
- package/dist/builtin/workflows/builtin/ralph.d.ts +2 -0
- package/dist/builtin/workflows/builtin/ralph.ts +452 -279
- package/dist/builtin/workflows/package.json +2 -2
- package/dist/builtin/workflows/skills/create-spec/SKILL.md +14 -0
- package/dist/builtin/workflows/skills/research-codebase/SKILL.md +29 -10
- package/dist/builtin/workflows/src/extension/index.ts +23 -5
- package/dist/builtin/workflows/src/extension/runtime.ts +35 -3
- package/dist/builtin/workflows/src/extension/wiring.ts +13 -1
- package/dist/builtin/workflows/src/runs/background/status.ts +52 -6
- package/dist/builtin/workflows/src/runs/foreground/executor.ts +453 -21
- package/dist/builtin/workflows/src/runs/foreground/stage-runner.ts +130 -13
- package/dist/builtin/workflows/src/runs/shared/model-fallback.ts +402 -8
- package/dist/builtin/workflows/src/runs/shared/worktree.ts +2 -2
- package/dist/builtin/workflows/src/shared/authoring-contract.d.ts +2 -2
- 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 +160 -18
- package/dist/builtin/workflows/src/shared/types.ts +3 -3
- package/dist/builtin/workflows/src/shared/workflow-failures.ts +758 -132
- package/dist/builtin/workflows/src/tui/inline-form-overlay.ts +12 -3
- package/dist/builtin/workflows/src/tui/inline-form-store.ts +17 -6
- package/dist/builtin/workflows/src/tui/stage-chat-view.ts +39 -3
- package/dist/builtin/workflows/src/tui/store-widget-installer.ts +74 -74
- package/dist/core/agent-session-services.d.ts.map +1 -1
- package/dist/core/agent-session-services.js +13 -0
- package/dist/core/agent-session-services.js.map +1 -1
- package/dist/core/agent-session.d.ts +33 -6
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +157 -182
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/atomic-guide-command.d.ts.map +1 -1
- package/dist/core/atomic-guide-command.js +11 -9
- package/dist/core/atomic-guide-command.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 +175 -0
- package/dist/core/compaction/context-compaction.d.ts.map +1 -0
- package/dist/core/compaction/context-compaction.js +1636 -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/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +7 -0
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/types.d.ts +16 -3
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/footer-data-provider.d.ts.map +1 -1
- package/dist/core/footer-data-provider.js +3 -0
- package/dist/core/footer-data-provider.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/package-manager.d.ts.map +1 -1
- package/dist/core/package-manager.js +14 -7
- package/dist/core/package-manager.js.map +1 -1
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +17 -0
- package/dist/core/resource-loader.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 -1
- package/dist/core/slash-commands.js.map +1 -1
- package/dist/core/timings.d.ts +9 -0
- package/dist/core/timings.d.ts.map +1 -1
- package/dist/core/timings.js +28 -1
- package/dist/core/timings.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 +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +4 -2
- package/dist/main.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/components/context-compaction-summary-message.d.ts +17 -0
- package/dist/modes/interactive/components/context-compaction-summary-message.d.ts.map +1 -0
- package/dist/modes/interactive/components/context-compaction-summary-message.js +83 -0
- package/dist/modes/interactive/components/context-compaction-summary-message.js.map +1 -0
- package/dist/modes/interactive/components/custom-message.d.ts +1 -0
- package/dist/modes/interactive/components/custom-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/custom-message.js +36 -4
- package/dist/modes/interactive/components/custom-message.js.map +1 -1
- package/dist/modes/interactive/components/footer.d.ts.map +1 -1
- package/dist/modes/interactive/components/footer.js +4 -1
- package/dist/modes/interactive/components/footer.js.map +1 -1
- package/dist/modes/interactive/components/index.d.ts +1 -0
- package/dist/modes/interactive/components/index.d.ts.map +1 -1
- package/dist/modes/interactive/components/index.js +1 -0
- package/dist/modes/interactive/components/index.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 +94 -17
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-client.d.ts +13 -8
- 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 +14 -3
- package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-types.js.map +1 -1
- package/dist/utils/git-env.d.ts +10 -0
- package/dist/utils/git-env.d.ts.map +1 -0
- package/dist/utils/git-env.js +33 -0
- package/dist/utils/git-env.js.map +1 -0
- package/docs/compaction.md +185 -50
- package/docs/custom-provider.md +11 -9
- package/docs/extensions.md +46 -42
- package/docs/index.md +13 -6
- package/docs/json.md +15 -12
- package/docs/packages.md +2 -0
- package/docs/providers.md +4 -1
- package/docs/quickstart.md +18 -11
- package/docs/rpc.md +38 -23
- package/docs/sdk.md +17 -8
- package/docs/session-format.md +26 -13
- package/docs/sessions.md +3 -3
- package/docs/settings.md +2 -2
- 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 -2
- package/docs/workflows.md +60 -16
- package/package.json +6 -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
|
@@ -79,7 +79,7 @@ interface CardComponent {
|
|
|
79
79
|
invalidate?(): void;
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
type RawRenderer = (payload: unknown) =>
|
|
82
|
+
type RawRenderer = (payload: unknown) => CardComponent | null | undefined;
|
|
83
83
|
|
|
84
84
|
/**
|
|
85
85
|
* Wire the message renderer once per live ExtensionAPI host. pi creates a new
|
|
@@ -106,8 +106,11 @@ export function registerInlineFormRenderer(pi: ExtensionAPI, theme: GraphTheme):
|
|
|
106
106
|
if (!formId) return undefined;
|
|
107
107
|
const state = getForm(formId);
|
|
108
108
|
if (!state) {
|
|
109
|
-
//
|
|
110
|
-
|
|
109
|
+
// No backing state — the session was resumed/replaced (the store is
|
|
110
|
+
// cleared on session_start) or the map was evicted. Return null so the
|
|
111
|
+
// host renders nothing: the input widget must not reappear in chat after
|
|
112
|
+
// /resume rather than showing a stale or "snapshot lost" placeholder.
|
|
113
|
+
return null;
|
|
111
114
|
}
|
|
112
115
|
return {
|
|
113
116
|
// The card is fully reactive: read fresh state on every render call,
|
|
@@ -291,11 +294,17 @@ export async function openInlineInputsForm(
|
|
|
291
294
|
display?: boolean;
|
|
292
295
|
details?: FormMessageDetails;
|
|
293
296
|
},
|
|
297
|
+
options?: { excludeFromContext?: boolean },
|
|
294
298
|
) => void).call(pi, {
|
|
295
299
|
customType: CUSTOM_TYPE,
|
|
296
300
|
content: opts.workflowName,
|
|
297
301
|
display: true,
|
|
298
302
|
details: { formId },
|
|
303
|
+
}, {
|
|
304
|
+
// The input form is a transient UI surface, not conversation. Keep it
|
|
305
|
+
// out of LLM context so spawning the picker and exiting without
|
|
306
|
+
// running the workflow never leaks the form into the model.
|
|
307
|
+
excludeFromContext: true,
|
|
299
308
|
});
|
|
300
309
|
} catch {
|
|
301
310
|
activeEditor?.dispose?.();
|
|
@@ -12,11 +12,12 @@
|
|
|
12
12
|
* `finalizeForm(id, "submit")` → status = "submitted", values frozen
|
|
13
13
|
* `finalizeForm(id, "cancel")` → status = "cancelled"
|
|
14
14
|
*
|
|
15
|
-
* After finalize the state stays in the map
|
|
16
|
-
* renderer reads it to display the historical card.
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
15
|
+
* After finalize the state stays in the map for the lifetime of the session.
|
|
16
|
+
* The renderer reads it to display the historical card. On a session boundary
|
|
17
|
+
* (`session_start`: new/resume/fork/reload) the store is cleared via
|
|
18
|
+
* {@link clearForms}, so a rehydrated `workflows:input-form` message has no
|
|
19
|
+
* backing state and its renderer suppresses output (returns null) — the input
|
|
20
|
+
* widget never reappears in chat after `/resume`.
|
|
20
21
|
*
|
|
21
22
|
* Why a global registry instead of closure capture: the message renderer is
|
|
22
23
|
* registered ONCE at factory time and called many times for any number of
|
|
@@ -73,7 +74,17 @@ export function finalizeForm(formId: string, outcome: "submit" | "cancel"): void
|
|
|
73
74
|
touch(s);
|
|
74
75
|
}
|
|
75
76
|
|
|
77
|
+
/**
|
|
78
|
+
* Clear all inline form state. Called on `session_start` so a resumed or
|
|
79
|
+
* replaced session never renders a stale live form, and so a rehydrated
|
|
80
|
+
* `workflows:input-form` message resolves to no backing state (its renderer
|
|
81
|
+
* then returns null and the host renders nothing).
|
|
82
|
+
*/
|
|
83
|
+
export function clearForms(): void {
|
|
84
|
+
FORMS.clear();
|
|
85
|
+
}
|
|
86
|
+
|
|
76
87
|
/** Test helper — clear the registry between tests. */
|
|
77
88
|
export function _resetForms(): void {
|
|
78
|
-
|
|
89
|
+
clearForms();
|
|
79
90
|
}
|
|
@@ -521,6 +521,7 @@ export class StageChatView implements Component, Focusable {
|
|
|
521
521
|
}
|
|
522
522
|
if (!this.promptState || this.promptState.prompt.id !== prompt.id) {
|
|
523
523
|
this.promptState = createPromptCardState(prompt);
|
|
524
|
+
this._seedPromptTextState(prompt);
|
|
524
525
|
this._resetPromptEditor(prompt);
|
|
525
526
|
this._resetPromptScroll();
|
|
526
527
|
return true;
|
|
@@ -533,19 +534,49 @@ export class StageChatView implements Component, Focusable {
|
|
|
533
534
|
this.promptMaxScroll = 0;
|
|
534
535
|
}
|
|
535
536
|
|
|
537
|
+
private _promptSeedText(prompt: PendingPrompt): string {
|
|
538
|
+
const draft = this.store.getStagePromptDraft(this.runId, this.stageId, prompt.id);
|
|
539
|
+
if (draft !== undefined) return draft;
|
|
540
|
+
return typeof prompt.initial === "string" ? prompt.initial : "";
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
private _seedPromptTextState(prompt: PendingPrompt): void {
|
|
544
|
+
if (prompt.kind !== "input" && prompt.kind !== "editor") return;
|
|
545
|
+
if (!this.promptState || this.promptState.prompt.id !== prompt.id) return;
|
|
546
|
+
const seed = this._promptSeedText(prompt);
|
|
547
|
+
this.promptState.rawText = seed;
|
|
548
|
+
this.promptState.caret = seed.length;
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
private _recordPromptDraft(promptId: string, text: string): void {
|
|
552
|
+
this.store.recordStagePromptDraft(this.runId, this.stageId, promptId, text);
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
private _recordCurrentPromptDraft(): void {
|
|
556
|
+
const state = this.promptState;
|
|
557
|
+
if (!state) return;
|
|
558
|
+
const prompt = state.prompt;
|
|
559
|
+
if (prompt.kind !== "input" && prompt.kind !== "editor") return;
|
|
560
|
+
const text = this.promptEditor && this.promptEditorPromptId === prompt.id
|
|
561
|
+
? this.promptEditor.getText()
|
|
562
|
+
: state.rawText;
|
|
563
|
+
this._recordPromptDraft(prompt.id, text);
|
|
564
|
+
}
|
|
565
|
+
|
|
536
566
|
private _resetPromptEditor(prompt: PendingPrompt): void {
|
|
537
567
|
this._disposePromptEditor();
|
|
538
568
|
if ((prompt.kind !== "input" && prompt.kind !== "editor") || !this.piTui) return;
|
|
539
569
|
const editor = this.piEditorFactory
|
|
540
570
|
? this.piEditorFactory(this.piTui, editorThemeFromGraphTheme(this.theme), this.piKeybindings)
|
|
541
571
|
: new Editor(this.piTui, editorThemeFromGraphTheme(this.theme), { paddingX: 0 });
|
|
542
|
-
editor.setText(
|
|
572
|
+
editor.setText(this.promptState?.prompt.id === prompt.id ? this.promptState.rawText : this._promptSeedText(prompt));
|
|
543
573
|
setEditorPlaceholder(editor, "Type your response…");
|
|
544
574
|
setEditorBorderColor(editor, (text) => hexToAnsi(this.theme.accent) + text + RESET);
|
|
545
575
|
editor.onChange = (text: string) => {
|
|
546
576
|
if (this.promptState?.prompt.id !== prompt.id) return;
|
|
547
577
|
this.promptState.rawText = text;
|
|
548
578
|
this.promptState.caret = text.length;
|
|
579
|
+
this._recordPromptDraft(prompt.id, text);
|
|
549
580
|
this.requestRender?.();
|
|
550
581
|
};
|
|
551
582
|
editor.onSubmit = (text: string) => {
|
|
@@ -634,11 +665,12 @@ export class StageChatView implements Component, Focusable {
|
|
|
634
665
|
const [command, ...rest] = text.trim().split(/\s+/);
|
|
635
666
|
switch (command) {
|
|
636
667
|
case "/compact": {
|
|
668
|
+
if (rest.length > 0) return true;
|
|
637
669
|
const handle = this._liveHandle();
|
|
638
670
|
if (!handle) return false;
|
|
639
671
|
await handle.ensureAttached();
|
|
640
672
|
if (!handle.agentSession) return false;
|
|
641
|
-
await handle.agentSession.compact(
|
|
673
|
+
await handle.agentSession.compact();
|
|
642
674
|
return true;
|
|
643
675
|
}
|
|
644
676
|
case "/quit":
|
|
@@ -1248,11 +1280,14 @@ export class StageChatView implements Component, Focusable {
|
|
|
1248
1280
|
return;
|
|
1249
1281
|
}
|
|
1250
1282
|
const action = handlePromptCardInput(data, state, this._promptKeybindings());
|
|
1283
|
+
const prompt = state.prompt;
|
|
1284
|
+
if (prompt.kind === "input" || prompt.kind === "editor") {
|
|
1285
|
+
this._recordPromptDraft(prompt.id, state.rawText);
|
|
1286
|
+
}
|
|
1251
1287
|
if (action.kind === "noop") {
|
|
1252
1288
|
this.requestRender?.();
|
|
1253
1289
|
return;
|
|
1254
1290
|
}
|
|
1255
|
-
const prompt = state.prompt;
|
|
1256
1291
|
const response = action.kind === "submit"
|
|
1257
1292
|
? action.response
|
|
1258
1293
|
: defaultResponseFor(prompt);
|
|
@@ -1306,6 +1341,7 @@ export class StageChatView implements Component, Focusable {
|
|
|
1306
1341
|
const readOnlyPromptArchive = readOnlyArchive && stage?.promptFootprint !== undefined;
|
|
1307
1342
|
if (matchesKey(data, Key.ctrl("d"))) {
|
|
1308
1343
|
if (!this.promptState && this.chatHost.hasInputText()) return this.chatHost.handleInput(data);
|
|
1344
|
+
this._recordCurrentPromptDraft();
|
|
1309
1345
|
this.onDetach();
|
|
1310
1346
|
return true;
|
|
1311
1347
|
}
|
|
@@ -160,121 +160,125 @@ export function installToolExecutionHooks(pi: LiveWidgetAPI, storeInstance: Stor
|
|
|
160
160
|
const extensionOn = pi.on;
|
|
161
161
|
if (typeof eventBusOn !== "function" && typeof extensionOn !== "function") return;
|
|
162
162
|
|
|
163
|
-
|
|
163
|
+
interface StageScope {
|
|
164
|
+
readonly runId: string;
|
|
165
|
+
readonly stageId: string;
|
|
166
|
+
}
|
|
164
167
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
+
interface ActiveToolCall extends StageScope {
|
|
169
|
+
readonly callId: string;
|
|
170
|
+
readonly name: string;
|
|
171
|
+
readonly startedAt: number;
|
|
172
|
+
}
|
|
168
173
|
|
|
169
|
-
|
|
170
|
-
|
|
174
|
+
const terminalRunStatuses = new Set(["completed", "failed", "killed"]);
|
|
175
|
+
const terminalStageStatuses = new Set(["completed", "failed", "skipped"]);
|
|
176
|
+
const activeToolCalls = new Map<string, ActiveToolCall>();
|
|
171
177
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
178
|
+
function activeCallKey(runId: string, stageId: string, callId: string): string {
|
|
179
|
+
return `${runId}\0${stageId}\0${callId}`;
|
|
180
|
+
}
|
|
175
181
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
if (
|
|
182
|
+
function firstNonEmptyString(...values: readonly unknown[]): string | null {
|
|
183
|
+
for (const value of values) {
|
|
184
|
+
if (typeof value === "string" && value.length > 0) return value;
|
|
179
185
|
}
|
|
180
|
-
|
|
181
186
|
return null;
|
|
182
187
|
}
|
|
183
188
|
|
|
184
|
-
function
|
|
185
|
-
|
|
189
|
+
function resolveExplicitStageScope(payload: ToolExecutionStartPayload): StageScope | null {
|
|
190
|
+
const runId = firstNonEmptyString(payload.runId, payload.run_id);
|
|
191
|
+
const stageId = firstNonEmptyString(payload.stageId, payload.stage_id);
|
|
192
|
+
if (runId === null || stageId === null) return null;
|
|
193
|
+
return { runId, stageId };
|
|
186
194
|
}
|
|
187
195
|
|
|
188
|
-
function
|
|
189
|
-
const
|
|
190
|
-
|
|
191
|
-
const
|
|
196
|
+
function hasLiveStageScope(scope: StageScope, snap: StoreSnapshot): boolean {
|
|
197
|
+
const run = snap.runs.find((candidate) => candidate.id === scope.runId);
|
|
198
|
+
if (!run || run.endedAt !== undefined || terminalRunStatuses.has(run.status)) return false;
|
|
199
|
+
const stage = run.stages.find((candidate) => candidate.id === scope.stageId);
|
|
200
|
+
return stage !== undefined && !terminalStageStatuses.has(stage.status);
|
|
201
|
+
}
|
|
192
202
|
|
|
193
|
-
|
|
194
|
-
|
|
203
|
+
function pruneActiveToolCalls(snap: StoreSnapshot): void {
|
|
204
|
+
for (const [key, call] of activeToolCalls) {
|
|
205
|
+
if (!hasLiveStageScope(call, snap)) activeToolCalls.delete(key);
|
|
195
206
|
}
|
|
196
|
-
|
|
197
|
-
const matches = [...activeAskUserQuestionCalls.values()].filter((entry) => {
|
|
198
|
-
if (entry.callId !== callId) return false;
|
|
199
|
-
if (runId !== undefined && entry.runId !== runId) return false;
|
|
200
|
-
if (stageId !== undefined && entry.stageId !== stageId) return false;
|
|
201
|
-
return true;
|
|
202
|
-
});
|
|
203
|
-
return matches.length === 1 ? matches[0] : undefined;
|
|
204
207
|
}
|
|
205
208
|
|
|
206
|
-
function
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
);
|
|
210
|
-
}
|
|
209
|
+
function activeToolCallForPayload(payload: ToolExecutionStartPayload): { key: string; call: ActiveToolCall } | null {
|
|
210
|
+
const scope = resolveExplicitStageScope(payload);
|
|
211
|
+
if (!scope) return null;
|
|
211
212
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
activeAskUserQuestionCalls.set(activeCallKey(ids.runId, ids.stageId, callId), {
|
|
216
|
-
...ids,
|
|
217
|
-
callId,
|
|
218
|
-
});
|
|
219
|
-
storeInstance.recordStageAwaitingInput(ids.runId, ids.stageId, true, payload.ts);
|
|
213
|
+
const key = activeCallKey(scope.runId, scope.stageId, toolCallId(payload));
|
|
214
|
+
const call = activeToolCalls.get(key);
|
|
215
|
+
return call ? { key, call } : null;
|
|
220
216
|
}
|
|
221
217
|
|
|
222
|
-
|
|
223
|
-
const activeCall = findActiveAskCall(payload);
|
|
224
|
-
const resolvedIds = activeCall ?? ids;
|
|
225
|
-
if (resolvedIds === null || resolvedIds === undefined) return;
|
|
226
|
-
|
|
227
|
-
const shouldClear = activeCall !== undefined || isAskUserQuestionToolName(toolName(payload));
|
|
228
|
-
if (!shouldClear) return;
|
|
229
|
-
|
|
230
|
-
activeAskUserQuestionCalls.delete(activeCallKey(resolvedIds.runId, resolvedIds.stageId, toolCallId(payload)));
|
|
231
|
-
if (!stageHasActiveAskCall(resolvedIds.runId, resolvedIds.stageId)) {
|
|
232
|
-
storeInstance.recordStageAwaitingInput(resolvedIds.runId, resolvedIds.stageId, false);
|
|
233
|
-
}
|
|
234
|
-
}
|
|
218
|
+
storeInstance.subscribe(pruneActiveToolCalls);
|
|
235
219
|
|
|
236
220
|
function recordToolStart(payload: unknown): void {
|
|
237
221
|
if (!isToolExecutionPayload(payload)) return;
|
|
238
222
|
|
|
239
|
-
const
|
|
240
|
-
|
|
223
|
+
const snap = storeInstance.snapshot();
|
|
224
|
+
pruneActiveToolCalls(snap);
|
|
225
|
+
|
|
226
|
+
const scope = resolveExplicitStageScope(payload);
|
|
227
|
+
if (!scope || !hasLiveStageScope(scope, snap)) return;
|
|
241
228
|
|
|
242
|
-
|
|
243
|
-
|
|
229
|
+
const callId = toolCallId(payload);
|
|
230
|
+
const key = activeCallKey(scope.runId, scope.stageId, callId);
|
|
231
|
+
if (activeToolCalls.has(key)) return;
|
|
232
|
+
|
|
233
|
+
const name = toolName(payload);
|
|
234
|
+
const startedAt = payload.ts ?? Date.now();
|
|
235
|
+
activeToolCalls.set(key, { ...scope, callId, name, startedAt });
|
|
236
|
+
storeInstance.recordToolStart(scope.runId, scope.stageId, {
|
|
237
|
+
name,
|
|
244
238
|
input: toolInput(payload),
|
|
245
|
-
startedAt
|
|
239
|
+
startedAt,
|
|
246
240
|
});
|
|
247
|
-
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function recordToolUpdate(payload: unknown): void {
|
|
244
|
+
if (!isToolExecutionPayload(payload)) return;
|
|
245
|
+
|
|
246
|
+
pruneActiveToolCalls(storeInstance.snapshot());
|
|
247
|
+
|
|
248
|
+
if (!activeToolCallForPayload(payload)) return;
|
|
249
|
+
// Updates are attach-only until the store has an explicit update API.
|
|
248
250
|
}
|
|
249
251
|
|
|
250
252
|
function recordToolEnd(payload: unknown): void {
|
|
251
253
|
if (!isToolExecutionPayload(payload)) return;
|
|
252
254
|
|
|
253
|
-
|
|
254
|
-
const ids = activeAskCall ?? resolveIds(payload, false);
|
|
255
|
-
if (!ids) return;
|
|
255
|
+
pruneActiveToolCalls(storeInstance.snapshot());
|
|
256
256
|
|
|
257
|
-
|
|
258
|
-
|
|
257
|
+
const active = activeToolCallForPayload(payload);
|
|
258
|
+
if (!active) return;
|
|
259
|
+
|
|
260
|
+
storeInstance.recordToolEnd(active.call.runId, active.call.stageId, {
|
|
261
|
+
name: active.call.name,
|
|
259
262
|
input: toolInput(payload),
|
|
260
|
-
startedAt:
|
|
263
|
+
startedAt: active.call.startedAt,
|
|
261
264
|
endedAt: payload.endedAt ?? payload.ended_at ?? Date.now(),
|
|
262
265
|
output: payload.output,
|
|
263
266
|
});
|
|
264
|
-
|
|
267
|
+
activeToolCalls.delete(active.key);
|
|
265
268
|
}
|
|
266
269
|
|
|
267
270
|
const safeStart = safelyHandle(recordToolStart);
|
|
271
|
+
const safeUpdate = safelyHandle(recordToolUpdate);
|
|
268
272
|
const safeEnd = safelyHandle(recordToolEnd);
|
|
269
273
|
|
|
270
274
|
if (typeof eventBusOn === "function") {
|
|
271
275
|
eventBusOn.call(pi.events, "tool_execution_start", safeStart);
|
|
272
|
-
eventBusOn.call(pi.events, "tool_execution_update",
|
|
276
|
+
eventBusOn.call(pi.events, "tool_execution_update", safeUpdate);
|
|
273
277
|
eventBusOn.call(pi.events, "tool_execution_end", safeEnd);
|
|
274
278
|
}
|
|
275
279
|
if (typeof extensionOn === "function") {
|
|
276
280
|
extensionOn.call(pi, "tool_execution_start", safeStart);
|
|
277
|
-
extensionOn.call(pi, "tool_execution_update",
|
|
281
|
+
extensionOn.call(pi, "tool_execution_update", safeUpdate);
|
|
278
282
|
extensionOn.call(pi, "tool_execution_end", safeEnd);
|
|
279
283
|
extensionOn.call(pi, "tool_call", safeStart);
|
|
280
284
|
extensionOn.call(pi, "tool_result", safeEnd);
|
|
@@ -306,7 +310,3 @@ function toolCallId(payload: ToolExecutionStartPayload): string {
|
|
|
306
310
|
function toolInput(payload: ToolExecutionStartPayload): Record<string, unknown> | undefined {
|
|
307
311
|
return payload.input ?? payload.args;
|
|
308
312
|
}
|
|
309
|
-
|
|
310
|
-
function isAskUserQuestionToolName(name: string): boolean {
|
|
311
|
-
return name.toLowerCase().replace(/[^a-z0-9]/g, "") === "askuserquestion";
|
|
312
|
-
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-session-services.d.ts","sourceRoot":"","sources":["../../src/core/agent-session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AC/B,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;IACtC,KAAK,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;IACnB,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,YAAY,CAAC,EAAE,KAAK,CAAC;QAAE,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;QAAC,aAAa,CAAC,EAAE,aAAa,CAAA;KAAE,CAAC,CAAC;IAC3E,KAAK,CAAC,EAAE,yBAAyB,CAAC,OAAO,CAAC,CAAC;IAC3C,aAAa,CAAC,EAAE,yBAAyB,CAAC,eAAe,CAAC,CAAC;IAC3D,OAAO,CAAC,EAAE,yBAAyB,CAAC,SAAS,CAAC,CAAC;IAC/C,WAAW,CAAC,EAAE,cAAc,EAAE,CAAC;CAC/B;AAED;;;;;GAKG;AACH,MAAM,WAAW,oBAAoB;IACpC,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,WAAW,CAAC;IACzB,eAAe,EAAE,eAAe,CAAC;IACjC,aAAa,EAAE,aAAa,CAAC;IAC7B,cAAc,EAAE,cAAc,CAAC;IAC/B,WAAW,EAAE,6BAA6B,EAAE,CAAC;CAC7C;AAkDD;;;;GAIG;AACH,wBAAsB,0BAA0B,CAC/C,OAAO,EAAE,iCAAiC,GACxC,OAAO,CAAC,oBAAoB,CAAC,CAuC/B;AAED;;;;;;GAMG;AACH,wBAAsB,8BAA8B,CACnD,OAAO,EAAE,qCAAqC,GAC5C,OAAO,CAAC,wBAAwB,CAAC,CAkBnC","sourcesContent":["import { join } from \"node:path\";\nimport type { ThinkingLevel } from \"@earendil-works/pi-agent-core\";\nimport type { Api, Model } from \"@earendil-works/pi-ai\";\nimport { getAgentDir } from \"../config.ts\";\nimport { resolvePath } from \"../utils/paths.ts\";\nimport { AuthStorage } from \"./auth-storage.ts\";\nimport type { SessionStartEvent, ToolDefinition } from \"./extensions/index.ts\";\nimport { ModelRegistry } from \"./model-registry.ts\";\nimport { DefaultResourceLoader, type DefaultResourceLoaderOptions, type ResourceLoader } from \"./resource-loader.ts\";\nimport { type CreateAgentSessionOptions, type CreateAgentSessionResult, createAgentSession } from \"./sdk.ts\";\nimport type { SessionManager } from \"./session-manager.ts\";\nimport { SettingsManager } from \"./settings-manager.ts\";\n\n/**\n * Non-fatal issues collected while creating services or sessions.\n *\n * Runtime creation returns diagnostics to the caller instead of printing or\n * exiting. The app layer decides whether warnings should be shown and whether\n * errors should abort startup.\n */\nexport interface AgentSessionRuntimeDiagnostic {\n\ttype: \"info\" | \"warning\" | \"error\";\n\tmessage: string;\n}\n\n/**\n * Inputs for creating cwd-bound runtime services.\n *\n * These services are recreated whenever the effective session cwd changes.\n * CLI-provided resource paths should be resolved to absolute paths before they\n * reach this function, so later cwd switches do not reinterpret them.\n */\nexport interface CreateAgentSessionServicesOptions {\n\tcwd: string;\n\tagentDir?: string;\n\tauthStorage?: AuthStorage;\n\tsettingsManager?: SettingsManager;\n\tmodelRegistry?: ModelRegistry;\n\textensionFlagValues?: Map<string, boolean | string>;\n\tresourceLoaderOptions?: Omit<DefaultResourceLoaderOptions, \"cwd\" | \"agentDir\" | \"settingsManager\">;\n}\n\n/**\n * Inputs for creating an AgentSession from already-created services.\n *\n * Use this after services exist and any cwd-bound model/tool/session options\n * have been resolved against those services.\n */\nexport interface CreateAgentSessionFromServicesOptions {\n\tservices: AgentSessionServices;\n\tsessionManager: SessionManager;\n\tsessionStartEvent?: SessionStartEvent;\n\tmodel?: Model<Api>;\n\tthinkingLevel?: ThinkingLevel;\n\tscopedModels?: Array<{ model: Model<Api>; thinkingLevel?: ThinkingLevel }>;\n\ttools?: CreateAgentSessionOptions[\"tools\"];\n\texcludedTools?: CreateAgentSessionOptions[\"excludedTools\"];\n\tnoTools?: CreateAgentSessionOptions[\"noTools\"];\n\tcustomTools?: ToolDefinition[];\n}\n\n/**\n * Coherent cwd-bound runtime services for one effective session cwd.\n *\n * This is infrastructure only. The AgentSession itself is created separately so\n * session options can be resolved against these services first.\n */\nexport interface AgentSessionServices {\n\tcwd: string;\n\tagentDir: string;\n\tauthStorage: AuthStorage;\n\tsettingsManager: SettingsManager;\n\tmodelRegistry: ModelRegistry;\n\tresourceLoader: ResourceLoader;\n\tdiagnostics: AgentSessionRuntimeDiagnostic[];\n}\n\nfunction applyExtensionFlagValues(\n\tresourceLoader: ResourceLoader,\n\textensionFlagValues: Map<string, boolean | string> | undefined,\n): AgentSessionRuntimeDiagnostic[] {\n\tif (!extensionFlagValues) {\n\t\treturn [];\n\t}\n\n\tconst diagnostics: AgentSessionRuntimeDiagnostic[] = [];\n\tconst extensionsResult = resourceLoader.getExtensions();\n\tconst registeredFlags = new Map<string, { type: \"boolean\" | \"string\" }>();\n\tfor (const extension of extensionsResult.extensions) {\n\t\tfor (const [name, flag] of extension.flags) {\n\t\t\tregisteredFlags.set(name, { type: flag.type });\n\t\t}\n\t}\n\n\tconst unknownFlags: string[] = [];\n\tfor (const [name, value] of extensionFlagValues) {\n\t\tconst flag = registeredFlags.get(name);\n\t\tif (!flag) {\n\t\t\tunknownFlags.push(name);\n\t\t\tcontinue;\n\t\t}\n\t\tif (flag.type === \"boolean\") {\n\t\t\textensionsResult.runtime.flagValues.set(name, true);\n\t\t\tcontinue;\n\t\t}\n\t\tif (typeof value === \"string\") {\n\t\t\textensionsResult.runtime.flagValues.set(name, value);\n\t\t\tcontinue;\n\t\t}\n\t\tdiagnostics.push({\n\t\t\ttype: \"error\",\n\t\t\tmessage: `Extension flag \"--${name}\" requires a value`,\n\t\t});\n\t}\n\n\tif (unknownFlags.length > 0) {\n\t\tdiagnostics.push({\n\t\t\ttype: \"error\",\n\t\t\tmessage: `Unknown option${unknownFlags.length === 1 ? \"\" : \"s\"}: ${unknownFlags.map((name) => `--${name}`).join(\", \")}`,\n\t\t});\n\t}\n\n\treturn diagnostics;\n}\n\n/**\n * Create cwd-bound runtime services.\n *\n * Returns services plus diagnostics. It does not create an AgentSession.\n */\nexport async function createAgentSessionServices(\n\toptions: CreateAgentSessionServicesOptions,\n): Promise<AgentSessionServices> {\n\tconst cwd = resolvePath(options.cwd);\n\tconst agentDir = options.agentDir ? resolvePath(options.agentDir) : getAgentDir();\n\tconst authStorage = options.authStorage ?? AuthStorage.create(join(agentDir, \"auth.json\"));\n\tconst settingsManager = options.settingsManager ?? SettingsManager.create(cwd, agentDir);\n\tconst modelRegistry = options.modelRegistry ?? ModelRegistry.create(authStorage, join(agentDir, \"models.json\"));\n\tconst resourceLoader = new DefaultResourceLoader({\n\t\t...(options.resourceLoaderOptions ?? {}),\n\t\tcwd,\n\t\tagentDir,\n\t\tsettingsManager,\n\t});\n\tawait resourceLoader.reload();\n\n\tconst diagnostics: AgentSessionRuntimeDiagnostic[] = [];\n\tconst extensionsResult = resourceLoader.getExtensions();\n\tfor (const { name, config, extensionPath } of extensionsResult.runtime.pendingProviderRegistrations) {\n\t\ttry {\n\t\t\tmodelRegistry.registerProvider(name, config);\n\t\t} catch (error) {\n\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\tdiagnostics.push({\n\t\t\t\ttype: \"error\",\n\t\t\t\tmessage: `Extension \"${extensionPath}\" error: ${message}`,\n\t\t\t});\n\t\t}\n\t}\n\textensionsResult.runtime.pendingProviderRegistrations = [];\n\tdiagnostics.push(...applyExtensionFlagValues(resourceLoader, options.extensionFlagValues));\n\n\treturn {\n\t\tcwd,\n\t\tagentDir,\n\t\tauthStorage,\n\t\tsettingsManager,\n\t\tmodelRegistry,\n\t\tresourceLoader,\n\t\tdiagnostics,\n\t};\n}\n\n/**\n * Create an AgentSession from previously created services.\n *\n * This keeps session creation separate from service creation so callers can\n * resolve model, thinking, tools, and other session inputs against the target\n * cwd before constructing the session.\n */\nexport async function createAgentSessionFromServices(\n\toptions: CreateAgentSessionFromServicesOptions,\n): Promise<CreateAgentSessionResult> {\n\treturn createAgentSession({\n\t\tcwd: options.services.cwd,\n\t\tagentDir: options.services.agentDir,\n\t\tauthStorage: options.services.authStorage,\n\t\tsettingsManager: options.services.settingsManager,\n\t\tmodelRegistry: options.services.modelRegistry,\n\t\tresourceLoader: options.services.resourceLoader,\n\t\tsessionManager: options.sessionManager,\n\t\tmodel: options.model,\n\t\tthinkingLevel: options.thinkingLevel,\n\t\tscopedModels: options.scopedModels,\n\t\ttools: options.tools,\n\t\texcludedTools: options.excludedTools,\n\t\tnoTools: options.noTools,\n\t\tcustomTools: options.customTools,\n\t\tsessionStartEvent: options.sessionStartEvent,\n\t});\n}\n"]}
|
|
1
|
+
{"version":3,"file":"agent-session-services.d.ts","sourceRoot":"","sources":["../../src/core/agent-session-services.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAGxD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,KAAK,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC/E,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAyB,KAAK,4BAA4B,EAAE,KAAK,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACrH,OAAO,EAAE,KAAK,yBAAyB,EAAE,KAAK,wBAAwB,EAAsB,MAAM,UAAU,CAAC;AAC7G,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAGxD;;;;;;GAMG;AACH,MAAM,WAAW,6BAA6B;IAC7C,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC;IACnC,OAAO,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,iCAAiC;IACjD,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,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,oBAAoB,CAAC,CAmD/B;AAED;;;;;;GAMG;AACH,wBAAsB,8BAA8B,CACnD,OAAO,EAAE,qCAAqC,GAC5C,OAAO,CAAC,wBAAwB,CAAC,CAkBnC","sourcesContent":["import { join } from \"node:path\";\nimport type { ThinkingLevel } from \"@earendil-works/pi-agent-core\";\nimport type { Api, Model } from \"@earendil-works/pi-ai\";\nimport { getAgentDir } from \"../config.ts\";\nimport { resolvePath } from \"../utils/paths.ts\";\nimport { AuthStorage } from \"./auth-storage.ts\";\nimport type { SessionStartEvent, ToolDefinition } from \"./extensions/index.ts\";\nimport { ModelRegistry } from \"./model-registry.ts\";\nimport { DefaultResourceLoader, type DefaultResourceLoaderOptions, type ResourceLoader } from \"./resource-loader.ts\";\nimport { type CreateAgentSessionOptions, type CreateAgentSessionResult, createAgentSession } from \"./sdk.ts\";\nimport type { SessionManager } from \"./session-manager.ts\";\nimport { SettingsManager } from \"./settings-manager.ts\";\nimport { endTimingSpan, startTimingSpan } from \"./timings.ts\";\n\n/**\n * Non-fatal issues collected while creating services or sessions.\n *\n * Runtime creation returns diagnostics to the caller instead of printing or\n * exiting. The app layer decides whether warnings should be shown and whether\n * errors should abort startup.\n */\nexport interface AgentSessionRuntimeDiagnostic {\n\ttype: \"info\" | \"warning\" | \"error\";\n\tmessage: string;\n}\n\n/**\n * Inputs for creating cwd-bound runtime services.\n *\n * These services are recreated whenever the effective session cwd changes.\n * CLI-provided resource paths should be resolved to absolute paths before they\n * reach this function, so later cwd switches do not reinterpret them.\n */\nexport interface CreateAgentSessionServicesOptions {\n\tcwd: string;\n\tagentDir?: string;\n\tauthStorage?: AuthStorage;\n\tsettingsManager?: SettingsManager;\n\tmodelRegistry?: ModelRegistry;\n\textensionFlagValues?: Map<string, boolean | string>;\n\tresourceLoaderOptions?: Omit<DefaultResourceLoaderOptions, \"cwd\" | \"agentDir\" | \"settingsManager\">;\n}\n\n/**\n * Inputs for creating an AgentSession from already-created services.\n *\n * Use this after services exist and any cwd-bound model/tool/session options\n * have been resolved against those services.\n */\nexport interface CreateAgentSessionFromServicesOptions {\n\tservices: AgentSessionServices;\n\tsessionManager: SessionManager;\n\tsessionStartEvent?: SessionStartEvent;\n\tmodel?: Model<Api>;\n\tthinkingLevel?: ThinkingLevel;\n\tscopedModels?: Array<{ model: Model<Api>; thinkingLevel?: ThinkingLevel }>;\n\ttools?: CreateAgentSessionOptions[\"tools\"];\n\texcludedTools?: CreateAgentSessionOptions[\"excludedTools\"];\n\tnoTools?: CreateAgentSessionOptions[\"noTools\"];\n\tcustomTools?: ToolDefinition[];\n}\n\n/**\n * Coherent cwd-bound runtime services for one effective session cwd.\n *\n * This is infrastructure only. The AgentSession itself is created separately so\n * session options can be resolved against these services first.\n */\nexport interface AgentSessionServices {\n\tcwd: string;\n\tagentDir: string;\n\tauthStorage: AuthStorage;\n\tsettingsManager: SettingsManager;\n\tmodelRegistry: ModelRegistry;\n\tresourceLoader: ResourceLoader;\n\tdiagnostics: AgentSessionRuntimeDiagnostic[];\n}\n\nfunction applyExtensionFlagValues(\n\tresourceLoader: ResourceLoader,\n\textensionFlagValues: Map<string, boolean | string> | undefined,\n): AgentSessionRuntimeDiagnostic[] {\n\tif (!extensionFlagValues) {\n\t\treturn [];\n\t}\n\n\tconst diagnostics: AgentSessionRuntimeDiagnostic[] = [];\n\tconst extensionsResult = resourceLoader.getExtensions();\n\tconst registeredFlags = new Map<string, { type: \"boolean\" | \"string\" }>();\n\tfor (const extension of extensionsResult.extensions) {\n\t\tfor (const [name, flag] of extension.flags) {\n\t\t\tregisteredFlags.set(name, { type: flag.type });\n\t\t}\n\t}\n\n\tconst unknownFlags: string[] = [];\n\tfor (const [name, value] of extensionFlagValues) {\n\t\tconst flag = registeredFlags.get(name);\n\t\tif (!flag) {\n\t\t\tunknownFlags.push(name);\n\t\t\tcontinue;\n\t\t}\n\t\tif (flag.type === \"boolean\") {\n\t\t\textensionsResult.runtime.flagValues.set(name, true);\n\t\t\tcontinue;\n\t\t}\n\t\tif (typeof value === \"string\") {\n\t\t\textensionsResult.runtime.flagValues.set(name, value);\n\t\t\tcontinue;\n\t\t}\n\t\tdiagnostics.push({\n\t\t\ttype: \"error\",\n\t\t\tmessage: `Extension flag \"--${name}\" requires a value`,\n\t\t});\n\t}\n\n\tif (unknownFlags.length > 0) {\n\t\tdiagnostics.push({\n\t\t\ttype: \"error\",\n\t\t\tmessage: `Unknown option${unknownFlags.length === 1 ? \"\" : \"s\"}: ${unknownFlags.map((name) => `--${name}`).join(\", \")}`,\n\t\t});\n\t}\n\n\treturn diagnostics;\n}\n\n/**\n * Create cwd-bound runtime services.\n *\n * Returns services plus diagnostics. It does not create an AgentSession.\n */\nexport async function createAgentSessionServices(\n\toptions: CreateAgentSessionServicesOptions,\n): Promise<AgentSessionServices> {\n\tconst cwd = resolvePath(options.cwd);\n\tconst agentDir = options.agentDir ? resolvePath(options.agentDir) : getAgentDir();\n\tconst authStorageSpan = startTimingSpan(\"createAgentSessionServices.authStorage\");\n\tconst authStorage = options.authStorage ?? AuthStorage.create(join(agentDir, \"auth.json\"));\n\tendTimingSpan(authStorageSpan);\n\tconst settingsSpan = startTimingSpan(\"createAgentSessionServices.settingsManager\");\n\tconst settingsManager = options.settingsManager ?? SettingsManager.create(cwd, agentDir);\n\tendTimingSpan(settingsSpan);\n\tconst modelRegistrySpan = startTimingSpan(\"createAgentSessionServices.modelRegistry\");\n\tconst modelRegistry = options.modelRegistry ?? ModelRegistry.create(authStorage, join(agentDir, \"models.json\"));\n\tendTimingSpan(modelRegistrySpan);\n\tconst resourceLoader = new DefaultResourceLoader({\n\t\t...(options.resourceLoaderOptions ?? {}),\n\t\tcwd,\n\t\tagentDir,\n\t\tsettingsManager,\n\t});\n\tconst reloadSpan = startTimingSpan(\"createAgentSessionServices.resourceLoader.reload\");\n\tawait resourceLoader.reload();\n\tendTimingSpan(reloadSpan);\n\n\tconst diagnostics: AgentSessionRuntimeDiagnostic[] = [];\n\tconst providerSpan = startTimingSpan(\"createAgentSessionServices.providerRegistrations\");\n\tconst extensionsResult = resourceLoader.getExtensions();\n\tfor (const { name, config, extensionPath } of extensionsResult.runtime.pendingProviderRegistrations) {\n\t\ttry {\n\t\t\tmodelRegistry.registerProvider(name, config);\n\t\t} catch (error) {\n\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\tdiagnostics.push({\n\t\t\t\ttype: \"error\",\n\t\t\t\tmessage: `Extension \"${extensionPath}\" error: ${message}`,\n\t\t\t});\n\t\t}\n\t}\n\textensionsResult.runtime.pendingProviderRegistrations = [];\n\tendTimingSpan(providerSpan);\n\tconst flagSpan = startTimingSpan(\"createAgentSessionServices.extensionFlagValidation\");\n\tdiagnostics.push(...applyExtensionFlagValues(resourceLoader, options.extensionFlagValues));\n\tendTimingSpan(flagSpan);\n\n\treturn {\n\t\tcwd,\n\t\tagentDir,\n\t\tauthStorage,\n\t\tsettingsManager,\n\t\tmodelRegistry,\n\t\tresourceLoader,\n\t\tdiagnostics,\n\t};\n}\n\n/**\n * Create an AgentSession from previously created services.\n *\n * This keeps session creation separate from service creation so callers can\n * resolve model, thinking, tools, and other session inputs against the target\n * cwd before constructing the session.\n */\nexport async function createAgentSessionFromServices(\n\toptions: CreateAgentSessionFromServicesOptions,\n): Promise<CreateAgentSessionResult> {\n\treturn createAgentSession({\n\t\tcwd: options.services.cwd,\n\t\tagentDir: options.services.agentDir,\n\t\tauthStorage: options.services.authStorage,\n\t\tsettingsManager: options.services.settingsManager,\n\t\tmodelRegistry: options.services.modelRegistry,\n\t\tresourceLoader: options.services.resourceLoader,\n\t\tsessionManager: options.sessionManager,\n\t\tmodel: options.model,\n\t\tthinkingLevel: options.thinkingLevel,\n\t\tscopedModels: options.scopedModels,\n\t\ttools: options.tools,\n\t\texcludedTools: options.excludedTools,\n\t\tnoTools: options.noTools,\n\t\tcustomTools: options.customTools,\n\t\tsessionStartEvent: options.sessionStartEvent,\n\t});\n}\n"]}
|
|
@@ -6,6 +6,7 @@ import { ModelRegistry } from "./model-registry.js";
|
|
|
6
6
|
import { DefaultResourceLoader } from "./resource-loader.js";
|
|
7
7
|
import { createAgentSession } from "./sdk.js";
|
|
8
8
|
import { SettingsManager } from "./settings-manager.js";
|
|
9
|
+
import { endTimingSpan, startTimingSpan } from "./timings.js";
|
|
9
10
|
function applyExtensionFlagValues(resourceLoader, extensionFlagValues) {
|
|
10
11
|
if (!extensionFlagValues) {
|
|
11
12
|
return [];
|
|
@@ -54,17 +55,26 @@ function applyExtensionFlagValues(resourceLoader, extensionFlagValues) {
|
|
|
54
55
|
export async function createAgentSessionServices(options) {
|
|
55
56
|
const cwd = resolvePath(options.cwd);
|
|
56
57
|
const agentDir = options.agentDir ? resolvePath(options.agentDir) : getAgentDir();
|
|
58
|
+
const authStorageSpan = startTimingSpan("createAgentSessionServices.authStorage");
|
|
57
59
|
const authStorage = options.authStorage ?? AuthStorage.create(join(agentDir, "auth.json"));
|
|
60
|
+
endTimingSpan(authStorageSpan);
|
|
61
|
+
const settingsSpan = startTimingSpan("createAgentSessionServices.settingsManager");
|
|
58
62
|
const settingsManager = options.settingsManager ?? SettingsManager.create(cwd, agentDir);
|
|
63
|
+
endTimingSpan(settingsSpan);
|
|
64
|
+
const modelRegistrySpan = startTimingSpan("createAgentSessionServices.modelRegistry");
|
|
59
65
|
const modelRegistry = options.modelRegistry ?? ModelRegistry.create(authStorage, join(agentDir, "models.json"));
|
|
66
|
+
endTimingSpan(modelRegistrySpan);
|
|
60
67
|
const resourceLoader = new DefaultResourceLoader({
|
|
61
68
|
...(options.resourceLoaderOptions ?? {}),
|
|
62
69
|
cwd,
|
|
63
70
|
agentDir,
|
|
64
71
|
settingsManager,
|
|
65
72
|
});
|
|
73
|
+
const reloadSpan = startTimingSpan("createAgentSessionServices.resourceLoader.reload");
|
|
66
74
|
await resourceLoader.reload();
|
|
75
|
+
endTimingSpan(reloadSpan);
|
|
67
76
|
const diagnostics = [];
|
|
77
|
+
const providerSpan = startTimingSpan("createAgentSessionServices.providerRegistrations");
|
|
68
78
|
const extensionsResult = resourceLoader.getExtensions();
|
|
69
79
|
for (const { name, config, extensionPath } of extensionsResult.runtime.pendingProviderRegistrations) {
|
|
70
80
|
try {
|
|
@@ -79,7 +89,10 @@ export async function createAgentSessionServices(options) {
|
|
|
79
89
|
}
|
|
80
90
|
}
|
|
81
91
|
extensionsResult.runtime.pendingProviderRegistrations = [];
|
|
92
|
+
endTimingSpan(providerSpan);
|
|
93
|
+
const flagSpan = startTimingSpan("createAgentSessionServices.extensionFlagValidation");
|
|
82
94
|
diagnostics.push(...applyExtensionFlagValues(resourceLoader, options.extensionFlagValues));
|
|
95
|
+
endTimingSpan(flagSpan);
|
|
83
96
|
return {
|
|
84
97
|
cwd,
|
|
85
98
|
agentDir,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-session-services.js","sourceRoot":"","sources":["../../src/core/agent-session-services.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAGjC,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,qBAAqB,EAA0D,MAAM,sBAAsB,CAAC;AACrH,OAAO,EAAiE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAE7G,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAkExD,SAAS,wBAAwB,CAChC,cAA8B,EAC9B,mBAA8D;IAE9D,IAAI,CAAC,mBAAmB,EAAE,CAAC;QAC1B,OAAO,EAAE,CAAC;IACX,CAAC;IAED,MAAM,WAAW,GAAoC,EAAE,CAAC;IACxD,MAAM,gBAAgB,GAAG,cAAc,CAAC,aAAa,EAAE,CAAC;IACxD,MAAM,eAAe,GAAG,IAAI,GAAG,EAA0C,CAA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C,aAAa;QACpC,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,WAAW,EAAE,OAAO,CAAC,WAAW;QAChC,iBAAiB,EAAE,OAAO,CAAC,iBAAiB;KAC5C,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { join } from \"node:path\";\nimport type { ThinkingLevel } from \"@earendil-works/pi-agent-core\";\nimport type { Api, Model } from \"@earendil-works/pi-ai\";\nimport { getAgentDir } from \"../config.ts\";\nimport { resolvePath } from \"../utils/paths.ts\";\nimport { AuthStorage } from \"./auth-storage.ts\";\nimport type { SessionStartEvent, ToolDefinition } from \"./extensions/index.ts\";\nimport { ModelRegistry } from \"./model-registry.ts\";\nimport { DefaultResourceLoader, type DefaultResourceLoaderOptions, type ResourceLoader } from \"./resource-loader.ts\";\nimport { type CreateAgentSessionOptions, type CreateAgentSessionResult, createAgentSession } from \"./sdk.ts\";\nimport type { SessionManager } from \"./session-manager.ts\";\nimport { SettingsManager } from \"./settings-manager.ts\";\n\n/**\n * Non-fatal issues collected while creating services or sessions.\n *\n * Runtime creation returns diagnostics to the caller instead of printing or\n * exiting. The app layer decides whether warnings should be shown and whether\n * errors should abort startup.\n */\nexport interface AgentSessionRuntimeDiagnostic {\n\ttype: \"info\" | \"warning\" | \"error\";\n\tmessage: string;\n}\n\n/**\n * Inputs for creating cwd-bound runtime services.\n *\n * These services are recreated whenever the effective session cwd changes.\n * CLI-provided resource paths should be resolved to absolute paths before they\n * reach this function, so later cwd switches do not reinterpret them.\n */\nexport interface CreateAgentSessionServicesOptions {\n\tcwd: string;\n\tagentDir?: string;\n\tauthStorage?: AuthStorage;\n\tsettingsManager?: SettingsManager;\n\tmodelRegistry?: ModelRegistry;\n\textensionFlagValues?: Map<string, boolean | string>;\n\tresourceLoaderOptions?: Omit<DefaultResourceLoaderOptions, \"cwd\" | \"agentDir\" | \"settingsManager\">;\n}\n\n/**\n * Inputs for creating an AgentSession from already-created services.\n *\n * Use this after services exist and any cwd-bound model/tool/session options\n * have been resolved against those services.\n */\nexport interface CreateAgentSessionFromServicesOptions {\n\tservices: AgentSessionServices;\n\tsessionManager: SessionManager;\n\tsessionStartEvent?: SessionStartEvent;\n\tmodel?: Model<Api>;\n\tthinkingLevel?: ThinkingLevel;\n\tscopedModels?: Array<{ model: Model<Api>; thinkingLevel?: ThinkingLevel }>;\n\ttools?: CreateAgentSessionOptions[\"tools\"];\n\texcludedTools?: CreateAgentSessionOptions[\"excludedTools\"];\n\tnoTools?: CreateAgentSessionOptions[\"noTools\"];\n\tcustomTools?: ToolDefinition[];\n}\n\n/**\n * Coherent cwd-bound runtime services for one effective session cwd.\n *\n * This is infrastructure only. The AgentSession itself is created separately so\n * session options can be resolved against these services first.\n */\nexport interface AgentSessionServices {\n\tcwd: string;\n\tagentDir: string;\n\tauthStorage: AuthStorage;\n\tsettingsManager: SettingsManager;\n\tmodelRegistry: ModelRegistry;\n\tresourceLoader: ResourceLoader;\n\tdiagnostics: AgentSessionRuntimeDiagnostic[];\n}\n\nfunction applyExtensionFlagValues(\n\tresourceLoader: ResourceLoader,\n\textensionFlagValues: Map<string, boolean | string> | undefined,\n): AgentSessionRuntimeDiagnostic[] {\n\tif (!extensionFlagValues) {\n\t\treturn [];\n\t}\n\n\tconst diagnostics: AgentSessionRuntimeDiagnostic[] = [];\n\tconst extensionsResult = resourceLoader.getExtensions();\n\tconst registeredFlags = new Map<string, { type: \"boolean\" | \"string\" }>();\n\tfor (const extension of extensionsResult.extensions) {\n\t\tfor (const [name, flag] of extension.flags) {\n\t\t\tregisteredFlags.set(name, { type: flag.type });\n\t\t}\n\t}\n\n\tconst unknownFlags: string[] = [];\n\tfor (const [name, value] of extensionFlagValues) {\n\t\tconst flag = registeredFlags.get(name);\n\t\tif (!flag) {\n\t\t\tunknownFlags.push(name);\n\t\t\tcontinue;\n\t\t}\n\t\tif (flag.type === \"boolean\") {\n\t\t\textensionsResult.runtime.flagValues.set(name, true);\n\t\t\tcontinue;\n\t\t}\n\t\tif (typeof value === \"string\") {\n\t\t\textensionsResult.runtime.flagValues.set(name, value);\n\t\t\tcontinue;\n\t\t}\n\t\tdiagnostics.push({\n\t\t\ttype: \"error\",\n\t\t\tmessage: `Extension flag \"--${name}\" requires a value`,\n\t\t});\n\t}\n\n\tif (unknownFlags.length > 0) {\n\t\tdiagnostics.push({\n\t\t\ttype: \"error\",\n\t\t\tmessage: `Unknown option${unknownFlags.length === 1 ? \"\" : \"s\"}: ${unknownFlags.map((name) => `--${name}`).join(\", \")}`,\n\t\t});\n\t}\n\n\treturn diagnostics;\n}\n\n/**\n * Create cwd-bound runtime services.\n *\n * Returns services plus diagnostics. It does not create an AgentSession.\n */\nexport async function createAgentSessionServices(\n\toptions: CreateAgentSessionServicesOptions,\n): Promise<AgentSessionServices> {\n\tconst cwd = resolvePath(options.cwd);\n\tconst agentDir = options.agentDir ? resolvePath(options.agentDir) : getAgentDir();\n\tconst authStorage = options.authStorage ?? AuthStorage.create(join(agentDir, \"auth.json\"));\n\tconst settingsManager = options.settingsManager ?? SettingsManager.create(cwd, agentDir);\n\tconst modelRegistry = options.modelRegistry ?? ModelRegistry.create(authStorage, join(agentDir, \"models.json\"));\n\tconst resourceLoader = new DefaultResourceLoader({\n\t\t...(options.resourceLoaderOptions ?? {}),\n\t\tcwd,\n\t\tagentDir,\n\t\tsettingsManager,\n\t});\n\tawait resourceLoader.reload();\n\n\tconst diagnostics: AgentSessionRuntimeDiagnostic[] = [];\n\tconst extensionsResult = resourceLoader.getExtensions();\n\tfor (const { name, config, extensionPath } of extensionsResult.runtime.pendingProviderRegistrations) {\n\t\ttry {\n\t\t\tmodelRegistry.registerProvider(name, config);\n\t\t} catch (error) {\n\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\tdiagnostics.push({\n\t\t\t\ttype: \"error\",\n\t\t\t\tmessage: `Extension \"${extensionPath}\" error: ${message}`,\n\t\t\t});\n\t\t}\n\t}\n\textensionsResult.runtime.pendingProviderRegistrations = [];\n\tdiagnostics.push(...applyExtensionFlagValues(resourceLoader, options.extensionFlagValues));\n\n\treturn {\n\t\tcwd,\n\t\tagentDir,\n\t\tauthStorage,\n\t\tsettingsManager,\n\t\tmodelRegistry,\n\t\tresourceLoader,\n\t\tdiagnostics,\n\t};\n}\n\n/**\n * Create an AgentSession from previously created services.\n *\n * This keeps session creation separate from service creation so callers can\n * resolve model, thinking, tools, and other session inputs against the target\n * cwd before constructing the session.\n */\nexport async function createAgentSessionFromServices(\n\toptions: CreateAgentSessionFromServicesOptions,\n): Promise<CreateAgentSessionResult> {\n\treturn createAgentSession({\n\t\tcwd: options.services.cwd,\n\t\tagentDir: options.services.agentDir,\n\t\tauthStorage: options.services.authStorage,\n\t\tsettingsManager: options.services.settingsManager,\n\t\tmodelRegistry: options.services.modelRegistry,\n\t\tresourceLoader: options.services.resourceLoader,\n\t\tsessionManager: options.sessionManager,\n\t\tmodel: options.model,\n\t\tthinkingLevel: options.thinkingLevel,\n\t\tscopedModels: options.scopedModels,\n\t\ttools: options.tools,\n\t\texcludedTools: options.excludedTools,\n\t\tnoTools: options.noTools,\n\t\tcustomTools: options.customTools,\n\t\tsessionStartEvent: options.sessionStartEvent,\n\t});\n}\n"]}
|
|
1
|
+
{"version":3,"file":"agent-session-services.js","sourceRoot":"","sources":["../../src/core/agent-session-services.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAGjC,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,qBAAqB,EAA0D,MAAM,sBAAsB,CAAC;AACrH,OAAO,EAAiE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAE7G,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE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AC,oDAAoD,CAAC,CAAC;IACvF,WAAW,CAAC,IAAI,CAAC,GAAG,wBAAwB,CAAC,cAAc,EAAE,OAAO,CAAC,mBAAmB,CAAC,CAAC,CAAC;IAC3F,aAAa,CAAC,QAAQ,CAAC,CAAC;IAExB,OAAO;QACN,GAAG;QACH,QAAQ;QACR,WAAW;QACX,eAAe;QACf,aAAa;QACb,cAAc;QACd,WAAW;KACX,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,8BAA8B,CACnD,OAA8C;IAE9C,OAAO,kBAAkB,CAAC;QACzB,GAAG,EAAE,OAAO,CAAC,QAAQ,CAAC,GAAG;QACzB,QAAQ,EAAE,OAAO,CAAC,QAAQ,CAAC,QAAQ;QACnC,WAAW,EAAE,OAAO,CAAC,QAAQ,CAAC,WAAW;QACzC,eAAe,EAAE,OAAO,CAAC,QAAQ,CAAC,eAAe;QACjD,aAAa,EAAE,OAAO,CAAC,QAAQ,CAAC,aAAa;QAC7C,cAAc,EAAE,OAAO,CAAC,QAAQ,CAAC,cAAc;QAC/C,cAAc,EAAE,OAAO,CAAC,cAAc;QACtC,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,aAAa,EAAE,OAAO,CAAC,aAAa;QACpC,YAAY,EAAE,OAAO,CAAC,YAAY;QAClC,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,aAAa,EAAE,OAAO,CAAC,aAAa;QACpC,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,WAAW,EAAE,OAAO,CAAC,WAAW;QAChC,iBAAiB,EAAE,OAAO,CAAC,iBAAiB;KAC5C,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { join } from \"node:path\";\nimport type { ThinkingLevel } from \"@earendil-works/pi-agent-core\";\nimport type { Api, Model } from \"@earendil-works/pi-ai\";\nimport { getAgentDir } from \"../config.ts\";\nimport { resolvePath } from \"../utils/paths.ts\";\nimport { AuthStorage } from \"./auth-storage.ts\";\nimport type { SessionStartEvent, ToolDefinition } from \"./extensions/index.ts\";\nimport { ModelRegistry } from \"./model-registry.ts\";\nimport { DefaultResourceLoader, type DefaultResourceLoaderOptions, type ResourceLoader } from \"./resource-loader.ts\";\nimport { type CreateAgentSessionOptions, type CreateAgentSessionResult, createAgentSession } from \"./sdk.ts\";\nimport type { SessionManager } from \"./session-manager.ts\";\nimport { SettingsManager } from \"./settings-manager.ts\";\nimport { endTimingSpan, startTimingSpan } from \"./timings.ts\";\n\n/**\n * Non-fatal issues collected while creating services or sessions.\n *\n * Runtime creation returns diagnostics to the caller instead of printing or\n * exiting. The app layer decides whether warnings should be shown and whether\n * errors should abort startup.\n */\nexport interface AgentSessionRuntimeDiagnostic {\n\ttype: \"info\" | \"warning\" | \"error\";\n\tmessage: string;\n}\n\n/**\n * Inputs for creating cwd-bound runtime services.\n *\n * These services are recreated whenever the effective session cwd changes.\n * CLI-provided resource paths should be resolved to absolute paths before they\n * reach this function, so later cwd switches do not reinterpret them.\n */\nexport interface CreateAgentSessionServicesOptions {\n\tcwd: string;\n\tagentDir?: string;\n\tauthStorage?: AuthStorage;\n\tsettingsManager?: SettingsManager;\n\tmodelRegistry?: ModelRegistry;\n\textensionFlagValues?: Map<string, boolean | string>;\n\tresourceLoaderOptions?: Omit<DefaultResourceLoaderOptions, \"cwd\" | \"agentDir\" | \"settingsManager\">;\n}\n\n/**\n * Inputs for creating an AgentSession from already-created services.\n *\n * Use this after services exist and any cwd-bound model/tool/session options\n * have been resolved against those services.\n */\nexport interface CreateAgentSessionFromServicesOptions {\n\tservices: AgentSessionServices;\n\tsessionManager: SessionManager;\n\tsessionStartEvent?: SessionStartEvent;\n\tmodel?: Model<Api>;\n\tthinkingLevel?: ThinkingLevel;\n\tscopedModels?: Array<{ model: Model<Api>; thinkingLevel?: ThinkingLevel }>;\n\ttools?: CreateAgentSessionOptions[\"tools\"];\n\texcludedTools?: CreateAgentSessionOptions[\"excludedTools\"];\n\tnoTools?: CreateAgentSessionOptions[\"noTools\"];\n\tcustomTools?: ToolDefinition[];\n}\n\n/**\n * Coherent cwd-bound runtime services for one effective session cwd.\n *\n * This is infrastructure only. The AgentSession itself is created separately so\n * session options can be resolved against these services first.\n */\nexport interface AgentSessionServices {\n\tcwd: string;\n\tagentDir: string;\n\tauthStorage: AuthStorage;\n\tsettingsManager: SettingsManager;\n\tmodelRegistry: ModelRegistry;\n\tresourceLoader: ResourceLoader;\n\tdiagnostics: AgentSessionRuntimeDiagnostic[];\n}\n\nfunction applyExtensionFlagValues(\n\tresourceLoader: ResourceLoader,\n\textensionFlagValues: Map<string, boolean | string> | undefined,\n): AgentSessionRuntimeDiagnostic[] {\n\tif (!extensionFlagValues) {\n\t\treturn [];\n\t}\n\n\tconst diagnostics: AgentSessionRuntimeDiagnostic[] = [];\n\tconst extensionsResult = resourceLoader.getExtensions();\n\tconst registeredFlags = new Map<string, { type: \"boolean\" | \"string\" }>();\n\tfor (const extension of extensionsResult.extensions) {\n\t\tfor (const [name, flag] of extension.flags) {\n\t\t\tregisteredFlags.set(name, { type: flag.type });\n\t\t}\n\t}\n\n\tconst unknownFlags: string[] = [];\n\tfor (const [name, value] of extensionFlagValues) {\n\t\tconst flag = registeredFlags.get(name);\n\t\tif (!flag) {\n\t\t\tunknownFlags.push(name);\n\t\t\tcontinue;\n\t\t}\n\t\tif (flag.type === \"boolean\") {\n\t\t\textensionsResult.runtime.flagValues.set(name, true);\n\t\t\tcontinue;\n\t\t}\n\t\tif (typeof value === \"string\") {\n\t\t\textensionsResult.runtime.flagValues.set(name, value);\n\t\t\tcontinue;\n\t\t}\n\t\tdiagnostics.push({\n\t\t\ttype: \"error\",\n\t\t\tmessage: `Extension flag \"--${name}\" requires a value`,\n\t\t});\n\t}\n\n\tif (unknownFlags.length > 0) {\n\t\tdiagnostics.push({\n\t\t\ttype: \"error\",\n\t\t\tmessage: `Unknown option${unknownFlags.length === 1 ? \"\" : \"s\"}: ${unknownFlags.map((name) => `--${name}`).join(\", \")}`,\n\t\t});\n\t}\n\n\treturn diagnostics;\n}\n\n/**\n * Create cwd-bound runtime services.\n *\n * Returns services plus diagnostics. It does not create an AgentSession.\n */\nexport async function createAgentSessionServices(\n\toptions: CreateAgentSessionServicesOptions,\n): Promise<AgentSessionServices> {\n\tconst cwd = resolvePath(options.cwd);\n\tconst agentDir = options.agentDir ? resolvePath(options.agentDir) : getAgentDir();\n\tconst authStorageSpan = startTimingSpan(\"createAgentSessionServices.authStorage\");\n\tconst authStorage = options.authStorage ?? AuthStorage.create(join(agentDir, \"auth.json\"));\n\tendTimingSpan(authStorageSpan);\n\tconst settingsSpan = startTimingSpan(\"createAgentSessionServices.settingsManager\");\n\tconst settingsManager = options.settingsManager ?? SettingsManager.create(cwd, agentDir);\n\tendTimingSpan(settingsSpan);\n\tconst modelRegistrySpan = startTimingSpan(\"createAgentSessionServices.modelRegistry\");\n\tconst modelRegistry = options.modelRegistry ?? ModelRegistry.create(authStorage, join(agentDir, \"models.json\"));\n\tendTimingSpan(modelRegistrySpan);\n\tconst resourceLoader = new DefaultResourceLoader({\n\t\t...(options.resourceLoaderOptions ?? {}),\n\t\tcwd,\n\t\tagentDir,\n\t\tsettingsManager,\n\t});\n\tconst reloadSpan = startTimingSpan(\"createAgentSessionServices.resourceLoader.reload\");\n\tawait resourceLoader.reload();\n\tendTimingSpan(reloadSpan);\n\n\tconst diagnostics: AgentSessionRuntimeDiagnostic[] = [];\n\tconst providerSpan = startTimingSpan(\"createAgentSessionServices.providerRegistrations\");\n\tconst extensionsResult = resourceLoader.getExtensions();\n\tfor (const { name, config, extensionPath } of extensionsResult.runtime.pendingProviderRegistrations) {\n\t\ttry {\n\t\t\tmodelRegistry.registerProvider(name, config);\n\t\t} catch (error) {\n\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\tdiagnostics.push({\n\t\t\t\ttype: \"error\",\n\t\t\t\tmessage: `Extension \"${extensionPath}\" error: ${message}`,\n\t\t\t});\n\t\t}\n\t}\n\textensionsResult.runtime.pendingProviderRegistrations = [];\n\tendTimingSpan(providerSpan);\n\tconst flagSpan = startTimingSpan(\"createAgentSessionServices.extensionFlagValidation\");\n\tdiagnostics.push(...applyExtensionFlagValues(resourceLoader, options.extensionFlagValues));\n\tendTimingSpan(flagSpan);\n\n\treturn {\n\t\tcwd,\n\t\tagentDir,\n\t\tauthStorage,\n\t\tsettingsManager,\n\t\tmodelRegistry,\n\t\tresourceLoader,\n\t\tdiagnostics,\n\t};\n}\n\n/**\n * Create an AgentSession from previously created services.\n *\n * This keeps session creation separate from service creation so callers can\n * resolve model, thinking, tools, and other session inputs against the target\n * cwd before constructing the session.\n */\nexport async function createAgentSessionFromServices(\n\toptions: CreateAgentSessionFromServicesOptions,\n): Promise<CreateAgentSessionResult> {\n\treturn createAgentSession({\n\t\tcwd: options.services.cwd,\n\t\tagentDir: options.services.agentDir,\n\t\tauthStorage: options.services.authStorage,\n\t\tsettingsManager: options.services.settingsManager,\n\t\tmodelRegistry: options.services.modelRegistry,\n\t\tresourceLoader: options.services.resourceLoader,\n\t\tsessionManager: options.sessionManager,\n\t\tmodel: options.model,\n\t\tthinkingLevel: options.thinkingLevel,\n\t\tscopedModels: options.scopedModels,\n\t\ttools: options.tools,\n\t\texcludedTools: options.excludedTools,\n\t\tnoTools: options.noTools,\n\t\tcustomTools: options.customTools,\n\t\tsessionStartEvent: options.sessionStartEvent,\n\t});\n}\n"]}
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
import type { Agent, AgentEvent, AgentMessage, AgentState, AgentTool, ThinkingLevel } from "@earendil-works/pi-agent-core";
|
|
16
16
|
import type { Api, ImageContent, Model, TextContent } from "@earendil-works/pi-ai";
|
|
17
17
|
import { type BashResult } from "./bash-executor.ts";
|
|
18
|
-
import { type CompactionResult } from "./compaction/index.ts";
|
|
18
|
+
import { type CompactionResult, type ContextCompactionResult } from "./compaction/index.ts";
|
|
19
19
|
import { type ContextUsage, type ExtensionCommandContextActions, type ExtensionErrorListener, ExtensionRunner, type ExtensionUIContext, type InputSource, type OrchestrationContext, type ReplacedSessionContext, type SendMessageOptions, type SessionStartEvent, type ShutdownHandler, type ToolDefinition, type ToolInfo } from "./extensions/index.ts";
|
|
20
20
|
import type { CustomMessage } from "./messages.ts";
|
|
21
21
|
import type { ModelRegistry } from "./model-registry.ts";
|
|
@@ -44,6 +44,9 @@ export type AgentSessionEvent = AgentEvent | {
|
|
|
44
44
|
} | {
|
|
45
45
|
type: "compaction_start";
|
|
46
46
|
reason: "manual" | "threshold" | "overflow";
|
|
47
|
+
} | {
|
|
48
|
+
type: "context_compaction_start";
|
|
49
|
+
reason: "manual";
|
|
47
50
|
} | {
|
|
48
51
|
type: "session_info_changed";
|
|
49
52
|
name: string | undefined;
|
|
@@ -58,10 +61,17 @@ export type AgentSessionEvent = AgentEvent | {
|
|
|
58
61
|
} | {
|
|
59
62
|
type: "compaction_end";
|
|
60
63
|
reason: "manual" | "threshold" | "overflow";
|
|
61
|
-
result: CompactionResult | undefined;
|
|
64
|
+
result: CompactionResult | ContextCompactionResult | undefined;
|
|
62
65
|
aborted: boolean;
|
|
63
66
|
willRetry: boolean;
|
|
64
67
|
errorMessage?: string;
|
|
68
|
+
} | {
|
|
69
|
+
type: "context_compaction_end";
|
|
70
|
+
reason: "manual";
|
|
71
|
+
result: ContextCompactionResult | undefined;
|
|
72
|
+
aborted: boolean;
|
|
73
|
+
willRetry: false;
|
|
74
|
+
errorMessage?: string;
|
|
65
75
|
} | {
|
|
66
76
|
type: "auto_retry_start";
|
|
67
77
|
attempt: number;
|
|
@@ -473,12 +483,17 @@ export declare class AgentSession {
|
|
|
473
483
|
* Saves to settings.
|
|
474
484
|
*/
|
|
475
485
|
setFollowUpMode(mode: "all" | "one-at-a-time"): void;
|
|
486
|
+
private _applyContextVerbatimCompaction;
|
|
487
|
+
/**
|
|
488
|
+
* Manually compact the session context using deletion-only verbatim context compaction.
|
|
489
|
+
* Aborts current agent operation first. Custom summary instructions are not accepted.
|
|
490
|
+
*/
|
|
491
|
+
compact(customInstructions?: string): Promise<ContextCompactionResult>;
|
|
476
492
|
/**
|
|
477
|
-
* Manually compact the session context.
|
|
478
|
-
*
|
|
479
|
-
* @param customInstructions Optional instructions for the compaction summary
|
|
493
|
+
* Manually compact the session context by applying validated logical deletions.
|
|
494
|
+
* Retained transcript entries/content blocks stay verbatim; no user prompt text is accepted.
|
|
480
495
|
*/
|
|
481
|
-
|
|
496
|
+
contextCompact(): Promise<ContextCompactionResult>;
|
|
482
497
|
/**
|
|
483
498
|
* Cancel in-progress compaction (manual or auto).
|
|
484
499
|
*/
|
|
@@ -488,6 +503,18 @@ export declare class AgentSession {
|
|
|
488
503
|
*/
|
|
489
504
|
abortBranchSummary(): void;
|
|
490
505
|
private _checkCompaction;
|
|
506
|
+
/**
|
|
507
|
+
* Internal: remove the trailing overflow error from retry context if it is still present.
|
|
508
|
+
*/
|
|
509
|
+
private _dropTrailingOverflowAssistantErrorIfPresent;
|
|
510
|
+
/**
|
|
511
|
+
* Internal: schedule a live post-event continuation probe after compaction_end listeners can flush queues.
|
|
512
|
+
*/
|
|
513
|
+
private _schedulePostAutoCompactionContinuationProbe;
|
|
514
|
+
/**
|
|
515
|
+
* Internal: resume generation after successful auto-compaction only when active work remains.
|
|
516
|
+
*/
|
|
517
|
+
private _resumeAfterAutoCompaction;
|
|
491
518
|
private _runAutoCompaction;
|
|
492
519
|
/**
|
|
493
520
|
* Toggle auto-compaction setting.
|