sparc-refine

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

SPARC Refinement + Completion

SPARC优化与完成阶段

Run Phases 4 and 5 of the SPARC methodology: iteratively improve through code review and testing, then finalize with validation, documentation, and deployment readiness.
执行SPARC方法论的第4和第5阶段:通过代码审查与测试迭代优化,随后通过验证、文档编制和部署就绪检查完成收尾工作。

When to use

使用时机

After the Architecture phase is complete and its gate has been passed. This skill covers the final two phases that bring a feature from implemented to production-ready.
在架构阶段完成并通过阶段门之后使用。本技能涵盖将功能从已实现状态推进至生产就绪状态的最后两个阶段。

Steps

步骤

Phase 4 — Refinement

第4阶段——优化

  1. Retrieve all prior artifacts — call
    mcp__claude-flow__memory_search
    with namespace
    sparc-phases
    and query for the feature slug. Load spec (acceptance criteria), pseudocode, and architecture.
  2. Retrieve phase state — call
    mcp__claude-flow__memory_search
    with namespace
    sparc-state
    to confirm we are in Phase 4.
  3. Code review — review the implementation against: a. Specification compliance: does every acceptance criterion have a corresponding code path? b. Architecture adherence: do modules follow the defined boundaries and dependency rules? c. Pseudocode fidelity: does the implementation match the designed algorithms? d. Code quality: naming conventions, single responsibility, error handling, no dead code e. Document findings as review comments
  4. Test coverage analysis: a. Run existing tests and measure coverage b. Identify uncovered acceptance criteria c. Write missing tests:
    • Unit tests for each public function
    • Integration tests for cross-module interactions
    • Edge case tests for each identified edge case from the spec d. Target coverage >= 80% on new code
  5. Performance validation — if the spec includes performance constraints: a. Profile critical paths identified in the pseudocode b. Compare measured performance against constraint thresholds c. Optimize if thresholds are not met
  6. Iterate — repeat steps 3-5 until:
    • All acceptance criteria have passing tests
    • Code review has no critical or high-severity issues
    • Coverage meets the threshold
    • Performance constraints are satisfied
  7. Store refinement artifact — call
    mcp__claude-flow__memory_store
    with namespace
    sparc-phases
    , key
    refine-{feature-slug}
    , value:
    { status: "complete", reviewFindings: [...], coveragePercent: N, performanceResults: {...}, iterations: N }
  8. Record trajectory step — call
    mcp__claude-flow__hooks_intelligence_trajectory-step
    with refinement summary
  1. 获取所有前期工件 —— 调用
    mcp__claude-flow__memory_search
    ,命名空间为
    sparc-phases
    ,查询功能slug。加载规范(验收标准)、伪代码和架构文档。
  2. 获取阶段状态 —— 调用
    mcp__claude-flow__memory_search
    ,命名空间为
    sparc-state
    ,确认当前处于第4阶段。
  3. 代码审查 —— 对照以下维度审查实现代码: a. 规范符合性:每项验收标准是否都有对应的代码路径? b. 架构一致性:模块是否遵循定义的边界和依赖规则? c. 伪代码忠实度:实现是否与设计的算法一致? d. 代码质量:命名规范、单一职责原则、错误处理、无死代码 e. 将审查结果记录为评审意见
  4. 测试覆盖率分析: a. 运行现有测试并测量覆盖率 b. 识别未覆盖的验收标准 c. 编写缺失的测试:
    • 每个公共函数的单元测试
    • 跨模块交互的集成测试
    • 规范中每个已识别边缘场景的边缘用例测试 d. 目标:新代码覆盖率≥80%
  5. 性能验证 —— 如果规范包含性能约束: a. 对伪代码中识别的关键路径进行性能剖析 b. 将实测性能与约束阈值对比 c. 若未达到阈值则进行优化
  6. 迭代 —— 重复步骤3-5,直到:
    • 所有验收标准对应的测试均通过
    • 代码审查无严重或高优先级问题
    • 覆盖率达到阈值要求
    • 满足性能约束
  7. 存储优化阶段工件 —— 调用
    mcp__claude-flow__memory_store
    ,命名空间为
    sparc-phases
    ,键为
    refine-{feature-slug}
    ,值为:
    { status: "complete", reviewFindings: [...], coveragePercent: N, performanceResults: {...}, iterations: N }
  8. 记录轨迹步骤 —— 调用
    mcp__claude-flow__hooks_intelligence_trajectory-step
    ,传入优化阶段摘要

Phase 5 — Completion

