cortex-agents 3.4.0 → 4.0.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.
Files changed (49) hide show
  1. package/.opencode/agents/architect.md +82 -89
  2. package/.opencode/agents/audit.md +57 -188
  3. package/.opencode/agents/{crosslayer.md → coder.md} +9 -52
  4. package/.opencode/agents/debug.md +151 -0
  5. package/.opencode/agents/devops.md +142 -0
  6. package/.opencode/agents/docs-writer.md +195 -0
  7. package/.opencode/agents/fix.md +119 -189
  8. package/.opencode/agents/implement.md +115 -74
  9. package/.opencode/agents/perf.md +151 -0
  10. package/.opencode/agents/refactor.md +163 -0
  11. package/.opencode/agents/{guard.md → security.md} +20 -85
  12. package/.opencode/agents/testing.md +115 -0
  13. package/.opencode/skills/data-engineering/SKILL.md +221 -0
  14. package/.opencode/skills/monitoring-observability/SKILL.md +251 -0
  15. package/.opencode/skills/ui-design/SKILL.md +402 -0
  16. package/README.md +303 -287
  17. package/dist/cli.js +6 -9
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +26 -28
  20. package/dist/registry.d.ts +4 -4
  21. package/dist/registry.d.ts.map +1 -1
  22. package/dist/registry.js +6 -6
  23. package/dist/tools/branch.d.ts +2 -2
  24. package/dist/tools/docs.d.ts +2 -2
  25. package/dist/tools/github.d.ts +3 -3
  26. package/dist/tools/plan.d.ts +28 -4
  27. package/dist/tools/plan.d.ts.map +1 -1
  28. package/dist/tools/plan.js +232 -4
  29. package/dist/tools/quality-gate.d.ts +28 -0
  30. package/dist/tools/quality-gate.d.ts.map +1 -0
  31. package/dist/tools/quality-gate.js +233 -0
  32. package/dist/tools/repl.d.ts +5 -0
  33. package/dist/tools/repl.d.ts.map +1 -1
  34. package/dist/tools/repl.js +58 -7
  35. package/dist/tools/worktree.d.ts +5 -32
  36. package/dist/tools/worktree.d.ts.map +1 -1
  37. package/dist/tools/worktree.js +75 -458
  38. package/dist/utils/change-scope.d.ts +33 -0
  39. package/dist/utils/change-scope.d.ts.map +1 -0
  40. package/dist/utils/change-scope.js +198 -0
  41. package/dist/utils/plan-extract.d.ts +21 -0
  42. package/dist/utils/plan-extract.d.ts.map +1 -1
  43. package/dist/utils/plan-extract.js +65 -0
  44. package/dist/utils/repl.d.ts +31 -0
  45. package/dist/utils/repl.d.ts.map +1 -1
  46. package/dist/utils/repl.js +126 -13
  47. package/package.json +1 -1
  48. package/.opencode/agents/qa.md +0 -265
  49. package/.opencode/agents/ship.md +0 -249
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
  <img src="https://img.shields.io/badge/cortex-agents-111?style=for-the-badge&labelColor=111&color=4d96ff" alt="cortex-agents" height="40">
3
3
  </p>
4
4
 
5
- <h3 align="center">Supercharge OpenCode with structured workflows, intelligent agents, and automated development practices.</h3>
5
+ <h3 align="center">Structured AI development workflows for <a href="https://opencode.ai">OpenCode</a>.<br>Plan. Build. Ship. With discipline.</h3>
6
6
 
7
7
  <p align="center">
8
8
  <a href="https://www.npmjs.com/package/cortex-agents"><img src="https://img.shields.io/npm/v/cortex-agents.svg?style=flat-square&color=4d96ff" alt="npm version"></a>
@@ -12,238 +12,243 @@
12
12
  </p>
13
13
 
14
14
  <p align="center">
15
- <a href="#-quick-start">Quick Start</a>&nbsp;&nbsp;|&nbsp;&nbsp;
16
- <a href="#-what-it-does">What It Does</a>&nbsp;&nbsp;|&nbsp;&nbsp;
17
- <a href="#-agents">Agents</a>&nbsp;&nbsp;|&nbsp;&nbsp;
18
- <a href="#-tools">Tools</a>&nbsp;&nbsp;|&nbsp;&nbsp;
19
- <a href="#-skills">Skills</a>&nbsp;&nbsp;|&nbsp;&nbsp;
15
+ <a href="#-quick-start">Quick Start</a>&nbsp;&nbsp;&bull;&nbsp;&nbsp;
16
+ <a href="#-architecture">Architecture</a>&nbsp;&nbsp;&bull;&nbsp;&nbsp;
17
+ <a href="#-agents">Agents</a>&nbsp;&nbsp;&bull;&nbsp;&nbsp;
18
+ <a href="#-tools">Tools</a>&nbsp;&nbsp;&bull;&nbsp;&nbsp;
19
+ <a href="#-skills">Skills</a>&nbsp;&nbsp;&bull;&nbsp;&nbsp;
20
20
  <a href="#-contributing">Contributing</a>
21
21
  </p>
22
22
 
23
- <br>
24
-
25
23
  ---
26
24
 
27
- <br>
28
-
29
25
  ## Why Cortex Agents?
30
26
 
31
27
  AI coding assistants are powerful, but without structure they produce inconsistent results. **Cortex Agents** adds the missing layer: a complete development workflow that turns OpenCode into a disciplined engineering partner.
32
28
 
