claude-code-workflow 6.3.52 → 6.3.54

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 (43) hide show
  1. package/.claude/agents/action-planning-agent.md +26 -1
  2. package/.claude/agents/cli-lite-planning-agent.md +66 -2
  3. package/.claude/commands/codex-coordinator.md +513 -0
  4. package/.claude/commands/flow-create.md +675 -0
  5. package/.claude/commands/workflow/collaborative-plan-with-file.md +761 -0
  6. package/.claude/commands/workflow/lite-fix.md +49 -20
  7. package/.claude/commands/workflow/lite-plan.md +35 -8
  8. package/.claude/commands/workflow/plan.md +14 -1
  9. package/.claude/commands/workflow/tools/task-generate-agent.md +35 -24
  10. package/.claude/commands/workflow/unified-execute-with-file.md +101 -19
  11. package/.claude/skills/flow-coordinator/SKILL.md +394 -0
  12. package/.claude/skills/flow-coordinator/templates/analyze.json +16 -0
  13. package/.claude/skills/flow-coordinator/templates/brainstorm-to-issue.json +36 -0
  14. package/.claude/skills/flow-coordinator/templates/brainstorm.json +16 -0
  15. package/.claude/skills/flow-coordinator/templates/bugfix-hotfix.json +16 -0
  16. package/.claude/skills/flow-coordinator/templates/bugfix.json +47 -0
  17. package/.claude/skills/flow-coordinator/templates/coupled.json +71 -0
  18. package/.claude/skills/flow-coordinator/templates/debug.json +16 -0
  19. package/.claude/skills/flow-coordinator/templates/docs.json +27 -0
  20. package/.claude/skills/flow-coordinator/templates/full.json +61 -0
  21. package/.claude/skills/flow-coordinator/templates/issue.json +43 -0
  22. package/.claude/skills/flow-coordinator/templates/lite-lite-lite.json +16 -0
  23. package/.claude/skills/flow-coordinator/templates/multi-cli-plan.json +47 -0
  24. package/.claude/skills/flow-coordinator/templates/rapid-to-issue.json +46 -0
  25. package/.claude/skills/flow-coordinator/templates/rapid.json +47 -0
  26. package/.claude/skills/flow-coordinator/templates/review.json +43 -0
  27. package/.claude/skills/flow-coordinator/templates/tdd.json +34 -0
  28. package/.claude/skills/flow-coordinator/templates/test-fix.json +26 -0
  29. package/ccw/dist/tools/claude-cli-tools.d.ts +8 -0
  30. package/ccw/dist/tools/claude-cli-tools.d.ts.map +1 -1
  31. package/ccw/dist/tools/claude-cli-tools.js +13 -2
  32. package/ccw/dist/tools/claude-cli-tools.js.map +1 -1
  33. package/ccw/dist/tools/cli-executor-core.d.ts.map +1 -1
  34. package/ccw/dist/tools/cli-executor-core.js +24 -3
  35. package/ccw/dist/tools/cli-executor-core.js.map +1 -1
  36. package/ccw/src/templates/dashboard-js/components/cli-status.js +28 -0
  37. package/ccw/src/templates/dashboard-js/views/cli-manager.js +44 -0
  38. package/ccw/src/tools/claude-cli-tools.ts +20 -2
  39. package/ccw/src/tools/cli-executor-core.ts +23 -4
  40. package/package.json +92 -92
  41. package/.claude/commands/workflow/merge-plans-with-file.md +0 -807
  42. package/.claude/commands/workflow/quick-plan-with-file.md +0 -808
  43. package/.codex/prompts/quick-plan-with-file.md +0 -450
