Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
feat(desktop): 插件安装移除 Node 原生二次确认弹窗 (#333)
Lizida184a405f64
diff --git a/apps/desktop/src/main/agent-island/__tests__/service.test.ts b/apps/desktop/src/main/agent-island/__tests__/service.test.tsindex 5c118765ab..69a38da7e1 100644--- a/apps/desktop/src/main/agent-island/__tests__/service.test.ts+++ b/apps/desktop/src/main/agent-island/__tests__/service.test.ts@@ -1,3 +1,6 @@+import { homedir } from 'node:os';+import path from 'node:path';+import { beforeEach, describe, expect, it, vi } from 'vitest';import type { BrowserWindow } from 'electron';import { SESSION_ACTIVITY_CHANNEL } from '@cindy/device-link';@@ -25,6 +28,11 @@ import type { AgentIslandService } from '../service.js';const REMOTE_DAEMON_CLOSED_REASON = 'remote_daemon_closed';+// 受保护目录检测按 path.join(homedir(), ...) 的字面量匹配;测试消息必须用同一+// 拼法,否则在 Windows 开发机上分隔符对不上,darwin mock 下的用例会失真。+const protectedFolderFile = (kind: 'Desktop' | 'Documents', file: string): string =>+ path.join(homedir(), kind, file);+function handleInteractionRequestForTest(service: AgentIslandService,meta: Parameters<AgentIslandService['handleInteractionRequest']>[0],@@ -1483,7 +1491,7 @@ describe('AgentIslandService native publishing', () => {source: 'claude-code',data: {toolUseId: 'tool-1',- fullText: `EPERM: operation not permitted, open '${process.env.HOME}/Desktop/blocked.txt'`,+ fullText: `EPERM: operation not permitted, open '${protectedFolderFile('Desktop', 'blocked.txt')}'`,},};@@ -1523,7 +1531,7 @@ describe('AgentIslandService native publishing', () => {source: 'claude-code',data: {toolUseId: 'tool-1',- fullText: `EPERM: operation not permitted, open '${process.env.HOME}/Documents/blocked.txt'`,+ fullText: `EPERM: operation not permitted, open '${protectedFolderFile('Documents', 'blocked.txt')}'`,isError: true,},},@@ -1557,7 +1565,7 @@ describe('AgentIslandService native publishing', () => {source: 'codex',data: {toolUseId: 'tool-1',- fullText: `Log excerpt: EPERM under '${process.env.HOME}/Desktop/blocked.txt'`,+ fullText: `Log excerpt: EPERM under '${protectedFolderFile('Desktop', 'blocked.txt')}'`,isError: false,},},@@ -1587,7 +1595,7 @@ describe('AgentIslandService native publishing', () => {source: 'claude-code',data: {toolUseId: 'tool-1',- fullText: `EPERM: operation not permitted, open '${process.env.HOME}/Desktop/blocked.txt'`,+ fullText: `EPERM: operation not permitted, open '${protectedFolderFile('Desktop', 'blocked.txt')}'`,isError: true,},},diff --git a/apps/desktop/src/main/cindy-brain/__tests__/nodeInstallAuthorization.test.ts b/apps/desktop/src/main/cindy-brain/__tests__/nodeInstallAuthorization.test.tsdeleted file mode 100644index 041d5abc30..0000000000--- a/apps/desktop/src/main/cindy-brain/__tests__/nodeInstallAuthorization.test.ts+++ /dev/null@@ -1,79 +0,0 @@-/** nodeInstallAuthorization.test — Node 真授权必须由 Main 原生系统弹窗取得。 */--import { beforeEach, describe, expect, it, vi } from 'vitest';--const electronMocks = vi.hoisted(() => ({- fromWebContents: vi.fn(),- showMessageBox: vi.fn(),- getPreferredSystemLanguages: vi.fn(() => ['en-US']),- getLocale: vi.fn(() => 'en-US'),-}));--vi.mock('electron', () => ({- app: {- getPreferredSystemLanguages: electronMocks.getPreferredSystemLanguages,- getLocale: electronMocks.getLocale,- },- BrowserWindow: { fromWebContents: electronMocks.fromWebContents },- dialog: { showMessageBox: electronMocks.showMessageBox },-}));--import type { GhostManifest } from '../../../shared/ghost';-import {- buildNodeInstallDialogOptions,- requestNodeInstallAuthorization,-} from '../nodeInstallAuthorization';--const nodeManifest = {- schemaVersion: 2,- id: 'node-ghost',- name: 'Node Ghost',- version: '1.0.0',- kind: 'chip',- entry: 'main.js',- slots: ['node'],- node: { entry: 'node/worker.cjs', protocol: 'json-rpc-stdio' },-} as GhostManifest;--beforeEach(() => {- vi.clearAllMocks();- electronMocks.fromWebContents.mockReturnValue({ isDestroyed: () => false });- electronMocks.showMessageBox.mockResolvedValue({ response: 0 });-});--describe('nodeInstallAuthorization', () => {- it('原生弹窗明确说明本机权限,并默认停在取消', () => {- const options = buildNodeInstallDialogOptions(nodeManifest, 'install');- expect(options.type).toBe('warning');- expect(options.detail).toContain('Node Ghost · v1.0.0');- expect(options.detail).toContain('same local permissions as your user account');- expect(options.defaultId).toBe(1);- expect(options.cancelId).toBe(1);- expect(options.noLink).toBe(true);- });-- it('用户点继续才授权;点取消返回 false', async () => {- const sender = {} as never;- await expect(requestNodeInstallAuthorization(sender, nodeManifest, 'install')).resolves.toBe(- true,- );- electronMocks.showMessageBox.mockResolvedValueOnce({ response: 1 });- await expect(requestNodeInstallAuthorization(sender, nodeManifest, 'update')).resolves.toBe(- false,- );- expect(electronMocks.showMessageBox).toHaveBeenCalledTimes(2);- });-- it('普通沙箱插件不弹 Node 提示;找不到所属窗口时 Node 授权失败关闭', async () => {- const sender = {} as never;- const plain = { ...nodeManifest, slots: ['card'], node: undefined } as GhostManifest;- await expect(requestNodeInstallAuthorization(sender, plain, 'install')).resolves.toBe(true);- expect(electronMocks.showMessageBox).not.toHaveBeenCalled();-- electronMocks.fromWebContents.mockReturnValueOnce(null);- await expect(requestNodeInstallAuthorization(sender, nodeManifest, 'install')).resolves.toBe(- false,- );- expect(electronMocks.showMessageBox).not.toHaveBeenCalled();- });-});diff --git a/apps/desktop/src/main/cindy-brain/index.ts b/apps/desktop/src/main/cindy-brain/index.tsindex e7ef595737..676fb21f37 100644--- a/apps/desktop/src/main/cindy-brain/index.ts+++ b/apps/desktop/src/main/cindy-brain/index.ts@@ -65,7 +65,6 @@ import { reclaimLoopbackPort } from './portReclaim.js';import { GhostConnectionManager } from './ghostConnections.js';import { t } from '../i18n.js';import { assertTrustedAppRendererEvent } from '../security/trustedAppRenderer.js';-import { requestNodeInstallAuthorization } from './nodeInstallAuthorization.js';import {FILO_GOOGLE_GHOST_ID,migrateFiloGoogleAccounts,@@ -2537,9 +2536,8 @@ export function registerGhostIpc(): void {}rejectReservedGhostId(probe.manifest.id);rejectUnauthorizedTokenBroker(probe.manifest);- if (!(await requestNodeInstallAuthorization(event.sender, probe.manifest, 'install'))) {- return { canceled: true };- }+ // Node 高风险提示在 renderer 装入确认卡的权限清单里如实展示;+ // 2026-07-24 Lizi 定案:不再追加 Main 原生二次确认弹窗。const enable = installOpts.enable === true;return {ghost: await installAndDock(manager, lizFilePath, {@@ -2572,9 +2570,6 @@ export function registerGhostIpc(): void {}rejectReservedGhostId(inspected.manifest.id);rejectUnauthorizedTokenBroker(inspected.manifest);- if (!(await requestNodeInstallAuthorization(event.sender, inspected.manifest, 'update'))) {- return { canceled: true };- }const previousGhost = manager.list().find((g) => g.manifest.id === inspected.manifest.id);runtime.stop(inspected.manifest.id);getGhostNodeRuntimeBroker().stop(inspected.manifest.id);diff --git a/apps/desktop/src/main/cindy-brain/nodeInstallAuthorization.ts b/apps/desktop/src/main/cindy-brain/nodeInstallAuthorization.tsdeleted file mode 100644index 7a8a9e6baf..0000000000--- a/apps/desktop/src/main/cindy-brain/nodeInstallAuthorization.ts+++ /dev/null@@ -1,57 +0,0 @@-/**- * Node 插件安装授权 — Main 进程原生系统弹窗。- *- * Renderer 的权限清单负责解释插件申请了什么;真正允许本机 Node 代码进入- * 安装目录的第二次确认必须由 Main 自己弹出,不能让被 XSS 控制的 Renderer- * 伪造“用户已经同意”。取消只返回 false,不安装、不更新任何文件。- */--import { BrowserWindow, dialog, type MessageBoxOptions, type WebContents } from 'electron';--import type { GhostManifest } from '../../shared/ghost.js';-import { t } from '../i18n.js';--export type NodeInstallOperation = 'install' | 'update';--/** 生成原生弹窗内容;插件名字与版本只作为纯文本展示。 */-export function buildNodeInstallDialogOptions(- manifest: GhostManifest,- operation: NodeInstallOperation,-): MessageBoxOptions {- return {- type: 'warning',- title: t('settings.ghosts.installConfirm.nodeRiskTitle'),- message: t('settings.ghosts.installConfirm.nodeRiskTitle'),- detail: `${manifest.name} · v${manifest.version}\n\n${t(- 'settings.ghosts.installConfirm.nodeRiskDescription',- )}`,- buttons: [- t('settings.ghosts.installConfirm.nodeRiskConfirm'),- operation === 'update'- ? t('settings.ghosts.updateConfirm.cancel')- : t('settings.ghosts.installConfirm.nodeRiskCancel'),- ],- defaultId: 1,- cancelId: 1,- noLink: true,- };-}--/**- * Node 清单需要原生二次确认;普通浏览器沙箱插件直接通过。- * 找不到所属 Cindy 窗口时失败关闭,绝不退化成无父窗口的宽松授权。- */-export async function requestNodeInstallAuthorization(- sender: WebContents,- manifest: GhostManifest,- operation: NodeInstallOperation,-): Promise<boolean> {- if (!manifest.node) return true;- const win = BrowserWindow.fromWebContents(sender);- if (!win || win.isDestroyed()) return false;- const { response } = await dialog.showMessageBox(- win,- buildNodeInstallDialogOptions(manifest, operation),- );- return response === 0;-}diff --git a/apps/desktop/src/main/cindy-brain/nodeRuntimeWorkerProcess.ts b/apps/desktop/src/main/cindy-brain/nodeRuntimeWorkerProcess.tsindex 4aeb29d32d..e1600bf8d2 100644--- a/apps/desktop/src/main/cindy-brain/nodeRuntimeWorkerProcess.ts+++ b/apps/desktop/src/main/cindy-brain/nodeRuntimeWorkerProcess.ts@@ -17,7 +17,8 @@* [node, entryPath, ...args],让 Maker 这类库以为自己被 node 正常启动。** 插件代码拥有当前系统用户级本机权限。这里提供的是进程隔离与通信收口,不是- * OS 沙箱;安装时的主机原生二次确认仍是授权边界。+ * OS 沙箱;授权入口是装入确认卡的权限清单(2026-07-24 起不再有 Main 原生+ * 二次确认弹窗)。*/import { EventEmitter } from 'node:events';diff --git a/apps/desktop/src/preload/preload.ts b/apps/desktop/src/preload/preload.tsindex e468dd9b66..6f34a4f4d7 100644--- a/apps/desktop/src/preload/preload.ts+++ b/apps/desktop/src/preload/preload.ts@@ -769,12 +769,12 @@ contextBridge.exposeInMainWorld('electronAPI', {install: (lizFilePath: string,opts: { enable?: boolean; expectedPackageSha256: string },- ): Promise<{ ghost: unknown } | { canceled: true }> =>+ ): Promise<{ ghost: unknown }> =>ipcRenderer.invoke('ghosts:install', lizFilePath, opts),update: (lizFilePath: string,opts: { expectedPackageSha256: string },- ): Promise<{ ghost: unknown } | { canceled: true }> =>+ ): Promise<{ ghost: unknown }> =>ipcRenderer.invoke('ghosts:update', lizFilePath, opts),cindyPrefsSync: (id: string,diff --git a/apps/desktop/src/renderer/cindy-brain/__tests__/installFlow.test.tsx b/apps/desktop/src/renderer/cindy-brain/__tests__/installFlow.test.tsxindex 7138dabc5e..59f9847df8 100644--- a/apps/desktop/src/renderer/cindy-brain/__tests__/installFlow.test.tsx+++ b/apps/desktop/src/renderer/cindy-brain/__tests__/installFlow.test.tsx@@ -1,4 +1,4 @@-/** installFlow.test — Renderer 只展示权限清单,Node 真授权由 Main 原生弹窗负责。 */+/** installFlow.test — 装入确认卡权限清单确认后直接交给 Main 落盘(无二次弹窗)。 */import { afterEach, describe, expect, it, vi } from 'vitest';@@ -22,7 +22,7 @@ const baseManifest = {function setupWindow(manifest: object,- installResult: { ghost: { manifest: object } } | { canceled: true } = { ghost: { manifest } },+ installResult: { ghost: { manifest: object } } = { ghost: { manifest } },) {const install = vi.fn(async () => installResult);const electronAPI = {@@ -62,31 +62,21 @@ afterEach(() => {Reflect.deleteProperty(globalThis, 'window');});-describe('installFlow · Node 原生确认交接', () => {- it('Main 原生风险提示取消时,不显示安装完成提示', async () => {- const { install } = setupWindow(baseManifest, { canceled: true });- const confirm = vi.fn(async () => true);-- await confirmAndInstallGhost('/tmp/node.cindy', deps(confirm));-- expect(confirm).not.toHaveBeenCalled();- expect(install).toHaveBeenCalledTimes(1);- expect(toast.success).not.toHaveBeenCalled();- expect(toast.error).not.toHaveBeenCalled();- });-- it('Renderer 权限清单确认后把 Node 安装交给 Main', async () => {+describe('installFlow · 装入确认', () => {+ it('Renderer 权限清单确认后把 Node 插件安装交给 Main,并提示装入完成', async () => {const { install } = setupWindow(baseManifest);const confirm = vi.fn(async () => true);await confirmAndInstallGhost('/tmp/node.cindy', deps(confirm));- // confirmWithCheckbox 是第一层权限清单;普通 confirm 不再伪装成安全边界。+ // confirmWithCheckbox 是唯一确认层(权限清单含 Node 高风险行);+ // 普通 confirm 不再伪装成安全边界。expect(confirm).not.toHaveBeenCalled();expect(install).toHaveBeenCalledWith('/tmp/node.cindy', {enable: false,expectedPackageSha256: 'a'.repeat(64),});+ expect(toast.success).toHaveBeenCalledTimes(1);});it('普通浏览器沙箱插件同样只走现有权限清单', async () => {diff --git a/apps/desktop/src/renderer/cindy-brain/ghostDevTools.ts b/apps/desktop/src/renderer/cindy-brain/ghostDevTools.tsindex 59fb8289b1..8102074886 100644--- a/apps/desktop/src/renderer/cindy-brain/ghostDevTools.ts+++ b/apps/desktop/src/renderer/cindy-brain/ghostDevTools.ts@@ -48,7 +48,6 @@ export function installGhostDevTools(): void {const result = await window.electronAPI.ghosts.install(lizFilePath, {expectedPackageSha256: inspected.packageSha256,});- if ('canceled' in result) throw new Error('用户取消了 Node 安全确认');return result.ghost;},uninstall: async (id: string) => {diff --git a/apps/desktop/src/renderer/cindy-brain/installFlow.tsx b/apps/desktop/src/renderer/cindy-brain/installFlow.tsxindex d2d5d33077..41d49bdba6 100644--- a/apps/desktop/src/renderer/cindy-brain/installFlow.tsx+++ b/apps/desktop/src/renderer/cindy-brain/installFlow.tsx@@ -19,7 +19,8 @@ import { ghostInstallErrorKey } from './installErrorKey';/*** 装入/更新意识的统一编排:inspect(验明正身)→ Renderer 权限清单 →- * install / update。若含 Node,Main 会在真正写盘前再弹一次系统安全确认。+ * install / update。Node 高风险条目在权限清单里如实展示+ * (2026-07-24 起不再有 Main 原生二次确认弹窗)。** 「装意识前弹确认」是 README 定下的安全原则:确认框展示的是**意识自称的身份*** (名字/版本/形态/是否带面板),不是文件名 —— 文件名可以随便改,身份卡不会陪它演。@@ -103,12 +104,9 @@ async function confirmAndRunUpdate(});if (!ok) return;try {- const result = await window.electronAPI.ghosts.update(lizFilePath, {+ const { ghost } = await window.electronAPI.ghosts.update(lizFilePath, {expectedPackageSha256: packageSha256,});- // Node 的 Main 原生安全确认取消属于正常返回,不显示错误或成功提示。- if ('canceled' in result) return;- const { ghost } = result;toast.success(t('settings.ghosts.toast.updated', {name: ghost.manifest.name,@@ -177,14 +175,13 @@ export async function confirmAndInstallGhost(});if (!ok) return;- // 3) 真装(main 侧同一主体:来源校验 + Node 原生确认 + 落盘 + 停靠)。+ // 3) 真装(main 侧同一主体:来源校验 + 落盘 + 停靠)。Node 高风险提示+ // 已在上面的权限清单里如实展示,不再有 Main 原生二次确认。try {- const result = await window.electronAPI.ghosts.install(lizFilePath, {+ const { ghost } = await window.electronAPI.ghosts.install(lizFilePath, {enable,expectedPackageSha256: packageSha256,});- if ('canceled' in result) return;- const { ghost } = result;toast.success(enable? t('settings.ghosts.toast.installed', { name: ghost.manifest.name })diff --git a/apps/desktop/src/renderer/i18n/locales/en/common.json b/apps/desktop/src/renderer/i18n/locales/en/common.jsonindex ca209319c9..44c1b175e7 100644--- a/apps/desktop/src/renderer/i18n/locales/en/common.json+++ b/apps/desktop/src/renderer/i18n/locales/en/common.json@@ -2269,11 +2269,7 @@"metaWithAuthor": "By {{author}} · Version {{version}}. Installs locally and can be uninstalled anytime.","enableNow": "Enable right after install","expandDescription": "Show Full Description",- "collapseDescription": "Hide Full Description",- "nodeRiskTitle": "Allow a local Node program to run?",- "nodeRiskDescription": "This is high risk. The plugin's Node program has the same local permissions as your user account: it can read or change accessible files, use the network, and start other programs. The browser sandbox cannot contain it. Install only plugins from sources you trust.",- "nodeRiskConfirm": "I understand, continue",- "nodeRiskCancel": "Cancel installation"+ "collapseDescription": "Hide Full Description"},"trust": {"official": "Official Cindy plugin",diff --git a/apps/desktop/src/renderer/i18n/locales/ja/common.json b/apps/desktop/src/renderer/i18n/locales/ja/common.jsonindex 3eab9e69ae..728a925c5a 100644--- a/apps/desktop/src/renderer/i18n/locales/ja/common.json+++ b/apps/desktop/src/renderer/i18n/locales/ja/common.json@@ -2268,11 +2268,7 @@"metaWithAuthor": "作者 {{author}} · バージョン {{version}}。ローカルにインストールされ、いつでもアンインストールできます。","enableNow": "インストール後すぐに有効化","expandDescription": "紹介全文を表示",- "collapseDescription": "紹介を折りたたむ",- "nodeRiskTitle": "ローカル Node プログラムの実行を許可しますか?",- "nodeRiskDescription": "これは高リスクな権限です。プラグインの Node プログラムはあなたのユーザーアカウントと同じローカル権限を持ち、アクセス可能なファイルの読み書き、ネットワーク利用、他のプログラムの起動ができます。ブラウザーサンドボックスでは隔離できません。信頼できる配布元のプラグインだけをインストールしてください。",- "nodeRiskConfirm": "リスクを理解して続行",- "nodeRiskCancel": "インストールを中止"+ "collapseDescription": "紹介を折りたたむ"},"trust": {"official": "Cindy 公式プラグイン",diff --git a/apps/desktop/src/renderer/i18n/locales/ko/common.json b/apps/desktop/src/renderer/i18n/locales/ko/common.jsonindex db463017a5..69ab466fe9 100644--- a/apps/desktop/src/renderer/i18n/locales/ko/common.json+++ b/apps/desktop/src/renderer/i18n/locales/ko/common.json@@ -2268,11 +2268,7 @@"metaWithAuthor": "제작자 {{author}} · 버전 {{version}}. 로컬에 설치되며 언제든 제거할 수 있습니다.","enableNow": "설치 후 바로 활성화","expandDescription": "전체 소개 보기",- "collapseDescription": "소개 접기",- "nodeRiskTitle": "로컬 Node 프로그램 실행을 허용할까요?",- "nodeRiskDescription": "고위험 권한입니다. 플러그인의 Node 프로그램은 사용자 계정과 같은 로컬 권한으로 접근 가능한 파일을 읽거나 바꾸고, 네트워크를 사용하며, 다른 프로그램을 시작할 수 있습니다. 브라우저 샌드박스로 격리할 수 없습니다. 신뢰하는 출처의 플러그인만 설치하세요.",- "nodeRiskConfirm": "위험을 이해하고 계속",- "nodeRiskCancel": "설치 취소"+ "collapseDescription": "소개 접기"},"trust": {"official": "Cindy 공식 플러그인",diff --git a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.jsonindex 6d443ff603..a1ac65c0e8 100644--- a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json+++ b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json@@ -2268,11 +2268,7 @@"metaWithAuthor": "作者 {{author}} · 版本 {{version}}。将安装到本机,可随时卸载。","enableNow": "安装后立即生效","expandDescription": "展开完整介绍",- "collapseDescription": "收起介绍",- "nodeRiskTitle": "确认运行本机 Node 程序?",- "nodeRiskDescription": "这是高风险能力。这个插件里的 Node 程序拥有与你当前账号相同的本机权限:能读写你有权访问的文件、访问网络、启动其它程序。浏览器沙箱挡不住它。只安装你信任来源的插件。",- "nodeRiskConfirm": "我明白风险,继续",- "nodeRiskCancel": "取消安装"+ "collapseDescription": "收起介绍"},"trust": {"official": "Cindy 官方插件",diff --git a/apps/desktop/src/renderer/vite-env.d.ts b/apps/desktop/src/renderer/vite-env.d.tsindex 9eeb8b95b9..017c61803c 100644--- a/apps/desktop/src/renderer/vite-env.d.ts+++ b/apps/desktop/src/renderer/vite-env.d.ts@@ -1017,12 +1017,12 @@ interface ElectronAPI {lizFilePath: string,/** enable:装入后立即开启(确认框勾选决定;缺省沉睡)。 */opts: { enable?: boolean; expectedPackageSha256: string },- ) => Promise<{ ghost: import('../shared/ghost').InstalledGhost } | { canceled: true }>;+ ) => Promise<{ ghost: import('../shared/ghost').InstalledGhost }>;/** 原位更新(同 id 换版):唤醒状态与面板位置延续,沙箱熄灯待重拉。 */update: (lizFilePath: string,opts: { expectedPackageSha256: string },- ) => Promise<{ ghost: import('../shared/ghost').InstalledGhost } | { canceled: true }>;+ ) => Promise<{ ghost: import('../shared/ghost').InstalledGhost }>;/*** cindy 槽后端覆盖:首帧同步读(规则 7);overrides 键为 "image.generate"* 等能力键;image/video 各一份下拉数据,defaultModel = 目录默认