mirror of
https://github.com/catlog22/Claude-Code-Workflow.git
synced 2026-02-14 02:42:04 +08:00
feat: 更新 CLI 自动调用触发器和执行原则,增强文档说明
This commit is contained in:
@@ -37,21 +37,9 @@ Available CLI endpoints are dynamically defined by the config file:
|
|||||||
- Aggregate multiple analysis results before proposing solutions
|
- Aggregate multiple analysis results before proposing solutions
|
||||||
|
|
||||||
### CLI Auto-Invoke Triggers
|
### CLI Auto-Invoke Triggers
|
||||||
|
- **Reference**: See `cli-tools-usage.md` → [Auto-Invoke Triggers](#auto-invoke-triggers) for full specification
|
||||||
**Proactive CLI invocation scenarios** - Auto-invoke `ccw cli` for external analysis in these cases:
|
- **Key scenarios**: Self-repair fails, ambiguous requirements, architecture decisions, pattern uncertainty, critical code paths
|
||||||
|
- **Principles**: Default `--mode analysis`, no confirmation needed, wait for completion, flexible rule selection
|
||||||
| Trigger Condition | Recommended Mode | Description |
|
|
||||||
|-------------------|------------------|-------------|
|
|
||||||
| **Bug fix fails after 1+ attempts** | `--mode analysis --rule analysis-diagnose-bug-root-cause` | Invoke CLI for root cause analysis when self-repair attempts fail |
|
|
||||||
| **Unclear task description** | `--mode analysis --rule planning-breakdown-task-steps` | Invoke CLI for task decomposition when requirements are ambiguous |
|
|
||||||
| **Quick planning needed** | `--mode analysis --rule planning-plan-architecture-design` | Invoke CLI for architecture design on complex feature requests |
|
|
||||||
| **Uncertain code patterns** | `--mode analysis --rule analysis-analyze-code-patterns` | Invoke CLI to analyze existing code style/patterns when uncertain |
|
|
||||||
| **Security/performance critical paths** | `--mode analysis --rule analysis-assess-security-risks` | Proactively request review for security or performance-sensitive code |
|
|
||||||
|
|
||||||
**Execution principles**:
|
|
||||||
- When trigger conditions are met, invoke CLI **without user confirmation**
|
|
||||||
- Wait for results before determining next steps
|
|
||||||
- Tool fallback chain: `gemini` → `qwen` → `codex`
|
|
||||||
|
|
||||||
## Code Diagnostics
|
## Code Diagnostics
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
2. [Tool Selection](#tool-selection)
|
2. [Tool Selection](#tool-selection)
|
||||||
3. [Prompt Template](#prompt-template)
|
3. [Prompt Template](#prompt-template)
|
||||||
4. [CLI Execution](#cli-execution)
|
4. [CLI Execution](#cli-execution)
|
||||||
5. [Execution Configuration](#execution-configuration)
|
5. [Auto-Invoke Triggers](#auto-invoke-triggers)
|
||||||
6. [Best Practices](#best-practices)
|
6. [Best Practices](#best-practices)
|
||||||
|
|
||||||
---
|
---
|
||||||
@@ -462,6 +462,41 @@ ccw cli --tool codex --mode review --commit abc123
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## Auto-Invoke Triggers
|
||||||
|
|
||||||
|
**Proactive CLI invocation** - Auto-invoke `ccw cli` when encountering these scenarios:
|
||||||
|
|
||||||
|
| Trigger Condition | Suggested Rule | When to Use |
|
||||||
|
|-------------------|----------------|-------------|
|
||||||
|
| **Self-repair fails** | `analysis-diagnose-bug-root-cause` | After 1+ failed fix attempts |
|
||||||
|
| **Ambiguous requirements** | `planning-breakdown-task-steps` | Task description lacks clarity |
|
||||||
|
| **Architecture decisions** | `planning-plan-architecture-design` | Complex feature needs design |
|
||||||
|
| **Pattern uncertainty** | `analysis-analyze-code-patterns` | Unsure of existing conventions |
|
||||||
|
| **Critical code paths** | `analysis-assess-security-risks` | Security/performance sensitive |
|
||||||
|
|
||||||
|
### Execution Principles
|
||||||
|
|
||||||
|
- **Default mode**: `--mode analysis` (read-only, safe for auto-execution)
|
||||||
|
- **No confirmation needed**: Invoke proactively when triggers match
|
||||||
|
- **Wait for results**: Complete analysis before next action
|
||||||
|
- **Tool selection**: Use context-appropriate tool or fallback chain (`gemini` → `qwen` → `codex`)
|
||||||
|
- **Rule flexibility**: Suggested rules are guidelines, not requirements - choose the most appropriate template for the situation
|
||||||
|
|
||||||
|
### Example: Bug Fix with Auto-Invoke
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# After 1+ failed fix attempts, auto-invoke root cause analysis
|
||||||
|
ccw cli -p "PURPOSE: Identify root cause of [bug description]; success = actionable fix strategy
|
||||||
|
TASK: • Trace execution flow • Identify failure point • Analyze state at failure • Determine fix approach
|
||||||
|
MODE: analysis
|
||||||
|
CONTEXT: @src/module/**/* | Memory: Previous fix attempts failed at [location]
|
||||||
|
EXPECTED: Root cause analysis with: failure mechanism, stack trace interpretation, fix recommendation with code
|
||||||
|
CONSTRAINTS: Focus on [specific area]
|
||||||
|
" --tool gemini --mode analysis --rule analysis-diagnose-bug-root-cause
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## Best Practices
|
## Best Practices
|
||||||
|
|
||||||
### Core Principles
|
### Core Principles
|
||||||
|
|||||||
@@ -12,8 +12,15 @@ Usage:
|
|||||||
import subprocess
|
import subprocess
|
||||||
import time
|
import time
|
||||||
import json
|
import json
|
||||||
|
import re
|
||||||
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
def strip_ansi(text: str) -> str:
|
||||||
|
"""Remove ANSI color codes from text."""
|
||||||
|
ansi_escape = re.compile(r'\x1b\[[0-9;]*m')
|
||||||
|
return ansi_escape.sub('', text)
|
||||||
|
|
||||||
def run_search(query: str, method: str, limit: int = 20) -> tuple[list, float]:
|
def run_search(query: str, method: str, limit: int = 20) -> tuple[list, float]:
|
||||||
"""Run search via CLI and measure time."""
|
"""Run search via CLI and measure time."""
|
||||||
cmd = [
|
cmd = [
|
||||||
@@ -31,19 +38,25 @@ def run_search(query: str, method: str, limit: int = 20) -> tuple[list, float]:
|
|||||||
cwd=str(Path("D:/Claude_dms3/codex-lens/src")),
|
cwd=str(Path("D:/Claude_dms3/codex-lens/src")),
|
||||||
capture_output=True,
|
capture_output=True,
|
||||||
text=True,
|
text=True,
|
||||||
|
env={**os.environ, "NO_COLOR": "1"}, # Try to disable colors
|
||||||
)
|
)
|
||||||
elapsed = time.perf_counter() - start
|
elapsed = time.perf_counter() - start
|
||||||
|
|
||||||
if result.returncode != 0:
|
if result.returncode != 0:
|
||||||
print(f"Error running {method} search:")
|
print(f"Error running {method} search:")
|
||||||
print(result.stderr)
|
print(result.stderr[:200])
|
||||||
return [], elapsed
|
return [], elapsed
|
||||||
|
|
||||||
try:
|
try:
|
||||||
data = json.loads(result.stdout)
|
# Strip ANSI codes and parse JSON
|
||||||
|
clean_output = strip_ansi(result.stdout)
|
||||||
|
data = json.loads(clean_output)
|
||||||
|
# Results are nested in "result" object
|
||||||
|
if "result" in data and "results" in data["result"]:
|
||||||
|
return data["result"]["results"], elapsed
|
||||||
return data.get("results", []), elapsed
|
return data.get("results", []), elapsed
|
||||||
except json.JSONDecodeError:
|
except json.JSONDecodeError as e:
|
||||||
print(f"Failed to parse JSON output for {method}")
|
print(f"Failed to parse JSON output for {method}: {e}")
|
||||||
return [], elapsed
|
return [], elapsed
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user