@rasensio/aidlc 2.23.0 → 2.24.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.
@@ -94,7 +94,23 @@ export interface DriverCtx {
94
94
  /** At most `max` bytes of `path` from `offset`; empty when unreadable. */
95
95
  readRange?(path: string, offset: number, max: number): Buffer;
96
96
  append?(path: string, text: string): void;
97
+ /**
98
+ * Delete `path`; nothing when it does not exist. Absent: a failed retrospective's new
99
+ * files and its snapshot are left where they are (autopilot-runs-retrospective/AC-10).
100
+ */
101
+ remove?(path: string): void;
97
102
  };
103
+ /**
104
+ * Record one finished session's cost against `instance`, now, and say whether it could:
105
+ * `busy` while another capture of the session holds its lock, `none` when its record
106
+ * cannot be found. Absent: skipped, and the cost hook records it alone
107
+ * (autopilot-runs-retrospective/AC-16, design D5).
108
+ */
109
+ captureSession?(a: {
110
+ provider: 'claude-code' | 'codex';
111
+ sessionId: string;
112
+ instance: string;
113
+ }): 'done' | 'busy' | 'none';
98
114
  /** The effective rate table for the primary checkout. Absent: Codex usage is unpriced (AC-21). */
99
115
  rates?(): EffectiveRates;
100
116
  /** The model a Codex thread used, read from its rollout; null when it cannot be read (AC-20, AC-21). */
