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 / interactive-safety-workflows

Interactive safety workflows

Interactive safety workflows let an engineer inspect a command or repository, understand a finding, decide whether to proceed, and keep a record of the result. The CLI separates checks from execution and gives human users short feedback while giving hooks, CI jobs, and other tools stable machine-readable signals. See the parent page CLI and user workflows for the full command map, Installation and self-management for setup and shell integration, and Audit data and reporting outputs for the record formats.

Safety decision flow

The workflow starts with an input and ends with a decision signal. A check can allow a caller to continue, warn that a human or policy must review the result, block the action, or place a non-critical block in the pending-review flow.

flowchart LR
    A[Command or repository input] --> B[Analyze]
    B --> C{Decision}
    C -->|Allow| D[Caller may continue]
    C -->|Warn| E[Show findings and request review]
    C -->|Block| F[Stop the action]
    C -->|Defer non-critical block| G[Record pending decision]
    E --> H{Acknowledged?}
    H -->|Yes| D
    H -->|No| F
    B --> I[Audit and feedback]

Decision signals

The common command verdict uses action names and exit codes that let a shell hook or automation act without parsing human text. A zero result means the command passed the current gate. A non-zero result is not always a hard stop, so callers must use the action or the documented command contract.

SignalMeaningTypical exit code
allowNo finding requires a stop or review0
warnFindings are advisory unless a stricter acknowledgement policy applies2
blockThe action must not proceed1
warn_ackA warning needs explicit acknowledgement in a hook workflow3
Deferred blockA non-critical block is recorded for later review4

The exact result also depends on the surface. For example, a scan has its own threshold and CI rules, while status reports protection health rather than a command verdict. Machine callers should use JSON or SARIF where the command provides it. Human output stays on the terminal and is sanitized before it displays untrusted command, path, or log text. References: crates/…/verdict.rs• L1035-1064, crates/…/check.rs• L738-830, crates/…/mod.rs• L63-120

Command checks and runs

Command workflows cover both preflight analysis and controlled execution. They use the same safety decision model, but only an explicit run workflow can start a child process.

Command checks

tirith check -- <command> analyzes a command for the selected shell without running it. It accepts a complete command string for all shells; POSIX input may also be supplied as several arguments because the CLI preserves their word boundaries. When no command argument is present, a non-terminal standard input stream can provide the command instead. The stream has a size limit, and an unreadable or oversized stream fails closed rather than becoming a clean result.

The check may use the local engine or a daemon when suitable. It records the effective decision for audit and can show findings, remediation, or a verified safe-command suggestion. --defer is an opt-in path for a non-critical block when no terminal is available. It changes the result only after the pending record is saved successfully; a failed save remains a hard block.

For shell execution, the check can prepare a one-use receipt that carries the reviewed decision to the hook. Approval and warning acknowledgement are completed before that receipt is armed. A hook that cannot safely own the required interaction blocks instead of passing an unresolved decision to the shell.

sequenceDiagram
    participant Caller
    participant Tirith
    participant Audit
    Caller->>Tirith: check command
    Tirith->>Tirith: analyze with shell context and policy
    Tirith->>Audit: record verdict
    alt allow
        Tirith-->>Caller: exit 0
    else warning
        Tirith-->>Caller: findings and exit 2
    else block
        Tirith-->>Caller: findings and exit 1
    else opted-in deferred block
        Tirith->>Tirith: save redacted pending decision
        Tirith-->>Caller: exit 4
    end
    opt shell execution handoff
        Tirith->>Tirith: resolve approval and acknowledgement
        Tirith-->>Caller: one-use armed execution receipt
    end

A check is a preflight boundary. A zero exit permits the caller to run the command later, but the check process does not claim that it observed the later execution. References: crates/…/main.rs• L243-343, crates/…/check.rs• L148-188, crates/…/check.rs• L391-481, crates/…/check.rs• L1124-1217

