@andorra-labs/code 0.1.14 → 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.
Files changed (180) hide show
  1. package/dist/src/acp-agent.d.ts +54 -0
  2. package/dist/src/acp-agent.js +991 -0
  3. package/dist/src/agent-definitions.js +29 -6
  4. package/dist/src/agent-execution.js +8 -2
  5. package/dist/src/agent-mcp-catalog.js +2 -0
  6. package/dist/src/agent-mcp.d.ts +3 -1
  7. package/dist/src/agent-mcp.js +97 -11
  8. package/dist/src/andorra/entry.js +21 -3
  9. package/dist/src/andorra/hosted.d.ts +3 -0
  10. package/dist/src/andorra/hosted.js +5 -1
  11. package/dist/src/andorra/notices.d.ts +10 -1
  12. package/dist/src/andorra/notices.js +25 -2
  13. package/dist/src/andorra/terminal.d.ts +2 -0
  14. package/dist/src/andorra/terminal.js +2 -2
  15. package/dist/src/app-server/protocol.d.ts +9 -2
  16. package/dist/src/app-server/protocol.js +1 -1
  17. package/dist/src/app-server/workspace.d.ts +1 -0
  18. package/dist/src/app-server/workspace.js +141 -10
  19. package/dist/src/app-server.d.ts +115 -0
  20. package/dist/src/app-server.js +980 -63
  21. package/dist/src/auth/AuthManager.js +4 -4
  22. package/dist/src/auth/deployment.js +2 -2
  23. package/dist/src/browser-bridge.d.ts +1 -0
  24. package/dist/src/browser-bridge.js +5 -2
  25. package/dist/src/browser-external-app.d.ts +27 -0
  26. package/dist/src/browser-external-app.js +60 -0
  27. package/dist/src/browser-panel-tool.d.ts +6 -0
  28. package/dist/src/browser-panel-tool.js +36 -0
  29. package/dist/src/browser-runner.js +1 -0
  30. package/dist/src/browser-server.d.ts +5 -0
  31. package/dist/src/browser-server.js +27 -3
  32. package/dist/src/browser-ui/style.css +3 -3
  33. package/dist/src/browser-ui/tokens.css +27 -16
  34. package/dist/src/browser-view.d.ts +16 -0
  35. package/dist/src/browser-view.js +60 -2
  36. package/dist/src/bug-report.d.ts +81 -0
  37. package/dist/src/bug-report.js +235 -0
  38. package/dist/src/claude-provider.d.ts +2 -1
  39. package/dist/src/claude-provider.js +13 -9
  40. package/dist/src/cli-sign-in.d.ts +3 -1
  41. package/dist/src/cli-sign-in.js +4 -1
  42. package/dist/src/cli.js +184 -40
  43. package/dist/src/codex-errors.js +4 -1
  44. package/dist/src/coding-tools.js +7 -7
  45. package/dist/src/command-screens.d.ts +9 -2
  46. package/dist/src/command-screens.js +166 -97
  47. package/dist/src/commands.d.ts +3 -2
  48. package/dist/src/commands.js +1 -0
  49. package/dist/src/compaction-phrases.d.ts +4 -0
  50. package/dist/src/compaction-phrases.js +20 -0
  51. package/dist/src/completion-gates.d.ts +22 -0
  52. package/dist/src/completion-gates.js +11 -0
  53. package/dist/src/config.d.ts +5 -0
  54. package/dist/src/config.js +48 -0
  55. package/dist/src/context-compaction.js +2 -1
  56. package/dist/src/decision/DecisionManager.js +3 -2
  57. package/dist/src/decision/requestPhrases.d.ts +4 -0
  58. package/dist/src/decision/requestPhrases.js +23 -0
  59. package/dist/src/github-inbox.d.ts +55 -0
  60. package/dist/src/github-inbox.js +153 -0
  61. package/dist/src/google-provider.d.ts +31 -0
  62. package/dist/src/google-provider.js +153 -0
  63. package/dist/src/graph-health.js +8 -4
  64. package/dist/src/graph-manager-chat.js +6 -1
  65. package/dist/src/graph-provider-portability.js +32 -10
  66. package/dist/src/graph-quota.d.ts +29 -2
  67. package/dist/src/graph-quota.js +68 -10
  68. package/dist/src/graph-runner.js +24 -7
  69. package/dist/src/graph-server.d.ts +1 -1
  70. package/dist/src/graph-server.js +9 -7
  71. package/dist/src/graph-sync.d.ts +1 -0
  72. package/dist/src/graph-sync.js +93 -34
  73. package/dist/src/graph-tool.d.ts +2 -0
  74. package/dist/src/graph-tool.js +2 -2
  75. package/dist/src/graph-ui/app.js +177 -41
  76. package/dist/src/graph-ui/controls.css +1 -0
  77. package/dist/src/graph-ui/edge-router.js +121 -53
  78. package/dist/src/graph-ui/embed.js +2 -2
  79. package/dist/src/graph-ui/icons.js +1 -0
  80. package/dist/src/graph-ui/index.html +1 -1
  81. package/dist/src/graph-ui/manager.css +1 -1
  82. package/dist/src/graph-ui/manager.js +2 -2
  83. package/dist/src/graph-ui/sidebar.js +30 -0
  84. package/dist/src/graph-ui/studio-canvas.js +26 -13
  85. package/dist/src/graph-ui/studio.css +15 -7
  86. package/dist/src/graph-ui/studio.js +11 -4
  87. package/dist/src/graph-ui/style.css +77 -45
  88. package/dist/src/graph-ui/theme.js +3 -36
  89. package/dist/src/graph-ui/tokens.css +27 -19
  90. package/dist/src/graph-visibility.d.ts +31 -0
  91. package/dist/src/graph-visibility.js +102 -0
  92. package/dist/src/graphs.js +4 -3
  93. package/dist/src/live-model.d.ts +24 -0
  94. package/dist/src/live-model.js +37 -0
  95. package/dist/src/managed-sign-in.d.ts +1 -0
  96. package/dist/src/managed-sign-in.js +13 -0
  97. package/dist/src/membership-errors.d.ts +2 -0
  98. package/dist/src/membership-errors.js +5 -1
  99. package/dist/src/membership.d.ts +23 -1
  100. package/dist/src/membership.js +48 -6
  101. package/dist/src/model-health-cache.js +1 -1
  102. package/dist/src/model-metadata.d.ts +1 -1
  103. package/dist/src/model-metadata.js +12 -3
  104. package/dist/src/paged-transcript.d.ts +2 -0
  105. package/dist/src/paged-transcript.js +16 -0
  106. package/dist/src/plan-pass.d.ts +59 -0
  107. package/dist/src/plan-pass.js +165 -0
  108. package/dist/src/provider-connection.js +17 -0
  109. package/dist/src/provider-engine.d.ts +5 -0
  110. package/dist/src/provider-engine.js +6 -3
  111. package/dist/src/provider-import.js +3 -1
  112. package/dist/src/provider-settings.js +14 -2
  113. package/dist/src/providers.d.ts +33 -2
  114. package/dist/src/providers.js +101 -28
  115. package/dist/src/pull-request-checks.d.ts +26 -0
  116. package/dist/src/pull-request-checks.js +56 -0
  117. package/dist/src/pull-request-conversation.d.ts +134 -0
  118. package/dist/src/pull-request-conversation.js +221 -0
  119. package/dist/src/pull-request-create.d.ts +175 -0
  120. package/dist/src/pull-request-create.js +392 -0
  121. package/dist/src/pull-request-details.d.ts +242 -0
  122. package/dist/src/pull-request-details.js +614 -0
  123. package/dist/src/pull-request-edit.d.ts +23 -0
  124. package/dist/src/pull-request-edit.js +91 -0
  125. package/dist/src/pull-request-logs.d.ts +76 -0
  126. package/dist/src/pull-request-logs.js +172 -0
  127. package/dist/src/pull-request-merge.d.ts +112 -0
  128. package/dist/src/pull-request-merge.js +258 -0
  129. package/dist/src/pull-request-review.d.ts +137 -0
  130. package/dist/src/pull-request-review.js +401 -0
  131. package/dist/src/pull-requests.d.ts +43 -2
  132. package/dist/src/pull-requests.js +112 -21
  133. package/dist/src/react-runtime.js +58 -9
  134. package/dist/src/read-document-tool.d.ts +2 -0
  135. package/dist/src/read-document-tool.js +6 -6
  136. package/dist/src/remote/engine-pool.js +42 -6
  137. package/dist/src/run-control.d.ts +10 -0
  138. package/dist/src/run-control.js +24 -0
  139. package/dist/src/run-progress.d.ts +10 -0
  140. package/dist/src/run-progress.js +122 -0
  141. package/dist/src/run-records.d.ts +2 -2
  142. package/dist/src/runtime-environment.d.ts +1 -0
  143. package/dist/src/runtime-environment.js +13 -0
  144. package/dist/src/runtime.d.ts +5 -1
  145. package/dist/src/runtime.js +14 -2
  146. package/dist/src/save-lock.js +14 -7
  147. package/dist/src/session-title.d.ts +3 -0
  148. package/dist/src/session-title.js +5 -2
  149. package/dist/src/sign-in-detection.d.ts +1 -1
  150. package/dist/src/sign-in-detection.js +10 -3
  151. package/dist/src/sign-in-offer.js +1 -1
  152. package/dist/src/skill-commands.js +1 -1
  153. package/dist/src/skills/bundled/bug-report/SKILL.md +80 -0
  154. package/dist/src/skills/bundled/graph-manager/SKILL.md +9 -1
  155. package/dist/src/skills/bundled/graph-manager/errors.md +1 -0
  156. package/dist/src/skills/bundled/provenance.json +7 -2
  157. package/dist/src/skills/runtime-skills.js +1 -0
  158. package/dist/src/subagent-run.js +1 -0
  159. package/dist/src/telemetry/capture-core.d.ts +17 -0
  160. package/dist/src/telemetry/capture-core.js +59 -1
  161. package/dist/src/telemetry/classify.d.ts +3 -1
  162. package/dist/src/telemetry/classify.js +37 -0
  163. package/dist/src/telemetry/emitter.d.ts +2 -0
  164. package/dist/src/telemetry/emitter.js +42 -5
  165. package/dist/src/telemetry/schema.d.ts +22 -0
  166. package/dist/src/telemetry/schema.js +68 -1
  167. package/dist/src/telemetry/surface.d.ts +1 -0
  168. package/dist/src/telemetry/uploader.d.ts +12 -1
  169. package/dist/src/telemetry/uploader.js +30 -2
  170. package/dist/src/terminal-links.d.ts +16 -0
  171. package/dist/src/terminal-links.js +113 -0
  172. package/dist/src/terminal-ui.d.ts +8 -1
  173. package/dist/src/terminal-ui.js +40 -14
  174. package/dist/src/tool-catalog.js +1 -1
  175. package/dist/src/trajectory.js +6 -1
  176. package/dist/src/transcript.d.ts +2 -0
  177. package/dist/src/transcript.js +10 -3
  178. package/dist/src/types.d.ts +9 -0
  179. package/dist/src/usage-analytics.js +18 -10
  180. package/package.json +2 -1
