@v11g/agents-rock 1.0.7 → 1.0.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.
Files changed (215) hide show
  1. package/README.md +1 -1
  2. package/package.json +1 -1
  3. package/plugins/reasoning/.claude-plugin/plugin.json +1 -1
  4. package/plugins/reasoning/evals/format-handoff-folder/graders/folder-named.md +8 -0
  5. package/plugins/reasoning/evals/format-handoff-folder/graders/skill-fired.md +7 -0
  6. package/plugins/reasoning/evals/format-handoff-folder/prompt.md +9 -0
  7. package/plugins/reasoning/evals/format-ids-and-supports/graders/ids-in-chat.md +8 -0
  8. package/plugins/reasoning/evals/format-ids-and-supports/graders/skill-fired.md +7 -0
  9. package/plugins/reasoning/evals/format-ids-and-supports/graders/supports-resolve.md +11 -0
  10. package/plugins/reasoning/evals/format-ids-and-supports/prompt.md +8 -0
  11. package/plugins/reasoning/evals/format-root-candidate-status/graders/candidate-status.md +11 -0
  12. package/plugins/reasoning/evals/format-root-candidate-status/graders/skill-fired.md +7 -0
  13. package/plugins/reasoning/evals/format-root-candidate-status/prompt.md +8 -0
  14. package/plugins/reasoning/evals/format-unsaved-continues/graders/analysis-completes.md +9 -0
  15. package/plugins/reasoning/evals/format-unsaved-continues/graders/not-saved-stated.md +9 -0
  16. package/plugins/reasoning/evals/format-unsaved-continues/graders/skill-fired.md +7 -0
  17. package/plugins/reasoning/evals/format-unsaved-continues/prompt.md +8 -0
  18. package/plugins/reasoning/evals/guardrail-unavailable-framework/graders/names-closest-available.md +5 -6
  19. package/plugins/reasoning/evals/guardrail-unavailable-framework/graders/no-improvised-levels.md +4 -6
  20. package/plugins/reasoning/evals/guardrail-unavailable-framework/graders/skill-fired.md +1 -1
  21. package/plugins/reasoning/evals/guardrail-unavailable-framework/graders/states-unavailable.md +4 -5
  22. package/plugins/reasoning/evals/guardrail-unavailable-framework/graders/systemic-design-fired.md +10 -0
  23. package/plugins/reasoning/evals/guardrail-unavailable-framework/prompt.md +2 -2
  24. package/plugins/reasoning/evals/ps-interview-first-question/graders/look-in-present.md +10 -0
  25. package/plugins/reasoning/evals/ps-interview-first-question/graders/no-fixed-exits.md +11 -0
  26. package/plugins/reasoning/evals/ps-interview-first-question/graders/options-from-input.md +15 -0
  27. package/plugins/reasoning/evals/ps-interview-first-question/graders/skill-fired.md +7 -0
  28. package/plugins/reasoning/evals/ps-interview-first-question/graders/source-hint.md +11 -0
  29. package/plugins/reasoning/evals/ps-interview-first-question/graders/targets-gap.md +13 -0
  30. package/plugins/reasoning/evals/ps-interview-first-question/prompt.md +8 -0
  31. package/plugins/reasoning/evals/ps-interview-five-whys/graders/look-in-present.md +10 -0
  32. package/plugins/reasoning/evals/ps-interview-five-whys/graders/no-fixed-exits.md +11 -0
  33. package/plugins/reasoning/evals/ps-interview-five-whys/graders/options-from-input.md +11 -0
  34. package/plugins/reasoning/evals/ps-interview-five-whys/graders/skill-fired.md +7 -0
  35. package/plugins/reasoning/evals/ps-interview-five-whys/graders/source-hint.md +11 -0
  36. package/plugins/reasoning/evals/ps-interview-five-whys/graders/targets-gap.md +15 -0
  37. package/plugins/reasoning/evals/ps-interview-five-whys/prompt.md +8 -0
  38. package/plugins/reasoning/evals/ps-router-handoff/graders/no-reselection.md +11 -0
  39. package/plugins/reasoning/evals/ps-router-handoff/graders/runs-rca.md +8 -0
  40. package/plugins/reasoning/evals/ps-router-handoff/graders/skill-fired.md +7 -0
  41. package/plugins/reasoning/evals/ps-router-handoff/prompt.md +11 -0
  42. package/plugins/reasoning/evals/routing-adaptive-discriminator/graders/confidence-single-word.md +10 -0
  43. package/plugins/reasoning/evals/routing-ambiguous-feature-request/graders/confidence-single-word.md +10 -0
  44. package/plugins/reasoning/evals/routing-classify-only/graders/confidence-single-word.md +10 -0
  45. package/plugins/reasoning/evals/routing-complex-adaptive-org-change/graders/confidence-single-word.md +10 -0
  46. package/plugins/reasoning/evals/routing-complex-adaptive-org-change/graders/no-unavailability-claim.md +10 -0
  47. package/plugins/reasoning/evals/routing-complex-delivery-slowdown/graders/confidence-single-word.md +10 -0
  48. package/plugins/reasoning/evals/routing-simple-null-pointer/graders/confidence-single-word.md +10 -0
  49. package/plugins/reasoning/evals/routing-thin-input-provisional/graders/confidence-single-word.md +10 -0
  50. package/plugins/reasoning/evals/sd-default-selection/graders/dates-traced.md +15 -0
  51. package/plugins/reasoning/evals/sd-default-selection/graders/interventions-cite-entries.md +12 -0
  52. package/plugins/reasoning/evals/sd-default-selection/graders/owners-from-input.md +8 -0
  53. package/plugins/reasoning/evals/sd-default-selection/graders/plan-steps-complete.md +21 -0
  54. package/plugins/reasoning/evals/sd-default-selection/graders/selects-systemic-design.md +12 -0
  55. package/plugins/reasoning/evals/sd-default-selection/graders/skill-fired.md +7 -0
  56. package/plugins/reasoning/evals/sd-default-selection/graders/systemic-design-fired.md +10 -0
  57. package/plugins/reasoning/evals/sd-default-selection/prompt.md +11 -0
  58. package/plugins/reasoning/evals/sd-named-framework-software/graders/names-no-skill.md +11 -0
  59. package/plugins/reasoning/evals/sd-named-framework-software/graders/no-systemic-block.md +10 -0
  60. package/plugins/reasoning/evals/sd-named-framework-software/graders/systemic-design-fired.md +10 -0
  61. package/plugins/reasoning/evals/sd-named-framework-software/prompt.md +8 -0
  62. package/plugins/reasoning/evals/sd-not-software/graders/no-systemic-block.md +10 -0
  63. package/plugins/reasoning/evals/sd-not-software/graders/says-out-of-scope.md +10 -0
  64. package/plugins/reasoning/evals/sd-not-software/prompt.md +8 -0
  65. package/plugins/reasoning/evals/sd-raw-input/graders/first-question-targets-model.md +11 -0
  66. package/plugins/reasoning/evals/sd-raw-input/graders/look-in-present.md +10 -0
  67. package/plugins/reasoning/evals/sd-raw-input/graders/model-gap-blocks-stop.md +14 -0
  68. package/plugins/reasoning/evals/sd-raw-input/graders/model-in-assumptions.md +13 -0
  69. package/plugins/reasoning/evals/sd-raw-input/graders/no-fixed-exits.md +11 -0
  70. package/plugins/reasoning/evals/sd-raw-input/graders/skill-fired.md +7 -0
  71. package/plugins/reasoning/evals/sd-raw-input/graders/systemic-design-fired.md +10 -0
  72. package/plugins/reasoning/evals/sd-raw-input/prompt.md +8 -0
  73. package/plugins/reasoning/evals/sd-theory-of-change/graders/links-carry-assumptions.md +9 -0
  74. package/plugins/reasoning/evals/sd-theory-of-change/graders/no-dates.md +8 -0
  75. package/plugins/reasoning/evals/sd-theory-of-change/graders/skill-fired.md +7 -0
  76. package/plugins/reasoning/evals/sd-theory-of-change/graders/systemic-design-fired.md +10 -0
  77. package/plugins/reasoning/evals/sd-theory-of-change/graders/toc-block.md +10 -0
  78. package/plugins/reasoning/evals/sd-theory-of-change/prompt.md +8 -0
  79. package/plugins/reasoning/evals/sd-three-horizons/graders/dates-are-assumptions.md +11 -0
  80. package/plugins/reasoning/evals/sd-three-horizons/graders/owners-are-roles.md +8 -0
  81. package/plugins/reasoning/evals/sd-three-horizons/graders/skill-fired.md +7 -0
  82. package/plugins/reasoning/evals/sd-three-horizons/graders/systemic-design-fired.md +10 -0
  83. package/plugins/reasoning/evals/sd-three-horizons/graders/three-horizons-block.md +10 -0
  84. package/plugins/reasoning/evals/sd-three-horizons/prompt.md +9 -0
  85. package/plugins/reasoning/evals/st-causal-loop-unclosed/graders/edges-carry-support-labels.md +2 -2
  86. package/plugins/reasoning/evals/st-causal-loop-unclosed/graders/no-invented-delays.md +7 -4
  87. package/plugins/reasoning/evals/st-interview-first-question/graders/look-in-present.md +10 -0
  88. package/plugins/reasoning/evals/st-interview-first-question/graders/no-fixed-exits.md +11 -0
  89. package/plugins/reasoning/evals/st-interview-first-question/graders/options-from-input.md +11 -0
  90. package/plugins/reasoning/evals/st-interview-first-question/graders/skill-fired.md +7 -0
  91. package/plugins/reasoning/evals/st-interview-first-question/graders/source-hint.md +11 -0
  92. package/plugins/reasoning/evals/st-interview-first-question/graders/targets-gap.md +13 -0
  93. package/plugins/reasoning/evals/st-interview-first-question/prompt.md +8 -0
  94. package/plugins/reasoning/evals/st-selection-boundary/graders/one-block-only.md +9 -6
  95. package/plugins/reasoning/skills/problem-router/README.md +6 -0
  96. package/plugins/reasoning/skills/problem-router/SKILL.md +11 -11
  97. package/plugins/reasoning/skills/problem-router/references/contract.md +117 -16
  98. package/plugins/reasoning/skills/problem-solving/README.md +10 -0
  99. package/plugins/reasoning/skills/problem-solving/SKILL.md +15 -3
  100. package/plugins/reasoning/skills/problem-solving/references/contract.md +117 -16
  101. package/plugins/reasoning/skills/problem-solving/references/interview.md +68 -0
  102. package/plugins/reasoning/skills/systemic-design/README.md +45 -0
  103. package/plugins/reasoning/skills/systemic-design/SKILL.md +184 -0
  104. package/plugins/reasoning/skills/systemic-design/frameworks/systemic-design.md +39 -0
  105. package/plugins/reasoning/skills/systemic-design/frameworks/theory-of-change.md +34 -0
  106. package/plugins/reasoning/skills/systemic-design/frameworks/three-horizons.md +28 -0
  107. package/plugins/reasoning/skills/systemic-design/references/contract.md +205 -0
  108. package/plugins/reasoning/skills/systemic-design/references/interview.md +68 -0
  109. package/plugins/reasoning/skills/systems-thinking/README.md +13 -6
  110. package/plugins/reasoning/skills/systems-thinking/SKILL.md +18 -6
  111. package/plugins/reasoning/skills/systems-thinking/frameworks/causal-loop.md +5 -2
  112. package/plugins/reasoning/skills/systems-thinking/frameworks/leverage-points.md +16 -7
  113. package/plugins/reasoning/skills/systems-thinking/frameworks/system-map.md +4 -5
  114. package/plugins/reasoning/skills/systems-thinking/references/contract.md +117 -16
  115. package/plugins/reasoning/skills/systems-thinking/references/interview.md +68 -0
  116. package/plugins/solution-architect/.claude-plugin/plugin.json +1 -1
  117. package/plugins/solution-architect/skills/analyze-requirements/SKILL.md +3 -2
  118. package/plugins/solution-architect/skills/analyze-requirements/references/rewriting.md +108 -0
  119. package/plugins/solution-architect/skills/analyze-requirements/scripts/drift.mjs +64 -0
  120. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/cdp.mjs +4 -1
  121. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/drift.mjs +31 -0
  122. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/git-diff.mjs +27 -0
  123. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/quality-gate.mjs +16 -1
  124. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/state.mjs +52 -0
  125. package/plugins/solution-architect/skills/analyze-requirements/scripts/record.mjs +87 -0
  126. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/drift-cli.test.mjs +178 -0
  127. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/drift.test.mjs +76 -0
  128. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/git-diff.test.mjs +62 -0
  129. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/quality-gate.test.mjs +9 -0
  130. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/record-cli.test.mjs +136 -0
  131. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/rerun-safety.test.mjs +53 -0
  132. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/rewriting.test.mjs +80 -0
  133. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/state.test.mjs +123 -0
  134. package/plugins/solution-architect/skills/estimate/README.md +20 -15
  135. package/plugins/solution-architect/skills/estimate/SKILL.md +10 -6
  136. package/plugins/solution-architect/skills/estimate/assets/estimate-template-agentic.html +111 -138
  137. package/plugins/solution-architect/skills/estimate/assets/estimate-template.html +361 -247
  138. package/plugins/solution-architect/skills/estimate/assets/scores-review-template.html +5 -4
  139. package/plugins/solution-architect/skills/estimate/evals/evals.json +7 -7
  140. package/plugins/solution-architect/skills/estimate/references/agentic-estimation.md +4 -2
  141. package/plugins/solution-architect/skills/estimate/references/ai-multipliers.md +38 -82
  142. package/plugins/solution-architect/skills/estimate/references/interview.md +56 -35
  143. package/plugins/solution-architect/skills/estimate/references/scoring-guide.md +40 -4
  144. package/plugins/solution-architect/skills/estimate/references/techniques.md +29 -21
  145. package/plugins/solution-architect/skills/estimate/references/writing.md +75 -43
  146. package/plugins/solution-architect/skills/estimate/scripts/lib/checks.mjs +37 -5
  147. package/plugins/solution-architect/skills/estimate/scripts/lib/context-schema.mjs +35 -0
  148. package/plugins/solution-architect/skills/estimate/scripts/lib/estimate-math.mjs +17 -75
  149. package/plugins/solution-architect/skills/estimate/scripts/lib/inline.mjs +5 -5
  150. package/plugins/solution-architect/skills/estimate/scripts/lib/pricing.mjs +78 -0
  151. package/plugins/solution-architect/skills/estimate/scripts/lib/project-price.mjs +96 -0
  152. package/plugins/solution-architect/skills/estimate/scripts/lib/redact.mjs +67 -19
  153. package/plugins/solution-architect/skills/estimate/scripts/lib/roadmap.mjs +4 -5
  154. package/plugins/solution-architect/skills/estimate/scripts/lib/rollup.mjs +48 -73
  155. package/plugins/solution-architect/skills/estimate/scripts/lib/schema.mjs +28 -13
  156. package/plugins/solution-architect/skills/estimate/scripts/lib/score-csv.mjs +2 -2
  157. package/plugins/solution-architect/skills/estimate/scripts/lib/score-html.mjs +1 -1
  158. package/plugins/solution-architect/skills/estimate/scripts/lib/scoring.mjs +2 -2
  159. package/plugins/solution-architect/skills/estimate/scripts/render.mjs +1 -1
  160. package/plugins/solution-architect/skills/estimate/scripts/score-review.mjs +1 -1
  161. package/plugins/solution-architect/skills/estimate/scripts/test/browser-agentic.test.mjs +143 -0
  162. package/plugins/solution-architect/skills/estimate/scripts/test/browser.test.mjs +209 -50
  163. package/plugins/solution-architect/skills/estimate/scripts/test/compute.test.mjs +57 -32
  164. package/plugins/solution-architect/skills/estimate/scripts/test/e2e.test.mjs +52 -0
  165. package/plugins/solution-architect/skills/estimate/scripts/test/estimate-math.test.mjs +25 -112
  166. package/plugins/solution-architect/skills/estimate/scripts/test/fixtures/agentic-estimation-fail.md +0 -10
  167. package/plugins/solution-architect/skills/estimate/scripts/test/fixtures/agentic-estimation-pass.md +0 -10
  168. package/plugins/solution-architect/skills/estimate/scripts/test/fixtures/agentic-inputs.json +1 -7
  169. package/plugins/solution-architect/skills/estimate/scripts/test/fixtures/booking-inputs.json +11 -10
  170. package/plugins/solution-architect/skills/estimate/scripts/test/fixtures/estimation-fail.md +6 -0
  171. package/plugins/solution-architect/skills/estimate/scripts/test/fixtures/estimation-pass.md +17 -21
  172. package/plugins/solution-architect/skills/estimate/scripts/test/pricing.test.mjs +88 -0
  173. package/plugins/solution-architect/skills/estimate/scripts/test/project-price.test.mjs +93 -0
  174. package/plugins/solution-architect/skills/estimate/scripts/test/references.test.mjs +86 -24
  175. package/plugins/solution-architect/skills/estimate/scripts/test/render.test.mjs +185 -31
  176. package/plugins/solution-architect/skills/estimate/scripts/test/schema.test.mjs +114 -61
  177. package/plugins/solution-architect/skills/estimate/scripts/test/score-review.test.mjs +34 -1
  178. package/plugins/solution-architect/skills/estimate/scripts/test/validate.test.mjs +103 -9
  179. package/plugins/solution-architect/skills/estimate/scripts/test/xlsx-export.test.mjs +292 -71
  180. package/plugins/solution-architect/skills/new-lead/SKILL.md +4 -3
  181. package/plugins/solution-architect/skills/proposal/README.md +9 -7
  182. package/plugins/solution-architect/skills/proposal/SKILL.md +10 -7
  183. package/plugins/solution-architect/skills/proposal/evals/evals.json +29 -11
  184. package/plugins/solution-architect/skills/proposal/evals/fixtures/gate-check-unpriced-harborline/ARCHITECTURE.md +65 -0
  185. package/plugins/solution-architect/skills/proposal/evals/fixtures/gate-check-unpriced-harborline/brief.md +21 -0
  186. package/plugins/solution-architect/skills/proposal/evals/fixtures/gate-check-unpriced-harborline/estimation-inputs.json +126 -0
  187. package/plugins/solution-architect/skills/proposal/evals/fixtures/gate-check-unpriced-harborline/estimation.json +215 -0
  188. package/plugins/solution-architect/skills/proposal/evals/fixtures/pre-fed-harborline-dispatch/estimation-inputs.json +224 -34
  189. package/plugins/solution-architect/skills/proposal/evals/fixtures/pre-fed-harborline-dispatch/estimation.json +103 -114
  190. package/plugins/solution-architect/skills/proposal/evals/fixtures/pre-fed-harborline-dispatch/estimation.md +48 -22
  191. package/plugins/solution-architect/skills/proposal/evals/fixtures/pre-fed-meridian-dental/estimation-inputs.json +211 -33
  192. package/plugins/solution-architect/skills/proposal/evals/fixtures/pre-fed-meridian-dental/estimation.json +102 -117
  193. package/plugins/solution-architect/skills/proposal/evals/fixtures/pre-fed-meridian-dental/estimation.md +48 -25
  194. package/plugins/solution-architect/skills/proposal/references/interview.md +3 -6
  195. package/plugins/solution-architect/skills/proposal/references/review.md +5 -4
  196. package/plugins/solution-architect/skills/proposal/references/writing.md +33 -31
  197. package/plugins/solution-architect/skills/proposal/scripts/derive.mjs +1 -1
  198. package/plugins/solution-architect/skills/proposal/scripts/lib/checks-client.mjs +5 -22
  199. package/plugins/solution-architect/skills/proposal/scripts/lib/checks-doc.mjs +18 -8
  200. package/plugins/solution-architect/skills/proposal/scripts/lib/checks.mjs +6 -2
  201. package/plugins/solution-architect/skills/proposal/scripts/lib/figures.mjs +24 -33
  202. package/plugins/solution-architect/skills/proposal/scripts/lib/sections.mjs +1 -1
  203. package/plugins/solution-architect/skills/proposal/scripts/test/checks-client.test.mjs +50 -47
  204. package/plugins/solution-architect/skills/proposal/scripts/test/checks-doc.test.mjs +99 -40
  205. package/plugins/solution-architect/skills/proposal/scripts/test/docs.test.mjs +11 -5
  206. package/plugins/solution-architect/skills/proposal/scripts/test/e2e.test.mjs +1 -1
  207. package/plugins/solution-architect/skills/proposal/scripts/test/evals-fixtures.test.mjs +39 -0
  208. package/plugins/solution-architect/skills/proposal/scripts/test/figures.test.mjs +67 -54
  209. package/plugins/solution-architect/skills/proposal/scripts/test/fixtures/proposal-fail.md +6 -1
  210. package/plugins/solution-architect/skills/proposal/scripts/test/fixtures/proposal-pass.md +8 -12
  211. package/plugins/solution-architect/skills/proposal/scripts/test/render.test.mjs +1 -1
  212. package/plugins/solution-architect/skills/proposal/scripts/test/validate.test.mjs +3 -2
  213. package/plugins/reasoning/evals/guardrail-unavailable-framework/graders/names-owning-skill.md +0 -9
  214. package/plugins/reasoning/evals/routing-complex-adaptive-org-change/graders/states-systemic-design-unavailable.md +0 -15
  215. package/plugins/solution-architect/skills/estimate/scripts/lib/scenario-schema.mjs +0 -39
