@andorra-labs/code 0.1.15 → 0.1.16
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/agent-definitions.js +29 -6
- package/dist/src/agent-execution.js +4 -2
- package/dist/src/agent-mcp.d.ts +1 -1
- package/dist/src/agent-mcp.js +13 -9
- package/dist/src/app-server/protocol.d.ts +4 -1
- package/dist/src/app-server/protocol.js +1 -1
- package/dist/src/app-server.d.ts +107 -0
- package/dist/src/app-server.js +893 -22
- package/dist/src/auth/deployment.js +2 -2
- package/dist/src/browser-runner.js +1 -0
- package/dist/src/browser-ui/style.css +3 -3
- package/dist/src/browser-ui/tokens.css +27 -16
- package/dist/src/claude-provider.js +3 -1
- package/dist/src/cli.js +22 -8
- package/dist/src/codex-errors.js +4 -1
- package/dist/src/command-screens.js +5 -3
- package/dist/src/commands.d.ts +2 -1
- package/dist/src/compaction-phrases.d.ts +4 -0
- package/dist/src/compaction-phrases.js +20 -0
- package/dist/src/context-compaction.js +2 -1
- package/dist/src/decision/DecisionManager.js +3 -2
- package/dist/src/decision/requestPhrases.d.ts +4 -0
- package/dist/src/decision/requestPhrases.js +23 -0
- package/dist/src/github-inbox.d.ts +55 -0
- package/dist/src/github-inbox.js +153 -0
- package/dist/src/graph-health.js +7 -3
- package/dist/src/graph-provider-portability.js +32 -10
- package/dist/src/graph-quota.d.ts +29 -2
- package/dist/src/graph-quota.js +68 -10
- package/dist/src/graph-runner.js +24 -7
- package/dist/src/graph-server.d.ts +1 -1
- package/dist/src/graph-server.js +9 -7
- package/dist/src/graph-ui/app.js +110 -33
- package/dist/src/graph-ui/controls.css +1 -0
- package/dist/src/graph-ui/embed.js +2 -2
- package/dist/src/graph-ui/icons.js +1 -0
- package/dist/src/graph-ui/index.html +1 -1
- package/dist/src/graph-ui/manager.css +1 -1
- package/dist/src/graph-ui/manager.js +2 -2
- package/dist/src/graph-ui/sidebar.js +30 -0
- package/dist/src/graph-ui/studio-canvas.js +26 -13
- package/dist/src/graph-ui/studio.css +15 -7
- package/dist/src/graph-ui/studio.js +11 -4
- package/dist/src/graph-ui/style.css +77 -45
- package/dist/src/graph-ui/theme.js +3 -36
- package/dist/src/graph-ui/tokens.css +27 -19
- package/dist/src/graphs.js +4 -3
- package/dist/src/membership.d.ts +20 -1
- package/dist/src/membership.js +29 -4
- package/dist/src/model-metadata.d.ts +1 -1
- package/dist/src/model-metadata.js +4 -2
- package/dist/src/plan-pass.d.ts +59 -0
- package/dist/src/plan-pass.js +165 -0
- package/dist/src/provider-engine.js +3 -0
- package/dist/src/providers.d.ts +17 -0
- package/dist/src/providers.js +68 -19
- package/dist/src/pull-request-checks.d.ts +26 -0
- package/dist/src/pull-request-checks.js +56 -0
- package/dist/src/pull-request-conversation.d.ts +134 -0
- package/dist/src/pull-request-conversation.js +221 -0
- package/dist/src/pull-request-create.d.ts +175 -0
- package/dist/src/pull-request-create.js +392 -0
- package/dist/src/pull-request-details.d.ts +242 -0
- package/dist/src/pull-request-details.js +614 -0
- package/dist/src/pull-request-edit.d.ts +23 -0
- package/dist/src/pull-request-edit.js +91 -0
- package/dist/src/pull-request-logs.d.ts +76 -0
- package/dist/src/pull-request-logs.js +172 -0
- package/dist/src/pull-request-merge.d.ts +112 -0
- package/dist/src/pull-request-merge.js +258 -0
- package/dist/src/pull-request-review.d.ts +137 -0
- package/dist/src/pull-request-review.js +401 -0
- package/dist/src/pull-requests.d.ts +43 -2
- package/dist/src/pull-requests.js +112 -21
- package/dist/src/react-runtime.js +37 -4
- package/dist/src/remote/engine-pool.js +16 -4
- package/dist/src/run-control.d.ts +10 -0
- package/dist/src/run-control.js +24 -0
- package/dist/src/run-progress.d.ts +10 -0
- package/dist/src/run-progress.js +122 -0
- package/dist/src/run-records.d.ts +2 -2
- package/dist/src/runtime.d.ts +5 -1
- package/dist/src/runtime.js +14 -2
- package/dist/src/subagent-run.js +1 -0
- package/dist/src/telemetry/capture-core.d.ts +17 -0
- package/dist/src/telemetry/capture-core.js +59 -1
- package/dist/src/telemetry/classify.d.ts +3 -1
- package/dist/src/telemetry/classify.js +37 -0
- package/dist/src/telemetry/emitter.d.ts +2 -0
- package/dist/src/telemetry/emitter.js +42 -5
- package/dist/src/telemetry/schema.d.ts +22 -0
- package/dist/src/telemetry/schema.js +68 -1
- package/dist/src/telemetry/surface.d.ts +1 -0
- package/dist/src/telemetry/uploader.d.ts +6 -1
- package/dist/src/telemetry/uploader.js +22 -3
- package/dist/src/terminal-ui.js +1 -1
- package/dist/src/transcript.js +8 -2
- package/dist/src/types.d.ts +7 -0
- package/dist/src/usage-analytics.js +18 -10
- package/package.json +1 -1
package/dist/src/runtime.d.ts
CHANGED
|
@@ -45,6 +45,8 @@ export interface InvocationBudget {
|
|
|
45
45
|
export interface RunResult {
|
|
46
46
|
providerRequestFailed?: boolean;
|
|
47
47
|
providerOverflow?: boolean;
|
|
48
|
+
/** The telemetry error code of the failure that ended the run, when one did. */
|
|
49
|
+
failureCode?: string;
|
|
48
50
|
telemetry?: import('./telemetry/capture.js').RunTelemetry;
|
|
49
51
|
id: string;
|
|
50
52
|
graph: typeof DEFAULT_GRAPH | Graph;
|
|
@@ -88,6 +90,8 @@ export interface AgentContinuationState {
|
|
|
88
90
|
failures: import('./tool-failure-tracker.js').ToolFailureTracker;
|
|
89
91
|
remainingToolCalls?: number;
|
|
90
92
|
remainingWallTimeMs?: number;
|
|
93
|
+
/** Set only on a checkpoint handed to a resume the user asked to compact (/compact during a run); never saved back. */
|
|
94
|
+
compactRequested?: true;
|
|
91
95
|
copies?: {
|
|
92
96
|
messages: Message[];
|
|
93
97
|
state: AgentContinuationState;
|
|
@@ -109,7 +113,7 @@ export interface AgentContinuationState {
|
|
|
109
113
|
};
|
|
110
114
|
}
|
|
111
115
|
export declare function timerReminderText(prompt: string): string;
|
|
112
|
-
type RetainedWake = 'timer' | 'auto-fix';
|
|
116
|
+
type RetainedWake = 'timer' | 'auto-fix' | 'fix-checks';
|
|
113
117
|
export declare function wakeMessageText(wake: RetainedWake | undefined, message: string): string;
|
|
114
118
|
export declare function turnModelTask(turn: {
|
|
115
119
|
task: string;
|
package/dist/src/runtime.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { attachmentReferenceBlock } from './attachments.js';
|
|
2
2
|
import { advertiseAvailableTools } from './tool-availability.js';
|
|
3
|
-
import { createRunTelemetry, recordModelUse } from './telemetry/capture.js';
|
|
3
|
+
import { createRunTelemetry, recordErrorOnce, recordModelUse, recordRunError } from './telemetry/capture.js';
|
|
4
|
+
import { runFailureCode } from './providers.js';
|
|
4
5
|
import { pricingFor } from './model-tiers.js';
|
|
5
6
|
import { bucketEndpoint } from './telemetry/schema.js';
|
|
6
7
|
export const DEFAULT_GRAPH = Object.freeze({
|
|
@@ -18,6 +19,9 @@ export function timerReminderText(prompt) {
|
|
|
18
19
|
export function wakeMessageText(wake, message) {
|
|
19
20
|
if (wake === 'auto-fix')
|
|
20
21
|
return `Delivered by Auto-fix (not a message from the user): ${message}`;
|
|
22
|
+
// The person pressed Fix with Agent in the PR tab; the text is the engine's, built from GitHub's checks.
|
|
23
|
+
if (wake === 'fix-checks')
|
|
24
|
+
return `Sent by the user with Fix with Agent in the PR tab: ${message}`;
|
|
21
25
|
return wake === 'timer' ? timerReminderText(message) : message;
|
|
22
26
|
}
|
|
23
27
|
export function turnModelTask(turn) {
|
|
@@ -60,10 +64,18 @@ export async function generateWithUsage(options, result, request) {
|
|
|
60
64
|
model: request.model,
|
|
61
65
|
role: options.telemetryIdentity?.role ?? (options.subagentId ? 'subagent' : 'other'),
|
|
62
66
|
};
|
|
67
|
+
// Every model request of the run goes through here (agent turns, compaction summaries, auxiliary calls), so this is
|
|
68
|
+
// where an error the provider recovered from is recorded: before the retry or resend, never only on failure.
|
|
69
|
+
const recordError = (code) => { recordRunError(result.telemetry ??= createRunTelemetry(), code ?? 'provider_error'); };
|
|
63
70
|
const response = await options.adapter.generate({ ...request, onRequest: () => {
|
|
64
71
|
recordedRequests++;
|
|
65
72
|
add({ inputTokens: 0, outputTokens: 0, requests: 1 });
|
|
66
|
-
}
|
|
73
|
+
}, onRetry: retry => { recordError(retry.code); return request.onRetry?.(retry); },
|
|
74
|
+
onRecoveredError: code => { recordError(code); request.onRecoveredError?.(code); } }).catch(error => {
|
|
75
|
+
// The failed request is recorded here, before a caller recovers from it (a verifier's failed verdict, a distiller's
|
|
76
|
+
// fallback, a compaction or image retry). Handlers further up reuse this record instead of counting it again.
|
|
77
|
+
if (!request.signal.aborted)
|
|
78
|
+
recordErrorOnce(result.telemetry ??= createRunTelemetry(), error, runFailureCode(error));
|
|
67
79
|
if (recordedRequests > 0) {
|
|
68
80
|
result.telemetry ??= createRunTelemetry();
|
|
69
81
|
recordModelUse(result.telemetry, { ...identity, usage: { requests: recordedRequests } });
|
package/dist/src/subagent-run.js
CHANGED
|
@@ -467,6 +467,7 @@ export class SubagentRunner {
|
|
|
467
467
|
status: settled, ...(why === undefined ? {} : { reason: why }),
|
|
468
468
|
...(result?.providerRequestFailed || run.healthProviderFailed ? { providerRequestFailed: true } : {}),
|
|
469
469
|
...(result?.providerOverflow ? { providerOverflow: true } : {}),
|
|
470
|
+
...(result?.failureCode === undefined ? {} : { errorCode: result.failureCode }),
|
|
470
471
|
...(result?.telemetry !== undefined || run.probeModels.size > 0 ? { telemetry: finishedTelemetry } : {}),
|
|
471
472
|
...(result?.toolCalls === undefined ? {} : { toolCalls: result.toolCalls }),
|
|
472
473
|
})).catch(() => { });
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Usage } from '../types.js';
|
|
2
|
+
import { type TelemetryErrorRecord, type TelemetrySavings } from './schema.js';
|
|
2
3
|
import type { ModelTuple } from './aggregate.js';
|
|
3
4
|
import type { ModelPricing } from '../efficiency.js';
|
|
4
5
|
export interface JevTally {
|
|
@@ -76,6 +77,12 @@ export interface RunTelemetry {
|
|
|
76
77
|
models: ModelTuple[];
|
|
77
78
|
jev: JevTally;
|
|
78
79
|
providerOverflow?: boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Every error the run met, in the order each code was first seen, including the ones it recovered from
|
|
82
|
+
* (a provider retry that later succeeded, an attempt the engine ran again). Append-only: a later error or
|
|
83
|
+
* a run that carries on never removes or replaces an earlier entry.
|
|
84
|
+
*/
|
|
85
|
+
errors?: TelemetryErrorRecord[];
|
|
79
86
|
pendingQuestions: number;
|
|
80
87
|
pendingByInvocation: Record<string, number>;
|
|
81
88
|
pendingDecisions?: Promise<unknown>[];
|
|
@@ -95,6 +102,16 @@ export declare function recordModelUse(telemetry: RunTelemetry, input: {
|
|
|
95
102
|
pricing?: ModelPricing;
|
|
96
103
|
}): void;
|
|
97
104
|
export declare function recordToolUse(telemetry: RunTelemetry, name: string, failed: boolean): void;
|
|
105
|
+
export declare function recordRunError(telemetry: RunTelemetry, code: unknown, count?: number): void;
|
|
106
|
+
/**
|
|
107
|
+
* Records a thrown error once, however many handlers see it on its way up (the request path, then a compactor, the
|
|
108
|
+
* agent loop or a graph). Returns the code it was recorded under, which later handlers reuse.
|
|
109
|
+
*/
|
|
110
|
+
export declare function recordErrorOnce(telemetry: RunTelemetry, error: unknown, code: string): string;
|
|
111
|
+
/** The code an error was already recorded under, if any handler recorded it. */
|
|
112
|
+
export declare function recordedErrorCode(error: unknown): string | undefined;
|
|
113
|
+
/** The measured savings a run's efficiency tally holds, as sent in run.finished; undefined when nothing was tallied. */
|
|
114
|
+
export declare function savingsFrom(telemetry: RunTelemetry): TelemetrySavings | undefined;
|
|
98
115
|
export declare function recordAttempt(telemetry: RunTelemetry, retry: boolean): void;
|
|
99
116
|
export declare function recordEdit(telemetry: RunTelemetry, filePath: string, created: boolean): void;
|
|
100
117
|
export declare function recordTestCommand(telemetry: RunTelemetry): void;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { bucketEndpoint, bucketModel, bucketProviderType, bucketToolName } from './schema.js';
|
|
1
|
+
import { TELEMETRY_ERROR_KINDS, bucketEndpoint, bucketErrorCode, bucketModel, bucketProviderType, bucketToolName, } from './schema.js';
|
|
2
2
|
import { isDocumentationPath, isTestPath } from './classify.js';
|
|
3
3
|
import { usageCostMicroUsd } from '../model-tiers.js';
|
|
4
4
|
export function createEfficiencyTally() {
|
|
@@ -171,6 +171,62 @@ export function recordToolUse(telemetry, name, failed) {
|
|
|
171
171
|
telemetry.toolFailures += 1;
|
|
172
172
|
telemetry.task.activity = true;
|
|
173
173
|
}
|
|
174
|
+
export function recordRunError(telemetry, code, count = 1) {
|
|
175
|
+
if (!Number.isSafeInteger(count) || count < 1)
|
|
176
|
+
return;
|
|
177
|
+
const errors = telemetry.errors ??= [];
|
|
178
|
+
let bucket = bucketErrorCode(code);
|
|
179
|
+
// At most fifteen named codes are kept; every later new code is counted under `other`, so no count is lost.
|
|
180
|
+
const named = errors.filter(record => record.code !== 'other').length;
|
|
181
|
+
if (bucket !== 'other' && !errors.some(record => record.code === bucket) && named >= TELEMETRY_ERROR_KINDS - 1)
|
|
182
|
+
bucket = 'other';
|
|
183
|
+
const entry = errors.find(record => record.code === bucket);
|
|
184
|
+
if (entry)
|
|
185
|
+
entry.count += count;
|
|
186
|
+
else
|
|
187
|
+
errors.push({ code: bucket, count });
|
|
188
|
+
}
|
|
189
|
+
const recordedFailures = new WeakMap();
|
|
190
|
+
/**
|
|
191
|
+
* Records a thrown error once, however many handlers see it on its way up (the request path, then a compactor, the
|
|
192
|
+
* agent loop or a graph). Returns the code it was recorded under, which later handlers reuse.
|
|
193
|
+
*/
|
|
194
|
+
export function recordErrorOnce(telemetry, error, code) {
|
|
195
|
+
if (error === null || (typeof error !== 'object' && typeof error !== 'function')) {
|
|
196
|
+
recordRunError(telemetry, code);
|
|
197
|
+
return code;
|
|
198
|
+
}
|
|
199
|
+
const previous = recordedFailures.get(error);
|
|
200
|
+
if (previous !== undefined)
|
|
201
|
+
return previous;
|
|
202
|
+
recordedFailures.set(error, code);
|
|
203
|
+
recordRunError(telemetry, code);
|
|
204
|
+
return code;
|
|
205
|
+
}
|
|
206
|
+
/** The code an error was already recorded under, if any handler recorded it. */
|
|
207
|
+
export function recordedErrorCode(error) {
|
|
208
|
+
return error !== null && (typeof error === 'object' || typeof error === 'function') ? recordedFailures.get(error) : undefined;
|
|
209
|
+
}
|
|
210
|
+
/** The measured savings a run's efficiency tally holds, as sent in run.finished; undefined when nothing was tallied. */
|
|
211
|
+
export function savingsFrom(telemetry) {
|
|
212
|
+
const tally = telemetry.efficiency;
|
|
213
|
+
if (!tally)
|
|
214
|
+
return undefined;
|
|
215
|
+
return {
|
|
216
|
+
toolResultsFiltered: tally.toolResults.filtered,
|
|
217
|
+
toolResultOriginalChars: tally.toolResults.originalChars,
|
|
218
|
+
toolResultKeptChars: tally.toolResults.keptChars,
|
|
219
|
+
toolResultExpandedChars: tally.toolResults.expandedChars,
|
|
220
|
+
schemaCharsBefore: tally.catalog.schemaCharsBefore,
|
|
221
|
+
schemaCharsAfter: tally.catalog.schemaCharsAfter,
|
|
222
|
+
contextOmittedChars: tally.context.omittedChars,
|
|
223
|
+
contextDuplicates: tally.context.duplicates,
|
|
224
|
+
preparedSteps: tally.prepared.steps,
|
|
225
|
+
preparedExecuted: tally.prepared.executed,
|
|
226
|
+
deterministicSteps: tally.prepared.deterministic,
|
|
227
|
+
postflightSkipped: tally.postflight.skipped,
|
|
228
|
+
};
|
|
229
|
+
}
|
|
174
230
|
export function recordAttempt(telemetry, retry) {
|
|
175
231
|
telemetry.attempts += 1;
|
|
176
232
|
if (retry)
|
|
@@ -299,6 +355,8 @@ export function mergeRunTelemetry(into, from) {
|
|
|
299
355
|
into.task.testCommand ||= from.task.testCommand;
|
|
300
356
|
into.task.activity ||= from.task.activity;
|
|
301
357
|
into.providerOverflow ||= from.providerOverflow;
|
|
358
|
+
for (const record of from.errors ?? [])
|
|
359
|
+
recordRunError(into, record.code, record.count);
|
|
302
360
|
for (const [invocation, questions] of Object.entries(from.pendingByInvocation))
|
|
303
361
|
into.pendingByInvocation[invocation] = questions;
|
|
304
362
|
const keyedPending = Object.values(into.pendingByInvocation).reduce((sum, questions) => sum + questions, 0);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type TelemetryFailureClass, type TelemetryFramework, type TelemetryLanguage, type TelemetryOutcome, type TelemetryTaskCategory, type TelemetryWorkspaceBucket } from './schema.js';
|
|
1
|
+
import { type TelemetryFailureClass, type TelemetryFramework, type TelemetryLanguage, type TelemetryOutcome, type TelemetryStopReason, type TelemetryTaskCategory, type TelemetryWorkspaceBucket } from './schema.js';
|
|
2
2
|
export type ClassifiableStatus = 'succeeded' | 'exhausted' | 'cancelled' | 'infrastructure_error' | 'needs_clarification' | 'interrupted';
|
|
3
3
|
export interface FailureEvidence {
|
|
4
4
|
reason?: string;
|
|
@@ -9,6 +9,8 @@ export declare function classifyOutcome(status: ClassifiableStatus, evidence?: F
|
|
|
9
9
|
outcome: TelemetryOutcome;
|
|
10
10
|
failureClass?: TelemetryFailureClass;
|
|
11
11
|
};
|
|
12
|
+
/** Why a run that did not complete stopped; undefined for a completed run. */
|
|
13
|
+
export declare function stopReasonFor(status: ClassifiableStatus, evidence?: FailureEvidence): TelemetryStopReason | undefined;
|
|
12
14
|
export declare function languageForPath(filePath: string): TelemetryLanguage | undefined;
|
|
13
15
|
export declare function isDocumentationPath(filePath: string): boolean;
|
|
14
16
|
export declare function isTestPath(filePath: string): boolean;
|
|
@@ -16,6 +16,43 @@ export function classifyOutcome(status, evidence = {}) {
|
|
|
16
16
|
return { outcome: 'failed', failureClass: 'provider_error' };
|
|
17
17
|
return { outcome: 'failed', failureClass: 'infrastructure' };
|
|
18
18
|
}
|
|
19
|
+
/** Why a run that did not complete stopped; undefined for a completed run. */
|
|
20
|
+
export function stopReasonFor(status, evidence = {}) {
|
|
21
|
+
if (status === 'succeeded')
|
|
22
|
+
return undefined;
|
|
23
|
+
if (status === 'cancelled')
|
|
24
|
+
return 'user_stopped';
|
|
25
|
+
if (status === 'interrupted')
|
|
26
|
+
return 'app_closed';
|
|
27
|
+
if (status === 'needs_clarification')
|
|
28
|
+
return 'needs_clarification';
|
|
29
|
+
if (status === 'exhausted')
|
|
30
|
+
return exhaustionReason(evidence.reason ?? '');
|
|
31
|
+
if (evidence.providerOverflow)
|
|
32
|
+
return 'context_overflow';
|
|
33
|
+
if (evidence.providerRequestFailed)
|
|
34
|
+
return 'provider_error';
|
|
35
|
+
return 'runtime_error';
|
|
36
|
+
}
|
|
37
|
+
function exhaustionReason(reason) {
|
|
38
|
+
if (reason === 'wallTimeMs')
|
|
39
|
+
return 'wall_time';
|
|
40
|
+
if (reason === 'repeatedToolFailure')
|
|
41
|
+
return 'repeated_tool_failure';
|
|
42
|
+
if (reason === 'maxIterations' || reason.startsWith('loop.maxIterations:'))
|
|
43
|
+
return 'max_iterations';
|
|
44
|
+
if (reason === 'maxToolCalls')
|
|
45
|
+
return 'max_tool_calls';
|
|
46
|
+
if (reason === 'maxTodoCalls')
|
|
47
|
+
return 'max_todo_calls';
|
|
48
|
+
if (reason === 'maxContextChars')
|
|
49
|
+
return 'max_context';
|
|
50
|
+
if (reason.startsWith('maxNodeVisits:'))
|
|
51
|
+
return 'max_node_visits';
|
|
52
|
+
if (reason.includes('metadata allowance exhausted'))
|
|
53
|
+
return 'metadata_limit';
|
|
54
|
+
return 'other_limit';
|
|
55
|
+
}
|
|
19
56
|
function exhaustionClass(reason) {
|
|
20
57
|
if (reason === 'wallTimeMs')
|
|
21
58
|
return 'timeout';
|
|
@@ -27,6 +27,8 @@ export interface RunFinishInput extends TelemetryContext, RunDimensions {
|
|
|
27
27
|
reason?: string;
|
|
28
28
|
providerRequestFailed?: boolean;
|
|
29
29
|
providerOverflow?: boolean;
|
|
30
|
+
/** The telemetry error code of the failure that ended the run (`http_429`, `ECONNRESET`), when one did. */
|
|
31
|
+
errorCode?: string;
|
|
30
32
|
telemetry?: RunTelemetry;
|
|
31
33
|
workspace?: string;
|
|
32
34
|
toolCalls?: number;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto';
|
|
2
2
|
import { release } from 'node:os';
|
|
3
3
|
import { configDirectory, loadConfig } from '../config.js';
|
|
4
|
-
import { classifyOutcome, classifyTaskCounts } from './classify.js';
|
|
5
|
-
import { hasRunTelemetry } from './capture.js';
|
|
4
|
+
import { classifyOutcome, classifyTaskCounts, stopReasonFor } from './classify.js';
|
|
5
|
+
import { createRunTelemetry, hasRunTelemetry, recordRunError, savingsFrom } from './capture.js';
|
|
6
6
|
import { aggregateModelTuples } from './aggregate.js';
|
|
7
7
|
import { ensureInstallId, telemetryDirectory } from './identity.js';
|
|
8
|
-
import { TELEMETRY_PERMISSION_MODES, TELEMETRY_ROUTING, bucketAppVersion, bucketArchitecture, bucketGraph, bucketOperatingSystem, isMetadataTool, telemetryEventId, telemetryTimestamp, validateTelemetryEvent, } from './schema.js';
|
|
8
|
+
import { TELEMETRY_PERMISSION_MODES, TELEMETRY_ROUTING, TELEMETRY_BOUNDS, bucketAppVersion, bucketArchitecture, bucketErrorCode, bucketGraph, bucketOperatingSystem, isMetadataTool, telemetryEventId, telemetryTimestamp, validateTelemetryEvent, } from './schema.js';
|
|
9
9
|
import { telemetryGate } from './gate.js';
|
|
10
10
|
import { queueEvent } from './uploader.js';
|
|
11
11
|
import { appVersion } from './version.js';
|
|
@@ -119,11 +119,13 @@ export async function emitRunFinished(context, input) {
|
|
|
119
119
|
const capture = hasRunTelemetry(input.telemetry) ? input.telemetry : undefined;
|
|
120
120
|
if (capture?.pendingDecisions?.length)
|
|
121
121
|
await Promise.allSettled(capture.pendingDecisions);
|
|
122
|
-
const
|
|
122
|
+
const evidence = {
|
|
123
123
|
reason: input.reason,
|
|
124
124
|
providerRequestFailed: input.providerRequestFailed,
|
|
125
125
|
providerOverflow: input.providerOverflow ?? capture?.providerOverflow,
|
|
126
|
-
}
|
|
126
|
+
};
|
|
127
|
+
const outcome = classifyOutcome(input.status, evidence);
|
|
128
|
+
const stop = stopFields(input, outcome.outcome, stopReasonFor(input.status, evidence), capture);
|
|
127
129
|
const mix = await workspaceMix(input.workspace);
|
|
128
130
|
const toolCalls = Math.min(capture?.toolCalls ?? input.toolCalls ?? 0, 10_000_000_000_000);
|
|
129
131
|
const toolFailures = Math.min(capture?.toolFailures ?? input.toolFailures ?? 0, 10_000_000_000_000);
|
|
@@ -146,6 +148,7 @@ export async function emitRunFinished(context, input) {
|
|
|
146
148
|
decisionRouting: routing(input.decisionRouting ?? config.decisions?.mode),
|
|
147
149
|
outcome: outcome.outcome,
|
|
148
150
|
...(outcome.failureClass === undefined ? {} : { failureClass: outcome.failureClass }),
|
|
151
|
+
...stop,
|
|
149
152
|
durationMs: Math.max(0, Math.min(1_000_000_000_000, Date.now() - Date.parse(input.startedAt) || 0)),
|
|
150
153
|
attempts: capture?.attempts ?? input.attempts ?? 0,
|
|
151
154
|
retries: capture?.retries ?? input.retries ?? 0,
|
|
@@ -154,6 +157,7 @@ export async function emitRunFinished(context, input) {
|
|
|
154
157
|
...(capture && capture.models.length ? { models: aggregateModelTuples(capture.models) } : {}),
|
|
155
158
|
...(tools.length ? { tools } : {}),
|
|
156
159
|
...(capture ? { jev: { ...capture.jev } } : {}),
|
|
160
|
+
...savingsField(capture),
|
|
157
161
|
...(mix.languages === undefined ? {} : { languages: mix.languages }),
|
|
158
162
|
...(mix.frameworks === undefined ? {} : { frameworks: mix.frameworks }),
|
|
159
163
|
...(capture ? category(capture) : {}),
|
|
@@ -163,6 +167,39 @@ export async function emitRunFinished(context, input) {
|
|
|
163
167
|
});
|
|
164
168
|
return queued;
|
|
165
169
|
}
|
|
170
|
+
const STOP_CODES = new Set(['provider_error', 'context_overflow', 'runtime_error']);
|
|
171
|
+
/**
|
|
172
|
+
* Why the run stopped and every error it met. The errors are the run's own append-only record, so an error the
|
|
173
|
+
* run recovered from and carried on past is still reported; the code that ended the run is added to them when
|
|
174
|
+
* the run never recorded it (a failure before the agent started), never put in place of an earlier one.
|
|
175
|
+
*/
|
|
176
|
+
function stopFields(input, outcome, stopReason, capture) {
|
|
177
|
+
const errorCode = outcome !== 'failed' ? undefined
|
|
178
|
+
: input.errorCode !== undefined ? bucketErrorCode(input.errorCode)
|
|
179
|
+
: stopReason !== undefined && STOP_CODES.has(stopReason) ? stopReason : undefined;
|
|
180
|
+
const tally = createRunTelemetry();
|
|
181
|
+
for (const record of capture?.errors ?? [])
|
|
182
|
+
recordRunError(tally, record.code, Math.min(record.count, TELEMETRY_BOUNDS.counter));
|
|
183
|
+
// A code the run itself reported (its failureCode) is already in its errors, perhaps folded into `other` once the
|
|
184
|
+
// table filled, so it is never counted twice. Only a code the run never recorded (a failure outside the agent, or
|
|
185
|
+
// one derived from the stop reason) is added.
|
|
186
|
+
const recorded = input.errorCode !== undefined && (capture?.errors?.length ?? 0) > 0;
|
|
187
|
+
if (errorCode !== undefined && !recorded)
|
|
188
|
+
recordRunError(tally, errorCode);
|
|
189
|
+
return {
|
|
190
|
+
...(stopReason === undefined ? {} : { stopReason }),
|
|
191
|
+
...(errorCode === undefined ? {} : { errorCode }),
|
|
192
|
+
...(tally.errors?.length ? { errors: tally.errors.map(record => ({ code: record.code, count: Math.min(record.count, TELEMETRY_BOUNDS.counter) })) } : {}),
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
function savingsField(capture) {
|
|
196
|
+
const savings = capture ? savingsFrom(capture) : undefined;
|
|
197
|
+
if (savings === undefined)
|
|
198
|
+
return {};
|
|
199
|
+
for (const field of Object.keys(savings))
|
|
200
|
+
savings[field] = Math.max(0, Math.min(TELEMETRY_BOUNDS.counter, savings[field]));
|
|
201
|
+
return { savings };
|
|
202
|
+
}
|
|
166
203
|
function category(capture) {
|
|
167
204
|
const value = classifyTaskCounts(capture.task);
|
|
168
205
|
return value === undefined ? {} : { taskCategory: value };
|
|
@@ -10,6 +10,24 @@ export declare const TELEMETRY_OUTCOMES: readonly ["completed", "failed", "cance
|
|
|
10
10
|
export type TelemetryOutcome = typeof TELEMETRY_OUTCOMES[number];
|
|
11
11
|
export declare const TELEMETRY_FAILURE_CLASSES: readonly ["provider_error", "tool_error", "timeout", "limit", "infrastructure"];
|
|
12
12
|
export type TelemetryFailureClass = typeof TELEMETRY_FAILURE_CLASSES[number];
|
|
13
|
+
/** Why a run that did not complete stopped. Finer than outcome and failureClass, and absent on a completed run. */
|
|
14
|
+
export declare const TELEMETRY_STOP_REASONS: readonly ["user_stopped", "app_closed", "needs_clarification", "provider_error", "context_overflow", "runtime_error", "wall_time", "max_iterations", "max_tool_calls", "max_todo_calls", "max_context", "max_node_visits", "metadata_limit", "repeated_tool_failure", "other_limit"];
|
|
15
|
+
export type TelemetryStopReason = typeof TELEMETRY_STOP_REASONS[number];
|
|
16
|
+
/**
|
|
17
|
+
* Error codes are one of these names, `http_<status>`, or an operating-system error code such as
|
|
18
|
+
* `ECONNREFUSED`. Nothing else is sent: an unrecognised code becomes `other`.
|
|
19
|
+
*/
|
|
20
|
+
export declare const TELEMETRY_ERROR_NAMES: readonly ["provider_timeout", "connection_failed", "stream_interrupted", "malformed_response", "blank_tool_call", "context_overflow", "provider_error", "runtime_error", "other"];
|
|
21
|
+
export declare const TELEMETRY_ERROR_KINDS = 16;
|
|
22
|
+
export declare function isTelemetryErrorCode(value: unknown): value is string;
|
|
23
|
+
export declare function bucketErrorCode(value: unknown): string;
|
|
24
|
+
export interface TelemetryErrorRecord {
|
|
25
|
+
code: string;
|
|
26
|
+
count: number;
|
|
27
|
+
}
|
|
28
|
+
/** Measured savings counters for one run, in characters or steps; the server derives token estimates. */
|
|
29
|
+
export declare const TELEMETRY_SAVINGS_FIELDS: readonly ["toolResultsFiltered", "toolResultOriginalChars", "toolResultKeptChars", "toolResultExpandedChars", "schemaCharsBefore", "schemaCharsAfter", "contextOmittedChars", "contextDuplicates", "preparedSteps", "preparedExecuted", "deterministicSteps", "postflightSkipped"];
|
|
30
|
+
export type TelemetrySavings = Record<typeof TELEMETRY_SAVINGS_FIELDS[number], number>;
|
|
13
31
|
export declare const TELEMETRY_PROVIDER_TYPES: readonly ["openai-compatible", "anthropic", "codex", "other"];
|
|
14
32
|
export type TelemetryProviderType = typeof TELEMETRY_PROVIDER_TYPES[number];
|
|
15
33
|
export declare const TELEMETRY_ENDPOINTS: readonly ["hosted", "local", "other"];
|
|
@@ -94,6 +112,10 @@ export interface TelemetryEvent extends TelemetryIdentity {
|
|
|
94
112
|
decisionRouting?: TelemetryRouting;
|
|
95
113
|
outcome?: TelemetryOutcome;
|
|
96
114
|
failureClass?: TelemetryFailureClass;
|
|
115
|
+
stopReason?: TelemetryStopReason;
|
|
116
|
+
errorCode?: string;
|
|
117
|
+
errors?: TelemetryErrorRecord[];
|
|
118
|
+
savings?: TelemetrySavings;
|
|
97
119
|
attempts?: number;
|
|
98
120
|
retries?: number;
|
|
99
121
|
durationMs?: number;
|
|
@@ -8,6 +8,37 @@ export const TELEMETRY_SURFACES = ['cli', 'desktop', 'remote', 'subagent'];
|
|
|
8
8
|
export const TELEMETRY_PLANS = ['free', 'legacy', 'paid', 'unknown'];
|
|
9
9
|
export const TELEMETRY_OUTCOMES = ['completed', 'failed', 'cancelled', 'needs_clarification', 'interrupted'];
|
|
10
10
|
export const TELEMETRY_FAILURE_CLASSES = ['provider_error', 'tool_error', 'timeout', 'limit', 'infrastructure'];
|
|
11
|
+
/** Why a run that did not complete stopped. Finer than outcome and failureClass, and absent on a completed run. */
|
|
12
|
+
export const TELEMETRY_STOP_REASONS = [
|
|
13
|
+
'user_stopped', 'app_closed', 'needs_clarification',
|
|
14
|
+
'provider_error', 'context_overflow', 'runtime_error',
|
|
15
|
+
'wall_time', 'max_iterations', 'max_tool_calls', 'max_todo_calls', 'max_context', 'max_node_visits',
|
|
16
|
+
'metadata_limit', 'repeated_tool_failure', 'other_limit',
|
|
17
|
+
];
|
|
18
|
+
/**
|
|
19
|
+
* Error codes are one of these names, `http_<status>`, or an operating-system error code such as
|
|
20
|
+
* `ECONNREFUSED`. Nothing else is sent: an unrecognised code becomes `other`.
|
|
21
|
+
*/
|
|
22
|
+
export const TELEMETRY_ERROR_NAMES = [
|
|
23
|
+
'provider_timeout', 'connection_failed', 'stream_interrupted', 'malformed_response', 'blank_tool_call',
|
|
24
|
+
'context_overflow', 'provider_error', 'runtime_error', 'other',
|
|
25
|
+
];
|
|
26
|
+
const HTTP_ERROR_CODE = /^http_[1-5]\d\d$/;
|
|
27
|
+
const SYSTEM_ERROR_CODE = /^[A-Z][A-Z0-9_]{1,39}$/;
|
|
28
|
+
export const TELEMETRY_ERROR_KINDS = 16;
|
|
29
|
+
export function isTelemetryErrorCode(value) {
|
|
30
|
+
return typeof value === 'string'
|
|
31
|
+
&& (TELEMETRY_ERROR_NAMES.includes(value) || HTTP_ERROR_CODE.test(value) || SYSTEM_ERROR_CODE.test(value));
|
|
32
|
+
}
|
|
33
|
+
export function bucketErrorCode(value) {
|
|
34
|
+
return isTelemetryErrorCode(value) ? value : 'other';
|
|
35
|
+
}
|
|
36
|
+
/** Measured savings counters for one run, in characters or steps; the server derives token estimates. */
|
|
37
|
+
export const TELEMETRY_SAVINGS_FIELDS = [
|
|
38
|
+
'toolResultsFiltered', 'toolResultOriginalChars', 'toolResultKeptChars', 'toolResultExpandedChars',
|
|
39
|
+
'schemaCharsBefore', 'schemaCharsAfter', 'contextOmittedChars', 'contextDuplicates',
|
|
40
|
+
'preparedSteps', 'preparedExecuted', 'deterministicSteps', 'postflightSkipped',
|
|
41
|
+
];
|
|
11
42
|
export const TELEMETRY_PROVIDER_TYPES = ['openai-compatible', 'anthropic', 'codex', 'other'];
|
|
12
43
|
export const TELEMETRY_ENDPOINTS = ['hosted', 'local', 'other'];
|
|
13
44
|
export const TELEMETRY_ROLES = ['agent', 'orchestrator', 'subagent', 'jev', 'other'];
|
|
@@ -336,7 +367,7 @@ export function validateTelemetryEvent(value) {
|
|
|
336
367
|
throw new SchemaError('jevEnabled is required');
|
|
337
368
|
out.decisionRouting = requireEnum(TELEMETRY_ROUTING, v.decisionRouting, 'decisionRouting');
|
|
338
369
|
if (event === 'run.started') {
|
|
339
|
-
for (const key of ['outcome', 'failureClass', 'attempts', 'retries', 'durationMs', 'toolCalls', 'toolFailures', 'models', 'tools', 'jev', 'languages', 'frameworks', 'taskCategory']) {
|
|
370
|
+
for (const key of ['outcome', 'failureClass', 'stopReason', 'errorCode', 'errors', 'savings', 'attempts', 'retries', 'durationMs', 'toolCalls', 'toolFailures', 'models', 'tools', 'jev', 'languages', 'frameworks', 'taskCategory']) {
|
|
340
371
|
if (v[key] !== undefined)
|
|
341
372
|
throw new SchemaError(`${key} belongs to run.finished`);
|
|
342
373
|
}
|
|
@@ -348,6 +379,42 @@ export function validateTelemetryEvent(value) {
|
|
|
348
379
|
throw new SchemaError('failureClass is required when outcome is failed');
|
|
349
380
|
if (out.outcome !== 'failed' && out.failureClass !== undefined)
|
|
350
381
|
throw new SchemaError('failureClass is only valid when outcome is failed');
|
|
382
|
+
if (v.stopReason !== undefined) {
|
|
383
|
+
out.stopReason = requireEnum(TELEMETRY_STOP_REASONS, v.stopReason, 'stopReason');
|
|
384
|
+
if (out.outcome === 'completed')
|
|
385
|
+
throw new SchemaError('stopReason is not valid on a completed run');
|
|
386
|
+
}
|
|
387
|
+
if (v.errorCode !== undefined) {
|
|
388
|
+
if (!isTelemetryErrorCode(v.errorCode))
|
|
389
|
+
throw new SchemaError('errorCode is not an allowed value');
|
|
390
|
+
if (out.outcome !== 'failed')
|
|
391
|
+
throw new SchemaError('errorCode is only valid when outcome is failed');
|
|
392
|
+
out.errorCode = v.errorCode;
|
|
393
|
+
}
|
|
394
|
+
if (v.errors !== undefined) {
|
|
395
|
+
if (!Array.isArray(v.errors) || v.errors.length > TELEMETRY_ERROR_KINDS)
|
|
396
|
+
throw new SchemaError(`errors must be an array of at most ${TELEMETRY_ERROR_KINDS} records`);
|
|
397
|
+
out.errors = v.errors.map((record, index) => {
|
|
398
|
+
if (!record || typeof record !== 'object' || Array.isArray(record))
|
|
399
|
+
throw new SchemaError(`errors[${index}] must be an object`);
|
|
400
|
+
const r = record;
|
|
401
|
+
if (!isTelemetryErrorCode(r.code))
|
|
402
|
+
throw new SchemaError(`errors[${index}].code is not an allowed value`);
|
|
403
|
+
return { code: r.code, count: requireInteger(r.count, 1, TELEMETRY_BOUNDS.counter, `errors[${index}].count`) };
|
|
404
|
+
});
|
|
405
|
+
unique(out.errors, record => record.code, 'errors');
|
|
406
|
+
}
|
|
407
|
+
if (v.savings !== undefined) {
|
|
408
|
+
if (!v.savings || typeof v.savings !== 'object' || Array.isArray(v.savings))
|
|
409
|
+
throw new SchemaError('savings must be an object');
|
|
410
|
+
const s = v.savings;
|
|
411
|
+
if (Object.keys(s).some(key => !TELEMETRY_SAVINGS_FIELDS.includes(key)))
|
|
412
|
+
throw new SchemaError('savings has an unknown key');
|
|
413
|
+
const savings = {};
|
|
414
|
+
for (const field of TELEMETRY_SAVINGS_FIELDS)
|
|
415
|
+
savings[field] = requireInteger(s[field], 0, TELEMETRY_BOUNDS.counter, `savings.${field}`);
|
|
416
|
+
out.savings = savings;
|
|
417
|
+
}
|
|
351
418
|
out.durationMs = requireInteger(v.durationMs, 0, TELEMETRY_BOUNDS.durationMs, 'durationMs');
|
|
352
419
|
out.attempts = requireInteger(v.attempts, 0, TELEMETRY_BOUNDS.counter, 'attempts');
|
|
353
420
|
out.retries = requireInteger(v.retries, 0, TELEMETRY_BOUNDS.counter, 'retries');
|
|
@@ -31,6 +31,7 @@ export declare function reportRunFinished(input: SurfaceInput, handle: RunTeleme
|
|
|
31
31
|
reason?: string;
|
|
32
32
|
providerRequestFailed?: boolean;
|
|
33
33
|
providerOverflow?: boolean;
|
|
34
|
+
errorCode?: string;
|
|
34
35
|
telemetry?: RunTelemetry;
|
|
35
36
|
toolCalls?: number;
|
|
36
37
|
toolFailures?: number;
|
|
@@ -4,8 +4,13 @@ import { type TelemetryEvent } from './schema.js';
|
|
|
4
4
|
* no endpoint unless the test names one, so a test that starts an engine against a throwaway home can never
|
|
5
5
|
* report to the production service as a new installation. Nothing a user's own tools set (Node's test-runner
|
|
6
6
|
* variables among them) switches reporting off.
|
|
7
|
+
*
|
|
8
|
+
* `ANDORRA_TELEMETRY_URL` names another endpoint for development only: it is read in a test run and in a build
|
|
9
|
+
* that runs from a source checkout, and an installed release ignores it and posts to the stamped endpoint.
|
|
7
10
|
*/
|
|
8
|
-
export declare function telemetryEndpoint(env?: NodeJS.ProcessEnv): string | undefined;
|
|
11
|
+
export declare function telemetryEndpoint(env?: NodeJS.ProcessEnv, sourceCheckout?: boolean): string | undefined;
|
|
12
|
+
/** Whether this build sits in a git working tree (a `.git` entry beside package.json), which a published package never has. */
|
|
13
|
+
export declare function runsFromSourceCheckout(): boolean;
|
|
9
14
|
export interface UploadDependencies {
|
|
10
15
|
reporting?: () => Promise<boolean>;
|
|
11
16
|
fetch?: typeof globalThis.fetch;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
1
2
|
import { join } from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
2
4
|
import { TEST_RUN_MARKER } from '../andorra/hosted.js';
|
|
3
5
|
import { AUTH_DEPLOYMENT } from '../auth/deployment.js';
|
|
4
6
|
import { enqueue, pruneGeneration, pruneOld, readSpool, rewriteSpool, spoolNames, sweepOutbox, withSpoolLock, withSpoolLockWait, } from './outbox.js';
|
|
@@ -9,13 +11,30 @@ import { uploadSignal } from './uploads.js';
|
|
|
9
11
|
* no endpoint unless the test names one, so a test that starts an engine against a throwaway home can never
|
|
10
12
|
* report to the production service as a new installation. Nothing a user's own tools set (Node's test-runner
|
|
11
13
|
* variables among them) switches reporting off.
|
|
14
|
+
*
|
|
15
|
+
* `ANDORRA_TELEMETRY_URL` names another endpoint for development only: it is read in a test run and in a build
|
|
16
|
+
* that runs from a source checkout, and an installed release ignores it and posts to the stamped endpoint.
|
|
12
17
|
*/
|
|
13
|
-
export function telemetryEndpoint(env = process.env) {
|
|
14
|
-
|
|
18
|
+
export function telemetryEndpoint(env = process.env, sourceCheckout = runsFromSourceCheckout()) {
|
|
19
|
+
const override = env[TEST_RUN_MARKER] || sourceCheckout ? env.ANDORRA_TELEMETRY_URL : undefined;
|
|
20
|
+
if (env[TEST_RUN_MARKER] && !override)
|
|
15
21
|
return undefined;
|
|
16
|
-
const configured =
|
|
22
|
+
const configured = override || AUTH_DEPLOYMENT.telemetryBaseUrl;
|
|
17
23
|
return configured ? configured.replace(/\/+$/, '') : undefined;
|
|
18
24
|
}
|
|
25
|
+
let sourceCheckout;
|
|
26
|
+
/** Whether this build sits in a git working tree (a `.git` entry beside package.json), which a published package never has. */
|
|
27
|
+
export function runsFromSourceCheckout() {
|
|
28
|
+
if (sourceCheckout === undefined) {
|
|
29
|
+
try {
|
|
30
|
+
sourceCheckout = existsSync(fileURLToPath(new URL('../../../.git', import.meta.url)));
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
sourceCheckout = false;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return sourceCheckout;
|
|
37
|
+
}
|
|
19
38
|
const REQUEST_TIMEOUT_MS = 5_000;
|
|
20
39
|
async function post(endpoint, event, dependencies) {
|
|
21
40
|
let body;
|
package/dist/src/terminal-ui.js
CHANGED
|
@@ -85,7 +85,7 @@ const submittedCommand = (value) => {
|
|
|
85
85
|
};
|
|
86
86
|
const workingCommandHint = (command) => `${command} doesn't run while a task is working. Run ${command} once this task has finished.`
|
|
87
87
|
+ (command === '/graph' ? ' Switching graphs clears the previous graph progress and starts fresh.' : '');
|
|
88
|
-
const liveRunCommands = ['/model', '/browser', '/attach', '/yolo', '/permissions', '/jev', '/help', '/status', '/usage', '/tools', '/exit', '/quit'];
|
|
88
|
+
const liveRunCommands = ['/model', '/browser', '/attach', '/compact', '/yolo', '/permissions', '/jev', '/help', '/status', '/usage', '/tools', '/exit', '/quit'];
|
|
89
89
|
const paint = (text, color = GRAY) => typeof color === 'number'
|
|
90
90
|
? `\x1b[38;5;${color}m${text}\x1b[0m`
|
|
91
91
|
: `\x1b[${color}m${text}\x1b[0m`;
|
package/dist/src/transcript.js
CHANGED
|
@@ -6,6 +6,8 @@ import { HEADING_PREFIX, renderMarkdown } from './markdown.js';
|
|
|
6
6
|
import { formatDuration } from './duration.js';
|
|
7
7
|
import { toolCallStamp } from './tool-call-clock.js';
|
|
8
8
|
import { canonicalCodingToolName } from './tool-names.js';
|
|
9
|
+
import { jevRequestPhrase } from './decision/requestPhrases.js';
|
|
10
|
+
import { compactionText } from './compaction-phrases.js';
|
|
9
11
|
const clean = (value) => stripVTControlCharacters(String(value ?? '')).replace(/\r\n?/g, '\n').replace(/[\x00-\x08\x0b-\x1f\x7f-\x9f\u202a-\u202e\u2066-\u2069]/g, '');
|
|
10
12
|
const line = (value) => clipText(clean(value).replace(/\s+/g, ' ').trim(), 240);
|
|
11
13
|
export function formatDurationSuffix(data) {
|
|
@@ -94,7 +96,7 @@ export function formatEvent(event) {
|
|
|
94
96
|
const data = event.data;
|
|
95
97
|
if (data.provider === 'andorra' || data.provider === 'jev') {
|
|
96
98
|
if (event.type === 'decision.requested')
|
|
97
|
-
return { text:
|
|
99
|
+
return { text: `• [Jev] ${jevRequestPhrase(data.text)}` };
|
|
98
100
|
if (event.type === 'decision.skills_truncated')
|
|
99
101
|
return typeof data.text === 'string' && data.text ? { text: ` ⚠ ${data.text}` } : undefined;
|
|
100
102
|
if (event.type === 'decision.completed')
|
|
@@ -115,7 +117,11 @@ export function formatEvent(event) {
|
|
|
115
117
|
const identity = [data.nodeName, typeof data.copy === 'number' && Number(data.copies ?? 2) > 1 ? `copy ${data.copy}${data.copies ? `/${data.copies}` : ''}` : '', data.subagentId].filter(Boolean).map(line).join(' - ');
|
|
116
118
|
const actor = identity ? `[${identity}] ` : '';
|
|
117
119
|
if (event.type === 'agent.context.compaction.started')
|
|
118
|
-
return { text:
|
|
120
|
+
return { text: compactionText(data.text) };
|
|
121
|
+
if (event.type === 'agent.context.compacted' && data.reason === 'requested')
|
|
122
|
+
return { text: data.removedExchanges === 0 ? 'Nothing to compact yet: the run has no earlier exchanges to summarize. Continuing.' : `Compacted ${line(data.removedExchanges)} earlier exchange${data.removedExchanges === 1 ? '' : 's'} into a summary. Continuing.` };
|
|
123
|
+
if (event.type === 'agent.context.compaction.deferred' && data.requested === true)
|
|
124
|
+
return { text: `The context summary could not be written (${line(data.reason)}), so the run continues with its full history.` };
|
|
119
125
|
if (event.type === 'agent.context.compaction.retry')
|
|
120
126
|
return { text: `Context summary incomplete (${line(data.reason)}); retrying ${line(data.nextAttempt)}/3.` };
|
|
121
127
|
if (event.type === 'agent.model.retry' && data.quiet === true)
|
package/dist/src/types.d.ts
CHANGED
|
@@ -67,6 +67,8 @@ export interface ModelRetry {
|
|
|
67
67
|
unparsedReply?: string;
|
|
68
68
|
/** The system error code behind a connection that could not be made (`ECONNREFUSED`, `EAI_AGAIN`), for the record only: `reason` stays the plain sentence. */
|
|
69
69
|
cause?: string;
|
|
70
|
+
/** The telemetry error code of the failure being retried (`http_429`, `provider_timeout`, `ECONNRESET`); record-only, never shown. */
|
|
71
|
+
code?: string;
|
|
70
72
|
}
|
|
71
73
|
export interface GenerateRequest {
|
|
72
74
|
model: string;
|
|
@@ -79,6 +81,11 @@ export interface GenerateRequest {
|
|
|
79
81
|
context?: ModelRequestContext;
|
|
80
82
|
estimateInputTokens?: () => number;
|
|
81
83
|
onRetry?: (retry: ModelRetry) => void | Promise<void>;
|
|
84
|
+
/**
|
|
85
|
+
* A failed request the provider recovered from without a visible retry (a 400 answered by sending again
|
|
86
|
+
* without a forced tool choice or without streaming). Record-only: its telemetry code, never shown.
|
|
87
|
+
*/
|
|
88
|
+
onRecoveredError?: (code: string) => void;
|
|
82
89
|
onRequest?: () => void;
|
|
83
90
|
onReasoning?: (delta: string) => void;
|
|
84
91
|
onText?: (delta: string) => void;
|