@kitman-sh/software-engineering 0.13.7 → 0.13.9

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.
@@ -3,7 +3,7 @@
3
3
  {
4
4
  "id": "build",
5
5
  "title": "Build",
6
- "version": "2.10.0",
6
+ "version": "2.11.0",
7
7
  "input": {
8
8
  "type": "object",
9
9
  "properties": {
@@ -273,6 +273,45 @@
273
273
  }
274
274
  ]
275
275
  },
276
+ "scope": {
277
+ "anyOf": [
278
+ {
279
+ "type": "object",
280
+ "properties": {
281
+ "met": {
282
+ "type": "boolean"
283
+ },
284
+ "unmet": {
285
+ "type": "array",
286
+ "items": {
287
+ "type": "string"
288
+ }
289
+ },
290
+ "reported": {
291
+ "anyOf": [
292
+ {
293
+ "type": "array",
294
+ "items": {
295
+ "type": "string"
296
+ }
297
+ },
298
+ {
299
+ "type": "null"
300
+ }
301
+ ]
302
+ }
303
+ },
304
+ "required": [
305
+ "met",
306
+ "unmet"
307
+ ],
308
+ "additionalProperties": true
309
+ },
310
+ {
311
+ "type": "null"
312
+ }
313
+ ]
314
+ },
276
315
  "deliveryTarget": {
277
316
  "anyOf": [
278
317
  {
@@ -526,6 +565,45 @@
526
565
  }
527
566
  ]
528
567
  },
568
+ "scope": {
569
+ "anyOf": [
570
+ {
571
+ "type": "object",
572
+ "properties": {
573
+ "met": {
574
+ "type": "boolean"
575
+ },
576
+ "unmet": {
577
+ "type": "array",
578
+ "items": {
579
+ "type": "string"
580
+ }
581
+ },
582
+ "reported": {
583
+ "anyOf": [
584
+ {
585
+ "type": "array",
586
+ "items": {
587
+ "type": "string"
588
+ }
589
+ },
590
+ {
591
+ "type": "null"
592
+ }
593
+ ]
594
+ }
595
+ },
596
+ "required": [
597
+ "met",
598
+ "unmet"
599
+ ],
600
+ "additionalProperties": true
601
+ },
602
+ {
603
+ "type": "null"
604
+ }
605
+ ]
606
+ },
529
607
  "blockingCounts": {
530
608
  "anyOf": [
531
609
  {
@@ -873,6 +951,45 @@
873
951
  "type": "null"
874
952
  }
875
953
  ]
954
+ },
955
+ "scope": {
956
+ "anyOf": [
957
+ {
958
+ "type": "object",
959
+ "properties": {
960
+ "met": {
961
+ "type": "boolean"
962
+ },
963
+ "unmet": {
964
+ "type": "array",
965
+ "items": {
966
+ "type": "string"
967
+ }
968
+ },
969
+ "reported": {
970
+ "anyOf": [
971
+ {
972
+ "type": "array",
973
+ "items": {
974
+ "type": "string"
975
+ }
976
+ },
977
+ {
978
+ "type": "null"
979
+ }
980
+ ]
981
+ }
982
+ },
983
+ "required": [
984
+ "met",
985
+ "unmet"
986
+ ],
987
+ "additionalProperties": true
988
+ },
989
+ {
990
+ "type": "null"
991
+ }
992
+ ]
876
993
  }
877
994
  },
