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