AGENT SKILL

audit-code-map

Generate or refresh `docs/code-map.md` — a structural map of the project's classes, top-level functions, and import graph across Python, TypeScript/JavaScript, Go, and Rust. Use when the user wants a code map, structure overview, dependency graph, module inventory, "show me how everything is wired", DRY hotspot scout, or a refreshable architecture summary.

License 许可
MIT
最近更新
2026-10-23
Stars
★ 0
Forks
0

01 前言 Front Matter

name
audit-code-map
description
Generate or refresh `docs/code-map.md` — a structural map of the project's classes, top-level functions, and import graph across Python, TypeScript/JavaScript, Go, and Rust. Use when the user wants a code map, structure overview, dependency graph, module inventory, "show me how everything is wired", DRY hotspot scout, or a refreshable architecture summary.

02 资源文件 2

03 SKILL.md 正文

audit-code-map

Generates docs/code-map.md — file inventory, per-file class/function lists, import graph — for Python (full AST), TS/JS, Go and Rust (regex), with Python 3.8+ stdlib only. With --emit-json it also writes docs/code-map.json, the structured artifact consumed by the forge-code-map MCP server at mcp-servers/code-map/.

Index

File or section Read when…
Steps 1–4 (below) Every invocation
Tools/code_map.py Run it (step 1) — the analyzer
Flags (below) Choosing options; when the SessionStart hook co-emits JSON
Integration with the framework (below) Checking which hook, agent or skill reads the map before changing its format
PHASES.md Extending the analyzer (skill maintainers)

Invocation

User runs:

/audit-code-map [flags] — generate or refresh docs/code-map.md. Flags: the table below; Tools/code_map.py --help is the source of truth.


Step 1: Detect

Run the analyzer:

python3 .claude/skills/audit-code-map/Tools/code_map.py [args]

The script:

  1. Walks the repo (uses git ls-files when available so .gitignore is honored; falls back to Path.rglob with a sensible exclude set).
  2. Identifies language by extension. Languages NOT in {python, ts, tsx, js, jsx, mjs, cjs, go, rs} are skipped silently.
  3. Detects stack manifests at the root (package.json, pyproject.toml, requirements.txt, go.mod, Cargo.toml, etc.).

Step 2: Parse

Per file, extract top-level symbols:

