cortex-agents 4.0.5 → 4.0.7
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.
|
@@ -126,24 +126,33 @@ Use `plan_save` with:
|
|
|
126
126
|
|
|
127
127
|
**If plan_commit fails** (e.g., nothing to stage), inform the user.
|
|
128
128
|
|
|
129
|
-
### Step 5: Handoff to Implementation
|
|
130
|
-
|
|
129
|
+
### Step 5: Handoff to Implementation (MUST ASK — NEVER skip)
|
|
130
|
+
|
|
131
|
+
**CRITICAL: You MUST use the question tool to ask the user before creating any branch or worktree. NEVER call `branch_create` or `worktree_create` without explicit user selection. Do NOT assume a choice — always present the options and WAIT for the user's response.**
|
|
132
|
+
|
|
133
|
+
After committing the plan, use the **question tool** with these exact options:
|
|
131
134
|
|
|
132
135
|
"Plan committed. Suggested branch: `{suggestedBranch}`. How would you like to proceed?"
|
|
133
136
|
|
|
134
|
-
1. **Create a worktree (Recommended)** —
|
|
135
|
-
2. **
|
|
137
|
+
1. **Create a worktree (Recommended)** — Isolated copy in `.worktrees/` for parallel development. This is the safest option.
|
|
138
|
+
2. **Create a branch** — Create and switch to `{suggestedBranch}` in this repo
|
|
136
139
|
3. **Stay in Architect mode** — Continue planning or refine the plan
|
|
137
140
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
-
|
|
141
|
-
-
|
|
141
|
+
**Only after the user selects an option**, execute the corresponding action:
|
|
142
|
+
|
|
143
|
+
- **User chose "Create a worktree"**:
|
|
144
|
+
- Use `worktree_create` with `name` derived from the suggested branch slug and `type` from the plan type
|
|
145
|
+
- Report the worktree path so the user can navigate to it
|
|
146
|
+
- Suggest: "Navigate to the worktree and run OpenCode with the Implement agent to begin implementation"
|
|
147
|
+
|
|
148
|
+
- **User chose "Create a branch"**:
|
|
149
|
+
- Use `branch_create` with the suggested branch name (type and name from the plan)
|
|
150
|
+
- This creates and switches to the new branch
|
|
151
|
+
- Then switch to the Implement agent
|
|
142
152
|
|
|
143
|
-
|
|
144
|
-
-
|
|
145
|
-
-
|
|
146
|
-
- Then switch to the Implement agent
|
|
153
|
+
- **User chose "Stay in Architect mode"**:
|
|
154
|
+
- Do NOT create any branch or worktree
|
|
155
|
+
- Continue in the current session for further planning
|
|
147
156
|
|
|
148
157
|
### Step 6: Provide Handoff Context
|
|
149
158
|
If user chooses to switch agents, provide:
|
|
@@ -88,37 +88,40 @@ If a plan exists, load it with `plan_load`.
|
|
|
88
88
|
|
|
89
89
|
**Suggested branch detection:** If the loaded plan has a `branch` field in its frontmatter (set by `plan_commit`), this is the **suggested branch name** for implementation. The branch may or may not exist yet — `plan_commit` only writes the suggestion, it does not create the branch.
|
|
90
90
|
|
|
91
|
-
### Step 4: Ask User About Branch Strategy
|
|
91
|
+
### Step 4: Ask User About Branch Strategy (MUST ASK — NEVER skip)
|
|
92
|
+
|
|
93
|
+
**CRITICAL: You MUST use the question tool to ask the user before creating any branch or worktree. NEVER call `branch_create` or `worktree_create` without explicit user selection. Do NOT assume a choice — always present the options and WAIT for the user's response.**
|
|
92
94
|
|
|
93
95
|
**If you are already on the suggested branch (it was created during architect handoff):**
|
|
94
96
|
Skip the branch creation prompt entirely — you're already set up. Inform the user:
|
|
95
97
|
"You're on the plan branch `{branch}`. Ready to implement."
|
|
96
98
|
|
|
97
99
|
**If the plan has a `branch` field BUT the branch doesn't exist yet or you're on a different branch:**
|
|
98
|
-
|
|
100
|
+
Use the **question tool** with these options:
|
|
99
101
|
|
|
100
102
|
"The plan suggests branch `{branch}`. How would you like to proceed?"
|
|
101
103
|
|
|
102
|
-
|
|
103
|
-
1. **Create a worktree (Recommended)** — Isolated copy with the suggested branch name
|
|
104
|
+
1. **Create a worktree (Recommended)** — Isolated copy with the suggested branch name. This is the safest option.
|
|
104
105
|
2. **Create the branch here** — Create and switch to `{branch}` in this repo
|
|
105
106
|
3. **Create a different branch** — Use a custom branch name
|
|
106
107
|
4. **Continue here** — Only if you're certain (not recommended on protected branches)
|
|
107
108
|
|
|
108
109
|
**If no plan exists AND on a protected branch:**
|
|
109
|
-
Use the
|
|
110
|
+
Use the **question tool** with these options:
|
|
110
111
|
|
|
111
112
|
"I'm ready to implement changes. How would you like to proceed?"
|
|
112
113
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
3. **Continue here** - Only if you're certain (not recommended on protected branches)
|
|
114
|
+
1. **Create a worktree (Recommended)** — Isolated copy in `.worktrees/` for parallel development. This is the safest option.
|
|
115
|
+
2. **Create a new branch** — Stay in this repo, create feature/bugfix branch
|
|
116
|
+
3. **Continue here** — Only if you're certain (not recommended on protected branches)
|
|
117
117
|
|
|
118
118
|
### Step 5: Execute Based on Response
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
119
|
+
|
|
120
|
+
**Only after the user selects an option**, execute the corresponding action:
|
|
121
|
+
|
|
122
|
+
- **User chose "Worktree"**: Use `worktree_create` with appropriate type and name. Report the worktree path. Continue working in the current session.
|
|
123
|
+
- **User chose "Create branch"**: Use `branch_create` with the suggested branch name (or custom name)
|
|
124
|
+
- **User chose "Continue"**: Proceed with caution, warn user about risks
|
|
122
125
|
|
|
123
126
|
### Step 6: REPL Implementation Loop
|
|
124
127
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worktree.d.ts","sourceRoot":"","sources":["../../src/tools/worktree.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"worktree.d.ts","sourceRoot":"","sources":["../../src/tools/worktree.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AASvD,KAAK,MAAM,GAAG,WAAW,CAAC,QAAQ,CAAC,CAAC;AAEpC;;;GAGG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM;;;;;;;;;;;;;;;;;;;;EA0H1C;AAED,eAAO,MAAM,IAAI;;;;CAiCf,CAAC;AAEH;;;GAGG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM;;;;;;;;;;EAyG1C;AAED,eAAO,MAAM,IAAI;;;;;;;;CAgDf,CAAC"}
|
package/dist/tools/worktree.js
CHANGED
|
@@ -2,6 +2,7 @@ import { tool } from "@opencode-ai/plugin";
|
|
|
2
2
|
import * as fs from "fs";
|
|
3
3
|
import * as path from "path";
|
|
4
4
|
import { git } from "../utils/shell.js";
|
|
5
|
+
import { detectWorktreeInfo } from "../utils/worktree-detect.js";
|
|
5
6
|
const WORKTREE_ROOT = ".worktrees";
|
|
6
7
|
/**
|
|
7
8
|
* Factory function that creates the worktree_create tool with access
|
|
@@ -175,7 +176,20 @@ export function createRemove(client) {
|
|
|
175
176
|
},
|
|
176
177
|
async execute(args, context) {
|
|
177
178
|
const { name, deleteBranch = false } = args;
|
|
178
|
-
|
|
179
|
+
// Resolve the main repo root — if we're inside a worktree, context.worktree
|
|
180
|
+
// points to the worktree itself, not the main repo. We need the main repo
|
|
181
|
+
// to construct the correct .worktrees/ path and to run git commands from outside.
|
|
182
|
+
let mainRepoRoot = context.worktree;
|
|
183
|
+
try {
|
|
184
|
+
const info = await detectWorktreeInfo(context.worktree);
|
|
185
|
+
if (info.isWorktree && info.mainWorktreePath) {
|
|
186
|
+
mainRepoRoot = info.mainWorktreePath;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
catch {
|
|
190
|
+
// Fall back to context.worktree
|
|
191
|
+
}
|
|
192
|
+
const worktreePath = path.join(mainRepoRoot, WORKTREE_ROOT, name);
|
|
179
193
|
const absoluteWorktreePath = path.resolve(worktreePath);
|
|
180
194
|
// Check if worktree exists
|
|
181
195
|
if (!fs.existsSync(absoluteWorktreePath)) {
|
|
@@ -192,14 +206,15 @@ Use worktree_list to see existing worktrees.`;
|
|
|
192
206
|
catch {
|
|
193
207
|
// Ignore error, branch detection is optional
|
|
194
208
|
}
|
|
195
|
-
// Remove the worktree
|
|
209
|
+
// Remove the worktree — must run from the main repo, not from inside
|
|
210
|
+
// the worktree being removed (git rejects that).
|
|
196
211
|
try {
|
|
197
|
-
await git(
|
|
212
|
+
await git(mainRepoRoot, "worktree", "remove", absoluteWorktreePath);
|
|
198
213
|
}
|
|
199
214
|
catch {
|
|
200
215
|
// Try force remove if there are changes
|
|
201
216
|
try {
|
|
202
|
-
await git(
|
|
217
|
+
await git(mainRepoRoot, "worktree", "remove", "--force", absoluteWorktreePath);
|
|
203
218
|
}
|
|
204
219
|
catch (error2) {
|
|
205
220
|
try {
|
|
@@ -224,7 +239,7 @@ The worktree may have uncommitted changes. Commit or stash them first.`;
|
|
|
224
239
|
// Delete branch if requested
|
|
225
240
|
if (deleteBranch && branchName) {
|
|
226
241
|
try {
|
|
227
|
-
await git(
|
|
242
|
+
await git(mainRepoRoot, "branch", "-d", branchName);
|
|
228
243
|
output += `\n\u2713 Deleted branch ${branchName}`;
|
|
229
244
|
}
|
|
230
245
|
catch (error) {
|
package/package.json
CHANGED