Introducing a new way to review your PRs.

Read the announcement

sheeki03 / tirith

Terminal security for developers and AI agents. Intercepts homograph URLs, pipe-to-shell, ANSI injection, obfuscated payloads, data exfiltration, and malicious AI skills/configs before they execute.

View on GitHub

19 documents · Updated Nov 23, 2026

docs / audit-observability-and-reporting

Audit, observability, and reporting

Tirith turns security decisions and related system activity into local, redacted audit data. It stores that data for review, rolls it into summaries and policy advice, correlates short-lived session events, watches persistence state, can buffer verdicts for optional server upload, and exposes local dashboards plus machine-readable outputs without making observability part of the command verdict.

Audit event model

Audit event classes

The audit stream is a JSON Lines record of what Tirith observed or changed. Verdict records describe analyzed commands. Hook telemetry records integration events and timing. Trust-change records describe changes to trusted patterns. Task-boundary records describe owned-boundary assessments. Artifact and capsule receipt records anchor saved results to the audit chain.

Each record keeps the context needed for later review: time, session, action, rule IDs, reached tier, bypass state, policy path, and caller origin when the event is a verdict. Command text and other free-form values are projected through the durable privacy boundary before they are stored or sent for upload, so reporting works from safe data rather than original secrets.

The entry_type field separates these classes. Older records without that field remain verdict records for readers and reports. This lets new telemetry share one stream without changing the meaning of existing command statistics.

References: crates/…/audit.rs• L48-105 crates/…/audit.rs• L2222-2279 crates/…/audit.rs• L2304-2455 crates/…/audit.rs• L2475-2639

Audit capture flow

Audit capture runs after the security engine has produced a verdict or after an audit-worthy operator or integration event occurs. The capture path projects sensitive data, appends one record to the local log, and for verdict records can place the exact serialized line into the upload queue.

The main capture paths and their downstream effects are:

EventRecord purposeDownstream use
VerdictExplain an Allow, Warn, or Block decisionStatistics, reports, tuning, dashboard activity, optional upload
Hook telemetryShow integration events and elapsed timeHook statistics and operational review
Task boundaryRecord an owned-boundary assessmentReview of approval and denial outcomes
Trust changeRecord trust additions and removalsAudit history and review of policy exceptions
Artifact or capsule receiptBind a saved result to the audit chainReceipt integrity checks

This diagram shows how an event moves from capture to local and remote observability surfaces.

flowchart LR
    A[Verdict or audit-worthy event] --> B[Project sensitive data]
    B --> C[Append JSONL audit record]
    C --> D[Hash chain and optional signature]
    C --> E[Durable upload queue for verdicts when configured]
    D --> F[Export, stats, reports, verify]
    E --> G[Background server upload]
    C --> H[Dashboard and policy tuning]

A normal audit write is best effort and does not change the security verdict. A path that needs a recorded transaction can require the append and fail instead of proceeding without its audit record.

References: crates/…/audit.rs• L581-955 crates/…/audit.rs• L2222-2301 crates/…/audit.rs• L2349-2455 crates/…/audit.rs• L2475-2639

Log persistence and integrity

The default audit file is data_dir()/log.jsonl. Writers serialize one record per line and coordinate concurrent access with a file lock. The log is private by default, and the write path rejects unsafe destinations such as symlinks.

The stream can form a tamper-evident chain. Each new line links to the hash of the prior line, while a sidecar head receipt records the current tail and line count so truncation can be detected. An optional Ed25519 key signs records and the head receipt. tirith audit verify checks the chain, signatures when expected, the head receipt, and an optional out-of-band expected head.

The verifier tolerates a leading legacy prefix and a head receipt that is one entry behind because of a crash window. It does not treat a missing head receipt on an existing chained or signed log as harmless unless the operator supplies an external expected head.

References: crates/…/audit.rs• L114-117 crates/…/audit.rs• L236-380 crates/…/audit.rs• L811-839 crates/…/audit.rs• L1130-1212 crates/…/audit.rs• L203-333

Local audit result persistence

Not every observability result belongs in the command audit stream. The visual audit stores the operator's terminal-specific answers in config_dir()/visual-audit-result.json. It records which confusable glyph pairs were distinguishable, indistinguishable, or skipped, plus the terminal name and time.

This result is deliberately local. It describes one rendering stack and does not claim that another machine, font, or terminal is safe. A non-interactive run records skipped answers by design, while an accidental non-TTY invocation reports a result without persisting it.

For the wider safety flow that uses this local check, see Interactive safety workflows.

References: crates/…/visual_audit.rs• L191-237 crates/…/visual_audit.rs• L256-321 crates/…/visual_audit.rs• L362-402

Audit aggregation and tuning

Record reading and filters

