@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/src/review.ts CHANGED
@@ -16,12 +16,15 @@ import {
16
16
  RebuttalVerdict,
17
17
  pipelineStatus,
18
18
  resolveRevisions,
19
- ScopeJudgement
19
+ ResolvedDeliveryTarget,
20
+ ScopeJudgement,
21
+ settleRound
20
22
  } from '@kitman-sh/sdk/loop'
21
23
  import * as Effect from 'effect/Effect'
22
24
  import * as Schema from 'effect/Schema'
23
25
  import build, { BuildInput, BuildOutput } from './build'
24
26
  import { verifyHead } from './change-request-body'
27
+ import { DeliveryFields, ownDeliveryTarget } from './delivery'
25
28
  import { FindingDetail, OneSentence } from './text-limits'
26
29
 
27
30
  /** Build, by its schemas: the module imports this one, so its definition is not ready when this one loads. */
@@ -78,7 +81,8 @@ const Input = Schema.Struct({
78
81
  /** Why each head test verify never ran is unverified; a ChangeRequest's head is verified here too. */
79
82
  notRun: Schema.optional(Schema.Array(Schema.String)),
80
83
  /** What to do after a ChangeRequest's review without asking; Done when nobody answers. */
81
- next: Schema.optional(Schema.Literals(choices))
84
+ next: Schema.optional(Schema.Literals(choices)),
85
+ ...DeliveryFields
82
86
  })
83
87
 
84
88
  const FollowUpStatus = Schema.Literals(['fixed', 'changed', 'still_there'])
@@ -119,7 +123,9 @@ const Output = Schema.Struct({
119
123
  Schema.Struct({ head: Schema.String, approved: Schema.Boolean, reason: Schema.optional(Schema.String) })
120
124
  ),
121
125
  /** What happened after a ChangeRequest's review. */
122
- next: Schema.optional(Schema.Struct({ choice: Schema.Literals(choices), detail: Schema.optional(Schema.String) }))
126
+ next: Schema.optional(Schema.Struct({ choice: Schema.Literals(choices), detail: Schema.optional(Schema.String) })),
127
+ /** Where the reviewed delivery lands and the layer it came from. */
128
+ deliversTo: Schema.optional(ResolvedDeliveryTarget)
123
129
  })
124
130
 
