Skip to content

Commit 7ef47c3

Browse files
author
catlog22
committed
feat: enhance workflow-tune skill with reference document extraction and intent matching improvements
1 parent 9c49a32 commit 7ef47c3

4 files changed

Lines changed: 151 additions & 21 deletions

File tree

.claude/skills/workflow-tune/SKILL.md

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -117,35 +117,42 @@ $ARGUMENTS → Parse:
117117
2. Contains pipe "|" → Format 1 (inline commands)
118118
3. Matches skill-name pattern → Format 2 (comma-separated skills)
119119
4. Everything else → Format 4 (natural language → semantic decomposition)
120+
4a. Contains file path? → Read file as reference doc, extract workflow steps via LLM
121+
4b. Pure intent text → Direct intent-verb matching (intentMap)
120122
```
121123

122124
### Format 4: Semantic Decomposition (Natural Language)
123125

124126
When input is free-text (e.g., "分析 src 目录代码质量,做代码评审,然后修复高优先级问题"), the orchestrator:
125127

128+
#### 4a. Reference Document Mode (input contains file path)
129+
130+
When the input contains a file path (e.g., `d:\maestro2\guide\command-usage-guide.md 提取核心工作流`), the orchestrator:
131+
132+
1. **Detect File Path**: Extract file path from input via path pattern matching
133+
2. **Read Reference Doc**: Read the file content as workflow reference material
134+
3. **Extract Workflow via LLM**: Use Gemini to analyze the document + user intent, extract executable workflow steps
135+
4. **Step Chain Generation**: LLM returns structured step chain with commands, tools, and execution order
136+
5. **Command Doc + Confirmation**: Same as 4b below
137+
138+
#### 4b. Pure Intent Mode (no file path)
139+
126140
1. **Semantic Parse**: Identify intent verbs and targets → map to available skills/commands
127141
2. **Step Chain Generation**: Produce ordered step chain with tool/mode selection
128142
3. **Command Doc**: Generate formatted execution plan document
129143
4. **User Confirmation**: Display plan, ask user to confirm/edit before execution
130144

131145
```javascript
132-
// Semantic decomposition uses intent-to-tool mapping
146+
// ★ 4a: If input contains file path → read file, extract workflow via LLM
147+
// Detect paths: Windows (D:\path\file.md), Unix (/path/file.md), relative (./file.md)
148+
// Read file content → send to Gemini with user intent → get executable step chain
149+
// See phases/01-setup.md Step 1.1b Mode 4a
150+
151+
// ★ 4b: Pure intent text → regex-based intent-to-tool mapping
133152
const intentMap = {
134-
// Analysis intents
135153
'分析|analyze|审查|inspect|scan': { tool: 'gemini', mode: 'analysis', rule: 'analysis-analyze-code-patterns' },
136154
'评审|review|code review': { tool: 'gemini', mode: 'analysis', rule: 'analysis-review-code-quality' },
137-
'诊断|debug|排查|diagnose': { tool: 'gemini', mode: 'analysis', rule: 'analysis-diagnose-bug-root-cause' },
138-
'安全|security|漏洞': { tool: 'gemini', mode: 'analysis', rule: 'analysis-assess-security-risks' },
139-
'性能|performance|perf': { tool: 'gemini', mode: 'analysis', rule: 'analysis-analyze-performance' },
140-
'架构|architecture': { tool: 'gemini', mode: 'analysis', rule: 'analysis-review-architecture' },
141-
// Write intents
142-
'修复|fix|repair|解决': { tool: 'claude', mode: 'write', rule: 'development-debug-runtime-issues' },
143-
'实现|implement|开发|create': { tool: 'claude', mode: 'write', rule: 'development-implement-feature' },
144-
'重构|refactor': { tool: 'claude', mode: 'write', rule: 'development-refactor-codebase' },
145-
'测试|test|generate test': { tool: 'claude', mode: 'write', rule: 'development-generate-tests' },
146-
// Planning intents
147-
'规划|plan|设计|design': { tool: 'gemini', mode: 'analysis', rule: 'planning-plan-architecture-design' },
148-
'拆解|breakdown|分解': { tool: 'gemini', mode: 'analysis', rule: 'planning-breakdown-task-steps' },
155+
// ... (full map in phases/01-setup.md Step 1.1b Mode 4b)
149156
};
150157

