fix: 全面修复审计问题并优化系统提示词
**崩溃/挂死修复 (5):** - 统一 TrayManager.isQuitting 变量,修复 Cmd+Q 无法退出 - useAgentStream 闭包过期快照 → 每次 getState() - Agnes chatStream 添加 AbortSignal.timeout - SSE JSON.parse 添加 try-catch 保护 - Orchestrator setTools 污染 → save/restore 模式 **功能修复 (14):** - 上下文压缩实现 (每5轮 COMPRESSING 状态) - 修复 requestId 硬编码空串 - ConfigService.set() 保留已有 category - MemoryManager 新增 working 类型搜索 - PromptInjectionDefender 补全 sanitize() - Ollama: 补全 dynamicReminders + reasoningContent - openai-format: 所有 assistant 消息保留 reasoningContent - SSE: finish_reason 时提前 flush tool_calls - DeepSeek thinking effort 映射注释 - Ollama done_reason load→stop - RateLimitHook >= 边界修复 - WorkspaceService isValid 首次启动修复 - sessions:archive IPC handler - 托盘/窗口图标路径生产环境修复 **系统提示词优化:** - SOUL.md 存在时不显示兜底身份,原文放最前 - 兜底身份改为中文 (MetonaAI 自身描述) - 用户文本在前,附件内容在后 **文件上传:** - 非图片文件不再 base64 编码,保留 JSON 结构 - 用户文本优先于文件内容 **UI 修复:** - 首页 Logo 路径修复 (public/ + 相对路径) - TokenUsage contextWindow 动态计算 (Provider 感知) - 切换 Provider 同步 contextWindow - 托盘图标始终显示 Logo (状态由右键菜单展示)
This commit is contained in:
@@ -77,8 +77,18 @@ export class ContextBuilder {
|
||||
* 5. 内置安全准则 — 尾部锚定
|
||||
*/
|
||||
buildSystemPrompt(workspaceFiles?: WorkspaceFiles): MetonaSystemPrompt {
|
||||
let staticUserProfile = '';
|
||||
|
||||
// ===== 静态区:用户画像(变化不频繁,放入静态区利用 LLM 缓存)=====
|
||||
if (workspaceFiles?.users) {
|
||||
const usersContent = this.extractContent(workspaceFiles.users);
|
||||
if (usersContent) {
|
||||
staticUserProfile = `## 用户画像\n${usersContent}`;
|
||||
}
|
||||
}
|
||||
|
||||
// ===== 静态区:角色定义(SOUL.md)=====
|
||||
const roleDefinition = this.buildRoleDefinition(workspaceFiles?.soul);
|
||||
const roleDefinition = this.buildRoleDefinition(workspaceFiles?.soul, staticUserProfile);
|
||||
|
||||
// ===== 静态区:行为规则(AGENTS.md)=====
|
||||
const outputConstraints = this.buildOutputConstraints(workspaceFiles?.agents);
|
||||
@@ -86,16 +96,9 @@ export class ContextBuilder {
|
||||
// ===== 静态区:安全准则 =====
|
||||
const safetyGuidelines = this.buildSafetyGuidelines();
|
||||
|
||||
// ===== 动态区:记忆 + 用户画像 =====
|
||||
// ===== 动态区:记忆 =====
|
||||
const dynamicParts: string[] = [];
|
||||
|
||||
if (workspaceFiles?.users) {
|
||||
const usersContent = this.extractContent(workspaceFiles.users);
|
||||
if (usersContent) {
|
||||
dynamicParts.push(`## 用户画像\n${usersContent}`);
|
||||
}
|
||||
}
|
||||
|
||||
if (workspaceFiles?.memory) {
|
||||
const memoryContent = this.extractContent(workspaceFiles.memory);
|
||||
if (memoryContent) {
|
||||
@@ -121,20 +124,24 @@ export class ContextBuilder {
|
||||
/**
|
||||
* 构建角色定义(来自 SOUL.md)
|
||||
*/
|
||||
private buildRoleDefinition(soulContent?: string): string {
|
||||
private buildRoleDefinition(soulContent?: string, userProfile?: string): string {
|
||||
const parts: string[] = [];
|
||||
|
||||
// 基础身份
|
||||
parts.push(`# Role Definition
|
||||
You are Metona, a professional AI Agent powered by ReAct reasoning loop.
|
||||
You operate in a desktop environment with access to file system, network, memory, and command execution tools.`);
|
||||
|
||||
// SOUL.md 内容
|
||||
// SOUL.md 内容 — 始终在系统提示词最前面,不做任何内容跳过
|
||||
if (soulContent) {
|
||||
const content = this.extractContent(soulContent);
|
||||
if (content) {
|
||||
parts.push(`## Agent Soul (User-Defined)\n${content}`);
|
||||
}
|
||||
// SOUL.md 存在时,直接使用其全部内容,不加任何固定前缀
|
||||
parts.push(soulContent);
|
||||
} else {
|
||||
// SOUL.md 不存在时的兜底基础身份
|
||||
parts.push(`# 身份定义
|
||||
你是 MetonaAI,一款运行在用户本地桌面上的通用 AI Agent 智能体应用。
|
||||
你拥有访问文件系统、网络搜索、记忆管理和命令行执行等工具能力。
|
||||
你的目标是帮助用户高效完成各种任务,始终坚持准确、可靠、安全的原则。`);
|
||||
}
|
||||
|
||||
// 用户画像(静态区)
|
||||
if (userProfile) {
|
||||
parts.push(userProfile);
|
||||
}
|
||||
|
||||
return parts.join('\n\n');
|
||||
|
||||
Reference in New Issue
Block a user