Skip to main content

Module ide_permissions

Module ide_permissions 

Source
Expand description

Read the active IDE’s tool-permission configuration and resolve an effective action for a lean-ctx tool, so lean-ctx can mirror (“inherit”) the user’s IDE permission rules instead of forming a second, ungoverned execution path.

Motivation (community request): when lean-ctx is mounted as an MCP server, its tools (e.g. ctx_shell) run inside the lean-ctx process and therefore bypass the host IDE’s own permission engine — a user who set bash/rm * to ask/deny in their IDE would have that guard silently skipped whenever the agent reaches for ctx_shell instead of the native tool. This module parses the IDE permission config and lets the server gate apply an equivalent decision.

v1 supports OpenCode (opencode.json / opencode.jsonc, global + project). The mapping is intentionally pure and side-effect-free; the server wiring (client detection, tool→key mapping, messaging, caching) lives in server::permission_inheritance.

lean-ctx never writes the IDE’s permission block — inheritance is read-only and runtime-only.

Structs§

IdePermissionPolicy
Normalized IDE permission policy: the merged permission object from the IDE config (project entries override global ones per top-level key).
PermDecision
A resolved decision together with the human-readable rule that produced it.

Enums§

PermAction
An IDE permission decision for a single action.

Functions§

load_opencode
Read and merge the OpenCode permission object: global config first, then the project config (project keys override global). Missing/invalid files are skipped silently — inheritance must never break a tool call by erroring.
wildcard_match
Minimal glob matcher supporting * (matches any run of characters, including empty); ** is treated as *. No ? or character classes — this mirrors the simple command/path globs OpenCode permission rules use (git *, rm *, src/*). Matching is case-sensitive.