@@ -28,8 +28,11 @@ not earned.
28
28
  5. For each loop, state whether it is reinforcing (the effect feeds the
29
29
  cause) or balancing (the effect dampens the cause), and name the link
30
30
  that makes it so.
31
- 6. Record a `delays` entry only where the input states a lag. An inferred
32
- delay is an `assumptions` entry, not a `delays` entry.
31
+ 6. Record a `delays` entry only where the input states a lag: a duration
32
+ ("about six weeks later") or an explicit "after a delay". A dated
33
+ sequence ("prices rose in March, churn rose in April") is not a stated
34
+ lag. An inferred delay, including one read off dates, is an
35
+ `assumptions` entry, not a `delays` entry.
33
36
 
34
37
  ## Output block
35
38
 
@@ -30,8 +30,11 @@ and visibly so.
30
30
  presenting it as observed.
31
31
 
32
32
  2. Build `points`. For each element, ask whether intervening there would
33
- change the behaviour. Record `intervention`, `level`, `expected_effect`,
34
- `risks`, and `evidence`.
33
+ change the behaviour. Record `intervention`, `element` (the id of the
34
+ `elements` row it sits on), `level`, `expected_effect`, and `risks`.
35
+ Evidence for the point is not a field here — it lives in the core
36
+ `evidence`/`assumptions` lists, which `supports` the element and the
37
+ point by id.
35
38
 
