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, PackageArtifactsCommand, PackageCacheCommand,
109    PackageCommand, PublishArgs, 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, TestBenchExportAnnotationsArgs, TestBenchFidelityArgs,
144    TestBenchReplayArgs, TestBenchRunArgs, TestBenchValidateAnnotationsArgs,
145};
146pub(crate) use trace::{TraceArgs, TraceCommand, TraceImportArgs};
147pub(crate) use trigger::{TriggerArgs, TriggerCancelArgs, TriggerCommand, TriggerReplayArgs};
148pub(crate) use try_cmd::TryArgs;
149// `TrustOutcomeArg` / `TrustTierArg` are referenced from the cli
150// parser tests only; they're matched via destructuring elsewhere.
151#[allow(unused_imports)]
152pub(crate) use trust::{
153    TrustArgs, TrustCommand, TrustExportArgs, TrustOutcomeArg, TrustQueryArgs, TrustTierArg,
154    TrustVerifyChainArgs,
155};
156pub(crate) use verify::VerifyArgs;
157pub(crate) use viz::VizArgs;
158pub(crate) use watch::WatchArgs;
159pub(crate) use workflow::{
160    WorkflowArgs, WorkflowCommand, WorkflowFunctionToolsArgs, WorkflowNestedCeilingArgs,
161    WorkflowPatchApplyArgs, WorkflowPatchCommand, WorkflowPatchPreviewArgs,
162    WorkflowPatchValidateArgs,
163};
164
165use clap::{Parser, Subcommand};
166
167#[derive(Debug, Parser)]
168#[command(
169    name = "harn",
170    about = "The agent harness language",
171    version,
172    disable_help_subcommand = false,
173    arg_required_else_help = true
174)]
175pub(crate) struct Cli {
176    #[command(subcommand)]
177    pub command: Option<Command>,
178}
179
180#[derive(Debug, Subcommand)]
181pub(crate) enum Command {
182    /// Execute a .harn file or an inline expression.
183    #[command(long_about = "\
184Execute a .harn file or an inline expression.
185
186USAGE
187    harn run script.harn
188    harn run -e 'println(\"hello\")'
189    harn run script.harn -- arg1 arg2   (script reads `argv` as list<string>)
190
191CONCURRENCY
192    Harn supports first-class concurrency primitives:
193      - spawn { ... }         — launch a task, return a handle
194      - parallel each LIST    — concurrent map
195      - parallel settle LIST  — concurrent map, collect Ok/Err
196      - parallel N            — N-way fan-out
197      - with { max_concurrent: N }  — cap in-flight workers
198      - channels, retry, select
199    https://harnlang.com/concurrency.html
200
201LLM THROTTLING
202    Providers can be rate-limited via `rpm:` in harn.toml / providers.toml
203    or via `HARN_RATE_LIMIT_<PROVIDER>=N`. Rate limits control throughput
204    (RPM); `max_concurrent` on `parallel` caps simultaneous in-flight jobs.
205
206SCRIPTING
207    LLM-readable one-pager: https://harnlang.com/docs/llm/harn-quickref.html
208    Human cheatsheet:       https://harnlang.com/scripting-cheatsheet.html
209    Full docs:              https://harnlang.com/
210")]
211    Run(RunArgs),
212    /// Type-check .harn files or directories without executing them.
213    Check(CheckArgs),
214    /// Explain the control-flow path that violates a Harn invariant
215    /// (e.g. `fs.writes`, `approval.reachability`) for a specific
216    /// function or trigger handler.
217    Explain(ExplainArgs),
218    /// Export machine-readable Harn contracts and bundle manifests.
219    Contracts(ContractsArgs),
220    /// Lint .harn files or directories for common issues.
221    Lint(PathTargetsArgs),
222    /// Format .harn files or directories.
223    Fmt(FmtArgs),
224    /// Run user tests or the conformance suite.
225    Test(TestArgs),
226    /// Run a .harn script under a hermetic testbench (paused clock,
227    /// optional LLM/process tapes, fs overlay, deny-by-default network).
228    #[command(name = "test-bench")]
229    TestBench(TestBenchArgs),
230    /// Scaffold a new project with harn.toml.
231    Init(InitArgs),
232    /// Scaffold a new project, package, or connector from a starter template.
233    New(NewArgs),
234    /// Diagnose the local Harn environment: toolchain version, configured
235    /// LLM providers and credentials, MCP server reachability, file
236    /// permissions on `~/.harn`, and project manifest health. Reports
237    /// each check as ok/warn/fail with a suggested fix.
238    Doctor(DoctorArgs),
239    /// Configure a starter Harn project and LLM provider settings.
240    Quickstart(QuickstartArgs),
241    /// Register outbound connector resources with a provider.
242    Connect(Box<ConnectArgs>),
243    /// Validate pure-Harn connector packages against the connector contract.
244    Connector(ConnectorArgs),
245    /// Serve a Harn workflow over a transport adapter.
246    Serve(ServeArgs),
247    /// Manage remote MCP OAuth credentials and status.
248    Mcp(McpArgs),
249    /// Watch a .harn file and re-run it on changes.
250    Watch(WatchArgs),
251    /// Launch the local Harn observability portal.
252    Portal(PortalArgs),
253    /// Replay and inspect historical trigger dispatches from the event log.
254    Trigger(TriggerArgs),
255    /// Inspect Harn Flow atom, slice, and predicate audit state.
256    Flow(FlowArgs),
257    /// Validate, preview, and run portable workflow bundles.
258    Workflow(WorkflowArgs),
259    /// Control local durable workflow automations for trusted hosts.
260    Supervisor(SupervisorArgs),
261    /// Import third-party eval traces into replayable Harn fixtures.
262    Trace(TraceArgs),
263    /// Mine repeated traces into a reviewable deterministic Harn workflow candidate.
264    Crystallize(CrystallizeArgs),
265    /// Query and manage trust-graph autonomy state.
266    Trust(TrustArgs),
267    /// Alias for `harn trust`. Query and verify trust-graph autonomy state.
268    #[command(name = "trust-graph")]
269    TrustGraph(TrustArgs),
270    /// Verify a signed Harn provenance receipt.
271    Verify(VerifyArgs),
272    /// Print shell completion script to stdout.
273    Completions(CompletionsArgs),
274    /// Start the orchestrator process that hosts triggers and connector dispatch.
275    Orchestrator(OrchestratorArgs),
276    /// Run a pipeline against a Harn-native host module for fast iteration.
277    Playground(PlaygroundArgs),
278    /// Inspect persisted workflow run records.
279    Runs(RunsArgs),
280    /// Replay a persisted workflow run record.
281    Replay(ReplayArgs),
282    /// Evaluate a run record, run directory, or eval manifest.
283    Eval(EvalArgs),
284    /// Start the interactive REPL.
285    Repl,
286    /// Benchmark a .harn pipeline over repeated runs.
287    Bench(BenchArgs),
288    /// Render a .harn file as a Mermaid workflow graph.
289    Viz(VizArgs),
290    /// Install dependencies declared in harn.toml.
291    Install(InstallArgs),
292    /// Add a dependency to harn.toml.
293    Add(AddArgs),
294    /// Refresh one or more dependency lock entries.
295    Update(UpdateArgs),
296    /// Remove a dependency from harn.toml and harn.lock.
297    Remove(RemoveArgs),
298    /// Resolve dependencies and write harn.lock without materializing packages.
299    Lock,
300    /// Manage Harn package caches and integrity verification.
301    Package(PackageArgs),
302    /// Prepare a package manifest and bundle for publication. Validates
303    /// `harn.toml` and produces a publishable archive locally; remote
304    /// registry submission is not yet implemented (the resulting
305    /// archive can be installed via `harn add <repo-or-path>` in the
306    /// meantime).
307    Publish(PublishArgs),
308    /// List and inspect durable agent persona manifests.
309    Persona(PersonaArgs),
310    /// Merge Captain transcript oracle and audit (#1013).
311    #[command(name = "merge-captain")]
312    MergeCaptain(MergeCaptainArgs),
313    /// Print resolved metadata for a model alias or model id as JSON.
314    ModelInfo(ModelInfoArgs),
315    /// List, install, recommend, and test configured LLM models.
316    Models(ModelsArgs),
317    /// Print the provider/model catalog Harn loaded as JSON.
318    ProviderCatalog(ProviderCatalogArgs),
319    /// Probe a provider's /models endpoint and optionally verify a served model.
320    ProviderReady(ProviderReadyArgs),
321    /// One-shot agent_loop with a prompt. Routes through the configured
322    /// provider (or `HARN_LLM_PROVIDER=mock` for offline use).
323    #[command(name = "try")]
324    Try(TryArgs),
325    /// Manage and inspect Harn skills (list, inspect, match, install, new).
326    Skills(SkillsArgs),
327    /// Manage skill provenance: keys, signatures, verification, and trust policy.
328    Skill(SkillArgs),
329    /// Print the decorated version banner.
330    Version,
331    /// Regenerate docs/theme/harn-keywords.js from the live lexer + stdlib sets.
332    ///
333    /// Dev-only. Hidden from `--help` — invoke via
334    /// `cargo run -p harn-cli -- dump-highlight-keywords` or the
335    /// `make gen-highlight` target.
336    #[command(hide = true, name = "dump-highlight-keywords")]
337    DumpHighlightKeywords(DumpHighlightKeywordsArgs),
338    /// Regenerate docs/llm/harn-triggers-quickref.md from the live trigger provider catalog.
339    ///
340    /// Dev-only. Hidden from `--help` — invoke via
341    /// `cargo run -p harn-cli -- dump-trigger-quickref` or the
342    /// `make gen-trigger-quickref` target.
343    #[command(hide = true, name = "dump-trigger-quickref")]
344    DumpTriggerQuickref(DumpTriggerQuickrefArgs),
345    /// Regenerate docs/src/connectors/parity-matrix.md from connector package manifests.
346    ///
347    /// Dev-only. Hidden from `--help` — invoke via
348    /// `cargo run -p harn-cli -- dump-connector-matrix` or the
349    /// `make gen-connector-matrix` target.
350    #[command(hide = true, name = "dump-connector-matrix")]
351    DumpConnectorMatrix(DumpConnectorMatrixArgs),
352    /// Regenerate Harn protocol schemas and TypeScript/Swift bindings.
353    ///
354    /// Dev-only. Hidden from `--help` — invoke via
355    /// `cargo run -p harn-cli -- dump-protocol-artifacts` or the
356    /// `make gen-protocol-artifacts` target.
357    #[command(hide = true, name = "dump-protocol-artifacts")]
358    DumpProtocolArtifacts(DumpProtocolArtifactsArgs),
359}
360
361#[cfg(test)]
362mod tests;