Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(ios-simulator): omit denied commands from logs
JiangJiahao9af5cb5c6260
diff --git a/apps/desktop/src/main/maker-host/__tests__/iosSimulatorShellHook.test.ts b/apps/desktop/src/main/maker-host/__tests__/iosSimulatorShellHook.test.tsnew file mode 100644index 0000000000..47a2b45c14--- /dev/null+++ b/apps/desktop/src/main/maker-host/__tests__/iosSimulatorShellHook.test.ts@@ -0,0 +1,58 @@+import { describe, expect, it, vi } from 'vitest';++import type { Logger } from '@cindy/maker-core';++import { createIOSSimulatorShellGuardHook } from '../claude-hooks/ios-simulator-shell-hook.js';++function createLoggerSpy(): { logger: Logger; warn: ReturnType<typeof vi.fn> } {+ const warn = vi.fn();+ const logger = {+ trace: vi.fn(),+ debug: vi.fn(),+ info: vi.fn(),+ warn,+ error: vi.fn(),+ fatal: vi.fn(),+ child: () => logger,+ } as unknown as Logger;+ return { logger, warn };+}++describe('iOS Simulator shell guard hook', () => {+ it('denies bypass commands without persisting command text in logs', async () => {+ const { logger, warn } = createLoggerSpy();+ const hook = createIOSSimulatorShellGuardHook(logger);+ const command = 'API_TOKEN=super-secret xcrun simctl boot DEVICE';++ const result = await hook(+ {+ session_id: 'session-1',+ transcript_path: '/tmp/transcript',+ cwd: '/tmp',+ hook_event_name: 'PreToolUse',+ tool_name: 'Bash',+ tool_input: { command },+ } as never,+ 'tool-secret',+ { signal: new AbortController().signal },+ );++ expect(result).toMatchObject({+ hookSpecificOutput: {+ hookEventName: 'PreToolUse',+ permissionDecision: 'deny',+ },+ });+ expect(warn).toHaveBeenCalledWith(+ 'shell command denied by embedded iOS Simulator policy',+ expect.objectContaining({+ toolUseId: 'tool-secret',+ toolName: 'Bash',+ reason: expect.any(String),+ }),+ );+ const persistedLog = JSON.stringify(warn.mock.calls);+ expect(persistedLog).not.toContain(command);+ expect(persistedLog).not.toContain('super-secret');+ });+});diff --git a/apps/desktop/src/main/maker-host/claude-hooks/ios-simulator-shell-hook.ts b/apps/desktop/src/main/maker-host/claude-hooks/ios-simulator-shell-hook.tsindex 886e637e71..fdd4fb4ba4 100644--- a/apps/desktop/src/main/maker-host/claude-hooks/ios-simulator-shell-hook.ts+++ b/apps/desktop/src/main/maker-host/claude-hooks/ios-simulator-shell-hook.ts@@ -20,7 +20,7 @@ export function createIOSSimulatorShellGuardHook(logger: Logger): HookCallback {log.warn('shell command denied by embedded iOS Simulator policy', {toolUseId: toolUseId ?? null,toolName: pre.tool_name,- command,+ reason: policy.reason,});return {hookSpecificOutput: {diff --git a/packages/maker-core/src/agents/codex/index.test.ts b/packages/maker-core/src/agents/codex/index.test.tsindex dec343ffd2..59efff12ea 100644--- a/packages/maker-core/src/agents/codex/index.test.ts+++ b/packages/maker-core/src/agents/codex/index.test.ts@@ -282,6 +282,18 @@ function createNoopLogger(): Logger {return logger;}+function createLoggerSpy(): { logger: Logger; warn: ReturnType<typeof vi.fn> } {+ const warn = vi.fn();+ const logger: Logger = {+ ...createNoopLogger(),+ warn,+ child() {+ return logger;+ },+ };+ return { logger, warn };+}+function createDeps(runtimeConfig: AgentDeps['runtimeConfig'] = {},overrides: Partial<AgentDeps> = {},@@ -12640,11 +12652,12 @@ describe('CodexAgent MCP thread context hooks', () => {});it('applies a host shell-command denial before Full access auto-approval', async () => {+ const { logger, warn } = createLoggerSpy();const policy = vi.fn(() => ({decision: 'deny' as const,reason: 'use the embedded iOS Simulator',}));- const agent = new CodexAgent(createDeps({}, { getShellCommandPolicy: policy }));+ const agent = new CodexAgent(createDeps({}, { getShellCommandPolicy: policy, logger }));const host = installFakeHost(agent);const handle = await agent.startSession({sessionId: 'session-command-host-policy',@@ -12660,30 +12673,37 @@ describe('CodexAgent MCP thread context hooks', () => {}));handle.setInteractionResolver(resolver);+ const command = 'API_TOKEN=super-secret open -a Simulator';const result = await handlers.commandExecutionApproval({threadId: 'start-thread-id',turnId: 'turn-1',itemId: 'cmd-1',- command: 'open -a Simulator',+ command,cwd: '/repo',});expect(policy).toHaveBeenCalledWith({agentKind: 'codex',- command: 'open -a Simulator',+ command,cwd: '/repo',});expect(resolver).not.toHaveBeenCalled();expect(result).toEqual({ decision: 'decline' });+ expect(warn).toHaveBeenCalledWith('command execution denied by host policy', {+ requestId: 'cmd-1',+ reason: 'use the embedded iOS Simulator',+ });+ expect(JSON.stringify(warn.mock.calls)).not.toContain('super-secret');await handle.close();});it('interrupts an already-started absolute-path shell bypass as a fail-safe', async () => {+ const { logger, warn } = createLoggerSpy();const policy = vi.fn(() => ({decision: 'deny' as const,reason: 'use the embedded iOS Simulator',}));- const agent = new CodexAgent(createDeps({}, { getShellCommandPolicy: policy }));+ const agent = new CodexAgent(createDeps({}, { getShellCommandPolicy: policy, logger }));const host = installFakeHost(agent, (method) =>method === Method.TurnInterrupt ? {} : undefined,);@@ -12696,26 +12716,32 @@ describe('CodexAgent MCP thread context hooks', () => {const handlers = host.getThreadHandlers();if (!handlers?.itemStarted) throw new Error('expected itemStarted handler');+ const command = 'API_TOKEN=super-secret /usr/bin/open -a Simulator';handlers.itemStarted({threadId: 'start-thread-id',turnId: 'turn-1',item: {id: 'cmd-absolute',type: 'commandExecution',- command: '/usr/bin/open -a Simulator',+ command,cwd: '/repo',},});expect(policy).toHaveBeenCalledWith({agentKind: 'codex',- command: '/usr/bin/open -a Simulator',+ command,cwd: undefined,});expect(host.request).toHaveBeenCalledWith(Method.TurnInterrupt, {threadId: 'start-thread-id',turnId: 'turn-1',});+ expect(warn).toHaveBeenCalledWith('command execution interrupted by host policy', {+ turnId: 'turn-1',+ reason: 'use the embedded iOS Simulator',+ });+ expect(JSON.stringify(warn.mock.calls)).not.toContain('super-secret');await handle.close();});diff --git a/packages/maker-core/src/agents/codex/index.ts b/packages/maker-core/src/agents/codex/index.tsindex f92e91de27..4fbc2d8155 100644--- a/packages/maker-core/src/agents/codex/index.ts+++ b/packages/maker-core/src/agents/codex/index.ts@@ -5817,8 +5817,7 @@ export class CodexAgent extends BaseAgent {});if (hostPolicy?.decision === 'deny') {log.warn('command execution denied by host policy', {- command: params.command ?? '',- cwd: params.cwd ?? null,+ requestId: params.approvalId ?? params.itemId,reason: hostPolicy.reason,});return { decision: 'decline' };@@ -8451,7 +8450,6 @@ export class CodexAgent extends BaseAgent {discardPendingSpawnLineageIds(reservedChildThreadIds);log.warn('command execution interrupted by host policy', {turnId: params.turnId,- command: shellCommand.command,reason: hostPolicy.reason,});void host