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。

fix(desktop): 限定企业身份写入 Forge 自测来源

fmfsaisai2d4600f3ff22
diff --git a/apps/desktop/src/main/cindy-brain/__tests__/GhostManager.test.ts b/apps/desktop/src/main/cindy-brain/__tests__/GhostManager.test.ts
index 9ac67904f8..a202d8d0c9 100644
--- a/apps/desktop/src/main/cindy-brain/__tests__/GhostManager.test.ts
+++ b/apps/desktop/src/main/cindy-brain/__tests__/GhostManager.test.ts
@@ -20,6 +20,7 @@ import {
} from '../ghostZipPermissions';
import { signGhostPackage } from '../ghostSignature';
import { GhostInstallReceiptStore, hashApprovedSkillContent } from '../ghostInstallReceipt';
+import { forgeInstallOriginForMembership } from '../forgeOidcInstallConfirmBridge';
import { runGhostSnapshotWorkerRequest } from '../ghostSnapshotWorkerProcess';
/** 每个用例独立的临时仓库根 + 源文件目录(规则 23:测试路径一律 os.tmpdir)。 */
@@ -2268,22 +2269,29 @@ describe('GhostManager · update pre-rename recovery', () => {
});
describe('GhostManager · install', () => {
- it('only an explicitly tagged Forge install writes agent-forge origin', async () => {
- const manual = await manager.install(await makeCindy('manual.cindy', goodManifest('manual')));
- expect(manual).toHaveProperty('ghost');
- const manualReceipt = JSON.parse(
- await fs.promises.readFile(path.join(manager.approvalStateRoot(), 'manual.json'), 'utf8'),
+ it('个人 Forge 新装不写来源,企业确认后的 Forge 新装才写 agent-forge', async () => {
+ const personalOrigin = forgeInstallOriginForMembership('personal');
+ const personal = await manager.install(
+ await makeCindy('personal.cindy', goodManifest('personal')),
+ personalOrigin ? { installOrigin: personalOrigin } : undefined,
+ );
+ expect(personal).toHaveProperty('ghost');
+ const personalReceipt = JSON.parse(
+ await fs.promises.readFile(path.join(manager.approvalStateRoot(), 'personal.json'), 'utf8'),
) as Record<string, unknown>;
- expect(manualReceipt).not.toHaveProperty('installOrigin');
- expect(manager.readEffectiveInstallOrigin('manual')).toBe('manual');
+ expect(personalReceipt).not.toHaveProperty('installOrigin');
+ expect(manager.readEffectiveInstallOrigin('personal')).toBe('manual');
+ const organizationOrigin = forgeInstallOriginForMembership('org');
const forged = await manager.install(
await makeCindy('forge.cindy', goodManifest('acme-tool')),
- {
- installOrigin: 'agent-forge',
- },
+ organizationOrigin ? { installOrigin: organizationOrigin } : undefined,
);
expect(forged).toHaveProperty('ghost');
+ const organizationReceipt = JSON.parse(
+ await fs.promises.readFile(path.join(manager.approvalStateRoot(), 'acme-tool.json'), 'utf8'),
+ ) as Record<string, unknown>;
+ expect(organizationReceipt).toHaveProperty('installOrigin', 'agent-forge');
expect(manager.readEffectiveInstallOrigin('acme-tool')).toBe('agent-forge');
});
@@ -4554,16 +4562,20 @@ describe('GhostManager · update(原位换版)', () => {
expect(manager.readEffectiveInstallOrigin('hello')).toBe('agent-forge');
});
- it('a manual update clears an earlier Forge origin instead of inheriting privilege', async () => {
+ it('个人 Forge 更新清掉旧企业 Forge 来源而不是继承资格', async () => {
await manager.install(await makeCindy('forge-v1.cindy', goodManifest()), {
installOrigin: 'agent-forge',
});
expect(manager.readEffectiveInstallOrigin('hello')).toBe('agent-forge');
const installed = manager.list().find((ghost) => ghost.manifest.id === 'hello');
+ const personalOrigin = forgeInstallOriginForMembership('personal');
const result = await manager.update(
- await makeCindy('manual-v2.cindy', { ...goodManifest(), version: '2.0.0' }),
- { expectedInstalledApproval: ghostInstallApprovalToken(installed?.approval) },
+ await makeCindy('personal-forge-v2.cindy', { ...goodManifest(), version: '2.0.0' }),
+ {
+ expectedInstalledApproval: ghostInstallApprovalToken(installed?.approval),
+ ...(personalOrigin ? { installOrigin: personalOrigin } : {}),
+ },
);
expect(result).toHaveProperty('ghost');
const receipt = JSON.parse(
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 b1f80c0647..66e6503dbd 100644
--- a/apps/desktop/src/main/cindy-brain/__tests__/forge.test.ts
+++ b/apps/desktop/src/main/cindy-brain/__tests__/forge.test.ts
@@ -1501,7 +1501,7 @@ describe('FORGE_GUIDE', () => {
expect(FORGE_GUIDE).toContain("ghost_forge_install({ dir: '<绝对路径>' })");
expect(FORGE_GUIDE).toContain('不要因为 scaffold 或 pack 成功就自动调用本工具');
expect(FORGE_GUIDE).toContain('同版本也可覆盖');
- expect(FORGE_GUIDE).toContain('手动导入不会取得这项 Forge 作者资格');
+ expect(FORGE_GUIDE).toContain('个人身份下的 Forge 安装和手动导入都不会取得这项资格');
});
it('开场白要求读完沙箱红线与打包测试两章', () => {
diff --git a/apps/desktop/src/main/cindy-brain/__tests__/forgeOidcInstallConfirmBridge.test.ts b/apps/desktop/src/main/cindy-brain/__tests__/forgeOidcInstallConfirmBridge.test.ts
index 8e9c33c2e0..362f16d07b 100644
--- a/apps/desktop/src/main/cindy-brain/__tests__/forgeOidcInstallConfirmBridge.test.ts
+++ b/apps/desktop/src/main/cindy-brain/__tests__/forgeOidcInstallConfirmBridge.test.ts
@@ -5,6 +5,7 @@ import {
createForgeOidcInstallMainWindowSender,
ForgeOidcInstallConfirmBridge,
forgeOidcInstallConfirmFacts,
+ forgeInstallOriginForMembership,
type ForgeOidcInstallConfirmPush,
} from '../forgeOidcInstallConfirmBridge';
@@ -71,6 +72,13 @@ describe('createForgeOidcInstallMainWindowSender', () => {
});
});
+describe('forgeInstallOriginForMembership', () => {
+ it('只给本次企业身份的 Forge 安装写作者自测来源', () => {
+ expect(forgeInstallOriginForMembership('org')).toBe('agent-forge');
+ expect(forgeInstallOriginForMembership('personal')).toBeUndefined();
+ });
+});
+
describe('forgeOidcInstallConfirmFacts', () => {
it('requires confirmation only for organization installs that declare oidc-token', () => {
expect(forgeOidcInstallConfirmFacts(OIDC, 'org')).toEqual({
diff --git a/apps/desktop/src/main/cindy-brain/__tests__/forgeOidcInstallEntry.test.ts b/apps/desktop/src/main/cindy-brain/__tests__/forgeOidcInstallEntry.test.ts
index 46331d0f6c..f1d1b4ef7b 100644
--- a/apps/desktop/src/main/cindy-brain/__tests__/forgeOidcInstallEntry.test.ts
+++ b/apps/desktop/src/main/cindy-brain/__tests__/forgeOidcInstallEntry.test.ts
@@ -13,7 +13,7 @@ function forgeInstallBody(): string {
}
describe('Forge OIDC install entry wiring', () => {
- it('finishes the narrow confirmation before any install/update mutation begins', () => {
+ it('企业取消在任何 install/update 与 receipt 写入前收口', () => {
const body = forgeInstallBody();
const confirm = body.indexOf(
'await ensureForgeOidcInstallConfirmBridge().request(confirmFacts)',
@@ -22,19 +22,23 @@ describe('Forge OIDC install entry wiring', () => {
expect(confirm).toBeGreaterThanOrEqual(0);
expect(mutation).toBeGreaterThan(confirm);
expect(body).toContain("throwIpcError('MUTATION_CANCELLED'");
+ const beforeMutation = body.slice(0, mutation);
+ expect(beforeMutation).not.toContain('installAndDockLocked(');
+ expect(beforeMutation).not.toContain('updateLocalGhostPackageLocked(');
});
- it('marks both new installs and in-place updates as explicit agent-forge', () => {
+ it('新装与原位更新都只在本次企业身份下传 agent-forge', () => {
const body = forgeInstallBody();
- expect(body).toContain("installOrigin: 'agent-forge'");
- expect(body).toContain("getActiveAppSession(),\n 'agent-forge',");
+ expect(body).toContain("const membershipKind = user?.membershipKind ?? 'personal';");
+ expect(body).toContain('const installOrigin = forgeInstallOriginForMembership(membershipKind);');
+ expect(body).toContain('...(installOrigin ? { installOrigin } : {})');
+ expect(body).toContain('getActiveAppSession(),\n installOrigin,');
+ expect(body).not.toContain("installOrigin: 'agent-forge'");
});
- it('authorizes tokenBroker against Forge facts without making it trigger the OIDC dialog', () => {
+ it('tokenBroker 只在企业身份下拿 Forge facts,且不触发 OIDC 确认窗', () => {
const body = forgeInstallBody();
- expect(body).toContain(
- "rejectUnauthorizedTokenBroker(inspected.manifest, { installOrigin: 'agent-forge' })",
- );
+ expect(body).toContain('installOrigin ? { installOrigin } : undefined');
expect(body).toContain('forgeOidcInstallConfirmFacts(');
});
diff --git a/apps/desktop/src/main/cindy-brain/forge.ts b/apps/desktop/src/main/cindy-brain/forge.ts
index 6febdcdc43..41a67b453c 100644
--- a/apps/desktop/src/main/cindy-brain/forge.ts
+++ b/apps/desktop/src/main/cindy-brain/forge.ts
@@ -2979,7 +2979,7 @@ Auth 的企业服务。主机只在当前登录账号属于组织 Membership,
保有本次包的完整 sha256。两路都要求清单声明目标服务域名。
audience 与组织身份由主机推导,插件清单和运行时代码都不能选择、读取或保存
audience/token;audience 固定为 \`\${orgSlug}:\${ghostId}\`,总长不得超过 64 字符。
-个人身份与手动导入不签发;Forge 安装前会展示插件名、id 与精确域名,并要求手输相同 id
+个人身份与手动导入不签发;企业身份的 Forge 安装前会展示插件名、id 与精确域名,并要求手输相同 id
确认。市场与 Forge 两条组织基座都只给 Broker 与 oidc-token、不给宿主原语。
该凭证必须固定声明
\`"inject": { "header": "Authorization", "format": "Bearer {value}", "hosts": [...] }\`,
@@ -4378,9 +4378,9 @@ const opened = await cindy.iosSimulator.request({
\`ghost_forge_install({ dir: '<绝对路径>' })\`。它会重新校验并打包当前源码,再把这次
产生的确切包直接安装;首次安装会启用,同 id 已安装时原位更新并保留启用状态、配置、
数据与面板位置,同版本也可覆盖。不要因为 scaffold 或 pack 成功就自动调用本工具。
- 企业身份下若清单声明 \`source:"oidc-token"\`,提交安装前会展示插件名、id 与精确注入
- 域名,并要求用户手输相同 id;取消不会安装。确认后的企业作者自测可签发 Connection JWT。
- 用户也可以自己导入上一步的 \`.cindy\`,但手动导入不会取得这项 Forge 作者资格;
+ 企业身份下若清单声明 \`source:"oidc-token"\`,提交安装前会展示插件名、id 与精确请求
+ 域名,并要求用户手输相同 id;取消不会安装。只有确认后的企业作者自测才会取得 Forge
+ 作者资格并可签发 Connection JWT;个人身份下的 Forge 安装和手动导入都不会取得这项资格;
4. 安装后再让用户 \`$<command> <内容>\` 试一单,看聊天图卡/面板是否符合预期。
企业组织成员需要发布时,调用 \`ghost_forge_pack({ dir: '<绝对路径>', intent: 'publish' })\`。
diff --git a/apps/desktop/src/main/cindy-brain/forgeOidcInstallConfirmBridge.ts b/apps/desktop/src/main/cindy-brain/forgeOidcInstallConfirmBridge.ts
index 9f4653bb1b..759bcb9e8e 100644
--- a/apps/desktop/src/main/cindy-brain/forgeOidcInstallConfirmBridge.ts
+++ b/apps/desktop/src/main/cindy-brain/forgeOidcInstallConfirmBridge.ts
@@ -17,6 +17,13 @@ export interface ForgeOidcInstallConfirmFacts {
hosts: string[];
}
+/** 只有本次安装发生在企业身份下,receipt 才记录 Forge 作者自测来源。 */
+export function forgeInstallOriginForMembership(
+ membershipKind: 'personal' | 'org',
+): 'agent-forge' | undefined {
+ return membershipKind === 'org' ? 'agent-forge' : undefined;
+}
+
/** 只有企业身份安装声明了 oidc-token 的 Forge 包才需要这扇窄确认窗。 */
export function forgeOidcInstallConfirmFacts(
manifest: GhostManifest,
diff --git a/apps/desktop/src/main/cindy-brain/index.ts b/apps/desktop/src/main/cindy-brain/index.ts
index 2965b6e543..bf80895b7f 100644
--- a/apps/desktop/src/main/cindy-brain/index.ts
+++ b/apps/desktop/src/main/cindy-brain/index.ts
@@ -272,6 +272,7 @@ import {
import {
createForgeOidcInstallMainWindowSender,
forgeOidcInstallConfirmFacts,
+ forgeInstallOriginForMembership,
getForgeOidcInstallConfirmBridge,
initForgeOidcInstallConfirmBridge,
} from './forgeOidcInstallConfirmBridge.js';
@@ -5584,14 +5585,16 @@ export async function installOrUpdateLocalGhostPackageFromForge(
}
rejectReservedGhostId(inspected.manifest.id);
rejectBrokerWithoutDeclaredRedirectPort(inspected.manifest);
- rejectUnauthorizedTokenBroker(inspected.manifest, { installOrigin: 'agent-forge' });
const authState = getAuthState();
const user = authState.isAuthenticated ? authState.user : null;
- const confirmFacts = forgeOidcInstallConfirmFacts(
+ const membershipKind = user?.membershipKind ?? 'personal';
+ const installOrigin = forgeInstallOriginForMembership(membershipKind);
+ rejectUnauthorizedTokenBroker(
inspected.manifest,
- user?.membershipKind ?? 'personal',
+ installOrigin ? { installOrigin } : undefined,
);
+ const confirmFacts = forgeOidcInstallConfirmFacts(inspected.manifest, membershipKind);
if (confirmFacts) {
let confirmed = false;
try {
@@ -5612,7 +5615,7 @@ export async function installOrUpdateLocalGhostPackageFromForge(
ghostId: inspected.manifest.id,
enable: true,
expectedPackageSha256: expected.packageSha256,
- installOrigin: 'agent-forge',
+ ...(installOrigin ? { installOrigin } : {}),
}),
action: 'installed',
};
@@ -5625,7 +5628,7 @@ export async function installOrUpdateLocalGhostPackageFromForge(
expected.packageSha256,
ghostInstallApprovalToken(installed.approval),
getActiveAppSession(),
- 'agent-forge',
+ installOrigin,
),
action: 'updated',
};