Skip to content

M31A does not use a single "is this allowed?" flag. A tool call passes through a stack of decisions, and a later layer can override an earlier one. This page describes the stack in the order it is applied.

The core implementation is in packages/core/src/policy/, especially policy-engine.ts, config.ts, and types.ts. The admission path from the agent is packages/core/src/scheduler/policy.ts.

1. Folder trust ​

Trust is the first gate. Until a folder is trusted, project context is not loaded and file and shell tools are restricted.

  • security.folderTrust.enabled defaults to true.
  • --skip-trust trusts the folder for one invocation.
  • /permissions trust records trust interactively.
  • M31A_TRUST_WORKSPACE=true forces trust for non-interactive environments.

Trust state is stored locally. The policy engine also consults it while parsing shell commands: git commands in an untrusted folder are downgraded. See Sandboxing and trust.

2. Approval mode ​

The approval mode is the interactive baseline:

ModeBaseline
defaultPrompt before executing tools.
auto_editAuto-approve edit tools; still prompt for other tools.
planRead-only; writes and shell execution are blocked.
yoloAuto-approve everything (CLI flag only).

general.defaultApprovalMode accepts default, auto_edit, and plan; YOLO must be requested per invocation with --yolo or --approval-mode yolo. security.disableYoloMode and admin.secureModeEnabled can block it. In policy TOML files the enum value is written autoEdit, matching the internal ApprovalMode type.

Mode selection filters rules: a rule with modes only applies in those modes. plan.toml contains a catch-all deny at priority 40, explicit read-only allows at 50, and narrow exceptions that permit writing plan files under .m31a/tmp/.../plans/.

3. Policy tiers and priorities ​

Policies are TOML files loaded from several directories. Each source is assigned a tier, and effective priority is tier + (priority / 1000):

TierSourceExample priority
1Default policies shipped in packages/core/src/policy/policies/1.050
2Policies contributed by extensions2.100
3Workspace policies in <project>/.m31a/policies/3.100
4User policies in the per-user .m31a/policies/ directory4.100
5System / administrator policies5.100

Higher numbers win. Within a tier, the file's own priority field breaks ties. Rules are sorted by descending effective priority, and the engine uses the first matching rule. This is why a workspace deny beats a built-in allow, and why an admin deny beats everything.

Extension policies are sanitized at load time: ALLOW decisions and rules targeting YOLO mode are discarded, so an extension cannot silently approve actions.

Useful built-in priorities:

PriorityMeaning
10Write tools require confirmation in interactive mode.
15autoEdit overrides for edit tools.
40Plan mode catch-all deny.
50Read-only tools allowed; plan-mode read-only exceptions.
70Mode-transition and plan-file write overrides.
998YOLO allow-all.
999ask_user stays interactive even in YOLO mode.

4. Settings-derived rules ​

createPolicyEngineConfig() converts settings into policy rules in the user tier. This is why the settings reference calls these "deprecated" controls: they are still enforced, but as ordinary rules.

SettingPriorityDecision
mcp.excluded4.9Deny (persistent server block).
tools.exclude4.4Deny.
tools.confirmationRequired4.35Ask user; overrides allowlists.
tools.allowed4.3Allow, optionally narrowed by a command prefix.
tools.core4.25Allow listed core tools plus a catch-all deny at 4.24.
MCP servers with trust: true4.2Allow their tools.
mcp.allowed4.1Allow listed servers.
Headless MCP auto-allow4.1Allow configured servers when mcp.autoAllowInHeadless is set.

"Always allow" selections made in a confirmation dialog become dynamic rules at 3.95 for workspace scope or 4.95 for user scope. They are scoped to the current approval mode and more permissive modes, and security.disableAlwaysAllow or admin.secureModeEnabled can remove the choice.

5. Matching and shell analysis ​

A rule matches on tool name (including legacy aliases and virtual subagent names), optional mcpName, argument pattern, tool annotations such as readOnlyHint, approval mode, and interactivity. Argument patterns are compiled with SafeRegExp, a linear-time engine; native regular expressions are not accepted.

For shell tools, the engine parses the command and may split compound commands. Redirection and command substitution downgrade an ALLOW to ask_user unless the rule sets allowRedirection or allowCommandSubstitution. The YOLO default sets both.

There is also a hard build-file protection rule with maximum priority: editing a detected build configuration file is downgraded to ask_user (deny in non-interactive mode), regardless of a lower-priority allow rule.

6. Safety checkers ​

After a rule decision, safety checkers run unless the decision is already deny. Built-in checker types are:

  • allowed-path — path validation, used by autoEdit rules in write.toml.
  • plan-mode-command-guard — blocks mutating shell commands in Plan Mode.
  • conseca — experimental context-aware checker, enabled by security.enableConseca.

Checkers can deny or request confirmation. A checker that throws results in a deny, and in non-interactive mode any remaining ask_user becomes deny.

7. Administrator constraints ​

Admin controls are a distinct layer from ordinary rules:

  • adminPolicyPaths and the system policy directory form the highest tier.
  • If the system policy directory contains .toml files, supplemental --admin-policy paths are ignored; a central policy cannot be weakened by a command-line flag.
  • The system policy directory is skipped entirely if it fails a directory security check.
  • admin.secureModeEnabled blocks YOLO and "always allow".
  • admin.mcp can allowlist, blocklist, or require specific MCP servers.
  • admin.extensions and admin.skills restrict those extension points.

Admin denial is final: no lower tier can restore permission.

8. Worked example ​

A workspace policy that blocks reading key material while allowing a specific safe shell prefix:

toml
[[rule]]
toolName = "read_file"
argsPattern = ".*(\\.env|id_rsa).*"
decision = "deny"
priority = 200
denyMessage = "Secret files are blocked by workspace policy."

[[rule]]
toolName = "run_shell_command"
argsPattern = "^git status$"
decision = "allow"
priority = 100

Load it for one run with:

bash
m31a --policy ./company-policies.toml

Then inspect the effective rules inside the app with /policies list. Note that argsPattern values must be safe regular expressions; patterns that compile to an unsafe or catastrophic form are rejected.

9. Quick mental model ​

text
trusted folder?           no  -> restricted tools
approval mode             -> baseline rules (plan is special)
rule tiers 1..5           -> highest priority match wins
settings allow/exclude    -> ordinary user-tier rules
safety checkers           -> can deny or force a prompt
non-interactive           -> ask_user becomes deny
admin constraints         -> cannot be overridden

Next steps ​

Built with VitePress. Powered by NVIDIA NIM.