Metadata-Version: 2.4
Name: awgov
Version: 0.1.8
Summary: The platform's Policy Decision Point for agent tool calls -- allow, deny plus the lane to use instead, or needs-owner.
License: Apache-2.0
Project-URL: Homepage, https://github.com/Aitherium/awgov
Project-URL: Documentation, https://github.com/Aitherium/awgov#readme
Project-URL: Repository, https://github.com/Aitherium/awgov.git
Project-URL: Issues, https://github.com/Aitherium/awgov/issues
Requires-Python: >=3.10
Description-Content-Type: text/markdown
Requires-Dist: awbac
Requires-Dist: PyYAML>=6
Provides-Extra: dev
Requires-Dist: pytest>=7.0; extra == "dev"
Requires-Dist: awdecide; extra == "dev"

# awgov

The platform's Policy Decision Point for tool calls. One YAML sanction file
(`agent_policy.yaml`, the sanction file in the platform's config) decides; the answer is one of:

- **allow** — a grant covers every descriptor the call resolves to;
- **deny** — a destructive floor fired (G1..G16) or no grant covers a descriptor;
  the verdict carries the **lane** that should have been used instead;
- **needs_owner** — a B2/B3 call; a decision card is raised, never a raw prompt.
  The card SHOWS the whole call in its facts (the command, or every input field
  but the agent's own description and timeout) and carries `call sha256:<digest>`
  of it (principal, session, tool, input, cwd). When the owner approves it **with
  a signed answer** (a passkey/TOTP sign-in, verified by
  `awstorage.attest.verify_receipt`), the agent's re-run of that same call is
  admitted **once** (`verdict.rule_id == "owner-approved"`). Refused: an unsigned
  answer, a different call, a second run, a call with two steps of the kind or
  carrying a secret-looking value (the card says approving runs nothing), and any
  step the call's grants do not cover. A deny cools the call and its family down
  for `AWGOV_ASK_TTL_S` (900 s); a session holds at most three open asks.
  `AWGOV_ADMIT=0` turns admission off. The card names the session whose call it is,
  so the owner's answer is written into that session's steering mailbox: the agent
  that has to re-run the call hears the answer without polling the card.
- **a standing permit** lifts G12 (spend) without a card per call. The owner signs
  one permit card (`awgov permit request`) whose facts ARE the grant: one op on one
  loopback/fleet host, a per-call `max_price_per_hour` ceiling, a number of uses and
  an expiry of at most 24 h. A spend call it covers is allowed as
  `rule_id == "owner-permit"`, and each use is counted. The call must be one literal
  POST to `http://<host>/api/op/<op>`, with nothing that can reroute it, and a JSON
  body inside the ceiling. Anything else still asks per call. A permit never lifts a
  send, a secret write or a publish.

Claude Code reaches it through a `PreToolUse` hook. P1 is **shadow**: awgov
computes and audits every call and never blocks (`hook_response` returns `{}`).
Enforce is a mode switch on the hook, not a code change.

## API

```python
from awgov import evaluate, hook_response, load_policy
from awgov.audit import record

verdict = evaluate(payload, principal="agent:atlas")   # "owner-tty" by default
verdict.decision      # "allow" | "deny" | "needs_owner"
verdict.rule_id       # "G1" | "grant" | "default" | "error"
verdict.lane          # the platform lane to use instead, or ""
verdict.b_code        # "" | "B2" | "B3"
verdict.descriptors   # ("fleet:read:podman.logs", ...)

hook_response(verdict, "shadow")    # {} -- no decision
hook_response(verdict, "enforce")   # {"hookSpecificOutput": {...}}
record(verdict, payload, principal, "shadow")   # append-only, never raises
```

`load_policy(path=None)` reads `AWGOV_POLICY`, else the repo's
the sanction file `agent_policy.yaml`, else a built-in **deny floor** (reads only),
and caches by mtime.

## Parsing, not pattern matching

A command is split into steps on unquoted separators, `$(...)` substitutions are
parsed as their own commands, and every step is resolved through `env`, `sudo`,
`wsl -d X -u root --`, `nsenter`, `bash -c`, `pwsh -Command` and `cmd /c` before
it is classified on the resolved argv. `rg -n "rm -rf .git" .claude/hooks` is a
read; the text it searches for is data, never a verb.

## CLI

```bash
awgov check --tool Bash --command "git status"
awgov check --tool Edit --path C:/x/y.py --principal agent:lyra
echo '<PreToolUse json>' | awgov hook          # AWGOV_MODE=shadow|enforce
awgov replay --days 5                          # read-only audit of transcripts
awgov permit request --op burst_up --host 127.0.0.1:8200 --max-price 1.6 --uses 3 \
    --session <session id>                     # the session the signed answer reaches
awgov permit status                            # permits, their terms and uses
awgov --self-test                              # incident + sanctioned fixture
```

`replay` exits 1 if any READ-class command was denied (the false positive the
parser exists to prevent) and 2 if it could not read the transcripts.

## Wiring into hookd

The durable host service (`awdk/adk/harnesses/hookd.py`) gets a `POST /pdp` route
that forwards the PreToolUse body here, sets `AITHER_PDP_PRINCIPAL` from the
daemon's session record (`owner-tty` for the owner, `agent:<name>` or
`tainted:<name>` for workers) and returns the `hook_response` JSON verbatim. The
hook must be HTTP and must never exit non-zero in shadow.

## Tests

```bash
python -m pytest tests -q          # from this package's directory
python -m pytest ../../dev/tests/test_awgov_policy.py -q --noconftest
```

Every incident command must deny for `owner-tty`; every sanctioned ops command
must allow for both `owner-tty` and `agent:atlas`. Tests point `AWGOV_HOME` at a
temp dir — nothing under `~/.aither` is written by a test run.