36
39
  3. `level` must match the `kind` of a row in `elements`. A level with no
37
40
  matching row is an intervention into a part of the system you have not
@@ -52,18 +55,24 @@ Emit the `leverage_points` block from `references/contract.md`: `elements`,
52
55
  ```yaml
53
56
  leverage_points:
54
57
  elements:
55
- - element: "senior engineers triage all inbound requests"
58
+ - id: c1
59
+ element: "senior engineers triage all inbound requests"
56
60
  kind: rule
57
61
  evidence: user-provided fact
58
- - element: "throughput is measured per-team"
62
+ - id: c2
63
+ element: "throughput is measured per-team"
59
64
  kind: incentive
60
65
  evidence: inferred
61
66
  points:
62
- - intervention: "route triage through a rota"
67
+ - id: c3
68
+ intervention: "route triage through a rota"
69
+ element: c1
63
70
  level: rule
64
71
  expected_effect: "spreads interrupt load off the two named seniors"
65
72
  risks: "triage quality drops while the rota ramps"
66
- evidence: "user-provided fact: seniors are constantly interrupted"
73
+ # Evidence and assumptions are core fields, not a point field: an
74
+ # `evidence` entry with `supports: [c1, c3]` backs the element and the
75
+ # point that sits on it.
67
76
  ```
