feat(cli): 添加 --rule 选项支持模板自动发现

重构 ccw cli 模板系统:

- 新增 template-discovery.ts 模块,支持扁平化模板自动发现
- 添加 --rule <template> 选项,自动加载 protocol 和 template
- 模板目录从嵌套结构 (prompts/category/file.txt) 迁移到扁平结构 (prompts/category-function.txt)
- 更新所有 agent/command 文件,使用 $PROTO $TMPL 环境变量替代 $(cat ...) 模式
- 支持模糊匹配:--rule 02-review-architecture 可匹配 analysis-review-architecture.txt

其他更新:
- Dashboard: 添加 Claude Manager 和 Issue Manager 页面
- Codex-lens: 增强 chain_search 和 clustering 模块

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
catlog22
2026-01-17 19:20:24 +08:00
parent 1fae35c05d
commit f14418603a
137 changed files with 13125 additions and 301 deletions

View File

@@ -124,6 +124,13 @@ interface CliExecOptions {
cache?: string | boolean; // Cache: true = auto from CONTEXT, string = comma-separated patterns/content
injectMode?: 'none' | 'full' | 'progressive'; // Inject mode for cached content
debug?: boolean; // Enable debug logging
// Codex review options
uncommitted?: boolean; // Review uncommitted changes (default for review mode)
base?: string; // Review changes against base branch
commit?: string; // Review changes from specific commit
title?: string; // Optional title for review summary
// Template/Rules options
rule?: string; // Template name for auto-discovery (defines $PROTO and $TMPL env vars)
}
/** Cache configuration parsed from --cache */
@@ -535,7 +542,7 @@ async function statusAction(debug?: boolean): Promise<void> {
* @param {Object} options - CLI options
*/
async function execAction(positionalPrompt: string | undefined, options: CliExecOptions): Promise<void> {
const { prompt: optionPrompt, file, tool = 'gemini', mode = 'analysis', model, cd, includeDirs, stream, resume, id, noNative, cache, injectMode, debug } = options;
const { prompt: optionPrompt, file, tool = 'gemini', mode = 'analysis', model, cd, includeDirs, stream, resume, id, noNative, cache, injectMode, debug, uncommitted, base, commit, title, rule } = options;
// Enable debug mode if --debug flag is set
if (debug) {
@@ -579,6 +586,25 @@ async function execAction(positionalPrompt: string | undefined, options: CliExec
const prompt_to_use = finalPrompt || '';
// Load rules templates if --rule is specified (will be passed as env vars)
let rulesEnv: { PROTO?: string; TMPL?: string } = {};
if (rule) {
try {
const { loadProtocol, loadTemplate } = await import('../tools/template-discovery.js');
const proto = loadProtocol(mode);
const tmpl = loadTemplate(rule);
if (proto) rulesEnv.PROTO = proto;
if (tmpl) rulesEnv.TMPL = tmpl;
if (debug) {
console.log(chalk.gray(` Rule loaded: 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`));
}
} 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
let cacheSessionId: string | undefined;
let actualPrompt = prompt_to_use;
@@ -847,7 +873,14 @@ async function execAction(positionalPrompt: string | undefined, options: CliExec
id, // custom execution ID
noNative,
stream: !!stream, // stream=true → streaming enabled (no cache), stream=false → cache output (default)
outputFormat // Enable JSONL parsing for tools that support it
outputFormat, // Enable JSONL parsing for tools that support it
// Codex review options
uncommitted,
base,
commit,
title,
// Rules env vars (PROTO, TMPL)
rulesEnv: Object.keys(rulesEnv).length > 0 ? rulesEnv : undefined
}, onOutput); // Always pass onOutput for real-time dashboard streaming
if (elapsedInterval) clearInterval(elapsedInterval);