129 lines
16 KiB
Markdown
129 lines
16 KiB
Markdown
---
|
||
name: web-project-audit
|
||
description: Audit-level architecture report for an existing web project (frontend, full-stack or monorepo — React/Next.js, Vue/Nuxt, Svelte/SvelteKit, Astro, Angular, Node backends), built by reading the source files themselves (not README/docs, which may be stale). Use when the user wants to understand, audit, map, or document how a web app is architected — its file/package organization, the libraries and mechanisms behind each implementation category (rendering, routing, styling, state, data fetching, API/backend, persistence, auth, background jobs, etc.) with code pointers, how modules interact and pass data to each other (grouped into user-facing and background interactions), and the user-facing features. Crawls files one by one (optionally fanned out to subagents), records findings into a library of per-category audit docs, then synthesizes a REPORT.md with an implementation table, a module interaction map and a features table.
|
||
---
|
||
|
||
# Web Project Audit
|
||
|
||
Goal: a report of how the app is built **as implemented today**. Every claim traces to a source file the auditor actually read. Documentation (README, `docs/`, wiki, ADRs, comments describing intent) is **not evidence** — it is excluded from the crawl and must not be used to fill gaps. Where code is unclear, say so; don't backfill from docs.
|
||
|
||
The audit runs in phases. All state lives in an **audit workspace** so the work can be resumed and split across subagents:
|
||
|
||
```
|
||
<AUDIT_DIR>/
|
||
ledger.tsv every in-scope file + status (pending/contributed/redundant/trivial/skipped)
|
||
library/<cat>.md one audit doc per implementation category — the findings library
|
||
occurrences.tsv further files that repeat an already-documented pattern (prevalence)
|
||
batches/ file lists for subagents
|
||
modules.txt, resource-counts.tsv
|
||
timeline.tsv phase start timestamps (duration tracking)
|
||
usage.md/.json token usage + duration, written by `finish`
|
||
REPORT.md final synthesized report
|
||
```
|
||
|
||
**Timing and tokens:** `init` starts the clock. Run `bash $A phase $AUDIT_DIR <name>` as the first command of each later phase (`orientation`, `per-file`, `gate`, `cross-cutting`, `report`). `bash $A finish $AUDIT_DIR` stops the clock and writes `usage.md`. Usage is read from the harness's own logs: Claude Code transcripts (main session, subagents and headless local workers) or OpenCode's session DB. Calls are counted only inside the audit window, and only from sessions whose transcript mentions `AUDIT_DIR`. Nothing to track by hand.
|
||
|
||
## Harness notes (Claude Code and OpenCode)
|
||
|
||
This skill is shared by Claude Code and OpenCode, which both load it from `~/.claude/skills/`.
|
||
- **`SKILL_DIR`** is the directory containing this SKILL.md. Claude Code provides it; elsewhere use the skill's reported location, normally `~/.claude/skills/web-project-audit`.
|
||
- **Tool names:** "file-read tool" means `Read` in Claude Code and `read` in OpenCode. "Subagent" means the `Agent` tool with `general-purpose` in Claude Code, and the `task` tool with the `general` agent in OpenCode.
|
||
- **Local model:** if you yourself are running on a locally hosted model (e.g. OpenCode pointed at vLLM or Ollama), your subagents already run locally. Never use `local-worker-handoff` from there; it exists only to move work off Anthropic models in Claude Code.
|
||
|
||
Helper: `A="$SKILL_DIR/scripts/audit.sh"` (run `bash $A` with no args for usage). It is the only way findings and statuses are written — it validates categories, keeps one entry per pattern slug, and locks for concurrent subagents.
|
||
|
||
## Phase 0 — Set up
|
||
|
||
1. Confirm the project root (the dir with the top-level `package.json` or backend manifest, or the workspace root of a monorepo). If the user didn't give one, use the cwd if it qualifies; otherwise ask.
|
||
2. `AUDIT_DIR` defaults to `<project>/.web-audit/`. Tell the user it was created there and suggest adding it to `.gitignore` (don't edit `.gitignore` yourself unless asked). Use another location if the user names one.
|
||
3. If `AUDIT_DIR/ledger.tsv` already exists with progress, **resume**: skip to the phase `bash $A coverage $AUDIT_DIR` indicates. `init` refuses to overwrite progress.
|
||
4. Record the git SHA if the project is a repo (`git -C <project> rev-parse --short HEAD`) for the report header.
|
||
|
||
## Phase 1 — Inventory
|
||
|
||
```bash
|
||
bash $A init <project> <AUDIT_DIR> # builds ledger + empty library docs; prints counts by module/kind
|
||
bash $A tree <AUDIT_DIR> # package → top-level area → directory tree with file counts
|
||
bash $A signals <AUDIT_DIR> # import/dependency hits per library
|
||
```
|
||
|
||
- Modules are directories holding a `package.json` or a backend manifest (`requirements.txt`, `pyproject.toml`, `go.mod`, `Gemfile`, `Cargo.toml`, `composer.json`). Projects with a non-Node backend and no-build frontends (plain ES modules served from `static/`) are in scope.
|
||
- The inventory includes source (`.ts .tsx .js .jsx .mjs .cjs`), backend code (`.py .go .rb .php .rs .ex .cs`), server templates (Jinja, EJS, Handlebars, ERB), shell scripts and Makefiles, framework components (`.vue .svelte .astro`), styles (`.css .scss .sass .less`), markup (`.html .mdx`), schemas (`.prisma .graphql .sql .proto`, migrations), `package.json` and workspace files, tooling config (`tsconfig`, `*.config.*`, lint/format rc files), infra (Dockerfiles, compose, `vercel.json`, `netlify.toml`, `wrangler.toml`), CI config, and JSON/TOML/YAML data. Each file gets a kind: `build config source component server style markup template schema data test story infra script ci other`. It excludes `node_modules`, build outputs (`dist`, `.next`, `.nuxt`, `.svelte-kit`, `.astro`, `.turbo`, `coverage`…), generated dirs, lockfiles, minified bundles and source maps, `vendor/` directories, Python venvs and caches, images/fonts/media under `public/`/`static/`/`assets/` (counted only; hand-written code there is kept), translated locale files (English kept), and all documentation (listed in `docs.txt` for the optional drift step only).
|
||
- `secret-files.txt` lists `.env*`, `*.env`, `.npmrc`, `.dev.vars`, keys/certificates and credentials JSON. They are kept out of the ledger. **Never open them.** Record their existence and role from the code that reads them (e.g. "`STRIPE_SECRET_KEY` read via `process.env` in `lib/stripe.ts`") under `auth-security`, and note which variables are exposed to the client bundle (`NEXT_PUBLIC_*`, `VITE_*`, `PUBLIC_*`).
|
||
- `signals` output is a **map of where to look, not evidence**. A library on the classpath may be unused; an import may be dead. Nothing goes into the library from `signals` alone.
|
||
- If the ledger has obvious noise (e.g. a vendored library, an example app, large JSON fixtures or data dumps, a generated API client the filters missed), mark those `skipped` with a reason and tell the user what was excluded.
|
||
|
||
## Phase 2 — Orientation pass (main model, always)
|
||
|
||
`bash $A phase $AUDIT_DIR orientation`
|
||
|
||
Read these yourself first, in full, recording findings and marking each file. They establish the vocabulary every later reader needs:
|
||
|
||
1. Root `package.json` and workspace config (`pnpm-workspace.yaml`, `turbo.json`, `nx.json`), root `tsconfig*.json`, and the framework/bundler config (`next.config.*`, `vite.config.*`, `nuxt.config.*`, `svelte.config.*`, `astro.config.*`, `angular.json`).
|
||
2. Each package's `package.json`: dependencies with versions, scripts, and `workspace:` dependencies on other packages → package graph.
|
||
3. Entry points: the root layout/`_app`/`App.tsx`/`main.ts`, the router definition or the top of the file-based route tree, middleware (`middleware.ts`, server hooks), and the server entry if there is a backend (`server.ts`, `app.ts`, `src/index.ts`).
|
||
4. Env handling (`env.ts`, `import.meta.env` usage) and the global stylesheet / theme / Tailwind config.
|
||
|
||
Then write a 10–20 line **orientation summary** (packages and what each is for, framework + rendering model, core libraries + versions, architectural style as seen so far, slug names already used; for a single-package app, the top-level feature/layer directories that will be treated as modules). Keep it in your context; it is passed to every subagent.
|
||
|
||
## Phase 3 — Per-file audit
|
||
|
||
`bash $A phase $AUDIT_DIR per-file`
|
||
|
||
Every remaining `pending` file is read **one by one, in full**, and filed into the right library doc. The exact procedure — read, pick category, new pattern vs. refinement vs. repetition, features, mark status — is in **`references/file-auditor-prompt.md`**. Read it before starting this phase; it applies to you as much as to subagents.
|
||
|
||
Reading: use one file-read call per file (several independent reads in one message is fine). Don't `cat` whole packages through Bash — it blurs the per-file judgement and large UI packages overflow tool output.
|
||
|
||
Key rule on redundancy: a file does not need to contribute. When a file is "more of the same" (the 12th shadcn primitive, the 30th page component with the identical data-loading shape) log it with `also` and mark it `redundant`. Only write prose when the file shows something not already in the library. Before writing, check `bash $A patterns $AUDIT_DIR <category>`.
|
||
|
||
**Choose an execution mode** from the pending count (`bash $A coverage $AUDIT_DIR`):
|
||
|
||
- **≤ 150 pending files → main model alone.** Loop: `bash $A next $AUDIT_DIR 10`, read and file each, repeat until `coverage` exits 0.
|
||
- **> 150, or the user asked to offload to a local model → batched workers.** `bash $A batch $AUDIT_DIR 40` (batches stay within one package where possible). Fill the prompt in `references/file-auditor-prompt.md` per batch (`{PROJECT_ROOT}`, `{AUDIT_DIR}`, `{SKILL_DIR}`, `{BATCH_FILE}`, `{ORIENTATION_SUMMARY}`). Then pick the worker backend:
|
||
1. **Local worker (Claude Code only, preferred when available).** If you are in Claude Code on an Anthropic model and the `local-worker-handoff` skill is installed, load it and run its `check`. On success, write each filled prompt to a file and dispatch it through that skill's `run`, with `--cwd <project>` and `--allow "Read Grep Glob Bash(bash $A:*)"`, respecting the backend's `max_parallel`. Use batches of ~20 files for local workers. This skill never names a server, model or key; those belong to the handoff skill's config.
|
||
2. **Native subagents.** This is the default in OpenCode and the fallback in Claude Code when the handoff skill is absent or `check` fails (say so in one line). Spawn one subagent per batch (see Harness notes for the tool), several in a single message: **up to 6 at a time** on hosted models, **2–3 at a time** on a local model so they don't queue on one GPU. Local-model subagents get batches of ~20 files and the heavier spot-check in Phase 4.
|
||
|
||
When a wave finishes, run `patterns` and pass any notable new slugs into the next wave's orientation summary so later workers reuse them instead of inventing synonyms. Tell the user the batch count and backend before launching, and give a one-line update per wave.
|
||
- If the user asked for a quick/cheaper run, say what you'll reduce (e.g. read all source and components but only sample styles, stories and JSON data) and mark the unsampled files `skipped` with note `sampled-out` — never silently drop coverage.
|
||
|
||
## Phase 4 — Coverage gate
|
||
|
||
`bash $A phase $AUDIT_DIR gate`
|
||
|
||
1. `bash $A gate $AUDIT_DIR` must print `GATE: PASS`: no `pending` files, every `contributed` file is cited by a finding, every `redundant` file has a logged occurrence. Fix or re-audit whatever it lists. (`coverage` is the non-failing progress view.)
|
||
2. **Spot-check delegated work** (skip in main-model mode). Per batch, pick ~3 files marked `redundant`/`trivial` and ~2 `contributed` exemplars, open them, and confirm the status and the finding are right. Check local-worker batches more heavily (~5 + 3). If a batch looks skimmed (everything `trivial`, findings that don't match the file, invented line numbers), redo it with a built-in subagent or yourself and tell the user which batches were redone.
|
||
3. Check for slug synonyms across workers (`patterns` output: e.g. `tanstack-query-hook` vs `react-query-custom-hook`). Treat them as one pattern in the report.
|
||
|
||
## Phase 4.5 — Cross-cutting entries (main model)
|
||
|
||
`bash $A phase $AUDIT_DIR cross-cutting`
|
||
|
||
The per-file loop doesn't naturally produce these, so write them now:
|
||
- `file-organization`: the packaging scheme, naming conventions and outliers, from `audit.sh tree` plus what you read. Use source `(project)`.
|
||
- Empty categories: `bash $A none $AUDIT_DIR <category> "<what you looked for>"`, so the report can say "None found in code" with evidence of looking.
|
||
- `module-interactions`: close the gaps the per-file pass leaves. For every `workspace:` dependency in the package graph (Phase 2), check that at least one interaction entry explains what it is used for; read the files needed to fill any missing edge. Also check the client → server boundary, external services (payment, email, auth providers, webhooks) and every background entry point (cron, queue worker, webhook, service worker) for an entry. Confirm or correct "Inferred:" callee sides with a refinement. In a single-package app, do the same across the top-level feature/layer directories. If the app really is one undivided unit, record `none` saying so.
|
||
- `observations`: inconsistencies across files, such as two mechanisms for one job or migrations in progress, that no single file reveals.
|
||
- Superseded claims: the library is append-only. If an early finding was wrong or an "Inferred:" note was later confirmed, add a refinement to that slug saying so. The report uses the latest refinement.
|
||
|
||
## Phase 5 — Consolidate and report
|
||
|
||
`bash $A phase $AUDIT_DIR report`
|
||
|
||
1. Read **every** `library/*.md` in full and `occurrences.tsv` (prevalence per slug: `awk -F'\t' 'NR>1{print $1"/"$2}' occurrences.tsv | sort | uniq -c | sort -rn`).
|
||
2. Resolve conflicts: where two mechanisms coexist (styled-components + Tailwind, SWR + TanStack Query), report both with counts — that is a finding, not noise. Note which is newer/dominant only if the code shows it.
|
||
3. Pick **code pointers** per category: the 1–3 files that most clearly show the pattern (usually the exemplar, but prefer a clean canonical file over a first-seen edge case). Verify each path exists.
|
||
4. Run `bash $A finish $AUDIT_DIR` immediately before writing the report. It stops the clock and writes `usage.md`, whose tables go verbatim into the report's "Usage & duration" section. Tokens spent writing the report itself fall after the clock stops; the report's section says so.
|
||
5. Write `AUDIT_DIR/REPORT.md` following **`references/report-template.md`**: at-a-glance, build & toolchain, **file tree organization scheme**, **implementation summary table (Category | Implementation details | Code pointers)**, **features table (Feature | What it lets the user do | Entry point)**, architecture & data flow with one end-to-end trace, **module interactions** (user-facing and background tables of From → To | Mechanism | Data passed | Trigger, plus a diagram), observations (inconsistencies, risks, strengths), coverage & method.
|
||
6. Print the summary to the terminal as the template's last paragraph describes, and give the full path to `REPORT.md` and the library dir.
|
||
|
||
If this skill is itself running inside a subagent and the harness refuses the `REPORT.md` write, don't work around it. Return the full report text as your final reply, with the intended path, so the parent session saves it.
|
||
|
||
Optional, only after the report is complete and only if documentation exists: add a **"Documentation drift"** section listing doc claims the code contradicts (e.g. README says Redux, code uses Zustand). This is the only point where docs are opened, and they are compared against the report — never used to write it.
|
||
|
||
## Guardrails
|
||
|
||
- Read files; don't infer content from names, grep hits, or `signals`.
|
||
- Cite paths (and `:line` for key facts). Mark inferences as "Inferred:".
|
||
- Versions from `package.json` / the backend manifest (lockfile only to resolve a range). For vendored libraries with no manifest, read only the version banner at the top of each file and say that's where the version came from.
|
||
- Never open files in `secret-files.txt`, and never copy secret values into the library or report; note location and type only.
|
||
- Don't modify the audited project. The only writes are inside `AUDIT_DIR`.
|