@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
|
@@ -30,6 +30,7 @@ export declare class QaProcessManager {
|
|
|
30
30
|
get(id: string): ManagedProcessInfo | undefined;
|
|
31
31
|
list(): ManagedProcessInfo[];
|
|
32
32
|
logs(id: string, tailBytes?: number): string;
|
|
33
|
+
private logTail;
|
|
33
34
|
waitForUrl(url: string, timeoutMs: number, signal: AbortSignal, processId?: string): Promise<{
|
|
34
35
|
ready: boolean;
|
|
35
36
|
reason?: string;
|
|
@@ -39,7 +40,10 @@ export declare class QaProcessManager {
|
|
|
39
40
|
ready: boolean;
|
|
40
41
|
reason?: string;
|
|
41
42
|
}>;
|
|
42
|
-
wait(id: string, timeoutMs: number, signal: AbortSignal): Promise<ManagedProcessInfo
|
|
43
|
+
wait(id: string, timeoutMs: number, signal: AbortSignal): Promise<ManagedProcessInfo & {
|
|
44
|
+
waitExpired?: true;
|
|
45
|
+
tail?: string;
|
|
46
|
+
}>;
|
|
43
47
|
stop(id: string): Promise<void>;
|
|
44
48
|
stopAll(options?: {
|
|
45
49
|
keepPersistent?: boolean;
|
|
@@ -109,6 +109,9 @@ export class QaProcessManager {
|
|
|
109
109
|
const record = this.processes.get(id);
|
|
110
110
|
if (!record)
|
|
111
111
|
throw new Error(`no QA process named "${id}"`);
|
|
112
|
+
return this.logTail(record, tailBytes);
|
|
113
|
+
}
|
|
114
|
+
logTail(record, tailBytes) {
|
|
112
115
|
const text = record.persistent ? readTail(record.logPath, tailBytes) : Buffer.concat(record.chunks).toString('utf8');
|
|
113
116
|
const tail = text.length > tailBytes ? text.slice(-tailBytes) : text;
|
|
114
117
|
const status = record.exited ? `\n[process exited code=${record.exited.code ?? record.exited.signal}${record.spawnError ? ` error=${record.spawnError}` : ''}]` : '';
|
|
@@ -161,12 +164,15 @@ export class QaProcessManager {
|
|
|
161
164
|
record.child.off('close', onClose);
|
|
162
165
|
signal.removeEventListener('abort', onAbort);
|
|
163
166
|
};
|
|
164
|
-
const settle = () => {
|
|
167
|
+
const settle = (waitExpired = false) => {
|
|
165
168
|
if (settled)
|
|
166
169
|
return;
|
|
167
170
|
settled = true;
|
|
168
171
|
cleanup();
|
|
169
|
-
resolve(
|
|
172
|
+
resolve({
|
|
173
|
+
...this.info(record),
|
|
174
|
+
...(waitExpired ? { waitExpired: true, tail: this.logTail(record, 2_000) } : {}),
|
|
175
|
+
});
|
|
170
176
|
};
|
|
171
177
|
const onClose = () => settle();
|
|
172
178
|
const onAbort = () => {
|
|
@@ -176,7 +182,7 @@ export class QaProcessManager {
|
|
|
176
182
|
cleanup();
|
|
177
183
|
reject(signal.reason ?? new Error('Wait aborted'));
|
|
178
184
|
};
|
|
179
|
-
const timer = setTimeout(settle, timeoutMs);
|
|
185
|
+
const timer = setTimeout(() => settle(!record.exited), timeoutMs);
|
|
180
186
|
record.child.on('close', onClose);
|
|
181
187
|
signal.addEventListener('abort', onAbort, { once: true });
|
|
182
188
|
if (record.exited)
|
|
@@ -3,18 +3,21 @@ import { createGoalCompletionVerifier } from './goal-completion-verification.js'
|
|
|
3
3
|
import { goalSystemNote, withGoalSystemNote } from './session-goal.js';
|
|
4
4
|
import { validateExtendedToolSchema } from './tool-schema-compatibility.js';
|
|
5
5
|
import { canonicalToolName } from './tool-names.js';
|
|
6
|
-
import {
|
|
6
|
+
import { schemaChars } from './tool-catalog.js';
|
|
7
|
+
import { ContextUsageAnchor, IMAGE_INPUT_REJECTED_NOTE, JevOutputBaseline, bypassAccounting, contextInputLimit, contextThreshold, dropRejectedImages, microcompactToolResults, pruneHistoricalImages, serializeContext } from './context-budget.js';
|
|
7
8
|
import { browserEventArguments, disposeBrowserSessions, isBrowserToolName } from './browser-session.js';
|
|
8
9
|
import { runRegularTurnLoop } from '../vendor/zcode/source/runtime/turn-loop.js';
|
|
9
10
|
import { validateInitialModelToolInput, getInitialInputValidationModelContent } from '../vendor/zcode/source/tool/executor/validation.js';
|
|
11
|
+
import { coerceStringArguments } from './tool-argument-coercion.js';
|
|
10
12
|
import { andorraIsContextOverflow } from '../vendor/engine/runtime/ai/utils/overflow.js';
|
|
11
13
|
import { toEngineResponse, engineModel } from './engine/protocol.js';
|
|
12
14
|
import { ProviderRequestError, runFailureCode } from './providers.js';
|
|
15
|
+
import { ProviderTurnTimeoutError } from './provider-turn-deadline.js';
|
|
13
16
|
import { COMPLETION_ALONE_ERROR, COMPLETION_TOOL, COMPLETION_GUIDANCE, FINAL_RESPONSE_GUIDANCE, OUTPUT_STOOD_IN_NOTE, RESPONSE_STRUCTURE_GUIDANCE, completionTool, completionResponse, parseCompletion, withoutTrailingEnvelope } from './completion.js';
|
|
14
17
|
import { MAX_GATE_ASKS, MAX_IDLE_UNFINISHED_ASKS, finalAnswerGate, proseIsFinalAnswer } from './completion-gates.js';
|
|
15
18
|
import { TestEditGuard, testEditNudge, undoneWorkNudge } from './test-edit-guard.js';
|
|
16
19
|
import { unchangedWorkNudge } from './decision/taskKind.js';
|
|
17
|
-
import { HistoryCompactor, CompactionRecoveryError, pinnedContextChars, PINNED_CONTEXT_GUIDANCE, retireSupersededNodeScaffolding
|
|
20
|
+
import { HistoryCompactor, CompactionRecoveryError, pinnedContextChars, pinnedContextBreakdown, PINNED_CONTEXT_GUIDANCE, retireSupersededNodeScaffolding } from './context-compaction.js';
|
|
18
21
|
import { createHash, randomUUID } from 'node:crypto';
|
|
19
22
|
import { ToolFailureTracker } from './tool-failure-tracker.js';
|
|
20
23
|
import { CommandExitError, FileReadRequiredError } from './tool-errors.js';
|
|
@@ -24,7 +27,7 @@ import { monotonicNow, elapsedMs } from './duration.js';
|
|
|
24
27
|
import { planToolDependencies, requiresToolBarrier } from './tool-dependencies.js';
|
|
25
28
|
import { realpath, stat } from 'node:fs/promises';
|
|
26
29
|
import { isAbsolute, relative, resolve } from 'node:path';
|
|
27
|
-
import { createRunTelemetry, recordEdit, recordErrorOnce, recordTestCommand, recordToolFailure, recordToolUse } from './telemetry/capture.js';
|
|
30
|
+
import { resolveTelemetryCapture, bindRunTelemetry, createRunTelemetry, recordEdit, recordErrorOnce, recordTestCommand, recordToolFailure, recordToolUse } from './telemetry/capture.js';
|
|
28
31
|
import { isTestCommandLine } from './telemetry/classify.js';
|
|
29
32
|
import { callFileDiff, diffLineStats, fileDiffTarget, readFileSnapshot } from './tool-diff-stats.js';
|
|
30
33
|
import { TodoStore } from './todos.js';
|
|
@@ -135,6 +138,7 @@ function retireTodoUpdates(messages, retire) {
|
|
|
135
138
|
}
|
|
136
139
|
export class AndorraAgentEngine {
|
|
137
140
|
async execute(options) {
|
|
141
|
+
options = { ...options, telemetry: resolveTelemetryCapture(options.telemetry) };
|
|
138
142
|
const limits = resolveLimits(options.limits);
|
|
139
143
|
const configuredContextCharCeiling = options.contextCharCeiling ?? limits.maxContextChars;
|
|
140
144
|
for (const [name, value] of Object.entries(limits)) {
|
|
@@ -157,12 +161,13 @@ export class AndorraAgentEngine {
|
|
|
157
161
|
const result = {
|
|
158
162
|
id: options.runId ?? randomUUID(), graph: options.graph ?? DEFAULT_GRAPH, provider: options.provider, model: options.model,
|
|
159
163
|
status: 'exhausted', usage: { inputTokens: 0, outputTokens: 0, requests: 0 }, toolCalls: 0,
|
|
160
|
-
telemetry: createRunTelemetry(),
|
|
161
164
|
};
|
|
165
|
+
bindRunTelemetry(result, createRunTelemetry(options.telemetry));
|
|
162
166
|
const invocationId = randomUUID();
|
|
163
167
|
let modelTurn = 0;
|
|
164
168
|
const onEvent = options.onEvent;
|
|
165
|
-
|
|
169
|
+
const jevOutputBaseline = options.jevOutputBaseline ?? new JevOutputBaseline();
|
|
170
|
+
options = { ...options, jevOutputBaseline, onEvent: event => onEvent?.({ ...event, data: { ...event.data, invocationId } }) };
|
|
166
171
|
const verifyCompletion = options.verifyCompletion ?? (options.goalCompletionVerification ? createGoalCompletionVerifier({
|
|
167
172
|
goal: options.goalCompletionVerification.goal, model: options.model,
|
|
168
173
|
generate: request => generateWithUsage(options, result, request),
|
|
@@ -200,16 +205,13 @@ export class AndorraAgentEngine {
|
|
|
200
205
|
if (offersTodoList)
|
|
201
206
|
tools.push({
|
|
202
207
|
name: 'update_todos', executionMode: 'sequential',
|
|
203
|
-
description: 'Publish the visible task todo list.
|
|
204
|
-
parameters: { type: 'object', properties: { todos: { type: 'array', minItems: 1, maxItems: 100, items: { type: 'object', properties: { id: { type: 'string', minLength: 1, maxLength: 80 }, text: { type: 'string', minLength: 1, maxLength: 500 }, status: { type: 'string', enum: ['pending', 'in_progress', 'completed'] } }, required: ['id', 'text', 'status'], additionalProperties: false } } }, required: ['todos'], additionalProperties: false },
|
|
208
|
+
description: 'Publish the visible task todo list. For a phase with separately trackable steps, put each step in the same todos array with its own id and status and set parentId to the phase id. Only top-level items can have subtasks. Keep parentId on subtask updates. Mark a phase completed once its subtasks and any remaining phase work are complete. Items omitted from the context snapshot are retained automatically. Initialize before substantive work; keep stable ids and update statuses as work proceeds. Send it beside other tool calls, or beside complete_agent for the final statuses. Preserve unfinished items across graph stages.',
|
|
209
|
+
parameters: { type: 'object', properties: { todos: { type: 'array', minItems: 1, maxItems: 100, items: { type: 'object', properties: { id: { type: 'string', minLength: 1, maxLength: 80 }, text: { type: 'string', minLength: 1, maxLength: 500 }, status: { type: 'string', enum: ['pending', 'in_progress', 'completed'] }, parentId: { type: 'string', minLength: 1, maxLength: 80 } }, required: ['id', 'text', 'status'], additionalProperties: false } } }, required: ['todos'], additionalProperties: false },
|
|
205
210
|
execute: async (args, ctx) => {
|
|
206
211
|
ctx.signal.throwIfAborted();
|
|
207
212
|
if (Object.keys(args).some(key => key !== 'todos'))
|
|
208
213
|
throw new Error('Only the todos argument is accepted');
|
|
209
|
-
const
|
|
210
|
-
const submittedIds = new Set(submitted.map(item => item.id));
|
|
211
|
-
const retained = todoStore.snapshot().filter(item => omittedTodoIds.has(item.id) && !submittedIds.has(item.id));
|
|
212
|
-
const todos = todoStore.update([...submitted, ...retained]);
|
|
214
|
+
const todos = todoStore.update(args.todos, Math.min(12_000, Math.floor(limits.maxContextChars / 8)), omittedTodoIds);
|
|
213
215
|
await emit('graph.todos.updated', { todos });
|
|
214
216
|
ctx.signal.throwIfAborted();
|
|
215
217
|
options.onTodosUpdated?.();
|
|
@@ -241,6 +243,9 @@ export class AndorraAgentEngine {
|
|
|
241
243
|
const recoverTools = executableRecovery.filter(advertisable);
|
|
242
244
|
const decisionCatalog = [...tools, ...recoverTools.filter(tool => !tools.some(current => current.name === tool.name))];
|
|
243
245
|
const omittedTools = recoverTools.filter(tool => !tools.includes(tool));
|
|
246
|
+
const jevOmittedSchemas = [...new Map((options.jevToolRouting?.omittedTools ?? []).filter(permittedTool)
|
|
247
|
+
.map(tool => [tool.name, tool])).values()];
|
|
248
|
+
const jevPromptAdditions = options.jevToolRouting?.promptAdditions ?? [];
|
|
244
249
|
if (omittedTools.length)
|
|
245
250
|
tools.push({
|
|
246
251
|
name: 'restore_tools', executionMode: 'sequential',
|
|
@@ -402,6 +407,13 @@ ${runtimeEnvironmentNote()}` + (options.systemPrompt ? `\nAgent instructions:\n$
|
|
|
402
407
|
? { role: 'user', content: `${options.task}\n\n${attachmentReferenceBlock(options.attachments.refs)}` }
|
|
403
408
|
: { role: 'user', content: options.task });
|
|
404
409
|
}
|
|
410
|
+
if ((options.subagentId || !options.resumeMessages) && options.optionalContext) {
|
|
411
|
+
for (const source of ['memory', 'repository']) {
|
|
412
|
+
const content = options.optionalContext[source];
|
|
413
|
+
if (content)
|
|
414
|
+
messages.push({ role: 'user', content, optionalContext: source });
|
|
415
|
+
}
|
|
416
|
+
}
|
|
405
417
|
retireTodoUpdates(messages, isLegacyTodoPlaceholder);
|
|
406
418
|
let todoMessage = options.subagentId ? undefined : { role: 'user', content: '' };
|
|
407
419
|
if (todoMessage)
|
|
@@ -457,7 +469,6 @@ ${runtimeEnvironmentNote()}` + (options.systemPrompt ? `\nAgent instructions:\n$
|
|
|
457
469
|
let stall;
|
|
458
470
|
const retriedReads = new Set();
|
|
459
471
|
const historyCompactor = new HistoryCompactor();
|
|
460
|
-
let pinnedClipAttempted = false;
|
|
461
472
|
const contextUsage = new ContextUsageAnchor();
|
|
462
473
|
const continuationState = options.subagentId ? undefined : options.resumeState;
|
|
463
474
|
let repairs = continuationState?.repairs ?? 0;
|
|
@@ -769,6 +780,7 @@ ${runtimeEnvironmentNote()}` + (options.systemPrompt ? `\nAgent instructions:\n$
|
|
|
769
780
|
: `${error.message} Resume with the retained conversation after restoring the summary provider.` });
|
|
770
781
|
return true;
|
|
771
782
|
};
|
|
783
|
+
let appliedModelRevision;
|
|
772
784
|
const prepareTurn = async () => {
|
|
773
785
|
iteration++;
|
|
774
786
|
modelTurn++;
|
|
@@ -786,8 +798,9 @@ ${runtimeEnvironmentNote()}` + (options.systemPrompt ? `\nAgent instructions:\n$
|
|
|
786
798
|
}
|
|
787
799
|
signal.throwIfAborted();
|
|
788
800
|
await control?.wait(signal);
|
|
789
|
-
const liveModel = await options.getLiveModel?.(options.nodeId, options.provider, options.model, signal);
|
|
790
|
-
if (liveModel && (liveModel.provider !== options.provider || liveModel.model !== options.model)) {
|
|
801
|
+
const liveModel = await options.getLiveModel?.(options.nodeId, options.provider, options.model, signal, appliedModelRevision, options.decisionHints);
|
|
802
|
+
if (liveModel && (liveModel.provider !== options.provider || liveModel.model !== options.model || (liveModel.selectionRevision !== undefined && appliedModelRevision !== liveModel.selectionRevision))) {
|
|
803
|
+
appliedModelRevision = liveModel.selectionRevision;
|
|
791
804
|
options.provider = liveModel.provider;
|
|
792
805
|
options.model = liveModel.model;
|
|
793
806
|
options.adapter = liveModel.adapter;
|
|
@@ -843,7 +856,12 @@ ${runtimeEnvironmentNote()}` + (options.systemPrompt ? `\nAgent instructions:\n$
|
|
|
843
856
|
finishingRequest = finishing;
|
|
844
857
|
if (factsMode)
|
|
845
858
|
replacePostflightGuidance(finishing ? FINISH_ONLY_GUIDANCE : '');
|
|
846
|
-
const
|
|
859
|
+
const eligible = (tool) => tool.providerVisible !== false && (tool.name === 'update_todos'
|
|
860
|
+
? maxTodoCalls === undefined || todoCalls < maxTodoCalls : finishing ? false
|
|
861
|
+
: isPreparedPlanCall(tool) ? preparedPlanCalls < maxPreparedPlanCalls
|
|
862
|
+
: isRestorationCall(tool) ? restorationCalls < maxRestorationCalls
|
|
863
|
+
: isWidgetCall(tool) ? widgetCalls < maxWidgetCalls : executionBudgetAvailable);
|
|
864
|
+
const advertisedTools = [...tools.filter(eligible), completionTool(options)];
|
|
847
865
|
if (finishing)
|
|
848
866
|
await emit('efficiency.facts.finish_only', { iteration });
|
|
849
867
|
const schemaKey = JSON.stringify(advertisedTools.map(({ name, description, parameters }) => ({ name, description, parameters })));
|
|
@@ -852,6 +870,8 @@ ${runtimeEnvironmentNote()}` + (options.systemPrompt ? `\nAgent instructions:\n$
|
|
|
852
870
|
retireTodoUpdates(messages, (_call, owner, observation) => !inheritedMessages.has(owner) && !!observation && !observation.content.startsWith('Tool error:'));
|
|
853
871
|
closeAssistantTail();
|
|
854
872
|
const threshold = contextThreshold(model.contextWindow, model.maxTokens);
|
|
873
|
+
const inputTokenLimit = contextInputLimit(model.contextWindow, model.maxTokens);
|
|
874
|
+
const exceedsRequestBudget = (tokens) => contextChars() > limits.maxContextChars || tokens > inputTokenLimit;
|
|
855
875
|
if (control && !options.subagentId && control.takeCompactionRequest())
|
|
856
876
|
compactRequested = true;
|
|
857
877
|
if (compactRequested) {
|
|
@@ -907,21 +927,46 @@ ${runtimeEnvironmentNote()}` + (options.systemPrompt ? `\nAgent instructions:\n$
|
|
|
907
927
|
await emit('agent.context.microcompacted', { ...cleaned, reason: 'contextPressure', beforeTokens: beforeCleanup.tokens, afterTokens: afterCleanup.tokens, tokenSource: beforeCleanup.source, afterTokenSource: afterCleanup.source });
|
|
908
928
|
}
|
|
909
929
|
}
|
|
910
|
-
|
|
930
|
+
// Prefer losing re-fetchable references to altering directives or recent continuation.
|
|
931
|
+
const retireOptionalContext = async (reason) => {
|
|
932
|
+
let pressure = contextUsage.pressure(messages, toolContextChars, schemaKey);
|
|
933
|
+
let removedTotal = 0;
|
|
934
|
+
for (const source of ['memory', 'repository']) {
|
|
935
|
+
// After a provider rejection the local estimate cannot tell us how much to remove.
|
|
936
|
+
if (reason === 'localBudget' && !exceedsRequestBudget(pressure.tokens))
|
|
937
|
+
break;
|
|
938
|
+
const beforeChars = contextChars();
|
|
939
|
+
let removed = 0;
|
|
940
|
+
for (let index = messages.length - 1; index >= 0; index--) {
|
|
941
|
+
if (messages[index].role !== 'user' || messages[index].optionalContext !== source)
|
|
942
|
+
continue;
|
|
943
|
+
messages.splice(index, 1);
|
|
944
|
+
removed++;
|
|
945
|
+
}
|
|
946
|
+
if (!removed)
|
|
947
|
+
continue;
|
|
948
|
+
removedTotal += removed;
|
|
949
|
+
const beforeTokens = pressure.tokens;
|
|
950
|
+
pressure = contextUsage.pressure(messages, toolContextChars, schemaKey);
|
|
951
|
+
await emit('agent.context.optional_retired', { reason, source, removed, savedChars: beforeChars - contextChars(), beforeTokens, afterTokens: pressure.tokens });
|
|
952
|
+
}
|
|
953
|
+
return { pressure, removed: removedTotal };
|
|
954
|
+
};
|
|
955
|
+
const { pressure } = await retireOptionalContext('localBudget');
|
|
911
956
|
const tokenPressure = pressure.tokens >= threshold;
|
|
912
|
-
|
|
913
|
-
const hardPressure = contextChars() > limits.maxContextChars || tokenPressure;
|
|
914
|
-
if (hardPressure) {
|
|
957
|
+
if (tokenPressure || exceedsRequestBudget(pressure.tokens)) {
|
|
915
958
|
let compacted;
|
|
916
959
|
try {
|
|
917
960
|
const target = tokenPressure ? Math.min(limits.maxContextChars, Math.floor(contextChars() * Math.min(.7, threshold * .7 / pressure.tokens))) : limits.maxContextChars;
|
|
918
|
-
|
|
961
|
+
// Aim for headroom, but do not require the summary to fit the soft target.
|
|
962
|
+
compacted = await historyCompactor.compact(messages, toolContextChars, limits.maxContextChars, { options, result, signal: operationSignal, invocationId }, { triggerChars: 0, targetChars: Math.max(1, target - pinnedContextChars(messages, toolContextChars)), protectDiscovery: false, keepRecentToolTurns: 2, retireAllEligible: true,
|
|
963
|
+
// Use the compactor's actual retention set, including protected recent exchanges.
|
|
964
|
+
canFitRetained: minimum => contextUsage.pressure(minimum, toolContextChars, schemaKey).tokens <= inputTokenLimit });
|
|
919
965
|
}
|
|
920
966
|
catch (error) {
|
|
921
967
|
signal.throwIfAborted();
|
|
922
|
-
if (!operationSignal.aborted && !
|
|
923
|
-
|
|
924
|
-
await emit('agent.context.compaction.deferred', { reason: error.reason, contextChars: compacted.chars });
|
|
968
|
+
if (!operationSignal.aborted && !exceedsRequestBudget(pressure.tokens) && error instanceof CompactionRecoveryError && error.reason !== 'content_filter') {
|
|
969
|
+
await emit('agent.context.compaction.deferred', { reason: error.reason, contextChars: contextChars() });
|
|
925
970
|
}
|
|
926
971
|
else {
|
|
927
972
|
if (!operationSignal.aborted && !await recoverCompaction(error))
|
|
@@ -930,29 +975,22 @@ ${runtimeEnvironmentNote()}` + (options.systemPrompt ? `\nAgent instructions:\n$
|
|
|
930
975
|
return;
|
|
931
976
|
}
|
|
932
977
|
}
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
...recentHumanMessages(messages, 2)]);
|
|
940
|
-
const allowance = tokenPressure ? Math.min(limits.maxContextChars, Math.floor(contextChars() * threshold * .7 / Math.max(1, pressure.tokens))) : limits.maxContextChars;
|
|
941
|
-
const clipped = clipOldPinnedMessages(messages, protect, Math.max(1, contextChars() - allowance));
|
|
942
|
-
if (clipped.clipped) {
|
|
943
|
-
await emit('agent.context.pinned_clipped', { ...clipped, contextChars: contextChars() });
|
|
944
|
-
iteration--;
|
|
945
|
-
return;
|
|
946
|
-
}
|
|
947
|
-
}
|
|
948
|
-
if (!compacted.fits) {
|
|
978
|
+
const currentPressure = contextUsage.pressure(messages, toolContextChars, schemaKey);
|
|
979
|
+
if (compacted?.removed)
|
|
980
|
+
await emit('agent.context.compacted', { reason: tokenPressure ? 'tokenBudget' : 'explicitCharLimit', removedExchanges: compacted.removed, contextChars: compacted.chars, beforeTokens: pressure.tokens, afterTokens: currentPressure.tokens, tokenSource: pressure.source, threshold });
|
|
981
|
+
const overBudget = exceedsRequestBudget(currentPressure.tokens);
|
|
982
|
+
// Never truncate user instructions just to make a request fit.
|
|
983
|
+
if (overBudget) {
|
|
949
984
|
result.reason = 'maxContextChars';
|
|
950
|
-
|
|
985
|
+
const breakdown = pinnedContextBreakdown(messages, toolContextChars);
|
|
986
|
+
const pinnedChars = Object.values(breakdown).reduce((total, chars) => total + chars, 0);
|
|
987
|
+
await emit('agent.context.rejected', { reason: 'pinnedContextExceededLimit', guidance: PINNED_CONTEXT_GUIDANCE,
|
|
988
|
+
contextChars: contextChars(), maxContextChars: limits.maxContextChars, pinnedChars, ...breakdown,
|
|
989
|
+
estimatedInputTokens: currentPressure.tokens, tokenThreshold: threshold, inputTokenLimit, tokenSource: currentPressure.source });
|
|
951
990
|
await emit('agent.message', { text: PINNED_CONTEXT_GUIDANCE });
|
|
952
991
|
return;
|
|
953
992
|
}
|
|
954
993
|
}
|
|
955
|
-
pinnedClipAttempted = false;
|
|
956
994
|
await emit('agent.turn.started', { iteration });
|
|
957
995
|
await emit('agent.iteration.started', { iteration });
|
|
958
996
|
let requestMessages = structuredClone(messages);
|
|
@@ -973,9 +1011,12 @@ ${runtimeEnvironmentNote()}` + (options.systemPrompt ? `\nAgent instructions:\n$
|
|
|
973
1011
|
return;
|
|
974
1012
|
}
|
|
975
1013
|
signal.throwIfAborted();
|
|
976
|
-
|
|
1014
|
+
const requestChars = serializeContext(requestMessages).length + toolContextChars;
|
|
1015
|
+
const transformedPressure = options.transformContext ? contextUsage.pressure(requestMessages, toolContextChars, schemaKey) : undefined;
|
|
1016
|
+
if (requestChars > limits.maxContextChars || (transformedPressure && transformedPressure.tokens > inputTokenLimit)) {
|
|
977
1017
|
result.reason = 'maxContextChars';
|
|
978
|
-
await emit('agent.context.rejected', { reason: 'transformExceededLimit'
|
|
1018
|
+
await emit('agent.context.rejected', { reason: 'transformExceededLimit', contextChars: requestChars,
|
|
1019
|
+
maxContextChars: limits.maxContextChars, estimatedInputTokens: transformedPressure?.tokens, inputTokenLimit });
|
|
979
1020
|
return;
|
|
980
1021
|
}
|
|
981
1022
|
selectedStep = pendingStep;
|
|
@@ -1023,7 +1064,8 @@ ${runtimeEnvironmentNote()}` + (options.systemPrompt ? `\nAgent instructions:\n$
|
|
|
1023
1064
|
return;
|
|
1024
1065
|
}
|
|
1025
1066
|
if (!operationSignal.aborted) {
|
|
1026
|
-
const contextOverflow =
|
|
1067
|
+
const contextOverflow = (error instanceof ProviderRequestError && error.contextOverflow)
|
|
1068
|
+
|| andorraIsContextOverflow({ ...toEngineResponse({ text: '', toolCalls: [] }, model), stopReason: 'error', errorMessage: error instanceof Error ? error.message : String(error) }, model.contextWindow);
|
|
1027
1069
|
if (!contextOverflow && refusedRequest(error) && requestMessages.some(message => message.images?.length)) {
|
|
1028
1070
|
const dropped = dropRejectedImages(messages);
|
|
1029
1071
|
if (dropped) {
|
|
@@ -1033,26 +1075,50 @@ ${runtimeEnvironmentNote()}` + (options.systemPrompt ? `\nAgent instructions:\n$
|
|
|
1033
1075
|
return;
|
|
1034
1076
|
}
|
|
1035
1077
|
}
|
|
1036
|
-
if (!contextOverflow
|
|
1078
|
+
if (!contextOverflow)
|
|
1037
1079
|
throw error;
|
|
1080
|
+
const stopOnOverflow = () => {
|
|
1081
|
+
result.providerOverflow = true;
|
|
1082
|
+
throw error;
|
|
1083
|
+
};
|
|
1084
|
+
if (overflowRecoveries >= 1)
|
|
1085
|
+
return stopOnOverflow();
|
|
1086
|
+
const retryOverflow = () => {
|
|
1087
|
+
if (forced)
|
|
1088
|
+
forceToolCall = true;
|
|
1089
|
+
if (finishing)
|
|
1090
|
+
finishOnly = true;
|
|
1091
|
+
iteration--;
|
|
1092
|
+
};
|
|
1093
|
+
// Retiring references does not spend the history-compaction retry. If this
|
|
1094
|
+
// smaller request still overflows, try the remaining safe reduction once.
|
|
1095
|
+
if ((await retireOptionalContext('providerOverflow')).removed) {
|
|
1096
|
+
retryOverflow();
|
|
1097
|
+
return;
|
|
1098
|
+
}
|
|
1099
|
+
overflowRecoveries++;
|
|
1038
1100
|
let compacted;
|
|
1039
1101
|
try {
|
|
1040
1102
|
if (routedRun())
|
|
1041
1103
|
dropSupersededSnapshots();
|
|
1042
|
-
const
|
|
1043
|
-
|
|
1104
|
+
const beforeChars = contextChars();
|
|
1105
|
+
const recoveryLimit = Math.min(limits.maxContextChars, beforeChars - 1);
|
|
1106
|
+
const recoveryTarget = Math.floor(beforeChars * .65);
|
|
1107
|
+
compacted = await historyCompactor.compact(messages, toolContextChars, recoveryLimit, { options, result, signal: operationSignal, invocationId }, { triggerChars: 0, targetChars: Math.max(1, recoveryTarget - pinnedContextChars(messages, toolContextChars)), keepRecentToolTurns: 2, retireAllEligible: true });
|
|
1044
1108
|
}
|
|
1045
1109
|
catch (compactionError) {
|
|
1046
1110
|
signal.throwIfAborted();
|
|
1047
1111
|
if (!operationSignal.aborted && !await recoverCompaction(compactionError))
|
|
1048
1112
|
throw compactionError;
|
|
1049
1113
|
overflowRecoveries--;
|
|
1050
|
-
|
|
1114
|
+
retryOverflow();
|
|
1051
1115
|
return;
|
|
1052
1116
|
}
|
|
1053
1117
|
if (!compacted.fits || !compacted.removed)
|
|
1054
|
-
|
|
1118
|
+
return stopOnOverflow();
|
|
1055
1119
|
await emit('agent.context.compacted', { reason: 'providerOverflow', removedExchanges: compacted.removed, contextChars: compacted.chars });
|
|
1120
|
+
retryOverflow();
|
|
1121
|
+
return;
|
|
1056
1122
|
}
|
|
1057
1123
|
iteration--;
|
|
1058
1124
|
return;
|
|
@@ -1067,10 +1133,24 @@ ${runtimeEnvironmentNote()}` + (options.systemPrompt ? `\nAgent instructions:\n$
|
|
|
1067
1133
|
if (selectedStep) {
|
|
1068
1134
|
automaticTurns++;
|
|
1069
1135
|
if (selectedStep.completion)
|
|
1070
|
-
await emit('decision.turn_bypassed', { kind: selectedStep.kind, selection: selectedReason ?? 'jev_selected', ...bypassAccounting(selectedStepInput, options.provider, options.model) });
|
|
1136
|
+
await emit('decision.turn_bypassed', { kind: selectedStep.kind, selection: selectedReason ?? 'jev_selected', ...bypassAccounting(selectedStepInput, options.provider, options.model, jevOutputBaseline.estimate(options.provider, options.model)) });
|
|
1071
1137
|
}
|
|
1072
1138
|
else {
|
|
1073
1139
|
automaticTurns = 0;
|
|
1140
|
+
if (jevOmittedSchemas.length && response.usage?.requests !== 0 && (response.usage?.inputTokens ?? 0) > 0) {
|
|
1141
|
+
const advertisedNames = new Set(advertisedTools.map(tool => tool.name));
|
|
1142
|
+
const omitted = jevOmittedSchemas.filter(tool => eligible(tool) && !advertisedNames.has(tool.name));
|
|
1143
|
+
if (omitted.length) {
|
|
1144
|
+
const routingPromptChars = jevPromptAdditions.reduce((chars, text) => chars + (requestMessages.some(message => message.content.includes(text)) ? JSON.stringify(text).length - 2 : 0), 0);
|
|
1145
|
+
const restore = advertisedTools.find(tool => tool.name === 'restore_tools');
|
|
1146
|
+
const restoreChars = restore ? schemaChars([restore]) - 2 : 0;
|
|
1147
|
+
const estimatedInputTokens = Math.floor((schemaChars(omitted) - 2 - routingPromptChars - restoreChars) / 3);
|
|
1148
|
+
if (estimatedInputTokens > 0)
|
|
1149
|
+
await emit('decision.prompt_reduced', {
|
|
1150
|
+
estimatedInputTokens, providerId: options.provider, model: options.model,
|
|
1151
|
+
});
|
|
1152
|
+
}
|
|
1153
|
+
}
|
|
1074
1154
|
await emit('agent.model.completed', { usage: { ...result.usage } });
|
|
1075
1155
|
}
|
|
1076
1156
|
signal.throwIfAborted();
|
|
@@ -1291,10 +1371,10 @@ ${runtimeEnvironmentNote()}` + (options.systemPrompt ? `\nAgent instructions:\n$
|
|
|
1291
1371
|
closeUserWait();
|
|
1292
1372
|
return emit(type, { ...data, toolCallId: entry.call.id });
|
|
1293
1373
|
},
|
|
1294
|
-
...(askUser ? { askUser: async (
|
|
1374
|
+
...(askUser ? { askUser: async (...args) => {
|
|
1295
1375
|
waitSince ??= monotonicNow();
|
|
1296
1376
|
try {
|
|
1297
|
-
return await askUser(
|
|
1377
|
+
return await askUser(...args);
|
|
1298
1378
|
}
|
|
1299
1379
|
finally {
|
|
1300
1380
|
closeUserWait();
|
|
@@ -1450,7 +1530,7 @@ ${runtimeEnvironmentNote()}` + (options.systemPrompt ? `\nAgent instructions:\n$
|
|
|
1450
1530
|
}
|
|
1451
1531
|
else {
|
|
1452
1532
|
await emit('efficiency.prepared.executed', { kind: selectedStep.kind, succeeded: item?.isError !== true });
|
|
1453
|
-
await emit('decision.turn_bypassed', { kind: selectedStep.kind, selection: selectedReasonOf(selectedStep), ...bypassAccounting(selectedStepInput, options.provider, options.model) });
|
|
1533
|
+
await emit('decision.turn_bypassed', { kind: selectedStep.kind, selection: selectedReasonOf(selectedStep), ...bypassAccounting(selectedStepInput, options.provider, options.model, jevOutputBaseline.estimate(options.provider, options.model)) });
|
|
1454
1534
|
}
|
|
1455
1535
|
}
|
|
1456
1536
|
if (result.reason)
|
|
@@ -1820,14 +1900,16 @@ ${runtimeEnvironmentNote()}` + (options.systemPrompt ? `\nAgent instructions:\n$
|
|
|
1820
1900
|
return { id: call.id, content: 'Not executed: tool failure limit reached.', success: false };
|
|
1821
1901
|
if (entry.tool && !entry.immediate) {
|
|
1822
1902
|
try {
|
|
1823
|
-
const
|
|
1903
|
+
const argumentsIn = entry.tool.prepareArguments ? entry.tool.prepareArguments(entry.args) : entry.args;
|
|
1824
1904
|
const validatorTool = { ...entry.tool, parameters: entry.tool.validationParameters ?? entry.tool.parameters };
|
|
1905
|
+
// "60000" for an integer or a JSON-encoded list for an array: take the value the string spells.
|
|
1906
|
+
const normalized = coerceStringArguments(argumentsIn, validatorTool.parameters);
|
|
1825
1907
|
if (!await validateExtendedToolSchema(validatorTool.parameters, normalized ?? {})) {
|
|
1826
1908
|
const validation = validateInitialModelToolInput(normalized ?? {}, { metadata: { name: entry.tool.name }, inputSchema: validatorTool.parameters });
|
|
1827
1909
|
if (validation)
|
|
1828
1910
|
throw new Error(getInitialInputValidationModelContent(validation));
|
|
1829
1911
|
}
|
|
1830
|
-
if (entry.tool.prepareArguments)
|
|
1912
|
+
if (entry.tool.prepareArguments || normalized !== argumentsIn)
|
|
1831
1913
|
entry.args = normalized;
|
|
1832
1914
|
}
|
|
1833
1915
|
catch (error) {
|
|
@@ -1872,6 +1954,7 @@ ${runtimeEnvironmentNote()}` + (options.systemPrompt ? `\nAgent instructions:\n$
|
|
|
1872
1954
|
// The starting state for the finish-time test-edit check is captured while the model takes its first
|
|
1873
1955
|
// turn; nothing waits for it, and the finally below stops it if the run ends first.
|
|
1874
1956
|
void testEditGuard.start(signal);
|
|
1957
|
+
let providerTimeout;
|
|
1875
1958
|
try {
|
|
1876
1959
|
await emit('agent.session.started', { graph: result.graph, provider: options.provider, model: options.model, executor: 'andorra-core', engineOrigin: 'andorra-core', engineRevision: '29628c9acdb81b703bbd4080c207a0e7ce5e276e' });
|
|
1877
1960
|
await runRegularTurnLoop(enginePorts);
|
|
@@ -1889,6 +1972,8 @@ ${runtimeEnvironmentNote()}` + (options.systemPrompt ? `\nAgent instructions:\n$
|
|
|
1889
1972
|
if (error.contextOverflow)
|
|
1890
1973
|
result.providerOverflow = true;
|
|
1891
1974
|
}
|
|
1975
|
+
if (!cancelled && !deadline && error instanceof ProviderTurnTimeoutError)
|
|
1976
|
+
providerTimeout = error;
|
|
1892
1977
|
if (!cancelled && !deadline && !(error instanceof ClarificationRequiredError)) {
|
|
1893
1978
|
// A model request's failure was recorded where it happened; this reuses that code rather than counting it again.
|
|
1894
1979
|
result.failureCode = recordErrorOnce(result.telemetry, error, runFailureCode(error));
|
|
@@ -1897,7 +1982,9 @@ ${runtimeEnvironmentNote()}` + (options.systemPrompt ? `\nAgent instructions:\n$
|
|
|
1897
1982
|
result.reason = cancelled ? 'cancelled' : deadline ? 'wallTimeMs' : error instanceof Error ? error.message : 'Runtime failure';
|
|
1898
1983
|
}
|
|
1899
1984
|
try {
|
|
1900
|
-
|
|
1985
|
+
// A provider deadline or context rejection does not abort the run signal. Save the
|
|
1986
|
+
// interrupted turn at the same safe boundary as cancellation so Resume can retry.
|
|
1987
|
+
if ((signal.aborted || providerTimeout || result.providerOverflow || result.reason === 'maxContextChars') && !options.subagentId && options.onConversationCheckpoint) {
|
|
1901
1988
|
const retained = structuredClone(messages.filter(message => !isRunSnapshot(message)));
|
|
1902
1989
|
const observed = new Set(retained.filter(message => message.role === 'tool').map(message => message.toolCallId));
|
|
1903
1990
|
for (const message of retained.slice())
|
|
@@ -1915,6 +2002,10 @@ ${runtimeEnvironmentNote()}` + (options.systemPrompt ? `\nAgent instructions:\n$
|
|
|
1915
2002
|
remainingWallTimeMs: budget.remainingMs(), ...archiveState(),
|
|
1916
2003
|
}, { provider: options.provider, model: options.model, ...archiveState(), messages: structuredClone(retained) });
|
|
1917
2004
|
}
|
|
2005
|
+
if (providerTimeout) {
|
|
2006
|
+
const { phase, limitMs, elapsedMs, lastProgressAgeMs } = providerTimeout;
|
|
2007
|
+
await emit('agent.model.timeout', { phase, limitMs, elapsedMs, lastProgressAgeMs });
|
|
2008
|
+
}
|
|
1918
2009
|
if (!options.subagentId)
|
|
1919
2010
|
result.todos = todoStore.snapshot();
|
|
1920
2011
|
if (!options.subagentId && widgetStore && widgetStore.definitionsList().length)
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type ProviderConfig, type ReasoningEffort } from './providers.js';
|
|
2
|
+
type ProbeProvider = Pick<ProviderConfig, 'type' | 'baseUrl'>;
|
|
3
|
+
export declare function currentReasoningProbeSubject(signal?: AbortSignal): Promise<string | undefined>;
|
|
4
|
+
/** Undefined means no saved result was available. An empty list is a completed probe that accepted no levels. */
|
|
5
|
+
export declare function readReasoningProbe(provider: ProbeProvider, model: string, signal?: AbortSignal): Promise<ReasoningEffort[] | undefined>;
|
|
6
|
+
/** Persist only the latest result for a portable model, under the account that initiated the probe. */
|
|
7
|
+
export declare function queueReasoningProbe(directory: string, subject: string, provider: ProbeProvider, model: string, supported: readonly ReasoningEffort[]): Promise<void>;
|
|
8
|
+
/** Serialize uploads across engine processes and acknowledge only the exact result sent. */
|
|
9
|
+
export declare function flushReasoningProbes(directory: string, signal?: AbortSignal): Promise<void>;
|
|
10
|
+
export {};
|