Runtime permission enforcement for agent commands.
Implements CommandHook to check commands against a permission policy
before execution. Supports a hierarchical permission mode with per-command-type
requirements and an optional prompter for interactive escalation.
Permission Modes (ordered least to most permissive)
:read_only-- no side effects allowed:send_only-- inter-agent messaging only:workspace_write-- file writes within workspace:full_access-- shell, system, network:allow-- everything permitted
Usage
# Create a policy
policy = PermissionHook.policy(:workspace_write)
# Use as a command hook
defmodule MyAgent do
use Raxol.Agent
def command_hooks do
[PermissionHook.new(:workspace_write)]
end
endCustom Prompter
For interactive permission escalation (terminal prompt, SSH, LiveView):
policy = PermissionHook.policy(:read_only,
prompter: fn command, _context ->
# Ask user for permission
IO.gets("Allow #{command.type}? [y/n] ") |> String.trim() == "y"
end
)
Summary
Functions
Check whether a directive is authorized under the given policy.
Check if mode a is at least as permissive as mode b.
Set the active permission policy for the current process.
Create a permission policy struct.
Returns the minimum permission mode required for a command type.
Set the active policy for the current process.
Types
@type effect() :: Raxol.Agent.Directive.t()
@type mode() :: :read_only | :send_only | :workspace_write | :full_access | :allow
Functions
Check whether a directive is authorized under the given policy.
Check if mode a is at least as permissive as mode b.
Set the active permission policy for the current process.
Returns the module name for use in command_hooks/0 lists.
The policy is stored in the process dictionary, so each agent
process maintains its own independent policy.
Create a permission policy struct.
Returns the minimum permission mode required for a command type.
@spec set_policy(t()) :: :ok
Set the active policy for the current process.