@andorra-labs/code 0.1.15 → 0.1.17
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/acp-agent.d.ts +6 -0
- package/dist/src/acp-agent.js +15 -4
- package/dist/src/agent-definitions.js +29 -6
- package/dist/src/agent-execution.js +15 -10
- package/dist/src/agent-mcp-catalog.js +1 -0
- package/dist/src/agent-mcp.d.ts +4 -1
- package/dist/src/agent-mcp.js +46 -10
- package/dist/src/andorra/entry.d.ts +10 -0
- package/dist/src/andorra/entry.js +18 -4
- package/dist/src/andorra/hosted.d.ts +2 -1
- package/dist/src/andorra/hosted.js +2 -1
- package/dist/src/andorra/notices.d.ts +5 -0
- package/dist/src/andorra/notices.js +7 -0
- package/dist/src/andorra/state.d.ts +3 -2
- package/dist/src/andorra/state.js +4 -4
- package/dist/src/andorra/terminal.js +7 -2
- package/dist/src/anthropic-credentials.js +2 -0
- package/dist/src/app-server/error.d.ts +5 -0
- package/dist/src/app-server/error.js +7 -0
- package/dist/src/app-server/protocol.d.ts +22 -44
- package/dist/src/app-server/protocol.js +5 -1
- package/dist/src/app-server/workspace.d.ts +89 -0
- package/dist/src/app-server/workspace.js +457 -11
- package/dist/src/app-server.d.ts +465 -32
- package/dist/src/app-server.js +3308 -517
- package/dist/src/auth/deployment.js +2 -2
- package/dist/src/bridge/cloud.d.ts +27 -0
- package/dist/src/bridge/cloud.js +187 -0
- package/dist/src/bridge/command.d.ts +30 -0
- package/dist/src/bridge/command.js +347 -0
- package/dist/src/bridge/control.d.ts +68 -0
- package/dist/src/bridge/control.js +233 -0
- package/dist/src/bridge/engines.d.ts +90 -0
- package/dist/src/bridge/engines.js +601 -0
- package/dist/src/bridge/host-ops.d.ts +9 -0
- package/dist/src/bridge/host-ops.js +129 -0
- package/dist/src/bridge/host.d.ts +47 -0
- package/dist/src/bridge/host.js +540 -0
- package/dist/src/bridge/link.d.ts +38 -0
- package/dist/src/bridge/link.js +508 -0
- package/dist/src/bridge/login-link.d.ts +29 -0
- package/dist/src/bridge/login-link.js +54 -0
- package/dist/src/bridge/protocol.d.ts +136 -0
- package/dist/src/bridge/protocol.js +11 -0
- package/dist/src/bridge/store.d.ts +12 -0
- package/dist/src/bridge/store.js +61 -0
- package/dist/src/bridge/wording.d.ts +6 -0
- package/dist/src/bridge/wording.js +10 -0
- package/dist/src/browser-runner.js +1 -0
- package/dist/src/browser-server.js +7 -1
- package/dist/src/browser-ui/style.css +3 -3
- package/dist/src/browser-ui/tokens.css +28 -17
- package/dist/src/change-authors.d.ts +41 -0
- package/dist/src/change-authors.js +146 -0
- package/dist/src/claude-provider.js +3 -1
- package/dist/src/cli.js +202 -38
- package/dist/src/codex-errors.js +4 -1
- package/dist/src/coding-tools.js +15 -15
- package/dist/src/command-screens.d.ts +6 -0
- package/dist/src/command-screens.js +19 -14
- package/dist/src/commands.d.ts +14 -1
- package/dist/src/compaction-phrases.d.ts +4 -0
- package/dist/src/compaction-phrases.js +20 -0
- package/dist/src/completion.js +82 -5
- package/dist/src/config.d.ts +71 -3
- package/dist/src/config.js +202 -77
- package/dist/src/context-compaction.js +2 -1
- package/dist/src/deadline.js +13 -1
- package/dist/src/decision/DecisionManager.js +3 -2
- package/dist/src/decision/checks.js +1 -1
- package/dist/src/decision/requestPhrases.d.ts +4 -0
- package/dist/src/decision/requestPhrases.js +22 -0
- package/dist/src/default-graph.js +1 -1
- package/dist/src/file-diff.d.ts +4 -0
- package/dist/src/file-diff.js +2 -1
- package/dist/src/github-app/agent-writes.d.ts +102 -0
- package/dist/src/github-app/agent-writes.js +320 -0
- package/dist/src/github-app/client.d.ts +349 -0
- package/dist/src/github-app/client.js +810 -0
- package/dist/src/github-app/event-source.d.ts +208 -0
- package/dist/src/github-app/event-source.js +684 -0
- package/dist/src/github-app/metrics.d.ts +32 -0
- package/dist/src/github-app/metrics.js +49 -0
- package/dist/src/github-app/review-loop.d.ts +274 -0
- package/dist/src/github-app/review-loop.js +1177 -0
- package/dist/src/github-app/review-node.d.ts +81 -0
- package/dist/src/github-app/review-node.js +205 -0
- package/dist/src/github-app/review-post.d.ts +73 -0
- package/dist/src/github-app/review-post.js +139 -0
- package/dist/src/github-app/review-text.d.ts +107 -0
- package/dist/src/github-app/review-text.js +1133 -0
- package/dist/src/github-app/review-threads.d.ts +47 -0
- package/dist/src/github-app/review-threads.js +107 -0
- package/dist/src/github-app/reviewer.d.ts +121 -0
- package/dist/src/github-app/reviewer.js +598 -0
- package/dist/src/github-app/store.d.ts +59 -0
- package/dist/src/github-app/store.js +148 -0
- package/dist/src/github-app/triggers.d.ts +141 -0
- package/dist/src/github-app/triggers.js +441 -0
- package/dist/src/github-inbox.d.ts +55 -0
- package/dist/src/github-inbox.js +153 -0
- package/dist/src/github-names.d.ts +8 -0
- package/dist/src/github-names.js +8 -0
- package/dist/src/glob-search.d.ts +61 -0
- package/dist/src/glob-search.js +180 -0
- package/dist/src/graph-health.js +13 -4
- package/dist/src/graph-manager-chat.js +1 -1
- package/dist/src/graph-preview.d.ts +46 -0
- package/dist/src/graph-preview.js +55 -0
- package/dist/src/graph-provider-portability.js +34 -11
- package/dist/src/graph-quota.d.ts +29 -2
- package/dist/src/graph-quota.js +68 -10
- package/dist/src/graph-runner.js +88 -10
- package/dist/src/graph-server.d.ts +1 -1
- package/dist/src/graph-server.js +11 -9
- package/dist/src/graph-sync.js +3 -3
- package/dist/src/graph-ui/app.js +201 -40
- 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 +3 -1
- 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 +26 -5
- 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 +28 -20
- package/dist/src/graphs.d.ts +34 -1
- package/dist/src/graphs.js +162 -17
- package/dist/src/image-input.d.ts +16 -0
- package/dist/src/image-input.js +41 -0
- package/dist/src/membership.d.ts +30 -1
- package/dist/src/membership.js +48 -8
- package/dist/src/model-health-cache.js +1 -1
- package/dist/src/model-metadata.d.ts +7 -1
- package/dist/src/model-metadata.js +39 -17
- package/dist/src/model-relay/local.d.ts +116 -0
- package/dist/src/model-relay/local.js +468 -0
- package/dist/src/model-relay/remote.d.ts +129 -0
- package/dist/src/model-relay/remote.js +252 -0
- package/dist/src/model-relay/runs.d.ts +34 -0
- package/dist/src/model-relay/runs.js +146 -0
- package/dist/src/model-relay/wire.d.ts +5 -0
- package/dist/src/model-relay/wire.js +5 -0
- package/dist/src/plan-pass.d.ts +59 -0
- package/dist/src/plan-pass.js +165 -0
- package/dist/src/project-registry.d.ts +21 -0
- package/dist/src/project-registry.js +74 -0
- package/dist/src/provider-engine.js +3 -0
- package/dist/src/provider-import.d.ts +0 -12
- package/dist/src/provider-import.js +7 -195
- package/dist/src/providers.d.ts +40 -2
- package/dist/src/providers.js +93 -23
- 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 +87 -0
- package/dist/src/pull-request-logs.js +183 -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 +369 -8
- package/dist/src/pull-requests.js +524 -55
- package/dist/src/react-runtime.js +38 -5
- package/dist/src/remote/engine-pool.d.ts +88 -4
- package/dist/src/remote/engine-pool.js +379 -90
- package/dist/src/remote/roots.d.ts +19 -0
- package/dist/src/remote/roots.js +45 -7
- package/dist/src/remote/types.d.ts +0 -44
- package/dist/src/run-control.d.ts +17 -0
- package/dist/src/run-control.js +47 -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 +7 -2
- package/dist/src/run-records.js +71 -6
- package/dist/src/runtime.d.ts +9 -1
- package/dist/src/runtime.js +24 -4
- package/dist/src/session-changes.d.ts +35 -0
- package/dist/src/session-changes.js +194 -6
- package/dist/src/session-monitor.js +2 -1
- package/dist/src/session-reaper.d.ts +1 -1
- package/dist/src/session-reaper.js +6 -1
- package/dist/src/session-summary.d.ts +2 -1
- package/dist/src/session-summary.js +2 -1
- package/dist/src/sessions.d.ts +11 -1
- package/dist/src/sessions.js +17 -4
- package/dist/src/skills/bundled/diagram/SKILL.md +5 -3
- package/dist/src/skills/bundled/graph-manager/SKILL.md +7 -4
- package/dist/src/skills/bundled/provenance.json +2 -2
- package/dist/src/skills/runtime-skills.js +1 -1
- 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 +17 -0
- package/dist/src/telemetry/emitter.js +76 -5
- package/dist/src/telemetry/schema.d.ts +47 -2
- package/dist/src/telemetry/schema.js +120 -5
- package/dist/src/telemetry/surface.d.ts +3 -1
- package/dist/src/telemetry/surface.js +4 -1
- package/dist/src/telemetry/uploader.d.ts +6 -1
- package/dist/src/telemetry/uploader.js +22 -3
- package/dist/src/terminal-ui.d.ts +1 -0
- package/dist/src/terminal-ui.js +10 -3
- package/dist/src/test-edit-guard.d.ts +7 -0
- package/dist/src/test-edit-guard.js +49 -1
- package/dist/src/timers.d.ts +2 -0
- package/dist/src/tools.js +59 -9
- 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 +6 -1
- package/dist/src/remote/cert.d.ts +0 -11
- package/dist/src/remote/cert.js +0 -87
- package/dist/src/remote/client.d.ts +0 -119
- package/dist/src/remote/client.js +0 -544
- package/dist/src/remote/command.d.ts +0 -4
- package/dist/src/remote/command.js +0 -194
- package/dist/src/remote/errors.d.ts +0 -11
- package/dist/src/remote/errors.js +0 -14
- package/dist/src/remote/network.d.ts +0 -22
- package/dist/src/remote/network.js +0 -102
- package/dist/src/remote/pairing.d.ts +0 -63
- package/dist/src/remote/pairing.js +0 -299
- package/dist/src/remote/pem.d.ts +0 -2
- package/dist/src/remote/pem.js +0 -7
- package/dist/src/remote/serve.d.ts +0 -68
- package/dist/src/remote/serve.js +0 -244
- package/dist/src/remote/server.d.ts +0 -21
- package/dist/src/remote/server.js +0 -406
|
@@ -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;
|
|
@@ -43,5 +45,20 @@ export declare function emitRunStarted(context: TelemetryContext, input: RunDime
|
|
|
43
45
|
}): Promise<number | undefined>;
|
|
44
46
|
export declare function emitRunFinished(context: TelemetryContext, input: RunFinishInput): Promise<boolean>;
|
|
45
47
|
export declare function emitInterruptedRun(context: TelemetryContext, record: Record<string, unknown>): Promise<boolean>;
|
|
48
|
+
export interface GitHubWatchInput {
|
|
49
|
+
minutes: number;
|
|
50
|
+
coverage: {
|
|
51
|
+
state: string;
|
|
52
|
+
prs: number;
|
|
53
|
+
calls: number;
|
|
54
|
+
}[];
|
|
55
|
+
wakeLatencies: number[];
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* One window of the GitHub App watcher's counts (ADR 0021, `github.watch`): per coverage state, how many PRs
|
|
59
|
+
* were watched and how many gh calls the watcher made for them, and the Auto-fix wake latencies in whole
|
|
60
|
+
* seconds. Built field by field: no PR, repository, account or session reaches the record.
|
|
61
|
+
*/
|
|
62
|
+
export declare function emitGitHubWatch(context: TelemetryContext, input: GitHubWatchInput): Promise<boolean>;
|
|
46
63
|
export declare function engineSpoolId(prefix: string): string;
|
|
47
64
|
export declare function telemetryHome(home?: string): string;
|
|
@@ -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, TELEMETRY_GITHUB_COVERAGE, telemetryEventId, telemetrySchemaFor, 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 };
|
|
@@ -210,6 +247,40 @@ export async function emitInterruptedRun(context, record) {
|
|
|
210
247
|
decisionRouting: typeof telemetry.decisionRouting === 'string' ? telemetry.decisionRouting : undefined,
|
|
211
248
|
});
|
|
212
249
|
}
|
|
250
|
+
/**
|
|
251
|
+
* One window of the GitHub App watcher's counts (ADR 0021, `github.watch`): per coverage state, how many PRs
|
|
252
|
+
* were watched and how many gh calls the watcher made for them, and the Auto-fix wake latencies in whole
|
|
253
|
+
* seconds. Built field by field: no PR, repository, account or session reaches the record.
|
|
254
|
+
*/
|
|
255
|
+
export async function emitGitHubWatch(context, input) {
|
|
256
|
+
let queued = false;
|
|
257
|
+
await safely(async () => {
|
|
258
|
+
const watched = TELEMETRY_GITHUB_COVERAGE.flatMap(coverage => {
|
|
259
|
+
const record = input.coverage.find(entry => entry.state === coverage);
|
|
260
|
+
if (!record || record.prs < 1)
|
|
261
|
+
return [];
|
|
262
|
+
return [{ coverage: coverage, prs: Math.min(record.prs, TELEMETRY_BOUNDS.watchedPrs), ghCalls: Math.max(0, Math.min(record.calls, TELEMETRY_BOUNDS.counter)) }];
|
|
263
|
+
});
|
|
264
|
+
if (!watched.length)
|
|
265
|
+
return;
|
|
266
|
+
const resolved = await identityFor(context);
|
|
267
|
+
if (!resolved)
|
|
268
|
+
return;
|
|
269
|
+
const latencies = input.wakeLatencies.slice(0, TELEMETRY_BOUNDS.wakeLatencies)
|
|
270
|
+
.map(seconds => Math.max(0, Math.min(TELEMETRY_BOUNDS.wakeLatencySeconds, Math.round(seconds))));
|
|
271
|
+
const event = {
|
|
272
|
+
...resolved.identity,
|
|
273
|
+
schema: telemetrySchemaFor('github.watch'),
|
|
274
|
+
event: 'github.watch',
|
|
275
|
+
minutes: Math.max(1, Math.min(TELEMETRY_BOUNDS.watchMinutes, Math.round(input.minutes))),
|
|
276
|
+
watched,
|
|
277
|
+
...(latencies.length ? { wakeLatencies: latencies } : {}),
|
|
278
|
+
};
|
|
279
|
+
await queue(context, resolved.generation, event);
|
|
280
|
+
queued = true;
|
|
281
|
+
});
|
|
282
|
+
return queued;
|
|
283
|
+
}
|
|
213
284
|
export function engineSpoolId(prefix) {
|
|
214
285
|
return `${prefix}-${process.pid}-${Math.random().toString(36).slice(2, 10)}`;
|
|
215
286
|
}
|
|
@@ -1,7 +1,22 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* The newest schema version this client implements. Each record carries the version that defines its event
|
|
3
|
+
* (`telemetrySchemaFor`): the run and session events are still version 1, so an ingest that implements only
|
|
4
|
+
* version 1 keeps storing them, and refuses `github.watch` (version 2) rather than mislabelling it.
|
|
5
|
+
*/
|
|
6
|
+
export declare const TELEMETRY_SCHEMA = 2;
|
|
2
7
|
export declare const TELEMETRY_BODY_LIMIT: number;
|
|
3
|
-
export declare const TELEMETRY_EVENTS: readonly ["session.started", "run.started", "run.finished"];
|
|
8
|
+
export declare const TELEMETRY_EVENTS: readonly ["session.started", "run.started", "run.finished", "github.watch"];
|
|
4
9
|
export type TelemetryEventName = typeof TELEMETRY_EVENTS[number];
|
|
10
|
+
export declare function telemetrySchemaFor(event: TelemetryEventName): number;
|
|
11
|
+
/** A watched pull request's GitHub App coverage, as the engine sees it (`design/specs/github-app.md`, "Fallback to gh"). */
|
|
12
|
+
export declare const TELEMETRY_GITHUB_COVERAGE: readonly ["covered", "signed-out", "not-connected", "not-installed", "not-covered", "suspended", "permissions-pending", "limit", "pending", "disabled", "unavailable"];
|
|
13
|
+
export type TelemetryGitHubCoverage = typeof TELEMETRY_GITHUB_COVERAGE[number];
|
|
14
|
+
/** One coverage state's share of a `github.watch` window: how many watched PRs were in it, and the gh calls made for them. */
|
|
15
|
+
export interface TelemetryGitHubWatchRecord {
|
|
16
|
+
coverage: TelemetryGitHubCoverage;
|
|
17
|
+
prs: number;
|
|
18
|
+
ghCalls: number;
|
|
19
|
+
}
|
|
5
20
|
export declare const TELEMETRY_SURFACES: readonly ["cli", "desktop", "remote", "subagent"];
|
|
6
21
|
export type TelemetrySurface = typeof TELEMETRY_SURFACES[number];
|
|
7
22
|
export declare const TELEMETRY_PLANS: readonly ["free", "legacy", "paid", "unknown"];
|
|
@@ -10,6 +25,24 @@ export declare const TELEMETRY_OUTCOMES: readonly ["completed", "failed", "cance
|
|
|
10
25
|
export type TelemetryOutcome = typeof TELEMETRY_OUTCOMES[number];
|
|
11
26
|
export declare const TELEMETRY_FAILURE_CLASSES: readonly ["provider_error", "tool_error", "timeout", "limit", "infrastructure"];
|
|
12
27
|
export type TelemetryFailureClass = typeof TELEMETRY_FAILURE_CLASSES[number];
|
|
28
|
+
/** Why a run that did not complete stopped. Finer than outcome and failureClass, and absent on a completed run. */
|
|
29
|
+
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"];
|
|
30
|
+
export type TelemetryStopReason = typeof TELEMETRY_STOP_REASONS[number];
|
|
31
|
+
/**
|
|
32
|
+
* Error codes are one of these names, `http_<status>`, or an operating-system error code such as
|
|
33
|
+
* `ECONNREFUSED`. Nothing else is sent: an unrecognised code becomes `other`.
|
|
34
|
+
*/
|
|
35
|
+
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"];
|
|
36
|
+
export declare const TELEMETRY_ERROR_KINDS = 16;
|
|
37
|
+
export declare function isTelemetryErrorCode(value: unknown): value is string;
|
|
38
|
+
export declare function bucketErrorCode(value: unknown): string;
|
|
39
|
+
export interface TelemetryErrorRecord {
|
|
40
|
+
code: string;
|
|
41
|
+
count: number;
|
|
42
|
+
}
|
|
43
|
+
/** Measured savings counters for one run, in characters or steps; the server derives token estimates. */
|
|
44
|
+
export declare const TELEMETRY_SAVINGS_FIELDS: readonly ["toolResultsFiltered", "toolResultOriginalChars", "toolResultKeptChars", "toolResultExpandedChars", "schemaCharsBefore", "schemaCharsAfter", "contextOmittedChars", "contextDuplicates", "preparedSteps", "preparedExecuted", "deterministicSteps", "postflightSkipped"];
|
|
45
|
+
export type TelemetrySavings = Record<typeof TELEMETRY_SAVINGS_FIELDS[number], number>;
|
|
13
46
|
export declare const TELEMETRY_PROVIDER_TYPES: readonly ["openai-compatible", "anthropic", "codex", "other"];
|
|
14
47
|
export type TelemetryProviderType = typeof TELEMETRY_PROVIDER_TYPES[number];
|
|
15
48
|
export declare const TELEMETRY_ENDPOINTS: readonly ["hosted", "local", "other"];
|
|
@@ -94,6 +127,10 @@ export interface TelemetryEvent extends TelemetryIdentity {
|
|
|
94
127
|
decisionRouting?: TelemetryRouting;
|
|
95
128
|
outcome?: TelemetryOutcome;
|
|
96
129
|
failureClass?: TelemetryFailureClass;
|
|
130
|
+
stopReason?: TelemetryStopReason;
|
|
131
|
+
errorCode?: string;
|
|
132
|
+
errors?: TelemetryErrorRecord[];
|
|
133
|
+
savings?: TelemetrySavings;
|
|
97
134
|
attempts?: number;
|
|
98
135
|
retries?: number;
|
|
99
136
|
durationMs?: number;
|
|
@@ -105,6 +142,10 @@ export interface TelemetryEvent extends TelemetryIdentity {
|
|
|
105
142
|
languages?: TelemetryLanguage[];
|
|
106
143
|
frameworks?: TelemetryFramework[];
|
|
107
144
|
taskCategory?: TelemetryTaskCategory;
|
|
145
|
+
/** `github.watch` only: the window's length in minutes, at most an hour. */
|
|
146
|
+
minutes?: number;
|
|
147
|
+
watched?: TelemetryGitHubWatchRecord[];
|
|
148
|
+
wakeLatencies?: number[];
|
|
108
149
|
}
|
|
109
150
|
export declare const TELEMETRY_BOUNDS: {
|
|
110
151
|
readonly token: 1000000000000;
|
|
@@ -115,6 +156,10 @@ export declare const TELEMETRY_BOUNDS: {
|
|
|
115
156
|
readonly jevCounter: 1000000;
|
|
116
157
|
readonly nodes: 10000;
|
|
117
158
|
readonly osMajor: 999;
|
|
159
|
+
readonly watchMinutes: 60;
|
|
160
|
+
readonly watchedPrs: 10000;
|
|
161
|
+
readonly wakeLatencySeconds: 86400;
|
|
162
|
+
readonly wakeLatencies: 60;
|
|
118
163
|
};
|
|
119
164
|
export declare function telemetryTimestamp(date?: Date): string;
|
|
120
165
|
export declare function telemetryEventId(): string;
|
|
@@ -1,13 +1,57 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto';
|
|
2
2
|
import { isIP } from 'node:net';
|
|
3
3
|
import { CANONICAL_CODING_TOOLS, canonicalToolName } from '../tool-names.js';
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* The newest schema version this client implements. Each record carries the version that defines its event
|
|
6
|
+
* (`telemetrySchemaFor`): the run and session events are still version 1, so an ingest that implements only
|
|
7
|
+
* version 1 keeps storing them, and refuses `github.watch` (version 2) rather than mislabelling it.
|
|
8
|
+
*/
|
|
9
|
+
export const TELEMETRY_SCHEMA = 2;
|
|
5
10
|
export const TELEMETRY_BODY_LIMIT = 64 * 1024;
|
|
6
|
-
export const TELEMETRY_EVENTS = ['session.started', 'run.started', 'run.finished'];
|
|
11
|
+
export const TELEMETRY_EVENTS = ['session.started', 'run.started', 'run.finished', 'github.watch'];
|
|
12
|
+
export function telemetrySchemaFor(event) {
|
|
13
|
+
return event === 'github.watch' ? 2 : 1;
|
|
14
|
+
}
|
|
15
|
+
/** A watched pull request's GitHub App coverage, as the engine sees it (`design/specs/github-app.md`, "Fallback to gh"). */
|
|
16
|
+
export const TELEMETRY_GITHUB_COVERAGE = [
|
|
17
|
+
'covered', 'signed-out', 'not-connected', 'not-installed', 'not-covered', 'suspended', 'permissions-pending',
|
|
18
|
+
'limit', 'pending', 'disabled', 'unavailable',
|
|
19
|
+
];
|
|
7
20
|
export const TELEMETRY_SURFACES = ['cli', 'desktop', 'remote', 'subagent'];
|
|
8
21
|
export const TELEMETRY_PLANS = ['free', 'legacy', 'paid', 'unknown'];
|
|
9
22
|
export const TELEMETRY_OUTCOMES = ['completed', 'failed', 'cancelled', 'needs_clarification', 'interrupted'];
|
|
10
23
|
export const TELEMETRY_FAILURE_CLASSES = ['provider_error', 'tool_error', 'timeout', 'limit', 'infrastructure'];
|
|
24
|
+
/** Why a run that did not complete stopped. Finer than outcome and failureClass, and absent on a completed run. */
|
|
25
|
+
export const TELEMETRY_STOP_REASONS = [
|
|
26
|
+
'user_stopped', 'app_closed', 'needs_clarification',
|
|
27
|
+
'provider_error', 'context_overflow', 'runtime_error',
|
|
28
|
+
'wall_time', 'max_iterations', 'max_tool_calls', 'max_todo_calls', 'max_context', 'max_node_visits',
|
|
29
|
+
'metadata_limit', 'repeated_tool_failure', 'other_limit',
|
|
30
|
+
];
|
|
31
|
+
/**
|
|
32
|
+
* Error codes are one of these names, `http_<status>`, or an operating-system error code such as
|
|
33
|
+
* `ECONNREFUSED`. Nothing else is sent: an unrecognised code becomes `other`.
|
|
34
|
+
*/
|
|
35
|
+
export const TELEMETRY_ERROR_NAMES = [
|
|
36
|
+
'provider_timeout', 'connection_failed', 'stream_interrupted', 'malformed_response', 'blank_tool_call',
|
|
37
|
+
'context_overflow', 'provider_error', 'runtime_error', 'other',
|
|
38
|
+
];
|
|
39
|
+
const HTTP_ERROR_CODE = /^http_[1-5]\d\d$/;
|
|
40
|
+
const SYSTEM_ERROR_CODE = /^[A-Z][A-Z0-9_]{1,39}$/;
|
|
41
|
+
export const TELEMETRY_ERROR_KINDS = 16;
|
|
42
|
+
export function isTelemetryErrorCode(value) {
|
|
43
|
+
return typeof value === 'string'
|
|
44
|
+
&& (TELEMETRY_ERROR_NAMES.includes(value) || HTTP_ERROR_CODE.test(value) || SYSTEM_ERROR_CODE.test(value));
|
|
45
|
+
}
|
|
46
|
+
export function bucketErrorCode(value) {
|
|
47
|
+
return isTelemetryErrorCode(value) ? value : 'other';
|
|
48
|
+
}
|
|
49
|
+
/** Measured savings counters for one run, in characters or steps; the server derives token estimates. */
|
|
50
|
+
export const TELEMETRY_SAVINGS_FIELDS = [
|
|
51
|
+
'toolResultsFiltered', 'toolResultOriginalChars', 'toolResultKeptChars', 'toolResultExpandedChars',
|
|
52
|
+
'schemaCharsBefore', 'schemaCharsAfter', 'contextOmittedChars', 'contextDuplicates',
|
|
53
|
+
'preparedSteps', 'preparedExecuted', 'deterministicSteps', 'postflightSkipped',
|
|
54
|
+
];
|
|
11
55
|
export const TELEMETRY_PROVIDER_TYPES = ['openai-compatible', 'anthropic', 'codex', 'other'];
|
|
12
56
|
export const TELEMETRY_ENDPOINTS = ['hosted', 'local', 'other'];
|
|
13
57
|
export const TELEMETRY_ROLES = ['agent', 'orchestrator', 'subagent', 'jev', 'other'];
|
|
@@ -48,6 +92,10 @@ export const TELEMETRY_BOUNDS = {
|
|
|
48
92
|
jevCounter: 1_000_000,
|
|
49
93
|
nodes: 10_000,
|
|
50
94
|
osMajor: 999,
|
|
95
|
+
watchMinutes: 60,
|
|
96
|
+
watchedPrs: 10_000,
|
|
97
|
+
wakeLatencySeconds: 86_400,
|
|
98
|
+
wakeLatencies: 60,
|
|
51
99
|
};
|
|
52
100
|
const HEX_32 = /^[a-f0-9]{32}$/;
|
|
53
101
|
const isEnum = (allowed, value) => typeof value === 'string' && allowed.includes(value);
|
|
@@ -291,7 +339,7 @@ export function validateTelemetryEvent(value) {
|
|
|
291
339
|
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
292
340
|
throw new SchemaError('the body must be an object');
|
|
293
341
|
const v = value;
|
|
294
|
-
if (v.schema
|
|
342
|
+
if (!Number.isSafeInteger(v.schema) || v.schema < 1 || v.schema > TELEMETRY_SCHEMA)
|
|
295
343
|
throw new SchemaError(`unsupported schema version ${String(v.schema)}`);
|
|
296
344
|
if (!isString(v.eventId, 36) || !/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/.test(v.eventId))
|
|
297
345
|
throw new SchemaError('eventId must be a UUID');
|
|
@@ -302,8 +350,11 @@ export function validateTelemetryEvent(value) {
|
|
|
302
350
|
if (!isString(v.appVersion, 64))
|
|
303
351
|
throw new SchemaError('appVersion is required');
|
|
304
352
|
const event = requireEnum(TELEMETRY_EVENTS, v.event, 'event');
|
|
353
|
+
// A record is labelled with the one version that defines its event.
|
|
354
|
+
if (v.schema !== telemetrySchemaFor(event))
|
|
355
|
+
throw new SchemaError(`unsupported schema version ${String(v.schema)} for ${event}`);
|
|
305
356
|
const identity = {
|
|
306
|
-
schema:
|
|
357
|
+
schema: v.schema,
|
|
307
358
|
eventId: v.eventId,
|
|
308
359
|
installId: v.installId,
|
|
309
360
|
ts: v.ts,
|
|
@@ -315,6 +366,8 @@ export function validateTelemetryEvent(value) {
|
|
|
315
366
|
plan: requireEnum(TELEMETRY_PLANS, v.plan, 'plan'),
|
|
316
367
|
};
|
|
317
368
|
const out = { ...identity, event };
|
|
369
|
+
if (event === 'github.watch')
|
|
370
|
+
return validateGitHubWatch(v, out);
|
|
318
371
|
if (event === 'session.started') {
|
|
319
372
|
if (v.runId !== undefined)
|
|
320
373
|
throw new SchemaError('runId belongs to no session');
|
|
@@ -336,7 +389,7 @@ export function validateTelemetryEvent(value) {
|
|
|
336
389
|
throw new SchemaError('jevEnabled is required');
|
|
337
390
|
out.decisionRouting = requireEnum(TELEMETRY_ROUTING, v.decisionRouting, 'decisionRouting');
|
|
338
391
|
if (event === 'run.started') {
|
|
339
|
-
for (const key of ['outcome', 'failureClass', 'attempts', 'retries', 'durationMs', 'toolCalls', 'toolFailures', 'models', 'tools', 'jev', 'languages', 'frameworks', 'taskCategory']) {
|
|
392
|
+
for (const key of ['outcome', 'failureClass', 'stopReason', 'errorCode', 'errors', 'savings', 'attempts', 'retries', 'durationMs', 'toolCalls', 'toolFailures', 'models', 'tools', 'jev', 'languages', 'frameworks', 'taskCategory']) {
|
|
340
393
|
if (v[key] !== undefined)
|
|
341
394
|
throw new SchemaError(`${key} belongs to run.finished`);
|
|
342
395
|
}
|
|
@@ -348,6 +401,42 @@ export function validateTelemetryEvent(value) {
|
|
|
348
401
|
throw new SchemaError('failureClass is required when outcome is failed');
|
|
349
402
|
if (out.outcome !== 'failed' && out.failureClass !== undefined)
|
|
350
403
|
throw new SchemaError('failureClass is only valid when outcome is failed');
|
|
404
|
+
if (v.stopReason !== undefined) {
|
|
405
|
+
out.stopReason = requireEnum(TELEMETRY_STOP_REASONS, v.stopReason, 'stopReason');
|
|
406
|
+
if (out.outcome === 'completed')
|
|
407
|
+
throw new SchemaError('stopReason is not valid on a completed run');
|
|
408
|
+
}
|
|
409
|
+
if (v.errorCode !== undefined) {
|
|
410
|
+
if (!isTelemetryErrorCode(v.errorCode))
|
|
411
|
+
throw new SchemaError('errorCode is not an allowed value');
|
|
412
|
+
if (out.outcome !== 'failed')
|
|
413
|
+
throw new SchemaError('errorCode is only valid when outcome is failed');
|
|
414
|
+
out.errorCode = v.errorCode;
|
|
415
|
+
}
|
|
416
|
+
if (v.errors !== undefined) {
|
|
417
|
+
if (!Array.isArray(v.errors) || v.errors.length > TELEMETRY_ERROR_KINDS)
|
|
418
|
+
throw new SchemaError(`errors must be an array of at most ${TELEMETRY_ERROR_KINDS} records`);
|
|
419
|
+
out.errors = v.errors.map((record, index) => {
|
|
420
|
+
if (!record || typeof record !== 'object' || Array.isArray(record))
|
|
421
|
+
throw new SchemaError(`errors[${index}] must be an object`);
|
|
422
|
+
const r = record;
|
|
423
|
+
if (!isTelemetryErrorCode(r.code))
|
|
424
|
+
throw new SchemaError(`errors[${index}].code is not an allowed value`);
|
|
425
|
+
return { code: r.code, count: requireInteger(r.count, 1, TELEMETRY_BOUNDS.counter, `errors[${index}].count`) };
|
|
426
|
+
});
|
|
427
|
+
unique(out.errors, record => record.code, 'errors');
|
|
428
|
+
}
|
|
429
|
+
if (v.savings !== undefined) {
|
|
430
|
+
if (!v.savings || typeof v.savings !== 'object' || Array.isArray(v.savings))
|
|
431
|
+
throw new SchemaError('savings must be an object');
|
|
432
|
+
const s = v.savings;
|
|
433
|
+
if (Object.keys(s).some(key => !TELEMETRY_SAVINGS_FIELDS.includes(key)))
|
|
434
|
+
throw new SchemaError('savings has an unknown key');
|
|
435
|
+
const savings = {};
|
|
436
|
+
for (const field of TELEMETRY_SAVINGS_FIELDS)
|
|
437
|
+
savings[field] = requireInteger(s[field], 0, TELEMETRY_BOUNDS.counter, `savings.${field}`);
|
|
438
|
+
out.savings = savings;
|
|
439
|
+
}
|
|
351
440
|
out.durationMs = requireInteger(v.durationMs, 0, TELEMETRY_BOUNDS.durationMs, 'durationMs');
|
|
352
441
|
out.attempts = requireInteger(v.attempts, 0, TELEMETRY_BOUNDS.counter, 'attempts');
|
|
353
442
|
out.retries = requireInteger(v.retries, 0, TELEMETRY_BOUNDS.counter, 'retries');
|
|
@@ -402,6 +491,32 @@ export function validateTelemetryEvent(value) {
|
|
|
402
491
|
out.taskCategory = requireEnum(TELEMETRY_TASK_CATEGORIES, v.taskCategory, 'taskCategory');
|
|
403
492
|
return out;
|
|
404
493
|
}
|
|
494
|
+
/** `github.watch`: one engine's window of GitHub App watching. Counts and coverage states only. */
|
|
495
|
+
function validateGitHubWatch(v, out) {
|
|
496
|
+
if (v.runId !== undefined)
|
|
497
|
+
throw new SchemaError('runId belongs to no watch window');
|
|
498
|
+
out.minutes = requireInteger(v.minutes, 1, TELEMETRY_BOUNDS.watchMinutes, 'minutes');
|
|
499
|
+
if (!Array.isArray(v.watched) || v.watched.length < 1 || v.watched.length > TELEMETRY_GITHUB_COVERAGE.length) {
|
|
500
|
+
throw new SchemaError(`watched must be an array of 1 to ${TELEMETRY_GITHUB_COVERAGE.length} records`);
|
|
501
|
+
}
|
|
502
|
+
out.watched = v.watched.map((record, index) => {
|
|
503
|
+
if (!record || typeof record !== 'object' || Array.isArray(record))
|
|
504
|
+
throw new SchemaError(`watched[${index}] must be an object`);
|
|
505
|
+
const r = record;
|
|
506
|
+
return {
|
|
507
|
+
coverage: requireEnum(TELEMETRY_GITHUB_COVERAGE, r.coverage, `watched[${index}].coverage`),
|
|
508
|
+
prs: requireInteger(r.prs, 1, TELEMETRY_BOUNDS.watchedPrs, `watched[${index}].prs`),
|
|
509
|
+
ghCalls: requireInteger(r.ghCalls, 0, TELEMETRY_BOUNDS.counter, `watched[${index}].ghCalls`),
|
|
510
|
+
};
|
|
511
|
+
});
|
|
512
|
+
unique(out.watched, record => record.coverage, 'watched');
|
|
513
|
+
if (v.wakeLatencies !== undefined) {
|
|
514
|
+
if (!Array.isArray(v.wakeLatencies) || v.wakeLatencies.length > TELEMETRY_BOUNDS.wakeLatencies)
|
|
515
|
+
throw new SchemaError(`wakeLatencies must be an array of at most ${TELEMETRY_BOUNDS.wakeLatencies} values`);
|
|
516
|
+
out.wakeLatencies = v.wakeLatencies.map((seconds, index) => requireInteger(seconds, 0, TELEMETRY_BOUNDS.wakeLatencySeconds, `wakeLatencies[${index}]`));
|
|
517
|
+
}
|
|
518
|
+
return out;
|
|
519
|
+
}
|
|
405
520
|
export function serializeTelemetryEvent(event) {
|
|
406
521
|
return JSON.stringify(validateTelemetryEvent(event));
|
|
407
522
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Config } from '../config.js';
|
|
2
|
-
import { telemetryHome, type RunDimensions, type TelemetryContext } from './emitter.js';
|
|
2
|
+
import { telemetryHome, type GitHubWatchInput, type RunDimensions, type TelemetryContext } from './emitter.js';
|
|
3
3
|
import type { Graph } from '../graphs.js';
|
|
4
4
|
import type { RunTelemetry } from './capture.js';
|
|
5
5
|
import type { ClassifiableStatus } from './classify.js';
|
|
@@ -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;
|
|
@@ -38,6 +39,7 @@ export declare function reportRunFinished(input: SurfaceInput, handle: RunTeleme
|
|
|
38
39
|
retries?: number;
|
|
39
40
|
}): Promise<void>;
|
|
40
41
|
export declare function reportInterruptedRuns(input: SurfaceInput, records: Record<string, unknown>[]): Promise<void>;
|
|
42
|
+
export declare function reportGitHubWatch(input: SurfaceInput, summary: GitHubWatchInput): Promise<void>;
|
|
41
43
|
export declare function reportSessionStarted(input: SurfaceInput & {
|
|
42
44
|
workspace?: string;
|
|
43
45
|
}): Promise<void>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { configDirectory, loadConfig } from '../config.js';
|
|
2
2
|
import { drainOutbox } from './uploader.js';
|
|
3
|
-
import { emitInterruptedRun, emitRunFinished, emitRunStarted, emitSessionStarted, telemetryHome, } from './emitter.js';
|
|
3
|
+
import { emitGitHubWatch, emitInterruptedRun, emitRunFinished, emitRunStarted, emitSessionStarted, telemetryHome, } from './emitter.js';
|
|
4
4
|
import { telemetryDirectory } from './identity.js';
|
|
5
5
|
import { telemetryGate } from './gate.js';
|
|
6
6
|
import { clearInterruptedTelemetry } from '../run-records.js';
|
|
@@ -60,6 +60,9 @@ export async function reportInterruptedRuns(input, records) {
|
|
|
60
60
|
if (reported.length)
|
|
61
61
|
await clearInterruptedTelemetry(input.home ?? configDirectory(), reported).catch(() => { });
|
|
62
62
|
}
|
|
63
|
+
export async function reportGitHubWatch(input, summary) {
|
|
64
|
+
await emitGitHubWatch(contextFor(input), summary);
|
|
65
|
+
}
|
|
63
66
|
export async function reportSessionStarted(input) {
|
|
64
67
|
await emitSessionStarted({ ...contextFor(input), workspace: input.workspace });
|
|
65
68
|
}
|
|
@@ -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;
|