Permission Engine Lab [Core]
Experiment: experiments/exp_05_permission_engine/main.py
Objective
Implement a pure decision function over permission modes, rule sources, and pattern matching, including bypass-immune tools—mirroring the mental model of src/permissions/.
Source mapping (Claude Code)
| Concept | Location |
|---|---|
| Modes, rules, ask/allow/deny | src/permissions/ |
Architecture
Key code walkthrough
Modes and rule priority (lower number = higher priority in sort):
Pure decide() — mode overrides, then sorted rules:
How to run
cd experiments
python -m exp_05_permission_engine.main --mock
python -m exp_05_permission_engine.main --provider anthropic
python -m exp_05_permission_engine.main --provider openai
Exercises
- Add session rules loaded from a temp JSON file with highest priority.
- Extend
_pattern_matchesto support regex forinput_pattern. - Wire
decide()into exp_04’sexecute_batchso each call checks permissions first.
Concept checklist
- Plan mode is a coarse gate: it denies whole tool families (writes, shell) before rules run.
- Bypass is not absolute: immune tools still flow through
decide()so dangerous categories remain governable. - Rules are total-order sorted by
RuleSource; first match on tool + optional input pattern wins. interactive_approvesimulates the UI path when the engine returnsASK.
Next experiment
Prompt Assembly Lab — how allowed tools and context become the system prompt.