Audit reference
agent_tessera.audit
Append-only hash-chained audit log.
VerifyResult
dataclass
VerifyResult(
ok: bool,
events: int,
error_line: int | None = None,
error: str | None = None,
)
Outcome of checking an audit log's hash chain.
Attributes:
| Name | Type | Description |
|---|---|---|
ok |
bool
|
Whether every event is intact and in order. |
events |
int
|
How many events were accepted before the first problem. |
error_line |
int | None
|
1-based line of the first problem, when there is one. |
error |
str | None
|
Why verification failed, when it failed. |
AuditLog
AuditLog(path: str | Path)
Append JSON events to a file and chain each one to the previous hash.
The log creates missing parent directories. Reopening a file continues the sequence number and the hash chain.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
File to append events to. Created if it does not exist. |
required |
Example
from agent_tessera.audit import AuditLog, verify_audit_log
log = AuditLog("audit.jsonl")
log.write("lifecycle", {"event": "start"})
log.close()
assert verify_audit_log("audit.jsonl").ok
Open an audit log, creating parent directories when needed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
File to append events to. |
required |
path
property
path: Path
Return the log file path.
Returns:
| Type | Description |
|---|---|
Path
|
The path passed to the constructor, as a |
write
write(
event_type: str, fields: Mapping[str, object]
) -> dict[str, object]
Append one event and return the stored record.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event_type
|
str
|
Event type, such as |
required |
fields
|
Mapping[str, object]
|
Extra fields. Must not use reserved record keys. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, object]
|
The record that was written, including its hash. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
close
close() -> None
Close the log file.
verify_audit_log
verify_audit_log(path: str | Path) -> VerifyResult
Recompute every hash and check that the sequence is intact.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Audit log to read. |
required |
Returns:
| Type | Description |
|---|---|
VerifyResult
|
A result that names the first bad line, or confirms the chain. |
Example
from agent_tessera.audit import verify_audit_log
result = verify_audit_log("missing.jsonl")
assert result.ok is False
assert result.error == "file not found"