Skip to main content

harn_cli/cli/
mod.rs

1//! Top-level clap definition for the `harn` CLI.
2//!
3//! Per-subcommand arg structs live in their own modules under
4//! `crates/harn-cli/src/cli/`. The `Cli` and `Command` enum here only
5//! reference types via `pub(crate) use ...` re-exports so external
6//! consumers can keep using `crate::cli::TypeName` unchanged.
7//!
8//! Some variants of subcommand enums are reached only by destructuring
9//! the parent (`SubCommand::Foo(args) => ...`) and are never referenced
10//! by name from outside this module. Those types stay private to their
11//! per-subcommand module and are accessed through their parent enum.
12
13mod bench;
14mod check;
15mod completions;
16mod connect;
17mod connector;
18mod contracts;
19mod crystallize;
20mod doctor;
21mod dump;
22mod explain;
23mod flow;
24mod init;
25mod lint_fmt;
26mod mcp;
27mod merge_captain;
28mod models;
29mod orchestrator;
30mod package;
31mod persona;
32mod playground;
33mod portal;
34mod provider;
35mod quickstart;
36mod run;
37mod runs;
38mod serve;
39mod skill;
40mod skills;
41mod supervisor;
42mod test;
43mod test_bench;
44mod trace;
45mod trigger;
46mod trust;
47mod try_cmd;
48mod util;
49mod verify;
50mod viz;
51mod watch;
52mod workflow;
53
54pub(crate) use bench::BenchArgs;
55pub(crate) use check::{CheckArgs, CheckOutputFormat};
56pub(crate) use completions::{CompletionShell, CompletionsArgs};
57pub(crate) use connect::{
58    ConnectApiKeyArgs, ConnectArgs, ConnectCommand, ConnectGenericArgs, ConnectGithubArgs,
59    ConnectLinearArgs, ConnectOAuthArgs, ConnectSetupPlanArgs, ConnectStatusArgs,
60};
61pub(crate) use connector::{
62    ConnectorArgs, ConnectorCheckArgs, ConnectorCommand, ConnectorTestArgs,
63};
64pub(crate) use contracts::{
65    ContractsArgs, ContractsBundleArgs, ContractsCommand, ContractsHostCapabilitiesArgs,
66    ContractsOutputArgs,
67};
68pub(crate) use crystallize::{
69    CrystallizeArgs, CrystallizeCommand, CrystallizeIngestArgs, CrystallizeShadowArgs,
70    CrystallizeValidateArgs,
71};
72pub(crate) use doctor::DoctorArgs;
73pub(crate) use dump::{
74    DumpConnectorMatrixArgs, DumpHighlightKeywordsArgs, DumpProtocolArtifactsArgs,
75    DumpTriggerQuickrefArgs,
76};
77pub(crate) use explain::ExplainArgs;
78pub(crate) use flow::{
79    FlowArchivistCommand, FlowArchivistScanArgs, FlowArgs, FlowCommand, FlowReplayAuditArgs,
80    FlowShipCommand, FlowShipWatchArgs,
81};
82pub(crate) use init::{InitArgs, NewArgs, ProjectTemplate};
83pub(crate) use lint_fmt::{FmtArgs, PathTargetsArgs};
84pub(crate) use mcp::{McpArgs, McpCommand, McpLoginArgs, McpServeArgs, McpServerRefArgs};
85pub(crate) use merge_captain::{
86    MergeCaptainArgs, MergeCaptainAuditArgs, MergeCaptainAuditFormat, MergeCaptainBackendKind,
87    MergeCaptainCommand, MergeCaptainIterateArgs, MergeCaptainIterateFormat,
88    MergeCaptainLadderArgs, MergeCaptainLadderFormat, MergeCaptainMockCleanupArgs,
89    MergeCaptainMockCommand, MergeCaptainMockInitArgs, MergeCaptainMockServeArgs,
90    MergeCaptainMockStatusArgs, MergeCaptainMockStepArgs, MergeCaptainRunArgs,
91};
92pub(crate) use models::{
93    ModelRecommendArgs, ModelsArgs, ModelsCommand, ModelsInstallArgs, ModelsListArgs,
94    ModelsTestArgs,
95};
96pub(crate) use orchestrator::{
97    OrchestratorArgs, OrchestratorCommand, OrchestratorDeployArgs, OrchestratorDeployProvider,
98    OrchestratorDlqArgs, OrchestratorFireArgs, OrchestratorInspectArgs, OrchestratorLocalArgs,
99    OrchestratorLogFormat, OrchestratorQueueArgs, OrchestratorQueueCommand,
100    OrchestratorQueueDrainArgs, OrchestratorQueueLsArgs, OrchestratorQueuePurgeArgs,
101    OrchestratorRecoverArgs, OrchestratorReloadArgs, OrchestratorReplayArgs,
102    OrchestratorReplayOracleArgs, OrchestratorResumeArgs, OrchestratorServeArgs,
103    OrchestratorStatsArgs, OrchestratorTenantArgs, OrchestratorTenantCommand,
104    OrchestratorTenantCreateArgs, OrchestratorTenantDeleteArgs, OrchestratorTenantLsArgs,
105    OrchestratorTenantSuspendArgs,
106};
107pub(crate) use package::{
108    AddArgs, InstallArgs, PackageArgs, PackageCacheCommand, PackageCommand, PublishArgs,
109    RemoveArgs, UpdateArgs,
110};
111pub(crate) use persona::{
112    PersonaArgs, PersonaCheckArgs, PersonaCommand, PersonaControlArgs, PersonaDoctorArgs,
113    PersonaInspectArgs, PersonaListArgs, PersonaNewArgs, PersonaSpendArgs, PersonaStatusArgs,
114    PersonaTemplateKind, PersonaTickArgs, PersonaTriggerArgs,
115};
116pub(crate) use playground::PlaygroundArgs;
117pub(crate) use portal::PortalArgs;
118pub(crate) use provider::{ModelInfoArgs, ProviderCatalogArgs, ProviderReadyArgs};
119pub(crate) use quickstart::QuickstartArgs;
120pub(crate) use run::RunArgs;
121pub(crate) use runs::{EvalArgs, ReplayArgs, RunsArgs, RunsCommand};
122pub(crate) use serve::{
123    A2aServeArgs, McpServeTransport, ServeAcpArgs, ServeArgs, ServeCommand, ServeMcpArgs,
124    ServeTlsMode,
125};
126pub(crate) use skill::{
127    SkillArgs, SkillCommand, SkillEndorseArgs, SkillKeyCommand, SkillKeyGenerateArgs,
128    SkillSignArgs, SkillTrustAddArgs, SkillTrustCommand, SkillTrustListArgs, SkillVerifyArgs,
129    SkillWhoSignedArgs,
130};
131pub(crate) use skills::{
132    SkillsArgs, SkillsCommand, SkillsInspectArgs, SkillsInstallArgs, SkillsListArgs,
133    SkillsMatchArgs, SkillsNewArgs,
134};
135pub(crate) use supervisor::{
136    SupervisorArgs, SupervisorCommand, SupervisorDlqCommand, SupervisorDlqListArgs,
137    SupervisorDlqReplayArgs, SupervisorFireArgs, SupervisorInspectArgs, SupervisorListArgs,
138    SupervisorPauseArgs, SupervisorRecoverArgs, SupervisorReplayArgs, SupervisorResumeArgs,
139    SupervisorStartArgs, SupervisorStopArgs,
140};
141pub(crate) use test::TestArgs;
142pub(crate) use test_bench::{
143    TestBenchArgs, TestBenchCommand, TestBenchReplayArgs, TestBenchRunArgs,
144};
145pub(crate) use trace::{TraceArgs, TraceCommand, TraceImportArgs};
146pub(crate) use trigger::{TriggerArgs, TriggerCancelArgs, TriggerCommand, TriggerReplayArgs};
147pub(crate) use try_cmd::TryArgs;
148// `TrustOutcomeArg` / `TrustTierArg` are referenced from the cli
149// parser tests only; they're matched via destructuring elsewhere.
150#[allow(unused_imports)]
151pub(crate) use trust::{
152    TrustArgs, TrustCommand, TrustExportArgs, TrustOutcomeArg, TrustQueryArgs, TrustTierArg,
153    TrustVerifyChainArgs,
154};
155pub(crate) use verify::VerifyArgs;
156pub(crate) use viz::VizArgs;
157pub(crate) use watch::WatchArgs;
158pub(crate) use workflow::{WorkflowArgs, WorkflowCommand};
159
160use clap::{Parser, Subcommand};
161
162#[derive(Debug, Parser)]
163#[command(
164    name = "harn",
165    about = "The agent harness language",
166    version,
167    disable_help_subcommand = false,
168    arg_required_else_help = true
169)]
170pub(crate) struct Cli {
171    #[command(subcommand)]
172    pub command: Option<Command>,
173}
174
175#[derive(Debug, Subcommand)]
176pub(crate) enum Command {
177    /// Execute a .harn file or an inline expression.
178    #[command(long_about = "\
179Execute a .harn file or an inline expression.
180
181USAGE
182    harn run script.harn
183    harn run -e 'println(\"hello\")'
184    harn run script.harn -- arg1 arg2   (script reads `argv` as list<string>)
185
186CONCURRENCY
187    Harn supports first-class concurrency primitives:
188      - spawn { ... }         — launch a task, return a handle
189      - parallel each LIST    — concurrent map
190      - parallel settle LIST  — concurrent map, collect Ok/Err
191      - parallel N            — N-way fan-out
192      - with { max_concurrent: N }  — cap in-flight workers
193      - channels, retry, select
194    https://harnlang.com/concurrency.html
195
196LLM THROTTLING
197    Providers can be rate-limited via `rpm:` in harn.toml / providers.toml
198    or via `HARN_RATE_LIMIT_<PROVIDER>=N`. Rate limits control throughput
199    (RPM); `max_concurrent` on `parallel` caps simultaneous in-flight jobs.
200
201SCRIPTING
202    LLM-readable one-pager: https://harnlang.com/docs/llm/harn-quickref.html
203    Human cheatsheet:       https://harnlang.com/scripting-cheatsheet.html
204    Full docs:              https://harnlang.com/
205")]
206    Run(RunArgs),
207    /// Type-check .harn files or directories without executing them.
208    Check(CheckArgs),
209    /// Explain the control-flow path that violates a Harn invariant
210    /// (e.g. `fs.writes`, `approval.reachability`) for a specific
211    /// function or trigger handler.
212    Explain(ExplainArgs),
213    /// Export machine-readable Harn contracts and bundle manifests.
214    Contracts(ContractsArgs),
215    /// Lint .harn files or directories for common issues.
216    Lint(PathTargetsArgs),
217    /// Format .harn files or directories.
218    Fmt(FmtArgs),
219    /// Run user tests or the conformance suite.
220    Test(TestArgs),
221    /// Run a .harn script under a hermetic testbench (paused clock,
222    /// optional LLM/process tapes, fs overlay, deny-by-default network).
223    #[command(name = "test-bench")]
224    TestBench(TestBenchArgs),
225    /// Scaffold a new project with harn.toml.
226    Init(InitArgs),
227    /// Scaffold a new project, package, or connector from a starter template.
228    New(NewArgs),
229    /// Diagnose the local Harn environment: toolchain version, configured
230    /// LLM providers and credentials, MCP server reachability, file
231    /// permissions on `~/.harn`, and project manifest health. Reports
232    /// each check as ok/warn/fail with a suggested fix.
233    Doctor(DoctorArgs),
234    /// Configure a starter Harn project and LLM provider settings.
235    Quickstart(QuickstartArgs),
236    /// Register outbound connector resources with a provider.
237    Connect(Box<ConnectArgs>),
238    /// Validate pure-Harn connector packages against the connector contract.
239    Connector(ConnectorArgs),
240    /// Serve a Harn workflow over a transport adapter.
241    Serve(ServeArgs),
242    /// Manage remote MCP OAuth credentials and status.
243    Mcp(McpArgs),
244    /// Watch a .harn file and re-run it on changes.
245    Watch(WatchArgs),
246    /// Launch the local Harn observability portal.
247    Portal(PortalArgs),
248    /// Replay and inspect historical trigger dispatches from the event log.
249    Trigger(TriggerArgs),
250    /// Inspect Harn Flow atom, slice, and predicate audit state.
251    Flow(FlowArgs),
252    /// Validate, preview, and run portable workflow bundles.
253    Workflow(WorkflowArgs),
254    /// Control local durable workflow automations for trusted hosts.
255    Supervisor(SupervisorArgs),
256    /// Import third-party eval traces into replayable Harn fixtures.
257    Trace(TraceArgs),
258    /// Mine repeated traces into a reviewable deterministic Harn workflow candidate.
259    Crystallize(CrystallizeArgs),
260    /// Query and manage trust-graph autonomy state.
261    Trust(TrustArgs),
262    /// Alias for `harn trust`. Query and verify trust-graph autonomy state.
263    #[command(name = "trust-graph")]
264    TrustGraph(TrustArgs),
265    /// Verify a signed Harn provenance receipt.
266    Verify(VerifyArgs),
267    /// Print shell completion script to stdout.
268    Completions(CompletionsArgs),
269    /// Start the orchestrator process that hosts triggers and connector dispatch.
270    Orchestrator(OrchestratorArgs),
271    /// Run a pipeline against a Harn-native host module for fast iteration.
272    Playground(PlaygroundArgs),
273    /// Inspect persisted workflow run records.
274    Runs(RunsArgs),
275    /// Replay a persisted workflow run record.
276    Replay(ReplayArgs),
277    /// Evaluate a run record, run directory, or eval manifest.
278    Eval(EvalArgs),
279    /// Start the interactive REPL.
280    Repl,
281    /// Benchmark a .harn pipeline over repeated runs.
282    Bench(BenchArgs),
283    /// Render a .harn file as a Mermaid workflow graph.
284    Viz(VizArgs),
285    /// Install dependencies declared in harn.toml.
286    Install(InstallArgs),
287    /// Add a dependency to harn.toml.
288    Add(AddArgs),
289    /// Refresh one or more dependency lock entries.
290    Update(UpdateArgs),
291    /// Remove a dependency from harn.toml and harn.lock.
292    Remove(RemoveArgs),
293    /// Resolve dependencies and write harn.lock without materializing packages.
294    Lock,
295    /// Manage Harn package caches and integrity verification.
296    Package(PackageArgs),
297    /// Prepare a package manifest and bundle for publication. Validates
298    /// `harn.toml` and produces a publishable archive locally; remote
299    /// registry submission is not yet implemented (the resulting
300    /// archive can be installed via `harn add <repo-or-path>` in the
301    /// meantime).
302    Publish(PublishArgs),
303    /// List and inspect durable agent persona manifests.
304    Persona(PersonaArgs),
305    /// Merge Captain transcript oracle and audit (#1013).
306    #[command(name = "merge-captain")]
307    MergeCaptain(MergeCaptainArgs),
308    /// Print resolved metadata for a model alias or model id as JSON.
309    ModelInfo(ModelInfoArgs),
310    /// List, install, recommend, and test configured LLM models.
311    Models(ModelsArgs),
312    /// Print the provider/model catalog Harn loaded as JSON.
313    ProviderCatalog(ProviderCatalogArgs),
314    /// Probe a provider's /models endpoint and optionally verify a served model.
315    ProviderReady(ProviderReadyArgs),
316    /// One-shot agent_loop with a prompt. Routes through the configured
317    /// provider (or `HARN_LLM_PROVIDER=mock` for offline use).
318    #[command(name = "try")]
319    Try(TryArgs),
320    /// Manage and inspect Harn skills (list, inspect, match, install, new).
321    Skills(SkillsArgs),
322    /// Manage skill provenance: keys, signatures, verification, and trust policy.
323    Skill(SkillArgs),
324    /// Print the decorated version banner.
325    Version,
326    /// Regenerate docs/theme/harn-keywords.js from the live lexer + stdlib sets.
327    ///
328    /// Dev-only. Hidden from `--help` — invoke via
329    /// `cargo run -p harn-cli -- dump-highlight-keywords` or the
330    /// `make gen-highlight` target.
331    #[command(hide = true, name = "dump-highlight-keywords")]
332    DumpHighlightKeywords(DumpHighlightKeywordsArgs),
333    /// Regenerate docs/llm/harn-triggers-quickref.md from the live trigger provider catalog.
334    ///
335    /// Dev-only. Hidden from `--help` — invoke via
336    /// `cargo run -p harn-cli -- dump-trigger-quickref` or the
337    /// `make gen-trigger-quickref` target.
338    #[command(hide = true, name = "dump-trigger-quickref")]
339    DumpTriggerQuickref(DumpTriggerQuickrefArgs),
340    /// Regenerate docs/src/connectors/parity-matrix.md from connector package manifests.
341    ///
342    /// Dev-only. Hidden from `--help` — invoke via
343    /// `cargo run -p harn-cli -- dump-connector-matrix` or the
344    /// `make gen-connector-matrix` target.
345    #[command(hide = true, name = "dump-connector-matrix")]
346    DumpConnectorMatrix(DumpConnectorMatrixArgs),
347    /// Regenerate Harn protocol schemas and TypeScript/Swift bindings.
348    ///
349    /// Dev-only. Hidden from `--help` — invoke via
350    /// `cargo run -p harn-cli -- dump-protocol-artifacts` or the
351    /// `make gen-protocol-artifacts` target.
352    #[command(hide = true, name = "dump-protocol-artifacts")]
353    DumpProtocolArtifacts(DumpProtocolArtifactsArgs),
354}
355
356#[cfg(test)]
357mod tests;