@@ -1 +1 @@
1
- {"version":3,"file":"driver.d.ts","sourceRoot":"","sources":["../../src/autopilot/driver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAKH,OAAO,EAA0B,KAAK,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAE/E,OAAO,EAAsB,KAAK,IAAI,EAAE,MAAM,iBAAiB,CAAC;AA+BhE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAgB1C,OAAO,KAAK,EACV,eAAe,EACf,aAAa,EACb,cAAc,EACd,cAAc,EACd,QAAQ,EAIR,WAAW,EACZ,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAuD,KAAK,UAAU,EAAE,KAAK,KAAK,EAAE,MAAM,YAAY,CA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E,MAAM,CAAC,EAAE,MAAM,GAAG,cAAc,CAmC3F;AAED,mGAAmG;AACnG,wBAAgB,OAAO,CAAC,KAAK,EAAE,cAAc,GAAG,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAEpE;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,cAAc,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,CAKvG;AAiBD,oGAAoG;AACpG,wBAAgB,SAAS,CAAC,CAAC,EAAE,aAAa,GAAG,MAAM,CAOlD;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CACxB,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE,cAAc,EACrB,GAAG,EAAE,MAAM,EACX,QAAQ,GAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAqB,GAC/C,MAAM,CAIR;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,cAAc,GAAG,MAAM,GAAG,IAAI,CAE9D;AAYD,wBAAgB,WAAW,CAAC,GAAG,EAAE,IAAI,CAAC,SAAS,EAAE,IAAI,GAAG,OAAO,GAAG,KAAK,CAAC,EAAE,KAAK,EAAE,cAAc,EAAE,IAAI,GAAE,IAAe,GAAG,MAAM,EAAE,CAahI"}
@@ -24,6 +24,8 @@ import { DIFF_MAX, DIFF_PATHSPEC, VERDICT_SCHEMA, changedSince, checkerPrompt, f
24
24
  import { classify, jobRef, parseRunJobs } from './ci-jobs.js';
25
25
  import { GLAB_READ_RE, TAG_PIPELINES_ARGS, classifyJobs, jobsArgs, mergeArgs, mergedAnswer, mrCreateArgs, mrNumber, mrViewArgs, noteArgs, parseJobs, parseMr, releaseInFlight, retryArgs, } from './gitlab.js';
26
26
  import { REASON_MAX, RESET_WAIT_MAX_MS, codexEnd, emptyCodexProgress, firstLine, lastClaudeResult, readClaudeResult, readCodexEvents, refusalSuffix, resetAt, stoppedBy, summaryLines, } from './result.js';
27
+ import { retroMarker, retroSnapshotPath } from './state.js';
28
+ import { RETRO_LIMIT_MS, retroAllowed, retroChanges, retroPrompt } from './retro.js';
27
29
  import { capInForce, tokensLeft } from './cap.js';
28
30
  import { fmtTokens } from '../commands/cost.js';
29
31
  import { LEGACY_STOPS, pauseEnv, pendingReview, stopsInForce } from './stops.js';
@@ -315,6 +317,21 @@ export function launchBlocked(state, now) {
315
317
  const capReached = (cap, spentMicro) => `cost cap ${cap} USD reached — spent ${microToUsd(spentMicro)}`;
316
318
  /** The park reason when the item's tokens have used up its token cap (cost-in-tokens/AC-14, AC-15). */
317
319
  const tokenCapReached = (cap, used) => `token cap ${fmtTokens(cap)} reached — used ${fmtTokens(used)} tokens`;
320
+ /**
321
+ * Why the item's recorded spend leaves no room for another session, or null. In dollars: a
322
+ * budget under a cent. In tokens: none left — checked between sessions, since Claude has a
323
+ * dollar budget flag and no token one (cost-in-tokens/AC-14, AC-17).
324
+ */
325
+ function capUsedUp(ctx, item) {
326
+ const capSet = capInForce(ctx.config);
327
+ const spent = item.spent_micro_usd ?? 0;
328
+ if (capSet?.unit === 'usd' && budgetCents(capSet.usd, spent) < 1)
329
+ return capReached(capSet.usd, spent);
330
+ if (capSet?.unit === 'tokens' && tokensLeft(capSet.tokens, item.spent_tokens ?? 0) < 1) {
331
+ return tokenCapReached(capSet.tokens, item.spent_tokens ?? 0);
332
+ }
333
+ return null;
334
+ }
318
335
  const logFile = (ctx, item) => `${ctx.paths.logs}/${item.name}.log`;
319
336
  /**
320
337
  * Launch the item's agent. False when nothing was launched: a session-limit wait is in
@@ -336,14 +353,12 @@ function launchAgent(ctx, io, state, item, prompt, budget, resume, kind = 'build
336
353
  const cap = capSet?.unit === 'usd' ? capSet.usd : undefined;
337
354
  const spent = item.spent_micro_usd ?? 0;
338
355
  const cents = typeof cap === 'number' ? budgetCents(cap, spent) : null;
339
- if (typeof cap === 'number' && (cents ?? 0) < 1) {
340
- park(ctx, io, state, item, capReached(cap, spent), budget);
341
- return false;
342
- }
343
- // A token cap is checked between sessions: Claude has a dollar budget flag and no
344
- // token one, so `cents` stays null and none is passed (cost-in-tokens/AC-14, AC-17).
345
- if (capSet?.unit === 'tokens' && tokensLeft(capSet.tokens, item.spent_tokens ?? 0) < 1) {
346
- park(ctx, io, state, item, tokenCapReached(capSet.tokens, item.spent_tokens ?? 0), budget);
356
+ const used = capUsedUp(ctx, item);
357
+ if (used !== null) {
358
+ // A retrospective never parks: `afterClose` checked the cap before it got here, and
359
+ // this is only the net under that check (autopilot-runs-retrospective/AC-5, AC-13).
360
+ if (kind !== 'retro')
361
+ park(ctx, io, state, item, used, budget);
347
362
  return false;
348
363
  }
349
364
  const command = ctx.config?.agent_command ?? [];
@@ -358,7 +373,8 @@ function launchAgent(ctx, io, state, item, prompt, budget, resume, kind = 'build
358
373
  // A checker ends with its verdict, not the build's outcome, and cannot use the edit
359
374
  // tools; it never resumes (pr-checker-earns-merge/AC-1, AC-4, AC-6, design D5).
360
375
  const check = kind === 'check';
361
- const outcomeFile = `${ctx.paths.dir}/outcomes/${item.name}${check ? '.check' : ''}.json`;
376
+ // Its own file, so a build's outcome is never read as the retrospective's (autopilot-runs-retrospective, design D2).
377
+ const outcomeFile = `${ctx.paths.dir}/outcomes/${item.name}${check ? '.check' : kind === 'retro' ? '.retro' : ''}.json`;
362
378
  const schemaFile = `${ctx.paths.dir}/${check ? 'check' : 'outcome'}-schema.json`;
363
379
  const typed = typedArgv(command, {
364
380
  harness,
@@ -370,7 +386,8 @@ function launchAgent(ctx, io, state, item, prompt, budget, resume, kind = 'build
370
386
  ...(check ? { schema: VERDICT_SCHEMA, disallowedTools: ['Edit', 'Write', 'NotebookEdit'] } : {}),
371
387
  });
372
388
  if (typed === null) {
373
- park(ctx, io, state, item, `${resume?.label ?? 'session'} — no usable session id`, budget);
389
+ if (kind !== 'retro')
390
+ park(ctx, io, state, item, `${resume?.label ?? 'session'} — no usable session id`, budget);
374
391
  return false;
375
392
  }
376
393
  argv = typed;
@@ -395,15 +412,22 @@ function launchAgent(ctx, io, state, item, prompt, budget, resume, kind = 'build
395
412
  ctx.fs.write(outcomeFile, '');
396
413
  }
397
414
  }
415
+ const retro = kind === 'retro';
398
416
  const env = {
399
417
  AIDLC_UNATTENDED: '1',
400
418
  AIDLC_AGENT: ctx.config?.agent_platform ?? 'claude-code',
401
419
  // Where the unattended rule's review boundaries are (autopilot-stop-controls/AC-11).
402
- AIDLC_PAUSE_AFTER: itemPauses(item),
420
+ // A retrospective has no phases to pause after (autopilot-runs-retrospective, design D2).
421
+ AIDLC_PAUSE_AFTER: retro ? '' : itemPauses(item),
422
+ // Its session is after the completion moment, which no claim interval covers: the
423
+ // recorder files it under the instance by this name (AC-16, design D5).
424
+ ...(retro ? { AIDLC_COST_INSTANCE: item.name } : {}),
403
425
  };
404
- const who = kind === 'check' ? 'checker' : 'agent';
426
+ const who = kind === 'check' ? 'checker' : retro ? 'retrospective agent' : 'agent';
427
+ // The primary checkout: the item's worktree no longer holds anything to merge (AC-1).
428
+ const cwd = retro ? ctx.repo : item.worktree;
405
429
  if (ctx.dryRun) {
406
- ctx.say(`[dry-run] (in ${item.worktree}) launch ${who}: ${argv[0]} … (${argv.length} args${harness === null ? '' : `, typed ${harness}`})`);
430
+ ctx.say(`[dry-run] (in ${cwd}) launch ${who}: ${argv[0]} … (${argv.length} args${harness === null ? '' : `, typed ${harness}`})`);
407
431
  return true;
408
432
  }
409
433
  if (launch === undefined) {
@@ -417,7 +441,7 @@ function launchAgent(ctx, io, state, item, prompt, budget, resume, kind = 'build
417
441
  launch.read_offset = launch.log_offset;
418
442
  item.launch = launch;
419
443
  }
420
- item.pid = ctx.spawnDetached(argv, { cwd: item.worktree, env, logFile: log });
444
+ item.pid = ctx.spawnDetached(argv, { cwd, env, logFile: log });
421
445
  item.pid_started_at = new Date(ctx.now()).toISOString();
422
446
  if (!isPid(item.pid)) {
423
447
  // Its error arrives after this pass; the next one parks it (agent-binary-missing-crashes-loop/AC-3).
@@ -653,7 +677,7 @@ const onRecord = (record, key) => key === null ? 0 : record?.[key] ?? 0;
653
677
  *
654
678
  * @returns whether it stopped and parked the item.
655
679
  */
656
- function stoppedAtCap(ctx, io, state, item, launch, capSet, budget) {
680
+ function stoppedAtCap(ctx, io, state, item, launch, capSet, budget, onCap = (reason) => park(ctx, io, state, item, reason, budget)) {
657
681
  if ((launch.progress?.turns ?? 0) === 0)
658
682
  return false;
659
683
  const thread = launch.progress?.thread_id ?? null;
@@ -668,7 +692,7 @@ function stoppedAtCap(ctx, io, state, item, launch, capSet, budget) {
668
692
  if (!ctx.dryRun && item.pid !== null)
669
693
  ctx.kill(item.pid);
670
694
  appendSummary(ctx, item, summaryLines(sessionSoFar(launch, launchUsageMicro(ctx, launch)), 'stopped by autopilot at the token cap'));
671
- park(ctx, io, state, item, tokenCapReached(capSet.tokens, used), budget);
695
+ onCap(tokenCapReached(capSet.tokens, used));
672
696
  return true;
673
697
  }
674
698
  const cap = capSet.usd;
@@ -683,7 +707,7 @@ function stoppedAtCap(ctx, io, state, item, launch, capSet, budget) {
683
707
  if (!ctx.dryRun && item.pid !== null)
684
708
  ctx.kill(item.pid);
685
709
  appendSummary(ctx, item, summaryLines(sessionSoFar(launch, priced), 'stopped by autopilot at the cost cap'));
686
- park(ctx, io, state, item, capReached(cap, spent), budget);
710
+ onCap(capReached(cap, spent));
687
711
  return true;
688
712
  }
689
713
  /**
@@ -778,18 +802,19 @@ function appendSummary(ctx, item, lines) {
778
802
  append(log, `${lead}${lines.join('\n')}\n`);
779
803
  }
780
804
  /**
781
- * While the item's agent — a build or a pull request checker — is alive: fold a Codex log
782
- * and hold it to the cap, parking the item when it is past. True while it runs
783
- * (pr-checker-earns-merge/AC-18).
805
+ * While the item's agent — a build, a pull request checker or a retrospective — is alive:
806
+ * fold a Codex log and hold it to the cap, calling `onCap` when it is past: a park, except
807
+ * for a retrospective, which fails instead (pr-checker-earns-merge/AC-18,
808
+ * autopilot-runs-retrospective/AC-11). True while it runs.
784
809
  */
785
- function agentRunning(ctx, io, state, item, budget) {
810
+ function agentRunning(ctx, io, state, item, budget, onCap = (reason) => park(ctx, io, state, item, reason, budget)) {
786
811
  if (isPid(item.pid) && ctx.isAlive(item.pid)) {
787
812
  const launch = item.launch;
788
813
  if (launch?.harness === 'codex')
789
814
  followCodex(ctx, item, launch, false);
790
815
  const capSet = capInForce(ctx.config);
791
816
  if (capSet !== null) {
792
- if (launch?.harness === 'codex' && stoppedAtCap(ctx, io, state, item, launch, capSet, budget))
817
+ if (launch?.harness === 'codex' && stoppedAtCap(ctx, io, state, item, launch, capSet, budget, onCap))
793
818
  return true;
794
819
  // Every agent, typed or not: the ledger's view of the cap stands (autopilot-reads-agent-result/AC-22),
795
820
  // in the unit the cap is set in (cost-in-tokens/AC-16).
@@ -814,7 +839,7 @@ function agentRunning(ctx, io, state, item, budget) {
814
839
  const reason = capSet.unit === 'usd'
815
840
  ? `cost cap ${capSet.usd} USD exceeded`
816
841
  : `token cap ${fmtTokens(capSet.tokens)} exceeded — aidlc cost reports ${fmtTokens(tokens)} tokens`;
817
- park(ctx, io, state, item, reason, budget);
842
+ onCap(reason);
818
843
  }
819
844
  }
820
845
  return true;
@@ -1167,6 +1192,14 @@ function droppedIfMerged(ctx, state, item, view, budget) {
1167
1192
  */
1168
1193
  function answeredByPerson(ctx, io, state, item, view, budget) {
1169
1194
  if (view?.state === 'MERGED') {
1195
+ // Its close-out waits for the running retrospective, and runs on the first pass after it.
1196
+ // Checked here, not in a caller, so every step a person can merge from waits
1197
+ // (autopilot-runs-retrospective/AC-3, design D1).
1198
+ const retro = retroRunning(state);
1199
+ if (retro !== null) {
1200
+ record(ctx, item, `merged — closing it out waits for ${retro.name}'s retrospective`);
1201
+ return true;
1202
+ }
1170
1203
  closeOut(ctx, io, state, item, budget);
1171
1204
  return true;
1172
1205
  }
@@ -1217,7 +1250,7 @@ function closeOut(ctx, io, state, item, budget) {
1217
1250
  const closed = `${ref(hostOf(ctx), item.pr)} merged by you, and closed${closeNote(report)}`;
1218
1251
  tell(ctx, item, closed);
1219
1252
  notice(ctx, 'item closed', `${item.name}: ${closed}`);
1220
- drop(state, item, budget);
1253
+ afterClose(ctx, io, state, item, budget);
1221
1254
  }
1222
1255
  const emptyReport = () => ({ paths: [], leftOut: [], earlier: [], notCopied: [] });
1223
1256
  /** Shown by a dry run in place of the pathspec, which is only known once the transition has written (design D6). */
@@ -1228,8 +1261,8 @@ const DRY_PATHS = '<the paths the close-out changed>';
1228
1261
  * new file; porcelain paths are relative to the repository's top, so the project's `prefix`
1229
1262
  * is removed (closeout-carries-worktree-state/AC-4, design D1).
1230
1263
  */
1231
- function dirtyPaths(ctx, io, prefix) {
1232
- const r = io.call('git', ['status', '--porcelain=v1', '-z', '--no-renames', '--untracked-files=all', '--', '.aidlc'], { cwd: ctx.repo });
1264
+ function dirtyPaths(ctx, io, prefix, pathspec = '.aidlc') {
1265
+ const r = io.call('git', ['status', '--porcelain=v1', '-z', '--no-renames', '--untracked-files=all', '--', pathspec], { cwd: ctx.repo });
1233
1266
  if (r.status !== 0)
1234
1267
  return r;
1235
1268
  return r.stdout
@@ -1364,10 +1397,281 @@ function closeSteps(ctx, io, item, report) {
1364
1397
  ['push-close', () => io.call('git', ['push', 'origin', 'main'], { cwd: ctx.repo })],
1365
1398
  ];
1366
1399
  }
1400
+ // ---------------------------------------------------------------------------
1401
+ // The retrospective after a close-out (autopilot-runs-retrospective)
1402
+ // ---------------------------------------------------------------------------
1403
+ /** The item whose retrospective is running, or null. At most one is (AC-3). */
1404
+ function retroRunning(state) {
1405
+ return state.items.find((i) => i.step === 'retrospective') ?? null;
1406
+ }
1407
+ const MARKER_STAYS = 'the marker stays for aidlc autopilot pending';
1408
+ /** `; left as they are: a, b` — the paths it changed outside the allowed set (AC-7). */
1409
+ const leftAloneNote = (paths) => (paths.length === 0 ? '' : `; left as they are: ${paths.join(', ')}`);
1410
+ function readSnapshot(ctx, item) {
1411
+ const text = ctx.fs.read(retroSnapshotPath(ctx.paths, item.name));
1412
+ if (text === null)
1413
+ return null;
1414
+ try {
1415
+ return JSON.parse(text);
1416
+ }
1417
+ catch {
1418
+ return null;
1419
+ }
1420
+ }
1421
+ /** The fixed allowed paths' text and every uncommitted path's fingerprint, now; or git's failure (design D3). */
1422
+ function readRetroNow(ctx, io, prefix, name) {
1423
+ const dirty = dirtyPaths(ctx, io, prefix, '.');
1424
+ if (!Array.isArray(dirty))
1425
+ return { failed: `git status: ${fail(dirty)}` };
1426
+ const allowed = Object.fromEntries(Object.values(retroAllowed(name)).map((p) => [p, ctx.fs.read(`${ctx.repo}/${p}`)]));
1427
+ return { allowed, dirty: fingerprint(ctx.fs.read, ctx.repo, dirty) };
1428
+ }
1429
+ /** Stop tracking the item, and delete its snapshot. */
1430
+ function finishRetro(ctx, state, item, budget) {
1431
+ ctx.fs.remove?.(retroSnapshotPath(ctx.paths, item.name));
1432
+ drop(state, item, budget);
1433
+ }
1434
+ /**
1435
+ * Push main; a rate limit is a failed push like any other here, because the commit is made
1436
+ * and a back-off that left the item where it is would read the committed paths as changed
1437
+ * on the next pass (AC-14).
1438
+ */
1439
+ function pushMain(ctx, io) {
1440
+ try {
1441
+ return io.call('git', ['push', 'origin', 'main'], { cwd: ctx.repo });
1442
+ }
1443
+ catch (err) {
1444
+ if (!(err instanceof RateLimited))
1445
+ throw err;
1446
+ return { status: 1, stdout: '', stderr: err.message };
1447
+ }
1448
+ }
1449
+ /**
1450
+ * After a close-out has committed on main: run the item's retrospective, or stop tracking it
1451
+ * as before (AC-1, AC-2, AC-5, AC-13, design D1, D2). With no marker there is nothing to run.
1452
+ * A session-limit wait or a used-up cap launches nothing and keeps the marker. Otherwise the
1453
+ * snapshot is taken and the agent launched in the primary checkout; the item moves to
1454
+ * `retrospective`, which holds the merge lane until it ends.
1455
+ */
1456
+ function afterClose(ctx, io, state, item, budget) {
1457
+ const markerText = ctx.fs.read(retroMarker(ctx.paths, item.name));
1458
+ // A dry run ran no transition, so it cannot know whether one would leave a marker: it
1459
+ // says the launch either way (AC-5).
1460
+ if (markerText === null && !ctx.dryRun) {
1461
+ drop(state, item, budget);
1462
+ return;
1463
+ }
1464
+ const skip = (why) => {
1465
+ tell(ctx, item, `retrospective not run — ${why}; ${MARKER_STAYS}`);
1466
+ drop(state, item, budget);
1467
+ };
1468
+ const blocked = launchBlocked(state, ctx.now());
1469
+ if (blocked !== null)
1470
+ return skip(`waiting for the session limit to reset at ${blocked}`);
1471
+ const used = capUsedUp(ctx, item);
1472
+ if (used !== null)
1473
+ return skip(used);
1474
+ if (ctx.dryRun) {
1475
+ launchAgent(ctx, io, state, item, retroPrompt(item), budget, undefined, 'retro');
1476
+ drop(state, item, budget);
1477
+ return;
1478
+ }
1479
+ const head = io.call('git', ['rev-parse', 'HEAD'], { cwd: ctx.repo });
1480
+ if (head.status !== 0)
1481
+ return skip(`main cannot be read (git rev-parse: ${fail(head)})`);
1482
+ const top = io.call('git', ['rev-parse', '--show-prefix'], { cwd: ctx.repo });
1483
+ if (top.status !== 0)
1484
+ return skip(`main cannot be read (git rev-parse: ${fail(top)})`);
1485
+ const prefix = top.stdout.trim();
1486
+ const now = readRetroNow(ctx, io, prefix, item.name);
1487
+ if ('failed' in now)
1488
+ return skip(`main cannot be read (${now.failed})`);
1489
+ const at = new Date(ctx.now()).toISOString();
1490
+ const snapshot = {
1491
+ name: item.name,
1492
+ at,
1493
+ head: head.stdout.trim(),
1494
+ prefix,
1495
+ marker: markerText ?? '',
1496
+ allowed: now.allowed,
1497
+ dirty: now.dirty,
1498
+ };
1499
+ ctx.fs.write(retroSnapshotPath(ctx.paths, item.name), `${JSON.stringify(snapshot)}\n`);
1500
+ dequeue(state, item);
1501
+ item.step = 'retrospective';
1502
+ item.retro = { at };
1503
+ if (!launchAgent(ctx, io, state, item, retroPrompt(item), budget, undefined, 'retro')) {
1504
+ // Unreachable past the two checks above; the net keeps the item from waiting on nothing.
1505
+ ctx.fs.remove?.(retroSnapshotPath(ctx.paths, item.name));
1506
+ skip('it could not be launched');
1507
+ }
1508
+ }
1509
+ /**
1510
+ * Why the ended retrospective is not a success, or null (AC-12). Success is a known exit
1511
+ * of 0, the marker gone, and for a typed launch the outcome `shipped`. An exit the pass
1512
+ * cannot read — the run restarted while the agent ran — is a failure: the marker is put
1513
+ * back, and a person can still run it from `aidlc autopilot pending`.
1514
+ */
1515
+ function retroFailure(ctx, item) {
1516
+ const launch = item.launch;
1517
+ const end = launch?.end ?? null;
1518
+ if (end?.limit === 'budget') {
1519
+ const spent = item.spent_micro_usd ?? 0;
1520
+ return `stopped at the cost cap — ${launch?.cap_usd === undefined ? `budget reached, spent ${microToUsd(spent)}` : capReached(launch.cap_usd, spent)}`;
1521
+ }
1522
+ if (neverStarted(item))
1523
+ return launchFailure(ctx, item) ?? 'its agent did not start';
1524
+ const exit = isPid(item.pid) ? ctx.exited?.(item.pid) ?? null : null;
1525
+ if (exit === null)
1526
+ return 'how its agent ended cannot be read';
1527
+ if (exit.code !== 0)
1528
+ return exit.code === null ? `its agent ended on signal ${exit.signal ?? 'unknown'}` : `its agent exited ${exit.code}`;
1529
+ if (ctx.fs.exists(retroMarker(ctx.paths, item.name)))
1530
+ return 'it left the retro-pending marker in place';
1531
+ if (launch === undefined)
1532
+ return null;
1533
+ if (end?.outcome == null)
1534
+ return 'it ended with no readable result';
1535
+ if (end.outcome.outcome !== 'shipped') {
1536
+ const reason = firstLine(end.outcome.reason, REASON_MAX);
1537
+ return `it reported ${end.outcome.outcome}${reason === null ? '' : `: ${reason}`}`;
1538
+ }
1539
+ return null;
1540
+ }
1541
+ /**
1542
+ * The retrospective step, each pass (AC-6..AC-16, design D4..D6). While its agent runs it is
1543
+ * held to the 30-minute limit and the cap; once it has ended: its spend, one capture of its
1544
+ * cost, the success check, the limits, then the commit by pathspec and the push.
1545
+ */
1546
+ function advanceRetrospective(ctx, io, state, item, budget) {
1547
+ if (ctx.dryRun) {
1548
+ // A dry run reads nothing back and writes nothing: restoring or committing is a write.
1549
+ ctx.say(`[dry-run] ${item.name}: its retrospective is running — nothing is read or written`);
1550
+ return;
1551
+ }
1552
+ const snap = readSnapshot(ctx, item);
1553
+ const at = item.retro?.at;
1554
+ if (snap === null || at === undefined) {
1555
+ if (isPid(item.pid) && ctx.isAlive(item.pid))
1556
+ return;
1557
+ tell(ctx, item, `retrospective ended, but its launch record is gone — nothing committed or restored; check main with git status`);
1558
+ finishRetro(ctx, state, item, budget);
1559
+ return;
1560
+ }
1561
+ const failed = (why, now) => failRetro(ctx, io, state, item, snap, why, budget, now);
1562
+ if (isPid(item.pid) && ctx.isAlive(item.pid) && ctx.now() - Date.parse(at) >= RETRO_LIMIT_MS) {
1563
+ ctx.kill(item.pid);
1564
+ failed(`still running after ${RETRO_LIMIT_MS / 60_000} minutes`);
1565
+ return;
1566
+ }
1567
+ if (agentRunning(ctx, io, state, item, budget, (reason) => failed(`stopped at the cost cap — ${reason}`)))
1568
+ return;
1569
+ const launch = item.launch;
1570
+ if (neverStarted(item) && launch !== undefined && launch.end === undefined)
1571
+ launch.end = null;
1572
+ // Its tokens and price on the item, so the cap sees them (AC-16).
1573
+ if (launch !== undefined && launch.end === undefined && !endSession(ctx, item, launch))
1574
+ return;
1575
+ const sessionId = launch?.end?.session_id ?? null;
1576
+ if (launch !== undefined && sessionId !== null && item.retro?.captured !== true && ctx.captureSession !== undefined) {
1577
+ // The hook runs detached and may finish after the commit; one capture now leaves it
1578
+ // nothing to append, so the ledger is final before the diff is read (design D5).
1579
+ const r = ctx.captureSession({ provider: launch.harness === 'codex' ? 'codex' : 'claude-code', sessionId, instance: item.name });
1580
+ if (r === 'busy') {
1581
+ record(ctx, item, 'retrospective ended — waiting for its cost to be recorded');
1582
+ return;
1583
+ }
1584
+ item.retro = { at, captured: true };
1585
+ }
1586
+ const why = retroFailure(ctx, item);
1587
+ if (why !== null)
1588
+ return failed(why);
1589
+ const now = readRetroNow(ctx, io, snap.prefix, item.name);
1590
+ if ('failed' in now)
1591
+ return failed(`main cannot be read (${now.failed})`);
1592
+ const changes = retroChanges(snap, now);
1593
+ if (!changes.ok)
1594
+ return failed(changes.why, now);
1595
+ let line = 'retrospective ran and wrote nothing to commit';
1596
+ if (changes.commit.length > 0) {
1597
+ const repo = { cwd: ctx.repo };
1598
+ // `add` first: a pathspec commit of an untracked file fails (design D4).
1599
+ const add = io.call('git', ['add', '--', ...changes.commit], repo);
1600
+ const commit = add.status !== 0 ? add : io.call('git', ['commit', '-q', '-m', `chore(aidlc): retrospective for ${item.name} (autopilot)`, '--', ...changes.commit], repo);
1601
+ if (commit.status !== 0) {
1602
+ io.call('git', ['reset', '-q', '--', ...changes.commit], repo);
1603
+ return failed(`its commit failed: ${fail(commit)}`, now);
1604
+ }
1605
+ const counts = `${changes.lessons} ${changes.lessons === 1 ? 'lesson' : 'lessons'}, ${changes.followUps} ${changes.followUps === 1 ? 'follow-up' : 'follow-ups'}`;
1606
+ const push = pushMain(ctx, io);
1607
+ line =
1608
+ push.status === 0
1609
+ ? `retrospective committed on main and pushed — ${counts}`
1610
+ : `retrospective committed on main (${counts}); the push failed (${fail(push)}) — the next push of main carries it`;
1611
+ }
1612
+ tell(ctx, item, `${line}${leftAloneNote(changes.leftAlone)}`);
1613
+ finishRetro(ctx, state, item, budget);
1614
+ }
1615
+ /**
1616
+ * A failed retrospective (AC-10, design D6): each allowed path it changed goes back to its
1617
+ * text at launch and each inbox file it created is deleted; its cost lines are kept and
1618
+ * committed alone (Q1); the marker is put back; one line says why; the item is dropped.
1619
+ * Never `park` and never `error`, so the merge lane is never halted.
1620
+ */
1621
+ function failRetro(ctx, io, state, item, snap, why, budget, known) {
1622
+ const now = known ?? readRetroNow(ctx, io, snap.prefix, item.name);
1623
+ const { retro, lessons, costs } = retroAllowed(item.name);
1624
+ for (const p of [retro, lessons]) {
1625
+ const before = snap.allowed[p] ?? null;
1626
+ const file = `${ctx.repo}/${p}`;
1627
+ if (ctx.fs.read(file) === before)
1628
+ continue;
1629
+ if (before === null)
1630
+ ctx.fs.remove?.(file);
1631
+ else
1632
+ ctx.fs.write(file, before);
1633
+ }
1634
+ // Unreadable git: the fixed paths are back, but its new inbox files cannot be told apart.
1635
+ const seen = 'failed' in now ? null : retroChanges(snap, now);
1636
+ for (const p of seen?.created ?? [])
1637
+ ctx.fs.remove?.(`${ctx.repo}/${p}`);
1638
+ const leftAlone = [...(seen?.leftAlone ?? [])];
1639
+ let costNote = '';
1640
+ if (ctx.fs.read(`${ctx.repo}/${costs}`) !== (snap.allowed[costs] ?? null)) {
1641
+ if (costs in snap.dirty)
1642
+ leftAlone.push(costs);
1643
+ else
1644
+ costNote = commitRetroCost(ctx, io, item, costs);
1645
+ }
1646
+ const marker = retroMarker(ctx.paths, item.name);
1647
+ if (!ctx.fs.exists(marker))
1648
+ ctx.fs.write(marker, snap.marker);
1649
+ const unread = 'failed' in now ? `; its new inbox files cannot be told apart (${now.failed})` : '';
1650
+ tell(ctx, item, `retrospective failed — ${why}; ${MARKER_STAYS}${costNote}${unread}${leftAloneNote([...new Set(leftAlone)].sort())}`);
1651
+ notice(ctx, 'retrospective failed', `${item.name}: ${why}`);
1652
+ finishRetro(ctx, state, item, budget);
1653
+ }
1654
+ /**
1655
+ * Commit the failed retrospective's cost lines alone and push them: a deleted ledger line
1656
+ * cannot be recovered, a commit can be reverted (design-questions Q1). A failure is named
1657
+ * and changes nothing else.
1658
+ */
1659
+ function commitRetroCost(ctx, io, item, costs) {
1660
+ const repo = { cwd: ctx.repo };
1661
+ const add = io.call('git', ['add', '--', costs], repo);
1662
+ const commit = add.status !== 0
1663
+ ? add
1664
+ : io.call('git', ['commit', '-q', '-m', `chore(aidlc): record the failed retrospective's cost for ${item.name} (autopilot)`, '--', costs], repo);
1665
+ if (commit.status !== 0)
1666
+ return `; its cost lines are not committed (${fail(commit)})`;
1667
+ const push = pushMain(ctx, io);
1668
+ return push.status === 0 ? '; its cost lines are committed on main' : `; its cost lines are committed on main, the push failed (${fail(push)})`;
1669
+ }
1367
1670
  /** Waiting for a person to merge: only their answer moves it (autopilot-stop-controls/AC-19). */
1368
1671
  function advanceAwaitingMerge(ctx, io, state, item, budget) {
1672
+ const view = prView(ctx, io, item);
1369
1673
  // Silent otherwise: a "still waiting" line would repeat every pass.
1370
- answeredByPerson(ctx, io, state, item, prView(ctx, io, item), budget);
1674
+ answeredByPerson(ctx, io, state, item, view, budget);
1371
1675
  }
1372
1676
  /**
1373
1677
  * The branch conflicts with main: hand it back to the agent, twice at most,
@@ -2087,6 +2391,13 @@ function serveQueue(ctx, io, state, budget) {
2087
2391
  state.queue.shift();
2088
2392
  return;
2089
2393
  }
2394
+ // The merge lane is one lane: a retrospective writes on main, so nothing merges or closes
2395
+ // out under it (autopilot-runs-retrospective/AC-3). Recorded, not said: it would repeat every pass.
2396
+ const retro = retroRunning(state);
2397
+ if (retro !== null) {
2398
+ record(ctx, item, `waiting — ${retro.name}'s retrospective is running on main`);
2399
+ return;
2400
+ }
2090
2401
  if (item.step === 'error') {
2091
2402
  // An observation repeated every pass: the failure that halted the queue already notified.
2092
2403
  ctx.say(`queue halted: ${item.name} — ${item.error}`);
@@ -2168,7 +2479,7 @@ function serveQueue(ctx, io, state, budget) {
2168
2479
  const closed = `merged${releases ? ', released' : ''} and closed${closeNote(report)}`;
2169
2480
  tell(ctx, item, closed);
2170
2481
  notice(ctx, releases ? 'item released' : 'item merged', `${item.name}: ${closed}`);
2171
- drop(state, item, budget);
2482
+ afterClose(ctx, io, state, item, budget);
2172
2483
  }
2173
2484
  /**
2174
2485
  * Park an item `aidlc start` failed on. By file, not by instance: a start that failed
@@ -2388,6 +2699,8 @@ export function tick(ctx, state, budget) {
2388
2699
  advancePr(ctx, io, state, item, budget);
2389
2700
  else if (item.step === 'awaiting-merge')
2390
2701
  advanceAwaitingMerge(ctx, io, state, item, budget);
2702
+ else if (item.step === 'retrospective')
2703
+ advanceRetrospective(ctx, io, state, item, budget);
2391
2704
  }
2392
2705
  serveQueue(ctx, io, state, budget);
2393
2706
  startBuilds(ctx, io, state, budget);
@@ -2433,6 +2746,8 @@ function waitingFor(i, host) {
2433
2746
  }
2434
2747
  if (i.step === 'awaiting-merge')
2435
2748
  return ` — waiting for you to merge ${ref(host, i.pr)}`;
2749
+ if (i.step === 'retrospective')
2750
+ return ` — running its retrospective on main since ${i.retro?.at ?? 'its close-out'}; nothing merges meanwhile`;
2436
2751
  return '';
2437
2752
  }
2438
2753
  /** The item's pull request check in words, or '' when it has none (pr-checker-earns-merge/AC-8). */