trusty_code/permissions/mod.rs
1//! Per-verb glob-pattern tool permissions for tcode agents (#7948).
2//!
3//! Why: before this, an agent's only tool control was `tcode_tools:` — a flat
4//! exact-match allowlist that can say "this agent may run `bash`" and nothing
5//! finer. Real coding work needs "`git status` without asking, never `rm`, ask
6//! about everything else", which is what opencode's `permission` config
7//! expresses and what the TUI permission prompt (#3422) has to prompt FROM.
8//! What: `config` (the `permissions:` frontmatter schema, parser, and
9//! fail-closed validation), `matcher` (glob matching, subject extraction, and
10//! the precedence order), `gate` (the runtime decision and the ask/await
11//! round trip), `session` (per-session pending requests and remembered
12//! grants, plus the daemon-wide broker), `redact` (credential scrubbing for
13//! the published subject), and `protocol` (the `session.permission.respond`
14//! JSON-RPC method).
15//!
16//! The legacy `tcode_tools` allowlist is enforced FIRST: a tool absent from it
17//! is denied before the permission map is consulted, so a map can only narrow
18//! an agent's reach. #7948: the exception is `gate::HARNESS_REGISTERED_TOOLS` —
19//! tools the harness wires up for the agent rather than the agent asking for
20//! them — which the allowlist branch skips; a written `deny` still refuses one.
21//! Stock bundled agents declare no `permissions:` block, so their behaviour
22//! does not change.
23//! Test: `permissions::tests` — one test module per submodule.
24
25pub mod config;
26pub mod gate;
27pub mod matcher;
28pub mod protocol;
29pub mod redact;
30pub mod session;
31
32pub use config::{PermissionConfigError, PermissionMap, RuleDecision, parse_permissions};
33pub use gate::{
34 DEFAULT_ASK_TIMEOUT_SECS, Decision, DenySource, HARNESS_REGISTERED_TOOLS, Outcome,
35 PERMISSION_MODE_ENV, PermissionContext, PermissionEvents, PermissionGate, PermissionMode,
36};
37pub use matcher::{RuleMatch, subjects_for, subjects_for_in_root};
38pub use protocol::{PERMISSION_RESPOND_METHOD, PermissionDecision};
39pub use redact::redact_subject;
40pub use session::{PermissionBroker, SessionPermissions};
41
42#[cfg(test)]
43mod tests;