feat(plugins): make CCAM installable straight from a Claude Code plugin

Adds a root `ccam` plugin (`.claude-plugin/plugin.json`, `"source": "./"`) so
`/plugin marketplace add` + `/plugin install ccam@...` is enough on a machine
with nothing but Claude Code: no clone, no npm run setup, no manual npm start.

- scripts/plugin-bootstrap.js: SessionStart hook. Fast-path exit, Node >=22.5
  gate (node:sqlite), mkdir lock with stale reclaim, deps installed into
  ~/.claude/agent-dashboard/runtime/ (never the plugin cache), legacy
  checkout-hook cleanup (backed up), ~/.local/bin/ccam launcher, eager UI
  build so client routes like /run work immediately, detached server spawn.
- scripts/plugin-open.js, scripts/plugin-doctor.js: /ccam-open, /ccam-doctor.
- server/index.js: DASHBOARD_CLIENT_DIST override (plugin cache is read-only).
- mcp/build/ is committed (plugin MCP servers start before any bootstrap could
  build them) and kept honest by scripts/check-mcp-build.js (content hash,
  not mtime), enforced by pre-commit when mcp/src changes.
- plugins/ccam-dashboard/.mcp.json moved under plugins/ccam/ with a working
  ${CLAUDE_PLUGIN_ROOT} path (the old relative path never resolved from a
  marketplace-cached subdir).
- Docs: README, INSTALL, SETUP, ARCHITECTURE, CLAUDE.md, docs/PLUGINS.md,
  docs/MCP.md, docs/CLI.md, docs/HOOKS.md.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2026-08-10 16:05:37 +07:00
parent 5a793e70cc
commit 8a82895c65
59 changed files with 5982 additions and 44 deletions
+31 -1
View File
@@ -14,6 +14,23 @@ const { getSettingsPath } = require("../server/lib/claude-home");
const SETTINGS_PATH = getSettingsPath();
const HOOK_HANDLER = path.resolve(__dirname, "hook-handler.js").replace(/\\/g, "/");
/**
* True when the plugin bootstrap has run on this machine — i.e. the `ccam`
* plugin is (or was) installed and supplies its own hook entries.
* Read-only and never throws; `plugin-bootstrap.js` is not required here to
* keep this module free of a circular dependency.
*
* @returns {boolean}
*/
function pluginBootstrapRan() {
try {
const { getDataDir } = require("../server/lib/claude-home");
return fs.existsSync(path.join(getDataDir(), "runtime", "state.json"));
} catch {
return false;
}
}
function envFlag(name) {
return ["1", "true", "yes", "on"].includes(String(process.env[name] || "").toLowerCase());
}
@@ -126,6 +143,17 @@ function installHooks(silent = false) {
return false;
}
// The `ccam` plugin installs the same eight hooks itself. Running both means
// every event is POSTed twice and token/cost figures double — warn loudly
// rather than silently double-count. (`/ccam-doctor` reports the same state.)
if (!silent && pluginBootstrapRan()) {
console.warn(
"WARNING: the ccam plugin is installed and already provides these hooks.\n" +
" Installing them again double-counts every event. Uninstall the\n" +
" plugin first, or skip this step. Run /ccam-doctor to check."
);
}
let settings = {};
if (fs.existsSync(SETTINGS_PATH)) {
try {
@@ -176,4 +204,6 @@ if (require.main === module) {
if (!installHooks(false)) process.exitCode = 1;
}
module.exports = { installHooks, isInsideContainer };
// isOurEntry is also used by scripts/plugin-bootstrap.js to strip hook entries
// a previous checkout install left behind (they would double-count events).
module.exports = { installHooks, isInsideContainer, isOurEntry };