33
- - **Before**: AI writes code wherever, no branching discipline, no documentation, no plan.
34
- - **After**: AI checks git status, asks about branching strategy, loads implementation plans, creates docs with architecture diagrams, commits cleanly, and opens PRs.
29
+ ```
30
+ Before After
31
+ ────── ─────
32
+ AI writes code wherever AI checks git status first
33
+ No branching discipline Creates worktrees/branches automatically
34
+ No documentation Generates docs with mermaid diagrams
35
+ No quality checks Runs parallel quality gates (6 sub-agents)
36
+ No plan, no traceability Plans with acceptance criteria, ships PRs
37
+ ```
35
38
 
36
- <br>
39
+ ---
37
40
 
38
41
  ## Quick Start
39
42
 
40
43
  ```bash
41
44
  npx cortex-agents install # Add plugin + agents + skills
42
45
  npx cortex-agents configure # Pick your models interactively
43
- # Restart OpenCode - done.
46
+ # Restart OpenCode done.
44
47
  ```
45
48
 
46
- That's it. Your OpenCode session now has 8 specialized agents, 32 tools, and 14 domain skills.
49
+ Your OpenCode session now has **12 specialized agents**, **33 tools**, and **17 domain skills**.
47
50
 
48
- > **Built-in Agent Replacement** — When installed, cortex-agents automatically disables OpenCode's native `build` and `plan` agents (replaced by `implement` and `architect`). The `architect` agent becomes the default, promoting a planning-first workflow. Native agents are fully restored on `uninstall`.
51
+ > **Built-in Agent Replacement** — Cortex automatically disables OpenCode's native `build` and `plan` agents (replaced by `implement` and `architect`). The `architect` agent becomes the default, promoting a planning-first workflow. Native agents are fully restored on `uninstall`.
49
52
 
50
- <br>
53
+ ---
51
54
 
52
- ## What It Does
55
+ ## Architecture
53
56
 
54
- ### Plan, Build, Ship
57
+ ### Agent Hierarchy
55
58
 
56
- Cortex agents follow a structured workflow from planning through to PR:
59
+ ```
60
+ User Request
61
+ |
62
+ v
63
+ Architect (read-only planning)
64
+ |
65
+ |-- read-only analysis -----> @security @coder @perf
66
+ |
67
+ v
68
+ Implement / Fix (execution)
69
+ |
70
+ |-- REPL Loop (task-by-task) --> build + test per task
71
+ |
72
+ v
73
+ Quality Gate (two-phase)
74
+ |
75
+ |-- Phase 1 (parallel, scope-based):
76
+ | @testing @security @audit @docs-writer @devops @perf
77
+ |
78
+ |-- Phase 2 (cross-agent):
79
+ | @testing reacts to @security findings
80
+ |
81
+ v
82
+ quality_gate_summary --> GO / NO-GO / GO-WITH-WARNINGS
83
+ |
84
+ v
85
+ Fix blockers --> task_finalize --> PR
86
+ ```
87
+
88
+ ### The Workflow
57
89
 
58
90
  ```
59
91
  You: "Add user authentication"
60
92
 
61
93
  Architect Agent reads codebase, creates plan with mermaid diagrams
62
- saves to .cortex/plans/ "Plan saved. Switch to Implement?"
94
+ saves to .cortex/plans/ commits plan to feature branch
95
+ "Plan committed. Switch to offers worktree or branch
96
+ Implement?"
63
97
 
64
98
  Implement Agent loads plan, checks git status
65
- "You're on main. Create a branch two-step prompt: strategy -> execution
66
- or worktree?"
67
- creates feature/user-auth implements following the plan
68
- "Ready to finalize?" stages, commits, pushes, opens PR
69
- ```
70
-
71
- ### Worktree Launcher
72
-
73
- Create isolated development environments and launch them instantly:
74
-
75
- | Mode | What Happens |
76
- |------|-------------|
77
- | **IDE Terminal** | Opens in your detected IDE (VS Code, Cursor, Windsurf, Zed) with integrated terminal |
78
- | **New Terminal** | Opens a new terminal tab with OpenCode pre-configured in the worktree |
79
- | **In-App PTY** | Spawns an embedded terminal inside your current OpenCode session |
80
- | **Background** | AI implements headlessly while you keep working - toast notifications on completion |
81
-
82
- Plans are automatically propagated into the worktree's `.cortex/plans/` so the new session has full context.
83
-
84
- **IDE-Aware Launch Options** — The launcher detects your development environment and offers contextual options:
85
- - **VS Code / Cursor / Windsurf / Zed**: "Open in [IDE] (Recommended)" as the first option
86
- - **JetBrains IDEs**: Terminal tab with manual IDE opening instructions
87
- - **Terminal only**: Standard terminal tab options
88
-
89
- **Cross-platform terminal support** via the terminal driver system — automatically detects and integrates with VS Code, Cursor, Windsurf, Zed, JetBrains IDEs, tmux, iTerm2, Terminal.app, kitty, wezterm, Konsole, and GNOME Terminal. Tabs opened by the launcher are tracked and automatically closed when the worktree is removed.
90
-
91
- ### Task Finalizer
92
-
93
- One tool to close the loop:
94
-
95
- ```
96
- task_finalize
97
- git add -A
98
- git commit -m "feat: add user auth"
99
- git push -u origin feature/user-auth
100
- gh pr create --base main auto-detected if in worktree
101
- PR body auto-populated from .cortex/plans/
102
- "PR created! Clean up worktree?"
99
+ repl_init parses tasks + ACs iterates task-by-task with build+test
100
+ Quality Gate → 6 agents in parallel testing + security + audit + docs + devops + perf
101
+ quality_gate_summary → GO aggregates findings, recommends go/no-go
102
+ task_finalize stages, commits, pushes, opens PR
103
103
  ```
104
104
 
105
- ### Auto-Prompted Documentation
105
+ ### Scope-Based Quality Gate
106
106
 
