Revision: 9 Last modified: 2026-12-04T14:03:58Z
Source: constitution/scripts/codegraph/codegraph_guard.sh (159 lines).
Every statement below cites codegraph_guard.sh:<line>.
Mechanical gate CM-CODEGRAPH-SAFE-INDEX-PATH (line 3). It scans tracked
scripts, hooks and documentation commands for two patterns that bypass the
single safe writer entry codegraph_safe.sh (lines 5-8):
direct-stock-init-index— a direct stockcodegraph initorcodegraph index, including thenpx [-y] @colbymchenry/codegraph indexform and a quoted python argv-list form ("codegraph", "index") (regexCMD, line 50).masked-codegraph-failure— acodegraph <subcommand>line that also contains|| trueor|| :(regexesMASK_CMD+MASK, lines 51-52).
Both patterns were at the root of the 2026-09-23 bulk-window incident: a legacy one-liner reached the bulk-window FK-cascade hazard and masked every failure (lines 9-10).
The scanner is read-only; it never runs codegraph itself.
bash,python3(stdlib only) (lines 25, 47).- For
--self-test: a writable$TMPDIR(default/tmp) andcodegraph_safe.shin the same directory (lines 119, 124).
# Default roots: this constitution's scripts/ dir, plus the consuming
# project's scripts/ dir when the constitution is its submodule
codegraph_guard.sh
# Explicit roots (repeatable)
codegraph_guard.sh --root <project_root>/scripts --root <project_root>/hooks
# Built-in golden-true / golden-false fixture check
codegraph_guard.sh --self-test
# Help (prints the header, lines 2-32)
codegraph_guard.sh --help| Flag | Meaning |
|---|---|
--root DIR |
Add a scan root; repeatable. Missing value → exit 2 (line 38). A root that is not a directory → exit 2 (line 158). |
--self-test |
Run the fixture self-test instead of a scan (lines 117-150). |
-h, --help |
Print header lines 2-32 and exit 0 (line 42). |
Any other argument → unknown argument, exit 2 (line 43).
When no --root is given: $HERE/.. (the constitution scripts/ dir). If
the directory three levels up contains both scripts/ and constitution/,
its scripts/ is added as a second root.
One line per offender: <relpath>:<line>: <rule>: <text> (text truncated to
160 characters, lines 101-104), then a summary:
GUARD PASS files=<n> offenders=0orGUARD FAIL files=<n> offenders=<n>(line 113);- or
GUARD BLIND no candidate files under: <roots>(line 110).
| Code | Meaning | Source |
|---|---|---|
| 0 | Clean scan; --help; --self-test all PASS |
lines 42, 114, 148 |
| 1 | Offenders found; --self-test had a failure |
lines 114, 149 |
| 2 | Usage error, root not a directory, or BLIND (0 candidate files under a root) | lines 38, 43, 111, 158 |
BLIND is deliberately exit 2: an empty scan proves nothing (header line 24).
- Extensions:
.sh .bash .py .js .mjs .ts .yml .yaml .md(line 53), plus extension-less files whose first two bytes are#!(lines 67-73). - Skipped directories:
.git node_modules .codegraph __pycache__ .compressed out(line 54). Symlinks and non-regular files are skipped (lines 62-63). - Markdown: only lines inside ``` fences are scanned; prose is not a command (lines 91-96).
- Other files: full-line comments starting with
#or//are skipped as carriers (lines 97-98). - Exemption: a line containing
codegraph-guard: allow <reason>is skipped; the reason must be non-empty (regexALLOW, line 52; applied at line 99). A bare marker is not an exemption. - Unreadable files are skipped without counting as an offender (lines 86-87) but still count toward the file total (line 81).
- A trailing comment such as
cmd # codegraph index …on a code line is NOT skipped (only full-line comments are, line 97) — add anallowmarker with a reason if the line is legitimate. CMDtakes precedence: a line matching both rules reports onlydirect-stock-init-index(lines 101-104).- The lookbehind
(?<![A-Za-z0-9_.-])inCMD/MASK_CMD(lines 50-51) means names such ascodegraph_safe.sh indexormy-codegraph indexdo not match; the self-test assertscodegraph_safe.shitself is never flagged (lines 142-145). MASKonly matches|| true/|| :followed by a non-identifier character (line 52); other masking forms (; true,set +e) are not detected. UNCONFIRMED: whether any other masking idiom is used in the scanned trees.
Creates $TMPDIR/cg_guard_selftest/run.XXXXXX with scripts/ + docs/,
copies codegraph_safe.sh in, then checks four cases:
- golden-false-with-carrier: a comment and a prose mention → exit 0;
- golden-true: planted
codegraph index→ exit 1 and reported atscripts/planted.sh:3; - golden-true: planted
(codegraph sync . || true)→ reported atscripts/mask.sh:2; - the copied launcher is not flagged.
The run directory is removed afterwards (line 147); the parent
cg_guard_selftest directory is left in place.
| Guide | Relation |
|---|---|
| codegraph_safe | The only permitted writer entry this gate protects |
| codegraph_safe_helper | Helper used by the writer entry |
| disk_tripwire | Free-space watcher started by the writer entry |
| index_watch | Progress-proven watchdog |
| fk_index_patch | Runner patcher |
| fk_cascade_probe | Bulk-window hazard probe |
| codegraph_runner_patches | Version-keyed runner patches |
| codegraph_scope_guard | Scope proof |
| scope_render | Scope generator |
| codegraph_mcp_probe | MCP reachability probe |
| lumen_verify | Semantic-index health check |
| gen_lumenignore | Semantic-index scope generator |
| codegraph_lumen_overview | Overview |
Tests: scripts/codegraph/tests/test_guard.sh exists (header line 26).
UNCONFIRMED: its content was not read for this guide.
2026-09-24 — read codegraph_guard.sh lines 1-159 in full; bash -n codegraph_guard.sh passed. The script (including --self-test) was NOT
executed for this guide.