mcpField
W
workflow-multi-cli-plan

workflow-multi-cli-plan

github.com/catlog22Agent 工作流2.1k64 次安装19 周前更新
代码仓库

关于 workflow-multi-cli-plan

workflow-multi-cli-plan 是面向开发任务的协作式规划技能,通过多 CLI 讨论、交叉验证和方案综合来生成实施计划。它收集项目上下文、让用户选择方案,并可将计划交给 workflow-lite-execute 执行。

主要功能

  1. 01ACE 语义搜索收集上下文
  2. 02Gemini、Codex 和 Claude 多 CLI 讨论
  3. 03交叉验证并综合方案
  4. 04生成分层计划文件
  5. 05批准后移交执行

适用场景

  1. 01为开发任务收集相关代码上下文
  2. 02比较并核验多 CLI 提出的方案
  3. 03将选定方案转成实施计划

MCP 相关

流程使用 mcp__ace-tool__search_context 查询项目上下文;其他 MCP 相关能力未说明。

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/catlog22/claude-code-workflow --skill workflow-multi-cli-plan

安装后在 Claude Code 中输入/workflow-multi-cli-plan确认已加载。

详细介绍

多 CLI 协作规划

自动模式

当 workflowPreferences.autoYes 为 true 时:自动批准计划,采用推荐的解决方案和执行方式(Agent,跳过审查)。

上下文来源:ACE 语义搜索 + 多 CLI 分析 输出目录:.workflow/.multi-cli-plan/{session-id}/ 默认最大轮数:3(可能提前达成收敛) CLI 工具:@cli-discuss-agent(分析)、@cli-lite-planning-agent(生成计划) 执行:计划获批后自动移交给 workflow-lite-execute

编排器边界(重要)
  • 多 CLI 协作规划的唯一命令
  • 管理:会话状态、用户决策、Agent 委派、阶段转换
  • 委派:由 @cli-discuss-agent 执行 CLI,由 @cli-lite-planning-agent 生成计划
执行流程
Phase 1: Context Gathering
   └─ ACE semantic search, extract keywords, build context package

Phase 2: Multi-CLI Discussion (Iterative, via @cli-discuss-agent)
   ├─ Round N: Agent executes Gemini + Codex + Claude
   ├─ Cross-verify findings, synthesize solutions
   ├─ Write synthesis.json to rounds/{N}/
   └─ Loop until convergence or max rounds

Phase 3: Present Options
   └─ Display solutions with trade-offs from agent output

Phase 4: User Decision
   ├─ Select solution approach
   ├─ Select execution method (Agent/Codex/Auto)
   ├─ Select code review tool (Skip/Gemini/Codex/Agent)
   └─ Route:
      ├─ Approve → Phase 5
      ├─ Need More Analysis → Return to Phase 2
      └─ Cancel → Save session

