@cat-factory/executor-harness 1.132.3 → 1.135.0

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 (67) hide show
  1. package/README.md +49 -0
  2. package/dist/agent-capabilities.d.ts +21 -24
  3. package/dist/agent-capabilities.js +22 -50
  4. package/dist/agent-env.d.ts +17 -0
  5. package/dist/agent-env.js +47 -0
  6. package/dist/agent-runner.d.ts +18 -2
  7. package/dist/agent-runner.js +29 -231
  8. package/dist/agent-shared.d.ts +14 -5
  9. package/dist/agent-shared.js +14 -5
  10. package/dist/agent.d.ts +0 -11
  11. package/dist/agent.js +7 -138
  12. package/dist/captured-command.d.ts +1 -1
  13. package/dist/captured-command.js +3 -2
  14. package/dist/claude-cli.d.ts +90 -0
  15. package/dist/claude-cli.js +181 -0
  16. package/dist/claude-home.d.ts +41 -0
  17. package/dist/claude-home.js +159 -0
  18. package/dist/coding-agent.d.ts +35 -0
  19. package/dist/coding-agent.js +213 -41
  20. package/dist/docker-status.d.ts +89 -0
  21. package/dist/docker-status.js +147 -0
  22. package/dist/frontend-infra.js +4 -3
  23. package/dist/git.d.ts +48 -5
  24. package/dist/git.js +93 -26
  25. package/dist/guard-driver.d.ts +71 -0
  26. package/dist/guard-driver.js +171 -0
  27. package/dist/harness-server.js +13 -0
  28. package/dist/infra-standup.d.ts +69 -0
  29. package/dist/infra-standup.js +182 -0
  30. package/dist/job.d.ts +10 -0
  31. package/dist/multi-repo-coding.d.ts +17 -0
  32. package/dist/multi-repo-coding.js +61 -16
  33. package/dist/pi-workspace.d.ts +11 -0
  34. package/dist/pi-workspace.js +126 -57
  35. package/dist/pi.d.ts +8 -0
  36. package/dist/pi.js +16 -9
  37. package/dist/progress-guard.d.ts +56 -10
  38. package/dist/progress-guard.js +84 -22
  39. package/dist/runner.d.ts +1 -1
  40. package/dist/salvage.d.ts +180 -0
  41. package/dist/salvage.js +289 -0
  42. package/dist/workspace-probe.d.ts +85 -0
  43. package/dist/workspace-probe.js +124 -0
  44. package/package.json +4 -4
  45. package/src/agent-capabilities.ts +25 -51
  46. package/src/agent-env.ts +49 -0
  47. package/src/agent-runner.ts +40 -267
  48. package/src/agent-shared.ts +16 -5
  49. package/src/agent.ts +7 -164
  50. package/src/captured-command.ts +3 -2
  51. package/src/claude-cli.ts +217 -0
  52. package/src/claude-home.ts +233 -0
  53. package/src/coding-agent.ts +252 -44
  54. package/src/docker-status.ts +201 -0
  55. package/src/frontend-infra.ts +4 -3
  56. package/src/git.ts +104 -26
  57. package/src/guard-driver.ts +203 -0
  58. package/src/harness-server.ts +13 -0
  59. package/src/infra-standup.ts +218 -0
  60. package/src/job.ts +10 -0
  61. package/src/multi-repo-coding.ts +65 -16
  62. package/src/pi-workspace.ts +161 -57
  63. package/src/pi.ts +27 -12
  64. package/src/progress-guard.ts +110 -34
  65. package/src/runner.ts +1 -1
  66. package/src/salvage.ts +407 -0
  67. package/src/workspace-probe.ts +155 -0
package/dist/pi.js CHANGED
@@ -3,11 +3,13 @@ import { appendFile, mkdir, readFile, writeFile } from 'node:fs/promises';
3
3
  import { homedir } from 'node:os';
4
4
  import { dirname, join } from 'node:path';
5
5
  import { killChildProcess, spawnDetached } from './process.js';
6
+ import { agentChildEnv } from './agent-env.js';
6
7
  import { pathExists } from './fs-utils.js';
7
8
  import { redactSecrets, secretsToRedact } from './redact.js';
8
9
  import { HarnessFailure } from './failure.js';
9
10
  import { log } from './logger.js';
10
11
  import { ProgressGuard, progressGuardLimitsFromEnv, toolCallSignal, } from './progress-guard.js';
