claude-code-workflow 6.3.48 → 6.3.49

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 (211) hide show
  1. package/.claude/CLAUDE.md +6 -8
  2. package/.claude/agents/action-planning-agent.md +28 -45
  3. package/.claude/agents/cli-lite-planning-agent.md +93 -1
  4. package/.claude/agents/code-developer.md +144 -27
  5. package/.claude/commands/ccw-coordinator.md +175 -21
  6. package/.claude/commands/ccw-debug.md +832 -0
  7. package/.claude/commands/ccw.md +90 -9
  8. package/.claude/commands/cli/cli-init.md +1 -0
  9. package/.claude/commands/issue/convert-to-plan.md +718 -0
  10. package/.claude/commands/issue/from-brainstorm.md +382 -0
  11. package/.claude/commands/memory/tips.md +332 -0
  12. package/.claude/commands/workflow/analyze-with-file.md +804 -0
  13. package/.claude/commands/workflow/brainstorm/auto-parallel.md +18 -43
  14. package/.claude/commands/workflow/brainstorm/role-analysis.md +705 -0
  15. package/.claude/commands/workflow/brainstorm-with-file.md +1153 -0
  16. package/.claude/commands/workflow/debug-with-file.md +7 -5
  17. package/.claude/commands/workflow/execute.md +6 -4
  18. package/.claude/commands/workflow/lite-plan.md +2 -2
  19. package/.claude/commands/workflow/plan-verify.md +162 -327
  20. package/.claude/commands/workflow/plan.md +162 -26
  21. package/.claude/commands/workflow/replan.md +78 -2
  22. package/.claude/commands/workflow/{review-fix.md → review-cycle-fix.md} +6 -6
  23. package/.claude/commands/workflow/review-module-cycle.md +2 -2
  24. package/.claude/commands/workflow/review-session-cycle.md +2 -2
  25. package/.claude/commands/workflow/tools/conflict-resolution.md +16 -26
  26. package/.claude/commands/workflow/tools/context-gather.md +81 -118
  27. package/.claude/commands/workflow/tools/task-generate-agent.md +94 -10
  28. package/.claude/skills/ccw-help/command.json +4 -4
  29. package/.claude/skills/lite-skill-generator/SKILL.md +650 -0
  30. package/.claude/skills/lite-skill-generator/templates/simple-skill.md +68 -0
  31. package/.claude/skills/lite-skill-generator/templates/style-guide.md +64 -0
  32. package/.claude/skills/skill-generator/SKILL.md +277 -85
  33. package/.claude/skills/skill-generator/phases/01-requirements-discovery.md +4 -15
  34. package/.claude/skills/skill-generator/phases/02-structure-generation.md +72 -17
  35. package/.claude/skills/skill-generator/phases/03-phase-generation.md +218 -51
  36. package/.claude/skills/skill-generator/phases/04-specs-templates.md +111 -41
  37. package/.claude/skills/skill-generator/phases/05-validation.md +139 -56
  38. package/.claude/skills/skill-generator/templates/autonomous-action.md +78 -268
  39. package/.claude/skills/skill-generator/templates/autonomous-orchestrator.md +14 -0
  40. package/.claude/skills/skill-generator/templates/code-analysis-action.md +12 -0
  41. package/.claude/skills/skill-generator/templates/llm-action.md +12 -0
  42. package/.claude/skills/skill-generator/templates/script-template.md +368 -0
  43. package/.claude/skills/skill-generator/templates/sequential-phase.md +14 -0
  44. package/.claude/skills/skill-generator/templates/skill-md.md +14 -0
  45. package/.claude/skills/skill-tuning/SKILL.md +130 -266
  46. package/.claude/skills/skill-tuning/phases/orchestrator.md +95 -283
  47. package/.claude/skills/skill-tuning/specs/problem-taxonomy.md +90 -198
  48. package/.claude/skills/skill-tuning/specs/tuning-strategies.md +193 -1345
  49. package/.claude/workflows/cli-templates/schemas/plan-verify-agent-schema.json +47 -0
  50. package/.claude/workflows/cli-templates/schemas/verify-json-schema.json +158 -0
  51. package/.claude/workflows/cli-tools-usage.md +1 -1
  52. package/.codex/AGENTS.md +1 -3
  53. package/.codex/prompts/analyze-with-file.md +607 -0
  54. package/.codex/prompts/brainstorm-to-cycle.md +455 -0
  55. package/.codex/prompts/brainstorm-with-file.md +933 -0
  56. package/.codex/prompts/debug-with-file.md +15 -20
  57. package/.codex/skills/ccw-cli-tools/SKILL.md +559 -0
  58. package/ccw/dist/commands/cli.d.ts.map +1 -1
  59. package/ccw/dist/commands/cli.js +29 -5
  60. package/ccw/dist/commands/cli.js.map +1 -1
  61. package/ccw/dist/commands/issue.d.ts +2 -0
  62. package/ccw/dist/commands/issue.d.ts.map +1 -1
  63. package/ccw/dist/commands/issue.js +62 -20
  64. package/ccw/dist/commands/issue.js.map +1 -1
  65. package/ccw/dist/config/litellm-api-config-manager.d.ts.map +1 -1
  66. package/ccw/dist/config/litellm-api-config-manager.js +5 -3
  67. package/ccw/dist/config/litellm-api-config-manager.js.map +1 -1
  68. package/ccw/dist/config/litellm-provider-models.d.ts +73 -0
  69. package/ccw/dist/config/litellm-provider-models.d.ts.map +1 -0
  70. package/ccw/dist/config/litellm-provider-models.js +172 -0
  71. package/ccw/dist/config/litellm-provider-models.js.map +1 -0
  72. package/ccw/dist/config/provider-models.d.ts +25 -51
  73. package/ccw/dist/config/provider-models.d.ts.map +1 -1
  74. package/ccw/dist/config/provider-models.js +84 -149
  75. package/ccw/dist/config/provider-models.js.map +1 -1
  76. package/ccw/dist/config/storage-paths.d.ts.map +1 -1
  77. package/ccw/dist/config/storage-paths.js +23 -5
  78. package/ccw/dist/config/storage-paths.js.map +1 -1
  79. package/ccw/dist/core/auth/csrf-middleware.js +3 -3
  80. package/ccw/dist/core/auth/csrf-middleware.js.map +1 -1
  81. package/ccw/dist/core/dashboard-generator.d.ts.map +1 -1
  82. package/ccw/dist/core/dashboard-generator.js +3 -1
  83. package/ccw/dist/core/dashboard-generator.js.map +1 -1
  84. package/ccw/dist/core/routes/claude-routes.d.ts.map +1 -1
  85. package/ccw/dist/core/routes/claude-routes.js +206 -14
  86. package/ccw/dist/core/routes/claude-routes.js.map +1 -1
  87. package/ccw/dist/core/routes/cli-routes.d.ts.map +1 -1
  88. package/ccw/dist/core/routes/cli-routes.js.map +1 -1
  89. package/ccw/dist/core/routes/commands-routes.d.ts +7 -0
  90. package/ccw/dist/core/routes/commands-routes.d.ts.map +1 -0
  91. package/ccw/dist/core/routes/commands-routes.js +480 -0
  92. package/ccw/dist/core/routes/commands-routes.js.map +1 -0
  93. package/ccw/dist/core/routes/model-routes.d.ts +11 -0
  94. package/ccw/dist/core/routes/model-routes.d.ts.map +1 -0
  95. package/ccw/dist/core/routes/model-routes.js +112 -0
  96. package/ccw/dist/core/routes/model-routes.js.map +1 -0
  97. package/ccw/dist/core/routes/nav-status-routes.d.ts.map +1 -1
  98. package/ccw/dist/core/routes/nav-status-routes.js +84 -1
  99. package/ccw/dist/core/routes/nav-status-routes.js.map +1 -1
  100. package/ccw/dist/core/routes/provider-routes.d.ts +11 -0
  101. package/ccw/dist/core/routes/provider-routes.d.ts.map +1 -0
  102. package/ccw/dist/core/routes/provider-routes.js +67 -0
  103. package/ccw/dist/core/routes/provider-routes.js.map +1 -0
  104. package/ccw/dist/core/routes/skills-routes.d.ts.map +1 -1
  105. package/ccw/dist/core/routes/skills-routes.js +219 -7
  106. package/ccw/dist/core/routes/skills-routes.js.map +1 -1
  107. package/ccw/dist/core/routes/system-routes.d.ts.map +1 -1
  108. package/ccw/dist/core/routes/system-routes.js +58 -6
  109. package/ccw/dist/core/routes/system-routes.js.map +1 -1
  110. package/ccw/dist/core/server.d.ts.map +1 -1
  111. package/ccw/dist/core/server.js +13 -0
  112. package/ccw/dist/core/server.js.map +1 -1
  113. package/ccw/dist/mcp-server/index.js +2 -2
  114. package/ccw/dist/mcp-server/index.js.map +1 -1
  115. package/ccw/dist/tools/claude-cli-tools.d.ts +48 -11
  116. package/ccw/dist/tools/claude-cli-tools.d.ts.map +1 -1
  117. package/ccw/dist/tools/claude-cli-tools.js +146 -50
  118. package/ccw/dist/tools/claude-cli-tools.js.map +1 -1
  119. package/ccw/dist/tools/cli-config-manager.d.ts +1 -13
  120. package/ccw/dist/tools/cli-config-manager.d.ts.map +1 -1
  121. package/ccw/dist/tools/cli-config-manager.js +3 -27
  122. package/ccw/dist/tools/cli-config-manager.js.map +1 -1
  123. package/ccw/dist/tools/cli-executor-core.d.ts.map +1 -1
  124. package/ccw/dist/tools/cli-executor-core.js +7 -2
  125. package/ccw/dist/tools/cli-executor-core.js.map +1 -1
  126. package/ccw/dist/tools/cli-executor-state.d.ts.map +1 -1
  127. package/ccw/dist/tools/cli-history-store.d.ts +11 -0
  128. package/ccw/dist/tools/cli-history-store.d.ts.map +1 -1
  129. package/ccw/dist/tools/cli-history-store.js +82 -2
  130. package/ccw/dist/tools/cli-history-store.js.map +1 -1
  131. package/ccw/dist/tools/command-registry.d.ts +7 -0
  132. package/ccw/dist/tools/command-registry.d.ts.map +1 -1
  133. package/ccw/dist/tools/command-registry.js +14 -1
  134. package/ccw/dist/tools/command-registry.js.map +1 -1
  135. package/ccw/dist/tools/generate-module-docs.d.ts.map +1 -1
  136. package/ccw/dist/tools/generate-module-docs.js +11 -7
  137. package/ccw/dist/tools/generate-module-docs.js.map +1 -1
  138. package/ccw/dist/tools/litellm-executor.d.ts +1 -0
  139. package/ccw/dist/tools/litellm-executor.d.ts.map +1 -1
  140. package/ccw/dist/tools/litellm-executor.js +11 -9
  141. package/ccw/dist/tools/litellm-executor.js.map +1 -1
  142. package/ccw/dist/types/skill-types.d.ts +97 -0
  143. package/ccw/dist/types/skill-types.d.ts.map +1 -0
  144. package/ccw/dist/types/skill-types.js +6 -0
  145. package/ccw/dist/types/skill-types.js.map +1 -0
  146. package/ccw/src/commands/cli.ts +36 -5
  147. package/ccw/src/commands/issue.ts +81 -26
  148. package/ccw/src/config/litellm-api-config-manager.ts +5 -3
  149. package/ccw/src/config/litellm-provider-models.ts +222 -0
  150. package/ccw/src/config/provider-models.ts +91 -190
  151. package/ccw/src/config/storage-paths.ts +20 -5
  152. package/ccw/src/core/auth/csrf-middleware.ts +3 -3
  153. package/ccw/src/core/dashboard-generator.ts +3 -1
  154. package/ccw/src/core/routes/claude-routes.ts +233 -15
  155. package/ccw/src/core/routes/cli-routes.ts +2 -3
  156. package/ccw/src/core/routes/commands-routes.ts +620 -0
  157. package/ccw/src/core/routes/nav-status-routes.ts +95 -1
  158. package/ccw/src/core/routes/provider-routes.ts +78 -0
  159. package/ccw/src/core/routes/skills-routes.ts +266 -45
  160. package/ccw/src/core/routes/system-routes.ts +102 -50
  161. package/ccw/src/core/server.ts +13 -0
  162. package/ccw/src/mcp-server/index.ts +2 -2
  163. package/ccw/src/templates/dashboard-css/18-cli-settings.css +35 -0
  164. package/ccw/src/templates/dashboard-css/37-commands.css +193 -0
  165. package/ccw/src/templates/dashboard-js/components/navigation.js +4 -0
  166. package/ccw/src/templates/dashboard-js/i18n.js +116 -0
  167. package/ccw/src/templates/dashboard-js/views/cli-manager.js +249 -4
  168. package/ccw/src/templates/dashboard-js/views/commands-manager.js +503 -0
  169. package/ccw/src/templates/dashboard-js/views/issue-manager.js +7 -7
  170. package/ccw/src/templates/dashboard-js/views/mcp-manager.js +2 -7
  171. package/ccw/src/templates/dashboard-js/views/skills-manager.js +164 -23
  172. package/ccw/src/templates/dashboard.html +7 -0
  173. package/ccw/src/tools/claude-cli-tools.ts +170 -56
  174. package/ccw/src/tools/cli-config-manager.ts +2 -33
  175. package/ccw/src/tools/cli-executor-core.ts +8 -2
  176. package/ccw/src/tools/cli-history-store.ts +92 -2
  177. package/ccw/src/tools/command-registry.ts +16 -1
  178. package/ccw/src/tools/generate-module-docs.ts +11 -7
  179. package/ccw/src/tools/litellm-executor.ts +13 -9
  180. package/ccw/src/types/skill-types.ts +99 -0
  181. package/package.json +1 -1
  182. package/.claude/commands/enhance-prompt.md +0 -93
  183. package/.claude/commands/memory/code-map-memory.md +0 -687
  184. package/.claude/commands/memory/docs.md +0 -615
  185. package/.claude/commands/memory/load-skill-memory.md +0 -182
  186. package/.claude/commands/memory/skill-memory.md +0 -525
  187. package/.claude/commands/memory/swagger-docs.md +0 -773
  188. package/.claude/commands/memory/tech-research-rules.md +0 -310
  189. package/.claude/commands/memory/workflow-skill-memory.md +0 -517
  190. package/.claude/commands/task/breakdown.md +0 -208
  191. package/.claude/commands/task/create.md +0 -152
  192. package/.claude/commands/task/execute.md +0 -270
  193. package/.claude/commands/task/replan.md +0 -441
  194. package/.claude/commands/version.md +0 -254
  195. package/.claude/commands/workflow/action-plan-verify.md +0 -485
  196. package/.claude/commands/workflow/brainstorm/api-designer.md +0 -587
  197. package/.claude/commands/workflow/brainstorm/data-architect.md +0 -220
  198. package/.claude/commands/workflow/brainstorm/product-manager.md +0 -200
  199. package/.claude/commands/workflow/brainstorm/product-owner.md +0 -200
  200. package/.claude/commands/workflow/brainstorm/scrum-master.md +0 -200
  201. package/.claude/commands/workflow/brainstorm/subject-matter-expert.md +0 -200
  202. package/.claude/commands/workflow/brainstorm/system-architect.md +0 -389
  203. package/.claude/commands/workflow/brainstorm/ui-designer.md +0 -221
  204. package/.claude/commands/workflow/brainstorm/ux-expert.md +0 -221
  205. package/.claude/commands/workflow/debug.md +0 -331
  206. package/.claude/commands/workflow/develop-with-file.md +0 -1044
  207. package/.claude/skills/ccw-loop/README.md +0 -303
  208. package/.claude/skills/skill-generator/templates/script-bash.md +0 -277
  209. package/.claude/skills/skill-generator/templates/script-python.md +0 -198
  210. package/.codex/prompts/debug.md +0 -318
  211. package/ccw/src/core/routes/mcp-routes.ts.backup +0 -549
