codebyplan 1.5.1 → 1.9.0

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 (211) hide show
  1. package/dist/cli.js +4462 -748
  2. package/package.json +5 -1
  3. package/templates/.gitkeep +0 -0
  4. package/templates/README.md +20 -0
  5. package/templates/agents/cbp-cc-executor.md +213 -0
  6. package/templates/agents/cbp-database-agent.md +229 -0
  7. package/templates/agents/cbp-improve-claude.md +245 -0
  8. package/templates/agents/cbp-improve-round.md +284 -0
  9. package/templates/agents/cbp-mechanical-edits.md +111 -0
  10. package/templates/agents/cbp-research.md +282 -0
  11. package/templates/agents/cbp-round-executor.md +604 -0
  12. package/templates/agents/cbp-security-agent.md +134 -0
  13. package/templates/agents/cbp-task-check.md +213 -0
  14. package/templates/agents/cbp-task-planner.md +582 -0
  15. package/templates/agents/cbp-test-e2e-agent.md +363 -0
  16. package/templates/agents/cbp-testing-qa-agent.md +400 -0
  17. package/templates/context/mcp-docs.md +139 -0
  18. package/templates/hooks/README.md +236 -0
  19. package/templates/hooks/cbp-auto-test-hooks.sh +44 -0
  20. package/templates/hooks/cbp-lint-format-on-edit.sh +159 -0
  21. package/templates/hooks/cbp-maestro-yaml-validate.sh +100 -0
  22. package/templates/hooks/cbp-mcp-migration-guard.sh +32 -0
  23. package/templates/hooks/cbp-mcp-round-sync.sh +79 -0
  24. package/templates/hooks/cbp-mcp-worktree-inject.sh +76 -0
  25. package/templates/hooks/cbp-notify.sh +68 -0
  26. package/templates/hooks/cbp-plugin-dispatch.sh +29 -0
  27. package/templates/hooks/cbp-pre-commit-quality-gate.sh +204 -0
  28. package/templates/hooks/cbp-statusline.sh +347 -0
  29. package/templates/hooks/cbp-subagent-statusline.sh +182 -0
  30. package/templates/hooks/cbp-test-coverage-gate.sh +144 -0
  31. package/templates/hooks/cbp-test-hooks.sh +320 -0
  32. package/templates/hooks/hooks.json +85 -0
  33. package/templates/hooks/validate-context-usage.sh +59 -0
  34. package/templates/hooks/validate-git-commit.sh +78 -0
  35. package/templates/hooks/validate-git-stash-deny.sh +32 -0
  36. package/templates/hooks/validate-structure-lengths.sh +57 -0
  37. package/templates/hooks/validate-structure-lib.sh +104 -0
  38. package/templates/hooks/validate-structure-patterns.sh +54 -0
  39. package/templates/hooks/validate-structure-scope.sh +33 -0
  40. package/templates/hooks/validate-structure-smoke.sh +95 -0
  41. package/templates/hooks/validate-structure-templates.sh +34 -0
  42. package/templates/hooks/validate-structure.sh +69 -0
  43. package/templates/rules/.gitkeep +0 -0
  44. package/templates/rules/README.md +47 -0
  45. package/templates/rules/context-file-loading.md +52 -0
  46. package/templates/rules/scope-vocabulary.md +64 -0
  47. package/templates/rules/todo-backend.md +109 -0
  48. package/templates/settings.project.base.json +55 -0
  49. package/templates/settings.user.base.json +25 -0
  50. package/templates/skills/cbp-build-cc-agent/SKILL.md +139 -0
  51. package/templates/skills/cbp-build-cc-agent/examples/read-only-reviewer.md +32 -0
  52. package/templates/skills/cbp-build-cc-agent/examples/with-hooks.md +41 -0
  53. package/templates/skills/cbp-build-cc-agent/examples/with-skills-preload.md +25 -0
  54. package/templates/skills/cbp-build-cc-agent/reference/cbp-quality.md +153 -0
  55. package/templates/skills/cbp-build-cc-agent/reference/frontmatter-fields.md +37 -0
  56. package/templates/skills/cbp-build-cc-agent/reference/permission-modes.md +18 -0
  57. package/templates/skills/cbp-build-cc-agent/scripts/validate-agent.sh +67 -0
  58. package/templates/skills/cbp-build-cc-agent/templates/agent.md +66 -0
  59. package/templates/skills/cbp-build-cc-claude-file/SKILL.md +178 -0
  60. package/templates/skills/cbp-build-cc-claude-file/examples/minimal-project.md +33 -0
  61. package/templates/skills/cbp-build-cc-claude-file/examples/monorepo-with-imports.md +39 -0
  62. package/templates/skills/cbp-build-cc-claude-file/reference/imports.md +72 -0
  63. package/templates/skills/cbp-build-cc-claude-file/reference/what-belongs.md +39 -0
  64. package/templates/skills/cbp-build-cc-claude-file/templates/project-claude-md.md +48 -0
  65. package/templates/skills/cbp-build-cc-claude-file/templates/user-claude-md.md +22 -0
  66. package/templates/skills/cbp-build-cc-memory/SKILL.md +201 -0
  67. package/templates/skills/cbp-build-cc-memory/examples/feedback-memory.md +11 -0
  68. package/templates/skills/cbp-build-cc-memory/examples/project-memory.md +11 -0
  69. package/templates/skills/cbp-build-cc-memory/examples/reference-memory.md +13 -0
  70. package/templates/skills/cbp-build-cc-memory/examples/user-memory.md +14 -0
  71. package/templates/skills/cbp-build-cc-memory/reference/memory-types.md +59 -0
  72. package/templates/skills/cbp-build-cc-memory/reference/when-to-save.md +62 -0
  73. package/templates/skills/cbp-build-cc-memory/templates/MEMORY-index.md +4 -0
  74. package/templates/skills/cbp-build-cc-memory/templates/memory-entry.md +15 -0
  75. package/templates/skills/cbp-build-cc-mode/SKILL.md +99 -0
  76. package/templates/skills/cbp-build-cc-rule/SKILL.md +176 -0
  77. package/templates/skills/cbp-build-cc-rule/examples/global-rule.md +19 -0
  78. package/templates/skills/cbp-build-cc-rule/examples/scoped-rule.md +41 -0
  79. package/templates/skills/cbp-build-cc-rule/reference/paths-patterns.md +48 -0
  80. package/templates/skills/cbp-build-cc-rule/templates/rule.md +32 -0
  81. package/templates/skills/cbp-build-cc-settings/SKILL.md +220 -0
  82. package/templates/skills/cbp-build-cc-settings/examples/hooks-config.json +64 -0
  83. package/templates/skills/cbp-build-cc-settings/examples/permissions-config.json +34 -0
  84. package/templates/skills/cbp-build-cc-settings/examples/sandbox-config.json +42 -0
  85. package/templates/skills/cbp-build-cc-settings/reference/cbp-conventions.md +104 -0
  86. package/templates/skills/cbp-build-cc-settings/reference/permission-rules.md +61 -0
  87. package/templates/skills/cbp-build-cc-settings/reference/scope-precedence.md +73 -0
  88. package/templates/skills/cbp-build-cc-settings/reference/settings-fields.md +166 -0
  89. package/templates/skills/cbp-build-cc-settings/templates/settings.json +23 -0
  90. package/templates/skills/cbp-build-cc-settings/templates/settings.local.json +10 -0
  91. package/templates/skills/cbp-build-cc-skill/SKILL.md +154 -0
  92. package/templates/skills/cbp-build-cc-skill/examples/dynamic-context.md +31 -0
  93. package/templates/skills/cbp-build-cc-skill/examples/fork-skill.md +22 -0
  94. package/templates/skills/cbp-build-cc-skill/examples/knowledge-skill.md +25 -0
  95. package/templates/skills/cbp-build-cc-skill/examples/task-skill.md +29 -0
  96. package/templates/skills/cbp-build-cc-skill/reference/cbp-quality.md +157 -0
  97. package/templates/skills/cbp-build-cc-skill/reference/frontmatter-fields.md +35 -0
  98. package/templates/skills/cbp-build-cc-skill/reference/string-substitutions.md +60 -0
  99. package/templates/skills/cbp-build-cc-skill/scripts/validate-skill.sh +90 -0
  100. package/templates/skills/cbp-build-cc-skill/templates/skill.md +51 -0
  101. package/templates/skills/cbp-checkpoint-check/SKILL.md +156 -0
  102. package/templates/skills/cbp-checkpoint-complete/SKILL.md +109 -0
  103. package/templates/skills/cbp-checkpoint-create/SKILL.md +116 -0
  104. package/templates/skills/cbp-checkpoint-end/SKILL.md +241 -0
  105. package/templates/skills/cbp-checkpoint-plan/SKILL.md +137 -0
  106. package/templates/skills/cbp-checkpoint-plan/reference/alternative-comparison-template.md +54 -0
  107. package/templates/skills/cbp-checkpoint-plan/reference/dep-decision-rubric.md +50 -0
  108. package/templates/skills/cbp-checkpoint-plan/reference/e2e-discovery-probe.md +57 -0
  109. package/templates/skills/cbp-checkpoint-plan/reference/gap-analysis-playbook.md +47 -0
  110. package/templates/skills/cbp-checkpoint-start/SKILL.md +84 -0
  111. package/templates/skills/cbp-checkpoint-update/SKILL.md +115 -0
  112. package/templates/skills/cbp-frontend-a11y/SKILL.md +109 -0
  113. package/templates/skills/cbp-frontend-a11y/reference/aria-roles-states.md +130 -0
  114. package/templates/skills/cbp-frontend-a11y/reference/contrast-visual.md +122 -0
  115. package/templates/skills/cbp-frontend-a11y/reference/keyboard-patterns.md +154 -0
  116. package/templates/skills/cbp-frontend-a11y/reference/semantic-html.md +111 -0
  117. package/templates/skills/cbp-frontend-design/SKILL.md +145 -0
  118. package/templates/skills/cbp-frontend-design/reference/nextjs-scss.md +118 -0
  119. package/templates/skills/cbp-frontend-design/reference/rn-expo.md +101 -0
  120. package/templates/skills/cbp-frontend-design/reference/tauri-react.md +82 -0
  121. package/templates/skills/cbp-frontend-ui/SKILL.md +262 -0
  122. package/templates/skills/cbp-frontend-ui/reference/ui-label-maps.md +42 -0
  123. package/templates/skills/cbp-frontend-ui/reference/ui-layout-patterns.md +105 -0
  124. package/templates/skills/cbp-frontend-ui/reference/variant-defaults.md +149 -0
  125. package/templates/skills/cbp-frontend-ux/SKILL.md +181 -0
  126. package/templates/skills/cbp-git-branch-feat-create/SKILL.md +115 -0
  127. package/templates/skills/cbp-git-commit/SKILL.md +278 -0
  128. package/templates/skills/cbp-git-worktree-create/SKILL.md +226 -0
  129. package/templates/skills/cbp-git-worktree-remove/SKILL.md +145 -0
  130. package/templates/skills/cbp-merge-main/SKILL.md +228 -0
  131. package/templates/skills/cbp-round-check/SKILL.md +104 -0
  132. package/templates/skills/cbp-round-end/SKILL.md +183 -0
  133. package/templates/skills/cbp-round-end/reference/findings-presentation.md +44 -0
  134. package/templates/skills/cbp-round-end/reference/inline-fallback.md +35 -0
  135. package/templates/skills/cbp-round-execute/SKILL.md +211 -0
  136. package/templates/skills/cbp-round-execute/reference/inline-fallback.md +59 -0
  137. package/templates/skills/cbp-round-input/SKILL.md +165 -0
  138. package/templates/skills/cbp-round-start/SKILL.md +222 -0
  139. package/templates/skills/cbp-round-update/SKILL.md +163 -0
  140. package/templates/skills/cbp-session-end/SKILL.md +187 -0
  141. package/templates/skills/cbp-session-start/SKILL.md +155 -0
  142. package/templates/skills/cbp-ship/SKILL.md +332 -0
  143. package/templates/skills/cbp-ship/reference/changesets-overview.md +120 -0
  144. package/templates/skills/cbp-ship/reference/eas-cli-overview.md +60 -0
  145. package/templates/skills/cbp-ship/reference/gh-cli-overview.md +135 -0
  146. package/templates/skills/cbp-ship/reference/gh-cli-shipment-commands.md +283 -0
  147. package/templates/skills/cbp-ship/reference/npm-publish-monorepo.md +252 -0
  148. package/templates/skills/cbp-ship/reference/npm-publish-oidc-trusted.md +157 -0
  149. package/templates/skills/cbp-ship/reference/npm-publish-overview.md +171 -0
  150. package/templates/skills/cbp-ship/reference/preflight-checklist.md +88 -0
  151. package/templates/skills/cbp-ship/reference/railway-nestjs-deployment.md +169 -0
  152. package/templates/skills/cbp-ship/reference/railway-overview.md +120 -0
  153. package/templates/skills/cbp-ship/reference/railway-troubleshooting.md +168 -0
  154. package/templates/skills/cbp-ship/reference/release-please-overview.md +99 -0
  155. package/templates/skills/cbp-ship/reference/surface-expo-eas.md +155 -0
  156. package/templates/skills/cbp-ship/reference/surface-npm.md +180 -0
  157. package/templates/skills/cbp-ship/reference/surface-railway.md +152 -0
  158. package/templates/skills/cbp-ship/reference/surface-supabase.md +178 -0
  159. package/templates/skills/cbp-ship/reference/surface-tauri.md +138 -0
  160. package/templates/skills/cbp-ship/reference/surface-vercel.md +124 -0
  161. package/templates/skills/cbp-ship/reference/surface-vscode-ext.md +144 -0
  162. package/templates/skills/cbp-ship/reference/surfaces.md +60 -0
  163. package/templates/skills/cbp-ship/reference/testflight-automation.md +215 -0
  164. package/templates/skills/cbp-ship/reference/testflight-internal-vs-external.md +69 -0
  165. package/templates/skills/cbp-ship/reference/testflight-overview.md +98 -0
  166. package/templates/skills/cbp-ship/reference/versioning.md +116 -0
  167. package/templates/skills/cbp-ship/scripts/detect-surfaces.sh +217 -0
  168. package/templates/skills/cbp-ship/scripts/verify-expo-eas.sh +35 -0
  169. package/templates/skills/cbp-ship/scripts/verify-npm.sh +21 -0
  170. package/templates/skills/cbp-ship/scripts/verify-railway.sh +41 -0
  171. package/templates/skills/cbp-ship/scripts/verify-supabase.sh +19 -0
  172. package/templates/skills/cbp-ship/scripts/verify-tauri.sh +24 -0
  173. package/templates/skills/cbp-ship/scripts/verify-vercel.sh +32 -0
  174. package/templates/skills/cbp-ship/scripts/verify-vscode-ext.sh +25 -0
  175. package/templates/skills/cbp-ship/templates/eas.json +66 -0
  176. package/templates/skills/cbp-ship/templates/railway.toml +15 -0
  177. package/templates/skills/cbp-ship/templates/release-please-config.json +17 -0
  178. package/templates/skills/cbp-ship/templates/vercel.json +19 -0
  179. package/templates/skills/cbp-ship/templates/vscodeignore +21 -0
  180. package/templates/skills/cbp-ship/templates/workflow-changesets.yml +41 -0
  181. package/templates/skills/cbp-ship/templates/workflow-eas-submit.yml +53 -0
  182. package/templates/skills/cbp-ship/templates/workflow-npm-publish.yml +36 -0
  183. package/templates/skills/cbp-ship/templates/workflow-release-please.yml +21 -0
  184. package/templates/skills/cbp-ship/templates/workflow-tauri-release.yml +69 -0
  185. package/templates/skills/cbp-ship/templates/workflow-vsce-publish.yml +31 -0
  186. package/templates/skills/cbp-ship-configure/SKILL.md +296 -0
  187. package/templates/skills/cbp-ship-configure/reference/expo-mobile.md +204 -0
  188. package/templates/skills/cbp-ship-configure/reference/npm-package.md +165 -0
  189. package/templates/skills/cbp-ship-configure/reference/railway-backend.md +199 -0
  190. package/templates/skills/cbp-ship-configure/reference/supabase.md +200 -0
  191. package/templates/skills/cbp-ship-configure/reference/tauri-desktop.md +181 -0
  192. package/templates/skills/cbp-ship-configure/reference/vercel.md +117 -0
  193. package/templates/skills/cbp-ship-configure/reference/vscode-ext.md +155 -0
  194. package/templates/skills/cbp-ship-main/SKILL.md +65 -0
  195. package/templates/skills/cbp-supabase-branch-check/SKILL.md +337 -0
  196. package/templates/skills/cbp-supabase-branch-check/reference/dag-steps.md +29 -0
  197. package/templates/skills/cbp-supabase-migrate/SKILL.md +314 -0
  198. package/templates/skills/cbp-supabase-migrate/reference/advisor-triage.md +70 -0
  199. package/templates/skills/cbp-supabase-migrate/reference/cli-fallback.md +87 -0
  200. package/templates/skills/cbp-supabase-migrate/reference/preflight-dry-run.md +58 -0
  201. package/templates/skills/cbp-supabase-setup/SKILL.md +239 -0
  202. package/templates/skills/cbp-supabase-setup/reference/branching-setup.md +121 -0
  203. package/templates/skills/cbp-supabase-setup/reference/cli-fallback.md +109 -0
  204. package/templates/skills/cbp-task-check/SKILL.md +166 -0
  205. package/templates/skills/cbp-task-complete/SKILL.md +206 -0
  206. package/templates/skills/cbp-task-complete/reference/checkpoint-done-branching.md +48 -0
  207. package/templates/skills/cbp-task-complete/reference/next-step-heuristic.md +56 -0
  208. package/templates/skills/cbp-task-create/SKILL.md +167 -0
  209. package/templates/skills/cbp-task-start/SKILL.md +239 -0
  210. package/templates/skills/cbp-task-testing/SKILL.md +277 -0
  211. package/templates/skills/cbp-todo/SKILL.md +111 -0
