@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.
- package/CHANGELOG.md +1421 -0
- package/LICENSE +201 -0
- package/README.md +206 -2
- package/package.json +44 -4
- package/plugins/devos/agents/reader.md +27 -0
- package/plugins/devos/agents/verifier.md +155 -0
- package/plugins/devos/pi/extension/devos.ts +605 -0
- package/plugins/devos/scripts/check-evidence-router.sh +140 -0
- package/plugins/devos/scripts/evidence-router.py +254 -0
- package/plugins/devos/scripts/gates/check-dod-core.sh +285 -0
- package/plugins/devos/scripts/gates/check-dod.sh +38 -0
- package/plugins/devos/scripts/gates/check-implementation-boundary.sh +99 -0
- package/plugins/devos/scripts/gates/check-port-source.sh +134 -0
- package/plugins/devos/scripts/gates/check-report-locations.sh +148 -0
- package/plugins/devos/scripts/gates/check-scenario-coverage.sh +104 -0
- package/plugins/devos/scripts/gates/gate-check.mjs +204 -0
- package/plugins/devos/scripts/gates/phase-gate.sh +208 -0
- package/plugins/devos/scripts/gates/plan-template-check.py +141 -0
- package/plugins/devos/scripts/gates/run-gate.sh +148 -0
- package/plugins/devos/scripts/gates/spec-contract.sh +19 -0
- package/plugins/devos/scripts/gates/spec-template-check.py +152 -0
- package/plugins/devos/scripts/gates/suite/01-dod.sh +485 -0
- package/plugins/devos/scripts/gates/suite/02-integrity.sh +310 -0
- package/plugins/devos/scripts/gates/suite/03-archetype.sh +255 -0
- package/plugins/devos/scripts/gates/suite/04-spec-validator.sh +183 -0
- package/plugins/devos/scripts/gates/suite/05-requires.sh +360 -0
- package/plugins/devos/scripts/gates/suite/06-clarify-adapters.sh +435 -0
- package/plugins/devos/scripts/gates/suite/07-lint-evals.sh +350 -0
- package/plugins/devos/scripts/gates/suite/08-converge.sh +591 -0
- package/plugins/devos/scripts/gates/suite/09-quality.sh +516 -0
- package/plugins/devos/scripts/gates/suite/10-eval-harness.sh +679 -0
- package/plugins/devos/scripts/gates/test-gates.sh +76 -0
- package/plugins/devos/scripts/gates/test-integrity-rubric.sh +152 -0
- package/plugins/devos/scripts/gates/test-phase-gate.sh +116 -0
- package/plugins/devos/skills/absorb/SKILL.md +75 -0
- package/plugins/devos/skills/absorb/references/distill.md +67 -0
- package/plugins/devos/skills/absorb/scripts/check-refs.sh +108 -0
- package/plugins/devos/skills/absorb/scripts/knowledge.py +258 -0
- package/plugins/devos/skills/build/SKILL.md +71 -0
- package/plugins/devos/skills/build/references/advanced-routing.md +19 -0
- package/plugins/devos/skills/build/references/defect.md +17 -0
- package/plugins/devos/skills/build/references/exposure.md +28 -0
- package/plugins/devos/skills/build/references/hard.md +39 -0
- package/plugins/devos/skills/build/references/refactor.md +66 -0
- package/plugins/devos/skills/build/references/routes.md +56 -0
- package/plugins/devos/skills/build/references/scale.md +84 -0
- package/plugins/devos/skills/build/references/spike.md +19 -0
- package/plugins/devos/skills/build/scripts/construct-census.py +204 -0
- package/plugins/devos/skills/build/scripts/dep-order.py +297 -0
- package/plugins/devos/skills/build/scripts/ledger.sh +228 -0
- package/plugins/devos/skills/build/scripts/route.sh +5 -0
- package/plugins/devos/skills/build/scripts/secret-scan.sh +121 -0
- package/plugins/devos/skills/build/scripts/toolchain-preflight.py +302 -0
- package/plugins/devos/skills/frame/SKILL.md +54 -0
- package/plugins/devos/skills/frame/references/template.md +115 -0
- package/plugins/devos/skills/frame/scripts/survey.sh +44 -0
- package/plugins/devos/skills/implement/SKILL.md +36 -0
- package/plugins/devos/skills/implement/references/conditional-plan.md +17 -0
- package/plugins/devos/skills/implement/references/debug-loop.md +7 -0
- package/plugins/devos/skills/implement/references/dod.md +37 -0
- package/plugins/devos/skills/implement/references/implement.md +54 -0
- package/plugins/devos/skills/implement/references/manual-gates.md +16 -0
- package/plugins/devos/skills/implement/references/plan.md +142 -0
- package/plugins/devos/skills/implement/references/resume.md +9 -0
- package/plugins/devos/skills/implement/references/scale.md +86 -0
- package/plugins/devos/skills/implement/references/verify-close.md +62 -0
- package/plugins/devos/skills/implement/references/visual-verification.md +7 -0
- package/plugins/devos/skills/implement/scripts/check-converge.sh +147 -0
- package/plugins/devos/skills/implement/scripts/equivalence-check.sh +140 -0
- package/plugins/devos/skills/implement/scripts/manifest-queue.sh +185 -0
- package/plugins/devos/skills/implement/scripts/ops-log.sh +58 -0
- package/plugins/devos/skills/implement/scripts/pilot-consistency.py +173 -0
- package/plugins/devos/skills/implement/scripts/validate-spec.sh +220 -0
- package/plugins/devos/skills/init/SKILL.md +100 -0
- package/plugins/devos/skills/init/references/archetype-sections.md +15 -0
- package/plugins/devos/skills/init/references/context.md +42 -0
- package/plugins/devos/skills/init/references/conventions-template.md +153 -0
- package/plugins/devos/skills/init/references/reverse-engineer.md +3 -0
- package/plugins/devos/skills/init/references/rule-format.md +58 -0
- package/plugins/devos/skills/init/references/shape-model.md +29 -0
- package/plugins/devos/skills/init/scripts/detect-archetype.py +461 -0
- package/plugins/devos/skills/init/scripts/render-rule.py +114 -0
- package/plugins/devos/skills/init/scripts/reverse-engineer.sh +162 -0
- package/plugins/devos/skills/learn/SKILL.md +29 -0
- package/plugins/devos/skills/learn/references/destinations.md +43 -0
- package/plugins/devos/skills/learn/references/scoring.md +26 -0
- package/plugins/devos/skills/review/SKILL.md +54 -0
- package/plugins/devos/skills/review/references/comments.md +13 -0
- package/plugins/devos/skills/review/references/gaps.md +26 -0
- package/plugins/devos/skills/review/references/reviewer.md +124 -0
- package/plugins/devos/skills/review/references/routing.md +35 -0
- package/plugins/devos/skills/review/scripts/__pycache__/prepare.cpython-313.pyc +0 -0
- package/plugins/devos/skills/review/scripts/prepare.py +763 -0
- package/plugins/devos/skills/spec/SKILL.md +57 -0
- package/plugins/devos/skills/spec/references/prototype.md +21 -0
- package/plugins/devos/skills/spec/references/question-craft.md +47 -0
- package/plugins/devos/skills/spec/references/roadmap-link.md +5 -0
- package/plugins/devos/skills/spec/references/write-spec.md +128 -0
- package/plugins/devos/skills/spec/scripts/clarify.sh +173 -0
- package/plugins/devos/skills/status/SKILL.md +67 -0
- package/plugins/devos/skills/status/references/cost.md +38 -0
- package/plugins/devos/skills/status/scripts/artifact-budgets.sh +88 -0
- package/plugins/devos/skills/status/scripts/check-requires.py +556 -0
- package/plugins/devos/skills/status/scripts/context-cost.sh +89 -0
- package/plugins/devos/skills/status/scripts/convention-usage.sh +184 -0
- package/plugins/devos/skills/status/scripts/findings-summary.sh +112 -0
- package/plugins/devos/skills/status/scripts/quality-correlation.sh +259 -0
- package/plugins/devos/skills/status/scripts/sizing-calibration.sh +71 -0
- package/plugins/devos/skills/status/scripts/spec-diff.sh +137 -0
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# One dispatcher for every tool hook shim. Usage: run-gate.sh --agent <tool>
|
|
3
|
+
# <test-integrity|dod>.
|
|
4
|
+
#
|
|
5
|
+
# Per-tool differences (jq field paths, the rubric --format flag, the JSON
|
|
6
|
+
# response contract) live in the case branches below, one arm per tool that
|
|
7
|
+
# has a hook: claude, cursor, copilot, codex. Adding a tool that supports hooks is
|
|
8
|
+
# adding a case arm here.
|
|
9
|
+
#
|
|
10
|
+
# Hand-maintained since 0.11.9: the generator that used to emit this file was
|
|
11
|
+
# removed with the per-tool agent translations.
|
|
12
|
+
#
|
|
13
|
+
# Unparseable input allows rather than blocks: a broken adapter must never
|
|
14
|
+
# brick every edit in the session.
|
|
15
|
+
set -u
|
|
16
|
+
GATES="$(cd "$(dirname "${BASH_SOURCE[0]}")" 2>/dev/null && pwd)"
|
|
17
|
+
|
|
18
|
+
AGENT=""
|
|
19
|
+
GATE=""
|
|
20
|
+
while [[ $# -gt 0 ]]; do
|
|
21
|
+
case "$1" in
|
|
22
|
+
--agent)
|
|
23
|
+
[[ $# -ge 2 ]] || break
|
|
24
|
+
AGENT="$2"; shift 2
|
|
25
|
+
;;
|
|
26
|
+
test-integrity|dod) GATE="$1"; shift;;
|
|
27
|
+
*) shift;;
|
|
28
|
+
esac
|
|
29
|
+
done
|
|
30
|
+
if [[ -z "$AGENT" || -z "$GATE" ]]; then
|
|
31
|
+
echo "run-gate.sh: usage: --agent <tool> <test-integrity|dod>" >&2
|
|
32
|
+
exit 0
|
|
33
|
+
fi
|
|
34
|
+
|
|
35
|
+
TI_FILE="" TI_CONTENT="" TI_NEW="" TI_OLD="" TI_FORMAT="" TI_ALLOW=""
|
|
36
|
+
DOD_TRANSCRIPT="" DOD_ALLOW="" DOD_DENY=""
|
|
37
|
+
case "$AGENT" in
|
|
38
|
+
cursor)
|
|
39
|
+
TI_FILE='.tool_input.path // .tool_input.file_path // .tool_input.target_file // empty'
|
|
40
|
+
TI_CONTENT='.tool_input.content // empty'
|
|
41
|
+
TI_NEW='.tool_input.new_string // .tool_input.new_content // empty'
|
|
42
|
+
TI_OLD='.tool_input.old_string // empty'
|
|
43
|
+
TI_FORMAT='cursor'
|
|
44
|
+
TI_ALLOW='{"permission":"allow"}'
|
|
45
|
+
DOD_TRANSCRIPT=''
|
|
46
|
+
DOD_ALLOW=''
|
|
47
|
+
DOD_DENY=''
|
|
48
|
+
;;
|
|
49
|
+
copilot)
|
|
50
|
+
TI_FILE='.toolArgs.path // .toolArgs.file_path // .toolArgs.target_file // empty'
|
|
51
|
+
TI_CONTENT='.toolArgs.content // empty'
|
|
52
|
+
TI_NEW='.toolArgs.new_string // .toolArgs.new_content // empty'
|
|
53
|
+
TI_OLD='.toolArgs.old_string // empty'
|
|
54
|
+
TI_FORMAT='copilot'
|
|
55
|
+
TI_ALLOW='{"permissionDecision":"allow"}'
|
|
56
|
+
DOD_TRANSCRIPT='.transcriptPath // empty'
|
|
57
|
+
DOD_ALLOW='{"decision":"allow"}'
|
|
58
|
+
DOD_DENY='{"decision":"block","reason":"%s"}'
|
|
59
|
+
;;
|
|
60
|
+
codex)
|
|
61
|
+
TI_FILE='.tool_input.path // .tool_input.file_path // .tool_input.target_file // empty'
|
|
62
|
+
TI_CONTENT='.tool_input.content // empty'
|
|
63
|
+
TI_NEW='.tool_input.new_string // .tool_input.new_content // empty'
|
|
64
|
+
TI_OLD='.tool_input.old_string // empty'
|
|
65
|
+
TI_FORMAT='codex'
|
|
66
|
+
TI_ALLOW='{"permissionDecision":"allow"}'
|
|
67
|
+
DOD_TRANSCRIPT='.transcript_path // empty'
|
|
68
|
+
DOD_ALLOW='{"continue":true}'
|
|
69
|
+
DOD_DENY='{"continue":false,"stopReason":"%s"}'
|
|
70
|
+
;;
|
|
71
|
+
claude)
|
|
72
|
+
TI_FILE='.tool_input.file_path // empty'
|
|
73
|
+
TI_CONTENT='.tool_input.content // empty'
|
|
74
|
+
TI_NEW='.tool_input.new_string // empty'
|
|
75
|
+
TI_OLD='.tool_input.old_string // empty'
|
|
76
|
+
TI_FORMAT=''
|
|
77
|
+
TI_ALLOW=''
|
|
78
|
+
DOD_TRANSCRIPT=''
|
|
79
|
+
DOD_ALLOW=''
|
|
80
|
+
DOD_DENY=''
|
|
81
|
+
;;
|
|
82
|
+
*)
|
|
83
|
+
exit 0
|
|
84
|
+
;;
|
|
85
|
+
esac
|
|
86
|
+
|
|
87
|
+
if [[ "$GATE" == "test-integrity" ]]; then
|
|
88
|
+
command -v jq >/dev/null 2>&1 || { [[ -n "$TI_ALLOW" ]] && echo "$TI_ALLOW"; exit 0; }
|
|
89
|
+
# An unreachable rubric (moved clone, missing gate script) must allow, not
|
|
90
|
+
# exit 127 with no decision emitted.
|
|
91
|
+
[[ -x "$GATES/test-integrity-rubric.sh" ]] || { [[ -n "$TI_ALLOW" ]] && echo "$TI_ALLOW"; exit 0; }
|
|
92
|
+
input=$(cat)
|
|
93
|
+
file=$(printf '%s' "$input" | jq -r "$TI_FILE" 2>/dev/null)
|
|
94
|
+
content=$(printf '%s' "$input" | jq -r "$TI_CONTENT" 2>/dev/null)
|
|
95
|
+
new_string=$(printf '%s' "$input" | jq -r "$TI_NEW" 2>/dev/null)
|
|
96
|
+
old_string=$(printf '%s' "$input" | jq -r "$TI_OLD" 2>/dev/null)
|
|
97
|
+
if [[ -z "$file" ]]; then
|
|
98
|
+
if printf '%s' "$input" | jq -e 'has("tool_input") or has("toolArgs")' >/dev/null 2>&1; then
|
|
99
|
+
echo "run-gate.sh: test-integrity could not read file path from payload (field renamed?); allowing (fail-open)" >&2
|
|
100
|
+
fi
|
|
101
|
+
[[ -n "$TI_ALLOW" ]] && echo "$TI_ALLOW"
|
|
102
|
+
exit 0
|
|
103
|
+
fi
|
|
104
|
+
old_tmp=$(mktemp)
|
|
105
|
+
new_tmp=$(mktemp)
|
|
106
|
+
trap 'rm -f "$old_tmp" "$new_tmp"' EXIT
|
|
107
|
+
write=0
|
|
108
|
+
if [[ -n "$content" ]]; then
|
|
109
|
+
[[ -f "$file" ]] && cp "$file" "$old_tmp"
|
|
110
|
+
printf '%s' "$content" > "$new_tmp"
|
|
111
|
+
write=1
|
|
112
|
+
else
|
|
113
|
+
printf '%s' "$old_string" > "$old_tmp"
|
|
114
|
+
printf '%s' "$new_string" > "$new_tmp"
|
|
115
|
+
fi
|
|
116
|
+
if [[ -n "$TI_FORMAT" ]]; then
|
|
117
|
+
gate_args=(--format "$TI_FORMAT" --file "$file" --old "$old_tmp" --new "$new_tmp")
|
|
118
|
+
else
|
|
119
|
+
gate_args=(--file "$file" --old "$old_tmp" --new "$new_tmp")
|
|
120
|
+
fi
|
|
121
|
+
[[ "$write" -eq 1 ]] && gate_args+=(--write)
|
|
122
|
+
"$GATES/test-integrity-rubric.sh" "${gate_args[@]}"
|
|
123
|
+
status=$?
|
|
124
|
+
rm -f "$old_tmp" "$new_tmp"
|
|
125
|
+
exit "$status"
|
|
126
|
+
elif [[ "$GATE" == "dod" ]]; then
|
|
127
|
+
command -v jq >/dev/null 2>&1 || { [[ -n "$DOD_ALLOW" ]] && echo "$DOD_ALLOW"; exit 0; }
|
|
128
|
+
input=$(cat)
|
|
129
|
+
transcript=$(printf '%s' "$input" | jq -r "$DOD_TRANSCRIPT" 2>/dev/null)
|
|
130
|
+
if [[ -z "$transcript" || ! -x "$GATES/check-dod-core.sh" ]]; then
|
|
131
|
+
[[ -n "$DOD_ALLOW" ]] && echo "$DOD_ALLOW"
|
|
132
|
+
exit 0
|
|
133
|
+
fi
|
|
134
|
+
reason=$("$GATES/check-dod-core.sh" "$transcript" 2>&1)
|
|
135
|
+
status=$?
|
|
136
|
+
if [[ $status -eq 2 ]]; then
|
|
137
|
+
escaped=$(printf '%s' "$reason" | sed 's/"/\\"/g' | tr '\n' ' ')
|
|
138
|
+
if [[ -n "$DOD_DENY" ]]; then
|
|
139
|
+
printf "$DOD_DENY" "$escaped"
|
|
140
|
+
else
|
|
141
|
+
echo "$reason" >&2
|
|
142
|
+
exit 2
|
|
143
|
+
fi
|
|
144
|
+
else
|
|
145
|
+
[[ -n "$DOD_ALLOW" ]] && echo "$DOD_ALLOW"
|
|
146
|
+
fi
|
|
147
|
+
exit 0
|
|
148
|
+
fi
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# spec-contract.sh <spec-dir>: print the contract sections of spec.md (Goal,
|
|
3
|
+
# Scenarios, Functionality, Behavior delta, Invariant, Functional constraints,
|
|
4
|
+
# Out of scope) plus any Requires: line. Exit 1 with no output when spec.md is missing.
|
|
5
|
+
# spec-contract.sh --has-plan <spec-dir>: exit 0 when spec.md carries an Implementation Plan.
|
|
6
|
+
if [[ "${1:-}" == "--has-plan" ]]; then
|
|
7
|
+
grep -q '^## Implementation Plan' "${2:-}/spec.md" 2>/dev/null
|
|
8
|
+
exit
|
|
9
|
+
fi
|
|
10
|
+
dir="${1:-}"
|
|
11
|
+
[[ -f "$dir/spec.md" ]] || exit 1
|
|
12
|
+
awk '
|
|
13
|
+
/^## / {
|
|
14
|
+
h = tolower($0); sub(/^##[ \t]*/, "", h); sub(/^[0-9]+[.)]?[ \t]*/, "", h)
|
|
15
|
+
keep = (h ~ /^(goal|scenarios|functionality|behavior delta|invariant|functional constraints|out of scope)/)
|
|
16
|
+
}
|
|
17
|
+
/^Requires:/ { print; next }
|
|
18
|
+
keep { print }
|
|
19
|
+
' "$dir/spec.md"
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Both spec shapes in write-spec.md must pass the gate.
|
|
3
|
+
|
|
4
|
+
An M change is a few files with clear behavior, and the router sends it to the
|
|
5
|
+
one-page shape as the whole specification. An L change is sent to the full
|
|
6
|
+
shape. Both are contracts in the same sense the plan.md template is one: if
|
|
7
|
+
either drifts from what validate-spec.sh reads, every spec the model writes
|
|
8
|
+
from it is rejected, and the first thing that shows it is a real run failing on
|
|
9
|
+
something nobody changed.
|
|
10
|
+
|
|
11
|
+
Each block is extracted, its placeholders filled, and the result run through the
|
|
12
|
+
gate. The REQUIRED pre-assert is one-directional on purpose: remove Out of scope
|
|
13
|
+
from a block and validate-spec rejects the specimen. Add a new requirement to
|
|
14
|
+
validate-spec.sh and a specimen fails because the block does not carry it. Both
|
|
15
|
+
directions were checked by hand before this shipped.
|
|
16
|
+
"""
|
|
17
|
+
import re
|
|
18
|
+
import subprocess
|
|
19
|
+
import sys
|
|
20
|
+
import tempfile
|
|
21
|
+
from pathlib import Path
|
|
22
|
+
|
|
23
|
+
ROOT = Path(__file__).resolve().parents[4]
|
|
24
|
+
SKILLS = ROOT / "plugins/devos/skills"
|
|
25
|
+
WRITE_SPEC = SKILLS / "spec/references/write-spec.md"
|
|
26
|
+
VALIDATE = SKILLS / "implement/scripts/validate-spec.sh"
|
|
27
|
+
|
|
28
|
+
# The three things validate-spec.sh requires of a functional spec. Present as
|
|
29
|
+
# substrings because the block is a template, not a finished spec.
|
|
30
|
+
REQUIRED = [
|
|
31
|
+
"## Goal",
|
|
32
|
+
"## Scenarios",
|
|
33
|
+
"Scenario SC-1:",
|
|
34
|
+
"Scenario SC-2:",
|
|
35
|
+
"WHEN [condition] / THEN [observable outcome]",
|
|
36
|
+
"## Out of scope",
|
|
37
|
+
]
|
|
38
|
+
|
|
39
|
+
FILL = [
|
|
40
|
+
(r"^# \[Feature Name\]$", "# Export invoices"),
|
|
41
|
+
(r"^\[1-2 sentences of business purpose\]$", "A user downloads their invoices."),
|
|
42
|
+
(r"^- Scenario SC-1: .*$",
|
|
43
|
+
"- Scenario SC-1: plain export / WHEN an account has 3 invoices "
|
|
44
|
+
"/ THEN a PDF with all 3 is downloaded"),
|
|
45
|
+
(r"^- Scenario SC-2: .*$",
|
|
46
|
+
"- Scenario SC-2: empty account / WHEN an account has no invoices "
|
|
47
|
+
"/ THEN the export is refused naming why"),
|
|
48
|
+
(r"^- \[Item 1 explicitly out of scope\]$", "- Scheduled exports"),
|
|
49
|
+
]
|
|
50
|
+
|
|
51
|
+
# The full L shape. Same three requirements plus the two sections an L feature
|
|
52
|
+
# exists to produce, the Behavior delta and the Functional Constraints.
|
|
53
|
+
L_REQUIRED = REQUIRED + ["## Behavior delta", "## Functional constraints"]
|
|
54
|
+
|
|
55
|
+
L_FILL = FILL + [
|
|
56
|
+
(r"^- \[Rule 1\]$", "- one rule"),
|
|
57
|
+
(r"^\*\*Added\*\* \(capability: .*$", "**Added** (capability: `invoices`):"),
|
|
58
|
+
(r"^- \[New behavior, one line each\]$", "- a new behavior"),
|
|
59
|
+
(r"^- \[Current behavior, quoted\] → \[new behavior\]$", "- old -> new"),
|
|
60
|
+
(r"^\*\*Modified\*\* \(capability: .*$", "**Modified** (capability: `invoices`):"),
|
|
61
|
+
(r"^\*\*Removed:\*\* \(none\)$", "**Removed:** (none)"),
|
|
62
|
+
(r"^- \[Constraint 1, functional only\]$", "- functional only"),
|
|
63
|
+
(r"^\*\*Engineer overrides:\*\* .*$", "**Engineer overrides:** none"),
|
|
64
|
+
(r"^\*\*Open assumptions:\*\* .*$", "**Open assumptions:** none"),
|
|
65
|
+
(r"^Requires: .*$", "Requires: none"),
|
|
66
|
+
]
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def block(heading, required, fill):
|
|
70
|
+
body = WRITE_SPEC.read_text()
|
|
71
|
+
# Take the first fenced block after the heading rather than slicing to the
|
|
72
|
+
# next `## ` line: the block's own headings (`## Goal`, `## Out of
|
|
73
|
+
# scope`) are the same level, so a section boundary cannot find the end of
|
|
74
|
+
# it. Locating the fence by position survives renumbering the sections.
|
|
75
|
+
start = re.search(rf"^## \d+\. {re.escape(heading)}$", body, re.M)
|
|
76
|
+
if not start:
|
|
77
|
+
raise SystemExit(f"FAIL spec-template: write-spec.md has no '{heading}' section")
|
|
78
|
+
fenced = re.search(r"```markdown\n(.*?)\n```", body[start.end():], re.S)
|
|
79
|
+
if not fenced:
|
|
80
|
+
raise SystemExit(f"FAIL spec-template: the {heading} section carries no ```markdown block")
|
|
81
|
+
raw = fenced.group(1)
|
|
82
|
+
absent = [t for t in required if t not in raw]
|
|
83
|
+
if absent:
|
|
84
|
+
raise SystemExit(
|
|
85
|
+
f"FAIL spec-template: the {heading} block no longer carries what "
|
|
86
|
+
"validate-spec.sh requires, so every spec written from it is rejected. "
|
|
87
|
+
"Missing:\n " + "\n ".join(absent))
|
|
88
|
+
spec = raw
|
|
89
|
+
for pattern, value in fill:
|
|
90
|
+
spec = re.sub(pattern, value, spec, flags=re.M)
|
|
91
|
+
# Ask the drift question against the RAW block: a raw line carrying a
|
|
92
|
+
# bracket that no FILL rule matches is a placeholder this specimen does not
|
|
93
|
+
# fill, so it is testing an older shape than the file holds. Asking it
|
|
94
|
+
# against the substituted text instead is wrong, because a replacement value
|
|
95
|
+
# may itself contain brackets, which is exactly what `- [ ] Criterion 1`
|
|
96
|
+
# does.
|
|
97
|
+
unfilled = [l.strip() for l in raw.splitlines()
|
|
98
|
+
if "[" in l and l.strip() != "["
|
|
99
|
+
and not any(re.search(p, l, re.M) for p, _ in fill)]
|
|
100
|
+
if unfilled:
|
|
101
|
+
raise SystemExit(
|
|
102
|
+
f"FAIL spec-template: the FILL list no longer covers the {heading} block, "
|
|
103
|
+
"so this check is testing an older shape than the file holds. Unfilled:\n "
|
|
104
|
+
+ "\n ".join(unfilled[:6]))
|
|
105
|
+
# Guidance inside the form lands in the artifact. Two real specs in this
|
|
106
|
+
# repo still carry a template note that told the writer where technical
|
|
107
|
+
# constraints belong, because it was a line of the form rather than of the
|
|
108
|
+
# instructions. A short bracketed line is a field placeholder the author
|
|
109
|
+
# overwrites; a long one is a paragraph of advice nobody overwrites.
|
|
110
|
+
paras = [l.strip() for l in raw.splitlines()
|
|
111
|
+
if len(l.strip()) > 60 and l.strip().startswith("[") and l.strip().endswith("]")]
|
|
112
|
+
if paras:
|
|
113
|
+
raise SystemExit(
|
|
114
|
+
f"FAIL spec-template: the {heading} block carries guidance a model will "
|
|
115
|
+
"paste into the spec instead of a field it will fill:\n "
|
|
116
|
+
+ "\n ".join(p[:70] for p in paras[:4])
|
|
117
|
+
+ "\n fix: move it above the fence, into the section's prose")
|
|
118
|
+
return spec.rstrip() + "\n"
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def m_block():
|
|
122
|
+
return block("M: one page", REQUIRED, FILL)
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def l_block():
|
|
126
|
+
return block("L: the full shape", L_REQUIRED, L_FILL)
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def main():
|
|
130
|
+
failures = []
|
|
131
|
+
for label, shape in (("M: one page", m_block), ("L: the full shape", l_block)):
|
|
132
|
+
spec = shape()
|
|
133
|
+
with tempfile.TemporaryDirectory() as tmp:
|
|
134
|
+
d = Path(tmp) / "spec"
|
|
135
|
+
d.mkdir()
|
|
136
|
+
(d / "spec.md").write_text(spec)
|
|
137
|
+
r = subprocess.run(["bash", str(VALIDATE), str(d)],
|
|
138
|
+
capture_output=True, text=True)
|
|
139
|
+
if r.returncode != 0:
|
|
140
|
+
failures.append((label, r.stdout + r.stderr))
|
|
141
|
+
if failures:
|
|
142
|
+
for label, out in failures:
|
|
143
|
+
print(f"FAIL the {label} shape in write-spec.md does not pass "
|
|
144
|
+
"validate-spec, so every spec the model writes from it is "
|
|
145
|
+
"rejected:", file=sys.stderr)
|
|
146
|
+
print(out, file=sys.stderr)
|
|
147
|
+
return 1
|
|
148
|
+
print("PASS both spec shapes in write-spec.md pass validate-spec")
|
|
149
|
+
return 0
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
sys.exit(main())
|