@@ -1,28 +1,57 @@
1
1
  # Orchestrator
2
2
 
3
- Autonomous orchestrator for skill-tuning workflow. Reads current state and selects the next action based on diagnosis progress and quality gates.
3
+ State-driven orchestrator for autonomous skill-tuning workflow.
4
4
 
5
5
  ## Role
6
6
 
7
- Drive the tuning workflow by:
8
- 1. Reading current session state
9
- 2. Selecting the appropriate next action
10
- 3. Executing the action via sub-agent
11
- 4. Updating state with results
12
- 5. Repeating until termination conditions met
7
+ Read state Select action → Execute → Update → Repeat until termination.
13
8
 
14
- ## State Management
9
+ ## Decision Logic
15
10
 
16
- ### Read State
11
+ ### Termination Checks (priority order)
12
+
13
+ | Condition | Action |
14
+ |-----------|--------|
15
+ | `status === 'user_exit'` | null (exit) |
16
+ | `status === 'completed'` | null (exit) |
17
+ | `error_count >= max_errors` | action-abort |
18
+ | `iteration_count >= max_iterations` | action-complete |
19
+ | `quality_gate === 'pass'` | action-complete |
20
+
21
+ ### Action Selection
22
+
23
+ | Priority | Condition | Action |
24
+ |----------|-----------|--------|
25
+ | 1 | `status === 'pending'` | action-init |
26
+ | 2 | Init done, req analysis missing | action-analyze-requirements |
27
+ | 3 | Req needs clarification | null (wait) |
28
+ | 4 | Req coverage unsatisfied | action-gemini-analysis |
29
+ | 5 | Gemini requested/critical issues | action-gemini-analysis |
30
+ | 6 | Gemini running | null (wait) |
31
+ | 7 | Diagnosis pending (in order) | action-diagnose-{type} |
32
+ | 8 | All diagnosis done, no report | action-generate-report |
33
+ | 9 | Report done, issues exist | action-propose-fixes |
34
+ | 10 | Pending fixes exist | action-apply-fix |
35
+ | 11 | Fixes need verification | action-verify |
36
+ | 12 | New iteration needed | action-diagnose-context (restart) |
37
+ | 13 | Default | action-complete |
38
+
39
+ **Diagnosis Order**: context → memory → dataflow → agent → docs → token_consumption
40
+
41
+ **Gemini Triggers**:
42
+ - `gemini_analysis_requested === true`
43
+ - Critical issues detected
44
+ - Focus areas include: architecture, prompt, performance, custom
45
+ - Second iteration with unresolved issues
46
+
47
+ ## State Management
17
48
 
