@kitman-sh/software-engineering 0.14.8 → 0.15.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
@@ -1,5 +1,5 @@
1
1
  import {
2
- agentWork,
2
+ agent,
3
3
  approveChangeRequest,
4
4
  artifact,
5
5
  ask,
@@ -18,11 +18,17 @@ import {
18
18
  type Severity,
19
19
  resolveRevisions,
20
20
  ResolvedDeliveryTarget,
21
+ ReviewRoleInput,
22
+ ReviewRoleOutput,
21
23
  ScopeJudgement,
22
- settleRound
24
+ settleRound,
25
+ step
23
26
  } from '@kitman-sh/sdk/loop'
27
+ import type * as Arr from 'effect/Array'
28
+ import * as Context from 'effect/Context'
24
29
  import * as Effect from 'effect/Effect'
25
30
  import * as Schema from 'effect/Schema'
31
+ import * as Struct from 'effect/Struct'
26
32
  import build, { BuildInput, BuildOutput } from './build'
27
33
  import { verifyHead } from './change-request-body'
28
34
  import { DeliveryFields, ownDeliveryTarget } from './delivery'
@@ -33,20 +39,46 @@ import { FindingDetail, OneSentence, ShortStatement } from './text-limits'
33
39
  /** Build, by its schemas: the module imports this one, so its definition is not ready when this one loads. */
34
40
  const buildLoop = () => ({ id: 'build', input: BuildInput, output: BuildOutput })
35
41
 
36
- /** The two reviewers: each follows one Kit's review skill, and what it looks for when that skill is not installed. */
37
- const seats = {
38
- 'code-review': {
42
+ /** A reviewer: its role in the Loop's `agents`, its skill, and what it looks for when that skill is not installed. */
43
+ export const ReviewSeat = Schema.Struct({
44
+ name: Schema.String.annotate({ description: "The seat's role in `agents`, which names its findings." }),
45
+ skill: Schema.String,
46
+ focus: Schema.String
47
+ })
48
+
49
+ export type ReviewSeat = typeof ReviewSeat.Type
50
+
51
+ export const reviewSeats: Arr.NonEmptyReadonlyArray<ReviewSeat> = [
52
+ {
53
+ name: 'code-review',
39
54
  skill: 'code-review',
40
55
  focus:
41
56
  "Review along two axes: Standards (does the change follow the repository's documented conventions?) and Spec (does it do what was asked?)."
42
57
  },
43
- quality: {
58
+ {
59
+ name: 'quality',
44
60
  skill: 'code-review-and-quality',
45
61
  focus: 'Review across correctness, readability, architecture, security and performance.'
46
62
  }
47
- } as const
63
+ ]
48
64
 
49
- const seatNames = ['code-review', 'quality'] as const
65
+ /** The seats a Review asks; a fork adds one, or replaces one by its name, with `Layer.succeed` in `provide`. */
66
+ export const ReviewSeats = Context.Reference<Arr.NonEmptyReadonlyArray<ReviewSeat>>(
67
+ '@kitman-sh/software-engineering/ReviewSeats',
68
+ { defaultValue: () => reviewSeats }
69
+ )
70
+
71
+ /**
72
+ * The seats, one a name, the last of a name winning, as a seat's name keys its visit and its findings. A fix the scope
73
+ * seat alone reviews, when the panel has it.
74
+ */
75
+ const panelFor = (input: typeof Input.Type) =>
76
+ Effect.map(Effect.service(ReviewSeats), seats => {
77
+ const named = [...new Map(seats.map(seat => [seat.name, seat])).values()]
78
+ const scoping = named.filter(seat => seat.name === scopeSeat)
79
+
80
+ return fixRound(input) && scoping.length > 0 ? scoping : named
81
+ })
50
82
 
51
83
  /** The seat that judges the Task's scope, and the only one that reviews a fix. */
52
84
  const scopeSeat = 'code-review'
@@ -54,61 +86,77 @@ const scopeSeat = 'code-review'
54
86
  const choices = ['Post to the ChangeRequest', 'Fix here', 'Build from it', 'Done'] as const
55
87
 
56
88
  const Input = Schema.Struct({
57
- /** Reviews this ChangeRequest, then asks what next: posting, fixing and building are each the user's call. */
58
- changeRequestId: Schema.optional(Schema.String),
59
- /** With `base` and `head`, the ChangeRequest the change delivers: Kitman gives its Task's Out of scope list only if that ChangeRequest delivers the Task. */
60
- deliveredBy: Schema.optional(Schema.String),
61
- /** Or reviews `git diff base...head`, and only returns the findings. */
62
- base: Schema.optional(Schema.String),
63
- head: Schema.optional(Schema.String),
64
- /**
65
- * With `base` and `head`, reviews only these files of the change, such as the conflicts a catch-up merge settled; the
66
- * rest was approved before. A review of a fix counts whatever changed in them since as the fix. It judges no scope and
67
- * approves nothing itself.
68
- */
69
- files: Schema.optional(Schema.Array(Schema.String)),
70
- /**
71
- * With `files`, also reviews everything in `git diff since..head`, such as a fix made after the files' review; in a
72
- * review of a fix, only where the fix starts when `reviewed` does not say.
73
- */
74
- since: Schema.optional(Schema.String),
75
- /**
76
- * With `base` and `head`, the last approved head: reviews only what the change gained or lost since then, or only the
77
- * fix in a review of one, judges no scope, and keeps findings about code that head already had apart, where they do
78
- * not block.
79
- */
80
- approved: Schema.optional(Schema.String),
81
- /** The implementer's rebuttals of the last round's findings, for the panel to judge. */
82
- rebuttals: Schema.optional(Schema.Array(Rebuttal)),
83
- /** The Outcome the change must prove. */
84
- outcome: Schema.optional(LoopOutcome),
85
- /** What the implementer claims it built, for the scope seat to check. */
86
- claims: Schema.optional(Schema.Array(Schema.String)),
87
- /** An earlier review's open findings: each is checked as fixed, changed or still there, keeping its id. */
88
- earlier: Schema.optional(Schema.Array(MergedFinding)),
89
- /**
90
- * The head an earlier review of this change read. With it or `earlier`, only the `code-review` seat runs, on the fix,
91
- * as `git diff reviewed..head`, and a new finding outside the fix blocks only as a blocker.
92
- */
93
- reviewed: Schema.optional(Schema.String),
94
- /** In a review of a fix, the earlier review's scope judgement: what it found unmet is judged again. */
95
- scope: Schema.optional(ReviewedScope),
96
- /** The checks that fail on the head and pass on the base, which the implementer is already told. */
97
- failing: Schema.optional(Schema.Array(Schema.String)),
98
- /** Why each head test verify never ran is unverified; a ChangeRequest's head is verified here too. */
99
- notRun: Schema.optional(Schema.Array(Schema.String)),
100
- /** Earlier reviews' findings kept apart as out of scope; one whose case the Task no longer lists is open again. */
101
- outOfScopeFindings: Schema.optional(Schema.Array(OutOfScopeFinding)),
102
- /** The acceptance criteria the implementer answered not met, in its words, for the scope seat to judge. */
103
- unmetCriteria: Schema.optional(Schema.Array(Schema.String)),
104
- /** The other acceptance criteria, in the implementer's words, numbered after those so the scope seat can name one it finds not done. */
105
- metCriteria: Schema.optional(Schema.Array(Schema.String)),
106
- /** The criteria the implementer answered can only be seen once merged, in its words, numbered after the met ones. */
107
- afterMergeCriteria: Schema.optional(Schema.Array(Schema.String)),
108
- /** The Task's Out of scope list, the only cases a finding or unmet part may be waived for; Kitman sets it when the Run starts. */
109
- taskOutOfScope: Schema.optional(Schema.Array(Schema.String)),
110
- /** What to do after a ChangeRequest's review without asking; Done when nobody answers. */
111
- next: Schema.optional(Schema.Literals(choices)),
89
+ ...ReviewRoleInput.fields,
90
+ changeRequestId: Schema.optional(Schema.String).annotate({
91
+ description:
92
+ "Reviews this ChangeRequest, then asks what next: posting, fixing and building are each the user's call."
93
+ }),
94
+ deliveredBy: Schema.optional(Schema.String).annotate({
95
+ description:
96
+ "With `base` and `head`, the ChangeRequest the change delivers: Kitman gives its Task's Out of scope list only if that ChangeRequest delivers the Task."
97
+ }),
98
+ base: Schema.optional(Schema.String).annotate({
99
+ description:
100
+ 'With `head`, reviews `git diff base...head` instead of a ChangeRequest, and only returns the findings.'
101
+ }),
102
+ head: Schema.optional(Schema.String).annotate({ description: 'With `base`, the head of the change to review.' }),
103
+ files: Schema.optional(Schema.Array(Schema.String)).annotate({
104
+ description:
105
+ 'With `base` and `head`, reviews only these files of the change, such as the conflicts a catch-up merge settled; the rest was approved before. A review of a fix counts whatever changed in them since as the fix. It judges no scope and approves nothing itself.'
106
+ }),
107
+ since: Schema.optional(Schema.String).annotate({
108
+ description:
109
+ "With `files`, also reviews everything in `git diff since..head`, such as a fix made after the files' review; in a review of a fix, only where the fix starts when `reviewed` does not say."
110
+ }),
111
+ approved: Schema.optional(Schema.String).annotate({
112
+ description:
113
+ 'With `base` and `head`, the last approved head: reviews only what the change gained or lost since then, or only the fix in a review of one, judges no scope, and keeps findings about code that head already had apart, where they do not block.'
114
+ }),
115
+ rebuttals: Schema.optional(Schema.Array(Rebuttal)).annotate({
116
+ description: "The implementer's rebuttals of the last round's findings, for the panel to judge."
117
+ }),
118
+ outcome: Schema.optional(LoopOutcome).annotate({ description: 'The Outcome the change must prove.' }),
119
+ claims: Schema.optional(Schema.Array(Schema.String)).annotate({
120
+ description: 'What the implementer claims it built, for the scope seat to check.'
121
+ }),
122
+ earlier: Schema.optional(Schema.Array(MergedFinding)).annotate({
123
+ description: "An earlier review's open findings: each is checked as fixed, changed or still there, keeping its id."
124
+ }),
125
+ reviewed: Schema.optional(Schema.String).annotate({
126
+ description:
127
+ 'The head an earlier review of this change read. With it or `earlier`, only the `code-review` seat runs, on the fix, as `git diff reviewed..head`, and a new finding outside the fix blocks only as a blocker.'
128
+ }),
129
+ scope: Schema.optional(ReviewedScope).annotate({
130
+ description: "In a review of a fix, the earlier review's scope judgement: what it found unmet is judged again."
131
+ }),
132
+ failing: Schema.optional(Schema.Array(Schema.String)).annotate({
133
+ description: 'The checks that fail on the head and pass on the base, which the implementer is already told.'
134
+ }),
135
+ notRun: Schema.optional(Schema.Array(Schema.String)).annotate({
136
+ description: "Why each head test verify never ran is unverified; a ChangeRequest's head is verified here too."
137
+ }),
138
+ outOfScopeFindings: Schema.optional(Schema.Array(OutOfScopeFinding)).annotate({
139
+ description:
140
+ "Earlier reviews' findings kept apart as out of scope; one whose case the Task no longer lists is open again."
141
+ }),
142
+ unmetCriteria: Schema.optional(Schema.Array(Schema.String)).annotate({
143
+ description: 'The acceptance criteria the implementer answered not met, in its words, for the scope seat to judge.'
144
+ }),
145
+ metCriteria: Schema.optional(Schema.Array(Schema.String)).annotate({
146
+ description:
147
+ "The other acceptance criteria, in the implementer's words, numbered after those so the scope seat can name one it finds not done."
148
+ }),
149
+ afterMergeCriteria: Schema.optional(Schema.Array(Schema.String)).annotate({
150
+ description:
151
+ 'The criteria the implementer answered can only be seen once merged, in its words, numbered after the met ones.'
152
+ }),
153
+ taskOutOfScope: Schema.optional(Schema.Array(Schema.String)).annotate({
154
+ description:
155
+ "The Task's Out of scope list, the only cases a finding or unmet part may be waived for; Kitman sets it when the Run starts."
156
+ }),
157
+ next: Schema.optional(Schema.Literals(choices)).annotate({
158
+ description: "What to do after a ChangeRequest's review without asking; Done when nobody answers."
159
+ }),
112
160
  ...DeliveryFields
113
161
  })
114
162
 
@@ -329,7 +377,7 @@ const carriedScope = (
329
377
  return reported.length === 0 ? rest : { ...rest, reported }
330
378
  }
331
379
 
332
- const SeatOutput = Schema.Struct({
380
+ export const SeatOutput = Schema.Struct({
333
381
  /** One sentence: can it merge, and what matters most. */
334
382
  summary: OneSentence,
335
383
  findings: Schema.Array(SeatFinding),
@@ -346,34 +394,49 @@ const ApprovedFinding = Schema.Struct({
346
394
 
347
395
  type ApprovedFinding = typeof ApprovedFinding.Type
348
396
 
349
- const Output = Schema.Struct({
350
- /** What the review leads with: each reviewer's one sentence. */
351
- summary: Schema.String,
352
- findings: Schema.Array(MergedFinding),
353
- /**
354
- * In a review since an approved head, the findings about code that head already had; they never block. One in a case
355
- * the Task lists as Out of scope keeps its case as `item`, at its own severity.
356
- */
357
- approvedFindings: Schema.optional(Schema.Array(ApprovedFinding)),
358
- /** The majors and minors in cases the Task lists as Out of scope, earlier reviews' among them; they never block. */
359
- outOfScopeFindings: Schema.optional(Schema.Array(OutOfScopeFinding)),
360
- /** Each earlier finding, as fixed, changed but not fixed, or still there. */
361
- followUps: Schema.Array(FollowUp),
362
- verdicts: Schema.Array(RebuttalVerdict),
363
- blocking: Schema.Boolean,
364
- artifactId: Schema.String,
365
- /** The scope seat's judgement of the Task's scope; absent when there was no Task to judge against. */
366
- scope: Schema.optional(ReviewedScope),
367
- /** The checks that fail on the head, given or verified here; the head is not ready while any does. */
368
- failing: Schema.optional(Schema.Array(Schema.String)),
369
- /** Kitman's approval of the ChangeRequest's head, recorded when nothing blocks it; or why it was refused. */
397
+ /** What a review found and whether it was approved, which its Output gives with what happened next. */
398
+ const reviewedFields = {
399
+ ...ReviewRoleOutput.fields,
400
+ summary: Schema.String.annotate({ description: "What the review leads with: each reviewer's one sentence." }),
401
+ findings: Schema.Array(MergedFinding).annotate({ description: "The panel's findings, merged across reviewers." }),
402
+ approvedFindings: Schema.optional(Schema.Array(ApprovedFinding)).annotate({
403
+ description:
404
+ 'In a review since an approved head, the findings about code that head already had; they never block. One in a case the Task lists as Out of scope keeps its case as `item`, at its own severity.'
405
+ }),
406
+ outOfScopeFindings: Schema.optional(Schema.Array(OutOfScopeFinding)).annotate({
407
+ description:
408
+ "The majors and minors in cases the Task lists as Out of scope, earlier reviews' among them; they never block."
409
+ }),
410
+ followUps: Schema.Array(FollowUp).annotate({
411
+ description: 'Each earlier finding, as fixed, changed but not fixed, or still there.'
412
+ }),
413
+ verdicts: Schema.Array(RebuttalVerdict).annotate({
414
+ description: "The panel's verdict on each rebuttal: accepted or not."
415
+ }),
416
+ blocking: Schema.Boolean.annotate({ description: 'Whether any finding blocks the change.' }),
417
+ artifactId: Schema.String.annotate({ description: 'The Artifact holding the review.' }),
418
+ scope: Schema.optional(ReviewedScope).annotate({
419
+ description: "The scope seat's judgement of the Task's scope; absent when there was no Task to judge against."
420
+ }),
421
+ failing: Schema.optional(Schema.Array(Schema.String)).annotate({
422
+ description: 'The checks that fail on the head, given or verified here; the head is not ready while any does.'
423
+ }),
370
424
  approval: Schema.optional(
371
425
  Schema.Struct({ head: Schema.String, approved: Schema.Boolean, reason: Schema.optional(Schema.String) })
372
- ),
373
- /** What happened after a ChangeRequest's review. */
374
- next: Schema.optional(Schema.Struct({ choice: Schema.Literals(choices), detail: Schema.optional(Schema.String) })),
375
- /** Where the reviewed delivery lands and the layer it came from. */
376
- deliversTo: Schema.optional(ResolvedDeliveryTarget)
426
+ ).annotate({
427
+ description:
428
+ "Kitman's approval of the ChangeRequest's head, recorded when nothing blocks it; or why it was refused."
429
+ })
430
+ }
431
+
432
+ const Output = Schema.Struct({
433
+ ...reviewedFields,
434
+ next: Schema.optional(
435
+ Schema.Struct({ choice: Schema.Literals(choices), detail: Schema.optional(Schema.String) })
436
+ ).annotate({ description: "What happened after a ChangeRequest's review." }),
437
+ deliversTo: Schema.optional(ResolvedDeliveryTarget).annotate({
438
+ description: 'Where the reviewed delivery lands and the layer it came from.'
439
+ })
377
440
  })
378
441
 
379
442
  export class ReviewTargetMissing extends Schema.TaggedError<ReviewTargetMissing>()('ReviewTargetMissing', {
@@ -391,19 +454,47 @@ export class ReviewBaseUnpinned extends Schema.TaggedError<ReviewBaseUnpinned>()
391
454
  }) {}
392
455
 
393
456
  /** The commits a review diffs, `git diff base...head`, resolved once so every seat reads the same diff. */
394
- type Range = {
395
- readonly base: string
396
- readonly head: string
457
+ export class Ranged extends Schema.TaggedClass<Ranged>()('Ranged', {
458
+ base: Schema.String,
459
+ head: Schema.String,
397
460
  /** A ChangeRequest's branches, which its reviewers are told so they need not look it up. */
398
- readonly branches?: { readonly source: string | undefined; readonly target: string }
461
+ branches: Schema.optionalKey(Schema.Struct({ source: Schema.optionalKey(Schema.String), target: Schema.String })),
399
462
  /** The epic branch and default branch it diffs, when the review is of an epic's whole change. */
400
- readonly epic?: { readonly branch: string; readonly defaultBranch: string }
463
+ epic: Schema.optionalKey(Schema.Struct({ branch: Schema.String, defaultBranch: Schema.String }))
464
+ }) {}
465
+
466
+ /** The checks that fail on the head, and why each head test verify never ran is unverified. */
467
+ export class Checked extends Schema.TaggedClass<Checked>()('Checked', {
468
+ failing: Schema.Array(Schema.String),
469
+ notRun: Schema.Array(Schema.String)
470
+ }) {}
471
+
472
+ /** The review of every seat's findings, stored. */
473
+ export class Reviewed extends Schema.TaggedClass<Reviewed>()('Reviewed', {
474
+ ...reviewedFields,
475
+ fresh: Schema.Array(Schema.String).annotate({ description: 'The ids of the findings no earlier review raised.' })
476
+ }) {}
477
+
478
+ const followUp = {
479
+ choice: Schema.Literals(choices),
480
+ detail: Schema.optionalKey(Schema.String)
401
481
  }
402
482
 
483
+ export class Posted extends Schema.TaggedClass<Posted>()('Posted', followUp) {}
484
+
485
+ /** A Build pushed its fixes to the ChangeRequest. */
486
+ export class Fixed extends Schema.TaggedClass<Fixed>()('Fixed', followUp) {}
487
+
488
+ /** A Build fixed it in a new ChangeRequest. */
489
+ export class Built extends Schema.TaggedClass<Built>()('Built', followUp) {}
490
+
491
+ /** Nothing was posted, fixed or built; `detail` says why when the chosen Build failed. */
492
+ export class Done extends Schema.TaggedClass<Done>()('Done', followUp) {}
493
+
403
494
  const unfetchable = (head: string) =>
404
495
  `If the Runner cannot fetch revision ${head} (a fork, say), report exactly that as your only finding, a blocker, and stop.`
405
496
 
406
- const targetOf = (input: typeof Input.Type, { base, head, branches, epic }: Range) => {
497
+ const targetOf = (input: typeof Input.Type, { base, head, branches, epic }: Ranged) => {
407
498
  if (epic !== undefined)
408
499
  return `the epic's whole change \`git diff ${base}...${head}\` in your checkout: epic branch \`${epic.branch}\` against default branch \`${epic.defaultBranch}\`, as they stood when this review started. Fetch both from \`origin\` and diff exactly those commits, even if either branch has moved since.`
409
500
 
@@ -448,18 +539,21 @@ const pinnedRange = (input: typeof Input.Type) =>
448
539
 
449
540
  const [base = ''] = yield* resolveRevisions('pin', [`origin/${status.targetBranch}`])
450
541
 
451
- return {
542
+ return new Ranged({
452
543
  base,
453
544
  head: status.head.toLowerCase(),
454
- branches: { source: status.sourceBranch, target: status.targetBranch }
455
- }
545
+ branches: {
546
+ ...(status.sourceBranch === undefined ? undefined : { source: status.sourceBranch }),
547
+ target: status.targetBranch
548
+ }
549
+ })
456
550
  }
457
551
 
458
552
  if ((input.base === undefined || input.head === undefined) && input.epic !== undefined) {
459
553
  const { branch, defaultBranch } = input.epic
460
554
  const [base = '', head = ''] = yield* resolveRevisions('pin', [`origin/${defaultBranch}`, `origin/${branch}`])
461
555
 
462
- return { base, head, epic: { branch, defaultBranch } }
556
+ return new Ranged({ base, head, epic: { branch, defaultBranch } })
463
557
  }
464
558
 
465
559
  if (input.base === undefined || input.head === undefined)
@@ -467,7 +561,7 @@ const pinnedRange = (input: typeof Input.Type) =>
467
561
 
468
562
  const [base = '', head = ''] = yield* resolveRevisions('pin', [input.base, input.head])
469
563
 
470
- return { base, head }
564
+ return new Ranged({ base, head })
471
565
  })
472
566
 
473
567
  /** A review of the whole change judges its scope; one of some files or of a change since an approval does not. */
@@ -657,7 +751,7 @@ const outsideFixPrompt = (cases: readonly string[]) =>
657
751
  ].join(' ')
658
752
 
659
753
  /** The fix a review of one reads, in place of the change `targetOf` names. */
660
- const fixTargetOf = (input: typeof Input.Type, { head, branches, epic }: Range) => {
754
+ const fixTargetOf = (input: typeof Input.Type, { head, branches, epic }: Ranged) => {
661
755
  const from = input.reviewed ?? (input.files === undefined ? undefined : input.since)
662
756
  const branch = branches === undefined ? epic?.branch : (branches.source ?? head)
663
757
 
@@ -688,25 +782,29 @@ const fixTargetOf = (input: typeof Input.Type, { head, branches, epic }: Range)
688
782
  ].join('\n\n')
689
783
  }
690
784
 
785
+ const panelOf = (reviewers: number, fixing: boolean) =>
786
+ reviewers === 1
787
+ ? `You are the only reviewer${fixing ? ' of this round' : ''}.`
788
+ : `You are one of ${reviewers === 2 ? 'two' : reviewers} reviewers.`
789
+
691
790
  const promptFor = (
692
- seat: keyof typeof seats,
693
- target: string,
791
+ seat: ReviewSeat,
792
+ reviewers: number,
793
+ range: Ranged,
694
794
  input: typeof Input.Type,
695
- earlier: readonly MergedFinding[],
696
- failing: readonly string[],
697
- notRun: readonly string[]
795
+ { failing, notRun }: Checked
698
796
  ) =>
699
797
  [
700
- `You are ${fixRound(input) ? 'the only reviewer of this round' : 'one of two reviewers'}. Follow your \`${seats[seat].skill}\` skill; if you do not have it: ${seats[seat].focus}`,
701
- `Review ${target}`,
798
+ `${panelOf(reviewers, fixRound(input))} Follow your \`${seat.skill}\` skill; if you do not have it: ${seat.focus}`,
799
+ `Review ${fixRound(input) ? fixTargetOf(input, range) : targetOf(input, range)}`,
702
800
  'Give `summary`: one sentence on whether it can merge and what matters most.',
703
801
  'Report each problem as a finding: severity blocker (must not ship), major (fix before merge) or minor (optional); the file path from the repository root; the line; and the detail. When it is one instance of a class of bug, name every other instance in the diff in its detail. Report nothing you have not checked in the code.',
704
802
  exhaustivePrompt(fixRound(input) ? 'the fix' : 'the change'),
705
803
  "What an answer under your brief's Answers so far put out of scope is reported, not missing: do not report it as a finding.",
706
804
  ...(casesOf(input).length === 0 ? [] : [outOfScopePrompt(casesOf(input))]),
707
805
  'If the diff is too big to review in one go, review it directory by directory and say so in a finding on the first file you skipped.',
708
- ...(seat === scopeSeat && wholeChange(input) ? [scopePrompt(input)] : []),
709
- ...(earlier.length === 0 ? [] : [earlierPrompt(earlier, casesOf(input))]),
806
+ ...(seat.name === scopeSeat && wholeChange(input) ? [scopePrompt(input)] : []),
807
+ ...(earlierOf(input).length === 0 ? [] : [earlierPrompt(earlierOf(input), casesOf(input))]),
710
808
  ...(fixRound(input) ? [outsideFixPrompt(casesOf(input))] : []),
711
809
  ...(failing.length === 0
712
810
  ? []
@@ -1009,18 +1107,24 @@ const findingLines = (findings: readonly MergedFinding[]) =>
1009
1107
  .map(finding => `- **${finding.severity}** \`${finding.id}\` ${finding.detail} _(${finding.seats.join(', ')})_`)
1010
1108
  .join('\n')
1011
1109
 
1110
+ type ReviewedParts = Pick<
1111
+ Reviewed,
1112
+ 'summary' | 'findings' | 'followUps' | 'approvedFindings' | 'outOfScopeFindings' | 'scope'
1113
+ >
1114
+
1115
+ /** The review as it is stored and posted. */
1012
1116
  const reviewText = (
1013
- summary: string,
1014
- findings: readonly MergedFinding[],
1015
- followUps: readonly (typeof FollowUp.Type)[],
1016
- approvedFindings: readonly ApprovedFinding[],
1017
- outOfScopeFindings: readonly MergedFinding[],
1018
- notRun: readonly string[],
1019
- scope: ReviewedScope | undefined
1117
+ { summary, findings, followUps, approvedFindings = [], outOfScopeFindings = [], scope }: ReviewedParts,
1118
+ notRun: readonly string[]
1020
1119
  ) => {
1021
1120
  const reported = scope?.reported ?? []
1022
1121
  const outOfScope = scope?.outOfScope ?? []
1023
1122
 
1123
+ const shownOutOfScope = outOfScopeFindings.map(finding => ({
1124
+ ...finding,
1125
+ detail: inCase(finding.detail, finding.item)
1126
+ }))
1127
+
1024
1128
  return [
1025
1129
  `**Kitman review.** ${summary}`,
1026
1130
  ...(reported.length === 0
@@ -1039,13 +1143,13 @@ const reviewText = (
1039
1143
  )
1040
1144
  )}`
1041
1145
  ]),
1042
- ...(outOfScope.length + outOfScopeFindings.length === 0
1146
+ ...(outOfScope.length + shownOutOfScope.length === 0
1043
1147
  ? []
1044
1148
  : [
1045
1149
  [
1046
1150
  'In a case the Task lists as Out of scope, so reported, not blocking:',
1047
1151
  ...outOfScope.map(({ part, item }) => `- ${inCase(part, item)}`),
1048
- ...(outOfScopeFindings.length === 0 ? [] : [findingLines(outOfScopeFindings)])
1152
+ ...(shownOutOfScope.length === 0 ? [] : [findingLines(shownOutOfScope)])
1049
1153
  ].join('\n')
1050
1154
  ]),
1051
1155
  ...(followUps.length === 0
@@ -1063,82 +1167,92 @@ const fixBrief = (changeRequestId: string, findings: readonly MergedFinding[], u
1063
1167
  ...(unmet.length === 0 ? [] : ['Do what it found unmet:', ...unmet.map(item => `- ${item}`)])
1064
1168
  ].join('\n')
1065
1169
 
1066
- /**
1067
- * Reviews a ChangeRequest or a revision range with two reviewer Agents, one following the `code-review` skill and one
1068
- * `code-review-and-quality`, and writes one review from their findings, each said once. It first resolves the base and
1069
- * head to commits on a Runner, so every reviewer reads one diff, and fails when they are one commit. Given an earlier
1070
- * review's findings or the head it read, the `code-review` reviewer alone reviews the fix and follows the findings up,
1071
- * keeping their ids. On a ChangeRequest it verifies the head it reviews against the ChangeRequest's target and approves
1072
- * it when nothing blocks it, none of its checks broke and verify ran all of its tests, unless it wrote the change, then
1073
- * asks what next and posts only when told to, as one summary comment it edits on later reviews.
1074
- */
1075
- export default defineLoop({
1076
- id: 'review',
1077
- version: '3.11.0',
1078
- title: 'Review',
1170
+ const reviewing = {
1079
1171
  input: Input,
1080
- output: Output,
1081
- agents: { 'code-review': 'code-reviewer', quality: 'quality-reviewer' },
1082
- checkout: 'read',
1083
- // Build's, for Fix here and Build from it.
1084
- capabilities: [
1085
- 'agent_work',
1086
- 'post_comment',
1087
- 'ask',
1088
- 'call',
1089
- 'verify',
1090
- 'change_request',
1091
- 'write_back',
1092
- 'read_change_request',
1093
- 'merge_change_request',
1094
- 'approve_change_request'
1095
- ],
1096
- calls: (): readonly CalledLoop[] => [build],
1097
- offers: [
1098
- { id: 'build', title: 'Build from it', loop: 'build' },
1099
- { id: 'review', title: 'Review again', loop: 'review' }
1100
- ],
1101
- run: input =>
1172
+ range: Ranged.annotate({ description: 'The commits the review diffs.' }),
1173
+ checks: Checked.annotate({ description: "The head's checks." })
1174
+ }
1175
+
1176
+ /** Pins the commits the review diffs, before anything reads them, so an approval approves the head the seats read. */
1177
+ export const ranged = step('ranged', {
1178
+ payload: { input: Input },
1179
+ success: Ranged,
1180
+ error: Schema.Union([ReviewTargetMissing, ReviewBaseUnpinned, ReviewDiffEmpty]),
1181
+ run: ({ input }) =>
1102
1182
  Effect.gen(function* () {
1103
- // The head is read first, so an approval approves the commit the reviewers read.
1104
1183
  const range = yield* pinnedRange(input)
1105
- const head = input.changeRequestId === undefined ? undefined : range.head
1106
1184
 
1107
1185
  if (range.base === range.head)
1108
1186
  return yield* new ReviewDiffEmpty({
1109
1187
  message: `Base and head are both commit ${range.head}, so the diff is empty: give the base the change is to merge into`
1110
1188
  })
1111
1189
 
1112
- const target = fixRound(input) ? fixTargetOf(input, range) : targetOf(input, range)
1190
+ return range
1191
+ })
1192
+ })
1113
1193
 
1114
- // Evidence Kitman holds for the head's tree is reused.
1115
- const verified = head === undefined ? { failing: [], notRun: [] } : yield* verifyHead('verify', head)
1194
+ /** Verifies a ChangeRequest's head, reusing the evidence Kitman holds for its tree, beside the checks its caller names. */
1195
+ export const checked = step('checked', {
1196
+ payload: { input: Input, range: reviewing.range },
1197
+ success: Checked,
1198
+ run: ({ input, range }) =>
1199
+ Effect.gen(function* () {
1200
+ const verified =
1201
+ input.changeRequestId === undefined ? { failing: [], notRun: [] } : yield* verifyHead('verify', range.head)
1116
1202
 
1117
- const failing = [...new Set([...(input.failing ?? []), ...verified.failing])]
1118
- const notRun = [...new Set([...(input.notRun ?? []), ...verified.notRun])]
1203
+ return new Checked({
1204
+ failing: [...new Set([...(input.failing ?? []), ...verified.failing])],
1205
+ notRun: [...new Set([...(input.notRun ?? []), ...verified.notRun])]
1206
+ })
1207
+ })
1208
+ })
1119
1209
 
1120
- const earlier = earlierOf(input)
1210
+ export const seated = step('seated', {
1211
+ payload: {
1212
+ ...reviewing,
1213
+ seat: ReviewSeat,
1214
+ reviewers: Schema.Int.annotate({ description: 'How many seats review.' })
1215
+ },
1216
+ success: SeatOutput,
1217
+ key: ({ seat }) => seat.name,
1218
+ run: ({ input, range, checks, seat, reviewers }) =>
1219
+ Effect.gen(function* () {
1220
+ const review = yield* agent(seat.name)('review', {
1221
+ prompt: promptFor(seat, reviewers, range, input, checks),
1222
+ output: SeatOutput
1223
+ })
1121
1224
 
1122
- const outputs = yield* Effect.forEach(
1123
- fixRound(input) ? ([scopeSeat] as const) : seatNames,
1124
- seat =>
1125
- agentWork(`review:${seat}`, {
1126
- agent: seat,
1127
- prompt: promptFor(seat, target, input, earlier, failing, notRun),
1128
- output: SeatOutput
1129
- }).pipe(Effect.map(output => [seat, output] as const)),
1130
- { concurrency: 'unbounded' }
1131
- )
1225
+ return review
1226
+ })
1227
+ })
1132
1228
 
1229
+ /**
1230
+ * Merges the seats' findings into one review, carries and withdraws an earlier review's, stores it, and approves a
1231
+ * ChangeRequest's head that nothing blocks.
1232
+ */
1233
+ export const judged = step('judged', {
1234
+ payload: {
1235
+ ...reviewing,
1236
+ outputs: Schema.Array(Schema.Struct({ seat: Schema.String, output: SeatOutput })).annotate({
1237
+ description: "Each seat's review, in the seats' order."
1238
+ })
1239
+ },
1240
+ success: Reviewed,
1241
+ run: ({ input, range, checks: { failing, notRun }, outputs }) =>
1242
+ Effect.gen(function* () {
1243
+ const earlier = earlierOf(input)
1133
1244
  const cases = casesOf(input)
1134
1245
  const earlierById = new Map(earlier.map(finding => [finding.id, finding]))
1135
1246
 
1136
- const answers = outputs.flatMap(([seat, output]) => (output.followUps ?? []).map(answer => ({ ...answer, seat })))
1247
+ const answers = outputs.flatMap(({ seat, output }) =>
1248
+ (output.followUps ?? []).map(answer => ({ ...answer, seat }))
1249
+ )
1250
+
1137
1251
  const answered = followUpsOf(earlier, answers)
1138
1252
 
1139
1253
  const standing = new Set(answered.flatMap(entry => (entry.status === 'fixed' ? [] : [entry.id])))
1140
1254
 
1141
- const given = outputs.flatMap(([, output]) => output.verdicts ?? [])
1255
+ const given = outputs.flatMap(({ output }) => output.verdicts ?? [])
1142
1256
 
1143
1257
  const settled = settleRound({ findings: earlier, rebuttals: input.rebuttals ?? [], verdicts: given })
1144
1258
 
@@ -1227,7 +1341,7 @@ export default defineLoop({
1227
1341
 
1228
1342
  const seatFindings = (holds: (finding: SeatFinding) => boolean) =>
1229
1343
  Object.fromEntries(
1230
- outputs.map(([seat, output]) => [
1344
+ outputs.map(({ seat, output }) => [
1231
1345
  seat,
1232
1346
  output.findings
1233
1347
  .map(finding => (fixRound(input) && !keepsSeverity(finding) ? outsideFixAsMinor(finding) : finding))
@@ -1301,10 +1415,13 @@ export default defineLoop({
1301
1415
  )
1302
1416
 
1303
1417
  const blockers = findings.filter(isBlocking)
1304
- const judged = outputs.find(([seat]) => seat === scopeSeat)?.[1].scope
1418
+ const judgedScope = outputs.find(({ seat }) => seat === scopeSeat)?.output.scope
1305
1419
 
1306
1420
  const scope = wholeChange(input)
1307
- ? withUnjudged(carriedScope(judged, earlierScope(input), cases, criteriaOf(input)), requiredCriteriaOf(input))
1421
+ ? withUnjudged(
1422
+ carriedScope(judgedScope, earlierScope(input), cases, criteriaOf(input)),
1423
+ requiredCriteriaOf(input)
1424
+ )
1308
1425
  : undefined
1309
1426
 
1310
1427
  // A seat's own summary is kept only when nothing blocks, so it cannot contradict the verdict.
@@ -1323,24 +1440,25 @@ export default defineLoop({
1323
1440
  : outOfScopeFindings.length > 0
1324
1441
  ? 'No findings in scope: nothing stands in the way of merging.'
1325
1442
  : 'No findings: nothing stands in the way of merging.'
1326
- : ['Can merge: nothing blocks it.', ...outputs.map(([, output]) => output.summary)].join(' ')
1327
-
1328
- const shownOutOfScope = outOfScopeFindings.map(finding => ({
1329
- ...finding,
1330
- detail: inCase(finding.detail, finding.item)
1331
- }))
1332
-
1333
- const text = reviewText(summary, findings, followUps, approvedFindings, shownOutOfScope, notRun, scope)
1443
+ : ['Can merge: nothing blocks it.', ...outputs.map(({ output }) => output.summary)].join(' ')
1334
1444
 
1335
1445
  const apart = {
1336
1446
  ...(approvedFindings.length === 0 ? undefined : { approvedFindings }),
1337
1447
  ...(outOfScopeFindings.length === 0 ? undefined : { outOfScopeFindings })
1338
1448
  }
1339
1449
 
1450
+ const parts: ReviewedParts = {
1451
+ summary,
1452
+ findings,
1453
+ followUps,
1454
+ ...apart,
1455
+ ...(scope === undefined ? undefined : { scope })
1456
+ }
1457
+
1340
1458
  const stored = yield* artifact('findings', {
1341
1459
  kind: 'review-findings',
1342
1460
  title: 'Review findings',
1343
- text,
1461
+ text: reviewText(parts, notRun),
1344
1462
  data: {
1345
1463
  findings,
1346
1464
  followUps,
@@ -1349,32 +1467,46 @@ export default defineLoop({
1349
1467
  }
1350
1468
  })
1351
1469
 
1352
- const reviewed = {
1353
- summary,
1354
- findings,
1355
- followUps,
1356
- verdicts,
1357
- blocking: findings.some(isBlocking),
1358
- artifactId: stored.artifactId,
1359
- ...apart,
1360
- ...(scope === undefined ? undefined : { scope }),
1361
- ...(failing.length === 0 ? undefined : { failing }),
1362
- ...(input.deliversTo === undefined ? undefined : { deliversTo: input.deliversTo })
1363
- }
1364
-
1365
- const changeRequestId = input.changeRequestId
1366
-
1367
- if (changeRequestId === undefined || head === undefined) return reviewed
1470
+ const { changeRequestId } = input
1471
+ const blocking = blockers.length > 0
1368
1472
 
1369
1473
  const approval =
1370
- reviewed.blocking || scope?.met === false || failing.length > 0 || notRun.length > 0
1474
+ changeRequestId === undefined || blocking || scope?.met === false || failing.length > 0 || notRun.length > 0
1371
1475
  ? undefined
1372
- : yield* approveChangeRequest('approve', { changeRequestId, head, summary }).pipe(
1476
+ : yield* approveChangeRequest('approve', { changeRequestId, head: range.head, summary }).pipe(
1373
1477
  Effect.map(result =>
1374
- result.approved ? { head, approved: true } : { head, approved: false, reason: result.reason }
1478
+ result.approved
1479
+ ? { head: range.head, approved: true }
1480
+ : { head: range.head, approved: false, reason: result.reason }
1375
1481
  )
1376
1482
  )
1377
1483
 
1484
+ return new Reviewed({
1485
+ ...parts,
1486
+ verdicts,
1487
+ blocking,
1488
+ artifactId: stored.artifactId,
1489
+ ...(failing.length === 0 ? undefined : { failing }),
1490
+ ...(approval === undefined ? undefined : { approval }),
1491
+ fresh: [...freshIds]
1492
+ })
1493
+ })
1494
+ })
1495
+
1496
+ /** Asks what to do with a ChangeRequest's review, unless its Input says, and does it. */
1497
+ export const followedUp = step('followedUp', {
1498
+ payload: {
1499
+ ...reviewing,
1500
+ // `reviewed` holds what still stands of it, and a visit's journal entry is capped.
1501
+ input: Input.mapFields(Struct.omit(['earlier'])),
1502
+ changeRequestId: Schema.String,
1503
+ reviewed: Reviewed.annotate({ description: 'The review to follow up.' })
1504
+ },
1505
+ success: Schema.Union([Posted, Fixed, Built, Done]),
1506
+ run: ({ input, range, checks: { notRun }, changeRequestId, reviewed }) =>
1507
+ Effect.gen(function* () {
1508
+ const { summary, findings, outOfScopeFindings = [], scope } = reviewed
1509
+
1378
1510
  const answer =
1379
1511
  input.next ??
1380
1512
  (yield* ask('next', {
@@ -1397,60 +1529,144 @@ export default defineLoop({
1397
1529
 
1398
1530
  const choice = choices.find(option => option === answer) ?? 'Done'
1399
1531
 
1400
- const next = yield* Effect.gen(function* () {
1401
- if (choice === 'Post to the ChangeRequest') {
1402
- yield* comment('post', { changeRequestId, body: text, summary: 'kitman-review' })
1532
+ if (choice === 'Post to the ChangeRequest') {
1533
+ yield* comment('post', { changeRequestId, body: reviewText(reviewed, notRun), summary: 'kitman-review' })
1403
1534
 
1404
- // Earlier findings were anchored by the Run that found them; the summary carries them all.
1405
- const anchors = findings.flatMap(finding =>
1406
- !freshIds.has(finding.id) || finding.line < 1
1407
- ? []
1408
- : [{ file: finding.file, line: finding.line, body: `**${finding.severity}:** ${finding.detail}` }]
1409
- )
1535
+ // Earlier findings were anchored by the Run that found them; the summary carries them all.
1536
+ const anchors = findings.flatMap(finding =>
1537
+ !reviewed.fresh.includes(finding.id) || finding.line < 1
1538
+ ? []
1539
+ : [{ file: finding.file, line: finding.line, body: `**${finding.severity}:** ${finding.detail}` }]
1540
+ )
1410
1541
 
1411
- if (anchors.length === 0) return { choice }
1542
+ if (anchors.length === 0) return new Posted({ choice })
1412
1543
 
1413
- // A line outside the diff refuses the lot; the summary comment still carries every finding.
1414
- return yield* comment('anchors', { changeRequestId, body: '', anchors }).pipe(
1415
- Effect.as({ choice }),
1416
- Effect.catchTag('StepFailed', error =>
1417
- Effect.succeed({ choice, detail: `Posted the summary; the line comments failed: ${error.reason}` })
1544
+ // A line outside the diff refuses the lot; the summary comment still carries every finding.
1545
+ return yield* comment('anchors', { changeRequestId, body: '', anchors }).pipe(
1546
+ Effect.map(() => new Posted({ choice })),
1547
+ Effect.catchTag('StepFailed', error =>
1548
+ Effect.succeed(
1549
+ new Posted({ choice, detail: `Posted the summary; the line comments failed: ${error.reason}` })
1418
1550
  )
1419
1551
  )
1420
- }
1552
+ )
1553
+ }
1421
1554
 
1422
- if (choice === 'Fix here') {
1423
- const fixed = yield* call('fix', buildLoop(), {
1424
- words: fixBrief(changeRequestId, findings, scope?.unmet ?? []),
1425
- changeRequestId,
1426
- maxRounds: 2,
1427
- reviewed: range.head,
1428
- ...(findings.length === 0 ? undefined : { earlier: findings }),
1429
- ...(outOfScopeFindings.length === 0 ? undefined : { outOfScopeFindings }),
1430
- ...(scope === undefined ? undefined : { scope }),
1431
- ...ownDeliveryTarget(input)
1432
- })
1433
-
1434
- return { choice, detail: fixed.settled ? 'Fixed and pushed' : `Pushed; left: ${fixed.unsettled.join('; ')}` }
1435
- }
1555
+ if (choice === 'Fix here')
1556
+ return yield* call('fix', buildLoop(), {
1557
+ words: fixBrief(changeRequestId, findings, scope?.unmet ?? []),
1558
+ changeRequestId,
1559
+ maxRounds: 2,
1560
+ reviewed: range.head,
1561
+ ...(findings.length === 0 ? undefined : { earlier: findings }),
1562
+ ...(outOfScopeFindings.length === 0 ? undefined : { outOfScopeFindings }),
1563
+ ...(scope === undefined ? undefined : { scope }),
1564
+ ...ownDeliveryTarget(input)
1565
+ }).pipe(
1566
+ Effect.map(
1567
+ fixed =>
1568
+ new Fixed({
1569
+ choice,
1570
+ detail: fixed.settled ? 'Fixed and pushed' : `Pushed; left: ${fixed.unsettled.join('; ')}`
1571
+ })
1572
+ ),
1573
+ Effect.catchTag('ChildFailed', failed => Effect.succeed(new Done({ choice, detail: failed.reason })))
1574
+ )
1436
1575
 
1437
- if (choice === 'Build from it') {
1438
- const built = yield* call('build', buildLoop(), {
1439
- words: fixBrief(changeRequestId, findings, scope?.unmet ?? []),
1440
- ...ownDeliveryTarget(input)
1441
- })
1576
+ if (choice === 'Build from it')
1577
+ return yield* call('build', buildLoop(), {
1578
+ words: fixBrief(changeRequestId, findings, scope?.unmet ?? []),
1579
+ ...ownDeliveryTarget(input)
1580
+ }).pipe(
1581
+ Effect.map(built => new Built({ choice, detail: built.changeRequest.url })),
1582
+ Effect.catchTag('ChildFailed', failed => Effect.succeed(new Done({ choice, detail: failed.reason })))
1583
+ )
1442
1584
 
1443
- return { choice, detail: built.changeRequest.url }
1444
- }
1585
+ return new Done({ choice, detail: 'The review is kept as an artifact' })
1586
+ })
1587
+ })
1445
1588
 
1446
- return { choice, detail: 'The review is kept as an artifact' }
1447
- }).pipe(Effect.catchTag('ChildFailed', failed => Effect.succeed({ choice, detail: failed.reason })))
1589
+ /** The Loop's Output: the review, and what followed it on a ChangeRequest. */
1590
+ const outputOf = (
1591
+ input: typeof Input.Type,
1592
+ reviewed: Reviewed,
1593
+ followed?: Posted | Fixed | Built | Done
1594
+ ): typeof Output.Type => ({
1595
+ summary: reviewed.summary,
1596
+ findings: reviewed.findings,
1597
+ followUps: reviewed.followUps,
1598
+ verdicts: reviewed.verdicts,
1599
+ blocking: reviewed.blocking,
1600
+ artifactId: reviewed.artifactId,
1601
+ ...(reviewed.approvedFindings === undefined ? undefined : { approvedFindings: reviewed.approvedFindings }),
1602
+ ...(reviewed.outOfScopeFindings === undefined ? undefined : { outOfScopeFindings: reviewed.outOfScopeFindings }),
1603
+ ...(reviewed.scope === undefined ? undefined : { scope: reviewed.scope }),
1604
+ ...(reviewed.failing === undefined ? undefined : { failing: reviewed.failing }),
1605
+ ...(input.deliversTo === undefined ? undefined : { deliversTo: input.deliversTo }),
1606
+ ...(reviewed.approval === undefined ? undefined : { approval: reviewed.approval }),
1607
+ ...(followed === undefined
1608
+ ? undefined
1609
+ : {
1610
+ next: { choice: followed.choice, ...(followed.detail === undefined ? undefined : { detail: followed.detail }) }
1611
+ })
1612
+ })
1448
1613
 
1449
- return {
1450
- ...reviewed,
1451
- ...(approval === undefined ? undefined : { approval }),
1452
- next
1453
- }
1614
+ /**
1615
+ * Reviews a ChangeRequest or a revision range: pins it, checks its head, seats its reviewers, or on a fix the scope
1616
+ * seat alone, judges and follows up.
1617
+ */
1618
+ export default defineLoop({
1619
+ id: 'review',
1620
+ version: '4.0.0',
1621
+ title: 'Review',
1622
+ description: 'Reviews a ChangeRequest or revision range with two reviewers and writes one review.',
1623
+ role: 'review',
1624
+ input: Input,
1625
+ output: Output,
1626
+ agents: { 'code-review': 'code-reviewer', quality: 'quality-reviewer' },
1627
+ checkout: 'read',
1628
+ // Build's, for Fix here and Build from it.
1629
+ capabilities: [
1630
+ 'agent_work',
1631
+ 'post_comment',
1632
+ 'ask',
1633
+ 'call',
1634
+ 'verify',
1635
+ 'change_request',
1636
+ 'write_back',
1637
+ 'read_change_request',
1638
+ 'merge_change_request',
1639
+ 'approve_change_request'
1640
+ ],
1641
+ calls: (): readonly CalledLoop[] => [build],
1642
+ offers: [
1643
+ { id: 'build', title: 'Build from it', loop: 'build' },
1644
+ { id: 'review', title: 'Review again', loop: 'review' }
1645
+ ],
1646
+ run: input =>
1647
+ Effect.gen(function* () {
1648
+ const seats = yield* panelFor(input)
1649
+ const range = yield* ranged({ input })
1650
+ const checks = yield* checked({ input, range })
1651
+
1652
+ const outputs = yield* Effect.forEach(
1653
+ seats,
1654
+ seat =>
1655
+ Effect.map(seated({ input, range, checks, seat, reviewers: seats.length }), output => ({
1656
+ seat: seat.name,
1657
+ output
1658
+ })),
1659
+ { concurrency: 'unbounded' }
1660
+ )
1661
+
1662
+ const reviewed = yield* judged({ input, range, checks, outputs })
1663
+ const { changeRequestId } = input
1664
+
1665
+ if (changeRequestId === undefined) return outputOf(input, reviewed)
1666
+
1667
+ const followed = yield* followedUp({ input, range, checks, changeRequestId, reviewed })
1668
+
1669
+ return outputOf(input, reviewed, followed)
1454
1670
  })
1455
1671
  })
1456
1672