feat: 升级至 v0.3.0 — 安全增强、死循环检测、六轮全面审计修复
大版本迭代,新增安全增强、Agent Loop 增强、UI/UX 增强,经六轮全面审计修复所有问题。
新增功能:
- OutputValidator 事实一致性检查 + 幻觉检测
- PromptInjectionDefender 语义级检测(指令性动词密度、角色边界、分隔符嵌套)
- DeadLoopError 死循环检测(连续3轮相同工具调用自动终止)
- PolicyEngine maxFrequency 滑动窗口频率限制
- MemoryManager TF-IDF 语义检索 + IDF 缓存原子替换
- 斜杠命令(/tool /memory /clear /export)+ 快捷键(Ctrl+B/J/Shift+F/N/[/])
- 专注模式(Ctrl+Shift+F)带面板状态快照保存/恢复
六轮审计修复(共修复 3 CRITICAL + 8 HIGH + 13 MEDIUM + 11 LOW):
CRITICAL:
- main.ts 传入 createAdapter 而非 reloadAdapter,导致 Provider 切换完全失效
- Ctrl+N/Ctrl+[/Ctrl+] 不同步 agent-store,导致消息发到错误会话
- engine.ts emit('error') 无监听器导致 DONE 事件丢失、前端卡死
HIGH:
- 死循环检测在工具执行之后(移入 PARSING 后 EXECUTING 前)
- deadLoop 事件前端未处理
- ConfirmationHook.clearPending 从未调用导致定时器泄漏
- engine.ts retry abort listener 未移除导致监听器堆积
- MCPManager JSON.parse 无 try-catch 导致初始化崩溃
- sendMessage 自动创建会话不同步 session-store
- setCurrentSession 竞态导致旧请求覆盖新会话数据
MEDIUM:
- toggleFocusMode 覆盖用户原有面板状态
- 正则检测可被常见词绕过
- 频率限制内存泄漏 + customPolicies 覆盖
- LIKE 回退转义未包含反斜杠
- OutputValidator 新功能未传入 toolResults/context
- MemoryConsolidator LLM 调用无超时保护
- AuditService 每次 log 都查询数据库
- browser-window-manager 超时后未停止页面加载
- output-validator URL 比较大小写敏感
- FileReader 无 onerror 导致 Promise 永久挂起
- /clear /export 不关闭斜杠菜单
- 专注模式下 toggleSidebar/toggleDetail 未恢复另一面板快照
LOW:
- abortPromise 事件监听器堆积
- RateLimitHook Map 内存泄漏
- memory.ts await 同步方法
- PolicyEngine 死代码清理
- Orchestrator sessionDepth 会话结束不清理
- workspace.service.ts 元数据插入边界问题
This commit is contained in:
@@ -12,8 +12,15 @@ import { toggleTheme } from './useTheme';
|
||||
|
||||
/**
|
||||
* 检测是否为 macOS
|
||||
* v0.3.0 修复:navigator.platform 已废弃,改用 userAgentData(Chromium 90+)或降级到 platform
|
||||
*/
|
||||
function isMac(): boolean {
|
||||
// 优先使用 userAgentData.platform(现代 API)
|
||||
const userAgentData = (navigator as Navigator & { userAgentData?: { platform?: string } }).userAgentData;
|
||||
if (userAgentData?.platform) {
|
||||
return userAgentData.platform.toUpperCase().includes('MAC');
|
||||
}
|
||||
// 降级到 navigator.platform(已废弃但仍可用)
|
||||
return navigator.platform.toUpperCase().indexOf('MAC') >= 0;
|
||||
}
|
||||
|
||||
@@ -55,6 +62,8 @@ export function useKeyboardShortcuts(): void {
|
||||
window.metona.sessions.create().then((result: MetonaSessionInfo) => {
|
||||
useSessionStore.getState().addSession(result);
|
||||
useSessionStore.getState().setCurrentSession(result.id);
|
||||
// v0.3.0 修复: 同步 agent-store,确保聊天面板清空并加载新会话
|
||||
useAgentStore.getState().setCurrentSession(result.id);
|
||||
}).catch((err) => { console.error('[KeyboardShortcuts]', err); });
|
||||
}
|
||||
e.preventDefault();
|
||||
@@ -101,7 +110,12 @@ export function useKeyboardShortcuts(): void {
|
||||
const { sessions, currentSessionId, setCurrentSession } = useSessionStore.getState();
|
||||
if (sessions.length > 0 && currentSessionId) {
|
||||
const idx = sessions.findIndex((s) => s.id === currentSessionId);
|
||||
if (idx > 0) setCurrentSession(sessions[idx - 1].id);
|
||||
// v0.3.0 修复: 同步 agent-store,确保聊天面板加载新会话消息
|
||||
if (idx > 0) {
|
||||
const newId = sessions[idx - 1].id;
|
||||
setCurrentSession(newId);
|
||||
useAgentStore.getState().setCurrentSession(newId);
|
||||
}
|
||||
}
|
||||
e.preventDefault();
|
||||
return;
|
||||
@@ -112,14 +126,25 @@ export function useKeyboardShortcuts(): void {
|
||||
const { sessions, currentSessionId, setCurrentSession } = useSessionStore.getState();
|
||||
if (sessions.length > 0 && currentSessionId) {
|
||||
const idx = sessions.findIndex((s) => s.id === currentSessionId);
|
||||
if (idx < sessions.length - 1) setCurrentSession(sessions[idx + 1].id);
|
||||
// v0.3.0 修复: 同步 agent-store,确保聊天面板加载新会话消息
|
||||
if (idx < sessions.length - 1) {
|
||||
const newId = sessions[idx + 1].id;
|
||||
setCurrentSession(newId);
|
||||
useAgentStore.getState().setCurrentSession(newId);
|
||||
}
|
||||
}
|
||||
e.preventDefault();
|
||||
return;
|
||||
}
|
||||
|
||||
// Ctrl+Shift+C — 复制最后一条 Agent 回复
|
||||
// v0.3.0 修复:若有任何选中文本(无论是否在输入框),跳过(让浏览器执行默认复制操作)
|
||||
if (key === 'c' && matchModifier(e, true, true)) {
|
||||
const selection = window.getSelection();
|
||||
if (selection && selection.toString().length > 0) {
|
||||
// 有选中文本,让浏览器执行默认复制操作
|
||||
return;
|
||||
}
|
||||
const { messages } = useAgentStore.getState();
|
||||
const lastAssistant = [...messages].reverse().find((m) => m.role === 'assistant');
|
||||
if (lastAssistant?.content) {
|
||||
@@ -128,6 +153,27 @@ export function useKeyboardShortcuts(): void {
|
||||
e.preventDefault();
|
||||
return;
|
||||
}
|
||||
|
||||
// v0.3.0: Ctrl+B — 切换侧边栏
|
||||
if (key === 'b' && matchModifier(e, true)) {
|
||||
useUIStore.getState().toggleSidebar();
|
||||
e.preventDefault();
|
||||
return;
|
||||
}
|
||||
|
||||
// v0.3.0: Ctrl+J — 切换详情面板
|
||||
if (key === 'j' && matchModifier(e, true)) {
|
||||
useUIStore.getState().toggleDetail();
|
||||
e.preventDefault();
|
||||
return;
|
||||
}
|
||||
|
||||
// v0.3.0: Ctrl+Shift+F — 专注模式
|
||||
if (key === 'f' && matchModifier(e, true, true)) {
|
||||
useUIStore.getState().toggleFocusMode();
|
||||
e.preventDefault();
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
window.addEventListener('keydown', handleKeyDown);
|
||||
|
||||
Reference in New Issue
Block a user