18
49
  ```javascript
50
+ // Read
19
51
  const state = JSON.parse(Read(`${workDir}/state.json`));
20
- ```
21
52
 
22
- ### Update State
23
-
24
- ```javascript
25
- function updateState(updates) {
53
+ // Update (with sliding window for history)
54
+ function updateState(workDir, updates) {
26
55
  const state = JSON.parse(Read(`${workDir}/state.json`));
27
56
  const newState = {
28
57
  ...state,
@@ -34,344 +63,127 @@ function updateState(updates) {
34
63
  }
35
64
  ```
36
65
 
37
- ## Decision Logic
38
-
39
- ```javascript
40
- function selectNextAction(state) {
41
- // === Termination Checks ===
42
-
43
- // User exit
44
- if (state.status === 'user_exit') return null;
45
-
46
- // Completed
47
- if (state.status === 'completed') return null;
48
-
49
- // Error limit exceeded
50
- if (state.error_count >= state.max_errors) {
51
- return 'action-abort';
52
- }
53
-
54
- // Max iterations exceeded
55
- if (state.iteration_count >= state.max_iterations) {
56
- return 'action-complete';
57
- }
58
-
59
- // === Action Selection ===
60
-
61
- // 1. Not initialized yet
62
- if (state.status === 'pending') {
63
- return 'action-init';
64
- }
65
-
66
- // 1.5. Requirement analysis (在 init 后,diagnosis 前)
67
- if (state.status === 'running' &&
68
- state.completed_actions.includes('action-init') &&
69
- !state.completed_actions.includes('action-analyze-requirements')) {
70
- return 'action-analyze-requirements';
71
- }
72
-
73
- // 1.6. 如果需求分析发现歧义需要澄清,暂停等待用户
74
- if (state.requirement_analysis?.status === 'needs_clarification') {
75
- return null; // 等待用户澄清后继续
76
- }
77
-
78
- // 1.7. 如果需求分析覆盖度不足,优先触发 Gemini 深度分析
79
- if (state.requirement_analysis?.coverage?.status === 'unsatisfied' &&
80
- !state.completed_actions.includes('action-gemini-analysis')) {
81
- return 'action-gemini-analysis';
82
- }
83
-
84
- // 2. Check if Gemini analysis is requested or needed
85
- if (shouldTriggerGeminiAnalysis(state)) {
86
- return 'action-gemini-analysis';
87
- }
88
-
89
- // 3. Check if Gemini analysis is running
90
- if (state.gemini_analysis?.status === 'running') {
91
- // Wait for Gemini analysis to complete
92
- return null; // Orchestrator will be re-triggered when CLI completes
93
- }
94
-
95
- // 4. Run diagnosis in order (only if not completed)
96
- const diagnosisOrder = ['context', 'memory', 'dataflow', 'agent', 'docs', 'token_consumption'];
97
-
98
- for (const diagType of diagnosisOrder) {
99
- if (state.diagnosis[diagType] === null) {
100
- // Check if user wants to skip this diagnosis
101
- if (!state.focus_areas.length || state.focus_areas.includes(diagType)) {
102
- return `action-diagnose-${diagType}`;
103
- }
104
- // For docs diagnosis, also check 'all' focus_area
105
- if (diagType === 'docs' && state.focus_areas.includes('all')) {
106
- return 'action-diagnose-docs';
107
- }
108
- }
109
- }
110
-
111
- // 5. All diagnosis complete, generate report if not done
112
- const allDiagnosisComplete = diagnosisOrder.every(
113
- d => state.diagnosis[d] !== null || !state.focus_areas.includes(d)
114
- );
115
-
116
- if (allDiagnosisComplete && !state.completed_actions.includes('action-generate-report')) {
117
- return 'action-generate-report';
118
- }
119
-
120
- // 6. Report generated, propose fixes if not done
121
- if (state.completed_actions.includes('action-generate-report') &&
122
- state.proposed_fixes.length === 0 &&
123
- state.issues.length > 0) {
124
- return 'action-propose-fixes';
125
- }
126
-
127
- // 7. Fixes proposed, check if user wants to apply
128
- if (state.proposed_fixes.length > 0 && state.pending_fixes.length > 0) {
129
- return 'action-apply-fix';
130
- }
131
-
132
- // 8. Fixes applied, verify
133
- if (state.applied_fixes.length > 0 &&
134
- state.applied_fixes.some(f => f.verification_result === 'pending')) {
135
- return 'action-verify';
136
- }
137
-
138
- // 9. Quality gate check
139
- if (state.quality_gate === 'pass') {
140
- return 'action-complete';
141
- }
142
-
143
- // 10. More iterations needed
144
- if (state.iteration_count < state.max_iterations &&
145
- state.quality_gate !== 'pass' &&
146
- state.issues.some(i => i.severity === 'critical' || i.severity === 'high')) {
147
- // Reset diagnosis for re-evaluation
148
- return 'action-diagnose-context'; // Start new iteration
149
- }
150
-
151
- // 11. Default: complete
152
- return 'action-complete';
153
- }
154
-
155
- /**
156
- * 判断是否需要触发 Gemini CLI 分析
157
- */
158
- function shouldTriggerGeminiAnalysis(state) {
159
- // 已完成 Gemini 分析,不再触发
160
- if (state.gemini_analysis?.status === 'completed') {
161
- return false;
162
- }
163
-
164
- // 用户显式请求
165
- if (state.gemini_analysis_requested === true) {
166
- return true;
167
- }
168
-
169
- // 发现 critical 问题且未进行深度分析
170
- if (state.issues.some(i => i.severity === 'critical') &&
171
- !state.completed_actions.includes('action-gemini-analysis')) {
172
- return true;
173
- }
174
-
175
- // 用户指定了需要 Gemini 分析的 focus_areas
176
- const geminiAreas = ['architecture', 'prompt', 'performance', 'custom'];
177
- if (state.focus_areas.some(area => geminiAreas.includes(area))) {
178
- return true;
179
- }
180
-
181
- // 标准诊断完成但问题未得到解决,需要深度分析
182
- const diagnosisComplete = ['context', 'memory', 'dataflow', 'agent', 'docs'].every(
183
- d => state.diagnosis[d] !== null
184
- );
185
- if (diagnosisComplete &&
186
- state.issues.length > 0 &&
187
- state.iteration_count > 0 &&
188
- !state.completed_actions.includes('action-gemini-analysis')) {
189
- // 第二轮迭代如果问题仍存在,触发 Gemini 分析
190
- return true;
191
- }
192
-
193
- return false;
194
- }
195
- ```
196
-
197
66
  ## Execution Loop