12
+ import { createGuardDriver } from './guard-driver.js';
11
13
  import { ToolCallTracker, readToolCallId, toolCallResult, toolCallStart, } from './tool-trajectory.js';
12
14
  import { BoundedTail, JsonlLineReader } from './jsonl-stream.js';
13
15
  import { PI_MAX_OUTPUT_TOKENS, PiRunReducer, isObject, } from './pi-reduction.js';
@@ -562,7 +564,7 @@ export function runPi(opts) {
562
564
  }
563
565
  const child = spawn('pi', ['-p', '--mode', 'json', '--model', `proxy/${opts.model}`, '--approve'], {
564
566
  cwd: opts.cwd,
565
- env: { ...process.env, ...opts.extraEnv, PI_PROXY_TOKEN: opts.sessionToken },
567
+ env: agentChildEnv(opts.extraEnv, { PI_PROXY_TOKEN: opts.sessionToken }),
566
568
  // stdin is piped (not 'ignore') so the prompt is delivered out-of-band
567
569
  // rather than on argv — see the function doc for the injection rationale.
568
570
  stdio: ['pipe', 'pipe', 'pipe'],
@@ -597,7 +599,6 @@ export function runPi(opts) {
597
599
  // spam): `{`-leading lines that failed to JSON.parse, and observer-callback throws.
598
600
  let malformedLines = 0;
599
601
  let observerErrors = 0;
600
- const guard = new ProgressGuard(opts.guardLimits ?? progressGuardLimitsFromEnv(), opts.expectsEdits ?? true);
601
602
  // Pairs each tool call's start with its result, numbers the pairs and captures the two
602
603
  // bodies (scrubbed + capped). A call whose start Pi never emitted still gets an entry,
603
604
  // timed from the previous call's end — see `ToolCallTracker`.
@@ -612,6 +613,17 @@ export function runPi(opts) {
612
613
  // SIGTERM first, then SIGKILL if Pi ignores it. Shared by the watchdog abort
613
614
  // and the no-progress guard; the `close` handler turns it into a rejection.
614
615
  const killChild = () => killChildProcess(child);
616
+ // The guard, plus the driver that settles its one bound needing evidence from outside this
617
+ // stream (see `guard-driver.ts`). `processLine` is a synchronous reader, so the driver owns
618
+ // the probe's lifetime rather than this handler awaiting inside it.
619
+ const guardDriver = createGuardDriver({
620
+ guard: new ProgressGuard(opts.guardLimits ?? progressGuardLimitsFromEnv(), opts.expectsEdits ?? true),
621
+ probe: opts.workspaceProbe,
622
+ onAbort: (reason) => {
623
+ guardReason = reason;
624
+ killChild();
625
+ },
626
+ });
615
627
  // Parse each complete JSONL record once, retaining it for the close-of-run reductions and
616
628
  // feeding the todo-progress emitter and the no-progress guard. A tripped guard kills Pi
617
629
  // with a diagnostic the run then fails on.
@@ -668,13 +680,8 @@ export function runPi(opts) {
668
680
  }
669
681
  }
670
682
  }
671
- if (!final && !guardReason && !aborted) {
672
- const reason = guard.observe(event);
673
- if (reason) {
674
- guardReason = reason;
675
- killChild();
676
- }
677
- }
683
+ if (!final && !guardReason && !aborted)
684
+ guardDriver.observeEvent(event);
678
685
  };
679
686
  // Pi's json mode is strict LF-framed JSONL; the reader buffers partial records across
680
687
  // chunks (bounded — see `JsonlLineReader`) so we only ever parse complete ones.
@@ -82,11 +82,35 @@ export declare function progressGuardLimitsFromEnv(env?: NodeJS.ProcessEnv): Pro
82
82
  */
83
83
  export declare function mergeGuardLimits(base: ProgressGuardLimits, overrides: Partial<ProgressGuardLimits> | undefined): ProgressGuardLimits;
84
84
  /**
85
- * Live anti-rabbithole guard: fed each streamed Pi event, it returns a diagnostic
86
- * reason the moment a run has plainly stopped making progress, so the harness can
87
- * kill Pi early instead of letting it burn the whole budget (and then surface a
88
- * useful failure instead of a generic "no file changes"). Pure and incremental so
89
- * it can be unit-tested over a fixed event sequence.
85
+ * What the guard concluded from one tool-call signal.
86
+ *
87
+ * `abort` is a settled judgement the caller acts on immediately: every STREAK bound
88
+ * (consecutive errors / web calls / MCP calls / non-action calls) reads only the stream, so the
89
+ * stream is all the evidence there is.
90
+ *
91
+ * `needs-workspace-evidence` is the no-edit bound, and it is deliberately NOT settled. That bound
92
+ * asks "has this run changed the repository yet", and the tool names are only a proxy for it: an
93
+ * agent writing files through `bash` reads as forty calls and no edits however much work it did.
94
+ * So the guard hands the question back with the diagnostic it would abort on, and the caller
95
+ * answers it from the working tree (see `workspace-probe.ts`) before anything is killed.
96
+ */
97
+ export type ProgressVerdict = {
98
+ kind: 'abort';
99
+ reason: string;
100
+ } | {
101
+ kind: 'needs-workspace-evidence';
102
+ reason: string;
103
+ };
104
+ /**
105
+ * Live anti-rabbithole guard: fed each streamed tool-call signal, it returns a {@link
106
+ * ProgressVerdict} the moment a run has plainly stopped making progress, so the harness can kill
107
+ * the CLI early instead of letting it burn the whole budget (and then surface a useful failure
108
+ * instead of a generic "no file changes").
109
+ *
110
+ * PURE, SYNCHRONOUS and INCREMENTAL, so it can be unit-tested over a fixed event sequence: it
111
+ * spawns nothing and reads nothing off disk. The one bound that needs evidence from outside the
112
+ * stream says so in its verdict and lets the caller fetch it, then reports the answer back
113
+ * through {@link noteWorkspaceMutation} / {@link rearmNoEditBound}.
90
114
  */
91
115
  export declare class ProgressGuard {
92
116
  private readonly limits;
@@ -98,14 +122,36 @@ export declare class ProgressGuard {
98
122
  private consecutiveWebCalls;
99
123
  private consecutiveMcpCalls;
100
124
  private consecutiveNonActionCalls;
125
+ private awaitingWorkspaceEvidence;
101
126
  constructor(limits: ProgressGuardLimits,
102
127
  /** When false (assess-only runs like the merger), the no-edit bound is skipped. */
103
128
  expectsEdits?: boolean);
104
- /** Feed one parsed Pi event; returns a diagnostic reason when the run should abort, else null. */
105
- observe(event: Record<string, unknown>): string | null;
129
+ /** Feed one parsed Pi event; returns a {@link ProgressVerdict} when the run is in trouble, else null. */
130
+ observe(event: Record<string, unknown>): ProgressVerdict | null;
131
+ /**
132
+ * Record that the run HAS changed the repository, however it did it. Satisfies the no-edit
133
+ * bound permanently, exactly as a recognised edit-tool call does, matching that bound's
134
+ * existing semantics: it guards a run only UNTIL its first edit, because an agent that has
135
+ * changed the tree has demonstrably started the work.
136
+ *
137
+ * Called by the driver when a workspace probe answers a `needs-workspace-evidence` verdict
138
+ * positively. Idempotent, and cheap enough that a caller who probes for other reasons may also
139
+ * report through it.
140
+ */
141
+ noteWorkspaceMutation(): void;
142
+ /**
143
+ * Re-arm the no-edit bound after a probe that could answer NEITHER way (it threw). The bound
144
+ * becomes trippable again once another `maxToolCallsWithoutEdit` action calls have gone by,
145
+ * rather than the run being killed on a git failure or left permanently unguarded by one.
146
+ *
147
+ * Failing open here is the deliberate half: killing a productive run is the expensive error,
148
+ * and the streak bounds, the inactivity watchdog and the job's wall-clock cap all still hold
149
+ * the run in the meantime.
150
+ */
151
+ rearmNoEditBound(): void;
106
152
  /**
107
- * Feed one already-parsed tool-call signal (name + error flag), returning a diagnostic reason
108
- * when the run should abort, else null. Split out of {@link observe} so a caller whose stream
153
+ * Feed one already-parsed tool-call signal (name + error flag), returning a {@link
154
+ * ProgressVerdict} when a bound is reached, else null. Split out of {@link observe} so a caller whose stream
109
155
  * is NOT Pi's `tool_execution_end` envelope — the claude-code runner, which correlates a
110
156
  * `tool_use` block's name with its `tool_result`'s `is_error` — can drive the SAME guard logic
111
157
  * without synthesising a fake Pi event.
@@ -113,5 +159,5 @@ export declare class ProgressGuard {
113
159
  observeSignal(tool: {
114
160
  name: string;
115
161
  isError: boolean;
116
- }): string | null;
162
+ }): ProgressVerdict | null;
117
163
  }
@@ -43,8 +43,14 @@ export const DEFAULT_PROGRESS_GUARD_LIMITS = {
43
43
  // broad on purpose: different models/extensions name the same capability differently
44
44
  // (`edit`/`write`, but also `apply_patch`/`patch`/`str_replace`/`multiedit`/`create`),
45
45
  // and a false "no edits" reading would kill a run that IS making changes. Matched
46
- // case-insensitively. NOTE: a file written purely via `bash` (e.g. a heredoc) is not
47
- // recognised here — broaden or move to a working-tree signal if that becomes common.
46
+ // case-insensitively.
47
+ //
48
+ // A file written purely through `bash` (a heredoc, `sed -i`, `node -e`) is NOT recognised here,
49
+ // and deliberately so: this set answers "did the model call a tool we already know edits files",
50
+ // which is a cheap SUFFICIENT condition and never a necessary one. The necessary one is the
51
+ // working tree itself, which is what the no-edit bound now actually decides on: see the
52
+ // `needs-workspace-evidence` verdict and {@link ProgressGuard.noteWorkspaceMutation}. A hit here
53
+ // still satisfies the bound outright, so the common case never pays for a probe.
48
54
  const FILE_EDIT_TOOLS = new Set([
49
55
  'edit',
50
56
  'write',
@@ -170,11 +176,15 @@ export function mergeGuardLimits(base, overrides) {
170
176
  };
171
177
  }
172
178
  /**
173
- * Live anti-rabbithole guard: fed each streamed Pi event, it returns a diagnostic
174
- * reason the moment a run has plainly stopped making progress, so the harness can
175
- * kill Pi early instead of letting it burn the whole budget (and then surface a
176
- * useful failure instead of a generic "no file changes"). Pure and incremental so
177
- * it can be unit-tested over a fixed event sequence.
179
+ * Live anti-rabbithole guard: fed each streamed tool-call signal, it returns a {@link
180
+ * ProgressVerdict} the moment a run has plainly stopped making progress, so the harness can kill
181
+ * the CLI early instead of letting it burn the whole budget (and then surface a useful failure
182
+ * instead of a generic "no file changes").
183
+ *
184
+ * PURE, SYNCHRONOUS and INCREMENTAL, so it can be unit-tested over a fixed event sequence: it
185
+ * spawns nothing and reads nothing off disk. The one bound that needs evidence from outside the
186
+ * stream says so in its verdict and lets the caller fetch it, then reports the answer back
187
+ * through {@link noteWorkspaceMutation} / {@link rearmNoEditBound}.
178
188
  */
179
189
  export class ProgressGuard {
180
190
  limits;
@@ -185,13 +195,18 @@ export class ProgressGuard {
185
195
  consecutiveWebCalls = 0;
186
196
  consecutiveMcpCalls = 0;
187
197
  consecutiveNonActionCalls = 0;
198
+ // Set when the no-edit bound has been reported as `needs-workspace-evidence` and the caller's
199
+ // probe has not answered yet. It suppresses a second report: the bound is a threshold, so every
200
+ // action call past it would otherwise re-raise the same unanswered question and the caller would
201
+ // probe git once per tool call. Cleared by whichever answer comes back.
202
+ awaitingWorkspaceEvidence = false;
188
203
  constructor(limits,
189
204
  /** When false (assess-only runs like the merger), the no-edit bound is skipped. */
190
205
  expectsEdits = true) {
191
206
  this.limits = limits;
192
207
  this.expectsEdits = expectsEdits;
193
208
  }
194
- /** Feed one parsed Pi event; returns a diagnostic reason when the run should abort, else null. */
209
+ /** Feed one parsed Pi event; returns a {@link ProgressVerdict} when the run is in trouble, else null. */
195
210
  observe(event) {
196
211
  const tool = toolCallSignal(event);
197
212
  if (!tool)
@@ -199,8 +214,35 @@ export class ProgressGuard {
199
214
  return this.observeSignal(tool);
200
215
  }
201
216
  /**
202
- * Feed one already-parsed tool-call signal (name + error flag), returning a diagnostic reason
203
- * when the run should abort, else null. Split out of {@link observe} so a caller whose stream
217
+ * Record that the run HAS changed the repository, however it did it. Satisfies the no-edit
218
+ * bound permanently, exactly as a recognised edit-tool call does, matching that bound's
219
+ * existing semantics: it guards a run only UNTIL its first edit, because an agent that has
220
+ * changed the tree has demonstrably started the work.
221
+ *
222
+ * Called by the driver when a workspace probe answers a `needs-workspace-evidence` verdict
223
+ * positively. Idempotent, and cheap enough that a caller who probes for other reasons may also
224
+ * report through it.
225
+ */
226
+ noteWorkspaceMutation() {
227
+ this.edits++;
228
+ this.awaitingWorkspaceEvidence = false;
229
+ }
230
+ /**
231
+ * Re-arm the no-edit bound after a probe that could answer NEITHER way (it threw). The bound
232
+ * becomes trippable again once another `maxToolCallsWithoutEdit` action calls have gone by,
233
+ * rather than the run being killed on a git failure or left permanently unguarded by one.
234
+ *
235
+ * Failing open here is the deliberate half: killing a productive run is the expensive error,
236
+ * and the streak bounds, the inactivity watchdog and the job's wall-clock cap all still hold
237
+ * the run in the meantime.
238
+ */
239
+ rearmNoEditBound() {
240
+ this.toolCalls = 0;
241
+ this.awaitingWorkspaceEvidence = false;
242
+ }
243
+ /**
244
+ * Feed one already-parsed tool-call signal (name + error flag), returning a {@link
245
+ * ProgressVerdict} when a bound is reached, else null. Split out of {@link observe} so a caller whose stream
204
246
  * is NOT Pi's `tool_execution_end` envelope — the claude-code runner, which correlates a
205
247
  * `tool_use` block's name with its `tool_result`'s `is_error` — can drive the SAME guard logic
206
248
  * without synthesising a fake Pi event.
@@ -211,8 +253,11 @@ export class ProgressGuard {
211
253
  // isn't wedged in a failing-op loop), so it's updated before the planning skip.
212
254
  this.consecutiveErrors = tool.isError ? this.consecutiveErrors + 1 : 0;
213
255
  if (this.consecutiveErrors >= this.limits.maxConsecutiveErrors) {
214
- return (`no progress: ${this.consecutiveErrors} consecutive failing tool calls — the agent is stuck ` +
215
- `retrying a failing operation rather than making progress. Aborting.`);
256
+ return {
257
+ kind: 'abort',
258
+ reason: `no progress: ${this.consecutiveErrors} consecutive failing tool calls — the agent is stuck ` +
259
+ `retrying a failing operation rather than making progress. Aborting.`,
260
+ };
216
261
  }
217
262
  // Web search/fetch loop: web tools are read-only (they don't count toward the
218
263
  // no-edit bound), so guard them separately — an uninterrupted streak of them is a
@@ -221,8 +266,11 @@ export class ProgressGuard {
221
266
  this.consecutiveWebCalls++;
222
267
  const webCap = this.limits.maxConsecutiveWebCalls ?? DEFAULT_PROGRESS_GUARD_LIMITS.maxConsecutiveWebCalls;
223
268
  if (this.consecutiveWebCalls >= webCap) {
224
- return (`no progress: ${this.consecutiveWebCalls} consecutive web search/fetch calls without ` +
225
- `any other action — the agent is stuck researching instead of doing the work. Aborting.`);
269
+ return {
270
+ kind: 'abort',
271
+ reason: `no progress: ${this.consecutiveWebCalls} consecutive web search/fetch calls without ` +
272
+ `any other action — the agent is stuck researching instead of doing the work. Aborting.`,
273
+ };
226
274
  }
227
275
  }
228
276
  else {
@@ -235,9 +283,12 @@ export class ProgressGuard {
235
283
  this.consecutiveMcpCalls++;
236
284
  const mcpCap = this.limits.maxConsecutiveMcpCalls ?? DEFAULT_PROGRESS_GUARD_LIMITS.maxConsecutiveMcpCalls;
237
285
  if (this.consecutiveMcpCalls >= mcpCap) {
238
- return (`no progress: ${this.consecutiveMcpCalls} consecutive tool-server (MCP) calls without ` +
239
- `any other action. The agent is stuck querying its tools instead of doing the work. ` +
240
- `Aborting.`);
286
+ return {
287
+ kind: 'abort',
288
+ reason: `no progress: ${this.consecutiveMcpCalls} consecutive tool-server (MCP) calls without ` +
289
+ `any other action. The agent is stuck querying its tools instead of doing the work. ` +
290
+ `Aborting.`,
291
+ };
241
292
  }
242
293
  }
243
294
  else {
@@ -264,9 +315,12 @@ export class ProgressGuard {
264
315
  const nonActionCap = this.limits.maxConsecutiveNonActionCalls ??
265
316
  DEFAULT_PROGRESS_GUARD_LIMITS.maxConsecutiveNonActionCalls;
266
317
  if (this.consecutiveNonActionCalls >= nonActionCap) {
267
- return (`no progress: ${this.consecutiveNonActionCalls} consecutive read-only calls (searching, ` +
268
- `reading, tool-server lookups, subagent dispatches) with no action call between them. ` +
269
- `The agent is cycling through research instead of doing the work. Aborting.`);
318
+ return {
319
+ kind: 'abort',
320
+ reason: `no progress: ${this.consecutiveNonActionCalls} consecutive read-only calls (searching, ` +
321
+ `reading, tool-server lookups, subagent dispatches) with no action call between them. ` +
322
+ `The agent is cycling through research instead of doing the work. Aborting.`,
323
+ };
270
324
  }
271
325
  return null;
272
326
  }
@@ -274,11 +328,19 @@ export class ProgressGuard {
274
328
  this.toolCalls++;
275
329
  if (FILE_EDIT_TOOLS.has(name))
276
330
  this.edits++;
331
+ // PROVISIONAL, not settled: the tool names say no recognised edit tool was called, which is
332
+ // not the same fact as "the repository is unchanged". The caller answers that from the
333
+ // working tree and reports back; until it does, the question is not re-raised.
277
334
  if (this.expectsEdits &&
278
335
  this.edits === 0 &&
336
+ !this.awaitingWorkspaceEvidence &&
279
337
  this.toolCalls >= this.limits.maxToolCallsWithoutEdit) {
280
- return (`no progress: ${this.toolCalls} tool calls and not one file edit — the agent is exploring or ` +
281
- `probing the environment without implementing anything. Aborting before it burns the whole run.`);
338
+ this.awaitingWorkspaceEvidence = true;
339
+ return {
340
+ kind: 'needs-workspace-evidence',
341
+ reason: `no progress: ${this.toolCalls} tool calls and no recognised file edit — the agent may be ` +
342
+ `exploring or probing the environment without implementing anything.`,
343
+ };
282
344
  }
283
345
  return null;
284
346
  }
package/dist/runner.d.ts CHANGED
@@ -99,7 +99,7 @@ export interface RunOptions {
99
99
  log?: Logger;
100
100
  /**
101
101
  * Extra environment for the agent's child process, scoped to THIS job. The CLI is spawned with
102
- * `{...process.env, ...agentEnv}`, so these reach the agent and every shell tool it spawns.
102
+ * `agentChildEnv(agentEnv)`, so these reach the agent and every shell tool it spawns.
103
103
  *
104
104
  * This is the seam for anything per-job that would otherwise be written to a process- or
105
105
  * HOME-global (the tester's secrets, a private-registry npmrc pointer). Those globals are only
@@ -0,0 +1,180 @@
1
+ import type { Logger } from './logger.js';
2
+ /**
3
+ * Directory and file names never salvaged. A greenfield checkout may not have a `.gitignore` yet
4
+ * (the agent had not written one when it was killed), and git only excludes what a `.gitignore`
5
+ * tells it to, so without this a blanket salvage would commit `node_modules` into the PR.
6
+ *
7
+ * Matched against every SEGMENT of a path, so `packages/api/node_modules/x` is caught as surely as
8
+ * a root-level one. Deliberately a short list of the unambiguous ones: a cleverer heuristic starts
9
+ * discarding the deliverable, and a `dist/` that genuinely belonged in a commit is a far cheaper
10
+ * miss than a `node_modules/` that did not.
11
+ */
12
+ export declare const SALVAGE_DENIED_SEGMENTS: readonly string[];
13
+ /** Suffixes never salvaged: run output, not source. */
14
+ export declare const SALVAGE_DENIED_SUFFIXES: readonly string[];
15
+ /**
16
+ * Basenames and suffixes that carry CREDENTIALS, withheld from every salvage.
17
+ *
18
+ * The deny-list above trades a cheap miss (a `dist/` that belonged in a commit) against an
19
+ * expensive one (`node_modules/` in a PR). For a secret that trade INVERTS: a private key or a
20
+ * populated `.env` pushed to a branch is a disclosure that outlives the run, cannot be taken back
21
+ * by deleting the commit, and forces a rotation. Missing a file is recoverable; leaking one is not.
22
+ *
23
+ * This exists for the same reason the deny-list does: on the greenfield case the salvage was
24
+ * written for, the agent was killed before it wrote a `.gitignore`, so git excludes nothing and
25
+ * the harness is the only thing standing between an agent-authored key and the pull request.
26
+ *
27
+ * Unlike a junk path, a withheld secret is REPORTED (see {@link SalvageReport.withheld}): the file
28
+ * is real work that did not land, and whoever reads the run has to decide whether to re-create it
29
+ * or, if it holds a live credential, to rotate it.
30
+ */
31
+ export declare const SALVAGE_SECRET_BASENAMES: readonly string[];
32
+ /**
33
+ * Suffixes that mark a key store or an environment file, withheld for the reason above.
34
+ *
35
+ * `.env` is here as well as in {@link isSecretBearingName}'s own `.env` / `.env.*` test, so that
36
+ * `prod.env` and `local.env` are caught alongside `.env` and `.env.production`. The sample
37
+ * allow-list is unaffected: `.env.example` ends in `.example`, not in `.env`.
38
+ */
39
+ export declare const SALVAGE_SECRET_SUFFIXES: readonly string[];
40
+ /** Path segments that are credential or state stores rather than source. */
41
+ export declare const SALVAGE_SECRET_SEGMENTS: readonly string[];
42
+ /**
43
+ * The `.env` files that carry no secret and ARE the deliverable: the checked-in sample every
44
+ * scaffold ships so a reader knows which variables the service wants.
45
+ *
46
+ * An allow-list rather than a cleverer rule, because the two are the same shape and only the
47
+ * convention tells them apart. `.env` and every other `.env.<something>` is withheld: a scaffolded
48
+ * `.env.local` or `.env.production` is exactly where a real key ends up.
49
+ */
50
+ export declare const SALVAGE_ENV_SAMPLE_BASENAMES: readonly string[];
51
+ /** How much may be salvaged before the whole salvage is refused. */
52
+ export interface SalvageBounds {
53
+ maxFiles: number;
54
+ maxBytes: number;
55
+ }
56
+ /**
57
+ * The default bounds. Generous enough for a scaffolded service (the run this was written for left
58
+ * about twenty source files) and far below anything that looks like a build output or a dependency
59
+ * tree that slipped past the deny-list.
60
+ */
61
+ export declare const DEFAULT_SALVAGE_BOUNDS: SalvageBounds;
62
+ /** What the salvage did, carried onto the run outcome so a human is told rather than left to infer. */
63
+ export interface SalvageReport {
64
+ /**
65
+ * `none`: nothing was left uncommitted. `committed`: the files below are in `commitSha`.
66
+ * `refused`: there was work but it exceeded the bounds, so NOTHING was committed — a truncated
67
+ * salvage is worse than none, because a half-committed tree reads as a complete one.
68
+ * `failed`: the commit itself could not be made; the paths are named so the loss is on the record.
69
+ */
70
+ status: 'none' | 'committed' | 'refused' | 'failed';
71
+ /** The salvaged (or would-be salvaged) paths, capped for the log/wire; `fileCount` is the truth. */
72
+ files: string[];
73
+ fileCount: number;
74
+ totalBytes: number;
75
+ commitSha?: string;
76
+ /** Why a `refused`/`failed` salvage did not land. */
77
+ reason?: string;
78
+ /**
79
+ * Secret-bearing paths the salvage refused to commit, whatever its `status` (a run with nothing
80
+ * else to salvage still reports them, as `none`). Named rather than counted: the point is that
81
+ * someone can look at the file and decide whether it held a live credential.
82
+ */
83
+ withheld?: string[];
84
+ }
85
+ /**
86
+ * What the salvage does with one path.
87
+ *
88
+ * Three outcomes, not two, because the reasons for withholding a file are not the same fact. A
89
+ * `skip` is expected and uninteresting: nobody wants `node_modules` in a PR, and saying so would
90
+ * be noise on every run. A `secret` is a decision someone has to know about — the file was real
91
+ * work, it did not land, and it may hold a live credential that now needs rotating.
92
+ */
93
+ export type SalvageDisposition = 'salvage' | 'skip' | 'secret';
94
+ /** What the salvage would do with `path`: keep it, drop it quietly, or withhold it as a secret. */
95
+ export declare function classifySalvagePath(path: string): SalvageDisposition;
96
+ /**
97
+ * Split the untracked paths into what the salvage commits and what it withholds as secret-bearing.
98
+ *
99
+ * The secret check runs BEFORE the junk one, so a key under a denied directory is still counted as
100
+ * withheld rather than swallowed as junk: the point of the count is telling someone a credential
101
+ * may have been created, and where it happened to sit does not change that.
102
+ */
103
+ export declare function partitionSalvageCandidates(paths: readonly string[]): {
104
+ candidates: string[];
105
+ withheld: string[];
106
+ };
107
+ /**
108
+ * Commit the new, untracked, non-ignored files the agent left behind in `dir`.
109
+ *
110
+ * Bounded by FILE COUNT and TOTAL BYTES, and over either bound it salvages NOTHING and says so:
111
+ * committing a prefix would produce a tree that looks complete and is not, which is the one
112
+ * outcome worse than the loss this exists to prevent.
113
+ *
114
+ * The message names the salvage as a salvage. A commit that arrives on a branch with no
115
+ * explanation is indistinguishable from work the agent chose to make, and this work was chosen by
116
+ * nobody — the run was killed with it still on the floor.
117
+ *
118
+ * CODING MODE ONLY: the caller decides that. A read-only kind has no branch to carry a commit and
119
+ * must never be given one.
120
+ */
121
+ export declare function salvageUntrackedWork(args: {
122
+ dir: string;
123
+ /** How the run ended, which is what the commit message has to state. */
124
+ occasion: SalvageOccasion;
125
+ logger: Logger;
126
+ signal?: AbortSignal;
127
+ bounds?: SalvageBounds;
128
+ }): Promise<SalvageReport>;
129
+ /**
130
+ * How the run that left these files behind ended. It decides what the commit message SAYS, which
131
+ * is the whole point of marking a salvage: a commit arriving on a branch with no explanation is
132
+ * indistinguishable from work the agent chose to make and someone chose to keep.
133
+ */
134
+ export type SalvageOccasion =
135
+ /** The run was killed mid-flight (guard, watchdog, eviction); `cause` is what killed it. */
136
+ {
137
+ kind: 'aborted';
138
+ cause: string;
139
+ }
140
+ /** The agent finished but never added its own new files. */
141
+ | {
142
+ kind: 'settled';
143
+ };
144
+ /** The salvage commit's message: what it is, why it exists, and how much to trust it. */
145
+ export declare function salvageCommitMessage(fileCount: number, occasion: SalvageOccasion): string;
146
+ /**
147
+ * The banner for a pull request whose ENTIRE content is a salvage.
148
+ *
149
+ * A branch the agent never committed to, which exists only because the harness swept up the
150
+ * untracked files left in that checkout, is not a change anyone proposed. It is still worth
151
+ * opening (dropping it is the loss this whole module exists to prevent, and a peer repository in a
152
+ * multi-repo run is where a cross-service change most easily goes missing), but its reviewer has
153
+ * to be told that before reading it as a considered contribution: the agent may have been building
154
+ * there, or it may have left scratch work behind while working on a sibling repository, and
155
+ * nothing in the diff distinguishes the two.
156
+ *
157
+ * Lives here with {@link salvageCommitMessage} and {@link describeSalvage} because all three are
158
+ * the same job — saying what a salvage is to whoever finds it — and the three had better not drift
159
+ * into describing it differently. The caller decides WHERE it goes.
160
+ */
161
+ export declare function salvageOnlyNotice(): string;
162
+ /**
163
+ * Where a salvage commit ENDED UP, which the salvage itself cannot know: it commits, and someone
164
+ * else pushes. A commit that was not pushed dies with the container exactly as the uncommitted
165
+ * files would have, so a note that does not say so describes a rescue that did not happen.
166
+ */
167
+ export interface SalvageDelivery {
168
+ pushed: boolean;
169
+ /** Why the push did not land, when it did not. */
170
+ reason?: string;
171
+ }
172
+ /**
173
+ * What a human can act on, in one or two sentences. Joined onto the failure an aborted run
174
+ * reports, so the person reading "the run was killed" is told in the same breath what became of
175
+ * its work: on the branch and reviewed by nobody, still in the container, or never committed.
176
+ *
177
+ * `delivery` is supplied by whoever pushed. Absent means the caller is on a path where the
178
+ * ordinary push follows (the settle path), so there is nothing extra to say.
179
+ */
180
+ export declare function describeSalvage(report: SalvageReport, delivery?: SalvageDelivery): string | undefined;