feat(cli): default to universal-rigorous-style template when --rule not specified

- Add default template fallback in cli.ts (effectiveRule)
- Update cli-tools-usage.md with English descriptions
- Add ACE semantic search to Pattern Discovery Workflow
- Simplify Template System documentation (list template names only)
- Filter CLI progress messages (auth, loading) in output converter

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
catlog22
2026-01-17 19:51:21 +08:00
parent 1f87ca0be3
commit 1e691fa751
3 changed files with 81 additions and 62 deletions

View File

@@ -207,7 +207,11 @@ Memory: Integration with auth module, using shared error patterns from @shared/u
For complex requirements, discover files BEFORE CLI execution: For complex requirements, discover files BEFORE CLI execution:
```bash ```bash
# Step 1: Discover files # Step 1: Discover files (choose one method)
# Method A: ACE semantic search (recommended)
mcp__ace-tool__search_context(project_root_path="/path", query="React components with export")
# Method B: Ripgrep pattern search
rg "export.*Component" --files-with-matches --type ts rg "export.*Component" --files-with-matches --type ts
# Step 2: Build CONTEXT # Step 2: Build CONTEXT
@@ -219,74 +223,66 @@ ccw cli -p "..." --tool <tool-id> --mode analysis --cd src
### RULES Configuration ### RULES Configuration
**使用 `--rule` 选项自动加载模板** **Use `--rule` option to auto-load templates**:
```bash ```bash
ccw cli -p "... RULES: \$PROTO \$TMPL | constraints" --tool gemini --mode analysis --rule analysis-review-architecture ccw cli -p "... RULES: \$PROTO \$TMPL | constraints" --tool gemini --mode analysis --rule analysis-review-architecture
``` ```
**`--rule` 工作原理** **`--rule` How It Works**:
1. 自动从 `~/.claude/workflows/cli-templates/prompts/` 发现模板 1. Auto-discovers templates from `~/.claude/workflows/cli-templates/prompts/`
2. 根据 `--mode` 自动加载对应 protocolanalysis-protocol.md write-protocol.md 2. Auto-loads corresponding protocol based on `--mode` (analysis-protocol.md or write-protocol.md)
3. 设置环境变量 `$PROTO`protocol)和 `$TMPL`template)供子进程使用 3. Sets environment variables `$PROTO` (protocol) and `$TMPL` (template) for subprocess
4. 在提示词中用 `$PROTO` `$TMPL` 引用 4. Reference `$PROTO` and `$TMPL` in prompt
**模板选择**:从 Task-Template Matrix 选择或使用通用模板: > **Important**: `$PROTO` is required and must be included in RULES. `$TMPL` is optional.
- `universal-rigorous-style` - 精确型任务
- `universal-creative-style` - 探索型任务
### Mode Protocol References ### Mode Protocol References
**`--rule` 自动处理 Protocol** **`--rule` auto-handles Protocol**:
- `--mode analysis``$PROTO` = analysis-protocol.md - `--mode analysis``$PROTO` = analysis-protocol.md
- `--mode write``$PROTO` = write-protocol.md - `--mode write``$PROTO` = write-protocol.md
**Protocol 映射** **Protocol Mapping**:
- **`analysis`** 模式 - **`analysis`** mode
- 权限:只读操作 - Permission: Read-only
- 约束:禁止文件创建/修改/删除 - Constraint: No file create/modify/delete
- **`write`** 模式 - **`write`** mode
- 权限:创建/修改/删除文件 - Permission: Create/Modify/Delete files
- 约束:完整工作流执行能力 - Constraint: Full workflow execution
### Template System ### Template System
**Base Path**: `~/.claude/workflows/cli-templates/prompts/` **Available `--rule` template names**:
**Naming Convention**: `category-function.txt` **Universal**:
- 第一段为分类analysis, development, planning 等) - `universal-rigorous-style` - Precise tasks
- 第二段为功能描述 - `universal-creative-style` - Exploratory tasks
**Universal Templates**:
- `universal-rigorous-style` - 精确型任务
- `universal-creative-style` - 探索型任务
**Task-Template Matrix**:
**Analysis**: **Analysis**:
- Execution Tracing: `analysis-trace-code-execution` - `analysis-trace-code-execution` - Execution tracing
- Bug Diagnosis: `analysis-diagnose-bug-root-cause` - `analysis-diagnose-bug-root-cause` - Bug diagnosis
- Code Patterns: `analysis-analyze-code-patterns` - `analysis-analyze-code-patterns` - Code patterns
- Document Analysis: `analysis-analyze-technical-document` - `analysis-analyze-technical-document` - Document analysis
- Architecture Review: `analysis-review-architecture` - `analysis-review-architecture` - Architecture review
- Code Review: `analysis-review-code-quality` - `analysis-review-code-quality` - Code review
- Performance: `analysis-analyze-performance` - `analysis-analyze-performance` - Performance analysis
- Security: `analysis-assess-security-risks` - `analysis-assess-security-risks` - Security assessment
**Planning**: **Planning**:
- Architecture: `planning-plan-architecture-design` - `planning-plan-architecture-design` - Architecture design
- Task Breakdown: `planning-breakdown-task-steps` - `planning-breakdown-task-steps` - Task breakdown
- Component Design: `planning-design-component-spec` - `planning-design-component-spec` - Component design
- Migration: `planning-plan-migration-strategy` - `planning-plan-migration-strategy` - Migration strategy
**Development**: **Development**:
- Feature: `development-implement-feature` - `development-implement-feature` - Feature implementation
- Refactoring: `development-refactor-codebase` - `development-refactor-codebase` - Code refactoring
- Tests: `development-generate-tests` - `development-generate-tests` - Test generation
- UI Component: `development-implement-component-ui` - `development-implement-component-ui` - UI component
- Debugging: `development-debug-runtime-issues` - `development-debug-runtime-issues` - Runtime debugging
--- ---

