Files
boshu2__agentops/scripts/validate-sovereignty-proof-citations.sh
T
Bo 81fe2d5ae8 feat(docs): sovereignty-proof page — F6/F7 + RPI-leanness case studies (soc-vuu6.32 #sovereignty-proof) (#386)
## Summary

New \`docs/sovereignty-proof/\` surface with two committed case studies
showing where independent-vendor review caught what same-vendor review
missed:

- **2026-05-15 RPI-leanness council** — Codex (gpt-5.5) independently
reframed "RPI is waterfall" to "plan.md is an artifact-boundary bug",
turning a multi-week methodology rewrite into a single-port surgical
change (PR #275 was already in-flight implementing this).
- **2026-05-16 CDLC research council** — Two Codex judges independently
flagged the F6 session-misjoin bug in
\`cli/cmd/ao/flywheel_citation_feedback.go\` and the F7
\`hooks/citation-tracker.sh\` wiring gap. No Claude judge surfaced
either.

## Why

Council non-negotiable #2
(.agents/council/2026-05-18-validate-agentops-3.0-doctrine.md).
Mixed-model capability must be visible as load-bearing proof of the
sovereignty thesis, not buried as opt-in obscurity. The page is what
makes the sovereignty claim falsifiable + linkable from the README hero
(unblocks soc-vuu6.30).

## Mechanical guarantees

- \`scripts/validate-sovereignty-proof-citations.sh\` scans every
\`.md\` under \`docs/sovereignty-proof/\` for \`file:line\` citations
(\`path/to/file:NN\` or \`path/to/file:NN-MM\`) and verifies each
resolves at HEAD. Currently 16 citations across 3 pages.
- New CI job \`validate-sovereignty-proof-citations\` (required) wires
the script into \`validate.yml\` with broad triggers so any
referenced-surface change re-runs the gate. Added to merge-gate
\`needs:\` arrays + summary echo.
- 8-case bats regression suite at
\`tests/scripts/validate-sovereignty-proof-citations.bats\` (pass /
file-missing / line-overflow / fenced-code-block / backtick / multi-page
/ no-dir / no-markdown).
- mkdocs nav entry under Concepts → Sovereignty Proof.
- \`docs/documentation-index.md\` Concepts entry.

## Acceptance (BDD)

Given a visitor wants to verify the sovereignty claim is real, When they
click "Sovereignty proof" from README hero (slice 1, blocked on this),
Then they land on \`docs/sovereignty-proof/index.md\` showing real
\`/council --mixed\` output from the 2026-05-15 reframe AND 2026-05-16
F6+F7 findings with \`file:line\` citations and verdict file links.

## Verification

\`\`\`bash
bash scripts/validate-sovereignty-proof-citations.sh
# validate-sovereignty-proof-citations: scanned 3 pages, 16 citations
# PASS — all citations resolve.

bats tests/scripts/validate-sovereignty-proof-citations.bats
# 1..8 (all pass)
\`\`\`

Closes-scenario: soc-vuu6.32#sovereignty-proof
Bounded-context: BC1-Corpus
Evidence: docs/sovereignty-proof/index.md
Evidence: scripts/validate-sovereignty-proof-citations.sh
Evidence: tests/scripts/validate-sovereignty-proof-citations.bats
Evidence: .github/workflows/validate.yml
2026-05-21 00:48:38 +00:00

128 lines
3.5 KiB
Bash
Executable File

#!/usr/bin/env bash
# validate-sovereignty-proof-citations.sh
#
# Scans docs/sovereignty-proof/ for file:line citations and verifies each
# resolves at HEAD: the file exists, and the cited line number is within
# the file's line count.
#
# Why: docs/sovereignty-proof/index.md is the falsifiable artifact behind
# the sovereignty claim. A proof page that lies about its citations is
# worse than no proof page at all. This gate is mechanical enforcement.
#
# Citation forms recognized:
# path/to/file:NN — single line
# path/to/file:NN-MM — line range (validates NN and MM)
#
# Citations are matched anywhere in the page text (markdown bullets,
# tables, prose). Paths are resolved relative to the repo root.
#
# Exit codes:
# 0 — all citations resolve
# 1 — one or more citations fail to resolve
# 2 — usage / setup error
#
# Sibling pattern: matches the shape of scripts/check-registry-drift.sh
# (simple POSIX bash, repo-root cd, summary + exit code).
#
# soc-vuu6.32
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
cd "$ROOT"
TARGET_DIR="docs/sovereignty-proof"
if [ ! -d "$TARGET_DIR" ]; then
echo "ERROR: $TARGET_DIR does not exist" >&2
exit 2
fi
declare -i checked=0
declare -i failed=0
failures=()
# Find all .md files under docs/sovereignty-proof/
mapfile -t pages < <(find "$TARGET_DIR" -type f -name "*.md" | sort)
if [ ${#pages[@]} -eq 0 ]; then
echo "ERROR: no .md files under $TARGET_DIR" >&2
exit 2
fi
# Citation regex:
# - Captures: file path (no spaces), colon, line number (or NN-MM)
# - File path must contain at least one slash to avoid matching e.g. "x:1"
# - Excludes URLs (http: / https:) by requiring no protocol prefix
# - Excludes citations inside fenced code blocks (handled via awk below)
#
# We use awk to strip fenced code blocks first, then grep for citations.
#
# Recognized:
# foo/bar.go:42
# foo/bar.md:10-25
# `foo/bar.sh:5` (backtick wrappers OK; we strip via -o)
extract_citations() {
local page="$1"
awk '
/^```/ { in_block = !in_block; next }
!in_block { print }
' "$page" | grep -oE '[a-zA-Z0-9_./-]+\.(go|sh|md|json|yml|yaml|ts|js|py|rs|sql|hujson|toml)[`]?:[0-9]+(-[0-9]+)?' | sed 's/`//g'
}
for page in "${pages[@]}"; do
while IFS= read -r citation; do
[ -z "$citation" ] && continue
checked=$((checked + 1))
# Split file:lines
file="${citation%:*}"
lines="${citation##*:}"
# Resolve line endpoints (single or range)
if [[ "$lines" == *-* ]]; then
start="${lines%-*}"
end="${lines#*-}"
else
start="$lines"
end="$lines"
fi
# File must exist relative to repo root
if [ ! -f "$file" ]; then
failed=$((failed + 1))
failures+=("$page → $citation : file does not exist")
continue
fi
# Line count must be >= cited end line
total_lines=$(wc -l < "$file")
if [ "$end" -gt "$total_lines" ]; then
failed=$((failed + 1))
failures+=("$page → $citation : cited line $end exceeds file's $total_lines lines")
continue
fi
if [ "$start" -lt 1 ]; then
failed=$((failed + 1))
failures+=("$page → $citation : cited line $start < 1")
continue
fi
done < <(extract_citations "$page")
done
echo "validate-sovereignty-proof-citations: scanned ${#pages[@]} pages, $checked citations"
if [ "$failed" -eq 0 ]; then
echo "PASS — all citations resolve."
exit 0
fi
echo "FAIL — $failed unresolved citation(s):" >&2
for f in "${failures[@]}"; do
echo " - $f" >&2
done
exit 1