17d56d0e01
Clean break, no compatibility alias. Renames the product name, the CLI binary (`ccam` -> `agenthub`), the env var prefix (`CCAM_` -> `AGENTHUB_`), the Prometheus metric namespace (`ccam_*` -> `agenthub_*`), the tmux session prefix (`ccam-lane-<id>` -> `agenthub-lane-<id>`), the per-repo runtime profile directory (`.ccam/profile` -> `.agenthub/profile`), the lanes state root (`~/.claude/ccam-lanes` -> `~/.claude/agenthub-lanes`), the bundled plugins (`plugins/ccam*` -> `plugins/agenthub*`) and their slash commands (`/ccam-doctor` -> `/agenthub-doctor`, `/ccam:*` -> `/agenthub:*`). Because there is no alias, an existing install has to be updated by hand: rename its `.ccam/profile` directory and any `CCAM_*` variables, and reinstall the plugin under its new name. Two other name families are deliberately left alone here, since they are not just strings: the `Claude-Code-Monitor` repository/marketplace name, and the `agent-dashboard` npm package plus its `~/.claude/agent-dashboard` runtime directory, which holds the live database and needs a migration rather than a rename. Verified: server 1406/1406, client 459/459, `grep -i ccam` clean across tracked files, `openapi.yaml` regenerated (95 paths, unchanged count).
108 lines
3.4 KiB
JavaScript
108 lines
3.4 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* @file check-mcp-build.js
|
|
* @description `mcp/build/` is committed so a plugin install has a working MCP
|
|
* server the instant the session opens — Claude Code starts plugin MCP servers
|
|
* immediately and offers no "not ready yet" retry, so an async bootstrap cannot
|
|
* win that race. The cost is that the artifact can drift from `mcp/src`.
|
|
*
|
|
* Freshness is tracked by hashing the CONTENT of `mcp/src` (plus the manifests
|
|
* and tsconfig) into `mcp/build/.srchash`. Modification times are useless here:
|
|
* a fresh clone or checkout stamps every file with the same time in arbitrary
|
|
* order.
|
|
*
|
|
* Run by the pre-commit hook and by `/agenthub-doctor`.
|
|
* @author Nguyễn Ngọc Trí Vĩ <vinnt@smartgift.vn>
|
|
*/
|
|
|
|
const fs = require("fs");
|
|
const path = require("path");
|
|
const crypto = require("crypto");
|
|
|
|
const HASH_FILE = ".srchash";
|
|
|
|
/** Every file whose content the build depends on, in a stable order. */
|
|
function sourceFiles(mcpDir) {
|
|
const files = [];
|
|
const walk = (dir) => {
|
|
let entries;
|
|
try {
|
|
entries = fs
|
|
.readdirSync(dir, { withFileTypes: true })
|
|
.sort((a, b) => (a.name < b.name ? -1 : 1));
|
|
} catch {
|
|
return;
|
|
}
|
|
for (const e of entries) {
|
|
const full = path.join(dir, e.name);
|
|
if (e.isDirectory()) walk(full);
|
|
else files.push(full);
|
|
}
|
|
};
|
|
walk(path.join(mcpDir, "src"));
|
|
for (const f of ["package.json", "package-lock.json", "tsconfig.json"]) {
|
|
const full = path.join(mcpDir, f);
|
|
if (fs.existsSync(full)) files.push(full);
|
|
}
|
|
return files;
|
|
}
|
|
|
|
function sourceHash(root = path.resolve(__dirname, "..")) {
|
|
const mcpDir = path.join(root, "mcp");
|
|
const h = crypto.createHash("sha256");
|
|
for (const f of sourceFiles(mcpDir)) {
|
|
h.update(path.relative(mcpDir, f).replace(/\\/g, "/"));
|
|
h.update(fs.readFileSync(f));
|
|
}
|
|
return h.digest("hex");
|
|
}
|
|
|
|
/**
|
|
* @returns {{ok:boolean, reason:string, expected:string, recorded:string|null}}
|
|
*/
|
|
function mcpBuildStatus(root = path.resolve(__dirname, "..")) {
|
|
const buildDir = path.join(root, "mcp", "build");
|
|
const expected = sourceHash(root);
|
|
if (!fs.existsSync(path.join(buildDir, "index.js"))) {
|
|
return { ok: false, reason: "mcp/build/index.js is missing", expected, recorded: null };
|
|
}
|
|
let recorded = null;
|
|
try {
|
|
recorded = fs.readFileSync(path.join(buildDir, HASH_FILE), "utf8").trim();
|
|
} catch {
|
|
return { ok: false, reason: "mcp/build has no recorded source hash", expected, recorded: null };
|
|
}
|
|
return recorded === expected
|
|
? { ok: true, reason: "up to date", expected, recorded }
|
|
: {
|
|
ok: false,
|
|
reason: "mcp/build is stale — mcp/src has changed since it was built",
|
|
expected,
|
|
recorded,
|
|
};
|
|
}
|
|
|
|
/** Stamp the current source hash into the build directory. */
|
|
function writeHash(root = path.resolve(__dirname, "..")) {
|
|
const buildDir = path.join(root, "mcp", "build");
|
|
fs.mkdirSync(buildDir, { recursive: true });
|
|
fs.writeFileSync(path.join(buildDir, HASH_FILE), sourceHash(root) + "\n", "utf8");
|
|
}
|
|
|
|
if (require.main === module) {
|
|
if (process.argv.includes("--write")) {
|
|
writeHash();
|
|
console.log("mcp/build/.srchash updated");
|
|
} else {
|
|
const status = mcpBuildStatus();
|
|
if (status.ok) {
|
|
console.log("mcp/build is up to date");
|
|
} else {
|
|
console.error(`${status.reason}\nRun: npm run mcp:build`);
|
|
process.exitCode = 1;
|
|
}
|
|
}
|
|
}
|
|
|
|
module.exports = { sourceHash, mcpBuildStatus, writeHash };
|