@kitman-sh/software-engineering 0.10.67 → 0.10.69

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
@@ -5680,6 +5680,7 @@ var succeedSome2 = succeedSome;
5680
5680
  var suspend2 = suspend;
5681
5681
  var sync2 = sync;
5682
5682
  var void_3 = void_;
5683
+ var undefined_2 = undefined_;
5683
5684
  var callback2 = callback;
5684
5685
  var never2 = never;
5685
5686
  var gen2 = gen;
@@ -7162,7 +7163,7 @@ var Undefined = class extends ASTNodeImpl {
7162
7163
  var undefinedToNull = /* @__PURE__ */ new Link(null_, /* @__PURE__ */ new Transformation(/* @__PURE__ */ transform(() => {
7163
7164
  return;
7164
7165
  }), /* @__PURE__ */ transform(() => null)));
7165
- var undefined_2 = /* @__PURE__ */ new Undefined;
7166
+ var undefined_3 = /* @__PURE__ */ new Undefined;
7166
7167
  var Void = class extends ASTNodeImpl {
7167
7168
  _tag = "Void";
7168
7169
  getParser() {
@@ -8504,7 +8505,7 @@ var optionalKey = /* @__PURE__ */ memoizeIdempotent((ast) => {
8504
8505
  return optionalKeyLastLink(replaceContext(ast, context));
8505
8506
  });
8506
8507
  var optionalKeyLastLink = /* @__PURE__ */ applyToLastLink(optionalKey);
8507
- var optional = /* @__PURE__ */ memoize((ast) => optionalKey(new Union([ast, undefined_2])));
8508
+ var optional = /* @__PURE__ */ memoize((ast) => optionalKey(new Union([ast, undefined_3])));
8508
8509
  function withConstructorDefault(ast, defaultValue) {
8509
8510
  const context = ast.context ? new Context(ast.context.isOptional, ast.context.isMutable, defaultValue, ast.context.annotations) : new Context(false, false, defaultValue);
8510
8511
  return replaceContext(ast, context);
@@ -11071,7 +11072,7 @@ function Literal2(literal) {
11071
11072
  var Never2 = /* @__PURE__ */ make12(never3);
11072
11073
  var Unknown2 = /* @__PURE__ */ make12(unknown);
11073
11074
  var Null2 = /* @__PURE__ */ make12(null_);
11074
- var Undefined2 = /* @__PURE__ */ make12(undefined_2);
11075
+ var Undefined2 = /* @__PURE__ */ make12(undefined_3);
11075
11076
  var String5 = /* @__PURE__ */ make12(string2);
11076
11077
  var Number5 = /* @__PURE__ */ make12(number2);
11077
11078
  var Boolean3 = /* @__PURE__ */ make12(boolean);
@@ -19066,6 +19067,7 @@ var verify = (name, request) => takeStep(name, "verify", "verify", gen2(function
19066
19067
  ...request.revision === undefined ? undefined : { revision: request.revision },
19067
19068
  ...request.checks === undefined ? undefined : { checks: request.checks },
19068
19069
  ...request.suggested === undefined || request.suggested.length === 0 ? undefined : { suggested: request.suggested },
19070
+ ...request.rerunFailed === true ? { rerunFailed: true } : undefined,
19069
19071
  token: token2
19070
19072
  }));
19071
19073
  return yield* await_2(deferred);
@@ -20248,7 +20250,7 @@ var journaled = (engine, journal, ran) => ({
20248
20250
  })
20249
20251
  });
20250
20252
  var scriptedExit = (scripted, failure) => scripted === undefined ? fail5(failure("nothing was scripted for this Step")) : scripted instanceof ScriptedFailure ? fail5(failure(scripted.reason)) : succeed4(scripted);
20251
- var scriptedHost = (script, engine, agentLaunches, childLaunches, waits) => {
20253
+ var scriptedHost = (script, engine, agentLaunches, childLaunches, waits, verifyLaunches) => {
20252
20254
  const resolve = (deferred, token, exit) => done4(deferred, { token, exit }).pipe(provideService2(WorkflowEngine, engine));
20253
20255
  return {
20254
20256
  startAgentWork: (launch) => andThen2(sync2(() => agentLaunches.push({
@@ -20278,6 +20280,13 @@ var scriptedHost = (script, engine, agentLaunches, childLaunches, waits) => {
20278
20280
  claimResource: (launch) => launch.action === "let_go" ? resolve(letGoDeferred(launch.step), launch.token, succeed4(null)) : resolve(claimDeferred(launch.step), launch.token, succeed4(script.claims?.[launch.step] ?? { status: "granted", resource: launch.resource })),
20279
20281
  startVerification: (launch) => {
20280
20282
  const scripted = script.verifications?.[launch.step];
20283
+ if (launch.measure === undefined)
20284
+ verifyLaunches.push({
20285
+ step: launch.step,
20286
+ ...launch.revision === undefined ? undefined : { revision: launch.revision },
20287
+ ...launch.checks === undefined ? undefined : { checks: launch.checks },
20288
+ ...launch.rerunFailed === undefined ? undefined : { rerunFailed: launch.rerunFailed }
20289
+ });
20281
20290
  if (launch.measure !== undefined) {
20282
20291
  const measured = script.measurements?.[launch.step];
20283
20292
  const flat = Array.from({ length: launch.measure.samples }, () => Object.fromEntries(launch.measure?.plan.metrics.map((metric) => [metric.name, 100]) ?? []));
@@ -20328,6 +20337,7 @@ var testLoop = (loop, script) => {
20328
20337
  const agentLaunches = [];
20329
20338
  const childLaunches = [];
20330
20339
  const waits = [];
20340
+ const verifyLaunches = [];
20331
20341
  let latestSteps = [];
20332
20342
  const declared = capabilitiesOf(loop);
20333
20343
  const granted = new Set((script.grant ?? declared).filter((capability) => declared.includes(capability)));
@@ -20340,7 +20350,7 @@ var testLoop = (loop, script) => {
20340
20350
  const execute = (payload) => gen2(function* () {
20341
20351
  const engine = yield* WorkflowEngine;
20342
20352
  return yield* executeLoop(loop, {
20343
- host: scriptedHost(script, engine, agentLaunches, childLaunches, waits),
20353
+ host: scriptedHost(script, engine, agentLaunches, childLaunches, waits, verifyLaunches),
20344
20354
  activities,
20345
20355
  granted,
20346
20356
  onRun: (run) => {
@@ -20350,7 +20360,7 @@ var testLoop = (loop, script) => {
20350
20360
  });
20351
20361
  return gen2(function* () {
20352
20362
  const result = yield* exit2(workflow.execute({ input: script.input }).pipe(provideService2(ConfigProvider, fromUnknown(script.secrets ?? {}))));
20353
- return { result, steps: latestSteps, journal, activities: ran, agentLaunches, childLaunches, waits };
20363
+ return { result, steps: latestSteps, journal, activities: ran, agentLaunches, childLaunches, waits, verifyLaunches };
20354
20364
  }).pipe(provide4(workflow.toLayer(execute).pipe(provideMerge(layerMemory))));
20355
20365
  };
20356
20366
  // ../../packages/sdk/src/loop/review.ts
@@ -20990,14 +21000,41 @@ var release_default = defineLoop({
20990
21000
  const changeRequestId = input.changeRequestId;
20991
21001
  let gated;
20992
21002
  if (changeRequestId === undefined) {
20993
- const gate = yield* verify("gate", input.revision === undefined ? {} : { revision: input.revision });
21003
+ const gate = yield* verify("gate", {
21004
+ ...input.revision === undefined ? undefined : { revision: input.revision },
21005
+ rerunFailed: true
21006
+ });
20994
21007
  if (!gate.passed) {
20995
- const failing = gate.checks.filter((check) => check.status !== "passed").map((check) => check.name);
20996
- return {
20997
- status: "gate_failed",
20998
- reason: `The checks fail at ${gate.revision}: ${failing.join(", ")}`,
20999
- revision: gate.revision
21000
- };
21008
+ const failed = gate.checks.filter((check) => check.status !== "passed" && !check.preExisting);
21009
+ const retry = yield* verify("gate:retry", {
21010
+ revision: gate.revision,
21011
+ ...failed.length === 0 ? undefined : { checks: failed.map((check) => check.name) },
21012
+ rerunFailed: true
21013
+ });
21014
+ const environmental = failed.filter((check) => retry.checks.some((again) => again.name === check.name && again.status === "passed"));
21015
+ const names = environmental.map((check) => check.name).join(", ");
21016
+ if (environmental.length > 0)
21017
+ yield* artifact("environment-failure", {
21018
+ kind: "gate_environment_failure",
21019
+ title: `${names} failed on the gate's checkout at ${gate.revision}`,
21020
+ text: `These checks failed at ${gate.revision} and passed in a fresh checkout of it, so the first checkout's environment failed them, not the code: ${names}.`,
21021
+ data: {
21022
+ revision: gate.revision,
21023
+ checks: environmental.map((check) => ({
21024
+ name: check.name,
21025
+ failedEvidenceId: check.evidenceId,
21026
+ ...check.outputTail === undefined ? undefined : { outputTail: check.outputTail }
21027
+ }))
21028
+ }
21029
+ });
21030
+ const failing = retry.checks.filter((check) => check.status !== "passed").map((check) => check.name);
21031
+ if (!retry.passed || retry.checks.length === 0 || failing.length > 0) {
21032
+ return {
21033
+ status: "gate_failed",
21034
+ reason: `The checks fail at ${retry.revision}, and again in a fresh checkout: ${(failing.length > 0 ? failing : failed.map((check) => check.name)).join(", ")}`,
21035
+ revision: retry.revision
21036
+ };
21037
+ }
21001
21038
  }
21002
21039
  gated = gate.revision;
21003
21040
  } else {
@@ -21221,8 +21258,8 @@ var threadLine = (thread) => [
21221
21258
  ].join(`
21222
21259
  `);
21223
21260
  var ReviewFix = Struct({ summary: String5 });
21224
- var reviewFixPrompt = (findings) => [
21225
- "A review of the files the catch-up merge changed found these. Fix each blocker and major finding, with a test that shows it where one can. Kitman pushes what you leave.",
21261
+ var reviewFixPrompt = (reviewed, findings) => [
21262
+ `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.`,
21226
21263
  ...findings.map((finding) => `- ${finding.id} (${finding.severity}): ${finding.detail}`)
21227
21264
  ].join(`
21228
21265
  `);
@@ -21269,6 +21306,8 @@ var shepherd_default = defineLoop({
21269
21306
  const answered = new Set;
21270
21307
  const reranHeads = new Set;
21271
21308
  const ranOnRunner = new Set;
21309
+ const leftToPerson = new Set;
21310
+ let headFindings = [];
21272
21311
  let fixRounds = 0;
21273
21312
  let replies = 0;
21274
21313
  let stalledAt;
@@ -21458,7 +21497,7 @@ var shepherd_default = defineLoop({
21458
21497
  fixRounds++;
21459
21498
  yield* agentWork(`review-fix:${cycle}`, {
21460
21499
  agent: "implementer",
21461
- prompt: reviewFixPrompt(blocking),
21500
+ prompt: reviewFixPrompt("the files the catch-up merge changed", blocking),
21462
21501
  output: ReviewFix,
21463
21502
  timeout: stepBudget
21464
21503
  });
@@ -21488,12 +21527,68 @@ var shepherd_default = defineLoop({
21488
21527
  }
21489
21528
  ] : []
21490
21529
  ];
21491
- const approved = reviewedHere ? undefined : yield* waitFor(`approved:${cycle}`, {
21530
+ const approval = {
21492
21531
  event: "change_request.approval",
21493
21532
  filter: { changeRequestId, approved: true, head: pipeline.head },
21494
- timeout: "7 days",
21495
21533
  or: [commented, ...moved]
21496
- });
21534
+ };
21535
+ const byKitman = (wait) => wait.event === "change_request.approval" ? { ...wait, filter: { ...wait.filter, source: "kitman" } } : wait;
21536
+ let approved = reviewedHere || leftToPerson.has(pipeline.head) ? undefined : yield* waitFor(`approved:${cycle}`, {
21537
+ ...byKitman(approval),
21538
+ or: approval.or.map(byKitman),
21539
+ timeout: "1 minute"
21540
+ }).pipe(map8((woke) => woke.type === "change_request.approval" && woke.payload.source !== "kitman" ? undefined : woke), catchTag2("WaitTimedOut", () => undefined_2));
21541
+ if (!reviewedHere && approved === undefined) {
21542
+ const head = pipeline.head;
21543
+ const reviewIt = leftToPerson.has(head) ? "Wait" : yield* ask(`unapproved:${cycle}`, {
21544
+ prompt: `Nobody has approved ${head}, the head whose pipeline passed. Have Kitman review it?`,
21545
+ options: [
21546
+ {
21547
+ value: "Review",
21548
+ description: "Kitman's Review reads the whole change at this head and approves it if nothing blocks."
21549
+ },
21550
+ { value: "Wait", description: "Waits for a person to approve this head." }
21551
+ ],
21552
+ recommended: "Review",
21553
+ recommendationReason: "A passing Review of the whole change is what approved the head Build shipped.",
21554
+ default: "Wait",
21555
+ auto: "Review",
21556
+ timeout: "1 hour"
21557
+ });
21558
+ if (reviewIt === "Wait") {
21559
+ leftToPerson.add(head);
21560
+ approved = yield* waitFor(`approval:${cycle}`, { ...approval, timeout: "7 days" });
21561
+ } else {
21562
+ const reviewed = yield* call(`head-review:${cycle}`, reviewLoop(), {
21563
+ base: `origin/${target}`,
21564
+ head,
21565
+ ...headFindings.length === 0 ? undefined : { earlier: headFindings }
21566
+ });
21567
+ if (reviewed.blocking) {
21568
+ const blocking = reviewed.findings.filter(isBlocking);
21569
+ if (fixRounds >= (input.maxFixRounds ?? 3))
21570
+ return done("needs_you", `The review of ${head} still finds ${blocking.map((finding) => finding.id).join(", ")} after ${fixRounds} fix rounds`);
21571
+ fixRounds++;
21572
+ yield* agentWork(`head-fix:${cycle}`, {
21573
+ agent: "implementer",
21574
+ prompt: reviewFixPrompt(`the change at ${head}`, blocking),
21575
+ output: ReviewFix,
21576
+ timeout: stepBudget
21577
+ });
21578
+ headFindings = reviewed.findings;
21579
+ continue;
21580
+ }
21581
+ const recorded = yield* approveChangeRequest(`head-approve:${cycle}`, {
21582
+ changeRequestId,
21583
+ head,
21584
+ summary: `A review of the whole change at ${head} passed with nothing blocking.`,
21585
+ review: `head-review:${cycle}`
21586
+ }).pipe(catchTag2("StepFailed", (error) => succeed7({ approved: false, reason: error.reason })));
21587
+ if (!recorded.approved)
21588
+ return done("needs_you", `The review of ${head} passed, but did not approve it: ${recorded.reason}`);
21589
+ headFindings = [];
21590
+ }
21591
+ }
21497
21592
  if (approved !== undefined && approved.type !== "change_request.approval")
21498
21593
  continue;
21499
21594
  if (pipeline.source === "reported" && approved !== undefined && approved.payload.head !== pipeline.head)
@@ -21536,7 +21631,26 @@ var shepherd_default = defineLoop({
21536
21631
  if (ship === "Not now")
21537
21632
  return done("merged", `Merged at ${merged.revision}`);
21538
21633
  const released = yield* call("release", release_default, { revision: merged.revision });
21539
- if (released.status !== "deployed" && released.status !== "rejected")
21634
+ const handedOn = released.status === "gate_failed" && (yield* ask("release-gate-failed", {
21635
+ prompt: `Merged at ${merged.revision}, but its Release gate failed: ${released.reason}`,
21636
+ options: [
21637
+ {
21638
+ value: "Next Release",
21639
+ description: "Leaves the revision to the next Release, which gates it with the next merge."
21640
+ },
21641
+ { value: "Taken over", description: "A person looks at the failing checks from here." }
21642
+ ],
21643
+ recommended: "Next Release",
21644
+ recommendationReason: "Nothing was tagged or deployed, and the gate already ran the failure again in a fresh checkout.",
21645
+ default: null,
21646
+ auto: "Next Release"
21647
+ })) === "Next Release";
21648
+ if (handedOn)
21649
+ return {
21650
+ ...done("merged", `Merged at ${merged.revision}; its Release gate failed, so the next Release ships it`),
21651
+ release: { runStatus: released.status, reason: released.reason }
21652
+ };
21653
+ if (released.status !== "deployed" && released.status !== "rejected" && released.status !== "gate_failed")
21540
21654
  yield* ask("release-failed", {
21541
21655
  prompt: `Merged at ${merged.revision}, but its Release ended ${released.status}: ${released.reason}`,
21542
21656
  options: [{ value: "Taken over", description: "A person looks at the release and production from here." }],
@@ -26415,6 +26529,7 @@ class RunnerCapabilityRpcs extends make30(make29("PutQuestion", {
26415
26529
  revision: optionalKey2(String5),
26416
26530
  checks: optional2(ArraySchema(String5)),
26417
26531
  suggested: optionalKey2(ArraySchema(ApprovedCheck)),
26532
+ rerunFailed: optionalKey2(Boolean3),
26418
26533
  measure: optionalKey2(Struct({
26419
26534
  base: optionalKey2(String5),
26420
26535
  plan: MeasurePlan,
@@ -26906,6 +27021,7 @@ var runnerHost = (capabilities) => ({
26906
27021
  ...launch.revision === undefined ? undefined : { revision: launch.revision },
26907
27022
  ...launch.checks === undefined ? undefined : { checks: launch.checks },
26908
27023
  ...launch.suggested === undefined ? undefined : { suggested: launch.suggested },
27024
+ ...launch.rerunFailed === undefined ? undefined : { rerunFailed: launch.rerunFailed },
26909
27025
  ...launch.measure === undefined ? undefined : { measure: launch.measure }
26910
27026
  })).pipe(asVoid2),
26911
27027
  startAgentWork: (launch) => requested(launch.step, capabilities.startAgentStep({
@@ -27129,6 +27245,7 @@ var rpcProgramPorts = (rpc, work) => {
27129
27245
  ...verification.revision === undefined ? undefined : { revision: verification.revision },
27130
27246
  ...verification.checks === undefined ? undefined : { checks: [...verification.checks] },
27131
27247
  ...verification.suggested === undefined ? undefined : { suggested: [...verification.suggested] },
27248
+ ...verification.rerunFailed === undefined ? undefined : { rerunFailed: verification.rerunFailed },
27132
27249
  ...verification.measure === undefined ? undefined : { measure: verification.measure }
27133
27250
  }),
27134
27251
  startAgentStep: ({ secrets, ...step }) => rpc.startAgentStep({ lease, ...step, ...secrets === undefined ? undefined : { secrets: [...secrets] } }),
@@ -29421,4 +29538,4 @@ var runKit = (config, identity, packages) => {
29421
29538
  runMain2(program.pipe(flatMap3((code) => sync2(() => process.exit(code)))));
29422
29539
  };
29423
29540
  // .kitman-build-entry.ts
29424
- runKit(kitman_config_default, { name: "@kitman-sh/software-engineering", version: "0.10.67" }, []);
29541
+ runKit(kitman_config_default, { name: "@kitman-sh/software-engineering", version: "0.10.69" }, []);
@@ -3187,7 +3187,7 @@
3187
3187
  "carried": [
3188
3188
  {
3189
3189
  "name": "@kitman-sh/software-engineering",
3190
- "version": "0.10.67",
3190
+ "version": "0.10.69",
3191
3191
  "setup": "2a237548a69b0cd53ec3be7f687cfa8c2128335b3a655d34e185f2abce6a3c37",
3192
3192
  "loops": [
3193
3193
  "build",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitman-sh/software-engineering",
3
- "version": "0.10.67",
3
+ "version": "0.10.69",
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.67",
20
+ "@kitman-sh/sdk": "0.10.69",
21
21
  "effect": "4.1.2"
22
22
  },
23
23
  "kitman": {
24
24
  "bundle": "dist/bundle.js",
25
- "digest": "4bd344d8c4a782f44ae802170dcef5527a273a00afd95f2da831b27fbf7dfe30",
25
+ "digest": "27f761c2d200d215f836134dccfed9a3fa59b9cdd77877079250bd354d2a6f08",
26
26
  "protocolVersion": 5,
27
27
  "declarations": "dist/declarations.json",
28
28
  "setup": {
package/src/release.ts CHANGED
@@ -194,7 +194,8 @@ const recovery = (previous: string | undefined) =>
194
194
 
195
195
  /**
196
196
  * Proves the release before anyone is asked: the approved checks pass on the revision to tag, or a release
197
- * ChangeRequest is green, approved and mergeable. It then asks once, with no default, whether to release the drafted
197
+ * ChangeRequest is green, approved and mergeable. A failed check runs once more in a fresh checkout; one that passes
198
+ * there is recorded as an environment failure. It then asks once, with no default, whether to release the drafted
198
199
  * notes, which can be edited in place. On approval it merges the ChangeRequest when there is one, tags and publishes
199
200
  * once (a tag already released at the same revision counts as done; one at another is never moved), holds the deploy
200
201
  * target so two Releases never deploy over each other, and waits for the deploy. A failed or late deploy asks whether
@@ -225,16 +226,53 @@ export default defineLoop({
225
226
  let gated: string
226
227
 
227
228
  if (changeRequestId === undefined) {
228
- const gate = yield* verify('gate', input.revision === undefined ? {} : { revision: input.revision })
229
+ // A failure an earlier Release recorded at this tree may be its checkout's, so it is run again.
230
+ const gate = yield* verify('gate', {
231
+ ...(input.revision === undefined ? undefined : { revision: input.revision }),
232
+ rerunFailed: true
233
+ })
229
234
 
230
235
  if (!gate.passed) {
231
- const failing = gate.checks.filter(check => check.status !== 'passed').map(check => check.name)
236
+ const failed = gate.checks.filter(check => check.status !== 'passed' && !check.preExisting)
232
237
 
233
- return {
234
- status: 'gate_failed',
235
- reason: `The checks fail at ${gate.revision}: ${failing.join(', ')}`,
236
- revision: gate.revision
237
- } satisfies Output
238
+ // Once more in a fresh checkout of the same commit: a check that passes there failed on its environment.
239
+ const retry = yield* verify('gate:retry', {
240
+ revision: gate.revision,
241
+ ...(failed.length === 0 ? undefined : { checks: failed.map(check => check.name) }),
242
+ rerunFailed: true
243
+ })
244
+
245
+ const environmental = failed.filter(check =>
246
+ retry.checks.some(again => again.name === check.name && again.status === 'passed')
247
+ )
248
+
249
+ const names = environmental.map(check => check.name).join(', ')
250
+
251
+ if (environmental.length > 0)
252
+ yield* artifact('environment-failure', {
253
+ kind: 'gate_environment_failure',
254
+ title: `${names} failed on the gate's checkout at ${gate.revision}`,
255
+ text: `These checks failed at ${gate.revision} and passed in a fresh checkout of it, so the first checkout's environment failed them, not the code: ${names}.`,
256
+ data: {
257
+ revision: gate.revision,
258
+ checks: environmental.map(check => ({
259
+ name: check.name,
260
+ failedEvidenceId: check.evidenceId,
261
+ ...(check.outputTail === undefined ? undefined : { outputTail: check.outputTail })
262
+ }))
263
+ }
264
+ })
265
+
266
+ // A retry passes only when its checks passed: one failing again may read as pre-existing against a moved target.
267
+ const failing = retry.checks.filter(check => check.status !== 'passed').map(check => check.name)
268
+
269
+ if (!retry.passed || retry.checks.length === 0 || failing.length > 0) {
270
+ return {
271
+ status: 'gate_failed',
272
+ reason: `The checks fail at ${retry.revision}, and again in a fresh checkout: ${(failing.length > 0 ? failing : failed.map(check => check.name)).join(', ')}`,
273
+ revision: retry.revision
274
+ } satisfies Output
275
+ }
238
276
  }
239
277
 
240
278
  gated = gate.revision
package/src/shepherd.ts CHANGED
@@ -99,9 +99,9 @@ const threadLine = (thread: ReviewThreads['threads'][number]) =>
99
99
 
100
100
  const ReviewFix = Schema.Struct({ summary: Schema.String })
101
101
 
102
- const reviewFixPrompt = (findings: readonly MergedFinding[]) =>
102
+ const reviewFixPrompt = (reviewed: string, findings: readonly MergedFinding[]) =>
103
103
  [
104
- 'A review of the files the catch-up merge changed found these. Fix each blocker and major finding, with a test that shows it where one can. Kitman pushes what you leave.',
104
+ `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.`,
105
105
  ...findings.map(finding => `- ${finding.id} (${finding.severity}): ${finding.detail}`)
106
106
  ].join('\n')
107
107
 
@@ -169,6 +169,10 @@ export default defineLoop({
169
169
  const answered = new Set<string>()
170
170
  const reranHeads = new Set<string>()
171
171
  const ranOnRunner = new Set<string>()
172
+ /** Heads nobody approved whose approval was left to a person, so they are not asked about again. */
173
+ const leftToPerson = new Set<string>()
174
+ /** The last review of an unapproved head's open findings, for the review of the head that fixes them. */
175
+ let headFindings: readonly MergedFinding[] = []
172
176
  let fixRounds = 0
173
177
  let replies = 0
174
178
  let stalledAt: string | undefined
@@ -454,7 +458,7 @@ export default defineLoop({
454
458
 
455
459
  yield* agentWork(`review-fix:${cycle}`, {
456
460
  agent: 'implementer',
457
- prompt: reviewFixPrompt(blocking),
461
+ prompt: reviewFixPrompt('the files the catch-up merge changed', blocking),
458
462
  output: ReviewFix,
459
463
  timeout: stepBudget
460
464
  })
@@ -498,16 +502,101 @@ export default defineLoop({
498
502
  : [])
499
503
  ]
500
504
 
501
- const approved = reviewedHere
502
- ? undefined
503
- : yield* waitFor(`approved:${cycle}`, {
504
- event: 'change_request.approval',
505
- // An approval of an earlier commit does not approve the one whose pipeline passed.
506
- filter: { changeRequestId, approved: true, head: pipeline.head },
507
- timeout: '7 days',
508
- or: [commented, ...moved]
505
+ const approval = {
506
+ event: 'change_request.approval',
507
+ // An approval of an earlier commit does not approve the one whose pipeline passed.
508
+ filter: { changeRequestId, approved: true, head: pipeline.head },
509
+ or: [commented, ...moved]
510
+ }
511
+
512
+ // Kitman's approval of the head settles this at once, as Build's of the head it shipped does. A forge approval
513
+ // is no Kitman review, so it waits behind the question below, which a full-auto Team answers with a Review.
514
+ const byKitman = <Wait extends { readonly event: string; readonly filter: object }>(wait: Wait) =>
515
+ wait.event === 'change_request.approval' ? { ...wait, filter: { ...wait.filter, source: 'kitman' } } : wait
516
+
517
+ let approved =
518
+ reviewedHere || leftToPerson.has(pipeline.head)
519
+ ? undefined
520
+ : yield* waitFor(`approved:${cycle}`, {
521
+ ...byKitman(approval),
522
+ or: approval.or.map(byKitman),
523
+ timeout: '1 minute'
524
+ }).pipe(
525
+ Effect.map(woke =>
526
+ woke.type === 'change_request.approval' && woke.payload.source !== 'kitman' ? undefined : woke
527
+ ),
528
+ Effect.catchTag('WaitTimedOut', () => Effect.undefined)
529
+ )
530
+
531
+ if (!reviewedHere && approved === undefined) {
532
+ const head = pipeline.head
533
+
534
+ const reviewIt = leftToPerson.has(head)
535
+ ? 'Wait'
536
+ : yield* ask(`unapproved:${cycle}`, {
537
+ prompt: `Nobody has approved ${head}, the head whose pipeline passed. Have Kitman review it?`,
538
+ options: [
539
+ {
540
+ value: 'Review',
541
+ description:
542
+ "Kitman's Review reads the whole change at this head and approves it if nothing blocks."
543
+ },
544
+ { value: 'Wait', description: 'Waits for a person to approve this head.' }
545
+ ],
546
+ recommended: 'Review',
547
+ recommendationReason: 'A passing Review of the whole change is what approved the head Build shipped.',
548
+ default: 'Wait',
549
+ // A full-auto Team merges what its Review approved, including heads Shepherd pushed itself.
550
+ auto: 'Review',
551
+ timeout: '1 hour'
552
+ })
553
+
554
+ if (reviewIt === 'Wait') {
555
+ leftToPerson.add(head)
556
+ approved = yield* waitFor(`approval:${cycle}`, { ...approval, timeout: '7 days' })
557
+ } else {
558
+ const reviewed = yield* call(`head-review:${cycle}`, reviewLoop(), {
559
+ base: `origin/${target}`,
560
+ head,
561
+ ...(headFindings.length === 0 ? undefined : { earlier: headFindings })
509
562
  })
510
563
 
564
+ if (reviewed.blocking) {
565
+ const blocking = reviewed.findings.filter(isBlocking)
566
+
567
+ if (fixRounds >= (input.maxFixRounds ?? 3))
568
+ return done(
569
+ 'needs_you',
570
+ `The review of ${head} still finds ${blocking.map(finding => finding.id).join(', ')} after ${fixRounds} fix rounds`
571
+ )
572
+ fixRounds++
573
+
574
+ yield* agentWork(`head-fix:${cycle}`, {
575
+ agent: 'implementer',
576
+ prompt: reviewFixPrompt(`the change at ${head}`, blocking),
577
+ output: ReviewFix,
578
+ timeout: stepBudget
579
+ })
580
+ headFindings = reviewed.findings
581
+
582
+ continue
583
+ }
584
+
585
+ const recorded = yield* approveChangeRequest(`head-approve:${cycle}`, {
586
+ changeRequestId,
587
+ head,
588
+ summary: `A review of the whole change at ${head} passed with nothing blocking.`,
589
+ review: `head-review:${cycle}`
590
+ }).pipe(
591
+ Effect.catchTag('StepFailed', error => Effect.succeed({ approved: false as const, reason: error.reason }))
592
+ )
593
+
594
+ if (!recorded.approved)
595
+ return done('needs_you', `The review of ${head} passed, but did not approve it: ${recorded.reason}`)
596
+ headFindings = []
597
+ }
598
+ }
599
+
511
600
  if (approved !== undefined && approved.type !== 'change_request.approval') continue
512
601
 
513
602
  // The approval of a newer head woke a wait on a reported pipeline: that head needs its own pipeline first.
@@ -562,8 +651,34 @@ export default defineLoop({
562
651
 
563
652
  const released = yield* call('release', release, { revision: merged.revision })
564
653
 
654
+ // A failed gate changed nothing in production, and the next merge's Release gates this revision with its own.
655
+ const handedOn =
656
+ released.status === 'gate_failed' &&
657
+ (yield* ask('release-gate-failed', {
658
+ prompt: `Merged at ${merged.revision}, but its Release gate failed: ${released.reason}`,
659
+ options: [
660
+ {
661
+ value: 'Next Release',
662
+ description: 'Leaves the revision to the next Release, which gates it with the next merge.'
663
+ },
664
+ { value: 'Taken over', description: 'A person looks at the failing checks from here.' }
665
+ ],
666
+ recommended: 'Next Release',
667
+ recommendationReason:
668
+ 'Nothing was tagged or deployed, and the gate already ran the failure again in a fresh checkout.',
669
+ // No default: outside full auto a person decides.
670
+ default: null,
671
+ auto: 'Next Release'
672
+ })) === 'Next Release'
673
+
674
+ if (handedOn)
675
+ return {
676
+ ...done('merged', `Merged at ${merged.revision}; its Release gate failed, so the next Release ships it`),
677
+ release: { runStatus: released.status, reason: released.reason }
678
+ }
679
+
565
680
  // It merged either way; a Release that did not deploy, other than one a person rejected, needs a person.
566
- if (released.status !== 'deployed' && released.status !== 'rejected')
681
+ if (released.status !== 'deployed' && released.status !== 'rejected' && released.status !== 'gate_failed')
567
682
  yield* ask('release-failed', {
568
683
  prompt: `Merged at ${merged.revision}, but its Release ended ${released.status}: ${released.reason}`,
569
684
  options: [{ value: 'Taken over', description: 'A person looks at the release and production from here.' }],