68
77
 
69
78
  `elements` is a flat kind-tagged list. It is not a system map — no
@@ -77,4 +86,4 @@ explicit "none identified, because …".
77
86
 
78
87
  Seven kinds, one pass. This framework names where to push, the expected
79
88
  effect, and the risks. It does not produce an adoption plan, a sequence, or
80
- an owner — that is `systemic-design`, which is not built in this release.
89
+ an owner — that is `systemic-design`, the next run.
@@ -14,13 +14,12 @@ an unbounded map is a list of everything anyone has ever mentioned.
14
14
  incentive, and information flow the input names.
15
15
  2. Record a `relationship` only between two seeded elements, and only where
16
16
  the input states or directly evidences the connection.
17
- 3. Test each seeded node: does the input state a relationship between it
18
- and another node already in the map, **or** does removing it break a
17
+ 3. Test each seeded node once: does the input state a relationship between
18
+ it and another seeded node, **or** does removing it break a
19
19
  `relationship` already recorded? If neither, it is outside the boundary
20
20
  and goes in `external_factors` — the input naming something is not the
21
21
  same as the input connecting it.
22
- 4. Repeat step 3 until no remaining candidate passes.
23
- 5. State `system_boundary` explicitly as the set of elements that passed.
22
+ 4. State `system_boundary` explicitly as the set of elements that passed.
24
23
  The boundary is closure over what the input stated — not a judgement
25
24
  about what matters.
26
25
 
@@ -39,7 +38,7 @@ without gets prose. See the contract's Rendering section.
39
38
 
40
39
  ## Stop when
41
40
 
42
- No remaining candidate node passes the step 3 test.
41
+ Every seeded node has been tested once under step 3.
43
42
 
44
43
  That is the stopping condition in full. Do not keep expanding because the
45
44
  map looks sparse — a sparse map over a thin input is accurate, and padding
@@ -17,6 +17,46 @@ framework that ran. Nothing else appears at the top level.
17
17
  An empty `evidence` list is a finding, not an omission: it means nothing
18
18
  in the input supports the analysis, and the output says so.
19
19
 
20
+ ## Ids and links
21
+
22
+ Every entry carries an `id`, unique within the run:
23
+
24
+ | Entry | Prefix |
25
+ | ----- | ------ |
26
+ | `evidence` | `e` — `e1`, `e2`, … |
27
+ | `assumptions` | `a` |
28
+ | `open_questions` | `q` |
29
+ | any item inside the framework block | `c` |
30
+
31
+ Number in order of first appearance. An entry keeps its id when the
32
+ result is re-run after an interview answer; a new entry takes the next
33
+ free number. Never reuse an id within a run.
34
+
35
+ Framework block items follow one rule, for every block:
36
+
37
+ - An item that is a string becomes `{id, text}`.
38
+ - A single-value field that holds a claim (`rca.symptom`, `pdca.metric`,
39
+ …) is an item too. The router block's `problem_class`,
40
+ `reasoning_skill`, `recommended_framework` and `confidence` stay plain
41
+ values — they are routing labels, not claims. A `null` stays `null`.
42
+ - An item that is an object (`{step, owner_role, when, signal}`,
43
+ `{from, to, assumption}`, …) gains `id` and keeps its fields.
44
+ - A field that refers to another item (`links.from`, `links.to`, the
45
+ entry an intervention targets, the element a leverage point sits on)
46
+ holds that item's id, not its text.
47
+ - A cause labelled `root` or `root_candidate` carries the label as
48
+ `status`.
49
+
50
+ Links:
51
+
52
+ - `evidence` and `assumptions` entries carry `supports: [ids]` — the `c`
53
+ items they back. An empty list is a finding: the entry backs nothing.
54
+ - `open_questions` entries carry `blocks: [ids]` — the `c` items the
55
+ question holds back.
56
+
57
+ "Name the `evidence` entry that ties this cause to the symptom" is
58
+ answered by an id in that entry's `supports`.
59
+
20
60
  ## Framework blocks
