@andorra-labs/code 0.1.11 → 0.1.13
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/README.md +8 -2
- package/THIRD_PARTY_NOTICES.md +15 -0
- package/dist/src/account-presentation.d.ts +1 -37
- package/dist/src/account-presentation.js +2 -42
- package/dist/src/activity.d.ts +0 -25
- package/dist/src/activity.js +1 -23
- package/dist/src/agent-definitions.d.ts +0 -26
- package/dist/src/agent-definitions.js +0 -43
- package/dist/src/agent-execution.d.ts +0 -2
- package/dist/src/agent-execution.js +59 -414
- package/dist/src/agent-mcp-catalog.d.ts +0 -8
- package/dist/src/agent-mcp-catalog.js +0 -2
- package/dist/src/agent-mcp.d.ts +0 -56
- package/dist/src/agent-mcp.js +14 -153
- package/dist/src/agent-modifiers.d.ts +0 -1
- package/dist/src/agent-modifiers.js +25 -68
- package/dist/src/analytics.d.ts +0 -66
- package/dist/src/analytics.js +0 -45
- package/dist/src/anthropic-console-auth.d.ts +0 -24
- package/dist/src/anthropic-console-auth.js +0 -37
- package/dist/src/anthropic-credentials.d.ts +0 -25
- package/dist/src/anthropic-credentials.js +0 -28
- package/dist/src/app-server/protocol.d.ts +19 -244
- package/dist/src/app-server/protocol.js +1 -132
- package/dist/src/app-server/reasoning.d.ts +0 -31
- package/dist/src/app-server/reasoning.js +0 -54
- package/dist/src/app-server/terminal.d.ts +0 -36
- package/dist/src/app-server/terminal.js +3 -39
- package/dist/src/app-server/workspace.d.ts +0 -167
- package/dist/src/app-server/workspace.js +4 -406
- package/dist/src/app-server.d.ts +33 -918
- package/dist/src/app-server.js +608 -2984
- package/dist/src/artifacts.d.ts +0 -10
- package/dist/src/artifacts.js +1 -11
- package/dist/src/attachments.d.ts +4 -98
- package/dist/src/attachments.js +10 -130
- package/dist/src/auth/AuthManager.d.ts +0 -93
- package/dist/src/auth/AuthManager.js +3 -165
- package/dist/src/auth/callback-page.d.ts +0 -1
- package/dist/src/auth/callback-page.js +0 -4
- package/dist/src/auth/callback.d.ts +0 -25
- package/dist/src/auth/callback.js +1 -29
- package/dist/src/auth/deployment.d.ts +0 -16
- package/dist/src/auth/deployment.js +0 -16
- package/dist/src/auth/index.d.ts +0 -11
- package/dist/src/auth/index.js +0 -11
- package/dist/src/auth/lock.d.ts +0 -1
- package/dist/src/auth/lock.js +0 -1
- package/dist/src/auth/store.d.ts +7 -108
- package/dist/src/auth/store.js +21 -129
- package/dist/src/auth/types.d.ts +0 -8
- package/dist/src/auth-commands.d.ts +0 -5
- package/dist/src/auth-commands.js +0 -1
- package/dist/src/automation-runner.d.ts +0 -9
- package/dist/src/automation-runner.js +0 -11
- package/dist/src/automation-service.d.ts +0 -10
- package/dist/src/automation-service.js +3 -17
- package/dist/src/automation-tool.js +0 -5
- package/dist/src/automation-worker-shutdown.d.ts +0 -1
- package/dist/src/automation-worker-shutdown.js +0 -3
- package/dist/src/automations.d.ts +23 -2
- package/dist/src/automations.js +91 -12
- package/dist/src/background-tasks.d.ts +0 -23
- package/dist/src/background-tasks.js +0 -11
- package/dist/src/boot-trace.d.ts +0 -13
- package/dist/src/boot-trace.js +1 -14
- package/dist/src/browser-activity.js +0 -2
- package/dist/src/browser-bridge.d.ts +0 -2
- package/dist/src/browser-bridge.js +0 -27
- package/dist/src/browser-captcha-tool.d.ts +0 -13
- package/dist/src/browser-captcha-tool.js +3 -35
- package/dist/src/browser-extensions-tool.d.ts +24 -0
- package/dist/src/browser-extensions-tool.js +137 -0
- package/dist/src/browser-extensions.d.ts +127 -0
- package/dist/src/browser-extensions.js +729 -0
- package/dist/src/browser-observation.d.ts +0 -15
- package/dist/src/browser-observation.js +1 -22
- package/dist/src/browser-panel-tool.d.ts +10 -25
- package/dist/src/browser-panel-tool.js +64 -60
- package/dist/src/browser-runner.d.ts +0 -1
- package/dist/src/browser-runner.js +7 -46
- package/dist/src/browser-server.d.ts +0 -6
- package/dist/src/browser-server.js +6 -229
- package/dist/src/browser-session.d.ts +0 -25
- package/dist/src/browser-session.js +1 -71
- package/dist/src/browser-stealth.d.ts +0 -12
- package/dist/src/browser-stealth.js +0 -36
- package/dist/src/browser-ui/app.js +7 -174
- package/dist/src/browser-ui/style.css +0 -68
- package/dist/src/browser-ui/tokens.css +11 -93
- package/dist/src/browser-view.d.ts +52 -290
- package/dist/src/browser-view.js +354 -567
- package/dist/src/capabilities.d.ts +0 -8
- package/dist/src/capabilities.js +0 -29
- package/dist/src/capsolver.d.ts +0 -13
- package/dist/src/capsolver.js +0 -15
- package/dist/src/clarification-ui.d.ts +0 -7
- package/dist/src/clarification-ui.js +0 -8
- package/dist/src/claude-executable.d.ts +0 -1
- package/dist/src/claude-executable.js +1 -2
- package/dist/src/claude-provider.d.ts +6 -19
- package/dist/src/claude-provider.js +166 -61
- package/dist/src/cli-executable.d.ts +0 -16
- package/dist/src/cli-executable.js +0 -7
- package/dist/src/cli-process.d.ts +0 -26
- package/dist/src/cli-process.js +0 -18
- package/dist/src/cli-sign-in.d.ts +0 -20
- package/dist/src/cli-sign-in.js +1 -17
- package/dist/src/cli.d.ts +3 -56
- package/dist/src/cli.js +193 -702
- package/dist/src/code-intelligence/CodeIntelligenceManager.d.ts +4 -59
- package/dist/src/code-intelligence/CodeIntelligenceManager.js +27 -100
- package/dist/src/code-intelligence/ContextLedger.d.ts +0 -4
- package/dist/src/code-intelligence/ContextLedger.js +0 -10
- package/dist/src/code-intelligence/ContextRouter.d.ts +0 -6
- package/dist/src/code-intelligence/ContextRouter.js +0 -8
- package/dist/src/code-intelligence/codegraph/CodeGraphProjectSession.d.ts +0 -2
- package/dist/src/code-intelligence/codegraph/CodeGraphProjectSession.js +5 -12
- package/dist/src/code-intelligence/codegraph/CodeGraphProvider.d.ts +0 -6
- package/dist/src/code-intelligence/codegraph/CodeGraphProvider.js +0 -6
- package/dist/src/code-intelligence/codegraph/CodeGraphSyncBarrier.d.ts +0 -5
- package/dist/src/code-intelligence/codegraph/CodeGraphSyncBarrier.js +1 -17
- package/dist/src/code-intelligence/codegraph/repoExploreTool.d.ts +0 -5
- package/dist/src/code-intelligence/codegraph/repoExploreTool.js +0 -5
- package/dist/src/code-intelligence/repository.d.ts +0 -9
- package/dist/src/code-intelligence/repository.js +1 -11
- package/dist/src/code-intelligence/types.d.ts +0 -8
- package/dist/src/codex-auth.d.ts +0 -44
- package/dist/src/codex-auth.js +0 -45
- package/dist/src/codex-browser-auth.d.ts +0 -13
- package/dist/src/codex-browser-auth.js +3 -20
- package/dist/src/codex-errors.js +0 -2
- package/dist/src/codex-executable.d.ts +0 -2
- package/dist/src/codex-executable.js +1 -7
- package/dist/src/codex-provider.d.ts +0 -13
- package/dist/src/codex-provider.js +1 -26
- package/dist/src/codex-rpc.d.ts +0 -10
- package/dist/src/codex-rpc.js +0 -12
- package/dist/src/coding-tools.d.ts +6 -27
- package/dist/src/coding-tools.js +193 -205
- package/dist/src/command-metrics.d.ts +0 -4
- package/dist/src/command-output-tap.d.ts +0 -11
- package/dist/src/command-output-tap.js +0 -3
- package/dist/src/command-screens.d.ts +24 -0
- package/dist/src/command-screens.js +132 -100
- package/dist/src/commands.d.ts +6 -63
- package/dist/src/commands.js +20 -100
- package/dist/src/completion-gates.d.ts +0 -47
- package/dist/src/completion-gates.js +0 -14
- package/dist/src/completion.d.ts +2 -58
- package/dist/src/completion.js +90 -186
- package/dist/src/config.d.ts +12 -116
- package/dist/src/config.js +41 -171
- package/dist/src/context-budget.d.ts +0 -22
- package/dist/src/context-budget.js +0 -44
- package/dist/src/context-compaction.d.ts +29 -6
- package/dist/src/context-compaction.js +94 -25
- package/dist/src/context-selection.d.ts +0 -24
- package/dist/src/context-selection.js +0 -34
- package/dist/src/dashboard-view.d.ts +0 -2
- package/dist/src/dashboard-view.js +0 -35
- package/dist/src/dashboard.d.ts +0 -2
- package/dist/src/dashboard.js +0 -9
- package/dist/src/deadline.d.ts +0 -45
- package/dist/src/deadline.js +0 -54
- package/dist/src/decision/ContinuationAdapter.d.ts +0 -5
- package/dist/src/decision/ContinuationAdapter.js +0 -5
- package/dist/src/decision/DecisionEngine.d.ts +0 -4
- package/dist/src/decision/DecisionManager.d.ts +0 -1
- package/dist/src/decision/DecisionManager.js +2 -7
- package/dist/src/decision/DecisionPolicy.d.ts +0 -1
- package/dist/src/decision/DecisionPolicy.js +0 -1
- package/dist/src/decision/FactContinuations.d.ts +11 -43
- package/dist/src/decision/FactContinuations.js +126 -95
- package/dist/src/decision/FactServiceGate.d.ts +0 -1
- package/dist/src/decision/FactServiceGate.js +0 -4
- package/dist/src/decision/PreparedSteps.d.ts +0 -15
- package/dist/src/decision/PreparedSteps.js +1 -11
- package/dist/src/decision/applyToolMenu.d.ts +0 -1
- package/dist/src/decision/applyToolMenu.js +1 -5
- package/dist/src/decision/checks.d.ts +15 -28
- package/dist/src/decision/checks.js +118 -49
- package/dist/src/decision/facts.d.ts +0 -16
- package/dist/src/decision/facts.js +0 -30
- package/dist/src/decision/guidancePolicy.js +0 -1
- package/dist/src/decision/hostedPolicy.d.ts +0 -6
- package/dist/src/decision/hostedPolicy.js +0 -7
- package/dist/src/decision/hostedSkills.d.ts +0 -19
- package/dist/src/decision/hostedSkills.js +0 -19
- package/dist/src/decision/optimizationPolicy.d.ts +0 -3
- package/dist/src/decision/optimizationPolicy.js +1 -4
- package/dist/src/decision/providers/AndorraDecisionProvider.d.ts +0 -7
- package/dist/src/decision/providers/AndorraDecisionProvider.js +4 -27
- package/dist/src/decision/providers/HttpDecisionProvider.d.ts +0 -2
- package/dist/src/decision/providers/HttpDecisionProvider.js +0 -6
- package/dist/src/decision/routeTools.d.ts +0 -8
- package/dist/src/decision/routeTools.js +1 -8
- package/dist/src/decision/toolFamilies.d.ts +0 -1
- package/dist/src/decision/toolFamilies.js +0 -1
- package/dist/src/decision/toolMenu.d.ts +0 -3
- package/dist/src/decision/toolMenu.js +0 -4
- package/dist/src/decision/types.d.ts +0 -6
- package/dist/src/default-graph.d.ts +0 -9
- package/dist/src/default-graph.js +0 -9
- package/dist/src/delegation-changes.d.ts +0 -56
- package/dist/src/delegation-changes.js +15 -124
- package/dist/src/diff-preview.d.ts +1 -1
- package/dist/src/diff-preview.js +4 -12
- package/dist/src/duration.d.ts +0 -50
- package/dist/src/duration.js +0 -50
- package/dist/src/efficiency.d.ts +0 -39
- package/dist/src/efficiency.js +0 -16
- package/dist/src/engine/protocol.d.ts +0 -2
- package/dist/src/engine/protocol.js +0 -2
- package/dist/src/engine-streams.d.ts +13 -0
- package/dist/src/engine-streams.js +16 -0
- package/dist/src/extensions.d.ts +3 -2
- package/dist/src/extensions.js +76 -37
- package/dist/src/favicons.d.ts +0 -26
- package/dist/src/favicons.js +0 -34
- package/dist/src/file-diff.d.ts +2 -58
- package/dist/src/file-diff.js +0 -32
- package/dist/src/file-read-key.d.ts +1 -0
- package/dist/src/file-read-key.js +5 -0
- package/dist/src/file-read-state.d.ts +0 -1
- package/dist/src/file-read-state.js +0 -4
- package/dist/src/firefox-cookies.d.ts +0 -34
- package/dist/src/firefox-cookies.js +1 -55
- package/dist/src/git-identity-audit.d.ts +27 -0
- package/dist/src/git-identity-audit.js +286 -0
- package/dist/src/git-identity-guard.d.ts +4 -0
- package/dist/src/git-identity-guard.js +998 -0
- package/dist/src/git-identity-hold.d.ts +12 -0
- package/dist/src/git-identity-hold.js +81 -0
- package/dist/src/git-summary.d.ts +0 -58
- package/dist/src/git-summary.js +2 -212
- package/dist/src/goal-completion-verification.d.ts +2 -2
- package/dist/src/goal-completion-verification.js +3 -6
- package/dist/src/graph-account.d.ts +0 -21
- package/dist/src/graph-account.js +0 -17
- package/dist/src/graph-editor-session.d.ts +0 -1
- package/dist/src/graph-editor-session.js +1 -3
- package/dist/src/graph-health.d.ts +7 -49
- package/dist/src/graph-health.js +35 -46
- package/dist/src/graph-manager-chat.d.ts +27 -128
- package/dist/src/graph-manager-chat.js +36 -166
- package/dist/src/graph-provider-portability.d.ts +1 -21
- package/dist/src/graph-provider-portability.js +6 -45
- package/dist/src/graph-quota.d.ts +0 -33
- package/dist/src/graph-quota.js +1 -44
- package/dist/src/graph-runner.d.ts +0 -1
- package/dist/src/graph-runner.js +47 -387
- package/dist/src/graph-selection.d.ts +0 -14
- package/dist/src/graph-selection.js +0 -14
- package/dist/src/graph-server.d.ts +3 -11
- package/dist/src/graph-server.js +70 -111
- package/dist/src/graph-studio-features.d.ts +0 -5
- package/dist/src/graph-studio-features.js +2 -42
- package/dist/src/graph-sync.d.ts +0 -78
- package/dist/src/graph-sync.js +5 -201
- package/dist/src/graph-tool.d.ts +0 -18
- package/dist/src/graph-tool.js +0 -27
- package/dist/src/graph-ui/app.js +229 -498
- package/dist/src/graph-ui/compat.js +0 -7
- package/dist/src/graph-ui/controls.css +47 -43
- package/dist/src/graph-ui/controls.js +0 -88
- package/dist/src/graph-ui/drafts.js +0 -12
- package/dist/src/graph-ui/edge-router.js +0 -62
- package/dist/src/graph-ui/embed.js +0 -59
- package/dist/src/graph-ui/icons.js +2 -7
- package/dist/src/graph-ui/index.html +2 -2
- package/dist/src/graph-ui/library.css +0 -5
- package/dist/src/graph-ui/manager-markdown.js +0 -11
- package/dist/src/graph-ui/manager-state.js +110 -49
- package/dist/src/graph-ui/manager.css +2 -20
- package/dist/src/graph-ui/manager.js +251 -166
- package/dist/src/graph-ui/model-picker.js +250 -0
- package/dist/src/graph-ui/provider-glyphs/alibaba-cloud.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/anthropic.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/aws-bedrock.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/claude.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/deepseek.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/fireworks.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/kimi.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/minimax.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/openai.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/opencode.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/openrouter.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/xai.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/xiaomi-mimo.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/zai.png +0 -0
- package/dist/src/graph-ui/sidebar.js +2 -3
- package/dist/src/graph-ui/skill-picker.js +373 -39
- package/dist/src/graph-ui/studio-canvas.js +3 -38
- package/dist/src/graph-ui/studio.css +0 -18
- package/dist/src/graph-ui/studio.js +3 -71
- package/dist/src/graph-ui/style.css +11 -134
- package/dist/src/graph-ui/theme.js +1 -26
- package/dist/src/graph-ui/tokens.css +15 -114
- package/dist/src/graphs.d.ts +7 -156
- package/dist/src/graphs.js +72 -273
- package/dist/src/grep-regex-worker.js +0 -2
- package/dist/src/grep-regex.d.ts +1 -5
- package/dist/src/grep-regex.js +6 -8
- package/dist/src/grok-provider.d.ts +0 -17
- package/dist/src/grok-provider.js +1 -26
- package/dist/src/handoffs.d.ts +0 -11
- package/dist/src/handoffs.js +0 -13
- package/dist/src/hardened-runtime.d.ts +0 -10
- package/dist/src/hardened-runtime.js +8 -46
- package/dist/src/harness-home.d.ts +21 -0
- package/dist/src/harness-home.js +87 -0
- package/dist/src/host-process-guard.d.ts +0 -50
- package/dist/src/host-process-guard.js +0 -641
- package/dist/src/limits.d.ts +0 -64
- package/dist/src/limits.js +0 -62
- package/dist/src/managed-sign-in.d.ts +0 -12
- package/dist/src/managed-sign-in.js +0 -16
- package/dist/src/markdown.d.ts +0 -28
- package/dist/src/markdown.js +1 -175
- package/dist/src/mcp.d.ts +21 -82
- package/dist/src/mcp.js +228 -237
- package/dist/src/membership-errors.d.ts +0 -14
- package/dist/src/membership-errors.js +0 -13
- package/dist/src/membership.d.ts +2 -60
- package/dist/src/membership.js +0 -85
- package/dist/src/memory/LocalToolMemory.d.ts +0 -1
- package/dist/src/memory/LocalToolMemory.js +2 -7
- package/dist/src/memory/MemoryDistiller.js +0 -15
- package/dist/src/memory/MemoryManager.d.ts +0 -3
- package/dist/src/memory/MemoryManager.js +6 -18
- package/dist/src/memory/MemoryPolicy.d.ts +0 -2
- package/dist/src/memory/MemoryPolicy.js +0 -2
- package/dist/src/memory/MemoryProvider.d.ts +0 -6
- package/dist/src/memory/MemoryRetriever.js +0 -7
- package/dist/src/memory/PermissionMemoryProvider.d.ts +0 -1
- package/dist/src/memory/PermissionMemoryProvider.js +0 -1
- package/dist/src/memory/ProjectMemory.d.ts +42 -0
- package/dist/src/memory/ProjectMemory.js +285 -0
- package/dist/src/memory/ToolFailureLessons.d.ts +0 -3
- package/dist/src/memory/ToolFailureLessons.js +0 -6
- package/dist/src/memory/index.d.ts +1 -0
- package/dist/src/memory/index.js +1 -0
- package/dist/src/memory/providers/NoOpMemoryProvider.d.ts +0 -1
- package/dist/src/memory/providers/NoOpMemoryProvider.js +0 -1
- package/dist/src/memory/redaction.d.ts +0 -5
- package/dist/src/memory/redaction.js +0 -11
- package/dist/src/memory/repository.d.ts +0 -6
- package/dist/src/memory/repository.js +2 -12
- package/dist/src/memory/types.d.ts +0 -1
- package/dist/src/model-health-cache.d.ts +0 -38
- package/dist/src/model-health-cache.js +1 -49
- package/dist/src/model-metadata.d.ts +0 -18
- package/dist/src/model-metadata.js +2 -42
- package/dist/src/model-override.d.ts +0 -36
- package/dist/src/model-override.js +0 -43
- package/dist/src/model-tiers.d.ts +0 -13
- package/dist/src/model-tiers.js +0 -23
- package/dist/src/opencode-catalog.d.ts +0 -2
- package/dist/src/opencode-catalog.js +0 -11
- package/dist/src/opencode-cli-provider.d.ts +0 -35
- package/dist/src/opencode-cli-provider.js +1 -44
- package/dist/src/opencode-provider.d.ts +0 -2
- package/dist/src/opencode-provider.js +6 -22
- package/dist/src/package-name.d.ts +1 -0
- package/dist/src/package-name.js +1 -0
- package/dist/src/paged-transcript.d.ts +0 -11
- package/dist/src/paged-transcript.js +2 -20
- package/dist/src/palette.d.ts +0 -63
- package/dist/src/palette.js +0 -63
- package/dist/src/permissions.d.ts +0 -15
- package/dist/src/permissions.js +0 -17
- package/dist/src/powershell-pool.d.ts +0 -9
- package/dist/src/powershell-pool.js +3 -26
- package/dist/src/process-warnings.d.ts +4 -0
- package/dist/src/process-warnings.js +103 -0
- package/dist/src/profile.d.ts +0 -43
- package/dist/src/profile.js +0 -43
- package/dist/src/project-reservation.d.ts +11 -0
- package/dist/src/project-reservation.js +143 -0
- package/dist/src/provider-connection.d.ts +0 -18
- package/dist/src/provider-connection.js +0 -39
- package/dist/src/provider-engine.d.ts +0 -21
- package/dist/src/provider-engine.js +3 -98
- package/dist/src/provider-import.d.ts +0 -49
- package/dist/src/provider-import.js +0 -60
- package/dist/src/provider-keys.d.ts +1 -36
- package/dist/src/provider-keys.js +5 -48
- package/dist/src/provider-settings.d.ts +0 -2
- package/dist/src/provider-settings.js +0 -32
- package/dist/src/providers.d.ts +0 -217
- package/dist/src/providers.js +0 -315
- package/dist/src/pull-requests.d.ts +0 -173
- package/dist/src/pull-requests.js +5 -195
- package/dist/src/qa/browser/PlaywrightRunner.d.ts +0 -7
- package/dist/src/qa/browser/PlaywrightRunner.js +2 -16
- package/dist/src/qa/command-policy.d.ts +0 -23
- package/dist/src/qa/command-policy.js +0 -30
- package/dist/src/qa/guidance.d.ts +0 -21
- package/dist/src/qa/guidance.js +0 -20
- package/dist/src/qa/profile/ProjectInspector.d.ts +0 -4
- package/dist/src/qa/profile/ProjectInspector.js +0 -6
- package/dist/src/qa/profile/QaConfigLoader.d.ts +0 -7
- package/dist/src/qa/profile/QaConfigLoader.js +0 -6
- package/dist/src/qa/profile/QaProfile.d.ts +0 -7
- package/dist/src/qa/profile/QaProfile.js +0 -7
- package/dist/src/qa/profile/yaml.d.ts +0 -9
- package/dist/src/qa/profile/yaml.js +0 -13
- package/dist/src/qa/qa-authorize.d.ts +0 -19
- package/dist/src/qa/qa-authorize.js +4 -11
- package/dist/src/qa/runtime/ProcessManager.d.ts +0 -31
- package/dist/src/qa/runtime/ProcessManager.js +4 -41
- package/dist/src/qa/runtime/PtyManager.d.ts +0 -4
- package/dist/src/qa/runtime/PtyManager.js +2 -7
- package/dist/src/qa/runtime/changes.d.ts +0 -11
- package/dist/src/qa/runtime/changes.js +1 -3
- package/dist/src/qa/tools.d.ts +0 -10
- package/dist/src/qa/tools.js +0 -12
- package/dist/src/qa/types.d.ts +0 -13
- package/dist/src/react-runtime.d.ts +2 -21
- package/dist/src/react-runtime.js +106 -418
- package/dist/src/read-document-doc.d.ts +0 -6
- package/dist/src/read-document-doc.js +0 -55
- package/dist/src/read-document-docx.d.ts +0 -16
- package/dist/src/read-document-docx.js +2 -69
- package/dist/src/read-document-text.d.ts +0 -17
- package/dist/src/read-document-text.js +0 -22
- package/dist/src/read-document-tool.d.ts +0 -31
- package/dist/src/read-document-tool.js +0 -30
- package/dist/src/read-document.d.ts +0 -49
- package/dist/src/read-document.js +1 -67
- package/dist/src/read-image.d.ts +0 -32
- package/dist/src/read-image.js +0 -33
- package/dist/src/remote/cert.d.ts +1 -19
- package/dist/src/remote/cert.js +2 -51
- package/dist/src/remote/client.d.ts +0 -70
- package/dist/src/remote/client.js +2 -117
- package/dist/src/remote/command.js +0 -17
- package/dist/src/remote/engine-pool.d.ts +0 -152
- package/dist/src/remote/engine-pool.js +17 -335
- package/dist/src/remote/errors.d.ts +0 -15
- package/dist/src/remote/errors.js +0 -7
- package/dist/src/remote/network.d.ts +0 -26
- package/dist/src/remote/network.js +1 -34
- package/dist/src/remote/pairing.d.ts +16 -51
- package/dist/src/remote/pairing.js +50 -57
- package/dist/src/remote/pem.d.ts +2 -0
- package/dist/src/remote/pem.js +7 -0
- package/dist/src/remote/roots.d.ts +0 -20
- package/dist/src/remote/roots.js +0 -8
- package/dist/src/remote/serve.d.ts +0 -47
- package/dist/src/remote/serve.js +0 -30
- package/dist/src/remote/server.d.ts +0 -14
- package/dist/src/remote/server.js +1 -79
- package/dist/src/remote/types.d.ts +1 -32
- package/dist/src/remote/types.js +0 -10
- package/dist/src/run-control.d.ts +0 -7
- package/dist/src/run-control.js +0 -7
- package/dist/src/run-progress.d.ts +0 -170
- package/dist/src/run-progress.js +0 -285
- package/dist/src/run-records.d.ts +0 -443
- package/dist/src/run-records.js +44 -678
- package/dist/src/run-temp.d.ts +12 -0
- package/dist/src/run-temp.js +50 -0
- package/dist/src/runtime.d.ts +11 -227
- package/dist/src/runtime.js +0 -127
- package/dist/src/sandbox-child.js +0 -1
- package/dist/src/save-lock.d.ts +0 -12
- package/dist/src/save-lock.js +0 -28
- package/dist/src/screen-selection.d.ts +0 -23
- package/dist/src/screen-selection.js +0 -22
- package/dist/src/secret-redaction.d.ts +0 -12
- package/dist/src/secret-redaction.js +0 -45
- package/dist/src/session-changes.d.ts +4 -80
- package/dist/src/session-changes.js +25 -130
- package/dist/src/session-goal.d.ts +129 -0
- package/dist/src/session-goal.js +230 -0
- package/dist/src/session-monitor.d.ts +1 -10
- package/dist/src/session-monitor.js +2 -39
- package/dist/src/session-reaper.d.ts +0 -15
- package/dist/src/session-reaper.js +0 -14
- package/dist/src/session-skills.d.ts +15 -44
- package/dist/src/session-skills.js +75 -60
- package/dist/src/session-summary.d.ts +0 -26
- package/dist/src/session-summary.js +0 -32
- package/dist/src/session-title.d.ts +0 -1
- package/dist/src/session-title.js +0 -2
- package/dist/src/sessions.d.ts +2 -120
- package/dist/src/sessions.js +9 -178
- package/dist/src/shell.d.ts +3 -20
- package/dist/src/shell.js +8 -72
- package/dist/src/side-panel.d.ts +5 -99
- package/dist/src/side-panel.js +76 -133
- package/dist/src/sign-in-detection.d.ts +43 -0
- package/dist/src/sign-in-detection.js +154 -0
- package/dist/src/sign-in-offer.d.ts +17 -0
- package/dist/src/sign-in-offer.js +103 -0
- package/dist/src/skill-commands.d.ts +0 -1
- package/dist/src/skill-commands.js +1 -4
- package/dist/src/skills/bundled/control-browser/SKILL.md +1 -1
- package/dist/src/skills/bundled/graph-manager/SKILL.md +22 -4
- package/dist/src/skills/bundled/provenance.json +2 -2
- package/dist/src/skills/invocable-skills.d.ts +0 -18
- package/dist/src/skills/invocable-skills.js +0 -17
- package/dist/src/skills/project-skills.d.ts +0 -1
- package/dist/src/skills/project-skills.js +0 -3
- package/dist/src/skills/prompt-skills.js +0 -14
- package/dist/src/skills/runtime-skills.d.ts +1 -8
- package/dist/src/skills/runtime-skills.js +8 -32
- package/dist/src/stall-recovery.d.ts +0 -25
- package/dist/src/stall-recovery.js +0 -38
- package/dist/src/stray-files.d.ts +5 -0
- package/dist/src/stray-files.js +65 -0
- package/dist/src/structured-step.d.ts +0 -22
- package/dist/src/structured-step.js +0 -22
- package/dist/src/subagent-run.d.ts +0 -163
- package/dist/src/subagent-run.js +10 -374
- package/dist/src/subagent-tree.d.ts +32 -0
- package/dist/src/subagent-tree.js +128 -0
- package/dist/src/telemetry/aggregate.d.ts +0 -37
- package/dist/src/telemetry/aggregate.js +0 -40
- package/dist/src/telemetry/capture-core.d.ts +0 -87
- package/dist/src/telemetry/capture-core.js +0 -67
- package/dist/src/telemetry/capture.d.ts +0 -1
- package/dist/src/telemetry/capture.js +0 -3
- package/dist/src/telemetry/classify.d.ts +0 -58
- package/dist/src/telemetry/classify.js +0 -60
- package/dist/src/telemetry/decision-capture.d.ts +0 -1
- package/dist/src/telemetry/emitter.d.ts +0 -30
- package/dist/src/telemetry/emitter.js +1 -62
- package/dist/src/telemetry/gate.d.ts +0 -29
- package/dist/src/telemetry/gate.js +0 -22
- package/dist/src/telemetry/identity.d.ts +0 -13
- package/dist/src/telemetry/identity.js +0 -29
- package/dist/src/telemetry/outbox.d.ts +0 -64
- package/dist/src/telemetry/outbox.js +1 -108
- package/dist/src/telemetry/schema.d.ts +1 -49
- package/dist/src/telemetry/schema.js +1 -82
- package/dist/src/telemetry/state.d.ts +0 -53
- package/dist/src/telemetry/state.js +0 -64
- package/dist/src/telemetry/surface.d.ts +0 -31
- package/dist/src/telemetry/surface.js +1 -39
- package/dist/src/telemetry/uploader.d.ts +0 -11
- package/dist/src/telemetry/uploader.js +0 -46
- package/dist/src/telemetry/uploads.d.ts +0 -11
- package/dist/src/telemetry/uploads.js +0 -11
- package/dist/src/telemetry/version.d.ts +0 -4
- package/dist/src/telemetry/version.js +0 -14
- package/dist/src/telemetry/workspace.d.ts +0 -7
- package/dist/src/telemetry/workspace.js +1 -22
- package/dist/src/terminal-ui.d.ts +15 -524
- package/dist/src/terminal-ui.js +80 -876
- package/dist/src/test-edit-guard.d.ts +74 -0
- package/dist/src/test-edit-guard.js +269 -0
- package/dist/src/text.d.ts +0 -1
- package/dist/src/text.js +0 -1
- package/dist/src/time-limit.d.ts +0 -36
- package/dist/src/time-limit.js +0 -37
- package/dist/src/timers.d.ts +0 -161
- package/dist/src/timers.js +0 -126
- package/dist/src/todos.d.ts +0 -1
- package/dist/src/todos.js +0 -3
- package/dist/src/token-rate.d.ts +0 -94
- package/dist/src/token-rate.js +0 -154
- package/dist/src/tool-activity.d.ts +0 -6
- package/dist/src/tool-activity.js +1 -8
- package/dist/src/tool-availability.d.ts +0 -13
- package/dist/src/tool-availability.js +1 -14
- package/dist/src/tool-call-clock.d.ts +1 -4
- package/dist/src/tool-call-clock.js +0 -13
- package/dist/src/tool-catalog.d.ts +0 -11
- package/dist/src/tool-catalog.js +0 -23
- package/dist/src/tool-dependencies.d.ts +0 -5
- package/dist/src/tool-dependencies.js +0 -4
- package/dist/src/tool-diff-stats.d.ts +0 -23
- package/dist/src/tool-diff-stats.js +0 -49
- package/dist/src/tool-errors.d.ts +9 -7
- package/dist/src/tool-errors.js +13 -6
- package/dist/src/tool-failure-tracker.d.ts +3 -11
- package/dist/src/tool-failure-tracker.js +19 -27
- package/dist/src/tool-names.d.ts +0 -16
- package/dist/src/tool-names.js +0 -12
- package/dist/src/tool-profile.d.ts +6 -0
- package/dist/src/tool-profile.js +23 -0
- package/dist/src/tool-result-filter.d.ts +0 -19
- package/dist/src/tool-result-filter.js +1 -66
- package/dist/src/tool-schema-compatibility.d.ts +1 -2
- package/dist/src/tool-schema-compatibility.js +2 -7
- package/dist/src/tools.d.ts +0 -4
- package/dist/src/tools.js +11 -114
- package/dist/src/trajectory.d.ts +0 -13
- package/dist/src/trajectory.js +23 -79
- package/dist/src/transcript.d.ts +1 -37
- package/dist/src/transcript.js +11 -61
- package/dist/src/types.d.ts +2 -167
- package/dist/src/untracked-file-removal.d.ts +3 -0
- package/dist/src/untracked-file-removal.js +105 -0
- package/dist/src/update-check.d.ts +0 -14
- package/dist/src/update-check.js +2 -16
- package/dist/src/update.d.ts +4 -29
- package/dist/src/update.js +20 -98
- package/dist/src/usage-analytics.d.ts +17 -17
- package/dist/src/usage-analytics.js +168 -209
- package/dist/src/web-search.d.ts +0 -23
- package/dist/src/web-search.js +1 -27
- package/dist/src/widgets.d.ts +0 -25
- package/dist/src/widgets.js +0 -24
- package/dist/src/workspace-facts.d.ts +0 -12
- package/dist/src/workspace-facts.js +1 -18
- package/dist/src/workspace-git-metadata.d.ts +4 -5
- package/dist/src/workspace-git-metadata.js +37 -9
- package/dist/src/workspace-instructions.d.ts +3 -15
- package/dist/src/workspace-instructions.js +7 -20
- package/package.json +2 -2
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import { goalRoute, routedOutcomes, runEndingOutcomes as goalRunEndingOutcomes } from './session-goal.js';
|
|
1
2
|
import { DecisionPolicy } from './decision/DecisionPolicy.js';
|
|
2
3
|
import { answerOnlyTask, hasAdaptiveAlternative } from './decision/optimizationPolicy.js';
|
|
3
4
|
import { resolveEfficiency } from './efficiency.js';
|
|
4
5
|
import { collectWorkspaceFacts } from './workspace-facts.js';
|
|
5
6
|
import { conversationContains, omittedContextNote, selectContext } from './context-selection.js';
|
|
7
|
+
import { MAPPED_INPUTS_HEADING } from './context-compaction.js';
|
|
6
8
|
import { orderSkillCatalog, selectToolCatalog } from './tool-catalog.js';
|
|
7
9
|
import { decideModelTier } from './model-tiers.js';
|
|
8
10
|
import { structuredText } from './code-intelligence/CodeIntelligenceManager.js';
|
|
@@ -23,24 +25,22 @@ import { createRunTelemetry, mergeRunTelemetry, recordAttempt, recordDecisionEve
|
|
|
23
25
|
import { bindUserWaits, createRuntimeBudget } from './deadline.js';
|
|
24
26
|
import { createAgentEngine } from './hardened-runtime.js';
|
|
25
27
|
import { completionTool } from './completion.js';
|
|
28
|
+
import { applyToolProfile } from './tool-profile.js';
|
|
26
29
|
import { DELIVERED_OUTCOME, GRAPH_MANAGER_GRAPH_ID, capabilitySubset, delegatesWriting, effectiveCapabilities, intakeCapabilities, isTestingNode, isWritingRole, laterAgentNodes, permitsBuiltInTool, testerOnEveryRoute } from './graphs.js';
|
|
27
30
|
import { DELEGATION_DIFF_LIMIT, LandingRestoreError, addChangeWorktree, assertDelegationGit, applyLanding, collectChange, prepareLanding, removeChangeWorktree, repositoryRoot, snapshotWorkspace } from './delegation-changes.js';
|
|
28
|
-
import { classifyWorkspaceWrites } from './tools.js';
|
|
29
31
|
import { stopQaProcessesUnder } from './qa/runtime/ProcessManager.js';
|
|
30
32
|
import { qaGuidance } from './qa/guidance.js';
|
|
31
33
|
import { disposePooledPowerShellUnder } from './powershell-pool.js';
|
|
32
34
|
import { validateValue } from './handoffs.js';
|
|
33
35
|
import { ArtifactStore } from './artifacts.js';
|
|
34
36
|
import { approveOperation, capabilityTools, gitReadTool } from './capabilities.js';
|
|
37
|
+
import { removeUntrackedFileTool } from './untracked-file-removal.js';
|
|
35
38
|
import { permissionMode, serializeApprovals, assertPlanMutationAllowed } from './permissions.js';
|
|
36
39
|
import { adaptLegacyCodingToolArguments, canonicalToolName, canonicalizeToolList } from './tool-names.js';
|
|
37
40
|
const exec = promisify(execFile);
|
|
38
|
-
/** How many times one accept_change prepares a landing when the working folder keeps changing under it. */
|
|
39
41
|
const LANDING_ATTEMPTS = 3;
|
|
40
|
-
/** Serialized size of the `restore_tools` schema the engine adds when a catalog omits anything. */
|
|
41
42
|
const RESTORE_TOOL_SCHEMA_CHARS = 420;
|
|
42
43
|
const MISSING_CONFIRMATION = 'Use ask_user and obtain a real answer confirming design considerations before completing.';
|
|
43
|
-
/** Joins the plan body and the decision prompt the way `ask_user` joins its notes; the desktop splits on the same marker. */
|
|
44
44
|
export const PLAN_DECISION_MARKER = '\n\nPlan awaiting your decision:\n';
|
|
45
45
|
const PLAN_APPROVE_CHOICE = 'Approve plan';
|
|
46
46
|
const PLAN_REJECT_CHOICE = 'Reject plan';
|
|
@@ -52,48 +52,19 @@ Use ask_user to clarify requirements and explicitly confirm or revise proposed d
|
|
|
52
52
|
Write user-facing questions, choices and progress in plain everyday language. Ask one concrete decision at a time. Explain what changes for the user, not file names, code symbols, terminal escape sequences, git jargon or internal terms. Keep detailed research, repository workflow rules and test plans in codebaseFindings and taskInstruction, not the question or answer choices. Use 1-3 short proposedDesign notes only for consequences the user needs to decide. Prefer 2-3 short choices (about 2-6 words each), put your recommendation first and label it (Recommended). Never repeat tool-result JSON in public messages. For example: "Should this update include both scrolling and the Enter-key change?" with "Fix scrolling only (Recommended)" and "Include both changes".
|
|
53
53
|
After inspection and user confirmation, return a compact structured handoff containing the originalTask, requirements, acceptanceCriteria, designConsiderations, codebaseFindings and taskInstruction. Include agreed decisions and unresolved facts, not conversation transcripts. Do not implement code during intake. Spawning is optional and bounded by policy.
|
|
54
54
|
When multiple completion outcomes are declared, use this node's prompt and the confirmed task to choose exactly one declared outcome string. The graph follows every connection for that outcome, which may start several downstream branches. Never return an array of outcomes or invent an undeclared outcome. Selecting a route does not replace the required plan, research, user confirmation or structured handoff.`;
|
|
55
|
-
/** Appended to the Orchestrator instructions only while delegation is active (a writing role and a routed `delivered` outcome). */
|
|
56
55
|
const DELEGATION_INSTRUCTIONS = `This Orchestrator can also deliver the work through writing subagents. Two paths end this node: complete with the outcome "completed" to hand the task instruction to the next node as usual, or complete with the outcome "delivered" once subagents implemented the work and you reviewed and accepted their changes. Choose from the task: hand off when the next node should implement, deliver when the work fits bounded subagent tasks you can review.
|
|
57
56
|
Clarify first on either path: publish the plan with update_todos, research, and obtain the user's confirmation with ask_user before any writing subagent starts; writing spawns are refused until then.
|
|
58
57
|
Delegate implementation to the writing roles with spawn_subagent, several in parallel when their tasks are independent. Each runs in its own Git worktree started from the working folder as it stands and may run commands and tests there. Give each one a bounded task carrying the confirmed requirements and acceptance criteria, and ask it to report the commands and tests it ran.
|
|
59
58
|
Each writing spawn returns a change record: an id (use it exactly as returned), the changed files, the diff (the full diff is behind read_artifact when truncated), the worktree path, and the tests report the subagent gave. Review every change: read the diff, read files inside the worktree with your read tools when the diff is not enough, and weigh the tests report; a failure report is grounds for a fix.
|
|
60
59
|
Decide every change: accept_change with its id lands it in the working folder as uncommitted edits; discard_change drops it. A new subagent starts from the working folder, so it sees landed work only, never a change still waiting for your decision. To build on a change, accept it first and then spawn the follow-up. When work is wrong or incomplete, discard it and spawn a redo whose task carries your review findings, then review the redo. A conflict lands nothing and names the files: the change no longer fits the working folder and accepting it again conflicts again, so discard it, spawn a redo (it starts from the folder as it now stands) and accept the redo.
|
|
61
|
-
Complete with "delivered" only when no subagent is still running, at least one change landed, and every change is accepted or discarded. Never write code or run commands yourself: you have no write or shell tools, and the change tools take only an id.`;
|
|
62
|
-
/**
|
|
63
|
-
* Appended to a delegating Orchestrator's instructions when it continues a resumed conversation:
|
|
64
|
-
* the change registry is per visit and is not restored.
|
|
65
|
-
*/
|
|
60
|
+
Complete with "delivered" only when no subagent is still running, at least one change landed, and every change is accepted or discarded. Never write code or run commands yourself: you have no write or shell tools, and the change tools take only an id. The one exception is remove_untracked_file, for a stray untracked file left by mistake (such as one named nul or after a sentence); remove it yourself instead of asking the user to.`;
|
|
66
61
|
const RESUMED_DELEGATION_INSTRUCTIONS = `This run was resumed. Changes from before the resume are no longer tracked: their ids are unknown to accept_change and discard_change, and their worktrees are gone. Work that was already landed stays in the working folder. Spawn again for anything that was still undecided. Completing as "delivered" needs at least one change accepted after the resume; otherwise complete as "completed".`;
|
|
67
|
-
/**
|
|
68
|
-
* The exemption a retry attempt needs from the rule above.
|
|
69
|
-
*
|
|
70
|
-
* A fresh attempt is a new invocation, so the shared instructions tell it to obtain a user
|
|
71
|
-
* response — which is exactly what a retry must not do again. The user's answer really was
|
|
72
|
-
* obtained, by this node, and is carried into the retry's task text, so the requirement is already
|
|
73
|
-
* satisfied; appending this keeps a compliant model from re-asking and turning a promised
|
|
74
|
-
* single-question retry into a second interview.
|
|
75
|
-
*/
|
|
76
62
|
const RETAINED_CLARIFICATION_INSTRUCTION = 'This attempt retains a previous clarification: the user already answered this intake and their confirmed decisions are included in the task text. That answer satisfies the clarification requirement, so do not ask those questions again. Ask only if a genuinely new decision is required to hand off.';
|
|
77
|
-
/**
|
|
78
|
-
* Narrow the supplied limits by whatever this node configures.
|
|
79
|
-
*
|
|
80
|
-
* A node bound only ever tightens the run's own bound: `Math.min` against an absent supplied
|
|
81
|
-
* value would yield NaN, which reaches the executor as "Invalid limit", so an unlimited
|
|
82
|
-
* supplied bound leaves the node's explicit value in force. The key set comes from
|
|
83
|
-
* {@link LIMIT_KEYS} rather than the defaults, because the unlimited-by-default keys are
|
|
84
|
-
* absent from the defaults and testing those would silently drop a configured node bound.
|
|
85
|
-
* @param node - the graph node whose limits narrow the run.
|
|
86
|
-
* @param supplied - limits already in force for this run.
|
|
87
|
-
* @returns the effective limits for the node attempt.
|
|
88
|
-
*/
|
|
89
63
|
function mergeLimits(node, supplied = {}) {
|
|
90
64
|
const limits = resolveLimits(supplied);
|
|
91
65
|
const configured = { ...node.limits, ...(node.maxIterations !== undefined ? { maxIterations: Math.min(node.maxIterations, node.limits?.maxIterations ?? node.maxIterations) } : {}) };
|
|
92
66
|
for (const key of LIMIT_KEYS) {
|
|
93
67
|
const value = configured[key];
|
|
94
|
-
// A node's `0` alias means it adds no bound of its own. Min-ing it in would compute zero,
|
|
95
|
-
// which the budget reads as unlimited, so this node would silently discard an enclosing
|
|
96
|
-
// bound instead of leaving it in force.
|
|
97
68
|
if (isUnlimitedAlias(key, value))
|
|
98
69
|
continue;
|
|
99
70
|
if (value === undefined)
|
|
@@ -126,7 +97,6 @@ async function resolveBeforeAbort(resolve, signal) {
|
|
|
126
97
|
signal.removeEventListener('abort', abort);
|
|
127
98
|
}
|
|
128
99
|
}
|
|
129
|
-
/** Retry only read-only setup; a paused run must not wait for a stuck service. */
|
|
130
100
|
async function retryReadOnly(context, operation) {
|
|
131
101
|
for (;;) {
|
|
132
102
|
await context.runControl?.wait(context.signal);
|
|
@@ -141,13 +111,10 @@ async function retryReadOnly(context, operation) {
|
|
|
141
111
|
catch (error) {
|
|
142
112
|
if (context.signal.aborted || !pauseSignal?.aborted)
|
|
143
113
|
throw error;
|
|
144
|
-
// A fast resume may have replaced the controller already; inspect the
|
|
145
|
-
// captured signal rather than isPaused so that this attempt still retries.
|
|
146
114
|
await context.runControl.wait(context.signal);
|
|
147
115
|
}
|
|
148
116
|
}
|
|
149
117
|
}
|
|
150
|
-
/** Configures one shared executor; internal delegation never receives the scheduler or edges. */
|
|
151
118
|
export async function executeAgentNode(node, options) {
|
|
152
119
|
if (node.maxSubagents !== undefined && (!Number.isSafeInteger(node.maxSubagents) || node.maxSubagents < 0 || node.maxSubagents > 100))
|
|
153
120
|
throw new Error('maxSubagents must be an integer from 0 to 100');
|
|
@@ -160,11 +127,6 @@ export async function executeAgentNode(node, options) {
|
|
|
160
127
|
let checkpoint;
|
|
161
128
|
if (publishCheckpoint)
|
|
162
129
|
options = { ...options, onConversationCheckpoint: async (messages, state, conversation) => {
|
|
163
|
-
// The conversation is captured for the publication that follows the node — that one carries
|
|
164
|
-
// the outer invocation's allowance — and forwarded to the durable sink at every boundary.
|
|
165
|
-
// Forwarding is what makes the boundary durable: a node that continues after a mutating tool
|
|
166
|
-
// call must have that conversation on disk before the next model turn, or a process killed in
|
|
167
|
-
// that window resumes the node from a conversation that predates the call and runs it again.
|
|
168
130
|
checkpoint = { messages, state, conversation };
|
|
169
131
|
await publishCheckpoint(messages, state, conversation);
|
|
170
132
|
} };
|
|
@@ -174,21 +136,12 @@ export async function executeAgentNode(node, options) {
|
|
|
174
136
|
return () => { resume(); resumeParent?.(); };
|
|
175
137
|
};
|
|
176
138
|
const signal = AbortSignal.any([nodeBudget.signal, controller.signal]);
|
|
177
|
-
// Bind both prompts this node drives to its own clock. Wrapping only `approve` left the
|
|
178
|
-
// clearer case — an Orchestrator's `ask_user` — free to expire this node budget while the
|
|
179
|
-
// user was still answering, so their thinking time was charged to the run after all.
|
|
180
139
|
const bounded = bindUserWaits(options.context, nodeBudget, signal);
|
|
181
|
-
// Direct embedders may omit runId; observations and the returned run still
|
|
182
|
-
// need the same identity. Leave the off-mode path untouched.
|
|
183
140
|
if (options.decisionManager?.enabled && !options.runId)
|
|
184
141
|
options = { ...options, runId: randomUUID() };
|
|
185
142
|
const store = options.artifactStore ?? new ArtifactStore(options.runId ?? randomUUID());
|
|
186
143
|
const orchestrator = node.agentRole === 'orchestrator';
|
|
187
|
-
// Delegation is offered only when the graph routes `delivered`; otherwise a writing role is refused
|
|
188
|
-
// at spawn exactly as before, and nothing below changes behavior.
|
|
189
144
|
const delegationActive = orchestrator && delegatesWriting(node) && !!options.graph?.edges.some(edge => edge.source === node.id && edge.outcome === DELIVERED_OUTCOME);
|
|
190
|
-
// A resumed conversation is continued under the system message of its checkpoint, so the note
|
|
191
|
-
// goes there, once: the instructions built below for a fresh conversation are not sent.
|
|
192
145
|
if (delegationActive && options.resumeMessages?.[0]?.role === 'system' && !options.resumeMessages[0].content.includes(RESUMED_DELEGATION_INSTRUCTIONS)) {
|
|
193
146
|
const [system, ...rest] = options.resumeMessages;
|
|
194
147
|
options = { ...options, resumeMessages: [{ ...system, content: `${system.content}\n\n${RESUMED_DELEGATION_INSTRUCTIONS}` }, ...rest] };
|
|
@@ -203,30 +156,16 @@ export async function executeAgentNode(node, options) {
|
|
|
203
156
|
const maxTotal = Math.min(policy.maxTotal ?? 8, node.maxSubagents ?? Infinity);
|
|
204
157
|
const approve = serializeApprovals((name, args, approvalSignal) => bounded.approve(name, args, approvalSignal), () => permissionMode(bounded));
|
|
205
158
|
let active = 0, total = 0;
|
|
206
|
-
/** Changes of this visit's writing subagents, by change id. */
|
|
207
159
|
const changes = new Map();
|
|
208
|
-
/** Worktrees holding a pending change: the Orchestrator reads inside them without an outside-workspace prompt. */
|
|
209
160
|
const delegationRoots = [];
|
|
210
|
-
/** Every delegated worktree still on disk, whether or not a change holds it; all are removed when the node ends. */
|
|
211
161
|
const liveWorktrees = new Set();
|
|
212
|
-
/**
|
|
213
|
-
* Stops the processes a writing child left running inside its delegated worktree. There are two
|
|
214
|
-
* kinds, each kept by its own registry: a background job started with AsyncProcess, which
|
|
215
|
-
* outlives the tool call and the child, and the interpreter PowerShellFast reuses, which stays
|
|
216
|
-
* alive for its idle time after a command. Nothing can stop either afterwards (the Orchestrator
|
|
217
|
-
* has no shell), so they end with their child, and again before the worktree is removed: a
|
|
218
|
-
* job's listeners would outlive the folder, and on Windows a process whose current directory is
|
|
219
|
-
* a folder keeps the folder from being deleted. Both stops wait until the processes are gone.
|
|
220
|
-
*/
|
|
221
162
|
const stopWorktreeJobs = async (worktree) => {
|
|
222
|
-
// The tools key a process by the real path of the child's workspace, which can be spelled differently.
|
|
223
163
|
const root = await realpath(worktree).catch(() => undefined);
|
|
224
164
|
for (const folder of root !== undefined && root !== worktree ? [worktree, root] : [worktree]) {
|
|
225
165
|
await stopQaProcessesUnder(folder);
|
|
226
166
|
await disposePooledPowerShellUnder(folder);
|
|
227
167
|
}
|
|
228
168
|
};
|
|
229
|
-
/** Removes a delegated worktree and forgets it as a trusted read root. Best effort, like the removal itself. */
|
|
230
169
|
const dropWorktree = async (worktree) => {
|
|
231
170
|
liveWorktrees.delete(worktree);
|
|
232
171
|
await stopWorktreeJobs(worktree);
|
|
@@ -236,12 +175,6 @@ export async function executeAgentNode(node, options) {
|
|
|
236
175
|
delegationRoots.splice(index, 1);
|
|
237
176
|
await removeChangeWorktree(options.context.workspace, worktree);
|
|
238
177
|
};
|
|
239
|
-
/**
|
|
240
|
-
* Node-end cleanup, on every exit: an undecided change is discarded and announced, and every
|
|
241
|
-
* delegated worktree goes, including one a cancelled child was still working in. Accepted changes
|
|
242
|
-
* are already in the working folder and stay there. Also runs before a retry attempt, which
|
|
243
|
-
* starts a conversation that never saw the undecided changes. Returns the changes it discarded.
|
|
244
|
-
*/
|
|
245
178
|
const releaseChanges = async () => {
|
|
246
179
|
const discarded = [];
|
|
247
180
|
for (const change of changes.values()) {
|
|
@@ -256,9 +189,6 @@ export async function executeAgentNode(node, options) {
|
|
|
256
189
|
await emit('subagent.change', { subagentId: change.subagentId, changeId: change.id, state: 'discarded', files: change.files.map(file => file.path) });
|
|
257
190
|
return discarded;
|
|
258
191
|
};
|
|
259
|
-
// Delegated worktree setup is approved once per node visit: the first writing spawn's grant covers
|
|
260
|
-
// the visit's worktrees, with the same live-mode recheck the per-spawn path keeps. Concurrent
|
|
261
|
-
// writing spawns share one prompt rather than each raising their own.
|
|
262
192
|
let worktreeAudited = false, worktreeGranted = false;
|
|
263
193
|
let worktreeApproval;
|
|
264
194
|
const authorizeDelegatedWorktree = async (parentContext, approvalArgs) => {
|
|
@@ -278,16 +208,7 @@ export async function executeAgentNode(node, options) {
|
|
|
278
208
|
};
|
|
279
209
|
const waiters = [];
|
|
280
210
|
const emit = async (type, data) => options.onEvent?.({ type, time: new Date().toISOString(), data: { runId: options.runId, nodeId: node.id, ...data } });
|
|
281
|
-
/** Release this node's budget and abort its controller. Both operations are idempotent. */
|
|
282
211
|
const finish = () => { controller.abort(); nodeBudget.dispose(); };
|
|
283
|
-
/**
|
|
284
|
-
* Orchestrator intake that can end this node before the attempt starts.
|
|
285
|
-
*
|
|
286
|
-
* It runs in its own cleanup scope: the headless case returns here and either branch awaits
|
|
287
|
-
* an event sink that may reject, and the attempt's own `finally` is not in scope yet. Both
|
|
288
|
-
* exits would otherwise leave this node's timer retained until the original deadline.
|
|
289
|
-
* @returns an early result when intake cannot proceed, otherwise undefined.
|
|
290
|
-
*/
|
|
291
212
|
const runIntake = async () => {
|
|
292
213
|
if (!orchestrator)
|
|
293
214
|
return undefined;
|
|
@@ -307,7 +228,6 @@ export async function executeAgentNode(node, options) {
|
|
|
307
228
|
{ id: 'clarify', text: 'Confirm requirements and design considerations', status: 'pending' },
|
|
308
229
|
{ id: 'deliver', text: 'Complete the requested work and verify the result', status: 'pending' },
|
|
309
230
|
]);
|
|
310
|
-
// Intake continues into the attempt on success, so only a rejection leaves the function.
|
|
311
231
|
try {
|
|
312
232
|
await emit('graph.todos.updated', { todos });
|
|
313
233
|
}
|
|
@@ -326,16 +246,10 @@ export async function executeAgentNode(node, options) {
|
|
|
326
246
|
const nodeBudget = createRuntimeBudget(context.signal, nodeLimits.wallTimeMs, context.runControl);
|
|
327
247
|
const observationController = options.decisionManager?.enabled ? new AbortController() : undefined;
|
|
328
248
|
const nodeSignal = observationController ? AbortSignal.any([nodeBudget.signal, observationController.signal]) : nodeBudget.signal;
|
|
329
|
-
// The whole attempt is wrapped so this node's timer is released on every exit, including a
|
|
330
|
-
// rethrow: a long-lived session would otherwise keep one timer per finished attempt alive
|
|
331
|
-
// until its original deadline, retaining the budget closure for no reason.
|
|
332
249
|
try {
|
|
333
250
|
let result;
|
|
334
251
|
try {
|
|
335
252
|
nodeSignal.throwIfAborted();
|
|
336
|
-
// This node has its own clock in addition to the enclosing one, so the tool context must
|
|
337
|
-
// be bound to it as well: otherwise a wait on the user would pause the outer budget
|
|
338
|
-
// while this node's own deadline quietly expired underneath the open prompt.
|
|
339
253
|
result = await runWithinDeadline(configured, bindUserWaits({ ...context, signal: nodeSignal }, nodeBudget, nodeSignal), depth, inputs, task, subagentId, parentFallback, () => {
|
|
340
254
|
const resumeInvocation = suspendInvocationMemoryBudget();
|
|
341
255
|
const resume = nodeBudget.suspend();
|
|
@@ -348,10 +262,6 @@ export async function executeAgentNode(node, options) {
|
|
|
348
262
|
result = { id: options.runId ?? randomUUID(), graph: options.graph ?? DEFAULT_GRAPH, provider: configured.provider ?? options.provider, model: configured.model ?? options.model,
|
|
349
263
|
status: 'cancelled', usage: { inputTokens: 0, outputTokens: 0, requests: 0 }, toolCalls: 0, todos: todoStore.snapshot() };
|
|
350
264
|
}
|
|
351
|
-
// A node signal can end for two different reasons, and only one of them is a deadline.
|
|
352
|
-
// `context.signal` may itself be budget-derived from an enclosing node, so the cancellation
|
|
353
|
-
// test uses the session signal: testing the fused one would report an enclosing deadline
|
|
354
|
-
// to the user as "cancelled".
|
|
355
265
|
if (nodeSignal.aborted) {
|
|
356
266
|
const cancelled = (context.userSignal ?? context.signal).aborted;
|
|
357
267
|
result.status = cancelled ? 'cancelled' : 'exhausted';
|
|
@@ -366,28 +276,22 @@ export async function executeAgentNode(node, options) {
|
|
|
366
276
|
}
|
|
367
277
|
};
|
|
368
278
|
const runWithinDeadline = async (configured, context, depth, inputs, task, subagentId, parentFallback = false, suspendMemoryBudget, commandScope = depth > 0) => {
|
|
369
|
-
// The Orchestrator and its ordinary children run at the intake ceiling. A delegated writing child
|
|
370
|
-
// was admitted against the node's configured ceiling and keeps the capabilities it was given.
|
|
371
279
|
const delegatedChild = commandScope === 'delegated-worktree';
|
|
372
280
|
if (orchestrator && !delegatedChild)
|
|
373
281
|
configured = { ...configured, capabilities: intakeCapabilities(configured) };
|
|
374
|
-
// A delegating Orchestrator ends with `completed` (the handoff) or `delivered`; every other node
|
|
375
|
-
// keeps its configured policy, so an inactive Orchestrator is unchanged.
|
|
376
282
|
const completionPolicy = delegationActive && depth === 0 && configured.completion?.mode !== 'outcomes'
|
|
377
283
|
? { mode: 'outcomes', outcomes: [configured.completion?.outcome ?? 'completed', DELIVERED_OUTCOME] }
|
|
378
284
|
: configured.completion ?? { mode: 'single', outcome: 'completed' };
|
|
379
|
-
// Outcomes this node routes straight to an End node: its completion is then the run's result and
|
|
380
|
-
// its summary the answer the user reads, so the handoff passes the final-answer gates first. A
|
|
381
|
-
// delegated child and a node that hands off to another node are left alone: the plan belongs to
|
|
382
|
-
// the whole run, and a successor reads the output, not the summary. So is one iteration or copy
|
|
383
|
-
// of a loop or parallel modifier: the modifier aggregates those results, and it cannot be known
|
|
384
|
-
// inside an iteration whether it is the last. An Orchestrator is left alone too: the host seeds its
|
|
385
|
-
// plan with every stage of the run, and its `delivered` outcome has its own guard below (every
|
|
386
|
-
// change decided, at least one landed).
|
|
387
285
|
const declaredOutcomes = completionPolicy.mode === 'single' ? [completionPolicy.outcome] : completionPolicy.outcomes;
|
|
388
|
-
const
|
|
286
|
+
const endOutcomes = depth === 0 && !subagentId && !orchestrator && options.graph
|
|
389
287
|
? declaredOutcomes.filter(outcome => options.graph.edges.some(edge => edge.source === node.id && (edge.outcome ?? 'completed') === outcome && options.graph.nodes[edge.target]?.type === 'end'))
|
|
390
288
|
: [];
|
|
289
|
+
const finalAnswerOutcomes = options.modifierIteration === undefined ? endOutcomes : [];
|
|
290
|
+
// The session goal is checked on the last agent before the run ends, which may sit behind an
|
|
291
|
+
// action, join or other non-agent node rather than on a direct edge to End. An Orchestrator is
|
|
292
|
+
// included: its intake handoff routes to an agent, but its delivered outcome ends the run.
|
|
293
|
+
const goalGraph = depth === 0 && !subagentId ? options.graph : undefined;
|
|
294
|
+
const goalCanEndRun = goalGraph !== undefined && goalRunEndingOutcomes(goalGraph, node.id, routedOutcomes(node, declaredOutcomes)).length > 0;
|
|
391
295
|
context.toolState ??= { fileReads: new Map() };
|
|
392
296
|
if (configured.executor && configured.executor !== 'react-basic')
|
|
393
297
|
throw new Error('Only react-basic is available');
|
|
@@ -399,11 +303,6 @@ export async function executeAgentNode(node, options) {
|
|
|
399
303
|
if (inputText.length > contextChars)
|
|
400
304
|
throw new Error('Mapped inputs exceed context limit; pass artifact references instead');
|
|
401
305
|
const configuredProvider = configured.provider ?? options.provider;
|
|
402
|
-
// The model this node runs: its own, or — for a node that names neither a provider nor a model —
|
|
403
|
-
// the run's own model. A node that names a provider but no model runs that provider's
|
|
404
|
-
// configured model, which is the rule the checkpoint identity and the model preflight both
|
|
405
|
-
// use: they read the same node the same way, and a run that resolved such a node to the run's
|
|
406
|
-
// model would write a checkpoint no later run could recognize.
|
|
407
306
|
const configuredModel = configured.model ?? (configured.provider === undefined ? options.model : undefined);
|
|
408
307
|
const resolve = async (provider, model) => retryReadOnly(context, signal => options.resolveModel
|
|
409
308
|
? options.resolveModel(provider, model, signal)
|
|
@@ -412,10 +311,6 @@ export async function executeAgentNode(node, options) {
|
|
|
412
311
|
if (!resolved)
|
|
413
312
|
throw new Error(`Unknown provider ${provider}. Run andorra and open /providers first.`);
|
|
414
313
|
let model = configured.model ?? resolved.model;
|
|
415
|
-
// A delegated child inherits its parent's effective pair, so a parent continuing on a retry's
|
|
416
|
-
// fallback hands the fallback down too. The flag travels with the invocation because the
|
|
417
|
-
// child's own attempt counter starts at 1 and its node carries no retry policy: without it the
|
|
418
|
-
// selection resolver would read the child as running the primary pair and move it there.
|
|
419
314
|
let fallbackAttempt = parentFallback;
|
|
420
315
|
const orchestratorCompletionGuard = () => {
|
|
421
316
|
if (!clarified)
|
|
@@ -430,11 +325,8 @@ export async function executeAgentNode(node, options) {
|
|
|
430
325
|
const codeLedger = codeManager?.createLedger();
|
|
431
326
|
const codeIntel = codeManager?.active && permitsBuiltInTool(configured, 'repo_explore') ? codeManager : undefined;
|
|
432
327
|
const researchTool = (name) => ['Read', 'Glob', 'Grep', 'git_read', 'repo_explore'].includes(canonicalToolName(name));
|
|
433
|
-
// The panel browser tool is bound to the primary agent's session panel: a child
|
|
434
|
-
// driving the same visible tabs the parent is using cannot be authorized apart,
|
|
435
|
-
// so children never inherit it (and a role naming it fails selection below).
|
|
436
328
|
const catalog = [...options.tools, ...(options.tools.some(tool => tool.name === 'git_read') ? [] : [gitReadTool()])];
|
|
437
|
-
let tools = capabilityTools(configured, catalog, commandScope).filter(tool => !['ask_user', 'spawn_subagent', 'present_plan'].includes(tool.name) && (depth === 0 || !['browser.panel', 'browser.incognito'].includes(tool.name)) && (!orchestrator || delegatedChild || researchTool(tool.name) || ['read_skill_resource', 'qa.browser_session', 'browser.panel', 'browser.incognito'].includes(tool.name)));
|
|
329
|
+
let tools = capabilityTools(configured, catalog, commandScope).filter(tool => !['ask_user', 'spawn_subagent', 'present_plan'].includes(tool.name) && (depth === 0 || !['browser.panel', 'browser.incognito', 'browser.extensions'].includes(tool.name)) && (!orchestrator || delegatedChild || researchTool(tool.name) || ['read_skill_resource', 'qa.browser_session', 'browser.panel', 'browser.incognito', 'browser.extensions'].includes(tool.name)));
|
|
438
330
|
const compatibilityRecoverTools = options.tools.filter(tool => tool.providerVisible === false
|
|
439
331
|
&& permitsBuiltInTool(configured, tool.name, commandScope)
|
|
440
332
|
&& (!orchestrator || delegatedChild || researchTool(tool.name))).flatMap(legacy => {
|
|
@@ -443,15 +335,10 @@ export async function executeAgentNode(node, options) {
|
|
|
443
335
|
if (!canonical)
|
|
444
336
|
return [];
|
|
445
337
|
return [{ ...legacy, execute: (args, ctx) => {
|
|
446
|
-
// Resolve at call time: the node list is wrapped in place for research observation,
|
|
447
|
-
// so a legacy research call must run the wrapper or intake never sees evidence.
|
|
448
338
|
const current = tools.find(tool => tool.name === canonical.name) ?? canonical;
|
|
449
339
|
return current.execute(adaptLegacyCodingToolArguments(legacy.name, args), ctx);
|
|
450
340
|
} }];
|
|
451
341
|
});
|
|
452
|
-
// repo_explore is optional. When CodeGraph is unavailable, canonical
|
|
453
|
-
// Read/Glob/Grep remain the only filesystem research surface; legacy
|
|
454
|
-
// compatibility aliases stay hidden from the provider.
|
|
455
342
|
if (orchestrator && !codeIntel && configured.tools?.some(name => canonicalToolName(name) === 'repo_explore') && effectiveCapabilities(configured).filesystem !== 'none') {
|
|
456
343
|
const existing = new Set(tools.map(tool => tool.name));
|
|
457
344
|
for (const fallback of options.tools.filter(tool => ['Read', 'Glob', 'Grep'].includes(canonicalToolName(tool.name)) && tool.providerVisible !== false)) {
|
|
@@ -463,6 +350,10 @@ export async function executeAgentNode(node, options) {
|
|
|
463
350
|
}
|
|
464
351
|
if (codeLedger && codeIntel)
|
|
465
352
|
tools.push(codeIntel.exploreTool(codeLedger));
|
|
353
|
+
if (options.projectMemory && depth === 0 && configured.contextPolicy?.projectMemory !== false) {
|
|
354
|
+
const present = new Set(tools.map(tool => tool.name));
|
|
355
|
+
tools.push(...options.projectMemory.tools().filter(tool => !present.has(tool.name)));
|
|
356
|
+
}
|
|
466
357
|
if (orchestrator)
|
|
467
358
|
for (let index = 0; index < tools.length; index++) {
|
|
468
359
|
const tool = tools[index];
|
|
@@ -475,8 +366,9 @@ export async function executeAgentNode(node, options) {
|
|
|
475
366
|
return observation;
|
|
476
367
|
} };
|
|
477
368
|
}
|
|
369
|
+
const headlessRun = options.context.approvalMode === 'headless';
|
|
478
370
|
if (codeLedger && codeManager)
|
|
479
|
-
tools = codeManager.wrapTools(tools, codeLedger);
|
|
371
|
+
tools = codeManager.wrapTools(tools, codeLedger, { grepPolicy: headlessRun ? 'advisory' : 'graph-first' });
|
|
480
372
|
if (orchestrator && depth === 0)
|
|
481
373
|
tools.push({ name: 'ask_user', executionMode: 'sequential', description: 'Ask the user to clarify requirements and confirm or revise proposed design considerations. Ask one short question in plain language. Include only 1-3 brief user-facing consequences in proposedDesign; keep code details in the handoff. Prefer 2-3 short answer choices, with the recommended choice first and labelled (Recommended). Required before Orchestrator completion. A refusal stops intake.',
|
|
482
374
|
parameters: { type: 'object', properties: { question: { type: 'string', minLength: 1, maxLength: 500, description: 'One plain-language question about what the user wants.' }, proposedDesign: { type: 'array', items: { type: 'string', minLength: 1, maxLength: 240 }, minItems: 1, maxItems: 3, description: 'Short consequences that help the user decide. No source listings or implementation notes.' }, choices: { type: 'array', items: { type: 'string', minLength: 1, maxLength: 200 }, minItems: 2, maxItems: 8 } }, required: ['question', 'proposedDesign'], additionalProperties: false },
|
|
@@ -504,14 +396,10 @@ export async function executeAgentNode(node, options) {
|
|
|
504
396
|
await emit('agent.clarification.answered', { answered: true });
|
|
505
397
|
return JSON.stringify({ answer, proposedDesign: args.proposedDesign });
|
|
506
398
|
} });
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
// nothing, and a reply that is only a question is a stalled turn the runtime sends back, so
|
|
510
|
-
// the user watches the question scroll past while the run keeps working. It is offered only
|
|
511
|
-
// where a person can answer; a headless run keeps the complete_agent handoff, and a delegated
|
|
512
|
-
// child reports to its parent rather than to the user.
|
|
399
|
+
if (orchestrator && depth === 0 && effectiveCapabilities(configured).filesystem !== 'none')
|
|
400
|
+
tools.push(removeUntrackedFileTool());
|
|
513
401
|
if (!orchestrator && depth === 0 && options.context.approvalMode !== 'headless' && options.context.askUser)
|
|
514
|
-
tools.push({ name: 'ask_user', executionMode: 'sequential', description: 'Ask the user a question only they can answer and wait for the answer. Use it whenever a choice is theirs to make: a skill or instruction that says to ask, a preference, a missing requirement. A question written in your reply does not pause the run and may go unseen, so never ask that way. Ask one short question per call in plain language; when the options are known give 2-4 short choices, the recommended one first and labelled (Recommended). Do not ask what your tools can find out or what you can reasonably decide yourself.',
|
|
402
|
+
tools.push({ name: 'ask_user', executionMode: 'sequential', description: 'Ask the user a question only they can answer and wait for the answer. Use it whenever a choice is theirs to make: a skill or instruction that says to ask, a preference, a missing requirement. A question written in your reply does not pause the run and may go unseen, so never ask that way. Ask one short question per call in plain language; when the options are known give 2-4 short choices, the recommended one first and labelled (Recommended). Do not ask what your tools can find out or what you can reasonably decide yourself. Before asking where something is or what a name refers to, finish a search for it by file name and by content; a search that was cut short or timed out does not count.',
|
|
515
403
|
parameters: { type: 'object', properties: { question: { type: 'string', minLength: 1, maxLength: 500, description: 'One plain-language question.' }, choices: { type: 'array', items: { type: 'string', minLength: 1, maxLength: 200 }, minItems: 2, maxItems: 8, description: 'Short answers the user can pick from; they can always type their own.' } }, required: ['question'], additionalProperties: false },
|
|
516
404
|
execute: async (args, ctx) => {
|
|
517
405
|
ctx.signal.throwIfAborted();
|
|
@@ -528,10 +416,6 @@ export async function executeAgentNode(node, options) {
|
|
|
528
416
|
ctx.signal.throwIfAborted();
|
|
529
417
|
const answered = typeof answer === 'string' && !!answer.trim() && answer.trim().toLowerCase() !== '/cancel';
|
|
530
418
|
await emit('agent.clarification.answered', { answered });
|
|
531
|
-
// The surfaces report two different refusals. No answer at all, or /cancel, is the user
|
|
532
|
-
// cancelling: the terminal's choice is labelled "Cancel this task", so the run stops as it
|
|
533
|
-
// does for an Orchestrator question. An empty answer is the desktop's Skip, which declines
|
|
534
|
-
// this one question and lets the work go on.
|
|
535
419
|
if (typeof answer !== 'string' || answer.trim().toLowerCase() === '/cancel')
|
|
536
420
|
throw new ClarificationRequiredError('Needs clarification: the user cancelled the task at a question. Nothing further was done.');
|
|
537
421
|
if (!answered)
|
|
@@ -540,11 +424,6 @@ export async function executeAgentNode(node, options) {
|
|
|
540
424
|
throw new Error('The answer exceeds 16000 characters; ask for a shorter decision.');
|
|
541
425
|
return JSON.stringify({ answered: true, answer });
|
|
542
426
|
} });
|
|
543
|
-
// Plan mode is offered at the run's top level regardless of the mode this attempt composed
|
|
544
|
-
// under: the mode is the user's pick and can change while the task runs (the live picker or
|
|
545
|
-
// /permissions plan), and a catalog keyed to the starting mode would leave a switched-in run
|
|
546
|
-
// told to present a plan it has no tool for. The execution-time check below decides what a
|
|
547
|
-
// call means under the mode in force when it lands.
|
|
548
427
|
if (depth === 0)
|
|
549
428
|
tools.push({ name: 'present_plan', executionMode: 'sequential', description: 'Present the implementation plan for the user to approve, reject, or send feedback on. Only meaningful while the run is in plan mode: file mutations and escalations stay refused until a plan is approved. Present one complete plan in markdown after researching; a later call may present a revised plan after feedback.',
|
|
550
429
|
parameters: { type: 'object', properties: { plan: { type: 'string', minLength: 1, maxLength: 16000, description: 'The implementation plan in markdown: what will change, the files or areas touched, the approach, and how it will be verified.' } }, required: ['plan'], additionalProperties: false },
|
|
@@ -552,8 +431,6 @@ export async function executeAgentNode(node, options) {
|
|
|
552
431
|
ctx.signal.throwIfAborted();
|
|
553
432
|
if (Object.keys(args).some(key => key !== 'plan') || typeof args.plan !== 'string' || !args.plan.trim() || args.plan.length > 16000)
|
|
554
433
|
throw new Error('Provide the plan as one markdown string of 1-16000 characters.');
|
|
555
|
-
// The mode is read live: a plan already approved, or the user switching modes by hand,
|
|
556
|
-
// leaves nothing to present for, and the error steers the model back to the task.
|
|
557
434
|
if (permissionMode(ctx) !== 'plan')
|
|
558
435
|
throw new Error('Plan mode is not active for this run; no plan presentation is needed. Proceed with the task under the current permissions.');
|
|
559
436
|
if (ctx.approvalMode === 'headless' || !ctx.askUser)
|
|
@@ -590,12 +467,7 @@ export async function executeAgentNode(node, options) {
|
|
|
590
467
|
tools.push(artifactTools[0]);
|
|
591
468
|
if (configured.tools === undefined || configured.tools.includes('write_artifact'))
|
|
592
469
|
tools.push({ ...write, execute: async (args, ctx) => { const result = await write.execute(args, ctx); scopedRefs.add(JSON.parse(result).ref); return result; } });
|
|
593
|
-
// Skill wrappers replace the visible resource reader later in this invocation.
|
|
594
|
-
// Delegation still needs its original, capability-filtered name to load inherited skills.
|
|
595
470
|
const canDelegateSkillReader = tools.some(tool => tool.name === 'read_skill_resource');
|
|
596
|
-
// Under a delegating Orchestrator no child spawns further, whatever the depth limit: a writing
|
|
597
|
-
// role spawned from a child would take the ordinary path, with a worktree made from HEAD that is
|
|
598
|
-
// kept and registered in the user's repository, outside the review this node promises.
|
|
599
471
|
if (policy.enabled && maxTotal > 0 && depth < (policy.maxDepth ?? 1) && !(delegationActive && depth > 0)) {
|
|
600
472
|
tools.push({ name: 'spawn_subagent', description: 'Run one configured role on a bounded task. Its typed result returns as an observation. Batch spawn calls can run concurrently within configured limits. Role contracts: ' + JSON.stringify((policy.roles ?? []).map(role => ({ id: role.id, name: role.name, instruction: role.instruction, inputSchema: role.inputSchema, outputSchema: role.outputSchema }))),
|
|
601
473
|
parameters: { type: 'object', properties: { role: { type: 'string', enum: (policy.roles ?? []).map(role => role.id) }, task: { type: 'string' }, input: { type: 'object' } }, required: ['role', 'task'], additionalProperties: false },
|
|
@@ -612,9 +484,6 @@ export async function executeAgentNode(node, options) {
|
|
|
612
484
|
throw new Error('Subagent input must be an object');
|
|
613
485
|
if (role.inputSchema)
|
|
614
486
|
validateValue(role.inputSchema, childInputs, `Subagent ${role.name} input`);
|
|
615
|
-
// A writing role of a delegating Orchestrator is admitted against the node's configured
|
|
616
|
-
// ceiling, not the intake ceiling the Orchestrator itself runs under; it starts only once
|
|
617
|
-
// the user has confirmed the design.
|
|
618
487
|
const delegated = delegationActive && depth === 0 && isWritingRole(role);
|
|
619
488
|
if (delegated && !clarified)
|
|
620
489
|
throw new Error('Ask the user to confirm the design before starting writing subagents: a real ask_user answer is required first.');
|
|
@@ -629,15 +498,10 @@ export async function executeAgentNode(node, options) {
|
|
|
629
498
|
throw new Error('Concurrent writing subagents require separate worktrees');
|
|
630
499
|
if ((policy.workspace ?? 'shared-read-only') === 'shared-read-only' && writingChild)
|
|
631
500
|
throw new Error('Shared read-only subagents cannot write');
|
|
632
|
-
// `browser.panel` and `browser.incognito` stay with the primary agent (see the tools filter above);
|
|
633
|
-
// excluded here rather than at selection so a role naming it explicitly is
|
|
634
|
-
// refused as exceeding the parent instead of silently losing its browser.
|
|
635
|
-
// A delegated writing role's tools come from the node's capabilities, not from the
|
|
636
|
-
// Orchestrator's own read-only intake kit: a worktree child may write and run commands.
|
|
637
501
|
const available = new Set(delegated
|
|
638
|
-
? [...capabilityTools({ ...node, capabilities: parentCapabilities, tools: undefined }, catalog, 'delegated-worktree').map(tool => tool.name).filter(name => name !== 'browser.panel' && name !== 'browser.incognito'),
|
|
502
|
+
? [...capabilityTools({ ...node, capabilities: parentCapabilities, tools: undefined }, catalog, 'delegated-worktree').map(tool => tool.name).filter(name => name !== 'browser.panel' && name !== 'browser.incognito' && name !== 'browser.extensions'),
|
|
639
503
|
...tools.map(tool => tool.name).filter(name => name === 'read_artifact' || name === 'write_artifact'), ...(canDelegateSkillReader ? ['read_skill_resource'] : [])]
|
|
640
|
-
: [...tools.map(tool => tool.name).filter(name => name !== 'browser.panel' && name !== 'browser.incognito'), ...(canDelegateSkillReader ? ['read_skill_resource'] : [])]);
|
|
504
|
+
: [...tools.map(tool => tool.name).filter(name => name !== 'browser.panel' && name !== 'browser.incognito' && name !== 'browser.extensions'), ...(canDelegateSkillReader ? ['read_skill_resource'] : [])]);
|
|
641
505
|
const childToolNames = delegated ? canonicalizeToolList(role.tools) ?? [...available]
|
|
642
506
|
: policy.toolInheritance === 'inherit' ? [...available] : canonicalizeToolList(role.tools) ?? [...available].filter(name => ['Read', 'Glob', 'Grep', 'git_read', 'qa.browser_session', 'read_skill_resource'].includes(canonicalToolName(name)));
|
|
643
507
|
if (childToolNames.some(name => !available.has(name)))
|
|
@@ -671,7 +535,6 @@ export async function executeAgentNode(node, options) {
|
|
|
671
535
|
total++;
|
|
672
536
|
const id = randomUUID();
|
|
673
537
|
let workspaceArtifact;
|
|
674
|
-
/** The delegated child's worktree and the snapshot it started from; kept only while a change is pending. */
|
|
675
538
|
let delegatedWorktree;
|
|
676
539
|
let keepWorktree = false;
|
|
677
540
|
try {
|
|
@@ -681,11 +544,7 @@ export async function executeAgentNode(node, options) {
|
|
|
681
544
|
if (delegated) {
|
|
682
545
|
if (parentCapabilities.git !== 'write')
|
|
683
546
|
throw new Error('Creating child worktrees requires parent Git write capability');
|
|
684
|
-
// Git itself is checked before any approval or temporary directory, so an unsuitable
|
|
685
|
-
// workspace fails without side effects.
|
|
686
547
|
await assertDelegationGit(parentWorkspace, parentContext.signal);
|
|
687
|
-
// A workspace that is a subfolder of its repository puts the child in the same
|
|
688
|
-
// subfolder of the worktree; the snapshot and the worktree cover the whole repository.
|
|
689
548
|
const inside = relative(await repositoryRoot(parentWorkspace, parentContext.signal), await realpath(parentWorkspace));
|
|
690
549
|
const temporaryDirectoryPrefix = join(tmpdir(), 'andorra-subagent-');
|
|
691
550
|
const approvalArgs = { role: role.id, workspace: parentWorkspace, temporaryDirectoryPrefix,
|
|
@@ -703,9 +562,6 @@ export async function executeAgentNode(node, options) {
|
|
|
703
562
|
else if (policy.workspace === 'worktree' && writingChild) {
|
|
704
563
|
if (parentCapabilities.git !== 'write')
|
|
705
564
|
throw new Error('Creating child worktrees requires parent Git write capability');
|
|
706
|
-
// Worktree setup is a host operation: even status can follow an external
|
|
707
|
-
// gitdir or execute PATH Git. Obtain one scoped grant before any probe
|
|
708
|
-
// or temporary-directory mutation, including protected Git metadata.
|
|
709
565
|
const temporaryDirectoryPrefix = join(tmpdir(), 'andorra-subagent-');
|
|
710
566
|
const approvalArgs = { role: role.id, workspace, temporaryDirectoryPrefix,
|
|
711
567
|
operations: ['git status --porcelain', 'create temporary directory', 'git worktree add --detach <temporary-directory>/worktree HEAD'],
|
|
@@ -714,8 +570,6 @@ export async function executeAgentNode(node, options) {
|
|
|
714
570
|
const authorizeWorktree = async () => {
|
|
715
571
|
parentContext.signal.throwIfAborted();
|
|
716
572
|
assertPlanMutationAllowed(parentContext);
|
|
717
|
-
// Recheck after audit delivery and between setup steps. A Full
|
|
718
|
-
// Access policy grant must not survive a live-mode downgrade.
|
|
719
573
|
while (!audited || (!explicitlyApproved && permissionMode(parentContext) !== 'full-access')) {
|
|
720
574
|
await approveOperation({ ...parentContext, approve: async (...approval) => {
|
|
721
575
|
const allowed = await parentContext.approve(...approval);
|
|
@@ -742,37 +596,24 @@ export async function executeAgentNode(node, options) {
|
|
|
742
596
|
await exec('git', [...args, 'worktree', 'add', '--detach', workspace, 'HEAD'], gitOptions);
|
|
743
597
|
workspaceArtifact = await store.put('git-worktree', JSON.stringify({ workspace, role: role.id, note: 'Changes retained for explicit inspection and integration; not merged automatically.' }));
|
|
744
598
|
}
|
|
745
|
-
// A delegated child inherits the run's bounds rather than inventing its own. With
|
|
746
|
-
// the run unlimited, an arbitrary child ceiling would become the only thing
|
|
747
|
-
// stopping a long sub-task, which is the behavior this runtime just removed.
|
|
748
|
-
// `maxWallTimeMs` stays the explicit way to bound a child.
|
|
749
599
|
child.limits = {
|
|
750
600
|
...(policy.maxWallTimeMs === undefined ? {} : { wallTimeMs: policy.maxWallTimeMs }),
|
|
751
601
|
...(limits.maxIterations === undefined ? {} : { maxIterations: Math.min(limits.maxIterations, 40) }),
|
|
752
602
|
};
|
|
753
|
-
await emit('subagent.started', { subagentId: id, role: role.id, depth: depth + 1
|
|
603
|
+
await emit('subagent.started', { subagentId: id, role: role.id, depth: depth + 1,
|
|
604
|
+
...(childProvider ? { provider: childProvider } : {}), ...(childModel ? { model: childModel } : {}) });
|
|
754
605
|
let result;
|
|
755
606
|
try {
|
|
756
|
-
// The worktrees awaiting review are the Orchestrator's review aid: no child reads
|
|
757
|
-
// them, whether it is a delegated writer or an ordinary research role.
|
|
758
607
|
result = await run(child, { ...parentContext, workspace, ...(parentContext.delegationRoots ? { delegationRoots: undefined } : {}) }, depth + 1, childInputs, task, id, fallbackAttempt, delegated ? 'delegated-worktree' : undefined);
|
|
759
608
|
}
|
|
760
609
|
catch (error) {
|
|
761
|
-
// A child that throws once started (oversized mapped inputs, a cancelled parent) still
|
|
762
|
-
// ends here: without a settling event, a listener counting this child keeps it running
|
|
763
|
-
// until the whole run ends. The spawn call itself still fails with the error.
|
|
764
610
|
await emit('subagent.completed', { subagentId: id, role: role.id, status: parentContext.signal.aborted ? 'cancelled' : 'failed' });
|
|
765
611
|
throw error;
|
|
766
612
|
}
|
|
767
613
|
finally {
|
|
768
|
-
// However the child ended, its background jobs end with it, before its files are
|
|
769
|
-
// collected: a worktree kept for review must not have a process still writing in it.
|
|
770
614
|
if (delegatedWorktree)
|
|
771
615
|
await stopWorktreeJobs(delegatedWorktree.worktree);
|
|
772
616
|
}
|
|
773
|
-
// The child's requests, tools and decisions were billed to the run, so its capture is
|
|
774
|
-
// folded into the parent's; the result object itself is consumed as a tool observation
|
|
775
|
-
// and would otherwise take those totals with it.
|
|
776
617
|
if (result.telemetry)
|
|
777
618
|
mergeRunTelemetry(telemetry, result.telemetry);
|
|
778
619
|
if (result.status === 'succeeded' && researchResults.get(result))
|
|
@@ -785,19 +626,13 @@ export async function executeAgentNode(node, options) {
|
|
|
785
626
|
const observation = { status: result.status, reason: result.reason, outcome: result.completion?.outcome, output: result.completion?.output, artifacts: returnedArtifacts };
|
|
786
627
|
if (delegatedWorktree) {
|
|
787
628
|
observation.tests = result.completion?.tests ?? [];
|
|
788
|
-
// A child that failed, was cancelled or changed nothing yields no change: its worktree
|
|
789
|
-
// goes in the cleanup below. Otherwise the change waits for the Orchestrator's review.
|
|
790
629
|
const collected = result.status === 'succeeded' ? await collectChange(delegatedWorktree.worktree, delegatedWorktree.base, parentContext.signal) : undefined;
|
|
791
630
|
if (collected?.files.length) {
|
|
792
631
|
const { worktree, base } = delegatedWorktree;
|
|
793
|
-
// Random rather than counted: a resumed visit starts a new registry, and a counter
|
|
794
|
-
// would hand out ids the resumed conversation already uses for other changes.
|
|
795
632
|
let changeId = `change-${randomUUID().slice(0, 8)}`;
|
|
796
633
|
while (changes.has(changeId))
|
|
797
634
|
changeId = `change-${randomUUID().slice(0, 8)}`;
|
|
798
635
|
const truncated = collected.diff.length > DELEGATION_DIFF_LIMIT;
|
|
799
|
-
// The full diff is an artifact the Orchestrator can page through; one too large even
|
|
800
|
-
// for an artifact stays readable in the worktree, and the observation says so.
|
|
801
636
|
let diffArtifact, diffNote;
|
|
802
637
|
try {
|
|
803
638
|
diffArtifact = await store.put('delegation-diff', collected.diff);
|
|
@@ -806,8 +641,6 @@ export async function executeAgentNode(node, options) {
|
|
|
806
641
|
catch (error) {
|
|
807
642
|
diffNote = `The full diff could not be stored as an artifact (${error instanceof Error ? error.message : String(error)}); read the changed files inside the worktree.`;
|
|
808
643
|
}
|
|
809
|
-
// The record is registered only after every step that can throw: a pending record must
|
|
810
|
-
// never point at a worktree the cleanup below already removed.
|
|
811
644
|
const root = await realpath(worktree);
|
|
812
645
|
changes.set(changeId, { id: changeId, subagentId: id, role: role.id, worktree, base, tree: collected.tree, files: collected.files, state: 'pending',
|
|
813
646
|
provider: result.provider ?? childProvider, model: result.model ?? childModel, conflicts: [], ...(diffArtifact ? { diffArtifact } : {}) });
|
|
@@ -828,8 +661,6 @@ export async function executeAgentNode(node, options) {
|
|
|
828
661
|
}
|
|
829
662
|
} });
|
|
830
663
|
}
|
|
831
|
-
// The landing tools act on a change record by id and nothing else: the Orchestrator cannot
|
|
832
|
-
// supply content, a patch or a command through them, so it still cannot write code itself.
|
|
833
664
|
if (delegationActive && depth === 0) {
|
|
834
665
|
const idOnly = () => ({ type: 'object', properties: { id: { type: 'string', minLength: 1, description: 'The change id from a spawn_subagent result.' } }, required: ['id'], additionalProperties: false });
|
|
835
666
|
const undecided = (args, name) => {
|
|
@@ -855,36 +686,24 @@ export async function executeAgentNode(node, options) {
|
|
|
855
686
|
const { base, tree } = change;
|
|
856
687
|
assertPlanMutationAllowed(ctx);
|
|
857
688
|
const conflict = async (conflicts, detail) => {
|
|
858
|
-
// The paths stay on the record after a later clean landing: the delivery record says
|
|
859
|
-
// the change conflicted before it landed.
|
|
860
689
|
change.state = 'conflict';
|
|
861
690
|
change.conflicts = conflicts;
|
|
862
691
|
await announce(change);
|
|
863
692
|
return JSON.stringify({ state: 'conflict', conflicts, detail });
|
|
864
693
|
};
|
|
865
694
|
const failed = async (error) => {
|
|
866
|
-
// A landing that wrote part of the change and could not put the folder back is not a
|
|
867
|
-
// conflict the Orchestrator can review its way out of: the node stops, and its reason
|
|
868
|
-
// carries the snapshot commit and the files the user needs to recover.
|
|
869
695
|
if (error instanceof LandingRestoreError) {
|
|
870
696
|
change.state = 'conflict';
|
|
871
697
|
change.conflicts = error.paths;
|
|
872
698
|
await announce(change);
|
|
873
699
|
throw new ClarificationRequiredError(error.message);
|
|
874
700
|
}
|
|
875
|
-
// A cancelled run propagates as cancellation. Any other failure happened before
|
|
876
|
-
// anything was written (the snapshot, the merge or the copy made before applying), so
|
|
877
|
-
// it is a conflict in effect.
|
|
878
701
|
if (ctx.signal.aborted || (error instanceof Error && error.name === 'AbortError'))
|
|
879
702
|
throw error;
|
|
880
703
|
return conflict([], error instanceof Error ? error.message : String(error));
|
|
881
704
|
};
|
|
882
|
-
/** Paths an approval prompt of this call already covered. */
|
|
883
705
|
const granted = new Set();
|
|
884
706
|
let asked = false;
|
|
885
|
-
// A landing is prepared, authorized for the paths it writes, then applied. The folder can
|
|
886
|
-
// change while a prompt is open; the apply then refuses the prepared patch as a whole and
|
|
887
|
-
// the landing is prepared again from the folder as it now stands.
|
|
888
707
|
for (let attempt = 1;; attempt++) {
|
|
889
708
|
ctx.signal.throwIfAborted();
|
|
890
709
|
let prepared;
|
|
@@ -896,14 +715,8 @@ export async function executeAgentNode(node, options) {
|
|
|
896
715
|
}
|
|
897
716
|
if (!prepared.ready)
|
|
898
717
|
return conflict(prepared.conflicts, prepared.detail);
|
|
899
|
-
// Landing follows the rule for an Edit of the same files, and the files are the ones
|
|
900
|
-
// the merged patch writes or removes, not the ones the subagent changed: a file the
|
|
901
|
-
// user moved meanwhile takes the edit at its new place. A change lands at the
|
|
902
|
-
// repository root, so it can reach files above a subfolder workspace or protected
|
|
903
|
-
// metadata inside it; those prompt exactly where an Edit of them would. Inside the
|
|
904
|
-
// workspace, the modes that auto-approve workspace writes land without a prompt and
|
|
905
|
-
// audit the grant.
|
|
906
718
|
const files = prepared.landing.files;
|
|
719
|
+
const { classifyWorkspaceWrites } = await import('./tools.js');
|
|
907
720
|
const { outside, protected: protectedPaths } = await classifyWorkspaceWrites(ctx.workspace, prepared.landing.root, files);
|
|
908
721
|
const automatic = () => !outside.length && !protectedPaths.length && ['ask-for-approval', 'approve-for-me'].includes(permissionMode(ctx) ?? '');
|
|
909
722
|
while (!(asked && files.every(file => granted.has(file)))) {
|
|
@@ -918,21 +731,14 @@ export async function executeAgentNode(node, options) {
|
|
|
918
731
|
}
|
|
919
732
|
await ctx.onApprovalEvent?.('node.tool.approval.requested', { name: 'accept_change', arguments: { id: change.id, files }, mode: 'workspace-policy' });
|
|
920
733
|
await ctx.onApprovalEvent?.('node.tool.approval.decided', { name: 'accept_change', mode: 'workspace-policy', approved: true, actor: 'workspace-policy' });
|
|
921
|
-
// The audit hooks can yield to a live permission change; a policy grant holds only
|
|
922
|
-
// while the policy that gave it is still the live one.
|
|
923
734
|
assertPlanMutationAllowed(ctx);
|
|
924
735
|
if (automatic())
|
|
925
736
|
break;
|
|
926
737
|
}
|
|
927
738
|
ctx.signal.throwIfAborted();
|
|
928
739
|
assertPlanMutationAllowed(ctx);
|
|
929
|
-
// The review record (Keep / Undo) keeps what each landed path holds before the patch writes or
|
|
930
|
-
// removes it, the same way an Edit's write is recorded, and holds its lock while the patch is applied
|
|
931
|
-
// so an Undo cannot interleave with the landing. A landing that does not land records nothing.
|
|
932
740
|
const recording = ctx.fileChanges ? await ctx.fileChanges.beforeWrite(files.map(file => join(prepared.landing.root, ...file.split('/')))).catch(() => undefined) : undefined;
|
|
933
741
|
const locked = recording ? await recording.begin().then(() => true, () => false) : false;
|
|
934
|
-
// The lock can wait behind an Undo; a stop or a switch to Plan mode in that wait still decides, and
|
|
935
|
-
// is refused exactly as it is just above, with the lock given back.
|
|
936
742
|
try {
|
|
937
743
|
ctx.signal.throwIfAborted();
|
|
938
744
|
assertPlanMutationAllowed(ctx);
|
|
@@ -984,44 +790,32 @@ export async function executeAgentNode(node, options) {
|
|
|
984
790
|
},
|
|
985
791
|
};
|
|
986
792
|
tools = tools.map(requirePublishedPlan);
|
|
987
|
-
// The manager applies provider-specific bounds to its decision snapshot.
|
|
988
793
|
const decisionRoles = tools.some(tool => tool.name === 'spawn_subagent')
|
|
989
794
|
? (policy.roles ?? []).map(role => role.id) : [];
|
|
990
795
|
const systemPrompt = [orchestrator && depth === 0 ? ORCHESTRATOR_INSTRUCTIONS : '', orchestrator && depth === 0 && delegationActive ? DELEGATION_INSTRUCTIONS : '', configured.systemPrompt ?? configured.prompt ?? ''].filter(Boolean).join('\n\n');
|
|
991
|
-
// The nodes that can run after this one, and the QA guidance this node can act on. A node whose
|
|
992
|
-
// work is sure to reach a testing node is told so and leaves the running-app testing to it: told
|
|
993
|
-
// only to verify, an implementation node scripted clicks into the user's own window. The check
|
|
994
|
-
// is on the graph node's routes, so a delegated child answers to its parent's: a writer whose
|
|
995
|
-
// work can be delivered straight to Done keeps its own running-app checks.
|
|
996
796
|
const graphNodeId = options.nodeId ?? node.id;
|
|
997
797
|
const laterNodes = options.graph ? laterAgentNodes(options.graph, graphNodeId) : [];
|
|
998
798
|
const routeTester = options.graph ? testerOnEveryRoute(options.graph, graphNodeId) : undefined;
|
|
999
799
|
const reachableTester = laterNodes.find(isTestingNode)?.name;
|
|
1000
800
|
const nodeInstructions = [options.instructions, qaGuidance({ tools: tools.map(tool => tool.name), laterTester: routeTester })].filter(Boolean).join('\n\n');
|
|
1001
|
-
const
|
|
1002
|
-
// Skills the node's own prompts name as `/name`. A delegated child runs a dispatched task, not
|
|
1003
|
-
// these prompts, so only the node itself reads them.
|
|
801
|
+
const requestedInheritedSkills = [...new Set(options.inheritedSkills ?? [])];
|
|
1004
802
|
const promptSkillNames = depth === 0 ? promptSkillReferences(configured.instruction, configured.systemPrompt ?? configured.prompt) : [];
|
|
1005
803
|
const canReadProjectSkills = ['Read', 'Glob', 'Grep', 'repo_explore'].some(name => permitsBuiltInTool(configured, name, commandScope));
|
|
1006
|
-
|
|
1007
|
-
// Inherited and prompt-named references still load even if ambient discovery is disabled.
|
|
1008
|
-
const discoverProjectSkills = canReadProjectSkills && (inheritedSkills.length > 0 || promptSkillNames.length > 0
|
|
804
|
+
const discoverProjectSkills = canReadProjectSkills && (requestedInheritedSkills.length > 0 || promptSkillNames.length > 0
|
|
1009
805
|
|| options.efficiency?.projectSkillDiscovery === true
|
|
1010
806
|
|| (options.efficiency?.projectSkillDiscovery !== false && options.decisionManager?.skillRoutingEnabled === true));
|
|
1011
807
|
const resourceReader = tools.find(tool => tool.name === 'read_skill_resource');
|
|
1012
|
-
const skills = discoverProjectSkills ||
|
|
808
|
+
const skills = discoverProjectSkills || requestedInheritedSkills.length > 0 || promptSkillNames.length > 0 || resourceReader || tools.some(tool => tool.name === 'qa.browser_session')
|
|
1013
809
|
? await discoverRuntimeSkills(context.workspace, context.signal, tools.map(tool => tool.name), discoverProjectSkills) : [];
|
|
1014
|
-
// A
|
|
1015
|
-
//
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
// reports it.
|
|
810
|
+
// A skill inherited from earlier nodes that this node cannot load (broken locally, or no skill
|
|
811
|
+
// reader among its tools) is left out for this node only; the run continues without it.
|
|
812
|
+
const inheritedSkills = requestedInheritedSkills.filter(id => {
|
|
813
|
+
const local = skills.find(skill => skill.id === id);
|
|
814
|
+
return local ? !local.unavailable : !!resourceReader;
|
|
815
|
+
});
|
|
1021
816
|
const promptSkills = [];
|
|
1022
817
|
const missingPromptSkills = [];
|
|
1023
818
|
for (const reference of promptSkillNames) {
|
|
1024
|
-
// `/skill::name` is the command of an installed skill whose name is a built-in command.
|
|
1025
819
|
const name = reference.startsWith('skill::') ? reference.slice('skill::'.length) : reference;
|
|
1026
820
|
let id;
|
|
1027
821
|
if (!skills.some(skill => skill.id === name)) {
|
|
@@ -1029,7 +823,7 @@ export async function executeAgentNode(node, options) {
|
|
|
1029
823
|
try {
|
|
1030
824
|
id = resourceReader.resolveSkillEntryId(name, 'SKILL.md');
|
|
1031
825
|
}
|
|
1032
|
-
catch {
|
|
826
|
+
catch { }
|
|
1033
827
|
}
|
|
1034
828
|
if (!id && options.installedSkillClaims?.(name)) {
|
|
1035
829
|
missingPromptSkills.push(reference);
|
|
@@ -1046,13 +840,6 @@ export async function executeAgentNode(node, options) {
|
|
|
1046
840
|
const list = missingPromptSkills.map(name => '/' + name).join(', ');
|
|
1047
841
|
await emit('graph.skill.missing', { skills: missingPromptSkills, text: `${configured.name ?? configured.id} names ${list}, which ${missingPromptSkills.length === 1 ? 'is' : 'are'} not available on this machine. The node runs without ${missingPromptSkills.length === 1 ? 'it' : 'them'}.` });
|
|
1048
842
|
}
|
|
1049
|
-
for (const id of inheritedSkills) {
|
|
1050
|
-
const local = skills.find(skill => skill.id === id);
|
|
1051
|
-
if (local?.unavailable)
|
|
1052
|
-
throw new Error(`Node ${configured.id}: inherited skill "${id}" is unavailable: ${local.unavailable}`);
|
|
1053
|
-
if (!local && !resourceReader)
|
|
1054
|
-
throw new Error(`Node ${configured.id}: inherited skill "${id}" cannot be loaded. Enable the skill reader or disable skill inheritance on this node.`);
|
|
1055
|
-
}
|
|
1056
843
|
const loadedSkills = new Set();
|
|
1057
844
|
const missingSkillError = () => {
|
|
1058
845
|
const missing = inheritedSkills.filter(id => !loadedSkills.has(id));
|
|
@@ -1066,48 +853,26 @@ export async function executeAgentNode(node, options) {
|
|
|
1066
853
|
loadedSkills.add(id);
|
|
1067
854
|
await options.onSkillActivated?.(id);
|
|
1068
855
|
}).map(requirePublishedPlan) : [];
|
|
1069
|
-
// Merge registered external resources into the same tool, without duplicate schemas.
|
|
1070
856
|
if (skillTools.length)
|
|
1071
857
|
tools = tools.filter(tool => tool.name !== 'read_skill_resource');
|
|
1072
858
|
const effectiveTask = typeof inputs.taskInstruction === 'string' && inputs.taskInstruction.trim() ? inputs.taskInstruction.trim() : task;
|
|
1073
859
|
const graphFirstSearch = depth === 0 && !!codeIntel?.active && codeGraphRoute(effectiveTask) === 'graph';
|
|
1074
860
|
const decisionTask = depth > 0 ? task : options.decisionPreflight?.task ?? effectiveTask;
|
|
1075
861
|
let result;
|
|
1076
|
-
// Every attempt's capture is folded here: a failed attempt whose result is discarded still
|
|
1077
|
-
// spent tokens and executed tools, and the run's totals must include them.
|
|
1078
862
|
const telemetry = createRunTelemetry();
|
|
1079
863
|
let attempts = depth === 0 ? configured.retry?.maxAttempts ?? 1 : 1;
|
|
1080
864
|
const efficiency = resolveEfficiency(options.efficiency);
|
|
1081
|
-
// Bounded facts about the workspace, collected once per node when a feature that reads them is
|
|
1082
|
-
// on; the runner may have collected them for the run already.
|
|
1083
865
|
const facts = depth === 0 && (efficiency.contextSelection || efficiency.catalogSelection)
|
|
1084
866
|
? options.workspaceFacts ?? await collectWorkspaceFacts(context.workspace, { signal: context.signal }) : undefined;
|
|
1085
|
-
// Adaptive routing state across attempts: the tier the attempt ran on, how often it escalated,
|
|
1086
|
-
// and what the failed attempt left behind, so a re-attempt inspects rather than repeats it.
|
|
1087
867
|
const nodeBaseline = { provider, model };
|
|
1088
868
|
let routedTier;
|
|
1089
869
|
let escalations = 0;
|
|
1090
870
|
let previousAttemptReason;
|
|
1091
|
-
// An escalation that was granted an attempt but could not move up (no higher tier configured, an
|
|
1092
|
-
// unresolvable target, the limit reached) closes the path: the loop never extends again on a tier
|
|
1093
|
-
// that already exhausted itself, so the node budget stays the bound it was before routing.
|
|
1094
871
|
let escalationPending = false;
|
|
1095
872
|
let escalationFailed = false;
|
|
1096
873
|
let previousMutations;
|
|
1097
|
-
// The plan the user approved in this invocation, if any. A retry starts a fresh conversation
|
|
1098
|
-
// that would otherwise inherit only the files: without carrying the approval forward, a
|
|
1099
|
-
// replacement model could implement the original request without the constraints the user
|
|
1100
|
-
// approved. Set by present_plan when its answer is the approval.
|
|
1101
874
|
let approvedPlan;
|
|
1102
|
-
// A retry rebuilds the conversation from the node task, so a message the user steered into the
|
|
1103
|
-
// failed attempt is not in it — and the engine's queue has already spliced it out. What each
|
|
1104
|
-
// attempt read is retained here and offered again to the next one; without that, the run would
|
|
1105
|
-
// finish under the instructions the message corrected while its transcript says it was read.
|
|
1106
875
|
const consumedSteers = [];
|
|
1107
|
-
// Ids of the changes that were still undecided when an attempt failed. A retry starts a fresh
|
|
1108
|
-
// conversation that has none of the failed attempt's spawn results, so it could not review
|
|
1109
|
-
// them, and completing as delivered requires every change decided: they are discarded before
|
|
1110
|
-
// the retry starts, and the retry is told so. Landed changes stay and still count.
|
|
1111
876
|
const discardedAtRetry = [];
|
|
1112
877
|
for (let attempt = 1; attempt <= attempts; attempt++) {
|
|
1113
878
|
context.signal.throwIfAborted();
|
|
@@ -1116,38 +881,22 @@ export async function executeAgentNode(node, options) {
|
|
|
1116
881
|
discardedAtRetry.push(change.id);
|
|
1117
882
|
if (attempt > 1 && configured.retry?.fallback)
|
|
1118
883
|
fallbackAttempt = true;
|
|
1119
|
-
// This invocation's identity for the caller's live-selection resolver: a delegated child is
|
|
1120
|
-
// `<node>/<role>`, and `#fallback` marks a pair continuing a retry's fallback.
|
|
1121
884
|
const liveNodeId = `${node.id}${subagentId ? '/' + configured.id : ''}${fallbackAttempt ? '#fallback' : ''}`;
|
|
1122
|
-
// Resolve the live pair before this attempt's window, transcript and request are built. The
|
|
1123
|
-
// runner froze the graph the run started on, so a node reached after a live model change
|
|
1124
|
-
// would otherwise judge the predecessor's transcript against the superseded pair, discard
|
|
1125
|
-
// it, and only then move to the model that produced it.
|
|
1126
885
|
const liveModel = await options.getLiveModel?.(liveNodeId, provider, model, context.signal);
|
|
1127
|
-
// A live selection is the user's explicit choice for this attempt, whatever it names.
|
|
1128
886
|
const liveSelected = liveModel !== undefined;
|
|
1129
887
|
if (liveModel && (liveModel.provider !== provider || liveModel.model !== model)) {
|
|
1130
888
|
provider = liveModel.provider;
|
|
1131
889
|
model = liveModel.model;
|
|
1132
890
|
resolved = liveModel;
|
|
1133
|
-
// The node's start line named the pair the frozen graph resolves: publish the pair that
|
|
1134
|
-
// actually answers so the rows and the live chip follow, as they do for a mid-node switch.
|
|
1135
891
|
await emit('agent.model.changed', { provider, model, ...(liveModel.contextWindow === undefined ? {} : { contextWindow: liveModel.contextWindow }), ...(subagentId ? { subagentId } : {}) });
|
|
1136
892
|
}
|
|
1137
893
|
else if (!subagentId) {
|
|
1138
|
-
// The window of the pair this attempt runs, published even though nothing changed. `run.context`
|
|
1139
|
-
// describes the session's pair, and for a graph whose every node pins its own provider that
|
|
1140
|
-
// snapshot is built without discovery — so a window only the endpoint reports (no saved
|
|
1141
|
-
// per-model entry) was known here, where the node resolved its model, and nowhere a client
|
|
1142
|
-
// could read it. An unknown window is published as unknown: the reading must not stay sized
|
|
1143
|
-
// against the pair another node ran.
|
|
1144
894
|
await emit('agent.model.resolved', { provider, model, ...(resolved.contextWindow === undefined ? {} : { contextWindow: resolved.contextWindow }) });
|
|
1145
895
|
}
|
|
1146
896
|
loadedSkills.clear();
|
|
1147
897
|
const retainedClarification = Boolean(orchestrator && depth === 0 && confirmedClarifications.length);
|
|
1148
|
-
let taskBase = `${task}${retainedClarification ? `\n\nConfirmed user clarification observations (retain these decisions across retries):\n${JSON.stringify(confirmedClarifications)}` : ''}\n\nNode instruction: ${configured.instruction ?? 'Complete the assigned task.'}
|
|
898
|
+
let taskBase = `${task}${retainedClarification ? `\n\nConfirmed user clarification observations (retain these decisions across retries):\n${JSON.stringify(confirmedClarifications)}` : ''}\n\nNode instruction: ${configured.instruction ?? 'Complete the assigned task.'}${MAPPED_INPUTS_HEADING}${inputText}${typeof inputs.taskInstruction === 'string' ? `\n\nTask instruction from handoff:\n${inputs.taskInstruction}` : ''}`;
|
|
1149
899
|
if (previousMutations?.length) {
|
|
1150
|
-
// The escalated attempt starts a fresh conversation; the files are the only state it inherits.
|
|
1151
900
|
taskBase += `\n\nA previous attempt on another model already changed these workspace files: ${JSON.stringify(previousMutations)}. Inspect them before changing them again and do not repeat work that is already done.`;
|
|
1152
901
|
}
|
|
1153
902
|
if (delegationActive && depth === 0 && attempt > 1) {
|
|
@@ -1159,9 +908,6 @@ export async function executeAgentNode(node, options) {
|
|
|
1159
908
|
}
|
|
1160
909
|
}
|
|
1161
910
|
if (approvedPlan !== undefined && permissionMode(context) !== 'plan') {
|
|
1162
|
-
// The approval granted editing permissions to this invocation, so the fresh attempt
|
|
1163
|
-
// implements the plan the user approved rather than reinterpreting the raw task. Still in
|
|
1164
|
-
// plan mode, the attempt must present again instead — the approval did not happen.
|
|
1165
911
|
taskBase += `\n\nThe user approved this plan in a previous attempt of this task; implement it as approved:\n${approvedPlan}`;
|
|
1166
912
|
}
|
|
1167
913
|
if (inheritedSkills.length) {
|
|
@@ -1182,28 +928,17 @@ export async function executeAgentNode(node, options) {
|
|
|
1182
928
|
}
|
|
1183
929
|
let attemptPrompt = retainedClarification ? `${systemPrompt}\n\n${RETAINED_CLARIFICATION_INSTRUCTION}` : systemPrompt;
|
|
1184
930
|
const executionLimits = mergeLimits(configured, depth ? { ...limits, wallTimeMs: configured.limits?.wallTimeMs } : limits);
|
|
1185
|
-
// The initial model's smaller window must not become the permanent character ceiling:
|
|
1186
|
-
// a later live selection can increase it again, up to this configured node limit.
|
|
1187
931
|
const contextCharCeiling = executionLimits.maxContextChars;
|
|
1188
932
|
const window = resolved.contextWindow;
|
|
1189
933
|
if (window !== undefined && Number.isSafeInteger(window) && window > 0)
|
|
1190
934
|
executionLimits.maxContextChars = Math.min(executionLimits.maxContextChars, window * 3);
|
|
1191
935
|
let attemptRepoBlock = '';
|
|
1192
|
-
// Room left for repository context, under two ceilings (the same pair the skill catalog uses,
|
|
1193
|
-
// see `skillContextBudget`). `repoBudget` is what the whole request can still hold: it counts
|
|
1194
|
-
// the tool schemas, and gets them back when routing trims the catalog. `repoPolicyRoom` is what
|
|
1195
|
-
// the node's context policy still allows the node to be handed to read, which the tool schemas
|
|
1196
|
-
// are not part of. Charging the schemas to the policy left a node with the full tool set a
|
|
1197
|
-
// negative budget before its task was read, so it never received repository context.
|
|
1198
936
|
let repoBudget = 0;
|
|
1199
937
|
let repoPolicyRoom = 0;
|
|
1200
938
|
const repoRoom = () => Math.min(repoBudget, repoPolicyRoom);
|
|
1201
939
|
const spendRepoRoom = (chars) => { repoBudget -= chars; repoPolicyRoom -= chars; };
|
|
1202
940
|
let committedChars = 0;
|
|
1203
941
|
if (depth === 0 && codeLedger && codeIntel) {
|
|
1204
|
-
// Budget the rendered turn, not its stored `task`: the seed the request actually carries expands
|
|
1205
|
-
// a continued turn's direction into the message (`turnModelTask`), and budgeting less than the
|
|
1206
|
-
// request sends would let the repository block be sized into an over-window prompt.
|
|
1207
942
|
const historyChars = configured.contextPolicy?.history ? (options.history ?? []).reduce((sum, item) => sum + turnModelTask(item).length + JSON.stringify(item.completion).length, 0) : 0;
|
|
1208
943
|
const toolSchemaChars = JSON.stringify(tools.map(tool => ({ name: tool.name, description: tool.description, parameters: tool.parameters }))).length;
|
|
1209
944
|
const contractChars = JSON.stringify({ outputSchema: configured.outputSchema, completion: configured.completion }).length;
|
|
@@ -1216,8 +951,6 @@ export async function executeAgentNode(node, options) {
|
|
|
1216
951
|
let attemptTools = tools;
|
|
1217
952
|
const initialPromptChars = attemptPrompt.length;
|
|
1218
953
|
let recoverTools;
|
|
1219
|
-
// These values are pinned in the executor request. Count their serialized
|
|
1220
|
-
// representation (including nested JSON escaping), not only task text.
|
|
1221
954
|
const skillContextBudget = () => {
|
|
1222
955
|
const pinned = [taskBase, attemptPrompt, nodeInstructions,
|
|
1223
956
|
JSON.stringify(configured.outputSchema ?? { type: 'object' }),
|
|
@@ -1230,16 +963,7 @@ export async function executeAgentNode(node, options) {
|
|
|
1230
963
|
const schemaChars = JSON.stringify([...attemptTools, completionTool({ ...options, completionPolicy, outputSchema: configured.outputSchema })]
|
|
1231
964
|
.map(({ name, description, parameters }) => ({ name, description, parameters }))).length
|
|
1232
965
|
+ JSON.stringify((recoverTools ?? []).filter(tool => !attemptTools.includes(tool)).map(tool => tool.name)).length;
|
|
1233
|
-
// Reserve executor instructions, message wrappers and the skill reference wrapper before
|
|
1234
|
-
// allocating optional content.
|
|
1235
966
|
const fixedChars = JSON.stringify(pinned).length + historyChars + 8300;
|
|
1236
|
-
// Two different ceilings, and the tool schemas count against only one of them. The node's
|
|
1237
|
-
// context policy bounds what the node is handed to read (its task, mapped inputs, history and
|
|
1238
|
-
// optional references such as this catalog); the tool schemas are sent whatever that policy
|
|
1239
|
-
// says and, for a node with the full tool set, are about as large as the default policy on
|
|
1240
|
-
// their own. Charging them to the policy left the catalog no room on exactly those nodes, so
|
|
1241
|
-
// an agent with every tool was never told which skills exist. The execution limit is the
|
|
1242
|
-
// real bound on the whole request (it follows the model's window), so the schemas count there.
|
|
1243
967
|
const policyRoom = contextChars - fixedChars;
|
|
1244
968
|
const requestRoom = executionLimits.maxContextChars - fixedChars - schemaChars;
|
|
1245
969
|
return Math.max(0, Math.min(8000, policyRoom, requestRoom));
|
|
@@ -1247,10 +971,6 @@ export async function executeAgentNode(node, options) {
|
|
|
1247
971
|
let memoryBlockAdded = false;
|
|
1248
972
|
let pendingMemoryApplication;
|
|
1249
973
|
let pendingGraphApplication;
|
|
1250
|
-
// The single layer that counts decision events into this invocation's capture. Both stages
|
|
1251
|
-
// publish through it: the preflight manager through the sink below, the post-tool check
|
|
1252
|
-
// through the executor's event path. Counting at a stage callback as well would double the
|
|
1253
|
-
// counters once the runtime's capture is merged in.
|
|
1254
974
|
const recordDecision = (event) => {
|
|
1255
975
|
if (event.type.startsWith('decision.'))
|
|
1256
976
|
recordDecisionEvent(telemetry, event.type, event.data);
|
|
@@ -1266,17 +986,12 @@ export async function executeAgentNode(node, options) {
|
|
|
1266
986
|
repository: { codeGraphAvailable: depth === 0 && !!codeIntel?.active && repoRoom() >= 512 && allowsGraphRouting(effectiveTask), memoryAvailable: decisionManager.active ? depth === 0 && configured.agentRole !== 'orchestrator' && !!options.memory?.activeFor(options.runId) && options.memory.automaticRetrieval : (depth === 0 ? options.decisionPreflight?.memoryAvailable : undefined) ?? options.memory?.activeFor(options.runId) ?? false },
|
|
1267
987
|
capabilities: { toolFamilies: toolFamilies(tools), subagentRoles: decisionRoles, ...(skills.length ? { skills: skills.filter(skill => !skill.unavailable).map(({ id, description }) => ({ id, description })) } : {}) },
|
|
1268
988
|
run: depth === 0 && options.modifierIteration !== undefined ? { iteration: options.modifierIteration } : {},
|
|
1269
|
-
// Host-only consumer eligibility; the manager removes this before egress.
|
|
1270
989
|
consumers: { answerOnly: answerOnlyTask(decisionTask),
|
|
1271
990
|
adaptiveRouting: attempt === 1 && depth === 0 && !subagentId && !fallbackAttempt
|
|
1272
991
|
&& configured.provider === undefined && configured.model === undefined && !options.modelPinned && !liveSelected
|
|
1273
992
|
&& hasAdaptiveAlternative(efficiency.adaptiveRouting, nodeBaseline, options.configuredModels ?? []),
|
|
1274
993
|
},
|
|
1275
994
|
}, { runId: options.runId, nodeId: configured.id, invocationId: randomUUID() }, { codeGraph: depth === 0 && !!codeIntel?.active && repoRoom() >= 512 && codeGraphRoute(effectiveTask) === 'graph', memory: depth === 0 && (options.decisionPreflight?.memory ?? (configured.agentRole !== 'orchestrator' && !!options.memory?.activeFor(options.runId) && options.memory.automaticRetrieval)) }, signal, event => {
|
|
1276
|
-
// The decision manager publishes through this sink, not through the runtime's own event
|
|
1277
|
-
// helper. The sink forwards to the caller's `onEvent`, which is the unwrapped one: the
|
|
1278
|
-
// runtime wraps only the options object it is given, so these events would otherwise
|
|
1279
|
-
// never reach the capture this invocation returns.
|
|
1280
995
|
if (signal.aborted)
|
|
1281
996
|
return;
|
|
1282
997
|
return recordDecision(event);
|
|
@@ -1300,16 +1015,12 @@ export async function executeAgentNode(node, options) {
|
|
|
1300
1015
|
return preflight(signal);
|
|
1301
1016
|
});
|
|
1302
1017
|
else {
|
|
1303
|
-
// A shadow answer may arrive after the node returns; the finish waits for it so the
|
|
1304
|
-
// request and its terminal events are counted together.
|
|
1305
1018
|
const shadow = preflight(context.runControl ? AbortSignal.any([context.signal, context.runControl.signal]) : context.signal);
|
|
1306
1019
|
(telemetry.pendingDecisions ??= []).push(shadow.catch(() => undefined));
|
|
1307
1020
|
void shadow.catch(() => undefined);
|
|
1308
1021
|
}
|
|
1309
1022
|
}
|
|
1310
1023
|
context.signal.throwIfAborted();
|
|
1311
|
-
// Facts settle what no decision needs to: an empty workspace has no source to explore and no
|
|
1312
|
-
// repository history to recall, so neither retrieval is attempted.
|
|
1313
1024
|
let retrievalSkipped = false;
|
|
1314
1025
|
if (efficiency.contextSelection && depth === 0 && facts?.empty && (codeIntel || options.memory?.activeFor(options.runId))) {
|
|
1315
1026
|
retrievalSkipped = true;
|
|
@@ -1317,11 +1028,6 @@ export async function executeAgentNode(node, options) {
|
|
|
1317
1028
|
activeRouting = { ...activeRouting, codeGraph: false, memory: false };
|
|
1318
1029
|
await emitEfficiency('efficiency.context.retrieval_skipped', { reason: 'empty_workspace' });
|
|
1319
1030
|
}
|
|
1320
|
-
// Adaptive model-tier routing, decided once per attempt before this attempt's conversation
|
|
1321
|
-
// is built. Explicit choices (a node pin, a run pin, a live selection) are never overridden;
|
|
1322
|
-
// uncertainty keeps the baseline; a target the configuration cannot resolve keeps it too.
|
|
1323
|
-
// A retry that the node's own `retry.fallback` serves is an explicit choice, so routing does not
|
|
1324
|
-
// move it back to the tier that just failed; an escalation retry is routing's own move.
|
|
1325
1031
|
const explicitFallbackRetry = attempt > 1 && configured.retry?.fallback !== undefined && !escalationPending;
|
|
1326
1032
|
if (efficiency.adaptiveRouting.enabled && depth === 0 && !subagentId && explicitFallbackRetry) {
|
|
1327
1033
|
await emitEfficiency('efficiency.routing.decided', { tier: undefined, reason: 'pinned', evidence: 'pinned', applied: false, attempt });
|
|
@@ -1335,10 +1041,6 @@ export async function executeAgentNode(node, options) {
|
|
|
1335
1041
|
});
|
|
1336
1042
|
let applied = false;
|
|
1337
1043
|
let unresolved = false;
|
|
1338
|
-
// `served` is what routing needs: the attempt ran on the decision's resolved target — either
|
|
1339
|
-
// because routing moved the model onto it or because that target already was the model in
|
|
1340
|
-
// use. `applied` stays "the model changed"; a tier naming the baseline model is not a
|
|
1341
|
-
// change, but it is still the tier that served, and the escalation climbs from it.
|
|
1342
1044
|
let served = false;
|
|
1343
1045
|
if (decision.target) {
|
|
1344
1046
|
const target = decision.target;
|
|
@@ -1358,8 +1060,6 @@ export async function executeAgentNode(node, options) {
|
|
|
1358
1060
|
served = true;
|
|
1359
1061
|
const routedWindow = routed.contextWindow;
|
|
1360
1062
|
executionLimits.maxContextChars = routedWindow !== undefined && Number.isSafeInteger(routedWindow) && routedWindow > 0 ? Math.min(contextCharCeiling, routedWindow * 3) : contextCharCeiling;
|
|
1361
|
-
// The repository budget was sized against the baseline window; the routed window is what
|
|
1362
|
-
// this attempt actually has, and retrieval must not fill what no longer fits.
|
|
1363
1063
|
if (depth === 0 && codeLedger && codeIntel)
|
|
1364
1064
|
repoBudget = executionLimits.maxContextChars - committedChars;
|
|
1365
1065
|
await emit('agent.model.changed', { provider, model, ...(routedWindow === undefined ? {} : { contextWindow: routedWindow }), tier: decision.tier });
|
|
@@ -1372,9 +1072,6 @@ export async function executeAgentNode(node, options) {
|
|
|
1372
1072
|
}
|
|
1373
1073
|
}
|
|
1374
1074
|
}
|
|
1375
|
-
// Only a tier whose resolved target served this attempt counts as routed: a decision without
|
|
1376
|
-
// a target (the tier is not configured) or one that could not resolve leaves the attempt on
|
|
1377
|
-
// what it had, and an escalation can only climb from a tier that actually ran.
|
|
1378
1075
|
if (served)
|
|
1379
1076
|
routedTier = decision.tier;
|
|
1380
1077
|
if (decision.reason === 'escalated' && applied)
|
|
@@ -1386,15 +1083,11 @@ export async function executeAgentNode(node, options) {
|
|
|
1386
1083
|
}
|
|
1387
1084
|
await emitEfficiency('efficiency.routing.decided', { tier: decision.tier, reason: unresolved ? 'unconfigured' : decision.reason, evidence: decision.evidence, applied, served, attempt });
|
|
1388
1085
|
}
|
|
1389
|
-
// The transcript this attempt will inherit, if any: the engine reuses a predecessor's
|
|
1390
|
-
// conversation only on the same provider and model (see its `previousConversation` guard).
|
|
1391
1086
|
const inheritedConversation = depth === 0 && configured.contextPolicy?.conversation !== 'isolate' && configured.contextPolicy?.skillInheritance !== 'none'
|
|
1392
1087
|
&& options.previousConversation?.provider === provider && options.previousConversation.model === model ? options.previousConversation : undefined;
|
|
1393
1088
|
const historicalToolNames = [...new Set((inheritedConversation?.messages ?? []).flatMap(message => (message.toolCalls ?? []).map(call => call.name)))];
|
|
1394
|
-
/** The skill catalog entry list, ordered and bounded under catalog selection, whole or absent otherwise. */
|
|
1395
1089
|
const skillCatalogText = (budget) => {
|
|
1396
1090
|
if (!efficiency.catalogSelection) {
|
|
1397
|
-
// The shipped all-or-nothing catalog; the callers' own budget checks decide as before.
|
|
1398
1091
|
const all = JSON.stringify(skills.map(({ id, description, unavailable }) => ({ id, description, ...(unavailable ? { unavailable } : {}) })));
|
|
1399
1092
|
return JSON.stringify(all).length <= budget ? all : undefined;
|
|
1400
1093
|
}
|
|
@@ -1405,8 +1098,6 @@ export async function executeAgentNode(node, options) {
|
|
|
1405
1098
|
if (activeRouting?.decisions) {
|
|
1406
1099
|
const decisions = activeRouting.decisions;
|
|
1407
1100
|
recoverTools = [...tools, ...skillTools];
|
|
1408
|
-
// Facts style keeps every permitted schema: a wrongly omitted tool costs a restore_tools turn,
|
|
1409
|
-
// more than the schemas it would save over a whole run.
|
|
1410
1101
|
attemptTools = options.decisionManager?.toolTrimmingEnabled === false ? [...recoverTools] : routeToolFamilies(recoverTools, decisions);
|
|
1411
1102
|
if (inheritedSkills.length) {
|
|
1412
1103
|
const loader = skillTools.find(tool => tool.name === 'Skill');
|
|
@@ -1414,8 +1105,6 @@ export async function executeAgentNode(node, options) {
|
|
|
1414
1105
|
attemptTools.push(loader);
|
|
1415
1106
|
}
|
|
1416
1107
|
if (efficiency.catalogSelection) {
|
|
1417
|
-
// A tool the inherited transcript already called keeps its schema: providers that validate
|
|
1418
|
-
// historical tool calls against the catalog would otherwise reject the request.
|
|
1419
1108
|
for (const name of historicalToolNames) {
|
|
1420
1109
|
const historical = recoverTools.find(tool => tool.name === name);
|
|
1421
1110
|
if (historical && !attemptTools.some(tool => tool.name === name))
|
|
@@ -1442,8 +1131,6 @@ export async function executeAgentNode(node, options) {
|
|
|
1442
1131
|
attemptPrompt += `\n\nSome already-permitted tool schemas were omitted to reduce context: ${JSON.stringify(omitted.map(tool => tool.name))}. If task evidence requires one, call restore_tools with its name in the names array, then call the restored tool normally. Restoration never grants new permissions or bypasses approvals.`;
|
|
1443
1132
|
const skillBudget = skillContextBudget();
|
|
1444
1133
|
let skillBlock = '';
|
|
1445
|
-
// Keep the routed identifier ahead of the optional catalog: a large
|
|
1446
|
-
// catalog must not erase a confident selection. Bodies stay tool-loaded.
|
|
1447
1134
|
const selectedSkill = options.decisionManager?.skillRoutingEnabled
|
|
1448
1135
|
? skills.find(skill => !skill.unavailable && skill.id === DecisionPolicy.choice(decisions, 'skill_role')) : undefined;
|
|
1449
1136
|
if (selectedSkill && attemptTools.some(tool => tool.name === 'Skill')) {
|
|
@@ -1473,7 +1160,6 @@ export async function executeAgentNode(node, options) {
|
|
|
1473
1160
|
}
|
|
1474
1161
|
}
|
|
1475
1162
|
else if (skillTools.length) {
|
|
1476
|
-
// Decision failure or uncertainty must leave the bounded catalog accessible.
|
|
1477
1163
|
attemptTools = [...tools, ...skillTools];
|
|
1478
1164
|
const catalog = skillCatalogText(skillContextBudget());
|
|
1479
1165
|
if (catalog !== undefined) {
|
|
@@ -1489,18 +1175,11 @@ export async function executeAgentNode(node, options) {
|
|
|
1489
1175
|
}
|
|
1490
1176
|
}
|
|
1491
1177
|
}
|
|
1492
|
-
// Plan-mode guidance is mandatory even without Jev decisions (disabled, signed out,
|
|
1493
|
-
// or no routing result). The tool is always available, but does not announce the mode.
|
|
1494
1178
|
if (depth === 0 && permissionMode(bounded) === 'plan')
|
|
1495
1179
|
attemptPrompt += `\n\n${PLAN_MODE_INSTRUCTIONS}`;
|
|
1496
1180
|
if (efficiency.catalogSelection && depth === 0) {
|
|
1497
|
-
// Deterministic, task-appropriate catalog from the permitted tools. Everything omitted stays
|
|
1498
|
-
// restorable through restore_tools under the same permission checks; nothing is added.
|
|
1499
1181
|
const selection = selectToolCatalog({ tools: attemptTools, task: effectiveTask, facts, explicitTools: configured.tools, historicalToolNames,
|
|
1500
1182
|
codeGraphAvailable: !!codeIntel?.active, memoryAvailable: !!options.memory?.activeFor(options.runId) });
|
|
1501
|
-
// Omission is applied only when it saves more than it costs: the omitted names are listed
|
|
1502
|
-
// in the prompt and `restore_tools` joins the catalog (about 420 serialized characters), so
|
|
1503
|
-
// dropping one small schema would make the request larger, not smaller.
|
|
1504
1183
|
const note = `\n\nSome already-permitted tool schemas were omitted for this task: ${JSON.stringify(selection.omitted.map(tool => tool.name))}. If task evidence requires one, call restore_tools with its name in the names array, then call the restored tool normally. Restoration never grants new permissions or bypasses approvals.`;
|
|
1505
1184
|
const saved = selection.schemaCharsBefore - selection.schemaCharsAfter;
|
|
1506
1185
|
const applied = selection.omitted.length > 0 && saved > note.length + RESTORE_TOOL_SCHEMA_CHARS;
|
|
@@ -1514,7 +1193,14 @@ export async function executeAgentNode(node, options) {
|
|
|
1514
1193
|
}
|
|
1515
1194
|
await emitEfficiency('efficiency.catalog.selected', { omitted: applied ? selection.omitted.length : 0, candidates: selection.omitted.length, schemaCharsBefore: selection.schemaCharsBefore, schemaCharsAfter: applied ? selection.schemaCharsAfter : selection.schemaCharsBefore, reasons: applied ? Object.values(selection.reasons).sort() : [], ...(selection.omitted.length && !applied ? { skipped: 'no_benefit' } : {}) });
|
|
1516
1195
|
}
|
|
1517
|
-
if (graphFirstSearch) {
|
|
1196
|
+
if (graphFirstSearch && headlessRun) {
|
|
1197
|
+
const repoExplore = tools.find(tool => tool.name === 'repo_explore');
|
|
1198
|
+
if (repoExplore && !attemptTools.some(tool => tool.name === 'repo_explore'))
|
|
1199
|
+
attemptTools.push(repoExplore);
|
|
1200
|
+
if (attemptTools.some(tool => tool.name === 'repo_explore'))
|
|
1201
|
+
attemptPrompt += '\n\nRepository search: repo_explore (CodeGraph) answers questions about structure, callers and data flow and returns source. Grep finds exact text. Both are available; use whichever fits the question.';
|
|
1202
|
+
}
|
|
1203
|
+
else if (graphFirstSearch) {
|
|
1518
1204
|
const fallbackSearch = attemptTools.filter(tool => canonicalToolName(tool.name) === 'Grep');
|
|
1519
1205
|
if (fallbackSearch.length) {
|
|
1520
1206
|
const beforeGraphFirst = [...attemptTools];
|
|
@@ -1531,29 +1217,21 @@ export async function executeAgentNode(node, options) {
|
|
|
1531
1217
|
}
|
|
1532
1218
|
if (codeLedger && codeIntel) {
|
|
1533
1219
|
const schemaSize = (catalog) => JSON.stringify(catalog.map(({ name, description, parameters }) => ({ name, description, parameters }))).length;
|
|
1534
|
-
// Trimmed schemas give room back to the request only; prompt growth is charged to both.
|
|
1535
1220
|
repoBudget += schemaSize(tools) - schemaSize(attemptTools);
|
|
1536
1221
|
spendRepoRoom(attemptPrompt.length - initialPromptChars);
|
|
1537
1222
|
}
|
|
1538
1223
|
if (activeRouting?.memory && depth === 0 && configured.agentRole !== 'orchestrator' && options.memory?.activeFor(options.runId) && options.memory.automaticRetrieval) {
|
|
1539
|
-
// Baseline retrieval used to precede node clocks. Keep fallback retrieval
|
|
1540
|
-
// exempt from those clocks, while retaining run deadlines and cancellation.
|
|
1541
1224
|
const resume = !pendingMemoryApplication ? suspendMemoryBudget?.() : undefined;
|
|
1542
1225
|
try {
|
|
1543
1226
|
context.signal.throwIfAborted();
|
|
1544
1227
|
const memory = await retryReadOnly(context, signal => options.memory.retrieve({ task: options.decisionPreflight?.task ?? effectiveTask, nodeId: configured.id, runId: options.runId, signal }));
|
|
1545
1228
|
let memoryBlock = memory.block;
|
|
1546
1229
|
if (efficiency.contextSelection && memoryBlock) {
|
|
1547
|
-
// Memory entries are untrusted evidence ranked by what they share with the task; the
|
|
1548
|
-
// omitted ones are named so memory_search can fetch them. Nothing is reworded.
|
|
1549
1230
|
const items = [...memory.context.current, ...(memory.context.historical ?? [])];
|
|
1550
1231
|
const selection = selectContext(items.map(item => ({ id: item.id, kind: 'memory', content: `${item.title}\n${item.content}`, item })), { task: effectiveTask, maxChars: Number.MAX_SAFE_INTEGER });
|
|
1551
|
-
// Selection decides relevance only; the character budget stays with the block builder, which
|
|
1552
|
-
// clips an oversized entry into a bounded excerpt the way the unselected block already does.
|
|
1553
1232
|
if (selection.omitted.length) {
|
|
1554
1233
|
const selected = new Set(selection.selected.map(candidate => candidate.item));
|
|
1555
1234
|
const rebuilt = buildMemoryBlock({ current: memory.context.current.filter(item => selected.has(item)), historical: (memory.context.historical ?? []).filter(item => selected.has(item)) }, memoryBlock.length);
|
|
1556
|
-
// The note survives even when nothing was kept: what was retrieved and set aside stays recoverable.
|
|
1557
1235
|
memoryBlock = rebuilt ? `${rebuilt}\n${omittedContextNote(selection.omitted, 'memory_search')}` : omittedContextNote(selection.omitted, 'memory_search');
|
|
1558
1236
|
}
|
|
1559
1237
|
await emitEfficiency('efficiency.context.selected', { source: 'memory', candidates: items.length, selected: selection.selected.length, omitted: selection.omitted.length,
|
|
@@ -1582,9 +1260,6 @@ export async function executeAgentNode(node, options) {
|
|
|
1582
1260
|
}
|
|
1583
1261
|
if (depth === 0 && codeIntel && codeLedger) {
|
|
1584
1262
|
let repoSelection;
|
|
1585
|
-
// Content-level selection among the files the graph returned: identifier overlap with the
|
|
1586
|
-
// task, with every kept file's dependencies kept too. Only structured results (per-file
|
|
1587
|
-
// content) are selected; unstructured provider text is injected as before.
|
|
1588
1263
|
const selectRepository = efficiency.contextSelection ? (found) => {
|
|
1589
1264
|
if (found.files.length < 2 || found.files.some(file => file.content === undefined))
|
|
1590
1265
|
return found;
|
|
@@ -1607,18 +1282,18 @@ export async function executeAgentNode(node, options) {
|
|
|
1607
1282
|
}
|
|
1608
1283
|
}
|
|
1609
1284
|
if (graphFirstSearch && !attemptRepoBlock) {
|
|
1610
|
-
// Automatic graph lookup either could not fit or did not provide
|
|
1611
|
-
// usable context. Enable textual fallback in this same coding-model
|
|
1612
|
-
// turn instead of spending another turn discovering that fact.
|
|
1613
1285
|
codeLedger.markExhausted();
|
|
1614
1286
|
const catalog = recoverTools ?? tools;
|
|
1615
1287
|
for (const fallback of catalog.filter(tool => canonicalToolName(tool.name) === 'Grep')) {
|
|
1616
1288
|
if (!attemptTools.some(tool => tool.name === fallback.name))
|
|
1617
1289
|
attemptTools.push(fallback);
|
|
1618
1290
|
}
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1291
|
+
const stillIndexing = repoRoom() >= 512 && (await codeIntel.getStatus().catch(() => undefined))?.state === 'indexing';
|
|
1292
|
+
attemptPrompt += stillIndexing
|
|
1293
|
+
? '\n\nCodeGraph is still indexing this repository, so no repository context was preloaded. Grep is available now. repo_explore usually becomes ready within seconds; use it once it answers.'
|
|
1294
|
+
: repoRoom() >= 512
|
|
1295
|
+
? '\n\nCodeGraph did not return usable context for this task, so canonical Grep fallback is enabled for this invocation.'
|
|
1296
|
+
: '\n\nThe node context budget has no room for CodeGraph source injection, so canonical Grep fallback is enabled for this invocation.';
|
|
1622
1297
|
}
|
|
1623
1298
|
}
|
|
1624
1299
|
if (pendingGraphApplication) {
|
|
@@ -1628,13 +1303,9 @@ export async function executeAgentNode(node, options) {
|
|
|
1628
1303
|
} };
|
|
1629
1304
|
void publish(event);
|
|
1630
1305
|
}
|
|
1631
|
-
// Finalization resumes the same conversation; a provider retry still starts
|
|
1632
|
-
// fresh and must gather its own research evidence.
|
|
1633
1306
|
observedResearch = Boolean(attemptRepoBlock) || (depth === 0 && attempt === 1 && !!retainedIntake?.observedResearch);
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
// the same attempt see only what the engine newly queued. Replaying keeps the list intact, so
|
|
1637
|
-
// a third attempt still sees what the first one read and the second one replayed.
|
|
1307
|
+
attemptTools = applyToolProfile(attemptTools, options.toolProfile);
|
|
1308
|
+
const engineRecoverTools = applyToolProfile([...(recoverTools ?? []), ...compatibilityRecoverTools.filter(tool => !(recoverTools ?? []).some(current => current.name === tool.name))], options.toolProfile);
|
|
1638
1309
|
let replaying = attempt > 1 && consumedSteers.length > 0;
|
|
1639
1310
|
const steeringSource = options.getSteeringMessages;
|
|
1640
1311
|
const steeringForAttempt = steeringSource === undefined ? undefined : async (signal) => {
|
|
@@ -1646,7 +1317,6 @@ export async function executeAgentNode(node, options) {
|
|
|
1646
1317
|
return [...replay, ...fresh];
|
|
1647
1318
|
};
|
|
1648
1319
|
result = await createAgentEngine().execute({ ...options, instructions: nodeInstructions || undefined, todoStore, context, provider, model,
|
|
1649
|
-
// Graph Manager's chat edits graphs on the user's behalf; a task plan is noise in its conversation.
|
|
1650
1320
|
todoList: options.todoList !== false && options.graph?.id !== GRAPH_MANAGER_GRAPH_ID,
|
|
1651
1321
|
efficiency: configured.tools && options.efficiency?.toolMenuRouting
|
|
1652
1322
|
? { ...options.efficiency, toolMenuRouting: { ...options.efficiency.toolMenuRouting, pinnedTools: [...new Set([...(options.efficiency.toolMenuRouting.pinnedTools ?? []), ...configured.tools.map(canonicalToolName)])] } }
|
|
@@ -1655,24 +1325,21 @@ export async function executeAgentNode(node, options) {
|
|
|
1655
1325
|
adapter: resolved.adapter, contextWindow: resolved.contextWindow, tools: attemptTools, recoverTools: engineRecoverTools, decisionTask,
|
|
1656
1326
|
telemetryIdentity: { providerType: resolved.providerType, baseUrl: resolved.baseUrl, role: subagentId ? 'subagent' : orchestrator ? 'orchestrator' : 'agent' }, decisionHints: activeRouting?.decisions, budget, artifactStore: store,
|
|
1657
1327
|
previousConversation: depth === 0 && configured.contextPolicy?.conversation !== 'isolate' && configured.contextPolicy?.skillInheritance !== 'none' && options.previousConversation?.provider === provider && options.previousConversation.model === model ? options.previousConversation : undefined,
|
|
1658
|
-
// The inner callback is returned rather than called and dropped: the durable write it
|
|
1659
|
-
// performs is awaited by the runtime, so the promise has to travel back up through here.
|
|
1660
1328
|
onConversationCheckpoint: depth === 0 && options.onConversationCheckpoint ? (messages, state, conversation) => options.onConversationCheckpoint(messages, { ...state, ...(orchestrator ? { orchestratorIntake: {
|
|
1661
1329
|
nodeId: node.id, clarified, publishedPlan, observedResearch,
|
|
1662
1330
|
confirmedClarifications: structuredClone(confirmedClarifications),
|
|
1663
1331
|
} } : {}) }, conversation) : undefined,
|
|
1664
1332
|
onTodosUpdated: orchestrator && depth === 0 ? () => { publishedPlan = true; options.onTodosUpdated?.(); } : options.onTodosUpdated,
|
|
1665
1333
|
subagentId, limits: executionLimits, contextCharCeiling, systemPrompt: attemptPrompt, nodeInstruction: configured.instruction,
|
|
1666
|
-
// A user steer belongs to the root attempt the user is watching. A delegated
|
|
1667
|
-
// subagent owns a dispatched task, so letting it consume the steer would apply the
|
|
1668
|
-
// instruction to the wrong agent and lose it from the root conversation.
|
|
1669
1334
|
getSteeringMessages: subagentId ? undefined : steeringForAttempt,
|
|
1670
|
-
// Attachments belong to the conversation the user submitted into: a dispatched
|
|
1671
|
-
// subagent's task is its own opening message, and the root's files and images would
|
|
1672
|
-
// silently answer questions the child never received.
|
|
1673
1335
|
attachments: subagentId ? undefined : options.attachments,
|
|
1674
1336
|
canonicalTask: orchestrator && depth === 0 ? options.task : undefined,
|
|
1675
1337
|
...(finalAnswerOutcomes.length ? { finalAnswerOutcomes } : {}),
|
|
1338
|
+
goalCompletionVerification: options.graph && !goalCanEndRun ? undefined : options.goalCompletionVerification,
|
|
1339
|
+
sessionGoal: depth === 0 && !subagentId ? options.goalCompletionVerification?.goal : undefined,
|
|
1340
|
+
...(goalGraph && goalCanEndRun ? { goalRoute: (completion) => goalRoute(goalGraph, node, completion, {
|
|
1341
|
+
looping: options.modifierIteration !== undefined, copies: node.modifiers?.parallel?.mode === 'copies', ...(completionPolicy.mode === 'single' ? { defaultOutcome: completionPolicy.outcome } : {})
|
|
1342
|
+
}) } : {}),
|
|
1676
1343
|
completionGuard: orchestrator && depth === 0 ? completion => {
|
|
1677
1344
|
const missing = missingSkillError();
|
|
1678
1345
|
if (missing)
|
|
@@ -1683,8 +1350,6 @@ export async function executeAgentNode(node, options) {
|
|
|
1683
1350
|
const output = completion.output;
|
|
1684
1351
|
if (!output || typeof output.taskInstruction !== 'string' || !output.taskInstruction.trim() || ['requirements', 'acceptanceCriteria', 'designConsiderations', 'codebaseFindings'].some(key => !Array.isArray(output[key]) || output[key].some(value => typeof value !== 'string')))
|
|
1685
1352
|
return 'Return requirements, acceptanceCriteria, designConsiderations and codebaseFindings as string arrays and a nonempty taskInstruction in the structured handoff.';
|
|
1686
|
-
// `delivered` keeps the handoff contract and adds the delivery conditions: no child still
|
|
1687
|
-
// running, every reviewed change decided, and at least one of them landed.
|
|
1688
1353
|
if (completion.outcome === DELIVERED_OUTCOME) {
|
|
1689
1354
|
if (active > 0)
|
|
1690
1355
|
return 'Wait for every running subagent to finish before completing as delivered.';
|
|
@@ -1700,8 +1365,6 @@ export async function executeAgentNode(node, options) {
|
|
|
1700
1365
|
onUsage: (usage, origin) => {
|
|
1701
1366
|
options.onUsage?.(usage, origin);
|
|
1702
1367
|
},
|
|
1703
|
-
// Decision events from the runtime's own path (the post-tool check) reach the capture
|
|
1704
|
-
// here, once, instead of being counted by the runtime and again by this invocation.
|
|
1705
1368
|
onEvent: recordDecision });
|
|
1706
1369
|
if (result.telemetry) {
|
|
1707
1370
|
recordAttempt(result.telemetry, attempt > 1);
|
|
@@ -1710,16 +1373,12 @@ export async function executeAgentNode(node, options) {
|
|
|
1710
1373
|
}
|
|
1711
1374
|
previousAttemptReason = result.reason;
|
|
1712
1375
|
previousMutations = result.mutations;
|
|
1713
|
-
// Bounded upward escalation: a routed attempt that exhausted itself on a defined failure gets
|
|
1714
|
-
// one more attempt on the next tier, within the same node budget and never after a cancel.
|
|
1715
1376
|
const tiers = efficiency.adaptiveRouting.tiers ?? {};
|
|
1716
1377
|
const higherTier = routedTier === 'economy' ? tiers.balanced ?? tiers.premium : routedTier === 'balanced' ? tiers.premium : undefined;
|
|
1717
1378
|
const escalate = efficiency.adaptiveRouting.enabled && depth === 0 && !subagentId && routedTier !== undefined && higherTier !== undefined && !escalationFailed
|
|
1718
1379
|
&& escalations < efficiency.adaptiveRouting.maxEscalations && result.status === 'exhausted'
|
|
1719
1380
|
&& ['repeatedToolFailure', 'maxIterations'].includes(result.reason ?? '') && !context.signal.aborted
|
|
1720
1381
|
&& (options.budget === undefined || options.budget.maxToolCalls === undefined || options.budget.toolCalls < options.budget.maxToolCalls);
|
|
1721
|
-
// Every admitted escalation is pending, whether or not the loop had to grow for it: the next
|
|
1722
|
-
// attempt is routing's move, so a configured fallback does not take it instead.
|
|
1723
1382
|
if (escalate) {
|
|
1724
1383
|
escalationPending = true;
|
|
1725
1384
|
if (attempt === attempts)
|
|
@@ -1740,11 +1399,6 @@ export async function executeAgentNode(node, options) {
|
|
|
1740
1399
|
return result;
|
|
1741
1400
|
};
|
|
1742
1401
|
try {
|
|
1743
|
-
// `userSignal` is pinned to the session signal here, before any budget-derived signal
|
|
1744
|
-
// replaces `signal`, so prompts driven by nested executors can never inherit a deadline.
|
|
1745
|
-
// `bounded` supplies both prompts already exempt from this node's clock.
|
|
1746
|
-
// A wake this node arms is its own reminder about its own work, so the wake names the node and the
|
|
1747
|
-
// attempt: delivery returns it to this node rather than to the graph's entry.
|
|
1748
1402
|
const wakeOrigin = options.runId === undefined ? undefined : { runId: options.runId, nodeId: node.id };
|
|
1749
1403
|
const result = await run(node, { ...bounded, approve, ...(wakeOrigin === undefined ? {} : { wakeOrigin }), ...(delegationActive ? { delegationRoots } : {}) }, 0, orchestrator ? { ...options.mappedInputs, originalTask: options.task } : options.mappedInputs ?? {}, options.task);
|
|
1750
1404
|
if (orchestrator && !clarified && result.status === 'exhausted' && result.reason === MISSING_CONFIRMATION) {
|
|
@@ -1752,11 +1406,6 @@ export async function executeAgentNode(node, options) {
|
|
|
1752
1406
|
result.reason = 'Needs clarification: use ask_user to confirm the user design considerations before implementation.';
|
|
1753
1407
|
delete result.completion;
|
|
1754
1408
|
}
|
|
1755
|
-
// The delivery record: every change of this visit with its role, model, files, final state and
|
|
1756
|
-
// the conflicts it last hit. The guard already proved each one was decided, so the record is
|
|
1757
|
-
// written once, after acceptance. The accepted edits are already in the working folder, so a
|
|
1758
|
-
// store that cannot take the record (ENOSPC, EACCES) must not turn the delivered run into a
|
|
1759
|
-
// failure: the completion is kept and its summary says the record is missing.
|
|
1760
1409
|
if (delegationActive && result.status === 'succeeded' && result.completion?.outcome === DELIVERED_OUTCOME) {
|
|
1761
1410
|
const content = JSON.stringify({ changes: [...changes.values()].map(change => ({
|
|
1762
1411
|
id: change.id, subagentId: change.subagentId, role: change.role, provider: change.provider, model: change.model, state: change.state,
|
|
@@ -1779,8 +1428,6 @@ export async function executeAgentNode(node, options) {
|
|
|
1779
1428
|
delete result.completion;
|
|
1780
1429
|
}
|
|
1781
1430
|
if ((result.status === 'succeeded' || result.status === 'needs_clarification' || options.context.signal.aborted) && checkpoint) {
|
|
1782
|
-
// Capture the outer invocation allowance, including setup and delegated work,
|
|
1783
|
-
// not just the inner executor's clock and direct tool calls.
|
|
1784
1431
|
const narrow = (inner, outer) => inner === undefined ? outer : outer === undefined ? inner : Math.min(inner, outer);
|
|
1785
1432
|
await publishCheckpoint?.(checkpoint.messages, { ...checkpoint.state,
|
|
1786
1433
|
remainingWallTimeMs: narrow(checkpoint.state.remainingWallTimeMs, nodeBudget.remainingMs()),
|
|
@@ -1790,8 +1437,6 @@ export async function executeAgentNode(node, options) {
|
|
|
1790
1437
|
return result;
|
|
1791
1438
|
}
|
|
1792
1439
|
finally {
|
|
1793
|
-
// Delegated worktrees never outlive the node, whatever ended it; the release runs before the
|
|
1794
|
-
// node's controller is aborted so its announcements still reach the event sink.
|
|
1795
1440
|
try {
|
|
1796
1441
|
if (delegationActive)
|
|
1797
1442
|
await releaseChanges();
|