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。

feat(agent): 关闭 Cindy 里看不到结果的下游 harness 输出能力

Dash5de80d3206ea
diff --git a/apps/desktop/src/main/maker-host/__tests__/capability-routing.test.ts b/apps/desktop/src/main/maker-host/__tests__/capability-routing.test.ts
index e7c39264c5..996f59f533 100644
--- a/apps/desktop/src/main/maker-host/__tests__/capability-routing.test.ts
+++ b/apps/desktop/src/main/maker-host/__tests__/capability-routing.test.ts
@@ -1,5 +1,7 @@
import { describe, expect, it } from 'vitest';
+import { findUnenforcedCapabilityRoutes } from '@cindy/maker-core';
+
import { buildDesktopCapabilityRoutingPolicy } from '../capability-routing.js';
function codexPluginRoutes(cindyBrowserEnabled: boolean, codexBrowserUseAvailable = true) {
@@ -10,7 +12,8 @@ function codexPluginRoutes(cindyBrowserEnabled: boolean, codexBrowserUseAvailabl
(override) =>
override.source.kind === 'harness-plugin'
&& override.source.harness === 'codex'
- && override.source.surface === 'plugin',
+ && override.source.surface === 'plugin'
+ && override.capabilityId !== 'output-delivery',
);
}
@@ -82,7 +85,9 @@ describe('buildDesktopCapabilityRoutingPolicy', () => {
});
const routes = policy.overrides.filter(
(route) =>
- route.source.id !== 'computer-use@openai-bundled' && route.source.surface === 'plugin',
+ route.source.id !== 'computer-use@openai-bundled'
+ && route.source.surface === 'plugin'
+ && route.capabilityId !== 'output-delivery',
);
expect(routes.map((route) => route.source.id)).toEqual([
@@ -140,3 +145,46 @@ describe('buildDesktopCapabilityRoutingPolicy', () => {
expect(browserRoutes[0]?.replacement).toBeUndefined();
});
});
+
+describe('desktop capability routing stays enforceable', () => {
+ const variants = [true, false, undefined].flatMap((cindyBrowserEnabled) =>
+ [true, false].flatMap((codexBrowserUseAvailable) =>
+ [true, false].flatMap((codexBrowserUseProvisioned) =>
+ [undefined, 'remote-1'].flatMap((remoteHostId) =>
+ [true, false].map((cindyComputerAvailable) => ({
+ cindyBrowserEnabled,
+ codexBrowserUseAvailable,
+ codexBrowserUseProvisioned,
+ remoteHostId,
+ cindyComputerAvailable,
+ })),
+ ),
+ ),
+ ),
+ );
+
+ it('only emits routes that a harness adapter applies', () => {
+ for (const variant of variants) {
+ expect(findUnenforcedCapabilityRoutes(buildDesktopCapabilityRoutingPolicy(variant)))
+ .toEqual([]);
+ }
+ });
+
+ it('hides vendor-UI output surfaces in every runtime', () => {
+ for (const variant of variants) {
+ const sources = buildDesktopCapabilityRoutingPolicy(variant).overrides
+ .filter((route) => route.capabilityId === 'output-delivery')
+ .map((route) => `${route.source.harness}:${route.source.surface}:${route.source.id}:${route.invocation}`);
+ expect(sources).toEqual([
+ 'claude-code:tool:SendUserFile:disabled',
+ 'claude-code:tool:Artifact:disabled',
+ 'claude-code:mcp:claude.ai Claude Docs:disabled',
+ 'claude-code:skill:artifact-design:disabled',
+ 'claude-code:skill:artifact-diagramming:disabled',
+ 'claude-code:skill:artifact-capabilities:disabled',
+ 'claude-code:skill:anthropic-skills:docs:disabled',
+ 'codex:plugin:visualize@openai-bundled:disabled',
+ ]);
+ }
+ });
+});
diff --git a/apps/desktop/src/main/maker-host/capability-routing.ts b/apps/desktop/src/main/maker-host/capability-routing.ts
index 19f29ff723..8cb3b3f225 100644
--- a/apps/desktop/src/main/maker-host/capability-routing.ts
+++ b/apps/desktop/src/main/maker-host/capability-routing.ts
@@ -19,6 +19,79 @@ const CODEX_COMPUTER_USE_REPLACEMENT_ROUTE = {
reason: 'Cindy owns desktop-control enablement, permissions, and execution.',
} as const satisfies CapabilityRouteOverride;
+const HARNESS_OUTPUT_UNAVAILABLE_REASON =
+ 'Its result is shown only in the vendor app, not in Cindy; Cindy delivers files, images, and pages itself.';
+
+function claudeSkillOutputOverride(
+ kind: 'harness-builtin' | 'harness-plugin',
+ id: string,
+) {
+ return {
+ capabilityId: 'output-delivery',
+ source: {
+ kind,
+ harness: 'claude-code',
+ surface: 'skill',
+ id,
+ },
+ invocation: 'disabled',
+ reason: HARNESS_OUTPUT_UNAVAILABLE_REASON,
+ } as const satisfies CapabilityRouteOverride;
+}
+
+/**
+ * Harness surfaces that deliver results to a vendor UI Cindy cannot show.
+ * Leaving them visible makes the model pick them over Cindy's own delivery
+ * (managed media, local file preview, Cindy plugins), and their long tool
+ * instructions also cost context on every request.
+ *
+ * Only names owned by the harness are listed here. Claude's generic `design`
+ * Skill is left alone: skill overrides match by name and would also disable a
+ * user's own `design` Skill.
+ */
+const HARNESS_OUTPUT_SURFACE_OVERRIDES = [
+ ...['SendUserFile', 'Artifact'].map((id) => ({
+ capabilityId: 'output-delivery',
+ source: {
+ kind: 'harness-builtin',
+ harness: 'claude-code',
+ surface: 'tool',
+ id,
+ },
+ invocation: 'disabled',
+ reason: HARNESS_OUTPUT_UNAVAILABLE_REASON,
+ } as const satisfies CapabilityRouteOverride)),
+ {
+ capabilityId: 'output-delivery',
+ source: {
+ kind: 'harness-builtin',
+ harness: 'claude-code',
+ surface: 'mcp',
+ // claude.ai account connector. Its instructions direct the model to the
+ // Artifact tool, so it is unusable once Artifact is disabled.
+ id: 'claude.ai Claude Docs',
+ },
+ invocation: 'disabled',
+ reason: HARNESS_OUTPUT_UNAVAILABLE_REASON,
+ },
+ ...['artifact-design', 'artifact-diagramming', 'artifact-capabilities'].map(
+ (id) => claudeSkillOutputOverride('harness-builtin', id),
+ ),
+ // Skill synced from the claude.ai account; it drives the Claude Docs connector.
+ claudeSkillOutputOverride('harness-plugin', 'anthropic-skills:docs'),
+ {
+ capabilityId: 'output-delivery',
+ source: {
+ kind: 'harness-plugin',
+ harness: 'codex',
+ surface: 'plugin',
+ id: 'visualize@openai-bundled',
+ },
+ invocation: 'disabled',
+ reason: HARNESS_OUTPUT_UNAVAILABLE_REASON,
+ },
+] as const satisfies CapabilityRoutingPolicy['overrides'];
+
/**
* Product-level arbitration for capability sources that collide inside Cindy.
*
@@ -130,6 +203,7 @@ export const DESKTOP_CAPABILITY_ROUTING_POLICY = {
invocation: 'disabled',
reason: 'The bundled Skill requires node_repl, which is unavailable in Cindy.',
},
+ ...HARNESS_OUTPUT_SURFACE_OVERRIDES,
],
} as const satisfies CapabilityRoutingPolicy;
diff --git a/docs/dev-rules/maker-core-and-agent-behavior.md b/docs/dev-rules/maker-core-and-agent-behavior.md
index b3c7d18753..efd9a3e754 100644
--- a/docs/dev-rules/maker-core-and-agent-behavior.md
+++ b/docs/dev-rules/maker-core-and-agent-behavior.md
@@ -300,6 +300,17 @@ sessionRunningRetry 就停。每次因 replacement 关闭而重新入队都计
- 打算用 prompt 解决某个问题前先自问:这件事用代码能不能做?能就用代码。
- 把本应由代码保证的确定性逻辑(格式校验、字段抽取、流程跳转、是否调用某个工具等)
交给模型自由发挥,会引入不可复现的行为漂移,属于本规则明确禁止的做法。
+- 下游 harness 自带的能力与 Cindy 重叠、或结果只在厂商自家界面可见(如 Claude Code 的
+ `SendUserFile`/`Artifact`、claude.ai 连接器、Codex 的 `visualize` 插件)时,不靠 prompt
+ 劝模型别用,而是在 host 能力路由表
+ (`apps/desktop/src/main/maker-host/capability-routing.ts`)加一条 `disabled` 路由,由各
+ harness 适配层从模型可见面移除:Claude 用 SDK `disallowedTools`、flag settings 的
+ `deniedMcpServers` 与 `skillOverrides`,Codex 用线程级 `plugins`/`mcp_servers`/
+ `skills.config`。各 harness 适配层用同一个判断函数决定能否执行某条路由并生成参数,
+ `findUnenforcedCapabilityRoutes`(`packages/maker-core/src/agents/capability-route-support.ts`)
+ 直接复用这些判断;路由表里有执行不了的规则(来源类型不对、缺必填字段、Pi 等没有适配的
+ harness)会被测试拦下,不会静默失效。Skill 覆盖按名字匹配,`design` 这类通用名会误伤用户同名 Skill,只关 harness
+ 专属名字。
- Cindy 的目标模式由 `goal-host` 统一管理续跑、预算与暂停/恢复。Codex 创建和恢复线程时
使用会话级 `features.goals=false`,避免模型另建原生目标,形成绕过宿主调度与来源标记的
第二套循环;不写用户的全局 Codex 配置。不能仅把无来源事件改判为目标事件,否则用户
diff --git a/packages/maker-core/src/agents/__tests__/capability-route-support.test.ts b/packages/maker-core/src/agents/__tests__/capability-route-support.test.ts
new file mode 100644
index 0000000000..ee8289e274
--- /dev/null
+++ b/packages/maker-core/src/agents/__tests__/capability-route-support.test.ts
@@ -0,0 +1,149 @@
+import { describe, expect, it } from 'vitest';
+
+import type {
+ CapabilityInvocationPolicy,
+ CapabilityRouteOverride,
+ CapabilitySurface,
+} from '../../types/capability-routing.js';
+import { findUnenforcedCapabilityRoutes } from '../capability-route-support.js';
+import {
+ buildClaudeDeniedMcpServers,
+ buildClaudeDisallowedTools,
+ buildClaudeRemoteToolGuards,
+ buildClaudeSkillOverrides,
+} from '../claude-code/capability-routing.js';
+import {
+ buildCodexCapabilityConfigOverrides,
+ buildCodexCapabilitySkillConfigOverrides,
+} from '../codex/capability-routing.js';
+
+const SURFACES: CapabilitySurface[] = ['skill', 'plugin', 'mcp', 'app', 'tool'];
+const INVOCATIONS: CapabilityInvocationPolicy[] = ['auto', 'explicit-only', 'disabled'];
+const IDENTITIES = [
+ { id: 'visualize@openai-bundled' },
+ { id: 'Artifact' },
+ { id: 'server', containerId: 'tools@market' },
+ { id: 'server', containerId: 'tools@market', artifactId: 'server' },
+ { id: 'routed-server', containerId: 'tools@market', artifactId: 'server' },
+ { id: 'tools:skill', containerId: 'not-a-plugin-id', artifactId: 'skill' },
+];
+
+function candidateRoutes(): CapabilityRouteOverride[] {
+ return ['claude-code', 'codex', 'pi'].flatMap((harness) =>
+ (['harness-builtin', 'harness-plugin'] as const).flatMap((kind) =>
+ SURFACES.flatMap((surface) =>
+ INVOCATIONS.flatMap((invocation) =>
+ IDENTITIES.map((identity) => ({
+ capabilityId: 'contract',
+ source: { kind, harness, surface, ...identity },
+ invocation,
+ })),
+ ),
+ ),
+ ),
+ );
+}
+
+function hasClaudeEffect(route: CapabilityRouteOverride): boolean {
+ const policy = { overrides: [route] };
+ return (
+ Object.keys(buildClaudeSkillOverrides(policy)).length > 0 ||
+ buildClaudeDisallowedTools(policy).length > 0 ||
+ buildClaudeDeniedMcpServers(policy).length > 0 ||
+ buildClaudeRemoteToolGuards(policy).length > 0
+ );
+}
+
+/** Codex must apply the route without throwing, locally and remotely. */
+function hasCodexEffect(route: CapabilityRouteOverride): boolean {
+ const policy = { overrides: [route] };
+ try {
+ const remote = buildCodexCapabilityConfigOverrides(policy, { isolatedPluginOverlays: false });
+ const local = buildCodexCapabilityConfigOverrides(policy, { isolatedPluginOverlays: true });
+ const pluginId = route.source.surface === 'plugin' ? route.source.id : route.source.containerId;
+ const [name, marketplace] = (pluginId ?? 'x@y').split('@');
+ const skills = buildCodexCapabilitySkillConfigOverrides(policy, [{
+ path: `/codex/plugins/cache/${marketplace}/${name}/1.0.0/skills/${route.source.artifactId ?? 'skill'}/SKILL.md`,
+ enabled: true,
+ }]);
+ if (route.invocation === 'explicit-only') {
+ // Local explicit-only sources are narrowed by the desktop plugin overlay.
+ return Object.keys(remote).length > 0;
+ }
+ // A disabled Skill is hidden through Skill config; plugins and MCP servers
+ // through thread config, in both runtimes.
+ if (route.source.surface === 'skill') return Object.keys(skills).length > 0;
+ return Object.keys(remote).length > 0 && Object.keys(local).length > 0;
+ } catch {
+ return false;
+ }
+}
+
+describe('findUnenforcedCapabilityRoutes', () => {
+ it('accepts a route only when its harness adapter produces a control for it', () => {
+ for (const route of candidateRoutes()) {
+ const accepted = findUnenforcedCapabilityRoutes({ overrides: [route] }).length === 0;
+ if (!accepted) continue;
+ const effect = route.source.harness === 'claude-code'
+ ? hasClaudeEffect(route)
+ : route.source.harness === 'codex'
+ ? hasCodexEffect(route)
+ : false;
+ expect({ route, effect }).toEqual({ route, effect: true });
+ }
+ });
+
+ it('rejects a disabled route whenever its adapter would ignore or reject it', () => {
+ for (const route of candidateRoutes().filter((r) => r.invocation === 'disabled')) {
+ const accepted = findUnenforcedCapabilityRoutes({ overrides: [route] }).length === 0;
+ const effect = route.source.harness === 'claude-code'
+ ? hasClaudeEffect(route)
+ : route.source.harness === 'codex'
+ ? hasCodexEffect(route)
+ : false;
+ expect({ route, accepted }).toEqual({ route, accepted: effect });
+ }
+ });
+
+ it('rejects the wrong source kind, missing identity fields, Pi and unknown harnesses', () => {
+ const rejected: CapabilityRouteOverride[] = [
+ {
+ capabilityId: 'output-delivery',
+ source: { kind: 'harness-builtin', harness: 'codex', surface: 'plugin', id: 'visualize@openai-bundled' },
+ invocation: 'disabled',
+ },
+ {
+ capabilityId: 'computer-use',
+ source: { kind: 'harness-plugin', harness: 'codex', surface: 'skill', id: 'computer-use:computer-use', artifactId: 'computer-use' },
+ invocation: 'disabled',
+ },
+ {
+ capabilityId: 'output-delivery',
+ source: { kind: 'harness-plugin', harness: 'claude-code', surface: 'tool', id: 'Artifact' },
+ invocation: 'disabled',
+ },
+ {
+ capabilityId: 'output-delivery',
+ source: { kind: 'harness-builtin', harness: 'claude-code', surface: 'tool', id: 'Artifact' },
+ invocation: 'explicit-only',
+ },
+ {
+ capabilityId: 'output-delivery',
+ source: { kind: 'harness-builtin', harness: 'pi', surface: 'tool', id: 'write' },
+ invocation: 'disabled',
+ },
+ {
+ capabilityId: 'output-delivery',
+ source: { kind: 'harness-builtin', harness: 'future-harness', surface: 'tool', id: 'x' },
+ invocation: 'disabled',
+ },
+ {
+ capabilityId: 'output-delivery',
+ source: { kind: 'user-skill', surface: 'skill', id: 'design' },
+ invocation: 'disabled',
+ },
+ ];
+
+ expect(findUnenforcedCapabilityRoutes({ overrides: rejected })).toEqual(rejected);
+ });
+});
diff --git a/packages/maker-core/src/agents/capability-route-support.ts b/packages/maker-core/src/agents/capability-route-support.ts
new file mode 100644
index 0000000000..c8080894dc
--- /dev/null
+++ b/packages/maker-core/src/agents/capability-route-support.ts
@@ -0,0 +1,33 @@
+import type {
+ CapabilityRouteOverride,
+ CapabilityRoutingPolicy,
+} from '../types/capability-routing.js';
+import { isClaudeCapabilityRouteEnforced } from './claude-code/capability-routing.js';
+import { isCodexCapabilityRouteEnforced } from './codex/capability-routing.js';
+
+/**
+ * Each harness adapter's own enforcement predicate. Pi exposes no
+ * harness-owned capability that overlaps Cindy today, so it accepts no routes.
+ */
+const CAPABILITY_ROUTE_ENFORCERS: Readonly<
+ Record<string, (directive: CapabilityRouteOverride) => boolean>
+> = {
+ 'claude-code': isClaudeCapabilityRouteEnforced,
+ codex: isCodexCapabilityRouteEnforced,
+ pi: () => false,
+};
+
+/**
+ * Routes that no harness adapter would apply. A host policy must return an
+ * empty list; anything else would be silently ignored or fail at startup.
+ */
+export function findUnenforcedCapabilityRoutes(
+ policy: CapabilityRoutingPolicy | undefined,
+): CapabilityRouteOverride[] {
+ return (policy?.overrides ?? []).filter((directive) => {
+ const enforce = directive.source.harness
+ ? CAPABILITY_ROUTE_ENFORCERS[directive.source.harness]
+ : undefined;
+ return !enforce?.(directive);
+ });
+}
diff --git a/packages/maker-core/src/agents/claude-code/__tests__/capability-routing.test.ts b/packages/maker-core/src/agents/claude-code/__tests__/capability-routing.test.ts
index c07b414dc9..1696e7b1ba 100644
--- a/packages/maker-core/src/agents/claude-code/__tests__/capability-routing.test.ts
+++ b/packages/maker-core/src/agents/claude-code/__tests__/capability-routing.test.ts
@@ -3,6 +3,8 @@ import { describe, expect, it } from 'vitest';
import type { CapabilityRoutingPolicy } from '../../../types/capability-routing.js';
import {
buildClaudeAskUserQuestionCallerProvenanceHooks,
+ buildClaudeDeniedMcpServers,
+ buildClaudeDisallowedTools,
buildClaudeOrcaCallerProvenanceHooks,
buildClaudeRemoteOrcaCallerGuards,
buildClaudeRemoteRootOnlyToolGuards,
@@ -163,6 +165,45 @@ describe('buildClaudeSkillOverrides', () => {
});
});
+describe('Claude disabled built-in surfaces', () => {
+ const policy = {
+ overrides: [
+ {
+ capabilityId: 'output-delivery',
+ source: { kind: 'harness-builtin', harness: 'claude-code', surface: 'tool', id: 'Artifact' },
+ invocation: 'disabled',
+ },
+ {
+ capabilityId: 'output-delivery',
+ source: { kind: 'harness-builtin', harness: 'claude-code', surface: 'mcp', id: 'claude.ai Claude Docs' },
+ invocation: 'disabled',
+ },
+ {
+ capabilityId: 'feishu',
+ source: { kind: 'harness-plugin', harness: 'claude-code', surface: 'mcp', id: 'plugin:feishu-delegate:feishu-delegate' },
+ invocation: 'explicit-only',
+ },
+ {
+ capabilityId: 'output-delivery',
+ source: { kind: 'harness-builtin', harness: 'codex', surface: 'tool', id: 'view_image' },
+ invocation: 'disabled',
+ },
+ ],
+ } as const satisfies CapabilityRoutingPolicy;
+
+ it('maps disabled tools to SDK disallowedTools', () => {
+ expect(buildClaudeDisallowedTools(policy)).toEqual(['Artifact']);
+ expect(buildClaudeDisallowedTools(undefined)).toEqual([]);
+ });
+
+ it('denies a disabled MCP server by name so its instructions leave the prompt too', () => {
+ expect(buildClaudeDeniedMcpServers(policy)).toEqual([
+ { serverName: 'claude.ai Claude Docs' },
+ ]);
+ expect(buildClaudeDeniedMcpServers(undefined)).toEqual([]);
+ });
+});
+
describe('buildClaudeRemoteToolGuards', () => {
it('serializes only non-auto Claude MCP routes with the real plugin prefix', () => {
const policy = {
diff --git a/packages/maker-core/src/agents/claude-code/__tests__/flag-settings.test.ts b/packages/maker-core/src/agents/claude-code/__tests__/flag-settings.test.ts
index 44b7970d63..1f9703fbfb 100644
--- a/packages/maker-core/src/agents/claude-code/__tests__/flag-settings.test.ts
+++ b/packages/maker-core/src/agents/claude-code/__tests__/flag-settings.test.ts
@@ -89,6 +89,31 @@ describe('buildClaudeFlagSettings', () => {
});
});
+ it('denies disabled downstream MCP servers from the host routing policy', () => {
+ const settings = buildClaudeFlagSettings({
+ showThinkingSummaries: false,
+ fastMode: false,
+ capabilityRouting: {
+ overrides: [
+ {
+ capabilityId: 'output-delivery',
+ source: {
+ kind: 'harness-builtin',
+ harness: 'claude-code',
+ surface: 'mcp',
+ id: 'claude.ai Claude Docs',
+ },
+ invocation: 'disabled',
+ },
+ ],
+ },
+ });
+
+ expect(settings.deniedMcpServers).toEqual([{ serverName: 'claude.ai Claude Docs' }]);
+ expect(buildClaudeFlagSettings({ showThinkingSummaries: false, fastMode: false }))
+ .not.toHaveProperty('deniedMcpServers');
+ });
+
it('enforces a Bot Skill allowlist with native Claude skill overrides', () => {
const settings = buildClaudeFlagSettings({
showThinkingSummaries: false,
diff --git a/packages/maker-core/src/agents/claude-code/__tests__/mcp-approval-policy.test.ts b/packages/maker-core/src/agents/claude-code/__tests__/mcp-approval-policy.test.ts
index 8d550cee35..e8a39962e2 100644
--- a/packages/maker-core/src/agents/claude-code/__tests__/mcp-approval-policy.test.ts
+++ b/packages/maker-core/src/agents/claude-code/__tests__/mcp-approval-policy.test.ts
@@ -293,7 +293,37 @@ afterEach(async () => {
await Promise.all(tempDirs.splice(0).map((dir) => fs.rm(dir, { recursive: true, force: true })));
});
+const OUTPUT_DELIVERY_ROUTING = {
+ overrides: [
+ {
+ capabilityId: 'output-delivery',
+ source: { kind: 'harness-builtin', harness: 'claude-code', surface: 'tool', id: 'Artifact' },
+ invocation: 'disabled',
+ },
+ {
+ capabilityId: 'output-delivery',
+ source: { kind: 'harness-builtin', harness: 'claude-code', surface: 'mcp', id: 'claude.ai Claude Docs' },
+ invocation: 'disabled',
+ },
+ ],
+} as const satisfies CapabilityRoutingPolicy;
+
describe('ClaudeCodeAgent canUseTool honors the host MCP approval policy', () => {
+ it('removes host-disabled built-in tools and MCP servers from a local session', async () => {
+ const { handle } = await startSession(undefined, {
+ capabilityRouting: OUTPUT_DELIVERY_ROUTING,
+ });
+ const options = sdkMock.query.mock.calls.at(-1)?.[0]?.options as {
+ disallowedTools?: string[];
+ settings?: { deniedMcpServers?: unknown };
+ };
+
+ expect(options.disallowedTools).toEqual(['Artifact']);
+ expect(options.settings?.deniedMcpServers).toEqual([
+ { serverName: 'claude.ai Claude Docs' },
+ ]);
+ await handle.close();
+ });
it('captures known writes before execution and marks Bash opaque only after execution', async () => {
const beforeKnownFileWrite = vi.fn(async () => undefined);
const noteOpaqueWrite = vi.fn();
@@ -1998,3 +2028,32 @@ describe('remote sessions share the same permission semantics', () => {
await failed.handle.close();
});
});
+
+describe('remote sessions apply host-disabled built-in surfaces', () => {
+ it('passes disallowed tools and denied MCP servers to the remote daemon', async () => {
+ const config = await makeTempDir();
+ process.env.CLAUDE_CONFIG_DIR = config;
+ const workingDir = await makeTempDir();
+ let startParams: Record<string, unknown> | undefined;
+ const deps = createDeps(() => 'auto-approve');
+ deps.capabilityRouting = OUTPUT_DELIVERY_ROUTING;
+ deps.remoteCcQueryFactory = (async (args: { startParams: Record<string, unknown> }) => {
+ startParams = args.startParams;
+ return createFakeQuery() as never;
+ }) as NonNullable<AgentDeps['remoteCcQueryFactory']>;
+ const handle = await new ClaudeCodeAgent(deps).startSession({
+ sessionId: 'session-remote-output-routing',
+ model: 'claude-opus-4-6',
+ workingDir,
+ remoteHostId: 'remote-1',
+ permissionMode: 'default',
+ });
+
+ expect(startParams?.disallowedTools).toEqual(['Artifact']);
+ expect(
+ (startParams?.extraOptions as { settings?: { deniedMcpServers?: unknown } })
+ ?.settings?.deniedMcpServers,
+ ).toEqual([{ serverName: 'claude.ai Claude Docs' }]);
+ await handle.close();
+ });
+});
diff --git a/packages/maker-core/src/agents/claude-code/capability-routing.ts b/packages/maker-core/src/agents/claude-code/capability-routing.ts
index e05e7e67c6..b4cf41808b 100644
--- a/packages/maker-core/src/agents/claude-code/capability-routing.ts
+++ b/packages/maker-core/src/agents/claude-code/capability-routing.ts
@@ -67,9 +67,7 @@ export function buildClaudeAskUserQuestionCallerProvenanceHooks(): Partial<Recor
function isClaudeSkillDirective(directive: CapabilityRouteOverride): boolean {
return (
directive.source.surface === 'skill' &&
- directive.source.harness === CLAUDE_CODE_HARNESS_ID &&
- (directive.source.kind === 'harness-builtin' ||
- directive.source.kind === 'harness-plugin')
+ isClaudeCapabilityRouteEnforced(directive)
);
}
@@ -102,6 +100,73 @@ export function buildClaudeSkillOverrides(
return overrides;
}
+/**
+ * Whether this adapter turns a host route into a Claude Code control. The
+ * builders below select routes through this same predicate, so the route
+ * support check cannot drift from what is actually applied.
+ */
+export function isClaudeCapabilityRouteEnforced(
+ directive: CapabilityRouteOverride,
+): boolean {
+ if (
+ !isHarnessOwnedCapabilitySource(directive.source) ||
+ directive.source.harness !== CLAUDE_CODE_HARNESS_ID
+ ) {
+ return false;
+ }
+ switch (directive.source.surface) {
+ case 'skill':
+ return true;
+ case 'mcp':
+ return directive.invocation !== 'auto';
+ case 'tool':
+ // Claude can only remove a built-in tool outright; plugin tools are MCP.
+ return (
+ directive.source.kind === 'harness-builtin' &&
+ directive.invocation === 'disabled'
+ );
+ default:
+ return false;
+ }
+}
+
+function isDisabledClaudeSource(
+ directive: CapabilityRouteOverride,
+ surface: 'tool' | 'mcp',
+): boolean {
+ return (
+ isClaudeCapabilityRouteEnforced(directive) &&
+ directive.source.surface === surface &&
+ directive.invocation === 'disabled'
+ );
+}
+
+/**
+ * Disabled Claude built-in tools, passed as SDK `disallowedTools`. Claude Code
+ * drops a disallowed tool and its description from the model-facing list.
+ */
+export function buildClaudeDisallowedTools(
+ policy: CapabilityRoutingPolicy | undefined,
+): string[] {
+ return (policy?.overrides ?? [])
+ .filter((directive) => isDisabledClaudeSource(directive, 'tool'))
+ .map((directive) => directive.source.id);
+}
+
+/**
+ * Disabled MCP servers, passed as flag-settings `deniedMcpServers`. Denying
+ * only the server's tools would leave its server instructions in the prompt;
+ * a denied server is never connected. Claude merges this list with the user's
+ * own deny list instead of replacing it.
+ */
+export function buildClaudeDeniedMcpServers(
+ policy: CapabilityRoutingPolicy | undefined,
+): Array<{ serverName: string }> {
+ return (policy?.overrides ?? [])
+ .filter((directive) => isDisabledClaudeSource(directive, 'mcp'))
+ .map((directive) => ({ serverName: directive.source.id }));
+}
+
export interface ClaudeRemoteToolGuard {
toolNamePrefix: string;
sourceServerId: string;
@@ -144,10 +209,8 @@ export function buildClaudeRemoteToolGuards(
if (!policy) return [];
return policy.overrides.flatMap((directive) => {
if (
- !isHarnessOwnedCapabilitySource(directive.source) ||
- directive.source.harness !== CLAUDE_CODE_HARNESS_ID ||
directive.source.surface !== 'mcp' ||
- directive.invocation === 'auto'
+ !isClaudeCapabilityRouteEnforced(directive)
) {
return [];
}
@@ -181,10 +244,8 @@ export function buildClaudeLocalToolGuardHooks(
if (
!policy?.overrides.some(
(directive) =>
- isHarnessOwnedCapabilitySource(directive.source) &&
- directive.source.harness === CLAUDE_CODE_HARNESS_ID &&
directive.source.surface === 'mcp' &&
- directive.invocation !== 'auto',
+ isClaudeCapabilityRouteEnforced(directive),
)
) {
return {};
diff --git a/packages/maker-core/src/agents/claude-code/flag-settings.ts b/packages/maker-core/src/agents/claude-code/flag-settings.ts
index 6d2ce41ce2..346eb8ad51 100644
--- a/packages/maker-core/src/agents/claude-code/flag-settings.ts
+++ b/packages/maker-core/src/agents/claude-code/flag-settings.ts
@@ -41,7 +41,10 @@
import type { Settings } from '@anthropic-ai/claude-agent-sdk';
import type { CapabilityRoutingPolicy } from '../../types/capability-routing.js';
import type { BotRuntimeSkillPolicy } from '../base-agent.js';
-import { buildClaudeSkillOverrides } from './capability-routing.js';
+import {
+ buildClaudeDeniedMcpServers,
+ buildClaudeSkillOverrides,
+} from './capability-routing.js';
export interface ClaudeFlagSettingsInput {
/** reasoning summary 展示开关(displayReasoning === 'summarized')。 */
@@ -87,6 +90,7 @@ export function buildClaudeFlagSettings(input: ClaudeFlagSettingsInput): Setting
// Host routing is a security boundary and therefore wins over a Bot's
// allowlist when both address the same Skill.
Object.assign(skillOverrides, buildClaudeSkillOverrides(input.capabilityRouting));
+ const deniedMcpServers = buildClaudeDeniedMcpServers(input.capabilityRouting);
return {
showThinkingSummaries: input.showThinkingSummaries,
// 屏蔽用户级 apiKeyHelper,防止它劫持 oauth-spawn 的订阅鉴权(见文件头注释)。
@@ -105,5 +109,6 @@ export function buildClaudeFlagSettings(input: ClaudeFlagSettingsInput): Setting
availableModels: [...new Set(input.availableModels)],
}),
...(Object.keys(skillOverrides).length > 0 && { skillOverrides }),
+ ...(deniedMcpServers.length > 0 && { deniedMcpServers }),
};
}
diff --git a/packages/maker-core/src/agents/claude-code/index.ts b/packages/maker-core/src/agents/claude-code/index.ts
index ae74a737e6..91a5416fd0 100644
--- a/packages/maker-core/src/agents/claude-code/index.ts
+++ b/packages/maker-core/src/agents/claude-code/index.ts
@@ -143,6 +143,7 @@ import {
import { buildClaudeFlagSettings } from './flag-settings.js';
import {
buildClaudeAskUserQuestionCallerProvenanceHooks,
+ buildClaudeDisallowedTools,
buildClaudeOrcaCallerProvenanceHooks,
buildClaudeLocalToolGuardHooks,
buildClaudeRemoteOrcaCallerGuards,
@@ -1803,6 +1804,12 @@ export class ClaudeCodeAgent extends BaseAgent {
: this.deps.claudeAllowedTools?.length
? [...this.deps.claudeAllowedTools]
: undefined;
+ // 与 Cindy 重复且结果在 Cindy 里看不到的 Claude 自带工具(host 路由表决定),
+ // 加上设备托管时交给 cindy_exec 顶替的本机工具。启动时快照, 整条会话不变。
+ const claudeDisallowedTools = [...new Set([
+ ...(hosted ? DEVICE_HOSTED_DISALLOWED_CLAUDE_TOOLS : []),
+ ...buildClaudeDisallowedTools(reviewMode ? undefined : this.deps.capabilityRouting),
+ ])];
/**
* 本 session 实际注册进 SDK 的 MCP server 名, 由 buildMcpServers 写入。
* canUseTool 用它把 `mcp__<server>__<tool>` 归属到唯一 server; 空集合时
@@ -3768,6 +3775,9 @@ export class ClaudeCodeAgent extends BaseAgent {
// cc-manager 的 QueryStartParams 已原生支持 allowedTools; 传副本避免 RPC
// 序列化前后任一侧原地改写 session 快照。
...(claudeAllowedTools ? { allowedTools: [...claudeAllowedTools] } : {}),
+ ...(claudeDisallowedTools.length > 0
+ ? { disallowedTools: [...claudeDisallowedTools] }
+ : {}),
...(remoteToolGuards.length > 0
? { toolGuards: remoteToolGuards }
: {}),
@@ -4399,8 +4409,11 @@ export class ClaudeCodeAgent extends BaseAgent {
// Bot MCP selection is explicit; native delegation remains available.
// 设备托管:只用经隧道的 MCP(本机用户 / 项目里的 MCP 启动命令会在本机执行)。
...(opts.botRuntimeProfile || hosted ? { strictMcpConfig: true } : {}),
- // 设备托管:自带文件与命令工具只能操作本机,关掉,由 cindy_exec 顶替。
- ...(hosted ? { disallowedTools: [...DEVICE_HOSTED_DISALLOWED_CLAUDE_TOOLS] } : {}),
+ // 设备托管:自带文件与命令工具只能操作本机,关掉,由 cindy_exec 顶替;
+ // 另含 host 路由表关闭的自带工具(见 claudeDisallowedTools)。
+ ...(claudeDisallowedTools.length > 0
+ ? { disallowedTools: [...claudeDisallowedTools] }
+ : {}),
// 受邀者(另一个账号):自带工具只开白名单里的,其余都作用于本机或本机用户的账号。
...(hosted?.guest ? { tools: [...DEVICE_HOSTED_GUEST_CLAUDE_TOOLS] } : {}),
// 设备托管:个人配置(用户级设置、hooks)属于任务所在电脑,不加载本机用户级设置;
diff --git a/packages/maker-core/src/agents/codex/capability-routing.ts b/packages/maker-core/src/agents/codex/capability-routing.ts
index 9adf0b4918..0934439f64 100644
--- a/packages/maker-core/src/agents/codex/capability-routing.ts
+++ b/packages/maker-core/src/agents/codex/capability-routing.ts
@@ -212,6 +212,41 @@ function isSkillFromPluginDistribution(
return false;
}
+function hasCodexPluginIdentity(pluginId: string | undefined): boolean {
+ return !!pluginId && parseCodexPluginCacheIdentity(pluginId) !== null;
+}
+
+/**
+ * Whether Codex enforces a host route: through thread config and Skill config
+ * here, or through the desktop's provenance-preserving plugin overlay for
+ * explicit-only sources. Keep this in step with those builders; a route that
+ * fails it would be ignored or rejected at session start.
+ */
+export function isCodexCapabilityRouteEnforced(
+ directive: CapabilityRouteOverride,
+): boolean {
+ if (!isCodexHarnessPluginDirective(directive)) return false;
+ const { surface, id, containerId, artifactId } = directive.source;
+ if (directive.invocation === 'disabled') {
+ switch (surface) {
+ case 'plugin':
+ return hasCodexPluginIdentity(id);
+ case 'skill':
+ return hasCodexPluginIdentity(containerId) && !!artifactId;
+ case 'mcp':
+ return true;
+ default:
+ return false;
+ }
+ }
+ if (directive.invocation === 'explicit-only') {
+ if (!hasCodexPluginIdentity(containerId)) return false;
+ if (surface === 'skill') return true;
+ if (surface === 'mcp') return !!artifactId && artifactId !== id;
+ }
+ return false;
+}
+
/**
* Remove replacement-arbitration routes that the selected Codex host cannot
* satisfy. Compatibility-only restrictions without a replacement remain in
diff --git a/packages/maker-core/src/agents/index.ts b/packages/maker-core/src/agents/index.ts
index 46592dc375..1616e25713 100644
--- a/packages/maker-core/src/agents/index.ts
+++ b/packages/maker-core/src/agents/index.ts
@@ -12,6 +12,7 @@ export type {
ClaudeSubagentModelAccessStatus,
} from './claude-code/subagent-model-access.js';
export { CodexAgent } from './codex/index.js';
+export { findUnenforcedCapabilityRoutes } from './capability-route-support.js';
export { isCodexHistoryRecoveryRequired } from './codex/history-recovery.js';
export {
CODEX_HISTORY_OVERSIZED_REASON,