feat: 增加文件模式参考和复杂模式发现的示例,增强 CLI 命令的文档

This commit is contained in:
catlog22
2025-10-05 10:26:08 +08:00
parent 7d9adf5a55
commit a9d6de228e
7 changed files with 291 additions and 34 deletions

View File

@@ -69,13 +69,46 @@ codex -C [dir] -i screenshot.png --full-auto exec "..." --skip-git-repo-check -s
## File Pattern Logic
Auto-detect file patterns from keywords:
- "auth" → `@{**/*auth*}`
- "component" → `@{src/components/**/*}`
- "API" → `@{**/api/**/*}`
- "test" → `@{**/*.test.*}`
### Auto-Detection from Keywords
- "auth" → `@{**/*auth*,**/*user*}`
- "component" → `@{src/components/**/*,**/*.component.*}`
- "API" → `@{**/api/**/*,**/routes/**/*}`
- "test" → `@{**/*.test.*,**/*.spec.*}`
- "config" → `@{*.config.*,**/config/**/*}`
- Generic → `@{src/**/*}`
### Common File Patterns
- All files: `@{**/*}`
- Source files: `@{src/**/*}`
- TypeScript: `@{*.ts,*.tsx}`
- JavaScript: `@{*.js,*.jsx}`
- With docs: `@{CLAUDE.md,**/*CLAUDE.md}`
- Tests: `@{**/*.test.*,**/*.spec.*}`
### Complex Pattern Discovery
For complex file pattern requirements, use semantic discovery BEFORE CLI execution:
**Workflow**: Discover → Extract precise paths → Build CONTEXT field
```bash
# Step 1: Discover files semantically
rg "export.*Component" --files-with-matches --type ts
mcp__code-index__search_code_advanced(pattern="interface.*Props", file_pattern="*.tsx")
# Step 2: Build precise CONTEXT from discovery results
CONTEXT: @{src/components/Auth.tsx,src/types/auth.d.ts,src/hooks/useAuth.ts}
# Step 3: Execute CLI with precise file references
cd src && ~/.claude/scripts/gemini-wrapper -p "
PURPOSE: Analyze authentication components
TASK: Review auth component patterns and props interfaces
MODE: analysis
CONTEXT: @{components/Auth.tsx,types/auth.d.ts,hooks/useAuth.ts}
EXPECTED: Pattern analysis and improvement suggestions
RULES: Focus on type safety and component composition
"
```
## Session Integration
- **Active Session**: Save results to `.workflow/WFS-[id]/.chat/analysis-[timestamp].md`

View File

@@ -44,6 +44,34 @@ Context gathered from:
2. **User-Explicit Files**: Files specified by user
3. **All Files Flag**: `--all-files` includes entire codebase
### File Pattern Reference
- All files: `@{**/*}`
- Source files: `@{src/**/*}`
- TypeScript: `@{*.ts,*.tsx}`
- JavaScript: `@{*.js,*.jsx}`
- With docs: `@{CLAUDE.md,**/*CLAUDE.md}`
- Tests: `@{**/*.test.*,**/*.spec.*}`
- Config files: `@{*.config.*,**/config/**/*}`
### Complex Pattern Discovery
For targeted analysis, use semantic discovery BEFORE CLI execution:
```bash
# Step 1: Discover relevant files
rg "specific_pattern" --files-with-matches --type ts
mcp__code-index__search_code_advanced(pattern="target_code", file_pattern="*.ts")
# Step 2: Build CONTEXT with discovered files
CONTEXT: @{CLAUDE.md} @{src/file1.ts,src/file2.ts}
# Step 3: Execute chat command
cd src && ~/.claude/scripts/gemini-wrapper -p "
PURPOSE: Answer specific inquiry
CONTEXT: @{CLAUDE.md,file1.ts,file2.ts}
EXPECTED: Detailed response
"
```
## Command Template
**Gemini/Qwen**:

View File

