Lines 1-47javascript
2// SPDX-License-Identifier: MIT
3// ============================================================================
4// agentmap — the repo map your coding agent is *forced* to use.
6// A ts-morph code-relationship map for TypeScript/JavaScript repos. Unlike
7// one-shot "pack the repo into a prompt" tools, this is a QUERYABLE, RANKED
8// map: PageRank importance (approach from Aider's repo map), Aider-style
9// symbol ranking, a token-budgeted `--map` digest, and a single `--any`
10// router (file → symbol → feature → live git-grep) — wired into the agent
11// loop via a post-commit auto-refresh + a PreToolUse hook.
13// Near-zero deps (ts-morph only). Runs in the target repo's cwd.
14// Algorithm credit: Aider's repo map (Apache-2.0) — github.com/Aider-AI/aider
15// ============================================================================
16import { writeFileSync, readFileSync, existsSync, mkdirSync, renameSync, readdirSync, lstatSync, chmodSync } from "node:fs";
17import { execSync, execFileSync } from "node:child_process";
18import { createHash } from "node:crypto";
19import { createRequire } from "node:module";
20import { homedir } from "node:os";
21import { fileURLToPath } from "node:url";
22import { join, dirname } from "node:path";
24// Lazy ts-morph: its ~105ms module init only fires on a COLD rebuild. Warm cache
25// queries (the common case) never construct a Project, so they skip the load
26// entirely (~2x faster warm). createRequire keeps it synchronous — no async to
27// thread through build()/makeProject().
28const _require = createRequire(import.meta.url);
29let _tsm = null;
MediumDynamic Require
Package source references dynamic require/import behavior.
agentmap.mjsView on unpkg · L27 30const tsMorph = () => (_tsm ??= _require("ts-morph"));
32const MAP = ".claude/agentmap/map.json";
33const MAP_LEGACY = ".claude/agentmap.json"; // pre-namespacing path; read for migration
34// Bumped 2 → 3: Vue SFC support. `.vue` files now appear in the map and the
35// source-discovery / freshness checks treat them as first-class source files.
36// Old caches (schema 2) are ignored so the first run after upgrade rebuilds.
37const SCHEMA_VERSION = 3;
39// ---------------------------------------------------------------------------
40// Tuning constants — KEEP THESE VALUES IDENTICAL (output + marketing must not
41// shift). Hoisted out of inline literals so the algorithm is self-documenting.
42// ---------------------------------------------------------------------------
43const DAMPING = 0.85; // PageRank damping (Aider parity)
44const TOL = 1e-6; // power-iteration convergence tolerance
45const MAX_ITER = 100; // power-iteration iteration cap
46const IDENT_BOOST = 10; // weight ×: mentioned ident, or long multi-word ident
47const RARE_PENALTY = 0.1; // weight ×: ident defined in >RARE_DEFINERS files (too common)
LowWeak Crypto
Package source references weak cryptographic algorithms.
agentmap.mjsView on unpkg · L16