cortex-agents 4.0.7 → 4.1.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.
@@ -23,6 +23,8 @@ tools:
23
23
  session_list: true
24
24
  branch_status: true
25
25
  branch_create: true
26
+ worktree_create: true
27
+ worktree_list: true
26
28
  docs_list: true
27
29
  github_status: true
28
30
  github_issues: true
@@ -141,8 +143,9 @@ After committing the plan, use the **question tool** with these exact options:
141
143
  **Only after the user selects an option**, execute the corresponding action:
142
144
 
143
145
  - **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
+ - Use `worktree_create` with `name` derived from the suggested branch slug, `type` from the plan type, and `fromBranch` set to the suggested branch name from `plan_commit`
147
+ - The tool auto-deduplicates if the branch already exists (appends `-2`, `-3`, etc.)
148
+ - Report the worktree path and **actual branch name** (may differ from suggestion if deduplicated)
146
149
  - Suggest: "Navigate to the worktree and run OpenCode with the Implement agent to begin implementation"
147
150
 
148
151
  - **User chose "Create a branch"**:
@@ -329,6 +332,8 @@ sequenceDiagram
329
332
  - `session_save` - Save session summary
330
333
  - `branch_status` - Check current git state
331
334
  - `branch_create` - Create a new branch (used during handoff to implementation)
335
+ - `worktree_create` - Create an isolated worktree for parallel development (used during handoff)
336
+ - `worktree_list` - List existing worktrees (check before creating)
332
337
  - `github_status` - Check GitHub CLI availability, auth, and detect projects
333
338
  - `github_issues` - List/filter GitHub issues for work item selection
334
339
  - `github_projects` - List GitHub Project boards and their work items
@@ -1,5 +1,5 @@
1
1
  ---
2
- description: Multi-layer code implementation across frontend, backend, and database
2
+ description: Code implementation sub-agent handles all task types
3
3
  mode: subagent
4
4
  temperature: 0.3
5
5
  tools:
@@ -13,7 +13,7 @@ permission:
13
13
  bash: ask
14
14
  ---
15
15
 
16
- You are a fullstack developer. You implement complete features spanning frontend, backend, and database layers with consistent contracts across the stack.
16
+ You are a skilled developer. You implement tasks ranging from single-file changes to full-stack features spanning frontend, backend, and database layers with consistent contracts across the stack.
17
17
 
18
18
  ## Auto-Load Skills (based on affected layers)
19
19
 
@@ -37,12 +37,14 @@ You are launched as a sub-agent by a primary agent in one of two contexts:
37
37
 
38
38
  ### Context A — Implementation (from implement agent)
39
39
 
40
- You receive requirements and implement end-to-end features across multiple layers. You will get:
41
- - The plan or requirements describing the feature
42
- - Current codebase structure for relevant layers
43
- - Any API contracts or interfaces that need to be consistent across layers
40
+ You receive requirements and implement the task. Tasks range from single-file changes to end-to-end features across multiple layers. You will get:
41
+ - The task title, description, and acceptance criteria
42
+ - Relevant files and codebase structure
43
+ - Build/test commands for verification
44
+ - Files modified by previous tasks (for cross-task consistency)
45
+ - On retries: error output from failed build/test and summary of previous attempt
44
46
 
45
- **Your job:** Implement the feature across all affected layers, maintaining consistency. Write the code, ensure interfaces match, and return a structured summary.
47
+ **Your job:** Implement the task, write the code, ensure interfaces match (for multi-layer tasks), and return a structured summary.
46
48
 
47
49
  ### Context B — Feasibility Analysis (from architect agent)
48
50
 
@@ -57,6 +59,24 @@ You receive requirements and analyze implementation feasibility. You will get:
57
59
 
58
60
  ### For Context A (Implementation)
59
61
 
62
+ Use the format that matches the task scope:
63
+
64
+ **Single-layer / focused tasks:**
65
+ ```
66
+ ### Implementation Summary
67
+ - **Files created**: [count]
68
+ - **Files modified**: [count]
69
+
70
+ ### Changes
71
+ - `path/to/file.ts` — [what was done]
72
+ - `path/to/file.test.ts` — [what was done]
73
+
74
+ ### Notes
75
+ - [Any assumptions made]
76
+ - [Things the orchestrating agent should verify]
77
+ ```
78
+
79
+ **Multi-layer / full-stack tasks:**
60
80
  ```
61
81
  ### Implementation Summary
62
82
  - **Layers modified**: [frontend, backend, database, infrastructure]
@@ -66,7 +66,7 @@ permission:
66
66
  "npm run lint --*": allow
67
67
  ---
68
68
 
69
- You are an expert software developer. Your role is to write clean, maintainable, and well-tested code.
69
+ You are an expert software development orchestrator. Your role is to analyze plans, delegate implementation tasks to the `@coder` sub-agent, verify results, and manage the development workflow. You do NOT write code directly — all code changes are performed by `@coder`.
70
70
 
71
71
  ## Pre-Implementation Workflow (MANDATORY)
72
72
 
@@ -129,9 +129,9 @@ Implement plan tasks iteratively using the REPL loop. Each task goes through a *
129
129
 
130
130
  **Session recovery:** Run `repl_resume` first to check for an interrupted loop from a previous session. If found, it will show progress and the interrupted task — skip to 6b to continue.
131
131
 
132
- **If no plan was loaded in Step 3**, fall back to implementing changes directly (skip to 6c without the loop tools) and proceed to Step 7 when done.
132
+ **If no plan was loaded in Step 3**, delegate the user's request to `@coder` via the Task tool (skip to 6c without the loop tools) and proceed to Step 7 when done.
133
133
 
134
- **Multi-layer feature detection:** If the task involves changes across 3+ layers (e.g., database + API + frontend, or CLI + library + tests), launch the **@coder sub-agent** via the Task tool to implement the end-to-end feature.
134
+ **ALL implementation tasks are delegated to `@coder`.** The implement agent does NOT write code directly. For every task, prepare context and launch `@coder` via the Task tool (see Step 6c).
135
135
 
136
136
  #### 6a: Initialize the Loop
137
137
  Run `repl_init` with the plan filename from Step 3.
@@ -140,8 +140,12 @@ Review the auto-detected build/test commands. If they look wrong, re-run with ma
140
140
  #### 6b: Check Loop Status
141
141
  Run `repl_status` to see the next pending task, current progress, build/test commands, and acceptance criteria (ACs) for the current task. Implement to satisfy all listed ACs.
142
142
 
143
- #### 6c: Implement the Current Task
144
- Read the task description and implement it. Write the code changes needed for that specific task.
143
+ #### 6c: Delegate to @coder Sub-Agent
144
+ Prepare context from `repl_status` output and launch `@coder` via the Task tool:
145
+ 1. **Gather context** — Task title, description, acceptance criteria, relevant files, and build/test commands from the `repl_status` output
146
+ 2. **Include cross-task context** — List files created or modified by previous tasks so `@coder` can maintain consistency
147
+ 3. **Launch `@coder`** — Pass all gathered context via the Task tool
148
+ 4. **Review the summary** — When `@coder` returns, review its implementation summary before proceeding to 6d (verification)
145
149
 
146
150
  #### 6d: Verify — Build + Test
147
151
  Run the build command (from repl_status output) via bash.
@@ -157,7 +161,7 @@ Run `repl_report` with the result:
157
161
  #### 6f: Loop Decision
158
162
  Based on the repl_report response:
159
163
  - **"Next: Task #N"** → Go to 6b (pick up next task)
160
- - **"Fix the issue, N retries remaining"** → Fix the code, go to 6d (re-verify)
164
+ - **"Fix the issue, N retries remaining"** → Re-launch `@coder` with: the original task description, error output from the failed build/test, and a summary of the previous `@coder` attempt. Then go to 6d (re-verify)
161
165
  - **"ASK THE USER"** → Use the question tool:
162
166
  "Task #N has failed after 3 attempts. How would you like to proceed?"
163
167
  Options:
@@ -410,7 +414,7 @@ The following sub-agents are available via the Task tool. **Launch multiple sub-
410
414
  | `@audit` | Standard + High scope changes | Code quality, tech debt, pattern review | Step 7 — scope-based |
411
415
  | `@docs-writer` | Standard + High scope changes | Auto-generates decision/feature/flow docs | Step 7 — scope-based |
412
416
  | `@perf` | High scope or hot-path/DB/render changes | Complexity analysis, N+1 detection, bundle impact | Step 7 — conditional |
413
- | `@coder` | Multi-layer features (3+ layers) | End-to-end implementation across frontend/backend/database | Step 6conditional |
417
+ | `@coder` | ALL implementation tasks | Code implementation for every task — single-file to full-stack | Step 6calways |
414
418
  | `@devops` | High scope or CI/CD/Docker/infra files changed | Config validation, best practices checklist | Step 7 — conditional |
415
419
  | `@refactor` | Plan type is `refactor` | Behavior-preserving restructuring with test verification | Step 6 — conditional |
416
420
  | `@debug` | Issues found during implementation | Root cause analysis, troubleshooting | Step 6 — conditional |
@@ -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;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"}
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;;;;;;;;;;;;;;;;;;;;EAgJ1C;AAED,eAAO,MAAM,IAAI;;;;CAiCf,CAAC;AAEH;;;GAGG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM;;;;;;;;;;EAyG1C;AAED,eAAO,MAAM,IAAI;;;;;;;;CAgDf,CAAC"}
@@ -2,7 +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
+ import { detectWorktreeInfo, deduplicateBranch } from "../utils/worktree-detect.js";
6
6
  const WORKTREE_ROOT = ".worktrees";
7
7
  /**
8
8
  * Factory function that creates the worktree_create tool with access
@@ -26,7 +26,9 @@ export function createCreate(client) {
26
26
  },
27
27
  async execute(args, context) {
28
28
  const { name, type, fromBranch } = args;
29
- const branchName = fromBranch || `${type}/${name}`;
29
+ let branchName = fromBranch || `${type}/${name}`;
30
+ const originalBranch = branchName;
31
+ let deduplicated = false;
30
32
  const worktreePath = path.join(context.worktree, WORKTREE_ROOT, name);
31
33
  const absoluteWorktreePath = path.resolve(worktreePath);
32
34
  // Check if we're in a git repository
@@ -58,21 +60,30 @@ Use worktree_list to see existing worktrees.`;
58
60
  try {
59
61
  await git(context.worktree, "worktree", "add", "-b", fromBranch, absoluteWorktreePath);
60
62
  }