第5阶段——完成

  1. Full regression — run the complete test suite to verify no regressions from refinement changes
  2. Traceability matrix — build a matrix mapping every acceptance criterion to:
    • The test(s) that verify it
    • The code file(s) that implement it
    • The current pass/fail status
  3. Documentation: a. Generate API documentation from code comments and type definitions b. Write usage examples for key public interfaces c. Update any existing documentation affected by the changes
  4. Deployment readiness checklist:
    • All tests passing
    • Documentation complete
    • Database migrations prepared (if applicable)
    • Configuration changes documented
    • Feature flags configured (if applicable)
    • Rollback plan defined
    • Security review complete (no secrets, inputs validated)
  5. Store completion artifact — call
    mcp__claude-flow__memory_store
    with namespace
    sparc-phases
    , key
    complete-{feature-slug}
    , value:
    { status: "complete", traceabilityMatrix: [...], documentationFiles: [...], deploymentChecklist: {...}, regressionResult: "pass" }
  6. End trajectory — call
    mcp__claude-flow__hooks_intelligence_trajectory-end
    with the full SPARC cycle summary
  7. Train neural patterns — call
    mcp__claude-flow__neural_train
    with the successful SPARC cycle data to improve future predictions
  8. Store learned pattern — call
    mcp__claude-flow__memory_store
    with namespace
    patterns
    , key
    sparc-{feature-slug}
    , value summarizing what worked, phase durations, and common blockers encountered
  9. Present completion report — display the traceability matrix, deployment checklist, and final status. Suggest running
    /sparc advance
    to pass the final gate, or
    /sparc report
    for the full methodology report.
  1. 全量回归测试 —— 运行完整测试套件,验证优化阶段的修改未引入回归问题
  2. 可追溯矩阵 —— 构建矩阵,将每项验收标准映射至:
    • 验证该标准的测试用例
    • 实现该标准的代码文件
    • 当前的通过/失败状态
  3. 文档编制: a. 从代码注释和类型定义生成API文档 b. 编写关键公共接口的使用示例 c. 更新受修改影响的现有文档
  4. 部署就绪检查清单
    • 所有测试通过
    • 文档编制完成
    • 数据库迁移已准备(如适用)
    • 配置变更已记录
    • 功能标志已配置(如适用)
    • 回滚计划已定义
    • 安全审查完成(无密钥泄露、输入已验证)
  5. 存储完成阶段工件 —— 调用
    mcp__claude-flow__memory_store
    ,命名空间为
    sparc-phases
    ,键为
    complete-{feature-slug}
    ,值为:
    { status: "complete", traceabilityMatrix: [...], documentationFiles: [...], deploymentChecklist: {...}, regressionResult: "pass" }
  6. 结束轨迹 —— 调用
    mcp__claude-flow__hooks_intelligence_trajectory-end
    ,传入完整SPARC周期摘要
  7. 训练神经模式 —— 调用
    mcp__claude-flow__neural_train
    ,传入成功的SPARC周期数据以提升未来预测能力
  8. 存储学习到的模式 —— 调用
    mcp__claude-flow__memory_store
    ,命名空间为
    patterns
    ,键为
    sparc-{feature-slug}
    ,值总结有效实践、阶段时长和遇到的常见障碍
  9. 展示完成报告 —— 显示可追溯矩阵、部署检查清单和最终状态。建议运行
    /sparc advance
    以通过最终阶段门,或运行
    /sparc report
    获取完整方法论报告。

Output format

输出格式

undefined
undefined

Refinement: {Feature Name}

优化阶段: {功能名称}

Code Review Summary

代码审查摘要

  • Critical issues: {N} (must be 0 to pass gate)
  • High issues: {N}
  • Medium issues: {N}
  • Resolved: {N}/{total}
  • 严重问题: {N} (必须为0才能通过阶段门)
  • 高优先级问题: {N}
  • 中优先级问题: {N}
  • 已解决: {N}/{总数}

Test Coverage

测试覆盖率

  • Overall: {N}%
  • New code: {N}%
  • Acceptance criteria covered: {N}/{total}
  • 整体覆盖率: {N}%
  • 新代码覆盖率: {N}%
  • 已覆盖验收标准: {N}/{总数}

Performance

性能

ConstraintTargetMeasuredStatus
Response time<200ms145msPass

约束条件目标值实测值状态
响应时间<200ms145ms通过

Completion: {Feature Name}

完成阶段: {功能名称}

Traceability Matrix

可追溯矩阵

ACTestCodeStatus
AC-1test_xxxservice.ts:42Pass
AC-2test_yyycontroller.ts:18Pass
AC-3test_zzzrepository.ts:31Pass
验收标准测试用例代码状态
AC-1test_xxxservice.ts:42通过
AC-2test_yyycontroller.ts:18通过
AC-3test_zzzrepository.ts:31通过

Deployment Checklist

部署检查清单

  • All tests passing
  • Documentation complete
  • Migrations prepared
  • Config documented
  • Rollback plan defined
  • Security reviewed

SPARC workflow complete. Run
/sparc report
for the full methodology report.
undefined
  • 所有测试通过
  • 文档编制完成
  • 迁移已准备
  • 配置已记录
  • 回滚计划已定义
  • 安全审查完成

SPARC工作流完成。运行
/sparc report
获取完整方法论报告。
undefined