@kitman-sh/software-engineering 0.10.68 → 0.10.70

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
@@ -13787,6 +13787,12 @@ var RunWaiting = Union2([
13787
13787
  name: String5.check(isMinLength(1)),
13788
13788
  verificationId: Id
13789
13789
  }),
13790
+ Struct({
13791
+ kind: Literal2("claim"),
13792
+ name: String5.check(isMinLength(1)),
13793
+ resource: String5.check(isMinLength(1)),
13794
+ holder: optionalKey2(Struct({ runId: Id, loopId: String5 }))
13795
+ }),
13790
13796
  Struct({
13791
13797
  kind: Literal2("queue"),
13792
13798
  name: String5.check(isMinLength(1)),
@@ -19067,6 +19073,7 @@ var verify = (name, request) => takeStep(name, "verify", "verify", gen2(function
19067
19073
  ...request.revision === undefined ? undefined : { revision: request.revision },
19068
19074
  ...request.checks === undefined ? undefined : { checks: request.checks },
19069
19075
  ...request.suggested === undefined || request.suggested.length === 0 ? undefined : { suggested: request.suggested },
19076
+ ...request.rerunFailed === true ? { rerunFailed: true } : undefined,
19070
19077
  token: token2
19071
19078
  }));
19072
19079
  return yield* await_2(deferred);
@@ -19248,7 +19255,10 @@ var PipelineStatus = Struct({
19248
19255
  source: Literals(["forge", "reported"]),
19249
19256
  jobs: ArraySchema(PipelineJob),
19250
19257
  readAt: optionalKey2(String5),
19251
- runnerChecks: optionalKey2(ArraySchema(String5))
19258
+ runnerChecks: optionalKey2(ArraySchema(String5)),
19259
+ approved: optionalKey2(String5),
19260
+ repository: optionalKey2(String5),
19261
+ target: optionalKey2(Struct({ branch: String5, head: String5, jobs: ArraySchema(PipelineJob) }))
19252
19262
  });
19253
19263
  var ReviewThread = Struct({
19254
19264
  id: String5,
@@ -19680,6 +19690,11 @@ var claim = (name, request) => gen2(function* () {
19680
19690
  return taken;
19681
19691
  return yield* new StepFailed({ step: name, reason: `${request.resource} is kept by ${holderName(taken.holder)}` });
19682
19692
  });
19693
+ var letGo = (name, held) => takeStep(name, "let_go", "claim", gen2(function* () {
19694
+ const deferred = letGoDeferred(name);
19695
+ yield* launch(deferred, (host, token) => host.claimResource({ step: name, resource: held.resource, action: "let_go", token }));
19696
+ yield* await_2(deferred);
19697
+ }));
19683
19698
 
19684
19699
  // ../../packages/core/src/repo-binding.ts
19685
19700
  var ForgeKinds = ["github", "gitlab", "forgejo", "gitea", "gitee", "bitbucket", "azure-devops"];
@@ -20249,7 +20264,7 @@ var journaled = (engine, journal, ran) => ({
20249
20264
  })
20250
20265
  });
20251
20266
  var scriptedExit = (scripted, failure) => scripted === undefined ? fail5(failure("nothing was scripted for this Step")) : scripted instanceof ScriptedFailure ? fail5(failure(scripted.reason)) : succeed4(scripted);
20252
- var scriptedHost = (script, engine, agentLaunches, childLaunches, waits) => {
20267
+ var scriptedHost = (script, engine, agentLaunches, childLaunches, waits, verifyLaunches) => {
20253
20268
  const resolve = (deferred, token, exit) => done4(deferred, { token, exit }).pipe(provideService2(WorkflowEngine, engine));
20254
20269
  return {
20255
20270
  startAgentWork: (launch) => andThen2(sync2(() => agentLaunches.push({
@@ -20276,9 +20291,16 @@ var scriptedHost = (script, engine, agentLaunches, childLaunches, waits) => {
20276
20291
  });
20277
20292
  return resolve(eventDeferred(launch.step), launch.token, event === undefined ? fail5(new WaitTimedOut({ step: launch.step, event: launch.event })) : succeed4(event));
20278
20293
  },
20279
- 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 })),
20294
+ claimResource: (launch) => flatMap3(script.claimed?.({ step: launch.step, resource: launch.resource, action: launch.action }) ?? undefined_2, (settled) => launch.action === "let_go" ? resolve(letGoDeferred(launch.step), launch.token, succeed4(null)) : resolve(claimDeferred(launch.step), launch.token, succeed4(settled ?? script.claims?.[launch.step] ?? { status: "granted", resource: launch.resource }))),
20280
20295
  startVerification: (launch) => {
20281
20296
  const scripted = script.verifications?.[launch.step];
20297
+ if (launch.measure === undefined)
20298
+ verifyLaunches.push({
20299
+ step: launch.step,
20300
+ ...launch.revision === undefined ? undefined : { revision: launch.revision },
20301
+ ...launch.checks === undefined ? undefined : { checks: launch.checks },
20302
+ ...launch.rerunFailed === undefined ? undefined : { rerunFailed: launch.rerunFailed }
20303
+ });
20282
20304
  if (launch.measure !== undefined) {
20283
20305
  const measured = script.measurements?.[launch.step];
20284
20306
  const flat = Array.from({ length: launch.measure.samples }, () => Object.fromEntries(launch.measure?.plan.metrics.map((metric) => [metric.name, 100]) ?? []));
@@ -20329,6 +20351,7 @@ var testLoop = (loop, script) => {
20329
20351
  const agentLaunches = [];
20330
20352
  const childLaunches = [];
20331
20353
  const waits = [];
20354
+ const verifyLaunches = [];
20332
20355
  let latestSteps = [];
20333
20356
  const declared = capabilitiesOf(loop);
20334
20357
  const granted = new Set((script.grant ?? declared).filter((capability) => declared.includes(capability)));
@@ -20341,7 +20364,7 @@ var testLoop = (loop, script) => {
20341
20364
  const execute = (payload) => gen2(function* () {
20342
20365
  const engine = yield* WorkflowEngine;
20343
20366
  return yield* executeLoop(loop, {
20344
- host: scriptedHost(script, engine, agentLaunches, childLaunches, waits),
20367
+ host: scriptedHost(script, engine, agentLaunches, childLaunches, waits, verifyLaunches),
20345
20368
  activities,
20346
20369
  granted,
20347
20370
  onRun: (run) => {
@@ -20351,7 +20374,7 @@ var testLoop = (loop, script) => {
20351
20374
  });
20352
20375
  return gen2(function* () {
20353
20376
  const result = yield* exit2(workflow.execute({ input: script.input }).pipe(provideService2(ConfigProvider, fromUnknown(script.secrets ?? {}))));
20354
- return { result, steps: latestSteps, journal, activities: ran, agentLaunches, childLaunches, waits };
20377
+ return { result, steps: latestSteps, journal, activities: ran, agentLaunches, childLaunches, waits, verifyLaunches };
20355
20378
  }).pipe(provide4(workflow.toLayer(execute).pipe(provideMerge(layerMemory))));
20356
20379
  };
20357
20380
  // ../../packages/sdk/src/loop/review.ts
@@ -20626,6 +20649,7 @@ var Input = Struct({
20626
20649
  head: optional2(String5),
20627
20650
  files: optional2(ArraySchema(String5)),
20628
20651
  since: optional2(String5),
20652
+ approved: optional2(String5),
20629
20653
  rebuttals: optional2(ArraySchema(Rebuttal)),
20630
20654
  outcome: optional2(LoopOutcome),
20631
20655
  claims: optional2(ArraySchema(String5)),
@@ -20635,9 +20659,13 @@ var Input = Struct({
20635
20659
  });
20636
20660
  var FollowUpStatus = Literals(["fixed", "changed", "still_there"]);
20637
20661
  var FollowUp = Struct({ id: String5, status: FollowUpStatus });
20662
+ var SeatFinding = Struct({
20663
+ ...Finding.fields,
20664
+ approvedCode: optional2(Boolean3)
20665
+ });
20638
20666
  var SeatOutput = Struct({
20639
20667
  summary: String5,
20640
- findings: ArraySchema(Finding),
20668
+ findings: ArraySchema(SeatFinding),
20641
20669
  verdicts: optional2(ArraySchema(RebuttalVerdict)),
20642
20670
  scope: optional2(ScopeJudgement),
20643
20671
  followUps: optional2(ArraySchema(FollowUp))
@@ -20645,6 +20673,7 @@ var SeatOutput = Struct({
20645
20673
  var Output = Struct({
20646
20674
  summary: String5,
20647
20675
  findings: ArraySchema(MergedFinding),
20676
+ approvedFindings: optional2(ArraySchema(MergedFinding)),
20648
20677
  followUps: ArraySchema(FollowUp),
20649
20678
  verdicts: ArraySchema(RebuttalVerdict),
20650
20679
  blocking: Boolean3,
@@ -20661,6 +20690,13 @@ class ReviewTargetMissing extends TaggedError3()("ReviewTargetMissing", {
20661
20690
  var targetOf = (input, head) => {
20662
20691
  if (input.changeRequestId !== undefined)
20663
20692
  return `ChangeRequest ${input.changeRequestId} at revision ${head}. Read it with \`kitman.changeRequests.get("${input.changeRequestId}")\` through Kitman's MCP, fetch its source branch, and review the diff of revision ${head} against its target branch, even if the branch has moved since. If the Runner cannot fetch that revision (a fork, say), report exactly that as your only finding, a blocker, and stop.`;
20693
+ if (input.base !== undefined && input.head !== undefined && input.files === undefined && input.approved !== undefined)
20694
+ return [
20695
+ `only what the change gained or lost since it was approved at ${input.approved}: compare \`git diff ${input.base}...${input.approved}\`, the change as approved, with \`git diff ${input.base}...${input.head}\`, the change now, in your checkout. The rest was reviewed and approved before.`,
20696
+ "Report a problem in code the change already had at the approved head only if it matters, with `approvedCode` set to true: such findings are kept apart and do not block."
20697
+ ].join(`
20698
+
20699
+ `);
20664
20700
  if (input.base !== undefined && input.head !== undefined)
20665
20701
  return input.files === undefined ? `the change \`git diff ${input.base}...${input.head}\` in your checkout.` : [
20666
20702
  `only these files of the change \`git diff ${input.base}...${input.head}\` in your checkout; the rest of it was reviewed and approved before:`,
@@ -20670,6 +20706,7 @@ var targetOf = (input, head) => {
20670
20706
  `);
20671
20707
  return;
20672
20708
  };
20709
+ var wholeChange = (input) => input.files === undefined && input.approved === undefined;
20673
20710
  var scopePrompt = (input) => [
20674
20711
  "If your brief has a Task, judge its scope and give it as `scope`: does the change do what the Task's description and each of its Acceptance Criteria ask? Set `met` to true only if it does all of it, and list in `unmet` one line for each criterion or part of the description that is not done. If your brief has no Task, leave `scope` out.",
20675
20712
  ...input.outcome === undefined ? [] : [`The Outcome to prove is ${input.outcome}.`],
@@ -20691,7 +20728,7 @@ var promptFor = (seat, target, input) => [
20691
20728
  "Give `summary`: one sentence on whether it can merge and what matters most.",
20692
20729
  "Report each problem as a finding: severity blocker (must not ship), major (fix before merge) or minor (optional); the file path from the repository root; the line; and the detail. When it is one instance of a class of bug, name every other instance in the diff in its detail. Report nothing you have not checked in the code.",
20693
20730
  "If the diff is too big to review in one go, review it directory by directory and say so in a finding on the first file you skipped.",
20694
- ...seat === scopeSeat && input.files === undefined ? [scopePrompt(input)] : [],
20731
+ ...seat === scopeSeat && wholeChange(input) ? [scopePrompt(input)] : [],
20695
20732
  ...input.earlier === undefined || input.earlier.length === 0 ? [] : [earlierPrompt(input.earlier)],
20696
20733
  ...input.failing === undefined || input.failing.length === 0 ? [] : [
20697
20734
  `These checks fail on this head and pass on the base: ${input.failing.join(", ")}. The implementer has their output, so do not report them as findings, and do not say it can merge while they fail.`
@@ -20711,12 +20748,13 @@ var followUpsOf = (earlier, answers) => earlier.map((finding) => {
20711
20748
  status: statuses.length === 0 ? "still_there" : statuses.reduce((worst, status) => rank2[status] < rank2[worst] ? status : worst)
20712
20749
  };
20713
20750
  });
20714
- var reviewText = (summary, findings, followUps) => [
20751
+ var findingLines = (findings) => findings.map((finding) => `- **${finding.severity}** \`${finding.id}\` ${finding.detail} _(${finding.seats.join(", ")})_`).join(`
20752
+ `);
20753
+ var reviewText = (summary, findings, followUps, approvedFindings) => [
20715
20754
  `**Kitman review.** ${summary}`,
20716
- ...findings.length === 0 ? [] : [
20717
- findings.map((finding) => `- **${finding.severity}** \`${finding.id}\` ${finding.detail} _(${finding.seats.join(", ")})_`).join(`
20718
- `)
20719
- ],
20755
+ ...findings.length === 0 ? [] : [findingLines(findings)],
20756
+ ...approvedFindings.length === 0 ? [] : [`In code approved before, not blocking:
20757
+ ${findingLines(approvedFindings)}`],
20720
20758
  ...followUps.length === 0 ? [] : [
20721
20759
  `Earlier findings:
20722
20760
  ${followUps.map((entry) => `- \`${entry.id}\` ${entry.status.replace("_", " ")}`).join(`
@@ -20732,7 +20770,7 @@ var fixBrief = (changeRequestId, findings) => [
20732
20770
  `);
20733
20771
  var review_default = defineLoop({
20734
20772
  id: "review",
20735
- version: "3.3.0",
20773
+ version: "3.4.0",
20736
20774
  title: "Review",
20737
20775
  input: Input,
20738
20776
  output: Output,
@@ -20777,22 +20815,25 @@ var review_default = defineLoop({
20777
20815
  };
20778
20816
  const carried = earlier.filter((finding) => standing.has(finding.id) && !withdrawn(finding.id));
20779
20817
  const followUps = answered.filter((entry) => !withdrawn(entry.id));
20780
- const fresh = mergeFindings(Object.fromEntries(outputs.map(([seat, output]) => [
20818
+ const sinceApproval = input.approved !== undefined && input.files === undefined;
20819
+ const merged = (approvedCode) => mergeFindings(Object.fromEntries(outputs.map(([seat, output]) => [
20781
20820
  seat,
20782
- output.findings.filter((finding) => !earlierIds.has(`${finding.file}:${finding.line}`))
20821
+ output.findings.filter((finding) => !earlierIds.has(`${finding.file}:${finding.line}`) && (sinceApproval && finding.approvedCode === true) === approvedCode)
20783
20822
  ])));
20823
+ const fresh = merged(false);
20824
+ const approvedFindings = sinceApproval ? merged(true) : [];
20784
20825
  const findings = [...carried, ...fresh];
20785
20826
  const blockers = findings.filter(isBlocking);
20786
- const scope = input.files === undefined ? outputs.find(([seat]) => seat === scopeSeat)?.[1].scope : undefined;
20827
+ const scope = wholeChange(input) ? outputs.find(([seat]) => seat === scopeSeat)?.[1].scope : undefined;
20787
20828
  const failing = input.failing ?? [];
20788
- const summary = blockers.length > 0 ? `Blocking: fix ${blockers.map((finding) => finding.id).join(", ")} before merging.` : scope?.met === false ? "Not ready: the change does not yet do what was asked." : failing.length > 0 ? `Not ready: ${failing.join(", ")} fails on this head.` : findings.length === 0 ? "No findings: nothing stands in the way of merging." : ["Can merge: nothing blocks it.", ...outputs.map(([, output]) => output.summary)].join(" ");
20829
+ const summary = blockers.length > 0 ? `Blocking: fix ${blockers.map((finding) => finding.id).join(", ")} before merging.` : scope?.met === false ? "Not ready: the change does not yet do what was asked." : failing.length > 0 ? `Not ready: ${failing.join(", ")} fails on this head.` : findings.length === 0 ? sinceApproval ? `No findings in what changed since ${input.approved}: nothing stands in the way of merging.` : "No findings: nothing stands in the way of merging." : ["Can merge: nothing blocks it.", ...outputs.map(([, output]) => output.summary)].join(" ");
20789
20830
  const freshIds = new Set(fresh.map((finding) => finding.id));
20790
- const text = reviewText(summary, findings, followUps);
20831
+ const text = reviewText(summary, findings, followUps, approvedFindings);
20791
20832
  const stored = yield* artifact("findings", {
20792
20833
  kind: "review-findings",
20793
20834
  title: "Review findings",
20794
20835
  text,
20795
- data: { findings, followUps }
20836
+ data: { findings, followUps, ...approvedFindings.length === 0 ? undefined : { approvedFindings } }
20796
20837
  });
20797
20838
  const reviewed = {
20798
20839
  summary,
@@ -20801,6 +20842,7 @@ var review_default = defineLoop({
20801
20842
  verdicts,
20802
20843
  blocking: findings.some(isBlocking),
20803
20844
  artifactId: stored.artifactId,
20845
+ ...approvedFindings.length === 0 ? undefined : { approvedFindings },
20804
20846
  ...scope === undefined ? undefined : { scope }
20805
20847
  };
20806
20848
  const changeRequestId = input.changeRequestId;
@@ -20991,14 +21033,41 @@ var release_default = defineLoop({
20991
21033
  const changeRequestId = input.changeRequestId;
20992
21034
  let gated;
20993
21035
  if (changeRequestId === undefined) {
20994
- const gate = yield* verify("gate", input.revision === undefined ? {} : { revision: input.revision });
21036
+ const gate = yield* verify("gate", {
21037
+ ...input.revision === undefined ? undefined : { revision: input.revision },
21038
+ rerunFailed: true
21039
+ });
20995
21040
  if (!gate.passed) {
20996
- const failing = gate.checks.filter((check) => check.status !== "passed").map((check) => check.name);
20997
- return {
20998
- status: "gate_failed",
20999
- reason: `The checks fail at ${gate.revision}: ${failing.join(", ")}`,
21000
- revision: gate.revision
21001
- };
21041
+ const failed = gate.checks.filter((check) => check.status !== "passed" && !check.preExisting);
21042
+ const retry = yield* verify("gate:retry", {
21043
+ revision: gate.revision,
21044
+ ...failed.length === 0 ? undefined : { checks: failed.map((check) => check.name) },
21045
+ rerunFailed: true
21046
+ });
21047
+ const environmental = failed.filter((check) => retry.checks.some((again) => again.name === check.name && again.status === "passed"));
21048
+ const names = environmental.map((check) => check.name).join(", ");
21049
+ if (environmental.length > 0)
21050
+ yield* artifact("environment-failure", {
21051
+ kind: "gate_environment_failure",
21052
+ title: `${names} failed on the gate's checkout at ${gate.revision}`,
21053
+ 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}.`,
21054
+ data: {
21055
+ revision: gate.revision,
21056
+ checks: environmental.map((check) => ({
21057
+ name: check.name,
21058
+ failedEvidenceId: check.evidenceId,
21059
+ ...check.outputTail === undefined ? undefined : { outputTail: check.outputTail }
21060
+ }))
21061
+ }
21062
+ });
21063
+ const failing = retry.checks.filter((check) => check.status !== "passed").map((check) => check.name);
21064
+ if (!retry.passed || retry.checks.length === 0 || failing.length > 0) {
21065
+ return {
21066
+ status: "gate_failed",
21067
+ reason: `The checks fail at ${retry.revision}, and again in a fresh checkout: ${(failing.length > 0 ? failing : failed.map((check) => check.name)).join(", ")}`,
21068
+ revision: retry.revision
21069
+ };
21070
+ }
21002
21071
  }
21003
21072
  gated = gate.revision;
21004
21073
  } else {
@@ -21173,23 +21242,30 @@ ${drafted.notes}`,
21173
21242
 
21174
21243
  // src/shepherd-output.ts
21175
21244
  var ShepherdOutput = Struct({
21176
- status: Literals(["merged", "ready", "needs_you"]),
21245
+ status: Literals(["merged", "ready", "needs_you", "handed_back"]),
21177
21246
  reason: String5,
21178
21247
  fixRounds: Int,
21179
21248
  replies: Int,
21180
- release: optional2(Struct({ runStatus: String5, reason: String5, tag: optional2(String5) }))
21249
+ release: optional2(Struct({ runStatus: String5, reason: String5, tag: optional2(String5) })),
21250
+ handBack: optional2(Struct({
21251
+ changeRequestId: String5,
21252
+ words: String5,
21253
+ taskId: optional2(String5),
21254
+ branch: optional2(String5)
21255
+ }))
21181
21256
  });
21182
21257
 
21183
21258
  // src/shepherd.ts
21184
21259
  var reviewLoop = () => ({ id: "review", input: Input, output: Output });
21185
21260
  var stepBudget = "45 minutes";
21261
+ var roundLimits = { "ci-fix": 1, "head-fix": 2 };
21262
+ var handBackAnswer = "Hand back to Build";
21186
21263
  var Input3 = Struct({
21187
21264
  changeRequestId: String5,
21188
21265
  taskId: optional2(String5),
21189
21266
  merge: optional2(Boolean3),
21190
21267
  branch: optional2(String5),
21191
21268
  continuing: optional2(Continuing),
21192
- maxFixRounds: optional2(Int),
21193
21269
  maxCycles: optional2(Int)
21194
21270
  });
21195
21271
  var Output3 = ShepherdOutput;
@@ -21207,24 +21283,39 @@ var Replies = Struct({
21207
21283
  var failedJobs = (pipeline) => pipeline.jobs.flatMap((job) => job.status === "failed" ? [`### ${job.name}${job.url === undefined ? "" : ` (${job.url})`}
21208
21284
 
21209
21285
  ${job.logTail ?? "No log was served."}`] : []);
21210
- var ciFixPrompt = (pipeline, target) => [
21211
- `The pipeline at ${pipeline.head} failed. These jobs failed, with the end of each log:`,
21212
- ...failedJobs(pipeline),
21213
- "Run the failing job once more here to rule out a flake; if it passes, change nothing and answer flaky.",
21214
- `Then run it on the target branch (a worktree of \`origin/${target}\`, which Kitman fetched just before this Step; do not fetch). If it fails there too, the branch did not cause it: change nothing and answer pre_existing.`,
21215
- "Otherwise it is this branch's own failure: write or fix a test that shows it first, then fix it, and answer fixed. Kitman pushes what you leave."
21216
- ].join(`
21286
+ var failingJobs = (pipeline) => pipeline.jobs.flatMap((job) => job.status === "failed" ? [job.name] : []);
21287
+ var ciFixPrompt = (pipeline, target, onTarget) => {
21288
+ const unknown = failingJobs(pipeline).filter((name) => !onTarget.failed.includes(name) && !onTarget.passed.includes(name));
21289
+ return [
21290
+ `The pipeline at ${pipeline.head} failed. These jobs failed, with the end of each log:`,
21291
+ ...failedJobs(pipeline),
21292
+ "Run the failing job once more here to rule out a flake; if it passes, change nothing and answer flaky.",
21293
+ ...onTarget.passed.length === 0 ? [] : [
21294
+ `Kitman ran ${onTarget.passed.join(", ")} at the head of \`origin/${target}\` and they passed there, so do not run them on the target branch.`
21295
+ ],
21296
+ ...onTarget.failed.length === 0 ? [] : [
21297
+ `${onTarget.failed.join(", ")} fail at the head of \`origin/${target}\` too: they are the target's to fix, so leave them as they are.`
21298
+ ],
21299
+ ...unknown.length === 0 ? [] : [
21300
+ `Run ${unknown.join(", ")} on the target branch (a worktree of \`origin/${target}\`, which Kitman fetched just before this Step; do not fetch). If every failing job fails there too, the branch did not cause it: change nothing and answer pre_existing.`
21301
+ ],
21302
+ "Otherwise it is this branch's own failure: write or fix a test that shows it first, then fix it, and answer fixed. Kitman pushes what you leave."
21303
+ ].join(`
21217
21304
 
21218
21305
  `);
21306
+ };
21307
+ var turnResource = (target, repository) => `merge:${repository === undefined ? "" : `${repository}:`}${target}`.toLowerCase().replace(/[^a-z0-9._:-]+/g, "-").slice(0, 128);
21219
21308
  var threadLine = (thread) => [
21220
21309
  `### Thread ${thread.id}${thread.path === undefined ? "" : ` on ${thread.path}${thread.line === undefined ? "" : `:${thread.line}`}`}`,
21221
21310
  ...thread.comments.map((entry) => `${entry.author ?? "someone"}: ${entry.body}`)
21222
21311
  ].join(`
21223
21312
  `);
21224
21313
  var ReviewFix = Struct({ summary: String5 });
21314
+ var findingLines2 = (findings) => findings.map((finding) => `- ${finding.id} (${finding.severity}): ${finding.detail}`).join(`
21315
+ `);
21225
21316
  var reviewFixPrompt = (reviewed, findings) => [
21226
21317
  `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.`,
21227
- ...findings.map((finding) => `- ${finding.id} (${finding.severity}): ${finding.detail}`)
21318
+ findingLines2(findings)
21228
21319
  ].join(`
21229
21320
  `);
21230
21321
  var catchUpVerdict = (catchUp) => {
@@ -21246,7 +21337,7 @@ var repliesPrompt = (threads) => [
21246
21337
  var threadKey = (thread) => `${thread.id}:${thread.comments.length}`;
21247
21338
  var shepherd_default = defineLoop({
21248
21339
  id: "shepherd",
21249
- version: "1.1.0",
21340
+ version: "1.2.0",
21250
21341
  title: "Shepherd",
21251
21342
  input: Input3,
21252
21343
  output: Output3,
@@ -21261,9 +21352,11 @@ var shepherd_default = defineLoop({
21261
21352
  "call",
21262
21353
  "write_back",
21263
21354
  "ask",
21264
- "verify"
21355
+ "verify",
21356
+ "claim"
21265
21357
  ],
21266
21358
  calls: () => [review_default, release_default],
21359
+ offers: [{ id: "build", title: "Hand back to Build", loop: "build", from: "handBack" }],
21267
21360
  run: (input) => {
21268
21361
  const changeRequestId = input.changeRequestId;
21269
21362
  const target = input.continuing?.targetBranch ?? input.branch ?? "HEAD";
@@ -21272,7 +21365,8 @@ var shepherd_default = defineLoop({
21272
21365
  const ranOnRunner = new Set;
21273
21366
  const leftToPerson = new Set;
21274
21367
  let headFindings = [];
21275
- let fixRounds = 0;
21368
+ const rounds = { "ci-fix": 0, "head-fix": 0 };
21369
+ const allowed = { "ci-fix": 0, "head-fix": 0 };
21276
21370
  let replies = 0;
21277
21371
  let stalledAt;
21278
21372
  let stalls = 0;
@@ -21280,7 +21374,65 @@ var shepherd_default = defineLoop({
21280
21374
  let notCarried;
21281
21375
  let behind = false;
21282
21376
  let pushed;
21283
- const done = (status, reason) => ({ status, reason, fixRounds, replies });
21377
+ let turn;
21378
+ let turns = 0;
21379
+ let passes = 0;
21380
+ let repository;
21381
+ let redTarget;
21382
+ const fixRounds = () => rounds["ci-fix"] + rounds["head-fix"];
21383
+ const done = (status, reason) => ({
21384
+ status,
21385
+ reason,
21386
+ fixRounds: fixRounds(),
21387
+ replies
21388
+ });
21389
+ const handBack = (reason, open) => ({
21390
+ ...done("handed_back", reason),
21391
+ handBack: {
21392
+ changeRequestId,
21393
+ words: `Shepherd handed ChangeRequest ${changeRequestId} back: ${reason}. Fix it forward on its branch:
21394
+ ${open}`,
21395
+ ...input.taskId === undefined ? undefined : { taskId: input.taskId },
21396
+ ...target === "HEAD" ? undefined : { branch: target }
21397
+ }
21398
+ });
21399
+ const takeTurn = () => gen2(function* () {
21400
+ if (turn !== undefined)
21401
+ return;
21402
+ return yield* claim(`turn:${++turns}`, { resource: turnResource(target, repository) }).pipe(map8((granted) => {
21403
+ turn = granted;
21404
+ return;
21405
+ }), catchTag2("StepFailed", (error) => succeed7(error.reason)));
21406
+ });
21407
+ const passTurn = () => gen2(function* () {
21408
+ if (turn === undefined)
21409
+ return;
21410
+ const held = turn;
21411
+ turn = undefined;
21412
+ yield* letGo(`pass-turn:${++passes}`, held);
21413
+ });
21414
+ const mayFix = (kind, cycle, open) => gen2(function* () {
21415
+ if (rounds[kind] < roundLimits[kind] + allowed[kind])
21416
+ return true;
21417
+ const answer = yield* ask(`rounds:${cycle}`, {
21418
+ prompt: `Shepherd has run ${rounds[kind]} ${kind} rounds, its limit, and ${open} still stands. Hand the ChangeRequest back to Build?`,
21419
+ options: [
21420
+ {
21421
+ value: handBackAnswer,
21422
+ description: "Stops here; the ChangeRequest stays open, with a Build offer that carries what is open."
21423
+ },
21424
+ { value: "One more round", description: `Runs one more ${kind} round here.` }
21425
+ ],
21426
+ recommended: handBackAnswer,
21427
+ recommendationReason: "More rounds here have not settled it, and Build fixes and reviews the change as a whole.",
21428
+ default: handBackAnswer,
21429
+ auto: handBackAnswer,
21430
+ timeout: "1 hour"
21431
+ });
21432
+ if (answer !== handBackAnswer)
21433
+ allowed[kind]++;
21434
+ return answer !== handBackAnswer;
21435
+ });
21284
21436
  const runOnRunner = (step, cycle, head, checks) => gen2(function* () {
21285
21437
  const verification = `pipeline-${step}:${cycle}`;
21286
21438
  const failed = yield* verify(verification, { revision: head, checks }).pipe(as2(undefined), catchTag2("StepFailed", (error) => succeed7(error.reason)));
@@ -21291,6 +21443,86 @@ var shepherd_default = defineLoop({
21291
21443
  });
21292
21444
  return failed;
21293
21445
  });
21446
+ const checkTarget = (cycle, pipeline) => gen2(function* () {
21447
+ const failing = failingJobs(pipeline);
21448
+ const onForge = (pipeline.target?.jobs ?? []).filter((job) => failing.includes(job.name));
21449
+ const failed = onForge.flatMap((job) => job.status === "failed" ? [job.name] : []);
21450
+ const passed = onForge.flatMap((job) => job.status === "success" ? [job.name] : []);
21451
+ const onRunner = failing.filter((name) => !failed.includes(name) && !passed.includes(name) && (pipeline.runnerChecks ?? []).includes(name));
21452
+ if (onRunner.length === 0)
21453
+ return { failed, passed };
21454
+ const atTarget = yield* verify(`target-check:${cycle}`, {
21455
+ revision: `origin/${target}`,
21456
+ checks: onRunner
21457
+ }).pipe(catchTag2("StepFailed", () => undefined_2));
21458
+ const ran = atTarget?.checks.filter((check) => onRunner.includes(check.name)) ?? [];
21459
+ return {
21460
+ failed: [...failed, ...ran.flatMap((check) => check.status === "failed" ? [check.name] : [])],
21461
+ passed: [...passed, ...ran.flatMap((check) => check.status === "passed" ? [check.name] : [])]
21462
+ };
21463
+ });
21464
+ const waitOutTarget = (cycle, pipeline, why) => gen2(function* () {
21465
+ yield* passTurn();
21466
+ yield* note(`target-red:${cycle}`, {
21467
+ text: `Shepherd is waiting for ${target} to change instead of fixing ${pipeline.head}: ${why}`
21468
+ }).pipe(catchTag2("StepFailed", () => void_3));
21469
+ const woke = yield* waitFor(`target-moved:${cycle}`, {
21470
+ event: "change_request.closed",
21471
+ filter: {
21472
+ merged: true,
21473
+ ...target === "HEAD" ? undefined : { targetBranch: target },
21474
+ ...repository === undefined ? undefined : { repository }
21475
+ },
21476
+ or: [{ event: "change_request.closed", filter: { changeRequestId } }],
21477
+ timeout: "1 hour",
21478
+ ...pipeline.readAt === undefined ? undefined : { since: pipeline.readAt }
21479
+ }).pipe(catchTag2("WaitTimedOut", () => undefined_2));
21480
+ if (woke?.payload.changeRequestId === changeRequestId)
21481
+ return woke.payload.merged === true ? done("merged", "Someone else merged the ChangeRequest") : done("needs_you", "The ChangeRequest was closed");
21482
+ redTarget = { head: pipeline.head, targetHead: pipeline.target?.head, moved: woke !== undefined };
21483
+ return;
21484
+ });
21485
+ const catchUp = (cycle) => gen2(function* () {
21486
+ const refused = yield* takeTurn();
21487
+ if (refused !== undefined)
21488
+ return done("needs_you", `The turn to merge into ${target} was refused: ${refused}`);
21489
+ const synced = yield* syncBase(`sync:${cycle}`, { agent: "implementer", target });
21490
+ if (synced.status === "conflict")
21491
+ return done("needs_you", `Merging ${target} in conflicts on ${synced.files.join(", ")}: ${synced.reason}`);
21492
+ if (synced.status !== "merged")
21493
+ return;
21494
+ const caught = synced.catchUp;
21495
+ const verdict = caught === undefined ? { kind: "changed", why: "its Runner did not report what it did to the branch" } : catchUpVerdict(caught);
21496
+ if (verdict.kind === "changed") {
21497
+ unreviewed = undefined;
21498
+ notCarried = `merging ${target} in changed it: ${verdict.why}`;
21499
+ } else if (caught !== undefined && unreviewed !== undefined) {
21500
+ const files = [...new Set([...unreviewed.files, ...verdict.kind === "review" ? verdict.files : []])];
21501
+ unreviewed = caught.from === unreviewed.synced ? { ...unreviewed, files, synced: caught.head } : { ...unreviewed, files };
21502
+ } else if (caught !== undefined && verdict.kind === "review") {
21503
+ notCarried = undefined;
21504
+ unreviewed = { files: verdict.files, synced: caught.head, sync: `sync:${cycle}`, earlier: [] };
21505
+ } else if (caught !== undefined) {
21506
+ notCarried = undefined;
21507
+ const carried = yield* approveChangeRequest(`carry:${cycle}`, {
21508
+ changeRequestId,
21509
+ head: caught.head,
21510
+ summary: `Merging ${target} in left the branch's own diff as it was approved.`,
21511
+ carries: `sync:${cycle}`
21512
+ }).pipe(catchTag2("StepFailed", (error) => succeed7({ approved: false, reason: error.reason })));
21513
+ if (!carried.approved)
21514
+ notCarried = `the approval was not carried: ${carried.reason}`;
21515
+ }
21516
+ if (caught !== undefined) {
21517
+ pushed = { head: caught.head, stale: 0 };
21518
+ yield* waitFor(`pushed:${cycle}`, {
21519
+ event: "change_request.mergeable",
21520
+ filter: { changeRequestId, head: caught.head },
21521
+ timeout: "5 minutes"
21522
+ }).pipe(catchTag2("WaitTimedOut", () => void_3));
21523
+ }
21524
+ return;
21525
+ });
21294
21526
  return gen2(function* () {
21295
21527
  for (let cycle = 1;; cycle++) {
21296
21528
  if (cycle > (input.maxCycles ?? 20)) {
@@ -21306,6 +21538,7 @@ var shepherd_default = defineLoop({
21306
21538
  return done("needs_you", `Stopped after ${cycle - 1} looks without landing it`);
21307
21539
  }
21308
21540
  const pipeline = yield* pipelineStatus(`pipeline:${cycle}`, { changeRequestId });
21541
+ repository = pipeline.repository ?? repository;
21309
21542
  if (pushed !== undefined && pipeline.head !== pushed.head) {
21310
21543
  if (++pushed.stale > 5)
21311
21544
  return done("needs_you", `The forge still shows ${pipeline.head}, not ${pushed.head} that the catch-up pushed`);
@@ -21332,24 +21565,61 @@ var shepherd_default = defineLoop({
21332
21565
  continue;
21333
21566
  }
21334
21567
  if (pipeline.status === "failed" || pipeline.status === "canceled") {
21568
+ const targetMoved = redTarget?.head === pipeline.head && (redTarget.targetHead !== undefined && pipeline.target !== undefined ? pipeline.target.head !== redTarget.targetHead : redTarget.moved);
21569
+ if (targetMoved) {
21570
+ redTarget = undefined;
21571
+ const stopped = yield* catchUp(cycle);
21572
+ if (stopped !== undefined)
21573
+ return stopped;
21574
+ continue;
21575
+ }
21576
+ const onTarget = yield* checkTarget(cycle, pipeline);
21577
+ const failing = failingJobs(pipeline);
21578
+ if (failing.length > 0 && failing.every((name) => onTarget.failed.includes(name))) {
21579
+ const stopped = yield* waitOutTarget(cycle, pipeline, `${target} fails ${failing.join(", ")} at its own head too, so no fix here can mend it`);
21580
+ if (stopped !== undefined)
21581
+ return stopped;
21582
+ continue;
21583
+ }
21584
+ if (onTarget.passed.length > 0 && redTarget?.head === pipeline.head) {
21585
+ redTarget = undefined;
21586
+ const stopped = yield* catchUp(cycle);
21587
+ if (stopped !== undefined)
21588
+ return stopped;
21589
+ continue;
21590
+ }
21591
+ if (redTarget?.head === pipeline.head) {
21592
+ const stopped = yield* waitOutTarget(cycle, pipeline, `${target} still fails as ${pipeline.head} does`);
21593
+ if (stopped !== undefined)
21594
+ return stopped;
21595
+ continue;
21596
+ }
21335
21597
  if (stalledAt === pipeline.head)
21336
21598
  stalls++;
21337
21599
  else
21338
21600
  stalls = 0;
21339
21601
  if (stalls >= 2)
21340
21602
  return done("needs_you", `Two fixes pushed nothing new; the pipeline at ${pipeline.head} still fails`);
21341
- if (fixRounds >= (input.maxFixRounds ?? 3))
21342
- return done("needs_you", `The pipeline still fails after ${fixRounds} fix rounds`);
21343
- fixRounds++;
21603
+ if (!(yield* mayFix("ci-fix", cycle, `the failing pipeline at ${pipeline.head}`)))
21604
+ return handBack(`The pipeline at ${pipeline.head} still fails after ${rounds["ci-fix"]} ci-fix rounds`, failedJobs(pipeline).join(`
21605
+
21606
+ `));
21344
21607
  stalledAt = pipeline.head;
21608
+ yield* passTurn();
21345
21609
  const fixed = yield* agentWork(`ci-fix:${cycle}`, {
21346
21610
  agent: "implementer",
21347
- prompt: ciFixPrompt(pipeline, target),
21611
+ prompt: ciFixPrompt(pipeline, target, onTarget),
21348
21612
  output: CiFix,
21349
21613
  timeout: stepBudget
21350
21614
  });
21351
- if (fixed.verdict === "pre_existing")
21352
- return done("needs_you", `The failure is pre-existing on the target branch: ${fixed.summary}`);
21615
+ if (fixed.verdict === "fixed")
21616
+ rounds["ci-fix"]++;
21617
+ if (fixed.verdict === "pre_existing") {
21618
+ const stopped = yield* waitOutTarget(cycle, pipeline, `the failure is pre-existing on the target branch: ${fixed.summary}`);
21619
+ if (stopped !== undefined)
21620
+ return stopped;
21621
+ continue;
21622
+ }
21353
21623
  if (fixed.verdict === "flaky") {
21354
21624
  if (pipeline.source === "reported") {
21355
21625
  if (pipeline.runnerChecks === undefined)
@@ -21370,8 +21640,10 @@ var shepherd_default = defineLoop({
21370
21640
  }
21371
21641
  continue;
21372
21642
  }
21643
+ redTarget = undefined;
21373
21644
  const threads = (yield* reviewThreads(`threads:${cycle}`, { changeRequestId })).threads.filter((thread) => !answered.has(threadKey(thread)));
21374
21645
  if (threads.length > 0) {
21646
+ yield* passTurn();
21375
21647
  const answers = yield* agentWork(`comments:${cycle}`, {
21376
21648
  agent: "implementer",
21377
21649
  prompt: repliesPrompt(threads),
@@ -21406,47 +21678,16 @@ var shepherd_default = defineLoop({
21406
21678
  continue;
21407
21679
  if (mergeable.payload.mergeable === false || behind) {
21408
21680
  behind = false;
21409
- const synced = yield* syncBase(`sync:${cycle}`, { agent: "implementer", target });
21410
- if (synced.status === "conflict")
21411
- return done("needs_you", `Merging ${target} in conflicts on ${synced.files.join(", ")}: ${synced.reason}`);
21412
- if (synced.status === "merged") {
21413
- const caught = synced.catchUp;
21414
- const verdict = caught === undefined ? { kind: "changed", why: "its Runner did not report what it did to the branch" } : catchUpVerdict(caught);
21415
- if (verdict.kind === "changed") {
21416
- unreviewed = undefined;
21417
- notCarried = `merging ${target} in changed it: ${verdict.why}`;
21418
- } else if (caught !== undefined && unreviewed !== undefined) {
21419
- const files = [...new Set([...unreviewed.files, ...verdict.kind === "review" ? verdict.files : []])];
21420
- unreviewed = caught.from === unreviewed.synced ? { ...unreviewed, files, synced: caught.head } : { ...unreviewed, files };
21421
- } else if (caught !== undefined && verdict.kind === "review") {
21422
- notCarried = undefined;
21423
- unreviewed = { files: verdict.files, synced: caught.head, sync: `sync:${cycle}`, earlier: [] };
21424
- } else if (caught !== undefined) {
21425
- notCarried = undefined;
21426
- const carried = yield* approveChangeRequest(`carry:${cycle}`, {
21427
- changeRequestId,
21428
- head: caught.head,
21429
- summary: `Merging ${target} in left the branch's own diff as it was approved.`,
21430
- carries: `sync:${cycle}`
21431
- }).pipe(catchTag2("StepFailed", (error) => succeed7({ approved: false, reason: error.reason })));
21432
- if (!carried.approved)
21433
- notCarried = `the approval was not carried: ${carried.reason}`;
21434
- }
21435
- if (caught !== undefined) {
21436
- pushed = { head: caught.head, stale: 0 };
21437
- yield* waitFor(`pushed:${cycle}`, {
21438
- event: "change_request.mergeable",
21439
- filter: { changeRequestId, head: caught.head },
21440
- timeout: "5 minutes"
21441
- }).pipe(catchTag2("WaitTimedOut", () => void_3));
21442
- }
21443
- }
21681
+ const stopped = yield* catchUp(cycle);
21682
+ if (stopped !== undefined)
21683
+ return stopped;
21444
21684
  continue;
21445
21685
  }
21446
21686
  let reviewedHere = false;
21447
21687
  if (unreviewed !== undefined) {
21448
21688
  const files = unreviewed;
21449
21689
  const head = pipeline.head;
21690
+ yield* passTurn();
21450
21691
  const reviewed = yield* call(`review:${cycle}`, reviewLoop(), {
21451
21692
  base: `origin/${target}`,
21452
21693
  head,
@@ -21456,9 +21697,9 @@ var shepherd_default = defineLoop({
21456
21697
  });
21457
21698
  if (reviewed.blocking) {
21458
21699
  const blocking = reviewed.findings.filter(isBlocking);
21459
- if (fixRounds >= (input.maxFixRounds ?? 3))
21460
- return done("needs_you", `The review of the catch-up merge's files still finds ${blocking.map((finding) => finding.id).join(", ")} after ${fixRounds} fix rounds`);
21461
- fixRounds++;
21700
+ if (!(yield* mayFix("head-fix", cycle, blocking.map((finding) => finding.id).join(", "))))
21701
+ 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));
21702
+ rounds["head-fix"]++;
21462
21703
  yield* agentWork(`review-fix:${cycle}`, {
21463
21704
  agent: "implementer",
21464
21705
  prompt: reviewFixPrompt("the files the catch-up merge changed", blocking),
@@ -21504,21 +21745,23 @@ var shepherd_default = defineLoop({
21504
21745
  }).pipe(map8((woke) => woke.type === "change_request.approval" && woke.payload.source !== "kitman" ? undefined : woke), catchTag2("WaitTimedOut", () => undefined_2));
21505
21746
  if (!reviewedHere && approved === undefined) {
21506
21747
  const head = pipeline.head;
21748
+ const since = pipeline.approved === undefined || pipeline.approved === head ? undefined : pipeline.approved;
21507
21749
  const reviewIt = leftToPerson.has(head) ? "Wait" : yield* ask(`unapproved:${cycle}`, {
21508
21750
  prompt: `Nobody has approved ${head}, the head whose pipeline passed. Have Kitman review it?`,
21509
21751
  options: [
21510
21752
  {
21511
21753
  value: "Review",
21512
- description: "Kitman's Review reads the whole change at this head and approves it if nothing blocks."
21754
+ 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.`
21513
21755
  },
21514
21756
  { value: "Wait", description: "Waits for a person to approve this head." }
21515
21757
  ],
21516
21758
  recommended: "Review",
21517
- recommendationReason: "A passing Review of the whole change is what approved the head Build shipped.",
21759
+ recommendationReason: "A passing Review of the change is what approved the head Build shipped.",
21518
21760
  default: "Wait",
21519
21761
  auto: "Review",
21520
21762
  timeout: "1 hour"
21521
21763
  });
21764
+ yield* passTurn();
21522
21765
  if (reviewIt === "Wait") {
21523
21766
  leftToPerson.add(head);
21524
21767
  approved = yield* waitFor(`approval:${cycle}`, { ...approval, timeout: "7 days" });
@@ -21526,16 +21769,17 @@ var shepherd_default = defineLoop({
21526
21769
  const reviewed = yield* call(`head-review:${cycle}`, reviewLoop(), {
21527
21770
  base: `origin/${target}`,
21528
21771
  head,
21772
+ ...since === undefined ? undefined : { approved: since },
21529
21773
  ...headFindings.length === 0 ? undefined : { earlier: headFindings }
21530
21774
  });
21531
21775
  if (reviewed.blocking) {
21532
21776
  const blocking = reviewed.findings.filter(isBlocking);
21533
- if (fixRounds >= (input.maxFixRounds ?? 3))
21534
- return done("needs_you", `The review of ${head} still finds ${blocking.map((finding) => finding.id).join(", ")} after ${fixRounds} fix rounds`);
21535
- fixRounds++;
21777
+ if (!(yield* mayFix("head-fix", cycle, blocking.map((finding) => finding.id).join(", "))))
21778
+ return handBack(`The review of ${head} still finds ${blocking.map((finding) => finding.id).join(", ")} after ${rounds["head-fix"]} head-fix rounds`, findingLines2(blocking));
21779
+ rounds["head-fix"]++;
21536
21780
  yield* agentWork(`head-fix:${cycle}`, {
21537
21781
  agent: "implementer",
21538
- prompt: reviewFixPrompt(`the change at ${head}`, blocking),
21782
+ prompt: reviewFixPrompt(since === undefined ? `the change at ${head}` : `what changed between ${since} and ${head}`, blocking),
21539
21783
  output: ReviewFix,
21540
21784
  timeout: stepBudget
21541
21785
  });
@@ -21545,7 +21789,7 @@ var shepherd_default = defineLoop({
21545
21789
  const recorded = yield* approveChangeRequest(`head-approve:${cycle}`, {
21546
21790
  changeRequestId,
21547
21791
  head,
21548
- summary: `A review of the whole change at ${head} passed with nothing blocking.`,
21792
+ 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.`,
21549
21793
  review: `head-review:${cycle}`
21550
21794
  }).pipe(catchTag2("StepFailed", (error) => succeed7({ approved: false, reason: error.reason })));
21551
21795
  if (!recorded.approved)
@@ -21571,6 +21815,9 @@ var shepherd_default = defineLoop({
21571
21815
  });
21572
21816
  if (merge === "Wait")
21573
21817
  return done("ready", "Approved, green and mergeable; left for a person to merge");
21818
+ const refused = yield* takeTurn();
21819
+ if (refused !== undefined)
21820
+ return done("needs_you", `The turn to merge into ${target} was refused: ${refused}`);
21574
21821
  const merged = yield* mergeChangeRequest(`merge-change-request:${cycle}`, {
21575
21822
  changeRequestId,
21576
21823
  head: pipeline.head
@@ -21579,6 +21826,7 @@ var shepherd_default = defineLoop({
21579
21826
  behind = true;
21580
21827
  if (merged.status !== "merged")
21581
21828
  continue;
21829
+ yield* passTurn();
21582
21830
  yield* writeBack("write-back", { milestone: "merged" });
21583
21831
  const ship = yield* ask("ship", {
21584
21832
  prompt: `Merged at ${merged.revision}. Release it now?`,
@@ -21595,7 +21843,26 @@ var shepherd_default = defineLoop({
21595
21843
  if (ship === "Not now")
21596
21844
  return done("merged", `Merged at ${merged.revision}`);
21597
21845
  const released = yield* call("release", release_default, { revision: merged.revision });
21598
- if (released.status !== "deployed" && released.status !== "rejected")
21846
+ const handedOn = released.status === "gate_failed" && (yield* ask("release-gate-failed", {
21847
+ prompt: `Merged at ${merged.revision}, but its Release gate failed: ${released.reason}`,
21848
+ options: [
21849
+ {
21850
+ value: "Next Release",
21851
+ description: "Leaves the revision to the next Release, which gates it with the next merge."
21852
+ },
21853
+ { value: "Taken over", description: "A person looks at the failing checks from here." }
21854
+ ],
21855
+ recommended: "Next Release",
21856
+ recommendationReason: "Nothing was tagged or deployed, and the gate already ran the failure again in a fresh checkout.",
21857
+ default: null,
21858
+ auto: "Next Release"
21859
+ })) === "Next Release";
21860
+ if (handedOn)
21861
+ return {
21862
+ ...done("merged", `Merged at ${merged.revision}; its Release gate failed, so the next Release ships it`),
21863
+ release: { runStatus: released.status, reason: released.reason }
21864
+ };
21865
+ if (released.status !== "deployed" && released.status !== "rejected" && released.status !== "gate_failed")
21599
21866
  yield* ask("release-failed", {
21600
21867
  prompt: `Merged at ${merged.revision}, but its Release ended ${released.status}: ${released.reason}`,
21601
21868
  options: [{ value: "Taken over", description: "A person looks at the release and production from here." }],
@@ -26474,6 +26741,7 @@ class RunnerCapabilityRpcs extends make30(make29("PutQuestion", {
26474
26741
  revision: optionalKey2(String5),
26475
26742
  checks: optional2(ArraySchema(String5)),
26476
26743
  suggested: optionalKey2(ArraySchema(ApprovedCheck)),
26744
+ rerunFailed: optionalKey2(Boolean3),
26477
26745
  measure: optionalKey2(Struct({
26478
26746
  base: optionalKey2(String5),
26479
26747
  plan: MeasurePlan,
@@ -26615,7 +26883,19 @@ class RunnerCapabilityRpcs extends make30(make29("PutQuestion", {
26615
26883
  logTail: optionalKey2(String5)
26616
26884
  })),
26617
26885
  readAt: optionalKey2(String5),
26618
- runnerChecks: optionalKey2(ArraySchema(String5))
26886
+ runnerChecks: optionalKey2(ArraySchema(String5)),
26887
+ approved: optionalKey2(String5),
26888
+ repository: optionalKey2(String5),
26889
+ target: optionalKey2(Struct({
26890
+ branch: String5,
26891
+ head: String5,
26892
+ jobs: ArraySchema(Struct({
26893
+ name: String5,
26894
+ status: Literals(["running", "success", "failed", "skipped"]),
26895
+ url: optionalKey2(String5),
26896
+ logTail: optionalKey2(String5)
26897
+ }))
26898
+ }))
26619
26899
  }),
26620
26900
  error: RunnerRpcError
26621
26901
  }), make29("ReportPipeline", {
@@ -26965,6 +27245,7 @@ var runnerHost = (capabilities) => ({
26965
27245
  ...launch.revision === undefined ? undefined : { revision: launch.revision },
26966
27246
  ...launch.checks === undefined ? undefined : { checks: launch.checks },
26967
27247
  ...launch.suggested === undefined ? undefined : { suggested: launch.suggested },
27248
+ ...launch.rerunFailed === undefined ? undefined : { rerunFailed: launch.rerunFailed },
26968
27249
  ...launch.measure === undefined ? undefined : { measure: launch.measure }
26969
27250
  })).pipe(asVoid2),
26970
27251
  startAgentWork: (launch) => requested(launch.step, capabilities.startAgentStep({
@@ -27188,6 +27469,7 @@ var rpcProgramPorts = (rpc, work) => {
27188
27469
  ...verification.revision === undefined ? undefined : { revision: verification.revision },
27189
27470
  ...verification.checks === undefined ? undefined : { checks: [...verification.checks] },
27190
27471
  ...verification.suggested === undefined ? undefined : { suggested: [...verification.suggested] },
27472
+ ...verification.rerunFailed === undefined ? undefined : { rerunFailed: verification.rerunFailed },
27191
27473
  ...verification.measure === undefined ? undefined : { measure: verification.measure }
27192
27474
  }),
27193
27475
  startAgentStep: ({ secrets, ...step }) => rpc.startAgentStep({ lease, ...step, ...secrets === undefined ? undefined : { secrets: [...secrets] } }),
@@ -29480,4 +29762,4 @@ var runKit = (config, identity, packages) => {
29480
29762
  runMain2(program.pipe(flatMap3((code) => sync2(() => process.exit(code)))));
29481
29763
  };
29482
29764
  // .kitman-build-entry.ts
29483
- runKit(kitman_config_default, { name: "@kitman-sh/software-engineering", version: "0.10.68" }, []);
29765
+ runKit(kitman_config_default, { name: "@kitman-sh/software-engineering", version: "0.10.70" }, []);