Repository navigation
sctx-dev: contributor plugin with doc-review, test-review and the review check #242
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7251c6c
feat(dev-plugin): sctx-dev contributor plugin with doc-review, test-r…
mindsocket b17b31c
feat(dev-plugin): check the repo holding the hook's cwd, on Stop and …
mindsocket 09f20a2
docs(dev-plugin): architecture says what the contributor plugin is fo…
mindsocket 0d88ea1
feat(dev-plugin): doc-review reads whole passages and what they descr…
mindsocket File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,10 @@ | |
| { | ||
| "name": "structured-context", | ||
| "source": "./plugin" | ||
| }, | ||
| { | ||
| "name": "sctx-dev", | ||
| "source": "./dev-plugin" | ||
| } | ||
| ] | ||
| } | ||
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| # Generated files: collapsed in GitHub diffs and left out of the sctx-dev review check. | ||
| plugin/hooks/projection.js linguist-generated | ||
| plugin/types/index.d.ts linguist-generated | ||
| schemas/generated/** linguist-generated | ||
| bun.lock linguist-generated |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "name": "sctx-dev", | ||
| "description": "For contributors to structured-context repositories: doc-review and test-review skills, and Stop and SubagentStop hooks that block while a branch adds prose or tests no review has seen.", | ||
| "homepage": "https://github.com/mindsocket/structured-context", | ||
| "repository": "https://github.com/mindsocket/structured-context", | ||
| "license": "MIT" | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| { | ||
| "hooks": { | ||
| "Stop": [ | ||
| { | ||
| "hooks": [ | ||
| { | ||
| "type": "command", | ||
| "command": "bash \"${CLAUDE_PLUGIN_ROOT}/scripts/on-stop.sh\"", | ||
| "timeout": 120 | ||
| } | ||
| ] | ||
| } | ||
| ], | ||
| "SubagentStop": [ | ||
| { | ||
| "hooks": [ | ||
| { | ||
| "type": "command", | ||
| "command": "bash \"${CLAUDE_PLUGIN_ROOT}/scripts/on-stop.sh\"", | ||
| "timeout": 120 | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| #!/usr/bin/env bash | ||
| # Runs the review check for the repo holding the hook's cwd: the session's checkout, or a | ||
| # subagent's own worktree on SubagentStop. Where cwd is a folder above several checkouts, | ||
| # each git checkout directly under it gets the check. | ||
| set -uo pipefail | ||
|
|
||
| check="$(dirname "$0")/review-check.sh" | ||
|
|
||
| # Without jq the hook stays in the directory Claude Code ran it from. | ||
| cwd="$(jq -r '.cwd // empty' 2>/dev/null)" | ||
| [ -n "$cwd" ] && cd "$cwd" 2>/dev/null | ||
|
|
||
| if git rev-parse --is-inside-work-tree >/dev/null 2>&1; then | ||
| exec bash "$check" | ||
| fi | ||
|
|
||
| status=0 | ||
| for dir in */; do | ||
| [ -e "$dir.git" ] || continue | ||
| (cd "$dir" && bash "$check") | ||
| [ $? -eq 2 ] && status=2 | ||
| done | ||
| exit "$status" |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| #!/usr/bin/env bash | ||
| # Exits 2 while the branch adds prose (docs and code comments) or tests that no review | ||
| # has seen. A kind argument (prose or tests) checks that kind only. --mark <kind> | ||
| # records the current additions of that kind as reviewed. | ||
| # | ||
| # Paths with the linguist-generated attribute in .gitattributes are left out. | ||
| set -uo pipefail | ||
|
|
||
| script="$(cd "$(dirname "$0")" && pwd)/$(basename "$0")" | ||
|
|
||
| mark= | ||
| if [ "${1:-}" = "--mark" ]; then | ||
| mark=1 | ||
| shift | ||
| if [ $# -ne 1 ]; then | ||
| echo "usage: $script --mark prose|tests" >&2 | ||
| exit 1 | ||
| fi | ||
| fi | ||
| kinds="${*:-prose tests}" | ||
| for kind in $kinds; do | ||
| case "$kind" in | ||
| prose | tests) ;; | ||
| *) | ||
| echo "unknown kind: $kind (expected prose or tests)" >&2 | ||
| exit 1 | ||
| ;; | ||
| esac | ||
| done | ||
|
|
||
| root="$(git rev-parse --show-toplevel 2>/dev/null)" || exit 0 | ||
| cd "$root" || exit 0 | ||
|
|
||
| # A slow or unreachable remote must not hold up a hook, so the fetch gets 10 seconds. | ||
| git fetch --quiet origin main >/dev/null 2>&1 & | ||
| fetch=$! | ||
| (sleep 10 && kill "$fetch") >/dev/null 2>&1 & | ||
| watch=$! | ||
| wait "$fetch" 2>/dev/null | ||
| kill "$watch" 2>/dev/null | ||
|
|
||
| base="$(git merge-base origin/main HEAD 2>/dev/null)" || exit 0 | ||
|
|
||
| # Prints "file<TAB>label<TAB>line" for each added line of the kind, untracked files included. | ||
| added() { | ||
| local specs | ||
| case "$1" in | ||
| prose) specs=('*.md' '*.ts' '*.tsx' '*.js' '*.mjs' '*.cjs' '*.sh' '*.yml' '*.yaml' '*.json5' '*.jsonc') ;; | ||
| tests) specs=('*.test.*' '*.spec.*') ;; | ||
| esac | ||
| specs+=(':(exclude,attr:linguist-generated)') | ||
| { | ||
| git diff -U0 --no-color "$base" -- "${specs[@]}" | ||
| git ls-files -z --others --exclude-standard -- "${specs[@]}" | | ||
| xargs -0 -r -n1 git diff -U0 --no-color --no-index /dev/null | ||
| } | awk -v kind="$1" ' | ||
| /^\+\+\+ b\// { file = substr($0, 7); doc = file ~ /\.md$/; next } | ||
| /^\+/ { | ||
| line = substr($0, 2) | ||
| if (line !~ /[^[:space:]]/) next | ||
| if (kind == "tests") print file "\ttest\t" line | ||
| else if (doc) print file "\tdoc\t" line | ||
| else if (line ~ /^[[:space:]]*(\/\/|\/\*|\*|#)/ && line !~ /^#!/) print file "\tcomment\t" line | ||
| }' | ||
| } | ||
|
|
||
| status=0 | ||
| for kind in $kinds; do | ||
| lines="$(added "$kind")" | ||
| stamp="$(git rev-parse --git-path "$kind-reviewed")" | ||
| hash="$(printf '%s' "$lines" | git hash-object --stdin)" | ||
| if [ -n "$mark" ]; then | ||
| echo "$hash" >"$stamp" | ||
| continue | ||
| fi | ||
| [ -z "$lines" ] && continue | ||
| [ "$(cat "$stamp" 2>/dev/null)" = "$hash" ] && continue | ||
|
|
||
| case "$kind" in | ||
| prose) what="Prose" skill="doc-review" ;; | ||
| tests) what="Tests" skill="test-review" ;; | ||
| esac | ||
| { | ||
| echo "$what added in $root since the last $skill:" | ||
| printf '%s\n' "$lines" | awk -F'\t' '{ n[$1 " (" $2 ")"]++ } END { for (f in n) printf " %4d %s\n", n[f], f }' | sort -rn | ||
| echo "Run the $skill skill on this diff, apply its findings, then run $script --mark $kind." | ||
| } >&2 | ||
| status=2 | ||
| done | ||
| exit "$status" |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| --- | ||
| name: test-review | ||
| description: Review new or changed tests in a structured-context (sctx) repo for tests that duplicate others, re-test a schema, or assert what their own setup makes true, then fix what it finds. Use after adding or changing tests, before committing or opening a PR. | ||
| allowed-tools: Bash(${CLAUDE_PLUGIN_ROOT}/scripts/review-check.sh --mark tests) | ||
| --- | ||
|
|
||
| ## Task | ||
|
|
||
| Review the tests in the target named by `$ARGUMENTS`: a PR number, branch, commit, or list of files. With no | ||
| argument, use uncommitted changes, or if there are none, the branch against `main` (`git diff main...HEAD`). | ||
| Apply the test principles in the repo's `AGENTS.md`, then fix the findings. Read the code under test and the | ||
| neighbouring test files before judging a test: coverage is a property of the whole suite. | ||
|
|
||
| ## Checks | ||
|
|
||
| For every added or changed test, ask: | ||
|
|
||
| 1. **Does it prove something no other test does?** Search the suite for a test that already covers the | ||
| behaviour. Flag the newer or weaker one. | ||
| 2. **Does it re-test a JSON Schema?** A schema's own constraints (types, required keys, enums, patterns) are the | ||
| validator's job. Test only the checks the schema can't express. | ||
| 3. **Is it a second input down a covered code path?** One input per path. Flag cases, `each` rows or fixtures | ||
| that take a branch another case already takes. | ||
| 4. **Does it assert what its own setup makes true?** Flag assertions that hold because of the test's config, | ||
| fixture or mock, whatever the code under test does. | ||
| 5. **Are expected values derived?** Expected values come from the fixture or the code under test, not from a | ||
| copy of the output pasted in. | ||
| 6. **Will it grow with the code?** Flag hard-coded lists (layouts, exports, files, schema keys) that a new entry | ||
| elsewhere makes stale. | ||
| 7. **Does it assert the behaviour its name states?** Flag names that promise more or other than the assertions | ||
| check, and assertions on things that only happen to be true. | ||
|
|
||
| For the change as a whole: | ||
|
|
||
| 8. **Did it make a test redundant?** When a change moves or narrows behaviour, flag the tests it leaves proving | ||
| nothing new, including ones the diff doesn't touch. | ||
|
|
||
| ## Output | ||
|
|
||
| List findings as `file:line, check number, proposed change` (a rewrite, a merge into another test, or a deletion | ||
| naming the test that covers it), then apply them. Run the repo's test, typecheck and lint commands from | ||
| `AGENTS.md`. Finish with `${CLAUDE_PLUGIN_ROOT}/scripts/review-check.sh --mark tests`. |
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
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
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.