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) uses the
50    /// embedded skim picker and falls back to external `fzf` only when
51    /// skim isn't compiled in; a hint is printed if `fzf` is also on
52    /// PATH. `fzf`/`skim` force one backend and error if it isn't
53    /// available.
54    #[cfg(not(target_os = "emscripten"))]
55    #[arg(long, global = true, value_enum, default_value_t = fuzzy::Picker::Auto)]
56    picker: fuzzy::Picker,
57}
58
59#[derive(Subcommand, Debug)]
60enum Commands {
61    /// Show a single session as a markdown summary (used by fzf preview)
62    #[cfg(not(target_os = "emscripten"))]
63    Show {
64        #[command(subcommand)]
65        source: cmd_show::ShowSource,
66        /// Emit ANSI-styled terminal output instead of raw markdown
67        /// (bold speakers, dim metadata, colored diffs). Used by the
68        /// fzf preview panes.
69        #[arg(long)]
70        ansi: bool,
71    },
72    /// Share an agent session to Pathbase via an interactive picker
73    #[cfg(not(target_os = "emscripten"))]
74    Share {
75        #[command(flatten)]
76        args: cmd_share::ShareArgs,
77    },
78    /// Resume an agent session into the chosen harness, projecting the
79    /// document and exec'ing the harness's resume command.
80    #[cfg(not(target_os = "emscripten"))]
81    Resume {
82        #[command(flatten)]
83        args: cmd_resume::ResumeArgs,
84    },
85    /// Query Toolpath documents
86    Query {
87        #[command(subcommand)]
88        op: cmd_query::QueryOp,
89    },
90    /// Manage Pathbase credentials for trace uploads
91    #[cfg(not(target_os = "emscripten"))]
92    Auth {
93        #[command(subcommand)]
94        op: cmd_auth::AuthOp,
95    },
96    /// Plumbing: lower-level operations on documents and sources
97    /// (import, export, cache, list, render, merge, validate, derive,
98    /// project, incept, track)
99    P {
100        #[command(subcommand)]
101        command: cmd_p::PCommand,
102    },
103    /// Print a random Toolpath haiku
104    Haiku,
105}
106
107pub fn run() -> Result<()> {
108    let cli = Cli::parse();
109
110    #[cfg(not(target_os = "emscripten"))]
111    fuzzy::set_picker_override(cli.picker);
112
113    match cli.command {
114        Commands::Haiku => {
115            cmd_haiku::run();
116            Ok(())
117        }
118        #[cfg(not(target_os = "emscripten"))]
119        Commands::Show { source, ansi } => cmd_show::run(source, ansi),
120        #[cfg(not(target_os = "emscripten"))]
121        Commands::Share { args } => cmd_share::run(args),
122        #[cfg(not(target_os = "emscripten"))]
123        Commands::Resume { args } => cmd_resume::run(args),
124        Commands::Query { op } => cmd_query::run(op, cli.pretty),
125        #[cfg(not(target_os = "emscripten"))]
126        Commands::Auth { op } => cmd_auth::run(op),
127        Commands::P { command } => cmd_p::run(command, cli.pretty),
128    }
129}