ccc-xray · diff

git:20260722.9d3ab82 to git:20261013.fbe187d

86 added, 146 removed. Audit A to A.

---
name: ccc-xray
- description: "Project health scorecard — scans current repo across 7 dimensions (quality, docs, tests, deps, security, perf, CI) and returns a markdown table with 0-100 scores +…"
+ description: "Project health scorecard: scans the current repo for quality, docs, tests, deps, security, performance, CI, session cost and plugin context cost, then returns 0-100 scores with one fix-first call. Use when asked for a health check, repo audit, x-ray or token-cost inventory."
allowed-tools:
- Read
- - Write
- Bash
- Glob
- Grep
- Workflow
- AskUserQuestion
- mcp__ccd_session__spawn_task
- argument-hint: "[quick | full | security | deps | perf]"
+ argument-hint: "[quick | full | security | deps | perf | cost | context]"
+ model: sonnet
+ effort: medium
---
- # $ccc-xray — Project Health Scorecard
-
- Scan this repo and return a scorecard. Click-first UX — the user never types a number.
-
- Promoted from `commands/ccc-xray.md` (legacy slash command).
-
- ## Response shape (EVERY time)
-
- Output these three sections in order.
-
- ### 1. Brand header
-
- ```
- **CC Commander** · X-Ray Scanner · [Docs](https://commanderplugin.com)
- ```
-
- ### 2. Context strip (one line)
-
- Run in parallel via a single Bash call:
- - `git rev-parse --abbrev-ref HEAD 2>/dev/null` → branch
- - `git ls-files | wc -l` → file count
- - Detect stack: presence of `package.json` / `pyproject.toml` / `Cargo.toml` / `go.mod`
-
- Render:
- > 🔬 Target: `<branch>` · <N> files · stack: <detected> · ready to scan.
-
- If not a git repo: "🔬 Not a git repo — pick a scan scope below, I'll run shallow checks."
-
- ### 3. Scope picker — `AskUserQuestion`
-
- Call `AskUserQuestion` with 4 options (never list numbered options as text):
-
- ```
- question: "What depth?"
- header: "X-Ray Scan"
- multiSelect: false
- options:
- - label: "⚡ Quick scan (5 areas)"
- description: "Quality, docs, tests, deps, security. ~20s."
- preview: "Recommended for most repos — trims perf + CI."
- - label: "🔬 Full scan (7 areas)"
- description: "Adds performance + CI. ~45s."
- preview: "Use when prepping for a release or new-to-repo onboarding."
- - label: "🔐 Focus: security"
- description: "npm audit + secrets scan + dep age only."
- preview: "Fastest path to 'am I leaking secrets?'"
- - label: "📦 Focus: deps"
- description: "Outdated deps, lockfile hygiene, duplicate packages."
- preview: "Use before a dep bump PR."
- ```
-
- Prepend ⭐ to Quick scan by default — it's the recommended starting point.
-
- ### Native workflow (Claude Code v2.1.154+)
+ # $ccc-xray — scan, score, fix first
- If the `Workflow` tool is available, prefer invoking the bundled audit workflow for the **Full scan** depth (and optionally Quick scan when you want adversarially verified findings):
+ **CC Commander** · $ccc-xray · a scored health table for this repo and one recommendation for what to fix first.
- ```js
- Workflow({
- scriptPath: "${CLAUDE_PLUGIN_ROOT}/workflows/ccc-audit.workflow.js",
- args: { target: ".", dimensions: ["quality","security","perf","deps","tests","docs","ci"] }
- })
- ```
+ ## When to use / when not to
- Pass `dimensions` to match the user's chosen scope (e.g. `["security","deps"]` for the focused security/deps picks). The workflow fans out one agent per dimension, adversarially verifies each finding, and returns a synthesized scorecard — false positives are filtered before they reach you.
+ - Use for a repo health check, onboarding to an unfamiliar repo, release prep, or a "what is eating my context" inventory of installed plugins.
+ - Do not use for a single-file review (`$ccc-code-review`), a security threat model (`$ccc-security`), or a multi-reviewer branch pass (`$ccc-review`).
+ - This skill only reads. It never edits files; fixes are offered as opt-in tasks.
- If `Workflow` is unavailable (older client or tool not allowed), fall back to the Agent-based flow below — leave that flow intact.
+ ## What happens
- ## Running the scan
+ 1. **Context strip.** Run one Bash call:
- After user picks, run checks in parallel via a single Bash call. Each check is cheap + silent-on-failure:
+ ```bash
+ git rev-parse --abbrev-ref HEAD 2>/dev/null || echo "no-git"
+ basename "$(git rev-parse --show-toplevel 2>/dev/null || pwd)"
+ git ls-files 2>/dev/null | wc -l
+ ls package.json pyproject.toml Cargo.toml go.mod 2>/dev/null
+ ```
- | Area | Check (Bash) |
- |------|--------------|
- | Quality | `find . -type f \( -name '*.ts' -o -name '*.js' -o -name '*.py' \) -not -path './node_modules/*' \| wc -l` (size spread) |
- | Docs | Test for `README.md`, `CLAUDE.md`, `CHANGELOG.md` presence |
- | Tests | `find . -path '*/tests/*' -o -path '*/__tests__/*' -o -name '*.test.*' \| head -50 \| wc -l` |
- | Deps | `npm outdated --json 2>/dev/null \|\| true` (or `pip list --outdated`) |
- | Security | `npm audit --json 2>/dev/null \|\| true` (or `pip-audit -f json`) |
- | Performance | bundle-size heuristic: `du -sh dist 2>/dev/null` + check for missing memoization patterns |
- | CI | Presence of `.github/workflows/`, `.gitlab-ci.yml`, `.circleci/` |
+ Render one line: `🔬 Target: <branch> · <N> files · stack: <detected> · ready to scan.` If it is not a git repo, say so and continue with shallow checks. Take the repo name from the `--show-toplevel` basename; never hardcode it.
- Translate each result to a 0-100 score with the rubric:
- - 90-100: 🟢 healthy
- - 70-89: 🟡 acceptable
- - 50-69: 🟠 needs attention
- - 0-49: 🔴 critical
+ 2. **Pick the scope.** Map an argument straight to its scope and skip the picker: `quick`, `full`, `security`, `deps`, `perf`, `cost`, `context`. With no argument, ask the depth picker (see Decision points). Run no scan before the scope is chosen.
- ## Scorecard output (markdown table)
+ 3. **Full scan through the audit workflow (preferred).** When the `Workflow` tool is available and the scope is Full, or a focused scope where verified findings matter, run the bundled audit workflow:
- Render this shape:
+ ```js
+ Workflow({
+ scriptPath: "${CLAUDE_PLUGIN_ROOT}/workflows/ccc-audit.workflow.js",
+ args: { target: ".", dimensions: ["quality", "security", "performance", "deps", "tests", "docs", "ci"] }
+ })
+ ```
- ```
- ### 🔬 X-Ray Report — <repo-name>
+ The same workflow runs as `/commander:ccc-audit`. Dimension keys are exactly `quality`, `security`, `performance`, `deps`, `tests`, `docs`, `ci`; an unknown key is dropped silently, so pass `performance`, never `perf`. Subset `dimensions` to the chosen scope (security focus: `["security", "deps"]`). The workflow runs one finder per dimension, has a fresh skeptic try to refute each finding, and returns a scored scorecard. If `Workflow` is unavailable (older client, Codex, or not allowed), use step 4 for every area.
- | Area | Score | Top finding | Fix |
- |------|-------|-------------|-----|
- | 🧹 Code quality | 🟢 88 | 2 files >800 lines | Spawn `$ccc-makeover` |
- | 📚 Docs | 🟡 72 | CHANGELOG stale (14d) | Spawn docs-update task |
- | 🧪 Tests | 🟠 54 | Coverage 41% | Run `/tdd` on missing modules |
- | 📦 Deps | 🟡 70 | 4 minor updates pending | Run `npm outdated` |
- | 🔐 Security | 🟢 91 | Clean | — |
- | ⚡ Performance | 🟢 85 | Bundle 420 KB | — |
- | 🚢 CI | 🔴 20 | No `.github/workflows/` | Spawn CI setup task |
+ 4. **Shallow scan (Quick scan and fallback).** Run every check for the chosen scope in one Bash call, each guarded with `2>/dev/null || true` so one failure never aborts the scan:
- **Overall: 66 · 🟠 needs attention · fix CI first.**
- ```
+ | Area | Check |
+ |------|-------|
+ | 🧹 Quality | `git ls-files '*.ts' '*.js' '*.py' \| xargs wc -l \| grep -v ' total$' \| sort -rn \| head -5` (files over 800 lines) |
+ | 📚 Docs | `ls README.md CLAUDE.md CHANGELOG.md` and `git log -1 --format=%cr -- CHANGELOG.md` |
+ | 🧪 Tests | `git ls-files \| grep -cE '(^\|/)(tests?\|__tests__)/\|\.test\.\|\.spec\.'` |
+ | 📦 Deps | `npm outdated --json` (or `pip list --outdated --format json`) |
+ | 🔐 Security | `npm audit --json` (or `pip-audit -f json`) plus `git ls-files \| grep -E '\.env$\|\.pem$\|id_rsa'` |
+ | ⚡ Performance | `du -sh dist build` (bundle-size heuristic) |
+ | 🚢 CI | `ls -d .github/workflows .gitlab-ci.yml .circleci` |
- ## Post-scorecard: spawn fix offers
+ Quick runs Quality, Docs, Tests, Deps, Security. Full adds Performance and CI (when step 3 did not already cover them). A check that cannot run (no network, no npm) renders as `⚪ n/a`, never as a failure.
- For every LOW-scoring row (🟠 or 🔴), append a "Fix it?" chip via `mcp__ccd_session__spawn_task`:
+ 5. **Session cost row (`cost`, or Full when the user pastes `/cost` output).** Parse the pasted text with the bundled side-effect-free parser. Malformed lines land in `skipped[]`; empty input returns a zero-state object.
- Example (pseudocode):
- > Spawn a background task to: "Set up GitHub Actions CI for this <stack> repo — test + lint + deploy. See `.github/workflows/` conventions."
+ ```bash
+ cat <<'COST' | node --no-warnings --input-type=module -e 'const { parseCostOutput } = await import(process.argv[1]); let s = ""; process.stdin.on("data", d => s += d).on("end", () => console.log(JSON.stringify(parseCostOutput(s))));' "${CLAUDE_SKILL_DIR}/lib/cost-parser.js"
+ <pasted /cost output>
+ COST
+ ```
- Each chip is ONE spawn_task call. Do NOT auto-execute — only offer. User clicks to spawn.
+ Result fields: `totalUsd`, `models`, `cacheHitRate`, `turns`, `avgUsdPerTurn`, `skipped`, `raw`. Score the 💰 Cost row: 🟢 when `cacheHitRate >= 0.5` and `avgUsdPerTurn < 0.10`; 🟡 when `cacheHitRate` is 0.2–0.5 or `avgUsdPerTurn` is 0.10–0.50; 🟠 when `cacheHitRate < 0.2` or `avgUsdPerTurn >= 0.50`.
- For 🟢/🟡 rows: no chip, just the score row.
+ 6. **Plugin context cost row (`context`, or Full).** Inventory each enabled plugin's projected context cost with `claude plugin details <name>`. Take the plugin names from the namespaces of the plugin skills loaded in this session (`<plugin>:<skill>`) or from the `/plugin` manager; if neither gives a list, ask the user which plugins to inspect. Then run one guarded Bash call:
- ## Priority rule (single recommendation line)
+ ```bash
+ for p in <plugin> <plugin>; do echo "== $p"; claude plugin details "$p" 2>/dev/null || echo "n/a"; done
+ ```
- At bottom, state **which area to fix first** based on impact × effort:
- - If 🔴 Security → always first (blocks release)
- - Else if 🔴 CI and repo has no deploy → CI first (unlocks everything)
- - Else lowest score wins
+ Read the token breakdown from that output as printed; do not assume a particular line label, column layout or machine-readable format. For each plugin, note the cost it reports as loaded into every session and, separately, any cost it reports as loaded only when a component is invoked. When a plugin's output gives no token figure, or the command is unavailable, that plugin is `n/a`; when no plugin yields a figure, the 🧠 Context row renders as `⚪ n/a`. For the largest contributor, quote its biggest per-component rows exactly as the output shows them. Score the 🧠 Context row on the summed every-session cost: 🟢 under 10k tokens, 🟡 10k–25k, 🟠 25k–50k, 🔴 over 50k. These thresholds are a Commander heuristic, not a platform limit; say so in the finding.
- Output: `**🎯 My call: fix <area> first — <one-line rationale>.**`
+ 7. **Score and render.** Translate each result to 0–100: 90–100 🟢 healthy, 70–89 🟡 acceptable, 50–69 🟠 needs attention, 0–49 🔴 critical. Render exactly the rows for the chosen scope (Quick shows five), keep the table under 15 rows, and summarize sub-findings in the Top finding column:
- ## Argument handling
+ ```
+ ### 🔬 X-Ray Report — <repo-name>
- - `$ccc-xray quick` → skip picker, run Quick scan directly
- - `$ccc-xray full` → skip picker, run Full scan directly
- - `$ccc-xray security` / `deps` / `perf` → skip picker, run focused scan
- - `$ccc-xray` bare → show the picker
+ | Area | Score | Top finding | Fix |
+ |------|-------|-------------|-----|
+ | 🧹 Code quality | 🟢 88 | 2 files over 800 lines | $ccc-makeover |
+ | 🚢 CI | 🔴 20 | No .github/workflows/ | CI setup task |
+ | 🧠 Context | 🟡 72 | 18k every-session; <plugin> ~9k | disable an unused plugin |
- ## Anti-patterns — DO NOT
+ **Overall: 66 · 🟠 needs attention**
+ ```
- - ❌ Run scans BEFORE user picks scope (wastes tokens on rejected depth)
- - ❌ Render 7 rows when Quick scan was selected (show 5)
- - ❌ Auto-spawn fix tasks without offering — chip pattern is click-first
- - ❌ Output ASCII banners or box-drawing — plain markdown tables render everywhere
- - ❌ Hardcode repo name — read from `git rev-parse --show-toplevel` basename
- - ❌ Block waiting for slow network audits — use `|| true` fallbacks, never fail the whole scan
+ 8. **Fix-first call.** End with one line, `**🎯 My call: fix <area> first — <one-line rationale>.**`, chosen in this order: a 🔴 Security row always wins (it blocks release); else a 🔴 CI row when the repo has no deploy path (it unlocks everything else); else the lowest score.
- ## Brand rules
+ 9. **Offer fixes, never run them.** For each 🟠 or 🔴 row, offer one fix task with one `mcp__ccd_session__spawn_task` call (Desktop), for example "Set up GitHub Actions CI for this <stack> repo: test and lint on every PR." The user clicks to start it. Where `spawn_task` is unavailable (CLI, Codex), list the same prompts as text and ask the follow-up picker. 🟢 and 🟡 rows get no offer.
- - Emoji-forward, scan-friendly (PM Consultant voice)
- - Lead with the scorecard table, not narrative
- - One recommendation line at the end, always
- - ⭐ marks the recommended option in every picker
+ ## Decision points
- ## Cost analysis (NEW in beta.11+)
+ Depth picker (`AskUserQuestion`, header "X-Ray Scan", single select):
- When the user asks for `$ccc-xray cost` or `$ccc-xray full` and a `/cost` transcript is available, parse it via the bundled utility at `lib/cost-parser.js` (ESM, side-effect-free):
+ - 🟢 **⚡ Quick scan (5 areas)** — quality, docs, tests, deps, security; about 20 s; right for most repos.
+ - **🔬 Full scan (all areas)** — adds performance, CI, session cost and plugin context cost through the audit workflow; for release prep or onboarding.
+ - **🔐 Focus: security** — audit, secrets scan and dependency age only; fastest answer to "am I leaking secrets?".
+ - **📦 Focus: deps** — outdated packages, lockfile hygiene, duplicates; run before a dependency bump.
- ```js
- import { parseCostOutput } from './lib/cost-parser.js';
- const report = parseCostOutput(rawCostText);
- // → { totalUsd, models, cacheHitRate, turns, avgUsdPerTurn, skipped, raw }
- ```
+ Follow-up picker when spawn chips are unavailable: 🟢 **Start the fix-first task** (runs it in this session) · **Show all fix prompts** (copyable text) · **Done**.
- Use the result to render a "💰 Cost" row in the scorecard:
- - `🟢` if `cacheHitRate ≥ 0.5` and `avgUsdPerTurn < $0.10`
- - `🟡` if `cacheHitRate ∈ [0.2, 0.5)` or `avgUsdPerTurn ∈ [$0.10, $0.50)`
- - `🟠` if `cacheHitRate < 0.2` or `avgUsdPerTurn ≥ $0.50`
+ In Codex or any surface without `AskUserQuestion`, ask the same choices as one plain-text question.
- The parser is liberal: malformed lines land in `skipped[]` (not thrown), empty input returns a zero-state object. Safe to call on any text the user pastes.
+ ## Done when
- ## Tips for the agent executing this skill
+ - The scope the user chose is the scope that ran (five rows for Quick).
+ - Every row has a score or `⚪ n/a` and a top finding; the overall line and the single 🎯 fix-first line are present.
+ - Every 🟠/🔴 row has exactly one fix offer, and no task started without a click.
- 1. Whole flow is ≤3 turns: context+picker → user clicks → parallel scan → scorecard + chips.
- 2. Run ALL checks in a single Bash call (chained with `;`) to save turns.
- 3. If a check fails (network down, no npm), show the row as `⚪ n/a` — don't crash.
- 4. Keep the scorecard table under ~15 rows total — summarize sub-findings in "Top finding" column.
+ ## Guardrails
- ---
+ - Read-only: no file edits, no dependency installs, no `npm audit fix`.
+ - Never block on slow network audits; guard each check and mark it n/a.
+ - Never print secret values found by the secrets scan; report the path and type only.
+ - No ASCII banners or box drawing; plain markdown tables render everywhere.
+ - Keep the flow to three turns: context and picker, scan, scorecard and offers.
- **Bottom line:** pick scope → scan in parallel → one markdown table → one recommendation → chips for 🟠/🔴 rows. User clicks to fix.
+ ## See also
- ---
+ - `$ccc-review` — multi-reviewer pass on a branch or PR.
+ - `$ccc-security` — focused security audit and threat model.
+ - `$ccc-makeover` — act on a low quality score.
+ - `$ccc-usage` — spend and usage trends beyond one session.
> ⚙️ **Fable contract:** plan before build · verifier ≠ worker · prove before alarm · loops need gates · leave durable state — `rules/fable-method.md`
> (On Codex, present these options as a numbered list and ask the user to reply with a number — AskUserQuestion is Claude-only.)
> (The Workflow(...) tool is not available on Codex — run the steps sequentially.)