Skip to content

Commit ad1dd25

Browse files
committed
docs: sync CLI and agent docs with shipped capabilities.
README and --help now cover apply, skill/rule, audit, and MCP resources; lessons and agent rules use the pointer-protocol maintenance model and .codemap/index.db paths; clean script preserves .codemap/ after consolidation.
1 parent b4de377 commit ad1dd25

9 files changed

Lines changed: 33 additions & 13 deletions

File tree

.agents/lessons.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ Each entry is a single bullet: `- **<topic>** — <lesson>`. Newest entries at t
88

99
## Lessons
1010

11-
- **changesets bump policy (pre-v1)** — while in `0.x`, default to **patch** for everything (additive features, fixes, docs, internal refactors); reserve **minor** for schema-breaking changes that force a `.codemap.db` rebuild (matches 0.2.0 precedent: new tables/columns/`SCHEMA_VERSION` bump). Strict SemVer kicks in only after `1.0.0`. Don't propose `minor` just because new CLI commands or public types were added.
12-
- **agent rule + skill maintenance** — when shipping a CLI flag, recipe id, recipe `actions` template, schema column, or any agent-queryable surface, update **both** copies of the codemap rule + skill in the **same PR** per [docs/README.md Rule 10](../docs/README.md): `templates/agents/rules/codemap.md` + `templates/agents/skills/codemap/SKILL.md` (ships to npm) **and** `.agents/rules/codemap.md` + `.agents/skills/codemap/SKILL.md` (this clone's mirror). Drift between the two pairs should be CLI-prefix-only (`codemap` vs `bun src/index.ts`). Forgetting this leaves installed agents with a stale view of the CLI — that's how `--summary` / `--changed-since` / `--group-by` / `actions` / `symbols.visibility` shipped without any `templates/agents/` mention until PR #29 retro-fixed it.
11+
- **changesets bump policy (pre-v1)** — while in `0.x`, default to **patch** for everything (additive features, fixes, docs, internal refactors); reserve **minor** for schema-breaking changes that force a `.codemap/index.db` rebuild (matches 0.2.0 precedent: new tables/columns/`SCHEMA_VERSION` bump). Strict SemVer kicks in only after `1.0.0`. Don't propose `minor` just because new CLI commands or public types were added.
12+
- **agent-content maintenance (pointer protocol)** — when shipping a CLI flag, recipe id, recipe `actions` template, schema column, or any agent-queryable surface, follow [docs/README.md Rule 10](../docs/README.md) in the **same PR**: (1) **recipes**`templates/recipes/*.{sql,md}` (auto-flows via `20-recipes.gen.md`); (2) **schema** `src/db.ts` (auto-flows via `30-schema.gen.md`); (3) **narrative** (flags, MCP/HTTP tools, output shapes) → hand-written `templates/agent-content/skill/*.md`; (4) **pointer shape** only → `templates/agents/{rules/codemap,skills/codemap/SKILL}.md` + bump `EXPECTED_POINTER_VERSION` in `agent-content.ts`. Consumer pointers in `.agents/` regenerate via `bun src/index.ts agents init --force` when shape changes — no fat dual-copy sync. Pre-pointer mistake: editing only `.agents/` and leaving served content stale.
1313
- **backticks inside SQL or help-text template literals** — never put a literal backtick inside a `` `...` `` template-literal string. `db.ts` SQL DDL strings (multi-line CREATE TABLE templates) and `printQueryCmdHelp()` (multi-line help text) are both `` `...` `` template literals; an inner backtick — typically a Markdown-style code-fence around a flag like `` `--full` `` — terminates the literal early and the parser blows up several lines later with cryptic "expected `,` or `)`" errors. **Use plain prose in those strings** (`--full` not `` `--full` ``), or escape (`` \` ``) if you really need the character. Hit twice (B.7 + B.6 PR #30); the lesson is general — applies to any TS template literal that gets pasted prose later, not just SQL / help text.
1414
- **STOP-before-Grep applies to symbol lookups too**`Grep` for symbol names like `printQueryResult`, `getCurrentCommit`, `dropAll` violates the [`codemap` rule](rules/codemap.md). The codemap query `SELECT file_path, line_start FROM symbols WHERE name = '<X>'` answers it faster and without scanning. Reach for `Grep` only when the question is content-shaped (regex over file bodies, finding pattern usages inside function bodies, etc.) — not when it's "where is X defined / who calls X / what does file Y export." This was a PR #30 self-correction.
1515
- **PR / issue / comment bodies always go through a temp file** — never pass markdown bodies via shell heredoc to `gh pr create --body "$(cat <<'EOF'…)"` / `gh pr edit --body …` / `gh pr comment --body …` / `gh issue create --body …` / `gh api` `--field body=…`. Backticks inside the heredoc (every code span and code fence) get shell-escaped to `\`` and render literally on GitHub — every recipe id, file path, flag, SQL fragment, and code fence in the rendered body comes out as `\`coverage\``instead of`coverage`. Pattern: write the body to a temp file (`Write`to`/tmp/pr-<n>-body.md`), pass `--body-file /tmp/pr-<n>-body.md`, then delete the temp file. Cost is one extra tool call; saves redoing every PR body that has more than a few backticks. Hit on PR #57 — final body was a wall of `\`` artifacts until rewritten via temp file.

.agents/rules/agents-tier-system.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Today's Tier-2 rules:
5151

5252
Pure intent-triggered. The skill description is detailed enough that Cursor surfaces it on relevant phrases. No always-on cost.
5353

54-
Skills stay rule-less when the work is **explicitly invoked** by the user, not pattern-triggered. Today: `audit-pr-architecture`, `diagnose`, `docs-governance`, `docs-lifecycle-sweep`, `grill-me`, `improve-codebase-architecture`, `write-a-skill`. (Skills like `gritql-codemods` and `ubiquitous-language` would also fit this tier if adopted.)
54+
Skills stay rule-less when the work is **explicitly invoked** by the user, not pattern-triggered. Today: `audit-pr-architecture`, `diagnose`, `docs-governance`, `docs-lifecycle-sweep`, `grill-me`, `improve-codebase-architecture`, `pr-comment-fact-check`, `write-a-skill`. (Skills like `gritql-codemods` and `ubiquitous-language` would also fit this tier if adopted.)
5555

5656
## Authoring guidelines
5757

.agents/rules/tracer-bullets.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ AI agents tend to produce complete solutions in one leap — all parsers, all sc
2222

2323
A typical vertical slice for Codemap touches these layers top-to-bottom:
2424

25-
1. **CLI / orchestration**`src/index.ts` (args, incremental vs full, `query` subcommand)
26-
2. **Workers / parsing**`src/parse-worker.ts`, `src/parser.ts`, `src/css-parser.ts`
25+
1. **CLI / orchestration**`src/cli/` (`bootstrap.ts`, `main.ts`, lazy `cmd-*` chunks; entry `src/index.ts`)
26+
2. **Workers / parsing**`src/parse-worker.ts` / `parse-worker-node.ts`, `parse-worker-core.ts`, `src/parser.ts`, `src/css-parser.ts`, `src/adapters/`
2727
3. **Persistence**`src/db.ts` (schema, inserts, `SCHEMA_VERSION`)
2828
4. **Config / runtime**`src/config.ts`, `src/runtime.ts`, resolver
2929
5. **Tests**`src/*.test.ts`
@@ -38,7 +38,7 @@ Bad — building in layers:
3838

3939
Good — tracer bullet:
4040

41-
1. **`constants` + parser language**`LANG_MAP` + `extractFileData` / worker `TS_EXTENSIONS` — commit, `bun run check`, small test parsing a one-line file
41+
1. **`constants` + adapter**`LANG_MAP` + builtin adapter extensions + `extractFileData` — commit, `bun run check`, small test parsing a one-line file
4242
2. **Resolver**`resolver` extensions if needed — commit, validate
4343
3. **Docs**`docs/architecture.md` table row — commit, validate
4444

.agents/skills/diagnose/SKILL.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Spend disproportionate effort here. **Be aggressive. Be creative. Refuse to give
1919

2020
1. **Failing test** at whatever seam reaches the bug — unit, integration, e2e. Codemap convention: `src/**/<name>.test.ts` for unit + integration; `fixtures/golden/` for query-shape regressions; `bun test <file>` runs them.
2121
2. **CLI invocation** with a fixture input, diffing stdout against a known-good snapshot. Examples: `bun src/index.ts query --json …` against `fixtures/minimal/`, golden runner under `scripts/query-golden.ts`.
22-
3. **Replay a captured trace.** Save a real `.codemap.db` / config / fixture file to disk; replay it through the code path in isolation.
22+
3. **Replay a captured trace.** Save a real `.codemap/index.db` / config / fixture file to disk; replay it through the code path in isolation.
2323
4. **Throwaway harness.** Spin up a minimal subset (one parser, one DB connection) that exercises the bug code path with a single function call.
2424
5. **Property / fuzz loop.** If the bug is "sometimes wrong output", run 1000 random inputs and look for the failure mode.
2525
6. **Bisection harness.** If the bug appeared between two known states (commit, dataset, version), automate "boot at state X, check, repeat" so you can `git bisect run` it.
@@ -44,7 +44,7 @@ The goal is not a clean repro but a **higher reproduction rate**. Loop the trigg
4444

4545
### When you genuinely cannot build a loop
4646

47-
Stop and say so explicitly. List what you tried. Ask the user for: (a) access to whatever environment reproduces it, (b) a captured artifact (HAR file, log dump, core dump, screen recording with timestamps, broken `.codemap.db`), or (c) permission to add temporary instrumentation. Do **not** proceed to hypothesise without a loop.
47+
Stop and say so explicitly. List what you tried. Ask the user for: (a) access to whatever environment reproduces it, (b) a captured artifact (HAR file, log dump, core dump, screen recording with timestamps, broken `.codemap/index.db`), or (c) permission to add temporary instrumentation. Do **not** proceed to hypothesise without a loop.
4848

4949
Do not proceed to Phase 2 until you have a loop you believe in.
5050

.agents/skills/pr-comment-fact-check/SKILL.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ These come up repeatedly with LLM reviewers and warrant extra scrutiny. The code
165165
7. **Memory-leak / resource-leak claims with no concrete trigger** — "this could leak the SQLite handle" without a scenario is speculation; ask for the path. Codemap closes DB handles via the `using` pattern in most call sites — verify before accepting.
166166
8. **Type-safety alarms** — if `tsgo --noEmit` (`bun run typecheck`) passes, the claim is almost always wrong (or about runtime behaviour the type system can't see, in which case the reviewer should justify with the runtime case).
167167
9. **Convention citations that don't exist** — "This breaks our API conventions" — grep `.agents/` and `docs/` for the convention. If it's not codified, it's preference, not rule.
168-
10. **Schema-bump / changeset alarms** — "this needs a minor changeset" — check [`.agents/lessons.md`](../../lessons.md) ("changesets bump policy"): pre-v1, default is patch unless the schema actually breaks the `.codemap.db` (new tables/columns/SCHEMA_VERSION bump). Don't accept "minor for new CLI commands or public types".
168+
10. **Schema-bump / changeset alarms** — "this needs a minor changeset" — check [`.agents/lessons.md`](../../lessons.md) ("changesets bump policy"): pre-v1, default is patch unless the schema actually breaks `.codemap/index.db` (new tables/columns/`SCHEMA_VERSION` bump). Don't accept "minor for new CLI commands or public types".
169169

170170
## Anti-patterns
171171

.github/CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ bun test
1414
bun run test:golden # golden SQL vs fixtures/minimal (also runs at end of `bun run check`)
1515
bun run test:golden:external # Tier B: local tree via CODEMAP_ROOT / --root (not in CI)
1616
bun run check # format + lint + tests + typecheck + build + test:golden
17-
bun run clean # remove untracked/ignored build artifacts (keeps `.env`, `.codemap.db*`)
17+
bun run clean # remove untracked/ignored build artifacts (keeps `.env`, `.codemap/`)
1818
bun run check-updates # interactive dependency updates (`bun update -i --latest`)
1919
```
2020

README.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ codemap context --compact --for "refactor auth" # JSON envelope + i
5555
codemap ingest-coverage coverage/coverage-final.json --json # Istanbul / LCOV (auto-detected) → coverage table; joins with symbols
5656
NODE_V8_COVERAGE=.cov bun test && codemap ingest-coverage .cov --runtime --json # V8 protocol (per-process dumps); local-only
5757
codemap agents init # scaffold .agents/ rules + skills
58+
codemap apply rename-preview --params old=foo,new=bar --dry-run # preview recipe-driven edits (substrate executor)
5859
```
5960

6061
**Version-matched agent guidance:** `codemap agents init` writes **thin pointer files** to `.agents/` (~16-line SKILL.md + ~22-line rule). The full content is served live by **`codemap skill`** / **`codemap rule`** (CLI) and **`codemap://skill`** / **`codemap://rule`** (MCP / HTTP) — so `bun update @stainless-code/codemap` auto-refreshes the content agents see, no re-init needed. See [docs/agents.md](docs/agents.md).
@@ -197,11 +198,23 @@ codemap impact runWatchLoop --json --summary | jq '.summary.nodes' # CI-gate fa
197198
# (default 3, --depth 0 = unbounded), limit-capped (default 500). Result envelope:
198199
# {target, matches: [{depth, edge, kind, name?, file_path}], summary: {nodes, terminated_by}}.
199200

201+
# Apply — substrate-shaped fix executor (recipe SQL describes hunks; codemap validates + writes)
202+
codemap apply rename-preview --params old=usePermissions,new=useAccess,kind=function --dry-run
203+
codemap apply rename-preview --params old=usePermissions,new=useAccess,kind=function --yes # TTY prompts without --yes
204+
# Consumes the --format diff-json row contract ({file_path, line_start, before_pattern, after_pattern}).
205+
# All-or-nothing: any conflict aborts before any file is written. Pair with --format diff-json preview first.
206+
207+
# Live agent content (pointer protocol — full body served from installed package version)
208+
codemap skill # full codemap SKILL markdown to stdout
209+
codemap rule # full codemap rule markdown to stdout
210+
200211
# MCP server (Model Context Protocol) — for agent hosts (Claude Code, Cursor, Codex, generic MCP clients)
201212
codemap mcp # JSON-RPC on stdio; one tool per CLI verb plus query_batch
202213
# Tools: query, query_batch (MCP-only — N statements in one round-trip), query_recipe, audit,
203-
# save_baseline, list_baselines, drop_baseline, context, validate, show, snippet, impact
204-
# Resources: codemap://schema, codemap://skill, codemap://rule (lazy-cached); codemap://recipes, codemap://recipes/{id} (live read-per-call — keep recency fresh)
214+
# save_baseline, list_baselines, drop_baseline, context, validate, show, snippet, impact, apply
215+
# Resources: codemap://schema, codemap://skill, codemap://rule (lazy-cached);
216+
# codemap://recipes, codemap://recipes/{id} (live read-per-call — recency fields stay fresh);
217+
# codemap://files/{path}, codemap://symbols/{name} (live per-file / per-symbol roll-ups)
205218
# Output shape verbatim from `--json` envelopes (no re-mapping). Snake_case throughout.
206219

207220
# Another project

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"check-updates": "bun update -i --latest",
5151
"check:perf-baseline": "bun scripts/check-perf-baseline.ts",
5252
"check:perf-baseline:update": "bun scripts/check-perf-baseline.ts --update",
53-
"clean": "git clean -xdf -e .env -e .codemap.db -e .codemap.db-wal -e .codemap.db-shm",
53+
"clean": "git clean -xdf -e .env -e .codemap",
5454
"dev": "bun src/index.ts",
5555
"fix": "bun run lint:fix && bun run format",
5656
"format": "oxfmt",

src/cli/bootstrap.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,15 @@ Validate (compare on-disk SHA-256 to indexed hash):
2929
Context (project snapshot envelope for any agent):
3030
codemap context [--compact] [--for "<intent>"]
3131
32+
Audit (structural drift — baseline snapshots or git ref):
33+
codemap audit [--baseline <prefix>] [--base <ref>] [--json] [--ci] ...
34+
3235
Agents:
3336
codemap agents init [--force] [--interactive|-i]
37+
codemap skill · codemap rule # live full markdown (pointer protocol)
38+
39+
PR comment renderer (audit/SARIF → markdown summary):
40+
codemap pr-comment <file> [--shape audit|sarif] [--json] # - for stdin
3441
3542
MCP server (Model Context Protocol — for agent hosts):
3643
codemap mcp # stdio JSON-RPC, one tool per CLI verb

0 commit comments

Comments
 (0)