@@ -0,0 +1,761 @@
1
+ ---
2
+ name: workflow:collaborative-plan-with-file
3
+ description: Unified collaborative planning with dynamic requirement splitting, parallel sub-agent exploration/understanding/planning, and automatic merge. Each agent maintains process files for full traceability.
4
+ argument-hint: "[-y|--yes] <task description> [--max-agents=5] [--depth=normal|deep] [--merge-rule=consensus|priority]"
5
+ allowed-tools: TodoWrite(*), Task(*), AskUserQuestion(*), Read(*), Bash(*), Write(*), Glob(*), Grep(*), mcp__ace-tool__search_context(*)
6
+ ---
7
+
8
+ ## Auto Mode
9
+
10
+ When `--yes` or `-y`: Auto-approve splits, use default merge rule, skip confirmations.
11
+
12
+ # Collaborative Planning Command
13
+
14
+ ## Quick Start
15
+
16
+ ```bash
17
+ # Basic usage
18
+ /workflow:collaborative-plan-with-file "Implement real-time notification system"
19
+
20
+ # With options
21
+ /workflow:collaborative-plan-with-file "Refactor authentication module" --max-agents=4
22
+ /workflow:collaborative-plan-with-file "Add payment gateway support" --depth=deep
23
+ /workflow:collaborative-plan-with-file "Migrate to microservices" --merge-rule=priority
24
+ ```
25
+
26
+ **Context Source**: ACE semantic search + Per-agent CLI exploration
27
+ **Output Directory**: `.workflow/.planning/{session-id}/`
28
+ **Default Max Agents**: 5 (actual count based on requirement complexity)
29
+ **CLI Tools**: cli-lite-planning-agent (internally calls ccw cli with gemini/codex/qwen)
30
+ **Schema**: plan-json-schema.json (sub-plans & final plan share same base schema)
31
+
32
+ ## Output Artifacts
33
+
34
+ ### Per Sub-Agent (Phase 2)
35
+
36
+ | Artifact | Description |
37
+ |----------|-------------|
38
+ | `planning-context.md` | Evidence paths + synthesized understanding |
39
+ | `sub-plan.json` | Sub-plan following plan-json-schema.json |
40
+
41
+ ### Final Output (Phase 4)
42
+
43
+ | Artifact | Description |
44
+ |----------|-------------|
45
+ | `requirement-analysis.json` | Requirement breakdown and sub-agent assignments |
46
+ | `conflicts.json` | Detected conflicts between sub-plans |
47
+ | `plan.json` | Merged plan (plan-json-schema + merge_metadata) |
48
+ | `plan.md` | Human-readable plan summary |
49
+
50
+ **Agent**: `cli-lite-planning-agent` with `process_docs: true` for sub-agents
51
+
52
+ ## Overview
53
+
54
+ Unified collaborative planning workflow that:
55
+
56
+ 1. **Analyzes** complex requirements and splits into sub-requirements
57
+ 2. **Spawns** parallel sub-agents, each responsible for one sub-requirement
58
+ 3. **Each agent** maintains process files: planning-refs.md + sub-plan.json
59
+ 4. **Merges** all sub-plans into unified plan.json with conflict resolution
60
+
61
+ ```
62
+ ┌─────────────────────────────────────────────────────────────────────────┐
63
+ │ COLLABORATIVE PLANNING │
64
+ ├─────────────────────────────────────────────────────────────────────────┤
65
+ │ │
66
+ │ Phase 1: Requirement Analysis & Splitting │
67
+ │ ├─ Analyze requirement complexity │
68
+ │ ├─ Identify 2-5 sub-requirements (focus areas) │
69
+ │ └─ Write requirement-analysis.json │
70
+ │ │
71
+ │ Phase 2: Parallel Sub-Agent Execution │
72
+ │ ┌──────────────┬──────────────┬──────────────┐ │
73
+ │ │ Agent 1 │ Agent 2 │ Agent N │ │
74
+ ├──────────────┼──────────────┼──────────────┤ │
75
+ │ │ planning │ planning │ planning │ → planning-context.md│
76
+ │ │ + sub-plan │ + sub-plan │ + sub-plan │ → sub-plan.json │
77
+ │ └──────────────┴──────────────┴──────────────┘ │
78
+ │ │
79
+ │ Phase 3: Cross-Verification & Conflict Detection │
80
+ │ ├─ Load all sub-plan.json files │
81
+ │ ├─ Detect conflicts (effort, approach, dependencies) │
82
+ │ └─ Write conflicts.json │
83
+ │ │
84
+ │ Phase 4: Merge & Synthesis │
85
+ │ ├─ Resolve conflicts using merge-rule │
86
+ │ ├─ Merge all sub-plans into unified plan │
87
+ │ └─ Write plan.json + plan.md │
88
+ │ │
89
+ └─────────────────────────────────────────────────────────────────────────┘
90
+ ```
91
+
92
+ ## Output Structure
93
+
94
+ ```
95
+ .workflow/.planning/{CPLAN-slug-YYYY-MM-DD}/
96
+ ├── requirement-analysis.json # Phase 1: Requirement breakdown
97
+ ├── agents/ # Phase 2: Per-agent process files
98
+ │ ├── {focus-area-1}/
99
+ │ │ ├── planning-context.md # Evidence + understanding
100
+ │ │ └── sub-plan.json # Agent's plan for this focus area
101
+ │ ├── {focus-area-2}/
102
+ │ │ └── ...
103
+ │ └── {focus-area-N}/
104
+ │ └── ...
105
+ ├── conflicts.json # Phase 3: Detected conflicts
106
+ ├── plan.json # Phase 4: Unified merged plan
107
+ └── plan.md # Phase 4: Human-readable plan
108
+ ```
109
+
110
+ ## Implementation
111
+
112
+ ### Session Initialization
113
+
114
+ ```javascript
115
+ const getUtc8ISOString = () => new Date(Date.now() + 8 * 60 * 60 * 1000).toISOString()
116
+
117
+ const taskDescription = "$ARGUMENTS"
118
+ const taskSlug = taskDescription.toLowerCase()
119
+ .replace(/[^a-z0-9\u4e00-\u9fa5]+/g, '-')
120
+ .substring(0, 30)
121
+
122
+ const sessionId = `CPLAN-${taskSlug}-${getUtc8ISOString().substring(0, 10)}`
123
+ const sessionFolder = `.workflow/.planning/${sessionId}`
124
+
125
+ // Parse options
126
+ const maxAgents = parseInt($ARGUMENTS.match(/--max-agents=(\d+)/)?.[1] || '5')
127
+ const depth = $ARGUMENTS.match(/--depth=(normal|deep)/)?.[1] || 'normal'
128
+ const mergeRule = $ARGUMENTS.match(/--merge-rule=(consensus|priority)/)?.[1] || 'consensus'
129
+ const autoMode = $ARGUMENTS.includes('--yes') || $ARGUMENTS.includes('-y')
130
+
131
+ Bash(`mkdir -p ${sessionFolder}/agents`)
132
+ ```
133
+
134
+ ### Phase 1: Requirement Analysis & Splitting
135
+
136
+ Use CLI to analyze and split requirements:
137
+
138
+ ```javascript
139
+ TodoWrite({ todos: [
140
+ { content: "Phase 1: Requirement Analysis", status: "in_progress", activeForm: "Analyzing requirements" },
141
+ { content: "Phase 2: Parallel Agent Execution", status: "pending", activeForm: "Running agents" },
142
+ { content: "Phase 3: Conflict Detection", status: "pending", activeForm: "Detecting conflicts" },
143
+ { content: "Phase 4: Merge & Synthesis", status: "pending", activeForm: "Merging plans" }
144
+ ]})
145
+
146
+ // Step 1.1: Use CLI to analyze requirement and propose splits
147
+ Bash({
148
+ command: `ccw cli -p "
149
+ PURPOSE: Analyze requirement and identify distinct sub-requirements/focus areas
150
+ Success: 2-${maxAgents} clearly separated sub-requirements that can be planned independently
151
+
152
+ TASK:
153
+ • Understand the overall requirement: '${taskDescription}'
154
+ • Identify major components, features, or concerns
155
+ • Split into 2-${maxAgents} independent sub-requirements
156
+ • Each sub-requirement should be:
157
+ - Self-contained (can be planned independently)
158
+ - Non-overlapping (minimal dependency on other sub-requirements)
159
+ - Roughly equal in complexity
160
+ • For each sub-requirement, provide:
161
+ - focus_area: Short identifier (e.g., 'auth-backend', 'ui-components')
162
+ - description: What this sub-requirement covers
163
+ - key_concerns: Main challenges or considerations
164
+ - suggested_cli_tool: Which CLI tool is best suited (gemini/codex/qwen)
165
+
166
+ MODE: analysis
167
+
168
+ CONTEXT: @**/*
169
+
170
+ EXPECTED: JSON output with structure:
171
+ {
172
+ \"original_requirement\": \"...\",
173
+ \"complexity\": \"low|medium|high\",
174
+ \"sub_requirements\": [
175
+ {
176
+ \"index\": 1,
177
+ \"focus_area\": \"...\",
178
+ \"description\": \"...\",
179
+ \"key_concerns\": [\"...\"],
180
+ \"suggested_cli_tool\": \"gemini|codex|qwen\",
181
+ \"estimated_effort\": \"low|medium|high\"
182
+ }
183
+ ],
184
+ \"dependencies_between_subs\": [
185
+ { \"from\": 1, \"to\": 2, \"reason\": \"...\" }
186
+ ],
187
+ \"rationale\": \"Why this split was chosen\"
188
+ }
189
+
190
+ CONSTRAINTS: Maximum ${maxAgents} sub-requirements | Ensure clear boundaries
191
+ " --tool gemini --mode analysis`,
192
+ run_in_background: true
193
+ })
194
+
195
+ // Wait for CLI completion and parse result
196
+ // ... (hook callback will provide result)
197
+ ```
198
+
199
+ **After CLI completes**:
200
+
201
+ ```javascript
202
+ // Parse CLI output to extract sub-requirements
203
+ const analysisResult = parseCLIOutput(cliOutput)
204
+ const subRequirements = analysisResult.sub_requirements
205
+
206
+ // Write requirement-analysis.json
207
+ Write(`${sessionFolder}/requirement-analysis.json`, JSON.stringify({
208
+ session_id: sessionId,
209
+ original_requirement: taskDescription,
210
+ analysis_timestamp: getUtc8ISOString(),
211
+ complexity: analysisResult.complexity,
212
+ sub_requirements: subRequirements,
213
+ dependencies_between_subs: analysisResult.dependencies_between_subs,
214
+ rationale: analysisResult.rationale,
215
+ options: { maxAgents, depth, mergeRule }
216
+ }, null, 2))
217
+
218
+ // Create agent folders
219
+ subRequirements.forEach(sub => {
220
+ Bash(`mkdir -p ${sessionFolder}/agents/${sub.focus_area}`)
221
+ })
222
+
223
+ // User confirmation (unless auto mode)
224
+ if (!autoMode) {
225
+ AskUserQuestion({
226
+ questions: [{
227
+ question: `已识别 ${subRequirements.length} 个子需求:\n${subRequirements.map((s, i) => `${i+1}. ${s.focus_area}: ${s.description}`).join('\n')}\n\n确认开始并行规划?`,
228
+ header: "Confirm Split",
229
+ multiSelect: false,
230
+ options: [
231
+ { label: "开始规划", description: "启动并行sub-agent" },
232
+ { label: "调整拆分", description: "修改子需求划分" },
233
+ { label: "取消", description: "退出规划" }
234
+ ]
235
+ }]
236
+ })
237
+ }
238
+ ```
239
+
240
+ ### Phase 2: Parallel Sub-Agent Execution
241
+
242
+ Launch one agent per sub-requirement, each maintaining its own process files:
243
+
244
+ ```javascript
245
+ TodoWrite({ todos: [
246
+ { content: "Phase 1: Requirement Analysis", status: "completed", activeForm: "Analyzing requirements" },
247
+ { content: "Phase 2: Parallel Agent Execution", status: "in_progress", activeForm: "Running agents" },
248
+ ...subRequirements.map((sub, i) => ({
249
+ content: ` → Agent ${i+1}: ${sub.focus_area}`,
250
+ status: "pending",
251
+ activeForm: `Planning ${sub.focus_area}`
252
+ })),
253
+ { content: "Phase 3: Conflict Detection", status: "pending", activeForm: "Detecting conflicts" },
254
+ { content: "Phase 4: Merge & Synthesis", status: "pending", activeForm: "Merging plans" }
255
+ ]})
256
+
257
+ // Launch all sub-agents in parallel
258
+ const agentPromises = subRequirements.map((sub, index) => {
259
+ return Task({
260
+ subagent_type: "cli-lite-planning-agent",
261
+ run_in_background: false,
262
+ description: `Plan: ${sub.focus_area}`,
263
+ prompt: `
264
+ ## Sub-Agent Context
265
+
266
+ You are planning ONE sub-requirement. Generate process docs + sub-plan.
267
+
268
+ **Focus Area**: ${sub.focus_area}
269
+ **Description**: ${sub.description}
270
+ **Key Concerns**: ${sub.key_concerns.join(', ')}
271
+ **CLI Tool**: ${sub.suggested_cli_tool}
272
+ **Depth**: ${depth}
273
+
274
+ ## Input Context
275
+
276
+ \`\`\`json
277
+ {
278
+ "task_description": "${sub.description}",
279
+ "schema_path": "~/.claude/workflows/cli-templates/schemas/plan-json-schema.json",
280
+ "session": { "id": "${sessionId}", "folder": "${sessionFolder}" },
281
+ "process_docs": true,
282
+ "focus_area": "${sub.focus_area}",
283
+ "output_folder": "${sessionFolder}/agents/${sub.focus_area}",
284
+ "cli_config": { "tool": "${sub.suggested_cli_tool}" },
285
+ "parent_requirement": "${taskDescription}"
286
+ }
287
+ \`\`\`
288
+
289
+ ## Output Requirements
290
+
291
+ Write 2 files to \`${sessionFolder}/agents/${sub.focus_area}/\`:
292
+ 1. **planning-context.md** - Evidence paths + synthesized understanding
293
+ 2. **sub-plan.json** - Plan with \`_metadata.source_agent: "${sub.focus_area}"\`
294
+
295
+ See cli-lite-planning-agent documentation for file formats.
296
+ `
297
+ })
298
+ })
299
+
300
+ // Wait for all agents to complete
301
+ const agentResults = await Promise.all(agentPromises)
302
+ ```
303
+
304
+ ### Phase 3: Cross-Verification & Conflict Detection
305
+
306
+ Load all sub-plans and detect conflicts:
307
+
308
+ ```javascript
309
+ TodoWrite({ todos: [
310
+ { content: "Phase 1: Requirement Analysis", status: "completed", activeForm: "Analyzing requirements" },
311
+ { content: "Phase 2: Parallel Agent Execution", status: "completed", activeForm: "Running agents" },
312
+ { content: "Phase 3: Conflict Detection", status: "in_progress", activeForm: "Detecting conflicts" },
313
+ { content: "Phase 4: Merge & Synthesis", status: "pending", activeForm: "Merging plans" }
314
+ ]})
315
+
316
+ // Load all sub-plans
317
+ const subPlans = subRequirements.map(sub => {
318
+ const planPath = `${sessionFolder}/agents/${sub.focus_area}/sub-plan.json`
319
+ const content = Read(planPath)
320
+ return {
321
+ focus_area: sub.focus_area,
322
+ index: sub.index,
323
+ plan: JSON.parse(content)
324
+ }
325
+ })
326
+
327
+ // Detect conflicts
328
+ const conflicts = {
329
+ detected_at: getUtc8ISOString(),
330
+ total_sub_plans: subPlans.length,
331
+ conflicts: []
332
+ }
333
+
334
+ // 1. Effort conflicts (same task estimated differently)
335
+ const effortConflicts = detectEffortConflicts(subPlans)
336
+ conflicts.conflicts.push(...effortConflicts)
337
+
338
+ // 2. File conflicts (multiple agents modifying same file)
339
+ const fileConflicts = detectFileConflicts(subPlans)
340
+ conflicts.conflicts.push(...fileConflicts)
341
+
342
+ // 3. Approach conflicts (different approaches to same problem)
343
+ const approachConflicts = detectApproachConflicts(subPlans)
344
+ conflicts.conflicts.push(...approachConflicts)
345
+
346
+ // 4. Dependency conflicts (circular or missing dependencies)
347
+ const dependencyConflicts = detectDependencyConflicts(subPlans)
348
+ conflicts.conflicts.push(...dependencyConflicts)
349
+
350
+ // Write conflicts.json
351
+ Write(`${sessionFolder}/conflicts.json`, JSON.stringify(conflicts, null, 2))
352
+
353
+ console.log(`
354
+ ## Conflict Detection Complete
355
+
356
+ **Total Sub-Plans**: ${subPlans.length}
357
+ **Conflicts Found**: ${conflicts.conflicts.length}
358
+
359
+ ${conflicts.conflicts.length > 0 ? `
360
+ ### Conflicts:
361
+ ${conflicts.conflicts.map((c, i) => `
362
+ ${i+1}. **${c.type}** (${c.severity})
363
+ - Agents: ${c.agents_involved.join(' vs ')}
364
+ - Issue: ${c.description}
365
+ - Suggested Resolution: ${c.suggested_resolution}
366
+ `).join('\n')}
367
+ ` : '✅ No conflicts detected - sub-plans are compatible'}
368
+ `)
369
+ ```
370
+
371
+ **Conflict Detection Functions**:
372
+
373
+ ```javascript
374
+ function detectFileConflicts(subPlans) {
375
+ const fileModifications = {}
376
+ const conflicts = []
377
+
378
+ subPlans.forEach(sp => {
379
+ sp.plan.tasks.forEach(task => {
380
+ task.modification_points?.forEach(mp => {
381
+ if (!fileModifications[mp.file]) {
382
+ fileModifications[mp.file] = []
383
+ }
384
+ fileModifications[mp.file].push({
385
+ focus_area: sp.focus_area,
386
+ task_id: task.id,
387
+ target: mp.target,
388
+ change: mp.change
389
+ })
390
+ })
391
+ })
392
+ })
393
+
394
+ Object.entries(fileModifications).forEach(([file, mods]) => {
395
+ if (mods.length > 1) {
396
+ const agents = [...new Set(mods.map(m => m.focus_area))]
397
+ if (agents.length > 1) {
398
+ conflicts.push({
399
+ type: "file_conflict",
400
+ severity: "high",
401
+ file: file,
402
+ agents_involved: agents,
403
+ modifications: mods,
404
+ description: `Multiple agents modifying ${file}`,
405
+ suggested_resolution: "Sequence modifications or consolidate"
406
+ })
407
+ }
408
+ }
409
+ })
410
+
411
+ return conflicts
412
+ }
413
+
414
+ function detectEffortConflicts(subPlans) {
415
+ // Compare effort estimates across similar tasks
416
+ // Return conflicts where estimates differ by >50%
417
+ return []
418
+ }
419
+
420
+ function detectApproachConflicts(subPlans) {
421
+ // Analyze approaches for contradictions
422
+ // Return conflicts where approaches are incompatible
423
+ return []
424
+ }
425
+
426
+ function detectDependencyConflicts(subPlans) {
427
+ // Check for circular dependencies
428
+ // Check for missing dependencies
429
+ return []
430
+ }
431
+ ```
432
+
433
+ ### Phase 4: Merge & Synthesis
434
+
435
+ Use cli-lite-planning-agent to merge all sub-plans:
436
+
437
+ ```javascript
438
+ TodoWrite({ todos: [
439
+ { content: "Phase 1: Requirement Analysis", status: "completed", activeForm: "Analyzing requirements" },
440
+ { content: "Phase 2: Parallel Agent Execution", status: "completed", activeForm: "Running agents" },
441
+ { content: "Phase 3: Conflict Detection", status: "completed", activeForm: "Detecting conflicts" },
442
+ { content: "Phase 4: Merge & Synthesis", status: "in_progress", activeForm: "Merging plans" }
443
+ ]})
444
+
445
+ // Collect all planning context documents for context
446
+ const contextDocs = subRequirements.map(sub => {
447
+ const path = `${sessionFolder}/agents/${sub.focus_area}/planning-context.md`
448
+ return {
449
+ focus_area: sub.focus_area,
450
+ content: Read(path)
451
+ }
452
+ })
453
+
454
+ // Invoke planning agent to merge
455
+ Task({
456
+ subagent_type: "cli-lite-planning-agent",
457
+ run_in_background: false,
458
+ description: "Merge sub-plans into unified plan",
459
+ prompt: `
460
+ ## Mission: Merge Multiple Sub-Plans
461
+
462
+ Merge ${subPlans.length} sub-plans into a single unified plan.
463
+
464
+ ## Schema Reference
465
+
466
+ Execute: cat ~/.claude/workflows/cli-templates/schemas/plan-json-schema.json
467
+
468
+ The merged plan follows the SAME schema as lite-plan, with ONE additional field:
469
+ - \`merge_metadata\`: Object containing merge-specific information
470
+
471
+ ## Project Context
472
+
473
+ 1. Read: .workflow/project-tech.json
474
+ 2. Read: .workflow/project-guidelines.json
475
+
476
+ ## Original Requirement
477
+
478
+ ${taskDescription}
479
+
480
+ ## Sub-Plans to Merge
481
+
482
+ ${subPlans.map(sp => `
483
+ ### Sub-Plan: ${sp.focus_area}
484
+ \`\`\`json
485
+ ${JSON.stringify(sp.plan, null, 2)}
486
+ \`\`\`
487
+ `).join('\n')}
488
+
489
+ ## Planning Context Documents
490
+
491
+ ${contextDocs.map(cd => `
492
+ ### Context: ${cd.focus_area}
493
+ ${cd.content}
494
+ `).join('\n')}
495
+
496
+ ## Detected Conflicts
497
+
498
+ \`\`\`json
499
+ ${JSON.stringify(conflicts, null, 2)}
500
+ \`\`\`
501
+
502
+ ## Merge Rules
503
+
504
+ **Rule**: ${mergeRule}
505
+ ${mergeRule === 'consensus' ? `
506
+ - Equal weight to all sub-plans
507
+ - Conflicts resolved by finding middle ground
508
+ - Combine overlapping tasks
509
+ ` : `
510
+ - Priority based on sub-requirement index
511
+ - Earlier agents' decisions take precedence
512
+ - Later agents adapt to earlier decisions
513
+ `}
514
+
515
+ ## Requirements
516
+
517
+ 1. **Task Consolidation**:
518
+ - Combine tasks that modify same files
519
+ - Preserve unique tasks from each sub-plan
520
+ - Ensure no task duplication
521
+ - Maintain clear task boundaries
522
+
523
+ 2. **Dependency Resolution**:
524
+ - Cross-reference dependencies between sub-plans
525
+ - Create global task ordering
526
+ - Handle inter-sub-plan dependencies
527
+
528
+ 3. **Conflict Resolution**:
529
+ - Apply ${mergeRule} rule to resolve conflicts
530
+ - Document resolution rationale
531
+ - Ensure no contradictions in final plan
532
+
533
+ 4. **Metadata Preservation**:
534
+ - Track which sub-plan each task originated from (source_agent field)
535
+ - Include merge_metadata with:
536
+ - merged_from: list of sub-plan focus areas
537
+ - conflicts_resolved: count
538
+ - merge_rule: ${mergeRule}
539
+
540
+ ## Output
541
+
542
+ Write to ${sessionFolder}/plan.json following plan-json-schema.json.
543
+
544
+ Add ONE extension field for merge tracking:
545
+
546
+ \`\`\`json
547
+ {
548
+ // ... all standard plan-json-schema fields ...
549
+
550
+ "merge_metadata": {
551
+ "source_session": "${sessionId}",
552
+ "merged_from": ["focus-area-1", "focus-area-2"],
553
+ "sub_plan_count": N,
554
+ "conflicts_detected": N,
555
+ "conflicts_resolved": N,
556
+ "merge_rule": "${mergeRule}",
557
+ "merged_at": "ISO-timestamp"
558
+ }
559
+ }
560
+ \`\`\`
561
+
562
+ Each task should include \`source_agent\` field indicating which sub-plan it originated from.
563
+
564
+ ## Success Criteria
565
+
566
+ - [ ] All sub-plan tasks included (or explicitly merged)
567
+ - [ ] Conflicts resolved per ${mergeRule} rule
568
+ - [ ] Dependencies form valid DAG (no cycles)
569
+ - [ ] merge_metadata present
570
+ - [ ] Schema compliance verified
571
+ - [ ] plan.json written to ${sessionFolder}/plan.json
572
+ `
573
+ })
574
+
575
+ // Generate human-readable plan.md
576
+ const plan = JSON.parse(Read(`${sessionFolder}/plan.json`))
577
+ const planMd = generatePlanMarkdown(plan, subRequirements, conflicts)
578
+ Write(`${sessionFolder}/plan.md`, planMd)
579
+ ```
580
+
581
+ **Markdown Generation**:
582
+
583
+ ```javascript
584
+ function generatePlanMarkdown(plan, subRequirements, conflicts) {
585
+ return `# Collaborative Planning Session
586
+
587
+ **Session ID**: ${plan._metadata?.session_id || sessionId}
588
+ **Original Requirement**: ${taskDescription}
589
+ **Created**: ${getUtc8ISOString()}
590
+
591
+ ---
592
+
593
+ ## Sub-Requirements Analyzed
594
+
595
+ ${subRequirements.map((sub, i) => `
596
+ ### ${i+1}. ${sub.focus_area}
597
+ ${sub.description}
598
+ - **Key Concerns**: ${sub.key_concerns.join(', ')}
599
+ - **Estimated Effort**: ${sub.estimated_effort}
600
+ `).join('\n')}
601
+
602
+ ---
603
+
604
+ ## Conflict Resolution
605
+
606
+ ${conflicts.conflicts.length > 0 ? `
607
+ **Conflicts Detected**: ${conflicts.conflicts.length}
608
+ **Merge Rule**: ${mergeRule}
609
+
610
+ ${conflicts.conflicts.map((c, i) => `
611
+ ${i+1}. **${c.type}** - ${c.description}
612
+ - Resolution: ${c.suggested_resolution}
613
+ `).join('\n')}
614
+ ` : '✅ No conflicts detected'}
615
+
616
+ ---
617
+
618
+ ## Merged Plan
619
+
620
+ ### Summary
621
+ ${plan.summary}
622
+
623
+ ### Approach
624
+ ${plan.approach}
625
+
626
+ ---
627
+
628
+ ## Tasks
629
+
630
+ ${plan.tasks.map((task, i) => `
631
+ ### ${task.id}: ${task.title}
632
+
633
+ **Source**: ${task.source_agent || 'merged'}
634
+ **Scope**: ${task.scope}
635
+ **Action**: ${task.action}
636
+ **Complexity**: ${task.effort?.complexity || 'medium'}
637
+
638
+ ${task.description}
639
+
640
+ **Modification Points**:
641
+ ${task.modification_points?.map(mp => `- \`${mp.file}\` → ${mp.target}: ${mp.change}`).join('\n') || 'N/A'}
642
+
643
+ **Implementation**:
644
+ ${task.implementation?.map((step, idx) => `${idx+1}. ${step}`).join('\n') || 'N/A'}
645
+
646
+ **Acceptance Criteria**:
647
+ ${task.acceptance?.map(ac => `- ${ac}`).join('\n') || 'N/A'}
648
+
649
+ **Dependencies**: ${task.depends_on?.join(', ') || 'None'}
650
+
651
+ ---
652
+ `).join('\n')}
653
+
654
+ ## Execution
655
+
656
+ \`\`\`bash
657
+ # Execute this plan
658
+ /workflow:unified-execute-with-file -p ${sessionFolder}/plan.json
659
+
660
+ # Or with auto-confirmation
661
+ /workflow:unified-execute-with-file -y -p ${sessionFolder}/plan.json
662
+ \`\`\`
663
+
664
+ ---
665
+
666
+ ## Agent Process Files
667
+
668
+ ${subRequirements.map(sub => `
669
+ ### ${sub.focus_area}
670
+ - Context: \`${sessionFolder}/agents/${sub.focus_area}/planning-context.md\`
671
+ - Sub-Plan: \`${sessionFolder}/agents/${sub.focus_area}/sub-plan.json\`
672
+ `).join('\n')}
673
+
674
+ ---
675
+
676
+ **Generated by**: /workflow:collaborative-plan-with-file
677
+ **Merge Rule**: ${mergeRule}
678
+ `
679
+ }
680
+ ```
681
+
682
+ ### Completion
683
+
684
+ ```javascript
685
+ TodoWrite({ todos: [
686
+ { content: "Phase 1: Requirement Analysis", status: "completed", activeForm: "Analyzing requirements" },
687
+ { content: "Phase 2: Parallel Agent Execution", status: "completed", activeForm: "Running agents" },
688
+ { content: "Phase 3: Conflict Detection", status: "completed", activeForm: "Detecting conflicts" },
689
+ { content: "Phase 4: Merge & Synthesis", status: "completed", activeForm: "Merging plans" }
690
+ ]})
691
+
692
+ console.log(`
693
+ ✅ Collaborative Planning Complete
694
+
695
+ **Session**: ${sessionId}
696
+ **Sub-Agents**: ${subRequirements.length}
697
+ **Conflicts Resolved**: ${conflicts.conflicts.length}
698
+
699
+ ## Output Files
700
+
701
+ 📁 ${sessionFolder}/
702
+ ├── requirement-analysis.json # Requirement breakdown
703
+ ├── agents/ # Per-agent process files
704
+ ${subRequirements.map(sub => `│ ├── ${sub.focus_area}/
705
+ │ │ ├── planning-context.md
706
+ │ │ └── sub-plan.json`).join('\n')}
707
+ ├── conflicts.json # Detected conflicts
708
+ ├── plan.json # Unified plan (execution-ready)
709
+ └── plan.md # Human-readable plan
710
+
711
+ ## Next Steps
712
+
713
+ Execute the plan:
714
+ \`\`\`bash
715
+ /workflow:unified-execute-with-file -p ${sessionFolder}/plan.json
716
+ \`\`\`
717
+
718
+ Review a specific agent's work:
719
+ \`\`\`bash
720
+ cat ${sessionFolder}/agents/{focus-area}/planning-context.md
721
+ \`\`\`
722
+ `)
723
+ ```
724
+
725
+ ## Configuration
726
+
727
+ | Flag | Default | Description |
728
+ |------|---------|-------------|
729
+ | `--max-agents` | 5 | Maximum sub-agents to spawn |
730
+ | `--depth` | normal | Exploration depth: normal or deep |
731
+ | `--merge-rule` | consensus | Conflict resolution: consensus or priority |
732
+ | `-y, --yes` | false | Auto-confirm all decisions |
733
+
734
+ ## Error Handling
735
+
736
+ | Error | Resolution |
737
+ |-------|------------|
738
+ | Requirement too simple | Use single-agent lite-plan instead |
739
+ | Agent fails | Retry once, then continue with partial results |
740
+ | Merge conflicts unresolvable | Ask user for manual resolution |
741
+ | CLI timeout | Use fallback CLI tool |
742
+ | File write fails | Retry with alternative path |
743
+
744
+ ## vs Other Planning Commands
745
+
746
+ | Command | Use Case |
747
+ |---------|----------|
748
+ | **collaborative-plan-with-file** | Complex multi-aspect requirements needing parallel exploration |
749
+ | lite-plan | Simple single-focus tasks |
750
+ | multi-cli-plan | Iterative cross-verification with convergence |
751
+
752
+ ## Best Practices
753
+
754
+ 1. **Be Specific**: Detailed requirements lead to better splits
755
+ 2. **Review Process Files**: Check planning-context.md for insights
756
+ 3. **Trust the Merge**: Conflict resolution follows defined rules
757
+ 4. **Iterate if Needed**: Re-run with different --merge-rule if results unsatisfactory
758
+
759
+ ---
760
+
761
+ **Now execute collaborative-plan-with-file for**: $ARGUMENTS