Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
refactor(plugins): 删除无效权限扫描并清理提审临时包
liugaoweie175780944c9
diff --git a/apps/desktop/src/main/plugin-contributions/__tests__/prepared.test.ts b/apps/desktop/src/main/plugin-contributions/__tests__/prepared.test.tsindex 7da7195048..bf14668410 100644--- a/apps/desktop/src/main/plugin-contributions/__tests__/prepared.test.ts+++ b/apps/desktop/src/main/plugin-contributions/__tests__/prepared.test.ts@@ -11,10 +11,14 @@ const harness = vi.hoisted(() => ({generation: 1,ghosts: [] as InstalledGhost[],ledger: null as { scope: string; organizationId: string | null; source?: string; installed?: boolean } | null,+ quit: null as (() => void | Promise<void>) | null,snapshot: vi.fn(),inspect: vi.fn(),}));vi.mock('electron', () => ({ app: { getPath: () => harness.root } }));+vi.mock('../../lifecycle', () => ({+ onQuit: (_name: string, callback: () => void | Promise<void>) => { harness.quit = callback; },+}));vi.mock('../../appSessionState', () => ({activeOwnerScopeKey: () => `owner:${harness.generation}`,getActiveAppSession: () => ({ mode: 'cloud', dataOwnerId: 'owner' }),@@ -164,6 +168,20 @@ it('gives concurrent preview callers independent ownership', async () => {expect(prepared.getPreparedContribution(second.preparedId).summary).toEqual(second);});+// unit:真实 prepare 生成文件后执行宿主退出回调;原 TTL 用例漏掉正常退出前不触发定时器的场景。+// 最小输入:一个预览和一个已接管快照;退出后两份包与内存条目均应释放。+it('releases both preview and operation-owned package bytes on normal quit', async () => {+ const first = await prepared.prepareInstalledContribution('hello');+ const second = await prepared.prepareInstalledContribution('hello');+ const entry = prepared.getPreparedContribution(second.preparedId);+ entry.pinned = true;+ expect(harness.quit).toBeTypeOf('function');+ await harness.quit!();+ expect(() => prepared.getPreparedContribution(first.preparedId)).toThrow('PRECONDITION_FAILED');+ expect(() => prepared.getPreparedContribution(second.preparedId)).toThrow('PRECONDITION_FAILED');+ expect(await fsp.readdir(harness.root)).toEqual([]);+});+it('keeps operation-owned packages without consuming the eight preview slots', async () => {const ids: string[] = [];try {diff --git a/apps/desktop/src/main/plugin-contributions/prepared.ts b/apps/desktop/src/main/plugin-contributions/prepared.tsindex 2c2595acff..461085be93 100644--- a/apps/desktop/src/main/plugin-contributions/prepared.ts+++ b/apps/desktop/src/main/plugin-contributions/prepared.ts@@ -20,6 +20,7 @@ import { getAuthState, getActiveAuthRealm } from '../authManager.js';import { getGhostManager } from '../cindy-brain/index.js';import { snapshotInstalledGhostPackage } from '../cindy-brain/exportGhostPackage.js';import { PluginMarketLedger } from '../plugin-market/ledger.js';+import { onQuit } from '../lifecycle.js';import { throwIpcError } from '../utils/ipcValidate.js';export function contributionAccountKey(): string {@@ -242,3 +243,7 @@ export async function releasePreparedContribution(preparedId: string): Promise<ventries.delete(preparedId);await fs.rm(entry.directory, { recursive: true, force: true }).catch(() => undefined);}++onQuit('plugin-contribution-previews', async () => {+ await Promise.all([...entries.keys()].map(releasePreparedContribution));+}, 'async');diff --git a/apps/desktop/src/renderer/features/plugin/GhostPluginPage.tsx b/apps/desktop/src/renderer/features/plugin/GhostPluginPage.tsxindex 39321d4078..c056d384d8 100644--- a/apps/desktop/src/renderer/features/plugin/GhostPluginPage.tsx+++ b/apps/desktop/src/renderer/features/plugin/GhostPluginPage.tsx@@ -6,7 +6,6 @@ import { useSignInToCindy } from '@/hooks/useSignInToCindy';import { rememberContributionIntent, consumeContributionIntent, matchesContributionIntent } from './lib/contributionIntent';import { MyPluginsPage, contributionErrorKey, type MyPluginsPageCache, type PluginSubmitOptions } from './MyPluginsPage';import { localPublishingUnavailableKey } from './lib/ghostPluginDetailModel';-import { usePublishingInstallations } from './lib/usePublishingInstallations';import type { MyPluginView } from '../../../shared/pluginContributions';import { featureRetirementById } from '../../../shared/featureRetirements';import { RetiredFeatureDetail } from './RetiredFeatureDetail';@@ -541,9 +540,6 @@ function LocalGhostPluginPage({const showEnterprise = user?.membershipKind === 'org';const personalContributor = mode === 'cloud' && user?.membershipKind === 'personal';const ghosts = useInstalledGhosts();- const publishingInstallations = usePublishingInstallations(contributionOwner, personalContributor, ghosts);- const canSubmitMarketInstallation = (ghost: InstalledGhost) => publishingInstallations.some(plugin =>- plugin.localInstanceId === installedGhostStoragePart(ghost) && plugin.actions.submitUpdate);useMainViewVisibilityRevision();const installedGhostMarketKey = useMemo(() => installedGhostMarketKeyFor(ghosts),@@ -821,10 +817,10 @@ function LocalGhostPluginPage({const publishableInstalledItems = useMemo(() => {const eligible = new Set(ghosts.filter((ghost) =>ghost.publishingSource?.kind === 'local' &&- !localPublishingUnavailableKey(ghost, marketItemForInstalledGhost(marketItems, ghost), canSubmitMarketInstallation(ghost)),+ !localPublishingUnavailableKey(ghost, marketItemForInstalledGhost(marketItems, ghost)),).map(installedGhostStoragePart));return allInstalledItems.filter((item) => eligible.has(item.id));- }, [ghosts, marketItems, allInstalledItems, publishingInstallations]);+ }, [ghosts, marketItems, allInstalledItems]);const searchedInstalledItems = useMemo(() => filterGhostPluginItems(installedItems, query),[installedItems, query],@@ -1694,8 +1690,7 @@ function LocalGhostPluginPage({}, [searchParams, setSearchParams]);const localContributionKey = JSON.stringify([contributionOwner, selectedDetail?.id, selectedGhost?.dir, selectedGhost?.manifest.version, ghostInstallApprovalToken(selectedGhost?.approval), selectedGhost?.publishingSource, publicationRefresh]);const localContributionResult = localContribution?.key === localContributionKey ? localContribution : null;- const contributionUnavailableKey = localPublishingUnavailableKey(selectedGhost, selectedMarketInstall,- Boolean(selectedGhost && canSubmitMarketInstallation(selectedGhost)));+ const contributionUnavailableKey = localPublishingUnavailableKey(selectedGhost, selectedMarketInstall);// Ordinary downloads have use/configuration details only. Unknown provenance// also cannot become a first publication merely because no market card exists.const showLocalPublishing = selectedGhost?.publishingSource?.kind === 'local';diff --git a/apps/desktop/src/renderer/features/plugin/__tests__/GhostPluginPage.navigation.test.tsx b/apps/desktop/src/renderer/features/plugin/__tests__/GhostPluginPage.navigation.test.tsxindex c346ceadaf..38c2febe44 100644--- a/apps/desktop/src/renderer/features/plugin/__tests__/GhostPluginPage.navigation.test.tsx+++ b/apps/desktop/src/renderer/features/plugin/__tests__/GhostPluginPage.navigation.test.tsx@@ -1001,6 +1001,8 @@ describe('plugin use details and independent author management', () => {expect(screen.queryByRole('button', { name: `${prefix}.publish` })).toBeNull();expect(api.prepare).not.toHaveBeenCalled();expect(api.submit).not.toHaveBeenCalled();+ // 普通下载详情无需扫描本人投稿权限,公开安装也不能开启 UI 提审。+ expect(api.list).not.toHaveBeenCalled();});it.each(['author-list', 'installed', 'installed-market', 'market'] as const)('keeps use and version management separate when entering from %s', async entry => {auth.mode = 'cloud';diff --git a/apps/desktop/src/renderer/features/plugin/lib/__tests__/ghostPluginDetailModel.test.ts b/apps/desktop/src/renderer/features/plugin/lib/__tests__/ghostPluginDetailModel.test.tsindex cd600f1a34..9eb84fa4fd 100644--- a/apps/desktop/src/renderer/features/plugin/lib/__tests__/ghostPluginDetailModel.test.ts+++ b/apps/desktop/src/renderer/features/plugin/lib/__tests__/ghostPluginDetailModel.test.ts@@ -16,21 +16,20 @@ const installed: InstalledGhost = {};describe('local publishing availability shared by details and selection', () => {- it('explains the GitHub requirement for verified official public plugins even with submission permission', () => {+ it('explains the GitHub requirement for verified official public plugins', () => {const market = { scope: 'public' as const, organizationId: null, sourceType: 'server' as const, publisherKind: 'official' as const };- expect(localPublishingUnavailableKey(installed, market, true)).toBe('officialGithubRequired');+ expect(localPublishingUnavailableKey(installed, market)).toBe('officialGithubRequired');const trusted: InstalledGhost = { ...installed, publishingSource: { kind: 'public-market', pluginId: 'official-id' },trust: { level: 'cindy-official', publisherSigned: true, publisherVerified: true, reviewed: true } };- expect(localPublishingUnavailableKey(trusted, null, true)).toBe('officialGithubRequired');- expect(localPublishingUnavailableKey(installed, { ...market, sourceType: 'local-market' }, true)).toBeNull();- expect(localPublishingUnavailableKey({ ...installed, manifest: { ...installed.manifest, author: 'Cindy' } }, { ...market, publisherKind: 'personal' }, true)).toBeNull();+ expect(localPublishingUnavailableKey(trusted, null)).toBe('officialGithubRequired');+ expect(localPublishingUnavailableKey(installed, { ...market, sourceType: 'local-market' })).toBeNull();+ expect(localPublishingUnavailableKey({ ...installed, manifest: { ...installed.manifest, author: 'Cindy' } }, { ...market, publisherKind: 'personal' })).toBeNull();});- it('separates approved use from current exact publishing permission', () => {+ it('keeps UI publishing unavailable for downloaded or unverified sources', () => {expect(localPublishingUnavailableKey({ ...installed, publishingSource: undefined })).toBe('sourceUnverified');const downloaded: InstalledGhost = { ...installed, publishingSource: { kind: 'public-market', pluginId: 'public-id' } };expect(localPublishingUnavailableKey(downloaded)).toBe('publishingPermissionRequired');- expect(localPublishingUnavailableKey(downloaded, null, true)).toBeNull();- expect(localPublishingUnavailableKey({ ...downloaded, publishingSource: { kind: 'unavailable' } }, null, true)).toBe('sourceUnverified');+ expect(localPublishingUnavailableKey({ ...downloaded, publishingSource: { kind: 'unavailable' } })).toBe('sourceUnverified');});it.each([{ ghost: null, reason: 'installationUnavailable' },diff --git a/apps/desktop/src/renderer/features/plugin/lib/ghostPluginDetailModel.ts b/apps/desktop/src/renderer/features/plugin/lib/ghostPluginDetailModel.tsindex 426a72a4d5..a20c48eceb 100644--- a/apps/desktop/src/renderer/features/plugin/lib/ghostPluginDetailModel.ts+++ b/apps/desktop/src/renderer/features/plugin/lib/ghostPluginDetailModel.ts@@ -7,11 +7,10 @@import { isUserInstallReservedGhostId, type InstalledGhost } from '../../../../shared/ghost';import type { PluginMarketItem } from '../../../../shared/pluginMarket';-/** Host provenance is not authorship. Market updates additionally need current exact submit ACL. */+/** UI submissions use local installations; Host and server verify actual publishing permission. */export function localPublishingUnavailableKey(ghost: InstalledGhost | null | undefined,market?: (Pick<PluginMarketItem, 'scope' | 'organizationId'> & Partial<Pick<PluginMarketItem, 'sourceType' | 'publisherKind'>>) | null,- canSubmitMarket = false,) {if (!ghost) return 'installationUnavailable';if (ghost.namespace === null && (@@ -23,7 +22,7 @@ export function localPublishingUnavailableKey(if (ghost.namespace !== null || (market && (market.scope !== 'public' || market.organizationId !== null))) return 'privatePlugin';if (ghost.approval.state !== 'approved') return 'approvalRequired';if (!ghost.publishingSource || ghost.publishingSource.kind === 'unavailable') return 'sourceUnverified';- if (ghost.publishingSource.kind === 'public-market' && !canSubmitMarket) return 'publishingPermissionRequired';+ if (ghost.publishingSource.kind === 'public-market') return 'publishingPermissionRequired';return null;}diff --git a/apps/desktop/src/renderer/features/plugin/lib/usePublishingInstallations.ts b/apps/desktop/src/renderer/features/plugin/lib/usePublishingInstallations.tsdeleted file mode 100644index 77eaf0d806..0000000000--- a/apps/desktop/src/renderer/features/plugin/lib/usePublishingInstallations.ts+++ /dev/null@@ -1,50 +0,0 @@-import { useEffect, useState } from 'react';-import type { InstalledGhost } from '../../../../shared/ghost';-import type { MyPluginView } from '../../../../shared/pluginContributions';-import { installedGhostStoragePart } from '../../../../shared/pluginIdentity';--/** Rebuildable exact install/ACL projection. Never derives ownership from package metadata. */-export function usePublishingInstallations(owner: string, personal: boolean, ghosts: InstalledGhost[]) {- const installationKey = JSON.stringify(ghosts.map(ghost => [installedGhostStoragePart(ghost), ghost.dir,- ghost.approval, ghost.publishingSource]));- const key = JSON.stringify([owner, personal, installationKey]);- const [result, setResult] = useState<{ key: string; plugins: MyPluginView[] } | null>(null);- useEffect(() => {- let disposed = false;- let generation = 0;- const refresh = async () => {- const request = ++generation;- setResult(null);- if (!personal || !navigator.onLine || !ghosts.some(ghost => ghost.publishingSource?.kind === 'public-market')) return;- try {- const plugins: MyPluginView[] = [];- let cursor: string | undefined;- do {- const page = await window.electronAPI.pluginContributions.list({ query: '', filter: 'all', cursor });- if (disposed || request !== generation) return;- plugins.push(...page.plugins);- cursor = page.nextCursor ?? undefined;- } while (cursor);- setResult({ key, plugins });- } catch {- // Unknown current permission cannot preserve an old write candidate.- }- };- const foreground = () => { if (document.visibilityState === 'visible') void refresh(); };- const offline = () => { generation++; setResult(null); };- void refresh();- window.addEventListener('focus', foreground);- window.addEventListener('online', foreground);- window.addEventListener('offline', offline);- document.addEventListener('visibilitychange', foreground);- return () => {- disposed = true;- window.removeEventListener('focus', foreground);- window.removeEventListener('online', foreground);- window.removeEventListener('offline', offline);- document.removeEventListener('visibilitychange', foreground);- };- // The serialized key binds every source, approval, directory and owner generation.- }, [key]);- return result?.key === key ? result.plugins : [];-}