107
- After every task, agents prompt you to document what you built:
107
+ Not every change needs a full audit. The quality gate scales with risk:
108
108
 
109
- | Type | What's Generated | Includes |
110
- |------|-----------------|----------|
111
- | **Decision** | Architecture Decision Record | Mermaid graph comparing options |
112
- | **Feature** | Feature documentation | Mermaid component diagram |
113
- | **Flow** | Process/data flow doc | Mermaid sequence diagram |
109
+ | Scope | Criteria | Sub-Agents Launched |
110
+ |-------|----------|-------------------|
111
+ | **Trivial** | Docs, comments, formatting | `@docs-writer` only (or skip) |
112
+ | **Low** | Tests, config files | `@testing` |
113
+ | **Standard** | Normal code changes | `@testing` + `@security` + `@audit` + `@docs-writer` |
114
+ | **High** | Auth, payments, crypto, infra, DB migrations | All 6: `@testing` + `@security` + `@audit` + `@docs-writer` + `@devops` + `@perf` |
114
115
 
115
- All docs are saved to `docs/` with an auto-generated `INDEX.md`.
116
-
117
- <br>
116
+ ---
118
117
 
119
118
  ## Agents
120
119
 
121
- ### Primary Agents
120
+ ### Primary Agents (3)
122
121
 
123
122
  Handle complex, multi-step work. Use your best model.
124
123
 
125
- | Agent | Role | Superpower |
126
- |-------|------|-----------|
127
- | **implement** | Full-access development | Skill-aware implementation, worktree launcher, quality gates, task finalizer |
128
- | **architect** | Read-only analysis | Architectural plans with mermaid diagrams, NFR analysis, hands off to implement |
129
- | **fix** | Deep troubleshooting | Performance debugging, distributed tracing, hotfix workflow |
130
- | **audit** | Code quality assessment | Tech debt scoring, pattern review, refactoring advisor (read-only) |
124
+ | Agent | Role | Key Capabilities |
125
+ |-------|------|-----------------|
126
+ | **architect** | Read-only analysis & planning | Plans with mermaid diagrams, acceptance criteria, NFR analysis. Commits plans to branches. Delegates read-only analysis to `@security`, `@coder`, `@perf`. |
127
+ | **implement** | Full-access development | Skill-aware implementation, REPL loop with ACs, two-phase quality gate, parallel sub-agent orchestration, task finalizer. |
128
+ | **fix** | Quick turnaround bug fixes | Rapid diagnosis, scope-based quality gate, optional REPL loop. Delegates deep debugging to `@debug`. |
131
129
 
132
- ### Subagents
130
+ ### Sub-Agents (9)
133
131
 
134
- Focused specialists launched **automatically** as parallel quality gates. Each auto-loads its core domain skill for deeper analysis. Use a fast/cheap model.
132
+ Focused specialists launched **automatically** by primary agents. Each auto-loads domain skills for deeper analysis. Use a fast/cheap model.
135
133
 
136
134
  | Agent | Role | Auto-Loads Skill | Triggered By |
137
135
  |-------|------|-----------------|-------------|
138
- | **@qa** | Writes tests, runs suite, reports coverage | `testing-strategies` | Implement (always), Fix (always) |
139
- | **@guard** | OWASP audit, secrets scan, code-level fix patches | `security-hardening` | Implement (always), Fix (if security-relevant) |
140
- | **@crosslayer** | Cross-layer implementation + feasibility analysis | Per-layer skills | Implement (multi-layer features), Architect (analysis) |
141
- | **@ship** | CI/CD validation, IaC review, deployment strategy | `deployment-automation` | Implement (when CI/Docker/infra files change) |
142
-
143
- Subagents return **structured reports** with severity levels (`BLOCKING`, `CRITICAL`, `HIGH`, `MEDIUM`, `LOW`) that the orchestrating agent uses to decide whether to proceed or fix issues first.
136
+ | **@testing** | Test writing, suite execution, coverage | `testing-strategies` | Implement (standard+high), Fix (low+standard+high) |
137
+ | **@security** | OWASP audit, secrets scan, threat modeling | `security-hardening` | Implement (standard+high), Fix (standard+high), Architect (read-only) |
138
+ | **@audit** | Code quality, tech debt, pattern review | `code-quality` | Implement (standard+high) |
139
+ | **@docs-writer** | Auto-documentation generation | | Implement (standard+high) |
140
+ | **@perf** | Complexity analysis, N+1 detection, bundle impact | `performance-optimization` | Implement (high), Fix (high), Architect (read-only) |
141
+ | **@devops** | CI/CD validation, IaC review | `deployment-automation` | Implement (high, or infra files changed) |
142
+ | **@coder** | Cross-layer implementation, feasibility | Per-layer skills | Implement (3+ layers), Architect (feasibility analysis) |
143
+ | **@refactor** | Behavior-preserving restructuring | `design-patterns` + `code-quality` | Implement (refactor plans) |
144
+ | **@debug** | Root cause analysis, troubleshooting | `testing-strategies` | Fix (complex issues) |
145
+
146
+ Sub-agents return **structured reports** with severity levels (`BLOCKING`, `CRITICAL`, `HIGH`, `MEDIUM`, `LOW`) that the orchestrating agent uses to decide whether to proceed or fix issues first.
144
147
 
145
148
  ### Skill Routing
146
149
 
147
- All agents detect the project's technology stack and **automatically load relevant skills** before working. This turns the 14 domain skills from passive knowledge into active intelligence:
150
+ All agents detect the project's technology stack and **automatically load relevant skills** before working:
148
151
 