125
131
  export class ReviewTargetMissing extends Schema.TaggedError<ReviewTargetMissing>()('ReviewTargetMissing', {
@@ -318,7 +324,7 @@ const fixBrief = (changeRequestId: string, findings: readonly MergedFinding[]) =
318
324
  */
319
325
  export default defineLoop({
320
326
  id: 'review',
321
- version: '3.7.0',
327
+ version: '3.8.0',
322
328
  title: 'Review',
323
329
  input: Input,
324
330
  output: Output,
@@ -383,17 +389,13 @@ export default defineLoop({
383
389
  const standing = new Set(answered.flatMap(entry => (entry.status === 'fixed' ? [] : [entry.id])))
384
390
 
385
391
  const verdicts = outputs.flatMap(([, output]) => output.verdicts ?? [])
386
- const rebutted = new Set((input.rebuttals ?? []).map(rebuttal => rebuttal.findingId))
387
392
 
388
- // A rebutted finding every verdict on it accepts is withdrawn, as Build's settleRound counts it.
389
- const withdrawn = (id: string) => {
390
- const on = verdicts.filter(verdict => verdict.findingId === id)
393
+ const settled = settleRound({ findings: earlier, rebuttals: input.rebuttals ?? [], verdicts })
391
394
 
392
- return rebutted.has(id) && on.length > 0 && on.every(verdict => verdict.accepted)
393
- }
395
+ const withdrawn = new Set(settled.withdrawn.map(entry => entry.finding.id))
394
396
 
395
- const carried = earlier.filter(finding => standing.has(finding.id) && !withdrawn(finding.id))
396
- const followUps = answered.filter(entry => !withdrawn(entry.id))
397
+ const carried = earlier.filter(finding => standing.has(finding.id) && !withdrawn.has(finding.id))
398
+ const followUps = answered.filter(entry => !withdrawn.has(entry.id))
397
399
 
398
400
  const sinceApproval = input.approved !== undefined && input.files === undefined
399
401
 
@@ -453,7 +455,8 @@ export default defineLoop({
453
455
  blocking: findings.some(isBlocking),
454
456
  artifactId: stored.artifactId,
455
457
  ...(approvedFindings.length === 0 ? undefined : { approvedFindings }),
456
- ...(scope === undefined ? undefined : { scope })
458
+ ...(scope === undefined ? undefined : { scope }),
459
+ ...(input.deliversTo === undefined ? undefined : { deliversTo: input.deliversTo })
457
460
  }
458
461
 
459
462
  const changeRequestId = input.changeRequestId
@@ -517,14 +520,18 @@ export default defineLoop({
517
520
  const fixed = yield* call('fix', buildLoop(), {
518
521
  words: fixBrief(changeRequestId, findings),
519
522
  changeRequestId,
520
- maxRounds: 2
523
+ maxRounds: 2,
524
+ ...ownDeliveryTarget(input)
521
525
  })
522
526
 
523
527
  return { choice, detail: fixed.settled ? 'Fixed and pushed' : `Pushed; left: ${fixed.unsettled.join('; ')}` }
524
528
  }
525
529
 
526
530
  if (choice === 'Build from it') {
527
- const built = yield* call('build', buildLoop(), { words: fixBrief(changeRequestId, findings) })
531
+ const built = yield* call('build', buildLoop(), {
532
+ words: fixBrief(changeRequestId, findings),
533
+ ...ownDeliveryTarget(input)
534
+ })
528
535
 
529
536
  return { choice, detail: built.changeRequest.url }
530
537
  }
@@ -532,7 +539,11 @@ export default defineLoop({
532
539
  return { choice, detail: 'The review is kept as an artifact' }
533
540
  }).pipe(Effect.catchTag('ChildFailed', failed => Effect.succeed({ choice, detail: failed.reason })))
534
541
 
535
- return { ...reviewed, ...(approval === undefined ? undefined : { approval }), next }
542
+ return {
543
+ ...reviewed,
544
+ ...(approval === undefined ? undefined : { approval }),
545
+ next
546
+ }
536
547
  })
537
548
  })
538
549
 
@@ -1,4 +1,4 @@
1
- import { ResolvedReleaseTrigger } from '@kitman-sh/sdk/loop'
1
+ import { ResolvedDeliveryTarget, ResolvedReleaseTrigger } from '@kitman-sh/sdk/loop'
2
2
  import * as Schema from 'effect/Schema'
3
3
 
4
4
  /** Shepherd's Output, outside shepherd.ts so Build can import it without the review → build → shepherd cycle. */
@@ -17,6 +17,10 @@ export const ShepherdOutput = Schema.Struct({
17
17
  ),
18
18
  /** The release trigger the Run used and the layer it came from. */
19
19
  releaseWhen: Schema.optional(ResolvedReleaseTrigger),
20
+ /** Where the Run's delivery landed and the layer it came from. */
21
+ deliversTo: Schema.optional(ResolvedDeliveryTarget),
22
+ /** What Land epic did after a sub-task merged into its epic's branch: kept it up with the default branch, or opened the epic's ChangeRequest. */
23
+ epicLanding: Schema.optional(Schema.Struct({ status: Schema.String, reason: Schema.String })),
20
24
  /** The Build its offer starts when it hands the ChangeRequest back: that ChangeRequest, and what is still open. */
21
25
  handBack: Schema.optional(
22
26
  Schema.Struct({
package/src/shepherd.ts CHANGED
@@ -22,6 +22,7 @@ import {
22
22
  syncBase,
23
23
  verify,
24
24
  waitFor,
25
+ type EpicDelivery,
25
26
  writeBack,
26
27
  isBlocking,
27
28
  isUnansweredQuestion,
@@ -32,7 +33,9 @@ import {
32
33
  } from '@kitman-sh/sdk/loop'
33
34
  import * as Effect from 'effect/Effect'
34
35
  import * as Schema from 'effect/Schema'
35
- import release from './release'
36
+ import release, { approvalRef } from './release'
37
+ import landEpic, { LandEpicInput, LandEpicOutput } from './land-epic'
38
+ import { DeliveryFields, epicOf, ownDeliveryTarget } from './delivery'
36
39
  import { verifyHead } from './change-request-body'
37
40
  import review, { ReviewInput, ReviewOutput } from './review'
38
41
  import { ShepherdOutput } from './shepherd-output'
@@ -41,6 +44,18 @@ import { OneSentence } from './text-limits'
41
44
  /** Review, by its schemas: Build calls this Loop and Review calls Build, so Review's definition may not be ready yet. */
42
45
  const reviewLoop = () => ({ id: 'review', input: ReviewInput, output: ReviewOutput })
43
46
 
47
+ /** Land epic, by its schemas: it calls this Loop, so its definition may not be ready yet. */
48
+ const landEpicLoop = () => ({ id: 'land-epic', input: LandEpicInput, output: LandEpicOutput })
49
+
50
+ /** How often a merge into an epic branch calls Land epic while another Run works that branch, and how far apart. */
51
+ const landingCalls = 6
52
+
53
+ const landingRetry = '10 minutes'
54
+
55
+ /** Kitman's refusals of a Land epic: another Run lands the epic already, or works the epic branch for now. */
56
+ const landingStatus = (code: string | undefined) =>
57
+ code === 'epic_landing' ? 'landing' : code === 'task_branch_busy' ? 'busy' : 'refused'
58
+
44
59
  /** The model time one fix or round of replies may take before a person looks. */
45
60
  const stepBudget = '45 minutes'
46
61
 
@@ -50,6 +65,12 @@ const pipelineRun = '10 minutes' as const
50
65
  /** The reads of a red target one look takes, about an hour of them. */
51
66
  const targetLooks = 6
52
67
 
68
+ /** How long one look waits, left for a person to merge, for the target to move before it reads the ChangeRequest again. */
69
+ const watchLook = '6 hours' as const
70
+
71
+ /** The looks it takes, about a week of them, before it leaves the merge to a person for good. */
72
+ const watchLooks = 28
73
+
53
74
  /** Rounds of each kind a Run takes before it asks whether to hand the ChangeRequest back to Build. */
54
75
  const roundLimits = { 'ci-fix': 1, 'head-fix': 2 } as const
55
76
 
@@ -74,7 +95,8 @@ const Input = Schema.Struct({
74
95
  /** This Run's own release trigger, over its Project's, Team's and Workspace's; `merge` releases this merge, as for a hotfix. */
75
96
  releaseTrigger: Schema.optional(ReleaseTrigger),
76
97
  /** The release trigger the Run uses and the layer it came from; Kitman sets it when the Run starts. */
77
- releaseWhen: Schema.optional(ResolvedReleaseTrigger)
98
+ releaseWhen: Schema.optional(ResolvedReleaseTrigger),
99
+ ...DeliveryFields
78
100
  })
79
101
 
80
102
  const layerWords = { run: 'this Run', project: 'its Project', team: 'its Team', workspace: 'the Workspace' } as const
@@ -214,17 +236,28 @@ const threadKey = (thread: ReviewThreads['threads'][number]) => `${thread.id}:${
214
236
  * order. A head nobody approved gets a review of what changed since the last approved head, and the head a catch-up
215
237
  * 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
216
238
  * head-fix rounds, each judged by the pipeline at the head the last fix pushed, then hands the ChangeRequest back to
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.
239
+ * Build, and stops as needs you, with why, instead of spinning. Left for a person to merge, it watches the target for up to
240
+ * a week, runs the repository's checks that read the target again at the head each time the target moves, and catches
241
+ * up when they fail, as when the target gained a migration the head's own does not build on. After merging it starts Release only when its release
242
+ * trigger is `merge`; under a Milestone or Project trigger that completion starts Release instead. A Team can turn on
243
+ * starting it when the forge fails the pipeline of a ChangeRequest that delivers a Task.
219
244
  */
220
245
  export default defineLoop({
221
246
  id: 'shepherd',
222
- version: '1.6.1',
247
+ version: '1.8.0',
223
248
  title: 'Shepherd',
224
249
  input: Input,
225
250
  output: Output,
226
251
  agents: { implementer: 'implementer' },
227
252
  checkout: 'write',
253
+ when: [
254
+ {
255
+ event: 'change_request.pipeline',
256
+ filter: { status: 'failed', source: 'forge', linked: true },
257
+ input: { changeRequestId: 'changeRequestId', taskId: 'taskId' },
258
+ optIn: true
259
+ }
260
+ ],
228
261
  capabilities: [
229
262
  'agent_work',
230
263
  'read_change_request',
@@ -237,7 +270,7 @@ export default defineLoop({
237
270
  'verify',
238
271
  'claim'
239
272
  ],
240
- calls: (): readonly CalledLoop[] => [review, release],
273
+ calls: (): readonly CalledLoop[] => [review, release, landEpic],
241
274
  offers: [{ id: 'build', title: 'Hand back to Build', loop: 'build', from: 'handBack' }],
242
275
  run: input => {
243
276
  const changeRequestId = input.changeRequestId
@@ -276,6 +309,8 @@ export default defineLoop({
276
309
  let pipelineFirst: string | undefined
277
310
  /** Heads Shepherd's own review passed, approved or left to a person for tests verify never ran. */
278
311
  const reviewedHeads = new Set<string>()
312
+ /** The id of the approval Shepherd's own review recorded, by the head it approved. */
313
+ const approvalOf = new Map<string, string>()
279
314
 
280
315
  /** Why an approval of the head is still needed after a catch-up merge, for a person who is left to give it. */
281
316
  let notCarried: string | undefined
@@ -301,6 +336,12 @@ export default defineLoop({
301
336
  /** How often the forge's blocker has been looked at again at a head a sync settled it for. */
302
337
  const blockerRechecks = new Map<string, number>()
303
338
 
339
+ /** How the last catch-up's base sync ended. */
340
+ let lastSync: BaseSync['status'] | undefined
341
+
342
+ /** The head the checks that read the target last ran at, and the target's head they read then. */
343
+ let targetChecked: { readonly head: string; readonly targetHead: string } | undefined
344
+
304
345
  /** The target's turn: held from the sync before the merge until the merge, so one ChangeRequest merges at a time. */
305
346
  let turn: Claim | undefined
306
347
  let turns = 0
@@ -321,10 +362,50 @@ export default defineLoop({
321
362
  fixRounds: fixRounds(),
322
363
  replies,
323
364
  ...(input.releaseWhen === undefined ? undefined : { releaseWhen: input.releaseWhen }),
365
+ ...(input.deliversTo === undefined ? undefined : { deliversTo: input.deliversTo }),
324
366
  ...(status === 'needs_you' || status === 'handed_back' ? { unsettled: [reason] } : undefined)
325
367
  })
326
368
 
327
369
  const releaseWhen = input.releaseWhen
370
+ const epic = epicOf(input)
371
+
372
+ /**
373
+ * Calls Land epic once this merge is in the epic branch: it takes in the default branch, and opens the epic's
374
+ * ChangeRequest once every sub-task is done. While another Run works the epic branch Kitman refuses it, so it calls
375
+ * again once that Run can have ended: a landing that started before this merge saw this sub-task still open. One
376
+ * that saw every sub-task done, as epic.ready starts when this merge closes the last, lands the epic itself.
377
+ */
378
+ const landEpicAfter = (landing: EpicDelivery) =>
379
+ Effect.gen(function* () {
380
+ for (let attempt = 1; ; attempt++) {
381
+ const step = attempt === 1 ? 'land-epic' : `land-epic:${attempt}`
382
+
383
+ const called = yield* call(step, landEpicLoop(), {
384
+ taskId: landing.taskId,
385
+ ...ownDeliveryTarget(input)
386
+ }).pipe(
387
+ Effect.map(landed => ({ status: landed.status, reason: landed.reason })),
388
+ Effect.catchTags({
389
+ ChildFailed: failed => Effect.succeed({ status: 'failed', reason: failed.reason }),
390
+ StepFailed: refused => Effect.succeed({ status: landingStatus(refused.code), reason: refused.reason })
391
+ })
392
+ )
393
+
394
+ if (called.status !== 'busy') return called
395
+
396
+ if (attempt === landingCalls) return { status: 'refused', reason: called.reason }
397
+
398
+ yield* waitFor(`land-epic-busy:${attempt}`, {
399
+ event: 'change_request.closed',
400
+ filter: {
401
+ merged: true,
402
+ targetBranch: landing.branch,
403
+ ...(repository === undefined ? undefined : { repository })
404
+ },
405
+ timeout: landingRetry
406
+ }).pipe(Effect.catchTag('WaitTimedOut', () => Effect.void))
407
+ }
408
+ })
328
409
 
329
410
  const handBack = (reason: string, open: string): Output => ({
330
411
  ...done('handed_back', reason),
@@ -542,6 +623,8 @@ export default defineLoop({
542
623
 
543
624
  const synced = yield* syncBase(`sync:${cycle}`, { agent: 'implementer', target })
544
625
 
626
+ lastSync = synced.status
627
+
545
628
  if (synced.status === 'conflict')
546
629
  return handBack(
547
630
  `Merging ${target} in conflicts on ${synced.files.join(', ')}: ${synced.reason}`,
@@ -606,6 +689,101 @@ export default defineLoop({
606
689
 
607
690
  const stop = (output: Output) => ({ kind: 'stop', output }) as const
608
691
 
692
+ /**
693
+ * Left for a person to merge: watches the target and runs the checks that read it again at `pipeline`'s head each
694
+ * time it moves, and catches up when they fail, so the person merges a head that builds on the target. `again` when
695
+ * the ChangeRequest goes round once more, or `stop` with the Output: `ready` once the looks run out.
696
+ */
697
+ const watchTarget = (cycle: number, pipeline: PipelineStatus, ready: Output) =>
698
+ Effect.gen(function* () {
699
+ const checks = pipeline.targetChecks ?? []
700
+
701
+ if (checks.length === 0) return stop(ready)
702
+
703
+ yield* passTurn()
704
+
705
+ /** Runs the checks against the target as it is now; `again` or `stop` when they fail, else undefined. */
706
+ const runChecks = (step: string, targetHead: string | undefined) =>
707
+ Effect.gen(function* () {
708
+ const checked = yield* verify(step, { revision: pipeline.head, checks }).pipe(
709
+ Effect.catchTag('StepFailed', error => Effect.succeed({ failed: error.reason }))
710
+ )
711
+
712
+ if ('failed' in checked)
713
+ return stop(
714
+ done('needs_you', `${checks.join(', ')} could not run against ${target} as it moved: ${checked.failed}`)
715
+ )
716
+
717
+ if (targetHead !== undefined) targetChecked = { head: pipeline.head, targetHead }
718
+
719
+ if (checked.passed) return undefined
720
+
721
+ const stopped = yield* catchUp(cycle, targetHead)
722
+
723
+ if (stopped !== undefined) return stop(stopped)
724
+
725
+ if (lastSync === 'up_to_date')
726
+ return stop(
727
+ done(
728
+ 'needs_you',
729
+ `${checks.join(', ')} failed at ${pipeline.head} against ${target}, which has nothing new to merge in`
730
+ )
731
+ )
732
+
733
+ return { kind: 'again' } as const
734
+ })
735
+
736
+ const isChecked = (targetHead: string | undefined) =>
737
+ targetHead !== undefined && targetChecked?.head === pipeline.head && targetChecked.targetHead === targetHead
738
+
739
+ // The target may have moved before this read, and the head's own checks need not have read it.
740
+ if (!isChecked(pipeline.target?.head)) {
741
+ const first = yield* runChecks(`target-verify:${cycle}:0`, pipeline.target?.head)
742
+
743
+ if (first !== undefined) return first
744
+ }
745
+
746
+ let since = pipeline.readAt
747
+
748
+ for (let look = 1; look <= watchLooks; look++) {
749
+ const woke = yield* waitFor(`watch:${cycle}:${look}`, {
750
+ event: 'change_request.closed',
751
+ filter: {
752
+ merged: true,
753
+ ...(target === 'HEAD' ? undefined : { targetBranch: target }),
754
+ ...(repository === undefined ? undefined : { repository })
755
+ },
756
+ or: [{ event: 'change_request.closed', filter: { changeRequestId } }],
757
+ timeout: watchLook,
758
+ ...(since === undefined ? undefined : { since })
759
+ }).pipe(Effect.catchTag('WaitTimedOut', () => Effect.undefined))
760
+
761
+ if (woke?.payload.changeRequestId === changeRequestId)
762
+ return stop(
763
+ woke.payload.merged === true
764
+ ? done('merged', 'A person merged the ChangeRequest')
765
+ : done('needs_you', 'The ChangeRequest was closed')
766
+ )
767
+
768
+ const again = yield* pipelineStatus(`watch-read:${cycle}:${look}`, { changeRequestId })
769
+
770
+ since = again.readAt ?? since
771
+
772
+ if (again.head !== pipeline.head) return { kind: 'again' } as const
773
+
774
+ // A push straight to the target makes no Event: only a read that names its head shows it.
775
+ const targetHead = again.target?.head
776
+
777
+ if (woke === undefined && (targetHead === undefined || isChecked(targetHead))) continue
778
+
779
+ const ran = yield* runChecks(`target-verify:${cycle}:${look}`, targetHead)
780
+
781
+ if (ran !== undefined) return ran
782
+ }
783
+
784
+ return stop(ready)
785
+ })
786
+
609
787
  /**
610
788
  * Reviews the files a catch-up merge settled, at `head`, and approves it on a pass: `fixing` when a fix round ran for
611
789
  * its findings, `approved` or `unapproved` once the review passed, or `stop` with the Output.
@@ -665,6 +843,7 @@ export default defineLoop({
665
843
  return { kind: 'unapproved' } as const
666
844
  }
667
845
 
846
+ approvalOf.set(head, approval.reviewId)
668
847
  reviewedHeads.add(head)
669
848
 
670
849
  return { kind: 'approved' } as const
@@ -700,6 +879,7 @@ export default defineLoop({
700
879
  default: 'Wait',
701
880
  // A full-auto Team merges what its Review approved, including heads Shepherd pushed itself.
702
881
  auto: 'Review',
882
+ evidence: { head },
703
883
  timeout: '1 hour'
704
884
  })
705
885
 
@@ -768,6 +948,8 @@ export default defineLoop({
768
948
 
769
949
  if (!recorded.approved)
770
950
  return stop(done('needs_you', `The review of ${head} passed, but did not approve it: ${recorded.reason}`))
951
+
952
+ approvalOf.set(head, recorded.reviewId)
771
953
  }
772
954
 
773
955
  reviewedHeads.add(head)
@@ -1195,6 +1377,15 @@ export default defineLoop({
1195
1377
  const unapproved = unranAt.get(pipeline.head)
1196
1378
  const notRun = unapproved?.notRun ?? input.notRun ?? []
1197
1379
 
1380
+ const approvedBy = () => approvalOf.get(pipeline.head) ?? approvalRef(approved)
1381
+
1382
+ /** What full auto relies on to take its answer: the approval of the ChangeRequest head, and `head`. */
1383
+ const evidenceAt = (head: string) => {
1384
+ const review = approvedBy()
1385
+
1386
+ return { ...(review === undefined ? undefined : { review }), head }
1387
+ }
1388
+
1198
1389
  // A head with tests verify never ran merges only on a person's say.
1199
1390
  const merge =
1200
1391
  input.merge === true && notRun.length === 0
@@ -1215,18 +1406,27 @@ export default defineLoop({
1215
1406
  : 'Nobody has seen those tests pass, so run them by hand before it lands.',
1216
1407
  default: 'Wait',
1217
1408
  // A full-auto Team merges what its Review approved and its checks passed.
1218
- ...(notRun.length === 0 ? { auto: 'Merge' } : undefined),
1409
+ ...(notRun.length === 0 ? { auto: 'Merge', evidence: evidenceAt(pipeline.head) } : undefined),
1219
1410
  timeout: '1 hour'
1220
1411
  })
1221
1412
 
1222
- if (merge === 'Wait')
1223
- return done(
1224
- 'ready',
1225
- unapproved === undefined
1226
- ? 'Approved, green and mergeable; left for a person to merge'
1227
- : 'Reviewed, green and mergeable, but verify never ran some of its tests; left for a person to merge'
1413
+ if (merge === 'Wait') {
1414
+ const watched = yield* watchTarget(
1415
+ cycle,
1416
+ pipeline,
1417
+ done(
1418
+ 'ready',
1419
+ unapproved === undefined
1420
+ ? 'Approved, green and mergeable; left for a person to merge'
1421
+ : 'Reviewed, green and mergeable, but verify never ran some of its tests; left for a person to merge'
1422
+ )
1228
1423
  )
1229
1424
 
1425
+ if (watched.kind === 'stop') return watched.output
1426
+
1427
+ continue
1428
+ }
1429
+
1230
1430
  if (unapproved !== undefined) {
1231
1431
  const recorded = yield* approveChangeRequest(`head-approve:${cycle}`, {
1232
1432
  changeRequestId,
@@ -1242,6 +1442,8 @@ export default defineLoop({
1242
1442
  'needs_you',
1243
1443
  `The review of ${pipeline.head} passed, but did not approve it: ${recorded.reason}`
1244
1444
  )
1445
+
1446
+ approvalOf.set(pipeline.head, recorded.reviewId)
1245
1447
  }
1246
1448
 
1247
1449
  // A Run ahead of it merges first; its merge moves the target, which this merge then finds and catches up with.
@@ -1262,6 +1464,19 @@ export default defineLoop({
1262
1464
  yield* passTurn()
1263
1465
  yield* writeBack('write-back', { milestone: 'merged' })
1264
1466
 
1467
+ // A sub-task lands on its epic's branch, which only the epic's own ChangeRequest takes to Release.
1468
+ if (epic !== undefined && target === epic.branch) {
1469
+ const landing = yield* landEpicAfter(epic)
1470
+
1471
+ return {
1472
+ ...done(
1473
+ 'merged',
1474
+ `Merged into ${epic.branch} at ${merged.revision}; Release waits for epic ${epic.key} to land on ${epic.defaultBranch}`
1475
+ ),
1476
+ epicLanding: landing
1477
+ }
1478
+ }
1479
+
1265
1480
  // A Milestone's or Project's completion starts its Release; this merge does not, unless the Run says so.
1266
1481
  if (releaseWhen !== undefined && releaseWhen.trigger !== 'merge')
1267
1482
  return done(
@@ -1279,15 +1494,24 @@ export default defineLoop({
1279
1494
  recommendationReason: 'The merge is approved and green, so it is ready to ship.',
1280
1495
  default: 'Not now',
1281
1496
  auto: 'Release',
1497
+ evidence: evidenceAt(merged.revision),
1282
1498
  timeout: '1 hour'
1283
1499
  })
1284
1500
 
1285
1501
  if (ship === 'Not now') return done('merged', `Merged at ${merged.revision}`)
1286
1502
 
1503
+ const review = approvedBy()
1504
+
1287
1505
  const released = yield* call('release', release, {
1288
1506
  revision: merged.revision,
1507
+ ...(review === undefined ? undefined : { review }),
1289
1508
  // 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)
1509
+ ...(releaseWhen?.layer === 'run' ? { releaseTrigger: releaseWhen.trigger } : undefined),
1510
+ // A sub-task merged straight into the default branch ships past its unlanded epic; the epic's own merge
1511
+ // lands the epic, so its Release resolves the same layers.
1512
+ ...(epic !== undefined && epic.own !== true
1513
+ ? { deliveryTarget: 'default_branch' as const }
1514
+ : ownDeliveryTarget(input))
1291
1515
  })
1292
1516
 
1293
1517
  // A failed gate changed nothing in production, and the next merge's Release gates this revision with its own.
@@ -1316,8 +1540,9 @@ export default defineLoop({
1316
1540
  release: { runStatus: released.status, reason: released.reason }
1317
1541
  }
1318
1542
 
1319
- // It merged either way; a Release that did not deploy, other than one a person rejected or one that found it released, needs a person.
1543
+ // It merged either way; a Release that did not deploy needs a person, unless it was rejected, found it released or a person left it.
1320
1544
  if (
1545
+ released.leftUndeployed !== true &&
1321
1546
  released.status !== 'deployed' &&
1322
1547
  released.status !== 'rejected' &&
1323
1548
  released.status !== 'gate_failed' &&
package/src/sweep.ts CHANGED
@@ -186,7 +186,7 @@ const reportText = (landing: readonly Placed[], left: readonly Placed[], heading
186
186
  */
187
187
  export default defineLoop({
188
188
  id: 'sweep',
189
- version: '1.1.0',
189
+ version: '1.2.0',
190
190
  title: 'Sweep',
191
191
  input: Input,
192
192
  output: Output,
@@ -212,7 +212,20 @@ export default defineLoop({
212
212
  merge: notRun.length === 0,
213
213
  ...(notRun.length === 0 ? undefined : { notRun }),
214
214
  ...(input.branch === undefined ? undefined : { branch: input.branch })
215
- })
215
+ }).pipe(
216
+ Effect.catchTag('StepFailed', refused =>
217
+ refused.code === 'task_branch_busy' ? Effect.succeed({ held: refused.reason }) : Effect.fail(refused)
218
+ )
219
+ )
220
+
221
+ if ('held' in landed)
222
+ return {
223
+ status: 'opened',
224
+ summary: `${earlier.url}, from an earlier Sweep, is still open, and another Run works its branch, so Sweep left it to that Run: ${landed.held}`,
225
+ landed: [],
226
+ left: [],
227
+ changeRequest: { id: earlier.id, number: earlier.number, url: earlier.url }
228
+ } satisfies Output
216
229
 
217
230
  const summary = `${earlier.url}, from an earlier Sweep, is still open; Sweep took it on instead of batching again: ${landed.status}. ${landed.reason}`
218
231
  // Its description names what it supersedes, so merging it closes those as a fresh batch would.
@@ -1,11 +0,0 @@
1
- You are a deployer. Release has tagged a version, and you run the repository's own deploy script for it, once.
2
-
3
- ## Boundaries
4
-
5
- - Run only the command your brief names. Do not edit files, commit, push, tag, merge or retry it: the script backs up, publishes, deploys, verifies and rolls back by itself.
6
- - It runs for a long time. Start it once in the background with its output in a log file, and wait for it to exit.
7
- - Never print, copy or summarise the variables, tokens or secrets it pulls, or the production host's address.
8
-
9
- ## Output
10
-
11
- Submit your Output with the Kitman MCP `submit_output` tool, in the shape the brief's Output schema gives.