Skip to content

Permissions: load rules from config files (per-repo + user scopes) + import from Claude Code settings.json #13

Closed

Description

@JAORMX

Summary

Permission rules today come from exactly two places, both in-process and neither configurable without recompiling:

  1. defaultRules() — a hardcoded Go literal in internal/app/build.go:1355, all seeded at ScopeManaged.
  2. Learned rules — in-memory, per-session, non-durable (internal/adapter/permstore); lost on process restart by design.

There is no config file. To change what is auto-approved you must edit defaultRules() and task build. This issue proposes closing that gap with a file-based permission config, per-repo discovery, and a Claude Code settings.json import path.

The good news, from a code read: this is mostly a "wire up the missing producers" task, not a "design a permission system" task. The precedence engine and the full five-tier Scope ladder already exist and are unit-tested — three of the five scopes just have nothing that populates them yet.

Current state (what already exists)

  • governance.Rule (internal/governance/permission.go:54): {Scope, Tool, Pattern, Effect, Exact}. Effect is a string-backed enum ("allow"/"ask"/"deny"). Scope is an int enum with precedence Managed > CLI > LocalProject > SharedProject > User (permission.go:31).
  • Resolution is deny → ask → allow, scope-independent for effect dominance, scope only breaks same-effect ties; unmatched calls default to Ask (evaluator.go:243-253).
  • ruleMatches (evaluator.go:274): empty Tool = any tool, empty Pattern = any args, literal fast-path, then globMatch (*/?, where * spans /) unless Exact:true.
  • The scope-wiring gap: ScopeCLI, ScopeLocalProject, ScopeSharedProject are referenced nowhere outside their declaration. ScopeManaged is used only by defaultRules(); ScopeUser only by the learned-rule path. The merge machinery is complete and tested but has no production producers for 3 of 5 scopes.
  • Single composition point for injecting rules: internal/app/build.go:424, permpolicy.NewPolicy(defaultRules(), learned). This is shared by the main engine and per-session MCP engines.
  • This was an acknowledged deferral: docs/design/PRODUCTION-READINESS.md:70 — "Config file (vs flags only) — flags suffice for v1; add if operators ask." The Scope enum comment mirrors the docs/harnesses/08-design-considerations.md §10 model verbatim, i.e. it was designed against the Claude Code layering up front.

Proposal

1. A permission config file

A YAML file (mecatl already depends directly on go.yaml.in/yaml/v3 — used by the skills + agents adapters; no new dep) carrying allow/ask/deny rule lists. Strawman:

# .mecatl/settings.yaml
permissions:
  allow:
    - Read
    - Grep
    - "Bash(go test:*)"
  ask:
    - Edit
    - Write
  deny:
    - "Read(./.env)"
    - "Bash(curl:*)"
  • A new adapter package (sibling to permpolicy/permclassify, e.g. internal/adapter/permconfig) does the file reading + YAML parse + translation into []governance.Rule. governance itself must stay session-free and os-free (layering rule), so the loader cannot live there — it mirrors how permpolicy adapts the session-free Evaluator.
  • Wired at the one composition point: NewPolicy(append(defaultRules(), loadedRules...), learned) in build.go.
  • A --permission-config (and conventional-discovery toggle) flag on cmd/mecated, following the existing --agents-dir / --agents-conventional pattern (cmd/mecated/main.go).

2. Per-repo config discovery

Reuse the existing tiered discovery precedent from internal/adapter/agents/resolve.go (ResolveSources), which already resolves explicit > project (.mecatl/, .claude/) > user (XDG / ~/.claude/) and maps almost exactly onto the unused Scope ladder. Each discovered location loads at a fixed Scope:

Location Scope
--permission-config / CLI flags ScopeCLI
<repo>/.mecatl/settings.local.yaml (git-ignored, personal) ScopeLocalProject
<repo>/.mecatl/settings.yaml (checked in, shared) ScopeSharedProject
~/.config/mecatl/settings.yaml (XDG user global) ScopeUser
managed/enterprise (future) ScopeManaged

