claude-code-workflow 6.3.26 → 6.3.28

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 (129) hide show
  1. package/.claude/CLAUDE.md +7 -1
  2. package/.claude/agents/action-planning-agent.md +1 -0
  3. package/.claude/agents/cli-discuss-agent.md +391 -0
  4. package/.claude/agents/cli-execution-agent.md +2 -0
  5. package/.claude/agents/cli-explore-agent.md +2 -1
  6. package/.claude/agents/cli-lite-planning-agent.md +1 -0
  7. package/.claude/agents/cli-planning-agent.md +1 -0
  8. package/.claude/agents/code-developer.md +1 -0
  9. package/.claude/agents/conceptual-planning-agent.md +2 -0
  10. package/.claude/agents/context-search-agent.md +1 -0
  11. package/.claude/agents/debug-explore-agent.md +2 -0
  12. package/.claude/agents/doc-generator.md +1 -0
  13. package/.claude/agents/issue-plan-agent.md +2 -1
  14. package/.claude/agents/issue-queue-agent.md +2 -1
  15. package/.claude/agents/memory-bridge.md +2 -0
  16. package/.claude/agents/test-context-search-agent.md +2 -0
  17. package/.claude/agents/test-fix-agent.md +1 -0
  18. package/.claude/agents/ui-design-agent.md +2 -0
  19. package/.claude/agents/universal-executor.md +1 -0
  20. package/.claude/commands/issue/execute.md +141 -163
  21. package/.claude/commands/workflow/lite-lite-lite.md +798 -0
  22. package/.claude/commands/workflow/multi-cli-plan.md +510 -0
  23. package/.claude/skills/ccw/SKILL.md +262 -372
  24. package/.claude/skills/ccw/command.json +547 -0
  25. package/.claude/skills/ccw-help/SKILL.md +46 -107
  26. package/.claude/skills/ccw-help/command.json +511 -0
  27. package/.claude/skills/skill-tuning/SKILL.md +303 -0
  28. package/.claude/skills/skill-tuning/phases/actions/action-abort.md +164 -0
  29. package/.claude/skills/skill-tuning/phases/actions/action-analyze-requirements.md +406 -0
  30. package/.claude/skills/skill-tuning/phases/actions/action-apply-fix.md +206 -0
  31. package/.claude/skills/skill-tuning/phases/actions/action-complete.md +195 -0
  32. package/.claude/skills/skill-tuning/phases/actions/action-diagnose-agent.md +317 -0
  33. package/.claude/skills/skill-tuning/phases/actions/action-diagnose-context.md +243 -0
  34. package/.claude/skills/skill-tuning/phases/actions/action-diagnose-dataflow.md +318 -0
  35. package/.claude/skills/skill-tuning/phases/actions/action-diagnose-docs.md +299 -0
  36. package/.claude/skills/skill-tuning/phases/actions/action-diagnose-memory.md +269 -0
  37. package/.claude/skills/skill-tuning/phases/actions/action-diagnose-token-consumption.md +200 -0
  38. package/.claude/skills/skill-tuning/phases/actions/action-gemini-analysis.md +322 -0
  39. package/.claude/skills/skill-tuning/phases/actions/action-generate-report.md +228 -0
  40. package/.claude/skills/skill-tuning/phases/actions/action-init.md +149 -0
  41. package/.claude/skills/skill-tuning/phases/actions/action-propose-fixes.md +317 -0
  42. package/.claude/skills/skill-tuning/phases/actions/action-verify.md +222 -0
  43. package/.claude/skills/skill-tuning/phases/orchestrator.md +377 -0
  44. package/.claude/skills/skill-tuning/phases/state-schema.md +378 -0
  45. package/.claude/skills/skill-tuning/specs/category-mappings.json +284 -0
  46. package/.claude/skills/skill-tuning/specs/dimension-mapping.md +212 -0
  47. package/.claude/skills/skill-tuning/specs/problem-taxonomy.md +318 -0
  48. package/.claude/skills/skill-tuning/specs/quality-gates.md +263 -0
  49. package/.claude/skills/skill-tuning/specs/skill-authoring-principles.md +189 -0
  50. package/.claude/skills/skill-tuning/specs/tuning-strategies.md +1537 -0
  51. package/.claude/skills/skill-tuning/templates/diagnosis-report.md +153 -0
  52. package/.claude/skills/skill-tuning/templates/fix-proposal.md +204 -0
  53. package/.claude/workflows/cli-templates/schemas/multi-cli-discussion-schema.json +421 -0
  54. package/.claude/workflows/cli-tools-usage.md +0 -41
  55. package/ccw/dist/core/auth/csrf-middleware.d.ts.map +1 -1
  56. package/ccw/dist/core/auth/csrf-middleware.js +3 -1
  57. package/ccw/dist/core/auth/csrf-middleware.js.map +1 -1
  58. package/ccw/dist/core/data-aggregator.d.ts +2 -0
  59. package/ccw/dist/core/data-aggregator.d.ts.map +1 -1
  60. package/ccw/dist/core/data-aggregator.js +5 -2
  61. package/ccw/dist/core/data-aggregator.js.map +1 -1
  62. package/ccw/dist/core/lite-scanner.d.ts +2 -1
  63. package/ccw/dist/core/lite-scanner.d.ts.map +1 -1
  64. package/ccw/dist/core/lite-scanner.js +295 -6
  65. package/ccw/dist/core/lite-scanner.js.map +1 -1
  66. package/ccw/dist/core/routes/codexlens/config-handlers.d.ts.map +1 -1
  67. package/ccw/dist/core/routes/codexlens/config-handlers.js +5 -5
  68. package/ccw/dist/core/routes/codexlens/config-handlers.js.map +1 -1
  69. package/ccw/dist/core/routes/session-routes.d.ts.map +1 -1
  70. package/ccw/dist/core/routes/session-routes.js +166 -48
  71. package/ccw/dist/core/routes/session-routes.js.map +1 -1
  72. package/ccw/dist/core/routes/system-routes.d.ts.map +1 -1
  73. package/ccw/dist/core/routes/system-routes.js +87 -0
  74. package/ccw/dist/core/routes/system-routes.js.map +1 -1
  75. package/ccw/dist/core/server.js +2 -2
  76. package/ccw/dist/core/server.js.map +1 -1
  77. package/ccw/scripts/IMPLEMENTATION-SUMMARY.md +226 -0
  78. package/ccw/scripts/QUICK-REFERENCE.md +135 -0
  79. package/ccw/scripts/README-memory-embedder.md +157 -0
  80. package/ccw/scripts/__pycache__/memory_embedder.cpython-313.pyc +0 -0
  81. package/ccw/scripts/__pycache__/test_memory_embedder.cpython-313-pytest-8.4.2.pyc +0 -0
  82. package/ccw/scripts/memory-embedder-example.ts +184 -0
  83. package/ccw/scripts/memory_embedder.py +428 -0
  84. package/ccw/scripts/test_memory_embedder.py +245 -0
  85. package/ccw/src/core/auth/csrf-middleware.ts +3 -1
  86. package/ccw/src/core/data-aggregator.ts +7 -2
  87. package/ccw/src/core/lite-scanner.ts +440 -6
  88. package/ccw/src/core/routes/codexlens/config-handlers.ts +12 -9
  89. package/ccw/src/core/routes/session-routes.ts +201 -48
  90. package/ccw/src/core/routes/system-routes.ts +102 -0
  91. package/ccw/src/core/server.ts +2 -2
  92. package/ccw/src/templates/dashboard-css/01-base.css +8 -0
  93. package/ccw/src/templates/dashboard-css/02-session.css +81 -0
  94. package/ccw/src/templates/dashboard-css/04-lite-tasks.css +2442 -0
  95. package/ccw/src/templates/dashboard-css/21-cli-toolmgmt.css +157 -0
  96. package/ccw/src/templates/dashboard-css/32-issue-manager.css +23 -0
  97. package/ccw/src/templates/dashboard-js/components/cli-stream-viewer.js +38 -4
  98. package/ccw/src/templates/dashboard-js/components/hook-manager.js +38 -13
  99. package/ccw/src/templates/dashboard-js/components/navigation.js +24 -4
  100. package/ccw/src/templates/dashboard-js/i18n.js +194 -6
  101. package/ccw/src/templates/dashboard-js/views/api-settings.js +32 -0
  102. package/ccw/src/templates/dashboard-js/views/claude-manager.js +44 -3
  103. package/ccw/src/templates/dashboard-js/views/cli-manager.js +303 -31
  104. package/ccw/src/templates/dashboard-js/views/history.js +44 -6
  105. package/ccw/src/templates/dashboard-js/views/home.js +1 -0
  106. package/ccw/src/templates/dashboard-js/views/issue-manager.js +54 -7
  107. package/ccw/src/templates/dashboard-js/views/lite-tasks.js +1817 -4
  108. package/ccw/src/templates/dashboard.html +5 -0
  109. package/package.json +2 -1
  110. package/.claude/skills/ccw/index/command-capabilities.json +0 -127
  111. package/.claude/skills/ccw/index/intent-rules.json +0 -136
  112. package/.claude/skills/ccw/index/workflow-chains.json +0 -451
  113. package/.claude/skills/ccw/phases/actions/bugfix.md +0 -218
  114. package/.claude/skills/ccw/phases/actions/coupled.md +0 -194
  115. package/.claude/skills/ccw/phases/actions/docs.md +0 -93
  116. package/.claude/skills/ccw/phases/actions/full.md +0 -154
  117. package/.claude/skills/ccw/phases/actions/issue.md +0 -201
  118. package/.claude/skills/ccw/phases/actions/rapid.md +0 -104
  119. package/.claude/skills/ccw/phases/actions/review-fix.md +0 -84
  120. package/.claude/skills/ccw/phases/actions/tdd.md +0 -66
  121. package/.claude/skills/ccw/phases/actions/ui.md +0 -79
  122. package/.claude/skills/ccw/phases/orchestrator.md +0 -435
  123. package/.claude/skills/ccw/specs/intent-classification.md +0 -336
  124. package/.claude/skills/ccw-help/index/all-agents.json +0 -82
  125. package/.claude/skills/ccw-help/index/all-commands.json +0 -882
  126. package/.claude/skills/ccw-help/index/by-category.json +0 -914
  127. package/.claude/skills/ccw-help/index/by-use-case.json +0 -896
  128. package/.claude/skills/ccw-help/index/command-relationships.json +0 -160
  129. package/.claude/skills/ccw-help/index/essential-commands.json +0 -112
