@kitman-sh/software-engineering 0.10.102 → 0.10.104

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,
@@ -21181,7 +21215,11 @@ var Input2 = Struct({
21181
21215
  changeRequestId: optional2(String5),
21182
21216
  deployTarget: optional2(String5),
21183
21217
  deployEvent: optional2(String5),
21184
- deployTimeoutMinutes: optional2(Int)
21218
+ deployTimeoutMinutes: optional2(Int),
21219
+ repoBindingId: optional2(String5),
21220
+ releaseTrigger: optional2(ReleaseTrigger),
21221
+ releaseWhen: optional2(ResolvedReleaseTrigger),
21222
+ releaseScope: optional2(ReleaseScope)
21185
21223
  });
21186
21224
  var Drafted = Struct({
21187
21225
  tag: String5,
@@ -21212,16 +21250,37 @@ var Output2 = Struct({
21212
21250
  "rolled_back",
21213
21251
  "deploy_failed",
21214
21252
  "rollback_failed",
21215
- "timed_out"
21253
+ "timed_out",
21254
+ "not_due",
21255
+ "no_version"
21216
21256
  ]),
21217
21257
  reason: String5,
21218
21258
  tag: optional2(String5),
21219
21259
  notesArtifactId: optional2(String5),
21220
21260
  revision: optional2(String5),
21221
- url: optional2(String5)
21222
- });
21223
- 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) => [
21224
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),
21225
21284
  ...changeRequestId === undefined ? [] : [`The release ChangeRequest ${changeRequestId} is part of it.`],
21226
21285
  "Group them by what a user of the software notices, and name each ChangeRequest you cover.",
21227
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}.`,
@@ -21297,12 +21356,23 @@ var readyToMerge = (changeRequestId, round = 1) => gen2(function* () {
21297
21356
  var recovery = (previous) => previous === undefined ? ["Retry the deploy", "Leave it"] : ["Retry the deploy", `Roll back to ${previous}`, "Leave it"];
21298
21357
  var release_default = defineLoop({
21299
21358
  id: "release",
21300
- version: "2.0.0",
21359
+ version: "2.1.0",
21301
21360
  title: "Release",
21302
21361
  input: Input2,
21303
21362
  output: Output2,
21304
21363
  agents: { releaser: "releaser", deployer: "deployer" },
21305
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
+ ],
21306
21376
  capabilities: [
21307
21377
  "agent_work",
21308
21378
  "ask",
@@ -21313,6 +21383,18 @@ var release_default = defineLoop({
21313
21383
  "merge_change_request"
21314
21384
  ],
21315
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
+ };
21316
21398
  const changeRequestId = input.changeRequestId;
21317
21399
  let gated;
21318
21400
  if (changeRequestId === undefined) {
@@ -21361,7 +21443,7 @@ var release_default = defineLoop({
21361
21443
  }
21362
21444
  let drafted = yield* agentWork("draft-notes", {
21363
21445
  agent: "releaser",
21364
- prompt: draftPrompt(input.tag, changeRequestId),
21446
+ prompt: draftPrompt(input.tag, changeRequestId, input.releaseScope),
21365
21447
  output: Drafted
21366
21448
  });
21367
21449
  const tag = input.tag ?? drafted.tag;
@@ -21395,7 +21477,11 @@ ${drafted.notes}`,
21395
21477
  kind: "release_notes",
21396
21478
  title: drafted.title,
21397
21479
  text: drafted.notes,
21398
- data: { tag, changeRequests: drafted.changeRequests }
21480
+ data: {
21481
+ tag,
21482
+ changeRequests: drafted.changeRequests,
21483
+ ...input.releaseScope === undefined ? undefined : { shipped: shippedScope(input.releaseScope) }
21484
+ }
21399
21485
  });
21400
21486
  return { status: "rejected", reason: why, tag, notesArtifactId: kept.artifactId };
21401
21487
  }
@@ -21419,7 +21505,11 @@ ${drafted.notes}`,
21419
21505
  kind: "release_notes",
21420
21506
  title: drafted.title,
21421
21507
  text: drafted.notes,
21422
- data: { tag, changeRequests: drafted.changeRequests }
21508
+ data: {
21509
+ tag,
21510
+ changeRequests: drafted.changeRequests,
21511
+ ...input.releaseScope === undefined ? undefined : { shipped: shippedScope(input.releaseScope) }
21512
+ }
21423
21513
  });
21424
21514
  let revision = gated;
21425
21515
  if (changeRequestId !== undefined) {
@@ -21520,7 +21610,11 @@ ${drafted.notes}`,
21520
21610
  data: { tag, status, revision: released.revision, url: released.url }
