codebyplan 1.13.49 → 1.13.51

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.
Files changed (34) hide show
  1. package/dist/cli.js +447 -14
  2. package/package.json +1 -1
  3. package/templates/agents/cbp-round-executor.md +1 -6
  4. package/templates/agents/cbp-task-planner.md +2 -2
  5. package/templates/hooks/cbp-skill-context-guard.sh +52 -0
  6. package/templates/hooks/cbp-test-hooks.sh +144 -0
  7. package/templates/hooks/hooks.json +9 -0
  8. package/templates/rules/model-invocation-convention.md +40 -0
  9. package/templates/rules/parallel-waves.md +1 -1
  10. package/templates/rules/supabase-branch-lifecycle.md +2 -3
  11. package/templates/rules/task-routing-recommendation.md +1 -1
  12. package/templates/settings.project.base.json +2 -3
  13. package/templates/skills/cbp-build-cc-mode/SKILL.md +1 -1
  14. package/templates/skills/cbp-build-cc-settings/reference/cbp-permission-policy.md +42 -0
  15. package/templates/skills/cbp-checkpoint-create/SKILL.md +1 -0
  16. package/templates/skills/cbp-checkpoint-start/SKILL.md +1 -0
  17. package/templates/skills/cbp-clear-continue/SKILL.md +86 -0
  18. package/templates/skills/cbp-clear-prep/SKILL.md +121 -0
  19. package/templates/skills/cbp-round-start/SKILL.md +1 -1
  20. package/templates/skills/cbp-session-end/SKILL.md +2 -18
  21. package/templates/skills/cbp-session-start/SKILL.md +4 -18
  22. package/templates/skills/cbp-supabase-migrate/SKILL.md +1 -1
  23. package/templates/skills/cbp-task-check/SKILL.md +12 -5
  24. package/templates/skills/cbp-task-complete/SKILL.md +9 -11
  25. package/templates/skills/cbp-task-complete/reference/checkpoint-done-branching.md +14 -21
  26. package/templates/skills/cbp-task-complete/reference/next-step-heuristic.md +4 -6
  27. package/templates/skills/cbp-task-testing/SKILL.md +9 -14
  28. package/templates/skills/cbp-frontend-a11y/SKILL.md +0 -108
  29. package/templates/skills/cbp-frontend-a11y/reference/aria-roles-states.md +0 -130
  30. package/templates/skills/cbp-frontend-a11y/reference/contrast-visual.md +0 -122
  31. package/templates/skills/cbp-frontend-a11y/reference/keyboard-patterns.md +0 -154
  32. package/templates/skills/cbp-frontend-a11y/reference/semantic-html.md +0 -111
  33. package/templates/skills/cbp-git-worktree-create/SKILL.md +0 -199
  34. package/templates/skills/cbp-git-worktree-remove/SKILL.md +0 -144
@@ -527,6 +527,150 @@ fi
527
527
 
528
528
  echo ""
529
529
 
