feat: v0.7.2 安全收口 · 断链接线 · 观测补洞 — 230 用例扩充与全量回归
CI / 类型检查 + Lint + 单元测试 (push) Failing after 5m43s
CI / 全量测试 (Electron ABI) (push) Failing after 5m25s
CI / 产物编译验证 (push) Successful in 10m1s

P1 修复面收口: /clear 全链路根治(前端清空联动 DB messages+摘要游标+TRACE 快照,
IPC 语义改"操作完成"; 流式中拒绝); web_browser open 补 SSRF 校验(Chromium 旁路关闭,
与 web_fetch/http_request 同源 validateSSRF); MCP 工具结果纳入注入扫描(mcp_* 前缀
按网络来源同级 full 模式, 收敛 resolveScanMode 单点); Trace 落库/入 store 双重瘦身
(tool_result base64/超长字段剥离, metadata 防 MB 级膨胀); 文本附件 512KB 闸门
(file.slice 首段读取+truncated 标志随消息持久化+主进程附件提示感知截断);
单实例锁(requestSingleInstanceLock + second-instance 聚焦已有窗口)

P2 安全纵深: ConfirmationHook 多窗口化(确认请求/超时提示改全窗口广播,
getAllWindows 空时回退 mainWindow, fail-closed 判定升级双通道); mcp_servers.headers
全链路接线(safeParseHeaders 容错解析+SSE/StreamableHTTP requestInit 注入+IPC 逐项
校验+设置页 JSON 输入, 远程 MCP 鉴权头可用)

P3 断链接线: llm:listModels IPC(六家 adapter 动态模型发现首次接线, 配置完整性
前置校验); Ollama pullModel IPC+设置页下载卡片(进度/取消/能力徽标, v0.7.0 死代码
激活); 后台会话运行指示(sessionRunStates 图+Sidebar 状态点, 多会话并发可见);
IR 卫生(移除 THINKING_START/END 死枚举, constraints 标注预留)

P4 质量与文档: i18n 第二阶段(确认弹框/侧栏/状态栏/AgentMonitor/终止原因出层,
外观设置 zh-CN/en-US 切换, ui.locale 持久化, 渲染时求值规避异步注册); README/D1
文档对齐(http_request 风险等级/用例数/实现状态注记); 版本号 0.7.2

测试: 507 → 737 用例(+230, 11 个新文件)。覆盖补齐: context-builder/consolidator/
orchestrator/workspace.service/session-recorder/config-layering/secure-config/
network-proxy + IPC mcp/tasks/memory/app/data 域 + 渲染层 store 与流事件管线纯函数。
测试驱动修复: workspace.appendMemory 中文分区 \b 词边界失效(JS \b 不含 CJK),
固化条目恒追加文件末尾产生重复分区头 → (?=\n|$) 前瞻断言根治

回归: typecheck 双端 0 错误; ESLint 0/0; 系统 Node 687 通过 50 跳过;
Electron ABI 全量 737/737 零跳过
This commit is contained in:
2026-08-30 00:09:25 +08:00
parent 36e4b28d93
commit 26169b7be4
55 changed files with 5673 additions and 434 deletions
+50 -24
View File
@@ -116,6 +116,35 @@ export class ConfirmationHook implements PreToolHook {
this.mainWindow = window;
}
/**
* v0.7.2 P2-7 根治: 确认请求/超时通知从"仅 mainWindow"升级为全窗口广播。
*
* 原缺陷:流式事件已走 broadcast() 多窗口分发(P2-10),但确认弹框只发给
* 注册时捕获的 ctx.mainWindow —— 第二窗口里运行的会话触发确认时,弹框
* 只出现在主窗口(甚至随窗口重建指向已销毁实例),多窗口场景确认链路不可达。
*
* 现契约:遍历所有存活窗口广播;getAllWindows 为空或不可用时回退到注入的
* mainWindow(测试环境 / 生命周期早期兜底),行为向后兼容。
*/
private broadcastToAllWindows(channel: string, payload: unknown): void {
const windows = BrowserWindow.getAllWindows().filter((w) => !w.isDestroyed() && w.webContents);
if (windows.length > 0) {
for (const win of windows) {
win.webContents.send(channel, payload);
}
return;
}
if (this.mainWindow && !this.mainWindow.isDestroyed()) {
this.mainWindow.webContents.send(channel, payload);
}
}
/** 当前是否存在任何可接收确认请求的窗口(广播窗口或注入的 mainWindow */
private hasAvailableWindow(): boolean {
if (BrowserWindow.getAllWindows().some((w) => !w.isDestroyed())) return true;
return Boolean(this.mainWindow && !this.mainWindow.isDestroyed());
}
/**
* 从 ConfigService 加载已设置为自动执行的工具列表
* 配置键格式:tools.{toolName}.autoExecute = true
@@ -367,7 +396,8 @@ export class ConfirmationHook implements PreToolHook {
// v0.6.4 P2-1: 增加第三个来源 —— 策略引擎的 requireConfirmationmcp_* 通配
// 策略等)。此前只看工具定义的 requiresPermission / riskLevel,外部 MCP 工具
// 被 adapter 全量标为免审批,策略层的"需确认"从未真正生效。
const policyRequiresConfirmation = this.policyEngine?.requiresConfirmation(toolCall.name) ?? false;
const policyRequiresConfirmation =
this.policyEngine?.requiresConfirmation(toolCall.name) ?? false;
const needsConfirmation =
def.requiresPermission ||
ConfirmationHook.REQUIRES_CONFIRMATION.includes(def.riskLevel) ||
@@ -400,8 +430,8 @@ export class ConfirmationHook implements PreToolHook {
}
}
// 如果没有主窗口,安全起见阻止执行
if (!this.mainWindow || this.mainWindow.isDestroyed()) {
// 如果没有任何可用窗口(全窗口广播 + mainWindow 双通道皆不可达),安全起见阻止执行
if (!this.hasAvailableWindow()) {
return { blocked: true, reason: 'Cannot request confirmation: no main window available' };
}
@@ -458,21 +488,17 @@ export class ConfirmationHook implements PreToolHook {
if (settled) return; // 已被 resolveConfirmation 处理,跳过超时副作用
this.pendingConfirmations.delete(request.toolCallId);
// 超时发送 toast 通知用户(3 秒节流,防止并行工具风暴)
if (this.mainWindow && !this.mainWindow.isDestroyed()) {
const now = Date.now();
if (now - this.lastTimeoutToastAt > 3000) {
this.lastTimeoutToastAt = now;
// 统计当前还有多少 pending(含本次刚超时的)
const pendingCount = this.pendingConfirmations.size + 1;
const message =
pendingCount > 1
? `工具确认超时(${Math.round(this.confirmationTimeoutMs / 1000)}秒),${pendingCount} 个工具未执行`
: `工具确认超时(${Math.round(this.confirmationTimeoutMs / 1000)}秒),"${request.toolName}" 未执行`;
this.mainWindow.webContents.send('toast:show', {
type: 'warning',
message,
});
}
// v0.7.2 P2-7: 超时提示同样广播到所有窗口(与确认请求同通道语义)
const now = Date.now();
if (now - this.lastTimeoutToastAt > 3000) {
this.lastTimeoutToastAt = now;
// 统计当前还有多少 pending(含本次刚超时的)
const pendingCount = this.pendingConfirmations.size + 1;
const message =
pendingCount > 1
? `工具确认超时(${Math.round(this.confirmationTimeoutMs / 1000)}秒),${pendingCount} 个工具未执行`
: `工具确认超时(${Math.round(this.confirmationTimeoutMs / 1000)}秒),"${request.toolName}" 未执行`;
this.broadcastToAllWindows('toast:show', { type: 'warning', message });
}
safeResolve(false); // 超时视为拒绝
}, this.confirmationTimeoutMs);
@@ -490,12 +516,12 @@ export class ConfirmationHook implements PreToolHook {
});
// 发送确认请求到渲染进程(携带过期时间戳,供前端倒计时)
if (this.mainWindow && !this.mainWindow.isDestroyed()) {
this.mainWindow.webContents.send('tool:confirmationRequest', {
...request,
expiresAt,
});
}
// v0.7.2 P2-7: 广播到所有窗口 —— 多窗口场景下任意窗口发起的会话
// 触发的确认请求都可达(ConfirmationDialog 按会话过滤展示)
this.broadcastToAllWindows('tool:confirmationRequest', {
...request,
expiresAt,
});
});
}