@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,38 @@
1
+ #!/bin/bash
2
+ # DoD stop-gate: a turn may not end on "Verdict: DONE" unless the spec's
3
+ # verification report actually exists. Deterministic, no LLM judgment.
4
+ # Exit 0 = allow, exit 2 = block (reason on stderr).
5
+ #
6
+ # Claude-specific transcript extraction (JSONL, stop_hook_active guard) lives
7
+ # here; the actual DONE/verification-report decision is the sibling
8
+ # check-dod-core.sh, shared with every adapter.
9
+ #
10
+ # This wrapper and its core sit inside the plugin so `claude plugin install`
11
+ # (which copies only the plugin dir) ships them together. Resolve the core as
12
+ # a sibling only, never a climb out of the plugin: on a copied install nothing
13
+ # outside ${CLAUDE_PLUGIN_ROOT} exists.
14
+ set -u
15
+
16
+ CORE="$(cd "$(dirname "${BASH_SOURCE[0]}")" 2>/dev/null && pwd)/check-dod-core.sh"
17
+
18
+ input=$(cat)
19
+ command -v jq >/dev/null 2>&1 || exit 0
20
+
21
+ # Avoid blocking loops: if we already blocked once this stop, let it through.
22
+ [[ $(printf '%s' "$input" | jq -r '.stop_hook_active // false' 2>/dev/null) == "true" ]] && exit 0
23
+
24
+ # jq's own parse errors stay off stderr: on non-JSON stdin this hook allows, and
25
+ # a hook that allows must say nothing. Stderr from a gate reads as a gate reason.
26
+ transcript=$(printf '%s' "$input" | jq -r '.transcript_path // empty' 2>/dev/null)
27
+ [[ -f "$transcript" ]] || exit 0
28
+
29
+ last=$(jq -rs '[.[] | select(.type=="assistant")] | last
30
+ | .message.content | map(select(.type=="text") | .text) | join("\n")' "$transcript" 2>/dev/null) || exit 0
31
+
32
+ [[ -x "$CORE" ]] || exit 0
33
+ tmp=$(mktemp)
34
+ printf '%s' "$last" > "$tmp"
35
+ "$CORE" "$tmp"
36
+ status=$?
37
+ rm -f "$tmp"
38
+ exit "$status"
@@ -0,0 +1,99 @@
1
+ #!/bin/bash
2
+ # Deny process metadata in project-owned implementation files.
3
+ # SC trace IDs, framework rules, and framework names belong in devos/ artifacts.
4
+ # Project source, tests, comments, fixtures, and strings use project language only.
5
+ #
6
+ # Usage:
7
+ # check-implementation-boundary.sh --file <path> --old <old-file> --new <new-file>
8
+ # check-implementation-boundary.sh --write --file <path> --old <old-file> --new <new-file>
9
+ # check-implementation-boundary.sh --scan --file <path>
10
+ #
11
+ # Exit 0 = allow or an internal error, 2 = project output contains internal metadata.
12
+ set -u
13
+
14
+ file=""
15
+ old=""
16
+ new=""
17
+ scan=0
18
+ write=0
19
+ while [[ $# -gt 0 ]]; do
20
+ case "$1" in
21
+ --file) [[ $# -ge 2 ]] || exit 0; file="$2"; shift 2 ;;
22
+ --old) [[ $# -ge 2 ]] || exit 0; old="$2"; shift 2 ;;
23
+ --new) [[ $# -ge 2 ]] || exit 0; new="$2"; shift 2 ;;
24
+ --scan) scan=1; shift ;;
25
+ --write) write=1; shift ;;
26
+ *) shift ;;
27
+ esac
28
+ done
29
+
30
+ # A malformed hook payload must not brick an edit.
31
+ [[ -n "$file" ]] || exit 0
32
+
33
+ is_internal_path() {
34
+ local path="$1" dir base rooted root
35
+ if [[ "$path" == /* ]]; then
36
+ dir=$(dirname "$path")
37
+ base=$(basename "$path")
38
+ else
39
+ dir="$PWD/$(dirname "$path")"
40
+ base=$(basename "$path")
41
+ fi
42
+ [[ -d "$dir" ]] || return 1
43
+ dir=$(cd "$dir" 2>/dev/null && pwd -P) || return 1
44
+ root=$(cd "$PWD" 2>/dev/null && pwd -P) || return 1
45
+ rooted="$dir/$base"
46
+ case "$rooted" in
47
+ "$root/devos/"*) return 0 ;;
48
+ "$root/plugins/devos/"*)
49
+ # The framework checkout is allowed to edit its own plugin source.
50
+ [[ -f "$PWD/plugins/devos/skills/build/SKILL.md" && -f "$PWD/devos/product/codebase-map.md" ]] && return 0
51
+ ;;
52
+ esac
53
+ return 1
54
+ }
55
+
56
+ is_code_path() {
57
+ local path="$1"
58
+ case "$path" in
59
+ *.js|*.jsx|*.mjs|*.cjs|*.ts|*.tsx|*.mts|*.cts|*.py|*.go|*.rs|*.java|*.kt|*.kts|*.swift|*.rb|*.php|*.cs|*.c|*.h|*.cc|*.cpp|*.hpp|*.scala|*.clj|*.ex|*.exs|*.erl|*.dart|*.lua|*.r|*.jl|*.sh|*.bash|*.zsh|*.fish|*.sql|*.html|*.css|*.scss|*.sass|*.less|*.vue|*.svelte|*.astro|*.graphql|*.gql|*.proto) return 0 ;;
60
+ src/*|*/src/*|lib/*|*/lib/*|app/*|*/app/*|packages/*|*/packages/*|components/*|*/components/*|server/*|*/server/*|client/*|*/client/*) return 0 ;;
61
+ test/*|*/test/*|tests/*|*/tests/*|__tests__/*|*/__tests__/*) return 0 ;;
62
+ esac
63
+ return 1
64
+ }
65
+
66
+ is_internal_path "$file" && exit 0
67
+ is_code_path "$file" || exit 0
68
+
69
+ if (( scan )); then
70
+ [[ -f "$file" ]] || exit 0
71
+ old_content=""
72
+ new_content=$(cat "$file" 2>/dev/null) || exit 0
73
+ else
74
+ [[ -f "$new" ]] || exit 0
75
+ old_content=""
76
+ if (( ! write )) && [[ -f "$old" ]]; then
77
+ old_content=$(cat "$old" 2>/dev/null)
78
+ fi
79
+ new_content=$(cat "$new" 2>/dev/null) || exit 0
80
+ fi
81
+
82
+ # A hyphen, space, or underscore joins the ID to a test name. The leading
83
+ # boundary keeps names such as disc3 out while still catching test_sc_3.
84
+ INTERNAL_RE='(^|[^[:alnum:]])SC[-_ ]?([0-9]+|X)([^[:alnum:]]|$)|devos'
85
+ hits=$(printf '%s\n' "$new_content" | grep -EIin "$INTERNAL_RE" 2>/dev/null || true)
86
+
87
+ while IFS= read -r hit; do
88
+ [[ -n "$hit" ]] || continue
89
+ lineno="${hit%%:*}"
90
+ line="${hit#*:}"
91
+ old_count=$(printf '%s\n' "$old_content" | grep -Fxc -- "$line" 2>/dev/null || true)
92
+ new_count=$(printf '%s\n' "$new_content" | grep -Fxc -- "$line" 2>/dev/null || true)
93
+ if (( new_count > old_count )); then
94
+ echo "Implementation output contains internal process metadata at $file:$lineno. Keep trace IDs and framework rules in devos artifacts." >&2
95
+ exit 2
96
+ fi
97
+ done <<<"$hits"
98
+
99
+ exit 0
@@ -0,0 +1,134 @@
1
+ #!/bin/bash
2
+ # check-port-source.sh: the tree a port reads is not the tree it writes.
3
+ #
4
+ # A port writes a new tree and leaves the tree it read alone, and the tree it
5
+ # read may be running in production. An edit to it is a deploy of code nobody
6
+ # reviewed, so the manifest's sources are off limits for the length of the
7
+ # port.
8
+ #
9
+ # The manifest is the contract: it names the source of every unit. The base
10
+ # is the commit that introduced the spec, because the spec is what the port
11
+ # reads, and everything after it is the port's own work. A spec that was never
12
+ # committed has no committed port work to compare against, so only the
13
+ # uncommitted changes are judged. A check that cannot say anything fails open:
14
+ # the hook's own trouble is never policy.
15
+ #
16
+ # Usage:
17
+ # check-port-source.sh --spec-dir DIR [--root DIR]
18
+ #
19
+ # Diagnostic envelope (shared by DevOS check scripts):
20
+ # FAIL <check>: <message>
21
+ # fix: <one actionable line>
22
+ # Exit 0 = nothing touched, 1 = a source path changed, 2 = usage.
23
+ set -u
24
+ SPEC_DIR=""
25
+ ROOT=""
26
+ while [[ $# -gt 0 ]]; do
27
+ case "$1" in
28
+ --spec-dir) SPEC_DIR="${2:-}"; shift 2 ;;
29
+ --root) ROOT="${2:-}"; shift 2 ;;
30
+ -h | --help) sed -n '2,22p' "$0"; exit 0 ;;
31
+ *) echo "FAIL check-port-source: unknown argument: $1" >&2; echo " fix: pass --spec-dir DIR" >&2; exit 2 ;;
32
+ esac
33
+ done
34
+ [[ -n "$SPEC_DIR" ]] || { echo "FAIL check-port-source: no spec dir given" >&2; echo " fix: pass --spec-dir DIR" >&2; exit 2; }
35
+
36
+ ROOT="${ROOT:-$(git rev-parse --show-toplevel 2>/dev/null || pwd)}"
37
+ [[ -d "$ROOT" ]] || exit 0
38
+ git -C "$ROOT" rev-parse --git-dir >/dev/null 2>&1 || exit 0
39
+ prefix=$(git -C "$ROOT" rev-parse --show-prefix 2>/dev/null || echo "")
40
+
41
+ # The spec dir is named relative to the caller, to the root, or absolutely, and
42
+ # a closed spec ends up under devos/specs/archive. Every path the check
43
+ # compares is repo-root relative, so the spec dir is converted to that first.
44
+ to_repo_path() {
45
+ local d="$1" abs
46
+ case "$d" in
47
+ /*) abs="$d" ;;
48
+ *) abs="$(cd "$d" 2>/dev/null && pwd)" || abs="" ;;
49
+ esac
50
+ [[ -n "$abs" && "$abs" == "$ROOT"/* ]] && { echo "${abs#"$ROOT"/}"; return; }
51
+ [[ -n "$abs" && "$abs" == "$ROOT" ]] && { echo "."; return; }
52
+ echo ""
53
+ }
54
+ spec_rel=$(to_repo_path "$SPEC_DIR")
55
+ if [[ -z "$spec_rel" || ! -d "$ROOT/$spec_rel" ]]; then
56
+ name=$(basename "$SPEC_DIR")
57
+ for c in "devos/specs/$name" "devos/specs/archive/$name"; do
58
+ [[ -d "$ROOT/$c" ]] && { spec_rel="$c"; break; }
59
+ done
60
+ fi
61
+ [[ -n "$spec_rel" && -d "$ROOT/$spec_rel" ]] || exit 0
62
+
63
+ manifest="$ROOT/$spec_rel/manifest.tsv"
64
+ [[ -f "$manifest" ]] || exit 0
65
+
66
+ sources=()
67
+ while IFS=$'\t' read -r src tgt; do
68
+ [[ "$src" == "source" ]] && continue
69
+ [[ -n "$src" ]] || continue
70
+ sources+=("${src%/}")
71
+ done <"$manifest"
72
+ [[ "${#sources[@]}" -gt 0 ]] || exit 0
73
+
74
+ # The protected set is the manifest's own paths plus the tree they share: a
75
+ # port that edits a legacy file the manifest never named is still editing the
76
+ # tree it reads. The shared prefix is only a tree when it is narrower than the
77
+ # repository, otherwise it names the whole checkout and protects everything.
78
+ protected=("${sources[@]}")
79
+ common_dir() {
80
+ local acc="$1" s="$2" a b
81
+ while :; do
82
+ a="${acc%/*}"
83
+ b="${s%/*}"
84
+ [[ "$a" == "$acc" && "$b" == "$s" ]] && break
85
+ acc="$a"
86
+ s="$b"
87
+ [[ -z "$acc" || -z "$s" ]] && { echo ""; return; }
88
+ done
89
+ echo "$acc"
90
+ }
91
+ prefix_dir="${sources[0]}"
92
+ for s in "${sources[@]}"; do
93
+ d=$(common_dir "$prefix_dir" "$s")
94
+ [[ -z "$d" ]] && { prefix_dir=""; break; }
95
+ prefix_dir="$d"
96
+ done
97
+ if [[ -n "$prefix_dir" && "$prefix_dir" != "." && "$prefix_dir" != "/" ]]; then
98
+ protected+=("$prefix_dir")
99
+ fi
100
+
101
+ # The base is the commit that introduced the spec. The manifest is what the
102
+ # port reads, and the spec file is what the port answers to, so whichever
103
+ # landed first is the state the port started from.
104
+ base=""
105
+ for rel in "manifest.tsv" "spec.md"; do
106
+ p="$spec_rel/$rel"
107
+ [[ -f "$ROOT/$p" ]] || continue
108
+ c=$(git -C "$ROOT" log --format=%H --diff-filter=A --follow -- "$p" 2>/dev/null | tail -1)
109
+ [[ -n "$c" ]] || continue
110
+ base="$c"
111
+ break
112
+ done
113
+ [[ -n "$base" ]] || exit 0
114
+
115
+ changed=$(git -C "$ROOT" diff --name-only "$base"..HEAD 2>/dev/null || true)
116
+ pending=$(git -C "$ROOT" status --porcelain 2>/dev/null | sed -E 's/^...//; s/.* -> //' || true)
117
+
118
+ hit=0
119
+ seen=" "
120
+ for file in $changed $pending; do
121
+ file="${file#./}"
122
+ [[ -n "$file" ]] || continue
123
+ case "$seen" in *" $file "*) continue ;; esac
124
+ for p in "${protected[@]}"; do
125
+ if [[ "$file" == "$p" || "$file" == "$p"/* ]]; then
126
+ seen="$seen$file "
127
+ echo "FAIL check-port-source: the port changed $file, and the tree it reads is not the tree it writes"
128
+ echo " fix: revert that change; the legacy tree keeps running while the port lands, and a port that edits it deploys code nobody reviewed"
129
+ hit=1
130
+ break
131
+ fi
132
+ done
133
+ done
134
+ exit $hit
@@ -0,0 +1,148 @@
1
+ #!/bin/bash
2
+ # check-report-locations.sh: reflection pass over a verification report.
3
+ # Deterministic, zero model calls.
4
+ #
5
+ # A verification report cites positions (`path:line`). The verifier writes them
6
+ # from memory or from a diff hunk, and until this script nothing checked a
7
+ # citation against the tree: a line past the end of its file, or a path that
8
+ # never existed, reads exactly like a real one. This re-derives every citation
9
+ # and reports the ones that do not survive contact, instead of trusting the
10
+ # report's account of where the problem is.
11
+ #
12
+ # Usage: check-report-locations.sh <spec-dir | verification.md> [--root DIR]
13
+ # <spec-dir> resolves to <spec-dir>/verifications/verification.md
14
+ # Exit 0 = every citation resolves, 1 = findings, 2 = usage/missing report.
15
+ set -u
16
+
17
+ target="${1:-}"
18
+ shift || true
19
+ root=""
20
+ while [[ $# -gt 0 ]]; do
21
+ case "$1" in
22
+ --root) root="${2:-}"; shift 2 ;;
23
+ *) shift ;;
24
+ esac
25
+ done
26
+
27
+ if [[ -z "$target" ]]; then
28
+ echo "usage: check-report-locations.sh <spec-dir | verification.md> [--root DIR]" >&2
29
+ exit 2
30
+ fi
31
+
32
+ report=""
33
+ if [[ -d "$target" ]]; then
34
+ report="$target/verifications/verification.md"
35
+ elif [[ -f "$target" ]]; then
36
+ report="$target"
37
+ else
38
+ echo "FAIL check-report-locations: no report at '$target'" >&2
39
+ echo " fix: pass a spec folder (devos/specs/<name>) or a verification.md" >&2
40
+ exit 2
41
+ fi
42
+ if [[ ! -f "$report" ]]; then
43
+ echo "FAIL check-report-locations: $report does not exist" >&2
44
+ echo " fix: run the verifier before citing its report" >&2
45
+ exit 2
46
+ fi
47
+
48
+ # The project root is the ancestor holding devos/. Resolving it here keeps the
49
+ # call cwd-independent: a hook, the suite, and a human all pass the same
50
+ # relative report path and get the same answer.
51
+ if [[ -z "$root" ]]; then
52
+ d="$(cd "$(dirname "$report")" && pwd)"
53
+ while [[ "$d" != "/" ]]; do
54
+ if [[ -d "$d/devos" ]]; then root="$d"; break; fi
55
+ d="$(dirname "$d")"
56
+ done
57
+ [[ -n "$root" ]] || root="$(pwd)"
58
+ fi
59
+ report_dir="$(cd "$(dirname "$report")" && pwd)"
60
+ spec_dir="$(dirname "$report_dir")"
61
+ root_real=$(cd "$root" 2>/dev/null && pwd -P) || root_real="$root"
62
+
63
+ # Strip URLs first: `https://host:8080/a.js:9` carries a colon-number that is not
64
+ # a citation. Left in, every link in a report would be reported as a bad path.
65
+ body="$(sed -E 's#https?://[^ )>]*##g' "$report")"
66
+
67
+ refs="$(grep -oE '(\.[A-Za-z0-9_-]+|[A-Za-z0-9_./-][A-Za-z0-9_./-]*\.[A-Za-z0-9]+):[0-9]+(-[0-9]+)?' <<<"$body" | sort -u)"
68
+ [[ -z "$refs" ]] && { echo "PASS check-report-locations: $report cites no positions"; exit 0; }
69
+
70
+ fail=0
71
+ finding() { echo "FAIL check-report-locations: $1"; echo " fix: $2"; fail=1; }
72
+
73
+ canonicalize_candidate() {
74
+ local candidate="$1" candidate_dir current link hops=0
75
+ candidate_dir=$(cd "$(dirname "$candidate")" 2>/dev/null && pwd -P) || return 1
76
+ current="$candidate_dir/$(basename "$candidate")"
77
+ while [[ -L "$current" ]]; do
78
+ ((hops++))
79
+ if ((hops > 40)); then
80
+ return 1
81
+ fi
82
+ link=$(readlink "$current") || return 1
83
+ if [[ "$link" = /* ]]; then
84
+ current="$link"
85
+ else
86
+ current="$(dirname "$current")/$link"
87
+ fi
88
+ candidate_dir=$(cd "$(dirname "$current")" 2>/dev/null && pwd -P) || return 1
89
+ current="$candidate_dir/$(basename "$current")"
90
+ done
91
+ printf '%s\n' "$current"
92
+ }
93
+
94
+ while IFS= read -r ref; do
95
+ [[ -n "$ref" ]] || continue
96
+ path="${ref%%:*}"
97
+ rng="${ref#*:}"
98
+ start="${rng%%-*}"
99
+ end="${rng##*-}"
100
+ if [[ "$start" -lt 1 ]]; then
101
+ finding "$report cites $ref but source line numbers start at 1" \
102
+ "re-derive the citation from the first line of the file"
103
+ continue
104
+ fi
105
+ if [[ "$end" -lt "$start" ]]; then
106
+ finding "$report cites $ref but its range end $end is before start $start" \
107
+ "use an in-order range such as $start-$start or a later end line"
108
+ continue
109
+ fi
110
+
111
+ f=""
112
+ escaped=0
113
+ for base in "$root" "$spec_dir" "$report_dir"; do
114
+ candidate="$base/$path"
115
+ candidate_real=$(canonicalize_candidate "$candidate") || continue
116
+ case "$candidate_real" in
117
+ "$root_real"/*) ;;
118
+ *) escaped=1; continue ;;
119
+ esac
120
+ if [[ -f "$candidate_real" ]]; then f="$candidate_real"; break; fi
121
+ done
122
+ if [[ -z "$f" && "$escaped" -eq 1 ]]; then
123
+ finding "$report cites $ref but the path resolves outside the project root" \
124
+ "cite a file contained by $root, or drop the citation"
125
+ continue
126
+ fi
127
+ if [[ -z "$f" ]]; then
128
+ finding "$report cites $ref but no such file exists under $root" \
129
+ "point the finding at a real path, or drop the citation"
130
+ continue
131
+ fi
132
+
133
+ total=$(awk 'END{print NR+0}' "$f")
134
+ if (( start > total )); then
135
+ finding "$report cites $ref but ${path} has only $total lines" \
136
+ "re-derive the line from the current file; the citation drifted"
137
+ continue
138
+ fi
139
+ if (( end > total )); then
140
+ finding "$report cites $ref but ${path} has only $total lines" \
141
+ "re-derive the range from the current file; the citation drifted"
142
+ fi
143
+ done <<<"$refs"
144
+
145
+ if (( fail == 0 )); then
146
+ echo "PASS check-report-locations: every citation in $report resolves"
147
+ fi
148
+ exit $fail
@@ -0,0 +1,104 @@
1
+ #!/bin/bash
2
+ # check-scenario-coverage.sh: every scenario the functional spec declares is
3
+ # recorded in the verification report.
4
+ # Deterministic, zero model calls.
5
+ #
6
+ # The verifier is told to read the `SC-n` IDs from spec.md and record
7
+ # each one in verifications/verification.md, and until this script nothing
8
+ # checked that it did. An omission is the one failure a clean-looking report
9
+ # cannot show: every row it carries resolves, the verdict reads CLEAN + PASS,
10
+ # and the scenario nobody executed leaves no trace. This is the omission twin of
11
+ # check-report-locations.sh, which catches a row that points nowhere. The same
12
+ # IDs are checked one hop earlier by validate-spec.sh, the contract to
13
+ # the plan; this is the hop from the spec to the report.
14
+ #
15
+ # Presence, not format: a report may record an ID in the criteria table, in a
16
+ # scenario mapping line, or beside the test that proves it. Pinning one layout
17
+ # would reject honest reports for their shape and teach the verifier to write
18
+ # for the gate instead of for the engineer.
19
+ #
20
+ # Usage: check-scenario-coverage.sh <spec-dir | verification.md>
21
+ # Exit 0 = every declared SC-n is recorded (or nothing is declared),
22
+ # 1 = an ID is missing, or the report cites one the spec never declared,
23
+ # 2 = usage or missing report.
24
+ set -u
25
+
26
+ target="${1:-}"
27
+ if [[ -z "$target" ]]; then
28
+ echo "usage: check-scenario-coverage.sh <spec-dir | verification.md>" >&2
29
+ exit 2
30
+ fi
31
+
32
+ report=""
33
+ if [[ -d "$target" ]]; then
34
+ spec="$target"
35
+ report="$spec/verifications/verification.md"
36
+ elif [[ -f "$target" ]]; then
37
+ report="$target"
38
+ spec="$(dirname "$(dirname "$report")")"
39
+ else
40
+ echo "FAIL check-scenario-coverage: no spec or report at '$target'" >&2
41
+ echo " fix: pass a spec folder (devos/specs/<name>) or its verifications/verification.md" >&2
42
+ exit 2
43
+ fi
44
+ if [[ ! -f "$report" ]]; then
45
+ echo "FAIL check-scenario-coverage: $report does not exist" >&2
46
+ echo " fix: run the verifier before checking its report" >&2
47
+ exit 2
48
+ fi
49
+
50
+ sf=$(mktemp)
51
+ trap 'rm -f "$sf"' EXIT
52
+ if ! bash "$(dirname "${BASH_SOURCE[0]}")/spec-contract.sh" "$spec" >"$sf"; then
53
+ echo "PASS check-scenario-coverage: $spec declares no functional spec"
54
+ exit 0
55
+ fi
56
+ sfname=spec.md
57
+
58
+ # A C-route spec says what must not change, so it declares no scenarios and has
59
+ # no IDs to trace. Same heading normalization and exact match as validate-spec.sh,
60
+ # so a feature spec with a "Business invariants" section keeps every check it
61
+ # needs.
62
+ inv=$(awk '/^#+ /{
63
+ h = tolower($0); sub(/^#+[ \t]*/, "", h); sub(/^[0-9]+[.)]?[ \t]*/, "", h)
64
+ sub(/[ \t]+$/, "", h); inv = (h == "invariant"); next
65
+ } inv' "$sf")
66
+ if [[ -n "$inv" ]]; then
67
+ echo "PASS check-scenario-coverage: $(basename "$spec") is an invariant spec, no scenarios declared"
68
+ exit 0
69
+ fi
70
+
71
+ declared=$(grep -E 'Scenario SC-[0-9]+:' "$sf" | grep -oE 'SC-[0-9]+' | sort -u)
72
+ if [[ -z "$declared" ]]; then
73
+ echo "PASS check-scenario-coverage: $spec/$sfname declares no numbered scenarios"
74
+ exit 0
75
+ fi
76
+ recorded=$(grep -oE 'SC-[0-9]+' "$report" | sort -u)
77
+
78
+ missing=""
79
+ while IFS= read -r id; do
80
+ [[ -n "$id" ]] || continue
81
+ grep -qxF "$id" <<<"$recorded" || missing="${missing}${id} "
82
+ done <<<"$declared"
83
+
84
+ extra=""
85
+ while IFS= read -r id; do
86
+ [[ -n "$id" ]] || continue
87
+ grep -qxF "$id" <<<"$declared" || extra="${extra}${id} "
88
+ done <<<"$recorded"
89
+
90
+ fail=0
91
+ if [[ -n "$missing" ]]; then
92
+ echo "FAIL check-scenario-coverage: $report does not record ${missing% }"
93
+ echo " fix: record each one in this report with what shows it: the test name and file:line, AWAITING HUMAN, or UNVERIFIED. The ID stays in the report, never in the test source. A scenario recorded nowhere was not verified."
94
+ fail=1
95
+ fi
96
+ if [[ -n "$extra" ]]; then
97
+ echo "FAIL check-scenario-coverage: $report cites ${extra% }, which $spec/$sfname never declares"
98
+ echo " fix: cite the IDs the functional spec declares, or drop the stale row and re-run the verifier if the spec changed"
99
+ fail=1
100
+ fi
101
+ if ((fail == 0)); then
102
+ echo "PASS check-scenario-coverage: $report records every scenario $spec/$sfname declares"
103
+ fi
104
+ exit $fail