Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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).

ToolDecisionNotes
read_file, glob_search, grep_search, list_directory, web_fetch, lsp, web_search, todo, mcp_read_resource, mcp_get_promptallowRead/search always allowed
bashaskUser approval required
write_fileask (except *.md → allow)File pattern matching supported
edit_file, create_directory, undo_edit, background_spawnaskUser approval required
delete_filedenyAlways blocked
* (default)askUnknown tools require approval

Plan Mode

ToolDecision
Read/search/web toolsallow
* (default)deny

Explore Mode

ToolDecision
Read/search/lsp toolsallow
* (default)deny

Review Mode

ToolDecision
Read/search/lsp/web toolsallow
web_fetchask
* (default)deny

General Mode

ToolDecision
* (default)allow
bashask
delete_fileask
background_spawnallow

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:

CategoryPatternsExample
Destructive deleterm -rf /, rm -rf ~Always dangerous
Remote code executioncurl | bash, wget | shAlways dangerous
System controlshutdown, halt, poweroffAlways dangerous
Privilege escalationsudo, chmod 777caution
Network exfilscp, rsync to remotecaution
File removalrm - with flagscaution

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
  }
}
SettingDefaultDescription
enabledfalseGlobal enable/disable
modelqwen2.5-coder:7bClassifier model (fast local recommended)
confidence_threshold0.85Minimum confidence for auto-decision
timeout5Seconds before fallback to dialog
cache_size64LRU cache entries for repeated invocations

Environment Overrides

VariableDescription
LUNA_CLASSIFIER_ENABLED"true" / "false"
LUNA_CLASSIFIER_MODELOverride classifier model
LUNA_CLASSIFIER_PROVIDEROverride classifier provider
LUNA_CLASSIFIER_THRESHOLDOverride confidence threshold (0.0-1.0)

Safety Guarantees

The classifier never blocks tool execution on failure:

ScenarioBehavior
Classifier model unavailableShow TUI dialog
Request timeout (>5s)Show TUI dialog
Response unparseableShow TUI dialog
Confidence below thresholdShow 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.