Manifest-backed command workflows

tirith commands gives a repository a named catalogue of commands. commands init creates the starter catalogue, commands list shows it, and commands check -- <command> evaluates a command through the normal check path with the repository manifest in scope.

commands run <name> is the execution path for a named allowed command. The manifest can identify a known command and can add a dangerous-pattern warning or block, but it cannot override a real engine finding. Tirith rechecks the resolved command before it starts it. A block is refused; a warning needs --yes or confirmation from the controlling terminal. A successful spawn is recorded as a run, while a declined warning or failed spawn is not.

References: crates/…/commands.rs• L1-10 crates/…/commands.rs• L18-190 crates/…/commands.rs• L193-359 crates/…/commands.rs• L413-439

Remote script workflows

tirith run <url> downloads and analyzes a remote script before it can execute. --no-exec stops after inspection. Live execution uses the reviewed script content inside the same contained execution boundary on every live path; the legacy --capsule spelling is accepted but is no longer the switch that enables containment. The command refuses to run when the required safety coverage is not available. An expected SHA-256 value can bind the review to exact downloaded bytes.

JSON mode is inspection-only for this surface when execution is enabled. This keeps script-controlled standard output from corrupting the one structured result that a machine consumer expects. A JSON result also marks incomplete analysis as blocked and incomplete, so a missing verdict cannot be read as a successful inspection. Completed script runs produce receipts that can later be listed or checked.

References: crates/…/run.rs• L13-30 crates/…/run.rs• L145-204 crates/…/run.rs• L387-486

Repository scans and impact previews

Scans and previews answer different questions. A scan asks whether repository content contains known safety issues. A preview asks what a destructive filesystem command would touch without running that command.

Repository scans

tirith scan can inspect a directory, one file, or standard input. It reports findings in human output, JSON, or SARIF. Include, exclude, ignore, and profile choices shape the review scope. A named policy profile takes precedence over a same-named built-in profile; built-in profiles cover CI hardening, AI-agent repositories, and open-source maintenance. Profiles may suppress or re-grade selected findings but do not invent new ones.

An explicitly named file or path must exist. This prevents a typo from becoming a successful empty scan. The default current-directory scan remains discovery-oriented when no target is supplied.

The --ci mode treats the scan as a build gate. --fail-on sets the severity threshold, and a profile can supply its default threshold. The result also states when the scan is incomplete because files were skipped, a rule failed, or coverage limits were reached. An incomplete security-relevant scan can fail CI even when the visible finding list is empty, so consumers must inspect the completeness fields rather than treat an empty list as proof of a clean tree.

References: crates/…/scan.rs• L8-82 crates/…/scan.rs• L104-235 crates/…/scan.rs• L248-325 crates/…/scan.rs• L397-425

Filesystem impact previews

The preview reads the filesystem to count impact. It does not execute the command and is not a sandbox. Depth, work, and read errors can limit the walk. When that happens, the counts are lower bounds and the output says that the result is incomplete. The preview combines filesystem findings with the cheap command-shape check before it derives its action.

References: crates/…/preview.rs• L1-28 crates/…/preview.rs• L35-69 crates/…/preview.rs• L93-167 crates/…/preview.rs• L185-218

Finding explanations and session feedback

The CLI provides a path from a finding to an explanation and from repeated warnings to a compact session view. These surfaces help an engineer decide what to change without weakening the original decision.

Finding explanations

tirith explain --rule <id> shows the purpose of a rule, its severity rationale, examples, false-positive guidance, remediation, and any security mapping. --fix limits the result to the remediation. --list can show the available rules or filter them by category.

tirith explain --finding <event-id:index> starts from an audit finding reference and resolves it to the rule that produced it. This is useful when the rule name is not known. tirith why is the shorter path for the most recent trigger. Both paths are explanatory only; they do not change trust, policy, or the original verdict.