The aggregation layer reads the JSONL stream line by line and converts valid lines into tolerant AuditRecord values. Blank lines are ignored. Malformed JSON lines are skipped and counted so a damaged record is visible to callers instead of silently changing the data set. A read error is terminal rather than a malformed record.

Readers can use the full log or a bounded newest tail. The bounded form inspects only a recent suffix, with limits on bytes, physical lines, and individual line size. It reports when older bytes or records were omitted. Filters select a time range, session, action, rule ID, or entry type. A missing entry type means verdict, which preserves the meaning of older logs.

References: crates/…/audit_aggregator.rs• L13-89 crates/…/audit_aggregator.rs• L121-234 crates/…/audit_aggregator.rs• L268-327

Summary statistics

Verdict statistics turn filtered records into a compact view of command activity. They count commands, findings, actions, sessions, the block rate, the time range, and the most frequent rules. They also keep raw pre-paranoia finding counts when the record contains them, which lets a reviewer compare detected activity with the final effective result.

Hook telemetry has a separate summary because it measures integration events rather than commands. It counts events by integration and lists the most common event names. Trust changes and task-boundary records are available as records but are not treated as verdict or hook statistics.

References: crates/…/audit_aggregator.rs• L91-113 crates/…/audit_aggregator.rs• L329-453

Policy tuning suggestions

tirith policy tune --from-audit uses the local verdict history to suggest conservative policy changes. It never edits the policy. The suggestions are deterministic counts that an engineer can trace back to the audit records.

The tuner waits for at least 20 verdict records. It can identify a rule that fired at least five times and was always allowed or bypassed without ever being blocked. It can also report a short list of known rules that never fired. These are review prompts, not proof that a rule is wrong or safe to disable.

References: crates/…/audit_tune.rs• L1-26 crates/…/audit_tune.rs• L63-91 crates/…/audit_tune.rs• L130-245 crates/…/policy.rs• L603-704

Cross-event correlation buffer

The cross-event correlation buffer keeps a bounded, per-session history of typed events. It looks for short sequences whose combined shape is more concerning than either event alone, while keeping provisional, unresolved, and confirmed execution evidence distinct.

The correlation rules cover these high-level patterns:

  • A secret-bearing file write followed by network activity within 30 seconds.
  • A dependency manifest change followed by network activity within 60 seconds.
  • File deletion followed by a forced Git push within 60 seconds.
  • At least three non-build file paths deleted within 20 seconds.

The buffer uses stable session order when available and produces a privacy-safe signature for each match. Consumers can use that signature to avoid repeating the same warning while the source events remain in the live window. The buffer itself performs no I/O; its caller owns event persistence and supplies the current time.

The mass-deletion check counts affected non-build paths rather than only delete events. This lets one multi-path delete and several single-path deletes represent the same destructive pattern without counting build-artifact cleanup as a user-file deletion burst.

References: crates/…/event_buffer.rs• L1-14 crates/…/event_buffer.rs• L24-88 crates/…/event_buffer.rs• L563-584 crates/…/event_buffer.rs• L710-868 crates/…/event_buffer.rs• L1055-1226

Persistence state monitoring

Persistence monitoring compares known ways for user or project startup behavior to change against a saved baseline. It turns changes in shell startup files, SSH settings, scheduled jobs, user services, launch agents, and directory environment files into security findings rather than treating each scan as a command verdict.

Persistence snapshots

The inventory covers the user's home directory and the current working directory's ancestor chain. A persistence snapshot records the presence, size, whole-file fingerprint, and per-line fingerprints of each surface. It stores no cleartext, so the baseline can support later change detection without becoming a copy of sensitive configuration.

The default snapshot is state_dir()/persistence_snapshot.json. Saving it is atomic and owner-only. A missing snapshot means that there is no baseline yet; a later diff can then identify newly present surfaces.

References: crates/…/persistence.rs• L1-22 crates/…/persistence.rs• L74-161 crates/…/persistence.rs• L207-298 crates/…/persistence.rs• L800-829

Persistence change findings

The diff compares the live inventory with the snapshot and reports changed surfaces. It returns added lines only, and it redacts credentials and private-key material before those lines leave the current scan. The finding severity depends on the surface: new authorized keys and launch units are high, while shell startup changes, cron changes, SSH includes, and new .envrc files are medium.

An SSH configuration change produces a finding only when it adds an Include directive. Inventory-only surfaces provide context but do not create one of the six state-change rules. Unsafe or unreadable existing surfaces remain visible as present changes instead of being mistaken for clean removal.

References: crates/…/persistence.rs• L187-205 crates/…/persistence.rs• L566-657 crates/…/persistence.rs• L660-748

Event buffering and upload

Durable upload queue

When both TIRITH_SERVER_URL and TIRITH_API_KEY are set, a successfully written verdict line is copied to a local JSONL spool before background upload begins. The default spool is $XDG_STATE_HOME/tirith/audit-queue.jsonl, with a home-state fallback. The queue is separate from the audit log so a server outage does not block the command path.

