439 lines
28 KiB
Bash
439 lines
28 KiB
Bash
#!/usr/bin/env bash
|
|
# web-project-audit helper.
|
|
# All state lives in an audit workspace (AUDIT_DIR). Safe for concurrent use by
|
|
# several subagents: every write goes through a mkdir-based lock.
|
|
#
|
|
# Usage:
|
|
# audit.sh init <project-dir> <audit-dir> # inventory + library skeleton
|
|
# audit.sh tree <audit-dir> # package/directory organization view
|
|
# audit.sh signals <audit-dir> # import/dependency-based library hints (NOT evidence)
|
|
# audit.sh batch <audit-dir> [size] # split pending files into batches
|
|
# audit.sh next <audit-dir> [n] # next n pending files (single-agent mode)
|
|
# audit.sh patterns <audit-dir> [category] # pattern slugs already documented (+ counts)
|
|
# audit.sh finding <audit-dir> <category> <slug> <source-path|(project)> ["<title>"] # body on stdin
|
|
# title required for a new slug; omit for a refinement of an existing slug
|
|
# audit.sh none <audit-dir> <category> "<what was looked for>" # record an absence
|
|
# audit.sh also <audit-dir> <category> <slug> <source-path> # another occurrence
|
|
# audit.sh mark <audit-dir> <source-path> <status> [note]
|
|
# status: contributed | redundant | trivial | skipped
|
|
# audit.sh coverage <audit-dir> # progress report (always exits 0)
|
|
# audit.sh phase <audit-dir> <name> # timestamp the start of a phase (for durations)
|
|
# audit.sh finish <audit-dir> # stop the clock; write usage.md (tokens + duration)
|
|
# audit.sh usage <audit-dir> [--json] # token usage + duration so far
|
|
# audit.sh gate <audit-dir> # exit 1 if pending files or status/finding mismatches
|
|
set -euo pipefail
|
|
|
|
SELF_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
TEMPLATES="$SELF_DIR/../templates"
|
|
|
|
CATEGORIES="build-and-tooling file-organization architecture module-interactions routing rendering ui-components styling state-management data-fetching forms-validation api-backend persistence auth-security background-jobs i18n-a11y performance observability testing deployment features observations"
|
|
|
|
die() { echo "audit.sh: $*" >&2; exit 2; }
|
|
now_ms() { python3 -I -c 'import time; print(int(time.time()*1000))'; }
|
|
|
|
lock() {
|
|
local l="$AUDIT_DIR/.lock" i=0
|
|
until mkdir "$l" 2>/dev/null; do
|
|
i=$((i+1)); [ $i -gt 600 ] && die "could not acquire lock $l (stale? rmdir it)"
|
|
sleep 0.1
|
|
done
|
|
trap 'rmdir "$AUDIT_DIR/.lock" 2>/dev/null || true' EXIT
|
|
}
|
|
unlock() { rmdir "$AUDIT_DIR/.lock" 2>/dev/null || true; trap - EXIT; }
|
|
|
|
need_dir() { AUDIT_DIR="${1:?audit-dir required}"; [ -f "$AUDIT_DIR/ledger.tsv" ] || die "no ledger in $AUDIT_DIR (run init first)"; }
|
|
|
|
valid_cat() { case " $CATEGORIES " in *" $1 "*) ;; *) die "unknown category '$1'. Valid: $CATEGORIES";; esac; }
|
|
|
|
# Normalise a source path to be project-relative (accepts absolute paths too).
|
|
relpath() {
|
|
local p="$1" root; root="$(cat "$AUDIT_DIR/.project_root")"
|
|
[ "$p" = "(project)" ] && { printf '%s' "$p"; return; }
|
|
case "$p" in "$root"/*) p="${p#"$root"/}";; esac
|
|
printf '%s' "${p#./}"
|
|
}
|
|
|
|
cmd_init() {
|
|
local proj="${1:?project-dir required}" out="${2:?audit-dir required}"
|
|
[ -d "$proj" ] || die "project dir not found: $proj"
|
|
proj="$(cd "$proj" && pwd)"
|
|
if [ -f "$out/ledger.tsv" ] && awk -F'\t' 'NR>1 && $7!="pending" {f=1} END {exit !f}' "$out/ledger.tsv" && [ "${FORCE:-}" != 1 ]; then
|
|
die "$out already has audit progress. Resume with 'coverage'/'next'/'batch', or re-run with FORCE=1 to start over (wipe $out first)."
|
|
fi
|
|
mkdir -p "$out/library" "$out/batches"
|
|
AUDIT_DIR="$(cd "$out" && pwd)"
|
|
echo "$proj" > "$AUDIT_DIR/.project_root"
|
|
now_ms > "$AUDIT_DIR/.started_at"; rm -f "$AUDIT_DIR/.finished_at"
|
|
printf '%s\tinventory\n' "$(cat "$AUDIT_DIR/.started_at")" > "$AUDIT_DIR/timeline.tsv"
|
|
|
|
# Module roots = dirs holding a package.json or a backend manifest (requirements.txt, pyproject.toml, go.mod, Gemfile, Cargo.toml, composer.json).
|
|
( cd "$proj" && find . \( -name node_modules -o -name .git -o -name dist -o -name build -o -name out -o -name .next -o -name .nuxt -o -name .output \
|
|
-o -name .svelte-kit -o -name .astro -o -name .turbo -o -name .vercel -o -name .netlify -o -name coverage -o -name .cache \
|
|
-o -name .parcel-cache -o -name storybook-static -o -name generated -o -name __generated__ -o -name .idea -o -name .vscode \
|
|
-o -name vendor -o -name .web-audit -o -name .yarn -o -name .pnpm-store \
|
|
-o -name .venv -o -name venv -o -name __pycache__ -o -name .pytest_cache -o -name .mypy_cache -o -name target \) -prune -o \
|
|
\( -name package.json -o -name requirements.txt -o -name pyproject.toml -o -name go.mod -o -name Gemfile -o -name Cargo.toml \
|
|
-o -name composer.json -o -name deno.json -o -name deno.jsonc \) -print ) \
|
|
| sed 's#^\./##; s#/\{0,1\}[^/]*$##' | sort -u > "$AUDIT_DIR/modules.txt"
|
|
[ -s "$AUDIT_DIR/modules.txt" ] || echo "" > "$AUDIT_DIR/modules.txt"
|
|
|
|
# Candidate source files. Documentation (*.md, docs/) is deliberately excluded:
|
|
# this audit is about current implementation, not what docs claim.
|
|
( cd "$proj" && find . \
|
|
\( -name node_modules -o -name .git -o -name dist -o -name build -o -name out -o -name .next -o -name .nuxt -o -name .output \
|
|
-o -name .svelte-kit -o -name .astro -o -name .turbo -o -name .vercel -o -name .netlify -o -name coverage -o -name .cache \
|
|
-o -name .parcel-cache -o -name storybook-static -o -name generated -o -name __generated__ -o -name .idea -o -name .vscode \
|
|
-o -name vendor -o -name .web-audit -o -name .yarn -o -name .pnpm-store \
|
|
-o -name .venv -o -name venv -o -name __pycache__ -o -name .pytest_cache -o -name .mypy_cache -o -name target -o -name docs -o -name doc \) -prune -o \
|
|
-type f \( -name '*.ts' -o -name '*.tsx' -o -name '*.js' -o -name '*.jsx' -o -name '*.mjs' -o -name '*.cjs' \
|
|
-o -name '*.vue' -o -name '*.svelte' -o -name '*.astro' -o -name '*.css' -o -name '*.scss' -o -name '*.sass' -o -name '*.less' \
|
|
-o -name '*.pcss' -o -name '*.html' -o -name '*.mdx' -o -name '*.json' -o -name '*.jsonc' -o -name '*.prisma' -o -name '*.graphql' \
|
|
-o -name '*.gql' -o -name '*.sql' -o -name '*.proto' -o -name '*.toml' -o -name '*.yml' -o -name '*.yaml' -o -name 'Dockerfile*' \
|
|
-o -name '.babelrc' -o -name '.eslintrc*' -o -name '.prettierrc*' -o -name '.browserslistrc' -o -name '.nvmrc' -o -name '.node-version' \
|
|
-o -name 'Procfile' -o -name 'Caddyfile' -o -name 'nginx*.conf' \
|
|
-o -name '*.py' -o -name '*.go' -o -name '*.rb' -o -name '*.php' -o -name '*.rs' -o -name '*.ex' -o -name '*.exs' -o -name '*.cs' \
|
|
-o -name '*.sh' -o -name 'Makefile' -o -name 'justfile' -o -name 'requirements*.txt' -o -name 'go.mod' -o -name 'Gemfile' \
|
|
-o -name '*.jinja' -o -name '*.jinja2' -o -name '*.j2' -o -name '*.hbs' -o -name '*.ejs' -o -name '*.njk' -o -name '*.erb' \) -print ) \
|
|
| sed 's#^\./##' \
|
|
| awk '
|
|
# drop noise: lockfiles, minified/bundled output, source maps, translated locale files.
|
|
# Hand-written code under public/ or static/ stays: no-build apps serve their whole frontend from there.
|
|
/(^|\/)(package-lock\.json|npm-shrinkwrap\.json|yarn\.lock|pnpm-lock\.yaml|bun\.lockb?|composer\.lock)$/ { next }
|
|
/\.min\.(js|css)$/ || /\.map$/ || /\.bundle\.js$/ { next }
|
|
/(^|\/)(locales?|i18n|lang|translations|messages)\/.*/ { n=split($0,a,"/"); f=a[n]; d=a[n-1]
|
|
if (f !~ /^en([-_][A-Za-z]+)?\.json$/ && d !~ /^en([-_][A-Za-z]+)?$/ && (f ~ /^[a-z][a-z]([-_][A-Za-z]+)?\.json$/ || d ~ /^[a-z][a-z]([-_][A-Za-z]+)?$/)) next }
|
|
/\.ya?ml$/ && !/^\.github\// && !/^\.gitlab-ci/ && !/circleci|bitbucket-pipelines|azure-pipelines|docker-compose|compose\.ya?ml|pnpm-workspace|netlify|render\.ya?ml|fly|app\.ya?ml|openapi|swagger/ { next }
|
|
{ print }' \
|
|
| sort > "$AUDIT_DIR/.files"
|
|
|
|
# Build ledger: id module sourceset kind lines path status note
|
|
awk -v root="$proj" '
|
|
FILENAME==ARGV[1] { mods[++m]=$0; next }
|
|
{
|
|
path=$0; best=""; bl=-1
|
|
for (i=1;i<=m;i++) { mod=mods[i]
|
|
if (mod=="" ) { if (bl<0) { best="(root)"; bl=0 } continue }
|
|
if (index(path, mod "/")==1 && length(mod)>bl) { best=mod; bl=length(mod) } }
|
|
if (best=="") best="(root)"
|
|
rel=path; if (best!="(root)") rel=substr(path, length(best)+2)
|
|
ss="-"; if (index(rel, "/")) ss=substr(rel, 1, index(rel, "/")-1)
|
|
f=path; sub(/.*\//, "", f)
|
|
k="other"
|
|
if (f=="package.json" || f ~ /^(pnpm-workspace\.yaml|turbo\.json|nx\.json|lerna\.json|rush\.json|deno\.jsonc?|requirements.*\.txt|pyproject\.toml|go\.mod|Gemfile|Cargo\.toml|composer\.json|Makefile|justfile)$/) k="build"
|
|
else if (path ~ /^\.github\/|^\.gitlab-ci|circleci|bitbucket-pipelines|azure-pipelines/) k="ci"
|
|
else if (f ~ /^(Dockerfile.*|docker-compose.*|compose\.ya?ml|Procfile|Caddyfile|nginx.*\.conf|vercel\.json|netlify\.toml|wrangler\.toml|fly\.toml|render\.ya?ml|firebase\.json|app\.ya?ml|serverless\.ya?ml)$/) k="infra"
|
|
else if (f ~ /^(tsconfig.*|jsconfig.*)\.json$/ || f ~ /\.config\.(js|cjs|mjs|ts|mts|cts|json)$/ || f ~ /^\.(babelrc|eslintrc.*|prettierrc.*|browserslistrc|nvmrc|node-version)$/ || f ~ /^(biome|components|\.?swcrc)\.json$/) k="config"
|
|
else if (f ~ /\.(test|spec)\.[cm]?[jt]sx?$/ || f ~ /^test_.*\.py$|_test\.(py|go)$|_spec\.rb$/ || path ~ /(^|\/)(__tests__|tests?|e2e|cypress|playwright)\//) k="test"
|
|
else if (f ~ /\.stories\.[cm]?[jt]sx?$|\.stories\.(mdx|svelte|vue)$/) k="story"
|
|
else if (f ~ /\.(prisma|graphql|gql|sql|proto)$/ || path ~ /(^|\/)(migrations?|schema)\//) k="schema"
|
|
else if (f ~ /\.(css|scss|sass|less|pcss)$/) k="style"
|
|
else if (f ~ /\.(html|mdx)$/) k="markup"
|
|
else if (f ~ /\.(json|jsonc|toml|ya?ml)$/) k="data"
|
|
else if (f ~ /\.(vue|svelte|astro)$/) k="component"
|
|
else if (f ~ /\.(py|go|rb|php|rs|ex|exs|cs)$/) k="server"
|
|
else if (f ~ /\.sh$/) k="script"
|
|
else if (f ~ /\.(jinja2?|j2|hbs|ejs|njk|erb)$/) k="template"
|
|
else if (f ~ /\.[cm]?[jt]sx?$/) k="source"
|
|
cmd="wc -l < \"" root "/" path "\""; cmd | getline n; close(cmd); gsub(/ /,"",n)
|
|
printf "%d\t%s\t%s\t%s\t%s\t%s\tpending\t\n", ++id, best, ss, k, n, path
|
|
}' "$AUDIT_DIR/modules.txt" "$AUDIT_DIR/.files" > "$AUDIT_DIR/ledger.body"
|
|
{ printf 'id\tmodule\tsourceset\tkind\tlines\tpath\tstatus\tnote\n'; cat "$AUDIT_DIR/ledger.body"; } > "$AUDIT_DIR/ledger.tsv"
|
|
rm -f "$AUDIT_DIR/ledger.body" "$AUDIT_DIR/.files"
|
|
[ -f "$AUDIT_DIR/occurrences.tsv" ] || printf 'category\tslug\tpath\n' > "$AUDIT_DIR/occurrences.tsv"
|
|
|
|
for c in $CATEGORIES; do
|
|
f="$AUDIT_DIR/library/$c.md"
|
|
[ -f "$f" ] || cp "$TEMPLATES/library/$c.md" "$f"
|
|
done
|
|
|
|
# Static assets: counted, not read.
|
|
( cd "$proj" && find . \( -name node_modules -o -name .git -o -name dist -o -name build -o -name out -o -name .next -o -name .nuxt -o -name .output \
|
|
-o -name .svelte-kit -o -name .astro -o -name .turbo -o -name .vercel -o -name .netlify -o -name coverage -o -name .cache \
|
|
-o -name .parcel-cache -o -name storybook-static -o -name generated -o -name __generated__ -o -name .idea -o -name .vscode \
|
|
-o -name vendor -o -name .web-audit -o -name .yarn -o -name .pnpm-store \
|
|
-o -name .venv -o -name venv -o -name __pycache__ -o -name .pytest_cache -o -name .mypy_cache -o -name target \) -prune -o -type f \( -path '*/public/*' -o -path '*/static/*' -o -path '*/assets/*' \) \
|
|
\( -iname '*.png' -o -iname '*.jpg' -o -iname '*.jpeg' -o -iname '*.gif' -o -iname '*.webp' -o -iname '*.avif' -o -iname '*.svg' -o -iname '*.ico' \
|
|
-o -iname '*.woff' -o -iname '*.woff2' -o -iname '*.ttf' -o -iname '*.otf' -o -iname '*.mp4' -o -iname '*.webm' -o -iname '*.mp3' -o -iname '*.pdf' \) -print ) \
|
|
| awk '{ e=$0; sub(/.*\./, "", e); c[tolower(e)]++ } END { for (k in c) printf "%s\t%d\n", k, c[k] }' \
|
|
| sort > "$AUDIT_DIR/resource-counts.tsv"
|
|
|
|
( cd "$proj" && find . \( -name node_modules -o -name .git -o -name dist -o -name build -o -name out -o -name .next -o -name .nuxt -o -name .output \
|
|
-o -name .svelte-kit -o -name .astro -o -name .turbo -o -name .vercel -o -name .netlify -o -name coverage -o -name .cache \
|
|
-o -name .parcel-cache -o -name storybook-static -o -name generated -o -name __generated__ -o -name .idea -o -name .vscode \
|
|
-o -name vendor -o -name .web-audit -o -name .yarn -o -name .pnpm-store \
|
|
-o -name .venv -o -name venv -o -name __pycache__ -o -name .pytest_cache -o -name .mypy_cache -o -name target \) -prune -o \
|
|
-type f \( -iname '*.md' -o -iname '*.adoc' -o -iname '*.rst' \) -print ) | sed 's#^\./##' | sort > "$AUDIT_DIR/docs.txt"
|
|
( cd "$proj" && find . \( -name node_modules -o -name .git -o -name dist -o -name build -o -name out -o -name .next -o -name .nuxt -o -name .output \
|
|
-o -name .svelte-kit -o -name .astro -o -name .turbo -o -name .vercel -o -name .netlify -o -name coverage -o -name .cache \
|
|
-o -name .parcel-cache -o -name storybook-static -o -name generated -o -name __generated__ -o -name .idea -o -name .vscode \
|
|
-o -name vendor -o -name .web-audit -o -name .yarn -o -name .pnpm-store \
|
|
-o -name .venv -o -name venv -o -name __pycache__ -o -name .pytest_cache -o -name .mypy_cache -o -name target \) -prune -o -type f \( -name '.env' -o -name '.env.*' -o -name '*.env' -o -name '*.pem' -o -name '*.key' \
|
|
-o -name '*.p12' -o -name '*.pfx' -o -name '.npmrc' -o -name '.yarnrc.yml' -o -name 'credentials*.json' -o -name 'service-account*.json' \
|
|
-o -name '*-sa.json' -o -name '.dev.vars' -o -name 'secrets.*' \) -print ) | sed 's#^\./##' | sort > "$AUDIT_DIR/secret-files.txt"
|
|
# Secret-bearing files never enter the ledger.
|
|
awk -F'\t' -v s="$AUDIT_DIR/secret-files.txt" 'BEGIN{while((getline l<s)>0) S[l]=1} NR==1 || !($6 in S)' "$AUDIT_DIR/ledger.tsv" > "$AUDIT_DIR/ledger.tmp" && mv "$AUDIT_DIR/ledger.tmp" "$AUDIT_DIR/ledger.tsv"
|
|
echo "Project: $proj"
|
|
echo "Audit dir: $AUDIT_DIR"
|
|
echo "Modules: $(grep -c . "$AUDIT_DIR/modules.txt" || true)"
|
|
echo "Files in ledger: $(($(wc -l < "$AUDIT_DIR/ledger.tsv")-1))"
|
|
echo "Docs found (NOT audited; only for optional drift check): $(grep -c . "$AUDIT_DIR/docs.txt" || true) -> docs.txt"
|
|
echo "Secret-bearing files (never open; note existence/role only): $(grep -c . "$AUDIT_DIR/secret-files.txt" || true) -> secret-files.txt"
|
|
echo
|
|
echo "By kind:"; awk -F'\t' 'NR>1{c[$4]++; l[$4]+=$5} END{for(k in c) printf " %-15s %5d files %8d lines\n", k, c[k], l[k]}' "$AUDIT_DIR/ledger.tsv" | sort
|
|
echo "By module:"; awk -F'\t' 'NR>1{c[$2]++; l[$2]+=$5} END{for(k in c) printf " %-40s %5d files %8d lines\n", k, c[k], l[k]}' "$AUDIT_DIR/ledger.tsv" | sort
|
|
}
|
|
|
|
cmd_tree() {
|
|
need_dir "$1"
|
|
echo "== Modules (dirs with package.json or a backend manifest) =="; sed 's/^$/(root)/; s/^/ /' "$AUDIT_DIR/modules.txt"
|
|
echo
|
|
echo "== Directories per module [top-level area] (code files per directory: source/component/server/style/markup/test/story/template) =="
|
|
awk -F'\t' 'NR>1 && ($4=="source"||$4=="component"||$4=="server"||$4=="style"||$4=="test"||$4=="story"||$4=="markup"||$4=="template") {
|
|
p=$6; if ($2!="(root)") p=substr(p, length($2)+2); if (index(p, "/")) sub(/\/[^\/]+$/, "", p); else p="."
|
|
key=$2 " [" $3 "]"; d[key SUBSEP p]++ }
|
|
END { for (k in d) { split(k, a, SUBSEP); printf "%s\t%s\t%d\n", a[1], a[2], d[k] } }' "$AUDIT_DIR/ledger.tsv" \
|
|
| sort -t$'\t' -k1,1 -k2,2 \
|
|
| awk -F'\t' '{ if ($1!=last) { print "\n" $1; last=$1 } printf " %-70s %4d\n", $2 "/", $3 }'
|
|
echo
|
|
echo "== Static assets (counted, not read) =="; sed 's/^/ /' "$AUDIT_DIR/resource-counts.tsv"
|
|
}
|
|
|
|
cmd_signals() {
|
|
need_dir "$1"; local root; root="$(cat "$AUDIT_DIR/.project_root")"
|
|
echo "Import/plugin hits — HINTS ONLY. Confirm by reading files before recording anything."
|
|
awk -F'\t' 'NR>1 && ($4=="source"||$4=="component"||$4=="server"||$4=="markup"||$4=="template"||$4=="build"||$4=="config"||$4=="test"||$4=="story"||$4=="style"||$4=="infra"||$4=="script") {print $6}' "$AUDIT_DIR/ledger.tsv" > "$AUDIT_DIR/.sig"
|
|
while IFS='|' read -r label re; do
|
|
hits=$(cd "$root" && tr '\n' '\0' < "$AUDIT_DIR/.sig" | xargs -0 grep -lE -- "$re" 2>/dev/null || true)
|
|
[ -n "$hits" ] || continue
|
|
printf ' %-34s %4d files e.g. %s\n' "$label" "$(printf '%s\n' "$hits" | wc -l)" "$(printf '%s\n' "$hits" | head -1)"
|
|
done <<'EOF'
|
|
React|from ['"]react['"]|"react":
|
|
Next.js|from ['"]next/|"next":
|
|
Remix / React Router framework|@remix-run/|@react-router/|"react-router":
|
|
Vue|from ['"]vue['"]|\.vue['"]|"vue":
|
|
Nuxt|"nuxt":|defineNuxtConfig|useFetch\(|useAsyncData\(
|
|
Svelte / SvelteKit|"svelte":|@sveltejs/kit|\$app/
|
|
Astro|"astro":|Astro\.props
|
|
Angular|@angular/core
|
|
SolidJS|from ['"]solid-js
|
|
Qwik|@builder\.io/qwik
|
|
Server components / actions|['"]use server['"]|['"]use client['"]
|
|
Tailwind CSS|tailwindcss|@tailwind |@import ['"]tailwindcss
|
|
CSS Modules|\.module\.(css|scss)
|
|
Sass/SCSS|"sass":|\.scss['"]
|
|
styled-components / Emotion|styled-components|@emotion/
|
|
vanilla-extract / Panda / StyleX|@vanilla-extract|@pandacss|@stylexjs
|
|
Radix / shadcn|@radix-ui/|components\.json|class-variance-authority
|
|
Headless UI / Ark / React Aria|@headlessui/|@ark-ui/|react-aria
|
|
MUI / Chakra / Mantine / Ant|@mui/|@chakra-ui/|@mantine/|from ['"]antd
|
|
Lucide / other icon sets|lucide-|@heroicons/|react-icons|@iconify
|
|
React Router|from ['"]react-router(-dom)?['"]
|
|
TanStack Router|@tanstack/react-router
|
|
Vue Router|vue-router
|
|
TanStack Query|@tanstack/(react|vue|svelte)-query|react-query
|
|
SWR|from ['"]swr['"]
|
|
Apollo / urql / GraphQL|@apollo/client|from ['"]urql|graphql-request|gql`
|
|
tRPC|@trpc/
|
|
axios / ky / ofetch|from ['"](axios|ky|ofetch)['"]
|
|
OpenAPI clients|openapi-fetch|openapi-typescript|@hey-api|orval
|
|
Redux / RTK|@reduxjs/toolkit|from ['"]redux|react-redux
|
|
Zustand / Jotai / Valtio|from ['"](zustand|jotai|valtio)
|
|
Pinia / Vuex|from ['"](pinia|vuex)['"]
|
|
XState|from ['"]xstate|@xstate/
|
|
React Hook Form / Formik|react-hook-form|from ['"]formik
|
|
TanStack Form / Superforms|@tanstack/(react-)?form|sveltekit-superforms
|
|
Zod / Yup / Valibot|from ['"](zod|yup|valibot)['"]
|
|
Express / Fastify / Koa|from ['"](express|fastify|koa)['"]|require\(['"](express|fastify|koa)['"]\)
|
|
Hono / Elysia|from ['"](hono|elysia)
|
|
NestJS|@nestjs/
|
|
Route handlers / API routes|export (async )?function (GET|POST|PUT|PATCH|DELETE)|export const (GET|POST)|pages/api/
|
|
Prisma|@prisma/client|PrismaClient
|
|
Drizzle|drizzle-orm
|
|
Kysely / Knex / TypeORM / Sequelize|from ['"](kysely|knex|typeorm|sequelize)
|
|
Mongoose / MongoDB|from ['"](mongoose|mongodb)['"]
|
|
Supabase|@supabase/
|
|
Firebase|from ['"]firebase/|firebase-admin
|
|
Redis|ioredis|from ['"]redis['"]|@upstash/redis
|
|
localStorage / IndexedDB|localStorage\.|sessionStorage\.|indexedDB|from ['"](idb|dexie|localforage)
|
|
Auth.js / NextAuth|next-auth|@auth/
|
|
Clerk / Auth0 / Lucia / Better Auth|@clerk/|@auth0/|from ['"]lucia|better-auth
|
|
JWT / sessions / cookies|jsonwebtoken|from ['"]jose['"]|iron-session|cookies\(\)|express-session
|
|
Background jobs / queues|bullmq|from ['"]bull['"]|inngest|trigger\.dev|@vercel/functions|qstash|graphile-worker|pg-boss
|
|
Cron / schedules|node-cron|cron-parser|"crons":|scheduled\(|schedule\(
|
|
Webhooks|webhook|stripe\.webhooks|svix
|
|
Service worker / PWA|serviceWorker\.register|workbox|vite-plugin-pwa|next-pwa|self\.addEventListener\(['"](fetch|install|push)
|
|
WebSockets / realtime|new WebSocket|socket\.io|from ['"]ws['"]|pusher|ably|EventSource
|
|
Stripe / payments|from ['"]stripe|@stripe/
|
|
i18n|i18next|react-intl|next-intl|vue-i18n|@formatjs|paraglide|lingui
|
|
Motion / animation|framer-motion|from ['"]motion|gsap|@react-spring|auto-animate
|
|
Charts / viz|recharts|from ['"]d3|chart\.js|@visx/|echarts|@nivo/|apexcharts
|
|
3D / canvas|from ['"]three|@react-three/|pixi\.js|konva
|
|
Dates|date-fns|dayjs|moment|luxon|@internationalized/date
|
|
Markdown / MDX|react-markdown|@mdx-js|remark-|rehype-|marked|shiki|prismjs
|
|
Sentry / error tracking|@sentry/|bugsnag|(^|[^A-Za-z])rollbar
|
|
Analytics|posthog|@vercel/analytics|plausible|@segment/|mixpanel|gtag\(|amplitude
|
|
Logging|from ['"](pino|winston)['"]|consola
|
|
Feature flags|launchdarkly|growthbook|@vercel/flags|unleash|flagsmith
|
|
Vitest|from ['"]vitest['"]|"vitest":
|
|
Jest|from ['"]@jest/|jest\.fn|"jest":
|
|
Testing Library|@testing-library/
|
|
Playwright|@playwright/test
|
|
Cypress|cypress
|
|
MSW|from ['"]msw
|
|
Storybook|@storybook/
|
|
Vite|from ['"]vite['"]|"vite":
|
|
Webpack / Rspack / Turbopack|webpack|@rspack|--turbo
|
|
ESLint / Prettier / Biome|eslint|prettier|@biomejs
|
|
Monorepo tooling|turbo\.json|nx\.json|pnpm-workspace|"workspaces":|lerna
|
|
Docker|^FROM |docker-compose
|
|
Vercel / Netlify / Cloudflare|vercel\.json|netlify\.toml|wrangler|@cloudflare/
|
|
No-build ES modules / import maps|<script type="module"|type="importmap"
|
|
FastAPI / Starlette|from fastapi|from starlette|import fastapi
|
|
Flask / Django|from flask|import flask|from django|django\.
|
|
Python DB (SQLAlchemy / sqlite3)|sqlalchemy|import sqlite3|from sqlmodel
|
|
Go HTTP (net/http, Gin, Echo, Chi)|"net/http"|gin-gonic|labstack/echo|go-chi
|
|
Rails / Sinatra|Rails\.application|ActiveRecord|require .sinatra
|
|
pytest|import pytest|def test_
|
|
Node test runner|from ['"]node:test['"]|node --test
|
|
EOF
|
|
rm -f "$AUDIT_DIR/.sig"
|
|
}
|
|
|
|
cmd_batch() {
|
|
need_dir "$1"; local size="${2:-40}"
|
|
rm -f "$AUDIT_DIR"/batches/batch-*.txt
|
|
# Pending files, grouped by module then path, so a batch stays within one area.
|
|
# Build + config files are expected to be handled in the orientation pass, so they sort first.
|
|
awk -F'\t' 'NR>1 && $7=="pending" { pr=($4=="build"||$4=="config")?0:1; print pr "\t" $2 "\t" $6 }' "$AUDIT_DIR/ledger.tsv" \
|
|
| sort -t$'\t' -k1,1n -k2,2 -k3,3 \
|
|
| awk -F'\t' -v size="$size" -v dir="$AUDIT_DIR/batches" '
|
|
{ if (n==0 || cnt>=size || ($2!=lastmod && cnt>=size/2)) { n++; cnt=0; f=sprintf("%s/batch-%03d.txt", dir, n) }
|
|
print $3 > f; cnt++; lastmod=$2 }
|
|
END { print n+0 " batches written to " dir }'
|
|
for f in "$AUDIT_DIR"/batches/batch-*.txt; do [ -f "$f" ] && printf ' %s %3d files %s\n' "$(basename "$f")" "$(wc -l < "$f")" "$(head -1 "$f")"; done
|
|
}
|
|
|
|
cmd_next() {
|
|
need_dir "$1"; local n="${2:-10}"
|
|
awk -F'\t' -v n="$n" 'NR>1 && $7=="pending" { pr=($4=="build"||$4=="config")?0:1; print pr "\t" $2 "\t" $6 }' "$AUDIT_DIR/ledger.tsv" \
|
|
| sort -t$'\t' -k1,1n -k2,2 -k3,3 | head -n "$n" | cut -f3
|
|
}
|
|
|
|
cmd_patterns() {
|
|
need_dir "$1"; local cat="${2:-}"
|
|
local files; if [ -n "$cat" ]; then valid_cat "$cat"; files="$AUDIT_DIR/library/$cat.md"; else files="$AUDIT_DIR/library/*.md"; fi
|
|
# shellcheck disable=SC2086
|
|
grep -H '^### \[' $files 2>/dev/null | sed 's#.*/library/\([^.]*\)\.md:\#\#\# \[\([^]]*\)\] *\(.*\)#\1\t\2\t\3#' \
|
|
| while IFS=$'\t' read -r c s t; do
|
|
occ=$(awk -F'\t' -v c="$c" -v s="$s" '$1==c && $2==s' "$AUDIT_DIR/occurrences.tsv" | wc -l)
|
|
printf '%-22s %-40s +%-3d %s\n' "$c" "$s" "$occ" "$t"
|
|
done
|
|
}
|
|
|
|
cmd_finding() {
|
|
need_dir "$1"; local cat="${2:?category}" slug="${3:?slug}" src="${4:?source-path}" title="${5:-}"
|
|
valid_cat "$cat"
|
|
[[ "$slug" =~ ^[a-z0-9][a-z0-9-]*$ ]] || die "slug must be kebab-case: $slug"
|
|
src="$(relpath "$src")"
|
|
local body; body="$(cat)"; [ -n "$body" ] || die "finding body (stdin) is empty"
|
|
local f="$AUDIT_DIR/library/$cat.md"
|
|
lock
|
|
# A workspace from an older skill version may lack a newer category's doc: seed it from the template.
|
|
[ -f "$f" ] || cp "$TEMPLATES/library/$cat.md" "$f"
|
|
if grep -q "^### \[$slug\]" "$f"; then
|
|
# Same pattern already documented: insert the refinement right after that entry's block.
|
|
printf '\n#### +[%s] refinement from `%s`\n%s\n\n' "$slug" "$src" "$body" > "$f.ins"
|
|
awk -v slug="$slug" -v ins="$f.ins" '
|
|
function flush() { while ((getline l < ins) > 0) print l; close(ins); done=1 }
|
|
/^### \[/ { if (inblk && !done) flush(); inblk = (index($0, "### [" slug "]")==1) }
|
|
{ print } END { if (!done) flush() }' "$f" > "$f.tmp" && mv "$f.tmp" "$f"; rm -f "$f.ins"
|
|
else
|
|
[ -n "$title" ] || { unlock; die "title required for new slug [$slug]"; }
|
|
printf '\n### [%s] %s\n- **Exemplar:** `%s`\n%s\n' "$slug" "$title" "$src" "$body" >> "$f"
|
|
fi
|
|
unlock
|
|
echo "recorded $cat/$slug from $src"
|
|
}
|
|
|
|
cmd_phase() {
|
|
need_dir "$1"; local name="${2:?phase name}"
|
|
lock; printf '%s\t%s\n' "$(now_ms)" "${name//$'\t'/ }" >> "$AUDIT_DIR/timeline.tsv"; unlock
|
|
echo "phase '$name' started"
|
|
}
|
|
|
|
cmd_usage() { need_dir "$1"; shift; python3 -I "$SELF_DIR/usage.py" "$AUDIT_DIR" "$@"; }
|
|
|
|
cmd_finish() {
|
|
need_dir "$1"
|
|
[ -f "$AUDIT_DIR/.finished_at" ] || now_ms > "$AUDIT_DIR/.finished_at"
|
|
python3 -I "$SELF_DIR/usage.py" "$AUDIT_DIR" > "$AUDIT_DIR/usage.md"
|
|
python3 -I "$SELF_DIR/usage.py" "$AUDIT_DIR" --json > "$AUDIT_DIR/usage.json"
|
|
cat "$AUDIT_DIR/usage.md"
|
|
}
|
|
|
|
cmd_none() {
|
|
need_dir "$1"; local cat="${2:?category}" what="${3:?what was looked for}"
|
|
valid_cat "$cat"; lock
|
|
printf '\n### [none] None found in code\n- **Exemplar:** `(project)`\n- Looked for: %s\n' "$what" >> "$AUDIT_DIR/library/$cat.md"
|
|
unlock; echo "recorded absence in $cat"
|
|
}
|
|
|
|
cmd_also() {
|
|
need_dir "$1"; local cat="${2:?category}" slug="${3:?slug}" src="${4:?source-path}"
|
|
valid_cat "$cat"; src="$(relpath "$src")"
|
|
grep -q "^### \[$slug\]" "$AUDIT_DIR/library/$cat.md" || die "no pattern [$slug] in $cat.md — record it with 'finding' first"
|
|
lock; printf '%s\t%s\t%s\n' "$cat" "$slug" "$src" >> "$AUDIT_DIR/occurrences.tsv"; unlock
|
|
}
|
|
|
|
cmd_mark() {
|
|
need_dir "$1"; local src="${2:?source-path}" st="${3:?status}" note="${4:-}"
|
|
case "$st" in contributed|redundant|trivial|skipped) ;; *) die "status must be contributed|redundant|trivial|skipped";; esac
|
|
src="$(relpath "$src")"; note="${note//$'\t'/ }"; note="${note//$'\n'/ }"
|
|
lock
|
|
awk -F'\t' -v OFS='\t' -v p="$src" -v s="$st" -v n="$note" '
|
|
NR>1 && $6==p { $7=s; $8=n; hit=1 } { print }
|
|
END { if (!hit) exit 3 }' "$AUDIT_DIR/ledger.tsv" > "$AUDIT_DIR/ledger.tmp" \
|
|
&& mv "$AUDIT_DIR/ledger.tmp" "$AUDIT_DIR/ledger.tsv" \
|
|
|| { rm -f "$AUDIT_DIR/ledger.tmp"; unlock; die "path not in ledger: $src"; }
|
|
unlock
|
|
}
|
|
|
|
cmd_coverage() {
|
|
need_dir "$1"
|
|
awk -F'\t' 'NR>1 { c[$7]++; t++ } END { for (k in c) printf " %-12s %5d (%.0f%%)\n", k, c[k], 100*c[k]/t; printf " %-12s %5d\n", "total", t }' "$AUDIT_DIR/ledger.tsv"
|
|
echo "Patterns documented: $(grep -h '^### \[' "$AUDIT_DIR"/library/*.md | wc -l) extra occurrences: $(($(wc -l < "$AUDIT_DIR/occurrences.tsv")-1))"
|
|
local p; p=$(awk -F'\t' 'NR>1 && $7=="pending"' "$AUDIT_DIR/ledger.tsv" | wc -l)
|
|
if [ "$p" -gt 0 ]; then
|
|
echo "PENDING: $p (first 20):"; awk -F'\t' 'NR>1 && $7=="pending" {print " " $6}' "$AUDIT_DIR/ledger.tsv" | head -20
|
|
else echo "All files accounted for."; fi
|
|
}
|
|
|
|
# Files whose status disagrees with the library: contributed with no finding, redundant with no occurrence.
|
|
mismatches() {
|
|
cat "$AUDIT_DIR"/library/*.md | grep -oE '^- \*\*Exemplar:\*\* `[^`]+`|^#### \+\[[^]]+\] refinement from `[^`]+`' \
|
|
| sed 's/.*`\([^`]*\)`$/\1/' | sort -u > "$AUDIT_DIR/.contrib"
|
|
awk -F'\t' 'NR>1 {print $3}' "$AUDIT_DIR/occurrences.tsv" | sort -u > "$AUDIT_DIR/.occ"
|
|
awk -F'\t' -v c="$AUDIT_DIR/.contrib" -v o="$AUDIT_DIR/.occ" '
|
|
BEGIN { while ((getline l < c) > 0) C[l]=1; while ((getline l < o) > 0) O[l]=1 }
|
|
NR>1 && $7=="contributed" && !($6 in C) { print " contributed but no finding cites it: " $6 }
|
|
NR>1 && $7=="redundant" && !($6 in O) && !($6 in C) { print " redundant but no occurrence logged: " $6 }' "$AUDIT_DIR/ledger.tsv"
|
|
rm -f "$AUDIT_DIR/.contrib" "$AUDIT_DIR/.occ"
|
|
}
|
|
|
|
cmd_gate() {
|
|
need_dir "$1"; cmd_coverage "$1"
|
|
local p m; p=$(awk -F'\t' 'NR>1 && $7=="pending"' "$AUDIT_DIR/ledger.tsv" | wc -l); m="$(mismatches)"
|
|
[ -n "$m" ] && { echo "Status/library mismatches:"; echo "$m"; }
|
|
[ "$p" -eq 0 ] && [ -z "$m" ] && { echo "GATE: PASS"; return 0; }
|
|
echo "GATE: FAIL"; return 1
|
|
}
|
|
|
|
sub="${1:-}"; shift || true
|
|
case "$sub" in
|
|
init) cmd_init "$@";; tree) cmd_tree "$@";; signals) cmd_signals "$@";; batch) cmd_batch "$@";;
|
|
next) cmd_next "$@";; patterns) cmd_patterns "$@";; finding) cmd_finding "$@";; also) cmd_also "$@";;
|
|
mark) cmd_mark "$@";; coverage) cmd_coverage "$@";; gate) cmd_gate "$@";; none) cmd_none "$@";;
|
|
phase) cmd_phase "$@";; usage) cmd_usage "$@";; finish) cmd_finish "$@";;
|
|
""|-h|--help|help) sed -n '2,28p' "$0";;
|
|
*) sed -n '2,28p' "$0"; exit 2;;
|
|
esac
|