codebyplan 1.13.13 → 1.13.14

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.
@@ -0,0 +1,152 @@
1
+ ---
2
+ scope: repo-only:codebyplan
3
+ name: cbp-standalone-task-check
4
+ description: AI production review for the current standalone task
5
+ argument-hint: [task] # e.g. `45` (standalone TASK-45)
6
+ triggers: [cbp-standalone-task-testing]
7
+ effort: high
8
+ ---
9
+
10
+ # Standalone Task Check Command
11
+
12
+ AI-driven production readiness review for standalone tasks. Spawns the `cbp-task-check` agent for thorough verification including user satisfaction discussion. This command is a thin orchestrator — the agent does the heavy lifting.
13
+
14
+ ## Inline-Fallback for Spawn Failure
15
+
16
+ If the `cbp-task-check` agent spawn fails for any reason, follow the canonical inline-fallback procedure documented in `skills/cbp-round-end/SKILL.md` "Inline-fallback for any spawn failure". Walk every agent phase inline with the same Read/Grep depth the agent would have used — do not skip phases.
17
+
18
+ ## When Used
19
+
20
+ - After all rounds complete and all files approved (auto-triggered by `/cbp-round-update`)
21
+ - Before `/cbp-standalone-task-testing`
22
+ - Never skippable
23
+
24
+ ## Instructions
25
+
26
+ ### Step 1: Parse `$ARGUMENTS`
27
+
28
+ | Shape | Regex | Resolves to |
29
+ |-------|-------|-------------|
30
+ | `{task}` (e.g. `45`) | `^[0-9]+$` | Standalone TASK-{task} |
31
+ | _(empty)_ | — | Use MCP `get_current_standalone_task` to find the active in-progress task |
32
+
33
+ Any multi-segment input is an error:
34
+
35
+ ```
36
+ standalone-task-check: argument `{value}` looks like a checkpoint-task pair.
37
+ Use /cbp-task-check {chk}-{task} for checkpoint-bound tasks.
38
+ Standalone tasks use a bare number, e.g. /cbp-standalone-task-check 45.
39
+ ```
40
+
41
+ Error cases: any multi-segment input, `abc`, `108-`, `-1`, anything with whitespace or non-numeric characters.
42
+
43
+ #### Worked examples
44
+
45
+ - `standalone-task-check 45` → standalone TASK-45
46
+ - `standalone-task-check` (no arg) → active in-progress task via `get_current_standalone_task`
47
+ - `standalone-task-check 141-3` → error: "Use /cbp-task-check {chk}-{task} for checkpoint-bound tasks."
48
+ - `standalone-task-check abc` → error: malformed
49
+
50
+ ### Step 1.5: Get Current Task
51
+
52
+ | Parse | Resolution path |
53
+ |-------|-----------------|
54
+ | `{task}` | MCP `get_standalone_tasks(repo_id)` → filter `number === {task}`. |
55
+ | _(empty)_ | MCP `get_current_standalone_task(repo_id)` — finds the active in-progress task. |
56
+
57
+ If no in-progress task, show error and stop.
58
+
59
+ ### Step 2: Quick Gate — Verify All Rounds Complete
60
+
61
+ Use MCP `get_standalone_rounds(standalone_task_id)`. Verify all rounds are `completed`.
62
+
63
+ If any rounds still in_progress:
64
+
65
+ ```
66
+ ## Cannot Run Standalone Task Check
67
+
68
+ Standalone TASK-[N] has an active round (Round [N]). Complete it first:
69
+ - Run `/cbp-round-update` to finish the round
70
+ ```
71
+
72
+ Stop here.
73
+
74
+ ### Step 3: Load All Context
75
+
76
+ 1. Get task details: id, title, requirements, context, qa
77
+ 2. Get all rounds via `get_standalone_rounds(standalone_task_id)`: number, requirements, context, qa, files_changed
78
+
79
+ No checkpoint context is needed — standalone tasks have no parent checkpoint.
80
+
81
+ ### Step 4: Spawn Task Check Agent
82
+
83
+ Spawn `cbp-task-check` agent with full context:
84
+
85
+ ```yaml
86
+ input:
87
+ task_number: [N]
88
+ round_number: [total rounds]
89
+ checkpoint: null
90
+ task: { id, title, requirements, context, files_changed, qa }
91
+ rounds: [{ number, requirements, context, qa, files_changed }]
92
+ ```
93
+
94
+ Wait for agent to complete. Agent handles all phases including user satisfaction discussion.
95
+
96
+ ### Step 5: Save Agent Output
97
+
98
+ Save agent output to task context via MCP `update_standalone_task`:
99
+
100
+ - `task.context.check_verdict` = agent output (verdict, requirements_check, etc.)
101
+
102
+ ```
103
+ update_standalone_task(task_id, context: { ...existing, check_verdict: agentOutput })
104
+ ```
105
+
106
+ ### Step 6: Route Based on Verdict
107
+
108
+ **READY + satisfied:**
109
+
110
+ **Next**: Run `/clear`, then `/cbp-standalone-task-testing {task}` to run comprehensive task-level testing.
111
+
112
+ **NOT READY — fixable issues:**
113
+
114
+ ```
115
+ Issues found that need addressing:
116
+ - [issue 1]
117
+ - [issue 2]
118
+ ```
119
+
120
+ Suggest: `/cbp-round-input` with specific issues. Stop — wait for user.
121
+
122
+ **NOT READY — needs new task:**
123
+
124
+ ```
125
+ Scope issues identified that require a new task:
126
+ - [scope issue]
127
+ ```
128
+
129
+ Suggest: `/cbp-standalone-task-create`. Stop — wait for user.
130
+
131
+ **NOT READY — approvals missing:**
132
+
133
+ ```
134
+ Code review passed but [N] files need user approval.
135
+ ```
136
+
137
+ Suggest: Approve files, then re-run `/cbp-standalone-task-check {task}`. Stop — wait for user.
138
+
139
+ ## Key Rules
140
+
141
+ - **Never skippable** — mandatory before `/cbp-standalone-task-testing`
142
+ - **This is AI review + user satisfaction** — not automated testing
143
+ - **Read all changed files** — agent does the heavy lifting
144
+ - **No file changes** — review only, never edit
145
+ - **No checkpoint context** — standalone tasks are self-contained
146
+
147
+ ## Integration
148
+
149
+ - **Reads**: MCP `get_current_standalone_task`, `get_standalone_tasks`, `get_standalone_rounds`, all changed files (via agent)
150
+ - **Writes**: MCP `update_standalone_task` (context.check_verdict)
151
+ - **Triggers**: emits directive `Next: /clear, then /cbp-standalone-task-testing {task}` on READY + satisfied
152
+ - **Triggered by**: `/cbp-round-update` (auto, when all files approved)
@@ -0,0 +1,201 @@
1
+ ---
2
+ scope: repo-only:codebyplan
3
+ name: cbp-standalone-task-complete
4
+ description: Complete a standalone task — merge feat branch and mark done
5
+ argument-hint: [task] # e.g. `45` (standalone TASK-45)
6
+ effort: xhigh
7
+ ---
8
+
9
+ # Standalone Task Complete Command
10
+
11
+ Complete a standalone task. Auto-triggered by `/cbp-standalone-task-testing` when all tests pass. Can also be run manually.
12
+
13
+ ## Instructions
14
+
15
+ ### Step 1: Parse `$ARGUMENTS`
16
+
17
+ | Shape | Regex | Resolves to |
18
+ |-------|-------|-------------|
19
+ | `{task}` (e.g. `45`) | `^[0-9]+$` | Standalone TASK-{task} |
20
+ | _(empty)_ | — | Use MCP `get_current_standalone_task` to find the active in-progress task |
21
+
22
+ Any multi-segment input is an error:
23
+
24
+ ```
25
+ standalone-task-complete: argument `{value}` looks like a checkpoint-task pair.
26
+ Use /cbp-task-complete {chk}-{task} for checkpoint-bound tasks.
27
+ Standalone tasks use a bare number, e.g. /cbp-standalone-task-complete 45.
28
+ ```
29
+
30
+ Error cases: any multi-segment input, `abc`, `108-`, `-1`, anything with whitespace or non-numeric characters.
31
+
32
+ #### Worked examples
33
+
34
+ - `standalone-task-complete 45` → standalone TASK-45
35
+ - `standalone-task-complete` (no arg) → active in-progress task via `get_current_standalone_task`
36
+ - `standalone-task-complete 141-3` → error: "Use /cbp-task-complete {chk}-{task} for checkpoint-bound tasks."
37
+ - `standalone-task-complete abc` → error: malformed
38
+
39
+ ### Step 1.5: Get Current Task
40
+
41
+ | Parse | Resolution path |
42
+ |-------|-----------------|
43
+ | `{task}` | MCP `get_standalone_tasks(repo_id)` → filter `number === {task}`. |
44
+ | _(empty)_ | MCP `get_current_standalone_task(repo_id)` — finds the active in-progress task. |
45
+
46
+ If no in-progress task, show error and stop.
47
+
48
+ ### Step 2: Verify Rounds Complete and Validated
49
+
50
+ Use MCP `get_standalone_rounds(standalone_task_id)`. Verify all rounds are `completed`.
51
+
52
+ If any round is `in_progress`:
53
+
54
+ ```
55
+ ## Cannot Complete Standalone Task
56
+
57
+ Standalone TASK-[N] has an active round (Round [N]). Run `/cbp-round-update` to finish it.
58
+ ```
59
+
60
+ Stop here.
61
+
62
+ Verify at least one round has `testing_qa_output` in its context. If not:
63
+
64
+ ```
65
+ ## Cannot Complete Standalone Task
66
+
67
+ No testing-qa-agent validation found. Run `/cbp-round-start` to execute a validated round.
68
+ ```
69
+
70
+ Stop here.
71
+
72
+ ### Step 2.5: Verify `/cbp-standalone-task-check` Has Run
73
+
74
+ `task.context.check_verdict` must exist and have `verdict: 'READY'`. If not, surface "Run `/cbp-standalone-task-check` first" and stop.
75
+
76
+ ### Step 2.6: Verify `/cbp-standalone-task-testing` Has Run
77
+
78
+ `task.context.task_testing_output` must exist with `all_passed: true`. If not, surface "Run `/cbp-standalone-task-testing` first" and stop.
79
+
80
+ ### Step 3: Verify QA and File Approval
81
+
82
+ Load `task.qa` and `task.files_changed`:
83
+
84
+ 1. **QA**: count items by status (pass / fail / pending / skipped). If any item has status `fail` or `pending`, warn the user.
85
+ 2. **Files**: list any file with `user_approved === false` and warn.
86
+
87
+ **If issues exist**, AskUserQuestion: `Complete anyway` / `Run QA first` / `Cancel`. On `Run QA first` or `Cancel`, stop. On `Complete anyway`, continue.
88
+
89
+ **If no issues**, AskUserQuestion to confirm: `Ready to complete standalone TASK-[N]: [title] — [N] rounds, [N] files. Proceed?`
90
+
91
+ ### Step 4: Aggregate Files Changed
92
+
93
+ Collect all files_changed from all standalone rounds. Deduplicate (latest action wins).
94
+
95
+ ### Step 5: Git Commit (no push)
96
+
97
+ Commit task work FIRST, before the merge in Step 7. `/cbp-merge-main` must never run before the task commit.
98
+
99
+ **Zero-file guard**: if `aggregated_files` is empty, skip the commit. Record "No git commit: zero files changed" in the Step 9 summary, then continue.
100
+
101
+ **Already-committed guard**: if the aggregated files are already committed (working tree clean for them), skip the commit and continue; the prior run's task commit still stands.
102
+
103
+ Otherwise: invoke `/cbp-git-commit` to stage approved files and create the commit. Claude does NOT git add directly. Do NOT push here.
104
+
105
+ ### Step 5.5: Merge Production Branch (mandatory)
106
+
107
+ Ensure the feat branch is current with the latest production work.
108
+
109
+ 1. Trigger `/cbp-merge-main`.
110
+ 2. If the skill exits with failure (offline, unresolved conflicts, user-aborted): surface the failure and STOP. The task commit from Step 5 persists; the user resolves and re-invokes.
111
+ 3. If QA warnings the user chose to commit-as-is: continue to Step 5.7 with a soft warning.
112
+ 4. On clean success: continue to Step 5.7.
113
+
114
+ ### Step 5.7: Push
115
+
116
+ Push once, carrying both the task commit and the merge commit:
117
+
118
+ ```bash
119
+ git push origin $(git branch --show-current)
120
+ ```
121
+
122
+ Skip only when nothing was committed AND `/cbp-merge-main` reported already-up-to-date. If push fails, investigate and fix.
123
+
124
+ ### Step 6: Update Task Files
125
+
126
+ `update_standalone_task(task_id, context: { ...existing, files_changed: aggregated_files })`.
127
+
128
+ ### Step 7: Standalone Task Branch Merge
129
+
130
+ Only when current branch matches `feat/standalone-TASK-*`:
131
+
132
+ 1. Read `.codebyplan/git.json` `branch_config.production` (default: `main`). Store as `PRODUCTION`.
133
+ 2. `git checkout {PRODUCTION}`
134
+ 3. `git merge {feat-branch} --no-ff -m "Merge {feat-branch}: {task title}"`
135
+ 4. `git push origin {PRODUCTION}`
136
+ 5. Delete feat branch local: `git branch -d {feat-branch}`
137
+ 6. Delete feat branch remote: `git push origin --delete {feat-branch}`
138
+
139
+ If merge has conflicts, stop immediately and ask the user to resolve. Do not delete the feat branch until the merge succeeds and is pushed.
140
+
141
+ If current branch is not `feat/standalone-TASK-*`, skip this step.
142
+
143
+ ### Step 7.5: Complete Standalone Task
144
+
145
+ Note: `complete_standalone_task` is called only after the branch merge succeeds — the DB completion record reflects work that has landed in production.
146
+
147
+ Resolve caller worktree: `CALLER_WT=$(npx codebyplan resolve-worktree 2>/dev/null)`.
148
+
149
+ Call `complete_standalone_task(standalone_task_id, caller_worktree_id: CALLER_WT)`. `caller_worktree_id` is REQUIRED — the MCP server's pre-guard rejects mutations from non-matching worktrees. The server auto-clears `assigned_worktree_id` on the task on success.
150
+
151
+ If `CALLER_WT` is empty, surface this warning and ask user to confirm before proceeding:
152
+
153
+ ```
154
+ Warning: could not resolve caller_worktree_id (npx codebyplan resolve-worktree returned empty).
155
+ The complete_standalone_task call may be rejected by the pre-guard. Proceed anyway? (yes / no)
156
+ ```
157
+
158
+ ### Step 8: Run Cleanup + Migration (inline)
159
+
160
+ Apply the `cleanup` skill inline to remove orphan references to deleted/modified files. Apply `migration` to propagate renames/moves to consumers. Both run without sub-agent spawns. Skip cleanup if no deletions/modifications; skip migration if cleanup handled everything.
161
+
162
+ ### Step 9: Show Result and Route
163
+
164
+ ```
165
+ ## Standalone Task Completed
166
+
167
+ **Standalone TASK-[N]**: [title]
168
+ **Rounds**: [N] completed
169
+ **Files**: [N] changed
170
+ **Commit**: [hash]
171
+ **Branch merged**: [feat-branch] → {PRODUCTION}
172
+ ```
173
+
174
+ #### Route (single directive — never a menu)
175
+
176
+ Standalone tasks have no checkpoint parent. Route to session end or new work:
177
+
178
+ Next: /cbp-session-end
179
+
180
+ If the user has mentioned more standalone work to create:
181
+
182
+ Next: /cbp-standalone-task-create
183
+
184
+ Do NOT use AskUserQuestion for routing. Do NOT use the Skill tool to auto-trigger. Emit one directive and stop.
185
+
186
+ ## Key Rules
187
+
188
+ - **`caller_worktree_id` is REQUIRED** for `complete_standalone_task`
189
+ - **Branch merge lives here** (not in checkpoint-end) — standalone tasks self-ship to production
190
+ - **Single-directive routing** — no menus, no auto-triggers via Skill tool
191
+ - **No checkpoint** — never check `checkpoint_id`, always treat task as standalone
192
+ - **Never skippable prerequisites** — check_verdict READY + task_testing_output all_passed required
193
+
194
+ ## Integration
195
+
196
+ - **Triggered by**: `/cbp-standalone-task-testing` emits directive (user runs it manually after seeing directive)
197
+ - **Chain**: `/cbp-standalone-task-check` → `/cbp-standalone-task-testing` → `/cbp-standalone-task-complete`
198
+ - **Reads**: MCP `get_current_standalone_task`, `get_standalone_tasks`, `get_standalone_rounds`
199
+ - **Writes**: MCP `update_standalone_task`, `complete_standalone_task`
200
+ - **Uses skills (inline, no sub-agent)**: `cleanup` (if deletions), `migration` (if exports renamed)
201
+ - **Does NOT** auto-trigger next skill — emits single directive only
@@ -0,0 +1,150 @@
1
+ ---
2
+ scope: repo-only:codebyplan
3
+ name: cbp-standalone-task-create
4
+ description: Creates a standalone task (not checkpoint-bound) via create_standalone_task MCP tool
5
+ effort: xhigh
6
+ ---
7
+
8
+ # Standalone Task Create Command
9
+
10
+ Create a new standalone task — independent of any checkpoint. Gathers user context, analyzes existing standalone work, and creates a well-positioned task. Runs inline (no subagent) to preserve Q&A conversation flow.
11
+
12
+ ## When Used
13
+
14
+ - User wants to create a task that is not tied to any checkpoint
15
+ - Improvement or fix work that stands alone
16
+ - Maintenance, research, or investigative tasks with no checkpoint parent
17
+
18
+ ## Identifier Notation
19
+
20
+ Standalone tasks use a bare number (e.g. `45` = standalone TASK-45). There is no checkpoint segment. Canonical notation follows `.claude/rules/notation-consistency.md`.
21
+
22
+ ## Instructions
23
+
24
+ ### Step 1: Gather User Context
25
+
26
+ Use AskUserQuestion to understand the new standalone task:
27
+
28
+ ```
29
+ ## New Standalone Task
30
+
31
+ What should this standalone task accomplish?
32
+
33
+ Please describe:
34
+ 1. What the task should accomplish
35
+ 2. Any specific requirements or constraints
36
+ 3. Priority or deadline (if any)
37
+ ```
38
+
39
+ ### Step 2: Load Existing Standalone Tasks
40
+
41
+ Use MCP `get_standalone_tasks(repo_id)` to read existing standalone tasks. Review:
42
+ - Existing task titles and requirements
43
+ - Task statuses (completed, in_progress, pending)
44
+
45
+ ### Step 3: Determine Next Task Number
46
+
47
+ Sort existing standalone tasks by `number` descending. Next number = highest existing number + 1. If no standalone tasks exist, start at 1.
48
+
49
+ ### Step 3.5: Dedup Against Pending Standalone Tasks (MANDATORY)
50
+
51
+ Before creating, compare the proposed task against every pending standalone task on these match dimensions:
52
+
53
+ | Match dimension | Action if matched |
54
+ |-----------------|-------------------|
55
+ | Same target file(s) | STOP — `update_standalone_task` to append, do not create new |
56
+ | Same feature / module | STOP — `update_standalone_task` to append, do not create new |
57
+ | Same root cause | STOP — `update_standalone_task` to append, do not create new |
58
+ | Same dependency / advisory | STOP — `update_standalone_task` to append, do not create new |
59
+
60
+ If a match is found, surface it before appending:
61
+
62
+ ```
63
+ Found existing pending standalone task TASK-[N]: [title]
64
+ This finding overlaps on [dimension]. Append to TASK-[N] instead of creating new? (yes / no — create separately)
65
+ ```
66
+
67
+ Default to append. Only create a separate task if the user explicitly says no, OR if the existing task is in_progress / completed.
68
+
69
+ ### Step 4: Analyze Codebase Context
70
+
71
+ Brief inline analysis:
72
+ 1. Grep/Glob for files related to the user's described work
73
+ 2. Understand what existing standalone tasks have already built
74
+ 3. Note any obvious dependencies
75
+
76
+ ### Step 5: Clarify Ambiguities (if needed)
77
+
78
+ If the task scope is unclear after Steps 1-4, ask up to 4 clarifying questions via AskUserQuestion:
79
+
80
+ ```
81
+ To create the best task definition, I need to clarify:
82
+
83
+ 1. [question about scope]
84
+ 2. [question about approach]
85
+ [max 4 questions]
86
+ ```
87
+
88
+ Skip if requirements are already clear from Step 1.
89
+
90
+ ### Step 6: Resolve Worktree Assignment
91
+
92
+ Resolve worktree_id via `npx codebyplan resolve-worktree 2>/dev/null`.
93
+
94
+ - If non-empty: pass as `assigned_worktree_id` in Step 7. This engages the hard-lock from creation.
95
+ - If empty: warn the user that the task will be unassigned and offer to run `npx codebyplan setup` from the current directory first. After setup, re-resolve and proceed. If the user declines, create without `assigned_worktree_id`.
96
+
97
+ ### Step 7: Create Standalone Task
98
+
99
+ Use MCP `create_standalone_task` with:
100
+ - **repo_id**: from `.codebyplan/repo.json`
101
+ - **title**: Concise task title
102
+ - **number**: next available number from Step 3
103
+ - **requirements**: Numbered requirements list
104
+ - **context**: Include decisions from Q&A and source findings
105
+ - **assigned_worktree_id**: from Step 6 (if resolved)
106
+
107
+ ```
108
+ ## Standalone Task Created
109
+
110
+ **TASK-[N]**: [title]
111
+
112
+ ### Requirements:
113
+ 1. [requirement 1]
114
+ 2. [requirement 2]
115
+ ...
116
+
117
+ ### Context:
118
+ - Decisions: [key decisions from Q&A]
119
+ - Files likely touched: [relevant paths]
120
+ ```
121
+
122
+ ### Step 8: Route
123
+
124
+ ```
125
+ Standalone TASK-[N] created successfully.
126
+ ```
127
+
128
+ ---
129
+
130
+ **Next:**
131
+ Run `/cbp-standalone-task-start {N}` to begin work on this task.
132
+
133
+ ---
134
+
135
+ Waiting for user to decide next step.
136
+
137
+ ## Key Rules
138
+
139
+ - **Runs inline** — no subagent, preserves Q&A flow
140
+ - **No checkpoint** — standalone tasks have no checkpoint_id
141
+ - **Gather context first** — understand before creating
142
+ - **Dedup against existing standalone tasks** — check Step 3.5 always
143
+ - **Does NOT auto-trigger** — user decides when to start
144
+
145
+ ## Integration
146
+
147
+ - **Reads**: MCP `get_standalone_tasks`
148
+ - **Writes**: MCP `create_standalone_task`
149
+ - **Triggered by**: user manual
150
+ - **Does NOT auto-trigger** next command — user decides
@@ -0,0 +1,177 @@
1
+ ---
2
+ scope: repo-only:codebyplan
3
+ name: cbp-standalone-task-start
4
+ description: Start a standalone task, load context from DB
5
+ argument-hint: [task] # e.g. `45` (standalone TASK-45)
6
+ effort: xhigh
7
+ ---
8
+
9
+ # Standalone Task Start Command
10
+
11
+ Start a standalone task by loading context from the database and preparing for work. Standalone tasks are not checkpoint-bound — they have no CHK-NNN parent.
12
+
13
+ ## Instructions
14
+
15
+ ### Step 1: Parse `$ARGUMENTS`
16
+
17
+ | Shape | Regex | Resolves to |
18
+ |-------|-------|-------------|
19
+ | `{task}` (e.g. `45`) | `^[0-9]+$` | Standalone TASK-{task} |
20
+ | _(empty)_ | — | Use MCP `get_current_standalone_task` |
21
+
22
+ Any multi-segment input is an error — stop immediately:
23
+
24
+ ```
25
+ standalone-task-start: argument `{value}` looks like a checkpoint-task pair.
26
+ Use /cbp-task-start {chk}-{task} for checkpoint-bound tasks.
27
+ Standalone tasks use a bare number, e.g. /cbp-standalone-task-start 45.
28
+ ```
29
+
30
+ Error cases: `141-3` (that is a checkpoint-task pair), `abc`, `108-`, `-1`, anything with whitespace or non-numeric characters, or multiple dash-separated segments.
31
+
32
+ #### Worked examples
33
+
34
+ - `standalone-task-start 45` → standalone TASK-45
35
+ - `standalone-task-start` (no arg) → current standalone task via `get_current_standalone_task`
36
+ - `standalone-task-start 141-3` → error: "Use /cbp-task-start {chk}-{task} for checkpoint-bound tasks."
37
+ - `standalone-task-start abc` → error: malformed
38
+
39
+ ### Step 2: Resolve Task
40
+
41
+ | Parse | Resolution path |
42
+ |-------|-----------------|
43
+ | `{task}` | MCP `get_standalone_tasks(repo_id)` → filter `number === {task}` (must exist). |
44
+ | _(empty)_ | MCP `get_current_standalone_task(repo_id)` — finds the active in-progress standalone task. |
45
+
46
+ If no row is found, surface this and stop:
47
+
48
+ ```
49
+ standalone-task-start: no standalone task found for `{ARG}`.
50
+ - Check with /cbp-standalone-task-create if the task has not been created yet.
51
+ - For checkpoint-bound tasks, use /cbp-task-start {chk}-{task}.
52
+ ```
53
+
54
+ ### Step 3: Branch Auto-Handling
55
+
56
+ The task MUST run on its target feat branch. Claude switches/creates that branch automatically — never asks the user to do it.
57
+
58
+ #### 3.1 — Determine the target branch
59
+
60
+ Read `.codebyplan/git.json`:
61
+ - `branch_config.protected` (fall back to `["main"]`)
62
+ - `branch_config.production` (fall back to `"main"`) → store as `PRODUCTION`
63
+
64
+ Compute `TARGET`:
65
+
66
+ | Task type | TARGET |
67
+ |-----------|--------|
68
+ | Standalone, `task.branch_name` set | `task.branch_name` |
69
+ | Standalone, `branch_name` null | `feat/standalone-TASK-{N}-{kebab-slug-from-task-title}` |
70
+
71
+ Slug rules: lowercase, words joined by `-`, drop punctuation, truncate to 40 chars.
72
+
73
+ #### 3.2 — Compare current branch
74
+
75
+ Run `git branch --show-current`. If `current == TARGET` → continue to Step 3b. Done.
76
+
77
+ #### 3.3 — Switch automatically (no AskUserQuestion, no blocking)
78
+
79
+ ```bash
80
+ # (a) target exists locally
81
+ if git rev-parse --verify "$TARGET" >/dev/null 2>&1; then
82
+ git checkout "$TARGET"
83
+
84
+ # (b) target exists on origin (track it)
85
+ elif git rev-parse --verify "origin/$TARGET" >/dev/null 2>&1; then
86
+ git checkout -t "origin/$TARGET"
87
+
88
+ # (c) target doesn't exist — create from production branch
89
+ else
90
+ git fetch origin "$PRODUCTION" 2>/dev/null || true
91
+ git checkout -b "$TARGET" "origin/$PRODUCTION" 2>/dev/null \
92
+ || git checkout -b "$TARGET" "$PRODUCTION"
93
+ fi
94
+ ```
95
+
96
+ No `git stash`, ever (per `git-safety.md`). No `git add`, ever (per `git-workflow.md`).
97
+
98
+ If `git checkout` exits non-zero (would clobber), surface the raw git error verbatim and stop.
99
+
100
+ #### 3.4 — Persist + verify
101
+
102
+ After successful switch:
103
+
104
+ 1. Re-run `git branch --show-current` to confirm `current == TARGET`.
105
+ 2. If `task.branch_name` was null, persist: `update_standalone_task(task_id, context: { ...task.context, branch_name: TARGET })`
106
+ 3. One-line confirmation: `Branch: [TARGET] (switched from [previous])`.
107
+
108
+ #### 3.5 — Protected-branch sanity (defensive)
109
+
110
+ If `current` is still in `branch_config.protected`, block with a hard error citing the bad config.
111
+
112
+ ### Step 3b: Clean Slate
113
+
114
+ 1. Run `git status --short` to check for uncommitted files.
115
+ 2. If uncommitted files exist → commit them with `chore: clean slate for task start`. Prefer `git add -A && git commit -m "..."`.
116
+
117
+ ### Step 3.5: Worktree-Match Verification
118
+
119
+ Before activating, verify the caller's worktree matches the assigned worktree.
120
+
121
+ 1. `CALLER_WT=$(npx codebyplan resolve-worktree 2>/dev/null)`. If empty, omit `caller_worktree_id` from MCP calls.
122
+ 2. `TARGET_WT = task.assigned_worktree_id`.
123
+ 3. If `TARGET_WT IS NOT NULL AND TARGET_WT != CALLER_WT`, surface error and abort:
124
+
125
+ ```
126
+ Standalone TASK-N is assigned to worktree {TARGET_WT_NAME} ({TARGET_WT}); current worktree is {CALLER_WT_NAME} ({CALLER_WT}).
127
+ Use the release_assignment MCP tool (requires maintainer role) if {TARGET_WT_NAME} is dead, then re-run /cbp-standalone-task-start.
128
+ ```
129
+
130
+ 4. If `TARGET_WT IS NULL` or matches, proceed.
131
+
132
+ ### Step 3.6: Main-Drift Check (optional)
133
+
134
+ Soft-skip on fetch failure.
135
+
136
+ 1. Run `git fetch origin {PRODUCTION}`. Skip entire step if fetch fails.
137
+ 2. `BEHIND=$(git rev-list --count HEAD..origin/{PRODUCTION})`.
138
+ 3. Compute `LAST_FETCH_AGE_HOURS` from mtime of `.git/FETCH_HEAD`.
139
+ 4. If `BEHIND >= 10` OR `LAST_FETCH_AGE_HOURS > 24`: AskUserQuestion — merge main now (A: Yes → trigger `/cbp-merge-main`, B: No → proceed).
140
+
141
+ ### Step 4: Load Context
142
+
143
+ Load context from DB:
144
+
145
+ 1. **Task context**: decisions, discoveries, requirements
146
+ 2. **Previous rounds**: check for completed rounds via `get_standalone_rounds(task_id)`
147
+
148
+ ```
149
+ ## Starting Standalone Task: TASK-[N]
150
+
151
+ **Task**: [title]
152
+ **Requirements**: [requirements]
153
+
154
+ ### Context
155
+ - **Decisions**: [list locked decisions relevant to this task]
156
+ - **Previous rounds**: [count] completed
157
+ ```
158
+
159
+ ### Step 5: Set Task Status
160
+
161
+ Use MCP `update_standalone_task(task_id, status: "in_progress")`.
162
+
163
+ If `CALLER_WT` is present, include `caller_worktree_id: CALLER_WT`.
164
+
165
+ ### Step 6: Auto-trigger Round Start
166
+
167
+ Trigger `/cbp-round-start` with no argument. Do NOT pass the task number — round-start's 2-segment form means standalone TASK-{a} round {b}, not a checkpoint task. Passing no argument causes round-start to derive the active task/round from state, which is correct.
168
+
169
+ ```
170
+ Starting first round...
171
+ ```
172
+
173
+ ## Integration
174
+
175
+ - **Reads**: MCP `get_standalone_tasks`, `get_current_standalone_task`, `get_standalone_rounds`
176
+ - **Writes**: MCP `update_standalone_task`
177
+ - **Triggers**: `/cbp-round-start` (no argument — auto, round 1)