Skip to main content

path_cli/
lib.rs

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