mirror of
https://github.com/catlog22/Claude-Code-Workflow.git
synced 2026-02-13 02:41:50 +08:00
refactor(routes): 更新 rules-routes 和 claude-routes 使用 $PROTO $TMPL
- rules-routes.ts: 替换 4 处 $(cat ...) 模板引用为 $PROTO $TMPL - claude-routes.ts: 替换 2 处 $(cat ...) 模板引用为 $PROTO $TMPL - 添加 loadProtocol/loadTemplate 导入 - 在 executeCliTool 调用中添加 rulesEnv 参数 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -314,7 +314,7 @@ TASK: • Analyze module's purpose and responsibilities • Document public APIs
|
||||
MODE: analysis
|
||||
CONTEXT: @${modulePath}/**/* | Memory: Project conventions from .claude/CLAUDE.md
|
||||
EXPECTED: Module-level CLAUDE.md with: - Module purpose (1-2 sentences) - Key files and their roles - Public API documentation - Integration points - Testing approach
|
||||
RULES: $(cat ~/.claude/workflows/cli-templates/prompts/planning/02-design-component-spec.txt) | Module-level perspective only | Concrete examples | analysis=READ-ONLY`;
|
||||
RULES: $PROTO $TMPL | Module-level perspective only | Concrete examples | analysis=READ-ONLY`;
|
||||
} else {
|
||||
// User/Project level prompt
|
||||
const contextPath = level === 'user' ? '~/.claude' : '.claude';
|
||||
@@ -323,7 +323,7 @@ TASK: • Analyze ${level} configuration and conventions • Identify common pat
|
||||
MODE: analysis
|
||||
CONTEXT: @${contextPath}/**/*
|
||||
EXPECTED: Updated CLAUDE.md content with: - Preserved existing sections - New insights appended to relevant sections - Timestamp header - Focus on ${level}-level concerns
|
||||
RULES: $(cat ~/.claude/workflows/cli-templates/prompts/analysis/02-analyze-code-patterns.txt) | Maintain existing CLAUDE.md structure | Focus on actionable rules | analysis=READ-ONLY`;
|
||||
RULES: $PROTO $TMPL | Maintain existing CLAUDE.md structure | Focus on actionable rules | analysis=READ-ONLY`;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -559,6 +559,7 @@ export async function handleClaudeRoutes(ctx: RouteContext): Promise<boolean> {
|
||||
// Import CLI executor and content formatter
|
||||
const { executeCliTool } = await import('../../tools/cli-executor.js');
|
||||
const { SmartContentFormatter } = await import('../../tools/cli-output-converter.js');
|
||||
const { loadProtocol, loadTemplate } = await import('../../tools/template-discovery.js');
|
||||
|
||||
// Determine file path based on level
|
||||
let filePath: string;
|
||||
@@ -617,6 +618,15 @@ export async function handleClaudeRoutes(ctx: RouteContext): Promise<boolean> {
|
||||
});
|
||||
};
|
||||
|
||||
// Build rulesEnv for $PROTO and $TMPL injection
|
||||
const templateName = level === 'module'
|
||||
? 'planning-design-component-spec'
|
||||
: 'analysis-analyze-code-patterns';
|
||||
const rulesEnv = {
|
||||
PROTO: loadProtocol('analysis'),
|
||||
TMPL: loadTemplate(templateName)
|
||||
};
|
||||
|
||||
const startTime = Date.now();
|
||||
const result = await executeCliTool({
|
||||
tool: tool === 'qwen' ? 'qwen' : 'gemini',
|
||||
@@ -627,7 +637,8 @@ export async function handleClaudeRoutes(ctx: RouteContext): Promise<boolean> {
|
||||
timeout: 600000, // 10 minutes
|
||||
stream: false,
|
||||
category: 'internal',
|
||||
id: syncId
|
||||
id: syncId,
|
||||
rulesEnv
|
||||
}, (unit) => {
|
||||
// CliOutputUnit handler: use SmartContentFormatter for intelligent formatting (never returns null)
|
||||
const content = SmartContentFormatter.format(unit.content, unit.type);
|
||||
|
||||
@@ -7,6 +7,7 @@ import { join } from 'path';
|
||||
import { homedir } from 'os';
|
||||
import { executeCliTool } from '../../tools/cli-executor.js';
|
||||
import { SmartContentFormatter } from '../../tools/cli-output-converter.js';
|
||||
import { loadProtocol, loadTemplate } from '../../tools/template-discovery.js';
|
||||
import type { RouteContext } from './types.js';
|
||||
|
||||
interface ParsedRuleFrontmatter {
|
||||
@@ -445,7 +446,7 @@ FILE NAME: ${fileName}
|
||||
${subdirectory ? `SUBDIRECTORY: ${subdirectory}` : ''}
|
||||
${reviewInstruction}
|
||||
|
||||
RULES: $(cat ~/.claude/workflows/cli-templates/prompts/universal/00-universal-rigorous-style.txt) | Generate ONLY the rule content in markdown | No additional commentary | Do NOT use any tools | Output raw markdown text directly | write=CREATE`;
|
||||
RULES: $PROTO $TMPL | Generate ONLY the rule content in markdown | No additional commentary | Do NOT use any tools | Output raw markdown text directly | write=CREATE`;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -516,7 +517,7 @@ FILE NAME: ${fileName}
|
||||
${subdirectory ? `SUBDIRECTORY: ${subdirectory}` : ''}
|
||||
INFERRED CATEGORY: ${context.category}
|
||||
|
||||
RULES: $(cat ~/.claude/workflows/cli-templates/prompts/analysis/02-analyze-code-patterns.txt) | Extract REAL patterns from code | Include actual code snippets as examples | Do NOT use any tools | Output raw markdown text directly | analysis=READ-ONLY`;
|
||||
RULES: $PROTO $TMPL | Extract REAL patterns from code | Include actual code snippets as examples | Do NOT use any tools | Output raw markdown text directly | analysis=READ-ONLY`;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -567,7 +568,7 @@ EXPECTED OUTPUT:
|
||||
- If the original is already high quality, return it unchanged
|
||||
- Preserve any frontmatter (---paths---) if present
|
||||
|
||||
RULES: $(cat ~/.claude/workflows/cli-templates/prompts/universal/00-universal-rigorous-style.txt) | Output ONLY improved markdown content | No additional text | Do NOT use any tools | Output raw markdown text directly | write=CREATE`;
|
||||
RULES: $PROTO $TMPL | Output ONLY improved markdown content | No additional text | Do NOT use any tools | Output raw markdown text directly | write=CREATE`;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -628,7 +629,7 @@ async function generateRuleViaCLI(params: RuleGenerateParams): Promise<Record<st
|
||||
TASK: • Create rule based on ${templateType} template • Generate structured markdown content
|
||||
MODE: write
|
||||
EXPECTED: Complete rule content in markdown format following template structure
|
||||
RULES: $(cat ~/.claude/workflows/cli-templates/prompts/universal/00-universal-rigorous-style.txt) | Follow Claude Code rule format | Use ${templateType} template patterns | Do NOT use any tools | Output raw markdown text directly | write=CREATE
|
||||
RULES: $PROTO $TMPL | Follow Claude Code rule format | Use ${templateType} template patterns | Do NOT use any tools | Output raw markdown text directly | write=CREATE
|
||||
|
||||
TEMPLATE TYPE: ${templateType}
|
||||
FILE NAME: ${fileName}`;
|
||||
@@ -676,6 +677,15 @@ FILE NAME: ${fileName}`;
|
||||
}
|
||||
: undefined;
|
||||
|
||||
// Build rulesEnv for $PROTO and $TMPL injection
|
||||
const templateName = generationType === 'extract'
|
||||
? 'analysis-analyze-code-patterns'
|
||||
: 'universal-universal-rigorous-style';
|
||||
const rulesEnv = {
|
||||
PROTO: loadProtocol(mode),
|
||||
TMPL: loadTemplate(templateName)
|
||||
};
|
||||
|
||||
// Execute CLI tool (Claude) with at least 10 minutes timeout
|
||||
const startTime = Date.now();
|
||||
const result = await executeCliTool({
|
||||
@@ -685,7 +695,8 @@ FILE NAME: ${fileName}`;
|
||||
cd: workingDir,
|
||||
timeout: 600000, // 10 minutes
|
||||
category: 'internal',
|
||||
id: executionId
|
||||
id: executionId,
|
||||
rulesEnv
|
||||
}, onOutput);
|
||||
|
||||
// Broadcast CLI_EXECUTION_COMPLETED event
|
||||
@@ -763,6 +774,12 @@ FILE NAME: ${fileName}`;
|
||||
}
|
||||
: undefined;
|
||||
|
||||
// Build rulesEnv for review step
|
||||
const reviewRulesEnv = {
|
||||
PROTO: loadProtocol('write'),
|
||||
TMPL: loadTemplate('universal-universal-rigorous-style')
|
||||
};
|
||||
|
||||
const reviewStartTime = Date.now();
|
||||
const reviewExecution = await executeCliTool({
|
||||
tool: 'claude',
|
||||
@@ -771,7 +788,8 @@ FILE NAME: ${fileName}`;
|
||||
cd: workingDir,
|
||||
timeout: 300000, // 5 minutes for review
|
||||
category: 'internal',
|
||||
id: reviewExecutionId
|
||||
id: reviewExecutionId,
|
||||
rulesEnv: reviewRulesEnv
|
||||
}, reviewOnOutput);
|
||||
|
||||
// Broadcast review CLI_EXECUTION_COMPLETED event
|
||||
|
||||
Reference in New Issue
Block a user