@andorra-labs/code 0.1.16 → 0.1.18

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 (236) hide show
  1. package/dist/src/acp-agent.d.ts +6 -0
  2. package/dist/src/acp-agent.js +15 -4
  3. package/dist/src/agent-execution.js +108 -19
  4. package/dist/src/agent-mcp-catalog.js +1 -0
  5. package/dist/src/agent-mcp.d.ts +3 -0
  6. package/dist/src/agent-mcp.js +33 -1
  7. package/dist/src/andorra/entry.d.ts +10 -0
  8. package/dist/src/andorra/entry.js +18 -4
  9. package/dist/src/andorra/errors.js +3 -0
  10. package/dist/src/andorra/hosted.d.ts +2 -1
  11. package/dist/src/andorra/hosted.js +2 -1
  12. package/dist/src/andorra/notices.d.ts +5 -0
  13. package/dist/src/andorra/notices.js +7 -0
  14. package/dist/src/andorra/state.d.ts +3 -2
  15. package/dist/src/andorra/state.js +4 -4
  16. package/dist/src/andorra/terminal.js +7 -2
  17. package/dist/src/anthropic-credentials.js +2 -0
  18. package/dist/src/app-server/error.d.ts +5 -0
  19. package/dist/src/app-server/error.js +7 -0
  20. package/dist/src/app-server/protocol.d.ts +30 -44
  21. package/dist/src/app-server/protocol.js +5 -1
  22. package/dist/src/app-server/workspace.d.ts +108 -0
  23. package/dist/src/app-server/workspace.js +608 -11
  24. package/dist/src/app-server.d.ts +390 -33
  25. package/dist/src/app-server.js +3033 -565
  26. package/dist/src/attachments.d.ts +10 -0
  27. package/dist/src/attachments.js +102 -7
  28. package/dist/src/automation-tool.js +2 -1
  29. package/dist/src/bridge/cloud.d.ts +27 -0
  30. package/dist/src/bridge/cloud.js +187 -0
  31. package/dist/src/bridge/command.d.ts +30 -0
  32. package/dist/src/bridge/command.js +359 -0
  33. package/dist/src/bridge/control.d.ts +70 -0
  34. package/dist/src/bridge/control.js +238 -0
  35. package/dist/src/bridge/engines.d.ts +90 -0
  36. package/dist/src/bridge/engines.js +601 -0
  37. package/dist/src/bridge/github.d.ts +108 -0
  38. package/dist/src/bridge/github.js +378 -0
  39. package/dist/src/bridge/host-ops.d.ts +9 -0
  40. package/dist/src/bridge/host-ops.js +139 -0
  41. package/dist/src/bridge/host.d.ts +47 -0
  42. package/dist/src/bridge/host.js +543 -0
  43. package/dist/src/bridge/link.d.ts +38 -0
  44. package/dist/src/bridge/link.js +508 -0
  45. package/dist/src/bridge/login-link.d.ts +29 -0
  46. package/dist/src/bridge/login-link.js +54 -0
  47. package/dist/src/bridge/protocol.d.ts +136 -0
  48. package/dist/src/bridge/protocol.js +11 -0
  49. package/dist/src/bridge/store.d.ts +12 -0
  50. package/dist/src/bridge/store.js +61 -0
  51. package/dist/src/bridge/wording.d.ts +6 -0
  52. package/dist/src/bridge/wording.js +10 -0
  53. package/dist/src/browser-server.js +7 -1
  54. package/dist/src/browser-ui/tokens.css +1 -1
  55. package/dist/src/bug-report-attachments.d.ts +48 -0
  56. package/dist/src/bug-report-attachments.js +327 -0
  57. package/dist/src/bug-report.d.ts +23 -3
  58. package/dist/src/bug-report.js +72 -9
  59. package/dist/src/change-authors.d.ts +41 -0
  60. package/dist/src/change-authors.js +146 -0
  61. package/dist/src/cli.d.ts +1 -3
  62. package/dist/src/cli.js +191 -35
  63. package/dist/src/codex-provider.js +1 -1
  64. package/dist/src/coding-tools.js +24 -17
  65. package/dist/src/command-screens.d.ts +6 -0
  66. package/dist/src/command-screens.js +14 -11
  67. package/dist/src/commands.d.ts +15 -3
  68. package/dist/src/commands.js +2 -1
  69. package/dist/src/compaction-phrases.js +1 -1
  70. package/dist/src/completion.js +89 -8
  71. package/dist/src/config.d.ts +71 -3
  72. package/dist/src/config.js +205 -78
  73. package/dist/src/context-budget.js +15 -2
  74. package/dist/src/deadline.js +13 -1
  75. package/dist/src/decision/DecisionEngine.d.ts +2 -0
  76. package/dist/src/decision/DecisionManager.d.ts +11 -0
  77. package/dist/src/decision/DecisionManager.js +36 -0
  78. package/dist/src/decision/applyTaskKind.d.ts +8 -0
  79. package/dist/src/decision/applyTaskKind.js +53 -0
  80. package/dist/src/decision/checks.js +1 -1
  81. package/dist/src/decision/hostedPolicy.js +2 -1
  82. package/dist/src/decision/providers/AndorraDecisionProvider.d.ts +2 -0
  83. package/dist/src/decision/providers/AndorraDecisionProvider.js +12 -0
  84. package/dist/src/decision/requestPhrases.js +0 -1
  85. package/dist/src/decision/taskKind.d.ts +52 -0
  86. package/dist/src/decision/taskKind.js +76 -0
  87. package/dist/src/decision/types.d.ts +1 -1
  88. package/dist/src/default-graph.js +1 -1
  89. package/dist/src/efficiency.d.ts +5 -0
  90. package/dist/src/efficiency.js +5 -1
  91. package/dist/src/effort-routing.d.ts +27 -0
  92. package/dist/src/effort-routing.js +34 -0
  93. package/dist/src/evidence.d.ts +110 -0
  94. package/dist/src/evidence.js +195 -0
  95. package/dist/src/file-diff.d.ts +4 -0
  96. package/dist/src/file-diff.js +2 -1
  97. package/dist/src/github-app/agent-writes.d.ts +102 -0
  98. package/dist/src/github-app/agent-writes.js +320 -0
  99. package/dist/src/github-app/client.d.ts +368 -0
  100. package/dist/src/github-app/client.js +830 -0
  101. package/dist/src/github-app/event-source.d.ts +208 -0
  102. package/dist/src/github-app/event-source.js +684 -0
  103. package/dist/src/github-app/metrics.d.ts +32 -0
  104. package/dist/src/github-app/metrics.js +49 -0
  105. package/dist/src/github-app/review-loop.d.ts +274 -0
  106. package/dist/src/github-app/review-loop.js +1177 -0
  107. package/dist/src/github-app/review-node.d.ts +81 -0
  108. package/dist/src/github-app/review-node.js +205 -0
  109. package/dist/src/github-app/review-post.d.ts +73 -0
  110. package/dist/src/github-app/review-post.js +139 -0
  111. package/dist/src/github-app/review-text.d.ts +107 -0
  112. package/dist/src/github-app/review-text.js +1133 -0
  113. package/dist/src/github-app/review-threads.d.ts +47 -0
  114. package/dist/src/github-app/review-threads.js +107 -0
  115. package/dist/src/github-app/reviewer.d.ts +121 -0
  116. package/dist/src/github-app/reviewer.js +598 -0
  117. package/dist/src/github-app/store.d.ts +59 -0
  118. package/dist/src/github-app/store.js +148 -0
  119. package/dist/src/github-app/triggers.d.ts +141 -0
  120. package/dist/src/github-app/triggers.js +441 -0
  121. package/dist/src/github-names.d.ts +15 -0
  122. package/dist/src/github-names.js +15 -0
  123. package/dist/src/glob-search.d.ts +61 -0
  124. package/dist/src/glob-search.js +180 -0
  125. package/dist/src/graph-health.js +6 -1
  126. package/dist/src/graph-manager-chat.js +1 -1
  127. package/dist/src/graph-preview.d.ts +48 -0
  128. package/dist/src/graph-preview.js +56 -0
  129. package/dist/src/graph-provider-portability.js +2 -1
  130. package/dist/src/graph-runner.js +65 -4
  131. package/dist/src/graph-server.js +7 -5
  132. package/dist/src/graph-sync.js +3 -3
  133. package/dist/src/graph-ui/app.js +121 -7
  134. package/dist/src/graph-ui/icons.js +2 -1
  135. package/dist/src/graph-ui/studio.js +15 -1
  136. package/dist/src/graph-ui/tokens.css +1 -1
  137. package/dist/src/graphs.d.ts +40 -1
  138. package/dist/src/graphs.js +164 -15
  139. package/dist/src/hardened-runtime.js +32 -21
  140. package/dist/src/image-input.d.ts +16 -0
  141. package/dist/src/image-input.js +41 -0
  142. package/dist/src/membership.d.ts +10 -0
  143. package/dist/src/membership.js +19 -4
  144. package/dist/src/model-health-cache.js +1 -1
  145. package/dist/src/model-metadata.d.ts +6 -0
  146. package/dist/src/model-metadata.js +35 -15
  147. package/dist/src/model-override.d.ts +2 -1
  148. package/dist/src/model-override.js +9 -0
  149. package/dist/src/model-relay/local.d.ts +116 -0
  150. package/dist/src/model-relay/local.js +468 -0
  151. package/dist/src/model-relay/remote.d.ts +129 -0
  152. package/dist/src/model-relay/remote.js +252 -0
  153. package/dist/src/model-relay/runs.d.ts +34 -0
  154. package/dist/src/model-relay/runs.js +146 -0
  155. package/dist/src/model-relay/wire.d.ts +5 -0
  156. package/dist/src/model-relay/wire.js +5 -0
  157. package/dist/src/model-tiers.d.ts +3 -0
  158. package/dist/src/model-tiers.js +3 -3
  159. package/dist/src/project-registry.d.ts +21 -0
  160. package/dist/src/project-registry.js +74 -0
  161. package/dist/src/provider-engine.d.ts +13 -1
  162. package/dist/src/provider-engine.js +74 -0
  163. package/dist/src/provider-import.d.ts +0 -12
  164. package/dist/src/provider-import.js +7 -195
  165. package/dist/src/providers.d.ts +28 -2
  166. package/dist/src/providers.js +59 -12
  167. package/dist/src/pull-request-logs.d.ts +12 -1
  168. package/dist/src/pull-request-logs.js +14 -3
  169. package/dist/src/pull-requests.d.ts +338 -8
  170. package/dist/src/pull-requests.js +482 -53
  171. package/dist/src/react-runtime.js +99 -16
  172. package/dist/src/remote/engine-pool.d.ts +88 -4
  173. package/dist/src/remote/engine-pool.js +367 -90
  174. package/dist/src/remote/roots.d.ts +19 -0
  175. package/dist/src/remote/roots.js +45 -7
  176. package/dist/src/remote/types.d.ts +0 -44
  177. package/dist/src/run-control.d.ts +7 -0
  178. package/dist/src/run-control.js +23 -0
  179. package/dist/src/run-records.d.ts +7 -2
  180. package/dist/src/run-records.js +71 -6
  181. package/dist/src/runtime.d.ts +34 -2
  182. package/dist/src/runtime.js +18 -2
  183. package/dist/src/session-changes.d.ts +35 -0
  184. package/dist/src/session-changes.js +194 -6
  185. package/dist/src/session-monitor.js +2 -1
  186. package/dist/src/session-reaper.d.ts +1 -1
  187. package/dist/src/session-reaper.js +6 -1
  188. package/dist/src/session-summary.d.ts +2 -1
  189. package/dist/src/session-summary.js +2 -1
  190. package/dist/src/sessions.d.ts +35 -1
  191. package/dist/src/sessions.js +70 -4
  192. package/dist/src/skills/bundled/bug-report/SKILL.md +51 -7
  193. package/dist/src/skills/bundled/diagram/SKILL.md +5 -3
  194. package/dist/src/skills/bundled/graph-manager/SKILL.md +7 -4
  195. package/dist/src/skills/bundled/provenance.json +3 -3
  196. package/dist/src/skills/runtime-skills.js +1 -1
  197. package/dist/src/task-checkout.d.ts +141 -0
  198. package/dist/src/task-checkout.js +558 -0
  199. package/dist/src/telemetry/emitter.d.ts +15 -0
  200. package/dist/src/telemetry/emitter.js +35 -1
  201. package/dist/src/telemetry/schema.d.ts +25 -2
  202. package/dist/src/telemetry/schema.js +52 -4
  203. package/dist/src/telemetry/surface.d.ts +2 -1
  204. package/dist/src/telemetry/surface.js +4 -1
  205. package/dist/src/terminal-ui.d.ts +1 -0
  206. package/dist/src/terminal-ui.js +10 -3
  207. package/dist/src/test-edit-guard.d.ts +37 -0
  208. package/dist/src/test-edit-guard.js +216 -3
  209. package/dist/src/thinking-level-detect.d.ts +11 -0
  210. package/dist/src/thinking-level-detect.js +47 -0
  211. package/dist/src/thinking-levels.d.ts +30 -0
  212. package/dist/src/thinking-levels.js +124 -0
  213. package/dist/src/timers.d.ts +3 -0
  214. package/dist/src/tool-catalog.js +1 -1
  215. package/dist/src/tools.js +59 -9
  216. package/dist/src/transcript.js +1 -1
  217. package/dist/src/types.d.ts +34 -0
  218. package/package.json +6 -1
  219. package/dist/src/remote/cert.d.ts +0 -11
  220. package/dist/src/remote/cert.js +0 -87
  221. package/dist/src/remote/client.d.ts +0 -119
  222. package/dist/src/remote/client.js +0 -544
  223. package/dist/src/remote/command.d.ts +0 -4
  224. package/dist/src/remote/command.js +0 -194
  225. package/dist/src/remote/errors.d.ts +0 -11
  226. package/dist/src/remote/errors.js +0 -14
  227. package/dist/src/remote/network.d.ts +0 -22
  228. package/dist/src/remote/network.js +0 -102
  229. package/dist/src/remote/pairing.d.ts +0 -63
  230. package/dist/src/remote/pairing.js +0 -299
  231. package/dist/src/remote/pem.d.ts +0 -2
  232. package/dist/src/remote/pem.js +0 -7
  233. package/dist/src/remote/serve.d.ts +0 -68
  234. package/dist/src/remote/serve.js +0 -244
  235. package/dist/src/remote/server.d.ts +0 -21
  236. package/dist/src/remote/server.js +0 -406
