Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(plugin): accept narrowed network host patterns
liugaowei32b11da4807d
diff --git a/apps/desktop/src/shared/__tests__/ghost.test.ts b/apps/desktop/src/shared/__tests__/ghost.test.tsindex 9042535b43..a2951465ee 100644--- a/apps/desktop/src/shared/__tests__/ghost.test.ts+++ b/apps/desktop/src/shared/__tests__/ghost.test.ts@@ -4391,6 +4391,51 @@ describe('ghost · skill 槽(捆绑 Agent Skills,2026-07-25)', () => {});describe('ghostPermissionProjectionFingerprint', () => {+ it('market cap accepts network wildcard hosts narrowed to covered host patterns', () => {+ const manifest = (host: string) =>+ validateGhostManifest({+ ...goodChipManifest(),+ slots: ['panel', 'model', 'network'],+ settingsHtml: 'settings.html',+ network: {+ hosts: [host],+ secrets: [+ {+ key: 'api_token',+ label: 'API Token',+ inject: {+ hosts: [host],+ header: 'Authorization',+ format: 'Bearer {value}',+ },+ },+ ],+ },+ });+ const reviewed = manifest('*.example.com');+ const exact = manifest('api.example.com');+ const narrowerWildcard = manifest('*.api.example.com');+ const outside = manifest('api.example.net');+ expect(reviewed.ok && exact.ok && narrowerWildcard.ok && outside.ok).toBe(true);+ if (!reviewed.ok || !exact.ok || !narrowerWildcard.ok || !outside.ok) return;++ expect(ghostNetworkAuthorizationWithinCap(reviewed.manifest, exact.manifest)).toBe(true);+ expect(ghostNetworkAuthorizationWithinCap(reviewed.manifest, narrowerWildcard.manifest)).toBe(+ true,+ );+ expect(unreviewedGhostPermissionItems(reviewed.manifest, undefined, exact.manifest)).toEqual([]);+ expect(+ unreviewedGhostPermissionItems(reviewed.manifest, undefined, narrowerWildcard.manifest),+ ).toEqual([]);+ expect(ghostNetworkAuthorizationWithinCap(exact.manifest, narrowerWildcard.manifest)).toBe(+ false,+ );+ expect(ghostNetworkAuthorizationWithinCap(narrowerWildcard.manifest, reviewed.manifest)).toBe(+ false,+ );+ expect(ghostNetworkAuthorizationWithinCap(reviewed.manifest, outside.manifest)).toBe(false);+ });+it('market cap compares network credential injection semantics, not only display items', () => {const reviewed = validateGhostManifest({...goodChipManifest(),@@ -4579,7 +4624,8 @@ describe('ghostPermissionProjectionFingerprint', () => {const [credentials, workspace] = reviewed.manifest.setup.requires;const withSetup = (requires: NonNullable<GhostManifest['setup']>['requires']): GhostManifest =>({ ...reviewed.manifest, setup: { requires } });- const { setup: _setup, ...implicit } = reviewed.manifest;+ const implicit = { ...reviewed.manifest };+ delete implicit.setup;const explicitOptOut = withSetup([]);expect(diff --git a/apps/desktop/src/shared/ghost.ts b/apps/desktop/src/shared/ghost.tsindex af78fcd02c..d89bcbd39d 100644--- a/apps/desktop/src/shared/ghost.ts+++ b/apps/desktop/src/shared/ghost.ts@@ -646,6 +646,12 @@ export function ghostNetworkHostMatches(pattern: string, hostname: string): boolreturn hostname === pattern;}+function ghostNetworkHostPatternWithinCap(actual: string, reviewed: string): boolean {+ if (!actual.startsWith('*.')) return ghostNetworkHostMatches(reviewed, actual);+ if (!reviewed.startsWith('*.')) return false;+ return ghostNetworkHostMatches(reviewed, `cap-probe.${actual.slice(2)}`);+}+/*** 凭证注入声明:该凭证以什么形态、进哪些域名的请求头。绑定在 secret 上* (而非独立 auth 模板)是刻意的——结构上保证"key 只流向它声明的域名",@@ -2494,6 +2500,15 @@ export function unreviewedGhostPermissionItems(ghostNodeSecretAuthorizationWithinCap(reviewed, actual) ||(previouslyInstalled !== undefined &&ghostNodeSecretAuthorizationWithinCap(previouslyInstalled, actual));+ const networkHostApproved = (item: GhostPermissionItem): boolean => {+ if (!item.key.startsWith('network:host:')) return false;+ const actualPattern = item.key.slice('network:host:'.length);+ return [reviewed, previouslyInstalled].some((cap) =>+ cap?.network?.hosts.some((reviewedPattern) =>+ ghostNetworkHostPatternWithinCap(actualPattern, reviewedPattern),+ ),+ );+ };const oauthPermissionApproved = (item: GhostPermissionItem): boolean =>ghostOauthPermissionWithinCap(reviewed, actual, item) ||(previouslyInstalled !== undefined &&@@ -2507,6 +2522,9 @@ export function unreviewedGhostPermissionItems(// preview 的展示 detail 包含完整 hosts;真实包删减 host 是收权,不应因// detail 字符串变化被反判成新增能力。新增或替换 host 仍会保留为未审查项。!(item.key === 'preview' && previewApproved) &&+ // Network host 的展示 key 带声明模式;通配域收窄为具体域或更窄通配域+ // 仍是收权,实际覆盖关系由专用上限比较守住。+ !networkHostApproved(item) &&// Node secret 的展示 key 带完整 methods;换序或收窄是收权。URL/hint 与// entry 等 Host 实际消费字段由专用上限比较守住,不能依赖展示投影相等。!(item.key.startsWith('node:secret:') && nodeSecretsApproved) &&@@ -2575,9 +2593,11 @@ export function ghostNetworkAuthorizationWithinCap(const reviewedNetwork = reviewed.network;if (!reviewedNetwork) return false;- const isStringSubset = (values: readonly string[], cap: readonly string[]): boolean =>- values.every((value) => cap.includes(value));- if (!isStringSubset(actualNetwork.hosts, reviewedNetwork.hosts)) return false;+ const isHostPatternSubset = (values: readonly string[], cap: readonly string[]): boolean =>+ values.every((value) =>+ cap.some((reviewedPattern) => ghostNetworkHostPatternWithinCap(value, reviewedPattern)),+ );+ if (!isHostPatternSubset(actualNetwork.hosts, reviewedNetwork.hosts)) return false;const reviewedSecrets = new Map((reviewedNetwork.secrets ?? []).map((secret) => [secret.key, secret] as const),@@ -2590,7 +2610,7 @@ export function ghostNetworkAuthorizationWithinCap(}const actualHosts = secret.inject.hosts ?? actualNetwork.hosts;const reviewedHosts = cap.inject.hosts ?? reviewedNetwork.hosts;- if (!isStringSubset(actualHosts, reviewedHosts)) return false;+ if (!isHostPatternSubset(actualHosts, reviewedHosts)) return false;if (secret.url !== undefined && secret.url !== cap.url) return false;if (secret.hint !== undefined && secret.hint !== cap.hint) return false;if (