@kitman-sh/software-engineering 0.10.76 → 0.10.77

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/bundle.js CHANGED
@@ -19039,6 +19039,8 @@ var ask = (name, question) => takeStep(name, "ask", "ask", gen2(function* () {
19039
19039
  return yield* new QuestionRefused({ step: name, answer: fallback, options });
19040
19040
  if (question.auto !== undefined && options !== undefined && !options.includes(question.auto))
19041
19041
  return yield* new QuestionRefused({ step: name, answer: question.auto, options });
19042
+ if (question.unattendedAuto !== undefined && options !== undefined && !options.includes(question.unattendedAuto))
19043
+ return yield* new QuestionRefused({ step: name, answer: question.unattendedAuto, options });
19042
19044
  yield* launch(deferred, (host, token2) => host.putQuestion({
19043
19045
  step: name,
19044
19046
  prompt: question.prompt,
@@ -19046,6 +19048,7 @@ var ask = (name, question) => takeStep(name, "ask", "ask", gen2(function* () {
19046
19048
  ...advice,
19047
19049
  ...fallback === undefined ? undefined : { default: fallback },
19048
19050
  ...question.auto === undefined ? undefined : { auto: question.auto },
19051
+ ...question.unattendedAuto === undefined ? undefined : { unattendedAuto: question.unattendedAuto },
19049
19052
  ...question.timeout === undefined ? undefined : { timeoutMillis: toMillis(fromInputUnsafe2(question.timeout)) },
19050
19053
  token: token2
19051
19054
  }));
@@ -19058,10 +19061,17 @@ var ask = (name, question) => takeStep(name, "ask", "ask", gen2(function* () {
19058
19061
  return yield* new QuestionRefused({ step: name, answer, options });
19059
19062
  return offeredAnswer;
19060
19063
  }));
19061
- var call = (name, loop, input) => takeStep(name, "call", "call", gen2(function* () {
19064
+ var call = (name, loop, input, options) => takeStep(name, "call", "call", gen2(function* () {
19062
19065
  const deferred = childDeferred(name);
19063
19066
  const encoded = yield* toJson2(name, loop.input, input);
19064
- yield* launch(deferred, (host, token2) => host.admitChild({ step: name, loop: loop.id, input: encoded, token: token2 }));
19067
+ const constraints = options?.constraints ?? [];
19068
+ yield* launch(deferred, (host, token2) => host.admitChild({
19069
+ step: name,
19070
+ loop: loop.id,
19071
+ input: encoded,
19072
+ ...constraints.length === 0 ? undefined : { constraints },
19073
+ token: token2
19074
+ }));
19065
19075
  const result = yield* await_2(deferred);
19066
19076
  return yield* decodeEffect2(toCodecJson2(loop.output))(result).pipe(mapError3((error) => new ChildFailed({ step: name, loop: loop.id, reason: error.message })));
19067
19077
  }));
@@ -19177,7 +19187,11 @@ var ArtifactRequest = Struct({
19177
19187
  files: optional2(ArraySchema(RunFile))
19178
19188
  });
19179
19189
  var ArtifactResult = Struct({ artifactId: String5 });
19180
- var NoteRequest = Struct({ text: String5, artifactId: optional2(String5) });
19190
+ var NoteRequest = Struct({
19191
+ text: String5,
19192
+ artifactId: optional2(String5),
19193
+ kind: optional2(Literals(["note", "blocker"]))
19194
+ });
19181
19195
  var CreateTasksRequest = Struct({
19182
19196
  tickets: ArraySchema(PlanTicket),
19183
19197
  projectId: optionalKey2(String5)
@@ -20321,10 +20335,17 @@ var scriptedHost = (script, engine, agentLaunches, childLaunches, waits, verifyL
20321
20335
  ...launch.mergeTarget === undefined ? undefined : { mergeTarget: launch.mergeTarget }
20322
20336
  })), resolve(agentDeferredNamed(launch.deferredName), launch.token, scriptedExit(script.outputs?.[launch.step], (reason) => new StepFailed({ step: launch.step, reason })))),
20323
20337
  putQuestion: (launch) => {
20324
- const answer = script.answers?.[launch.step] ?? (script.fullAuto === true ? launch.auto : undefined) ?? launch.default;
20338
+ const attended = script.attended === true;
20339
+ const auto = script.fullAuto === true ? launch.auto ?? (attended ? undefined : launch.unattendedAuto) : undefined;
20340
+ const answer = script.answers?.[launch.step] ?? auto ?? (attended ? undefined : launch.default);
20325
20341
  return resolve(answerDeferred(launch.step), launch.token, answer === undefined ? fail5(new StepFailed({ step: launch.step, reason: "no answer was scripted" })) : succeed4(answer));
20326
20342
  },
20327
- admitChild: (launch) => andThen2(sync2(() => childLaunches.push({ step: launch.step, loop: launch.loop, input: launch.input })), resolve(childDeferred(launch.step), launch.token, scriptedExit(script.children?.[launch.step], (reason) => new ChildFailed({ step: launch.step, loop: launch.loop, reason })))),
20343
+ admitChild: (launch) => andThen2(sync2(() => childLaunches.push({
20344
+ step: launch.step,
20345
+ loop: launch.loop,
20346
+ input: launch.input,
20347
+ ...launch.constraints === undefined ? undefined : { constraints: launch.constraints }
20348
+ })), resolve(childDeferred(launch.step), launch.token, scriptedExit(script.children?.[launch.step], (reason) => new ChildFailed({ step: launch.step, loop: launch.loop, reason })))),
20328
20349
  awaitEvent: (launch) => {
20329
20350
  const event = script.events?.[launch.step];
20330
20351
  waits.push({
@@ -22055,7 +22076,8 @@ var BuildInput = Struct({
22055
22076
  maxRounds: optional2(Int),
22056
22077
  continuing: optional2(Continuing),
22057
22078
  land: optional2(Boolean3),
22058
- changeRequestId: optional2(String5)
22079
+ changeRequestId: optional2(String5),
22080
+ maxRebuilds: optional2(Int.check(isGreaterThanOrEqualTo2(0)))
22059
22081
  });
22060
22082
  var CriterionAnswer = Struct({
22061
22083
  criterion: String5,
@@ -22105,6 +22127,11 @@ var BuildOutput = Struct({
22105
22127
  next: Struct({ changeRequestId: String5 })
22106
22128
  });
22107
22129
 
22130
+ class BuildBlocked extends TaggedError3()("BuildBlocked", {
22131
+ message: String5
22132
+ }) {
22133
+ }
22134
+
22108
22135
  class BuildTargetMissing extends TaggedError3()("BuildTargetMissing", {
22109
22136
  message: String5
22110
22137
  }) {
@@ -22180,6 +22207,10 @@ var fixPrompt = (settled) => {
22180
22207
  ].join(`
22181
22208
  `);
22182
22209
  };
22210
+ var takenOverAnswer = "Taken over";
22211
+ var buildAgainAnswer = "Build again";
22212
+ var blockedAnswer = "Mark blocked";
22213
+ var standingConstraint = (item) => `Settle what an earlier Build left standing: ${item}`;
22183
22214
  var blockingIds = (settled) => settled.open.filter(isBlocking).map((finding) => finding.id);
22184
22215
  var onlyChecksBlock = (settled) => blockingIds(settled).every(isCheckFinding) && !settled.standing.some((entry) => isBlocking(entry.finding));
22185
22216
  var rally = (input) => gen2(function* () {
@@ -22252,9 +22283,9 @@ var rally = (input) => gen2(function* () {
22252
22283
  last = { head, settled, scope: reviewed.scope };
22253
22284
  }
22254
22285
  });
22255
- var build_default = defineLoop({
22286
+ var build2 = defineLoop({
22256
22287
  id: "build",
22257
- version: "2.3.0",
22288
+ version: "2.4.0",
22258
22289
  title: "Build",
22259
22290
  input: BuildInput,
22260
22291
  output: BuildOutput,
@@ -22267,7 +22298,7 @@ var build_default = defineLoop({
22267
22298
  { id: "retry", title: "Retry with a steer", loop: "build" }
22268
22299
  ],
22269
22300
  capabilities: ["agent_work", "verify", "change_request", "write_back", "post_comment", "approve_change_request"],
22270
- calls: () => [review_default, shepherd_default],
22301
+ calls: () => [review_default, shepherd_default, build2],
22271
22302
  run: (input) => gen2(function* () {
22272
22303
  if (input.words === undefined && input.taskId === undefined)
22273
22304
  return yield* new BuildTargetMissing({ message: "Give the words to build, or a Task" });
@@ -22349,22 +22380,7 @@ var build_default = defineLoop({
22349
22380
  summary: `Review round ${last.round} passed with nothing blocking.`,
22350
22381
  review: `review:${last.round}`
22351
22382
  }).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,
22383
+ let settledAs = {
22368
22384
  revision: last.head.revision,
22369
22385
  tree: last.head.tree,
22370
22386
  settled: unsettled.length === 0,
@@ -22373,12 +22389,78 @@ var build_default = defineLoop({
22373
22389
  stopped: last.decision.reason,
22374
22390
  criteria,
22375
22391
  ...lastNotRun.length === 0 ? undefined : { notRun: lastNotRun },
22376
- ...approval === undefined ? undefined : { approval },
22392
+ ...approval === undefined ? undefined : { approval }
22393
+ };
22394
+ const maxRebuilds = input.maxRebuilds ?? 1;
22395
+ for (let rebuilds = 0;input.land !== false && settledAs.unsettled.length > 0; ) {
22396
+ const standing = settledAs.unsettled;
22397
+ const again = rebuilds < maxRebuilds;
22398
+ const answer = yield* ask(rebuilds === 0 ? "unsettled" : `unsettled:${rebuilds + 1}`, {
22399
+ prompt: `The ChangeRequest ${opened.url} is open, but these still stand: ${standing.join("; ")}. Build will not land it.`,
22400
+ options: [
22401
+ { value: takenOverAnswer, description: "A person fixes, rebuts or steers it from here." },
22402
+ again ? {
22403
+ value: buildAgainAnswer,
22404
+ description: "Starts one more Build on this branch, with each of these as a constraint."
22405
+ } : {
22406
+ value: blockedAnswer,
22407
+ description: "Fails this Build, recording these as a blocker on its Task, and tells its owner."
22408
+ }
22409
+ ],
22410
+ recommended: takenOverAnswer,
22411
+ recommendationReason: "Build stopped with these unsettled, so the next step is a person\u2019s.",
22412
+ default: null,
22413
+ unattendedAuto: again ? buildAgainAnswer : blockedAnswer
22414
+ });
22415
+ if (answer === takenOverAnswer)
22416
+ break;
22417
+ if (answer === blockedAnswer) {
22418
+ if (input.taskId !== undefined)
22419
+ yield* note("blocked", {
22420
+ kind: "blocker",
22421
+ text: [
22422
+ `Build stopped without landing ${opened.url}, marked blocked on what still stands:`,
22423
+ "",
22424
+ ...standing.map((item) => `- ${item}`)
22425
+ ].join(`
22426
+ `)
22427
+ });
22428
+ return yield* new BuildBlocked({
22429
+ message: `The ChangeRequest ${opened.url} is open, and Build was marked blocked on what still stands: ${standing.join("; ")}`
22430
+ });
22431
+ }
22432
+ rebuilds++;
22433
+ const {
22434
+ changeRequest: _,
22435
+ landed: __,
22436
+ next: ___,
22437
+ ...rebuilt
22438
+ } = yield* call(`rebuild:${rebuilds}`, { id: "build", input: BuildInput, output: BuildOutput }, {
22439
+ ...input.words === undefined ? undefined : { words: input.words },
22440
+ ...input.taskId === undefined ? undefined : { taskId: input.taskId },
22441
+ ...input.repoBindingId === undefined ? undefined : { repoBindingId: input.repoBindingId },
22442
+ ...input.outcome === undefined ? undefined : { outcome: input.outcome },
22443
+ ...input.maxRounds === undefined ? undefined : { maxRounds: input.maxRounds },
22444
+ changeRequestId: opened.id,
22445
+ land: false
22446
+ }, { constraints: standing.map(standingConstraint) });
22447
+ settledAs = rebuilt;
22448
+ }
22449
+ const landed = input.land !== false && settledAs.unsettled.length === 0 ? yield* call("land", shepherd_default, {
22450
+ changeRequestId: opened.id,
22451
+ ...settledAs.notRun === undefined ? undefined : { notRun: settledAs.notRun },
22452
+ ...input.taskId === undefined ? undefined : { taskId: input.taskId },
22453
+ ...input.branch === undefined ? undefined : { branch: input.branch }
22454
+ }) : undefined;
22455
+ return {
22456
+ changeRequest: opened,
22457
+ ...settledAs,
22377
22458
  ...landed === undefined ? undefined : { landed },
22378
22459
  next: { changeRequestId: opened.id }
22379
22460
  };
22380
22461
  }).pipe(tapError2(() => ignore2(writeBack("write-back:failed", { milestone: "failed" }))))
22381
22462
  });
22463
+ var build_default = build2;
22382
22464
 
22383
22465
  // src/errand.ts
22384
22466
  var Input4 = Struct({
@@ -26925,6 +27007,7 @@ class RunnerCapabilityRpcs extends make30(make29("PutQuestion", {
26925
27007
  verification: optional2(SuggestedVerification),
26926
27008
  default: optional2(String5),
26927
27009
  auto: optional2(String5),
27010
+ unattendedAuto: optional2(String5),
26928
27011
  timeoutMillis: optional2(Finite),
26929
27012
  deferredName: String5
26930
27013
  },
@@ -26995,6 +27078,7 @@ class RunnerCapabilityRpcs extends make30(make29("PutQuestion", {
26995
27078
  step: String5,
26996
27079
  loop: String5,
26997
27080
  input: Json2,
27081
+ constraints: optional2(ArraySchema(String5)),
26998
27082
  deferredName: String5
26999
27083
  },
27000
27084
  success: Struct({ runId: String5 }),
@@ -27016,7 +27100,8 @@ class RunnerCapabilityRpcs extends make30(make29("PutQuestion", {
27016
27100
  lease: ProgramLease,
27017
27101
  step: String5,
27018
27102
  text: String5,
27019
- artifactId: optional2(String5)
27103
+ artifactId: optional2(String5),
27104
+ kind: optional2(Literals(["note", "blocker"]))
27020
27105
  },
27021
27106
  error: RunnerRpcError
27022
27107
  }), make29("PerformHostEffect", {
@@ -27450,6 +27535,7 @@ var runnerHost = (capabilities) => ({
27450
27535
  ...launch.verification === undefined ? undefined : { verification: launch.verification },
27451
27536
  ...launch.default === undefined ? undefined : { default: launch.default },
27452
27537
  ...launch.auto === undefined ? undefined : { auto: launch.auto },
27538
+ ...launch.unattendedAuto === undefined ? undefined : { unattendedAuto: launch.unattendedAuto },
27453
27539
  ...launch.timeoutMillis === undefined ? undefined : { timeoutMillis: launch.timeoutMillis }
27454
27540
  })).pipe(asVoid2),
27455
27541
  startVerification: (launch) => requested(launch.step, capabilities.startVerification({
@@ -27477,6 +27563,7 @@ var runnerHost = (capabilities) => ({
27477
27563
  step: launch.step,
27478
27564
  loop: launch.loop,
27479
27565
  input: launch.input,
27566
+ ...launch.constraints === undefined ? undefined : { constraints: launch.constraints },
27480
27567
  deferredName: childDeferred(launch.step).name
27481
27568
  })).pipe(asVoid2),
27482
27569
  claimResource: (launch) => requested(launch.step, capabilities.claimResource({
@@ -27673,6 +27760,7 @@ var rpcProgramPorts = (rpc, work) => {
27673
27760
  ...question.verification === undefined ? undefined : { verification: question.verification },
27674
27761
  ...question.default === undefined ? undefined : { default: question.default },
27675
27762
  ...question.auto === undefined ? undefined : { auto: question.auto },
27763
+ ...question.unattendedAuto === undefined ? undefined : { unattendedAuto: question.unattendedAuto },
27676
27764
  ...question.timeoutMillis === undefined ? undefined : { timeoutMillis: question.timeoutMillis }
27677
27765
  }),
27678
27766
  startVerification: (verification) => rpc.startVerification({
@@ -27688,7 +27776,11 @@ var rpcProgramPorts = (rpc, work) => {
27688
27776
  startAgentStep: ({ secrets, ...step }) => rpc.startAgentStep({ lease, ...step, ...secrets === undefined ? undefined : { secrets: [...secrets] } }),
27689
27777
  awaitEvent: (wait) => rpc.awaitEvent({ lease, ...wait }),
27690
27778
  claimResource: (claim) => rpc.claimResource({ lease, ...claim }),
27691
- admitChild: (child) => rpc.admitChild({ lease, ...child }),
27779
+ admitChild: ({ constraints, ...child }) => rpc.admitChild({
27780
+ lease,
27781
+ ...child,
27782
+ ...constraints === undefined ? undefined : { constraints: [...constraints] }
27783
+ }),
27692
27784
  storeArtifact: ({ fileIds, ...artifact }) => rpc.storeArtifact({ lease, ...artifact, ...fileIds === undefined ? undefined : { fileIds: [...fileIds] } }),
27693
27785
  ...rpcRunFiles(rpc, lease),
27694
27786
  recordNote: (note) => rpc.recordNote({ lease, ...note }),
@@ -29975,4 +30067,4 @@ var runKit = (config, identity, packages) => {
29975
30067
  runMain2(program.pipe(flatMap3((code) => sync2(() => process.exit(code)))));
29976
30068
  };
29977
30069
  // .kitman-build-entry.ts
29978
- runKit(kitman_config_default, { name: "@kitman-sh/software-engineering", version: "0.10.76" }, []);
30070
+ runKit(kitman_config_default, { name: "@kitman-sh/software-engineering", version: "0.10.77" }, []);
@@ -3,7 +3,7 @@
3
3
  {
4
4
  "id": "build",
5
5
  "title": "Build",
6
- "version": "2.3.0",
6
+ "version": "2.4.0",
7
7
  "input": {
8
8
  "type": "object",
9
9
  "properties": {
@@ -182,6 +182,18 @@
182
182
  "type": "null"
183
183
  }
184
184
  ]
185
+ },
186
+ "maxRebuilds": {
187
+ "anyOf": [
188
+ {
189
+ "type": "integer",
190
+ "minimum": 0,
191
+ "maximum": 9007199254740991
192
+ },
193
+ {
194
+ "type": "null"
195
+ }
196
+ ]
185
197
  }
186
198
  },
187
199
  "additionalProperties": true,
@@ -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.77",
3375
3387
  "setup": "2a237548a69b0cd53ec3be7f687cfa8c2128335b3a655d34e185f2abce6a3c37",
3376
3388
  "loops": [
3377
3389
  "build",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitman-sh/software-engineering",
3
- "version": "0.10.76",
3
+ "version": "0.10.77",
4
4
  "description": "Everything for building software: Loops, their Agents, the skills they use and the Ponytail plugin.",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",
@@ -17,12 +17,12 @@
17
17
  "tsconfig.json"
18
18
  ],
19
19
  "dependencies": {
20
- "@kitman-sh/sdk": "0.10.76",
20
+ "@kitman-sh/sdk": "0.10.77",
21
21
  "effect": "4.1.2"
22
22
  },
23
23
  "kitman": {
24
24
  "bundle": "dist/bundle.js",
25
- "digest": "b4e95b0c8f4903ce4470016ecfe7a3f4b2e06596609cad0c60bd5bd73690f661",
25
+ "digest": "8ef24b6204d3b3602670c240f18dd0039f956ab84137ec2db22a97bf7ca0270e",
26
26
  "protocolVersion": 5,
27
27
  "declarations": "dist/declarations.json",
28
28
  "setup": {
package/src/build.ts CHANGED
@@ -18,6 +18,7 @@ import {
18
18
  failsOn,
19
19
  isBlocking,
20
20
  LoopOutcome,
21
+ note,
21
22
  rallyStop,
22
23
  Rebuttal,
23
24
  settleRound,
@@ -65,7 +66,12 @@ export const BuildInput = Schema.Struct({
65
66
  * An open ChangeRequest to fix forward on: the Run works its branch, never force-pushing, and reports in one comment
66
67
  * on it, leaving the ChangeRequest's title and description to its author.
67
68
  */
68
- changeRequestId: Schema.optional(Schema.String)
69
+ changeRequestId: Schema.optional(Schema.String),
70
+ /**
71
+ * How many more Builds an unattended full-auto Run starts on its ChangeRequest while review findings still stand,
72
+ * before it fails with them; 1 when left out.
73
+ */
74
+ maxRebuilds: Schema.optional(Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)))
69
75
  })
70
76
 
71
77
  /** The implementer's answer to one acceptance criterion of the Task. */
@@ -139,6 +145,11 @@ export const BuildOutput = Schema.Struct({
139
145
  next: Schema.Struct({ changeRequestId: Schema.String })
140
146
  })
141
147
 
148
+ /** Build was marked blocked on findings that still stand, so the Task waits on its owner. */
149
+ export class BuildBlocked extends Schema.TaggedError<BuildBlocked>()('BuildBlocked', {
150
+ message: Schema.String
151
+ }) {}
152
+
142
153
  export class BuildTargetMissing extends Schema.TaggedError<BuildTargetMissing>()('BuildTargetMissing', {
143
154
  message: Schema.String
144
155
  }) {}
@@ -235,6 +246,14 @@ const fixPrompt = (settled: SettledRound) => {
235
246
  ].join('\n')
236
247
  }
237
248
 
249
+ const takenOverAnswer = 'Taken over'
250
+
251
+ const buildAgainAnswer = 'Build again'
252
+
253
+ const blockedAnswer = 'Mark blocked'
254
+
255
+ const standingConstraint = (item: string) => `Settle what an earlier Build left standing: ${item}`
256
+
238
257
  const blockingIds = (settled: SettledRound) => settled.open.filter(isBlocking).map(finding => finding.id)
239
258
 
240
259
  const onlyChecksBlock = (settled: SettledRound) =>
@@ -369,11 +388,12 @@ const rally = (input: {
369
388
  /**
370
389
  * Implements a Task or words, reviews and fixes until the rally stops, gates on the evidence for the head, and opens
371
390
  * the Run's ChangeRequest with the evidence, the claims and whatever it could not settle (ADR-0051). It writes the
372
- * Run's milestones to its Task: started, ChangeRequest opened, and failed.
391
+ * Run's milestones to its Task: started, ChangeRequest opened, and failed. Findings that still stand once full auto's
392
+ * rebuilds run out go on the Task as a blocker before the Run fails.
373
393
  */
374
- export default defineLoop({
394
+ const build = defineLoop({
375
395
  id: 'build',
376
- version: '2.3.0',
396
+ version: '2.4.0',
377
397
  title: 'Build',
378
398
  input: BuildInput,
379
399
  output: BuildOutput,
@@ -386,7 +406,7 @@ export default defineLoop({
386
406
  { id: 'retry', title: 'Retry with a steer', loop: 'build' }
387
407
  ],
388
408
  capabilities: ['agent_work', 'verify', 'change_request', 'write_back', 'post_comment', 'approve_change_request'],
389
- calls: (): readonly CalledLoop[] => [review, shepherd],
409
+ calls: (): readonly CalledLoop[] => [review, shepherd, build],
390
410
  run: input =>
391
411
  Effect.gen(function* () {
392
412
  if (input.words === undefined && input.taskId === undefined)
@@ -524,40 +544,107 @@ export default defineLoop({
524
544
  )
525
545
  : undefined
526
546
 
527
- // A blocking Review, or anything else left unsettled, stops here with the findings for a person, not in Shepherd.
547
+ let settledAs: Omit<typeof BuildOutput.Type, 'changeRequest' | 'landed' | 'next'> = {
548
+ revision: last.head.revision,
549
+ tree: last.head.tree,
550
+ settled: unsettled.length === 0,
551
+ unsettled,
552
+ rounds: last.round,
553
+ stopped: last.decision.reason,
554
+ criteria,
555
+ ...(lastNotRun.length === 0 ? undefined : { notRun: lastNotRun }),
556
+ ...(approval === undefined ? undefined : { approval })
557
+ }
558
+
559
+ const maxRebuilds = input.maxRebuilds ?? 1
560
+
561
+ // Anything left unsettled stops here with the findings for a person, not in Shepherd. Full auto builds again on
562
+ // the same branch up to the cap, then fails with them rather than wait on a Question nobody answers.
563
+ for (let rebuilds = 0; input.land !== false && settledAs.unsettled.length > 0;) {
564
+ const standing = settledAs.unsettled
565
+ const again = rebuilds < maxRebuilds
566
+
567
+ const answer = yield* ask(rebuilds === 0 ? 'unsettled' : `unsettled:${rebuilds + 1}`, {
568
+ prompt: `The ChangeRequest ${opened.url} is open, but these still stand: ${standing.join('; ')}. Build will not land it.`,
569
+ options: [
570
+ { value: takenOverAnswer, description: 'A person fixes, rebuts or steers it from here.' },
571
+ again
572
+ ? {
573
+ value: buildAgainAnswer,
574
+ description: 'Starts one more Build on this branch, with each of these as a constraint.'
575
+ }
576
+ : {
577
+ value: blockedAnswer,
578
+ description: 'Fails this Build, recording these as a blocker on its Task, and tells its owner.'
579
+ }
580
+ ],
581
+ recommended: takenOverAnswer,
582
+ recommendationReason: 'Build stopped with these unsettled, so the next step is a person’s.',
583
+ // No default: an unattended Run would take it at once even in a gated Team, and finish as partial.
584
+ default: null,
585
+ unattendedAuto: again ? buildAgainAnswer : blockedAnswer
586
+ })
587
+
588
+ if (answer === takenOverAnswer) break
589
+
590
+ if (answer === blockedAnswer) {
591
+ if (input.taskId !== undefined)
592
+ yield* note('blocked', {
593
+ kind: 'blocker',
594
+ text: [
595
+ `Build stopped without landing ${opened.url}, marked blocked on what still stands:`,
596
+ '',
597
+ ...standing.map(item => `- ${item}`)
598
+ ].join('\n')
599
+ })
600
+
601
+ return yield* new BuildBlocked({
602
+ message: `The ChangeRequest ${opened.url} is open, and Build was marked blocked on what still stands: ${standing.join('; ')}`
603
+ })
604
+ }
605
+
606
+ rebuilds++
607
+
608
+ const {
609
+ changeRequest: _,
610
+ landed: __,
611
+ next: ___,
612
+ ...rebuilt
613
+ } = yield* call(
614
+ `rebuild:${rebuilds}`,
615
+ { id: 'build', input: BuildInput, output: BuildOutput },
616
+ {
617
+ ...(input.words === undefined ? undefined : { words: input.words }),
618
+ ...(input.taskId === undefined ? undefined : { taskId: input.taskId }),
619
+ ...(input.repoBindingId === undefined ? undefined : { repoBindingId: input.repoBindingId }),
620
+ ...(input.outcome === undefined ? undefined : { outcome: input.outcome }),
621
+ ...(input.maxRounds === undefined ? undefined : { maxRounds: input.maxRounds }),
622
+ changeRequestId: opened.id,
623
+ land: false
624
+ },
625
+ { constraints: standing.map(standingConstraint) }
626
+ )
627
+
628
+ settledAs = rebuilt
629
+ }
630
+
528
631
  const landed =
529
- input.land !== false && unsettled.length === 0
632
+ input.land !== false && settledAs.unsettled.length === 0
530
633
  ? yield* call('land', shepherd, {
531
634
  changeRequestId: opened.id,
532
- ...(lastNotRun.length === 0 ? undefined : { notRun: lastNotRun }),
635
+ ...(settledAs.notRun === undefined ? undefined : { notRun: settledAs.notRun }),
533
636
  ...(input.taskId === undefined ? undefined : { taskId: input.taskId }),
534
637
  ...(input.branch === undefined ? undefined : { branch: input.branch })
535
638
  })
536
639
  : undefined
537
640
 
538
- if (input.land !== false && unsettled.length > 0)
539
- yield* ask('unsettled', {
540
- prompt: `The ChangeRequest ${opened.url} is open, but these still stand: ${unsettled.join('; ')}. Build will not land it.`,
541
- options: [{ value: 'Taken over', description: 'A person fixes, rebuts or steers it from here.' }],
542
- recommended: 'Taken over',
543
- recommendationReason: 'Build stopped with these unsettled, so the next step is a person’s.',
544
- // No default: an unattended Run, as full auto starts, would take it at once and finish as partial.
545
- default: null
546
- })
547
-
548
641
  return {
549
642
  changeRequest: opened,
550
- revision: last.head.revision,
551
- tree: last.head.tree,
552
- settled: unsettled.length === 0,
553
- unsettled,
554
- rounds: last.round,
555
- stopped: last.decision.reason,
556
- criteria,
557
- ...(lastNotRun.length === 0 ? undefined : { notRun: lastNotRun }),
558
- ...(approval === undefined ? undefined : { approval }),
643
+ ...settledAs,
559
644
  ...(landed === undefined ? undefined : { landed }),
560
645
  next: { changeRequestId: opened.id }
561
646
  }
562
647
  }).pipe(Effect.tapError(() => Effect.ignore(writeBack('write-back:failed', { milestone: 'failed' }))))
563
648
  })
649
+
650
+ export default build