feat(bstack): add bstack doctor — verify primitive contract#2
Conversation
Companion to broomva/workspace P10 PR. Closes the user request: when
bstack is installed, the skill should make sure the agent .md rules
properly comply with the whole stack's primitive strategies.
scripts/doctor.sh:
Validates that the workspace's governance files comply with the
bstack primitive contract. Seven sections of checks:
1. Governance files exist (CLAUDE.md, AGENTS.md, .control/policy.yaml)
2. CLAUDE.md primitives table — all P1–P10 rows + correct count header
3. AGENTS.md primitive sections — `### P1:` through `### P10:`
4. Reflexive Trigger Rule subsections present for primitives whose
discipline is reasoning-enforced (P6 Bookkeeping, P7 CI Watcher,
P10 Worktree Hygiene)
5. .control/policy.yaml has required blocks (ci_watch:, ci_heal:,
auto_merge:)
6. .claude/settings.json hooks wired (P1, P2, P8)
7. Each primitive's mechanism reachable on disk (the relevant
scripts/skill exists)
Modes:
default — full passes/gaps report with → fix: hints; exit 0
--quiet — only show gaps (used by bootstrap)
--strict — exit 1 on any gap (CI mode)
Always non-blocking by default — never breaks a session. Each gap
includes an actionable fix hint.
scripts/bootstrap.sh:
- Total skill count 27 → 30 (matches current bootstrap roster)
- New final step: invoke doctor in --quiet mode
- A fresh install now immediately self-checks primitive compliance
SKILL.md:
- New `doctor` command section between `validate` and `revamp`
- Documents the seven check sections and the three modes
- Notes that `bootstrap` invokes `doctor` automatically
Smoke-tested locally — caught the expected 4 P10 gaps on a workspace
that hadn't yet pulled broomva/workspace#42 (Ten/10 header missing,
P10 row missing in CLAUDE.md table, P10 section missing in AGENTS.md,
P10 reflexive rule missing). After workspace#42 lands, doctor will
report 39/39 passes.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
📝 WalkthroughWalkthroughThis PR introduces a new ChangesGovernance Validation Feature
Estimated Code Review Effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
scripts/bootstrap.sh (1)
88-88: ⚡ Quick winDerive total from roster instead of hardcoding
30Line 88 will drift if skills are added/removed again. Prefer
${#ORDERED_SKILLS[@]}for an always-correct total.Suggested fix
-echo " Total: $((installed + skipped))/30" +echo " Total: $((installed + skipped))/${`#ORDERED_SKILLS`[@]}"🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@scripts/bootstrap.sh` at line 88, The summary count uses a hardcoded 30; update the echo to derive the total from the roster by replacing the hardcoded 30 with the length of ORDERED_SKILLS (use ${`#ORDERED_SKILLS`[@]} or a computed total variable) so the displayed total reflects the actual number of skills; adjust the echo line that references installed and skipped (and any related variable named ORDERED_SKILLS, installed, skipped) to use ${`#ORDERED_SKILLS`[@]} for the denominator.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@scripts/doctor.sh`:
- Around line 47-49: The workspace existence check in scripts/doctor.sh uses -d
for "$WORKSPACE/.git" which fails for Git worktrees where .git is a file; update
the conditional that references WORKSPACE to treat .git as either a file or
directory (e.g., test for existence with -e or combine -d || -f) so the check
becomes: if neither "$WORKSPACE/.git" nor "$WORKSPACE/.control" exist, then
print the message and exit. Modify the conditional guarding that echo/exit block
(the one referencing WORKSPACE, "$WORKSPACE/.git" and "$WORKSPACE/.control")
accordingly.
---
Nitpick comments:
In `@scripts/bootstrap.sh`:
- Line 88: The summary count uses a hardcoded 30; update the echo to derive the
total from the roster by replacing the hardcoded 30 with the length of
ORDERED_SKILLS (use ${`#ORDERED_SKILLS`[@]} or a computed total variable) so the
displayed total reflects the actual number of skills; adjust the echo line that
references installed and skipped (and any related variable named ORDERED_SKILLS,
installed, skipped) to use ${`#ORDERED_SKILLS`[@]} for the denominator.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 1ee8be61-9d74-433c-821a-a4cbefd50537
📒 Files selected for processing (3)
SKILL.mdscripts/bootstrap.shscripts/doctor.sh
| if [ ! -d "$WORKSPACE/.git" ] && [ ! -d "$WORKSPACE/.control" ]; then | ||
| echo "[bstack doctor] workspace not found at $WORKSPACE (set BROOMVA_WORKSPACE)" | ||
| exit 0 |
There was a problem hiding this comment.
Workspace detection misses valid Git worktrees (false “not found”)
Line 47 checks .git with -d, but in worktrees .git is a file. That can make doctor exit early on valid workspaces and skip all checks.
Suggested fix
-if [ ! -d "$WORKSPACE/.git" ] && [ ! -d "$WORKSPACE/.control" ]; then
+if [ ! -e "$WORKSPACE/.git" ] && [ ! -d "$WORKSPACE/.control" ]; then
echo "[bstack doctor] workspace not found at $WORKSPACE (set BROOMVA_WORKSPACE)"
exit 0
fi📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if [ ! -d "$WORKSPACE/.git" ] && [ ! -d "$WORKSPACE/.control" ]; then | |
| echo "[bstack doctor] workspace not found at $WORKSPACE (set BROOMVA_WORKSPACE)" | |
| exit 0 | |
| if [ ! -e "$WORKSPACE/.git" ] && [ ! -d "$WORKSPACE/.control" ]; then | |
| echo "[bstack doctor] workspace not found at $WORKSPACE (set BROOMVA_WORKSPACE)" | |
| exit 0 | |
| fi |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@scripts/doctor.sh` around lines 47 - 49, The workspace existence check in
scripts/doctor.sh uses -d for "$WORKSPACE/.git" which fails for Git worktrees
where .git is a file; update the conditional that references WORKSPACE to treat
.git as either a file or directory (e.g., test for existence with -e or combine
-d || -f) so the check becomes: if neither "$WORKSPACE/.git" nor
"$WORKSPACE/.control" exist, then print the message and exit. Modify the
conditional guarding that echo/exit block (the one referencing WORKSPACE,
"$WORKSPACE/.git" and "$WORKSPACE/.control") accordingly.
…e_gate (#18) * docs(specs): indirect prompt injection defense spec (2026-05-15) Four-tier defense plan for the AI-coding-agent-as-attack-vector class of vulnerabilities, triggered by the blockchain-C2 incident at https://gist.github.com/mihai-r-lupu/d94afd240658c37fb0924609f159431b (mihai-r-lupu, 2026-05-06). The spec is grounded in deep-research synthesis of 35+ sources spanning academic (OWASP LLM Top 10 2025, NIST AI 600-1, arxiv papers from DeepMind / Microsoft / Berkeley / Meta), vendor docs (Anthropic, OpenAI, Cursor, Replit, Cognition, Continue.dev, Aider, MCP), and 30+ CVE-classed real-world incidents (EchoLeak, CamoLeak, CVE-2025-53773 Copilot YOLO-Mode, CurXecute, MCPoison, Nx s1ngularity, Shai-Hulud). The four tiers: Tier 1 (~1 week): policy + write-gate substrate (this PR ships the schema) Tier 2 (~2 weeks): read-side trust boundary (P14 prototype already exists) Tier 3 (~1 month): sandbox-runtime + AI-commit trailer Tier 4 (ongoing): AgentDojo adversarial eval + CVE-feed monitoring Full research basis: ~/Documents/IndirectPromptInjection_Research_20260515/report.md Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * feat(policy): editor-config + gitignore path gates + write_gate block Tier 1 of the indirect-prompt-injection defense spec (specs/2026-05-15-indirect-prompt-injection-defense.md §4 Tier 1). Schema-first ship: the policy template extension lands first, the runtime consumer (~/broomva/scripts/check-file-write-safety.py) ships in a separate PR against broomva/workspace so this PR is atomic and reviewable on its own. Three additions to policy.yaml.template: 1. Seven new auto_merge.rules entries (require_human on editor-config paths): - .vscode/* — CVE-2025-53773 Copilot YOLO-Mode; blockchain-C2 gist - .cursor/* — CurXecute CVE-2025-54135; MCPoison CVE-2025-54136 - .idea/* — JetBrains config equivalent (pre-emptive) - .continue/* — Continue.dev config - .aider/* — Aider config - .claude/settings.json — Claudy Day Claude.ai exfil class - .gitignore — blockchain-C2 stage 5 (silent commit via pattern removal) 2. New top-level `write_gate` block with three sub-blocks: - content_patterns: 6 regex refusal patterns covering runOn:folderOpen, task.allowAutomaticTasks:true, chat.tools.autoApprove:true, --dangerously-skip-permissions, public-blockchain RPCs, detached child_process.spawn - magic_bytes_check: refuses font/image/text files whose content starts with script or executable magic bytes (catches the font- file-with-JS-content disguise from blockchain-C2 stage 4) - gitignore_modification: removed_patterns_require_human (additions are normal; pattern removals enable silent commits) 3. Inline rationale per rule citing the specific CVE or incident evidence — every gate is grounded in documented exploitation. P11 validation (schema): - yaml.safe_load() parses cleanly ✓ - 11 auto_merge.rules total (was 4, now 4 governance + 7 editor-config) - 6 content_patterns, 3 magic_bytes_check rules, gitignore_modification enabled - All 7 require_human editor-config rules discoverable via path_touched filter The runtime ships next as PR #2 against broomva/workspace. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Summary
Adds `bstack doctor` — a companion to the upcoming P10 (Worktree Hygiene Discipline) primitive in broomva/workspace#42.
When bstack is installed, the skill should make sure the workspace's governance files (`AGENTS.md`, `CLAUDE.md`, `.control/policy.yaml`, `.claude/settings.json`) properly comply with the whole stack's primitive contract. `bstack doctor` is that mechanism.
Files
What the doctor checks
Modes
Smoke test
Run locally on a workspace that hasn't yet pulled broomva/workspace#42:
```
[bstack doctor] 35/39 passed, 4 gap(s) — see above
```
Caught exactly the 4 expected P10 gaps. After workspace#42 lands, doctor will report 39/39.
Order of merges
This PR + workspace#42 (P10 governance) ship together. Recommended order:
🤖 Generated with Claude Code
Summary by CodeRabbit
doctorcommand to verify governance compliance and contract requirements across your workspace.