Language Strategy Extracts
Python stdlib ast (full parse) classes, top-level functions, import + from … import
TypeScript / JavaScript regex class X, function X, export const X = ( arrow functions, import … from '…'
Go regex type X struct/interface, func X( (incl. methods), import "…" (single + grouped)
Rust regex pub struct/enum/trait, pub fn/async fn, use

Regex parsing is best-effort — multi-line declarations and unusual formatting may be missed. The Python AST path is exact.

Step 3: Render

Produces docs/code-map.md with these sections:

  1. Generated metadata — timestamp (UTC), root path, total files, total LOC.
  2. Stack — detected manifests + per-language file/LOC table sorted by LOC.
  3. Largest files (top 20) — file path, lang, LOC, class count, function count.
  4. DRY hotspots — symbols declared in 3+ files of the same language (cheap duplication signal).
  5. Directories needing context files — directories over ~20k estimated tokens (bytes ÷ 4, by immediate parent dir) that lack a nested CLAUDE.md/AGENTS.md. The "Intent Layer" heuristic — a context file here points the model at the right files instead of re-discovering structure each session. Advisory only: candidates, never auto-created.
  6. Module symbols — per-file listing of top-level classes and functions, capped at --max-symbols-per-file (default 15) with … overflow indicator.
  7. Import graph — directory-level (first-path-segment) Mermaid flowchart LR, edge labels = import frequency, capped at top-100 edges.

Step 4: Commit (when running inside an Algorithm phase)

If the skill was fired by another skill or by the Algorithm BUILD phase, commit the regenerated map:

git add docs/code-map.md
git commit -m "docs(code-map): regenerate"

Standalone invocations leave the file unstaged so the user can review the diff.


Flags

Flag Default Effect
--root PATH cwd Project root to analyze
--output PATH <root>/docs/code-map.md Where to write the map
--no-mermaid off Skip the Mermaid import-graph section (faster, smaller file)
--include-tests off Include tests/, *.test.*, *.spec.*, *_test.* files
--max-symbols-per-file N 15 Cap per-file symbol listings
--emit-json off Also write docs/code-map.json — structured artifact for the forge-code-map MCP server
--json-output PATH <root>/docs/code-map.json Custom JSON output path. Implies --emit-json.

When does the SessionStart hook co-emit JSON?

The --ensure-fresh path used by hooks/session/session-context.py co-emits docs/code-map.json automatically when the JSON already exists alongside the markdown. The contract: if you've opted into the MCP server once (by running /audit-code-map --emit-json), every subsequent session keeps the JSON fresh without further intervention. If you don't want the JSON, don't generate it — the hook will only co-emit if it sees an existing JSON to refresh.

When to use

  • Onboarding into a new or unfamiliar codebase — quick structural overview
  • Pre-refactor scout — identify largest files, complex modules, cross-cutting imports
  • After a feature lands — regenerate the map so newcomers see the new shape
  • Light DRY check — the largest-files table surfaces obvious extraction candidates
  • Algorithm OBSERVE phase, when scoping a refactor or large change

Integration with the framework

The map isn't a static artifact you generate and forget — it's wired into the runtime so agents and skills consult it without prompting:

Integration What it does
SessionStart hook (hooks/session/session-context.py) Calls code_map.py --ensure-fresh on every session start. Regenerates docs/code-map.md if it's missing or older than the youngest source file, then injects a ~150-token summary block (file count, LOC, language mix, modules, top-10 largest files) into session context.
Stale-on-load regen (built into --ensure-fresh) Compares map mtime to the youngest source file. If the map is behind, regenerates it before injecting. The map can never silently lie about the codebase.
Framework agents (@architect, @project-manager, @quality-engineer, @security-boss, @devops) Every framework agent's ## Project conventions I respect block includes "read docs/code-map.md before X". The map is part of their working context the moment they're invoked.
Planning skills (/new-feature, /run-epic) Each has a "Step 0: Map the surface" that reads docs/code-map.md before classification or planning. Prevents proposals that duplicate existing capability.
forge-code-map MCP server (mcp-servers/code-map/) Optional. Reads docs/code-map.json and exposes 5 tools (find_definition, find_references, dependents_of, list_symbols_in_file, language_stats). Opt in by running /audit-code-map --emit-json once and registering the server in .claude/settings.json — see mcp-servers/code-map/README.md.

The result: agents and skills know what already exists before suggesting changes. No more "build feature X" recommendations when X mostly already lives at src/lib/x.py. No more "extract method Y" suggestions when Y already exists in a sibling module.

The summary block injected at SessionStart looks like this:

=== CODE MAP ===
Files: 42 | LOC: 10,418 | Langs: python:10,418
Modules: hooks, scripts, security, skills
Top 10 largest:
  scripts/forge/check_consistency.py (745 LOC)
  ...
Full map: docs/code-map.md
===

When a deeper read is needed, the model uses Read docs/code-map.md to pull the full map (file inventory, per-file symbols, Mermaid import graph).

Limitations (known)

  • Polyglot regex parsers can miss exotic syntax (computed class names, dynamically-named functions, decorators-as-classes). The Python AST path is exact.
  • The import graph collapses to first-path-segment nodes (src/api/users.ts → src/api); file-to-file edges would explode and become unreadable.
  • C, C++, Java, Ruby, PHP, Swift, Kotlin, etc. — not yet supported. Files in these languages are silently skipped.

Prerequisites

  • Python 3.8+ (uses Path type hints, dataclasses, subprocess.run(timeout=...))
  • Git installed (optional — falls back to filesystem walk if absent)

See also

  • skills/audit-code-map/PHASES.md — phase walkthrough for skill maintainers
  • skills/audit-code-map/Tools/code_map.py — the analyzer
  • agents/README.md — @architect is the natural follow-up consumer of the map for ADR work

Project-specific overrides: if SKILL.local.md exists in this directory, read it — it is consumer-owned, survives framework refresh, and wins on conflict. A sidecar that relaxes a gate defined above must state how to prove the gate is wrong in that case. Doctrine: rules/framework-vs-project-root.md.

04 同仓库更多 Skills

rynhardt81
rynhardt81/forgeFlow

wizard

Generates an interactive bash wizard that walks a human through steps only they can perform — opens each URL, says what to click and copy, captures values (hidden entry for secrets), writes .env and GitHub secrets, confirms before irreversible actions. Use when provisioning infrastructure, setting up credentials or CI secrets, walking an unfamiliar third-party dashboard, or running a one-off migration or cutover. Don't invoke this for steps the agent can perform itself.

★ 0
rynhardt81
rynhardt81/forgeFlow

vet-idea

Vets an idea, decision, or plan BEFORE it is built. Runs a single model through five fixed adversarial advisor roles, a peer-review pass, and a chairman synthesis that emits a halt-capable GO / NO-GO / RECONSIDER verdict. Advisory and non-mutating — outputs a report, never writes task state. Use when an idea, feature, or costly hard-to-reverse decision is of uncertain worth and the question is whether to build it at all. NOT FOR settled work (bug fixes, approved features) or for shaping how to build it (the ISA Interview workflow).

★ 0
rynhardt81
rynhardt81/forgeFlow

triage-incident

Production incident triage — from "something is broken for users" to fixed, verified, and learned-from. Pulls the error signal (Sentry/logs/user report), reproduces before touching code, routes the fix through /fix-bug's prod fast path, and closes with a postmortem entry. Use when something is broken for users in production — an outage, data corruption, a Sentry spike, or a crash-rate alert. NOT FOR bugs found in development (use /fix-bug directly) or CI failures (use /diagnose-ci).

★ 0
rynhardt81
rynhardt81/forgeFlow

setup-review-bot

Configures a repo's AI code reviewers — the post-PR mention bot and the pre-push local reviewer — and writes the AGENTS.md the reviewers read. Interviews the user for what the reviewer should weight, then sets git config forge.reviewBot / forge.localReview and populates AGENTS.md at the project root. Use when a repo has no reviewer configured, when review findings are consistently off-target, or when onboarding a new project.

★ 0
rynhardt81
rynhardt81/forgeFlow

security-review

Portable security review for a feature, endpoint, or change before it ships. Orchestrates the existing OWASP review (@security-boss) and secrets scan (security_secrets validator), then adds the pass they miss — an explicit business-logic-flaw walkthrough (IDOR, race/TOCTOU, state-machine bypass, privilege escalation, price/quantity tampering). Advisory and non-mutating — produces a findings report; real findings are filed as tasks. Use when a change touching money, access control, or multi-step state is about to ship, or when the auth looks fine but the flow could be abused. NOT FOR SAST or dependency-CVE scanning (consumer CI owns those).

★ 0
rynhardt81
rynhardt81/forgeFlow

run-epic

Autonomously drains every open task in a single epic. Pulls ready tasks via the forge CLI, executes the work in-context using the matching discipline (fix-bug / new-feature / refactor), files newly-discovered work as follow-up tasks without stopping to ask, opens a PR per completed task via /create-pr, and repeats until the epic has zero ready/in-progress/pending tasks. Use when the user says `/run-epic E##`, "run epic autonomously", "finish all remaining tasks for epic X", or "drive epic X to completion".

★ 0