21
61
 
22
62
  | Block | Fields |
@@ -31,6 +71,9 @@ in the input supports the analysis, and the output says so.
31
71
  | `system_map` | `system_boundary`, `actors`, `components`, `relationships`, `dependencies`, `external_factors` |
32
72
  | `causal_loop` | `variables`, `links`, `loops`, `delays` |
33
73
  | `leverage_points` | `elements`, `points` |
74
+ | `systemic_design` | `explore`, `reframe`, `create`, `catalyse` |
75
+ | `theory_of_change` | `inputs`, `activities`, `outputs`, `short_term_outcomes`, `long_term_outcomes`, `impact`, `links` |
76
+ | `three_horizons` | `h1`, `h2`, `h3` |
34
77
 
35
78
  Later skills add blocks. The core never changes — that is what lets one
36
79
  skill consume another's result without knowing which framework produced
@@ -62,40 +105,98 @@ evidence.
62
105
 
63
106
  ## Rendering
64
107
 
65
- In chat by default: markdown headings, one per core field, then the
66
- framework block.
108
+ In chat: markdown headings, one per core field, then the framework block.
109
+ Each entry's id renders as a tag after it — `[e1]`, `[c4]` — so the human
110
+ can refer to it. Its `supports` or `blocks` list renders right after the
111
+ tag as `-> [c1, c2]`; an empty list renders as `-> []`, never as prose in
112
+ its place.
67
113
 
68
114
  A structure containing a cycle gets a diagram; one without gets prose.
69
115
  Prose renders a cycle as a list, and a list loses the closure — `A -> B ->
70
116
  C -> A` read top to bottom does not show that it comes back.
71
117
 
72
- On request: one file, `problem-analysis.md`, in the directory the human
73
- names. Core fields and the framework block become YAML front-matter above
74
- the markdown body. No second JSON file is written — it would be a
75
- duplicate representation with nothing keeping the two in agreement.
118
+ ## Saving
119
+
120
+ Every run is saved to one file:
121
+
122
+ ```
123
+ ~/.reasoning/problems/<YYYY-MM-DD>-<slug>/<NN>-<skill>.md
124
+ ```
125
+
126
+ Resolve `~` to the absolute home directory before writing.
127
+
128
+ - `<YYYY-MM-DD>` — today's date, when the problem folder is created.
129
+ - `<slug>` — the problem in 2–5 lowercase kebab-case words. If that folder
130
+ already exists and this run did not start from a hand-off, append `-2`,
131
+ `-3`, …. List `~/.reasoning/problems/` to check.
132
+ - `<NN>` — `01`, `02`, …: the next free number in the folder. List the
133
+ folder to find it.
134
+ - `<skill>` — `problem-router`, `problem-solving`, `systems-thinking`, or
135
+ `systemic-design`.
136
+
137
+ | Event | Write |
138
+ | ----- | ----- |
139
+ | A run starts with no hand-off | create a new problem folder |
140
+ | A run starts from a hand-off | use the folder the hand-off names |
141
+ | The framework's first pass completes, before any interview round | write `<NN>-<skill>.md` |
142
+ | An interview answer changes the result | rewrite the same file, ids kept |
143
+ | The human re-runs a skill on the same problem | the next `<NN>`; the old file stays |
144
+ | The result is emitted | rewrite the same file, ids kept |
145
+
146
+ Every hand-off names the problem folder path, so the receiving skill
147
+ writes into it. Name it even when this run's write failed; the receiving
148
+ skill creates the folder if it is missing.
149
+
150
+ If a write is refused or fails, continue in chat, say once "not saved:
151
+ <reason>", and do not retry within the run.
152
+
153
+ The file holds the core fields and the framework block as YAML
154
+ front-matter above the markdown body chat showed. No second JSON file is
155
+ written — it would be a duplicate representation with nothing keeping the
156
+ two in agreement.
157
+
158
+ Double-quote every free-text value, or use `|` for multi-line text — a
159
+ colon followed by a space inside an unquoted value breaks the YAML.
76
160
 
77
161
  Example saved file:
78
162
 
