Skip to main content

path_cli/
lib.rs

1pub mod artifact;
2mod cache;
3#[cfg(not(target_os = "emscripten"))]
4mod cmd_auth;
5mod cmd_cache;
6mod cmd_derive;
7mod cmd_export;
8mod cmd_haiku;
9mod cmd_import;
10mod cmd_incept;
11mod cmd_kind;
12mod cmd_list;
13mod cmd_merge;
14mod cmd_p;
15mod cmd_p_query;
16#[cfg(not(target_os = "emscripten"))]
17mod cmd_pathbase;
18mod cmd_project;
19mod cmd_query;
20mod cmd_render;
21#[cfg(not(target_os = "emscripten"))]
22pub mod cmd_resume;
23#[cfg(not(target_os = "emscripten"))]
24mod cmd_share;
25#[cfg(not(target_os = "emscripten"))]
26mod cmd_show;
27mod cmd_track;
28mod cmd_validate;
29mod config;
30mod derive;
31#[cfg(not(target_os = "emscripten"))]
32mod fuzzy;
33#[cfg(not(target_os = "emscripten"))]
34pub mod harness;
35mod io;
36mod kinds;
37mod query;
38mod schema;
39#[cfg(all(not(target_os = "emscripten"), feature = "embedded-picker"))]
40mod skim_picker;
41mod sync;
42mod term;
43
44use anyhow::Result;
45use clap::{Parser, Subcommand};
46
47#[derive(Parser, Debug)]
48#[command(name = "path", version)]
49#[command(about = "Derive, query, and visualize Toolpath provenance documents")]
50struct Cli {
51    #[command(subcommand)]
52    command: Commands,
53
54    /// Pretty-print JSON output
55    #[arg(long, global = true)]
56    pretty: bool,
57
58    /// Backend for the interactive fuzzy picker used by `share`,
59    /// `resume`, and `p import <provider>`. `auto` (default) uses the
60    /// embedded skim picker and falls back to external `fzf` only when
61    /// skim isn't compiled in; a hint is printed if `fzf` is also on
62    /// PATH. `fzf`/`skim` force one backend and error if it isn't
63    /// available.
64    #[cfg(not(target_os = "emscripten"))]
65    #[arg(long, global = true, value_enum, default_value_t = fuzzy::Picker::Auto)]
66    picker: fuzzy::Picker,
67}
68
69#[derive(Subcommand, Debug)]
70enum Commands {
71    /// Show a single session as a markdown summary (used by fzf preview)
72    #[cfg(not(target_os = "emscripten"))]
73    Show {
74        #[command(subcommand)]
75        source: cmd_show::ShowSource,
76        /// Emit ANSI-styled terminal output instead of raw markdown
77        /// (bold speakers, dim metadata, colored diffs). Used by the
78        /// fzf preview panes.
79        #[arg(long)]
80        ansi: bool,
81    },
82    /// Share an agent session to Pathbase via an interactive picker
83    #[cfg(not(target_os = "emscripten"))]
84    Share {
85        #[command(flatten)]
86        args: cmd_share::ShareArgs,
87    },
88    /// Resume an agent session into the chosen harness, projecting the
89    /// document and exec'ing the harness's resume command.
90    #[cfg(not(target_os = "emscripten"))]
91    Resume {
92        #[command(flatten)]
93        args: cmd_resume::ResumeArgs,
94    },
95    /// Query the local cache: load every step into one JSON array and
96    /// transform it with a jaq (jq) filter
97    Query {
98        #[command(flatten)]
99        args: cmd_query::QueryArgs,
100    },
101    /// List bundled document kinds, or print a kind's schema (the field
102    /// reference for `path query`)
103    Kind {
104        #[command(flatten)]
105        args: cmd_kind::KindArgs,
106    },
107    /// Manage Pathbase credentials for trace uploads
108    #[cfg(not(target_os = "emscripten"))]
109    Auth {
110        #[command(subcommand)]
111        op: cmd_auth::AuthOp,
112    },
113    /// Plumbing: lower-level operations on documents and sources
114    /// (import, export, cache, list, render, merge, validate, derive,
115    /// project, incept, track, query)
116    P {
117        #[command(subcommand)]
118        command: cmd_p::PCommand,
119    },
120    /// Print a random Toolpath haiku
121    Haiku,
122}
123
124pub fn run() -> Result<()> {
125    let cli = Cli::parse();
126
127    #[cfg(not(target_os = "emscripten"))]
128    fuzzy::set_picker_override(cli.picker);
129
130    match cli.command {
131        Commands::Haiku => {
132            cmd_haiku::run();
133            Ok(())
134        }
135        #[cfg(not(target_os = "emscripten"))]
136        Commands::Show { source, ansi } => cmd_show::run(source, ansi),
137        #[cfg(not(target_os = "emscripten"))]
138        Commands::Share { args } => cmd_share::run(args),
139        #[cfg(not(target_os = "emscripten"))]
140        Commands::Resume { args } => cmd_resume::run(args),
141        Commands::Query { args } => cmd_query::run(args, cli.pretty),
142        Commands::Kind { args } => cmd_kind::run(args),
143        #[cfg(not(target_os = "emscripten"))]
144        Commands::Auth { op } => cmd_auth::run(op),
145        Commands::P { command } => cmd_p::run(command, cli.pretty),
146    }
147}