Compare commits

...

10 Commits
v7.2.5 ... main

Author SHA1 Message Date
catlog22
1cd96b90e8 chore: bump version to 7.2.7
- Enhance smart-search with advanced MCP integration
- Add GEMINI_API_KEY configuration support in codexlens
- Update MCP server with new tool handlers
- Add tests for smart-search MCP usage
- Update documentation
2026-03-11 16:48:16 +08:00
catlog22
efbbaff834 chore: bump version to 7.2.6
- Fix: ccw install --force now properly skips all interactive prompts
- Fix: Backup confirmation prompt respects --force flag
- Fix: Git Bash fix prompt respects --force flag
2026-03-11 11:05:33 +08:00
catlog22
1ada08f073 refactor: 移除调试日志相关代码,简化历史保存逻辑 2026-03-11 10:35:57 +08:00
catlog22
65ff5f54cb refactor: update version check logic and response handling 2026-03-10 23:52:00 +08:00
catlog22
c50d9b21dc refactor: update workflow commands to use /workflow:spec:setup for initialization 2026-03-10 23:47:27 +08:00
catlog22
38d1987f41 改进交互推荐审查流程,支持批量确认和修改记录 2026-03-10 23:46:19 +08:00
catlog22
d29dabf0a9 Refactor code structure for improved readability and maintainability 2026-03-10 22:09:35 +08:00
catlog22
2d723644ea chore: remove unused subproject test-ddd-project 2026-03-10 21:43:44 +08:00
catlog22
9fb13ed6b0 Implement phases for skill iteration tuning: Evaluation, Improvement, and Reporting
- Added Phase 3: Evaluate Quality with steps for preparing context, constructing evaluation prompts, executing evaluation via CLI, parsing scores, and checking termination conditions.
- Introduced Phase 4: Apply Improvements to implement targeted changes based on evaluation suggestions, including agent execution and change documentation.
- Created Phase 5: Final Report to generate a comprehensive report of the iteration process, including score progression and remaining weaknesses.
- Established evaluation criteria in a new document to guide the evaluation process.
- Developed templates for evaluation and execution prompts to standardize input for the evaluation and execution phases.
2026-03-10 21:42:58 +08:00
catlog22
b4ad8c7b80 fix(frontend): fix TS2352 type cast in AdvancedTab test mock 2026-03-09 23:28:36 +08:00
52 changed files with 3058 additions and 268 deletions

View File

@@ -332,21 +332,22 @@ CONSTRAINTS: Focus on ${dimensions.join(', ')}
5. **Interactive Recommendation Review** (skip in auto mode): 5. **Interactive Recommendation Review** (skip in auto mode):
Walk through each recommendation one-by-one for user confirmation: Present all recommendations, then batch-confirm via **single AskUserQuestion call** (up to 4 questions):
``` ```
For each recommendation (ordered by priority high→medium→low): 1. Display all recommendations with numbering (action, rationale, priority, steps[])
1. Present: action, rationale, priority, steps[] (numbered sub-steps) 2. Single AskUserQuestion call — one question per recommendation (max 4, ordered by priority high→medium→low):
2. AskUserQuestion (single-select, header: "建议#N"): Each question (single-select, header: "建议#N"):
- **确认** (label: "确认", desc: "Accept as-is") → review_status = "accepted" - **确认** (label: "确认", desc: "Accept as-is") → review_status = "accepted"
- **修改** (label: "修改", desc: "Adjust scope/steps") → record modification → review_status = "modified" - **修改** (label: "修改", desc: "Adjust scope/steps") → review_status = "modified"
- **删除** (label: "删除", desc: "Not needed") → record reason → review_status = "rejected" - **删除** (label: "删除", desc: "Not needed") → review_status = "rejected"
- **跳过审议** (label: "跳过审议", desc: "Accept all remaining") → break loop 3. If >4 recommendations: batch in groups of 4 with additional AskUserQuestion calls
3. Record review decision to discussion.md Decision Log 4. For "修改" selections: follow up to capture modification details
4. Update conclusions.json recommendation.review_status 5. Record all review decisions to discussion.md Decision Log
6. Update conclusions.json recommendation.review_status for each
``` ```
**After review loop**: Display summary of reviewed recommendations: **After review**: Display summary of reviewed recommendations:
- Accepted: N items | Modified: N items | Rejected: N items - Accepted: N items | Modified: N items | Rejected: N items
- Only accepted/modified recommendations proceed to next step - Only accepted/modified recommendations proceed to next step

View File

@@ -289,7 +289,7 @@
}, },
{ {
"name": "init-guidelines", "name": "init-guidelines",
"command": "/workflow:init-guidelines", "command": "/workflow:spec:setup -guidelines",
"description": "Interactive wizard to fill specs/*.md based on project analysis", "description": "Interactive wizard to fill specs/*.md based on project analysis",
"arguments": "[--reset]", "arguments": "[--reset]",
"category": "workflow", "category": "workflow",
@@ -300,7 +300,7 @@
}, },
{ {
"name": "init-specs", "name": "init-specs",
"command": "/workflow:init-specs", "command": "/workflow:spec:setup -specs",
"description": "Interactive wizard to create individual specs or personal constraints with scope selection", "description": "Interactive wizard to create individual specs or personal constraints with scope selection",
"arguments": "[--scope <global|project>] [--dimension <specs|personal>] [--category <general|exploration|planning|execution>]", "arguments": "[--scope <global|project>] [--dimension <specs|personal>] [--category <general|exploration|planning|execution>]",
"category": "workflow", "category": "workflow",
@@ -311,7 +311,7 @@
}, },
{ {
"name": "init", "name": "init",
"command": "/workflow:init", "command": "/workflow:spec:setup ",
"description": "Initialize project-level state with intelligent project analysis using cli-explore-agent", "description": "Initialize project-level state with intelligent project analysis using cli-explore-agent",
"arguments": "[--regenerate] [--skip-specs]", "arguments": "[--regenerate] [--skip-specs]",
"category": "workflow", "category": "workflow",

View File

@@ -276,7 +276,7 @@
}, },
{ {
"name": "init-guidelines", "name": "init-guidelines",
"command": "/workflow:init-guidelines", "command": "/workflow:spec:setup -guidelines",
"description": "Interactive wizard to fill specs/*.md based on project analysis", "description": "Interactive wizard to fill specs/*.md based on project analysis",
"arguments": "[--reset]", "arguments": "[--reset]",
"category": "workflow", "category": "workflow",
@@ -287,7 +287,7 @@
}, },
{ {
"name": "init-specs", "name": "init-specs",
"command": "/workflow:init-specs", "command": "/workflow:spec:setup -specs",
"description": "Interactive wizard to create individual specs or personal constraints with scope selection", "description": "Interactive wizard to create individual specs or personal constraints with scope selection",
"arguments": "[--scope <global|project>] [--dimension <specs|personal>] [--category <general|exploration|planning|execution>]", "arguments": "[--scope <global|project>] [--dimension <specs|personal>] [--category <general|exploration|planning|execution>]",
"category": "workflow", "category": "workflow",
@@ -298,7 +298,7 @@
}, },
{ {
"name": "init", "name": "init",
"command": "/workflow:init", "command": "/workflow:spec:setup ",
"description": "Initialize project-level state with intelligent project analysis using cli-explore-agent", "description": "Initialize project-level state with intelligent project analysis using cli-explore-agent",
"arguments": "[--regenerate] [--skip-specs]", "arguments": "[--regenerate] [--skip-specs]",
"category": "workflow", "category": "workflow",

View File

@@ -298,7 +298,7 @@
}, },
{ {
"name": "init-guidelines", "name": "init-guidelines",
"command": "/workflow:init-guidelines", "command": "/workflow:spec:setup -guidelines",
"description": "Interactive wizard to fill specs/*.md based on project analysis", "description": "Interactive wizard to fill specs/*.md based on project analysis",
"arguments": "[--reset]", "arguments": "[--reset]",
"category": "workflow", "category": "workflow",
@@ -309,7 +309,7 @@
}, },
{ {
"name": "init-specs", "name": "init-specs",
"command": "/workflow:init-specs", "command": "/workflow:spec:setup -specs",
"description": "Interactive wizard to create individual specs or personal constraints with scope selection", "description": "Interactive wizard to create individual specs or personal constraints with scope selection",
"arguments": "[--scope <global|project>] [--dimension <specs|personal>] [--category <general|exploration|planning|execution>]", "arguments": "[--scope <global|project>] [--dimension <specs|personal>] [--category <general|exploration|planning|execution>]",
"category": "workflow", "category": "workflow",
@@ -320,7 +320,7 @@
}, },
{ {
"name": "init", "name": "init",
"command": "/workflow:init", "command": "/workflow:spec:setup ",
"description": "Initialize project-level state with intelligent project analysis using cli-explore-agent", "description": "Initialize project-level state with intelligent project analysis using cli-explore-agent",
"arguments": "[--regenerate] [--skip-specs]", "arguments": "[--regenerate] [--skip-specs]",
"category": "workflow", "category": "workflow",

View File

@@ -145,7 +145,7 @@
}, },
{ {
"name": "init-guidelines", "name": "init-guidelines",
"command": "/workflow:init-guidelines", "command": "/workflow:spec:setup -guidelines",
"description": "Interactive wizard to fill specs/*.md based on project analysis", "description": "Interactive wizard to fill specs/*.md based on project analysis",
"arguments": "[--reset]", "arguments": "[--reset]",
"category": "workflow", "category": "workflow",
@@ -156,7 +156,7 @@
}, },
{ {
"name": "init-specs", "name": "init-specs",
"command": "/workflow:init-specs", "command": "/workflow:spec:setup -specs",
"description": "Interactive wizard to create individual specs or personal constraints with scope selection", "description": "Interactive wizard to create individual specs or personal constraints with scope selection",
"arguments": "[--scope <global|project>] [--dimension <specs|personal>] [--category <general|exploration|planning|execution>]", "arguments": "[--scope <global|project>] [--dimension <specs|personal>] [--category <general|exploration|planning|execution>]",
"category": "workflow", "category": "workflow",
@@ -167,7 +167,7 @@
}, },
{ {
"name": "init", "name": "init",
"command": "/workflow:init", "command": "/workflow:spec:setup ",
"description": "Initialize project-level state with intelligent project analysis using cli-explore-agent", "description": "Initialize project-level state with intelligent project analysis using cli-explore-agent",
"arguments": "[--regenerate] [--skip-specs]", "arguments": "[--regenerate] [--skip-specs]",
"category": "workflow", "category": "workflow",

View File

@@ -0,0 +1,382 @@
---
name: skill-iter-tune
description: Iterative skill tuning via execute-evaluate-improve feedback loop. Uses ccw cli Claude to execute skill, Gemini to evaluate quality, and Agent to apply improvements. Iterates until quality threshold or max iterations. Triggers on "skill iter tune", "iterative skill tuning", "tune skill".
allowed-tools: Skill, Agent, AskUserQuestion, TaskCreate, TaskUpdate, TaskList, Read, Write, Edit, Bash, Glob, Grep
---
# Skill Iter Tune
Iterative skill refinement through execute-evaluate-improve feedback loops. Each iteration runs the skill via Claude, evaluates output via Gemini, and applies improvements via Agent.
## Architecture Overview
```
┌──────────────────────────────────────────────────────────────────────────┐
│ Skill Iter Tune Orchestrator (SKILL.md) │
│ → Parse input → Setup workspace → Iteration Loop → Final Report │
└────────────────────────────┬─────────────────────────────────────────────┘
┌───────────────────┼───────────────────────────────────┐
↓ ↓ ↓
┌──────────┐ ┌─────────────────────────────┐ ┌──────────┐
│ Phase 1 │ │ Iteration Loop (2→3→4) │ │ Phase 5 │
│ Setup │ │ ┌─────┐ ┌─────┐ ┌─────┐ │ │ Report │
│ │─────→│ │ P2 │→ │ P3 │→ │ P4 │ │────→│ │
│ Backup + │ │ │Exec │ │Eval │ │Impr │ │ │ History │
│ Init │ │ └─────┘ └─────┘ └─────┘ │ │ Summary │
└──────────┘ │ ↑ │ │ └──────────┘
│ └───────────────┘ │
│ (if score < threshold │
│ AND iter < max) │
└─────────────────────────────┘
```
### Chain Mode Extension
```
Chain Mode (execution_mode === "chain"):
Phase 2 runs per-skill in chain_order:
Skill A → ccw cli → artifacts/skill-A/
↓ (artifacts as input)
Skill B → ccw cli → artifacts/skill-B/
↓ (artifacts as input)
Skill C → ccw cli → artifacts/skill-C/
Phase 3 evaluates entire chain output + per-skill scores
Phase 4 improves weakest skill(s) in chain
```
## Key Design Principles
1. **Iteration Loop**: Phases 2-3-4 repeat until quality threshold, max iterations, or convergence
2. **Two-Tool Pipeline**: Claude (write/execute) + Gemini (analyze/evaluate) = complementary perspectives
3. **Pure Orchestrator**: SKILL.md coordinates only — execution detail lives in phase files
4. **Progressive Phase Loading**: Phase docs read only when that phase executes
5. **Skill Versioning**: Each iteration snapshots skill state before execution
6. **Convergence Detection**: Stop early if score stalls (no improvement in 2 consecutive iterations)
## Interactive Preference Collection
```javascript
// ★ Auto mode detection
const autoYes = /\b(-y|--yes)\b/.test($ARGUMENTS)
if (autoYes) {
workflowPreferences = {
autoYes: true,
maxIterations: 5,
qualityThreshold: 80,
executionMode: 'single'
}
} else {
const prefResponse = AskUserQuestion({
questions: [
{
question: "选择迭代调优配置:",
header: "Tune Config",
multiSelect: false,
options: [
{ label: "Quick (3 iter, 70)", description: "快速迭代,适合小幅改进" },
{ label: "Standard (5 iter, 80) (Recommended)", description: "平衡方案,适合多数场景" },
{ label: "Thorough (8 iter, 90)", description: "深度优化,适合生产级 skill" }
]
}
]
})
const configMap = {
"Quick": { maxIterations: 3, qualityThreshold: 70 },
"Standard": { maxIterations: 5, qualityThreshold: 80 },
"Thorough": { maxIterations: 8, qualityThreshold: 90 }
}
const selected = Object.keys(configMap).find(k =>
prefResponse["Tune Config"].startsWith(k)
) || "Standard"
workflowPreferences = { autoYes: false, ...configMap[selected] }
// ★ Mode selection: chain vs single
const modeResponse = AskUserQuestion({
questions: [{
question: "选择调优模式:",
header: "Tune Mode",
multiSelect: false,
options: [
{ label: "Single Skill (Recommended)", description: "独立调优每个 skill适合单一 skill 优化" },
{ label: "Skill Chain", description: "按链序执行,前一个 skill 的产出作为后一个的输入" }
]
}]
});
workflowPreferences.executionMode = modeResponse["Tune Mode"].startsWith("Skill Chain")
? "chain" : "single";
}
```
## Input Processing
```
$ARGUMENTS → Parse:
├─ Skill path(s): first arg, comma-separated for multiple
│ e.g., ".claude/skills/my-skill" or "my-skill" (auto-prefixed)
│ Chain mode: order preserved as chain_order
├─ Test scenario: --scenario "description" or remaining text
└─ Flags: --max-iterations=N, --threshold=N, -y/--yes
```
## Execution Flow
> **⚠️ COMPACT DIRECTIVE**: Context compression MUST check TodoWrite phase status.
> The phase currently marked `in_progress` is the active execution phase — preserve its FULL content.
> Only compress phases marked `completed` or `pending`.
### Phase 1: Setup (one-time)
Read and execute: `Ref: phases/01-setup.md`
- Parse skill paths, validate existence
- Create workspace at `.workflow/.scratchpad/skill-iter-tune-{ts}/`
- Backup original skill files
- Initialize iteration-state.json
Output: `workDir`, `targetSkills[]`, `testScenario`, initialized state
### Iteration Loop
```javascript
// Orchestrator iteration loop
while (true) {
// Increment iteration
state.current_iteration++;
state.iterations.push({
round: state.current_iteration,
status: 'pending',
execution: null,
evaluation: null,
improvement: null
});
// Update TodoWrite
TaskUpdate(iterationTask, {
subject: `Iteration ${state.current_iteration}/${state.max_iterations}`,
status: 'in_progress',
activeForm: `Running iteration ${state.current_iteration}`
});
// === Phase 2: Execute ===
// Read: phases/02-execute.md
// Single mode: one ccw cli call for all skills
// Chain mode: sequential ccw cli per skill in chain_order, passing artifacts
// Snapshot skill → construct prompt → ccw cli --tool claude --mode write
// Collect artifacts
// === Phase 3: Evaluate ===
// Read: phases/03-evaluate.md
// Construct eval prompt → ccw cli --tool gemini --mode analysis
// Parse score → write iteration-N-eval.md → check termination
// Check termination
if (shouldTerminate(state)) {
break; // → Phase 5
}
// === Phase 4: Improve ===
// Read: phases/04-improve.md
// Agent applies suggestions → write iteration-N-changes.md
// Update TodoWrite with score
// Continue loop
}
```
### Phase 2: Execute Skill (per iteration)
Read and execute: `Ref: phases/02-execute.md`
- Snapshot skill → `iteration-{N}/skill-snapshot/`
- Build execution prompt from skill content + test scenario
- Execute: `ccw cli -p "..." --tool claude --mode write --cd "${iterDir}/artifacts"`
- Collect artifacts
### Phase 3: Evaluate Quality (per iteration)
Read and execute: `Ref: phases/03-evaluate.md`
- Build evaluation prompt with skill + artifacts + criteria + history
- Execute: `ccw cli -p "..." --tool gemini --mode analysis`
- Parse 5-dimension score (Clarity, Completeness, Correctness, Effectiveness, Efficiency)
- Write `iteration-{N}-eval.md`
- Check termination: score >= threshold | iter >= max | convergence | error limit
### Phase 4: Apply Improvements (per iteration, skipped on termination)
Read and execute: `Ref: phases/04-improve.md`
- Read evaluation suggestions
- Launch general-purpose Agent to apply changes
- Write `iteration-{N}-changes.md`
- Update state
### Phase 5: Final Report (one-time)
Read and execute: `Ref: phases/05-report.md`
- Generate comprehensive report with score progression table
- Write `final-report.md`
- Display summary to user
**Phase Reference Documents** (read on-demand when phase executes):
| Phase | Document | Purpose | Compact |
|-------|----------|---------|---------|
| 1 | [phases/01-setup.md](phases/01-setup.md) | Initialize workspace and state | TodoWrite 驱动 |
| 2 | [phases/02-execute.md](phases/02-execute.md) | Execute skill via ccw cli Claude | TodoWrite 驱动 + 🔄 sentinel |
| 3 | [phases/03-evaluate.md](phases/03-evaluate.md) | Evaluate via ccw cli Gemini | TodoWrite 驱动 + 🔄 sentinel |
| 4 | [phases/04-improve.md](phases/04-improve.md) | Apply improvements via Agent | TodoWrite 驱动 + 🔄 sentinel |
| 5 | [phases/05-report.md](phases/05-report.md) | Generate final report | TodoWrite 驱动 |
**Compact Rules**:
1. **TodoWrite `in_progress`** → 保留完整内容,禁止压缩
2. **TodoWrite `completed`** → 可压缩为摘要
3. **🔄 sentinel fallback** → 若 compact 后仅存 sentinel 而无完整 Step 协议,立即 `Read()` 恢复
## Core Rules
1. **Start Immediately**: First action is preference collection → Phase 1 setup
2. **Progressive Loading**: Read phase doc ONLY when that phase is about to execute
3. **Snapshot Before Execute**: Always snapshot skill state before each iteration
4. **Background CLI**: ccw cli runs in background, wait for hook callback before proceeding
5. **Parse Every Output**: Extract structured JSON from CLI outputs for state updates
6. **DO NOT STOP**: Continuous iteration until termination condition met
7. **Single State Source**: `iteration-state.json` is the only source of truth
## Data Flow
```
User Input (skill paths + test scenario)
↓ (+ execution_mode + chain_order if chain mode)
Phase 1: Setup
↓ workDir, targetSkills[], testScenario, iteration-state.json
┌─→ Phase 2: Execute (ccw cli claude)
│ ↓ artifacts/ (skill execution output)
│ ↓
│ Phase 3: Evaluate (ccw cli gemini)
│ ↓ score, dimensions[], suggestions[], iteration-N-eval.md
│ ↓
│ [Terminate?]─── YES ──→ Phase 5: Report → final-report.md
│ ↓ NO
│ ↓
│ Phase 4: Improve (Agent)
│ ↓ modified skill files, iteration-N-changes.md
│ ↓
└───┘ next iteration
```
## TodoWrite Pattern
```javascript
// Initial state
TaskCreate({ subject: "Phase 1: Setup workspace", activeForm: "Setting up workspace" })
TaskCreate({ subject: "Iteration Loop", activeForm: "Running iterations" })
TaskCreate({ subject: "Phase 5: Final Report", activeForm: "Generating report" })
// Chain mode: create per-skill tracking tasks
if (state.execution_mode === 'chain') {
for (const skillName of state.chain_order) {
TaskCreate({
subject: `Chain: ${skillName}`,
activeForm: `Tracking ${skillName}`,
description: `Skill chain member position ${state.chain_order.indexOf(skillName) + 1}`
})
}
}
// During iteration N
// Single mode: one score per iteration (existing behavior)
// Chain mode: per-skill status updates
if (state.execution_mode === 'chain') {
// After each skill executes in Phase 2:
TaskUpdate(chainSkillTask, {
subject: `Chain: ${skillName} — Iter ${N} executed`,
activeForm: `${skillName} iteration ${N}`
})
// After Phase 3 evaluates:
TaskUpdate(chainSkillTask, {
subject: `Chain: ${skillName} — Score ${chainScores[skillName]}/100`,
activeForm: `${skillName} scored`
})
} else {
// Single mode (existing)
TaskCreate({
subject: `Iteration ${N}: Score ${score}/100`,
activeForm: `Iteration ${N} complete`,
description: `Strengths: ... | Weaknesses: ... | Suggestions: ${count}`
})
}
// Completed — collapse
TaskUpdate(iterLoop, {
subject: `Iteration Loop (${totalIters} iters, final: ${finalScore})`,
status: 'completed'
})
```
## Termination Logic
```javascript
function shouldTerminate(state) {
// 1. Quality threshold met
if (state.latest_score >= state.quality_threshold) {
return { terminate: true, reason: 'quality_threshold_met' };
}
// 2. Max iterations reached
if (state.current_iteration >= state.max_iterations) {
return { terminate: true, reason: 'max_iterations_reached' };
}
// 3. Convergence: ≤2 points improvement over last 2 iterations
if (state.score_trend.length >= 3) {
const last3 = state.score_trend.slice(-3);
if (last3[2] - last3[0] <= 2) {
state.converged = true;
return { terminate: true, reason: 'convergence_detected' };
}
}
// 4. Error limit
if (state.error_count >= state.max_errors) {
return { terminate: true, reason: 'error_limit_reached' };
}
return { terminate: false };
}
```
## Error Handling
| Phase | Error | Recovery |
|-------|-------|----------|
| 2: Execute | CLI timeout/crash | Retry once with simplified prompt, then skip |
| 3: Evaluate | CLI fails | Retry once, then use score 50 with warning |
| 3: Evaluate | JSON parse fails | Extract score heuristically, save raw output |
| 4: Improve | Agent fails | Rollback from `iteration-{N}/skill-snapshot/` |
| Any | 3+ consecutive errors | Terminate with error report |
**Error Budget**: Each phase gets 1 retry. 3 consecutive failed iterations triggers termination.
## Coordinator Checklist
### Pre-Phase Actions
- [ ] Read iteration-state.json for current state
- [ ] Verify workspace directory exists
- [ ] Check error count hasn't exceeded limit
### Per-Iteration Actions
- [ ] Increment current_iteration in state
- [ ] Create iteration-{N} subdirectory
- [ ] Update TodoWrite with iteration status
- [ ] After Phase 3: check termination before Phase 4
- [ ] After Phase 4: write state, proceed to next iteration
### Post-Workflow Actions
- [ ] Execute Phase 5 (Report)
- [ ] Display final summary to user
- [ ] Update all TodoWrite tasks to completed

View File

@@ -0,0 +1,144 @@
# Phase 1: Setup
Initialize workspace, backup skills, parse inputs.
## Objective
- Parse skill path(s) and test scenario from user input
- Validate all skill paths exist and contain SKILL.md
- Create isolated workspace directory structure
- Backup original skill files
- Initialize iteration-state.json
## Execution
### Step 1.1: Parse Input
Parse `$ARGUMENTS` to extract skill paths and test scenario.
```javascript
// Parse skill paths (first argument or comma-separated)
const args = $ARGUMENTS.trim();
const pathMatch = args.match(/^([^\s]+)/);
const rawPaths = pathMatch ? pathMatch[1].split(',') : [];
// Parse test scenario
const scenarioMatch = args.match(/(?:--scenario|--test)\s+"([^"]+)"/);
const scenarioText = scenarioMatch ? scenarioMatch[1] : args.replace(rawPaths.join(','), '').trim();
// Record chain order (preserves input order for chain mode)
const chainOrder = rawPaths.map(p => p.startsWith('.claude/') ? p.split('/').pop() : p);
// If no scenario, ask user
if (!scenarioText) {
const response = AskUserQuestion({
questions: [{
question: "Please describe the test scenario for evaluating this skill:",
header: "Test Scenario",
multiSelect: false,
options: [
{ label: "General quality test", description: "Evaluate overall skill quality with a generic task" },
{ label: "Specific scenario", description: "I'll describe a specific test case" }
]
}]
});
// Use response to construct testScenario
}
```
### Step 1.2: Validate Skill Paths
```javascript
const targetSkills = [];
for (const rawPath of rawPaths) {
const skillPath = rawPath.startsWith('.claude/') ? rawPath : `.claude/skills/${rawPath}`;
// Validate SKILL.md exists
const skillFiles = Glob(`${skillPath}/SKILL.md`);
if (skillFiles.length === 0) {
throw new Error(`Skill not found at: ${skillPath} -- SKILL.md missing`);
}
// Collect all skill files
const allFiles = Glob(`${skillPath}/**/*.md`);
targetSkills.push({
name: skillPath.split('/').pop(),
path: skillPath,
files: allFiles.map(f => f.replace(skillPath + '/', '')),
primary_file: 'SKILL.md'
});
}
```
### Step 1.3: Create Workspace
```javascript
const ts = Date.now();
const workDir = `.workflow/.scratchpad/skill-iter-tune-${ts}`;
Bash(`mkdir -p "${workDir}/backups" "${workDir}/iterations"`);
```
### Step 1.4: Backup Original Skills
```javascript
for (const skill of targetSkills) {
Bash(`cp -r "${skill.path}" "${workDir}/backups/${skill.name}"`);
}
```
### Step 1.5: Initialize State
Write `iteration-state.json` with initial state:
```javascript
const initialState = {
status: 'running',
started_at: new Date().toISOString(),
updated_at: new Date().toISOString(),
target_skills: targetSkills,
test_scenario: {
description: scenarioText,
// Parse --requirements and --input-args from $ARGUMENTS if provided
// e.g., --requirements "clear output,no errors" --input-args "my-skill --scenario test"
requirements: parseListArg(args, '--requirements') || [],
input_args: parseStringArg(args, '--input-args') || '',
success_criteria: parseStringArg(args, '--success-criteria') || 'Produces correct, high-quality output'
},
execution_mode: workflowPreferences.executionMode || 'single',
chain_order: workflowPreferences.executionMode === 'chain'
? targetSkills.map(s => s.name)
: [],
current_iteration: 0,
max_iterations: workflowPreferences.maxIterations,
quality_threshold: workflowPreferences.qualityThreshold,
latest_score: 0,
score_trend: [],
converged: false,
iterations: [],
errors: [],
error_count: 0,
max_errors: 3,
work_dir: workDir,
backup_dir: `${workDir}/backups`
};
Write(`${workDir}/iteration-state.json`, JSON.stringify(initialState, null, 2));
// Chain mode: create per-skill tracking tasks
if (initialState.execution_mode === 'chain') {
for (const skill of targetSkills) {
TaskCreate({
subject: `Chain: ${skill.name}`,
activeForm: `Tracking ${skill.name}`,
description: `Skill chain member: ${skill.path} | Position: ${targetSkills.indexOf(skill) + 1}/${targetSkills.length}`
});
}
}
```
## Output
- **Variables**: `workDir`, `targetSkills[]`, `testScenario`, `chainOrder` (chain mode)
- **Files**: `iteration-state.json`, `backups/` directory with skill copies
- **TodoWrite**: Mark Phase 1 completed, start Iteration Loop. Chain mode: per-skill tracking tasks created

View File

@@ -0,0 +1,292 @@
# Phase 2: Execute Skill
> **COMPACT SENTINEL [Phase 2: Execute]**
> This phase contains 4 execution steps (Step 2.1 -- 2.4).
> If you can read this sentinel but cannot find the full Step protocol below, context has been compressed.
> Recovery: `Read("phases/02-execute.md")`
Execute the target skill against the test scenario using `ccw cli --tool claude --mode write`. Claude receives the full skill definition and simulates producing its expected output artifacts.
## Objective
- Snapshot current skill version before execution
- Construct execution prompt with full skill content + test scenario
- Execute via ccw cli Claude
- Collect output artifacts
## Execution
### Step 2.1: Snapshot Current Skill
```javascript
const N = state.current_iteration;
const iterDir = `${state.work_dir}/iterations/iteration-${N}`;
Bash(`mkdir -p "${iterDir}/skill-snapshot" "${iterDir}/artifacts"`);
// Chain mode: create per-skill artifact directories
if (state.execution_mode === 'chain') {
for (const skillName of state.chain_order) {
Bash(`mkdir -p "${iterDir}/artifacts/${skillName}"`);
}
}
// Snapshot current skill state (so we can compare/rollback)
for (const skill of state.target_skills) {
Bash(`cp -r "${skill.path}" "${iterDir}/skill-snapshot/${skill.name}"`);
}
```
### Step 2.2: Construct Execution Prompt (Single Mode)
Read the execute-prompt template and substitute variables.
> Skip to Step 2.2b if `state.execution_mode === 'chain'`.
```javascript
// Ref: templates/execute-prompt.md
// Build skillContent by reading only executable skill files (SKILL.md, phases/, specs/)
// Exclude README.md, docs/, and other non-executable files to save tokens
const skillContent = state.target_skills.map(skill => {
const skillMd = Read(`${skill.path}/SKILL.md`);
const phaseFiles = Glob(`${skill.path}/phases/*.md`).sort().map(f => ({
relativePath: f.replace(skill.path + '/', ''),
content: Read(f)
}));
const specFiles = Glob(`${skill.path}/specs/*.md`).map(f => ({
relativePath: f.replace(skill.path + '/', ''),
content: Read(f)
}));
return `### File: SKILL.md\n${skillMd}\n\n` +
phaseFiles.map(f => `### File: ${f.relativePath}\n${f.content}`).join('\n\n') +
(specFiles.length > 0 ? '\n\n' + specFiles.map(f => `### File: ${f.relativePath}\n${f.content}`).join('\n\n') : '');
}).join('\n\n---\n\n');
// Construct full prompt using template
const executePrompt = `PURPOSE: Simulate executing the following workflow skill against a test scenario. Produce all expected output artifacts as if the skill were invoked with the given input.
SKILL CONTENT:
${skillContent}
TEST SCENARIO:
Description: ${state.test_scenario.description}
Input Arguments: ${state.test_scenario.input_args}
Requirements: ${state.test_scenario.requirements.join('; ')}
Success Criteria: ${state.test_scenario.success_criteria}
TASK:
1. Study the complete skill structure (SKILL.md + all phase files)
2. Follow the skill execution flow sequentially
3. For each phase, produce the artifacts that phase would generate
4. Write all output artifacts to the current working directory
5. Create a manifest.json listing all produced artifacts
MODE: write
CONTEXT: @**/*
EXPECTED: All artifacts written to disk + manifest.json
CONSTRAINTS: Follow skill flow exactly, produce realistic output, not placeholders`;
```
### Step 2.3: Execute via ccw cli
> **CHECKPOINT**: Before executing CLI, verify:
> 1. This phase is TodoWrite `in_progress`
> 2. `iterDir/artifacts/` directory exists
> 3. Prompt is properly escaped
```javascript
function escapeForShell(str) {
return str.replace(/"/g, '\\"').replace(/\$/g, '\\$').replace(/`/g, '\\`');
}
const cliCommand = `ccw cli -p "${escapeForShell(executePrompt)}" --tool claude --mode write --cd "${iterDir}/artifacts"`;
// Execute in background, wait for hook callback
Bash({
command: cliCommand,
run_in_background: true,
timeout: 600000 // 10 minutes max
});
// STOP HERE -- wait for hook callback to resume
// After callback, verify artifacts were produced
```
### Step 2.2b: Chain Execution Path
> Skip this step if `state.execution_mode === 'single'`.
In chain mode, execute each skill sequentially. Each skill receives the previous skill's artifacts as input context.
```javascript
// Chain execution: iterate through chain_order
let previousArtifacts = ''; // Accumulates upstream output
for (let i = 0; i < state.chain_order.length; i++) {
const skillName = state.chain_order[i];
const skill = state.target_skills.find(s => s.name === skillName);
const skillArtifactDir = `${iterDir}/artifacts/${skillName}`;
// Build this skill's content
const skillMd = Read(`${skill.path}/SKILL.md`);
const phaseFiles = Glob(`${skill.path}/phases/*.md`).sort().map(f => ({
relativePath: f.replace(skill.path + '/', ''),
content: Read(f)
}));
const specFiles = Glob(`${skill.path}/specs/*.md`).map(f => ({
relativePath: f.replace(skill.path + '/', ''),
content: Read(f)
}));
const singleSkillContent = `### File: SKILL.md\n${skillMd}\n\n` +
phaseFiles.map(f => `### File: ${f.relativePath}\n${f.content}`).join('\n\n') +
(specFiles.length > 0 ? '\n\n' + specFiles.map(f => `### File: ${f.relativePath}\n${f.content}`).join('\n\n') : '');
// Build chain context from previous skill's artifacts
const chainInputContext = previousArtifacts
? `\nPREVIOUS CHAIN OUTPUT (from upstream skill "${state.chain_order[i - 1]}"):\n${previousArtifacts}\n\nIMPORTANT: Use the above output as input context for this skill's execution.\n`
: '';
// Construct per-skill execution prompt
// Ref: templates/execute-prompt.md
const chainPrompt = `PURPOSE: Simulate executing the following workflow skill against a test scenario. Produce all expected output artifacts.
SKILL CONTENT (${skillName} — chain position ${i + 1}/${state.chain_order.length}):
${singleSkillContent}
${chainInputContext}
TEST SCENARIO:
Description: ${state.test_scenario.description}
Input Arguments: ${state.test_scenario.input_args}
Requirements: ${state.test_scenario.requirements.join('; ')}
Success Criteria: ${state.test_scenario.success_criteria}
TASK:
1. Study the complete skill structure
2. Follow the skill execution flow sequentially
3. Produce all expected artifacts
4. Write output to the current working directory
5. Create manifest.json listing all produced artifacts
MODE: write
CONTEXT: @**/*
CONSTRAINTS: Follow skill flow exactly, produce realistic output`;
function escapeForShell(str) {
return str.replace(/"/g, '\\"').replace(/\$/g, '\\$').replace(/`/g, '\\`');
}
const cliCommand = `ccw cli -p "${escapeForShell(chainPrompt)}" --tool claude --mode write --cd "${skillArtifactDir}"`;
// Execute in background
Bash({
command: cliCommand,
run_in_background: true,
timeout: 600000
});
// STOP -- wait for hook callback
// After callback: collect artifacts for next skill in chain
const artifacts = Glob(`${skillArtifactDir}/**/*`);
const skillSuccess = artifacts.length > 0;
if (skillSuccess) {
previousArtifacts = artifacts.slice(0, 10).map(f => {
const relPath = f.replace(skillArtifactDir + '/', '');
const content = Read(f, { limit: 100 });
return `--- ${relPath} ---\n${content}`;
}).join('\n\n');
} else {
// Mid-chain failure: keep previous artifacts for downstream skills
// Log warning but continue chain — downstream skills receive last successful output
state.errors.push({
phase: 'execute',
message: `Chain skill "${skillName}" (position ${i + 1}) produced no artifacts. Downstream skills will receive upstream output from "${state.chain_order[i - 1] || 'none'}" instead.`,
timestamp: new Date().toISOString()
});
state.error_count++;
// previousArtifacts remains from last successful skill (or empty if first)
}
// Update per-skill TodoWrite
// TaskUpdate chain skill task with execution status
// Record per-skill execution
if (!state.iterations[N - 1].execution.chain_executions) {
state.iterations[N - 1].execution.chain_executions = [];
}
state.iterations[N - 1].execution.chain_executions.push({
skill_name: skillName,
cli_command: cliCommand,
artifacts_dir: skillArtifactDir,
success: skillSuccess
});
// Check error budget: abort chain if too many consecutive failures
if (state.error_count >= 3) {
state.errors.push({
phase: 'execute',
message: `Chain execution aborted at skill "${skillName}" — error limit reached (${state.error_count} errors).`,
timestamp: new Date().toISOString()
});
break;
}
}
```
### Step 2.4: Collect Artifacts
After CLI completes (hook callback received):
```javascript
// List produced artifacts
const artifactFiles = Glob(`${iterDir}/artifacts/**/*`);
// Chain mode: check per-skill artifacts
if (state.execution_mode === 'chain') {
const chainSuccess = state.iterations[N - 1].execution.chain_executions?.every(e => e.success) ?? false;
state.iterations[N - 1].execution.success = chainSuccess;
state.iterations[N - 1].execution.artifacts_dir = `${iterDir}/artifacts`;
} else {
if (artifactFiles.length === 0) {
// Execution produced nothing -- record error
state.iterations[N - 1].execution = {
cli_command: cliCommand,
started_at: new Date().toISOString(),
completed_at: new Date().toISOString(),
artifacts_dir: `${iterDir}/artifacts`,
success: false
};
state.error_count++;
// Continue to Phase 3 anyway -- Gemini can evaluate the skill even without artifacts
} else {
state.iterations[N - 1].execution = {
cli_command: cliCommand,
started_at: new Date().toISOString(),
completed_at: new Date().toISOString(),
artifacts_dir: `${iterDir}/artifacts`,
success: true
};
}
} // end single mode branch
// Update state
Write(`${state.work_dir}/iteration-state.json`, JSON.stringify(state, null, 2));
```
## Error Handling
| Error | Recovery |
|-------|----------|
| CLI timeout (10min) | Record failure, continue to Phase 3 without artifacts |
| CLI crash | Retry once with simplified prompt (SKILL.md only, no phase files) |
| No artifacts produced | Continue to Phase 3, evaluation focuses on skill definition quality |
## Output
- **Files**: `iteration-{N}/skill-snapshot/`, `iteration-{N}/artifacts/`
- **State**: `iterations[N-1].execution` updated
- **Next**: Phase 3 (Evaluate)

View File

@@ -0,0 +1,312 @@
# Phase 3: Evaluate Quality
> **COMPACT SENTINEL [Phase 3: Evaluate]**
> This phase contains 5 execution steps (Step 3.1 -- 3.5).
> If you can read this sentinel but cannot find the full Step protocol below, context has been compressed.
> Recovery: `Read("phases/03-evaluate.md")`
Evaluate skill quality using `ccw cli --tool gemini --mode analysis`. Gemini scores the skill across 5 dimensions and provides improvement suggestions.
## Objective
- Construct evaluation prompt with skill + artifacts + criteria
- Execute via ccw cli Gemini
- Parse multi-dimensional score
- Write iteration-{N}-eval.md
- Check termination conditions
## Execution
### Step 3.1: Prepare Evaluation Context
```javascript
const N = state.current_iteration;
const iterDir = `${state.work_dir}/iterations/iteration-${N}`;
// Read evaluation criteria
// Ref: specs/evaluation-criteria.md
const evaluationCriteria = Read('.claude/skills/skill-iter-tune/specs/evaluation-criteria.md');
// Build skillContent (same pattern as Phase 02 — only executable files)
const skillContent = state.target_skills.map(skill => {
const skillMd = Read(`${skill.path}/SKILL.md`);
const phaseFiles = Glob(`${skill.path}/phases/*.md`).sort().map(f => ({
relativePath: f.replace(skill.path + '/', ''),
content: Read(f)
}));
const specFiles = Glob(`${skill.path}/specs/*.md`).map(f => ({
relativePath: f.replace(skill.path + '/', ''),
content: Read(f)
}));
return `### File: SKILL.md\n${skillMd}\n\n` +
phaseFiles.map(f => `### File: ${f.relativePath}\n${f.content}`).join('\n\n') +
(specFiles.length > 0 ? '\n\n' + specFiles.map(f => `### File: ${f.relativePath}\n${f.content}`).join('\n\n') : '');
}).join('\n\n---\n\n');
// Build artifacts summary
let artifactsSummary = 'No artifacts produced (execution may have failed)';
if (state.execution_mode === 'chain') {
// Chain mode: group artifacts by skill
const chainSummaries = state.chain_order.map(skillName => {
const skillArtifactDir = `${iterDir}/artifacts/${skillName}`;
const files = Glob(`${skillArtifactDir}/**/*`);
if (files.length === 0) return `### ${skillName} (no artifacts)`;
const filesSummary = files.map(f => {
const relPath = f.replace(`${skillArtifactDir}/`, '');
const content = Read(f, { limit: 200 });
return `--- ${relPath} ---\n${content}`;
}).join('\n\n');
return `### ${skillName} (chain position ${state.chain_order.indexOf(skillName) + 1})\n${filesSummary}`;
});
artifactsSummary = chainSummaries.join('\n\n---\n\n');
} else {
// Single mode (existing)
const artifactFiles = Glob(`${iterDir}/artifacts/**/*`);
if (artifactFiles.length > 0) {
artifactsSummary = artifactFiles.map(f => {
const relPath = f.replace(`${iterDir}/artifacts/`, '');
const content = Read(f, { limit: 200 });
return `--- ${relPath} ---\n${content}`;
}).join('\n\n');
}
}
// Build previous evaluation context
const previousEvalContext = state.iterations.filter(i => i.evaluation).length > 0
? `PREVIOUS ITERATIONS:\n` + state.iterations.filter(i => i.evaluation).map(iter =>
`Iteration ${iter.round}: Score ${iter.evaluation.score}\n` +
` Applied: ${iter.improvement?.changes_applied?.map(c => c.summary).join('; ') || 'none'}\n` +
` Weaknesses: ${iter.evaluation.weaknesses?.slice(0, 3).join('; ') || 'none'}`
).join('\n') + '\nIMPORTANT: Focus on NEW issues not yet addressed.'
: '';
```
### Step 3.2: Construct Evaluation Prompt
```javascript
// Ref: templates/eval-prompt.md
const evalPrompt = `PURPOSE: Evaluate the quality of a workflow skill by examining its definition and produced artifacts.
SKILL DEFINITION:
${skillContent}
TEST SCENARIO:
${state.test_scenario.description}
Requirements: ${state.test_scenario.requirements.join('; ')}
Success Criteria: ${state.test_scenario.success_criteria}
ARTIFACTS PRODUCED:
${artifactsSummary}
EVALUATION CRITERIA:
${evaluationCriteria}
${previousEvalContext}
${state.execution_mode === 'chain' ? `
CHAIN CONTEXT:
This skill chain contains ${state.chain_order.length} skills executed in order:
${state.chain_order.map((s, i) => `${i+1}. ${s}`).join('\n')}
Current evaluation covers the entire chain output.
Please provide per-skill quality scores in an additional "chain_scores" field: { "${state.chain_order[0]}": <score>, ... }
` : ''}
TASK:
1. Score each dimension (Clarity 0.20, Completeness 0.25, Correctness 0.25, Effectiveness 0.20, Efficiency 0.10) on 0-100
2. Calculate weighted composite score
3. List top 3 strengths
4. List top 3-5 weaknesses with file:section references
5. Provide 3-5 prioritized improvement suggestions with concrete changes
EXPECTED OUTPUT (strict JSON, no markdown):
{
"composite_score": <0-100>,
"dimensions": [
{"name":"Clarity","id":"clarity","score":<0-100>,"weight":0.20,"feedback":"..."},
{"name":"Completeness","id":"completeness","score":<0-100>,"weight":0.25,"feedback":"..."},
{"name":"Correctness","id":"correctness","score":<0-100>,"weight":0.25,"feedback":"..."},
{"name":"Effectiveness","id":"effectiveness","score":<0-100>,"weight":0.20,"feedback":"..."},
{"name":"Efficiency","id":"efficiency","score":<0-100>,"weight":0.10,"feedback":"..."}
],
"strengths": ["...", "...", "..."],
"weaknesses": ["...with file:section ref...", "..."],
"suggestions": [
{"priority":"high|medium|low","target_file":"...","description":"...","rationale":"...","code_snippet":"..."}
]
}
CONSTRAINTS: Be rigorous, reference exact files, focus on highest-impact changes, output ONLY JSON`;
```
### Step 3.3: Execute via ccw cli Gemini
> **CHECKPOINT**: Verify evaluation prompt is properly constructed before CLI execution.
```javascript
// Shell escape utility (same as Phase 02)
function escapeForShell(str) {
return str.replace(/"/g, '\\"').replace(/\$/g, '\\$').replace(/`/g, '\\`');
}
const skillPath = state.target_skills[0].path; // Primary skill for --cd
const cliCommand = `ccw cli -p "${escapeForShell(evalPrompt)}" --tool gemini --mode analysis --cd "${skillPath}"`;
// Execute in background
Bash({
command: cliCommand,
run_in_background: true,
timeout: 300000 // 5 minutes
});
// STOP -- wait for hook callback
```
### Step 3.4: Parse Score and Write Eval File
After CLI completes:
```javascript
// Parse JSON from Gemini output
// The output may contain markdown wrapping -- extract JSON
const rawOutput = /* CLI output from callback */;
const jsonMatch = rawOutput.match(/\{[\s\S]*\}/);
let evaluation;
if (jsonMatch) {
try {
evaluation = JSON.parse(jsonMatch[0]);
// Extract chain_scores if present
if (state.execution_mode === 'chain' && evaluation.chain_scores) {
state.iterations[N - 1].evaluation.chain_scores = evaluation.chain_scores;
}
} catch (e) {
// Fallback: try to extract score heuristically
const scoreMatch = rawOutput.match(/"composite_score"\s*:\s*(\d+)/);
evaluation = {
composite_score: scoreMatch ? parseInt(scoreMatch[1]) : 50,
dimensions: [],
strengths: [],
weaknesses: ['Evaluation output parsing failed -- raw output saved'],
suggestions: []
};
}
} else {
evaluation = {
composite_score: 50,
dimensions: [],
strengths: [],
weaknesses: ['No structured evaluation output -- defaulting to 50'],
suggestions: []
};
}
// Write iteration-N-eval.md
const evalReport = `# Iteration ${N} Evaluation
**Composite Score**: ${evaluation.composite_score}/100
**Date**: ${new Date().toISOString()}
## Dimension Scores
| Dimension | Score | Weight | Feedback |
|-----------|-------|--------|----------|
${(evaluation.dimensions || []).map(d =>
`| ${d.name} | ${d.score} | ${d.weight} | ${d.feedback} |`
).join('\n')}
${(state.execution_mode === 'chain' && evaluation.chain_scores) ? `
## Chain Scores
| Skill | Score | Chain Position |
|-------|-------|----------------|
${state.chain_order.map((s, i) => `| ${s} | ${evaluation.chain_scores[s] || '-'} | ${i + 1} |`).join('\n')}
` : ''}
## Strengths
${(evaluation.strengths || []).map(s => `- ${s}`).join('\n')}
## Weaknesses
${(evaluation.weaknesses || []).map(w => `- ${w}`).join('\n')}
## Improvement Suggestions
${(evaluation.suggestions || []).map((s, i) =>
`### ${i + 1}. [${s.priority}] ${s.description}\n- **Target**: ${s.target_file}\n- **Rationale**: ${s.rationale}\n${s.code_snippet ? `- **Suggested**:\n\`\`\`\n${s.code_snippet}\n\`\`\`` : ''}`
).join('\n\n')}
`;
Write(`${iterDir}/iteration-${N}-eval.md`, evalReport);
// Update state
state.iterations[N - 1].evaluation = {
score: evaluation.composite_score,
dimensions: evaluation.dimensions || [],
strengths: evaluation.strengths || [],
weaknesses: evaluation.weaknesses || [],
suggestions: evaluation.suggestions || [],
chain_scores: evaluation.chain_scores || null,
eval_file: `${iterDir}/iteration-${N}-eval.md`
};
state.latest_score = evaluation.composite_score;
state.score_trend.push(evaluation.composite_score);
Write(`${state.work_dir}/iteration-state.json`, JSON.stringify(state, null, 2));
```
### Step 3.5: Check Termination
```javascript
function shouldTerminate(state) {
// 1. Quality threshold met
if (state.latest_score >= state.quality_threshold) {
return { terminate: true, reason: 'quality_threshold_met' };
}
// 2. Max iterations reached
if (state.current_iteration >= state.max_iterations) {
return { terminate: true, reason: 'max_iterations_reached' };
}
// 3. Convergence: no improvement in last 2 iterations
if (state.score_trend.length >= 3) {
const last3 = state.score_trend.slice(-3);
const improvement = last3[2] - last3[0];
if (improvement <= 2) {
state.converged = true;
return { terminate: true, reason: 'convergence_detected' };
}
}
// 4. Error limit
if (state.error_count >= state.max_errors) {
return { terminate: true, reason: 'error_limit_reached' };
}
return { terminate: false };
}
const termination = shouldTerminate(state);
if (termination.terminate) {
state.termination_reason = termination.reason;
Write(`${state.work_dir}/iteration-state.json`, JSON.stringify(state, null, 2));
// Skip Phase 4, go directly to Phase 5 (Report)
} else {
// Continue to Phase 4 (Improve)
}
```
## Error Handling
| Error | Recovery |
|-------|----------|
| CLI timeout | Retry once, if still fails use score 50 with warning |
| JSON parse failure | Extract score heuristically, save raw output |
| No output | Default score 50, note in weaknesses |
## Output
- **Files**: `iteration-{N}-eval.md`
- **State**: `iterations[N-1].evaluation`, `latest_score`, `score_trend` updated
- **Decision**: terminate -> Phase 5, continue -> Phase 4
- **TodoWrite**: Update current iteration score display

View File

@@ -0,0 +1,186 @@
# Phase 4: Apply Improvements
> **COMPACT SENTINEL [Phase 4: Improve]**
> This phase contains 4 execution steps (Step 4.1 -- 4.4).
> If you can read this sentinel but cannot find the full Step protocol below, context has been compressed.
> Recovery: `Read("phases/04-improve.md")`
Apply targeted improvements to skill files based on evaluation suggestions. Uses a general-purpose Agent to make changes, ensuring only suggested modifications are applied.
## Objective
- Read evaluation suggestions from current iteration
- Launch Agent to apply improvements in priority order
- Document all changes made
- Update iteration state
## Execution
### Step 4.1: Prepare Improvement Context
```javascript
const N = state.current_iteration;
const iterDir = `${state.work_dir}/iterations/iteration-${N}`;
const evaluation = state.iterations[N - 1].evaluation;
// Verify we have suggestions to apply
if (!evaluation.suggestions || evaluation.suggestions.length === 0) {
// No suggestions -- skip improvement, mark iteration complete
state.iterations[N - 1].improvement = {
changes_applied: [],
changes_file: null,
improvement_rationale: 'No suggestions provided by evaluation'
};
state.iterations[N - 1].status = 'completed';
Write(`${state.work_dir}/iteration-state.json`, JSON.stringify(state, null, 2));
// -> Return to orchestrator for next iteration
return;
}
// Build file inventory for agent context
const skillFileInventory = state.target_skills.map(skill => {
return `Skill: ${skill.name} (${skill.path})\nFiles:\n` +
skill.files.map(f => ` - ${f}`).join('\n');
}).join('\n\n');
// Chain mode: add chain relationship context
const chainContext = state.execution_mode === 'chain'
? `\nChain Order: ${state.chain_order.join(' -> ')}\n` +
`Chain Scores: ${state.chain_order.map(s =>
`${s}: ${state.iterations[N-1].evaluation?.chain_scores?.[s] || 'N/A'}`
).join(', ')}\n` +
`Weakest Link: ${state.chain_order.reduce((min, s) => {
const score = state.iterations[N-1].evaluation?.chain_scores?.[s] || 100;
return score < (state.iterations[N-1].evaluation?.chain_scores?.[min] || 100) ? s : min;
}, state.chain_order[0])}`
: '';
```
### Step 4.2: Launch Improvement Agent
> **CHECKPOINT**: Before launching agent, verify:
> 1. evaluation.suggestions is non-empty
> 2. All target_file paths in suggestions are valid
```javascript
const suggestionsText = evaluation.suggestions.map((s, i) =>
`${i + 1}. [${s.priority.toUpperCase()}] ${s.description}\n` +
` Target: ${s.target_file}\n` +
` Rationale: ${s.rationale}\n` +
(s.code_snippet ? ` Suggested change:\n ${s.code_snippet}\n` : '')
).join('\n');
Agent({
subagent_type: 'general-purpose',
run_in_background: false,
description: `Apply skill improvements iteration ${N}`,
prompt: `## Task: Apply Targeted Improvements to Skill Files
You are improving a workflow skill based on evaluation feedback. Apply ONLY the suggested changes -- do not refactor, add features, or "improve" beyond what is explicitly suggested.
## Current Score: ${evaluation.score}/100
Dimension breakdown:
${evaluation.dimensions.map(d => `- ${d.name}: ${d.score}/100`).join('\n')}
## Skill File Inventory
${skillFileInventory}
${chainContext ? `## Chain Context\n${chainContext}\n\nPrioritize improvements on the weakest skill in the chain. Also consider interface compatibility between adjacent skills in the chain.\n` : ''}
## Improvement Suggestions (apply in priority order)
${suggestionsText}
## Rules
1. Read each target file BEFORE modifying it
2. Apply ONLY the suggested changes -- no unsolicited modifications
3. If a suggestion's target_file doesn't exist, skip it and note in summary
4. If a suggestion conflicts with existing patterns, adapt it to fit (note adaptation)
5. Preserve existing code style, naming conventions, and structure
6. After all changes, write a change summary to: ${iterDir}/iteration-${N}-changes.md
## Changes Summary Format (write to ${iterDir}/iteration-${N}-changes.md)
# Iteration ${N} Changes
## Applied Suggestions
- [high] description: what was changed in which file
- [medium] description: what was changed in which file
## Files Modified
- path/to/file.md: brief description of changes
## Skipped Suggestions (if any)
- description: reason for skipping
## Notes
- Any adaptations or considerations
## Success Criteria
- All high-priority suggestions applied
- Medium-priority suggestions applied if feasible
- Low-priority suggestions applied if trivial
- Changes summary written to ${iterDir}/iteration-${N}-changes.md
`
});
```
### Step 4.3: Verify Changes
After agent completes:
```javascript
// Verify changes summary was written
const changesFile = `${iterDir}/iteration-${N}-changes.md`;
const changesExist = Glob(changesFile).length > 0;
if (!changesExist) {
// Agent didn't write summary -- create a minimal one
Write(changesFile, `# Iteration ${N} Changes\n\n## Notes\nAgent completed but did not produce changes summary.\n`);
}
// Read changes summary to extract applied changes
const changesContent = Read(changesFile);
// Parse applied changes (heuristic: count lines starting with "- [")
const appliedMatches = changesContent.match(/^- \[.+?\]/gm) || [];
const changes_applied = appliedMatches.map(m => ({
summary: m.replace(/^- /, ''),
file: '' // Extracted from context
}));
```
### Step 4.4: Update State
```javascript
state.iterations[N - 1].improvement = {
changes_applied: changes_applied,
changes_file: changesFile,
improvement_rationale: `Applied ${changes_applied.length} improvements based on evaluation score ${evaluation.score}`
};
state.iterations[N - 1].status = 'completed';
state.updated_at = new Date().toISOString();
// Also update the skill files list in case new files were created
for (const skill of state.target_skills) {
skill.files = Glob(`${skill.path}/**/*.md`).map(f => f.replace(skill.path + '/', ''));
}
Write(`${state.work_dir}/iteration-state.json`, JSON.stringify(state, null, 2));
// -> Return to orchestrator for next iteration (Phase 2) or termination check
```
## Error Handling
| Error | Recovery |
|-------|----------|
| Agent fails to complete | Rollback from skill-snapshot: `cp -r "${iterDir}/skill-snapshot/${skill.name}/*" "${skill.path}/"` |
| Agent corrupts files | Same rollback from snapshot |
| Changes summary missing | Create minimal summary, continue |
| target_file not found | Agent skips suggestion, notes in summary |
## Output
- **Files**: `iteration-{N}-changes.md`, modified skill files
- **State**: `iterations[N-1].improvement` and `.status` updated
- **Next**: Return to orchestrator, begin next iteration (Phase 2) or terminate

View File

@@ -0,0 +1,166 @@
# Phase 5: Final Report
> **COMPACT SENTINEL [Phase 5: Report]**
> This phase contains 4 execution steps (Step 5.1 -- 5.4).
> If you can read this sentinel but cannot find the full Step protocol below, context has been compressed.
> Recovery: `Read("phases/05-report.md")`
Generate comprehensive iteration history report and display results to user.
## Objective
- Read complete iteration state
- Generate formatted final report with score progression
- Write final-report.md
- Display summary to user
## Execution
### Step 5.1: Read Complete State
```javascript
const state = JSON.parse(Read(`${state.work_dir}/iteration-state.json`));
state.status = 'completed';
state.updated_at = new Date().toISOString();
```
### Step 5.2: Generate Report
```javascript
// Determine outcome
const outcomeMap = {
quality_threshold_met: 'PASSED -- Quality threshold reached',
max_iterations_reached: 'MAX ITERATIONS -- Threshold not reached',
convergence_detected: 'CONVERGED -- Score stopped improving',
error_limit_reached: 'FAILED -- Too many errors'
};
const outcome = outcomeMap[state.termination_reason] || 'COMPLETED';
// Build score progression table
const scoreTable = state.iterations
.filter(i => i.evaluation)
.map(i => {
const dims = i.evaluation.dimensions || [];
const dimScores = ['clarity', 'completeness', 'correctness', 'effectiveness', 'efficiency']
.map(id => {
const dim = dims.find(d => d.id === id);
return dim ? dim.score : '-';
});
return `| ${i.round} | ${i.evaluation.score} | ${dimScores.join(' | ')} |`;
}).join('\n');
// Build iteration details
const iterationDetails = state.iterations.map(iter => {
const evalSection = iter.evaluation
? `**Score**: ${iter.evaluation.score}/100\n` +
`**Strengths**: ${iter.evaluation.strengths?.join(', ') || 'N/A'}\n` +
`**Weaknesses**: ${iter.evaluation.weaknesses?.slice(0, 3).join(', ') || 'N/A'}`
: '**Evaluation**: Skipped or failed';
const changesSection = iter.improvement
? `**Changes Applied**: ${iter.improvement.changes_applied?.length || 0}\n` +
(iter.improvement.changes_applied?.map(c => ` - ${c.summary}`).join('\n') || ' None')
: '**Improvements**: None';
return `### Iteration ${iter.round}\n${evalSection}\n${changesSection}`;
}).join('\n\n');
const report = `# Skill Iter Tune -- Final Report
## Summary
| Field | Value |
|-------|-------|
| **Target Skills** | ${state.target_skills.map(s => s.name).join(', ')} |
| **Execution Mode** | ${state.execution_mode} |
${state.execution_mode === 'chain' ? `| **Chain Order** | ${state.chain_order.join(' -> ')} |` : ''}
| **Test Scenario** | ${state.test_scenario.description} |
| **Iterations** | ${state.iterations.length} |
| **Initial Score** | ${state.score_trend[0] || 'N/A'} |
| **Final Score** | ${state.latest_score}/100 |
| **Quality Threshold** | ${state.quality_threshold} |
| **Outcome** | ${outcome} |
| **Started** | ${state.started_at} |
| **Completed** | ${state.updated_at} |
## Score Progression
| Iter | Composite | Clarity | Completeness | Correctness | Effectiveness | Efficiency |
|------|-----------|---------|--------------|-------------|---------------|------------|
${scoreTable}
**Trend**: ${state.score_trend.join(' -> ')}
${state.execution_mode === 'chain' ? `
## Chain Score Progression
| Iter | ${state.chain_order.join(' | ')} |
|------|${state.chain_order.map(() => '------').join('|')}|
${state.iterations.filter(i => i.evaluation?.chain_scores).map(i => {
const scores = state.chain_order.map(s => i.evaluation.chain_scores[s] || '-');
return `| ${i.round} | ${scores.join(' | ')} |`;
}).join('\n')}
` : ''}
## Iteration Details
${iterationDetails}
## Remaining Weaknesses
${state.iterations.length > 0 && state.iterations[state.iterations.length - 1].evaluation
? state.iterations[state.iterations.length - 1].evaluation.weaknesses?.map(w => `- ${w}`).join('\n') || 'None identified'
: 'No evaluation data available'}
## Artifact Locations
| Path | Description |
|------|-------------|
| \`${state.work_dir}/iteration-state.json\` | Complete state history |
| \`${state.work_dir}/iterations/iteration-{N}/iteration-{N}-eval.md\` | Per-iteration evaluations |
| \`${state.work_dir}/iterations/iteration-{N}/iteration-{N}-changes.md\` | Per-iteration change logs |
| \`${state.work_dir}/final-report.md\` | This report |
| \`${state.backup_dir}/\` | Original skill backups |
## Restore Original
To revert all changes and restore the original skill files:
\`\`\`bash
${state.target_skills.map(s => `cp -r "${state.backup_dir}/${s.name}"/* "${s.path}/"`).join('\n')}
\`\`\`
`;
```
### Step 5.3: Write Report and Update State
```javascript
Write(`${state.work_dir}/final-report.md`, report);
state.status = 'completed';
Write(`${state.work_dir}/iteration-state.json`, JSON.stringify(state, null, 2));
```
### Step 5.4: Display Summary to User
Output to user:
```
Skill Iter Tune Complete!
Target: {skill names}
Iterations: {count}
Score: {initial} -> {final} ({outcome})
Threshold: {threshold}
Score trend: {score1} -> {score2} -> ... -> {scoreN}
Full report: {workDir}/final-report.md
Backups: {backupDir}/
```
## Output
- **Files**: `final-report.md`
- **State**: `status = completed`
- **Next**: Workflow complete. Return control to user.

View File

@@ -0,0 +1,63 @@
# Evaluation Criteria
Skill 质量评估标准,由 Phase 03 (Evaluate) 引用。Gemini 按此标准对 skill 产出物进行多维度评分。
## Dimensions
| Dimension | Weight | ID | Description |
|-----------|--------|----|-------------|
| Clarity | 0.20 | clarity | 指令清晰无歧义结构良好易于遵循。Phase 文件有明确的 Step 划分、输入输出说明 |
| Completeness | 0.25 | completeness | 覆盖所有必要阶段、边界情况、错误处理。没有遗漏关键执行路径 |
| Correctness | 0.25 | correctness | 逻辑正确数据流一致Phase 间无矛盾。State schema 与实际使用匹配 |
| Effectiveness | 0.20 | effectiveness | 在给定测试场景下能产出高质量输出。产物满足用户需求和成功标准 |
| Efficiency | 0.10 | efficiency | 无冗余内容,上下文使用合理,不浪费 token。Phase 职责清晰无重叠 |
## Scoring Guide
| Range | Level | Description |
|-------|-------|-------------|
| 90-100 | Excellent | 生产级别,几乎无改进空间 |
| 80-89 | Good | 可投入使用,仅需微调 |
| 70-79 | Adequate | 功能可用,有明显可改进区域 |
| 60-69 | Needs Work | 存在影响产出质量的显著问题 |
| 0-59 | Poor | 结构或逻辑存在根本性问题 |
## Composite Score Calculation
```
composite = sum(dimension.score * dimension.weight)
```
## Output JSON Schema
```json
{
"composite_score": 75,
"dimensions": [
{ "name": "Clarity", "id": "clarity", "score": 80, "weight": 0.20, "feedback": "..." },
{ "name": "Completeness", "id": "completeness", "score": 70, "weight": 0.25, "feedback": "..." },
{ "name": "Correctness", "id": "correctness", "score": 78, "weight": 0.25, "feedback": "..." },
{ "name": "Effectiveness", "id": "effectiveness", "score": 72, "weight": 0.20, "feedback": "..." },
{ "name": "Efficiency", "id": "efficiency", "score": 85, "weight": 0.10, "feedback": "..." }
],
"strengths": ["...", "...", "..."],
"weaknesses": ["...", "...", "..."],
"suggestions": [
{
"priority": "high",
"target_file": "phases/02-execute.md",
"description": "Add explicit error handling for CLI timeout",
"rationale": "Current phase has no recovery path when CLI execution exceeds timeout",
"code_snippet": "optional suggested replacement code"
}
]
}
```
## Evaluation Focus by Iteration
| Iteration | Primary Focus |
|-----------|--------------|
| 1 | 全面评估,建立 baseline |
| 2-3 | 重点关注上一轮 weaknesses 是否改善,避免重复已解决的问题 |
| 4+ | 精细化改进,关注 Effectiveness 和 Efficiency |

View File

@@ -0,0 +1,134 @@
# Evaluation Prompt Template
Phase 03 使用此模板构造 ccw cli 提示词,让 Gemini 按多维度评估 skill 质量。
## Template
```
PURPOSE: Evaluate the quality of a workflow skill by examining both its definition files and the artifacts it produced when executed against a test scenario. Provide a structured multi-dimensional score with actionable improvement suggestions.
SKILL DEFINITION:
${skillContent}
TEST SCENARIO:
${testScenario.description}
Requirements: ${testScenario.requirements}
Success Criteria: ${testScenario.success_criteria}
ARTIFACTS PRODUCED:
${artifactsSummary}
EVALUATION CRITERIA:
${evaluationCriteria}
${previousEvalContext}
TASK:
1. Read all skill definition files and produced artifacts carefully
2. Score each dimension on 0-100 based on the evaluation criteria:
- Clarity (weight 0.20): Instructions unambiguous, well-structured, easy to follow
- Completeness (weight 0.25): All phases, edge cases, error handling covered
- Correctness (weight 0.25): Logic sound, data flow consistent, no contradictions
- Effectiveness (weight 0.20): Produces high-quality output for the test scenario
- Efficiency (weight 0.10): Minimal redundancy, appropriate context usage
3. Calculate weighted composite score
4. List top 3 strengths
5. List top 3-5 weaknesses with specific file:section references
6. Provide 3-5 prioritized improvement suggestions with concrete changes
MODE: analysis
EXPECTED OUTPUT FORMAT (strict JSON, no markdown wrapping):
{
"composite_score": <number 0-100>,
"dimensions": [
{ "name": "Clarity", "id": "clarity", "score": <0-100>, "weight": 0.20, "feedback": "<specific feedback>" },
{ "name": "Completeness", "id": "completeness", "score": <0-100>, "weight": 0.25, "feedback": "<specific feedback>" },
{ "name": "Correctness", "id": "correctness", "score": <0-100>, "weight": 0.25, "feedback": "<specific feedback>" },
{ "name": "Effectiveness", "id": "effectiveness", "score": <0-100>, "weight": 0.20, "feedback": "<specific feedback>" },
{ "name": "Efficiency", "id": "efficiency", "score": <0-100>, "weight": 0.10, "feedback": "<specific feedback>" }
],
"strengths": ["<strength 1>", "<strength 2>", "<strength 3>"],
"weaknesses": ["<weakness 1 with file:section reference>", "..."],
"suggestions": [
{
"priority": "high|medium|low",
"target_file": "<relative path to skill file>",
"description": "<what to change>",
"rationale": "<why this improves quality>",
"code_snippet": "<optional: suggested replacement content>"
}
],
"chain_scores": {
"<skill_name>": "<number 0-100, per-skill score — only present in chain mode>"
}
}
CONSTRAINTS:
- Be rigorous and specific — reference exact file paths and sections
- Each suggestion MUST include a target_file that maps to a skill file
- Focus suggestions on highest-impact changes first
- Do NOT suggest changes already addressed in previous iterations
- Output ONLY the JSON object, no surrounding text or markdown
```
## Variable Substitution
| Variable | Source | Description |
|----------|--------|-------------|
| `${skillContent}` | Same as execute-prompt.md | 完整 skill 文件内容 |
| `${testScenario.*}` | iteration-state.json | 测试场景信息 |
| `${artifactsSummary}` | Phase 03 reads artifacts/ dir | 产出物文件列表 + 内容摘要 |
| `${evaluationCriteria}` | specs/evaluation-criteria.md | 评分标准全文 |
| `${previousEvalContext}` | 历史迭代记录 | 前几轮评估摘要(避免重复建议) |
| `${chainContext}` | Phase 03 constructs | chain 模式下的链上下文信息 |
## previousEvalContext Construction
```javascript
// Build context from prior iterations to avoid repeating suggestions
const previousEvalContext = state.iterations.length > 0
? `PREVIOUS ITERATIONS (context for avoiding duplicate suggestions):
${state.iterations.map(iter => `
Iteration ${iter.round}: Score ${iter.evaluation?.score || 'N/A'}
Applied changes: ${iter.improvement?.changes_applied?.map(c => c.summary).join('; ') || 'none'}
Remaining weaknesses: ${iter.evaluation?.weaknesses?.slice(0, 3).join('; ') || 'none'}
`).join('')}
IMPORTANT: Focus on NEW issues or issues NOT adequately addressed in previous improvements.`
: '';
```
## chainContext Construction
```javascript
// Build chain context for evaluation (chain mode only)
const chainContext = state.execution_mode === 'chain'
? `CHAIN CONTEXT:
This skill chain contains ${state.chain_order.length} skills executed in order:
${state.chain_order.map((s, i) => `${i+1}. ${s}`).join('\n')}
Current evaluation covers the entire chain output.
Please provide per-skill quality scores in an additional "chain_scores" field.`
: '';
```
## artifactsSummary Construction
```javascript
// Read manifest.json if available, otherwise list files
const manifestPath = `${iterDir}/artifacts/manifest.json`;
let artifactsSummary;
if (fileExists(manifestPath)) {
const manifest = JSON.parse(Read(manifestPath));
artifactsSummary = manifest.artifacts.map(a =>
`- ${a.path}: ${a.description} (Phase ${a.phase})`
).join('\n');
} else {
// Fallback: list all files with first 200 lines each
const files = Glob(`${iterDir}/artifacts/**/*`);
artifactsSummary = files.map(f => {
const content = Read(f, { limit: 200 });
return `--- ${f.replace(iterDir + '/artifacts/', '')} ---\n${content}`;
}).join('\n\n');
}
```

View File

@@ -0,0 +1,97 @@
# Execute Prompt Template
Phase 02 使用此模板构造 ccw cli 提示词,让 Claude 模拟执行 skill 并产出所有预期产物。
## Template
```
PURPOSE: Simulate executing the following workflow skill against a test scenario. Produce all expected output artifacts as if the skill were invoked with the given input. This is for evaluating skill quality.
SKILL CONTENT:
${skillContent}
TEST SCENARIO:
Description: ${testScenario.description}
Input Arguments: ${testScenario.input_args}
Requirements: ${testScenario.requirements}
Success Criteria: ${testScenario.success_criteria}
TASK:
1. Study the complete skill structure (SKILL.md + all phase files)
2. Follow the skill's execution flow sequentially (Phase 1 → Phase N)
3. For each phase, produce the artifacts that phase would generate
4. Write all output artifacts to the current working directory
5. Create a manifest.json listing all produced artifacts with descriptions
MODE: write
CONTEXT: @**/*
EXPECTED:
- All artifacts the skill would produce for this test scenario
- Each artifact in its correct relative path
- A manifest.json at root: { "artifacts": [{ "path": "...", "description": "...", "phase": N }] }
CONSTRAINTS:
- Follow the skill execution flow exactly — do not skip or reorder phases
- Produce realistic, high-quality output (not placeholder content)
- If the skill requires user interaction (AskUserQuestion), use reasonable defaults
- If the skill invokes external tools/CLIs, document what would be called but produce expected output directly
```
## Variable Substitution
| Variable | Source | Description |
|----------|--------|-------------|
| `${skillContent}` | Phase 02 reads all skill files | 完整 SKILL.md + phase 文件内容,用 markdown headers 分隔 |
| `${testScenario.description}` | iteration-state.json | 用户描述的测试场景 |
| `${testScenario.input_args}` | iteration-state.json | 模拟传给 skill 的参数 |
| `${testScenario.requirements}` | iteration-state.json | 质量要求列表 |
| `${testScenario.success_criteria}` | iteration-state.json | 成功标准定义 |
## Chain Mode Extension
When running in chain mode, the template is invoked once per skill in `chain_order`. Each invocation includes:
### Additional Variable
| Variable | Source | Description |
|----------|--------|-------------|
| `${previousChainOutput}` | Phase 02 chain loop | 前序 skill 的 artifacts 摘要 (chain 模式下非首个 skill) |
### Chain Prompt Modification
When `execution_mode === 'chain'`, the prompt includes:
```
PREVIOUS CHAIN OUTPUT (from upstream skill "${previousSkillName}"):
${previousChainOutput}
IMPORTANT: Use the above output as input context for this skill's execution.
```
This section is only added for skills at position 2+ in the chain. The first skill in the chain receives no upstream context.
## skillContent Construction
```javascript
// Read only executable skill files and format with consistent headers
const skillMd = Read(`${skill.path}/SKILL.md`);
const phaseFiles = Glob(`${skill.path}/phases/*.md`).map(f => ({
relativePath: f.replace(skill.path + '/', ''),
content: Read(f)
}));
const specFiles = Glob(`${skill.path}/specs/*.md`).map(f => ({
relativePath: f.replace(skill.path + '/', ''),
content: Read(f)
}));
const skillContent = `
### File: SKILL.md
${skillMd}
${phaseFiles.map(f => `### File: ${f.relativePath}\n${f.content}`).join('\n\n')}
${specFiles.length > 0 ? specFiles.map(f => `### File: ${f.relativePath}\n${f.content}`).join('\n\n') : ''}
`.trim();
```

View File

@@ -148,7 +148,7 @@ AskUserQuestion({
|----------|------------| |----------|------------|
| Unknown --role value | Error with role registry list | | Unknown --role value | Error with role registry list |
| Role file not found | Error with expected path (roles/{name}/role.md) | | Role file not found | Error with expected path (roles/{name}/role.md) |
| project-tech.json missing | Coordinator invokes /workflow:init | | project-tech.json missing | Coordinator invokes /workflow:spec:setup |
| Phase verification fails with gaps | Coordinator triggers gap closure loop (max 3 iterations) | | Phase verification fails with gaps | Coordinator triggers gap closure loop (max 3 iterations) |
| Max gap closure iterations (3) | Report to user, ask for guidance | | Max gap closure iterations (3) | Report to user, ask for guidance |
| Worker crash | Respawn worker, reassign task | | Worker crash | Respawn worker, reassign task |

View File

@@ -284,7 +284,7 @@ Delegate to `commands/monitor.md`:
| Scenario | Resolution | | Scenario | Resolution |
|----------|------------| |----------|------------|
| project-tech.json missing | Invoke /workflow:init automatically | | project-tech.json missing | Invoke /workflow:spec:setup automatically |
| User cancels roadmap discussion | Save session state, exit gracefully | | User cancels roadmap discussion | Save session state, exit gracefully |
| Planner fails | Retry once, then ask user for guidance | | Planner fails | Retry once, then ask user for guidance |
| Executor fails on plan | Mark plan as failed, continue with next | | Executor fails on plan | Mark plan as failed, continue with next |

View File

@@ -85,7 +85,7 @@
"init_prerequisite": { "init_prerequisite": {
"required_files": [".workflow/project-tech.json"], "required_files": [".workflow/project-tech.json"],
"optional_files": [".workflow/specs/*.md"], "optional_files": [".workflow/specs/*.md"],
"init_command": "/workflow:init" "init_command": "/workflow:spec:setup "
}, },
"_metadata": { "_metadata": {
"created_at": "2026-02-24", "created_at": "2026-02-24",

Binary file not shown.

Before

Width:  |  Height:  |  Size: 166 KiB

BIN
assets/wechat-group-qr.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 226 KiB

View File

@@ -85,7 +85,7 @@ function setupDefaultMocks() {
vi.mocked(useNotifications).mockReturnValue({ vi.mocked(useNotifications).mockReturnValue({
success: mockToastSuccess, success: mockToastSuccess,
error: mockToastError, error: mockToastError,
} as ReturnType<typeof useNotifications>); } as unknown as ReturnType<typeof useNotifications>);
} }
describe('AdvancedTab', () => { describe('AdvancedTab', () => {

View File

@@ -61,6 +61,7 @@ const mockConfig: CodexLensConfig = {
const mockEnv: Record<string, string> = { const mockEnv: Record<string, string> = {
CODEXLENS_EMBEDDING_BACKEND: 'local', CODEXLENS_EMBEDDING_BACKEND: 'local',
CODEXLENS_EMBEDDING_MODEL: 'fast', CODEXLENS_EMBEDDING_MODEL: 'fast',
CODEXLENS_AUTO_EMBED_MISSING: 'true',
CODEXLENS_USE_GPU: 'true', CODEXLENS_USE_GPU: 'true',
CODEXLENS_RERANKER_ENABLED: 'true', CODEXLENS_RERANKER_ENABLED: 'true',
CODEXLENS_RERANKER_BACKEND: 'onnx', CODEXLENS_RERANKER_BACKEND: 'onnx',
@@ -141,6 +142,7 @@ describe('SettingsTab', () => {
expect(screen.getByText(/Concurrency/i)).toBeInTheDocument(); expect(screen.getByText(/Concurrency/i)).toBeInTheDocument();
expect(screen.getByText(/Cascade/i)).toBeInTheDocument(); expect(screen.getByText(/Cascade/i)).toBeInTheDocument();
expect(screen.getByText(/Chunking/i)).toBeInTheDocument(); expect(screen.getByText(/Chunking/i)).toBeInTheDocument();
expect(screen.getByText(/Auto Build Missing Vectors/i)).toBeInTheDocument();
}); });
it('should initialize index dir from config', () => { it('should initialize index dir from config', () => {

View File

@@ -56,6 +56,13 @@ export const envVarGroupsSchema: EnvVarGroupsSchema = {
}, },
], ],
}, },
CODEXLENS_AUTO_EMBED_MISSING: {
key: 'CODEXLENS_AUTO_EMBED_MISSING',
labelKey: 'codexlens.envField.autoEmbedMissing',
type: 'checkbox',
default: 'true',
settingsPath: 'embedding.auto_embed_missing',
},
CODEXLENS_USE_GPU: { CODEXLENS_USE_GPU: {
key: 'CODEXLENS_USE_GPU', key: 'CODEXLENS_USE_GPU',
labelKey: 'codexlens.envField.useGpu', labelKey: 'codexlens.envField.useGpu',

View File

@@ -256,8 +256,22 @@ export function McpServerDialog({
// Parse JSON config and populate form // Parse JSON config and populate form
const parseJsonConfig = useCallback(() => { const parseJsonConfig = useCallback(() => {
try { try {
const config = JSON.parse(jsonInput); let config = JSON.parse(jsonInput);
let extractedServerName = '';
// Auto-detect mcpServers wrapper format (Claude Code config format)
// Supports both: { "mcpServers": { "name": {...} } } and direct { "command": ... }
if (config.mcpServers && typeof config.mcpServers === 'object' && !Array.isArray(config.mcpServers)) {
const serverNames = Object.keys(config.mcpServers);
if (serverNames.length > 0) {
extractedServerName = serverNames[0];
const serverConfig = config.mcpServers[extractedServerName];
if (serverConfig && typeof serverConfig === 'object') {
config = serverConfig;
}
}
}
// Detect transport type based on config structure // Detect transport type based on config structure
if (config.url) { if (config.url) {
// HTTP transport // HTTP transport
@@ -278,6 +292,7 @@ export function McpServerDialog({
setFormData(prev => ({ setFormData(prev => ({
...prev, ...prev,
name: extractedServerName || prev.name,
url: config.url || '', url: config.url || '',
headers, headers,
bearerTokenEnvVar: config.bearer_token_env_var || config.bearerTokenEnvVar || '', bearerTokenEnvVar: config.bearer_token_env_var || config.bearerTokenEnvVar || '',
@@ -291,6 +306,7 @@ export function McpServerDialog({
setFormData(prev => ({ setFormData(prev => ({
...prev, ...prev,
name: extractedServerName || prev.name,
command: config.command || '', command: config.command || '',
args, args,
env, env,

View File

@@ -6,13 +6,10 @@ import { VersionCheckModal } from './VersionCheckModal';
interface VersionData { interface VersionData {
currentVersion: string; currentVersion: string;
latestVersion: string; latestVersion: string;
updateAvailable: boolean; hasUpdate: boolean;
} packageName?: string;
updateCommand?: string;
interface VersionCheckResponse { checkedAt?: string;
success: boolean;
data?: VersionData;
error?: string;
} }
/** /**
@@ -42,30 +39,26 @@ export function VersionCheck() {
const checkVersion = async (silent = false) => { const checkVersion = async (silent = false) => {
if (!silent) setChecking(true); if (!silent) setChecking(true);
try { try {
const response = await fetch('/api/config/version'); const response = await fetch('/api/version-check');
if (!response.ok) { if (!response.ok) {
throw new Error(`HTTP ${response.status}: ${response.statusText}`); throw new Error(`HTTP ${response.status}: ${response.statusText}`);
} }
const data: VersionCheckResponse = await response.json(); const data: VersionData = await response.json();
// Validate response structure // Validate response structure
if (!data || typeof data !== 'object') { if (!data || typeof data !== 'object') {
throw new Error('Invalid response format'); throw new Error('Invalid response format');
} }
if (!data.success) { if (!data.currentVersion) {
throw new Error(data.error || 'Version check failed');
}
if (!data.data || typeof data.data !== 'object') {
throw new Error('Invalid version data in response'); throw new Error('Invalid version data in response');
} }
setVersionData(data.data); setVersionData(data);
if (data.data.updateAvailable && !silent) { if (data.hasUpdate && !silent) {
toast.info('新版本可用: ' + data.data.latestVersion); toast.info('新版本可用: ' + data.latestVersion);
} }
} catch (error) { } catch (error) {
console.error('Version check failed:', error); console.error('Version check failed:', error);
@@ -98,7 +91,7 @@ export function VersionCheck() {
localStorage.setItem('ccw.autoUpdate', JSON.stringify(enabled)); localStorage.setItem('ccw.autoUpdate', JSON.stringify(enabled));
}; };
if (!versionData?.updateAvailable) { if (!versionData?.hasUpdate) {
return null; // Don't show anything if no update return null; // Don't show anything if no update
} }

View File

@@ -298,6 +298,7 @@
"envField": { "envField": {
"backend": "Backend", "backend": "Backend",
"model": "Model", "model": "Model",
"autoEmbedMissing": "Auto Build Missing Vectors",
"useGpu": "Use GPU", "useGpu": "Use GPU",
"highAvailability": "High Availability", "highAvailability": "High Availability",
"loadBalanceStrategy": "Load Balance Strategy", "loadBalanceStrategy": "Load Balance Strategy",

View File

@@ -102,6 +102,6 @@
}, },
"empty": { "empty": {
"title": "No Project Overview", "title": "No Project Overview",
"message": "Run /workflow:init to initialize project analysis" "message": "Run /workflow:spec:setup to initialize project analysis"
} }
} }

View File

@@ -298,6 +298,7 @@
"envField": { "envField": {
"backend": "后端", "backend": "后端",
"model": "模型", "model": "模型",
"autoEmbedMissing": "缺失向量时自动构建",
"useGpu": "使用 GPU", "useGpu": "使用 GPU",
"highAvailability": "高可用", "highAvailability": "高可用",
"loadBalanceStrategy": "负载均衡策略", "loadBalanceStrategy": "负载均衡策略",

View File

@@ -102,6 +102,6 @@
}, },
"empty": { "empty": {
"title": "暂无项目概览", "title": "暂无项目概览",
"message": "运行 /workflow:init 初始化项目分析" "message": "运行 /workflow:spec:setup 初始化项目分析"
} }
} }

View File

@@ -306,15 +306,17 @@ export async function installCommand(options: InstallOptions): Promise<void> {
info(` Files in manifest: ${existingManifest.files?.length || 0}`); info(` Files in manifest: ${existingManifest.files?.length || 0}`);
info(` Installed: ${new Date(existingManifest.installation_date).toLocaleDateString()}`); info(` Installed: ${new Date(existingManifest.installation_date).toLocaleDateString()}`);
const { backup } = await inquirer.prompt([{ if (!options.force) {
type: 'confirm', const { backup } = await inquirer.prompt([{
name: 'backup', type: 'confirm',
message: 'Create backup before reinstalling?', name: 'backup',
default: true message: 'Create backup before reinstalling?',
}]); default: true
}]);
if (backup) { if (backup) {
await createBackup(existingManifest); await createBackup(existingManifest);
}
} }
// Clean based on manifest records // Clean based on manifest records
@@ -495,7 +497,7 @@ export async function installCommand(options: InstallOptions): Promise<void> {
}); });
// Install Git Bash fix on Windows // Install Git Bash fix on Windows
if (platform() === 'win32') { if (platform() === 'win32' && !options.force) {
console.log(''); console.log('');
const { installFix } = await inquirer.prompt([{ const { installFix } = await inquirer.prompt([{
type: 'confirm', type: 'confirm',

View File

@@ -955,6 +955,9 @@ export async function handleCodexLensConfigRoutes(ctx: RouteContext): Promise<bo
if (settings.embedding?.use_gpu !== undefined) { if (settings.embedding?.use_gpu !== undefined) {
settingsDefaults['CODEXLENS_USE_GPU'] = String(settings.embedding.use_gpu); settingsDefaults['CODEXLENS_USE_GPU'] = String(settings.embedding.use_gpu);
} }
if (settings.embedding?.auto_embed_missing !== undefined) {
settingsDefaults['CODEXLENS_AUTO_EMBED_MISSING'] = String(settings.embedding.auto_embed_missing);
}
if (settings.embedding?.strategy) { if (settings.embedding?.strategy) {
settingsDefaults['CODEXLENS_EMBEDDING_STRATEGY'] = settings.embedding.strategy; settingsDefaults['CODEXLENS_EMBEDDING_STRATEGY'] = settings.embedding.strategy;
} }
@@ -1219,6 +1222,7 @@ export async function handleCodexLensConfigRoutes(ctx: RouteContext): Promise<bo
'CODEXLENS_EMBEDDING_BACKEND': { path: ['embedding', 'backend'] }, 'CODEXLENS_EMBEDDING_BACKEND': { path: ['embedding', 'backend'] },
'CODEXLENS_EMBEDDING_MODEL': { path: ['embedding', 'model'] }, 'CODEXLENS_EMBEDDING_MODEL': { path: ['embedding', 'model'] },
'CODEXLENS_USE_GPU': { path: ['embedding', 'use_gpu'], transform: v => v === 'true' }, 'CODEXLENS_USE_GPU': { path: ['embedding', 'use_gpu'], transform: v => v === 'true' },
'CODEXLENS_AUTO_EMBED_MISSING': { path: ['embedding', 'auto_embed_missing'], transform: v => v === 'true' },
'CODEXLENS_EMBEDDING_STRATEGY': { path: ['embedding', 'strategy'] }, 'CODEXLENS_EMBEDDING_STRATEGY': { path: ['embedding', 'strategy'] },
'CODEXLENS_EMBEDDING_COOLDOWN': { path: ['embedding', 'cooldown'], transform: v => parseFloat(v) }, 'CODEXLENS_EMBEDDING_COOLDOWN': { path: ['embedding', 'cooldown'], transform: v => parseFloat(v) },
'CODEXLENS_RERANKER_BACKEND': { path: ['reranker', 'backend'] }, 'CODEXLENS_RERANKER_BACKEND': { path: ['reranker', 'backend'] },

View File

@@ -20,6 +20,7 @@ const SERVER_VERSION = '6.2.0';
// Environment variable names for documentation // Environment variable names for documentation
const ENV_PROJECT_ROOT = 'CCW_PROJECT_ROOT'; const ENV_PROJECT_ROOT = 'CCW_PROJECT_ROOT';
const ENV_ALLOWED_DIRS = 'CCW_ALLOWED_DIRS'; const ENV_ALLOWED_DIRS = 'CCW_ALLOWED_DIRS';
const STDIO_DISCONNECT_ERROR_CODES = new Set(['EPIPE', 'ERR_STREAM_DESTROYED']);
// Default enabled tools (core set - file operations, core memory, and smart search) // Default enabled tools (core set - file operations, core memory, and smart search)
const DEFAULT_TOOLS: string[] = ['write_file', 'edit_file', 'read_file', 'read_many_files', 'read_outline', 'core_memory', 'smart_search']; const DEFAULT_TOOLS: string[] = ['write_file', 'edit_file', 'read_file', 'read_many_files', 'read_outline', 'core_memory', 'smart_search'];
@@ -67,6 +68,47 @@ function formatToolResult(result: unknown): string {
return String(result); return String(result);
} }
/**
* Detect broken stdio pipes so orphaned MCP processes can terminate cleanly.
*/
function isStdioDisconnectError(error: unknown): error is NodeJS.ErrnoException {
if (error && typeof error === 'object') {
const maybeErrnoError = error as NodeJS.ErrnoException;
if (typeof maybeErrnoError.code === 'string' && STDIO_DISCONNECT_ERROR_CODES.has(maybeErrnoError.code)) {
return true;
}
}
return error instanceof Error && /broken pipe/i.test(error.message);
}
/**
* Best-effort logging for teardown paths where stderr may already be gone.
*/
function safeStderrWrite(message: string): void {
try {
if (process.stderr.destroyed || !process.stderr.writable) {
return;
}
process.stderr.write(`${message}\n`);
} catch {
// Ignore logging failures while stdio is tearing down.
}
}
function safeLogError(prefix: string, error: unknown): void {
if (error instanceof Error) {
safeStderrWrite(`${prefix}: ${error.message}`);
if (error.stack) {
safeStderrWrite(error.stack);
}
return;
}
safeStderrWrite(`${prefix}: ${String(error)}`);
}
/** /**
* Create and configure the MCP server * Create and configure the MCP server
*/ */
@@ -151,28 +193,77 @@ function createServer(): Server {
async function main(): Promise<void> { async function main(): Promise<void> {
const server = createServer(); const server = createServer();
const transport = new StdioServerTransport(); const transport = new StdioServerTransport();
let shutdownPromise: Promise<void> | null = null;
const shutdown = (reason: string, exitCode = 0, error?: unknown): Promise<void> => {
if (shutdownPromise) {
return shutdownPromise;
}
if (error && !isStdioDisconnectError(error)) {
safeLogError(`[${SERVER_NAME}] ${reason}`, error);
}
shutdownPromise = (async () => {
try {
await server.close();
} catch (closeError) {
if (!isStdioDisconnectError(closeError)) {
safeLogError(`[${SERVER_NAME}] Failed to close server`, closeError);
}
}
process.exit(exitCode);
})();
return shutdownPromise;
};
const handleStreamClose = (streamName: string) => () => {
void shutdown(`${streamName} disconnected`);
};
const handleStreamError = (streamName: string) => (error: unknown) => {
const exitCode = isStdioDisconnectError(error) ? 0 : 1;
void shutdown(`${streamName} stream error`, exitCode, error);
};
// Connect server to transport // Connect server to transport
await server.connect(transport); await server.connect(transport);
// Error handling - prevent process crashes from closing transport process.stdin.once('end', handleStreamClose('stdin'));
process.stdin.once('close', handleStreamClose('stdin'));
process.stdin.once('error', handleStreamError('stdin'));
process.stdout.once('close', handleStreamClose('stdout'));
process.stdout.once('error', handleStreamError('stdout'));
process.stderr.once('close', handleStreamClose('stderr'));
process.stderr.once('error', handleStreamError('stderr'));
// Error handling - stdio disconnects should terminate, other errors stay logged.
process.on('uncaughtException', (error) => { process.on('uncaughtException', (error) => {
console.error(`[${SERVER_NAME}] Uncaught exception:`, error.message); if (isStdioDisconnectError(error)) {
console.error(error.stack); void shutdown('Uncaught stdio disconnect', 0, error);
return;
}
safeLogError(`[${SERVER_NAME}] Uncaught exception`, error);
}); });
process.on('unhandledRejection', (reason) => { process.on('unhandledRejection', (reason) => {
console.error(`[${SERVER_NAME}] Unhandled rejection:`, reason); if (isStdioDisconnectError(reason)) {
void shutdown('Unhandled stdio disconnect', 0, reason);
return;
}
safeLogError(`[${SERVER_NAME}] Unhandled rejection`, reason);
}); });
process.on('SIGINT', async () => { process.on('SIGINT', async () => {
await server.close(); await shutdown('Received SIGINT');
process.exit(0);
}); });
process.on('SIGTERM', async () => { process.on('SIGTERM', async () => {
await server.close(); await shutdown('Received SIGTERM');
process.exit(0);
}); });
// Log server start (to stderr to not interfere with stdio protocol) // Log server start (to stderr to not interfere with stdio protocol)

View File

@@ -35,29 +35,6 @@ import {
saveConversation saveConversation
} from './cli-executor-state.js'; } from './cli-executor-state.js';
// Debug logging for history save investigation (Iteration 4)
const DEBUG_SESSION_ID = 'DBG-parallel-ccw-cli-test-2026-03-07';
const DEBUG_LOG_PATH = path.join(process.cwd(), '.workflow', '.debug', DEBUG_SESSION_ID, 'debug-save.log');
// Ensure debug log directory exists
try {
const debugDir = path.dirname(DEBUG_LOG_PATH);
if (!fs.existsSync(debugDir)) {
fs.mkdirSync(debugDir, { recursive: true });
}
} catch (err) {
// Ignore directory creation errors
}
function writeDebugLog(event: string, data: Record<string, any>): void {
try {
const logEntry = JSON.stringify({ event, ...data, timestamp: new Date().toISOString() }) + '\n';
fs.appendFileSync(DEBUG_LOG_PATH, logEntry, 'utf8');
} catch (err) {
// Silently ignore logging errors
}
}
// Track all running child processes for cleanup on interruption (multi-process support) // Track all running child processes for cleanup on interruption (multi-process support)
const runningChildProcesses = new Set<ChildProcess>(); const runningChildProcesses = new Set<ChildProcess>();
@@ -1296,11 +1273,8 @@ async function executeCliTool(
}; };
// Try to save conversation to history // Try to save conversation to history
try { try {
writeDebugLog('BEFORE_SAVE_CONV', { conversationId: conversation.id, workingDir, tool });
saveConversation(workingDir, conversation); saveConversation(workingDir, conversation);
writeDebugLog('AFTER_SAVE_CONV', { conversationId: conversation.id, workingDir, tool });
} catch (err) { } catch (err) {
writeDebugLog('SAVE_CONV_OUTER_ERROR', { conversationId: conversation.id, workingDir, tool, error: (err as Error).message, stack: (err as Error).stack });
// Non-fatal: continue even if history save fails // Non-fatal: continue even if history save fails
console.error('[CLI Executor] Failed to save history:', (err as Error).message); console.error('[CLI Executor] Failed to save history:', (err as Error).message);
} }

View File

@@ -9,29 +9,6 @@ import type { CliOutputUnit } from './cli-output-converter.js';
import * as fs from 'fs'; import * as fs from 'fs';
import * as path from 'path'; import * as path from 'path';
// Debug logging for history save investigation (Iteration 4)
const DEBUG_SESSION_ID = 'DBG-parallel-ccw-cli-test-2026-03-07';
const DEBUG_LOG_PATH = path.join(process.cwd(), '.workflow', '.debug', DEBUG_SESSION_ID, 'debug-save.log');
// Ensure debug log directory exists
try {
const debugDir = path.dirname(DEBUG_LOG_PATH);
if (!fs.existsSync(debugDir)) {
fs.mkdirSync(debugDir, { recursive: true });
}
} catch (err) {
// Ignore directory creation errors
}
function writeDebugLog(event: string, data: Record<string, any>): void {
try {
const logEntry = JSON.stringify({ event, ...data, timestamp: new Date().toISOString() }) + '\n';
fs.appendFileSync(DEBUG_LOG_PATH, logEntry, 'utf8');
} catch (err) {
// Silently ignore logging errors
}
}
// Lazy-loaded SQLite store module // Lazy-loaded SQLite store module
let sqliteStoreModule: typeof import('./cli-history-store.js') | null = null; let sqliteStoreModule: typeof import('./cli-history-store.js') | null = null;
@@ -39,10 +16,8 @@ let sqliteStoreModule: typeof import('./cli-history-store.js') | null = null;
* Get or initialize SQLite store (async) * Get or initialize SQLite store (async)
*/ */
export async function getSqliteStore(baseDir: string) { export async function getSqliteStore(baseDir: string) {
writeDebugLog('GET_STORE', { baseDir, baseDirType: typeof baseDir, moduleInitialized: sqliteStoreModule !== null });
if (!sqliteStoreModule) { if (!sqliteStoreModule) {
sqliteStoreModule = await import('./cli-history-store.js'); sqliteStoreModule = await import('./cli-history-store.js');
writeDebugLog('MODULE_LOADED', { baseDir });
} }
return sqliteStoreModule.getHistoryStore(baseDir); return sqliteStoreModule.getHistoryStore(baseDir);
} }
@@ -163,20 +138,15 @@ async function saveConversationAsync(baseDir: string, conversation: Conversation
* @param baseDir - Project base directory (NOT historyDir) * @param baseDir - Project base directory (NOT historyDir)
*/ */
export function saveConversation(baseDir: string, conversation: ConversationRecord): void { export function saveConversation(baseDir: string, conversation: ConversationRecord): void {
writeDebugLog('SAVE_CONV_START', { baseDir, conversationId: conversation.id, moduleInitialized: sqliteStoreModule !== null });
try { try {
const store = getSqliteStoreSync(baseDir); const store = getSqliteStoreSync(baseDir);
writeDebugLog('SAVE_CONV_SYNC', { baseDir, conversationId: conversation.id });
// Fire and forget - don't block on async save in sync context // Fire and forget - don't block on async save in sync context
store.saveConversation(conversation).catch(err => { store.saveConversation(conversation).catch(err => {
writeDebugLog('SAVE_CONV_ERROR', { baseDir, conversationId: conversation.id, error: err.message, stack: err.stack });
console.error('[CLI Executor] Failed to save conversation:', err.message); console.error('[CLI Executor] Failed to save conversation:', err.message);
}); });
} catch (err) { } catch (err) {
writeDebugLog('SAVE_CONV_FALLBACK_ASYNC', { baseDir, conversationId: conversation.id, error: (err as Error).message });
// If sync not available, queue for async save // If sync not available, queue for async save
saveConversationAsync(baseDir, conversation).catch(err => { saveConversationAsync(baseDir, conversation).catch(err => {
writeDebugLog('SAVE_CONV_ASYNC_ERROR', { baseDir, conversationId: conversation.id, error: err.message, stack: err.stack });
console.error('[CLI Executor] Failed to save conversation:', err.message); console.error('[CLI Executor] Failed to save conversation:', err.message);
}); });
} }

View File

@@ -11,29 +11,6 @@ import { getDiscoverer, getNativeSessions } from './native-session-discovery.js'
import { StoragePaths, ensureStorageDir, getProjectId, getCCWHome } from '../config/storage-paths.js'; import { StoragePaths, ensureStorageDir, getProjectId, getCCWHome } from '../config/storage-paths.js';
import { createOutputParser, flattenOutputUnits, type CliOutputUnit } from './cli-output-converter.js'; import { createOutputParser, flattenOutputUnits, type CliOutputUnit } from './cli-output-converter.js';
// Debug logging for history save investigation (Iteration 4)
const DEBUG_SESSION_ID = 'DBG-parallel-ccw-cli-test-2026-03-07';
const DEBUG_LOG_PATH = join(process.cwd(), '.workflow', '.debug', DEBUG_SESSION_ID, 'debug-save.log');
// Ensure debug log directory exists
try {
const debugDir = dirname(DEBUG_LOG_PATH);
if (!existsSync(debugDir)) {
mkdirSync(debugDir, { recursive: true });
}
} catch (err) {
// Ignore directory creation errors
}
function writeDebugLog(event: string, data: Record<string, any>): void {
try {
const logEntry = JSON.stringify({ event, ...data, timestamp: new Date().toISOString() }) + '\n';
appendFileSync(DEBUG_LOG_PATH, logEntry, 'utf8');
} catch (err) {
// Silently ignore logging errors
}
}
function reconstructFinalOutputFromStdout(rawStdout: string, canTrustStdout: boolean): string | undefined { function reconstructFinalOutputFromStdout(rawStdout: string, canTrustStdout: boolean): string | undefined {
if (!canTrustStdout || !rawStdout.trim()) { if (!canTrustStdout || !rawStdout.trim()) {
return undefined; return undefined;
@@ -154,29 +131,22 @@ export class CliHistoryStore {
private projectPath: string; private projectPath: string;
constructor(baseDir: string) { constructor(baseDir: string) {
writeDebugLog('STORE_CONSTRUCT_START', { baseDir });
this.projectPath = baseDir; this.projectPath = baseDir;
// Use centralized storage path // Use centralized storage path
const paths = StoragePaths.project(baseDir); const paths = StoragePaths.project(baseDir);
const historyDir = paths.cliHistory; const historyDir = paths.cliHistory;
writeDebugLog('STORAGE_PATHS', { baseDir, historyDir, historyDb: paths.historyDb });
ensureStorageDir(historyDir); ensureStorageDir(historyDir);
this.dbPath = paths.historyDb; this.dbPath = paths.historyDb;
writeDebugLog('DB_INSTANCE_CREATE', { dbPath: this.dbPath });
this.db = new Database(this.dbPath); this.db = new Database(this.dbPath);
writeDebugLog('DB_INSTANCE_CREATED', { dbPath: this.dbPath });
this.db.pragma('journal_mode = WAL'); this.db.pragma('journal_mode = WAL');
this.db.pragma('synchronous = NORMAL'); this.db.pragma('synchronous = NORMAL');
this.db.pragma('busy_timeout = 10000'); // Wait up to 10 seconds for locks (increased for write-heavy scenarios) this.db.pragma('busy_timeout = 10000'); // Wait up to 10 seconds for locks (increased for write-heavy scenarios)
this.db.pragma('wal_autocheckpoint = 1000'); // Optimize WAL checkpointing this.db.pragma('wal_autocheckpoint = 1000'); // Optimize WAL checkpointing
writeDebugLog('INIT_SCHEMA_START', { dbPath: this.dbPath });
this.initSchema(); this.initSchema();
writeDebugLog('INIT_SCHEMA_COMPLETE', { dbPath: this.dbPath });
this.migrateFromJson(historyDir); this.migrateFromJson(historyDir);
writeDebugLog('STORE_CONSTRUCT_COMPLETE', { baseDir, dbPath: this.dbPath });
} }
/** /**

File diff suppressed because it is too large Load Diff

View File

@@ -11,26 +11,46 @@ import { dirname, join } from 'node:path';
const __filename = fileURLToPath(import.meta.url); const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename); const __dirname = dirname(__filename);
const serverPath = join(__dirname, '../bin/ccw-mcp.js');
async function waitForServerStart(child) {
await new Promise((resolve, reject) => {
const timeout = setTimeout(() => {
reject(new Error('Server start timeout'));
}, 5000);
const onData = (data) => {
const message = data.toString();
if (message.includes('started')) {
clearTimeout(timeout);
child.stderr.off('data', onData);
child.off('exit', onExit);
resolve();
}
};
const onExit = (code, signal) => {
clearTimeout(timeout);
child.stderr.off('data', onData);
reject(new Error(`Server exited before start (code=${code}, signal=${signal})`));
};
child.stderr.on('data', onData);
child.once('exit', onExit);
});
}
describe('MCP Server', () => { describe('MCP Server', () => {
let serverProcess; let serverProcess;
before(async () => { before(async () => {
// Start the MCP server // Start the MCP server
const serverPath = join(__dirname, '../bin/ccw-mcp.js');
serverProcess = spawn('node', [serverPath], { serverProcess = spawn('node', [serverPath], {
stdio: ['pipe', 'pipe', 'pipe'] stdio: ['pipe', 'pipe', 'pipe']
}); });
// Wait for server to start // Wait for server to start
await new Promise((resolve) => { await waitForServerStart(serverProcess);
serverProcess.stderr.once('data', (data) => {
const message = data.toString();
if (message.includes('started')) {
resolve();
}
});
});
}); });
after(() => { after(() => {
@@ -157,4 +177,43 @@ describe('MCP Server', () => {
// Error could be "not enabled" (filtered by default tools) or "not found" (all tools enabled) // Error could be "not enabled" (filtered by default tools) or "not found" (all tools enabled)
assert(response.result.content[0].text.includes('not enabled') || response.result.content[0].text.includes('not found')); assert(response.result.content[0].text.includes('not enabled') || response.result.content[0].text.includes('not found'));
}); });
it('should exit when stdout disconnects during a request', async () => {
const disconnectedProcess = spawn('node', [serverPath], {
stdio: ['pipe', 'pipe', 'pipe']
});
try {
await waitForServerStart(disconnectedProcess);
const exitPromise = new Promise((resolve, reject) => {
const timeout = setTimeout(() => {
disconnectedProcess.kill('SIGKILL');
reject(new Error('Server did not exit after stdout disconnect'));
}, 1500);
disconnectedProcess.once('exit', (code, signal) => {
clearTimeout(timeout);
resolve({ code, signal });
});
});
// Simulate the MCP client disappearing before the server sends its response.
disconnectedProcess.stdout.destroy();
disconnectedProcess.stdin.write(JSON.stringify({
jsonrpc: '2.0',
id: 4,
method: 'tools/list',
params: {}
}) + '\n');
const exitResult = await exitPromise;
assert.equal(exitResult.code, 0);
assert.equal(exitResult.signal, null);
} finally {
if (disconnectedProcess.exitCode === null) {
disconnectedProcess.kill('SIGKILL');
}
}
});
}); });

View File

@@ -45,6 +45,19 @@ describe('Smart Search MCP usage defaults and path handling', async () => {
assert.match(props.apiMaxWorkers.description, /endpoint pool/i); assert.match(props.apiMaxWorkers.description, /endpoint pool/i);
assert.match(schema.description, /apiMaxWorkers=8/i); assert.match(schema.description, /apiMaxWorkers=8/i);
assert.match(props.path.description, /single file path/i); assert.match(props.path.description, /single file path/i);
assert.ok(props.output_mode.enum.includes('ace'));
assert.match(props.output_mode.description, /ACE-style/i);
assert.equal(props.output_mode.default, 'ace');
});
it('defaults auto embedding warmup to enabled unless explicitly disabled', () => {
if (!smartSearchModule) return;
const { __testables } = smartSearchModule;
assert.equal(__testables.isAutoEmbedMissingEnabled(undefined), true);
assert.equal(__testables.isAutoEmbedMissingEnabled({}), true);
assert.equal(__testables.isAutoEmbedMissingEnabled({ embedding_auto_embed_missing: true }), true);
assert.equal(__testables.isAutoEmbedMissingEnabled({ embedding_auto_embed_missing: false }), false);
}); });
it('honors explicit small limit values', async () => { it('honors explicit small limit values', async () => {
@@ -58,6 +71,7 @@ describe('Smart Search MCP usage defaults and path handling', async () => {
action: 'search', action: 'search',
query: 'hit', query: 'hit',
path: dir, path: dir,
output_mode: 'full',
limit: 1, limit: 1,
regex: false, regex: false,
tokenize: false, tokenize: false,
@@ -82,6 +96,7 @@ describe('Smart Search MCP usage defaults and path handling', async () => {
action: 'search', action: 'search',
query: 'TARGET_TOKEN', query: 'TARGET_TOKEN',
path: target, path: target,
output_mode: 'full',
regex: false, regex: false,
tokenize: false, tokenize: false,
}); });
@@ -112,6 +127,7 @@ describe('Smart Search MCP usage defaults and path handling', async () => {
action: 'search', action: 'search',
query: wrappedQuery, query: wrappedQuery,
path: wrappedPath, path: wrappedPath,
output_mode: 'full',
regex: false, regex: false,
caseSensitive: false, caseSensitive: false,
}); });
@@ -121,6 +137,66 @@ describe('Smart Search MCP usage defaults and path handling', async () => {
assert.ok(toolResult.result.results.length >= 1); assert.ok(toolResult.result.results.length >= 1);
}); });
it('falls back to literal ripgrep matching for invalid regex-like code queries', async () => {
if (!smartSearchModule) return;
const dir = createWorkspace();
const target = join(dir, 'component.ts');
writeFileSync(target, 'defineExpose({ handleResize });\n');
const toolResult = await smartSearchModule.handler({
action: 'search',
query: 'defineExpose({ handleResize',
path: dir,
output_mode: 'full',
limit: 5,
});
assert.equal(toolResult.success, true, toolResult.error);
assert.equal(toolResult.result.success, true);
assert.ok(toolResult.result.results.length >= 1);
assert.match(toolResult.result.metadata.warning, /literal ripgrep matching/i);
});
it('renders grouped ace-style output by default with multi-line chunks', async () => {
if (!smartSearchModule) return;
const dir = createWorkspace();
const target = join(dir, 'ace-target.ts');
writeFileSync(target, [
'const before = 1;',
'const TARGET_TOKEN = 1;',
'const after = 2;',
'',
'function useToken() {',
' return TARGET_TOKEN;',
'}',
].join('\n'));
const toolResult = await smartSearchModule.handler({
action: 'search',
query: 'TARGET_TOKEN',
path: dir,
contextLines: 1,
regex: false,
tokenize: false,
});
assert.equal(toolResult.success, true, toolResult.error);
assert.equal(toolResult.result.success, true);
assert.equal(toolResult.result.results.format, 'ace');
assert.equal(Array.isArray(toolResult.result.results.groups), true);
assert.equal(Array.isArray(toolResult.result.results.sections), true);
assert.equal(toolResult.result.results.groups.length, 1);
assert.equal(toolResult.result.results.groups[0].sections.length, 2);
assert.match(toolResult.result.results.text, /The following code sections were retrieved:/);
assert.match(toolResult.result.results.text, /Path: .*ace-target\.ts/);
assert.match(toolResult.result.results.text, /Chunk 1: lines 1-3/);
assert.match(toolResult.result.results.text, />\s+2 \| const TARGET_TOKEN = 1;/);
assert.match(toolResult.result.results.text, /Chunk 2: lines 5-7/);
assert.equal(toolResult.result.metadata.pagination.total >= 1, true);
});
it('defaults embed selection to local-fast for bulk indexing', () => { it('defaults embed selection to local-fast for bulk indexing', () => {
if (!smartSearchModule) return; if (!smartSearchModule) return;
@@ -181,6 +257,50 @@ describe('Smart Search MCP usage defaults and path handling', async () => {
assert.equal(smartSearchModule.__testables.hasCentralizedVectorArtifacts(dir), true); assert.equal(smartSearchModule.__testables.hasCentralizedVectorArtifacts(dir), true);
}); });
it('recognizes CodexLens CLI compatibility failures and invalid regex fallback', () => {
if (!smartSearchModule) return;
const compatibilityError = [
'UsageError: Got unexpected extra arguments (20 0 fts)',
'TypeError: TyperArgument.make_metavar() takes 1 positional argument but 2 were given',
].join('\n');
assert.equal(
smartSearchModule.__testables.isCodexLensCliCompatibilityError(compatibilityError),
true,
);
const resolution = smartSearchModule.__testables.resolveRipgrepQueryMode(
'defineExpose({ handleResize',
true,
true,
);
assert.equal(resolution.regex, false);
assert.equal(resolution.literalFallback, true);
assert.match(resolution.warning, /literal ripgrep matching/i);
});
it('builds actionable index suggestions for unhealthy index states', () => {
if (!smartSearchModule) return;
const suggestions = smartSearchModule.__testables.buildIndexSuggestions(
{
indexed: true,
has_embeddings: false,
embeddings_coverage_percent: 0,
warning: 'Index exists but no embeddings generated. Run smart_search(action="embed") to build the vector index.',
},
{
workingDirectory: 'D:/tmp/demo',
searchPaths: ['.'],
},
);
assert.equal(Array.isArray(suggestions), true);
assert.match(suggestions[0].command, /smart_search\(action="embed"/);
});
it('surfaces backend failure details when fuzzy search fully fails', async () => { it('surfaces backend failure details when fuzzy search fully fails', async () => {
if (!smartSearchModule) return; if (!smartSearchModule) return;
@@ -189,6 +309,7 @@ describe('Smart Search MCP usage defaults and path handling', async () => {
action: 'search', action: 'search',
query: 'TARGET_TOKEN', query: 'TARGET_TOKEN',
path: missingPath, path: missingPath,
output_mode: 'full',
regex: false, regex: false,
tokenize: false, tokenize: false,
}); });

View File

@@ -1566,6 +1566,8 @@ def config(
result["embedding_backend"] = embedding["backend"] result["embedding_backend"] = embedding["backend"]
if embedding.get("model"): if embedding.get("model"):
result["embedding_model"] = embedding["model"] result["embedding_model"] = embedding["model"]
if embedding.get("auto_embed_missing") is not None:
result["embedding_auto_embed_missing"] = embedding["auto_embed_missing"]
except (json.JSONDecodeError, OSError): except (json.JSONDecodeError, OSError):
pass # Settings file not readable, continue with defaults pass # Settings file not readable, continue with defaults
@@ -1584,6 +1586,10 @@ def config(
if env_overrides.get("EMBEDDING_BACKEND"): if env_overrides.get("EMBEDDING_BACKEND"):
result["embedding_backend"] = env_overrides["EMBEDDING_BACKEND"] result["embedding_backend"] = env_overrides["EMBEDDING_BACKEND"]
result["embedding_backend_source"] = ".env" result["embedding_backend_source"] = ".env"
auto_embed_missing_override = env_overrides.get("CODEXLENS_AUTO_EMBED_MISSING") or env_overrides.get("AUTO_EMBED_MISSING")
if auto_embed_missing_override:
result["embedding_auto_embed_missing"] = auto_embed_missing_override.lower() in ("true", "1", "yes", "on")
result["embedding_auto_embed_missing_source"] = ".env"
if env_overrides.get("RERANKER_MODEL"): if env_overrides.get("RERANKER_MODEL"):
result["reranker_model"] = env_overrides["RERANKER_MODEL"] result["reranker_model"] = env_overrides["RERANKER_MODEL"]
result["reranker_model_source"] = ".env" result["reranker_model_source"] = ".env"
@@ -1613,6 +1619,9 @@ def config(
model = result.get('embedding_model', 'code') model = result.get('embedding_model', 'code')
model_source = result.get('embedding_model_source', 'settings.json') model_source = result.get('embedding_model_source', 'settings.json')
console.print(f" Model: {model} [dim]({model_source})[/dim]") console.print(f" Model: {model} [dim]({model_source})[/dim]")
auto_embed_missing = result.get("embedding_auto_embed_missing", True)
auto_embed_missing_source = result.get("embedding_auto_embed_missing_source", "settings.json")
console.print(f" Auto Embed Missing: {auto_embed_missing} [dim]({auto_embed_missing_source})[/dim]")
# Show reranker settings # Show reranker settings
console.print(f"\n[bold]Reranker[/bold]") console.print(f"\n[bold]Reranker[/bold]")
@@ -1647,7 +1656,7 @@ def config(
# Handle reranker and embedding settings (stored in settings.json) # Handle reranker and embedding settings (stored in settings.json)
elif key in ("reranker_backend", "reranker_model", "reranker_enabled", "reranker_top_k", elif key in ("reranker_backend", "reranker_model", "reranker_enabled", "reranker_top_k",
"embedding_backend", "embedding_model", "reranker_api_provider"): "embedding_backend", "embedding_model", "embedding_auto_embed_missing", "reranker_api_provider"):
settings_file = Path.home() / ".codexlens" / "settings.json" settings_file = Path.home() / ".codexlens" / "settings.json"
settings_file.parent.mkdir(parents=True, exist_ok=True) settings_file.parent.mkdir(parents=True, exist_ok=True)
@@ -1680,6 +1689,8 @@ def config(
settings["embedding"]["backend"] = value settings["embedding"]["backend"] = value
elif key == "embedding_model": elif key == "embedding_model":
settings["embedding"]["model"] = value settings["embedding"]["model"] = value
elif key == "embedding_auto_embed_missing":
settings["embedding"]["auto_embed_missing"] = value.lower() in ("true", "1", "yes", "on")
# Save settings # Save settings
settings_file.write_text(json.dumps(settings, indent=2), encoding="utf-8") settings_file.write_text(json.dumps(settings, indent=2), encoding="utf-8")

View File

@@ -110,6 +110,7 @@ class Config:
embedding_model: str = "code" # For fastembed: profile (fast/code/multilingual/balanced) embedding_model: str = "code" # For fastembed: profile (fast/code/multilingual/balanced)
# For litellm: model name from config (e.g., "qwen3-embedding") # For litellm: model name from config (e.g., "qwen3-embedding")
embedding_use_gpu: bool = True # For fastembed: whether to use GPU acceleration embedding_use_gpu: bool = True # For fastembed: whether to use GPU acceleration
embedding_auto_embed_missing: bool = True # Auto-build embeddings in background when indexed projects are searched without vectors
# Indexing/search optimizations # Indexing/search optimizations
global_symbol_index_enabled: bool = True # Enable project-wide symbol index fast path global_symbol_index_enabled: bool = True # Enable project-wide symbol index fast path
@@ -281,6 +282,7 @@ class Config:
"backend": self.embedding_backend, "backend": self.embedding_backend,
"model": self.embedding_model, "model": self.embedding_model,
"use_gpu": self.embedding_use_gpu, "use_gpu": self.embedding_use_gpu,
"auto_embed_missing": self.embedding_auto_embed_missing,
"pool_enabled": self.embedding_pool_enabled, "pool_enabled": self.embedding_pool_enabled,
"strategy": self.embedding_strategy, "strategy": self.embedding_strategy,
"cooldown": self.embedding_cooldown, "cooldown": self.embedding_cooldown,
@@ -376,6 +378,8 @@ class Config:
self.embedding_model = embedding["model"] self.embedding_model = embedding["model"]
if "use_gpu" in embedding: if "use_gpu" in embedding:
self.embedding_use_gpu = embedding["use_gpu"] self.embedding_use_gpu = embedding["use_gpu"]
if "auto_embed_missing" in embedding:
self.embedding_auto_embed_missing = embedding["auto_embed_missing"]
# Load multi-endpoint configuration # Load multi-endpoint configuration
if "endpoints" in embedding: if "endpoints" in embedding:
@@ -782,6 +786,14 @@ class Config:
else: else:
log.warning("Invalid EMBEDDING_BACKEND in .env: %r", embedding_backend) log.warning("Invalid EMBEDDING_BACKEND in .env: %r", embedding_backend)
auto_embed_missing = get_env("AUTO_EMBED_MISSING")
if auto_embed_missing:
self.embedding_auto_embed_missing = _parse_bool(auto_embed_missing)
log.debug(
"Overriding embedding_auto_embed_missing from .env: %s",
self.embedding_auto_embed_missing,
)
embedding_pool = get_env("EMBEDDING_POOL_ENABLED") embedding_pool = get_env("EMBEDDING_POOL_ENABLED")
if embedding_pool: if embedding_pool:
value = embedding_pool.lower() value = embedding_pool.lower()

View File

@@ -33,6 +33,7 @@ ENV_VARS = {
# Embedding configuration (overrides settings.json) # Embedding configuration (overrides settings.json)
"EMBEDDING_MODEL": "Embedding model/profile name (overrides settings.json)", "EMBEDDING_MODEL": "Embedding model/profile name (overrides settings.json)",
"EMBEDDING_BACKEND": "Embedding backend: fastembed, litellm", "EMBEDDING_BACKEND": "Embedding backend: fastembed, litellm",
"AUTO_EMBED_MISSING": "Auto-build embeddings in background when indexed projects are searched without vectors: true/false",
"EMBEDDING_API_KEY": "API key for embedding service", "EMBEDDING_API_KEY": "API key for embedding service",
"EMBEDDING_API_BASE": "Base URL for embedding API", "EMBEDDING_API_BASE": "Base URL for embedding API",
"EMBEDDING_POOL_ENABLED": "Enable embedding high availability pool: true/false", "EMBEDDING_POOL_ENABLED": "Enable embedding high availability pool: true/false",

View File

@@ -37,7 +37,7 @@
| [`/workflow-multi-cli-plan`](./workflow.md#multi-cli-plan) | 多 CLI 协作规划 | Intermediate | | [`/workflow-multi-cli-plan`](./workflow.md#multi-cli-plan) | 多 CLI 协作规划 | Intermediate |
| [`/workflow:review`](./workflow.md#review) | 实现后审查 | Intermediate | | [`/workflow:review`](./workflow.md#review) | 实现后审查 | Intermediate |
| [`/workflow:clean`](./workflow.md#clean) | 智能代码清理 | Intermediate | | [`/workflow:clean`](./workflow.md#clean) | 智能代码清理 | Intermediate |
| [`/workflow:init`](./workflow.md#init) | 初始化项目状态 | Intermediate | | [`/workflow:spec:setup `](./workflow.md#init) | 初始化项目状态 | Intermediate |
| [`/workflow:brainstorm-with-file`](./workflow.md#brainstorm-with-file) | 交互式头脑风暴 | Intermediate | | [`/workflow:brainstorm-with-file`](./workflow.md#brainstorm-with-file) | 交互式头脑风暴 | Intermediate |
| [`/workflow:analyze-with-file`](./workflow.md#analyze-with-file) | 交互式协作分析 | Beginner | | [`/workflow:analyze-with-file`](./workflow.md#analyze-with-file) | 交互式协作分析 | Beginner |
| [`/workflow:debug-with-file`](./workflow.md#debug-with-file) | 交互式假设驱动调试 | Intermediate | | [`/workflow:debug-with-file`](./workflow.md#debug-with-file) | 交互式假设驱动调试 | Intermediate |

View File

@@ -37,7 +37,7 @@
| [`/workflow-multi-cli-plan`](./workflow.md#multi-cli-plan) | Multi-CLI collaborative planning | Intermediate | | [`/workflow-multi-cli-plan`](./workflow.md#multi-cli-plan) | Multi-CLI collaborative planning | Intermediate |
| [`/workflow:review`](./workflow.md#review) | Post-implementation review | Intermediate | | [`/workflow:review`](./workflow.md#review) | Post-implementation review | Intermediate |
| [`/workflow:clean`](./workflow.md#clean) | Smart code cleanup | Intermediate | | [`/workflow:clean`](./workflow.md#clean) | Smart code cleanup | Intermediate |
| [`/workflow:init`](./workflow.md#init) | Initialize project state | Intermediate | | [`/workflow:spec:setup `](./workflow.md#init) | Initialize project state | Intermediate |
| [`/workflow:brainstorm-with-file`](./workflow.md#brainstorm-with-file) | Interactive brainstorming | Intermediate | | [`/workflow:brainstorm-with-file`](./workflow.md#brainstorm-with-file) | Interactive brainstorming | Intermediate |
| [`/workflow:analyze-with-file`](./workflow.md#analyze-with-file) | Interactive collaborative analysis | Beginner | | [`/workflow:analyze-with-file`](./workflow.md#analyze-with-file) | Interactive collaborative analysis | Beginner |
| [`/workflow:debug-with-file`](./workflow.md#debug-with-file) | Interactive hypothesis-driven debugging | Intermediate | | [`/workflow:debug-with-file`](./workflow.md#debug-with-file) | Interactive hypothesis-driven debugging | Intermediate |

View File

@@ -59,7 +59,7 @@
| Command | Function | Syntax | | Command | Function | Syntax |
|---------|----------|--------| |---------|----------|--------|
| [`clean`](#clean) | Smart code cleanup | `/workflow:clean [-y] [--dry-run] ["focus area"]` | | [`clean`](#clean) | Smart code cleanup | `/workflow:clean [-y] [--dry-run] ["focus area"]` |
| [`init`](#init) | Initialize project state | `/workflow:init [--regenerate]` | | [`init`](#init) | Initialize project state | `/workflow:spec:setup [--regenerate]` |
| [`plan-verify`](#plan-verify) | Verify planning consistency | `/workflow-plan-verify [--session session-id]` | | [`plan-verify`](#plan-verify) | Verify planning consistency | `/workflow-plan-verify [--session session-id]` |
## Command Details ## Command Details

View File

@@ -81,7 +81,7 @@ This creates a new workflow session. All subsequent operations will be performed
### 2.2.2 Initialize Project Specs ### 2.2.2 Initialize Project Specs
``` ```
/workflow:init /workflow:spec:setup
``` ```
This creates the `project-tech.json` file, recording your project's technology stack information. This creates the `project-tech.json` file, recording your project's technology stack information.
@@ -89,7 +89,7 @@ This creates the `project-tech.json` file, recording your project's technology s
### 2.2.3 Populate Project Specs ### 2.2.3 Populate Project Specs
``` ```
/workflow:init-guidelines /workflow:spec:setup -guidelines
``` ```
Interactively populate project specifications, including coding style, architectural decisions, and other information. Interactively populate project specifications, including coding style, architectural decisions, and other information.
@@ -282,7 +282,7 @@ npm install
/workflow:session:start /workflow:session:start
# 5. Initialize project # 5. Initialize project
/workflow:init /workflow:spec:setup
``` ```
### Common Commands ### Common Commands

View File

@@ -50,7 +50,7 @@ Create a simple workflow in under 5 minutes:
# Prompt: "Fix the login timeout issue" # Execute without confirmation prompts # Prompt: "Fix the login timeout issue" # Execute without confirmation prompts
# Or use specific workflow commands # Or use specific workflow commands
/workflow:init # Initialize project state /workflow:spec:setup # Initialize project state
/workflow-plan /workflow-plan
# Prompt: "Add OAuth2 authentication" # Create implementation plan # Prompt: "Add OAuth2 authentication" # Create implementation plan
/workflow-execute # Execute planned tasks /workflow-execute # Execute planned tasks

View File

@@ -74,7 +74,7 @@ To check available CCW commands, you can list them:
Available CCW Commands: Available CCW Commands:
- /ccw - Main workflow orchestrator - /ccw - Main workflow orchestrator
- /ccw-coordinator - External CLI orchestration - /ccw-coordinator - External CLI orchestration
- /workflow:init - Initialize project configuration - /workflow:spec:setup - Initialize project configuration
- /workflow:status - Generate project views - /workflow:status - Generate project views
- /issue:discover - Discover and plan issues - /issue:discover - Discover and plan issues
- /brainstorm - Multi-perspective brainstorming - /brainstorm - Multi-perspective brainstorming
@@ -145,7 +145,7 @@ Create `CLAUDE.md` in your project root to define project-specific instructions:
Initialize CCW in your project: Initialize CCW in your project:
``` ```
/workflow:init /workflow:spec:setup
``` ```
This creates `.workflow/project-tech.json` with your project's technology stack. This creates `.workflow/project-tech.json` with your project's technology stack.
@@ -343,7 +343,7 @@ After installation, try these commands to verify everything works:
``` ```
# 1. Initialize in your project # 1. Initialize in your project
/workflow:init /workflow:spec:setup
# 2. Try a simple analysis using the CLI tool # 2. Try a simple analysis using the CLI tool
Bash: ccw cli -p "Analyze the project structure" --tool gemini --mode analysis Bash: ccw cli -p "Analyze the project structure" --tool gemini --mode analysis
@@ -369,7 +369,7 @@ What would you like to accomplish? Please describe your task.
**Using workflow init:** **Using workflow init:**
``` ```
You: /workflow:init You: /workflow:spec:setup
✔ Created .workflow/project-tech.json ✔ Created .workflow/project-tech.json
✔ Project configuration complete ✔ Project configuration complete
``` ```

View File

@@ -98,16 +98,18 @@ Unified search with content search, file discovery, and semantic search.
{ {
"name": "smart_search", "name": "smart_search",
"parameters": { "parameters": {
"action": "search | find_files | init | status", "action": "search | find_files | init | init_force | embed | status | update | watch",
"query": "string (for search)", "query": "string (for search)",
"pattern": "glob pattern (for find_files)", "pattern": "glob pattern (for find_files)",
"mode": "fuzzy | semantic (default: fuzzy)", "mode": "fuzzy | semantic (default: fuzzy)",
"output_mode": "full | files_only | count", "output_mode": "ace | full | files_only | count (default: ace)",
"maxResults": "number (default: 20)" "maxResults": "number (default: 5)"
} }
} }
``` ```
`search` now defaults to `output_mode: "ace"`, which groups results by file and renders multi-line code chunks. When the index is missing, embeddings are incomplete, or status parsing looks unhealthy, the response metadata includes actionable `smart_search(...)` suggestions such as `init`, `status`, or `embed`. If an index exists but vectors are missing, `smart_search` can also start a background embedding build automatically when `CODEXLENS_AUTO_EMBED_MISSING` is enabled (default: `true`).
**Usage:** **Usage:**
```javascript ```javascript
// Fuzzy search (default) // Fuzzy search (default)

View File

@@ -37,7 +37,7 @@
| [`/workflow-multi-cli-plan`](./workflow.md#multi-cli-plan) | 多 CLI 协作规划 | Intermediate | | [`/workflow-multi-cli-plan`](./workflow.md#multi-cli-plan) | 多 CLI 协作规划 | Intermediate |
| [`/workflow:review`](./workflow.md#review) | 实现后审查 | Intermediate | | [`/workflow:review`](./workflow.md#review) | 实现后审查 | Intermediate |
| [`/workflow:clean`](./workflow.md#clean) | 智能代码清理 | Intermediate | | [`/workflow:clean`](./workflow.md#clean) | 智能代码清理 | Intermediate |
| [`/workflow:init`](./workflow.md#init) | 初始化项目状态 | Intermediate | | [`/workflow:spec:setup `](./workflow.md#init) | 初始化项目状态 | Intermediate |
| [`/workflow:brainstorm-with-file`](./workflow.md#brainstorm-with-file) | 交互式头脑风暴 | Intermediate | | [`/workflow:brainstorm-with-file`](./workflow.md#brainstorm-with-file) | 交互式头脑风暴 | Intermediate |
| [`/workflow:analyze-with-file`](./workflow.md#analyze-with-file) | 交互式协作分析 | Beginner | | [`/workflow:analyze-with-file`](./workflow.md#analyze-with-file) | 交互式协作分析 | Beginner |
| [`/workflow:debug-with-file`](./workflow.md#debug-with-file) | 交互式假设驱动调试 | Intermediate | | [`/workflow:debug-with-file`](./workflow.md#debug-with-file) | 交互式假设驱动调试 | Intermediate |

View File

@@ -59,7 +59,7 @@
| 命令 | 功能 | 语法 | | 命令 | 功能 | 语法 |
| --- | --- | --- | | --- | --- | --- |
| [`clean`](#clean) | 智能代码清理 | `/workflow:clean [-y] [--dry-run] ["焦点区域"]` | | [`clean`](#clean) | 智能代码清理 | `/workflow:clean [-y] [--dry-run] ["焦点区域"]` |
| [`init`](#init) | 初始化项目状态 | `/workflow:init [--regenerate]` | | [`init`](#init) | 初始化项目状态 | `/workflow:spec:setup [--regenerate]` |
| [`plan-verify`](#plan-verify) | 验证规划一致性 | `/workflow-plan-verify [--session session-id]` | | [`plan-verify`](#plan-verify) | 验证规划一致性 | `/workflow-plan-verify [--session session-id]` |
## 命令详解 ## 命令详解

View File

@@ -67,7 +67,7 @@ API Keys 也可以在项目级别配置 `.claude/settings.json`,项目级配
### 2.2.2 初始化项目规范 ### 2.2.2 初始化项目规范
``` ```
/workflow:init /workflow:spec:setup
``` ```
这会创建 `project-tech.json` 文件,记录项目的技术栈信息。 这会创建 `project-tech.json` 文件,记录项目的技术栈信息。
@@ -75,7 +75,7 @@ API Keys 也可以在项目级别配置 `.claude/settings.json`,项目级配
### 2.2.3 填充项目规范 ### 2.2.3 填充项目规范
``` ```
/workflow:init-guidelines /workflow:spec:setup -guidelines
``` ```
交互式填充项目规范,包括编码风格、架构决策等信息。 交互式填充项目规范,包括编码风格、架构决策等信息。
@@ -272,7 +272,7 @@ npm install
/workflow:session:start /workflow:session:start
# 5. 初始化项目 # 5. 初始化项目
/workflow:init /workflow:spec:setup
``` ```
### 常用命令 ### 常用命令

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{ {
"name": "claude-code-workflow", "name": "claude-code-workflow",
"version": "7.2.4", "version": "7.2.7",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "claude-code-workflow", "name": "claude-code-workflow",
"version": "7.2.4", "version": "7.2.7",
"hasInstallScript": true, "hasInstallScript": true,
"license": "MIT", "license": "MIT",
"workspaces": [ "workspaces": [

View File

@@ -1,6 +1,6 @@
{ {
"name": "claude-code-workflow", "name": "claude-code-workflow",
"version": "7.2.5", "version": "7.2.7",
"description": "JSON-driven multi-agent development framework with intelligent CLI orchestration (Gemini/Qwen/Codex), context-first architecture, and automated workflow execution", "description": "JSON-driven multi-agent development framework with intelligent CLI orchestration (Gemini/Qwen/Codex), context-first architecture, and automated workflow execution",
"type": "module", "type": "module",
"main": "ccw/dist/index.js", "main": "ccw/dist/index.js",