/** * Pure, dependency-light workspace command-allowlist logic, shared by the * daemon's `command_execute` MCP tool (`command-tools.ts`) and any other * host that needs to gate shell execution against the same * `/.agentproto/allowed-commands.json` file — e.g. the * `mastra-agent` adapter's own `command_execute` workspace tool, which runs * out-of-process from the daemon and has no other way to reach this logic. * * Kept free of daemon-only concerns (session recording, PR provenance, * OS-level sandboxing) so it stays cheap to import from a spawned child * process — no `SessionsRegistry`, no `@agentproto/command-sandbox`. * * Allowlist file shape — each entry in `commands` is either a plain * basename string (unconstrained args) or an object constraining the argv * prefix: * { * "version": 1, * "commands": [ * "claude", * "node", * { "command": "git", "args": ["status"] } * ] * } * * Match is by command BASENAME. A plain string entry allows that basename * with ANY args. An object entry with `args` only allows invocations whose * argv starts with exactly that token sequence (a prefix match). When a * basename has BOTH a plain entry and constrained entries, the plain entry * wins. */ declare const ALLOWLIST_REL = ".agentproto/allowed-commands.json"; /** One normalized allowlist entry — a basename with an optional argv-prefix * constraint. `args` absent ⇒ unconstrained (any args), matching a plain * basename-string entry in the JSON file. */ interface AllowlistEntry { command: string; args?: string[]; } /** Load the workspace's allowlist as normalized entries (basename + * optional argv-prefix constraint). Cheap stat-cached, same as * `loadAllowlist`; both share one cache keyed on the file's mtime. */ declare function loadAllowlistEntries(workspace: string): Promise; /** Basename-only view of the allowlist — every basename that has AT LEAST * ONE entry, constrained or not. Existing callers (cron-scheduler.ts, * task-ledger.ts, supervisor.ts) gate on basename alone, same as before * this change; only `command_execute` itself enforces argv constraints * (see `isCommandAllowed`). */ declare function loadAllowlist(workspace: string): Promise>; /** What a shell gate actually executes, after `resolveShellGateExec`. */ interface ResolvedShellGateExec { command: string; args: string[]; /** The original whole-shell-line `command`, set only when it was * rewritten to `bash -c `; used to make refusals readable. */ shellLine?: string; } /** * Resolve the argv a shell gate (`{command, args?}`) should run. A task * `verify` or policy gate is often written as a WHOLE shell line in `command` * with no `args` (`"grep -q x /a/b/RAPPORT.md"`, `"cd /x && test -s a"`). * Gating that string by `basename()` yields the text after its last `/` * (`RAPPORT.md`) and refuses with a misleading error, so a `command` that * contains whitespace, has no `args` and is not itself an existing file path * is run as `bash -c `. The allowlist then applies to `bash`, which is * exactly the explicit `{command:"bash", args:["-c", ...]}` form. Anything * else is returned unchanged. A relative `command` is probed against `cwd` * (the directory the gate runs in), not the daemon's own cwd. */ declare function resolveShellGateExec(spec: { command: string; args?: readonly string[]; }, cwd?: string): ResolvedShellGateExec; /** * Allowlist check for a resolved shell gate. Plain gates keep the historical * basename-only rule; a rewritten `bash -c ` additionally honours any * argv constraint on a `bash` entry, so the auto-rewrite cannot bypass an * operator who allowlisted bash for specific arguments only. */ declare function isShellGateExecAllowed(entries: readonly AllowlistEntry[], target: ResolvedShellGateExec): boolean; /** `not in allowlist` text for a gate refusal. Names the command that was * actually checked and, when it came from a shell line, that line. */ declare function describeGateRefusal(label: string, baseName: string, shellLine?: string): string; /** Argv-aware allowlist check used by `command_execute`. A basename with * no matching entry ⇒ denied. A basename with any unconstrained entry * (plain string, or object with no `args`) ⇒ allowed regardless of args. * Otherwise every matching entry is constrained, so `args` must match * one of them as a prefix. */ declare function isCommandAllowed(entries: readonly AllowlistEntry[], baseName: string, args: readonly string[]): boolean; /** * How `terminal_start` is gated for a workspace: * - `"allowlist"` — `argv[0]` must pass the same allowlist check * `command_execute` applies. The shipped default. * - `"all"` — no check. The legitimate setting for a trusted local * workspace: this task exists so `all` becomes a deliberate * DECISION, not an accident of which tool the caller happened to * use. * - `"off"` — `terminal_start` is refused outright, whatever the argv. * NOTE: `off` means the door is CLOSED, not that the gate is * disabled — the name reads both ways and the wrong reading is a * security hole. */ type TerminalGateMode = "allowlist" | "all" | "off"; /** Global-default env var: the fallback when a workspace's allowlist * file carries no `terminalGate` field. */ declare const TERMINAL_GATE_ENV = "AGENTPROTO_TERMINAL_GATE"; /** Shipped default: gate `terminal_start` through the allowlist, same as * `command_execute`. */ declare const DEFAULT_TERMINAL_GATE: TerminalGateMode; /** * Resolve the terminal gate mode for `workspace`, highest priority first: * the workspace's own `terminalGate` field in * `/.agentproto/allowed-commands.json`, then the global * default from `AGENTPROTO_TERMINAL_GATE`, then * `DEFAULT_TERMINAL_GATE`. * * NOTE the precedence is the OPPOSITE of `loadSandboxConfig`'s * env-as-escape-hatch: here the env var is the GLOBAL DEFAULT, so a * workspace's explicit setting deliberately WINS over it. Don't "fix" * that — a workspace must be able to pin its own posture. * * An unrecognised value in either place resolves to * `DEFAULT_TERMINAL_GATE` and is never treated as `all` — fail toward * the gate, not away from it. */ declare function loadTerminalGateMode(workspace: string): Promise; /** * Command basenames that execute arbitrary code and read the filesystem * unrestricted. Allowlisting one grants a caller full host code execution + * FS read — the workspace cwd-anchor bounds only the working directory, not * what the interpreter itself opens. Used to surface a one-time warning * (see `isInterpreterBasename` / `interpreterExecWarning`) until an OS-level * command sandbox lands. */ declare const INTERPRETER_BASENAMES: ReadonlySet; /** True when `name` (a command basename) is a code interpreter. Case-insensitive * so `Rscript`/`RSCRIPT` match. */ declare function isInterpreterBasename(name: string): boolean; /** Human-readable warning for allowlisting/running an interpreter. */ declare function interpreterExecWarning(baseName: string): string; export { ALLOWLIST_REL, type AllowlistEntry, DEFAULT_TERMINAL_GATE, INTERPRETER_BASENAMES, type ResolvedShellGateExec, TERMINAL_GATE_ENV, type TerminalGateMode, describeGateRefusal, interpreterExecWarning, isCommandAllowed, isInterpreterBasename, isShellGateExecAllowed, loadAllowlist, loadAllowlistEntries, loadTerminalGateMode, resolveShellGateExec };