@kitman-sh/software-engineering 0.12.0-rc.2 → 0.12.0-rc.4
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/agents/reviewer.md +8 -0
- package/dist/bundle.js +243 -110
- package/dist/declarations.json +407 -6
- package/package.json +3 -3
- package/src/build.ts +26 -6
- package/src/hillclimb.ts +5 -2
- package/src/plan.ts +128 -91
- package/src/review.ts +99 -11
- package/src/shepherd-output.ts +7 -2
- package/src/shepherd.ts +84 -13
package/src/hillclimb.ts
CHANGED
|
@@ -185,7 +185,7 @@ const steadier = (plan: MeasurePlan): MeasurePlan | undefined => {
|
|
|
185
185
|
*/
|
|
186
186
|
export default defineLoop({
|
|
187
187
|
id: 'hillclimb',
|
|
188
|
-
version: '1.
|
|
188
|
+
version: '1.4.0',
|
|
189
189
|
title: 'Hillclimb',
|
|
190
190
|
outcome: 'performance',
|
|
191
191
|
input: Input,
|
|
@@ -379,6 +379,8 @@ export default defineLoop({
|
|
|
379
379
|
if (final.verdict !== 'gain')
|
|
380
380
|
return yield* ending('gain_gone', `The review's fixes cost the gain: ${final.reason}`, final)
|
|
381
381
|
|
|
382
|
+
const fixedFrom = head.revision
|
|
383
|
+
|
|
382
384
|
head = fixed
|
|
383
385
|
|
|
384
386
|
reviewed = yield* call(`review:${round + 1}`, review, {
|
|
@@ -387,7 +389,8 @@ export default defineLoop({
|
|
|
387
389
|
outcome: 'performance',
|
|
388
390
|
...notRunOf(fixed),
|
|
389
391
|
claims,
|
|
390
|
-
earlier: blocking
|
|
392
|
+
earlier: blocking,
|
|
393
|
+
reviewed: fixedFrom
|
|
391
394
|
})
|
|
392
395
|
}
|
|
393
396
|
|
package/src/plan.ts
CHANGED
|
@@ -293,7 +293,16 @@ const buildTicket = (
|
|
|
293
293
|
revision: head.revision,
|
|
294
294
|
// Plan merges each Build's ChangeRequest into its integration branch itself.
|
|
295
295
|
land: false
|
|
296
|
-
}).pipe(
|
|
296
|
+
}).pipe(
|
|
297
|
+
Effect.catchTags({
|
|
298
|
+
ChildFailed: (failure: ChildFailed) => Effect.succeed(failure),
|
|
299
|
+
// Kitman refuses a Build on a Task that already has a Run, such as one pickup started.
|
|
300
|
+
StepFailed: refused =>
|
|
301
|
+
refused.code === 'task_run_unsettled'
|
|
302
|
+
? Effect.succeed(new ChildFailed({ step: refused.step, loop: build.id, reason: refused.reason }))
|
|
303
|
+
: Effect.fail(refused)
|
|
304
|
+
})
|
|
305
|
+
)
|
|
297
306
|
|
|
298
307
|
if (built instanceof ChildFailed)
|
|
299
308
|
return settled(ticket, { status: 'failed', repoBindingId: head.repoBindingId, reason: built.reason })
|
|
@@ -421,6 +430,7 @@ const implement = (input: typeof Input.Type, plan: Plan, revision: number, filed
|
|
|
421
430
|
? filed.tasks
|
|
422
431
|
: (yield* createTasks('tasks', {
|
|
423
432
|
tickets: plan.tickets,
|
|
433
|
+
builds: true,
|
|
424
434
|
...(input.projectId === undefined ? undefined : { projectId: input.projectId })
|
|
425
435
|
})).tasks
|
|
426
436
|
|
|
@@ -579,6 +589,29 @@ export default defineLoop({
|
|
|
579
589
|
|
|
580
590
|
const project = input.projectId === undefined ? undefined : { projectId: input.projectId }
|
|
581
591
|
|
|
592
|
+
// Filed tickets by key, held from pickup while this Run could still build them as its own Child Runs.
|
|
593
|
+
const held = new Map<string, PlanTicket>()
|
|
594
|
+
let implementing = false
|
|
595
|
+
|
|
596
|
+
const file = (step: string) =>
|
|
597
|
+
Effect.gen(function* () {
|
|
598
|
+
const made = yield* createTasks(step, { tickets: plan.tickets, builds: true, ...project })
|
|
599
|
+
|
|
600
|
+
for (const ticket of plan.tickets) held.set(ticket.key, ticket)
|
|
601
|
+
filed = { revision, tasks: made.tasks }
|
|
602
|
+
})
|
|
603
|
+
|
|
604
|
+
/** Leaves the held Tasks, but for those Implement now builds, for pickup to start. */
|
|
605
|
+
const release = (building: readonly PlanTicket[] = []) => {
|
|
606
|
+
const tickets = [...held.values()].filter(ticket => !building.some(built => built.key === ticket.key))
|
|
607
|
+
|
|
608
|
+
held.clear()
|
|
609
|
+
|
|
610
|
+
return tickets.length === 0
|
|
611
|
+
? Effect.void
|
|
612
|
+
: Effect.asVoid(createTasks('release-tasks', { tickets, releases: true, ...project }))
|
|
613
|
+
}
|
|
614
|
+
|
|
582
615
|
const ended = (rest: { readonly implemented: boolean; readonly stopped?: string }) => ({
|
|
583
616
|
title: plan.title,
|
|
584
617
|
outOfScope: plan.outOfScope,
|
|
@@ -591,104 +624,108 @@ export default defineLoop({
|
|
|
591
624
|
...rest
|
|
592
625
|
})
|
|
593
626
|
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
const options = menu.filter(
|
|
598
|
-
option =>
|
|
599
|
-
!(option === 'File as Tasks' && isFiled) && !(option === 'Second opinion' && opinions >= maxOpinionsPerPlan)
|
|
600
|
-
)
|
|
601
|
-
|
|
602
|
-
const fallback: Choice = input.implement === true ? 'Implement now' : isFiled ? 'Finish' : 'File as Tasks'
|
|
603
|
-
|
|
604
|
-
const answer = yield* ask(`next:${round}`, {
|
|
605
|
-
prompt: `What next for the plan "${plan.title}"?`,
|
|
606
|
-
options: options.map(option => ({ value: option, description: menuDescriptions[option] })),
|
|
607
|
-
recommended: fallback,
|
|
608
|
-
recommendationReason:
|
|
609
|
-
fallback === 'Implement now'
|
|
610
|
-
? 'You asked for the plan to be implemented.'
|
|
611
|
-
: fallback === 'Finish'
|
|
612
|
-
? 'The plan is filed as Tasks, so nothing is lost by finishing.'
|
|
613
|
-
: 'Filing keeps the plan as Tasks a person or a Build can pick up later.',
|
|
614
|
-
default: fallback,
|
|
615
|
-
timeout: '1 hour'
|
|
616
|
-
})
|
|
617
|
-
|
|
618
|
-
const choice = menu.find(option => option === answer) ?? fallback
|
|
619
|
-
|
|
620
|
-
switch (choice) {
|
|
621
|
-
case 'Finish':
|
|
622
|
-
return ended({ implemented: false })
|
|
623
|
-
case 'Implement now': {
|
|
624
|
-
const delivered = yield* implement(input, plan, revision, filed)
|
|
625
|
-
|
|
626
|
-
return { ...ended({ implemented: true }), ...delivered }
|
|
627
|
-
}
|
|
628
|
-
|
|
629
|
-
case 'File as Tasks': {
|
|
630
|
-
const made = yield* createTasks(`file-tasks:${round}`, { tickets: plan.tickets, ...project })
|
|
631
|
-
|
|
632
|
-
filed = { revision, tasks: made.tasks }
|
|
633
|
-
break
|
|
634
|
-
}
|
|
627
|
+
const decide = Effect.gen(function* () {
|
|
628
|
+
for (let round = 1; round <= maxRounds; round++) {
|
|
629
|
+
const isFiled = filed?.revision === revision
|
|
635
630
|
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
prompt: opinionPrompt(plan),
|
|
642
|
-
output: Opinion
|
|
643
|
-
})
|
|
631
|
+
const options = menu.filter(
|
|
632
|
+
option =>
|
|
633
|
+
!(option === 'File as Tasks' && isFiled) &&
|
|
634
|
+
!(option === 'Second opinion' && opinions >= maxOpinionsPerPlan)
|
|
635
|
+
)
|
|
644
636
|
|
|
645
|
-
|
|
646
|
-
kind: 'plan_review',
|
|
647
|
-
title: `Second opinion on ${plan.title}`,
|
|
648
|
-
text: [opinion.summary, ...opinion.concerns.map(concern => `- ${concern}`)].join('\n\n')
|
|
649
|
-
})
|
|
637
|
+
const fallback: Choice = input.implement === true ? 'Implement now' : isFiled ? 'Finish' : 'File as Tasks'
|
|
650
638
|
|
|
651
|
-
|
|
652
|
-
|
|
639
|
+
const answer = yield* ask(`next:${round}`, {
|
|
640
|
+
prompt: `What next for the plan "${plan.title}"?`,
|
|
641
|
+
options: options.map(option => ({ value: option, description: menuDescriptions[option] })),
|
|
642
|
+
recommended: fallback,
|
|
643
|
+
recommendationReason:
|
|
644
|
+
fallback === 'Implement now'
|
|
645
|
+
? 'You asked for the plan to be implemented.'
|
|
646
|
+
: fallback === 'Finish'
|
|
647
|
+
? 'The plan is filed as Tasks, so nothing is lost by finishing.'
|
|
648
|
+
: 'Filing keeps the plan as Tasks a person or a Build can pick up later.',
|
|
649
|
+
default: fallback,
|
|
650
|
+
timeout: '1 hour'
|
|
651
|
+
})
|
|
653
652
|
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
653
|
+
const choice = menu.find(option => option === answer) ?? fallback
|
|
654
|
+
|
|
655
|
+
switch (choice) {
|
|
656
|
+
case 'Finish':
|
|
657
|
+
yield* release()
|
|
658
|
+
|
|
659
|
+
return ended({ implemented: false })
|
|
660
|
+
case 'Implement now': {
|
|
661
|
+
implementing = true
|
|
662
|
+
yield* release(plan.tickets)
|
|
663
|
+
|
|
664
|
+
const delivered = yield* implement(input, plan, revision, filed)
|
|
665
|
+
|
|
666
|
+
return { ...ended({ implemented: true }), ...delivered }
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
case 'File as Tasks':
|
|
670
|
+
yield* file(`file-tasks:${round}`)
|
|
671
|
+
break
|
|
672
|
+
|
|
673
|
+
case 'Second opinion': {
|
|
674
|
+
opinions++
|
|
675
|
+
|
|
676
|
+
const opinion = yield* agentWork(`second-opinion:${round}`, {
|
|
677
|
+
agent: 'reviewer',
|
|
678
|
+
prompt: opinionPrompt(plan),
|
|
679
|
+
output: Opinion
|
|
680
|
+
})
|
|
681
|
+
|
|
682
|
+
yield* artifact(`opinion:${round}`, {
|
|
683
|
+
kind: 'plan_review',
|
|
684
|
+
title: `Second opinion on ${plan.title}`,
|
|
685
|
+
text: [opinion.summary, ...opinion.concerns.map(concern => `- ${concern}`)].join('\n\n')
|
|
686
|
+
})
|
|
687
|
+
|
|
688
|
+
break
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
case 'Refine': {
|
|
692
|
+
const words = yield* ask(`refine:${round}`, {
|
|
693
|
+
prompt: 'What should change in the plan?',
|
|
694
|
+
freeText: true,
|
|
695
|
+
informationOnly: true,
|
|
696
|
+
recommendationReason: 'You chose to refine it, so only you know what should change.'
|
|
697
|
+
})
|
|
698
|
+
|
|
699
|
+
const refined = yield* agentWorkOnce(`refine-plan:${round}`, {
|
|
700
|
+
agent: 'planner',
|
|
701
|
+
prompt: refinePrompt(plan, words),
|
|
702
|
+
output: Plan
|
|
703
|
+
})
|
|
704
|
+
|
|
705
|
+
const before = plan
|
|
706
|
+
|
|
707
|
+
revision++
|
|
708
|
+
;({ plan, rejected } = yield* checked(refined, revision))
|
|
709
|
+
yield* storePlan(plan, `:${round}`)
|
|
710
|
+
yield* artifact(`changes:${round}`, {
|
|
711
|
+
kind: 'plan_changes',
|
|
712
|
+
title: `Revision ${revision} of ${plan.title}`,
|
|
713
|
+
text: changelog(before, plan, words)
|
|
714
|
+
})
|
|
715
|
+
break
|
|
716
|
+
}
|
|
679
717
|
}
|
|
680
718
|
}
|
|
681
|
-
}
|
|
682
719
|
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
revision,
|
|
686
|
-
tasks: (yield* createTasks('file-tasks:last', { tickets: plan.tickets, ...project })).tasks
|
|
687
|
-
}
|
|
720
|
+
if (filed?.revision !== revision) yield* file('file-tasks:last')
|
|
721
|
+
yield* release()
|
|
688
722
|
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
723
|
+
return ended({
|
|
724
|
+
implemented: false,
|
|
725
|
+
stopped: `No decision after ${maxRounds} rounds, so the tickets are filed as Tasks for a person to pick up`
|
|
726
|
+
})
|
|
692
727
|
})
|
|
728
|
+
|
|
729
|
+
return yield* decide.pipe(Effect.tapError(() => (implementing ? Effect.void : Effect.ignore(release()))))
|
|
693
730
|
})
|
|
694
731
|
})
|
package/src/review.ts
CHANGED
|
@@ -25,7 +25,7 @@ import * as Schema from 'effect/Schema'
|
|
|
25
25
|
import build, { BuildInput, BuildOutput } from './build'
|
|
26
26
|
import { verifyHead } from './change-request-body'
|
|
27
27
|
import { DeliveryFields, ownDeliveryTarget } from './delivery'
|
|
28
|
-
import { FindingDetail, OneSentence } from './text-limits'
|
|
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. */
|
|
31
31
|
const buildLoop = () => ({ id: 'build', input: BuildInput, output: BuildOutput })
|
|
@@ -76,6 +76,11 @@ const Input = Schema.Struct({
|
|
|
76
76
|
claims: Schema.optional(Schema.Array(Schema.String)),
|
|
77
77
|
/** An earlier review's open findings: each is checked as fixed, changed or still there, keeping its id. */
|
|
78
78
|
earlier: Schema.optional(Schema.Array(MergedFinding)),
|
|
79
|
+
/**
|
|
80
|
+
* The head an earlier review of this change read. With it or `earlier`, this review reviews the fix, as
|
|
81
|
+
* `git diff reviewed..head`, and a new finding outside the fix blocks only as a blocker.
|
|
82
|
+
*/
|
|
83
|
+
reviewed: Schema.optional(Schema.String),
|
|
79
84
|
/** The checks that fail on the head and pass on the base, which the implementer is already told. */
|
|
80
85
|
failing: Schema.optional(Schema.Array(Schema.String)),
|
|
81
86
|
/** Why each head test verify never ran is unverified; a ChangeRequest's head is verified here too. */
|
|
@@ -93,7 +98,13 @@ const SeatFinding = Schema.Struct({
|
|
|
93
98
|
...Finding.fields,
|
|
94
99
|
detail: FindingDetail,
|
|
95
100
|
/** In a review since an approved head: the problem is in code the change already had there. */
|
|
96
|
-
approvedCode: Schema.optional(Schema.Boolean)
|
|
101
|
+
approvedCode: Schema.optional(Schema.Boolean),
|
|
102
|
+
/** The rule or check it breaks, worded alike for every finding that breaks it. */
|
|
103
|
+
rule: Schema.optional(OneSentence),
|
|
104
|
+
/** The sibling cases of that rule the seat checked and found fine. */
|
|
105
|
+
checked: Schema.optional(Schema.Array(ShortStatement)),
|
|
106
|
+
/** In a review of a fix: the problem is outside the fix and the code it touches. */
|
|
107
|
+
outsideFix: Schema.optional(Schema.Boolean)
|
|
97
108
|
})
|
|
98
109
|
|
|
99
110
|
/** A scope judgement with what an answer put out of scope, which is reported and never unmet. */
|
|
@@ -128,6 +139,8 @@ const Output = Schema.Struct({
|
|
|
128
139
|
artifactId: Schema.String,
|
|
129
140
|
/** The scope seat's judgement of the Task's scope; absent when there was no Task to judge against. */
|
|
130
141
|
scope: Schema.optional(ReviewedScope),
|
|
142
|
+
/** The checks that fail on the head, given or verified here; the head is not ready while any does. */
|
|
143
|
+
failing: Schema.optional(Schema.Array(Schema.String)),
|
|
131
144
|
/** Kitman's approval of the ChangeRequest's head, recorded when nothing blocks it; or why it was refused. */
|
|
132
145
|
approval: Schema.optional(
|
|
133
146
|
Schema.Struct({ head: Schema.String, approved: Schema.Boolean, reason: Schema.optional(Schema.String) })
|
|
@@ -231,15 +244,32 @@ const scopePrompt = (input: typeof Input.Type) =>
|
|
|
231
244
|
])
|
|
232
245
|
].join('\n\n')
|
|
233
246
|
|
|
247
|
+
const exhaustivePrompt = [
|
|
248
|
+
'Review exhaustively, in this one pass. For each rule or check the change 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.',
|
|
249
|
+
'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.'
|
|
250
|
+
].join(' ')
|
|
251
|
+
|
|
234
252
|
const earlierPrompt = (earlier: readonly MergedFinding[]) =>
|
|
235
253
|
[
|
|
236
|
-
'An earlier review found these. 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
|
|
254
|
+
'An earlier review found these. 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.',
|
|
237
255
|
...earlier.map(finding => `- ${finding.id} (${finding.severity}): ${finding.detail}`)
|
|
238
256
|
].join('\n')
|
|
239
257
|
|
|
258
|
+
/** A review of a fix: given an earlier review's findings, or the head an earlier review read. */
|
|
259
|
+
const fixRound = (input: typeof Input.Type) => (input.earlier?.length ?? 0) > 0 || input.reviewed !== undefined
|
|
260
|
+
|
|
261
|
+
const fixPrompt = (fix: string) =>
|
|
262
|
+
`This round reviews ${fix} and the code it touches, exhaustively as above. 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.`
|
|
263
|
+
|
|
264
|
+
const fixOf = (input: typeof Input.Type, head: string) =>
|
|
265
|
+
input.reviewed === undefined
|
|
266
|
+
? 'the fix since the earlier review'
|
|
267
|
+
: `the fix, \`git diff ${input.reviewed}..${head}\` (the target branch merged into it is not the fix),`
|
|
268
|
+
|
|
240
269
|
const promptFor = (
|
|
241
270
|
seat: keyof typeof seats,
|
|
242
271
|
target: string,
|
|
272
|
+
head: string,
|
|
243
273
|
input: typeof Input.Type,
|
|
244
274
|
failing: readonly string[],
|
|
245
275
|
notRun: readonly string[]
|
|
@@ -249,10 +279,12 @@ const promptFor = (
|
|
|
249
279
|
`Review ${target}`,
|
|
250
280
|
'Give `summary`: one sentence on whether it can merge and what matters most.',
|
|
251
281
|
'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.',
|
|
282
|
+
exhaustivePrompt,
|
|
252
283
|
"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.",
|
|
253
284
|
'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.',
|
|
254
285
|
...(seat === scopeSeat && wholeChange(input) ? [scopePrompt(input)] : []),
|
|
255
286
|
...(input.earlier === undefined || input.earlier.length === 0 ? [] : [earlierPrompt(input.earlier)]),
|
|
287
|
+
...(fixRound(input) ? [fixPrompt(fixOf(input, head))] : []),
|
|
256
288
|
...(failing.length === 0
|
|
257
289
|
? []
|
|
258
290
|
: [
|
|
@@ -276,6 +308,57 @@ const promptFor = (
|
|
|
276
308
|
|
|
277
309
|
const rank = { still_there: 0, changed: 1, fixed: 2 } as const
|
|
278
310
|
|
|
311
|
+
type SeatFinding = typeof SeatFinding.Type
|
|
312
|
+
|
|
313
|
+
/** A review of a fix lands past a new problem outside it unless that problem is a blocker. */
|
|
314
|
+
const outsideFixAsMinor = (finding: SeatFinding): SeatFinding =>
|
|
315
|
+
finding.outsideFix === true && finding.severity === 'major' ? { ...finding, severity: 'minor' } : finding
|
|
316
|
+
|
|
317
|
+
const detailOf = (detail: string, rule: string | undefined, checked: readonly string[]) =>
|
|
318
|
+
[
|
|
319
|
+
...(rule === undefined ? [] : [`[${rule}]`]),
|
|
320
|
+
detail,
|
|
321
|
+
...(checked.length === 0 ? [] : [`Checked and fine: ${checked.join('; ')}.`])
|
|
322
|
+
].join(' ')
|
|
323
|
+
|
|
324
|
+
const idOf = (finding: SeatFinding) => `${finding.file}:${finding.line}`
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Merges the seats' findings with the rule and the cases checked for each in its detail, those of one rule together.
|
|
328
|
+
* A line takes the first rule any seat gave it and every seat's checked cases, whichever seat's detail the merge keeps.
|
|
329
|
+
*/
|
|
330
|
+
const groupedByRule = (bySeat: { readonly [seat: string]: readonly SeatFinding[] }) => {
|
|
331
|
+
const rules = new Map<string, string>()
|
|
332
|
+
const checked = new Map<string, Set<string>>()
|
|
333
|
+
|
|
334
|
+
for (const finding of Object.values(bySeat).flat()) {
|
|
335
|
+
const id = idOf(finding)
|
|
336
|
+
|
|
337
|
+
if (finding.rule !== undefined && !rules.has(id)) rules.set(id, finding.rule)
|
|
338
|
+
checked.set(id, new Set([...(checked.get(id) ?? []), ...(finding.checked ?? [])]))
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
const findings = mergeFindings(
|
|
342
|
+
Object.fromEntries(
|
|
343
|
+
Object.entries(bySeat).map(([seat, seatFindings]) => [
|
|
344
|
+
seat,
|
|
345
|
+
seatFindings.map(finding => ({
|
|
346
|
+
severity: finding.severity,
|
|
347
|
+
file: finding.file,
|
|
348
|
+
line: finding.line,
|
|
349
|
+
detail: detailOf(finding.detail, rules.get(idOf(finding)), [...(checked.get(idOf(finding)) ?? [])])
|
|
350
|
+
}))
|
|
351
|
+
])
|
|
352
|
+
)
|
|
353
|
+
)
|
|
354
|
+
|
|
355
|
+
// Groups keep the order of their worst finding, as mergeFindings sorts by severity.
|
|
356
|
+
const groupOf = (finding: MergedFinding) => rules.get(finding.id) ?? finding.id
|
|
357
|
+
const order = [...new Set(findings.map(groupOf))]
|
|
358
|
+
|
|
359
|
+
return findings.toSorted((left, right) => order.indexOf(groupOf(left)) - order.indexOf(groupOf(right)))
|
|
360
|
+
}
|
|
361
|
+
|
|
279
362
|
/** Each earlier finding's status: the worst any seat gave, and still there when no seat answered for it. */
|
|
280
363
|
const followUpsOf = (earlier: readonly MergedFinding[], answers: readonly (typeof FollowUp.Type)[]) =>
|
|
281
364
|
earlier.map(finding => {
|
|
@@ -339,7 +422,7 @@ const fixBrief = (changeRequestId: string, findings: readonly MergedFinding[]) =
|
|
|
339
422
|
*/
|
|
340
423
|
export default defineLoop({
|
|
341
424
|
id: 'review',
|
|
342
|
-
version: '3.
|
|
425
|
+
version: '3.9.0',
|
|
343
426
|
title: 'Review',
|
|
344
427
|
input: Input,
|
|
345
428
|
output: Output,
|
|
@@ -387,7 +470,7 @@ export default defineLoop({
|
|
|
387
470
|
seat =>
|
|
388
471
|
agentWork(`review:${seat}`, {
|
|
389
472
|
agent: seat,
|
|
390
|
-
prompt: promptFor(seat, target, input, failing, notRun),
|
|
473
|
+
prompt: promptFor(seat, target, range.head, input, failing, notRun),
|
|
391
474
|
output: SeatOutput
|
|
392
475
|
}).pipe(Effect.map(output => [seat, output] as const)),
|
|
393
476
|
{ concurrency: 'unbounded' }
|
|
@@ -415,15 +498,17 @@ export default defineLoop({
|
|
|
415
498
|
const sinceApproval = input.approved !== undefined && input.files === undefined
|
|
416
499
|
|
|
417
500
|
const merged = (approvedCode: boolean) =>
|
|
418
|
-
|
|
501
|
+
groupedByRule(
|
|
419
502
|
Object.fromEntries(
|
|
420
503
|
outputs.map(([seat, output]) => [
|
|
421
504
|
seat,
|
|
422
|
-
output.findings
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
505
|
+
output.findings
|
|
506
|
+
.filter(
|
|
507
|
+
finding =>
|
|
508
|
+
!earlierIds.has(`${finding.file}:${finding.line}`) &&
|
|
509
|
+
(sinceApproval && finding.approvedCode === true) === approvedCode
|
|
510
|
+
)
|
|
511
|
+
.map(finding => (fixRound(input) ? outsideFixAsMinor(finding) : finding))
|
|
427
512
|
])
|
|
428
513
|
)
|
|
429
514
|
)
|
|
@@ -472,6 +557,7 @@ export default defineLoop({
|
|
|
472
557
|
artifactId: stored.artifactId,
|
|
473
558
|
...(approvedFindings.length === 0 ? undefined : { approvedFindings }),
|
|
474
559
|
...(scope === undefined ? undefined : { scope }),
|
|
560
|
+
...(failing.length === 0 ? undefined : { failing }),
|
|
475
561
|
...(input.deliversTo === undefined ? undefined : { deliversTo: input.deliversTo })
|
|
476
562
|
}
|
|
477
563
|
|
|
@@ -537,6 +623,8 @@ export default defineLoop({
|
|
|
537
623
|
words: fixBrief(changeRequestId, findings),
|
|
538
624
|
changeRequestId,
|
|
539
625
|
maxRounds: 2,
|
|
626
|
+
reviewed: range.head,
|
|
627
|
+
...(findings.length === 0 ? undefined : { earlier: findings }),
|
|
540
628
|
...ownDeliveryTarget(input)
|
|
541
629
|
})
|
|
542
630
|
|
package/src/shepherd-output.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ResolvedDeliveryTarget, ResolvedReleaseTrigger } from '@kitman-sh/sdk/loop'
|
|
1
|
+
import { MergedFinding, 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. */
|
|
@@ -9,6 +9,8 @@ export const ShepherdOutput = Schema.Struct({
|
|
|
9
9
|
reason: Schema.String,
|
|
10
10
|
fixRounds: Schema.Int,
|
|
11
11
|
replies: Schema.Int,
|
|
12
|
+
/** Each passed Review another Run recorded that Shepherd used for a head instead of reviewing that head again. */
|
|
13
|
+
reused: Schema.optional(Schema.Array(Schema.Struct({ review: Schema.String, head: Schema.String }))),
|
|
12
14
|
/** What still stands when it stopped without landing (needs_you, handed_back), so the Run and a Build above it read partial. */
|
|
13
15
|
unsettled: Schema.optional(Schema.Array(Schema.String)),
|
|
14
16
|
/** The Release it started after merging, when it was told to release. */
|
|
@@ -28,7 +30,10 @@ export const ShepherdOutput = Schema.Struct({
|
|
|
28
30
|
words: Schema.String,
|
|
29
31
|
taskId: Schema.optional(Schema.String),
|
|
30
32
|
/** The ChangeRequest's target, which Build merges into. */
|
|
31
|
-
branch: Schema.optional(Schema.String)
|
|
33
|
+
branch: Schema.optional(Schema.String),
|
|
34
|
+
/** The head the review that handed it back read, and its findings, so Build's first review reviews the fix. */
|
|
35
|
+
reviewed: Schema.optional(Schema.String),
|
|
36
|
+
earlier: Schema.optional(Schema.Array(MergedFinding))
|
|
32
37
|
})
|
|
33
38
|
)
|
|
34
39
|
})
|