feat(m0.6-r3): generic external CLI Tool Protocol v1

- add tool install/list/remove and unknown-command dispatch without hardcoded
  tool names or clap variants
- validate and copy local tool packages atomically, reject entrypoint escapes
  and symlinks, record and re-verify SHA-256
- forward OsString args, stdio, cwd and exit status without a shell; never
  execute PATH programs implicitly
- add black-box tests for arbitrary names, Unicode args, built-in conflicts,
  traversal, version mismatch, tampering and PATH hijacking
- add ADR-0013 and mark R3 complete
This commit is contained in:
cflmy committed 2026-11-20 11:44:20 +08:00
1 parent 7797d78d86
commit 25a1faa6ef
7 files changed
+859 -3

No files matched your search

+54
View File
@@ -8,7 +8,9 @@ mod args;
mod commands;
mod loader;
mod output;
mod tool;
use std::ffi::OsString;
use std::path::PathBuf;
use clap::{Args, Parser, Subcommand};
@@ -49,6 +51,11 @@ enum Command {
Lock(LockArgs),
/// Verify that path dependencies match the lockfile.
Sync(SyncArgs),
/// Manage and dispatch generic external CLI tools.
Tool(ToolArgs),
/// Unknown top-level command: dispatch to a registered external tool.
#[command(external_subcommand)]
External(Vec<OsString>),
}
#[derive(Args)]
@@ -251,6 +258,47 @@ struct LockArgs {
json: bool,
}
#[derive(Args)]
struct ToolArgs {
#[command(subcommand)]
command: ToolCommand,
}
#[derive(Subcommand)]
enum ToolCommand {
/// Install a tool from a local tool.json (or its directory).
Install(ToolInstallArgs),
/// List installed external tools.
List(ToolListArgs),
/// Remove an installed external tool.
Remove(ToolRemoveArgs),
}
#[derive(Args)]
struct ToolInstallArgs {
/// Path to tool.json or the tool package directory.
manifest: PathBuf,
/// Machine readable JSON output.
#[arg(long)]
json: bool,
}
#[derive(Args)]
struct ToolListArgs {
/// Machine readable JSON output.
#[arg(long)]
json: bool,
}
#[derive(Args)]
struct ToolRemoveArgs {
/// Tool command to remove.
command: String,
/// Machine readable JSON output.
#[arg(long)]
json: bool,
}
#[derive(Args)]
struct SyncArgs {
/// Fail instead of silently updating when the lockfile is stale.
@@ -315,6 +363,12 @@ fn main() {
Command::Remove(args) => commands::remove(&args.name, args.json),
Command::Lock(args) => commands::lock(args.json),
Command::Sync(args) => commands::sync(args.locked, args.json),
Command::Tool(args) => match args.command {
ToolCommand::Install(args) => tool::install(&args.manifest, args.json),
ToolCommand::List(args) => tool::list(args.json),
ToolCommand::Remove(args) => tool::remove(&args.command, args.json),
},
Command::External(args) => tool::dispatch(&args),
};
std::process::exit(code);
}