This finally gives the three orphaned scopes real producers. Discovery must use the tool.Workspace FS port for the repo-root file (never os directly), consistent with prompt.DiscoverInstructions.

3. Import from Claude Code settings.json

Claude Code's settings.json permissions block (allow/ask/deny arrays of Tool(specifier) strings) and its five-tier file precedence (enterprise managed → CLI → .claude/settings.local.json → .claude/settings.json → ~/.claude/settings.json) map one-to-one onto mecatl's Scope enum and Effect set. The import therefore reduces to: discover the .claude/settings*.json locations (the agents adapter already reads .claude/ paths), parse the three arrays, translate each Tool(specifier) into a governance.Rule, and merge.

The one hard part — glob grammar translation. mecatl's globMatch (evaluator.go:300) is intentionally simpler than Claude Code's gitignore-style matcher:

  • Bash(npm run test:*) — Claude's :* prefix → mecatl * glob.
  • Edit(src/**) — Claude ** recursive → mecatl has no ** (but * already spans /, so src/* is the down-conversion).
  • WebFetch(domain:example.com) — domain: specifier → *example.com*.
  • Read(~/.zshrc) — no ~ expansion in mecatl; / is not a path separator.

Translation is best-effort, not byte-for-byte. Anything that doesn't translate cleanly should fail safe toward Ask/Deny, never silently widen to Allow — consistent with the existing "unmatched → Ask" posture. This should be documented loudly, and ideally the import emits a report of what it dropped or approximated (no silent caps).

Design constraints / things to get right

  • Layering: loader lives in an adapter, not governance. Translate to governance.Rule at the adapter boundary; governance gets no JSON/YAML tags.
  • Exact:false for all config-loaded rules — config rules keep glob semantics; only learned rules use Exact:true (the glob-escalation safety floor, permission.go:64).
  • Default-rule scope tension: today every default is ScopeManaged (highest). A user/project config Allow at a lower scope can't win a same-effect tie, but a config Deny still beats a managed Allow (effect dominance is scope-independent), and a config Allow can satisfy a tool that has no managed rule. We should decide whether the built-in defaults should move to a lower "built-in default" tier so project/user config can selectively loosen a default Ask (e.g. auto-approve Recall) rather than only tighten it. This is the main open design question.
  • Trust / supply-chain: a checked-in .mecatl/settings.yaml (or imported .claude/settings.json) is attacker-controllable in a cloned repo. Importing/loading project-scoped allow rules from an untrusted repo needs a trust gate (cf. the first-time-trust-dialog framing in docs/harnesses/08-design-considerations.md:175). Loading a project file that grants permissions silently would be a regression of the permission model. Lean toward: project-scope deny always honored; project-scope allow gated behind explicit trust.
  • Durability note: this is adjacent to the separately-tracked "durable learned rules" follow-up (permstore.go:16) but distinct — this issue is static configured rules, not persisted runtime learning.

Scope of this issue vs. follow-ups

In scope: the loader adapter, YAML schema, per-repo + user discovery, the Claude Code importer, the trust gate decision, and the default-rule-scope decision.

Likely follow-ups: enterprise/managed settings path, durable persistence of learned rules, hot-reload on file change.

Acceptance criteria (draft)

  • A .mecatl/settings.yaml at the repo root can add allow/ask/deny rules that the engine honors, verified by an offline test (mockllm + memfs).
  • Per-repo (shared + local) and user-global locations load at the correct Scope, with precedence verified against the existing evaluator tests.
  • .claude/settings.json permissions import produces equivalent rules; lossy glob translations are documented and fail safe toward Ask/Deny.
  • Project-scope allow rules from an untrusted repo do not take effect without a trust signal.
  • task lint && task test green; go run ./cmd/mecademo still prints a full offline session.

Research basis: file:line references above are from a full read of internal/governance, internal/app/build.go, internal/adapter/{permpolicy,permstore,agents,skills}, internal/prompt, and docs/. The Claude Code settings.json schema specifics are from general knowledge cross-checked against the repo's existing .claude/ compatibility conventions.

Activity

  1. added a commit that references this issue on Jun 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions