claude-dev-env 2.0.0 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/agents/clean-coder.md +31 -1
- package/audit-rubrics/prompts/category-e-dead-code.md +2 -2
- package/bin/install.test.mjs +2 -2
- package/docs/CLAUDE.md +6 -3
- package/docs/CODE_RULES.md +5 -1
- package/docs/agent-spawn-protocol.md +39 -0
- package/docs/nas-ssh-invocation.md +23 -0
- package/docs/worker-completion-gate.md +33 -0
- package/hooks/blocking/code_rules_dead_module_constant.py +11 -5
- package/hooks/blocking/config/verified_commit_constants.py +8 -1
- package/hooks/blocking/test_code_rules_enforcer_dead_module_constant.py +58 -0
- package/hooks/blocking/test_code_rules_enforcer_dead_module_constant_alias.py +133 -0
- package/hooks/blocking/test_verification_verdict_store.py +12 -0
- package/hooks/blocking/test_verified_commit_docs_delta.py +176 -0
- package/hooks/blocking/test_verifier_verdict_minter.py +55 -158
- package/hooks/blocking/tests/test_pii_prevention_blocker.py +0 -1
- package/hooks/hooks_constants/dead_module_constant_constants.py +8 -0
- package/hooks/hooks_constants/pii_prevention_constants.py +1 -0
- package/package.json +1 -1
- package/rules/CLAUDE.md +2 -3
- package/rules/agent-spawn-protocol.md +5 -43
- package/rules/code-standards.md +1 -36
- package/rules/env-var-table-code-drift.md +2 -21
- package/rules/hook-prose-matches-detector.md +5 -16
- package/rules/nas-ssh-invocation.md +3 -15
- package/rules/no-historical-clutter.md +7 -49
- package/rules/no-inline-destructive-literals.md +3 -5
- package/rules/package-inventory-stale-entry.md +7 -32
- package/rules/re-stage-before-commit.md +6 -23
- package/rules/shell-invocation-policy.md +1 -1
- package/rules/vault-context.md +3 -3
- package/rules/workers-done-before-complete.md +2 -30
- package/scripts/claude_chain_runner.py +39 -3
- package/scripts/dev_env_scripts_constants/claude_chain_constants.py +3 -0
- package/scripts/test_claude_chain_runner.py +112 -0
- package/scripts/test_grok_headless_runner.py +0 -1
- package/skills/auditing-claude-config/SKILL.md +1 -1
- package/skills/everything-search/SKILL.md +7 -1
- package/skills/orchestrator/SKILL.md +166 -143
- package/skills/orchestrator-refresh/SKILL.md +12 -4
- package/system-prompts/CLAUDE.md +3 -3
- package/docs/agents-md-alignment-plan.md +0 -123
- package/docs/emotion-informed-prompt-design.md +0 -362
- package/rules/es-exe-file-search.md +0 -17
|
@@ -4,23 +4,12 @@ paths: **/hooks/**/*.py
|
|
|
4
4
|
|
|
5
5
|
# Hook Prose Matches Its Detector
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
A hook's docstring lead narrative and its `CORRECTIVE_MESSAGE` describe exactly the shapes the detector flags — no broader trigger surface than the regex enforces.
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
`hook_prose_detector_consistency` (PreToolUse on Write|Edit of hook modules and `*_constants.py` companions) blocks prose that claims a trigger the detector never fires on, and names the fix.
|
|
10
10
|
|
|
11
|
-
##
|
|
11
|
+
## Judgment
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
After writing a hook, ask: would a token that matches every word of this message actually trip the detector? When the message names a shape the regex skips, rewrite the message to name only what the regex catches.
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
A path-shape blocker detects a per-iteration token only when the token sits next to a path separator (its detection regex keys off a `[\\/]`-style character class). Such a hook must not claim it blocks an "output-key segment": a quoted structured-output key alone, with no looped path, is never flagged. The `*_constants.py` companion holds the corrective message and not the detector, so the phrase "output-key segment" describing a blocked trigger is itself the violation there, regardless of which file holds the regex.
|
|
18
|
-
|
|
19
|
-
| Prohibited claim | Why it overstates | Correct phrasing |
|
|
20
|
-
|---|---|---|
|
|
21
|
-
| "appears as a path or output-key segment" | the detector keys off a path separator only | "appears as a per-iteration path segment" |
|
|
22
|
-
| docstring: "blocks a bare token like `cand_i`" | a bare prose token next to no separator is not flagged | "blocks a per-iteration path like `${work}\cand_i\plate.svg`" |
|
|
23
|
-
|
|
24
|
-
## The test
|
|
25
|
-
|
|
26
|
-
After writing a hook, ask: **would a token that matches every word of this message actually trip the detector?** When the message names a shape the regex skips, rewrite the message to name only what the regex catches.
|
|
15
|
+
The path-shape case is the common overstatement: a detector that keys off a path separator must not claim it blocks an "output-key segment". The corrective message spells the rewrite.
|
|
@@ -1,23 +1,11 @@
|
|
|
1
1
|
# NAS SSH Invocation Policy
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
## Rule
|
|
6
|
-
|
|
7
|
-
Reach the NAS through the Windows OpenSSH binary with batch mode on. Git Bash's MSYS `ssh` reads `~/.ssh/id_ed25519` as world-readable through its ACL mapping, rejects the key as bad permissions, offers no key, and falls back to an interactive password prompt. In an unattended session no one answers that prompt, so the session hangs. The `System32/OpenSSH` binary authenticates the same key without a prompt.
|
|
8
|
-
|
|
9
|
-
Use this form for every NAS ssh command:
|
|
3
|
+
Reach the NAS through the Windows `System32/OpenSSH` binary with `-o BatchMode=yes` on every `ssh`, `scp`, or `sftp` command:
|
|
10
4
|
|
|
11
5
|
```
|
|
12
6
|
"/c/Windows/System32/OpenSSH/ssh.exe" -o BatchMode=yes -o ConnectTimeout=10 -p 22 operator@nas.example.local "<cmd>"
|
|
13
7
|
```
|
|
14
8
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
The host, ssh user, and port come from the `CLAUDE_NAS_*` environment variables or `~/.claude/local-identity.json`; the committed examples show placeholders (`nas.example.local`, `operator`, `22`).
|
|
18
|
-
|
|
19
|
-
`-o BatchMode=yes` is required, not optional: it turns a key-authentication failure into a loud non-zero exit rather than a silent password prompt, so an auth regression surfaces as an error you can read.
|
|
20
|
-
|
|
21
|
-
## Enforcement
|
|
9
|
+
Git Bash's MSYS `ssh` falls back to an interactive password prompt that hangs an unattended session; the `System32/OpenSSH` binary authenticates the key without a prompt, and `-o BatchMode=yes` turns an auth failure into a loud non-zero exit. `nas_ssh_binary_enforcer.py` (PreToolUse on Bash) enforces this: it denies a bare ssh-family word aimed at the NAS, and denies the full binary when `-o BatchMode=yes` is absent.
|
|
22
10
|
|
|
23
|
-
|
|
11
|
+
Host, user, and port config, the `scp`/`sftp` forms, and the full rationale: `@~/.claude/docs/nas-ssh-invocation.md`.
|
|
@@ -11,58 +11,16 @@ paths:
|
|
|
11
11
|
|
|
12
12
|
# No Historical Clutter in Documentation or Comments
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
Never reference removed implementations, old defaults, prior behaviors, or earlier contracts when updating documentation or comments. The current state is all that matters. A module or function docstring carries the same describe-current-state-only contract as a `.md` file.
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
`state_description_blocker` (PreToolUse on Write|Edit) blocks historical and comparative phrases in `.md` prose, code comments, and Python docstrings; a phrase wrapped in double quotes or backticks inside a docstring counts as a mention and is skipped. The denial names the matched phrases and shows a rewrite example.
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
## What stays allowed
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
A module or function docstring carries the same describe-current-state-only contract as a `.md` file.
|
|
25
|
-
|
|
26
|
-
## Examples of prohibited patterns
|
|
27
|
-
|
|
28
|
-
### In documentation (.md files)
|
|
29
|
-
|
|
30
|
-
| Pattern | Why it's clutter |
|
|
31
|
-
|---------|-----------------|
|
|
32
|
-
| `` `"instead of 30"` `` in a pagination rule | The old default `no longer` exists in code; the rule reader doesn't need to know what it was |
|
|
33
|
-
| `` `"previously this used X"` `` | If X is gone, it's noise |
|
|
34
|
-
| `` `"before this rule, we did Y"` `` | The rule exists now; the before-state is irrelevant |
|
|
35
|
-
| `` `"migrated from Z to W"` `` | If Z is fully removed, the migration story is git history, not documentation |
|
|
36
|
-
| `` `"the old implementation did A"` `` | If A is gone, the reader gains nothing from knowing it existed |
|
|
37
|
-
| `` `"originally"` `` / `` `"used to be"` `` | Same — dead context |
|
|
38
|
-
|
|
39
|
-
### In code comments
|
|
40
|
-
|
|
41
|
-
| Pattern | Good replacement |
|
|
42
|
-
|---------|-----------------|
|
|
43
|
-
| `# Uses X instead of Y` | `# Uses X` |
|
|
44
|
-
| `# Previously configured via Z` | `# Configured via Z` |
|
|
45
|
-
| `# Now uses the new API client` | `# Uses the new API client` |
|
|
46
|
-
| `# No longer supports legacy mode` | `# Supports modern mode only` |
|
|
47
|
-
| `// Switched to async processing` | `// Processes asynchronously` |
|
|
48
|
-
| `# Replaced by the cache layer` | `# Cache layer handles reads` |
|
|
49
|
-
|
|
50
|
-
### Hook-detected patterns
|
|
51
|
-
|
|
52
|
-
The `state-description-blocker` hook (PreToolUse on Write\|Edit) enforces these patterns automatically:
|
|
53
|
-
|
|
54
|
-
`instead of`, `previously`, `now uses/does/handles/supports/names/includes`, `was previously`, `were previously`, `was formerly`, `was added`, `used to`, `no longer`, `has/have been updated/changed`, `replaced by`, `replaces`, `superseded by`, `supersedes`, `changed from`, `changes from`, `switched from/to`, `migrated from/to`, `moved to/into`, `extracted as`, `updated to`, `originally`, `as of`
|
|
55
|
-
|
|
56
|
-
## What IS allowed
|
|
57
|
-
|
|
58
|
-
- Comparisons to *currently existing* alternatives (e.g., "use `--paginate --slurp | jq`, not `--jq` alone")
|
|
59
|
-
- Rationale that explains *why* a pattern is wrong in terms of present behavior (e.g., "`--jq` runs per-page, so cross-page operations produce wrong results")
|
|
60
|
-
- References to external sources for defects that still exist (e.g., gh CLI #10459)
|
|
20
|
+
- Comparisons to alternatives that still exist (for example, "use `--paginate --slurp | jq`, not `--jq` alone")
|
|
21
|
+
- Rationale that explains why a pattern is wrong in terms of present behavior (for example, "`--jq` runs per-page, so cross-page operations produce wrong results")
|
|
22
|
+
- References to external sources for defects that still exist (for example, gh CLI #10459)
|
|
61
23
|
|
|
62
24
|
## The test
|
|
63
25
|
|
|
64
|
-
After writing
|
|
65
|
-
|
|
66
|
-
## Why
|
|
67
|
-
|
|
68
|
-
Historical references clog context windows and force readers to mentally filter "what was" from "what is." The git log is the authoritative record of what changed and why. Documentation describes the current contract.
|
|
26
|
+
After writing, ask: if someone reads this a year from now with no knowledge of earlier states, does every sentence still make sense and add value? If a sentence only helps someone who knew an earlier state, delete it.
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
# No Inline Destructive-Command Literals in Bash
|
|
2
2
|
|
|
3
|
-
The `destructive_command_blocker` PreToolUse hook matches destructive patterns (`rm -rf`, `git reset --hard`, `dd`, `mkfs`, `chmod -R`, fork bombs) as raw text anywhere in a Bash-tool command, with no quote-awareness — so a destructive literal carried only as
|
|
3
|
+
The `destructive_command_blocker` PreToolUse hook matches destructive patterns (`rm -rf`, `git reset --hard`, `dd`, `mkfs`, `chmod -R`, fork bombs) as raw text anywhere in a Bash-tool command, with no quote-awareness — so a destructive literal carried only as data (a commit message, a PR/issue body, an echoed string, a `python -c` / `node -e` / `awk` argument, a heredoc) trips the confirmation prompt even though the shell never executes it. In a background or auto-mode run no human can answer that prompt, so the call stalls.
|
|
4
4
|
|
|
5
5
|
Keep destructive literals out of the Bash command string:
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
- To exercise or verify
|
|
7
|
+
- Bodies that describe destructive-command behavior go in a file passed by path — `git commit -F <file>`, `gh ... --body-file <file>` (see [`gh-body-file`](gh-body-file.md)) — never `git commit -m` / `gh ... -b`.
|
|
8
|
+
- To exercise or verify the blocker (or any hook), run the committed test suite (`python -m pytest <test_file>`), which passes the command strings as in-language data — never an inline `python -c` harness.
|
|
9
9
|
- Genuine cleanup targets the OS temp dir or `$CLAUDE_JOB_DIR/tmp` (auto-allowed as ephemeral), never a repository or worktree path.
|
|
10
|
-
|
|
11
|
-
The `destructive_command_blocker` hook is the enforcement surface; this rule is how to keep a non-executing mention from tripping it.
|
|
@@ -10,41 +10,16 @@ paths:
|
|
|
10
10
|
|
|
11
11
|
# New Production File Absent From Its Package Inventory
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
A package directory that documents its own files in a `README.md` Layout table, a `CLAUDE.md` "Key files" list, or a skill `SKILL.md` Layout table keeps that inventory in step with the directory. When you create a new production file in such a directory, add an entry naming it — a row in the table or a bullet in the list — in the same change. The entry names the file in backticks and says what it does.
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
`package_inventory_stale_blocker.py` (PreToolUse on Write) blocks a new production file whose basename appears in no present inventory and names the fix. A skill `SKILL.md` Layout table that maps `scripts/` counts as the inventory for files in that subdirectory.
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
## Judgment the gate cannot derive
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
The file-list entry is the slice the gate checks by name. Two free-prose slices stay with judgment and belong in the same change:
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
1. **Purpose / scope sentence.** When the new module adds a responsibility the package `## Purpose` (or the parent inventory's one-line summary of this subdirectory) omits, broaden that sentence to name it. A hook cannot derive a module's responsibility from its filename.
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
2. **Per-file description clause.** When a file gains a responsibility the inventory's em-dash description omits — a new public function, a new module-level constant — broaden the description clause to name it. The gate only checks that the basename appears once; it never reads the description. Constants modules (`*_constants.py`, or any `.py` directly inside `config/`) are the common shape: the constant's other home is the module docstring, so the clause that lands in the docstring lands in the inventory description in the same change. The gate fires on Write of a new file and skips files directly inside `config/`, so an Edit that adds a constant to an existing config module matches neither path.
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
This scope-sentence slice is free prose: a hook cannot derive a module's responsibility from its filename, so the gate leaves it to judgment. It is the judgment companion to the file-list entry the gate enforces, and it belongs in the same change. This is the `category-o-docstring-vs-impl-drift` (O8) orphaned-doc-claim shape applied to a package inventory: a behavior change orphans a scope claim the prose still makes.
|
|
28
|
-
|
|
29
|
-
## Companion: keep a per-file description in step with the file it describes
|
|
30
|
-
|
|
31
|
-
The per-file entry a `CLAUDE.md` "Key files" list or a `README.md` Layout table gives each file carries more than the backticked filename the gate checks for. The clause after the file name — the em-dash description — is itself a free-prose scope claim about what the file holds. When the file gains a responsibility the description omits — a new public function, a new constant — the same change broadens the description clause to name it. The gate's file-list check passes the moment the file name appears once; it never reads the description clause, so a stale description beside a present file name stays invisible to the gate.
|
|
32
|
-
|
|
33
|
-
A constants module is the common shape of this drift. A file whose name ends `_constants.py`, or any `.py` directly inside a `config/` directory, holds a set of module-level constants, and a sibling inventory describes that file by listing the set — `` `stp_constants.py` — the STP archive member constants: the Properties.xml member name, the workspace prefix every asset reference carries, and the source-form nine-patch filename suffix ``. When the file gains a module-level constant the list omits, three claims drift together: the list itself, the scope label that heads it (`the STP archive member constants`), and the package `## Purpose` sentence when that sentence describes the file's contents. The constant's other home — the module docstring of the constants file — and the sibling inventory's description of that file cover the same set, so the clause that lands in the docstring lands in the inventory description in the same change.
|
|
34
|
-
|
|
35
|
-
This slice sits outside the gate. The gate fires on a Write that creates a new file, and it skips a file directly inside a `config/` directory, so an Edit that adds a constant to an existing `config/` constants module matches neither path. Like the Purpose/scope companion above, it is free prose a hook cannot derive from a file name, so it stays judgment here and a Category O8 finding at audit: a behavior change orphans a description claim the inventory still makes.
|
|
36
|
-
|
|
37
|
-
## What the gate checks
|
|
38
|
-
|
|
39
|
-
The `package_inventory_stale_blocker.py` hook runs on every Write whose target is a new file (a path not yet on disk). It:
|
|
40
|
-
|
|
41
|
-
1. Skips a target that is not a production code file (`.py`, `.mjs`, `.js`, `.ts`, `.ps1`, `.sh`), an exempt basename (`__init__.py`, `conftest.py`, `setup.py`, `_path_setup.py`), a test file (`test_*.py`, `*_test.py`, `*.spec.*`, `*.test.*`), or a file directly inside a `config/` or `tests/` directory.
|
|
42
|
-
2. Reads each `README.md`, `CLAUDE.md`, and `SKILL.md` present in the target's own directory and, when the target sits in a `scripts/` subdirectory, the parent directory's `SKILL.md`, and collects every bare filename they name in backticks. A backticked token holding a path contributes its final segment, so `pipeline/seam_continuity.py` in an inventory counts as naming `seam_continuity.py` and `scripts/stp_selection.py` in a parent `SKILL.md` Layout table counts as naming `stp_selection.py`. A multi-word command-example span — one carrying whitespace or shell punctuation (`:`, `$`, `<`, `>`), such as `parent:node_modules package.json` or `python <file>.py` — names no literal file and is dropped.
|
|
43
|
-
3. Filters the named basenames to those that exist as a file in the target's own directory — the inventory's own sibling files — and treats the directory as carrying a maintained inventory only when two or more such sibling files are named. A directory with no inventory, one whose `README.md` mentions a single file in passing, or one whose inventory prose names only files living in other directories (so no named basename is an on-disk sibling) is out of scope.
|
|
44
|
-
4. Blocks the write when the new file's basename appears in no present inventory. An unreadable or oversized inventory document is skipped, so a missing inventory never blocks a write.
|
|
45
|
-
|
|
46
|
-
The check fires on Write only — editing an existing file adds no new inventory entry — and stays quiet for a directory with no inventory document, an inventory naming too few siblings to be a maintained list, an exempt or test file, and a file the inventory already names.
|
|
47
|
-
|
|
48
|
-
## Why this is a hook, not a lint pass
|
|
49
|
-
|
|
50
|
-
A package inventory that omits a file reads as a complete map of the directory while leaving one file off it. A reader trusting the inventory to list the package misses the new file, and the gap survives review because the inventory still looks complete. Catching it as the new file is written keeps the inventory and the directory in step. This is the counterpart to `claude-md-orphan-file.md`, which catches the reverse drift: an inventory entry naming a file the directory does not hold.
|
|
25
|
+
This is the `category-o-docstring-vs-impl-drift` (O8) orphaned-doc-claim shape applied to a package inventory.
|
|
@@ -1,31 +1,14 @@
|
|
|
1
1
|
# Re-Stage Session Edits Before Commit
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Stage the files you edited this session right before you commit them. A plain `git commit` records only the staged snapshot; a tracked file this session changed but left unstaged stays behind in the working tree.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
`session_edit_stage_gate` (PreToolUse on Bash `git commit`) denies a commit that would drop tracked session edits and names the fix: `git add <paths>`, `git commit -a`, or a `# partial-commit` marker.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
## Escapes the denial does not restate
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
## What the gate allows
|
|
12
|
-
|
|
13
|
-
The gate steps aside for a commit that skips staged files on purpose:
|
|
14
|
-
|
|
15
|
-
- **`-a` / `--all`** — the commit already takes every tracked change, so nothing is dropped.
|
|
16
|
-
- **A pathspec** — `git commit -- <paths>` or `git commit <paths>` commits only the named paths on purpose.
|
|
17
|
-
- **A preceding `git add` / `git stage`** — `git add <paths> && git commit …` stages the files in its own segment before the commit runs, so they are staged by the time the commit records the index.
|
|
18
|
-
- **`# partial-commit`** — add this marker to the command to commit the staged set on purpose and leave the rest.
|
|
9
|
+
- **A pathspec** — `git commit -- <paths>` or `git commit <paths>` commits only the named paths on purpose and steps the gate aside.
|
|
10
|
+
- **A preceding `git add` / `git stage`** — `git add <paths> && git commit …` stages the files in its own segment before the commit runs.
|
|
19
11
|
|
|
20
12
|
A `--amend` does not step the gate aside: an amend records the staged snapshot too, so an unstaged session edit is dropped the same way a plain commit drops it.
|
|
21
13
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
## Companion hooks
|
|
25
|
-
|
|
26
|
-
- `session_file_edit_tracker` (PostToolUse) records the resolved absolute path of each Write, Edit, and MultiEdit into the per-session tracker file.
|
|
27
|
-
- `session_edit_tracker_cleanup` (SessionStart, SessionEnd) deletes the running session's own tracker file: at a fresh SessionStart so a new session begins with an empty record, and at SessionEnd so a clean exit leaves nothing behind. A tracker is read only by the session that wrote it, so a file a crashed session leaves behind is inert and no peer session touches it.
|
|
28
|
-
|
|
29
|
-
## Why
|
|
30
|
-
|
|
31
|
-
A stale git index is a quiet failure: the commit succeeds, the branch looks right, and one file you meant to include never lands. Catching it at commit time keeps the staged set and the session's edits in step.
|
|
14
|
+
`session_file_edit_tracker` (PostToolUse) records each Write/Edit/MultiEdit path; `session_edit_tracker_cleanup` (SessionStart, SessionEnd) clears the session's tracker.
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
|
|
3
3
|
Every Bash-tool shell command on Windows uses `pwsh`: `pwsh -NoProfile -File '<script>.ps1' <args>` for scripts, `pwsh -NoProfile -Command "..."` (or a literal `@'...'@` here-string) for inline work, or the built-in `PowerShell` tool for pure-PowerShell workflows (it supports `run_in_background`). Never wrap a script path in `-Command "& '...'"` — `-File` keeps `permissions.allow` matching. The `&` call operator is fine for invoking an executable at a path (`& '<venv>\Scripts\python.exe' script.py`).
|
|
4
4
|
|
|
5
|
-
`powershell`, `powershell.exe`, `cmd /c`, and `bash -c`
|
|
5
|
+
Keep `powershell`, `powershell.exe`, `cmd /c`, and `bash -c` out of the `settings.json` permission rules. `Audit-ShellPolicy.ps1` reports those forms and `Migrate-ShellPolicy.ps1` rewrites them to `pwsh`, both in `packages/claude-dev-env/scripts/` and run on demand, not as a live gate.
|
package/rules/vault-context.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Obsidian Vault Context
|
|
2
2
|
|
|
3
|
-
An Obsidian vault
|
|
3
|
+
An Obsidian vault holds session reports (`sessions/`), decisions (`decisions/`), and research (`Research/`) across projects, reached through the obsidian MCP tools.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Before substantive project work, search the vault for prior sessions and decisions on the current project through the `recall` skill — by `project` frontmatter first, then by keyword. Search again when touching a component with known history, or when a task might repeat or reverse a prior decision.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
At the end of a substantive session, offer the `session-log` skill; it owns the report format, the `vault_context_retrieved` and `session_id` frontmatter, and the closing `/rename` hand-off.
|
|
@@ -1,33 +1,5 @@
|
|
|
1
1
|
# Workers Done Before Complete
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Before marking a task `completed` that spawned workers — subagents, workflow agents, or background shells — confirm both: every worker has finished, and each worker's result is merged into run state (`state.json`, `pr-converge-state.json`, the task list, or whatever record the task keeps). A worker still running, or one whose output never landed in run state, keeps the task `in_progress`: list the live workers, report any dead or hung one as a finding rather than dropping it in silence, and schedule a wakeup so the run picks the workers back up before the task closes.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
A task reaches `completed` only when two things hold: every worker it spawned has finished, and each worker's result is merged into run state — `state.json`, `pr-converge-state.json`, the task list, or whatever record the task keeps. A worker that still runs, or one that finished but whose output never landed in run state, leaves the task open.
|
|
8
|
-
|
|
9
|
-
List the live workers before you mark the task complete. When a worker is dead or hung, that is a finding to record and report, not a result to drop in silence. A step that waits on workers ends its turn `in_progress` with a wakeup scheduled, so the run picks the workers back up rather than closing the task without them.
|
|
10
|
-
|
|
11
|
-
## Checklist before marking complete
|
|
12
|
-
|
|
13
|
-
| Check | Action |
|
|
14
|
-
|---|---|
|
|
15
|
-
| Are any spawned workers still running? | List them; if yes, stay `in_progress` and schedule a wakeup. |
|
|
16
|
-
| Did every finished worker return a result? | Read each result; a dead or hung worker is a finding to report. |
|
|
17
|
-
| Is each result merged into run state? | Write it to `state.json` / the task list before closing. |
|
|
18
|
-
| Does the task's own goal now hold? | Confirm against the merged state, not a worker's self-report. |
|
|
19
|
-
|
|
20
|
-
Mark `completed` only when every row passes.
|
|
21
|
-
|
|
22
|
-
## Examples
|
|
23
|
-
|
|
24
|
-
**Wrong:** Marking the audit task complete while two bugteam workers still run in the background.
|
|
25
|
-
**Right:** List the workers, see two still running, keep the task `in_progress`, and schedule a wakeup to collect them.
|
|
26
|
-
|
|
27
|
-
**Wrong:** A worker crashes; the task closes as complete because the other workers finished.
|
|
28
|
-
**Right:** Record the crashed worker as a finding, report it, and hold the task open until its work is covered.
|
|
29
|
-
|
|
30
|
-
## Relationship to other rules
|
|
31
|
-
|
|
32
|
-
- **`long-horizon-autonomy`** covers acting on what you have and not ending a turn on a promise. This rule names the specific completion gate: workers finished and their results merged.
|
|
33
|
-
- **`skills/pr-converge/reference/state-schema.md`** defines the run-state records this rule requires a worker's result to land in before the task closes.
|
|
5
|
+
Checklist, examples, and run-state detail: `@~/.claude/docs/worker-completion-gate.md`.
|
|
@@ -19,6 +19,12 @@ A usage-limited primary falls over to the second binary::
|
|
|
19
19
|
primary claude -> exit 1, "usage limit reached" (falls over)
|
|
20
20
|
fallback claude-ev -> exit 0 (served)
|
|
21
21
|
|
|
22
|
+
When stdin is piped (not a TTY), the runner reads it once and forwards the
|
|
23
|
+
same text to every chain attempt so a piped ``-p`` charter body reaches each
|
|
24
|
+
binary in the walk::
|
|
25
|
+
|
|
26
|
+
cat charter.md | python claude_chain_runner.py -- -p --strict-mcp-config
|
|
27
|
+
|
|
22
28
|
Import ``run_claude`` for the outcome object, or run the module as a CLI::
|
|
23
29
|
|
|
24
30
|
python claude_chain_runner.py [--timeout-seconds N] -- <claude args...>
|
|
@@ -27,11 +33,13 @@ Import ``run_claude`` for the outcome object, or run the module as a CLI::
|
|
|
27
33
|
from __future__ import annotations
|
|
28
34
|
|
|
29
35
|
import argparse
|
|
36
|
+
import io
|
|
30
37
|
import json
|
|
31
38
|
import subprocess
|
|
32
39
|
import sys
|
|
33
40
|
from dataclasses import dataclass
|
|
34
41
|
from pathlib import Path
|
|
42
|
+
from typing import TextIO
|
|
35
43
|
|
|
36
44
|
from dev_env_scripts_constants.claude_chain_constants import (
|
|
37
45
|
ALL_USAGE_LIMIT_SIGNATURES,
|
|
@@ -48,6 +56,7 @@ from dev_env_scripts_constants.claude_chain_constants import (
|
|
|
48
56
|
CLAUDE_HOME_SUBDIRECTORY,
|
|
49
57
|
CLI_ARGUMENTS_SEPARATOR,
|
|
50
58
|
CLI_TIMEOUT_FLAG,
|
|
59
|
+
CODEC_ERROR_STRATEGY,
|
|
51
60
|
CONFIG_CHAIN_EMPTY_REASON,
|
|
52
61
|
CONFIG_CHAIN_KEY,
|
|
53
62
|
CONFIG_CHAIN_NOT_LIST_REASON,
|
|
@@ -283,7 +292,10 @@ def _classify_completion(
|
|
|
283
292
|
|
|
284
293
|
|
|
285
294
|
def run_claude(
|
|
286
|
-
all_claude_arguments: list[str],
|
|
295
|
+
all_claude_arguments: list[str],
|
|
296
|
+
*,
|
|
297
|
+
timeout_seconds: int,
|
|
298
|
+
stdin_text: str | None = None,
|
|
287
299
|
) -> ChainInvocationOutcome:
|
|
288
300
|
"""Run *all_claude_arguments* through the configured fallback chain.
|
|
289
301
|
|
|
@@ -291,12 +303,16 @@ def run_claude(
|
|
|
291
303
|
exit whose output carries a usage-limit signature) falls over to the next
|
|
292
304
|
binary. A missing fallback binary is skipped and the walk continues. A
|
|
293
305
|
timeout, a missing primary binary, or a non-zero exit without a usage-limit
|
|
294
|
-
signature stops the walk and returns that outcome unchanged.
|
|
306
|
+
signature stops the walk and returns that outcome unchanged. When
|
|
307
|
+
*stdin_text* is set, that same text is supplied as stdin on every chain
|
|
308
|
+
attempt.
|
|
295
309
|
|
|
296
310
|
Args:
|
|
297
311
|
all_claude_arguments: Arguments passed after the binary name, such as
|
|
298
312
|
``["-p", prompt, "--strict-mcp-config"]``.
|
|
299
313
|
timeout_seconds: Timeout applied to each binary invocation.
|
|
314
|
+
stdin_text: Optional UTF-8 text forwarded as stdin to every binary.
|
|
315
|
+
``None`` leaves the subprocess without a piped stdin body.
|
|
300
316
|
|
|
301
317
|
Returns:
|
|
302
318
|
The outcome of the walk, naming the serving binary and the full
|
|
@@ -315,8 +331,11 @@ def run_claude(
|
|
|
315
331
|
_build_invocation(each_entry, all_claude_arguments),
|
|
316
332
|
capture_output=True,
|
|
317
333
|
text=True,
|
|
334
|
+
encoding=UTF8_ENCODING,
|
|
335
|
+
errors=CODEC_ERROR_STRATEGY,
|
|
318
336
|
timeout=timeout_seconds,
|
|
319
337
|
check=False,
|
|
338
|
+
input=stdin_text,
|
|
320
339
|
)
|
|
321
340
|
except subprocess.TimeoutExpired as timeout_error:
|
|
322
341
|
all_attempts.append(
|
|
@@ -368,6 +387,12 @@ def _exhausted_message(all_attempts: tuple[ChainAttempt, ...]) -> str:
|
|
|
368
387
|
return CHAIN_EXHAUSTED_MESSAGE_TEMPLATE.format(attempt_summary=attempt_summary)
|
|
369
388
|
|
|
370
389
|
|
|
390
|
+
def _read_piped_stdin_text() -> str | None:
|
|
391
|
+
if sys.stdin.isatty():
|
|
392
|
+
return None
|
|
393
|
+
return sys.stdin.read()
|
|
394
|
+
|
|
395
|
+
|
|
371
396
|
def main(all_command_arguments: list[str]) -> int:
|
|
372
397
|
"""Walk the chain for CLI arguments and return the process exit code.
|
|
373
398
|
|
|
@@ -381,9 +406,12 @@ def main(all_command_arguments: list[str]) -> int:
|
|
|
381
406
|
parser = _build_argument_parser()
|
|
382
407
|
parsed_arguments = parser.parse_args(all_command_arguments)
|
|
383
408
|
all_claude_arguments = _strip_leading_separator(parsed_arguments.passthrough)
|
|
409
|
+
maybe_stdin_text = _read_piped_stdin_text()
|
|
384
410
|
try:
|
|
385
411
|
chain_outcome = run_claude(
|
|
386
|
-
all_claude_arguments,
|
|
412
|
+
all_claude_arguments,
|
|
413
|
+
timeout_seconds=parsed_arguments.timeout_seconds,
|
|
414
|
+
stdin_text=maybe_stdin_text,
|
|
387
415
|
)
|
|
388
416
|
except ChainConfigurationError as configuration_error:
|
|
389
417
|
print(str(configuration_error), file=sys.stderr)
|
|
@@ -396,5 +424,13 @@ def main(all_command_arguments: list[str]) -> int:
|
|
|
396
424
|
return chain_outcome.returncode
|
|
397
425
|
|
|
398
426
|
|
|
427
|
+
def _reconfigure_stream_to_utf8(stream: TextIO) -> None:
|
|
428
|
+
"""Reconfigure *stream* to emit UTF-8, replacing any unmappable character."""
|
|
429
|
+
if isinstance(stream, io.TextIOWrapper):
|
|
430
|
+
stream.reconfigure(encoding=UTF8_ENCODING, errors=CODEC_ERROR_STRATEGY)
|
|
431
|
+
|
|
432
|
+
|
|
399
433
|
if __name__ == "__main__":
|
|
434
|
+
_reconfigure_stream_to_utf8(sys.stdout)
|
|
435
|
+
_reconfigure_stream_to_utf8(sys.stderr)
|
|
400
436
|
sys.exit(main(sys.argv[1:]))
|
|
@@ -9,6 +9,9 @@ from __future__ import annotations
|
|
|
9
9
|
UTF8_ENCODING: str = "utf-8"
|
|
10
10
|
"""Encoding used to read the chain configuration file."""
|
|
11
11
|
|
|
12
|
+
CODEC_ERROR_STRATEGY: str = "replace"
|
|
13
|
+
"""Codec error handler that maps any unencodable or undecodable value to a marker."""
|
|
14
|
+
|
|
12
15
|
CLAUDE_HOME_SUBDIRECTORY: str = ".claude"
|
|
13
16
|
"""Per-user directory under the home directory that holds the chain config."""
|
|
14
17
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"""Behavioral tests for the claude fallback-chain runner."""
|
|
2
2
|
|
|
3
3
|
import json
|
|
4
|
+
import os
|
|
4
5
|
import subprocess
|
|
5
6
|
import sys
|
|
6
7
|
from pathlib import Path
|
|
@@ -78,20 +79,32 @@ class _Recorder:
|
|
|
78
79
|
self.behavior_by_command = behavior_by_command
|
|
79
80
|
self.invocations = []
|
|
80
81
|
self.timeouts = []
|
|
82
|
+
self.all_keyword_arguments = []
|
|
81
83
|
|
|
82
84
|
def __call__(self, invocation, **keyword_arguments):
|
|
83
85
|
self.invocations.append(invocation)
|
|
84
86
|
self.timeouts.append(keyword_arguments.get("timeout"))
|
|
87
|
+
self.all_keyword_arguments.append(keyword_arguments)
|
|
85
88
|
behavior = self.behavior_by_command[invocation[0]]
|
|
86
89
|
if isinstance(behavior, BaseException):
|
|
87
90
|
raise behavior
|
|
88
91
|
return behavior
|
|
89
92
|
|
|
90
93
|
|
|
94
|
+
class _TtyStdin:
|
|
95
|
+
def isatty(self) -> bool:
|
|
96
|
+
return True
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def _install_tty_stdin(monkeypatch):
|
|
100
|
+
monkeypatch.setattr(runner.sys, "stdin", _TtyStdin())
|
|
101
|
+
|
|
102
|
+
|
|
91
103
|
def _install(monkeypatch, config_file, behavior_by_command):
|
|
92
104
|
recorder = _Recorder(behavior_by_command)
|
|
93
105
|
monkeypatch.setattr(runner, "chain_config_path", lambda: config_file)
|
|
94
106
|
monkeypatch.setattr(runner, "chain_subprocess_runner", recorder)
|
|
107
|
+
_install_tty_stdin(monkeypatch)
|
|
95
108
|
return recorder
|
|
96
109
|
|
|
97
110
|
|
|
@@ -276,6 +289,45 @@ def test_extra_args_are_appended_to_invocation(
|
|
|
276
289
|
assert recorder.invocations[0] == ["claude", "-p", "hello", "--account", "ev"]
|
|
277
290
|
|
|
278
291
|
|
|
292
|
+
def test_run_claude_forwards_stdin_text_to_subprocess(
|
|
293
|
+
monkeypatch: pytest.MonkeyPatch, tmp_path: Path
|
|
294
|
+
) -> None:
|
|
295
|
+
config_file = _write_chain_config(tmp_path, [_entry("claude")])
|
|
296
|
+
recorder = _install(monkeypatch, config_file, {"claude": _completed("claude", 0)})
|
|
297
|
+
runner.run_claude(
|
|
298
|
+
_PROMPT_ARGUMENTS, timeout_seconds=5, stdin_text="charter body"
|
|
299
|
+
)
|
|
300
|
+
assert recorder.all_keyword_arguments[0]["input"] == "charter body"
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
def test_run_claude_passes_none_input_when_stdin_text_omitted(
|
|
304
|
+
monkeypatch: pytest.MonkeyPatch, tmp_path: Path
|
|
305
|
+
) -> None:
|
|
306
|
+
config_file = _write_chain_config(tmp_path, [_entry("claude")])
|
|
307
|
+
recorder = _install(monkeypatch, config_file, {"claude": _completed("claude", 0)})
|
|
308
|
+
runner.run_claude(_PROMPT_ARGUMENTS, timeout_seconds=5)
|
|
309
|
+
assert recorder.all_keyword_arguments[0].get("input") is None
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
def test_cli_forwards_piped_stdin_to_invocation(
|
|
313
|
+
monkeypatch: pytest.MonkeyPatch, tmp_path: Path
|
|
314
|
+
) -> None:
|
|
315
|
+
config_file = _write_chain_config(tmp_path, [_entry("claude")])
|
|
316
|
+
recorder = _install(monkeypatch, config_file, {"claude": _completed("claude", 0)})
|
|
317
|
+
|
|
318
|
+
class _PipedStdin:
|
|
319
|
+
def isatty(self) -> bool:
|
|
320
|
+
return False
|
|
321
|
+
|
|
322
|
+
def read(self) -> str:
|
|
323
|
+
return "charter body"
|
|
324
|
+
|
|
325
|
+
monkeypatch.setattr(runner.sys, "stdin", _PipedStdin())
|
|
326
|
+
exit_code = runner.main([CLI_ARGUMENTS_SEPARATOR, "-p", "hi"])
|
|
327
|
+
assert exit_code == 0
|
|
328
|
+
assert recorder.all_keyword_arguments[0]["input"] == "charter body"
|
|
329
|
+
|
|
330
|
+
|
|
279
331
|
def test_signature_matching_is_case_insensitive(
|
|
280
332
|
monkeypatch: pytest.MonkeyPatch, tmp_path: Path
|
|
281
333
|
) -> None:
|
|
@@ -362,6 +414,7 @@ def test_cli_missing_config_exits_config_error(
|
|
|
362
414
|
) -> None:
|
|
363
415
|
missing_config = tmp_path / CONFIG_FILENAME
|
|
364
416
|
monkeypatch.setattr(runner, "chain_config_path", lambda: missing_config)
|
|
417
|
+
_install_tty_stdin(monkeypatch)
|
|
365
418
|
exit_code = runner.main([CLI_ARGUMENTS_SEPARATOR, "-p", "hi"])
|
|
366
419
|
captured = capsys.readouterr()
|
|
367
420
|
assert exit_code == CHAIN_CONFIG_ERROR_EXIT_CODE
|
|
@@ -470,3 +523,62 @@ def test_chain_config_path_points_at_home_config() -> None:
|
|
|
470
523
|
config_path = runner.chain_config_path()
|
|
471
524
|
assert config_path.name == CONFIG_FILENAME
|
|
472
525
|
assert CLAUDE_HOME_SUBDIRECTORY in config_path.parts
|
|
526
|
+
|
|
527
|
+
|
|
528
|
+
def test_real_subprocess_capture_replaces_undecodable_bytes(
|
|
529
|
+
monkeypatch: pytest.MonkeyPatch, tmp_path: Path
|
|
530
|
+
) -> None:
|
|
531
|
+
config_file = _write_chain_config(tmp_path, [_entry(sys.executable)])
|
|
532
|
+
monkeypatch.setattr(runner, "chain_config_path", lambda: config_file)
|
|
533
|
+
child_code = 'import sys; sys.stdout.buffer.write(b"ok \\x90 end")'
|
|
534
|
+
chain_result = runner.run_claude(["-c", child_code], timeout_seconds=60)
|
|
535
|
+
assert chain_result.served_command == sys.executable
|
|
536
|
+
assert chain_result.returncode == 0
|
|
537
|
+
assert chain_result.stdout == "ok � end"
|
|
538
|
+
|
|
539
|
+
|
|
540
|
+
def test_real_subprocess_capture_preserves_utf8_text(
|
|
541
|
+
monkeypatch: pytest.MonkeyPatch, tmp_path: Path
|
|
542
|
+
) -> None:
|
|
543
|
+
config_file = _write_chain_config(tmp_path, [_entry(sys.executable)])
|
|
544
|
+
monkeypatch.setattr(runner, "chain_config_path", lambda: config_file)
|
|
545
|
+
child_code = 'import sys; sys.stdout.buffer.write("report ✅ done".encode("utf-8"))'
|
|
546
|
+
chain_result = runner.run_claude(["-c", child_code], timeout_seconds=60)
|
|
547
|
+
assert chain_result.served_command == sys.executable
|
|
548
|
+
assert chain_result.returncode == 0
|
|
549
|
+
assert chain_result.stdout == "report ✅ done"
|
|
550
|
+
|
|
551
|
+
|
|
552
|
+
def test_cli_emits_utf8_when_console_encoding_is_legacy(tmp_path: Path) -> None:
|
|
553
|
+
tmp_home = tmp_path / "home"
|
|
554
|
+
claude_directory = tmp_home / CLAUDE_HOME_SUBDIRECTORY
|
|
555
|
+
claude_directory.mkdir(parents=True)
|
|
556
|
+
config_file = claude_directory / CONFIG_FILENAME
|
|
557
|
+
config_file.write_text(
|
|
558
|
+
json.dumps({CONFIG_CHAIN_KEY: [_entry(sys.executable)]}),
|
|
559
|
+
encoding=UTF8_ENCODING,
|
|
560
|
+
)
|
|
561
|
+
runner_script = _SCRIPTS_DIR / "claude_chain_runner.py"
|
|
562
|
+
child_code = 'import sys; sys.stdout.buffer.write("report ✅".encode("utf-8"))'
|
|
563
|
+
legacy_console_encoding = "cp1252"
|
|
564
|
+
child_environment = dict(os.environ)
|
|
565
|
+
child_environment["USERPROFILE"] = str(tmp_home)
|
|
566
|
+
child_environment["HOME"] = str(tmp_home)
|
|
567
|
+
child_environment["PYTHONIOENCODING"] = legacy_console_encoding
|
|
568
|
+
child_environment.pop("PYTHONUTF8", None)
|
|
569
|
+
runner_command = [
|
|
570
|
+
sys.executable,
|
|
571
|
+
str(runner_script),
|
|
572
|
+
CLI_ARGUMENTS_SEPARATOR,
|
|
573
|
+
"-c",
|
|
574
|
+
child_code,
|
|
575
|
+
]
|
|
576
|
+
completed = subprocess.run(
|
|
577
|
+
runner_command,
|
|
578
|
+
capture_output=True,
|
|
579
|
+
env=child_environment,
|
|
580
|
+
timeout=60,
|
|
581
|
+
)
|
|
582
|
+
assert completed.returncode == 0
|
|
583
|
+
assert b"Traceback" not in completed.stderr
|
|
584
|
+
assert "report ✅" in completed.stdout.decode(UTF8_ENCODING)
|
|
@@ -418,7 +418,6 @@ def test_tightened_auth_phrases_still_classify_auth_failure(
|
|
|
418
418
|
assert outcome.classification == CLASSIFICATION_AUTH_FAILURE, each_stderr
|
|
419
419
|
|
|
420
420
|
|
|
421
|
-
def test_dual_match_prefers_auth_failure_over_usage_limit(
|
|
422
421
|
def test_missing_binary_returns_dedicated_error(
|
|
423
422
|
monkeypatch: pytest.MonkeyPatch, tmp_path: Path
|
|
424
423
|
) -> None:
|
|
@@ -31,7 +31,7 @@ These come from the official Claude Code documentation; do not re-derive them.
|
|
|
31
31
|
| Files in `.claude/rules/` without `paths:` frontmatter load **every** session | "Rules without `paths` frontmatter are loaded unconditionally and apply to all files" |
|
|
32
32
|
| Path-scoped rules load **lazily** when matching files are accessed | "Rules can be scoped to specific files using YAML frontmatter with the `paths` field. These conditional rules only apply when Claude is working with files matching the specified patterns" |
|
|
33
33
|
| Skills preload **metadata only** | "At startup, only the metadata (name and description) from all Skills is pre-loaded. Claude reads SKILL.md only when the Skill becomes relevant, and reads additional files only as needed" |
|
|
34
|
-
| `@`-imports inside fenced/inline code blocks do not trigger imports | Empirical (
|
|
34
|
+
| `@`-imports inside fenced/inline code blocks do not trigger imports | Empirical (`InstructionsLoaded` hook): a bare `@`-import fires an `include` load event; the same path wrapped in backticks fires none, so the referenced file stays out of session-start context |
|
|
35
35
|
|
|
36
36
|
## Audit workflow
|
|
37
37
|
|