/** * Heuristic danger detection for `exec` tool commands. * * Layered on top of `BLOCKED_ARG_PATTERNS` (which is a hard-deny list for * clear sandbox escapes) and `bash-kill-guard.ts` (which protects WrongStack * itself from kill). This module assigns a danger level to a command/arg * pair so the caller can decide whether to: * * - 'safe' → execute normally * - 'caution' → execute and emit a warning line to the tool output * - 'destructive' → route through the existing confirm flow * (`execTool.permission === 'confirm'`) instead of * hard-deny, so the user can still proceed if intentional * * Design constraints: * - Deterministic: no randomness, no I/O, no time. Same input → same output. * - No LLM calls. Patterns are regex / exact-match. * - Per-rule `id` so config can override specific rules via * `tools.exec.danger.bypass`. * - Reasons are human-readable, joined with "; " for the confirm prompt. * * Caution rules are deliberately permissive — they execute and emit a * warning rather than blocking. The rationale: many of these patterns * (python -c, sudo) are part of legitimate dev workflows, * so a hard deny would block too much. A warning gives the user a * chance to notice "wait, I didn't mean to do that" without forcing * them to add a config override for every script. */ export type DangerLevel = 'safe' | 'caution' | 'destructive'; export interface DangerAssessment { level: DangerLevel; reasons: string[]; /** Stable id of the matched rule, for tests and config-override. */ matchedRule?: string; } export interface DangerRule { id: string; level: DangerLevel; /** Match a (cmd, args) pair. Return true if this rule fires. */ test: (cmd: string, args: readonly string[]) => boolean; /** Human-readable explanation, joined with "; " in the output. */ reason: string; } /** * Evaluate the danger level of a (cmd, args) pair. * * Returns 'safe' if no rule fires, otherwise the highest level among all * matching rules. The 'matchedRule' field is the *last* rule that fired * (stable, since rules are evaluated in declaration order). * * Optional `bypass` argument: a set of rule ids that should be SKIPPED * even if they would otherwise match. Wired from * `config.tools.exec.danger.bypass` (see `ExecDangerConfig` in * `@wrongstack/core/src/types/config.ts`). Unknown ids are silently * ignored — forward-compat: a rule added in a future version can be * referenced before the user upgrades their config schema. * * This function is the single source of truth for danger classification; * it is pure (no side effects) and unit-tested in `danger-detect.test.ts`. */ export declare function detectDanger(cmd: string, args: readonly string[], bypass?: ReadonlySet): DangerAssessment; //# sourceMappingURL=_danger-detect.d.ts.map