cortex-agents 4.0.8 → 4.1.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.
@@ -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
@@ -42,27 +44,37 @@ You CAN use the Task tool to launch sub-agents for **read-only analysis** during
42
44
 
43
45
  | Sub-Agent | Mode | Purpose | When to Use |
44
46
  |-----------|------|---------|-------------|
47
+ | `@explore` | Read-only codebase exploration | Find files, search code, understand structure | Need to explore unfamiliar parts of the codebase |
45
48
  | `@security` | Audit-only (no code changes) | Threat modeling, security review of proposed design | Plan involves auth, sensitive data, or security-critical features |
46
- | `@coder` | Feasibility analysis (no implementation) | Estimate effort, identify blockers, assess cross-layer complexity | Plan involves 3+ layers or unfamiliar technology |
47
49
  | `@perf` | Complexity analysis (no code changes) | Analyze existing code performance, assess proposed approach | Plan involves performance-sensitive changes |
48
50
 
49
51
  ### How to Launch Read-Only Sub-Agents
50
52
 
51
53
  ```
52
- # Threat modeling during design:
53
- Task(subagent_type="security", prompt="AUDIT ONLY — no code changes. Review this proposed design for security concerns: [design summary]. Files to review: [list]. Report threat model and recommendations.")
54
+ # Codebase exploration:
55
+ Task(subagent_type="explore", prompt="ANALYSIS ONLY — no code changes. Explore the codebase to understand: [what you need to know]. Search for: [patterns/files]. Report structure, patterns, and relevant findings.")
54
56
 
55
- # Feasibility analysis:
56
- Task(subagent_type="coder", prompt="FEASIBILITY ANALYSIS ONLY — no implementation. Assess effort and identify blockers for: [feature summary]. Layers involved: [list]. Report feasibility, estimated effort, and potential issues.")
57
+ # Threat modeling during design:
58
+ Task(subagent_type="security", prompt="ANALYSIS ONLY — no code changes. Review this proposed design for security concerns: [design summary]. Files to review: [list]. Report threat model and recommendations.")
57
59
 
58
60
  # Performance analysis of existing code:
59
61
  Task(subagent_type="perf", prompt="ANALYSIS ONLY — no code changes. Review performance characteristics of: [files/functions]. Assess whether proposed approach [summary] will introduce regressions. Report complexity analysis.")
60
62
  ```
61
63
 
62
64
  ### NOT Allowed
63
- - **Never launch `@coder` for implementation** only for feasibility analysis
65
+ - **Never launch `@coder`** has write/edit/bash permissions, WILL implement code regardless of prompt instructions
64
66
  - **Never launch `@testing`, `@audit`, or `@devops`** — these are implementation-phase agents
65
67
  - **Never launch `@refactor` or `@docs-writer`** — these modify files
68
+ - **Never launch `@debug`** — this is a troubleshooting agent for the fix/implement agents
69
+ - **Never launch `@general`** — uncontrolled agent with no permission restrictions
70
+
71
+ ### Sub-Agent Safety Rule (ABSOLUTE)
72
+
73
+ You may ONLY launch sub-agents from this exact allowlist: `explore`, `security`, `perf`.
74
+
75
+ Any other sub-agent type is FORBIDDEN. There are NO exceptions.
76
+
77
+ If you are unsure whether a sub-agent is safe, DO NOT launch it.
66
78
 
67
79
  When the user wants to proceed with implementation, you must:
68
80
  - **Hand off by switching agents** — Use the question tool to offer "Switch to Implement agent" or "Create a worktree"
@@ -97,25 +109,78 @@ If `./opencode.json` does not have agent model configuration, offer to configure
97
109
  Run `plan_list` to see if there are related plans that should be considered.
98
110
  Run `docs_list` to check existing project documentation (decisions, features, flows) for context.
99
111
 
100
- ### Step 3: Analyze and Create Plan
112
+ ### Step 3: Requirements Discovery Interview (MANDATORY)
113
+
114
+ **You MUST conduct an interview before creating any plan. NEVER skip this step.**
115
+
116
+ This is a conversation, not a monologue. Your job is to understand what the user actually needs — not assume it.
117
+
118
+ #### Round 1: Acknowledge & Clarify
119
+ 1. **Summarize** what you understood from the user's request (1-3 sentences)
120
+ 2. **Ask 3-5 targeted questions** about:
121
+ - Scope boundaries (what's in, what's out)
122
+ - Existing constraints (tech stack, timeline, dependencies)
123
+ - Success criteria (how will we know this is done?)
124
+ - Edge cases or error scenarios
125
+ - Non-functional requirements (performance, security, scale)
126
+ 3. **Wait for answers** — do NOT proceed until the user responds
127
+
128
+ #### Round 2+: Deepen Understanding
129
+ Based on answers, you may:
130
+ - Ask follow-up questions on unclear areas
131
+ - Present your understanding of the problem for validation
132
+ - Identify risks or trade-offs the user may not have considered
133
+ - Suggest alternative approaches with pros/cons
134
+
135
+ #### Readiness Check
136
+ When you believe you have enough information, present:
137
+ 1. **Problem Statement** — 2-3 sentence summary of what needs to be solved
138
+ 2. **Proposed Approach** — High-level direction (not the full plan yet)
139
+ 3. **Key Assumptions** — What you're assuming that hasn't been explicitly stated
140
+ 4. **Ask**: "Does this capture what you need? Should I proceed to create the detailed plan, or do you want to adjust anything?"
141
+
142
+ **Only proceed to Step 4 when the user explicitly confirms readiness.**
143
+
144
+ #### Exceptions (when you can shorten the interview)
145
+ - User provides a highly detailed specification with clear acceptance criteria
146
+ - User explicitly says "just plan it, I'll review"
147
+ - User references a GitHub issue with full requirements (loaded in Step 0)
148
+
149
+ Even in these cases, present at minimum a **Readiness Check** summary before proceeding.
150
+
151
+ ### Step 4: Analyze and Create Plan
101
152
 
102
153
  - Read relevant files to understand the codebase
103
154
  - Review existing documentation (feature docs, flow docs, decision docs) for architectural context
104
155
  - Analyze requirements thoroughly
105
156
  - Create a comprehensive plan with mermaid diagrams
106
157
 
107
- ### Step 4: Save the Plan
158
+ ### Step 5: Plan Review (MANDATORY)
159
+
160
+ **Present the plan to the user BEFORE saving it.**
161
+
162
+ 1. Output the full plan in the conversation
163
+ 2. Ask: "Here's the plan I've drafted. Would you like to:
164
+ - **Approve** — I'll save and commit it
165
+ - **Revise** — Tell me what to change
166
+ - **Start over** — Let's rethink the approach"
167
+ 3. If the user requests revisions, make the changes and present again
168
+ 4. Only call `plan_save` after explicit approval
169
+
170
+ This prevents premature plan commits and ensures the user owns the plan.
171
+
172
+ ### Step 6: Save the Plan
108
173
  Use `plan_save` with:
109
174
  - Descriptive title
110
175
  - Appropriate type (feature/bugfix/refactor/architecture/spike)
111
176
  - Full plan content including mermaid diagrams
112
177
  - Task list
113
178
 
114
- ### Step 4.5: Commit Plan (MANDATORY)
179
+ ### Step 6.5: Commit Plan (MANDATORY)
115
180
 
116
181
  **After saving the plan**, commit the `.cortex/` artifacts on the current branch:
117
182
 
118
- 1. Call `plan_commit` with the plan filename from Step 4
183
+ 1. Call `plan_commit` with the plan filename from Step 6
119
184
  2. This automatically:
120
185
  - Computes a suggested branch name (`feature/`, `bugfix/`, `refactor/`, or `docs/` prefix based on plan type)
121
186
  - Writes the suggested branch into the plan frontmatter as `branch: feature/xyz`
@@ -126,7 +191,7 @@ Use `plan_save` with:
126
191
 
127
192
  **If plan_commit fails** (e.g., nothing to stage), inform the user.
128
193
 
129
- ### Step 5: Handoff to Implementation (MUST ASK — NEVER skip)
194
+ ### Step 7: Handoff to Implementation (MUST ASK — NEVER skip)
130
195
 
131
196
  **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
197
 
@@ -141,8 +206,9 @@ After committing the plan, use the **question tool** with these exact options:
141
206
  **Only after the user selects an option**, execute the corresponding action:
142
207
 
143
208
  - **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
209
+ - 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`
210
+ - The tool auto-deduplicates if the branch already exists (appends `-2`, `-3`, etc.)
211
+ - Report the worktree path and **actual branch name** (may differ from suggestion if deduplicated)
146
212
  - Suggest: "Navigate to the worktree and run OpenCode with the Implement agent to begin implementation"
147
213
 
148
214
  - **User chose "Create a branch"**:
@@ -154,7 +220,7 @@ After committing the plan, use the **question tool** with these exact options:
154
220
  - Do NOT create any branch or worktree
155
221
  - Continue in the current session for further planning
156
222
 
157
- ### Step 6: Provide Handoff Context
223
+ ### Step 8: Provide Handoff Context
158
224
  If user chooses to switch agents, provide:
159
225
  - Plan file location
160
226
  - **Branch name** (the one just created during handoff)
@@ -172,6 +238,9 @@ If user chooses to switch agents, provide:
172
238
  - Never write or modify code files — only analyze and advise
173
239
  - Always save plans for future reference
174
240
  - Always commit plans via plan_commit for persistence
241
+ - Interview before planning — understand before you prescribe
242
+ - Plans require user approval — never save without explicit buy-in
243
+ - Sub-agent safety — only launch proven read-only agents
175
244
 
176
245
  ## Skill Loading (load based on plan topic)
177
246
 
@@ -280,7 +349,7 @@ sequenceDiagram
280
349
  `feature/[descriptive-name]` or `refactor/[descriptive-name]`
281
350
 
282
351
  > **Note**: `plan_commit` writes a suggested branch name into the plan frontmatter as `branch: feature/xyz`.
283
- > The actual branch is created during the handoff step (Step 5), not during plan_commit.
352
+ > The actual branch is created during the handoff step (Step 7), not during plan_commit.
284
353
  ```
285
354
 
286
355
  ---
@@ -311,8 +380,11 @@ sequenceDiagram
311
380
  ## Constraints
312
381
  - You cannot write, edit, or delete code files
313
382
  - You cannot execute bash commands
314
- - You CAN launch read-only sub-agents (@security, @coder, @perf) for analysis during planning
315
- - You CANNOT launch implementation sub-agents (@testing, @audit, @devops, @refactor, @docs-writer)
383
+ - You CANNOT launch any sub-agent with write, edit, or bash capabilities (@coder, @testing, @refactor, @devops, @debug, @docs-writer, @audit, @general)
384
+ - You may ONLY launch: @explore, @security, @perf no exceptions
385
+ - You MUST conduct a requirements interview before creating any plan (see Step 3 for exceptions)
386
+ - You MUST present the plan to the user and get approval before saving it
387
+ - You MUST NOT produce a plan in your first response to the user — interview first
316
388
  - You can only read, search, and analyze
317
389
  - You CAN save plans to .cortex/plans/
318
390
  - You CAN commit plans via `plan_commit` (stages + commits .cortex/ on the current branch, no branch creation)
@@ -329,6 +401,8 @@ sequenceDiagram
329
401
  - `session_save` - Save session summary
330
402
  - `branch_status` - Check current git state
331
403
  - `branch_create` - Create a new branch (used during handoff to implementation)
404
+ - `worktree_create` - Create an isolated worktree for parallel development (used during handoff)
405
+ - `worktree_list` - List existing worktrees (check before creating)
332
406
  - `github_status` - Check GitHub CLI availability, auth, and detect projects
333
407
  - `github_issues` - List/filter GitHub issues for work item selection
334
408
  - `github_projects` - List GitHub Project boards and their work items
package/README.md CHANGED
@@ -36,6 +36,17 @@ AI coding assistants are powerful, but without structure they produce inconsiste
36
36
  No plan, no traceability Plans with acceptance criteria, ships PRs
37
37
  ```
38
38
 
39
+ ### Interview-First Planning
40
+
41
+ The **Architect agent** doesn't jump straight to solutions. Before creating any plan, it conducts a structured conversation:
42
+
43
+ 1. **Acknowledge & Clarify** — Summarizes your request and asks 3-5 targeted questions about scope, constraints, and success criteria
44
+ 2. **Deepen Understanding** — Follows up on unclear areas, identifies risks, presents trade-offs
45
+ 3. **Readiness Check** — Presents problem statement + proposed approach + assumptions, asks for your approval
46
+ 4. **Plan Review** — Only saves the plan after you explicitly approve it
47
+
48
+ This ensures you get plans that actually solve the right problem — not AI hallucinations.
49
+
39
50
  ---
40
51
 
41
52
  ## Quick Start
@@ -62,7 +73,7 @@ User Request
62
73
  v
63
74
  Architect (read-only planning)
64
75
  |
65
- |-- read-only analysis -----> @security @coder @perf
76
+ |-- read-only analysis -----> @security @explore @perf
66
77
  |
67
78
  v
68
79
  Implement / Fix (execution)
@@ -122,7 +133,7 @@ Handle complex, multi-step work. Use your best model.
122
133
 
123
134
  | Agent | Role | Key Capabilities |
124
135
  |-------|------|-----------------|
125
- | **architect** | Read-only analysis & planning | Plans with mermaid diagrams, acceptance criteria, NFR analysis. Commits plans and defers branch creation to handoff. Delegates read-only analysis to `@security`, `@coder`, `@perf`. |
136
+ | **architect** | Read-only analysis & planning | Plans with mermaid diagrams, acceptance criteria, NFR analysis. Conducts mandatory requirements interview and plan review before saving. Commits plans and defers branch creation to handoff. Delegates read-only analysis to `@explore`, `@security`, `@perf` only. |
126
137
  | **implement** | Full-access development | Skill-aware implementation, REPL loop with ACs, two-phase quality gate, parallel sub-agent orchestration, task finalizer. |
127
138
  | **fix** | Quick turnaround bug fixes | Rapid diagnosis, scope-based quality gate, optional REPL loop. Delegates deep debugging to `@debug`. |
128
139
 
@@ -134,11 +145,12 @@ Focused specialists launched **automatically** by primary agents. Each auto-load
134
145
  |-------|------|-----------------|-------------|
135
146
  | **@testing** | Test writing, suite execution, coverage | `testing-strategies` | Implement (standard+high), Fix (low+standard+high) |
136
147
  | **@security** | OWASP audit, secrets scan, threat modeling | `security-hardening` | Implement (standard+high), Fix (standard+high), Architect (read-only) |
148
+ | **@explore** | Read-only codebase exploration | — | Architect only (read-only analysis) |
137
149
  | **@audit** | Code quality, tech debt, pattern review | `code-quality` | Implement (standard+high) |
138
150
  | **@docs-writer** | Auto-documentation generation | — | Implement (standard+high) |
139
151
  | **@perf** | Complexity analysis, N+1 detection, bundle impact | `performance-optimization` | Implement (high), Fix (high), Architect (read-only) |
140
152
  | **@devops** | CI/CD validation, IaC review | `deployment-automation` | Implement (high, or infra files changed) |
141
- | **@coder** | Cross-layer implementation, feasibility | Per-layer skills | Implement (3+ layers), Architect (feasibility analysis) |
153
+ | **@coder** | Cross-layer implementation, feasibility | Per-layer skills | Implement (3+ layers) |
142
154
  | **@refactor** | Behavior-preserving restructuring | `design-patterns` + `code-quality` | Implement (refactor plans) |
143
155
  | **@debug** | Root cause analysis, troubleshooting | `testing-strategies` | Fix (complex issues) |
144
156
 
@@ -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.8",
3
+ "version": "4.1.1",
4
4
  "description": "Supercharge OpenCode with structured workflows, intelligent agents, and automated development practices",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",