mod agent;
mod check;
mod codegen;
mod doctor;
mod forge;
mod gate;
mod hub;
mod logo;
mod mcp;
mod names;
mod proc;
mod publish;
mod render;
mod scaffold;
mod show;
mod spec;
mod stack;
mod state;
mod task;
mod templates;
mod ui;
mod util;
use anyhow::{Result, bail};
use clap::{Args, Parser, Subcommand};
use spec::Spec;
use std::path::{Path, PathBuf};
use std::process::ExitCode;
use std::time::Duration;
#[derive(Parser)]
#[command(name = "anything-anything", version, about, arg_required_else_help = true)]
#[command(
after_help = "One command:\n anything-anything new translate \"translate any app's UI strings to any language\" --agent claude\n\nStep by step:\n anything-anything new translate \"...\" --stack python-cli (no agent: write anything.toml yourself)\n anything-anything build --agent claude\n anything-anything verify\n anything-anything publish"
)]
struct Cli {
#[arg(short = 'C', long = "dir", global = true, default_value = ".")]
dir: PathBuf,
#[command(subcommand)]
cmd: Cmd,
}
#[derive(Args, Clone)]
struct AgentArgs {
#[arg(long)]
agent: Option<String>,
#[arg(long, default_value_t = 3)]
attempts: usize,
#[arg(long, default_value_t = 60)]
minutes: u64,
}
impl AgentArgs {
fn opts(&self) -> Option<forge::AgentOpts> {
self.agent.clone().map(|agent| forge::AgentOpts {
agent,
attempts: self.attempts.max(1),
timeout: Duration::from_secs(self.minutes.max(1) * 60),
})
}
fn need(&self) -> Result<forge::AgentOpts> {
match self.opts() {
Some(o) => Ok(o),
None => bail!(
"which agent? --agent claude, --agent codex, or --agent \"any command that reads a prompt on stdin\""
),
}
}
}
#[derive(Subcommand, Clone)]
enum HubCmd {
Top {
#[arg(long, default_value_t = 25)]
limit: usize,
#[arg(long)]
offline: bool,
},
Search {
#[arg(required = true)]
words: Vec<String>,
#[arg(long, default_value_t = 25)]
limit: usize,
#[arg(long)]
offline: bool,
},
Made {
#[arg(long, default_value_t = 50)]
limit: usize,
},
Show { repo: String },
Install {
repo: String,
#[arg(long)]
yes: bool,
},
}
#[derive(Subcommand, Clone)]
enum Cmd {
New {
what: String,
idea: Vec<String>,
#[arg(long)]
stack: Option<String>,
#[arg(long)]
spec: Option<PathBuf>,
#[arg(long)]
out: Option<PathBuf>,
#[arg(long)]
no_build: bool,
#[arg(long)]
owner: Option<String>,
#[arg(long)]
npm: Option<String>,
#[arg(long)]
color: Option<String>,
#[arg(long)]
no_git: bool,
#[command(flatten)]
agent: AgentArgs,
},
Design {
idea: Vec<String>,
#[command(flatten)]
agent: AgentArgs,
},
Build {
#[command(flatten)]
agent: AgentArgs,
},
Task,
Sync {
#[arg(long)]
check: bool,
},
Verify {
#[arg(long)]
json: bool,
},
Status,
Spec,
Stacks,
Hub {
#[command(subcommand)]
cmd: Option<HubCmd>,
},
Publish {
#[arg(long)]
yes: bool,
#[arg(long)]
private: bool,
},
Doctor,
Mcp,
}
fn main() -> ExitCode {
let cli = Cli::parse();
let root = util::absolute(&cli.dir);
match run(cli.cmd, &root) {
Ok(true) => ExitCode::SUCCESS,
Ok(false) => ExitCode::FAILURE,
Err(e) => {
ui::error(format!("{e:#}"));
ExitCode::FAILURE
}
}
}
fn finish(report: &gate::Report, root: &Path) -> bool {
show::report(report);
if report.ok {
ui::next(format!("anything-anything -C {} publish", root.display()));
}
report.ok
}
fn run(cmd: Cmd, root: &Path) -> Result<bool> {
match cmd {
Cmd::Mcp => return mcp::serve().map(|()| true),
Cmd::Spec => {
println!("{}", spec::REFERENCE);
return Ok(true);
}
Cmd::Verify { json: true } => {
ui::set_quiet(true);
let r = gate::verify(root)?;
println!("{}", serde_json::to_string_pretty(&r)?);
return Ok(r.ok);
}
_ => {}
}
ui::banner();
match cmd {
Cmd::New { what, idea, stack, spec, out, no_build, owner, npm, color, no_git, agent } => {
let opts = forge::NewOpts {
what,
idea: idea.join(" "),
stack,
spec,
out,
owner,
npm,
color,
git: !no_git,
agent: agent.opts(),
build: !no_build,
};
let has_agent = opts.agent.is_some();
let (dir, report) = forge::create(root, opts)?;
match report {
Some(r) => Ok(finish(&r, &dir)),
None => {
let spec = Spec::load(&dir)?;
let problems = spec.problems(&stack::load(&spec)?);
if problems.is_empty() {
forge::write_task(&dir, &[])?;
ui::ok("ready to build: .anything/TASK.md says what");
ui::next(format!("anything-anything -C {} build --agent claude", dir.display()));
} else {
ui::line(format!(" {} to finish in {}:", ui::bold("the spec"), spec::FILE));
for p in &problems {
ui::line(format!(" {} {p}", ui::dim("·")));
}
ui::next(if has_agent {
format!("anything-anything -C {} design --agent claude", dir.display())
} else {
format!(
"edit {}, or: anything-anything -C {} design --agent claude",
dir.join(spec::FILE).display(),
dir.display()
)
});
}
Ok(true)
}
}
}
Cmd::Design { idea, agent } => {
let spec = Spec::load(root)?;
forge::design(
root,
&idea.join(" "),
Some(&spec.stack).filter(|s| *s != "any").map(|s| s.as_str()),
&agent.need()?,
)?;
show::synced(&scaffold::sync(root, &Spec::load(root)?, false)?);
ui::next("anything-anything build --agent claude");
Ok(true)
}
Cmd::Build { agent } => {
let r = forge::build(root, &agent.need()?)?;
Ok(finish(&r, root))
}
Cmd::Task => {
let p = forge::write_task(root, &[])?;
ui::ok(format!("wrote {}: hand it to your agent, then run anything-anything verify", p.display()));
Ok(true)
}
Cmd::Sync { check } => {
let spec = Spec::load(root)?;
let s = scaffold::sync(root, &spec, check)?;
show::synced(&s);
Ok(!check || (s.created.is_empty() && s.updated.is_empty()))
}
Cmd::Verify { .. } => {
let r = gate::verify(root)?;
Ok(finish(&r, root))
}
Cmd::Status => {
show::status(&Spec::load(root)?, &state::load(root));
Ok(true)
}
Cmd::Stacks => {
for (id, about) in stack::all() {
ui::line(format!(" {} {id:<11} {}", ui::brand("•"), about));
}
Ok(true)
}
Cmd::Hub { cmd } => {
match cmd.unwrap_or(HubCmd::Top { limit: 25, offline: false }) {
HubCmd::Top { limit, offline } => show::tools(&hub::list("", limit, offline)),
HubCmd::Search { words, limit, offline } => show::tools(&hub::list(&words.join(" "), limit, offline)),
HubCmd::Made { limit } => show::tools(&hub::Listing { tools: hub::made(limit)?, offline: None }),
HubCmd::Show { repo } => {
let (t, w) = hub::show(&repo)?;
show::ways(&t, &w);
}
HubCmd::Install { repo, yes } => hub::install(&repo, yes)?,
}
Ok(true)
}
Cmd::Publish { yes, private } => {
publish::run(root, yes, private)?;
Ok(true)
}
Cmd::Doctor => {
doctor::run()?;
Ok(true)
}
Cmd::Mcp | Cmd::Spec => unreachable!(),
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn the_command_line() {
let cli = Cli::try_parse_from([
"anything-anything",
"new",
"translate",
"translate",
"any",
"app",
"--agent",
"claude",
"--stack",
"web",
])
.unwrap();
let Cmd::New { what, idea, stack, agent, .. } = cli.cmd else { panic!("not new") };
assert_eq!(
(what.as_str(), idea.join(" ").as_str(), stack.as_deref()),
("translate", "translate any app", Some("web"))
);
assert_eq!(agent.opts().unwrap().attempts, 3);
assert!(Cli::try_parse_from(["anything-anything", "hub", "search"]).is_err());
assert!(matches!(
Cli::try_parse_from(["anything-anything", "-C", "x", "verify", "--json"]).unwrap().cmd,
Cmd::Verify { json: true }
));
}
}