@kitman-sh/software-engineering 0.10.75 → 0.10.77

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.
package/dist/bundle.js CHANGED
@@ -19039,6 +19039,8 @@ var ask = (name, question) => takeStep(name, "ask", "ask", gen2(function* () {
19039
19039
  return yield* new QuestionRefused({ step: name, answer: fallback, options });
19040
19040
  if (question.auto !== undefined && options !== undefined && !options.includes(question.auto))
19041
19041
  return yield* new QuestionRefused({ step: name, answer: question.auto, options });
19042
+ if (question.unattendedAuto !== undefined && options !== undefined && !options.includes(question.unattendedAuto))
19043
+ return yield* new QuestionRefused({ step: name, answer: question.unattendedAuto, options });
19042
19044
  yield* launch(deferred, (host, token2) => host.putQuestion({
19043
19045
  step: name,
19044
19046
  prompt: question.prompt,
@@ -19046,6 +19048,7 @@ var ask = (name, question) => takeStep(name, "ask", "ask", gen2(function* () {
19046
19048
  ...advice,
19047
19049
  ...fallback === undefined ? undefined : { default: fallback },
19048
19050
  ...question.auto === undefined ? undefined : { auto: question.auto },
19051
+ ...question.unattendedAuto === undefined ? undefined : { unattendedAuto: question.unattendedAuto },
19049
19052
  ...question.timeout === undefined ? undefined : { timeoutMillis: toMillis(fromInputUnsafe2(question.timeout)) },
19050
19053
  token: token2
19051
19054
  }));
@@ -19058,10 +19061,17 @@ var ask = (name, question) => takeStep(name, "ask", "ask", gen2(function* () {
19058
19061
  return yield* new QuestionRefused({ step: name, answer, options });
19059
19062
  return offeredAnswer;
19060
19063
  }));
19061
- var call = (name, loop, input) => takeStep(name, "call", "call", gen2(function* () {
19064
+ var call = (name, loop, input, options) => takeStep(name, "call", "call", gen2(function* () {
19062
19065
  const deferred = childDeferred(name);
19063
19066
  const encoded = yield* toJson2(name, loop.input, input);
19064
- yield* launch(deferred, (host, token2) => host.admitChild({ step: name, loop: loop.id, input: encoded, token: token2 }));
19067
+ const constraints = options?.constraints ?? [];
19068
+ yield* launch(deferred, (host, token2) => host.admitChild({
19069
+ step: name,
19070
+ loop: loop.id,
19071
+ input: encoded,
19072
+ ...constraints.length === 0 ? undefined : { constraints },
19073
+ token: token2
19074
+ }));
19065
19075
  const result = yield* await_2(deferred);
19066
19076
  return yield* decodeEffect2(toCodecJson2(loop.output))(result).pipe(mapError3((error) => new ChildFailed({ step: name, loop: loop.id, reason: error.message })));
19067
19077
  }));
@@ -19177,7 +19187,11 @@ var ArtifactRequest = Struct({
19177
19187
  files: optional2(ArraySchema(RunFile))
19178
19188
  });
19179
19189
  var ArtifactResult = Struct({ artifactId: String5 });
19180
- var NoteRequest = Struct({ text: String5, artifactId: optional2(String5) });
19190
+ var NoteRequest = Struct({
19191
+ text: String5,
19192
+ artifactId: optional2(String5),
19193
+ kind: optional2(Literals(["note", "blocker"]))
19194
+ });
19181
19195
  var CreateTasksRequest = Struct({
19182
19196
  tickets: ArraySchema(PlanTicket),
19183
19197
  projectId: optionalKey2(String5)
@@ -20321,10 +20335,17 @@ var scriptedHost = (script, engine, agentLaunches, childLaunches, waits, verifyL
20321
20335
  ...launch.mergeTarget === undefined ? undefined : { mergeTarget: launch.mergeTarget }
20322
20336
  })), resolve(agentDeferredNamed(launch.deferredName), launch.token, scriptedExit(script.outputs?.[launch.step], (reason) => new StepFailed({ step: launch.step, reason })))),
20323
20337
  putQuestion: (launch) => {
20324
- const answer = script.answers?.[launch.step] ?? (script.fullAuto === true ? launch.auto : undefined) ?? launch.default;
20338
+ const attended = script.attended === true;
20339
+ const auto = script.fullAuto === true ? launch.auto ?? (attended ? undefined : launch.unattendedAuto) : undefined;
20340
+ const answer = script.answers?.[launch.step] ?? auto ?? (attended ? undefined : launch.default);
20325
20341
  return resolve(answerDeferred(launch.step), launch.token, answer === undefined ? fail5(new StepFailed({ step: launch.step, reason: "no answer was scripted" })) : succeed4(answer));
20326
20342
  },
20327
- admitChild: (launch) => andThen2(sync2(() => childLaunches.push({ step: launch.step, loop: launch.loop, input: launch.input })), resolve(childDeferred(launch.step), launch.token, scriptedExit(script.children?.[launch.step], (reason) => new ChildFailed({ step: launch.step, loop: launch.loop, reason })))),
20343
+ admitChild: (launch) => andThen2(sync2(() => childLaunches.push({
20344
+ step: launch.step,
20345
+ loop: launch.loop,
20346
+ input: launch.input,
20347
+ ...launch.constraints === undefined ? undefined : { constraints: launch.constraints }
20348
+ })), resolve(childDeferred(launch.step), launch.token, scriptedExit(script.children?.[launch.step], (reason) => new ChildFailed({ step: launch.step, loop: launch.loop, reason })))),
20328
20349
  awaitEvent: (launch) => {
20329
20350
  const event = script.events?.[launch.step];
20330
20351
  waits.push({
@@ -21399,11 +21420,14 @@ var threadLine = (thread) => [
21399
21420
  ...thread.comments.map((entry) => `${entry.author ?? "someone"}: ${entry.body}`)
21400
21421
  ].join(`
21401
21422
  `);
21402
- var ReviewFix = Struct({ summary: String5 });
21423
+ var ReviewFix = Struct({
21424
+ summary: String5,
21425
+ changed: Boolean3
21426
+ });
21403
21427
  var findingLines2 = (findings) => findings.map((finding) => `- ${finding.id} (${finding.severity}): ${finding.detail}`).join(`
21404
21428
  `);
21405
21429
  var reviewFixPrompt = (reviewed, findings) => [
21406
- `A review of ${reviewed} found these. Fix each blocker and major finding, with a test that shows it where one can. Kitman pushes what you leave.`,
21430
+ `A review of ${reviewed} found these. Fix each blocker and major finding, with a test that shows it where one can. Kitman pushes what you leave; answer changed with whether you left anything.`,
21407
21431
  findingLines2(findings)
21408
21432
  ].join(`
21409
21433
  `);
@@ -21426,7 +21450,7 @@ var repliesPrompt = (threads) => [
21426
21450
  var threadKey = (thread) => `${thread.id}:${thread.comments.length}`;
21427
21451
  var shepherd_default = defineLoop({
21428
21452
  id: "shepherd",
21429
- version: "1.3.0",
21453
+ version: "1.4.0",
21430
21454
  title: "Shepherd",
21431
21455
  input: Input3,
21432
21456
  output: Output3,
@@ -21464,6 +21488,7 @@ var shepherd_default = defineLoop({
21464
21488
  let notCarried;
21465
21489
  let behind = false;
21466
21490
  let pushed;
21491
+ let fixedFrom;
21467
21492
  let turn;
21468
21493
  let turns = 0;
21469
21494
  let passes = 0;
@@ -21523,15 +21548,36 @@ ${open}`,
21523
21548
  allowed[kind]++;
21524
21549
  return answer !== handBackAnswer;
21525
21550
  });
21551
+ const reportSteps = { run: "pipeline-report", rerun: "pipeline-rereport", fix: "pipeline-fix-report" };
21526
21552
  const runOnRunner = (step, cycle, head, checks) => gen2(function* () {
21527
21553
  const verification = `pipeline-${step}:${cycle}`;
21528
- const failed = yield* verify(verification, { revision: head, checks }).pipe(as2(undefined), catchTag2("StepFailed", (error) => succeed7(error.reason)));
21529
- if (failed === undefined)
21530
- yield* reportPipeline(`pipeline-${step === "run" ? "report" : "rereport"}:${cycle}`, {
21531
- changeRequestId,
21532
- verification
21533
- });
21534
- return failed;
21554
+ const ran = yield* verify(verification, {
21555
+ ...head === undefined ? undefined : { revision: head },
21556
+ checks
21557
+ }).pipe(map8((result) => ({ revision: result.revision })), catchTag2("StepFailed", (error) => succeed7({ failed: error.reason })));
21558
+ if ("revision" in ran)
21559
+ yield* reportPipeline(`${reportSteps[step]}:${cycle}`, { changeRequestId, verification });
21560
+ return ran;
21561
+ });
21562
+ const pushedByFix = (cycle, pipeline, changed) => gen2(function* () {
21563
+ if (pipeline.runnerChecks === undefined) {
21564
+ if (!changed)
21565
+ return "nothing";
21566
+ const woke = yield* pipelineMoved(`fix-pushed:${cycle}`, changeRequestId, pipeline, "5 minutes").pipe(catchTag2("WaitTimedOut", () => undefined_2));
21567
+ const head = woke?.payload.head;
21568
+ if (!is2(String5)(head) || head === pipeline.head)
21569
+ return "unknown";
21570
+ pushed = { head, stale: 0, by: "the fix" };
21571
+ return "pushed";
21572
+ }
21573
+ const ran = yield* runOnRunner("fix", cycle, undefined, pipeline.runnerChecks);
21574
+ if ("failed" in ran)
21575
+ return done("needs_you", `The pipeline could not run on the Runner: ${ran.failed}`);
21576
+ if (ran.revision === pipeline.head)
21577
+ return "nothing";
21578
+ ranOnRunner.add(ran.revision);
21579
+ pushed = { head: ran.revision, stale: 0, by: "the fix" };
21580
+ return "pushed";
21535
21581
  });
21536
21582
  const checkTarget = (cycle, pipeline) => gen2(function* () {
21537
21583
  const failing = failingJobs(pipeline);
@@ -21604,7 +21650,7 @@ ${open}`,
21604
21650
  notCarried = `the approval was not carried: ${carried.reason}`;
21605
21651
  }
21606
21652
  if (caught !== undefined) {
21607
- pushed = { head: caught.head, stale: 0 };
21653
+ pushed = { head: caught.head, stale: 0, by: "the catch-up" };
21608
21654
  yield* waitFor(`pushed:${cycle}`, {
21609
21655
  event: "change_request.mergeable",
21610
21656
  filter: { changeRequestId, head: caught.head },
@@ -21631,7 +21677,7 @@ ${open}`,
21631
21677
  repository = pipeline.repository ?? repository;
21632
21678
  if (pushed !== undefined && pipeline.head !== pushed.head) {
21633
21679
  if (++pushed.stale > 5)
21634
- return done("needs_you", `The forge still shows ${pipeline.head}, not ${pushed.head} that the catch-up pushed`);
21680
+ return done("needs_you", `The forge still shows ${pipeline.head}, not ${pushed.head} that ${pushed.by} pushed`);
21635
21681
  yield* waitFor(`pushed-again:${cycle}`, {
21636
21682
  event: "change_request.mergeable",
21637
21683
  filter: { changeRequestId, head: pushed.head },
@@ -21641,13 +21687,29 @@ ${open}`,
21641
21687
  continue;
21642
21688
  }
21643
21689
  pushed = undefined;
21690
+ if (fixedFrom !== undefined && pipeline.head !== fixedFrom.head)
21691
+ fixedFrom = undefined;
21692
+ if (fixedFrom !== undefined) {
21693
+ const found = yield* pushedByFix(cycle, pipeline, fixedFrom.changed);
21694
+ if (found === "unknown") {
21695
+ if (++fixedFrom.looks < 3)
21696
+ continue;
21697
+ return done("needs_you", `The fix from ${fixedFrom.head} left a change, but the forge showed no pipeline on a new head after three looks`);
21698
+ }
21699
+ if (found === "nothing")
21700
+ fixedFrom = undefined;
21701
+ else if (found === "pushed")
21702
+ continue;
21703
+ else
21704
+ return found;
21705
+ }
21644
21706
  if (pipeline.status === "none" && pipeline.runnerChecks !== undefined) {
21645
21707
  if (ranOnRunner.has(pipeline.head))
21646
21708
  return done("needs_you", `The pipeline ran on the Runner at ${pipeline.head}, but no result was recorded`);
21647
21709
  ranOnRunner.add(pipeline.head);
21648
- const failed = yield* runOnRunner("run", cycle, pipeline.head, pipeline.runnerChecks);
21649
- if (failed !== undefined)
21650
- return done("needs_you", `The pipeline could not run on the Runner: ${failed}`);
21710
+ const ran = yield* runOnRunner("run", cycle, pipeline.head, pipeline.runnerChecks);
21711
+ if ("failed" in ran)
21712
+ return done("needs_you", `The pipeline could not run on the Runner: ${ran.failed}`);
21651
21713
  continue;
21652
21714
  }
21653
21715
  if (pipeline.status === "none" || pipeline.status === "running") {
@@ -21702,8 +21764,10 @@ ${open}`,
21702
21764
  output: CiFix,
21703
21765
  timeout: stepBudget
21704
21766
  });
21705
- if (fixed.verdict === "fixed")
21767
+ if (fixed.verdict === "fixed") {
21706
21768
  rounds["ci-fix"]++;
21769
+ fixedFrom = { head: pipeline.head, changed: true, looks: 0 };
21770
+ }
21707
21771
  if (fixed.verdict === "pre_existing") {
21708
21772
  const stopped = yield* waitOutTarget(cycle, pipeline, `the failure is pre-existing on the target branch: ${fixed.summary}`);
21709
21773
  if (stopped !== undefined)
@@ -21717,9 +21781,9 @@ ${open}`,
21717
21781
  if (reranHeads.has(pipeline.head))
21718
21782
  return done("needs_you", `The failing job failed again when run again on the Runner: ${fixed.summary}`);
21719
21783
  reranHeads.add(pipeline.head);
21720
- const failed = yield* runOnRunner("rerun", cycle, pipeline.head, pipeline.runnerChecks);
21721
- if (failed !== undefined)
21722
- return done("needs_you", `The pipeline could not run on the Runner: ${failed}`);
21784
+ const ran = yield* runOnRunner("rerun", cycle, pipeline.head, pipeline.runnerChecks);
21785
+ if ("failed" in ran)
21786
+ return done("needs_you", `The pipeline could not run on the Runner: ${ran.failed}`);
21723
21787
  continue;
21724
21788
  }
21725
21789
  if (reranHeads.has(pipeline.head))
@@ -21790,13 +21854,14 @@ ${open}`,
21790
21854
  if (!(yield* mayFix("head-fix", cycle, blocking.map((finding) => finding.id).join(", "))))
21791
21855
  return handBack(`The review of the catch-up merge's files still finds ${blocking.map((finding) => finding.id).join(", ")} after ${rounds["head-fix"]} head-fix rounds`, findingLines2(blocking));
21792
21856
  rounds["head-fix"]++;
21793
- yield* agentWork(`review-fix:${cycle}`, {
21857
+ const fix = yield* agentWork(`review-fix:${cycle}`, {
21794
21858
  agent: "implementer",
21795
21859
  prompt: reviewFixPrompt("the files the catch-up merge changed", blocking),
21796
21860
  output: ReviewFix,
21797
21861
  timeout: stepBudget
21798
21862
  });
21799
21863
  unreviewed = { ...files, earlier: reviewed.findings };
21864
+ fixedFrom = { head, changed: fix.changed, looks: 0 };
21800
21865
  continue;
21801
21866
  }
21802
21867
  const approval = yield* approveChangeRequest(`approve:${cycle}`, {
@@ -21870,13 +21935,14 @@ ${open}`,
21870
21935
  if (!(yield* mayFix("head-fix", cycle, blocking.map((finding) => finding.id).join(", "))))
21871
21936
  return handBack(`The review of ${head} still finds ${blocking.map((finding) => finding.id).join(", ")} after ${rounds["head-fix"]} head-fix rounds`, findingLines2(blocking));
21872
21937
  rounds["head-fix"]++;
21873
- yield* agentWork(`head-fix:${cycle}`, {
21938
+ const fix = yield* agentWork(`head-fix:${cycle}`, {
21874
21939
  agent: "implementer",
21875
21940
  prompt: reviewFixPrompt(since === undefined ? `the change at ${head}` : `what changed between ${since} and ${head}`, blocking),
21876
21941
  output: ReviewFix,
21877
21942
  timeout: stepBudget
21878
21943
  });
21879
21944
  headFindings = reviewed.findings;
21945
+ fixedFrom = { head, changed: fix.changed, looks: 0 };
21880
21946
  continue;
21881
21947
  }
21882
21948
  headFindings = [];
@@ -22010,7 +22076,8 @@ var BuildInput = Struct({
22010
22076
  maxRounds: optional2(Int),
22011
22077
  continuing: optional2(Continuing),
22012
22078
  land: optional2(Boolean3),
22013
- changeRequestId: optional2(String5)
22079
+ changeRequestId: optional2(String5),
22080
+ maxRebuilds: optional2(Int.check(isGreaterThanOrEqualTo2(0)))
22014
22081
  });
22015
22082
  var CriterionAnswer = Struct({
22016
22083
  criterion: String5,
@@ -22060,6 +22127,11 @@ var BuildOutput = Struct({
22060
22127
  next: Struct({ changeRequestId: String5 })
22061
22128
  });
22062
22129
 
22130
+ class BuildBlocked extends TaggedError3()("BuildBlocked", {
22131
+ message: String5
22132
+ }) {
22133
+ }
22134
+
22063
22135
  class BuildTargetMissing extends TaggedError3()("BuildTargetMissing", {
22064
22136
  message: String5
22065
22137
  }) {
@@ -22135,6 +22207,10 @@ var fixPrompt = (settled) => {
22135
22207
  ].join(`
22136
22208
  `);
22137
22209
  };
22210
+ var takenOverAnswer = "Taken over";
22211
+ var buildAgainAnswer = "Build again";
22212
+ var blockedAnswer = "Mark blocked";
22213
+ var standingConstraint = (item) => `Settle what an earlier Build left standing: ${item}`;
22138
22214
  var blockingIds = (settled) => settled.open.filter(isBlocking).map((finding) => finding.id);
22139
22215
  var onlyChecksBlock = (settled) => blockingIds(settled).every(isCheckFinding) && !settled.standing.some((entry) => isBlocking(entry.finding));
22140
22216
  var rally = (input) => gen2(function* () {
@@ -22207,9 +22283,9 @@ var rally = (input) => gen2(function* () {
22207
22283
  last = { head, settled, scope: reviewed.scope };
22208
22284
  }
22209
22285
  });
22210
- var build_default = defineLoop({
22286
+ var build2 = defineLoop({
22211
22287
  id: "build",
22212
- version: "2.3.0",
22288
+ version: "2.4.0",
22213
22289
  title: "Build",
22214
22290
  input: BuildInput,
22215
22291
  output: BuildOutput,
@@ -22222,7 +22298,7 @@ var build_default = defineLoop({
22222
22298
  { id: "retry", title: "Retry with a steer", loop: "build" }
22223
22299
  ],
22224
22300
  capabilities: ["agent_work", "verify", "change_request", "write_back", "post_comment", "approve_change_request"],
22225
- calls: () => [review_default, shepherd_default],
22301
+ calls: () => [review_default, shepherd_default, build2],
22226
22302
  run: (input) => gen2(function* () {
22227
22303
  if (input.words === undefined && input.taskId === undefined)
22228
22304
  return yield* new BuildTargetMissing({ message: "Give the words to build, or a Task" });
@@ -22304,22 +22380,7 @@ var build_default = defineLoop({
22304
22380
  summary: `Review round ${last.round} passed with nothing blocking.`,
22305
22381
  review: `review:${last.round}`
22306
22382
  }).pipe(catchTag2("StepFailed", (error) => succeed7({ approved: false, reason: error.reason }))) : undefined;
22307
- const landed = input.land !== false && unsettled.length === 0 ? yield* call("land", shepherd_default, {
22308
- changeRequestId: opened.id,
22309
- ...lastNotRun.length === 0 ? undefined : { notRun: lastNotRun },
22310
- ...input.taskId === undefined ? undefined : { taskId: input.taskId },
22311
- ...input.branch === undefined ? undefined : { branch: input.branch }
22312
- }) : undefined;
22313
- if (input.land !== false && unsettled.length > 0)
22314
- yield* ask("unsettled", {
22315
- prompt: `The ChangeRequest ${opened.url} is open, but these still stand: ${unsettled.join("; ")}. Build will not land it.`,
22316
- options: [{ value: "Taken over", description: "A person fixes, rebuts or steers it from here." }],
22317
- recommended: "Taken over",
22318
- recommendationReason: "Build stopped with these unsettled, so the next step is a person\u2019s.",
22319
- default: null
22320
- });
22321
- return {
22322
- changeRequest: opened,
22383
+ let settledAs = {
22323
22384
  revision: last.head.revision,
22324
22385
  tree: last.head.tree,
22325
22386
  settled: unsettled.length === 0,
@@ -22328,12 +22389,78 @@ var build_default = defineLoop({
22328
22389
  stopped: last.decision.reason,
22329
22390
  criteria,
22330
22391
  ...lastNotRun.length === 0 ? undefined : { notRun: lastNotRun },
22331
- ...approval === undefined ? undefined : { approval },
22392
+ ...approval === undefined ? undefined : { approval }
22393
+ };
22394
+ const maxRebuilds = input.maxRebuilds ?? 1;
22395
+ for (let rebuilds = 0;input.land !== false && settledAs.unsettled.length > 0; ) {
22396
+ const standing = settledAs.unsettled;
22397
+ const again = rebuilds < maxRebuilds;
22398
+ const answer = yield* ask(rebuilds === 0 ? "unsettled" : `unsettled:${rebuilds + 1}`, {
22399
+ prompt: `The ChangeRequest ${opened.url} is open, but these still stand: ${standing.join("; ")}. Build will not land it.`,
22400
+ options: [
22401
+ { value: takenOverAnswer, description: "A person fixes, rebuts or steers it from here." },
22402
+ again ? {
22403
+ value: buildAgainAnswer,
22404
+ description: "Starts one more Build on this branch, with each of these as a constraint."
22405
+ } : {
22406
+ value: blockedAnswer,
22407
+ description: "Fails this Build, recording these as a blocker on its Task, and tells its owner."
22408
+ }
22409
+ ],
22410
+ recommended: takenOverAnswer,
22411
+ recommendationReason: "Build stopped with these unsettled, so the next step is a person\u2019s.",
22412
+ default: null,
22413
+ unattendedAuto: again ? buildAgainAnswer : blockedAnswer
22414
+ });
22415
+ if (answer === takenOverAnswer)
22416
+ break;
22417
+ if (answer === blockedAnswer) {
22418
+ if (input.taskId !== undefined)
22419
+ yield* note("blocked", {
22420
+ kind: "blocker",
22421
+ text: [
22422
+ `Build stopped without landing ${opened.url}, marked blocked on what still stands:`,
22423
+ "",
22424
+ ...standing.map((item) => `- ${item}`)
22425
+ ].join(`
22426
+ `)
22427
+ });
22428
+ return yield* new BuildBlocked({
22429
+ message: `The ChangeRequest ${opened.url} is open, and Build was marked blocked on what still stands: ${standing.join("; ")}`
22430
+ });
22431
+ }
22432
+ rebuilds++;
22433
+ const {
22434
+ changeRequest: _,
22435
+ landed: __,
22436
+ next: ___,
22437
+ ...rebuilt
22438
+ } = yield* call(`rebuild:${rebuilds}`, { id: "build", input: BuildInput, output: BuildOutput }, {
22439
+ ...input.words === undefined ? undefined : { words: input.words },
22440
+ ...input.taskId === undefined ? undefined : { taskId: input.taskId },
22441
+ ...input.repoBindingId === undefined ? undefined : { repoBindingId: input.repoBindingId },
22442
+ ...input.outcome === undefined ? undefined : { outcome: input.outcome },
22443
+ ...input.maxRounds === undefined ? undefined : { maxRounds: input.maxRounds },
22444
+ changeRequestId: opened.id,
22445
+ land: false
22446
+ }, { constraints: standing.map(standingConstraint) });
22447
+ settledAs = rebuilt;
22448
+ }
22449
+ const landed = input.land !== false && settledAs.unsettled.length === 0 ? yield* call("land", shepherd_default, {
22450
+ changeRequestId: opened.id,
22451
+ ...settledAs.notRun === undefined ? undefined : { notRun: settledAs.notRun },
22452
+ ...input.taskId === undefined ? undefined : { taskId: input.taskId },
22453
+ ...input.branch === undefined ? undefined : { branch: input.branch }
22454
+ }) : undefined;
22455
+ return {
22456
+ changeRequest: opened,
22457
+ ...settledAs,
22332
22458
  ...landed === undefined ? undefined : { landed },
22333
22459
  next: { changeRequestId: opened.id }
22334
22460
  };
22335
22461
  }).pipe(tapError2(() => ignore2(writeBack("write-back:failed", { milestone: "failed" }))))
22336
22462
  });
22463
+ var build_default = build2;
22337
22464
 
22338
22465
  // src/errand.ts
22339
22466
  var Input4 = Struct({
@@ -26880,6 +27007,7 @@ class RunnerCapabilityRpcs extends make30(make29("PutQuestion", {
26880
27007
  verification: optional2(SuggestedVerification),
26881
27008
  default: optional2(String5),
26882
27009
  auto: optional2(String5),
27010
+ unattendedAuto: optional2(String5),
26883
27011
  timeoutMillis: optional2(Finite),
26884
27012
  deferredName: String5
26885
27013
  },
@@ -26950,6 +27078,7 @@ class RunnerCapabilityRpcs extends make30(make29("PutQuestion", {
26950
27078
  step: String5,
26951
27079
  loop: String5,
26952
27080
  input: Json2,
27081
+ constraints: optional2(ArraySchema(String5)),
26953
27082
  deferredName: String5
26954
27083
  },
26955
27084
  success: Struct({ runId: String5 }),
@@ -26971,7 +27100,8 @@ class RunnerCapabilityRpcs extends make30(make29("PutQuestion", {
26971
27100
  lease: ProgramLease,
26972
27101
  step: String5,
26973
27102
  text: String5,
26974
- artifactId: optional2(String5)
27103
+ artifactId: optional2(String5),
27104
+ kind: optional2(Literals(["note", "blocker"]))
26975
27105
  },
26976
27106
  error: RunnerRpcError
26977
27107
  }), make29("PerformHostEffect", {
@@ -27405,6 +27535,7 @@ var runnerHost = (capabilities) => ({
27405
27535
  ...launch.verification === undefined ? undefined : { verification: launch.verification },
27406
27536
  ...launch.default === undefined ? undefined : { default: launch.default },
27407
27537
  ...launch.auto === undefined ? undefined : { auto: launch.auto },
27538
+ ...launch.unattendedAuto === undefined ? undefined : { unattendedAuto: launch.unattendedAuto },
27408
27539
  ...launch.timeoutMillis === undefined ? undefined : { timeoutMillis: launch.timeoutMillis }
27409
27540
  })).pipe(asVoid2),
27410
27541
  startVerification: (launch) => requested(launch.step, capabilities.startVerification({
@@ -27432,6 +27563,7 @@ var runnerHost = (capabilities) => ({
27432
27563
  step: launch.step,
27433
27564
  loop: launch.loop,
27434
27565
  input: launch.input,
27566
+ ...launch.constraints === undefined ? undefined : { constraints: launch.constraints },
27435
27567
  deferredName: childDeferred(launch.step).name
27436
27568
  })).pipe(asVoid2),
27437
27569
  claimResource: (launch) => requested(launch.step, capabilities.claimResource({
@@ -27628,6 +27760,7 @@ var rpcProgramPorts = (rpc, work) => {
27628
27760
  ...question.verification === undefined ? undefined : { verification: question.verification },
27629
27761
  ...question.default === undefined ? undefined : { default: question.default },
27630
27762
  ...question.auto === undefined ? undefined : { auto: question.auto },
27763
+ ...question.unattendedAuto === undefined ? undefined : { unattendedAuto: question.unattendedAuto },
27631
27764
  ...question.timeoutMillis === undefined ? undefined : { timeoutMillis: question.timeoutMillis }
27632
27765
  }),
27633
27766
  startVerification: (verification) => rpc.startVerification({
@@ -27643,7 +27776,11 @@ var rpcProgramPorts = (rpc, work) => {
27643
27776
  startAgentStep: ({ secrets, ...step }) => rpc.startAgentStep({ lease, ...step, ...secrets === undefined ? undefined : { secrets: [...secrets] } }),
27644
27777
  awaitEvent: (wait) => rpc.awaitEvent({ lease, ...wait }),
27645
27778
  claimResource: (claim) => rpc.claimResource({ lease, ...claim }),
27646
- admitChild: (child) => rpc.admitChild({ lease, ...child }),
27779
+ admitChild: ({ constraints, ...child }) => rpc.admitChild({
27780
+ lease,
27781
+ ...child,
27782
+ ...constraints === undefined ? undefined : { constraints: [...constraints] }
27783
+ }),
27647
27784
  storeArtifact: ({ fileIds, ...artifact }) => rpc.storeArtifact({ lease, ...artifact, ...fileIds === undefined ? undefined : { fileIds: [...fileIds] } }),
27648
27785
  ...rpcRunFiles(rpc, lease),
27649
27786
  recordNote: (note) => rpc.recordNote({ lease, ...note }),
@@ -29930,4 +30067,4 @@ var runKit = (config, identity, packages) => {
29930
30067
  runMain2(program.pipe(flatMap3((code) => sync2(() => process.exit(code)))));
29931
30068
  };
29932
30069
  // .kitman-build-entry.ts
29933
- runKit(kitman_config_default, { name: "@kitman-sh/software-engineering", version: "0.10.75" }, []);
30070
+ runKit(kitman_config_default, { name: "@kitman-sh/software-engineering", version: "0.10.77" }, []);
@@ -3,7 +3,7 @@
3
3
  {
4
4
  "id": "build",
5
5
  "title": "Build",
6
- "version": "2.3.0",
6
+ "version": "2.4.0",
7
7
  "input": {
8
8
  "type": "object",
9
9
  "properties": {
@@ -182,6 +182,18 @@
182
182
  "type": "null"
183
183
  }
184
184
  ]
185
+ },
186
+ "maxRebuilds": {
187
+ "anyOf": [
188
+ {
189
+ "type": "integer",
190
+ "minimum": 0,
191
+ "maximum": 9007199254740991
192
+ },
193
+ {
194
+ "type": "null"
195
+ }
196
+ ]
185
197
  }
186
198
  },
187
199
  "additionalProperties": true,
@@ -2588,7 +2600,7 @@
2588
2600
  {
2589
2601
  "id": "shepherd",
2590
2602
  "title": "Shepherd",
2591
- "version": "1.3.0",
2603
+ "version": "1.4.0",
2592
2604
  "input": {
2593
2605
  "type": "object",
2594
2606
  "properties": {
@@ -3371,7 +3383,7 @@
3371
3383
  "carried": [
3372
3384
  {
3373
3385
  "name": "@kitman-sh/software-engineering",
3374
- "version": "0.10.75",
3386
+ "version": "0.10.77",
3375
3387
  "setup": "2a237548a69b0cd53ec3be7f687cfa8c2128335b3a655d34e185f2abce6a3c37",
3376
3388
  "loops": [
3377
3389
  "build",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitman-sh/software-engineering",
3
- "version": "0.10.75",
3
+ "version": "0.10.77",
4
4
  "description": "Everything for building software: Loops, their Agents, the skills they use and the Ponytail plugin.",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",
@@ -17,12 +17,12 @@
17
17
  "tsconfig.json"
18
18
  ],
19
19
  "dependencies": {
20
- "@kitman-sh/sdk": "0.10.75",
20
+ "@kitman-sh/sdk": "0.10.77",
21
21
  "effect": "4.1.2"
22
22
  },
23
23
  "kitman": {
24
24
  "bundle": "dist/bundle.js",
25
- "digest": "b729a9de3543699451e51f1aa414871ea52b1d94c1bd8523aad1d65cfbaecafd",
25
+ "digest": "8ef24b6204d3b3602670c240f18dd0039f956ab84137ec2db22a97bf7ca0270e",
26
26
  "protocolVersion": 5,
27
27
  "declarations": "dist/declarations.json",
28
28
  "setup": {
package/src/build.ts CHANGED
@@ -18,6 +18,7 @@ import {
18
18
  failsOn,
19
19
  isBlocking,
20
20
  LoopOutcome,
21
+ note,
21
22
  rallyStop,
22
23
  Rebuttal,
23
24
  settleRound,
@@ -65,7 +66,12 @@ export const BuildInput = Schema.Struct({
65
66
  * An open ChangeRequest to fix forward on: the Run works its branch, never force-pushing, and reports in one comment
66
67
  * on it, leaving the ChangeRequest's title and description to its author.
67
68
  */
68
- changeRequestId: Schema.optional(Schema.String)
69
+ changeRequestId: Schema.optional(Schema.String),
70
+ /**
71
+ * How many more Builds an unattended full-auto Run starts on its ChangeRequest while review findings still stand,
72
+ * before it fails with them; 1 when left out.
73
+ */
74
+ maxRebuilds: Schema.optional(Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)))
69
75
  })
70
76
 
71
77
  /** The implementer's answer to one acceptance criterion of the Task. */
@@ -139,6 +145,11 @@ export const BuildOutput = Schema.Struct({
139
145
  next: Schema.Struct({ changeRequestId: Schema.String })
140
146
  })
141
147
 
148
+ /** Build was marked blocked on findings that still stand, so the Task waits on its owner. */
149
+ export class BuildBlocked extends Schema.TaggedError<BuildBlocked>()('BuildBlocked', {
150
+ message: Schema.String
151
+ }) {}
152
+
142
153
  export class BuildTargetMissing extends Schema.TaggedError<BuildTargetMissing>()('BuildTargetMissing', {
143
154
  message: Schema.String
144
155
  }) {}
@@ -235,6 +246,14 @@ const fixPrompt = (settled: SettledRound) => {
235
246
  ].join('\n')
236
247
  }
237
248
 
249
+ const takenOverAnswer = 'Taken over'
250
+
251
+ const buildAgainAnswer = 'Build again'
252
+
253
+ const blockedAnswer = 'Mark blocked'
254
+
255
+ const standingConstraint = (item: string) => `Settle what an earlier Build left standing: ${item}`
256
+
238
257
  const blockingIds = (settled: SettledRound) => settled.open.filter(isBlocking).map(finding => finding.id)
239
258
 
240
259
  const onlyChecksBlock = (settled: SettledRound) =>
@@ -369,11 +388,12 @@ const rally = (input: {
369
388
  /**
370
389
  * Implements a Task or words, reviews and fixes until the rally stops, gates on the evidence for the head, and opens
371
390
  * the Run's ChangeRequest with the evidence, the claims and whatever it could not settle (ADR-0051). It writes the
372
- * Run's milestones to its Task: started, ChangeRequest opened, and failed.
391
+ * Run's milestones to its Task: started, ChangeRequest opened, and failed. Findings that still stand once full auto's
392
+ * rebuilds run out go on the Task as a blocker before the Run fails.
373
393
  */
374
- export default defineLoop({
394
+ const build = defineLoop({
375
395
  id: 'build',
376
- version: '2.3.0',
396
+ version: '2.4.0',
377
397
  title: 'Build',
378
398
  input: BuildInput,
379
399
  output: BuildOutput,
@@ -386,7 +406,7 @@ export default defineLoop({
386
406
  { id: 'retry', title: 'Retry with a steer', loop: 'build' }
387
407
  ],
388
408
  capabilities: ['agent_work', 'verify', 'change_request', 'write_back', 'post_comment', 'approve_change_request'],
389
- calls: (): readonly CalledLoop[] => [review, shepherd],
409
+ calls: (): readonly CalledLoop[] => [review, shepherd, build],
390
410
  run: input =>
391
411
  Effect.gen(function* () {
392
412
  if (input.words === undefined && input.taskId === undefined)
@@ -524,40 +544,107 @@ export default defineLoop({
524
544
  )
525
545
  : undefined
526
546
 
527
- // A blocking Review, or anything else left unsettled, stops here with the findings for a person, not in Shepherd.
547
+ let settledAs: Omit<typeof BuildOutput.Type, 'changeRequest' | 'landed' | 'next'> = {
548
+ revision: last.head.revision,
549
+ tree: last.head.tree,
550
+ settled: unsettled.length === 0,
551
+ unsettled,
552
+ rounds: last.round,
553
+ stopped: last.decision.reason,
554
+ criteria,
555
+ ...(lastNotRun.length === 0 ? undefined : { notRun: lastNotRun }),
556
+ ...(approval === undefined ? undefined : { approval })
557
+ }
558
+
559
+ const maxRebuilds = input.maxRebuilds ?? 1
560
+
561
+ // Anything left unsettled stops here with the findings for a person, not in Shepherd. Full auto builds again on
562
+ // the same branch up to the cap, then fails with them rather than wait on a Question nobody answers.
563
+ for (let rebuilds = 0; input.land !== false && settledAs.unsettled.length > 0;) {
564
+ const standing = settledAs.unsettled
565
+ const again = rebuilds < maxRebuilds
566
+
567
+ const answer = yield* ask(rebuilds === 0 ? 'unsettled' : `unsettled:${rebuilds + 1}`, {
568
+ prompt: `The ChangeRequest ${opened.url} is open, but these still stand: ${standing.join('; ')}. Build will not land it.`,
569
+ options: [
570
+ { value: takenOverAnswer, description: 'A person fixes, rebuts or steers it from here.' },
571
+ again
572
+ ? {
573
+ value: buildAgainAnswer,
574
+ description: 'Starts one more Build on this branch, with each of these as a constraint.'
575
+ }
576
+ : {
577
+ value: blockedAnswer,
578
+ description: 'Fails this Build, recording these as a blocker on its Task, and tells its owner.'
579
+ }
580
+ ],
581
+ recommended: takenOverAnswer,
582
+ recommendationReason: 'Build stopped with these unsettled, so the next step is a person’s.',
583
+ // No default: an unattended Run would take it at once even in a gated Team, and finish as partial.
584
+ default: null,
585
+ unattendedAuto: again ? buildAgainAnswer : blockedAnswer
586
+ })
587
+
588
+ if (answer === takenOverAnswer) break
589
+
590
+ if (answer === blockedAnswer) {
591
+ if (input.taskId !== undefined)
592
+ yield* note('blocked', {
593
+ kind: 'blocker',
594
+ text: [
595
+ `Build stopped without landing ${opened.url}, marked blocked on what still stands:`,
596
+ '',
597
+ ...standing.map(item => `- ${item}`)
598
+ ].join('\n')
599
+ })
600
+
601
+ return yield* new BuildBlocked({
602
+ message: `The ChangeRequest ${opened.url} is open, and Build was marked blocked on what still stands: ${standing.join('; ')}`
603
+ })
604
+ }
605
+
606
+ rebuilds++
607
+
608
+ const {
609
+ changeRequest: _,
610
+ landed: __,
611
+ next: ___,
612
+ ...rebuilt
613
+ } = yield* call(
614
+ `rebuild:${rebuilds}`,
615
+ { id: 'build', input: BuildInput, output: BuildOutput },
616
+ {
617
+ ...(input.words === undefined ? undefined : { words: input.words }),
618
+ ...(input.taskId === undefined ? undefined : { taskId: input.taskId }),
619
+ ...(input.repoBindingId === undefined ? undefined : { repoBindingId: input.repoBindingId }),
620
+ ...(input.outcome === undefined ? undefined : { outcome: input.outcome }),
621
+ ...(input.maxRounds === undefined ? undefined : { maxRounds: input.maxRounds }),
622
+ changeRequestId: opened.id,
623
+ land: false
624
+ },
625
+ { constraints: standing.map(standingConstraint) }
626
+ )
627
+
628
+ settledAs = rebuilt
629
+ }
630
+
528
631
  const landed =
529
- input.land !== false && unsettled.length === 0
632
+ input.land !== false && settledAs.unsettled.length === 0
530
633
  ? yield* call('land', shepherd, {
531
634
  changeRequestId: opened.id,
532
- ...(lastNotRun.length === 0 ? undefined : { notRun: lastNotRun }),
635
+ ...(settledAs.notRun === undefined ? undefined : { notRun: settledAs.notRun }),
533
636
  ...(input.taskId === undefined ? undefined : { taskId: input.taskId }),
534
637
  ...(input.branch === undefined ? undefined : { branch: input.branch })
535
638
  })
536
639
  : undefined
537
640
 
538
- if (input.land !== false && unsettled.length > 0)
539
- yield* ask('unsettled', {
540
- prompt: `The ChangeRequest ${opened.url} is open, but these still stand: ${unsettled.join('; ')}. Build will not land it.`,
541
- options: [{ value: 'Taken over', description: 'A person fixes, rebuts or steers it from here.' }],
542
- recommended: 'Taken over',
543
- recommendationReason: 'Build stopped with these unsettled, so the next step is a person’s.',
544
- // No default: an unattended Run, as full auto starts, would take it at once and finish as partial.
545
- default: null
546
- })
547
-
548
641
  return {
549
642
  changeRequest: opened,
550
- revision: last.head.revision,
551
- tree: last.head.tree,
552
- settled: unsettled.length === 0,
553
- unsettled,
554
- rounds: last.round,
555
- stopped: last.decision.reason,
556
- criteria,
557
- ...(lastNotRun.length === 0 ? undefined : { notRun: lastNotRun }),
558
- ...(approval === undefined ? undefined : { approval }),
643
+ ...settledAs,
559
644
  ...(landed === undefined ? undefined : { landed }),
560
645
  next: { changeRequestId: opened.id }
561
646
  }
562
647
  }).pipe(Effect.tapError(() => Effect.ignore(writeBack('write-back:failed', { milestone: 'failed' }))))
563
648
  })
649
+
650
+ export default build
package/src/shepherd.ts CHANGED
@@ -141,14 +141,18 @@ const threadLine = (thread: ReviewThreads['threads'][number]) =>
141
141
  ...thread.comments.map(entry => `${entry.author ?? 'someone'}: ${entry.body}`)
142
142
  ].join('\n')
143
143
 
144
- const ReviewFix = Schema.Struct({ summary: Schema.String })
144
+ const ReviewFix = Schema.Struct({
145
+ summary: Schema.String,
146
+ /** Whether it left a change for Kitman to push. */
147
+ changed: Schema.Boolean
148
+ })
145
149
 
146
150
  const findingLines = (findings: readonly MergedFinding[]) =>
147
151
  findings.map(finding => `- ${finding.id} (${finding.severity}): ${finding.detail}`).join('\n')
148
152
 
149
153
  const reviewFixPrompt = (reviewed: string, findings: readonly MergedFinding[]) =>
150
154
  [
151
- `A review of ${reviewed} found these. Fix each blocker and major finding, with a test that shows it where one can. Kitman pushes what you leave.`,
155
+ `A review of ${reviewed} found these. Fix each blocker and major finding, with a test that shows it where one can. Kitman pushes what you leave; answer changed with whether you left anything.`,
152
156
  findingLines(findings)
153
157
  ].join('\n')
154
158
 
@@ -189,12 +193,13 @@ const threadKey = (thread: ReviewThreads['threads'][number]) => `${thread.id}:${
189
193
  * each new review thread on the thread, merges the target branch in when it is behind, and merges once approved, green
190
194
  * and mergeable when told to or when a person says so. It merges the target in and merges only while it holds the
191
195
  * target's turn, so ChangeRequests for one target land one at a time, in order. A head nobody approved gets a review
192
- * of what changed since the last approved head. It runs one ci-fix and two head-fix rounds, then hands the
193
- * ChangeRequest back to Build, and stops as needs you, with why, instead of spinning.
196
+ * of what changed since the last approved head. It runs one ci-fix and two head-fix rounds, each judged by the
197
+ * pipeline at the head the last fix pushed, then hands the ChangeRequest back to Build, and stops as needs you, with
198
+ * why, instead of spinning.
194
199
  */
195
200
  export default defineLoop({
196
201
  id: 'shepherd',
197
- version: '1.3.0',
202
+ version: '1.4.0',
198
203
  title: 'Shepherd',
199
204
  input: Input,
200
205
  output: Output,
@@ -249,8 +254,14 @@ export default defineLoop({
249
254
  let notCarried: string | undefined
250
255
  // The last merge did not go in as the ChangeRequest is: its target moved on, or it conflicts.
251
256
  let behind = false
252
- /** The head a catch-up merge pushed, until the forge shows it, and how many reads showed another. */
253
- let pushed: { readonly head: string; stale: number } | undefined
257
+ /** The head a catch-up merge or a fix pushed, until the forge shows it, how many reads showed another, and who pushed it. */
258
+ let pushed: { readonly head: string; stale: number; readonly by: string } | undefined
259
+
260
+ /**
261
+ * The head the last fix round started from, until a read shows another or the round is known to have pushed
262
+ * nothing; whether the round says it left a change, and how many looks found no pipeline on its push.
263
+ */
264
+ let fixedFrom: { readonly head: string; readonly changed: boolean; looks: number } | undefined
254
265
 
255
266
  /** The target's turn: held from the sync before the merge until the merge, so one ChangeRequest merges at a time. */
256
267
  let turn: Claim | undefined
@@ -337,23 +348,66 @@ export default defineLoop({
337
348
  return answer !== handBackAnswer
338
349
  })
339
350
 
340
- /** Runs the repository's pipeline on a Runner at `head` and reports it; the reason when it could not run. */
341
- const runOnRunner = (step: 'run' | 'rerun', cycle: number, head: string, checks: readonly string[]) =>
351
+ const reportSteps = { run: 'pipeline-report', rerun: 'pipeline-rereport', fix: 'pipeline-fix-report' } as const
352
+
353
+ /**
354
+ * Runs the repository's pipeline on a Runner at `head`, the Run's own head when left out, and reports it: the
355
+ * revision it ran at, or the reason it could not run.
356
+ */
357
+ const runOnRunner = (
358
+ step: keyof typeof reportSteps,
359
+ cycle: number,
360
+ head: string | undefined,
361
+ checks: readonly string[]
362
+ ) =>
342
363
  Effect.gen(function* () {
343
364
  const verification = `pipeline-${step}:${cycle}`
344
365
 
345
- const failed = yield* verify(verification, { revision: head, checks }).pipe(
346
- Effect.as(undefined),
347
- Effect.catchTag('StepFailed', error => Effect.succeed(error.reason))
366
+ const ran = yield* verify(verification, {
367
+ ...(head === undefined ? undefined : { revision: head }),
368
+ checks
369
+ }).pipe(
370
+ Effect.map(result => ({ revision: result.revision })),
371
+ Effect.catchTag('StepFailed', error => Effect.succeed({ failed: error.reason }))
348
372
  )
349
373
 
350
- if (failed === undefined)
351
- yield* reportPipeline(`pipeline-${step === 'run' ? 'report' : 'rereport'}:${cycle}`, {
352
- changeRequestId,
353
- verification
354
- })
374
+ if ('revision' in ran) yield* reportPipeline(`${reportSteps[step]}:${cycle}`, { changeRequestId, verification })
375
+
376
+ return ran
377
+ })
378
+
379
+ /**
380
+ * What the last fix round pushed from `pipeline`, the head it started from, which the forge can show for a while
381
+ * after the push: on a Runner it runs the pipeline at the Run's own head, which is what the round pushed; otherwise
382
+ * the head of the forge's next pipeline says, and a round that left a change but has no such pipeline yet is
383
+ * `unknown`. The Output to stop with, when the pipeline cannot run.
384
+ */
385
+ const pushedByFix = (cycle: number, pipeline: PipelineStatus, changed: boolean) =>
386
+ Effect.gen(function* () {
387
+ if (pipeline.runnerChecks === undefined) {
388
+ if (!changed) return 'nothing' as const
389
+
390
+ const woke = yield* pipelineMoved(`fix-pushed:${cycle}`, changeRequestId, pipeline, '5 minutes').pipe(
391
+ Effect.catchTag('WaitTimedOut', () => Effect.undefined)
392
+ )
393
+
394
+ const head = woke?.payload.head
355
395
 
356
- return failed
396
+ if (!Schema.is(Schema.String)(head) || head === pipeline.head) return 'unknown' as const
397
+ pushed = { head, stale: 0, by: 'the fix' }
398
+
399
+ return 'pushed' as const
400
+ }
401
+
402
+ const ran = yield* runOnRunner('fix', cycle, undefined, pipeline.runnerChecks)
403
+
404
+ if ('failed' in ran) return done('needs_you', `The pipeline could not run on the Runner: ${ran.failed}`)
405
+
406
+ if (ran.revision === pipeline.head) return 'nothing' as const
407
+ ranOnRunner.add(ran.revision)
408
+ pushed = { head: ran.revision, stale: 0, by: 'the fix' }
409
+
410
+ return 'pushed' as const
357
411
  })
358
412
 
359
413
  /**
@@ -469,7 +523,7 @@ export default defineLoop({
469
523
 
470
524
  // The forge can show the old head for a moment after the push; the next look reads it once it shows this one.
471
525
  if (caught !== undefined) {
472
- pushed = { head: caught.head, stale: 0 }
526
+ pushed = { head: caught.head, stale: 0, by: 'the catch-up' }
473
527
 
474
528
  yield* waitFor(`pushed:${cycle}`, {
475
529
  event: 'change_request.mergeable',
@@ -506,7 +560,7 @@ export default defineLoop({
506
560
  if (++pushed.stale > 5)
507
561
  return done(
508
562
  'needs_you',
509
- `The forge still shows ${pipeline.head}, not ${pushed.head} that the catch-up pushed`
563
+ `The forge still shows ${pipeline.head}, not ${pushed.head} that ${pushed.by} pushed`
510
564
  )
511
565
 
512
566
  // Only an Event since this read settles it, so the one that settled the last wait does not end it at once.
@@ -522,15 +576,35 @@ export default defineLoop({
522
576
 
523
577
  pushed = undefined
524
578
 
579
+ // The round limit judges only the pipeline at the head the last fix left, so a push the read misses goes first.
580
+ if (fixedFrom !== undefined && pipeline.head !== fixedFrom.head) fixedFrom = undefined
581
+
582
+ if (fixedFrom !== undefined) {
583
+ const found = yield* pushedByFix(cycle, pipeline, fixedFrom.changed)
584
+
585
+ if (found === 'unknown') {
586
+ if (++fixedFrom.looks < 3) continue
587
+
588
+ return done(
589
+ 'needs_you',
590
+ `The fix from ${fixedFrom.head} left a change, but the forge showed no pipeline on a new head after three looks`
591
+ )
592
+ }
593
+
594
+ if (found === 'nothing') fixedFrom = undefined
595
+ else if (found === 'pushed') continue
596
+ else return found
597
+ }
598
+
525
599
  // The forge runs no pipeline for this repository: its pipeline runs on a Runner and is reported to Kitman.
526
600
  if (pipeline.status === 'none' && pipeline.runnerChecks !== undefined) {
527
601
  if (ranOnRunner.has(pipeline.head))
528
602
  return done('needs_you', `The pipeline ran on the Runner at ${pipeline.head}, but no result was recorded`)
529
603
  ranOnRunner.add(pipeline.head)
530
604
 
531
- const failed = yield* runOnRunner('run', cycle, pipeline.head, pipeline.runnerChecks)
605
+ const ran = yield* runOnRunner('run', cycle, pipeline.head, pipeline.runnerChecks)
532
606
 
533
- if (failed !== undefined) return done('needs_you', `The pipeline could not run on the Runner: ${failed}`)
607
+ if ('failed' in ran) return done('needs_you', `The pipeline could not run on the Runner: ${ran.failed}`)
534
608
 
535
609
  continue
536
610
  }
@@ -617,7 +691,10 @@ export default defineLoop({
617
691
  })
618
692
 
619
693
  // Only a round that fixed something counts: one that found the target's failure or a flake changed nothing.
620
- if (fixed.verdict === 'fixed') rounds['ci-fix']++
694
+ if (fixed.verdict === 'fixed') {
695
+ rounds['ci-fix']++
696
+ fixedFrom = { head: pipeline.head, changed: true, looks: 0 }
697
+ }
621
698
 
622
699
  if (fixed.verdict === 'pre_existing') {
623
700
  const stopped = yield* waitOutTarget(
@@ -641,9 +718,9 @@ export default defineLoop({
641
718
  return done('needs_you', `The failing job failed again when run again on the Runner: ${fixed.summary}`)
642
719
  reranHeads.add(pipeline.head)
643
720
 
644
- const failed = yield* runOnRunner('rerun', cycle, pipeline.head, pipeline.runnerChecks)
721
+ const ran = yield* runOnRunner('rerun', cycle, pipeline.head, pipeline.runnerChecks)
645
722
 
646
- if (failed !== undefined) return done('needs_you', `The pipeline could not run on the Runner: ${failed}`)
723
+ if ('failed' in ran) return done('needs_you', `The pipeline could not run on the Runner: ${ran.failed}`)
647
724
 
648
725
  continue
649
726
  }
@@ -743,13 +820,15 @@ export default defineLoop({
743
820
  )
744
821
  rounds['head-fix']++
745
822
 
746
- yield* agentWork(`review-fix:${cycle}`, {
823
+ const fix = yield* agentWork(`review-fix:${cycle}`, {
747
824
  agent: 'implementer',
748
825
  prompt: reviewFixPrompt('the files the catch-up merge changed', blocking),
749
826
  output: ReviewFix,
750
827
  timeout: stepBudget
751
828
  })
829
+
752
830
  unreviewed = { ...files, earlier: reviewed.findings }
831
+ fixedFrom = { head, changed: fix.changed, looks: 0 }
753
832
 
754
833
  continue
755
834
  }
@@ -869,7 +948,7 @@ export default defineLoop({
869
948
  )
870
949
  rounds['head-fix']++
871
950
 
872
- yield* agentWork(`head-fix:${cycle}`, {
951
+ const fix = yield* agentWork(`head-fix:${cycle}`, {
873
952
  agent: 'implementer',
874
953
  prompt: reviewFixPrompt(
875
954
  since === undefined ? `the change at ${head}` : `what changed between ${since} and ${head}`,
@@ -878,7 +957,9 @@ export default defineLoop({
878
957
  output: ReviewFix,
879
958
  timeout: stepBudget
880
959
  })
960
+
881
961
  headFindings = reviewed.findings
962
+ fixedFrom = { head, changed: fix.changed, looks: 0 }
882
963
 
883
964
  continue
884
965
  }