feat(cli): add ctxguard doctor command - #4
Merged
Conversation
Verifies the local install end to end: ctxguard resolves on PATH (what the hooks registered by `ctxguard init` actually invoke at runtime), the resolved binary's version matches what's running the check, .claude/settings.json has both PreToolUse and SessionStart hooks registered with the expected matcher, .ctxguard.toml parses if present, and a real invocation of the PreToolUse hook succeeds end to end. Each check reports ok/warn/fail; only fail affects the exit code (1), so e.g. a missing .ctxguard.toml (defaults apply) or a narrower-than- expected matcher don't block CI while still surfacing as visible warnings. --json for scripting, matching scan's convention.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ctxguard doctor [path] [--json], a follow-up to thectxguard initflow that verifies the local install actually works end to end:ctxguardresolves onPATH(what the hooks registered byctxguard initinvoke at runtime, as opposed to plugin-mode hooks which callpython3directly).claude/settings.jsonhas bothPreToolUseandSessionStarthooks registered, with the expected matcher.ctxguard.tomlparses cleanly if presentPreToolUsehook succeeds (not just static checks)ok/warn/fail; onlyfailaffects the exit code, so e.g. a missing.ctxguard.toml(defaults apply) or a narrower-than-expected matcher surface as visible warnings without blocking CI.pip installinto an unactivated venv silently leaves the hooks unresolvable, since ctxguard fails open by design and won't say anything).Test plan
pytest: 192 passed (10 new tests: nothing-set-up, fully-healthy end-to-end via the real installed binary, narrow-matcher warning, malformed-TOML failure, missing-dir exit code, rich report rendering)ctxguard scan .) returns findings only undertests/fixtures/ruff checkclean on changed files--jsonoutput