149
152
  ```
150
153
  Implement Agent detects: package.json has React + Express + Prisma
151
- auto-loads: frontend-development, backend-development, database-design, api-design
152
- implements with deep framework-specific knowledge
154
+ -> auto-loads: frontend-development, backend-development, database-design, api-design
155
+ -> implements with deep framework-specific knowledge
153
156
  ```
154
157
 
155
- <br>
158
+ ---
156
159
 
157
160
  ## Tools
158
161
 
159
- 32 tools bundled and auto-registered. No configuration needed.
162
+ 33 tools bundled and auto-registered. No configuration needed.
160
163
 
161
164
  <table>
162
165
  <tr><td width="50%">
163
166
 
164
167
  **Git Workflow**
165
- - `branch_status` - Current branch + change detection
166
- - `branch_create` - Convention-named branches (with toast notifications)
167
- - `branch_switch` - Safe branch switching
168
- - `worktree_create` - Isolated worktree in `.worktrees/` (with toast notifications)
169
- - `worktree_launch` - Launch worktree (terminal/PTY/background)
168
+ - `branch_status` Current branch + change detection
169
+ - `branch_create` Convention-named branches (with toast)
170
+ - `branch_switch` Safe branch switching
171
+ - `worktree_create` Isolated worktree in `.worktrees/`
170
172
  - `worktree_list` / `worktree_remove` / `worktree_open`
171
173
 
172
174
  </td><td width="50%">
173
175
 
174
176
  **Planning & Sessions**
175
177
  - `plan_save` / `plan_load` / `plan_list` / `plan_delete`
178
+ - `plan_commit` — Commit plan to feature branch
176
179
  - `session_save` / `session_list` / `session_load`
177
180
  - `cortex_init` / `cortex_status` / `cortex_configure`
178
- - `detect_environment` - Detect IDE/terminal for contextual launch options
179
181
 
180
182
  </td></tr>
181
183
  <tr><td width="50%">
182
184
 
183
185
  **Documentation**
184
- - `docs_init` - Set up `docs/` structure
185
- - `docs_save` - Save doc with mermaid diagrams
186
- - `docs_list` - Browse all docs
187
- - `docs_index` - Rebuild `docs/INDEX.md`
186
+ - `docs_init` Set up `docs/` structure
187
+ - `docs_save` Save doc with mermaid diagrams
188
+ - `docs_list` Browse all docs
189
+ - `docs_index` Rebuild `docs/INDEX.md`
188
190
 
189
191
  </td><td width="50%">
190
192
 
191
- **Finalization & Config**
192
- - `task_finalize` - Stage, commit, push, create PR
193
+ **Finalization**
194
+ - `task_finalize` Stage, commit, push, create PR
193
195
  - Auto-detects worktree (targets main)
194
196
  - Auto-populates PR from `.cortex/plans/`
195
- - Auto-links issues via `Closes #N` from plan metadata
196
- - Warns if docs are missing
197
- - `cortex_configure` - Set models from within an agent session
197
+ - Auto-links issues via `Closes #N`
198
+ - `quality_gate_summary` Aggregate sub-agent findings, GO/NO-GO recommendation
198
199
 
199
200
  </td></tr>
200
201
  <tr><td colspan="2">
201
202
 
202
203
  **GitHub Integration**
203
- - `github_status` - Check `gh` CLI availability, authentication, and detect GitHub Projects
204
- - `github_issues` - List/filter repo issues by state, labels, milestone, assignee
205
- - `github_projects` - List GitHub Project boards and their work items
204
+ - `github_status` Check `gh` CLI availability, auth, and detect projects
205
+ - `github_issues` List/filter repo issues by state, labels, milestone, assignee
206
+ - `github_projects` List GitHub Project boards and their work items
206
207
 
207
- The architect agent uses these tools to browse your backlog and seed plans from real GitHub issues. Issue numbers are stored in plan frontmatter (`issues: [42, 51]`) and automatically appended as `Closes #N` to the PR body when `task_finalize` runs — GitHub auto-closes the issues when the PR merges. Supports both github.com and GitHub Enterprise Server URLs.
208
+ The architect uses these to browse your backlog and seed plans from real issues. Issue numbers stored in plan frontmatter (`issues: [42, 51]`) are automatically appended as `Closes #N` to the PR body.
208
209
 
209
210
  </td></tr>
210
211
  <tr><td colspan="2">
211
212
 
212
- **REPL Loop** (Iterative Task-by-Task Implementation)
213
- - `repl_init` - Initialize a loop from a plan (parses tasks, auto-detects build/test commands)
214
- - `repl_status` - Get current progress, active task, retry counts (auto-advances to next task)
215
- - `repl_report` - Report task outcome (`pass`/`fail`/`skip`) with auto-retry and escalation
216
- - `repl_summary` - Generate markdown summary table for PR body
213
+ **REPL Loop** Iterative task-by-task implementation
214
+ - `repl_init` Initialize loop from plan (parses tasks + ACs, auto-detects build/test)
215
+ - `repl_status` Current progress, active task with ACs, retry counts
216
+ - `repl_report` Report outcome (`pass`/`fail`/`skip`) with auto-retry and escalation
217
+ - `repl_resume` Detect and resume interrupted loop from previous session
218
+ - `repl_summary` — Markdown results table with AC satisfaction for PR body
217
219
 
218
- The implement agent uses these tools to work through plan tasks one at a time, running build+test verification after each task. Failed tasks are automatically retried (up to a configurable limit) before escalating to the user. State is persisted to `.cortex/repl-state.json` so progress survives context compaction and session restarts.
220
+ State persists to `.cortex/repl-state.json` survives context compaction, session restarts, and agent switches.
219
221
 
220
222
  </td></tr>
221
223
  </table>
222
224
 
223
- <br>
225
+ ---
224
226
 
