Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(plugins): 在 Harness 输出前复用工具参数脱敏
liugaoweid9ef20283fc0
diff --git a/apps/desktop/src/main/cindy-brain/__tests__/harnessSlot.test.ts b/apps/desktop/src/main/cindy-brain/__tests__/harnessSlot.test.tsindex 6ca14be360..c7c77e630b 100644--- a/apps/desktop/src/main/cindy-brain/__tests__/harnessSlot.test.ts+++ b/apps/desktop/src/main/cindy-brain/__tests__/harnessSlot.test.ts@@ -1,5 +1,5 @@import { afterEach, describe, expect, it, vi } from 'vitest';-import type { AgentEvent, HarnessHookHandler, Session } from '@cindy/maker-core';+import type { AgentEvent, HarnessHookHandler, HarnessHookRequest, Session } from '@cindy/maker-core';import type { GhostPipeHarnessEvent } from '@cindy/plugin-protocol';import { GhostHarnessSlot } from '../harnessSlot.js';import { GhostSubscriptionGateway } from '../subscriptionGateway.js';@@ -83,10 +83,12 @@ function fixture(remote: { remoteHostId?: string; agentDeviceId?: string } = {})items: [],nextCursor: null,}));+ const redactToolInput = vi.fn((_toolName: string, input: unknown) => input);const slot = new GhostHarnessSlot({listGhosts: () => ghosts,eligible,readHistory,+ redactToolInput,ownerScope: { capture: () => 1, isCurrent: () => owner, isStable: () => owner },isRunning: () => true,captureSource: () => () => true,@@ -111,10 +113,12 @@ function fixture(remote: { remoteHostId?: string; agentDeviceId?: string } = {})guards,eligible,readHistory,+ redactToolInput,session,dispose,emit: (event: AgentEvent) => observe!(event),- screen: () => hook!({ name: 'permission.request', toolName: 'write' }),+ screen: (request: HarnessHookRequest = { name: 'permission.request', toolName: 'write' }) =>+ hook!(request),changeOwner: () => {owner = false;},@@ -423,6 +427,55 @@ describe('Harness host bridge', () => {f.dispose();});+ // Session events and native hooks carry raw arguments, unlike saved history.+ // Both new plugin exits must apply the injected, canonical boundary redactor.+ it.each(['event', 'tool.before'] as const)('redacts raw tool input before delivering %s', async (path) => {+ const f = fixture();+ f.ghosts[1].enabled = false;+ f.ghosts[0].manifest.harness!.read!.push('tool-content');+ f.ghosts[0].manifest.harness!.hooks!.push('tool.before');+ f.ghosts[0].harnessCapabilityApproved!.push(+ 'harness:read:tool-content', 'harness:hooks:tool.before',+ );+ const toolName = 'mcp__cindy_browser__call_tool';+ const input = { name: 'browser', args: { proxyServer: 'http://qa-user:[email protected]:8080' } };+ const safeInput = { name: 'browser', args: { proxyServer: '[REDACTED]' } };+ f.redactToolInput.mockReturnValue(safeInput);+ await f.slot.handleRequest('a', { kind: 'read', name: 'runtime', sessionId: 's' }, () => true);+ let decision: ReturnType<HarnessHookHandler> | undefined;+ try {+ let delivered: GhostPipeEventPush;+ if (path === 'event') {+ const send = vi.fn();+ const gateway = new GhostSubscriptionGateway({+ listGhosts: () => f.ghosts,+ isRunning: () => true,+ wake: async () => {},+ sendToGhost: send,+ now: () => 1,+ });+ f.emit({ type: 'tool_use', data: { toolUseId: 'browser-proxy', toolName, input } });+ f.events.forEach((event, index) => gateway.publishHarness(event, f.guards[index]));+ expect(send).toHaveBeenCalledOnce();+ delivered = send.mock.calls[0][1];+ } else {+ decision = f.screen({ name: 'tool.before', toolName, input });+ await vi.waitFor(() => expect(f.messages).toHaveLength(1));+ delivered = f.messages[0].payload;+ if (delivered.type !== 'harness-hook') throw new Error('expected hook');+ f.slot.handleVerdict('a', { hookId: delivered.hookId, action: 'continue' });+ expect(await decision).toEqual({ action: 'continue' });+ }+ expect(delivered).toMatchObject({ data: { content: { toolName, input: safeInput } } });+ expect(f.redactToolInput).toHaveBeenCalledExactlyOnceWith(toolName, input);+ expect(JSON.stringify(delivered)).not.toContain('qa-password');+ expect(input.args.proxyServer).toContain('qa-password');+ } finally {+ f.dispose();+ await decision;+ }+ });+// Unit contract from docs/plugin-harness-bridge.md: task signals must reach// only approved recipients and keep one opaque task identity across updates.// Existing event tests cover tools/compaction, not this payload. The minimaldiff --git a/apps/desktop/src/main/cindy-brain/harnessSlot.ts b/apps/desktop/src/main/cindy-brain/harnessSlot.tsindex b9be2e2ebf..35dfbd9fc7 100644--- a/apps/desktop/src/main/cindy-brain/harnessSlot.ts+++ b/apps/desktop/src/main/cindy-brain/harnessSlot.ts@@ -69,6 +69,7 @@ export interface GhostHarnessSlotDeps {allowed(ghostId: string, session: Session): boolean;send(ghostId: string, payload: GhostPipeEventPush): boolean;gateway(): Pick<GhostSubscriptionGateway, 'publishHarness'>;+ redactToolInput(toolName: string, input: unknown): unknown;readHistory?(sessionId: string,name: 'messages' | 'tool-content',@@ -446,7 +447,12 @@ export class GhostHarnessSlot {data.role = event.type === 'tool_use' ? 'tool_use' : 'tool_result';Object.assign(data,- projectHarnessContent(data.role, event.type === 'tool_use' ? raw : raw.fullText),+ projectHarnessContent(data.role, event.type === 'tool_use' ? {+ toolName: raw.toolName,+ input: this.deps.redactToolInput(+ typeof raw.toolName === 'string' ? raw.toolName : '', raw.input,+ ),+ } : raw.fullText),);break;case 'text':@@ -603,7 +609,7 @@ export class GhostHarnessSlot {...data,...projectHarnessContent('tool_use', {toolName: request.toolName,- input: request.input,+ input: this.deps.redactToolInput(request.toolName ?? '', request.input),}),}: data,diff --git a/apps/desktop/src/main/cindy-brain/index.ts b/apps/desktop/src/main/cindy-brain/index.tsindex d5d3e41411..6e263fef5b 100644--- a/apps/desktop/src/main/cindy-brain/index.ts+++ b/apps/desktop/src/main/cindy-brain/index.ts@@ -10,6 +10,7 @@ import { takePeerAttachment } from '../device-link/peerAttachmentStore.js';import { parsePeerAttachmentRef } from '@cindy/device-link';import type { Session as MakerSession } from '@cindy/maker-core';import { GhostHarnessSlot } from './harnessSlot.js';+import { redactToolInputForUntrustedBoundary } from '../messagePersistBroadcaster.js';import { capturePluginOauthPeer } from '../plugin-oauth/runtime.js';import { readMobilePreview } from './mobilePreview.js';import { createMailReader, mailReaderRemoteProvider } from './mailReader.js';@@ -2467,6 +2468,7 @@ function getGhostHarnessSlot(): GhostHarnessSlot {captureSource: captureGhostLogicSource,allowed: (id, session) => !isGhostDisabledForWorkdir(id, session.workDir),gateway: getGhostSubscriptionGateway,+ redactToolInput: redactToolInputForUntrustedBoundary,readHistory: async (...args) => (await import('./harnessHistory.js')).readHarnessHistory(...args),});}