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。

plugins: hide page tools a plugin declares replaced by My browser

Dash6ca1674e35e5
diff --git a/apps/desktop/src/main/bootstrap-electron.ts b/apps/desktop/src/main/bootstrap-electron.ts
index d69a14494f..4d8972f35f 100644
--- a/apps/desktop/src/main/bootstrap-electron.ts
+++ b/apps/desktop/src/main/bootstrap-electron.ts
@@ -758,6 +758,7 @@ import {
setIsDetachedForBackend,
setUserBrowserPageControlProvider,
} from './mcp-integrations/browser.js';
+import { setPageControlGhostProvider } from './mcp-integrations/ghost.js';
import { RsbWindowController } from './right-sidebar-window/controller.js';
import { resolveRsbHostContextFromSession } from './right-sidebar-window/resolveHostContext.js';
import { createRightSidebarWindow } from './right-sidebar-window/window.js';
@@ -2504,6 +2505,8 @@ setIsDetachedForBackend(() => readRsbWindowSettings().detached);
// 「我的浏览器」后端经 browserExtension 插件槽拿页面控制桥接;槽归 cindy-brain,
// 这里倒置依赖,browser.ts 不反向 import 插件基座。
setUserBrowserPageControlProvider(() => getGhostBrowserExtensionSlot().getPageControl());
+// The plugin providing "My browser" hides its own page tools from agents: one way to drive the user's browser.
+setPageControlGhostProvider(() => getGhostBrowserExtensionSlot().getPageControl()?.ghostId ?? null);
setBrowserSessionUploadRootResolver(async (sessionId) => {
try {
const meta = await getMakerCore().getSessionMeta(sessionId);
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 29f11e9259..c80517ff85 100644
--- a/apps/desktop/src/main/mcp-integrations/__tests__/ghostWorkdirGate.test.ts
+++ b/apps/desktop/src/main/mcp-integrations/__tests__/ghostWorkdirGate.test.ts
@@ -272,7 +272,7 @@ vi.mock('../../plugin-contributions/prepared.js', () => ({
getPreparedContribution: (...args: unknown[]) => communityPreparedMock(...args),
}));
-const { authorizeDesktopSessionPath, getCindyGhostsMcpDeps, getGhostRosterPrompt } = await import('../ghost');
+const { authorizeDesktopSessionPath, getCindyGhostsMcpDeps, getGhostRosterPrompt, setPageControlGhostProvider } = await import('../ghost');
const { createCindyGhostsMcpServer, handleGhostList, handleGhostInfo, handleGhostCall, handleGhostManual } = await import('cindy-tools');
const { setGhostDisabledForWorkdir, listDisabledGhostIdsForWorkdir, isGhostDisabledForWorkdir } =
await import('../../cindy-brain/ghostWorkdirPrefs');
@@ -3693,3 +3693,46 @@ describe('personal contribution account surface', () => {
expect(communitySubmitMock).toHaveBeenCalledTimes(restrict ? 0 : 1);
});
});
+
+describe('「我的浏览器」取代插件自有页面工具', () => {
+ function pageControlGhost(): unknown {
+ return chipGhost('my-browser', ['tool'], {
+ tools: [
+ { name: 'browser_read', description: 'read' },
+ { name: 'browser_act', description: 'act' },
+ { name: 'browser_policy', description: 'policy' },
+ ],
+ manual: { items: [{ dir: 'manual/browser', name: 'browser', description: 'browser manual' }] },
+ browserExtension: {
+ protocol: 'cindy-browser-extension/3',
+ extensionIds: ['a'.repeat(32)],
+ pageControl: true,
+ pageControlReplaces: { tools: ['browser_read', 'browser_act'], manual: ['browser'] },
+ },
+ });
+ }
+ afterEach(() => setPageControlGhostProvider(() => null));
+
+ it('宿主经该插件提供页面控制时,只隐藏被取代的工具与手册;调用被引导到 browser 工具', async () => {
+ listMock.mockReturnValue([pageControlGhost()]);
+ setPageControlGhostProvider(() => 'my-browser');
+ const deps = makeDeps();
+ const [ghost] = await deps.listAwakeGhosts();
+ expect(ghost.tools.map((tool) => tool.name)).toEqual(['browser_policy']);
+ expect(ghost.manual ?? []).toEqual([]);
+ const refused = await deps.callGhostTool({ ghostId: 'my-browser', tool: 'browser_read', args: {} });
+ expect(refused).toMatchObject({ ok: false, errorCode: 'TOOL_NOT_FOUND', message: expect.stringContaining('user-browser') });
+ await expect(deps.readGhostManual({ ghostId: 'my-browser', path: 'browser/MANUAL.md' })).resolves.toMatchObject({
+ ok: false,
+ message: expect.stringContaining('browser 工具'),
+ });
+ expect(dispatchMock).not.toHaveBeenCalled();
+ });
+
+ it('桥接未运行(没有页面控制)时插件工具照常可见', async () => {
+ listMock.mockReturnValue([pageControlGhost()]);
+ const [ghost] = await makeDeps().listAwakeGhosts();
+ expect(ghost.tools.map((tool) => tool.name)).toEqual(['browser_read', 'browser_act', 'browser_policy']);
+ expect(ghost.manual?.map((item) => item.name)).toEqual(['browser']);
+ });
+});
diff --git a/apps/desktop/src/main/mcp-integrations/ghost.ts b/apps/desktop/src/main/mcp-integrations/ghost.ts
index f01ab7ffde..1dbaa9d63a 100644
--- a/apps/desktop/src/main/mcp-integrations/ghost.ts
+++ b/apps/desktop/src/main/mcp-integrations/ghost.ts
@@ -1672,6 +1672,23 @@ const ghostVisibilityDeps = {
isDisabledForWorkdir: isGhostDisabledForWorkdir,
};
+/**
+ * 「我的浏览器」由哪个插件提供(宿主正在经它的扩展承接页面控制)。该插件声明的
+ * pageControlReplaces 工具与手册此时对 Agent 隐藏:操作用户浏览器只留 Browser Use
+ * 一套。未接线或桥接未运行时返回 null,插件工具照常可用。
+ */
+let pageControlGhostProvider: () => string | null = () => null;
+export function setPageControlGhostProvider(provider: () => string | null): void {
+ pageControlGhostProvider = provider;
+}
+function pageControlHidden(ghost: InstalledGhost): { tools: Set<string>; manual: Set<string> } | null {
+ const replaces = ghost.manifest.browserExtension?.pageControlReplaces;
+ if (!replaces || pageControlGhostProvider() !== ghost.manifest.id) return null;
+ return { tools: new Set(replaces.tools), manual: new Set(replaces.manual ?? []) };
+}
+const PAGE_CONTROL_TOOL_MESSAGE =
+ '这个插件工具已由 Cindy 的 browser 工具取代:读取或操作用户自己的浏览器,请用 cindy_browser 的 browser 工具,浏览器目标选「我的浏览器」(user-browser)。';
+
function ghostRecall(ghost: InstalledGhost): string | undefined {
return ghost.manifest.whenToUse ?? ghost.manifest.description;
}
@@ -1694,6 +1711,7 @@ export function getGhostRosterPrompt({ workingDir }: { workingDir?: string }): s
function toCindyGhostInfo(ghost: InstalledGhost): CindyGhostInfo {
const recall = ghostRecall(ghost);
+ const hidden = pageControlHidden(ghost);
let setup: CindyGhostInfo['setup'];
try {
setup = getGhostSetupAssessment(installedGhostStoragePart(ghost));
@@ -1713,14 +1731,16 @@ function toCindyGhostInfo(ghost: InstalledGhost): CindyGhostInfo {
...(recall ? { recall } : {}),
...(ghost.manifest.manual
? {
- manual: ghost.manifest.manual.items.map(({ name, description }) => ({
- name,
- description,
- })),
+ manual: ghost.manifest.manual.items
+ .filter(({ name }) => !hidden?.manual.has(name))
+ .map(({ name, description }) => ({
+ name,
+ description,
+ })),
}
: {}),
...(setup ? { setup } : {}),
- tools: (ghost.manifest.tools ?? []).map((tool) => ({
+ tools: (ghost.manifest.tools ?? []).filter((tool) => !hidden?.tools.has(tool.name)).map((tool) => ({
name: tool.name,
description: tool.description,
...(tool.parameters ? { parameters: tool.parameters } : {}),
@@ -2087,6 +2107,10 @@ export function getCindyGhostsMcpDeps(
message: '该插件未声明可供读取的手册;不要重试,改用其它方式完成。',
};
}
+ const hiddenManual = pageControlHidden(visibility.ghost)?.manual;
+ if (hiddenManual?.size && hiddenManual.has(String(manualPath ?? '').split('/')[0])) {
+ return { ok: false, manual: [], content: '', errorCode: 'GHOST_NOT_FOUND', message: PAGE_CONTROL_TOOL_MESSAGE };
+ }
return readInstalledGhostManual(visibility.ghost, manualPath);
},
async callGhostTool({
@@ -2136,6 +2160,9 @@ export function getCindyGhostsMcpDeps(
// Runtime setup gate: the shared visibility check above runs before any
// durable attachment grant, directory ticket, sandbox, card call, or dispatch.
// grant_only never dispatches and intentionally ignores its tool field.
+ if (!grantOnly && pageControlHidden(target)?.tools.has(tool)) {
+ return { ok: false, errorCode: 'TOOL_NOT_FOUND', message: PAGE_CONTROL_TOOL_MESSAGE };
+ }
if (
!grantOnly &&
!(target.manifest.tools ?? []).some((candidate) => candidate.name === tool)
diff --git a/apps/desktop/src/shared/__tests__/ghost.test.ts b/apps/desktop/src/shared/__tests__/ghost.test.ts
index 50078cb521..cd5c6f4a49 100644
--- a/apps/desktop/src/shared/__tests__/ghost.test.ts
+++ b/apps/desktop/src/shared/__tests__/ghost.test.ts
@@ -5013,11 +5013,25 @@ describe('ghost · browserExtension 槽(2026-10-27 浏览器扩展经宿主桥
{ ...good, nativeHost: { name: 'com.example.browser', binary: '../outside' } },
{ ...good, pageControl: false },
{ ...good, pageControl: 'yes' },
+ { ...good, pageControlReplaces: { tools: 'browser_read' } },
+ { ...good, pageControlReplaces: { tools: ['bad name'] } },
+ { ...good, pageControlReplaces: { tools: ['browser_read'], manual: 'browser' } },
+ { protocol: good.protocol, extensionIds: [chromeId], pageControlReplaces: { tools: ['browser_read'] } },
]) {
expect(withNeeds(bad).ok, JSON.stringify(bad)).toBe(false);
}
});
+ it('pageControlReplaces 列出被「我的浏览器」取代的插件工具与手册,须与 pageControl 同时声明', () => {
+ const replaces = { tools: ['browser_read', 'browser_act'], manual: ['browser'] };
+ const ok = withNeeds({ ...good, pageControlReplaces: replaces });
+ expect(ok.ok, JSON.stringify(ok)).toBe(true);
+ if (!ok.ok) return;
+ expect(ok.manifest.browserExtension?.pageControlReplaces).toEqual(replaces);
+ expect(validateGhostManifest(ok.manifest)).toEqual(ok);
+ expect(withNeeds({ ...good, pageControlReplaces: { tools: [] } }).ok).toBe(true);
+ });
+
it('装入前展示为一项权限;页面控制用单独说明;id 子集与去掉页面控制是收权,新增 id 是扩权', () => {
const reviewed = withNeeds(good);
expect(reviewed.ok).toBe(true);
diff --git a/apps/desktop/src/shared/ghost.ts b/apps/desktop/src/shared/ghost.ts
index f35787d9a0..8c4cc53c6b 100644
--- a/apps/desktop/src/shared/ghost.ts
+++ b/apps/desktop/src/shared/ghost.ts
@@ -1115,6 +1115,12 @@ export interface GhostBrowserExtensionNeeds {
nativeHost?: { name: string; binary: string };
/** 扩展实现页面控制契约;Browser Use 据此把它列为用户浏览器执行端。 */
pageControl?: true;
+ /**
+ * 宿主承接页面控制后被取代的插件自有 Agent 工具与手册条目。宿主确实在经本插件
+ * 提供「我的浏览器」时,对 Agent 隐藏它们,只留一套操作用户浏览器的工具;
+ * 不认识此字段的旧宿主照常暴露。须同时声明 pageControl。
+ */
+ pageControlReplaces?: { tools: string[]; manual?: string[] };
}
/** skill 槽:单插件最多捆绑的 Agent Skill 数(范围越小越好,同 preview 精神)。 */
@@ -5029,12 +5035,38 @@ function validateGhostManifestInput(value: unknown, preserveHistoricalTasks: boo
if (needsRaw.pageControl !== undefined && needsRaw.pageControl !== true) {
return { ok: false, reason: 'browserExtension.pageControl 只能省略或为字面量 true' };
}
+ let pageControlReplaces: { tools: string[]; manual?: string[] } | undefined;
+ if (needsRaw.pageControlReplaces !== undefined) {
+ const raw = needsRaw.pageControlReplaces as Record<string, unknown> | null;
+ const names = (value: unknown) =>
+ Array.isArray(value) &&
+ value.length <= 32 &&
+ value.every((name) => typeof name === 'string' && /^[A-Za-z0-9_.-]{1,64}$/.test(name));
+ if (
+ needsRaw.pageControl !== true ||
+ !raw ||
+ typeof raw !== 'object' ||
+ Array.isArray(raw) ||
+ !names(raw.tools) ||
+ (raw.manual !== undefined && !names(raw.manual))
+ ) {
+ return {
+ ok: false,
+ reason: 'browserExtension.pageControlReplaces 须与 pageControl 同时声明,形如 {tools:[名称…], manual?:[名称…]}',
+ };
+ }
+ pageControlReplaces = {
+ tools: [...(raw.tools as string[])],
+ ...(raw.manual !== undefined ? { manual: [...(raw.manual as string[])] } : {}),
+ };
+ }
browserExtension = {
- ...unknownDeclarationFields(needsRaw, ['protocol', 'extensionIds', 'nativeHost', 'pageControl']),
+ ...unknownDeclarationFields(needsRaw, ['protocol', 'extensionIds', 'nativeHost', 'pageControl', 'pageControlReplaces']),
protocol: GHOST_BROWSER_EXTENSION_PROTOCOL,
extensionIds: needsRaw.extensionIds as string[],
...(nativeHost !== undefined ? { nativeHost } : {}),
...(needsRaw.pageControl === true ? { pageControl: true as const } : {}),
+ ...(pageControlReplaces !== undefined ? { pageControlReplaces } : {}),
};
}