225
227
  ## Skills
226
228
 
227
- 14 domain-specific skill packs loaded on demand via the `skill` tool:
229
+ 17 domain-specific skill packs loaded on demand:
228
230
 
229
231
  | Skill | Covers |
230
232
  |-------|--------|
231
- | **frontend-development** | React, Vue, Svelte, CSS architecture, accessibility |
232
- | **backend-development** | API design, middleware, auth, caching, queue systems |
233
- | **mobile-development** | React Native, Flutter, native iOS/Android patterns |
234
- | **desktop-development** | Electron, Tauri, native desktop application patterns |
235
- | **database-design** | Schema design, migrations, indexing, query optimization |
236
- | **api-design** | REST, GraphQL, gRPC, versioning, documentation |
237
- | **testing-strategies** | Unit, integration, E2E, TDD, coverage strategies |
238
- | **security-hardening** | OWASP, auth/authz, input validation, secure coding |
239
- | **deployment-automation** | CI/CD, Docker, Kubernetes, cloud deployment |
240
- | **architecture-patterns** | Microservices, monorepo, event-driven, CQRS |
241
- | **design-patterns** | GoF patterns, SOLID principles, DDD |
242
- | **performance-optimization** | Profiling, caching, lazy loading, bundle optimization |
243
- | **code-quality** | Refactoring, linting, code review, maintainability |
244
- | **git-workflow** | Branching strategies, worktrees, rebase vs merge |
245
-
246
- <br>
233
+ | `frontend-development` | React, Vue, Svelte, CSS architecture, accessibility |
234
+ | `ui-design` | Visual hierarchy, typography, color systems, spacing, motion, professional polish |
235
+ | `backend-development` | API design, middleware, auth, caching, queue systems |
236
+ | `mobile-development` | React Native, Flutter, native iOS/Android patterns |
237
+ | `desktop-development` | Electron, Tauri, native desktop application patterns |
238
+ | `database-design` | Schema design, migrations, indexing, query optimization |
239
+ | `api-design` | REST, GraphQL, gRPC, versioning, documentation |
240
+ | `testing-strategies` | Unit, integration, E2E, TDD, coverage strategies |
241
+ | `security-hardening` | OWASP, auth/authz, input validation, secure coding |
242
+ | `deployment-automation` | CI/CD, Docker, Kubernetes, cloud deployment |
243
+ | `architecture-patterns` | Microservices, monorepo, event-driven, CQRS |
244
+ | `design-patterns` | GoF patterns, SOLID principles, DDD |
245
+ | `performance-optimization` | Profiling, caching, lazy loading, bundle optimization |
246
+ | `code-quality` | Refactoring, linting, code review, maintainability |
247
+ | `git-workflow` | Branching strategies, worktrees, rebase vs merge |
248
+ | `monitoring-observability` | Structured logging, metrics, distributed tracing, health checks |
249
+ | `data-engineering` | ETL pipelines, data validation, streaming, message queues, partitioning |
250
+
251
+ ---
247
252
 
248
253
  ## Model Configuration
249
254
 
@@ -255,7 +260,7 @@ npx cortex-agents configure --project # Per-project (saves to .opencode/models.
255
260
  ```
256
261
 
257
262
  ```
258
- ? Select model for PRIMARY agents:
263
+ ? Select model for PRIMARY agents (architect, implement, fix):
259
264
  Claude Sonnet 4 (anthropic) Best balance of intelligence and speed
260
265
  Claude Opus 4 (anthropic) Most capable, best for complex architecture
261
266
  GPT-4.1 (openai) Fast multimodal model
@@ -263,40 +268,97 @@ npx cortex-agents configure --project # Per-project (saves to .opencode/models.
263
268
  Kimi K2P5 (kimi) Optimized for code generation
264
269
  Enter custom model ID
265
270
 
266
- ? Select model for SUBAGENTS:
271
+ ? Select model for SUBAGENTS (debug, coder, testing, security, devops, audit, ...):
267
272
  Claude 3.5 Haiku (anthropic) Fast and cost-effective
268
273
  o4 Mini (openai) Fast reasoning, cost-effective
269
274
  Gemini 2.5 Flash (google) Fast and efficient
270
275
  Same as primary
271
276
  ```
272
277
 
273
- ### In-Agent Configuration
278
+ Agents can also configure models mid-session via `cortex_configure` — no need to leave OpenCode.
279
+
280
+ > Don't see your provider in the picker? Select **"Enter custom model ID"** and type any `provider/model` string.
281
+
282
+ ---
283
+
284
+ ## How It Works
285
+
286
+ ### Implement Agent — Step by Step
274
287
 
275
- Agents can also configure models during a session via the `cortex_configure` tool — no need to leave OpenCode. The agent will prompt you to select models when `.cortex/` is first initialized.
288
+ ```
289
+ Step 1 branch_status Am I on a protected branch?
290
+ Step 2 cortex_status Is .cortex initialized?
291
+ Step 3 plan_list / plan_load Is there a plan for this work?
292
+ Step 4 Ask: strategy Worktree (recommended) or branch?
293
+ Step 5 Execute Create worktree/branch
294
+ Step 6 REPL Loop repl_init -> iterate tasks one-by-one
295
+ 6a repl_init Parse tasks + ACs, detect build/test commands
296
+ 6b repl_status Get current task with ACs, auto-advance
297
+ 6c Implement task Write code to satisfy acceptance criteria
298
+ 6d Build + test Run detected build/test commands
299
+ 6e repl_report Report pass/fail/skip -> auto-advance or retry
300
+ 6f Loop Repeat 6b-6e until all tasks complete
301
+ Step 7 Quality Gate Two-phase sub-agent review (scope-based)
302
+ 7a repl_summary Generate loop results
303
+ 7b Assess scope Classify changed files by risk tier
304
+ 7c Phase 1 Launch sub-agents in parallel
305
+ 7d Phase 2 Cross-agent reactions (@testing <- @security)
306
+ 7e quality_gate_summary Aggregate findings -> GO / NO-GO
307
+ Step 8 Documentation Review @docs-writer output or prompt user
308
+ Step 9 session_save Record what was done and why
309
+ Step 10 task_finalize Commit, push, create PR (with quality gate in body)
310
+ Step 11 Cleanup Remove worktree if applicable
311
+ ```
276
312
 
277
- ### Per-Project vs Global
313
+ ### REPL Loop Example
278
314
 
279
- | Scope | Where | Use Case |
280
- |-------|-------|----------|
281
- | **Global** | `~/.config/opencode/opencode.json` | Default for all projects |
282
- | **Per-project** | `.opencode/models.json` + `opencode.json` | Different models for different repos |
315
+ ```
316
+ repl_init("my-plan.md")
317
+ -> Parses tasks (- [ ] checkboxes) with ACs (- AC: lines)
318
+ -> Auto-detects: npm run build, npx vitest run
319
+ -> Creates .cortex/repl-state.json
283
320
 
