feat(exec): integrate pre-exec hooks into exec tool
Calls checkPreExecApproval() before running any shell command. If a hook denies the command, throws an error with the hook name and denial reason instead of executing.
This commit is contained in:
parent
0ddcd6b381
commit
663dd5a44e
@ -19,6 +19,7 @@ import {
|
|||||||
resolveExecApprovals,
|
resolveExecApprovals,
|
||||||
resolveExecApprovalsFromFile,
|
resolveExecApprovalsFromFile,
|
||||||
} from "../infra/exec-approvals.js";
|
} from "../infra/exec-approvals.js";
|
||||||
|
import { checkPreExecApproval } from "../infra/pre-exec-hooks.js";
|
||||||
import { requestHeartbeatNow } from "../infra/heartbeat-wake.js";
|
import { requestHeartbeatNow } from "../infra/heartbeat-wake.js";
|
||||||
import { buildNodeShellCommand } from "../infra/node-shell.js";
|
import { buildNodeShellCommand } from "../infra/node-shell.js";
|
||||||
import {
|
import {
|
||||||
@ -755,6 +756,22 @@ export function createExecTool(
|
|||||||
throw new Error("Provide a command to start.");
|
throw new Error("Provide a command to start.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Pre-exec hooks check (workspace-level command validation)
|
||||||
|
const workspaceDir = defaults?.cwd || process.cwd();
|
||||||
|
const preExecResult = await checkPreExecApproval({
|
||||||
|
workspaceDir,
|
||||||
|
toolName: "exec",
|
||||||
|
command: params.command,
|
||||||
|
workdir: params.workdir,
|
||||||
|
env: params.env,
|
||||||
|
});
|
||||||
|
if (!preExecResult.allowed) {
|
||||||
|
const hookInfo = preExecResult.hookName ? ` (hook: ${preExecResult.hookName})` : "";
|
||||||
|
throw new Error(
|
||||||
|
`Command blocked by pre-exec hook${hookInfo}: ${preExecResult.reason || "denied"}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const maxOutput = DEFAULT_MAX_OUTPUT;
|
const maxOutput = DEFAULT_MAX_OUTPUT;
|
||||||
const pendingMaxOutput = DEFAULT_PENDING_MAX_OUTPUT;
|
const pendingMaxOutput = DEFAULT_PENDING_MAX_OUTPUT;
|
||||||
const warnings: string[] = [];
|
const warnings: string[] = [];
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user