References: crates/…/main.rs• L619-662 crates/…/explain.rs• L6-39 crates/…/explain.rs• L41-115 crates/…/why.rs• L5-41

Session warning feedback

tirith warnings summarizes warnings for the current shell session. It shows event detail, rule counts, and findings that lower paranoia settings hid. --summary is intended for shell-exit feedback, while JSON is intended for tools that need the session fields. The command is informational and does not enforce a new decision.

Repeated warning display can be reduced for readability, but the underlying verdict and audit record remain complete. A hidden-finding count can therefore explain why a session looks quiet while still carrying lower-severity activity.

References: crates/…/warnings.rs• L21-118 crates/…/warnings.rs• L121-175 crates/…/check.rs• L27-121

Protection status feedback

tirith status answers whether protection is actively available for the current environment. It combines the protection mode, hook configuration, policy path and scope, and threat-database state. It exits non-zero for a posture that is provably reduced, such as warn-only protection, degradation, a missing hook, or an unknown state.

An external status process may not see a live mode that remains inside the shell. When a hook is configured but its live mode is not visible, status reports that uncertainty instead of claiming that protection is off. Run tirith doctor inside the shell when that distinction matters.

References: crates/…/status.rs• L1-10 crates/…/status.rs• L16-77 crates/…/status.rs• L80-145

Prompt status feedback

tirith prompt-status provides a fast, low-noise view for a shell prompt. It shows the protection label and selected active context such as AWS, Kubernetes, SSH, or sudo state. The short form is bracketed for prompts, the long form is readable in a terminal, and JSON is stable for prompt integrations.

This is an indicator rather than an enforcement boundary. It is designed to return zero even when its cache or context read fails, using a minimal off view so a prompt does not break. The cache has a short lifetime and includes the inputs that shape the status, so a context from another shell is not reused.

References: crates/…/prompt_status.rs• L1-30 crates/…/prompt_status.rs• L106-150 crates/…/prompt_status.rs• L209-271 docs/prompt-integration.md• L1-43

Audit, receipts, and pending decisions

These workflows preserve evidence around decisions and actions. Audit records show what Tirith saw, receipts show the identity of downloaded scripts, and pending decisions hold work that needs a later operator choice.

Audit workflows

tirith audit export filters audit records by time, session, action, rule, or entry type and emits JSON or verdict CSV. audit stats summarizes verdict or hook-telemetry activity. audit report creates a verdict-focused compliance view in Markdown, JSON, or HTML.

audit verify checks the tamper-evident audit chain. An optional expected head anchors the check to a known tail and makes a missing log a failure rather than an empty result. A malformed or partially unreadable log is surfaced as a problem; it is not silently treated as a clean history. Diagnostic workflows can inspect a bounded recent tail instead of loading an unbounded audit history; they must mark the result as partial when older records were not inspected.

References: crates/…/main.rs• L1221-1233 crates/…/main.rs• L5194-5275 crates/…/audit.rs• L3-76 crates/…/audit.rs• L78-200 crates/…/audit.rs• L203-334 crates/…/audit_aggregator.rs• L73-167 crates/…/audit_aggregator.rs• L378-530

Script receipts

tirith receipt last and receipt list show records for scripts handled by tirith run. A receipt retains the script identity, source and redirect information, referenced domains and paths, analysis method, privilege context, and time. The default public view removes URL credentials and local working-directory data. Human and JSON views use that public boundary rather than exposing stored local metadata.

receipt verify <sha256> checks that the cached script bytes still match the receipt identity. A missing cache entry, changed content, or substituted receipt cannot be reported as a valid match. A missing receipt is an error rather than an empty successful verification.

References: crates/…/receipt.rs• L1-39 crates/…/receipt.rs• L43-119 crates/…/receipt.rs• L24-40 crates/…/receipt.rs• L73-135 crates/…/receipt.rs• L137-159

Interactive execution receipts