284
- Per-project config takes priority. Team members get the same model settings when they clone the repo (`.opencode/models.json` is git-tracked).
321
+ Loop:
322
+ repl_status -> "Task #1: Implement user model"
323
+ AC: User model has name, email, password
324
+ AC: Email validation rejects malformed addresses
325
+ [implement task]
326
+ [run build + tests]
327
+ repl_report(pass, "42 tests pass")
328
+ -> "Task #1 PASSED (1st attempt)"
329
+ -> "Next: Task #2"
330
+
331
+ repl_status -> "Task #2: Add API endpoints"
332
+ [implement task]
333
+ [run build + tests]
334
+ repl_report(fail, "POST /users 500")
335
+ -> "Task #2 FAILED (attempt 1/3)"
336
+ -> "Fix and retry. 2 retries remaining."
337
+ [fix issue, re-run tests]
338
+ repl_report(pass, "All green")
339
+ -> "Task #2 PASSED (2nd attempt)"
340
+ ...
285
341
 
286
- ### Supported Providers
342
+ repl_summary -> Markdown table for PR body
343
+ ```
287
344
 
288
- | Provider | Premium | Standard | Fast |
289
- |----------|---------|----------|------|
290
- | **Anthropic** | Claude Opus 4 | Claude Sonnet 4 | Claude 3.5 Haiku |
291
- | **OpenAI** | o3 | GPT-4.1 | o4 Mini |
292
- | **Google** | Gemini 2.5 Pro | - | Gemini 2.5 Flash |
293
- | **xAI** | Grok 3 | - | Grok 3 Mini |
294
- | **DeepSeek** | DeepSeek R1 | - | DeepSeek Chat |
295
- | **Kimi** | - | Kimi K2P5 | - |
345
+ ### Quality Gate Example
296
346
 
297
- > Don't see your provider? Select **"Enter custom model ID"** and type any `provider/model` string.
347
+ ```
348
+ quality_gate_summary receives reports from 6 agents:
349
+ @testing: PASS — 12 tests written, all passing
350
+ @security: PASS WITH WARNINGS — 1 medium finding (XSS in tooltip)
351
+ @audit: PASS — score A, no critical issues
352
+ @docs-writer: 1 feature doc created
353
+ @devops: N/A
354
+ @perf: PASS — no regressions, all O(n) or better
355
+
356
+ -> Recommendation: GO-WITH-WARNINGS
357
+ -> Blocker: none
358
+ -> PR body section auto-generated
359
+ ```
298
360
 
299
- <br>
361
+ ---
300
362
 
301
363
  ## Project Structure
302
364
 
@@ -304,12 +366,13 @@ Per-project config takes priority. Team members get the same model settings when
304
366
  your-project/
305
367
  .cortex/ Project context (auto-initialized)
306
368
  config.json Configuration
307
- plans/ Implementation plans (gitignored)
308
- sessions/ Session summaries (gitignored)
309
- repl-state.json REPL loop progress (gitignored, auto-managed)
369
+ plans/ Implementation plans
370
+ sessions/ Session summaries
371
+ repl-state.json REPL loop progress (auto-managed)
372
+ quality-gate.json Last quality gate results
310
373
  .opencode/
311
374
  models.json Per-project model config (git tracked)
312
- .worktrees/ Git worktrees (gitignored)
375
+ .worktrees/ Git worktrees
313
376
  feature-auth/ Isolated development copy
314
377
  bugfix-login/
315
378
  docs/ Documentation (git tracked)
@@ -319,7 +382,7 @@ your-project/
319
382
  flows/ Process/data flow docs
320
383
  ```
321
384
 
322
- <br>
385
+ ---
323
386
 
324
387
  ## CLI Reference
325
388
 
@@ -333,131 +396,20 @@ npx cortex-agents uninstall # Clean removal of everything
333
396
  npx cortex-agents status # Show installation and model status
