cortex-agents 4.0.6 → 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.
@@ -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;AAQvD,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;;;;;;;;;;EA0F1C;AAED,eAAO,MAAM,IAAI;;;;;;;;CAgDf,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"}
@@ -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
- const worktreePath = path.join(context.worktree, WORKTREE_ROOT, name);
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(context.worktree, "worktree", "remove", absoluteWorktreePath);
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(context.worktree, "worktree", "remove", "--force", absoluteWorktreePath);
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(context.worktree, "branch", "-d", branchName);
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cortex-agents",
3
- "version": "4.0.6",
3
+ "version": "4.0.7",
4
4
  "description": "Supercharge OpenCode with structured workflows, intelligent agents, and automated development practices",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",