@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
@@ -2,6 +2,7 @@ import { normalizeAnswers } from './HttpDecisionProvider.js';
2
2
  import { validateBatch } from '../DecisionPolicy.js';
3
3
  import { clipFactText, factProbability, FACT_LIMITS } from '../facts.js';
4
4
  import { parseToolRouteEvidence } from '../routeTools.js';
5
+ import { parseTaskKindEvidence } from '../taskKind.js';
5
6
  import { abstainSkill, chunkSkills, expandSkillAnswer, HOSTED_SKILLS_PER_REQUEST, LEGACY_HOSTED_SKILLS_PER_REQUEST, mergeNoSkill } from '../hostedSkills.js';
6
7
  const HOSTED_REQUEST_BYTES = 32_768;
7
8
  const CLIP_MARKER = '\n…[Jev routing context clipped]…\n';
@@ -254,6 +255,17 @@ export class AndorraDecisionProvider {
254
255
  throw new Error('invalid_response');
255
256
  return evidence;
256
257
  }
258
+ async evaluateTaskKind(request, signal, observe) {
259
+ signal?.throwIfAborted();
260
+ const body = JSON.stringify({ taskKind: request });
261
+ if (Buffer.byteLength(body, 'utf8') > HOSTED_REQUEST_BYTES)
262
+ throw new Error('decision_input_too_large');
263
+ const response = await this.post(body, signal, observe);
264
+ const evidence = parseTaskKindEvidence(response.taskKind);
265
+ if (!evidence)
266
+ throw new Error('invalid_response');
267
+ return evidence;
268
+ }
257
269
  async post(body, signal, observe) {
258
270
  const auth = this.dependencies ?? await (async () => {
259
271
  const { getAccessToken, getAuthConfiguration } = await import('../../auth/index.js');
@@ -8,7 +8,6 @@ export const JEV_REQUEST_PHRASES = [
8
8
  'Haggling with the token meter',
9
9
  'Teaching the prompt to travel light',
10
10
  'Bargain-hunting for bytes',
11
- 'Squeezing the context like a toothpaste tube',
12
11
  "Shrinking the bill before it's printed",
13
12
  'Leaving the extra tokens at home',
14
13
  'Sending unnecessary tokens home',
@@ -0,0 +1,52 @@
1
+ /**
2
+ * What the first message of a run asks the agent to deliver, as judged by the hosted classifier.
3
+ * The classifier's wording lives on the server; the client sends only the task text and receives
4
+ * a probability for each kind. The verdict is advice to the model and a fact for the finish check.
5
+ * It grants no permission and changes no tool.
6
+ */
7
+ export declare const TASK_KIND_VERSION: 1;
8
+ export declare const TASK_KIND_MODEL = "jev-1.13.0";
9
+ export declare const TASK_KIND_UNCLEAR = "needs_clarification";
10
+ export declare const TASK_KINDS: readonly ["fix_defect", "make_change", "answer_question", "investigate", "run_or_verify", "general"];
11
+ export type TaskKind = typeof TASK_KINDS[number];
12
+ export declare const TASK_KIND_CHOICES: readonly string[];
13
+ /** Below this a verdict is not used, and the finish check never relies on a weaker one. */
14
+ export declare const TASK_KIND_CONFIDENCE_FLOOR = 0.9;
15
+ /**
16
+ * A one-line bug report ("why is the button doing nothing?") is read as a defect with less
17
+ * confidence than a full issue, and the note for it only restates what the default instruction
18
+ * already asks. So the note is added from this lower floor, while the notes that tell the model
19
+ * not to edit, and the finish check, keep the stricter one.
20
+ */
21
+ export declare const TASK_KIND_DEFECT_NOTE_FLOOR = 0.7;
22
+ export declare const TASK_KIND_TASK_CHARS = 3000;
23
+ export interface TaskKindRequest {
24
+ version: typeof TASK_KIND_VERSION;
25
+ model: typeof TASK_KIND_MODEL;
26
+ task: string;
27
+ }
28
+ export interface TaskKindEvidence {
29
+ version: typeof TASK_KIND_VERSION;
30
+ model: typeof TASK_KIND_MODEL;
31
+ choice: string;
32
+ confidence: number;
33
+ probabilities: Record<string, number>;
34
+ }
35
+ export interface TaskKindVerdict {
36
+ kind: TaskKind;
37
+ confidence: number;
38
+ /** The task is not delivered while the workspace's code is unchanged. */
39
+ expectsChange: boolean;
40
+ }
41
+ export type TaskKindReason = 'selected' | 'invalid_or_unavailable_evidence' | 'needs_clarification' | 'low_confidence';
42
+ export declare function makeTaskKindRequest(task: string): TaskKindRequest;
43
+ export declare function parseTaskKindEvidence(value: unknown): TaskKindEvidence | undefined;
44
+ export declare function decideTaskKind(raw: unknown): {
45
+ verdict?: TaskKindVerdict;
46
+ reason: TaskKindReason;
47
+ evidence?: TaskKindEvidence;
48
+ };
49
+ /** The sentence appended to the run's first message for a kind, when one helps. */
50
+ export declare function taskKindNote(kind: TaskKind): string | undefined;
51
+ /** The reminder for a run whose task calls for a code change and that finishes with the code unchanged. */
52
+ export declare function unchangedWorkNudge(kind: TaskKind): string;
@@ -0,0 +1,76 @@
1
+ /**
2
+ * What the first message of a run asks the agent to deliver, as judged by the hosted classifier.
3
+ * The classifier's wording lives on the server; the client sends only the task text and receives
4
+ * a probability for each kind. The verdict is advice to the model and a fact for the finish check.
5
+ * It grants no permission and changes no tool.
6
+ */
7
+ export const TASK_KIND_VERSION = 1;
8
+ export const TASK_KIND_MODEL = 'jev-1.13.0';
9
+ export const TASK_KIND_UNCLEAR = 'needs_clarification';
10
+ export const TASK_KINDS = ['fix_defect', 'make_change', 'answer_question', 'investigate', 'run_or_verify', 'general'];
11
+ export const TASK_KIND_CHOICES = [...TASK_KINDS, TASK_KIND_UNCLEAR];
12
+ /** Below this a verdict is not used, and the finish check never relies on a weaker one. */
13
+ export const TASK_KIND_CONFIDENCE_FLOOR = 0.9;
14
+ /**
15
+ * A one-line bug report ("why is the button doing nothing?") is read as a defect with less
16
+ * confidence than a full issue, and the note for it only restates what the default instruction
17
+ * already asks. So the note is added from this lower floor, while the notes that tell the model
18
+ * not to edit, and the finish check, keep the stricter one.
19
+ */
20
+ export const TASK_KIND_DEFECT_NOTE_FLOOR = 0.7;
21
+ export const TASK_KIND_TASK_CHARS = 3_000;
22
+ const own = (value) => !!value && typeof value === 'object' && !Array.isArray(value);
23
+ const unit = (value) => typeof value === 'number' && Number.isFinite(value) && value >= 0 && value <= 1;
24
+ export function makeTaskKindRequest(task) {
25
+ if (typeof task !== 'string' || !task.trim() || task.length > TASK_KIND_TASK_CHARS)
26
+ throw new Error('Invalid task-kind task');
27
+ return { version: TASK_KIND_VERSION, model: TASK_KIND_MODEL, task };
28
+ }
29
+ export function parseTaskKindEvidence(value) {
30
+ if (!own(value) || value.version !== TASK_KIND_VERSION || value.model !== TASK_KIND_MODEL
31
+ || typeof value.choice !== 'string' || !TASK_KIND_CHOICES.includes(value.choice) || !unit(value.confidence)
32
+ || !own(value.probabilities))
33
+ return undefined;
34
+ const scores = value.probabilities;
35
+ if (Object.keys(scores).length !== TASK_KIND_CHOICES.length
36
+ || TASK_KIND_CHOICES.some(id => !Object.hasOwn(scores, id) || !unit(scores[id])))
37
+ return undefined;
38
+ const probabilities = Object.fromEntries(TASK_KIND_CHOICES.map(id => [id, scores[id]]));
39
+ if (Math.abs(Object.values(probabilities).reduce((sum, p) => sum + p, 0) - 1) > 1e-6
40
+ || probabilities[value.choice] !== Math.max(...Object.values(probabilities)))
41
+ return undefined;
42
+ return { version: TASK_KIND_VERSION, model: TASK_KIND_MODEL, choice: value.choice, confidence: value.confidence, probabilities };
43
+ }
44
+ export function decideTaskKind(raw) {
45
+ const evidence = parseTaskKindEvidence(raw);
46
+ if (!evidence)
47
+ return { reason: 'invalid_or_unavailable_evidence' };
48
+ if (evidence.choice === TASK_KIND_UNCLEAR)
49
+ return { reason: 'needs_clarification', evidence };
50
+ const kind = evidence.choice;
51
+ if (evidence.confidence < (kind === 'fix_defect' ? TASK_KIND_DEFECT_NOTE_FLOOR : TASK_KIND_CONFIDENCE_FLOOR))
52
+ return { reason: 'low_confidence', evidence };
53
+ return { reason: 'selected', evidence, verdict: { kind, confidence: evidence.confidence,
54
+ expectsChange: (kind === 'fix_defect' || kind === 'make_change') && evidence.confidence >= TASK_KIND_CONFIDENCE_FLOOR } };
55
+ }
56
+ const NOTES = {
57
+ fix_defect: 'This task reports a defect in the code in this workspace. The expected result is the fix, made here and left in place, with any question in the task answered in the report. If the reported behavior turns out to be intended or cannot be reproduced, say so with the evidence instead of changing the code.',
58
+ // A requested change needs no reminder: the task already says what to change.
59
+ make_change: undefined,
60
+ answer_question: 'This task asks for an answer about the code, not a change to it. Read what is needed and answer; leave the workspace as it is unless the answer cannot be established without a temporary change, which is then removed.',
61
+ investigate: 'This task asks for findings, not a change. Temporary instrumentation is fine and is removed before finishing; report what was found and how it was confirmed.',
62
+ run_or_verify: 'This task asks for something to be run and its result reported. Report the commands and their actual output; change code only if the task also asks for failures to be fixed.',
63
+ general: undefined,
64
+ };
65
+ /** The sentence appended to the run's first message for a kind, when one helps. */
66
+ export function taskKindNote(kind) {
67
+ const note = NOTES[kind];
68
+ return note ? `Task type (a classifier's reading of the request above, not an instruction from the user; the request itself wins where they differ): ${note}` : undefined;
69
+ }
70
+ /** The reminder for a run whose task calls for a code change and that finishes with the code unchanged. */
71
+ export function unchangedWorkNudge(kind) {
72
+ const what = kind === 'fix_defect' ? 'reports a defect in the code in this workspace' : 'asks for a change to this workspace';
73
+ return `Completion not accepted yet. The task ${what}, and the workspace holds no change to its code. `
74
+ + 'If the work was done and then removed, or was only described, make the change in the workspace and leave it in place; an explanation or a workaround does not deliver it. '
75
+ + 'If no change is the right outcome (the behavior is intended, it cannot be reproduced, or the task needs only an answer), say why in the summary and call complete_agent again to finish; this reminder is not repeated.';
76
+ }
@@ -5,7 +5,7 @@ export interface DecisionConfig {
5
5
  model?: string;
6
6
  apiKeyEnv?: string;
7
7
  requestTimeoutMs?: number;
8
- features?: Partial<Record<'toolRouting' | 'codeGraphRouting' | 'memoryRouting' | 'webRouting' | 'delegationRouting' | 'verificationRouting' | 'riskClassification' | 'resultRouting', boolean>>;
8
+ features?: Partial<Record<'toolRouting' | 'taskRouting' | 'codeGraphRouting' | 'memoryRouting' | 'webRouting' | 'delegationRouting' | 'verificationRouting' | 'riskClassification' | 'resultRouting', boolean>>;
9
9
  style?: 'facts' | 'questions';
10
10
  }
11
11
  export declare const DECISION_DEFAULTS: {
@@ -2,7 +2,7 @@ export const DEFAULT_AGENT_GRAPH = {
2
2
  name: 'Andorra Agent', entry: 'engineer',
3
3
  nodes: {
4
4
  engineer: { id: 'engineer', name: 'Andorra Agent', type: 'agent', executor: 'react-basic',
5
- instruction: 'Handle the user\'s task end to end, whether it is a coding task or a general one: implement code and verify changes with appropriate tools, and answer general research, writing and analysis directly from the available sources. Ask for clarification when needed. Report the result and any remaining issues. For follow-up questions, use the retained conversation and prior results first. Answer directly when they contain the answer; do not restart completed work or scan unrelated files. If no pull request was created or its number is unknown, say so rather than guessing. Start new implementation work only when the user requests it.',
5
+ instruction: 'Handle the user\'s task end to end, whether it is a coding task or a general one: implement code and verify changes with appropriate tools, and answer general research, writing and analysis directly from the available sources. Ask for clarification when needed. Report the result and any remaining issues. For follow-up questions, use the retained conversation and prior results first. Answer directly when they contain the answer; do not restart completed work or scan unrelated files. Never guess a pull request number. Mention pull requests in the report only when the task asked for one or one was opened; a pull request nobody asked for is not unfinished work. Start new implementation work only when the user requests it. A task that describes a defect in the code in this workspace is such a request, even when it is phrased as a question: fix the defect there and answer the question in the report.',
6
6
  contextPolicy: { history: true }, jevEnabled: true,
7
7
  subagents: { enabled: false }, position: { x: 120, y: 120 } },
8
8
  done: { id: 'done', name: 'Done', type: 'end', position: { x: 440, y: 120 } },
@@ -23,12 +23,17 @@ export interface ToolMenuRoutingConfig {
23
23
  minSavingsChars?: number;
24
24
  pinnedTools?: string[];
25
25
  }
26
+ /** off: no call. shadow: classify and record, change nothing. on: note the first message and check the finish. Unset: on for a Paid account, off otherwise. */
27
+ export interface TaskKindRoutingConfig {
28
+ mode?: 'off' | 'shadow' | 'on';
29
+ }
26
30
  export interface EfficiencyConfig {
27
31
  deterministicContinuations?: boolean;
28
32
  jevFactInterpretation?: boolean;
29
33
  jevPreflight?: boolean;
30
34
  projectSkillDiscovery?: boolean;
31
35
  toolMenuRouting?: ToolMenuRoutingConfig;
36
+ taskKindRouting?: TaskKindRoutingConfig;
32
37
  preparedContinuations?: boolean;
33
38
  postflightOnlyWithCandidates?: boolean;
34
39
  toolResultFiltering?: boolean;
@@ -17,7 +17,7 @@ export function validateEfficiencyConfig(value) {
17
17
  if (!record(value))
18
18
  throw new Error('Invalid efficiency configuration');
19
19
  const independent = ['deterministicContinuations', 'jevFactInterpretation', 'jevPreflight', 'projectSkillDiscovery'];
20
- const allowed = [...EFFICIENCY_FEATURES, ...independent, 'toolResultFilterThresholdChars', 'adaptiveRouting', 'toolMenuRouting'];
20
+ const allowed = [...EFFICIENCY_FEATURES, ...independent, 'toolResultFilterThresholdChars', 'adaptiveRouting', 'toolMenuRouting', 'taskKindRouting'];
21
21
  for (const [key, entry] of Object.entries(value)) {
22
22
  if (!allowed.includes(key))
23
23
  throw new Error(`Unsupported efficiency configuration field: ${key}`);
@@ -27,6 +27,10 @@ export function validateEfficiencyConfig(value) {
27
27
  const threshold = value.toolResultFilterThresholdChars;
28
28
  if (threshold !== undefined && (!Number.isSafeInteger(threshold) || threshold < 1000 || threshold > 1_000_000))
29
29
  throw new Error('efficiency.toolResultFilterThresholdChars must be an integer from 1000 to 1000000');
30
+ const kind = value.taskKindRouting;
31
+ if (kind !== undefined && (!record(kind) || Object.keys(kind).some(key => key !== 'mode')
32
+ || (kind.mode !== undefined && (typeof kind.mode !== 'string' || !['off', 'shadow', 'on'].includes(kind.mode)))))
33
+ throw new Error('Invalid efficiency.taskKindRouting');
30
34
  const menu = value.toolMenuRouting;
31
35
  if (menu !== undefined) {
32
36
  if (!record(menu) || Object.keys(menu).some(key => !['mode', 'topK', 'minSavingsChars', 'pinnedTools'].includes(key)))
@@ -0,0 +1,27 @@
1
+ import type { DecisionBatch } from './decision/types.js';
2
+ import type { ReasoningEffort } from './providers.js';
3
+ export interface EffortDecisionInput {
4
+ task: string;
5
+ /** The model's enabled levels, lowest first. A level that is not here is never returned. */
6
+ levels: readonly ReasoningEffort[];
7
+ hints?: DecisionBatch;
8
+ /** The level the node would run at without Auto. */
9
+ fallback?: ReasoningEffort;
10
+ /** The level of the attempt that just failed, and why it failed. */
11
+ previous?: {
12
+ level: ReasoningEffort;
13
+ reason?: string;
14
+ };
15
+ }
16
+ export interface EffortDecision {
17
+ level?: ReasoningEffort;
18
+ evidence: 'hint' | 'lexical' | 'none' | 'escalation' | 'fixed';
19
+ }
20
+ /** A failed attempt moves up a level only when the failure suggests the model needed to think harder. */
21
+ export declare const EFFORT_ESCALATION_REASONS: ReadonlySet<string>;
22
+ /**
23
+ * The thinking level for one start of a node on Auto. Risk takes the highest enabled level, a confident complexity
24
+ * score is spread evenly across the enabled levels, and an obviously mechanical short task takes the lowest. With no
25
+ * decisive signal the node keeps the level it would have had, moved onto an enabled one.
26
+ */
27
+ export declare function decideEffort(input: EffortDecisionInput): EffortDecision;
@@ -0,0 +1,34 @@
1
+ import { DecisionPolicy } from './decision/DecisionPolicy.js';
2
+ import { MECHANICAL_MAX_CHARS, MECHANICAL_WORDS, RISK_WORDS } from './model-tiers.js';
3
+ import { nearestEnabled } from './thinking-levels.js';
4
+ /** A failed attempt moves up a level only when the failure suggests the model needed to think harder. */
5
+ export const EFFORT_ESCALATION_REASONS = new Set(['repeatedToolFailure', 'maxIterations']);
6
+ /**
7
+ * The thinking level for one start of a node on Auto. Risk takes the highest enabled level, a confident complexity
8
+ * score is spread evenly across the enabled levels, and an obviously mechanical short task takes the lowest. With no
9
+ * decisive signal the node keeps the level it would have had, moved onto an enabled one.
10
+ */
11
+ export function decideEffort(input) {
12
+ const { levels } = input;
13
+ if (levels.length === 0)
14
+ return { evidence: 'none' };
15
+ if (input.previous) {
16
+ const at = levels.indexOf(nearestEnabled(levels, input.previous.level));
17
+ const up = input.previous.reason !== undefined && EFFORT_ESCALATION_REASONS.has(input.previous.reason) && at < levels.length - 1;
18
+ return { level: levels[up ? at + 1 : at], evidence: up ? 'escalation' : 'none' };
19
+ }
20
+ if (levels.length === 1)
21
+ return { level: levels[0], evidence: 'none' };
22
+ const highest = levels[levels.length - 1];
23
+ const hints = input.hints;
24
+ if (hints && (DecisionPolicy.boolean(hints, 'security_sensitive') === true || DecisionPolicy.boolean(hints, 'architecture_affecting') === true))
25
+ return { level: highest, evidence: 'hint' };
26
+ if (RISK_WORDS.test(input.task))
27
+ return { level: highest, evidence: 'lexical' };
28
+ const complexity = hints ? DecisionPolicy.score(hints, 'task_complexity') : undefined;
29
+ if (complexity !== undefined)
30
+ return { level: levels[Math.min(levels.length - 1, Math.max(0, Math.floor(complexity * levels.length)))], evidence: 'hint' };
31
+ if (input.task.length <= MECHANICAL_MAX_CHARS && MECHANICAL_WORDS.test(input.task))
32
+ return { level: levels[0], evidence: 'lexical' };
33
+ return { level: input.fallback === undefined ? undefined : nearestEnabled(levels, input.fallback), evidence: 'none' };
34
+ }
@@ -0,0 +1,110 @@
1
+ /** What the agent lists in complete_agent's `outcomes`. */
2
+ export interface RequestedOutcome {
3
+ /** The outcome in plain language: "The SDK handles the API's final page". */
4
+ outcome: string;
5
+ status: 'passed' | 'failed' | 'not_checked';
6
+ /** The exact command that shows it, as it was run. */
7
+ command?: string;
8
+ /** The agent's own reading of the result. */
9
+ reading?: string;
10
+ /** For a not-checked outcome: why, and how a person can check it. */
11
+ why?: string;
12
+ how?: string;
13
+ }
14
+ /** The runtime's record of one command an agent ran. */
15
+ export interface CommandObservation {
16
+ id: string;
17
+ command: string;
18
+ directory: string;
19
+ startedAt: string;
20
+ endedAt?: string;
21
+ exitCode?: number;
22
+ /** The last 4 KB of what it printed. */
23
+ output?: string;
24
+ /**
25
+ * What it ran against, read just before it started: the commit, and the uncommitted files at that moment.
26
+ * `inputsUnknown`: Git could not list them (it timed out, say), so the revision is labelled as incomplete.
27
+ */
28
+ revision?: {
29
+ commit?: string;
30
+ dirty: string[];
31
+ dirtyCount: number;
32
+ inputsUnknown?: true;
33
+ };
34
+ }
35
+ export type EvidenceState = 'passed' | 'failed' | 'unchecked' | 'reported';
36
+ /** One row of a turn's evidence. Runtime facts and the agent's reading are kept apart. */
37
+ export interface EvidenceItem {
38
+ criterion: string;
39
+ state: EvidenceState;
40
+ /** The result in a few words: from the run for an observed row. */
41
+ result: string;
42
+ observation?: CommandObservation;
43
+ /** The agent's reading, labelled as such. */
44
+ agent?: string;
45
+ why?: string;
46
+ how?: string;
47
+ /** A neutral freshness note: the result stands, but what it covered may have changed. */
48
+ stale?: string;
49
+ }
50
+ export declare const MAX_OUTCOMES = 20;
51
+ /** Commands are kept, and compared, up to this length. */
52
+ export declare const COMMAND_LIMIT = 8000;
53
+ export declare const OUTPUT_TAIL_BYTES = 4096;
54
+ export declare const OUTCOMES_DESCRIPTION = "Optional. When the task asked for results that can be checked, list each requested outcome: outcome (plain language), status (passed, failed or not_checked), command (the exact command you ran that shows it, copied as you ran it), reading (your short reading of its result), and for not_checked: why, and how a person can check it. The runtime links each command to its own record of the run; an outcome with no recorded command shows as unverified.";
55
+ /** The JSON schema of `outcomes` in complete_agent. */
56
+ export declare const OUTCOMES_SCHEMA: {
57
+ readonly type: "array";
58
+ readonly maxItems: 20;
59
+ readonly description: "Optional. When the task asked for results that can be checked, list each requested outcome: outcome (plain language), status (passed, failed or not_checked), command (the exact command you ran that shows it, copied as you ran it), reading (your short reading of its result), and for not_checked: why, and how a person can check it. The runtime links each command to its own record of the run; an outcome with no recorded command shows as unverified.";
60
+ readonly items: {
61
+ readonly type: "object";
62
+ readonly properties: {
63
+ readonly outcome: {
64
+ readonly type: "string";
65
+ };
66
+ readonly status: {
67
+ readonly type: "string";
68
+ readonly enum: readonly ["passed", "failed", "not_checked"];
69
+ };
70
+ readonly command: {
71
+ readonly type: "string";
72
+ };
73
+ readonly reading: {
74
+ readonly type: "string";
75
+ };
76
+ readonly why: {
77
+ readonly type: "string";
78
+ };
79
+ readonly how: {
80
+ readonly type: "string";
81
+ };
82
+ };
83
+ readonly required: readonly ["outcome", "status"];
84
+ readonly additionalProperties: false;
85
+ };
86
+ };
87
+ /** The outcomes an agent sent, kept leniently: a malformed entry is dropped with a note, never a failed completion. */
88
+ export declare function parseOutcomes(value: unknown, notes?: string[]): RequestedOutcome[] | undefined;
89
+ /**
90
+ * Each outcome against what ran: the newest recorded run of its exact command decides passed or failed by its exit
91
+ * code, whatever the agent claimed; an outcome whose command never ran is agent-reported; a not-checked one says why.
92
+ * `edits` are the times files were edited by the agent; a run followed by an edit, or by a run that saw other files,
93
+ * keeps its result with "Edited since".
94
+ */
95
+ export declare function resolveEvidence(outcomes: readonly RequestedOutcome[], observations: readonly CommandObservation[], edits?: readonly string[], finalRevisions?: ReadonlyMap<string, CommandObservation['revision']>): EvidenceItem[];
96
+ /**
97
+ * What the ledger names about a turn (E7): each outcome it did not verify, said as it stands — not checked, only
98
+ * agent-reported, failed, or passed before later edits.
99
+ */
100
+ export declare function unverified(items: readonly EvidenceItem[] | undefined): string[];
101
+ /**
102
+ * The commit and uncommitted files of `directory`'s repository right now; undefined outside Git. Git runs as the
103
+ * app's other reads of a workspace do: found outside the workspace, with fsmonitor, hooks and the repository's
104
+ * filter drivers off, so reading the revision never runs anything the workspace configured.
105
+ */
106
+ export declare function readRevision(directory: string, signal?: AbortSignal): Promise<CommandObservation['revision']>;
107
+ /** A command or its output as kept: terminal escapes stripped and known secret shapes redacted. */
108
+ export declare function cleanRecorded(text: string): string;
109
+ /** The last 4 KB of a command's output, cut at a line where it can be. */
110
+ export declare function outputTail(output: string): string;
@@ -0,0 +1,195 @@
1
+ import { execFile } from 'node:child_process';
2
+ import { stripVTControlCharacters } from 'node:util';
3
+ import { excludedRoots, trustedGitEnv, trustedGitPath } from './git-summary.js';
4
+ import { redactSecrets } from './secret-redaction.js';
5
+ export const MAX_OUTCOMES = 20;
6
+ /** Commands are kept, and compared, up to this length. */
7
+ export const COMMAND_LIMIT = 8000;
8
+ export const OUTPUT_TAIL_BYTES = 4096;
9
+ const TEXT_LIMIT = 600;
10
+ const DIRTY_LISTED = 20;
11
+ export const OUTCOMES_DESCRIPTION = 'Optional. When the task asked for results that can be checked, list each requested outcome: outcome (plain language), status (passed, failed or not_checked), command (the exact command you ran that shows it, copied as you ran it), reading (your short reading of its result), and for not_checked: why, and how a person can check it. The runtime links each command to its own record of the run; an outcome with no recorded command shows as unverified.';
12
+ /** The JSON schema of `outcomes` in complete_agent. */
13
+ export const OUTCOMES_SCHEMA = {
14
+ type: 'array', maxItems: MAX_OUTCOMES, description: OUTCOMES_DESCRIPTION,
15
+ items: {
16
+ type: 'object',
17
+ properties: {
18
+ outcome: { type: 'string' }, status: { type: 'string', enum: ['passed', 'failed', 'not_checked'] },
19
+ command: { type: 'string' }, reading: { type: 'string' }, why: { type: 'string' }, how: { type: 'string' },
20
+ },
21
+ required: ['outcome', 'status'],
22
+ additionalProperties: false,
23
+ },
24
+ };
25
+ const text = (value, limit = TEXT_LIMIT) => typeof value === 'string' && value.trim() ? value.trim().slice(0, limit) : undefined;
26
+ /** The outcomes an agent sent, kept leniently: a malformed entry is dropped with a note, never a failed completion. */
27
+ export function parseOutcomes(value, notes) {
28
+ if (value === undefined)
29
+ return undefined;
30
+ // Some models send a list as JSON text.
31
+ if (typeof value === 'string') {
32
+ try {
33
+ value = JSON.parse(value);
34
+ notes?.push('outcomes arrived as JSON text and was decoded');
35
+ }
36
+ catch { /* not JSON */ }
37
+ }
38
+ if (!Array.isArray(value)) {
39
+ notes?.push('outcomes was not a list and was ignored');
40
+ return undefined;
41
+ }
42
+ const kept = [];
43
+ let dropped = 0;
44
+ for (const entry of value.slice(0, MAX_OUTCOMES)) {
45
+ const item = entry;
46
+ const outcome = text(item?.outcome, 300);
47
+ if (outcome === undefined) {
48
+ dropped++;
49
+ continue;
50
+ }
51
+ // A status the list does not know (skipped, blocked) is a gap the agent disclosed: kept as not checked.
52
+ const said = typeof item?.status === 'string' ? item.status : '';
53
+ const status = said === 'passed' || said === 'failed' || said === 'not_checked' ? said : 'not_checked';
54
+ const command = text(item?.command, COMMAND_LIMIT), reading = text(item?.reading), how = text(item?.how);
55
+ const why = text(item?.why) ?? (status !== said && said ? `Reported as ${said.slice(0, 40)}.` : undefined);
56
+ kept.push({ outcome, status, ...(command ? { command } : {}), ...(reading ? { reading } : {}), ...(why ? { why } : {}), ...(how ? { how } : {}) });
57
+ }
58
+ if (dropped)
59
+ notes?.push(`${dropped} outcome${dropped === 1 ? ' was' : 's were'} malformed and dropped`);
60
+ return kept.length ? kept : undefined;
61
+ }
62
+ /** Commands compare with their ends trimmed and runs of spaces or tabs between words collapsed; line breaks count. */
63
+ const normalized = (command) => command.slice(0, COMMAND_LIMIT).trim().replace(/[ \t]+/g, ' ').replace(/ ?\r?\n ?/g, '\n');
64
+ /** The last non-empty line of the output, as the row's result. */
65
+ function lastLine(output) {
66
+ const line = output?.split('\n').map(part => part.trim()).filter(Boolean).at(-1);
67
+ return line === undefined ? undefined : line.length > 120 ? `${line.slice(0, 119)}…` : line;
68
+ }
69
+ /**
70
+ * Each outcome against what ran: the newest recorded run of its exact command decides passed or failed by its exit
71
+ * code, whatever the agent claimed; an outcome whose command never ran is agent-reported; a not-checked one says why.
72
+ * `edits` are the times files were edited by the agent; a run followed by an edit, or by a run that saw other files,
73
+ * keeps its result with "Edited since".
74
+ */
75
+ export function resolveEvidence(outcomes, observations, edits = [], finalRevisions = new Map()) {
76
+ return outcomes.map(outcome => {
77
+ const agent = outcome.reading;
78
+ if (outcome.status === 'not_checked') {
79
+ return { criterion: outcome.outcome, state: 'unchecked', result: 'Not checked', ...(outcome.why ? { why: outcome.why } : {}), ...(outcome.how ? { how: outcome.how } : {}), ...(agent ? { agent } : {}) };
80
+ }
81
+ const wanted = outcome.command === undefined ? undefined : normalized(outcome.command);
82
+ const observed = wanted === undefined ? undefined : [...observations].reverse().find(item => normalized(item.command) === wanted && item.endedAt !== undefined);
83
+ if (observed === undefined) {
84
+ return {
85
+ criterion: outcome.outcome, state: 'reported',
86
+ result: outcome.command ? 'Agent-reported · the command it names was not recorded' : 'Agent-reported · no recorded run',
87
+ why: 'The agent reported this, but no run of the command it names was recorded in this turn.',
88
+ ...(agent ? { agent } : {}),
89
+ };
90
+ }
91
+ // A zero exit can hide failures (a pipe into tail, `|| true`): when the agent read a failure, it stays failed.
92
+ const passed = observed.exitCode === 0 && outcome.status !== 'failed';
93
+ const tail = lastLine(observed.output);
94
+ const after = Date.parse(observed.endedAt);
95
+ const known = (revision) => revision !== undefined && revision.inputsUnknown !== true;
96
+ const finalRevision = finalRevisions.get(observed.directory);
97
+ const editedLater = edits.some(at => Date.parse(at) > after)
98
+ // A later command in the same folder that saw other files means the shell changed them.
99
+ || observations.some(item => item.directory === observed.directory && Date.parse(item.startedAt) > after && known(item.revision) && known(observed.revision) && revisionKey(item) !== revisionKey(observed))
100
+ // So does the folder as the turn left it.
101
+ || (known(finalRevision) && known(observed.revision) && revisionKey({ ...observed, revision: finalRevision }) !== revisionKey(observed));
102
+ return {
103
+ criterion: outcome.outcome,
104
+ state: passed ? 'passed' : 'failed',
105
+ result: [tail, observed.exitCode === undefined ? 'did not finish' : `exit ${observed.exitCode}`, observed.exitCode === 0 && !passed ? 'agent read failures' : undefined].filter(Boolean).join(' · '),
106
+ observation: observed,
107
+ ...(agent ? { agent } : {}),
108
+ ...(editedLater ? { stale: 'Edited since' } : {}),
109
+ };
110
+ });
111
+ }
112
+ function revisionKey(item) {
113
+ return `${item.revision?.commit ?? ''}|${(item.revision?.dirty ?? []).join(',')}|${item.revision?.dirtyCount ?? 0}`;
114
+ }
115
+ /**
116
+ * What the ledger names about a turn (E7): each outcome it did not verify, said as it stands — not checked, only
117
+ * agent-reported, failed, or passed before later edits.
118
+ */
119
+ export function unverified(items) {
120
+ const phrase = { unchecked: 'not checked', reported: 'only agent-reported', failed: 'failed' };
121
+ // The most serious first: a failure, then a gap, then a claim, then a pass that edits may have overtaken.
122
+ const rank = (item) => item.state === 'failed' ? 0 : item.state === 'unchecked' ? 1 : item.state === 'reported' ? 2 : 3;
123
+ return [...(items ?? [])].sort((a, b) => rank(a) - rank(b)).flatMap(item => {
124
+ const said = phrase[item.state] ?? (item.stale ? 'edited since its check' : undefined);
125
+ return said === undefined ? [] : [`${item.criterion.replace(/[.\s]+$/, '')} ${said}`];
126
+ });
127
+ }
128
+ const GIT_FLAGS = ['--no-pager', '--no-optional-locks', '-c', 'core.fsmonitor=false', '-c', 'core.hooksPath=', '-c', 'core.quotePath=false', '-c', 'gc.auto=0'];
129
+ const REVISION_TIMEOUT_MS = 3000;
130
+ function run(binary, args, cwd, env, signal) {
131
+ return new Promise(resolve => {
132
+ execFile(binary, args, { cwd, env, windowsHide: true, timeout: REVISION_TIMEOUT_MS, maxBuffer: 4 << 20, ...(signal ? { signal } : {}) }, (error, stdout, stderr) => resolve({ code: error === null ? 0 : typeof error.code === 'number' ? error.code : 1, stdout: String(stdout), stderr: String(stderr) }));
133
+ });
134
+ }
135
+ /**
136
+ * The commit and uncommitted files of `directory`'s repository right now; undefined outside Git. Git runs as the
137
+ * app's other reads of a workspace do: found outside the workspace, with fsmonitor, hooks and the repository's
138
+ * filter drivers off, so reading the revision never runs anything the workspace configured.
139
+ */
140
+ export async function readRevision(directory, signal) {
141
+ const env = { ...trustedGitEnv(directory), GIT_TERMINAL_PROMPT: '0' };
142
+ const binary = trustedGitPath(env, excludedRoots(directory));
143
+ if (binary === undefined)
144
+ return undefined;
145
+ const drivers = await run(binary, [...GIT_FLAGS, 'config', '--null', '--get-regexp', '^filter\\.'], directory, env, signal);
146
+ const names = [...new Set(drivers.stdout.split('\0').map(entry => /^filter\.(.+)\.[^.\n]+\n/.exec(entry)?.[1]).filter((name) => !!name))];
147
+ const neutral = names.flatMap(name => ['-c', `filter.${name}.clean=`, '-c', `filter.${name}.smudge=`, '-c', `filter.${name}.process=`, '-c', `filter.${name}.required=false`]);
148
+ const status = await run(binary, [...GIT_FLAGS, ...neutral, 'status', '--porcelain=v2', '--branch', '-z', '--untracked-files=all'], directory, env, signal);
149
+ if (status.code !== 0) {
150
+ if (/not a git repository/i.test(status.stderr))
151
+ return undefined;
152
+ const head = await run(binary, [...GIT_FLAGS, 'rev-parse', '--verify', '--quiet', 'HEAD'], directory, env, signal);
153
+ if (head.code !== 0 && /not a git repository/i.test(head.stderr))
154
+ return undefined;
155
+ return { ...(head.code === 0 && head.stdout.trim() ? { commit: head.stdout.trim() } : {}), dirty: [], dirtyCount: 0, inputsUnknown: true };
156
+ }
157
+ let commit;
158
+ const files = [];
159
+ const records = status.stdout.split('\0');
160
+ for (let index = 0; index < records.length; index++) {
161
+ const record = records[index];
162
+ if (record.startsWith('# branch.oid ')) {
163
+ const oid = record.slice('# branch.oid '.length).trim();
164
+ if (/^[0-9a-f]{7,64}$/.test(oid))
165
+ commit = oid;
166
+ continue;
167
+ }
168
+ if (record.startsWith('#') || !record)
169
+ continue;
170
+ const fields = record.split(' ');
171
+ if (record[0] === '1')
172
+ files.push(fields.slice(8).join(' '));
173
+ else if (record[0] === '2') {
174
+ files.push(fields.slice(9).join(' '));
175
+ index++;
176
+ }
177
+ else if (record[0] === 'u')
178
+ files.push(fields.slice(10).join(' '));
179
+ else if (record[0] === '?')
180
+ files.push(record.slice(2));
181
+ }
182
+ return { ...(commit ? { commit } : {}), dirty: files.slice(0, DIRTY_LISTED), dirtyCount: files.length };
183
+ }
184
+ /** A command or its output as kept: terminal escapes stripped and known secret shapes redacted. */
185
+ export function cleanRecorded(text) {
186
+ return redactSecrets(stripVTControlCharacters(text));
187
+ }
188
+ /** The last 4 KB of a command's output, cut at a line where it can be. */
189
+ export function outputTail(output) {
190
+ if (output.length <= OUTPUT_TAIL_BYTES)
191
+ return output;
192
+ const tail = output.slice(-OUTPUT_TAIL_BYTES);
193
+ const at = tail.indexOf('\n');
194
+ return at >= 0 && at < 200 ? tail.slice(at + 1) : tail;
195
+ }
@@ -5,6 +5,8 @@ export interface FileDiffLine {
5
5
  newLine?: number;
6
6
  noNewline?: true;
7
7
  clipped?: true;
8
+ /** Set on a file the person also edited (`change-authors.ts`): who added or removed the line. */
9
+ author?: 'agent' | 'user';
8
10
  }
9
11
  export interface FileDiffHunk {
10
12
  oldStart: number;
@@ -19,6 +21,8 @@ export interface FileDiff {
19
21
  linesRemoved: number;
20
22
  hiddenLines: number;
21
23
  coarse?: true;
24
+ /** The line matcher gave up (too many edits, or too slow), so the middle is shown as all removed, then all added. */
25
+ approximate?: true;
22
26
  }
23
27
  export type DiffSide = Buffer | string | null;
24
28
  export type FileDiffResult = {
@@ -74,6 +74,7 @@ export function textDiff(oldText, newText, options = {}) {
74
74
  let changes = midA.length && midB.length
75
75
  ? diffArrays(midA, midB, { timeout: MATCH_TIMEOUT_MS, maxEditLength: MATCH_EDIT_LIMIT })
76
76
  : undefined;
77
+ const approximate = changes === undefined && midA.length > 0 && midB.length > 0;
77
78
  changes ??= [
78
79
  ...(midA.length ? [{ value: midA, added: false, removed: true }] : []),
79
80
  ...(midB.length ? [{ value: midB, added: true, removed: false }] : []),
@@ -179,7 +180,7 @@ export function textDiff(oldText, newText, options = {}) {
179
180
  if (lines.length)
180
181
  hunks.push({ oldStart, oldLines, newStart, newLines, lines });
181
182
  }
182
- return { hunks, linesAdded, linesRemoved, hiddenLines: hidden };
183
+ return { hunks, linesAdded, linesRemoved, hiddenLines: hidden, ...(approximate ? { approximate: true } : {}) };
183
184
  }
184
185
  export function coarseCounts(oldText, newText) {
185
186
  if (oldText === newText)