334
397
  ```
335
398
 
336
- <br>
337
-
338
- ## How It Works
339
-
340
- ### The Implement Agent Workflow
341
-
342
- Every time the implement agent starts, it follows a structured pre-implementation checklist:
343
-
344
- ```
345
- Step 1 branch_status Am I on a protected branch?
346
- Step 2 cortex_status Is .cortex initialized? Offer model config if new project.
347
- Step 3 plan_list / plan_load Is there a plan for this work?
348
- Step 4 Ask: strategy Worktree (recommended) or branch?
349
- Step 4b Ask: launch mode Terminal tab (recommended) / stay / PTY / background?
350
- Step 5 Execute Create worktree/branch, auto-detect terminal
351
- Step 6 REPL Loop If plan loaded: repl_init → iterate tasks one-by-one
352
- 6a repl_init Parse plan tasks, auto-detect build/test commands
353
- 6b repl_status Get current task, auto-advance from pending
354
- 6c Implement task Write code for the current task only
355
- 6d Build + test Run detected build/test commands
356
- 6e repl_report Report pass/fail/skip → auto-advance or retry
357
- 6f Repeat 6b-6e Until all tasks done or user intervenes
358
- Step 7 Quality Gate Launch @qa + @guard in parallel (includes repl_summary)
359
- Step 8 Ask: documentation Decision doc / feature doc / flow doc?
360
- Step 9 session_save Record what was done and why
361
- Step 10 task_finalize Commit, push, create PR
362
- Step 11 Ask: cleanup Remove worktree + close terminal tab? (if applicable)
363
- ```
364
-
365
- This isn't just documentation - it's enforced by the agent's instructions. The AI follows this workflow every time.
366
-
367
- ### Sub-Agent Quality Gates
368
-
369
- After implementation (Step 7), the implement agent **automatically** launches sub-agents in parallel as quality gates:
370
-
371
- ```
372
- Implement Agent completes implementation
373
- |
374
- +-- launches in parallel (single message) --+
375
- | |
376
- v v
377
- @qa @guard
378
- Writes unit tests OWASP audit
379
- Runs test suite Secrets scan
380
- Reports coverage Severity ratings
381
- Returns: PASS/FAIL Returns: PASS/FAIL
382
- | |
383
- +------ results reviewed by Implement ------+
384
- |
385
- v
386
- Quality Gate Summary included in PR body
387
- ```
388
-
389
- The fix agent uses the same pattern: `@qa` for regression tests (always) and `@guard` when the fix touches sensitive code.
390
-
391
- Sub-agents use **structured return contracts** so results are actionable:
392
- - `BLOCKING` / `CRITICAL` / `HIGH` findings block finalization
393
- - `MEDIUM` findings are noted in the PR body
394
- - `LOW` findings are deferred
395
-
396
- ### REPL Loop (Iterative Implementation)
397
-
398
- When a plan is loaded, the implement agent activates a **Read-Eval-Print Loop** that works through tasks one at a time with build+test verification after each:
399
-
400
- ```
401
- repl_init("my-plan.md")
402
- → Parses plan tasks (- [ ] checkboxes)
403
- → Auto-detects: npm run build, npx vitest run (vitest)
404
- → Creates .cortex/repl-state.json
405
-
406
- Loop:
407
- repl_status → "Task #1: Implement user model"
408
- [agent implements task]
409
- [agent runs build + tests]
410
- repl_report(pass, "42 tests pass") → "✓ Task #1 PASSED (1st attempt)"
411
- → "→ Next: Task #2"
412
-
413
- repl_status → "Task #2: Add API endpoints"
414
- [agent implements task]
415
- [agent runs build + tests]
416
- repl_report(fail, "POST /users 500") → "⚠ Task #2 FAILED (attempt 1/3)"
417
- → "Fix and retry. 2 retries remaining."
418
- [agent fixes the issue]
419
- [agent runs build + tests]
420
- repl_report(pass, "All green") → "✓ Task #2 PASSED (2nd attempt)"
421
- → "→ Next: Task #3"
422
- ...
423
-
424
- repl_summary → Markdown table for PR body
425
- ```
426
-
427
- **Key behaviors:**
428
- - **Opt-in**: Only activates when a plan is loaded. No-plan sessions use the standard linear workflow.
429
- - **Auto-detection**: Scans `package.json`, `Cargo.toml`, `go.mod`, `pyproject.toml`, `Makefile`, `mix.exs` for build/test/lint commands.
430
- - **Retry with escalation**: Failed tasks retry up to `maxRetries` (default: 3) before asking the user how to proceed.
431
- - **Persistent state**: Progress saved to `.cortex/repl-state.json` — survives context compaction, session restarts, and agent switches.
432
- - **Skip support**: Tasks can be skipped with a reason, which is tracked in the summary.
433
-
434
- ### Agent Handover
435
-
436
- When agents switch, a toast notification tells you what mode you're in:
437
-
438
- ```
439
- Agent: implement Development mode - ready to implement
440
- Agent: architect Planning mode - read-only analysis
441
- Agent: fix Debug mode - troubleshooting and fixes
442
- Agent: audit Review mode - code quality assessment
443
- ```
444
-
445
- The Architect agent creates plans with mermaid diagrams and hands off to Implement. Implement loads the plan, detects the tech stack, loads relevant skills, and implements. If something breaks, Fix takes over with performance debugging tools. Audit provides code quality assessment and tech debt analysis on demand.
446
-
447
- <br>
399
+ ---
448
400
 
449
401
  ## Requirements
450
402
 
451
403
  - [OpenCode](https://opencode.ai) >= 1.0.0
452
404
  - Node.js >= 18.0.0
453
405
  - Git (for branch/worktree features)
454
- - [GitHub CLI](https://cli.github.com/) (optional, for `task_finalize` PR creation and `github_*` tools)
406
+ - [GitHub CLI](https://cli.github.com/) (optional for PR creation and issue integration)
455
407
 
456
- <br>
408
+ ---
457
409
 
458
410
  ## Contributing
459
411
 
460
- Contributions are welcome! This is an Apache-2.0 licensed project and we'd love your help.
412
+ We welcome contributions of all sizes. Whether it's a typo fix, a new skill pack, or a whole new agent — we appreciate it.
461
413
 
462
414
  ### Getting Started
463
415
 
@@ -466,45 +418,109 @@ git clone https://github.com/ps-carvalho/cortex-agents.git
466
418
  cd cortex-agents
467
419
  npm install
468
420
  npm run build
421
+ npm test # 447 tests, all should pass
469
422
  ```
