@tduyng/pi-devos 0.0.0-stage → 0.14.0

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 (109) hide show
  1. package/CHANGELOG.md +1421 -0
  2. package/LICENSE +201 -0
  3. package/README.md +206 -2
  4. package/package.json +44 -4
  5. package/plugins/devos/agents/reader.md +27 -0
  6. package/plugins/devos/agents/verifier.md +155 -0
  7. package/plugins/devos/pi/extension/devos.ts +605 -0
  8. package/plugins/devos/scripts/check-evidence-router.sh +140 -0
  9. package/plugins/devos/scripts/evidence-router.py +254 -0
  10. package/plugins/devos/scripts/gates/check-dod-core.sh +285 -0
  11. package/plugins/devos/scripts/gates/check-dod.sh +38 -0
  12. package/plugins/devos/scripts/gates/check-implementation-boundary.sh +99 -0
  13. package/plugins/devos/scripts/gates/check-port-source.sh +134 -0
  14. package/plugins/devos/scripts/gates/check-report-locations.sh +148 -0
  15. package/plugins/devos/scripts/gates/check-scenario-coverage.sh +104 -0
  16. package/plugins/devos/scripts/gates/gate-check.mjs +204 -0
  17. package/plugins/devos/scripts/gates/phase-gate.sh +208 -0
  18. package/plugins/devos/scripts/gates/plan-template-check.py +141 -0
  19. package/plugins/devos/scripts/gates/run-gate.sh +148 -0
  20. package/plugins/devos/scripts/gates/spec-contract.sh +19 -0
  21. package/plugins/devos/scripts/gates/spec-template-check.py +152 -0
  22. package/plugins/devos/scripts/gates/suite/01-dod.sh +485 -0
  23. package/plugins/devos/scripts/gates/suite/02-integrity.sh +310 -0
  24. package/plugins/devos/scripts/gates/suite/03-archetype.sh +255 -0
  25. package/plugins/devos/scripts/gates/suite/04-spec-validator.sh +183 -0
  26. package/plugins/devos/scripts/gates/suite/05-requires.sh +360 -0
  27. package/plugins/devos/scripts/gates/suite/06-clarify-adapters.sh +435 -0
  28. package/plugins/devos/scripts/gates/suite/07-lint-evals.sh +350 -0
  29. package/plugins/devos/scripts/gates/suite/08-converge.sh +591 -0
  30. package/plugins/devos/scripts/gates/suite/09-quality.sh +516 -0
  31. package/plugins/devos/scripts/gates/suite/10-eval-harness.sh +679 -0
  32. package/plugins/devos/scripts/gates/test-gates.sh +76 -0
  33. package/plugins/devos/scripts/gates/test-integrity-rubric.sh +152 -0
  34. package/plugins/devos/scripts/gates/test-phase-gate.sh +116 -0
  35. package/plugins/devos/skills/absorb/SKILL.md +75 -0
  36. package/plugins/devos/skills/absorb/references/distill.md +67 -0
  37. package/plugins/devos/skills/absorb/scripts/check-refs.sh +108 -0
  38. package/plugins/devos/skills/absorb/scripts/knowledge.py +258 -0
  39. package/plugins/devos/skills/build/SKILL.md +71 -0
  40. package/plugins/devos/skills/build/references/advanced-routing.md +19 -0
  41. package/plugins/devos/skills/build/references/defect.md +17 -0
  42. package/plugins/devos/skills/build/references/exposure.md +28 -0
  43. package/plugins/devos/skills/build/references/hard.md +39 -0
  44. package/plugins/devos/skills/build/references/refactor.md +66 -0
  45. package/plugins/devos/skills/build/references/routes.md +56 -0
  46. package/plugins/devos/skills/build/references/scale.md +84 -0
  47. package/plugins/devos/skills/build/references/spike.md +19 -0
  48. package/plugins/devos/skills/build/scripts/construct-census.py +204 -0
  49. package/plugins/devos/skills/build/scripts/dep-order.py +297 -0
  50. package/plugins/devos/skills/build/scripts/ledger.sh +228 -0
  51. package/plugins/devos/skills/build/scripts/route.sh +5 -0
  52. package/plugins/devos/skills/build/scripts/secret-scan.sh +121 -0
  53. package/plugins/devos/skills/build/scripts/toolchain-preflight.py +302 -0
  54. package/plugins/devos/skills/frame/SKILL.md +54 -0
  55. package/plugins/devos/skills/frame/references/template.md +115 -0
  56. package/plugins/devos/skills/frame/scripts/survey.sh +44 -0
  57. package/plugins/devos/skills/implement/SKILL.md +36 -0
  58. package/plugins/devos/skills/implement/references/conditional-plan.md +17 -0
  59. package/plugins/devos/skills/implement/references/debug-loop.md +7 -0
  60. package/plugins/devos/skills/implement/references/dod.md +37 -0
  61. package/plugins/devos/skills/implement/references/implement.md +54 -0
  62. package/plugins/devos/skills/implement/references/manual-gates.md +16 -0
  63. package/plugins/devos/skills/implement/references/plan.md +142 -0
  64. package/plugins/devos/skills/implement/references/resume.md +9 -0
  65. package/plugins/devos/skills/implement/references/scale.md +86 -0
  66. package/plugins/devos/skills/implement/references/verify-close.md +62 -0
  67. package/plugins/devos/skills/implement/references/visual-verification.md +7 -0
  68. package/plugins/devos/skills/implement/scripts/check-converge.sh +147 -0
  69. package/plugins/devos/skills/implement/scripts/equivalence-check.sh +140 -0
  70. package/plugins/devos/skills/implement/scripts/manifest-queue.sh +185 -0
  71. package/plugins/devos/skills/implement/scripts/ops-log.sh +58 -0
  72. package/plugins/devos/skills/implement/scripts/pilot-consistency.py +173 -0
  73. package/plugins/devos/skills/implement/scripts/validate-spec.sh +220 -0
  74. package/plugins/devos/skills/init/SKILL.md +100 -0
  75. package/plugins/devos/skills/init/references/archetype-sections.md +15 -0
  76. package/plugins/devos/skills/init/references/context.md +42 -0
  77. package/plugins/devos/skills/init/references/conventions-template.md +153 -0
  78. package/plugins/devos/skills/init/references/reverse-engineer.md +3 -0
  79. package/plugins/devos/skills/init/references/rule-format.md +58 -0
  80. package/plugins/devos/skills/init/references/shape-model.md +29 -0
  81. package/plugins/devos/skills/init/scripts/detect-archetype.py +461 -0
  82. package/plugins/devos/skills/init/scripts/render-rule.py +114 -0
  83. package/plugins/devos/skills/init/scripts/reverse-engineer.sh +162 -0
  84. package/plugins/devos/skills/learn/SKILL.md +29 -0
  85. package/plugins/devos/skills/learn/references/destinations.md +43 -0
  86. package/plugins/devos/skills/learn/references/scoring.md +26 -0
  87. package/plugins/devos/skills/review/SKILL.md +54 -0
  88. package/plugins/devos/skills/review/references/comments.md +13 -0
  89. package/plugins/devos/skills/review/references/gaps.md +26 -0
  90. package/plugins/devos/skills/review/references/reviewer.md +124 -0
  91. package/plugins/devos/skills/review/references/routing.md +35 -0
  92. package/plugins/devos/skills/review/scripts/__pycache__/prepare.cpython-313.pyc +0 -0
  93. package/plugins/devos/skills/review/scripts/prepare.py +763 -0
  94. package/plugins/devos/skills/spec/SKILL.md +57 -0
  95. package/plugins/devos/skills/spec/references/prototype.md +21 -0
  96. package/plugins/devos/skills/spec/references/question-craft.md +47 -0
  97. package/plugins/devos/skills/spec/references/roadmap-link.md +5 -0
  98. package/plugins/devos/skills/spec/references/write-spec.md +128 -0
  99. package/plugins/devos/skills/spec/scripts/clarify.sh +173 -0
  100. package/plugins/devos/skills/status/SKILL.md +67 -0
  101. package/plugins/devos/skills/status/references/cost.md +38 -0
  102. package/plugins/devos/skills/status/scripts/artifact-budgets.sh +88 -0
  103. package/plugins/devos/skills/status/scripts/check-requires.py +556 -0
  104. package/plugins/devos/skills/status/scripts/context-cost.sh +89 -0
  105. package/plugins/devos/skills/status/scripts/convention-usage.sh +184 -0
  106. package/plugins/devos/skills/status/scripts/findings-summary.sh +112 -0
  107. package/plugins/devos/skills/status/scripts/quality-correlation.sh +259 -0
  108. package/plugins/devos/skills/status/scripts/sizing-calibration.sh +71 -0
  109. package/plugins/devos/skills/status/scripts/spec-diff.sh +137 -0
