#![allow(dead_code)]
use std::path::{Path, PathBuf};
use tuff_core::bundle::write_source_pack;
use tuff_core::lockfile::{self, PackArtifactSource, PackSource};
use tuff_core::pack::PackArtifact;
use tuff_packs::build::build_as;
use tuff_packs::build::build_for_declared_targets;
use tuff_packs::build::build_for_targets;
use tuff_packs::git::{CheckoutRequest, checkout};
use tuff_packs::git::{GitPackStatus, status};
use tuff_packs::import::source_pack_of;
use tuff_packs::import::{ImportRequest, import};
use tuff_packs::inspect;
use tuff_packs::install::{Approval, apply_approved};
use tuff_packs::install::{UpdateRequest, apply, plan_install, plan_remove, plan_update};
use tuff_packs::marketplace::{MarketplaceBuildOptions, build_marketplace};
use tuff_packs::workspace::{Baselines, Workspace};
fn review(folder: &Path) -> tuff_packs::Result<()> {
let built = build_for_declared_targets(folder)?;
let source = serde_json::json!({ "kind": "folder", "path": folder.display().to_string() });
let document = inspect::document(&built.artifact, &source)?;
for member in &document.members {
println!(
"{} ({:?}) runs code: {}",
member.id, member.capability_type, member.runs_code
);
if let Some(mcp) = &member.mcp {
println!(" needs {:?}", mcp.env);
}
}
for item in document.unsupported {
println!("not carried: {} ({})", item.kind, item.reason);
}
println!("{}", serde_json::to_string(&document)?);
Ok(())
}
fn review_git(url: &str) -> tuff_packs::Result<()> {
let checked_out = checkout(CheckoutRequest {
url,
path: None, git_ref: None, plugin: None, allow_remote: false, })?;
let pack = source_pack_of(&checked_out)?;
let built = build_for_declared_targets(&pack.root)?;
let mut source = serde_json::to_value(&checked_out.source)?;
source["kind"] = "git".into();
let document = inspect::document(&built.artifact, &source)?;
println!("{} at {}", document.version, checked_out.source.git_ref);
for note in pack.notes.iter().chain(&built.notes) {
println!("note: {note}");
}
Ok(())
}
fn check(project: &Path) -> tuff_packs::Result<()> {
let lock = lockfile::require_lockfile(project)?;
for (name, pack) in lock.normalized_packs() {
let PackSource::Git(git) = &pack.source else {
continue;
};
match status(&name, &pack.version, git)?.0 {
GitPackStatus::Newer { version, .. } => println!("{name}: {version} is available"),
GitPackStatus::Repointed { .. } => {
println!("{name}: its tag moved; review before updating")
}
GitPackStatus::TagMissing => println!("{name}: its tag was deleted"),
GitPackStatus::BranchMoved { commit } => println!("{name}: branch moved to {commit}"),
GitPackStatus::Current | GitPackStatus::Pinned => {}
}
}
Ok(())
}
fn convert(plugin: &str, output: &Path) -> tuff_packs::Result<()> {
let imported = import(ImportRequest {
source: plugin, plugin: None, git_ref: None,
path: None,
})?;
for item in imported.unsupported() {
println!("not carried: {} {}", item.kind, item.reason);
}
write_source_pack(output, &imported)
}
fn publish(packs: &[PathBuf], output: &Path) -> tuff_packs::Result<()> {
let plugin = build_as(&packs[0], &["claude-plugin".to_string()], false)?;
println!("{} files", plugin.artifact.contents.len());
let built = build_marketplace(MarketplaceBuildOptions {
sources: packs,
output,
name: Some("acme"),
owner_name: "Acme",
owner_url: Some("https://example.com"),
skip_unsupported: false,
})?;
for (name, version) in &built.plugins {
println!("{name} {version}");
}
Ok(())
}
fn install(project: &Path, url: &str, baselines: &Path) -> tuff_packs::Result<()> {
let workspace = Workspace::open(project)?;
let checked_out = checkout(CheckoutRequest {
url,
path: None,
git_ref: None,
plugin: None,
allow_remote: false,
})?;
let pack = source_pack_of(&checked_out)?;
let targets = ["claude".to_string()];
let built = build_for_targets(&pack.root, &targets)?;
let source = PackSource::Git(checked_out.source.clone());
let plan = plan_install(&workspace, &built.artifact, &source, &targets)?;
for file in &plan.files {
println!("{:?} {}", file.change, file.path);
}
for note in &plan.notes {
println!("note: {note}");
}
println!("{}", serde_json::to_string(&plan)?);
apply(&workspace, &Baselines::dir(baselines), plan)?;
Ok(())
}
fn update(
project: &Path,
pack: &str,
artifact: &PackArtifact,
source: &PackSource,
) -> tuff_packs::Result<()> {
let workspace = Workspace::open(project)?;
let request = UpdateRequest {
pack,
artifact,
source,
targets: &[], force: false,
};
match plan_update(&workspace, request)? {
None => println!("{pack} is up to date"),
Some(plan) => {
for member in &plan.members {
println!("{:?} {}", member.change, member.id);
}
apply(&workspace, &Baselines::none(), plan)?;
}
}
Ok(())
}
fn remove(project: &Path, pack: &str) -> tuff_packs::Result<()> {
let workspace = Workspace::open(project)?;
let plan = plan_remove(&workspace, pack, false)?;
apply(&workspace, &Baselines::none(), plan)?;
Ok(())
}
fn ask(project: &Path, artifact: &PackArtifact, source: &PackSource) -> tuff_packs::Result<String> {
let workspace = Workspace::open(project)?;
let plan = plan_install(&workspace, artifact, source, &["claude".to_string()])?;
println!("{}", serde_json::to_string(&plan)?);
Ok(plan.fingerprint.clone())
}
fn approve(
project: &Path,
artifact: &PackArtifact,
source: &PackSource,
approved: &str,
) -> tuff_packs::Result<()> {
let workspace = Workspace::open(project)?;
let plan = plan_install(&workspace, artifact, source, &["claude".to_string()])?;
match apply_approved(&workspace, &Baselines::none(), plan, approved)? {
Approval::Applied(summary) => println!("installed {}", summary.pack),
Approval::Changed(plan) => println!("{}", serde_json::to_string(&plan)?),
}
Ok(())
}
fn landing() -> tuff_packs::Result<()> {
let workspace = Workspace::open("my-project")?;
let pack = build_for_declared_targets("review-pack".as_ref())?;
let source = PackSource::Artifact(PackArtifactSource { registry: None });
let plan = plan_install(&workspace, &pack.artifact, &source, &["claude".into()])?;
for file in &plan.files {
println!("{:?} {}", file.change, file.path);
}
apply(&workspace, &Baselines::none(), plan)?;
Ok(())
}
fn main() {}