@kitman-sh/software-engineering 0.12.0-rc.1 → 0.12.0-rc.3
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 +278 -121
- package/dist/declarations.json +420 -6
- package/package.json +3 -3
- package/src/build.ts +27 -7
- package/src/hillclimb.ts +5 -2
- package/src/plan.ts +128 -91
- package/src/review.ts +121 -17
- package/src/shepherd-output.ts +7 -2
- package/src/shepherd.ts +84 -13
package/src/build.ts
CHANGED
|
@@ -28,7 +28,7 @@ import {
|
|
|
28
28
|
verify,
|
|
29
29
|
writeBack,
|
|
30
30
|
type Disputed,
|
|
31
|
-
|
|
31
|
+
MergedFinding,
|
|
32
32
|
type RallyDecision,
|
|
33
33
|
type ScopeJudgement,
|
|
34
34
|
type SettledRound,
|
|
@@ -79,6 +79,9 @@ export const BuildInput = Schema.Struct({
|
|
|
79
79
|
* before it fails with them; 1 when left out.
|
|
80
80
|
*/
|
|
81
81
|
maxRebuilds: Schema.optional(Schema.Int.check(Schema.isGreaterThanOrEqualTo(0))),
|
|
82
|
+
/** The head an earlier review read, whose `earlier` findings this Build fixes: its first review reviews the fix. */
|
|
83
|
+
reviewed: Schema.optional(Schema.String),
|
|
84
|
+
earlier: Schema.optional(Schema.Array(MergedFinding)),
|
|
82
85
|
...DeliveryFields
|
|
83
86
|
})
|
|
84
87
|
|
|
@@ -147,6 +150,8 @@ export const BuildOutput = Schema.Struct({
|
|
|
147
150
|
criteria: Schema.Array(CriterionAnswer),
|
|
148
151
|
/** Why each head test verify never ran is unverified; absent when it ran them all. */
|
|
149
152
|
notRun: Schema.optional(Schema.Array(Schema.String)),
|
|
153
|
+
/** The last review's code findings still open or disputed, which a Build fixing them takes as `earlier`. */
|
|
154
|
+
findings: Schema.optional(Schema.Array(MergedFinding)),
|
|
150
155
|
/** Whether the last Review's approval was recorded, or why not, when nothing was left unsettled. */
|
|
151
156
|
approval: Schema.optional(ApproveChangeRequestResult),
|
|
152
157
|
/** What Shepherd did with the ChangeRequest, when the Build was told to land it. */
|
|
@@ -211,7 +216,7 @@ const criteriaPrompt = (unanswered: boolean, unmet: readonly CriterionAnswer[])
|
|
|
211
216
|
[
|
|
212
217
|
unanswered
|
|
213
218
|
? "You did not answer the Task's acceptance criteria. Answer each one before anyone reviews the change."
|
|
214
|
-
: 'These acceptance criteria are not met yet. Meet them, or say why they cannot be met here:',
|
|
219
|
+
: 'These acceptance criteria are not met yet. Meet them, or say why they cannot be met here, such as an answer under Answers so far that put them out of scope; do not ask that Question again:',
|
|
215
220
|
...unmet.map(answer => `- ${answer.criterion}: ${answer.detail}`),
|
|
216
221
|
criteriaGuidance
|
|
217
222
|
].join('\n\n')
|
|
@@ -284,6 +289,7 @@ type Round = {
|
|
|
284
289
|
readonly claims: readonly string[]
|
|
285
290
|
readonly scope: ScopeJudgement | undefined
|
|
286
291
|
readonly conflicts: readonly string[]
|
|
292
|
+
readonly earlier: readonly MergedFinding[]
|
|
287
293
|
}
|
|
288
294
|
|
|
289
295
|
/**
|
|
@@ -296,12 +302,14 @@ const rally = (input: {
|
|
|
296
302
|
readonly outcome: LoopOutcome | undefined
|
|
297
303
|
readonly claims: readonly string[]
|
|
298
304
|
readonly suggested: readonly (typeof SuggestedCheck.Type)[]
|
|
305
|
+
readonly reviewed: string | undefined
|
|
306
|
+
readonly earlier: readonly MergedFinding[]
|
|
299
307
|
}) =>
|
|
300
308
|
Effect.gen(function* () {
|
|
301
309
|
const claims = [...input.claims]
|
|
302
310
|
const conflicts: string[] = []
|
|
303
311
|
let rebuttals: readonly Rebuttal[] = []
|
|
304
|
-
let earlier
|
|
312
|
+
let earlier = input.earlier
|
|
305
313
|
let previous: readonly string[] | undefined
|
|
306
314
|
let last: Pick<Round, 'head' | 'settled' | 'scope'> | undefined
|
|
307
315
|
const shown = new Set<string>()
|
|
@@ -338,7 +346,8 @@ const rally = (input: {
|
|
|
338
346
|
head,
|
|
339
347
|
decision: { stop: true, reason: 'findings_returned', unsettled: blockingIds(last.settled) },
|
|
340
348
|
claims,
|
|
341
|
-
conflicts
|
|
349
|
+
conflicts,
|
|
350
|
+
earlier
|
|
342
351
|
} satisfies Round
|
|
343
352
|
|
|
344
353
|
const failing = brokenChecks(head).map(check => check.name)
|
|
@@ -349,6 +358,11 @@ const rally = (input: {
|
|
|
349
358
|
head: head.revision,
|
|
350
359
|
...(rebuttals.length === 0 ? undefined : { rebuttals }),
|
|
351
360
|
...(earlier.length === 0 ? undefined : { earlier }),
|
|
361
|
+
...(last === undefined
|
|
362
|
+
? input.reviewed === undefined
|
|
363
|
+
? undefined
|
|
364
|
+
: { reviewed: input.reviewed }
|
|
365
|
+
: { reviewed: last.head.revision }),
|
|
352
366
|
...(input.outcome === undefined ? undefined : { outcome: input.outcome }),
|
|
353
367
|
...(failing.length === 0 ? undefined : { failing }),
|
|
354
368
|
...(notRun.length === 0 ? undefined : { notRun }),
|
|
@@ -379,7 +393,7 @@ const rally = (input: {
|
|
|
379
393
|
})
|
|
380
394
|
|
|
381
395
|
if (decision.stop && (!unseen || round >= input.maxRounds))
|
|
382
|
-
return { round, head, settled, decision, claims, scope: reviewed.scope, conflicts } satisfies Round
|
|
396
|
+
return { round, head, settled, decision, claims, scope: reviewed.scope, conflicts, earlier } satisfies Round
|
|
383
397
|
|
|
384
398
|
for (const finding of checks) shown.add(finding.detail)
|
|
385
399
|
|
|
@@ -419,7 +433,7 @@ const rally = (input: {
|
|
|
419
433
|
*/
|
|
420
434
|
const build = defineLoop({
|
|
421
435
|
id: 'build',
|
|
422
|
-
version: '2.
|
|
436
|
+
version: '2.8.0',
|
|
423
437
|
title: 'Build',
|
|
424
438
|
input: BuildInput,
|
|
425
439
|
output: BuildOutput,
|
|
@@ -507,7 +521,9 @@ const build = defineLoop({
|
|
|
507
521
|
target,
|
|
508
522
|
outcome,
|
|
509
523
|
claims: [...implemented.claims, ...criteria.map(answer => `Criterion ${answerLine(answer)}`)],
|
|
510
|
-
suggested: implemented.checks ?? []
|
|
524
|
+
suggested: implemented.checks ?? [],
|
|
525
|
+
reviewed: input.reviewed,
|
|
526
|
+
earlier: input.earlier ?? []
|
|
511
527
|
})
|
|
512
528
|
|
|
513
529
|
const verdict = evidenceGate({
|
|
@@ -583,6 +599,7 @@ const build = defineLoop({
|
|
|
583
599
|
stopped: last.decision.reason,
|
|
584
600
|
criteria,
|
|
585
601
|
...(lastNotRun.length === 0 ? undefined : { notRun: lastNotRun }),
|
|
602
|
+
...(last.earlier.length === 0 ? undefined : { findings: last.earlier }),
|
|
586
603
|
...(approval === undefined ? undefined : { approval })
|
|
587
604
|
}
|
|
588
605
|
|
|
@@ -653,6 +670,9 @@ const build = defineLoop({
|
|
|
653
670
|
...(input.maxRounds === undefined ? undefined : { maxRounds: input.maxRounds }),
|
|
654
671
|
changeRequestId: opened.id,
|
|
655
672
|
land: false,
|
|
673
|
+
// Its first review reviews the fix of what the last review read.
|
|
674
|
+
reviewed: settledAs.revision,
|
|
675
|
+
...(settledAs.findings === undefined ? undefined : { earlier: settledAs.findings }),
|
|
656
676
|
...ownDeliveryTarget(input)
|
|
657
677
|
},
|
|
658
678
|
{ constraints: standing.map(standingConstraint) }
|
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
|
})
|