codebyplan 1.9.0 → 1.10.1

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.
package/dist/cli.js CHANGED
@@ -14,7 +14,7 @@ var VERSION, PACKAGE_NAME;
14
14
  var init_version = __esm({
15
15
  "src/lib/version.ts"() {
16
16
  "use strict";
17
- VERSION = "1.9.0";
17
+ VERSION = "1.10.1";
18
18
  PACKAGE_NAME = "codebyplan";
19
19
  }
20
20
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codebyplan",
3
- "version": "1.9.0",
3
+ "version": "1.10.1",
4
4
  "description": "CLI for CodeByPlan — AI-powered development planning and tracking",
5
5
  "type": "module",
6
6
  "bin": {
@@ -23,6 +23,7 @@ Examples:
23
23
  - Must run from the **main repo** (the non-worktree checkout)
24
24
  - Working tree should be clean
25
25
  - Branch should not already exist as a worktree
26
+ - New branches are always rooted at `origin/{production}` (read from `.codebyplan/git.json`), independent of the main repo's currently checked-out branch
26
27
 
27
28
  ## Instructions
28
29
 
@@ -87,18 +88,23 @@ If it exists, stop and inform the user.
87
88
 
88
89
  ### Step 4: Create Branch If Needed
89
90
 
91
+ Resolve the production branch: read `.codebyplan/git.json` and take `branch_config.production` (fall back to `main` if the file or field is absent). Call this `$PRODUCTION`.
92
+
90
93
  Check if branch exists:
91
94
 
92
95
  ```bash
93
96
  git branch --list "$BRANCH_NAME"
94
97
  ```
95
98
 
96
- If branch does NOT exist, create it from current HEAD:
99
+ If branch does NOT exist, create it from the freshest production tip — **not** from the main repo's ambient HEAD (which is often a stale home branch such as `codebyplan-main`):
97
100
 
98
101
  ```bash
99
- git branch "$BRANCH_NAME"
102
+ git fetch origin "$PRODUCTION" 2>/dev/null || true
103
+ git branch "$BRANCH_NAME" "origin/$PRODUCTION"
100
104
  ```
101
105
 
106
+ This guarantees every worktree starts at `origin/{production}` regardless of which branch the main repo currently has checked out.
107
+
102
108
  ### Step 5: Create Worktree
103
109
 
104
110
  ```bash
@@ -204,6 +210,7 @@ No need to mark as `skip-worktree` — the committed files are merge-safe per CH
204
210
  **Branch**: [branch-name]
205
211
  **Path**: [worktree-path]
206
212
  **Main repo**: [main-repo-path]
213
+ **Base**: origin/[production] ([sha])
207
214
  **CodeByPlan**: Registered (worktree ID: [id])
208
215
 
209
216
  ### Setup
@@ -10,12 +10,12 @@ effort: high
10
10
 
11
11
  Codifies the long-lived-branch-integration auto-memory rule (`[[feedback_long-lived-branch-integration]]`): when working on a feat branch that has diverged from main, merge main INTO the feat branch (not the reverse), resolve conflicts with the user, run a scoped QA pass, then return control to the caller — never rebase, never force-push, never push automatically.
12
12
 
13
- Triggered by `/cbp-task-start` (Step 3.6, optional stale-check), `/cbp-task-complete` (Step 4.5, mandatory pre-complete), and `/cbp-checkpoint-end` (Step 0, mandatory pre-shipment). User can also invoke manually at any time.
13
+ Triggered by `/cbp-task-start` (Step 3.6, optional stale-check), `/cbp-task-complete` (Step 5.5, mandatory pre-push — runs after the task commit on a clean tree), and `/cbp-checkpoint-end` (Step 0, mandatory pre-shipment). User can also invoke manually at any time.
14
14
 
15
15
  ## When to Use
16
16
 
17
17
  - **Auto-trigger (optional)**: `/cbp-task-start` Step 3.6 detects the feat branch is >10 commits behind `origin/{BASE}` OR the last fetch is >24h old.
18
- - **Auto-trigger (mandatory)**: `/cbp-task-complete` Step 4.5 — always run before marking a task complete to ensure the feat branch includes the latest main work.
18
+ - **Auto-trigger (mandatory)**: `/cbp-task-complete` Step 5.5 — mandatory pre-push, after the task commit; runs on a clean tree to ensure the feat branch includes the latest main work before the single trailing push.
19
19
  - **Auto-trigger (mandatory)**: `/cbp-checkpoint-end` Step 0 — always run before shipment to ensure no main drift reaches production.
20
20
  - **Manual invocation**: user runs `/cbp-merge-main` directly when they know main has advanced and want to pull it in immediately.
21
21
 
@@ -219,7 +219,7 @@ Return control to the caller. **This skill NEVER pushes** — the caller decides
219
219
 
220
220
  - **Triggered by**:
221
221
  - `/cbp-task-start` Step 3.6 (optional stale-check: >10 commits behind OR >24h fetch age)
222
- - `/cbp-task-complete` Step 4.5 (mandatory pre-complete)
222
+ - `/cbp-task-complete` Step 5.5 (mandatory pre-push, after task commit)
223
223
  - `/cbp-checkpoint-end` Step 0 (mandatory pre-shipment)
224
224
  - User-invocable manually
225
225
  - **Reads**: `.codebyplan/git.json`, MCP `get_checkpoints`, MCP `get_tasks`, git state
@@ -74,6 +74,31 @@ 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 asset-update CLIs operate on the freshest tree.
82
+
83
+ Resolve the production branch: read `.codebyplan/git.json` and take `branch_config.production` (fall back to `main` if the file or field is absent). Call this `$PRODUCTION`. Then compare the current branch against the worktree's folder name:
84
+
85
+ ```bash
86
+ FOLDER="$(basename "$(git rev-parse --show-toplevel)")"
87
+ CURRENT="$(git rev-parse --abbrev-ref HEAD)"
88
+ ```
89
+
90
+ - **`$CURRENT` != `$FOLDER`** (a `feat/*` or any non-home branch): skip silently — no fetch, no output.
91
+ - **`$CURRENT` == `$FOLDER`** (home branch): fast-forward to `origin/$PRODUCTION`, warning once per failure and continuing:
92
+
93
+ ```bash
94
+ git fetch origin "$PRODUCTION" 2>/dev/null \
95
+ || echo "⚠ home-branch ff: fetch failed — staying on local $CURRENT"
96
+ git merge --ff-only "origin/$PRODUCTION" 2>/dev/null \
97
+ || echo "⚠ home-branch ff: $CURRENT not fast-forwardable (ahead/diverged) — left untouched"
98
+ ```
99
+
100
+ Never rebase, reset, force-push, or stash. A non-fast-forwardable home branch is a signal to reconcile manually, not to overwrite.
101
+
77
102
  ### Step 1.7: Auto-Update CodeByPlan Assets
78
103
 
79
104
  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.
@@ -179,7 +204,7 @@ You can close this window.
179
204
  ## Integration
180
205
 
181
206
  - **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)
207
+ - **Reads**: `.codebyplan/repo.json`, `.codebyplan/git.json` (`branch_config.production` for the Step 1.6 home-branch fast-forward), MCP `get_session_logs` (resolve current log), MCP `get_current_task`, MCP `get_rounds`, MCP `get_next_action` (Step 1.3 handoff snapshot)
183
208
  - **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
209
  - **Spawns**: none
185
210
  - **Triggers**: none at the skill-contract level. Steps 1.5 and 1.7 may invoke `/cbp-git-commit` inline on user approval.
@@ -12,7 +12,7 @@ Activate the session, open a fresh session log, and surface the previous log's p
12
12
 
13
13
  ## Instructions
14
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`.
15
+ Do Steps 0–5 and Step 4.5 silently (no intermediate output). Step 1.4 may surface a one-line fast-forward note or warning, and Step 5.7 may surface an approval gate. Produce ONE output block at Step 6, then auto-trigger `/cbp-todo`.
16
16
 
17
17
  ### Step 0: MCP Health Check
18
18
 
@@ -50,6 +50,29 @@ Pass `WORKTREE_ID` to MCP tools that support it. Empty output means the (device,
50
50
 
51
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
52
 
53
+ ### Step 1.4: Home-Branch Fast-Forward
54
+
55
+ 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.
56
+
57
+ Resolve the production branch: read `.codebyplan/git.json` and take `branch_config.production` (fall back to `main` if the file or field is absent). Call this `$PRODUCTION`. Then compare the current branch against the worktree's folder name:
58
+
59
+ ```bash
60
+ FOLDER="$(basename "$(git rev-parse --show-toplevel)")"
61
+ CURRENT="$(git rev-parse --abbrev-ref HEAD)"
62
+ ```
63
+
64
+ - **`$CURRENT` != `$FOLDER`** (a `feat/*` or any non-home branch): skip silently — no fetch, no output.
65
+ - **`$CURRENT` == `$FOLDER`** (home branch): fast-forward to `origin/$PRODUCTION`, warning once per failure and continuing:
66
+
67
+ ```bash
68
+ git fetch origin "$PRODUCTION" 2>/dev/null \
69
+ || echo "⚠ home-branch ff: fetch failed — staying on local $CURRENT"
70
+ git merge --ff-only "origin/$PRODUCTION" 2>/dev/null \
71
+ || echo "⚠ home-branch ff: $CURRENT not fast-forwardable (ahead/diverged) — left untouched"
72
+ ```
73
+
74
+ Never rebase, reset, force-push, or stash. A non-fast-forwardable home branch is a signal to reconcile manually, not to overwrite.
75
+
53
76
  ### Step 2: Check Dev Server
54
77
 
55
78
  **Skip if `server_type` is `"none"`.**
@@ -147,7 +170,7 @@ Trigger `/cbp-todo` to determine what to work on.
147
170
  ## Integration
148
171
 
149
172
  - **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)
173
+ - **Reads**: `.codebyplan/repo.json`, `.codebyplan/git.json` (`branch_config.production` for the Step 1.4 home-branch fast-forward), 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
174
  - **Writes**: MCP `create_session_log` (new, possibly empty), MCP `update_session_state` (activate)
152
175
  - **Spawns**: none
153
176
  - **Triggers**: `/cbp-git-commit` (conditional, on user approval), `handoff.command` (on fresh handoff hit at Step 4.5), `/cbp-todo` (auto fall-through)
@@ -102,26 +102,34 @@ Load `task.qa` and `task.files_changed`:
102
102
 
103
103
  Collect all files_changed from task. Deduplicate (latest action wins).
104
104
 
105
- ### Step 4.5: Merge Production Branch Before Commit (mandatory)
105
+ ### Step 5: Git Commit (no push)
106
106
 
107
- Before committing task work, ensure the feat branch is current with the latest production (main) work. This prevents shipping a stale PR and surfaces conflicts at task-complete time rather than at PR review.
107
+ Commit the task work FIRST, so the merge in Step 5.5 runs against a clean tree. `/cbp-merge-main` must never run before the task commit.
108
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 — do NOT proceed to Step 5 (commit). The user resolves and re-invokes `/cbp-task-complete`.
111
- 3. If the skill exits with QA warnings the user chose to commit-as-is: continue to Step 5; surface a soft warning in the Step 9 output (`⚠ Merged with QA failures pending fix in follow-up`).
112
- 4. On clean success: continue to Step 5.
109
+ **Zero-file guard**: if `aggregated_files` is empty (investigative or DB-only tasks), skip the commit. Record "No git commit: zero files changed" in the Step 9 summary, then continue to Step 5.5 (the branch may still need a main sync).
110
+
111
+ **Already-committed guard**: if the aggregated files are already committed (working tree clean for them — e.g. a re-invoke after a Step 5.5 merge failure), skip the commit and continue to Step 5.5; the prior run's task commit still stands.
112
+
113
+ Otherwise: invoke `/cbp-git-commit` to stage approved files and create the commit. Claude does NOT git add directly. Do NOT push here — the push in Step 5.7 carries both this commit and the merge commit.
113
114
 
114
- ### Step 5: Git Commit and Push
115
+ ### Step 5.5: Merge Production Branch (mandatory)
116
+
117
+ Now that task work is committed, ensure the feat branch is current with the latest production (main) work. Running the merge AFTER the commit means `/cbp-merge-main` resolves conflicts against committed work on a clean tree — no dirty-tree interleave, no Step-0 dirty-tree prompt for the task files. This still prevents shipping a stale PR and surfaces conflicts at task-complete time rather than at PR review.
118
+
119
+ 1. Trigger `/cbp-merge-main`.
120
+ 2. If the skill exits with failure (offline, unresolved conflicts, user-aborted): surface the failure and STOP — do NOT proceed to Step 5.7 (push) or Step 7 (complete). The task commit from Step 5 persists; the user resolves and re-invokes `/cbp-task-complete`, which re-runs the merge on the now-clean tree.
121
+ 3. If the skill exits with QA warnings the user chose to commit-as-is: continue to Step 5.7; surface a soft warning in the Step 9 output (`⚠ Merged with QA failures pending fix in follow-up`).
122
+ 4. On clean success: continue to Step 5.7.
115
123
 
116
- **Zero-file guard**: if `aggregated_files` is empty (investigative or DB-only tasks), skip commit and push. Record "No git commit: zero files changed" in the Step 9 summary.
124
+ ### Step 5.7: Push
117
125
 
118
- Otherwise: invoke `/cbp-git-commit` to stage approved files and create the commit. Claude does NOT git add directly. After commit:
126
+ Push once, carrying BOTH the task commit (Step 5) and the merge commit (Step 5.5):
119
127
 
120
128
  ```bash
121
129
  git push origin $(git branch --show-current)
122
130
  ```
123
131
 
124
- If push fails, investigate and fix per migration-infrastructure rule — never skip.
132
+ Skip the push only when nothing was committed in Step 5 AND `/cbp-merge-main` reported already-up-to-date (nothing to push). If push fails, investigate and fix per migration-infrastructure rule — never skip.
125
133
 
126
134
  ### Step 6: Update Task Files
127
135