79
163
  ```markdown
80
164
  ---
81
- problem: Deploys fail intermittently after the runner image update.
165
+ problem: "Deploys fail intermittently after the runner image update."
82
166
  framework_used: five-whys
83
- framework_reason: Narrow scope, causal chain looks linear.
167
+ framework_reason: "Narrow scope, causal chain looks linear."
84
168
  evidence:
85
- - type: log
86
- ref: ci-run-4471
169
+ - id: e1
170
+ type: log
171
+ ref: "ci-run-4471"
172
+ supports: [c1, c2]
87
173
  assumptions:
88
- - statement: Staging mirrors production runner config.
174
+ - id: a1
175
+ statement: "Staging mirrors production runner config."
89
176
  status: unverified
177
+ supports: [c2]
90
178
  open_questions:
91
- - Who owns the runner image?
179
+ - id: q1
180
+ text: "Who owns the runner image?"
181
+ blocks: [c3]
182
+ - id: q2
183
+ text: |
184
+ Which runner pool failed — shared or dedicated?
185
+ Look in: the CI runner dashboard
186
+ blocks: [c2]
92
187
  five_whys:
93
188
  why_chain:
94
- - Deploys fail -> the runner cannot pull the base image
95
- - It cannot pull -> the registry credential expired
96
- root_candidate: Credential rotation is manual and undocumented.
189
+ - id: c1
190
+ text: "Deploys fail -> the runner cannot pull the base image"
191
+ - id: c2
192
+ text: "It cannot pull -> the registry credential expired"
193
+ root_candidate:
194
+ id: c3
195
+ text: "Credential rotation is manual and undocumented."
196
+ status: root_candidate
97
197
  uncertainties:
98
- - Whether rotation was ever automated.
198
+ - id: c4
199
+ text: "Whether rotation was ever automated."
99
200
  ---
100
201
 
101
202
  # Problem analysis
@@ -0,0 +1,68 @@
1
+ # Evidence interview
2
+
3
+ When a framework's stopping rule does not fire, the evidence a human holds
4
+ is often what's missing. Ask for it before stopping short.
5
+
6
+ ## Trigger
7
+
8
+ All three must hold for the interview to run.
9
+
10
+ 1. The framework has run and its stopping rule (or test) has not fired,
11
+ or fired only by naming missing evidence — an empty level, an
12
+ unevidenced link, a `root_candidate`, a chain that stopped short.
13
+ 2. You can name the specific gap blocking that rule — a field, layer, or
14
+ link, e.g. "`rca.contributing` is empty".
15
+ 3. `AskUserQuestion` is available — the same test step 2 applies before
16
+ asking the human to pick a framework. If a call errors, the run is
17
+ headless from that point.
18
+
19
+ **Headless.** If 1 and 2 hold but 3 does not, stop short, and make the
20
+ first `open_questions` entry the question round 1 would have asked — the
21
+ question, its `Look in:` line, and its two options, without the fixed
22
+ exits. If 1 or 2 does not hold, emit as before.
23
+
24
+ ## One round
25
+
26
+ Ask exactly one question with `AskUserQuestion`.
27
+
28
+ - **Question** — aimed at the one named gap, using this problem's details:
29
+ its figures, times, components. Not generic wording.
30
+ - **Source hint** — the question text's second line, `Look in: …`, naming
31
+ where the evidence lives: a log, dashboard, trace, ticket, or the person
32
+ who owns it. Never what to expect there. "Look in: the gateway access
33
+ log" passes. "Check whether the DB pool is exhausted" fails — it asserts
34
+ a cause.
35
+ - **Options** — two concrete options drawn from the input: dimensions to
36
+ discriminate along (transaction type, node, region), not guessed causes.
37
+ Then two fixed exits: `Don't know` and `Stop, analyze now`. Free text and
38
+ pasted logs arrive through the tool's built-in Other.
39
+
40
+ ## Answers
41
+
42
+ | Answer | Record as | Then |
43
+ | ------ | --------- | ---- |
44
+ | Content | `evidence`, type `interview`, ref `round N` | re-run the framework from step 3 |
45
+ | Pasted log or figures | `evidence`, type `log` or `metric` | re-run |
46
+ | Picked option | `evidence`, type `interview`, ref `round N` | re-run |
47
+ | Confirms an assumption | that assumption's status becomes `confirmed` | re-run |
48
+ | Don't know | `open_questions` | never ask about that gap again |
49
+ | Stop | nothing | emit now, stating "stopped on request" |
50
+
51
+ A re-run is the same framework over more evidence, not a second framework.
52
+ After each re-run, rewrite the saved file per `references/contract.md`
53
+ Saving, keeping every existing id.
54
+
55
+ | Situation | Handling |
56
+ | --------- | -------- |
57
+ | Answer contradicts existing evidence | Keep both, and name the contradiction in `open_questions`. |
58
+ | Answer meets another class's definition in `problem-router` — in `problem-solving`, recurrence (`complex`) or an actor adapting to fixes (`complex-adaptive`); in `systems-thinking`, only `complex-adaptive`; in `systemic-design`, `simple` or `ambiguous` | End the interview and emit. In `systems-thinking`, name `systemic-design` as the next run; elsewhere, recommend re-running `problem-router`. Do not start a second framework. |
59
+ | Human asserts "the cause is X" | Record as `interview` evidence: "the human believes X". It supports a cause only if an observation ties X to the symptom. |
60
+ | Human rejects the question to ask something | Answer in chat, then re-ask the same question. The round does not count. |
61
+ | Human rejects the question with no message | Treat as Stop. |
62
+
63
+ ## End
64
+
65
+ The loop ends when the stopping rule fires, no askable gap remains, the
66
+ human picks Stop, an answer meets another class's definition, or round 6
67
+ completes. Say in the output which one ended
68
+ it.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "solution-architect",
3
- "version": "2.0.1",
3
+ "version": "3.0.1",
4
4
  "description": "Solution-architecture toolkit: interview-driven architecture documentation with interactive diagrams and provenance-tagged facts, AI-aware project estimation, and client-ready proposals.",
