mod account;
mod cache;
use cache::CacheCommand;
mod config;
use config::ConfigCommand;
#[cfg(test)]
#[path = "cli/tests/defaults.rs"]
mod defaults_tests;
mod dispatch;
mod follow;
use follow::Follow;
mod graph;
#[cfg(test)]
#[path = "cli/tests/identity.rs"]
mod identity_tests;
mod interactive;
mod maintenance;
#[cfg(test)]
#[path = "cli/tests/monitor.rs"]
mod monitor_tests;
mod plugin;
mod provider;
mod remote;
mod render;
mod run;
use run::RunCommand;
mod runtime;
use runtime::cancellation_listener;
pub use runtime::run;
mod secret;
mod selection;
use selection::SelectionArgs;
mod status;
mod tools;
use tools::ToolsCommand;
mod workflow;
use dispatch::Context;
use render::{outcome_code, print_json};
mod request;
mod server;
mod session;
use request::RequestCommand;
use server::ServerCommand;
use session::SessionCommand;
use std::{num::NonZeroU32, path::PathBuf};
use clap::{Args, Parser, Subcommand};
use artifactize_core::{
config::ProfileKind,
types::{RequestId, RunId},
};
const INTERRUPTED_EXIT: u8 = 130;
const FAILURE_EXIT: u8 = 2;
#[derive(Debug, Parser)]
#[command(
name = "artifactize",
// Help names the command, not the file run; on Windows that is artifactize.exe.
bin_name = "artifactize",
version,
about = "The AI-native collaboration layer for one-of-a-kind teammates and their agents."
)]
pub struct Cli {
#[arg(long, global = true, value_name = "PATH")]
pub repo: Option<PathBuf>,
#[arg(long, global = true, value_name = "PATH")]
pub state_dir: Option<PathBuf>,
#[arg(long, global = true)]
pub json: bool,
#[command(subcommand)]
command: Option<CommandArgs>,
}
#[derive(Debug, Subcommand)]
enum CommandArgs {
Monitor {
#[arg(value_name = "PATH", conflicts_with = "repo")]
path: Option<PathBuf>,
#[arg(long, conflicts_with_all = ["path", "repo"])]
all: bool,
},
Review {
#[arg(value_name = "REQUEST_ID")]
request: Option<RequestId>,
#[arg(long)]
all: bool,
#[arg(long, value_name = "NAME")]
reviewer: Option<artifactize_core::types::ReviewerId>,
},
#[command(disable_help_subcommand = true, version)]
Tools {
#[command(subcommand)]
command: ToolsCommand,
},
#[command(flatten)]
General(Command),
}
#[derive(Clone, Debug)]
pub enum Removed {}
fn removed_defer_human(_: &str) -> Result<Removed, String> {
Err("--defer-human was removed in 0.16.0: every verify lets machine work go on while sign-offs wait; remove the flag.".into())
}
#[derive(Debug, Subcommand)]
pub enum Command {
Mcp,
#[command(name = "__verify", hide = true)]
VerifyWorker { run_id: RunId },
#[command(name = "__execute", hide = true)]
VerifyExecution { run_id: RunId },
Login {
#[arg(value_enum)]
provider: account::LoginTarget,
},
Logout {
#[arg(value_enum)]
provider: account::LoginTarget,
},
Provider {
#[command(subcommand)]
command: provider::ProviderCommand,
},
Plugin {
#[command(subcommand)]
command: plugin::PluginCommand,
},
Remote {
#[command(subcommand)]
command: remote::RemoteCommand,
},
Doctor,
Prune {
#[arg(long, value_name = "DURATION", value_parser = artifactize_core::store::prune::parse_duration)]
older_than: Option<std::time::Duration>,
#[arg(long)]
dry_run: bool,
},
Limits {
#[arg(long, value_name = "SECONDS", value_parser = seconds, help = format!(
"Seconds a Run with nothing but unclaimed sign-offs left stays open (0–{}), for the Runs started afterwards.",
artifactize_core::limits::MAX_SIGNOFF_IDLE_GRACE.as_secs()
))]
signoff_idle_grace: Option<std::time::Duration>,
},
Models {
provider: artifactize_core::config::Backend,
},
#[command(group(clap::ArgGroup::new("required_selection")
.args(["artifact", "eval", "evals", "artifacts", "evals_file", "artifacts_file", "all"])
.required(true)))]
Verify {
#[command(flatten)]
selection: SelectionArgs,
#[command(flatten)]
policy: PolicyArgs,
#[arg(long, value_name = "N")]
jobs: Option<NonZeroU32>,
#[arg(long, value_name = "N")]
max_executions: Option<u64>,
#[command(flatten)]
follow: Follow,
#[arg(long, value_name = "KEY", help = format!(
"Retry-safe caller attempt key (1–{} ASCII letters/digits/._:-).",
artifactize_core::types::MAX_REQUEST_KEY_BYTES
))]
request_key: Option<artifactize_core::types::RequestKey>,
#[arg(long, value_name = "TEXT", help = format!(
"A short note on what you are working on, shown with the Run (1–{} characters).",
artifactize_core::types::MAX_RUN_COMMENT_CHARS
))]
comment: Option<artifactize_core::types::RunComment>,
#[arg(long, value_name = "KINDS", value_enum, value_delimiter = ',')]
reuse_only: Vec<ProfileKind>,
#[arg(long)]
speculate: bool,
#[arg(long, hide = true, num_args = 0, default_missing_value = "", value_parser = removed_defer_human)]
defer_human: Option<Removed>,
},
Status {
#[command(flatten)]
selection: SelectionArgs,
#[command(flatten)]
policy: PolicyArgs,
},
#[command(hide = true, disable_help_flag = true)]
Graph {
#[arg(trailing_var_arg = true, allow_hyphen_values = true, hide = true)]
args: Vec<std::ffi::OsString>,
},
Run {
#[command(subcommand)]
command: RunCommand,
},
Request {
#[command(subcommand)]
command: RequestCommand,
},
Session {
#[command(subcommand)]
command: SessionCommand,
},
Cache {
#[command(subcommand)]
command: CacheCommand,
},
Config {
#[command(subcommand)]
command: ConfigCommand,
},
Server {
#[command(subcommand)]
command: ServerCommand,
},
}
#[derive(Debug, Args)]
pub struct PolicyArgs {
#[arg(long)]
recursive: bool,
#[arg(long)]
force: bool,
#[arg(long, value_name = "N")]
fingerprint_jobs: Option<NonZeroU32>,
}
impl PolicyArgs {
fn options(self) -> artifactize_core::project::VerifyOptions {
artifactize_core::project::VerifyOptions {
recursive: self.recursive,
force: self.force,
fingerprint_jobs: self.fingerprint_jobs.map(|jobs| jobs.get() as usize),
..Default::default()
}
}
}
mod argv;
use argv::{Invocation, ParseError, Parsed, parse_args};
fn seconds(text: &str) -> Result<std::time::Duration, String> {
text.parse::<u64>()
.map(std::time::Duration::from_secs)
.map_err(|error| error.to_string())
}