@orchestrator-claude/cli 3.25.2 → 3.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/dist/index.d.ts +1 -1
  2. package/dist/index.js +1 -1
  3. package/dist/templates/base/claude/agents/debug-sidecar.md +133 -0
  4. package/dist/templates/base/claude/agents/doc-sidecar.md +60 -0
  5. package/dist/templates/base/claude/agents/implementer.md +162 -31
  6. package/dist/templates/base/claude/agents/test-sidecar.md +106 -0
  7. package/dist/templates/base/claude/hooks/mailbox-listener.ts +246 -0
  8. package/dist/templates/base/claude/hooks/sprint-registry.ts +85 -0
  9. package/dist/templates/base/claude/settings.json +19 -0
  10. package/dist/templates/base/claude/skills/sprint-launch/SKILL.md +176 -0
  11. package/dist/templates/base/claude/skills/sprint-teammate/sprint-teammate.md +79 -0
  12. package/dist/templates/base/scripts/lib/SprintLauncher.ts +325 -0
  13. package/dist/templates/base/scripts/lib/TmuxManager.ts +296 -0
  14. package/dist/templates/base/scripts/lib/WorktreeIsolator.ts +165 -0
  15. package/dist/templates/base/scripts/lib/WorktreeManager.ts +106 -0
  16. package/dist/templates/base/scripts/lib/mailbox/types.ts +175 -0
  17. package/dist/templates/base/scripts/lib/sidecar/SidecarWatcher.ts +249 -0
  18. package/dist/templates/base/scripts/lib/sidecar/run.ts +90 -0
  19. package/dist/templates/base/scripts/sprint-launch.ts +285 -0
  20. package/package.json +1 -1
  21. package/templates/base/claude/agents/debug-sidecar.md +133 -0
  22. package/templates/base/claude/agents/doc-sidecar.md +60 -0
  23. package/templates/base/claude/agents/implementer.md +162 -31
  24. package/templates/base/claude/agents/test-sidecar.md +106 -0
  25. package/templates/base/claude/hooks/mailbox-listener.ts +246 -0
  26. package/templates/base/claude/hooks/sprint-registry.ts +85 -0
  27. package/templates/base/claude/settings.json +19 -0
  28. package/templates/base/claude/skills/sprint-launch/SKILL.md +176 -0
  29. package/templates/base/claude/skills/sprint-teammate/sprint-teammate.md +79 -0
  30. package/templates/base/scripts/lib/SprintLauncher.ts +325 -0
  31. package/templates/base/scripts/lib/TmuxManager.ts +296 -0
  32. package/templates/base/scripts/lib/WorktreeIsolator.ts +165 -0
  33. package/templates/base/scripts/lib/WorktreeManager.ts +106 -0
  34. package/templates/base/scripts/lib/mailbox/types.ts +175 -0
  35. package/templates/base/scripts/lib/sidecar/SidecarWatcher.ts +249 -0
  36. package/templates/base/scripts/lib/sidecar/run.ts +90 -0
  37. package/templates/base/scripts/sprint-launch.ts +285 -0
@@ -46,6 +46,12 @@
46
46
  "command": "npx tsx .claude/hooks/session-start.ts",
47
47
  "timeout": 10000,
48
48
  "on_failure": "ignore"
49
+ },
50
+ {
51
+ "type": "command",
52
+ "command": "npx tsx .claude/hooks/sprint-registry.ts",
53
+ "timeout": 5000,
54
+ "on_failure": "ignore"
49
55
  }
50
56
  ]
51
57
  }
@@ -126,6 +132,19 @@
126
132
  ]
127
133
  }
128
134
  ],