@@ -98,6 +98,34 @@ For Each Subtask Group:
- Focused file scope (1-5 files per subtask)
- **Group coherence**: Subtasks in same group share context/files
### File Pattern Reference
- All files: `@{**/*}`
- Source files: `@{src/**/*}`
- TypeScript: `@{*.ts,*.tsx}`
- JavaScript: `@{*.js,*.jsx}`
- Python: `@{*.py}`
- Tests: `@{**/*.test.*,**/*.spec.*}`
- Config files: `@{*.config.*,**/config/**/*}`
### Complex Pattern Discovery
For task decomposition, use semantic discovery to identify relevant files:
**Workflow**: Discover → Analyze scope → Group by files → Decompose
```bash
# Step 1: Discover all relevant files
rg "authentication" --files-with-matches --type ts
mcp__code-index__search_code_advanced(pattern="auth|login", file_pattern="*.ts")
# Step 2: Analyze scope and group files
# Group A: src/auth/model.ts, src/auth/schema.ts
# Group B: src/api/auth.ts, src/middleware/auth.ts
# Group C: tests/auth/*.test.ts
# Step 3: Create task flow based on file groups
# Each group becomes a session with related subtasks
```
### Phase 2: Group-Based Execution
**Pre-Execution Git Staging** (if valid git repository):

View File