Phase 5: Plan Generation & Execution Handoff
   ├─ Generate plan.json + .task/*.json (via @cli-lite-planning-agent, two-layer output)
   ├─ Build executionContext with user selections and taskFiles
   └─ Execute via workflow-lite-execute
Agent 角色
Agent职责
Orchestrator会话管理、ACE 上下文、用户决策、阶段转换、executionContext 组装
@cli-discuss-agent多 CLI 执行(Gemini/Codex/Claude)、交叉验证、方案综合、输出 synthesis.json
@cli-lite-planning-agent任务分解、两层输出:plan.json(包含 task_ids[] 的概览)+ .task/*.json(任务文件)

核心职责

阶段 1:收集上下文

会话初始化:

const sessionId = `MCP-${taskSlug}-${date}`
const sessionFolder = `.workflow/.multi-cli-plan/${sessionId}`
Bash(`mkdir -p ${sessionFolder}/rounds`)

ACE 上下文查询:

const aceQueries = [
  `Project architecture related to ${keywords}`,
  `Existing implementations of ${keywords[0]}`,
  `Code patterns for ${keywords} features`,
  `Integration points for ${keywords[0]}`
]
// Execute via mcp__ace-tool__search_context

上下文包(传递给 Agent):

  • relevant_files[] - ACE 识别的文件
  • detected_patterns[] - 发现的代码模式
  • architecture_insights - 对结构的理解
阶段 2:Agent 委派

核心原则:Orchestrator 仅进行委派并读取输出——不得直接执行 CLI。CLI 调用必须使用 Bash 和 run_in_background: true,等待钩子回调,不得使用 TaskOutput 轮询。

Agent 调用:

Agent({
  subagent_type: "cli-discuss-agent",
  run_in_background: false,
  description: `Discussion round ${currentRound}`,
  prompt: `
## Input Context
- task_description: ${taskDescription}
- round_number: ${currentRound}
- session: { id: "${sessionId}", folder: "${sessionFolder}" }
- ace_context: ${JSON.stringify(contextPackage)}
- previous_rounds: ${JSON.stringify(analysisResults)}
- user_feedback: ${userFeedback || 'None'}
- cli_config: { tools: ["gemini", "codex"], mode: "parallel", fallback_chain: ["gemini", "codex", "claude"] }

## Execution Process
1. Parse input context (handle JSON strings)
2. Check if ACE supplementary search needed
3. Build CLI prompts with context
4. Execute CLIs (parallel or serial per cli_config.mode)
5. Parse CLI outputs, handle failures with fallback
6. Perform cross-verification between CLI results
7. Synthesize solutions, calculate scores
8. Calculate convergence, generate clarification questions
9. Write synthesis.json

## Output
Write: ${sessionFolder}/rounds/${currentRound}/synthesis.json

## Completion Checklist
- [ ] All configured CLI tools executed (or fallback triggered)
- [ ] Cross-verification completed with agreements/disagreements
- [ ] 2-3 solutions generated with file:line references
- [ ] Convergence score calculated (0.0-1.0)
- [ ] synthesis.json written with all Primary Fields
`
})

读取 Agent 输出:

const synthesis = JSON.parse(Read(`${sessionFolder}/rounds/${round}/synthesis.json`))
// Access top-level fields: solutions, convergence, cross_verification, clarification_questions

收敛决策:

if (synthesis.convergence.recommendation === 'converged') {
  // Proceed to Phase 3
} else if (synthesis.convergence.recommendation === 'user_input_needed') {
  // Collect user feedback, return to Phase 2
} else {
  // Continue to next round if new_insights && round < maxRounds
}
阶段 3:展示选项

展示 synthesis.solutions[] 中的解决方案,并显示以下信息:名称、来源 CLI、工作量/风险、优缺点、受影响的文件(file:line)。同时显示交叉验证中一致和不一致的数量。

阶段 4:用户决策
AskUserQuestion({
  questions: [
    {
      question: "Which solution approach?",
      header: "Solution",
      multiSelect: false,
      options: solutions.map((s, i) => ({
        label: `Option ${i+1}: ${s.name}`,
        description: `${s.effort} effort, ${s.risk} risk`
      })).concat([
        { label: "Need More Analysis", description: "Return to Phase 2" }
      ])
    },
    {
      question: "Execution method:",
      header: "Execution",
      multiSelect: false,
      options: [
        { label: "Agent", description: "@code-developer agent" },
        { label: "Codex", description: "codex CLI tool" },
        { label: "Auto", description: "Auto-select based on complexity" }
      ]
    },
    {
      question: "Code review after execution?",
      header: "Review",
      multiSelect: false,
      options: [
        { label: "Skip", description: "No review" },
        { label: "Gemini Review", description: "Gemini CLI tool" },
        { label: "Codex Review", description: "Codex CLI: prompt-based code quality review (--mode analysis)" },
        { label: "Agent Review", description: "Current agent review" }
      ]
    }
  ]
})

后续流程:

  • 批准 + 执行方式 → 阶段 5
  • 需要更多分析 → 提供反馈并返回阶段 2
  • 取消 → 保存会话以便恢复

TodoWrite 更新(阶段 4 决策):

const executionLabel = userSelection.execution_method  // "Agent" / "Codex" / "Auto"

TodoWrite({ todos: [
  { content: "Phase 1: Context Gathering", status: "completed", activeForm: "Gathering context" },
  { content: "Phase 2: Multi-CLI Discussion", status: "completed", activeForm: "Running discussion" },
  { content: "Phase 3: Present Options", status: "completed", activeForm: "Presenting options" },
  { content: `Phase 4: User Decision [${executionLabel}]`, status: "completed", activeForm: "Decision recorded" },
  { content: `Phase 5: Plan Generation [${executionLabel}]`, status: "in_progress", activeForm: `Generating plan [${executionLabel}]` }
]})
阶段 5:生成计划并移交执行

步骤 1:构建上下文包(Orchestrator 负责):

const contextPackage = {
  solution: {
    name: selectedSolution.name,
    source_cli: selectedSolution.source_cli,
    feasibility: selectedSolution.feasibility,
    effort: selectedSolution.effort,
    risk: selectedSolution.risk,
    summary: selectedSolution.summary
  },
  implementation_plan: selectedSolution.implementation_plan,
  dependencies: selectedSolution.dependencies || { internal: [], external: [] },
  technical_concerns: selectedSolution.technical_concerns || [],
  consensus: {
    agreements: synthesis.cross_verification.agreements,
    resolved_conflicts: synthesis.cross_verification.resolution
  },
  constraints: userConstraints || [],
  task_description: taskDescription,
  session_id: sessionId
}
Write(`${sessionFolder}/context-package.json`, JSON.stringify(contextPackage, null, 2))

步骤 2:调用规划 Agent:

Agent({
  subagent_type: "cli-lite-planning-agent",
  run_in_background: false,
  description: "Generate implementation plan",
  prompt: `
## Schema Reference
Execute: cat ~/.ccw/workflows/cli-templates/schemas/plan-overview-base-schema.json
Execute: cat ~/.ccw/workflows/cli-templates/schemas/task-schema.json

## Output Format: Two-Layer Structure
- plan.json: Overview with task_ids[] referencing .task/ files (NO tasks[] array)
- .task/TASK-*.json: Independent task files following task-schema.json

plan.json required: summary, approach, task_ids, task_count, _metadata (with plan_type)
Task files required: id, title, description, depends_on, convergence (with criteria[])
Task fields: files[].change (not modification_points), convergence.criteria (not acceptance), test (not verification)

## Context-Package (from orchestrator)
${JSON.stringify(contextPackage, null, 2)}

## Execution Process
1. Read plan-overview-base-schema.json + task-schema.json for output structure
2. Read project-tech.json and specs/*.md
3. Parse context-package fields:
   - solution: name, feasibility, summary
   - implementation_plan: tasks[], execution_flow, milestones
   - dependencies: internal[], external[]
   - technical_concerns: risks/blockers
   - consensus: agreements, resolved_conflicts
   - constraints: user requirements
4. Use implementation_plan.tasks[] as task foundation
5. Preserve task dependencies (depends_on) and execution_flow
6. Expand tasks with convergence.criteria (testable completion conditions)
7. Create .task/ directory and write individual TASK-*.json files
8. Generate plan.json with task_ids[] referencing .task/ files

## Output
- ${sessionFolder}/plan.json (overview with task_ids[])
- ${sessionFolder}/.task/TASK-*.json (independent task files)

## Completion Checklist
- [ ] plan.json has task_ids[] and task_count (NO embedded tasks[])
- [ ] .task/*.json files preserve task dependencies from implementation_plan
- [ ] Task execution order follows execution_flow
- [ ] Key_points reflected in task descriptions
- [ ] User constraints applied to implementation
- [ ] convergence.criteria are testable
- [ ] plan.json follows plan-overview-base-schema.json
- [ ] Task files follow task-schema.json
`
})

步骤 3:构建 executionContext:

const plan = JSON.parse(Read(`${sessionFolder}/plan.json`))
const taskFiles = plan.task_ids.map(id => `${sessionFolder}/.task/${id}.json`)

// Build executionContext (same structure as lite-plan)
executionContext = {
  planObject: plan,
  taskFiles: taskFiles,                              // Paths to .task/*.json files (two-layer format)
  explorationsContext: null,                          // Multi-CLI doesn't use exploration files
  explorationAngles: [],
  explorationManifest: null,
  clarificationContext: null,                         // Store user feedback from Phase 2 if exists
  executionMethod: userSelection.execution_method,    // From Phase 4
  codeReviewTool: userSelection.code_review_tool,     // From Phase 4
  originalUserInput: taskDescription,
  executorAssignments: null,
  session: {
    id: sessionId,
    folder: sessionFolder,
    artifacts: {
      explorations: [],                              // No explorations in multi-CLI workflow
      explorations_manifest: null,
      plan: `${sessionFolder}/plan.json`,
      task_dir: plan.task_ids ? `${sessionFolder}/.task/` : null,
      synthesis_rounds: Array.from({length: currentRound}, (_, i) =>
        `${sessionFolder}/rounds/${i+1}/synthesis.json`
      ),
      context_package: `${sessionFolder}/context-package.json`
    }
  }
}

步骤 4:移交执行:

Skill({
  skill: "workflow-lite-execute",
  args: "--in-memory"
})
// executionContext is passed via global variable to workflow-lite-execute (Mode 1: In-Memory Plan)

synthesis.json 架构

{
  "round": 1,
  "solutions": [{
    "name": "Solution Name",
    "source_cli": ["gemini", "codex"],
    "feasibility": 0.85,
    "effort": "low|medium|high",
    "risk": "low|medium|high",
    "summary": "Brief analysis summary",
    "implementation_plan": {
      "approach": "High-level technical approach",
      "tasks": [
        {"id": "T1", "name": "Task", "depends_on": [], "files": [], "key_point": "..."}
      ],
      "execution_flow": "T1 → T2 → T3",
      "milestones": ["Checkpoint 1", "Checkpoint 2"]
    },
    "dependencies": {"internal": [], "external": []},
    "technical_concerns": ["Risk 1", "Blocker 2"]
  }],
  "convergence": {
    "score": 0.85,
    "new_insights": false,
    "recommendation": "converged|continue|user_input_needed"
  },
  "cross_verification": {
    "agreements": [],
    "disagreements": [],
    "resolution": "..."
  },
  "clarification_questions": []
}

TodoWrite 模式

初始化(阶段 1 开始):

TodoWrite({ todos: [
  { content: "Phase 1: Context Gathering", status: "in_progress", activeForm: "Gathering context" },
  { content: "Phase 2: Multi-CLI Discussion", status: "pending", activeForm: "Running discussion" },
  { content: "Phase 3: Present Options", status: "pending", activeForm: "Presenting options" },
  { content: "Phase 4: User Decision", status: "pending", activeForm: "Awaiting decision" },
  { content: "Phase 5: Plan Generation", status: "pending", activeForm: "Generating plan" }
]})

输出文件结构

.workflow/.multi-cli-plan/{MCP-task-slug-YYYY-MM-DD}/
├── session-state.json          # Session tracking (orchestrator)
├── rounds/
│   ├── 1/synthesis.json        # Round 1 analysis (cli-discuss-agent)
│   ├── 2/synthesis.json        # Round 2 analysis (cli-discuss-agent)
│   └── .../
├── context-package.json        # Extracted context for planning (orchestrator)
├── plan.json                   # Plan overview with task_ids[] (NO embedded tasks[])
└── .task/                      # Independent task files
    ├── TASK-001.json            # Task file following task-schema.json
    ├── TASK-002.json
    └── ...

错误处理

错误解决方案
ACE 搜索失败回退到 Glob/Grep 查找文件
Agent 失败重试一次,然后展示部分结果
CLI 超时(在 Agent 中)Agent 使用备用工具:gemini → codex → claude
未能收敛展示最佳选项并标记不确定性
synthesis.json 解析错误请求 Agent 重试
用户取消保存会话以便稍后恢复

配置

标志默认值描述
--max-rounds3最大讨论轮数
--toolsgemini,codex用于分析的 CLI 工具
--modeparallel执行模式:parallel 或 serial
--auto-executefalse获批后自动执行

评论

支持 Markdown