# Glossary

The terms this package uses, each with the meaning it has here.
An entry defines a term; the record it links to decides how the thing behaves.
Terms are grouped by topic, and each heading is a stable anchor (`glossary.md#surface`) that other docs and agents may link to.
[The domain model](domain-model.md) walks through how the terms compose, with a worked example.

## Decisions

### Action

What a rule specifies: `allow`, `ask`, or `deny`.
`allow` lets the call proceed, `deny` blocks it, and `ask` escalates it to live [authority](#authority).
A `deny` may carry a reason, which the agent is shown.
A later rule can override an earlier rule's action (see [last-match-wins](#last-match-wins)), so an action is not yet a [decision](#decision).
In code an action is a `PermissionState`, held in a resolved check's `state`.

### Decision

The final `allow` or `deny` for one request, after any escalation.
The `permissions:decision` event reports it as `result`, and the [review log](#review-log) records what made it as `decidedBy` (its [decider](#decider)).

### Decider

What decided a request, recorded in the [review log](#review-log) as `decidedBy`.
It is one of: a rule (recorded [authority](#authority), [session rules](#session-rule) included); an [authorizer link](#link); the human, at the inline dialog or the `select` fallback; [auto-approve](#auto-approve); another session, for a [forwarded](#forwarding) ask, recorded with that session's own decider; or nobody, when no authority was reachable or a prompt went unanswered.
A gate that throws decides by blocking, and a Pi infrastructure read is allowed by containment rather than by a rule; each is recorded as its own decider.
An [authorizer](#authorizer) is not always the decider: when `LocalUserAuthorizer` prompts, the human decides.
The type in code is `DecisionSource`.

### Verdict

What an [authorizer link](#link) returns for an `ask`: `allow`, `deny`, [`defer`](#defer), or `allow_units`, which allows some [asking units](#asking-unit) of a bash chain and passes the ask on narrowed to the rest.
A [terminal](#terminal) returns only `allow` or `deny`.
See [ADR 0007](decisions/0007-model-judge-authorizer-chain-adr.md) decisions 1 and 2.

### Judgment

A decision made by live authority (the human, or a model behind an [authorizer link](#link)) on an `ask`, as opposed to the deterministic resolution of recorded authority.
Judgment may be non-deterministic; the package's determinism guarantee covers recorded authority only.
The layering rule is "surface deterministically, discriminate with judgment" ([ADR 0009](decisions/0009-bash-path-projection-completeness-contract.md)).

## Policy

### Rule

One [rule key](#rule-key) → [action](#action) entry, carrying its [rule origin](#rule-origin).
Every [policy](#policy), a policy file's or the session's, is normalized to rules before a check consults them.
See [Core data model](architecture/architecture.md#core-data-model).

### Rule key

A rule's [surface](#surface) and [pattern](#pattern) together: `bash` and `git *` in `bash git *` → `allow`.
In a config file the surface is the outer key and the pattern the inner one, `{ "bash": { "git *": "allow" } }`.
A rule key identifies a rule: when a later [scope](#scope) restates an earlier scope's rule key, the earlier rule is dropped and the later one sits at the later scope's position ([ADR 0016](decisions/0016-policy-channels.md) §2).

### Pattern

The match side of a rule: a command glob, tool name, file path, MCP target, skill name, or `*`.
`*` matches any run of characters, including `/`, and `?` matches one character; `**` is not a separate globstar and behaves exactly like `*`.

### Surface

The key a rule is filed under, naming the kind of access it governs.
Surfaces are tool names (`read`, `write`, `edit`, `bash`, …), `mcp`, `skill`, and the directional path surfaces (`path_read`, `path_write`, `external_directory_read`, `external_directory_write`).
One tool call can be checked on several surfaces; see [gate](#gate).
The `*` key, `permission["*"]`, is the universal fallback for any surface without a matching rule.

### Surface family

`path` and `external_directory` each name a family of two directional surfaces, `_read` and `_write`.
The two directions are independent: a `path_write` allow grants no read, and a `path_read` deny blocks no write.
See [ADR 0013](decisions/0013-permission-policy-model.md) decisions 3 and 4.

### Sugar

A bare `path` or `external_directory` key in config.
It is expanded at load time, separately for each [scope](#scope) and before scopes are merged, into both directional surfaces of its family; explicit directional entries are placed after the expanded ones.

### Path

The `path` family governs a file path wherever it is, matched against both its typed spelling and its resolved one (symlinks followed and, on POSIX, the spelling the filesystem stores).
Its idiomatic use is carving denials such as `~/.ssh/*`; granting access outside the working directory is the job of [external directory](#external-directory).

### External directory

The `external_directory` family fires on a path's relation to the session's working directory (being outside it), not on how the path is spelled.
It answers "is this in scope at all", while `path` answers "is this particular access permitted", and a call must pass both.
Granting an outside root takes one line: `external_directory_read: { "~/dev/*": "allow" }`.
See [ADR 0013](decisions/0013-permission-policy-model.md) decision 5.

### Effect

What an access does to a file: `read` or `write`.
A bash path operand's effect is proven by syntax (a redirect), by the built-in set of pure-reader commands, or by the user's `commandEffects` declarations; an operand whose effect is unproven consults both directions.
`commandEffects` classifies commands; it is not a rule and grants nothing by itself.
See [ADR 0013](decisions/0013-permission-policy-model.md) decisions 2 and 7.

### Policy

The rules one [policy source](#policy-source) contributes, and nothing else: the global policy (the global config file's rules), the project-local policy, an agent policy, the session policy, the default policy.
Runtime knobs and `commandEffects` declarations change outcomes too, but they are not policy.
The policies in effect for a check, together, are the [composed policy](#composed-policy).

### Policy source

Where a [policy](#policy) comes from: a [policy file](#policy-file), which fills a [scope](#scope); the session's grants, which make the session policy; or this package, which supplies the default and baseline policies.

### Policy file

A file a [policy](#policy) is read from: a scope's `config.json` or [local config file](#local-config-file), or the `permission:` block in an agent definition's frontmatter (`~/.pi/agent/agents/<agent>.md`, `<cwd>/.pi/agents/<agent>.md`).

### Layer

A band of the [composed policy](#composed-policy), in this order: `default` (the default policy), `baseline` (the baseline policy), `config` (every scope's policy, in scope order), and `session` (the session policy).
Each rule records its layer (`Rule.layer`).

### Composed policy

Every [policy](#policy) in [layer](#layer) order, for one agent at one moment: the agent running decides which agent policies join, and session grants accumulate as the session goes on.
It includes rewrites: while a [fail-closed floor](#fail-closed-floor) applies, it holds the floored rules in place of the rules as written.
Evaluation is [last-match-wins](#last-match-wins), so a later layer overrides an earlier one.
The code holds it as a `Ruleset`, an ordered list of rules.
See [Composed ruleset](architecture/architecture.md#composed-ruleset).

### Rule origin

The [policy source](#policy-source) a rule came from, recorded as the rule's `origin` string (`RuleOrigin`).
For a config rule it is the name of the [scope](#scope) its policy file fills (`global`, `global-local`, `project`, `project-local`, `agent`, `project-agent`); otherwise it is `baseline`, `session`, `fail-closed` (a floored rule, which no longer records its scope), or `builtin` (the default policy when no scope sets `"*"`, or a result a gate built without a rule).
A scope has a name, not a rule origin; its name becomes one once it is stamped on the rules its policy file contributed.
The `permissions:decision` event and the review log report it as `origin`, so a surprising outcome traces to its policy source.

### Scope

A precedence slot that a [policy file](#policy-file) fills: `global` (the global config file), `global-local` (the global [local config file](#local-config-file)), `project` (the project config file), `project-local` (the project local config file), `agent` (global agent frontmatter), and `project-agent` (project agent frontmatter), in that order.
A later scope's patterns are placed after an earlier scope's, and a pattern both define moves to the later scope's position, so a later catch-all overrides an earlier scope's specific patterns ([ADR 0016](decisions/0016-policy-channels.md) §2).
The three project scopes load only for a trusted project; see [project trust](#project-trust).

### Local config file

A `config.local.json` beside a scope's `config.json`, holding the same keys, for policy and settings that belong to one person on one machine rather than to everyone who shares the `config.json`.
Each is its own [scope](#scope), read right after its `config.json`; it is the only file the package itself writes, so no `config.json` is ever machine-written ([ADR 0016](decisions/0016-policy-channels.md) §4).

### Channel

Any path by which something that changes a check's outcome reaches the package: a scope's file, agent frontmatter, the session layer, a runtime knob such as `debugLog`, or a launch flag such as `--auto-approve`.
Which channels are admissible, and at what precedence, is decided in [ADR 0016](decisions/0016-policy-channels.md).
The authority model's "three channels" for reaching live authority use the word in that narrower sense.

### Relax and tighten

A change relaxes policy when it can move an outcome toward `allow` (`deny` or `ask` to `allow`), and tightens it when it moves the other way.

### Last-match-wins

Within one surface, the last matching rule in the [composed policy](#composed-policy) decides, so a later layer overrides an earlier one; for scopes, see [scope](#scope).

### Most-restrictive-wins

Across the surfaces one tool call is checked on, the most restrictive outcome wins (`deny` over `ask` over `allow`), so an allow on one surface cannot loosen another.
The same [combining rule](#combining-rule) joins a request's checks, a bash chain's command units, and a surface family's two directions.

### Session rule

A rule in the session policy, created when a human answers "for this session" at a prompt; also called a session approval.
The grant is made in one of three places: at this node's own prompt; at another session's prompt, for an ask this node [forwarded](#forwarding), recorded here when the answer comes back; or at this node's prompt while serving a subagent's forwarded ask, for the whole serving session ([ADR 0006](decisions/0006-forwarded-grant-scope-selection.md)).
It is held in memory, in the session [layer](#layer) after every config rule, and cleared when the session ends.
For bash, the suggested pattern comes from the arity table (`git checkout main` suggests `git checkout *`).
See [docs/session-approvals.md](session-approvals.md).

### Auto-approve

A per-session mode in which an `ask` every [authorizer link](#link) defers is allowed instead of prompted; a `deny` still denies.
It is a terminal reached after the chain, so links see every ask, and its decision is recorded as `decidedBy: { kind: "auto_approve", setter, scope }` with resolution `auto_approved`.
It is set in memory, never in a file: by the `--auto-approve` launch flag or the `/permission-system:auto-approve` command, scoped to this session's own asks, forwarded asks, or one requesting agent.
It replaced yolo, the retired `yoloMode` key, which rewrote every `ask` to `allow` before the chain.
See [Auto-approve is a terminal](architecture/architecture.md#auto-approve-is-a-terminal).

### Fail-closed floor

When a non-global scope is present but invalid, every `allow` in the default, baseline, and config [layers](#layer) becomes `ask` and its [rule origin](#rule-origin) becomes `fail-closed`, so a permissive lower scope cannot survive behind a broken higher one.
The session layer is not floored, so a session rule's `allow` still holds.
Its asks reach live authority like any other, so auto-approve may answer them.
See [Fail-closed on an invalid non-global scope](architecture/architecture.md#fail-closed-on-an-invalid-non-global-scope).

### Default and baseline

The default policy is one synthesized catch-all rule, `* *`, taking its action from the universal `permission["*"]` (`ask` when no scope sets it) and placed first in the [composed policy](#composed-policy).
Its [rule origin](#rule-origin) is the scope that set `"*"`, or `builtin` when none did.
The baseline policy is a small set of synthesized MCP metadata allows, present only when some scope allows anything on `mcp`, placed after the default and before config, so a config rule overrides it.

### Runtime knob

A config field that changes behavior without being a rule, such as `debugLog`, `permissionReviewLog`, or `promptTimeoutMs`.

### Propagation

When a running session sees a changed [channel](#channel).
Rules in config files and agent frontmatter, runtime knobs, and `commandEffects` declarations are all re-read at the next tool call, in both directions ([ADR 0016](decisions/0016-policy-channels.md) K7).

### Project trust

Pi's per-directory decision to trust a project's local resources, which this package observes through `ctx.isProjectTrusted()` and never makes itself.
See [ADR 0001](decisions/0001-project-trust-adoption.md).

## Checking

### Tool call

One invocation of a tool by the model.
Pi emits a `tool_call` event before the tool runs, where this package's [gates](#gate) check it and may block it.

### Gate

One stage a tool call must pass, each about one concern (a skill read, its paths, its external directories, the tool itself): a gate that applies runs one or more [checks](#check) against the [composed policy](#composed-policy), raises a [request](#request) when they leave something to decide or record, and acts on the result.
A tool call passes through a fixed sequence of six gates (skill read, path, external directory, bash external directory, bash path, tool), and the first block stops the call (an unconditionally denying gate is checked ahead of the rest); for a shell tool, the tool gate checks each command unit.
A `/skill:` invocation typed by the user has its own input gate.

### Request

What one [gate](#gate) raises for one tool call, identified by its `requestId`.
It is resolved by one or more [checks](#check), combined [most-restrictive-wins](#most-restrictive-wins); an `ask` escalates to live [authority](#authority), and the request ends in a [decision](#decision).
A gate raises none when it does not apply, or when its checks leave nothing to decide or record, which each gate judges for itself: the path gate, for instance, raises none when the [composed policy](#composed-policy) allows the path.
The review log and the `permissions:ui_prompt` and `permissions:decision` events carry the same `requestId`, so one request's records join.

### Check

One [access intent](#access-intent) resolved against the [composed policy](#composed-policy) under [last-match-wins](#last-match-wins), ending at one [matched rule](#matched-rule).
A request can run many: the bash path gate runs one check per path in `cat ~/a ~/b`, and the tool gate one per [command unit](#command-unit).
A check consults recorded authority only and never escalates.

### Access intent

What one [check](#check) is about, described without consulting policy and handed by a gate to the resolver: one path (`access-path`), one bash [command unit](#command-unit) (`bash-command`), or a tool's input (`tool`), which on `mcp` names the call's targets, on `skill` the skill, and on any other tool the tool itself.

### Candidate value

One spelling of an [access intent](#access-intent) that a [check](#check) matches rules against: a path's typed and resolved spellings, a command unit's spellings, or an MCP call's names (`github_search_code`, `github`, `mcp_call`).
The last rule matching any candidate value wins, so a catch-all matched by one spelling cannot mask a later, more specific rule matched by another.

### Matched rule

The rule a [check](#check) resolved to: the last rule matching any of its candidate values, or the [default policy](#default-and-baseline)'s `* *` when no other rule matches.
The review log and the `permissions:decision` event report its [rule origin](#rule-origin) as `origin`, and its pattern as `matchedPattern` when it is a config or session rule.

### Resolved action

The [matched rule](#matched-rule)'s [action](#action), after any floor.
It can be `ask`; only a [decision](#decision) cannot.

### Check result

What a [check](#check) returns: the [resolved action](#resolved-action), with the matched rule's pattern and [rule origin](#rule-origin).
In code it is a `PermissionCheckResult`.

### Combining rule

How results combine at one level of checking.
There are three:

- [last-match-wins](#last-match-wins), across the rules matching a check and across its candidate values;
- [most-restrictive-wins](#most-restrictive-wins), across a request's checks, a bash chain's command units, and a [surface family](#surface-family)'s two directions;
- the [wrapper unit](#wrapper-unit)'s rule, below.

### Command unit

One command the enumerator takes from a bash program and checks on the `bash` surface; the term is specific to bash.
A plain command is one unit, and three kinds have names of their own: a [compound unit](#compound-unit), a [nested unit](#nested-unit), and a [wrapper unit](#wrapper-unit).
Every unit of a chain is checked, combined [most-restrictive-wins](#most-restrictive-wins).

### Compound unit

A compound statement (`if`, `for`, `while`, `case`, a `{ … }` group, a function definition) checked whole, with each statement inside it checked as a unit too.
Checking the whole as well as its parts means adding the inner units can only make the outcome more restrictive.

### Nested unit

A command inside a command substitution (`$(…)`), a process substitution (`<(…)`), or a subshell (`( … )`), checked as a unit of its own in addition to the command that encloses it, since it really runs.
Its check result records where it sat (`commandContext`).

### Wrapper unit

A command that runs another: an indirection such as `sudo`, `env`, `xargs`, `time`, or `find -exec`, or an opaque payload such as `eval` or `bash -c`.
Its rule applies only when the unit's own check resolves `allow`, and not by a session grant.
The `allow` is floored to `ask`, unless the wrapper names no command at all (`env` alone), which keeps it, or the wrapper only changes how its [executed command](#executed-command) runs or that command is a pure reader, in which case a check of the executed command replaces it.

### Executed command

The command a [wrapper unit](#wrapper-unit) runs: `rm x` in `sudo rm x`.
It is checked only when the wrapper's rule hands it the decision, and it is never a command unit of its own.

### Asking unit

A [command unit](#command-unit) of a bash chain whose own rule, or a floor, resolved `ask`.
A chain's prompt names its first asking unit as the value and every other one beside it, its session option records one pattern per asking unit, and a forwarded ask carries them all so the serving node judges each.
A link's `allow_units` [verdict](#verdict) settles some of them, and the prompt and its session option then cover only the rest.

### Exposure

The check run at `before_agent_start` that hides a tool from the model when every value on its surface resolves to `deny`.
It is the first of two phases; gating at each tool call is the second.
See [Two-phase checking](architecture/architecture.md#two-phase-checking).

### Review log

The permission review log, a JSONL file recording each gate decision with its request facts and `decidedBy`.
Values bound to sensitive names are masked.

## Authority

### Authority

The right to decide whether an action may happen.
Recorded authority is the [composed policy](#composed-policy); live authority is reached only on `ask`, when recorded authority is silent; absent authority (nothing recorded, nothing reachable) means the action is denied.
See [The authority model](architecture/architecture.md#the-authority-model).

### Authorizer

The entity that holds live authority for an `ask`.
The [terminal](#terminal) authorizers are `LocalUserAuthorizer` (prompt the human here), `ParentAuthorizer` (forward to the parent), and `DenyingAuthorizer` (no authority reachable); [links](#link) are the non-terminal ones.

### Chain

The ordered sequence an `ask` passes through: the [links](#link) the operator names in `authorizerChain`, in config order, then the [terminal](#terminal).
Each link decides or defers.
There is one chain per [node](#node); a relaying node runs none and forwards instead.
See [ADR 0007](decisions/0007-model-judge-authorizer-chain-adr.md).

### Link

A named, non-terminal authorizer that another extension registers with `registerAuthorizer`.
It decides nothing until the operator names it in `authorizerChain`, and it returns a [verdict](#verdict).

### Terminal

The last authorizer in a chain, which must decide and cannot defer.

### Defer

A link's verdict meaning "not mine to decide": the `ask` passes to the next link, and in the end to the terminal.

### Envelope

The bounded-delegation checkpoint this package applies to every link verdict, so a link can never exceed the operator's policy.
A link's `allow` on the `path` or `external_directory` families becomes [`defer`](#defer), except on an `external_directory` ask carrying the nothing-on-disk [license](#license).
A `deny` rule never reaches the chain at all.

### License

A fact a gate computes that lets a link's otherwise-capped `allow` through the [envelope](#envelope).
The one license today is nothing-on-disk: every flagged path of a bash `external_directory` ask names nothing that exists.

## Sessions and nodes

### Session

One Pi conversation, from `session_start` to `session_shutdown`; `/new`, `/resume`, and `/fork` each start a new one.
Session rules live exactly this long.

### Prompt

One user submission and the agent loop it starts, from `agent_start` to `agent_end`.
`before_agent_start` fires once per prompt; this package refreshes its runtime config and runs [exposure](#exposure) there.

### Turn

One model response and the tool calls it requests, from `turn_start` to `turn_end`.
A single [prompt](#prompt) can run many turns.

### Node

One Pi session runtime: one `ExtensionContext`, one event bus, one set of gates, its own registries.
A node is not a process: one process can host several, such as a parent and its in-process subagent children.
See [ADR 0012](decisions/0012-cross-node-extension-contract.md).

### Requesting, relaying, serving, and adjudicating nodes

The roles in forwarding: the requesting node raises the `ask`; a relaying node forwards it instead of deciding; the serving node drains forwarded asks; the adjudicating node is the one whose chain and terminal decide.

### Forwarding

How a subagent that cannot decide sends its `ask` up the session tree: its `ParentAuthorizer` hands the request to the serving parent, whose chain and terminal decide.
See [docs/subagent-integration.md](subagent-integration.md).

## Packaging

### This package

`@gotgenes/pi-permission-system`, an npm package containing one Pi [extension](#extension).

### Extension

Code Pi loads into a session; it receives `ExtensionAPI` and registers event handlers, tools, and commands.
An extension is fully trusted code in Pi's process, so the boundaries this package draws are about operator attention, not about what other extensions are able to do.

### Pi package

Pi's installable unit (`pi install npm:…`, `git:…`, or a local path), bundling extensions, skills, prompt templates, and themes.

### Downstream extension

An extension that integrates with this package through its published service (`getPermissionsService(sessionId)`, with `registerAuthorizer`, `registerToolAccessExtractor`, and the query methods) or its `permissions:*` events, such as `@gotgenes/pi-permission-model-judge`.
The dependency points toward this package, never away from it.
See [docs/cross-extension-api.md](cross-extension-api.md).

## Open questions

Terms not yet settled, each with the meanings that compete for it.
An entry above uses the word as it is used today until its question is answered.

1. **Channel.**
   [ADR 0016](decisions/0016-policy-channels.md) uses it for every route by which something that changes an outcome reaches the package, the authority model uses it for the three ways live authority is reached, and the [channel](#channel) entry's own example, `debugLog`, changes no outcome.
2. **Runtime knob.**
   The word covers six settings that change an outcome (`commandEffects`, `shellTools`, `piInfrastructureReadPaths`, `authorizerChain`, `promptTimeoutMs`, `forwardingTimeoutMs`) and ten that change only presentation or logging, and none of them is [policy](#policy).
3. **Auto-approve's scope, and mode.**
   `decidedBy`'s auto-approve `scope` (`own`, `forwarded`, `agent`) names whose asks it covers, which is not a [scope](#scope); *coverage* is one candidate.
   The [auto-approve](#auto-approve) entry calls it a mode, a word other harnesses use for a whole permission posture, while here it is a [terminal](#terminal).
4. **Session rule, session approval, and grant.**
   One rule has two names, and the code adds `SessionApproval` and `ApprovalGrant` for the act that creates it.
5. **Source, bare.**
   `PermissionCheckResult.source` is a surface kind plus two [layer](#layer) values, `DecisionSource` is the [decider](#decider), `PermissionUiPromptSource` names what triggered a prompt, and the review log's `source` names the Pi event that raised a request.
   This glossary uses the word only in [policy source](#policy-source).
6. **Ruleset.**
   Whether it stays as the plain word for an ordered list of rules at any level (the code's `Ruleset`), or retires in favor of [composed policy](#composed-policy).
7. **Unrestricted.**
   Whether the planned final allow-all rule ([#1119]) is a fifth [layer](#layer) or a rewrite, decided when it is built.
8. **Access.**
   A name for the thing an [access intent](#access-intent) describes, apart from the description; declined for now as awkward.
9. **Inline shell payloads.**
   A `bash -c '…'` or `eval` payload is not enumerated into [command units](#command-unit), so the commands inside it have no unit to be checked as; [#481] floored such a wrapper to `ask` instead, and no open issue tracks enumerating it.
10. **Effective policy.**
    Undefined: the [composed policy](#composed-policy) names the whole, rewrites included.

[#481]: https://github.com/gotgenes/pi-packages/issues/481
[#1119]: https://github.com/gotgenes/pi-packages/issues/1119