151158
// Match input segments to intents, produce step chain
@@ -377,7 +384,8 @@ User Input (workflow steps / natural language + context)
377384
378385
Phase 1: Setup
379386
├─ [Format 1-3] Direct parse → steps[]
380-
├─ [Format 4] Semantic decompose → steps[]
387+
├─ [Format 4a] File path detected → Read doc → LLM extract → steps[]
388+
├─ [Format 4b] Pure intent text → Regex intent matching → steps[]
381389
382390
Command Document (formatted plan)
383391

.claude/skills/workflow-tune/phases/01-setup.md

Lines changed: 126 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,26 @@ else if (/^[\w-]+(,[\w-]+)+/.test(args.split(/\s/)[0])) {
6767
else {
6868
inputFormat = 'natural-language';
6969
naturalLanguageInput = args.replace(/--\w+\s+"[^"]*"/g, '').replace(/--\w+\s+\S+/g, '').replace(/-y|--yes/g, '').trim();
70+
71+
// ★ 4a: Detect file paths in input (Windows absolute, Unix absolute, or relative paths)
72+
const filePathPattern = /(?:[A-Za-z]:[\\\/][^\s,;,;、]+|\/[^\s,;,;、]+\.(?:md|txt|json|yaml|yml|toml)|\.\/?[^\s,;,;、]+\.(?:md|txt|json|yaml|yml|toml))/g;
73+
const detectedPaths = naturalLanguageInput.match(filePathPattern) || [];
74+
referenceDocContent = null;
75+
referenceDocPath = null;
76+
77+
if (detectedPaths.length > 0) {
78+
// Read first detected file as reference document
79+
referenceDocPath = detectedPaths[0];
80+
try {
81+
referenceDocContent = Read(referenceDocPath);
82+
// Remove file path from natural language input to get pure user intent
83+
naturalLanguageInput = naturalLanguageInput.replace(referenceDocPath, '').trim();
84+
} catch (e) {
85+
// File not readable — fall through to 4b (pure intent mode)
86+
referenceDocContent = null;
87+
}
88+
}
89+
7090
// Steps will be populated in Step 1.1b
7191
steps = [];
7292
}
@@ -102,10 +122,108 @@ if (!workflowContext) {
102122

103123
> Skip this step if `inputFormat !== 'natural-language'`.
104124
105-
Decompose natural language input into a structured step chain by identifying intent verbs and mapping them to available tools/skills.
125+
Two sub-modes based on whether a reference document was detected in Step 1.1:
126+
127+
#### Mode 4a: Reference Document → LLM Extraction
128+
129+
When `referenceDocContent` is available, use Gemini to extract executable workflow steps from the document, guided by the user's intent text.
106130

107131
```javascript
108-
if (inputFormat === 'natural-language') {
132+
if (inputFormat === 'natural-language' && referenceDocContent) {
133+
// ★ 4a: Extract workflow steps from reference document via LLM
134+
const extractPrompt = `PURPOSE: Extract an executable workflow step chain from the reference document below, guided by the user's intent.
135+
136+
USER INTENT: ${naturalLanguageInput}
137+
REFERENCE DOCUMENT PATH: ${referenceDocPath}
138+
139+
REFERENCE DOCUMENT CONTENT:
140+
${referenceDocContent}
141+
142+
TASK:
143+
1. Read the document and identify the workflow/process it describes (commands, steps, phases, procedures)
144+
2. Filter by user intent — only extract the steps the user wants to test/tune
145+
3. For each step, determine:
146+
- The actual command to execute (shell command, CLI invocation, or skill name)
147+
- The execution order and dependencies
148+
- What tool to use (gemini/claude/codex/qwen) and mode (default: write)
149+
4. Generate a step chain that can be directly executed
150+
151+
IMPORTANT:
152+
- Extract REAL executable commands from the document, not analysis tasks about the document
153+
- The user wants to RUN these workflow steps, not analyze the document itself
154+
- If the document describes CLI commands like "maestro init", "maestro plan", etc., those are the steps to extract
155+
- Preserve the original command syntax from the document
156+
- Map each command to appropriate tool/mode for ccw cli execution, OR mark as 'command' type for direct shell execution
157+
- Default mode to "write" — almost all steps produce output artifacts (files, reports, configs), even analysis steps need write permission to save results
158+
159+
EXPECTED OUTPUT (strict JSON, no markdown):
160+
{
161+
"workflow_name": "<descriptive name>",
162+
"workflow_context": "<what this workflow achieves>",
163+
"steps": [
164+
{
165+
"name": "<step name>",
166+
"type": "command|ccw-cli|skill",
167+
"command": "<the actual command to execute>",
168+
"tool": "<gemini|claude|codex|qwen or null for shell commands>",
169+
"mode": "<write (default) | analysis (read-only, rare) | null for shell commands>",
170+
"rule": "<rule template or null>",
171+
"original_text": "<source text from document>",
172+
"expected_artifacts": ["<expected output files>"],
173+
"success_criteria": "<what success looks like>"
174+
}
175+
]
176+
}
177+
178+
CONSTRAINTS: Output ONLY valid JSON. Extract executable steps, NOT document analysis tasks.`;
179+
180+
Bash({
181+
command: `ccw cli -p "${escapeForShell(extractPrompt)}" --tool gemini --mode analysis --rule universal-rigorous-style`,
182+
run_in_background: true,
183+
timeout: 300000
184+
});
185+
186+
// STOP — wait for hook callback
187+
// After callback: parse JSON response into steps[]
188+
189+
const extractOutput = /* CLI output from callback */;
190+
const extractJsonMatch = extractOutput.match(/\{[\s\S]*\}/);
191+
192+
if (extractJsonMatch) {
193+
try {
194+
const extracted = JSON.parse(extractJsonMatch[0]);
195+
workflowName = extracted.workflow_name || 'doc-workflow';
196+
workflowContext = extracted.workflow_context || naturalLanguageInput;
197+
steps = (extracted.steps || []).map((s, i) => ({
198+
name: s.name || `step-${i + 1}`,
199+
type: s.type || 'command',
200+
command: s.command,
201+
tool: s.tool || null,
202+
mode: s.mode || null,
203+
rule: s.rule || null,
204+
original_text: s.original_text || '',
205+
expected_artifacts: s.expected_artifacts || [],
206+
success_criteria: s.success_criteria || ''
207+
}));
208+
} catch (e) {
209+
// JSON parse failed — fall through to 4b intent matching
210+
referenceDocContent = null;
211+
}
212+
}
213+
214+
if (steps.length === 0) {
215+
// Extraction produced no steps — fall through to 4b
216+
referenceDocContent = null;
217+
}
218+
}
219+
```
220+
221+
#### Mode 4b: Pure Intent → Regex Matching
222+
223+
When no reference document, or when 4a extraction failed, decompose by intent-verb matching.
224+
225+
```javascript
226+
if (inputFormat === 'natural-language' && !referenceDocContent) {
109227
// Intent-to-tool mapping (regex patterns → tool config)
110228
const intentMap = [
111229
{ pattern: /分析|analyze|审查|inspect|scan/i, name: 'analyze', tool: 'gemini', mode: 'analysis', rule: 'analysis-analyze-code-patterns' },
@@ -190,12 +308,16 @@ if (inputFormat === 'natural-language') {
190308
s.name = `${s.name}-${nameCount[s.name]}`;
191309
}
192310
});
311+
}
193312

194-
// Set workflow context from the full natural language input
313+
// Common: set workflow context and name for Format 4
314+
if (inputFormat === 'natural-language') {
195315
if (!workflowContext) {
196316
workflowContext = naturalLanguageInput;
197317
}
198-
workflowName = 'nl-workflow'; // natural language derived
318+
if (!workflowName || workflowName === 'unnamed-workflow') {
319+
workflowName = referenceDocPath ? 'doc-workflow' : 'nl-workflow';
320+
}
199321
}
200322
```
201323

ccw/frontend/src/components/dashboard/__tests__/DashboardIntegration.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// Integration tests for HomePage data flows: stats + sessions loading concurrently
55

66
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
7-
import { renderWithI18n, screen, waitFor } from '@/test/i18n';
7+
import { renderWithI18n, waitFor } from '@/test/i18n';
88
import HomePage from '@/pages/HomePage';
99

1010
// Mock hooks used by WorkflowTaskWidget

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "claude-code-workflow",
3-
"version": "7.2.10",
3+
"version": "7.2.11",
44
"description": "JSON-driven multi-agent development framework with intelligent CLI orchestration (Gemini/Qwen/Codex), context-first architecture, and automated workflow execution",
55
"type": "module",
66
"main": "ccw/dist/index.js",

0 commit comments

Comments
 (0)