feat: Phase4 命令系统与上下文增强
新增基础设施: - TokenTracker: 真实Token使用量追踪和费用估算(按模型定价) - SkillLoader: .claude/skills/ 扫描加载,支持YAML frontmatter元数据 - GitContext: Git分支/状态/最近提交收集,注入系统提示词 新增命令 (4个): - /init: 项目CLAUDE.md初始化向导,自动检测项目类型(Maven/Gradle/Node/Python等) - /status: 会话状态仪表板(模型、Token、内存、运行时间等) - /context: 上下文概览(CLAUDE.md、Skills、Git、系统提示词大小) - /config: 配置查看/设置(支持model快捷切换和API key显示) 增强命令 (3个): - /cost: 从占位→真实Token统计,显示input/output/cache tokens和费用 - /model: 支持快捷名称切换(sonnet/opus/haiku),显示可用模型列表 - /compact: 增强显示压缩前后消息数和Token使用量 系统提示词增强: - 集成Skills摘要和Git上下文到系统提示词 - 新增Shell环境信息和更详细的Guidelines 命令总数: 6 → 10, 工具总数: 11 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -3,7 +3,8 @@ package com.claudecode.context;
|
||||
/**
|
||||
* 系统提示词构建器 —— 对应 claude-code/src/prompts.ts。
|
||||
* <p>
|
||||
* 组装完整的系统提示词,包括核心指令、环境信息、工具说明等。
|
||||
* 组装完整的系统提示词,包括核心指令、环境信息、
|
||||
* CLAUDE.md、Skills、Git 上下文等模块化内容。
|
||||
*/
|
||||
public class SystemPromptBuilder {
|
||||
|
||||
@@ -12,6 +13,8 @@ public class SystemPromptBuilder {
|
||||
private String userName;
|
||||
private String claudeMdContent;
|
||||
private String customInstructions;
|
||||
private String skillsSummary;
|
||||
private String gitSummary;
|
||||
|
||||
public SystemPromptBuilder() {
|
||||
this.workDir = System.getProperty("user.dir");
|
||||
@@ -34,6 +37,16 @@ public class SystemPromptBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
public SystemPromptBuilder skills(String skillsSummary) {
|
||||
this.skillsSummary = skillsSummary;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SystemPromptBuilder git(String gitSummary) {
|
||||
this.gitSummary = gitSummary;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建完整的系统提示词。
|
||||
*/
|
||||
@@ -53,6 +66,8 @@ public class SystemPromptBuilder {
|
||||
sb.append("- Working directory: ").append(workDir).append("\n");
|
||||
sb.append("- OS: ").append(osName).append("\n");
|
||||
sb.append("- User: ").append(userName).append("\n");
|
||||
sb.append("- Shell: ").append(System.getenv().getOrDefault("SHELL",
|
||||
System.getenv().getOrDefault("COMSPEC", "unknown"))).append("\n");
|
||||
sb.append("\n");
|
||||
|
||||
// 行为准则
|
||||
@@ -63,15 +78,27 @@ public class SystemPromptBuilder {
|
||||
- Use tools to explore the codebase before making changes
|
||||
- When writing code, follow existing patterns and conventions
|
||||
- Ask for clarification when requirements are ambiguous
|
||||
- When making file edits, always use the Edit tool with exact string matching
|
||||
- Prefer editing existing files over creating new ones
|
||||
|
||||
""");
|
||||
|
||||
// Git 上下文
|
||||
if (gitSummary != null && !gitSummary.isBlank()) {
|
||||
sb.append(gitSummary).append("\n");
|
||||
}
|
||||
|
||||
// CLAUDE.md 内容
|
||||
if (claudeMdContent != null && !claudeMdContent.isBlank()) {
|
||||
sb.append("# Project Instructions (CLAUDE.md)\n");
|
||||
sb.append(claudeMdContent).append("\n\n");
|
||||
}
|
||||
|
||||
// Skills 摘要
|
||||
if (skillsSummary != null && !skillsSummary.isBlank()) {
|
||||
sb.append(skillsSummary).append("\n");
|
||||
}
|
||||
|
||||
// 自定义指令
|
||||
if (customInstructions != null && !customInstructions.isBlank()) {
|
||||
sb.append("# Custom Instructions\n");
|
||||
|
||||
Reference in New Issue
Block a user