@kitman-sh/software-engineering 0.10.91 → 0.10.93

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
@@ -20195,6 +20195,7 @@ var WorkUnitOutcome = Struct({
20195
20195
  boundary: optionalKey2(BoundaryChange),
20196
20196
  catchUp: optionalKey2(CatchUp),
20197
20197
  syncedTarget: optionalKey2(Revision),
20198
+ cleanSync: optionalKey2(Literals(["up_to_date", "merged"])),
20198
20199
  harnessHold: optionalKey2(HarnessHold),
20199
20200
  restart: optionalKey2(StepRestart),
20200
20201
  failureSummary: optionalKey2(String5.check(isMinLength(1), isMaxLength(4000)))
@@ -20448,7 +20449,8 @@ var scriptedHost = (script, engine, agentLaunches, childLaunches, waits, verifyL
20448
20449
  event: launch.event,
20449
20450
  ...launch.filter === undefined ? undefined : { filter: launch.filter },
20450
20451
  ...launch.since === undefined ? undefined : { since: launch.since },
20451
- ...launch.or === undefined ? undefined : { or: launch.or }
20452
+ ...launch.or === undefined ? undefined : { or: launch.or },
20453
+ timeoutMillis: launch.timeoutMillis
20452
20454
  });
20453
20455
  return resolve(eventDeferred(launch.step), launch.token, event === undefined ? fail5(new WaitTimedOut({ step: launch.step, event: launch.event })) : succeed4(event));
20454
20456
  },
