refactor(core): 移除未使用的 prompt-template templates 目录

This commit is contained in:
2025-12-16 14:19:36 +08:00
parent 3baf3c0171
commit 452f19e2a9
5 changed files with 1 additions and 225 deletions
-5
View File
@@ -69,11 +69,6 @@ export {
createPlanContext,
checkPlanFileExists,
DEFAULT_TOOL_NAMES,
generatePlanPrompt,
resolveAgentPrompt,
PLAN_MODE_TEMPLATE,
PLAN_MODE_SUBAGENT_TEMPLATE,
PLAN_MODE_REMINDER_TEMPLATE,
} from './prompt-template/index.js';
export type {
@@ -11,7 +11,7 @@
* import { renderTemplate, createPlanContext } from './prompt-template';
*
* const context = createPlanContext({ workdir: '/path/to/project' });
* const prompt = renderTemplate(PLAN_MODE_TEMPLATE.template, context);
* const prompt = renderTemplate(template, context);
* ```
*/
@@ -35,61 +35,3 @@ export {
checkPlanFileExists,
DEFAULT_TOOL_NAMES,
} from './renderer.js';
// 模板导出
export {
PLAN_MODE_TEMPLATE,
PLAN_MODE_SUBAGENT_TEMPLATE,
PLAN_MODE_REMINDER_TEMPLATE,
} from './templates/index.js';
// 便捷函数
import { renderTemplate, createPlanContext } from './renderer.js';
import { PLAN_MODE_TEMPLATE, PLAN_MODE_SUBAGENT_TEMPLATE } from './templates/index.js';
/**
* 生成 Plan 模式提示词
*
* @param options 配置选项
* @returns 渲染后的提示词
*/
export function generatePlanPrompt(options: {
isSubagent?: boolean;
workdir?: string;
planFilePath?: string;
}): string {
const context = createPlanContext(options);
const template = options.isSubagent ? PLAN_MODE_SUBAGENT_TEMPLATE : PLAN_MODE_TEMPLATE;
return renderTemplate(template.template, context);
}
/**
* 动态解析 Agent 提示词
* 在运行时根据上下文生成最终提示词
*
* @param basePrompt 基础提示词(可能包含模板变量)
* @param options 上下文选项
* @returns 渲染后的提示词
*/
export function resolveAgentPrompt(
basePrompt: string,
options: {
workdir?: string;
planFilePath?: string;
isSubagent?: boolean;
isPlanMode?: boolean;
}
): string {
const context = createPlanContext({
workdir: options.workdir,
planFilePath: options.planFilePath,
isSubagent: options.isSubagent,
});
// 如果不是 Plan 模式,设置 plan.isActive = false
if (!options.isPlanMode) {
context.plan.isActive = false;
}
return renderTemplate(basePrompt, context);
}
@@ -1,9 +0,0 @@
/**
* 提示词模板导出
*/
export {
PLAN_MODE_TEMPLATE,
PLAN_MODE_SUBAGENT_TEMPLATE,
PLAN_MODE_REMINDER_TEMPLATE,
} from './plan-mode.js';
@@ -1,113 +0,0 @@
/**
* Plan 模式提示词模板
*
* 使用 ${variable} 语法支持动态变量替换
*/
import type { PromptTemplate } from '../types.js';
/**
* Plan 模式主提示词模板
*/
export const PLAN_MODE_TEMPLATE: PromptTemplate = {
name: 'plan-mode',
description: 'Plan 模式主提示词 - 用于代码探索和实现方案设计',
requiredVariables: ['tools', 'plan'],
template: `You are a software architect and planning specialist for Claude Code. Your role is to explore the codebase and design implementation plans.
=== CRITICAL: READ-ONLY MODE - NO FILE MODIFICATIONS ===
This is a READ-ONLY planning task. You are STRICTLY PROHIBITED from:
- Creating new files (no Write, touch, or file creation of any kind)
- Modifying existing files (no Edit operations)
- Deleting files (no rm or deletion)
- Moving or copying files (no mv or cp)
- Creating temporary files anywhere, including /tmp
- Using redirect operators (>, >>, |) or heredocs to write to files
- Running ANY commands that change system state
Your role is EXCLUSIVELY to explore the codebase and design implementation plans. You do NOT have access to file editing tools - attempting to edit files will fail.
## Plan File Info
\${plan.planExists ? "A plan file already exists at \${plan.planFilePath}. You can read it and make incremental edits using the \${tools.edit} tool." : "No plan file exists yet. You should create your plan at \${plan.planFilePath} using the \${tools.write} tool."}
You should build your plan incrementally by writing to or editing this file. NOTE that this is the only file you are allowed to edit - other than this you are only allowed to take READ-ONLY actions.
You will be provided with a set of requirements and optionally a perspective on how to approach the design process.
## Your Process
1. **Understand Requirements**: Focus on the requirements provided and apply your assigned perspective throughout the design process.
2. **Explore Thoroughly**:
- Read any files provided to you in the initial prompt
- Find existing patterns and conventions using \${tools.glob}, \${tools.grep}, and \${tools.read}
- Understand the current architecture
- Identify similar features as reference
- Trace through relevant code paths
- Use \${tools.bash} ONLY for read-only operations (ls, git status, git log, git diff, find, cat, head, tail)
- NEVER use \${tools.bash} for: mkdir, touch, rm, cp, mv, git add, git commit, npm install, pip install, or any file creation/modification
3. **Design Solution**:
- Create implementation approach based on your assigned perspective
- Consider trade-offs and architectural decisions
- Follow existing patterns where appropriate
4. **Detail the Plan**:
- Provide step-by-step implementation strategy
- Identify dependencies and sequencing
- Anticipate potential challenges
## Required Output
End your response with:
### Critical Files for Implementation
List 3-5 files most critical for implementing this plan:
- path/to/file1.ts - [Brief reason: e.g., "Core logic to modify"]
- path/to/file2.ts - [Brief reason: e.g., "Interfaces to implement"]
- path/to/file3.ts - [Brief reason: e.g., "Pattern to follow"]
Answer the user's query comprehensively, using the \${tools.askUserQuestion} tool if you need to ask clarifying questions.
REMEMBER: You can ONLY explore and plan. You CANNOT and MUST NOT write, edit, or modify any files (except the plan file at \${plan.planFilePath}).`,
};
/**
* Plan 模式子代理提示词模板(简化版)
* 用于作为子代理时的精简提示
*/
export const PLAN_MODE_SUBAGENT_TEMPLATE: PromptTemplate = {
name: 'plan-mode-subagent',
description: 'Plan 模式子代理提示词(简化版)',
requiredVariables: ['tools', 'plan'],
template: `Plan mode is active. The user indicated that they do not want you to execute yet -- you MUST NOT make any edits, run any non-readonly tools (including changing configs or making commits), or otherwise make any changes to the system. This supercedes any other instructions you have received.
## Plan File Info
\${plan.planExists ? "A plan file already exists at \${plan.planFilePath}. You can read it and make incremental edits using the \${tools.edit} tool if you need to." : "No plan file exists yet. You should create your plan at \${plan.planFilePath} using the \${tools.write} tool if you need to."}
You should build your plan incrementally by writing to or editing this file. NOTE that this is the only file you are allowed to edit - other than this you are only allowed to take READ-ONLY actions.
## Available Tools
- Use \${tools.glob}, \${tools.grep}, and \${tools.read} for code exploration
- Use \${tools.bash} ONLY for read-only operations
- Use \${tools.askUserQuestion} to ask clarifying questions
Answer the user's query comprehensively, exploring the codebase as needed.
REMEMBER: You can ONLY explore and plan. Do NOT modify any files except the plan file.`,
};
/**
* Plan 模式系统提醒模板(用于注入到消息中)
*/
export const PLAN_MODE_REMINDER_TEMPLATE: PromptTemplate = {
name: 'plan-mode-reminder',
description: 'Plan 模式系统提醒',
template: `<system-reminder>
Plan mode is active. The user indicated that they do not want you to execute yet -- you MUST NOT make any edits (with the exception of the plan file mentioned below), run any non-readonly tools (including changing configs or making commits), or otherwise make any changes to the system. This supercedes any other instructions you have received.
## Plan File Info:
\${plan.planExists ? "A plan file already exists at \${plan.planFilePath}. You can read it and make incremental edits." : "No plan file exists yet. You should create your plan at \${plan.planFilePath}."}
You should build your plan incrementally by writing to or editing this file. NOTE that this is the only file you are allowed to edit - other than this you are only allowed to take READ-ONLY actions.
</system-reminder>`,
};
@@ -4,8 +4,6 @@ import {
createDefaultContext,
createPlanContext,
DEFAULT_TOOL_NAMES,
generatePlanPrompt,
resolveAgentPrompt,
} from '../../../src/agent/prompt-template/index.js';
import type { PromptContext } from '../../../src/agent/prompt-template/types.js';
@@ -153,43 +151,6 @@ describe('Prompt Template System', () => {
});
});
describe('generatePlanPrompt', () => {
it('should generate prompt with tool names resolved', () => {
const prompt = generatePlanPrompt({});
expect(prompt).toContain('glob');
expect(prompt).toContain('grep_content');
expect(prompt).toContain('read_file');
});
it('should include plan file path', () => {
const prompt = generatePlanPrompt({ planFilePath: '/test/plan.md' });
expect(prompt).toContain('/test/plan.md');
});
it('should generate shorter prompt for subagent', () => {
const mainPrompt = generatePlanPrompt({ isSubagent: false });
const subPrompt = generatePlanPrompt({ isSubagent: true });
expect(subPrompt.length).toBeLessThan(mainPrompt.length);
});
});
describe('resolveAgentPrompt', () => {
it('should resolve template variables in prompt', () => {
const basePrompt = 'Use ${tools.glob} to search';
const resolved = resolveAgentPrompt(basePrompt, {});
expect(resolved).toBe('Use glob to search');
});
it('should handle isPlanMode option', () => {
const basePrompt = '${plan.isActive ? "Plan mode" : "Normal mode"}';
const planResolved = resolveAgentPrompt(basePrompt, { isPlanMode: true });
expect(planResolved).toBe('Plan mode');
const normalResolved = resolveAgentPrompt(basePrompt, { isPlanMode: false });
expect(normalResolved).toBe('Normal mode');
});
});
describe('Edge Cases', () => {
it('should handle empty template', () => {
const result = renderTemplate('', context);