Files
Daniel Avila a56202407d feat(cli-rust): Rust port of the CLI core (install path) + npm distribution + CI (#640)
* feat(cli-rust): add Rust port of the CLI core with npm distribution + CI

Adds a new `cli-rust/` crate (binary `cct`) that ports the CORE of the
claude-code-templates CLI to Rust, alongside the existing Node `cli-tool/`.

Native (byte-parity with the Node CLI, verified via `diff -r`):
- Component installation: --agent/--command/--mcp/--setting/--hook/--skill
  and --workflow YAML, replicating the exact GitHub raw/API URLs, target
  paths (flat dir, category dropped), .mcp.json/settings/hooks merge
  semantics, .py/.sh sidecars, 2-space JSON + trailing newline.
- Fire-and-forget tracking (3 endpoints, detached threads, env opt-out).

Delegated to the Node CLI for now (commands/delegate.rs forwards argv via
CCT_NODE_BIN or `npx claude-code-templates@latest`): dashboards, sandbox,
global agents, stats, health-check, interactive setup.

Parity gotcha handled: serde_json Map::remove does swap-remove under
preserve_order; switched to shift_remove to match JS `delete` key order.

Distribution: npm shim (npm/cct/bin/cct.js) execs a prebuilt binary from
optionalDependencies (@davila7/cct-<os>-<arch>, esbuild pattern) so `npx`
keeps working; plus Homebrew, cargo-binstall, and install.sh from GitHub
Releases. build-rust-cli.yml builds all 5 targets on tag `cli-rust-v*`.

Tests: 23 offline unit/integration tests + 2 network integration tests
(#[ignore]). fmt + clippy clean.

CI: rust-ci.yml runs fmt + clippy + tests only when cli-rust/** changes and
posts a sticky PR comment with the results.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* fix(cli-rust): address cubic review (config safety, opt-out, packaging, CI)

Fixes from the cubic automated review on PR #640:

- install.rs: fail safe on a corrupt/unreadable existing .mcp.json/settings
  file instead of silently overwriting it (MCP aborts; setting/hook skip the
  location), matching Node's throw-on-bad-config behavior.
- tracking.rs: honor both `=1` and `=true` as opt-out values (the README
  documents `=1`); Node only checks `=true`, so this is more privacy-safe.
- cli.rs/main.rs: implement --dry-run for the native install path (prints the
  plan, writes nothing) instead of parsing the flag and ignoring it.
- main.rs: run_prompt surfaces a non-zero `claude` exit code (a missing
  `claude` stays a soft warning since the install already succeeded).
- delegate.rs: propagate signal-based termination as 128+signal on Unix
  instead of collapsing to exit code 1.
- github.rs: warn when a skill file fails to download (mirrors Node's
  "Could not download" log) instead of skipping silently.
- npm/build-packages.mjs: accept the release `.tgz` artifacts (extract them)
  in addition to unpacked binaries, matching build-rust-cli.yml output.
- npm/cct/package.json: add top-level os/cpu so npm rejects unsupported
  platforms at install time instead of failing at runtime.
- build-rust-cli.yml: add `permissions: contents: write` (gh-release) and
  Swatinem/rust-cache for the 5-target matrix.
- tests/integration.rs: tighten the 2-space-indent assertion.

Not changed (intentional parity with the Node CLI):
- merge.rs new-hook-type copy: Node copies the incoming value as-is for a
  previously-absent hook type (no old-format normalization); kept identical.

fmt + clippy clean; 23 offline + 2 network tests pass.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* fix(cli-rust): abort install on corrupt existing settings/hook config

Follow-up to the cubic review: a corrupt/unreadable existing settings or
hook file now fails the whole component install (returns 0) instead of
skipping just that location, matching Node — where readJson throws out of
the per-location loop and fails the component. Prevents a multi-location
run from reporting success despite a bad target location.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* chore(cli-rust): prep v0.1.0 release via GitHub Releases + cargo-binstall

Wire up the two opt-in distribution channels that don't touch the existing
`claude-code-templates` npm package:

- Cargo.toml: fix cargo-binstall pkg-url to the `cli-rust-v<version>` tag
  (was `v<version>`), so `cargo binstall --git ...` resolves the release asset.
- install.sh: resolve the latest `cli-rust-v*` release instead of the generic
  /releases/latest, which could otherwise pick a Node-CLI `vX.Y.Z` release.
- README: install table now lists the available preview channels (curl|sh,
  cargo-binstall via --git, from source) and marks Homebrew/npm as planned;
  Release section documents the merge -> tag cli-rust-v0.1.0 -> verify flow.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-18 22:20:46 -04:00
..

cct — Rust core for claude-code-templates

A Rust port of the core of the claude-code-templates CLI: component installation (agents, commands, mcps, settings, hooks, skills), verified at byte-for-byte parity with the Node.js CLI.

Everything else (dashboards, sandbox, global agents, stats, health-check, interactive setup) is delegated to the existing Node CLI for now — see Delegation.

Install

Released as a standalone binary from GitHub Releases (tagged cli-rust-v*), separate from the existing claude-code-templates npm package so nothing about the current npx experience changes.

Available now (v0.1.0 preview):

Channel Command
Shell script curl -fsSL https://raw.githubusercontent.com/davila7/claude-code-templates/main/cli-rust/dist/install.sh | sh
cargo-binstall cargo binstall --git https://github.com/davila7/claude-code-templates claude-code-templates
From source cargo install --path cli-rust

The --git form reads the prebuilt-binary metadata straight from this repo, so no crates.io publish is required. (A plain cargo binstall claude-code-templates / cargo install claude-code-templates would need the crate published to crates.io — optional, later.)

Planned (not wired up yet):

Channel Command
Homebrew tap brew install davila7/tap/cct
npm (new name) npx @davila7/cct

The npm path (when enabled) ships a tiny JS shim (npm/cct/bin/cct.js) that execs the prebuilt binary for the current platform, pulled in as an optionalDependency (@davila7/cct-<os>-<arch>). The existing claude-code-templates npm package stays on Node until the binary is proven.

Usage

cct --agent deep-research-team/research-synthesizer   # install an agent
cct --mcp devtools/elasticsearch                       # merge into .mcp.json
cct --setting api/custom-headers --hook monitoring/desktop-notification-on-stop
cct --skill creative-design/algorithmic-art            # recursive skill tree
cct --agent a,b --command c -d ./project -y            # batch into a directory

Opt out of anonymous telemetry with CCT_NO_TRACKING=1 (also disabled when CI=true).

Architecture

src/
  main.rs          dispatch: native install path vs Node delegation
  cli.rs           clap flag surface (mirrors the commander options)
  constants.rs     GitHub raw/API bases, tracking URLs, version
  github.rs        raw fetch + recursive contents-API tree (skills)
  tracking.rs      fire-and-forget analytics (3 endpoints, detached threads)
  merge.rs         .mcp.json / settings / hooks merge semantics (+ unit tests)
  python_compat.rs Windows python3->python shim
  commands/
    install.rs     installIndividual* + installMultipleComponents
    delegate.rs    forward argv to the Node CLI
  util/{fs_ext,paths}.rs

Parity-critical details preserved: 2-space JSON with trailing newline, shift_remove (not swap-remove) so key order matches JS delete, permissions.{allow,deny,ask} Set-union, hook array concatenation, category dropping in target filenames, .py/.sh sidecar downloads, skills via the GitHub contents API.

Delegation

Non-install flags forward verbatim to the Node CLI:

  1. CCT_NODE_BIN — path to cli-tool/bin/create-claude-config.js (run with node) or an executable. Used for local testing.
  2. Fallback: npx -y claude-code-templates@latest <args>.
CCT_NODE_BIN=../cli-tool/bin/create-claude-config.js cct --list-agents

Develop

cargo build                 # debug build
cargo test                  # unit tests (merge semantics)
cargo build --release       # optimized binary at target/release/cct

Parity check vs Node

RDIR=$(mktemp -d); NDIR=$(mktemp -d)
ARGS="--agent deep-research-team/research-synthesizer --mcp devtools/elasticsearch -y"
CCT_NO_TRACKING=1 target/release/cct $ARGS -d "$RDIR"
CCT_NO_TRACKING=1 node ../cli-tool/bin/create-claude-config.js $ARGS -d "$NDIR"
diff -r "$RDIR" "$NDIR" && echo "IDENTICAL"

Release

v0.1.0 preview (GitHub Releases + curl + cargo-binstall)

  1. Merge this branch to main (so the workflow and install.sh exist there).
  2. Tag and push: git tag cli-rust-v0.1.0 && git push origin cli-rust-v0.1.0. .github/workflows/build-rust-cli.yml builds all 5 targets and uploads cct-<target>.tgz to the GitHub Release (contents: write is granted).
  3. Verify the channels:
    curl -fsSL https://raw.githubusercontent.com/davila7/claude-code-templates/main/cli-rust/dist/install.sh | sh
    cargo binstall --git https://github.com/davila7/claude-code-templates claude-code-templates
    
    The tag must keep the cli-rust-v prefix — both the binstall metadata (Cargo.toml) and install.sh's tag filter depend on it.

Later channels (when enabled)

  • Homebrew tap: create davila7/homebrew-tap, drop in dist/homebrew/cct.rb, fill the sha256 per asset (shasum -a 256 cct-<target>.tgz).
  • npm (new name): node npm/build-packages.mjs <version> <dist-dir> (accepts the release .tgzs), then publish each npm/platforms/* and npm/cct under a new name (e.g. @davila7/cct) — leaves claude-code-templates untouched.