530
+ # ===== HOOK SMOKE TESTS — cbp-skill-context-guard =====
531
+ echo "## Hook Smoke Tests — cbp-skill-context-guard (CHK-217)"
532
+
533
+ GUARD_HOOK="$HOOKS_DIR/cbp-skill-context-guard.sh"
534
+ FIXTURES_GUARD="$HOOKS_DIR/__test-fixtures__/cbp-context-window-notify"
535
+
536
+ if [ ! -f "$GUARD_HOOK" ]; then
537
+ test_result "cbp-skill-context-guard.sh present" "passed" "missing"
538
+ else
539
+
540
+ # Case 1: over-threshold + cbp-round-execute (heavy) → permissionDecision=deny
541
+ STDIN=$(jq -n \
542
+ --arg t "$FIXTURES_GUARD/over-threshold.jsonl" \
543
+ --arg s "cbp-round-execute" \
544
+ '{transcript_path:$t,tool_input:{skill:$s}}')
545
+ OUTPUT=$(echo "$STDIN" | CBP_CONTEXT_WARN_TOKENS=200000 bash "$GUARD_HOOK" 2>/dev/null)
546
+ EXIT_CODE=$?
547
+ if [ "$EXIT_CODE" = "0" ] \
548
+ && echo "$OUTPUT" | jq -e '.hookSpecificOutput.permissionDecision == "deny"' >/dev/null 2>&1; then
549
+ test_result "cbp-skill-context-guard.sh over-threshold + cbp-round-execute → deny" "passed" "passed"
550
+ else
551
+ test_result "cbp-skill-context-guard.sh over-threshold + cbp-round-execute → deny" "passed" "failed (exit=$EXIT_CODE output=$(echo "$OUTPUT" | head -c 80))"
552
+ fi
553
+
554
+ # Case 2: over-threshold + cbp-clear-prep (exempt) → empty stdout, exit 0
555
+ STDIN=$(jq -n \
556
+ --arg t "$FIXTURES_GUARD/over-threshold.jsonl" \
557
+ --arg s "cbp-clear-prep" \
558
+ '{transcript_path:$t,tool_input:{skill:$s}}')
559
+ OUTPUT=$(echo "$STDIN" | CBP_CONTEXT_WARN_TOKENS=200000 bash "$GUARD_HOOK" 2>/dev/null)
560
+ EXIT_CODE=$?
561
+ if [ "$EXIT_CODE" = "0" ] && [ -z "$OUTPUT" ]; then
562
+ test_result "cbp-skill-context-guard.sh over-threshold + cbp-clear-prep (exempt) → empty stdout" "passed" "passed"
563
+ else
564
+ test_result "cbp-skill-context-guard.sh over-threshold + cbp-clear-prep (exempt) → empty stdout" "passed" "failed (exit=$EXIT_CODE)"
565
+ fi
566
+
567
+ # Case 3: over-threshold + cbp-clear-continue (exempt) → empty stdout, exit 0
568
+ STDIN=$(jq -n \
569
+ --arg t "$FIXTURES_GUARD/over-threshold.jsonl" \
570
+ --arg s "cbp-clear-continue" \
571
+ '{transcript_path:$t,tool_input:{skill:$s}}')
572
+ OUTPUT=$(echo "$STDIN" | CBP_CONTEXT_WARN_TOKENS=200000 bash "$GUARD_HOOK" 2>/dev/null)
573
+ EXIT_CODE=$?
574
+ if [ "$EXIT_CODE" = "0" ] && [ -z "$OUTPUT" ]; then
575
+ test_result "cbp-skill-context-guard.sh over-threshold + cbp-clear-continue (exempt) → empty stdout" "passed" "passed"
576
+ else
577
+ test_result "cbp-skill-context-guard.sh over-threshold + cbp-clear-continue (exempt) → empty stdout" "passed" "failed (exit=$EXIT_CODE)"
578
+ fi
579
+
580
+ # Case 4: under-threshold + cbp-round-execute → empty stdout, exit 0
581
+ STDIN=$(jq -n \
582
+ --arg t "$FIXTURES_GUARD/under-threshold.jsonl" \
583
+ --arg s "cbp-round-execute" \
584
+ '{transcript_path:$t,tool_input:{skill:$s}}')
585
+ OUTPUT=$(echo "$STDIN" | CBP_CONTEXT_WARN_TOKENS=200000 bash "$GUARD_HOOK" 2>/dev/null)
586
+ EXIT_CODE=$?
587
+ if [ "$EXIT_CODE" = "0" ] && [ -z "$OUTPUT" ]; then
588
+ test_result "cbp-skill-context-guard.sh under-threshold + cbp-round-execute → empty stdout" "passed" "passed"
589
+ else
590
+ test_result "cbp-skill-context-guard.sh under-threshold + cbp-round-execute → empty stdout" "passed" "failed (exit=$EXIT_CODE)"
591
+ fi
592
+
593
+ # Case 5: empty skill_name → empty stdout, exit 0
594
+ STDIN=$(jq -n \
595
+ --arg t "$FIXTURES_GUARD/over-threshold.jsonl" \
596
+ '{transcript_path:$t,tool_input:{}}')
597
+ OUTPUT=$(echo "$STDIN" | CBP_CONTEXT_WARN_TOKENS=200000 bash "$GUARD_HOOK" 2>/dev/null)
598
+ EXIT_CODE=$?
599
+ if [ "$EXIT_CODE" = "0" ] && [ -z "$OUTPUT" ]; then
600
+ test_result "cbp-skill-context-guard.sh empty skill_name → empty stdout" "passed" "passed"
601
+ else
602
+ test_result "cbp-skill-context-guard.sh empty skill_name → empty stdout" "passed" "failed (exit=$EXIT_CODE)"
603
+ fi
604
+
605
+ # Case 6: missing transcript_path → empty stdout, exit 0 (fast-path)
606
+ STDIN=$(jq -n --arg s "cbp-round-execute" '{tool_input:{skill:$s}}')
607
+ OUTPUT=$(echo "$STDIN" | CBP_CONTEXT_WARN_TOKENS=200000 bash "$GUARD_HOOK" 2>/dev/null)
608
+ EXIT_CODE=$?
609
+ if [ "$EXIT_CODE" = "0" ] && [ -z "$OUTPUT" ]; then
610
+ test_result "cbp-skill-context-guard.sh missing transcript_path → empty stdout" "passed" "passed"
611
+ else
612
+ test_result "cbp-skill-context-guard.sh missing transcript_path → empty stdout" "passed" "failed (exit=$EXIT_CODE)"
613
+ fi
614
+
615
+ fi
616
+
617
+ # ===== STRUCTURAL ASSERTIONS — cbp-clear-* skills (CHK-217) =====
618
+ echo ""
619
+ echo "## Structural Assertions — cbp-clear-* skills (CHK-217)"
620
+
621
+ # cbp-clear-prep/SKILL.md: scope: org-shared + references handoff.md
622
+ CLEAR_PREP_SKILL="$(dirname "$HOOKS_DIR")/skills/cbp-clear-prep/SKILL.md"
623
+ if [ -f "$CLEAR_PREP_SKILL" ]; then
624
+ if grep -q 'scope: org-shared' "$CLEAR_PREP_SKILL"; then
625
+ test_result "cbp-clear-prep/SKILL.md has scope: org-shared" "passed" "passed"
626
+ else
627
+ test_result "cbp-clear-prep/SKILL.md has scope: org-shared" "passed" "missing"
628
+ fi
629
+ if grep -q 'handoff\.md' "$CLEAR_PREP_SKILL"; then
630
+ test_result "cbp-clear-prep/SKILL.md references handoff.md" "passed" "passed"
631
+ else
632
+ test_result "cbp-clear-prep/SKILL.md references handoff.md" "passed" "missing"
633
+ fi
634
+ else
635
+ test_result "cbp-clear-prep/SKILL.md structural checks (file absent — skipped)" "passed" "passed"
636
+ fi
637
+
638
+ # cbp-clear-continue/SKILL.md: scope: org-shared + references handoff.md + has rm of handoff
639
+ CLEAR_CONTINUE_SKILL="$(dirname "$HOOKS_DIR")/skills/cbp-clear-continue/SKILL.md"
640
+ if [ -f "$CLEAR_CONTINUE_SKILL" ]; then
641
+ if grep -q 'scope: org-shared' "$CLEAR_CONTINUE_SKILL"; then
642
+ test_result "cbp-clear-continue/SKILL.md has scope: org-shared" "passed" "passed"
643
+ else
644
+ test_result "cbp-clear-continue/SKILL.md has scope: org-shared" "passed" "missing"
645
+ fi
646
+ if grep -q 'handoff\.md' "$CLEAR_CONTINUE_SKILL"; then
647
+ test_result "cbp-clear-continue/SKILL.md references handoff.md" "passed" "passed"
648
+ else
649
+ test_result "cbp-clear-continue/SKILL.md references handoff.md" "passed" "missing"
650
+ fi
651
+ if grep -Eq 'rm -f.*handoff' "$CLEAR_CONTINUE_SKILL"; then
652
+ test_result "cbp-clear-continue/SKILL.md has rm -f of handoff.md" "passed" "passed"
653
+ else
654
+ test_result "cbp-clear-continue/SKILL.md has rm -f of handoff.md" "passed" "missing"
655
+ fi
656
+ else
657
+ test_result "cbp-clear-continue/SKILL.md structural checks (file absent — skipped)" "passed" "passed"
658
+ fi
659
+
660
+ # .gitignore contains .codebyplan/clear/
661
+ REPO_GITIGNORE="${CLAUDE_PROJECT_DIR:-}/.gitignore"
662
+ if [ -n "${CLAUDE_PROJECT_DIR:-}" ] && [ -f "$REPO_GITIGNORE" ]; then
663
+ if grep -q '\.codebyplan/clear/' "$REPO_GITIGNORE"; then
664
+ test_result ".gitignore contains .codebyplan/clear/" "passed" "passed"
665
+ else
666
+ test_result ".gitignore contains .codebyplan/clear/" "passed" "missing"
667
+ fi
668
+ else
669
+ test_result ".gitignore check skipped (CLAUDE_PROJECT_DIR unset or no .gitignore)" "passed" "passed"
670
+ fi
671
+
672
+ echo ""
673
+
530
674
  # ===== SUMMARY =====
