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): align media preferences by capability

liugaowei0c0924415356
diff --git a/apps/desktop/src/main/cindy-brain/forge.ts b/apps/desktop/src/main/cindy-brain/forge.ts
index d1a8dee2c5..6ce783c56b 100644
--- a/apps/desktop/src/main/cindy-brain/forge.ts
+++ b/apps/desktop/src/main/cindy-brain/forge.ts
@@ -2261,11 +2261,10 @@ const result = await (await fetch('/media-models?type=image')).json();
1. Agent 用 \`ghost_call\` 调用插件的业务工具;
2. 插件通过普通 \`tool-result\` JSON 返回业务参数、面板里保存的模型选择或其它上下文;
3. 同一个 Agent 读取结果后,自行调用 Cindy Core \`media\` 工具;
-4. 如果插件需要最终媒体,在普通接收工具的 \`attachmentArgs\` 声明承载媒体地址的
- 顶层参数;Agent 按该参数调用时,Host 机械提取地址并复用通用 attachments 授权链,
- 再把声明参数中的原地址改写为该插件自己的 \`cindy-ghost://<id>/media/<hash>.<ext>\`
- 地址后派发,避免把本地绝对路径暴露给插件。插件自行保存业务状态与更新 UI;显式
- \`ghost_call.attachments\` 仍保持兼容。
+4. 如果插件需要最终媒体,Agent 再调用插件的普通接收工具,并通过顶层
+ \`ghost_call.attachments\` 显式交接;Host 复用通用 attachments 授权链,把授权后的
+ 指纹注入 \`args.attachments\`,避免把本地绝对路径暴露给插件。插件自行保存业务状态
+ 与更新 UI。
第 2 步的字段完全由插件定义,Host 不识别 \`mediaIntent\`、\`nextTool\` 等保留字段,也不
自动把插件结果转成媒体请求。下面只是普通结果示例,字段名不是平台契约:
@@ -2292,13 +2291,12 @@ Guide 组装请求;Core 负责鉴权、Guide、安全边界、任务状态与
插件获取结果不需要专用回调协议:
\`\`\`js
-// manifest:声明哪个顶层参数承载媒体地址
-// { name:'import_artwork', attachmentArgs:['mediaUrl'], parameters:{ ... } }
-// Agent 侧:Core media 成功后按普通工具参数交给插件
+// Agent 侧:Core media 成功后通过通用附件参数交给插件
ghost_call({
ghost_id: 'cindy-art',
- tool: 'import_artwork',
- args: { mediaUrl: resultUrl, caption: prompt }
+ tool: 'receive_media',
+ args: { caption: prompt },
+ attachments: [resultUrl]
});
// 插件侧:msg.args.attachments 是已授权指纹;插件自行写 /kv 并广播面板
diff --git a/apps/desktop/src/main/cindy-brain/index.ts b/apps/desktop/src/main/cindy-brain/index.ts
index 2a32dbe7f0..0b0a4b4c21 100644
--- a/apps/desktop/src/main/cindy-brain/index.ts
+++ b/apps/desktop/src/main/cindy-brain/index.ts
@@ -3166,14 +3166,18 @@ const getCatalogEmbedConfig = (): ReturnType<typeof getCatalogMediaConfig> =>
* Art 等插件的媒体偏好只认 Gateway `/models` 快照,并叠加客户端现有停用准入。
* 不合并 providers.json 的 OpenAI/Gemini/自定义来源;第三方媒体模型后续单独接入。
*/
-function getGatewayMediaPreferenceConfig(kind: 'image' | 'video'): CindyMediaCatalogConfig {
- const capability = kind === 'image' ? 'image.generate' : 'video.generate';
+function getGatewayMediaPreferenceConfig(
+ capability: GhostMediaCapability,
+): CindyMediaCatalogConfig {
+ const kind = capability.startsWith('image.') ? 'image' : 'video';
+ const coreCapability: MediaCapability =
+ capability === 'video.edit' ? 'video.image_to_video' : capability;
const models = filterEnabledGatewayMediaModels(
getXdGatewayModels(),
- capability,
+ coreCapability,
readModelDisableOverrides(),
)
- .filter((model) => isMediaModelExecutable(model.id, capability))
+ .filter((model) => isMediaModelExecutable(model.id, coreCapability))
.map((model) => ({
id: model.id,
label: model.name ?? model.id,
@@ -3296,7 +3300,7 @@ function getGhostConfiguredMediaModel(
};
}
- const config = getGatewayMediaPreferenceConfig(type);
+ const config = getGatewayMediaPreferenceConfig(mediaCapability);
const available = new Set(config.models.map((model) => model.id));
const override = readGhostCindyOverrides(ghostId)[mediaCapability];
const modelId = override && available.has(override) ? override : config.defaults?.standard;
@@ -5886,8 +5890,10 @@ export function registerGhostIpc(): void {
: null;
event.returnValue = {
overrides,
- image: byKind(getGatewayMediaPreferenceConfig('image')),
- video: byKind(getGatewayMediaPreferenceConfig('video')),
+ image: byKind(getGatewayMediaPreferenceConfig('image.generate')),
+ imageEdit: byKind(getGatewayMediaPreferenceConfig('image.edit')),
+ video: byKind(getGatewayMediaPreferenceConfig('video.generate')),
+ videoEdit: byKind(getGatewayMediaPreferenceConfig('video.edit')),
text: {
options: textOptions,
defaultModel:
@@ -5960,8 +5966,12 @@ export function registerGhostIpc(): void {
// fail-closed 兜底,不在这层把「暂时没配 key」当成非法值。
if (
!isCindyOverrideModelAllowed(capability as string, model, {
- image: getGatewayMediaPreferenceConfig('image').models,
- video: getGatewayMediaPreferenceConfig('video').models,
+ image: getGatewayMediaPreferenceConfig(
+ capability === 'image.edit' ? 'image.edit' : 'image.generate',
+ ).models,
+ video: getGatewayMediaPreferenceConfig(
+ capability === 'video.edit' ? 'video.edit' : 'video.generate',
+ ).models,
embed: getCatalogEmbedConfig().models,
textPinIds: buildTextOneshotPinOptions(
getActiveCatalog(),
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 b7a1cb3a1e..f3151a1ae6 100644
--- a/apps/desktop/src/main/mcp-integrations/__tests__/ghostWorkdirGate.test.ts
+++ b/apps/desktop/src/main/mcp-integrations/__tests__/ghostWorkdirGate.test.ts
@@ -70,11 +70,6 @@ const ledgerAddRefMock = vi.fn(async (params: TestLedgerRef) => {
ledgerRefs.push({ ...params });
return `ref-${ledgerRefs.length}`;
});
-const ledgerGetBlobInfoMock = vi.fn(async () => ({
- ext: '.png',
- mimeType: 'image/png',
- bytes: 1,
-}));
const callCindyMediaMock = vi.fn();
const dirDepositMock = vi.fn(() => ({ ok: true, receipt: { token: 'dir-ticket' } }));
const saveDepositMock = vi.fn(() => ({ ok: true, receipt: { token: 'save-ticket' } }));
@@ -189,7 +184,6 @@ vi.mock('../../cindy-media/ledger.js', () => ({
hasRef: ledgerHasRefMock,
hasGhostToolGrant: ledgerHasGhostToolGrantMock,
addRef: ledgerAddRefMock,
- getBlobInfo: ledgerGetBlobInfoMock,
}));
vi.mock('../../cindy-media/invocationService.js', () => ({
callCindyMedia: callCindyMediaMock,
@@ -346,8 +340,6 @@ beforeEach(() => {
ledgerRefs.push({ ...params });
return `ref-${ledgerRefs.length}`;
});
- ledgerGetBlobInfoMock.mockReset();
- ledgerGetBlobInfoMock.mockResolvedValue({ ext: '.png', mimeType: 'image/png', bytes: 1 });
ledgerRefs.length = 0;
dirDepositMock.mockClear();
saveDepositMock.mockClear();
@@ -744,42 +736,6 @@ describe('ghost_call 兜底拒绝', () => {
expect(dispatchMock).toHaveBeenCalledTimes(1);
});
- it('attachmentArgs 在派发前改写为插件私有媒体地址,不泄漏本地路径', async () => {
- const file = path.join(outsideDir, 'declared-media.png');
- const bytes = Buffer.from('declared-media');
- fs.writeFileSync(file, bytes);
- const hash = createHash('sha256').update(bytes).digest('hex');
- listMock.mockReturnValue([
- chipGhost('art', ['tool'], {
- tools: [
- {
- name: 'import_artwork',
- description: 'd',
- attachmentArgs: ['mediaUrl'],
- },
- ],
- }),
- ]);
-
- const result = await makeDeps().callGhostTool({
- ghostId: 'art',
- tool: 'import_artwork',
- args: { mediaUrl: file, caption: 'snow' },
- });
-
- expect(result).toMatchObject({ ok: true, result: 'done' });
- expect(dispatchMock).toHaveBeenCalledWith(
- expect.objectContaining({
- args: {
- mediaUrl: `cindy-ghost://art/media/${hash}.png`,
- caption: 'snow',
- attachments: [hash],
- },
- }),
- );
- expect(JSON.stringify(dispatchMock.mock.calls)).not.toContain(file);
- });
-
it('ready + scope stale 时成功 envelope 附非阻塞 reauthSuggest', async () => {
const assessment = {
state: 'ready' as const,
diff --git a/apps/desktop/src/main/mcp-integrations/ghost.ts b/apps/desktop/src/main/mcp-integrations/ghost.ts
index 7ab23e5323..aa9a0418fd 100644
--- a/apps/desktop/src/main/mcp-integrations/ghost.ts
+++ b/apps/desktop/src/main/mcp-integrations/ghost.ts
@@ -55,7 +55,6 @@ import { toolNotFoundMessage } from '../cindy-brain/pipeDispatcher.js';
import { getSessionFsSnapshot } from '../localDb/ipc/sessions.js';
import {
deriveGhostSessionContext,
- type GhostToolDecl,
type GhostSessionContextInjected,
type GhostSetupAssessment,
type InstalledGhost,
@@ -1170,62 +1169,6 @@ function toCindyGhostInfo(ghost: InstalledGhost): CindyGhostInfo {
};
}
-function declaredAttachmentUrls(
- tool: GhostToolDecl,
- args: Record<string, unknown>,
-): { ok: true; urls: string[] } | { ok: false; message: string } {
- const urls: string[] = [];
- for (const name of tool.attachmentArgs ?? []) {
- const value = args[name];
- if (value === undefined) continue;
- const candidates = typeof value === 'string' ? [value] : value;
- if (
- !Array.isArray(candidates) ||
- candidates.some((candidate) => typeof candidate !== 'string' || candidate.length === 0)
- ) {
- return {
- ok: false,
- message: `插件工具 ${JSON.stringify(tool.name)} 的媒体参数 ${JSON.stringify(name)} 必须是非空地址或地址数组`,
- };
- }
- urls.push(...candidates);
- }
- return { ok: true, urls };
-}
-
-async function rewriteDeclaredAttachmentArgs(
- ghostId: string,
- tool: GhostToolDecl,
- args: Record<string, unknown>,
- sourceUrls: string[],
- hashes: string[],
-): Promise<{ ok: true; args: Record<string, unknown> } | { ok: false; message: string }> {
- const safeUrlBySource = new Map<string, string>();
- for (let index = 0; index < sourceUrls.length; index += 1) {
- const source = sourceUrls[index]!;
- const hash = hashes[index];
- if (!hash) {
- return { ok: false, message: '媒体授权结果不完整,本次插件调用未执行' };
- }
- const info = await ledger.getBlobInfo(hash);
- if (!info) {
- return { ok: false, message: '媒体授权结果未写入总仓,本次插件调用未执行' };
- }
- safeUrlBySource.set(source, `cindy-ghost://${ghostId}/media/${hash}${info.ext}`);
- }
-
- const rewritten = { ...args };
- for (const name of tool.attachmentArgs ?? []) {
- const value = args[name];
- if (typeof value === 'string') {
- rewritten[name] = safeUrlBySource.get(value) ?? value;
- } else if (Array.isArray(value)) {
- rewritten[name] = value.map((source) => safeUrlBySource.get(source) ?? source);
- }
- }
- return { ok: true, args: rewritten };
-}
-
/**
* 构造总机 deps(每次工具调用都现查,无任何缓存层)。
*
@@ -1358,8 +1301,7 @@ export function getCindyGhostsMcpDeps(
);
if (!initialVisibility.ok) return initialVisibility;
const target = initialVisibility.ghost;
- // 媒体过户:显式 attachments 与工具声明的 attachmentArgs 汇合后,
- // 逐张落媒体总仓 + 记可读引用
+ // 媒体过户:显式 attachments 逐张落媒体总仓 + 记可读引用
// (人工确认 = ghost-grant;Host 工具代办 = ghost-tool-grant),指纹注入
// args.attachments 交给意识。任何一张失败整批拒(ATTACHMENT_INVALID),
// 不做半成品授权。全链路见 grantAttachmentUrls。
@@ -1410,10 +1352,10 @@ export function getCindyGhostsMcpDeps(
);
if (!refreshedVisibility.ok) return refreshedVisibility;
const refreshed = refreshedVisibility.ghost;
- const refreshedTool = grantOnly
- ? undefined
- : (refreshed.manifest.tools ?? []).find((candidate) => candidate.name === tool);
- if (!grantOnly && !refreshedTool) {
+ if (
+ !grantOnly &&
+ !(refreshed.manifest.tools ?? []).some((candidate) => candidate.name === tool)
+ ) {
return {
ok: false,
errorCode: 'TOOL_NOT_FOUND',
@@ -1517,17 +1459,7 @@ export function getCindyGhostsMcpDeps(
},
};
}
- const declaredAttachments = refreshedTool
- ? declaredAttachmentUrls(refreshedTool, args)
- : { ok: true as const, urls: [] };
- if (!declaredAttachments.ok) {
- return {
- ok: false,
- errorCode: 'ATTACHMENT_INVALID',
- message: declaredAttachments.message,
- };
- }
- const attachmentUrls = [...new Set([...(attachments ?? []), ...declaredAttachments.urls])];
+ const attachmentUrls = [...new Set(attachments ?? [])];
if (attachmentUrls.length > 0) {
const grant = await grantAttachmentUrls({
ghostId,
@@ -1541,19 +1473,7 @@ export function getCindyGhostsMcpDeps(
if (!grant.ok) {
return { ok: false, errorCode: 'ATTACHMENT_INVALID', message: grant.message };
}
- const rewritten = refreshedTool
- ? await rewriteDeclaredAttachmentArgs(
- ghostId,
- refreshedTool,
- args,
- attachmentUrls,
- grant.hashes,
- )
- : { ok: true as const, args };
- if (!rewritten.ok) {
- return { ok: false, errorCode: 'ATTACHMENT_INVALID', message: rewritten.message };
- }
- mergedArgs = { ...rewritten.args, attachments: grant.hashes };
+ mergedArgs = { ...args, attachments: grant.hashes };
}
// 目录过户(xd-service 意识化二期):dir 收集文件发一次性票据,元数据
// 注入 args.dir_deposit——意识拿到的只有票据与相对路径清单;上传时
diff --git a/apps/desktop/src/preload/preload.ts b/apps/desktop/src/preload/preload.ts
index 1591cfac61..eda1f7d97c 100644
--- a/apps/desktop/src/preload/preload.ts
+++ b/apps/desktop/src/preload/preload.ts
@@ -1058,10 +1058,18 @@ contextBridge.exposeInMainWorld('electronAPI', {
options: Array<{ id: string; label: string }>;
defaultModel: { id: string; label: string } | null;
};
+ imageEdit: {
+ options: Array<{ id: string; label: string }>;
+ defaultModel: { id: string; label: string } | null;
+ };
video: {
options: Array<{ id: string; label: string }>;
defaultModel: { id: string; label: string } | null;
};
+ videoEdit: {
+ options: Array<{ id: string; label: string }>;
+ defaultModel: { id: string; label: string } | null;
+ };
/** 文本类(快问快答):选项是当前供应商目录的全部文本模型(cat: 编码钉值,
* 带供应商/模型/徽标等结构化字段供富列表渲染);declaredModel = 身份卡声明
* 的偏好模型;utilityProfiles = 存量轻量档位钉的展示名表(老钉值回显用)。 */
diff --git a/apps/desktop/src/renderer/cindy-brain/CindyCapabilityPrefs.tsx b/apps/desktop/src/renderer/cindy-brain/CindyCapabilityPrefs.tsx
index 3f153192cf..62b2863cca 100644
--- a/apps/desktop/src/renderer/cindy-brain/CindyCapabilityPrefs.tsx
+++ b/apps/desktop/src/renderer/cindy-brain/CindyCapabilityPrefs.tsx
@@ -89,13 +89,17 @@ export function CindyCapabilityPrefs({
// 按能力键的类目取对应清单。少一个分支的后果不是少个下拉,而是拿
// **图像模型清单**去填一个文本能力——用户存进去的值链路根本不认。
const isText = capability.startsWith('text.');
- const kind = capability.startsWith('video.')
- ? prefs.video
+ const kind = capability === 'video.edit'
+ ? prefs.videoEdit
+ : capability.startsWith('video.')
+ ? prefs.video
: isText
? prefs.text
: capability.startsWith('embed.')
? prefs.embed
- : prefs.image;
+ : capability === 'image.edit'
+ ? prefs.imageEdit
+ : prefs.image;
// 目录没给这个类目任何模型 = 能力暂不可用:行照旧显示(插件确实申请了
// 这项能力),但右侧不给下拉,改一句不可点的灰字,不拿旧型号冒充可选。
const defaultModel = kind.defaultModel;
diff --git a/apps/desktop/src/renderer/features/plugin/__tests__/GhostPluginDetailSections.test.tsx b/apps/desktop/src/renderer/features/plugin/__tests__/GhostPluginDetailSections.test.tsx
index 21042534d2..46f229130d 100644
--- a/apps/desktop/src/renderer/features/plugin/__tests__/GhostPluginDetailSections.test.tsx
+++ b/apps/desktop/src/renderer/features/plugin/__tests__/GhostPluginDetailSections.test.tsx
@@ -580,7 +580,7 @@ describe('Ghost plugin detail sections', () => {
expect(screen.getByText('By Cindy').className).toContain('truncate');
});
- it('marks Cindy model preferences as a card-width responsive control group', () => {
+ it('uses each Cindy capability catalog in the responsive control group', () => {
Object.defineProperty(window, 'electronAPI', {
configurable: true,
value: {
@@ -591,10 +591,18 @@ describe('Ghost plugin detail sections', () => {
options: [{ id: 'image-default', label: 'Image Default' }],
defaultModel: { id: 'image-default', label: 'Image Default' },
},
+ imageEdit: {
+ options: [{ id: 'image-edit', label: 'Image Edit' }],
+ defaultModel: { id: 'image-edit', label: 'Image Edit' },
+ },
video: {
options: [{ id: 'video-default', label: 'Video Default' }],
defaultModel: { id: 'video-default', label: 'Video Default' },
},
+ videoEdit: {
+ options: [{ id: 'video-edit', label: 'Video Edit' }],
+ defaultModel: { id: 'video-edit', label: 'Video Edit' },
+ },
}),
setCindyPref: vi.fn(),
},
@@ -604,16 +612,19 @@ describe('Ghost plugin detail sections', () => {
const { container } = render(
<CindyCapabilityPrefs
ghostId="builtin.example"
- capabilities={['image.generate']}
+ capabilities={['image.generate', 'image.edit']}
appearance="plugin"
/>,
);
expect(container.querySelector('.cindy-capability-prefs')).toBeTruthy();
expect(container.querySelector('.cindy-capability-row')).toBeTruthy();
- const select = screen.getByRole('combobox');
- expect(select.className).toContain('cindy-capability-select');
- expect(select.className).toContain('max-w-[60%]');
+ const selects = screen.getAllByRole('combobox') as HTMLSelectElement[];
+ expect(selects).toHaveLength(2);
+ expect(selects[0]!.options[0]!.textContent).toContain('Image Default');
+ expect(selects[1]!.options[0]!.textContent).toContain('Image Edit');
+ expect(selects[0]!.className).toContain('cindy-capability-select');
+ expect(selects[0]!.className).toContain('max-w-[60%]');
});
// 2026-08-05:快问快答钉档扩展为目录全量文本模型——富列表选择器(供应商
@@ -635,7 +646,9 @@ describe('Ghost plugin detail sections', () => {
cindyPrefsSync: () => ({
overrides: {},
image: { options: [], defaultModel: null },
+ imageEdit: { options: [], defaultModel: null },
video: { options: [], defaultModel: null },
+ videoEdit: { options: [], defaultModel: null },
text: {
options: [
{
@@ -721,7 +734,9 @@ describe('Ghost plugin detail sections', () => {
cindyPrefsSync: () => ({
overrides: { 'text.oneshot': 'litellm-kimi-k2.6' },
image: { options: [], defaultModel: null },
+ imageEdit: { options: [], defaultModel: null },
video: { options: [], defaultModel: null },
+ videoEdit: { options: [], defaultModel: null },
text: {
options: [
{
@@ -775,7 +790,9 @@ describe('Ghost plugin detail sections', () => {
cindyPrefsSync: () => ({
overrides: { 'text.oneshot': 'cat:gone:codex:retired-model' },
image: { options: [], defaultModel: null },
+ imageEdit: { options: [], defaultModel: null },
video: { options: [], defaultModel: null },
+ videoEdit: { options: [], defaultModel: null },
text: {
options: [
{
@@ -833,8 +850,13 @@ describe('Ghost plugin detail sections', () => {
options: [{ id: 'image-default', label: 'Image Default' }],
defaultModel: { id: 'image-default', label: 'Image Default' },
},
+ imageEdit: {
+ options: [{ id: 'image-edit', label: 'Image Edit' }],
+ defaultModel: { id: 'image-edit', label: 'Image Edit' },
+ },
// 目录没给视频清单 = 能力暂不可用。
video: { options: [], defaultModel: null },
+ videoEdit: { options: [], defaultModel: null },
}),
setCindyPref: vi.fn(),
},
diff --git a/apps/desktop/src/renderer/vite-env.d.ts b/apps/desktop/src/renderer/vite-env.d.ts
index 254ee83bac..437ae68935 100644
--- a/apps/desktop/src/renderer/vite-env.d.ts
+++ b/apps/desktop/src/renderer/vite-env.d.ts
@@ -1229,10 +1229,18 @@ interface ElectronAPI {
options: Array<{ id: string; label: string }>;
defaultModel: { id: string; label: string } | null;
};
+ imageEdit: {
+ options: Array<{ id: string; label: string }>;
+ defaultModel: { id: string; label: string } | null;
+ };
video: {
options: Array<{ id: string; label: string }>;
defaultModel: { id: string; label: string } | null;
};
+ videoEdit: {
+ options: Array<{ id: string; label: string }>;
+ defaultModel: { id: string; label: string } | null;
+ };
/** 文本类(快问快答):选项是当前供应商目录的全部文本模型(cat: 编码钉值,
* 带供应商/模型/徽标等结构化字段供富列表渲染);declaredModel = 身份卡声明
* 的偏好模型(目录里解析得到才给,"跟随默认"行据此如实展示实际路由)。 */
diff --git a/apps/desktop/src/shared/__tests__/ghost.test.ts b/apps/desktop/src/shared/__tests__/ghost.test.ts
index aa4c38bc2c..0e05b2f279 100644
--- a/apps/desktop/src/shared/__tests__/ghost.test.ts
+++ b/apps/desktop/src/shared/__tests__/ghost.test.ts
@@ -1427,51 +1427,6 @@ describe('ghost · 芯片型清单(schemaVersion 2)', () => {
).toBe(false);
});
- it('attachmentArgs 只接受已声明的 string / string[] 顶层参数', () => {
- const tool = {
- name: 'import_media',
- description: '导入媒体',
- parameters: {
- type: 'object',
- properties: {
- mediaUrl: { type: 'string' },
- references: { type: 'array', items: { type: 'string' } },
- count: { type: 'number' },
- },
- },
- };
- const validate = (attachmentArgs: unknown) =>
- validateGhostManifest({
- ...goodChipManifest(),
- slots: ['panel', 'tool'],
- tools: [{ ...tool, attachmentArgs }],
- });
-
- const valid = validate(['mediaUrl', 'references']);
- expect(valid.ok).toBe(true);
- if (valid.ok) {
- expect(valid.manifest.tools?.[0]?.attachmentArgs).toEqual(['mediaUrl', 'references']);
- const previous = validateGhostManifest({
- ...goodChipManifest(),
- slots: ['panel', 'tool'],
- tools: [tool],
- });
- expect(previous.ok).toBe(true);
- if (previous.ok) {
- expect(diffGhostPermissionItems(previous.manifest, valid.manifest).added).toEqual([
- expect.objectContaining({
- key: 'tool:import_media',
- detail: expect.stringContaining('attachmentArgs: mediaUrl, references'),
- }),
- ]);
- }
- }
- expect(validate(['missing']).ok).toBe(false);
- expect(validate(['count']).ok).toBe(false);
- expect(validate(['mediaUrl', 'mediaUrl']).ok).toBe(false);
- expect(validate(['__proto__']).ok).toBe(false);
- });
-
it('@ 资源入口只可引用一个已声明工具,并按已知字段收窄', () => {
const base = {
...goodChipManifest(),
diff --git a/apps/desktop/src/shared/ghost.ts b/apps/desktop/src/shared/ghost.ts
index 736ed294cc..9827666ff0 100644
--- a/apps/desktop/src/shared/ghost.ts
+++ b/apps/desktop/src/shared/ghost.ts
@@ -425,12 +425,6 @@ export interface GhostToolDecl {
description: string;
/** JSON Schema(object)形态的参数声明;可省略(无参工具)。 */
parameters?: Record<string, unknown>;
- /**
- * 参数中承载媒体地址的顶层字段名。调用工具时 Host 从这些字段提取
- * string / string[],复用 attachments 授权链完成过户并把指纹注入
- * args.attachments;Agent 无需再把同一地址手工复制到 ghost_call.attachments。
- */
- attachmentArgs?: string[];
}
/** cindy 槽·图像类可申请的动作(主机代办菜单的"图像"类目)。 */
@@ -2047,15 +2041,12 @@ export function ghostPermissionItems(manifest: GhostManifest): GhostPermissionIt
});
}
for (const tool of manifest.tools ?? []) {
- const attachmentDetail = tool.attachmentArgs?.length
- ? `attachmentArgs: ${[...tool.attachmentArgs].sort().join(', ')}`
- : null;
items.push({
key: `tool:${tool.name}`,
kind: 'tool',
labelKey: 'tool',
labelArgs: { name: tool.name },
- detail: attachmentDetail ? `${tool.description}\n${attachmentDetail}` : tool.description,
+ detail: tool.description,
});
}
if (manifest.command) {
@@ -3478,63 +3469,12 @@ export function validateGhostManifest(raw: unknown): ManifestValidation {
return { ok: false, reason: 'tools[].parameters 必须可序列化' };
}
}
- let attachmentArgs: string[] | undefined;
- if (t.attachmentArgs !== undefined) {
- if (
- !Array.isArray(t.attachmentArgs) ||
- t.attachmentArgs.length === 0 ||
- t.attachmentArgs.length > 4
- ) {
- return { ok: false, reason: 'tools[].attachmentArgs 必须是 1–4 项的字段名数组' };
- }
- const properties =
- isPlainObject(t.parameters) && isPlainObject(t.parameters.properties)
- ? t.parameters.properties
- : null;
- const seenAttachmentArgs = new Set<string>();
- attachmentArgs = [];
- for (const rawName of t.attachmentArgs) {
- if (
- typeof rawName !== 'string' ||
- rawName.length === 0 ||
- rawName.length > 64 ||
- isGhostManifestReservedRecordKey(rawName)
- ) {
- return {
- ok: false,
- reason: 'tools[].attachmentArgs 只能引用 1–64 字符的安全顶层参数名',
- };
- }
- if (seenAttachmentArgs.has(rawName)) {
- return {
- ok: false,
- reason: `tools[].attachmentArgs 含重复字段 ${JSON.stringify(rawName)}`,
- };
- }
- const schema = properties?.[rawName];
- const acceptsMediaRef =
- isPlainObject(schema) &&
- (schema.type === 'string' ||
- (schema.type === 'array' &&
- isPlainObject(schema.items) &&
- schema.items.type === 'string'));
- if (!acceptsMediaRef) {
- return {
- ok: false,
- reason: `tools[].attachmentArgs 字段 ${JSON.stringify(rawName)} 必须在 parameters.properties 中声明为 string 或 string[]`,
- };
- }
- seenAttachmentArgs.add(rawName);
- attachmentArgs.push(rawName);
- }
- }
tools.push({
name: t.name,
description: t.description,
...(t.parameters !== undefined
? { parameters: t.parameters as Record<string, unknown> }
: {}),
- ...(attachmentArgs !== undefined ? { attachmentArgs } : {}),
});
}
}
diff --git a/docs/dev-rules/plugin-security-and-authoring.md b/docs/dev-rules/plugin-security-and-authoring.md
index 5adf826bb4..4eba6af338 100644
--- a/docs/dev-rules/plugin-security-and-authoring.md
+++ b/docs/dev-rules/plugin-security-and-authoring.md
@@ -234,11 +234,9 @@
工具发起,插件沙箱和 panel 不得直接提交、轮询或下载。存量 `cindy-request` 媒体代办仅作
兼容,不得作为新 Guide 模型的接入路径。插件工具通过现有 `tool-result` 返回普通 JSON,
Agent 读取后自行决定下一次 `media` 调用;Host 不识别插件专用媒体意图字段,也不自动
- 转发。插件需要结果时,在普通接收工具上用 `attachmentArgs` 声明承载媒体地址的顶层
- 参数名;Agent 后续只需按工具参数调用,Host 从这些参数机械提取地址并复用已有的
- `ghost_call.attachments` 通用授权链完成交接,并在派发前把声明参数中的原地址改写为该
- 插件自己的 `cindy-ghost://<id>/media/<hash>.<ext>` 地址,绝不把本地绝对路径暴露给插件。
- 显式 `ghost_call.attachments` 仍兼容并与声明参数去重;插件自行保存业务状态和更新 UI。
+ 转发。插件需要结果时,Agent 调用普通接收工具,并通过顶层
+ `ghost_call.attachments` 显式交接;Host 复用已有的通用授权链,将授权后的指纹注入
+ `args.attachments`,绝不把本地绝对路径暴露给插件。插件自行保存业务状态和更新 UI。
Host 不自动回调插件,也不得新增画廊等插件业务语义。
- 面板供片与注入的主题 token 只用 `ghostPanelTheme.ts` 白名单内的值,不扩大暴露面。
- `ios-simulator` 槽只允许读取 Host 当前台前任务的公开模拟器状态,并请求打开既有
diff --git a/packages/cindy-tools/src/ghost/mcpServer.ts b/packages/cindy-tools/src/ghost/mcpServer.ts
index 14d87337ed..f06c4e9754 100644
--- a/packages/cindy-tools/src/ghost/mcpServer.ts
+++ b/packages/cindy-tools/src/ghost/mcpServer.ts
@@ -93,7 +93,7 @@ const D_GHOST_CALL = [
const D_MEDIA = [
"Cindy Core 的低级媒体接口,供当前 Agent 执行插件提供的上层能力;插件负责场景语义和可选 UI,Core 负责模型调用与媒体交付。",
"常规链路是 Agent 先调用插件工具,读取插件返回的普通 JSON,再自行调用本工具;不存在 mediaIntent 等保留结果格式,Host 也不会自动把插件结果转成本工具调用。",
- "如果插件需要把最终结果同步进自己的面板,Agent 可在本工具成功后再调用插件声明的普通导入工具;这不是生成请求的必经步骤。",
+ "如果插件需要消费最终结果,Agent 可在本工具成功后再调用插件声明的普通工具,并通过 ghost_call.attachments 显式交接;这不是生成请求的必经步骤。",
"模型存在性来自当前账号的 Model Access model group;list_models 只投影同时满足 Gateway modalities、Guide operation 与当前客户端协议支持度的可执行模型。",
"媒体生成必须由当前 Agent 通过本工具发起;插件面板和插件沙箱代码不得直接提交生成请求。",
"插件已返回用户配置的 model_id 时可直接用它和目标 capability 走 prepare → request;没有已配置 model_id 时,先用 list_models 查询可用媒体模型。prepare 会由 Server 根据 model_id 返回 Guide,并在 Guide 不存在或不支持该 capability 时明确报错。",
diff --git a/packages/plugin-protocol/src/__tests__/manifest.test.ts b/packages/plugin-protocol/src/__tests__/manifest.test.ts
index 3394fda903..72a6cc3e7f 100644
--- a/packages/plugin-protocol/src/__tests__/manifest.test.ts
+++ b/packages/plugin-protocol/src/__tests__/manifest.test.ts
@@ -664,7 +664,6 @@ describe('Ghost manifest contract', () => {
},
required: ['input'],
},
- attachmentArgs: ['mediaUrl', 'references'],
},
],
cindy: { image: ['generate'], video: ['edit'] },
@@ -705,32 +704,6 @@ describe('Ghost manifest contract', () => {
'fs',
]);
expect(result.manifest).not.toHaveProperty('unknownField');
- expect(result.manifest.tools?.[0]?.attachmentArgs).toEqual(['mediaUrl', 'references']);
- });
-
- it('rejects invalid attachmentArgs declarations', () => {
- const tool = {
- name: 'import_media',
- description: 'Import generated media.',
- parameters: {
- type: 'object',
- properties: {
- mediaUrl: { type: 'string' },
- count: { type: 'number' },
- },
- },
- };
- const validate = (attachmentArgs: unknown) =>
- validateGhostManifest({
- ...validManifest,
- slots: ['tool'],
- tools: [{ ...tool, attachmentArgs }],
- });
-
- expect(validate(['missing'])).toMatchObject({ ok: false });
- expect(validate(['count'])).toMatchObject({ ok: false });
- expect(validate(['mediaUrl', 'mediaUrl'])).toMatchObject({ ok: false });
- expect(validate(['__proto__'])).toMatchObject({ ok: false });
});
it('accepts Desktop-supported badge and confirm slots while requiring a badge panel', () => {
diff --git a/packages/plugin-protocol/src/manifest.ts b/packages/plugin-protocol/src/manifest.ts
index 27bbcac4e3..0d31815420 100644
--- a/packages/plugin-protocol/src/manifest.ts
+++ b/packages/plugin-protocol/src/manifest.ts
@@ -147,11 +147,6 @@ export interface GhostToolDecl {
description: string;
/** JSON Schema(object)形态的参数声明;可省略(无参工具)。 */
parameters?: Record<string, unknown>;
- /**
- * 参数中承载媒体地址的顶层字段名。Host 从这些字段提取 string / string[],
- * 复用 attachments 授权链完成过户并把指纹注入 args.attachments。
- */
- attachmentArgs?: string[];
}
/**
@@ -1428,63 +1423,12 @@ export function validateGhostManifest(raw: unknown): ManifestValidation {
return { ok: false, reason: 'tools[].parameters 必须可序列化' };
}
}
- let attachmentArgs: string[] | undefined;
- if (t.attachmentArgs !== undefined) {
- if (
- !Array.isArray(t.attachmentArgs) ||
- t.attachmentArgs.length === 0 ||
- t.attachmentArgs.length > 4
- ) {
- return { ok: false, reason: 'tools[].attachmentArgs 必须是 1–4 项的字段名数组' };
- }
- const properties =
- isPlainObject(t.parameters) && isPlainObject(t.parameters.properties)
- ? t.parameters.properties
- : null;
- const seenAttachmentArgs = new Set<string>();
- attachmentArgs = [];
- for (const rawName of t.attachmentArgs) {
- if (
- typeof rawName !== 'string' ||
- rawName.length === 0 ||
- rawName.length > 64 ||
- ['__proto__', 'constructor', 'prototype'].includes(rawName)
- ) {
- return {
- ok: false,
- reason: 'tools[].attachmentArgs 只能引用 1–64 字符的安全顶层参数名',
- };
- }
- if (seenAttachmentArgs.has(rawName)) {
- return {
- ok: false,
- reason: `tools[].attachmentArgs 含重复字段 ${JSON.stringify(rawName)}`,
- };
- }
- const schema = properties?.[rawName];
- const acceptsMediaRef =
- isPlainObject(schema) &&
- (schema.type === 'string' ||
- (schema.type === 'array' &&
- isPlainObject(schema.items) &&
- schema.items.type === 'string'));
- if (!acceptsMediaRef) {
- return {
- ok: false,
- reason: `tools[].attachmentArgs 字段 ${JSON.stringify(rawName)} 必须在 parameters.properties 中声明为 string 或 string[]`,
- };
- }
- seenAttachmentArgs.add(rawName);
- attachmentArgs.push(rawName);
- }
- }
tools.push({
name: t.name,
description: t.description,
...(t.parameters !== undefined
? { parameters: t.parameters as Record<string, unknown> }
: {}),
- ...(attachmentArgs !== undefined ? { attachmentArgs } : {}),
});
}
}