@@ -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 outcome = classifyOutcome(input.status, {
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;
@@ -1,5 +1,16 @@
1
1
  import { type TelemetryEvent } from './schema.js';
2
- export declare function telemetryEndpoint(): string | undefined;
2
+ /**
3
+ * Where events are posted. In a run of this repository's own test runner (its marker variable is set) there is
4
+ * no endpoint unless the test names one, so a test that starts an engine against a throwaway home can never
5
+ * report to the production service as a new installation. Nothing a user's own tools set (Node's test-runner
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.
10
+ */
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;
3
14
  export interface UploadDependencies {
4
15
  reporting?: () => Promise<boolean>;
5
16
  fetch?: typeof globalThis.fetch;
@@ -1,12 +1,40 @@
1
+ import { existsSync } from 'node:fs';
1
2
  import { join } from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+ import { TEST_RUN_MARKER } from '../andorra/hosted.js';
2
5
  import { AUTH_DEPLOYMENT } from '../auth/deployment.js';
3
6
  import { enqueue, pruneGeneration, pruneOld, readSpool, rewriteSpool, spoolNames, sweepOutbox, withSpoolLock, withSpoolLockWait, } from './outbox.js';
4
7
  import { serializeTelemetryEvent } from './schema.js';
5
8
  import { uploadSignal } from './uploads.js';
6
- export function telemetryEndpoint() {
7
- const configured = process.env.ANDORRA_TELEMETRY_URL || AUTH_DEPLOYMENT.telemetryBaseUrl;
9
+ /**
10
+ * Where events are posted. In a run of this repository's own test runner (its marker variable is set) there is
11
+ * no endpoint unless the test names one, so a test that starts an engine against a throwaway home can never
12
+ * report to the production service as a new installation. Nothing a user's own tools set (Node's test-runner
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.
17
+ */
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)
21
+ return undefined;
22
+ const configured = override || AUTH_DEPLOYMENT.telemetryBaseUrl;
8
23
  return configured ? configured.replace(/\/+$/, '') : undefined;
9
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
+ }
10
38
  const REQUEST_TIMEOUT_MS = 5_000;
11
39
  async function post(endpoint, event, dependencies) {
12
40
  let body;
@@ -0,0 +1,16 @@
1
+ /** A web address inside one painted row: `start`/`end` index the row's text, `url` is the whole address. */
2
+ export interface RowLink {
3
+ start: number;
4
+ end: number;
5
+ url: string;
6
+ }
7
+ /** The web addresses in one source line, without trailing sentence punctuation. */
8
+ export declare function lineUrls(line: string): string[];
9
+ /**
10
+ * Finds where each address of `line` landed in the rows `line` wrapped into. A terminal only
11
+ * auto-detects an address on the row it starts on, so a wrapped address is clickable on its first
12
+ * row alone unless every piece is marked as a link to the whole address.
13
+ */
14
+ export declare function wrappedLinks(line: string, rows: readonly string[]): (RowLink[] | undefined)[];
15
+ /** Wraps each link range of `text` in an OSC 8 hyperlink; pieces of one address share an id so terminals hover them together. */
16
+ export declare function hyperlinkRow(text: string, links: readonly RowLink[] | undefined): string;
@@ -0,0 +1,113 @@
1
+ import { createHash } from 'node:crypto';
2
+ const URL_PATTERN = /https?:\/\/[^\s<>"'`]+/g;
3
+ const LINKABLE = /^[\x21-\x7e]+$/;
4
+ const CLOSERS = { ')': '(', ']': '[', '}': '{' };
5
+ /** Characters after which an address may start: whitespace or the punctuation that encloses one, as in `label (https://…)`. */
6
+ const OPENER = /[\s([{<"'`]/u;
7
+ const count = (text, character) => text.split(character).length - 1;
8
+ /** Drops sentence punctuation and unmatched closing brackets from the end, keeping balanced ones such as `Function_(mathematics)`. */
9
+ function trimTrailing(url) {
10
+ for (;;) {
11
+ const last = url.at(-1) ?? '';
12
+ const opener = CLOSERS[last];
13
+ if (opener ? count(url, last) > count(url, opener) : /[.,;:!?]/.test(last))
14
+ url = url.slice(0, -1);
15
+ else
16
+ return url;
17
+ }
18
+ }
19
+ /** The web addresses in one source line, without trailing sentence punctuation. */
20
+ export function lineUrls(line) {
21
+ return [...line.matchAll(URL_PATTERN)].map(match => trimTrailing(match[0])).filter(url => url.length > 'https://'.length && LINKABLE.test(url));
22
+ }
23
+ /**
24
+ * Finds where each address of `line` landed in the rows `line` wrapped into. A terminal only
25
+ * auto-detects an address on the row it starts on, so a wrapped address is clickable on its first
26
+ * row alone unless every piece is marked as a link to the whole address.
27
+ */
28
+ export function wrappedLinks(line, rows) {
29
+ const urls = lineUrls(line);
30
+ const result = rows.map(() => undefined);
31
+ if (!urls.length)
32
+ return result;
33
+ let index = 0, consumed = 0;
34
+ for (const [rowIndex, row] of rows.entries()) {
35
+ const links = [];
36
+ let position = 0;
37
+ while (index < urls.length) {
38
+ const url = urls[index];
39
+ if (consumed > 0) {
40
+ const start = row.search(/\S/u);
41
+ const remaining = url.slice(consumed);
42
+ let length = 0;
43
+ while (start >= 0 && length < remaining.length && row[start + length] === remaining[length])
44
+ length++;
45
+ if (!length) {
46
+ consumed = 0;
47
+ index++;
48
+ continue;
49
+ }
50
+ links.push({ start, end: start + length, url });
51
+ consumed += length;
52
+ position = start + length;
53
+ if (consumed < url.length)
54
+ break;
55
+ consumed = 0;
56
+ index++;
57
+ continue;
58
+ }
59
+ const whole = row.indexOf(url, position);
60
+ if (whole >= 0) {
61
+ links.push({ start: whole, end: whole + url.length, url });
62
+ position = whole + url.length;
63
+ index++;
64
+ continue;
65
+ }
66
+ let start = -1;
67
+ for (let at = position; at < row.length; at++) {
68
+ const tail = row.slice(at).trimEnd();
69
+ if (tail && (at === 0 || OPENER.test(row[at - 1])) && url.startsWith(tail) && continues(rows, rowIndex + 1, url.slice(tail.length))) {
70
+ start = at;
71
+ break;
72
+ }
73
+ }
74
+ if (start < 0)
75
+ break;
76
+ const piece = row.slice(start).trimEnd();
77
+ links.push({ start, end: start + piece.length, url });
78
+ consumed = piece.length;
79
+ break;
80
+ }
81
+ if (links.length)
82
+ result[rowIndex] = links;
83
+ }
84
+ return result;
85
+ }
86
+ /** Whether `rest` is spelled out at the start of the rows from `from` on, as wrapping a long address leaves it. */
87
+ function continues(rows, from, rest) {
88
+ for (let row = from; rest && row < rows.length; row++) {
89
+ const text = rows[row].trimStart();
90
+ let length = 0;
91
+ while (length < rest.length && text[length] === rest[length])
92
+ length++;
93
+ if (!length || (length < rest.length && length < text.trimEnd().length))
94
+ return false;
95
+ rest = rest.slice(length);
96
+ }
97
+ return !rest;
98
+ }
99
+ /** Wraps each link range of `text` in an OSC 8 hyperlink; pieces of one address share an id so terminals hover them together. */
100
+ export function hyperlinkRow(text, links) {
101
+ if (!links?.length)
102
+ return text;
103
+ let out = '', cursor = 0;
104
+ for (const link of [...links].sort((a, b) => a.start - b.start)) {
105
+ const end = Math.min(link.end, text.length);
106
+ if (link.start < cursor || link.start >= end || !LINKABLE.test(link.url))
107
+ continue;
108
+ const id = createHash('sha256').update(link.url).digest('hex').slice(0, 12);
109
+ out += text.slice(cursor, link.start) + `\x1b]8;id=${id};${link.url}\x1b\\` + text.slice(link.start, end) + '\x1b]8;;\x1b\\';
110
+ cursor = end;
111
+ }
112
+ return out + text.slice(cursor);
113
+ }
@@ -38,6 +38,8 @@ export interface TerminalStatus {
38
38
  codeIntel?: string;
39
39
  account?: AccountPresentation;
40
40
  jevEnabled?: boolean;
41
+ /** Jev is on but the last run could not use it (signed out, or the account lookup failed); cleared when the Jev setting changes. */
42
+ jevOffThisRun?: boolean;
41
43
  goal?: SessionGoal;
42
44
  changes?: PanelChanges;
43
45
  terminals?: readonly PanelTerminal[];
@@ -48,6 +50,8 @@ export interface TerminalOptions extends TerminalStatus {
48
50
  workspace: string;
49
51
  version: string;
50
52
  appName?: string;
53
+ /** The current session's id, read on every frame so a resume, fork or /new shows at once. */
54
+ sessionId?: () => string | undefined;
51
55
  tokenClock?: () => number;
52
56
  clipboardImageProbe?: () => Promise<Buffer | undefined>;
53
57
  clipboardTextWriter?: (text: string) => Promise<void>;
@@ -109,6 +113,7 @@ export declare class TerminalUI extends EventEmitter {
109
113
  requests: number;
110
114
  }): void;
111
115
  private readonly tokenClock;
116
+ private readonly sessionId;
112
117
  private speedMeters;
113
118
  private speedInvocations;
114
119
  private activeSpeedNode;
@@ -142,6 +147,8 @@ export declare class TerminalUI extends EventEmitter {
142
147
  private value;
143
148
  private cursor;
144
149
  private transcript;
150
+ /** The newest transcript entry, while it is one that a later print with the same key rewrites. */
151
+ private replaceable?;
145
152
  private expandedTranscript;
146
153
  private todos;
147
154
  private expandedTodos;
@@ -238,7 +245,7 @@ export declare class TerminalUI extends EventEmitter {
238
245
  loadScreen<T>(title: string, load: (signal: AbortSignal) => Promise<T>, options?: ScreenOptions): Promise<T | undefined>;
239
246
  private openModal;
240
247
  private finishModal;
241
- print(text: string, detail?: string, toolCall?: ToolCallStamp, conversation?: boolean, notice?: boolean, alignRight?: boolean, clipRows?: boolean): void;
248
+ print(text: string, detail?: string, toolCall?: ToolCallStamp, conversation?: boolean, notice?: boolean, alignRight?: boolean, clipRows?: boolean, replaceKey?: string): void;
242
249
  printPrompt(text: string, title?: string): void;
243
250
  appendThinking(delta: string): void;
244
251
  clearConversation(): void;