mirror of
https://github.com/davila7/claude-code-templates.git
synced 2026-09-19 01:30:23 +08:00
a56202407d
* 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>
97 lines
3.6 KiB
JavaScript
97 lines
3.6 KiB
JavaScript
#!/usr/bin/env node
|
|
// Assemble per-platform npm packages from prebuilt Rust binaries.
|
|
//
|
|
// Usage:
|
|
// node build-packages.mjs <version> <dist-dir>
|
|
//
|
|
// <dist-dir> may contain EITHER the release tarballs `cct-<target>.tgz` (what
|
|
// build-rust-cli.yml uploads — each holds a single `cct`/`cct.exe`) OR the
|
|
// already-unpacked binaries `cct-<target>` / `cct-<target>.exe`. Produces
|
|
// `cli-rust/npm/platforms/<pkg>/` directories ready to `npm publish`, and
|
|
// rewrites the version in the main wrapper package + its optionalDependencies.
|
|
|
|
import {
|
|
mkdirSync,
|
|
mkdtempSync,
|
|
copyFileSync,
|
|
writeFileSync,
|
|
readFileSync,
|
|
chmodSync,
|
|
existsSync,
|
|
} from 'node:fs';
|
|
import { dirname, join } from 'node:path';
|
|
import { tmpdir } from 'node:os';
|
|
import { execFileSync } from 'node:child_process';
|
|
import { fileURLToPath } from 'node:url';
|
|
|
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
|
|
// Resolve the source binary for a target: prefer the release tarball
|
|
// (`cct-<target>.tgz`), extracting it to a temp dir; otherwise fall back to an
|
|
// unpacked `cct-<target>` binary in the dist dir.
|
|
function resolveSourceBinary(distDir, rustTarget, binName) {
|
|
const tgz = join(distDir, `cct-${rustTarget}.tgz`);
|
|
if (existsSync(tgz)) {
|
|
const tmp = mkdtempSync(join(tmpdir(), 'cct-pkg-'));
|
|
execFileSync('tar', ['-xzf', tgz, '-C', tmp]);
|
|
return join(tmp, binName);
|
|
}
|
|
const isWin = binName.endsWith('.exe');
|
|
return join(distDir, `cct-${rustTarget}${isWin ? '.exe' : ''}`);
|
|
}
|
|
|
|
// Rust target triple -> { pkg, os, cpu, rustTarget }
|
|
const TARGETS = [
|
|
{ pkg: '@davila7/cct-darwin-arm64', os: 'darwin', cpu: 'arm64', rustTarget: 'aarch64-apple-darwin' },
|
|
{ pkg: '@davila7/cct-darwin-x64', os: 'darwin', cpu: 'x64', rustTarget: 'x86_64-apple-darwin' },
|
|
{ pkg: '@davila7/cct-linux-x64', os: 'linux', cpu: 'x64', rustTarget: 'x86_64-unknown-linux-gnu' },
|
|
{ pkg: '@davila7/cct-linux-arm64', os: 'linux', cpu: 'arm64', rustTarget: 'aarch64-unknown-linux-gnu' },
|
|
{ pkg: '@davila7/cct-win32-x64', os: 'win32', cpu: 'x64', rustTarget: 'x86_64-pc-windows-msvc' },
|
|
];
|
|
|
|
const version = process.argv[2];
|
|
const distDir = process.argv[3];
|
|
if (!version || !distDir) {
|
|
console.error('Usage: node build-packages.mjs <version> <dist-dir>');
|
|
process.exit(1);
|
|
}
|
|
|
|
const platformsRoot = join(__dirname, 'platforms');
|
|
|
|
for (const t of TARGETS) {
|
|
const isWin = t.os === 'win32';
|
|
const binName = isWin ? 'cct.exe' : 'cct';
|
|
const srcBin = resolveSourceBinary(distDir, t.rustTarget, binName);
|
|
const pkgDir = join(platformsRoot, t.pkg.replace('/', '__'));
|
|
const binDir = join(pkgDir, 'bin');
|
|
mkdirSync(binDir, { recursive: true });
|
|
|
|
const destBin = join(binDir, binName);
|
|
copyFileSync(srcBin, destBin);
|
|
if (!isWin) chmodSync(destBin, 0o755);
|
|
|
|
const pkgJson = {
|
|
name: t.pkg,
|
|
version,
|
|
description: `Prebuilt cct binary for ${t.os}/${t.cpu}`,
|
|
os: [t.os],
|
|
cpu: [t.cpu],
|
|
files: [`bin/${binName}`],
|
|
license: 'MIT',
|
|
repository: {
|
|
type: 'git',
|
|
url: 'git+https://github.com/davila7/claude-code-templates.git',
|
|
},
|
|
};
|
|
writeFileSync(join(pkgDir, 'package.json'), JSON.stringify(pkgJson, null, 2) + '\n');
|
|
console.log(`✓ assembled ${t.pkg} (${t.rustTarget})`);
|
|
}
|
|
|
|
// Sync version into the main wrapper package + optionalDependencies.
|
|
const mainPkgPath = join(__dirname, 'cct', 'package.json');
|
|
const mainPkg = JSON.parse(readFileSync(mainPkgPath, 'utf8'));
|
|
mainPkg.version = version;
|
|
for (const t of TARGETS) mainPkg.optionalDependencies[t.pkg] = version;
|
|
writeFileSync(mainPkgPath, JSON.stringify(mainPkg, null, 2) + '\n');
|
|
console.log(`✓ synced version ${version} into wrapper package`);
|