@kitman-sh/software-engineering 0.10.101 → 0.10.103

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
@@ -12291,6 +12291,38 @@ var LoopLayers = ["team", "workspace"];
12291
12291
  var AgentEfforts = ["low", "medium", "high", "xhigh"];
12292
12292
  var AgentCapabilities = ["web", "subagents", "artifacts", "browser"];
12293
12293
 
12294
+ // ../../packages/core/src/release-trigger.ts
12295
+ var ReleaseTrigger = Literals(["merge", "milestone", "project"]);
12296
+ var ReleaseTriggerLayer = Literals(["run", "project", "team", "workspace"]);
12297
+ var ResolvedReleaseTrigger = Struct({ trigger: ReleaseTrigger, layer: ReleaseTriggerLayer });
12298
+ var ReleaseTriggerSetting = Struct({
12299
+ trigger: NullOr(ReleaseTrigger),
12300
+ resolved: optionalKey2(ResolvedReleaseTrigger)
12301
+ });
12302
+ var ReleaseTriggerUpdate = Struct({
12303
+ trigger: NullOr(ReleaseTrigger)
12304
+ });
12305
+ var ReleaseScope = Struct({
12306
+ kind: Literals(["milestone", "project"]),
12307
+ projectId: String5,
12308
+ projectName: optionalKey2(String5),
12309
+ milestoneId: optionalKey2(String5),
12310
+ milestoneName: optionalKey2(String5),
12311
+ tasks: ArraySchema(Struct({ id: String5, key: String5, title: String5 }))
12312
+ });
12313
+ var ShippedScope = Struct({
12314
+ kind: Literals(["milestone", "project"]),
12315
+ projectId: String5,
12316
+ milestoneId: optionalKey2(String5),
12317
+ taskIds: ArraySchema(String5)
12318
+ });
12319
+ var shippedScope = (scope) => ({
12320
+ kind: scope.kind,
12321
+ projectId: scope.projectId,
12322
+ ...scope.milestoneId === undefined ? undefined : { milestoneId: scope.milestoneId },
12323
+ taskIds: scope.tasks.map((task) => task.id)
12324
+ });
12325
+
12294
12326
  // ../../packages/core/src/context-pack.ts
12295
12327
  var ContextPackIndexEntryKinds = [
12296
12328
  "task",
@@ -14300,7 +14332,9 @@ var RunHeader = Struct({
14300
14332
  startedBy: optionalKey2(Union2([
14301
14333
  Struct({ kind: Literal2("person"), name: String5 }),
14302
14334
  Struct({ kind: Literal2("event"), event: String5 })
14303
- ]))
14335
+ ])),
14336
+ releaseWhen: optionalKey2(ResolvedReleaseTrigger),
14337
+ releaseScope: optionalKey2(ReleaseScope)
14304
14338
  });
