Files
nntrivi2001 8a82895c65 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>
2026-08-10 16:05:37 +07:00

75 lines
3.2 KiB
Bash
Executable File

#!/usr/bin/env sh
#
# Pre-commit: auto-format staged files, then run the full test suite.
# The commit is ABORTED unless every test passes.
#
# Activated via `core.hooksPath=.husky` (set by the package.json "prepare"
# script on `npm install`). No husky/lint-staged runtime required.
# Abort the commit on the first failing command (formatting error or failing test).
set -e
ROOT="$(git rev-parse --show-toplevel)"
cd "$ROOT"
# ── 1. Format staged files with Prettier, then re-stage them ────────────────
# Only Added/Copied/Modified/Renamed paths in the index. --ignore-unknown lets
# Prettier silently skip anything it can't parse, so we can hand it every staged
# path without filtering by extension. NUL-delimited (-z / -0) so paths with
# spaces are handled correctly.
#
# NOTE: this re-adds the *whole* file. If you intentionally staged only part of
# a file, review the result after the auto-format.
STAGED="$(git diff --cached --name-only --diff-filter=ACMR)"
if [ -n "$STAGED" ]; then
PRETTIER="$ROOT/node_modules/.bin/prettier"
if [ -x "$PRETTIER" ]; then
set -- "$PRETTIER"
else
set -- npx --no-install prettier
fi
echo "🎨 Formatting staged files with Prettier..."
git diff --cached --name-only --diff-filter=ACMR -z | xargs -0 "$@" --write --ignore-unknown
git diff --cached --name-only --diff-filter=ACMR -z | xargs -0 git add
else
echo "🎨 No staged files to format."
fi
# ── 2. Committed MCP build must match mcp/src ───────────────────────────────
# mcp/build/ is committed because a plugin's MCP server starts before any
# bootstrap could build it. Only enforced when mcp/src is part of this commit,
# so unrelated commits are not blocked by a stale artifact.
if git diff --cached --name-only --diff-filter=ACMR | grep -q '^mcp/src/'; then
echo "🔌 Checking the committed MCP build against mcp/src..."
node scripts/check-mcp-build.js
fi
# ── 3. Run tests — commit is blocked unless all pass ────────────────────────
# Each suite is retried once on failure. The full run executes dozens of test
# files concurrently, each starting its own server (plus the CLI suite's
# spawned child processes with hard kill timeouts), so a loaded machine can
# produce a one-off timing failure unrelated to the commit. A real regression
# is deterministic: it fails both runs and still blocks the commit. This keeps
# the gate strict without making commits a dice roll on machine load.
run_suite() {
# $1 = human label, $2 = npm script
echo "🧪 Running $1 tests..."
if npm run "$2"; then
return 0
fi
echo "⚠️ $1 suite failed — retrying once to rule out machine-load flakiness..."
if npm run "$2"; then
echo "$1 suite passed on retry — treating the first failure as a load flake."
echo " If this keeps happening, the flaky test above deserves a real fix."
return 0
fi
echo "$1 suite failed twice — genuine failure, aborting the commit."
return 1
}
run_suite backend test:server
run_suite frontend test:client
echo "✅ Formatting applied and all tests passed — proceeding with commit."