agentperm 0.2.0__tar.gz → 0.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- agentperm-0.3.0/PKG-INFO +217 -0
- agentperm-0.3.0/README.md +158 -0
- {agentperm-0.2.0 → agentperm-0.3.0}/pyproject.toml +3 -2
- agentperm-0.3.0/src/agentperm/__init__.py +94 -0
- agentperm-0.3.0/src/agentperm/adapters/__init__.py +55 -0
- agentperm-0.3.0/src/agentperm/adapters/base.py +313 -0
- agentperm-0.3.0/src/agentperm/adapters/claude.py +129 -0
- agentperm-0.3.0/src/agentperm/adapters/codex.py +163 -0
- agentperm-0.3.0/src/agentperm/adapters/gemini.py +103 -0
- agentperm-0.3.0/src/agentperm/adapters/kiro.py +314 -0
- agentperm-0.3.0/src/agentperm/adapters/opencode.py +163 -0
- agentperm-0.3.0/src/agentperm/cli.py +411 -0
- agentperm-0.3.0/src/agentperm/domain.py +678 -0
- agentperm-0.3.0/src/agentperm/errors.py +5 -0
- agentperm-0.3.0/src/agentperm/fileio.py +32 -0
- agentperm-0.3.0/src/agentperm/policy.py +206 -0
- agentperm-0.3.0/src/agentperm/pythoncode.py +308 -0
- agentperm-0.3.0/src/agentperm/rules.py +153 -0
- agentperm-0.3.0/src/agentperm/shell.py +755 -0
- agentperm-0.3.0/src/agentperm/shellpattern.py +679 -0
- {agentperm-0.2.0 → agentperm-0.3.0}/tests/test_adapters.py +508 -28
- {agentperm-0.2.0 → agentperm-0.3.0}/tests/test_cli.py +26 -0
- {agentperm-0.2.0 → agentperm-0.3.0}/tests/test_parser.py +141 -0
- {agentperm-0.2.0 → agentperm-0.3.0}/tests/test_policy.py +533 -2
- agentperm-0.3.0/tests/test_pythoncode.py +185 -0
- agentperm-0.3.0/tests/test_shellpattern.py +1031 -0
- {agentperm-0.2.0 → agentperm-0.3.0}/zellij-plugin/README.md +16 -2
- agentperm-0.2.0/zellij-plugin/src/lib.rs → agentperm-0.3.0/zellij-plugin/src/main.rs +9 -0
- agentperm-0.2.0/PKG-INFO +0 -194
- agentperm-0.2.0/README.md +0 -135
- agentperm-0.2.0/src/agentperm/__init__.py +0 -2302
- {agentperm-0.2.0 → agentperm-0.3.0}/.gitignore +0 -0
- {agentperm-0.2.0 → agentperm-0.3.0}/LICENSE +0 -0
- {agentperm-0.2.0 → agentperm-0.3.0}/tests/__init__.py +0 -0
agentperm-0.3.0/PKG-INFO
ADDED
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: agentperm
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: Permission policy mediator for Claude Code, Codex, OpenCode, Gemini CLI, and Kiro.
|
|
5
|
+
Project-URL: Homepage, https://github.com/jacks0n/agentperm
|
|
6
|
+
Project-URL: Repository, https://github.com/jacks0n/agentperm
|
|
7
|
+
Project-URL: Issues, https://github.com/jacks0n/agentperm/issues
|
|
8
|
+
Author-email: Jackson Cooper <jackson@jacksonc.com>
|
|
9
|
+
License: MIT License
|
|
10
|
+
|
|
11
|
+
Copyright (c) 2026 Jackson Cooper
|
|
12
|
+
|
|
13
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
14
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
15
|
+
in the Software without restriction, including without limitation the rights
|
|
16
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
17
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
18
|
+
furnished to do so, subject to the following conditions:
|
|
19
|
+
|
|
20
|
+
The above copyright notice and this permission notice shall be included in all
|
|
21
|
+
copies or substantial portions of the Software.
|
|
22
|
+
|
|
23
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
24
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
25
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
26
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
27
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
28
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
29
|
+
SOFTWARE.
|
|
30
|
+
License-File: LICENSE
|
|
31
|
+
Keywords: agent,agentic,agentic-ai,agentic-tools,ai,ai-agent,ai-agents,ai-coding-assistant,ai-tools,anthropic,claude,claude-code,codex,codex-cli,coding-agent,coding-assistant,developer-tools,gemini,gemini-cli,hooks,kiro,llm,llm-agent,llm-tools,mcp,mediator,openai,opencode,permissions,policy,policy-engine,shell,tree-sitter,tree-sitter-bash
|
|
32
|
+
Classifier: Development Status :: 4 - Beta
|
|
33
|
+
Classifier: Environment :: Console
|
|
34
|
+
Classifier: Intended Audience :: Developers
|
|
35
|
+
Classifier: Intended Audience :: System Administrators
|
|
36
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
37
|
+
Classifier: Operating System :: MacOS
|
|
38
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
39
|
+
Classifier: Programming Language :: Python :: 3
|
|
40
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
41
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
42
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
43
|
+
Classifier: Topic :: Security
|
|
44
|
+
Classifier: Topic :: Software Development
|
|
45
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
46
|
+
Classifier: Topic :: System :: Shells
|
|
47
|
+
Classifier: Topic :: System :: Systems Administration
|
|
48
|
+
Classifier: Typing :: Typed
|
|
49
|
+
Requires-Python: >=3.12
|
|
50
|
+
Requires-Dist: pyjson5<3,>=2.0
|
|
51
|
+
Requires-Dist: tomlkit<0.14,>=0.13
|
|
52
|
+
Requires-Dist: tree-sitter-bash<0.26,>=0.25
|
|
53
|
+
Requires-Dist: tree-sitter<0.26,>=0.25
|
|
54
|
+
Provides-Extra: dev
|
|
55
|
+
Requires-Dist: basedpyright>=1.13; extra == 'dev'
|
|
56
|
+
Requires-Dist: pytest>=8.0; extra == 'dev'
|
|
57
|
+
Requires-Dist: ruff>=0.6; extra == 'dev'
|
|
58
|
+
Description-Content-Type: text/markdown
|
|
59
|
+
|
|
60
|
+
# agentperm
|
|
61
|
+
|
|
62
|
+
One permission policy for [Claude Code](https://docs.anthropic.com/en/docs/claude-code), [Codex CLI](https://github.com/openai/codex), [OpenCode](https://opencode.ai), [Gemini CLI](https://github.com/google-gemini/gemini-cli), and [Kiro](https://kiro.dev), with a shell parser that reads compound commands the way bash does.
|
|
63
|
+
|
|
64
|
+
## The problem
|
|
65
|
+
|
|
66
|
+
Coding agents ask before running shell commands. Each has its own permission config, and none of them parse what you typed — `cat foo | head -60` is one opaque string, so every agent asks about it even though both sides are read-only. You end up maintaining the same rules in three different places, and still getting prompted for things you've already allowed.
|
|
67
|
+
|
|
68
|
+
## What agentperm does
|
|
69
|
+
|
|
70
|
+
It replaces those separate configs with a single `.agent-permissions.jsonc` that every agent consults. It parses pipes, `&&`/`||` chains, loops, subshells, redirects, and `bash -c` wrappers, then decides each segment against your rules:
|
|
71
|
+
|
|
72
|
+
```jsonc
|
|
73
|
+
{
|
|
74
|
+
"version": 1,
|
|
75
|
+
"permissions": {
|
|
76
|
+
"allow": [
|
|
77
|
+
"Shell(git {status,log,diff,show,branch} !-*)",
|
|
78
|
+
"Shell(sed !{-i,--in-place})",
|
|
79
|
+
"Shell({cat,head,grep,rg,ls,wc})",
|
|
80
|
+
"Python(readonly)",
|
|
81
|
+
"Read", "Grep"
|
|
82
|
+
],
|
|
83
|
+
"ask": [
|
|
84
|
+
{ "tool": "Bash", "command": ["sed"], "when": { "hasOption": ["-i"] },
|
|
85
|
+
"reason": "sed -i edits files in place" }
|
|
86
|
+
],
|
|
87
|
+
"deny": ["Shell(sudo)", "Shell(rm -r -f /*)"]
|
|
88
|
+
},
|
|
89
|
+
"shell": {
|
|
90
|
+
"redirection": {
|
|
91
|
+
"stdoutToFile": "ask",
|
|
92
|
+
"allowPaths": ["/tmp"]
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
| Command | Verdict | Why |
|
|
99
|
+
|---|---|---|
|
|
100
|
+
| `cat foo 2>&1 \| head -60` | **allow** | both segments allowed; `2>&1` is a safe fd dup |
|
|
101
|
+
| `git status && cat README.md` | **allow** | `&&` — both sides allowed |
|
|
102
|
+
| `sed -i s/old/new/ x.txt` | **ask** | the ask rule on `-i` wins over the allow |
|
|
103
|
+
| `echo hi > /tmp/out.txt` | **allow** | redirect target matches `allowPaths` |
|
|
104
|
+
| `echo hi > ~/notes.txt` | **ask** | redirect to file outside `allowPaths` |
|
|
105
|
+
| `cat foo \| ./deploy.sh` | **ask** | one unrecognized segment in a compound |
|
|
106
|
+
| `rm -rf /` | **deny** | deny always wins |
|
|
107
|
+
|
|
108
|
+
No prompt on the first two. Native matchers ask about both because a pipe or `&&` defeats string matching.
|
|
109
|
+
|
|
110
|
+
## Install
|
|
111
|
+
|
|
112
|
+
```sh
|
|
113
|
+
uv tool install agentperm # or: pipx install agentperm
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## Setup
|
|
117
|
+
|
|
118
|
+
```sh
|
|
119
|
+
agentperm install # wire hooks into Claude Code / Codex / OpenCode / Gemini / Kiro
|
|
120
|
+
agentperm import # pull existing native rules into ~/.agent-permissions.jsonc
|
|
121
|
+
agentperm edit # open the policy in $VISUAL/$EDITOR
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
`install` writes to each agent's hook config, or merges into `~/.rulesync/hooks.json` if you use [Rulesync](https://github.com/dyoshikawa/rulesync). Preview with `--dry-run`. Your native settings keep working underneath — nothing is taken away.
|
|
125
|
+
|
|
126
|
+
## Writing rules
|
|
127
|
+
|
|
128
|
+
Rules go in `allow`, `ask`, or `deny`. First match wins within a list; deny beats ask beats allow across lists.
|
|
129
|
+
|
|
130
|
+
**Shell patterns** — the recommended form. Flags float; trailing args open by default:
|
|
131
|
+
|
|
132
|
+
```jsonc
|
|
133
|
+
"Shell(git {status,log,diff} !-*)" // match subcommands, reject all flags
|
|
134
|
+
"Shell(git push !--force)" // allow push, forbid --force
|
|
135
|
+
"Shell(aws values(--region) ec2 describe-*)" // declare that --region eats the next token
|
|
136
|
+
"Shell(git stash {list,show} !... !-*)" // exact subcommand, no extra args or flags
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
**Per-rule redirect paths** — allow redirects to specific directories for matching commands:
|
|
140
|
+
|
|
141
|
+
```jsonc
|
|
142
|
+
{"Shell(mise exec just synth-env)": {"allowPaths": ["/tmp"]}}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
**Named tools** — match non-shell tools, optionally scoped by input:
|
|
146
|
+
|
|
147
|
+
```jsonc
|
|
148
|
+
"Read" // exact
|
|
149
|
+
"mcp__memory__*" // prefix glob
|
|
150
|
+
"WebFetch(domain:github.com)" // URL host scoping
|
|
151
|
+
"Edit(src/**)" // path glob scoping
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
**Legacy positional** — `"Bash(git status:*)"` remains supported for existing policies and imports.
|
|
155
|
+
|
|
156
|
+
**Flag matching** — `{ "tool": "Bash", "command": ["sed"], "when": { "hasOption": ["-i"] }, "reason": "..." }`.
|
|
157
|
+
|
|
158
|
+
**Python analysis** — `"Python(readonly)"` shallowly inspects `python -c` and heredoc source with the stdlib AST. Imports, printing, and inspection run without a prompt; mutation asks.
|
|
159
|
+
|
|
160
|
+
In compounds the strictest segment decides. One unrecognized command = ask. Deny always wins. Full spec: [Shell pattern DSL](docs/pattern-dsl.md) · [Policy reference](docs/policy-reference.md).
|
|
161
|
+
|
|
162
|
+
## Global + per-project
|
|
163
|
+
|
|
164
|
+
`~/.agent-permissions.jsonc` sets global defaults. `<repo>/.agent-permissions.jsonc` adds project-specific rules. Both apply at the same time — deny wins across both.
|
|
165
|
+
|
|
166
|
+
```jsonc
|
|
167
|
+
// global — broad defaults
|
|
168
|
+
{ "version": 1, "permissions": {
|
|
169
|
+
"allow": ["Shell({cat,ls,grep,rg})", "Shell(git {status,diff,log})", "Read"],
|
|
170
|
+
"deny": ["Shell(sudo)", "Shell(rm -r -f /*)"]
|
|
171
|
+
}}
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
```jsonc
|
|
175
|
+
// ~/work/payments/.agent-permissions.jsonc — project overrides
|
|
176
|
+
{ "version": 1, "permissions": {
|
|
177
|
+
"allow": ["Shell(pytest)", "Shell(pnpm run {build,test,lint})"],
|
|
178
|
+
"deny": [{ "tool": "Bash", "command": ["git"],
|
|
179
|
+
"when": { "hasOption": ["--force"] },
|
|
180
|
+
"reason": "no force-push in this repo" }]
|
|
181
|
+
}}
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
A repo adds its own tools and clamps down on dangerous variants without touching the global file. `agentperm edit --local` creates or opens the project file.
|
|
185
|
+
|
|
186
|
+
## Redirect allowlisting
|
|
187
|
+
|
|
188
|
+
File redirects (`>`, `>>`) default to `ask`. You can allowlist directories globally or per-rule:
|
|
189
|
+
|
|
190
|
+
```jsonc
|
|
191
|
+
"shell": {
|
|
192
|
+
"redirection": {
|
|
193
|
+
"stdoutToFile": "ask",
|
|
194
|
+
"allowPaths": ["/tmp", "/private/tmp/claude-*"]
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
Paths resolve through symlinks (`/tmp` covers `/private/tmp` on macOS). Globs match per component. Relative targets resolve against the working directory.
|
|
200
|
+
|
|
201
|
+
## Zellij pane bypass
|
|
202
|
+
|
|
203
|
+
The bundled [WASM plugin](zellij-plugin/README.md) adds a per-pane toggle: `ask` and unmatched commands become `allow` in that pane only. `deny` rules still bite. Under Claude Code's own `--dangerously-skip-permissions`, agentperm steps aside completely.
|
|
204
|
+
|
|
205
|
+
## What it doesn't do
|
|
206
|
+
|
|
207
|
+
- **No sandbox.** It decides allow / ask / deny; it doesn't contain what runs.
|
|
208
|
+
- **No replacing native settings.** Those keep working as a fast path.
|
|
209
|
+
- **No MCP server management.** Use Rulesync or native config for that.
|
|
210
|
+
|
|
211
|
+
## More
|
|
212
|
+
|
|
213
|
+
[Policy reference](docs/policy-reference.md) · [Shell pattern DSL](docs/pattern-dsl.md) · [Architecture](docs/architecture.md) · [Adapter notes](docs/adapters.md) · [Changelog](CHANGELOG.md)
|
|
214
|
+
|
|
215
|
+
## License
|
|
216
|
+
|
|
217
|
+
MIT
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
# agentperm
|
|
2
|
+
|
|
3
|
+
One permission policy for [Claude Code](https://docs.anthropic.com/en/docs/claude-code), [Codex CLI](https://github.com/openai/codex), [OpenCode](https://opencode.ai), [Gemini CLI](https://github.com/google-gemini/gemini-cli), and [Kiro](https://kiro.dev), with a shell parser that reads compound commands the way bash does.
|
|
4
|
+
|
|
5
|
+
## The problem
|
|
6
|
+
|
|
7
|
+
Coding agents ask before running shell commands. Each has its own permission config, and none of them parse what you typed — `cat foo | head -60` is one opaque string, so every agent asks about it even though both sides are read-only. You end up maintaining the same rules in three different places, and still getting prompted for things you've already allowed.
|
|
8
|
+
|
|
9
|
+
## What agentperm does
|
|
10
|
+
|
|
11
|
+
It replaces those separate configs with a single `.agent-permissions.jsonc` that every agent consults. It parses pipes, `&&`/`||` chains, loops, subshells, redirects, and `bash -c` wrappers, then decides each segment against your rules:
|
|
12
|
+
|
|
13
|
+
```jsonc
|
|
14
|
+
{
|
|
15
|
+
"version": 1,
|
|
16
|
+
"permissions": {
|
|
17
|
+
"allow": [
|
|
18
|
+
"Shell(git {status,log,diff,show,branch} !-*)",
|
|
19
|
+
"Shell(sed !{-i,--in-place})",
|
|
20
|
+
"Shell({cat,head,grep,rg,ls,wc})",
|
|
21
|
+
"Python(readonly)",
|
|
22
|
+
"Read", "Grep"
|
|
23
|
+
],
|
|
24
|
+
"ask": [
|
|
25
|
+
{ "tool": "Bash", "command": ["sed"], "when": { "hasOption": ["-i"] },
|
|
26
|
+
"reason": "sed -i edits files in place" }
|
|
27
|
+
],
|
|
28
|
+
"deny": ["Shell(sudo)", "Shell(rm -r -f /*)"]
|
|
29
|
+
},
|
|
30
|
+
"shell": {
|
|
31
|
+
"redirection": {
|
|
32
|
+
"stdoutToFile": "ask",
|
|
33
|
+
"allowPaths": ["/tmp"]
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
| Command | Verdict | Why |
|
|
40
|
+
|---|---|---|
|
|
41
|
+
| `cat foo 2>&1 \| head -60` | **allow** | both segments allowed; `2>&1` is a safe fd dup |
|
|
42
|
+
| `git status && cat README.md` | **allow** | `&&` — both sides allowed |
|
|
43
|
+
| `sed -i s/old/new/ x.txt` | **ask** | the ask rule on `-i` wins over the allow |
|
|
44
|
+
| `echo hi > /tmp/out.txt` | **allow** | redirect target matches `allowPaths` |
|
|
45
|
+
| `echo hi > ~/notes.txt` | **ask** | redirect to file outside `allowPaths` |
|
|
46
|
+
| `cat foo \| ./deploy.sh` | **ask** | one unrecognized segment in a compound |
|
|
47
|
+
| `rm -rf /` | **deny** | deny always wins |
|
|
48
|
+
|
|
49
|
+
No prompt on the first two. Native matchers ask about both because a pipe or `&&` defeats string matching.
|
|
50
|
+
|
|
51
|
+
## Install
|
|
52
|
+
|
|
53
|
+
```sh
|
|
54
|
+
uv tool install agentperm # or: pipx install agentperm
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Setup
|
|
58
|
+
|
|
59
|
+
```sh
|
|
60
|
+
agentperm install # wire hooks into Claude Code / Codex / OpenCode / Gemini / Kiro
|
|
61
|
+
agentperm import # pull existing native rules into ~/.agent-permissions.jsonc
|
|
62
|
+
agentperm edit # open the policy in $VISUAL/$EDITOR
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
`install` writes to each agent's hook config, or merges into `~/.rulesync/hooks.json` if you use [Rulesync](https://github.com/dyoshikawa/rulesync). Preview with `--dry-run`. Your native settings keep working underneath — nothing is taken away.
|
|
66
|
+
|
|
67
|
+
## Writing rules
|
|
68
|
+
|
|
69
|
+
Rules go in `allow`, `ask`, or `deny`. First match wins within a list; deny beats ask beats allow across lists.
|
|
70
|
+
|
|
71
|
+
**Shell patterns** — the recommended form. Flags float; trailing args open by default:
|
|
72
|
+
|
|
73
|
+
```jsonc
|
|
74
|
+
"Shell(git {status,log,diff} !-*)" // match subcommands, reject all flags
|
|
75
|
+
"Shell(git push !--force)" // allow push, forbid --force
|
|
76
|
+
"Shell(aws values(--region) ec2 describe-*)" // declare that --region eats the next token
|
|
77
|
+
"Shell(git stash {list,show} !... !-*)" // exact subcommand, no extra args or flags
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
**Per-rule redirect paths** — allow redirects to specific directories for matching commands:
|
|
81
|
+
|
|
82
|
+
```jsonc
|
|
83
|
+
{"Shell(mise exec just synth-env)": {"allowPaths": ["/tmp"]}}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
**Named tools** — match non-shell tools, optionally scoped by input:
|
|
87
|
+
|
|
88
|
+
```jsonc
|
|
89
|
+
"Read" // exact
|
|
90
|
+
"mcp__memory__*" // prefix glob
|
|
91
|
+
"WebFetch(domain:github.com)" // URL host scoping
|
|
92
|
+
"Edit(src/**)" // path glob scoping
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
**Legacy positional** — `"Bash(git status:*)"` remains supported for existing policies and imports.
|
|
96
|
+
|
|
97
|
+
**Flag matching** — `{ "tool": "Bash", "command": ["sed"], "when": { "hasOption": ["-i"] }, "reason": "..." }`.
|
|
98
|
+
|
|
99
|
+
**Python analysis** — `"Python(readonly)"` shallowly inspects `python -c` and heredoc source with the stdlib AST. Imports, printing, and inspection run without a prompt; mutation asks.
|
|
100
|
+
|
|
101
|
+
In compounds the strictest segment decides. One unrecognized command = ask. Deny always wins. Full spec: [Shell pattern DSL](docs/pattern-dsl.md) · [Policy reference](docs/policy-reference.md).
|
|
102
|
+
|
|
103
|
+
## Global + per-project
|
|
104
|
+
|
|
105
|
+
`~/.agent-permissions.jsonc` sets global defaults. `<repo>/.agent-permissions.jsonc` adds project-specific rules. Both apply at the same time — deny wins across both.
|
|
106
|
+
|
|
107
|
+
```jsonc
|
|
108
|
+
// global — broad defaults
|
|
109
|
+
{ "version": 1, "permissions": {
|
|
110
|
+
"allow": ["Shell({cat,ls,grep,rg})", "Shell(git {status,diff,log})", "Read"],
|
|
111
|
+
"deny": ["Shell(sudo)", "Shell(rm -r -f /*)"]
|
|
112
|
+
}}
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
```jsonc
|
|
116
|
+
// ~/work/payments/.agent-permissions.jsonc — project overrides
|
|
117
|
+
{ "version": 1, "permissions": {
|
|
118
|
+
"allow": ["Shell(pytest)", "Shell(pnpm run {build,test,lint})"],
|
|
119
|
+
"deny": [{ "tool": "Bash", "command": ["git"],
|
|
120
|
+
"when": { "hasOption": ["--force"] },
|
|
121
|
+
"reason": "no force-push in this repo" }]
|
|
122
|
+
}}
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
A repo adds its own tools and clamps down on dangerous variants without touching the global file. `agentperm edit --local` creates or opens the project file.
|
|
126
|
+
|
|
127
|
+
## Redirect allowlisting
|
|
128
|
+
|
|
129
|
+
File redirects (`>`, `>>`) default to `ask`. You can allowlist directories globally or per-rule:
|
|
130
|
+
|
|
131
|
+
```jsonc
|
|
132
|
+
"shell": {
|
|
133
|
+
"redirection": {
|
|
134
|
+
"stdoutToFile": "ask",
|
|
135
|
+
"allowPaths": ["/tmp", "/private/tmp/claude-*"]
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
Paths resolve through symlinks (`/tmp` covers `/private/tmp` on macOS). Globs match per component. Relative targets resolve against the working directory.
|
|
141
|
+
|
|
142
|
+
## Zellij pane bypass
|
|
143
|
+
|
|
144
|
+
The bundled [WASM plugin](zellij-plugin/README.md) adds a per-pane toggle: `ask` and unmatched commands become `allow` in that pane only. `deny` rules still bite. Under Claude Code's own `--dangerously-skip-permissions`, agentperm steps aside completely.
|
|
145
|
+
|
|
146
|
+
## What it doesn't do
|
|
147
|
+
|
|
148
|
+
- **No sandbox.** It decides allow / ask / deny; it doesn't contain what runs.
|
|
149
|
+
- **No replacing native settings.** Those keep working as a fast path.
|
|
150
|
+
- **No MCP server management.** Use Rulesync or native config for that.
|
|
151
|
+
|
|
152
|
+
## More
|
|
153
|
+
|
|
154
|
+
[Policy reference](docs/policy-reference.md) · [Shell pattern DSL](docs/pattern-dsl.md) · [Architecture](docs/architecture.md) · [Adapter notes](docs/adapters.md) · [Changelog](CHANGELOG.md)
|
|
155
|
+
|
|
156
|
+
## License
|
|
157
|
+
|
|
158
|
+
MIT
|
|
@@ -4,8 +4,8 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "agentperm"
|
|
7
|
-
version = "0.
|
|
8
|
-
description = "Permission policy mediator for Claude Code, Codex, OpenCode,
|
|
7
|
+
version = "0.3.0"
|
|
8
|
+
description = "Permission policy mediator for Claude Code, Codex, OpenCode, Gemini CLI, and Kiro."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = { file = "LICENSE" }
|
|
11
11
|
requires-python = ">=3.12"
|
|
@@ -33,6 +33,7 @@ keywords = [
|
|
|
33
33
|
"gemini",
|
|
34
34
|
"gemini-cli",
|
|
35
35
|
"hooks",
|
|
36
|
+
"kiro",
|
|
36
37
|
"llm",
|
|
37
38
|
"llm-agent",
|
|
38
39
|
"llm-tools",
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"""Permission policy mediator for Claude Code, Codex, OpenCode, Gemini CLI, and Kiro.
|
|
2
|
+
|
|
3
|
+
Package layout:
|
|
4
|
+
agentperm.domain — Decision, Verdict, Rule, Request, Pipeline, Segment, Policy
|
|
5
|
+
agentperm.shell — Tree-sitter Bash → Pipeline
|
|
6
|
+
agentperm.pythoncode — shallow AST analysis for inline Python
|
|
7
|
+
agentperm.rules — string/dict ↔ Rule
|
|
8
|
+
agentperm.policy — file ↔ Policy
|
|
9
|
+
agentperm.adapters — AgentAdapter ABC + Claude/Codex/Opencode/Gemini/Kiro
|
|
10
|
+
agentperm.cli — import, check, edit, install
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
from .adapters import ADAPTERS, ClaudeAdapter, CodexAdapter, GeminiAdapter, KiroAdapter, OpencodeAdapter
|
|
16
|
+
from .adapters.base import AgentAdapter
|
|
17
|
+
from .cli import agentperm_bypass_dir, coerce_for_pane_bypass, coerce_for_permission_mode, main
|
|
18
|
+
from .domain import (
|
|
19
|
+
POLICY_FILENAME,
|
|
20
|
+
AgentName,
|
|
21
|
+
BashCommand,
|
|
22
|
+
BashOption,
|
|
23
|
+
Decision,
|
|
24
|
+
InstallMode,
|
|
25
|
+
JsonArray,
|
|
26
|
+
JsonObject,
|
|
27
|
+
JsonValue,
|
|
28
|
+
NamedTool,
|
|
29
|
+
Pipeline,
|
|
30
|
+
Policy,
|
|
31
|
+
PythonCallPolicy,
|
|
32
|
+
PythonReadonly,
|
|
33
|
+
RedirectionPolicy,
|
|
34
|
+
Request,
|
|
35
|
+
Rule,
|
|
36
|
+
Segment,
|
|
37
|
+
ShellPattern,
|
|
38
|
+
ShellRequest,
|
|
39
|
+
ToolRequest,
|
|
40
|
+
Verdict,
|
|
41
|
+
aggregate,
|
|
42
|
+
narrow_json,
|
|
43
|
+
)
|
|
44
|
+
from .errors import PolicyError
|
|
45
|
+
from .policy import PolicyFile, git_toplevel, load_policy_file, merged_policy, save_policy_file, write_default_policy
|
|
46
|
+
from .rules import parse_rule
|
|
47
|
+
from .shell import parse_pipeline
|
|
48
|
+
|
|
49
|
+
__all__ = [
|
|
50
|
+
"ADAPTERS",
|
|
51
|
+
"POLICY_FILENAME",
|
|
52
|
+
"AgentAdapter",
|
|
53
|
+
"AgentName",
|
|
54
|
+
"BashCommand",
|
|
55
|
+
"BashOption",
|
|
56
|
+
"ClaudeAdapter",
|
|
57
|
+
"CodexAdapter",
|
|
58
|
+
"Decision",
|
|
59
|
+
"GeminiAdapter",
|
|
60
|
+
"InstallMode",
|
|
61
|
+
"JsonArray",
|
|
62
|
+
"JsonObject",
|
|
63
|
+
"JsonValue",
|
|
64
|
+
"KiroAdapter",
|
|
65
|
+
"NamedTool",
|
|
66
|
+
"OpencodeAdapter",
|
|
67
|
+
"Pipeline",
|
|
68
|
+
"Policy",
|
|
69
|
+
"PolicyError",
|
|
70
|
+
"PolicyFile",
|
|
71
|
+
"PythonCallPolicy",
|
|
72
|
+
"PythonReadonly",
|
|
73
|
+
"RedirectionPolicy",
|
|
74
|
+
"Request",
|
|
75
|
+
"Rule",
|
|
76
|
+
"Segment",
|
|
77
|
+
"ShellPattern",
|
|
78
|
+
"ShellRequest",
|
|
79
|
+
"ToolRequest",
|
|
80
|
+
"Verdict",
|
|
81
|
+
"agentperm_bypass_dir",
|
|
82
|
+
"aggregate",
|
|
83
|
+
"coerce_for_pane_bypass",
|
|
84
|
+
"coerce_for_permission_mode",
|
|
85
|
+
"git_toplevel",
|
|
86
|
+
"load_policy_file",
|
|
87
|
+
"main",
|
|
88
|
+
"merged_policy",
|
|
89
|
+
"narrow_json",
|
|
90
|
+
"parse_pipeline",
|
|
91
|
+
"parse_rule",
|
|
92
|
+
"save_policy_file",
|
|
93
|
+
"write_default_policy",
|
|
94
|
+
]
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"""Public adapter registry and automatic adapter selection."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from ..domain import AgentName, JsonObject
|
|
6
|
+
from .base import AgentAdapter
|
|
7
|
+
from .claude import ClaudeAdapter
|
|
8
|
+
from .codex import CodexAdapter
|
|
9
|
+
from .gemini import GEMINI_TOOL_NAMES, GeminiAdapter
|
|
10
|
+
from .kiro import KIRO_TOOL_NAMES, KiroAdapter
|
|
11
|
+
from .opencode import OpencodeAdapter
|
|
12
|
+
|
|
13
|
+
ADAPTERS: dict[AgentName, AgentAdapter] = {
|
|
14
|
+
AgentName.Claude: ClaudeAdapter(),
|
|
15
|
+
AgentName.Codex: CodexAdapter(),
|
|
16
|
+
AgentName.Opencode: OpencodeAdapter(),
|
|
17
|
+
AgentName.Gemini: GeminiAdapter(),
|
|
18
|
+
AgentName.Kiro: KiroAdapter(),
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def select_adapter(agent: AgentName, event: str, payload: JsonObject) -> AgentAdapter:
|
|
23
|
+
if agent is not AgentName.Auto:
|
|
24
|
+
return ADAPTERS[agent]
|
|
25
|
+
# Kiro's hook event names are lower camel case. Prefer this unambiguous
|
|
26
|
+
# signal before inspecting tool names shared with Gemini (for example
|
|
27
|
+
# ``glob`` and ``web_fetch``).
|
|
28
|
+
if event in ("preToolUse", "postToolUse"):
|
|
29
|
+
return ADAPTERS[AgentName.Kiro]
|
|
30
|
+
if event in ("BeforeTool", "AfterTool"):
|
|
31
|
+
return ADAPTERS[AgentName.Gemini]
|
|
32
|
+
tool_name = payload.get("tool_name")
|
|
33
|
+
if isinstance(tool_name, str) and tool_name in GEMINI_TOOL_NAMES:
|
|
34
|
+
return ADAPTERS[AgentName.Gemini]
|
|
35
|
+
if isinstance(tool_name, str) and tool_name in KIRO_TOOL_NAMES:
|
|
36
|
+
return ADAPTERS[AgentName.Kiro]
|
|
37
|
+
if event == "PermissionRequest" and isinstance(payload.get("permission"), dict):
|
|
38
|
+
return ADAPTERS[AgentName.Codex]
|
|
39
|
+
if event == "PermissionRequest":
|
|
40
|
+
return ADAPTERS[AgentName.Claude]
|
|
41
|
+
if event in ("permission.ask", "permission.asked"):
|
|
42
|
+
return ADAPTERS[AgentName.Opencode]
|
|
43
|
+
return ADAPTERS[AgentName.Claude]
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
__all__ = [
|
|
47
|
+
"ADAPTERS",
|
|
48
|
+
"AgentAdapter",
|
|
49
|
+
"ClaudeAdapter",
|
|
50
|
+
"CodexAdapter",
|
|
51
|
+
"GeminiAdapter",
|
|
52
|
+
"KiroAdapter",
|
|
53
|
+
"OpencodeAdapter",
|
|
54
|
+
"select_adapter",
|
|
55
|
+
]
|