The queue has bounded retention. By default it keeps up to 1,000 events and 5 MiB, subject to an absolute 64 MiB ceiling. When the limits are reached, it drops the oldest events. Retention is applied at append time, including during a long outage, so the queue cannot grow without limit.

References: crates/…/audit_upload.rs• L5-18 crates/…/audit_upload.rs• L42-64 crates/…/audit_upload.rs• L106-143 crates/…/audit_upload.rs• L347-375

Background upload lifecycle

A drainer snapshots the bounded queue under a lock, sends events one at a time to /api/audit/ingest, and removes only the confirmed sent prefix. Exponential backoff handles temporary failures. Authentication failures stop the pass because retrying the same credentials cannot help.

The network work runs in one coalesced background worker. New events signal a rescan rather than starting another worker. If the queue changes while a send is in progress, the rewrite preserves concurrent appends and favors at-least-once delivery over silent deletion.

The server URL is checked before upload to prevent a configured destination from becoming a path into a private or internal host. Upload failure is diagnostic background state; it does not rewrite the local audit record or alter the original command result.

References: crates/…/audit_upload.rs• L180-263 crates/…/audit_upload.rs• L273-345 crates/…/audit.rs• L2282-2301

Dashboards and reporting

Local security dashboard

The dashboard is a point-in-time local snapshot. By default it summarizes the last seven days of verdict activity and combines that view with the effective policy, threat database status, trust and canary counts, and shell-hook state.

The snapshot degrades each source to an explicit unavailable or empty state. A broken policy is not shown as benign defaults. The audit summary includes skipped-line counts and best-effort top hosts derived from already redacted command previews.

tirith dashboard export writes a self-contained HTML file with no external resources or network calls. tirith dashboard serve renders fresh snapshots over IPv4 loopback with a short-lived in-memory token. The served and exported views escape user-controlled values before they cross into HTML.

References: crates/…/dashboard.rs• L24-80 crates/…/dashboard.rs• L174-243 crates/…/dashboard.rs• L522-611 crates/…/template.html• L35-69 crates/…/dashboard.rs• L221-267 crates/…/dashboard.rs• L360-449

Compliance reports

tirith audit report creates a report from verdict records after an optional start-time filter. Markdown and HTML provide human review views with an executive summary, action breakdown, top rules, and a bounded list of blocked command previews. The report uses the audit log's redacted command field.

The report command supports verdict records only. This keeps compliance measures tied to command decisions rather than mixing hook, task-boundary, trust, or receipt events into command counts. Use audit export when the full event stream is needed.

References: crates/…/audit_aggregator.rs• L659-730 crates/…/audit_aggregator.rs• L733-862 crates/…/audit.rs• L336-418

Machine-readable reporting outputs

The CLI keeps JSON outputs stable enough for scripts and other tools to consume. Human text is useful for operators, while JSON carries structured records, summaries, status fields, and schema versions where a command defines them. Verdict records can also carry a structured caller origin, which gives reports and exports context about the source of a decision.

InterfaceMachine-readable result
audit export --format jsonFiltered audit records as a JSON array
audit export --format csvVerdict records as RFC 4180 CSV, including caller origin when present
audit stats --format jsonVerdict or hook telemetry summary
audit report --format jsonReport envelope with stats and filtered records
audit verify --format jsonChain status, counts, signing state, and problems
dashboard export --jsonWritten path, byte count, and dashboard snapshot
dashboard serve --jsonLoopback URL, port, host, and token lifetime
logs scan/summarize/redact --jsonFindings or bounded redacted content with counts
visual-audit --jsonTerminal-local pair results and totals

CSV export neutralizes spreadsheet formula prefixes in caller-influenced cells. JSON and HTML reporting escape or structure untrusted values so a report consumer does not turn audit content into executable markup or spreadsheet formulas.

For field-level contracts and output examples, see Audit data and reporting outputs.

References: crates/…/audit.rs• L3-75 crates/…/audit.rs• L78-201 crates/…/audit.rs• L282-333 crates/…/audit_aggregator.rs• L13-71 crates/…/audit_aggregator.rs• L456-547 crates/…/audit_aggregator.rs• L566-635 crates/…/dashboard.rs• L553-611 crates/…/dashboard.rs• L212-267

Log review

Log scanning

tirith logs scan reviews an external log file as untrusted content. It runs file-oriented security checks and adds credential and prompt-injection checks that are useful for agent output and build logs. A finding produces a non-zero result, while --json returns the action and finding list for automation.

Prompt-injection detection is a seed-based heuristic. A clean result does not make agent output trusted. The scan reads at most 64 MiB so a hostile or accidental large file cannot make the review unbounded.

