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