Repository navigation
Description
Summary
Permission rules today come from exactly two places, both in-process and neither configurable without recompiling:
defaultRules()— a hardcoded Go literal ininternal/app/build.go:1355, all seeded atScopeManaged.- 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}.Effectis a string-backed enum ("allow"/"ask"/"deny").Scopeis an int enum with precedenceManaged > 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): emptyTool= any tool, emptyPattern= any args, literal fast-path, thenglobMatch(*/?, where*spans/) unlessExact:true.- The scope-wiring gap:
ScopeCLI,ScopeLocalProject,ScopeSharedProjectare referenced nowhere outside their declaration.ScopeManagedis used only bydefaultRules();ScopeUseronly 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." TheScopeenum comment mirrors thedocs/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.governanceitself must stay session-free andos-free (layering rule), so the loader cannot live there — it mirrors howpermpolicyadapts the session-freeEvaluator. - Wired at the one composition point:
NewPolicy(append(defaultRules(), loadedRules...), learned)inbuild.go. - A
--permission-config(and conventional-discovery toggle) flag oncmd/mecated, following the existing--agents-dir/--agents-conventionalpattern (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/, sosrc/*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 togovernance.Ruleat the adapter boundary;governancegets no JSON/YAML tags. Exact:falsefor all config-loaded rules — config rules keep glob semantics; only learned rules useExact:true(the glob-escalation safety floor,permission.go:64).- Default-rule scope tension: today every default is
ScopeManaged(highest). A user/project configAllowat a lower scope can't win a same-effect tie, but a configDenystill beats a managedAllow(effect dominance is scope-independent), and a configAllowcan 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-approveRecall) 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 indocs/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-scopedenyalways honored; project-scopeallowgated 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.yamlat 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.jsonpermissionsimport produces equivalent rules; lossy glob translations are documented and fail safe toward Ask/Deny. - Project-scope
allowrules from an untrusted repo do not take effect without a trust signal. -
task lint && task testgreen;go run ./cmd/mecademostill 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
feat(soul): trust-gated project/imported soul (issue #14, Phase 3 ite…