470
423
 
471
- ### Development Workflow
424
+ ### Local Development
472
425
 
473
426
  ```bash
474
- # Link for local testing
427
+ # Link for local testing with OpenCode
475
428
  npm link
476
429
  cd ~/.config/opencode && npm link cortex-agents
477
430
 
478
- # Make changes, rebuild, restart OpenCode
431
+ # Edit, rebuild, restart OpenCode to test
479
432
  npm run build
480
433
 
481
434
  # Unlink when done
482
435
  cd ~/.config/opencode && npm unlink cortex-agents && npm install
483
436
  ```
484
437
 
438
+ ### Project Layout
439
+
440
+ ```
441
+ src/
442
+ index.ts Plugin entry point, tool registration, event hooks
443
+ registry.ts Agent/model registry constants
444
+ cli.ts CLI (install, configure, uninstall, status)
445
+ tools/
446
+ repl.ts REPL loop tools (init, status, report, resume, summary)
447
+ quality-gate.ts Quality gate aggregation tool
448
+ cortex.ts Project initialization tools
449
+ worktree.ts Git worktree tools
450
+ branch.ts Git branch tools
451
+ plan.ts Plan persistence tools
452
+ session.ts Session summary tools
453
+ docs.ts Documentation tools
454
+ task.ts Task finalization tool
455
+ github.ts GitHub integration tools
456
+ utils/
457
+ repl.ts REPL state management, command detection, formatting
458
+ change-scope.ts Risk-based file classification
459
+ plan-extract.ts Plan parsing utilities
460
+ shell.ts Shell command helpers
461
+ github.ts GitHub API helpers
462
+ worktree-detect.ts Worktree detection
463
+ __tests__/ Test files mirror src/ structure
464
+ .opencode/
465
+ agents/ 12 agent definition files (.md frontmatter)
466
+ skills/ 17 skill pack directories (SKILL.md each)
467
+ ```
468
+
485
469
  ### What We're Looking For
486
470
 
487
- - **New skills** - Domain-specific knowledge packs (e.g., Rust, Go, DevOps for AWS)
488
- - **New agents** - Specialized agents (e.g., reviewer, migration, docs-writer)
489
- - **Terminal drivers** - Improve detection/support for additional terminal emulators
490
- - **Tool improvements** - Better PR templates, test runners, linter integration
491
- - **Bug fixes** - Anything that doesn't work as expected
471
+ | Type | Examples | Difficulty |
472
+ |------|----------|-----------|
473
+ | **New skills** | Rust, Go, AWS, Terraform, GraphQL | Easy — add a `SKILL.md` file |
474
+ | **New agents** | Reviewer, migration specialist, API designer | Medium — agent `.md` + registry update |
475
+ | **Tool improvements** | Better PR templates, test runners, linter integration | Medium — TypeScript + tests |
476
+ | **Quality gate enhancements** | New parsers for agent report formats, smarter severity mapping | Medium |
477
+ | **Bug fixes** | Anything that doesn't work as expected | Varies |
478
+ | **Documentation** | Guides, examples, tutorials | Easy |
479
+
480
+ ### Adding a New Skill
481
+
482
+ 1. Create `.opencode/skills/your-skill/SKILL.md` with frontmatter (`name`, `description`, `license`, `compatibility`)
483
+ 2. Write the skill content — patterns, checklists, examples
484
+ 3. Update the skill count in tests if applicable
485
+ 4. Submit a PR
486
+
487
+ ### Adding a New Agent
488
+
489
+ 1. Create `.opencode/agents/your-agent.md` with frontmatter (`description`, `mode`, `temperature`, `tools`, `permission`)
490
+ 2. Add the agent name to `SUBAGENTS` or `PRIMARY_AGENTS` in `src/registry.ts`
491
+ 3. Add an agent description in `AGENT_DESCRIPTIONS` in `src/index.ts`
492
+ 4. Update test expectations in `src/__tests__/registry.test.ts`
493
+ 5. Submit a PR
492
494
 
493
495
  ### Submitting Changes
494
496
 
495
497
  1. Fork the repository
496
498
  2. Create your branch (`git checkout -b feature/amazing-feature`)
497
- 3. Commit with conventional format (`git commit -m 'feat: add amazing feature'`)
498
- 4. Push and open a Pull Request
499
+ 3. Write tests for new functionality
500
+ 4. Ensure all tests pass (`npm test`) and the build is clean (`npm run build`)
501
+ 5. Commit with conventional format (`feat:`, `fix:`, `docs:`, `chore:`)
502
+ 6. Push and open a Pull Request
499
503
 
500
- <br>
504
+ ### Commit Convention
501
505
 
502
- ## License
506
+ We use [Conventional Commits](https://www.conventionalcommits.org/):
503
507
 
504
- [Apache-2.0](LICENSE)
508
+ ```
509
+ feat: add new capability
510
+ fix: correct a bug
511
+ docs: update documentation
512
+ chore: maintenance, dependencies
513
+ refactor: code restructuring without behavior change
514
+ test: add or update tests
515
+ ```
516
+
517
+ ---
518
+
519
+ ## License
505
520
 
506
- <br>
521
+ [Apache-2.0](LICENSE) — use it, modify it, ship it.
507
522
 
508
523
  <p align="center">
524
+ <br>
509
525
  <sub>Built for the <a href="https://opencode.ai">OpenCode</a> community</sub>
510
526
  </p>