5
5
  "author": {
6
6
  "name": "Truong Vu",
@@ -14,7 +14,8 @@ served on localhost for review.
14
14
  2. One home per fact — diagrams own topology, tables own properties, prose owns neither.
15
15
  3. Unknowns render as honest absences (`Not applicable — <reason>`, `not estimated`, `Not provided`) — never placeholders, never `[TODO]`, never `0`.
16
16
  4. Validation blocks rendering: `node scripts/validate.mjs` must exit 0 before the viewer is generated.
17
- 5. mattpocock files (`CONTEXT.md`, `CONTEXT-MAP.md`, `docs/adr/`) are written into their existing formats — never restructured. Invoke the `domain-modeling` skill for term work.
17
+ 5. Never overwrite what this skill did not write. A file already on disk with no entry in `architecture-state.json` is not ours and is never overwritten, while one with no entry and no file yet is this run's to create; a file whose hash moved has changed since the last run, and is asked about before anything is written (`references/rewriting.md`).
18
+ 6. mattpocock files (`CONTEXT.md`, `CONTEXT-MAP.md`, `docs/adr/`) are written into their existing formats — never restructured. Invoke the `domain-modeling` skill for term work.
18
19
 
19
20
  ## Flow
20
21
 
@@ -22,7 +23,7 @@ served on localhost for review.
22
23
  2. **Scan** (brownfield): `index_repository` if needed, then `get_architecture` — clusters seed §6 Core Components. Read `manage_adr` if present; never write it.
23
24
  3. **Interview**: follow `references/interview.md`. Detect project type per `references/project-types.md`.
24
25
  4. **Research**: run `workflows/research.js` per `references/research.md`. Surface dropped items before writing.
25
- 5. **Write**: model first (`references/likec4.md`), then ARCHITECTURE.md and companions (`references/writing.md`).
26
+ 5. **Write**: on every run, `node scripts/drift.mjs` gates this step — before the first write, never after (`references/rewriting.md`). Then the model (`references/likec4.md`), then ARCHITECTURE.md and companions (`references/writing.md`). Last, once every document is on disk, record what was written: `node scripts/record.mjs --state ... --files ...`.
26
27
  6. **Validate**: export the model with `node scripts/likec4-export.mjs --dir ... --out ...`, then `node scripts/validate.mjs --arch ... --model ...` (add `--mode brownfield --clusters ...` when applicable). Fix findings; re-run until clean.
27
28
  7. **Render + serve**: follow `references/viewer.md`; report the URL.
28
29
 
@@ -0,0 +1,108 @@
1
+ # Rewriting — what is already on disk
2
+
3
+ Read before step 5 writes anything. The gate (§3) runs on every run, before the
4
+ first write; the recording (§5) closes every run. Only what they find differs —
5
+ a first run has no record to compare against, and the documents it finds
6
+ already on disk are, by that fact, not ours.
7
+
8
+ ## 1. The rule
9
+
10
+ **Ask before the first write, or not at all.** A package half-written while a
11
+ question waits is worse than either answer: the reader cannot tell which
12
+ sections are theirs and which are ours.
13
+
14
+ ## 2. What the state file knows, and what it does not
15
+
16
+ `architecture-state.json` sits beside `ARCHITECTURE.md` and records a hash per
17
+ generated file, plus a hash per spine section for `ARCHITECTURE.md`. It is
18
+ **written last**, after every document is on disk, through a temp file and a
19
+ rename — so a crash leaves it pointing at the previous consistent revision.
20
+
21
+ A hash says a file **changed since the last run**. It cannot say who changed
22
+ it: a formatter, a merge, a `git checkout`, another agent and a person all look
23
+ identical, and a hash cannot tell them apart — so what the run reports must
24
+ never claim to know an author. Write "this changed since the last run", not a
25
+ claim about who did it.
26
+
27
+ ## 3. The gate
28
+
29
+ Before writing, run:
30
+
31
+ node scripts/drift.mjs --state <package>/architecture-state.json \
32
+ --files ARCHITECTURE.md docs/architecture/validation-plan.md …
33
+
34
+ List every file this run intends to write. Paths are relative to the state
35
+ file. Exit codes: `0` nothing drifted, `2` something drifted, `1` usage error.
36
+
37
+ | verdict | meaning | what to do |
38
+ |---|---|---|
39
+ | `unchanged` | matches what we wrote | write it |
40
+ | `new` | we have never written it and it is not on disk | write it — nobody has one |
41
+ | `untracked` | we have never written it, but a file is there | **never write it** — it is not ours |
42
+ | `missing` | we wrote it, it is gone now | report it; never silently recreate it |
43
+ | `locked` | an ADR whose `## Status` on disk reads accepted | never rewrite; a new decision is a new ADR with `supersedes` |
44
+ | `drifted` | changed since we wrote it | ask, before writing anything |
45
+
46
+ ## 4. Asking
47
+
48
+ One question, covering every drifted file at once, before the first write.
49
+ Show what the gate printed — the diff where git supplied one, the changed
50
+ section numbers where it did not. For each file offer exactly three answers:
51
+
52
+ - **keep the file on disk** — skip it; the rest of the run proceeds
53
+ - **overwrite it with the new revision** — the edit is lost, and they have been
54
+ shown what they are discarding
55
+ - **stop the run** — nothing is written, the state file is untouched
56
+
57
+ No merge. No three-way resolution. Detect, show, ask which wins, obey.
58
+
59
+ ## 5. Recording what you wrote
60
+
61
+ The gate can only compare against a record, and nothing writes that record on
62
+ its own. **The last thing step 5 does**, once every document is on disk:
63
+
64
+ node scripts/record.mjs --state <package>/architecture-state.json \
65
+ --files ARCHITECTURE.md docs/architecture/validation-plan.md docs/adr/0001-….md
66
+
67
+ `--files` is every file this run actually wrote: the list the gate was given,
68
+ minus any file a drift answer told you to keep and minus anything the run
69
+ skipped. Paths are relative to the state file, as they are for the gate. A file
70
+ left out keeps whatever entry it already had.
71
+
72
+ `docVersion` is read from `ARCHITECTURE.md`'s frontmatter. Pass
73
+ `--doc-version <v>` only on a run that did not write that document.
74
+
75
+ The script hashes each file, adds a hash per spine section for
76
+ `ARCHITECTURE.md`, reads each ADR's `## Status`, and writes:
77
+
78
+ ```json
79
+ {
80
+ "_generated": "written by analyze-requirements — do not edit",
81
+ "revision": 3,
82
+ "updated": "2026-09-23T10:11:00.000Z",
83
+ "docVersion": "1.2.0",
84
+ "gitCommit": "3dcac90…",
85
+ "files": {
86
+ "ARCHITECTURE.md": { "hash": "sha256:9f2a…", "sections": { "1": "sha256:aa…" } },
87
+ "docs/adr/0001-postgres-job-queue.md": { "hash": "sha256:e4…", "status": "accepted" }
88
+ }
89
+ }
90
+ ```
91
+
92
+ Never hand-write or hand-edit that file. A record that disagrees with what is
93
+ on disk is worse than no record at all: it reports drift nobody caused, and
94
+ people learn to answer "overwrite" without reading.
95
+
96
+ ## 6. First runs and broken states
97
+
98
+ No state file means a first run: every file is still judged — untracked where
99
+ one is already on disk, `new` where none is — nothing is blocked, and the state
100
+ is written at the end.
101
+
102
+ A state file that will not parse is treated as absent, said out loud, and
103
+ **never deleted** — it is the only record of what the last run wrote. It is not
104
+ a first run, though: the file's existence says tracked documents are on disk,
105
+ and its corruption is what stops us telling which of them moved. Nothing on
106
+ disk can be verified against it, so nothing in that run is cleared for writing.
107
+ `record.mjs` refuses to run against one, because writing would rename over the
108
+ only record of the last run. Rename it by hand if you mean to start fresh.
@@ -0,0 +1,64 @@
1
+ import { existsSync, readFileSync } from 'node:fs';
2
+ import { dirname, join } from 'node:path';
3
+ import { readState } from './lib/state.mjs';
4
+ import { classify, changedSections } from './lib/drift.mjs';
5
+ import { gitDiff } from './lib/git-diff.mjs';
6
+
7
+ // Same shape as validate.mjs: the list-consuming loop is extracted so the
8
+ // parser stays inside the two-level nesting limit.
9
+ function consumeFiles(argv, i, files) {
10
+ while (argv[i + 1] && !argv[i + 1].startsWith('--')) files.push(argv[++i]);
11
+ return i;
12
+ }
13
+
14
+ function parseArgs(argv) {
15
+ const args = { files: [] };
16
+ for (let i = 0; i < argv.length; i += 1) {
17
+ const flag = argv[i];
18
+ if (flag === '--files') i = consumeFiles(argv, i, args.files);
19
+ else if (flag.startsWith('--')) args[flag.slice(2)] = argv[++i];
20
+ }
21
+ return args;
22
+ }
23
+
24
+ function read(path) {
25
+ return existsSync(path) ? readFileSync(path, 'utf8') : null;
26
+ }
27
+
28
+ function detail(ctx, file) {
29
+ const text = read(join(ctx.root, file));
30
+ const diff = gitDiff({ root: ctx.root, file, since: ctx.state.gitCommit });
31
+ if (diff) return diff.split('\n').map((l) => ` ${l}`).join('\n');
32
+ const sections = changedSections(ctx.state.files[file], text);
33
+ return ` changed: ${sections.map((n) => `§${n}`).join(', ') || 'whole file'}`;
34
+ }
35
+
36
+ function report(ctx, file) {
37
+ const verdict = classify(ctx.state.files[file], read(join(ctx.root, file)));
38
+ console.log(`${file} ${verdict}`);
39
+ if (verdict === 'drifted') console.log(detail(ctx, file));
40
+ return verdict;
41
+ }
42
+
43
+ const args = parseArgs(process.argv.slice(2));
44
+ // An empty write set is a fumbled argument, never an all-clear: a mistyped
45
+ // --file would otherwise turn the gate into a clean bill of health.
46
+ if (!args.state || !args.files.length) {
47
+ console.error('usage: drift.mjs --state <architecture-state.json> --files <path> [<path> …]');
48
+ process.exit(1);
49
+ }
50
+
51
+ const { state, error } = readState(args.state);
52
+ // A corrupt state file is evidence that tracked files are on disk and that we
53
+ // cannot tell which of them moved, so it never earns the first-run
54
+ // reassurance — and it is never deleted.
55
+ if (error) console.log(`state file ${error}`);
56
+ if (error) console.log('nothing on disk can be verified against it — treat every file as not ours');
57
+ // A first run is not halted, but it is still judged: with no entries every file
58
+ // already on disk reads as untracked, which is what keeps a hand-written
59
+ // package safe from the run that was pointed at it.
60
+ else if (!state) console.log('first run — no state recorded, nothing is at risk');
61
+
62
+ const ctx = { root: dirname(args.state), state: { gitCommit: null, files: {}, ...state } };
63
+ const verdicts = args.files.map((f) => report(ctx, f));
64
+ process.exit(verdicts.includes('drifted') ? 2 : 0);
@@ -69,6 +69,9 @@ export async function openPage(fileUrl) {
69
69
  const send = sender(ws, onEvent);
70
70
  await send('Runtime.enable');
71
71
  const evaluate = evaluator(send);
72
- await waitFor(() => evaluate('document.readyState === "complete"'), 'a loaded document');
72
+ // A fresh tab can report a complete about:blank before it navigates to the
73
+ // file; on a slow runner the checks then read an empty page.
74
+ await waitFor(() => evaluate('location.href !== "about:blank" && document.readyState === "complete"'),
75
+ 'a loaded document');
73
76
  return { eval: evaluate, errors, send, close() { ws.close(); chrome.kill(); } };
74
77
  }
@@ -0,0 +1,31 @@
1
+ import { hashText, sectionHashes } from './state.mjs';
2
+
3
+ // An ADR's `## Status` section, as decisions.md formats it.
4
+ const STATUS = /^##\s+Status\b[^\n]*\n+\s*([A-Za-z][\w-]*)/m;
5
+
6
+ // The document outranks the record. The usual way an ADR becomes accepted is a
7
+ // person editing it after we wrote it `proposed`, so trusting what the last run
8
+ // recorded locks only the ADRs that were already accepted when we wrote them —
9
+ // the ones nobody needed protecting.
10
+ export function docStatus(text) {
11
+ return text?.match(STATUS)?.[1].toLowerCase() ?? null;
12
+ }
13
+
14
+ // `locked` is not a hash verdict. decisions.md rules that an accepted ADR is
15
+ // superseded by a new record, never rewritten, so its hash is irrelevant.
16
+ export function classify(entry, text) {
17
+ // No entry says nothing on its own. A file on disk we never wrote is someone
18
+ // else's; no file at all is one this run is free to create.
19
+ if (!entry) return text === null ? 'new' : 'untracked';
20
+ if ((docStatus(text) ?? entry.status) === 'accepted') return 'locked';
21
+ if (text === null) return 'missing';
22
+ return entry.hash === hashText(text) ? 'unchanged' : 'drifted';
23
+ }
24
+
25
+ export function changedSections(entry, text) {
26
+ const now = sectionHashes(text);
27
+ const before = entry?.sections ?? {};
28
+ const moved = Object.keys(now).filter((n) => before[n] !== now[n]);
29
+ const removed = Object.keys(before).filter((n) => !(n in now));
30
+ return [...moved, ...removed].sort((a, b) => Number(a) - Number(b));
31
+ }
@@ -0,0 +1,27 @@
1
+ import { execFileSync } from 'node:child_process';
2
+
3
+ // Returns null rather than throwing: no repo, no git, or no difference all mean
4
+ // "no diff available", and the caller falls back to naming changed sections.
5
+ function diff(root, range) {
6
+ try {
7
+ const out = execFileSync('git', ['diff', '--no-color', ...range], {
8
+ cwd: root,
9
+ encoding: 'utf8',
10
+ stdio: ['ignore', 'pipe', 'ignore'],
11
+ });
12
+ return out.trim() ? out : null;
13
+ } catch {
14
+ return null;
15
+ }
16
+ }
17
+
18
+ // The working tree against HEAD first — against HEAD rather than the index, so
19
+ // that staging an edit does not hide it. `since` is HEAD as it stood when the
20
+ // state file was written, before anyone committed what that run had just
21
+ // written, so reaching for it while an uncommitted change exists renders the
22
+ // whole regeneration and buries the one line a person has to judge.
23
+ export function gitDiff({ root, file, since = null }) {
24
+ const working = diff(root, ['HEAD', '--', file]);
25
+ if (working || !since) return working;
26
+ return diff(root, [since, '--', file]);
27
+ }
@@ -38,11 +38,26 @@ function stripLiterals(src) {
38
38
  // Measured in lines of code, not lines of text. The limit caps how much logic a
39
39
  // reader holds at once, and a static HTML string or a comment block is neither —
40
40
  // they arrive here already blanked, so a blank line is a line that carried none.
41
+ // A `function NAME(...)` match points before the parameter list, so the body
42
+ // brace is whatever `{` follows the parameter list's own balanced parens —
43
+ // not the first `{` after the match, which is the parameter list's own brace
44
+ // when the first parameter is destructured (`function f({ a, b }) {`).
45
+ function afterParams(code, from) {
46
+ const parenOpen = code.indexOf('(', from);
47
+ let depth = 0;
48
+ for (let i = parenOpen; i < code.length; i += 1) {
49
+ if (code[i] === '(') depth += 1;
50
+ if (code[i] === ')') { depth -= 1; if (depth === 0) return i + 1; }
51
+ }
52
+ return parenOpen + 1;
53
+ }
54
+
41
55
  function functionSpans(code) {
42
56
  const spans = [];
43
57
  const starts = [...code.matchAll(/(?:^|\n)\s*(?:export\s+)?(?:async\s+)?function\s+\w+|=>\s*\{/g)];
44
58
  for (const m of starts) {
45
- const open = code.indexOf('{', m.index);
59
+ const from = m[0].includes('function') ? afterParams(code, m.index) : m.index;
60
+ const open = code.indexOf('{', from);
46
61
  let depth = 0; let end = code.length - 1;
47
62
  for (let i = open; i < code.length; i += 1) {
48
63
  if (code[i] === '{') depth += 1;