Skip to content

feat(bstack): add bstack doctor — verify primitive contract#2

Merged
broomva merged 1 commit into
mainfrom
feat/bstack-doctor
May 5, 2026
Merged

feat(bstack): add bstack doctor — verify primitive contract#2
broomva merged 1 commit into
mainfrom
feat/bstack-doctor

Conversation

@broomva
Copy link
Copy Markdown
Owner

@broomva broomva commented May 5, 2026

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

  • `scripts/doctor.sh` (~190 LOC) — Bash 3.2 compatible (no associative arrays). Seven check sections, ~39 individual checks total.
  • `SKILL.md` — new `doctor` command section between `validate` and `revamp`.
  • `scripts/bootstrap.sh` — invokes `doctor --quiet` as final step. Skill count 27 → 30 (matches current roster).

What the doctor checks

# Section What
1 Governance files CLAUDE.md, AGENTS.md, .control/policy.yaml exist
2 CLAUDE.md primitives table All P1–P10 rows + correct count header ("Ten irreducible…")
3 AGENTS.md primitive sections `### P1:` through `### P10:`
4 Reflexive Trigger Rules Present for P6, P7, P10 (the reasoning-enforced primitives)
5 policy.yaml blocks `ci_watch:`, `ci_heal:`, `auto_merge:` present
6 Settings hooks wired P1, P2, P8 hook scripts referenced in `.claude/settings.json`
7 Primitive mechanisms Each script/skill reachable on disk

Modes

  • default — full passes/gaps report with `→ fix:` hints; exit 0 (always non-blocking)
  • `--quiet` — only show gaps (used by bootstrap; minimal output when healthy)
  • `--strict` — exit 1 on any gap (CI mode)

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

  • primitive count header off (expected 'Ten irreducible'; saw 'Nine irreducible')
  • P10 row missing in primitives table
  • AGENTS.md missing '### P10: Worktree Hygiene' section
  • P10 section in AGENTS.md missing 'Reflexive Trigger Rule' subsection
    ```

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:

  1. workspace#42 (governance) merges first — adds P10 to CLAUDE.md/AGENTS.md
  2. bstack#this merges second — doctor is now satisfied by the new governance
  3. `npx skills update -g` propagates the new bstack to existing installs

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added a new doctor command to verify governance compliance and contract requirements across your workspace.
    • Bootstrap process now automatically runs doctor verification as the final step.
    • Generates comprehensive validation reports identifying gaps in governance setup.
    • Provides actionable fix guidance for identified gaps.
    • Supports quiet and strict CI modes for different workflow needs.

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>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 5, 2026

📝 Walkthrough

Walkthrough

This PR introduces a new doctor command that validates governance files (CLAUDE.md, AGENTS.md, .control/policy.yaml, .claude/settings.json) and primitive mechanisms against workspace contract requirements. The doctor script is integrated into bootstrap as a final verification step and documented in the command reference.

Changes

Governance Validation Feature

Layer / File(s) Summary
Documentation
SKILL.md
New doctor command documented under Commands section, describing validation checks, output modes (--quiet, --strict), and automatic invocation by bootstrap.
Core Implementation
scripts/doctor.sh
Complete validation script with helpers (ok(), gap(), section()). Performs seven sequential checks across governance files presence, CLAUDE.md primitives table structure, AGENTS.md sections P1–P10, reflexive trigger rules, policy.yaml blocks, Claude hook wiring, and on-disk primitive mechanisms. Reports gaps with fixes; exits 0 by default, 1 in strict CI mode.
Bootstrap Integration
scripts/bootstrap.sh
Integrates doctor as final bootstrap step in quiet mode. Updates item count from 27 to 30 and adds conditional execution of doctor.sh if present.

Estimated Code Review Effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 A doctor hops through governance halls,
Checking primitives beyond the walls,
P1 to P10, each gap it finds,
With nudges gentle and fixes kind—
Bootstrap's final guardian, ever keen! 🏥✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat(bstack): add bstack doctor — verify primitive contract' accurately and directly describes the main change: introducing a new bstack doctor command for verifying the primitive contract.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/bstack-doctor

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
scripts/bootstrap.sh (1)

88-88: ⚡ Quick win

Derive total from roster instead of hardcoding 30

Line 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

📥 Commits

Reviewing files that changed from the base of the PR and between 3376bb9 and 530f32e.

📒 Files selected for processing (3)
  • SKILL.md
  • scripts/bootstrap.sh
  • scripts/doctor.sh

Comment thread scripts/doctor.sh
Comment on lines +47 to +49
if [ ! -d "$WORKSPACE/.git" ] && [ ! -d "$WORKSPACE/.control" ]; then
echo "[bstack doctor] workspace not found at $WORKSPACE (set BROOMVA_WORKSPACE)"
exit 0
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

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.

Suggested change
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.

@broomva broomva merged commit 3ac4a0a into main May 5, 2026
1 check passed
@broomva broomva deleted the feat/bstack-doctor branch May 5, 2026 23:05
broomva added a commit that referenced this pull request May 15, 2026
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant