fix: v0.5.1 工具调用链路复检修复 — SubAgent 孤儿工具拦截 + 确认弹框会话隔离
背景:v0.5.0 发布后对工具调用链路(adapter 流式 tool_call → 引擎 PARSING → preToolHooks 管道 → ToolRegistry → 结果回填)做全链路复检,发现并修复两处问题。 安全修复: - SubAgent 中止时 pending 确认未清理(安全回归):SubEngine 以 taskId 为 sessionId 写入 ConfirmationHook,abortSession 的 clearPending(sessionId) 清不到它们。后果:中止会话后残留弹框若被补批,孤儿工具会真实执行副作用 (v0.4.x 的全局清空反而能拦截)。修复:abortByParent 返回被中止的 taskId 列表,abortSession 一并 clearPending(taskId)。 确认弹框会话隔离(前端对齐后端 v0.5.0 语义): - ConfirmationRequest 新增 sessionId 字段(主会话为 sessionId,SubAgent 为 taskId),弹框在会话 INIT/TERMINATED 时只清除该会话的请求 —— 修复并发 会话下任意会话结束误清其他会话等待中确认的问题 - 选中计数按当前 requests 收敛(selectedIds 残留 id 无害化) 测试(207 → 215 用例): - 新增引擎级工具调用链路集成测试 ×6(engine-toolchain.test.ts):真实 PermissionCheckHook + RateLimitHook + ConfirmationHook 管道 + 真实 ToolRegistry,覆盖 SAFE 工具直通 / HIGH 工具批准执行 / 拒绝以 Blocked 错误回传 LLM / 会话隔离端到端 / 工具异常不中断循环 / 策略拦截系统路径 - 新增 FTS 触发器 × NULL content 删除安全性测试 ×2:验证 truncateAfter (编辑重发/重新生成)删除 content=NULL 的 assistant 消息(模型仅发 tool_calls 的标准场景)不抛错且索引保持一致 - agent.test.ts 的 orchestrator mock 适配 abortByParent 新返回类型 验证: lint 0 problems / typecheck 双工程 0 errors / test:electron 215 全过 / build 成功
This commit is contained in:
@@ -22,6 +22,13 @@ export interface ConfirmationRequest {
|
||||
args: Record<string, unknown>;
|
||||
riskLevel: string;
|
||||
reason: string;
|
||||
/**
|
||||
* 发起确认的会话 ID(v0.5.1 新增)
|
||||
* 主会话为 sessionId;SubAgent 委派的工具确认为 taskId。
|
||||
* 前端确认弹框据此在会话 TERMINATED 时只清除该会话的请求,
|
||||
* 避免并发会话场景下误清其他会话等待中的确认。
|
||||
*/
|
||||
sessionId?: string;
|
||||
/**
|
||||
* 过期时间戳(ms),由 waitForConfirmation 注入,用于前端倒计时 UI。
|
||||
* 注意:beforeExecute 构造 request 时不带此字段,仅在 waitForConfirmation 中追加。
|
||||
@@ -276,6 +283,7 @@ export class ConfirmationHook implements PreToolHook {
|
||||
args: pending.args ?? {},
|
||||
riskLevel: pending.riskLevel ?? 'medium',
|
||||
reason: pending.reason ?? `Tool "${pending.toolName}" requires confirmation`,
|
||||
sessionId: pending.sessionId,
|
||||
expiresAt: pending.expiresAt,
|
||||
});
|
||||
}
|
||||
@@ -385,6 +393,7 @@ export class ConfirmationHook implements PreToolHook {
|
||||
reason: def.requiresPermission
|
||||
? `Tool "${toolCall.name}" requires permission (risk: ${def.riskLevel})`
|
||||
: `Tool "${toolCall.name}" has high risk level: ${def.riskLevel}`,
|
||||
sessionId,
|
||||
};
|
||||
|
||||
// 等待用户响应(带超时)
|
||||
|
||||
Reference in New Issue
Block a user