@andorra-labs/code 0.1.18 → 0.1.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/account-jev-savings.d.ts +4 -0
- package/dist/src/account-jev-savings.js +92 -0
- package/dist/src/acp-agent.js +2 -2
- package/dist/src/agent-execution.js +347 -45
- package/dist/src/agent-mcp.js +7 -1
- package/dist/src/agent-modifiers.js +5 -7
- package/dist/src/analytics.d.ts +19 -1
- package/dist/src/analytics.js +9 -1
- package/dist/src/andorra/entry.js +15 -6
- package/dist/src/andorra/hosted.d.ts +8 -0
- package/dist/src/andorra/hosted.js +22 -3
- package/dist/src/andorra/streams.d.ts +49 -0
- package/dist/src/andorra/streams.js +98 -0
- package/dist/src/antigravity-acp.d.ts +28 -0
- package/dist/src/antigravity-acp.js +150 -0
- package/dist/src/antigravity-terminal.d.ts +2 -0
- package/dist/src/antigravity-terminal.js +214 -0
- package/dist/src/app-server/adaptive-routing-settings.d.ts +37 -0
- package/dist/src/app-server/adaptive-routing-settings.js +69 -0
- package/dist/src/app-server/artifact.d.ts +14 -0
- package/dist/src/app-server/artifact.js +46 -0
- package/dist/src/app-server/legal-protocol.d.ts +33 -0
- package/dist/src/app-server/legal-protocol.js +16 -0
- package/dist/src/app-server/protocol.d.ts +23 -3
- package/dist/src/app-server/protocol.js +3 -1
- package/dist/src/app-server/telemetry-protocol.d.ts +53 -0
- package/dist/src/app-server/telemetry-protocol.js +2 -0
- package/dist/src/app-server/telemetry.d.ts +38 -0
- package/dist/src/app-server/telemetry.js +163 -0
- package/dist/src/app-server/workspace.d.ts +3 -1
- package/dist/src/app-server/workspace.js +39 -8
- package/dist/src/app-server.d.ts +50 -25
- package/dist/src/app-server.js +1008 -400
- package/dist/src/auth/AuthManager.d.ts +11 -2
- package/dist/src/auth/AuthManager.js +56 -13
- package/dist/src/auth/index.d.ts +5 -1
- package/dist/src/auth/index.js +8 -1
- package/dist/src/auth/lifecycle.d.ts +13 -0
- package/dist/src/auth/lifecycle.js +109 -0
- package/dist/src/auth/store.d.ts +1 -0
- package/dist/src/auth/store.js +12 -0
- package/dist/src/auth/types.d.ts +12 -0
- package/dist/src/automation-runner.js +2 -0
- package/dist/src/automation-service.js +7 -2
- package/dist/src/benchmark-scores.d.ts +88 -0
- package/dist/src/benchmark-scores.js +302 -0
- package/dist/src/bridge/command.js +4 -1
- package/dist/src/bridge/control.js +2 -1
- package/dist/src/bridge/engines.d.ts +2 -0
- package/dist/src/bridge/engines.js +9 -0
- package/dist/src/bridge/host-ops.d.ts +2 -2
- package/dist/src/bridge/host-ops.js +4 -2
- package/dist/src/bridge/host.d.ts +2 -0
- package/dist/src/bridge/host.js +63 -12
- package/dist/src/bridge/protocol.d.ts +1 -0
- package/dist/src/bridge/protocol.js +1 -0
- package/dist/src/browser-panel-tool.d.ts +12 -0
- package/dist/src/browser-panel-tool.js +30 -3
- package/dist/src/browser-runner.js +53 -62
- package/dist/src/browser-server.js +10 -4
- package/dist/src/browser-session.d.ts +14 -0
- package/dist/src/browser-session.js +57 -12
- package/dist/src/browser-view.d.ts +40 -1
- package/dist/src/browser-view.js +163 -9
- package/dist/src/browser-window-style.d.ts +27 -0
- package/dist/src/browser-window-style.js +244 -0
- package/dist/src/claude-provider.d.ts +1 -0
- package/dist/src/claude-provider.js +77 -36
- package/dist/src/cli.js +235 -58
- package/dist/src/codex-provider.d.ts +1 -0
- package/dist/src/codex-provider.js +43 -7
- package/dist/src/coding-tools.d.ts +1 -0
- package/dist/src/coding-tools.js +19 -5
- package/dist/src/command-screens.d.ts +1 -1
- package/dist/src/command-screens.js +2 -2
- package/dist/src/commands.d.ts +8 -1
- package/dist/src/commands.js +67 -63
- package/dist/src/completion.js +5 -3
- package/dist/src/config.d.ts +14 -3
- package/dist/src/config.js +54 -16
- package/dist/src/context-budget.d.ts +11 -2
- package/dist/src/context-budget.js +23 -2
- package/dist/src/context-compaction.d.ts +10 -8
- package/dist/src/context-compaction.js +23 -24
- package/dist/src/deadline.js +1 -1
- package/dist/src/decision/DecisionManager.d.ts +5 -0
- package/dist/src/decision/DecisionManager.js +39 -2
- package/dist/src/decision/applyToolMenu.js +6 -2
- package/dist/src/decision/hostedPolicy.js +6 -4
- package/dist/src/decision/optimizationPolicy.d.ts +10 -0
- package/dist/src/decision/optimizationPolicy.js +23 -3
- package/dist/src/decision/providers/AndorraDecisionProvider.d.ts +2 -1
- package/dist/src/decision/providers/AndorraDecisionProvider.js +17 -7
- package/dist/src/decision/providers/index.js +1 -1
- package/dist/src/decision/toolFamilies.js +1 -1
- package/dist/src/decision/types.d.ts +2 -0
- package/dist/src/efficiency.d.ts +75 -1
- package/dist/src/efficiency.js +114 -3
- package/dist/src/extensions.d.ts +2 -0
- package/dist/src/extensions.js +30 -20
- package/dist/src/github-app/agent-writes.d.ts +1 -1
- package/dist/src/github-app/agent-writes.js +1 -1
- package/dist/src/github-app/event-source.d.ts +0 -5
- package/dist/src/github-app/event-source.js +1 -31
- package/dist/src/github-app/metrics.d.ts +2 -5
- package/dist/src/github-app/metrics.js +2 -14
- package/dist/src/github-app/review-loop.d.ts +5 -5
- package/dist/src/github-app/review-loop.js +1 -1
- package/dist/src/github-app/review-node.d.ts +2 -2
- package/dist/src/github-app/triggers.d.ts +3 -3
- package/dist/src/glob-search.d.ts +1 -0
- package/dist/src/glob-search.js +3 -0
- package/dist/src/google-provider.d.ts +5 -28
- package/dist/src/google-provider.js +6 -141
- package/dist/src/graph-editor-session.d.ts +1 -0
- package/dist/src/graph-editor-session.js +2 -0
- package/dist/src/graph-health.js +3 -1
- package/dist/src/graph-runner.js +19 -13
- package/dist/src/graph-selection.d.ts +3 -1
- package/dist/src/graph-selection.js +2 -2
- package/dist/src/graph-server.d.ts +8 -1
- package/dist/src/graph-server.js +45 -10
- package/dist/src/graph-sync.d.ts +2 -1
- package/dist/src/graph-sync.js +13 -0
- package/dist/src/graph-ui/app.js +19 -8
- package/dist/src/graph-ui/index.html +1 -1
- package/dist/src/graphs.d.ts +17 -1
- package/dist/src/graphs.js +51 -5
- package/dist/src/grok-provider.js +17 -14
- package/dist/src/hardened-runtime.js +7 -4
- package/dist/src/jev-savings.d.ts +4 -0
- package/dist/src/jev-savings.js +13 -0
- package/dist/src/legal/client.d.ts +25 -0
- package/dist/src/legal/client.js +47 -0
- package/dist/src/legal/command.d.ts +13 -0
- package/dist/src/legal/command.js +98 -0
- package/dist/src/legal/documents.d.ts +2 -0
- package/dist/src/legal/documents.js +14 -0
- package/dist/src/legal/gate.d.ts +13 -0
- package/dist/src/legal/gate.js +96 -0
- package/dist/src/legal/manifest.d.ts +21 -0
- package/dist/src/legal/manifest.js +23 -0
- package/dist/src/legal/receipt.d.ts +13 -0
- package/dist/src/legal/receipt.js +137 -0
- package/dist/src/legal/release.d.ts +27 -0
- package/dist/src/legal/release.js +28 -0
- package/dist/src/managed-sign-in.d.ts +0 -1
- package/dist/src/managed-sign-in.js +0 -13
- package/dist/src/membership.d.ts +27 -1
- package/dist/src/membership.js +139 -7
- package/dist/src/model-metadata.js +3 -7
- package/dist/src/model-pool.d.ts +99 -0
- package/dist/src/model-pool.js +136 -0
- package/dist/src/model-relay/local.js +5 -0
- package/dist/src/model-relay/remote.d.ts +2 -0
- package/dist/src/model-relay/remote.js +4 -0
- package/dist/src/model-tiers.d.ts +13 -1
- package/dist/src/model-tiers.js +28 -4
- package/dist/src/opencode-cli-provider.js +59 -56
- package/dist/src/opencode-provider.js +16 -13
- package/dist/src/permissions.d.ts +5 -0
- package/dist/src/permissions.js +7 -0
- package/dist/src/plan-pass.js +2 -1
- package/dist/src/pool-scores.d.ts +45 -0
- package/dist/src/pool-scores.js +40 -0
- package/dist/src/provider-connection.js +3 -17
- package/dist/src/provider-engine.js +42 -12
- package/dist/src/provider-request-error.d.ts +8 -0
- package/dist/src/provider-request-error.js +12 -0
- package/dist/src/provider-settings.d.ts +1 -1
- package/dist/src/provider-settings.js +36 -18
- package/dist/src/provider-turn-deadline.d.ts +39 -0
- package/dist/src/provider-turn-deadline.js +139 -0
- package/dist/src/providers.d.ts +3 -9
- package/dist/src/providers.js +181 -146
- package/dist/src/pull-request-merge.d.ts +1 -8
- package/dist/src/pull-request-merge.js +0 -4
- package/dist/src/pull-requests.d.ts +82 -66
- package/dist/src/pull-requests.js +266 -276
- package/dist/src/qa/runtime/ProcessManager.d.ts +5 -1
- package/dist/src/qa/runtime/ProcessManager.js +9 -3
- package/dist/src/react-runtime.js +147 -56
- package/dist/src/reasoning-probe-cloud.d.ts +10 -0
- package/dist/src/reasoning-probe-cloud.js +209 -0
- package/dist/src/remote/engine-pool.d.ts +3 -0
- package/dist/src/remote/engine-pool.js +85 -18
- package/dist/src/remote/recovery.d.ts +6 -0
- package/dist/src/remote/recovery.js +37 -0
- package/dist/src/run-records.d.ts +13 -3
- package/dist/src/run-records.js +59 -34
- package/dist/src/runtime.d.ts +18 -1
- package/dist/src/runtime.js +25 -7
- package/dist/src/session-summary.d.ts +8 -0
- package/dist/src/session-summary.js +34 -0
- package/dist/src/sessions.d.ts +8 -0
- package/dist/src/sessions.js +12 -3
- package/dist/src/shell.js +6 -0
- package/dist/src/side-panel.js +36 -2
- package/dist/src/sign-in-detection.d.ts +1 -1
- package/dist/src/sign-in-detection.js +4 -10
- package/dist/src/sign-in-offer.js +1 -1
- package/dist/src/skill-commands.js +1 -1
- package/dist/src/skills/bundled/graph-manager/SKILL.md +2 -2
- package/dist/src/skills/bundled/graph-manager/patterns.md +13 -19
- package/dist/src/skills/bundled/provenance.json +2 -2
- package/dist/src/subagent-run.js +50 -50
- package/dist/src/subscription-usage.d.ts +50 -0
- package/dist/src/subscription-usage.js +92 -0
- package/dist/src/task-checkout.d.ts +20 -4
- package/dist/src/task-checkout.js +78 -8
- package/dist/src/telemetry/access.d.ts +18 -0
- package/dist/src/telemetry/access.js +43 -0
- package/dist/src/telemetry/aggregate.d.ts +18 -2
- package/dist/src/telemetry/aggregate.js +22 -9
- package/dist/src/telemetry/capture-core.d.ts +33 -14
- package/dist/src/telemetry/capture-core.js +124 -25
- package/dist/src/telemetry/capture.d.ts +3 -2
- package/dist/src/telemetry/capture.js +21 -1
- package/dist/src/telemetry/decision-capture.js +4 -0
- package/dist/src/telemetry/emitter.d.ts +6 -7
- package/dist/src/telemetry/emitter.js +124 -29
- package/dist/src/telemetry/gate.d.ts +41 -2
- package/dist/src/telemetry/gate.js +89 -4
- package/dist/src/telemetry/home.d.ts +1 -0
- package/dist/src/telemetry/home.js +20 -0
- package/dist/src/telemetry/identity.d.ts +6 -3
- package/dist/src/telemetry/identity.js +19 -6
- package/dist/src/telemetry/lifecycle.d.ts +8 -0
- package/dist/src/telemetry/lifecycle.js +76 -0
- package/dist/src/telemetry/outbox.d.ts +13 -8
- package/dist/src/telemetry/outbox.js +68 -12
- package/dist/src/telemetry/permission-command.d.ts +38 -0
- package/dist/src/telemetry/permission-command.js +208 -0
- package/dist/src/telemetry/permission.d.ts +168 -0
- package/dist/src/telemetry/permission.js +662 -0
- package/dist/src/telemetry/record-installation.d.ts +1 -0
- package/dist/src/telemetry/record-installation.js +9 -0
- package/dist/src/telemetry/region-data.d.ts +12 -0
- package/dist/src/telemetry/region-data.js +1314 -0
- package/dist/src/telemetry/region.d.ts +34 -0
- package/dist/src/telemetry/region.js +87 -0
- package/dist/src/telemetry/run-privacy.d.ts +11 -0
- package/dist/src/telemetry/run-privacy.js +165 -0
- package/dist/src/telemetry/schema.d.ts +27 -6
- package/dist/src/telemetry/schema.js +109 -14
- package/dist/src/telemetry/state.d.ts +11 -7
- package/dist/src/telemetry/state.js +39 -6
- package/dist/src/telemetry/surface.d.ts +20 -3
- package/dist/src/telemetry/surface.js +71 -15
- package/dist/src/telemetry/uploader.d.ts +6 -11
- package/dist/src/telemetry/uploader.js +72 -46
- package/dist/src/telemetry/uploads.d.ts +5 -1
- package/dist/src/telemetry/uploads.js +25 -6
- package/dist/src/telemetry/version.d.ts +5 -0
- package/dist/src/telemetry/version.js +34 -0
- package/dist/src/telemetry/workspace.d.ts +4 -1
- package/dist/src/telemetry/workspace.js +18 -3
- package/dist/src/terminal-ui.d.ts +3 -0
- package/dist/src/terminal-ui.js +48 -6
- package/dist/src/thinking-level-detect.d.ts +3 -1
- package/dist/src/thinking-level-detect.js +8 -3
- package/dist/src/thinking-levels.d.ts +1 -1
- package/dist/src/thinking-levels.js +11 -4
- package/dist/src/timers.d.ts +2 -0
- package/dist/src/todos.d.ts +2 -1
- package/dist/src/todos.js +24 -4
- package/dist/src/tool-argument-coercion.d.ts +7 -0
- package/dist/src/tool-argument-coercion.js +49 -0
- package/dist/src/tool-catalog.d.ts +2 -2
- package/dist/src/tools.js +67 -22
- package/dist/src/transcript.js +2 -1
- package/dist/src/types.d.ts +14 -1
- package/dist/src/update.js +4 -0
- package/dist/src/usage-analytics.d.ts +7 -0
- package/dist/src/usage-analytics.js +85 -13
- package/dist/telemetry-consent-v1 +1 -0
- package/package.json +97 -96
|
@@ -2,14 +2,17 @@ import { goalRoute, routedOutcomes, runEndingOutcomes as goalRunEndingOutcomes }
|
|
|
2
2
|
import { DecisionPolicy } from './decision/DecisionPolicy.js';
|
|
3
3
|
import { answerOnlyTask, hasAdaptiveAlternative } from './decision/optimizationPolicy.js';
|
|
4
4
|
import { resolveEfficiency } from './efficiency.js';
|
|
5
|
+
import { ANDORRA_STREAMS_TOOL, currentAndorraStreams, holdAndorraStream } from './andorra/streams.js';
|
|
5
6
|
import { collectWorkspaceFacts } from './workspace-facts.js';
|
|
6
7
|
import { conversationContains, omittedContextNote, selectContext } from './context-selection.js';
|
|
7
8
|
import { MAPPED_INPUTS_HEADING } from './context-compaction.js';
|
|
8
9
|
import { orderSkillCatalog, selectToolCatalog } from './tool-catalog.js';
|
|
9
10
|
import { decideModelTier } from './model-tiers.js';
|
|
11
|
+
import { decidePoolModel, isPoolClass } from './model-pool.js';
|
|
10
12
|
import { decideEffort, EFFORT_ESCALATION_REASONS } from './effort-routing.js';
|
|
11
13
|
import { nearestEnabled } from './thinking-levels.js';
|
|
12
14
|
import { REASONING_EFFORTS, supportsReasoningEffort } from './providers.js';
|
|
15
|
+
import { POOL_CLASSES } from './efficiency.js';
|
|
13
16
|
import { structuredText } from './code-intelligence/CodeIntelligenceManager.js';
|
|
14
17
|
import { buildMemoryBlock } from './memory/MemoryRetriever.js';
|
|
15
18
|
import { discoverRuntimeSkills, matchRuntimeSkill, runtimeSkillTools } from './skills/runtime-skills.js';
|
|
@@ -25,12 +28,12 @@ import { mkdtemp, realpath } from 'node:fs/promises';
|
|
|
25
28
|
import { tmpdir } from 'node:os';
|
|
26
29
|
import { join, relative } from 'node:path';
|
|
27
30
|
import { ClarificationRequiredError, DEFAULT_GRAPH, LIMIT_KEYS, isUnlimitedAlias, resolveLimits, turnModelCompletion, turnModelTask } from './runtime.js';
|
|
28
|
-
import { createRunTelemetry, mergeRunTelemetry, recordAttempt, recordDecisionEvent, recordEfficiencyEvent } from './telemetry/capture.js';
|
|
31
|
+
import { resolveTelemetryCapture, bindRunTelemetry, hasRunTelemetry, createRunTelemetry, mergeRunTelemetry, recordAttempt, recordDecisionEvent, recordEfficiencyEvent } from './telemetry/capture.js';
|
|
29
32
|
import { bindUserWaits, createRuntimeBudget } from './deadline.js';
|
|
30
33
|
import { createAgentEngine } from './hardened-runtime.js';
|
|
31
34
|
import { completionTool } from './completion.js';
|
|
32
35
|
import { applyToolProfile } from './tool-profile.js';
|
|
33
|
-
import { DELIVERED_OUTCOME, GRAPH_MANAGER_GRAPH_ID, REVIEWER_GRAPH_ID, capabilitySubset, isolatedGraph, reviewerOutputProblem, delegatesWriting, effectiveCapabilities, intakeCapabilities, isTestingNode, isWritingRole, laterAgentNodes, permitsBuiltInTool, testerOnEveryRoute } from './graphs.js';
|
|
36
|
+
import { DELIVERED_OUTCOME, GRAPH_MANAGER_GRAPH_ID, REVIEWER_GRAPH_ID, capabilitySubset, isolatedGraph, reviewerOutputProblem, delegatesWriting, effectiveCapabilities, freeformRole, intakeCapabilities, isCommandToolName, isTestingNode, isWritingRole, laterAgentNodes, permitsBuiltInTool, testerOnEveryRoute } from './graphs.js';
|
|
34
37
|
import { DELEGATION_DIFF_LIMIT, LandingRestoreError, addChangeWorktree, assertDelegationGit, applyLanding, collectChange, prepareLanding, removeChangeWorktree, repositoryRoot, snapshotWorkspace } from './delegation-changes.js';
|
|
35
38
|
import { stopQaProcessesUnder } from './qa/runtime/ProcessManager.js';
|
|
36
39
|
import { qaGuidance } from './qa/guidance.js';
|
|
@@ -40,7 +43,7 @@ import { ArtifactStore } from './artifacts.js';
|
|
|
40
43
|
import { approveOperation, capabilityTools, gitReadTool } from './capabilities.js';
|
|
41
44
|
import { removeUntrackedFileTool } from './untracked-file-removal.js';
|
|
42
45
|
import { permissionMode, serializeApprovals, assertPlanMutationAllowed } from './permissions.js';
|
|
43
|
-
import { adaptLegacyCodingToolArguments, canonicalToolName, canonicalizeToolList } from './tool-names.js';
|
|
46
|
+
import { adaptLegacyCodingToolArguments, canonicalToolName, canonicalizeToolList, toolNameMatches } from './tool-names.js';
|
|
44
47
|
const exec = promisify(execFile);
|
|
45
48
|
const LANDING_ATTEMPTS = 3;
|
|
46
49
|
const RESTORE_TOOL_SCHEMA_CHARS = 420;
|
|
@@ -92,6 +95,26 @@ function references(value, result = new Set()) {
|
|
|
92
95
|
}
|
|
93
96
|
return result;
|
|
94
97
|
}
|
|
98
|
+
// Artifact references an agent names explicitly: artifact:// references appearing anywhere in text
|
|
99
|
+
// (a task, a summary, a field value) plus {type, ref} object fields wherever they sit. Naming a
|
|
100
|
+
// reference is a request for read access, never a grant in itself. Only a well-formed reference
|
|
101
|
+
// counts as a request: a string that merely begins like one ('artifact://run/id/suffix') never
|
|
102
|
+
// matches a real reference, so a malformed quote cannot grant anything by prefix.
|
|
103
|
+
const ARTIFACT_REF_PATTERN = /artifact:\/\/[A-Za-z0-9_-]+\/[A-Za-z0-9_-]+(?![/\w-])/g;
|
|
104
|
+
const ARTIFACT_REF_EXACT = /^artifact:\/\/[A-Za-z0-9_-]+\/[A-Za-z0-9_-]+$/;
|
|
105
|
+
function quotedArtifactRefs(value, result = new Set()) {
|
|
106
|
+
if (typeof value === 'string') {
|
|
107
|
+
for (const match of value.matchAll(ARTIFACT_REF_PATTERN))
|
|
108
|
+
result.add(match[0]);
|
|
109
|
+
}
|
|
110
|
+
else if (value && typeof value === 'object') {
|
|
111
|
+
if ('ref' in value && typeof value.ref === 'string' && ARTIFACT_REF_EXACT.test(value.ref))
|
|
112
|
+
result.add(value.ref);
|
|
113
|
+
for (const child of Object.values(value))
|
|
114
|
+
quotedArtifactRefs(child, result);
|
|
115
|
+
}
|
|
116
|
+
return result;
|
|
117
|
+
}
|
|
95
118
|
async function resolveBeforeAbort(resolve, signal) {
|
|
96
119
|
signal.throwIfAborted();
|
|
97
120
|
let abort;
|
|
@@ -125,6 +148,7 @@ async function retryReadOnly(context, operation) {
|
|
|
125
148
|
}
|
|
126
149
|
}
|
|
127
150
|
export async function executeAgentNode(node, options) {
|
|
151
|
+
options = { ...options, telemetry: resolveTelemetryCapture(options.telemetry) };
|
|
128
152
|
if (node.maxSubagents !== undefined && (!Number.isSafeInteger(node.maxSubagents) || node.maxSubagents < 0 || node.maxSubagents > 100))
|
|
129
153
|
throw new Error('maxSubagents must be an integer from 0 to 100');
|
|
130
154
|
const limits = mergeLimits(node, options.limits);
|
|
@@ -304,20 +328,25 @@ export async function executeAgentNode(node, options) {
|
|
|
304
328
|
const intake = await runIntake();
|
|
305
329
|
if (intake)
|
|
306
330
|
return intake;
|
|
307
|
-
|
|
331
|
+
// Subagent nodes whose model was inherited or routed, not named by the graph. The runtime fills in their provider
|
|
332
|
+
// and model, which must not read as a pin when such a subagent spawns its own.
|
|
333
|
+
const inheritingChildren = new WeakSet();
|
|
334
|
+
const run = async (configured, context, depth, inputs, task, subagentId, parentFallback = false, commandScope = depth > 0, sharedRefs) => {
|
|
308
335
|
const nodeLimits = mergeLimits(configured, depth ? { ...limits, wallTimeMs: configured.limits?.wallTimeMs } : limits);
|
|
309
336
|
const nodeBudget = createRuntimeBudget(context.signal, nodeLimits.wallTimeMs, context.runControl);
|
|
310
337
|
const observationController = options.decisionManager?.enabled ? new AbortController() : undefined;
|
|
311
338
|
const nodeSignal = observationController ? AbortSignal.any([nodeBudget.signal, observationController.signal]) : nodeBudget.signal;
|
|
339
|
+
// This agent's place among the account's Andorra streams, held for the whole run and not only while a request is out.
|
|
340
|
+
const streamHold = holdAndorraStream();
|
|
312
341
|
try {
|
|
313
342
|
let result;
|
|
314
343
|
try {
|
|
315
344
|
nodeSignal.throwIfAborted();
|
|
316
|
-
result = await runWithinDeadline(configured, bindUserWaits({ ...context, signal: nodeSignal }, nodeBudget, nodeSignal), depth, inputs, task, subagentId, parentFallback, () => {
|
|
345
|
+
result = await streamHold.run(() => runWithinDeadline(configured, bindUserWaits({ ...context, signal: nodeSignal }, nodeBudget, nodeSignal), depth, inputs, task, subagentId, parentFallback, () => {
|
|
317
346
|
const resumeInvocation = suspendInvocationMemoryBudget();
|
|
318
347
|
const resume = nodeBudget.suspend();
|
|
319
348
|
return () => { resume(); resumeInvocation(); };
|
|
320
|
-
}, commandScope);
|
|
349
|
+
}, commandScope, sharedRefs, streamHold));
|
|
321
350
|
}
|
|
322
351
|
catch (error) {
|
|
323
352
|
if (!nodeSignal.aborted)
|
|
@@ -334,11 +363,12 @@ export async function executeAgentNode(node, options) {
|
|
|
334
363
|
return result;
|
|
335
364
|
}
|
|
336
365
|
finally {
|
|
366
|
+
streamHold.release();
|
|
337
367
|
observationController?.abort();
|
|
338
368
|
nodeBudget.dispose();
|
|
339
369
|
}
|
|
340
370
|
};
|
|
341
|
-
const runWithinDeadline = async (configured, context, depth, inputs, task, subagentId, parentFallback = false, suspendMemoryBudget, commandScope = depth > 0) => {
|
|
371
|
+
const runWithinDeadline = async (configured, context, depth, inputs, task, subagentId, parentFallback = false, suspendMemoryBudget, commandScope = depth > 0, sharedRefs, streamHold) => {
|
|
342
372
|
const delegatedChild = commandScope === 'delegated-worktree';
|
|
343
373
|
if (orchestrator && !delegatedChild)
|
|
344
374
|
configured = { ...configured, capabilities: intakeCapabilities(configured) };
|
|
@@ -373,16 +403,40 @@ export async function executeAgentNode(node, options) {
|
|
|
373
403
|
let provider = configuredProvider, resolved = await resolve(provider, configuredModel);
|
|
374
404
|
if (!resolved)
|
|
375
405
|
throw new Error(`Unknown provider ${provider}. Run andorra and open /providers first.`);
|
|
406
|
+
// The model a live change moved the running attempt to; the runtime applies it without telling this function.
|
|
407
|
+
let liveResolved;
|
|
408
|
+
streamHold?.watch(() => (liveResolved ?? resolved)?.providerType === 'andorra');
|
|
376
409
|
// The resolved model is the provider's own spelling of the configured one when they differ only in case.
|
|
377
410
|
const spelled = (wanted, got) => wanted !== undefined && wanted.toLowerCase() === got.toLowerCase() ? got : wanted ?? got;
|
|
378
411
|
let model = spelled(configured.model, resolved.model);
|
|
379
412
|
// The thinking level in force for this node's requests; a subagent that inherits the model runs at it too.
|
|
380
413
|
let activeEffort;
|
|
414
|
+
// Pool routing names a thinking level with the pair it picks; a node's own level still wins over it.
|
|
415
|
+
let poolEffort;
|
|
416
|
+
// With `subagents` on, a subagent that would inherit its parent's model gets its own routing decision, under either
|
|
417
|
+
// strategy and whether or not the run's own model was chosen: a chosen model pins only the agent it was chosen for.
|
|
418
|
+
const subagentRouting = (() => {
|
|
419
|
+
const routing = resolveEfficiency(options.efficiency).adaptiveRouting;
|
|
420
|
+
return routing.enabled && routing.subagents === true ? routing : undefined;
|
|
421
|
+
})();
|
|
422
|
+
const poolSubagents = subagentRouting?.strategy === 'pool' ? subagentRouting : undefined;
|
|
423
|
+
// A usage reading that fails is an unknown reading: the pair is neither preferred nor held back.
|
|
424
|
+
const readQuota = async (signal) => {
|
|
425
|
+
try {
|
|
426
|
+
return await options.quotaReadings?.(signal);
|
|
427
|
+
}
|
|
428
|
+
catch {
|
|
429
|
+
signal.throwIfAborted();
|
|
430
|
+
return undefined;
|
|
431
|
+
}
|
|
432
|
+
};
|
|
433
|
+
// The thinking levels a model takes, for routing that chooses a level from the model's scores.
|
|
434
|
+
const poolLevels = (id, name) => options.thinkingLevels?.(id, name, false);
|
|
381
435
|
const asLevel = (value) => value !== undefined && REASONING_EFFORTS.includes(value) ? value : undefined;
|
|
382
436
|
const levelsFor = (id, name, type, forAuto) => options.thinkingLevels?.(id, name, forAuto) ?? (type === undefined || !supportsReasoningEffort(type) ? [] : forAuto ? ['low', 'medium', 'high'] : [...REASONING_EFFORTS]);
|
|
383
437
|
// The run's own model: the one it started on, or the one a live whole-run change moved it to.
|
|
384
438
|
let sessionModel = { provider: options.provider, model: options.model };
|
|
385
|
-
const wantedEffort = () => configured.reasoningEffort
|
|
439
|
+
const wantedEffort = () => configured.reasoningEffort ?? poolEffort
|
|
386
440
|
?? (options.sessionEffortAuto && depth === 0 && provider === sessionModel.provider && model === sessionModel.model ? 'auto' : undefined);
|
|
387
441
|
let fallbackAttempt = parentFallback;
|
|
388
442
|
const orchestratorCompletionGuard = () => {
|
|
@@ -466,11 +520,28 @@ export async function executeAgentNode(node, options) {
|
|
|
466
520
|
throw new Error('Clarification response exceeds 16000 characters; ask for a shorter decision.');
|
|
467
521
|
clarified = true;
|
|
468
522
|
confirmedClarifications.push({ question: args.question, answer, proposedDesign: args.proposedDesign });
|
|
469
|
-
await emit('agent.clarification.answered', { answered: true });
|
|
523
|
+
await emit('agent.clarification.answered', { answered: true, question, answer });
|
|
470
524
|
return JSON.stringify({ answer, proposedDesign: args.proposedDesign });
|
|
471
525
|
} });
|
|
472
526
|
if (orchestrator && depth === 0 && effectiveCapabilities(configured).filesystem !== 'none')
|
|
473
527
|
tools.push(removeUntrackedFileTool());
|
|
528
|
+
if (depth === 0 && !isolated && options.context.chatHandoffs && options.context.askUser && !headlessRun)
|
|
529
|
+
tools.push({
|
|
530
|
+
name: 'propose_chat', executionMode: 'sequential',
|
|
531
|
+
description: 'Offer a fresh child chat for a distinct next stage of work. Ask one concise question, supply a self-contained handoff prompt (the child gets no transcript), and suggest a model and reasoning effort. Only the user can start it. Do not propose again after Skip.',
|
|
532
|
+
parameters: { type: 'object', additionalProperties: false, required: ['question', 'prompt', 'model', 'effort'], properties: {
|
|
533
|
+
question: { type: 'string', minLength: 1, maxLength: 240 }, prompt: { type: 'string', minLength: 1, maxLength: 16000 },
|
|
534
|
+
model: { type: 'string', minLength: 1, maxLength: 200 }, effort: { type: 'string', enum: ['default', 'none', 'minimal', 'low', 'medium', 'high', 'xhigh', 'max'] },
|
|
535
|
+
} },
|
|
536
|
+
execute: async (args, ctx) => {
|
|
537
|
+
const { question, prompt, model, effort } = args;
|
|
538
|
+
if (typeof question !== 'string' || !question.trim() || question.length > 240 || typeof prompt !== 'string' || !prompt.trim() || prompt.length > 16000 || typeof model !== 'string' || !model.trim() || model.length > 200 || typeof effort !== 'string' || !['default', 'none', 'minimal', 'low', 'medium', 'high', 'xhigh', 'max'].includes(effort))
|
|
539
|
+
throw new Error('Provide one short question, a self-contained prompt, a suggested model and a valid effort.');
|
|
540
|
+
ctx.signal.throwIfAborted();
|
|
541
|
+
const decision = await ctx.askUser(question.trim(), ctx.userSignal ?? ctx.signal, ['Skip', 'Start'], { prompt: prompt.trim(), model: model.trim(), ...(effort === 'default' ? {} : { effort }) });
|
|
542
|
+
return JSON.stringify({ decision: decision === 'Start' ? 'user-approved' : 'skipped' });
|
|
543
|
+
},
|
|
544
|
+
});
|
|
474
545
|
if (!orchestrator && !isolated && depth === 0 && options.context.approvalMode !== 'headless' && options.context.askUser)
|
|
475
546
|
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.',
|
|
476
547
|
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 },
|
|
@@ -488,7 +559,7 @@ export async function executeAgentNode(node, options) {
|
|
|
488
559
|
const answer = await ctx.askUser(question, ctx.userSignal ?? ctx.signal, choices);
|
|
489
560
|
ctx.signal.throwIfAborted();
|
|
490
561
|
const answered = typeof answer === 'string' && !!answer.trim() && answer.trim().toLowerCase() !== '/cancel';
|
|
491
|
-
await emit('agent.clarification.answered', { answered });
|
|
562
|
+
await emit('agent.clarification.answered', { answered, ...(answered && answer.length <= 16000 ? { question, answer } : {}) });
|
|
492
563
|
if (typeof answer !== 'string' || answer.trim().toLowerCase() === '/cancel')
|
|
493
564
|
throw new ClarificationRequiredError('Needs clarification: the user cancelled the task at a question. Nothing further was done.');
|
|
494
565
|
if (!answered)
|
|
@@ -534,6 +605,14 @@ export async function executeAgentNode(node, options) {
|
|
|
534
605
|
references(predecessorContext, scopedRefs);
|
|
535
606
|
if (depth === 0 && options.previousIterationCompletion)
|
|
536
607
|
references(options.previousIterationCompletion, scopedRefs);
|
|
608
|
+
// A subagent starts with only the artifact references its start explicitly granted, not with whatever
|
|
609
|
+
// its parent can read: the parent's grant is the filter, so sharing cannot amplify privileges. An
|
|
610
|
+
// undefined sharedRefs means a top-level invocation, which keeps its own mapped-input references.
|
|
611
|
+
if (sharedRefs) {
|
|
612
|
+
scopedRefs.clear();
|
|
613
|
+
for (const ref of sharedRefs)
|
|
614
|
+
scopedRefs.add(ref);
|
|
615
|
+
}
|
|
537
616
|
const artifactTools = store.tools(scopedRefs);
|
|
538
617
|
const write = artifactTools.find(tool => tool.name === 'write_artifact');
|
|
539
618
|
if (configured.tools === undefined || configured.tools.includes('read_artifact'))
|
|
@@ -542,12 +621,48 @@ export async function executeAgentNode(node, options) {
|
|
|
542
621
|
tools.push({ ...write, execute: async (args, ctx) => { const result = await write.execute(args, ctx); scopedRefs.add(JSON.parse(result).ref); return result; } });
|
|
543
622
|
const canDelegateSkillReader = tools.some(tool => tool.name === 'read_skill_resource');
|
|
544
623
|
if (policy.enabled && maxTotal > 0 && depth < (policy.maxDepth ?? 1) && !(delegationActive && depth > 0)) {
|
|
545
|
-
|
|
546
|
-
|
|
624
|
+
const freeformMode = policy.freeform ?? 'off';
|
|
625
|
+
// Offered where a subagent, or this agent itself, can be on an Andorra model: the only models with a stream cap.
|
|
626
|
+
// Routing and a live model change can move either onto any configured provider after this list is built.
|
|
627
|
+
const providerTypeOf = (id) => {
|
|
628
|
+
if (id === undefined || id === provider)
|
|
629
|
+
return resolved?.providerType;
|
|
630
|
+
// A graph run resolves only the providers its nodes name; the run's provider list has every configured one.
|
|
631
|
+
const configuredType = options.configuredModels?.find(entry => entry.id === id)?.type;
|
|
632
|
+
if (configuredType !== undefined)
|
|
633
|
+
return configuredType;
|
|
634
|
+
try {
|
|
635
|
+
return options.resolveProvider?.(id)?.providerType;
|
|
636
|
+
}
|
|
637
|
+
catch {
|
|
638
|
+
return undefined;
|
|
639
|
+
}
|
|
640
|
+
};
|
|
641
|
+
const andorraStreams = [provider, policy.provider, ...(policy.roles ?? []).map(role => role.provider),
|
|
642
|
+
...(options.configuredModels ?? []).map(entry => entry.id)].some(id => providerTypeOf(id) === 'andorra');
|
|
643
|
+
if (andorraStreams)
|
|
644
|
+
tools.push({ name: ANDORRA_STREAMS_TOOL,
|
|
645
|
+
description: 'Report how many Andorra streams the account has in use and how many are free. Andorra models allow a limited number of agents at once, and a subagent started past the limit fails. Call this before starting subagents when you or they run on an Andorra model, and start no more than it reports available. An agent holds its stream for its whole run, also while it runs a tool or waits, so every running agent is counted, you included.',
|
|
646
|
+
parameters: { type: 'object', properties: {}, additionalProperties: false },
|
|
647
|
+
execute: async (args, ctx) => {
|
|
648
|
+
ctx.signal.throwIfAborted();
|
|
649
|
+
if (Object.keys(args).length)
|
|
650
|
+
throw new Error(`${ANDORRA_STREAMS_TOOL} takes no arguments`);
|
|
651
|
+
return JSON.stringify(await currentAndorraStreams(options.andorraHostedCheck, ctx.signal));
|
|
652
|
+
} });
|
|
653
|
+
tools.push({ name: 'spawn_subagent', description: (freeformMode === 'off' ? 'Run one configured role on a bounded task.' : 'Run a subagent on a bounded task. Omit role to run a general subagent that follows the task you write' + ((policy.roles ?? []).length ? ', or name a configured role' : '') + (freeformMode === 'write' ? '. A general subagent may write within the configured permissions.' : '. A general subagent is read-only.')) + ' Its typed result returns as an observation. Batch spawn calls can run concurrently within configured limits.' + (policy.workspace === 'worktree' ? ' A subagent that runs commands (one whose tools include a command tool such as PowerShell, Bash or NativeExec) works in its own Git worktree started from the working folder; to let a subagent run commands it would not otherwise get, for example a verifier that must run the build, name those tools in tools.' : '') + (andorraStreams ? ` On an Andorra model, call ${ANDORRA_STREAMS_TOOL} first and start no more subagents at once than it reports available.` : '') + ' Role contracts: ' + JSON.stringify((policy.roles ?? []).map(role => ({ id: role.id, name: role.name, instruction: role.instruction, inputSchema: role.inputSchema, outputSchema: role.outputSchema }))),
|
|
654
|
+
parameters: { type: 'object', properties: { ...(freeformMode !== 'off' && !(policy.roles ?? []).length ? {} : { role: { type: 'string', enum: (policy.roles ?? []).map(role => role.id), ...(freeformMode === 'off' ? {} : { description: 'Optional. Omit it to run a general subagent.' }) } }), task: { type: 'string', description: 'The bounded task. Quoting an artifact:// reference in it or in input gives the subagent read access to that artifact only if you can already read it yourself; everything else stays outside its context.' }, input: { type: 'object' }, tools: { type: 'array', items: { type: 'string', minLength: 1 }, maxItems: 32, description: 'Optional. Tools from your own tool list to give this subagent in addition to its usual ones, for example PowerShell or NativeExec so it can run a build or tests.' + (policy.workspace === 'worktree' ? ' A subagent given a command tool runs it in its own Git worktree.' : ' Command tools cannot be given here: this node\'s subagents share its working folder.') }, ...(poolSubagents ? { class: { type: 'string', enum: [...POOL_CLASSES], description: 'Optional. How demanding the task is; it selects the model the subagent runs on.' } } : {}) }, required: freeformMode === 'off' ? ['role', 'task'] : ['task'], additionalProperties: false },
|
|
547
655
|
execute: async (args, callContext) => {
|
|
548
|
-
if (
|
|
549
|
-
throw new Error('
|
|
550
|
-
|
|
656
|
+
if (poolSubagents && args.class !== undefined && !isPoolClass(args.class))
|
|
657
|
+
throw new Error('class must be one of routine, quick, standard, deep or escalated');
|
|
658
|
+
if (args.tools !== undefined && (!Array.isArray(args.tools) || args.tools.length > 32 || args.tools.some(name => typeof name !== 'string' || !name.trim())))
|
|
659
|
+
throw new Error('tools must be an array of at most 32 tool names from your own tool list');
|
|
660
|
+
if (Object.keys(args).some(key => !['role', 'task', 'input', 'tools', ...(poolSubagents ? ['class'] : [])].includes(key)) || (typeof args.role !== 'string' && !(args.role === undefined && freeformMode !== 'off')) || typeof args.task !== 'string' || !args.task.trim() || args.task.length > 16000)
|
|
661
|
+
throw new Error((freeformMode === 'off' ? 'Choose a configured role' : 'Name a configured role or omit role') + ' and provide a task of 1–16000 characters');
|
|
662
|
+
// No role named: a general subagent bounded by the freeform setting. In write mode it takes the node's own
|
|
663
|
+
// permissions where this Orchestrator delegates, and its parent's everywhere else.
|
|
664
|
+
const general = args.role === undefined ? freeformRole(policy, freeformMode === 'write' && delegationActive && depth === 0 ? effectiveCapabilities(node) : effectiveCapabilities(configured)) : undefined;
|
|
665
|
+
const role = general ?? policy.roles?.find(item => item.id === args.role);
|
|
551
666
|
if (!role)
|
|
552
667
|
throw new Error('Subagent role is not allowed');
|
|
553
668
|
if (total >= maxTotal)
|
|
@@ -557,13 +672,30 @@ export async function executeAgentNode(node, options) {
|
|
|
557
672
|
throw new Error('Subagent input must be an object');
|
|
558
673
|
if (role.inputSchema)
|
|
559
674
|
validateValue(role.inputSchema, childInputs, `Subagent ${role.name} input`);
|
|
560
|
-
|
|
675
|
+
// Explicit artifact sharing: the subagent gains read access to an artifact it names in its task
|
|
676
|
+
// or input only when this agent can already read it itself. Everything else stays outside its
|
|
677
|
+
// context: what it merely mentions without access, what this agent cannot read, and unquoted
|
|
678
|
+
// artifacts, whatever this agent can do with them.
|
|
679
|
+
const requestedRefs = quotedArtifactRefs(args.task);
|
|
680
|
+
quotedArtifactRefs(childInputs, requestedRefs);
|
|
681
|
+
const sharedArtifactRefs = [...requestedRefs].filter(ref => scopedRefs.has(ref));
|
|
682
|
+
const refusedRefs = [...requestedRefs].filter(ref => !scopedRefs.has(ref));
|
|
683
|
+
// Tools the spawning agent grants for this spawn. A command tool among them gives the child the shell and
|
|
684
|
+
// its own worktree; commands never run in a folder the child shares with its parent.
|
|
685
|
+
const granted = [...new Set((args.tools ?? []).map(name => canonicalToolName(name.trim())))];
|
|
686
|
+
const grantsCommands = granted.some(isCommandToolName);
|
|
687
|
+
if (grantsCommands && policy.workspace !== 'worktree')
|
|
688
|
+
throw new Error('Command tools can only be given to a subagent that runs in its own Git worktree, and this node\'s subagents share its working folder. Select Separate Git worktree for its subagents, or run the commands yourself.');
|
|
689
|
+
const delegated = delegationActive && depth === 0 && (isWritingRole(role) || grantsCommands);
|
|
561
690
|
if (delegated && !clarified)
|
|
562
691
|
throw new Error('Ask the user to confirm the design before starting writing subagents: a real ask_user answer is required first.');
|
|
563
692
|
if (delegated && policy.workspace !== 'worktree')
|
|
564
693
|
throw new Error('Writing roles on an Orchestrator require separate worktrees; select Separate Git worktree.');
|
|
565
694
|
const parentCapabilities = delegated ? effectiveCapabilities(node) : effectiveCapabilities(configured);
|
|
566
|
-
const
|
|
695
|
+
const roleCapabilities = role.capabilities ?? { ...parentCapabilities, ...(policy.workspace === undefined || policy.workspace === 'shared-read-only' ? { filesystem: parentCapabilities.filesystem === 'none' ? 'none' : 'read', git: parentCapabilities.git === 'none' ? 'none' : 'read', shell: 'disabled' } : {}) };
|
|
696
|
+
if (grantsCommands && parentCapabilities.shell !== 'allowed')
|
|
697
|
+
throw new Error('Command tools cannot be given: this agent is not allowed to run commands, so its subagents cannot be either.');
|
|
698
|
+
const childCapabilities = grantsCommands ? { ...roleCapabilities, shell: 'allowed' } : roleCapabilities;
|
|
567
699
|
if (!capabilitySubset(childCapabilities, parentCapabilities))
|
|
568
700
|
throw new Error('Subagent capabilities exceed its parent');
|
|
569
701
|
const writingChild = childCapabilities.filesystem === 'read-write' || childCapabilities.git === 'write';
|
|
@@ -575,19 +707,65 @@ export async function executeAgentNode(node, options) {
|
|
|
575
707
|
? [...capabilityTools({ ...node, capabilities: parentCapabilities, tools: undefined }, catalog, 'delegated-worktree').map(tool => tool.name).filter(name => name !== 'browser.panel' && name !== 'browser.incognito' && name !== 'browser.extensions'),
|
|
576
708
|
...tools.map(tool => tool.name).filter(name => name === 'read_artifact' || name === 'write_artifact'), ...(canDelegateSkillReader ? ['read_skill_resource'] : [])]
|
|
577
709
|
: [...tools.map(tool => tool.name).filter(name => name !== 'browser.panel' && name !== 'browser.incognito' && name !== 'browser.extensions'), ...(canDelegateSkillReader ? ['read_skill_resource'] : [])]);
|
|
578
|
-
const
|
|
579
|
-
|
|
710
|
+
const unavailable = granted.filter(name => ![...available].some(own => toolNameMatches(own, name)));
|
|
711
|
+
if (unavailable.length)
|
|
712
|
+
throw new Error(`These tools are not in your own tool list, so they cannot be given to a subagent: ${unavailable.join(', ')}`);
|
|
713
|
+
const grantedNames = granted.map(name => [...available].find(own => toolNameMatches(own, name)));
|
|
714
|
+
const baseToolNames = delegated ? canonicalizeToolList(role.tools) ?? [...available]
|
|
715
|
+
: policy.toolInheritance === 'inherit' || (general !== undefined && writingChild) ? [...available] : canonicalizeToolList(role.tools) ?? [...available].filter(name => ['Read', 'Glob', 'Grep', 'git_read', 'qa.browser_session', 'read_skill_resource'].includes(canonicalToolName(name)));
|
|
716
|
+
const childToolNames = [...new Set([...baseToolNames, ...grantedNames])];
|
|
580
717
|
if (childToolNames.some(name => !available.has(name)))
|
|
581
718
|
throw new Error('Subagent tool selection exceeds its parent');
|
|
582
|
-
|
|
583
|
-
|
|
719
|
+
// A child runs commands only in its own worktree: a delegated one always has one, and any other child gets one
|
|
720
|
+
// when its tools include a command tool its permissions allow. Creating that worktree needs Git write on the
|
|
721
|
+
// parent: without it a grant is refused up front, and an inherited command tool is simply not offered.
|
|
722
|
+
if (grantsCommands && !delegated && parentCapabilities.git !== 'write')
|
|
723
|
+
throw new Error('Command tools cannot be given: a subagent that runs commands needs its own Git worktree, and creating one needs Git write access, which this agent does not have.');
|
|
724
|
+
const runsCommands = !delegated && policy.workspace === 'worktree' && parentCapabilities.git === 'write' && childCapabilities.shell === 'allowed' && childToolNames.some(isCommandToolName);
|
|
725
|
+
const childScope = delegated ? 'delegated-worktree' : runsCommands ? 'worktree' : undefined;
|
|
726
|
+
const refused = grantedNames.filter(name => isCommandToolName(name) && !permitsBuiltInTool({ capabilities: childCapabilities }, name, childScope ?? true));
|
|
727
|
+
if (refused.length)
|
|
728
|
+
throw new Error(`These command tools are outside the subagent's permissions: ${refused.join(', ')}`);
|
|
729
|
+
let childProvider = policy.modelPolicy === 'specific' ? policy.provider ?? provider : policy.modelPolicy === 'per-role' ? role.provider ?? provider : provider;
|
|
730
|
+
let childModel = policy.modelPolicy === 'specific' ? policy.model : policy.modelPolicy === 'per-role' ? role.model ?? (childProvider === provider ? model : undefined) : model;
|
|
731
|
+
let childEffort = activeEffort !== undefined && childProvider === provider && childModel === model ? activeEffort : undefined;
|
|
732
|
+
// Routing picks the pair for a subagent that would otherwise inherit its parent's; a graph that names the subagent's model, or a
|
|
733
|
+
// node that sets its own, keeps it. A model chosen for the run pins the parent alone, so its subagents are still routed.
|
|
734
|
+
const inheritsModel = policy.modelPolicy !== 'specific' && !(policy.modelPolicy === 'per-role' && (role.provider !== undefined || role.model !== undefined));
|
|
735
|
+
const unpinnedNode = (configured.provider === undefined && configured.model === undefined) || inheritingChildren.has(configured);
|
|
736
|
+
if (subagentRouting && !poolSubagents && inheritsModel && !fallbackAttempt && unpinnedNode) {
|
|
737
|
+
const decision = decideModelTier({ task: args.task, routing: subagentRouting, baseline: { provider: childProvider, model: childModel ?? model },
|
|
738
|
+
node: {}, configured: options.configuredModels ?? [], levels: poolLevels });
|
|
739
|
+
if (decision.target) {
|
|
740
|
+
childProvider = decision.target.provider;
|
|
741
|
+
childModel = decision.target.model;
|
|
742
|
+
childEffort = decision.target.effort;
|
|
743
|
+
}
|
|
744
|
+
await emit('efficiency.routing.decided', { strategy: 'tiers', role: role.id, tier: decision.tier, reason: decision.reason, evidence: decision.evidence, applied: decision.applied });
|
|
745
|
+
}
|
|
746
|
+
if (poolSubagents && inheritsModel && !fallbackAttempt && unpinnedNode) {
|
|
747
|
+
const decision = decidePoolModel({ task: args.task, routing: poolSubagents, baseline: { provider: childProvider, model: childModel ?? model, effort: childEffort },
|
|
748
|
+
node: {}, configured: options.configuredModels ?? [], levels: poolLevels, quota: await readQuota(context.signal), ...(isPoolClass(args.class) ? { declaredClass: args.class } : {}) });
|
|
749
|
+
const shadow = poolSubagents.mode === 'shadow';
|
|
750
|
+
if (decision.target && !shadow) {
|
|
751
|
+
// A pair that names no level runs at the provider's saved one, not at the level its parent is running at.
|
|
752
|
+
childProvider = decision.target.provider;
|
|
753
|
+
childModel = decision.target.model;
|
|
754
|
+
childEffort = decision.target.effort;
|
|
755
|
+
}
|
|
756
|
+
await emit('efficiency.routing.decided', { strategy: 'pool', role: role.id, poolClass: decision.poolClass, reason: decision.reason, evidence: decision.evidence,
|
|
757
|
+
applied: !shadow && decision.applied, candidates: decision.candidates, blocked: decision.blocked, ...(decision.standing === undefined ? {} : { standing: decision.standing }),
|
|
758
|
+
...(shadow ? { shadow: true, ...(decision.target ? { would: decision.target } : {}) } : {}) });
|
|
759
|
+
}
|
|
584
760
|
const child = { id: role.id, type: 'agent', executor: 'react-basic', name: role.name, instruction: role.instruction,
|
|
585
761
|
provider: childProvider, ...(childModel ? { model: childModel } : {}),
|
|
586
762
|
// With no model named, a child on the same provider runs that provider's default, which may not be the parent's.
|
|
587
|
-
...(
|
|
763
|
+
...(childEffort === undefined ? {} : { reasoningEffort: childEffort }),
|
|
588
764
|
capabilities: childCapabilities, tools: childToolNames,
|
|
589
765
|
completion: { mode: 'single', outcome: 'completed' }, inputSchema: role.inputSchema, outputSchema: role.outputSchema,
|
|
590
766
|
contextPolicy: { history: false, maxChars: Math.min(contextChars, 16000) } };
|
|
767
|
+
if (inheritsModel && unpinnedNode)
|
|
768
|
+
inheritingChildren.add(child);
|
|
591
769
|
if (depth > 0 && active >= (policy.maxConcurrent ?? 3))
|
|
592
770
|
throw new Error('Nested spawn would exceed concurrent subagent limit; finish current work first');
|
|
593
771
|
// A message for the parent ends the wait for a free slot too: the subagents holding the slots keep
|
|
@@ -621,6 +799,8 @@ export async function executeAgentNode(node, options) {
|
|
|
621
799
|
active++;
|
|
622
800
|
total++;
|
|
623
801
|
const id = randomUUID();
|
|
802
|
+
if (requestedRefs.size)
|
|
803
|
+
await emit('subagent.artifacts.shared', { role: role.id, shared: sharedArtifactRefs, refused: refusedRefs });
|
|
624
804
|
const cancel = new AbortController();
|
|
625
805
|
const childSignal = AbortSignal.any([callContext.signal, cancel.signal]);
|
|
626
806
|
const inbox = [];
|
|
@@ -641,6 +821,8 @@ export async function executeAgentNode(node, options) {
|
|
|
641
821
|
const work = (async () => {
|
|
642
822
|
let workspaceArtifact;
|
|
643
823
|
let delegatedWorktree;
|
|
824
|
+
// An ordinary child's worktree where it runs commands: its jobs stop with it, though the worktree is retained.
|
|
825
|
+
let commandWorktree;
|
|
644
826
|
let keepWorktree = false;
|
|
645
827
|
try {
|
|
646
828
|
const parentWorkspace = parentContext.workspace;
|
|
@@ -664,7 +846,7 @@ export async function executeAgentNode(node, options) {
|
|
|
664
846
|
workspace = inside ? join(worktree, inside) : worktree;
|
|
665
847
|
task += `\n\nThis task runs in a separate Git worktree started from the working folder as it stands: ${workspace}. Files ignored by Git (for example node_modules) are not in this worktree. Install what you need inside this worktree if a build or test requires it. Report the commands and tests you ran and their results in the tests list of your completion. This worktree shares the Git repository of the user's working folder: do not create or change stashes, branches, tags or Git configuration. Commit only if the task needs it; commits stay in this worktree, and your result is taken from the files as you leave them.`;
|
|
666
848
|
}
|
|
667
|
-
else if (policy.workspace === 'worktree' && writingChild) {
|
|
849
|
+
else if (policy.workspace === 'worktree' && (writingChild || runsCommands)) {
|
|
668
850
|
if (parentCapabilities.git !== 'write')
|
|
669
851
|
throw new Error('Creating child worktrees requires parent Git write capability');
|
|
670
852
|
const temporaryDirectoryPrefix = join(tmpdir(), 'andorra-subagent-');
|
|
@@ -697,6 +879,8 @@ export async function executeAgentNode(node, options) {
|
|
|
697
879
|
await authorizeWorktree();
|
|
698
880
|
const directory = await mkdtemp(temporaryDirectoryPrefix);
|
|
699
881
|
workspace = join(directory, 'worktree');
|
|
882
|
+
if (runsCommands)
|
|
883
|
+
commandWorktree = workspace;
|
|
700
884
|
await authorizeWorktree();
|
|
701
885
|
await exec('git', [...args, 'worktree', 'add', '--detach', workspace, 'HEAD'], gitOptions);
|
|
702
886
|
workspaceArtifact = await store.put('git-worktree', JSON.stringify({ workspace, role: role.id, note: 'Changes retained for explicit inspection and integration; not merged automatically.' }));
|
|
@@ -712,7 +896,7 @@ export async function executeAgentNode(node, options) {
|
|
|
712
896
|
task, ...(Object.keys(childInputs).length > 0 ? { input: childInputs } : {}) });
|
|
713
897
|
let result;
|
|
714
898
|
try {
|
|
715
|
-
result = await run(child, { ...parentContext, signal: childSignal, steerSignal: undefined, workspace, ...(parentContext.delegationRoots ? { delegationRoots: undefined } : {}) }, depth + 1, childInputs, task, id, fallbackAttempt,
|
|
899
|
+
result = await run(child, { ...parentContext, signal: childSignal, steerSignal: undefined, workspace, ...(parentContext.delegationRoots ? { delegationRoots: undefined } : {}) }, depth + 1, childInputs, task, id, fallbackAttempt, childScope, sharedArtifactRefs);
|
|
716
900
|
}
|
|
717
901
|
catch (error) {
|
|
718
902
|
await emit('subagent.completed', { subagentId: id, role: role.id, status: childSignal.aborted ? 'cancelled' : 'failed' });
|
|
@@ -721,6 +905,8 @@ export async function executeAgentNode(node, options) {
|
|
|
721
905
|
finally {
|
|
722
906
|
if (delegatedWorktree)
|
|
723
907
|
await stopWorktreeJobs(delegatedWorktree.worktree);
|
|
908
|
+
if (commandWorktree)
|
|
909
|
+
await stopWorktreeJobs(commandWorktree);
|
|
724
910
|
}
|
|
725
911
|
if (result.telemetry)
|
|
726
912
|
mergeRunTelemetry(telemetry, result.telemetry);
|
|
@@ -732,6 +918,9 @@ export async function executeAgentNode(node, options) {
|
|
|
732
918
|
scopedRefs.add(artifact.ref);
|
|
733
919
|
references(result.completion?.output, scopedRefs);
|
|
734
920
|
const observation = { status: result.status, reason: result.reason, outcome: result.completion?.outcome, output: result.completion?.output, artifacts: returnedArtifacts };
|
|
921
|
+
// A general subagent has no output schema, so its answer is its summary: without it the parent gets an empty output.
|
|
922
|
+
if (general !== undefined && result.completion?.summary)
|
|
923
|
+
observation.summary = result.completion.summary.slice(0, 16000);
|
|
735
924
|
if (delegatedWorktree) {
|
|
736
925
|
observation.tests = result.completion?.tests ?? [];
|
|
737
926
|
const collected = result.status === 'succeeded' ? await collectChange(delegatedWorktree.worktree, delegatedWorktree.base, parentContext.signal) : undefined;
|
|
@@ -1023,16 +1212,21 @@ export async function executeAgentNode(node, options) {
|
|
|
1023
1212
|
const graphFirstSearch = depth === 0 && !!codeIntel?.active && codeGraphRoute(effectiveTask) === 'graph';
|
|
1024
1213
|
const decisionTask = depth > 0 ? task : options.decisionPreflight?.task ?? effectiveTask;
|
|
1025
1214
|
let result;
|
|
1026
|
-
const telemetry = createRunTelemetry();
|
|
1215
|
+
const telemetry = createRunTelemetry(options.telemetry);
|
|
1027
1216
|
let attempts = depth === 0 ? configured.retry?.maxAttempts ?? 1 : 1;
|
|
1028
1217
|
const efficiency = resolveEfficiency(options.efficiency);
|
|
1029
1218
|
const facts = depth === 0 && (efficiency.contextSelection || efficiency.catalogSelection)
|
|
1030
1219
|
? options.workspaceFacts ?? await collectWorkspaceFacts(context.workspace, { signal: context.signal }) : undefined;
|
|
1031
1220
|
const nodeBaseline = { provider, model };
|
|
1032
1221
|
let routedTier;
|
|
1222
|
+
let routedPoolClass;
|
|
1223
|
+
const poolRouting = efficiency.adaptiveRouting.enabled && efficiency.adaptiveRouting.strategy === 'pool';
|
|
1224
|
+
const baselineEffort = asLevel(resolved.reasoningEffort);
|
|
1033
1225
|
let effortLevel;
|
|
1034
1226
|
let effortEscalated = false;
|
|
1035
1227
|
let escalations = 0;
|
|
1228
|
+
// The model a routed pair installed its thinking level on, so a later attempt whose pair names none can drop it.
|
|
1229
|
+
let poolLevelled;
|
|
1036
1230
|
let previousAttemptReason;
|
|
1037
1231
|
let escalationPending = false;
|
|
1038
1232
|
let escalationFailed = false;
|
|
@@ -1053,10 +1247,11 @@ export async function executeAgentNode(node, options) {
|
|
|
1053
1247
|
fallbackAttempt = true;
|
|
1054
1248
|
const liveNodeId = `${node.id}${subagentId ? '/' + configured.id : ''}${fallbackAttempt ? '#fallback' : ''}`;
|
|
1055
1249
|
const liveModel = await options.getLiveModel?.(liveNodeId, provider, model, context.signal);
|
|
1250
|
+
liveResolved = undefined;
|
|
1056
1251
|
const liveSelected = liveModel !== undefined;
|
|
1057
1252
|
if (liveModel?.sessionModel)
|
|
1058
1253
|
sessionModel = { provider: liveModel.provider, model: liveModel.model };
|
|
1059
|
-
if (liveModel && (liveModel.provider !== provider || liveModel.model !== model)) {
|
|
1254
|
+
if (liveModel && (liveModel.provider !== provider || liveModel.model !== model || liveModel.selectionRevision !== undefined)) {
|
|
1060
1255
|
provider = liveModel.provider;
|
|
1061
1256
|
model = liveModel.model;
|
|
1062
1257
|
resolved = liveModel;
|
|
@@ -1117,12 +1312,14 @@ export async function executeAgentNode(node, options) {
|
|
|
1117
1312
|
const todoChars = JSON.stringify(todoStore.snapshot()).length;
|
|
1118
1313
|
committedChars = taskBase.length + attemptPrompt.length + nodeInstructions.length + historyChars + toolSchemaChars + contractChars + todoChars + 8_000;
|
|
1119
1314
|
repoBudget = executionLimits.maxContextChars - committedChars;
|
|
1120
|
-
repoPolicyRoom = contextChars - (committedChars - toolSchemaChars);
|
|
1315
|
+
repoPolicyRoom = contextChars - (committedChars - toolSchemaChars - nodeInstructions.length - historyChars);
|
|
1121
1316
|
}
|
|
1122
1317
|
let activeRouting;
|
|
1123
1318
|
let attemptTools = tools;
|
|
1124
1319
|
const initialPromptChars = attemptPrompt.length;
|
|
1125
1320
|
let recoverTools;
|
|
1321
|
+
let jevOmittedTools = [];
|
|
1322
|
+
const jevPromptAdditions = [];
|
|
1126
1323
|
const skillContextBudget = () => {
|
|
1127
1324
|
const pinned = [taskBase, attemptPrompt, nodeInstructions,
|
|
1128
1325
|
JSON.stringify(configured.outputSchema ?? { type: 'object' }),
|
|
@@ -1136,11 +1333,12 @@ export async function executeAgentNode(node, options) {
|
|
|
1136
1333
|
.map(({ name, description, parameters }) => ({ name, description, parameters }))).length
|
|
1137
1334
|
+ JSON.stringify((recoverTools ?? []).filter(tool => !attemptTools.includes(tool)).map(tool => tool.name)).length;
|
|
1138
1335
|
const fixedChars = JSON.stringify(pinned).length + historyChars + 8300;
|
|
1139
|
-
const policyRoom = contextChars - fixedChars;
|
|
1336
|
+
const policyRoom = contextChars - (fixedChars - JSON.stringify(nodeInstructions).length - historyChars);
|
|
1140
1337
|
const requestRoom = executionLimits.maxContextChars - fixedChars - schemaChars;
|
|
1141
1338
|
return Math.max(0, Math.min(8000, policyRoom, requestRoom));
|
|
1142
1339
|
};
|
|
1143
1340
|
let memoryBlockAdded = false;
|
|
1341
|
+
let optionalMemoryBlock = '';
|
|
1144
1342
|
let pendingMemoryApplication;
|
|
1145
1343
|
let pendingGraphApplication;
|
|
1146
1344
|
const recordDecision = (event) => {
|
|
@@ -1161,7 +1359,7 @@ export async function executeAgentNode(node, options) {
|
|
|
1161
1359
|
consumers: { answerOnly: answerOnlyTask(decisionTask),
|
|
1162
1360
|
adaptiveRouting: attempt === 1 && depth === 0 && !subagentId && !fallbackAttempt
|
|
1163
1361
|
&& configured.provider === undefined && configured.model === undefined && !options.modelPinned && !liveSelected
|
|
1164
|
-
&& hasAdaptiveAlternative(efficiency.adaptiveRouting, nodeBaseline, options.configuredModels ?? [])
|
|
1362
|
+
&& hasAdaptiveAlternative(efficiency.adaptiveRouting, { ...nodeBaseline, effort: baselineEffort }, options.configuredModels ?? [])
|
|
1165
1363
|
// A node on Auto thinking needs the same three answers to pick among its model's levels.
|
|
1166
1364
|
|| attempt === 1 && depth === 0 && !subagentId && wantedEffort() === 'auto' && levelsFor(provider, model, resolved?.providerType, true).length >= 2,
|
|
1167
1365
|
},
|
|
@@ -1190,7 +1388,8 @@ export async function executeAgentNode(node, options) {
|
|
|
1190
1388
|
});
|
|
1191
1389
|
else {
|
|
1192
1390
|
const shadow = preflight(context.runControl ? AbortSignal.any([context.signal, context.runControl.signal]) : context.signal);
|
|
1193
|
-
|
|
1391
|
+
if (hasRunTelemetry(telemetry))
|
|
1392
|
+
(telemetry.pendingDecisions ??= []).push(shadow.catch(() => undefined));
|
|
1194
1393
|
void shadow.catch(() => undefined);
|
|
1195
1394
|
}
|
|
1196
1395
|
}
|
|
@@ -1206,12 +1405,73 @@ export async function executeAgentNode(node, options) {
|
|
|
1206
1405
|
if (efficiency.adaptiveRouting.enabled && depth === 0 && !subagentId && explicitFallbackRetry) {
|
|
1207
1406
|
await emitEfficiency('efficiency.routing.decided', { tier: undefined, reason: 'pinned', evidence: 'pinned', applied: false, attempt });
|
|
1208
1407
|
}
|
|
1209
|
-
|
|
1408
|
+
const previousPoolEffort = poolEffort;
|
|
1409
|
+
if (efficiency.adaptiveRouting.enabled)
|
|
1410
|
+
poolEffort = undefined;
|
|
1411
|
+
if (poolRouting && depth === 0 && !subagentId && !explicitFallbackRetry) {
|
|
1412
|
+
// Pool routing: the task's class sets the score a pair must reach, and subscription usage chooses among the
|
|
1413
|
+
// pairs that reach it. Shadow mode records the decision and leaves the attempt as it was.
|
|
1414
|
+
const shadow = efficiency.adaptiveRouting.mode === 'shadow';
|
|
1415
|
+
const decision = decidePoolModel({
|
|
1416
|
+
task: effectiveTask, routing: efficiency.adaptiveRouting, baseline: { ...nodeBaseline, effort: baselineEffort },
|
|
1417
|
+
node: { provider: configured.provider, model: configured.model }, modelPinned: options.modelPinned === true || liveSelected,
|
|
1418
|
+
hints: activeRouting?.decisions, configured: options.configuredModels ?? [], levels: poolLevels, quota: await readQuota(context.signal),
|
|
1419
|
+
previous: attempt > 1 && routedPoolClass ? { poolClass: routedPoolClass, reason: previousAttemptReason, escalations } : undefined,
|
|
1420
|
+
});
|
|
1421
|
+
let applied = false;
|
|
1422
|
+
let unresolved = false;
|
|
1423
|
+
let served = false;
|
|
1424
|
+
if (decision.target && !shadow) {
|
|
1425
|
+
const target = decision.target;
|
|
1426
|
+
if (provider === target.provider && model === target.model) {
|
|
1427
|
+
applied = decision.applied;
|
|
1428
|
+
served = true;
|
|
1429
|
+
}
|
|
1430
|
+
else {
|
|
1431
|
+
try {
|
|
1432
|
+
const routed = await resolve(target.provider, target.model);
|
|
1433
|
+
if (routed) {
|
|
1434
|
+
provider = target.provider;
|
|
1435
|
+
model = target.model;
|
|
1436
|
+
resolved = routed;
|
|
1437
|
+
applied = true;
|
|
1438
|
+
served = true;
|
|
1439
|
+
const routedWindow = routed.contextWindow;
|
|
1440
|
+
executionLimits.maxContextChars = routedWindow !== undefined && Number.isSafeInteger(routedWindow) && routedWindow > 0 ? Math.min(contextCharCeiling, routedWindow * 3) : contextCharCeiling;
|
|
1441
|
+
if (depth === 0 && codeLedger && codeIntel)
|
|
1442
|
+
repoBudget = executionLimits.maxContextChars - committedChars;
|
|
1443
|
+
await emit('agent.model.changed', { provider, model, ...(routedWindow === undefined ? {} : { contextWindow: routedWindow }), poolClass: decision.poolClass });
|
|
1444
|
+
}
|
|
1445
|
+
else
|
|
1446
|
+
unresolved = true;
|
|
1447
|
+
}
|
|
1448
|
+
catch {
|
|
1449
|
+
unresolved = true;
|
|
1450
|
+
}
|
|
1451
|
+
}
|
|
1452
|
+
// The level is applied with the node's other level rules below, once per attempt.
|
|
1453
|
+
if (served)
|
|
1454
|
+
poolEffort = target.effort;
|
|
1455
|
+
}
|
|
1456
|
+
if (served)
|
|
1457
|
+
routedPoolClass = decision.poolClass;
|
|
1458
|
+
if (decision.reason === 'escalated' && served)
|
|
1459
|
+
escalations++;
|
|
1460
|
+
if (escalationPending) {
|
|
1461
|
+
escalationPending = false;
|
|
1462
|
+
if (!(decision.reason === 'escalated' && served))
|
|
1463
|
+
escalationFailed = true;
|
|
1464
|
+
}
|
|
1465
|
+
await emitEfficiency('efficiency.routing.decided', { strategy: 'pool', poolClass: decision.poolClass, reason: unresolved ? 'unconfigured' : decision.reason, evidence: decision.evidence, applied, served, attempt,
|
|
1466
|
+
candidates: decision.candidates, blocked: decision.blocked, ...(decision.standing === undefined ? {} : { standing: decision.standing }),
|
|
1467
|
+
...(shadow ? { shadow: true, ...(decision.target ? { would: decision.target } : {}) } : {}) });
|
|
1468
|
+
}
|
|
1469
|
+
if (efficiency.adaptiveRouting.enabled && !poolRouting && depth === 0 && !subagentId && !explicitFallbackRetry) {
|
|
1210
1470
|
const decision = decideModelTier({
|
|
1211
1471
|
task: effectiveTask, routing: efficiency.adaptiveRouting, baseline: nodeBaseline,
|
|
1212
1472
|
node: { provider: configured.provider, model: configured.model }, modelPinned: options.modelPinned === true || liveSelected,
|
|
1213
1473
|
hints: activeRouting?.decisions, configured: options.configuredModels ?? [],
|
|
1214
|
-
previous: attempt > 1 && routedTier ? { tier: routedTier, reason: previousAttemptReason, escalations } : undefined,
|
|
1474
|
+
previous: attempt > 1 && routedTier ? { tier: routedTier, reason: previousAttemptReason, escalations } : undefined, levels: poolLevels,
|
|
1215
1475
|
});
|
|
1216
1476
|
let applied = false;
|
|
1217
1477
|
let unresolved = false;
|
|
@@ -1246,9 +1506,13 @@ export async function executeAgentNode(node, options) {
|
|
|
1246
1506
|
}
|
|
1247
1507
|
}
|
|
1248
1508
|
}
|
|
1249
|
-
|
|
1509
|
+
// The tier's thinking level is applied with the node's other level rules below, as a pool pair's is.
|
|
1510
|
+
if (served) {
|
|
1250
1511
|
routedTier = decision.tier;
|
|
1251
|
-
|
|
1512
|
+
poolEffort = asLevel(decision.target?.effort);
|
|
1513
|
+
}
|
|
1514
|
+
// A tier that keeps the model and changes only its thinking level is an escalation too.
|
|
1515
|
+
if (decision.reason === 'escalated' && (applied || (served && configured.reasoningEffort === undefined && poolEffort !== previousPoolEffort)))
|
|
1252
1516
|
escalations++;
|
|
1253
1517
|
if (escalationPending) {
|
|
1254
1518
|
escalationPending = false;
|
|
@@ -1257,6 +1521,19 @@ export async function executeAgentNode(node, options) {
|
|
|
1257
1521
|
}
|
|
1258
1522
|
await emitEfficiency('efficiency.routing.decided', { tier: decision.tier, reason: unresolved ? 'unconfigured' : decision.reason, evidence: decision.evidence, applied, served, attempt });
|
|
1259
1523
|
}
|
|
1524
|
+
if (poolLevelled && poolEffort === undefined && poolLevelled.provider === provider && poolLevelled.model === model) {
|
|
1525
|
+
// This attempt names no level, so it runs at the saved one, not at the level an earlier pair left in force.
|
|
1526
|
+
try {
|
|
1527
|
+
const saved = await resolve(provider, model);
|
|
1528
|
+
if (saved)
|
|
1529
|
+
resolved = saved;
|
|
1530
|
+
}
|
|
1531
|
+
catch {
|
|
1532
|
+
context.signal.throwIfAborted();
|
|
1533
|
+
}
|
|
1534
|
+
}
|
|
1535
|
+
if (poolEffort === undefined)
|
|
1536
|
+
poolLevelled = undefined;
|
|
1260
1537
|
{
|
|
1261
1538
|
// The thinking level is settled once per attempt, before the first request, and held for the whole attempt:
|
|
1262
1539
|
// a change between requests makes the provider re-read the conversation uncached.
|
|
@@ -1298,6 +1575,8 @@ export async function executeAgentNode(node, options) {
|
|
|
1298
1575
|
if (levelled) {
|
|
1299
1576
|
resolved = levelled;
|
|
1300
1577
|
inForce = decision.level;
|
|
1578
|
+
if (configured.reasoningEffort === undefined && poolEffort !== undefined)
|
|
1579
|
+
poolLevelled = { provider, model };
|
|
1301
1580
|
}
|
|
1302
1581
|
}
|
|
1303
1582
|
catch {
|
|
@@ -1342,6 +1621,7 @@ export async function executeAgentNode(node, options) {
|
|
|
1342
1621
|
}
|
|
1343
1622
|
}
|
|
1344
1623
|
const omitted = recoverTools.filter(tool => !attemptTools.includes(tool));
|
|
1624
|
+
jevOmittedTools = omitted;
|
|
1345
1625
|
const selectedRole = DecisionPolicy.choice(decisions, 'delegation_role');
|
|
1346
1626
|
const role = (policy.roles ?? []).find(item => item.id === selectedRole);
|
|
1347
1627
|
const explicitOtherRole = (policy.roles ?? []).some(item => item.id !== selectedRole
|
|
@@ -1349,24 +1629,27 @@ export async function executeAgentNode(node, options) {
|
|
|
1349
1629
|
if (role && !explicitOtherRole && DecisionPolicy.boolean(decisions, 'needs_delegation') === true) {
|
|
1350
1630
|
attemptTools = attemptTools.map(tool => tool.name !== 'spawn_subagent' ? tool : {
|
|
1351
1631
|
...tool,
|
|
1352
|
-
description: 'Run the selected configured role on a bounded task. Use restore_tools for spawn_subagent if another configured role is needed. Role contract: '
|
|
1632
|
+
description: 'Run the selected configured role on a bounded task. Use restore_tools for spawn_subagent if another configured role is needed. ' + ((policy.freeform ?? 'off') === 'off' ? '' : 'Omit role to run a general subagent instead. ') + 'Role contract: '
|
|
1353
1633
|
+ JSON.stringify({ id: role.id, name: role.name, instruction: role.instruction, inputSchema: role.inputSchema, outputSchema: role.outputSchema }),
|
|
1354
1634
|
parameters: { ...tool.parameters, properties: { ...tool.parameters.properties, role: { type: 'string', enum: [role.id] } } },
|
|
1355
1635
|
});
|
|
1356
1636
|
}
|
|
1357
1637
|
const guidance = decisionExecutionGuidance(decisions, tools.some(tool => tool.name === 'spawn_subagent') ? (policy.roles ?? []).map(role => role.id) : []);
|
|
1358
1638
|
if (guidance)
|
|
1359
|
-
|
|
1639
|
+
jevPromptAdditions.push(`\n\n${guidance}`);
|
|
1360
1640
|
if (omitted.length)
|
|
1361
|
-
|
|
1641
|
+
jevPromptAdditions.push(`\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.`);
|
|
1642
|
+
attemptPrompt += jevPromptAdditions.join('');
|
|
1362
1643
|
const skillBudget = skillContextBudget();
|
|
1363
1644
|
let skillBlock = '';
|
|
1364
1645
|
const selectedSkill = options.decisionManager?.skillRoutingEnabled
|
|
1365
1646
|
? skills.find(skill => !skill.unavailable && skill.id === DecisionPolicy.choice(decisions, 'skill_role')) : undefined;
|
|
1366
1647
|
if (selectedSkill && attemptTools.some(tool => tool.name === 'Skill')) {
|
|
1367
1648
|
const selected = `\nRuntime selected skill: ${JSON.stringify(selectedSkill.id)}. Load this reference lazily with Skill using ${JSON.stringify({ skill: selectedSkill.id })} before applying it, subject to explicit user instructions and required plan publication.`;
|
|
1368
|
-
if (JSON.stringify(selected).length <= skillBudget)
|
|
1649
|
+
if (JSON.stringify(selected).length <= skillBudget) {
|
|
1369
1650
|
skillBlock = selected;
|
|
1651
|
+
jevPromptAdditions.push(selected);
|
|
1652
|
+
}
|
|
1370
1653
|
}
|
|
1371
1654
|
if (skills.length) {
|
|
1372
1655
|
const entries = skillCatalogText(efficiency.catalogSelection ? Math.max(0, skillBudget - JSON.stringify(skillBlock).length - 96) : skillBudget);
|
|
@@ -1408,8 +1691,14 @@ export async function executeAgentNode(node, options) {
|
|
|
1408
1691
|
if (depth === 0 && permissionMode(bounded) === 'plan')
|
|
1409
1692
|
attemptPrompt += `\n\n${PLAN_MODE_INSTRUCTIONS}`;
|
|
1410
1693
|
if (efficiency.catalogSelection && depth === 0) {
|
|
1411
|
-
const
|
|
1412
|
-
codeGraphAvailable: !!codeIntel?.active, memoryAvailable: !!options.memory?.activeFor(options.runId) }
|
|
1694
|
+
const selectionInput = { tools: attemptTools, task: effectiveTask, facts, explicitTools: configured.tools, historicalToolNames,
|
|
1695
|
+
codeGraphAvailable: !!codeIntel?.active, memoryAvailable: !!options.memory?.activeFor(options.runId) };
|
|
1696
|
+
const selection = selectToolCatalog(selectionInput);
|
|
1697
|
+
if (jevOmittedTools.length) {
|
|
1698
|
+
// A schema that local catalog selection would also omit cannot be credited to Jev.
|
|
1699
|
+
const baseline = selectToolCatalog({ ...selectionInput, tools: [...attemptTools, ...jevOmittedTools] });
|
|
1700
|
+
jevOmittedTools = jevOmittedTools.filter(tool => baseline.tools.includes(tool));
|
|
1701
|
+
}
|
|
1413
1702
|
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.`;
|
|
1414
1703
|
const saved = selection.schemaCharsBefore - selection.schemaCharsAfter;
|
|
1415
1704
|
const applied = selection.omitted.length > 0 && saved > note.length + RESTORE_TOOL_SCHEMA_CHARS;
|
|
@@ -1472,7 +1761,10 @@ export async function executeAgentNode(node, options) {
|
|
|
1472
1761
|
memoryBlock = '';
|
|
1473
1762
|
}
|
|
1474
1763
|
if (memoryBlock) {
|
|
1475
|
-
|
|
1764
|
+
if (orchestrator)
|
|
1765
|
+
taskBase += `\n\n${memoryBlock}`;
|
|
1766
|
+
else
|
|
1767
|
+
optionalMemoryBlock = memoryBlock;
|
|
1476
1768
|
spendRepoRoom(memoryBlock.length + 2);
|
|
1477
1769
|
memoryBlockAdded = true;
|
|
1478
1770
|
}
|
|
@@ -1559,8 +1851,15 @@ export async function executeAgentNode(node, options) {
|
|
|
1559
1851
|
efficiency: configured.tools && options.efficiency?.toolMenuRouting
|
|
1560
1852
|
? { ...options.efficiency, toolMenuRouting: { ...options.efficiency.toolMenuRouting, pinnedTools: [...new Set([...(options.efficiency.toolMenuRouting.pinnedTools ?? []), ...configured.tools.map(canonicalToolName)])] } }
|
|
1561
1853
|
: options.efficiency,
|
|
1562
|
-
getLiveModel: options.getLiveModel ? (_id, currentProvider, currentModel, signal
|
|
1854
|
+
getLiveModel: options.getLiveModel ? async (_id, currentProvider, currentModel, signal, appliedRevision, hints) => {
|
|
1855
|
+
const live = await options.getLiveModel(liveNodeId, currentProvider, currentModel, signal, appliedRevision, hints);
|
|
1856
|
+
if (live)
|
|
1857
|
+
liveResolved = live;
|
|
1858
|
+
return live;
|
|
1859
|
+
} : undefined,
|
|
1563
1860
|
adapter: resolved.adapter, contextWindow: resolved.contextWindow, tools: attemptTools, recoverTools: engineRecoverTools, decisionTask,
|
|
1861
|
+
telemetry: options.telemetry,
|
|
1862
|
+
jevToolRouting: jevOmittedTools.length ? { omittedTools: applyToolProfile(jevOmittedTools, options.toolProfile), promptAdditions: jevPromptAdditions } : undefined,
|
|
1564
1863
|
telemetryIdentity: { providerType: resolved.providerType, baseUrl: resolved.baseUrl, role: subagentId ? 'subagent' : orchestrator ? 'orchestrator' : 'agent' }, decisionHints: activeRouting?.decisions, budget, artifactStore: store,
|
|
1565
1864
|
previousConversation: depth === 0 && configured.contextPolicy?.conversation !== 'isolate' && configured.contextPolicy?.skillInheritance !== 'none' && options.previousConversation?.provider === provider && options.previousConversation.model === model ? options.previousConversation : undefined,
|
|
1566
1865
|
onConversationCheckpoint: depth === 0 && options.onConversationCheckpoint ? (messages, state, conversation) => options.onConversationCheckpoint(messages, { ...state, ...(orchestrator ? { orchestratorIntake: {
|
|
@@ -1605,7 +1904,9 @@ export async function executeAgentNode(node, options) {
|
|
|
1605
1904
|
: depth === 0 && policy.enabled ? () => backgroundGuard() ?? (inheritedSkills.length || promptSkills.length ? missingSkillError() : undefined)
|
|
1606
1905
|
: inheritedSkills.length || promptSkills.length ? () => missingSkillError() : undefined, completionPolicy, outputSchema: configured.outputSchema,
|
|
1607
1906
|
history: configured.contextPolicy?.history ? options.history : [],
|
|
1608
|
-
|
|
1907
|
+
// Intake may rely on injected repository research to satisfy its clarification gate.
|
|
1908
|
+
task: orchestrator && attemptRepoBlock ? `${taskBase}\n\n${attemptRepoBlock}` : taskBase,
|
|
1909
|
+
optionalContext: orchestrator ? undefined : { memory: optionalMemoryBlock, repository: attemptRepoBlock },
|
|
1609
1910
|
onUsage: (usage, origin) => {
|
|
1610
1911
|
options.onUsage?.(usage, origin);
|
|
1611
1912
|
},
|
|
@@ -1613,13 +1914,14 @@ export async function executeAgentNode(node, options) {
|
|
|
1613
1914
|
if (result.telemetry) {
|
|
1614
1915
|
recordAttempt(result.telemetry, attempt > 1);
|
|
1615
1916
|
mergeRunTelemetry(telemetry, result.telemetry);
|
|
1616
|
-
result
|
|
1917
|
+
bindRunTelemetry(result, telemetry);
|
|
1617
1918
|
}
|
|
1618
1919
|
previousAttemptReason = result.reason;
|
|
1619
1920
|
previousMutations = result.mutations;
|
|
1620
1921
|
const tiers = efficiency.adaptiveRouting.tiers ?? {};
|
|
1621
1922
|
const higherTier = routedTier === 'economy' ? tiers.balanced ?? tiers.premium : routedTier === 'balanced' ? tiers.premium : undefined;
|
|
1622
|
-
const escalate = efficiency.adaptiveRouting.enabled && depth === 0 && !subagentId
|
|
1923
|
+
const escalate = efficiency.adaptiveRouting.enabled && depth === 0 && !subagentId
|
|
1924
|
+
&& (poolRouting ? routedPoolClass !== undefined && routedPoolClass !== 'escalated' : routedTier !== undefined && higherTier !== undefined) && !escalationFailed
|
|
1623
1925
|
&& escalations < efficiency.adaptiveRouting.maxEscalations && result.status === 'exhausted'
|
|
1624
1926
|
&& ['repeatedToolFailure', 'maxIterations'].includes(result.reason ?? '') && !context.signal.aborted
|
|
1625
1927
|
&& (options.budget === undefined || options.budget.maxToolCalls === undefined || options.budget.toolCalls < options.budget.maxToolCalls);
|