@pi-kode/permissions0.1.0
Standalone pi governance extension: permissions, planning mode, hooks, and subagents
Untested on omp
This is a pi package. No one has reported whether it works on omp yet. If you try it, add your result below.
Reports 0
No reports yet.
Readme
@pi-kode/permissions
Standalone pi governance extension providing tool permissions, planning mode, lifecycle hooks, and policy-enforced subagents.
Capabilities
1. Permissions and policy rules
Intercepts tool calls and evaluates them against the active permission mode and configured allow, ask, and deny rules.
Permission modes
Run /permissions or /permissions mode to open the mode picker, or switch directly with /permissions mode <mode>:
- Safe (
safe, default): automatically allows workspace reads (Read,Glob,Grep,TaskGet,TaskList,TaskOutputwithin the workspace), read-only subagents (Explore,Plan), and workflow tools. File mutations, shell commands, and other operations require approval unless matched by anallowrule. - Ask Everything (
ask): requires approval before every tool call, including reads and calls covered byallowrules. Session approvals are not reused. Explicitdenyrules still block. - Full Access (
fullAccess): allows operations without approval, including those covered byaskrules. Explicitdenyrules still apply. Full Access does not grant operating-system privileges or bypass external sandboxes.
Legacy modes (acceptEdits, dontAsk, bypassPermissions) remain supported; legacy default session state is normalized to safe on restore. Mode selection is persisted per session branch.
Use /permissions status (or any /permissions command) to inspect the active mode, loaded rules, session approval count, and session wildcard rules.
Interactive approvals and session grants
When a tool call requires approval, the UI prompts with:
Allow onceAllow this exact call for session(bound to tool name, input hash, canonical target path, policy fingerprint, and mode; not offered inaskmode)- Session wildcard rules where applicable, such as
Bash(<prefix>:*),Edit(<dir>/**), orGrep(<dir>/**)(not offered inaskmode) Deny
Before allowing execution after an approval prompt, the extension re-checks the policy fingerprint, input hash, and canonical path so changes during approval are rejected. Session grants and session rules persist in the session branch and are restored on session load or tree navigation.
Policy rules and tool aliasing
Add persistent project rules with /permissions allow <Rule>, /permissions ask <Rule>, or /permissions deny <Rule> (saved to .pi/settings.local.json; requires project trust).
Rules are evaluated in order: deny, then ask, then allow.
- Tool rules:
Bash,Edit,Write,Read,Glob,Grep,NotebookEdit,Agent, etc. - Path globs: e.g.
Edit(src/**)orRead(/path/to/file). Both lexical and canonical (symlink-resolved) paths are checked. - Shell rules: exact commands (
Bash(npm test)) or safe command prefixes (Bash(npm test:*)). Shell prefix parsing rejects compound operators (;,&&,||,|), redirections, expansions ($, backticks), and newlines, and normalizes redundantcd <cwd> && ...prefixes. - Tool aliases: native
pitools (read,write,edit,bash,grep,find,ls) map toRead,Write,Edit,Bash,Grep,Glob.TaskRunsharesBashpolicy,AgentBatchsharesAgentpolicy, andNotebookEditsharesEditpolicy.
2. Planning mode and user clarification
EnterPlanMode: switches the session to read-onlyplanmode, remembers the previous mode, and designates a session-scoped plan file (plan.md). While inplanmode, source edits, shell tools, anduser_bashare blocked; only workspace reads, read-only subagents, workflow tools, and edits to the designated plan file are allowed. Mode cannot be changed via/permissions modeuntil exited throughExitPlanMode.ExitPlanMode: displays the plan content and SHA-256 hash prefix for explicit UI approval. Verifies the plan file did not change during approval and restores the previous permission mode only if approved.AskUserQuestion: asks 1–4 structured single-select questions (each with 2–4 options plus a custom free-text option) via TUI/RPC UI. Fails explicitly in unattended/non-UI sessions.
3. Lifecycle hooks
Runs configured shell command hooks from hooks.<Event> in .pi/settings.json / .pi/settings.local.json (project hooks require project trust).
Supported events wired in this extension:
SessionStart/SessionEndUserPromptSubmit(can block prompts or append context)PreToolUse(can block tool calls; input rewrites on native tools are rejected)PostToolUse/PostToolUseFailure(can append additional context to tool results)Stop(can keep the agent working when a stop hook blocks settling)
Hooks receive a JSON payload on stdin and CLAUDE_PROJECT_DIR in their environment. Tool hooks support * or pipe-separated matchers (e.g. Bash|Edit) and configurable timeouts (default 30s, max 120s). Exit code 2 denies/blocks the operation; JSON stdout can return decision, continue, and hookSpecificOutput (permissionDecision, additionalContext).
4. Subagents
Agent: launches an isolated childpisession with roleExplore,Plan, orgeneral-purpose, inheriting the parent model, thinking level, and permission policy.ExploreandPlan(and any subagent while inplanmode) receive read-only tools (read,grep,find,ls).general-purpose(outsideplanmode) receivesread,grep,find,ls,bash,edit,write.- Recursive delegation is disabled. Child tool calls are evaluated against the parent policy, and approvals route through the parent UI.
- Supports
resumeby saved agent UUID (keeping the original role),max_turns(default 20, max 100), andtimeout(default 600s, max 3600s).
AgentBatch: runs 1–8 independent subagent requests concurrently with a cap of 4 active children at once, preserving individual reports even when a sibling fails.
Configuration
Settings are loaded from:
~/.pi/settings.json<workspace>/.pi/settings.json(when project trust is granted)<workspace>/.pi/settings.local.json(when project trust is granted)
Example .pi/settings.json:
{
"permissions": {
"defaultMode": "safe",
"allow": ["Bash(npm test:*)"],
"ask": ["Write(src/**)"],
"deny": ["Bash(rm -rf:*)"]
},
"hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [
{
"type": "command",
"command": "./scripts/check-command.sh",
"timeout": 15
}
]
}
]
}
}
Installing from npm
The committed .npmrc routes @pi-kode packages to the public npm registry. The package is published publicly at npmjs.com/settings/pi-kode/packages and requires no authentication to install:
npm install @pi-kode/permissions
Or install @pi-kode/permissions through pi's package manager.
Contributing & Development
See CONTRIBUTING.md for local setup, running tests and type checks, architecture guidelines, and the release process.