Ledger
agent_gate.ledger
¶
The gate's append-only ledger, one JSON Lines file per session.
The ledger is the gate's own record of every action it judged. It gives the model gate the recent trajectory and lets the history rules spot a retry of a blocked action. Claude Code's transcript is not used: it is written asynchronously and can lag the call being judged.
The ledger keeps the first 2,000 characters of each call's input with
secrets redacted (:func:redact), and a session's file is deleted
:data:KEEP_DAYS days after its last entry.
Ledger(session_id, root=None)
¶
The ledger for one session.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
the Claude Code session id. |
required |
root
|
Path | None
|
the state directory; defaults to :func: |
None
|
Source code in src/agent_gate/ledger.py
90 91 92 | |
append(action, verdict, digest)
¶
Record one judged action.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
action
|
Action
|
the action. |
required |
verdict
|
Verdict
|
the gate's verdict on it. |
required |
digest
|
str
|
the digest of the mandate it was judged under. |
required |
Source code in src/agent_gate/ledger.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | |
entries()
¶
Every entry so far, oldest first.
Source code in src/agent_gate/ledger.py
101 102 103 104 105 106 | |
prune()
¶
Delete session ledgers whose last entry is older than :data:KEEP_DAYS.
Source code in src/agent_gate/ledger.py
94 95 96 97 98 99 | |
gate_home()
¶
The gate's state directory: $AGENT_GATE_HOME or ~/.agent_gate.
Source code in src/agent_gate/ledger.py
78 79 80 | |
redact(text)
¶
Replace the secrets the gate can recognize in text with [redacted].
Recognized: private key blocks, tokens with a known prefix (Anthropic,
OpenAI, GitHub, Slack, AWS), Authorization headers, bearer tokens,
and values given to fields or flags named like a key, token, secret or
password. A secret of no recognizable shape is not found.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
the text to clean. |
required |
Returns:
| Type | Description |
|---|---|
str
|
the text with each recognized secret replaced. |
Source code in src/agent_gate/ledger.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 | |