@@ -21519,6 +21521,8 @@ var ShepherdOutput = Struct({
21519
21521
  // src/shepherd.ts
21520
21522
  var reviewLoop = () => ({ id: "review", input: Input, output: Output });
21521
21523
  var stepBudget = "45 minutes";
21524
+ var pipelineRun = "10 minutes";
21525
+ var targetLooks = 6;
21522
21526
  var roundLimits = { "ci-fix": 1, "head-fix": 2 };
21523
21527
  var handBackAnswer = "Hand back to Build";
21524
21528
  var Input3 = Struct({
@@ -21602,7 +21606,7 @@ var repliesPrompt = (threads) => [
21602
21606
  var threadKey = (thread) => `${thread.id}:${thread.comments.length}`;
21603
21607
  var shepherd_default = defineLoop({
21604
21608
  id: "shepherd",
21605
- version: "1.5.0",
21609
+ version: "1.6.0",
21606
21610
  title: "Shepherd",
21607
21611
  input: Input3,
21608
21612
  output: Output3,
@@ -21637,6 +21641,9 @@ var shepherd_default = defineLoop({
21637
21641
  let stalledAt;
21638
21642
  let stalls = 0;
21639
21643
  let unreviewed;
21644
+ let reviewOnceShown;
21645
+ let pipelineFirst;
21646
+ const reviewedHeads = new Set;
21640
21647
  let notCarried;
21641
21648
  let behind = false;
21642
21649
  let pushed;
@@ -21759,7 +21766,8 @@ ${open}`,
21759
21766
  yield* note(`target-red:${cycle}`, {
21760
21767
  text: `Shepherd is waiting for ${target} to change instead of fixing ${pipeline.head}: ${why}`
21761
21768
  }).pipe(catchTag2("StepFailed", () => void_3));
21762
- const woke = yield* waitFor(`target-moved:${cycle}`, {
21769
+ const targetHead = pipeline.target?.head;
21770
+ const mergedInto = {
21763
21771
  event: "change_request.closed",
21764
21772
  filter: {
21765
21773
  merged: true,
@@ -21767,12 +21775,19 @@ ${open}`,
21767
21775
  ...repository === undefined ? undefined : { repository }
21768
21776
  },
21769
21777
  or: [{ event: "change_request.closed", filter: { changeRequestId } }],
21770
- timeout: "1 hour",
21778
+ timeout: targetHead === undefined ? "1 hour" : pipelineRun,
21771
21779
  ...pipeline.readAt === undefined ? undefined : { since: pipeline.readAt }
21772
- }).pipe(catchTag2("WaitTimedOut", () => undefined_2));
21780
+ };
21781
+ let woke = yield* waitFor(`target-moved:${cycle}`, mergedInto).pipe(catchTag2("WaitTimedOut", () => undefined_2));
21782
+ for (let look = 2;woke === undefined && targetHead !== undefined && look <= targetLooks; look++) {
21783
+ const again = yield* pipelineStatus(`target-read:${cycle}:${look}`, { changeRequestId });
21784
+ if (again.head !== pipeline.head || again.target?.head !== targetHead)
21785
+ break;
21786
+ woke = yield* waitFor(`target-moved:${cycle}:${look}`, mergedInto).pipe(catchTag2("WaitTimedOut", () => undefined_2));
21787
+ }
21773
21788
  if (woke?.payload.changeRequestId === changeRequestId)
21774
21789
  return woke.payload.merged === true ? done("merged", "Someone else merged the ChangeRequest") : done("needs_you", "The ChangeRequest was closed");
21775
- redTarget = { head: pipeline.head, targetHead: pipeline.target?.head, moved: woke !== undefined };
21790
+ redTarget = { head: pipeline.head, targetHead, moved: woke !== undefined };
21776
21791
  return;
21777
21792
  });
21778
21793
  const catchUp = (cycle, targetHead, forBlocker = false) => gen2(function* () {
@@ -21809,6 +21824,8 @@ ${open}`,
21809
21824
  }
21810
21825
  if (caught !== undefined) {
21811
21826
  pushed = { head: caught.head, stale: 0, by: "the catch-up" };
21827
+ reviewOnceShown = caught.head;
21828
+ pipelineFirst = caught.head;
21812
21829
  if (targetHead !== undefined)
21813
21830
  syncedFor.add(syncedKey(caught.head, targetHead));
21814
21831
  if (forBlocker)
@@ -21821,6 +21838,120 @@ ${open}`,
21821
21838
  }
21822
21839
  return;
21823
21840
  });
21841
+ const stop = (output) => ({ kind: "stop", output });
21842
+ const reviewMergedFiles = (cycle, head, files) => gen2(function* () {
21843
+ yield* passTurn();
21844
+ const reviewed = yield* call(`review:${cycle}`, reviewLoop(), {
21845
+ base: `origin/${target}`,
21846
+ head,
21847
+ files: files.files,
21848
+ ...head === files.synced ? undefined : { since: files.synced },
21849
+ ...files.earlier.length === 0 ? undefined : { earlier: files.earlier }
21850
+ });
21851
+ if (reviewed.blocking) {
21852
+ const blocking = reviewed.findings.filter(isBlocking);
21853
+ if (!(yield* mayFix("head-fix", cycle, blocking.map((finding) => finding.id).join(", "))))
21854
+ return stop(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)));
21855
+ rounds["head-fix"]++;
21856
+ const fix = yield* agentWork(`review-fix:${cycle}`, {
21857
+ agent: "implementer",
21858
+ prompt: reviewFixPrompt("the files the catch-up merge changed", blocking),
21859
+ output: ReviewFix,
21860
+ timeout: stepBudget
21861
+ });
21862
+ unreviewed = { ...files, earlier: reviewed.findings };
21863
+ fixedFrom = { head, changed: fix.changed, looks: 0 };
21864
+ return { kind: "fixing" };
21865
+ }
21866
+ const approval = yield* approveChangeRequest(`approve:${cycle}`, {
21867
+ changeRequestId,
21868
+ head,
21869
+ summary: `A review of the files merging ${target} in changed (${files.files.join(", ")}) passed with nothing blocking.`,
21870
+ review: `review:${cycle}`,
21871
+ carries: files.sync
21872
+ }).pipe(catchTag2("StepFailed", (error) => succeed7({ approved: false, reason: error.reason })));
21873
+ unreviewed = undefined;
21874
+ if (!approval.approved) {
21875
+ notCarried = `merging ${target} in, whose files' review passed but did not approve it: ${approval.reason}`;
21876
+ return { kind: "unapproved" };
21877
+ }
21878
+ reviewedHeads.add(head);
21879
+ return { kind: "approved" };
21880
+ });
21881
+ const reviewHead = (cycle, pipeline, which) => gen2(function* () {
21882
+ const head = pipeline.head;
21883
+ const since = pipeline.approved === undefined || pipeline.approved === head ? undefined : pipeline.approved;
21884
+ const reviewIt = leftToPerson.has(head) ? "Wait" : yield* ask(`unapproved:${cycle}`, {
21885
+ prompt: `Nobody has approved ${head}, ${which}. Have Kitman review it?`,
21886
+ options: [
21887
+ {
21888
+ value: "Review",
21889
+ description: since === undefined ? "Kitman's Review reads the whole change at this head and approves it if nothing blocks." : `Kitman's Review reads what changed since ${since}, the last approved head, and approves it if nothing there blocks.`
21890
+ },
21891
+ { value: "Wait", description: "Waits for a person to approve this head." }
21892
+ ],
21893
+ recommended: "Review",
21894
+ recommendationReason: "A passing Review of the change is what approved the head Build shipped.",
21895
+ default: "Wait",
21896
+ auto: "Review",
21897
+ timeout: "1 hour"
21898
+ });
21899
+ yield* passTurn();
21900
+ if (reviewIt === "Wait") {
21901
+ leftToPerson.add(head);
21902
+ return { kind: "left" };
21903
+ }
21904
+ const { notRun: headNotRun } = yield* verifyHead(`head-verify:${cycle}`, head);
21905
+ const notRun = [...new Set([...input.notRun ?? [], ...headNotRun])];
21906
+ const reviewed = yield* call(`head-review:${cycle}`, reviewLoop(), {
21907
+ base: `origin/${target}`,
21908
+ head,
21909
+ ...notRun.length === 0 ? undefined : { notRun },
21910
+ ...since === undefined ? undefined : { approved: since },
21911
+ ...headFindings.length === 0 ? undefined : { earlier: headFindings }
21912
+ });
21913
+ if (reviewed.blocking) {
21914
+ const blocking = reviewed.findings.filter(isBlocking);
21915
+ if (!(yield* mayFix("head-fix", cycle, blocking.map((finding) => finding.id).join(", "))))
21916
+ return stop(handBack(`The review of ${head} still finds ${blocking.map((finding) => finding.id).join(", ")} after ${rounds["head-fix"]} head-fix rounds`, findingLines2(blocking)));
21917
+ rounds["head-fix"]++;
21918
+ const fix = yield* agentWork(`head-fix:${cycle}`, {
21919
+ agent: "implementer",
21920
+ prompt: reviewFixPrompt(since === undefined ? `the change at ${head}` : `what changed between ${since} and ${head}`, blocking),
21921
+ output: ReviewFix,
21922
+ timeout: stepBudget
21923
+ });
21924
+ headFindings = reviewed.findings;
21925
+ fixedFrom = { head, changed: fix.changed, looks: 0 };
21926
+ return { kind: "fixing" };
21927
+ }
21928
+ headFindings = [];
21929
+ if (notRun.length > 0)
21930
+ unranAt.set(head, { notRun, review: `head-review:${cycle}` });
21931
+ else {
21932
+ const recorded = yield* approveChangeRequest(`head-approve:${cycle}`, {
21933
+ changeRequestId,
21934
+ head,
21935
+ summary: since === undefined ? `A review of the whole change at ${head} passed with nothing blocking.` : `A review of what changed between ${since}, the last approved head, and ${head} passed with nothing blocking.`,
21936
+ review: `head-review:${cycle}`
21937
+ }).pipe(catchTag2("StepFailed", (error) => succeed7({ approved: false, reason: error.reason })));
21938
+ if (!recorded.approved)
21939
+ return stop(done("needs_you", `The review of ${head} passed, but did not approve it: ${recorded.reason}`));
21940
+ }
21941
+ reviewedHeads.add(head);
21942
+ return { kind: "reviewed" };
21943
+ });
21944
+ const reviewCaughtUp = (cycle, pipeline) => gen2(function* () {
21945
+ const head = reviewOnceShown;
21946
+ reviewOnceShown = undefined;
21947
+ if (head !== pipeline.head)
21948
+ return;
21949
+ if (unreviewed !== undefined)
21950
+ return yield* reviewMergedFiles(cycle, head, unreviewed);
21951
+ if (notCarried !== undefined && pipeline.approved !== head)
21952
+ return yield* reviewHead(cycle, pipeline, "the head its catch-up merge pushed");
21953
+ return;
21954
+ });
21824
21955
  return gen2(function* () {
21825
21956
  for (let cycle = 1;; cycle++) {
21826
21957
  if (cycle > (input.maxCycles ?? 20)) {
@@ -21865,7 +21996,25 @@ ${open}`,
21865
21996
  else
21866
21997
  return found;
21867
21998
  }
21868
- if (pipeline.conflicts === true || pipeline.needsRebase === true) {
21999
+ const blocked = pipeline.conflicts === true || pipeline.needsRebase === true;
22000
+ const caughtUpHead = pipeline.head === pipelineFirst;
22001
+ const onRunnerDue = pipeline.status === "none" && pipeline.runnerChecks !== undefined;
22002
+ if (onRunnerDue && (!blocked || caughtUpHead)) {
22003
+ if (ranOnRunner.has(pipeline.head))
22004
+ return done("needs_you", `The pipeline ran on the Runner at ${pipeline.head}, but no result was recorded`);
22005
+ ranOnRunner.add(pipeline.head);
22006
+ const ran = yield* runOnRunner("run", cycle, pipeline.head, pipeline.runnerChecks ?? []);
22007
+ if ("failed" in ran)
22008
+ return done("needs_you", `The pipeline could not run on the Runner: ${ran.failed}`);
22009
+ continue;
22010
+ }
22011
+ const reviewing = yield* reviewCaughtUp(cycle, pipeline);
22012
+ if (reviewing?.kind === "stop")
22013
+ return reviewing.output;
22014
+ const approvedHere = reviewing?.kind === "approved" || reviewing?.kind === "reviewed";
22015
+ if (reviewing?.kind === "fixing" || approvedHere && !blocked && pipeline.status === "success")
22016
+ continue;
22017
+ if (blocked && !(pipeline.status === "running" && caughtUpHead)) {
21869
22018
  const blocker = pipeline.conflicts === true ? `conflicts with ${target}` : `needs ${target} merged in`;
21870
22019
  const targetHead = pipeline.target?.head;
21871
22020
  const syncedAlready = targetHead === undefined ? blockerSynced.has(pipeline.head) : syncedFor.has(syncedKey(pipeline.head, targetHead));
@@ -21892,15 +22041,6 @@ ${open}`,
21892
22041
  return stopped;
21893
22042
  continue;
21894
22043
  }
21895
- if (pipeline.status === "none" && pipeline.runnerChecks !== undefined) {
21896
- if (ranOnRunner.has(pipeline.head))
21897
- return done("needs_you", `The pipeline ran on the Runner at ${pipeline.head}, but no result was recorded`);
21898
- ranOnRunner.add(pipeline.head);
21899
- const ran = yield* runOnRunner("run", cycle, pipeline.head, pipeline.runnerChecks);
21900
- if ("failed" in ran)
21901
- return done("needs_you", `The pipeline could not run on the Runner: ${ran.failed}`);
21902
- continue;
21903
- }
21904
22044
  if (pipeline.status === "none" || pipeline.status === "running") {
21905
22045
  yield* pipelineMoved(`wait:${cycle}`, changeRequestId, pipeline);
21906
22046
  continue;
@@ -22026,45 +22166,15 @@ ${open}`,
22026
22166
  return stopped;
22027
22167
  continue;
22028
22168
  }
22029
- let reviewedHere = false;
22169
+ let reviewedHere = reviewedHeads.has(pipeline.head) && (pipeline.approved === pipeline.head || unranAt.has(pipeline.head));
22030
22170
  if (unreviewed !== undefined) {
22031
- const files = unreviewed;
22032
- const head = pipeline.head;
22033
- yield* passTurn();
22034
- const reviewed = yield* call(`review:${cycle}`, reviewLoop(), {
22035
- base: `origin/${target}`,
22036
- head,
22037
- files: files.files,
22038
- ...head === files.synced ? undefined : { since: files.synced },
22039
- ...files.earlier.length === 0 ? undefined : { earlier: files.earlier }
22040
- });
22041
- if (reviewed.blocking) {
22042
- const blocking = reviewed.findings.filter(isBlocking);
22043
- if (!(yield* mayFix("head-fix", cycle, blocking.map((finding) => finding.id).join(", "))))
22044
- 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));
22045
- rounds["head-fix"]++;
22046
- const fix = yield* agentWork(`review-fix:${cycle}`, {
22047
- agent: "implementer",
22048
- prompt: reviewFixPrompt("the files the catch-up merge changed", blocking),
22049
- output: ReviewFix,
22050
- timeout: stepBudget
22051
- });
22052
- unreviewed = { ...files, earlier: reviewed.findings };
22053
- fixedFrom = { head, changed: fix.changed, looks: 0 };
22171
+ const reviewing = yield* reviewMergedFiles(cycle, pipeline.head, unreviewed);
22172
+ if (reviewing.kind === "stop")
22173
+ return reviewing.output;
22174
+ if (reviewing.kind === "fixing")
22054
22175
  continue;
22055
- }
22056
- const approval = yield* approveChangeRequest(`approve:${cycle}`, {
22057
- changeRequestId,
22058
- head,
22059
- summary: `A review of the files merging ${target} in changed (${files.files.join(", ")}) passed with nothing blocking.`,
22060
- review: `review:${cycle}`,
22061
- carries: files.sync
22062
- }).pipe(catchTag2("StepFailed", (error) => succeed7({ approved: false, reason: error.reason })));
22063
- unreviewed = undefined;
22064
- if (approval.approved)
22176
+ if (reviewing.kind === "approved")
22065
22177
  reviewedHere = true;
22066
- else
22067
- notCarried = `merging ${target} in, whose files' review passed but did not approve it: ${approval.reason}`;
22068
22178
  }
22069
22179
  const moved = pipeline.readAt === undefined ? [] : [
22070
22180
  { event: "change_request.pipeline", filter: { changeRequestId }, since: pipeline.readAt },
@@ -22088,66 +22198,13 @@ ${open}`,
22088
22198
  timeout: "1 minute"
22089
22199
  }).pipe(map8((woke) => woke.type === "change_request.approval" && woke.payload.source !== "kitman" ? undefined : woke), catchTag2("WaitTimedOut", () => undefined_2));
22090
22200
  if (!reviewedHere && approved === undefined) {
22091
- const head = pipeline.head;
22092
- const since = pipeline.approved === undefined || pipeline.approved === head ? undefined : pipeline.approved;
22093
- const reviewIt = leftToPerson.has(head) ? "Wait" : yield* ask(`unapproved:${cycle}`, {
22094
- prompt: `Nobody has approved ${head}, the head whose pipeline passed. Have Kitman review it?`,
22095
- options: [
22096
- {
22097
- value: "Review",
22098
- description: since === undefined ? "Kitman's Review reads the whole change at this head and approves it if nothing blocks." : `Kitman's Review reads what changed since ${since}, the last approved head, and approves it if nothing there blocks.`
22099
- },
22100
- { value: "Wait", description: "Waits for a person to approve this head." }
22101
- ],
22102
- recommended: "Review",
22103
- recommendationReason: "A passing Review of the change is what approved the head Build shipped.",
22104
- default: "Wait",
22105
- auto: "Review",
22106
- timeout: "1 hour"
22107
- });
22108
- yield* passTurn();
22109
- if (reviewIt === "Wait") {
22110
- leftToPerson.add(head);
22201
+ const reviewing = yield* reviewHead(cycle, pipeline, "the head whose pipeline passed");
22202
+ if (reviewing.kind === "stop")
22203
+ return reviewing.output;
22204
+ if (reviewing.kind === "fixing")
22205
+ continue;
22206
+ if (reviewing.kind === "left")
22111
22207
  approved = yield* waitFor(`approval:${cycle}`, { ...approval, timeout: "7 days" });
22112
- } else {
22113
- const { notRun: headNotRun } = yield* verifyHead(`head-verify:${cycle}`, head);
22114
- const notRun = [...new Set([...input.notRun ?? [], ...headNotRun])];
22115
- const reviewed = yield* call(`head-review:${cycle}`, reviewLoop(), {
22116
- base: `origin/${target}`,
22117
- head,
22118
- ...notRun.length === 0 ? undefined : { notRun },
22119
- ...since === undefined ? undefined : { approved: since },
22120
- ...headFindings.length === 0 ? undefined : { earlier: headFindings }
22121
- });
22122
- if (reviewed.blocking) {
22123
- const blocking = reviewed.findings.filter(isBlocking);
22124
- if (!(yield* mayFix("head-fix", cycle, blocking.map((finding) => finding.id).join(", "))))
22125
- return handBack(`The review of ${head} still finds ${blocking.map((finding) => finding.id).join(", ")} after ${rounds["head-fix"]} head-fix rounds`, findingLines2(blocking));
22126
- rounds["head-fix"]++;
22127
- const fix = yield* agentWork(`head-fix:${cycle}`, {
22128
- agent: "implementer",
22129
- prompt: reviewFixPrompt(since === undefined ? `the change at ${head}` : `what changed between ${since} and ${head}`, blocking),
22130
- output: ReviewFix,
22131
- timeout: stepBudget
22132
- });
22133
- headFindings = reviewed.findings;
22134
- fixedFrom = { head, changed: fix.changed, looks: 0 };
22135
- continue;
22136
- }
22137
- headFindings = [];
22138
- if (notRun.length > 0)
22139
- unranAt.set(head, { notRun, review: `head-review:${cycle}` });
22140
- else {
22141
- const recorded = yield* approveChangeRequest(`head-approve:${cycle}`, {
22142
- changeRequestId,
22143
- head,
22144
- summary: since === undefined ? `A review of the whole change at ${head} passed with nothing blocking.` : `A review of what changed between ${since}, the last approved head, and ${head} passed with nothing blocking.`,
22145
- review: `head-review:${cycle}`
22146
- }).pipe(catchTag2("StepFailed", (error) => succeed7({ approved: false, reason: error.reason })));
22147
- if (!recorded.approved)
22148
- return done("needs_you", `The review of ${head} passed, but did not approve it: ${recorded.reason}`);
22149
- }
22150
- }
22151
22208
  }
