Engine reference — generated from the canonical engineering source. Do not edit this page by hand.
Permissions & Safety
Luna uses a multi-layered permission system: permission modes (global), per-mode rulesets (fine-grained), danger detection (regex-based), and an optional AI classifier (LLM-based).
Permission Modes
6 modes control which tools the agent can use. Set via CLI, config, or TUI.
default
Standard mode. Per-mode rulesets determine allow/deny/ask per tool.
allow-all
No restrictions. All operations proceed without checks.
deny-all
Agent can only reason — no tool execution at all.
read-only
Only tools whose permission class is read (or unclassified) are allowed —
read_file, glob_search, grep_search, list_directory, web_fetch,
lsp, web_search, todo, mcp_read_resource, mcp_get_prompt and any
other read-category tool. The gate is class-based, not a fixed list
(permission_checker.lua resolves each tool’s class from its spec).
plan
The permission mode paired with the Plan agent mode; resolves exactly like
default (per-mode rulesets; ask/write-class escalations go through the
permission dialog).
auto (AI Classifier)
When the static ruleset returns "ask", an LLM-based classifier evaluates tool safety. If confidence >= 0.85, the decision is automatic. Otherwise, falls back to TUI permission dialog.
Requires Ollama (or compatible) to be running locally. Falls back to dialog if the classifier is unavailable.
Setting Permission Mode
CLI
luajit client/main.lua --permission-mode default
luajit client/main.lua -p auto
luajit client/main.lua -p allow-all
Valid values: default, allow-all, deny-all, read-only, plan, auto
Config File
// ~/.luna/config.json
{
"permission_mode": "auto"
}
TUI Slash Commands
/auto Enable AI classifier permission mode
Mode-specific permission rulesets are applied automatically when switching modes with Tab.
Per-Mode Rulesets
Each agent mode has a built-in permission ruleset that maps tool names to allow, deny, or ask.
Built-in Mode Defaults
Build Mode
Source: MODE_DEFAULTS.build (client/core/permission_ruleset.lua).
| Tool | Decision | Notes |
|---|---|---|
read_file, glob_search, grep_search, list_directory, web_fetch, lsp, web_search, todo, mcp_read_resource, mcp_get_prompt | allow | Read/search always allowed |
bash | ask | User approval required |
write_file | ask (except *.md → allow) | File pattern matching supported |
edit_file, create_directory, undo_edit, background_spawn | ask | User approval required |
delete_file | deny | Always blocked |
* (default) | ask | Unknown tools require approval |
Plan Mode
| Tool | Decision |
|---|---|
| Read/search/web tools | allow |
* (default) | deny |
Explore Mode
| Tool | Decision |
|---|---|
| Read/search/lsp tools | allow |
* (default) | deny |
Review Mode
| Tool | Decision |
|---|---|
| Read/search/lsp/web tools | allow |
web_fetch | ask |
* (default) | deny |
General Mode
| Tool | Decision |
|---|---|
* (default) | allow |
bash | ask |
delete_file | ask |
background_spawn | allow |
Coordinate Mode
coordinate registers as an agent mode but has no dedicated built-in
ruleset — default_for_mode("coordinate") falls back to the Build
ruleset (permission_ruleset.lua), so it resolves exactly like Build unless
an extension or the mode definition carries its own permissions table.
Teammate / Leader Modes
The team-swarm modes carry dedicated rulesets: teammate is deny-default
(read/search allow; write_file/edit_file/create_directory ask;
delete_file, sub_agent, memory, undo_edit,
attach_image, background_spawn denied; team_mail allowed); leader
mirrors General (* allow, bash/delete_file ask).
File Pattern Matching
Rulesets support file pattern matching for tools that take file paths:
{
"write_file": {
"default": "ask",
"patterns": {
"*.md": "allow",
"*.env": "deny"
}
}
}
Patterns use glob syntax: *.ext, path/prefix*, etc.
Danger Detection
Before evaluating the ruleset, the danger detector (client/core/danger_detector.lua, PATTERNS) scans bash commands against 45 regex patterns — 26 dangerous + 19 caution (plus additional AST-derived dangerous findings for pipe-to-shell, block-device writes and recursive deletes). Examples:
| Category | Patterns | Example |
|---|---|---|
| Destructive delete | rm -rf /, rm -rf ~ | Always dangerous |
| Remote code execution | curl | bash, wget | sh | Always dangerous |
| System control | shutdown, halt, poweroff | Always dangerous |
| Privilege escalation | sudo, chmod 777 | caution |
| Network exfil | scp, rsync to remote | caution |
| File removal | rm - with flags | caution |
Override behavior:
dangerous → overrides allow to deny
caution → overrides allow to ask
AI Classifier (Auto Mode)
When permission_mode is auto, an Ollama-hosted LLM classifies "ask" decisions:
Tool invocation → Ruleset → "ask"
│
├── AI classifier available?
│ ├── Yes → Classify (5s timeout)
│ │ ├── confidence >= 0.85 → auto allow/deny
│ │ └── confidence < 0.85 → TUI dialog
│ └── No → TUI dialog
└── Not auto mode → TUI dialog
Configuration
{
"classifier": {
"enabled": true,
"model": "qwen2.5-coder:7b",
"provider": "ollama",
"base_url": "http://localhost:11434",
"confidence_threshold": 0.85,
"timeout": 5,
"cache_size": 64
}
}
| Setting | Default | Description |
|---|---|---|
enabled | false | Global enable/disable |
model | qwen2.5-coder:7b | Classifier model (fast local recommended) |
confidence_threshold | 0.85 | Minimum confidence for auto-decision |
timeout | 5 | Seconds before fallback to dialog |
cache_size | 64 | LRU cache entries for repeated invocations |
Environment Overrides
| Variable | Description |
|---|---|
LUNA_CLASSIFIER_ENABLED | "true" / "false" |
LUNA_CLASSIFIER_MODEL | Override classifier model |
LUNA_CLASSIFIER_PROVIDER | Override classifier provider |
LUNA_CLASSIFIER_THRESHOLD | Override confidence threshold (0.0-1.0) |
Safety Guarantees
The classifier never blocks tool execution on failure:
| Scenario | Behavior |
|---|---|
| Classifier model unavailable | Show TUI dialog |
| Request timeout (>5s) | Show TUI dialog |
| Response unparseable | Show TUI dialog |
| Confidence below threshold | Show TUI dialog |
Bypass-immune safety classes & denial breaker
Four safety classes (dangerous_command, secret_access, credential_write,
destructive_delete) always escalate an ALLOW to the ask flow regardless of
the permission mode — including allow-all, auto, and server-admin ["*"]
grants — while DENY results stay deny and safety-class allows are never
cached. Consecutive permission denials (permission_denial_limit, default 3)
latch a per-agent breaker that ends the turn with the typed
permission_denial_limit terminal after the current tool batch. The full
mode × class table, trigger list, and reset/event contract live in
security.md → Luna safety classes & denial circuit breaker.
Permission Evaluation Flow
1. Global mode check
├── allow-all → execute immediately
├── deny-all → block immediately
└── read-only → only allow read-category tools
2. Mode ruleset evaluation
└── PermissionRuleset.evaluate_with_danger(mode_rules, tool, input)
├── Static rule: allow → execute
├── Static rule: deny → block
└── Static rule: ask → danger analysis
├── danger_level == dangerous → deny (override)
├── danger_level == caution + allow → ask (upgrade)
└── ask → permission_mode check
├── auto → AI classifier
└── other → TUI permission dialog
3. TUI dialog → user approves/denies
Mutation Queue
Write operations (write_file, edit_file, delete_file) are serialized through a mutation queue. This prevents race conditions when the agent executes multiple concurrent tool calls that modify the same files.
Server-Side RBAC (Scopes)
Everything above governs a worker — what a Luna agent may do on its host.
A completely separate layer governs the control plane: every Sol HTTP
route requires a verb:resource permission scope (e.g. inference:start,
tasks:read, zmq:dispatch — 61 scopes), resolved from the caller’s token
via Mango roles, with an additional object-ownership layer on task,
workflow, conversation, and orchestrate detail routes, plus an
execute-grade split (tasks:execute) that gates execute-class tools on
dispatched workers.
The full scope table, gate semantics, admin vs service-token vs user-token behavior, failure postures (401/403/404/503), and the Mango role composition model live in the dedicated reference: rbac-scopes.md.