135
+ "PostToolUse": [
136
+ {
137
+ "matcher": "",
138
+ "hooks": [
139
+ {
140
+ "type": "command",
141
+ "command": "npx tsx .claude/hooks/mailbox-listener.ts",
142
+ "timeout": 5000,
143
+ "on_failure": "ignore"
144
+ }
145
+ ]
146
+ }
147
+ ],
129
148
  "PostCompact": [
130
149
  {
131
150
  "matcher": "",
@@ -0,0 +1,176 @@
1
+ ---
2
+ name: sprint-launch
3
+ description: >
4
+ Launch parallel Claude sessions in tmux for sprint execution.
5
+ Use when starting a sprint with independent tasks that benefit from parallel panes.
6
+ Supports duo, duo-doc, squad, squad-review, platoon, and platoon-full presets
7
+ covering 2 to 5+ pane configurations.
8
+ argument-hint: <preset> [workflow-id]
9
+ ---
10
+
11
+ # Sprint Launcher — RFC-025 v2
12
+
13
+ Launch parallel Claude sessions in tmux panes, each isolated in a git worktree, to execute sprint tasks concurrently.
14
+
15
+ ## When to Use
16
+
17
+ - Starting a sprint with 1-5 independent task tracks
18
+ - You want parallel agent sessions with worktree isolation
19
+ - RFC-021 Sprints, ADR-017 phases, or any feature work with clear task separation
20
+
21
+ ## Prerequisites
22
+
23
+ Before launching, verify:
24
+ 1. **tmux** is installed and on PATH (`tmux -V`)
25
+ 2. **claude** CLI is on PATH (`claude --version`)
26
+ 3. **git** repo is clean (no uncommitted changes that could conflict with worktrees)
27
+ 4. An active workflow exists (or you have a workflowId)
28
+
29
+ ## Presets
30
+
31
+ | Preset | Panes | Composition | Use When |
32
+ |--------|-------|-------------|----------|
33
+ | `duo` | 1 | 1 implementer | Simple sprint, 1 task track |
34
+ | `duo-doc` | 2 | 1 implementer + 1 doc-sidecar | Documentation-heavy work |
35
+ | `squad` | 3 | 2 implementers + 1 debug-sidecar | 2 parallel tracks with review |
36
+ | `squad-review` | 3 | 1 implementer + 1 debug-sidecar + 1 doc-sidecar | Quality-critical single track |
37
+ | `platoon` | 5 | 3 implementers + 1 reviewer + 1 debug-sidecar | 3 parallel tracks with review |
38
+ | `platoon-full` | 7 | 2 implementers + 2 doc-sidecars + 1 debug-sidecar + 1 test-sidecar + 1 reviewer | Complex sprint with full observability |
39
+
40
+ ## Protocol
41
+
42
+ **IMPORTANT: Always confirm with the user before launching.**
43
+
44
+ ### Step 1: Gather Parameters
45
+
46
+ Parse from user input or active workflow context:
47
+ - **preset**: one of the 6 presets above (required)
48
+ - **workflowId**: from active workflow or user input (optional — script generates one if missing)
49
+
50
+ ### Step 2: Confirm via AskUserQuestion
51
+
52
+ Before executing anything, present the launch plan:
53
+
54
+ ```
55
+ AskUserQuestion({
56
+ question: "Sprint Launch: {preset} preset\n\nSession: sprint-{wfId:0:8}\nPanes: {pane descriptions}\nWorktrees: ../wt-sprint-{wfId:0:8}-{0,1,...}\n\nProceed?",
57
+ options: ["Launch", "Change preset", "Cancel"]
58
+ })
59
+ ```
60
+
61
+ ### Step 3: Execute
62
+
63
+ On user approval, run via TypeScript launcher:
64
+
65
+ ```bash
66
+ npx tsx scripts/sprint-launch.ts {preset} {workflowId}
67
+
68
+ # With task distribution (--task is repeatable, round-robin to implementer panes):
69
+ npx tsx scripts/sprint-launch.ts {preset} {workflowId} --mailbox \
70
+ --task "TASK-001: Implement auth endpoint" \
71
+ --task "TASK-002: Write integration tests"
72
+
73
+ # With tasks fetched from REST API (graceful fallback if API unavailable):
74
+ npx tsx scripts/sprint-launch.ts {preset} {workflowId} --mailbox --fetch-tasks
75
+ ```
76
+
77
+ ### Step 4: Auto-attach
78
+
79
+ The script automatically attaches after launching panes and injecting startup prompts:
80
+
81
+ - **Inside tmux**: opens a horizontal split pointing at the new session — zero user action required
82
+ - **Outside tmux**: prints the attach command to console, e.g. `tmux attach -t sprint-{prefix}`
83
+
84
+ Startup prompts are injected into each pane automatically. If a pane fails to receive its prompt, auto-attach still proceeds.
85
+
86
+ ## Task Distribution
87
+
88
+ When launching with tasks, the launcher distributes them **round-robin to implementer panes only**.
89
+ Sidecar agents (doc-sidecar, debug-sidecar, test-sidecar) react to implementer progress via mailbox
90
+ and do not receive direct task_assignment messages from the launcher.
91
+
92
+ ### --task flag (repeatable)
93
+
94
+ ```bash
95
+ --task "TASK-001: Title"
96
+ ```
97
+
98
+ - Parses `TASK-001` as `taskId` and `Title` as `title`
99
+ - Produces a `task_assignment` mailbox message with `description: ''` and `acceptanceCriteria: []`
100
+ - Tasks are distributed round-robin: task[0] → implementer[0], task[1] → implementer[1], task[2] → implementer[0], etc.
101
+ - The task title is also injected into the pane's CLAUDE.md as a hint (via WorktreeIsolator)
102
+
103
+ ### --fetch-tasks flag
104
+
105
+ ```bash
106
+ --fetch-tasks
107
+ ```
108
+
109
+ - Calls `GET /api/workflows/{workflowId}/tasks` on the configured REST API (`ORCHESTRATOR_API_URL` env var, default `http://localhost:3000`)
110
+ - Appends fetched tasks to any `--task` CLI tasks
111
+ - Graceful fallback: if the API is unreachable or returns an error, prints a warning and continues with CLI tasks only
112
+
113
+ ### Agent Protocol
114
+
115
+ Agents receive tasks via the sprint-teammate skill. See `.claude/skills/sprint-teammate/sprint-teammate.md`.
116
+
117
+ ## Critical Rules
118
+
119
+ 1. **NEVER use `--bare` for implementer panes** — `--bare` suppresses hooks, skills, and MCP tools. Implementers MUST have access to these. The script uses `claude -p` (without `--bare`).
120
+ 2. **Always confirm before launching** — never auto-launch panes.
121
+ 3. **Worktrees are cleaned up on exit** — the script traps EXIT/SIGINT/SIGTERM and removes worktrees if interrupted.
122
+ 4. **ANTHROPIC_API_KEY warning** — if unset, script warns but continues (Max OAuth mode assumed).
123
+
124
+ ## Monitoring
125
+
126
+ After launch, check pane health:
127
+
128
+ ```bash
129
+ # Single check
130
+ ./scripts/sprint-status.sh sprint-{prefix} --once
131
+
132
+ # Continuous monitoring (10s interval)
133
+ ./scripts/sprint-status.sh sprint-{prefix}
134
+
135
+ # Custom interval
136
+ POLL_INTERVAL=5 ./scripts/sprint-status.sh sprint-{prefix}
137
+ ```
138
+
139
+ Output shows ALIVE (green) or DEAD (red) per pane.
140
+
141
+ ## Cleanup
142
+
143
+ Worktrees are auto-cleaned on script exit. If a crash leaves orphans:
144
+
145
+ ```bash
146
+ git worktree prune
147
+ git worktree list # verify no wt-sprint-* remain
148
+ ```
149
+
150
+ To kill a running sprint session:
151
+
152
+ ```bash
153
+ tmux kill-session -t sprint-{prefix}
154
+ ```
155
+
156
+ ## Examples
157
+
158
+ ```bash
159
+ # Simple sprint with 1 implementer (auto-attaches)
160
+ /sprint-launch duo
161
+
162
+ # Documentation-heavy sprint
163
+ /sprint-launch duo-doc adaaa9a4-ef49-4e26-af14-2b239f62b40c
164
+
165
+ # 2 parallel tracks
166
+ /sprint-launch squad
167
+
168
+ # 2 tracks with reviewer sidecar
169
+ /sprint-launch squad-review adaaa9a4-ef49-4e26-af14-2b239f62b40c
170
+
171
+ # 3 parallel tracks
172
+ /sprint-launch platoon
173
+
174
+ # 3 tracks with reviewer sidecar
175
+ /sprint-launch platoon-full adaaa9a4-ef49-4e26-af14-2b239f62b40c
176
+ ```
@@ -0,0 +1,79 @@
1
+ # Sprint Teammate Protocol
2
+
3
+ You are a focused sprint agent. Read this protocol at session start.
4
+
5
+ ## Identity Guard
6
+
7
+ Check `process.env.SPRINT_ID`. If set, you are in a sprint session.
8
+ Your role is `process.env.PANE_ROLE`. Your inbox is:
9
+ `/tmp/{SPRINT_ID}/mailbox/{PANE_ROLE}/inbox/`
10
+
11
+ ## On Session Start
12
+
13
+ 1. Read your CLAUDE.md for sprint context (session, workflow, task hint).
14
+ 2. Check your inbox for any `task_assignment` messages.
15
+ 3. If a task is assigned: **execute immediately** — no greeting, no questions.
16
+ 4. If inbox is empty: wait. The mailbox-listener hook will inject messages as they arrive.
17
+
18
+ ## Message Types
19
+
20
+ ### Receiving: task_assignment
21
+ ```json
22
+ {
23
+ "type": "task_assignment",
24
+ "taskId": "TASK-001",
25
+ "title": "Short title",
26
+ "description": "Full description",
27
+ "acceptanceCriteria": ["criterion 1", "criterion 2"]
28
+ }
29
+ ```
30
+ On receipt: start implementation immediately. No acknowledgement needed.
31
+
32
+ ### Sending: task_complete
33
+ ```json
34
+ {
35
+ "type": "task_complete",
36
+ "taskId": "TASK-001",
37
+ "summary": "What was done and where"
38
+ }
39
+ ```
40
+ Write to: `/tmp/{SPRINT_ID}/mailbox/orchestrator-0/inbox/{uuid}.json`
41
+
42
+ ### Sending: status_update
43
+ ```json
44
+ {
45
+ "type": "status_update",
46
+ "taskId": "TASK-001",
47
+ "progress": 50,
48
+ "message": "Tests written, implementing..."
49
+ }
50
+ ```
51
+
52
+ ### Sending: error_report
53
+ ```json
54
+ {
55
+ "type": "error_report",
56
+ "errorCode": "BLOCKER",
57
+ "message": "Cannot proceed because...",
58
+ "taskId": "TASK-001"
59
+ }
60
+ ```
61
+
62
+ ## Mailbox Paths
63
+
64
+ | Direction | Path |
65
+ |-----------|------|
66
+ | Your inbox | `/tmp/{SPRINT_ID}/mailbox/{PANE_ROLE}/inbox/` |
67
+ | Orchestrator | `/tmp/{SPRINT_ID}/mailbox/orchestrator-0/inbox/` |
68
+ | Other pane | `/tmp/{SPRINT_ID}/mailbox/{role}-{index}/inbox/` |
69
+
70
+ Envelope format: `{ "id": "<uuid>", "from": {"role": "...", "index": N}, "to": {"role": "...", "index": N}, "timestamp": "<ISO>", "body": {...} }`
71
+
72
+ ## Self-Guarding Rules
73
+
74
+ - MUST NOT greet users or ask "What would you like to do?"
75
+ - MUST NOT invoke workflow MCP tools (advancePhase, completeWorkflow)
76
+ - MUST NOT spawn sub-agents
77
+ - MUST execute task_assignment immediately upon receipt
78
+ - MUST send task_complete when done
79
+ - MUST send error_report if blocked (do not silently stall)
@@ -0,0 +1,325 @@
1
+ /**
2
+ * SprintLauncher.ts — Orchestrates the full sprint session launch (RFC-025)
3
+ *
4
+ * Responsibilities:
5
+ * 1. Validate prerequisites (tmux on PATH, claude on PATH, no duplicate session)
6
+ * 2. Prune stale worktrees
7
+ * 3. Create worktrees via WorktreeManager (one per pane)
8
+ * 4. Isolate each worktree via WorktreeIsolator
9
+ * 5. Launch tmux session via TmuxManager
10
+ * 6. Return LaunchResult
11
+ *
12
+ * DI via factory function — same pattern as gate-guardian.ts (ADR-017 Phase 4).
13
+ * execSync is injected for testability; in production use child_process.execSync.
14
+ * Input values (preset, workflowId) are validated before use in shell commands.
15
+ */
16
+
17
+ import type { WorktreeManager } from './WorktreeManager.js';
18
+ import type { WorktreeIsolator } from './WorktreeIsolator.js';
19
+ import type { TmuxManager, PaneLaunchConfig } from './TmuxManager.js';
20
+ import { SprintPreset } from '../../src/domain/value-objects/SprintLayout.js';
21
+ import type { PaneConfig } from '../../src/domain/value-objects/SprintLayout.js';
22
+ import type { generateLayout as GenerateLayoutFn } from '../../src/domain/value-objects/generateLayout.js';
23
+
24
+ // ---------------------------------------------------------------------------
25
+ // Constants
26
+ // ---------------------------------------------------------------------------
27
+
28
+ /**
29
+ * Milliseconds to wait after launchLayout before sending activation prompts.
30
+ * Claude Code needs ~5-8 seconds to boot and display the ❯ prompt.
31
+ */
32
+ export const BOOT_DELAY_MS = 7000;
33
+
34
+ // ---------------------------------------------------------------------------
35
+ // Public types
36
+ // ---------------------------------------------------------------------------
37
+
38
+ import type { MailboxAddress, MessageEnvelope } from './mailbox/types.js';
39
+
40
+ /** Minimal MailboxManager interface required by SprintLauncher. */
41
+ export interface MailboxManager {
42
+ /** Create mailbox inbox directories for each role in the sprint. */
43
+ init(addresses: readonly MailboxAddress[]): void;
44
+ /**
45
+ * Send a message envelope to the address encoded in envelope.to.
46
+ * Matches MailboxManager.sendMessage(envelope) from MailboxManager.ts.
47
+ */
48
+ sendMessage(envelope: MessageEnvelope): void;
49
+ }
50
+
51
+ export interface SprintTask {
52
+ taskId: string;
53
+ title: string;
54
+ description: string;
55
+ acceptanceCriteria: string[];
56
+ }
57
+
58
+ export interface LaunchResult {
59
+ sessionName: string;
60
+ workflowId: string;
61
+ preset: string;
62
+ worktreePaths: readonly string[];
63
+ }
64
+
65
+ export interface SprintLauncherDeps {
66
+ worktreeManager: WorktreeManager;
67
+ worktreeIsolator: WorktreeIsolator;
68
+ tmuxManager: TmuxManager;
69
+ generateLayout: typeof GenerateLayoutFn;
70
+ execSync: (cmd: string, opts?: object) => string | Buffer;
71
+ projectRoot: string;
72
+ /** Optional mailbox manager — initialises inbox directories before launch. */
73
+ mailboxManager?: MailboxManager;
74
+ /**
75
+ * Optional delay function — defaults to real setTimeout-based delay.
76
+ * Inject a no-op `() => Promise.resolve()` in tests to avoid 7s waits.
77
+ */
78
+ delay?: (ms: number) => Promise<void>;
79
+ }
80
+
81
+ export interface SprintLauncher {
82
+ launch(presetName: string, workflowId: string, tasks?: SprintTask[]): Promise<LaunchResult>;
83
+ cleanup(sessionName: string): void;
84
+ }
85
+
86
+ // ---------------------------------------------------------------------------
87
+ // Factory
88
+ // ---------------------------------------------------------------------------
89
+
90
+ /**
91
+ * Returns true when the agent role is a reactive sidecar (RFC-025 v3.3).
92
+ * Sidecars launch as Node.js watcher processes instead of interactive claude sessions.
93
+ * Implementers, reviewers, and other roles remain interactive.
94
+ */
95
+ function isSidecarRole(role: string): boolean {
96
+ return role.includes('sidecar');
97
+ }
98
+
99
+ /**
100
+ * Builds the shell command for a reactive sidecar pane.
101
+ * Launches the SidecarWatcher script which watches the mailbox inbox
102
+ * and spawns Agent SDK query() calls on demand.
103
+ *
104
+ * The inbox path matches MailboxManager's layout: `/tmp/{sessionName}/mailbox/{role}-{index}/inbox`
105
+ *
106
+ * NOTE: The script runs from `projectRoot` (not the worktree) so that node_modules
107
+ * are available for chokidar and SDK imports. The worktree is passed as --worktree
108
+ * and used as cwd for the SDK query() call.
109
+ */
110
+ function buildSidecarCommand(agentSlug: string, worktreePath: string, sessionName: string, mailboxRole: string, paneIndex: number, projectRoot: string): string {
111
+ const inboxPath = `/tmp/${sessionName}/mailbox/${mailboxRole}-${paneIndex}/inbox`;
112
+ return `cd "${projectRoot}" && npx tsx scripts/lib/sidecar/run.ts --inbox "${inboxPath}" --worktree "${worktreePath}" --agent ${agentSlug}`;
113
+ }
114
+
115
+ export function createSprintLauncher(deps: SprintLauncherDeps): SprintLauncher {
116
+ const { worktreeManager, worktreeIsolator, tmuxManager, generateLayout, execSync, mailboxManager } = deps;
117
+ const delay = deps.delay ?? ((ms: number) => new Promise<void>((resolve) => setTimeout(resolve, ms)));
118
+
119
+ function validatePrerequisites(sessionName: string): void {
120
+ // Validate tmux is on PATH (static command — no user input)
121
+ try {
122
+ execSync('which tmux', { stdio: 'pipe' });
123
+ } catch {
124
+ throw new Error(
125
+ 'tmux is not on PATH. Install tmux to use sprint-launch.',
126
+ );
127
+ }
128
+
129
+ // Validate claude is on PATH (static command — no user input)
130
+ try {
131
+ execSync('which claude', { stdio: 'pipe' });
132
+ } catch {
133
+ throw new Error(
134
+ 'claude is not on PATH. Install Claude Code CLI to use sprint-launch.',
135
+ );
136
+ }
137
+
138
+ // Guard against duplicate session via TmuxManager (no shell exec here)
139
+ if (tmuxManager.hasSession(sessionName)) {
140
+ throw new Error(
141
+ `tmux session '${sessionName}' already exists. Attach with: tmux attach -t ${sessionName}`,
142
+ );
143
+ }
144
+ }
145
+
146
+ async function launch(presetName: string, workflowId: string, tasks?: SprintTask[]): Promise<LaunchResult> {
147
+ // 1. Validate preset (validates input before any use in commands)
148
+ const presetResult = SprintPreset.create(presetName);
149
+ if (presetResult.isErr()) {
150
+ throw new Error(`Invalid preset: ${presetResult.error}`);
151
+ }
152
+ const preset = presetResult.value;
153
+
154
+ // 2. Derive session name
155
+ const sessionName = `sprint-${workflowId.slice(0, 8)}`;
156
+
157
+ // 3. Validate prerequisites
158
+ validatePrerequisites(sessionName);
159
+
160
+ // 4. Generate layout
161
+ const layoutResult = generateLayout(preset, workflowId);
162
+ if (layoutResult.isErr()) {
163
+ throw new Error(`Failed to generate layout: ${layoutResult.error}`);
164
+ }
165
+ const layout = layoutResult.value;
166
+
167
+ // 5. Initialise mailbox inbox directories (before worktree prune)
168
+ if (mailboxManager) {
169
+ const addresses: MailboxAddress[] = layout.panes.map((p: PaneConfig, i: number) => ({
170
+ role: p.context.mailboxRole as MailboxAddress['role'],
171
+ index: i,
172
+ }));
173
+ mailboxManager.init(addresses);
174
+ }
175
+
176
+ // 6. Prune stale worktrees
177
+ worktreeManager.prune();
178
+
179
+ // 7. Create worktrees (one per pane, indexed)
180
+ const worktreePaths: string[] = [];
181
+ for (let i = 0; i < layout.panes.length; i++) {
182
+ const worktreePath = worktreeManager.addWorktree(i, sessionName);
183
+ worktreePaths.push(worktreePath);
184
+ }
185
+
186
+ // 8. Build round-robin task assignment map (implementer panes only).
187
+ // PaneConfig is frozen — use a separate Map to track assignments.
188
+ const paneTaskMap = new Map<number, SprintTask>();
189
+ if (tasks && tasks.length > 0) {
190
+ const implementerIndices = layout.panes
191
+ .map((pane: PaneConfig, i: number) => ({ pane, i }))
192
+ .filter(({ pane }) => pane.agent.includes('implementer'))
193
+ .map(({ i }) => i);
194
+
195
+ for (let t = 0; t < tasks.length; t++) {
196
+ const paneIndex = implementerIndices[t % implementerIndices.length];
197
+ if (paneIndex !== undefined) {
198
+ paneTaskMap.set(paneIndex, tasks[t]);
199
+ }
200
+ }
201
+ }
202
+
203
+ // 9. Isolate each worktree — inject sprint context into CLAUDE.md
204
+ // so agents know their workflow, mailbox, and task at startup.
205
+ // Zero tmux input needed (TD-133 resolved via CLAUDE.md injection).
206
+ for (let i = 0; i < layout.panes.length; i++) {
207
+ const pane = layout.panes[i];
208
+ const assignedTask = paneTaskMap.get(i);
209
+ worktreeIsolator.isolateWorktree(pane.agent, worktreePaths[i], {
210
+ sessionName,
211
+ workflowId,
212
+ mailboxRole: `${pane.context.mailboxRole}-${i}`,
213
+ task: assignedTask?.title ?? pane.context.task,
214
+ });
215
+ }
216
+
217
+ // 10. Send task assignment messages to agents via mailbox (before launch)
218
+ if (mailboxManager) {
219
+ for (let i = 0; i < layout.panes.length; i++) {
220
+ const pane = layout.panes[i];
221
+ const assignedTask = paneTaskMap.get(i);
222
+
223
+ // Use assigned SprintTask if available, otherwise fall back to pane.context.task
224
+ if (assignedTask) {
225
+ const address: MailboxAddress = {
226
+ role: pane.context.mailboxRole as MailboxAddress['role'],
227
+ index: i,
228
+ };
229
+ const envelope: MessageEnvelope = {
230
+ id: crypto.randomUUID(),
231
+ from: { role: 'orchestrator', index: 0 },
232
+ to: address,
233
+ timestamp: new Date().toISOString(),
234
+ body: {
235
+ type: 'task_assignment',
236
+ taskId: assignedTask.taskId,
237
+ title: assignedTask.title,
238
+ description: assignedTask.description,
239
+ acceptanceCriteria: assignedTask.acceptanceCriteria,
240
+ },
241
+ };
242
+ mailboxManager.sendMessage(envelope);
243
+ } else if (pane.context.task) {
244
+ const address: MailboxAddress = {
245
+ role: pane.context.mailboxRole as MailboxAddress['role'],
246
+ index: i,
247
+ };
248
+ const envelope: MessageEnvelope = {
249
+ id: crypto.randomUUID(),
250
+ from: { role: 'orchestrator', index: 0 },
251
+ to: address,
252
+ timestamp: new Date().toISOString(),
253
+ body: {
254
+ type: 'task_assignment',
255
+ taskId: `task-${i}`,
256
+ title: pane.context.task,
257
+ description: '',
258
+ acceptanceCriteria: [],
259
+ },
260
+ };
261
+ mailboxManager.sendMessage(envelope);
262
+ }
263
+ }
264
+ }
265
+
266
+ // 11. Build PaneLaunchConfig[] for TmuxManager (no initialPrompt needed)
267
+ // Sidecar panes get a custom `command` that launches the reactive watcher
268
+ // instead of an interactive `claude --agent` session (RFC-025 v3.3).
269
+ const paneLaunchConfigs: PaneLaunchConfig[] = layout.panes.map((pane: PaneConfig, i: number) => {
270
+ const config: PaneLaunchConfig = {
271
+ role: pane.agent,
272
+ workdir: worktreePaths[i],
273
+ sprintId: sessionName,
274
+ paneRole: `${pane.context.mailboxRole}-${i}`,
275
+ };
276
+ if (isSidecarRole(pane.agent)) {
277
+ config.command = buildSidecarCommand(
278
+ pane.agent,
279
+ worktreePaths[i],
280
+ sessionName,
281
+ pane.context.mailboxRole as string,
282
+ i,
283
+ deps.projectRoot,
284
+ );
285
+ }
286
+ return config;
287
+ });
288
+
289
+ // 12. Launch tmux session (interactive mode — TUI visible, context from CLAUDE.md)
290
+ tmuxManager.launchLayout(sessionName, paneLaunchConfigs);
291
+
292
+ // 12a. Wait for Claude to boot then activate implementer panes.
293
+ // Sidecars stay idle — they respond reactively in a future version.
294
+ const implementerIndicesForActivation = paneLaunchConfigs
295
+ .map((pane, i) => ({ pane, i }))
296
+ .filter(({ pane }) => pane.role.includes('implementer'))
297
+ .map(({ i }) => i);
298
+
299
+ if (implementerIndicesForActivation.length > 0) {
300
+ // eslint-disable-next-line no-console
301
+ console.log('[sprint-launch] Activating implementer panes...');
302
+ await delay(BOOT_DELAY_MS);
303
+ for (const paneIndex of implementerIndicesForActivation) {
304
+ tmuxManager.sendPromptLiteral(sessionName, paneIndex, 'siga');
305
+ }
306
+ }
307
+
308
+ // 13. Auto-attach for seamless UX
309
+ tmuxManager.autoAttach(sessionName);
310
+
311
+ return {
312
+ sessionName,
313
+ workflowId,
314
+ preset: preset.value,
315
+ worktreePaths: Object.freeze(worktreePaths),
316
+ };
317
+ }
318
+
319
+ function cleanup(sessionName: string): void {
320
+ worktreeManager.removeAll(sessionName);
321
+ tmuxManager.killSession(sessionName);
322
+ }
323
+
324
+ return { launch, cleanup };
325
+ }