14305
14339
  var RunShow = Struct({
14306
14340
  run: Run,
@@ -19312,11 +19346,15 @@ var IntegrationBranch = Struct({
19312
19346
  });
19313
19347
  var MergeChangeRequestRequest = Struct({
19314
19348
  changeRequestId: String5,
19315
- head: optionalKey2(String5)
19349
+ head: optionalKey2(String5),
19350
+ rebase: optionalKey2(Boolean3)
19316
19351
  });
19317
19352
  var MergeResult = Union2([
19318
19353
  Struct({ status: Literal2("merged"), revision: String5 }),
19319
- Struct({ status: Literal2("conflict") }),
19354
+ Struct({
19355
+ status: Literal2("conflict"),
19356
+ reason: optionalKey2(Literals(["conflicts", "behind", "not_ready"]))
19357
+ }),
19320
19358
  Struct({ status: Literal2("moved"), head: String5 })
19321
19359
  ]);
19322
19360
  var ApproveChangeRequestRequest = Struct({
@@ -21177,7 +21215,11 @@ var Input2 = Struct({
21177
21215
  changeRequestId: optional2(String5),
21178
21216
  deployTarget: optional2(String5),
21179
21217
  deployEvent: optional2(String5),
21180
- deployTimeoutMinutes: optional2(Int)
21218
+ deployTimeoutMinutes: optional2(Int),
21219
+ repoBindingId: optional2(String5),
21220
+ releaseTrigger: optional2(ReleaseTrigger),
21221
+ releaseWhen: optional2(ResolvedReleaseTrigger),
21222
+ releaseScope: optional2(ReleaseScope)
21181
21223
  });
21182
21224
  var Drafted = Struct({
21183
21225
  tag: String5,
@@ -21208,16 +21250,37 @@ var Output2 = Struct({
21208
21250
  "rolled_back",
21209
21251
  "deploy_failed",
21210
21252
  "rollback_failed",
21211
- "timed_out"
21253
+ "timed_out",
21254
+ "not_due",
21255
+ "no_version"
21212
21256
  ]),
21213
21257
  reason: String5,
21214
21258
  tag: optional2(String5),
21215
21259
  notesArtifactId: optional2(String5),
21216
21260
  revision: optional2(String5),
21217
- url: optional2(String5)
21218
- });
21219
- var draftPrompt = (tag, changeRequestId) => [
21261
+ url: optional2(String5),
21262
+ releaseWhen: optional2(ResolvedReleaseTrigger),
21263
+ shipped: optional2(ShippedScope)
21264
+ });
21265
+ var triggerWords = {
21266
+ milestone: "a Milestone is done",
21267
+ project: "its Project is done"
21268
+ };
21269
+ var layerWords = {
21270
+ run: "this Run",
21271
+ project: "its Project",
21272
+ team: "its Team",
21273
+ workspace: "the Workspace"
21274
+ };
21275
+ var scopeLine = (scope) => scope.kind === "milestone" ? `${scope.milestoneName === undefined ? "a Milestone" : `Milestone ${scope.milestoneName}`} of ${scope.projectName ?? "its Project"}` : scope.projectName === undefined ? "its Project" : `Project ${scope.projectName}`;
21276
+ var scopePrompt2 = (scope) => scope === undefined ? [] : [
21277
+ `This release ships ${scopeLine(scope)}, now that its Tasks are done:`,
21278
+ scope.tasks.map((task) => `- ${task.key} ${task.title}`).join(`
21279
+ `)
21280
+ ];
21281
+ var draftPrompt = (tag, changeRequestId, scope) => [
21220
21282
  "Draft the release notes for the ChangeRequests merged since the last release tag on the base branch, including those with no linked Task.",
21283
+ ...scopePrompt2(scope),
21221
21284
  ...changeRequestId === undefined ? [] : [`The release ChangeRequest ${changeRequestId} is part of it.`],
21222
21285
  "Group them by what a user of the software notices, and name each ChangeRequest you cover.",
21223
21286
  tag === undefined ? "Propose the next version tag, following the scheme earlier tags use. With no earlier tag, propose v0.1.0 and say so in the notes." : `The release is tagged ${tag}.`,
@@ -21293,12 +21356,23 @@ var readyToMerge = (changeRequestId, round = 1) => gen2(function* () {
21293
21356
  var recovery = (previous) => previous === undefined ? ["Retry the deploy", "Leave it"] : ["Retry the deploy", `Roll back to ${previous}`, "Leave it"];
21294
21357
  var release_default = defineLoop({
21295
21358
  id: "release",
21296
- version: "2.0.0",
21359
+ version: "2.1.0",
21297
21360
  title: "Release",
21298
21361
  input: Input2,
21299
21362
  output: Output2,
21300
21363
  agents: { releaser: "releaser", deployer: "deployer" },
21301
21364
  checkout: "read",
21365
+ when: [
21366
+ {
21367
+ event: "release.due",
21368
+ input: {
21369
+ tag: "tag",
21370
+ releaseScope: "releaseScope",
21371
+ releaseWhen: "releaseWhen",
21372
+ repoBindingId: "repoBindingId"
21373
+ }
21374
+ }
21375
+ ],
21302
21376
  capabilities: [
21303
21377
  "agent_work",
21304
21378
  "ask",
@@ -21309,6 +21383,18 @@ var release_default = defineLoop({
21309
21383
  "merge_change_request"
21310
21384
  ],
21311
21385
  run: (input) => gen2(function* () {
21386
+ const when = input.releaseWhen;
21387
+ if (when !== undefined && when.trigger !== "merge" && input.releaseScope === undefined)
21388
+ return {
21389
+ status: "not_due",
21390
+ reason: `Release runs when ${triggerWords[when.trigger]}, as ${layerWords[when.layer]} says; this Run did not override that`
21391
+ };
21392
+ if (input.releaseScope !== undefined && input.tag === undefined)
21393
+ return {
21394
+ status: "no_version",
21395
+ reason: "Kitman cut no version for this Milestone or Project: its Project is not named by a full semver version. Release it with a tag.",
21396
+ shipped: shippedScope(input.releaseScope)
21397
+ };
21312
21398
  const changeRequestId = input.changeRequestId;
21313
21399
  let gated;
21314
21400
  if (changeRequestId === undefined) {
@@ -21357,7 +21443,7 @@ var release_default = defineLoop({
21357
21443
  }
21358
21444
  let drafted = yield* agentWork("draft-notes", {
21359
21445
  agent: "releaser",
21360
- prompt: draftPrompt(input.tag, changeRequestId),
21446
+ prompt: draftPrompt(input.tag, changeRequestId, input.releaseScope),
21361
21447
  output: Drafted
21362
21448
  });
21363
21449
  const tag = input.tag ?? drafted.tag;
@@ -21391,7 +21477,11 @@ ${drafted.notes}`,
21391
21477
  kind: "release_notes",
21392
21478
  title: drafted.title,
21393
21479
  text: drafted.notes,
21394
- data: { tag, changeRequests: drafted.changeRequests }
21480
+ data: {
21481
+ tag,
21482
+ changeRequests: drafted.changeRequests,
21483
+ ...input.releaseScope === undefined ? undefined : { shipped: shippedScope(input.releaseScope) }
21484
+ }
21395
21485
  });
21396
21486
  return { status: "rejected", reason: why, tag, notesArtifactId: kept.artifactId };
21397
21487
  }
@@ -21415,7 +21505,11 @@ ${drafted.notes}`,
21415
21505
  kind: "release_notes",
21416
21506
  title: drafted.title,
21417
21507
  text: drafted.notes,
21418
- data: { tag, changeRequests: drafted.changeRequests }
21508
+ data: {
21509
+ tag,
21510
+ changeRequests: drafted.changeRequests,
21511
+ ...input.releaseScope === undefined ? undefined : { shipped: shippedScope(input.releaseScope) }
21512
+ }
21419
21513
  });
21420
21514
  let revision = gated;
21421
21515
  if (changeRequestId !== undefined) {
@@ -21516,7 +21610,11 @@ ${drafted.notes}`,
21516
21610
  data: { tag, status, revision: released.revision, url: released.url }
21517
21611
  });
21518
21612
  return { status: "deployed", reason: `${tag} deployed`, ...settled };
21519
- })
21613
+ }).pipe(map8((output) => ({
21614
+ ...output,
21615
+ ...input.releaseWhen === undefined ? undefined : { releaseWhen: input.releaseWhen },
21616
+ ...input.releaseScope === undefined ? undefined : { shipped: shippedScope(input.releaseScope) }
21617
+ })))
21520
21618
  });
21521
21619
 
21522
21620
  // src/shepherd-output.ts
@@ -21527,6 +21625,7 @@ var ShepherdOutput = Struct({
21527
21625
  replies: Int,
21528
21626
  unsettled: optional2(ArraySchema(String5)),
21529
21627
  release: optional2(Struct({ runStatus: String5, reason: String5, tag: optional2(String5) })),
21628
+ releaseWhen: optional2(ResolvedReleaseTrigger),
21530
21629
  handBack: optional2(Struct({
21531
21630
  changeRequestId: String5,
21532
21631
  words: String5,
@@ -21549,8 +21648,11 @@ var Input3 = Struct({
21549
21648
  notRun: optional2(ArraySchema(String5)),
21550
21649
  branch: optional2(String5),
21551
21650
  continuing: optional2(Continuing),
21552
- maxCycles: optional2(Int)
21651
+ maxCycles: optional2(Int),
21652
+ releaseTrigger: optional2(ReleaseTrigger),
21653
+ releaseWhen: optional2(ResolvedReleaseTrigger)
21553
21654
  });
21655
+ var layerWords2 = { run: "this Run", project: "its Project", team: "its Team", workspace: "the Workspace" };
21554
21656
  var Output3 = ShepherdOutput;
21555
21657
  var CiFix = Struct({
21556
21658
  verdict: Literals(["fixed", "pre_existing", "flaky"]),
@@ -21680,8 +21782,10 @@ var shepherd_default = defineLoop({
21680
21782
  reason,
21681
21783
  fixRounds: fixRounds(),
21682
21784
  replies,
21785
+ ...input.releaseWhen === undefined ? undefined : { releaseWhen: input.releaseWhen },
21683
21786
  ...status === "needs_you" || status === "handed_back" ? { unsettled: [reason] } : undefined
21684
21787
  });
21788
+ const releaseWhen = input.releaseWhen;
21685
21789
  const handBack = (reason, open) => ({
21686
21790
  ...done("handed_back", reason),
21687
21791
  handBack: {
@@ -22270,6 +22374,8 @@ Merge now?`,
22270
22374
  continue;
22271
22375
  yield* passTurn();
22272
22376
  yield* writeBack("write-back", { milestone: "merged" });
22377
+ if (releaseWhen !== undefined && releaseWhen.trigger !== "merge")
22378
+ return done("merged", `Merged at ${merged.revision}; Release runs when its ${releaseWhen.trigger === "milestone" ? "Milestone" : "Project"} is done, as ${layerWords2[releaseWhen.layer]} says`);
22273
22379
  const ship = yield* ask("ship", {
22274
22380
  prompt: `Merged at ${merged.revision}. Release it now?`,
22275
22381
  options: [
@@ -22284,7 +22390,10 @@ Merge now?`,
22284
22390
  });
22285
22391
  if (ship === "Not now")
22286
22392
  return done("merged", `Merged at ${merged.revision}`);
22287
- const released = yield* call("release", release_default, { revision: merged.revision });
22393
+ const released = yield* call("release", release_default, {
22394
+ revision: merged.revision,
22395
+ ...releaseWhen?.layer === "run" ? { releaseTrigger: releaseWhen.trigger } : undefined
22396
+ });
22288
22397
  const handedOn = released.status === "gate_failed" && (yield* ask("release-gate-failed", {
22289
22398
  prompt: `Merged at ${merged.revision}, but its Release gate failed: ${released.reason}`,
22290
22399
  options: [
@@ -22304,7 +22413,7 @@ Merge now?`,
22304
22413
  ...done("merged", `Merged at ${merged.revision}; its Release gate failed, so the next Release ships it`),
22305
22414
  release: { runStatus: released.status, reason: released.reason }
22306
22415
  };
22307
- if (released.status !== "deployed" && released.status !== "rejected" && released.status !== "gate_failed")
22416
+ if (released.status !== "deployed" && released.status !== "rejected" && released.status !== "gate_failed" && released.status !== "not_due")
22308
22417
  yield* ask("release-failed", {
22309
22418
  prompt: `Merged at ${merged.revision}, but its Release ended ${released.status}: ${released.reason}`,
22310
22419
  options: [{ value: "Taken over", description: "A person looks at the release and production from here." }],
@@ -23394,6 +23503,8 @@ var menuDescriptions = {
23394
23503
  Refine: "You say what to change and the planner rewrites it.",
23395
23504
  Finish: "Ends the Run with the plan as it is."
23396
23505
  };
23506
+ var onConflict = ["Rebuild on the integration branch", "Skip"];
23507
+ var onHeld = ["Merge again", ...onConflict];
23397
23508
  var onFailure = ["Retry with a steer", "Skip it and its dependents", "Stop here"];
23398
23509
  var ticketRules = [
23399
23510
  "Each ticket is one Build: a vertical slice an agent can implement, review and deliver as one ChangeRequest. Give it a short unique key, and list in blockedBy the keys of the tickets whose code it needs; tickets never block each other in a cycle. Set repoBindingId only when it changes another repository than the plan, keep one repository per ticket, and no cycle across repositories. Set outcome to the kind of change: feature, bug, refactor, docs, migration, investigation or performance.",
@@ -23546,28 +23657,55 @@ Merge it once they pass by hand, or skip it and the tickets it blocks?`,
23546
23657
  if (unverified === "Skip")
23547
23658
  return settled(ticket, { status: "skipped", ...delivered, reason: "Verify never ran some of its tests" });
23548
23659
  }
23549
- const merged = yield* mergeChangeRequest(`merge:${name}${suffix}`, {
23550
- changeRequestId: built.changeRequest.id,
23551
- head: built.revision
23552
- });
23553
- if (merged.status === "merged")
23554
- return settled(ticket, { status: "merged", ...delivered });
23555
- const choice = yield* ask(`conflict:${name}${suffix}`, {
23556
- prompt: `The ChangeRequest for ${ticket.key} (${built.changeRequest.url}) ${merged.status === "moved" ? "changed after it was built" : `conflicts with ${head.branch}`}. Rebuild ${ticket.key} on the integration branch as it is now, or skip it and the tickets it blocks?`,
23557
- options: [
23558
- {
23559
- value: "Rebuild on the integration branch",
23560
- description: "Builds the ticket again from the branch as it is now."
23561
- },
23562
- { value: "Skip", description: "Leaves it and the tickets it blocks undelivered." }
23563
- ],
23564
- recommended: "Rebuild on the integration branch",
23565
- recommendationReason: "A rebuild on the current branch usually resolves a conflict, and skipping also drops every ticket it blocks.",
23566
- default: "Skip",
23567
- timeout: "1 hour"
23568
- });
23660
+ const rebuild = {
23661
+ value: "Rebuild on the integration branch",
23662
+ description: "Builds the ticket again from the branch as it is now."
23663
+ };
23664
+ const skip = { value: "Skip", description: "Leaves it and the tickets it blocks undelivered." };
23665
+ let choice = "Merge again";
23666
+ let refusal = `It conflicted with ${head.branch}`;
23667
+ for (let again = 0;choice === "Merge again"; again++) {
23668
+ const label = again === 0 ? suffix : `${suffix}:again:${again}`;
23669
+ const merged = yield* mergeChangeRequest(`merge:${name}${label}`, {
23670
+ changeRequestId: built.changeRequest.id,
23671
+ head: built.revision,
23672
+ rebase: true
23673
+ });
23674
+ if (merged.status === "merged")
23675
+ return settled(ticket, { status: "merged", ...delivered });
23676
+ const request = `The ChangeRequest for ${ticket.key} (${built.changeRequest.url})`;
23677
+ if (merged.status === "conflict" && merged.reason === "not_ready") {
23678
+ refusal = `The forge held it back from ${head.branch}`;
23679
+ choice = yield* ask(`conflict:${name}${label}`, {
23680
+ prompt: `${request} cannot merge into ${head.branch} yet: the forge holds it back, as for approvals, unresolved discussions, a draft or a pipeline that must pass first. Merge it again once that is settled, rebuild ${ticket.key} on the integration branch as it is now, or skip it and the tickets it blocks?`,
23681
+ options: [
23682
+ {
23683
+ value: "Merge again",
23684
+ description: "Tries the merge again, for once whatever holds it back is settled."
23685
+ },
23686
+ rebuild,
23687
+ skip
23688
+ ],
23689
+ recommended: "Merge again",
23690
+ recommendationReason: "Nothing conflicts, so a rebuild meets the same hold, and skipping also drops every ticket it blocks.",
23691
+ default: "Skip",
23692
+ timeout: "1 hour"
23693
+ });
23694
+ } else {
23695
+ const behind = merged.status === "conflict" && merged.reason === "behind";
23696
+ refusal = `${behind ? "It stayed behind" : "It conflicted with"} ${head.branch}`;
23697
+ choice = yield* ask(`conflict:${name}${label}`, {
23698
+ prompt: `${request} ${merged.status === "moved" ? "changed after it was built" : `${behind ? "is behind" : "conflicts with"} ${head.branch}`}. Rebuild ${ticket.key} on the integration branch as it is now, or skip it and the tickets it blocks?`,
23699
+ options: [rebuild, skip],
23700
+ recommended: "Rebuild on the integration branch",
23701
+ recommendationReason: "A rebuild on the current branch usually resolves a conflict, and skipping also drops every ticket it blocks.",
23702
+ default: "Skip",
23703
+ timeout: "1 hour"
23704
+ });
23705
+ }
23706
+ }
23569
23707
  if (choice === "Skip")
23570
- return settled(ticket, { status: "failed", ...delivered, reason: `It conflicted with ${head.branch}` });
23708
+ return settled(ticket, { status: "failed", ...delivered, reason: refusal });
23571
23709
  head = yield* integrationBranch(`rebuild-from:${name}:${attempt + 1}`, {
23572
23710
  repoBindingId: head.repoBindingId
23573
23711
  });
@@ -27673,11 +27811,15 @@ class RunnerCapabilityRpcs extends make30(make29("PutQuestion", {
27673
27811
  lease: ProgramLease,
27674
27812
  step: String5,
27675
27813
  changeRequestId: String5,
27676
- head: optionalKey2(String5)
27814
+ head: optionalKey2(String5),
27815
+ rebase: optionalKey2(Boolean3)
27677
27816
  },
27678
27817
  success: Union2([
27679
27818
  Struct({ status: Literal2("merged"), revision: String5 }),
27680
- Struct({ status: Literal2("conflict") }),
27819
+ Struct({
27820
+ status: Literal2("conflict"),
27821
+ reason: optionalKey2(Literals(["conflicts", "behind", "not_ready"]))
27822
+ }),
27681
27823
  Struct({ status: Literal2("moved"), head: String5 })
27682
27824
  ]),
27683
27825
  error: RunnerRpcError
@@ -30414,4 +30556,4 @@ var runKit = (config, identity, packages) => {
30414
30556
  runMain2(program.pipe(flatMap3((code) => sync2(() => process.exit(code)))));
30415
30557
  };
30416
30558
  // .kitman-build-entry.ts
30417
- runKit(kitman_config_default, { name: "@kitman-sh/software-engineering", version: "0.10.101" }, []);
30559
+ runKit(kitman_config_default, { name: "@kitman-sh/software-engineering", version: "0.10.103" }, []);
@@ -412,6 +412,40 @@
412
412
  }
413
413
  ]
414
414
  },
415
+ "releaseWhen": {
416
+ "anyOf": [
417
+ {
418
+ "type": "object",
419
+ "properties": {
420
+ "trigger": {
421
+ "type": "string",
422
+ "enum": [
423
+ "merge",
424
+ "milestone",
425
+ "project"
426
+ ]
427
+ },
428
+ "layer": {
429
+ "type": "string",
430
+ "enum": [
431
+ "run",
432
+ "project",
433
+ "team",
434
+ "workspace"
435
+ ]
436
+ }
437
+ },
438
+ "required": [
439
+ "trigger",
440
+ "layer"
441
+ ],
442
+ "additionalProperties": true
443
+ },
444
+ {
445
+ "type": "null"
446
+ }
447
+ ]
448
+ },
415
449
  "handBack": {
416
450
  "anyOf": [
417
451
  {
@@ -1595,7 +1629,7 @@
1595
1629
  {
1596
1630
  "id": "release",
1597
1631
  "title": "Release",
1598
- "version": "2.0.0",
1632
+ "version": "2.1.0",
1599
1633
  "input": {
1600
1634
  "type": "object",
1601
1635
  "properties": {
@@ -1660,6 +1694,125 @@
1660
1694
  "type": "null"
1661
1695
  }
1662
1696
  ]
1697
+ },
1698
+ "repoBindingId": {
1699
+ "anyOf": [
1700
+ {
1701
+ "type": "string"
1702
+ },
1703
+ {
1704
+ "type": "null"
1705
+ }
1706
+ ]
1707
+ },
1708
+ "releaseTrigger": {
1709
+ "anyOf": [
1710
+ {
1711
+ "type": "string",
1712
+ "enum": [
1713
+ "merge",
1714
+ "milestone",
1715
+ "project"
1716
+ ]
1717
+ },
1718
+ {
1719
+ "type": "null"
1720
+ }
1721
+ ]
1722
+ },
1723
+ "releaseWhen": {
1724
+ "anyOf": [
1725
+ {
1726
+ "type": "object",
1727
+ "properties": {
1728
+ "trigger": {
1729
+ "type": "string",
1730
+ "enum": [
1731
+ "merge",
1732
+ "milestone",
1733
+ "project"
1734
+ ]
1735
+ },
1736
+ "layer": {
1737
+ "type": "string",
1738
+ "enum": [
1739
+ "run",
1740
+ "project",
1741
+ "team",
1742
+ "workspace"
1743
+ ]
1744
+ }
1745
+ },
1746
+ "required": [
1747
+ "trigger",
1748
+ "layer"
1749
+ ],
1750
+ "additionalProperties": true
1751
+ },
1752
+ {
1753
+ "type": "null"
1754
+ }
1755
+ ]
1756
+ },
1757
+ "releaseScope": {
1758
+ "anyOf": [
1759
+ {
1760
+ "type": "object",
1761
+ "properties": {
1762
+ "kind": {
1763
+ "type": "string",
1764
+ "enum": [
1765
+ "milestone",
1766
+ "project"
1767
+ ]
1768
+ },
1769
+ "projectId": {
1770
+ "type": "string"
1771
+ },
1772
+ "projectName": {
1773
+ "type": "string"
1774
+ },
1775
+ "milestoneId": {
1776
+ "type": "string"
1777
+ },
1778
+ "milestoneName": {
1779
+ "type": "string"
1780
+ },
1781
+ "tasks": {
1782
+ "type": "array",
1783
+ "items": {
1784
+ "type": "object",
1785
+ "properties": {
1786
+ "id": {
1787
+ "type": "string"
1788
+ },
1789
+ "key": {
1790
+ "type": "string"
1791
+ },
1792
+ "title": {
1793
+ "type": "string"
1794
+ }
1795
+ },
1796
+ "required": [
1797
+ "id",
1798
+ "key",
1799
+ "title"
1800
+ ],
1801
+ "additionalProperties": true
1802
+ }
1803
+ }
1804
+ },
1805
+ "required": [
1806
+ "kind",
1807
+ "projectId",
1808
+ "tasks"
1809
+ ],
1810
+ "additionalProperties": true
1811
+ },
1812
+ {
1813
+ "type": "null"
1814
+ }
1815
+ ]
1663
1816
  }
1664
1817
  },
1665
1818
  "additionalProperties": true,
@@ -1678,7 +1831,9 @@
1678
1831
  "rolled_back",
1679
1832
  "deploy_failed",
1680
1833
  "rollback_failed",
1681
- "timed_out"
1834
+ "timed_out",
1835
+ "not_due",
1836
+ "no_version"
1682
1837
  ]
1683
1838
  },
1684
1839
  "reason": {
@@ -1723,6 +1878,77 @@
1723
1878
  "type": "null"
1724
1879
  }
1725
1880
  ]
1881
+ },
1882
+ "releaseWhen": {
1883
+ "anyOf": [
1884
+ {
1885
+ "type": "object",
1886
+ "properties": {
1887
+ "trigger": {
1888
+ "type": "string",
1889
+ "enum": [
1890
+ "merge",
1891
+ "milestone",
1892
+ "project"
1893
+ ]
1894
+ },
1895
+ "layer": {
1896
+ "type": "string",
1897
+ "enum": [
1898
+ "run",
1899
+ "project",
1900
+ "team",
1901
+ "workspace"
1902
+ ]
1903
+ }
1904
+ },
1905
+ "required": [
1906
+ "trigger",
1907
+ "layer"
1908
+ ],
1909
+ "additionalProperties": true
1910
+ },
1911
+ {
1912
+ "type": "null"
1913
+ }
1914
+ ]
1915
+ },
1916
+ "shipped": {
1917
+ "anyOf": [
1918
+ {
1919
+ "type": "object",
1920
+ "properties": {
1921
+ "kind": {
1922
+ "type": "string",
1923
+ "enum": [
1924
+ "milestone",
1925
+ "project"
1926
+ ]
1927
+ },
1928
+ "projectId": {
1929
+ "type": "string"
1930
+ },
1931
+ "milestoneId": {
1932
+ "type": "string"
1933
+ },
1934
+ "taskIds": {
1935
+ "type": "array",
1936
+ "items": {
1937
+ "type": "string"
1938
+ }
1939
+ }
1940
+ },
1941
+ "required": [
1942
+ "kind",
1943
+ "projectId",
1944
+ "taskIds"
1945
+ ],
1946
+ "additionalProperties": true
1947
+ },
1948
+ {
1949
+ "type": "null"
1950
+ }
1951
+ ]
1726
1952
  }
1727
1953
  },
1728
1954
  "required": [
@@ -1737,7 +1963,17 @@
1737
1963
  "deployer": "deployer"
1738
1964
  },
1739
1965
  "checkout": "read",
1740
- "when": [],
1966
+ "when": [
1967
+ {
1968
+ "event": "release.due",
1969
+ "input": {
1970
+ "tag": "tag",
1971
+ "releaseScope": "releaseScope",
1972
+ "releaseWhen": "releaseWhen",
1973
+ "repoBindingId": "repoBindingId"
1974
+ }
1975
+ }
1976
+ ],
1741
1977
  "offers": [],
1742
1978
  "capabilities": [
1743
1979
  "agent_work",
@@ -2841,6 +3077,55 @@
2841
3077
  "type": "null"
2842
3078
  }
2843
3079
  ]
3080
+ },
3081
+ "releaseTrigger": {
3082
+ "anyOf": [
3083
+ {
3084
+ "type": "string",
3085
+ "enum": [
3086
+ "merge",
3087
+ "milestone",
3088
+ "project"
3089
+ ]
3090
+ },
3091
+ {
3092
+ "type": "null"
3093
+ }
3094
+ ]
3095
+ },
3096
+ "releaseWhen": {
3097
+ "anyOf": [
3098
+ {
3099
+ "type": "object",
3100
+ "properties": {
3101
+ "trigger": {
3102
+ "type": "string",
3103
+ "enum": [
3104
+ "merge",
3105
+ "milestone",
3106
+ "project"
3107
+ ]
3108
+ },
3109
+ "layer": {
3110
+ "type": "string",
3111
+ "enum": [
3112
+ "run",
3113
+ "project",
3114
+ "team",
3115
+ "workspace"
3116
+ ]
3117
+ }
3118
+ },
3119
+ "required": [
3120
+ "trigger",
3121
+ "layer"
3122
+ ],
3123
+ "additionalProperties": true
3124
+ },
3125
+ {
3126
+ "type": "null"
3127
+ }
3128
+ ]
2844
3129
  }
2845
3130
  },
2846
3131
  "required": [
@@ -2920,6 +3205,40 @@
2920
3205
  }
2921
3206
  ]
2922
3207
  },
3208
+ "releaseWhen": {
3209
+ "anyOf": [
3210
+ {
3211
+ "type": "object",
3212
+ "properties": {
3213
+ "trigger": {
3214
+ "type": "string",
3215
+ "enum": [
3216
+ "merge",
3217
+ "milestone",
3218
+ "project"
3219
+ ]
3220
+ },
3221
+ "layer": {
3222
+ "type": "string",
3223
+ "enum": [
3224
+ "run",
3225
+ "project",
3226
+ "team",
3227
+ "workspace"
3228
+ ]
3229
+ }
3230
+ },
3231
+ "required": [
3232
+ "trigger",
3233
+ "layer"
3234
+ ],
3235
+ "additionalProperties": true
3236
+ },
3237
+ {
3238
+ "type": "null"
3239
+ }
3240
+ ]
3241
+ },
2923
3242
  "handBack": {
2924
3243
  "anyOf": [
2925
3244
  {
@@ -3528,7 +3847,7 @@
3528
3847
  "carried": [
3529
3848
  {
3530
3849
  "name": "@kitman-sh/software-engineering",
3531
- "version": "0.10.101",
3850
+ "version": "0.10.103",
3532
3851
  "setup": "2a237548a69b0cd53ec3be7f687cfa8c2128335b3a655d34e185f2abce6a3c37",
3533
3852
  "loops": [
3534
3853
  "build",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitman-sh/software-engineering",
3
- "version": "0.10.101",
3
+ "version": "0.10.103",
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.101",
20
+ "@kitman-sh/sdk": "0.10.103",
21
21
  "effect": "^4.1.2"
22
22
  },
23
23
  "kitman": {
24
24
  "bundle": "dist/bundle.js",
25
- "digest": "40a4753e748e4670ae230cd78b48e61ba443b9726ff8f8415ffc181d005368f9",
25
+ "digest": "aeb153e088e49af667ba693190cad78333740fee16e7ecf5b61061b21af2f03e",
26
26
  "protocolVersion": 5,
27
27
  "declarations": "dist/declarations.json",
28
28
  "setup": {
package/src/plan.ts CHANGED
@@ -106,6 +106,8 @@ const menuDescriptions: Record<Choice, string> = {
106
106
 
107
107
  const onConflict = ['Rebuild on the integration branch', 'Skip'] as const
108
108
 
109
+ const onHeld = ['Merge again', ...onConflict] as const
110
+
109
111
  const onUnverified = ['Skip', 'Merge'] as const
110
112
 
111
113
  const onFailure = ['Retry with a steer', 'Skip it and its dependents', 'Stop here'] as const
@@ -260,8 +262,8 @@ const settled = (ticket: PlanTicket, result: Omit<TicketResult, 'key' | 'title'>
260
262
  /**
261
263
  * Builds a ticket from the integration head, then merges its ChangeRequest into the integration branch. When verify
262
264
  * never ran some of its tests, the user chooses to merge it or skip it. On a conflict the user chooses to rebuild from
263
- * the head as it is now, or to give the ticket up. `steer` is a person's words for a retry; `label` names its Steps
264
- * apart from the first try's.
265
+ * the head as it is now, or to give the ticket up; on a merge the forge only holds back, also to merge it again.
266
+ * `steer` is a person's words for a retry; `label` names its Steps apart from the first try's.
265
267
  */
266
268
  const buildTicket = (
267
269
  ticket: PlanTicket,
@@ -315,32 +317,68 @@ const buildTicket = (
315
317
  return settled(ticket, { status: 'skipped', ...delivered, reason: 'Verify never ran some of its tests' })
316
318
  }
317
319
 
318
- // Only what the Build verified merges; a commit pushed to its branch since is rebuilt or skipped like a conflict.
319
- const merged = yield* mergeChangeRequest(`merge:${name}${suffix}`, {
320
- changeRequestId: built.changeRequest.id,
321
- head: built.revision
322
- })
320
+ const rebuild = {
321
+ value: 'Rebuild on the integration branch',
322
+ description: 'Builds the ticket again from the branch as it is now.'
323
+ } as const
323
324
 
324
- if (merged.status === 'merged') return settled(ticket, { status: 'merged', ...delivered })
325
+ const skip = { value: 'Skip', description: 'Leaves it and the tickets it blocks undelivered.' } as const
326
+ let choice: (typeof onHeld)[number] = 'Merge again'
327
+ let refusal = `It conflicted with ${head.branch}`
325
328
 
326
- const choice = yield* ask(`conflict:${name}${suffix}`, {
327
- prompt: `The ChangeRequest for ${ticket.key} (${built.changeRequest.url}) ${merged.status === 'moved' ? 'changed after it was built' : `conflicts with ${head.branch}`}. Rebuild ${ticket.key} on the integration branch as it is now, or skip it and the tickets it blocks?`,
328
- options: [
329
- {
330
- value: 'Rebuild on the integration branch',
331
- description: 'Builds the ticket again from the branch as it is now.'
332
- },
333
- { value: 'Skip', description: 'Leaves it and the tickets it blocks undelivered.' }
334
- ] satisfies { readonly value: (typeof onConflict)[number]; readonly description: string }[],
335
- recommended: 'Rebuild on the integration branch',
336
- recommendationReason:
337
- 'A rebuild on the current branch usually resolves a conflict, and skipping also drops every ticket it blocks.',
338
- default: 'Skip',
339
- timeout: '1 hour'
340
- })
329
+ for (let again = 0; choice === 'Merge again'; again++) {
330
+ const label = again === 0 ? suffix : `${suffix}:again:${again}`
331
+
332
+ // Only what the Build verified merges; a commit pushed to its branch since is rebuilt or skipped like a
333
+ // conflict. The integration branch's own ChangeRequest is verified again, so one behind it is rebased onto it.
334
+ const merged = yield* mergeChangeRequest(`merge:${name}${label}`, {
335
+ changeRequestId: built.changeRequest.id,
336
+ head: built.revision,
337
+ rebase: true
338
+ })
339
+
340
+ if (merged.status === 'merged') return settled(ticket, { status: 'merged', ...delivered })
341
+ const request = `The ChangeRequest for ${ticket.key} (${built.changeRequest.url})`
342
+
343
+ if (merged.status === 'conflict' && merged.reason === 'not_ready') {
344
+ refusal = `The forge held it back from ${head.branch}`
345
+
346
+ choice = yield* ask(`conflict:${name}${label}`, {
347
+ prompt: `${request} cannot merge into ${head.branch} yet: the forge holds it back, as for approvals, unresolved discussions, a draft or a pipeline that must pass first. Merge it again once that is settled, rebuild ${ticket.key} on the integration branch as it is now, or skip it and the tickets it blocks?`,
348
+ options: [
349
+ {
350
+ value: 'Merge again',
351
+ description: 'Tries the merge again, for once whatever holds it back is settled.'
352
+ },
353
+ rebuild,
354
+ skip
355
+ ] satisfies { readonly value: (typeof onHeld)[number]; readonly description: string }[],
356
+ recommended: 'Merge again',
357
+ recommendationReason:
358
+ 'Nothing conflicts, so a rebuild meets the same hold, and skipping also drops every ticket it blocks.',
359
+ default: 'Skip',
360
+ timeout: '1 hour'
361
+ })
362
+ } else {
363
+ const behind = merged.status === 'conflict' && merged.reason === 'behind'
364
+ refusal = `${behind ? 'It stayed behind' : 'It conflicted with'} ${head.branch}`
365
+
366
+ choice = yield* ask(`conflict:${name}${label}`, {
367
+ prompt: `${request} ${merged.status === 'moved' ? 'changed after it was built' : `${behind ? 'is behind' : 'conflicts with'} ${head.branch}`}. Rebuild ${ticket.key} on the integration branch as it is now, or skip it and the tickets it blocks?`,
368
+ options: [rebuild, skip] satisfies {
369
+ readonly value: (typeof onConflict)[number]
370
+ readonly description: string
371
+ }[],
372
+ recommended: 'Rebuild on the integration branch',
373
+ recommendationReason:
374
+ 'A rebuild on the current branch usually resolves a conflict, and skipping also drops every ticket it blocks.',
375
+ default: 'Skip',
376
+ timeout: '1 hour'
377
+ })
378
+ }
379
+ }
341
380
 
342
- if (choice === 'Skip')
343
- return settled(ticket, { status: 'failed', ...delivered, reason: `It conflicted with ${head.branch}` })
381
+ if (choice === 'Skip') return settled(ticket, { status: 'failed', ...delivered, reason: refusal })
344
382
 
345
383
  head = yield* integrationBranch(`rebuild-from:${name}:${attempt + 1}`, {
346
384
  repoBindingId: head.repoBindingId
package/src/release.ts CHANGED
@@ -8,7 +8,12 @@ import {
8
8
  pipelineMoved,
9
9
  pipelineStatus,
10
10
  release,
11
+ ReleaseScope,
12
+ ReleaseTrigger,
13
+ ResolvedReleaseTrigger,
11
14
  rerunPipeline,
15
+ ShippedScope,
16
+ shippedScope,
12
17
  verify,
13
18
  waitFor
14
19
  } from '@kitman-sh/sdk/loop'
@@ -28,7 +33,15 @@ const Input = Schema.Struct({
28
33
  /** The Event type the deploy reports; `deploy` when left out. Its payload names the `tag` and a `status`. */
29
34
  deployEvent: Schema.optional(Schema.String),
30
35
  /** How long to wait for the deploy; 60 when left out. */
31
- deployTimeoutMinutes: Schema.optional(Schema.Int)
36
+ deployTimeoutMinutes: Schema.optional(Schema.Int),
37
+ /** The repository to release; the Run's Task's, else its Team's default, when left out. */
38
+ repoBindingId: Schema.optional(Schema.String),
39
+ /** This Run's own release trigger, over its Project's, Team's and Workspace's; `merge` releases now, as for a hotfix. */
40
+ releaseTrigger: Schema.optional(ReleaseTrigger),
41
+ /** The release trigger the Run uses and the layer it came from; Kitman sets it when the Run starts. */
42
+ releaseWhen: Schema.optional(ResolvedReleaseTrigger),
43
+ /** The Milestone or Project whose completion started this Release, and the Tasks it ships. */
44
+ releaseScope: Schema.optional(ReleaseScope)
32
45
  })
33
46
 
34
47
  const Drafted = Schema.Struct({
@@ -70,21 +83,57 @@ const Output = Schema.Struct({
70
83
  'deploy_failed',
71
84
  /** The deploy failed after production changed, and so did the rollback: production may be broken. */
72
85
  'rollback_failed',
73
- 'timed_out'
86
+ 'timed_out',
87
+ /** Its trigger is a Milestone or Project being done, and this Run was not started by one nor told to release now. */
88
+ 'not_due',
89
+ /** A Milestone or Project started it without the version to cut, which a Release never picks for itself. */
90
+ 'no_version'
74
91
  ]),
75
92
  /** Why it stopped, or what happened, in a line. */
76
93
  reason: Schema.String,
77
94
  tag: Schema.optional(Schema.String),
78
95
  notesArtifactId: Schema.optional(Schema.String),
79
96
  revision: Schema.optional(Schema.String),
80
- url: Schema.optional(Schema.String)
97
+ url: Schema.optional(Schema.String),
98
+ /** The release trigger the Run used and the layer it came from. */
99
+ releaseWhen: Schema.optional(ResolvedReleaseTrigger),
100
+ /** The Milestone or Project that triggered it, and the Tasks it shipped. */
101
+ shipped: Schema.optional(ShippedScope)
81
102
  })
82
103
 
83
104
  type Output = typeof Output.Type
84
105
 
85
- const draftPrompt = (tag: string | undefined, changeRequestId: string | undefined) =>
106
+ const triggerWords = {
107
+ milestone: 'a Milestone is done',
108
+ project: 'its Project is done'
109
+ } as const
110
+
111
+ const layerWords = {
112
+ run: 'this Run',
113
+ project: 'its Project',
114
+ team: 'its Team',
115
+ workspace: 'the Workspace'
116
+ } as const
117
+
118
+ const scopeLine = (scope: ReleaseScope) =>
119
+ scope.kind === 'milestone'
120
+ ? `${scope.milestoneName === undefined ? 'a Milestone' : `Milestone ${scope.milestoneName}`} of ${scope.projectName ?? 'its Project'}`
121
+ : scope.projectName === undefined
122
+ ? 'its Project'
123
+ : `Project ${scope.projectName}`
124
+
125
+ const scopePrompt = (scope: ReleaseScope | undefined) =>
126
+ scope === undefined
127
+ ? []
128
+ : [
129
+ `This release ships ${scopeLine(scope)}, now that its Tasks are done:`,
130
+ scope.tasks.map(task => `- ${task.key} ${task.title}`).join('\n')
131
+ ]
132
+
133
+ const draftPrompt = (tag: string | undefined, changeRequestId: string | undefined, scope?: ReleaseScope) =>
86
134
  [
87
135
  'Draft the release notes for the ChangeRequests merged since the last release tag on the base branch, including those with no linked Task.',
136
+ ...scopePrompt(scope),
88
137
  ...(changeRequestId === undefined ? [] : [`The release ChangeRequest ${changeRequestId} is part of it.`]),
89
138
  'Group them by what a user of the software notices, and name each ChangeRequest you cover.',
90
139
  tag === undefined
@@ -202,15 +251,31 @@ const recovery = (previous: string | undefined) =>
202
251
  * target so two Releases never deploy over each other, and waits for the deploy. A failed or late deploy asks whether
203
252
  * to retry (it runs the tag's failed pipeline again and waits), roll back to the previous tag (it runs that
204
253
  * tag's pipeline again in full and waits for its deploy), or leave it, which it does by default.
254
+ *
255
+ * Under a Milestone or Project release trigger, it releases only when that Milestone's or Project's completion starts
256
+ * it, with the tag Kitman cut and the Tasks it ships, which it records; without that tag it stops rather than choose a
257
+ * version. A Run whose `releaseTrigger` is `merge` releases anyway.
205
258
  */
206
259
  export default defineLoop({
207
260
  id: 'release',
208
- version: '2.0.0',
261
+ version: '2.1.0',
209
262
  title: 'Release',
210
263
  input: Input,
211
264
  output: Output,
212
265
  agents: { releaser: 'releaser', deployer: 'deployer' },
213
266
  checkout: 'read',
267
+ // Kitman records release.due per repository when a Milestone or Project closes under that trigger.
268
+ when: [
269
+ {
270
+ event: 'release.due',
271
+ input: {
272
+ tag: 'tag',
273
+ releaseScope: 'releaseScope',
274
+ releaseWhen: 'releaseWhen',
275
+ repoBindingId: 'repoBindingId'
276
+ }
277
+ }
278
+ ],
214
279
  capabilities: [
215
280
  'agent_work',
216
281
  'ask',
@@ -222,6 +287,23 @@ export default defineLoop({
222
287
  ],
223
288
  run: input =>
224
289
  Effect.gen(function* () {
290
+ const when = input.releaseWhen
291
+
292
+ // A Milestone's or Project's completion starts the Release it waits for; a merge does not, unless this Run says so.
293
+ if (when !== undefined && when.trigger !== 'merge' && input.releaseScope === undefined)
294
+ return {
295
+ status: 'not_due',
296
+ reason: `Release runs when ${triggerWords[when.trigger]}, as ${layerWords[when.layer]} says; this Run did not override that`
297
+ } satisfies Output
298
+
299
+ if (input.releaseScope !== undefined && input.tag === undefined)
300
+ return {
301
+ status: 'no_version',
302
+ reason:
303
+ 'Kitman cut no version for this Milestone or Project: its Project is not named by a full semver version. Release it with a tag.',
304
+ shipped: shippedScope(input.releaseScope)
305
+ } satisfies Output
306
+
225
307
  const changeRequestId = input.changeRequestId
226
308
  // The commit the gate proved, and the one tagged or merged: never the branch head read again later.
227
309
  let gated: string
@@ -286,7 +368,7 @@ export default defineLoop({
286
368
 
287
369
  let drafted = yield* agentWork('draft-notes', {
288
370
  agent: 'releaser',
289
- prompt: draftPrompt(input.tag, changeRequestId),
371
+ prompt: draftPrompt(input.tag, changeRequestId, input.releaseScope),
290
372
  output: Drafted
291
373
  })
292
374
 
@@ -325,7 +407,11 @@ export default defineLoop({
325
407
  kind: 'release_notes',
326
408
  title: drafted.title,
327
409
  text: drafted.notes,
328
- data: { tag, changeRequests: drafted.changeRequests }
410
+ data: {
411
+ tag,
412
+ changeRequests: drafted.changeRequests,
413
+ ...(input.releaseScope === undefined ? undefined : { shipped: shippedScope(input.releaseScope) })
414
+ }
329
415
  })
330
416
 
331
417
  return { status: 'rejected', reason: why, tag, notesArtifactId: kept.artifactId } satisfies Output
@@ -353,7 +439,11 @@ export default defineLoop({
353
439
  kind: 'release_notes',
354
440
  title: drafted.title,
355
441
  text: drafted.notes,
356
- data: { tag, changeRequests: drafted.changeRequests }
442
+ data: {
443
+ tag,
444
+ changeRequests: drafted.changeRequests,
445
+ ...(input.releaseScope === undefined ? undefined : { shipped: shippedScope(input.releaseScope) })
446
+ }
357
447
  })
358
448
 
359
449
  let revision = gated
@@ -490,5 +580,11 @@ export default defineLoop({
490
580
  })
491
581
 
492
582
  return { status: 'deployed', reason: `${tag} deployed`, ...settled } satisfies Output
493
- })
583
+ }).pipe(
584
+ Effect.map((output): Output => ({
585
+ ...output,
586
+ ...(input.releaseWhen === undefined ? undefined : { releaseWhen: input.releaseWhen }),
587
+ ...(input.releaseScope === undefined ? undefined : { shipped: shippedScope(input.releaseScope) })
588
+ }))
589
+ )
494
590
  })
@@ -1,3 +1,4 @@
1
+ import { ResolvedReleaseTrigger } from '@kitman-sh/sdk/loop'
1
2
  import * as Schema from 'effect/Schema'
2
3
 
3
4
  /** Shepherd's Output, outside shepherd.ts so Build can import it without the review → build → shepherd cycle. */
@@ -14,6 +15,8 @@ export const ShepherdOutput = Schema.Struct({
14
15
  release: Schema.optional(
15
16
  Schema.Struct({ runStatus: Schema.String, reason: Schema.String, tag: Schema.optional(Schema.String) })
16
17
  ),
18
+ /** The release trigger the Run used and the layer it came from. */
19
+ releaseWhen: Schema.optional(ResolvedReleaseTrigger),
17
20
  /** The Build its offer starts when it hands the ChangeRequest back: that ChangeRequest, and what is still open. */
18
21
  handBack: Schema.optional(
19
22
  Schema.Struct({
package/src/shepherd.ts CHANGED
@@ -14,6 +14,8 @@ import {
14
14
  note,
15
15
  pipelineMoved,
16
16
  pipelineStatus,
17
+ ReleaseTrigger,
18
+ ResolvedReleaseTrigger,
17
19
  reportPipeline,
18
20
  rerunPipeline,
19
21
  reviewThreads,
@@ -68,9 +70,15 @@ const Input = Schema.Struct({
68
70
  /** The ChangeRequest's branch and target, as Kitman puts the Run on it. */
69
71
  continuing: Schema.optional(Continuing),
70
72
  /** Times it looks at the ChangeRequest before asking whether to go on; 20 when left out. */
71
- maxCycles: Schema.optional(Schema.Int)
73
+ maxCycles: Schema.optional(Schema.Int),
74
+ /** This Run's own release trigger, over its Project's, Team's and Workspace's; `merge` releases this merge, as for a hotfix. */
75
+ releaseTrigger: Schema.optional(ReleaseTrigger),
76
+ /** The release trigger the Run uses and the layer it came from; Kitman sets it when the Run starts. */
77
+ releaseWhen: Schema.optional(ResolvedReleaseTrigger)
72
78
  })
73
79
 
80
+ const layerWords = { run: 'this Run', project: 'its Project', team: 'its Team', workspace: 'the Workspace' } as const
81
+
74
82
  export { ShepherdOutput }
75
83
 
76
84
  const Output = ShepherdOutput
@@ -205,7 +213,8 @@ const threadKey = (thread: ReviewThreads['threads'][number]) => `${thread.id}:${
205
213
  * order. A head nobody approved gets a review of what changed since the last approved head, and the head a catch-up
206
214
  * pushed gets its pipeline started and its review as soon as the forge shows it, not once its pipeline passes. It runs one ci-fix and two
207
215
  * head-fix rounds, each judged by the pipeline at the head the last fix pushed, then hands the ChangeRequest back to
208
- * Build, and stops as needs you, with why, instead of spinning.
216
+ * Build, and stops as needs you, with why, instead of spinning. After merging it starts Release only when its release
217
+ * trigger is `merge`; under a Milestone or Project trigger that completion starts Release instead.
209
218
  */
210
219
  export default defineLoop({
211
220
  id: 'shepherd',
@@ -310,9 +319,12 @@ export default defineLoop({
310
319
  reason,
311
320
  fixRounds: fixRounds(),
312
321
  replies,
322
+ ...(input.releaseWhen === undefined ? undefined : { releaseWhen: input.releaseWhen }),
313
323
  ...(status === 'needs_you' || status === 'handed_back' ? { unsettled: [reason] } : undefined)
314
324
  })
315
325
 
326
+ const releaseWhen = input.releaseWhen
327
+
316
328
  const handBack = (reason: string, open: string): Output => ({
317
329
  ...done('handed_back', reason),
318
330
  handBack: {
@@ -1244,6 +1256,13 @@ export default defineLoop({
1244
1256
  yield* passTurn()
1245
1257
  yield* writeBack('write-back', { milestone: 'merged' })
1246
1258
 
1259
+ // A Milestone's or Project's completion starts its Release; this merge does not, unless the Run says so.
1260
+ if (releaseWhen !== undefined && releaseWhen.trigger !== 'merge')
1261
+ return done(
1262
+ 'merged',
1263
+ `Merged at ${merged.revision}; Release runs when its ${releaseWhen.trigger === 'milestone' ? 'Milestone' : 'Project'} is done, as ${layerWords[releaseWhen.layer]} says`
1264
+ )
1265
+
1247
1266
  const ship = yield* ask('ship', {
1248
1267
  prompt: `Merged at ${merged.revision}. Release it now?`,
1249
1268
  options: [
@@ -1259,7 +1278,11 @@ export default defineLoop({
1259
1278
 
1260
1279
  if (ship === 'Not now') return done('merged', `Merged at ${merged.revision}`)
1261
1280
 
1262
- const released = yield* call('release', release, { revision: merged.revision })
1281
+ const released = yield* call('release', release, {
1282
+ revision: merged.revision,
1283
+ // Release resolves the same layers for the same Task; only this Run's own choice needs passing on.
1284
+ ...(releaseWhen?.layer === 'run' ? { releaseTrigger: releaseWhen.trigger } : undefined)
1285
+ })
1263
1286
 
1264
1287
  // A failed gate changed nothing in production, and the next merge's Release gates this revision with its own.
1265
1288
  const handedOn =
@@ -1288,7 +1311,12 @@ export default defineLoop({
1288
1311
  }
1289
1312
 
1290
1313
  // It merged either way; a Release that did not deploy, other than one a person rejected, needs a person.
1291
- if (released.status !== 'deployed' && released.status !== 'rejected' && released.status !== 'gate_failed')
1314
+ if (
1315
+ released.status !== 'deployed' &&
1316
+ released.status !== 'rejected' &&
1317
+ released.status !== 'gate_failed' &&
1318
+ released.status !== 'not_due'
1319
+ )
1292
1320
  yield* ask('release-failed', {
1293
1321
  prompt: `Merged at ${merged.revision}, but its Release ended ${released.status}: ${released.reason}`,
1294
1322
  options: [{ value: 'Taken over', description: 'A person looks at the release and production from here.' }],