@@ -0,0 +1,591 @@
1
+ # --- check-converge.sh -------------------------------------------------------
2
+ # Converge pass: every task group's declared Files must be touched on the spec
3
+ # branch since it diverged from the default branch. A group whose files never
4
+ # moved is done-drift (marked complete, work never landed).
5
+ CCV="$(cd "$(dirname "$DOD")/../.." && pwd)/skills/implement/scripts/check-converge.sh"
6
+ # Own repo root: the shared $tmp accumulates stray files and git state from
7
+ # other sections, which leaks into diff/untracked output.
8
+ cvgroot="$tmp/cvgrepo"
9
+ cvg="$cvgroot/devos/specs/cvg"
10
+ mkdir -p "$cvg" "$cvgroot/src"
11
+ printf '%s\n' '## Implementation Plan' '### Task Group 1: cache' '**Files:** `src/cache.ts`' '### Task Group 2: export' '**Files:** `src/export.ts`' > "$cvg/spec.md"
12
+ git -C "$cvgroot" init -q -b main
13
+ git -C "$cvgroot" config user.email t@t && git -C "$cvgroot" config user.name t
14
+ echo base > "$cvgroot/src/base.txt"
15
+ git -C "$cvgroot" add -A && git -C "$cvgroot" commit -qm base
16
+ git -C "$cvgroot" checkout -qb feature
17
+ echo e > "$cvgroot/src/export.ts"
18
+ out=$(cd "$cvgroot" && bash "$CCV" devos/specs/cvg 2>&1); rc=$?
19
+ [[ $rc -eq 1 ]] || { echo "FAIL converge: expected findings, got rc=$rc"; echo "$out"; fail=1; }
20
+ echo "$out" | grep -q "Task Group 1" || { echo "FAIL converge: untouched group 1 not named"; fail=1; }
21
+ echo "$out" | grep -q "Task Group 2" && { echo "FAIL converge: touched group 2 wrongly flagged"; fail=1; }
22
+ # Landing group 1's work clears the finding.
23
+ echo c > "$cvgroot/src/cache.ts"
24
+ out=$(cd "$cvgroot" && bash "$CCV" devos/specs/cvg 2>&1); rc=$?
25
+ [[ $rc -eq 0 ]] || { echo "FAIL converge: converged repo still flagged ($out)"; fail=1; }
26
+ # Outside a git repo: advisory skip, never a brick.
27
+ mkdir -p "$tmp/nogit/devos/specs/cvg2" && cp "$cvg/spec.md" "$tmp/nogit/devos/specs/cvg2/"
28
+ out=$(bash "$CCV" "$tmp/nogit/devos/specs/cvg2" 2>&1); rc=$?
29
+ [[ $rc -eq 0 ]] || { echo "FAIL converge: non-git dir must exit 0 (fail open), got $rc"; fail=1; }
30
+ # Nothing touched at all: the branch is even with the default branch and the
31
+ # tree is clean, so the touched-file list is empty. An FNR == NR reader sees the
32
+ # plan as its first file and calls every declared path touched, which passes the
33
+ # one state the gate exists to catch.
34
+ cvgempty="$tmp/cvgempty"
35
+ mkdir -p "$cvgempty/devos/specs/cvg3"
36
+ cp "$cvg/spec.md" "$cvgempty/devos/specs/cvg3/"
37
+ git -C "$cvgempty" init -q -b main
38
+ git -C "$cvgempty" config user.email t@t && git -C "$cvgempty" config user.name t
39
+ git -C "$cvgempty" add -A && git -C "$cvgempty" commit -qm base
40
+ out=$(cd "$cvgempty" && bash "$CCV" devos/specs/cvg3 2>&1); rc=$?
41
+ [[ $rc -eq 1 ]] || { echo "FAIL converge: empty touched list must still flag both groups, got rc=$rc"; echo "$out"; fail=1; }
42
+ echo "$out" | grep -q "Task Group 1" || { echo "FAIL converge: empty touched list did not name group 1"; fail=1; }
43
+ echo "$out" | grep -q "Task Group 2" || { echo "FAIL converge: empty touched list did not name group 2"; fail=1; }
44
+
45
+ # A directory declaration must match descendants, not a sibling with the same
46
+ # prefix. `src` owns `src/file.ts`, but not `src2/file.ts`.
47
+ cvgprefix="$tmp/cvgprefix"
48
+ mkdir -p "$cvgprefix/devos/specs/cvg4"
49
+ printf '%s\n' '## Implementation Plan' '### Task Group 1: source' '**Files:** `src`' > "$cvgprefix/devos/specs/cvg4/spec.md"
50
+ git -C "$cvgprefix" init -q -b main
51
+ git -C "$cvgprefix" config user.email t@t && git -C "$cvgprefix" config user.name t
52
+ mkdir -p "$cvgprefix/src2"
53
+ git -C "$cvgprefix" add -A && git -C "$cvgprefix" commit -qm base
54
+ git -C "$cvgprefix" checkout -qb feature
55
+ echo touched > "$cvgprefix/src2/file.ts"
56
+ git -C "$cvgprefix" add -A && git -C "$cvgprefix" commit -qm touch
57
+ out=$(cd "$cvgprefix" && bash "$CCV" devos/specs/cvg4 2>&1); rc=$?
58
+ [[ $rc -eq 1 ]] || { echo "FAIL converge: a sibling prefix must not satisfy a directory declaration, got rc=$rc ($out)"; fail=1; }
59
+ echo "$out" | grep -q "Task Group 1" || { echo "FAIL converge: sibling prefix wrongly treated as the declared directory"; fail=1; }
60
+
61
+ # A group the gate cannot identify is not checkable, and a group that cannot be
62
+ # checked used to be the one case this gate passed. The header pattern required
63
+ # whitespace after "Task Group", so "### Task Group: Parser" never even matched:
64
+ # a plan whose only group declared an untouched file exited 0.
65
+ cvgunnum="$tmp/cvgunnum"
66
+ mkdir -p "$cvgunnum/devos/specs/cvg5" "$cvgunnum/src"
67
+ printf '%s\n' '## Implementation Plan' '### Task Group: Parser' '**Files:** `src/never-touched.ts`' \
68
+ > "$cvgunnum/devos/specs/cvg5/spec.md"
69
+ echo base > "$cvgunnum/src/other.ts"
70
+ git -C "$cvgunnum" init -q -b main
71
+ git -C "$cvgunnum" config user.email t@t && git -C "$cvgunnum" config user.name t
72
+ git -C "$cvgunnum" add -A && git -C "$cvgunnum" commit -qm base
73
+ git -C "$cvgunnum" checkout -qb feature
74
+ out=$(cd "$cvgunnum" && bash "$CCV" devos/specs/cvg5 2>&1); rc=$?
75
+ [[ $rc -eq 1 ]] || { echo "FAIL converge: an unidentifiable group must be reported, got rc=$rc ($out)"; fail=1; }
76
+ echo "$out" | grep -q "has no resolvable group number" || { echo "FAIL converge: unidentifiable group not diagnosed ($out)"; fail=1; }
77
+ echo "$out" | grep -q "Task Group: Parser" || { echo "FAIL converge: diagnostic does not name the header"; fail=1; }
78
+ # It stays reported even when the declared file did land: the point is that the
79
+ # gate could not attribute the files to a group, not that a file went missing.
80
+ echo landed > "$cvgunnum/src/never-touched.ts"
81
+ out=$(cd "$cvgunnum" && bash "$CCV" devos/specs/cvg5 2>&1); rc=$?
82
+ [[ $rc -eq 1 ]] && echo "$out" | grep -q "has no resolvable group number" \
83
+ || { echo "FAIL converge: an unidentifiable group must stay reported when files land ($out)"; fail=1; }
84
+ # The documented and legacy numbered forms must be unaffected, and a heading
85
+ # that merely contains the words "Task Groups" is not a group.
86
+ printf '%s\n' '## Task Groups Overview' '### Task Group 1: Parser' '**Files:** `src/absent.ts`' \
87
+ > "$cvgunnum/devos/specs/cvg5/spec.md"
88
+ out=$(cd "$cvgunnum" && bash "$CCV" devos/specs/cvg5 2>&1); rc=$?
89
+ [[ $rc -eq 1 ]] && echo "$out" | grep -q "Task Group 1" \
90
+ && ! echo "$out" | grep -q "no resolvable group number" \
91
+ || { echo "FAIL converge: numbered group misparsed after the change ($out)"; fail=1; }
92
+ printf '%s\n' '## Task Groups Overview' '### Task Group 1: Parser' '**Files:** `src/never-touched.ts`' \
93
+ > "$cvgunnum/devos/specs/cvg5/spec.md"
94
+ echo more >> "$cvgunnum/src/never-touched.ts"
95
+ out=$(cd "$cvgunnum" && bash "$CCV" devos/specs/cvg5 2>&1); rc=$?
96
+ [[ $rc -eq 0 ]] || { echo "FAIL converge: a 'Task Groups' heading was read as a group ($out)"; fail=1; }
97
+ printf '%s\n' '## Implementation Plan' '### Task Group A: Parser' '**Files:** `src/never-touched.ts`' \
98
+ > "$cvgunnum/devos/specs/cvg5/spec.md"
99
+ out=$(cd "$cvgunnum" && bash "$CCV" devos/specs/cvg5 2>&1); rc=$?
100
+ [[ $rc -eq 0 ]] || { echo "FAIL converge: the pre-0.8.6 letter form must still resolve ($out)"; fail=1; }
101
+
102
+ # The declared file list is stored newline-joined, and interpolating it directly
103
+ # broke the one-line envelope: two untouched files printed three lines with a
104
+ # bare ") declares files" tail. A reader taking one line per finding saw a
105
+ # truncated message.
106
+ cvgmulti="$tmp/cvgmulti"
107
+ mkdir -p "$cvgmulti/devos/specs/cvg6" "$cvgmulti/src"
108
+ printf '%s\n' '## Implementation Plan' '### Task Group 1: Parser' '**Files:** `src/one.ts`, `src/two.ts`' \
109
+ > "$cvgmulti/devos/specs/cvg6/spec.md"
110
+ echo base > "$cvgmulti/src/base.ts"
111
+ git -C "$cvgmulti" init -q -b main
112
+ git -C "$cvgmulti" config user.email t@t && git -C "$cvgmulti" config user.name t
113
+ git -C "$cvgmulti" add -A && git -C "$cvgmulti" commit -qm base
114
+ git -C "$cvgmulti" checkout -qb feature
115
+ echo work > "$cvgmulti/src/work.ts"
116
+ git -C "$cvgmulti" add -A && git -C "$cvgmulti" commit -qm work
117
+ out=$(cd "$cvgmulti" && bash "$CCV" devos/specs/cvg6 2>&1); rc=$?
118
+ [[ $rc -eq 1 ]] || { echo "FAIL converge: a multi-file untouched group must fail, got rc=$rc ($out)"; fail=1; }
119
+ echo "$out" | grep -Fq 'Task Group 1 (src/one.ts, src/two.ts) declares files' \
120
+ || { echo "FAIL converge: multi-file finding is not one line: $out"; fail=1; }
121
+ # The stray tail lines that broke the envelope must be gone.
122
+ [[ "$(printf '%s\n' "$out" | grep -c '^src/')" -eq 0 ]] \
123
+ || { echo "FAIL converge: file list still leaks onto its own line: $out"; fail=1; }
124
+ [[ "$(printf '%s\n' "$out" | grep -c '^)')" -eq 0 ]] \
125
+ || { echo "FAIL converge: a bare closing paren line remains: $out"; fail=1; }
126
+ # The single-file form is unchanged: one file, no trailing separator.
127
+ printf '%s\n' '## Implementation Plan' '### Task Group 1: Parser' '**Files:** `src/absent.ts`' \
128
+ > "$cvgmulti/devos/specs/cvg6/spec.md"
129
+ out=$(cd "$cvgmulti" && bash "$CCV" devos/specs/cvg6 2>&1); rc=$?
130
+ [[ $rc -eq 1 ]] || { echo "FAIL converge: single-file untouched group must fail, got rc=$rc ($out)"; fail=1; }
131
+ echo "$out" | grep -Fq 'Task Group 1 (src/absent.ts) declares files' \
132
+ || { echo "FAIL converge: single-file finding changed shape: $out"; fail=1; }
133
+
134
+ # --- C route: validate-spec accepts an Invariant in place of scenarios ------
135
+
136
+ # A behavior-preserving spec declares what must NOT change, so
137
+ # it has no scenarios and no SC-n to trace. Every case here is a shape the old
138
+ # script either rejected (a valid C spec) or waved through (a confused one).
139
+ VS="$SKILLS/implement/scripts/validate-spec.sh"
140
+ cdir="$tmp/croute"
141
+ mkspec() { mkdir -p "$cdir/$1" && cat >"$cdir/$1/spec.md"; }
142
+
143
+ mkspec ok <<'EOF'
144
+ # Migrate the runner
145
+ ## 1. Goal
146
+ Config is duplicated across four packages.
147
+ ## 2. Invariant
148
+ **Commands that MUST still pass, with no fewer tests executed:**
149
+ - `npm test` -> baseline: exit 0, 42 passed
150
+ **Public surface that MUST NOT move:**
151
+ - none, internal only
152
+ ## 3. Out of Scope
153
+ - Behavior change of any kind.
154
+ EOF
155
+ bash "$VS" "$cdir/ok" >/dev/null 2>&1
156
+ check "validate-spec: an Invariant spec with no scenarios passes" 0 $?
157
+
158
+ mkspec nocmd <<'EOF'
159
+ # Migrate
160
+ ## 1. Goal
161
+ x
162
+ ## 2. Invariant
163
+ **Commands that MUST still pass:**
164
+ - the existing suite
165
+ **Public surface that MUST NOT move:**
166
+ - none, internal only
167
+ ## 3. Out of Scope
168
+ - none
169
+ EOF
170
+ bash "$VS" "$cdir/nocmd" >/dev/null 2>&1
171
+ check "validate-spec: an Invariant naming no command fails" 1 $?
172
+
173
+ mkspec nosurface <<'EOF'
174
+ # Migrate
175
+ ## 1. Goal
176
+ x
177
+ ## 2. Invariant
178
+ **Commands that MUST still pass:**
179
+ - `npm test` -> baseline: exit 0, 42 passed
180
+ ## 3. Out of Scope
181
+ - none
182
+ EOF
183
+ bash "$VS" "$cdir/nosurface" >/dev/null 2>&1
184
+ check "validate-spec: an Invariant with no public-surface line fails" 1 $?
185
+
186
+ mkspec both <<'EOF'
187
+ # Migrate
188
+ ## 1. Goal
189
+ x
190
+ ## 2. Invariant
191
+ **Commands that MUST still pass:**
192
+ - `npm test` -> baseline: exit 0, 42 passed
193
+ **Public surface that MUST NOT move:**
194
+ - none, internal only
195
+ ## Behavior delta
196
+ **Added** (capability: `runner`):
197
+ - reports coverage inline
198
+ ## 4. Out of Scope
199
+ - none
200
+ EOF
201
+ bash "$VS" "$cdir/both" >/dev/null 2>&1
202
+ check "validate-spec: Invariant plus a non-empty Behavior delta fails" 1 $?
203
+
204
+ mkspec nonedelta <<'EOF'
205
+ # Migrate
206
+ ## 1. Goal
207
+ x
208
+ ## 2. Invariant
209
+ **Commands that MUST still pass:**
210
+ - `npm test` -> baseline: exit 0, 42 passed
211
+ **Public surface that MUST NOT move:**
212
+ - none, internal only
213
+ ## Behavior delta
214
+ **Added:** (none)
215
+ **Removed:** (none)
216
+ ## 4. Out of Scope
217
+ - none
218
+ EOF
219
+ bash "$VS" "$cdir/nonedelta" >/dev/null 2>&1
220
+ check "validate-spec: Invariant plus an empty Behavior delta passes" 0 $?
221
+
222
+ # The heading is matched exactly, never as a substring: a feature spec is free
223
+ # to have a "Business invariants" section, and reading that as the C route
224
+ # would silently switch off the scenario checks it still needs.
225
+ mkspec businv <<'EOF'
226
+ # Feature
227
+ ## 1. Goal
228
+ x
229
+ ## 2. Business invariants
230
+ - balance MUST never go below 0
231
+ ## 3. Out of Scope
232
+ - none
233
+ EOF
234
+ bash "$VS" "$cdir/businv" >/dev/null 2>&1
235
+ check "validate-spec: a 'Business invariants' heading is not the C route" 1 $?
236
+
237
+ mkspec feature <<'EOF'
238
+ # Feature
239
+ ## 1. Goal
240
+ x
241
+ ## 2. Functionality
242
+ - Scenario SC-1: happy / WHEN a user submits THEN the record MUST persist
243
+ ## 3. Out of Scope
244
+ - none
245
+ EOF
246
+ bash "$VS" "$cdir/feature" >/dev/null 2>&1
247
+ check "validate-spec: an ordinary scenario spec is unaffected" 0 $?
248
+
249
+ # The plan capsule's own structural checks. Both run at Phase A step 5b now,
250
+ # before the human ever reads the plan, so a defect here costs one edit rather
251
+ # than a re-derivation after the code was written against it.
252
+ pdir="$cdir/plan"; mkdir -p "$pdir"
253
+ PCON='## Goal\nx\n## Scenarios\n- Scenario SC-1: a / WHEN x / THEN y\n## Out of scope\n- none\n'
254
+ mkplan() { { printf "$PCON"'## Local Craft\nNone\n'; cat; } > "$pdir/spec.md"; }
255
+
256
+ mkplan <<'MD'
257
+ ## Design Convergence
258
+ - **Direct MVP**: call it directly
259
+ - **Failed Items**: None
260
+ ## Implementation Plan
261
+ ### Task Group 1: A
262
+ **Files:** `a.ts`
263
+ **Scenarios covered:** SC-1
264
+ MD
265
+ bash "$VS" "$pdir" >/dev/null 2>&1
266
+ check "validate-spec: a well-formed capsule passes" 0 $?
267
+
268
+ # "None" with a reason is still None. The fix line says to state None, and a
269
+ # capsule that writes "None: the tree is new" was failing the gate that told
270
+ # it to write None.
271
+ { printf "$PCON"'## Local Craft\nNone: the project has nothing to reuse here\n'; cat <<'MD'
272
+ ## Design Convergence
273
+ - **Direct MVP**: call it directly
274
+ - **Failed Items**: None
275
+ ## Implementation Plan
276
+ ### Task Group 1: A
277
+ **Files:** `a.ts`
278
+ **Scenarios covered:** SC-1
279
+ MD
280
+ } > "$pdir/spec.md"
281
+ bash "$VS" "$pdir" >/dev/null 2>&1
282
+ check "validate-spec: Local Craft may state None with a reason" 0 $?
283
+
284
+ # A change that spans many units holds one group for the whole change, and
285
+ # the group's files are the target tree. The units live in the manifest, so
286
+ # the capsule does not carry them.
287
+ { printf "$PCON"'## Local Craft\nNone\n'; cat <<'MD'
288
+ ## Design Convergence
289
+ - **Direct MVP**: one group, the units live in the manifest
290
+ - **Failed Items**: None
291
+ ## Implementation Plan
292
+ ### Task Group 1: the port
293
+ **Files:** `modernized/`
294
+ **Scenarios covered:** SC-1
295
+ MD
296
+ } > "$pdir/spec.md"
297
+ bash "$VS" "$pdir" >/dev/null 2>&1
298
+ check "validate-spec: a one-group capsule naming a directory passes" 0 $?
299
+
300
+ write_capsule() {
301
+ local blank_lines="$1" trailing_newline="$2"
302
+ {
303
+ printf "$PCON"
304
+ printf '%s\n' \
305
+ '## Local Craft' \
306
+ 'None' \
307
+ '## Design Convergence' \
308
+ '- **Direct MVP**: call it directly' \
309
+ '- **Failed Items**: None' \
310
+ '## Implementation Plan' \
311
+ '### Task Group 1: A' \
312
+ '**Files:** `a.ts`' \
313
+ '**Scenarios covered:** SC-1'
314
+ for ((i = 0; i < blank_lines; i++)); do printf '\n'; done
315
+ if [[ "$trailing_newline" -eq 1 ]]; then
316
+ printf 'final logical line\n'
317
+ else
318
+ printf 'final logical line'
319
+ fi
320
+ } > "$pdir/spec.md"
321
+ }
322
+
323
+ write_capsule 284 1
324
+ bash "$VS" "$pdir" >/dev/null 2>&1
325
+ check "validate-spec: a 300-line capsule with a trailing newline passes" 0 $?
326
+
327
+ write_capsule 284 0
328
+ bash "$VS" "$pdir" >/dev/null 2>&1
329
+ check "validate-spec: a 300-line capsule without a trailing newline passes" 0 $?
330
+
331
+ write_capsule 285 0
332
+ out=$(bash "$VS" "$pdir" 2>&1); rc=$?
333
+ grep -q 'spec.md capsule is 301 lines (budget 300)' <<<"$out" && [[ $rc -eq 1 ]] \
334
+ && check "validate-spec: an unterminated 301st line is counted" 0 $? \
335
+ || { echo "FAIL validate-spec: unterminated final line not counted"; echo "$out"; fail=1; }
336
+
337
+ { printf "$PCON"; cat <<'MD'
338
+ ## Design Convergence
339
+ - **Direct MVP**: call it directly
340
+ ## Implementation Plan
341
+ ### Task Group 1: A
342
+ **Files:** `a.ts`
343
+ **Scenarios covered:** SC-1
344
+ MD
345
+ } > "$pdir/spec.md"
346
+ out=$(bash "$VS" "$pdir" 2>&1); rc=$?
347
+ grep -q 'spec.md has no Local Craft section' <<<"$out" && [[ $rc -eq 1 ]] \
348
+ && check "validate-spec: a capsule with no Local Craft section fails" 0 $? \
349
+ || { echo "FAIL validate-spec: missing Local Craft not caught"; echo "$out"; fail=1; }
350
+
351
+ { printf "$PCON"; cat <<'MD'
352
+ ## Local Craft
353
+ - Reuse the existing helper.
354
+ ## Design Convergence
355
+ - **Direct MVP**: call it directly
356
+ ## Implementation Plan
357
+ ### Task Group 1: A
358
+ **Files:** `a.ts`
359
+ **Scenarios covered:** SC-1
360
+ MD
361
+ } > "$pdir/spec.md"
362
+ out=$(bash "$VS" "$pdir" 2>&1); rc=$?
363
+ grep -q 'spec.md Local Craft has no file:line or URL evidence' <<<"$out" && [[ $rc -eq 1 ]] \
364
+ && check "validate-spec: ungrounded Local Craft evidence fails" 0 $? \
365
+ || { echo "FAIL validate-spec: ungrounded Local Craft not caught"; echo "$out"; fail=1; }
366
+
367
+ { printf "$PCON"; cat <<'MD'
368
+ ## Local Craft
369
+ - `src/a.ts:1` uses the existing helper.
370
+ ## Design Convergence
371
+ - **Direct MVP**: call it directly
372
+ ## Implementation Plan
373
+ ### Task Group 1: A
374
+ **Files:** `a.ts`
375
+ **Scenarios covered:** SC-1
376
+ MD
377
+ } > "$pdir/spec.md"
378
+ bash "$VS" "$pdir" >/dev/null 2>&1; check "validate-spec: grounded Local Craft evidence passes" 0 $?
379
+
380
+ # A group with no Files list is silently skipped by check-converge.sh, so the
381
+ # omission switches off an existing gate instead of merely thinning the plan.
382
+ mkplan <<'MD'
383
+ ## Design Convergence
384
+ - **Direct MVP**: call it directly
385
+ ## Implementation Plan
386
+ ### Task Group 1: A
387
+ **Scenarios covered:** SC-1
388
+ MD
389
+ out=$(bash "$VS" "$pdir" 2>&1)
390
+ grep -q 'has no \*\*Files:\*\* line' <<<"$out" \
391
+ && check "validate-spec: a task group with no Files line fails" 0 $? \
392
+ || { echo "FAIL validate-spec: missing Files line not caught"; echo "$out"; fail=1; }
393
+
394
+ # The section a plan skips exactly when it is adding the most.
395
+ mkplan <<'MD'
396
+ ## Implementation Plan
397
+ ### Task Group 1: A
398
+ **Files:** `a.ts`
399
+ **Scenarios covered:** SC-1
400
+ MD
401
+ out=$(bash "$VS" "$pdir" 2>&1)
402
+ grep -q 'no Design Convergence section' <<<"$out" \
403
+ && check "validate-spec: a capsule with no Design Convergence fails" 0 $? \
404
+ || { echo "FAIL validate-spec: missing Design Convergence not caught"; echo "$out"; fail=1; }
405
+
406
+ # A `## ` heading after the last group must not be read as a group missing its
407
+ # Files line: Change Log and Implementation Notes always follow the plan.
408
+ mkplan <<'MD'
409
+ ## Design Convergence
410
+ - **Direct MVP**: call it directly
411
+ ## Implementation Plan
412
+ ### Task Group 1: A
413
+ **Files:** `a.ts`
414
+ **Scenarios covered:** SC-1
415
+ ## Implementation Notes
416
+ - none
417
+ ## Change Log
418
+ - none
419
+ MD
420
+ bash "$VS" "$pdir" >/dev/null 2>&1
421
+ check "validate-spec: trailing sections after the last group are not a gap" 0 $?
422
+
423
+ # Presence alone passes with four empty labels. Every Adopted Addition answers
424
+ # a Failed Item, so additions against `Failed Items: None` is the section
425
+ # contradicting itself, which is the shape an unjustified abstraction takes.
426
+ mkconv() { printf "$PCON"'## Local Craft\nNone\n## Design Convergence\n%s\n## Implementation Plan\n### Task Group 1: A\n**Files:** `a.ts`\n**Scenarios covered:** SC-1\n' "$1" > "$pdir/spec.md"; }
427
+
428
+ mkconv '- **Direct MVP**: call it directly
429
+ - **Failed Items**: None
430
+ - **Adopted Additions**: None'
431
+ bash "$VS" "$pdir" >/dev/null 2>&1
432
+ check "validate-spec: a converged plan with no additions passes" 0 $?
433
+
434
+ mkconv '- **Direct MVP**: call it directly
435
+ - **Failed Items**: None
436
+ - **Adopted Additions**: a registry layer -> nothing -> it is more flexible'
437
+ out=$(bash "$VS" "$pdir" 2>&1)
438
+ grep -q 'adopts additions while Failed Items is None' <<<"$out" \
439
+ && check "validate-spec: an addition with no Failed Item fails" 0 $? \
440
+ || { echo "FAIL validate-spec: unjustified addition not caught"; echo "$out"; fail=1; }
441
+
442
+ mkconv '- **Direct MVP**: call it directly
443
+ - **Failed Items**: the MVP cannot express per-tenant limits, evidence in the scenario
444
+ - **Adopted Additions**: a per-tenant table -> that item -> nothing smaller holds the state'
445
+ bash "$VS" "$pdir" >/dev/null 2>&1
446
+ check "validate-spec: an addition answering a Failed Item passes" 0 $?
447
+ rm -rf "$pdir"
448
+
449
+ # --- Concurrent grouping across specs ----------------------
450
+ # Advisory only. The failure that matters is a false CONCURRENT: two specs
451
+ # grouped when a dependency or a shared file makes them unsafe.
452
+ CR="$SKILLS/status/scripts/check-requires.py"
453
+ gdir="$tmp/concurrent"
454
+ mkopen() { # mkopen <name> <requires|-> <files|->
455
+ mkdir -p "$gdir/devos/specs/$1"
456
+ { echo "# $1"; echo "## Goal"; echo "x"
457
+ [[ "$2" != "-" ]] && echo "Requires: [$2]"
458
+ echo "## Out of Scope"; echo "- none"; } >"$gdir/devos/specs/$1/spec.md"
459
+ [[ "$3" != "-" ]] && printf '### Task Group 1: t\n**Files:** %s\n' "$3" >>"$gdir/devos/specs/$1/spec.md"
460
+ return 0
461
+ }
462
+ mkopen alpha - '`src/a.ts`, `src/shared.ts`'
463
+ mkopen beta - '`src/b.ts`'
464
+ mkopen gamma beta '`src/g.ts`'
465
+ mkopen delta - '`src/shared.ts`, `src/d.ts`'
466
+ mkopen epsilon - -
467
+ gout=$(python3 "$CR" --concurrent "$gdir" 2>&1)
468
+
469
+ check "concurrent: disjoint independent specs group together" \
470
+ "CONCURRENT group 1: alpha beta" "$(grep '^CONCURRENT group 1' <<<"$gout")"
471
+ check "concurrent: a shared planned file separates two specs" 1 \
472
+ "$(grep -c 'OVERLAP alpha + delta: both plan to touch src/shared.ts' <<<"$gout")"
473
+ check "concurrent: a dependency edge separates two specs" 1 \
474
+ "$(grep -c 'BLOCKED beta + gamma' <<<"$gout")"
475
+ check "concurrent: a spec with no plan is UNPLANNED, never grouped" 1 \
476
+ "$(grep -c '^UNPLANNED epsilon' <<<"$gout")"
477
+ check "concurrent: an unplanned spec appears in no CONCURRENT group" 0 \
478
+ "$(grep '^CONCURRENT group' <<<"$gout" | grep -c epsilon || true)"
479
+ check "concurrent: dependent specs never share a group" 0 \
480
+ "$(grep '^CONCURRENT group' <<<"$gout" | grep -c 'beta.*gamma\|gamma.*beta' || true)"
481
+
482
+ # Directory declarations and descendants are not exact-string matches. Keep
483
+ # this separate from task-group safety so both consumers stay covered.
484
+ pdir="$tmp/concurrent-path"
485
+ mkdir -p "$pdir/devos/specs/alpha" "$pdir/devos/specs/beta"
486
+ for name in alpha beta; do
487
+ printf '# %s\n\n## Goal\nx\n\n## Out of Scope\n- none\n' "$name" \
488
+ > "$pdir/devos/specs/$name/spec.md"
489
+ printf '## Implementation Plan\n### Task Group 1: work\n**Files:** `%s`\n' \
490
+ "$([[ "$name" == alpha ]] && echo src || echo src/render.ts)" \
491
+ >> "$pdir/devos/specs/$name/spec.md"
492
+ done
493
+ pout=$(python3 "$CR" --concurrent "$pdir" 2>&1)
494
+ check "concurrent: directory and descendant specs are separated" 1 \
495
+ "$(grep -c '^OVERLAP alpha + beta: both plan to touch src$' <<<"$pout")"
496
+ check "concurrent: sibling prefix specs remain groupable" 1 \
497
+ "$(sed -i.bak 's|src/render.ts|src2/render.ts|' "$pdir/devos/specs/beta/spec.md"; rm -f "$pdir/devos/specs/beta/spec.md.bak"; python3 "$CR" --concurrent "$pdir" 2>&1 | grep -c '^CONCURRENT group 1: alpha beta$')"
498
+
499
+ rm -rf "$gdir/devos/specs/beta" "$gdir/devos/specs/gamma" "$gdir/devos/specs/delta" "$gdir/devos/specs/epsilon"
500
+ check "concurrent: a single open spec reports nothing to parallelize" \
501
+ "CONCURRENT 1 open spec(s): nothing to run in parallel" \
502
+ "$(python3 "$CR" --concurrent "$gdir" 2>&1)"
503
+
504
+ # --- findings-summary.sh: count records, not ledger lines -----------------
505
+ FS="$SKILLS/status/scripts/findings-summary.sh"
506
+ fdir="$tmp/findings/devos"
507
+ mkdir -p "$fdir"
508
+ cat > "$fdir/deferred.md" <<'MD'
509
+ # Deferred Findings
510
+
511
+ Severity and resolution are not records by themselves.
512
+
513
+ - [2026-01-01] [warning] defer: first finding
514
+ * [2026-01-02] [critical] [spec-amendment]: second finding
515
+ - [2026-01-03] [suggestion] [reject]: third finding
516
+ - [2026-01-04] [warning] defer: patch the critical path
517
+ - [2026-01-05] [suggestion] reject: avoid patch and spec-amendment in the message
518
+ [not-a-record] this prose must not be counted
519
+ MD
520
+ fout=$(bash "$FS" "$tmp/findings" 2>&1)
521
+ check "findings: headings, blank lines, and prose are not findings" 1 \
522
+ "$(grep -c '^| Total findings | 5 |$' <<<"$fout")"
523
+ if grep -Fqx '| By severity: critical | 1 |' <<<"$fout" \
524
+ && grep -Fqx '| By severity: warning | 2 |' <<<"$fout" \
525
+ && grep -Fqx '| By resolution: patch | 0 |' <<<"$fout" \
526
+ && grep -Fqx '| By resolution: spec-amendment | 1 |' <<<"$fout" \
527
+ && grep -Fqx '| By resolution: defer | 2 |' <<<"$fout" \
528
+ && grep -Fqx '| By resolution: reject | 2 |' <<<"$fout"; then
529
+ check "findings: severity and resolution counts come from record fields" 0 0
530
+ else
531
+ check "findings: severity and resolution counts come from record fields" 1 0
532
+ fi
533
+ check "findings: trend counts record dates only" 1 \
534
+ "$(grep -c '^ 2026-01: 5 findings$' <<<"$fout")"
535
+
536
+ # The month belongs to the record's leading bracketed field. A month named in
537
+ # the message is prose, not a second date, and counting it reported one finding
538
+ # under two months.
539
+ fmonth="$tmp/findings-month/devos"
540
+ mkdir -p "$fmonth/specs/archive/example"
541
+ printf -- '- [2026-01-01] [warning] defer: regression was seen in 2025-12\n' \
542
+ > "$fmonth/deferred.md"
543
+ fmout=$(bash "$FS" "$tmp/findings-month" 2>&1)
544
+ check "findings: a month named in the message is not a second date" 1 \
545
+ "$(grep -c '^ 2026-01: 1 findings$' <<<"$fmout")"
546
+ ! grep -Fq ' 2025-12:' <<<"$fmout"
547
+ check "findings: trend never invents a month from message text" 0 $?
548
+ rm -rf "$tmp/findings-month"
549
+
550
+ # The zero-findings rule counts specs, not ledger lines, and only L-route ones.
551
+ # Counting records against a completed-spec denominator printed "3 of 2", a
552
+ # ratio no set of specs can have, and an M-route entry inflated an L-only rule.
553
+ zroute="$tmp/findings-zero-route/devos/specs/archive"
554
+ mkdir -p "$zroute/large" "$zroute/small"
555
+ cat > "$tmp/findings-zero-route/devos/deferred.md" <<'MD'
556
+ - [large] [warning] defer: zero findings on first run
557
+ - [large] [suggestion] defer: zero findings on first run
558
+ - [small] [warning] defer: no findings on first run
559
+ MD
560
+ printf 'large\tL\tyes\t0\tnone\tyes\t?\t-/0\t-\n' > "$zroute/large.quality.md"
561
+ printf 'small\tM\tyes\t0\tnone\tyes\t?\t-/0\t-\n' > "$zroute/small.quality.md"
562
+ zout=$(bash "$FS" "$tmp/findings-zero-route" 2>&1)
563
+ check "findings: a spec counts once however many records mention it" 1 \
564
+ "$(grep -c '^Zero-findings rule: 1 of 2 completed specs' <<<"$zout")"
565
+ ! grep -Fq ' 2 of ' <<<"$zout" && ! grep -Fq ' 3 of ' <<<"$zout"
566
+ check "findings: the numerator can never exceed the completed specs" 0 $?
567
+ sed -i.bak 's/^small\tM\t/small\tL\t/' "$zroute/small.quality.md" && rm -f "$zroute/small.quality.md.bak"
568
+ zout2=$(bash "$FS" "$tmp/findings-zero-route" 2>&1)
569
+ check "findings: an L-route spec does count toward the rule" 1 \
570
+ "$(grep -c '^Zero-findings rule: 2 of 2 completed specs' <<<"$zout2")"
571
+ rm -rf "$tmp/findings-zero-route"
572
+
573
+ # The rule measures a clean first pass, so the record has to claim one. Prose
574
+ # that mentions an absence is not a measurement, and crediting it inflated the
575
+ # numerator with a spec whose first pass was never established.
576
+ fpass="$tmp/findings-first-pass/devos/specs/archive"
577
+ mkdir -p "$fpass/prose" "$fpass/measured"
578
+ printf -- '- [prose] [warning] defer: no findings were observed\n' \
579
+ > "$tmp/findings-first-pass/devos/deferred.md"
580
+ printf 'prose\tL\tyes\t0\tnone\tyes\t?\t-/0\t-\n' > "$fpass/prose.quality.md"
581
+ printf 'measured\tL\tyes\t0\tnone\tyes\t?\t-/0\t-\n' > "$fpass/measured.quality.md"
582
+ fpout=$(bash "$FS" "$tmp/findings-first-pass" 2>&1)
583
+ check "findings: prose mentioning no findings is not a first-pass claim" 1 \
584
+ "$(grep -c '^Zero-findings rule: 0 of 2 completed specs' <<<"$fpout")"
585
+ printf -- '- [measured] [warning] defer: zero findings on first run\n' \
586
+ >> "$tmp/findings-first-pass/devos/deferred.md"
587
+ fpout2=$(bash "$FS" "$tmp/findings-first-pass" 2>&1)
588
+ check "findings: an explicit first-run claim is still counted" 1 \
589
+ "$(grep -c '^Zero-findings rule: 1 of 2 completed specs' <<<"$fpout2")"
590
+ rm -rf "$tmp/findings-first-pass"
591
+