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

@@ -586,23 +586,24 @@ 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)
// 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 } = {};
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);
try {
const { loadProtocol, loadTemplate } = await import('../tools/template-discovery.js');
const proto = loadProtocol(mode);
const tmpl = loadTemplate(effectiveRule);
if (proto) rulesEnv.PROTO = proto;
if (tmpl) rulesEnv.TMPL = tmpl;
if (debug) {
console.log(chalk.gray(` Rule loaded: ${effectiveRule}${!rule ? ' (default)' : ''}`));
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`));
}
} 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

View File

@@ -110,7 +110,26 @@ export class JsonLinesParser implements IOutputParser {
* Helps distinguish real errors from normal progress/output sent 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 (originalType === 'stdout') {
return 'stdout';
@@ -273,8 +292,11 @@ export class JsonLinesParser implements IOutputParser {
if (json.type === 'message' && json.role) {
// Gemini assistant/user message
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 {
type: 'stdout',
type: outputType,
content: json.content || '',
timestamp
};