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.
- package/.claude/CLAUDE.md +6 -8
- package/.claude/agents/action-planning-agent.md +28 -45
- package/.claude/agents/cli-lite-planning-agent.md +93 -1
- package/.claude/agents/code-developer.md +144 -27
- package/.claude/commands/ccw-coordinator.md +175 -21
- package/.claude/commands/ccw-debug.md +832 -0
- package/.claude/commands/ccw.md +90 -9
- package/.claude/commands/cli/cli-init.md +1 -0
- package/.claude/commands/issue/convert-to-plan.md +718 -0
- package/.claude/commands/issue/from-brainstorm.md +382 -0
- package/.claude/commands/memory/tips.md +332 -0
- package/.claude/commands/workflow/analyze-with-file.md +804 -0
- package/.claude/commands/workflow/brainstorm/auto-parallel.md +18 -43
- package/.claude/commands/workflow/brainstorm/role-analysis.md +705 -0
- package/.claude/commands/workflow/brainstorm-with-file.md +1153 -0
- package/.claude/commands/workflow/debug-with-file.md +7 -5
- package/.claude/commands/workflow/execute.md +6 -4
- package/.claude/commands/workflow/lite-plan.md +2 -2
- package/.claude/commands/workflow/plan-verify.md +162 -327
- package/.claude/commands/workflow/plan.md +162 -26
- package/.claude/commands/workflow/replan.md +78 -2
- package/.claude/commands/workflow/{review-fix.md → review-cycle-fix.md} +6 -6
- package/.claude/commands/workflow/review-module-cycle.md +2 -2
- package/.claude/commands/workflow/review-session-cycle.md +2 -2
- package/.claude/commands/workflow/tools/conflict-resolution.md +16 -26
- package/.claude/commands/workflow/tools/context-gather.md +81 -118
- package/.claude/commands/workflow/tools/task-generate-agent.md +94 -10
- package/.claude/skills/ccw-help/command.json +4 -4
- package/.claude/skills/lite-skill-generator/SKILL.md +650 -0
- package/.claude/skills/lite-skill-generator/templates/simple-skill.md +68 -0
- package/.claude/skills/lite-skill-generator/templates/style-guide.md +64 -0
- package/.claude/skills/skill-generator/SKILL.md +277 -85
- package/.claude/skills/skill-generator/phases/01-requirements-discovery.md +4 -15
- package/.claude/skills/skill-generator/phases/02-structure-generation.md +72 -17
- package/.claude/skills/skill-generator/phases/03-phase-generation.md +218 -51
- package/.claude/skills/skill-generator/phases/04-specs-templates.md +111 -41
- package/.claude/skills/skill-generator/phases/05-validation.md +139 -56
- package/.claude/skills/skill-generator/templates/autonomous-action.md +78 -268
- package/.claude/skills/skill-generator/templates/autonomous-orchestrator.md +14 -0
- package/.claude/skills/skill-generator/templates/code-analysis-action.md +12 -0
- package/.claude/skills/skill-generator/templates/llm-action.md +12 -0
- package/.claude/skills/skill-generator/templates/script-template.md +368 -0
- package/.claude/skills/skill-generator/templates/sequential-phase.md +14 -0
- package/.claude/skills/skill-generator/templates/skill-md.md +14 -0
- package/.claude/skills/skill-tuning/SKILL.md +130 -266
- package/.claude/skills/skill-tuning/phases/orchestrator.md +95 -283
- package/.claude/skills/skill-tuning/specs/problem-taxonomy.md +90 -198
- package/.claude/skills/skill-tuning/specs/tuning-strategies.md +193 -1345
- package/.claude/workflows/cli-templates/schemas/plan-verify-agent-schema.json +47 -0
- package/.claude/workflows/cli-templates/schemas/verify-json-schema.json +158 -0
- package/.claude/workflows/cli-tools-usage.md +1 -1
- package/.codex/AGENTS.md +1 -3
- package/.codex/prompts/analyze-with-file.md +607 -0
- package/.codex/prompts/brainstorm-to-cycle.md +455 -0
- package/.codex/prompts/brainstorm-with-file.md +933 -0
- package/.codex/prompts/debug-with-file.md +15 -20
- package/.codex/skills/ccw-cli-tools/SKILL.md +559 -0
- package/ccw/dist/commands/cli.d.ts.map +1 -1
- package/ccw/dist/commands/cli.js +29 -5
- package/ccw/dist/commands/cli.js.map +1 -1
- package/ccw/dist/commands/issue.d.ts +2 -0
- package/ccw/dist/commands/issue.d.ts.map +1 -1
- package/ccw/dist/commands/issue.js +62 -20
- package/ccw/dist/commands/issue.js.map +1 -1
- package/ccw/dist/config/litellm-api-config-manager.d.ts.map +1 -1
- package/ccw/dist/config/litellm-api-config-manager.js +5 -3
- package/ccw/dist/config/litellm-api-config-manager.js.map +1 -1
- package/ccw/dist/config/litellm-provider-models.d.ts +73 -0
- package/ccw/dist/config/litellm-provider-models.d.ts.map +1 -0
- package/ccw/dist/config/litellm-provider-models.js +172 -0
- package/ccw/dist/config/litellm-provider-models.js.map +1 -0
- package/ccw/dist/config/provider-models.d.ts +25 -51
- package/ccw/dist/config/provider-models.d.ts.map +1 -1
- package/ccw/dist/config/provider-models.js +84 -149
- package/ccw/dist/config/provider-models.js.map +1 -1
- package/ccw/dist/config/storage-paths.d.ts.map +1 -1
- package/ccw/dist/config/storage-paths.js +23 -5
- package/ccw/dist/config/storage-paths.js.map +1 -1
- package/ccw/dist/core/auth/csrf-middleware.js +3 -3
- package/ccw/dist/core/auth/csrf-middleware.js.map +1 -1
- package/ccw/dist/core/dashboard-generator.d.ts.map +1 -1
- package/ccw/dist/core/dashboard-generator.js +3 -1
- package/ccw/dist/core/dashboard-generator.js.map +1 -1
- package/ccw/dist/core/routes/claude-routes.d.ts.map +1 -1
- package/ccw/dist/core/routes/claude-routes.js +206 -14
- package/ccw/dist/core/routes/claude-routes.js.map +1 -1
- package/ccw/dist/core/routes/cli-routes.d.ts.map +1 -1
- package/ccw/dist/core/routes/cli-routes.js.map +1 -1
- package/ccw/dist/core/routes/commands-routes.d.ts +7 -0
- package/ccw/dist/core/routes/commands-routes.d.ts.map +1 -0
- package/ccw/dist/core/routes/commands-routes.js +480 -0
- package/ccw/dist/core/routes/commands-routes.js.map +1 -0
- package/ccw/dist/core/routes/model-routes.d.ts +11 -0
- package/ccw/dist/core/routes/model-routes.d.ts.map +1 -0
- package/ccw/dist/core/routes/model-routes.js +112 -0
- package/ccw/dist/core/routes/model-routes.js.map +1 -0
- package/ccw/dist/core/routes/nav-status-routes.d.ts.map +1 -1
- package/ccw/dist/core/routes/nav-status-routes.js +84 -1
- package/ccw/dist/core/routes/nav-status-routes.js.map +1 -1
- package/ccw/dist/core/routes/provider-routes.d.ts +11 -0
- package/ccw/dist/core/routes/provider-routes.d.ts.map +1 -0
- package/ccw/dist/core/routes/provider-routes.js +67 -0
- package/ccw/dist/core/routes/provider-routes.js.map +1 -0
- package/ccw/dist/core/routes/skills-routes.d.ts.map +1 -1
- package/ccw/dist/core/routes/skills-routes.js +219 -7
- package/ccw/dist/core/routes/skills-routes.js.map +1 -1
- package/ccw/dist/core/routes/system-routes.d.ts.map +1 -1
- package/ccw/dist/core/routes/system-routes.js +58 -6
- package/ccw/dist/core/routes/system-routes.js.map +1 -1
- package/ccw/dist/core/server.d.ts.map +1 -1
- package/ccw/dist/core/server.js +13 -0
- package/ccw/dist/core/server.js.map +1 -1
- package/ccw/dist/mcp-server/index.js +2 -2
- package/ccw/dist/mcp-server/index.js.map +1 -1
- package/ccw/dist/tools/claude-cli-tools.d.ts +48 -11
- package/ccw/dist/tools/claude-cli-tools.d.ts.map +1 -1
- package/ccw/dist/tools/claude-cli-tools.js +146 -50
- package/ccw/dist/tools/claude-cli-tools.js.map +1 -1
- package/ccw/dist/tools/cli-config-manager.d.ts +1 -13
- package/ccw/dist/tools/cli-config-manager.d.ts.map +1 -1
- package/ccw/dist/tools/cli-config-manager.js +3 -27
- package/ccw/dist/tools/cli-config-manager.js.map +1 -1
- package/ccw/dist/tools/cli-executor-core.d.ts.map +1 -1
- package/ccw/dist/tools/cli-executor-core.js +7 -2
- package/ccw/dist/tools/cli-executor-core.js.map +1 -1
- package/ccw/dist/tools/cli-executor-state.d.ts.map +1 -1
- package/ccw/dist/tools/cli-history-store.d.ts +11 -0
- package/ccw/dist/tools/cli-history-store.d.ts.map +1 -1
- package/ccw/dist/tools/cli-history-store.js +82 -2
- package/ccw/dist/tools/cli-history-store.js.map +1 -1
- package/ccw/dist/tools/command-registry.d.ts +7 -0
- package/ccw/dist/tools/command-registry.d.ts.map +1 -1
- package/ccw/dist/tools/command-registry.js +14 -1
- package/ccw/dist/tools/command-registry.js.map +1 -1
- package/ccw/dist/tools/generate-module-docs.d.ts.map +1 -1
- package/ccw/dist/tools/generate-module-docs.js +11 -7
- package/ccw/dist/tools/generate-module-docs.js.map +1 -1
- package/ccw/dist/tools/litellm-executor.d.ts +1 -0
- package/ccw/dist/tools/litellm-executor.d.ts.map +1 -1
- package/ccw/dist/tools/litellm-executor.js +11 -9
- package/ccw/dist/tools/litellm-executor.js.map +1 -1
- package/ccw/dist/types/skill-types.d.ts +97 -0
- package/ccw/dist/types/skill-types.d.ts.map +1 -0
- package/ccw/dist/types/skill-types.js +6 -0
- package/ccw/dist/types/skill-types.js.map +1 -0
- package/ccw/src/commands/cli.ts +36 -5
- package/ccw/src/commands/issue.ts +81 -26
- package/ccw/src/config/litellm-api-config-manager.ts +5 -3
- package/ccw/src/config/litellm-provider-models.ts +222 -0
- package/ccw/src/config/provider-models.ts +91 -190
- package/ccw/src/config/storage-paths.ts +20 -5
- package/ccw/src/core/auth/csrf-middleware.ts +3 -3
- package/ccw/src/core/dashboard-generator.ts +3 -1
- package/ccw/src/core/routes/claude-routes.ts +233 -15
- package/ccw/src/core/routes/cli-routes.ts +2 -3
- package/ccw/src/core/routes/commands-routes.ts +620 -0
- package/ccw/src/core/routes/nav-status-routes.ts +95 -1
- package/ccw/src/core/routes/provider-routes.ts +78 -0
- package/ccw/src/core/routes/skills-routes.ts +266 -45
- package/ccw/src/core/routes/system-routes.ts +102 -50
- package/ccw/src/core/server.ts +13 -0
- package/ccw/src/mcp-server/index.ts +2 -2
- package/ccw/src/templates/dashboard-css/18-cli-settings.css +35 -0
- package/ccw/src/templates/dashboard-css/37-commands.css +193 -0
- package/ccw/src/templates/dashboard-js/components/navigation.js +4 -0
- package/ccw/src/templates/dashboard-js/i18n.js +116 -0
- package/ccw/src/templates/dashboard-js/views/cli-manager.js +249 -4
- package/ccw/src/templates/dashboard-js/views/commands-manager.js +503 -0
- package/ccw/src/templates/dashboard-js/views/issue-manager.js +7 -7
- package/ccw/src/templates/dashboard-js/views/mcp-manager.js +2 -7
- package/ccw/src/templates/dashboard-js/views/skills-manager.js +164 -23
- package/ccw/src/templates/dashboard.html +7 -0
- package/ccw/src/tools/claude-cli-tools.ts +170 -56
- package/ccw/src/tools/cli-config-manager.ts +2 -33
- package/ccw/src/tools/cli-executor-core.ts +8 -2
- package/ccw/src/tools/cli-history-store.ts +92 -2
- package/ccw/src/tools/command-registry.ts +16 -1
- package/ccw/src/tools/generate-module-docs.ts +11 -7
- package/ccw/src/tools/litellm-executor.ts +13 -9
- package/ccw/src/types/skill-types.ts +99 -0
- package/package.json +1 -1
- package/.claude/commands/enhance-prompt.md +0 -93
- package/.claude/commands/memory/code-map-memory.md +0 -687
- package/.claude/commands/memory/docs.md +0 -615
- package/.claude/commands/memory/load-skill-memory.md +0 -182
- package/.claude/commands/memory/skill-memory.md +0 -525
- package/.claude/commands/memory/swagger-docs.md +0 -773
- package/.claude/commands/memory/tech-research-rules.md +0 -310
- package/.claude/commands/memory/workflow-skill-memory.md +0 -517
- package/.claude/commands/task/breakdown.md +0 -208
- package/.claude/commands/task/create.md +0 -152
- package/.claude/commands/task/execute.md +0 -270
- package/.claude/commands/task/replan.md +0 -441
- package/.claude/commands/version.md +0 -254
- package/.claude/commands/workflow/action-plan-verify.md +0 -485
- package/.claude/commands/workflow/brainstorm/api-designer.md +0 -587
- package/.claude/commands/workflow/brainstorm/data-architect.md +0 -220
- package/.claude/commands/workflow/brainstorm/product-manager.md +0 -200
- package/.claude/commands/workflow/brainstorm/product-owner.md +0 -200
- package/.claude/commands/workflow/brainstorm/scrum-master.md +0 -200
- package/.claude/commands/workflow/brainstorm/subject-matter-expert.md +0 -200
- package/.claude/commands/workflow/brainstorm/system-architect.md +0 -389
- package/.claude/commands/workflow/brainstorm/ui-designer.md +0 -221
- package/.claude/commands/workflow/brainstorm/ux-expert.md +0 -221
- package/.claude/commands/workflow/debug.md +0 -331
- package/.claude/commands/workflow/develop-with-file.md +0 -1044
- package/.claude/skills/ccw-loop/README.md +0 -303
- package/.claude/skills/skill-generator/templates/script-bash.md +0 -277
- package/.claude/skills/skill-generator/templates/script-python.md +0 -198
- package/.codex/prompts/debug.md +0 -318
- package/ccw/src/core/routes/mcp-routes.ts.backup +0 -549
|
@@ -1,28 +1,57 @@
|
|
|
1
1
|
# Orchestrator
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
State-driven orchestrator for autonomous skill-tuning workflow.
|
|
4
4
|
|
|
5
5
|
## Role
|
|
6
6
|
|
|
7
|
-
|
|
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
|
-
##
|
|
9
|
+
## Decision Logic
|
|
15
10
|
|
|
16
|
-
###
|
|
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
|
-
|
|
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
|
|
205
|
-
|
|
206
|
-
while (iteration < MAX_LOOP_ITERATIONS) {
|
|
207
|
-
iteration++;
|
|
71
|
+
const MAX_LOOP = 50;
|
|
208
72
|
|
|
209
|
-
|
|
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
|
|
77
|
+
// 2. Select action
|
|
214
78
|
const actionId = selectNextAction(state);
|
|
79
|
+
if (!actionId) break;
|
|
215
80
|
|
|
216
|
-
|
|
217
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
107
|
+
Action: ${actionId}
|
|
258
108
|
Work directory: ${workDir}
|
|
259
109
|
|
|
260
110
|
[STATE KEY INFO]
|
|
261
|
-
${
|
|
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
|
|
115
|
+
(Read full state from this file if needed)
|
|
266
116
|
|
|
267
117
|
[ACTION INSTRUCTIONS]
|
|
268
118
|
${actionPrompt}
|
|
269
119
|
|
|
270
|
-
[OUTPUT
|
|
271
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
333
|
-
|
|
334
|
-
| Action |
|
|
335
|
-
|
|
336
|
-
|
|
|
337
|
-
|
|
|
338
|
-
|
|
|
339
|
-
|
|
|
340
|
-
|
|
|
341
|
-
|
|
|
342
|
-
|
|
|
343
|
-
|
|
|
344
|
-
|
|
|
345
|
-
|
|
|
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
|
-
##
|
|
167
|
+
## User Interaction Points
|
|
352
168
|
|
|
353
|
-
-
|
|
354
|
-
-
|
|
355
|
-
-
|
|
356
|
-
|
|
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 |
|
|
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
|
-
##
|
|
371
|
-
|
|
372
|
-
The orchestrator pauses for user input at these points:
|
|
183
|
+
## Termination Conditions
|
|
373
184
|
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
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)
|