@bastani/atomic 0.8.31-alpha.5 → 0.9.0-alpha.2
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 +28 -1
- package/dist/builtin/cursor/CHANGELOG.md +10 -1
- package/dist/builtin/cursor/package.json +2 -2
- package/dist/builtin/cursor/src/proto/protobuf-codec-json.ts +44 -0
- package/dist/builtin/cursor/src/proto/protobuf-codec-request.ts +271 -0
- package/dist/builtin/cursor/src/proto/protobuf-codec-wire.ts +231 -0
- package/dist/builtin/cursor/src/proto/protobuf-codec.ts +5 -523
- package/dist/builtin/cursor/src/stream.ts +6 -70
- package/dist/builtin/cursor/src/transport-errors.ts +74 -0
- package/dist/builtin/cursor/src/transport-frame.ts +56 -0
- package/dist/builtin/cursor/src/transport-http2.ts +122 -0
- package/dist/builtin/cursor/src/transport-native-client.ts +161 -0
- package/dist/builtin/cursor/src/transport-run-stream.ts +188 -0
- package/dist/builtin/cursor/src/transport-timeouts.ts +87 -0
- package/dist/builtin/cursor/src/transport-types.ts +140 -0
- package/dist/builtin/cursor/src/transport.ts +24 -790
- package/dist/builtin/intercom/CHANGELOG.md +9 -0
- package/dist/builtin/intercom/broker/client.ts +0 -35
- package/dist/builtin/intercom/contact-supervisor-tool.ts +289 -0
- package/dist/builtin/intercom/index-heavy.ts +77 -1336
- package/dist/builtin/intercom/intercom-tool.ts +409 -0
- package/dist/builtin/intercom/intercom-utils.ts +401 -0
- package/dist/builtin/intercom/lifecycle.ts +133 -0
- package/dist/builtin/intercom/overlay.ts +96 -0
- package/dist/builtin/intercom/package.json +2 -2
- package/dist/builtin/intercom/subagent-relay.ts +137 -0
- package/dist/builtin/mcp/CHANGELOG.md +9 -0
- package/dist/builtin/mcp/config-write-utils.ts +104 -0
- package/dist/builtin/mcp/config.ts +4 -180
- package/dist/builtin/mcp/mcp-panel-renderer.ts +243 -0
- package/dist/builtin/mcp/mcp-panel-state.ts +227 -0
- package/dist/builtin/mcp/mcp-panel-types.ts +86 -0
- package/dist/builtin/mcp/mcp-panel.ts +145 -579
- package/dist/builtin/mcp/mcp-setup-panel.ts +4 -81
- package/dist/builtin/mcp/package.json +3 -3
- package/dist/builtin/mcp/proxy-auth.ts +61 -0
- package/dist/builtin/mcp/proxy-call.ts +373 -0
- package/dist/builtin/mcp/proxy-connect.ts +58 -0
- package/dist/builtin/mcp/proxy-info-modes.ts +326 -0
- package/dist/builtin/mcp/proxy-modes.ts +3 -805
- package/dist/builtin/mcp/proxy-types.ts +3 -0
- package/dist/builtin/mcp/ui-server-http.ts +81 -0
- package/dist/builtin/mcp/ui-server.ts +2 -127
- package/dist/builtin/subagents/CHANGELOG.md +9 -0
- package/dist/builtin/subagents/package.json +4 -4
- package/dist/builtin/subagents/src/agents/agent-discovery.ts +127 -0
- package/dist/builtin/subagents/src/agents/agent-loaders.ts +175 -0
- package/dist/builtin/subagents/src/agents/agent-management-helpers.ts +310 -0
- package/dist/builtin/subagents/src/agents/agent-management.ts +3 -309
- package/dist/builtin/subagents/src/agents/agent-overrides.ts +397 -0
- package/dist/builtin/subagents/src/agents/agent-paths.ts +88 -0
- package/dist/builtin/subagents/src/agents/agent-types.ts +136 -0
- package/dist/builtin/subagents/src/agents/agents.ts +22 -895
- package/dist/builtin/subagents/src/agents/skills-paths.ts +333 -0
- package/dist/builtin/subagents/src/agents/skills.ts +3 -326
- package/dist/builtin/subagents/src/extension/index.ts +4 -118
- package/dist/builtin/subagents/src/extension/prompt-guidance.ts +13 -0
- package/dist/builtin/subagents/src/runs/background/async-execution-chain.ts +401 -0
- package/dist/builtin/subagents/src/runs/background/async-execution-common.ts +131 -0
- package/dist/builtin/subagents/src/runs/background/async-execution-single.ts +213 -0
- package/dist/builtin/subagents/src/runs/background/async-execution-types.ts +84 -0
- package/dist/builtin/subagents/src/runs/background/async-execution.ts +13 -795
- package/dist/builtin/subagents/src/runs/background/subagent-runner-dynamic.ts +215 -0
- package/dist/builtin/subagents/src/runs/background/subagent-runner-finalize.ts +136 -0
- package/dist/builtin/subagents/src/runs/background/subagent-runner-output.ts +105 -0
- package/dist/builtin/subagents/src/runs/background/subagent-runner-parallel-helpers.ts +112 -0
- package/dist/builtin/subagents/src/runs/background/subagent-runner-parallel.ts +159 -0
- package/dist/builtin/subagents/src/runs/background/subagent-runner-sequential.ts +127 -0
- package/dist/builtin/subagents/src/runs/background/subagent-runner-state.ts +427 -0
- package/dist/builtin/subagents/src/runs/background/subagent-runner-step.ts +273 -0
- package/dist/builtin/subagents/src/runs/background/subagent-runner-streaming.ts +269 -0
- package/dist/builtin/subagents/src/runs/background/subagent-runner-types.ts +196 -0
- package/dist/builtin/subagents/src/runs/background/subagent-runner-utils.ts +70 -0
- package/dist/builtin/subagents/src/runs/background/subagent-runner.ts +44 -2233
- package/dist/builtin/subagents/src/runs/foreground/chain-clarify-behavior.ts +75 -0
- package/dist/builtin/subagents/src/runs/foreground/chain-clarify-component.ts +202 -0
- package/dist/builtin/subagents/src/runs/foreground/chain-clarify-edit.ts +97 -0
- package/dist/builtin/subagents/src/runs/foreground/chain-clarify-editor.ts +160 -0
- package/dist/builtin/subagents/src/runs/foreground/chain-clarify-frame.ts +72 -0
- package/dist/builtin/subagents/src/runs/foreground/chain-clarify-render-modes.ts +161 -0
- package/dist/builtin/subagents/src/runs/foreground/chain-clarify-render-selectors.ts +203 -0
- package/dist/builtin/subagents/src/runs/foreground/chain-clarify-selectors.ts +234 -0
- package/dist/builtin/subagents/src/runs/foreground/chain-clarify-state.ts +103 -0
- package/dist/builtin/subagents/src/runs/foreground/chain-clarify-types.ts +29 -0
- package/dist/builtin/subagents/src/runs/foreground/chain-clarify.ts +4 -1328
- package/dist/builtin/subagents/src/runs/foreground/chain-execution-clarify.ts +117 -0
- package/dist/builtin/subagents/src/runs/foreground/chain-execution-details.ts +35 -0
- package/dist/builtin/subagents/src/runs/foreground/chain-execution-dynamic-step.ts +194 -0
- package/dist/builtin/subagents/src/runs/foreground/chain-execution-parallel-runner.ts +183 -0
- package/dist/builtin/subagents/src/runs/foreground/chain-execution-parallel-step.ts +185 -0
- package/dist/builtin/subagents/src/runs/foreground/chain-execution-sequential-step.ts +229 -0
- package/dist/builtin/subagents/src/runs/foreground/chain-execution-types.ts +194 -0
- package/dist/builtin/subagents/src/runs/foreground/chain-execution.ts +94 -1043
- package/dist/builtin/subagents/src/runs/foreground/execution-attempt-control.ts +135 -0
- package/dist/builtin/subagents/src/runs/foreground/execution-attempt-finalize.ts +107 -0
- package/dist/builtin/subagents/src/runs/foreground/execution-attempt-types.ts +17 -0
- package/dist/builtin/subagents/src/runs/foreground/execution-attempt.ts +454 -0
- package/dist/builtin/subagents/src/runs/foreground/execution-run-sync.ts +219 -0
- package/dist/builtin/subagents/src/runs/foreground/execution-structured-retries.ts +77 -0
- package/dist/builtin/subagents/src/runs/foreground/execution-updates.ts +34 -0
- package/dist/builtin/subagents/src/runs/foreground/execution-utils.ts +56 -0
- package/dist/builtin/subagents/src/runs/foreground/execution.ts +6 -1082
- package/dist/builtin/subagents/src/runs/foreground/subagent-executor-async.ts +207 -0
- package/dist/builtin/subagents/src/runs/foreground/subagent-executor-chain.ts +140 -0
- package/dist/builtin/subagents/src/runs/foreground/subagent-executor-context.ts +266 -0
- package/dist/builtin/subagents/src/runs/foreground/subagent-executor-input.ts +270 -0
- package/dist/builtin/subagents/src/runs/foreground/subagent-executor-parallel-task.ts +157 -0
- package/dist/builtin/subagents/src/runs/foreground/subagent-executor-parallel.ts +375 -0
- package/dist/builtin/subagents/src/runs/foreground/subagent-executor-resume.ts +463 -0
- package/dist/builtin/subagents/src/runs/foreground/subagent-executor-runtime.ts +17 -0
- package/dist/builtin/subagents/src/runs/foreground/subagent-executor-single.ts +320 -0
- package/dist/builtin/subagents/src/runs/foreground/subagent-executor-status.ts +207 -0
- package/dist/builtin/subagents/src/runs/foreground/subagent-executor-types.ts +121 -0
- package/dist/builtin/subagents/src/runs/foreground/subagent-executor-worktree.ts +113 -0
- package/dist/builtin/subagents/src/runs/foreground/subagent-executor.ts +150 -2522
- package/dist/builtin/subagents/src/runs/shared/model-fallback.ts +0 -16
- package/dist/builtin/subagents/src/runs/shared/nested-events-control.ts +167 -0
- package/dist/builtin/subagents/src/runs/shared/nested-events-core.ts +219 -0
- package/dist/builtin/subagents/src/runs/shared/nested-events-projection.ts +121 -0
- package/dist/builtin/subagents/src/runs/shared/nested-events-registry.ts +289 -0
- package/dist/builtin/subagents/src/runs/shared/nested-events-sanitize.ts +201 -0
- package/dist/builtin/subagents/src/runs/shared/nested-events.ts +50 -935
- package/dist/builtin/subagents/src/runs/shared/worktree.ts +0 -78
- package/dist/builtin/subagents/src/shared/types-async.ts +265 -0
- package/dist/builtin/subagents/src/shared/types-config.ts +125 -0
- package/dist/builtin/subagents/src/shared/types-depth.ts +121 -0
- package/dist/builtin/subagents/src/shared/types-output.ts +63 -0
- package/dist/builtin/subagents/src/shared/types-results.ts +318 -0
- package/dist/builtin/subagents/src/shared/types-runtime.ts +136 -0
- package/dist/builtin/subagents/src/shared/types.ts +10 -975
- package/dist/builtin/subagents/src/slash/slash-commands.ts +0 -12
- package/dist/builtin/subagents/src/tui/render-chain-graph.ts +247 -0
- package/dist/builtin/subagents/src/tui/render-event-formatting.ts +259 -0
- package/dist/builtin/subagents/src/tui/render-layout.ts +120 -0
- package/dist/builtin/subagents/src/tui/render-result-animation.ts +56 -0
- package/dist/builtin/subagents/src/tui/render-result-compact.ts +154 -0
- package/dist/builtin/subagents/src/tui/render-result.ts +390 -0
- package/dist/builtin/subagents/src/tui/render-stable-output.ts +83 -0
- package/dist/builtin/subagents/src/tui/render-status-progress.ts +133 -0
- package/dist/builtin/subagents/src/tui/render-widget-graph.ts +166 -0
- package/dist/builtin/subagents/src/tui/render-widget.ts +273 -0
- package/dist/builtin/subagents/src/tui/render.ts +14 -1801
- package/dist/builtin/web-access/CHANGELOG.md +9 -0
- package/dist/builtin/web-access/content-tools.ts +348 -0
- package/dist/builtin/web-access/curator-page-assets/script-1.ts +400 -0
- package/dist/builtin/web-access/curator-page-assets/script-2.ts +400 -0
- package/dist/builtin/web-access/curator-page-assets/script-3.ts +400 -0
- package/dist/builtin/web-access/curator-page-assets/script-4.ts +400 -0
- package/dist/builtin/web-access/curator-page-assets/script-5.ts +398 -0
- package/dist/builtin/web-access/curator-page-assets/styles-1.ts +394 -0
- package/dist/builtin/web-access/curator-page-assets/styles-2.ts +394 -0
- package/dist/builtin/web-access/curator-page-assets/styles-3.ts +393 -0
- package/dist/builtin/web-access/curator-page.ts +17 -3180
- package/dist/builtin/web-access/curator-server-helpers.ts +115 -0
- package/dist/builtin/web-access/curator-server.ts +2 -113
- package/dist/builtin/web-access/exa-mcp.ts +218 -0
- package/dist/builtin/web-access/exa.ts +2 -207
- package/dist/builtin/web-access/extract-frames.ts +228 -0
- package/dist/builtin/web-access/extract.ts +13 -214
- package/dist/builtin/web-access/github-config.ts +156 -0
- package/dist/builtin/web-access/github-extract.ts +3 -154
- package/dist/builtin/web-access/index-heavy.ts +8 -1904
- package/dist/builtin/web-access/package.json +3 -2
- package/dist/builtin/web-access/web-search-activity.ts +102 -0
- package/dist/builtin/web-access/web-search-browser.ts +116 -0
- package/dist/builtin/web-access/web-search-command.ts +242 -0
- package/dist/builtin/web-access/web-search-config.ts +163 -0
- package/dist/builtin/web-access/web-search-curator.ts +214 -0
- package/dist/builtin/web-access/web-search-features.ts +165 -0
- package/dist/builtin/web-access/web-search-formatting.ts +117 -0
- package/dist/builtin/web-access/web-search-return.ts +136 -0
- package/dist/builtin/web-access/web-search-summary.ts +170 -0
- package/dist/builtin/web-access/web-search-tool.ts +290 -0
- package/dist/builtin/web-access/web-search-types.ts +50 -0
- package/dist/builtin/workflows/CHANGELOG.md +16 -1
- package/dist/builtin/workflows/README.md +189 -122
- package/dist/builtin/workflows/builtin/deep-research-codebase-runner.ts +492 -0
- package/dist/builtin/workflows/builtin/deep-research-codebase-utils.ts +346 -0
- package/dist/builtin/workflows/builtin/deep-research-codebase.ts +36 -849
- package/dist/builtin/workflows/builtin/goal-artifacts.ts +43 -0
- package/dist/builtin/workflows/builtin/goal-ledger.ts +54 -0
- package/dist/builtin/workflows/builtin/goal-prompts.ts +360 -0
- package/dist/builtin/workflows/builtin/goal-reducer.ts +141 -0
- package/dist/builtin/workflows/builtin/goal-reports.ts +56 -0
- package/dist/builtin/workflows/builtin/goal-review.ts +84 -0
- package/dist/builtin/workflows/builtin/goal-runner.ts +336 -0
- package/dist/builtin/workflows/builtin/goal-schemas.ts +60 -0
- package/dist/builtin/workflows/builtin/goal-types.ts +132 -0
- package/dist/builtin/workflows/builtin/goal.ts +40 -1201
- package/dist/builtin/workflows/builtin/index.d.ts +1 -0
- package/dist/builtin/workflows/builtin/open-claude-design-phases.ts +432 -0
- package/dist/builtin/workflows/builtin/open-claude-design-runner.ts +476 -0
- package/dist/builtin/workflows/builtin/open-claude-design-utils.ts +312 -0
- package/dist/builtin/workflows/builtin/open-claude-design.d.ts +1 -0
- package/dist/builtin/workflows/builtin/open-claude-design.ts +47 -1131
- package/dist/builtin/workflows/builtin/ralph-core.ts +408 -0
- package/dist/builtin/workflows/builtin/ralph-models.ts +123 -0
- package/dist/builtin/workflows/builtin/ralph-runner.ts +499 -0
- package/dist/builtin/workflows/builtin/ralph.ts +50 -1019
- package/dist/builtin/workflows/package.json +2 -2
- package/dist/builtin/workflows/skills/impeccable/scripts/detector/detect-antipatterns-browser.js +2 -2
- package/dist/builtin/workflows/skills/impeccable/scripts/detector/engines/regex/detect-text.mjs +2 -2
- package/dist/builtin/workflows/skills/impeccable/scripts/detector/rules/checks.mjs +2 -2
- package/dist/builtin/workflows/skills/impeccable/scripts/detector/shared/page.mjs +8 -1
- package/dist/builtin/workflows/skills/impeccable/scripts/live-accept.mjs +13 -15
- package/dist/builtin/workflows/skills/impeccable/scripts/live-manual-edit-evidence.mjs +2 -2
- package/dist/builtin/workflows/skills/impeccable/scripts/live-server.mjs +9 -0
- package/dist/builtin/workflows/src/authoring/typebox-defaults.d.ts +41 -0
- package/dist/builtin/workflows/src/authoring/typebox-defaults.ts +217 -0
- package/dist/builtin/workflows/src/authoring/workflow.ts +184 -0
- package/dist/builtin/workflows/src/authoring.d.ts +14 -66
- package/dist/builtin/workflows/src/engine/graph-inference.ts +100 -0
- package/dist/builtin/workflows/src/engine/options.ts +40 -0
- package/dist/builtin/workflows/src/engine/primitives/chain.ts +29 -0
- package/dist/builtin/workflows/src/engine/primitives/exit.ts +2 -0
- package/dist/builtin/workflows/src/engine/primitives/parallel.ts +47 -0
- package/dist/builtin/workflows/src/engine/primitives/task.ts +108 -0
- package/dist/builtin/workflows/src/engine/primitives/ui.ts +41 -0
- package/dist/builtin/workflows/src/engine/primitives/workflow.ts +159 -0
- package/dist/builtin/workflows/src/engine/replay.ts +8 -0
- package/dist/builtin/workflows/src/engine/run.ts +356 -0
- package/dist/builtin/workflows/src/engine/runtime.ts +160 -0
- package/dist/builtin/workflows/src/extension/atomic-stage-session.ts +186 -0
- package/dist/builtin/workflows/src/extension/config-file-loader.ts +152 -0
- package/dist/builtin/workflows/src/extension/config-loader.ts +2 -167
- package/dist/builtin/workflows/src/extension/discovery-loaders.ts +115 -0
- package/dist/builtin/workflows/src/extension/discovery.ts +3 -117
- package/dist/builtin/workflows/src/extension/extension-factory.ts +120 -0
- package/dist/builtin/workflows/src/extension/extension-lifecycle.ts +109 -0
- package/dist/builtin/workflows/src/extension/extension-runtime-state.ts +270 -0
- package/dist/builtin/workflows/src/extension/index.ts +42 -4166
- package/dist/builtin/workflows/src/extension/public-types.ts +295 -0
- package/dist/builtin/workflows/src/extension/render-component.ts +14 -0
- package/dist/builtin/workflows/src/extension/runtime-direct.ts +96 -0
- package/dist/builtin/workflows/src/extension/runtime.ts +1 -92
- package/dist/builtin/workflows/src/extension/ui-surface.ts +286 -0
- package/dist/builtin/workflows/src/extension/wiring.ts +6 -475
- package/dist/builtin/workflows/src/extension/workflow-command-completions.ts +111 -0
- package/dist/builtin/workflows/src/extension/workflow-command-registration.ts +213 -0
- package/dist/builtin/workflows/src/extension/workflow-command-surfaces.ts +81 -0
- package/dist/builtin/workflows/src/extension/workflow-command-utils.ts +181 -0
- package/dist/builtin/workflows/src/extension/workflow-module-loader.ts +9 -3
- package/dist/builtin/workflows/src/extension/workflow-policy.ts +15 -0
- package/dist/builtin/workflows/src/extension/workflow-ports.ts +41 -0
- package/dist/builtin/workflows/src/extension/workflow-prompts.ts +23 -0
- package/dist/builtin/workflows/src/extension/workflow-run-control-command.ts +286 -0
- package/dist/builtin/workflows/src/extension/workflow-schema.ts +1 -19
- package/dist/builtin/workflows/src/extension/workflow-stage-results.ts +264 -0
- package/dist/builtin/workflows/src/extension/workflow-targets.ts +181 -0
- package/dist/builtin/workflows/src/extension/workflow-tool-content.ts +175 -0
- package/dist/builtin/workflows/src/extension/workflow-tool-control.ts +205 -0
- package/dist/builtin/workflows/src/extension/workflow-tool-helpers.ts +66 -0
- package/dist/builtin/workflows/src/extension/workflow-tool-inspection.ts +164 -0
- package/dist/builtin/workflows/src/extension/workflow-tool-registration.ts +54 -0
- package/dist/builtin/workflows/src/extension/workflow-tool-send.ts +164 -0
- package/dist/builtin/workflows/src/extension/workflow-tool.ts +102 -0
- package/dist/builtin/workflows/src/index.ts +0 -2
- package/dist/builtin/workflows/src/runs/background/runner.ts +6 -3
- package/dist/builtin/workflows/src/runs/foreground/executor-abort.ts +431 -0
- package/dist/builtin/workflows/src/runs/foreground/executor-child-boundary.ts +232 -0
- package/dist/builtin/workflows/src/runs/foreground/executor-child-helpers.ts +74 -0
- package/dist/builtin/workflows/src/runs/foreground/executor-child-workflow.ts +1 -0
- package/dist/builtin/workflows/src/runs/foreground/executor-continuation.ts +167 -0
- package/dist/builtin/workflows/src/runs/foreground/executor-direct-helpers.ts +450 -0
- package/dist/builtin/workflows/src/runs/foreground/executor-direct.ts +233 -0
- package/dist/builtin/workflows/src/runs/foreground/executor-exit-manager.ts +195 -0
- package/dist/builtin/workflows/src/runs/foreground/executor-hil.ts +368 -0
- package/dist/builtin/workflows/src/runs/foreground/executor-inputs.ts +83 -0
- package/dist/builtin/workflows/src/runs/foreground/executor-lifecycle.ts +441 -0
- package/dist/builtin/workflows/src/runs/foreground/executor-outputs.ts +160 -0
- package/dist/builtin/workflows/src/runs/foreground/executor-prompt-nodes.ts +274 -0
- package/dist/builtin/workflows/src/runs/foreground/executor-run-finalizers.ts +122 -0
- package/dist/builtin/workflows/src/runs/foreground/executor-run.ts +1 -0
- package/dist/builtin/workflows/src/runs/foreground/executor-scheduler.ts +204 -0
- package/dist/builtin/workflows/src/runs/foreground/executor-stage-call.ts +194 -0
- package/dist/builtin/workflows/src/runs/foreground/executor-stage-context.ts +120 -0
- package/dist/builtin/workflows/src/runs/foreground/executor-stage-control.ts +126 -0
- package/dist/builtin/workflows/src/runs/foreground/executor-stage-factory.ts +359 -0
- package/dist/builtin/workflows/src/runs/foreground/executor-stage-replay.ts +135 -0
- package/dist/builtin/workflows/src/runs/foreground/executor-stage-types.ts +61 -0
- package/dist/builtin/workflows/src/runs/foreground/executor-task-context.ts +2 -0
- package/dist/builtin/workflows/src/runs/foreground/executor-task-prompts.ts +293 -0
- package/dist/builtin/workflows/src/runs/foreground/executor-types.ts +109 -0
- package/dist/builtin/workflows/src/runs/foreground/executor.ts +19 -5354
- package/dist/builtin/workflows/src/runs/foreground/stage-runner-context.ts +219 -0
- package/dist/builtin/workflows/src/runs/foreground/stage-runner-controller.ts +500 -0
- package/dist/builtin/workflows/src/runs/foreground/stage-runner-messages.ts +129 -0
- package/dist/builtin/workflows/src/runs/foreground/stage-runner-options.ts +53 -0
- package/dist/builtin/workflows/src/runs/foreground/stage-runner-output.ts +146 -0
- package/dist/builtin/workflows/src/runs/foreground/stage-runner-session.ts +55 -0
- package/dist/builtin/workflows/src/runs/foreground/stage-runner-structured-output.ts +82 -0
- package/dist/builtin/workflows/src/runs/foreground/stage-runner-types.ts +141 -0
- package/dist/builtin/workflows/src/runs/foreground/stage-runner.ts +13 -1355
- package/dist/builtin/workflows/src/runs/shared/graph-inference.ts +2 -100
- package/dist/builtin/workflows/src/runs/shared/model-fallback-candidates.ts +453 -0
- package/dist/builtin/workflows/src/runs/shared/model-fallback-failures.ts +442 -0
- package/dist/builtin/workflows/src/runs/shared/model-fallback.ts +2 -836
- package/dist/builtin/workflows/src/runs/shared/worktree-diff.ts +165 -0
- package/dist/builtin/workflows/src/runs/shared/worktree-git.ts +220 -0
- package/dist/builtin/workflows/src/runs/shared/worktree-setup.ts +335 -0
- package/dist/builtin/workflows/src/runs/shared/worktree-types.ts +92 -0
- package/dist/builtin/workflows/src/runs/shared/worktree.ts +18 -791
- package/dist/builtin/workflows/src/sdk-surface.ts +6 -9
- package/dist/builtin/workflows/src/shared/authoring-contract-stage.d.ts +371 -0
- package/dist/builtin/workflows/src/shared/authoring-contract-stage.ts +439 -0
- package/dist/builtin/workflows/src/shared/authoring-contract-ui.d.ts +206 -0
- package/dist/builtin/workflows/src/shared/authoring-contract-ui.ts +282 -0
- package/dist/builtin/workflows/src/shared/authoring-contract.d.ts +5 -598
- package/dist/builtin/workflows/src/shared/persistence-restore-helpers.ts +428 -0
- package/dist/builtin/workflows/src/shared/persistence-restore.ts +9 -431
- package/dist/builtin/workflows/src/shared/store-factory.ts +16 -0
- package/dist/builtin/workflows/src/shared/store-internal.ts +219 -0
- package/dist/builtin/workflows/src/shared/store-prompt-methods.ts +219 -0
- package/dist/builtin/workflows/src/shared/store-public-types.ts +215 -0
- package/dist/builtin/workflows/src/shared/store-run-methods.ts +223 -0
- package/dist/builtin/workflows/src/shared/store-stage-methods.ts +305 -0
- package/dist/builtin/workflows/src/shared/store.ts +11 -1138
- package/dist/builtin/workflows/src/shared/types.ts +25 -8
- package/dist/builtin/workflows/src/shared/workflow-authoring-types.d.ts +49 -0
- package/dist/builtin/workflows/src/shared/workflow-authoring-types.ts +84 -0
- package/dist/builtin/workflows/src/shared/workflow-failures-classifier.ts +266 -0
- package/dist/builtin/workflows/src/shared/workflow-failures-contract.ts +75 -0
- package/dist/builtin/workflows/src/shared/workflow-failures-decisions.ts +477 -0
- package/dist/builtin/workflows/src/shared/workflow-failures-signals.ts +248 -0
- package/dist/builtin/workflows/src/shared/workflow-failures.ts +13 -1001
- package/dist/builtin/workflows/src/tui/chat-surface.ts +0 -66
- package/dist/builtin/workflows/src/tui/graph-view-constants.ts +45 -0
- package/dist/builtin/workflows/src/tui/graph-view-graph-render.ts +161 -0
- package/dist/builtin/workflows/src/tui/graph-view-input.ts +333 -0
- package/dist/builtin/workflows/src/tui/graph-view-render-helpers.ts +336 -0
- package/dist/builtin/workflows/src/tui/graph-view-render.ts +194 -0
- package/dist/builtin/workflows/src/tui/graph-view-state.ts +306 -0
- package/dist/builtin/workflows/src/tui/graph-view-types.ts +70 -0
- package/dist/builtin/workflows/src/tui/graph-view.ts +4 -1386
- package/dist/builtin/workflows/src/tui/inline-form-editor-text.ts +121 -0
- package/dist/builtin/workflows/src/tui/inline-form-editor.ts +11 -223
- package/dist/builtin/workflows/src/tui/inputs-picker-editing.ts +151 -0
- package/dist/builtin/workflows/src/tui/inputs-picker-input.ts +305 -0
- package/dist/builtin/workflows/src/tui/inputs-picker-render.ts +300 -0
- package/dist/builtin/workflows/src/tui/inputs-picker-types.ts +190 -0
- package/dist/builtin/workflows/src/tui/inputs-picker.ts +19 -997
- package/dist/builtin/workflows/src/tui/prompt-card-input.ts +226 -0
- package/dist/builtin/workflows/src/tui/prompt-card-render.ts +373 -0
- package/dist/builtin/workflows/src/tui/prompt-card-select.ts +116 -0
- package/dist/builtin/workflows/src/tui/prompt-card-state.ts +61 -0
- package/dist/builtin/workflows/src/tui/prompt-card-text.ts +129 -0
- package/dist/builtin/workflows/src/tui/prompt-card.ts +8 -910
- package/dist/builtin/workflows/src/tui/stage-chat-view-archive-history.ts +315 -0
- package/dist/builtin/workflows/src/tui/stage-chat-view-custom-ui.ts +127 -0
- package/dist/builtin/workflows/src/tui/stage-chat-view-footer-status.ts +187 -0
- package/dist/builtin/workflows/src/tui/stage-chat-view-input.ts +222 -0
- package/dist/builtin/workflows/src/tui/stage-chat-view-render-helpers.ts +152 -0
- package/dist/builtin/workflows/src/tui/stage-chat-view-state.ts +464 -0
- package/dist/builtin/workflows/src/tui/stage-chat-view-transcript.ts +242 -0
- package/dist/builtin/workflows/src/tui/stage-chat-view-types.ts +151 -0
- package/dist/builtin/workflows/src/tui/stage-chat-view.ts +141 -1777
- package/dist/builtin/workflows/src/tui/workflow-attach-pane-types.ts +85 -0
- package/dist/builtin/workflows/src/tui/workflow-attach-pane.ts +1 -129
- package/dist/builtin/workflows/src/workflows/registry.ts +7 -3
- package/dist/config-self-update.d.ts +21 -0
- package/dist/config-self-update.d.ts.map +1 -0
- package/dist/config-self-update.js +265 -0
- package/dist/config-self-update.js.map +1 -0
- package/dist/config.d.ts +3 -12
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +15 -252
- package/dist/config.js.map +1 -1
- package/dist/core/agent-session-accessors.d.ts +3 -0
- package/dist/core/agent-session-accessors.d.ts.map +1 -0
- package/dist/core/agent-session-accessors.js +36 -0
- package/dist/core/agent-session-accessors.js.map +1 -0
- package/dist/core/agent-session-auto-compaction.d.ts +32 -0
- package/dist/core/agent-session-auto-compaction.d.ts.map +1 -0
- package/dist/core/agent-session-auto-compaction.js +219 -0
- package/dist/core/agent-session-auto-compaction.js.map +1 -0
- package/dist/core/agent-session-bash.d.ts +30 -0
- package/dist/core/agent-session-bash.d.ts.map +1 -0
- package/dist/core/agent-session-bash.js +79 -0
- package/dist/core/agent-session-bash.js.map +1 -0
- package/dist/core/agent-session-compaction.d.ts +44 -0
- package/dist/core/agent-session-compaction.d.ts.map +1 -0
- package/dist/core/agent-session-compaction.js +282 -0
- package/dist/core/agent-session-compaction.js.map +1 -0
- package/dist/core/agent-session-events.d.ts +65 -0
- package/dist/core/agent-session-events.d.ts.map +1 -0
- package/dist/core/agent-session-events.js +373 -0
- package/dist/core/agent-session-events.js.map +1 -0
- package/dist/core/agent-session-export.d.ts +42 -0
- package/dist/core/agent-session-export.d.ts.map +1 -0
- package/dist/core/agent-session-export.js +199 -0
- package/dist/core/agent-session-export.js.map +1 -0
- package/dist/core/agent-session-extension-bindings.d.ts +37 -0
- package/dist/core/agent-session-extension-bindings.d.ts.map +1 -0
- package/dist/core/agent-session-extension-bindings.js +231 -0
- package/dist/core/agent-session-extension-bindings.js.map +1 -0
- package/dist/core/agent-session-message-queue.d.ts +85 -0
- package/dist/core/agent-session-message-queue.d.ts.map +1 -0
- package/dist/core/agent-session-message-queue.js +264 -0
- package/dist/core/agent-session-message-queue.js.map +1 -0
- package/dist/core/agent-session-methods.d.ts +300 -0
- package/dist/core/agent-session-methods.d.ts.map +1 -0
- package/dist/core/agent-session-methods.js +2 -0
- package/dist/core/agent-session-methods.js.map +1 -0
- package/dist/core/agent-session-models.d.ts +111 -0
- package/dist/core/agent-session-models.d.ts.map +1 -0
- package/dist/core/agent-session-models.js +368 -0
- package/dist/core/agent-session-models.js.map +1 -0
- package/dist/core/agent-session-prompt.d.ts +61 -0
- package/dist/core/agent-session-prompt.d.ts.map +1 -0
- package/dist/core/agent-session-prompt.js +330 -0
- package/dist/core/agent-session-prompt.js.map +1 -0
- package/dist/core/agent-session-retry.d.ts +62 -0
- package/dist/core/agent-session-retry.d.ts.map +1 -0
- package/dist/core/agent-session-retry.js +202 -0
- package/dist/core/agent-session-retry.js.map +1 -0
- package/dist/core/agent-session-services.d.ts +0 -1
- package/dist/core/agent-session-services.d.ts.map +1 -1
- package/dist/core/agent-session-services.js +0 -1
- package/dist/core/agent-session-services.js.map +1 -1
- package/dist/core/agent-session-skill-block.d.ts +13 -0
- package/dist/core/agent-session-skill-block.d.ts.map +1 -0
- package/dist/core/agent-session-skill-block.js +37 -0
- package/dist/core/agent-session-skill-block.js.map +1 -0
- package/dist/core/agent-session-state.d.ts +48 -0
- package/dist/core/agent-session-state.d.ts.map +1 -0
- package/dist/core/agent-session-state.js +129 -0
- package/dist/core/agent-session-state.js.map +1 -0
- package/dist/core/agent-session-tool-hooks.d.ts +7 -0
- package/dist/core/agent-session-tool-hooks.d.ts.map +1 -0
- package/dist/core/agent-session-tool-hooks.js +72 -0
- package/dist/core/agent-session-tool-hooks.js.map +1 -0
- package/dist/core/agent-session-tool-registry.d.ts +15 -0
- package/dist/core/agent-session-tool-registry.d.ts.map +1 -0
- package/dist/core/agent-session-tool-registry.js +149 -0
- package/dist/core/agent-session-tool-registry.js.map +1 -0
- package/dist/core/agent-session-tree.d.ts +46 -0
- package/dist/core/agent-session-tree.d.ts.map +1 -0
- package/dist/core/agent-session-tree.js +217 -0
- package/dist/core/agent-session-tree.js.map +1 -0
- package/dist/core/agent-session-types.d.ts +157 -0
- package/dist/core/agent-session-types.d.ts.map +1 -0
- package/dist/core/agent-session-types.js +41 -0
- package/dist/core/agent-session-types.js.map +1 -0
- package/dist/core/agent-session.d.ts +66 -688
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +26 -3153
- 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 +1 -1
- package/dist/core/atomic-guide-command.js.map +1 -1
- package/dist/core/auth-storage-backends.d.ts +49 -0
- package/dist/core/auth-storage-backends.d.ts.map +1 -0
- package/dist/core/auth-storage-backends.js +185 -0
- package/dist/core/auth-storage-backends.js.map +1 -0
- package/dist/core/auth-storage.d.ts +2 -49
- package/dist/core/auth-storage.d.ts.map +1 -1
- package/dist/core/auth-storage.js +3 -183
- package/dist/core/auth-storage.js.map +1 -1
- package/dist/core/compaction/context-compaction-metrics.d.ts +16 -0
- package/dist/core/compaction/context-compaction-metrics.d.ts.map +1 -0
- package/dist/core/compaction/context-compaction-metrics.js +58 -0
- package/dist/core/compaction/context-compaction-metrics.js.map +1 -0
- package/dist/core/compaction/context-compaction-prompt.d.ts +9 -0
- package/dist/core/compaction/context-compaction-prompt.d.ts.map +1 -0
- package/dist/core/compaction/context-compaction-prompt.js +161 -0
- package/dist/core/compaction/context-compaction-prompt.js.map +1 -0
- package/dist/core/compaction/context-compaction-runner.d.ts +5 -0
- package/dist/core/compaction/context-compaction-runner.d.ts.map +1 -0
- package/dist/core/compaction/context-compaction-runner.js +181 -0
- package/dist/core/compaction/context-compaction-runner.js.map +1 -0
- package/dist/core/compaction/context-compaction-strategy.d.ts +5 -0
- package/dist/core/compaction/context-compaction-strategy.d.ts.map +1 -0
- package/dist/core/compaction/context-compaction-strategy.js +27 -0
- package/dist/core/compaction/context-compaction-strategy.js.map +1 -0
- package/dist/core/compaction/context-compaction-types.d.ts +73 -0
- package/dist/core/compaction/context-compaction-types.d.ts.map +1 -0
- package/dist/core/compaction/context-compaction-types.js +6 -0
- package/dist/core/compaction/context-compaction-types.js.map +1 -0
- package/dist/core/compaction/context-compaction.d.ts +9 -200
- package/dist/core/compaction/context-compaction.d.ts.map +1 -1
- package/dist/core/compaction/context-compaction.js +7 -1943
- package/dist/core/compaction/context-compaction.js.map +1 -1
- package/dist/core/compaction/context-deletion-application.d.ts +13 -0
- package/dist/core/compaction/context-deletion-application.d.ts.map +1 -0
- package/dist/core/compaction/context-deletion-application.js +259 -0
- package/dist/core/compaction/context-deletion-application.js.map +1 -0
- package/dist/core/compaction/context-deletion-store.d.ts +78 -0
- package/dist/core/compaction/context-deletion-store.d.ts.map +1 -0
- package/dist/core/compaction/context-deletion-store.js +162 -0
- package/dist/core/compaction/context-deletion-store.js.map +1 -0
- package/dist/core/compaction/context-deletion-targets.d.ts +40 -0
- package/dist/core/compaction/context-deletion-targets.d.ts.map +1 -0
- package/dist/core/compaction/context-deletion-targets.js +267 -0
- package/dist/core/compaction/context-deletion-targets.js.map +1 -0
- package/dist/core/compaction/context-deletion-tool-definitions.d.ts +187 -0
- package/dist/core/compaction/context-deletion-tool-definitions.d.ts.map +1 -0
- package/dist/core/compaction/context-deletion-tool-definitions.js +98 -0
- package/dist/core/compaction/context-deletion-tool-definitions.js.map +1 -0
- package/dist/core/compaction/context-deletion-tool-helpers.d.ts +19 -0
- package/dist/core/compaction/context-deletion-tool-helpers.d.ts.map +1 -0
- package/dist/core/compaction/context-deletion-tool-helpers.js +137 -0
- package/dist/core/compaction/context-deletion-tool-helpers.js.map +1 -0
- package/dist/core/compaction/context-deletion-tools.d.ts +4 -0
- package/dist/core/compaction/context-deletion-tools.d.ts.map +1 -0
- package/dist/core/compaction/context-deletion-tools.js +395 -0
- package/dist/core/compaction/context-deletion-tools.js.map +1 -0
- package/dist/core/compaction/context-transcript-analysis.d.ts +9 -0
- package/dist/core/compaction/context-transcript-analysis.d.ts.map +1 -0
- package/dist/core/compaction/context-transcript-analysis.js +234 -0
- package/dist/core/compaction/context-transcript-analysis.js.map +1 -0
- package/dist/core/export-html/index.d.ts.map +1 -1
- package/dist/core/export-html/index.js +2 -1
- package/dist/core/export-html/index.js.map +1 -1
- package/dist/core/export-html/template-js/data-tree.js +287 -0
- package/dist/core/export-html/template-js/entries-navigation.js +424 -0
- package/dist/core/export-html/template-js/initialization.js +312 -0
- package/dist/core/export-html/template-js/message-tools.js +415 -0
- package/dist/core/export-html/template-js/tree-filter-render.js +421 -0
- package/dist/core/export-html/template-script.d.ts +3 -0
- package/dist/core/export-html/template-script.d.ts.map +1 -0
- package/dist/core/export-html/template-script.js +13 -0
- package/dist/core/export-html/template-script.js.map +1 -0
- package/dist/core/export-html/template.js +3 -1
- package/dist/core/extensions/agent-events.d.ts +159 -0
- package/dist/core/extensions/agent-events.d.ts.map +1 -0
- package/dist/core/extensions/agent-events.js +2 -0
- package/dist/core/extensions/agent-events.js.map +1 -0
- package/dist/core/extensions/api-types.d.ts +189 -0
- package/dist/core/extensions/api-types.d.ts.map +1 -0
- package/dist/core/extensions/api-types.js +2 -0
- package/dist/core/extensions/api-types.js.map +1 -0
- package/dist/core/extensions/command-types.d.ts +14 -0
- package/dist/core/extensions/command-types.d.ts.map +1 -0
- package/dist/core/extensions/command-types.js +2 -0
- package/dist/core/extensions/command-types.js.map +1 -0
- package/dist/core/extensions/context-types.d.ts +130 -0
- package/dist/core/extensions/context-types.d.ts.map +1 -0
- package/dist/core/extensions/context-types.js +2 -0
- package/dist/core/extensions/context-types.js.map +1 -0
- package/dist/core/extensions/event-results.d.ts +61 -0
- package/dist/core/extensions/event-results.d.ts.map +1 -0
- package/dist/core/extensions/event-results.js +2 -0
- package/dist/core/extensions/event-results.js.map +1 -0
- package/dist/core/extensions/event-types.d.ts +6 -0
- package/dist/core/extensions/event-types.d.ts.map +1 -0
- package/dist/core/extensions/event-types.js +2 -0
- package/dist/core/extensions/event-types.js.map +1 -0
- package/dist/core/extensions/loader-api.d.ts +10 -0
- package/dist/core/extensions/loader-api.d.ts.map +1 -0
- package/dist/core/extensions/loader-api.js +143 -0
- package/dist/core/extensions/loader-api.js.map +1 -0
- package/dist/core/extensions/loader-core.d.ts +10 -0
- package/dist/core/extensions/loader-core.d.ts.map +1 -0
- package/dist/core/extensions/loader-core.js +98 -0
- package/dist/core/extensions/loader-core.js.map +1 -0
- package/dist/core/extensions/loader-discovery.d.ts +7 -0
- package/dist/core/extensions/loader-discovery.d.ts.map +1 -0
- package/dist/core/extensions/loader-discovery.js +139 -0
- package/dist/core/extensions/loader-discovery.js.map +1 -0
- package/dist/core/extensions/loader-resources.d.ts +11 -0
- package/dist/core/extensions/loader-resources.d.ts.map +1 -0
- package/dist/core/extensions/loader-resources.js +10 -0
- package/dist/core/extensions/loader-resources.js.map +1 -0
- package/dist/core/extensions/loader-runtime.d.ts +7 -0
- package/dist/core/extensions/loader-runtime.d.ts.map +1 -0
- package/dist/core/extensions/loader-runtime.js +51 -0
- package/dist/core/extensions/loader-runtime.js.map +1 -0
- package/dist/core/extensions/loader-virtual-modules.d.ts +9 -0
- package/dist/core/extensions/loader-virtual-modules.d.ts.map +1 -0
- package/dist/core/extensions/loader-virtual-modules.js +124 -0
- package/dist/core/extensions/loader-virtual-modules.js.map +1 -0
- package/dist/core/extensions/loader.d.ts +5 -28
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +4 -542
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/message-types.d.ts +34 -0
- package/dist/core/extensions/message-types.d.ts.map +1 -0
- package/dist/core/extensions/message-types.js +2 -0
- package/dist/core/extensions/message-types.js.map +1 -0
- package/dist/core/extensions/provider-types.d.ts +71 -0
- package/dist/core/extensions/provider-types.d.ts.map +1 -0
- package/dist/core/extensions/provider-types.js +2 -0
- package/dist/core/extensions/provider-types.js.map +1 -0
- package/dist/core/extensions/runner-context.d.ts +42 -0
- package/dist/core/extensions/runner-context.d.ts.map +1 -0
- package/dist/core/extensions/runner-context.js +112 -0
- package/dist/core/extensions/runner-context.js.map +1 -0
- package/dist/core/extensions/runner-events.d.ts +47 -0
- package/dist/core/extensions/runner-events.d.ts.map +1 -0
- package/dist/core/extensions/runner-events.js +280 -0
- package/dist/core/extensions/runner-events.js.map +1 -0
- package/dist/core/extensions/runner-handlers.d.ts +32 -0
- package/dist/core/extensions/runner-handlers.d.ts.map +1 -0
- package/dist/core/extensions/runner-handlers.js +2 -0
- package/dist/core/extensions/runner-handlers.js.map +1 -0
- package/dist/core/extensions/runner-project-trust.d.ts +6 -0
- package/dist/core/extensions/runner-project-trust.d.ts.map +1 -0
- package/dist/core/extensions/runner-project-trust.js +27 -0
- package/dist/core/extensions/runner-project-trust.js.map +1 -0
- package/dist/core/extensions/runner-registries.d.ts +8 -0
- package/dist/core/extensions/runner-registries.d.ts.map +1 -0
- package/dist/core/extensions/runner-registries.js +76 -0
- package/dist/core/extensions/runner-registries.js.map +1 -0
- package/dist/core/extensions/runner-shortcuts.d.ts +10 -0
- package/dist/core/extensions/runner-shortcuts.d.ts.map +1 -0
- package/dist/core/extensions/runner-shortcuts.js +71 -0
- package/dist/core/extensions/runner-shortcuts.js.map +1 -0
- package/dist/core/extensions/runner-ui.d.ts +3 -0
- package/dist/core/extensions/runner-ui.d.ts.map +1 -0
- package/dist/core/extensions/runner-ui.js +50 -0
- package/dist/core/extensions/runner-ui.js.map +1 -0
- package/dist/core/extensions/runner.d.ts +7 -74
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +67 -673
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/runtime-types.d.ts +179 -0
- package/dist/core/extensions/runtime-types.d.ts.map +1 -0
- package/dist/core/extensions/runtime-types.js +2 -0
- package/dist/core/extensions/runtime-types.js.map +1 -0
- package/dist/core/extensions/session-events.d.ts +89 -0
- package/dist/core/extensions/session-events.d.ts.map +1 -0
- package/dist/core/extensions/session-events.js +2 -0
- package/dist/core/extensions/session-events.js.map +1 -0
- package/dist/core/extensions/tool-events.d.ts +127 -0
- package/dist/core/extensions/tool-events.d.ts.map +1 -0
- package/dist/core/extensions/tool-events.js +26 -0
- package/dist/core/extensions/tool-events.js.map +1 -0
- package/dist/core/extensions/tool-types.d.ts +100 -0
- package/dist/core/extensions/tool-types.d.ts.map +1 -0
- package/dist/core/extensions/tool-types.js +11 -0
- package/dist/core/extensions/tool-types.js.map +1 -0
- package/dist/core/extensions/types.d.ts +20 -1288
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js +4 -34
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/extensions/ui-types.d.ts +200 -0
- package/dist/core/extensions/ui-types.d.ts.map +1 -0
- package/dist/core/extensions/ui-types.js +2 -0
- package/dist/core/extensions/ui-types.js.map +1 -0
- package/dist/core/index.d.ts +0 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +0 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/model-registry-auth.d.ts +7 -0
- package/dist/core/model-registry-auth.d.ts.map +1 -0
- package/dist/core/model-registry-auth.js +64 -0
- package/dist/core/model-registry-auth.js.map +1 -0
- package/dist/core/model-registry-builtins.d.ts +9 -0
- package/dist/core/model-registry-builtins.d.ts.map +1 -0
- package/dist/core/model-registry-builtins.js +126 -0
- package/dist/core/model-registry-builtins.js.map +1 -0
- package/dist/core/model-registry-custom-loader.d.ts +3 -0
- package/dist/core/model-registry-custom-loader.d.ts.map +1 -0
- package/dist/core/model-registry-custom-loader.js +213 -0
- package/dist/core/model-registry-custom-loader.js.map +1 -0
- package/dist/core/model-registry-dynamic.d.ts +6 -0
- package/dist/core/model-registry-dynamic.d.ts.map +1 -0
- package/dist/core/model-registry-dynamic.js +155 -0
- package/dist/core/model-registry-dynamic.js.map +1 -0
- package/dist/core/model-registry-loader.d.ts +4 -0
- package/dist/core/model-registry-loader.d.ts.map +1 -0
- package/dist/core/model-registry-loader.js +20 -0
- package/dist/core/model-registry-loader.js.map +1 -0
- package/dist/core/model-registry-schemas.d.ts +1136 -0
- package/dist/core/model-registry-schemas.d.ts.map +1 -0
- package/dist/core/model-registry-schemas.js +171 -0
- package/dist/core/model-registry-schemas.js.map +1 -0
- package/dist/core/model-registry-types.d.ts +74 -0
- package/dist/core/model-registry-types.d.ts.map +1 -0
- package/dist/core/model-registry-types.js +2 -0
- package/dist/core/model-registry-types.js.map +1 -0
- package/dist/core/model-registry.d.ts +3 -76
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +24 -733
- package/dist/core/model-registry.js.map +1 -1
- package/dist/core/model-resolver-cli.d.ts +19 -0
- package/dist/core/model-resolver-cli.d.ts.map +1 -0
- package/dist/core/model-resolver-cli.js +118 -0
- package/dist/core/model-resolver-cli.js.map +1 -0
- package/dist/core/model-resolver-defaults.d.ts +5 -0
- package/dist/core/model-resolver-defaults.d.ts.map +1 -0
- package/dist/core/model-resolver-defaults.js +47 -0
- package/dist/core/model-resolver-defaults.js.map +1 -0
- package/dist/core/model-resolver-initial.d.ts +31 -0
- package/dist/core/model-resolver-initial.d.ts.map +1 -0
- package/dist/core/model-resolver-initial.js +116 -0
- package/dist/core/model-resolver-initial.js.map +1 -0
- package/dist/core/model-resolver-patterns.d.ts +26 -0
- package/dist/core/model-resolver-patterns.d.ts.map +1 -0
- package/dist/core/model-resolver-patterns.js +139 -0
- package/dist/core/model-resolver-patterns.js.map +1 -0
- package/dist/core/model-resolver-scope.d.ts +15 -0
- package/dist/core/model-resolver-scope.d.ts.map +1 -0
- package/dist/core/model-resolver-scope.js +66 -0
- package/dist/core/model-resolver-scope.js.map +1 -0
- package/dist/core/model-resolver-types.d.ts +29 -0
- package/dist/core/model-resolver-types.d.ts.map +1 -0
- package/dist/core/model-resolver-types.js +2 -0
- package/dist/core/model-resolver-types.js.map +1 -0
- package/dist/core/model-resolver.d.ts +6 -107
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js +5 -549
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/package-manager-auto-resources.d.ts +5 -0
- package/dist/core/package-manager-auto-resources.d.ts.map +1 -0
- package/dist/core/package-manager-auto-resources.js +109 -0
- package/dist/core/package-manager-auto-resources.js.map +1 -0
- package/dist/core/package-manager-command.d.ts +11 -0
- package/dist/core/package-manager-command.d.ts.map +1 -0
- package/dist/core/package-manager-command.js +102 -0
- package/dist/core/package-manager-command.js.map +1 -0
- package/dist/core/package-manager-constants.d.ts +4 -0
- package/dist/core/package-manager-constants.d.ts.map +1 -0
- package/dist/core/package-manager-constants.js +4 -0
- package/dist/core/package-manager-constants.js.map +1 -0
- package/dist/core/package-manager-env.d.ts +4 -0
- package/dist/core/package-manager-env.d.ts.map +1 -0
- package/dist/core/package-manager-env.js +40 -0
- package/dist/core/package-manager-env.js.map +1 -0
- package/dist/core/package-manager-git.d.ts +10 -0
- package/dist/core/package-manager-git.d.ts.map +1 -0
- package/dist/core/package-manager-git.js +271 -0
- package/dist/core/package-manager-git.js.map +1 -0
- package/dist/core/package-manager-manifest.d.ts +7 -0
- package/dist/core/package-manager-manifest.d.ts.map +1 -0
- package/dist/core/package-manager-manifest.js +45 -0
- package/dist/core/package-manager-manifest.js.map +1 -0
- package/dist/core/package-manager-npm.d.ts +25 -0
- package/dist/core/package-manager-npm.d.ts.map +1 -0
- package/dist/core/package-manager-npm.js +252 -0
- package/dist/core/package-manager-npm.js.map +1 -0
- package/dist/core/package-manager-operations.d.ts +11 -0
- package/dist/core/package-manager-operations.d.ts.map +1 -0
- package/dist/core/package-manager-operations.js +196 -0
- package/dist/core/package-manager-operations.js.map +1 -0
- package/dist/core/package-manager-paths.d.ts +14 -0
- package/dist/core/package-manager-paths.d.ts.map +1 -0
- package/dist/core/package-manager-paths.js +61 -0
- package/dist/core/package-manager-paths.js.map +1 -0
- package/dist/core/package-manager-progress.d.ts +4 -0
- package/dist/core/package-manager-progress.d.ts.map +1 -0
- package/dist/core/package-manager-progress.js +16 -0
- package/dist/core/package-manager-progress.js.map +1 -0
- package/dist/core/package-manager-resolver.d.ts +5 -0
- package/dist/core/package-manager-resolver.d.ts.map +1 -0
- package/dist/core/package-manager-resolver.js +149 -0
- package/dist/core/package-manager-resolver.js.map +1 -0
- package/dist/core/package-manager-resource-accumulator.d.ts +6 -0
- package/dist/core/package-manager-resource-accumulator.d.ts.map +1 -0
- package/dist/core/package-manager-resource-accumulator.js +67 -0
- package/dist/core/package-manager-resource-accumulator.js.map +1 -0
- package/dist/core/package-manager-resource-collector.d.ts +5 -0
- package/dist/core/package-manager-resource-collector.d.ts.map +1 -0
- package/dist/core/package-manager-resource-collector.js +148 -0
- package/dist/core/package-manager-resource-collector.js.map +1 -0
- package/dist/core/package-manager-resource-files.d.ts +14 -0
- package/dist/core/package-manager-resource-files.d.ts.map +1 -0
- package/dist/core/package-manager-resource-files.js +265 -0
- package/dist/core/package-manager-resource-files.js.map +1 -0
- package/dist/core/package-manager-resource-patterns.d.ts +12 -0
- package/dist/core/package-manager-resource-patterns.d.ts.map +1 -0
- package/dist/core/package-manager-resource-patterns.js +136 -0
- package/dist/core/package-manager-resource-patterns.js.map +1 -0
- package/dist/core/package-manager-settings.d.ts +10 -0
- package/dist/core/package-manager-settings.d.ts.map +1 -0
- package/dist/core/package-manager-settings.js +91 -0
- package/dist/core/package-manager-settings.js.map +1 -0
- package/dist/core/package-manager-source.d.ts +21 -0
- package/dist/core/package-manager-source.d.ts.map +1 -0
- package/dist/core/package-manager-source.js +146 -0
- package/dist/core/package-manager-source.js.map +1 -0
- package/dist/core/package-manager-types.d.ts +169 -0
- package/dist/core/package-manager-types.d.ts.map +1 -0
- package/dist/core/package-manager-types.js +9 -0
- package/dist/core/package-manager-types.js.map +1 -0
- package/dist/core/package-manager.d.ts +9 -174
- package/dist/core/package-manager.d.ts.map +1 -1
- package/dist/core/package-manager.js +56 -2100
- package/dist/core/package-manager.js.map +1 -1
- package/dist/core/resource-loader-assets.d.ts +6 -0
- package/dist/core/resource-loader-assets.d.ts.map +1 -0
- package/dist/core/resource-loader-assets.js +209 -0
- package/dist/core/resource-loader-assets.js.map +1 -0
- package/dist/core/resource-loader-context-files.d.ts +10 -0
- package/dist/core/resource-loader-context-files.d.ts.map +1 -0
- package/dist/core/resource-loader-context-files.js +74 -0
- package/dist/core/resource-loader-context-files.js.map +1 -0
- package/dist/core/resource-loader-core.d.ts +83 -0
- package/dist/core/resource-loader-core.d.ts.map +1 -0
- package/dist/core/resource-loader-core.js +170 -0
- package/dist/core/resource-loader-core.js.map +1 -0
- package/dist/core/resource-loader-discovery.d.ts +4 -0
- package/dist/core/resource-loader-discovery.d.ts.map +1 -0
- package/dist/core/resource-loader-discovery.js +28 -0
- package/dist/core/resource-loader-discovery.js.map +1 -0
- package/dist/core/resource-loader-extensions.d.ts +13 -0
- package/dist/core/resource-loader-extensions.d.ts.map +1 -0
- package/dist/core/resource-loader-extensions.js +110 -0
- package/dist/core/resource-loader-extensions.js.map +1 -0
- package/dist/core/resource-loader-helpers.d.ts +4 -0
- package/dist/core/resource-loader-helpers.d.ts.map +1 -0
- package/dist/core/resource-loader-helpers.js +23 -0
- package/dist/core/resource-loader-helpers.js.map +1 -0
- package/dist/core/resource-loader-internals.d.ts +97 -0
- package/dist/core/resource-loader-internals.d.ts.map +1 -0
- package/dist/core/resource-loader-internals.js +4 -0
- package/dist/core/resource-loader-internals.js.map +1 -0
- package/dist/core/resource-loader-package-resources.d.ts +31 -0
- package/dist/core/resource-loader-package-resources.d.ts.map +1 -0
- package/dist/core/resource-loader-package-resources.js +112 -0
- package/dist/core/resource-loader-package-resources.js.map +1 -0
- package/dist/core/resource-loader-paths.d.ts +4 -0
- package/dist/core/resource-loader-paths.d.ts.map +1 -0
- package/dist/core/resource-loader-paths.js +22 -0
- package/dist/core/resource-loader-paths.js.map +1 -0
- package/dist/core/resource-loader-reload.d.ts +6 -0
- package/dist/core/resource-loader-reload.d.ts.map +1 -0
- package/dist/core/resource-loader-reload.js +230 -0
- package/dist/core/resource-loader-reload.js.map +1 -0
- package/dist/core/resource-loader-source-info.d.ts +9 -0
- package/dist/core/resource-loader-source-info.d.ts.map +1 -0
- package/dist/core/resource-loader-source-info.js +101 -0
- package/dist/core/resource-loader-source-info.js.map +1 -0
- package/dist/core/resource-loader-types.d.ts +130 -0
- package/dist/core/resource-loader-types.d.ts.map +1 -0
- package/dist/core/resource-loader-types.js +2 -0
- package/dist/core/resource-loader-types.js.map +1 -0
- package/dist/core/resource-loader.d.ts +3 -242
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +2 -976
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/sdk-exports.d.ts +7 -0
- package/dist/core/sdk-exports.d.ts.map +1 -0
- package/dist/core/sdk-exports.js +5 -0
- package/dist/core/sdk-exports.js.map +1 -0
- package/dist/core/sdk-types.d.ts +83 -0
- package/dist/core/sdk-types.d.ts.map +1 -0
- package/dist/core/sdk-types.js +2 -0
- package/dist/core/sdk-types.js.map +1 -0
- package/dist/core/sdk.d.ts +3 -91
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +2 -7
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/session-manager-archive.d.ts +27 -0
- package/dist/core/session-manager-archive.d.ts.map +1 -0
- package/dist/core/session-manager-archive.js +114 -0
- package/dist/core/session-manager-archive.js.map +1 -0
- package/dist/core/session-manager-core.d.ts +104 -0
- package/dist/core/session-manager-core.d.ts.map +1 -0
- package/dist/core/session-manager-core.js +346 -0
- package/dist/core/session-manager-core.js.map +1 -0
- package/dist/core/session-manager-entries.d.ts +38 -0
- package/dist/core/session-manager-entries.d.ts.map +1 -0
- package/dist/core/session-manager-entries.js +124 -0
- package/dist/core/session-manager-entries.js.map +1 -0
- package/dist/core/session-manager-history.d.ts +38 -0
- package/dist/core/session-manager-history.d.ts.map +1 -0
- package/dist/core/session-manager-history.js +379 -0
- package/dist/core/session-manager-history.js.map +1 -0
- package/dist/core/session-manager-list.d.ts +5 -0
- package/dist/core/session-manager-list.d.ts.map +1 -0
- package/dist/core/session-manager-list.js +196 -0
- package/dist/core/session-manager-list.js.map +1 -0
- package/dist/core/session-manager-migrations.d.ts +11 -0
- package/dist/core/session-manager-migrations.d.ts.map +1 -0
- package/dist/core/session-manager-migrations.js +80 -0
- package/dist/core/session-manager-migrations.js.map +1 -0
- package/dist/core/session-manager-paths.d.ts +7 -0
- package/dist/core/session-manager-paths.d.ts.map +1 -0
- package/dist/core/session-manager-paths.js +22 -0
- package/dist/core/session-manager-paths.js.map +1 -0
- package/dist/core/session-manager-storage.d.ts +15 -0
- package/dist/core/session-manager-storage.d.ts.map +1 -0
- package/dist/core/session-manager-storage.js +127 -0
- package/dist/core/session-manager-storage.js.map +1 -0
- package/dist/core/session-manager-types.d.ts +172 -0
- package/dist/core/session-manager-types.d.ts.map +1 -0
- package/dist/core/session-manager-types.js +2 -0
- package/dist/core/session-manager-types.js.map +1 -0
- package/dist/core/session-manager-validation.d.ts +7 -0
- package/dist/core/session-manager-validation.d.ts.map +1 -0
- package/dist/core/session-manager-validation.js +34 -0
- package/dist/core/session-manager-validation.js.map +1 -0
- package/dist/core/session-manager.d.ts +8 -390
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +7 -1418
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/settings-manager-basic-accessors.d.ts +65 -0
- package/dist/core/settings-manager-basic-accessors.d.ts.map +1 -0
- package/dist/core/settings-manager-basic-accessors.js +253 -0
- package/dist/core/settings-manager-basic-accessors.js.map +1 -0
- package/dist/core/settings-manager-core.d.ts +57 -0
- package/dist/core/settings-manager-core.d.ts.map +1 -0
- package/dist/core/settings-manager-core.js +387 -0
- package/dist/core/settings-manager-core.js.map +1 -0
- package/dist/core/settings-manager-internals.d.ts +13 -0
- package/dist/core/settings-manager-internals.d.ts.map +1 -0
- package/dist/core/settings-manager-internals.js +4 -0
- package/dist/core/settings-manager-internals.js.map +1 -0
- package/dist/core/settings-manager-resource-accessors.d.ts +43 -0
- package/dist/core/settings-manager-resource-accessors.d.ts.map +1 -0
- package/dist/core/settings-manager-resource-accessors.js +172 -0
- package/dist/core/settings-manager-resource-accessors.js.map +1 -0
- package/dist/core/settings-manager-ui-accessors.d.ts +44 -0
- package/dist/core/settings-manager-ui-accessors.d.ts.map +1 -0
- package/dist/core/settings-manager-ui-accessors.js +208 -0
- package/dist/core/settings-manager-ui-accessors.js.map +1 -0
- package/dist/core/settings-manager.d.ts +6 -321
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +5 -1060
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/settings-merge.d.ts +4 -0
- package/dist/core/settings-merge.d.ts.map +1 -0
- package/dist/core/settings-merge.js +26 -0
- package/dist/core/settings-merge.js.map +1 -0
- package/dist/core/settings-storage.d.ts +20 -0
- package/dist/core/settings-storage.d.ts.map +1 -0
- package/dist/core/settings-storage.js +100 -0
- package/dist/core/settings-storage.js.map +1 -0
- package/dist/core/settings-types.d.ts +123 -0
- package/dist/core/settings-types.d.ts.map +1 -0
- package/dist/core/settings-types.js +2 -0
- package/dist/core/settings-types.js.map +1 -0
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js +7 -0
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/tools/bash.d.ts +0 -5
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +10 -11
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/edit-diff-preserve.d.ts +18 -0
- package/dist/core/tools/edit-diff-preserve.d.ts.map +1 -0
- package/dist/core/tools/edit-diff-preserve.js +85 -0
- package/dist/core/tools/edit-diff-preserve.js.map +1 -0
- package/dist/core/tools/edit-diff.d.ts +3 -2
- package/dist/core/tools/edit-diff.d.ts.map +1 -1
- package/dist/core/tools/edit-diff.js +15 -18
- package/dist/core/tools/edit-diff.js.map +1 -1
- package/dist/core/tools/index.d.ts +0 -1
- package/dist/core/tools/index.d.ts.map +1 -1
- package/dist/core/tools/index.js +0 -1
- package/dist/core/tools/index.js.map +1 -1
- package/dist/core/tools/todos-execute.d.ts +5 -0
- package/dist/core/tools/todos-execute.d.ts.map +1 -0
- package/dist/core/tools/todos-execute.js +200 -0
- package/dist/core/tools/todos-execute.js.map +1 -0
- package/dist/core/tools/todos-locks.d.ts +4 -0
- package/dist/core/tools/todos-locks.d.ts.map +1 -0
- package/dist/core/tools/todos-locks.js +80 -0
- package/dist/core/tools/todos-locks.js.map +1 -0
- package/dist/core/tools/todos-model.d.ts +21 -0
- package/dist/core/tools/todos-model.d.ts.map +1 -0
- package/dist/core/tools/todos-model.js +71 -0
- package/dist/core/tools/todos-model.js.map +1 -0
- package/dist/core/tools/todos-mutations.d.ts +6 -0
- package/dist/core/tools/todos-mutations.d.ts.map +1 -0
- package/dist/core/tools/todos-mutations.js +85 -0
- package/dist/core/tools/todos-mutations.js.map +1 -0
- package/dist/core/tools/todos-paths.d.ts +5 -0
- package/dist/core/tools/todos-paths.d.ts.map +1 -0
- package/dist/core/tools/todos-paths.js +25 -0
- package/dist/core/tools/todos-paths.js.map +1 -0
- package/dist/core/tools/todos-render.d.ts +10 -0
- package/dist/core/tools/todos-render.d.ts.map +1 -0
- package/dist/core/tools/todos-render.js +159 -0
- package/dist/core/tools/todos-render.js.map +1 -0
- package/dist/core/tools/todos-storage.d.ts +9 -0
- package/dist/core/tools/todos-storage.d.ts.map +1 -0
- package/dist/core/tools/todos-storage.js +183 -0
- package/dist/core/tools/todos-storage.js.map +1 -0
- package/dist/core/tools/todos-types.d.ts +46 -0
- package/dist/core/tools/todos-types.d.ts.map +1 -0
- package/dist/core/tools/todos-types.js +27 -0
- package/dist/core/tools/todos-types.js.map +1 -0
- package/dist/core/tools/todos.d.ts +12 -32
- package/dist/core/tools/todos.d.ts.map +1 -1
- package/dist/core/tools/todos.js +7 -893
- package/dist/core/tools/todos.js.map +1 -1
- package/dist/index-extensions.d.ts +3 -0
- package/dist/index-extensions.d.ts.map +1 -0
- package/dist/index-extensions.js +2 -0
- package/dist/index-extensions.js.map +1 -0
- package/dist/index.d.ts +3 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/main-app-mode.d.ts +15 -0
- package/dist/main-app-mode.d.ts.map +1 -0
- package/dist/main-app-mode.js +51 -0
- package/dist/main-app-mode.js.map +1 -0
- package/dist/main-session-options.d.ts +12 -0
- package/dist/main-session-options.d.ts.map +1 -0
- package/dist/main-session-options.js +87 -0
- package/dist/main-session-options.js.map +1 -0
- package/dist/main-session.d.ts +9 -0
- package/dist/main-session.d.ts.map +1 -0
- package/dist/main-session.js +188 -0
- package/dist/main-session.js.map +1 -0
- package/dist/main-stdio.d.ts +12 -0
- package/dist/main-stdio.d.ts.map +1 -0
- package/dist/main-stdio.js +68 -0
- package/dist/main-stdio.js.map +1 -0
- package/dist/main.d.ts +2 -3
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +11 -388
- package/dist/main.js.map +1 -1
- package/dist/migrations-config-values.d.ts +9 -0
- package/dist/migrations-config-values.d.ts.map +1 -0
- package/dist/migrations-config-values.js +298 -0
- package/dist/migrations-config-values.js.map +1 -0
- package/dist/migrations.d.ts.map +1 -1
- package/dist/migrations.js +2 -296
- package/dist/migrations.js.map +1 -1
- package/dist/modes/interactive/components/chat-message-renderer.d.ts.map +1 -1
- package/dist/modes/interactive/components/chat-message-renderer.js +0 -7
- package/dist/modes/interactive/components/chat-message-renderer.js.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-actions.d.ts +9 -0
- package/dist/modes/interactive/components/chat-session-host-actions.d.ts.map +1 -0
- package/dist/modes/interactive/components/chat-session-host-actions.js +244 -0
- package/dist/modes/interactive/components/chat-session-host-actions.js.map +1 -0
- package/dist/modes/interactive/components/chat-session-host-editor.d.ts +18 -0
- package/dist/modes/interactive/components/chat-session-host-editor.d.ts.map +1 -0
- package/dist/modes/interactive/components/chat-session-host-editor.js +165 -0
- package/dist/modes/interactive/components/chat-session-host-editor.js.map +1 -0
- package/dist/modes/interactive/components/chat-session-host-events.d.ts +5 -0
- package/dist/modes/interactive/components/chat-session-host-events.d.ts.map +1 -0
- package/dist/modes/interactive/components/chat-session-host-events.js +200 -0
- package/dist/modes/interactive/components/chat-session-host-events.js.map +1 -0
- package/dist/modes/interactive/components/chat-session-host-rendering.d.ts +13 -0
- package/dist/modes/interactive/components/chat-session-host-rendering.d.ts.map +1 -0
- package/dist/modes/interactive/components/chat-session-host-rendering.js +185 -0
- package/dist/modes/interactive/components/chat-session-host-rendering.js.map +1 -0
- package/dist/modes/interactive/components/chat-session-host-runtime.d.ts +13 -0
- package/dist/modes/interactive/components/chat-session-host-runtime.d.ts.map +1 -0
- package/dist/modes/interactive/components/chat-session-host-runtime.js +101 -0
- package/dist/modes/interactive/components/chat-session-host-runtime.js.map +1 -0
- package/dist/modes/interactive/components/chat-session-host-state.d.ts +53 -0
- package/dist/modes/interactive/components/chat-session-host-state.d.ts.map +1 -0
- package/dist/modes/interactive/components/chat-session-host-state.js +42 -0
- package/dist/modes/interactive/components/chat-session-host-state.js.map +1 -0
- package/dist/modes/interactive/components/chat-session-host-types.d.ts +63 -0
- package/dist/modes/interactive/components/chat-session-host-types.d.ts.map +1 -0
- package/dist/modes/interactive/components/chat-session-host-types.js +2 -0
- package/dist/modes/interactive/components/chat-session-host-types.js.map +1 -0
- package/dist/modes/interactive/components/chat-session-host-utils.d.ts +28 -0
- package/dist/modes/interactive/components/chat-session-host-utils.d.ts.map +1 -0
- package/dist/modes/interactive/components/chat-session-host-utils.js +103 -0
- package/dist/modes/interactive/components/chat-session-host-utils.js.map +1 -0
- package/dist/modes/interactive/components/chat-session-host.d.ts +6 -129
- package/dist/modes/interactive/components/chat-session-host.d.ts.map +1 -1
- package/dist/modes/interactive/components/chat-session-host.js +50 -1022
- package/dist/modes/interactive/components/chat-session-host.js.map +1 -1
- package/dist/modes/interactive/components/config-selector-list.d.ts +65 -0
- package/dist/modes/interactive/components/config-selector-list.d.ts.map +1 -0
- package/dist/modes/interactive/components/config-selector-list.js +458 -0
- package/dist/modes/interactive/components/config-selector-list.js.map +1 -0
- package/dist/modes/interactive/components/config-selector.d.ts +3 -58
- package/dist/modes/interactive/components/config-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/config-selector.js +2 -457
- package/dist/modes/interactive/components/config-selector.js.map +1 -1
- package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/model-selector.js +2 -2
- package/dist/modes/interactive/components/model-selector.js.map +1 -1
- package/dist/modes/interactive/components/session-selector-delete.d.ts +10 -0
- package/dist/modes/interactive/components/session-selector-delete.d.ts.map +1 -0
- package/dist/modes/interactive/components/session-selector-delete.js +40 -0
- package/dist/modes/interactive/components/session-selector-delete.js.map +1 -0
- package/dist/modes/interactive/components/session-selector-header.d.ts +33 -0
- package/dist/modes/interactive/components/session-selector-header.d.ts.map +1 -0
- package/dist/modes/interactive/components/session-selector-header.js +117 -0
- package/dist/modes/interactive/components/session-selector-header.js.map +1 -0
- package/dist/modes/interactive/components/session-selector-list.d.ts +49 -0
- package/dist/modes/interactive/components/session-selector-list.d.ts.map +1 -0
- package/dist/modes/interactive/components/session-selector-list.js +307 -0
- package/dist/modes/interactive/components/session-selector-list.js.map +1 -0
- package/dist/modes/interactive/components/session-selector-tree.d.ts +25 -0
- package/dist/modes/interactive/components/session-selector-tree.d.ts.map +1 -0
- package/dist/modes/interactive/components/session-selector-tree.js +53 -0
- package/dist/modes/interactive/components/session-selector-tree.js.map +1 -0
- package/dist/modes/interactive/components/session-selector-types.d.ts +4 -0
- package/dist/modes/interactive/components/session-selector-types.d.ts.map +1 -0
- package/dist/modes/interactive/components/session-selector-types.js +2 -0
- package/dist/modes/interactive/components/session-selector-types.js.map +1 -0
- package/dist/modes/interactive/components/session-selector-utils.d.ts +4 -0
- package/dist/modes/interactive/components/session-selector-utils.d.ts.map +1 -0
- package/dist/modes/interactive/components/session-selector-utils.js +37 -0
- package/dist/modes/interactive/components/session-selector-utils.js.map +1 -0
- package/dist/modes/interactive/components/session-selector.d.ts +3 -49
- package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/session-selector.js +5 -542
- package/dist/modes/interactive/components/session-selector.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector-handlers.d.ts +3 -0
- package/dist/modes/interactive/components/settings-selector-handlers.d.ts.map +1 -0
- package/dist/modes/interactive/components/settings-selector-handlers.js +84 -0
- package/dist/modes/interactive/components/settings-selector-handlers.js.map +1 -0
- package/dist/modes/interactive/components/settings-selector-items.d.ts +4 -0
- package/dist/modes/interactive/components/settings-selector-items.d.ts.map +1 -0
- package/dist/modes/interactive/components/settings-selector-items.js +211 -0
- package/dist/modes/interactive/components/settings-selector-items.js.map +1 -0
- package/dist/modes/interactive/components/settings-selector-options.d.ts +6 -0
- package/dist/modes/interactive/components/settings-selector-options.d.ts.map +1 -0
- package/dist/modes/interactive/components/settings-selector-options.js +14 -0
- package/dist/modes/interactive/components/settings-selector-options.js.map +1 -0
- package/dist/modes/interactive/components/settings-selector-submenus.d.ts +44 -0
- package/dist/modes/interactive/components/settings-selector-submenus.d.ts.map +1 -0
- package/dist/modes/interactive/components/settings-selector-submenus.js +228 -0
- package/dist/modes/interactive/components/settings-selector-submenus.js.map +1 -0
- package/dist/modes/interactive/components/settings-selector-types.d.ts +67 -0
- package/dist/modes/interactive/components/settings-selector-types.d.ts.map +1 -0
- package/dist/modes/interactive/components/settings-selector-types.js +2 -0
- package/dist/modes/interactive/components/settings-selector-types.js.map +1 -0
- package/dist/modes/interactive/components/settings-selector.d.ts +2 -63
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector.js +5 -538
- package/dist/modes/interactive/components/settings-selector.js.map +1 -1
- package/dist/modes/interactive/components/tree-selector-component.d.ts +21 -0
- package/dist/modes/interactive/components/tree-selector-component.d.ts.map +1 -0
- package/dist/modes/interactive/components/tree-selector-component.js +80 -0
- package/dist/modes/interactive/components/tree-selector-component.js.map +1 -0
- package/dist/modes/interactive/components/tree-selector-content.d.ts +8 -0
- package/dist/modes/interactive/components/tree-selector-content.d.ts.map +1 -0
- package/dist/modes/interactive/components/tree-selector-content.js +263 -0
- package/dist/modes/interactive/components/tree-selector-content.js.map +1 -0
- package/dist/modes/interactive/components/tree-selector-help.d.ts +16 -0
- package/dist/modes/interactive/components/tree-selector-help.d.ts.map +1 -0
- package/dist/modes/interactive/components/tree-selector-help.js +103 -0
- package/dist/modes/interactive/components/tree-selector-help.js.map +1 -0
- package/dist/modes/interactive/components/tree-selector-label-input.d.ts +16 -0
- package/dist/modes/interactive/components/tree-selector-label-input.d.ts.map +1 -0
- package/dist/modes/interactive/components/tree-selector-label-input.js +46 -0
- package/dist/modes/interactive/components/tree-selector-label-input.js.map +1 -0
- package/dist/modes/interactive/components/tree-selector-list.d.ts +33 -0
- package/dist/modes/interactive/components/tree-selector-list.d.ts.map +1 -0
- package/dist/modes/interactive/components/tree-selector-list.js +336 -0
- package/dist/modes/interactive/components/tree-selector-list.js.map +1 -0
- package/dist/modes/interactive/components/tree-selector-model.d.ts +7 -0
- package/dist/modes/interactive/components/tree-selector-model.d.ts.map +1 -0
- package/dist/modes/interactive/components/tree-selector-model.js +358 -0
- package/dist/modes/interactive/components/tree-selector-model.js.map +1 -0
- package/dist/modes/interactive/components/tree-selector-types.d.ts +57 -0
- package/dist/modes/interactive/components/tree-selector-types.d.ts.map +1 -0
- package/dist/modes/interactive/components/tree-selector-types.js +6 -0
- package/dist/modes/interactive/components/tree-selector-types.js.map +1 -0
- package/dist/modes/interactive/components/tree-selector-viewport.d.ts +10 -0
- package/dist/modes/interactive/components/tree-selector-viewport.d.ts.map +1 -0
- package/dist/modes/interactive/components/tree-selector-viewport.js +32 -0
- package/dist/modes/interactive/components/tree-selector-viewport.js.map +1 -0
- package/dist/modes/interactive/components/tree-selector.d.ts +2 -88
- package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/tree-selector.js +1 -1200
- package/dist/modes/interactive/components/tree-selector.js.map +1 -1
- package/dist/modes/interactive/interactive-agent-events.d.ts +2 -0
- package/dist/modes/interactive/interactive-agent-events.d.ts.map +1 -0
- package/dist/modes/interactive/interactive-agent-events.js +370 -0
- package/dist/modes/interactive/interactive-agent-events.js.map +1 -0
- package/dist/modes/interactive/interactive-auth-login.d.ts +2 -0
- package/dist/modes/interactive/interactive-auth-login.d.ts.map +1 -0
- package/dist/modes/interactive/interactive-auth-login.js +214 -0
- package/dist/modes/interactive/interactive-auth-login.js.map +1 -0
- package/dist/modes/interactive/interactive-auth-routing.d.ts +2 -0
- package/dist/modes/interactive/interactive-auth-routing.d.ts.map +1 -0
- package/dist/modes/interactive/interactive-auth-routing.js +128 -0
- package/dist/modes/interactive/interactive-auth-routing.js.map +1 -0
- package/dist/modes/interactive/interactive-autocomplete.d.ts +2 -0
- package/dist/modes/interactive/interactive-autocomplete.d.ts.map +1 -0
- package/dist/modes/interactive/interactive-autocomplete.js +140 -0
- package/dist/modes/interactive/interactive-autocomplete.js.map +1 -0
- package/dist/modes/interactive/interactive-bash-compact.d.ts +2 -0
- package/dist/modes/interactive/interactive-bash-compact.d.ts.map +1 -0
- package/dist/modes/interactive/interactive-bash-compact.js +112 -0
- package/dist/modes/interactive/interactive-bash-compact.js.map +1 -0
- package/dist/modes/interactive/interactive-editor-actions.d.ts +2 -0
- package/dist/modes/interactive/interactive-editor-actions.d.ts.map +1 -0
- package/dist/modes/interactive/interactive-editor-actions.js +131 -0
- package/dist/modes/interactive/interactive-editor-actions.js.map +1 -0
- package/dist/modes/interactive/interactive-extension-context.d.ts +2 -0
- package/dist/modes/interactive/interactive-extension-context.d.ts.map +1 -0
- package/dist/modes/interactive/interactive-extension-context.js +159 -0
- package/dist/modes/interactive/interactive-extension-context.js.map +1 -0
- package/dist/modes/interactive/interactive-extension-custom-ui.d.ts +2 -0
- package/dist/modes/interactive/interactive-extension-custom-ui.d.ts.map +1 -0
- package/dist/modes/interactive/interactive-extension-custom-ui.js +208 -0
- package/dist/modes/interactive/interactive-extension-custom-ui.js.map +1 -0
- package/dist/modes/interactive/interactive-extension-dialogs.d.ts +2 -0
- package/dist/modes/interactive/interactive-extension-dialogs.d.ts.map +1 -0
- package/dist/modes/interactive/interactive-extension-dialogs.js +162 -0
- package/dist/modes/interactive/interactive-extension-dialogs.js.map +1 -0
- package/dist/modes/interactive/interactive-extension-runtime.d.ts +2 -0
- package/dist/modes/interactive/interactive-extension-runtime.d.ts.map +1 -0
- package/dist/modes/interactive/interactive-extension-runtime.js +179 -0
- package/dist/modes/interactive/interactive-extension-runtime.js.map +1 -0
- package/dist/modes/interactive/interactive-extension-widgets.d.ts +2 -0
- package/dist/modes/interactive/interactive-extension-widgets.d.ts.map +1 -0
- package/dist/modes/interactive/interactive-extension-widgets.js +113 -0
- package/dist/modes/interactive/interactive-extension-widgets.js.map +1 -0
- package/dist/modes/interactive/interactive-hotkeys-debug.d.ts +2 -0
- package/dist/modes/interactive/interactive-hotkeys-debug.d.ts.map +1 -0
- package/dist/modes/interactive/interactive-hotkeys-debug.js +186 -0
- package/dist/modes/interactive/interactive-hotkeys-debug.js.map +1 -0
- package/dist/modes/interactive/interactive-input-handling.d.ts +2 -0
- package/dist/modes/interactive/interactive-input-handling.d.ts.map +1 -0
- package/dist/modes/interactive/interactive-input-handling.js +275 -0
- package/dist/modes/interactive/interactive-input-handling.js.map +1 -0
- package/dist/modes/interactive/interactive-mode-base.d.ts +103 -0
- package/dist/modes/interactive/interactive-mode-base.d.ts.map +1 -0
- package/dist/modes/interactive/interactive-mode-base.js +130 -0
- package/dist/modes/interactive/interactive-mode-base.js.map +1 -0
- package/dist/modes/interactive/interactive-mode-deps.d.ts +81 -0
- package/dist/modes/interactive/interactive-mode-deps.d.ts.map +1 -0
- package/dist/modes/interactive/interactive-mode-deps.js +74 -0
- package/dist/modes/interactive/interactive-mode-deps.js.map +1 -0
- package/dist/modes/interactive/interactive-mode-helpers.d.ts +21 -0
- package/dist/modes/interactive/interactive-mode-helpers.d.ts.map +1 -0
- package/dist/modes/interactive/interactive-mode-helpers.js +77 -0
- package/dist/modes/interactive/interactive-mode-helpers.js.map +1 -0
- package/dist/modes/interactive/interactive-mode-surface.d.ts +313 -0
- package/dist/modes/interactive/interactive-mode-surface.d.ts.map +1 -0
- package/dist/modes/interactive/interactive-mode-surface.js +2 -0
- package/dist/modes/interactive/interactive-mode-surface.js.map +1 -0
- package/dist/modes/interactive/interactive-mode-types.d.ts +29 -0
- package/dist/modes/interactive/interactive-mode-types.d.ts.map +1 -0
- package/dist/modes/interactive/interactive-mode-types.js +2 -0
- package/dist/modes/interactive/interactive-mode-types.js.map +1 -0
- package/dist/modes/interactive/interactive-mode.d.ts +30 -404
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +29 -5260
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/interactive-model-routing.d.ts +2 -0
- package/dist/modes/interactive/interactive-model-routing.d.ts.map +1 -0
- package/dist/modes/interactive/interactive-model-routing.js +269 -0
- package/dist/modes/interactive/interactive-model-routing.js.map +1 -0
- package/dist/modes/interactive/interactive-process-lifecycle.d.ts +2 -0
- package/dist/modes/interactive/interactive-process-lifecycle.d.ts.map +1 -0
- package/dist/modes/interactive/interactive-process-lifecycle.js +189 -0
- package/dist/modes/interactive/interactive-process-lifecycle.js.map +1 -0
- package/dist/modes/interactive/interactive-queueing.d.ts +2 -0
- package/dist/modes/interactive/interactive-queueing.d.ts.map +1 -0
- package/dist/modes/interactive/interactive-queueing.js +163 -0
- package/dist/modes/interactive/interactive-queueing.js.map +1 -0
- package/dist/modes/interactive/interactive-render-chat.d.ts +2 -0
- package/dist/modes/interactive/interactive-render-chat.d.ts.map +1 -0
- package/dist/modes/interactive/interactive-render-chat.js +170 -0
- package/dist/modes/interactive/interactive-render-chat.js.map +1 -0
- package/dist/modes/interactive/interactive-resource-disclosure.d.ts +2 -0
- package/dist/modes/interactive/interactive-resource-disclosure.d.ts.map +1 -0
- package/dist/modes/interactive/interactive-resource-disclosure.js +101 -0
- package/dist/modes/interactive/interactive-resource-disclosure.js.map +1 -0
- package/dist/modes/interactive/interactive-resource-paths.d.ts +2 -0
- package/dist/modes/interactive/interactive-resource-paths.d.ts.map +1 -0
- package/dist/modes/interactive/interactive-resource-paths.js +228 -0
- package/dist/modes/interactive/interactive-resource-paths.js.map +1 -0
- package/dist/modes/interactive/interactive-resource-rendering.d.ts +2 -0
- package/dist/modes/interactive/interactive-resource-rendering.d.ts.map +1 -0
- package/dist/modes/interactive/interactive-resource-rendering.js +181 -0
- package/dist/modes/interactive/interactive-resource-rendering.js.map +1 -0
- package/dist/modes/interactive/interactive-selectors.d.ts +2 -0
- package/dist/modes/interactive/interactive-selectors.d.ts.map +1 -0
- package/dist/modes/interactive/interactive-selectors.js +198 -0
- package/dist/modes/interactive/interactive-selectors.js.map +1 -0
- package/dist/modes/interactive/interactive-session-routing.d.ts +2 -0
- package/dist/modes/interactive/interactive-session-routing.d.ts.map +1 -0
- package/dist/modes/interactive/interactive-session-routing.js +232 -0
- package/dist/modes/interactive/interactive-session-routing.js.map +1 -0
- package/dist/modes/interactive/interactive-session-runtime.d.ts +2 -0
- package/dist/modes/interactive/interactive-session-runtime.d.ts.map +1 -0
- package/dist/modes/interactive/interactive-session-runtime.js +131 -0
- package/dist/modes/interactive/interactive-session-runtime.js.map +1 -0
- package/dist/modes/interactive/interactive-slash-commands.d.ts +2 -0
- package/dist/modes/interactive/interactive-slash-commands.d.ts.map +1 -0
- package/dist/modes/interactive/interactive-slash-commands.js +338 -0
- package/dist/modes/interactive/interactive-slash-commands.js.map +1 -0
- package/dist/modes/interactive/interactive-startup.d.ts +2 -0
- package/dist/modes/interactive/interactive-startup.d.ts.map +1 -0
- package/dist/modes/interactive/interactive-startup.js +348 -0
- package/dist/modes/interactive/interactive-startup.js.map +1 -0
- package/dist/modes/interactive/model-search.d.ts +5 -0
- package/dist/modes/interactive/model-search.d.ts.map +1 -1
- package/dist/modes/interactive/model-search.js +9 -0
- package/dist/modes/interactive/model-search.js.map +1 -1
- package/dist/modes/interactive/theme/color-utils.d.ts +20 -0
- package/dist/modes/interactive/theme/color-utils.d.ts.map +1 -0
- package/dist/modes/interactive/theme/color-utils.js +204 -0
- package/dist/modes/interactive/theme/color-utils.js.map +1 -0
- package/dist/modes/interactive/theme/export-colors.d.ts +19 -0
- package/dist/modes/interactive/theme/export-colors.d.ts.map +1 -0
- package/dist/modes/interactive/theme/export-colors.js +69 -0
- package/dist/modes/interactive/theme/export-colors.js.map +1 -0
- package/dist/modes/interactive/theme/global-theme.d.ts +12 -0
- package/dist/modes/interactive/theme/global-theme.d.ts.map +1 -0
- package/dist/modes/interactive/theme/global-theme.js +150 -0
- package/dist/modes/interactive/theme/global-theme.js.map +1 -0
- package/dist/modes/interactive/theme/terminal-detection.d.ts +30 -0
- package/dist/modes/interactive/theme/terminal-detection.d.ts.map +1 -0
- package/dist/modes/interactive/theme/terminal-detection.js +89 -0
- package/dist/modes/interactive/theme/terminal-detection.js.map +1 -0
- package/dist/modes/interactive/theme/theme-class.d.ts +30 -0
- package/dist/modes/interactive/theme/theme-class.d.ts.map +1 -0
- package/dist/modes/interactive/theme/theme-class.js +83 -0
- package/dist/modes/interactive/theme/theme-class.js.map +1 -0
- package/dist/modes/interactive/theme/theme-loading.d.ts +17 -0
- package/dist/modes/interactive/theme/theme-loading.d.ts.map +1 -0
- package/dist/modes/interactive/theme/theme-loading.js +155 -0
- package/dist/modes/interactive/theme/theme-loading.js.map +1 -0
- package/dist/modes/interactive/theme/theme-parse.d.ts +5 -0
- package/dist/modes/interactive/theme/theme-parse.d.ts.map +1 -0
- package/dist/modes/interactive/theme/theme-parse.js +52 -0
- package/dist/modes/interactive/theme/theme-parse.js.map +1 -0
- package/dist/modes/interactive/theme/theme-schema.d.ts +255 -0
- package/dist/modes/interactive/theme/theme-schema.d.ts.map +1 -0
- package/dist/modes/interactive/theme/theme-schema.js +78 -0
- package/dist/modes/interactive/theme/theme-schema.js.map +1 -0
- package/dist/modes/interactive/theme/theme.d.ts +6 -108
- package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
- package/dist/modes/interactive/theme/theme.js +6 -1065
- package/dist/modes/interactive/theme/theme.js.map +1 -1
- package/dist/modes/interactive/theme/tui-theme.d.ts +15 -0
- package/dist/modes/interactive/theme/tui-theme.d.ts.map +1 -0
- package/dist/modes/interactive/theme/tui-theme.js +199 -0
- package/dist/modes/interactive/theme/tui-theme.js.map +1 -0
- package/dist/modes/rpc/rpc-client.d.ts +1 -61
- package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-client.js +1 -72
- package/dist/modes/rpc/rpc-client.js.map +1 -1
- package/dist/modes/rpc/rpc-command-handler.d.ts +14 -0
- package/dist/modes/rpc/rpc-command-handler.d.ts.map +1 -0
- package/dist/modes/rpc/rpc-command-handler.js +226 -0
- package/dist/modes/rpc/rpc-command-handler.js.map +1 -0
- package/dist/modes/rpc/rpc-extension-ui.d.ts +15 -0
- package/dist/modes/rpc/rpc-extension-ui.d.ts.map +1 -0
- package/dist/modes/rpc/rpc-extension-ui.js +196 -0
- package/dist/modes/rpc/rpc-extension-ui.js.map +1 -0
- package/dist/modes/rpc/rpc-input.d.ts +12 -0
- package/dist/modes/rpc/rpc-input.d.ts.map +1 -0
- package/dist/modes/rpc/rpc-input.js +54 -0
- package/dist/modes/rpc/rpc-input.js.map +1 -0
- package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-mode.js +43 -607
- package/dist/modes/rpc/rpc-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-responses.d.ts +8 -0
- package/dist/modes/rpc/rpc-responses.d.ts.map +1 -0
- package/dist/modes/rpc/rpc-responses.js +27 -0
- package/dist/modes/rpc/rpc-responses.js.map +1 -0
- package/dist/modes/rpc/rpc-session-binding.d.ts +25 -0
- package/dist/modes/rpc/rpc-session-binding.d.ts.map +1 -0
- package/dist/modes/rpc/rpc-session-binding.js +70 -0
- package/dist/modes/rpc/rpc-session-binding.js.map +1 -0
- package/dist/package-manager-cli-parser.d.ts +28 -0
- package/dist/package-manager-cli-parser.d.ts.map +1 -0
- package/dist/package-manager-cli-parser.js +269 -0
- package/dist/package-manager-cli-parser.js.map +1 -0
- package/dist/package-manager-cli.d.ts +0 -1
- package/dist/package-manager-cli.d.ts.map +1 -1
- package/dist/package-manager-cli.js +2 -267
- package/dist/package-manager-cli.js.map +1 -1
- package/dist/utils/git.d.ts.map +1 -1
- package/dist/utils/git.js +10 -0
- package/dist/utils/git.js.map +1 -1
- package/dist/utils/shell.d.ts +1 -0
- package/dist/utils/shell.d.ts.map +1 -1
- package/dist/utils/shell.js +12 -5
- package/dist/utils/shell.js.map +1 -1
- package/dist/utils/version-check.d.ts +1 -0
- package/dist/utils/version-check.d.ts.map +1 -1
- package/dist/utils/version-check.js +17 -0
- package/dist/utils/version-check.js.map +1 -1
- package/docs/custom-provider.md +4 -3
- package/docs/development.md +4 -0
- package/docs/models.md +3 -2
- package/docs/packages.md +2 -2
- package/docs/quickstart.md +1 -1
- package/docs/sdk.md +2 -40
- package/docs/security.md +1 -1
- package/docs/workflows.md +246 -179
- package/examples/extensions/custom-provider-anthropic/index.ts +1 -106
- package/examples/extensions/gondolin/index.ts +0 -23
- package/examples/extensions/overlay-qa-animation-components.ts +255 -0
- package/examples/extensions/overlay-qa-focus-components.ts +222 -0
- package/examples/extensions/overlay-qa-position-components.ts +433 -0
- package/examples/extensions/overlay-qa-shared.ts +37 -0
- package/examples/extensions/overlay-qa-streaming-input-components.ts +205 -0
- package/examples/extensions/overlay-qa-tests.ts +17 -1156
- package/examples/extensions/overlay-qa-toggle-passive-components.ts +169 -0
- package/examples/extensions/space-invaders.ts +0 -60
- package/examples/extensions/subagent/display.ts +148 -0
- package/examples/extensions/subagent/index.ts +11 -858
- package/examples/extensions/subagent/render.ts +383 -0
- package/examples/extensions/subagent/runner.ts +252 -0
- package/examples/extensions/subagent/schemas.ts +59 -0
- package/examples/extensions/subagent/types.ts +36 -0
- package/examples/extensions/tic-tac-toe-instructions.ts +65 -0
- package/examples/extensions/tic-tac-toe-rendering.ts +414 -0
- package/examples/extensions/tic-tac-toe-state.ts +158 -0
- package/examples/extensions/tic-tac-toe.ts +92 -754
- package/examples/rpc-extension-ui-components.ts +189 -0
- package/examples/rpc-extension-ui.ts +2 -179
- package/package.json +7 -7
- package/dist/builtin/workflows/src/workflows/define-workflow.ts +0 -277
- package/dist/core/tools/bash-policy.d.ts +0 -62
- package/dist/core/tools/bash-policy.d.ts.map +0 -1
- package/dist/core/tools/bash-policy.js +0 -1069
- package/dist/core/tools/bash-policy.js.map +0 -1
|
@@ -1,199 +1,62 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* AgentSession - Core abstraction for agent lifecycle and session management.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* - Event subscription with automatic session persistence
|
|
8
|
-
* - Model and thinking level management
|
|
9
|
-
* - Compaction (manual and auto)
|
|
10
|
-
* - Bash execution
|
|
11
|
-
* - Session switching and branching
|
|
12
|
-
*
|
|
13
|
-
* Modes use this class and add their own I/O layer on top.
|
|
14
|
-
*/
|
|
15
|
-
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
16
|
-
import { basename, dirname } from "node:path";
|
|
17
|
-
import { clampThinkingLevel, cleanupSessionResources, getSupportedThinkingLevels, isContextOverflow, modelsAreEqual, resetApiProviders, } from "@earendil-works/pi-ai";
|
|
18
|
-
import { theme } from "../modes/interactive/theme/theme.js";
|
|
19
|
-
import { stripFrontmatter } from "../utils/frontmatter.js";
|
|
20
|
-
import { resolvePath } from "../utils/paths.js";
|
|
21
|
-
import { sleep } from "../utils/sleep.js";
|
|
22
|
-
import { ATOMIC_GUIDE_COMMAND_NAME, ATOMIC_GUIDE_HELP_CHOICES, atomicGuideModeForChoice, getAtomicGuideMessage, isAtomicGuideHelpChoice, normalizeAtomicGuideMode, } from "./atomic-guide-command.js";
|
|
23
|
-
import { formatAuthStorageLoadFailedMessage, formatNoApiKeyFoundMessage, formatNoModelSelectedMessage, formatUnresolvedModelMessage, } from "./auth-guidance.js";
|
|
24
|
-
import { executeBashWithOperations } from "./bash-executor.js";
|
|
25
|
-
import { calculateContextTokens, collectEntriesForBranchSummary, contextCompact as runContextCompact, estimateContextTokens, generateBranchSummary, prepareContextCompaction, shouldCompact, validateContextDeletionRequest, } from "./compaction/index.js";
|
|
26
|
-
import { getEffectiveInputBudget, getModelDefaultContextWindow, getSupportedContextWindows, selectContextWindow } from "./context-window.js";
|
|
27
|
-
import { formatCopilotProviderError, parseCopilotPromptLimitError } from "./copilot-errors.js";
|
|
28
|
-
import { DEFAULT_THINKING_LEVEL } from "./defaults.js";
|
|
29
|
-
import { exportSessionToHtml } from "./export-html/index.js";
|
|
30
|
-
import { createToolHtmlRenderer } from "./export-html/tool-renderer.js";
|
|
31
|
-
import { ExtensionRunner, wrapRegisteredTools, } from "./extensions/index.js";
|
|
32
|
-
import { emitSessionShutdownEvent } from "./extensions/runner.js";
|
|
33
|
-
import { expandPromptTemplate } from "./prompt-templates.js";
|
|
34
|
-
import { CURRENT_SESSION_VERSION, getLatestCompactionBoundaryEntry } from "./session-manager.js";
|
|
35
|
-
import { createSyntheticSourceInfo } from "./source-info.js";
|
|
36
|
-
import { buildSystemPrompt } from "./system-prompt.js";
|
|
37
|
-
import { createLocalBashOperations } from "./tools/bash.js";
|
|
38
|
-
import { evaluateBashCommandPolicy, formatBashCommandPolicyRejection, } from "./tools/bash-policy.js";
|
|
39
|
-
import { createAllToolDefinitions, defaultToolNames } from "./tools/index.js";
|
|
40
|
-
import { redirectOversizedToolResult } from "./tools/oversized-tool-result.js";
|
|
41
|
-
import { createToolDefinitionFromAgentTool } from "./tools/tool-definition-wrapper.js";
|
|
42
|
-
import { isCopilotGeminiModel } from "./copilot-gemini-payload-sanitizer.js";
|
|
43
|
-
import { normalizeToolArgumentsForModel } from "./copilot-gemini-tool-arguments.js";
|
|
44
|
-
function deepFreeze(value) {
|
|
45
|
-
if (value && typeof value === "object") {
|
|
46
|
-
Object.freeze(value);
|
|
47
|
-
for (const nested of Object.values(value)) {
|
|
48
|
-
deepFreeze(nested);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
return value;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Parse a skill block from message text.
|
|
55
|
-
* Returns null if the text doesn't contain a skill block.
|
|
4
|
+
* The historical import path is preserved here as a facade. Responsibilities are
|
|
5
|
+
* implemented in sibling modules by lifecycle area so each authored source file
|
|
6
|
+
* stays below the repository file-length gate.
|
|
56
7
|
*/
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
return null;
|
|
74
|
-
const contentStart = locationEnd + '">\n'.length;
|
|
75
|
-
const closing = "\n</skill>";
|
|
76
|
-
const contentEnd = text.indexOf(closing, contentStart);
|
|
77
|
-
if (contentEnd === -1)
|
|
78
|
-
return null;
|
|
79
|
-
const afterClosing = text.slice(contentEnd + closing.length);
|
|
80
|
-
if (afterClosing !== "" && !afterClosing.startsWith("\n\n"))
|
|
81
|
-
return null;
|
|
82
|
-
return {
|
|
83
|
-
name,
|
|
84
|
-
location,
|
|
85
|
-
content: text.slice(contentStart, contentEnd),
|
|
86
|
-
userMessage: afterClosing ? afterClosing.slice(2).trim() || undefined : undefined,
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
const COPILOT_CONTEXT_WINDOW_SELECTION_OPTIONS = { allowCopilotLongContextFallback: true };
|
|
90
|
-
function drainAgentMessageQueue(queue) {
|
|
91
|
-
if (!queue)
|
|
92
|
-
return [];
|
|
93
|
-
const drained = [];
|
|
94
|
-
while (queue.hasItems()) {
|
|
95
|
-
drained.push(...queue.drain());
|
|
96
|
-
}
|
|
97
|
-
return drained;
|
|
98
|
-
}
|
|
99
|
-
function normalizeInterruptAbortMessage(value) {
|
|
100
|
-
const trimmed = value?.trim();
|
|
101
|
-
return trimmed && trimmed.length > 0 ? trimmed : undefined;
|
|
102
|
-
}
|
|
103
|
-
function isGenericAbortText(value) {
|
|
104
|
-
const normalized = value.trim().toLowerCase().replace(/[.!]+$/, "");
|
|
105
|
-
return (normalized === "operation aborted" ||
|
|
106
|
-
normalized === "the operation was aborted" ||
|
|
107
|
-
normalized === "request was aborted" ||
|
|
108
|
-
normalized === "this operation was aborted" ||
|
|
109
|
-
normalized === "extension custom ui aborted");
|
|
110
|
-
}
|
|
111
|
-
function isSingleGenericAbortTextContent(content) {
|
|
112
|
-
return (Array.isArray(content) &&
|
|
113
|
-
content.length === 1 &&
|
|
114
|
-
typeof content[0] === "object" &&
|
|
115
|
-
content[0] !== null &&
|
|
116
|
-
content[0].type === "text" &&
|
|
117
|
-
typeof content[0].text === "string" &&
|
|
118
|
-
isGenericAbortText(content[0].text));
|
|
119
|
-
}
|
|
120
|
-
function replacementAbortContent(text) {
|
|
121
|
-
return [{ type: "text", text }];
|
|
122
|
-
}
|
|
123
|
-
// ============================================================================
|
|
124
|
-
// Constants
|
|
125
|
-
// ============================================================================
|
|
126
|
-
/** Standard thinking levels */
|
|
127
|
-
const THINKING_LEVELS = ["off", "minimal", "low", "medium", "high"];
|
|
128
|
-
function customMessageExcludesContext(message) {
|
|
129
|
-
return message.excludeFromContext === true;
|
|
130
|
-
}
|
|
131
|
-
// ============================================================================
|
|
132
|
-
// AgentSession Class
|
|
133
|
-
// ============================================================================
|
|
8
|
+
import { installAgentSessionAccessors } from "./agent-session-accessors.js";
|
|
9
|
+
import { agentSessionAutoCompactionMethods } from "./agent-session-auto-compaction.js";
|
|
10
|
+
import { agentSessionBashMethods } from "./agent-session-bash.js";
|
|
11
|
+
import { agentSessionCompactionMethods } from "./agent-session-compaction.js";
|
|
12
|
+
import { agentSessionEventsMethods } from "./agent-session-events.js";
|
|
13
|
+
import { agentSessionExportMethods } from "./agent-session-export.js";
|
|
14
|
+
import { agentSessionExtensionBindingsMethods } from "./agent-session-extension-bindings.js";
|
|
15
|
+
import { agentSessionMessageQueueMethods } from "./agent-session-message-queue.js";
|
|
16
|
+
import { agentSessionModelsMethods } from "./agent-session-models.js";
|
|
17
|
+
import { agentSessionPromptMethods } from "./agent-session-prompt.js";
|
|
18
|
+
import { agentSessionRetryMethods } from "./agent-session-retry.js";
|
|
19
|
+
import { agentSessionStateMethods } from "./agent-session-state.js";
|
|
20
|
+
import { agentSessionToolHooksMethods } from "./agent-session-tool-hooks.js";
|
|
21
|
+
import { agentSessionToolRegistryMethods } from "./agent-session-tool-registry.js";
|
|
22
|
+
import { agentSessionTreeMethods } from "./agent-session-tree.js";
|
|
23
|
+
export { parseSkillBlock } from "./agent-session-skill-block.js";
|
|
134
24
|
export class AgentSession {
|
|
135
25
|
constructor(config) {
|
|
136
26
|
this._eventListeners = [];
|
|
137
27
|
this._agentEventQueue = Promise.resolve();
|
|
138
|
-
/** Tracks pending steering messages for UI display. Removed when delivered. */
|
|
139
28
|
this._steeringMessages = [];
|
|
140
|
-
/** Tracks pending follow-up messages for UI display. Removed when delivered. */
|
|
141
29
|
this._followUpMessages = [];
|
|
142
|
-
/** Serializes interrupt custom-message delivery so only one immediate prompt runs at a time. */
|
|
143
30
|
this._interruptDeliveryQueue = Promise.resolve();
|
|
144
|
-
/** Number of interrupt custom messages enqueued or currently delivering. */
|
|
145
31
|
this._pendingInterruptDeliveries = 0;
|
|
146
|
-
/** Queues held out of pi-agent-core while an interrupt sequence is active. */
|
|
147
32
|
this._activeInterruptQueueHold = undefined;
|
|
148
|
-
/** Replacement text for generic abort results produced by an interrupt-delivered custom message. */
|
|
149
33
|
this._activeInterruptAbortMessage = undefined;
|
|
150
|
-
/** Messages queued to be included with the next user prompt as context ("asides"). */
|
|
151
34
|
this._pendingNextTurnMessages = [];
|
|
152
|
-
// Compaction state
|
|
153
35
|
this._compactionAbortController = undefined;
|
|
154
36
|
this._autoCompactionAbortController = undefined;
|
|
155
37
|
this._overflowRecoveryAttempted = false;
|
|
156
|
-
// Branch summarization state
|
|
157
38
|
this._branchSummaryAbortController = undefined;
|
|
158
|
-
// Retry state
|
|
159
39
|
this._retryAbortController = undefined;
|
|
160
40
|
this._retryAttempt = 0;
|
|
161
41
|
this._retryPromise = undefined;
|
|
162
42
|
this._retryResolve = undefined;
|
|
163
|
-
// Bash execution state
|
|
164
43
|
this._bashAbortController = undefined;
|
|
165
44
|
this._pendingBashMessages = [];
|
|
166
45
|
this._turnIndex = 0;
|
|
167
46
|
this._baseToolDefinitions = new Map();
|
|
168
47
|
this._extensionMode = "print";
|
|
169
|
-
// Tool registry for extension getTools/setTools
|
|
170
48
|
this._toolRegistry = new Map();
|
|
171
49
|
this._toolDefinitions = new Map();
|
|
172
50
|
this._toolPromptSnippets = new Map();
|
|
173
51
|
this._toolPromptGuidelines = new Map();
|
|
174
|
-
// Base system prompt (without extension appends) - used to apply fresh appends each turn
|
|
175
52
|
this._baseSystemPrompt = "";
|
|
176
|
-
// Track last assistant message for auto-compaction check
|
|
177
53
|
this._lastAssistantMessage = undefined;
|
|
178
|
-
/** Internal handler for agent events - shared by subscribe and reconnect */
|
|
179
|
-
this._handleAgentEvent = (event) => {
|
|
180
|
-
// Create retry promise synchronously before queueing async processing.
|
|
181
|
-
// Agent.emit() calls this handler synchronously, and prompt() calls waitForRetry()
|
|
182
|
-
// as soon as agent.prompt() resolves. If _retryPromise is created only inside
|
|
183
|
-
// _processAgentEvent, slow earlier queued events can delay agent_end processing
|
|
184
|
-
// and waitForRetry() can miss the in-flight retry.
|
|
185
|
-
this._createRetryPromiseForAgentEnd(event);
|
|
186
|
-
this._agentEventQueue = this._agentEventQueue.then(() => this._processAgentEvent(event), () => this._processAgentEvent(event));
|
|
187
|
-
// Keep queue alive if an event handler fails
|
|
188
|
-
this._agentEventQueue.catch(() => { });
|
|
189
|
-
};
|
|
190
54
|
this.agent = config.agent;
|
|
191
55
|
this.sessionManager = config.sessionManager;
|
|
192
56
|
this.settingsManager = config.settingsManager;
|
|
193
57
|
this._scopedModels = config.scopedModels ?? [];
|
|
194
58
|
this._resourceLoader = config.resourceLoader;
|
|
195
59
|
this._customTools = config.customTools ?? [];
|
|
196
|
-
this._bashPolicy = config.bashPolicy;
|
|
197
60
|
this._cwd = config.cwd;
|
|
198
61
|
this._modelRegistry = config.modelRegistry;
|
|
199
62
|
this._extensionRunnerRef = config.extensionRunnerRef;
|
|
@@ -203,3006 +66,16 @@ export class AgentSession {
|
|
|
203
66
|
this._baseToolsOverride = config.baseToolsOverride;
|
|
204
67
|
this._sessionStartEvent = config.sessionStartEvent ?? { type: "session_start", reason: "startup" };
|
|
205
68
|
this._orchestrationContext = config.orchestrationContext;
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
this._unsubscribeAgent = this.agent.subscribe(
|
|
209
|
-
|
|
210
|
-
|
|
69
|
+
const internals = this;
|
|
70
|
+
internals._handleAgentEvent = internals._handleAgentEvent.bind(this);
|
|
71
|
+
this._unsubscribeAgent = this.agent.subscribe(internals._handleAgentEvent);
|
|
72
|
+
internals._installAgentToolHooks();
|
|
73
|
+
internals._buildRuntime({
|
|
211
74
|
activeToolNames: this._initialActiveToolNames,
|
|
212
75
|
includeAllExtensionTools: true,
|
|
213
76
|
});
|
|
214
77
|
}
|
|
215
|
-
/** Orchestration context for this session, when owned by a workflow/subagent runtime. */
|
|
216
|
-
get orchestrationContext() {
|
|
217
|
-
return this._orchestrationContext;
|
|
218
|
-
}
|
|
219
|
-
/** Model registry for API key resolution and model discovery */
|
|
220
|
-
get modelRegistry() {
|
|
221
|
-
return this._modelRegistry;
|
|
222
|
-
}
|
|
223
|
-
async _getRequiredRequestAuth(model) {
|
|
224
|
-
const result = await this._modelRegistry.getApiKeyAndHeaders(model);
|
|
225
|
-
if (!result.ok) {
|
|
226
|
-
if (result.error.startsWith("No API key found")) {
|
|
227
|
-
throw new Error(formatNoApiKeyFoundMessage(model.provider));
|
|
228
|
-
}
|
|
229
|
-
throw new Error(result.error);
|
|
230
|
-
}
|
|
231
|
-
if (result.apiKey) {
|
|
232
|
-
return { apiKey: result.apiKey, headers: result.headers };
|
|
233
|
-
}
|
|
234
|
-
const isOAuth = this._modelRegistry.isUsingOAuth(model);
|
|
235
|
-
if (isOAuth) {
|
|
236
|
-
throw new Error(`Authentication failed for "${model.provider}". ` +
|
|
237
|
-
`Credentials may have expired or network is unavailable. ` +
|
|
238
|
-
`Run '/login ${model.provider}' to re-authenticate.`);
|
|
239
|
-
}
|
|
240
|
-
throw new Error(formatNoApiKeyFoundMessage(model.provider));
|
|
241
|
-
}
|
|
242
|
-
/**
|
|
243
|
-
* Install tool hooks once on the Agent instance.
|
|
244
|
-
*
|
|
245
|
-
* The callbacks read `this._extensionRunner` at execution time, so extension reload swaps in the
|
|
246
|
-
* new runner without reinstalling hooks. Extension-specific tool wrappers are still used to adapt
|
|
247
|
-
* registered tool execution to the extension context. Tool call and tool result interception now
|
|
248
|
-
* happens here instead of in wrappers.
|
|
249
|
-
*/
|
|
250
|
-
_installAgentToolHooks() {
|
|
251
|
-
this.agent.beforeToolCall = async ({ toolCall, args }) => {
|
|
252
|
-
const runner = this._extensionRunner;
|
|
253
|
-
if (!runner.hasHandlers("tool_call")) {
|
|
254
|
-
return undefined;
|
|
255
|
-
}
|
|
256
|
-
await this._agentEventQueue;
|
|
257
|
-
try {
|
|
258
|
-
return await runner.emitToolCall({
|
|
259
|
-
type: "tool_call",
|
|
260
|
-
toolName: toolCall.name,
|
|
261
|
-
toolCallId: toolCall.id,
|
|
262
|
-
input: args,
|
|
263
|
-
});
|
|
264
|
-
}
|
|
265
|
-
catch (err) {
|
|
266
|
-
if (err instanceof Error) {
|
|
267
|
-
throw err;
|
|
268
|
-
}
|
|
269
|
-
throw new Error(`Extension failed, blocking execution: ${String(err)}`);
|
|
270
|
-
}
|
|
271
|
-
};
|
|
272
|
-
this.agent.afterToolCall = async ({ toolCall, args, result, isError }) => {
|
|
273
|
-
const runner = this._extensionRunner;
|
|
274
|
-
const hookResult = runner.hasHandlers("tool_result")
|
|
275
|
-
? await runner.emitToolResult({
|
|
276
|
-
type: "tool_result",
|
|
277
|
-
toolName: toolCall.name,
|
|
278
|
-
toolCallId: toolCall.id,
|
|
279
|
-
input: args,
|
|
280
|
-
content: result.content,
|
|
281
|
-
details: result.details,
|
|
282
|
-
isError,
|
|
283
|
-
})
|
|
284
|
-
: undefined;
|
|
285
|
-
const extensionReplacement = hookResult
|
|
286
|
-
? {
|
|
287
|
-
content: hookResult.content,
|
|
288
|
-
details: hookResult.details,
|
|
289
|
-
isError: hookResult.isError ?? isError,
|
|
290
|
-
}
|
|
291
|
-
: undefined;
|
|
292
|
-
const finalResult = hookResult
|
|
293
|
-
? {
|
|
294
|
-
content: hookResult.content ?? result.content,
|
|
295
|
-
// Preserve original details when an extension hook rewrites only content;
|
|
296
|
-
// the redirect check only replaces model-visible content blocks.
|
|
297
|
-
details: hookResult.details ?? result.details,
|
|
298
|
-
}
|
|
299
|
-
: result;
|
|
300
|
-
const finalIsError = hookResult?.isError ?? isError;
|
|
301
|
-
const redirectReplacement = await redirectOversizedToolResult({
|
|
302
|
-
toolName: toolCall.name,
|
|
303
|
-
toolCallId: toolCall.id,
|
|
304
|
-
result: finalResult,
|
|
305
|
-
isError: finalIsError,
|
|
306
|
-
sessionId: this.sessionManager.getSessionId(),
|
|
307
|
-
sessionDir: this.sessionManager.getSessionDir() || undefined,
|
|
308
|
-
maxResultSizeChars: this.getToolDefinition(toolCall.name)?.maxResultSizeChars,
|
|
309
|
-
});
|
|
310
|
-
return redirectReplacement ?? extensionReplacement;
|
|
311
|
-
};
|
|
312
|
-
}
|
|
313
|
-
// =========================================================================
|
|
314
|
-
// Event Subscription
|
|
315
|
-
// =========================================================================
|
|
316
|
-
/** Emit an event to all listeners */
|
|
317
|
-
_emit(event) {
|
|
318
|
-
for (const l of this._eventListeners) {
|
|
319
|
-
l(event);
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
_emitQueueUpdate() {
|
|
323
|
-
this._emit({
|
|
324
|
-
type: "queue_update",
|
|
325
|
-
steering: [...this._steeringMessages],
|
|
326
|
-
followUp: [...this._followUpMessages],
|
|
327
|
-
});
|
|
328
|
-
}
|
|
329
|
-
_createRetryPromiseForAgentEnd(event) {
|
|
330
|
-
if (event.type !== "agent_end" || this._retryPromise) {
|
|
331
|
-
return;
|
|
332
|
-
}
|
|
333
|
-
const settings = this.settingsManager.getRetrySettings();
|
|
334
|
-
if (!settings.enabled) {
|
|
335
|
-
return;
|
|
336
|
-
}
|
|
337
|
-
const lastAssistant = this._findLastAssistantInMessages(event.messages);
|
|
338
|
-
if (!lastAssistant || !this._isRetryableError(lastAssistant)) {
|
|
339
|
-
return;
|
|
340
|
-
}
|
|
341
|
-
this._retryPromise = new Promise((resolve) => {
|
|
342
|
-
this._retryResolve = resolve;
|
|
343
|
-
});
|
|
344
|
-
}
|
|
345
|
-
_findLastAssistantInMessages(messages) {
|
|
346
|
-
for (let i = messages.length - 1; i >= 0; i--) {
|
|
347
|
-
const message = messages[i];
|
|
348
|
-
if (message.role === "assistant") {
|
|
349
|
-
return message;
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
return undefined;
|
|
353
|
-
}
|
|
354
|
-
async _processAgentEvent(event) {
|
|
355
|
-
// When a user message starts, check if it's from either queue and remove it BEFORE emitting
|
|
356
|
-
// This ensures the UI sees the updated queue state
|
|
357
|
-
if (event.type === "message_start" && event.message.role === "user") {
|
|
358
|
-
this._overflowRecoveryAttempted = false;
|
|
359
|
-
const messageText = this._getUserMessageText(event.message);
|
|
360
|
-
if (messageText) {
|
|
361
|
-
// Check steering queue first
|
|
362
|
-
const steeringIndex = this._steeringMessages.indexOf(messageText);
|
|
363
|
-
if (steeringIndex !== -1) {
|
|
364
|
-
this._steeringMessages.splice(steeringIndex, 1);
|
|
365
|
-
this._emitQueueUpdate();
|
|
366
|
-
}
|
|
367
|
-
else {
|
|
368
|
-
// Check follow-up queue
|
|
369
|
-
const followUpIndex = this._followUpMessages.indexOf(messageText);
|
|
370
|
-
if (followUpIndex !== -1) {
|
|
371
|
-
this._followUpMessages.splice(followUpIndex, 1);
|
|
372
|
-
this._emitQueueUpdate();
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
this._applyInterruptAbortMessage(event);
|
|
378
|
-
this._applyProviderErrorGuidance(event);
|
|
379
|
-
// Emit to extensions first
|
|
380
|
-
await this._emitExtensionEvent(event);
|
|
381
|
-
// Notify all listeners
|
|
382
|
-
this._emit(event);
|
|
383
|
-
// Handle session persistence
|
|
384
|
-
if (event.type === "message_end") {
|
|
385
|
-
// Check if this is a custom message from extensions
|
|
386
|
-
if (event.message.role === "custom") {
|
|
387
|
-
// Persist as CustomMessageEntry
|
|
388
|
-
this.sessionManager.appendCustomMessageEntry(event.message.customType, event.message.content, event.message.display, event.message.details, customMessageExcludesContext(event.message));
|
|
389
|
-
}
|
|
390
|
-
else if (event.message.role === "user" ||
|
|
391
|
-
event.message.role === "assistant" ||
|
|
392
|
-
event.message.role === "toolResult") {
|
|
393
|
-
if (event.message.role === "assistant") {
|
|
394
|
-
this._normalizePersistedGeminiToolArgs(event.message);
|
|
395
|
-
}
|
|
396
|
-
// Regular LLM message - persist as SessionMessageEntry
|
|
397
|
-
this.sessionManager.appendMessage(event.message);
|
|
398
|
-
}
|
|
399
|
-
// Other message types (bashExecution, branchSummary) are persisted elsewhere
|
|
400
|
-
// Track assistant message for auto-compaction (checked on agent_end)
|
|
401
|
-
if (event.message.role === "assistant") {
|
|
402
|
-
this._lastAssistantMessage = event.message;
|
|
403
|
-
const assistantMsg = event.message;
|
|
404
|
-
// Treat degenerate empty completions (no content, zero output tokens) as
|
|
405
|
-
// failures alongside stopReason === "error". Otherwise an empty turn that
|
|
406
|
-
// stops with reason "stop" would reset the retry counter on every attempt,
|
|
407
|
-
// causing unbounded retries instead of honoring maxRetries.
|
|
408
|
-
const assistantFailed = assistantMsg.stopReason === "error" || this._isEmptyCompletion(assistantMsg);
|
|
409
|
-
if (!assistantFailed) {
|
|
410
|
-
this._overflowRecoveryAttempted = false;
|
|
411
|
-
}
|
|
412
|
-
// Reset retry counter immediately on successful assistant response
|
|
413
|
-
// This prevents accumulation across multiple LLM calls within a turn
|
|
414
|
-
if (!assistantFailed && this._retryAttempt > 0) {
|
|
415
|
-
this._emit({
|
|
416
|
-
type: "auto_retry_end",
|
|
417
|
-
success: true,
|
|
418
|
-
attempt: this._retryAttempt,
|
|
419
|
-
});
|
|
420
|
-
this._retryAttempt = 0;
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
// Check auto-retry and auto-compaction after agent completes
|
|
425
|
-
if (event.type === "agent_end" && this._lastAssistantMessage) {
|
|
426
|
-
const msg = this._lastAssistantMessage;
|
|
427
|
-
this._lastAssistantMessage = undefined;
|
|
428
|
-
// Check for retryable errors first (overloaded, rate limit, server errors,
|
|
429
|
-
// transient provider finish_reason errors, or degenerate empty completions)
|
|
430
|
-
const retryableError = this._isRetryableError(msg);
|
|
431
|
-
const emptyCompletion = !retryableError && this._isEmptyCompletion(msg);
|
|
432
|
-
if (retryableError || emptyCompletion) {
|
|
433
|
-
if (emptyCompletion && !msg.errorMessage) {
|
|
434
|
-
// Surface a clear reason in the retry banner; empty completions carry no
|
|
435
|
-
// provider error message of their own.
|
|
436
|
-
msg.errorMessage = "Provider returned an empty completion";
|
|
437
|
-
}
|
|
438
|
-
const didRetry = await this._handleRetryableError(msg);
|
|
439
|
-
if (didRetry)
|
|
440
|
-
return; // Retry was initiated, don't proceed to compaction
|
|
441
|
-
}
|
|
442
|
-
this._resolveRetry();
|
|
443
|
-
await this._checkCompaction(msg);
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
_applyInterruptAbortMessage(event) {
|
|
447
|
-
const abortMessage = this._activeInterruptAbortMessage;
|
|
448
|
-
if (!abortMessage)
|
|
449
|
-
return;
|
|
450
|
-
if (event.type === "tool_execution_end" && event.isError && isSingleGenericAbortTextContent(event.result.content)) {
|
|
451
|
-
event.result.content = replacementAbortContent(abortMessage);
|
|
452
|
-
return;
|
|
453
|
-
}
|
|
454
|
-
if (event.type !== "message_start" && event.type !== "message_end")
|
|
455
|
-
return;
|
|
456
|
-
if (event.message.role === "toolResult" && event.message.isError && isSingleGenericAbortTextContent(event.message.content)) {
|
|
457
|
-
event.message.content = replacementAbortContent(abortMessage);
|
|
458
|
-
return;
|
|
459
|
-
}
|
|
460
|
-
if (event.message.role === "assistant") {
|
|
461
|
-
const assistantMessage = event.message;
|
|
462
|
-
if (assistantMessage.stopReason === "aborted") {
|
|
463
|
-
assistantMessage.errorMessage = abortMessage;
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
_applyProviderErrorGuidance(event) {
|
|
468
|
-
if (event.type !== "message_start" && event.type !== "message_update" && event.type !== "message_end")
|
|
469
|
-
return;
|
|
470
|
-
if (event.message.role !== "assistant")
|
|
471
|
-
return;
|
|
472
|
-
const assistantMessage = event.message;
|
|
473
|
-
if (assistantMessage.stopReason !== "error" || !assistantMessage.errorMessage)
|
|
474
|
-
return;
|
|
475
|
-
assistantMessage.errorMessage = formatCopilotProviderError(assistantMessage.provider, assistantMessage.errorMessage);
|
|
476
|
-
}
|
|
477
|
-
/** Resolve the pending retry promise */
|
|
478
|
-
_resolveRetry() {
|
|
479
|
-
if (this._retryResolve) {
|
|
480
|
-
this._retryResolve();
|
|
481
|
-
this._retryResolve = undefined;
|
|
482
|
-
this._retryPromise = undefined;
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
/** Extract text content from a message */
|
|
486
|
-
_getUserMessageText(message) {
|
|
487
|
-
if (message.role !== "user")
|
|
488
|
-
return "";
|
|
489
|
-
const content = message.content;
|
|
490
|
-
if (typeof content === "string")
|
|
491
|
-
return content;
|
|
492
|
-
const textBlocks = content.filter((c) => c.type === "text");
|
|
493
|
-
return textBlocks.map((c) => c.text).join("");
|
|
494
|
-
}
|
|
495
|
-
/** Find the last assistant message in agent state (including aborted ones) */
|
|
496
|
-
_findLastAssistantMessage() {
|
|
497
|
-
const messages = this.agent.state.messages;
|
|
498
|
-
for (let i = messages.length - 1; i >= 0; i--) {
|
|
499
|
-
const msg = messages[i];
|
|
500
|
-
if (msg.role === "assistant") {
|
|
501
|
-
return msg;
|
|
502
|
-
}
|
|
503
|
-
}
|
|
504
|
-
return undefined;
|
|
505
|
-
}
|
|
506
|
-
_replaceMessageInPlace(target, replacement) {
|
|
507
|
-
// Agent-core stores the finalized message object in its state before emitting message_end.
|
|
508
|
-
// SessionManager persistence happens later in _processAgentEvent() with event.message.
|
|
509
|
-
// Mutating this object in place keeps agent state, later turn/agent events, listeners,
|
|
510
|
-
// and the eventual SessionManager.appendMessage(event.message) persistence in sync.
|
|
511
|
-
if (target === replacement) {
|
|
512
|
-
return;
|
|
513
|
-
}
|
|
514
|
-
const targetRecord = target;
|
|
515
|
-
for (const key of Object.keys(targetRecord)) {
|
|
516
|
-
delete targetRecord[key];
|
|
517
|
-
}
|
|
518
|
-
Object.assign(targetRecord, replacement);
|
|
519
|
-
}
|
|
520
|
-
/** Emit extension events based on agent events */
|
|
521
|
-
async _emitExtensionEvent(event) {
|
|
522
|
-
if (event.type === "agent_start") {
|
|
523
|
-
this._turnIndex = 0;
|
|
524
|
-
await this._extensionRunner.emit({ type: "agent_start" });
|
|
525
|
-
}
|
|
526
|
-
else if (event.type === "agent_end") {
|
|
527
|
-
await this._extensionRunner.emit({ type: "agent_end", messages: event.messages });
|
|
528
|
-
}
|
|
529
|
-
else if (event.type === "turn_start") {
|
|
530
|
-
const extensionEvent = {
|
|
531
|
-
type: "turn_start",
|
|
532
|
-
turnIndex: this._turnIndex,
|
|
533
|
-
timestamp: Date.now(),
|
|
534
|
-
};
|
|
535
|
-
await this._extensionRunner.emit(extensionEvent);
|
|
536
|
-
}
|
|
537
|
-
else if (event.type === "turn_end") {
|
|
538
|
-
const extensionEvent = {
|
|
539
|
-
type: "turn_end",
|
|
540
|
-
turnIndex: this._turnIndex,
|
|
541
|
-
message: event.message,
|
|
542
|
-
toolResults: event.toolResults,
|
|
543
|
-
};
|
|
544
|
-
await this._extensionRunner.emit(extensionEvent);
|
|
545
|
-
this._turnIndex++;
|
|
546
|
-
}
|
|
547
|
-
else if (event.type === "message_start") {
|
|
548
|
-
const extensionEvent = {
|
|
549
|
-
type: "message_start",
|
|
550
|
-
message: event.message,
|
|
551
|
-
};
|
|
552
|
-
await this._extensionRunner.emit(extensionEvent);
|
|
553
|
-
}
|
|
554
|
-
else if (event.type === "message_update") {
|
|
555
|
-
const extensionEvent = {
|
|
556
|
-
type: "message_update",
|
|
557
|
-
message: event.message,
|
|
558
|
-
assistantMessageEvent: event.assistantMessageEvent,
|
|
559
|
-
};
|
|
560
|
-
await this._extensionRunner.emit(extensionEvent);
|
|
561
|
-
}
|
|
562
|
-
else if (event.type === "message_end") {
|
|
563
|
-
const extensionEvent = {
|
|
564
|
-
type: "message_end",
|
|
565
|
-
message: event.message,
|
|
566
|
-
};
|
|
567
|
-
const replacement = await this._extensionRunner.emitMessageEnd(extensionEvent);
|
|
568
|
-
if (replacement) {
|
|
569
|
-
this._replaceMessageInPlace(event.message, replacement);
|
|
570
|
-
}
|
|
571
|
-
}
|
|
572
|
-
else if (event.type === "tool_execution_start") {
|
|
573
|
-
const extensionEvent = {
|
|
574
|
-
type: "tool_execution_start",
|
|
575
|
-
toolCallId: event.toolCallId,
|
|
576
|
-
toolName: event.toolName,
|
|
577
|
-
args: event.args,
|
|
578
|
-
};
|
|
579
|
-
await this._extensionRunner.emit(extensionEvent);
|
|
580
|
-
}
|
|
581
|
-
else if (event.type === "tool_execution_update") {
|
|
582
|
-
const extensionEvent = {
|
|
583
|
-
type: "tool_execution_update",
|
|
584
|
-
toolCallId: event.toolCallId,
|
|
585
|
-
toolName: event.toolName,
|
|
586
|
-
args: event.args,
|
|
587
|
-
partialResult: event.partialResult,
|
|
588
|
-
};
|
|
589
|
-
await this._extensionRunner.emit(extensionEvent);
|
|
590
|
-
}
|
|
591
|
-
else if (event.type === "tool_execution_end") {
|
|
592
|
-
const extensionEvent = {
|
|
593
|
-
type: "tool_execution_end",
|
|
594
|
-
toolCallId: event.toolCallId,
|
|
595
|
-
toolName: event.toolName,
|
|
596
|
-
result: event.result,
|
|
597
|
-
isError: event.isError,
|
|
598
|
-
};
|
|
599
|
-
await this._extensionRunner.emit(extensionEvent);
|
|
600
|
-
}
|
|
601
|
-
}
|
|
602
|
-
/**
|
|
603
|
-
* Subscribe to agent events.
|
|
604
|
-
* Session persistence is handled internally (saves messages on message_end).
|
|
605
|
-
* Multiple listeners can be added. Returns unsubscribe function for this listener.
|
|
606
|
-
*/
|
|
607
|
-
subscribe(listener) {
|
|
608
|
-
this._eventListeners.push(listener);
|
|
609
|
-
// Return unsubscribe function for this specific listener
|
|
610
|
-
return () => {
|
|
611
|
-
const index = this._eventListeners.indexOf(listener);
|
|
612
|
-
if (index !== -1) {
|
|
613
|
-
this._eventListeners.splice(index, 1);
|
|
614
|
-
}
|
|
615
|
-
};
|
|
616
|
-
}
|
|
617
|
-
/**
|
|
618
|
-
* Temporarily disconnect from agent events.
|
|
619
|
-
* User listeners are preserved and will receive events again after resubscribe().
|
|
620
|
-
* Used internally during operations that need to pause event processing.
|
|
621
|
-
*/
|
|
622
|
-
_disconnectFromAgent() {
|
|
623
|
-
if (this._unsubscribeAgent) {
|
|
624
|
-
this._unsubscribeAgent();
|
|
625
|
-
this._unsubscribeAgent = undefined;
|
|
626
|
-
}
|
|
627
|
-
}
|
|
628
|
-
/**
|
|
629
|
-
* Reconnect to agent events after _disconnectFromAgent().
|
|
630
|
-
* Preserves all existing listeners.
|
|
631
|
-
*/
|
|
632
|
-
_reconnectToAgent() {
|
|
633
|
-
if (this._unsubscribeAgent)
|
|
634
|
-
return; // Already connected
|
|
635
|
-
this._unsubscribeAgent = this.agent.subscribe(this._handleAgentEvent);
|
|
636
|
-
}
|
|
637
|
-
/**
|
|
638
|
-
* Remove all listeners and disconnect from agent.
|
|
639
|
-
* Call this when completely done with the session.
|
|
640
|
-
*/
|
|
641
|
-
dispose() {
|
|
642
|
-
this._extensionRunner.invalidate("This extension ctx is stale after session replacement or reload. Do not use a captured pi or command ctx after ctx.newSession(), ctx.fork(), ctx.switchSession(), or ctx.reload(). For newSession, fork, and switchSession, move post-replacement work into withSession and use the ctx passed to withSession. For reload, do not use the old ctx after await ctx.reload().");
|
|
643
|
-
this._disconnectFromAgent();
|
|
644
|
-
this._eventListeners = [];
|
|
645
|
-
cleanupSessionResources(this.sessionId);
|
|
646
|
-
}
|
|
647
|
-
// =========================================================================
|
|
648
|
-
// Read-only State Access
|
|
649
|
-
// =========================================================================
|
|
650
|
-
/** Full agent state */
|
|
651
|
-
get state() {
|
|
652
|
-
return this.agent.state;
|
|
653
|
-
}
|
|
654
|
-
/** Current model (may be undefined if not yet selected) */
|
|
655
|
-
get model() {
|
|
656
|
-
return this.agent.state.model;
|
|
657
|
-
}
|
|
658
|
-
/** Current thinking level */
|
|
659
|
-
get thinkingLevel() {
|
|
660
|
-
return this.agent.state.thinkingLevel;
|
|
661
|
-
}
|
|
662
|
-
/** Whether agent is currently streaming a response */
|
|
663
|
-
get isStreaming() {
|
|
664
|
-
return this.agent.state.isStreaming;
|
|
665
|
-
}
|
|
666
|
-
/** Current effective system prompt (includes any per-turn extension modifications) */
|
|
667
|
-
get systemPrompt() {
|
|
668
|
-
return this.agent.state.systemPrompt;
|
|
669
|
-
}
|
|
670
|
-
/** Current retry attempt (0 if not retrying) */
|
|
671
|
-
get retryAttempt() {
|
|
672
|
-
return this._retryAttempt;
|
|
673
|
-
}
|
|
674
|
-
/**
|
|
675
|
-
* Get the names of currently active tools.
|
|
676
|
-
* Returns the names of tools currently set on the agent.
|
|
677
|
-
*/
|
|
678
|
-
getActiveToolNames() {
|
|
679
|
-
return this.agent.state.tools.map((t) => t.name);
|
|
680
|
-
}
|
|
681
|
-
/**
|
|
682
|
-
* Get all configured tools with name, description, parameter schema, and source metadata.
|
|
683
|
-
*/
|
|
684
|
-
getAllTools() {
|
|
685
|
-
return Array.from(this._toolDefinitions.values()).map(({ definition, sourceInfo }) => ({
|
|
686
|
-
name: definition.name,
|
|
687
|
-
description: definition.description,
|
|
688
|
-
parameters: definition.parameters,
|
|
689
|
-
promptGuidelines: definition.promptGuidelines,
|
|
690
|
-
sourceInfo,
|
|
691
|
-
}));
|
|
692
|
-
}
|
|
693
|
-
getToolDefinition(name) {
|
|
694
|
-
return this._toolDefinitions.get(name)?.definition;
|
|
695
|
-
}
|
|
696
|
-
/**
|
|
697
|
-
* Set active tools by name.
|
|
698
|
-
* Only tools in the registry can be enabled. Unknown tool names are ignored.
|
|
699
|
-
* Also rebuilds the system prompt to reflect the new tool set.
|
|
700
|
-
* Changes take effect on the next agent turn.
|
|
701
|
-
*/
|
|
702
|
-
setActiveToolsByName(toolNames) {
|
|
703
|
-
const tools = [];
|
|
704
|
-
const validToolNames = [];
|
|
705
|
-
for (const name of toolNames) {
|
|
706
|
-
const tool = this._toolRegistry.get(name);
|
|
707
|
-
if (tool) {
|
|
708
|
-
tools.push(tool);
|
|
709
|
-
validToolNames.push(name);
|
|
710
|
-
}
|
|
711
|
-
}
|
|
712
|
-
this.agent.state.tools = tools;
|
|
713
|
-
// Rebuild base system prompt with new tool set
|
|
714
|
-
this._baseSystemPrompt = this._rebuildSystemPrompt(validToolNames);
|
|
715
|
-
this.agent.state.systemPrompt = this._baseSystemPrompt;
|
|
716
|
-
}
|
|
717
|
-
/** Whether compaction or branch summarization is currently running */
|
|
718
|
-
get isCompacting() {
|
|
719
|
-
return (this._autoCompactionAbortController !== undefined ||
|
|
720
|
-
this._compactionAbortController !== undefined ||
|
|
721
|
-
this._branchSummaryAbortController !== undefined);
|
|
722
|
-
}
|
|
723
|
-
/** All messages including custom types like BashExecutionMessage */
|
|
724
|
-
get messages() {
|
|
725
|
-
return this.agent.state.messages;
|
|
726
|
-
}
|
|
727
|
-
/** Current steering mode */
|
|
728
|
-
get steeringMode() {
|
|
729
|
-
return this.agent.steeringMode;
|
|
730
|
-
}
|
|
731
|
-
/** Current follow-up mode */
|
|
732
|
-
get followUpMode() {
|
|
733
|
-
return this.agent.followUpMode;
|
|
734
|
-
}
|
|
735
|
-
/** Current session file path, or undefined if sessions are disabled */
|
|
736
|
-
get sessionFile() {
|
|
737
|
-
return this.sessionManager.getSessionFile();
|
|
738
|
-
}
|
|
739
|
-
/** Current session ID */
|
|
740
|
-
get sessionId() {
|
|
741
|
-
return this.sessionManager.getSessionId();
|
|
742
|
-
}
|
|
743
|
-
/** Current session display name, if set */
|
|
744
|
-
get sessionName() {
|
|
745
|
-
return this.sessionManager.getSessionName();
|
|
746
|
-
}
|
|
747
|
-
/** Scoped models for cycling (from --models flag) */
|
|
748
|
-
get scopedModels() {
|
|
749
|
-
return this._scopedModels;
|
|
750
|
-
}
|
|
751
|
-
/** Update scoped models for cycling */
|
|
752
|
-
setScopedModels(scopedModels) {
|
|
753
|
-
this._scopedModels = scopedModels;
|
|
754
|
-
}
|
|
755
|
-
/** File-based prompt templates */
|
|
756
|
-
get promptTemplates() {
|
|
757
|
-
return this._resourceLoader.getPrompts().prompts;
|
|
758
|
-
}
|
|
759
|
-
_normalizePromptSnippet(text) {
|
|
760
|
-
if (!text)
|
|
761
|
-
return undefined;
|
|
762
|
-
const oneLine = text
|
|
763
|
-
.replace(/[\r\n]+/g, " ")
|
|
764
|
-
.replace(/\s+/g, " ")
|
|
765
|
-
.trim();
|
|
766
|
-
return oneLine.length > 0 ? oneLine : undefined;
|
|
767
|
-
}
|
|
768
|
-
_normalizePromptGuidelines(guidelines) {
|
|
769
|
-
if (!guidelines || guidelines.length === 0) {
|
|
770
|
-
return [];
|
|
771
|
-
}
|
|
772
|
-
const unique = new Set();
|
|
773
|
-
for (const guideline of guidelines) {
|
|
774
|
-
const normalized = guideline.trim();
|
|
775
|
-
if (normalized.length > 0) {
|
|
776
|
-
unique.add(normalized);
|
|
777
|
-
}
|
|
778
|
-
}
|
|
779
|
-
return Array.from(unique);
|
|
780
|
-
}
|
|
781
|
-
_rebuildSystemPrompt(toolNames) {
|
|
782
|
-
const validToolNames = toolNames.filter((name) => this._toolRegistry.has(name));
|
|
783
|
-
const toolSnippets = {};
|
|
784
|
-
const promptGuidelines = [];
|
|
785
|
-
for (const name of validToolNames) {
|
|
786
|
-
const snippet = this._toolPromptSnippets.get(name);
|
|
787
|
-
if (snippet) {
|
|
788
|
-
toolSnippets[name] = snippet;
|
|
789
|
-
}
|
|
790
|
-
const toolGuidelines = this._toolPromptGuidelines.get(name);
|
|
791
|
-
if (toolGuidelines) {
|
|
792
|
-
promptGuidelines.push(...toolGuidelines);
|
|
793
|
-
}
|
|
794
|
-
}
|
|
795
|
-
const loaderSystemPrompt = this._resourceLoader.getSystemPrompt();
|
|
796
|
-
const loaderAppendSystemPrompt = this._resourceLoader.getAppendSystemPrompt();
|
|
797
|
-
const appendSystemPrompt = loaderAppendSystemPrompt.length > 0 ? loaderAppendSystemPrompt.join("\n\n") : undefined;
|
|
798
|
-
const loadedSkills = this._resourceLoader.getSkills().skills;
|
|
799
|
-
const loadedContextFiles = this._resourceLoader.getAgentsFiles().agentsFiles;
|
|
800
|
-
this._baseSystemPromptOptions = {
|
|
801
|
-
cwd: this._cwd,
|
|
802
|
-
selectedModel: this.model,
|
|
803
|
-
selectedThinkingLevel: this.thinkingLevel,
|
|
804
|
-
skills: loadedSkills,
|
|
805
|
-
contextFiles: loadedContextFiles,
|
|
806
|
-
customPrompt: loaderSystemPrompt,
|
|
807
|
-
appendSystemPrompt,
|
|
808
|
-
selectedTools: validToolNames,
|
|
809
|
-
excludedTools: this._excludedToolNames ? Array.from(this._excludedToolNames) : undefined,
|
|
810
|
-
toolSnippets,
|
|
811
|
-
promptGuidelines,
|
|
812
|
-
};
|
|
813
|
-
return buildSystemPrompt(this._baseSystemPromptOptions);
|
|
814
|
-
}
|
|
815
|
-
_refreshBaseSystemPromptFromActiveTools() {
|
|
816
|
-
this._baseSystemPrompt = this._rebuildSystemPrompt(this.getActiveToolNames());
|
|
817
|
-
this.agent.state.systemPrompt = this._baseSystemPrompt;
|
|
818
|
-
}
|
|
819
|
-
// =========================================================================
|
|
820
|
-
// Prompting
|
|
821
|
-
// =========================================================================
|
|
822
|
-
/**
|
|
823
|
-
* Send a prompt to the agent.
|
|
824
|
-
* - Handles extension commands (registered via pi.registerCommand) immediately, even during streaming
|
|
825
|
-
* - Expands file-based prompt templates by default
|
|
826
|
-
* - During streaming, queues via steer() or followUp() based on streamingBehavior option
|
|
827
|
-
* - Validates model and API key before sending (when not streaming)
|
|
828
|
-
* @throws Error if streaming and no streamingBehavior specified
|
|
829
|
-
* @throws Error if no model selected or no API key available (when not streaming)
|
|
830
|
-
*/
|
|
831
|
-
async prompt(text, options) {
|
|
832
|
-
const expandPromptTemplates = options?.expandPromptTemplates ?? true;
|
|
833
|
-
const preflightResult = options?.preflightResult;
|
|
834
|
-
let messages;
|
|
835
|
-
try {
|
|
836
|
-
// Handle slash commands first (execute immediately, even during streaming).
|
|
837
|
-
// Builtin and extension commands manage their own LLM interaction via custom messages.
|
|
838
|
-
if (expandPromptTemplates && text.startsWith("/")) {
|
|
839
|
-
const handledBuiltin = await this._tryExecuteBuiltinSlashCommand(text);
|
|
840
|
-
if (handledBuiltin) {
|
|
841
|
-
preflightResult?.(true);
|
|
842
|
-
return;
|
|
843
|
-
}
|
|
844
|
-
const handledExtension = await this._tryExecuteExtensionCommand(text);
|
|
845
|
-
if (handledExtension) {
|
|
846
|
-
preflightResult?.(true);
|
|
847
|
-
return;
|
|
848
|
-
}
|
|
849
|
-
}
|
|
850
|
-
// Emit input event for extension interception (before skill/template expansion)
|
|
851
|
-
let currentText = text;
|
|
852
|
-
let currentImages = options?.images;
|
|
853
|
-
if (this._extensionRunner.hasHandlers("input")) {
|
|
854
|
-
const inputResult = await this._extensionRunner.emitInput(currentText, currentImages, options?.source ?? "interactive", this.isStreaming ? options?.streamingBehavior : undefined);
|
|
855
|
-
if (inputResult.action === "handled") {
|
|
856
|
-
preflightResult?.(true);
|
|
857
|
-
return;
|
|
858
|
-
}
|
|
859
|
-
if (inputResult.action === "transform") {
|
|
860
|
-
currentText = inputResult.text;
|
|
861
|
-
currentImages = inputResult.images ?? currentImages;
|
|
862
|
-
}
|
|
863
|
-
}
|
|
864
|
-
// Expand skill commands (/skill:name args) and prompt templates (/template args)
|
|
865
|
-
let expandedText = currentText;
|
|
866
|
-
if (expandPromptTemplates) {
|
|
867
|
-
expandedText = this._expandSkillCommand(expandedText);
|
|
868
|
-
expandedText = expandPromptTemplate(expandedText, [...this.promptTemplates]);
|
|
869
|
-
}
|
|
870
|
-
// If streaming, queue via steer() or followUp() based on option
|
|
871
|
-
if (this.isStreaming) {
|
|
872
|
-
if (!options?.streamingBehavior) {
|
|
873
|
-
throw new Error("Agent is already processing. Specify streamingBehavior ('steer' or 'followUp') to queue the message.");
|
|
874
|
-
}
|
|
875
|
-
if (options.streamingBehavior === "followUp") {
|
|
876
|
-
await this._queueFollowUp(expandedText, currentImages);
|
|
877
|
-
}
|
|
878
|
-
else {
|
|
879
|
-
await this._queueSteer(expandedText, currentImages);
|
|
880
|
-
}
|
|
881
|
-
preflightResult?.(true);
|
|
882
|
-
return;
|
|
883
|
-
}
|
|
884
|
-
// Flush any pending bash messages before the new prompt
|
|
885
|
-
this._flushPendingBashMessages();
|
|
886
|
-
// Validate model
|
|
887
|
-
if (!this.model) {
|
|
888
|
-
throw new Error(formatNoModelSelectedMessage());
|
|
889
|
-
}
|
|
890
|
-
// Defensive guard: a model that never resolved to a real provider
|
|
891
|
-
// (for example an unknown/unresolved model id that reached this path
|
|
892
|
-
// as a bare string) has no `provider`, which would otherwise fail deep
|
|
893
|
-
// in auth resolution as the confusing "No API key found for undefined".
|
|
894
|
-
// Surface a clear, accurate "unknown model" error instead.
|
|
895
|
-
const resolvedProvider = this.model.provider;
|
|
896
|
-
if (typeof resolvedProvider !== "string" || resolvedProvider.length === 0) {
|
|
897
|
-
throw new Error(formatUnresolvedModelMessage(this.model));
|
|
898
|
-
}
|
|
899
|
-
if (!this._modelRegistry.hasConfiguredAuth(this.model)) {
|
|
900
|
-
// A failed credential-store load (for example auth.json briefly locked
|
|
901
|
-
// by a concurrent process, or invalid JSON) leaves an empty in-memory
|
|
902
|
-
// credential set. That would otherwise be misreported here as
|
|
903
|
-
// "No API key found" even though the credentials exist on disk. Surface
|
|
904
|
-
// the real load failure instead so configured providers are not falsely
|
|
905
|
-
// reported as unauthenticated (issue #1431).
|
|
906
|
-
const authLoadError = this._modelRegistry.authStorage.getLoadError();
|
|
907
|
-
if (authLoadError) {
|
|
908
|
-
throw new Error(formatAuthStorageLoadFailedMessage(this.model.provider, authLoadError), { cause: authLoadError });
|
|
909
|
-
}
|
|
910
|
-
const isOAuth = this._modelRegistry.isUsingOAuth(this.model);
|
|
911
|
-
if (isOAuth) {
|
|
912
|
-
throw new Error(`Authentication failed for "${this.model.provider}". ` +
|
|
913
|
-
`Credentials may have expired or network is unavailable. ` +
|
|
914
|
-
`Run '/login ${this.model.provider}' to re-authenticate.`);
|
|
915
|
-
}
|
|
916
|
-
throw new Error(formatNoApiKeyFoundMessage(this.model.provider));
|
|
917
|
-
}
|
|
918
|
-
// Check if we need to compact before sending (catches aborted responses)
|
|
919
|
-
const lastAssistant = this._findLastAssistantMessage();
|
|
920
|
-
if (lastAssistant) {
|
|
921
|
-
await this._checkCompaction(lastAssistant, false);
|
|
922
|
-
}
|
|
923
|
-
// Build messages array (custom message if any, then user message)
|
|
924
|
-
messages = [];
|
|
925
|
-
// Add user message
|
|
926
|
-
const userContent = [{ type: "text", text: expandedText }];
|
|
927
|
-
if (currentImages) {
|
|
928
|
-
userContent.push(...currentImages);
|
|
929
|
-
}
|
|
930
|
-
messages.push({
|
|
931
|
-
role: "user",
|
|
932
|
-
content: userContent,
|
|
933
|
-
timestamp: Date.now(),
|
|
934
|
-
});
|
|
935
|
-
// Inject any pending "nextTurn" messages as context alongside the user message
|
|
936
|
-
for (const msg of this._pendingNextTurnMessages) {
|
|
937
|
-
messages.push(msg);
|
|
938
|
-
}
|
|
939
|
-
this._pendingNextTurnMessages = [];
|
|
940
|
-
// Emit before_agent_start extension event
|
|
941
|
-
const result = await this._extensionRunner.emitBeforeAgentStart(expandedText, currentImages, this._baseSystemPrompt, this._baseSystemPromptOptions);
|
|
942
|
-
// Add all custom messages from extensions
|
|
943
|
-
if (result?.messages) {
|
|
944
|
-
for (const msg of result.messages) {
|
|
945
|
-
messages.push({
|
|
946
|
-
role: "custom",
|
|
947
|
-
customType: msg.customType,
|
|
948
|
-
content: msg.content,
|
|
949
|
-
display: msg.display,
|
|
950
|
-
details: msg.details,
|
|
951
|
-
timestamp: Date.now(),
|
|
952
|
-
});
|
|
953
|
-
}
|
|
954
|
-
}
|
|
955
|
-
// Apply extension-modified system prompt, or reset to base
|
|
956
|
-
if (result?.systemPrompt) {
|
|
957
|
-
this.agent.state.systemPrompt = result.systemPrompt;
|
|
958
|
-
}
|
|
959
|
-
else {
|
|
960
|
-
// Ensure we're using the base prompt (in case previous turn had modifications)
|
|
961
|
-
this.agent.state.systemPrompt = this._baseSystemPrompt;
|
|
962
|
-
}
|
|
963
|
-
}
|
|
964
|
-
catch (error) {
|
|
965
|
-
preflightResult?.(false);
|
|
966
|
-
throw error;
|
|
967
|
-
}
|
|
968
|
-
if (!messages) {
|
|
969
|
-
return;
|
|
970
|
-
}
|
|
971
|
-
preflightResult?.(true);
|
|
972
|
-
await this._runAgentPrompt(messages);
|
|
973
|
-
}
|
|
974
|
-
async _runAgentPrompt(messages) {
|
|
975
|
-
await this.agent.prompt(messages);
|
|
976
|
-
await this.waitForRetry();
|
|
977
|
-
await this._continueQueuedAgentMessages();
|
|
978
|
-
}
|
|
979
|
-
async _continueQueuedAgentMessages() {
|
|
980
|
-
await this._agentEventQueue;
|
|
981
|
-
while (this.agent.hasQueuedMessages()) {
|
|
982
|
-
await this.agent.continue();
|
|
983
|
-
await this.waitForRetry();
|
|
984
|
-
await this._agentEventQueue;
|
|
985
|
-
}
|
|
986
|
-
}
|
|
987
|
-
/**
|
|
988
|
-
* Try to execute a built-in slash command. Returns true if command was found and executed.
|
|
989
|
-
*/
|
|
990
|
-
async _tryExecuteBuiltinSlashCommand(text) {
|
|
991
|
-
const spaceIndex = text.indexOf(" ");
|
|
992
|
-
const commandName = spaceIndex === -1 ? text.slice(1) : text.slice(1, spaceIndex);
|
|
993
|
-
if (commandName !== ATOMIC_GUIDE_COMMAND_NAME)
|
|
994
|
-
return false;
|
|
995
|
-
const args = spaceIndex === -1 ? "" : text.slice(spaceIndex + 1);
|
|
996
|
-
const mode = normalizeAtomicGuideMode(args);
|
|
997
|
-
if (mode === "help" && this._extensionUIContext) {
|
|
998
|
-
const choice = await this._extensionUIContext.select("Atomic. Select where to start:", [
|
|
999
|
-
...ATOMIC_GUIDE_HELP_CHOICES,
|
|
1000
|
-
]);
|
|
1001
|
-
if (!choice || !isAtomicGuideHelpChoice(choice))
|
|
1002
|
-
return true;
|
|
1003
|
-
await this.sendCustomMessage({
|
|
1004
|
-
customType: "atomic",
|
|
1005
|
-
content: getAtomicGuideMessage(atomicGuideModeForChoice(choice), this._cwd),
|
|
1006
|
-
display: true,
|
|
1007
|
-
}, { triggerTurn: false });
|
|
1008
|
-
return true;
|
|
1009
|
-
}
|
|
1010
|
-
await this.sendCustomMessage({
|
|
1011
|
-
customType: "atomic",
|
|
1012
|
-
content: getAtomicGuideMessage(mode, this._cwd),
|
|
1013
|
-
display: true,
|
|
1014
|
-
}, { triggerTurn: false });
|
|
1015
|
-
return true;
|
|
1016
|
-
}
|
|
1017
|
-
/**
|
|
1018
|
-
* Try to execute an extension command. Returns true if command was found and executed.
|
|
1019
|
-
*/
|
|
1020
|
-
async _tryExecuteExtensionCommand(text) {
|
|
1021
|
-
// Parse command name and args
|
|
1022
|
-
const spaceIndex = text.indexOf(" ");
|
|
1023
|
-
const commandName = spaceIndex === -1 ? text.slice(1) : text.slice(1, spaceIndex);
|
|
1024
|
-
const args = spaceIndex === -1 ? "" : text.slice(spaceIndex + 1);
|
|
1025
|
-
const command = this._extensionRunner.getCommand(commandName);
|
|
1026
|
-
if (!command)
|
|
1027
|
-
return false;
|
|
1028
|
-
// Get command context from extension runner (includes session control methods)
|
|
1029
|
-
const ctx = this._extensionRunner.createCommandContext();
|
|
1030
|
-
try {
|
|
1031
|
-
await command.handler(args, ctx);
|
|
1032
|
-
return true;
|
|
1033
|
-
}
|
|
1034
|
-
catch (err) {
|
|
1035
|
-
// Emit error via extension runner
|
|
1036
|
-
this._extensionRunner.emitError({
|
|
1037
|
-
extensionPath: `command:${commandName}`,
|
|
1038
|
-
event: "command",
|
|
1039
|
-
error: err instanceof Error ? err.message : String(err),
|
|
1040
|
-
});
|
|
1041
|
-
return true;
|
|
1042
|
-
}
|
|
1043
|
-
}
|
|
1044
|
-
/**
|
|
1045
|
-
* Expand skill commands (/skill:name args) to their full content.
|
|
1046
|
-
* Returns the expanded text, or the original text if not a skill command or skill not found.
|
|
1047
|
-
* Emits errors via extension runner if file read fails.
|
|
1048
|
-
*/
|
|
1049
|
-
_expandSkillCommand(text) {
|
|
1050
|
-
if (!text.startsWith("/skill:"))
|
|
1051
|
-
return text;
|
|
1052
|
-
const spaceIndex = text.indexOf(" ");
|
|
1053
|
-
const skillName = spaceIndex === -1 ? text.slice(7) : text.slice(7, spaceIndex);
|
|
1054
|
-
const args = spaceIndex === -1 ? "" : text.slice(spaceIndex + 1).trim();
|
|
1055
|
-
const skill = this.resourceLoader.getSkills().skills.find((s) => s.name === skillName);
|
|
1056
|
-
if (!skill)
|
|
1057
|
-
return text; // Unknown skill, pass through
|
|
1058
|
-
try {
|
|
1059
|
-
const content = readFileSync(skill.filePath, "utf-8");
|
|
1060
|
-
const body = stripFrontmatter(content).trim();
|
|
1061
|
-
const skillBlock = `<skill name="${skill.name}" location="${skill.filePath}">\nReferences are relative to ${skill.baseDir}.\n\n${body}\n</skill>`;
|
|
1062
|
-
return args ? `${skillBlock}\n\n${args}` : skillBlock;
|
|
1063
|
-
}
|
|
1064
|
-
catch (err) {
|
|
1065
|
-
// Emit error like extension commands do
|
|
1066
|
-
this._extensionRunner.emitError({
|
|
1067
|
-
extensionPath: skill.filePath,
|
|
1068
|
-
event: "skill_expansion",
|
|
1069
|
-
error: err instanceof Error ? err.message : String(err),
|
|
1070
|
-
});
|
|
1071
|
-
return text; // Return original on error
|
|
1072
|
-
}
|
|
1073
|
-
}
|
|
1074
|
-
/**
|
|
1075
|
-
* Queue a steering message while the agent is running.
|
|
1076
|
-
* Delivered after the current assistant turn finishes executing its tool calls,
|
|
1077
|
-
* before the next LLM call.
|
|
1078
|
-
* Expands skill commands and prompt templates. Errors on extension commands.
|
|
1079
|
-
* @param images Optional image attachments to include with the message
|
|
1080
|
-
* @throws Error if text is an extension command
|
|
1081
|
-
*/
|
|
1082
|
-
async steer(text, images) {
|
|
1083
|
-
// Check for extension commands (cannot be queued)
|
|
1084
|
-
if (text.startsWith("/")) {
|
|
1085
|
-
this._throwIfExtensionCommand(text);
|
|
1086
|
-
}
|
|
1087
|
-
// Expand skill commands and prompt templates
|
|
1088
|
-
let expandedText = this._expandSkillCommand(text);
|
|
1089
|
-
expandedText = expandPromptTemplate(expandedText, [...this.promptTemplates]);
|
|
1090
|
-
await this._queueSteer(expandedText, images);
|
|
1091
|
-
}
|
|
1092
|
-
/**
|
|
1093
|
-
* Queue a follow-up message to be processed after the agent finishes.
|
|
1094
|
-
* Delivered only when agent has no more tool calls or steering messages.
|
|
1095
|
-
* Expands skill commands and prompt templates. Errors on extension commands.
|
|
1096
|
-
* @param images Optional image attachments to include with the message
|
|
1097
|
-
* @throws Error if text is an extension command
|
|
1098
|
-
*/
|
|
1099
|
-
async followUp(text, images) {
|
|
1100
|
-
// Check for extension commands (cannot be queued)
|
|
1101
|
-
if (text.startsWith("/")) {
|
|
1102
|
-
this._throwIfExtensionCommand(text);
|
|
1103
|
-
}
|
|
1104
|
-
// Expand skill commands and prompt templates
|
|
1105
|
-
let expandedText = this._expandSkillCommand(text);
|
|
1106
|
-
expandedText = expandPromptTemplate(expandedText, [...this.promptTemplates]);
|
|
1107
|
-
await this._queueFollowUp(expandedText, images);
|
|
1108
|
-
}
|
|
1109
|
-
/**
|
|
1110
|
-
* Internal: Queue a steering message (already expanded, no extension command check).
|
|
1111
|
-
*/
|
|
1112
|
-
async _queueSteer(text, images) {
|
|
1113
|
-
this._steeringMessages.push(text);
|
|
1114
|
-
this._emitQueueUpdate();
|
|
1115
|
-
const content = [{ type: "text", text }];
|
|
1116
|
-
if (images) {
|
|
1117
|
-
content.push(...images);
|
|
1118
|
-
}
|
|
1119
|
-
this._queueAgentMessage({
|
|
1120
|
-
role: "user",
|
|
1121
|
-
content,
|
|
1122
|
-
timestamp: Date.now(),
|
|
1123
|
-
}, "steer");
|
|
1124
|
-
}
|
|
1125
|
-
/**
|
|
1126
|
-
* Internal: Queue a follow-up message (already expanded, no extension command check).
|
|
1127
|
-
*/
|
|
1128
|
-
async _queueFollowUp(text, images) {
|
|
1129
|
-
this._followUpMessages.push(text);
|
|
1130
|
-
this._emitQueueUpdate();
|
|
1131
|
-
const content = [{ type: "text", text }];
|
|
1132
|
-
if (images) {
|
|
1133
|
-
content.push(...images);
|
|
1134
|
-
}
|
|
1135
|
-
this._queueAgentMessage({
|
|
1136
|
-
role: "user",
|
|
1137
|
-
content,
|
|
1138
|
-
timestamp: Date.now(),
|
|
1139
|
-
}, "followUp");
|
|
1140
|
-
}
|
|
1141
|
-
/**
|
|
1142
|
-
* Throw an error if the text is an extension command.
|
|
1143
|
-
*/
|
|
1144
|
-
_throwIfExtensionCommand(text) {
|
|
1145
|
-
const spaceIndex = text.indexOf(" ");
|
|
1146
|
-
const commandName = spaceIndex === -1 ? text.slice(1) : text.slice(1, spaceIndex);
|
|
1147
|
-
const command = this._extensionRunner.getCommand(commandName);
|
|
1148
|
-
if (command) {
|
|
1149
|
-
throw new Error(`Extension command "/${commandName}" cannot be queued. Use prompt() or execute the command when not streaming.`);
|
|
1150
|
-
}
|
|
1151
|
-
}
|
|
1152
|
-
/**
|
|
1153
|
-
* Send a custom message to the session. Creates a CustomMessageEntry.
|
|
1154
|
-
*
|
|
1155
|
-
* Handles five cases:
|
|
1156
|
-
* - Streaming + interrupt trigger: aborts the active run and starts an immediate custom-message turn
|
|
1157
|
-
* - Streaming + explicit display-only context exclusion: appends to state/session, no turn and no queue
|
|
1158
|
-
* - Streaming otherwise: queues message, processed when loop pulls from queue
|
|
1159
|
-
* - Not streaming + triggerTurn: appends to state/session, starts new turn
|
|
1160
|
-
* - Not streaming + no trigger: appends to state/session, no turn
|
|
1161
|
-
*
|
|
1162
|
-
* @param message Custom message with customType, content, display, details
|
|
1163
|
-
* @param options.triggerTurn If true and not streaming, triggers a new LLM turn
|
|
1164
|
-
* @param options.deliverAs Delivery mode: "steer", "followUp", "nextTurn", or "interrupt"
|
|
1165
|
-
*/
|
|
1166
|
-
async sendCustomMessage(message, options) {
|
|
1167
|
-
const appMessage = {
|
|
1168
|
-
role: "custom",
|
|
1169
|
-
customType: message.customType,
|
|
1170
|
-
content: message.content,
|
|
1171
|
-
display: message.display,
|
|
1172
|
-
details: message.details,
|
|
1173
|
-
timestamp: Date.now(),
|
|
1174
|
-
...(options?.excludeFromContext === true ? { excludeFromContext: true } : {}),
|
|
1175
|
-
};
|
|
1176
|
-
if (options?.deliverAs === "nextTurn") {
|
|
1177
|
-
this._pendingNextTurnMessages.push(appMessage);
|
|
1178
|
-
}
|
|
1179
|
-
else if (options?.deliverAs === "interrupt" && options.triggerTurn) {
|
|
1180
|
-
await this._enqueueInterruptCustomMessage(appMessage, options);
|
|
1181
|
-
}
|
|
1182
|
-
else if (this.isStreaming && options?.excludeFromContext === true && options.triggerTurn !== true && options.deliverAs === undefined) {
|
|
1183
|
-
this._appendCustomMessage(appMessage);
|
|
1184
|
-
}
|
|
1185
|
-
else if (this.isStreaming) {
|
|
1186
|
-
this._queueAgentMessage(appMessage, options?.deliverAs === "followUp" ? "followUp" : "steer");
|
|
1187
|
-
}
|
|
1188
|
-
else if (options?.triggerTurn) {
|
|
1189
|
-
await this._runAgentPrompt(appMessage);
|
|
1190
|
-
}
|
|
1191
|
-
else {
|
|
1192
|
-
this._appendCustomMessage(appMessage);
|
|
1193
|
-
}
|
|
1194
|
-
}
|
|
1195
|
-
_appendCustomMessage(message) {
|
|
1196
|
-
this.agent.state.messages.push(message);
|
|
1197
|
-
this.sessionManager.appendCustomMessageEntry(message.customType, message.content, message.display, message.details, customMessageExcludesContext(message));
|
|
1198
|
-
this._emit({ type: "message_start", message });
|
|
1199
|
-
this._emit({ type: "message_end", message });
|
|
1200
|
-
}
|
|
1201
|
-
_enqueueInterruptCustomMessage(message, options) {
|
|
1202
|
-
this._pendingInterruptDeliveries += 1;
|
|
1203
|
-
// Establish the hold synchronously when the interrupt is enqueued, not when
|
|
1204
|
-
// the serialized delivery callback later starts. Callers commonly fire and
|
|
1205
|
-
// forget sendCustomMessage(), then queue additional steer/follow-up messages
|
|
1206
|
-
// before the promise chain gets a microtask; those messages must be captured
|
|
1207
|
-
// in the active interrupt hold instead of pi-agent-core's live queues.
|
|
1208
|
-
this._ensureActiveInterruptQueueHold();
|
|
1209
|
-
const delivery = this._interruptDeliveryQueue.then(async () => {
|
|
1210
|
-
try {
|
|
1211
|
-
await this._sendInterruptCustomMessageNow(message, options);
|
|
1212
|
-
}
|
|
1213
|
-
finally {
|
|
1214
|
-
this._pendingInterruptDeliveries -= 1;
|
|
1215
|
-
if (this._pendingInterruptDeliveries === 0) {
|
|
1216
|
-
this._restoreAndClearActiveInterruptQueueHold();
|
|
1217
|
-
}
|
|
1218
|
-
}
|
|
1219
|
-
});
|
|
1220
|
-
this._interruptDeliveryQueue = delivery.catch(() => undefined);
|
|
1221
|
-
return delivery;
|
|
1222
|
-
}
|
|
1223
|
-
async _sendInterruptCustomMessageNow(message, options) {
|
|
1224
|
-
this.abortRetry();
|
|
1225
|
-
this._ensureActiveInterruptQueueHold();
|
|
1226
|
-
if (this.isStreaming) {
|
|
1227
|
-
const previousAbortMessage = this._activeInterruptAbortMessage;
|
|
1228
|
-
this._activeInterruptAbortMessage = normalizeInterruptAbortMessage(options?.interruptAbortMessage);
|
|
1229
|
-
try {
|
|
1230
|
-
this.agent.abort();
|
|
1231
|
-
await this.agent.waitForIdle();
|
|
1232
|
-
await this._agentEventQueue;
|
|
1233
|
-
}
|
|
1234
|
-
finally {
|
|
1235
|
-
this._activeInterruptAbortMessage = previousAbortMessage;
|
|
1236
|
-
}
|
|
1237
|
-
}
|
|
1238
|
-
await this.agent.prompt(message);
|
|
1239
|
-
}
|
|
1240
|
-
_ensureActiveInterruptQueueHold() {
|
|
1241
|
-
if (this._activeInterruptQueueHold !== undefined) {
|
|
1242
|
-
return this._activeInterruptQueueHold;
|
|
1243
|
-
}
|
|
1244
|
-
const drained = this._drainQueuedAgentMessages();
|
|
1245
|
-
this._activeInterruptQueueHold = {
|
|
1246
|
-
steering: [...drained.steering],
|
|
1247
|
-
followUp: [...drained.followUp],
|
|
1248
|
-
};
|
|
1249
|
-
return this._activeInterruptQueueHold;
|
|
1250
|
-
}
|
|
1251
|
-
_restoreAndClearActiveInterruptQueueHold() {
|
|
1252
|
-
const hold = this._activeInterruptQueueHold;
|
|
1253
|
-
if (hold === undefined) {
|
|
1254
|
-
return;
|
|
1255
|
-
}
|
|
1256
|
-
const currentCoreQueues = this._drainQueuedAgentMessages();
|
|
1257
|
-
this._restoreQueuedAgentMessages({
|
|
1258
|
-
steering: [...hold.steering, ...currentCoreQueues.steering],
|
|
1259
|
-
followUp: [...hold.followUp, ...currentCoreQueues.followUp],
|
|
1260
|
-
});
|
|
1261
|
-
this._activeInterruptQueueHold = undefined;
|
|
1262
|
-
}
|
|
1263
|
-
_queueAgentMessage(message, delivery) {
|
|
1264
|
-
const hold = this._activeInterruptQueueHold;
|
|
1265
|
-
if (hold !== undefined) {
|
|
1266
|
-
if (delivery === "followUp") {
|
|
1267
|
-
hold.followUp.push(message);
|
|
1268
|
-
}
|
|
1269
|
-
else {
|
|
1270
|
-
hold.steering.push(message);
|
|
1271
|
-
}
|
|
1272
|
-
return;
|
|
1273
|
-
}
|
|
1274
|
-
if (delivery === "followUp") {
|
|
1275
|
-
this.agent.followUp(message);
|
|
1276
|
-
}
|
|
1277
|
-
else {
|
|
1278
|
-
this.agent.steer(message);
|
|
1279
|
-
}
|
|
1280
|
-
}
|
|
1281
|
-
_drainQueuedAgentMessages() {
|
|
1282
|
-
// pi-agent-core exposes public clear methods but no public drain/restore pair.
|
|
1283
|
-
// Interrupts need to prevent the aborting run from consuming queued steer/follow-up
|
|
1284
|
-
// messages while still preserving those queues for a later turn.
|
|
1285
|
-
const agentWithQueues = this.agent;
|
|
1286
|
-
return {
|
|
1287
|
-
steering: drainAgentMessageQueue(agentWithQueues.steeringQueue),
|
|
1288
|
-
followUp: drainAgentMessageQueue(agentWithQueues.followUpQueue),
|
|
1289
|
-
};
|
|
1290
|
-
}
|
|
1291
|
-
_restoreQueuedAgentMessages(queues) {
|
|
1292
|
-
for (const message of queues.steering) {
|
|
1293
|
-
this.agent.steer(message);
|
|
1294
|
-
}
|
|
1295
|
-
for (const message of queues.followUp) {
|
|
1296
|
-
this.agent.followUp(message);
|
|
1297
|
-
}
|
|
1298
|
-
}
|
|
1299
|
-
/**
|
|
1300
|
-
* Send a user message to the agent. Always triggers a turn.
|
|
1301
|
-
* When the agent is streaming, use deliverAs to specify how to queue the message.
|
|
1302
|
-
*
|
|
1303
|
-
* @param content User message content (string or content array)
|
|
1304
|
-
* @param options.deliverAs Delivery mode when streaming: "steer" or "followUp"
|
|
1305
|
-
*/
|
|
1306
|
-
async sendUserMessage(content, options) {
|
|
1307
|
-
// Normalize content to text string + optional images
|
|
1308
|
-
let text;
|
|
1309
|
-
let images;
|
|
1310
|
-
if (typeof content === "string") {
|
|
1311
|
-
text = content;
|
|
1312
|
-
}
|
|
1313
|
-
else {
|
|
1314
|
-
const textParts = [];
|
|
1315
|
-
images = [];
|
|
1316
|
-
for (const part of content) {
|
|
1317
|
-
if (part.type === "text") {
|
|
1318
|
-
textParts.push(part.text);
|
|
1319
|
-
}
|
|
1320
|
-
else {
|
|
1321
|
-
images.push(part);
|
|
1322
|
-
}
|
|
1323
|
-
}
|
|
1324
|
-
text = textParts.join("\n");
|
|
1325
|
-
if (images.length === 0)
|
|
1326
|
-
images = undefined;
|
|
1327
|
-
}
|
|
1328
|
-
// Use prompt() with expandPromptTemplates: false to skip command handling and template expansion
|
|
1329
|
-
await this.prompt(text, {
|
|
1330
|
-
expandPromptTemplates: false,
|
|
1331
|
-
streamingBehavior: options?.deliverAs,
|
|
1332
|
-
images,
|
|
1333
|
-
source: "extension",
|
|
1334
|
-
});
|
|
1335
|
-
}
|
|
1336
|
-
/**
|
|
1337
|
-
* Clear all queued messages and return them.
|
|
1338
|
-
* Useful for restoring to editor when user aborts.
|
|
1339
|
-
* @returns Object with steering and followUp arrays
|
|
1340
|
-
*/
|
|
1341
|
-
clearQueue() {
|
|
1342
|
-
const steering = [...this._steeringMessages];
|
|
1343
|
-
const followUp = [...this._followUpMessages];
|
|
1344
|
-
this._steeringMessages = [];
|
|
1345
|
-
this._followUpMessages = [];
|
|
1346
|
-
this.agent.clearAllQueues();
|
|
1347
|
-
if (this._activeInterruptQueueHold !== undefined) {
|
|
1348
|
-
this._activeInterruptQueueHold.steering.length = 0;
|
|
1349
|
-
this._activeInterruptQueueHold.followUp.length = 0;
|
|
1350
|
-
}
|
|
1351
|
-
this._emitQueueUpdate();
|
|
1352
|
-
return { steering, followUp };
|
|
1353
|
-
}
|
|
1354
|
-
/** Number of pending messages (includes both steering and follow-up) */
|
|
1355
|
-
get pendingMessageCount() {
|
|
1356
|
-
return this._steeringMessages.length + this._followUpMessages.length;
|
|
1357
|
-
}
|
|
1358
|
-
/** Get pending steering messages (read-only) */
|
|
1359
|
-
getSteeringMessages() {
|
|
1360
|
-
return this._steeringMessages;
|
|
1361
|
-
}
|
|
1362
|
-
/** Get pending follow-up messages (read-only) */
|
|
1363
|
-
getFollowUpMessages() {
|
|
1364
|
-
return this._followUpMessages;
|
|
1365
|
-
}
|
|
1366
|
-
get resourceLoader() {
|
|
1367
|
-
return this._resourceLoader;
|
|
1368
|
-
}
|
|
1369
|
-
/**
|
|
1370
|
-
* Abort current operation and wait for agent to become idle.
|
|
1371
|
-
*/
|
|
1372
|
-
async abort() {
|
|
1373
|
-
this.abortRetry();
|
|
1374
|
-
this.agent.abort();
|
|
1375
|
-
await this.agent.waitForIdle();
|
|
1376
|
-
}
|
|
1377
|
-
// =========================================================================
|
|
1378
|
-
// Model Management
|
|
1379
|
-
// =========================================================================
|
|
1380
|
-
_emitModelChanged(nextModel, previousModel, source) {
|
|
1381
|
-
if (modelsAreEqual(previousModel, nextModel))
|
|
1382
|
-
return;
|
|
1383
|
-
this._emit({
|
|
1384
|
-
type: "model_changed",
|
|
1385
|
-
model: nextModel,
|
|
1386
|
-
previousModel,
|
|
1387
|
-
source,
|
|
1388
|
-
});
|
|
1389
|
-
}
|
|
1390
|
-
async _emitModelSelect(nextModel, previousModel, source) {
|
|
1391
|
-
if (modelsAreEqual(previousModel, nextModel))
|
|
1392
|
-
return;
|
|
1393
|
-
await this._extensionRunner.emit({
|
|
1394
|
-
type: "model_select",
|
|
1395
|
-
model: nextModel,
|
|
1396
|
-
previousModel,
|
|
1397
|
-
source,
|
|
1398
|
-
});
|
|
1399
|
-
}
|
|
1400
|
-
/**
|
|
1401
|
-
* Set model directly.
|
|
1402
|
-
* Validates that auth is configured, saves to session and settings.
|
|
1403
|
-
* @throws Error if no auth is configured for the model
|
|
1404
|
-
*/
|
|
1405
|
-
async setModel(model) {
|
|
1406
|
-
if (!this._modelRegistry.hasConfiguredAuth(model)) {
|
|
1407
|
-
throw new Error(`No API key for ${model.provider}/${model.id}`);
|
|
1408
|
-
}
|
|
1409
|
-
const previousModel = this.model;
|
|
1410
|
-
const thinkingLevel = this._getThinkingLevelForModelSwitch();
|
|
1411
|
-
const nextModel = this._withContextWindowForModelSwitch(model);
|
|
1412
|
-
this.agent.state.model = nextModel;
|
|
1413
|
-
this.sessionManager.appendModelChange(nextModel.provider, nextModel.id);
|
|
1414
|
-
this._appendContextWindowChangeIfChanged(previousModel, nextModel);
|
|
1415
|
-
this.settingsManager.setDefaultModelAndProvider(nextModel.provider, nextModel.id);
|
|
1416
|
-
// Re-clamp thinking level for new model's capabilities
|
|
1417
|
-
this.setThinkingLevel(thinkingLevel);
|
|
1418
|
-
this._refreshBaseSystemPromptFromActiveTools();
|
|
1419
|
-
this._emitModelChanged(nextModel, previousModel, "set");
|
|
1420
|
-
await this._emitModelSelect(nextModel, previousModel, "set");
|
|
1421
|
-
}
|
|
1422
|
-
/**
|
|
1423
|
-
* Cycle to next/previous model.
|
|
1424
|
-
* Uses scoped models (from --models flag) if available, otherwise all available models.
|
|
1425
|
-
* @param direction - "forward" (default) or "backward"
|
|
1426
|
-
* @returns The new model info, or undefined if only one model available
|
|
1427
|
-
*/
|
|
1428
|
-
async cycleModel(direction = "forward") {
|
|
1429
|
-
if (this._scopedModels.length > 0) {
|
|
1430
|
-
return this._cycleScopedModel(direction);
|
|
1431
|
-
}
|
|
1432
|
-
return this._cycleAvailableModel(direction);
|
|
1433
|
-
}
|
|
1434
|
-
async _cycleScopedModel(direction) {
|
|
1435
|
-
const scopedModels = this._scopedModels.filter((scoped) => this._modelRegistry.hasConfiguredAuth(scoped.model));
|
|
1436
|
-
if (scopedModels.length <= 1)
|
|
1437
|
-
return undefined;
|
|
1438
|
-
const currentModel = this.model;
|
|
1439
|
-
let currentIndex = scopedModels.findIndex((sm) => modelsAreEqual(sm.model, currentModel));
|
|
1440
|
-
if (currentIndex === -1)
|
|
1441
|
-
currentIndex = 0;
|
|
1442
|
-
const len = scopedModels.length;
|
|
1443
|
-
const nextIndex = direction === "forward" ? (currentIndex + 1) % len : (currentIndex - 1 + len) % len;
|
|
1444
|
-
const next = scopedModels[nextIndex];
|
|
1445
|
-
const thinkingLevel = this._getThinkingLevelForModelSwitch(next.thinkingLevel);
|
|
1446
|
-
const nextModel = this._withContextWindowForModelSwitch(next.model);
|
|
1447
|
-
// Apply model
|
|
1448
|
-
this.agent.state.model = nextModel;
|
|
1449
|
-
this.sessionManager.appendModelChange(nextModel.provider, nextModel.id);
|
|
1450
|
-
this._appendContextWindowChangeIfChanged(currentModel, nextModel);
|
|
1451
|
-
this.settingsManager.setDefaultModelAndProvider(nextModel.provider, nextModel.id);
|
|
1452
|
-
// Apply thinking level.
|
|
1453
|
-
// - Explicit scoped model thinking level overrides current session level
|
|
1454
|
-
// - Undefined scoped model thinking level inherits the current session preference
|
|
1455
|
-
// setThinkingLevel clamps to model capabilities.
|
|
1456
|
-
this.setThinkingLevel(thinkingLevel);
|
|
1457
|
-
this._refreshBaseSystemPromptFromActiveTools();
|
|
1458
|
-
this._emitModelChanged(nextModel, currentModel, "cycle");
|
|
1459
|
-
await this._emitModelSelect(nextModel, currentModel, "cycle");
|
|
1460
|
-
return { model: nextModel, thinkingLevel: this.thinkingLevel, isScoped: true };
|
|
1461
|
-
}
|
|
1462
|
-
async _cycleAvailableModel(direction) {
|
|
1463
|
-
const availableModels = await this._modelRegistry.getAvailable();
|
|
1464
|
-
if (availableModels.length <= 1)
|
|
1465
|
-
return undefined;
|
|
1466
|
-
const currentModel = this.model;
|
|
1467
|
-
let currentIndex = availableModels.findIndex((m) => modelsAreEqual(m, currentModel));
|
|
1468
|
-
if (currentIndex === -1)
|
|
1469
|
-
currentIndex = 0;
|
|
1470
|
-
const len = availableModels.length;
|
|
1471
|
-
const nextIndex = direction === "forward" ? (currentIndex + 1) % len : (currentIndex - 1 + len) % len;
|
|
1472
|
-
const selectedModel = this._withContextWindowForModelSwitch(availableModels[nextIndex]);
|
|
1473
|
-
const thinkingLevel = this._getThinkingLevelForModelSwitch();
|
|
1474
|
-
this.agent.state.model = selectedModel;
|
|
1475
|
-
this.sessionManager.appendModelChange(selectedModel.provider, selectedModel.id);
|
|
1476
|
-
this._appendContextWindowChangeIfChanged(currentModel, selectedModel);
|
|
1477
|
-
this.settingsManager.setDefaultModelAndProvider(selectedModel.provider, selectedModel.id);
|
|
1478
|
-
// Re-clamp thinking level for new model's capabilities
|
|
1479
|
-
this.setThinkingLevel(thinkingLevel);
|
|
1480
|
-
this._refreshBaseSystemPromptFromActiveTools();
|
|
1481
|
-
this._emitModelChanged(selectedModel, currentModel, "cycle");
|
|
1482
|
-
await this._emitModelSelect(selectedModel, currentModel, "cycle");
|
|
1483
|
-
return { model: selectedModel, thinkingLevel: this.thinkingLevel, isScoped: false };
|
|
1484
|
-
}
|
|
1485
|
-
// =========================================================================
|
|
1486
|
-
// Thinking Level Management
|
|
1487
|
-
// =========================================================================
|
|
1488
|
-
/**
|
|
1489
|
-
* Set thinking level.
|
|
1490
|
-
* Clamps to model capabilities based on available thinking levels.
|
|
1491
|
-
* Saves to session and settings only if the level actually changes.
|
|
1492
|
-
*/
|
|
1493
|
-
setThinkingLevel(level) {
|
|
1494
|
-
const availableLevels = this.getAvailableThinkingLevels();
|
|
1495
|
-
const effectiveLevel = availableLevels.includes(level) ? level : this._clampThinkingLevel(level, availableLevels);
|
|
1496
|
-
// Only persist if actually changing
|
|
1497
|
-
const previousLevel = this.agent.state.thinkingLevel;
|
|
1498
|
-
const isChanging = effectiveLevel !== previousLevel;
|
|
1499
|
-
this.agent.state.thinkingLevel = effectiveLevel;
|
|
1500
|
-
if (isChanging) {
|
|
1501
|
-
this.sessionManager.appendThinkingLevelChange(effectiveLevel);
|
|
1502
|
-
this._refreshBaseSystemPromptFromActiveTools();
|
|
1503
|
-
if (this.supportsThinking() || effectiveLevel !== "off") {
|
|
1504
|
-
this.settingsManager.setDefaultThinkingLevel(effectiveLevel);
|
|
1505
|
-
}
|
|
1506
|
-
this._emit({ type: "thinking_level_changed", level: effectiveLevel });
|
|
1507
|
-
void this._extensionRunner.emit({
|
|
1508
|
-
type: "thinking_level_select",
|
|
1509
|
-
level: effectiveLevel,
|
|
1510
|
-
previousLevel,
|
|
1511
|
-
});
|
|
1512
|
-
}
|
|
1513
|
-
}
|
|
1514
|
-
/**
|
|
1515
|
-
* Cycle to next thinking level.
|
|
1516
|
-
* @returns New level, or undefined if model doesn't support thinking
|
|
1517
|
-
*/
|
|
1518
|
-
cycleThinkingLevel() {
|
|
1519
|
-
if (!this.supportsThinking())
|
|
1520
|
-
return undefined;
|
|
1521
|
-
const levels = this.getAvailableThinkingLevels();
|
|
1522
|
-
const currentIndex = levels.indexOf(this.thinkingLevel);
|
|
1523
|
-
const nextIndex = (currentIndex + 1) % levels.length;
|
|
1524
|
-
const nextLevel = levels[nextIndex];
|
|
1525
|
-
this.setThinkingLevel(nextLevel);
|
|
1526
|
-
return nextLevel;
|
|
1527
|
-
}
|
|
1528
|
-
/**
|
|
1529
|
-
* Get available thinking levels for current model.
|
|
1530
|
-
* The provider will clamp to what the specific model supports internally.
|
|
1531
|
-
*/
|
|
1532
|
-
getAvailableThinkingLevels() {
|
|
1533
|
-
if (!this.model)
|
|
1534
|
-
return THINKING_LEVELS;
|
|
1535
|
-
return getSupportedThinkingLevels(this.model);
|
|
1536
|
-
}
|
|
1537
|
-
/**
|
|
1538
|
-
* Check if current model supports thinking/reasoning.
|
|
1539
|
-
*/
|
|
1540
|
-
supportsThinking() {
|
|
1541
|
-
return !!this.model?.reasoning;
|
|
1542
|
-
}
|
|
1543
|
-
_getThinkingLevelForModelSwitch(explicitLevel) {
|
|
1544
|
-
if (explicitLevel !== undefined) {
|
|
1545
|
-
return explicitLevel;
|
|
1546
|
-
}
|
|
1547
|
-
if (!this.supportsThinking()) {
|
|
1548
|
-
return this.settingsManager.getDefaultThinkingLevel() ?? DEFAULT_THINKING_LEVEL;
|
|
1549
|
-
}
|
|
1550
|
-
return this.thinkingLevel;
|
|
1551
|
-
}
|
|
1552
|
-
_clampThinkingLevel(level, _availableLevels) {
|
|
1553
|
-
return this.model ? clampThinkingLevel(this.model, level) : "off";
|
|
1554
|
-
}
|
|
1555
|
-
// =========================================================================
|
|
1556
|
-
// Context Window Management
|
|
1557
|
-
// =========================================================================
|
|
1558
|
-
getAvailableContextWindows() {
|
|
1559
|
-
return this.model ? getSupportedContextWindows(this.model) : [];
|
|
1560
|
-
}
|
|
1561
|
-
supportsContextWindowSelection() {
|
|
1562
|
-
return this.getAvailableContextWindows().length > 1;
|
|
1563
|
-
}
|
|
1564
|
-
setContextWindow(contextWindow, options = {}) {
|
|
1565
|
-
if (!this.model) {
|
|
1566
|
-
throw new Error("No model selected");
|
|
1567
|
-
}
|
|
1568
|
-
const selected = selectContextWindow(this.model, contextWindow, COPILOT_CONTEXT_WINDOW_SELECTION_OPTIONS);
|
|
1569
|
-
if ("error" in selected) {
|
|
1570
|
-
throw new Error(selected.error);
|
|
1571
|
-
}
|
|
1572
|
-
const previousContextWindow = this.model.contextWindow;
|
|
1573
|
-
const isChanging = previousContextWindow !== selected.contextWindow;
|
|
1574
|
-
this.agent.state.model = selected.model;
|
|
1575
|
-
if (isChanging) {
|
|
1576
|
-
this.sessionManager.appendContextWindowChange(selected.contextWindow);
|
|
1577
|
-
this._emit({ type: "context_window_changed", contextWindow: selected.contextWindow });
|
|
1578
|
-
}
|
|
1579
|
-
if (options.persistDefault === true) {
|
|
1580
|
-
this.settingsManager.setDefaultContextWindowForModel(selected.model.provider, selected.model.id, selected.contextWindow);
|
|
1581
|
-
}
|
|
1582
|
-
}
|
|
1583
|
-
_withContextWindowForModelSwitch(model) {
|
|
1584
|
-
// A source model's scalar contextWindow can be its natural default (for example a 1m-default
|
|
1585
|
-
// model). Do not treat that alone as an opt-in to larger windows on a 400k-default target.
|
|
1586
|
-
const settingsDefaultContextWindow = this._getSettingsContextWindowRequestForModel(model)?.contextWindow;
|
|
1587
|
-
const candidates = [];
|
|
1588
|
-
const targetDefaultContextWindow = getModelDefaultContextWindow(model);
|
|
1589
|
-
if (model.contextWindow !== targetDefaultContextWindow) {
|
|
1590
|
-
// Preserve an explicit context-window selection already applied to the target model
|
|
1591
|
-
// (for example a caller passing selectContextWindow(target, 1m).model).
|
|
1592
|
-
candidates.push(model.contextWindow);
|
|
1593
|
-
}
|
|
1594
|
-
const currentModel = this.model;
|
|
1595
|
-
if (currentModel && this._shouldCarryCurrentContextWindowForModelSwitch(currentModel, settingsDefaultContextWindow)) {
|
|
1596
|
-
candidates.push(currentModel.contextWindow);
|
|
1597
|
-
}
|
|
1598
|
-
if (settingsDefaultContextWindow !== undefined) {
|
|
1599
|
-
candidates.push(settingsDefaultContextWindow);
|
|
1600
|
-
}
|
|
1601
|
-
candidates.push(targetDefaultContextWindow);
|
|
1602
|
-
for (const candidate of candidates) {
|
|
1603
|
-
const selected = selectContextWindow(model, candidate, COPILOT_CONTEXT_WINDOW_SELECTION_OPTIONS);
|
|
1604
|
-
if (!("error" in selected))
|
|
1605
|
-
return selected.model;
|
|
1606
|
-
}
|
|
1607
|
-
return model;
|
|
1608
|
-
}
|
|
1609
|
-
_shouldCarryCurrentContextWindowForModelSwitch(currentModel, settingsDefaultContextWindow) {
|
|
1610
|
-
if (currentModel.contextWindow !== getModelDefaultContextWindow(currentModel)) {
|
|
1611
|
-
return true;
|
|
1612
|
-
}
|
|
1613
|
-
if (this.sessionManager.getBranch().some((entry) => entry.type === "context_window_change")) {
|
|
1614
|
-
return true;
|
|
1615
|
-
}
|
|
1616
|
-
return (settingsDefaultContextWindow !== undefined &&
|
|
1617
|
-
currentModel.contextWindow === settingsDefaultContextWindow &&
|
|
1618
|
-
getSupportedContextWindows(currentModel).includes(settingsDefaultContextWindow));
|
|
1619
|
-
}
|
|
1620
|
-
_getSettingsContextWindowRequestForModel(model) {
|
|
1621
|
-
const modelContextWindow = this.settingsManager.getDefaultContextWindowForModel(model.provider, model.id);
|
|
1622
|
-
if (modelContextWindow !== undefined) {
|
|
1623
|
-
return { contextWindow: modelContextWindow, source: "model-settings" };
|
|
1624
|
-
}
|
|
1625
|
-
const globalContextWindow = this.settingsManager.getDefaultContextWindow();
|
|
1626
|
-
return globalContextWindow === undefined
|
|
1627
|
-
? undefined
|
|
1628
|
-
: { contextWindow: globalContextWindow, source: "global-settings" };
|
|
1629
|
-
}
|
|
1630
|
-
_getContextWindowReplayForModel(model, requestedContextWindow, source) {
|
|
1631
|
-
if (requestedContextWindow !== undefined) {
|
|
1632
|
-
const selected = selectContextWindow(model, requestedContextWindow, COPILOT_CONTEXT_WINDOW_SELECTION_OPTIONS);
|
|
1633
|
-
if (!("error" in selected)) {
|
|
1634
|
-
return { model: selected.model, contextWindow: selected.contextWindow, wouldWarn: false };
|
|
1635
|
-
}
|
|
1636
|
-
return this._getDefaultContextWindowReplayForModel(model, source !== "global-settings");
|
|
1637
|
-
}
|
|
1638
|
-
return this._getDefaultContextWindowReplayForModel(model, false);
|
|
1639
|
-
}
|
|
1640
|
-
_getDefaultContextWindowReplayForModel(model, wouldWarn) {
|
|
1641
|
-
const defaultContextWindow = getModelDefaultContextWindow(model);
|
|
1642
|
-
const selected = selectContextWindow(model, defaultContextWindow, COPILOT_CONTEXT_WINDOW_SELECTION_OPTIONS);
|
|
1643
|
-
if (!("error" in selected)) {
|
|
1644
|
-
return { model: selected.model, contextWindow: selected.contextWindow, wouldWarn };
|
|
1645
|
-
}
|
|
1646
|
-
return {
|
|
1647
|
-
model: { ...model, contextWindow: defaultContextWindow, defaultContextWindow },
|
|
1648
|
-
contextWindow: defaultContextWindow,
|
|
1649
|
-
wouldWarn,
|
|
1650
|
-
};
|
|
1651
|
-
}
|
|
1652
|
-
_getResumeContextWindowReplayForModel(model) {
|
|
1653
|
-
const sessionContext = this.sessionManager.buildSessionContext();
|
|
1654
|
-
if (sessionContext.contextWindow !== undefined) {
|
|
1655
|
-
return this._getContextWindowReplayForModel(model, sessionContext.contextWindow, "session");
|
|
1656
|
-
}
|
|
1657
|
-
const settingsContextWindow = this._getSettingsContextWindowRequestForModel(model);
|
|
1658
|
-
return this._getContextWindowReplayForModel(model, settingsContextWindow?.contextWindow, settingsContextWindow?.source);
|
|
1659
|
-
}
|
|
1660
|
-
_applyContextWindowReplay(contextWindow) {
|
|
1661
|
-
if (!this.model)
|
|
1662
|
-
return;
|
|
1663
|
-
const previousContextWindow = this.model.contextWindow;
|
|
1664
|
-
const settingsContextWindow = this._getSettingsContextWindowRequestForModel(this.model);
|
|
1665
|
-
const requestedContextWindow = contextWindow ?? settingsContextWindow?.contextWindow;
|
|
1666
|
-
const source = contextWindow !== undefined ? "session" : settingsContextWindow?.source;
|
|
1667
|
-
const replay = this._getContextWindowReplayForModel(this.model, requestedContextWindow, source);
|
|
1668
|
-
this.agent.state.model = replay.model;
|
|
1669
|
-
if (previousContextWindow !== replay.contextWindow) {
|
|
1670
|
-
this._emit({ type: "context_window_changed", contextWindow: replay.contextWindow });
|
|
1671
|
-
}
|
|
1672
|
-
}
|
|
1673
|
-
_appendContextWindowChangeIfChanged(previousModel, nextModel) {
|
|
1674
|
-
const replay = this._getResumeContextWindowReplayForModel(nextModel);
|
|
1675
|
-
if (!replay.wouldWarn && nextModel.contextWindow === replay.contextWindow)
|
|
1676
|
-
return;
|
|
1677
|
-
this.sessionManager.appendContextWindowChange(nextModel.contextWindow);
|
|
1678
|
-
if (previousModel?.contextWindow !== nextModel.contextWindow) {
|
|
1679
|
-
this._emit({ type: "context_window_changed", contextWindow: nextModel.contextWindow });
|
|
1680
|
-
}
|
|
1681
|
-
}
|
|
1682
|
-
// =========================================================================
|
|
1683
|
-
// Queue Mode Management
|
|
1684
|
-
// =========================================================================
|
|
1685
|
-
/**
|
|
1686
|
-
* Set steering message mode.
|
|
1687
|
-
* Saves to settings.
|
|
1688
|
-
*/
|
|
1689
|
-
setSteeringMode(mode) {
|
|
1690
|
-
this.agent.steeringMode = mode;
|
|
1691
|
-
this.settingsManager.setSteeringMode(mode);
|
|
1692
|
-
}
|
|
1693
|
-
/**
|
|
1694
|
-
* Set follow-up message mode.
|
|
1695
|
-
* Saves to settings.
|
|
1696
|
-
*/
|
|
1697
|
-
setFollowUpMode(mode) {
|
|
1698
|
-
this.agent.followUpMode = mode;
|
|
1699
|
-
this.settingsManager.setFollowUpMode(mode);
|
|
1700
|
-
}
|
|
1701
|
-
// =========================================================================
|
|
1702
|
-
// Compaction
|
|
1703
|
-
// =========================================================================
|
|
1704
|
-
/**
|
|
1705
|
-
* Apply validated logical deletions and rebuild active agent context.
|
|
1706
|
-
* Retained transcript entries/content blocks stay verbatim.
|
|
1707
|
-
*/
|
|
1708
|
-
async _applyContextVerbatimCompaction(options) {
|
|
1709
|
-
if (!this.model) {
|
|
1710
|
-
throw new Error(formatNoModelSelectedMessage());
|
|
1711
|
-
}
|
|
1712
|
-
// Capture the narrowed model now (control-flow narrowing holds immediately after the
|
|
1713
|
-
// guard) so the lazy planner-fallback closure below can use a non-undefined model.
|
|
1714
|
-
const model = this.model;
|
|
1715
|
-
const compactionThinkingLevel = this.thinkingLevel;
|
|
1716
|
-
const pathEntries = this.sessionManager.getBranch();
|
|
1717
|
-
const settings = this.settingsManager.getCompactionSettings();
|
|
1718
|
-
const preparation = prepareContextCompaction(pathEntries, settings, {
|
|
1719
|
-
...(options.compression_ratio === undefined ? {} : { compression_ratio: options.compression_ratio }),
|
|
1720
|
-
...(options.preserve_recent === undefined ? {} : { preserve_recent: options.preserve_recent }),
|
|
1721
|
-
...(options.query === undefined ? {} : { query: options.query }),
|
|
1722
|
-
});
|
|
1723
|
-
if (!preparation) {
|
|
1724
|
-
return undefined;
|
|
1725
|
-
}
|
|
1726
|
-
const parameters = preparation.parameters;
|
|
1727
|
-
// Planner fallback used when no extension supplies a deletionRequest. Auth is resolved
|
|
1728
|
-
// lazily here so extension-provided deletion requests keep working offline. Returns
|
|
1729
|
-
// undefined when auth is unavailable (auto-mode resolvers), signaling a no-op compaction.
|
|
1730
|
-
const runPlanner = async () => {
|
|
1731
|
-
const auth = await options.resolvePlannerAuth();
|
|
1732
|
-
if (!auth)
|
|
1733
|
-
return undefined;
|
|
1734
|
-
return runContextCompact(preparation, model, auth.apiKey, auth.headers, options.abortController.signal, compactionThinkingLevel);
|
|
1735
|
-
};
|
|
1736
|
-
// Emit session_before_compact to allow extensions to cancel or provide a deletion request.
|
|
1737
|
-
// This happens BEFORE any auth resolution so local extension deletion requests work
|
|
1738
|
-
// without configured API credentials.
|
|
1739
|
-
let fromExtension = false;
|
|
1740
|
-
let validated;
|
|
1741
|
-
if (this._extensionRunner.hasHandlers("session_before_compact")) {
|
|
1742
|
-
// Deep-clone the preparation only when a before-compact handler actually exists. Extensions
|
|
1743
|
-
// receive an isolated, frozen snapshot so they cannot mutate protection metadata
|
|
1744
|
-
// (protectedEntryIds, entry .protected flags, etc.) on the internal preparation used for
|
|
1745
|
-
// validation. Building it lazily avoids deep-cloning the transcript — largest exactly when
|
|
1746
|
-
// compaction fires — on the common no-extension path.
|
|
1747
|
-
let extensionPreparation;
|
|
1748
|
-
try {
|
|
1749
|
-
extensionPreparation = deepFreeze(structuredClone(preparation));
|
|
1750
|
-
}
|
|
1751
|
-
catch (error) {
|
|
1752
|
-
// structuredClone only throws if an entry carries a non-cloneable value (a function or a
|
|
1753
|
-
// class instance). Transcript entries are plain data today, so this guards a latent
|
|
1754
|
-
// invariant: surface a clear error instead of letting a raw DataCloneError abort an
|
|
1755
|
-
// otherwise-viable compaction.
|
|
1756
|
-
throw new Error(`Failed to snapshot transcript for compaction extensions: ${error instanceof Error ? error.message : String(error)}`);
|
|
1757
|
-
}
|
|
1758
|
-
const hookResult = (await this._extensionRunner.emit({
|
|
1759
|
-
type: "session_before_compact",
|
|
1760
|
-
reason: options.reason,
|
|
1761
|
-
parameters,
|
|
1762
|
-
preparation: extensionPreparation,
|
|
1763
|
-
branchEntries: pathEntries,
|
|
1764
|
-
signal: options.abortController.signal,
|
|
1765
|
-
}));
|
|
1766
|
-
if (hookResult?.cancel) {
|
|
1767
|
-
throw new Error("Compaction cancelled");
|
|
1768
|
-
}
|
|
1769
|
-
if (hookResult?.deletionRequest) {
|
|
1770
|
-
const extensionDeletionRequest = hookResult.deletionRequest;
|
|
1771
|
-
// Reject empty deletion requests before any side effects (backup, append, rebuild).
|
|
1772
|
-
if (!Array.isArray(extensionDeletionRequest.deletions) || extensionDeletionRequest.deletions.length === 0) {
|
|
1773
|
-
throw new Error("No safe context deletions proposed by extension");
|
|
1774
|
-
}
|
|
1775
|
-
// Validate against the internal transcript snapshot, not the extension-facing clone.
|
|
1776
|
-
// Auth is NOT resolved here — local extension deletion requests work offline.
|
|
1777
|
-
validated = validateContextDeletionRequest(extensionDeletionRequest, preparation.transcript);
|
|
1778
|
-
// Reject if reconciliation reduced deletions to zero.
|
|
1779
|
-
if (validated.deletedTargets.length === 0) {
|
|
1780
|
-
throw new Error("No safe context deletions proposed by extension");
|
|
1781
|
-
}
|
|
1782
|
-
fromExtension = true;
|
|
1783
|
-
}
|
|
1784
|
-
}
|
|
1785
|
-
// Planner fallback shared by both paths: no before-compact handler at all, or a handler that
|
|
1786
|
-
// observed without supplying a deletionRequest. Resolves auth lazily; undefined means auth is
|
|
1787
|
-
// unavailable (auto-mode resolvers), so compaction is a no-op.
|
|
1788
|
-
if (!validated) {
|
|
1789
|
-
const plannerResult = await runPlanner();
|
|
1790
|
-
if (!plannerResult) {
|
|
1791
|
-
return undefined;
|
|
1792
|
-
}
|
|
1793
|
-
validated = plannerResult;
|
|
1794
|
-
}
|
|
1795
|
-
if (options.abortController.signal.aborted) {
|
|
1796
|
-
throw new Error("Compaction cancelled");
|
|
1797
|
-
}
|
|
1798
|
-
const backupPath = this.sessionManager.writeBackupSnapshot(options.backupLabel);
|
|
1799
|
-
const compactionEntryId = this.sessionManager.appendContextCompaction(validated.deletedTargets, validated.protectedEntryIds, validated.stats, backupPath);
|
|
1800
|
-
const sessionContext = this.sessionManager.buildSessionContext();
|
|
1801
|
-
this.agent.state.messages = sessionContext.messages;
|
|
1802
|
-
const result = {
|
|
1803
|
-
...validated,
|
|
1804
|
-
promptVersion: 1,
|
|
1805
|
-
parameters,
|
|
1806
|
-
...(backupPath ? { backupPath } : {}),
|
|
1807
|
-
};
|
|
1808
|
-
// Emit session_compact so extensions can observe the validated result. This is a pure
|
|
1809
|
-
// observation hook fired AFTER the compaction has been committed (backup written,
|
|
1810
|
-
// context_compaction entry persisted, active context rebuilt). A misbehaving observer must
|
|
1811
|
-
// never turn a successful, already-persisted compaction into a reported failure, so any
|
|
1812
|
-
// throw is routed to the non-fatal extension-error channel and compaction still reports
|
|
1813
|
-
// success.
|
|
1814
|
-
const contextCompactionEntry = this.sessionManager.getEntry(compactionEntryId);
|
|
1815
|
-
try {
|
|
1816
|
-
await this._extensionRunner.emit({
|
|
1817
|
-
type: "session_compact",
|
|
1818
|
-
reason: options.reason,
|
|
1819
|
-
parameters,
|
|
1820
|
-
result,
|
|
1821
|
-
contextCompactionEntry,
|
|
1822
|
-
fromExtension,
|
|
1823
|
-
});
|
|
1824
|
-
}
|
|
1825
|
-
catch (error) {
|
|
1826
|
-
this._extensionRunner.emitError({
|
|
1827
|
-
extensionPath: "<session_compact>",
|
|
1828
|
-
event: "session_compact",
|
|
1829
|
-
error: error instanceof Error ? error.message : String(error),
|
|
1830
|
-
stack: error instanceof Error ? error.stack : undefined,
|
|
1831
|
-
});
|
|
1832
|
-
}
|
|
1833
|
-
return result;
|
|
1834
|
-
}
|
|
1835
|
-
/**
|
|
1836
|
-
* Manually compact the session context using deletion-only verbatim context compaction.
|
|
1837
|
-
* Aborts current agent operation first.
|
|
1838
|
-
*/
|
|
1839
|
-
async compact(options = {}) {
|
|
1840
|
-
this._disconnectFromAgent();
|
|
1841
|
-
await this.abort();
|
|
1842
|
-
this._compactionAbortController = new AbortController();
|
|
1843
|
-
this._emit({ type: "compaction_start", reason: "manual" });
|
|
1844
|
-
try {
|
|
1845
|
-
if (!this.model) {
|
|
1846
|
-
throw new Error(formatNoModelSelectedMessage());
|
|
1847
|
-
}
|
|
1848
|
-
// Auth is resolved lazily: only called when the planner fallback is needed.
|
|
1849
|
-
// Extensions that provide a deletionRequest work without configured credentials.
|
|
1850
|
-
const model = this.model;
|
|
1851
|
-
const result = await this._applyContextVerbatimCompaction({
|
|
1852
|
-
resolvePlannerAuth: () => this._getRequiredRequestAuth(model),
|
|
1853
|
-
abortController: this._compactionAbortController,
|
|
1854
|
-
backupLabel: "compact",
|
|
1855
|
-
reason: "manual",
|
|
1856
|
-
...(options.compression_ratio === undefined ? {} : { compression_ratio: options.compression_ratio }),
|
|
1857
|
-
...(options.preserve_recent === undefined ? {} : { preserve_recent: options.preserve_recent }),
|
|
1858
|
-
...(options.query === undefined ? {} : { query: options.query }),
|
|
1859
|
-
});
|
|
1860
|
-
if (!result) {
|
|
1861
|
-
throw new Error("Nothing to compact (session too small)");
|
|
1862
|
-
}
|
|
1863
|
-
this._emit({
|
|
1864
|
-
type: "compaction_end",
|
|
1865
|
-
reason: "manual",
|
|
1866
|
-
result,
|
|
1867
|
-
aborted: false,
|
|
1868
|
-
willRetry: false,
|
|
1869
|
-
});
|
|
1870
|
-
return result;
|
|
1871
|
-
}
|
|
1872
|
-
catch (error) {
|
|
1873
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
1874
|
-
const aborted = message === "Compaction cancelled" || (error instanceof Error && error.name === "AbortError");
|
|
1875
|
-
this._emit({
|
|
1876
|
-
type: "compaction_end",
|
|
1877
|
-
reason: "manual",
|
|
1878
|
-
result: undefined,
|
|
1879
|
-
aborted,
|
|
1880
|
-
willRetry: false,
|
|
1881
|
-
errorMessage: aborted ? undefined : `Compaction failed: ${message}`,
|
|
1882
|
-
});
|
|
1883
|
-
throw error;
|
|
1884
|
-
}
|
|
1885
|
-
finally {
|
|
1886
|
-
this._compactionAbortController = undefined;
|
|
1887
|
-
this._reconnectToAgent();
|
|
1888
|
-
}
|
|
1889
|
-
}
|
|
1890
|
-
/**
|
|
1891
|
-
* Manually compact the session context by applying validated logical deletions.
|
|
1892
|
-
* Retained transcript entries/content blocks stay verbatim; no user prompt text is accepted.
|
|
1893
|
-
*/
|
|
1894
|
-
async contextCompact() {
|
|
1895
|
-
this._disconnectFromAgent();
|
|
1896
|
-
await this.abort();
|
|
1897
|
-
this._compactionAbortController = new AbortController();
|
|
1898
|
-
this._emit({ type: "context_compaction_start", reason: "manual" });
|
|
1899
|
-
try {
|
|
1900
|
-
if (!this.model) {
|
|
1901
|
-
throw new Error(formatNoModelSelectedMessage());
|
|
1902
|
-
}
|
|
1903
|
-
// Auth is resolved lazily: only called when the planner fallback is needed.
|
|
1904
|
-
// Extensions that provide a deletionRequest work without configured credentials.
|
|
1905
|
-
const model = this.model;
|
|
1906
|
-
const result = await this._applyContextVerbatimCompaction({
|
|
1907
|
-
resolvePlannerAuth: () => this._getRequiredRequestAuth(model),
|
|
1908
|
-
abortController: this._compactionAbortController,
|
|
1909
|
-
backupLabel: "context-compact",
|
|
1910
|
-
reason: "manual",
|
|
1911
|
-
});
|
|
1912
|
-
if (!result) {
|
|
1913
|
-
throw new Error("Nothing to context-compact (session too small)");
|
|
1914
|
-
}
|
|
1915
|
-
this._emit({
|
|
1916
|
-
type: "context_compaction_end",
|
|
1917
|
-
reason: "manual",
|
|
1918
|
-
result,
|
|
1919
|
-
aborted: false,
|
|
1920
|
-
willRetry: false,
|
|
1921
|
-
});
|
|
1922
|
-
return result;
|
|
1923
|
-
}
|
|
1924
|
-
catch (error) {
|
|
1925
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
1926
|
-
const aborted = message === "Compaction cancelled" || (error instanceof Error && error.name === "AbortError");
|
|
1927
|
-
this._emit({
|
|
1928
|
-
type: "context_compaction_end",
|
|
1929
|
-
reason: "manual",
|
|
1930
|
-
result: undefined,
|
|
1931
|
-
aborted,
|
|
1932
|
-
willRetry: false,
|
|
1933
|
-
errorMessage: aborted ? undefined : `Context compaction failed: ${message}`,
|
|
1934
|
-
});
|
|
1935
|
-
throw error;
|
|
1936
|
-
}
|
|
1937
|
-
finally {
|
|
1938
|
-
this._compactionAbortController = undefined;
|
|
1939
|
-
this._reconnectToAgent();
|
|
1940
|
-
}
|
|
1941
|
-
}
|
|
1942
|
-
/**
|
|
1943
|
-
* Cancel in-progress compaction (manual or auto).
|
|
1944
|
-
*/
|
|
1945
|
-
abortCompaction() {
|
|
1946
|
-
this._compactionAbortController?.abort();
|
|
1947
|
-
this._autoCompactionAbortController?.abort();
|
|
1948
|
-
}
|
|
1949
|
-
/**
|
|
1950
|
-
* Cancel in-progress branch summarization.
|
|
1951
|
-
*/
|
|
1952
|
-
abortBranchSummary() {
|
|
1953
|
-
this._branchSummaryAbortController?.abort();
|
|
1954
|
-
}
|
|
1955
|
-
/**
|
|
1956
|
-
* Check if compaction is needed and run it.
|
|
1957
|
-
* Called after agent_end and before prompt submission.
|
|
1958
|
-
*
|
|
1959
|
-
* Two cases:
|
|
1960
|
-
* 1. Overflow: LLM returned context overflow error, remove error message from agent state, compact, auto-retry
|
|
1961
|
-
* 2. Threshold: Context over threshold, compact, resume queued active-turn work if present; otherwise wait for user
|
|
1962
|
-
*
|
|
1963
|
-
* @param assistantMessage The assistant message to check
|
|
1964
|
-
* @param skipAbortedCheck If false, include aborted messages (for pre-prompt check). Default: true
|
|
1965
|
-
*/
|
|
1966
|
-
async _checkCompaction(assistantMessage, skipAbortedCheck = true) {
|
|
1967
|
-
const settings = this.settingsManager.getCompactionSettings();
|
|
1968
|
-
if (!settings.enabled)
|
|
1969
|
-
return;
|
|
1970
|
-
// Skip if message was aborted (user cancelled) - unless skipAbortedCheck is false
|
|
1971
|
-
if (skipAbortedCheck && assistantMessage.stopReason === "aborted")
|
|
1972
|
-
return;
|
|
1973
|
-
const contextWindow = this.model?.contextWindow ?? 0;
|
|
1974
|
-
// Skip overflow check if the message came from a different model.
|
|
1975
|
-
// This handles the case where user switched from a smaller-context model (e.g. opus)
|
|
1976
|
-
// to a larger-context model (e.g. codex) - the overflow error from the old model
|
|
1977
|
-
// shouldn't trigger compaction for the new model.
|
|
1978
|
-
const sameModel = this.model && assistantMessage.provider === this.model.provider && assistantMessage.model === this.model.id;
|
|
1979
|
-
// Skip compaction checks if this assistant message is older than the latest
|
|
1980
|
-
// compaction boundary. This prevents a stale pre-compaction usage/error
|
|
1981
|
-
// from retriggering compaction on the first prompt after compaction.
|
|
1982
|
-
const compactionBoundaryEntry = getLatestCompactionBoundaryEntry(this.sessionManager.getBranch());
|
|
1983
|
-
const assistantIsFromBeforeCompactionBoundary = compactionBoundaryEntry !== null &&
|
|
1984
|
-
assistantMessage.timestamp <= new Date(compactionBoundaryEntry.timestamp).getTime();
|
|
1985
|
-
if (assistantIsFromBeforeCompactionBoundary) {
|
|
1986
|
-
return;
|
|
1987
|
-
}
|
|
1988
|
-
// Case 1: Overflow - LLM returned context overflow error
|
|
1989
|
-
// When Copilot rejects a 1m client-budget prompt at a lower server cap (for example
|
|
1990
|
-
// because long-context/usage-based billing entitlement is missing), leave the friendly
|
|
1991
|
-
// error visible instead of auto-compacting down to a smaller server tier silently.
|
|
1992
|
-
if (sameModel && this._isCopilotServerCapBelowSelectedContextWindow(assistantMessage)) {
|
|
1993
|
-
return;
|
|
1994
|
-
}
|
|
1995
|
-
if (sameModel && isContextOverflow(assistantMessage, contextWindow)) {
|
|
1996
|
-
if (this._overflowRecoveryAttempted) {
|
|
1997
|
-
this._emit({
|
|
1998
|
-
type: "compaction_end",
|
|
1999
|
-
reason: "overflow",
|
|
2000
|
-
result: undefined,
|
|
2001
|
-
aborted: false,
|
|
2002
|
-
willRetry: false,
|
|
2003
|
-
errorMessage: "Context overflow recovery failed after one compact-and-retry attempt. Try reducing context or switching to a larger-context model.",
|
|
2004
|
-
});
|
|
2005
|
-
return;
|
|
2006
|
-
}
|
|
2007
|
-
this._overflowRecoveryAttempted = true;
|
|
2008
|
-
// Remove the error message from agent state (it IS saved to session for history,
|
|
2009
|
-
// but we don't want it in context for the retry)
|
|
2010
|
-
const messages = this.agent.state.messages;
|
|
2011
|
-
if (messages.length > 0 && messages[messages.length - 1].role === "assistant") {
|
|
2012
|
-
this.agent.state.messages = messages.slice(0, -1);
|
|
2013
|
-
}
|
|
2014
|
-
await this._runAutoCompaction("overflow", true);
|
|
2015
|
-
return;
|
|
2016
|
-
}
|
|
2017
|
-
// Case 2: Threshold - context is getting large
|
|
2018
|
-
// For error messages (no usage data), estimate from last successful response.
|
|
2019
|
-
// This ensures sessions that hit persistent API errors (e.g. 529) can still compact.
|
|
2020
|
-
let contextTokens;
|
|
2021
|
-
if (assistantMessage.stopReason === "error") {
|
|
2022
|
-
const messages = this.agent.state.messages;
|
|
2023
|
-
const estimate = estimateContextTokens(messages);
|
|
2024
|
-
if (estimate.lastUsageIndex === null)
|
|
2025
|
-
return; // No usage data at all
|
|
2026
|
-
// Verify the usage source is post-compaction. Kept pre-compaction messages
|
|
2027
|
-
// have stale usage reflecting the old (larger) context and would falsely
|
|
2028
|
-
// trigger compaction right after one just finished.
|
|
2029
|
-
const usageMsg = messages[estimate.lastUsageIndex];
|
|
2030
|
-
if (compactionBoundaryEntry &&
|
|
2031
|
-
usageMsg.role === "assistant" &&
|
|
2032
|
-
usageMsg.timestamp <= new Date(compactionBoundaryEntry.timestamp).getTime()) {
|
|
2033
|
-
return;
|
|
2034
|
-
}
|
|
2035
|
-
contextTokens = estimate.tokens;
|
|
2036
|
-
}
|
|
2037
|
-
else {
|
|
2038
|
-
contextTokens = calculateContextTokens(assistantMessage.usage);
|
|
2039
|
-
}
|
|
2040
|
-
// Compact against the effective input budget (the hard prompt cap for providers like Copilot
|
|
2041
|
-
// that advertise a larger total window) so we compact before overrunning the server-side limit
|
|
2042
|
-
// rather than relying on reactive overflow recovery near the cap.
|
|
2043
|
-
const compactionBudget = this.model ? getEffectiveInputBudget(this.model) : contextWindow;
|
|
2044
|
-
if (shouldCompact(contextTokens, compactionBudget, settings)) {
|
|
2045
|
-
await this._runAutoCompaction("threshold", false);
|
|
2046
|
-
}
|
|
2047
|
-
}
|
|
2048
|
-
_isCopilotServerCapBelowSelectedContextWindow(assistantMessage) {
|
|
2049
|
-
if (!this.model || this.model.provider !== "github-copilot" || !assistantMessage.errorMessage)
|
|
2050
|
-
return false;
|
|
2051
|
-
const promptLimitError = parseCopilotPromptLimitError(assistantMessage.errorMessage);
|
|
2052
|
-
// Compare against the effective input budget (the model's real prompt cap), not the displayed
|
|
2053
|
-
// total window. A rejection at the prompt cap is a normal overflow we should compact-and-retry;
|
|
2054
|
-
// only a rejection *below* the cap (e.g. a missing long-context entitlement dropping the account
|
|
2055
|
-
// to a lower server tier) keeps the friendly error visible instead of silently compacting down.
|
|
2056
|
-
return promptLimitError !== undefined && getEffectiveInputBudget(this.model) > promptLimitError.limitTokens;
|
|
2057
|
-
}
|
|
2058
|
-
/**
|
|
2059
|
-
* Internal: remove the trailing overflow error from retry context if it is still present.
|
|
2060
|
-
*/
|
|
2061
|
-
_dropTrailingOverflowAssistantErrorIfPresent() {
|
|
2062
|
-
const messages = this.agent.state.messages;
|
|
2063
|
-
const lastMsg = messages[messages.length - 1];
|
|
2064
|
-
if (lastMsg?.role === "assistant" && lastMsg.stopReason === "error") {
|
|
2065
|
-
this.agent.state.messages = messages.slice(0, -1);
|
|
2066
|
-
}
|
|
2067
|
-
}
|
|
2068
|
-
/**
|
|
2069
|
-
* Internal: schedule a live post-event continuation probe after compaction_end listeners can flush queues.
|
|
2070
|
-
*/
|
|
2071
|
-
_schedulePostAutoCompactionContinuationProbe(reason, willRetry) {
|
|
2072
|
-
setTimeout(() => {
|
|
2073
|
-
if (this.isCompacting || this.isStreaming) {
|
|
2074
|
-
return;
|
|
2075
|
-
}
|
|
2076
|
-
if (reason === "overflow" && willRetry) {
|
|
2077
|
-
this._resumeAfterAutoCompaction();
|
|
2078
|
-
return;
|
|
2079
|
-
}
|
|
2080
|
-
if (!this.agent.hasQueuedMessages()) {
|
|
2081
|
-
return;
|
|
2082
|
-
}
|
|
2083
|
-
this._resumeAfterAutoCompaction();
|
|
2084
|
-
}, 100);
|
|
2085
|
-
}
|
|
2086
|
-
/**
|
|
2087
|
-
* Internal: resume generation after successful auto-compaction only when active work remains.
|
|
2088
|
-
*/
|
|
2089
|
-
_resumeAfterAutoCompaction() {
|
|
2090
|
-
this.agent.continue().catch(() => { });
|
|
2091
|
-
}
|
|
2092
|
-
/**
|
|
2093
|
-
* Internal: Run auto-compaction with events.
|
|
2094
|
-
*/
|
|
2095
|
-
async _runAutoCompaction(reason, willRetry) {
|
|
2096
|
-
this._emit({ type: "compaction_start", reason });
|
|
2097
|
-
this._autoCompactionAbortController = new AbortController();
|
|
2098
|
-
try {
|
|
2099
|
-
if (!this.model) {
|
|
2100
|
-
this._emit({
|
|
2101
|
-
type: "compaction_end",
|
|
2102
|
-
reason,
|
|
2103
|
-
result: undefined,
|
|
2104
|
-
aborted: false,
|
|
2105
|
-
willRetry: false,
|
|
2106
|
-
});
|
|
2107
|
-
return;
|
|
2108
|
-
}
|
|
2109
|
-
// Auth is resolved lazily: only called when the planner fallback is needed.
|
|
2110
|
-
// This allows extension-provided deletion requests to run before auth is checked,
|
|
2111
|
-
// enabling local extension compaction even when API credentials are unavailable.
|
|
2112
|
-
// Auto-mode resolver returns undefined (rather than throwing) when auth is missing,
|
|
2113
|
-
// so compaction silently no-ops if the planner would be needed but credentials are absent.
|
|
2114
|
-
const model = this.model;
|
|
2115
|
-
const result = await this._applyContextVerbatimCompaction({
|
|
2116
|
-
resolvePlannerAuth: async () => {
|
|
2117
|
-
const authResult = await this._modelRegistry.getApiKeyAndHeaders(model);
|
|
2118
|
-
if (!authResult.ok || !authResult.apiKey) {
|
|
2119
|
-
return undefined;
|
|
2120
|
-
}
|
|
2121
|
-
return { apiKey: authResult.apiKey, headers: authResult.headers };
|
|
2122
|
-
},
|
|
2123
|
-
abortController: this._autoCompactionAbortController,
|
|
2124
|
-
backupLabel: reason === "overflow" ? "overflow-auto-compact" : "auto-compact",
|
|
2125
|
-
reason,
|
|
2126
|
-
});
|
|
2127
|
-
if (!result) {
|
|
2128
|
-
this._emit({
|
|
2129
|
-
type: "compaction_end",
|
|
2130
|
-
reason,
|
|
2131
|
-
result: undefined,
|
|
2132
|
-
aborted: false,
|
|
2133
|
-
willRetry: false,
|
|
2134
|
-
});
|
|
2135
|
-
return;
|
|
2136
|
-
}
|
|
2137
|
-
if (reason === "overflow" && willRetry) {
|
|
2138
|
-
this._dropTrailingOverflowAssistantErrorIfPresent();
|
|
2139
|
-
}
|
|
2140
|
-
this._emit({ type: "compaction_end", reason, result, aborted: false, willRetry });
|
|
2141
|
-
this._schedulePostAutoCompactionContinuationProbe(reason, willRetry);
|
|
2142
|
-
}
|
|
2143
|
-
catch (error) {
|
|
2144
|
-
const errorMessage = error instanceof Error ? error.message : "compaction failed";
|
|
2145
|
-
const aborted = errorMessage === "Compaction cancelled" || (error instanceof Error && error.name === "AbortError");
|
|
2146
|
-
this._emit({
|
|
2147
|
-
type: "compaction_end",
|
|
2148
|
-
reason,
|
|
2149
|
-
result: undefined,
|
|
2150
|
-
aborted,
|
|
2151
|
-
willRetry: false,
|
|
2152
|
-
errorMessage: aborted
|
|
2153
|
-
? undefined
|
|
2154
|
-
: reason === "overflow"
|
|
2155
|
-
? `Context overflow recovery failed: ${errorMessage}`
|
|
2156
|
-
: `Auto-compaction failed: ${errorMessage}`,
|
|
2157
|
-
});
|
|
2158
|
-
}
|
|
2159
|
-
finally {
|
|
2160
|
-
this._autoCompactionAbortController = undefined;
|
|
2161
|
-
}
|
|
2162
|
-
}
|
|
2163
|
-
/**
|
|
2164
|
-
* Toggle auto-compaction setting.
|
|
2165
|
-
*/
|
|
2166
|
-
setAutoCompactionEnabled(enabled) {
|
|
2167
|
-
this.settingsManager.setCompactionEnabled(enabled);
|
|
2168
|
-
}
|
|
2169
|
-
/** Whether auto-compaction is enabled */
|
|
2170
|
-
get autoCompactionEnabled() {
|
|
2171
|
-
return this.settingsManager.getCompactionEnabled();
|
|
2172
|
-
}
|
|
2173
|
-
async bindExtensions(bindings) {
|
|
2174
|
-
if (bindings.uiContext !== undefined) {
|
|
2175
|
-
this._extensionUIContext = bindings.uiContext;
|
|
2176
|
-
}
|
|
2177
|
-
if (bindings.mode !== undefined) {
|
|
2178
|
-
this._extensionMode = bindings.mode;
|
|
2179
|
-
}
|
|
2180
|
-
if (bindings.commandContextActions !== undefined) {
|
|
2181
|
-
this._extensionCommandContextActions = bindings.commandContextActions;
|
|
2182
|
-
}
|
|
2183
|
-
if (bindings.shutdownHandler !== undefined) {
|
|
2184
|
-
this._extensionShutdownHandler = bindings.shutdownHandler;
|
|
2185
|
-
}
|
|
2186
|
-
if (bindings.onError !== undefined) {
|
|
2187
|
-
this._extensionErrorListener = bindings.onError;
|
|
2188
|
-
}
|
|
2189
|
-
this._applyExtensionBindings(this._extensionRunner);
|
|
2190
|
-
await this._extensionRunner.emit(this._sessionStartEvent);
|
|
2191
|
-
await this.extendResourcesFromExtensions(this._sessionStartEvent.reason === "reload" ? "reload" : "startup");
|
|
2192
|
-
}
|
|
2193
|
-
async extendResourcesFromExtensions(reason) {
|
|
2194
|
-
if (!this._extensionRunner.hasHandlers("resources_discover")) {
|
|
2195
|
-
return;
|
|
2196
|
-
}
|
|
2197
|
-
const { skillPaths, promptPaths, themePaths } = await this._extensionRunner.emitResourcesDiscover(this._cwd, reason);
|
|
2198
|
-
if (skillPaths.length === 0 && promptPaths.length === 0 && themePaths.length === 0) {
|
|
2199
|
-
return;
|
|
2200
|
-
}
|
|
2201
|
-
const extensionPaths = {
|
|
2202
|
-
skillPaths: this.buildExtensionResourcePaths(skillPaths),
|
|
2203
|
-
promptPaths: this.buildExtensionResourcePaths(promptPaths),
|
|
2204
|
-
themePaths: this.buildExtensionResourcePaths(themePaths),
|
|
2205
|
-
};
|
|
2206
|
-
this._resourceLoader.extendResources(extensionPaths);
|
|
2207
|
-
this._baseSystemPrompt = this._rebuildSystemPrompt(this.getActiveToolNames());
|
|
2208
|
-
this.agent.state.systemPrompt = this._baseSystemPrompt;
|
|
2209
|
-
}
|
|
2210
|
-
buildExtensionResourcePaths(entries) {
|
|
2211
|
-
return entries.map((entry) => {
|
|
2212
|
-
const source = this.getExtensionSourceLabel(entry.extensionPath);
|
|
2213
|
-
const baseDir = entry.extensionPath.startsWith("<") ? undefined : dirname(entry.extensionPath);
|
|
2214
|
-
return {
|
|
2215
|
-
path: entry.path,
|
|
2216
|
-
metadata: {
|
|
2217
|
-
source,
|
|
2218
|
-
scope: "temporary",
|
|
2219
|
-
origin: "top-level",
|
|
2220
|
-
baseDir,
|
|
2221
|
-
},
|
|
2222
|
-
};
|
|
2223
|
-
});
|
|
2224
|
-
}
|
|
2225
|
-
getExtensionSourceLabel(extensionPath) {
|
|
2226
|
-
if (extensionPath.startsWith("<")) {
|
|
2227
|
-
return `extension:${extensionPath.replace(/[<>]/g, "")}`;
|
|
2228
|
-
}
|
|
2229
|
-
const base = basename(extensionPath);
|
|
2230
|
-
const name = base.replace(/\.(ts|js)$/, "");
|
|
2231
|
-
return `extension:${name}`;
|
|
2232
|
-
}
|
|
2233
|
-
_applyExtensionBindings(runner) {
|
|
2234
|
-
runner.setUIContext(this._extensionUIContext, this._extensionMode);
|
|
2235
|
-
runner.bindCommandContext(this._extensionCommandContextActions);
|
|
2236
|
-
this._extensionErrorUnsubscriber?.();
|
|
2237
|
-
this._extensionErrorUnsubscriber = this._extensionErrorListener
|
|
2238
|
-
? runner.onError(this._extensionErrorListener)
|
|
2239
|
-
: undefined;
|
|
2240
|
-
}
|
|
2241
|
-
_refreshCurrentModelFromRegistry() {
|
|
2242
|
-
const currentModel = this.model;
|
|
2243
|
-
if (!currentModel) {
|
|
2244
|
-
return;
|
|
2245
|
-
}
|
|
2246
|
-
const refreshedModel = this._modelRegistry.find(currentModel.provider, currentModel.id);
|
|
2247
|
-
if (!refreshedModel || refreshedModel === currentModel) {
|
|
2248
|
-
return;
|
|
2249
|
-
}
|
|
2250
|
-
const replay = this._getResumeContextWindowReplayForModel(refreshedModel);
|
|
2251
|
-
this.agent.state.model = replay.model;
|
|
2252
|
-
if (currentModel.contextWindow !== replay.contextWindow) {
|
|
2253
|
-
this._emit({ type: "context_window_changed", contextWindow: replay.contextWindow });
|
|
2254
|
-
}
|
|
2255
|
-
this._refreshBaseSystemPromptFromActiveTools();
|
|
2256
|
-
}
|
|
2257
|
-
_bindExtensionCore(runner) {
|
|
2258
|
-
const getCommands = () => {
|
|
2259
|
-
const extensionCommands = runner.getRegisteredCommands().map((command) => ({
|
|
2260
|
-
name: command.invocationName,
|
|
2261
|
-
description: command.description,
|
|
2262
|
-
source: "extension",
|
|
2263
|
-
sourceInfo: command.sourceInfo,
|
|
2264
|
-
}));
|
|
2265
|
-
const templates = this.promptTemplates.map((template) => ({
|
|
2266
|
-
name: template.name,
|
|
2267
|
-
description: template.description,
|
|
2268
|
-
source: "prompt",
|
|
2269
|
-
sourceInfo: template.sourceInfo,
|
|
2270
|
-
}));
|
|
2271
|
-
const skills = this._resourceLoader.getSkills().skills.map((skill) => ({
|
|
2272
|
-
name: `skill:${skill.name}`,
|
|
2273
|
-
description: skill.description,
|
|
2274
|
-
source: "skill",
|
|
2275
|
-
sourceInfo: skill.sourceInfo,
|
|
2276
|
-
}));
|
|
2277
|
-
return [...extensionCommands, ...templates, ...skills];
|
|
2278
|
-
};
|
|
2279
|
-
runner.bindCore({
|
|
2280
|
-
sendMessage: (message, options) => {
|
|
2281
|
-
this.sendCustomMessage(message, options).catch((err) => {
|
|
2282
|
-
runner.emitError({
|
|
2283
|
-
extensionPath: "<runtime>",
|
|
2284
|
-
event: "send_message",
|
|
2285
|
-
error: err instanceof Error ? err.message : String(err),
|
|
2286
|
-
});
|
|
2287
|
-
});
|
|
2288
|
-
},
|
|
2289
|
-
sendUserMessage: (content, options) => {
|
|
2290
|
-
this.sendUserMessage(content, options).catch((err) => {
|
|
2291
|
-
runner.emitError({
|
|
2292
|
-
extensionPath: "<runtime>",
|
|
2293
|
-
event: "send_user_message",
|
|
2294
|
-
error: err instanceof Error ? err.message : String(err),
|
|
2295
|
-
});
|
|
2296
|
-
});
|
|
2297
|
-
},
|
|
2298
|
-
appendEntry: (customType, data) => {
|
|
2299
|
-
this.sessionManager.appendCustomEntry(customType, data);
|
|
2300
|
-
},
|
|
2301
|
-
setSessionName: (name) => {
|
|
2302
|
-
this.setSessionName(name);
|
|
2303
|
-
},
|
|
2304
|
-
getSessionName: () => {
|
|
2305
|
-
return this.sessionManager.getSessionName();
|
|
2306
|
-
},
|
|
2307
|
-
setLabel: (entryId, label) => {
|
|
2308
|
-
this.sessionManager.appendLabelChange(entryId, label);
|
|
2309
|
-
},
|
|
2310
|
-
getActiveTools: () => this.getActiveToolNames(),
|
|
2311
|
-
getAllTools: () => this.getAllTools(),
|
|
2312
|
-
setActiveTools: (toolNames) => this.setActiveToolsByName(toolNames),
|
|
2313
|
-
refreshTools: () => this._refreshToolRegistry(),
|
|
2314
|
-
getCommands,
|
|
2315
|
-
setModel: async (model) => {
|
|
2316
|
-
if (!this.modelRegistry.hasConfiguredAuth(model))
|
|
2317
|
-
return false;
|
|
2318
|
-
await this.setModel(model);
|
|
2319
|
-
return true;
|
|
2320
|
-
},
|
|
2321
|
-
getThinkingLevel: () => this.thinkingLevel,
|
|
2322
|
-
setThinkingLevel: (level) => this.setThinkingLevel(level),
|
|
2323
|
-
}, {
|
|
2324
|
-
getModel: () => this.model,
|
|
2325
|
-
isIdle: () => !this.isStreaming,
|
|
2326
|
-
isProjectTrusted: () => this.settingsManager.isProjectTrusted(),
|
|
2327
|
-
getSignal: () => this.agent.signal,
|
|
2328
|
-
abort: () => this.abort(),
|
|
2329
|
-
hasPendingMessages: () => this.pendingMessageCount > 0,
|
|
2330
|
-
shutdown: () => {
|
|
2331
|
-
this._extensionShutdownHandler?.();
|
|
2332
|
-
},
|
|
2333
|
-
getContextUsage: () => this.getContextUsage(),
|
|
2334
|
-
compact: (options) => {
|
|
2335
|
-
void (async () => {
|
|
2336
|
-
try {
|
|
2337
|
-
const result = await this.compact({
|
|
2338
|
-
...(options?.compression_ratio === undefined ? {} : { compression_ratio: options.compression_ratio }),
|
|
2339
|
-
...(options?.preserve_recent === undefined ? {} : { preserve_recent: options.preserve_recent }),
|
|
2340
|
-
...(options?.query === undefined ? {} : { query: options.query }),
|
|
2341
|
-
});
|
|
2342
|
-
options?.onComplete?.(result);
|
|
2343
|
-
}
|
|
2344
|
-
catch (error) {
|
|
2345
|
-
const err = error instanceof Error ? error : new Error(String(error));
|
|
2346
|
-
options?.onError?.(err);
|
|
2347
|
-
}
|
|
2348
|
-
})();
|
|
2349
|
-
},
|
|
2350
|
-
getSystemPrompt: () => this.systemPrompt,
|
|
2351
|
-
getSystemPromptOptions: () => this._baseSystemPromptOptions,
|
|
2352
|
-
}, {
|
|
2353
|
-
registerProvider: (name, config) => {
|
|
2354
|
-
this._modelRegistry.registerProvider(name, config);
|
|
2355
|
-
this._refreshCurrentModelFromRegistry();
|
|
2356
|
-
},
|
|
2357
|
-
unregisterProvider: (name) => {
|
|
2358
|
-
this._modelRegistry.unregisterProvider(name);
|
|
2359
|
-
this._refreshCurrentModelFromRegistry();
|
|
2360
|
-
},
|
|
2361
|
-
});
|
|
2362
|
-
}
|
|
2363
|
-
_refreshToolRegistry(options) {
|
|
2364
|
-
const previousRegistryNames = new Set(this._toolRegistry.keys());
|
|
2365
|
-
const previousActiveToolNames = this.getActiveToolNames();
|
|
2366
|
-
const allowedToolNames = this._allowedToolNames;
|
|
2367
|
-
const excludedToolNames = this._excludedToolNames;
|
|
2368
|
-
const isExposedTool = (name) => {
|
|
2369
|
-
if (allowedToolNames && !allowedToolNames.has(name)) {
|
|
2370
|
-
return false;
|
|
2371
|
-
}
|
|
2372
|
-
if (excludedToolNames?.has(name)) {
|
|
2373
|
-
return false;
|
|
2374
|
-
}
|
|
2375
|
-
return true;
|
|
2376
|
-
};
|
|
2377
|
-
const registeredTools = this._extensionRunner.getAllRegisteredTools();
|
|
2378
|
-
const allCustomTools = [
|
|
2379
|
-
...registeredTools,
|
|
2380
|
-
...this._customTools.map((definition) => ({
|
|
2381
|
-
definition,
|
|
2382
|
-
sourceInfo: createSyntheticSourceInfo(`<sdk:${definition.name}>`, { source: "sdk" }),
|
|
2383
|
-
})),
|
|
2384
|
-
].filter((tool) => isExposedTool(tool.definition.name));
|
|
2385
|
-
const definitionRegistry = new Map(Array.from(this._baseToolDefinitions.entries())
|
|
2386
|
-
.filter(([name]) => isExposedTool(name))
|
|
2387
|
-
.map(([name, definition]) => [
|
|
2388
|
-
name,
|
|
2389
|
-
{
|
|
2390
|
-
definition,
|
|
2391
|
-
sourceInfo: createSyntheticSourceInfo(`<builtin:${name}>`, { source: "builtin" }),
|
|
2392
|
-
},
|
|
2393
|
-
]));
|
|
2394
|
-
for (const tool of allCustomTools) {
|
|
2395
|
-
definitionRegistry.set(tool.definition.name, {
|
|
2396
|
-
definition: tool.definition,
|
|
2397
|
-
sourceInfo: tool.sourceInfo,
|
|
2398
|
-
});
|
|
2399
|
-
}
|
|
2400
|
-
this._toolDefinitions = definitionRegistry;
|
|
2401
|
-
this._toolPromptSnippets = new Map(Array.from(definitionRegistry.values())
|
|
2402
|
-
.map(({ definition }) => {
|
|
2403
|
-
const snippet = this._normalizePromptSnippet(definition.promptSnippet);
|
|
2404
|
-
return snippet ? [definition.name, snippet] : undefined;
|
|
2405
|
-
})
|
|
2406
|
-
.filter((entry) => entry !== undefined));
|
|
2407
|
-
this._toolPromptGuidelines = new Map(Array.from(definitionRegistry.values())
|
|
2408
|
-
.map(({ definition }) => {
|
|
2409
|
-
const guidelines = this._normalizePromptGuidelines(definition.promptGuidelines);
|
|
2410
|
-
return guidelines.length > 0 ? [definition.name, guidelines] : undefined;
|
|
2411
|
-
})
|
|
2412
|
-
.filter((entry) => entry !== undefined));
|
|
2413
|
-
const runner = this._extensionRunner;
|
|
2414
|
-
const wrappedExtensionTools = wrapRegisteredTools(allCustomTools, runner);
|
|
2415
|
-
const wrappedBuiltInTools = wrapRegisteredTools(Array.from(this._baseToolDefinitions.values())
|
|
2416
|
-
.filter((definition) => isExposedTool(definition.name))
|
|
2417
|
-
.map((definition) => ({
|
|
2418
|
-
definition,
|
|
2419
|
-
sourceInfo: createSyntheticSourceInfo(`<builtin:${definition.name}>`, { source: "builtin" }),
|
|
2420
|
-
})), runner);
|
|
2421
|
-
const toolRegistry = new Map(wrappedBuiltInTools.map((tool) => [tool.name, tool]));
|
|
2422
|
-
for (const tool of wrappedExtensionTools) {
|
|
2423
|
-
toolRegistry.set(tool.name, tool);
|
|
2424
|
-
}
|
|
2425
|
-
// GitHub Copilot Gemini serializes array/object tool-call arguments as
|
|
2426
|
-
// flattened `name[index]` keys (confirmed on the raw CAPI wire). Reconstruct
|
|
2427
|
-
// them into proper arrays/objects before per-tool preparation and schema
|
|
2428
|
-
// validation, so tool calls (notably structured_output) don't fail and loop.
|
|
2429
|
-
// Gated to Copilot Gemini at call time via this.model; a no-op otherwise.
|
|
2430
|
-
// `prepareArguments` is a plain function field (no `this` binding), and the
|
|
2431
|
-
// `{ ...tool }` spread assumes AgentTools are plain objects — matching the
|
|
2432
|
-
// existing tool-definition-wrapper pattern; a class-instance tool would lose
|
|
2433
|
-
// prototype members here.
|
|
2434
|
-
this._toolRegistry = new Map(Array.from(toolRegistry, ([name, tool]) => {
|
|
2435
|
-
const basePrepareArguments = tool.prepareArguments;
|
|
2436
|
-
const prepareArguments = (args) => {
|
|
2437
|
-
const normalized = normalizeToolArgumentsForModel(args, this.model, tool.parameters);
|
|
2438
|
-
return basePrepareArguments ? basePrepareArguments(normalized) : normalized;
|
|
2439
|
-
};
|
|
2440
|
-
return [name, { ...tool, prepareArguments }];
|
|
2441
|
-
}));
|
|
2442
|
-
const nextActiveToolNames = (options?.activeToolNames ? [...options.activeToolNames] : [...previousActiveToolNames]).filter((name) => isExposedTool(name));
|
|
2443
|
-
if (allowedToolNames) {
|
|
2444
|
-
for (const toolName of this._toolRegistry.keys()) {
|
|
2445
|
-
if (allowedToolNames.has(toolName)) {
|
|
2446
|
-
nextActiveToolNames.push(toolName);
|
|
2447
|
-
}
|
|
2448
|
-
}
|
|
2449
|
-
}
|
|
2450
|
-
else if (options?.includeAllExtensionTools) {
|
|
2451
|
-
for (const tool of wrappedExtensionTools) {
|
|
2452
|
-
nextActiveToolNames.push(tool.name);
|
|
2453
|
-
}
|
|
2454
|
-
}
|
|
2455
|
-
else if (!options?.activeToolNames) {
|
|
2456
|
-
for (const toolName of this._toolRegistry.keys()) {
|
|
2457
|
-
if (!previousRegistryNames.has(toolName)) {
|
|
2458
|
-
nextActiveToolNames.push(toolName);
|
|
2459
|
-
}
|
|
2460
|
-
}
|
|
2461
|
-
}
|
|
2462
|
-
this.setActiveToolsByName([...new Set(nextActiveToolNames)]);
|
|
2463
|
-
}
|
|
2464
|
-
_buildRuntime(options) {
|
|
2465
|
-
const autoResizeImages = this.settingsManager.getImageAutoResize();
|
|
2466
|
-
const shellCommandPrefix = this.settingsManager.getShellCommandPrefix();
|
|
2467
|
-
const shellPath = this.settingsManager.getShellPath();
|
|
2468
|
-
const baseToolDefinitions = this._baseToolsOverride
|
|
2469
|
-
? Object.fromEntries(Object.entries(this._baseToolsOverride).map(([name, tool]) => [
|
|
2470
|
-
name,
|
|
2471
|
-
createToolDefinitionFromAgentTool(tool),
|
|
2472
|
-
]))
|
|
2473
|
-
: createAllToolDefinitions(this._cwd, {
|
|
2474
|
-
read: { autoResizeImages },
|
|
2475
|
-
bash: {
|
|
2476
|
-
commandPrefix: shellCommandPrefix,
|
|
2477
|
-
shellPath,
|
|
2478
|
-
policy: this._bashPolicy,
|
|
2479
|
-
policyLabel: "session bash policy",
|
|
2480
|
-
},
|
|
2481
|
-
});
|
|
2482
|
-
this._baseToolDefinitions = new Map(Object.entries(baseToolDefinitions).map(([name, tool]) => [name, tool]));
|
|
2483
|
-
const extensionsResult = this._resourceLoader.getExtensions();
|
|
2484
|
-
if (options.flagValues) {
|
|
2485
|
-
for (const [name, value] of options.flagValues) {
|
|
2486
|
-
extensionsResult.runtime.flagValues.set(name, value);
|
|
2487
|
-
}
|
|
2488
|
-
}
|
|
2489
|
-
this._extensionRunner = new ExtensionRunner(extensionsResult.extensions, extensionsResult.runtime, this._cwd, this.sessionManager, this._modelRegistry, this._orchestrationContext);
|
|
2490
|
-
if (this._extensionRunnerRef) {
|
|
2491
|
-
this._extensionRunnerRef.current = this._extensionRunner;
|
|
2492
|
-
}
|
|
2493
|
-
this._bindExtensionCore(this._extensionRunner);
|
|
2494
|
-
this._applyExtensionBindings(this._extensionRunner);
|
|
2495
|
-
const defaultActiveToolNames = this._baseToolsOverride
|
|
2496
|
-
? Object.keys(this._baseToolsOverride)
|
|
2497
|
-
: [...defaultToolNames];
|
|
2498
|
-
const baseActiveToolNames = options.activeToolNames ?? defaultActiveToolNames;
|
|
2499
|
-
this._refreshToolRegistry({
|
|
2500
|
-
activeToolNames: baseActiveToolNames,
|
|
2501
|
-
includeAllExtensionTools: options.includeAllExtensionTools,
|
|
2502
|
-
});
|
|
2503
|
-
}
|
|
2504
|
-
async reload() {
|
|
2505
|
-
const previousFlagValues = this._extensionRunner.getFlagValues();
|
|
2506
|
-
await emitSessionShutdownEvent(this._extensionRunner, { type: "session_shutdown", reason: "reload" });
|
|
2507
|
-
await this.settingsManager.reload();
|
|
2508
|
-
resetApiProviders();
|
|
2509
|
-
await this._resourceLoader.reload();
|
|
2510
|
-
this._buildRuntime({
|
|
2511
|
-
activeToolNames: this.getActiveToolNames(),
|
|
2512
|
-
flagValues: previousFlagValues,
|
|
2513
|
-
includeAllExtensionTools: true,
|
|
2514
|
-
});
|
|
2515
|
-
const hasBindings = this._extensionUIContext ||
|
|
2516
|
-
this._extensionCommandContextActions ||
|
|
2517
|
-
this._extensionShutdownHandler ||
|
|
2518
|
-
this._extensionErrorListener;
|
|
2519
|
-
if (hasBindings) {
|
|
2520
|
-
await this._extensionRunner.emit({ type: "session_start", reason: "reload" });
|
|
2521
|
-
await this.extendResourcesFromExtensions("reload");
|
|
2522
|
-
}
|
|
2523
|
-
}
|
|
2524
|
-
// =========================================================================
|
|
2525
|
-
// Auto-Retry
|
|
2526
|
-
// =========================================================================
|
|
2527
|
-
/**
|
|
2528
|
-
* Check if an error is retryable (overloaded, rate limit, server errors).
|
|
2529
|
-
* Context overflow errors are NOT retryable (handled by compaction instead).
|
|
2530
|
-
*/
|
|
2531
|
-
_isRetryableError(message) {
|
|
2532
|
-
if (message.stopReason !== "error" || !message.errorMessage)
|
|
2533
|
-
return false;
|
|
2534
|
-
// Context overflow is handled by compaction, not retry
|
|
2535
|
-
const contextWindow = this.model?.contextWindow ?? 0;
|
|
2536
|
-
if (isContextOverflow(message, contextWindow))
|
|
2537
|
-
return false;
|
|
2538
|
-
const err = message.errorMessage;
|
|
2539
|
-
// A genuine `content_filter` stop is a deliberate safety block: retrying it
|
|
2540
|
-
// re-issues the same blocked request up to maxRetries times for no benefit.
|
|
2541
|
-
// GitHub Copilot Gemini is the exception — CAPI maps spurious Gemini blocks
|
|
2542
|
-
// (RECITATION/safety on MALFORMED_FUNCTION_CALL etc.) to `content_filter`, so
|
|
2543
|
-
// only treat `content_filter` as retryable for those models.
|
|
2544
|
-
if (isCopilotGeminiModel({ provider: message.provider, api: message.api, id: message.model }) &&
|
|
2545
|
-
/finish.?reason:?\s*content.?filter/i.test(err)) {
|
|
2546
|
-
return true;
|
|
2547
|
-
}
|
|
2548
|
-
// Match: overloaded_error, provider returned error, rate limit, 429, 500, 502, 503, 504, service unavailable, network/connection errors (including connection lost), WebSocket transport closes/errors, fetch failed, premature stream endings, HTTP/2 closed before response, terminated, retry delay exceeded, and a bare/transient provider finish_reason "error" (e.g. github-copilot Gemini's CAPI mapping of MALFORMED_FUNCTION_CALL/OTHER/UNEXPECTED_TOOL_CALL). These are provider-agnostic transient failures.
|
|
2549
|
-
return /overloaded|provider.?returned.?error|rate.?limit|too many requests|429|500|502|503|504|service.?unavailable|server.?error|internal.?error|network.?error|connection.?error|connection.?refused|connection.?lost|websocket.?closed|websocket.?error|other side closed|fetch failed|upstream.?connect|reset before headers|socket hang up|ended without|stream ended before message_stop|http2 request did not get a response|timed? out|timeout|terminated|retry delay|finish.?reason:?\s*error/i.test(err);
|
|
2550
|
-
}
|
|
2551
|
-
/**
|
|
2552
|
-
* For GitHub Copilot Gemini, reconstruct flattened tool-call arguments
|
|
2553
|
-
* (for example `edits[0].newText`) into the nested arrays/objects Gemini
|
|
2554
|
-
* produced before the assistant message is persisted, so saved transcripts
|
|
2555
|
-
* never carry the flattened CAPI wire shape and replays loaded from disk match
|
|
2556
|
-
* the structure Gemini signed. In-place, gated to Copilot Gemini, and a no-op
|
|
2557
|
-
* for well-formed arguments or any other provider/model. The outbound replay
|
|
2558
|
-
* normalizer still heals already-persisted (legacy) sessions on the wire.
|
|
2559
|
-
*/
|
|
2560
|
-
_normalizePersistedGeminiToolArgs(message) {
|
|
2561
|
-
const model = this.model;
|
|
2562
|
-
if (!model || !isCopilotGeminiModel(model))
|
|
2563
|
-
return;
|
|
2564
|
-
for (const block of message.content) {
|
|
2565
|
-
if (block.type !== "toolCall")
|
|
2566
|
-
continue;
|
|
2567
|
-
const tool = this._toolRegistry.get(block.name);
|
|
2568
|
-
const normalized = normalizeToolArgumentsForModel(block.arguments, model, tool?.parameters);
|
|
2569
|
-
if (normalized !== block.arguments && normalized !== null && typeof normalized === "object") {
|
|
2570
|
-
block.arguments = normalized;
|
|
2571
|
-
}
|
|
2572
|
-
}
|
|
2573
|
-
}
|
|
2574
|
-
/**
|
|
2575
|
-
* Detect a degenerate empty completion: the provider ended the stream with no
|
|
2576
|
-
* usable content and zero output tokens. Seen with github-copilot Gemini models
|
|
2577
|
-
* that emit finish_reason "stop" (or a tool-use stop) with an empty content array
|
|
2578
|
-
* and 0 output tokens, leaving the turn dead instead of producing the next step.
|
|
2579
|
-
*
|
|
2580
|
-
* These are treated as retryable so the harness re-issues the request rather than
|
|
2581
|
-
* silently stopping mid-task. Guarded tightly (no text, no tool call, no thinking,
|
|
2582
|
-
* and output === 0) so legitimate non-empty turns are never matched.
|
|
2583
|
-
*
|
|
2584
|
-
* Intentionally provider-agnostic (not gated to Copilot Gemini): a degenerate
|
|
2585
|
-
* empty turn is a transient failure for any provider. It is bounded by
|
|
2586
|
-
* `maxRetries` and falls through to normal handling on exhaustion.
|
|
2587
|
-
*/
|
|
2588
|
-
_isEmptyCompletion(message) {
|
|
2589
|
-
// Only "completed" stop reasons can be deceptively empty. Real errors are handled
|
|
2590
|
-
// by _isRetryableError; aborted/length turns are intentional outcomes.
|
|
2591
|
-
if (message.stopReason !== "stop" && message.stopReason !== "toolUse")
|
|
2592
|
-
return false;
|
|
2593
|
-
const content = message.content;
|
|
2594
|
-
if (Array.isArray(content)) {
|
|
2595
|
-
const hasContent = content.some((part) => {
|
|
2596
|
-
if (part.type === "text")
|
|
2597
|
-
return part.text.trim().length > 0;
|
|
2598
|
-
if (part.type === "toolCall")
|
|
2599
|
-
return true;
|
|
2600
|
-
if (part.type === "thinking")
|
|
2601
|
-
return part.redacted === true || part.thinking.trim().length > 0;
|
|
2602
|
-
return true; // unknown part types count as content
|
|
2603
|
-
});
|
|
2604
|
-
if (hasContent)
|
|
2605
|
-
return false;
|
|
2606
|
-
}
|
|
2607
|
-
// A turn that produced output tokens but no surfaced content is not "empty"
|
|
2608
|
-
// (e.g. reasoning-only responses); leave those alone. Note: a provider that
|
|
2609
|
-
// fails to report `usage` (output defaults to 0) would make every
|
|
2610
|
-
// content-less turn match here; the dual requirement (empty content AND zero
|
|
2611
|
-
// output) keeps that false-positive risk low in practice.
|
|
2612
|
-
return (message.usage?.output ?? 0) === 0;
|
|
2613
|
-
}
|
|
2614
|
-
/**
|
|
2615
|
-
* Handle retryable errors with exponential backoff.
|
|
2616
|
-
* @returns true if retry was initiated, false if max retries exceeded or disabled
|
|
2617
|
-
*/
|
|
2618
|
-
async _handleRetryableError(message) {
|
|
2619
|
-
const settings = this.settingsManager.getRetrySettings();
|
|
2620
|
-
if (!settings.enabled) {
|
|
2621
|
-
this._resolveRetry();
|
|
2622
|
-
return false;
|
|
2623
|
-
}
|
|
2624
|
-
// Retry promise is created synchronously in _handleAgentEvent for agent_end.
|
|
2625
|
-
// Keep a defensive fallback here in case a future refactor bypasses that path.
|
|
2626
|
-
if (!this._retryPromise) {
|
|
2627
|
-
this._retryPromise = new Promise((resolve) => {
|
|
2628
|
-
this._retryResolve = resolve;
|
|
2629
|
-
});
|
|
2630
|
-
}
|
|
2631
|
-
this._retryAttempt++;
|
|
2632
|
-
if (this._retryAttempt > settings.maxRetries) {
|
|
2633
|
-
// Max retries exceeded, emit final failure and reset
|
|
2634
|
-
this._emit({
|
|
2635
|
-
type: "auto_retry_end",
|
|
2636
|
-
success: false,
|
|
2637
|
-
attempt: this._retryAttempt - 1,
|
|
2638
|
-
finalError: message.errorMessage,
|
|
2639
|
-
});
|
|
2640
|
-
this._retryAttempt = 0;
|
|
2641
|
-
this._resolveRetry(); // Resolve so waitForRetry() completes
|
|
2642
|
-
return false;
|
|
2643
|
-
}
|
|
2644
|
-
const delayMs = settings.baseDelayMs * 2 ** (this._retryAttempt - 1);
|
|
2645
|
-
this._emit({
|
|
2646
|
-
type: "auto_retry_start",
|
|
2647
|
-
attempt: this._retryAttempt,
|
|
2648
|
-
maxAttempts: settings.maxRetries,
|
|
2649
|
-
delayMs,
|
|
2650
|
-
errorMessage: message.errorMessage || "Unknown error",
|
|
2651
|
-
});
|
|
2652
|
-
// Remove error message from agent state (keep in session for history)
|
|
2653
|
-
const messages = this.agent.state.messages;
|
|
2654
|
-
if (messages.length > 0 && messages[messages.length - 1].role === "assistant") {
|
|
2655
|
-
this.agent.state.messages = messages.slice(0, -1);
|
|
2656
|
-
}
|
|
2657
|
-
// Wait with exponential backoff (abortable)
|
|
2658
|
-
this._retryAbortController = new AbortController();
|
|
2659
|
-
try {
|
|
2660
|
-
await sleep(delayMs, this._retryAbortController.signal);
|
|
2661
|
-
}
|
|
2662
|
-
catch {
|
|
2663
|
-
// Aborted during sleep - emit end event so UI can clean up
|
|
2664
|
-
const attempt = this._retryAttempt;
|
|
2665
|
-
this._retryAttempt = 0;
|
|
2666
|
-
this._retryAbortController = undefined;
|
|
2667
|
-
this._emit({
|
|
2668
|
-
type: "auto_retry_end",
|
|
2669
|
-
success: false,
|
|
2670
|
-
attempt,
|
|
2671
|
-
finalError: "Retry cancelled",
|
|
2672
|
-
});
|
|
2673
|
-
this._resolveRetry();
|
|
2674
|
-
return false;
|
|
2675
|
-
}
|
|
2676
|
-
this._retryAbortController = undefined;
|
|
2677
|
-
// Retry via continue() - use setTimeout to break out of event handler chain
|
|
2678
|
-
setTimeout(() => {
|
|
2679
|
-
this.agent.continue().catch(() => {
|
|
2680
|
-
// Retry failed - will be caught by next agent_end
|
|
2681
|
-
});
|
|
2682
|
-
}, 0);
|
|
2683
|
-
return true;
|
|
2684
|
-
}
|
|
2685
|
-
/**
|
|
2686
|
-
* Cancel in-progress retry.
|
|
2687
|
-
*/
|
|
2688
|
-
abortRetry() {
|
|
2689
|
-
this._retryAbortController?.abort();
|
|
2690
|
-
// Note: _retryAttempt is reset in the catch block of _autoRetry
|
|
2691
|
-
this._resolveRetry();
|
|
2692
|
-
}
|
|
2693
|
-
/**
|
|
2694
|
-
* Wait for any in-progress retry to complete.
|
|
2695
|
-
* Returns immediately if no retry is in progress.
|
|
2696
|
-
*/
|
|
2697
|
-
async waitForRetry() {
|
|
2698
|
-
if (!this._retryPromise) {
|
|
2699
|
-
return;
|
|
2700
|
-
}
|
|
2701
|
-
await this._retryPromise;
|
|
2702
|
-
await this.agent.waitForIdle();
|
|
2703
|
-
}
|
|
2704
|
-
/** Whether auto-retry is currently in progress */
|
|
2705
|
-
get isRetrying() {
|
|
2706
|
-
return this._retryPromise !== undefined;
|
|
2707
|
-
}
|
|
2708
|
-
/** Whether auto-retry is enabled */
|
|
2709
|
-
get autoRetryEnabled() {
|
|
2710
|
-
return this.settingsManager.getRetryEnabled();
|
|
2711
|
-
}
|
|
2712
|
-
/**
|
|
2713
|
-
* Toggle auto-retry setting.
|
|
2714
|
-
*/
|
|
2715
|
-
setAutoRetryEnabled(enabled) {
|
|
2716
|
-
this.settingsManager.setRetryEnabled(enabled);
|
|
2717
|
-
}
|
|
2718
|
-
// =========================================================================
|
|
2719
|
-
// Bash Execution
|
|
2720
|
-
// =========================================================================
|
|
2721
|
-
/**
|
|
2722
|
-
* Execute a bash command.
|
|
2723
|
-
* Adds result to agent context and session.
|
|
2724
|
-
* @param command The bash command to execute
|
|
2725
|
-
* @param onChunk Optional streaming callback for output
|
|
2726
|
-
* @param options.excludeFromContext If true, command output won't be sent to LLM (!! prefix)
|
|
2727
|
-
* @param options.operations Custom BashOperations for remote execution
|
|
2728
|
-
*/
|
|
2729
|
-
async executeBash(command, onChunk, options) {
|
|
2730
|
-
const policyDecision = evaluateBashCommandPolicy(command, this._bashPolicy);
|
|
2731
|
-
if (!policyDecision.allowed) {
|
|
2732
|
-
throw new Error(formatBashCommandPolicyRejection(policyDecision, "session bash policy"));
|
|
2733
|
-
}
|
|
2734
|
-
this._bashAbortController = new AbortController();
|
|
2735
|
-
// Apply command prefix if configured (e.g., "shopt -s expand_aliases" for alias support)
|
|
2736
|
-
const prefix = this.settingsManager.getShellCommandPrefix();
|
|
2737
|
-
const shellPath = this.settingsManager.getShellPath();
|
|
2738
|
-
const resolvedCommand = prefix ? `${prefix}\n${command}` : command;
|
|
2739
|
-
try {
|
|
2740
|
-
const result = await executeBashWithOperations(resolvedCommand, this.sessionManager.getCwd(), options?.operations ?? createLocalBashOperations({ shellPath }), {
|
|
2741
|
-
onChunk,
|
|
2742
|
-
signal: this._bashAbortController.signal,
|
|
2743
|
-
});
|
|
2744
|
-
this.recordBashResult(command, result, options);
|
|
2745
|
-
return result;
|
|
2746
|
-
}
|
|
2747
|
-
finally {
|
|
2748
|
-
this._bashAbortController = undefined;
|
|
2749
|
-
}
|
|
2750
|
-
}
|
|
2751
|
-
/**
|
|
2752
|
-
* Record a bash execution result in session history.
|
|
2753
|
-
* Used by executeBash and by extensions that handle bash execution themselves.
|
|
2754
|
-
*/
|
|
2755
|
-
recordBashResult(command, result, options) {
|
|
2756
|
-
const bashMessage = {
|
|
2757
|
-
role: "bashExecution",
|
|
2758
|
-
command,
|
|
2759
|
-
output: result.output,
|
|
2760
|
-
exitCode: result.exitCode,
|
|
2761
|
-
cancelled: result.cancelled,
|
|
2762
|
-
truncated: result.truncated,
|
|
2763
|
-
fullOutputPath: result.fullOutputPath,
|
|
2764
|
-
timestamp: Date.now(),
|
|
2765
|
-
excludeFromContext: options?.excludeFromContext,
|
|
2766
|
-
};
|
|
2767
|
-
// If agent is streaming, defer adding to avoid breaking tool_use/tool_result ordering
|
|
2768
|
-
if (this.isStreaming) {
|
|
2769
|
-
// Queue for later - will be flushed on agent_end
|
|
2770
|
-
this._pendingBashMessages.push(bashMessage);
|
|
2771
|
-
}
|
|
2772
|
-
else {
|
|
2773
|
-
// Add to agent state immediately
|
|
2774
|
-
this.agent.state.messages.push(bashMessage);
|
|
2775
|
-
// Save to session
|
|
2776
|
-
this.sessionManager.appendMessage(bashMessage);
|
|
2777
|
-
}
|
|
2778
|
-
}
|
|
2779
|
-
/**
|
|
2780
|
-
* Cancel running bash command.
|
|
2781
|
-
*/
|
|
2782
|
-
abortBash() {
|
|
2783
|
-
this._bashAbortController?.abort();
|
|
2784
|
-
}
|
|
2785
|
-
/** Whether a bash command is currently running */
|
|
2786
|
-
get isBashRunning() {
|
|
2787
|
-
return this._bashAbortController !== undefined;
|
|
2788
|
-
}
|
|
2789
|
-
/** Whether there are pending bash messages waiting to be flushed */
|
|
2790
|
-
get hasPendingBashMessages() {
|
|
2791
|
-
return this._pendingBashMessages.length > 0;
|
|
2792
|
-
}
|
|
2793
|
-
/**
|
|
2794
|
-
* Flush pending bash messages to agent state and session.
|
|
2795
|
-
* Called after agent turn completes to maintain proper message ordering.
|
|
2796
|
-
*/
|
|
2797
|
-
_flushPendingBashMessages() {
|
|
2798
|
-
if (this._pendingBashMessages.length === 0)
|
|
2799
|
-
return;
|
|
2800
|
-
for (const bashMessage of this._pendingBashMessages) {
|
|
2801
|
-
// Add to agent state
|
|
2802
|
-
this.agent.state.messages.push(bashMessage);
|
|
2803
|
-
// Save to session
|
|
2804
|
-
this.sessionManager.appendMessage(bashMessage);
|
|
2805
|
-
}
|
|
2806
|
-
this._pendingBashMessages = [];
|
|
2807
|
-
}
|
|
2808
|
-
// =========================================================================
|
|
2809
|
-
// Session Management
|
|
2810
|
-
// =========================================================================
|
|
2811
|
-
/**
|
|
2812
|
-
* Set a display name for the current session.
|
|
2813
|
-
*/
|
|
2814
|
-
setSessionName(name) {
|
|
2815
|
-
this.sessionManager.appendSessionInfo(name);
|
|
2816
|
-
this._emit({ type: "session_info_changed", name: this.sessionManager.getSessionName() });
|
|
2817
|
-
}
|
|
2818
|
-
// =========================================================================
|
|
2819
|
-
// Tree Navigation
|
|
2820
|
-
// =========================================================================
|
|
2821
|
-
/**
|
|
2822
|
-
* Navigate to a different node in the session tree.
|
|
2823
|
-
* Unlike fork() which creates a new session file, this stays in the same file.
|
|
2824
|
-
*
|
|
2825
|
-
* @param targetId The entry ID to navigate to
|
|
2826
|
-
* @param options.summarize Whether user wants to summarize abandoned branch
|
|
2827
|
-
* @param options.customInstructions Custom instructions for summarizer
|
|
2828
|
-
* @param options.replaceInstructions If true, customInstructions replaces the default prompt
|
|
2829
|
-
* @param options.label Label to attach to the branch summary entry
|
|
2830
|
-
* @returns Result with editorText (if user message) and cancelled status
|
|
2831
|
-
*/
|
|
2832
|
-
async navigateTree(targetId, options = {}) {
|
|
2833
|
-
const oldLeafId = this.sessionManager.getLeafId();
|
|
2834
|
-
// No-op if already at target
|
|
2835
|
-
if (targetId === oldLeafId) {
|
|
2836
|
-
return { cancelled: false };
|
|
2837
|
-
}
|
|
2838
|
-
// Model required for summarization
|
|
2839
|
-
if (options.summarize && !this.model) {
|
|
2840
|
-
throw new Error("No model available for summarization");
|
|
2841
|
-
}
|
|
2842
|
-
const targetEntry = this.sessionManager.getEntry(targetId);
|
|
2843
|
-
if (!targetEntry) {
|
|
2844
|
-
throw new Error(`Entry ${targetId} not found`);
|
|
2845
|
-
}
|
|
2846
|
-
// Collect entries to summarize (from old leaf to common ancestor)
|
|
2847
|
-
const { entries: entriesToSummarize, commonAncestorId } = collectEntriesForBranchSummary(this.sessionManager, oldLeafId, targetId);
|
|
2848
|
-
// Prepare event data - mutable so extensions can override
|
|
2849
|
-
let customInstructions = options.customInstructions;
|
|
2850
|
-
let replaceInstructions = options.replaceInstructions;
|
|
2851
|
-
let label = options.label;
|
|
2852
|
-
const preparation = {
|
|
2853
|
-
targetId,
|
|
2854
|
-
oldLeafId,
|
|
2855
|
-
commonAncestorId,
|
|
2856
|
-
entriesToSummarize,
|
|
2857
|
-
userWantsSummary: options.summarize ?? false,
|
|
2858
|
-
customInstructions,
|
|
2859
|
-
replaceInstructions,
|
|
2860
|
-
label,
|
|
2861
|
-
};
|
|
2862
|
-
// Set up abort controller for summarization
|
|
2863
|
-
this._branchSummaryAbortController = new AbortController();
|
|
2864
|
-
try {
|
|
2865
|
-
let extensionSummary;
|
|
2866
|
-
let fromExtension = false;
|
|
2867
|
-
// Emit session_before_tree event
|
|
2868
|
-
if (this._extensionRunner.hasHandlers("session_before_tree")) {
|
|
2869
|
-
const result = (await this._extensionRunner.emit({
|
|
2870
|
-
type: "session_before_tree",
|
|
2871
|
-
preparation,
|
|
2872
|
-
signal: this._branchSummaryAbortController.signal,
|
|
2873
|
-
}));
|
|
2874
|
-
if (result?.cancel) {
|
|
2875
|
-
return { cancelled: true };
|
|
2876
|
-
}
|
|
2877
|
-
if (result?.summary && options.summarize) {
|
|
2878
|
-
extensionSummary = result.summary;
|
|
2879
|
-
fromExtension = true;
|
|
2880
|
-
}
|
|
2881
|
-
// Allow extensions to override instructions and label
|
|
2882
|
-
if (result?.customInstructions !== undefined) {
|
|
2883
|
-
customInstructions = result.customInstructions;
|
|
2884
|
-
}
|
|
2885
|
-
if (result?.replaceInstructions !== undefined) {
|
|
2886
|
-
replaceInstructions = result.replaceInstructions;
|
|
2887
|
-
}
|
|
2888
|
-
if (result?.label !== undefined) {
|
|
2889
|
-
label = result.label;
|
|
2890
|
-
}
|
|
2891
|
-
}
|
|
2892
|
-
// Run default summarizer if needed
|
|
2893
|
-
let summaryText;
|
|
2894
|
-
let summaryDetails;
|
|
2895
|
-
if (options.summarize && entriesToSummarize.length > 0 && !extensionSummary) {
|
|
2896
|
-
const model = this.model;
|
|
2897
|
-
const { apiKey, headers } = await this._getRequiredRequestAuth(model);
|
|
2898
|
-
const branchSummarySettings = this.settingsManager.getBranchSummarySettings();
|
|
2899
|
-
const result = await generateBranchSummary(entriesToSummarize, {
|
|
2900
|
-
model,
|
|
2901
|
-
apiKey,
|
|
2902
|
-
headers,
|
|
2903
|
-
signal: this._branchSummaryAbortController.signal,
|
|
2904
|
-
customInstructions,
|
|
2905
|
-
replaceInstructions,
|
|
2906
|
-
reserveTokens: branchSummarySettings.reserveTokens,
|
|
2907
|
-
streamFn: this.agent.streamFn,
|
|
2908
|
-
});
|
|
2909
|
-
if (result.aborted) {
|
|
2910
|
-
return { cancelled: true, aborted: true };
|
|
2911
|
-
}
|
|
2912
|
-
if (result.error) {
|
|
2913
|
-
throw new Error(result.error);
|
|
2914
|
-
}
|
|
2915
|
-
summaryText = result.summary;
|
|
2916
|
-
summaryDetails = {
|
|
2917
|
-
readFiles: result.readFiles || [],
|
|
2918
|
-
modifiedFiles: result.modifiedFiles || [],
|
|
2919
|
-
};
|
|
2920
|
-
}
|
|
2921
|
-
else if (extensionSummary) {
|
|
2922
|
-
summaryText = extensionSummary.summary;
|
|
2923
|
-
summaryDetails = extensionSummary.details;
|
|
2924
|
-
}
|
|
2925
|
-
// Determine the new leaf position based on target type
|
|
2926
|
-
let newLeafId;
|
|
2927
|
-
let editorText;
|
|
2928
|
-
if (targetEntry.type === "message" && targetEntry.message.role === "user") {
|
|
2929
|
-
// User message: leaf = parent (null if root), text goes to editor
|
|
2930
|
-
newLeafId = targetEntry.parentId;
|
|
2931
|
-
editorText = this._extractUserMessageText(targetEntry.message.content);
|
|
2932
|
-
}
|
|
2933
|
-
else if (targetEntry.type === "custom_message") {
|
|
2934
|
-
// Custom message: leaf = parent (null if root), text goes to editor
|
|
2935
|
-
newLeafId = targetEntry.parentId;
|
|
2936
|
-
editorText =
|
|
2937
|
-
typeof targetEntry.content === "string"
|
|
2938
|
-
? targetEntry.content
|
|
2939
|
-
: targetEntry.content
|
|
2940
|
-
.filter((c) => c.type === "text")
|
|
2941
|
-
.map((c) => c.text)
|
|
2942
|
-
.join("");
|
|
2943
|
-
}
|
|
2944
|
-
else {
|
|
2945
|
-
// Non-user message: leaf = selected node
|
|
2946
|
-
newLeafId = targetId;
|
|
2947
|
-
}
|
|
2948
|
-
// Switch leaf (with or without summary)
|
|
2949
|
-
// Summary is attached at the navigation target position (newLeafId), not the old branch
|
|
2950
|
-
let summaryEntry;
|
|
2951
|
-
if (summaryText) {
|
|
2952
|
-
// Create summary at target position (can be null for root)
|
|
2953
|
-
const summaryId = this.sessionManager.branchWithSummary(newLeafId, summaryText, summaryDetails, fromExtension);
|
|
2954
|
-
summaryEntry = this.sessionManager.getEntry(summaryId);
|
|
2955
|
-
// Attach label to the summary entry
|
|
2956
|
-
if (label) {
|
|
2957
|
-
this.sessionManager.appendLabelChange(summaryId, label);
|
|
2958
|
-
}
|
|
2959
|
-
}
|
|
2960
|
-
else if (newLeafId === null) {
|
|
2961
|
-
// No summary, navigating to root - reset leaf
|
|
2962
|
-
this.sessionManager.resetLeaf();
|
|
2963
|
-
}
|
|
2964
|
-
else {
|
|
2965
|
-
// No summary, navigating to non-root
|
|
2966
|
-
this.sessionManager.branch(newLeafId);
|
|
2967
|
-
}
|
|
2968
|
-
// Attach label to target entry when not summarizing (no summary entry to label)
|
|
2969
|
-
if (label && !summaryText) {
|
|
2970
|
-
this.sessionManager.appendLabelChange(targetId, label);
|
|
2971
|
-
}
|
|
2972
|
-
// Update agent state
|
|
2973
|
-
const sessionContext = this.sessionManager.buildSessionContext();
|
|
2974
|
-
this.agent.state.messages = sessionContext.messages;
|
|
2975
|
-
this._applyContextWindowReplay(sessionContext.contextWindow);
|
|
2976
|
-
// Emit session_tree event
|
|
2977
|
-
await this._extensionRunner.emit({
|
|
2978
|
-
type: "session_tree",
|
|
2979
|
-
newLeafId: this.sessionManager.getLeafId(),
|
|
2980
|
-
oldLeafId,
|
|
2981
|
-
summaryEntry,
|
|
2982
|
-
fromExtension: summaryText ? fromExtension : undefined,
|
|
2983
|
-
});
|
|
2984
|
-
// Emit to custom tools
|
|
2985
|
-
return { editorText, cancelled: false, summaryEntry };
|
|
2986
|
-
}
|
|
2987
|
-
finally {
|
|
2988
|
-
this._branchSummaryAbortController = undefined;
|
|
2989
|
-
}
|
|
2990
|
-
}
|
|
2991
|
-
/**
|
|
2992
|
-
* Get all user messages from session for fork selector.
|
|
2993
|
-
*/
|
|
2994
|
-
getUserMessagesForForking() {
|
|
2995
|
-
const entries = this.sessionManager.getEntries();
|
|
2996
|
-
const result = [];
|
|
2997
|
-
for (const entry of entries) {
|
|
2998
|
-
if (entry.type !== "message")
|
|
2999
|
-
continue;
|
|
3000
|
-
if (entry.message.role !== "user")
|
|
3001
|
-
continue;
|
|
3002
|
-
const text = this._extractUserMessageText(entry.message.content);
|
|
3003
|
-
if (text) {
|
|
3004
|
-
result.push({ entryId: entry.id, text });
|
|
3005
|
-
}
|
|
3006
|
-
}
|
|
3007
|
-
return result;
|
|
3008
|
-
}
|
|
3009
|
-
_extractUserMessageText(content) {
|
|
3010
|
-
if (typeof content === "string")
|
|
3011
|
-
return content;
|
|
3012
|
-
if (Array.isArray(content)) {
|
|
3013
|
-
return content
|
|
3014
|
-
.filter((c) => c.type === "text")
|
|
3015
|
-
.map((c) => c.text)
|
|
3016
|
-
.join("");
|
|
3017
|
-
}
|
|
3018
|
-
return "";
|
|
3019
|
-
}
|
|
3020
|
-
/**
|
|
3021
|
-
* Get session statistics.
|
|
3022
|
-
*/
|
|
3023
|
-
getSessionStats() {
|
|
3024
|
-
const state = this.state;
|
|
3025
|
-
const userMessages = state.messages.filter((m) => m.role === "user").length;
|
|
3026
|
-
const assistantMessages = state.messages.filter((m) => m.role === "assistant").length;
|
|
3027
|
-
const toolResults = state.messages.filter((m) => m.role === "toolResult").length;
|
|
3028
|
-
let toolCalls = 0;
|
|
3029
|
-
let totalInput = 0;
|
|
3030
|
-
let totalOutput = 0;
|
|
3031
|
-
let totalCacheRead = 0;
|
|
3032
|
-
let totalCacheWrite = 0;
|
|
3033
|
-
let totalCost = 0;
|
|
3034
|
-
for (const message of state.messages) {
|
|
3035
|
-
if (message.role === "assistant") {
|
|
3036
|
-
const assistantMsg = message;
|
|
3037
|
-
toolCalls += assistantMsg.content.filter((c) => c.type === "toolCall").length;
|
|
3038
|
-
totalInput += assistantMsg.usage.input;
|
|
3039
|
-
totalOutput += assistantMsg.usage.output;
|
|
3040
|
-
totalCacheRead += assistantMsg.usage.cacheRead;
|
|
3041
|
-
totalCacheWrite += assistantMsg.usage.cacheWrite;
|
|
3042
|
-
totalCost += assistantMsg.usage.cost.total;
|
|
3043
|
-
}
|
|
3044
|
-
}
|
|
3045
|
-
return {
|
|
3046
|
-
sessionFile: this.sessionFile,
|
|
3047
|
-
sessionId: this.sessionId,
|
|
3048
|
-
userMessages,
|
|
3049
|
-
assistantMessages,
|
|
3050
|
-
toolCalls,
|
|
3051
|
-
toolResults,
|
|
3052
|
-
totalMessages: state.messages.length,
|
|
3053
|
-
tokens: {
|
|
3054
|
-
input: totalInput,
|
|
3055
|
-
output: totalOutput,
|
|
3056
|
-
cacheRead: totalCacheRead,
|
|
3057
|
-
cacheWrite: totalCacheWrite,
|
|
3058
|
-
total: totalInput + totalOutput + totalCacheRead + totalCacheWrite,
|
|
3059
|
-
},
|
|
3060
|
-
cost: totalCost,
|
|
3061
|
-
contextUsage: this.getContextUsage(),
|
|
3062
|
-
};
|
|
3063
|
-
}
|
|
3064
|
-
getContextUsage() {
|
|
3065
|
-
const model = this.model;
|
|
3066
|
-
if (!model)
|
|
3067
|
-
return undefined;
|
|
3068
|
-
const contextWindow = model.contextWindow ?? 0;
|
|
3069
|
-
if (contextWindow <= 0)
|
|
3070
|
-
return undefined;
|
|
3071
|
-
// After compaction, the last assistant usage reflects pre-compaction context size.
|
|
3072
|
-
// We can only trust usage from an assistant that responded after the latest compaction.
|
|
3073
|
-
// If no such assistant exists, context token count is unknown until the next LLM response.
|
|
3074
|
-
const branchEntries = this.sessionManager.getBranch();
|
|
3075
|
-
const latestCompactionBoundary = getLatestCompactionBoundaryEntry(branchEntries);
|
|
3076
|
-
if (latestCompactionBoundary) {
|
|
3077
|
-
// Check if there's a valid assistant usage after the compaction boundary
|
|
3078
|
-
const compactionIndex = branchEntries.lastIndexOf(latestCompactionBoundary);
|
|
3079
|
-
let hasPostCompactionUsage = false;
|
|
3080
|
-
for (let i = branchEntries.length - 1; i > compactionIndex; i--) {
|
|
3081
|
-
const entry = branchEntries[i];
|
|
3082
|
-
if (entry.type === "message" && entry.message.role === "assistant") {
|
|
3083
|
-
const assistant = entry.message;
|
|
3084
|
-
if (assistant.stopReason !== "aborted" && assistant.stopReason !== "error") {
|
|
3085
|
-
const contextTokens = calculateContextTokens(assistant.usage);
|
|
3086
|
-
if (contextTokens > 0) {
|
|
3087
|
-
hasPostCompactionUsage = true;
|
|
3088
|
-
}
|
|
3089
|
-
break;
|
|
3090
|
-
}
|
|
3091
|
-
}
|
|
3092
|
-
}
|
|
3093
|
-
if (!hasPostCompactionUsage) {
|
|
3094
|
-
return { tokens: null, contextWindow, percent: null };
|
|
3095
|
-
}
|
|
3096
|
-
}
|
|
3097
|
-
const estimate = estimateContextTokens(this.messages);
|
|
3098
|
-
const percent = (estimate.tokens / contextWindow) * 100;
|
|
3099
|
-
return {
|
|
3100
|
-
tokens: estimate.tokens,
|
|
3101
|
-
contextWindow,
|
|
3102
|
-
percent,
|
|
3103
|
-
};
|
|
3104
|
-
}
|
|
3105
|
-
/**
|
|
3106
|
-
* Export session to HTML.
|
|
3107
|
-
* @param outputPath Optional output path (defaults to session directory)
|
|
3108
|
-
* @returns Path to exported file
|
|
3109
|
-
*/
|
|
3110
|
-
async exportToHtml(outputPath) {
|
|
3111
|
-
const themeName = this.settingsManager.getTheme();
|
|
3112
|
-
// Create tool renderer if we have an extension runner (for custom tool HTML rendering)
|
|
3113
|
-
const toolRenderer = createToolHtmlRenderer({
|
|
3114
|
-
getToolDefinition: (name) => this.getToolDefinition(name),
|
|
3115
|
-
theme,
|
|
3116
|
-
cwd: this.sessionManager.getCwd(),
|
|
3117
|
-
});
|
|
3118
|
-
return await exportSessionToHtml(this.sessionManager, this.state, {
|
|
3119
|
-
outputPath,
|
|
3120
|
-
themeName,
|
|
3121
|
-
toolRenderer,
|
|
3122
|
-
});
|
|
3123
|
-
}
|
|
3124
|
-
/**
|
|
3125
|
-
* Export the current session branch to a JSONL file.
|
|
3126
|
-
* Writes the session header followed by all entries on the current branch path.
|
|
3127
|
-
* @param outputPath Target file path. If omitted, generates a timestamped file in cwd.
|
|
3128
|
-
* @returns The resolved output file path.
|
|
3129
|
-
*/
|
|
3130
|
-
exportToJsonl(outputPath) {
|
|
3131
|
-
const filePath = resolvePath(outputPath ?? `session-${new Date().toISOString().replace(/[:.]/g, "-")}.jsonl`, process.cwd());
|
|
3132
|
-
const dir = dirname(filePath);
|
|
3133
|
-
if (!existsSync(dir)) {
|
|
3134
|
-
mkdirSync(dir, { recursive: true });
|
|
3135
|
-
}
|
|
3136
|
-
const header = {
|
|
3137
|
-
type: "session",
|
|
3138
|
-
version: CURRENT_SESSION_VERSION,
|
|
3139
|
-
id: this.sessionManager.getSessionId(),
|
|
3140
|
-
timestamp: new Date().toISOString(),
|
|
3141
|
-
cwd: this.sessionManager.getCwd(),
|
|
3142
|
-
};
|
|
3143
|
-
const branchEntries = this.sessionManager.getBranch();
|
|
3144
|
-
const lines = [JSON.stringify(header)];
|
|
3145
|
-
// Re-chain parentIds to form a linear sequence
|
|
3146
|
-
let prevId = null;
|
|
3147
|
-
for (const entry of branchEntries) {
|
|
3148
|
-
const linear = { ...entry, parentId: prevId };
|
|
3149
|
-
lines.push(JSON.stringify(linear));
|
|
3150
|
-
prevId = entry.id;
|
|
3151
|
-
}
|
|
3152
|
-
writeFileSync(filePath, `${lines.join("\n")}\n`);
|
|
3153
|
-
return filePath;
|
|
3154
|
-
}
|
|
3155
|
-
// =========================================================================
|
|
3156
|
-
// Utilities
|
|
3157
|
-
// =========================================================================
|
|
3158
|
-
/**
|
|
3159
|
-
* Get text content of last assistant message.
|
|
3160
|
-
* Useful for /copy command.
|
|
3161
|
-
* @returns Text content, or undefined if no assistant message exists
|
|
3162
|
-
*/
|
|
3163
|
-
getLastAssistantText() {
|
|
3164
|
-
const lastAssistant = this.messages
|
|
3165
|
-
.slice()
|
|
3166
|
-
.reverse()
|
|
3167
|
-
.find((m) => {
|
|
3168
|
-
if (m.role !== "assistant")
|
|
3169
|
-
return false;
|
|
3170
|
-
const msg = m;
|
|
3171
|
-
// Skip aborted messages with no content
|
|
3172
|
-
if (msg.stopReason === "aborted" && msg.content.length === 0)
|
|
3173
|
-
return false;
|
|
3174
|
-
return true;
|
|
3175
|
-
});
|
|
3176
|
-
if (!lastAssistant)
|
|
3177
|
-
return undefined;
|
|
3178
|
-
let text = "";
|
|
3179
|
-
for (const content of lastAssistant.content) {
|
|
3180
|
-
if (content.type === "text") {
|
|
3181
|
-
text += content.text;
|
|
3182
|
-
}
|
|
3183
|
-
}
|
|
3184
|
-
return text.trim() || undefined;
|
|
3185
|
-
}
|
|
3186
|
-
// =========================================================================
|
|
3187
|
-
// Extension System
|
|
3188
|
-
// =========================================================================
|
|
3189
|
-
createReplacedSessionContext() {
|
|
3190
|
-
const context = Object.defineProperties({}, Object.getOwnPropertyDescriptors(this._extensionRunner.createCommandContext()));
|
|
3191
|
-
context.sendMessage = (message, options) => this.sendCustomMessage(message, options);
|
|
3192
|
-
context.sendUserMessage = (content, options) => this.sendUserMessage(content, options);
|
|
3193
|
-
return context;
|
|
3194
|
-
}
|
|
3195
|
-
/**
|
|
3196
|
-
* Check if extensions have handlers for a specific event type.
|
|
3197
|
-
*/
|
|
3198
|
-
hasExtensionHandlers(eventType) {
|
|
3199
|
-
return this._extensionRunner.hasHandlers(eventType);
|
|
3200
|
-
}
|
|
3201
|
-
/**
|
|
3202
|
-
* Get the extension runner (for setting UI context and error handlers).
|
|
3203
|
-
*/
|
|
3204
|
-
get extensionRunner() {
|
|
3205
|
-
return this._extensionRunner;
|
|
3206
|
-
}
|
|
3207
78
|
}
|
|
79
|
+
installAgentSessionAccessors(AgentSession.prototype);
|
|
80
|
+
Object.assign(AgentSession.prototype, agentSessionToolHooksMethods, agentSessionEventsMethods, agentSessionStateMethods, agentSessionPromptMethods, agentSessionMessageQueueMethods, agentSessionModelsMethods, agentSessionCompactionMethods, agentSessionAutoCompactionMethods, agentSessionExtensionBindingsMethods, agentSessionToolRegistryMethods, agentSessionRetryMethods, agentSessionBashMethods, agentSessionTreeMethods, agentSessionExportMethods);
|
|
3208
81
|
//# sourceMappingURL=agent-session.js.map
|