Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
feat(desktop): 保留前缀闸支持 dev 复现 packaged 行为
fmfsaisai91298b5797b5
diff --git a/apps/desktop/src/main/cindy-brain/__tests__/reservedGhostIdGate.test.ts b/apps/desktop/src/main/cindy-brain/__tests__/reservedGhostIdGate.test.tsnew file mode 100644index 0000000000..9896112609--- /dev/null+++ b/apps/desktop/src/main/cindy-brain/__tests__/reservedGhostIdGate.test.ts@@ -0,0 +1,52 @@+import { describe, expect, it } from 'vitest';++import {+ GHOST_RESERVED_PREFIX_GATE_ENV,+ shouldRejectReservedGhostIds,+} from '../reservedGhostIdGate.js';++describe('shouldRejectReservedGhostIds', () => {+ it('does not enable the reserved-prefix gate in dev by default', () => {+ expect(shouldRejectReservedGhostIds(false, undefined)).toBe(false);+ });++ it('enables the reserved-prefix gate in dev for the exact value 1', () => {+ expect(shouldRejectReservedGhostIds(false, '1')).toBe(true);+ });++ // Prevents Boolean(envValue); ` 1`/`1 ` pin the left/right boundaries of exact `1`.+ it.each(['0', '', 'true', 'anything', '01', ' 1', '1 '])(+ 'does not enable the dev gate for non-1 value %j',+ (envValue) => {+ expect(shouldRejectReservedGhostIds(false, envValue)).toBe(false);+ },+ );++ it('keeps the reserved-prefix gate enabled in packaged builds by default', () => {+ expect(shouldRejectReservedGhostIds(true, undefined)).toBe(true);+ });++ // Including `1` prevents XOR: packaged !== (envValue === '1') would open production here.+ it.each(['1', '0', '', 'anything', 'true'])(+ 'cannot disable the packaged reserved-prefix gate with %j',+ (envValue) => {+ expect(shouldRejectReservedGhostIds(true, envValue)).toBe(true);+ },+ );++ it('reads the environment on every call when no explicit value is supplied', () => {+ const original = process.env[GHOST_RESERVED_PREFIX_GATE_ENV];+ try {+ // This sequence prevents a module-load snapshot from masquerading as a live override.+ delete process.env[GHOST_RESERVED_PREFIX_GATE_ENV];+ expect(shouldRejectReservedGhostIds(false)).toBe(false);+ process.env[GHOST_RESERVED_PREFIX_GATE_ENV] = '1';+ expect(shouldRejectReservedGhostIds(false)).toBe(true);+ process.env[GHOST_RESERVED_PREFIX_GATE_ENV] = '0';+ expect(shouldRejectReservedGhostIds(false)).toBe(false);+ } finally {+ if (original === undefined) delete process.env[GHOST_RESERVED_PREFIX_GATE_ENV];+ else process.env[GHOST_RESERVED_PREFIX_GATE_ENV] = original;+ }+ });+});diff --git a/apps/desktop/src/main/cindy-brain/index.ts b/apps/desktop/src/main/cindy-brain/index.tsindex e9b65107d6..f3c278759c 100644--- a/apps/desktop/src/main/cindy-brain/index.ts+++ b/apps/desktop/src/main/cindy-brain/index.ts@@ -80,6 +80,7 @@ import {import { exportGhostPackage } from './exportGhostPackage.js';import { GhostMutationCoordinator } from './ghostMutationCoordinator.js';import { createOneShotTicketStore } from './oneShotTickets.js';+import { shouldRejectReservedGhostIds } from './reservedGhostIdGate.js';import {bindForgePackStagingTempDir,getForgePackStagingControllerIfConfigured,@@ -681,7 +682,7 @@ function getLegacyGhostRecoveryStatusForActiveSession(): LegacyGhostRecoveryStatisAppSessionBoundaryPending(),{reservedCommands: reservedBuiltinCommands,- rejectReservedIds: app.isPackaged,+ rejectReservedIds: shouldRejectReservedGhostIds(app.isPackaged),},);}@@ -798,7 +799,7 @@ async function retryLegacyGhostRecoveryForActiveSession(): Promise<LegacyGhostRe{shouldAbort,reservedCommands: reservedBuiltinCommands,- rejectReservedIds: app.isPackaged,+ rejectReservedIds: shouldRejectReservedGhostIds(app.isPackaged),},);} catch (error) {@@ -5214,10 +5215,11 @@ export function getGhostLibraryBindingStore(): LibraryBindingStore {/*** 官方保留前缀守门(docs/dev-rules/plugin-security-and-authoring.md):packaged 版本上,用户装入* 通道(install/update/inspect 三个 IPC,即拖入/选文件/forge 转交的共同出口)- * 对 `cindy-` 前缀 id 一律拒装——卸载内置意识后抢注同 id 的第三方包,会冒充- * 官方身份并蹭走凭证别名(用户历史填过的机器级 key 被注入攻击者白名单域名)。- * dev 构建豁免:内置意识(cindy-art / cindy-web-search)的开发迭代靠打包重装。- * 官方预装(builtinGhostProvisioner)走内部安装路径,不经这些 IPC。+ * 对 `cindy-` / `filo-` / `xd-` 前缀 id 一律拒装——卸载内置意识后抢注同 id 的+ * 第三方包,会冒充官方身份并蹭走凭证别名(用户历史填过的机器级 key 被注入攻击者白名单域名)。+ * dev 构建默认豁免:方便 `cindy-` / `filo-` / `xd-` 官方前缀插件在本地迭代;需要复现+ * packaged 行为时可设置 `XDT_GHOST_RESERVED_PREFIX_GATE=1`,此开关只能收紧、不能放宽。+ * 若恢复随包 seed,builtinGhostProvisioner 的内部安装路径不经这些 IPC;不要把本闸套到播种路径。*/function rejectReservedPublisherSlug(id: string): void {if (!isReservedConnectionPluginSlug(id)) return;@@ -5230,9 +5232,10 @@ function rejectReservedPublisherSlug(id: string): void {function rejectReservedGhostId(id: string): void {// Member-publisher identity slugs are never installable, including market// packages and unpackaged dev builds. Official prefix rejection stays- // packaged-only so first-party iteration can still reload cindy-/xd- plugins.+ // packaged-only by default so first-party iteration can still reload cindy-/filo-/xd- plugins.+ // The hidden dev override can reproduce the packaged gate but can never disable it.rejectReservedPublisherSlug(id);- if (!app.isPackaged) return;+ if (!shouldRejectReservedGhostIds(app.isPackaged)) return;if (!isUserInstallReservedGhostId(id)) return;throwIpcError('GHOST_ID_RESERVED',diff --git a/apps/desktop/src/main/cindy-brain/reservedGhostIdGate.ts b/apps/desktop/src/main/cindy-brain/reservedGhostIdGate.tsnew file mode 100644index 0000000000..b303b1da9d--- /dev/null+++ b/apps/desktop/src/main/cindy-brain/reservedGhostIdGate.ts@@ -0,0 +1,15 @@+/**+ * Hidden development override for reproducing the packaged reserved-prefix gate.+ *+ * Schema: only the exact value `1` enables the gate in an unpackaged build.+ * Packaged builds always keep the gate enabled; the override can only tighten+ * development behavior and can never weaken production behavior.+ */+export const GHOST_RESERVED_PREFIX_GATE_ENV = 'XDT_GHOST_RESERVED_PREFIX_GATE';++export function shouldRejectReservedGhostIds(+ isPackaged: boolean,+ envValue = process.env[GHOST_RESERVED_PREFIX_GATE_ENV],+): boolean {+ return isPackaged || envValue === '1';+}