198
67
 
199
68
  ```javascript
200
69
  async function runOrchestrator(workDir) {
201
- console.log('=== Skill Tuning Orchestrator Started ===');
202
-
203
70
  let iteration = 0;
204
- const MAX_LOOP_ITERATIONS = 50; // Safety limit
205
-
206
- while (iteration < MAX_LOOP_ITERATIONS) {
207
- iteration++;
71
+ const MAX_LOOP = 50;
208
72
 
209
- // 1. Read current state
73
+ while (iteration++ < MAX_LOOP) {
74
+ // 1. Read state
210
75
  const state = JSON.parse(Read(`${workDir}/state.json`));
211
- console.log(`[Loop ${iteration}] Status: ${state.status}, Action: ${state.current_action}`);
212
76
 
213
- // 2. Select next action
77
+ // 2. Select action
214
78
  const actionId = selectNextAction(state);
79
+ if (!actionId) break;
215
80
 
216
- if (!actionId) {
217
- console.log('No action selected, terminating orchestrator.');
218
- break;
219
- }
220
-
221
- console.log(`[Loop ${iteration}] Executing: ${actionId}`);
222
-
223
- // 3. Update state: current action
224
- // FIX CTX-001: sliding window for action_history (keep last 10)
225
- updateState({
81
+ // 3. Update: mark current action (sliding window)
82
+ updateState(workDir, {
226
83
  current_action: actionId,
227
84
  action_history: [...state.action_history, {
228
85
  action: actionId,
229
- started_at: new Date().toISOString(),
230
- completed_at: null,
231
- result: null,
232
- output_files: []
233
- }].slice(-10) // Sliding window: prevent unbounded growth
86
+ started_at: new Date().toISOString()
87
+ }].slice(-10) // Keep last 10
234
88
  });
235
89
 
236
90
  // 4. Execute action
237
91
  try {
238
92
  const actionPrompt = Read(`phases/actions/${actionId}.md`);
239
- // FIX CTX-003: Pass state path + key fields only instead of full state
93
+
94
+ // Pass state path + key fields (not full state)
240
95
  const stateKeyInfo = {
241
96
  status: state.status,
242
97
  iteration_count: state.iteration_count,
243
- issues_by_severity: state.issues_by_severity,
244
98
  quality_gate: state.quality_gate,
245
- current_action: state.current_action,
246
- completed_actions: state.completed_actions,
247
- user_issue_description: state.user_issue_description,
248
99
  target_skill: { name: state.target_skill.name, path: state.target_skill.path }
249
100
  };
250
- const stateKeyJson = JSON.stringify(stateKeyInfo, null, 2);
251
101
 
252
102
  const result = await Task({
253
103
  subagent_type: 'universal-executor',
254
104
  run_in_background: false,
255
105
  prompt: `
