oh-my-codex 0.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.
Files changed (182) hide show
  1. package/README.md +269 -0
  2. package/bin/omx.js +25 -0
  3. package/dist/agents/definitions.d.ts +22 -0
  4. package/dist/agents/definitions.d.ts.map +1 -0
  5. package/dist/agents/definitions.js +235 -0
  6. package/dist/agents/definitions.js.map +1 -0
  7. package/dist/cli/doctor.d.ts +11 -0
  8. package/dist/cli/doctor.d.ts.map +1 -0
  9. package/dist/cli/doctor.js +157 -0
  10. package/dist/cli/doctor.js.map +1 -0
  11. package/dist/cli/index.d.ts +6 -0
  12. package/dist/cli/index.d.ts.map +1 -0
  13. package/dist/cli/index.js +266 -0
  14. package/dist/cli/index.js.map +1 -0
  15. package/dist/cli/setup.d.ts +12 -0
  16. package/dist/cli/setup.d.ts.map +1 -0
  17. package/dist/cli/setup.js +175 -0
  18. package/dist/cli/setup.js.map +1 -0
  19. package/dist/cli/version.d.ts +2 -0
  20. package/dist/cli/version.d.ts.map +1 -0
  21. package/dist/cli/version.js +17 -0
  22. package/dist/cli/version.js.map +1 -0
  23. package/dist/config/generator.d.ts +14 -0
  24. package/dist/config/generator.d.ts.map +1 -0
  25. package/dist/config/generator.js +106 -0
  26. package/dist/config/generator.js.map +1 -0
  27. package/dist/hooks/__tests__/agents-overlay.test.d.ts +8 -0
  28. package/dist/hooks/__tests__/agents-overlay.test.d.ts.map +1 -0
  29. package/dist/hooks/__tests__/agents-overlay.test.js +148 -0
  30. package/dist/hooks/__tests__/agents-overlay.test.js.map +1 -0
  31. package/dist/hooks/agents-overlay.d.ts +34 -0
  32. package/dist/hooks/agents-overlay.d.ts.map +1 -0
  33. package/dist/hooks/agents-overlay.js +265 -0
  34. package/dist/hooks/agents-overlay.js.map +1 -0
  35. package/dist/hooks/emulator.d.ts +44 -0
  36. package/dist/hooks/emulator.d.ts.map +1 -0
  37. package/dist/hooks/emulator.js +108 -0
  38. package/dist/hooks/emulator.js.map +1 -0
  39. package/dist/hooks/keyword-detector.d.ts +27 -0
  40. package/dist/hooks/keyword-detector.d.ts.map +1 -0
  41. package/dist/hooks/keyword-detector.js +63 -0
  42. package/dist/hooks/keyword-detector.js.map +1 -0
  43. package/dist/hooks/session.d.ts +38 -0
  44. package/dist/hooks/session.d.ts.map +1 -0
  45. package/dist/hooks/session.js +135 -0
  46. package/dist/hooks/session.js.map +1 -0
  47. package/dist/hud/colors.d.ts +26 -0
  48. package/dist/hud/colors.d.ts.map +1 -0
  49. package/dist/hud/colors.js +71 -0
  50. package/dist/hud/colors.js.map +1 -0
  51. package/dist/hud/index.d.ts +12 -0
  52. package/dist/hud/index.d.ts.map +1 -0
  53. package/dist/hud/index.js +107 -0
  54. package/dist/hud/index.js.map +1 -0
  55. package/dist/hud/render.d.ts +9 -0
  56. package/dist/hud/render.d.ts.map +1 -0
  57. package/dist/hud/render.js +192 -0
  58. package/dist/hud/render.js.map +1 -0
  59. package/dist/hud/state.d.ts +21 -0
  60. package/dist/hud/state.d.ts.map +1 -0
  61. package/dist/hud/state.js +101 -0
  62. package/dist/hud/state.js.map +1 -0
  63. package/dist/hud/types.d.ts +87 -0
  64. package/dist/hud/types.d.ts.map +1 -0
  65. package/dist/hud/types.js +8 -0
  66. package/dist/hud/types.js.map +1 -0
  67. package/dist/index.d.ts +18 -0
  68. package/dist/index.d.ts.map +1 -0
  69. package/dist/index.js +18 -0
  70. package/dist/index.js.map +1 -0
  71. package/dist/mcp/code-intel-server.d.ts +7 -0
  72. package/dist/mcp/code-intel-server.d.ts.map +1 -0
  73. package/dist/mcp/code-intel-server.js +567 -0
  74. package/dist/mcp/code-intel-server.js.map +1 -0
  75. package/dist/mcp/memory-server.d.ts +7 -0
  76. package/dist/mcp/memory-server.d.ts.map +1 -0
  77. package/dist/mcp/memory-server.js +359 -0
  78. package/dist/mcp/memory-server.js.map +1 -0
  79. package/dist/mcp/state-server.d.ts +7 -0
  80. package/dist/mcp/state-server.d.ts.map +1 -0
  81. package/dist/mcp/state-server.js +181 -0
  82. package/dist/mcp/state-server.js.map +1 -0
  83. package/dist/mcp/trace-server.d.ts +7 -0
  84. package/dist/mcp/trace-server.d.ts.map +1 -0
  85. package/dist/mcp/trace-server.js +205 -0
  86. package/dist/mcp/trace-server.js.map +1 -0
  87. package/dist/modes/base.d.ts +50 -0
  88. package/dist/modes/base.d.ts.map +1 -0
  89. package/dist/modes/base.js +140 -0
  90. package/dist/modes/base.js.map +1 -0
  91. package/dist/notifications/notifier.d.ts +30 -0
  92. package/dist/notifications/notifier.d.ts.map +1 -0
  93. package/dist/notifications/notifier.js +124 -0
  94. package/dist/notifications/notifier.js.map +1 -0
  95. package/dist/team/orchestrator.d.ts +54 -0
  96. package/dist/team/orchestrator.d.ts.map +1 -0
  97. package/dist/team/orchestrator.js +106 -0
  98. package/dist/team/orchestrator.js.map +1 -0
  99. package/dist/utils/package.d.ts +9 -0
  100. package/dist/utils/package.d.ts.map +1 -0
  101. package/dist/utils/package.js +31 -0
  102. package/dist/utils/package.js.map +1 -0
  103. package/dist/utils/paths.d.ts +27 -0
  104. package/dist/utils/paths.d.ts.map +1 -0
  105. package/dist/utils/paths.js +60 -0
  106. package/dist/utils/paths.js.map +1 -0
  107. package/dist/verification/verifier.d.ts +32 -0
  108. package/dist/verification/verifier.d.ts.map +1 -0
  109. package/dist/verification/verifier.js +81 -0
  110. package/dist/verification/verifier.js.map +1 -0
  111. package/package.json +54 -0
  112. package/prompts/analyst.md +110 -0
  113. package/prompts/api-reviewer.md +98 -0
  114. package/prompts/architect.md +109 -0
  115. package/prompts/build-fixer.md +89 -0
  116. package/prompts/code-reviewer.md +105 -0
  117. package/prompts/critic.md +87 -0
  118. package/prompts/debugger.md +93 -0
  119. package/prompts/deep-executor.md +112 -0
  120. package/prompts/dependency-expert.md +99 -0
  121. package/prompts/designer.md +103 -0
  122. package/prompts/executor.md +99 -0
  123. package/prompts/explore.md +112 -0
  124. package/prompts/git-master.md +92 -0
  125. package/prompts/information-architect.md +267 -0
  126. package/prompts/performance-reviewer.md +94 -0
  127. package/prompts/planner.md +116 -0
  128. package/prompts/product-analyst.md +299 -0
  129. package/prompts/product-manager.md +255 -0
  130. package/prompts/qa-tester.md +98 -0
  131. package/prompts/quality-reviewer.md +105 -0
  132. package/prompts/quality-strategist.md +227 -0
  133. package/prompts/researcher.md +96 -0
  134. package/prompts/scientist.md +92 -0
  135. package/prompts/security-reviewer.md +125 -0
  136. package/prompts/style-reviewer.md +87 -0
  137. package/prompts/test-engineer.md +103 -0
  138. package/prompts/ux-researcher.md +282 -0
  139. package/prompts/verifier.md +95 -0
  140. package/prompts/vision.md +75 -0
  141. package/prompts/writer.md +86 -0
  142. package/scripts/notify-hook.js +237 -0
  143. package/skills/analyze/SKILL.md +93 -0
  144. package/skills/autopilot/SKILL.md +175 -0
  145. package/skills/build-fix/SKILL.md +123 -0
  146. package/skills/cancel/SKILL.md +387 -0
  147. package/skills/code-review/SKILL.md +208 -0
  148. package/skills/configure-discord/SKILL.md +256 -0
  149. package/skills/configure-telegram/SKILL.md +232 -0
  150. package/skills/deepinit/SKILL.md +320 -0
  151. package/skills/deepsearch/SKILL.md +38 -0
  152. package/skills/doctor/SKILL.md +193 -0
  153. package/skills/ecomode/SKILL.md +114 -0
  154. package/skills/frontend-ui-ux/SKILL.md +34 -0
  155. package/skills/git-master/SKILL.md +29 -0
  156. package/skills/help/SKILL.md +192 -0
  157. package/skills/hud/SKILL.md +97 -0
  158. package/skills/learn-about-omx/SKILL.md +37 -0
  159. package/skills/learner/SKILL.md +135 -0
  160. package/skills/note/SKILL.md +62 -0
  161. package/skills/omx-setup/SKILL.md +1147 -0
  162. package/skills/pipeline/SKILL.md +407 -0
  163. package/skills/plan/SKILL.md +223 -0
  164. package/skills/project-session-manager/SKILL.md +560 -0
  165. package/skills/psm/SKILL.md +20 -0
  166. package/skills/ralph/SKILL.md +197 -0
  167. package/skills/ralph-init/SKILL.md +38 -0
  168. package/skills/ralplan/SKILL.md +34 -0
  169. package/skills/release/SKILL.md +83 -0
  170. package/skills/research/SKILL.md +510 -0
  171. package/skills/review/SKILL.md +30 -0
  172. package/skills/security-review/SKILL.md +284 -0
  173. package/skills/skill/SKILL.md +837 -0
  174. package/skills/swarm/SKILL.md +25 -0
  175. package/skills/tdd/SKILL.md +106 -0
  176. package/skills/team/SKILL.md +860 -0
  177. package/skills/trace/SKILL.md +33 -0
  178. package/skills/ultrapilot/SKILL.md +632 -0
  179. package/skills/ultraqa/SKILL.md +130 -0
  180. package/skills/ultrawork/SKILL.md +143 -0
  181. package/skills/writer-memory/SKILL.md +443 -0
  182. package/templates/AGENTS.md +326 -0
