--- name: ccw-cli-tools description: CLI tools execution specification (gemini/claude/codex/qwen/opencode) with unified prompt template, mode options, and auto-invoke triggers for code analysis and implementation tasks. Supports configurable CLI endpoints for analysis, write, and review modes. version: 1.0.0 --- # CLI Tools - Unified Execution Framework **Purpose**: Structured CLI tool usage with configuration-driven tool selection, unified prompt templates, and quality-gated execution. **Configuration**: `~/.claude/cli-tools.json` (Global, always read at initialization) ## Initialization (Required First Step) **Before any tool selection or recommendation**: 1. Check if configuration exists in memory: - If configuration is already in conversation memory → Use it directly - If NOT in memory → Read the configuration file: ```bash Read(file_path="~/.claude/cli-tools.json") ``` 2. Parse the JSON to understand: - Available tools and their `enabled` status - Each tool's `primaryModel` and `secondaryModel` - Tags defined for tag-based routing - Tool types (builtin, cli-wrapper, api-endpoint) 3. Use configuration throughout the selection process **Why**: Tools, models, and tags may change. Configuration file is the single source of truth. **Optimization**: Reuse in-memory configuration to avoid redundant file reads. ## Process Flow ``` ┌─ USER REQUEST │ ├─ STEP 1: Load Configuration │ ├─ Check if configuration exists in conversation memory │ └─ If NOT in memory → Read(file_path="~/.claude/cli-tools.json") │ ├─ STEP 2: Understand User Intent │ ├─ Parse task type (analysis, implementation, security, etc.) │ ├─ Extract required capabilities (tags) │ └─ Identify scope (files, modules) │ ├─ STEP 3: Select Tool (based on config) │ ├─ Explicit --tool specified? │ │ YES → Validate in config → Use it │ │ NO → Match tags with enabled tools → Select best match │ │ → No match → Use first enabled tool (default) │ └─ Get primaryModel from config │ ├─ STEP 4: Build Prompt │ └─ Use 6-field template: PURPOSE, TASK, MODE, CONTEXT, EXPECTED, CONSTRAINTS │ ├─ STEP 5: Select Rule Template │ ├─ Determine rule from task type │ └─ Pass via --rule parameter │ ├─ STEP 6: Execute CLI Command │ └─ ccw cli -p "" --tool --mode --rule │ └─ STEP 7: Handle Results ├─ On success → Deliver output to user └─ On failure → Check secondaryModel or fallback tool ``` ## Configuration Reference ### Configuration File Location **Path**: `~/.claude/cli-tools.json` (Global configuration) **IMPORTANT**: Check conversation memory first. Only read file if configuration is not in memory. ### Reading Configuration **Priority**: Check conversation memory first **Loading Options**: - **Option 1** (Preferred): Use in-memory configuration if already loaded in conversation - **Option 2** (Fallback): Read from file when not in memory ```bash # Read configuration file cat ~/.claude/cli-tools.json ``` The configuration defines all available tools with their enabled status, models, and tags. ### Configuration Structure The JSON file contains a `tools` object where each tool has these fields: | Field | Type | Description | Example | |-------|------|-------------|---------| | `enabled` | boolean | Tool availability status | `true` or `false` | | `primaryModel` | string | Default model for execution | `"gemini-2.5-pro"` | | `secondaryModel` | string | Fallback model on primary failure | `"gemini-2.5-flash"` | | `tags` | array | Capability tags for routing | `["分析", "Debug"]` | | `type` | string | Tool type | `"builtin"`, `"cli-wrapper"`, `"api-endpoint"` | ### Expected Tools (Reference Only) Typical tools found in configuration (actual availability determined by reading the file): | Tool | Typical Type | Common Use | |------|--------------|------------| | `gemini` | builtin | Analysis, Debug (分析, Debug tags) | | `qwen` | builtin | General coding | | `codex` | builtin | Code review, implementation | | `claude` | builtin | General tasks | | `opencode` | builtin | Open-source model fallback | **Note**: Tool availability, models, and tags may differ. Use in-memory configuration or read `~/.claude/cli-tools.json` if not cached. ### Configuration Fields - **`enabled`**: Tool availability (boolean) - **`primaryModel`**: Default model for execution - **`secondaryModel`**: Fallback model on primary failure - **`tags`**: Capability tags for routing (分析, Debug, implementation, etc.) - **`type`**: Tool type (builtin, cli-wrapper, api-endpoint) ## Universal Prompt Template **Structure**: Every CLI command follows this 6-field template ```bash ccw cli -p "PURPOSE: [goal] + [why] + [success criteria] + [scope] TASK: • [step 1: specific action] • [step 2: specific action] • [step 3: specific action] MODE: [analysis|write|review] CONTEXT: @[file patterns] | Memory: [session/tech/module context] EXPECTED: [deliverable format] + [quality criteria] + [structure requirements] CONSTRAINTS: [domain constraints]" --tool --mode --rule