256
106
  [CONTEXT]
257
- You are executing action "${actionId}" for skill-tuning workflow.
107
+ Action: ${actionId}
258
108
  Work directory: ${workDir}
259
109
 
260
110
  [STATE KEY INFO]
261
- ${stateKeyJson}
111
+ ${JSON.stringify(stateKeyInfo, null, 2)}
262
112
 
263
113
  [FULL STATE PATH]
264
114
  ${workDir}/state.json
265
- (Read full state from this file if you need additional fields)
115
+ (Read full state from this file if needed)
266
116
 
267
117
  [ACTION INSTRUCTIONS]
268
118
  ${actionPrompt}
269
119
 
270
- [OUTPUT REQUIREMENT]
271
- After completing the action:
272
- 1. Write any output files to the work directory
273
- 2. Return a JSON object with:
274
- - stateUpdates: object with state fields to update
275
- - outputFiles: array of files created
276
- - summary: brief description of what was done
120
+ [OUTPUT]
121
+ Return JSON: { stateUpdates: {}, outputFiles: [], summary: "..." }
277
122
  `
278
123
  });
279
124
 
280
- // 5. Parse result and update state
281
- let actionResult;
282
- try {
283
- actionResult = JSON.parse(result);
284
- } catch (e) {
285
- actionResult = {
286
- stateUpdates: {},
287
- outputFiles: [],
288
- summary: result
289
- };
290
- }
291
-
292
- // 6. Update state: action complete
293
- const updatedHistory = [...state.action_history];
294
- updatedHistory[updatedHistory.length - 1] = {
295
- ...updatedHistory[updatedHistory.length - 1],
296
- completed_at: new Date().toISOString(),
297
- result: 'success',
298
- output_files: actionResult.outputFiles || []
299
- };
125
+ // 5. Parse result
126
+ let actionResult = result;
127
+ try { actionResult = JSON.parse(result); } catch {}
300
128
 
301
- updateState({
129
+ // 6. Update: mark complete
130
+ updateState(workDir, {
302
131
  current_action: null,
303
132
  completed_actions: [...state.completed_actions, actionId],
304
- action_history: updatedHistory,
305
133
  ...actionResult.stateUpdates
306
134
  });
307
135
 
308
- console.log(`[Loop ${iteration}] Completed: ${actionId}`);
309
-
310
136
  } catch (error) {
311
- console.log(`[Loop ${iteration}] Error in ${actionId}: ${error.message}`);
312
-
313
- // Error handling
314
- // FIX CTX-002: sliding window for errors (keep last 5)
315
- updateState({
137
+ // Error handling (sliding window for errors)
138
+ updateState(workDir, {
316
139
  current_action: null,
317
140
  errors: [...state.errors, {
318
141
  action: actionId,
319
142
  message: error.message,
320
- timestamp: new Date().toISOString(),
321
- recoverable: true
322
- }].slice(-5), // Sliding window: prevent unbounded growth
143
+ timestamp: new Date().toISOString()
144
+ }].slice(-5), // Keep last 5
323
145
  error_count: state.error_count + 1
324
146
  });
325
147
  }
326
148
  }
327
-
328
- console.log('=== Skill Tuning Orchestrator Finished ===');
329
149
  }
330
150
  ```
331
151
 
332
- ## Action Catalog
333
-
334
- | Action | Purpose | Preconditions | Effects |
335
- |--------|---------|---------------|---------|
336
- | [action-init](actions/action-init.md) | Initialize tuning session | status === 'pending' | Creates work dirs, backup, sets status='running' |
337
- | [action-analyze-requirements](actions/action-analyze-requirements.md) | Analyze user requirements | init completed | Sets requirement_analysis, optimizes focus_areas |
338
- | [action-diagnose-context](actions/action-diagnose-context.md) | Analyze context explosion | status === 'running' | Sets diagnosis.context |
339
- | [action-diagnose-memory](actions/action-diagnose-memory.md) | Analyze long-tail forgetting | status === 'running' | Sets diagnosis.memory |
340
- | [action-diagnose-dataflow](actions/action-diagnose-dataflow.md) | Analyze data flow issues | status === 'running' | Sets diagnosis.dataflow |
341
- | [action-diagnose-agent](actions/action-diagnose-agent.md) | Analyze agent coordination | status === 'running' | Sets diagnosis.agent |
342
- | [action-diagnose-docs](actions/action-diagnose-docs.md) | Analyze documentation structure | status === 'running', focus includes 'docs' | Sets diagnosis.docs |
343
- | [action-gemini-analysis](actions/action-gemini-analysis.md) | Deep analysis via Gemini CLI | User request OR critical issues | Sets gemini_analysis, adds issues |
344
- | [action-generate-report](actions/action-generate-report.md) | Generate consolidated report | All diagnoses complete | Creates tuning-report.md |
345
- | [action-propose-fixes](actions/action-propose-fixes.md) | Generate fix proposals | Report generated, issues > 0 | Sets proposed_fixes |
346
- | [action-apply-fix](actions/action-apply-fix.md) | Apply selected fix | pending_fixes > 0 | Updates applied_fixes |
347
- | [action-verify](actions/action-verify.md) | Verify applied fixes | applied_fixes with pending verification | Updates verification_result |
348
- | [action-complete](actions/action-complete.md) | Finalize session | quality_gate='pass' OR max_iterations | Sets status='completed' |
349
- | [action-abort](actions/action-abort.md) | Abort on errors | error_count >= max_errors | Sets status='failed' |
152
+ ## Action Preconditions
153
+
154
+ | Action | Precondition |
155
+ |--------|-------------|
156
+ | action-init | status='pending' |
157
+ | action-analyze-requirements | Init complete, not done |
158
+ | action-diagnose-* | status='running', focus area includes type |
159
+ | action-gemini-analysis | Requested OR critical issues OR high complexity |
160
+ | action-generate-report | All diagnosis complete |
161
+ | action-propose-fixes | Report generated, issues > 0 |
162
+ | action-apply-fix | pending_fixes > 0 |
163
+ | action-verify | applied_fixes with pending verification |
164
+ | action-complete | Quality gates pass OR max iterations |
165
+ | action-abort | error_count >= max_errors |
350
166
 