@@ -0,0 +1,860 @@
1
+ ---
2
+ name: team
3
+ description: N coordinated agents on shared task list using Codex CLI native teams
4
+ ---
5
+
6
+ # Team Skill
7
+
8
+ Spawn N coordinated agents working on a shared task list using Codex CLI's native team tools. Replaces the legacy `/swarm` skill (SQLite-based) with built-in team management, inter-agent messaging, and task dependencies -- no external dependencies required.
9
+
10
+ ## Usage
11
+
12
+ ```
13
+ /team N:agent-type "task description"
14
+ /team "task description"
15
+ /team ralph "task description"
16
+ ```
17
+
18
+ ### Parameters
19
+
20
+ - **N** - Number of teammate agents (1-20). Optional; defaults to auto-sizing based on task decomposition.
21
+ - **agent-type** - OMX agent to spawn for the `team-exec` stage (e.g., executor, build-fixer, designer). Optional; defaults to stage-aware routing (see Stage Agent Routing below).
22
+ - **task** - High-level task to decompose and distribute among teammates
23
+ - **ralph** - Optional modifier. When present, wraps the team pipeline in Ralph's persistence loop (retry on failure, architect verification before completion). See Team + Ralph Composition below.
24
+
25
+ ### Examples
26
+
27
+ ```bash
28
+ /team 5:executor "fix all TypeScript errors across the project"
29
+ /team 3:build-fixer "fix build errors in src/"
30
+ /team 4:designer "implement responsive layouts for all page components"
31
+ /team "refactor the auth module with security review"
32
+ /team ralph "build a complete REST API for user management"
33
+ ```
34
+
35
+ ## Architecture
36
+
37
+ ```
38
+ User: "/team 3:executor fix all TypeScript errors"
39
+ |
40
+ v
41
+ [TEAM ORCHESTRATOR (Lead)]
42
+ |
43
+ +-- TeamCreate("fix-ts-errors")
44
+ | -> lead becomes team-lead@fix-ts-errors
45
+ |
46
+ +-- Analyze & decompose task into subtasks
47
+ | -> explore/architect produces subtask list
48
+ |
49
+ +-- TaskCreate x N (one per subtask)
50
+ | -> tasks #1, #2, #3 with dependencies
51
+ |
52
+ +-- TaskUpdate x N (pre-assign owners)
53
+ | -> task #1 owner=worker-1, etc.
54
+ |
55
+ +-- spawn_sub_agent(team_name="fix-ts-errors", name="worker-1") x 3
56
+ | -> spawns teammates into the team
57
+ |
58
+ +-- Monitor loop
59
+ | <- SendMessage from teammates (auto-delivered)
60
+ | -> TaskList polling for progress
61
+ | -> SendMessage to unblock/coordinate
62
+ |
63
+ +-- Completion
64
+ -> SendMessage(shutdown_request) to each teammate
65
+ <- SendMessage(shutdown_response, approve: true)
66
+ -> TeamDelete("fix-ts-errors")
67
+ -> state_clear(mode="team")
68
+ ```
69
+
70
+ **Storage layout (managed by Codex CLI):**
71
+ ```
72
+ ~/.claude/
73
+ teams/fix-ts-errors/
74
+ config.json # Team metadata + members array
75
+ tasks/fix-ts-errors/
76
+ .lock # File lock for concurrent access
77
+ 1.json # Subtask #1
78
+ 2.json # Subtask #2 (may be internal)
79
+ 3.json # Subtask #3
80
+ ...
81
+ ```
82
+
83
+ ## Staged Pipeline (Canonical Team Runtime)
84
+
85
+ Team execution follows a staged pipeline:
86
+
87
+ `team-plan -> team-prd -> team-exec -> team-verify -> team-fix (loop)`
88
+
89
+ ### Stage Agent Routing
90
+
91
+ Each pipeline stage uses **specialized agents** -- not just executors. The lead selects agents based on the stage and task characteristics.
92
+
93
+ | Stage | Required Agents | Optional Agents | Selection Criteria |
94
+ |-------|----------------|-----------------|-------------------|
95
+ | **team-plan** | `explore` (haiku), `planner` (opus) | `analyst` (opus), `architect` (opus) | Use `analyst` for unclear requirements. Use `architect` for systems with complex boundaries. |
96
+ | **team-prd** | `analyst` (opus) | `product-manager` (sonnet), `critic` (opus) | Use `product-manager` for user-facing features. Use `critic` to challenge scope. |
97
+ | **team-exec** | `executor` (sonnet) | `deep-executor` (opus), `build-fixer` (sonnet), `designer` (sonnet), `writer` (haiku), `test-engineer` (sonnet) | Match agent to subtask type. Use `deep-executor` for complex autonomous work, `designer` for UI, `build-fixer` for compilation issues, `writer` for docs, `test-engineer` for test creation. |
98
+ | **team-verify** | `verifier` (sonnet) | `test-engineer` (sonnet), `security-reviewer` (sonnet), `code-reviewer` (opus), `quality-reviewer` (sonnet), `performance-reviewer` (sonnet) | Always run `verifier`. Add `security-reviewer` for auth/crypto changes. Add `code-reviewer` for >20 files or architectural changes. Add `performance-reviewer` for latency-sensitive code. |
99
+ | **team-fix** | `executor` (sonnet) | `build-fixer` (sonnet), `debugger` (sonnet), `deep-executor` (opus) | Use `build-fixer` for type/build errors. Use `debugger` for regression isolation. Use `deep-executor` for complex multi-file fixes. |
100
+
101
+ **Routing rules:**
102
+
103
+ 1. **The lead picks agents per stage, not the user.** The user's `N:agent-type` parameter only overrides the `team-exec` stage worker type. All other stages use stage-appropriate specialists.
104
+ 2. **MCP providers complement Claude agents.** Route analysis/review to Codex (`ask_codex`) and UI/large-context work to Gemini (`ask_gemini`) when available. MCP workers are one-shot and don't participate in team communication.
105
+ 3. **Cost mode affects model tier.** In ecomode, downgrade: `opus` agents to `sonnet`, `sonnet` to `haiku` where quality permits. `team-verify` always uses at least `sonnet`.
106
+ 4. **Risk level escalates review.** Security-sensitive or >20 file changes must include `security-reviewer` + `code-reviewer` (opus) in `team-verify`.
107
+
108
+ ### Stage Entry/Exit Criteria
109
+
110
+ - **team-plan**
111
+ - Entry: Team invocation is parsed and orchestration starts.
112
+ - Agents: `explore` scans codebase, `planner` creates task graph, optionally `analyst`/`architect` for complex tasks.
113
+ - Exit: decomposition is complete and a runnable task graph is prepared.
114
+ - **team-prd**
115
+ - Entry: scope is ambiguous or acceptance criteria are missing.
116
+ - Agents: `analyst` extracts requirements, optionally `product-manager`/`critic`.
117
+ - Exit: acceptance criteria and boundaries are explicit.
118
+ - **team-exec**
119
+ - Entry: `TeamCreate`, `TaskCreate`, assignment, and worker spawn are complete.
120
+ - Agents: workers spawned as the appropriate specialist type per subtask (see routing table).
121
+ - Exit: execution tasks reach terminal state for the current pass.
122
+ - **team-verify**
123
+ - Entry: execution pass finishes.
124
+ - Agents: `verifier` + task-appropriate reviewers (see routing table).
125
+ - Exit (pass): verification gates pass with no required follow-up.
126
+ - Exit (fail): fix tasks are generated and control moves to `team-fix`.
127
+ - **team-fix**
128
+ - Entry: verification found defects/regressions/incomplete criteria.
129
+ - Agents: `executor`/`build-fixer`/`debugger` depending on defect type.
130
+ - Exit: fixes are complete and flow returns to `team-exec` then `team-verify`.
131
+
132
+ ### Verify/Fix Loop and Stop Conditions
133
+
134
+ Continue `team-exec -> team-verify -> team-fix` until:
135
+ 1. verification passes and no required fix tasks remain, or
136
+ 2. work reaches an explicit terminal blocked/failed outcome with evidence.
137
+
138
+ `team-fix` is bounded by max attempts. If fix attempts exceed the configured limit, transition to terminal `failed` (no infinite loop).
139
+
140
+ ### Resume and Cancel Semantics
141
+
142
+ - **Resume:** restart from the last non-terminal stage using staged state + live task status.
143
+ - **Cancel:** `/cancel` requests teammate shutdown, waits for responses (best effort), marks phase `cancelled` with `active=false`, captures cancellation metadata, then deletes team resources and clears/preserves Team state per policy.
144
+ - Terminal states are `complete`, `failed`, and `cancelled`.
145
+
146
+ ## Workflow
147
+
148
+ ### Phase 1: Parse Input
149
+
150
+ - Extract **N** (agent count), validate 1-20
151
+ - Extract **agent-type**, validate it maps to a known OMX subagent
152
+ - Extract **task** description
153
+
154
+ ### Phase 2: Analyze & Decompose
155
+
156
+ Use `explore` or `architect` (via MCP or agent) to analyze the codebase and break the task into N subtasks:
157
+
158
+ - Each subtask should be **file-scoped** or **module-scoped** to avoid conflicts
159
+ - Subtasks must be independent or have clear dependency ordering
160
+ - Each subtask needs a concise `subject` and detailed `description`
161
+ - Identify dependencies between subtasks (e.g., "shared types must be fixed before consumers")
162
+
163
+ ### Phase 3: Create Team
164
+
165
+ Call `TeamCreate` with a slug derived from the task:
166
+
167
+ ```json
168
+ {
169
+ "team_name": "fix-ts-errors",
170
+ "description": "Fix all TypeScript errors across the project"
171
+ }
172
+ ```
173
+
174
+ **Response:**
175
+ ```json
176
+ {
177
+ "team_name": "fix-ts-errors",
178
+ "team_file_path": "~/.claude/teams/fix-ts-errors/config.json",
179
+ "lead_agent_id": "team-lead@fix-ts-errors"
180
+ }
181
+ ```
182
+
183
+ The current session becomes the team lead (`team-lead@fix-ts-errors`).
184
+
185
+ Write OMX state using the `state_write` MCP tool for proper session-scoped persistence:
186
+
187
+ ```
188
+ state_write(mode="team", active=true, current_phase="team-plan", state={
189
+ "team_name": "fix-ts-errors",
190
+ "agent_count": 3,
191
+ "agent_types": "executor",
192
+ "task": "fix all TypeScript errors",
193
+ "fix_loop_count": 0,
194
+ "max_fix_loops": 3,
195
+ "linked_ralph": false,
196
+ "stage_history": "team-plan"
197
+ })
198
+ ```
199
+
200
+ > **Note:** Use `omx_state` MCP tools for all Team mode state persistence (`state_write`, `state_read`, `state_clear`).
201
+
202
+ **State schema fields:**
203
+
204
+ | Field | Type | Description |
205
+ |-------|------|-------------|
206
+ | `active` | boolean | Whether team mode is active |
207
+ | `current_phase` | string | Current pipeline stage: `team-plan`, `team-prd`, `team-exec`, `team-verify`, `team-fix` |
208
+ | `team_name` | string | Slug name for the team |
209
+ | `agent_count` | number | Number of worker agents |
210
+ | `agent_types` | string | Comma-separated agent types used in team-exec |
211
+ | `task` | string | Original task description |
212
+ | `fix_loop_count` | number | Current fix iteration count |
213
+ | `max_fix_loops` | number | Maximum fix iterations before failing (default: 3) |
214
+ | `linked_ralph` | boolean | Whether team is linked to a ralph persistence loop |
215
+ | `stage_history` | string | Comma-separated list of stage transitions with timestamps |
216
+
217
+ **Update state on every stage transition:**
218
+
219
+ ```
220
+ state_write(mode="team", current_phase="team-exec", state={
221
+ "stage_history": "team-plan:2026-02-07T12:00:00Z,team-prd:2026-02-07T12:01:00Z,team-exec:2026-02-07T12:02:00Z"
222
+ })
223
+ ```
224
+
225
+ **Read state for resume detection:**
226
+
227
+ ```
228
+ state_read(mode="team")
229
+ ```
230
+
231
+ If `active=true` and `current_phase` is non-terminal, resume from the last incomplete stage instead of creating a new team.
232
+
233
+ ### Phase 4: Create Tasks
234
+
235
+ Call `TaskCreate` for each subtask. Set dependencies with `TaskUpdate` using `addBlockedBy`.
236
+
237
+ ```json
238
+ // TaskCreate for subtask 1
239
+ {
240
+ "subject": "Fix type errors in src/auth/",
241
+ "description": "Fix all TypeScript errors in src/auth/login.ts, src/auth/session.ts, and src/auth/types.ts. Run tsc --noEmit to verify.",
242
+ "activeForm": "Fixing auth type errors"
243
+ }
244
+ ```
245
+
246
+ **Response stores a task file (e.g. `1.json`):**
247
+ ```json
248
+ {
249
+ "id": "1",
250
+ "subject": "Fix type errors in src/auth/",
251
+ "description": "Fix all TypeScript errors in src/auth/login.ts...",
252
+ "activeForm": "Fixing auth type errors",
253
+ "owner": "",
254
+ "status": "pending",
255
+ "blocks": [],
256
+ "blockedBy": []
257
+ }
258
+ ```
259
+
260
+ For tasks with dependencies, use `TaskUpdate` after creation:
261
+
262
+ ```json
263
+ // Task #3 depends on task #1 (shared types must be fixed first)
264
+ {
265
+ "taskId": "3",
266
+ "addBlockedBy": ["1"]
267
+ }
268
+ ```
269
+
270
+ **Pre-assign owners from the lead** to avoid race conditions (there is no atomic claiming):
271
+
272
+ ```json
273
+ // Assign task #1 to worker-1
274
+ {
275
+ "taskId": "1",
276
+ "owner": "worker-1"
277
+ }
278
+ ```
279
+
280
+ ### Phase 5: Spawn Teammates
281
+
282
+ Spawn N teammates using `Task` with `team_name` and `name` parameters. Each teammate gets the team worker preamble (see below) plus their specific assignment.
283
+
284
+ ```json
285
+ {
286
+ "subagent_type": "oh-my-codex:executor",
287
+ "team_name": "fix-ts-errors",
288
+ "name": "worker-1",
289
+ "prompt": "<worker-preamble + assigned tasks>"
290
+ }
291
+ ```
292
+
293
+ **Response:**
294
+ ```json
295
+ {
296
+ "agent_id": "worker-1@fix-ts-errors",
297
+ "name": "worker-1",
298
+ "team_name": "fix-ts-errors"
299
+ }
300
+ ```
301
+
302
+ **Side effects:**
303
+ - Teammate added to `config.json` members array
304
+ - An **internal task** is auto-created (with `metadata._internal: true`) tracking the agent lifecycle
305
+ - Internal tasks appear in `TaskList` output -- filter them when counting real tasks
306
+
307
+ **IMPORTANT:** Spawn all teammates in parallel (they are background agents). Do NOT wait for one to finish before spawning the next.
308
+
309
+ ### Phase 6: Monitor
310
+
311
+ The lead orchestrator monitors progress through two channels:
312
+
313
+ 1. **Inbound messages** -- Teammates send `SendMessage` to `team-lead` when they complete tasks or need help. These arrive automatically as new conversation turns (no polling needed).
314
+
315
+ 2. **TaskList polling** -- Periodically call `TaskList` to check overall progress:
316
+ ```
317
+ #1 [completed] Fix type errors in src/auth/ (worker-1)
318
+ #3 [in_progress] Fix type errors in src/api/ (worker-2)
319
+ #5 [pending] Fix type errors in src/utils/ (worker-3)
320
+ ```
321
+ Format: `#ID [status] subject (owner)`
322
+
323
+ **Coordination actions the lead can take:**
324
+
325
+ - **Unblock a teammate:** Send a `message` with guidance or missing context
326
+ - **Reassign work:** If a teammate finishes early, use `TaskUpdate` to assign pending tasks to them and notify via `SendMessage`
327
+ - **Handle failures:** If a teammate reports failure, reassign the task or spawn a replacement
328
+
329
+ #### Task Watchdog Policy
330
+
331
+ Monitor for stuck or failed teammates:
332
+
333
+ - **Max in-progress age**: If a task stays `in_progress` for more than 5 minutes without messages, send a status check
334
+ - **Suspected dead worker**: No messages + stuck task for 10+ minutes → reassign task to another worker
335
+ - **Reassign threshold**: If a worker fails 2+ tasks, stop assigning new tasks to it
336
+
337
+ ### Phase 6.5: Stage Transitions (State Persistence)
338
+
339
+ On every stage transition, update OMX state:
340
+
341
+ ```
342
+ // Entering team-exec after planning
343
+ state_write(mode="team", current_phase="team-exec", state={
344
+ "stage_history": "team-plan:T1,team-prd:T2,team-exec:T3"
345
+ })
346
+
347
+ // Entering team-verify after execution
348
+ state_write(mode="team", current_phase="team-verify")
349
+
350
+ // Entering team-fix after verify failure
351
+ state_write(mode="team", current_phase="team-fix", state={
352
+ "fix_loop_count": 1
353
+ })
354
+ ```
355
+
356
+ This enables:
357
+ - **Resume**: If the lead crashes, `state_read(mode="team")` reveals the last stage and team name for recovery
358
+ - **Cancel**: The cancel skill reads `current_phase` to know what cleanup is needed
359
+ - **Ralph integration**: Ralph can read team state to know if the pipeline completed or failed
360
+
361
+ ### Phase 7: Completion
362
+
363
+ When all real tasks (non-internal) are completed or failed:
364
+
365
+ 1. **Verify results** -- Check that all subtasks are marked `completed` via `TaskList`
366
+ 2. **Shutdown teammates** -- Send `shutdown_request` to each active teammate:
367
+ ```json
368
+ {
369
+ "type": "shutdown_request",
370
+ "recipient": "worker-1",
371
+ "content": "All work complete, shutting down team"
372
+ }
373
+ ```
374
+ 3. **Await responses** -- Each teammate responds with `shutdown_response(approve: true)` and terminates
375
+ 4. **Delete team** -- Call `TeamDelete` to clean up:
376
+ ```json
377
+ { "team_name": "fix-ts-errors" }
378
+ ```
379
+ Response:
380
+ ```json
381
+ {
382
+ "success": true,
383
+ "message": "Cleaned up directories and worktrees for team \"fix-ts-errors\"",
384
+ "team_name": "fix-ts-errors"
385
+ }
386
+ ```
387
+ 5. **Clean OMX state** -- `state_clear(mode="team")`
388
+ 6. **Report summary** -- Present results to the user
389
+
390
+ ## Agent Preamble
391
+
392
+ When spawning teammates, include this preamble in the prompt to establish the work protocol. Adapt it per teammate with their specific task assignments.
393
+
394
+ ```
395
+ You are a TEAM WORKER in team "{team_name}". Your name is "{worker_name}".
396
+ You report to the team lead ("team-lead").
397
+
398
+ == WORK PROTOCOL ==
399
+
400
+ 1. CLAIM: Call TaskList to see your assigned tasks (owner = "{worker_name}").
401
+ Pick the first task with status "pending" that is assigned to you.
402
+ Call TaskUpdate to set status "in_progress":
403
+ {"taskId": "ID", "status": "in_progress", "owner": "{worker_name}"}
404
+
405
+ 2. WORK: Execute the task using your tools (Read, Write, Edit, Bash).
406
+ Do NOT spawn sub-agents. Do NOT delegate. Work directly.
407
+
408
+ 3. COMPLETE: When done, mark the task completed:
409
+ {"taskId": "ID", "status": "completed"}
410
+
411
+ 4. REPORT: Notify the lead via SendMessage:
412
+ {"type": "message", "recipient": "team-lead", "content": "Completed task #ID: <summary of what was done>", "summary": "Task #ID complete"}
413
+
414
+ 5. NEXT: Check TaskList for more assigned tasks. If you have more pending tasks, go to step 1.
415
+ If no more tasks are assigned to you, notify the lead:
416
+ {"type": "message", "recipient": "team-lead", "content": "All assigned tasks complete. Standing by.", "summary": "All tasks done, standing by"}
417
+
418
+ 6. SHUTDOWN: When you receive a shutdown_request, respond with:
419
+ {"type": "shutdown_response", "request_id": "<from the request>", "approve": true}
420
+
421
+ == BLOCKED TASKS ==
422
+ If a task has blockedBy dependencies, skip it until those tasks are completed.
423
+ Check TaskList periodically to see if blockers have been resolved.
424
+
425
+ == ERRORS ==
426
+ If you cannot complete a task, report the failure to the lead:
427
+ {"type": "message", "recipient": "team-lead", "content": "FAILED task #ID: <reason>", "summary": "Task #ID failed"}
428
+ Do NOT mark the task as completed. Leave it in_progress so the lead can reassign.
429
+
430
+ == RULES ==
431
+ - NEVER spawn sub-agents or use the sub-agent spawning
432
+ - ALWAYS use absolute file paths
433
+ - ALWAYS report progress via SendMessage to "team-lead"
434
+ - Use SendMessage with type "message" only -- never "broadcast"
435
+ ```
436
+
437
+ ## Communication Patterns
438
+
439
+ ### Teammate to Lead (task completion report)
440
+
441
+ ```json
442
+ {
443
+ "type": "message",
444
+ "recipient": "team-lead",
445
+ "content": "Completed task #1: Fixed 3 type errors in src/auth/login.ts and 2 in src/auth/session.ts. All files pass tsc --noEmit.",
446
+ "summary": "Task #1 complete"
447
+ }
448
+ ```
449
+
450
+ ### Lead to Teammate (reassignment or guidance)
451
+
452
+ ```json
453
+ {
454
+ "type": "message",
455
+ "recipient": "worker-2",
456
+ "content": "Task #3 is now unblocked. Also pick up task #5 which was originally assigned to worker-1.",
457
+ "summary": "New task assignment"
458
+ }
459
+ ```
460
+
461
+ ### Broadcast (use sparingly -- sends N separate messages)
462
+
463
+ ```json
464
+ {
465
+ "type": "broadcast",
466
+ "content": "STOP: shared types in src/types/index.ts have changed. Pull latest before continuing.",
467
+ "summary": "Shared types changed"
468
+ }
469
+ ```
470
+
471
+ ### Shutdown Protocol
472
+
473
+ **Lead sends:**
474
+ ```json
475
+ {
476
+ "type": "shutdown_request",
477
+ "recipient": "worker-1",
478
+ "content": "All work complete, shutting down team"
479
+ }
480
+ ```
481
+
482
+ **Teammate receives and responds:**
483
+ ```json
484
+ {
485
+ "type": "shutdown_response",
486
+ "request_id": "shutdown-1770428632375@worker-1",
487
+ "approve": true
488
+ }
489
+ ```
490
+
491
+ After approval:
492
+ - Teammate process terminates
493
+ - Teammate auto-removed from `config.json` members array
494
+ - Internal task for that teammate completes
495
+
496
+ **IMPORTANT:** The `request_id` is provided in the shutdown request message that the teammate receives. The teammate must extract it and pass it back. Do NOT fabricate request IDs.
497
+
498
+ ## MCP Workers (Hybrid Roles)
499
+
500
+ The team skill supports **hybrid execution** combining Claude agent teammates with external MCP workers (Codex and Gemini CLIs). Both types can make code changes -- they differ in capabilities and cost.
501
+
502
+ ### Execution Modes
503
+
504
+ Tasks are tagged with an execution mode during decomposition:
505
+
506
+ | Execution Mode | Provider | Capabilities |
507
+ |---------------|----------|-------------|
508
+ | `claude_worker` | Claude agent | Full Codex CLI tool access (Read/Write/Edit/Bash/Task). Best for tasks needing Claude's reasoning + iterative tool use. |
509
+ | `mcp_codex` | Codex CLI (`ask_codex`) | Full filesystem access in working_directory. Runs autonomously. Best for code review, security analysis, refactoring, architecture. |
510
+ | `mcp_gemini` | Gemini CLI (`ask_gemini`) | Full filesystem access + 1M token context. Runs autonomously. Best for UI/frontend work, large-scale changes, documentation. |
511
+
512
+ ### How MCP Workers Operate
513
+
514
+ Codex and Gemini CLIs run in full-auto mode with filesystem access. They are **autonomous executors**, not just analysts:
515
+
516
+ 1. Lead writes task instructions to a `prompt_file`
517
+ 2. Lead calls `ask_codex` or `ask_gemini` with `working_directory` set to the project root
518
+ 3. The CLI reads files, makes changes, runs commands -- all within the working directory
519
+ 4. Results/summary are written to `output_file`
520
+ 5. Lead reads the output, marks the task complete, and feeds results to dependent tasks
521
+
522
+ **Key difference from Claude teammates:**
523
+ - MCP workers operate via CLI, not Codex CLI's tool system
524
+ - They cannot use TaskList/TaskUpdate/SendMessage (no team awareness)
525
+ - They run as one-shot autonomous jobs, not persistent teammates
526
+ - The lead manages their lifecycle (spawn, monitor, collect results)
527
+
528
+ ### When to Route Where
529
+
530
+ | Task Type | Best Route | Why |
531
+ |-----------|-----------|-----|
532
+ | Iterative multi-step work | Claude teammate | Needs tool-mediated iteration + team communication |
533
+ | Code review / security audit | Codex MCP | Specialized, cheaper than Claude opus |
534
+ | Architecture analysis / planning | Codex MCP | External perspective, strong analytical reasoning |
535
+ | Refactoring (well-scoped) | Codex MCP | Autonomous execution, good at structured transforms |
536
+ | UI/frontend implementation | Gemini MCP | 1M context window, design expertise, can edit many files |
537
+ | Large-scale documentation | Gemini MCP | Writing expertise + large context for consistency |
538
+ | Visual/image analysis | Gemini MCP | Multimodal capability |
539
+ | Build/test iteration loops | Claude teammate | Needs Bash tool + iterative fix cycles |
540
+ | Tasks needing team coordination | Claude teammate | Needs SendMessage for status updates |
541
+
542
+ ### Example: Hybrid Team with MCP Executors
543
+
544
+ ```
545
+ /team 3:executor "refactor auth module with security review"
546
+
547
+ Task decomposition:
548
+ #1 [mcp_codex] Security review of current auth code -> output to .omx/research/auth-security.md
549
+ #2 [mcp_codex] Refactor auth/login.ts and auth/session.ts (uses #1 findings)
550
+ #3 [mcp_gemini] Redesign auth UI components (login form, session indicator)
551
+ #4 [claude_worker] Update auth tests + fix integration issues
552
+ #5 [mcp_codex] Final code review of all changes
553
+ ```
554
+
555
+ The lead runs #1 (Codex analysis), then #2 and #3 in parallel (Codex refactors backend, Gemini redesigns frontend), then #4 (Claude teammate handles test iteration), then #5 (final Codex review).
556
+
557
+ ### MCP Pre-flight Analysis (Optional)
558
+
559
+ For large ambiguous tasks, run analysis before team creation:
560
+
561
+ 1. Call `ToolSearch("mcp")` to discover deferred MCP tools (required before first use)
562
+ 2. Call `ask_codex` (planner role) with task description + codebase context
563
+ 3. Use the analysis to produce better task decomposition
564
+ 4. Create team and tasks with enriched context
565
+
566
+ If ToolSearch finds no MCP tools, skip MCP pre-flight and use Claude agents instead.
567
+
568
+ This is especially useful when the task scope is unclear and benefits from external reasoning before committing to a specific decomposition.
569
+
570
+ ## Monitor Enhancement: Outbox Auto-Ingestion
571
+
572
+ The lead can proactively ingest outbox messages from MCP workers using the outbox reader utilities, enabling event-driven monitoring without relying solely on `SendMessage` delivery.
573
+
574
+ ### Outbox Reader Functions
575
+
576
+ **`readNewOutboxMessages(teamName, workerName)`** -- Read new outbox messages for a single worker using a byte-offset cursor. Each call advances the cursor, so subsequent calls only return messages written since the last read. Mirrors the inbox cursor pattern from `readNewInboxMessages()`.
577
+
578
+ **`readAllTeamOutboxMessages(teamName)`** -- Read new outbox messages from ALL workers in a team. Returns an array of `{ workerName, messages }` entries, skipping workers with no new messages. Useful for batch polling in the monitor loop.
579
+
580
+ **`resetOutboxCursor(teamName, workerName)`** -- Reset the outbox cursor for a worker back to byte 0. Useful when re-reading historical messages after a lead restart or for debugging.
581
+
582
+ ### Using `getTeamStatus()` in the Monitor Phase
583
+
584
+ The `getTeamStatus(teamName, workingDirectory, heartbeatMaxAgeMs?)` function provides a unified snapshot combining:
585
+
586
+ - **Worker registration** -- Which MCP workers are registered (from shadow registry / config.json)
587
+ - **Heartbeat freshness** -- Whether each worker is alive based on heartbeat age
588
+ - **Task progress** -- Per-worker and team-wide task counts (pending, in_progress, completed)
589
+ - **Current task** -- Which task each worker is actively executing
590
+ - **Recent outbox messages** -- New messages since the last status check
591
+
592
+ Example usage in the monitor loop:
593
+
594
+ ```typescript
595
+ const status = getTeamStatus('fix-ts-errors', workingDirectory);
596
+
597
+ for (const worker of status.workers) {
598
+ if (!worker.isAlive) {
599
+ // Worker is dead -- reassign its in-progress tasks
600
+ }
601
+ for (const msg of worker.recentMessages) {
602
+ if (msg.type === 'task_complete') {
603
+ // Mark task complete, unblock dependents
604
+ } else if (msg.type === 'task_failed') {
605
+ // Handle failure, possibly retry or reassign
606
+ } else if (msg.type === 'error') {
607
+ // Log error, check if worker needs intervention
608
+ }
609
+ }
610
+ }
611
+
612
+ if (status.taskSummary.pending === 0 && status.taskSummary.inProgress === 0) {
613
+ // All work done -- proceed to shutdown
614
+ }
615
+ ```
616
+
617
+ ### Event-Based Actions from Outbox Messages
618
+
619
+ | Message Type | Action |
620
+ |-------------|--------|
621
+ | `task_complete` | Mark task completed, check if blocked tasks are now unblocked, notify dependent workers |
622
+ | `task_failed` | Increment failure sidecar, decide retry vs reassign vs skip |
623
+ | `idle` | Worker has no assigned tasks -- assign pending work or begin shutdown |
624
+ | `error` | Log the error, check `consecutiveErrors` in heartbeat for quarantine threshold |
625
+ | `shutdown_ack` | Worker acknowledged shutdown -- safe to remove from team |
626
+ | `heartbeat` | Update liveness tracking (redundant with heartbeat files but useful for latency monitoring) |
627
+
628
+ This approach complements the existing `SendMessage`-based communication by providing a pull-based mechanism for MCP workers that cannot use Codex CLI's team messaging tools.
629
+
630
+ ## Error Handling
631
+
632
+ ### Teammate Fails a Task
633
+
634
+ 1. Teammate sends `SendMessage` to lead reporting the failure
635
+ 2. Lead decides: retry (reassign same task to same or different worker) or skip
636
+ 3. To reassign: `TaskUpdate` to set new owner, then `SendMessage` to the new owner
637
+
638
+ ### Teammate Gets Stuck (No Messages)
639
+
640
+ 1. Lead detects via `TaskList` -- task stuck in `in_progress` for too long
641
+ 2. Lead sends `SendMessage` to the teammate asking for status
642
+ 3. If no response, consider the teammate dead
643
+ 4. Reassign the task to another worker via `TaskUpdate`
644
+
645
+ ### Dependency Blocked
646
+
647
+ 1. If a blocking task fails, the lead must decide whether to:
648
+ - Retry the blocker
649
+ - Remove the dependency (`TaskUpdate` with modified blockedBy)
650
+ - Skip the blocked task entirely
651
+ 2. Communicate decisions to affected teammates via `SendMessage`
652
+
653
+ ### Teammate Crashes
654
+
655
+ 1. Internal task for that teammate will show unexpected status
656
+ 2. Teammate disappears from `config.json` members
657
+ 3. Lead reassigns orphaned tasks to remaining workers
658
+ 4. If needed, spawn a replacement teammate with `spawn_sub_agent(team_name, name)`
659
+
660
+ ## Team + Ralph Composition
661
+
662
+ When the user invokes `/team ralph`, says "team ralph", or combines both keywords, team mode wraps itself in Ralph's persistence loop. This provides:
663
+
664
+ - **Team orchestration** -- multi-agent staged pipeline with specialized agents per stage
665
+ - **Ralph persistence** -- retry on failure, architect verification before completion, iteration tracking
666
+
667
+ ### Activation
668
+
669
+ Team+Ralph activates when:
670
+ 1. User invokes `/team ralph "task"` or `/team ralph "task"`
671
+ 2. Keyword detector finds both `team` and `ralph` in the prompt
672
+ 3. Hook detects `MAGIC KEYWORD: RALPH` alongside team context
673
+
674
+ ### State Linkage
675
+
676
+ Both modes write their own state files with cross-references:
677
+
678
+ ```
679
+ // Team state (via state_write)
680
+ state_write(mode="team", active=true, current_phase="team-plan", state={
681
+ "team_name": "build-rest-api",
682
+ "linked_ralph": true,
683
+ "task": "build a complete REST API"
684
+ })
685
+
686
+ // Ralph state (via state_write)
687
+ state_write(mode="ralph", active=true, iteration=1, max_iterations=10, current_phase="execution", state={
688
+ "linked_team": true,
689
+ "team_name": "build-rest-api"
690
+ })
691
+ ```
692
+
693
+ ### Execution Flow
694
+
695
+ 1. Ralph outer loop starts (iteration 1)
696
+ 2. Team pipeline runs: `team-plan -> team-prd -> team-exec -> team-verify`
697
+ 3. If `team-verify` passes: Ralph runs architect verification (STANDARD tier minimum)
698
+ 4. If architect approves: both modes complete, run `/cancel`
699
+ 5. If `team-verify` fails OR architect rejects: team enters `team-fix`, then loops back to `team-exec -> team-verify`
700
+ 6. If fix loop exceeds `max_fix_loops`: Ralph increments iteration and retries the full pipeline
701
+ 7. If Ralph exceeds `max_iterations`: terminal `failed` state
702
+
703
+ ### Cancellation
704
+
705
+ Cancel either mode cancels both:
706
+ - **Cancel Ralph (linked):** Cancel Team first (graceful shutdown), then clear Ralph state
707
+ - **Cancel Team (linked):** Clear Team, mark Ralph iteration cancelled, stop loop
708
+
709
+ See Cancellation section below for details.
710
+
711
+ ## Idempotent Recovery
712
+
713
+ If the lead crashes mid-run, the team skill should detect existing state and resume:
714
+
715
+ 1. Check `~/.claude/teams/` for teams matching the task slug
716
+ 2. If found, read `config.json` to discover active members
717
+ 3. Resume monitor mode instead of creating a duplicate team
718
+ 4. Call `TaskList` to determine current progress
719
+ 5. Continue from the monitoring phase
720
+
721
+ This prevents duplicate teams and allows graceful recovery from lead failures.
722
+
723
+ ## Comparison: Team vs Legacy Swarm
724
+
725
+ | Aspect | Team (Native) | Swarm (Legacy SQLite) |
726
+ |--------|--------------|----------------------|
727
+ | **Storage** | JSON files in `~/.claude/teams/` and `~/.claude/tasks/` | SQLite in `.omx/state/swarm.db` |
728
+ | **Dependencies** | `better-sqlite3` not needed | Requires `better-sqlite3` npm package |
729
+ | **Task claiming** | `TaskUpdate(owner + in_progress)` -- lead pre-assigns | SQLite IMMEDIATE transaction -- atomic |
730
+ | **Race conditions** | Possible if two agents claim same task (mitigate by pre-assigning) | None (SQLite transactions) |
731
+ | **Communication** | `SendMessage` (DM, broadcast, shutdown) | None (fire-and-forget agents) |
732
+ | **Task dependencies** | Built-in `blocks` / `blockedBy` arrays | Not supported |
733
+ | **Heartbeat** | Automatic idle notifications from Codex CLI | Manual heartbeat table + polling |
734
+ | **Shutdown** | Graceful request/response protocol | Signal-based termination |
735
+ | **Agent lifecycle** | Auto-tracked via internal tasks + config members | Manual tracking via heartbeat table |
736
+ | **Progress visibility** | `TaskList` shows live status with owner | SQL queries on tasks table |
737
+ | **Conflict prevention** | Owner field (lead-assigned) | Lease-based claiming with timeout |
738
+ | **Crash recovery** | Lead detects via missing messages, reassigns | Auto-release after 5-min lease timeout |
739
+ | **State cleanup** | `TeamDelete` removes everything | Manual `rm` of SQLite database |
740
+
741
+ **When to use Team over Swarm:** Always prefer `/team` for new work. It uses Codex CLI's built-in infrastructure, requires no external dependencies, supports inter-agent communication, and has task dependency management.
742
+
743
+ ## Cancellation
744
+
745
+ The `/cancel` skill handles team cleanup:
746
+
747
+ 1. Read team state via `state_read(mode="team")` to get `team_name` and `linked_ralph`
748
+ 2. Send `shutdown_request` to all active teammates (from `config.json` members)
749
+ 3. Wait for `shutdown_response` from each (15s timeout per member)
750
+ 4. Call `TeamDelete` to remove team and task directories
751
+ 5. Clear state via `state_clear(mode="team")`
752
+ 6. If `linked_ralph` is true, also clear ralph: `state_clear(mode="ralph")`
753
+
754
+ ### Linked Mode Cancellation (Team + Ralph)
755
+
756
+ When team is linked to ralph, cancellation follows dependency order:
757
+
758
+ - **Cancel triggered from Ralph context:** Cancel Team first (graceful shutdown of all teammates), then clear Ralph state. This ensures workers are stopped before the persistence loop exits.
759
+ - **Cancel triggered from Team context:** Clear Team state, then mark Ralph as cancelled. Ralph's stop hook will detect the missing team and stop iterating.
760
+ - **Force cancel (`--force`):** Clears both `team` and `ralph` state unconditionally via `state_clear`.
761
+
762
+ If teammates are unresponsive, `TeamDelete` may fail. In that case, the cancel skill should wait briefly and retry, or inform the user to manually clean up `~/.claude/teams/{team_name}/` and `~/.claude/tasks/{team_name}/`.
763
+
764
+ ## Configuration
765
+
766
+ Optional settings via `.omx-config.json`:
767
+
768
+ ```json
769
+ {
770
+ "team": {
771
+ "maxAgents": 20,
772
+ "defaultAgentType": "executor",
773
+ "monitorIntervalMs": 30000,
774
+ "shutdownTimeoutMs": 15000
775
+ }
776
+ }
777
+ ```
778
+
779
+ - **maxAgents** - Maximum teammates (default: 20)
780
+ - **defaultAgentType** - Agent type when not specified (default: `executor`)
781
+ - **monitorIntervalMs** - How often to poll `TaskList` (default: 30s)
782
+ - **shutdownTimeoutMs** - How long to wait for shutdown responses (default: 15s)
783
+
784
+ > **Note:** Team members do not have a hardcoded model default. Each teammate is a separate Codex CLI session that inherits the user's configured model. Since teammates can spawn their own subagents, the session model acts as the orchestration layer while subagents can use any model tier.
785
+
786
+ ## State Cleanup
787
+
788
+ On successful completion:
789
+
790
+ 1. `TeamDelete` handles all Codex CLI state:
791
+ - Removes `~/.claude/teams/{team_name}/` (config)
792
+ - Removes `~/.claude/tasks/{team_name}/` (all task files + lock)
793
+ 2. OMX state cleanup via MCP tools:
794
+ ```
795
+ state_clear(mode="team")
796
+ ```
797
+ If linked to Ralph:
798
+ ```
799
+ state_clear(mode="ralph")
800
+ ```
801
+ 3. Or run `/cancel` which handles all cleanup automatically.
802
+
803
+ **IMPORTANT:** Call `TeamDelete` only AFTER all teammates have been shut down. `TeamDelete` will fail if active members (besides the lead) still exist in the config.
804
+
805
+ ## Git Worktree Integration
806
+
807
+ MCP workers can operate in isolated git worktrees to prevent file conflicts between concurrent workers.
808
+
809
+ ### How It Works
810
+
811
+ 1. **Worktree creation**: Before spawning a worker, call `createWorkerWorktree(teamName, workerName, repoRoot)` to create an isolated worktree at `.omx/worktrees/{team}/{worker}` with branch `omc-team/{teamName}/{workerName}`.
812
+
813
+ 2. **Worker isolation**: Pass the worktree path as the `workingDirectory` in the worker's `BridgeConfig`. The worker operates exclusively in its own worktree.
814
+
815
+ 3. **Merge coordination**: After a worker completes its tasks, use `checkMergeConflicts()` to verify the branch can be cleanly merged, then `mergeWorkerBranch()` to merge with `--no-ff` for clear history.
816
+
817
+ 4. **Team cleanup**: On team shutdown, call `cleanupTeamWorktrees(teamName, repoRoot)` to remove all worktrees and their branches.
818
+
819
+ ### API Reference
820
+
821
+ | Function | Description |
822
+ |----------|-------------|
823
+ | `createWorkerWorktree(teamName, workerName, repoRoot, baseBranch?)` | Create isolated worktree |
824
+ | `removeWorkerWorktree(teamName, workerName, repoRoot)` | Remove worktree and branch |
825
+ | `listTeamWorktrees(teamName, repoRoot)` | List all team worktrees |
826
+ | `cleanupTeamWorktrees(teamName, repoRoot)` | Remove all team worktrees |
827
+ | `checkMergeConflicts(workerBranch, baseBranch, repoRoot)` | Non-destructive conflict check |
828
+ | `mergeWorkerBranch(workerBranch, baseBranch, repoRoot)` | Merge worker branch (--no-ff) |
829
+ | `mergeAllWorkerBranches(teamName, repoRoot, baseBranch?)` | Merge all completed workers |
830
+
831
+ ### Important Notes
832
+
833
+ - `createSession()` in `tmux-session.ts` does NOT handle worktree creation — worktree lifecycle is managed separately via `git-worktree.ts`
834
+ - Worktrees are NOT cleaned up on individual worker shutdown — only on team shutdown, to allow post-mortem inspection
835
+ - Branch names are sanitized via `sanitizeName()` to prevent injection
836
+ - All paths are validated against directory traversal
837
+
838
+ ## Gotchas
839
+
840
+ 1. **Internal tasks pollute TaskList** -- When a teammate is spawned, the system auto-creates an internal task with `metadata._internal: true`. These appear in `TaskList` output. Filter them when counting real task progress. The subject of an internal task is the teammate's name.
841
+
842
+ 2. **No atomic claiming** -- Unlike SQLite swarm, there is no transactional guarantee on `TaskUpdate`. Two teammates could race to claim the same task. **Mitigation:** The lead should pre-assign owners via `TaskUpdate(taskId, owner)` before spawning teammates. Teammates should only work on tasks assigned to them.
843
+
844
+ 3. **Task IDs are strings** -- IDs are auto-incrementing strings ("1", "2", "3"), not integers. Always pass string values to `taskId` fields.
845
+
846
+ 4. **TeamDelete requires empty team** -- All teammates must be shut down before calling `TeamDelete`. The lead (the only remaining member) is excluded from this check.
847
+
848
+ 5. **Messages are auto-delivered** -- Teammate messages arrive to the lead as new conversation turns. No polling or inbox-checking is needed for inbound messages. However, if the lead is mid-turn (processing), messages queue and deliver when the turn ends.
849
+
850
+ 6. **Teammate prompt stored in config** -- The full prompt text is stored in `config.json` members array. Do not put secrets or sensitive data in teammate prompts.
851
+
852
+ 7. **Members auto-removed on shutdown** -- After a teammate approves shutdown and terminates, it is automatically removed from `config.json`. Do not re-read config expecting to find shut-down teammates.
853
+
854
+ 8. **shutdown_response needs request_id** -- The teammate must extract the `request_id` from the incoming shutdown request JSON and pass it back. The format is `shutdown-{timestamp}@{worker-name}`. Fabricating this ID will cause the shutdown to fail silently.
855
+
856
+ 9. **Team name must be a valid slug** -- Use lowercase letters, numbers, and hyphens. Derive from the task description (e.g., "fix TypeScript errors" becomes "fix-ts-errors").
857
+
858
+ 10. **Broadcast is expensive** -- Each broadcast sends a separate message to every teammate. Use `message` (DM) by default. Only broadcast for truly team-wide critical alerts.
859
+
860
+ 11. **MCP workers are one-shot, not persistent** -- Codex and Gemini CLIs have full filesystem access and CAN make code changes. However, they run as autonomous one-shot jobs -- they cannot use TaskList/TaskUpdate/SendMessage. The lead must manage their lifecycle: write prompt_file, call MCP, read output_file, mark task complete. They don't participate in team communication like Claude teammates do.