Interactive shell hooks use a separate one-use execution receipt to carry a checked decision from the CLI to the hook that will observe the command. The receipt binds the command, shell channel, session, working-directory identity, decision, and required approval state. A warning or approval interaction is completed before the receipt is armed; a block cannot be armed.

The receipt is consumed only when the hook observes the matching execution context. Expired, discarded, conflicting, or already-consumed receipts do not authorize a retry. This protects the gap between a preflight check and the shell's actual execution without asking the shell hook to recreate the full decision.

References: crates/…/check.rs• L391-481 crates/…/check.rs• L1124-1217 crates/…/shell_receipt.rs• L26-92 crates/…/shell_receipt.rs• L2626-2766 crates/…/shell_receipt.rs• L2768-2862

Pending decisions

tirith pending is the review queue for decisions that were deferred or left unresolved. Entries can come from deferred blocks, suppressed findings, raw findings, or restore-related workflows. pending list shows unresolved entries, pending export saves the full record set, and pending resolve <id> keep|rollback|approve|deny records an operator choice.

Pending records retain a redacted context preview, related rules, severity, source, timestamps, and auxiliary references. Unresolved entries age into expired after 30 days when the list is read. A rollback resolution never performs the restore. It marks the decision and prints the exact checkpoint restore command for the operator to review and run. A real unreadable store is reported as an error rather than an empty queue, and exports use an atomic destination write.

References: crates/…/pending.rs• L1-68 crates/…/pending.rs• L70-139 crates/…/pending.rs• L141-207 crates/…/pending.rs• L1-10 crates/…/pending.rs• L18-81 crates/…/pending.rs• L311-405

Incident response

Incident workflows provide a deliberate emergency posture for a machine or session that may be under attack. They make the safety boundary stricter and leave an operator-readable record of the response.

Incident posture

tirith incident start --reason "…" declares the posture. While active, runtime policy is fail-closed, the TIRITH=0 bypass is disabled, and a selected set of credential, payload, and execution-provenance rules is elevated. A second start does not replace the first reason or start time.

tirith incident status shows the active state and its start metadata. incident stop restores normal policy after confirmation. Stop is a recovery action that remains available even when the incident policy is fail-closed; JSON mode requires --yes because it cannot safely prompt. If another process clears the incident first, the command reports an already-inactive outcome instead of claiming that it restored the policy.

References: crates/…/incident.rs• L1-18 crates/…/incident.rs• L39-128 crates/…/incident.rs• L131-247 crates/…/incident.rs• L249-323

Incident reports

tirith incident report creates a Markdown response report for the active incident or the current machine state. It brings together a bounded audit timeline, recent findings, persistence surfaces, sensitive environment names, PATH risks, repository hooks, canary status, and an operator-maintained actions section.

The report uses command previews that are already redacted and applies another safe display pass before embedding them. It is a response aid, not proof that every event was captured: an absent start time gives a recent-state report, and a bounded audit tail is marked as partial. Malformed records in the inspected tail are skipped and counted, while an unreadable log fails that section instead of being treated as empty. A selected report destination is written as a protected atomic file so the report does not replace a symlink target or expose a partial file.

References: crates/…/incident.rs• L326-420 crates/…/incident.rs• L453-497 crates/…/incident.rs• L507-655 crates/…/audit_aggregator.rs• L124-167

Change checklist

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

  • Keep the action-to-exit-code contract aligned across check, commands run, shell hooks, deferred decisions, and JSON output.
  • Keep command, finding, receipt, pending, and incident report redaction aligned. A new output field can expose data even when older fields are safe.
  • When scan coverage or profile behavior changes, update both the completeness signals and the CI failure decision. An empty finding list must not hide an incomplete scan, and an explicit missing target must not become a clean no-op.
  • Keep audit entry types and filters aligned with stats, reports, and chain verification. A new event that is written but cannot be exported or verified is hard to investigate.
  • Keep bounded audit readers aligned with report wording. A report that reads only a recent tail must show partial coverage and distinguish skipped malformed lines from terminal read errors.
  • Keep protection-mode labels aligned between status, prompt-status, shell hooks, and the prompt integration contract.
  • Preserve the separation between a check, an armed shell execution receipt, and a real run. Do not let a preflight success imply observed execution.
  • Keep remote-run JSON inspection semantics aligned with the execution boundary. Do not allow child output to share a structured stdout stream.

