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.
- package/.claude/CLAUDE.md +7 -1
- package/.claude/agents/action-planning-agent.md +1 -0
- package/.claude/agents/cli-discuss-agent.md +391 -0
- package/.claude/agents/cli-execution-agent.md +2 -0
- package/.claude/agents/cli-explore-agent.md +2 -1
- package/.claude/agents/cli-lite-planning-agent.md +1 -0
- package/.claude/agents/cli-planning-agent.md +1 -0
- package/.claude/agents/code-developer.md +1 -0
- package/.claude/agents/conceptual-planning-agent.md +2 -0
- package/.claude/agents/context-search-agent.md +1 -0
- package/.claude/agents/debug-explore-agent.md +2 -0
- package/.claude/agents/doc-generator.md +1 -0
- package/.claude/agents/issue-plan-agent.md +2 -1
- package/.claude/agents/issue-queue-agent.md +2 -1
- package/.claude/agents/memory-bridge.md +2 -0
- package/.claude/agents/test-context-search-agent.md +2 -0
- package/.claude/agents/test-fix-agent.md +1 -0
- package/.claude/agents/ui-design-agent.md +2 -0
- package/.claude/agents/universal-executor.md +1 -0
- package/.claude/commands/issue/execute.md +141 -163
- package/.claude/commands/workflow/lite-lite-lite.md +798 -0
- package/.claude/commands/workflow/multi-cli-plan.md +510 -0
- package/.claude/skills/ccw/SKILL.md +262 -372
- package/.claude/skills/ccw/command.json +547 -0
- package/.claude/skills/ccw-help/SKILL.md +46 -107
- package/.claude/skills/ccw-help/command.json +511 -0
- package/.claude/skills/skill-tuning/SKILL.md +303 -0
- package/.claude/skills/skill-tuning/phases/actions/action-abort.md +164 -0
- package/.claude/skills/skill-tuning/phases/actions/action-analyze-requirements.md +406 -0
- package/.claude/skills/skill-tuning/phases/actions/action-apply-fix.md +206 -0
- package/.claude/skills/skill-tuning/phases/actions/action-complete.md +195 -0
- package/.claude/skills/skill-tuning/phases/actions/action-diagnose-agent.md +317 -0
- package/.claude/skills/skill-tuning/phases/actions/action-diagnose-context.md +243 -0
- package/.claude/skills/skill-tuning/phases/actions/action-diagnose-dataflow.md +318 -0
- package/.claude/skills/skill-tuning/phases/actions/action-diagnose-docs.md +299 -0
- package/.claude/skills/skill-tuning/phases/actions/action-diagnose-memory.md +269 -0
- package/.claude/skills/skill-tuning/phases/actions/action-diagnose-token-consumption.md +200 -0
- package/.claude/skills/skill-tuning/phases/actions/action-gemini-analysis.md +322 -0
- package/.claude/skills/skill-tuning/phases/actions/action-generate-report.md +228 -0
- package/.claude/skills/skill-tuning/phases/actions/action-init.md +149 -0
- package/.claude/skills/skill-tuning/phases/actions/action-propose-fixes.md +317 -0
- package/.claude/skills/skill-tuning/phases/actions/action-verify.md +222 -0
- package/.claude/skills/skill-tuning/phases/orchestrator.md +377 -0
- package/.claude/skills/skill-tuning/phases/state-schema.md +378 -0
- package/.claude/skills/skill-tuning/specs/category-mappings.json +284 -0
- package/.claude/skills/skill-tuning/specs/dimension-mapping.md +212 -0
- package/.claude/skills/skill-tuning/specs/problem-taxonomy.md +318 -0
- package/.claude/skills/skill-tuning/specs/quality-gates.md +263 -0
- package/.claude/skills/skill-tuning/specs/skill-authoring-principles.md +189 -0
- package/.claude/skills/skill-tuning/specs/tuning-strategies.md +1537 -0
- package/.claude/skills/skill-tuning/templates/diagnosis-report.md +153 -0
- package/.claude/skills/skill-tuning/templates/fix-proposal.md +204 -0
- package/.claude/workflows/cli-templates/schemas/multi-cli-discussion-schema.json +421 -0
- package/.claude/workflows/cli-tools-usage.md +0 -41
- package/ccw/dist/core/auth/csrf-middleware.d.ts.map +1 -1
- package/ccw/dist/core/auth/csrf-middleware.js +3 -1
- package/ccw/dist/core/auth/csrf-middleware.js.map +1 -1
- package/ccw/dist/core/data-aggregator.d.ts +2 -0
- package/ccw/dist/core/data-aggregator.d.ts.map +1 -1
- package/ccw/dist/core/data-aggregator.js +5 -2
- package/ccw/dist/core/data-aggregator.js.map +1 -1
- package/ccw/dist/core/lite-scanner.d.ts +2 -1
- package/ccw/dist/core/lite-scanner.d.ts.map +1 -1
- package/ccw/dist/core/lite-scanner.js +295 -6
- package/ccw/dist/core/lite-scanner.js.map +1 -1
- package/ccw/dist/core/routes/codexlens/config-handlers.d.ts.map +1 -1
- package/ccw/dist/core/routes/codexlens/config-handlers.js +5 -5
- package/ccw/dist/core/routes/codexlens/config-handlers.js.map +1 -1
- package/ccw/dist/core/routes/session-routes.d.ts.map +1 -1
- package/ccw/dist/core/routes/session-routes.js +166 -48
- package/ccw/dist/core/routes/session-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 +87 -0
- package/ccw/dist/core/routes/system-routes.js.map +1 -1
- package/ccw/dist/core/server.js +2 -2
- package/ccw/dist/core/server.js.map +1 -1
- package/ccw/scripts/IMPLEMENTATION-SUMMARY.md +226 -0
- package/ccw/scripts/QUICK-REFERENCE.md +135 -0
- package/ccw/scripts/README-memory-embedder.md +157 -0
- package/ccw/scripts/__pycache__/memory_embedder.cpython-313.pyc +0 -0
- package/ccw/scripts/__pycache__/test_memory_embedder.cpython-313-pytest-8.4.2.pyc +0 -0
- package/ccw/scripts/memory-embedder-example.ts +184 -0
- package/ccw/scripts/memory_embedder.py +428 -0
- package/ccw/scripts/test_memory_embedder.py +245 -0
- package/ccw/src/core/auth/csrf-middleware.ts +3 -1
- package/ccw/src/core/data-aggregator.ts +7 -2
- package/ccw/src/core/lite-scanner.ts +440 -6
- package/ccw/src/core/routes/codexlens/config-handlers.ts +12 -9
- package/ccw/src/core/routes/session-routes.ts +201 -48
- package/ccw/src/core/routes/system-routes.ts +102 -0
- package/ccw/src/core/server.ts +2 -2
- package/ccw/src/templates/dashboard-css/01-base.css +8 -0
- package/ccw/src/templates/dashboard-css/02-session.css +81 -0
- package/ccw/src/templates/dashboard-css/04-lite-tasks.css +2442 -0
- package/ccw/src/templates/dashboard-css/21-cli-toolmgmt.css +157 -0
- package/ccw/src/templates/dashboard-css/32-issue-manager.css +23 -0
- package/ccw/src/templates/dashboard-js/components/cli-stream-viewer.js +38 -4
- package/ccw/src/templates/dashboard-js/components/hook-manager.js +38 -13
- package/ccw/src/templates/dashboard-js/components/navigation.js +24 -4
- package/ccw/src/templates/dashboard-js/i18n.js +194 -6
- package/ccw/src/templates/dashboard-js/views/api-settings.js +32 -0
- package/ccw/src/templates/dashboard-js/views/claude-manager.js +44 -3
- package/ccw/src/templates/dashboard-js/views/cli-manager.js +303 -31
- package/ccw/src/templates/dashboard-js/views/history.js +44 -6
- package/ccw/src/templates/dashboard-js/views/home.js +1 -0
- package/ccw/src/templates/dashboard-js/views/issue-manager.js +54 -7
- package/ccw/src/templates/dashboard-js/views/lite-tasks.js +1817 -4
- package/ccw/src/templates/dashboard.html +5 -0
- package/package.json +2 -1
- package/.claude/skills/ccw/index/command-capabilities.json +0 -127
- package/.claude/skills/ccw/index/intent-rules.json +0 -136
- package/.claude/skills/ccw/index/workflow-chains.json +0 -451
- package/.claude/skills/ccw/phases/actions/bugfix.md +0 -218
- package/.claude/skills/ccw/phases/actions/coupled.md +0 -194
- package/.claude/skills/ccw/phases/actions/docs.md +0 -93
- package/.claude/skills/ccw/phases/actions/full.md +0 -154
- package/.claude/skills/ccw/phases/actions/issue.md +0 -201
- package/.claude/skills/ccw/phases/actions/rapid.md +0 -104
- package/.claude/skills/ccw/phases/actions/review-fix.md +0 -84
- package/.claude/skills/ccw/phases/actions/tdd.md +0 -66
- package/.claude/skills/ccw/phases/actions/ui.md +0 -79
- package/.claude/skills/ccw/phases/orchestrator.md +0 -435
- package/.claude/skills/ccw/specs/intent-classification.md +0 -336
- package/.claude/skills/ccw-help/index/all-agents.json +0 -82
- package/.claude/skills/ccw-help/index/all-commands.json +0 -882
- package/.claude/skills/ccw-help/index/by-category.json +0 -914
- package/.claude/skills/ccw-help/index/by-use-case.json +0 -896
- package/.claude/skills/ccw-help/index/command-relationships.json +0 -160
- package/.claude/skills/ccw-help/index/essential-commands.json +0 -112
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
# Action: Diagnose Token Consumption
|
|
2
|
+
|
|
3
|
+
Analyze target skill for token consumption inefficiencies and output optimization opportunities.
|
|
4
|
+
|
|
5
|
+
## Purpose
|
|
6
|
+
|
|
7
|
+
Detect patterns that cause excessive token usage:
|
|
8
|
+
- Verbose prompts without compression
|
|
9
|
+
- Large state objects with unnecessary fields
|
|
10
|
+
- Full content passing instead of references
|
|
11
|
+
- Unbounded arrays without sliding windows
|
|
12
|
+
- Redundant file I/O (write-then-read patterns)
|
|
13
|
+
|
|
14
|
+
## Detection Patterns
|
|
15
|
+
|
|
16
|
+
| Pattern ID | Name | Detection Logic | Severity |
|
|
17
|
+
|------------|------|-----------------|----------|
|
|
18
|
+
| TKN-001 | Verbose Prompts | Prompt files > 4KB or high static/variable ratio | medium |
|
|
19
|
+
| TKN-002 | Excessive State Fields | State schema > 15 top-level keys | medium |
|
|
20
|
+
| TKN-003 | Full Content Passing | `Read()` result embedded directly in prompt | high |
|
|
21
|
+
| TKN-004 | Unbounded Arrays | `.push`/`concat` without `.slice(-N)` | high |
|
|
22
|
+
| TKN-005 | Redundant Write→Read | `Write(file)` followed by `Read(file)` | medium |
|
|
23
|
+
|
|
24
|
+
## Execution Steps
|
|
25
|
+
|
|
26
|
+
```javascript
|
|
27
|
+
async function diagnoseTokenConsumption(state, workDir) {
|
|
28
|
+
const issues = [];
|
|
29
|
+
const evidence = [];
|
|
30
|
+
const skillPath = state.target_skill.path;
|
|
31
|
+
|
|
32
|
+
// 1. Scan for verbose prompts (TKN-001)
|
|
33
|
+
const mdFiles = Glob(`${skillPath}/**/*.md`);
|
|
34
|
+
for (const file of mdFiles) {
|
|
35
|
+
const content = Read(file);
|
|
36
|
+
if (content.length > 4000) {
|
|
37
|
+
evidence.push({
|
|
38
|
+
file: file,
|
|
39
|
+
pattern: 'TKN-001',
|
|
40
|
+
severity: 'medium',
|
|
41
|
+
context: `File size: ${content.length} chars (threshold: 4000)`
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// 2. Check state schema field count (TKN-002)
|
|
47
|
+
const stateSchema = Glob(`${skillPath}/**/state-schema.md`)[0];
|
|
48
|
+
if (stateSchema) {
|
|
49
|
+
const schemaContent = Read(stateSchema);
|
|
50
|
+
const fieldMatches = schemaContent.match(/^\s*\w+:/gm) || [];
|
|
51
|
+
if (fieldMatches.length > 15) {
|
|
52
|
+
evidence.push({
|
|
53
|
+
file: stateSchema,
|
|
54
|
+
pattern: 'TKN-002',
|
|
55
|
+
severity: 'medium',
|
|
56
|
+
context: `State has ${fieldMatches.length} fields (threshold: 15)`
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// 3. Detect full content passing (TKN-003)
|
|
62
|
+
const fullContentPattern = /Read\([^)]+\)\s*[\+,]|`\$\{.*Read\(/g;
|
|
63
|
+
for (const file of mdFiles) {
|
|
64
|
+
const content = Read(file);
|
|
65
|
+
const matches = content.match(fullContentPattern);
|
|
66
|
+
if (matches) {
|
|
67
|
+
evidence.push({
|
|
68
|
+
file: file,
|
|
69
|
+
pattern: 'TKN-003',
|
|
70
|
+
severity: 'high',
|
|
71
|
+
context: `Full content passing detected: ${matches[0]}`
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// 4. Detect unbounded arrays (TKN-004)
|
|
77
|
+
const unboundedPattern = /\.(push|concat)\([^)]+\)(?!.*\.slice)/g;
|
|
78
|
+
for (const file of mdFiles) {
|
|
79
|
+
const content = Read(file);
|
|
80
|
+
const matches = content.match(unboundedPattern);
|
|
81
|
+
if (matches) {
|
|
82
|
+
evidence.push({
|
|
83
|
+
file: file,
|
|
84
|
+
pattern: 'TKN-004',
|
|
85
|
+
severity: 'high',
|
|
86
|
+
context: `Unbounded array growth: ${matches[0]}`
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// 5. Detect write-then-read patterns (TKN-005)
|
|
92
|
+
const writeReadPattern = /Write\([^)]+\)[\s\S]{0,100}Read\([^)]+\)/g;
|
|
93
|
+
for (const file of mdFiles) {
|
|
94
|
+
const content = Read(file);
|
|
95
|
+
const matches = content.match(writeReadPattern);
|
|
96
|
+
if (matches) {
|
|
97
|
+
evidence.push({
|
|
98
|
+
file: file,
|
|
99
|
+
pattern: 'TKN-005',
|
|
100
|
+
severity: 'medium',
|
|
101
|
+
context: `Write-then-read pattern detected`
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Calculate severity
|
|
107
|
+
const highCount = evidence.filter(e => e.severity === 'high').length;
|
|
108
|
+
const mediumCount = evidence.filter(e => e.severity === 'medium').length;
|
|
109
|
+
|
|
110
|
+
let severity = 'none';
|
|
111
|
+
if (highCount > 0) severity = 'high';
|
|
112
|
+
else if (mediumCount > 2) severity = 'medium';
|
|
113
|
+
else if (mediumCount > 0) severity = 'low';
|
|
114
|
+
|
|
115
|
+
return {
|
|
116
|
+
status: 'completed',
|
|
117
|
+
issues_found: evidence.length,
|
|
118
|
+
severity: severity,
|
|
119
|
+
execution_time_ms: Date.now() - startTime,
|
|
120
|
+
details: {
|
|
121
|
+
patterns_checked: ['TKN-001', 'TKN-002', 'TKN-003', 'TKN-004', 'TKN-005'],
|
|
122
|
+
patterns_matched: [...new Set(evidence.map(e => e.pattern))],
|
|
123
|
+
evidence: evidence,
|
|
124
|
+
recommendations: generateRecommendations(evidence)
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function generateRecommendations(evidence) {
|
|
130
|
+
const recs = [];
|
|
131
|
+
const patterns = [...new Set(evidence.map(e => e.pattern))];
|
|
132
|
+
|
|
133
|
+
if (patterns.includes('TKN-001')) {
|
|
134
|
+
recs.push('Apply prompt_compression: Extract static instructions to templates, use placeholders');
|
|
135
|
+
}
|
|
136
|
+
if (patterns.includes('TKN-002')) {
|
|
137
|
+
recs.push('Apply state_field_reduction: Remove debug/cache fields, consolidate related fields');
|
|
138
|
+
}
|
|
139
|
+
if (patterns.includes('TKN-003')) {
|
|
140
|
+
recs.push('Apply lazy_loading: Pass file paths instead of content, let agents read if needed');
|
|
141
|
+
}
|
|
142
|
+
if (patterns.includes('TKN-004')) {
|
|
143
|
+
recs.push('Apply sliding_window: Add .slice(-N) to array operations to bound growth');
|
|
144
|
+
}
|
|
145
|
+
if (patterns.includes('TKN-005')) {
|
|
146
|
+
recs.push('Apply output_minimization: Use in-memory data passing, eliminate temporary files');
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return recs;
|
|
150
|
+
}
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## Output
|
|
154
|
+
|
|
155
|
+
Write diagnosis result to `${workDir}/diagnosis/token-consumption-diagnosis.json`:
|
|
156
|
+
|
|
157
|
+
```json
|
|
158
|
+
{
|
|
159
|
+
"status": "completed",
|
|
160
|
+
"issues_found": 3,
|
|
161
|
+
"severity": "medium",
|
|
162
|
+
"execution_time_ms": 1500,
|
|
163
|
+
"details": {
|
|
164
|
+
"patterns_checked": ["TKN-001", "TKN-002", "TKN-003", "TKN-004", "TKN-005"],
|
|
165
|
+
"patterns_matched": ["TKN-001", "TKN-003"],
|
|
166
|
+
"evidence": [
|
|
167
|
+
{
|
|
168
|
+
"file": "phases/orchestrator.md",
|
|
169
|
+
"pattern": "TKN-001",
|
|
170
|
+
"severity": "medium",
|
|
171
|
+
"context": "File size: 5200 chars (threshold: 4000)"
|
|
172
|
+
}
|
|
173
|
+
],
|
|
174
|
+
"recommendations": [
|
|
175
|
+
"Apply prompt_compression: Extract static instructions to templates"
|
|
176
|
+
]
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
## State Update
|
|
182
|
+
|
|
183
|
+
```javascript
|
|
184
|
+
updateState({
|
|
185
|
+
diagnosis: {
|
|
186
|
+
...state.diagnosis,
|
|
187
|
+
token_consumption: diagnosisResult
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
## Fix Strategies Mapping
|
|
193
|
+
|
|
194
|
+
| Pattern | Strategy | Implementation |
|
|
195
|
+
|---------|----------|----------------|
|
|
196
|
+
| TKN-001 | prompt_compression | Extract static text to variables, use template inheritance |
|
|
197
|
+
| TKN-002 | state_field_reduction | Audit and consolidate fields, remove non-essential data |
|
|
198
|
+
| TKN-003 | lazy_loading | Pass paths instead of content, agents load when needed |
|
|
199
|
+
| TKN-004 | sliding_window | Add `.slice(-N)` after push/concat operations |
|
|
200
|
+
| TKN-005 | output_minimization | Use return values instead of file relay |
|
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
# Action: Gemini Analysis
|
|
2
|
+
|
|
3
|
+
动态调用 Gemini CLI 进行深度分析,根据用户需求或诊断结果选择分析类型。
|
|
4
|
+
|
|
5
|
+
## Role
|
|
6
|
+
|
|
7
|
+
- 接收用户指定的分析需求或从诊断结果推断需求
|
|
8
|
+
- 构建适当的 CLI 命令
|
|
9
|
+
- 执行分析并解析结果
|
|
10
|
+
- 更新状态以供后续动作使用
|
|
11
|
+
|
|
12
|
+
## Preconditions
|
|
13
|
+
|
|
14
|
+
- `state.status === 'running'`
|
|
15
|
+
- 满足以下任一条件:
|
|
16
|
+
- `state.gemini_analysis_requested === true` (用户请求)
|
|
17
|
+
- `state.issues.some(i => i.severity === 'critical')` (发现严重问题)
|
|
18
|
+
- `state.analysis_type !== null` (已指定分析类型)
|
|
19
|
+
|
|
20
|
+
## Analysis Types
|
|
21
|
+
|
|
22
|
+
### 1. root_cause - 问题根因分析
|
|
23
|
+
|
|
24
|
+
针对用户描述的问题进行深度分析。
|
|
25
|
+
|
|
26
|
+
```javascript
|
|
27
|
+
const analysisPrompt = `
|
|
28
|
+
PURPOSE: Identify root cause of skill execution issue: ${state.user_issue_description}
|
|
29
|
+
TASK:
|
|
30
|
+
• Analyze skill structure at: ${state.target_skill.path}
|
|
31
|
+
• Identify anti-patterns in phase files
|
|
32
|
+
• Trace data flow through state management
|
|
33
|
+
• Check agent coordination patterns
|
|
34
|
+
MODE: analysis
|
|
35
|
+
CONTEXT: @**/*.md
|
|
36
|
+
EXPECTED: JSON with structure:
|
|
37
|
+
{
|
|
38
|
+
"root_causes": [
|
|
39
|
+
{ "id": "RC-001", "description": "...", "severity": "high", "evidence": ["file:line"] }
|
|
40
|
+
],
|
|
41
|
+
"patterns_found": [
|
|
42
|
+
{ "pattern": "...", "type": "anti-pattern|best-practice", "locations": [] }
|
|
43
|
+
],
|
|
44
|
+
"recommendations": [
|
|
45
|
+
{ "priority": 1, "action": "...", "rationale": "..." }
|
|
46
|
+
]
|
|
47
|
+
}
|
|
48
|
+
RULES: Focus on execution flow, state management, agent coordination
|
|
49
|
+
`;
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### 2. architecture - 架构审查
|
|
53
|
+
|
|
54
|
+
评估 skill 的整体架构设计。
|
|
55
|
+
|
|
56
|
+
```javascript
|
|
57
|
+
const analysisPrompt = `
|
|
58
|
+
PURPOSE: Review skill architecture for: ${state.target_skill.name}
|
|
59
|
+
TASK:
|
|
60
|
+
• Evaluate phase decomposition and responsibility separation
|
|
61
|
+
• Check state schema design and data flow
|
|
62
|
+
• Assess agent coordination and error handling
|
|
63
|
+
• Review scalability and maintainability
|
|
64
|
+
MODE: analysis
|
|
65
|
+
CONTEXT: @**/*.md
|
|
66
|
+
EXPECTED: Markdown report with sections:
|
|
67
|
+
- Executive Summary
|
|
68
|
+
- Phase Architecture Assessment
|
|
69
|
+
- State Management Evaluation
|
|
70
|
+
- Agent Coordination Analysis
|
|
71
|
+
- Improvement Recommendations (prioritized)
|
|
72
|
+
RULES: Focus on modularity, extensibility, maintainability
|
|
73
|
+
`;
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### 3. prompt_optimization - 提示词优化
|
|
77
|
+
|
|
78
|
+
分析和优化 phase 中的提示词。
|
|
79
|
+
|
|
80
|
+
```javascript
|
|
81
|
+
const analysisPrompt = `
|
|
82
|
+
PURPOSE: Optimize prompts in skill phases for better output quality
|
|
83
|
+
TASK:
|
|
84
|
+
• Analyze existing prompts for clarity and specificity
|
|
85
|
+
• Identify ambiguous instructions
|
|
86
|
+
• Check output format specifications
|
|
87
|
+
• Evaluate constraint communication
|
|
88
|
+
MODE: analysis
|
|
89
|
+
CONTEXT: @phases/**/*.md
|
|
90
|
+
EXPECTED: JSON with structure:
|
|
91
|
+
{
|
|
92
|
+
"prompt_issues": [
|
|
93
|
+
{ "file": "...", "issue": "...", "severity": "...", "suggestion": "..." }
|
|
94
|
+
],
|
|
95
|
+
"optimized_prompts": [
|
|
96
|
+
{ "file": "...", "original": "...", "optimized": "...", "rationale": "..." }
|
|
97
|
+
]
|
|
98
|
+
}
|
|
99
|
+
RULES: Preserve intent, improve clarity, add structured output requirements
|
|
100
|
+
`;
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### 4. performance - 性能分析
|
|
104
|
+
|
|
105
|
+
分析 Token 消耗和执行效率。
|
|
106
|
+
|
|
107
|
+
```javascript
|
|
108
|
+
const analysisPrompt = `
|
|
109
|
+
PURPOSE: Analyze performance bottlenecks in skill execution
|
|
110
|
+
TASK:
|
|
111
|
+
• Estimate token consumption per phase
|
|
112
|
+
• Identify redundant data passing
|
|
113
|
+
• Check for unnecessary full-content transfers
|
|
114
|
+
• Evaluate caching opportunities
|
|
115
|
+
MODE: analysis
|
|
116
|
+
CONTEXT: @**/*.md
|
|
117
|
+
EXPECTED: JSON with structure:
|
|
118
|
+
{
|
|
119
|
+
"token_estimates": [
|
|
120
|
+
{ "phase": "...", "estimated_tokens": 1000, "breakdown": {} }
|
|
121
|
+
],
|
|
122
|
+
"bottlenecks": [
|
|
123
|
+
{ "type": "...", "location": "...", "impact": "high|medium|low", "fix": "..." }
|
|
124
|
+
],
|
|
125
|
+
"optimization_suggestions": []
|
|
126
|
+
}
|
|
127
|
+
RULES: Focus on token efficiency, reduce redundancy
|
|
128
|
+
`;
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### 5. custom - 自定义分析
|
|
132
|
+
|
|
133
|
+
用户指定的自定义分析需求。
|
|
134
|
+
|
|
135
|
+
```javascript
|
|
136
|
+
const analysisPrompt = `
|
|
137
|
+
PURPOSE: ${state.custom_analysis_purpose}
|
|
138
|
+
TASK: ${state.custom_analysis_tasks}
|
|
139
|
+
MODE: analysis
|
|
140
|
+
CONTEXT: @**/*.md
|
|
141
|
+
EXPECTED: ${state.custom_analysis_expected}
|
|
142
|
+
RULES: ${state.custom_analysis_rules || 'Follow best practices'}
|
|
143
|
+
`;
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## Execution
|
|
147
|
+
|
|
148
|
+
```javascript
|
|
149
|
+
async function executeGeminiAnalysis(state, workDir) {
|
|
150
|
+
// 1. 确定分析类型
|
|
151
|
+
const analysisType = state.analysis_type || determineAnalysisType(state);
|
|
152
|
+
|
|
153
|
+
// 2. 构建 prompt
|
|
154
|
+
const prompt = buildAnalysisPrompt(analysisType, state);
|
|
155
|
+
|
|
156
|
+
// 3. 构建 CLI 命令
|
|
157
|
+
const cliCommand = `ccw cli -p "${escapeForShell(prompt)}" --tool gemini --mode analysis --cd "${state.target_skill.path}"`;
|
|
158
|
+
|
|
159
|
+
console.log(`Executing Gemini analysis: ${analysisType}`);
|
|
160
|
+
console.log(`Command: ${cliCommand}`);
|
|
161
|
+
|
|
162
|
+
// 4. 执行 CLI (后台运行)
|
|
163
|
+
const result = Bash({
|
|
164
|
+
command: cliCommand,
|
|
165
|
+
run_in_background: true,
|
|
166
|
+
timeout: 300000 // 5 minutes
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
// 5. 等待结果
|
|
170
|
+
// 注意: 根据 CLAUDE.md 指引,CLI 后台执行后应停止轮询
|
|
171
|
+
// 结果会在 CLI 完成后写入 state
|
|
172
|
+
|
|
173
|
+
return {
|
|
174
|
+
stateUpdates: {
|
|
175
|
+
gemini_analysis: {
|
|
176
|
+
type: analysisType,
|
|
177
|
+
status: 'running',
|
|
178
|
+
started_at: new Date().toISOString(),
|
|
179
|
+
task_id: result.task_id
|
|
180
|
+
}
|
|
181
|
+
},
|
|
182
|
+
outputFiles: [],
|
|
183
|
+
summary: `Gemini ${analysisType} analysis started in background`
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function determineAnalysisType(state) {
|
|
188
|
+
// 根据状态推断分析类型
|
|
189
|
+
if (state.user_issue_description && state.user_issue_description.length > 100) {
|
|
190
|
+
return 'root_cause';
|
|
191
|
+
}
|
|
192
|
+
if (state.issues.some(i => i.severity === 'critical')) {
|
|
193
|
+
return 'root_cause';
|
|
194
|
+
}
|
|
195
|
+
if (state.focus_areas.includes('architecture')) {
|
|
196
|
+
return 'architecture';
|
|
197
|
+
}
|
|
198
|
+
if (state.focus_areas.includes('prompt')) {
|
|
199
|
+
return 'prompt_optimization';
|
|
200
|
+
}
|
|
201
|
+
if (state.focus_areas.includes('performance')) {
|
|
202
|
+
return 'performance';
|
|
203
|
+
}
|
|
204
|
+
return 'root_cause'; // 默认
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function buildAnalysisPrompt(type, state) {
|
|
208
|
+
const templates = {
|
|
209
|
+
root_cause: () => `
|
|
210
|
+
PURPOSE: Identify root cause of skill execution issue: ${state.user_issue_description}
|
|
211
|
+
TASK: • Analyze skill structure • Identify anti-patterns • Trace data flow issues • Check agent coordination
|
|
212
|
+
MODE: analysis
|
|
213
|
+
CONTEXT: @**/*.md
|
|
214
|
+
EXPECTED: JSON { root_causes: [], patterns_found: [], recommendations: [] }
|
|
215
|
+
RULES: Focus on execution flow, be specific about file:line locations
|
|
216
|
+
`,
|
|
217
|
+
architecture: () => `
|
|
218
|
+
PURPOSE: Review skill architecture for ${state.target_skill.name}
|
|
219
|
+
TASK: • Evaluate phase decomposition • Check state design • Assess agent coordination • Review extensibility
|
|
220
|
+
MODE: analysis
|
|
221
|
+
CONTEXT: @**/*.md
|
|
222
|
+
EXPECTED: Markdown architecture assessment report
|
|
223
|
+
RULES: Focus on modularity and maintainability
|
|
224
|
+
`,
|
|
225
|
+
prompt_optimization: () => `
|
|
226
|
+
PURPOSE: Optimize prompts in skill for better output quality
|
|
227
|
+
TASK: • Analyze prompt clarity • Check output specifications • Evaluate constraint handling
|
|
228
|
+
MODE: analysis
|
|
229
|
+
CONTEXT: @phases/**/*.md
|
|
230
|
+
EXPECTED: JSON { prompt_issues: [], optimized_prompts: [] }
|
|
231
|
+
RULES: Preserve intent, improve clarity
|
|
232
|
+
`,
|
|
233
|
+
performance: () => `
|
|
234
|
+
PURPOSE: Analyze performance bottlenecks in skill
|
|
235
|
+
TASK: • Estimate token consumption • Identify redundancy • Check data transfer efficiency
|
|
236
|
+
MODE: analysis
|
|
237
|
+
CONTEXT: @**/*.md
|
|
238
|
+
EXPECTED: JSON { token_estimates: [], bottlenecks: [], optimization_suggestions: [] }
|
|
239
|
+
RULES: Focus on token efficiency
|
|
240
|
+
`,
|
|
241
|
+
custom: () => `
|
|
242
|
+
PURPOSE: ${state.custom_analysis_purpose}
|
|
243
|
+
TASK: ${state.custom_analysis_tasks}
|
|
244
|
+
MODE: analysis
|
|
245
|
+
CONTEXT: @**/*.md
|
|
246
|
+
EXPECTED: ${state.custom_analysis_expected}
|
|
247
|
+
RULES: ${state.custom_analysis_rules || 'Best practices'}
|
|
248
|
+
`
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
return templates[type]();
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
function escapeForShell(str) {
|
|
255
|
+
// 转义 shell 特殊字符
|
|
256
|
+
return str.replace(/"/g, '\\"').replace(/\$/g, '\\$').replace(/`/g, '\\`');
|
|
257
|
+
}
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
## Output
|
|
261
|
+
|
|
262
|
+
### State Updates
|
|
263
|
+
|
|
264
|
+
```javascript
|
|
265
|
+
{
|
|
266
|
+
gemini_analysis: {
|
|
267
|
+
type: 'root_cause' | 'architecture' | 'prompt_optimization' | 'performance' | 'custom',
|
|
268
|
+
status: 'running' | 'completed' | 'failed',
|
|
269
|
+
started_at: '2024-01-01T00:00:00Z',
|
|
270
|
+
completed_at: '2024-01-01T00:05:00Z',
|
|
271
|
+
task_id: 'xxx',
|
|
272
|
+
result: { /* 分析结果 */ },
|
|
273
|
+
error: null
|
|
274
|
+
},
|
|
275
|
+
// 分析结果合并到 issues
|
|
276
|
+
issues: [
|
|
277
|
+
...state.issues,
|
|
278
|
+
...newIssuesFromAnalysis
|
|
279
|
+
]
|
|
280
|
+
}
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
### Output Files
|
|
284
|
+
|
|
285
|
+
- `${workDir}/diagnosis/gemini-analysis-${type}.json` - 原始分析结果
|
|
286
|
+
- `${workDir}/diagnosis/gemini-analysis-${type}.md` - 格式化报告
|
|
287
|
+
|
|
288
|
+
## Post-Execution
|
|
289
|
+
|
|
290
|
+
分析完成后:
|
|
291
|
+
1. 解析 CLI 输出为结构化数据
|
|
292
|
+
2. 提取新发现的 issues 合并到 state.issues
|
|
293
|
+
3. 更新 recommendations 到 state
|
|
294
|
+
4. 触发下一步动作 (通常是 action-generate-report 或 action-propose-fixes)
|
|
295
|
+
|
|
296
|
+
## Error Handling
|
|
297
|
+
|
|
298
|
+
| Error | Recovery |
|
|
299
|
+
|-------|----------|
|
|
300
|
+
| CLI 超时 | 重试一次,仍失败则跳过 Gemini 分析 |
|
|
301
|
+
| 解析失败 | 保存原始输出,手动处理 |
|
|
302
|
+
| 无结果 | 标记为 skipped,继续流程 |
|
|
303
|
+
|
|
304
|
+
## User Interaction
|
|
305
|
+
|
|
306
|
+
如果 `state.analysis_type === null` 且无法自动推断,询问用户:
|
|
307
|
+
|
|
308
|
+
```javascript
|
|
309
|
+
AskUserQuestion({
|
|
310
|
+
questions: [{
|
|
311
|
+
question: '请选择 Gemini 分析类型',
|
|
312
|
+
header: '分析类型',
|
|
313
|
+
options: [
|
|
314
|
+
{ label: '问题根因分析', description: '深度分析用户描述的问题' },
|
|
315
|
+
{ label: '架构审查', description: '评估整体架构设计' },
|
|
316
|
+
{ label: '提示词优化', description: '分析和优化 phase 提示词' },
|
|
317
|
+
{ label: '性能分析', description: '分析 Token 消耗和执行效率' }
|
|
318
|
+
],
|
|
319
|
+
multiSelect: false
|
|
320
|
+
}]
|
|
321
|
+
});
|
|
322
|
+
```
|