feat: v0.4.0 四阶段迭代 — 安全加固 + 工程基线 + 架构重构 + 双 Provider 扩展

P0 安全修复:
- API Key 加密存储(safeStorage 密钥链,版本化前缀,历史明文平滑兼容)
- 间接提示注入防护(SecurityScanHook 工具结果深扫描,网络工具脱敏/本地工具警示分级)
- error:report IPC 断链修复(渲染进程错误上报落 electron-log + 审计)
- abort 信号贯通工具层(run_command/dev-tools 子进程随会话中断终止)
- run_command 沙箱加固(cd 系统目录/敏感文件读取拦截 + chcp 前缀剥离防解析退化)
- .env 真实生效(dotenv 回退加载,应用内配置优先)

P1 工程基础:
- ESLint 9 flat config + 全部 34 条存量 warnings 清零(零容忍基线)
- 测试基线 118 用例 11 文件(token/文件防护/权限/沙箱/注入/命令/引擎/注册表/审计链/摘要分层)
- test:electron 双模式(ELECTRON_RUN_AS_NODE 跑 Electron ABI,SQLite 套件全执行)
- SessionRecorder 多会话隔离 + 9 种 TRACE 事件补全(含最终轮 iteration_end)
- Provider 故障转移(重试耗尽/不可重试一次性切换 fallback + 前端通知)
- MCP 真就绪(等待全部连接完成再广播 tools:ready)
- SLO/HealthChecker 真实接入(60s 巡检 + 托盘状态)
- CONFIG_DEFAULTS 单一来源(消除 SEED 双源漂移)

P2 架构升级:
- handlers.ts 1940 行拆分为 13 个 IPC 域模块(防重入注册 + 多窗口广播)
- AgentEngineManager 每会话独立引擎(LRU 30 + adapter 工厂隔离 abort 信号)
- TaskOrchestrator EngineProvider 改造 + abortByParent 联动中断 SubAgent
- 会话摘要分层上下文(session_summaries 滚动摘要 + 截断游标清理防因果污染)
- 消息编辑重发/重新生成(truncateAfter IPC + store 动作 + UI)
- Markdown 导出 / WebSearch 并行抓取(并发 3)/ 记忆 TF 缓存 / 版本构建期注入

P3 能力扩展:
- OpenAI Adapter(o 系列推理模型 reasoning_effort/max_completion_tokens)
- Anthropic Adapter(原生 Messages API:tool_use 块/角色合并/thinking budget/图片 base64/SSE 事件机)
- 设置页/Onboarding 六 Provider 全链路接入
This commit is contained in:
2026-08-20 23:17:02 +08:00
parent b9f7ec5118
commit 2230bcec3f
90 changed files with 6581 additions and 2771 deletions
+101
View File
@@ -164,6 +164,16 @@ interface AgentState {
saveTraceData: () => void;
clearMessages: () => void;
abort: () => void;
/**
* P2-11: 编辑重发——截断该用户消息(含)之后的所有消息,重新发送修订内容
* @param messageId 原用户消息 ID
* @param newContent 修订后的内容
*/
editAndResend: (messageId: string, newContent: string) => Promise<void>;
/**
* P2-11: 重新生成——删除最后一条用户消息(含)之后的所有消息并重发原内容
*/
regenerate: () => Promise<void>;
}
export const useAgentStore = create<AgentState>((set, get) => ({
@@ -497,4 +507,95 @@ export const useAgentStore = create<AgentState>((set, get) => ({
window.metona.agent.abortSession(sessionId).catch((err) => { console.error('[AgentStore]', err); });
}
},
// ===== P2-11: 编辑重发 =====
editAndResend: async (messageId, newContent) => {
const { messages, currentSessionId, isStreaming } = get();
if (isStreaming) {
import('@metona-team/metona-toast').then((mod) => mod.default.warning('Agent 正在回复中,请先中断再编辑重发')).catch(() => {});
return;
}
const idx = messages.findIndex((m) => m.id === messageId);
if (idx < 0 || messages[idx].role !== 'user') return;
const original = messages[idx];
if (!newContent.trim()) return;
// DB 截断:删除该用户消息(含)之后的所有消息
if (currentSessionId && window.metona?.sessions?.truncateAfter) {
try {
await window.metona.sessions.truncateAfter(currentSessionId, messageId, true);
} catch (err) {
console.error('[AgentStore] truncateAfter failed:', err);
import('@metona-team/metona-toast').then((mod) => mod.default.error('消息截断失败,无法重发')).catch(() => {});
return;
}
}
// 本地截断(保留之前的消息,重置运行状态)
set({
messages: messages.slice(0, idx),
agentStatus: 'idle',
isStreaming: false,
currentIteration: 0,
currentRunId: null,
});
// 从原消息附件重建图片参数(附件随消息保留重发)
const images = (original.attachments ?? [])
.filter((a) => a.type === 'image' && a.preview)
.map((a) => ({ url: a.preview as string, detail: 'auto' as const }));
get().sendMessage(
newContent.trim(),
images.length > 0 ? images : undefined,
original.attachments,
);
},
// ===== P2-11: 重新生成 =====
regenerate: async () => {
const { messages, currentSessionId, isStreaming } = get();
if (isStreaming) {
import('@metona-team/metona-toast').then((mod) => mod.default.warning('Agent 正在回复中,无法重新生成')).catch(() => {});
return;
}
// 找最后一条用户消息
const lastUserIdx = messages.length - 1 - [...messages].reverse().findIndex((m) => m.role === 'user');
if (lastUserIdx < 0 || lastUserIdx >= messages.length || messages[lastUserIdx].role !== 'user') {
import('@metona-team/metona-toast').then((mod) => mod.default.info('没有可重新生成的用户消息')).catch(() => {});
return;
}
const lastUser = messages[lastUserIdx];
// DB 截断:删除该用户消息(含)之后的所有消息
if (currentSessionId && window.metona?.sessions?.truncateAfter) {
try {
await window.metona.sessions.truncateAfter(currentSessionId, lastUser.id, true);
} catch (err) {
console.error('[AgentStore] truncateAfter failed:', err);
import('@metona-team/metona-toast').then((mod) => mod.default.error('消息截断失败,无法重新生成')).catch(() => {});
return;
}
}
// 本地截断
set({
messages: messages.slice(0, lastUserIdx),
agentStatus: 'idle',
isStreaming: false,
currentIteration: 0,
currentRunId: null,
});
// 重发原内容(含原附件)
const images = (lastUser.attachments ?? [])
.filter((a) => a.type === 'image' && a.preview)
.map((a) => ({ url: a.preview as string, detail: 'auto' as const }));
get().sendMessage(
lastUser.content,
images.length > 0 ? images : undefined,
lastUser.attachments,
);
},
}));