Important failure modes

TriggerConsequenceGuard
Piped command input is unreadable or exceeds the check limitTirith does not analyze a truncated command and returns a failurecheck reads one byte past the limit and fails closed
A warning-producing named command has no trusted terminal confirmationcommands run refuses the command instead of trusting piped input or an environment flagUse a controlling-terminal acknowledgement or explicit --yes for intentional automation
A scan has security-relevant coverage gaps or rule panics in CICI fails rather than treating unscanned content as cleanInspect analysis_incomplete, coverage_gaps, and panic fields in JSON/SARIF
An explicitly named scan target is missing or cannot be accessedThe scan fails instead of reporting a clean zero-file resultCorrect the target or scan a known directory
Preview walking reaches a depth/work cap or cannot read pathsCounts are lower bounds and may understate impactTreat the incomplete note and read-error count as a reason for manual review
The audit log is missing while --expected-head is suppliedVerification fails because deletion cannot satisfy the asserted history anchorPreserve the expected head outside the log and investigate the missing file
A receipt's cached bytes or embedded identity changesReceipt verification fails and the script is not treated as the reviewed artifactRe-fetch or review the exact content before using it
A receipt is absent or the pending store is corrupt, blank, or unreadableVerification or pending operations fail rather than claiming a clean or empty statePreserve the state for inspection and repair it through an explicit recovery process
An incident report reaches the audit-tail byte, line, or record limitThe report covers only recent history and may understate the incident timelineTreat the partial-history note as a review boundary and inspect the full audit history separately
An audit-tail read hits invalid UTF-8, an oversized line, or a read errorThe affected report section is unavailable instead of presenting a clean historyPreserve the audit log and investigate the read failure before relying on the report
Incident stop is attempted without confirmation in JSON modeThe incident remains activeRepeat with --yes; stop is intentionally not blocked by incident fail-closed policy
A configured hook's live mode is invisible to an external status processStatus reports configured uncertainty rather than claiming full protection or no protectionRun tirith doctor inside the protected shell

Key files

FileWhy to read it
crates/…/main.rsDefines the public command groups, flags, output modes, and dispatch for these workflows.
crates/…/check.rsShows the command preflight lifecycle, decision side effects, deferred blocks, warning acknowledgement, and shell receipt handoff.
crates/…/commands.rsShows how repository command names are checked and rechecked before execution.
crates/…/run.rsShows the remote-script inspection, authorization, structured result, and contained-run boundary.
crates/…/scan.rsShows scan targets, profiles, output forms, completeness reporting, and CI decisions.
crates/…/preview.rsShows the filesystem-impact preview and its lower-bound limits.
crates/…/explain.rsShows rule and audit-finding explanation paths.
crates/…/audit.rsShows audit export, aggregation, reports, and chain verification.
crates/…/audit_aggregator.rsDefines audit record filtering, statistics, exports, compliance reports, and bounded recent-tail reads used by diagnostic reports.
crates/…/receipt.rs and crates/…/receipt.rsShow script receipt views and identity checks for cached content.
crates/…/pending.rs and crates/…/pending.rsShow pending-decision review, expiry, export, and resolution semantics.
crates/…/incident.rsShows emergency posture, recovery, and response-report workflows.
crates/…/status.rs and crates/…/prompt_status.rsShow health-oriented status contracts for CI, terminals, and prompts.
docs/commands.mdProvides the concise command reference and places these workflows in the larger CLI.