531
675
  echo "=== TEST SUMMARY ==="
532
676
  echo -e "Passed: ${GREEN}$PASSED${NC}"
@@ -52,6 +52,15 @@
52
52
  }
53
53
  ]
54
54
  },
55
+ {
56
+ "matcher": "Skill",
57
+ "hooks": [
58
+ {
59
+ "type": "command",
60
+ "command": "bash ${CLAUDE_PLUGIN_ROOT}/hooks/cbp-skill-context-guard.sh"
61
+ }
62
+ ]
63
+ },
55
64
  {
56
65
  "matcher": "mcp__codebyplan__(update_task|complete_task|update_checkpoint|create_checkpoint|create_task)",
57
66
  "hooks": [
@@ -0,0 +1,40 @@
1
+ # Model Invocation Convention
2
+
3
+ CBP skills are **model-invocable by default**. Authors must omit `disable-model-invocation` unless
4
+ a skill is strictly user-only (i.e. it must never auto-trigger from another skill).
5
+
6
+ ## Default: omit `disable-model-invocation`
7
+
8
+ The absence of `disable-model-invocation` (or `disable-model-invocation: false`) is the normal
9
+ state. It allows the skill to be auto-triggered via the Skill tool from within other skills —
10
+ which is how the auto-trigger close-out flow works (e.g. `cbp-task-check` → `cbp-task-testing`,
11
+ `cbp-task-testing` → `cbp-task-complete`).
12
+
13
+ ## The sole exception: `cbp-round-complete`
14
+
15
+ `cbp-round-complete` sets `disable-model-invocation: true`. It is the permission-gated round
16
+ finalizer: the user must explicitly run it after their own `git add` selections, so it must
17
+ never auto-fire from within another skill. The `ask`-tier permission prompt on
18
+ `Skill(cbp-round-complete)` is a secondary gate on top of this; the frontmatter flag is the
19
+ primary model-invocation block.
20
+
21
+ No other skill in the CBP framework sets this flag. Do NOT add it to new skills without a
22
+ clear "user-only" rationale.
23
+
24
+ ## Human gates for auto-triggering skills
25
+
26
+ For auto-trigger skills, the human checkpoint is expressed via two complementary mechanisms —
27
+ not via `disable-model-invocation`:
28
+
29
+ 1. **`ask`-tier permission entry** in `settings.json` — the harness permission prompt is the
30
+ lightweight confirm gate. Skills in `ask` auto-fire silently ONLY after the user confirms.
31
+ 2. **Routing prose** inside the triggering skill — states explicitly which skill fires next and
32
+ under what condition, so the intent is auditable and overridable.
33
+
34
+ See `.claude/skills/cbp-build-cc-settings/reference/cbp-permission-policy.md` for the full
35
+ `allow` vs `ask` split and the auto-trigger + 200K context-guard model.
36
+
37
+ ## Related
38
+
39
+ - `rules/scope-vocabulary.md` — scope marker conventions for managed vs user-created files
40
+ - `cbp-build-cc-settings/reference/cbp-permission-policy.md` — allow/ask tiers
@@ -33,7 +33,7 @@ Each entry in `plan.waves[]` carries these fields (source: `.claude/agents/cbp-t
33
33
  - Above 15: apply the proximity-split algorithm below.
34
34
  - Sole exception — trivially small plans are exempt from the lower bound: a plan with fewer than 3 total files uses one single wave, and a single-app plan with ≤5 total files MAY skip decomposition entirely (one wave, or `waves[]` omitted — see `cbp-task-planner` Phase 5.6). Zero waves (omitted `waves[]`) trivially satisfies this invariant.
35
35
 
36
- **(IV) UI skill preloads** — for each wave whose `files[]` contains UI-bearing paths (`*.tsx`, `*.jsx`, `*.scss`, etc.), add `"frontend-design"` and `"frontend-a11y"` to `skill_preloads[]` in that order (source: `.claude/agents/cbp-task-planner.md` Phase 5.6 step "Populate `skill_preloads[]`").
36
+ **(IV) UI skill preloads** — for each wave whose `files[]` contains UI-bearing paths (`*.tsx`, `*.jsx`, `*.scss`, etc.), add `"frontend-design"` to `skill_preloads[]` (source: `.claude/agents/cbp-task-planner.md` Phase 5.6 step "Populate `skill_preloads[]`").
37
37
 
38
38
  ## Proximity-Split Algorithm
39
39
 
@@ -7,7 +7,6 @@ paths:
7
7
  - ".claude/skills/cbp-supabase-migrate/**"
8
8
  - ".claude/skills/cbp-supabase-branch-check/**"
9
9
  - ".claude/skills/cbp-checkpoint-end/**"
10
- - ".claude/skills/cbp-git-worktree-remove/**"
11
10
  - ".claude/skills/cbp-ship-main/**"
12
11
  - ".claude/skills/cbp-standalone-task-complete/**"
13
12
  ---
@@ -48,7 +47,7 @@ The Supabase branch is removed wherever the git branch is deleted:
48
47
  | Skill | Trigger |
49
48
  |---|---|
50
49
  | `cbp-checkpoint-end` | stale-branch cleanup + current feat-branch delete on ship |
51
- | `cbp-git-worktree-remove` | worktree teardown removes the coupled Supabase branch |
50
+ | `codebyplan worktree remove CHK-NNN` | worktree teardown removes the coupled Supabase branch |
52
51
  | `cbp-ship-main` | `branch_deleted` event after PR merge |
53
52
  | `cbp-standalone-task-complete` | `branch_deleted` event after standalone PR merge (Step 7.3) |
54
53
 
@@ -94,7 +93,7 @@ or auto-created by the GitHub integration — both paths use the same branch nam
94
93
  | Role | Skill |
95
94
  |---|---|
96
95
  | Create (lazy) | `cbp-supabase-migrate` (Step 2.3) |
97
- | Delete | `cbp-checkpoint-end`, `cbp-standalone-task-complete`, `cbp-git-worktree-remove`, `cbp-ship-main` |
96
+ | Delete | `cbp-checkpoint-end`, `cbp-standalone-task-complete`, `codebyplan worktree remove`, `cbp-ship-main` |
98
97
  | PR gate | `cbp-supabase-branch-check` |
99
98
 
100
99
  Each skill in the Skill Map above carries an inline back-reference to this rule at its create or teardown step.
@@ -45,7 +45,7 @@ After task completion, routes use single-directive form (never A/B/C menus):
45
45
 
46
46
  **Checkpoint-bound task complete:**
47
47
  - More tasks in checkpoint → auto-triggers next task (same context)
48
- - Last task in checkpoint → `Next: /clear, then /cbp-checkpoint-check`
48
+ - Last task in checkpoint → auto-triggers `cbp-checkpoint-check` (ask-tier permission prompt is the human gate; the 200K context guard handles oversized contexts)
49
49
 
50
50
  **Standalone task complete:**
51
51
  - Always → `Next: /cbp-session-end` (or `/cbp-standalone-task-create` for new work)
@@ -116,14 +116,13 @@
116
116
  "Skill(cbp-build-cc-skill)",
117
117
  "Skill(cbp-checkpoint-plan)",
118
118
  "Skill(cbp-checkpoint-update)",
119
- "Skill(cbp-frontend-a11y)",
119
+ "Skill(cbp-clear-continue)",
120
+ "Skill(cbp-clear-prep)",
120
121
  "Skill(cbp-frontend-design)",
121
122
  "Skill(cbp-frontend-ui)",
122
123
  "Skill(cbp-frontend-ux)",
123
124
  "Skill(cbp-git-branch-feat-create)",
124
125
  "Skill(cbp-git-commit)",
125
- "Skill(cbp-git-worktree-create)",
126
- "Skill(cbp-git-worktree-remove)",
127
126
  "Skill(cbp-map-architecture)",
128
127
  "Skill(cbp-merge-main)",
129
128
  "Skill(cbp-refresh-arch-map)",
@@ -32,7 +32,7 @@ Omit `model:` entirely (inherit the session model). Set `effort:` per the skill'
32
32
  | `xhigh` | deep authoring / planning / orchestration (most skills) | build-cc-*, checkpoint-check/end/plan, round-start/input/execute, task-create/start/complete/testing, standalone-task-*, frontend-*, ship, ship-configure, supabase-*, setup-e2e/eslint, session-end |
33
33
  | `high` | summary / orchestration, lighter than xhigh | checkpoint-create, checkpoint-start, checkpoint-update, round-end, task-check, standalone-task-check, ship-main, merge-main |
34
34
  | `medium` | moderate, scoped sync work | refresh-infra |
35
- | `low` | pure mechanical / dispatch / templated work | checkpoint-complete, round-check, round-complete, round-update, todo, session-start, git-commit, git-branch-feat-create, git-worktree-create, git-worktree-remove |
35
+ | `low` | pure mechanical / dispatch / templated work | checkpoint-complete, round-check, round-complete, round-update, todo, session-start, git-commit, git-branch-feat-create |
36
36
 
37
37
  A skill that carries a `model:` line is a **gap** — remove it unless a deliberate, documented exception is recorded here (currently none).
38
38
 
@@ -45,6 +45,48 @@ The pre-existing dangerous-`rm -rf` blocks. This policy does not alter `deny` se
45
45
 
46
46
  When you add a skill / MCP tool / CLI subcommand, add its matching rule (`Skill(<name>)`, `mcp__codebyplan__<name>`, or `Bash(codebyplan <sub>:*)` + `Bash(npx codebyplan <sub>:*)`) to `allow` or `ask` in `templates/settings.project.base.json` — and mirror it into any dogfooding `.claude/settings.json`.
47
47
 
48
+ ## Auto-trigger + allow/ask gating model
49
+
50
+ The CBP close-out flow uses **auto-triggers** instead of manual "Next: /cbp-X" directives.
51
+ A skill invokes the next skill via the Skill tool at the appropriate routing branch.
52
+
53
+ ### How the human gate works
54
+
55
+ - **`allow`-tier** skill: the harness auto-fires it silently when the triggering skill invokes it.
56
+ No permission prompt. Use for safe, routine-flow skills (e.g. `cbp-task-testing`,
57
+ `cbp-round-input`) where the trigger condition already encodes the human intent.
58
+ - **`ask`-tier** skill: the harness pauses and shows a permission prompt before the skill runs.
59
+ **That prompt IS the human gate** — it replaces the old "Next: /cbp-X, run it yourself"
60
+ manual directive. Use for lifecycle/state-transition skills (e.g. `cbp-task-complete`,
61
+ `cbp-checkpoint-check`) where a deliberate confirmation is still desirable.
62
+
63
+ This means:
64
+ - A skill in `allow` that is auto-triggered fires silently — do NOT claim "the ask-tier prompt
65
+ is the gate" for it in routing prose.
66
+ - A skill in `ask` that is auto-triggered shows a permission prompt — that prompt is the gate;
67
+ say so in the routing prose.
68
+
69
+ ### The 200K context guard
70
+
71
+ The `cbp-skill-context-guard.sh` PreToolUse hook denies heavy close-out skills when the
72
+ context window exceeds `CBP_CONTEXT_WARN_TOKENS` (default 200 000 tokens). The heavy allowlist
73
+ is: `cbp-round-execute`, `cbp-task-testing`, `cbp-standalone-task-testing`,
74
+ `cbp-checkpoint-check`, `cbp-checkpoint-end`.
75
+
76
+ When the guard fires, it directs the model to run `/cbp-clear-prep` instead. The flow is:
77
+ `cbp-clear-prep` (captures a handoff) → `/clear` (user command) → `cbp-clear-continue`
78
+ (re-invokes the blocked skill in the fresh context).
79
+
80
+ `cbp-clear-prep` and `cbp-clear-continue` are **excluded** from the guard's allowlist so they
81
+ always run regardless of context size.
82
+
83
+ Routing prose in triggering skills should NOT mandate an unconditional `/clear` before a heavy
84
+ skill — the guard handles oversized contexts automatically. Drop "Run /clear first" directives
85
+ from auto-trigger paths; only note the guard mechanism so the author understands when it fires.
86
+
87
+ See `rules/model-invocation-convention.md` for the `disable-model-invocation` convention —
88
+ authors must omit it on all skills except `cbp-round-complete`.
89
+
48
90
  ## Scope
49
91
 
50
92
  `scope: org-shared` — CBP-framework infrastructure that lands identically in every consuming repo via the `codebyplan` package.
@@ -113,6 +113,7 @@ Persist the branch via `codebyplan checkpoint update --id <checkpoint-id> --bran
113
113
 
114
114
  **CHK-NNN**: [title] • **Deadline**: [date] • **Branch**: feat/CHK-NNN-slug
115
115
  **Claim**: [claimed by this worktree / left open]
116
+ **Worktree**: `npx codebyplan worktree add CHK-{NNN}`
116
117
 
117
118
  Now planning CHK-NNN… handing off to /cbp-checkpoint-plan.
118
119
  ```
@@ -72,6 +72,7 @@ Show a one-line confirmation before routing:
72
72
 
73
73
  **CHK-NNN**: [title] • **Status**: active • **Claimed by**: [worktree or "open"]
74
74
  **Next task**: TASK-[N] — [title]
75
+ **Worktree**: `npx codebyplan worktree add CHK-{NNN}`
75
76
  ```
76
77
 
77
78
  ## Integration
@@ -0,0 +1,86 @@
1
+ ---
2
+ scope: org-shared
3
+ name: cbp-clear-continue
4
+ description: Resume work after /clear by reading .codebyplan/clear/handoff.md and re-invoking the previously-blocked heavy skill. Reports a friendly error if no handoff file exists.
5
+ effort: xhigh
6
+ ---
7
+
8
+ # cbp-clear-continue
9
+
10
+ Resume a blocked heavy skill after a `/clear`. Reads `.codebyplan/clear/handoff.md`, restores
11
+ task/round context into this fresh session, re-invokes the blocked skill, then deletes the
12
+ handoff file so a stale snapshot never misleads a future session.
13
+
14
+ ## When Used
15
+
16
+ - After running `/clear` following a `/cbp-clear-prep` capture
17
+ - The user is ready to re-run the heavy skill (cbp-round-execute, cbp-task-testing,
18
+ cbp-standalone-task-testing, cbp-checkpoint-check, cbp-checkpoint-end) that was denied
19
+
20
+ ## Instructions
21
+
22
+ ### Step 1 — Read the handoff
23
+
24
+ Read `.codebyplan/clear/handoff.md`.
25
+
26
+ If the file is absent: output the following and STOP — do not attempt to infer state.
27
+
28
+ ```
29
+ No handoff found at .codebyplan/clear/handoff.md — nothing to continue.
30
+ Use /cbp-todo to find the next action.
31
+ ```
32
+
33
+ ### Step 2 — Restore context
34
+
35
+ Parse the handoff fields:
36
+ - `checkpoint_number`, `task_number`, `round_number`
37
+ - `blocked_skill` — the skill that was denied
38
+ - `next_action` — the exact skill invocation to re-run (with args)
39
+ - `in_flight_notes` — any in-progress state worth restoring
40
+
41
+ Output a brief context summary to orient the fresh session:
42
+
43
+ ```
44
+ Resuming from handoff:
45
+ CHK-<N> TASK-<N> R<N>
46
+ Blocked skill: /<blocked-skill>
47
+ Next action: /<next-action>
48
+ ```
49
+
50
+ ### Step 3 — Delete the handoff BEFORE re-invoking
51
+
52
+ Delete `.codebyplan/clear/handoff.md` once its contents have been read and displayed:
53
+
54
+ ```bash
55
+ rm -f .codebyplan/clear/handoff.md
56
+ ```
57
+
58
+ A stale handoff must not mislead a later session. Delete it here, before the skill runs,
59
+ so even if the skill fails the handoff is gone and the user starts fresh next time.
60
+
61
+ ### Step 4 — Re-invoke the blocked skill
62
+
63
+ Invoke the skill from `next_action` via the Skill tool, passing any recorded arguments.
64
+
65
+ Example: if `next_action` is `/cbp-round-execute 217-2-1`, invoke `Skill(cbp-round-execute)`
66
+ with args `217-2-1`.
67
+
68
+ If the context window is STILL above threshold after `/clear` (unusual — compact may help),
69
+ the guard will deny again. Follow the same cycle: `/cbp-clear-prep` → `/clear` →
70
+ `/cbp-clear-continue`.
71
+
72
+ ## Key Rules
73
+
74
+ - Delete `.codebyplan/clear/handoff.md` in Step 3 BEFORE invoking the next skill
75
+ - If the handoff is absent, surface the friendly error and stop — never infer state from scratch
76
+ - Re-invoke the EXACT skill and arguments from `next_action` — do not substitute or guess
77
+ - `.codebyplan/clear/` is gitignored — never commit handoff.md
78
+
79
+ ## Integration
80
+
81
+ - **Invoked by**: user after `/clear` following `/cbp-clear-prep`
82
+ - **Reads**: `.codebyplan/clear/handoff.md`
83
+ - **Deletes**: `.codebyplan/clear/handoff.md` (Step 3, before resuming)
84
+ - **Then invokes**: the skill from `next_action` via Skill tool
85
+ - **Companion**: `.claude/skills/cbp-clear-prep/SKILL.md` writes the handoff
86
+ - **Guard hook**: `.claude/hooks/cbp-skill-context-guard.sh`
@@ -0,0 +1,121 @@
1
+ ---
2
+ scope: org-shared
3
+ name: cbp-clear-prep
4
+ description: Capture a clear-context handoff when the context window is too large to run a heavy skill. Reads active task/round state, writes .codebyplan/clear/handoff.md, then instructs the user to run /clear and /cbp-clear-continue to resume.
5
+ argument-hint: "[blocked-skill]"
6
+ effort: xhigh
7
+ ---
8
+
9
+ # cbp-clear-prep
10
+
11
+ Capture a handoff snapshot before clearing context. Invoked when the `cbp-skill-context-guard`
12
+ PreToolUse hook denies a heavy skill (cbp-round-execute, cbp-task-testing,
13
+ cbp-standalone-task-testing, cbp-checkpoint-check, cbp-checkpoint-end) because the context
14
+ window exceeds the configured threshold.
15
+
16
+ ## When Used
17
+
18
+ - The hook deny message says "Run /cbp-clear-prep now to capture a handoff"
19
+ - A heavy skill was just blocked by the context guard
20
+ - The user wants to preserve current task/round state before running `/clear`
21
+
22
+ ## Instructions
23
+
24
+ ### Step 1 — Identify the blocked skill
25
+
26
+ Check `$ARGUMENTS` first. If empty, identify the blocked skill from the recent guard deny message
27
+ in context — it will be one of: `cbp-round-execute`, `cbp-task-testing`,
28
+ `cbp-standalone-task-testing`, `cbp-checkpoint-check`, `cbp-checkpoint-end`.
29
+
30
+ ### Step 2 — Resolve active task and round (local-first)
31
+
32
+ 1. Read `.codebyplan/state/session/current.json` to find the active task_id and checkpoint_id.
33
+ 2. Read `.codebyplan/state/checkpoints/<checkpoint_id>/tasks/<task_id>.json` for task details.
34
+ 3. Read the latest round file in `.codebyplan/state/checkpoints/<checkpoint_id>/tasks/<task_id>/rounds/`.
35
+ 4. On miss: run `npx codebyplan sync` once and re-read.
36
+ 5. Break-glass if state dir is absent: call `mcp__codebyplan__get_current_task` and
37
+ `mcp__codebyplan__get_rounds`.
38
+
39
+ Capture: `checkpoint_id`, `checkpoint_number`, `task_id`, `task_number`, `round_id`,
40
+ `round_number`. If no active task is found, set all to `unknown` and note the gap.
41
+
42
+ ### Step 3 — Identify the next action to resume
43
+
44
+ From context, determine:
45
+ - The exact skill the user was trying to invoke (blocked skill from Step 1)
46
+ - Any arguments it was called with (e.g. `cbp-round-execute` args: `217-2-1`)
47
+ - Any relevant in-flight state (round goal, step in progress, pending decisions)
48
+
49
+ ### Step 4 — Write the handoff file
50
+
51
+ Create the directory and write `.codebyplan/clear/handoff.md`:
52
+
53
+ ```bash
54
+ mkdir -p .codebyplan/clear
55
+ ```
56
+
57
+ File content format:
58
+
59
+ ```
60
+ # CBP Clear Handoff
61
+
62
+ ## Active Context
63
+
64
+ checkpoint_id: <id or unknown>
65
+ checkpoint_number: CHK-<N or unknown>
66
+ task_id: <id or unknown>
67
+ task_number: TASK-<N or unknown>
68
+ round_id: <id or unknown>
69
+ round_number: R<N or unknown>
70
+
71
+ ## Blocked Skill
72
+
73
+ blocked_skill: <skill-name>
74
+
75
+ ## Next Action
76
+
77
+ next_action: /<skill-name> <args if any>
78
+
79
+ ## In-Flight Notes
80
+
81
+ <any relevant state — round goal, current step, pending decisions, uncommitted work>
82
+
83
+ ## Resume Instructions
84
+
85
+ After /clear, run: /cbp-clear-continue
86
+ ```
87
+
88
+ ### Step 5 — Instruct the user
89
+
90
+ Output exactly this summary (fill in the real values):
91
+
92
+ ```
93
+ Handoff captured at .codebyplan/clear/handoff.md
94
+
95
+ Active context: CHK-<N> TASK-<N> R<N>
96
+ Blocked skill: /<blocked-skill>
97
+ Resumes with: /<next-action>
98
+
99
+ Next steps:
100
+ 1. Run /clear to free context
101
+ 2. Run /cbp-clear-continue to resume
102
+ ```
103
+
104
+ Do NOT auto-invoke `/clear` or `/cbp-clear-continue`. This is a directive-only stop.
105
+ The user must run both commands manually.
106
+
107
+ ## Key Rules
108
+
109
+ - Always write `.codebyplan/clear/handoff.md` BEFORE instructing `/clear`
110
+ - Never auto-invoke the blocked skill — the guard denied it to protect context quality
111
+ - If no active task resolves, still write the handoff with available context and note the gap
112
+ - `.codebyplan/clear/` is gitignored — never commit handoff.md
113
+ - Overwrite any existing handoff.md (each prep captures the freshest context)
114
+
115
+ ## Integration
116
+
117
+ - **Invoked when**: `cbp-skill-context-guard` PreToolUse hook emits `permissionDecision: deny`
118
+ - **Writes**: `.codebyplan/clear/handoff.md`
119
+ - **Next**: user runs `/clear`, then `/cbp-clear-continue`
120
+ - **Companion**: `.claude/skills/cbp-clear-continue/SKILL.md` reads `.codebyplan/clear/handoff.md`
121
+ - **Guard hook**: `.claude/hooks/cbp-skill-context-guard.sh` — fires when context > CBP_CONTEXT_WARN_TOKENS (default 200000)
@@ -216,7 +216,7 @@ Present the plan to user:
216
216
  ### Execution Waves
217
217
  | Wave | Agent type | Files | Depends on | Skill preloads |
218
218
  |------|-----------|-------|-----------|----------------|
219
- | web-ui | cbp-round-executor | 7 | — | cbp-frontend-design, cbp-frontend-a11y |
219
+ | web-ui | cbp-round-executor | 7 | — | cbp-frontend-design |
220
220
  | backend-api | cbp-round-executor | 4 | — | — |
221
221
  ```
222
222
 
@@ -74,23 +74,9 @@ Same rule as `/cbp-session-start` Step 5.7 — only commit files that are **not*
74
74
 
75
75
  Non-blocking — session end proceeds either way.
76
76
 
77
- ### Step 1.6: Home-Branch Fast-Forward
78
-
79
- Keep this worktree's **home branch** rooted at the freshest production tip — no prompt, fully non-blocking. Home branches are the folder-named placeholder branches each worktree rests on (e.g. `codebyplan-web`); `feat/*` branches are deliberately skipped — they integrate via `/cbp-merge-main` with QA, never an auto fast-forward.
80
-
81
- Runs after Step 1.5 so any infra commits land first, and before Step 1.7 so the freshness gate's asset update operates on the freshest tree.
82
-
83
- Run `codebyplan session home-ff` and parse the JSON output (`{ result: 'skipped'|'warn'|'fast_forwarded', reason?, warn? }`):
84
-
85
- - **`result === 'skipped'`** (non-home branch or production mismatch): proceed silently.
86
- - **`result === 'warn'`** (fast-forward attempt failed): surface the `warn` field as one line, then proceed silently.
87
- - **`result === 'fast_forwarded'`** (home branch updated): proceed silently.
88
-
89
- Never rebase, reset, force-push, or stash. A non-fast-forwardable home branch is a signal to reconcile manually, not to overwrite.
90
-
91
77
  ### Step 1.7: Package Freshness Gate
92
78
 
93
- Check whether a newer `codebyplan` is published and safe to auto-install on this worktree's current branch, then run the local install + asset update. Runs after the Step 1.6 home-branch fast-forward (so any update lands on the freshest tree) and before Step 2. Fully non-blocking — the guard and skip branches proceed silently; any failure in the install/update commands warns once and continues to Step 2. session-end never halts.
79
+ Check whether a newer `codebyplan` is published and safe to auto-install on this worktree's current branch, then run the local install + asset update. Runs after the Step 1.5 non-task-file commit and before Step 2. Fully non-blocking — the guard and skip branches proceed silently; any failure in the install/update commands warns once and continues to Step 2. session-end never halts.
94
80
 
95
81
  Run `codebyplan session freshness-gate` (WITHOUT `--halt-on-update`; session-end is continue-only) and parse the JSON output (`{ result: 'skipped'|'guarded'|'up_to_date'|'updated'|'error', ... }`):
96
82
 
@@ -110,8 +96,6 @@ Run `codebyplan session freshness-gate` (WITHOUT `--halt-on-update`; session-end
110
96
  On `yes`: `git add` the listed paths only (not the whole directories), then trigger `/cbp-git-commit`. On `no`: skip. On `select`: ask which subset.
111
97
  - Continue to Step 2 — session-end does NOT halt. The update lands in the current worktree on its current branch; main/protected branches and the canonical source repo are already excluded by the `result !== 'guarded'` check above.
112
98
 
113
- **Home branches are intentionally not guarded.** A worktree's folder-named home branch (e.g. `codebyplan-web`) is neither protected/main nor the canonical source, so the freshness gate returns `result !== 'guarded'` there and this gate runs the update exactly as on a feat branch — landing it on whichever branch the worktree currently rests on (the deliberate "update the branch they're on, except main/canonical" behavior).
114
-
115
99
  Non-blocking — session end proceeds regardless of outcome.
116
100
 
117
101
  ### Step 2: Auto-Stop Servers
@@ -149,7 +133,7 @@ You can close this window.
149
133
  ## Integration
150
134
 
151
135
  - **Triggered by**: user invocation (prompted by `/cbp-todo` when no work remains)
152
- - **Reads**: `.codebyplan/repo.json`, `.codebyplan/git.json` (`branch_config.production` for the Step 1.6 home-branch fast-forward); local-first reads (with `npx codebyplan sync` + MCP break-glass): `.codebyplan/state/session/current.json` (Step 1 resolve log), `.codebyplan/state/todos.json` (Step 1.3 handoff snapshot + Step 1.5 active-task lookup), `.codebyplan/state/checkpoints/<id>/tasks/<id>/rounds/` (Step 1.5 task-file resolution); `codebyplan session home-ff` (Step 1.6 home-branch fast-forward); `codebyplan session freshness-gate` (Step 1.7 package-freshness gate, without --halt-on-update); `codebyplan session infra-files --json --task-files <csv>` (Step 1.5 infra-file set math)
136
+ - **Reads**: `.codebyplan/repo.json`; local-first reads (with `npx codebyplan sync` + MCP break-glass): `.codebyplan/state/session/current.json` (Step 1 resolve log), `.codebyplan/state/todos.json` (Step 1.3 handoff snapshot + Step 1.5 active-task lookup), `.codebyplan/state/checkpoints/<id>/tasks/<id>/rounds/` (Step 1.5 task-file resolution); `codebyplan session freshness-gate` (Step 1.7 package-freshness gate, without --halt-on-update); `codebyplan session infra-files --json --task-files <csv>` (Step 1.5 infra-file set math)
153
137
  - **Writes**: `codebyplan session update-log --id <id> ...` (Step 1 finalize — CLI write-through to `.codebyplan/state/session/current.json`; break-glass: MCP `update_session_log`), `codebyplan session create-log` (Step 1 fallback when no log exists; break-glass: MCP `create_session_log`), `codebyplan session update-state --action deactivate` (Step 3 — CLI write-through to `.codebyplan/state/session/state.json`; break-glass: MCP `update_session_state`)
154
138
  - **Spawns**: none
155
139
  - **Triggers**: none at the skill-contract level. Step 1.5 may invoke `/cbp-git-commit` inline on user approval; Step 1.7 may invoke `/cbp-git-commit` on the `result === 'updated'` path (committing changed `.claude/` and `.codebyplan/` paths).