@@ -0,0 +1,163 @@
1
+ ---
2
+ scope: org-shared
3
+ name: cbp-round-update
4
+ description: Check file approvals, complete round, and route to next step
5
+ argument-hint: [chk-task-round | task-round]
6
+ triggers: [cbp-round-input, cbp-task-check]
7
+ effort: low
8
+ ---
9
+
10
+ # Round Update Command
11
+
12
+ Checks file approval status, completes the round, and routes to next step. NEVER asks the user to git add or stage anything — it only reads current state.
13
+
14
+ ## HARD GATE — Every Step Must Execute
15
+
16
+ Step 2 (sync-approvals CLI) MUST exit 0. If it fails, do NOT proceed to Step 3. Before completing the round, verify:
17
+
18
+ - [ ] `codebyplan round sync-approvals` exited 0
19
+
20
+ If this is false: DO NOT proceed to Step 3.
21
+
22
+ ## Instructions
23
+
24
+ ### Step 1: Parse `$ARGUMENTS`
25
+
26
+ Parse the argument using the canonical chk-task-round notation (see `.claude/rules/notation-consistency.md`):
27
+
28
+ | Shape | Regex | Resolves to |
29
+ |-------|-------|-------------|
30
+ | `{chk}-{task}-{round}` (e.g. `108-1-2`) | `^[0-9]+-[0-9]+-[0-9]+$` | Checkpoint-bound: CHK-{chk} TASK-{task} ROUND-{round} |
31
+ | `{task}-{round}` (e.g. `45-2`) | `^[0-9]+-[0-9]+$` | Standalone: standalone TASK-{task} ROUND-{round} |
32
+ | _(empty)_ | — | Use MCP `get_current_task` / `get_rounds` to find the active task and latest round |
33
+
34
+ Anything else is malformed — surface this error and stop:
35
+
36
+ ```
37
+ round-update: invalid argument `{value}`. Expected:
38
+ 108-1-2 → CHK-108 TASK-1 ROUND-2 (checkpoint-bound)
39
+ 45-2 → standalone TASK-45 ROUND-2
40
+ (empty) → active task and latest round
41
+ ```
42
+
43
+ Error cases: `abc`, `108-`, `-1`, anything with whitespace or non-numeric characters. Note that `108-1` is **valid** here — it resolves to standalone TASK-108 ROUND-1 per the 2-segment task-round form. To target a checkpoint-bound round, use the 3-segment form `108-1-2`.
44
+
45
+ #### Worked examples
46
+
47
+ - `round-update 108-1-2` → CHK-108 TASK-1 ROUND-2
48
+ - `round-update 45-2` → standalone TASK-45 ROUND-2
49
+ - `round-update` (no arg) → active task and latest in-progress round via `get_current_task` + `get_rounds`
50
+ - `round-update abc` → error: malformed
51
+
52
+ ### Step 1.5: Get Current Task and Round
53
+
54
+ Given the parse from Step 1:
55
+
56
+ | Parse | Resolution path |
57
+ |-------|-----------------|
58
+ | `{chk}-{task}-{round}` | MCP `get_checkpoints(repo_id)` → filter `number === {chk}`. MCP `get_tasks(checkpoint_id)` → filter `number === {task}`. MCP `get_rounds(task_id)` → filter `number === {round}`. |
59
+ | `{task}-{round}` | MCP `get_tasks(repo_id, standalone: true)` → filter `number === {task}`. MCP `get_rounds(task_id)` → filter `number === {round}`. |
60
+ | _(empty)_ | MCP `get_current_task(repo_id)` to find active task. MCP `get_rounds(task_id)` to find latest round (in-progress or completed). |
61
+
62
+ If no task found: `No active task. Nothing to update.`
63
+
64
+ ### Step 2: Sync git diff + approvals via CLI
65
+
66
+ Run:
67
+
68
+ ```
69
+ npx codebyplan round sync-approvals --round-id <round_id> --task-id <task_id>
70
+ ```
71
+
72
+ The CLI auto-resolves the worktree id, parses `git status --short`, merges drift + staging + web-UI flag, and writes both round and task.
73
+
74
+ Read the stdout JSON: `{ added, stale_marked, reactivated, total_files }`.
75
+
76
+ If the command exits non-zero, surface the stderr and STOP. Do NOT proceed to Step 3.
77
+
78
+ ### Step 3: Complete Round
79
+
80
+ Calculate duration from `started_at` to now in minutes.
81
+ Use MCP `complete_round(round_id, duration_minutes)`.
82
+
83
+ ### Step 4: Auto-Loop Decision
84
+
85
+ Read the latest round's `improve_round_findings[]` and `testing_qa_output.totals.hard_fail`. If EITHER is non-clean (findings non-empty OR `hard_fail === true`), the auto-loop must spawn the next round automatically.
86
+
87
+ Procedure:
88
+
89
+ 1. Compute `next_index = (round.context.auto_loop_index ?? 0) + 1`.
90
+ 2. **If `next_index > (round.context.auto_loop_cap ?? 5)`**: surface the cap-exhausted prompt via AskUserQuestion (options: extend cap, stop loop / drop into round-input, close task as-is). Persist `round.context.auto_loop_cap_exhausted = { user_choice, decided_at }` and route per choice.
91
+ 3. **Otherwise**: persist `round.context.auto_loop_decision = { spawned_next: true, next_index, decided_at }` on the CURRENT round via `update_round` (audit trail), then auto-trigger `/cbp-round-input` with NO AskUserQuestion. Pass `auto_loop_mode: true`, `auto_loop_index: next_index`, `auto_loop_cap: (prior cap ?? 5)` forward — round-start Step 4 persists them on the new round.
92
+
93
+ If BOTH signals are clean, fall through to Step 5 (exit routing).
94
+
95
+ ### Step 5: Exit Routing
96
+
97
+ **5a: Count files** — Display: `"Files: X total, Y approved, Z pending"`
98
+
99
+ **5b: Route with four branches** (Step 4 already handled the dirty-loop case; Step 5 is the clean-exit path).
100
+
101
+ **Branch D — IF `round.context.round_type === 'survey'` (checked FIRST):**
102
+
103
+ Survey rounds produce no file diff; A/B/C predicates assume `files_changed[]` non-empty. Survey routing is decided by `improve_round_findings[]` instead:
104
+
105
+ - `improve_round_findings[]` non-empty → auto-trigger `/cbp-round-input`
106
+ - `improve_round_findings[]` empty → auto-trigger `/cbp-task-check`
107
+
108
+ Output: `"## Round [N] Complete — Survey Round"` with duration, files=0, findings count, routing message. Skip Branches A/B/C.
109
+
110
+ **Branch A — ELSE IF all files have `user_approved: true`:**
111
+
112
+ ```
113
+ ## Round [N] Complete - All Files Approved
114
+
115
+ **Duration**: [N] minutes
116
+ **Files**: [X] total, [X] approved, 0 pending
117
+ ```
118
+
119
+ Surface AskUserQuestion (clean-exit user-gate):
120
+
121
+ - **(a) close & complete round** → auto-trigger `/cbp-task-check`
122
+ - **(b) start new round** → auto-trigger `/cbp-round-input`
123
+
124
+ Persist `round.context.auto_loop_exit = { staged_count, unstaged_count, route, decided_at }`.
125
+
126
+ **Branch B — ELSE IF unapproved files exist AND every unapproved file has `claude_approved: true` AND `testing_qa_output.totals.hard_fail: false` AND no `improve_round_findings[]`:**
127
+
128
+ The clean-but-unstaged staging-gate case. Mode-dependent:
129
+
130
+ - **Auto-loop exit** (the completed round had `auto_loop_mode === true` on its context AND Step 4 fell through here with BOTH signals clean): surface the Branch A clean-exit user-gate — do NOT auto-trigger `/cbp-round-input`. Branch B's entry condition already requires `no improve_round_findings[]`, so the auto-loop's verbatim-from-findings procedure has no input to formulate requirements from; auto-triggering round-input would loop on an empty input. Persist `round.context.auto_loop_exit.degenerate_empty_findings: true` (degenerate sub-case: no findings to feed round-input, so surface the clean-exit user-gate above instead of auto-triggering).
131
+ - **Manual round**: emit staging-gate prompt and STOP. User stages files (never-git-add rule) and re-invokes; command then falls into Branch A.
132
+
133
+ Manual-mode prompt:
134
+
135
+ ```
136
+ ## Round [N] Complete — Files Pending Staging
137
+
138
+ **Files**: [X] total, [Y] approved, [Z] pending
139
+
140
+ ### Pending (passed all checks; not yet staged):
141
+ - [path]
142
+
143
+ Stage them (`git add <path>`) and re-run `/cbp-round-update` to proceed.
144
+ Waiting for user to stage files.
145
+ ```
146
+
147
+ **Branch C — ELSE (unapproved AND outstanding findings or `claude_approved: false`):**
148
+
149
+ Unreachable in the auto-loop path — Step 4 catches it first. Retained for MANUAL invocation. Output `## Round [N] Complete - [Z] Files Pending` with file counts and list of unapproved paths; auto-trigger `/cbp-round-input`.
150
+
151
+ ## Key Rules
152
+
153
+ - **Step 2 (CLI) must exit 0** — if it fails, STOP. The merge semantics are enforced by the CLI.
154
+ - **Step 4 owns the dirty-loop case**; Step 5 owns the clean-exit case. Step 5 Branch C is for manual invocation only.
155
+ - **NEVER ask user to git add files** — only reads staging status. **NEVER stage files** — Claude does not touch git staging area.
156
+ - Auto-triggered by `/cbp-round-end`, or run manually by user.
157
+
158
+ ## Integration
159
+
160
+ - **Triggered by**: `/cbp-round-end` (auto), or user manually
161
+ - **Reads**: MCP `get_current_task`, `get_rounds`; delegates git+approval sync to `npx codebyplan round sync-approvals`
162
+ - **Writes**: MCP `update_round` (auto_loop_decision / auto_loop_exit / auto_loop_cap_exhausted), `complete_round`; round+task files_changed written by CLI
163
+ - **Triggers**: `/cbp-round-input` (Step 4 dirty-loop spawn; Branch A 'b' choice; Branch B auto-loop-exit; Branch C manual), `/cbp-task-check` (Branch A 'a' choice; Branch D survey-clean), staging-gate stop (Branch B manual mode), cap-exhausted prompt routes from Step 4 (any of the three options)
@@ -0,0 +1,187 @@
1
+ ---
2
+ scope: org-shared
3
+ name: cbp-session-end
4
+ description: End a development session
5
+ effort: xhigh
6
+ ---
7
+
8
+ # Session End Command
9
+
10
+ End the current session. Commits only non-task files — files tied to an unfinished task stay uncommitted so the user finishes them on their terms.
11
+
12
+ ## Instructions
13
+
14
+ ### Step 1: Finalize Session Log
15
+
16
+ Always write a session log for this session — **even if empty**. `/cbp-session-start` opens the log; session-end finalizes it.
17
+
18
+ 1. Resolve the current session log:
19
+ - Preferred: use the log ID held in context from `/cbp-session-start`.
20
+ - Fallback: MCP `get_session_logs` (limit 1, most recent open log for this `repo_id`).
21
+ - If still none found (e.g. session-start was skipped), create one now with MCP `create_session_log`.
22
+ 2. Pull facts from the DB rather than narrating from memory:
23
+ - Rounds added/completed, tasks advanced/completed during this session
24
+ - Decisions, blockers, or discoveries recorded in checkpoint/task context
25
+
26
+ ### Step 1.3: Capture Handoff Snapshot
27
+
28
+ Snapshot the current next-action so the next `/cbp-session-start` (Step 4.5) can auto-resume. Per `.claude/rules/session-resume.md` write-path contract.
29
+
30
+ 1. Call MCP `get_next_action({ repo_id, worktree_id })`.
31
+ 2. If the returned `command` is non-empty (active work in flight):
32
+ ```yaml
33
+ handoff:
34
+ command: <result.command> # e.g. "/cbp-round-update"
35
+ instructions: <result.instructions> # human-readable trigger reason
36
+ state: <result.state> # workflow state label
37
+ context: <result.context> # entity ids (checkpoint_id / task_id / round_id) used by freshness probe
38
+ captured_at: <ISO now> # for entity-drift freshness comparison
39
+ captured_session_log_id: <current session log id>
40
+ ```
41
+ 3. If `command` is empty / idle / queue-empty: set `handoff = null` so the next session's probe falls through to `/cbp-todo`.
42
+ 4. Hold `handoff` in context for Step 1's `update_session_log` call below — it ships in the same write as `ended_at` and `summary`.
43
+
44
+ Continuing Step 1:
45
+
46
+ 3. Use MCP `update_session_log` to finalize:
47
+ - `ended_at`: now (maps to the `closed_at` column per TASK-2 alias)
48
+ - `handoff`: from Step 1.3 (jsonb or `null`; MCP write surface aliases to the `content` column transparently per CHK-111 Migration A — `handoff` wins over `content` when both are passed)
49
+ - `summary`: concise — may be empty if nothing happened
50
+ - `pending`: open items the next session should see first
51
+
52
+ ### Step 1.5: Commit Non-Task Files
53
+
54
+ Same rule as `/cbp-session-start` Step 5.7 — only commit files that are **not** part of an unfinished task.
55
+
56
+ 1. `git status --porcelain` — list all modified/untracked files. If empty → skip this step.
57
+ 2. Resolve **task-related files** (leave these uncommitted):
58
+ - MCP `get_current_task(repo_id)` → active task
59
+ - If active task exists: MCP `get_rounds(task_id)`, filter to rounds with status not in `completed` / `cancelled`
60
+ - Collect `files[]` from those rounds → `task_files` set
61
+ - If no active task exists, `task_files` is empty
62
+ 3. `infra_files = changed_files − task_files`
63
+ 4. If `infra_files` is empty → skip. Otherwise present once:
64
+
65
+ ```
66
+ Commit these non-task files before ending session?
67
+ [list of infra_files]
68
+
69
+ Reply: yes | no | select
70
+ ```
71
+
72
+ 5. On `yes`: `git add` the listed files, then trigger `/cbp-git-commit`.
73
+ On `no`: skip. On `select`: ask which subset.
74
+
75
+ Non-blocking — session end proceeds either way.
76
+
77
+ ### Step 1.7: Auto-Update CodeByPlan Assets
78
+
79
+ Run the latest published CLIs to pull any asset or config changes. Sub-block A runs first, then Sub-block B. A failure in A does **not** skip B — each sub-block has its own retry-and-warn lane.
80
+
81
+ **a) `codebyplan claude` (asset subcommand group)**
82
+
83
+ Run the latest published CLI's asset-update verb to pull any skill / agent / hook changes:
84
+
85
+ ```
86
+ npx codebyplan@latest claude update
87
+ ```
88
+
89
+ Always run — do not skip, even when the current repo is the canonical-owner monorepo source.
90
+
91
+ The command may pause for interactive prompts when:
92
+
93
+ - a tracked file has been hand-edited locally (overwrite / skip / diff)
94
+ - a new file is being shipped for the first time (opt-in / skip)
95
+ - a file has been removed from the package (remove / keep)
96
+
97
+ Respond to each prompt in the terminal as it appears. The commit prompt below runs only after all per-file prompts are resolved.
98
+
99
+ Failure handling:
100
+
101
+ - On non-zero exit: wait ~5 s, retry once.
102
+ - If retry also fails: print a warning and continue — this step is non-blocking.
103
+
104
+ After the command exits (success):
105
+
106
+ 1. Run `git status --porcelain -- .claude/` to detect any file changes.
107
+ 2. If non-empty, present once (same pattern as Step 1.5):
108
+
109
+ ```
110
+ .claude/ was updated. Commit these changes?
111
+ [list of changed paths under .claude/]
112
+
113
+ Reply: yes | no | select
114
+ ```
115
+
116
+ On `yes`: `git add` the listed paths only (not the whole `.claude/` directory), then trigger `/cbp-git-commit`.
117
+ On `no`: skip. On `select`: ask which subset.
118
+
119
+ 3. Print the final stdout line from the update command as a one-line session summary (e.g. `codebyplan claude update: 47 files tracked.`). Silent when the command produces no stdout.
120
+
121
+ Non-blocking — session end proceeds regardless of outcome.
122
+
123
+ **b) `codebyplan` (project CLI)**
124
+
125
+ Fetch the latest published version of the project CLI. The `codebyplan` CLI has no `update` verb (subcommands are `setup`, `sync`, `eslint`); the freshness idiom is to invoke a fast read-only flag with `@latest` so npx fetches and caches the newest published version:
126
+
127
+ ```
128
+ npx codebyplan@latest --version
129
+ ```
130
+
131
+ Do **not** run `sync`, `setup`, or any other state-changing subcommand — this step updates the cached binary only.
132
+
133
+ Failure handling:
134
+
135
+ - On non-zero exit: wait ~5 s, retry once.
136
+ - If retry also fails: print a warning and continue — this step is non-blocking.
137
+
138
+ After the command exits (success):
139
+
140
+ 1. Run `git status --porcelain -- .codebyplan/` to detect any file changes.
141
+ 2. If non-empty, present once (same pattern as Step 1.5):
142
+
143
+ ```
144
+ .codebyplan/ was updated. Commit these changes?
145
+ [list of changed paths under .codebyplan/]
146
+
147
+ Reply: yes | no | select
148
+ ```
149
+
150
+ On `yes`: `git add` the listed paths only, then trigger `/cbp-git-commit`.
151
+ On `no`: skip. On `select`: ask which subset.
152
+
153
+ 3. Print the command's stdout (the version line) as a one-line session summary (e.g. `codebyplan 1.4.2`). Silent when the command produces no stdout.
154
+
155
+ Non-blocking — session end proceeds regardless of outcome.
156
+
157
+ ### Step 2: Auto-Stop Servers
158
+
159
+ **Skip if `server_type` is `"none"`.**
160
+
161
+ 1. Get `server_port` from `.codebyplan/server.json` context
162
+ 2. Check for running process: `lsof -ti:{PORT} 2>/dev/null`
163
+ 3. If process found, kill: `lsof -ti:{PORT} | xargs kill -9 2>/dev/null || true`
164
+
165
+ Non-blocking — if kill fails, warn and continue. Silent when no process found.
166
+
167
+ ### Step 3: Update Session State
168
+
169
+ Use MCP `update_session_state` with action `deactivate`.
170
+
171
+ ### Step 4: Output
172
+
173
+ ```
174
+ Session ended. Log finalized.
175
+
176
+ You can close this window.
177
+ ```
178
+
179
+ ## Integration
180
+
181
+ - **Triggered by**: user invocation (prompted by `/cbp-todo` when no work remains)
182
+ - **Reads**: `.codebyplan/repo.json`, MCP `get_session_logs` (resolve current log), MCP `get_current_task`, MCP `get_rounds`, MCP `get_next_action` (Step 1.3 handoff snapshot)
183
+ - **Writes**: MCP `update_session_log` (with `ended_at` + `handoff` per TASK-2 alias surface; or `create_session_log` fallback), MCP `update_session_state` (deactivate)
184
+ - **Spawns**: none
185
+ - **Triggers**: none at the skill-contract level. Steps 1.5 and 1.7 may invoke `/cbp-git-commit` inline on user approval.
186
+ - **Paired with**: `/cbp-session-start`
187
+ - **Pairs with**: `.claude/rules/session-resume.md` (handoff payload shape + write-path contract)
@@ -0,0 +1,155 @@
1
+ ---
2
+ scope: org-shared
3
+ name: cbp-session-start
4
+ description: Start a development session
5
+ triggers: [cbp-todo]
6
+ effort: low
7
+ ---
8
+
9
+ # Session Start Command
10
+
11
+ Activate the session, open a fresh session log, and surface the previous log's pending items so the user can pick up where they left off.
12
+
13
+ ## Instructions
14
+
15
+ Do Steps 0–5 and Step 4.5 silently (no intermediate output). Step 5.7 may surface an approval gate. Produce ONE output block at Step 6, then auto-trigger `/cbp-todo`.
16
+
17
+ ### Step 0: MCP Health Check
18
+
19
+ Call MCP `health_check` tool.
20
+
21
+ - **If succeeds**: Continue silently
22
+ - **If fails**: Show warning:
23
+
24
+ ```
25
+ ⚠ MCP connection failed. Check:
26
+ 1. Network connectivity
27
+ 2. API key validity (CODEBYPLAN_API_KEY env var)
28
+ 3. codebyplan.com availability
29
+
30
+ Session continues but MCP-dependent features will be unavailable.
31
+ ```
32
+
33
+ Continue to Step 1 (non-blocking).
34
+
35
+ ### Step 1: Load Config
36
+
37
+ Read per-concern config files from the project root. Single load point for the session:
38
+
39
+ - `repo_id` (UUID) — from `.codebyplan/repo.json`, required for all MCP operations
40
+ - `server_port`, `server_type`, `auto_push_enabled` — from `.codebyplan/server.json`
41
+ - `git_branch` — from `.codebyplan/git.json`
42
+
43
+ Resolve `worktree_id` at runtime (CHK-108: never read from `.codebyplan/repo.json`):
44
+
45
+ ```bash
46
+ WORKTREE_ID=$(npx codebyplan resolve-worktree 2>/dev/null)
47
+ ```
48
+
49
+ Pass `WORKTREE_ID` to MCP tools that support it. Empty output means the (device, path, branch) tuple is unregistered — see fallback note below.
50
+
51
+ **If `worktree_id` resolves to empty** (the (device, path, branch) tuple does not match any registered worktree row): the session continues, but downstream MCP calls treat this caller as untagged — every hard-lock pre-guard sees a NULL `caller_worktree_id` and may reject mutations on assigned rows. Surface a one-line note in the Step 6 output instructing the user to run `npx codebyplan setup` from this directory to register the worktree.
52
+
53
+ ### Step 2: Check Dev Server
54
+
55
+ **Skip if `server_type` is `"none"`.**
56
+
57
+ 1. Get `server_port` from `.codebyplan/server.json`
58
+ 2. Check if running: `lsof -ti:{PORT} 2>/dev/null`
59
+ 3. If running, verify health: `curl -s -o /dev/null -w "%{http_code}" http://localhost:{PORT}/ --max-time 2`
60
+ 4. If NOT running, note in output that user should start via desktop app
61
+
62
+ ### Step 3: Update Session State
63
+
64
+ Use MCP `update_session_state` with action `activate`. This deactivates all other repos automatically.
65
+
66
+ ### Step 4: Read Last Session Log
67
+
68
+ Call MCP `get_session_logs({ repo_id, worktree_id, limit: 1 })` — same inclusive-worktree call shape used by Step 4.5 below so the previous-session display and the handoff probe agree on which row is "most recent for this worktree". Take the first (and only) row.
69
+
70
+ - If a previous log exists, hold its title/summary/pending items for the Step 6 output so the user sees where they left off.
71
+ - If none exists (first session ever for this worktree), skip silently.
72
+
73
+ ### Step 5: Create This Session's Log
74
+
75
+ Use MCP `create_session_log` to open a new session log for the current session. Create it **even if empty** — this establishes the record for session-end to finalize.
76
+
77
+ Minimal seed content:
78
+
79
+ - `started_at`: now
80
+ - `repo_id` from config; `worktree_id` from `WORKTREE_ID` resolved in Step 1
81
+ - `summary`: empty (session-end fills this in)
82
+
83
+ Hold the new log's ID in context so `/cbp-session-end` can update the same record.
84
+
85
+ ### Step 4.5: Handoff Auto-Resume Probe
86
+
87
+ Probe the most-recent closed session log for a structured handoff payload (per `.claude/rules/session-resume.md`) and auto-resume directly into the captured command when fresh. Additive — placed BEFORE the existing `/cbp-todo` auto-trigger; ALL failure paths fall through silently to Step 7.
88
+
89
+ 1. Reuse the row held from Step 4 (same `get_session_logs({ repo_id, worktree_id, limit: 1 })` call shape — no extra MCP round-trip).
90
+ 2. **Defensive gates** (any failure → silent fall-through to Step 7):
91
+ - No row returned → fall through.
92
+ - Row missing `closed_at` (orphan / still-open session) → fall through.
93
+ - `row.content` is `null` → no handoff captured at end-of-session → fall through.
94
+ - `row.content` exists but parse throws or shape mismatch (`command` field absent OR is an empty string) → fall through.
95
+ 3. **Freshness gate** — load the row as `handoff = row.content` (per CHK-111 Migration A column alias). Mark stale when ANY of:
96
+ - `(now - row.closed_at) > freshness_window_hours` (read from `.codebyplan/repo.json`, default 24 hours)
97
+ - Referenced entity in `handoff.context` has shifted. For each id present, run the matching MCP read and find the row whose `id` matches:
98
+ - `checkpoint_id` → `get_checkpoints({ repo_id })` → find entry where `entry.id === handoff.context.checkpoint_id`
99
+ - `task_id` → `get_tasks({ checkpoint_id })` if `handoff.context.checkpoint_id` is present, else `get_tasks({ repo_id, standalone: true })` → find entry where `entry.id === handoff.context.task_id`
100
+ - `round_id` → `get_rounds({ task_id: handoff.context.task_id })` → find entry where `entry.id === handoff.context.round_id`
101
+ Then compare `entry.updated_at > handoff.captured_at` → stale on any inequality.
102
+ - Entity lookup fails OR the matching `id` is not present in the returned array → stale (referenced entity gone or moved out of reach).
103
+ 4. **On stale OR any defensive gate hit**: fall through silently to Step 7 (existing `/cbp-todo` trigger).
104
+ 5. **On fresh hit**: trigger `handoff.command` directly with `handoff.context` / `handoff.state` in the trigger arguments. The downstream skill self-loads its full context — do NOT duplicate `/cbp-todo` Step 2's context-loading matrix here. Skip Step 5.7, Step 6 output, and Step 7.
105
+
106
+ ### Step 5.7: Commit Non-Task Files
107
+
108
+ Clean the working tree of leftover infra before the session begins. Only commit files that are **not** part of an unfinished task.
109
+
110
+ 1. `git status --porcelain` — list all modified/untracked files. If empty → skip this step.
111
+ 2. Resolve **task-related files** (leave these uncommitted):
112
+ - MCP `get_current_task(repo_id)` → active task
113
+ - If active task exists: MCP `get_rounds(task_id)`, filter to rounds with status not in `completed` / `cancelled`
114
+ - Collect `files[]` from those rounds → `task_files` set
115
+ - If no active task exists, `task_files` is empty
116
+ 3. `infra_files = changed_files − task_files`
117
+ 4. **Re-run `git status --porcelain` immediately before showing the commit-prompt** (after Steps 0–5 have completed all MCP round-trips). Eliminates the race where prior-session staged files appear in the index only after MCP init's network round-trips complete. Recompute `infra_files` from the fresh listing.
118
+ 5. If `infra_files` is empty → skip. Otherwise present once:
119
+
120
+ ```
121
+ Commit these non-task files before starting session?
122
+ [list of infra_files]
123
+
124
+ Reply: yes | no | select
125
+ ```
126
+
127
+ 6. On `yes`: `git add` the listed files, then trigger `/cbp-git-commit` (it handles conventional message + commit).
128
+ On `no`: skip. On `select`: ask which subset.
129
+
130
+ Non-blocking — session start proceeds either way.
131
+
132
+ ### Step 6: Output
133
+
134
+ ```
135
+ Session active | Worktree: [worktree_id or "main"]
136
+
137
+ Previous session: [title or "none"]
138
+ Pending: [pending items from previous log, or "—"]
139
+
140
+ [⚠ Dev server not running — start via desktop app — only if applicable]
141
+ ```
142
+
143
+ ### Step 7: Auto-trigger Todo
144
+
145
+ Trigger `/cbp-todo` to determine what to work on.
146
+
147
+ ## Integration
148
+
149
+ - **Triggered by**: user invocation, `/clear` recovery
150
+ - **Reads**: `.codebyplan/repo.json`, MCP `get_session_logs` (worktree-filtered, limit 1 — single call shared by Step 4 and Step 4.5), MCP `health_check`, MCP `get_current_task`, MCP `get_rounds`, MCP `get_checkpoints` / `get_tasks` / `get_rounds` for freshness probe (Step 4.5)
151
+ - **Writes**: MCP `create_session_log` (new, possibly empty), MCP `update_session_state` (activate)
152
+ - **Spawns**: none
153
+ - **Triggers**: `/cbp-git-commit` (conditional, on user approval), `handoff.command` (on fresh handoff hit at Step 4.5), `/cbp-todo` (auto fall-through)
154
+ - **Paired with**: `/cbp-session-end`
155
+ - **Pairs with**: `.claude/rules/session-resume.md` (handoff payload shape + freshness gate contract)