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,263 @@
|
|
|
1
|
+
# Quality Gates
|
|
2
|
+
|
|
3
|
+
Quality thresholds and verification criteria for skill tuning.
|
|
4
|
+
|
|
5
|
+
## When to Use
|
|
6
|
+
|
|
7
|
+
| Phase | Usage | Section |
|
|
8
|
+
|-------|-------|---------|
|
|
9
|
+
| action-generate-report | Calculate quality score | Scoring |
|
|
10
|
+
| action-verify | Check quality gates | Gate Definitions |
|
|
11
|
+
| action-complete | Final assessment | Pass Criteria |
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## Quality Dimensions
|
|
16
|
+
|
|
17
|
+
### 1. Issue Severity Distribution (40%)
|
|
18
|
+
|
|
19
|
+
Measures the severity profile of identified issues.
|
|
20
|
+
|
|
21
|
+
| Metric | Weight | Calculation |
|
|
22
|
+
|--------|--------|-------------|
|
|
23
|
+
| Critical Issues | -25 each | High penalty |
|
|
24
|
+
| High Issues | -15 each | Significant penalty |
|
|
25
|
+
| Medium Issues | -5 each | Moderate penalty |
|
|
26
|
+
| Low Issues | -1 each | Minor penalty |
|
|
27
|
+
|
|
28
|
+
**Score Calculation**:
|
|
29
|
+
```javascript
|
|
30
|
+
function calculateSeverityScore(issues) {
|
|
31
|
+
const weights = { critical: 25, high: 15, medium: 5, low: 1 };
|
|
32
|
+
const deductions = issues.reduce((sum, issue) =>
|
|
33
|
+
sum + (weights[issue.severity] || 0), 0);
|
|
34
|
+
return Math.max(0, 100 - deductions);
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### 2. Fix Effectiveness (30%)
|
|
39
|
+
|
|
40
|
+
Measures success rate of applied fixes.
|
|
41
|
+
|
|
42
|
+
| Metric | Weight | Threshold |
|
|
43
|
+
|--------|--------|-----------|
|
|
44
|
+
| Fixes Verified Pass | +30 | > 80% pass rate |
|
|
45
|
+
| Fixes Verified Fail | -20 | < 50% triggers review |
|
|
46
|
+
| Issues Resolved | +10 | Per resolved issue |
|
|
47
|
+
|
|
48
|
+
**Score Calculation**:
|
|
49
|
+
```javascript
|
|
50
|
+
function calculateFixScore(appliedFixes) {
|
|
51
|
+
const total = appliedFixes.length;
|
|
52
|
+
if (total === 0) return 100; // No fixes needed = good
|
|
53
|
+
|
|
54
|
+
const passed = appliedFixes.filter(f => f.verification_result === 'pass').length;
|
|
55
|
+
return Math.round((passed / total) * 100);
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### 3. Coverage Completeness (20%)
|
|
60
|
+
|
|
61
|
+
Measures diagnosis coverage across all areas.
|
|
62
|
+
|
|
63
|
+
| Metric | Weight | Threshold |
|
|
64
|
+
|--------|--------|-----------|
|
|
65
|
+
| All 4 diagnosis complete | +20 | Full coverage |
|
|
66
|
+
| 3 diagnosis complete | +15 | Good coverage |
|
|
67
|
+
| 2 diagnosis complete | +10 | Partial coverage |
|
|
68
|
+
| < 2 diagnosis complete | +0 | Insufficient |
|
|
69
|
+
|
|
70
|
+
### 4. Iteration Efficiency (10%)
|
|
71
|
+
|
|
72
|
+
Measures how quickly issues are resolved.
|
|
73
|
+
|
|
74
|
+
| Metric | Weight | Threshold |
|
|
75
|
+
|--------|--------|-----------|
|
|
76
|
+
| Resolved in 1 iteration | +10 | Excellent |
|
|
77
|
+
| Resolved in 2 iterations | +7 | Good |
|
|
78
|
+
| Resolved in 3 iterations | +4 | Acceptable |
|
|
79
|
+
| > 3 iterations | +0 | Needs improvement |
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
## Gate Definitions
|
|
84
|
+
|
|
85
|
+
### Gate: PASS
|
|
86
|
+
|
|
87
|
+
**Threshold**: Quality Score >= 80 AND Critical Issues = 0 AND High Issues <= 2
|
|
88
|
+
|
|
89
|
+
**Meaning**: Skill is production-ready with minor issues.
|
|
90
|
+
|
|
91
|
+
**Actions**:
|
|
92
|
+
- Complete tuning session
|
|
93
|
+
- Generate summary report
|
|
94
|
+
- No further fixes required
|
|
95
|
+
|
|
96
|
+
### Gate: REVIEW
|
|
97
|
+
|
|
98
|
+
**Threshold**: Quality Score 60-79 OR High Issues 3-5
|
|
99
|
+
|
|
100
|
+
**Meaning**: Skill has issues requiring attention.
|
|
101
|
+
|
|
102
|
+
**Actions**:
|
|
103
|
+
- Review remaining issues
|
|
104
|
+
- Apply additional fixes if possible
|
|
105
|
+
- May require manual intervention
|
|
106
|
+
|
|
107
|
+
### Gate: FAIL
|
|
108
|
+
|
|
109
|
+
**Threshold**: Quality Score < 60 OR Critical Issues > 0 OR High Issues > 5
|
|
110
|
+
|
|
111
|
+
**Meaning**: Skill has serious issues blocking deployment.
|
|
112
|
+
|
|
113
|
+
**Actions**:
|
|
114
|
+
- Must fix critical issues
|
|
115
|
+
- Re-run diagnosis after fixes
|
|
116
|
+
- Consider architectural review
|
|
117
|
+
|
|
118
|
+
---
|
|
119
|
+
|
|
120
|
+
## Quality Score Calculation
|
|
121
|
+
|
|
122
|
+
```javascript
|
|
123
|
+
function calculateQualityScore(state) {
|
|
124
|
+
// Dimension 1: Severity (40%)
|
|
125
|
+
const severityScore = calculateSeverityScore(state.issues);
|
|
126
|
+
|
|
127
|
+
// Dimension 2: Fix Effectiveness (30%)
|
|
128
|
+
const fixScore = calculateFixScore(state.applied_fixes);
|
|
129
|
+
|
|
130
|
+
// Dimension 3: Coverage (20%)
|
|
131
|
+
const diagnosisCount = Object.values(state.diagnosis)
|
|
132
|
+
.filter(d => d !== null).length;
|
|
133
|
+
const coverageScore = [0, 0, 10, 15, 20][diagnosisCount] || 0;
|
|
134
|
+
|
|
135
|
+
// Dimension 4: Efficiency (10%)
|
|
136
|
+
const efficiencyScore = state.iteration_count <= 1 ? 10 :
|
|
137
|
+
state.iteration_count <= 2 ? 7 :
|
|
138
|
+
state.iteration_count <= 3 ? 4 : 0;
|
|
139
|
+
|
|
140
|
+
// Weighted total
|
|
141
|
+
const total = (severityScore * 0.4) +
|
|
142
|
+
(fixScore * 0.3) +
|
|
143
|
+
(coverageScore * 1.0) + // Already scaled to 20
|
|
144
|
+
(efficiencyScore * 1.0); // Already scaled to 10
|
|
145
|
+
|
|
146
|
+
return Math.round(total);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function determineQualityGate(state) {
|
|
150
|
+
const score = calculateQualityScore(state);
|
|
151
|
+
const criticalCount = state.issues.filter(i => i.severity === 'critical').length;
|
|
152
|
+
const highCount = state.issues.filter(i => i.severity === 'high').length;
|
|
153
|
+
|
|
154
|
+
if (criticalCount > 0) return 'fail';
|
|
155
|
+
if (highCount > 5) return 'fail';
|
|
156
|
+
if (score < 60) return 'fail';
|
|
157
|
+
|
|
158
|
+
if (highCount > 2) return 'review';
|
|
159
|
+
if (score < 80) return 'review';
|
|
160
|
+
|
|
161
|
+
return 'pass';
|
|
162
|
+
}
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
---
|
|
166
|
+
|
|
167
|
+
## Verification Criteria
|
|
168
|
+
|
|
169
|
+
### For Each Issue Type
|
|
170
|
+
|
|
171
|
+
#### Context Explosion Issues
|
|
172
|
+
- [ ] Token count does not grow unbounded
|
|
173
|
+
- [ ] History limited to reasonable size
|
|
174
|
+
- [ ] No full content in prompts (paths used instead)
|
|
175
|
+
- [ ] Agent returns are compact
|
|
176
|
+
|
|
177
|
+
#### Long-tail Forgetting Issues
|
|
178
|
+
- [ ] Constraints visible in all phase prompts
|
|
179
|
+
- [ ] State schema includes requirements field
|
|
180
|
+
- [ ] Checkpoints exist at key milestones
|
|
181
|
+
- [ ] Output matches original constraints
|
|
182
|
+
|
|
183
|
+
#### Data Flow Issues
|
|
184
|
+
- [ ] Single state.json after execution
|
|
185
|
+
- [ ] No orphan state files
|
|
186
|
+
- [ ] Schema validation active
|
|
187
|
+
- [ ] Consistent field naming
|
|
188
|
+
|
|
189
|
+
#### Agent Coordination Issues
|
|
190
|
+
- [ ] All Task calls have error handling
|
|
191
|
+
- [ ] Agent results validated before use
|
|
192
|
+
- [ ] No nested agent calls
|
|
193
|
+
- [ ] Tool declarations match usage
|
|
194
|
+
|
|
195
|
+
---
|
|
196
|
+
|
|
197
|
+
## Iteration Control
|
|
198
|
+
|
|
199
|
+
### Max Iterations
|
|
200
|
+
|
|
201
|
+
Default: 5 iterations
|
|
202
|
+
|
|
203
|
+
**Rationale**:
|
|
204
|
+
- Each iteration may introduce new issues
|
|
205
|
+
- Diminishing returns after 3-4 iterations
|
|
206
|
+
- Prevents infinite loops
|
|
207
|
+
|
|
208
|
+
### Iteration Exit Criteria
|
|
209
|
+
|
|
210
|
+
```javascript
|
|
211
|
+
function shouldContinueIteration(state) {
|
|
212
|
+
// Exit if quality gate passed
|
|
213
|
+
if (state.quality_gate === 'pass') return false;
|
|
214
|
+
|
|
215
|
+
// Exit if max iterations reached
|
|
216
|
+
if (state.iteration_count >= state.max_iterations) return false;
|
|
217
|
+
|
|
218
|
+
// Exit if no improvement in last 2 iterations
|
|
219
|
+
if (state.iteration_count >= 2) {
|
|
220
|
+
const recentHistory = state.action_history.slice(-10);
|
|
221
|
+
const issuesResolvedRecently = recentHistory.filter(a =>
|
|
222
|
+
a.action === 'action-verify' && a.result === 'success'
|
|
223
|
+
).length;
|
|
224
|
+
|
|
225
|
+
if (issuesResolvedRecently === 0) {
|
|
226
|
+
console.log('No progress in recent iterations, stopping.');
|
|
227
|
+
return false;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// Continue if critical/high issues remain
|
|
232
|
+
const hasUrgentIssues = state.issues.some(i =>
|
|
233
|
+
i.severity === 'critical' || i.severity === 'high'
|
|
234
|
+
);
|
|
235
|
+
|
|
236
|
+
return hasUrgentIssues;
|
|
237
|
+
}
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
---
|
|
241
|
+
|
|
242
|
+
## Reporting Format
|
|
243
|
+
|
|
244
|
+
### Quality Summary Table
|
|
245
|
+
|
|
246
|
+
| Dimension | Score | Weight | Weighted |
|
|
247
|
+
|-----------|-------|--------|----------|
|
|
248
|
+
| Severity Distribution | {score}/100 | 40% | {weighted} |
|
|
249
|
+
| Fix Effectiveness | {score}/100 | 30% | {weighted} |
|
|
250
|
+
| Coverage Completeness | {score}/20 | 20% | {score} |
|
|
251
|
+
| Iteration Efficiency | {score}/10 | 10% | {score} |
|
|
252
|
+
| **Total** | | | **{total}/100** |
|
|
253
|
+
|
|
254
|
+
### Gate Status
|
|
255
|
+
|
|
256
|
+
```
|
|
257
|
+
Quality Gate: {PASS|REVIEW|FAIL}
|
|
258
|
+
|
|
259
|
+
Criteria:
|
|
260
|
+
- Quality Score: {score} (threshold: 60)
|
|
261
|
+
- Critical Issues: {count} (threshold: 0)
|
|
262
|
+
- High Issues: {count} (threshold: 5)
|
|
263
|
+
```
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
# Skill Authoring Principles
|
|
2
|
+
|
|
3
|
+
Skill 撰写首要准则。所有诊断和优化以此为纲。
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 核心原则
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
简洁高效 → 去除无关存储 → 去除中间存储 → 上下文流转
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## 1. 简洁高效
|
|
16
|
+
|
|
17
|
+
**原则**:最小化实现,只做必要的事
|
|
18
|
+
|
|
19
|
+
| DO | DON'T |
|
|
20
|
+
|----|-------|
|
|
21
|
+
| 单一职责阶段 | 臃肿的多功能阶段 |
|
|
22
|
+
| 直接的数据路径 | 迂回的处理流程 |
|
|
23
|
+
| 必要的字段 | 冗余的 schema 定义 |
|
|
24
|
+
| 精准的 prompt | 过度详细的指令 |
|
|
25
|
+
|
|
26
|
+
**检测模式**:
|
|
27
|
+
- Phase 文件 > 200 行 → 需拆分
|
|
28
|
+
- State schema 字段 > 20 个 → 需精简
|
|
29
|
+
- 同一数据多处定义 → 需去重
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
## 2. 去除无关存储
|
|
34
|
+
|
|
35
|
+
**原则**:不存储不需要的数据
|
|
36
|
+
|
|
37
|
+
| DO | DON'T |
|
|
38
|
+
|----|-------|
|
|
39
|
+
| 只存最终结果 | 存储调试信息 |
|
|
40
|
+
| 存路径引用 | 存完整内容副本 |
|
|
41
|
+
| 存必要索引 | 存全量历史 |
|
|
42
|
+
|
|
43
|
+
**检测模式**:
|
|
44
|
+
```javascript
|
|
45
|
+
// BAD: 存储完整内容
|
|
46
|
+
state.full_analysis_result = longAnalysisOutput;
|
|
47
|
+
|
|
48
|
+
// GOOD: 存路径 + 摘要
|
|
49
|
+
state.analysis = {
|
|
50
|
+
path: `${workDir}/analysis.json`,
|
|
51
|
+
summary: extractSummary(output),
|
|
52
|
+
key_findings: extractFindings(output)
|
|
53
|
+
};
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
**反模式清单**:
|
|
57
|
+
- `state.debug_*` → 删除
|
|
58
|
+
- `state.*_history` (无限增长) → 限制或删除
|
|
59
|
+
- `state.*_cache` (会话内) → 改用内存变量
|
|
60
|
+
- 重复字段 → 合并
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
## 3. 去除中间存储
|
|
65
|
+
|
|
66
|
+
**原则**:避免临时文件和中间状态文件
|
|
67
|
+
|
|
68
|
+
| DO | DON'T |
|
|
69
|
+
|----|-------|
|
|
70
|
+
| 直接传递结果 | 写文件再读文件 |
|
|
71
|
+
| 函数返回值 | 中间 JSON 文件 |
|
|
72
|
+
| 管道处理 | 阶段性存储 |
|
|
73
|
+
|
|
74
|
+
**检测模式**:
|
|
75
|
+
```javascript
|
|
76
|
+
// BAD: 中间文件
|
|
77
|
+
Write(`${workDir}/temp-step1.json`, step1Result);
|
|
78
|
+
const step1 = Read(`${workDir}/temp-step1.json`);
|
|
79
|
+
const step2Result = process(step1);
|
|
80
|
+
Write(`${workDir}/temp-step2.json`, step2Result);
|
|
81
|
+
|
|
82
|
+
// GOOD: 直接流转
|
|
83
|
+
const step1Result = await executeStep1();
|
|
84
|
+
const step2Result = process(step1Result);
|
|
85
|
+
const finalResult = finalize(step2Result);
|
|
86
|
+
Write(`${workDir}/final-output.json`, finalResult); // 只存最终结果
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
**允许的存储**:
|
|
90
|
+
- 最终输出(用户需要的结果)
|
|
91
|
+
- 检查点(长流程恢复用,可选)
|
|
92
|
+
- 备份(修改前的原始文件)
|
|
93
|
+
|
|
94
|
+
**禁止的存储**:
|
|
95
|
+
- `temp-*.json`
|
|
96
|
+
- `intermediate-*.json`
|
|
97
|
+
- `step[N]-output.json`
|
|
98
|
+
- `*-draft.md`
|
|
99
|
+
|
|
100
|
+
---
|
|
101
|
+
|
|
102
|
+
## 4. 上下文流转
|
|
103
|
+
|
|
104
|
+
**原则**:通过上下文传递而非文件
|
|
105
|
+
|
|
106
|
+
| DO | DON'T |
|
|
107
|
+
|----|-------|
|
|
108
|
+
| 函数参数传递 | 全局状态读写 |
|
|
109
|
+
| 返回值链式处理 | 文件中转 |
|
|
110
|
+
| prompt 内嵌数据 | 指向外部文件 |
|
|
111
|
+
|
|
112
|
+
**模式**:
|
|
113
|
+
```javascript
|
|
114
|
+
// 上下文流转模式
|
|
115
|
+
async function executePhase(context) {
|
|
116
|
+
const { previousResult, constraints, config } = context;
|
|
117
|
+
|
|
118
|
+
const result = await Task({
|
|
119
|
+
prompt: `
|
|
120
|
+
[CONTEXT]
|
|
121
|
+
Previous: ${JSON.stringify(previousResult)}
|
|
122
|
+
Constraints: ${constraints.join(', ')}
|
|
123
|
+
|
|
124
|
+
[TASK]
|
|
125
|
+
Process and return result directly.
|
|
126
|
+
`
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
return {
|
|
130
|
+
...context,
|
|
131
|
+
currentResult: result,
|
|
132
|
+
completed: ['phase-name']
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// 链式执行
|
|
137
|
+
let ctx = initialContext;
|
|
138
|
+
ctx = await executePhase1(ctx);
|
|
139
|
+
ctx = await executePhase2(ctx);
|
|
140
|
+
ctx = await executePhase3(ctx);
|
|
141
|
+
// ctx 包含完整上下文,无中间文件
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
**State 最小化**:
|
|
145
|
+
```typescript
|
|
146
|
+
// 只存必要状态
|
|
147
|
+
interface MinimalState {
|
|
148
|
+
status: 'pending' | 'running' | 'completed';
|
|
149
|
+
target: { name: string; path: string };
|
|
150
|
+
result_path: string; // 最终结果路径
|
|
151
|
+
error?: string;
|
|
152
|
+
}
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
---
|
|
156
|
+
|
|
157
|
+
## 应用场景
|
|
158
|
+
|
|
159
|
+
### 诊断时检查
|
|
160
|
+
|
|
161
|
+
| 检查项 | 违反时标记 |
|
|
162
|
+
|--------|-----------|
|
|
163
|
+
| Phase 内写入 temp 文件 | `unnecessary_storage` |
|
|
164
|
+
| State 包含 *_history 无限数组 | `unbounded_state` |
|
|
165
|
+
| 文件写入后立即读取 | `redundant_io` |
|
|
166
|
+
| 多阶段传递完整内容 | `context_bloat` |
|
|
167
|
+
|
|
168
|
+
### 优化策略
|
|
169
|
+
|
|
170
|
+
| 问题 | 策略 |
|
|
171
|
+
|------|------|
|
|
172
|
+
| 中间文件过多 | `eliminate_intermediate_files` |
|
|
173
|
+
| State 膨胀 | `minimize_state_schema` |
|
|
174
|
+
| 重复存储 | `deduplicate_storage` |
|
|
175
|
+
| 文件中转 | `context_passing` |
|
|
176
|
+
|
|
177
|
+
---
|
|
178
|
+
|
|
179
|
+
## 合规检查清单
|
|
180
|
+
|
|
181
|
+
```
|
|
182
|
+
□ 无 temp/intermediate 文件写入
|
|
183
|
+
□ State schema < 15 个字段
|
|
184
|
+
□ 无重复数据存储
|
|
185
|
+
□ Phase 间通过上下文/返回值传递
|
|
186
|
+
□ 只存最终结果文件
|
|
187
|
+
□ 无无限增长的数组
|
|
188
|
+
□ 无调试字段残留
|
|
189
|
+
```
|