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(cindy-tools): clarify organization publish intent

fmfsaisai7272a4dd45c3
diff --git a/apps/desktop/src/main/mcp-integrations/__tests__/ghostWorkdirGate.test.ts b/apps/desktop/src/main/mcp-integrations/__tests__/ghostWorkdirGate.test.ts
index de21d33bfd..8d41eef66d 100644
--- a/apps/desktop/src/main/mcp-integrations/__tests__/ghostWorkdirGate.test.ts
+++ b/apps/desktop/src/main/mcp-integrations/__tests__/ghostWorkdirGate.test.ts
@@ -48,13 +48,16 @@ const {
publishTicketConsumeMock: vi.fn(),
releaseForgePackStagingMock: vi.fn(),
startPluginPublishMock: vi.fn(() => ({ transferId: 'transfer-1', uploadId: null })),
- currentPublisherIdentityMock: vi.fn(() => ({
+ currentPublisherIdentityMock: vi.fn<
+ () => { membershipId: string; orgSlug: string; orgName: string } | null
+ >(() => ({
membershipId: 'member-1',
orgSlug: 'acme',
orgName: 'Acme',
})),
}));
const releaseMutationMock = vi.fn();
+const appSessionBoundaryPendingMock = vi.fn(() => false);
const captureMutationOwnerMock = vi.fn(() => ({
mode: 'local' as const,
dataOwnerId: 'test',
@@ -105,7 +108,7 @@ vi.mock('electron', () => ({ app: { getPath: () => tmpUserData } }));
vi.mock('../../appSessionState.js', () => ({
ownerScopedUserDataPath: (...parts: string[]) => path.join(tmpUserData, ...parts),
getActiveAppSession: () => ({ mode: 'cloud', dataOwnerId: 'member-1', generation: 7 }),
- isAppSessionBoundaryPending: () => false,
+ isAppSessionBoundaryPending: appSessionBoundaryPendingMock,
}));
vi.mock('../../maker-host/logger-adapter.js', () => {
const createMakerLogger = () => ({
@@ -421,6 +424,8 @@ beforeEach(() => {
releaseForgePackStagingMock.mockClear();
startPluginPublishMock.mockClear();
currentPublisherIdentityMock.mockClear();
+ appSessionBoundaryPendingMock.mockReset();
+ appSessionBoundaryPendingMock.mockReturnValue(false);
clearAllPrefs();
});
@@ -451,6 +456,32 @@ describe('Forge session workdir gate', () => {
});
const result = await makeDeps().forgePack({ dir: path.join(WORKDIR, 'plugin-src') });
expect(result).toMatchObject({ ok: true, cindyPath: 'demo-1.0.0.cindy' });
+ if (!result.ok) throw new Error('default install pack unexpectedly failed');
+ expect(result).not.toHaveProperty('publishToken');
+ expect(result.note).toContain("若接下来要发布到组织市场,请用 intent='publish' 重新打包");
+ expect(handleIncomingCindyFileMock).toHaveBeenCalledWith(
+ '/host/staging/demo.cindy',
+ 'ghost-forge',
+ expect.objectContaining({ kind: 'agent-forge' }),
+ );
+ });
+
+ it('does not suggest organization publishing to a personal account after default install pack', async () => {
+ currentPublisherIdentityMock.mockReturnValueOnce(null);
+ packGhostDirMock.mockResolvedValueOnce({
+ ok: true,
+ buf: Buffer.from('packed'),
+ cindyPath: path.join(WORKDIR, 'plugin-src', 'demo-1.0.0.cindy'),
+ manifest: { id: 'demo', name: 'Demo', version: '1.0.0' },
+ });
+
+ const result = await makeDeps().forgePack({ dir: path.join(WORKDIR, 'plugin-src') });
+
+ // Excludes showing an unusable publish next step to personal accounts.
+ expect(result.ok).toBe(true);
+ if (!result.ok) throw new Error('personal install pack unexpectedly failed');
+ expect(result.note).not.toContain("intent='publish'");
+ // Excludes changing the default intent while adding the conditional note.
expect(result).not.toHaveProperty('publishToken');
expect(handleIncomingCindyFileMock).toHaveBeenCalledWith(
'/host/staging/demo.cindy',
@@ -498,6 +529,48 @@ describe('Forge session workdir gate', () => {
expect(releaseForgePackStagingMock).toHaveBeenCalledWith('/host/staging/demo.cindy');
});
+ it('explains that an invalid publish token must come from a publish-intent pack', async () => {
+ publishTicketConsumeMock.mockReturnValueOnce(undefined);
+
+ const result = await makeDeps().forgePublish({ token: 'invalid-token' });
+
+ expect(result).toMatchObject({ ok: false, errorCode: 'PUBLISH_TOKEN_INVALID' });
+ if (result.ok) throw new Error('invalid publish token unexpectedly succeeded');
+ expect(result.message).toContain(
+ "只能由 ghost_forge_pack(intent='publish') 签发",
+ );
+ });
+
+ it('keeps owner-mismatch and boundary-pending guidance distinct from invalid-token repacking', async () => {
+ publishTicketConsumeMock.mockReturnValueOnce({
+ owner: { mode: 'cloud', dataOwnerId: 'member-1', generation: 8 },
+ operationKind: 'install',
+ stagingPath: '/host/staging/demo.cindy',
+ packageSha256: 'a'.repeat(64),
+ manifestId: 'demo',
+ packExpiresAt: Date.now() + 600_000,
+ });
+ const ownerMismatch = await makeDeps().forgePublish({ token: 'other-owner' });
+ if (ownerMismatch.ok) throw new Error('owner-mismatch token unexpectedly succeeded');
+ expect(ownerMismatch).toEqual({
+ ok: false,
+ errorCode: 'PUBLISH_TOKEN_OWNER_MISMATCH',
+ message: '发布票据无效、已过期或已被使用,请重新打包',
+ });
+
+ appSessionBoundaryPendingMock.mockReturnValueOnce(true);
+ const boundaryPending = await makeDeps().forgePublish({ token: 'boundary' });
+ if (boundaryPending.ok) throw new Error('boundary-pending token unexpectedly succeeded');
+ expect(boundaryPending).toEqual({
+ ok: false,
+ errorCode: 'SESSION_BOUNDARY_PENDING',
+ message: '账号切换中,请稍后重试',
+ });
+ // Excludes collapsing account-boundary failures into the invalid-ticket fix.
+ expect(ownerMismatch.message).not.toContain("intent='publish'");
+ expect(boundaryPending.message).not.toContain("intent='publish'");
+ });
+
it('rejects remote workdirs before touching local Forge fs', async () => {
sessionSnapshotMock.mockResolvedValueOnce({
workingDir: '/remote/project',
diff --git a/apps/desktop/src/main/mcp-integrations/ghost.ts b/apps/desktop/src/main/mcp-integrations/ghost.ts
index 2867617f65..5f8332a2d4 100644
--- a/apps/desktop/src/main/mcp-integrations/ghost.ts
+++ b/apps/desktop/src/main/mcp-integrations/ghost.ts
@@ -1836,6 +1836,9 @@ export function getCindyGhostsMcpDeps(
};
}
log.info('ghost forge packed', { dir, id: packed.manifest.id });
+ const publishHint = currentPublisherIdentity()
+ ? "若接下来要发布到组织市场,请用 intent='publish' 重新打包。"
+ : '';
return {
ok: true,
// 给 agent 的只是作者副本文件名提示,不可用于访问;staging 路径不下发。
@@ -1846,7 +1849,7 @@ export function getCindyGhostsMcpDeps(
// 不在这里说明确认框的加重形式(如"需手输 id"):本 note 会回到 agent,
// 被注入的 agent 读到就能照着编引导话术,帮用户"过掉"那一步。
// 告知"必须在应用内确认才会安装"已足够让作者知道下一步做什么。
- note: `${iconNote}已打包并弹出装入/更新确认框,请提示用户:只有在应用内确认后插件才会真正安装。`,
+ note: `${iconNote}已打包并弹出装入/更新确认框,请提示用户:只有在应用内确认后插件才会真正安装。${publishHint}`,
};
});
},
@@ -1870,7 +1873,9 @@ export function getCindyGhostsMcpDeps(
message:
consumed.reason === 'session-boundary-pending'
? '账号切换中,请稍后重试'
- : '发布票据无效、已过期或已被使用,请重新打包',
+ : consumed.reason === 'owner-mismatch'
+ ? '发布票据无效、已过期或已被使用,请重新打包'
+ : "发布票据无效、已过期或已被使用。发布票据只能由 ghost_forge_pack(intent='publish') 签发;若刚才是按缺省 install 打的包,请用 intent='publish' 重新打一次。",
};
}
const ticket = consumed.ticket;
diff --git a/packages/cindy-tools/src/__tests__/ghostMcp.test.ts b/packages/cindy-tools/src/__tests__/ghostMcp.test.ts
index 16ceaf5452..8c60e43d3a 100644
--- a/packages/cindy-tools/src/__tests__/ghostMcp.test.ts
+++ b/packages/cindy-tools/src/__tests__/ghostMcp.test.ts
@@ -1600,13 +1600,30 @@ describe("cindy_ghosts · ghost_forge(锻造)", () => {
it("forge_pack / publish 描述明确图片字段、发布意图与组织身份限制", () => {
const server = createCindyGhostsMcpServer(fakeDeps()) as unknown as {
- _registeredTools: Record<string, { description?: string } | undefined>;
+ _registeredTools: Record<
+ string,
+ {
+ description?: string;
+ inputSchema?: {
+ shape?: { intent?: { description?: string } };
+ };
+ } | undefined
+ >;
};
const description = server._registeredTools.ghost_forge_pack?.description ?? "";
expect(description).toContain("xdt_image_url");
expect(description).toContain("xdt_image_urls");
expect(description).toContain("icon_source");
expect(description).toContain("intent=publish");
+ expect(description).toContain("intent=publish 仅企业组织成员可用");
+ expect(description).toContain("个人账号不可用,请用缺省的 install");
+ const intentDescription =
+ server._registeredTools.ghost_forge_pack?.inputSchema?.shape?.intent
+ ?.description ?? "";
+ // Excludes documenting the organization restriction only in the tool summary
+ // while the registered intent parameter still advertises publish to everyone.
+ expect(intentDescription).toContain("publish 仅企业组织成员可用");
+ expect(intentDescription).toContain("个人账号不可用,请用缺省的 install");
const publishDescription = server._registeredTools.ghost_forge_publish?.description ?? "";
expect(publishDescription).toContain("publishToken");
expect(publishDescription).toContain("仅企业组织成员可用");
diff --git a/packages/cindy-tools/src/ghost/mcpServer.ts b/packages/cindy-tools/src/ghost/mcpServer.ts
index f48f760559..95737e9934 100644
--- a/packages/cindy-tools/src/ghost/mcpServer.ts
+++ b/packages/cindy-tools/src/ghost/mcpServer.ts
@@ -124,6 +124,7 @@ const D_GHOST_FORGE_SCAFFOLD = [
const D_GHOST_FORGE_PACK = [
"把一个插件源码目录校验并打包成 .cindy。缺省 intent=install,随后主机会弹出装入确认框",
'(同 id 已装则显示"更新 vX → vY");intent=publish 时不装入,只返回一次性 publishToken。',
+ "intent=publish 仅企业组织成员可用;个人账号不可用,请用缺省的 install。",
"dir 传源码目录的绝对路径(目录里须有 ghost.json;打包自动跳过 .git / node_modules /",
"隐藏文件 / *.cindy)。仅当用户明确选择 AI 生成图标时,可把图片工具结果的",
"xdt_image_url 取单张地址;若只有 xdt_image_urls 则取数组第一项,再把得到的 cindy-media:// 地址传给 icon_source;主机会 best-effort 嵌入,失败保留默认图标继续打包。",
@@ -1296,7 +1297,9 @@ export function createCindyGhostsMcpServer(
intent: z
.enum(["install", "publish"])
.optional()
- .describe("缺省 install:弹装入确认;publish:不装入,返回一次性发布票据"),
+ .describe(
+ "缺省 install:弹装入确认;publish:不装入,返回一次性发布票据。publish 仅企业组织成员可用;个人账号不可用,请用缺省的 install",
+ ),
},
async (input) => handleForgePack(deps, input),
);