Repository navigation
Hooks: whole-space baseline at prompt submit, compared at Stop (#124, #127) - #126
Conversation
The Stop hook kept the latest pre-edit entry per file, so a second edit to the same file took a baseline that already contained errors the first edit introduced, and they went unreported. It now keeps the earliest entry, and the pre-edit hook skips files it has already recorded, which avoids a full-space validation on every repeat edit. A Write over an existing file was recorded with no baseline, so all of the file's existing issues were reported as new. It now records a baseline like an Edit. Claude-Session: https://claude.ai/code/session_01EJgagmpxDYVYr7fp9C6cZi
The UserPromptSubmit hook baselines every space inside or containing the session directory; the Stop hook validates changed spaces and reports issues missing from the baseline in any file, so breakage in files that weren't edited and edits made through Bash are caught. The pre-edit hook remains as a fallback for spaces outside the session directory. Baselines store issue keys only. A hash of each space's markdown, schema and config file stats skips validation when nothing changed, and the last Stop's keys are reused at the next prompt. A baseline that survives an interrupted turn is kept. The hooks use `sctx validate --json` and the new `sctx spaces --json`. The CLI now routes console.log through process.stdout.write: once node:process is loaded, Bun dropped piped output past 64KB for slow readers. Claude-Session: https://claude.ai/code/session_01EJgagmpxDYVYr7fp9C6cZi
The Agent SDK loads ~/.claude settings and CLAUDE.md when settingSources is omitted. Claude-Session: https://claude.ai/code/session_01EJgagmpxDYVYr7fp9C6cZi
On Linux the fixture space lives directly under tmpdir(), so it counted as related and a baseline was written. Use a fresh sibling directory instead. Claude-Session: https://claude.ai/code/session_01EJgagmpxDYVYr7fp9C6cZi
Code review1 issue found (CLAUDE.md documentation compliance):
No bugs found in the diff. |
Two rows still described the old per-file save-time validation hook; align with the whole-space baseline/compare design already reflected elsewhere in the file. Claude-Session: https://claude.ai/code/session_01Vu78JfVBQXdqVtBZUPdu2E
# Conflicts: # plugin/.claude-plugin/plugin.json
Closes #124. Closes #127.
Failing tests and CI (#124)
These were already fixed on
mainshortly after the issue was filed:bun run test:hookto CI (test.yml) and to pre-push (check-pushed-tree.sh).Whole-space baseline at prompt submit (#127)
The hooks used to validate per file: one full-space read per edited file before the edit and again at Stop, reporting only issues in the edited file. The first commit fixed two baseline bugs in that design (a second edit hid the first edit's errors;
Writeover an existing file reported every existing issue as new). The second commit replaces it:on-prompt.ts): baselines every space inside or containing the session directory. Whencwdis the vault, that's every space in it.on-stop.ts): validates each space that changed since its baseline and reports issues missing from the baseline, in any file of the space. That catches breakage in files that weren't edited (e.g. renaming a note breaks another file's parent link) and edits made through Bash. Errors block and warnings go toadditionalContext, as before. Info-level rule violations are still ignored.pre-edit.ts): now a fallback for spaces outside the session directory. The first edit to such a space in a turn baselines the whole space.on-session-end.ts): removes the session's state file.Details:
.mdfiles, schema-directory files and config files. Stop skips spaces whose hash matches their baseline, and the next prompt reuses the last Stop's keys when the hash still matches.sctx validate <space> --jsonand a newsctx spaces --json(config files, and each space's path and schema). There's no new validation command.Measured with the eight spaces under the vault:
The state file is 60KB, almost all of it unresolved content-link keys (628 of 635 issues). #128 covers letting links outside a space validate without warnings.
CLI: piped output past 64KB
validate --jsonfor a large space was cut off at 65,536 bytes when the reader was slow, which would have broken the hooks.node:processis imported (here throughunified→vfile), Bun'sconsole.logdrops piped output past 64KB. A bare script printing the same output doesn't lose any, andprocess.stdout.writedelivers all of it.src/index.tsnow routesconsole.logthroughprocess.stdout.write, andvalidate/validate-filesetprocess.exitCodeinstead of callingprocess.exit().Tests
bun run test461, lint and typecheck all pass.https://claude.ai/code/session_01EJgagmpxDYVYr7fp9C6cZi