@kitman-sh/software-engineering 0.13.7 → 0.13.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle.js +159 -61
- package/dist/declarations.json +239 -5
- package/package.json +3 -3
- package/src/build.ts +15 -4
- package/src/hillclimb.ts +4 -3
- package/src/review.ts +175 -63
- package/src/reviewed-scope.ts +8 -0
- package/src/shepherd-output.ts +4 -1
- package/src/shepherd.ts +37 -10
package/src/review.ts
CHANGED
|
@@ -17,7 +17,6 @@ import {
|
|
|
17
17
|
pipelineStatus,
|
|
18
18
|
resolveRevisions,
|
|
19
19
|
ResolvedDeliveryTarget,
|
|
20
|
-
ScopeJudgement,
|
|
21
20
|
settleRound
|
|
22
21
|
} from '@kitman-sh/sdk/loop'
|
|
23
22
|
import * as Effect from 'effect/Effect'
|
|
@@ -25,6 +24,7 @@ import * as Schema from 'effect/Schema'
|
|
|
25
24
|
import build, { BuildInput, BuildOutput } from './build'
|
|
26
25
|
import { verifyHead } from './change-request-body'
|
|
27
26
|
import { DeliveryFields, ownDeliveryTarget } from './delivery'
|
|
27
|
+
import { ReviewedScope } from './reviewed-scope'
|
|
28
28
|
import { FindingDetail, OneSentence, ShortStatement } from './text-limits'
|
|
29
29
|
|
|
30
30
|
/** Build, by its schemas: the module imports this one, so its definition is not ready when this one loads. */
|
|
@@ -45,7 +45,7 @@ const seats = {
|
|
|
45
45
|
|
|
46
46
|
const seatNames = ['code-review', 'quality'] as const
|
|
47
47
|
|
|
48
|
-
/** The seat that judges the Task's scope
|
|
48
|
+
/** The seat that judges the Task's scope, and the only one that reviews a fix. */
|
|
49
49
|
const scopeSeat = 'code-review'
|
|
50
50
|
|
|
51
51
|
const choices = ['Post to the ChangeRequest', 'Fix here', 'Build from it', 'Done'] as const
|
|
@@ -58,14 +58,19 @@ const Input = Schema.Struct({
|
|
|
58
58
|
head: Schema.optional(Schema.String),
|
|
59
59
|
/**
|
|
60
60
|
* With `base` and `head`, reviews only these files of the change, such as the conflicts a catch-up merge settled; the
|
|
61
|
-
* rest was approved before. It judges no scope and
|
|
61
|
+
* rest was approved before. A review of a fix counts whatever changed in them since as the fix. It judges no scope and
|
|
62
|
+
* approves nothing itself.
|
|
62
63
|
*/
|
|
63
64
|
files: Schema.optional(Schema.Array(Schema.String)),
|
|
64
|
-
/**
|
|
65
|
+
/**
|
|
66
|
+
* With `files`, also reviews everything in `git diff since..head`, such as a fix made after the files' review; in a
|
|
67
|
+
* review of a fix, only where the fix starts when `reviewed` does not say.
|
|
68
|
+
*/
|
|
65
69
|
since: Schema.optional(Schema.String),
|
|
66
70
|
/**
|
|
67
|
-
* With `base` and `head`, the last approved head: reviews only what the change gained or lost since then,
|
|
68
|
-
* scope, and keeps findings about code that head already had apart, where they do
|
|
71
|
+
* With `base` and `head`, the last approved head: reviews only what the change gained or lost since then, or only the
|
|
72
|
+
* fix in a review of one, judges no scope, and keeps findings about code that head already had apart, where they do
|
|
73
|
+
* not block.
|
|
69
74
|
*/
|
|
70
75
|
approved: Schema.optional(Schema.String),
|
|
71
76
|
/** The implementer's rebuttals of the last round's findings, for the panel to judge. */
|
|
@@ -77,10 +82,12 @@ const Input = Schema.Struct({
|
|
|
77
82
|
/** An earlier review's open findings: each is checked as fixed, changed or still there, keeping its id. */
|
|
78
83
|
earlier: Schema.optional(Schema.Array(MergedFinding)),
|
|
79
84
|
/**
|
|
80
|
-
* The head an earlier review of this change read. With it or `earlier`,
|
|
81
|
-
* `git diff reviewed..head`, and a new finding outside the fix blocks only as a blocker.
|
|
85
|
+
* The head an earlier review of this change read. With it or `earlier`, only the `code-review` seat runs, on the fix,
|
|
86
|
+
* as `git diff reviewed..head`, and a new finding outside the fix blocks only as a blocker.
|
|
82
87
|
*/
|
|
83
88
|
reviewed: Schema.optional(Schema.String),
|
|
89
|
+
/** In a review of a fix, the earlier review's scope judgement: what it found unmet is judged again. */
|
|
90
|
+
scope: Schema.optional(ReviewedScope),
|
|
84
91
|
/** The checks that fail on the head and pass on the base, which the implementer is already told. */
|
|
85
92
|
failing: Schema.optional(Schema.Array(Schema.String)),
|
|
86
93
|
/** Why each head test verify never ran is unverified; a ChangeRequest's head is verified here too. */
|
|
@@ -107,16 +114,26 @@ const SeatFinding = Schema.Struct({
|
|
|
107
114
|
outsideFix: Schema.optional(Schema.Boolean)
|
|
108
115
|
})
|
|
109
116
|
|
|
110
|
-
/** A scope judgement with what an answer put out of scope, which is reported and never unmet. */
|
|
111
|
-
const ReviewedScope = Schema.Struct({
|
|
112
|
-
...ScopeJudgement.fields,
|
|
113
|
-
reported: Schema.optional(Schema.Array(Schema.String))
|
|
114
|
-
})
|
|
115
|
-
|
|
116
117
|
/** Met when nothing is unmet but what an answer put out of scope, so a waived criterion never blocks. */
|
|
117
118
|
const agreedScope = (scope: typeof ReviewedScope.Type): typeof ReviewedScope.Type =>
|
|
118
119
|
scope.unmet.length === 0 && (scope.reported ?? []).length > 0 ? { ...scope, met: true } : scope
|
|
119
120
|
|
|
121
|
+
/** This review's judgement, or the earlier one when it gave none. What was reported stays so unless it is unmet now. */
|
|
122
|
+
const carriedScope = (
|
|
123
|
+
judged: typeof ReviewedScope.Type | undefined,
|
|
124
|
+
earlier: typeof ReviewedScope.Type | undefined
|
|
125
|
+
): typeof ReviewedScope.Type | undefined => {
|
|
126
|
+
if (judged === undefined) return earlier
|
|
127
|
+
|
|
128
|
+
const scope = agreedScope(judged)
|
|
129
|
+
|
|
130
|
+
const reported = [...new Set([...(earlier?.reported ?? []), ...(scope.reported ?? [])])].filter(
|
|
131
|
+
item => !scope.unmet.includes(item)
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
return earlier === undefined || reported.length === 0 ? scope : { ...scope, reported }
|
|
135
|
+
}
|
|
136
|
+
|
|
120
137
|
const SeatOutput = Schema.Struct({
|
|
121
138
|
/** One sentence: can it merge, and what matters most. */
|
|
122
139
|
summary: OneSentence,
|
|
@@ -175,6 +192,9 @@ type Range = {
|
|
|
175
192
|
readonly epic?: { readonly branch: string; readonly defaultBranch: string }
|
|
176
193
|
}
|
|
177
194
|
|
|
195
|
+
const unfetchable = (head: string) =>
|
|
196
|
+
`If the Runner cannot fetch revision ${head} (a fork, say), report exactly that as your only finding, a blocker, and stop.`
|
|
197
|
+
|
|
178
198
|
const targetOf = (input: typeof Input.Type, { base, head, branches, epic }: Range) => {
|
|
179
199
|
if (epic !== undefined)
|
|
180
200
|
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.`
|
|
@@ -183,7 +203,7 @@ const targetOf = (input: typeof Input.Type, { base, head, branches, epic }: Rang
|
|
|
183
203
|
const { source, target } = branches
|
|
184
204
|
const from = source === undefined ? '' : ` from source branch \`${source}\``
|
|
185
205
|
|
|
186
|
-
return `ChangeRequest ${input.changeRequestId} at revision ${head}: \`git diff ${base}...${head}\`, its change${from} into target branch \`${target}\` as that stood when this review started. This names all you need of the ChangeRequest, so look nothing up: fetch \`${source ?? head}\` and \`${target}\` from \`origin\`, and diff exactly those commits even if either branch has moved since.
|
|
206
|
+
return `ChangeRequest ${input.changeRequestId} at revision ${head}: \`git diff ${base}...${head}\`, its change${from} into target branch \`${target}\` as that stood when this review started. This names all you need of the ChangeRequest, so look nothing up: fetch \`${source ?? head}\` and \`${target}\` from \`origin\`, and diff exactly those commits even if either branch has moved since. ${unfetchable(head)}`
|
|
187
207
|
}
|
|
188
208
|
|
|
189
209
|
if (input.files === undefined && input.approved !== undefined)
|
|
@@ -245,59 +265,112 @@ const pinnedRange = (input: typeof Input.Type) =>
|
|
|
245
265
|
/** A review of the whole change judges its scope; one of some files or of a change since an approval does not. */
|
|
246
266
|
const wholeChange = (input: typeof Input.Type) => input.files === undefined && input.approved === undefined
|
|
247
267
|
|
|
248
|
-
const
|
|
268
|
+
const wholeScopePrompt =
|
|
269
|
+
"If your brief has a Task, judge its scope and give it as `scope`: does the change do what the Task's description and each of its Acceptance Criteria ask? Judge it against what is still agreed: a criterion or part an answer under your brief's Answers so far put out of scope is reported, not unmet; list each in `reported`, one line each, and leave it out of `unmet`. Set `met` to true only if the change does all the rest, and list in `unmet` one line for each other criterion or part of the description that is not done. If your brief has no Task, leave `scope` out."
|
|
270
|
+
|
|
271
|
+
const rejudgedScopePrompt = (unmet: readonly string[]) =>
|
|
249
272
|
[
|
|
250
|
-
|
|
273
|
+
[
|
|
274
|
+
"If your brief has a Task, judge its scope again and give it as `scope`. An earlier round judged what the Task's description and Acceptance Criteria ask, and that stands, so do not judge all of it again.",
|
|
275
|
+
...(unmet.length === 0
|
|
276
|
+
? ['It found nothing unmet.']
|
|
277
|
+
: [
|
|
278
|
+
'It found these unmet. Judge each of these again, against the code at the head, and list each that is still not done in `unmet`, in the same words:',
|
|
279
|
+
...unmet.map(item => `- ${item}`)
|
|
280
|
+
])
|
|
281
|
+
].join('\n'),
|
|
282
|
+
"Also list in `unmet`, one line each, any criterion or part the fix undoes. What an answer under your brief's Answers so far put out of scope is reported, not unmet: list each of these in `reported` instead. Set `met` to true only if `unmet` is empty. If your brief has no Task, leave `scope` out."
|
|
283
|
+
].join('\n\n')
|
|
284
|
+
|
|
285
|
+
/** A review of a fix: given an earlier review's findings, or the head an earlier review read. */
|
|
286
|
+
const fixRound = (input: typeof Input.Type) => (input.earlier?.length ?? 0) > 0 || input.reviewed !== undefined
|
|
287
|
+
|
|
288
|
+
/** The earlier judgement a review of a fix starts from; undefined when it is unmet but names nothing. */
|
|
289
|
+
const scopeToRejudge = (input: typeof Input.Type) =>
|
|
290
|
+
fixRound(input) && (input.scope?.met === true || (input.scope?.unmet.length ?? 0) > 0) ? input.scope : undefined
|
|
291
|
+
|
|
292
|
+
const scopePrompt = (input: typeof Input.Type) => {
|
|
293
|
+
const earlier = scopeToRejudge(input)
|
|
294
|
+
|
|
295
|
+
return [
|
|
296
|
+
earlier === undefined ? wholeScopePrompt : rejudgedScopePrompt(earlier.unmet),
|
|
251
297
|
...(input.outcome === undefined ? [] : [`The Outcome to prove is ${input.outcome}.`]),
|
|
252
298
|
...(input.claims === undefined || input.claims.length === 0
|
|
253
299
|
? []
|
|
254
300
|
: [
|
|
255
|
-
|
|
301
|
+
earlier === undefined
|
|
302
|
+
? 'The implementer claims it built these. Check them against the code rather than taking them on trust:'
|
|
303
|
+
: 'The implementer claims these. Check those about the fix or an unmet item against the code rather than taking them on trust:',
|
|
256
304
|
...input.claims.map(claim => `- ${claim}`)
|
|
257
305
|
])
|
|
258
306
|
].join('\n\n')
|
|
307
|
+
}
|
|
259
308
|
|
|
260
|
-
const exhaustivePrompt =
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
309
|
+
const exhaustivePrompt = (subject: string) =>
|
|
310
|
+
[
|
|
311
|
+
`Review exhaustively, in this one pass. For each rule or check ${subject} adds or alters, such as who may read or change what, a validation, a limit or a state transition, trace it through every caller and every input it can get before you report: each kind of actor, each visibility, Team and Project scope, and ids the caller gives.`,
|
|
312
|
+
'Report every finding of every severity in this one pass, grouped by the rule it breaks: do not stop at the first serious one in an area, and hold none back for a later round. Give each its `rule`, worded alike for every finding that breaks the same rule, and its `checked`: the sibling cases of that rule you checked and found fine, so the next round need not explore them again.'
|
|
313
|
+
].join(' ')
|
|
264
314
|
|
|
265
315
|
const earlierPrompt = (earlier: readonly MergedFinding[]) =>
|
|
266
316
|
[
|
|
267
|
-
'
|
|
317
|
+
'Earlier rounds, by both reviewers, left these findings open. Give each as a `followUps` entry with its id: fixed, changed (the code moved but the problem stands) or still_there. Do not report them again as findings.',
|
|
268
318
|
...earlier.map(finding => `- ${finding.id} (${finding.severity}): ${finding.detail}`)
|
|
269
319
|
].join('\n')
|
|
270
320
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
const
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
321
|
+
const outsideFixPrompt =
|
|
322
|
+
'Raise a new problem outside the fix and the code it touches only if it is a blocker; report one that is not as a minor with `outsideFix` set to true, which does not block landing.'
|
|
323
|
+
|
|
324
|
+
/** The fix a review of one reads, in place of the change `targetOf` names. */
|
|
325
|
+
const fixTargetOf = (input: typeof Input.Type, { head, branches, epic }: Range) => {
|
|
326
|
+
const from = input.reviewed ?? (input.files === undefined ? undefined : input.since)
|
|
327
|
+
const branch = branches === undefined ? epic?.branch : (branches.source ?? head)
|
|
328
|
+
|
|
329
|
+
return [
|
|
330
|
+
`${
|
|
331
|
+
from === undefined
|
|
332
|
+
? `the fix made since the earlier review, up to revision ${head}, which you find from the open findings and \`git log\`,`
|
|
333
|
+
: `the fix, \`git diff ${from}..${head}\`,`
|
|
334
|
+
} and the code it touches. An empty fix means nothing was changed, so judge only what is asked below. An earlier round reviewed the rest of the change, so do not review that again. You may read any other code you need.`,
|
|
335
|
+
'The commits merging the target branch brought in are not the fix; what such a merge changed in this change, such as a settled conflict, is.',
|
|
336
|
+
...(input.files === undefined
|
|
337
|
+
? input.approved === undefined
|
|
338
|
+
? []
|
|
339
|
+
: [
|
|
340
|
+
`The change was approved at ${input.approved}. Report a problem in code it already had there only if it matters, with \`approvedCode\` set to true: such findings are kept apart and do not block.`
|
|
341
|
+
]
|
|
342
|
+
: [
|
|
343
|
+
[
|
|
344
|
+
'Whatever changed in these files since then, even by merging the target branch, counts as the fix:',
|
|
345
|
+
...input.files.map(file => `- ${file}`)
|
|
346
|
+
].join('\n')
|
|
347
|
+
]),
|
|
348
|
+
...(branch === undefined
|
|
349
|
+
? []
|
|
350
|
+
: [
|
|
351
|
+
`Look nothing up: fetch \`${branch}\` from \`origin\`, and read exactly revision ${head} even if it has moved since. ${unfetchable(head)}`
|
|
352
|
+
])
|
|
353
|
+
].join('\n\n')
|
|
354
|
+
}
|
|
281
355
|
|
|
282
356
|
const promptFor = (
|
|
283
357
|
seat: keyof typeof seats,
|
|
284
358
|
target: string,
|
|
285
|
-
head: string,
|
|
286
359
|
input: typeof Input.Type,
|
|
287
360
|
failing: readonly string[],
|
|
288
361
|
notRun: readonly string[]
|
|
289
362
|
) =>
|
|
290
363
|
[
|
|
291
|
-
`You are one of two reviewers. Follow your \`${seats[seat].skill}\` skill; if you do not have it: ${seats[seat].focus}`,
|
|
364
|
+
`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}`,
|
|
292
365
|
`Review ${target}`,
|
|
293
366
|
'Give `summary`: one sentence on whether it can merge and what matters most.',
|
|
294
367
|
'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.',
|
|
295
|
-
exhaustivePrompt,
|
|
368
|
+
exhaustivePrompt(fixRound(input) ? 'the fix' : 'the change'),
|
|
296
369
|
"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.",
|
|
297
370
|
'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.',
|
|
298
371
|
...(seat === scopeSeat && wholeChange(input) ? [scopePrompt(input)] : []),
|
|
299
372
|
...(input.earlier === undefined || input.earlier.length === 0 ? [] : [earlierPrompt(input.earlier)]),
|
|
300
|
-
...(fixRound(input) ? [
|
|
373
|
+
...(fixRound(input) ? [outsideFixPrompt] : []),
|
|
301
374
|
...(failing.length === 0
|
|
302
375
|
? []
|
|
303
376
|
: [
|
|
@@ -334,6 +407,25 @@ const detailOf = (detail: string, rule: string | undefined, checked: readonly st
|
|
|
334
407
|
...(checked.length === 0 ? [] : [`Checked and fine: ${checked.join('; ')}.`])
|
|
335
408
|
].join(' ')
|
|
336
409
|
|
|
410
|
+
const severityRank = { blocker: 0, major: 1, minor: 2 } as const
|
|
411
|
+
|
|
412
|
+
const blockingSeatsOf = (finding: MergedFinding) =>
|
|
413
|
+
isBlocking(finding) ? (finding.blockingSeats ?? finding.seats) : []
|
|
414
|
+
|
|
415
|
+
/** A worse problem on an open finding's line, with that finding's own. */
|
|
416
|
+
const withEarlier = (worse: MergedFinding, earlier: MergedFinding): MergedFinding => {
|
|
417
|
+
const { blockingSeats: _, ...finding } = worse
|
|
418
|
+
const seats = [...new Set([...earlier.seats, ...worse.seats])]
|
|
419
|
+
const blockingSeats = [...new Set([...blockingSeatsOf(earlier), ...blockingSeatsOf(worse)])]
|
|
420
|
+
|
|
421
|
+
return {
|
|
422
|
+
...finding,
|
|
423
|
+
detail: `${finding.detail} Still open on this line: ${earlier.detail}`,
|
|
424
|
+
seats,
|
|
425
|
+
...(blockingSeats.length === seats.length ? undefined : { blockingSeats })
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
|
|
337
429
|
const idOf = (finding: SeatFinding) => `${finding.file}:${finding.line}`
|
|
338
430
|
|
|
339
431
|
/**
|
|
@@ -418,24 +510,25 @@ const reviewText = (
|
|
|
418
510
|
])
|
|
419
511
|
].join('\n\n')
|
|
420
512
|
|
|
421
|
-
const fixBrief = (changeRequestId: string, findings: readonly MergedFinding[]) =>
|
|
513
|
+
const fixBrief = (changeRequestId: string, findings: readonly MergedFinding[], unmet: readonly string[]) =>
|
|
422
514
|
[
|
|
423
515
|
`Fix what a review of ChangeRequest ${changeRequestId} found, on its branch:`,
|
|
424
|
-
...findings.map(finding => `- ${finding.id} (${finding.severity}): ${finding.detail}`)
|
|
516
|
+
...findings.map(finding => `- ${finding.id} (${finding.severity}): ${finding.detail}`),
|
|
517
|
+
...(unmet.length === 0 ? [] : ['Do what it found unmet:', ...unmet.map(item => `- ${item}`)])
|
|
425
518
|
].join('\n')
|
|
426
519
|
|
|
427
520
|
/**
|
|
428
521
|
* Reviews a ChangeRequest or a revision range with two reviewer Agents, one following the `code-review` skill and one
|
|
429
522
|
* `code-review-and-quality`, and writes one review from their findings, each said once. It first resolves the base and
|
|
430
523
|
* head to commits on a Runner, so every reviewer reads one diff, and fails when they are one commit. Given an earlier
|
|
431
|
-
* review's findings
|
|
432
|
-
*
|
|
433
|
-
*
|
|
434
|
-
* on later reviews.
|
|
524
|
+
* review's findings or the head it read, the `code-review` reviewer alone reviews the fix and follows the findings up,
|
|
525
|
+
* keeping their ids. On a ChangeRequest it verifies the head it reviews against the ChangeRequest's target and approves
|
|
526
|
+
* it when nothing blocks it, none of its checks broke and verify ran all of its tests, unless it wrote the change, then
|
|
527
|
+
* asks what next and posts only when told to, as one summary comment it edits on later reviews.
|
|
435
528
|
*/
|
|
436
529
|
export default defineLoop({
|
|
437
530
|
id: 'review',
|
|
438
|
-
version: '3.
|
|
531
|
+
version: '3.10.0',
|
|
439
532
|
title: 'Review',
|
|
440
533
|
input: Input,
|
|
441
534
|
output: Output,
|
|
@@ -470,7 +563,7 @@ export default defineLoop({
|
|
|
470
563
|
message: `Base and head are both commit ${range.head}, so the diff is empty: give the base the change is to merge into`
|
|
471
564
|
})
|
|
472
565
|
|
|
473
|
-
const target = targetOf(input, range)
|
|
566
|
+
const target = fixRound(input) ? fixTargetOf(input, range) : targetOf(input, range)
|
|
474
567
|
|
|
475
568
|
// Evidence Kitman holds for the head's tree is reused.
|
|
476
569
|
const verified = head === undefined ? { failing: [], notRun: [] } : yield* verifyHead('verify', head)
|
|
@@ -479,18 +572,18 @@ export default defineLoop({
|
|
|
479
572
|
const notRun = [...new Set([...(input.notRun ?? []), ...verified.notRun])]
|
|
480
573
|
|
|
481
574
|
const outputs = yield* Effect.forEach(
|
|
482
|
-
seatNames,
|
|
575
|
+
fixRound(input) ? ([scopeSeat] as const) : seatNames,
|
|
483
576
|
seat =>
|
|
484
577
|
agentWork(`review:${seat}`, {
|
|
485
578
|
agent: seat,
|
|
486
|
-
prompt: promptFor(seat, target,
|
|
579
|
+
prompt: promptFor(seat, target, input, failing, notRun),
|
|
487
580
|
output: SeatOutput
|
|
488
581
|
}).pipe(Effect.map(output => [seat, output] as const)),
|
|
489
582
|
{ concurrency: 'unbounded' }
|
|
490
583
|
)
|
|
491
584
|
|
|
492
585
|
const earlier = input.earlier ?? []
|
|
493
|
-
const
|
|
586
|
+
const earlierById = new Map(earlier.map(finding => [finding.id, finding]))
|
|
494
587
|
|
|
495
588
|
const answered = followUpsOf(
|
|
496
589
|
earlier,
|
|
@@ -499,41 +592,60 @@ export default defineLoop({
|
|
|
499
592
|
|
|
500
593
|
const standing = new Set(answered.flatMap(entry => (entry.status === 'fixed' ? [] : [entry.id])))
|
|
501
594
|
|
|
502
|
-
const
|
|
595
|
+
const given = outputs.flatMap(([, output]) => output.verdicts ?? [])
|
|
503
596
|
|
|
504
|
-
const settled = settleRound({ findings: earlier, rebuttals: input.rebuttals ?? [], verdicts })
|
|
597
|
+
const settled = settleRound({ findings: earlier, rebuttals: input.rebuttals ?? [], verdicts: given })
|
|
505
598
|
|
|
506
599
|
const withdrawn = new Set(settled.withdrawn.map(entry => entry.finding.id))
|
|
507
600
|
|
|
508
|
-
const
|
|
601
|
+
const open = new Map([...earlierById].filter(([id]) => standing.has(id) && !withdrawn.has(id)))
|
|
602
|
+
|
|
509
603
|
const followUps = answered.filter(entry => !withdrawn.has(entry.id))
|
|
510
604
|
|
|
511
605
|
const sinceApproval = input.approved !== undefined && input.files === undefined
|
|
512
606
|
|
|
607
|
+
/** A problem on an earlier finding's line is new when it is worse, or when that finding is fixed. */
|
|
608
|
+
const isNew = (finding: SeatFinding) => {
|
|
609
|
+
const before = earlierById.get(idOf(finding))
|
|
610
|
+
|
|
611
|
+
return (
|
|
612
|
+
before === undefined ||
|
|
613
|
+
severityRank[finding.severity] < severityRank[before.severity] ||
|
|
614
|
+
(!standing.has(before.id) && !withdrawn.has(before.id))
|
|
615
|
+
)
|
|
616
|
+
}
|
|
617
|
+
|
|
513
618
|
const merged = (approvedCode: boolean) =>
|
|
514
619
|
groupedByRule(
|
|
515
620
|
Object.fromEntries(
|
|
516
621
|
outputs.map(([seat, output]) => [
|
|
517
622
|
seat,
|
|
518
623
|
output.findings
|
|
519
|
-
.filter(
|
|
520
|
-
finding =>
|
|
521
|
-
!earlierIds.has(`${finding.file}:${finding.line}`) &&
|
|
522
|
-
(sinceApproval && finding.approvedCode === true) === approvedCode
|
|
523
|
-
)
|
|
524
624
|
.map(finding => (fixRound(input) ? outsideFixAsMinor(finding) : finding))
|
|
625
|
+
.filter(finding => isNew(finding) && (sinceApproval && finding.approvedCode === true) === approvedCode)
|
|
525
626
|
])
|
|
526
627
|
)
|
|
527
628
|
)
|
|
528
629
|
|
|
529
|
-
const fresh = merged(false)
|
|
630
|
+
const fresh = merged(false).map(finding => {
|
|
631
|
+
const before = open.get(finding.id)
|
|
632
|
+
|
|
633
|
+
return before === undefined ? finding : withEarlier(finding, before)
|
|
634
|
+
})
|
|
635
|
+
|
|
636
|
+
const freshIds = new Set(fresh.map(finding => finding.id))
|
|
530
637
|
const approvedFindings = sinceApproval ? merged(true) : []
|
|
531
638
|
|
|
532
|
-
const findings = [...
|
|
639
|
+
const findings = [...[...open.values()].filter(finding => !freshIds.has(finding.id)), ...fresh]
|
|
640
|
+
|
|
641
|
+
// An accepted rebuttal settles the earlier finding, not the new one that shares its id.
|
|
642
|
+
const verdicts = given.map(verdict =>
|
|
643
|
+
freshIds.has(verdict.findingId) ? { ...verdict, accepted: false } : verdict
|
|
644
|
+
)
|
|
533
645
|
|
|
534
646
|
const blockers = findings.filter(isBlocking)
|
|
535
|
-
const judged =
|
|
536
|
-
const scope = judged
|
|
647
|
+
const judged = outputs.find(([seat]) => seat === scopeSeat)?.[1].scope
|
|
648
|
+
const scope = wholeChange(input) ? carriedScope(judged, fixRound(input) ? input.scope : undefined) : undefined
|
|
537
649
|
|
|
538
650
|
// A seat's own summary is kept only when nothing blocks, so it cannot contradict the verdict.
|
|
539
651
|
const summary =
|
|
@@ -551,7 +663,6 @@ export default defineLoop({
|
|
|
551
663
|
: 'No findings: nothing stands in the way of merging.'
|
|
552
664
|
: ['Can merge: nothing blocks it.', ...outputs.map(([, output]) => output.summary)].join(' ')
|
|
553
665
|
|
|
554
|
-
const freshIds = new Set(fresh.map(finding => finding.id))
|
|
555
666
|
const text = reviewText(summary, findings, followUps, approvedFindings, notRun, scope?.reported ?? [])
|
|
556
667
|
|
|
557
668
|
const stored = yield* artifact('findings', {
|
|
@@ -633,11 +744,12 @@ export default defineLoop({
|
|
|
633
744
|
|
|
634
745
|
if (choice === 'Fix here') {
|
|
635
746
|
const fixed = yield* call('fix', buildLoop(), {
|
|
636
|
-
words: fixBrief(changeRequestId, findings),
|
|
747
|
+
words: fixBrief(changeRequestId, findings, scope?.unmet ?? []),
|
|
637
748
|
changeRequestId,
|
|
638
749
|
maxRounds: 2,
|
|
639
750
|
reviewed: range.head,
|
|
640
751
|
...(findings.length === 0 ? undefined : { earlier: findings }),
|
|
752
|
+
...(scope === undefined ? undefined : { scope }),
|
|
641
753
|
...ownDeliveryTarget(input)
|
|
642
754
|
})
|
|
643
755
|
|
|
@@ -646,7 +758,7 @@ export default defineLoop({
|
|
|
646
758
|
|
|
647
759
|
if (choice === 'Build from it') {
|
|
648
760
|
const built = yield* call('build', buildLoop(), {
|
|
649
|
-
words: fixBrief(changeRequestId, findings),
|
|
761
|
+
words: fixBrief(changeRequestId, findings, scope?.unmet ?? []),
|
|
650
762
|
...ownDeliveryTarget(input)
|
|
651
763
|
})
|
|
652
764
|
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ScopeJudgement } from '@kitman-sh/sdk/loop'
|
|
2
|
+
import * as Schema from 'effect/Schema'
|
|
3
|
+
|
|
4
|
+
/** A scope judgement with what an answer put out of scope, which is reported and never unmet. */
|
|
5
|
+
export const ReviewedScope = Schema.Struct({
|
|
6
|
+
...ScopeJudgement.fields,
|
|
7
|
+
reported: Schema.optional(Schema.Array(Schema.String))
|
|
8
|
+
})
|
package/src/shepherd-output.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { MergedFinding, ResolvedDeliveryTarget, ResolvedReleaseTrigger } from '@kitman-sh/sdk/loop'
|
|
2
2
|
import * as Schema from 'effect/Schema'
|
|
3
|
+
import { ReviewedScope } from './reviewed-scope'
|
|
3
4
|
|
|
4
5
|
/** Shepherd's Output, outside shepherd.ts so Build can import it without the review → build → shepherd cycle. */
|
|
5
6
|
export const ShepherdOutput = Schema.Struct({
|
|
@@ -33,7 +34,9 @@ export const ShepherdOutput = Schema.Struct({
|
|
|
33
34
|
branch: Schema.optional(Schema.String),
|
|
34
35
|
/** The head the review that handed it back read, and its findings, so Build's first review reviews the fix. */
|
|
35
36
|
reviewed: Schema.optional(Schema.String),
|
|
36
|
-
earlier: Schema.optional(Schema.Array(MergedFinding))
|
|
37
|
+
earlier: Schema.optional(Schema.Array(MergedFinding)),
|
|
38
|
+
/** That review's scope judgement, whose unmet items Build's first review judges again. */
|
|
39
|
+
scope: Schema.optional(ReviewedScope)
|
|
37
40
|
})
|
|
38
41
|
)
|
|
39
42
|
})
|
package/src/shepherd.ts
CHANGED
|
@@ -37,6 +37,7 @@ import release, { approvalRef } from './release'
|
|
|
37
37
|
import landEpic, { LandEpicInput, LandEpicOutput } from './land-epic'
|
|
38
38
|
import { DeliveryFields, epicOf, ownDeliveryTarget } from './delivery'
|
|
39
39
|
import { verifyHead } from './change-request-body'
|
|
40
|
+
import type { ReviewedScope } from './reviewed-scope'
|
|
40
41
|
import review, { ReviewInput, ReviewOutput } from './review'
|
|
41
42
|
import { ShepherdOutput } from './shepherd-output'
|
|
42
43
|
import { OneSentence } from './text-limits'
|
|
@@ -248,7 +249,7 @@ type UnranReview = { readonly notRun: readonly string[] } & ({ readonly review:
|
|
|
248
249
|
*/
|
|
249
250
|
export default defineLoop({
|
|
250
251
|
id: 'shepherd',
|
|
251
|
-
version: '1.
|
|
252
|
+
version: '1.10.0',
|
|
252
253
|
title: 'Shepherd',
|
|
253
254
|
input: Input,
|
|
254
255
|
output: Output,
|
|
@@ -289,6 +290,8 @@ export default defineLoop({
|
|
|
289
290
|
let headFindings: readonly MergedFinding[] = []
|
|
290
291
|
/** The head that review read. */
|
|
291
292
|
let headFindingsAt: string | undefined
|
|
293
|
+
/** That review's scope judgement. */
|
|
294
|
+
let headScope: typeof ReviewedScope.Type | undefined
|
|
292
295
|
/** Each head a review passed but left unapproved, as verify never ran these of its tests. */
|
|
293
296
|
const unranAt = new Map<string, UnranReview>()
|
|
294
297
|
const rounds: Record<RoundKind, number> = { 'ci-fix': 0, 'head-fix': 0 }
|
|
@@ -305,6 +308,8 @@ export default defineLoop({
|
|
|
305
308
|
readonly synced: string
|
|
306
309
|
/** The base sync whose merged-from head's approval covers the rest of the change. */
|
|
307
310
|
readonly sync: string
|
|
311
|
+
/** The head that base sync merged from. */
|
|
312
|
+
readonly from: string
|
|
308
313
|
readonly earlier: readonly MergedFinding[]
|
|
309
314
|
/** The head the review that found `earlier` read. */
|
|
310
315
|
readonly reviewed?: string
|
|
@@ -423,7 +428,11 @@ export default defineLoop({
|
|
|
423
428
|
const handBack = (
|
|
424
429
|
reason: string,
|
|
425
430
|
open: string,
|
|
426
|
-
review?: {
|
|
431
|
+
review?: {
|
|
432
|
+
readonly reviewed: string
|
|
433
|
+
readonly earlier: readonly MergedFinding[]
|
|
434
|
+
readonly scope?: typeof ReviewedScope.Type
|
|
435
|
+
}
|
|
427
436
|
): Output => ({
|
|
428
437
|
...done('handed_back', reason),
|
|
429
438
|
handBack: {
|
|
@@ -669,7 +678,13 @@ export default defineLoop({
|
|
|
669
678
|
caught.from === unreviewed.synced ? { ...unreviewed, files, synced: caught.head } : { ...unreviewed, files }
|
|
670
679
|
} else if (caught !== undefined && verdict.kind === 'review') {
|
|
671
680
|
notCarried = undefined
|
|
672
|
-
unreviewed = {
|
|
681
|
+
unreviewed = {
|
|
682
|
+
files: verdict.files,
|
|
683
|
+
synced: caught.head,
|
|
684
|
+
sync: `sync:${cycle}`,
|
|
685
|
+
from: caught.from,
|
|
686
|
+
earlier: []
|
|
687
|
+
}
|
|
673
688
|
} else if (caught !== undefined) {
|
|
674
689
|
notCarried = undefined
|
|
675
690
|
|
|
@@ -806,8 +821,10 @@ export default defineLoop({
|
|
|
806
821
|
* Reviews the files a catch-up merge settled, at `head`, and approves it on a pass: `fixing` when a fix round ran for
|
|
807
822
|
* its findings, `approved` or `unapproved` once the review passed, or `stop` with the Output.
|
|
808
823
|
*/
|
|
809
|
-
const reviewMergedFiles = (cycle: number,
|
|
824
|
+
const reviewMergedFiles = (cycle: number, pipeline: PipelineStatus, files: NonNullable<typeof unreviewed>) =>
|
|
810
825
|
Effect.gen(function* () {
|
|
826
|
+
const { head } = pipeline
|
|
827
|
+
|
|
811
828
|
yield* passTurn()
|
|
812
829
|
|
|
813
830
|
const reviewed = yield* call(`review:${cycle}`, reviewLoop(), {
|
|
@@ -827,7 +844,8 @@ export default defineLoop({
|
|
|
827
844
|
handBack(
|
|
828
845
|
`The review of the catch-up merge's files still finds ${blocking.map(finding => finding.id).join(', ')} after ${rounds['head-fix']} head-fix rounds`,
|
|
829
846
|
findingLines(blocking),
|
|
830
|
-
|
|
847
|
+
// Nobody read the rest of a change whose merged-from head is not approved, so Build reviews it whole.
|
|
848
|
+
pipeline.approved === files.from ? { reviewed: head, earlier: reviewed.findings } : undefined
|
|
831
849
|
)
|
|
832
850
|
)
|
|
833
851
|
rounds['head-fix']++
|
|
@@ -920,7 +938,8 @@ export default defineLoop({
|
|
|
920
938
|
...(notRun.length === 0 ? undefined : { notRun }),
|
|
921
939
|
...(since === undefined ? undefined : { approved: since }),
|
|
922
940
|
...(headFindings.length === 0 ? undefined : { earlier: headFindings }),
|
|
923
|
-
...(headFindingsAt === undefined ? undefined : { reviewed: headFindingsAt })
|
|
941
|
+
...(headFindingsAt === undefined ? undefined : { reviewed: headFindingsAt }),
|
|
942
|
+
...(headScope === undefined ? undefined : { scope: headScope })
|
|
924
943
|
})
|
|
925
944
|
|
|
926
945
|
if (reviewed.blocking) {
|
|
@@ -930,8 +949,14 @@ export default defineLoop({
|
|
|
930
949
|
return stop(
|
|
931
950
|
handBack(
|
|
932
951
|
`The review of ${head} still finds ${blocking.map(finding => finding.id).join(', ')} after ${rounds['head-fix']} head-fix rounds`,
|
|
933
|
-
findingLines(blocking),
|
|
934
|
-
|
|
952
|
+
[findingLines(blocking), ...(reviewed.scope?.unmet ?? []).map(item => `- Not done: ${item}`)].join(
|
|
953
|
+
'\n'
|
|
954
|
+
),
|
|
955
|
+
{
|
|
956
|
+
reviewed: head,
|
|
957
|
+
earlier: reviewed.findings,
|
|
958
|
+
...(reviewed.scope === undefined ? undefined : { scope: reviewed.scope })
|
|
959
|
+
}
|
|
935
960
|
)
|
|
936
961
|
)
|
|
937
962
|
rounds['head-fix']++
|
|
@@ -948,6 +973,7 @@ export default defineLoop({
|
|
|
948
973
|
|
|
949
974
|
headFindings = reviewed.findings
|
|
950
975
|
headFindingsAt = head
|
|
976
|
+
headScope = reviewed.scope
|
|
951
977
|
fixedFrom = { head, changed: fix.changed, looks: 0 }
|
|
952
978
|
|
|
953
979
|
return { kind: 'fixing' } as const
|
|
@@ -955,6 +981,7 @@ export default defineLoop({
|
|
|
955
981
|
|
|
956
982
|
headFindings = []
|
|
957
983
|
headFindingsAt = undefined
|
|
984
|
+
headScope = undefined
|
|
958
985
|
|
|
959
986
|
if (notRun.length > 0) unranAt.set(head, { notRun, review: `head-review:${cycle}` })
|
|
960
987
|
else {
|
|
@@ -1029,7 +1056,7 @@ export default defineLoop({
|
|
|
1029
1056
|
|
|
1030
1057
|
if (head !== pipeline.head) return undefined
|
|
1031
1058
|
|
|
1032
|
-
if (unreviewed !== undefined) return yield* reviewMergedFiles(cycle,
|
|
1059
|
+
if (unreviewed !== undefined) return yield* reviewMergedFiles(cycle, pipeline, unreviewed)
|
|
1033
1060
|
|
|
1034
1061
|
if (notCarried !== undefined && pipeline.approved !== head)
|
|
1035
1062
|
return yield* reviewHead(cycle, pipeline, 'the head its catch-up merge pushed')
|
|
@@ -1375,7 +1402,7 @@ export default defineLoop({
|
|
|
1375
1402
|
reviewedHeads.has(pipeline.head) && (pipeline.approved === pipeline.head || unranAt.has(pipeline.head))
|
|
1376
1403
|
|
|
1377
1404
|
if (unreviewed !== undefined) {
|
|
1378
|
-
const reviewing = yield* reviewMergedFiles(cycle, pipeline
|
|
1405
|
+
const reviewing = yield* reviewMergedFiles(cycle, pipeline, unreviewed)
|
|
1379
1406
|
|
|
1380
1407
|
if (reviewing.kind === 'stop') return reviewing.output
|
|
1381
1408
|
|