61
- catch (error2) {
63
+ catch {
64
+ // Both failed — try deduplication
62
65
  try {
63
- await client.tui.showToast({
64
- body: {
65
- title: `Worktree: ${name}`,
66
- message: `Failed to create from branch '${fromBranch}': ${error2.message || error2}`,
67
- variant: "error",
68
- duration: 8000,
69
- },
70
- });
66
+ const uniqueBranch = await deduplicateBranch(context.worktree, fromBranch);
67
+ await git(context.worktree, "worktree", "add", "-b", uniqueBranch, absoluteWorktreePath);
68
+ branchName = uniqueBranch;
69
+ deduplicated = true;
71
70
  }
72
- catch {
73
- // Toast failure is non-fatal
71
+ catch (error3) {
72
+ try {
73
+ await client.tui.showToast({
74
+ body: {
75
+ title: `Worktree: ${name}`,
76
+ message: `Failed to create from branch '${fromBranch}': ${error3.message || error3}`,
77
+ variant: "error",
78
+ duration: 8000,
79
+ },
80
+ });
81
+ }
82
+ catch {
83
+ // Toast failure is non-fatal
84
+ }
85
+ return `\u2717 Error creating worktree from branch '${fromBranch}': ${error3.message || error3}`;
74
86
  }
75
- return `\u2717 Error creating worktree from branch '${fromBranch}': ${error2.message || error2}`;
76
87
  }
77
88
  }
78
89
  }