@@ -1,7 +1,22 @@
1
- export declare const TELEMETRY_SCHEMA = 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"];
@@ -127,6 +142,10 @@ export interface TelemetryEvent extends TelemetryIdentity {
127
142
  languages?: TelemetryLanguage[];
128
143
  frameworks?: TelemetryFramework[];
129
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[];
130
149
  }
131
150
  export declare const TELEMETRY_BOUNDS: {
132
151
  readonly token: 1000000000000;
@@ -137,6 +156,10 @@ export declare const TELEMETRY_BOUNDS: {
137
156
  readonly jevCounter: 1000000;
138
157
  readonly nodes: 10000;
139
158
  readonly osMajor: 999;
159
+ readonly watchMinutes: 60;
160
+ readonly watchedPrs: 10000;
161
+ readonly wakeLatencySeconds: 86400;
162
+ readonly wakeLatencies: 60;
140
163
  };
141
164
  export declare function telemetryTimestamp(date?: Date): string;
142
165
  export declare function telemetryEventId(): string;
@@ -1,9 +1,22 @@
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
- export const TELEMETRY_SCHEMA = 1;
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'];
@@ -79,6 +92,10 @@ export const TELEMETRY_BOUNDS = {
79
92
  jevCounter: 1_000_000,
80
93
  nodes: 10_000,
81
94
  osMajor: 999,
95
+ watchMinutes: 60,
96
+ watchedPrs: 10_000,
97
+ wakeLatencySeconds: 86_400,
98
+ wakeLatencies: 60,
82
99
  };
83
100
  const HEX_32 = /^[a-f0-9]{32}$/;
84
101
  const isEnum = (allowed, value) => typeof value === 'string' && allowed.includes(value);
@@ -322,7 +339,7 @@ export function validateTelemetryEvent(value) {
322
339
  if (!value || typeof value !== 'object' || Array.isArray(value))
323
340
  throw new SchemaError('the body must be an object');
324
341
  const v = value;
325
- if (v.schema !== TELEMETRY_SCHEMA)
342
+ if (!Number.isSafeInteger(v.schema) || v.schema < 1 || v.schema > TELEMETRY_SCHEMA)
326
343
  throw new SchemaError(`unsupported schema version ${String(v.schema)}`);
327
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))
328
345
  throw new SchemaError('eventId must be a UUID');
