CLI and user workflows
Tirith is a command-line safety gate for shell work, file review, package activity, and local security operations. The CLI turns the safety engine into related workflows that inspect an action, allow or stop it, explain the result, record evidence, and help the user keep protection active.
Command surface
Command dispatcher
The tirith executable accepts one top-level command and routes it to the matching workflow. The command definition and dispatcher live in crates/…/main.rs; command handlers live under crates/tirith/src/cli/. This split keeps command syntax at the boundary while each workflow owns its user-facing behavior.
The CLI groups commands by the job they help an engineer do:
| Group | Main purpose | Examples |
|---|---|---|
| Scan and analyze | Check commands, URLs, files, packages, tasks, and impact | check, run, scan, preview, score, explain, task |
| Status and health | Show protection state and local evidence | status, doctor, warnings, receipt, dashboard |
| Setup and onboarding | Connect Tirith to a shell, tool, or installation | init, onboard, setup, install, update |
| Policy and trust | Shape decisions and record narrow trust | policy, rule, trust, output |
| Shell and system | Inspect or guard the execution environment | hooks, path, exec, env, context, sudo, ssh |
| Supply chain | Review packages, artifacts, threat data, and build or deployment evidence | package, pkg, ecosystem, threat-db, iac, attest |
| Integrations | Connect agents, MCP clients, editors, and licensed features | mcp, gateway, agent, ai, lsp, license |
| Forensics | Preserve or review what happened | audit, incident, checkpoint, pending, share, redact |
The --help output repeats this grouping and each command has its own help. Hidden commands support integration protocols and shell internals rather than normal user work.
References: crates/…/main.rs• L9-23 crates/…/main.rs• L223-344 crates/…/main.rs• L3056-3297 crates/…/main.rs• L8095-8165
Command boundaries
The CLI has three useful boundaries. A preflight command analyzes input before another process runs. An execution command owns or observes the child process. An operations command changes or inspects Tirith state. Knowing the boundary prevents a report from being mistaken for enforcement.
| Boundary | User question | Typical commands |
|---|---|---|
| Preflight | “Is this command, file, URL, install, or task safe to use?” | check, paste, scan, score, diff, package risk, task check |
| Execution | “Can Tirith review and then run this action?” | run, install, pkg install, commands run |
| Observation | “What did the action change?” | watch, temp-run, preview, checkpoint |
| Operations | “Is protection configured and how do I manage it?” | init, onboard, doctor, status, policy, incident |
Some names look similar but have different guarantees. preview does not run a command. watch runs it and reports changes after the fact. temp-run changes the working directory for a run, but its normal mode is file isolation only and is not a sandbox. task check is diagnostic only: it reports what a task envelope would be allowed to do without enforcing or carrying out the task.
References: crates/…/main.rs• L42-130 crates/…/main.rs• L2327-2437 crates/…/preview.rs• L19-69 crates/…/temp_run.rs• L69-86 crates/…/task.rs• L1-14
Safety decision workflows
Command checks
tirith check is the main pre-execution workflow. It accepts a shell command, applies the selected shell grammar and policy, and returns a verdict for the caller. A verdict is an allow, warn, warn with acknowledgement, or block decision. The shell hook uses this same path so an interactive command and an explicit CLI check follow the same decision model.
The command can receive input as arguments or from standard input. Human output is intended for a terminal. JSON output is intended for hooks, CI, editors, and other callers that need stable structured data. Options such as --offline, --no-daemon, --defer, and --suggest change how the check is performed or presented, not the meaning of a real block.
Command analysis uses shell-aware normalization and resolves common execution wrappers before it classifies the command. The analysis has bounded work limits. If it cannot prove the complete command, it reports an incomplete analysis and blocks the unresolved part instead of treating it as clean. On Unix, the CLI can send the check to a local daemon; the request carries caller-specific state such as offline mode, and an unavailable daemon falls back to local analysis.
check can also create approval metadata for a shell hook. In the normal check path, a successful result permits a later caller to run the command; check itself does not claim that it executed the command.
References: crates/…/main.rs• L243-344 crates/…/check.rs• L134-220 crates/…/check.rs• L378-453 crates/…/command.rs• L45-60 crates/…/command.rs• L862-1052 crates/…/daemon.rs• L295-422
Reviewed execution
tirith run reviews a remote script before it executes. The workflow downloads the script, checks its content and related risk, and then either stops or runs the reviewed bytes. On supported live-execution paths, the run is contained by the execution controls required for that platform; if the required coverage is not available, the command fails closed instead of silently using an ordinary process.
--no-exec turns the command into an inspection-only workflow. A supplied hash adds an integrity check. JSON mode is also inspection-only when execution would make the output stream unsafe to parse. The result can include a verdict, execution state, exit code, and a receipt that lets a later operator inspect what was reviewed.
For ordinary package-manager installs, tirith install is a risk-analysis and recorded-transaction workflow. The enforcing package path is separate: tirith pkg install is designed to install verified package bytes under its supported platform conditions.
References: crates/…/main.rs• L383-430 crates/…/main.rs• L432-525 crates/…/main.rs• L527-542 crates/…/run.rs• L5-105 crates/…/install.rs• L1566-1601
Task envelope assessment
tirith task check assesses a bounded task envelope, which is a document that describes proposed actions and their claimed sources. It reads the document from a file or standard input, applies the local task policy, and reports inferred, allowed, and denied effects. It never executes an action, fetches a resource, resolves a package, or writes a file.
The adapter value is an operator assertion about where the document came from. The envelope cannot grant trust to itself. An incomplete assessment returns a finding state rather than treating unlisted effects as absent, so a caller can distinguish “nothing was denied” from “the full task could not be assessed.”
The following flow shows the diagnostic boundary of the task workflow.
flowchart LR
A[Task envelope from file or stdin] --> B[Parse and validate]
B --> C[Apply local task policy]
C --> D[Report inferred, allowed, and denied effects]
D --> E[Exit status for the caller]
C -. no execution, fetch, package resolution, or write .-> D
References: crates/…/main.rs• L620-628 crates/…/main.rs• L3056-3076 crates/…/task.rs• L34-83 crates/…/task.rs• L173-251
File and content checks
The CLI extends command checks to content that may reach a shell or an agent. paste checks copied text. scan checks a file, directory, or standard input. fetch can inspect a remote URL or save a downloaded file without running it. view, logs, share, and redact help an engineer inspect or pass on output without treating untrusted terminal text as trusted content.
Repository scans can run in CI mode and can emit human output, JSON, or SARIF. Profiles tune the scan for a use case such as CI hardening, an AI-agent repository, or open-source maintenance. The important product flow is the same: select an input, analyze it under policy, render findings, and return a status that a caller can use.
For command-level interaction details such as pending decisions, explanations, receipts, and scan feedback, see Interactive safety workflows.
References: crates/…/main.rs• L346-381 crates/…/main.rs• L868-943 crates/…/main.rs• L945-981 crates/…/scan.rs• L104-190
Review and remediation workflows
Impact review
tirith preview answers a narrow question before a destructive command runs: what could this command touch? It simulates filesystem impact and reports the likely file, directory, symlink, repository, and system-path scope. It also combines this impact view with the cheap command-shape checks.
The preview is deliberately separate from check. The normal check path stays fast and does not walk the disk. Preview is a review aid, not a block boundary or a sandbox, so the user must still decide whether to run the command.
References: crates/…/main.rs• L2327-2371 crates/…/preview.rs• L1-69
Verified fixes
tirith fix turns findings into either a verified command rewrite or plain remediation guidance. It re-checks the final command before it exposes that command for use. If no complete safe rewrite exists, it does not invent one; it explains what the user must change instead.
Interactive mode lets a user accept a rewrite. JSON and non-interactive modes emit suggestions without applying them. This gives scripts a clear separation between “a suggestion exists” and “a user accepted a command.” The check --suggest option exposes the same kind of suggestion as part of a check result.
References: crates/…/main.rs• L983-1044 crates/…/fix.rs• L1-68 crates/…/fix.rs• L165-215
Change observation
tirith watch runs a command and compares state before and after the run. It reports file changes in the current directory or selected paths together with changes to environment names, PATH, and shell start-up files. It is an after-the-fact lens: it does not stop the child and its exit code remains the child’s exit code.
tirith temp-run provides a stronger review shape for file output by starting the child in a fresh temporary directory. It can seed that directory with a repository copy and can reduce the child environment. These options improve review of file impact, but the normal mode still leaves the child with the user’s privileges and network access. The JSON result identifies the actual isolation kind so an automated consumer cannot mistake it for a sandbox.
References: crates/…/main.rs• L2373-2437 crates/…/main.rs• L44-77 crates/…/temp_run.rs• L25-79
Safeguard operations
Setup and self-management
Tirith needs a shell or tool integration before it can guard actions that users launch through that integration. init prints setup for Bash, Zsh, Fish, PowerShell, and Nushell. onboard inspects the local environment and recommends a policy and next steps. setup configures supported AI coding tools and related integrations. doctor checks the result and can offer bounded fixes.
The full doctor report combines hook state, policy discovery, threat-data health, and other local protection signals. doctor --quick is a small read-only status contract for fast polling. doctor --fix applies only the repairs the operator confirms, such as installing or refreshing hooks, creating a starter policy, repairing tool hooks, downloading threat data, or clearing a Bash safe-mode flag.
Installation, initialization, onboarding, shell integration, completions, health checks, and self-update form a separate lifecycle. See Installation and self-management for that lifecycle rather than treating setup commands as part of command analysis.
References: crates/…/main.rs• L713-781 crates/…/main.rs• L1390-1472 crates/…/init.rs• L116-297 crates/…/onboard.rs• L100-137 crates/…/doctor.rs• L7-65 crates/…/doctor.rs• L72-227 crates/…/doctor.rs• L1166-1238
Policy and trust controls
Policy commands define how findings become decisions. They initialize and validate policy, test a policy against a command, and tune policy from recorded audit data. Rule commands help an operator validate and understand custom rules. Trust commands add narrow, scoped, expiring exceptions for known patterns.
The command manifest workflow adds a repository-level catalogue without weakening the engine. commands init creates the catalogue, commands list shows it, and commands check evaluates a command through the normal check path. commands run re-checks the named command before execution, refuses blocks, and requires trusted acknowledgement for warnings. An allowed manifest entry can suppress only the “unknown repository command” annotation; it cannot suppress a real safety finding.
These controls shape the decision process but do not turn a broad allowlist into a universal bypass. The command manifest can document expected repository commands and make a repository stricter, while a listed command still passes through the safety engine before commands run executes it.
References: crates/…/main.rs• L1190-1298 crates/…/main.rs• L2693-2728 crates/…/commands.rs• L1-10 crates/…/commands.rs• L76-179 crates/…/commands.rs• L355-443 crates/…/commands.rs• L988-1019
Operational guards
Operational safeguards add context to actions that are easy to perform on the wrong target. Context and SSH commands label important environments. IaC commands check plan use before an apply. Sudo commands manage a short-lived reasoned session. Environment, executable, path, hook, persistence, hygiene, and alias commands inspect local conditions that can change what a command really does.
Most of these controls have an inspect or scan action and a separate guard switch. The inspect action gives the operator a full view. The guard switch opts selected checks into the command path. This keeps expensive or broad inspection out of the normal hot path while still allowing teams to enforce the safeguards that fit their work.
References: crates/…/main.rs• L1809-1847 crates/…/main.rs• L1852-1908 crates/…/main.rs• L1954-1999 crates/…/main.rs• L2198-2287
Threat intelligence operations
The threat-db workflow supplies signed threat data for checks that need package, host, IP, or typosquat indicators. threat-db update verifies the published metadata and downloaded database before installation. threat-db status shows whether the effective database is present, valid, and stale.
The workflow can also refresh optional supplemental feeds when policy enables them. A partial feed failure keeps the last known good supplemental data instead of publishing an incomplete replacement. Foreground checks and the daemon can request a background update when the configured interval is due; offline mode prevents that network activity.
References: crates/…/threatdb_cmd.rs• L348-405 crates/…/threatdb_cmd.rs• L523-643 crates/…/threatdb_cmd.rs• L733-842 crates/…/threatdb_cmd.rs• L1018-1091 crates/…/threatdb_cmd.rs• L1291-1349 crates/…/daemon.rs• L818-847
Incident controls
tirith incident changes the local posture when an operator suspects an active attack. Starting an incident forces fail-closed behavior, disables the environment bypass, and raises selected existing rules. Stopping the incident restores normal policy and remains available as a recovery action.
The surrounding safeguards support the same response loop. Canaries provide a local signal when a decoy token is touched. Pending decisions preserve work that needs later review. Checkpoints and receipts preserve evidence or support rollback-oriented review. incident report gathers a bounded timeline, recent findings, and current persistence, environment, path, hook, and canary state into a shareable report. The report uses already-redacted command previews and leaves an operator section for actions taken.
These commands help an operator move from detection to containment and then to recovery without changing the core detection engine. The stop action is deliberately available outside the active fail-closed decision path, so a stuck incident can be ended.
References: crates/…/main.rs• L2730-2821 crates/…/main.rs• L2861-2891 crates/…/main.rs• L3078-3116 crates/…/incident.rs• L39-227 crates/…/incident.rs• L249-395 crates/…/incident.rs• L453-497
Output and evidence
Human and machine output
Commands use human-readable output by default and expose JSON where another program needs a stable result. Scan also supports SARIF for code scanning systems. The common format handling in crates/…/mod.rs keeps --format json and the compatibility --json spelling aligned across commands.
Human output is written for a terminal and can be made quieter with the global --quiet option. Security notices, errors, verdicts, and structured output are not hidden by that option. Values that may come from commands, files, logs, or findings are sanitized before they are shown as terminal text. JSON writers report a non-zero result when stdout fails, so a consumer does not receive truncated JSON with a success status.
References: crates/…/mod.rs• L3-45 crates/…/mod.rs• L63-119 crates/…/main.rs• L25-40
Exit status contract
Exit codes let shell hooks and automation act without parsing human text. The common verdict convention is allow 0, block 1, warn 2, and warn-with-acknowledgement 3; other commands use codes that match their own job. For example, fix reports whether a rewrite was applied, while temp-run returns the child’s exit code and reports its file diff separately.
An engineer should read the command help before composing a pipeline because a command can use a different status contract even when it analyzes the same input. JSON output describes the result, but the exit code remains the primary control signal for a shell or CI step.
References: crates/…/fix.rs• L11-21 crates/…/temp_run.rs• L69-79 crates/…/preview.rs• L19-27 crates/…/check.rs• L24-25 crates/…/task.rs• L28-32 crates/…/attest.rs• L17-21
Audit evidence
Analysis and guarded operations can produce local audit records. Audit commands export and summarize those records, verify their tamper-evident chain, and produce reports. Receipt commands expose evidence for reviewed remote scripts. Status and dashboard commands turn local policy, hook, threat-data, and audit state into an operator view.
The attest workflow adds point-in-time evidence for a build and its deployment. attest build binds source and output trees to a receipt. attest verify-build checks whether those trees still match. attest deployment checks the routes named by the build output and records the bytes returned by one origin. attest verify-deployment checks that receipt without making another network request. These receipts do not claim that a build is reproducible or that a site is continuously monitored.
Evidence is useful for explaining a decision and checking system health. It does not change the fact that a preflight check did not execute the command. The CLI keeps execution receipts, attestation receipts, and audit records separate from ordinary explanatory output so an operator can distinguish what Tirith observed from what a child process or remote server did.
tirith explain connects this evidence back to the rule that produced it. It can list rule guidance, explain a rule directly, or resolve a finding identifier from the recent audit log before showing the matching rule. The lookup is intentionally bounded, so an old finding may need to be located with an audit export first.
The attestation flow connects local build evidence to a point-in-time deployment measurement.
flowchart LR
A[Source and output trees] --> B[Build receipt]
B --> C[Verify build]
B --> D[Fetch manifest-listed routes]
D --> E[Deployment receipt]
E --> F[Verify receipt without refetching]
References: crates/…/audit.rs• L3-75 crates/…/audit.rs• L203-220 crates/…/receipt.rs• L3-109 crates/…/status.rs• L1-78 crates/…/main.rs• L3078-3297 crates/…/attest.rs• L93-171 crates/…/attest.rs• L266-327 crates/…/attest.rs• L334-399 crates/…/attest.rs• L491-552 crates/…/explain.rs• L6-189
Change checklist
When these files or sections are changed, remember to consider these:
- Add or rename a top-level command in the command enum, dispatcher, category help, and any integration-facing command list. A command that dispatches correctly but is absent from the category text is hard to discover and can evade command-surface checks.
- Change a JSON or SARIF result only with its consuming hook, editor, CI, or gateway contract in view. The format resolver and command-specific envelope must continue to agree.
- Change
checkverdict or acknowledgement behavior together with the shell-hook exit contract and execution-receipt path. A mismatch can let a shell run a command with stale approval state. - Change
run,install, orpkg installplatform behavior together with the help text and the distinction between inspection, recorded execution, and enforcing execution. - Change
commandsmanifest semantics together withcommands checkandcommands run. The manifest must remain subordinate to the engine, and warning acknowledgement must remain trusted. - Change task-envelope decision fields together with the diagnostic CLI and any MCP preview consumer. Incomplete assessment must remain visible and must not be presented as an enforceable approval.
- Change attestation receipt fields or status codes together with both verify commands and the build/deployment help text. A point-in-time observation must not become a reproducibility or continuous-monitoring claim.
- Change a shared guard switch together with every namespace that reads it. Context, IaC, SSH, sudo, devcontainer, environment, executable, and hook controls can intentionally share policy state.
- Change audit or receipt fields together with redaction and public-output paths. Stored command data must not reappear through JSON, reports, or diagnostic explanations.
- Change command normalization or bounded-analysis behavior together with daemon checks and custom-rule command facts. All paths must keep unresolved command execution fail-closed.
- Change the daemon request or response fields together with the shell-hook client, offline propagation, and daemon status checks. A persistent daemon must not use stale caller state or report a live service that did not answer.
- Change shell-hook assets or shell detection together with
doctorhook classification and its quick-status schema. Presence alone must not be reported as effective protection. - Change
doctor --fixrepair scope together with its confirmation rules and policy-write boundary. A repair must not overwrite existing policy or turn manual PATH-shadow guidance into deletion. - Change finding identifiers or rule explanations together with audit retention and
explain --finding. A bounded lookup must report an old or unknown record instead of guessing a rule. - Change incident report fields together with redaction and the always-available stop path. Reports must remain safe to share and stop must remain able to recover a lockout.
- Change threat-data manifest, index, or feed handling together with signature, hash, rollback, currentness, and last-known-good rules. A partial or stale source must not silently replace verified data.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| Shell hook is missing, stale, or degraded | Commands launched through that shell can run without the expected gate or can only warn | Run tirith status and tirith doctor; restore the hook with the setup lifecycle |
tirith temp-run is treated as a sandbox | A child can still reach user credentials, network, and full user privileges | Treat normal temp-run as file-impact review only; use an explicitly supported contained workflow when containment is required |
tirith run --json is used for live execution | Child output could corrupt the single JSON result | Use --no-exec for JSON inspection or use human output for execution |
| The daemon runtime directory or socket is controlled by another user | A hook could trust a forged verdict or the daemon could bind in an unsafe location | Use the daemon only when its private directory, owner-only socket, and same-user peer checks pass; inspect failures with tirith daemon status |
tirith doctor --quick is treated as a full health report | Expensive checks such as audit, threat-data, and baseline inspection are not run | Use full tirith doctor when you need broad diagnosis; use --quick only for fast status polling |
| A Tirith-owned install flag is placed after the install source | The package manager receives the flag and Tirith may not apply the intended control | Put Tirith options before npm, pip, cargo, or another source selector |
External status cannot see a shell’s live mode | The result may be “configured; live mode unknown,” not proof of full protection | Run tirith doctor inside the configured shell |
| A command is listed in the repository manifest without an engine review | The manifest entry does not suppress real safety findings, but an operator may expect it to | Use tirith commands run, which re-checks the resolved command before execution |
| A warning-producing manifest command is run without trusted acknowledgement | The command is refused instead of treating piped input or caller-controlled state as approval | Pass --yes only for intentional automation, or confirm from the controlling terminal |
| A task envelope is incomplete or contains denied effects | The assessment exits non-zero and cannot be used as proof that unlisted effects are safe | Treat incomplete effects as unknown and review the reported policy decision |
| A build or deployment receipt is partial or mismatched | The evidence cannot support a clean verification result | Inspect the coverage and findings; re-run the relevant binding workflow after fixing the source, output, or route coverage |
attest verify-deployment is treated as a live site check | The operator may rely on an old route measurement as if it were current | Run tirith attest deployment again to measure the site again |
| A remote script is fetched and saved for later execution | The stable path is marked tainted and later execution can raise a high-risk finding | Review the saved file and manage its taint state explicitly; do not infer safety from download success |
A finding is older than the bounded audit tail used by explain --finding | The command cannot resolve the identifier and must not invent a rule explanation | Use tirith audit export --since to locate the record, then use tirith explain --rule |
| An incident report is written to an unsafe or shared destination | Sensitive local paths or host state can be exposed or the write can follow a planted path | Use a controlled destination and review the report before sharing; the writer applies safe replacement and restrictive permissions |
| A threat feed update is partial or returns no indicators | Replacing the last good supplemental data would reduce detection coverage | Keep the existing supplemental database and retry after the feed set is complete |
| A signed threat database is stale, mismatched, or fails verification | New threat checks may lack current data or the update must be rejected | Run tirith threat-db status; force a verified update and do not treat download success as database validity |
Key files
| File | Why to read it |
|---|---|
| crates/…/main.rs | Defines the public command tree, command categories, help contracts, and top-level dispatch. |
| crates/…/mod.rs | Defines shared output-format handling, terminal sanitization, JSON write behavior, and common CLI helpers. |
| crates/…/check.rs | Shows the main check workflow from input and policy through verdict, audit, approval, and receipt handling. |
| crates/…/command.rs | Shows shell-aware command classification, wrapper resolution, and fail-closed incomplete analysis. |
| crates/…/daemon.rs | Shows the local daemon check path, runtime safeguards, lifecycle commands, and status probe. |
| crates/…/run.rs | Shows the reviewed remote-script workflow and its inspection-versus-execution boundary. |
| crates/…/scan.rs | Shows how file scans select scope, profiles, output formats, and CI failure thresholds. |
| crates/…/fix.rs | Shows how remediation stays advisory unless a final command passes verification and a user accepts it. |
| crates/…/preview.rs | Shows the separate filesystem-impact review surface. |
| crates/…/temp_run.rs | Defines the file-isolation claim and the limits of temp-run. |
| crates/…/task.rs | Shows the read-only task-envelope assessment and its incomplete-assessment contract. |
| crates/…/attest.rs | Shows the build and deployment receipt workflows and their point-in-time evidence limits. |
| crates/…/init.rs | Shows shell-hook initialization, shell detection, hook assets, and prompt-status wiring. |
| crates/…/onboard.rs and crates/…/doctor.rs | Show environment discovery, setup recommendations, health checks, quick status, and bounded repair. |
| crates/…/explain.rs | Shows rule listing, rule remediation guidance, and bounded finding-to-rule lookup. |
| crates/…/incident.rs | Shows incident posture changes, recovery, and redacted report generation. |
| crates/…/threatdb_cmd.rs | Shows signed threat-data updates, status, supplemental feed handling, and background refresh. |
| crates/…/audit.rs and crates/…/receipt.rs | Show how the CLI exports audit evidence and exposes reviewed-script receipts. |
| crates/…/commands.rs | Shows how repository command manifests remain subordinate to the safety engine and how named commands are re-checked before execution. |