@@ -0,0 +1,303 @@
1
+ ---
2
+ name: skill-tuning
3
+ description: Universal skill diagnosis and optimization tool. Detect and fix skill execution issues including context explosion, long-tail forgetting, data flow disruption, and agent coordination failures. Supports Gemini CLI for deep analysis. Triggers on "skill tuning", "tune skill", "skill diagnosis", "optimize skill", "skill debug".
4
+ allowed-tools: Task, AskUserQuestion, Read, Write, Bash, Glob, Grep, mcp__ace-tool__search_context
5
+ ---
6
+
7
+ # Skill Tuning
8
+
9
+ Universal skill diagnosis and optimization tool that identifies and resolves skill execution problems through iterative multi-agent analysis.
10
+
11
+ ## Architecture Overview
12
+
13
+ ```
14
+ ┌─────────────────────────────────────────────────────────────────────────────┐
15
+ │ Skill Tuning Architecture (Autonomous Mode + Gemini CLI) │
16
+ ├─────────────────────────────────────────────────────────────────────────────┤
17
+ │ │
18
+ │ ⚠️ Phase 0: Specification → 阅读规范 + 理解目标 skill 结构 (强制前置) │
19
+ │ Study │
20
+ │ ↓ │
21
+ │ ┌───────────────────────────────────────────────────────────────────────┐ │
22
+ │ │ Orchestrator (状态驱动决策) │ │
23
+ │ │ 读取诊断状态 → 选择下一步动作 → 执行 → 更新状态 → 循环直到完成 │ │
24
+ │ └───────────────────────────────────────────────────────────────────────┘ │
25
+ │ │ │
26
+ │ ┌────────────┬───────────┼───────────┬────────────┬────────────┐ │
27
+ │ ↓ ↓ ↓ ↓ ↓ ↓ │
28
+ │ ┌──────┐ ┌──────────┐ ┌─────────┐ ┌────────┐ ┌────────┐ ┌─────────┐ │
29
+ │ │ Init │→ │ Analyze │→ │Diagnose │ │Diagnose│ │Diagnose│ │ Gemini │ │
30
+ │ │ │ │Requiremts│ │ Context │ │ Memory │ │DataFlow│ │Analysis │ │
31
+ │ └──────┘ └──────────┘ └─────────┘ └────────┘ └────────┘ └─────────┘ │
32
+ │ │ │ │ │ │ │
33
+ │ │ └───────────┴───────────┴────────────┘ │
34
+ │ ↓ │
35
+ │ ┌───────────────────────────────────────────────────────────────────────┐ │
36
+ │ │ Requirement Analysis (NEW) │ │
37
+ │ │ • Phase 1: 维度拆解 (Gemini CLI) - 单一描述 → 多个关注维度 │ │
38
+ │ │ • Phase 2: Spec 匹配 - 每个维度 → taxonomy + strategy │ │
39
+ │ │ • Phase 3: 覆盖度评估 - 以"有修复策略"为满足标准 │ │
40
+ │ │ • Phase 4: 歧义检测 - 识别多义性描述,必要时请求澄清 │ │
41
+ │ └───────────────────────────────────────────────────────────────────────┘ │
42
+ │ ↓ │
43
+ │ ┌──────────────────┐ │
44
+ │ │ Apply Fixes + │ │
45
+ │ │ Verify Results │ │
46
+ │ └──────────────────┘ │
47
+ │ │
48
+ │ ┌───────────────────────────────────────────────────────────────────────┐ │
49
+ │ │ Gemini CLI Integration │ │
50
+ │ │ 根据用户需求动态调用 gemini cli 进行深度分析: │ │
51
+ │ │ • 需求维度拆解 (requirement decomposition) │ │
52
+ │ │ • 复杂问题分析 (prompt engineering, architecture review) │ │
53
+ │ │ • 代码模式识别 (pattern matching, anti-pattern detection) │ │
54
+ │ │ • 修复策略生成 (fix generation, refactoring suggestions) │ │
55
+ │ └───────────────────────────────────────────────────────────────────────┘ │
56
+ │ │
57
+ └─────────────────────────────────────────────────────────────────────────────┘
58
+ ```
59
+
60
+ ## Problem Domain
61
+
62
+ Based on comprehensive analysis, skill-tuning addresses **core skill issues** and **general optimization areas**:
63
+
64
+ ### Core Skill Issues (自动检测)
65
+
66
+ | Priority | Problem | Root Cause | Solution Strategy |
67
+ |----------|---------|------------|-------------------|
68
+ | **P0** | Authoring Principles Violation | 中间文件存储, State膨胀, 文件中转 | eliminate_intermediate_files, minimize_state, context_passing |
69
+ | **P1** | Data Flow Disruption | Scattered state, inconsistent formats | state_centralization, schema_enforcement |
70
+ | **P2** | Agent Coordination | Fragile call chains, merge complexity | error_wrapping, result_validation |
71
+ | **P3** | Context Explosion | Token accumulation, multi-turn bloat | sliding_window, context_summarization |
72
+ | **P4** | Long-tail Forgetting | Early constraint loss | constraint_injection, checkpoint_restore |
73
+ | **P5** | Token Consumption | Verbose prompts, excessive state, redundant I/O | prompt_compression, lazy_loading, output_minimization |
74
+
75
+ ### General Optimization Areas (按需分析 via Gemini CLI)
76
+
77
+ | Category | Issues | Gemini Analysis Scope |
78
+ |----------|--------|----------------------|
79
+ | **Prompt Engineering** | 模糊指令, 输出格式不一致, 幻觉风险 | 提示词优化, 结构化输出设计 |
80
+ | **Architecture** | 阶段划分不合理, 依赖混乱, 扩展性差 | 架构审查, 模块化建议 |
81
+ | **Performance** | 执行慢, Token消耗高, 重复计算 | 性能分析, 缓存策略 |
82
+ | **Error Handling** | 错误恢复不当, 无降级策略, 日志不足 | 容错设计, 可观测性增强 |
83
+ | **Output Quality** | 输出不稳定, 格式漂移, 质量波动 | 质量门控, 验证机制 |
84
+ | **User Experience** | 交互不流畅, 反馈不清晰, 进度不可见 | UX优化, 进度追踪 |
85
+
86
+ ## Key Design Principles
87
+
88
+ 1. **Problem-First Diagnosis**: Systematic identification before any fix attempt
89
+ 2. **Data-Driven Analysis**: Record execution traces, token counts, state snapshots
90
+ 3. **Iterative Refinement**: Multiple tuning rounds until quality gates pass
91
+ 4. **Non-Destructive**: All changes are reversible with backup checkpoints
92
+ 5. **Agent Coordination**: Use specialized sub-agents for each diagnosis type
93
+ 6. **Gemini CLI On-Demand**: Deep analysis via CLI for complex/custom issues
94
+
95
+ ---
96
+
97
+ ## Gemini CLI Integration
98
+
99
+ 根据用户需求动态调用 Gemini CLI 进行深度分析。
100
+
101
+ ### Trigger Conditions
102
+
103
+ | Condition | Action | CLI Mode |
104
+ |-----------|--------|----------|
105
+ | 用户描述复杂问题 | 调用 Gemini 分析问题根因 | `analysis` |
106
+ | 自动诊断发现 critical 问题 | 请求深度分析确认 | `analysis` |
107
+ | 用户请求架构审查 | 执行架构分析 | `analysis` |
108
+ | 需要生成修复代码 | 生成修复提案 | `write` |
109
+ | 标准策略不适用 | 请求定制化策略 | `analysis` |
110
+
111
+ ### CLI Command Template
112
+
113
+ ```bash
114
+ ccw cli -p "
115
+ PURPOSE: ${purpose}
116
+ TASK: ${task_steps}
117
+ MODE: ${mode}
118
+ CONTEXT: @${skill_path}/**/*
119
+ EXPECTED: ${expected_output}
120
+ RULES: $(cat ~/.claude/workflows/cli-templates/protocols/${mode}-protocol.md) | ${constraints}
121
+ " --tool gemini --mode ${mode} --cd ${skill_path}
122
+ ```
123
+
124
+ ### Analysis Types
125
+
126
+ #### 1. Problem Root Cause Analysis
127
+
128
+ ```bash
129
+ ccw cli -p "
130
+ PURPOSE: Identify root cause of skill execution issue: ${user_issue_description}
131
+ TASK: • Analyze skill structure and phase flow • Identify anti-patterns • Trace data flow issues
132
+ MODE: analysis
133
+ CONTEXT: @**/*.md
134
+ EXPECTED: JSON with { root_causes: [], patterns_found: [], recommendations: [] }
135
+ RULES: $(cat ~/.claude/workflows/cli-templates/protocols/analysis-protocol.md) | Focus on execution flow
136
+ " --tool gemini --mode analysis
137
+ ```
138
+
139
+ #### 2. Architecture Review
140
+
141
+ ```bash
142
+ ccw cli -p "
143
+ PURPOSE: Review skill architecture for scalability and maintainability
144
+ TASK: • Evaluate phase decomposition • Check state management patterns • Assess agent coordination
145
+ MODE: analysis
146
+ CONTEXT: @**/*.md
147
+ EXPECTED: Architecture assessment with improvement recommendations
148
+ RULES: $(cat ~/.claude/workflows/cli-templates/protocols/analysis-protocol.md) | Focus on modularity
149
+ " --tool gemini --mode analysis
150
+ ```
151
+
152
+ #### 3. Fix Strategy Generation
153
+
154
+ ```bash
155
+ ccw cli -p "
156
+ PURPOSE: Generate fix strategy for issue: ${issue_id} - ${issue_description}
157
+ TASK: • Analyze issue context • Design fix approach • Generate implementation plan
158
+ MODE: analysis
159
+ CONTEXT: @**/*.md
160
+ EXPECTED: JSON with { strategy: string, changes: [], verification_steps: [] }
161
+ RULES: $(cat ~/.claude/workflows/cli-templates/protocols/analysis-protocol.md) | Minimal invasive changes
162
+ " --tool gemini --mode analysis
163
+ ```
164
+
165
+ ---
166
+
167
+ ## Mandatory Prerequisites
168
+
169
+ > **CRITICAL**: Read these documents before executing any action.
170
+
171
+ ### Core Specs (Required)
172
+
173
+ | Document | Purpose | Priority |
174
+ |----------|---------|----------|
175
+ | [specs/skill-authoring-principles.md](specs/skill-authoring-principles.md) | **首要准则:简洁高效、去除存储、上下文流转** | **P0** |
176
+ | [specs/problem-taxonomy.md](specs/problem-taxonomy.md) | Problem classification and detection patterns | **P0** |
177
+ | [specs/tuning-strategies.md](specs/tuning-strategies.md) | Fix strategies for each problem type | **P0** |
178
+ | [specs/dimension-mapping.md](specs/dimension-mapping.md) | Dimension to Spec mapping rules | **P0** |
179
+ | [specs/quality-gates.md](specs/quality-gates.md) | Quality thresholds and verification criteria | P1 |
180
+
181
+ ### Templates (Reference)
182
+
183
+ | Document | Purpose |
184
+ |----------|---------|
185
+ | [templates/diagnosis-report.md](templates/diagnosis-report.md) | Diagnosis report structure |
186
+ | [templates/fix-proposal.md](templates/fix-proposal.md) | Fix proposal format |
187
+
188
+ ---
189
+
190
+ ## Execution Flow
191
+
192
+ ```
193
+ ┌─────────────────────────────────────────────────────────────────────────────┐
194
+ │ Phase 0: Specification Study (强制前置 - 禁止跳过) │
195
+ │ → Read: specs/problem-taxonomy.md (问题分类) │
196
+ │ → Read: specs/tuning-strategies.md (调优策略) │
197
+ │ → Read: specs/dimension-mapping.md (维度映射规则) │
198
+ │ → Read: Target skill's SKILL.md and phases/*.md │
199
+ │ → Output: 内化规范,理解目标 skill 结构 │
200
+ ├─────────────────────────────────────────────────────────────────────────────┤
201
+ │ action-init: Initialize Tuning Session │
202
+ │ → Create work directory: .workflow/.scratchpad/skill-tuning-{timestamp} │
203
+ │ → Initialize state.json with target skill info │
204
+ │ → Create backup of target skill files │
205
+ ├─────────────────────────────────────────────────────────────────────────────┤
206
+ │ action-analyze-requirements: Requirement Analysis │
207
+ │ → Phase 1: 维度拆解 (Gemini CLI) - 单一描述 → 多个关注维度 │
208
+ │ → Phase 2: Spec 匹配 - 每个维度 → taxonomy + strategy │
209
+ │ → Phase 3: 覆盖度评估 - 以"有修复策略"为满足标准 │
210
+ │ → Phase 4: 歧义检测 - 识别多义性描述,必要时请求澄清 │
211
+ │ → Output: state.json (requirement_analysis field) │
212
+ ├─────────────────────────────────────────────────────────────────────────────┤
213
+ │ action-diagnose-*: Diagnosis Actions (context/memory/dataflow/agent/docs/ │
214
+ │ token_consumption) │
215
+ │ → Execute pattern-based detection for each category │
216
+ │ → Output: state.json (diagnosis.{category} field) │
217
+ ├─────────────────────────────────────────────────────────────────────────────┤
218
+ │ action-generate-report: Consolidated Report │
219
+ │ → Generate markdown summary from state.diagnosis │
220
+ │ → Prioritize issues by severity │
221
+ │ → Output: state.json (final_report field) │
222
+ ├─────────────────────────────────────────────────────────────────────────────┤
223
+ │ action-propose-fixes: Fix Proposal Generation │
224
+ │ → Generate fix strategies for each issue │
225
+ │ → Create implementation plan │
226
+ │ → Output: state.json (proposed_fixes field) │
227
+ ├─────────────────────────────────────────────────────────────────────────────┤
228
+ │ action-apply-fix: Apply Selected Fix │
229
+ │ → User selects fix to apply │
230
+ │ → Execute fix with backup │
231
+ │ → Update state with fix result │
232
+ ├─────────────────────────────────────────────────────────────────────────────┤
233
+ │ action-verify: Verification │
234
+ │ → Re-run affected diagnosis │
235
+ │ → Check quality gates │
236
+ │ → Update iteration count │
237
+ ├─────────────────────────────────────────────────────────────────────────────┤
238
+ │ action-complete: Finalization │
239
+ │ → Set status='completed' │
240
+ │ → Final report already in state.json (final_report field) │
241
+ │ → Output: state.json (final) │
242
+ └─────────────────────────────────────────────────────────────────────────────┘
243
+ ```
244
+
245
+ ## Directory Setup
246
+
247
+ ```javascript
248
+ const timestamp = new Date().toISOString().slice(0,19).replace(/[-:T]/g, '');
249
+ const workDir = `.workflow/.scratchpad/skill-tuning-${timestamp}`;
250
+
251
+ // Simplified: Only backups dir needed, diagnosis results go into state.json
252
+ Bash(`mkdir -p "${workDir}/backups"`);
253
+ ```
254
+
255
+ ## Output Structure
256
+
257
+ ```
258
+ .workflow/.scratchpad/skill-tuning-{timestamp}/
259
+ ├── state.json # Single source of truth (all results consolidated)
260
+ │ ├── diagnosis.* # All diagnosis results embedded
261
+ │ ├── issues[] # Found issues
262
+ │ ├── proposed_fixes[] # Fix proposals
263
+ │ └── final_report # Markdown summary (on completion)
264
+ └── backups/
265
+ └── {skill-name}-backup/ # Original skill files backup
266
+ ```
267
+
268
+ > **Token Optimization**: All outputs consolidated into state.json. No separate diagnosis files or report files.
269
+
270
+ ## State Schema
271
+
272
+ 详细状态结构定义请参阅 [phases/state-schema.md](phases/state-schema.md)。
273
+
274
+ 核心状态字段:
275
+ - `status`: 工作流状态 (pending/running/completed/failed)
276
+ - `target_skill`: 目标 skill 信息
277
+ - `diagnosis`: 各维度诊断结果
278
+ - `issues`: 发现的问题列表
279
+ - `proposed_fixes`: 建议的修复方案
280
+
281
+ ## Reference Documents
282
+
283
+ | Document | Purpose |
284
+ |----------|---------|
285
+ | [phases/orchestrator.md](phases/orchestrator.md) | Orchestrator decision logic |
286
+ | [phases/state-schema.md](phases/state-schema.md) | State structure definition |
287
+ | [phases/actions/action-init.md](phases/actions/action-init.md) | Initialize tuning session |
288
+ | [phases/actions/action-analyze-requirements.md](phases/actions/action-analyze-requirements.md) | Requirement analysis (NEW) |
289
+ | [phases/actions/action-diagnose-context.md](phases/actions/action-diagnose-context.md) | Context explosion diagnosis |
290
+ | [phases/actions/action-diagnose-memory.md](phases/actions/action-diagnose-memory.md) | Long-tail forgetting diagnosis |
291
+ | [phases/actions/action-diagnose-dataflow.md](phases/actions/action-diagnose-dataflow.md) | Data flow diagnosis |
292
+ | [phases/actions/action-diagnose-agent.md](phases/actions/action-diagnose-agent.md) | Agent coordination diagnosis |
293
+ | [phases/actions/action-diagnose-docs.md](phases/actions/action-diagnose-docs.md) | Documentation structure diagnosis |
294
+ | [phases/actions/action-diagnose-token-consumption.md](phases/actions/action-diagnose-token-consumption.md) | Token consumption diagnosis |
295
+ | [phases/actions/action-generate-report.md](phases/actions/action-generate-report.md) | Report generation |
296
+ | [phases/actions/action-propose-fixes.md](phases/actions/action-propose-fixes.md) | Fix proposal |
297
+ | [phases/actions/action-apply-fix.md](phases/actions/action-apply-fix.md) | Fix application |
298
+ | [phases/actions/action-verify.md](phases/actions/action-verify.md) | Verification |
299
+ | [phases/actions/action-complete.md](phases/actions/action-complete.md) | Finalization |
300
+ | [specs/problem-taxonomy.md](specs/problem-taxonomy.md) | Problem classification |
301
+ | [specs/tuning-strategies.md](specs/tuning-strategies.md) | Fix strategies |
302
+ | [specs/dimension-mapping.md](specs/dimension-mapping.md) | Dimension to Spec mapping (NEW) |
303
+ | [specs/quality-gates.md](specs/quality-gates.md) | Quality criteria |
@@ -0,0 +1,164 @@
1
+ # Action: Abort
2
+
3
+ Abort the tuning session due to unrecoverable errors.
4
+
5
+ ## Purpose
6
+
7
+ - Safely terminate on critical failures
8
+ - Preserve diagnostic information for debugging
9
+ - Ensure backup remains available
10
+ - Notify user of failure reason
11
+
12
+ ## Preconditions
13
+
14
+ - [ ] state.error_count >= state.max_errors
15
+ - [ ] OR critical failure detected
16
+
17
+ ## Execution
18
+
19
+ ```javascript
20
+ async function execute(state, workDir) {
21
+ console.log('Aborting skill tuning session...');
22
+
23
+ const errors = state.errors;
24
+ const targetSkill = state.target_skill;
25
+
26
+ // Generate abort report
27
+ const abortReport = `# Skill Tuning Aborted
28
+
29
+ **Target Skill**: ${targetSkill?.name || 'Unknown'}
30
+ **Aborted At**: ${new Date().toISOString()}
31
+ **Reason**: Too many errors or critical failure
32
+
33
+ ---
34
+
35
+ ## Error Log
36
+
37
+ ${errors.length === 0 ? '_No errors recorded_' :
38
+ errors.map((err, i) => `
39
+ ### Error ${i + 1}
40
+ - **Action**: ${err.action}
41
+ - **Message**: ${err.message}
42
+ - **Time**: ${err.timestamp}
43
+ - **Recoverable**: ${err.recoverable ? 'Yes' : 'No'}
44
+ `).join('\n')}
45
+
46
+ ---
47
+
48
+ ## Session State at Abort
49
+
50
+ - **Status**: ${state.status}
51
+ - **Iteration Count**: ${state.iteration_count}
52
+ - **Completed Actions**: ${state.completed_actions.length}
53
+ - **Issues Found**: ${state.issues.length}
54
+ - **Fixes Applied**: ${state.applied_fixes.length}
55
+
56
+ ---
57
+
58
+ ## Recovery Options
59
+
60
+ ### Option 1: Restore Original Skill
61
+ If any changes were made, restore from backup:
62
+ \`\`\`bash
63
+ cp -r "${state.backup_dir}/${targetSkill?.name || 'backup'}-backup"/* "${targetSkill?.path || 'target'}/"
64
+ \`\`\`
65
+
66
+ ### Option 2: Resume from Last State
67
+ The session state is preserved at:
68
+ \`${workDir}/state.json\`
69
+
70
+ To resume:
71
+ 1. Fix the underlying issue
72
+ 2. Reset error_count in state.json
73
+ 3. Re-run skill-tuning with --resume flag
74
+
75
+ ### Option 3: Manual Investigation
76
+ Review the following files:
77
+ - Diagnosis results: \`${workDir}/diagnosis/*.json\`
78
+ - Error log: \`${workDir}/errors.json\`
79
+ - State snapshot: \`${workDir}/state.json\`
80
+
81
+ ---
82
+
83
+ ## Diagnostic Information
84
+
85
+ ### Last Successful Action
86
+ ${state.completed_actions.length > 0 ? state.completed_actions[state.completed_actions.length - 1] : 'None'}
87
+
88
+ ### Current Action When Failed
89
+ ${state.current_action || 'Unknown'}
90
+
91
+ ### Partial Diagnosis Results
92
+ - Context: ${state.diagnosis.context ? 'Completed' : 'Not completed'}
93
+ - Memory: ${state.diagnosis.memory ? 'Completed' : 'Not completed'}
94
+ - Data Flow: ${state.diagnosis.dataflow ? 'Completed' : 'Not completed'}
95
+ - Agent: ${state.diagnosis.agent ? 'Completed' : 'Not completed'}
96
+
97
+ ---
98
+
99
+ *Skill tuning aborted - please review errors and retry*
100
+ `;
101
+
102
+ // Write abort report
103
+ Write(`${workDir}/abort-report.md`, abortReport);
104
+
105
+ // Save error log
106
+ Write(`${workDir}/errors.json`, JSON.stringify(errors, null, 2));
107
+
108
+ // Notify user
109
+ await AskUserQuestion({
110
+ questions: [{
111
+ question: `Skill tuning aborted due to ${errors.length} errors. Would you like to restore the original skill?`,
112
+ header: 'Restore',
113
+ multiSelect: false,
114
+ options: [
115
+ { label: 'Yes, restore', description: 'Restore original skill from backup' },
116
+ { label: 'No, keep changes', description: 'Keep any partial changes made' }
117
+ ]
118
+ }]
119
+ }).then(async response => {
120
+ if (response['Restore'] === 'Yes, restore') {
121
+ // Restore from backup
122
+ if (state.backup_dir && targetSkill?.path) {
123
+ Bash(`cp -r "${state.backup_dir}/${targetSkill.name}-backup"/* "${targetSkill.path}/"`);
124
+ console.log('Original skill restored from backup.');
125
+ }
126
+ }
127
+ }).catch(() => {
128
+ // User cancelled, don't restore
129
+ });
130
+
131
+ return {
132
+ stateUpdates: {
133
+ status: 'failed',
134
+ completed_at: new Date().toISOString()
135
+ },
136
+ outputFiles: [`${workDir}/abort-report.md`, `${workDir}/errors.json`],
137
+ summary: `Tuning aborted: ${errors.length} errors. Check abort-report.md for details.`
138
+ };
139
+ }
140
+ ```
141
+
142
+ ## State Updates
143
+
144
+ ```javascript
145
+ return {
146
+ stateUpdates: {
147
+ status: 'failed',
148
+ completed_at: '<timestamp>'
149
+ }
150
+ };
151
+ ```
152
+
153
+ ## Output
154
+
155
+ - **File**: `abort-report.md`
156
+ - **Location**: `${workDir}/abort-report.md`
157
+
158
+ ## Error Handling
159
+
160
+ This action should not fail - it's the final error handler.
161
+
162
+ ## Next Actions
163
+
164
+ - None (terminal state)