Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

feat(desktop): 插件 confirm 槽——请主机弹同款确认框并拿回真实点击

Lizieadbe32955ae
diff --git a/apps/desktop/src/main/cindy-brain/__tests__/confirmSlot.test.ts b/apps/desktop/src/main/cindy-brain/__tests__/confirmSlot.test.ts
new file mode 100644
index 0000000000..fd6bb551c4
--- /dev/null
+++ b/apps/desktop/src/main/cindy-brain/__tests__/confirmSlot.test.ts
@@ -0,0 +1,219 @@
+/** confirmSlot.test — 确认弹窗槽(confirm)的假 deps 单测。 */
+
+import { describe, expect, it, vi } from 'vitest';
+
+import {
+ GHOST_CONFIRM_BODY_MAX_CHARS,
+ GHOST_CONFIRM_BUTTON_MAX_CHARS,
+ type InstalledGhost,
+} from '../../../shared/ghost';
+import {
+ GhostConfirmSlot,
+ type ConfirmSlotDeps,
+ type GhostConfirmShowParams,
+} from '../confirmSlot';
+
+function confirmGhost(options: { slots?: string[]; enabled?: boolean; icon?: string } = {}): InstalledGhost {
+ return {
+ manifest: {
+ schemaVersion: 2,
+ id: 'confirm-ghost',
+ name: '确认插件',
+ version: '1.0.0',
+ kind: 'chip',
+ entry: 'main.js',
+ slots: options.slots ?? ['confirm'],
+ },
+ dir: '/fake/confirm-ghost',
+ enabled: options.enabled ?? true,
+ ...(options.icon ? { iconDataUrl: options.icon } : {}),
+ } as InstalledGhost;
+}
+
+/** 假弹窗:参数带类型,好让用例直接断言主机递过去的那份载荷。 */
+function showConfirmMock(answer = true) {
+ return vi.fn(async (_params: GhostConfirmShowParams) => answer);
+}
+
+function makeSlot(overrides: Partial<ConfirmSlotDeps> = {}) {
+ // 缺省时钟每次前进 60s,免得正常用例撞上 3 秒限速
+ let clock = 0;
+ const showConfirm = (overrides.showConfirm ?? showConfirmMock()) as ReturnType<typeof showConfirmMock>;
+ const deps: ConfirmSlotDeps = {
+ getGhost: () => confirmGhost(),
+ now: () => (clock += 60_000),
+ ...overrides,
+ showConfirm,
+ };
+ return { slot: new GhostConfirmSlot(deps), deps, showConfirm };
+}
+
+/** mock.calls[0][0] 的类型安全取法(断言前先确认真被调过)。 */
+function firstShown(mock: ReturnType<typeof showConfirmMock>): GhostConfirmShowParams {
+ const call = mock.mock.calls[0];
+ expect(call).toBeDefined();
+ return call![0];
+}
+
+const OK_BODY = { body: '把项目目录切到 fix/xxx 分支?' };
+
+describe('confirmSlot · 资格审与载荷校验', () => {
+ it('未声明 confirm 槽 / 未启用 一律 PERMISSION_DENIED', async () => {
+ const noSlot = makeSlot({ getGhost: () => confirmGhost({ slots: ['tool'] }) });
+ expect(await noSlot.slot.handleRequest('confirm-ghost', OK_BODY)).toMatchObject({
+ ok: false,
+ errorCode: 'PERMISSION_DENIED',
+ });
+ const disabled = makeSlot({ getGhost: () => confirmGhost({ enabled: false }) });
+ expect(await disabled.slot.handleRequest('confirm-ghost', OK_BODY)).toMatchObject({
+ ok: false,
+ errorCode: 'PERMISSION_DENIED',
+ });
+ const missing = makeSlot({ getGhost: () => null });
+ expect(await missing.slot.handleRequest('confirm-ghost', OK_BODY)).toMatchObject({
+ ok: false,
+ errorCode: 'PERMISSION_DENIED',
+ });
+ // 一次都不该弹
+ expect(noSlot.showConfirm).not.toHaveBeenCalled();
+ expect(disabled.showConfirm).not.toHaveBeenCalled();
+ });
+
+ it('载荷不是对象 / body 缺失或空 一律 INVALID_REQUEST,且不弹框', async () => {
+ const { slot, showConfirm } = makeSlot();
+ for (const payload of [null, 'x', [], {}, { body: 42 }, { body: ' ' }]) {
+ expect(await slot.handleRequest('confirm-ghost', payload)).toMatchObject({
+ ok: false,
+ errorCode: 'INVALID_REQUEST',
+ });
+ }
+ expect(showConfirm).not.toHaveBeenCalled();
+ });
+
+ it('body 超限拒单;控制字符先剥再量长度(不许注水绕过上限)', async () => {
+ const { slot } = makeSlot();
+ expect(
+ await slot.handleRequest('confirm-ghost', { body: 'x'.repeat(GHOST_CONFIRM_BODY_MAX_CHARS + 1) }),
+ ).toMatchObject({ ok: false, errorCode: 'INVALID_REQUEST' });
+
+ // 满长度正文 + 一堆控制字符:剥完刚好合规,应放行
+ const fresh = makeSlot();
+ const padded = `${'y'.repeat(GHOST_CONFIRM_BODY_MAX_CHARS)}${''.repeat(50)}`;
+ expect(await fresh.slot.handleRequest('confirm-ghost', { body: padded })).toEqual({
+ ok: true,
+ confirmed: true,
+ });
+ expect(firstShown(fresh.showConfirm).body).toBe('y'.repeat(GHOST_CONFIRM_BODY_MAX_CHARS));
+ });
+
+ it('按钮文案超限拒单;空串当没给(回 null 让主机用缺省文案)', async () => {
+ const { slot } = makeSlot();
+ expect(
+ await slot.handleRequest('confirm-ghost', {
+ ...OK_BODY,
+ confirmText: 'x'.repeat(GHOST_CONFIRM_BUTTON_MAX_CHARS + 1),
+ }),
+ ).toMatchObject({ ok: false, errorCode: 'INVALID_REQUEST' });
+
+ const fresh = makeSlot();
+ expect(
+ await fresh.slot.handleRequest('confirm-ghost', { ...OK_BODY, confirmText: ' ', cancelText: 42 }),
+ ).toMatchObject({ ok: false, errorCode: 'INVALID_REQUEST' }); // cancelText 类型不对
+ const ok = makeSlot();
+ await ok.slot.handleRequest('confirm-ghost', { ...OK_BODY, confirmText: ' ' });
+ expect(firstShown(ok.showConfirm).confirmText).toBeNull();
+ });
+
+ it('danger 必须是布尔;身份三件套取自已装清单而不是载荷自报', async () => {
+ const { slot } = makeSlot();
+ expect(await slot.handleRequest('confirm-ghost', { ...OK_BODY, danger: 'yes' })).toMatchObject({
+ ok: false,
+ errorCode: 'INVALID_REQUEST',
+ });
+
+ const withIcon = makeSlot({ getGhost: () => confirmGhost({ icon: 'data:image/png;base64,AAA' }) });
+ await withIcon.slot.handleRequest('confirm-ghost', {
+ ...OK_BODY,
+ // 插件试图自报身份:这些字段必须被无视
+ ghostName: '系统',
+ iconDataUrl: 'data:image/png;base64,EVIL',
+ title: '主机安全提示',
+ });
+ const shown = firstShown(withIcon.showConfirm);
+ expect(shown.ghostName).toBe('确认插件');
+ expect(shown.iconDataUrl).toBe('data:image/png;base64,AAA');
+ expect(shown).not.toHaveProperty('title');
+ });
+});
+
+describe('confirmSlot · 答案与失败分档', () => {
+ it('ok:true 只代表问到了:确认与取消分别回 confirmed true/false', async () => {
+ const yes = makeSlot({ showConfirm: vi.fn(async () => true) });
+ expect(await yes.slot.handleRequest('confirm-ghost', OK_BODY)).toEqual({ ok: true, confirmed: true });
+ const no = makeSlot({ showConfirm: vi.fn(async () => false) });
+ expect(await no.slot.handleRequest('confirm-ghost', OK_BODY)).toEqual({ ok: true, confirmed: false });
+ });
+
+ it('弹不出来(没有可挂靠窗口)回 UNAVAILABLE —— 不谎报成用户拒绝', async () => {
+ const { slot } = makeSlot({
+ showConfirm: vi.fn(async () => {
+ throw new Error('没有可挂靠的宿主窗口');
+ }),
+ });
+ expect(await slot.handleRequest('confirm-ghost', OK_BODY)).toMatchObject({
+ ok: false,
+ errorCode: 'UNAVAILABLE',
+ });
+ });
+});
+
+describe('confirmSlot · 骚扰钳制', () => {
+ it('同插件 3 秒内第二次回 RATE_LIMITED,且按尝试记账(刷请求顺延窗口)', async () => {
+ let clock = 1_000_000;
+ const { slot, showConfirm } = makeSlot({ now: () => clock });
+ expect(await slot.handleRequest('confirm-ghost', OK_BODY)).toEqual({ ok: true, confirmed: true });
+
+ clock += 1000; // 1 秒后再问
+ expect(await slot.handleRequest('confirm-ghost', OK_BODY)).toMatchObject({
+ ok: false,
+ errorCode: 'RATE_LIMITED',
+ });
+ // 被拒的这次也记了账:再过 2.5 秒(距首次 3.5 秒但距上次尝试只 2.5 秒)仍然拒
+ clock += 2500;
+ expect(await slot.handleRequest('confirm-ghost', OK_BODY)).toMatchObject({
+ ok: false,
+ errorCode: 'RATE_LIMITED',
+ });
+ clock += 3001;
+ expect(await slot.handleRequest('confirm-ghost', OK_BODY)).toEqual({ ok: true, confirmed: true });
+ expect(showConfirm).toHaveBeenCalledTimes(2);
+ });
+
+ it('已有确认框在场时回 BUSY(不排队)', async () => {
+ let release: (v: boolean) => void = () => {};
+ const { slot, showConfirm } = makeSlot({
+ showConfirm: vi.fn(() => new Promise<boolean>((resolve) => (release = resolve))),
+ });
+ const first = slot.handleRequest('confirm-ghost', OK_BODY);
+ // 第一单还挂着(用户没点),第二单直接 BUSY
+ expect(await slot.handleRequest('confirm-ghost', OK_BODY)).toMatchObject({
+ ok: false,
+ errorCode: 'BUSY',
+ });
+ release(true);
+ expect(await first).toEqual({ ok: true, confirmed: true });
+ expect(showConfirm).toHaveBeenCalledTimes(1);
+ });
+
+ it('在场标记会释放:上一单结束后还能再问(异常路径也释放)', async () => {
+ let clock = 0;
+ const showConfirm = showConfirmMock();
+ showConfirm.mockRejectedValueOnce(new Error('boom')).mockResolvedValueOnce(true);
+ const { slot } = makeSlot({ showConfirm, now: () => (clock += 60_000) });
+ expect(await slot.handleRequest('confirm-ghost', OK_BODY)).toMatchObject({
+ ok: false,
+ errorCode: 'UNAVAILABLE',
+ });
+ expect(await slot.handleRequest('confirm-ghost', OK_BODY)).toEqual({ ok: true, confirmed: true });
+ });
+});
diff --git a/apps/desktop/src/main/cindy-brain/__tests__/forge.test.ts b/apps/desktop/src/main/cindy-brain/__tests__/forge.test.ts
index 8dbf740c5c..b1e4e1b5f6 100644
--- a/apps/desktop/src/main/cindy-brain/__tests__/forge.test.ts
+++ b/apps/desktop/src/main/cindy-brain/__tests__/forge.test.ts
@@ -564,6 +564,12 @@ describe('FORGE_GUIDE', () => {
'设计小结',
'源码会放在工作目录的哪个文件夹',
'让用户知情即可',
+ // 2026-07-31 确认弹窗(confirm 槽):主机同款确认框 + 真实点击回执;
+ // §2 卡槽清单、§4.9 的"不是确认框"指向、§4.18 章节三处同步。
+ '确认弹窗(confirm 槽)',
+ 'cindy.confirm',
+ '只代表问到了,答案看',
+ '全局同时只有一个确认框',
]) {
expect(FORGE_GUIDE).toContain(marker);
}
diff --git a/apps/desktop/src/main/cindy-brain/__tests__/ghostConfirmDialogBridge.test.ts b/apps/desktop/src/main/cindy-brain/__tests__/ghostConfirmDialogBridge.test.ts
new file mode 100644
index 0000000000..87148db4ee
--- /dev/null
+++ b/apps/desktop/src/main/cindy-brain/__tests__/ghostConfirmDialogBridge.test.ts
@@ -0,0 +1,103 @@
+/** ghostConfirmDialogBridge.test — confirm 槽 main↔renderer 往返桥的单测。 */
+
+import { describe, expect, it, vi } from 'vitest';
+
+import {
+ GhostConfirmDialogBridge,
+ type GhostConfirmPush,
+ type GhostConfirmDialogBridgeDeps,
+} from '../ghostConfirmDialogBridge';
+
+const ASK = {
+ ghostId: 'g1',
+ ghostName: '确认插件',
+ body: '要切分支吗?',
+ confirmText: null,
+ cancelText: null,
+ danger: false,
+};
+
+function makeBridge(overrides: Partial<GhostConfirmDialogBridgeDeps> = {}) {
+ const sent: GhostConfirmPush[] = [];
+ const deps: GhostConfirmDialogBridgeDeps = {
+ sendToWindow: (payload) => {
+ sent.push(payload);
+ return true;
+ },
+ timeoutMs: 50,
+ ...overrides,
+ };
+ return { bridge: new GhostConfirmDialogBridge(deps), sent };
+}
+
+describe('ghostConfirmDialogBridge · 正常往返', () => {
+ it('投出去 → renderer 回包 → resolve 用户的点击', async () => {
+ const { bridge, sent } = makeBridge();
+ const pending = bridge.request(ASK);
+ expect(sent).toHaveLength(1);
+ expect(sent[0].requestId).toMatch(/[0-9a-f-]{36}/);
+ expect(sent[0].body).toBe('要切分支吗?');
+ expect(bridge.pendingCount).toBe(1);
+
+ expect(bridge.resolve(sent[0].requestId, true)).toBe(true);
+ expect(await pending).toBe(true);
+ expect(bridge.pendingCount).toBe(0);
+ });
+
+ it('取消回包 → false', async () => {
+ const { bridge, sent } = makeBridge();
+ const pending = bridge.request(ASK);
+ bridge.resolve(sent[0].requestId, false);
+ expect(await pending).toBe(false);
+ });
+});
+
+describe('ghostConfirmDialogBridge · fail closed', () => {
+ it('没有可投窗口 → reject(区别于"用户拒绝")', async () => {
+ const { bridge } = makeBridge({ sendToWindow: () => false });
+ await expect(bridge.request(ASK)).rejects.toThrow('没有可挂靠的宿主窗口');
+ expect(bridge.pendingCount).toBe(0);
+ });
+
+ it('没人应答到超时 → 当成没同意(false),并清掉 pending', async () => {
+ const warn = vi.fn();
+ const { bridge } = makeBridge({ timeoutMs: 10, log: { warn } });
+ expect(await bridge.request(ASK)).toBe(false);
+ expect(bridge.pendingCount).toBe(0);
+ expect(warn).toHaveBeenCalled();
+ });
+
+ it('回包不是布尔 → 一律按没同意兜底(不给靠畸形回包骗到同意的路)', async () => {
+ const warn = vi.fn();
+ const { bridge, sent } = makeBridge({ log: { warn } });
+ const pending = bridge.request(ASK);
+ bridge.resolve(sent[0].requestId, 'true');
+ expect(await pending).toBe(false);
+ expect(warn).toHaveBeenCalled();
+ });
+
+ it('陌生 / 重复的 requestId 直接忽略(返回 false,不抛)', async () => {
+ const { bridge, sent } = makeBridge();
+ expect(bridge.resolve('not-a-real-id', true)).toBe(false);
+ const pending = bridge.request(ASK);
+ expect(bridge.resolve(sent[0].requestId, true)).toBe(true);
+ expect(bridge.resolve(sent[0].requestId, false)).toBe(false); // 二次回包无效
+ expect(await pending).toBe(true);
+ });
+
+ it('cancelAll 清在途:全清 / 只清某个插件', async () => {
+ const { bridge } = makeBridge({ timeoutMs: 60_000 });
+ const a = bridge.request(ASK);
+ // 第一单还在场时桥本身不拦(单飞在 confirmSlot),这里直接再投一单验证按 ghostId 清
+ const b = bridge.request({ ...ASK, ghostId: 'g2' });
+ expect(bridge.pendingCount).toBe(2);
+
+ bridge.cancelAll('g1');
+ expect(await a).toBe(false);
+ expect(bridge.pendingCount).toBe(1);
+
+ bridge.cancelAll();
+ expect(await b).toBe(false);
+ expect(bridge.pendingCount).toBe(0);
+ });
+});
diff --git a/apps/desktop/src/main/cindy-brain/confirmSlot.ts b/apps/desktop/src/main/cindy-brain/confirmSlot.ts
new file mode 100644
index 0000000000..689ca338f4
--- /dev/null
+++ b/apps/desktop/src/main/cindy-brain/confirmSlot.ts
@@ -0,0 +1,178 @@
+/**
+ * confirmSlot.ts — 确认弹窗槽(confirm,2026-07-31)。
+ * ---------------------------------------------------------------------------
+ * 插件经管子上行 `{type:'confirm-request', body, confirmText?, cancelText?, danger?}`,
+ * 请主机弹**主机同款**的二选一确认框(renderer 的 ConfirmDialogProvider),拿回
+ * 用户的真实点击。
+ *
+ * 为什么单独开一个槽:notify 槽是「说一句就走」(无按钮、无回执),插件要
+ * 「动手前问一句」时只能自己在面板里画一个,每个插件画一套、长得都不一样,
+ * 而且面板外的场景(工具调用链里)根本没法问。本槽把基座自己在用的通用弹窗
+ * 接口开放出来,形态与基座一致。
+ *
+ * 安全模型(与 pick 槽同一套哲学:决定权在用户的点击上):
+ *
+ * - 资格审:已装、启用、声明 confirm 槽;
+ * - 主机拥有壳:标题是主机文案(带插件名)、身份头(图标+名字)由 renderer 从
+ * 已装清单取——**不用载荷里的自报字段**。插件只供 body 与按钮字,全部过
+ * sanitizeGhostNoticeText 净化并卡长度上限;伪装不了主机文案、冒充不了别的
+ * 插件,也点不了自己的按钮(点击链路主机独占);
+ * - 骚扰钳制:同插件两次最小间隔 GHOST_CONFIRM_MIN_INTERVAL_MS(按尝试记账,
+ * spam 顺延窗口),**全局**同时只允许一个确认框在场(BUSY)——排队就是骚扰
+ * 队列,模态框比 toast 更不能排;
+ * - fail closed:超时、无可挂靠窗口、桥未就绪、载荷非法一律当「没同意」,
+ * 绝不把「问不出来」错当成「用户同意了」;
+ * - 不开放「下次不再提示」:那等于插件点一次换来永久免问,直接废掉确认的意义。
+ * 三状态(confirmThree)与业务复选框同理,v1 都不开。
+ *
+ * 处理结果永不 reject——一切失败折叠成结构化 { ok:false, errorCode, message }
+ * (与 pick / cindy 槽同纪律,沙箱拿到的是拒绝而不是异常穿透)。
+ * 纯逻辑 + 依赖注入(规则 14):弹窗投递由 cindy-brain/index.ts 组装时注入,
+ * 单测喂假 deps 直测。
+ */
+
+import {
+ GHOST_CONFIRM_BODY_MAX_CHARS,
+ GHOST_CONFIRM_BUTTON_MAX_CHARS,
+ GHOST_CONFIRM_MIN_INTERVAL_MS,
+ type GhostPipeConfirmResult,
+ type InstalledGhost,
+} from '../../shared/ghost.js';
+import { sanitizeGhostNoticeText } from './notifySlot.js';
+
+/** 交给桥去弹的一单(身份三件套由主机按已装清单填,不信插件自报)。 */
+export interface GhostConfirmShowParams {
+ ghostId: string;
+ /** 插件展示名(主机拼标题用)。 */
+ ghostName: string;
+ /** 插件图标 data URL(身份头;未声明图标时缺省)。 */
+ iconDataUrl?: string;
+ /** 净化后的问句正文。 */
+ body: string;
+ /** 净化后的主按钮文案;null = 用主机缺省文案。 */
+ confirmText: string | null;
+ /** 净化后的次按钮文案;null = 用主机缺省文案。 */
+ cancelText: string | null;
+ danger: boolean;
+}
+
+export interface ConfirmSlotDeps {
+ getGhost(id: string): InstalledGhost | null;
+ /**
+ * 弹确认框并等用户点击:true = 点了主按钮;false = 取消 / Esc / 点外部 / 超时。
+ * 通道不可用(没有可挂靠的 Cindy 窗口、桥还没装配)时应 reject —— 槽据此回
+ * UNAVAILABLE,而不是谎报成「用户拒绝」。
+ */
+ showConfirm(params: GhostConfirmShowParams): Promise<boolean>;
+ now?(): number;
+ log?: {
+ info: (msg: string, meta?: Record<string, unknown>) => void;
+ warn: (msg: string, meta?: Record<string, unknown>) => void;
+ };
+}
+
+function fail(
+ errorCode: Extract<GhostPipeConfirmResult, { ok: false }>['errorCode'],
+ message: string,
+): GhostPipeConfirmResult {
+ return { ok: false, errorCode, message };
+}
+
+/**
+ * 按钮文案净化:空串/纯空白当「没给」(回 null → 用主机缺省文案),超长直接拒单
+ * ——按钮被塞长文会挤坏弹窗版式,静默截断会让作者以为自己写的话完整显示了。
+ */
+function normalizeButtonText(raw: unknown): { ok: true; value: string | null } | { ok: false } {
+ if (raw === undefined) return { ok: true, value: null };
+ if (typeof raw !== 'string') return { ok: false };
+ const text = sanitizeGhostNoticeText(raw);
+ if (!text) return { ok: true, value: null };
+ if (text.length > GHOST_CONFIRM_BUTTON_MAX_CHARS) return { ok: false };
+ return { ok: true, value: text };
+}
+
+/** 确认弹窗槽:资格审 → 校验/净化 → 限速/单飞 → 弹窗 → 回答案。 */
+export class GhostConfirmSlot {
+ /** 插件 id → 上次尝试时刻(按尝试记账;体量 = 已装插件数,无需清理)。 */
+ private readonly lastAttemptAt = new Map<string, number>();
+ /** 全局在场标记(模态框一次一个,不排队——排队就是骚扰队列)。 */
+ private dialogInFlight = false;
+
+ constructor(private readonly deps: ConfirmSlotDeps) {}
+
+ async handleRequest(ghostId: string, payload: unknown): Promise<GhostPipeConfirmResult> {
+ const ghost = this.deps.getGhost(ghostId);
+ if (!ghost?.enabled || !ghost.manifest.slots.includes('confirm')) {
+ return fail('PERMISSION_DENIED', '插件未申请确认弹窗权限(confirm 槽),或当前未启用');
+ }
+ if (!payload || typeof payload !== 'object' || Array.isArray(payload)) {
+ return fail('INVALID_REQUEST', 'confirm-request 载荷必须是对象');
+ }
+ const request = payload as Record<string, unknown>;
+
+ if (typeof request.body !== 'string') {
+ return fail('INVALID_REQUEST', 'body 必须是字符串(要问用户的话)');
+ }
+ // 先净化再验空与超限(防用控制字符注水绕过上限)。
+ const body = sanitizeGhostNoticeText(request.body);
+ if (!body) {
+ return fail('INVALID_REQUEST', 'body 不能为空——没写要问什么,弹出来用户也不知道在同意啥');
+ }
+ if (body.length > GHOST_CONFIRM_BODY_MAX_CHARS) {
+ return fail('INVALID_REQUEST', `body 过长(上限 ${GHOST_CONFIRM_BODY_MAX_CHARS} 字符)`);
+ }
+ if (request.danger !== undefined && typeof request.danger !== 'boolean') {
+ return fail('INVALID_REQUEST', 'danger 必须是布尔值');
+ }
+ const confirmText = normalizeButtonText(request.confirmText);
+ if (!confirmText.ok) {
+ return fail(
+ 'INVALID_REQUEST',
+ `confirmText 必须是字符串且不超过 ${GHOST_CONFIRM_BUTTON_MAX_CHARS} 字符`,
+ );
+ }
+ const cancelText = normalizeButtonText(request.cancelText);
+ if (!cancelText.ok) {
+ return fail(
+ 'INVALID_REQUEST',
+ `cancelText 必须是字符串且不超过 ${GHOST_CONFIRM_BUTTON_MAX_CHARS} 字符`,
+ );
+ }
+
+ // 骚扰钳制:限速按尝试记账(spam 顺延窗口),再看全局在场标记。
+ const now = this.deps.now?.() ?? Date.now();
+ const last = this.lastAttemptAt.get(ghostId);
+ this.lastAttemptAt.set(ghostId, now);
+ if (last !== undefined && now - last < GHOST_CONFIRM_MIN_INTERVAL_MS) {
+ return fail('RATE_LIMITED', '确认请求太频繁,稍后再试');
+ }
+ if (this.dialogInFlight) {
+ return fail('BUSY', '已有一个确认框在等用户操作');
+ }
+
+ this.dialogInFlight = true;
+ let confirmed: boolean;
+ try {
+ confirmed = await this.deps.showConfirm({
+ ghostId,
+ ghostName: ghost.manifest.name,
+ ...(ghost.iconDataUrl ? { iconDataUrl: ghost.iconDataUrl } : {}),
+ body,
+ confirmText: confirmText.value,
+ cancelText: cancelText.value,
+ danger: request.danger === true,
+ });
+ } catch (error) {
+ this.deps.log?.warn('ghost confirm dialog failed', {
+ ghostId,
+ err: error instanceof Error ? error.message : String(error),
+ });
+ return fail('UNAVAILABLE', '确认框打不开(没有可挂靠的窗口)');
+ } finally {
+ this.dialogInFlight = false;
+ }
+
+ this.deps.log?.info('ghost confirm answered', { ghostId, confirmed });
+ return { ok: true, confirmed };
+ }
+}
diff --git a/apps/desktop/src/main/cindy-brain/forge.ts b/apps/desktop/src/main/cindy-brain/forge.ts
index 249644bddb..8d064668d4 100644
--- a/apps/desktop/src/main/cindy-brain/forge.ts
+++ b/apps/desktop/src/main/cindy-brain/forge.ts
@@ -737,7 +737,8 @@ ghost_forge_pack 打包 → 用户在弹窗上确认装入。**
显式点名(推荐,§2)。
- **启动模式**:on-demand 按需拉起(缺省,推荐)/ resident 常驻(仅订阅型、要秒响应
的场景,§2)。
-- **后台能力**:要不要旁听事件(subscribe 槽,§4.6)、发系统提示(notify 槽,§4.9)。
+- **后台能力**:要不要旁听事件(subscribe 槽,§4.6)、发系统提示(notify 槽,§4.9)、
+ 动手前弹确认框征求同意(confirm 槽,§4.18)。
- **联网与凭证**:要不要 network 槽白名单联网(§4.7);要用户填 key 就需要 setup
就绪声明与 settingsHtml 设置区(§4.7、§4.8)。
- **运行形态**:纯沙箱 main.js 够用,还是要随包 Node 进程装依赖跑重活(node 槽,§4.12)。
@@ -882,12 +883,13 @@ key、未知字段、原清单没有的条目、类型或长度不合格、文
node secretBindings key、setup kv key——都不能使用 \`__proto__\`、\`constructor\` 或
\`prototype\`;这些名称是宿主保留键,打包时会直接拒绝。
-十五个卡槽:\`tool\`(注册工具给 AI)、\`cindy\`(请 Cindy 本体代办:出图/改图/快问快答,
+十六个卡槽:\`tool\`(注册工具给 AI)、\`cindy\`(请 Cindy 本体代办:出图/改图/快问快答,
见 §4 与 §4.0.2)、\`agent\`(让
当前 Agent 开始一个普通用户回合,或派活取回结果,见 §4.11 / §4.11.1)、\`panel\`(常驻
面板)、\`card\`(聊天卡片:自绘工具调用的过程与结果,见 §4.5)、\`subscribe\`(旁听会话
事件 + 拦截用户消息,见 §4.6)、\`network\`(访问自带服务的域名白名单 HTTP,主机代发,
-见 §4.7)、\`notify\`(弹系统轻提示,主机画壳带你的身份头,见 §4.9)、\`fs\`(请主机
+见 §4.7)、\`notify\`(弹系统轻提示,主机画壳带你的身份头,见 §4.9)、\`confirm\`(弹主机
+同款确认框征求用户同意并拿回真实点击,见 §4.18)、\`fs\`(请主机
代写文件:私有数据目录/会话工作目录/过户目录三档,见 §4.10)、\`node\`(运行随包
Node 工作进程或 stdio MCP,见 §4.12)、\`session-context\`(派活时主机把当前会话的
可信 session_id / workdir / 只读状态注入 args,见 §4.13)、\`pick\`(请主机弹系统选文件夹窗口,
@@ -2050,8 +2052,9 @@ const r = await cindy.send({ type: 'notify', text: '视频已生成,点面板查
别拿它刷进度条,进度走聊天卡片的过程版(§4.5);
- **身份头主机画**:提示上自动带你的图标和名字,冒充不了主机通知、也冒充不了别的
意识;正文里不用再自报家门;
-- 提示自动消失、无按钮、无回执——**不是确认框**。需要用户点选/确认的交互,用面板
- 自绘控件或交互卡(§4.5 的 data-ghost-action)。
+- 提示自动消失、无按钮、无回执——**不是确认框**。要用户点「同意/取消」并把答案交回
+ 给你,用 §4.18 的 confirm 槽(主机同款确认框);要在聊天流里放按钮用交互卡
+ (§4.5 的 data-ghost-action)。
## 4.10 写文件(fs 槽)
@@ -2605,6 +2608,49 @@ const ensured = await cindy.workspace({
- 创建的是**空会话**:不拉起 agent、不发消息、不自动开始任何任务;要让 Agent
立即干活请配合 agent 槽(§4.11)。
+## 4.18 确认弹窗(confirm 槽)
+
+动手之前要用户点头(切分支、覆盖文件、发不可撤回的东西)时,声明 \`confirm\` 槽,
+经管子请主机弹一个**和 Cindy 自己一模一样**的确认框,并拿回用户的真实点击:
+
+\`\`\`js
+const r = await cindy.confirm({
+ body: '把项目目录从 main 切到 fix/xxx 分支?你没提交的改动可能被带走。', // 必填,≤300 字
+ confirmText: '切换', // 可选,≤12 字;不给就用主机缺省的「确认」
+ cancelText: '先不切', // 可选,同上上限;不给就用主机缺省的「取消」
+ danger: true // 可选,危险动作(删除/覆盖/改用户文件)主按钮变红
+});
+if (r.ok && r.confirmed) {
+ // 用户点了主按钮 → 干活
+} else if (r.ok) {
+ // 用户点了取消 / 按了 Esc / 点了弹窗外面 → 什么都别做,也别再弹一次
+} else {
+ // r.errorCode: PERMISSION_DENIED / INVALID_REQUEST / RATE_LIMITED / BUSY /
+ // UNAVAILABLE / INTERNAL —— 这是"没问到",不是"用户拒绝"
+}
+\`\`\`
+
+规则与红线:
+
+- **\`ok:true\` 只代表问到了,答案看 \`confirmed\`**。把 \`ok\` 当同意是最常见的写错法;
+- 弹窗的壳、标题(主机文案「插件「你的名字」请你确认」)与身份头(你的图标+名字)
+ **由主机画**,身份取自已装清单而不是你自报;你只供 \`body\` 与按钮字,且会被净化
+ (控制字符剥除)+ 卡长度。**伪装不了主机文案、冒充不了别的插件,也点不了自己的
+ 按钮**——点击链路主机独占;
+- 同一插件两次请求最小间隔 3 秒(RATE_LIMITED),**全局同时只有一个确认框**
+ (BUSY,不排队)。模态框比提示更打扰人,排队就是骚扰队列;
+- 没人应答 90 秒 → 当成**没同意**。同理:没有可挂靠窗口回 UNAVAILABLE。一切
+ "问不出来"的情况一律 fail closed,你收不到假的同意;
+- **尊重取消**:用户点了取消就别换个说法再弹一次。反复弹会撞上限速,也会让用户
+ 直接停用你;
+- 没有「下次不再提示」,也没有三选一和复选框:确认的价值就在于每次都是真点击,
+ 给了"永久免问"等于没确认;
+- **桌面独占**:本机弹窗不进远程/手机版通道(平台白名单里属永不放行类别)。手机端
+ 或远程控制端跑到这里会拿到失败分档,你的逻辑要能接住(当"没同意"处理);
+- 真正的守门仍在你自己手里:确认只是问一句,**该校验的前置条件(文件在不在、
+ 工作区干不干净)确认前后都要自己再查一遍**——用户点确认和你真动手之间,
+ 世界可能已经变了。
+
## 5. 面板(panel.html/css/js)
- 显示形态由 \`panel.position\` 决定:\`left\`(缺省)= 停靠主聊天窗左侧的常驻
diff --git a/apps/desktop/src/main/cindy-brain/ghostConfirmDialogBridge.ts b/apps/desktop/src/main/cindy-brain/ghostConfirmDialogBridge.ts
new file mode 100644
index 0000000000..a05fc23f86
--- /dev/null
+++ b/apps/desktop/src/main/cindy-brain/ghostConfirmDialogBridge.ts
@@ -0,0 +1,146 @@
+/**
+ * GhostConfirmDialogBridge —— confirm 槽的 main ↔ renderer 往返桥(2026-07-31)。
+ *
+ * confirm 槽要的是**答案**,而 notify 那条通道是单向的(broadcast 完就结束)。
+ * 所以这里照 GhostGrantConfirmBridge 的成熟模式做一条带回执的往返:
+ * main 铸一个 requestId → 投给 renderer → pending promise 挂起 → renderer 用
+ * ConfirmDialogProvider 弹主机同款确认框 → 用户点击后经 IPC 回包 → settle。
+ *
+ * 与过户确认卡(GhostGrantConfirmBridge)的两处不同,都是刻意的:
+ *
+ * 1. **只投一个窗口,不 broadcast**。过户确认卡是聊天流里的卡片,广播到多窗口
+ * 再靠 DISMISSED 收卡没问题;模态确认框广播出去会在每个窗口各弹一个、收回
+ * 多份答案(preview 槽注释里踩过同类坑)。所以这里由 deps.sendToWindow 精确
+ * 投递单个窗口(focused ?? 第一个),投不出去就 reject 让槽回 UNAVAILABLE。
+ * 2. **不挂会话**。它可能来自面板点击、也可能来自工具调用链,不一定有 sessionId;
+ * 清理靠超时与显式 cancelAll(窗口关闭/插件沉睡时调)。
+ *
+ * fail closed 是本模块的第一原则:超时、投递失败、回包形状非法、被清理,
+ * 一律 resolve 成 false(没同意)。绝不把「问不出来」错当成「用户同意了」。
+ *
+ * 本模块保持 electron-free(投递由 index.ts 注入),单测直接 new。
+ */
+
+import { randomUUID } from 'node:crypto';
+
+import { GHOST_CONFIRM_TIMEOUT_MS } from '../../shared/ghost.js';
+
+/** 推给 renderer 的确认框载荷(身份三件套由主机填,renderer 只负责画)。 */
+export interface GhostConfirmPush {
+ requestId: string;
+ ghostId: string;
+ ghostName: string;
+ iconDataUrl?: string;
+ body: string;
+ /** null = renderer 用自己的缺省按钮文案(跟用户语言走)。 */
+ confirmText: string | null;
+ cancelText: string | null;
+ danger: boolean;
+}
+
+export interface GhostConfirmDialogBridgeDeps {
+ /**
+ * 把确认框投给**一个**窗口。返回 false = 没有可投的窗口(桥据此 reject,
+ * 槽回 UNAVAILABLE,而不是谎报用户拒绝)。
+ */
+ sendToWindow(payload: GhostConfirmPush): boolean;
+ /** 兜底超时;缺省 GHOST_CONFIRM_TIMEOUT_MS。测试注小值。 */
+ timeoutMs?: number;
+ now?(): number;
+ log?: { warn: (msg: string, meta?: Record<string, unknown>) => void };
+}
+
+interface PendingConfirmEntry {
+ ghostId: string;
+ resolve: (confirmed: boolean) => void;
+ timeoutId: ReturnType<typeof setTimeout>;
+}
+
+export class GhostConfirmDialogBridge {
+ private readonly pending = new Map<string, PendingConfirmEntry>();
+
+ constructor(private readonly deps: GhostConfirmDialogBridgeDeps) {}
+
+ /**
+ * 弹一个确认框并等答案。没有可投窗口时 reject(区别于「用户拒绝」)。
+ * 其余一切异常路径都 resolve(false)。
+ */
+ request(params: Omit<GhostConfirmPush, 'requestId'>): Promise<boolean> {
+ const requestId = randomUUID();
+ return new Promise<boolean>((resolve, reject) => {
+ const delivered = this.deps.sendToWindow({ requestId, ...params });
+ if (!delivered) {
+ reject(new Error('没有可挂靠的宿主窗口'));
+ return;
+ }
+ const timeoutMs = this.deps.timeoutMs ?? GHOST_CONFIRM_TIMEOUT_MS;
+ const timeoutId = setTimeout(() => {
+ // 没人应答 = 没同意。日志留痕,方便排查"插件说它问了但我没看到"。
+ this.deps.log?.warn('ghost confirm timed out (treated as declined)', {
+ ghostId: params.ghostId,
+ requestId,
+ });
+ this.settle(requestId, false);
+ }, timeoutMs);
+ this.pending.set(requestId, { ghostId: params.ghostId, resolve, timeoutId });
+ });
+ }
+
+ /**
+ * renderer 回包。返回是否命中本桥的 pending(false = 陌生/已结算的 requestId,
+ * 直接忽略——重复回包与伪造 id 都走这条,不抛)。
+ * 非布尔的 confirmed 一律按 false 兜底,不让沙箱靠畸形回包骗到「同意」。
+ */
+ resolve(requestId: string, confirmed: unknown): boolean {
+ const entry = this.pending.get(requestId);
+ if (!entry) return false;
+ if (typeof confirmed !== 'boolean') {
+ this.deps.log?.warn('ghost confirm: invalid decision shape, treated as declined', {
+ requestId,
+ });
+ }
+ this.settle(requestId, confirmed === true);
+ return true;
+ }
+
+ /**
+ * 清掉在途确认(窗口全关、插件沉睡/卸载时调):一律按「没同意」结算,
+ * 免得插件那侧永久挂起。传 ghostId 只清该插件的。
+ */
+ cancelAll(ghostId?: string): void {
+ for (const [requestId, entry] of Array.from(this.pending.entries())) {
+ if (ghostId !== undefined && entry.ghostId !== ghostId) continue;
+ this.settle(requestId, false);
+ }
+ }
+
+ /** 在途单数(单测与诊断用)。 */
+ get pendingCount(): number {
+ return this.pending.size;
+ }
+
+ private settle(requestId: string, confirmed: boolean): void {
+ const entry = this.pending.get(requestId);
+ if (!entry) return;
+ this.pending.delete(requestId);
+ clearTimeout(entry.timeoutId);
+ entry.resolve(confirmed);
+ }
+}
+
+let bridgeSingleton: GhostConfirmDialogBridge | null = null;
+
+/**
+ * 初始化单例(cindy-brain/index.ts 装配期调用,注入投递)。未初始化(极早期/
+ * 单测环境)时 getter 返回 null,调用方按「确认通道未就绪」拒绝,不抛。
+ */
+export function initGhostConfirmDialogBridge(
+ deps: GhostConfirmDialogBridgeDeps,
+): GhostConfirmDialogBridge {
+ bridgeSingleton = new GhostConfirmDialogBridge(deps);
+ return bridgeSingleton;
+}
+
+export function getGhostConfirmDialogBridge(): GhostConfirmDialogBridge | null {
+ return bridgeSingleton;
+}
diff --git a/apps/desktop/src/main/cindy-brain/index.ts b/apps/desktop/src/main/cindy-brain/index.ts
index ae7be1dc32..f47a2e2c6c 100644
--- a/apps/desktop/src/main/cindy-brain/index.ts
+++ b/apps/desktop/src/main/cindy-brain/index.ts
@@ -148,6 +148,11 @@ import { GhostPreviewSlot } from './previewSlot.js';
import { GhostWorkspaceSlot, type WorkspaceSessionService } from './workspaceSlot.js';
import type { GhostTrustRegistry } from './ghostSignature.js';
import { GhostNotifySlot, sanitizeGhostNoticeText } from './notifySlot.js';
+import { GhostConfirmSlot } from './confirmSlot.js';
+import {
+ getGhostConfirmDialogBridge,
+ initGhostConfirmDialogBridge,
+} from './ghostConfirmDialogBridge.js';
import { GhostNetworkSlot } from './networkSlot.js';
import { GhostFsSlot } from './fsSlot.js';
import { getGhostGrantConfirmBridge } from './ghostGrantConfirmBridge.js';
@@ -1554,6 +1559,50 @@ export function getGhostNotifySlot(): GhostNotifySlot {
return notifySlotSingleton;
}
+let confirmSlotSingleton: GhostConfirmSlot | null = null;
+
+/** 意识确认弹窗通道(main → **单个**窗口;renderer 用主机同款 ConfirmDialog 渲染)。 */
+export const GHOST_CONFIRM_CHANNEL = 'ghosts:confirm-request';
+
+/**
+ * 确认弹窗槽单例(confirm):资格审/净化/限速/单飞在 GhostConfirmSlot,往返与
+ * 超时兜底在 GhostConfirmDialogBridge,这里只组装"投给哪个窗口"。
+ *
+ * 只投**一个**窗口(focused ?? 第一个),不像 notify 那样广播:模态确认框广播
+ * 出去会在每个窗口各弹一个、收回多份答案。没有可投窗口时 sendToWindow 回
+ * false → 桥 reject → 槽回 UNAVAILABLE(明确区别于"用户拒绝")。
+ */
+export function getGhostConfirmSlot(): GhostConfirmSlot {
+ if (!confirmSlotSingleton) {
+ const bridge =
+ getGhostConfirmDialogBridge() ??
+ initGhostConfirmDialogBridge({
+ sendToWindow: (payload) => {
+ const win = BrowserWindow.getFocusedWindow() ?? BrowserWindow.getAllWindows()[0];
+ if (!win || win.isDestroyed()) return false;
+ win.webContents.send(GHOST_CONFIRM_CHANNEL, payload);
+ return true;
+ },
+ log,
+ });
+ confirmSlotSingleton = new GhostConfirmSlot({
+ getGhost: findAvailableGhost,
+ showConfirm: (params) =>
+ bridge.request({
+ ghostId: params.ghostId,
+ ghostName: params.ghostName,
+ ...(params.iconDataUrl ? { iconDataUrl: params.iconDataUrl } : {}),
+ body: params.body,
+ confirmText: params.confirmText,
+ cancelText: params.cancelText,
+ danger: params.danger,
+ }),
+ log,
+ });
+ }
+ return confirmSlotSingleton;
+}
+
let pickSlotSingleton: GhostPickSlot | null = null;
/**
@@ -3413,9 +3462,30 @@ export function registerGhostIpc(): void {
if (type === 'notify') {
return getGhostNotifySlot().handleNotify(id, payload);
}
+ // confirm-request = 确认弹窗(confirm 槽):资格审/净化/限速/单飞在
+ // confirmSlot,往返与超时兜底在 ghostConfirmDialogBridge。invoke 返回值即
+ // 结构化结果:ok:true 只代表问到了,答案看 confirmed。
+ if (type === 'confirm-request') {
+ return getGhostConfirmSlot().handleRequest(id, payload);
+ }
throwIpcError('INVALID_PARAMS', '未知的管子消息类型');
});
+ // ── 确认弹窗回包(confirm 槽)────────────────────────────────────────
+ // renderer 上的确认框被用户点掉之后,把答案送回 main 结算那条挂起的管子请求。
+ // 不校验 sender 归属:requestId 是 main 自己铸的 randomUUID,只在本机 renderer
+ // 手里;陌生/重复的 id 由桥直接忽略(返回 handled:false),没有可利用面。
+ // 非布尔的 confirmed 在桥里一律按"没同意"兜底,不给靠畸形回包骗到同意的路。
+ ipcMain.handle('ghosts:confirm:resolve', async (_event, raw: unknown) => {
+ const p = raw as { requestId?: unknown; confirmed?: unknown } | null;
+ if (!p || typeof p.requestId !== 'string' || p.requestId.length === 0 || p.requestId.length > 128) {
+ throwIpcError('INVALID_PARAMS', 'requestId must be a non-empty string');
+ }
+ const bridge = getGhostConfirmDialogBridge();
+ if (!bridge) return { handled: false };
+ return { handled: bridge.resolve(p.requestId, p.confirmed) };
+ });
+
// ── 意识聊天卡片取件(卡槽③;宿主 renderer 历史回放用)──────────────
// 查询型 handler:无卡返回 { card: null },renderer 据此降级为通用媒体
// 渲染(远程会话/被 GC 的历史卡都走这条),不抛 NOT_FOUND——规则 13 的
diff --git a/apps/desktop/src/preload/ghostPreload.ts b/apps/desktop/src/preload/ghostPreload.ts
index 81bb09a7f3..1b46212c4f 100644
--- a/apps/desktop/src/preload/ghostPreload.ts
+++ b/apps/desktop/src/preload/ghostPreload.ts
@@ -31,6 +31,9 @@ import { contextBridge, ipcRenderer } from 'electron';
* 的语法糖;URL 白名单守门在主机侧 previewSlot。
* - workspace(req):workspace 槽的便捷口——send({type:'workspace-request',
* …req}) 的语法糖;目录授权与会话创建守门全在主机侧 workspaceSlot。
+ * - confirm(req):confirm 槽的便捷口——send({type:'confirm-request', …req}) 的
+ * 语法糖;主机弹自己那套确认框并把用户的真实点击回给沙箱,资格审/净化/限速/
+ * 单飞/超时兜底全在主机侧 confirmSlot 与 ghostConfirmDialogBridge。
*/
type HostMessageListener = (payload: unknown) => void;
@@ -73,4 +76,6 @@ contextBridge.exposeInMainWorld('cindy', {
ipcRenderer.invoke('ghost-pipe:send', { ...req, type: 'preview-request' }),
workspace: (req: Record<string, unknown>): Promise<unknown> =>
ipcRenderer.invoke('ghost-pipe:send', { ...req, type: 'workspace-request' }),
+ confirm: (req: Record<string, unknown>): Promise<unknown> =>
+ ipcRenderer.invoke('ghost-pipe:send', { ...req, type: 'confirm-request' }),
});
diff --git a/apps/desktop/src/preload/preload.ts b/apps/desktop/src/preload/preload.ts
index 81dbeb2db6..fd38b2be87 100644
--- a/apps/desktop/src/preload/preload.ts
+++ b/apps/desktop/src/preload/preload.ts
@@ -429,6 +429,9 @@ const fanOutGhostAssistantPending = createIpcFanOut('ghosts:assistant-message-pe
const fanOutGhostHookFused = createIpcFanOut('ghosts:hook-fused');
// 意识系统提示(notify 槽:宿主 Toast 渲染,带意识身份头)。
const fanOutGhostNotify = createIpcFanOut('ghosts:notify');
+// 意识确认弹窗(confirm 槽:renderer 用主机同款 ConfirmDialog 弹,答案回 main)。
+// main 只投单个窗口(不广播),所以这里落地的窗口就是该弹框的唯一归属。
+const fanOutGhostConfirmRequest = createIpcFanOut('ghosts:confirm-request');
// 插件预览开页(preview 槽:renderer 在右侧栏开 web-browser 标签)。
const fanOutGhostPreviewOpen = createIpcFanOut('ghosts:preview-open');
const fanOutVoiceInputModifierShortcutKeys = createIpcFanOut('voice-input:modifier-shortcut-keys');
@@ -940,6 +943,11 @@ contextBridge.exposeInMainWorld('electronAPI', {
onAssistantMessagePending: fanOutGhostAssistantPending,
onHookFused: fanOutGhostHookFused,
onNotify: fanOutGhostNotify,
+ onConfirmRequest: fanOutGhostConfirmRequest,
+ // 确认弹窗回包(confirm 槽):renderer 把用户的点击送回 main 结算那条挂起的
+ // 管子请求。requestId 是 main 铸的,陌生/重复 id 由桥忽略。
+ resolveConfirm: (requestId: string, confirmed: boolean): Promise<{ handled: boolean }> =>
+ ipcRenderer.invoke('ghosts:confirm:resolve', { requestId, confirmed }),
onPreviewOpen: fanOutGhostPreviewOpen,
getCard: (
callId: string,
diff --git a/apps/desktop/src/renderer/App.tsx b/apps/desktop/src/renderer/App.tsx
index 0c5d5a8234..d8f05c0357 100644
--- a/apps/desktop/src/renderer/App.tsx
+++ b/apps/desktop/src/renderer/App.tsx
@@ -25,6 +25,7 @@ import { Tooltip } from '@/components/ui/tooltip';
import { ConfirmDialogProvider } from '@/components/ui/confirm-dialog-provider';
import { FindInPageBar } from '@/components/find-in-page/FindInPageBar';
import { ProjectAutomationNotifyBridge } from '@/features/scheduler/components/ProjectAutomationNotifyBridge';
+import { GhostConfirmDialogHost } from '@/cindy-brain/GhostConfirmDialogHost';
import { makerChatStore } from '@/lib/makerChatStore';
import { installSystemNetworkErrorToastListener } from '@/lib/systemNetworkErrorToast';
import { installSilentInstallToastListener } from '@/lib/silentInstallToast';
@@ -283,6 +284,10 @@ export function App() {
<EnvCheckGuard>
<MakerBootstrap />
<ProjectAutomationNotifyBridge />
+ {/* confirm 槽:插件请主机弹确认框。必须在 ConfirmDialogProvider
+ 内(要 useConfirmDialog);main 只投单个窗口,所以每个窗口
+ 都挂、谁收到谁弹,不按窗口类型 gate。 */}
+ <GhostConfirmDialogHost />
<RouterProvider router={router} />
</EnvCheckGuard>
</LoginHandoffHost>
diff --git a/apps/desktop/src/renderer/cindy-brain/GhostConfirmDialogHost.tsx b/apps/desktop/src/renderer/cindy-brain/GhostConfirmDialogHost.tsx
new file mode 100644
index 0000000000..a3596c9508
--- /dev/null
+++ b/apps/desktop/src/renderer/cindy-brain/GhostConfirmDialogHost.tsx
@@ -0,0 +1,77 @@
+import { useEffect } from 'react';
+import { useTranslation } from 'react-i18next';
+
+import { useConfirmDialog } from '@/components/ui/confirm-dialog-provider';
+
+/**
+ * GhostConfirmDialogHost —— confirm 槽的 renderer 落地(2026-07-31)。
+ *
+ * 插件经管子请主机弹确认框(main:confirmSlot → ghostConfirmDialogBridge),这里
+ * 把它接到**基座自己在用的那套** ConfirmDialogProvider 上,所以插件的确认框与
+ * Cindy 自己的确认框长得一模一样、排队规则也一致(useConfirmDialog 自带队列)。
+ *
+ * 信任边界(与 Toast 的来源身份头同款):
+ * - 标题是**主机文案**(带插件名),插件写不了;
+ * - 身份头(图标 + 名字)由这里画,数据来自 main 的已装清单(不是插件自报);
+ * - 插件只供 body 与按钮字,main 侧已净化 + 卡长度;这里作纯文本渲染(description
+ * 与 content 都是文本节点,不注入 HTML);
+ * - 用户的点击才是答案:确认 true、取消/Esc/点外部 false,原样回给 main。
+ *
+ * main 只把请求投给**单个**窗口,所以收到即本窗口负责弹,不需要按窗口类型 gate
+ * ——弹在用户正看着的那个窗口才对。
+ *
+ * 挂载点:App.tsx 的 ConfirmDialogProvider 内部(要用 context,不能挂在 store 里)。
+ */
+export function GhostConfirmDialogHost() {
+ const { t } = useTranslation();
+ const { confirm } = useConfirmDialog();
+
+ useEffect(() => {
+ const off = window.electronAPI.ghosts?.onConfirmRequest?.((payload) => {
+ if (!payload || typeof payload.requestId !== 'string' || typeof payload.body !== 'string') {
+ return;
+ }
+ const { requestId, ghostName, iconDataUrl, body, confirmText, cancelText, danger } = payload;
+ void (async () => {
+ let confirmed = false;
+ try {
+ confirmed = await confirm({
+ // 主机文案:插件名只作插值,伪装不了这句话本身
+ title: t('settings.ghosts.confirm.dialogTitle', { name: ghostName }),
+ description: body,
+ // 身份头:与 Toast 的来源头同款视觉(语义 token,明暗两档自动跟随)
+ content: (
+ <span className="inline-flex items-center gap-1.5">
+ {iconDataUrl && (
+ <img
+ src={iconDataUrl}
+ alt=""
+ draggable={false}
+ className="h-4 w-4 rounded-[4px] object-cover"
+ />
+ )}
+ <span className="max-w-[220px] truncate text-13 font-medium leading-snug text-[var(--text-tertiary)]">
+ {ghostName}
+ </span>
+ </span>
+ ),
+ ...(confirmText ? { confirmText } : {}),
+ ...(cancelText ? { cancelText } : {}),
+ ...(danger ? { confirmVariant: 'destructive' as const } : {}),
+ });
+ } finally {
+ // 无论如何都要回包:不回的话插件那侧会一直挂到 main 的 90 秒兜底超时。
+ // 回包失败(窗口正在关等)也不额外处理——那条超时就是为此存在的。
+ try {
+ await window.electronAPI.ghosts?.resolveConfirm?.(requestId, confirmed);
+ } catch {
+ // 忽略:main 侧超时会兜底成「没同意」
+ }
+ }
+ })();
+ });
+ return off;
+ }, [confirm, t]);
+
+ return null;
+}
diff --git a/apps/desktop/src/renderer/cindy-brain/GhostPermissionList.tsx b/apps/desktop/src/renderer/cindy-brain/GhostPermissionList.tsx
index 0fb29de1ab..260496cd6d 100644
--- a/apps/desktop/src/renderer/cindy-brain/GhostPermissionList.tsx
+++ b/apps/desktop/src/renderer/cindy-brain/GhostPermissionList.tsx
@@ -23,6 +23,7 @@ import {
LayoutTemplate,
MapPin,
Megaphone,
+ MessageCircleQuestion,
PanelLeft,
PanelRight,
Sparkles,
@@ -53,6 +54,7 @@ const KIND_ICON: Record<GhostPermissionItem['kind'], LucideIcon> = {
card: LayoutTemplate,
network: Globe,
notify: Megaphone,
+ confirm: MessageCircleQuestion,
fs: FilePen,
'session-context': MapPin,
pick: FolderOpen,
diff --git a/apps/desktop/src/renderer/features/plugin/GhostPluginDetailView.tsx b/apps/desktop/src/renderer/features/plugin/GhostPluginDetailView.tsx
index f5a3e31d69..fd38c0161f 100644
--- a/apps/desktop/src/renderer/features/plugin/GhostPluginDetailView.tsx
+++ b/apps/desktop/src/renderer/features/plugin/GhostPluginDetailView.tsx
@@ -26,6 +26,7 @@ import {
LayoutTemplate,
MapPin,
Megaphone,
+ MessageCircleQuestion,
MoreVertical,
PanelLeft,
PanelRight,
@@ -93,6 +94,7 @@ const PERMISSION_ICON: Record<GhostPermissionItem['kind'], LucideIcon> = {
card: LayoutTemplate,
network: Globe,
notify: Megaphone,
+ confirm: MessageCircleQuestion,
fs: FilePen,
'session-context': MapPin,
pick: FolderOpen,
diff --git a/apps/desktop/src/renderer/i18n/locales/en/common.json b/apps/desktop/src/renderer/i18n/locales/en/common.json
index b507670ed4..958ff4e322 100644
--- a/apps/desktop/src/renderer/i18n/locales/en/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/en/common.json
@@ -2947,6 +2947,8 @@
"cardExternalLinkDetail": "Clicking a card link shows a confirmation dialog; the URL opens in your system browser only after you approve. Only http/https addresses are allowed.",
"notify": "Can show system tips (light banner at the top of the screen)",
"notifyDetail": "Tip text is provided by this plugin and labeled with its name; tips fade automatically and never block your work.",
+ "confirm": "Can ask for your confirmation in a dialog",
+ "confirmDetail": "Before acting it can open a dialog that looks like Cindy's own to ask you. The question comes from the plugin and the dialog is labeled with its name; only you can click confirm or cancel — the plugin cannot. At most one dialog at a time, and asking too often is blocked.",
"fsWrite": "Can write files (create / modify)",
"fsWriteDetail": "Its own private data folder is always writable. Writes into the current session's working directory follow the session's permission mode (auto-approve modes write directly; per-action modes ask you first). Any other folder always requires your confirmation. Files are always written by the host — the plugin itself never touches your file system.",
"networkHost": "Accesses the network domain {{host}}",
@@ -3093,6 +3095,9 @@
"dialogTitle": "Choose a folder",
"dialogMessage": "Plugin “{{name}}” is asking you to choose a folder"
},
+ "confirm": {
+ "dialogTitle": "Plugin “{{name}}” needs your confirmation"
+ },
"workspace": {
"dialogTitle": "Choose a project folder",
"dialogMessage": "Plugin “{{name}}” is asking you to choose a project folder to create a session in the sidebar"
diff --git a/apps/desktop/src/renderer/i18n/locales/ja/common.json b/apps/desktop/src/renderer/i18n/locales/ja/common.json
index 2d4da38340..90035d4dde 100644
--- a/apps/desktop/src/renderer/i18n/locales/ja/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/ja/common.json
@@ -2946,6 +2946,8 @@
"cardExternalLinkDetail": "カード内のリンクをクリックすると確認ダイアログが表示され、承認後にシステムブラウザで開きます。http/https アドレスのみ許可されます。",
"notify": "システム通知を表示可能(画面上部のライトな通知)",
"notifyDetail": "通知の内容はこのプラグインが提供し、通知にはその名前が表示されます。自動的に消え、操作を妨げることはありません。",
+ "confirm": "確認ダイアログで同意を求められます",
+ "confirmDetail": "実行前に Cindy 自身と同じ確認ダイアログを開いて尋ねることができます。文面はプラグインが提供し、ダイアログにはその名前が表示されます。確認するかキャンセルするかはあなたがクリックして決め、プラグイン自身はクリックできません。同時に開けるのは 1 つまでで、頻繁な要求はブロックされます。",
"fsWrite": "ファイルを書き込めます(作成/変更)",
"fsWriteDetail": "専用データフォルダにはいつでも書き込めます。現在のセッションの作業ディレクトリへの書き込みはセッションの権限モードに従います(自動承認モードでは直接書き込み、逐次確認モードでは事前に承認を求めます)。それ以外のフォルダへの書き込みは毎回確認が必要です。ファイルは常にホストが代理で書き込み、プラグイン自体があなたのファイルシステムに直接アクセスすることはありません。",
"networkHost": "ネットワークドメイン {{host}} にアクセス",
@@ -3092,6 +3094,9 @@
"dialogTitle": "フォルダを選択",
"dialogMessage": "プラグイン「{{name}}」がフォルダの選択を求めています"
},
+ "confirm": {
+ "dialogTitle": "プラグイン「{{name}}」が確認を求めています"
+ },
"workspace": {
"dialogTitle": "プロジェクトフォルダを選択",
"dialogMessage": "プラグイン「{{name}}」がサイドバーにセッションを作成するため、プロジェクトフォルダの選択を求めています"
diff --git a/apps/desktop/src/renderer/i18n/locales/ko/common.json b/apps/desktop/src/renderer/i18n/locales/ko/common.json
index b369183f2b..af16740823 100644
--- a/apps/desktop/src/renderer/i18n/locales/ko/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/ko/common.json
@@ -2946,6 +2946,8 @@
"cardExternalLinkDetail": "카드의 링크를 클릭하면 확인 대화 상자가 표시되며, 승인 후에만 시스템 브라우저에서 열립니다. http/https 주소만 허용됩니다.",
"notify": "시스템 알림 표시 가능(화면 상단의 가벼운 알림)",
"notifyDetail": "알림 내용은 이 플러그인이 제공하며 알림에는 이름이 표시됩니다. 자동으로 사라지며 작업을 방해하지 않습니다.",
+ "confirm": "확인 대화상자로 동의를 요청할 수 있음",
+ "confirmDetail": "작업 전에 Cindy 자체와 동일한 확인 대화상자를 열어 물어볼 수 있습니다. 질문 내용은 플러그인이 제공하며 대화상자에는 그 이름이 표시됩니다. 확인이든 취소든 직접 클릭해야 하고 플러그인은 스스로 누를 수 없습니다. 동시에 하나만 열 수 있으며 너무 자주 요청하면 차단됩니다.",
"fsWrite": "파일을 쓸 수 있음(생성/수정)",
"fsWriteDetail": "전용 데이터 폴더에는 언제든지 쓸 수 있습니다. 현재 세션의 작업 디렉터리 쓰기는 세션의 권한 모드를 따릅니다(자동 승인 모드에서는 바로 쓰고, 개별 확인 모드에서는 먼저 승인을 요청합니다). 그 외 폴더에 쓰려면 매번 확인이 필요합니다. 파일은 항상 호스트가 대신 기록하며 플러그인 자체는 파일 시스템에 직접 접근할 수 없습니다.",
"networkHost": "네트워크 도메인 {{host}}에 접근",
@@ -3092,6 +3094,9 @@
"dialogTitle": "폴더 선택",
"dialogMessage": "플러그인 \"{{name}}\"이(가) 폴더 선택을 요청합니다"
},
+ "confirm": {
+ "dialogTitle": "플러그인 \"{{name}}\"이(가) 확인을 요청합니다"
+ },
"workspace": {
"dialogTitle": "프로젝트 폴더 선택",
"dialogMessage": "플러그인 \"{{name}}\"이(가) 사이드바에 세션을 만들기 위해 프로젝트 폴더 선택을 요청합니다"
diff --git a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
index 4d19ab961b..8d0ebee811 100644
--- a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
@@ -2946,6 +2946,8 @@
"cardExternalLinkDetail": "卡片中的链接点击后会弹出确认框,你同意后才会在系统浏览器中打开;仅限 http/https 地址。",
"notify": "可弹出系统提示(屏幕顶部的轻提示)",
"notifyDetail": "提示内容由这个插件提供,提示上会标注它的名字;自动消失,不会打断你的操作。",
+ "confirm": "可弹出确认框征求你同意",
+ "confirmDetail": "它动手前可以弹一个和 Cindy 同款的确认框来问你,问句由它提供、框上会标注它的名字;同意还是取消都由你亲手点,它自己点不了。同时最多一个确认框,弹得太频会被拦下。",
"fsWrite": "可写入文件(创建/修改)",
"fsWriteDetail": "它自己的专属数据目录随时可写;当前对话的工作目录跟随对话的权限模式(免批模式直接写,逐条确认模式先征求你同意);其它目录每次都需要你确认。文件始终由主机代写,插件本身无法直接访问你的文件系统。",
"networkHost": "访问网络域名 {{host}}",
@@ -3092,6 +3094,9 @@
"dialogTitle": "选择文件夹",
"dialogMessage": "插件「{{name}}」请求你选择一个文件夹"
},
+ "confirm": {
+ "dialogTitle": "插件「{{name}}」请你确认"
+ },
"workspace": {
"dialogTitle": "选择项目文件夹",
"dialogMessage": "插件「{{name}}」请求你选择一个项目文件夹,用于在侧边栏创建对话"
diff --git a/apps/desktop/src/renderer/vite-env.d.ts b/apps/desktop/src/renderer/vite-env.d.ts
index 23ff23960d..8514eecd49 100644
--- a/apps/desktop/src/renderer/vite-env.d.ts
+++ b/apps/desktop/src/renderer/vite-env.d.ts
@@ -1295,6 +1295,23 @@ interface ElectronAPI {
tone: 'info' | 'success' | 'warning' | 'error';
}) => void,
) => () => void;
+ /** confirm 槽:插件请求弹主机同款确认框(main 已资格审+净化+限速+单飞)。
+ * main 只投单个窗口,所以收到即本窗口负责弹;答案用 resolveConfirm 回包。
+ * confirmText/cancelText 为 null 时用 renderer 自己的缺省文案(跟语言走)。 */
+ onConfirmRequest: (
+ callback: (payload: {
+ requestId: string;
+ ghostId: string;
+ ghostName: string;
+ iconDataUrl?: string;
+ body: string;
+ confirmText: string | null;
+ cancelText: string | null;
+ danger: boolean;
+ }) => void,
+ ) => () => void;
+ /** confirm 槽回包:把用户的点击送回 main 结算挂起的管子请求。 */
+ resolveConfirm: (requestId: string, confirmed: boolean) => Promise<{ handled: boolean }>;
/** preview 槽:插件请求在右侧栏内置浏览器开预览标签(main 已白名单守门+限速)。 */
onPreviewOpen: (
callback: (payload: {
diff --git a/apps/desktop/src/shared/ghost.ts b/apps/desktop/src/shared/ghost.ts
index 89d0274fce..c37bccf311 100644
--- a/apps/desktop/src/shared/ghost.ts
+++ b/apps/desktop/src/shared/ghost.ts
@@ -56,7 +56,8 @@ export function parseGhostPartition(partition: unknown): string | null {
const GHOST_ID_RE = /^[a-z0-9][a-z0-9-]{0,31}$/;
/**
- * 十四个卡槽(意识能力的全部出口,docs/dev-rules/plugin-security-and-authoring.md)。
+ * 卡槽清单(意识能力的全部出口,docs/dev-rules/plugin-security-and-authoring.md)。
+ * 数量随迭代增长,以本数组为准——正文不再写死个数。
* 'cindy' = 请 Cindy 本体代办(借主机自带 AI 能力干活;2026-07-11 Lizi 定案
* 由 'model' 更名——本质是 Cindy 在干活,与选模型无关;旧名在校验层作
* 静默别名兼容,已装老包不消失)。
@@ -64,7 +65,14 @@ const GHOST_ID_RE = /^[a-z0-9][a-z0-9-]{0,31}$/;
* 内的 HTTP 经主机代发(沙箱本身保持零直连),凭证锁主机保险库按声明注入。
* 'notify' = 系统提示(2026-07-14):意识经管子请主机弹一条轻提示(toast),
* 意识只供纯文本,整块 UI 主机画并带意识身份头(与订阅槽红条同一信任边界);
- * 无阻塞、无按钮、无回执——确认类交互不在此槽(走面板自绘或卡槽③交互卡)。
+ * 无阻塞、无按钮、无回执——要用户点选/确认走 'confirm' 槽。
+ * 'confirm' = 确认弹窗(2026-07-31):意识经管子请主机弹**主机同款**的二选一确认框
+ * (renderer 的 ConfirmDialogProvider),拿回用户的真实点击。与 notify 的区别是它
+ * **阻塞、有按钮、有回执**,所以骚扰面也大得多,护栏对齐 pick 槽:同插件最小间隔
+ * GHOST_CONFIRM_MIN_INTERVAL_MS、全局同时只允许一个确认框在场(BUSY,不排队)、
+ * 超时/无窗口/载荷非法一律 fail closed 当「没同意」。壳、标题与身份头(图标+名字)
+ * 由主机画,意识只供被净化的正文与按钮字——伪装不了主机文案、冒充不了别的意识,
+ * 也点不了自己的按钮。桌面独占:本机对话框在 device-link 白名单里属永不放行类别。
* 'fs' = 写文件(2026-07-14):意识经管子请主机代写文件(创建/修改)。三档
* 目的地:自己的私有数据目录(userData/ghost-fs/<id>,免确认)、当前会话
* workdir(跟随会话 permission 模式:免批模式直写、逐条模式弹确认卡、
@@ -107,6 +115,7 @@ export const GHOST_SLOTS = [
'node',
'network',
'notify',
+ 'confirm',
'fs',
'session-context',
'pick',
@@ -1338,6 +1347,7 @@ export function ghostContentKeys(manifest: GhostManifest): string[] {
else if (slot === 'card') keys.push('slotCard');
else if (slot === 'network') keys.push('slotNetwork');
else if (slot === 'notify') keys.push('slotNotify');
+ else if (slot === 'confirm') keys.push('slotConfirm');
else if (slot === 'fs') keys.push('slotFs');
// skill 是信任面最高的内容(给主 Agent 灌指令),详情页必须如实露出。
else if (slot === 'skill') keys.push('slotSkill');
@@ -1403,7 +1413,7 @@ export interface GhostPermissionItem {
/** 稳定键:更新 diff 按它对齐(内容变化视为移除+新增,如面板换边)。 */
key: string;
/** 图标分组(renderer 按 kind 选图标)。 */
- kind: 'cindy' | 'agent' | 'node' | 'tool' | 'command' | 'panel' | 'code' | 'subscribe' | 'card' | 'network' | 'notify' | 'fs' | 'session-context' | 'pick' | 'preview' | 'skill' | 'workspace';
+ kind: 'cindy' | 'agent' | 'node' | 'tool' | 'command' | 'panel' | 'code' | 'subscribe' | 'card' | 'network' | 'notify' | 'confirm' | 'fs' | 'session-context' | 'pick' | 'preview' | 'skill' | 'workspace';
/** i18n key 后缀,消费方拼 `settings.ghosts.perm.<labelKey>`。 */
labelKey: string;
/** i18n 插值参数(工具名、指令名、面板标题等)。 */
@@ -1737,6 +1747,11 @@ export function ghostPermissionItems(manifest: GhostManifest): GhostPermissionIt
items.push({ key: 'notify', kind: 'notify', labelKey: 'notify', detailKey: 'notifyDetail' });
}
}
+ // confirm 槽:能请主机弹一个二选一确认框(会打断操作)。装入时如实告知"它会来问",
+ // 决定权仍在用户的点击上——detailKey 的固定说明把这层讲清。
+ if (manifest.slots.includes('confirm')) {
+ items.push({ key: 'confirm', kind: 'confirm', labelKey: 'confirm', detailKey: 'confirmDetail' });
+ }
// 常驻模式如实告知(用户要背一个后台进程);on-demand 是默认行为,不列。
if (manifest.launch === 'resident') {
items.push({ key: 'resident', kind: 'code', labelKey: 'resident', detailKey: 'residentDetail' });
@@ -4789,6 +4804,58 @@ export type GhostHostNoticeKey = (typeof GHOST_HOST_NOTICE_KEYS)[number];
/** 同一意识两条提示的最小间隔 ms(超发拒收,防 toast 刷屏骚扰)。 */
export const GHOST_NOTIFY_MIN_INTERVAL_MS = 5000;
+/**
+ * 上行:确认弹窗(confirm 槽,2026-07-31)。意识请主机弹**主机同款**的二选一
+ * 确认框(renderer 的 ConfirmDialogProvider),拿回用户的真实点击。
+ *
+ * 与 notify 的分工:notify 是「说一句就走」(无按钮无回执),本槽是「要一个答复」。
+ * 所以它会打断用户,骚扰面更大,护栏对齐 pick 槽(限速 + 全局单飞 + fail closed)。
+ *
+ * 信任边界:弹窗的壳、标题(主机文案「插件「X」请你确认」)与身份头(图标 + 名字)
+ * 全由主机画,身份取自已装清单而非载荷自报;意识只供 `body` 与按钮字,且一律过
+ * sanitizeGhostNoticeText 净化 + 长度上限。意识发起得了请求,点不了自己的按钮。
+ */
+export interface GhostPipeConfirm {
+ type: 'confirm-request';
+ /** 问句正文(纯文本,≤ GHOST_CONFIRM_BODY_MAX_CHARS;允许 \n 换行)。 */
+ body: string;
+ /** 主按钮文案(≤ GHOST_CONFIRM_BUTTON_MAX_CHARS);缺省用主机的「确认」。 */
+ confirmText?: string;
+ /** 次按钮文案(同上上限);缺省用主机的「取消」。 */
+ cancelText?: string;
+ /** 危险动作(删除/覆盖/改用户文件):主按钮走 destructive 语义色。缺省 false。 */
+ danger?: boolean;
+}
+
+/**
+ * confirm 的 invoke 返回。`ok:true` 只代表**问到了**;答案看 `confirmed`——
+ * false = 用户点了取消 / 按了 Esc / 点了弹窗外部。
+ * 失败分档带 errorCode,方便意识作者区分"被限速"与"用户拒绝"(两者处理完全不同)。
+ */
+export type GhostPipeConfirmResult =
+ | { ok: true; confirmed: boolean }
+ | {
+ ok: false;
+ errorCode: 'PERMISSION_DENIED' | 'INVALID_REQUEST' | 'RATE_LIMITED' | 'BUSY' | 'UNAVAILABLE' | 'INTERNAL';
+ message: string;
+ };
+
+/** 问句正文上限(比 notify 的 200 宽一点:确认要把后果说清,但仍是一眼读完的量)。 */
+export const GHOST_CONFIRM_BODY_MAX_CHARS = 300;
+
+/** 按钮文案上限(按钮就那么宽;超长会挤坏弹窗版式)。 */
+export const GHOST_CONFIRM_BUTTON_MAX_CHARS = 12;
+
+/** 同一意识两次确认请求的最小间隔 ms(按尝试记账,与 pick 槽同量级)。 */
+export const GHOST_CONFIRM_MIN_INTERVAL_MS = 3000;
+
+/**
+ * 无人应答的兜底超时 ms:到点当「没同意」。
+ * 90 秒是刻意选的——小于插件面板侧常用的 180 秒请求超时,好让面板拿到一个干净的
+ * "用户没答应"而不是自己先超时、留下一个语义不明的悬空请求。
+ */
+export const GHOST_CONFIRM_TIMEOUT_MS = 90_000;
+
/** cindy 槽代办的质量档位:意识只表达"要多好",具体模型由主机解析表决定。 */
export const GHOST_MODEL_TIERS = ['draft', 'standard', 'best'] as const;
export type GhostModelTier = (typeof GHOST_MODEL_TIERS)[number];
diff --git a/docs/dev-rules/plugin-security-and-authoring.md b/docs/dev-rules/plugin-security-and-authoring.md
index c0edf8387f..4025d63466 100644
--- a/docs/dev-rules/plugin-security-and-authoring.md
+++ b/docs/dev-rules/plugin-security-and-authoring.md
@@ -28,7 +28,7 @@
| 身份卡字段与校验、管子协议类型 | `apps/desktop/src/shared/ghost.ts`(`validateGhostManifest`、`cindy.send` / `cindy.onHostMessage` 类型) |
| 打包限制 | `apps/desktop/src/main/cindy-brain/forge.ts` 的 `packGhostDir` |
| 运行时、沙箱进程与生命周期 | `apps/desktop/src/main/cindy-brain/runtime/GhostRuntime.ts`、`GhostManager.ts` |
-| 能力 slot(网络/通知/文件系统/技能/宿主等) | `apps/desktop/src/main/cindy-brain/networkSlot.ts`、`notifySlot.ts`、`fsSlot.ts`、`cindySlot.ts`、`skillSlot.ts`、`agentSlot.ts`、`errandSlot.ts`(派活执行链在 `maker-ipc/ghostErrandRunner.ts`,每插件配置在 `errandPrefsStore.ts`) |
+| 能力 slot(网络/通知/确认/文件系统/技能/宿主等) | `apps/desktop/src/main/cindy-brain/networkSlot.ts`、`notifySlot.ts`、`confirmSlot.ts`(往返桥 `ghostConfirmDialogBridge.ts`,renderer 落地 `cindy-brain/GhostConfirmDialogHost.tsx`)、`fsSlot.ts`、`cindySlot.ts`、`skillSlot.ts`、`agentSlot.ts`、`errandSlot.ts`(派活执行链在 `maker-ipc/ghostErrandRunner.ts`,每插件配置在 `errandPrefsStore.ts`) |
| 面板供片、注入主题 token 与协议 | `apps/desktop/src/renderer/cindy-brain/ghostPanelTheme.ts`、`cindy-ghost://` 分支 |
| 权限注入/更新确认 UI | `apps/desktop/src/renderer/cindy-brain/GhostPermissionList.tsx` |
| 远程/手机版能力准入白名单 | `packages/device-link/src/allowlist.ts` |