@@ -18,18 +18,14 @@ allowed-tools: SlashCommand(*), Bash(*)
Execute implementation tasks with YOLO permissions (auto-approves all confirmations).
**Supported Tools**: codex, gemini (default), qwen
**Key Feature**: Automatic context inference and file pattern detection
## YOLO Permissions
## Core Concepts
### YOLO Permissions
Auto-approves: file pattern inference, execution, file modifications, summary generation
## Enhancement Integration
**When `--enhance` flag present** (Description Mode only): Execute `/enhance-prompt "[description]"` first, then use enhanced output (INTENT/CONTEXT/ACTION) for execution.
**Note**: Task ID Mode uses task JSON directly (no enhancement).
## Execution Modes
### Execution Modes
**1. Description Mode** (supports `--enhance`):
- Input: Natural language description
@@ -39,7 +35,7 @@ Auto-approves: file pattern inference, execution, file modifications, summary ge
- Input: Workflow task identifier (e.g., `IMPL-001`)
- Process: Task JSON parsing → Scope analysis → Execute
## Context Inference
### Context Inference
Auto-selects files based on:
- **Keywords**: "auth" → `@{**/*auth*,**/*user*}`
@@ -47,22 +43,42 @@ Auto-selects files based on:
- **Task Type**: "api" → `@{**/api/**/*,**/routes/**/*}`
- **Always**: `@{CLAUDE.md,**/*CLAUDE.md}`
## Options
### File Pattern Reference
- All files: `@{**/*}`
- Source files: `@{src/**/*}`
- TypeScript: `@{*.ts,*.tsx}`
- JavaScript: `@{*.js,*.jsx}`
- Python: `@{*.py}`
- Tests: `@{**/*.test.*,**/*.spec.*}`
- Config files: `@{*.config.*,**/config/**/*}`
- `--debug`: Verbose logging
- `--save-session`: Save execution to workflow session
### Complex Pattern Discovery
For precise file targeting, use semantic discovery BEFORE CLI execution:
## Workflow Integration
**Workflow**: Discover → Extract precise paths → Build CONTEXT field
**Session Management**: Auto-detects `.workflow/.active-*` marker
- **Active**: Save to `.workflow/WFS-[id]/.chat/execute-[timestamp].md`
- **None**: Create new session
```bash
# Step 1: Discover files semantically
rg "target_pattern" --files-with-matches --type ts
mcp__code-index__find_files(pattern="*auth*")
**Task Integration**: Load from `.task/[TASK-ID].json`, update status, generate summary
# Step 2: Build precise CONTEXT from discovery results
CONTEXT: @{src/auth/module.ts,src/middleware/auth.ts,CLAUDE.md}
## Command Template
# Step 3: Execute with precise file references
codex -C src --full-auto exec "
PURPOSE: Implement authentication
TASK: Add JWT validation
MODE: auto
CONTEXT: @{auth/module.ts,middleware/auth.ts,CLAUDE.md}
EXPECTED: Complete implementation
RULES: Follow security best practices
" --skip-git-repo-check -s danger-full-access
```
**Gemini/Qwen** (with YOLO approval):
## Command Templates
### Gemini/Qwen (with YOLO approval)
```bash
cd [dir] && ~/.claude/scripts/[gemini|qwen]-wrapper --approval-mode yolo -p "
PURPOSE: [implementation goal]
@@ -74,7 +90,7 @@ RULES: $(cat ~/.claude/workflows/cli-templates/prompts/[category]/[template].txt
"
```
**Codex**:
### Codex
```bash
codex -C [dir] --full-auto exec "
PURPOSE: [implementation goal]
@@ -89,21 +105,75 @@ RULES: [constraints]
codex -C [dir] -i design.png --full-auto exec "..." --skip-git-repo-check -s danger-full-access
```
## Examples
### Codex with Resume (for related tasks)
```bash
/cli:execute "implement JWT authentication with middleware" # Description mode
/cli:execute --enhance "implement JWT authentication" # Enhanced
/cli:execute IMPL-001 # Task ID mode
/cli:execute --tool codex "optimize database queries" # Codex execution
# First task - establish session
codex -C [dir] --full-auto exec "
PURPOSE: [implementation goal]
TASK: [specific task]
MODE: auto
CONTEXT: @{inferred_patterns} @{CLAUDE.md}
EXPECTED: Implementation with file:line references
RULES: [constraints]
" --skip-git-repo-check -s danger-full-access
# Related follow-up task - continue session
codex --full-auto exec "
PURPOSE: [continuation goal]
TASK: [related task]
MODE: auto
CONTEXT: Previous implementation from session
EXPECTED: Enhanced/extended implementation
RULES: Maintain consistency with previous work
" resume --last --skip-git-repo-check -s danger-full-access
```
## Auto-Generated Outputs
**Resume Decision**: Use `resume --last` when current task extends/relates to previous execution in conversation memory. See intelligent-tools-strategy.md for auto-resume rules.
## Enhancement Integration
**When `--enhance` flag present** (Description Mode only):
1. Execute `/enhance-prompt "[description]"` first
2. Use enhanced output (INTENT/CONTEXT/ACTION) for execution
3. Build command with enhanced context
**Note**: Task ID Mode uses task JSON directly (no enhancement).
## Options
- `--tool <codex|gemini|qwen>`: Select CLI tool (default: gemini)
- `--enhance`: Enhance input with `/enhance-prompt` first
- `--debug`: Verbose logging
- `--save-session`: Save execution to workflow session
## Workflow Integration
**Session Management**: Auto-detects `.workflow/.active-*` marker
- **Active**: Save to `.workflow/WFS-[id]/.chat/execute-[timestamp].md`
- **None**: Create new session
**Task Integration**: Load from `.task/[TASK-ID].json`, update status, generate summary
**Auto-Generated Outputs**:
- **Summary**: `.summaries/[TASK-ID]-summary.md`
- **Session**: `.chat/execute-[timestamp].md`
## Notes
## Examples
**vs. `/cli:analyze`**: Execute performs implementation, analyze is read-only.
```bash
# Description mode (default: gemini)
/cli:execute "implement JWT authentication with middleware"
# Enhanced prompt
/cli:execute --enhance "implement JWT authentication"
# Task ID mode
/cli:execute IMPL-001
# Codex execution
/cli:execute --tool codex "optimize database queries"
# Qwen with enhancement
/cli:execute --tool qwen --enhance "refactor auth module"
```

View File