22152
22209
  if (approved !== undefined && approved.type !== "change_request.approval")
22153
22210
  continue;
@@ -22423,6 +22480,8 @@ var rally = (input) => gen2(function* () {
22423
22480
  });
22424
22481
  if (synced.status === "conflict")
22425
22482
  conflicts.push(`Could not merge the target branch in round ${round}: ${synced.files.join(", ")} (${synced.reason})`);
22483
+ else
22484
+ conflicts.length = 0;
22426
22485
  const base = synced.base;
22427
22486
  if (base === undefined)
22428
22487
  return yield* new BuildBaseUnpinned({
@@ -30337,4 +30396,4 @@ var runKit = (config, identity, packages) => {
30337
30396
  runMain2(program.pipe(flatMap3((code) => sync2(() => process.exit(code)))));
30338
30397
  };
30339
30398
  // .kitman-build-entry.ts
30340
- runKit(kitman_config_default, { name: "@kitman-sh/software-engineering", version: "0.10.91" }, []);
30399
+ runKit(kitman_config_default, { name: "@kitman-sh/software-engineering", version: "0.10.93" }, []);
@@ -2705,7 +2705,7 @@
2705
2705
  {
2706
2706
  "id": "shepherd",
2707
2707
  "title": "Shepherd",
2708
- "version": "1.5.0",
2708
+ "version": "1.6.0",
2709
2709
  "input": {
2710
2710
  "type": "object",
2711
2711
  "properties": {
@@ -3528,7 +3528,7 @@
3528
3528
  "carried": [
3529
3529
  {
3530
3530
  "name": "@kitman-sh/software-engineering",
3531
- "version": "0.10.91",
3531
+ "version": "0.10.93",
3532
3532
  "setup": "2a237548a69b0cd53ec3be7f687cfa8c2128335b3a655d34e185f2abce6a3c37",
3533
3533
  "loops": [
3534
3534
  "build",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitman-sh/software-engineering",
3
- "version": "0.10.91",
3
+ "version": "0.10.93",
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.91",
20
+ "@kitman-sh/sdk": "0.10.93",
21
21
  "effect": "^4.1.2"
22
22
  },
23
23
  "kitman": {
24
24
  "bundle": "dist/bundle.js",
25
- "digest": "59d1513c526ad394e8733d33c5b2e2137e5eb33ad65c020ffe5f23692697254c",
25
+ "digest": "f7f4bc64d9ef71c74e4daf7679a432b2328ed9992ef81933996733d4552e8e76",
26
26
  "protocolVersion": 5,
27
27
  "declarations": "dist/declarations.json",
28
28
  "setup": {
package/src/build.ts CHANGED
@@ -304,10 +304,12 @@ const rally = (input: {
304
304
  ...(input.target === undefined ? undefined : { target: input.target })
305
305
  })
306
306
 
307
+ // A round that merges or finds the branch up to date settles every round before it that could not merge.
307
308
  if (synced.status === 'conflict')
308
309
  conflicts.push(
309
310
  `Could not merge the target branch in round ${round}: ${synced.files.join(', ')} (${synced.reason})`
310
311
  )
312
+ else conflicts.length = 0
311
313
 
312
314
  // Pinned, so a target that moves during the round does not move what is reviewed.
313
315
  const base = synced.base
package/src/shepherd.ts CHANGED
@@ -42,6 +42,12 @@ const reviewLoop = () => ({ id: 'review', input: ReviewInput, output: ReviewOutp
42
42
  /** The model time one fix or round of replies may take before a person looks. */
43
43
  const stepBudget = '45 minutes'
44
44
 
45
+ /** About one pipeline run: the longest it waits on a red target before it reads it again, for a push no Event announces. */
46
+ const pipelineRun = '10 minutes' as const
47
+
48
+ /** The reads of a red target one look takes, about an hour of them. */
49
+ const targetLooks = 6
50
+
45
51
  /** Rounds of each kind a Run takes before it asks whether to hand the ChangeRequest back to Build. */
46
52
  const roundLimits = { 'ci-fix': 1, 'head-fix': 2 } as const
47
53
 
@@ -196,13 +202,14 @@ const threadKey = (thread: ReviewThreads['threads'][number]) => `${thread.id}:${
196
202
  * and mergeable when told to or when a person says so. A branch the forge says conflicts or is behind merges its target
197
203
  * in before any pipeline is run or fixed, and one whose merge Shepherd cannot settle goes back to Build. It merges the
198
204
  * target in and merges only while it holds the target's turn, so ChangeRequests for one target land one at a time, in
199
- * order. A head nobody approved gets a review of what changed since the last approved head. It runs one ci-fix and two
205
+ * order. A head nobody approved gets a review of what changed since the last approved head, and the head a catch-up
206
+ * pushed gets its pipeline started and its review as soon as the forge shows it, not once its pipeline passes. It runs one ci-fix and two
200
207
  * head-fix rounds, each judged by the pipeline at the head the last fix pushed, then hands the ChangeRequest back to
201
208
  * Build, and stops as needs you, with why, instead of spinning.
202
209
  */
203
210
  export default defineLoop({
204
211
  id: 'shepherd',
205
- version: '1.5.0',
212
+ version: '1.6.0',
206
213
  title: 'Shepherd',
207
214
  input: Input,
208
215
  output: Output,
@@ -253,6 +260,13 @@ export default defineLoop({
253
260
  }
254
261
  | undefined
255
262
 
263
+ /** The head the last catch-up pushed, to review as soon as the forge shows it rather than once its pipeline passes. */
264
+ let reviewOnceShown: string | undefined
265
+ /** The head the last catch-up pushed, whose pipeline runs before Shepherd catches up again. */
266
+ let pipelineFirst: string | undefined
267
+ /** Heads Shepherd's own review passed, approved or left to a person for tests verify never ran. */
268
+ const reviewedHeads = new Set<string>()
269
+
256
270
  /** Why an approval of the head is still needed after a catch-up merge, for a person who is left to give it. */
257
271
  let notCarried: string | undefined
258
272
  // The last merge did not go in as the ChangeRequest is: its target moved on, or it conflicts.
@@ -463,7 +477,10 @@ export default defineLoop({
463
477
  text: `Shepherd is waiting for ${target} to change instead of fixing ${pipeline.head}: ${why}`
464
478
  }).pipe(Effect.catchTag('StepFailed', () => Effect.void))
465
479
 
466
- const woke = yield* waitFor(`target-moved:${cycle}`, {
480
+ // Only a read that names the target's head can tell a push straight to it, which makes no Event.
481
+ const targetHead = pipeline.target?.head
482
+
483
+ const mergedInto = {
467
484
  event: 'change_request.closed',
468
485
  filter: {
469
486
  merged: true,
@@ -471,16 +488,31 @@ export default defineLoop({
471
488
  ...(repository === undefined ? undefined : { repository })
472
489
  },
473
490
  or: [{ event: 'change_request.closed', filter: { changeRequestId } }],
474
- timeout: '1 hour',
491
+ timeout: targetHead === undefined ? ('1 hour' as const) : pipelineRun,
475
492
  ...(pipeline.readAt === undefined ? undefined : { since: pipeline.readAt })
476
- }).pipe(Effect.catchTag('WaitTimedOut', () => Effect.undefined))
493
+ }
494
+
495
+ let woke = yield* waitFor(`target-moved:${cycle}`, mergedInto).pipe(
496
+ Effect.catchTag('WaitTimedOut', () => Effect.undefined)
497
+ )
498
+
499
+ // Reading again each pipeline run is part of this one look, so it costs no look of its own.
500
+ for (let look = 2; woke === undefined && targetHead !== undefined && look <= targetLooks; look++) {
501
+ const again = yield* pipelineStatus(`target-read:${cycle}:${look}`, { changeRequestId })
502
+
503
+ if (again.head !== pipeline.head || again.target?.head !== targetHead) break
504
+
505
+ woke = yield* waitFor(`target-moved:${cycle}:${look}`, mergedInto).pipe(
506
+ Effect.catchTag('WaitTimedOut', () => Effect.undefined)
507
+ )
508
+ }
477
509
 
478
510
  if (woke?.payload.changeRequestId === changeRequestId)
479
511
  return woke.payload.merged === true
480
512
  ? done('merged', 'Someone else merged the ChangeRequest')
481
513
  : done('needs_you', 'The ChangeRequest was closed')
482
514
 
483
- redTarget = { head: pipeline.head, targetHead: pipeline.target?.head, moved: woke !== undefined }
515
+ redTarget = { head: pipeline.head, targetHead, moved: woke !== undefined }
484
516
 
485
517
  return undefined
486
518
  })
@@ -542,6 +574,8 @@ export default defineLoop({
542
574
  // The forge can show the old head for a moment after the push; the next look reads it once it shows this one.
543
575
  if (caught !== undefined) {
544
576
  pushed = { head: caught.head, stale: 0, by: 'the catch-up' }
577
+ reviewOnceShown = caught.head
578
+ pipelineFirst = caught.head
545
579
 
546
580
  if (targetHead !== undefined) syncedFor.add(syncedKey(caught.head, targetHead))
547
581
 
@@ -557,6 +591,194 @@ export default defineLoop({
557
591
  return undefined
558
592
  })
559
593
 
594
+ const stop = (output: Output) => ({ kind: 'stop', output }) as const
595
+
596
+ /**
597
+ * Reviews the files a catch-up merge settled, at `head`, and approves it on a pass: `fixing` when a fix round ran for
598
+ * its findings, `approved` or `unapproved` once the review passed, or `stop` with the Output.
599
+ */
600
+ const reviewMergedFiles = (cycle: number, head: string, files: NonNullable<typeof unreviewed>) =>
601
+ Effect.gen(function* () {
602
+ yield* passTurn()
603
+
604
+ const reviewed = yield* call(`review:${cycle}`, reviewLoop(), {
605
+ base: `origin/${target}`,
606
+ head,
607
+ files: files.files,
608
+ ...(head === files.synced ? undefined : { since: files.synced }),
609
+ ...(files.earlier.length === 0 ? undefined : { earlier: files.earlier })
610
+ })
611
+
612
+ if (reviewed.blocking) {
613
+ const blocking = reviewed.findings.filter(isBlocking)
614
+
615
+ if (!(yield* mayFix('head-fix', cycle, blocking.map(finding => finding.id).join(', '))))
616
+ return stop(
617
+ handBack(
618
+ `The review of the catch-up merge's files still finds ${blocking.map(finding => finding.id).join(', ')} after ${rounds['head-fix']} head-fix rounds`,
619
+ findingLines(blocking)
620
+ )
621
+ )
622
+ rounds['head-fix']++
623
+
624
+ const fix = yield* agentWork(`review-fix:${cycle}`, {
625
+ agent: 'implementer',
626
+ prompt: reviewFixPrompt('the files the catch-up merge changed', blocking),
627
+ output: ReviewFix,
628
+ timeout: stepBudget
629
+ })
630
+
631
+ unreviewed = { ...files, earlier: reviewed.findings }
632
+ fixedFrom = { head, changed: fix.changed, looks: 0 }
633
+
634
+ return { kind: 'fixing' } as const
635
+ }
636
+
637
+ const approval = yield* approveChangeRequest(`approve:${cycle}`, {
638
+ changeRequestId,
639
+ head,
640
+ summary: `A review of the files merging ${target} in changed (${files.files.join(', ')}) passed with nothing blocking.`,
641
+ review: `review:${cycle}`,
642
+ carries: files.sync
643
+ }).pipe(
644
+ Effect.catchTag('StepFailed', error => Effect.succeed({ approved: false as const, reason: error.reason }))
645
+ )
646
+
647
+ unreviewed = undefined
648
+
649
+ if (!approval.approved) {
650
+ notCarried = `merging ${target} in, whose files' review passed but did not approve it: ${approval.reason}`
651
+
652
+ return { kind: 'unapproved' } as const
653
+ }
654
+
655
+ reviewedHeads.add(head)
656
+
657
+ return { kind: 'approved' } as const
658
+ })
659
+
660
+ /**
661
+ * Has Kitman review the head of `pipeline`, which nobody approved, when a person or full auto says so, and approves
662
+ * it on a pass: `fixing` when a fix round ran for its findings, `left` when its approval is left to a person,
663
+ * `reviewed` once the review passed, or `stop` with the Output.
664
+ */
665
+ const reviewHead = (cycle: number, pipeline: PipelineStatus, which: string) =>
666
+ Effect.gen(function* () {
667
+ const head = pipeline.head
668
+ // Only what changed since the last approved head is unreviewed; the rest was approved as it stands.
669
+ const since = pipeline.approved === undefined || pipeline.approved === head ? undefined : pipeline.approved
670
+
671
+ const reviewIt = leftToPerson.has(head)
672
+ ? 'Wait'
673
+ : yield* ask(`unapproved:${cycle}`, {
674
+ prompt: `Nobody has approved ${head}, ${which}. Have Kitman review it?`,
675
+ options: [
676
+ {
677
+ value: 'Review',
678
+ description:
679
+ since === undefined
680
+ ? "Kitman's Review reads the whole change at this head and approves it if nothing blocks."
681
+ : `Kitman's Review reads what changed since ${since}, the last approved head, and approves it if nothing there blocks.`
682
+ },
683
+ { value: 'Wait', description: 'Waits for a person to approve this head.' }
684
+ ],
685
+ recommended: 'Review',
686
+ recommendationReason: 'A passing Review of the change is what approved the head Build shipped.',
687
+ default: 'Wait',
688
+ // A full-auto Team merges what its Review approved, including heads Shepherd pushed itself.
689
+ auto: 'Review',
690
+ timeout: '1 hour'
691
+ })
692
+
693
+ yield* passTurn()
694
+
695
+ if (reviewIt === 'Wait') {
696
+ leftToPerson.add(head)
697
+
698
+ return { kind: 'left' } as const
699
+ }
700
+
701
+ const { notRun: headNotRun } = yield* verifyHead(`head-verify:${cycle}`, head)
702
+ const notRun = [...new Set([...(input.notRun ?? []), ...headNotRun])]
703
+
704
+ const reviewed = yield* call(`head-review:${cycle}`, reviewLoop(), {
705
+ base: `origin/${target}`,
706
+ head,
707
+ ...(notRun.length === 0 ? undefined : { notRun }),
708
+ ...(since === undefined ? undefined : { approved: since }),
709
+ ...(headFindings.length === 0 ? undefined : { earlier: headFindings })
710
+ })
711
+
712
+ if (reviewed.blocking) {
713
+ const blocking = reviewed.findings.filter(isBlocking)
714
+
715
+ if (!(yield* mayFix('head-fix', cycle, blocking.map(finding => finding.id).join(', '))))
716
+ return stop(
717
+ handBack(
718
+ `The review of ${head} still finds ${blocking.map(finding => finding.id).join(', ')} after ${rounds['head-fix']} head-fix rounds`,
719
+ findingLines(blocking)
720
+ )
721
+ )
722
+ rounds['head-fix']++
723
+
724
+ const fix = yield* agentWork(`head-fix:${cycle}`, {
725
+ agent: 'implementer',
726
+ prompt: reviewFixPrompt(
727
+ since === undefined ? `the change at ${head}` : `what changed between ${since} and ${head}`,
728
+ blocking
729
+ ),
730
+ output: ReviewFix,
731
+ timeout: stepBudget
732
+ })
733
+
734
+ headFindings = reviewed.findings
735
+ fixedFrom = { head, changed: fix.changed, looks: 0 }
736
+
737
+ return { kind: 'fixing' } as const
738
+ }
739
+
740
+ headFindings = []
741
+
742
+ if (notRun.length > 0) unranAt.set(head, { notRun, review: `head-review:${cycle}` })
743
+ else {
744
+ const recorded = yield* approveChangeRequest(`head-approve:${cycle}`, {
745
+ changeRequestId,
746
+ head,
747
+ summary:
748
+ since === undefined
749
+ ? `A review of the whole change at ${head} passed with nothing blocking.`
750
+ : `A review of what changed between ${since}, the last approved head, and ${head} passed with nothing blocking.`,
751
+ review: `head-review:${cycle}`
752
+ }).pipe(
753
+ Effect.catchTag('StepFailed', error => Effect.succeed({ approved: false as const, reason: error.reason }))
754
+ )
755
+
756
+ if (!recorded.approved)
757
+ return stop(done('needs_you', `The review of ${head} passed, but did not approve it: ${recorded.reason}`))
758
+ }
759
+
760
+ reviewedHeads.add(head)
761
+
762
+ return { kind: 'reviewed' } as const
763
+ })
764
+
765
+ /** Reviews the head the last catch-up pushed, if `pipeline` shows it and it still needs a review. */
766
+ const reviewCaughtUp = (cycle: number, pipeline: PipelineStatus) =>
767
+ Effect.gen(function* () {
768
+ const head = reviewOnceShown
769
+
770
+ reviewOnceShown = undefined
771
+
772
+ if (head !== pipeline.head) return undefined
773
+
774
+ if (unreviewed !== undefined) return yield* reviewMergedFiles(cycle, head, unreviewed)
775
+
776
+ if (notCarried !== undefined && pipeline.approved !== head)
777
+ return yield* reviewHead(cycle, pipeline, 'the head its catch-up merge pushed')
778
+
779
+ return undefined
780
+ })
781
+
560
782
  return Effect.gen(function* () {
561
783
  for (let cycle = 1; ; cycle++) {
562
784
  if (cycle > (input.maxCycles ?? 20)) {
@@ -618,7 +840,37 @@ export default defineLoop({
618
840
  else return found
619
841
  }
620
842
 
621
- if (pipeline.conflicts === true || pipeline.needsRebase === true) {
843
+ const blocked = pipeline.conflicts === true || pipeline.needsRebase === true
844
+ const caughtUpHead = pipeline.head === pipelineFirst
845
+ // The forge runs no pipeline for this repository: its pipeline runs on a Runner and is reported to Kitman.
846
+ const onRunnerDue = pipeline.status === 'none' && pipeline.runnerChecks !== undefined
847
+
848
+ // Run this head's pipeline before reviewing it or catching up again.
849
+ if (onRunnerDue && (!blocked || caughtUpHead)) {
850
+ if (ranOnRunner.has(pipeline.head))
851
+ return done('needs_you', `The pipeline ran on the Runner at ${pipeline.head}, but no result was recorded`)
852
+ ranOnRunner.add(pipeline.head)
853
+
854
+ const ran = yield* runOnRunner('run', cycle, pipeline.head, pipeline.runnerChecks ?? [])
855
+
856
+ if ('failed' in ran) return done('needs_you', `The pipeline could not run on the Runner: ${ran.failed}`)
857
+
858
+ continue
859
+ }
860
+
861
+ // A catch-up's head is reviewed once the forge shows it, not once the target stops moving, so the next clean
862
+ // catch-up carries its approval. A head that may merge on this read is read again after its approval, which the
863
+ // merge gates would otherwise not see.
864
+ const reviewing = yield* reviewCaughtUp(cycle, pipeline)
865
+
866
+ if (reviewing?.kind === 'stop') return reviewing.output
867
+
868
+ const approvedHere = reviewing?.kind === 'approved' || reviewing?.kind === 'reviewed'
869
+
870
+ if (reviewing?.kind === 'fixing' || (approvedHere && !blocked && pipeline.status === 'success')) continue
871
+
872
+ // Wait for this head's running pipeline before catching up again.
873
+ if (blocked && !(pipeline.status === 'running' && caughtUpHead)) {
622
874
  const blocker = pipeline.conflicts === true ? `conflicts with ${target}` : `needs ${target} merged in`
623
875
  const targetHead = pipeline.target?.head
624
876
 
@@ -662,19 +914,6 @@ export default defineLoop({
662
914
  continue
663
915
  }
664
916
 
665
- // The forge runs no pipeline for this repository: its pipeline runs on a Runner and is reported to Kitman.
666
- if (pipeline.status === 'none' && pipeline.runnerChecks !== undefined) {
667
- if (ranOnRunner.has(pipeline.head))
668
- return done('needs_you', `The pipeline ran on the Runner at ${pipeline.head}, but no result was recorded`)
669
- ranOnRunner.add(pipeline.head)
670
-
671
- const ran = yield* runOnRunner('run', cycle, pipeline.head, pipeline.runnerChecks)
672
-
673
- if ('failed' in ran) return done('needs_you', `The pipeline could not run on the Runner: ${ran.failed}`)
674
-
675
- continue
676
- }
677
-
678
917
  if (pipeline.status === 'none' || pipeline.status === 'running') {
679
918
  yield* pipelineMoved(`wait:${cycle}`, changeRequestId, pipeline)
680
919
 
@@ -860,60 +1099,18 @@ export default defineLoop({
860
1099
  continue
861
1100
  }
862
1101
 
863
- let reviewedHere = false
1102
+ // Its own review approved a head only while this read still shows the approval: a request for changes takes it back.
1103
+ let reviewedHere =
1104
+ reviewedHeads.has(pipeline.head) && (pipeline.approved === pipeline.head || unranAt.has(pipeline.head))
864
1105
 
865
1106
  if (unreviewed !== undefined) {
866
- const files = unreviewed
867
- const head = pipeline.head
868
-
869
- yield* passTurn()
1107
+ const reviewing = yield* reviewMergedFiles(cycle, pipeline.head, unreviewed)
870
1108
 
871
- const reviewed = yield* call(`review:${cycle}`, reviewLoop(), {
872
- base: `origin/${target}`,
873
- head,
874
- files: files.files,
875
- ...(head === files.synced ? undefined : { since: files.synced }),
876
- ...(files.earlier.length === 0 ? undefined : { earlier: files.earlier })
877
- })
878
-
879
- if (reviewed.blocking) {
880
- const blocking = reviewed.findings.filter(isBlocking)
1109
+ if (reviewing.kind === 'stop') return reviewing.output
881
1110
 
882
- if (!(yield* mayFix('head-fix', cycle, blocking.map(finding => finding.id).join(', '))))
883
- return handBack(
884
- `The review of the catch-up merge's files still finds ${blocking.map(finding => finding.id).join(', ')} after ${rounds['head-fix']} head-fix rounds`,
885
- findingLines(blocking)
886
- )
887
- rounds['head-fix']++
1111
+ if (reviewing.kind === 'fixing') continue
888
1112
 
889
- const fix = yield* agentWork(`review-fix:${cycle}`, {
890
- agent: 'implementer',
891
- prompt: reviewFixPrompt('the files the catch-up merge changed', blocking),
892
- output: ReviewFix,
893
- timeout: stepBudget
894
- })
895
-
896
- unreviewed = { ...files, earlier: reviewed.findings }
897
- fixedFrom = { head, changed: fix.changed, looks: 0 }
898
-
899
- continue
900
- }
901
-
902
- const approval = yield* approveChangeRequest(`approve:${cycle}`, {
903
- changeRequestId,
904
- head,
905
- summary: `A review of the files merging ${target} in changed (${files.files.join(', ')}) passed with nothing blocking.`,
906
- review: `review:${cycle}`,
907
- carries: files.sync
908
- }).pipe(
909
- Effect.catchTag('StepFailed', error => Effect.succeed({ approved: false as const, reason: error.reason }))
910
- )
911
-
912
- unreviewed = undefined
913
-
914
- if (approval.approved) reviewedHere = true
915
- else
916
- notCarried = `merging ${target} in, whose files' review passed but did not approve it: ${approval.reason}`
1113
+ if (reviewing.kind === 'approved') reviewedHere = true
917
1114
  }
918
1115
 
919
1116
  // A newer head's finished pipeline goes round again, to gate that head and wait for its own approval. A
@@ -961,97 +1158,14 @@ export default defineLoop({
961
1158
  )
962
1159
 
963
1160
  if (!reviewedHere && approved === undefined) {
964
- const head = pipeline.head
965
- // Only what changed since the last approved head is unreviewed; the rest was approved as it stands.
966
- const since = pipeline.approved === undefined || pipeline.approved === head ? undefined : pipeline.approved
967
-
968
- const reviewIt = leftToPerson.has(head)
969
- ? 'Wait'
970
- : yield* ask(`unapproved:${cycle}`, {
971
- prompt: `Nobody has approved ${head}, the head whose pipeline passed. Have Kitman review it?`,
972
- options: [
973
- {
974
- value: 'Review',
975
- description:
976
- since === undefined
977
- ? "Kitman's Review reads the whole change at this head and approves it if nothing blocks."
978
- : `Kitman's Review reads what changed since ${since}, the last approved head, and approves it if nothing there blocks.`
979
- },
980
- { value: 'Wait', description: 'Waits for a person to approve this head.' }
981
- ],
982
- recommended: 'Review',
983
- recommendationReason: 'A passing Review of the change is what approved the head Build shipped.',
984
- default: 'Wait',
985
- // A full-auto Team merges what its Review approved, including heads Shepherd pushed itself.
986
- auto: 'Review',
987
- timeout: '1 hour'
988
- })
989
-
990
- yield* passTurn()
991
-
992
- if (reviewIt === 'Wait') {
993
- leftToPerson.add(head)
994
- approved = yield* waitFor(`approval:${cycle}`, { ...approval, timeout: '7 days' })
995
- } else {
996
- const { notRun: headNotRun } = yield* verifyHead(`head-verify:${cycle}`, head)
997
- const notRun = [...new Set([...(input.notRun ?? []), ...headNotRun])]
998
-
999
- const reviewed = yield* call(`head-review:${cycle}`, reviewLoop(), {
1000
- base: `origin/${target}`,
1001
- head,
1002
- ...(notRun.length === 0 ? undefined : { notRun }),
1003
- ...(since === undefined ? undefined : { approved: since }),
1004
- ...(headFindings.length === 0 ? undefined : { earlier: headFindings })
1005
- })
1006
-
1007
- if (reviewed.blocking) {
1008
- const blocking = reviewed.findings.filter(isBlocking)
1009
-
1010
- if (!(yield* mayFix('head-fix', cycle, blocking.map(finding => finding.id).join(', '))))
1011
- return handBack(
1012
- `The review of ${head} still finds ${blocking.map(finding => finding.id).join(', ')} after ${rounds['head-fix']} head-fix rounds`,
1013
- findingLines(blocking)
1014
- )
1015
- rounds['head-fix']++
1016
-
1017
- const fix = yield* agentWork(`head-fix:${cycle}`, {
1018
- agent: 'implementer',
1019
- prompt: reviewFixPrompt(
1020
- since === undefined ? `the change at ${head}` : `what changed between ${since} and ${head}`,
1021
- blocking
1022
- ),
1023
- output: ReviewFix,
1024
- timeout: stepBudget
1025
- })
1026
-
1027
- headFindings = reviewed.findings
1028
- fixedFrom = { head, changed: fix.changed, looks: 0 }
1161
+ const reviewing = yield* reviewHead(cycle, pipeline, 'the head whose pipeline passed')
1029
1162
 
1030
- continue
1031
- }
1163
+ if (reviewing.kind === 'stop') return reviewing.output
1032
1164
 
1033
- headFindings = []
1034
-
1035
- if (notRun.length > 0) unranAt.set(head, { notRun, review: `head-review:${cycle}` })
1036
- else {
1037
- const recorded = yield* approveChangeRequest(`head-approve:${cycle}`, {
1038
- changeRequestId,
1039
- head,
1040
- summary:
1041
- since === undefined
1042
- ? `A review of the whole change at ${head} passed with nothing blocking.`
1043
- : `A review of what changed between ${since}, the last approved head, and ${head} passed with nothing blocking.`,
1044
- review: `head-review:${cycle}`
1045
- }).pipe(
1046
- Effect.catchTag('StepFailed', error =>
1047
- Effect.succeed({ approved: false as const, reason: error.reason })
1048
- )
1049
- )
1165
+ if (reviewing.kind === 'fixing') continue
1050
1166
 
1051
- if (!recorded.approved)
1052
- return done('needs_you', `The review of ${head} passed, but did not approve it: ${recorded.reason}`)
1053
- }
1054
- }
1167
+ if (reviewing.kind === 'left')
1168
+ approved = yield* waitFor(`approval:${cycle}`, { ...approval, timeout: '7 days' })
1055
1169
  }
1056
1170
 
1057
1171
  if (approved !== undefined && approved.type !== 'change_request.approval') continue