protect-context
v3.3.1Agent guardrails: contract, evidence ledger, loop brake, diff-scope warnings, durable journal.
These tools were reported by the server itself during our smoke test (tools/list), not copied from the README.
guard_status
Session dashboard: diff, loops, evidence, contract size, and the last verify. Use it at the start of a turn, after a compaction, or before claiming the work is done, when you need the current guardrail state in one block. It takes no parameters. It returns text beginning with `PC status`: the session name (`PC_SESSION_ID`, or `default`), git head, diff stats and verdict, up to three loop streaks, the evidence count and last run, the merged constraint count, discovered conventions files, and a final Nudge line. Side effects: if `.agent-guard/` is missing it is created, `config.json` is seeded…
guard_verify
Run a shell command and record the outcome as evidence. Use it before claiming a check passed, and cite the returned evidence id. Do not use it to retry a command that `guard_loop_check` already says will be blocked. `command` is a required string and runs verbatim (`shell=True`) with the caller's privileges; stdin is closed. `timeout_s` is an int, default 180, clamped to 1–900. It returns a text report: on a real run, `PC verify ev-NNNN · exit N · ok|FAIL|UNTRUSTED · <ms>ms`, plus cwd, the command, a digest or failure tail, and a Nudge. Exit 0 from a pipeline (no pipefail) or a failure…
| Parameter | Type | Description |
|---|---|---|
command * | string | Shell command to run and record, as one string (pipes and quotes included). Required. Executed with the caller's privileges via the shell; this is not a sandbox. A blank string returns an error line a… |
timeout_s | integer | Seconds before the child is killed. Integer. Default 180. Clamped to 1–900; a timeout is recorded as exit 124, not raised. |
guard_evidence
Read recorded verification runs. Use it to recover a past evidence id, its exit code, and the stored digest instead of re-running the command. `limit` is an int, default 5, clamped to 0–20, and applies only when `evidence_id` is omitted. `evidence_id` is an optional string, default None. With an id, it returns the full single-run report (the same shape as `guard_verify`, including why/fix for FAIL and UNTRUSTED). Without an id, it returns `PC evidence · last N of TOTAL`, one line per run, the last digest line of any non-ok row, and a Nudge. Side effects: none. It does not create `.agent-gu…
| Parameter | Type | Description |
|---|---|---|
evidence_id | One evidence id to render in full, such as ev-0007. String or omitted. Default None, which lists recent runs. ev-7 and ev-0007 are the same id. An unknown id returns an error line. | |
limit | integer | How many newest verification runs to list when evidence_id is omitted. Integer. Default 5. Clamped to 0–20; 0 returns the header and nudge only. |
guard_contract
List, add, or remove a project contract constraint. Use `list` before acting on rules you might have forgotten, `add` when the owner states a durable constraint this session should keep, and `remove` only for a constraint this agent added. `action` is a required string: `list`, `add`, or `remove`. `text` is an optional string, required for `add`. `id` is an optional string, required for `remove`. `list` returns the merged contract (project plus personal layer) and a Nudge. `add` returns the new id and the rendered contract, or a duplicate notice. `remove` returns the rendered contract, or a r…
| Parameter | Type | Description |
|---|---|---|
action * | string | What to do with the project contract. Required string: "list", "add", or "remove". Any other value returns an error line. |
id | Constraint id for action "remove", such as 13-write-tests-first. String. Required for remove; ignored otherwise. Seed ids (source "seed") are refused. | |
text | Constraint text for action "add". String. Required for add; ignored for list and remove. A blank or missing value is an error. The new row is stored with source "agent". |
guard_note
Append one agent-authored journal entry. Use it when a decision, correction, risk, or note should survive the session and the next compaction. Do not use it for a claim that a command passed; that belongs in `guard_verify`. `type` is a required string: `decision`, `correction`, `risk`, or `note`. `text` is a required string. `tags` is an optional list of strings, default None. The tag `agent` is always stored, so the entry stays unverified: it does not enter the trusted decisions or corrections the brief treats as owner input. Tag `lesson` to make a precedent the brief can re-inject. It retur…
| Parameter | Type | Description |
|---|---|---|
text * | string | The entry body. Required string. Blank or whitespace-only text is rejected. Stored as one line, capped at 500 characters. |
type * | string | Journal type. Required string: decision, correction, risk, or note. Any other value returns an error line and writes nothing. |
tags | Optional tags. List of strings, default None (no caller tags). Cleaned, de-duplicated, and capped at 8 tags of 40 characters. The tag "agent" is always appended and cannot be crowded out. Add "lesson"… |
guard_journal
Read recent journal entries back after a compaction or a capped brief. Use it when the brief hid older decisions, corrections, risks, or the agent's own notes and you need the stored line, not a search. For a keyword, tag, or evidence-id search, use `guard_recall` instead. `limit` is an int, default 5, clamped to 0–20. `type` is an optional string, default None; when set it must be `decision`, `correction`, `risk`, or `note`. It returns `PC journal · last N of TOTAL` (or `PC journal <type>` when filtered), one line per entry (`timestamp · type · text [tags]`), and a Nudge. Side effects:…
| Parameter | Type | Description |
|---|---|---|
limit | integer | How many newest journal entries to return. Integer. Default 5. Clamped to 0–20; 0 returns the header and nudge only. |
type | Optional type filter. String or omitted. One of decision, correction, risk, note. Default None, which returns every type. Any other string returns an error line. |
guard_intent
Owner wants, needs, preferences, and corrections from the journal. Use it to answer "what does the owner want" without guessing keywords: every row whose text expresses an owner want, need, or preference, or an explicit "you are wrong" correction, plus rows already carrying the tags `owner-want`, `owner-need`, `owner-preference`, or `owner-correction`. Rows written before those tags existed are classified from their text, so nothing is lost. Each line is `<kind> · <ts> · <text> [<provenance>]`, where provenance `owner` is a trusted row and `agent` is model-recorded and still unverified. `li…
| Parameter | Type | Description |
|---|---|---|
limit | integer | How many owner statements to return. Integer. Default 5. Clamped to 0–20; 0 returns the header, counts and nudge only. |
guard_recall
Search the retained journal and evidence window. No embeddings and no network. Use it when you remember a word, tag, evidence id, or command but not which entry it was, including after the brief's caps hid it. Filters combine with AND. `query` is a string, default empty. `type` is an optional string (`decision`, `correction`, `risk`, `note`, or `evidence`), default None. `tags` is an optional list of strings, default None. `limit` is an int, default 5, clamped to 0–20. `evidence_id` and `cmd` are optional strings, default None. With a query, past bash commands from the retained events windo…
| Parameter | Type | Description |
|---|---|---|
cmd | Command fingerprint, or a substring of one, matched against verify runs only. String or omitted. Default None. Fingerprint matching is case-sensitive. | |
evidence_id | Exact evidence id to require, such as ev-0007. String or omitted. Default None. ev-7 and ev-0007 match the same id. A value that is not an evidence id returns an error line. | |
limit | integer | Maximum hits to return. Integer. Default 5. Clamped to 0–20. A non-integer returns an error line. |
query | string | Keywords to find, as one string. Default empty, which does not keyword-filter. Case-insensitive; every keyword must match journal text, a verify command, or a digest. A keyword that is itself ev-NNNN… |
tags | Tags that must all be present (AND). List of strings, or omitted. Default None. Matching is exact and case-insensitive. Evidence rows have no tags, so any tag filter excludes them. | |
type | Optional row type. String or omitted. One of decision, correction, risk, note, evidence. Default None (every type). Any other string returns an error line. |
guard_loop_check
Report failing-command streaks for this session and whether the next rerun blocks. Use it before repeating a command that just failed. The same normalized command, including a trailing `;` or a trailing `|| true` mask, shares one streak. It takes no parameters. It returns `PC loops`, up to five `command × count` lines, and a Nudge. When a streak is at `loop_block_after` (default 3), the text says the next identical run will be blocked. Streaks come from bash tool results and from `guard_verify` rows for `PC_SESSION_ID` (or `default`). An unproven exit 0 does not reset a streak. Side effects:…
guard_diff_audit
Audit the working tree's size against the configured line and file thresholds. Use it before a large edit, or when status shows a warn or hard diff, to see added/deleted lines, file count, and the verdict. `baseline` is an optional git ref string, default None (HEAD). Thresholds come from config: warn at 400 lines or 10 files, hard at 800 lines, unless the project or personal config overrides them. It returns the rendered diff audit, including a bounded-scan note when untracked reads hit their caps, and a Nudge. Outside a git repo the text says the diff is unavailable. Side effects: creates `…
| Parameter | Type | Description |
|---|---|---|
baseline | Git ref to diff the working tree against. String or omitted. Default None, which means HEAD (an unborn repository is compared as an unborn HEAD). Example: a commit sha. A ref git cannot resolve is rep… |
guard_preflight
Check configured tool presence and versions, and whether this directory is a git worktree. Use it when a tool fails in a surprising way, before blaming the code. It takes no parameters. The tool list is `preflight_tools` from config (default git, python3, pip, node, npm, rg, pytest). At most 20 entries are probed; extras are counted as omitted. Each present tool is run as `<tool> --version` with a 2 second cap, a 15 second overall deadline, and at most 4 KiB of output. It returns `PC preflight`, git yes/no, present and missing tools, any incomplete version probes, and a Nudge. Side effects: c…
guard_budget
Report this session's recorded tool-output size. Use it when the context watermark is climbing or a turn is getting large, to see which tools produced the bytes. It takes no parameters. It reads `events.jsonl` for the current session (`PC_SESSION_ID`, or `default`) and returns `PC budget`, the character total, an estimate of tokens (integer division of characters by 4), the tool-result count, the top 5 tools by characters, and a Nudge. Side effects: none. It does not create `.agent-guard/` and does not write events. A missing ledger is an empty budget.
guard_orientation
Bounded repository digest: tree, languages, and conventions files. Use it before the first edit in an unfamiliar checkout, so the next read starts from CLAUDE.md, AGENTS.md, CONVENTIONS.md, README.md, or README when those files exist. It takes no parameters. The scan starts at the git worktree root when one is found, otherwise the working directory. The tree is capped (12 entries, 8 children, depth 3, 4000 files). It returns `PC orientation`, the capped tree, up to six language counts by extension, the conventions files found, and a Nudge. Side effects: none. It only reads the filesystem. It…