4b6817381b
CI (OpenClaw E2E) / openclaw test (push) Has been cancelled
CI / coverage-report (push) Has been cancelled
CI / test-kubernetes (push) Has been cancelled
CI / should-run-thorough (push) Has been cancelled
CI / test-thorough (cloudwatch-demo) (push) Has been cancelled
CI / test-thorough (flink-ecs) (push) Has been cancelled
CI / test-thorough (upstream-lambda) (push) Has been cancelled
CI / test-thorough (prefect-ecs-fargate) (push) Has been cancelled
Release / build-binaries (zip, opensre.exe, onefile, windows-latest, windows-x64) (push) Has been cancelled
Benchmark image — build + push to ECR (any adapter) / build + push (push) Has been cancelled
CI / quality (ubuntu-latest) (push) Has been cancelled
CI / test (tools-runtime) (push) Has been cancelled
CI / test (e2e-general) (push) Has been cancelled
CI / test (cli-runtime) (push) Has been cancelled
CI / test (e2e-provider-and-openclaw) (push) Has been cancelled
CI / test (integrations-and-misc) (push) Has been cancelled
Release / verify (push) Has been cancelled
Release / build-python-dist (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, macos-15-intel, darwin-x64) (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, macos-latest, darwin-arm64) (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04, linux-x64) (push) Has been cancelled
Release / publish-release (push) Has been cancelled
Release / publish-main-release (push) Has been cancelled
Interactive Shell Live (PR + post-merge) / turn-checks (no-LLM) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
Interactive Shell Live (PR + post-merge) / turn-live shard ${{ matrix.shard_index }} (push) Has been cancelled
Release / prepare (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04-arm, linux-arm64) (push) Has been cancelled
Synthetic Deterministic Tests / Synthetic offline (deterministic) (push) Has been cancelled
72 lines
2.3 KiB
Python
72 lines
2.3 KiB
Python
"""Shell-specific execution policy for the interactive REPL.
|
|
|
|
Alpha mode allows every shell command; the only rejected case is genuinely
|
|
empty input. These helpers live next to the rest of the shell machinery so the shared
|
|
execution-policy module is not imported for shell-only concerns by other tools.
|
|
They reuse the shared policy contracts
|
|
(``ExecutionPolicyResult`` / ``ToolExecutionPlan``) from
|
|
``tools.interactive_shell.shared``.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import config.constants.platform as _platform
|
|
from tools.interactive_shell.shared import (
|
|
ExecutionPolicyResult,
|
|
ToolExecutionMode,
|
|
ToolExecutionPlan,
|
|
)
|
|
from tools.interactive_shell.shell.parsing import (
|
|
ParsedShellCommand,
|
|
parse_shell_command,
|
|
)
|
|
|
|
|
|
def evaluate_shell_from_parsed(parsed: ParsedShellCommand) -> ExecutionPolicyResult:
|
|
"""Alpha mode: allow every shell command; only reject empty input.
|
|
|
|
There is no command classification or deny floor — any command (mutating,
|
|
``restricted``, operators, substitution, passthrough) is allowed. A
|
|
``parse_error`` only occurs for empty input (e.g. a bare ``!``), which is
|
|
rejected because there is nothing to run.
|
|
"""
|
|
if parsed.parse_error is not None:
|
|
return ExecutionPolicyResult(
|
|
verdict="deny",
|
|
tool_type="shell",
|
|
reason=parsed.parse_error,
|
|
hint="Enter a command to run.",
|
|
shell_classification="unrestricted",
|
|
)
|
|
|
|
return ExecutionPolicyResult(
|
|
verdict="allow",
|
|
tool_type="shell",
|
|
reason=None,
|
|
shell_classification="unrestricted",
|
|
)
|
|
|
|
|
|
def plan_shell_execution(parsed: ParsedShellCommand) -> ToolExecutionPlan:
|
|
policy = evaluate_shell_from_parsed(parsed)
|
|
classification = policy.shell_classification or "unrestricted"
|
|
return ToolExecutionPlan(
|
|
tool_type="shell",
|
|
classification=classification,
|
|
execution_mode=ToolExecutionMode.FOREGROUND,
|
|
policy=policy,
|
|
)
|
|
|
|
|
|
def evaluate_shell_command(command: str) -> ExecutionPolicyResult:
|
|
"""Map shell policy + passthrough rules into allow/ask/deny."""
|
|
parsed = parse_shell_command(command, is_windows=_platform.IS_WINDOWS)
|
|
return evaluate_shell_from_parsed(parsed)
|
|
|
|
|
|
__all__ = [
|
|
"evaluate_shell_command",
|
|
"evaluate_shell_from_parsed",
|
|
"plan_shell_execution",
|
|
]
|