diff --git a/apps/cli/src/application/lib/agent.ts b/apps/cli/src/application/lib/agent.ts index 823ad3b3..d4aa737d 100644 --- a/apps/cli/src/application/lib/agent.ts +++ b/apps/cli/src/application/lib/agent.ts @@ -13,6 +13,7 @@ import { execTool } from "./exec-tool.js"; import { AskHumanRequestEvent, RunEvent, ToolPermissionRequestEvent, ToolPermissionResponseEvent } from "../entities/run-events.js"; import { BuiltinTools } from "./builtin-tools.js"; import { CopilotAgent } from "../assistant/agent.js"; +import { isBlocked } from "./command-executor.js"; export async function mapAgentTool(t: z.infer): Promise { switch (t.type) { @@ -552,11 +553,14 @@ export async function* streamAgent(state: AgentState): AsyncGenerator !allowSet.has(cmd)); } -function enforceSecurity(command: string): CommandResult | null { +// export const BlockedResult = { +// stdout: '', +// stderr: `Command blocked by security policy. Update ${SECURITY_CONFIG_PATH} to allow them before retrying.`, +// exitCode: 126, +// }; + +export function isBlocked(command: string): boolean { const blocked = findBlockedCommands(command); - - if (!blocked.length) { - return null; - } - - return { - stdout: '', - stderr: `Command blocked by security policy. Blocked command(s): ${blocked.join(', ')}. Update ${SECURITY_CONFIG_PATH} to allow them before retrying.`, - exitCode: 126, - }; + return blocked.length > 0; } export interface CommandResult { @@ -89,11 +86,6 @@ export async function executeCommand( maxBuffer?: number; // max buffer size in bytes } ): Promise { - const securityResult = enforceSecurity(command); - if (securityResult) { - return securityResult; - } - try { const { stdout, stderr } = await execPromise(command, { cwd: options?.cwd, @@ -128,11 +120,6 @@ export function executeCommandSync( timeout?: number; } ): CommandResult { - const securityResult = enforceSecurity(command); - if (securityResult) { - return securityResult; - } - try { const stdout = execSync(command, { cwd: options?.cwd,