@@ -100,6 +100,39 @@ RULES: $(cat ~/.claude/prompt-templates/bug-fix.md) | Focus on session managemen
- **Targeted Solutions**: Minimal, specific fixes
- **Impact Assessment**: Side effect evaluation
## File Pattern Reference
### Common Patterns
- All files: `@{**/*}`
- Source files: `@{src/**/*}`
- TypeScript: `@{*.ts,*.tsx}`
- JavaScript: `@{*.js,*.jsx}`
- Python: `@{*.py}`
- With docs: `@{CLAUDE.md,**/*CLAUDE.md}`
- Tests: `@{**/*.test.*,**/*.spec.*}`
### Complex Pattern Discovery
For bug investigation, use semantic discovery to find relevant code:
```bash
# Step 1: Find bug-related files
rg "error_keyword|exception_pattern" --files-with-matches
mcp__code-index__search_code_advanced(pattern="throw|catch|error", file_pattern="*.ts")
# Step 2: Trace error propagation path
# Identify: origin → propagation → handler
# Step 3: Execute bug analysis with focused context
cd src && ~/.claude/scripts/gemini-wrapper --all-files -p "
PURPOSE: Debug null pointer error in authentication
TASK: Identify root cause and provide fix
MODE: analysis
CONTEXT: @{CLAUDE.md,auth/service.ts,middleware/auth.ts}
EXPECTED: Root cause, execution trace, minimal fix
RULES: $(cat ~/.claude/prompt-templates/bug-fix.md) | Bug: null pointer in token validation
"
```
## Session Output
**Location**: `.workflow/WFS-[topic]/.chat/bug-index-[timestamp].md`

View File

@@ -46,6 +46,39 @@ The code-analysis template provides:
- **Logical Reasoning**: Explain "why" behind code behavior
- **Debugging Insights**: Identify potential bugs or inefficiencies
## File Pattern Reference
### Common Patterns
- All files: `@{**/*}`
- Source files: `@{src/**/*}`
- TypeScript: `@{*.ts,*.tsx}`
- JavaScript: `@{*.js,*.jsx}`
- Python: `@{*.py}`
- With docs: `@{CLAUDE.md,**/*CLAUDE.md}`
- Tests: `@{**/*.test.*,**/*.spec.*}`
### Complex Pattern Discovery
For deep code analysis, use semantic discovery to trace execution paths:
```bash
# Step 1: Find entry points and related files
rg "function.*authenticate|class.*AuthService" --files-with-matches
mcp__code-index__search_code_advanced(pattern="authenticate|login", file_pattern="*.ts")
# Step 2: Trace execution flow through discovered files
# Build call graph: entry → middleware → service → repository
# Step 3: Execute analysis with focused context
cd src && ~/.claude/scripts/gemini-wrapper --all-files -p "
PURPOSE: Trace authentication execution flow
TASK: Analyze complete auth flow from request to response
MODE: analysis
CONTEXT: @{CLAUDE.md,api/auth.ts,middleware/auth.ts,services/auth.ts}
EXPECTED: Step-by-step execution trace with call diagram
RULES: $(cat ~/.claude/prompt-templates/code-analysis.md) | Focus on control flow
"
```
## Command Templates
### Gemini (Default)

View File

@@ -47,6 +47,38 @@ RULES: $(cat ~/.claude/prompt-templates/plan.md) | Focus on [topic area]
"
```
## File Pattern Reference
### Common Patterns
- All files: `@{**/*}`
- Source files: `@{src/**/*}`
- TypeScript: `@{*.ts,*.tsx}`
- JavaScript: `@{*.js,*.jsx}`
- With docs: `@{CLAUDE.md,**/*CLAUDE.md}`
- Tests: `@{**/*.test.*,**/*.spec.*}`
- Config files: `@{*.config.*,**/config/**/*}`
### Complex Pattern Discovery
For comprehensive planning, use semantic discovery to understand project scope:
```bash
# Step 1: Discover project structure
~/.claude/scripts/get_modules_by_depth.sh
mcp__code-index__find_files(pattern="*.ts")
# Step 2: Identify key architectural files
rg "export.*class|export.*interface" --files-with-matches
mcp__code-index__search_code_advanced(pattern="class.*Service|interface.*Config")
# Step 3: Execute planning with full context
cd . && ~/.claude/scripts/gemini-wrapper --all-files -p "
PURPOSE: Plan feature implementation
CONTEXT: @{CLAUDE.md,**/*CLAUDE.md} Full project context
EXPECTED: Architecture design and implementation roadmap
RULES: $(cat ~/.claude/prompt-templates/plan.md) | Focus on scalability
"
```
## Examples
**Basic Planning**: