@kitman-sh/software-engineering 0.11.0-rc.6 → 0.11.0

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/kitman.config.ts CHANGED
@@ -10,6 +10,7 @@ import {
10
10
  release,
11
11
  research,
12
12
  hindsight,
13
+ landEpic,
13
14
  review,
14
15
  shepherd,
15
16
  sweep,
@@ -46,6 +47,7 @@ export default defineKit({
46
47
  release,
47
48
  research,
48
49
  hindsight,
50
+ landEpic,
49
51
  review,
50
52
  shepherd,
51
53
  sweep,
@@ -78,11 +80,6 @@ export default defineKit({
78
80
  skills: ['git-workflow-and-versioning', 'shipping-and-launch'],
79
81
  instructions: { file: 'agents/releaser.md' }
80
82
  },
81
- deployer: {
82
- effort: 'low',
83
- fallbacks,
84
- instructions: { file: 'agents/deployer.md' }
85
- },
86
83
  investigator: {
87
84
  effort: 'high',
88
85
  fallbacks,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitman-sh/software-engineering",
3
- "version": "0.11.0-rc.6",
3
+ "version": "0.11.0",
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.11.0-rc.6",
20
+ "@kitman-sh/sdk": "0.11.0",
21
21
  "effect": "^4.1.2"
22
22
  },
23
23
  "kitman": {
24
24
  "bundle": "dist/bundle.js",
25
- "digest": "83ce0a27e6119d8a59eb395c03738a860696e54e0105486592aa6b7abb57de86",
25
+ "digest": "edfa485ed3955a1883d1d79d79610ed02ffb4c608ff5d3347aa2a9ea17646230",
26
26
  "protocolVersion": 5,
27
27
  "declarations": "dist/declarations.json",
28
28
  "setup": {
package/src/build.ts CHANGED
@@ -8,6 +8,8 @@ import {
8
8
  CheckName,
9
9
  Continuing,
10
10
  continuingBrief,
11
+ deliveryBase,
12
+ ResolvedDeliveryTarget,
11
13
  syncBase,
12
14
  changeRequest,
13
15
  ChangeRequestResult,
@@ -45,6 +47,7 @@ import {
45
47
  import review from './review'
46
48
  import shepherd from './shepherd'
47
49
  import { ShepherdOutput } from './shepherd-output'
50
+ import { DeliveryFields, epicOf, ownDeliveryTarget } from './delivery'
48
51
  import { ChangeRequestSummary, Reason, ShortStatement } from './text-limits'
49
52
 
50
53
  export const BuildInput = Schema.Struct({
@@ -72,7 +75,8 @@ export const BuildInput = Schema.Struct({
72
75
  * How many more Builds an unattended full-auto Run starts on its ChangeRequest while review findings still stand,
73
76
  * before it fails with them; 1 when left out.
74
77
  */
75
- maxRebuilds: Schema.optional(Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)))
78
+ maxRebuilds: Schema.optional(Schema.Int.check(Schema.isGreaterThanOrEqualTo(0))),
79
+ ...DeliveryFields
76
80
  })
77
81
 
78
82
  /** The implementer's answer to one acceptance criterion of the Task. */
@@ -145,7 +149,9 @@ export const BuildOutput = Schema.Struct({
145
149
  /** What Shepherd did with the ChangeRequest, when the Build was told to land it. */
146
150
  landed: Schema.optional(ShepherdOutput),
147
151
  /** The input its Shepherd and Review offers start from. */
148
- next: Schema.Struct({ changeRequestId: Schema.String })
152
+ next: Schema.Struct({ changeRequestId: Schema.String }),
153
+ /** Where the Run's delivery landed and the layer it came from. */
154
+ deliversTo: Schema.optional(ResolvedDeliveryTarget)
149
155
  })
150
156
 
151
157
  /** Build was marked blocked on findings that still stand, so the Task waits on its owner. */
@@ -410,7 +416,7 @@ const rally = (input: {
410
416
  */
411
417
  const build = defineLoop({
412
418
  id: 'build',
413
- version: '2.6.0',
419
+ version: '2.7.0',
414
420
  title: 'Build',
415
421
  input: BuildInput,
416
422
  output: BuildOutput,
@@ -441,7 +447,12 @@ const build = defineLoop({
441
447
  const outcome = input.outcome
442
448
  // A retry carries the earlier Run's branch as `branch`, or the branch that Run started from when it never pushed;
443
449
  // the ChangeRequest it continues says what it merges into.
444
- const target = input.continuing?.targetBranch ?? input.branch
450
+ const epic = epicOf(input)
451
+ const target = input.continuing?.targetBranch ?? input.branch ?? epic?.branch
452
+
453
+ // Under epic delivery a sub-task branches from its epic's branch, which the first sub-task's Build makes.
454
+ if (epic !== undefined && input.continuing === undefined && input.branch === undefined)
455
+ yield* deliveryBase('epic-branch')
445
456
 
446
457
  if (input.changeRequestId !== undefined && input.continuing?.changeRequestId !== input.changeRequestId)
447
458
  return yield* new BuildTargetMissing({
@@ -639,7 +650,8 @@ const build = defineLoop({
639
650
  ...(input.outcome === undefined ? undefined : { outcome: input.outcome }),
640
651
  ...(input.maxRounds === undefined ? undefined : { maxRounds: input.maxRounds }),
641
652
  changeRequestId: opened.id,
642
- land: false
653
+ land: false,
654
+ ...ownDeliveryTarget(input)
643
655
  },
644
656
  { constraints: standing.map(standingConstraint) }
645
657
  )
@@ -653,7 +665,8 @@ const build = defineLoop({
653
665
  changeRequestId: opened.id,
654
666
  ...(settledAs.notRun === undefined ? undefined : { notRun: settledAs.notRun }),
655
667
  ...(input.taskId === undefined ? undefined : { taskId: input.taskId }),
656
- ...(input.branch === undefined ? undefined : { branch: input.branch })
668
+ ...(input.branch === undefined ? undefined : { branch: input.branch }),
669
+ ...ownDeliveryTarget(input)
657
670
  })
658
671
  : undefined
659
672
 
@@ -661,7 +674,8 @@ const build = defineLoop({
661
674
  changeRequest: opened,
662
675
  ...settledAs,
663
676
  ...(landed === undefined ? undefined : { landed }),
664
- next: { changeRequestId: opened.id }
677
+ next: { changeRequestId: opened.id },
678
+ ...(input.deliversTo === undefined ? undefined : { deliversTo: input.deliversTo })
665
679
  }
666
680
  }).pipe(
667
681
  Effect.tapError(error =>
@@ -0,0 +1,29 @@
1
+ import { DeliveryTarget, EpicDelivery, ResolvedDeliveryTarget } from '@kitman-sh/sdk/loop'
2
+ import * as Schema from 'effect/Schema'
3
+
4
+ /** The Input fields of a Loop that delivers by the Workspace's, Team's and Project's delivery target. */
5
+ export const DeliveryFields = {
6
+ /** This Run's own delivery target, over its Project's, Team's and Workspace's; `default_branch` ships a hotfix. */
7
+ deliveryTarget: Schema.optional(DeliveryTarget),
8
+ /** Where the Run's delivery lands and the layer it came from; Kitman sets it when the Run starts. */
9
+ deliversTo: Schema.optional(ResolvedDeliveryTarget),
10
+ /** The epic the Run's Task delivers through under epic delivery; Kitman sets it when the Run starts. */
11
+ epic: Schema.optional(EpicDelivery)
12
+ }
13
+
14
+ type Delivering = { readonly deliversTo?: ResolvedDeliveryTarget | undefined }
15
+
16
+ /** Passes a Run's own delivery target on to the Runs it calls; they resolve the same layers for the same Task. */
17
+ export const ownDeliveryTarget = (input: Delivering) =>
18
+ input.deliversTo?.layer === 'run' ? { deliveryTarget: input.deliversTo.target } : undefined
19
+
20
+ /** The epic a Run delivers through, when its delivery lands on the epic branch. */
21
+ export const epicOf = (input: Delivering & { readonly epic?: EpicDelivery | undefined }) =>
22
+ input.deliversTo?.target === 'epic_branch' ? input.epic : undefined
23
+
24
+ export const deliveryLayerWords = {
25
+ run: 'this Run',
26
+ project: 'its Project',
27
+ team: 'its Team',
28
+ workspace: 'the Workspace'
29
+ } as const
package/src/index.ts CHANGED
@@ -8,6 +8,7 @@ import projectUpdate from './project-update'
8
8
  import release from './release'
9
9
  import research from './research'
10
10
  import hindsight from './hindsight'
11
+ import landEpic from './land-epic'
11
12
  import review from './review'
12
13
  import shepherd from './shepherd'
13
14
  import sweep from './sweep'
@@ -25,6 +26,7 @@ export const loops = {
25
26
  release,
26
27
  research,
27
28
  hindsight,
29
+ 'land-epic': landEpic,
28
30
  review,
29
31
  shepherd,
30
32
  sweep,
@@ -42,6 +44,7 @@ export {
42
44
  release,
43
45
  research,
44
46
  hindsight,
47
+ landEpic,
45
48
  review,
46
49
  shepherd,
47
50
  sweep,
@@ -0,0 +1,137 @@
1
+ import {
2
+ call,
3
+ type CalledLoop,
4
+ changeRequest,
5
+ ChangeRequestResult,
6
+ Continuing,
7
+ defineLoop,
8
+ ResolvedDeliveryTarget,
9
+ syncBase,
10
+ writeBack
11
+ } from '@kitman-sh/sdk/loop'
12
+ import * as Effect from 'effect/Effect'
13
+ import * as Schema from 'effect/Schema'
14
+ import { DeliveryFields, deliveryLayerWords, epicOf, ownDeliveryTarget } from './delivery'
15
+ import shepherd from './shepherd'
16
+ import { ShepherdOutput } from './shepherd-output'
17
+
18
+ export const LandEpicInput = Schema.Struct({
19
+ /** The epic: a Task with sub-tasks. */
20
+ taskId: Schema.String,
21
+ /** Marks the Loop that works on the epic's own branch: Kitman puts the Run there, never force-pushing it. */
22
+ landsEpic: Schema.optional(Schema.Boolean),
23
+ /** Merges the epic's ChangeRequest once it is approved, green and mergeable, without asking. */
24
+ merge: Schema.optional(Schema.Boolean),
25
+ /** The epic's open ChangeRequest an earlier Run opened, as Kitman puts the Run on it. */
26
+ continuing: Schema.optional(Continuing),
27
+ ...DeliveryFields
28
+ })
29
+
30
+ export const LandEpicOutput = Schema.Struct({
31
+ status: Schema.Literals([
32
+ /** The Task delivers to the default branch, or has no epic: there is no epic branch to land. */
33
+ 'not_epic',
34
+ /** The epic branch took in the default branch; its sub-tasks are not all done, so it waits. */
35
+ 'synced',
36
+ /** The epic is done already: its ChangeRequest to the default branch merged. */
37
+ 'landed',
38
+ /** The default branch conflicts with the epic branch in files the agent could not settle. */
39
+ 'conflict',
40
+ /** Every sub-task is done: the epic's ChangeRequest is open, and Shepherd saw it as far as `landed` says. */
41
+ 'opened'
42
+ ]),
43
+ reason: Schema.String,
44
+ changeRequest: Schema.optional(ChangeRequestResult),
45
+ landed: Schema.optional(ShepherdOutput),
46
+ deliversTo: Schema.optional(ResolvedDeliveryTarget)
47
+ })
48
+
49
+ type Output = typeof LandEpicOutput.Type
50
+
51
+ /**
52
+ * Lands an epic under epic delivery, on the epic's own branch: it merges the default branch in, so the epic branch keeps
53
+ * up with it, and once every sub-task is done opens the epic's ChangeRequest to the default branch and calls Shepherd,
54
+ * which merges it and starts Release. Shepherd calls it after each sub-task's ChangeRequest merges into the epic branch,
55
+ * and epic.ready starts it once the last sub-task closes, however it closed.
56
+ */
57
+ const landEpic = defineLoop({
58
+ id: 'land-epic',
59
+ version: '1.0.0',
60
+ title: 'Land epic',
61
+ input: LandEpicInput,
62
+ output: LandEpicOutput,
63
+ agents: { implementer: 'implementer' },
64
+ checkout: 'write',
65
+ capabilities: ['agent_work', 'change_request', 'write_back', 'call'],
66
+ calls: (): readonly CalledLoop[] => [shepherd],
67
+ when: [{ event: 'epic.ready', input: { taskId: 'taskId' } }],
68
+ run: input =>
69
+ Effect.gen(function* () {
70
+ const epic = epicOf(input)
71
+ const recorded = input.deliversTo === undefined ? undefined : { deliversTo: input.deliversTo }
72
+
73
+ if (epic === undefined)
74
+ return {
75
+ status: 'not_epic',
76
+ reason:
77
+ input.deliversTo === undefined
78
+ ? 'The Task delivers to no epic branch'
79
+ : `The Task lands ${input.deliversTo.target === 'epic_branch' ? 'on no epic' : 'on the default branch'}, as ${deliveryLayerWords[input.deliversTo.layer]} says`,
80
+ ...recorded
81
+ } satisfies Output
82
+
83
+ if (epic.done)
84
+ return {
85
+ status: 'landed',
86
+ reason: `Epic ${epic.key} is done: its ChangeRequest merged into ${epic.defaultBranch}`,
87
+ ...recorded
88
+ } satisfies Output
89
+
90
+ const synced = yield* syncBase('sync-default', { agent: 'implementer', target: epic.defaultBranch })
91
+
92
+ if (synced.status === 'conflict')
93
+ return {
94
+ status: 'conflict',
95
+ reason: `${epic.defaultBranch} conflicts with ${epic.branch} in ${synced.files.join(', ')}: ${synced.reason}`,
96
+ ...recorded
97
+ } satisfies Output
98
+
99
+ if (!epic.subTasksDone && input.continuing === undefined)
100
+ return {
101
+ status: 'synced',
102
+ reason: `${epic.branch} is up to date with ${epic.defaultBranch}; ${epic.key} lands once every sub-task is done`,
103
+ ...recorded
104
+ } satisfies Output
105
+
106
+ const opened =
107
+ input.continuing === undefined
108
+ ? yield* changeRequest('epic-change-request', {
109
+ title: `${epic.key} Land the epic`,
110
+ body: [
111
+ `Lands epic ${epic.key} on ${epic.defaultBranch}: every sub-task is done, and each merged into ${epic.branch} through its own ChangeRequest.`,
112
+ `${epic.branch} took in ${epic.defaultBranch} before this opened.`
113
+ ].join('\n\n')
114
+ })
115
+ : { id: input.continuing.changeRequestId, number: input.continuing.number, url: input.continuing.url }
116
+
117
+ if (input.continuing === undefined)
118
+ yield* writeBack('write-back', { milestone: 'change_request_opened', changeRequestUrl: opened.url })
119
+
120
+ const landed = yield* call('shepherd', shepherd, {
121
+ changeRequestId: opened.id,
122
+ taskId: epic.taskId,
123
+ ...(input.merge === undefined ? undefined : { merge: input.merge }),
124
+ ...ownDeliveryTarget(input)
125
+ })
126
+
127
+ return {
128
+ status: 'opened',
129
+ reason: `${opened.url} lands ${epic.key}; Shepherd ended ${landed.status}: ${landed.reason}`,
130
+ changeRequest: opened,
131
+ landed,
132
+ ...recorded
133
+ } satisfies Output
134
+ })
135
+ })
136
+
137
+ export default landEpic
package/src/release.ts CHANGED
@@ -11,24 +11,38 @@ import {
11
11
  ReleaseScope,
12
12
  ReleaseTrigger,
13
13
  ResolvedReleaseTrigger,
14
+ ResolvedDeliveryTarget,
14
15
  rerunPipeline,
16
+ runDeploy,
15
17
  ShippedScope,
16
18
  shippedScope,
17
19
  StepFailed,
20
+ type LoopEvent,
18
21
  verify,
19
22
  waitFor
20
23
  } from '@kitman-sh/sdk/loop'
21
24
  import * as Effect from 'effect/Effect'
22
25
  import * as Schema from 'effect/Schema'
23
- import { FindingDetail } from './text-limits'
26
+ import { DeliveryFields, deliveryLayerWords, epicOf } from './delivery'
27
+
28
+ /** An id a full-auto answer's evidence can carry: Kitman refuses an empty one or one over 240 characters. */
29
+ const ApprovalRef = Schema.String.check(Schema.isMinLength(1), Schema.isMaxLength(240))
30
+
31
+ /** What identifies a `change_request.approval` Event's approval: a Kitman review's id, else the forge approval's `approvalId`. */
32
+ export const approvalRef = (event: LoopEvent | undefined) =>
33
+ [event?.payload.reviewId, event?.payload.approvalId].find(Schema.is(ApprovalRef))
24
34
 
25
35
  const Input = Schema.Struct({
26
36
  /** The tag to release; the drafting agent proposes one when left out. */
27
37
  tag: Schema.optional(Schema.String),
28
38
  /** The revision to tag; the Run's base branch head when left out. */
29
39
  revision: Schema.optional(Schema.String),
40
+ /** The approval of the change being released, recorded with a full-auto approval of the release. */
41
+ review: Schema.optional(ApprovalRef),
30
42
  /** A release ChangeRequest to wait for, merge, and tag the merge of. */
31
43
  changeRequestId: Schema.optional(Schema.String),
44
+ /** The Task it delivers, whose Project's release trigger the Run uses. */
45
+ taskId: Schema.optional(Schema.String),
32
46
  /** What the release deploys to; one Release deploys to it at a time. The deploy Event type when left out. */
33
47
  deployTarget: Schema.optional(Schema.String),
34
48
  /** The Event type the deploy reports; `deploy` when left out. Its payload names the `tag` and a `status`. */
@@ -46,7 +60,8 @@ const Input = Schema.Struct({
46
60
  /** The Project's version its Milestone or Project releases; Kitman sets it when release.due starts the Run. */
47
61
  version: Schema.optional(Schema.String),
48
62
  /** Whether it releases the next release candidate of `version`, numbered once it holds the deploy target, or `version`. */
49
- candidate: Schema.optional(Schema.Boolean)
63
+ candidate: Schema.optional(Schema.Boolean),
64
+ ...DeliveryFields
50
65
  })
51
66
 
52
67
  const Drafted = Schema.Struct({
@@ -69,22 +84,6 @@ const Picked = Schema.Struct({
69
84
  releasedIn: Schema.optional(Schema.String)
70
85
  })
71
86
 
72
- /** What the repository's own deploy script did, as the releaser read it from its last line and exit code. */
73
- const Deployed = Schema.Struct({
74
- /** none: the repository has no `.kitman/deploy`, so the deploy is left to whatever sends the deploy Event. */
75
- status: Schema.Literals(['deployed', 'failed', 'rolled_back', 'rollback_failed', 'none']),
76
- detail: FindingDetail
77
- })
78
-
79
- const deployPrompt = (tag: string, previousTag: string | undefined) =>
80
- [
81
- `Deploy the release ${tag}, which Kitman has just tagged and pushed.`,
82
- `Fetch the base branch and tags (\`git fetch origin --tags\`). If neither the base branch head nor ${tag} has an executable \`.kitman/deploy\`, change nothing and answer status none.`,
83
- `Otherwise run \`.kitman/deploy ${tag}${previousTag === undefined ? '' : ` ${previousTag}`}\` from a checkout of the base branch head when it has the script, so a rerun of an older tag gets the script's later fixes, or else from the checkout of ${tag}, and do nothing else: it deploys the tag it is given, backs up, publishes, verifies and rolls back by itself, and may take an hour. Run it in the background with its output in a log file, and wait for it to exit, checking every few minutes; never start it twice.`,
84
- 'Answer with the status its last line `kitman-deploy: <status> <detail>` names, and that detail. If it exited without that line, answer failed with its exit code and the end of its log.',
85
- 'Never print, copy or summarise the variables or secrets it pulls.'
86
- ].join('\n\n')
87
-
88
87
  const Output = Schema.Struct({
89
88
  status: Schema.Literals([
90
89
  'gate_failed',
@@ -107,10 +106,14 @@ const Output = Schema.Struct({
107
106
  reason: Schema.String,
108
107
  tag: Schema.optional(Schema.String),
109
108
  notesArtifactId: Schema.optional(Schema.String),
109
+ /** A person chose Leave it in the recover Question. */
110
+ leftUndeployed: Schema.optional(Schema.Boolean),
110
111
  revision: Schema.optional(Schema.String),
111
112
  url: Schema.optional(Schema.String),
112
113
  /** The release trigger the Run used and the layer it came from. */
113
114
  releaseWhen: Schema.optional(ResolvedReleaseTrigger),
115
+ /** Where the Run's delivery lands and the layer it came from. */
116
+ deliversTo: Schema.optional(ResolvedDeliveryTarget),
114
117
  /** The Milestone or Project that triggered it, and the Tasks it shipped. */
115
118
  shipped: Schema.optional(ShippedScope)
116
119
  })
@@ -301,7 +304,9 @@ const readyToMerge = (changeRequestId: string, round = 1) =>
301
304
  reason: `ChangeRequest ${changeRequestId} does not merge cleanly; bring it up to date first`
302
305
  } satisfies Output
303
306
 
304
- return { passed: read.head }
307
+ const review = approvalRef(approved)
308
+
309
+ return { passed: read.head, ...(review === undefined ? undefined : { review }) }
305
310
  }
306
311
  }).pipe(
307
312
  Effect.catchTags({
@@ -339,15 +344,17 @@ const recovery = (previous: string | undefined) =>
339
344
  * it, with the Project's version and the Tasks it ships, which it records; without a version it stops rather than
340
345
  * choose one. A Milestone's release candidate is numbered under the deploy target, after the latest one the repository
341
346
  * has, and gives way to the next when the forge finds it taken; the version itself is never moved. Either is released
342
- * even at a revision another tag contains. A Run whose `releaseTrigger` is `merge` releases anyway.
347
+ * even at a revision another tag contains. A Run whose `releaseTrigger` is `merge` releases anyway. A Team can turn on
348
+ * starting it on each head of a ChangeRequest delivering a Task that is approved and passed its pipeline while no Run
349
+ * works the ChangeRequest; it releases that only under a `merge` trigger.
343
350
  */
344
351
  export default defineLoop({
345
352
  id: 'release',
346
- version: '2.3.0',
353
+ version: '2.4.0',
347
354
  title: 'Release',
348
355
  input: Input,
349
356
  output: Output,
350
- agents: { releaser: 'releaser', deployer: 'deployer' },
357
+ agents: { releaser: 'releaser' },
351
358
  checkout: 'read',
352
359
  // Kitman records release.due per repository when a Milestone or Project closes under that trigger.
353
360
  when: [
@@ -360,6 +367,14 @@ export default defineLoop({
360
367
  releaseWhen: 'releaseWhen',
361
368
  repoBindingId: 'repoBindingId'
362
369
  }
370
+ },
371
+ {
372
+ event: 'change_request.ready',
373
+ filter: { busy: false },
374
+ input: { changeRequestId: 'changeRequestId', taskId: 'taskId' },
375
+ optIn: true,
376
+ description:
377
+ 'Releases a ChangeRequest delivering a Task once it is approved and green and no Run works it, only under a merge release trigger; under a Milestone or Project trigger each such Run ends not_due.'
363
378
  }
364
379
  ],
365
380
  capabilities: [
@@ -382,6 +397,15 @@ export default defineLoop({
382
397
  reason: `Release runs when ${triggerWords[when.trigger]}, as ${layerWords[when.layer]} says; this Run did not override that`
383
398
  } satisfies Output
384
399
 
400
+ const epic = epicOf(input)
401
+
402
+ // Under epic delivery a sub-task's work reaches the default branch only with its epic's ChangeRequest.
403
+ if (epic !== undefined && !epic.done)
404
+ return {
405
+ status: 'not_due',
406
+ reason: `Its Task lands on ${epic.branch}, as ${deliveryLayerWords[input.deliversTo?.layer ?? 'workspace']} says; Release runs once epic ${epic.key} merges into ${epic.defaultBranch}`
407
+ } satisfies Output
408
+
385
409
  if (input.releaseScope !== undefined && input.tag === undefined && input.version === undefined)
386
410
  return {
387
411
  status: 'no_version',
@@ -393,6 +417,7 @@ export default defineLoop({
393
417
  const changeRequestId = input.changeRequestId
394
418
  // The commit the gate proved, and the one tagged or merged: never the branch head read again later.
395
419
  let gated: string
420
+ let review = input.review
396
421
 
397
422
  if (changeRequestId === undefined) {
398
423
  // A failure an earlier Release recorded at this tree may be its checkout's, so it is run again.
@@ -450,6 +475,7 @@ export default defineLoop({
450
475
 
451
476
  if (!('passed' in ready)) return ready
452
477
  gated = ready.passed
478
+ review = ready.review
453
479
  }
454
480
 
455
481
  const cut: Cut | undefined =
@@ -500,7 +526,8 @@ export default defineLoop({
500
526
  'The release is proved: its checks pass, or its ChangeRequest is green, approved and mergeable.',
501
527
  default: null,
502
528
  // A full-auto Team has handed releasing a proved change to Kitman.
503
- auto: 'Approve'
529
+ auto: 'Approve',
530
+ evidence: { ...(review === undefined ? undefined : { review }), head: gated }
504
531
  })
505
532
 
506
533
  if (answer === 'Approve') break
@@ -575,6 +602,29 @@ export default defineLoop({
575
602
 
576
603
  if (!('passed' in ready)) return { ...ready, tag, notesArtifactId: notes.artifactId }
577
604
  gated = ready.passed
605
+ review = ready.review
606
+
607
+ // The release was approved at an earlier head, so this one is approved on its own approval and gate.
608
+ const again = yield* ask(`approve:merge:${round + 1}`, {
609
+ prompt: `ChangeRequest ${changeRequestId} moved to ${gated} after ${tag} was approved; its pipeline passed and it is approved again. Release ${tag} from it?`,
610
+ options: [
611
+ { value: 'Approve', description: 'Merges this head, then tags, publishes and deploys it.' },
612
+ { value: 'Reject', description: 'Keeps the draft and releases nothing.' }
613
+ ],
614
+ recommended: 'Approve',
615
+ recommendationReason: 'This head is green, approved and mergeable, like the one you approved.',
616
+ default: null,
617
+ auto: 'Approve',
618
+ evidence: { ...(review === undefined ? undefined : { review }), head: gated }
619
+ })
620
+
621
+ if (again !== 'Approve')
622
+ return {
623
+ status: 'rejected',
624
+ reason: `Not released from ${gated}, the head ChangeRequest ${changeRequestId} moved to`,
625
+ tag,
626
+ notesArtifactId: notes.artifactId
627
+ } satisfies Output
578
628
  }
579
629
  }
580
630
 
@@ -664,12 +714,7 @@ export default defineLoop({
664
714
  const settled = { tag, notesArtifactId: notes.artifactId, revision: released.revision, url: released.url }
665
715
 
666
716
  // The repository deploys itself from the Runner when it has a deploy script, which rolls back on its own.
667
- const ran = yield* agentWork('run-deploy', {
668
- agent: 'deployer',
669
- prompt: deployPrompt(tag, drafted.previousTag),
670
- output: Deployed,
671
- timeout: '3 hours'
672
- })
717
+ const ran = yield* runDeploy('run-deploy', { tag, previousTag: drafted.previousTag })
673
718
 
674
719
  if (ran.status !== 'none') {
675
720
  const status = ran.status === 'failed' ? 'deploy_failed' : ran.status
@@ -702,12 +747,17 @@ export default defineLoop({
702
747
  recommended: 'Retry the deploy',
703
748
  recommendationReason:
704
749
  'A failed or late deploy is often passing, and a retry runs only the failed jobs of the same tag.',
705
- default: 'Leave it',
706
- timeout: '1 hour'
750
+ // Waits for a person, so Leave it is always their choice.
751
+ default: null
707
752
  })
708
753
 
709
754
  if (answer === 'Leave it')
710
- return { status, reason: `${tag} at ${released.revision} was left undeployed`, ...settled } satisfies Output
755
+ return {
756
+ status,
757
+ reason: `${tag} at ${released.revision} was left undeployed`,
758
+ leftUndeployed: true,
759
+ ...settled
760
+ } satisfies Output
711
761
 
712
762
  if (answer === 'Retry the deploy') {
713
763
  yield* rerunPipeline(`deploy:rerun-${round}`, { ref: tag })
@@ -737,6 +787,7 @@ export default defineLoop({
737
787
  Effect.map((output): Output => ({
738
788
  ...output,
739
789
  ...(input.releaseWhen === undefined ? undefined : { releaseWhen: input.releaseWhen }),
790
+ ...(input.deliversTo === undefined ? undefined : { deliversTo: input.deliversTo }),
740
791
  ...(input.releaseScope === undefined ? undefined : { shipped: shippedScope(input.releaseScope) })
741
792
  }))
742
793
  )