View File

@@ -586,23 +586,24 @@ async function execAction(positionalPrompt: string | undefined, options: CliExec
const prompt_to_use = finalPrompt || ''; const prompt_to_use = finalPrompt || '';
// Load rules templates if --rule is specified (will be passed as env vars) // Load rules templates (will be passed as env vars)
// Default to universal-rigorous-style if --rule not specified
const effectiveRule = rule || 'universal-rigorous-style';
let rulesEnv: { PROTO?: string; TMPL?: string } = {}; let rulesEnv: { PROTO?: string; TMPL?: string } = {};
if (rule) { try {
try { const { loadProtocol, loadTemplate } = await import('../tools/template-discovery.js');
const { loadProtocol, loadTemplate } = await import('../tools/template-discovery.js'); const proto = loadProtocol(mode);
const proto = loadProtocol(mode); const tmpl = loadTemplate(effectiveRule);
const tmpl = loadTemplate(rule); if (proto) rulesEnv.PROTO = proto;
if (proto) rulesEnv.PROTO = proto; if (tmpl) rulesEnv.TMPL = tmpl;
if (tmpl) rulesEnv.TMPL = tmpl; if (debug) {
if (debug) { console.log(chalk.gray(` Rule loaded: ${effectiveRule}${!rule ? ' (default)' : ''}`));
console.log(chalk.gray(` Rule loaded: PROTO(${proto ? proto.length : 0} chars) + TMPL(${tmpl ? tmpl.length : 0} chars)`)); console.log(chalk.gray(` PROTO(${proto ? proto.length : 0} chars) + TMPL(${tmpl ? tmpl.length : 0} chars)`));
console.log(chalk.gray(` Use $PROTO and $TMPL in your prompt to reference them`)); console.log(chalk.gray(` Use $PROTO and $TMPL in your prompt to reference them`));
}
} catch (error) {
console.error(chalk.red(`Error loading rule template: ${error instanceof Error ? error.message : error}`));
process.exit(1);
} }
} catch (error) {
console.error(chalk.red(`Error loading rule template: ${error instanceof Error ? error.message : error}`));
process.exit(1);
} }
// Handle cache option: pack @patterns and/or content // Handle cache option: pack @patterns and/or content

View File

@@ -110,7 +110,26 @@ export class JsonLinesParser implements IOutputParser {
* Helps distinguish real errors from normal progress/output sent to stderr * Helps distinguish real errors from normal progress/output sent to stderr
* (Some CLI tools like Codex send all progress info to stderr) * (Some CLI tools like Codex send all progress info to stderr)
*/ */
private classifyNonJsonContent(content: string, originalType: 'stdout' | 'stderr'): 'stdout' | 'stderr' { private classifyNonJsonContent(content: string, originalType: 'stdout' | 'stderr'): 'stdout' | 'stderr' | 'progress' {
// Check for CLI initialization/progress patterns that should be filtered from final output
const cliProgressPatterns = [
/^Loaded cached credentials\.?$/i, // Gemini auth message
/^Loading.*\.\.\.$/i, // Loading messages
/^Initializ(ing|ed).*$/i, // Initialization messages
/^Connecting.*$/i, // Connection messages
/^Authenticat(ing|ed).*$/i, // Auth messages
/^Waiting.*$/i, // Waiting messages
/^Retry(ing)?.*$/i, // Retry messages
/^Using model:?.*$/i, // Model info
/^Session (started|resumed).*$/i, // Session info
];
for (const pattern of cliProgressPatterns) {
if (pattern.test(content.trim())) {
return 'progress'; // Will be filtered from final output
}
}
// If it came from stdout, keep it as stdout // If it came from stdout, keep it as stdout
if (originalType === 'stdout') { if (originalType === 'stdout') {
return 'stdout'; return 'stdout';
@@ -273,8 +292,11 @@ export class JsonLinesParser implements IOutputParser {
if (json.type === 'message' && json.role) { if (json.type === 'message' && json.role) {
// Gemini assistant/user message // Gemini assistant/user message
if (json.role === 'assistant') { if (json.role === 'assistant') {
// Delta messages are incremental streaming chunks - treat as progress (filtered from final output)
// Only non-delta messages are final content
const outputType = json.delta === true ? 'progress' : 'stdout';
return { return {
type: 'stdout', type: outputType,
content: json.content || '', content: json.content || '',
timestamp timestamp
}; };