mirror of
https://github.com/catlog22/Claude-Code-Workflow.git
synced 2026-02-13 02:41:50 +08:00
feat: 增强 command-guide skill 支持深度命令分析和 CLI 辅助查询
新增 Mode 6: 深度命令分析 - 创建 reference 备份目录(80个文档:11 agents + 69 commands) - 支持简单查询(直接文件查找)和复杂查询(CLI 辅助分析) - 集成 gemini/qwen 进行跨命令对比、最佳实践、工作流分析 - 添加查询复杂度自动分类和降级策略 更新文档 - SKILL.md: 添加 Mode 6 说明和 Reference Documentation 章节 - implementation-details.md: 添加完整的 Mode 6 实现逻辑 - 版本更新至 v1.3.0 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -9,9 +9,11 @@ User Query
|
||||
↓
|
||||
Intent Recognition
|
||||
↓
|
||||
Mode Selection (1 of 5)
|
||||
Mode Selection (1 of 6)
|
||||
↓
|
||||
Index/File Query
|
||||
Index/File/Reference Query
|
||||
↓
|
||||
Optional CLI Analysis (Mode 6)
|
||||
↓
|
||||
Response Formation
|
||||
↓
|
||||
@@ -51,6 +53,15 @@ function recognizeIntent(userQuery) {
|
||||
// Mode 3: Documentation
|
||||
if (query.includes('参数') || query.includes('怎么用') ||
|
||||
query.includes('如何使用') || query.match(/\/\w+:\w+.*详情/)) {
|
||||
|
||||
// Special case: CLI tools usage guide
|
||||
if (query.match(/cli.*工具/) || query.match(/如何.*使用.*cli/) ||
|
||||
query.match(/gemini|qwen|codex.*使用/) || query.match(/优雅.*使用/) ||
|
||||
query.includes('cli能力') || query.includes('cli特性') ||
|
||||
query.includes('语义调用') || query.includes('命令调用')) {
|
||||
return 'CLI_TOOLS_GUIDE';
|
||||
}
|
||||
|
||||
return 'DOCUMENTATION';
|
||||
}
|
||||
|
||||
@@ -60,6 +71,17 @@ function recognizeIntent(userQuery) {
|
||||
return 'ONBOARDING';
|
||||
}
|
||||
|
||||
// Mode 6: Deep Command Analysis
|
||||
// Triggered by specific command/agent names or complexity indicators
|
||||
if (query.match(/\/\w+:\w+/) || // Contains command name pattern
|
||||
query.match(/agent.*工作|实现.*原理|命令.*细节/) || // Asks about internals
|
||||
query.includes('详细说明') || query.includes('实现细节') ||
|
||||
query.match(/对比.*命令|workflow.*对比/) || // Comparison queries
|
||||
query.match(/\w+-agent/) || // Agent name pattern
|
||||
query.includes('最佳实践') && query.match(/\w+:\w+/)) { // Best practices for specific command
|
||||
return 'DEEP_ANALYSIS';
|
||||
}
|
||||
|
||||
// Default: Ask for clarification
|
||||
return 'CLARIFY';
|
||||
}
|
||||
@@ -225,6 +247,15 @@ async function getRecommendations(currentCommand) {
|
||||
- "如何使用 /cli:execute?"
|
||||
- "task:create 详细文档"
|
||||
|
||||
**Special Case - CLI Tools Guide**:
|
||||
**Keywords**: cli工具, 如何使用cli, gemini/qwen/codex使用, 优雅使用, cli能力, cli特性, 语义调用, 命令调用
|
||||
|
||||
**Examples**:
|
||||
- "如何优雅的使用cli工具"
|
||||
- "cli工具能做什么"
|
||||
- "gemini和codex的区别"
|
||||
- "语义调用是什么"
|
||||
|
||||
### Processing Flow
|
||||
|
||||
```
|
||||
@@ -253,7 +284,32 @@ async function getRecommendations(currentCommand) {
|
||||
### Implementation
|
||||
|
||||
```javascript
|
||||
async function getDocumentation(commandName) {
|
||||
async function getDocumentation(commandName, queryType = 'DOCUMENTATION') {
|
||||
// Special case: CLI tools usage guide
|
||||
if (queryType === 'CLI_TOOLS_GUIDE') {
|
||||
const guideContent = await readFile('guides/cli-tools-guide.md');
|
||||
return {
|
||||
type: 'CLI_TOOLS_GUIDE',
|
||||
title: 'CLI 工具使用指南',
|
||||
content: guideContent,
|
||||
sections: {
|
||||
introduction: extractSection(guideContent, '## 🎯 快速理解'),
|
||||
comparison: extractSection(guideContent, '## 📋 三大工具能力对比'),
|
||||
how_to_use: extractSection(guideContent, '## 🚀 如何调用'),
|
||||
capabilities: extractSection(guideContent, '## 💡 能力特性清单'),
|
||||
scenarios: extractSection(guideContent, '## 🔄 典型使用场景'),
|
||||
quick_reference: extractSection(guideContent, '## 📚 快速参考'),
|
||||
faq: extractSection(guideContent, '## 🆘 常见问题')
|
||||
},
|
||||
related_docs: [
|
||||
'intelligent-tools-strategy.md',
|
||||
'workflow-patterns.md',
|
||||
'getting-started.md'
|
||||
]
|
||||
};
|
||||
}
|
||||
|
||||
// Normal command documentation
|
||||
// Normalize command name
|
||||
const normalized = normalizeCommandName(commandName);
|
||||
|
||||
@@ -460,6 +516,419 @@ async function reportIssue(issueType) {
|
||||
|
||||
---
|
||||
|
||||
## Mode 6: Deep Command Analysis 🔬
|
||||
|
||||
### Trigger Analysis
|
||||
|
||||
**Keywords**: 详细说明, 命令原理, agent 如何工作, 实现细节, 对比命令, 最佳实践
|
||||
|
||||
**Examples**:
|
||||
- "action-planning-agent 如何工作?"
|
||||
- "/workflow:plan 的实现原理是什么?"
|
||||
- "对比 workflow:plan 和 workflow:tdd-plan"
|
||||
- "ui-design-agent 详细说明"
|
||||
|
||||
### Processing Flow
|
||||
|
||||
```
|
||||
1. Parse Query
|
||||
├─ Identify target command(s)/agent(s)
|
||||
├─ Determine query complexity
|
||||
└─ Extract specific questions
|
||||
↓
|
||||
2. Classify Query Type
|
||||
├─ Simple: Single entity, basic explanation
|
||||
└─ Complex: Multi-entity comparison, best practices, workflows
|
||||
↓
|
||||
3. Simple Query Path
|
||||
├─ Locate file in reference/
|
||||
├─ Read markdown content
|
||||
├─ Extract relevant sections
|
||||
└─ Format response
|
||||
↓
|
||||
4. Complex Query Path
|
||||
├─ Identify all relevant files
|
||||
├─ Construct CLI analysis prompt
|
||||
├─ Execute gemini/qwen analysis
|
||||
└─ Return comprehensive results
|
||||
↓
|
||||
5. Response Enhancement
|
||||
├─ Add usage examples
|
||||
├─ Link to related docs
|
||||
└─ Suggest next steps
|
||||
```
|
||||
|
||||
### Query Classification Logic
|
||||
|
||||
```javascript
|
||||
function classifyDeepAnalysisQuery(query) {
|
||||
const complexityIndicators = {
|
||||
multiEntity: query.match(/对比|比较|区别/) && query.match(/(\/\w+:\w+.*){2,}/),
|
||||
bestPractices: query.includes('最佳实践') || query.includes('推荐用法'),
|
||||
workflowAnalysis: query.match(/工作流.*分析|流程.*说明/),
|
||||
architecturalDepth: query.includes('架构') || query.includes('设计思路'),
|
||||
crossReference: query.match(/和.*一起用|配合.*使用/)
|
||||
};
|
||||
|
||||
const isComplex = Object.values(complexityIndicators).some(v => v);
|
||||
|
||||
return {
|
||||
isComplex,
|
||||
indicators: complexityIndicators,
|
||||
requiresCLI: isComplex
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
### Simple Query Implementation
|
||||
|
||||
```javascript
|
||||
async function handleSimpleQuery(query) {
|
||||
// Extract entity name (command or agent)
|
||||
const entityName = extractEntityName(query); // e.g., "action-planning-agent" or "workflow:plan"
|
||||
|
||||
// Determine if command or agent
|
||||
const isAgent = entityName.includes('-agent') || entityName.includes('agent');
|
||||
const isCommand = entityName.includes(':') || entityName.startsWith('/');
|
||||
|
||||
let filePath;
|
||||
if (isAgent) {
|
||||
// Agent query
|
||||
const agentFileName = entityName.replace(/^\//, '').replace(/-agent$/, '-agent');
|
||||
filePath = `reference/agents/${agentFileName}.md`;
|
||||
} else if (isCommand) {
|
||||
// Command query - need to find in command hierarchy
|
||||
const cmdName = entityName.replace(/^\//, '');
|
||||
filePath = await locateCommandFile(cmdName);
|
||||
}
|
||||
|
||||
// Read documentation
|
||||
const docContent = await readFile(filePath);
|
||||
|
||||
// Extract relevant sections based on query keywords
|
||||
const sections = extractRelevantSections(docContent, query);
|
||||
|
||||
// Format response
|
||||
return {
|
||||
entity: entityName,
|
||||
type: isAgent ? 'agent' : 'command',
|
||||
documentation: sections,
|
||||
full_path: filePath,
|
||||
related: await findRelatedEntities(entityName)
|
||||
};
|
||||
}
|
||||
|
||||
async function locateCommandFile(commandName) {
|
||||
// Parse command category from name
|
||||
// e.g., "workflow:plan" → "reference/commands/workflow/plan.md"
|
||||
const [category, name] = commandName.split(':');
|
||||
|
||||
// Search in reference/commands hierarchy
|
||||
const possiblePaths = [
|
||||
`reference/commands/${category}/${name}.md`,
|
||||
`reference/commands/${category}/${name}/*.md`,
|
||||
`reference/commands/${name}.md`
|
||||
];
|
||||
|
||||
for (const path of possiblePaths) {
|
||||
if (await fileExists(path)) {
|
||||
return path;
|
||||
}
|
||||
}
|
||||
|
||||
throw new Error(`Command file not found: ${commandName}`);
|
||||
}
|
||||
|
||||
function extractRelevantSections(markdown, query) {
|
||||
// Parse markdown into sections
|
||||
const sections = parseMarkdownSections(markdown);
|
||||
|
||||
// Determine which sections are relevant
|
||||
const keywords = extractKeywords(query);
|
||||
const relevantSections = {};
|
||||
|
||||
// Always include overview/description
|
||||
if (sections['## Overview'] || sections['## Description']) {
|
||||
relevantSections.overview = sections['## Overview'] || sections['## Description'];
|
||||
}
|
||||
|
||||
// Include specific sections based on keywords
|
||||
if (keywords.includes('参数') || keywords.includes('参数说明')) {
|
||||
relevantSections.parameters = sections['## Parameters'] || sections['## Arguments'];
|
||||
}
|
||||
|
||||
if (keywords.includes('例子') || keywords.includes('示例') || keywords.includes('example')) {
|
||||
relevantSections.examples = sections['## Examples'] || sections['## Usage'];
|
||||
}
|
||||
|
||||
if (keywords.includes('工作流') || keywords.includes('流程')) {
|
||||
relevantSections.workflow = sections['## Workflow'] || sections['## Process Flow'];
|
||||
}
|
||||
|
||||
if (keywords.includes('最佳实践') || keywords.includes('建议')) {
|
||||
relevantSections.best_practices = sections['## Best Practices'] || sections['## Recommendations'];
|
||||
}
|
||||
|
||||
return relevantSections;
|
||||
}
|
||||
```
|
||||
|
||||
### Complex Query Implementation (CLI-Assisted)
|
||||
|
||||
```javascript
|
||||
async function handleComplexQuery(query, classification) {
|
||||
// Identify all entities mentioned in query
|
||||
const entities = extractAllEntities(query); // Returns array of command/agent names
|
||||
|
||||
// Build file context for CLI analysis
|
||||
const contextPaths = [];
|
||||
for (const entity of entities) {
|
||||
const path = await resolveEntityPath(entity);
|
||||
contextPaths.push(path);
|
||||
}
|
||||
|
||||
// Construct CLI prompt based on query type
|
||||
const prompt = buildCLIPrompt(query, classification, contextPaths);
|
||||
|
||||
// Execute CLI analysis
|
||||
const cliResult = await executeCLIAnalysis(prompt);
|
||||
|
||||
return {
|
||||
query_type: 'complex',
|
||||
analysis_method: 'CLI-assisted (gemini)',
|
||||
entities_analyzed: entities,
|
||||
result: cliResult,
|
||||
source_files: contextPaths
|
||||
};
|
||||
}
|
||||
|
||||
function buildCLIPrompt(userQuery, classification, contextPaths) {
|
||||
// Extract key question
|
||||
const question = extractCoreQuestion(userQuery);
|
||||
|
||||
// Build context reference
|
||||
const contextRef = contextPaths.map(p => `@${p}`).join(' ');
|
||||
|
||||
// Determine analysis focus based on classification
|
||||
let taskDescription = '';
|
||||
if (classification.indicators.multiEntity) {
|
||||
taskDescription = `• Compare the entities mentioned in terms of:
|
||||
- Use cases and scenarios
|
||||
- Capabilities and features
|
||||
- When to use each
|
||||
- Workflow integration
|
||||
• Provide side-by-side comparison
|
||||
• Recommend usage guidelines`;
|
||||
} else if (classification.indicators.bestPractices) {
|
||||
taskDescription = `• Analyze best practices for the mentioned entities
|
||||
• Provide practical usage recommendations
|
||||
• Include common pitfalls to avoid
|
||||
• Show example workflows`;
|
||||
} else if (classification.indicators.workflowAnalysis) {
|
||||
taskDescription = `• Trace the workflow execution
|
||||
• Explain process flow and dependencies
|
||||
• Identify key integration points
|
||||
• Provide usage examples`;
|
||||
} else {
|
||||
taskDescription = `• Provide comprehensive analysis
|
||||
• Explain implementation details
|
||||
• Show practical examples
|
||||
• Include related concepts`;
|
||||
}
|
||||
|
||||
// Construct full prompt using Standard Template
|
||||
return `PURPOSE: Analyze command/agent documentation to provide comprehensive answer to user query
|
||||
TASK:
|
||||
${taskDescription}
|
||||
MODE: analysis
|
||||
CONTEXT: ${contextRef}
|
||||
EXPECTED: Comprehensive answer with examples, comparisons, and recommendations in markdown format
|
||||
RULES: $(cat ~/.claude/workflows/cli-templates/prompts/analysis/02-analyze-code-patterns.txt) | Focus on practical usage and real-world scenarios | analysis=READ-ONLY
|
||||
|
||||
User Question: ${question}`;
|
||||
}
|
||||
|
||||
async function executeCLIAnalysis(prompt) {
|
||||
// Change to reference directory for correct file context
|
||||
const cwd = 'reference';
|
||||
|
||||
// Execute gemini with analysis prompt
|
||||
const command = `cd ${cwd} && gemini -p "${escapePrompt(prompt)}" -m gemini-3-pro-preview-11-2025`;
|
||||
|
||||
try {
|
||||
const result = await execBash(command, { timeout: 120000 }); // 2 min timeout
|
||||
return parseAnalysisResult(result.stdout);
|
||||
} catch (error) {
|
||||
// Fallback to qwen if gemini fails
|
||||
console.warn('Gemini failed, falling back to qwen');
|
||||
const fallbackCmd = `cd ${cwd} && qwen -p "${escapePrompt(prompt)}" -m coder-model`;
|
||||
const result = await execBash(fallbackCmd, { timeout: 120000 });
|
||||
return parseAnalysisResult(result.stdout);
|
||||
}
|
||||
}
|
||||
|
||||
function parseAnalysisResult(rawOutput) {
|
||||
// Extract main content from CLI output
|
||||
// Remove CLI wrapper/metadata, keep analysis content
|
||||
const lines = rawOutput.split('\n');
|
||||
const contentStart = lines.findIndex(l => l.trim().startsWith('#') || l.length > 50);
|
||||
const content = lines.slice(contentStart).join('\n');
|
||||
|
||||
return {
|
||||
raw: rawOutput,
|
||||
parsed: content,
|
||||
format: 'markdown'
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
### Helper Functions
|
||||
|
||||
```javascript
|
||||
function extractEntityName(query) {
|
||||
// Extract command name pattern: /workflow:plan or workflow:plan
|
||||
const cmdMatch = query.match(/\/?(\w+:\w+)/);
|
||||
if (cmdMatch) return cmdMatch[1];
|
||||
|
||||
// Extract agent name pattern: action-planning-agent or action planning agent
|
||||
const agentMatch = query.match(/(\w+(?:-\w+)*-agent|\w+\s+agent)/);
|
||||
if (agentMatch) return agentMatch[1].replace(/\s+/g, '-');
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function extractAllEntities(query) {
|
||||
const entities = [];
|
||||
|
||||
// Find all command patterns
|
||||
const commands = query.match(/\/?(\w+:\w+)/g);
|
||||
if (commands) {
|
||||
entities.push(...commands.map(c => c.replace('/', '')));
|
||||
}
|
||||
|
||||
// Find all agent patterns
|
||||
const agents = query.match(/(\w+(?:-\w+)*-agent)/g);
|
||||
if (agents) {
|
||||
entities.push(...agents);
|
||||
}
|
||||
|
||||
return [...new Set(entities)]; // Deduplicate
|
||||
}
|
||||
|
||||
async function resolveEntityPath(entityName) {
|
||||
const isAgent = entityName.includes('-agent');
|
||||
|
||||
if (isAgent) {
|
||||
return `agents/${entityName}.md`;
|
||||
} else {
|
||||
// Command - need to find in hierarchy
|
||||
const [category] = entityName.split(':');
|
||||
// Use glob to find the file
|
||||
const matches = await glob(`commands/${category}/**/${entityName.split(':')[1]}.md`);
|
||||
if (matches.length > 0) {
|
||||
return matches[0];
|
||||
}
|
||||
throw new Error(`Entity file not found: ${entityName}`);
|
||||
}
|
||||
}
|
||||
|
||||
function extractCoreQuestion(query) {
|
||||
// Remove common prefixes
|
||||
const cleaned = query
|
||||
.replace(/^(请|帮我|能否|可以)/g, '')
|
||||
.replace(/^(ccw|CCW)[:\s]*/gi, '')
|
||||
.trim();
|
||||
|
||||
// Ensure it ends with question mark if it's interrogative
|
||||
if (cleaned.match(/什么|如何|为什么|怎么|哪个/) && !cleaned.endsWith('?') && !cleaned.endsWith('?')) {
|
||||
return cleaned + '?';
|
||||
}
|
||||
|
||||
return cleaned;
|
||||
}
|
||||
|
||||
function escapePrompt(prompt) {
|
||||
// Escape special characters for bash
|
||||
return prompt
|
||||
.replace(/\\/g, '\\\\')
|
||||
.replace(/"/g, '\\"')
|
||||
.replace(/\$/g, '\\$')
|
||||
.replace(/`/g, '\\`');
|
||||
}
|
||||
```
|
||||
|
||||
### Example Outputs
|
||||
|
||||
**Simple Query Example**:
|
||||
```javascript
|
||||
// Input: "action-planning-agent 如何工作?"
|
||||
{
|
||||
entity: "action-planning-agent",
|
||||
type: "agent",
|
||||
documentation: {
|
||||
overview: "# Action Planning Agent\n\nGenerates structured task plans...",
|
||||
workflow: "## Workflow\n1. Analyze requirements\n2. Break down into tasks...",
|
||||
examples: "## Examples\n```bash\n/workflow:plan --agent \"feature\"\n```"
|
||||
},
|
||||
full_path: "reference/agents/action-planning-agent.md",
|
||||
related: ["workflow:plan", "task:create", "conceptual-planning-agent"]
|
||||
}
|
||||
```
|
||||
|
||||
**Complex Query Example**:
|
||||
```javascript
|
||||
// Input: "对比 workflow:plan 和 workflow:tdd-plan 的使用场景和最佳实践"
|
||||
{
|
||||
query_type: "complex",
|
||||
analysis_method: "CLI-assisted (gemini)",
|
||||
entities_analyzed: ["workflow:plan", "workflow:tdd-plan"],
|
||||
result: {
|
||||
parsed: `# 对比分析: workflow:plan vs workflow:tdd-plan
|
||||
|
||||
## 使用场景对比
|
||||
|
||||
### workflow:plan
|
||||
- **适用场景**: 通用功能开发,无特殊测试要求
|
||||
- **特点**: 灵活的任务分解,focus on implementation
|
||||
...
|
||||
|
||||
### workflow:tdd-plan
|
||||
- **适用场景**: 测试驱动开发,需要严格测试覆盖
|
||||
- **特点**: Red-Green-Refactor 循环,test-first
|
||||
...
|
||||
|
||||
## 最佳实践
|
||||
|
||||
### workflow:plan 最佳实践
|
||||
1. 先分析需求,明确目标
|
||||
2. 合理分解任务,避免过大或过小
|
||||
...
|
||||
|
||||
### workflow:tdd-plan 最佳实践
|
||||
1. 先写测试,明确预期行为
|
||||
2. 保持 Red-Green-Refactor 节奏
|
||||
...
|
||||
|
||||
## 选择建议
|
||||
|
||||
| 情况 | 推荐命令 |
|
||||
|------|----------|
|
||||
| 新功能开发,无特殊测试要求 | workflow:plan |
|
||||
| 核心模块,需要高测试覆盖 | workflow:tdd-plan |
|
||||
| 快速原型,验证想法 | workflow:plan |
|
||||
| 关键业务逻辑 | workflow:tdd-plan |
|
||||
`,
|
||||
format: "markdown"
|
||||
},
|
||||
source_files: [
|
||||
"commands/workflow/plan.md",
|
||||
"commands/workflow/tdd-plan.md"
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Error Handling
|
||||
|
||||
### Not Found
|
||||
@@ -523,4 +992,6 @@ async function readIndex(filename) {
|
||||
|
||||
---
|
||||
|
||||
**Last Updated**: 2025-01-06
|
||||
**Last Updated**: 2025-11-06
|
||||
|
||||
**Version**: 1.3.0 - Added Mode 6: Deep Command Analysis with reference documentation backup and CLI-assisted complex queries
|
||||
|
||||
Reference in New Issue
Block a user