References: crates/…/logs.rs• L1-18 crates/…/logs.rs• L48-106 crates/…/logs.rs• L138-164

Log summarization and redaction

tirith logs summarize produces a smaller view of a log by collapsing repeated lines and keeping the head and tail within the requested line limit. With --safe-for-agent, it also removes secrets, internal hostnames, customer IDs, terminal escape data, and zero-width characters.

tirith logs redact applies audience-aware data loss prevention to log content. Its output can target an LLM, a public paste, Slack, a GitHub issue, or a generic audience. Both protected paths process bounded records and carry private-key block state across line and chunk boundaries. Oversized or incomplete secret-bearing input becomes a fail-closed marker rather than being passed through.

References: crates/…/logs.rs• L621-799 crates/…/logs.rs• L802-841 crates/…/logs.rs• L978-1092

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep the entry_type meanings aligned between AuditEntry, tolerant AuditRecord parsing, CLI filters, statistics, and report scope.
  • Preserve the redaction-before-storage rule when adding fields to verdict capture, typed events, persistence findings, or upload; a new caller-controlled field can become a local or remote data leak.
  • Treat changes to audit line fields, canonical hashing, signatures, or the .head receipt as a wire-contract change for audit verify and older logs.
  • Keep queue retention, snapshot rewrite, and rescan behavior aligned so concurrent appends are not lost during upload.
  • Keep correlation windows, event provenance, stable sequence-based signatures, and session persistence aligned so the same live event does not produce repeated or misleading warnings.
  • Keep persistence snapshot keys, presence state, per-line hashes, and change-to-rule mappings aligned; changing one can turn a new or unsafe surface into a silent no-change result.
  • Update dashboard snapshot consumers when its schema or unavailable states change; HTML, --json, and served output share the same snapshot.
  • Keep machine-readable output restrictions aligned with the data model, especially CSV's verdict-only contract, caller-origin fields, and the report command's verdict-only scope.

Important failure modes

TriggerConsequenceGuard
Audit destination is disabled or absentOrdinary events are not recorded; required audit paths return an errorTIRITH_LOG=0 and no-path are explicit states; required writes reject them
Log line is malformed or a log read failsA malformed line is omitted from aggregation and its count is reported; a read failure stops that readReaders count skipped lines and treat I/O errors as terminal
A diagnostic tail reaches its byte, line, or record boundOlder history is omitted from that read and statistics cover only the inspected suffixTail reads report truncation and warn that coverage is partial
Audit log or head receipt is edited, reordered, or truncatedVerification fails or reports that integrity cannot be provedHash links, head count/hash, optional signatures, and expected-head checks
Server is unavailable or credentials are rejectedEvents remain local until retention removes old queue entries; upload stops on auth failureDurable spool, bounded retention, retry backoff, and prefix-safe rewrite
Dashboard source is missing, unsafe, oversized, or brokenThat section is unavailable rather than showing false safe defaultsCapped regular-file reads, per-source degradation, and explicit policy parse-error state
Session history ages out or has unresolved execution evidenceA sequence may not correlate, or the warning uses a conservative description instead of claiming executionBounded time windows, provenance labels, and live-signature tracking
Persistence surface changes after an absent or unsafe baselineA new startup path can be missed if presence is treated as content alone; unsafe content must not be disclosedPresence-aware fingerprints, no-follow capped reads, and hash-only snapshots
Log contains prompt injection or secretsA reviewer or agent may trust hostile content if it is passed throughScan heuristics, audience-aware redaction, bounded secret-block handling, and the untrusted-content warning

Key files

FileWhy to read it
crates/…/audit.rsDefines audit records, capture paths, local persistence, redaction boundary, receipt anchors, and chain verification
crates/…/audit_aggregator.rsDefines streaming and bounded-tail parsing, filters, statistics, CSV/JSON export, and compliance report generation
crates/…/audit_tune.rsDefines deterministic, suggest-only policy tuning from verdict history
crates/…/event_buffer.rsDefines typed session events, privacy-safe execution provenance, cross-event correlations, and match signatures
crates/…/persistence.rsDefines persistence-surface inventory, hash-only baselines, change findings, and snapshot storage
crates/…/audit_upload.rsDefines durable event buffering, retention, background upload, and concurrent queue handling
crates/…/dashboard.rsDefines the read-only dashboard snapshot and HTML rendering boundary
crates/…/template.htmlShows the dashboard's user-facing sections and local-only report shape
crates/…/audit.rsMaps audit export, stats, report, and verify behavior to CLI output and exit codes
crates/…/dashboard.rsDefines dashboard file export and loopback serving behavior
crates/…/logs.rsDefines external log scan, summary, and audience-aware redaction outputs
crates/…/visual_audit.rsDefines persistence and machine output for terminal-local visual checks