@@ -86,21 +97,30 @@ Use worktree_list to see existing worktrees.`;
86
97
  try {
87
98
  await git(context.worktree, "worktree", "add", absoluteWorktreePath, branchName);
88
99
  }
89
- catch (error2) {
100
+ catch {
101
+ // Both failed — try deduplication
90
102
  try {
91
- await client.tui.showToast({
92
- body: {
93
- title: `Worktree: ${name}`,
94
- message: `Failed to create: ${error2.message || error2}`,
95
- variant: "error",
96
- duration: 8000,
97
- },
98
- });
103
+ const uniqueBranch = await deduplicateBranch(context.worktree, branchName);
104
+ await git(context.worktree, "worktree", "add", "-b", uniqueBranch, absoluteWorktreePath);
105
+ branchName = uniqueBranch;
106
+ deduplicated = true;
99
107
  }
100
- catch {
101
- // Toast failure is non-fatal
108
+ catch (error3) {
109
+ try {
110
+ await client.tui.showToast({
111
+ body: {
112
+ title: `Worktree: ${name}`,
113
+ message: `Failed to create: ${error3.message || error3}`,
114
+ variant: "error",
115
+ duration: 8000,
116
+ },
117
+ });
118
+ }
119
+ catch {
120
+ // Toast failure is non-fatal
121
+ }
122
+ return `\u2717 Error creating worktree: ${error3.message || error3}`;
102
123
  }
103
- return `\u2717 Error creating worktree: ${error2.message || error2}`;
104
124
  }
105
125
  }
106
126
  }
@@ -119,10 +139,13 @@ Use worktree_list to see existing worktrees.`;
119
139
  catch {
120
140
  // Toast failure is non-fatal
121
141
  }
142
+ const dedupeNote = deduplicated
143
+ ? `\n\nNote: Branch '${originalBranch}' was unavailable. Using '${branchName}' instead.`
144
+ : "";
122
145
  return `\u2713 Created worktree successfully
123
146
 
124
147
  Branch: ${branchName}${fromLabel}
125
- Path: ${absoluteWorktreePath}
148
+ Path: ${absoluteWorktreePath}${dedupeNote}
126
149
 
127
150
  To work in this worktree:
128
151
  cd ${absoluteWorktreePath}
@@ -1,3 +1,8 @@
1
+ /**
2
+ * Finds a unique branch name by appending -2, -3, etc. if the base name exists.
3
+ * Returns the first available candidate from baseName-2 through baseName-10.
4
+ */
5
+ export declare function deduplicateBranch(cwd: string, baseName: string): Promise<string>;
1
6
  /**
2
7
  * Information about the current worktree context.
3
8
  */
@@ -1 +1 @@
1
- {"version":3,"file":"worktree-detect.d.ts","sourceRoot":"","sources":["../../src/utils/worktree-detect.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,qFAAqF;IACrF,UAAU,EAAE,OAAO,CAAC;IACpB,8BAA8B;IAC9B,aAAa,EAAE,MAAM,CAAC;IACtB,2EAA2E;IAC3E,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;CACjC;AAED;;;;;;GAMG;AACH,wBAAsB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,CAqC3E"}
1
+ {"version":3,"file":"worktree-detect.d.ts","sourceRoot":"","sources":["../../src/utils/worktree-detect.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,wBAAsB,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAOtF;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,qFAAqF;IACrF,UAAU,EAAE,OAAO,CAAC;IACpB,8BAA8B;IAC9B,aAAa,EAAE,MAAM,CAAC;IACtB,2EAA2E;IAC3E,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;CACjC;AAED;;;;;;GAMG;AACH,wBAAsB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,CAqC3E"}
@@ -1,5 +1,18 @@
1
1
  import * as path from "path";
2
2
  import { git } from "./shell.js";
3
+ /**
4
+ * Finds a unique branch name by appending -2, -3, etc. if the base name exists.
5
+ * Returns the first available candidate from baseName-2 through baseName-10.
6
+ */
7
+ export async function deduplicateBranch(cwd, baseName) {
8
+ for (let i = 2; i <= 10; i++) {
9
+ const candidate = `${baseName}-${i}`;
10
+ const { stdout } = await git(cwd, "branch", "--list", candidate);
11
+ if (!stdout.trim())
12
+ return candidate;
13
+ }
14
+ throw new Error(`Could not find unique branch name after 10 attempts (base: ${baseName})`);
15
+ }
3
16
  /**
4
17
  * Detect whether the current git directory is a linked worktree.
5
18
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cortex-agents",
3
- "version": "4.0.7",
3
+ "version": "4.1.0",
4
4
  "description": "Supercharge OpenCode with structured workflows, intelligent agents, and automated development practices",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",