@@ -333,8 +350,11 @@ export function validateTelemetryEvent(value) {
333
350
  if (!isString(v.appVersion, 64))
334
351
  throw new SchemaError('appVersion is required');
335
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}`);
336
356
  const identity = {
337
- schema: TELEMETRY_SCHEMA,
357
+ schema: v.schema,
338
358
  eventId: v.eventId,
339
359
  installId: v.installId,
340
360
  ts: v.ts,
@@ -346,6 +366,8 @@ export function validateTelemetryEvent(value) {
346
366
  plan: requireEnum(TELEMETRY_PLANS, v.plan, 'plan'),
347
367
  };
348
368
  const out = { ...identity, event };
369
+ if (event === 'github.watch')
370
+ return validateGitHubWatch(v, out);
349
371
  if (event === 'session.started') {
350
372
  if (v.runId !== undefined)
351
373
  throw new SchemaError('runId belongs to no session');
@@ -469,6 +491,32 @@ export function validateTelemetryEvent(value) {
469
491
  out.taskCategory = requireEnum(TELEMETRY_TASK_CATEGORIES, v.taskCategory, 'taskCategory');
470
492
  return out;
471
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
+ }
472
520
  export function serializeTelemetryEvent(event) {
473
521
  return JSON.stringify(validateTelemetryEvent(event));
474
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';
@@ -39,6 +39,7 @@ export declare function reportRunFinished(input: SurfaceInput, handle: RunTeleme
39
39
  retries?: number;
40
40
  }): Promise<void>;
41
41
  export declare function reportInterruptedRuns(input: SurfaceInput, records: Record<string, unknown>[]): Promise<void>;
42
+ export declare function reportGitHubWatch(input: SurfaceInput, summary: GitHubWatchInput): Promise<void>;
42
43
  export declare function reportSessionStarted(input: SurfaceInput & {
43
44
  workspace?: string;
44
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
  }
@@ -229,6 +229,7 @@ export declare class TerminalUI extends EventEmitter {
229
229
  conversationPrompt?: boolean;
230
230
  history?: boolean;
231
231
  secret?: boolean;
232
+ yieldToQuestions?: boolean;
232
233
  }): Promise<string>;
233
234
  chooseQuestion(prompt: string, items: TerminalChoice[], options?: {
234
235
  kind?: 'question' | 'approval';
@@ -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', '/compact', '/yolo', '/permissions', '/jev', '/help', '/status', '/usage', '/tools', '/exit', '/quit'];
88
+ const liveRunCommands = ['/model', '/providers', '/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`;
@@ -696,6 +696,13 @@ export class TerminalUI extends EventEmitter {
696
696
  if (this.closed)
697
697
  return Promise.reject(new Error('Terminal is closed'));
698
698
  this.yieldScreen();
699
+ // A prompt that yields gives way to the run's question: the caller sees an AbortError and closes its screen.
700
+ if (this.pending && !options.yieldToQuestions) {
701
+ const held = this.pending;
702
+ if (!held.yieldToQuestions)
703
+ return Promise.reject(new Error('A terminal question is already active'));
704
+ held.abort?.();
705
+ }
699
706
  if (this.pending)
700
707
  return Promise.reject(new Error('A terminal question is already active'));
701
708
  if (this.modal)
@@ -718,7 +725,7 @@ export class TerminalUI extends EventEmitter {
718
725
  if (!regular)
719
726
  this.print(label);
720
727
  return new Promise((resolve, reject) => {
721
- const pending = { kind: options.kind ?? 'question', resolve, reject, signal: options.signal, label: oneLine(label), title: options.title ? oneLine(options.title).trim() : undefined, regular, cancelOnEscape: options.cancelOnEscape, conversationPrompt: options.conversationPrompt === true, secret: options.secret, history: regular && options.history !== false && !options.secret };
728
+ const pending = { kind: options.kind ?? 'question', resolve, reject, signal: options.signal, label: oneLine(label), title: options.title ? oneLine(options.title).trim() : undefined, regular, cancelOnEscape: options.cancelOnEscape, conversationPrompt: options.conversationPrompt === true, secret: options.secret, history: regular && options.history !== false && !options.secret, yieldToQuestions: options.yieldToQuestions === true };
722
729
  pending.abort = () => { if (this.pending !== pending)
723
730
  return; this.finishQuestion(); reject(new DOMException('Question aborted', 'AbortError')); this.scheduleRender(); };
724
731
  this.pending = pending;
@@ -731,7 +738,7 @@ export class TerminalUI extends EventEmitter {
731
738
  if (!items.length || items.some(item => !item.id))
732
739
  throw new Error('Question choices require nonempty IDs');
733
740
  this.yieldScreen();
734
- if (this.pending || this.modal)
741
+ if (this.modal || (this.pending && !this.pending.yieldToQuestions))
735
742
  throw new Error('A terminal question or screen is already active');
736
743
  const displayedPrompt = prompt === 'Choose an answer' ? this.dashboardNotices.at(-1) ?? prompt : prompt;
737
744
  if (options.printPrompt !== false)
@@ -14,6 +14,12 @@ export declare function isTestPath(name: string): boolean;
14
14
  /** True when the task itself asks for existing tests to change, so editing them is the work and not a shortcut. */
15
15
  export declare function taskAsksForTestChanges(task: string | undefined): boolean;
16
16
  export declare function testEditNudge(edits: readonly TestEdit[], restoreFrom?: string): string;
17
+ /**
18
+ * The reminder for a run that changed code through the file tools and finishes with none of it left:
19
+ * a fix that was applied, checked and then taken out again (to compare against the original, or to
20
+ * leave the workspace as it was found) is not delivered.
21
+ */
22
+ export declare function undoneWorkNudge(files: readonly string[]): string;
17
23
  /**
18
24
  * Finds files under test locations that existed when a run started and were modified or deleted
19
25
  * during it. In a Git repository the comparison is against the commit and working tree the run
@@ -26,6 +32,8 @@ export declare class TestEditGuard {
26
32
  private readonly nudged;
27
33
  private readonly created;
28
34
  private readonly toolEdits;
35
+ private readonly sourceEdits;
36
+ private undoneAsked;
29
37
  private restoreFrom?;
30
38
  private readonly startedAt;
31
39
  private readonly stopper;
@@ -65,7 +73,36 @@ export declare class TestEditGuard {
65
73
  * a file born after the run started was made by the run (through the shell, say) and is its own to change.
66
74
  */
67
75
  noteToolMutation(target: string, existed: boolean, bornAtMs?: number): void;
76
+ /** False for a link to another file: the edit changed that file, which is reported under its own path. */
77
+ private namesItself;
78
+ /**
79
+ * The files outside test locations that existed before the run and were changed through Write or
80
+ * Edit, when the workspace's tracked code is now identical to the commit the run started from: the
81
+ * run undid everything it changed. Raised once. Nothing is reported without Git, when any tracked
82
+ * file outside test locations still differs (the work is there, perhaps in another file), when an
83
+ * edited file is not tracked (its contents cannot be compared) or already differed from the commit
84
+ * when the run started (returning it to the commit may be the fix), or on a Git failure, so a
85
+ * doubt never holds a run back.
86
+ */
87
+ undone(signal?: AbortSignal): Promise<string[]>;
88
+ /**
89
+ * The modified test files whose change only adds new tests: no line of the starting commit's file was
90
+ * removed or replaced, and nothing added switches a test off or defines again a name the file already
91
+ * had. Appending a regression test to an existing test file is ordinary work, not a rewrite of the
92
+ * tests that constrain the fix. Any doubt (a Git failure, a file that is not test code) keeps the file flagged.
93
+ */
94
+ private onlyAddsTests;
68
95
  private current;
96
+ /**
97
+ * True, once, when the run finishes with the workspace's tracked code identical to the commit it
98
+ * started from, no edited file outside Git's view and no surviving new source file written through
99
+ * the file tools: nothing a task that calls for a change could have delivered. False without Git,
100
+ * on a Git failure, when the workspace's code already differed from the commit at the start, and
101
+ * after undone() or this has already raised the matter, so the agent is asked about it a single time.
102
+ * With testsCount, a change to a test file is work too: a request to write tests is delivered by them,
103
+ * while a defect is not fixed by a test alone.
104
+ */
105
+ unchanged(signal?: AbortSignal, testsCount?: boolean): Promise<boolean>;
69
106
  /**
70
107
  * Returns the changed pre-existing test files when at least one of them has not been reported yet,
71
108
  * and marks them reported; returns nothing otherwise, so each set of files is raised once.
@@ -10,10 +10,19 @@ function within(root, target) {
10
10
  const TEST_DIRECTORY = /(?:^|\/)(?:tests?|testing|__tests__|__snapshots__|baseline_images|testdata|test_data)\//i;
11
11
  const TEST_FILE = /(?:^|\/)(?:test_[^/]*\.py|conftest\.py|[^/]+_test\.[^/]+|[^/]+\.(?:test|spec)\.[^/]+)$/i;
12
12
  const ASKS_FOR_TEST_CHANGES = /\b(?:add|adds|adding|update|updates|updating|fix|fixes|fixing|change|changes|changing|modify|modifying|rewrite|rewriting|adjust|adjusting|extend|extending|refactor|refactoring|delete|deleting|remove|removing|rename|renaming|migrate|migrating|port|porting|regenerate|regenerating|write|writing)\b[^.!?\n]{0,60}\b(?:tests?|specs?|test suite|fixtures?|snapshots?|baselines?|conftest)\b/i;
13
+ /** Test source files, where an added line is a new test rather than new expected output. */
14
+ const ADDITIVE_TEST_CODE = /\.(?:py|[cm]?[jt]sx?|go|rs|java|kt|rb|php|cs|c|cc|cpp|h|hpp|swift|scala)$/i;
15
+ const FIXTURE_LOCATION = /(?:^|\/)(?:conftest\.py$|(?:__snapshots__|baseline_images|testdata|test_data|fixtures?)\/)/i;
16
+ /** An added line that can switch an existing test off, or narrow the run to some tests. */
17
+ const DISABLES_TESTS = /skip|xfail|expectedFailure|\bx(?:it|test|describe)\b|\.(?:only|todo|fixme)\b|\bf(?:it|describe)\b|collect_ignore|pytestmark|\bignore\b|\bdisabled?\b|\bpending\b/i;
18
+ /** A named definition; one that repeats a name already in the file replaces the earlier one in most languages. */
19
+ const DECLARATION = /^\s*(?:export\s+)?(?:public\s+|private\s+|protected\s+|static\s+|async\s+)*(?:def|class|func|function|fn|fun|void|module)\s+([A-Za-z_$][\w$]*)/;
20
+ const ADDITIVE_FILE_LIMIT = 40;
13
21
  const GIT_TIMEOUT_MS = 5_000;
14
22
  const HASH_FILE_LIMIT = 8 * 1024 * 1024;
15
23
  const BASELINE_DIRTY_LIMIT = 2_000;
16
24
  const MAX_NAMED_FILES = 12;
25
+ const UNTRACKED_LIMIT = 200;
17
26
  /** True for a path that holds tests, fixtures or expected output: a tests/test/testing directory, test_*.py, *_test.*, *.test.*, *.spec.*, conftest.py. */
18
27
  export function isTestPath(name) {
19
28
  const normalized = name.replace(/\\/g, '/').replace(/^\.\//, '');
@@ -42,9 +51,22 @@ export function testEditNudge(edits, restoreFrom) {
42
51
  : 'undo those edits';
43
52
  return `Completion not accepted yet. ${edits.length === 1 ? 'This test file' : 'These test files'} existed before this run and ${edits.length === 1 ? 'was' : 'were'} changed during it: ${named}${more}. `
44
53
  + 'An existing test that fails after your change is a constraint on the fix, not something to rewrite to fit it. '
45
- + `Unless the task explicitly asks for these tests to change, ${restore} and change the code until the original tests pass.${keep} Adding new test files is fine. `
54
+ + `Unless the task explicitly asks for these tests to change, ${restore} and change the code until the original tests pass.${keep} Adding new test files is fine, and so is adding new tests to an existing file without changing what it already holds. `
46
55
  + 'If the task does require these edits, call complete_agent again to finish; this reminder is not repeated for the same files.';
47
56
  }
57
+ /**
58
+ * The reminder for a run that changed code through the file tools and finishes with none of it left:
59
+ * a fix that was applied, checked and then taken out again (to compare against the original, or to
60
+ * leave the workspace as it was found) is not delivered.
61
+ */
62
+ export function undoneWorkNudge(files) {
63
+ const named = files.slice(0, MAX_NAMED_FILES).join(', ');
64
+ const more = files.length > MAX_NAMED_FILES ? `, and ${files.length - MAX_NAMED_FILES} more` : '';
65
+ const one = files.length === 1;
66
+ return `Completion not accepted yet. This run changed ${named}${more} and then restored ${one ? 'it' : 'them'}: the workspace now holds no change to its code. `
67
+ + 'If a change you made fixes a defect the task describes, apply it again and leave it in place. A fix that was verified and then removed is not delivered, and comparing against the original code is no reason to drop it. '
68
+ + 'If the changes were only instrumentation, or the task needs only an answer, call complete_agent again to finish; this reminder is not repeated.';
69
+ }
48
70
  function git(cwd, args, signal) {
49
71
  return new Promise((resolve, reject) => {
50
72
  execFile('git', ['-c', 'core.quotepath=off', ...args], {
@@ -91,6 +113,8 @@ export class TestEditGuard {
91
113
  nudged = new Set();
92
114
  created = new Set();
93
115
  toolEdits = new Map();
116
+ sourceEdits = new Set();
117
+ undoneAsked = false;
94
118
  restoreFrom;
95
119
  startedAt = Date.now();
96
120
  stopper = new AbortController();
@@ -156,7 +180,8 @@ export class TestEditGuard {
156
180
  }
157
181
  this.captured = true;
158
182
  this.restoreFrom = head.slice(0, 12);
159
- return { kind: 'git', root: path.resolve(root), prefix, head, dirty, unknown };
183
+ return { kind: 'git', root: path.resolve(root), prefix, head, dirty, unknown,
184
+ ...(local.length <= BASELINE_DIRTY_LIMIT ? { dirtyNames: new Set(local) } : {}) };
160
185
  }
161
186
  /**
162
187
  * Reports, before it runs, a tool that may change files: target is the file a file tool changes,
@@ -202,8 +227,111 @@ export class TestEditGuard {
202
227
  this.created.add(relative);
203
228
  return;
204
229
  }
205
- if (!this.created.has(relative) && isTestPath(relative))
230
+ if (this.created.has(relative))
231
+ return;
232
+ if (isTestPath(relative))
206
233
  this.toolEdits.set(relative, 'modified');
234
+ else if (this.namesItself(target, relative))
235
+ this.sourceEdits.add(relative);
236
+ }
237
+ /** False for a link to another file: the edit changed that file, which is reported under its own path. */
238
+ namesItself(target, relative) {
239
+ try {
240
+ return this.workspaceRelative(realpathSync(target)) === relative;
241
+ }
242
+ catch {
243
+ return true;
244
+ }
245
+ }
246
+ /**
247
+ * The files outside test locations that existed before the run and were changed through Write or
248
+ * Edit, when the workspace's tracked code is now identical to the commit the run started from: the
249
+ * run undid everything it changed. Raised once. Nothing is reported without Git, when any tracked
250
+ * file outside test locations still differs (the work is there, perhaps in another file), when an
251
+ * edited file is not tracked (its contents cannot be compared) or already differed from the commit
252
+ * when the run started (returning it to the commit may be the fix), or on a Git failure, so a
253
+ * doubt never holds a run back.
254
+ */
255
+ async undone(signal) {
256
+ if (this.undoneAsked || !this.sourceEdits.size)
257
+ return [];
258
+ const baseline = await (this.baseline ?? Promise.resolve({ kind: 'none' }));
259
+ if (baseline.kind !== 'git')
260
+ return [];
261
+ let changed;
262
+ try {
263
+ changed = (await git(this.workspace, ['diff', '--name-only', '-z', '--no-renames', '--relative', baseline.head, '--', '.'], signal)).split('\0').filter(Boolean);
264
+ }
265
+ catch {
266
+ return [];
267
+ }
268
+ if (changed.some(name => !isTestPath(name)))
269
+ return [];
270
+ // The comparison above covers tracked files only. A file Git does not track may still hold the
271
+ // run's change, so one among the edited files leaves the question open and nothing is reported.
272
+ const edited = [...this.sourceEdits];
273
+ if (edited.length > 200)
274
+ return [];
275
+ // "Identical to the commit" means "restored" only for a file that matched the commit when the run
276
+ // started. One that already differed may have been fixed by returning it to the commit, and one
277
+ // changed before the starting state was recorded has an unknown start.
278
+ if (!baseline.dirtyNames || this.racedUnknown || edited.some(name => baseline.dirtyNames.has(name) || this.racedPaths.has(name)))
279
+ return [];
280
+ let tracked;
281
+ try {
282
+ tracked = new Set((await git(this.workspace, ['ls-files', '-z', '--', ...edited], signal)).split('\0').filter(Boolean));
283
+ }
284
+ catch {
285
+ return [];
286
+ }
287
+ if (edited.some(name => !tracked.has(name)))
288
+ return [];
289
+ // Work delivered in a new file the run wrote, which Git does not list until it is added. An edit
290
+ // that replaces a file gives it a new creation time, so a file first seen as existing is not new.
291
+ for (const name of this.created) {
292
+ if (!isTestPath(name) && !this.sourceEdits.has(name) && await contentHash(path.join(this.workspace, name)) !== null)
293
+ return [];
294
+ }
295
+ this.undoneAsked = true;
296
+ return edited.sort((a, b) => a.localeCompare(b));
297
+ }
298
+ /**
299
+ * The modified test files whose change only adds new tests: no line of the starting commit's file was
300
+ * removed or replaced, and nothing added switches a test off or defines again a name the file already
301
+ * had. Appending a regression test to an existing test file is ordinary work, not a rewrite of the
302
+ * tests that constrain the fix. Any doubt (a Git failure, a file that is not test code) keeps the file flagged.
303
+ */
304
+ async onlyAddsTests(baseline, names, signal) {
305
+ const candidates = names.filter(name => ADDITIVE_TEST_CODE.test(name) && !FIXTURE_LOCATION.test(name)
306
+ && !baseline.dirty.has(name) && !baseline.unknown.has(name)).slice(0, ADDITIVE_FILE_LIMIT);
307
+ if (!candidates.length)
308
+ return [];
309
+ const additive = [];
310
+ try {
311
+ const counts = (await git(this.workspace, ['diff', '--numstat', '-z', '--no-renames', '--relative', baseline.head, '--', ...candidates], signal)).split('\0');
312
+ for (const entry of counts) {
313
+ const match = /^(\d+)\t0\t(.+)$/s.exec(entry);
314
+ if (!match || match[1] === '0' || !candidates.includes(match[2]))
315
+ continue;
316
+ const name = match[2];
317
+ const patch = await git(this.workspace, ['diff', '-U0', '--no-color', '--no-ext-diff', '--no-renames', '--relative', baseline.head, '--', name], signal);
318
+ const added = patch.split(/\r?\n/).filter(line => line.startsWith('+') && !line.startsWith('+++')).map(line => line.slice(1));
319
+ if (!added.length || added.some(line => DISABLES_TESTS.test(line)))
320
+ continue;
321
+ const declared = added.map(line => DECLARATION.exec(line)?.[1]).filter((item) => !!item);
322
+ if (declared.length) {
323
+ const before = await git(this.workspace, ['show', `${baseline.head}:${baseline.prefix}${name}`], signal);
324
+ const existing = new Set([...before.matchAll(new RegExp(DECLARATION.source, 'gm'))].map(found => found[1]));
325
+ if (declared.some(item => existing.has(item)) || new Set(declared).size !== declared.length)
326
+ continue;
327
+ }
328
+ additive.push(name);
329
+ }
330
+ }
331
+ catch {
332
+ return additive;
333
+ }
334
+ return additive;
207
335
  }
208
336
  async current(signal) {
209
337
  const baseline = await (this.baseline ?? Promise.resolve({ kind: 'none' }));
@@ -216,6 +344,8 @@ export class TestEditGuard {
216
344
  continue;
217
345
  edits.set(name, status.startsWith('D') ? 'deleted' : 'modified');
218
346
  }
347
+ for (const name of await this.onlyAddsTests(baseline, [...edits].filter(([, state]) => state === 'modified').map(([name]) => name), signal))
348
+ edits.delete(name);
219
349
  for (const [name, before] of baseline.dirty) {
220
350
  const now = await contentHash(path.join(baseline.root, baseline.prefix, name));
221
351
  if (now === before)
@@ -243,6 +373,89 @@ export class TestEditGuard {
243
373
  : unknown?.has(name) ? { path: name, state, startUnknown: true } : { path: name, state })
244
374
  .sort((a, b) => a.path.localeCompare(b.path));
245
375
  }
376
+ /**
377
+ * True, once, when the run finishes with the workspace's tracked code identical to the commit it
378
+ * started from, no edited file outside Git's view and no surviving new source file written through
379
+ * the file tools: nothing a task that calls for a change could have delivered. False without Git,
380
+ * on a Git failure, when the workspace's code already differed from the commit at the start, and
381
+ * after undone() or this has already raised the matter, so the agent is asked about it a single time.
382
+ * With testsCount, a change to a test file is work too: a request to write tests is delivered by them,
383
+ * while a defect is not fixed by a test alone.
384
+ */
385
+ async unchanged(signal, testsCount = false) {
386
+ const counts = (name) => testsCount || !isTestPath(name);
387
+ if (this.undoneAsked)
388
+ return false;
389
+ const baseline = await (this.baseline ?? Promise.resolve({ kind: 'none' }));
390
+ if (baseline.kind !== 'git')
391
+ return false;
392
+ // "Identical to the commit" means "nothing was delivered" only when the workspace's code matched
393
+ // the commit at the start: with source already changed then, returning it to the commit may be
394
+ // the fix. The same doubt holds when a tool changed files before the starting state was recorded.
395
+ if (!baseline.dirtyNames || this.racedUnknown || this.racedPaths.size
396
+ || [...baseline.dirtyNames].some(counts))
397
+ return false;
398
+ let changed;
399
+ try {
400
+ changed = (await git(this.workspace, ['diff', '--name-only', '--no-renames', '--relative', baseline.head, '--', '.'], signal)).split(/\r?\n/).filter(Boolean);
401
+ }
402
+ catch {
403
+ return false;
404
+ }
405
+ if (changed.some(counts))
406
+ return false;
407
+ // Git's comparison covers tracked files. Work may sit in an edited file Git does not track, or in a
408
+ // new file the run wrote that still exists.
409
+ const edited = [...this.sourceEdits];
410
+ if (edited.length > 200)
411
+ return false;
412
+ if (edited.length) {
413
+ let tracked;
414
+ try {
415
+ tracked = new Set((await git(this.workspace, ['ls-files', '--', ...edited], signal)).split(/\r?\n/).filter(Boolean));
416
+ }
417
+ catch {
418
+ return false;
419
+ }
420
+ if (edited.some(name => !tracked.has(name)))
421
+ return false;
422
+ }
423
+ for (const name of this.created) {
424
+ if (counts(name) && !this.sourceEdits.has(name) && await contentHash(path.join(this.workspace, name)) !== null)
425
+ return false;
426
+ }
427
+ // A shell command or subagent can write a new file without reporting it. Git lists such files as
428
+ // untracked; one written since the run started is the run's work, an older one was already there.
429
+ // An untracked directory may hold either, and too long a list is not examined: both abstain.
430
+ if (this.opaque) {
431
+ let untracked;
432
+ try {
433
+ untracked = statusPaths(await git(this.workspace, ['status', '--porcelain=v1', '-z', '--untracked-files=normal', '--', '.'], signal)
434
+ .then(output => output.split('\0').filter(entry => entry.startsWith('?? ')).join('\0')));
435
+ }
436
+ catch {
437
+ return false;
438
+ }
439
+ if (untracked.length > UNTRACKED_LIMIT)
440
+ return false;
441
+ for (const listed of untracked) {
442
+ const name = listed.startsWith(baseline.prefix) ? listed.slice(baseline.prefix.length) : listed;
443
+ if (!counts(name.replace(/\/$/, '')))
444
+ continue;
445
+ if (name.endsWith('/'))
446
+ return false;
447
+ try {
448
+ if ((await stat(path.join(this.workspace, name))).mtimeMs >= this.startedAt)
449
+ return false;
450
+ }
451
+ catch {
452
+ return false;
453
+ }
454
+ }
455
+ }
456
+ this.undoneAsked = true;
457
+ return true;
458
+ }
246
459
  /**
247
460
  * Returns the changed pre-existing test files when at least one of them has not been reported yet,
248
461
  * and marks them reported; returns nothing otherwise, so each set of files is raised once.
@@ -0,0 +1,11 @@
1
+ import { type ProviderConfig, type ReasoningEffort } from './providers.js';
2
+ import type { ModelAdapter } from './types.js';
3
+ /** The smallest output allowance at which an Anthropic request still thinks: a 1024-token budget plus 1024 to answer. */
4
+ export declare const ANTHROPIC_PROBE_MAX_TOKENS = 2048;
5
+ /** One minimal request at a level, answered with the HTTP status the provider gave it. Throws when there was none. */
6
+ export declare function probeLevel(adapter: ModelAdapter, model: string, signal: AbortSignal, maxTokens?: number): Promise<number>;
7
+ /**
8
+ * The thinking levels a provider's model accepts: from the built-in catalog for a catalogued Anthropic model, else by
9
+ * asking the provider once per level. Undefined when the provider type takes no level or the answer was inconclusive.
10
+ */
11
+ export declare function detectProviderLevels(provider: ProviderConfig, model: string, signal: AbortSignal, adapterFor?: (snapshot: ProviderConfig) => ModelAdapter): Promise<ReasoningEffort[] | undefined>;
@@ -0,0 +1,47 @@
1
+ import { anthropicCatalogLevels } from './provider-engine.js';
2
+ import { createAdapter, ProviderRequestError, supportsReasoningEffort } from './providers.js';
3
+ import { detectLevels } from './thinking-levels.js';
4
+ /** The smallest output allowance at which an Anthropic request still thinks: a 1024-token budget plus 1024 to answer. */
5
+ export const ANTHROPIC_PROBE_MAX_TOKENS = 2048;
6
+ /** One minimal request at a level, answered with the HTTP status the provider gave it. Throws when there was none. */
7
+ export async function probeLevel(adapter, model, signal, maxTokens = 16) {
8
+ // A retryable failure (rate limit, server error, timeout) says nothing about the level, and waiting through the
9
+ // adapter's retries would stall the probe: the first retry ends it.
10
+ const controller = new AbortController();
11
+ const bounded = AbortSignal.any([signal, controller.signal]);
12
+ let retried = false;
13
+ try {
14
+ await adapter.generate({ model, messages: [{ role: 'user', content: 'Reply with OK.' }], tools: [], signal: bounded, maxTokens,
15
+ onRetry: () => { retried = true; controller.abort(); } });
16
+ return 200;
17
+ }
18
+ catch (error) {
19
+ signal.throwIfAborted();
20
+ if (retried)
21
+ return 503;
22
+ if (!(error instanceof ProviderRequestError))
23
+ throw error;
24
+ // A refusal the adapter does not retry carries its status; one it would retry carries it in its telemetry code.
25
+ const direct = error.status;
26
+ const status = typeof direct === 'number' ? direct : Number(/^http_(\d{3})$/.exec(error.telemetryCode ?? '')?.[1]);
27
+ if (!Number.isInteger(status))
28
+ throw error;
29
+ return status;
30
+ }
31
+ }
32
+ /**
33
+ * The thinking levels a provider's model accepts: from the built-in catalog for a catalogued Anthropic model, else by
34
+ * asking the provider once per level. Undefined when the provider type takes no level or the answer was inconclusive.
35
+ */
36
+ export async function detectProviderLevels(provider, model, signal, adapterFor = snapshot => createAdapter(snapshot)) {
37
+ if (!supportsReasoningEffort(provider.type) || provider.type === 'relayed')
38
+ return undefined;
39
+ const catalog = provider.type === 'anthropic' ? anthropicCatalogLevels(model) : undefined;
40
+ return detectLevels((effort, probeSignal) => {
41
+ const snapshot = { ...provider, model, reasoningEffort: effort };
42
+ delete snapshot.thinkingLevels;
43
+ // An Anthropic request with a small output allowance has thinking turned off whatever level was asked for (the
44
+ // budget must leave 1024 tokens), so the probe would test nothing: give it room for the smallest budget.
45
+ return probeLevel(adapterFor(snapshot), model, probeSignal, provider.type === 'anthropic' ? ANTHROPIC_PROBE_MAX_TOKENS : 16);
46
+ }, signal, catalog);
47
+ }