351
- ## Termination Conditions
167
+ ## User Interaction Points
352
168
 
353
- - `status === 'completed'`: Normal completion
354
- - `status === 'user_exit'`: User requested exit
355
- - `status === 'failed'`: Unrecoverable error
356
- - `requirement_analysis.status === 'needs_clarification'`: Waiting for user clarification (暂停,非终止)
357
- - `error_count >= max_errors`: Too many errors (default: 3)
358
- - `iteration_count >= max_iterations`: Max iterations reached (default: 5)
359
- - `quality_gate === 'pass'`: All quality criteria met
169
+ 1. **action-init**: Confirm target skill, describe issue
170
+ 2. **action-propose-fixes**: Select which fixes to apply
171
+ 3. **action-verify**: Review verification, decide to continue or stop
172
+ 4. **action-complete**: Review final summary
360
173
 
361
174
  ## Error Recovery
362
175
 
363
- | Error Type | Recovery Strategy |
364
- |------------|-------------------|
176
+ | Error Type | Strategy |
177
+ |------------|----------|
365
178
  | Action execution failed | Retry up to 3 times, then skip |
366
179
  | State parse error | Restore from backup |
367
180
  | File write error | Retry with alternative path |
368
181
  | User abort | Save state and exit gracefully |
369
182
 
370
- ## User Interaction Points
371
-
372
- The orchestrator pauses for user input at these points:
183
+ ## Termination Conditions
373
184
 
374
- 1. **action-init**: Confirm target skill and describe issue
375
- 2. **action-propose-fixes**: Select which fixes to apply
376
- 3. **action-verify**: Review verification results, decide to continue or stop
377
- 4. **action-complete**: Review final summary
185
+ - Normal: `status === 'completed'`, `quality_gate === 'pass'`
186
+ - User: `status === 'user_exit'`
187
+ - Error: `status === 'failed'`, `error_count >= max_errors`
188
+ - Iteration limit: `iteration_count >= max_iterations`
189
+ - Clarification wait: `requirement_analysis.status === 'needs_clarification'` (pause, not terminate)