878
995
  "required": [
@@ -1298,7 +1415,7 @@
1298
1415
  {
1299
1416
  "id": "hillclimb",
1300
1417
  "title": "Hillclimb",
1301
- "version": "1.4.0",
1418
+ "version": "1.5.0",
1302
1419
  "input": {
1303
1420
  "type": "object",
1304
1421
  "properties": {
@@ -1715,7 +1832,7 @@
1715
1832
  {
1716
1833
  "id": "plan",
1717
1834
  "title": "Plan",
1718
- "version": "2.2.0",
1835
+ "version": "3.0.0",
1719
1836
  "input": {
1720
1837
  "type": "object",
1721
1838
  "properties": {
@@ -1985,7 +2102,8 @@
1985
2102
  },
1986
2103
  "agents": {
1987
2104
  "planner": "planner",
1988
- "reviewer": "reviewer"
2105
+ "reviewer": "reviewer",
2106
+ "plan-reviewer": "plan-reviewer"
1989
2107
  },
1990
2108
  "checkout": "write",
1991
2109
  "when": [],
@@ -3648,6 +3766,45 @@
3648
3766
  "type": "null"
3649
3767
  }
3650
3768
  ]
3769
+ },
3770
+ "scope": {
3771
+ "anyOf": [
3772
+ {
3773
+ "type": "object",
3774
+ "properties": {
3775
+ "met": {
3776
+ "type": "boolean"
3777
+ },
3778
+ "unmet": {
3779
+ "type": "array",
3780
+ "items": {
3781
+ "type": "string"
3782
+ }
3783
+ },
3784
+ "reported": {
3785
+ "anyOf": [
3786
+ {
3787
+ "type": "array",
3788
+ "items": {
3789
+ "type": "string"
3790
+ }
3791
+ },
3792
+ {
3793
+ "type": "null"
3794
+ }
3795
+ ]
3796
+ }
3797
+ },
3798
+ "required": [
3799
+ "met",
3800
+ "unmet"
3801
+ ],
3802
+ "additionalProperties": true
3803
+ },
3804
+ {
3805
+ "type": "null"
3806
+ }
3807
+ ]
3651
3808
  }
3652
3809
  },
3653
3810
  "required": [
@@ -3753,7 +3910,7 @@
3753
3910
  {
3754
3911
  "id": "review",
3755
3912
  "title": "Review",
3756
- "version": "3.9.0",
3913
+ "version": "3.10.0",
3757
3914
  "input": {
3758
3915
  "type": "object",
3759
3916
  "properties": {
@@ -3946,6 +4103,45 @@
3946
4103
  }
3947
4104
  ]
3948
4105
  },
4106
+ "scope": {
4107
+ "anyOf": [
4108
+ {
4109
+ "type": "object",
4110
+ "properties": {
4111
+ "met": {
4112
+ "type": "boolean"
4113
+ },
4114
+ "unmet": {
4115
+ "type": "array",
4116
+ "items": {
4117
+ "type": "string"
4118
+ }
4119
+ },
4120
+ "reported": {
4121
+ "anyOf": [
4122
+ {
4123
+ "type": "array",
4124
+ "items": {
4125
+ "type": "string"
4126
+ }
4127
+ },
4128
+ {
4129
+ "type": "null"
4130
+ }
4131
+ ]
4132
+ }
4133
+ },
4134
+ "required": [
4135
+ "met",
4136
+ "unmet"
4137
+ ],
4138
+ "additionalProperties": true
4139
+ },
4140
+ {
4141
+ "type": "null"
4142
+ }
4143
+ ]
4144
+ },
3949
4145
  "failing": {
3950
4146
  "anyOf": [
3951
4147
  {
@@ -4465,7 +4661,7 @@
4465
4661
  {
4466
4662
  "id": "shepherd",
4467
4663
  "title": "Shepherd",
4468
- "version": "1.9.0",
4664
+ "version": "1.10.0",
4469
4665
  "input": {
4470
4666
  "type": "object",
4471
4667
  "properties": {
@@ -5049,6 +5245,45 @@
5049
5245
  "type": "null"
5050
5246
  }
5051
5247
  ]
5248
+ },
5249
+ "scope": {
5250
+ "anyOf": [
5251
+ {
5252
+ "type": "object",
5253
+ "properties": {
5254
+ "met": {
5255
+ "type": "boolean"
5256
+ },
5257
+ "unmet": {
5258
+ "type": "array",
5259
+ "items": {
5260
+ "type": "string"
5261
+ }
5262
+ },
5263
+ "reported": {
5264
+ "anyOf": [
5265
+ {
5266
+ "type": "array",
5267
+ "items": {
5268
+ "type": "string"
5269
+ }
5270
+ },
5271
+ {
5272
+ "type": "null"
5273
+ }
5274
+ ]
5275
+ }
5276
+ },
5277
+ "required": [
5278
+ "met",
5279
+ "unmet"
5280
+ ],
5281
+ "additionalProperties": true
5282
+ },
5283
+ {
5284
+ "type": "null"
5285
+ }
5286
+ ]
5052
5287
  }
5053
5288
  },
5054
5289
  "required": [
@@ -5548,6 +5783,17 @@
5548
5783
  "security-and-hardening"
5549
5784
  ]
5550
5785
  },
5786
+ "plan-reviewer": {
5787
+ "extends": "reviewer",
5788
+ "instructions": "You are a plan reviewer. You check a plan's tickets before a person is asked to approve them; you report, and the planner revises.\n\n## Scope\n\n- Review only the plan you are given, against the code it is about and what the person asked for. Read that code before judging size and blockers.\n- Judge each ticket as the implementer who gets only that ticket would read it.\n\n## Skills\n\n- Load `skills({ name: 'scope-tasks' })` from the Kitman MCP and hold each ticket to it.\n\n## One pass\n\n- Check every ticket for everything the brief lists the first time. The plan is revised only once before the person sees it.\n- For each blocker, name to yourself the code the ticket needs and the ticket that writes it. A missing blocker and a needless one are both wrong.\n\n## Findings\n\n- Raise only a concern you can defend with what would go wrong when the ticket is built. No opinions on style or on what the person decided.\n- One concern per problem, in a few sentences, with what would answer it.\n- Finding nothing is a real answer: submit an empty list of concerns.\n\n## Rebuttals\n\n- Judge each reason the planner gives for not acting on a concern on its merits.\n- Raise that concern again only if you can answer the reason, and answer it when you do. What you raise again goes to the person with the plan.\n\n## Code comments\n\n- A plan has none to check.",
5789
+ "fallbacks": [
5790
+ {
5791
+ "harness": "claude",
5792
+ "model": "opus",
5793
+ "effort": "high"
5794
+ }
5795
+ ]
5796
+ },
5551
5797
  "planner": {
5552
5798
  "instructions": "You are a planner. You turn what someone asked for into a spec and tickets an implementer can build without asking again.\n\n## Questions\n\n- When your Step runs grill-with-docs, interview the person with the Kitman MCP `ask` tool, never in your reply: walk the decisions one at a time, and ask only when the answer changes what gets built. A clear goal needs no interview and no approval of a summary.\n- Ask one question at a time, and give options when the choices are clear, each with its trade-off in a short `description`.\n- Recommend an answer with `recommended` and say why in `recommendationReason`. Keep the prompt to the context and the decision. Only a question that purely asks for information you cannot guess, such as a secret's name, sets `informationOnly` instead, saying why.\n- Respect decisions already made; do not ask for them again.\n- Push back when an approach has a concrete downside: name it, propose an alternative, then accept the decision.\n\n## Tickets\n\n- Before you write tickets, load `skills({ name: 'scope-tasks' })` from the Kitman MCP and scope each ticket as it says.\n- Write vertical slices: each ticket lands on its own as one ChangeRequest and is verifiable on its own.\n- Give every ticket Acceptance Criteria that a reviewer can check against the change.\n- Give the plan an explicit out-of-scope list, so what was left out is a decision and not an omission.\n- Check the documentation when an API detail affects the plan.\n\n## Boundaries\n\n- Write no code; write only ADR and glossary changes. Your Output is the plan, and Kitman stores it.\n- Never `git stash`: the stash stack is shared with every other worktree of the repository.\n- An implementer that asks you a question gets one answer. Never give an answer and a wider version of it elsewhere: a requirement it was not told about is one it will not build.\n\n## Output\n\nSubmit your Output with the Kitman MCP `submit_output` tool, in the shape the brief's Output schema gives.",
5553
5799
  "harness": "claude",
@@ -5634,7 +5880,7 @@
5634
5880
  "carried": [
5635
5881
  {
5636
5882
  "name": "@kitman-sh/software-engineering",
5637
- "version": "0.13.7",
5883
+ "version": "0.13.9",
5638
5884
  "setup": "2a237548a69b0cd53ec3be7f687cfa8c2128335b3a655d34e185f2abce6a3c37",
5639
5885
  "loops": [
5640
5886
  "build",
@@ -5658,6 +5904,7 @@
5658
5904
  "reviewer",
5659
5905
  "code-reviewer",
5660
5906
  "quality-reviewer",
5907
+ "plan-reviewer",
5661
5908
  "planner",
5662
5909
  "releaser",
5663
5910
  "investigator",
package/kitman.config.ts CHANGED
@@ -68,6 +68,11 @@ export default defineKit({
68
68
  extends: 'reviewer',
69
69
  skills: ['code-review-and-quality', 'security-and-hardening']
70
70
  },
71
+ 'plan-reviewer': {
72
+ extends: 'reviewer',
73
+ fallbacks: [{ harness: 'claude', model: 'opus', effort: 'high' }],
74
+ instructions: { file: 'agents/plan-reviewer.md' }
75
+ },
71
76
  planner: {
72
77
  harness: 'claude',
73
78
  model: 'claude-fable-5-2',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitman-sh/software-engineering",
3
- "version": "0.13.7",
3
+ "version": "0.13.9",
4
4
  "description": "Everything for building software: Loops, their Agents, the skills they use and the Ponytail plugin.",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",
@@ -17,12 +17,12 @@
17
17
  "tsconfig.json"
18
18
  ],
19
19
  "dependencies": {
20
- "@kitman-sh/sdk": "0.13.7",
20
+ "@kitman-sh/sdk": "0.13.9",
21
21
  "effect": "^4.1.2"
22
22
  },
23
23
  "kitman": {
24
24
  "bundle": "dist/bundle.js",
25
- "digest": "4fb614facf6d2f22392e1be3142c31eee106ccf165a3c0fbfe9f71d41cd08766",
25
+ "digest": "7353385c50956862d45b00d01aef6df501970aa4c5a461d851a3a08efbdfbbeb",
26
26
  "protocolVersion": 5,
27
27
  "declarations": "dist/declarations.json",
28
28
  "setup": {
package/src/build.ts CHANGED
@@ -30,7 +30,6 @@ import {
30
30
  type Disputed,
31
31
  MergedFinding,
32
32
  type RallyDecision,
33
- type ScopeJudgement,
34
33
  type SettledRound,
35
34
  type VerifyResult
36
35
  } from '@kitman-sh/sdk/loop'
@@ -46,6 +45,7 @@ import {
46
45
  } from './change-request-body'
47
46
  import { blockingCount, rebuildRefusal } from './convergence'
48
47
  import review from './review'
48
+ import { ReviewedScope } from './reviewed-scope'
49
49
  import shepherd from './shepherd'
50
50
  import { ShepherdOutput } from './shepherd-output'
51
51
  import { DeliveryFields, epicOf, ownDeliveryTarget } from './delivery'
@@ -83,6 +83,8 @@ export const BuildInput = Schema.Struct({
83
83
  /** The head an earlier review read, whose `earlier` findings this Build fixes: its first review reviews the fix. */
84
84
  reviewed: Schema.optional(Schema.String),
85
85
  earlier: Schema.optional(Schema.Array(MergedFinding)),
86
+ /** That review's scope judgement, whose unmet items this Build's first review judges again. */
87
+ scope: Schema.optional(ReviewedScope),
86
88
  ...DeliveryFields
87
89
  })
88
90
 
@@ -153,6 +155,8 @@ export const BuildOutput = Schema.Struct({
153
155
  notRun: Schema.optional(Schema.Array(Schema.String)),
154
156
  /** The last review's code findings still open or disputed, which a Build fixing them takes as `earlier`. */
155
157
  findings: Schema.optional(Schema.Array(MergedFinding)),
158
+ /** The last review's scope judgement, which a Build fixing what it left takes as `scope`. */
159
+ scope: Schema.optional(ReviewedScope),
156
160
  /** Each Review round's blocking count, first to last, which decides whether a Rebuild may follow. */
157
161
  blockingCounts: Schema.optional(Schema.Array(Schema.Int)),
158
162
  /** Whether the last Review's approval was recorded, or why not, when nothing was left unsettled. */
@@ -295,7 +299,7 @@ type Round = {
295
299
  readonly settled: SettledRound
296
300
  readonly decision: RallyDecision & { readonly stop: true }
297
301
  readonly claims: readonly string[]
298
- readonly scope: ScopeJudgement | undefined
302
+ readonly scope: typeof ReviewedScope.Type | undefined
299
303
  readonly conflicts: readonly string[]
300
304
  readonly earlier: readonly MergedFinding[]
301
305
  readonly blockingCounts: readonly number[]
@@ -315,6 +319,7 @@ const rally = (input: {
315
319
  readonly reproducing: typeof SuggestedCheck.Type | undefined
316
320
  readonly reviewed: string | undefined
317
321
  readonly earlier: readonly MergedFinding[]
322
+ readonly scope: typeof ReviewedScope.Type | undefined
318
323
  }) =>
319
324
  Effect.gen(function* () {
320
325
  const claims = [...input.claims]
@@ -369,6 +374,8 @@ const rally = (input: {
369
374
  const failing = brokenChecks(head).map(check => check.name)
370
375
  const notRun = testsNotRunReasons(head)
371
376
 
377
+ const scope = last === undefined ? input.scope : last.scope
378
+
372
379
  const reviewed = yield* call(`review:${round}`, review, {
373
380
  base,
374
381
  head: head.revision,
@@ -379,6 +386,7 @@ const rally = (input: {
379
386
  ? undefined
380
387
  : { reviewed: input.reviewed }
381
388
  : { reviewed: last.head.revision }),
389
+ ...(scope === undefined ? undefined : { scope }),
382
390
  ...(input.outcome === undefined ? undefined : { outcome: input.outcome }),
383
391
  ...(failing.length === 0 ? undefined : { failing }),
384
392
  ...(notRun.length === 0 ? undefined : { notRun }),
@@ -462,7 +470,7 @@ const rally = (input: {
462
470
  */
463
471
  const build = defineLoop({
464
472
  id: 'build',
465
- version: '2.10.0',
473
+ version: '2.11.0',
466
474
  title: 'Build',
467
475
  input: BuildInput,
468
476
  output: BuildOutput,
@@ -553,7 +561,8 @@ const build = defineLoop({
553
561
  suggested: implemented.checks ?? [],
554
562
  reproducing: reproduced?.check,
555
563
  reviewed: input.reviewed,
556
- earlier: input.earlier ?? []
564
+ earlier: input.earlier ?? [],
565
+ scope: input.scope
557
566
  })
558
567
 
559
568
  const verdict = evidenceGate({
@@ -630,6 +639,7 @@ const build = defineLoop({
630
639
  criteria,
631
640
  ...(lastNotRun.length === 0 ? undefined : { notRun: lastNotRun }),
632
641
  ...(last.earlier.length === 0 ? undefined : { findings: last.earlier }),
642
+ ...(last.scope === undefined ? undefined : { scope: last.scope }),
633
643
  blockingCounts: last.blockingCounts,
634
644
  ...(approval === undefined ? undefined : { approval })
635
645
  }
@@ -711,6 +721,7 @@ const build = defineLoop({
711
721
  // Its first review reviews the fix of what the last review read.
712
722
  reviewed: settledAs.revision,
713
723
  ...(settledAs.findings === undefined ? undefined : { earlier: settledAs.findings }),
724
+ ...(settledAs.scope === undefined ? undefined : { scope: settledAs.scope }),
714
725
  ...ownDeliveryTarget(input)
715
726
  },
716
727
  { 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.4.0',
188
+ version: '1.5.0',
189
189
  title: 'Hillclimb',
190
190
  outcome: 'performance',
191
191
  input: Input,
@@ -389,8 +389,9 @@ export default defineLoop({
389
389
  outcome: 'performance',
390
390
  ...notRunOf(fixed),
391
391
  claims,
392
- earlier: blocking,
393
- reviewed: fixedFrom
392
+ earlier: reviewed.findings,
393
+ reviewed: fixedFrom,
394
+ ...(reviewed.scope === undefined ? undefined : { scope: reviewed.scope })
394
395
  })
395
396
  }
396
397
 
@@ -0,0 +1,155 @@
1
+ import { agentWork, type PlanTicket } from '@kitman-sh/sdk/loop'
2
+ import * as Effect from 'effect/Effect'
3
+ import * as Schema from 'effect/Schema'
4
+ import { Reason } from './text-limits'
5
+
6
+ const Concern = Schema.Struct({
7
+ /** The key of the ticket it is about; the whole plan when left out. */
8
+ ticket: Schema.optional(Schema.String),
9
+ concern: Reason
10
+ })
11
+
12
+ const Check = Schema.Struct({ concerns: Schema.Array(Concern) })
13
+
14
+ const Recheck = Schema.Struct({
15
+ concerns: Schema.Array(
16
+ Schema.Struct({
17
+ ...Concern.fields,
18
+ /** The id of the concern of the first check this one still holds; none for a new one. */
19
+ earlier: Schema.optional(Schema.String)
20
+ })
21
+ )
22
+ })
23
+
24
+ /** Why the planner did not act on a concern, by the concern's id. */
25
+ export const DeclinedConcern = Schema.Struct({ concern: Schema.String, why: Reason })
26
+
27
+ export type DeclinedConcern = typeof DeclinedConcern.Type
28
+
29
+ export type PlanConcern = typeof Concern.Type & { readonly id: string }
30
+
31
+ /** A concern the reviewer holds after the revision, and why the planner did not act on it when it said so. */
32
+ export type DisputedConcern = typeof Concern.Type & { readonly declined?: string }
33
+
34
+ type Revision<Plan> = { readonly plan: Plan; readonly declined: readonly DeclinedConcern[] }
35
+
36
+ type PlanUnderReview<Plan, E, R> = {
37
+ readonly plan: Plan
38
+ /** What the person asked for, which neither the review nor the revision may go against. */
39
+ readonly asked: string
40
+ readonly text: (plan: Plan) => string
41
+ /** Revises the plan as the Step it is named, from a prompt that holds the concerns. */
42
+ readonly revise: (step: string, prompt: string) => Effect.Effect<Revision<Plan>, E, R>
43
+ }
44
+
45
+ export const outOfScopeText = ({ outOfScope = [] }: PlanTicket) =>
46
+ outOfScope.length === 0 ? [] : ['Out of scope:', ...outOfScope.map(item => `- ${item}`)]
47
+
48
+ export const ticketText = (ticket: PlanTicket) =>
49
+ [
50
+ `### ${ticket.key}: ${ticket.title}`,
51
+ ticket.body,
52
+ ...(ticket.promise === undefined ? [] : [`Promise: ${ticket.promise}`]),
53
+ ...ticket.acceptanceCriteria.map(criterion => `- [ ] ${criterion}`),
54
+ ...outOfScopeText(ticket),
55
+ ...(ticket.repoBindingId === undefined ? [] : [`Repository (repoBindingId): ${ticket.repoBindingId}`]),
56
+ ...(ticket.outcome === undefined ? [] : [`Outcome: ${ticket.outcome}`]),
57
+ ...(ticket.blockedBy.length === 0 ? [] : [`Blocked by: ${ticket.blockedBy.join(', ')}`])
58
+ ].join('\n\n')
59
+
60
+ const checks = [
61
+ "Load skills({ name: 'scope-tasks' }) from the Kitman MCP, read the code the plan is about, and check every ticket for each of these:",
62
+ [
63
+ '- One Promise: the ticket promises one thing, and its Out of scope list names the cases it does not handle. An open-ended Promise is a concern.',
64
+ '- Size: estimate the context one agent session needs from reading the code to a verified change. 200k tokens or more is a concern; give your estimate.',
65
+ '- Decisions: no design decision is left to the implementer.',
66
+ '- Blockers: it is blocked by each ticket whose code it needs, and by no other.'
67
+ ].join('\n'),
68
+ "Give each concern its ticket's key, and say what would answer it. What the person asked for is not a concern. Submit no concerns when every ticket holds. Change nothing."
69
+ ].join('\n\n')
70
+
71
+ const askedText = (asked: string) =>
72
+ `What the person asked for, in turn; where two differ, the later one holds:\n\n${asked}`
73
+
74
+ const answeredConcern = (concern: PlanConcern, declined: readonly DeclinedConcern[] = []) => {
75
+ const why = declined.find(entry => entry.concern === concern.id)?.why
76
+
77
+ return [
78
+ `${concern.id}${concern.ticket === undefined ? '' : `, on ${concern.ticket}`}: ${concern.concern}`,
79
+ ...(why === undefined ? [] : [`The planner did not act on it: ${why}`])
80
+ ].join('\n')
81
+ }
82
+
83
+ const checkPrompt = (asked: string, text: string) =>
84
+ ['Review this plan before a person is asked to approve it.', checks, askedText(asked), text].join('\n\n')
85
+
86
+ const revisePrompt = (asked: string, text: string, concerns: readonly PlanConcern[]) =>
87
+ [
88
+ 'A reviewer checked the plan before a person is asked to approve it. Revise it to answer each concern, and keep what the person asked for and what no concern is about. Change no files; a decision a concern asks for goes in the plan. List in declined the id of each concern you did not act on and why; keep that out of the plan itself.',
89
+ concerns.map(concern => answeredConcern(concern)).join('\n\n'),
90
+ askedText(asked),
91
+ text
92
+ ].join('\n\n')
93
+
94
+ const recheckPrompt = (
95
+ asked: string,
96
+ text: string,
97
+ concerns: readonly PlanConcern[],
98
+ declined: readonly DeclinedConcern[]
99
+ ) =>
100
+ [
101
+ 'The planner revised this plan after your review. Check it once more. Raise again only a concern the revision does not answer, with its id in earlier; when the planner gave a reason not to act on it, raise it only if you can answer the reason. What you raise is shown to the person with the plan as still disputed.',
102
+ checks,
103
+ 'Your concerns on the plan before its revision:',
104
+ concerns.map(concern => answeredConcern(concern, declined)).join('\n\n'),
105
+ askedText(asked),
106
+ text
107
+ ].join('\n\n')
108
+
109
+ /**
110
+ * Has the calling Loop's `plan-reviewer` check a plan; when it has concerns, the plan is revised once and checked
111
+ * again. Returns the plan to show a person and what the reviewer still disputes.
112
+ */
113
+ export const reviewPlan = <Plan, E, R>(step: string, { plan, asked, text, revise }: PlanUnderReview<Plan, E, R>) =>
114
+ Effect.gen(function* () {
115
+ const first = yield* agentWork(step, {
116
+ agent: 'plan-reviewer',
117
+ prompt: checkPrompt(asked, text(plan)),
118
+ output: Check
119
+ })
120
+
121
+ if (first.concerns.length === 0) return { plan, disputed: [] }
122
+
123
+ const concerns = first.concerns.map((concern, index) => ({ ...concern, id: `c${index + 1}` }))
124
+ const revised = yield* revise(`${step}:revise`, revisePrompt(asked, text(plan), concerns))
125
+
126
+ const again = yield* agentWork(`${step}:recheck`, {
127
+ agent: 'plan-reviewer',
128
+ prompt: recheckPrompt(asked, text(revised.plan), concerns, revised.declined),
129
+ output: Recheck
130
+ })
131
+
132
+ const disputed = again.concerns.map(({ earlier, ...concern }): DisputedConcern => {
133
+ const declined = revised.declined.find(entry => entry.concern === earlier)?.why
134
+
135
+ return declined === undefined ? concern : { ...concern, declined }
136
+ })
137
+
138
+ return { plan: revised.plan, disputed }
139
+ })
140
+
141
+ const oneLine = (text: string) => text.replace(/\s+/gu, ' ').trim()
142
+
143
+ /** What is still disputed, as the section of the plan's Markdown a person reads it in. */
144
+ export const disputedText = (disputed: readonly DisputedConcern[]) =>
145
+ disputed.length === 0
146
+ ? []
147
+ : [
148
+ '## Still disputed',
149
+ disputed
150
+ .flatMap(({ ticket, concern, declined }) => [
151
+ `- ${ticket === undefined ? '' : `${ticket}: `}${oneLine(concern)}`,
152
+ ...(declined === undefined ? [] : [` - The planner did not act on it: ${oneLine(declined)}`])
153
+ ])
154
+ .join('\n')
155
+ ]