@kitman-sh/software-engineering 0.10.76 → 0.10.78

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
@@ -13478,6 +13478,8 @@ var LoopSafeReferenceString = String5.check(isMinLength(1), isMaxLength(240), is
13478
13478
  var LoopSafeInternalReferenceString = String5.check(isMinLength(1), isMaxLength(240), isPattern2(new RegExp(LoopSafeInternalReferencePattern, "u")));
13479
13479
  var LoopSafeText = String5.check(isMaxLength(4000), isPattern2(new RegExp(`^(?![\\s\\S]*(?:${LoopCredentialContentPattern}|[A-Za-z][A-Za-z0-9+.-]*://(?:[^\\s/?#]*@|[^\\s?#]*\\?)))[\\s\\S]*$`, "u")));
13480
13480
  var recommendedDefault = (recommended) => recommended !== undefined && is2(LoopSafeText)(recommended) ? recommended : undefined;
13481
+ var unansweredQuestionLead = "Nobody answers in full auto, and the agent's Question has no answer to take";
13482
+ var isUnansweredQuestion = (reason) => reason.startsWith(unansweredQuestionLead);
13481
13483
  var QuestionText = String5;
13482
13484
  var LoopSafeOutputDataString = String5.check(isMaxLength(4000), isPattern2(new RegExp(LoopSafeInternalReferencePattern, "u")));
13483
13485
  var LoopSafePackageName = String5.check(isMinLength(1), isMaxLength(200), isPattern2(new RegExp(LoopSafeReferencePattern, "u")));
@@ -19039,6 +19041,8 @@ var ask = (name, question) => takeStep(name, "ask", "ask", gen2(function* () {
19039
19041
  return yield* new QuestionRefused({ step: name, answer: fallback, options });
19040
19042
  if (question.auto !== undefined && options !== undefined && !options.includes(question.auto))
19041
19043
  return yield* new QuestionRefused({ step: name, answer: question.auto, options });
19044
+ if (question.unattendedAuto !== undefined && options !== undefined && !options.includes(question.unattendedAuto))
19045
+ return yield* new QuestionRefused({ step: name, answer: question.unattendedAuto, options });
19042
19046
  yield* launch(deferred, (host, token2) => host.putQuestion({
19043
19047
  step: name,
19044
19048
  prompt: question.prompt,
@@ -19046,6 +19050,7 @@ var ask = (name, question) => takeStep(name, "ask", "ask", gen2(function* () {
19046
19050
  ...advice,
19047
19051
  ...fallback === undefined ? undefined : { default: fallback },
19048
19052
  ...question.auto === undefined ? undefined : { auto: question.auto },
19053
+ ...question.unattendedAuto === undefined ? undefined : { unattendedAuto: question.unattendedAuto },
19049
19054
  ...question.timeout === undefined ? undefined : { timeoutMillis: toMillis(fromInputUnsafe2(question.timeout)) },
19050
19055
  token: token2
19051
19056
  }));
@@ -19058,10 +19063,17 @@ var ask = (name, question) => takeStep(name, "ask", "ask", gen2(function* () {
19058
19063
  return yield* new QuestionRefused({ step: name, answer, options });
19059
19064
  return offeredAnswer;
19060
19065
  }));
19061
- var call = (name, loop, input) => takeStep(name, "call", "call", gen2(function* () {
19066
+ var call = (name, loop, input, options) => takeStep(name, "call", "call", gen2(function* () {
19062
19067
  const deferred = childDeferred(name);
19063
19068
  const encoded = yield* toJson2(name, loop.input, input);
19064
- yield* launch(deferred, (host, token2) => host.admitChild({ step: name, loop: loop.id, input: encoded, token: token2 }));
19069
+ const constraints = options?.constraints ?? [];
19070
+ yield* launch(deferred, (host, token2) => host.admitChild({
19071
+ step: name,
19072
+ loop: loop.id,
19073
+ input: encoded,
19074
+ ...constraints.length === 0 ? undefined : { constraints },
19075
+ token: token2
19076
+ }));
19065
19077
  const result = yield* await_2(deferred);
19066
19078
  return yield* decodeEffect2(toCodecJson2(loop.output))(result).pipe(mapError3((error) => new ChildFailed({ step: name, loop: loop.id, reason: error.message })));
19067
19079
  }));
@@ -19177,7 +19189,11 @@ var ArtifactRequest = Struct({
19177
19189
  files: optional2(ArraySchema(RunFile))
19178
19190
  });
19179
19191
  var ArtifactResult = Struct({ artifactId: String5 });
19180
- var NoteRequest = Struct({ text: String5, artifactId: optional2(String5) });
19192
+ var NoteRequest = Struct({
19193
+ text: String5,
19194
+ artifactId: optional2(String5),
19195
+ kind: optional2(Literals(["note", "blocker"]))
19196
+ });
19181
19197
  var CreateTasksRequest = Struct({
19182
19198
  tickets: ArraySchema(PlanTicket),
19183
19199
  projectId: optionalKey2(String5)
@@ -19277,6 +19293,8 @@ var PipelineStatus = Struct({
19277
19293
  runnerChecks: optionalKey2(ArraySchema(String5)),
19278
19294
  approved: optionalKey2(String5),
19279
19295
  repository: optionalKey2(String5),
19296
+ conflicts: optionalKey2(Boolean3),
19297
+ needsRebase: optionalKey2(Boolean3),
19280
19298
  target: optionalKey2(Struct({ branch: String5, head: String5, jobs: ArraySchema(PipelineJob) }))
19281
19299
  });
19282
19300
  var ReviewThread = Struct({
@@ -20321,10 +20339,17 @@ var scriptedHost = (script, engine, agentLaunches, childLaunches, waits, verifyL
20321
20339
  ...launch.mergeTarget === undefined ? undefined : { mergeTarget: launch.mergeTarget }
20322
20340
  })), resolve(agentDeferredNamed(launch.deferredName), launch.token, scriptedExit(script.outputs?.[launch.step], (reason) => new StepFailed({ step: launch.step, reason })))),
20323
20341
  putQuestion: (launch) => {
20324
- const answer = script.answers?.[launch.step] ?? (script.fullAuto === true ? launch.auto : undefined) ?? launch.default;
20342
+ const attended = script.attended === true;
20343
+ const auto = script.fullAuto === true ? launch.auto ?? (attended ? undefined : launch.unattendedAuto) : undefined;
20344
+ const answer = script.answers?.[launch.step] ?? auto ?? (attended ? undefined : launch.default);
20325
20345
  return resolve(answerDeferred(launch.step), launch.token, answer === undefined ? fail5(new StepFailed({ step: launch.step, reason: "no answer was scripted" })) : succeed4(answer));
20326
20346
  },
20327
- admitChild: (launch) => andThen2(sync2(() => childLaunches.push({ step: launch.step, loop: launch.loop, input: launch.input })), resolve(childDeferred(launch.step), launch.token, scriptedExit(script.children?.[launch.step], (reason) => new ChildFailed({ step: launch.step, loop: launch.loop, reason })))),
20347
+ admitChild: (launch) => andThen2(sync2(() => childLaunches.push({
20348
+ step: launch.step,
20349
+ loop: launch.loop,
20350
+ input: launch.input,
20351
+ ...launch.constraints === undefined ? undefined : { constraints: launch.constraints }
20352
+ })), resolve(childDeferred(launch.step), launch.token, scriptedExit(script.children?.[launch.step], (reason) => new ChildFailed({ step: launch.step, loop: launch.loop, reason })))),
20328
20353
  awaitEvent: (launch) => {
20329
20354
  const event = script.events?.[launch.step];
20330
20355
  waits.push({
@@ -21429,7 +21454,7 @@ var repliesPrompt = (threads) => [
21429
21454
  var threadKey = (thread) => `${thread.id}:${thread.comments.length}`;
21430
21455
  var shepherd_default = defineLoop({
21431
21456
  id: "shepherd",
21432
- version: "1.4.0",
21457
+ version: "1.5.0",
21433
21458
  title: "Shepherd",
21434
21459
  input: Input3,
21435
21460
  output: Output3,
@@ -21468,6 +21493,9 @@ var shepherd_default = defineLoop({
21468
21493
  let behind = false;
21469
21494
  let pushed;
21470
21495
  let fixedFrom;
21496
+ const syncedFor = new Set;
21497
+ const syncedKey = (head, targetHead) => `${head}@${targetHead}`;
21498
+ const blockerSynced = new Set;
21471
21499
  let turn;
21472
21500
  let turns = 0;
21473
21501
  let passes = 0;
@@ -21597,13 +21625,14 @@ ${open}`,
21597
21625
  redTarget = { head: pipeline.head, targetHead: pipeline.target?.head, moved: woke !== undefined };
21598
21626
  return;
21599
21627
  });
21600
- const catchUp = (cycle) => gen2(function* () {
21628
+ const catchUp = (cycle, targetHead, forBlocker = false) => gen2(function* () {
21601
21629
  const refused = yield* takeTurn();
21602
21630
  if (refused !== undefined)
21603
21631
  return done("needs_you", `The turn to merge into ${target} was refused: ${refused}`);
21604
21632
  const synced = yield* syncBase(`sync:${cycle}`, { agent: "implementer", target });
21605
21633
  if (synced.status === "conflict")
21606
- return done("needs_you", `Merging ${target} in conflicts on ${synced.files.join(", ")}: ${synced.reason}`);
21634
+ return handBack(`Merging ${target} in conflicts on ${synced.files.join(", ")}: ${synced.reason}`, synced.files.map((file) => `- ${file}`).join(`
21635
+ `));
21607
21636
  if (synced.status !== "merged")
21608
21637
  return;
21609
21638
  const caught = synced.catchUp;
@@ -21630,6 +21659,10 @@ ${open}`,
21630
21659
  }
21631
21660
  if (caught !== undefined) {
21632
21661
  pushed = { head: caught.head, stale: 0, by: "the catch-up" };
21662
+ if (targetHead !== undefined)
21663
+ syncedFor.add(syncedKey(caught.head, targetHead));
21664
+ if (forBlocker)
21665
+ blockerSynced.add(caught.head);
21633
21666
  yield* waitFor(`pushed:${cycle}`, {
21634
21667
  event: "change_request.mergeable",
21635
21668
  filter: { changeRequestId, head: caught.head },
@@ -21682,6 +21715,21 @@ ${open}`,
21682
21715
  else
21683
21716
  return found;
21684
21717
  }
21718
+ if (pipeline.conflicts === true || pipeline.needsRebase === true) {
21719
+ const blocker = pipeline.conflicts === true ? `conflicts with ${target}` : `needs ${target} merged in`;
21720
+ const targetHead = pipeline.target?.head;
21721
+ const syncedAlready = targetHead === undefined ? blockerSynced.has(pipeline.head) : syncedFor.has(syncedKey(pipeline.head, targetHead));
21722
+ if (syncedAlready)
21723
+ return handBack(`The forge still says ${pipeline.head} ${blocker} after merging it in`, `Merge ${target} into the branch and settle what conflicts.`);
21724
+ if (targetHead !== undefined)
21725
+ syncedFor.add(syncedKey(pipeline.head, targetHead));
21726
+ blockerSynced.add(pipeline.head);
21727
+ behind = false;
21728
+ const stopped = yield* catchUp(cycle, targetHead, true);
21729
+ if (stopped !== undefined)
21730
+ return stopped;
21731
+ continue;
21732
+ }
21685
21733
  if (pipeline.status === "none" && pipeline.runnerChecks !== undefined) {
21686
21734
  if (ranOnRunner.has(pipeline.head))
21687
21735
  return done("needs_you", `The pipeline ran on the Runner at ${pipeline.head}, but no result was recorded`);
@@ -21699,7 +21747,7 @@ ${open}`,
21699
21747
  const targetMoved = redTarget?.head === pipeline.head && (redTarget.targetHead !== undefined && pipeline.target !== undefined ? pipeline.target.head !== redTarget.targetHead : redTarget.moved);
21700
21748
  if (targetMoved) {
21701
21749
  redTarget = undefined;
21702
- const stopped = yield* catchUp(cycle);
21750
+ const stopped = yield* catchUp(cycle, pipeline.target?.head);
21703
21751
  if (stopped !== undefined)
21704
21752
  return stopped;
21705
21753
  continue;
@@ -21714,7 +21762,7 @@ ${open}`,
21714
21762
  }
21715
21763
  if (onTarget.passed.length > 0 && redTarget?.head === pipeline.head) {
21716
21764
  redTarget = undefined;
21717
- const stopped = yield* catchUp(cycle);
21765
+ const stopped = yield* catchUp(cycle, pipeline.target?.head);
21718
21766
  if (stopped !== undefined)
21719
21767
  return stopped;
21720
21768
  continue;
@@ -21811,7 +21859,7 @@ ${open}`,
21811
21859
  continue;
21812
21860
  if (mergeable.payload.mergeable === false || behind) {
21813
21861
  behind = false;
21814
- const stopped = yield* catchUp(cycle);
21862
+ const stopped = yield* catchUp(cycle, pipeline.target?.head);
21815
21863
  if (stopped !== undefined)
21816
21864
  return stopped;
21817
21865
  continue;
@@ -22037,7 +22085,7 @@ Merge now?`,
22037
22085
  }
22038
22086
  };
22039
22087
  }
22040
- }).pipe(catchIf2((error) => error._tag === "StepFailed" && error.reason.includes("time budget"), (error) => succeed7(done("needs_you", `Step "${error.step}" ran past its ${stepBudget} budget`))), catchTags2({
22088
+ }).pipe(catchIf2((error) => error._tag === "StepFailed" && (isUnansweredQuestion(error.reason) || error.reason.includes("time budget")), (error) => succeed7(isUnansweredQuestion(error.reason) ? handBack(`Step "${error.step}" stopped on a Question nobody answers in full auto`, error.reason) : done("needs_you", `Step "${error.step}" ran past its ${stepBudget} budget`))), catchTags2({
22041
22089
  WaitTimedOut: (timedOut) => succeed7(done("needs_you", timedOut.event === "change_request.approval" && notCarried !== undefined ? `Nobody approved the head after ${notCarried}` : `Nothing happened on the ChangeRequest while waiting for ${timedOut.event}`)),
22042
22090
  ChangeRequestClosed: (ended) => succeed7(ended.merged ? done("merged", "Someone else merged the ChangeRequest") : done("needs_you", "The ChangeRequest was closed"))
22043
22091
  }));
@@ -22055,7 +22103,8 @@ var BuildInput = Struct({
22055
22103
  maxRounds: optional2(Int),
22056
22104
  continuing: optional2(Continuing),
22057
22105
  land: optional2(Boolean3),
22058
- changeRequestId: optional2(String5)
22106
+ changeRequestId: optional2(String5),
22107
+ maxRebuilds: optional2(Int.check(isGreaterThanOrEqualTo2(0)))
22059
22108
  });
22060
22109
  var CriterionAnswer = Struct({
22061
22110
  criterion: String5,
@@ -22105,6 +22154,11 @@ var BuildOutput = Struct({
22105
22154
  next: Struct({ changeRequestId: String5 })
22106
22155
  });
22107
22156
 
22157
+ class BuildBlocked extends TaggedError3()("BuildBlocked", {
22158
+ message: String5
22159
+ }) {
22160
+ }
22161
+
22108
22162
  class BuildTargetMissing extends TaggedError3()("BuildTargetMissing", {
22109
22163
  message: String5
22110
22164
  }) {
@@ -22180,6 +22234,10 @@ var fixPrompt = (settled) => {
22180
22234
  ].join(`
22181
22235
  `);
22182
22236
  };
22237
+ var takenOverAnswer = "Taken over";
22238
+ var buildAgainAnswer = "Build again";
22239
+ var blockedAnswer = "Mark blocked";
22240
+ var standingConstraint = (item) => `Settle what an earlier Build left standing: ${item}`;
22183
22241
  var blockingIds = (settled) => settled.open.filter(isBlocking).map((finding) => finding.id);
22184
22242
  var onlyChecksBlock = (settled) => blockingIds(settled).every(isCheckFinding) && !settled.standing.some((entry) => isBlocking(entry.finding));
22185
22243
  var rally = (input) => gen2(function* () {
@@ -22252,9 +22310,9 @@ var rally = (input) => gen2(function* () {
22252
22310
  last = { head, settled, scope: reviewed.scope };
22253
22311
  }
22254
22312
  });
22255
- var build_default = defineLoop({
22313
+ var build2 = defineLoop({
22256
22314
  id: "build",
22257
- version: "2.3.0",
22315
+ version: "2.4.0",
22258
22316
  title: "Build",
22259
22317
  input: BuildInput,
22260
22318
  output: BuildOutput,
@@ -22267,7 +22325,7 @@ var build_default = defineLoop({
22267
22325
  { id: "retry", title: "Retry with a steer", loop: "build" }
22268
22326
  ],
22269
22327
  capabilities: ["agent_work", "verify", "change_request", "write_back", "post_comment", "approve_change_request"],
22270
- calls: () => [review_default, shepherd_default],
22328
+ calls: () => [review_default, shepherd_default, build2],
22271
22329
  run: (input) => gen2(function* () {
22272
22330
  if (input.words === undefined && input.taskId === undefined)
22273
22331
  return yield* new BuildTargetMissing({ message: "Give the words to build, or a Task" });
@@ -22349,22 +22407,7 @@ var build_default = defineLoop({
22349
22407
  summary: `Review round ${last.round} passed with nothing blocking.`,
22350
22408
  review: `review:${last.round}`
22351
22409
  }).pipe(catchTag2("StepFailed", (error) => succeed7({ approved: false, reason: error.reason }))) : undefined;
22352
- const landed = input.land !== false && unsettled.length === 0 ? yield* call("land", shepherd_default, {
22353
- changeRequestId: opened.id,
22354
- ...lastNotRun.length === 0 ? undefined : { notRun: lastNotRun },
22355
- ...input.taskId === undefined ? undefined : { taskId: input.taskId },
22356
- ...input.branch === undefined ? undefined : { branch: input.branch }
22357
- }) : undefined;
22358
- if (input.land !== false && unsettled.length > 0)
22359
- yield* ask("unsettled", {
22360
- prompt: `The ChangeRequest ${opened.url} is open, but these still stand: ${unsettled.join("; ")}. Build will not land it.`,
22361
- options: [{ value: "Taken over", description: "A person fixes, rebuts or steers it from here." }],
22362
- recommended: "Taken over",
22363
- recommendationReason: "Build stopped with these unsettled, so the next step is a person\u2019s.",
22364
- default: null
22365
- });
22366
- return {
22367
- changeRequest: opened,
22410
+ let settledAs = {
22368
22411
  revision: last.head.revision,
22369
22412
  tree: last.head.tree,
22370
22413
  settled: unsettled.length === 0,
@@ -22373,12 +22416,78 @@ var build_default = defineLoop({
22373
22416
  stopped: last.decision.reason,
22374
22417
  criteria,
22375
22418
  ...lastNotRun.length === 0 ? undefined : { notRun: lastNotRun },
22376
- ...approval === undefined ? undefined : { approval },
22419
+ ...approval === undefined ? undefined : { approval }
22420
+ };
22421
+ const maxRebuilds = input.maxRebuilds ?? 1;
22422
+ for (let rebuilds = 0;input.land !== false && settledAs.unsettled.length > 0; ) {
22423
+ const standing = settledAs.unsettled;
22424
+ const again = rebuilds < maxRebuilds;
22425
+ const answer = yield* ask(rebuilds === 0 ? "unsettled" : `unsettled:${rebuilds + 1}`, {
22426
+ prompt: `The ChangeRequest ${opened.url} is open, but these still stand: ${standing.join("; ")}. Build will not land it.`,
22427
+ options: [
22428
+ { value: takenOverAnswer, description: "A person fixes, rebuts or steers it from here." },
22429
+ again ? {
22430
+ value: buildAgainAnswer,
22431
+ description: "Starts one more Build on this branch, with each of these as a constraint."
22432
+ } : {
22433
+ value: blockedAnswer,
22434
+ description: "Fails this Build, recording these as a blocker on its Task, and tells its owner."
22435
+ }
22436
+ ],
22437
+ recommended: takenOverAnswer,
22438
+ recommendationReason: "Build stopped with these unsettled, so the next step is a person\u2019s.",
22439
+ default: null,
22440
+ unattendedAuto: again ? buildAgainAnswer : blockedAnswer
22441
+ });
22442
+ if (answer === takenOverAnswer)
22443
+ break;
22444
+ if (answer === blockedAnswer) {
22445
+ if (input.taskId !== undefined)
22446
+ yield* note("blocked", {
22447
+ kind: "blocker",
22448
+ text: [
22449
+ `Build stopped without landing ${opened.url}, marked blocked on what still stands:`,
22450
+ "",
22451
+ ...standing.map((item) => `- ${item}`)
22452
+ ].join(`
22453
+ `)
22454
+ });
22455
+ return yield* new BuildBlocked({
22456
+ message: `The ChangeRequest ${opened.url} is open, and Build was marked blocked on what still stands: ${standing.join("; ")}`
22457
+ });
22458
+ }
22459
+ rebuilds++;
22460
+ const {
22461
+ changeRequest: _,
22462
+ landed: __,
22463
+ next: ___,
22464
+ ...rebuilt
22465
+ } = yield* call(`rebuild:${rebuilds}`, { id: "build", input: BuildInput, output: BuildOutput }, {
22466
+ ...input.words === undefined ? undefined : { words: input.words },
22467
+ ...input.taskId === undefined ? undefined : { taskId: input.taskId },
22468
+ ...input.repoBindingId === undefined ? undefined : { repoBindingId: input.repoBindingId },
22469
+ ...input.outcome === undefined ? undefined : { outcome: input.outcome },
22470
+ ...input.maxRounds === undefined ? undefined : { maxRounds: input.maxRounds },
22471
+ changeRequestId: opened.id,
22472
+ land: false
22473
+ }, { constraints: standing.map(standingConstraint) });
22474
+ settledAs = rebuilt;
22475
+ }
22476
+ const landed = input.land !== false && settledAs.unsettled.length === 0 ? yield* call("land", shepherd_default, {
22477
+ changeRequestId: opened.id,
22478
+ ...settledAs.notRun === undefined ? undefined : { notRun: settledAs.notRun },
22479
+ ...input.taskId === undefined ? undefined : { taskId: input.taskId },
22480
+ ...input.branch === undefined ? undefined : { branch: input.branch }
22481
+ }) : undefined;
22482
+ return {
22483
+ changeRequest: opened,
22484
+ ...settledAs,
22377
22485
  ...landed === undefined ? undefined : { landed },
22378
22486
  next: { changeRequestId: opened.id }
22379
22487
  };
22380
22488
  }).pipe(tapError2(() => ignore2(writeBack("write-back:failed", { milestone: "failed" }))))
22381
22489
  });
22490
+ var build_default = build2;
22382
22491
 
22383
22492
  // src/errand.ts
22384
22493
  var Input4 = Struct({
@@ -26925,6 +27034,7 @@ class RunnerCapabilityRpcs extends make30(make29("PutQuestion", {
26925
27034
  verification: optional2(SuggestedVerification),
26926
27035
  default: optional2(String5),
26927
27036
  auto: optional2(String5),
27037
+ unattendedAuto: optional2(String5),
26928
27038
  timeoutMillis: optional2(Finite),
26929
27039
  deferredName: String5
26930
27040
  },
@@ -26995,6 +27105,7 @@ class RunnerCapabilityRpcs extends make30(make29("PutQuestion", {
26995
27105
  step: String5,
26996
27106
  loop: String5,
26997
27107
  input: Json2,
27108
+ constraints: optional2(ArraySchema(String5)),
26998
27109
  deferredName: String5
26999
27110
  },
27000
27111
  success: Struct({ runId: String5 }),
@@ -27016,7 +27127,8 @@ class RunnerCapabilityRpcs extends make30(make29("PutQuestion", {
27016
27127
  lease: ProgramLease,
27017
27128
  step: String5,
27018
27129
  text: String5,
27019
- artifactId: optional2(String5)
27130
+ artifactId: optional2(String5),
27131
+ kind: optional2(Literals(["note", "blocker"]))
27020
27132
  },
27021
27133
  error: RunnerRpcError
27022
27134
  }), make29("PerformHostEffect", {
@@ -27099,6 +27211,8 @@ class RunnerCapabilityRpcs extends make30(make29("PutQuestion", {
27099
27211
  runnerChecks: optionalKey2(ArraySchema(String5)),
27100
27212
  approved: optionalKey2(String5),
27101
27213
  repository: optionalKey2(String5),
27214
+ conflicts: optionalKey2(Boolean3),
27215
+ needsRebase: optionalKey2(Boolean3),
27102
27216
  target: optionalKey2(Struct({
27103
27217
  branch: String5,
27104
27218
  head: String5,
@@ -27450,6 +27564,7 @@ var runnerHost = (capabilities) => ({
27450
27564
  ...launch.verification === undefined ? undefined : { verification: launch.verification },
27451
27565
  ...launch.default === undefined ? undefined : { default: launch.default },
27452
27566
  ...launch.auto === undefined ? undefined : { auto: launch.auto },
27567
+ ...launch.unattendedAuto === undefined ? undefined : { unattendedAuto: launch.unattendedAuto },
27453
27568
  ...launch.timeoutMillis === undefined ? undefined : { timeoutMillis: launch.timeoutMillis }
27454
27569
  })).pipe(asVoid2),
27455
27570
  startVerification: (launch) => requested(launch.step, capabilities.startVerification({
@@ -27477,6 +27592,7 @@ var runnerHost = (capabilities) => ({
27477
27592
  step: launch.step,
27478
27593
  loop: launch.loop,
27479
27594
  input: launch.input,
27595
+ ...launch.constraints === undefined ? undefined : { constraints: launch.constraints },
27480
27596
  deferredName: childDeferred(launch.step).name
27481
27597
  })).pipe(asVoid2),
27482
27598
  claimResource: (launch) => requested(launch.step, capabilities.claimResource({
@@ -27673,6 +27789,7 @@ var rpcProgramPorts = (rpc, work) => {
27673
27789
  ...question.verification === undefined ? undefined : { verification: question.verification },
27674
27790
  ...question.default === undefined ? undefined : { default: question.default },
27675
27791
  ...question.auto === undefined ? undefined : { auto: question.auto },
27792
+ ...question.unattendedAuto === undefined ? undefined : { unattendedAuto: question.unattendedAuto },
27676
27793
  ...question.timeoutMillis === undefined ? undefined : { timeoutMillis: question.timeoutMillis }
27677
27794
  }),
27678
27795
  startVerification: (verification) => rpc.startVerification({
@@ -27688,7 +27805,11 @@ var rpcProgramPorts = (rpc, work) => {
27688
27805
  startAgentStep: ({ secrets, ...step }) => rpc.startAgentStep({ lease, ...step, ...secrets === undefined ? undefined : { secrets: [...secrets] } }),
27689
27806
  awaitEvent: (wait) => rpc.awaitEvent({ lease, ...wait }),
27690
27807
  claimResource: (claim) => rpc.claimResource({ lease, ...claim }),
27691
- admitChild: (child) => rpc.admitChild({ lease, ...child }),
27808
+ admitChild: ({ constraints, ...child }) => rpc.admitChild({
27809
+ lease,
27810
+ ...child,
27811
+ ...constraints === undefined ? undefined : { constraints: [...constraints] }
27812
+ }),
27692
27813
  storeArtifact: ({ fileIds, ...artifact }) => rpc.storeArtifact({ lease, ...artifact, ...fileIds === undefined ? undefined : { fileIds: [...fileIds] } }),
27693
27814
  ...rpcRunFiles(rpc, lease),
27694
27815
  recordNote: (note) => rpc.recordNote({ lease, ...note }),
@@ -29975,4 +30096,4 @@ var runKit = (config, identity, packages) => {
29975
30096
  runMain2(program.pipe(flatMap3((code) => sync2(() => process.exit(code)))));
29976
30097
  };
29977
30098
  // .kitman-build-entry.ts
29978
- runKit(kitman_config_default, { name: "@kitman-sh/software-engineering", version: "0.10.76" }, []);
30099
+ runKit(kitman_config_default, { name: "@kitman-sh/software-engineering", version: "0.10.78" }, []);
@@ -3,7 +3,7 @@
3
3
  {
4
4
  "id": "build",
5
5
  "title": "Build",
6
- "version": "2.3.0",
6
+ "version": "2.4.0",
7
7
  "input": {
8
8
  "type": "object",
9
9
  "properties": {
@@ -182,6 +182,18 @@
182
182
  "type": "null"
183
183
  }
184
184
  ]
185
+ },
186
+ "maxRebuilds": {
187
+ "anyOf": [
188
+ {
189
+ "type": "integer",
190
+ "minimum": 0,
191
+ "maximum": 9007199254740991
192
+ },
193
+ {
194
+ "type": "null"
195
+ }
196
+ ]
185
197
  }
186
198
  },
187
199
  "additionalProperties": true,
@@ -2588,7 +2600,7 @@
2588
2600
  {
2589
2601
  "id": "shepherd",
2590
2602
  "title": "Shepherd",
2591
- "version": "1.4.0",
2603
+ "version": "1.5.0",
2592
2604
  "input": {
2593
2605
  "type": "object",
2594
2606
  "properties": {
@@ -3371,7 +3383,7 @@
3371
3383
  "carried": [
3372
3384
  {
3373
3385
  "name": "@kitman-sh/software-engineering",
3374
- "version": "0.10.76",
3386
+ "version": "0.10.78",
3375
3387
  "setup": "2a237548a69b0cd53ec3be7f687cfa8c2128335b3a655d34e185f2abce6a3c37",
3376
3388
  "loops": [
3377
3389
  "build",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitman-sh/software-engineering",
3
- "version": "0.10.76",
3
+ "version": "0.10.78",
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.76",
20
+ "@kitman-sh/sdk": "0.10.78",
21
21
  "effect": "4.1.2"
22
22
  },
23
23
  "kitman": {
24
24
  "bundle": "dist/bundle.js",
25
- "digest": "b4e95b0c8f4903ce4470016ecfe7a3f4b2e06596609cad0c60bd5bd73690f661",
25
+ "digest": "f05f24ece58370ae047e3b7439f73b1f293b518a8955963972d5c46e3872324a",
26
26
  "protocolVersion": 5,
27
27
  "declarations": "dist/declarations.json",
28
28
  "setup": {
package/src/build.ts CHANGED
@@ -18,6 +18,7 @@ import {
18
18
  failsOn,
19
19
  isBlocking,
20
20
  LoopOutcome,
21
+ note,
21
22
  rallyStop,
22
23
  Rebuttal,
23
24
  settleRound,
@@ -65,7 +66,12 @@ export const BuildInput = Schema.Struct({
65
66
  * An open ChangeRequest to fix forward on: the Run works its branch, never force-pushing, and reports in one comment
66
67
  * on it, leaving the ChangeRequest's title and description to its author.
67
68
  */
68
- changeRequestId: Schema.optional(Schema.String)
69
+ changeRequestId: Schema.optional(Schema.String),
70
+ /**
71
+ * How many more Builds an unattended full-auto Run starts on its ChangeRequest while review findings still stand,
72
+ * before it fails with them; 1 when left out.
73
+ */
74
+ maxRebuilds: Schema.optional(Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)))
69
75
  })
70
76
 
71
77
  /** The implementer's answer to one acceptance criterion of the Task. */
@@ -139,6 +145,11 @@ export const BuildOutput = Schema.Struct({
139
145
  next: Schema.Struct({ changeRequestId: Schema.String })
140
146
  })
141
147
 
148
+ /** Build was marked blocked on findings that still stand, so the Task waits on its owner. */
149
+ export class BuildBlocked extends Schema.TaggedError<BuildBlocked>()('BuildBlocked', {
150
+ message: Schema.String
151
+ }) {}
152
+
142
153
  export class BuildTargetMissing extends Schema.TaggedError<BuildTargetMissing>()('BuildTargetMissing', {
143
154
  message: Schema.String
144
155
  }) {}
@@ -235,6 +246,14 @@ const fixPrompt = (settled: SettledRound) => {
235
246
  ].join('\n')
236
247
  }
237
248
 
249
+ const takenOverAnswer = 'Taken over'
250
+
251
+ const buildAgainAnswer = 'Build again'
252
+
253
+ const blockedAnswer = 'Mark blocked'
254
+
255
+ const standingConstraint = (item: string) => `Settle what an earlier Build left standing: ${item}`
256
+
238
257
  const blockingIds = (settled: SettledRound) => settled.open.filter(isBlocking).map(finding => finding.id)
239
258
 
240
259
  const onlyChecksBlock = (settled: SettledRound) =>
@@ -369,11 +388,12 @@ const rally = (input: {
369
388
  /**
370
389
  * Implements a Task or words, reviews and fixes until the rally stops, gates on the evidence for the head, and opens
371
390
  * the Run's ChangeRequest with the evidence, the claims and whatever it could not settle (ADR-0051). It writes the
372
- * Run's milestones to its Task: started, ChangeRequest opened, and failed.
391
+ * Run's milestones to its Task: started, ChangeRequest opened, and failed. Findings that still stand once full auto's
392
+ * rebuilds run out go on the Task as a blocker before the Run fails.
373
393
  */
374
- export default defineLoop({
394
+ const build = defineLoop({
375
395
  id: 'build',
376
- version: '2.3.0',
396
+ version: '2.4.0',
377
397
  title: 'Build',
378
398
  input: BuildInput,
379
399
  output: BuildOutput,
@@ -386,7 +406,7 @@ export default defineLoop({
386
406
  { id: 'retry', title: 'Retry with a steer', loop: 'build' }
387
407
  ],
388
408
  capabilities: ['agent_work', 'verify', 'change_request', 'write_back', 'post_comment', 'approve_change_request'],
389
- calls: (): readonly CalledLoop[] => [review, shepherd],
409
+ calls: (): readonly CalledLoop[] => [review, shepherd, build],
390
410
  run: input =>
391
411
  Effect.gen(function* () {
392
412
  if (input.words === undefined && input.taskId === undefined)
@@ -524,40 +544,107 @@ export default defineLoop({
524
544
  )
525
545
  : undefined
526
546
 
527
- // A blocking Review, or anything else left unsettled, stops here with the findings for a person, not in Shepherd.
547
+ let settledAs: Omit<typeof BuildOutput.Type, 'changeRequest' | 'landed' | 'next'> = {
548
+ revision: last.head.revision,
549
+ tree: last.head.tree,
550
+ settled: unsettled.length === 0,
551
+ unsettled,
552
+ rounds: last.round,
553
+ stopped: last.decision.reason,
554
+ criteria,
555
+ ...(lastNotRun.length === 0 ? undefined : { notRun: lastNotRun }),
556
+ ...(approval === undefined ? undefined : { approval })
557
+ }
558
+
559
+ const maxRebuilds = input.maxRebuilds ?? 1
560
+
561
+ // Anything left unsettled stops here with the findings for a person, not in Shepherd. Full auto builds again on
562
+ // the same branch up to the cap, then fails with them rather than wait on a Question nobody answers.
563
+ for (let rebuilds = 0; input.land !== false && settledAs.unsettled.length > 0;) {
564
+ const standing = settledAs.unsettled
565
+ const again = rebuilds < maxRebuilds
566
+
567
+ const answer = yield* ask(rebuilds === 0 ? 'unsettled' : `unsettled:${rebuilds + 1}`, {
568
+ prompt: `The ChangeRequest ${opened.url} is open, but these still stand: ${standing.join('; ')}. Build will not land it.`,
569
+ options: [
570
+ { value: takenOverAnswer, description: 'A person fixes, rebuts or steers it from here.' },
571
+ again
572
+ ? {
573
+ value: buildAgainAnswer,
574
+ description: 'Starts one more Build on this branch, with each of these as a constraint.'
575
+ }
576
+ : {
577
+ value: blockedAnswer,
578
+ description: 'Fails this Build, recording these as a blocker on its Task, and tells its owner.'
579
+ }
580
+ ],
581
+ recommended: takenOverAnswer,
582
+ recommendationReason: 'Build stopped with these unsettled, so the next step is a person’s.',
583
+ // No default: an unattended Run would take it at once even in a gated Team, and finish as partial.
584
+ default: null,
585
+ unattendedAuto: again ? buildAgainAnswer : blockedAnswer
586
+ })
587
+
588
+ if (answer === takenOverAnswer) break
589
+
590
+ if (answer === blockedAnswer) {
591
+ if (input.taskId !== undefined)
592
+ yield* note('blocked', {
593
+ kind: 'blocker',
594
+ text: [
595
+ `Build stopped without landing ${opened.url}, marked blocked on what still stands:`,
596
+ '',
597
+ ...standing.map(item => `- ${item}`)
598
+ ].join('\n')
599
+ })
600
+
601
+ return yield* new BuildBlocked({
602
+ message: `The ChangeRequest ${opened.url} is open, and Build was marked blocked on what still stands: ${standing.join('; ')}`
603
+ })
604
+ }
605
+
606
+ rebuilds++
607
+
608
+ const {
609
+ changeRequest: _,
610
+ landed: __,
611
+ next: ___,
612
+ ...rebuilt
613
+ } = yield* call(
614
+ `rebuild:${rebuilds}`,
615
+ { id: 'build', input: BuildInput, output: BuildOutput },
616
+ {
617
+ ...(input.words === undefined ? undefined : { words: input.words }),
618
+ ...(input.taskId === undefined ? undefined : { taskId: input.taskId }),
619
+ ...(input.repoBindingId === undefined ? undefined : { repoBindingId: input.repoBindingId }),
620
+ ...(input.outcome === undefined ? undefined : { outcome: input.outcome }),
621
+ ...(input.maxRounds === undefined ? undefined : { maxRounds: input.maxRounds }),
622
+ changeRequestId: opened.id,
623
+ land: false
624
+ },
625
+ { constraints: standing.map(standingConstraint) }
626
+ )
627
+
628
+ settledAs = rebuilt
629
+ }
630
+
528
631
  const landed =
529
- input.land !== false && unsettled.length === 0
632
+ input.land !== false && settledAs.unsettled.length === 0
530
633
  ? yield* call('land', shepherd, {
531
634
  changeRequestId: opened.id,
532
- ...(lastNotRun.length === 0 ? undefined : { notRun: lastNotRun }),
635
+ ...(settledAs.notRun === undefined ? undefined : { notRun: settledAs.notRun }),
533
636
  ...(input.taskId === undefined ? undefined : { taskId: input.taskId }),
534
637
  ...(input.branch === undefined ? undefined : { branch: input.branch })
535
638
  })
536
639
  : undefined
537
640
 
538
- if (input.land !== false && unsettled.length > 0)
539
- yield* ask('unsettled', {
540
- prompt: `The ChangeRequest ${opened.url} is open, but these still stand: ${unsettled.join('; ')}. Build will not land it.`,
541
- options: [{ value: 'Taken over', description: 'A person fixes, rebuts or steers it from here.' }],
542
- recommended: 'Taken over',
543
- recommendationReason: 'Build stopped with these unsettled, so the next step is a person’s.',
544
- // No default: an unattended Run, as full auto starts, would take it at once and finish as partial.
545
- default: null
546
- })
547
-
548
641
  return {
549
642
  changeRequest: opened,
550
- revision: last.head.revision,
551
- tree: last.head.tree,
552
- settled: unsettled.length === 0,
553
- unsettled,
554
- rounds: last.round,
555
- stopped: last.decision.reason,
556
- criteria,
557
- ...(lastNotRun.length === 0 ? undefined : { notRun: lastNotRun }),
558
- ...(approval === undefined ? undefined : { approval }),
643
+ ...settledAs,
559
644
  ...(landed === undefined ? undefined : { landed }),
560
645
  next: { changeRequestId: opened.id }
561
646
  }
562
647
  }).pipe(Effect.tapError(() => Effect.ignore(writeBack('write-back:failed', { milestone: 'failed' }))))
563
648
  })
649
+
650
+ export default build
package/src/shepherd.ts CHANGED
@@ -22,6 +22,7 @@ import {
22
22
  waitFor,
23
23
  writeBack,
24
24
  isBlocking,
25
+ isUnansweredQuestion,
25
26
  type BaseSync,
26
27
  type MergedFinding,
27
28
  type PipelineStatus,
@@ -191,15 +192,16 @@ const threadKey = (thread: ReviewThreads['threads'][number]) => `${thread.id}:${
191
192
  * Takes an open ChangeRequest to merge: it waits on its Events with no model time between them, fixes a pipeline the
192
193
  * branch broke (after ruling out a flake and a target branch that fails the same check, which it waits out), answers
193
194
  * each new review thread on the thread, merges the target branch in when it is behind, and merges once approved, green
194
- * and mergeable when told to or when a person says so. It merges the target in and merges only while it holds the
195
- * target's turn, so ChangeRequests for one target land one at a time, in order. A head nobody approved gets a review
196
- * of what changed since the last approved head. It runs one ci-fix and two head-fix rounds, each judged by the
197
- * pipeline at the head the last fix pushed, then hands the ChangeRequest back to Build, and stops as needs you, with
198
- * why, instead of spinning.
195
+ * and mergeable when told to or when a person says so. A branch the forge says conflicts or is behind merges its target
196
+ * in before any pipeline is run or fixed, and one whose merge Shepherd cannot settle goes back to Build. It merges the
197
+ * target in and merges only while it holds the target's turn, so ChangeRequests for one target land one at a time, in
198
+ * order. A head nobody approved gets a review of what changed since the last approved head. It runs one ci-fix and two
199
+ * head-fix rounds, each judged by the pipeline at the head the last fix pushed, then hands the ChangeRequest back to
200
+ * Build, and stops as needs you, with why, instead of spinning.
199
201
  */
200
202
  export default defineLoop({
201
203
  id: 'shepherd',
202
- version: '1.4.0',
204
+ version: '1.5.0',
203
205
  title: 'Shepherd',
204
206
  input: Input,
205
207
  output: Output,
@@ -263,6 +265,15 @@ export default defineLoop({
263
265
  */
264
266
  let fixedFrom: { readonly head: string; readonly changed: boolean; looks: number } | undefined
265
267
 
268
+ /**
269
+ * Each head a sync pushed or a sync for the forge's conflict or needed rebase started from, with the target's head
270
+ * it took in, where the forge gave it; a blocker the forge shows again at both means the sync could not settle it.
271
+ */
272
+ const syncedFor = new Set<string>()
273
+ const syncedKey = (head: string, targetHead: string) => `${head}@${targetHead}`
274
+ /** The heads a sync for the forge's blocker started from or pushed, judged by when the target's head is unknown. */
275
+ const blockerSynced = new Set<string>()
276
+
266
277
  /** The target's turn: held from the sync before the merge until the merge, so one ChangeRequest merges at a time. */
267
278
  let turn: Claim | undefined
268
279
  let turns = 0
@@ -474,7 +485,7 @@ export default defineLoop({
474
485
  * Merges the target branch in while holding its turn, and carries the approval to the head it pushes when the merge
475
486
  * left the branch's own change as it was; the Output to stop with, when it cannot.
476
487
  */
477
- const catchUp = (cycle: number) =>
488
+ const catchUp = (cycle: number, targetHead: string | undefined, forBlocker = false) =>
478
489
  Effect.gen(function* () {
479
490
  const refused = yield* takeTurn()
480
491
 
@@ -483,7 +494,10 @@ export default defineLoop({
483
494
  const synced = yield* syncBase(`sync:${cycle}`, { agent: 'implementer', target })
484
495
 
485
496
  if (synced.status === 'conflict')
486
- return done('needs_you', `Merging ${target} in conflicts on ${synced.files.join(', ')}: ${synced.reason}`)
497
+ return handBack(
498
+ `Merging ${target} in conflicts on ${synced.files.join(', ')}: ${synced.reason}`,
499
+ synced.files.map(file => `- ${file}`).join('\n')
500
+ )
487
501
 
488
502
  if (synced.status !== 'merged') return undefined
489
503
  const caught = synced.catchUp
@@ -525,6 +539,10 @@ export default defineLoop({
525
539
  if (caught !== undefined) {
526
540
  pushed = { head: caught.head, stale: 0, by: 'the catch-up' }
527
541
 
542
+ if (targetHead !== undefined) syncedFor.add(syncedKey(caught.head, targetHead))
543
+
544
+ if (forBlocker) blockerSynced.add(caught.head)
545
+
528
546
  yield* waitFor(`pushed:${cycle}`, {
529
547
  event: 'change_request.mergeable',
530
548
  filter: { changeRequestId, head: caught.head },
@@ -596,6 +614,32 @@ export default defineLoop({
596
614
  else return found
597
615
  }
598
616
 
617
+ if (pipeline.conflicts === true || pipeline.needsRebase === true) {
618
+ const blocker = pipeline.conflicts === true ? `conflicts with ${target}` : `needs ${target} merged in`
619
+ const targetHead = pipeline.target?.head
620
+
621
+ const syncedAlready =
622
+ targetHead === undefined
623
+ ? blockerSynced.has(pipeline.head)
624
+ : syncedFor.has(syncedKey(pipeline.head, targetHead))
625
+
626
+ if (syncedAlready)
627
+ return handBack(
628
+ `The forge still says ${pipeline.head} ${blocker} after merging it in`,
629
+ `Merge ${target} into the branch and settle what conflicts.`
630
+ )
631
+
632
+ if (targetHead !== undefined) syncedFor.add(syncedKey(pipeline.head, targetHead))
633
+ blockerSynced.add(pipeline.head)
634
+ behind = false
635
+
636
+ const stopped = yield* catchUp(cycle, targetHead, true)
637
+
638
+ if (stopped !== undefined) return stopped
639
+
640
+ continue
641
+ }
642
+
599
643
  // The forge runs no pipeline for this repository: its pipeline runs on a Runner and is reported to Kitman.
600
644
  if (pipeline.status === 'none' && pipeline.runnerChecks !== undefined) {
601
645
  if (ranOnRunner.has(pipeline.head))
@@ -627,7 +671,7 @@ export default defineLoop({
627
671
  if (targetMoved) {
628
672
  redTarget = undefined
629
673
 
630
- const stopped = yield* catchUp(cycle)
674
+ const stopped = yield* catchUp(cycle, pipeline.target?.head)
631
675
 
632
676
  if (stopped !== undefined) return stopped
633
677
 
@@ -653,7 +697,7 @@ export default defineLoop({
653
697
  if (onTarget.passed.length > 0 && redTarget?.head === pipeline.head) {
654
698
  redTarget = undefined
655
699
 
656
- const stopped = yield* catchUp(cycle)
700
+ const stopped = yield* catchUp(cycle, pipeline.target?.head)
657
701
 
658
702
  if (stopped !== undefined) return stopped
659
703
 
@@ -787,7 +831,7 @@ export default defineLoop({
787
831
  if (mergeable.payload.mergeable === false || behind) {
788
832
  behind = false
789
833
 
790
- const stopped = yield* catchUp(cycle)
834
+ const stopped = yield* catchUp(cycle, pipeline.target?.head)
791
835
 
792
836
  if (stopped !== undefined) return stopped
793
837
 
@@ -1128,10 +1172,16 @@ export default defineLoop({
1128
1172
  }
1129
1173
  }
1130
1174
  }).pipe(
1131
- // Kitman fails a Step that runs past its time budget with this reason.
1132
1175
  Effect.catchIf(
1133
- error => error._tag === 'StepFailed' && error.reason.includes('time budget'),
1134
- error => Effect.succeed(done('needs_you', `Step "${error.step}" ran past its ${stepBudget} budget`))
1176
+ (error): error is Extract<typeof error, { readonly _tag: 'StepFailed' }> =>
1177
+ error._tag === 'StepFailed' && (isUnansweredQuestion(error.reason) || error.reason.includes('time budget')),
1178
+ error =>
1179
+ Effect.succeed(
1180
+ // An unanswered Question's reason carries the agent's own words, which may mention a time budget.
1181
+ isUnansweredQuestion(error.reason)
1182
+ ? handBack(`Step "${error.step}" stopped on a Question nobody answers in full auto`, error.reason)
1183
+ : done('needs_you', `Step "${error.step}" ran past its ${stepBudget} budget`)
1184
+ )
1135
1185
  ),
1136
1186
  Effect.catchTags({
1137
1187
  WaitTimedOut: timedOut =>