新增: AE-2025-04会话级授权(TrustKey目录级+同会话同类自动放行)

This commit is contained in:
2026-06-17 01:29:30 +08:00
parent 0202b5195e
commit 6ec191e750
9 changed files with 218 additions and 1 deletions

View File

@@ -246,6 +246,10 @@ export type AiChatEvent = ({
type: 'AiToolCallStarted'; id: string; name: string; args: unknown
} | {
type: 'AiToolCallCompleted'; id: string; result: unknown
} | {
// AE-2025-04 会话级信任:同会话已批准过同类操作(同工具+同目录)自动放行,前端显示轻量 toast。
// 不写消息/不动 pending(Started/Completed 仍独立发),仅提示性事件。
type: 'AiToolAutoApproved'; id: string; tool: string; dir: string
} | {
type: 'AiApprovalRequired'; id: string; name: string; args: unknown; reason: string; diff?: string
} | {

View File

@@ -936,6 +936,8 @@ function showToast(msg: string, type: 'error' | 'warning' | 'info' = 'info') {
// B-260616-12: 工具慢执行提示事件 unlistener(onMounted 注册,onBeforeUnmount 释放)
let _unlistenToolSlow: (() => void) | null = null
// AE-2025-04: 会话信任自动放行 toast unlistener(useAiEvents 经事件总线中转,同 _unlistenToolSlow 模式)
let _unlistenAutoApproved: (() => void) | null = null
const inputText = ref('')
const inputEl = ref<HTMLTextAreaElement>()
@@ -1813,6 +1815,7 @@ onBeforeUnmount(() => {
// F-15 阶段2: 释放上下文管理事件监听器
store.stopContextListener()
if (_unlistenToolSlow) { _unlistenToolSlow(); _unlistenToolSlow = null } // B-260616-12
if (_unlistenAutoApproved) { _unlistenAutoApproved(); _unlistenAutoApproved = null } // AE-2025-04
if (_toastTimer) { clearTimeout(_toastTimer); _toastTimer = null }
// UX-2025-20:释放标题淡入计时器
if (_titleFlashTimer) { clearTimeout(_titleFlashTimer); _titleFlashTimer = null }
@@ -1901,6 +1904,10 @@ onMounted(async () => {
_unlistenToolSlow = await listen<{ name: string }>('ai-tool-slow-toast', (e) => {
showToast(t('aiTool.executionSlow', { name: e.payload.name }), 'warning')
})
// AE-2025-04: 会话信任自动放行 toast(轻量 info,非审批气泡,避免干扰主流程)
_unlistenAutoApproved = await listen<{ tool: string; dir: string }>('ai-tool-auto-approved-toast', (e) => {
showToast(t('aiChat.autoApprovedToast', { tool: e.payload.tool, dir: e.payload.dir }), 'info')
})
// F-15 阶段2: 注册上下文管理事件监听器(清空/压缩生命周期事件 → toast/刷新)
await initContextEventListeners()
// 分离模式:接管主窗口当前对话(含生成中态),保持正在进行的对话

View File

@@ -227,6 +227,14 @@ export function handleEvent(event: AiChatEvent) {
break
}
case 'AiToolAutoApproved': {
// AE-2025-04 会话级信任:不写消息/不动 pending(Started/Completed 仍独立发),
// 仅经事件总线桥接到 AiChat.vue 弹本地 toast(composable 无组件上下文,与
// ai-tool-slow-toast 同款中转模式)。主窗口与分离窗口各挂一份 AiChat,各自消费。
void emit('ai-tool-auto-approved-toast', { tool: event.tool, dir: event.dir })
break
}
case 'AiApprovalRequired': {
clearStreamWatchdog() // 等用户审批,不计超时
const info: AiToolCallInfo = {

View File

@@ -160,5 +160,9 @@ export default {
collapse: 'Collapse',
// Compressed summary block label (before the system summary message when expanded)
compressedSummaryLabel: 'Context summary',
// ── AE-2025-04 Session Trust ──
// Auto-approval toast (same-session already approved same-kind op: same tool + same dir)
autoApprovedToast: 'Auto-approved: {tool}({dir})',
},
}

View File

@@ -160,5 +160,9 @@ export default {
collapse: '收起',
// 压缩摘要块标题(展开后 system 摘要消息前的标签)
compressedSummaryLabel: '上下文摘要',
// ── AE-2025-04 会话级信任(Session Trust) ──
// 自动放行 toast(同会话已批准过同类操作:同工具+同目录,轻量 info 非审批气泡)
autoApprovedToast: '已自动放行: {tool}({dir})',
},
}