21521
21611
  });
21522
21612
  return { status: "deployed", reason: `${tag} deployed`, ...settled };
21523
- })
21613
+ }).pipe(map8((output) => ({
21614
+ ...output,
21615
+ ...input.releaseWhen === undefined ? undefined : { releaseWhen: input.releaseWhen },
21616
+ ...input.releaseScope === undefined ? undefined : { shipped: shippedScope(input.releaseScope) }
21617
+ })))
21524
21618
  });
21525
21619
 
21526
21620
  // src/shepherd-output.ts
@@ -21531,6 +21625,7 @@ var ShepherdOutput = Struct({
21531
21625
  replies: Int,
21532
21626
  unsettled: optional2(ArraySchema(String5)),
21533
21627
  release: optional2(Struct({ runStatus: String5, reason: String5, tag: optional2(String5) })),
21628
+ releaseWhen: optional2(ResolvedReleaseTrigger),
21534
21629
  handBack: optional2(Struct({
21535
21630
  changeRequestId: String5,
21536
21631
  words: String5,
@@ -21553,8 +21648,11 @@ var Input3 = Struct({
21553
21648
  notRun: optional2(ArraySchema(String5)),
21554
21649
  branch: optional2(String5),
21555
21650
  continuing: optional2(Continuing),
21556
- maxCycles: optional2(Int)
21651
+ maxCycles: optional2(Int),
21652
+ releaseTrigger: optional2(ReleaseTrigger),
21653
+ releaseWhen: optional2(ResolvedReleaseTrigger)
21557
21654
  });
21655
+ var layerWords2 = { run: "this Run", project: "its Project", team: "its Team", workspace: "the Workspace" };
21558
21656
  var Output3 = ShepherdOutput;
21559
21657
  var CiFix = Struct({
21560
21658
  verdict: Literals(["fixed", "pre_existing", "flaky"]),
@@ -21684,8 +21782,10 @@ var shepherd_default = defineLoop({
21684
21782
  reason,
21685
21783
  fixRounds: fixRounds(),
21686
21784
  replies,
21785
+ ...input.releaseWhen === undefined ? undefined : { releaseWhen: input.releaseWhen },
21687
21786
  ...status === "needs_you" || status === "handed_back" ? { unsettled: [reason] } : undefined
21688
21787
  });
21788
+ const releaseWhen = input.releaseWhen;
21689
21789
  const handBack = (reason, open) => ({
21690
21790
  ...done("handed_back", reason),
21691
21791
  handBack: {
@@ -22017,7 +22117,8 @@ ${open}`,
22017
22117
  else
22018
22118
  return found;
22019
22119
  }
22020
- const blocked = pipeline.conflicts === true || pipeline.needsRebase === true;
22120
+ const pipelineFailed = pipeline.status === "failed" || pipeline.status === "canceled";
22121
+ const blocked = pipeline.conflicts === true || pipeline.needsRebase === true && pipelineFailed;
22021
22122
  const caughtUpHead = pipeline.head === pipelineFirst;
22022
22123
  const onRunnerDue = pipeline.status === "none" && pipeline.runnerChecks !== undefined;
22023
22124
  if (onRunnerDue && (!blocked || caughtUpHead)) {
@@ -22180,7 +22281,7 @@ ${open}`,
22180
22281
  });
22181
22282
  if (mergeable.type === commented.event)
22182
22283
  continue;
22183
- if (mergeable.payload.mergeable === false || behind) {
22284
+ if (mergeable.payload.mergeable === false && mergeable.payload.mergeState !== "need_rebase" || behind) {
22184
22285
  behind = false;
22185
22286
  const stopped = yield* catchUp(cycle, pipeline.target?.head);
22186
22287
  if (stopped !== undefined)
@@ -22274,6 +22375,8 @@ Merge now?`,
22274
22375
  continue;
22275
22376
  yield* passTurn();
22276
22377
  yield* writeBack("write-back", { milestone: "merged" });
22378
+ if (releaseWhen !== undefined && releaseWhen.trigger !== "merge")
22379
+ return done("merged", `Merged at ${merged.revision}; Release runs when its ${releaseWhen.trigger === "milestone" ? "Milestone" : "Project"} is done, as ${layerWords2[releaseWhen.layer]} says`);
22277
22380
  const ship = yield* ask("ship", {
22278
22381
  prompt: `Merged at ${merged.revision}. Release it now?`,
22279
22382
  options: [
@@ -22288,7 +22391,10 @@ Merge now?`,
22288
22391
  });
22289
22392
  if (ship === "Not now")
22290
22393
  return done("merged", `Merged at ${merged.revision}`);
22291
- const released = yield* call("release", release_default, { revision: merged.revision });
22394
+ const released = yield* call("release", release_default, {
22395
+ revision: merged.revision,
22396
+ ...releaseWhen?.layer === "run" ? { releaseTrigger: releaseWhen.trigger } : undefined
22397
+ });
22292
22398
  const handedOn = released.status === "gate_failed" && (yield* ask("release-gate-failed", {
22293
22399
  prompt: `Merged at ${merged.revision}, but its Release gate failed: ${released.reason}`,
22294
22400
  options: [
@@ -22308,7 +22414,7 @@ Merge now?`,
22308
22414
  ...done("merged", `Merged at ${merged.revision}; its Release gate failed, so the next Release ships it`),
22309
22415
  release: { runStatus: released.status, reason: released.reason }
22310
22416
  };
22311
- if (released.status !== "deployed" && released.status !== "rejected" && released.status !== "gate_failed")
22417
+ if (released.status !== "deployed" && released.status !== "rejected" && released.status !== "gate_failed" && released.status !== "not_due")
22312
22418
  yield* ask("release-failed", {
22313
22419
  prompt: `Merged at ${merged.revision}, but its Release ended ${released.status}: ${released.reason}`,
22314
22420
  options: [{ value: "Taken over", description: "A person looks at the release and production from here." }],
@@ -30451,4 +30557,4 @@ var runKit = (config, identity, packages) => {
30451
30557
  runMain2(program.pipe(flatMap3((code) => sync2(() => process.exit(code)))));
30452
30558
  };
30453
30559
  // .kitman-build-entry.ts
30454
- runKit(kitman_config_default, { name: "@kitman-sh/software-engineering", version: "0.10.102" }, []);
30560
+ runKit(kitman_config_default, { name: "@kitman-sh/software-engineering", version: "0.10.104" }, []);
@@ -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.102",
3850
+ "version": "0.10.104",
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.102",
3
+ "version": "0.10.104",
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.102",
20
+ "@kitman-sh/sdk": "0.10.104",
21
21
  "effect": "^4.1.2"
22
22
  },
23
23
  "kitman": {
24
24
  "bundle": "dist/bundle.js",
25
- "digest": "790e075dcc25cd2cd6a0d0228fc1ac568b5920efcddb5622dcefe2cccc7102fe",
25
+ "digest": "571aa8c507bfb0903017f9153f3a9fff34351be2cee095f3cb9734bb6b10ea03",
26
26
  "protocolVersion": 5,
27
27
  "declarations": "dist/declarations.json",
28
28
  "setup": {
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
@@ -199,13 +207,15 @@ const threadKey = (thread: ReviewThreads['threads'][number]) => `${thread.id}:${
199
207
  * Takes an open ChangeRequest to merge: it waits on its Events with no model time between them, fixes a pipeline the
200
208
  * branch broke (after ruling out a flake and a target branch that fails the same check, which it waits out), answers
201
209
  * each new review thread on the thread, merges the target branch in when it is behind, and merges once approved, green
202
- * and mergeable when told to or when a person says so. A branch the forge says conflicts or is behind merges its target
203
- * in before any pipeline is run or fixed, and one whose merge Shepherd cannot settle goes back to Build. It merges the
210
+ * and mergeable when told to or when a person says so. A branch the forge says conflicts, or is behind with a failing
211
+ * pipeline, merges its target in before any pipeline is run or fixed; one that is only behind catches up when its merge
212
+ * finds it behind, on its turn. One whose merge Shepherd cannot settle goes back to Build. It merges the
204
213
  * target in and merges only while it holds the target's turn, so ChangeRequests for one target land one at a time, in
205
214
  * order. A head nobody approved gets a review of what changed since the last approved head, and the head a catch-up
206
215
  * 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
216
  * 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.
217
+ * Build, and stops as needs you, with why, instead of spinning. After merging it starts Release only when its release
218
+ * trigger is `merge`; under a Milestone or Project trigger that completion starts Release instead.
209
219
  */
210
220
  export default defineLoop({
211
221
  id: 'shepherd',
@@ -310,9 +320,12 @@ export default defineLoop({
310
320
  reason,
311
321
  fixRounds: fixRounds(),
312
322
  replies,
323
+ ...(input.releaseWhen === undefined ? undefined : { releaseWhen: input.releaseWhen }),
313
324
  ...(status === 'needs_you' || status === 'handed_back' ? { unsettled: [reason] } : undefined)
314
325
  })
315
326
 
327
+ const releaseWhen = input.releaseWhen
328
+
316
329
  const handBack = (reason: string, open: string): Output => ({
317
330
  ...done('handed_back', reason),
318
331
  handBack: {
@@ -840,7 +853,11 @@ export default defineLoop({
840
853
  else return found
841
854
  }
842
855
 
843
- const blocked = pipeline.conflicts === true || pipeline.needsRebase === true
856
+ // Behind alone waits for the merge, which catches up while holding the turn: catching up any sooner is undone
857
+ // by every merge that lands before this one's turn. A failing pipeline catches up first, so a ci-fix never
858
+ // chases what the target already fixed.
859
+ const pipelineFailed = pipeline.status === 'failed' || pipeline.status === 'canceled'
860
+ const blocked = pipeline.conflicts === true || (pipeline.needsRebase === true && pipelineFailed)
844
861
  const caughtUpHead = pipeline.head === pipelineFirst
845
862
  // The forge runs no pipeline for this repository: its pipeline runs on a Runner and is reported to Kitman.
846
863
  const onRunnerDue = pipeline.status === 'none' && pipeline.runnerChecks !== undefined
@@ -1089,7 +1106,8 @@ export default defineLoop({
1089
1106
 
1090
1107
  if (mergeable.type === commented.event) continue
1091
1108
 
1092
- if (mergeable.payload.mergeable === false || behind) {
1109
+ // GitLab says `need_rebase` for a branch behind its target; the merge finds that and catches up on its turn.
1110
+ if ((mergeable.payload.mergeable === false && mergeable.payload.mergeState !== 'need_rebase') || behind) {
1093
1111
  behind = false
1094
1112
 
1095
1113
  const stopped = yield* catchUp(cycle, pipeline.target?.head)
@@ -1244,6 +1262,13 @@ export default defineLoop({
1244
1262
  yield* passTurn()
1245
1263
  yield* writeBack('write-back', { milestone: 'merged' })
1246
1264
 
1265
+ // A Milestone's or Project's completion starts its Release; this merge does not, unless the Run says so.
1266
+ if (releaseWhen !== undefined && releaseWhen.trigger !== 'merge')
1267
+ return done(
1268
+ 'merged',
1269
+ `Merged at ${merged.revision}; Release runs when its ${releaseWhen.trigger === 'milestone' ? 'Milestone' : 'Project'} is done, as ${layerWords[releaseWhen.layer]} says`
1270
+ )
1271
+
1247
1272
  const ship = yield* ask('ship', {
1248
1273
  prompt: `Merged at ${merged.revision}. Release it now?`,
1249
1274
  options: [
@@ -1259,7 +1284,11 @@ export default defineLoop({
1259
1284
 
1260
1285
  if (ship === 'Not now') return done('merged', `Merged at ${merged.revision}`)
1261
1286
 
1262
- const released = yield* call('release', release, { revision: merged.revision })
1287
+ const released = yield* call('release', release, {
1288
+ revision: merged.revision,
1289
+ // Release resolves the same layers for the same Task; only this Run's own choice needs passing on.
1290
+ ...(releaseWhen?.layer === 'run' ? { releaseTrigger: releaseWhen.trigger } : undefined)
1291
+ })
1263
1292
 
1264
1293
  // A failed gate changed nothing in production, and the next merge's Release gates this revision with its own.
1265
1294
  const handedOn =
@@ -1288,7 +1317,12 @@ export default defineLoop({
1288
1317
  }
1289
1318
 
1290
1319
  // 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')
1320
+ if (
1321
+ released.status !== 'deployed' &&
1322
+ released.status !== 'rejected' &&
1323
+ released.status !== 'gate_failed' &&
1324
+ released.status !== 'not_due'
1325
+ )
1292
1326
  yield* ask('release-failed', {
1293
1327
  prompt: `Merged at ${merged.revision}, but its Release ended ${released.status}: ${released.reason}`,
1294
1328
  options: [{ value: 'Taken over', description: 'A person looks at the release and production from here.' }],