layermap 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,28 +1,97 @@
1
+ <p align="center"><img src="https://raw.githubusercontent.com/coffeecoproject/layermap/main/assets/icon.png" alt="LayerMap" width="120"></p>
2
+
1
3
  # LayerMap
2
4
 
3
- A layered map of your codebase for coding agents. LayerMap gives Claude Code, Codex and other
4
- MCP clients three read-only tools that answer, in one call, questions an agent otherwise works out
5
- with dozens of searches:
5
+ **English** · [中文](https://github.com/coffeecoproject/layermap/blob/main/README.zh-CN.md)
6
+
7
+ [![npm](https://img.shields.io/npm/v/layermap)](https://www.npmjs.com/package/layermap)
8
+ [![License](https://img.shields.io/badge/license-Apache--2.0-blue)](https://github.com/coffeecoproject/layermap/blob/main/LICENSE)
9
+
10
+ A layered map of your codebase for coding agents. LayerMap gives Claude Code, Codex and other MCP
11
+ clients three read-only tools that answer, in one call, what an agent otherwise works out with
12
+ dozens of searches:
6
13
 
7
- - **What calls this, and what does changing it affect?** A declaration's callers, traced up to 8
8
- levels to the entry points: HTTP routes, handlers, jobs and commands.
14
+ - **What calls this, and what does changing it affect?** Callers traced up to 8 levels, to the
15
+ HTTP routes, handlers, jobs and commands they start from.
9
16
  - **What does it call?** Callees down to 8 levels.
10
- - **What is here?** Directories, modules, each file's declarations, and every usage of a symbol.
17
+ - **What is here?** Modules, each file's declarations, and every usage of a symbol.
18
+
19
+ It maps **TypeScript, JavaScript, Go, Python and Java** with each language's own compiler, so calls
20
+ through interfaces, base classes, templates and decorators resolve as the compiler resolves them,
21
+ including the ones text search misses.
22
+
23
+ ## Example
24
+
25
+ In [Miniflux](https://github.com/miniflux/v2), one call on `Storage.MarkFeedAsRead` finds all four
26
+ ways a request reaches it, each with its route:
27
+
28
+ ```
29
+ DECLARATION internal/storage/entry.go: Storage.MarkFeedAsRead m656-680 exported
30
+ ← called by internal/api/feed.go: handler.markFeedAsRead m140-155 @149
31
+ ← called by internal/fever/handler.go: handler.handleWriteFeeds m492-519 @508
32
+ ← called by internal/googlereader/handler.go: handler.markAllAsReadHandler m1261-1338 @1311
33
+ ← called by internal/ui/feed_mark_as_read.go: handler.markFeedAsRead m14-30 @24
34
+ [1] internal/api/feed.go: handler.markFeedAsRead m140-155
35
+ ← used as value by internal/api/api.go: Serve f25-84 @61 "/feeds/{feedID}/mark-all-as-read"
36
+ [1] internal/googlereader/handler.go: handler.markAllAsReadHandler m1261-1338
37
+ ← used as value by internal/googlereader/handler.go: Serve f44-64 @62 "/mark-all-as-read"
38
+ [1] internal/ui/feed_mark_as_read.go: handler.markFeedAsRead m14-30
39
+ ← used as value by internal/ui/ui.go: Serve f18-180 @77 "/feed/{feedID}/mark-all-as-read"
40
+ … (the Fever API, then on down to main.go: main)
41
+ ```
42
+
43
+ `m` and `f` mark methods and functions with their lines; `@` is the line of the call, and the quoted
44
+ path is the route it is registered under.
45
+
46
+ ## Results
47
+
48
+ Impact questions ("which HTTP endpoints does changing this affect?") on public Go, Python and Java
49
+ projects, graded blind against truth sets cross-checked with each language's own toolchain:
50
+
51
+ | | With LayerMap | Without |
52
+ |---|---|---|
53
+ | Endpoints found, at most 15 requests (`gpt-5.5`, 6 tasks × 3 runs) | **97.9%** | 58.8% |
54
+ | Used unprompted by Claude Code / Codex (plugin installed) | **6 of 6 / 6 of 6** | — |
55
+ | Endpoints found, no request limit (Claude Code / Codex) | 99.3% / 98.0% | 99.0% / 98.6% |
56
+ | Cost, no request limit (Claude Code in USD / Codex in input tokens) | **−32% / −55%** | |
57
+ | Time, no request limit | +24% / +17% | |
58
+
59
+ With a tight budget, the map finds far more of the affected code, at about 24% more tokens. With
60
+ no limit, both agents get there either way. The map makes the run cheaper, and the agents explore
61
+ more widely, which takes longer. These are small samples on tasks written by LayerMap's authors.
62
+ The [report](https://github.com/coffeecoproject/layermap/blob/main/docs/benchmark.md) has the
63
+ setup, the published tasks and the limitations.
64
+
65
+ ## How LayerMap differs
66
+
67
+ Other tools give agents part of this. LayerMap combines compiler accuracy with whole-chain traces
68
+ in one local map:
69
+
70
+ | | Tree-sitter code graphs (codegraph, GitNexus, …) | Language servers and IDEs (Claude Code's LSP tool, Serena, JetBrains) | Embedding search (Claude Context, Augment) | **LayerMap** |
71
+ |---|---|---|---|---|
72
+ | How calls are linked | Matched by names, imports and framework rules, often with confidence scores | The compiler's own resolution | Not linked; similar code is retrieved | **Resolved by each language's compiler or type checker** |
73
+ | Callers traced to routes and handlers | In several tools, at varying depth | One level per request (JetBrains: 5 by default) | — | **Up to 8 levels in one call** |
74
+ | Kept as a map | Yes, with file watching | No, answered live by a running server | An index of code chunks | **Yes, brought up to date on every call** |
75
+ | Runs on your machine | Yes; some send anonymous telemetry | Yes | Usually with cloud embeddings | **Yes, and sends nothing** |
11
76
 
12
- It maps **TypeScript, JavaScript, Go, Python and Java**, using each language's own compiler
13
- (TypeScript, `go/types`, Pyright, javac with Lombok), so calls through imports, methods, interfaces
14
- and decorators resolve the way the compiler resolves them.
77
+ Another tool fits better if you need:
78
+
79
+ - more languages, since tree-sitter graphs cover 30 or more;
80
+ - Windows;
81
+ - renaming and refactoring, from language servers;
82
+ - search by meaning, from embedding search;
83
+ - search across many repositories, with Sourcegraph.
15
84
 
16
85
  ## Install
17
86
 
18
- ### Claude Code
87
+ **Claude Code**
19
88
 
20
89
  ```
21
90
  /plugin marketplace add coffeecoproject/layermap
22
91
  /plugin install layermap@layermap
23
92
  ```
24
93
 
25
- ### Codex
94
+ **Codex**
26
95
 
27
96
  ```
28
97
  codex plugin marketplace add coffeecoproject/layermap
@@ -30,78 +99,80 @@ codex plugin add layermap@layermap
30
99
  ```
31
100
 
32
101
  Start a new session in a Git repository and ask as usual. The plugin tells the agent when the map
33
- helps; you do not need to mention it.
102
+ helps. On first launch, npx downloads the pinned `layermap` package from npm. Claude Code asks once
103
+ before each map tool runs in a project; choose "don't ask again", or run `npx layermap allow claude`
104
+ to allow the plugin's read-only tools everywhere.
34
105
 
35
- ### Other MCP clients, or without plugins
106
+ **Without plugins:** run `npx layermap setup claude` or `npx layermap setup codex`. Setup does three
107
+ things:
36
108
 
37
- ```
38
- npx layermap setup claude # or: npx layermap setup codex
39
- ```
109
+ - registers the server;
110
+ - lets its read-only tools run without a prompt;
111
+ - adds one marked sentence to the agent's instructions file.
40
112
 
41
- `setup` registers the server with the agent's own `mcp add`, lets its read-only tools run without
42
- a prompt, and adds one marked sentence to the agent's instructions file (`~/.claude/CLAUDE.md`,
43
- `~/.codex/AGENTS.md`) saying when to use the map; `--no-instructions` leaves that file alone, but
44
- Codex then rarely finds the tools. `--scope project` writes the configuration into the repository
45
- for a whole team. `npx layermap remove claude|codex` undoes it.
113
+ Use `--scope project` to set it up for a whole team, and `npx layermap remove …` to undo it. For any
114
+ other MCP client, run `npx -y layermap mcp` as a stdio server in the repository.
46
115
 
47
- For any other MCP client, run `npx -y layermap mcp` as a stdio server in the repository.
116
+ **Requirements:**
48
117
 
49
- ## Requirements
50
-
51
- - **Node.js 22.22 or later**, an official build: LayerMap keeps its maps in the SQLite that Node
52
- ships, and needs its full-text search (some package managers build Node without it).
53
- - **macOS or Linux** (x64 or arm64).
54
- - **Git**: LayerMap maps a Git work tree, the one around the directory the agent starts in.
55
- - **Java projects only:** a JDK 21 or later (found through `LAYERMAP_JAVA_HOME`, `JAVA_HOME`, `PATH`,
56
- Homebrew or SDKMAN). Without one, Java files are listed but have no declarations or calls.
118
+ - Node.js 22.22 or later.
119
+ - macOS or Linux (x64 or arm64).
120
+ - A Git repository.
121
+ - For Java projects, a JDK 21 or later.
57
122
 
58
123
  ## How it works
59
124
 
60
- The first tool call in a repository builds its map: seconds for a small project, a few minutes
61
- for a large one (until then the tools say the map is still building). Every later call checks the
62
- files first and re-analyzes only what changed, so the map always matches the working tree.
63
-
64
- Maps live in your user cache (`~/Library/Caches/layermap` on macOS, `$XDG_CACHE_HOME/layermap`
65
- or `~/.cache/layermap` on Linux, or `LAYERMAP_CACHE`), never in the repository. A project keeps
66
- its three latest map versions; a map unused for 30 days is removed.
125
+ The first call in a repository builds its map: seconds for a small project, a few minutes for a
126
+ large one. Later calls re-analyze only what changed, so the map always matches the working tree.
67
127
 
68
- **Privacy:** LayerMap runs entirely on your machine and sends nothing anywhere. Your agent sends
69
- the tool results to its model as it does with any file it reads.
70
-
71
- ## The tools
128
+ Maps stay in your user cache (`~/Library/Caches/layermap`, `~/.cache/layermap` or
129
+ `LAYERMAP_CACHE`), never in the repository. LayerMap runs entirely on your machine and sends
130
+ nothing anywhere ([privacy](https://github.com/coffeecoproject/layermap/blob/main/PRIVACY.md),
131
+ [security](https://github.com/coffeecoproject/layermap/blob/main/SECURITY.md)).
72
132
 
73
133
  | Tool | Use |
74
134
  |---|---|
75
- | `project_explore_map` | `path` `"."` or a directory: modules and files. A file: its declarations, imports and importers. With `name` (and `line` when names repeat): the declaration's callers, callees, writes, heritage and members, `direction` INCOMING or OUTGOING with `depth` up to 8. |
135
+ | `project_explore_map` | A directory, a file, or a declaration's callers and callees (`direction` INCOMING or OUTGOING, `depth` up to 8). |
76
136
  | `project_search_map` | Find declarations by words in their names, paths or documentation. |
77
137
  | `project_find_references` | Every usage of a declaration, compiled from current source. |
78
138
 
79
- The map is static. Calls through interfaces and base members follow the implementations it links;
80
- dynamic dispatch, framework wiring, reflection and computed names need source reading, and a
81
- missing relationship does not prove absence. The tools say where a trace stops.
82
-
83
- ## Command line
139
+ The same from the command line:
84
140
 
85
141
  ```
86
- npx layermap index # build or update the map now
87
142
  npx layermap explore src/api/users.ts --name createUser --direction INCOMING --depth 8
88
143
  npx layermap search "invoice total"
89
144
  npx layermap refs src/billing/tax.ts calculateTax
90
145
  ```
91
146
 
147
+ ## FAQ
148
+
149
+ **How long does the first map take?** On a recent Mac:
150
+
151
+ - Miniflux (400 Go files): about 3 s.
152
+ - Polar's server (1,900 Python files): about a minute.
153
+ - Conductor (1,500 Java and 1,300 TypeScript files): under two minutes.
154
+
155
+ **What can't it see?** Calls the compiler cannot resolve statically: dependency injection, unknown
156
+ framework routing, reflection and computed names. The tools say where a trace stops, and a missing
157
+ relationship does not prove absence.
158
+
159
+ **Windows?** Not yet.
160
+
161
+ **How do I remove it?**
162
+
163
+ - Claude Code: `/plugin uninstall layermap@layermap`.
164
+ - Codex: `codex plugin remove layermap@layermap`.
165
+ - Then delete the cache directory.
166
+
92
167
  ## Development
93
168
 
94
- Building from source needs pnpm, Go 1.24 for the Go analyzer and a JDK 21 or later for the Java
95
- analyzer; a missing toolchain leaves its language unanalyzed.
169
+ You need pnpm, Go 1.24 and a JDK 21+. A missing toolchain leaves its language unanalyzed.
96
170
 
97
- ```
98
- pnpm install
99
- pnpm test # builds the analyzers once, then runs the tests
100
- pnpm typecheck
101
- pnpm lint
102
- pnpm package # the npm package, into .pack/
103
- ```
171
+ Run `pnpm install`, then `pnpm test`, `pnpm typecheck` or `pnpm lint`.
172
+
173
+ `pnpm package` builds the npm package.
104
174
 
105
175
  ## License
106
176
 
107
- Apache-2.0. See [LICENSE](LICENSE) and [NOTICE](NOTICE).
177
+ Apache-2.0. See [LICENSE](https://github.com/coffeecoproject/layermap/blob/main/LICENSE) and
178
+ [NOTICE](https://github.com/coffeecoproject/layermap/blob/main/NOTICE).
package/dist/cli.mjs CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env -S node --disable-warning=ExperimentalWarning
1
+ #!/usr/bin/env node
2
2
  import { createRequire as layermapCreateRequire } from "node:module"; const require = layermapCreateRequire(import.meta.url);
3
3
  var __defProp = Object.defineProperty;
4
4
  var __export = (target, all) => {
@@ -24,7 +24,7 @@ import { createHash as createHash4 } from "node:crypto";
24
24
  import { mkdirSync } from "node:fs";
25
25
  import { lstat as lstat2, realpath as realpath2 } from "node:fs/promises";
26
26
  import path7 from "node:path";
27
- import { DatabaseSync } from "node:sqlite";
27
+ import { DatabaseSync } from "@photostructure/sqlite";
28
28
 
29
29
  // src/capture-policy.ts
30
30
  import path2 from "node:path";
@@ -21894,7 +21894,7 @@ function openMapDatabase(file2) {
21894
21894
  database.exec(`PRAGMA user_version = ${SCHEMA_VERSION}; COMMIT;`);
21895
21895
  } catch (error51) {
21896
21896
  database.exec("ROLLBACK");
21897
- throw /no such module: fts5/u.test(String(error51)) ? new ProjectEvidenceError("LAYERMAP_SQLITE_WITHOUT_FTS5", false) : error51;
21897
+ throw error51;
21898
21898
  }
21899
21899
  } else if (version2 === 1) {
21900
21900
  database.exec(
@@ -21938,7 +21938,9 @@ var LayerMap = class _LayerMap {
21938
21938
  directory: { canonicalPath: project, device: String(stat2.dev), inode: String(stat2.ino) }
21939
21939
  };
21940
21940
  const store = new CodeIndexStore(
21941
- openMapDatabase(mapDatabasePath(options.cacheDirectory, project))
21941
+ openMapDatabase(
21942
+ mapDatabasePath(options.cacheDirectory, project)
21943
+ )
21942
21944
  );
21943
21945
  const { typescript, go, python, java } = options.analyzers;
21944
21946
  const index = new CodeIndex(
@@ -22260,8 +22262,7 @@ var HINTS = {
22260
22262
  PROJECT_READ_INPUT_INVALID: "The arguments do not describe a valid selection.",
22261
22263
  PROJECT_PATH_INVALID: "Paths are relative to the project root, use / and contain no . or .. parts.",
22262
22264
  PROJECT_MAP_REFERENCE_TARGET_UNAVAILABLE: "References are not available for this declaration; use its callers in project_explore_map.",
22263
- LAYERMAP_NOT_A_GIT_REPOSITORY: "LayerMap maps Git repositories, and the agent was started outside one. Start it in a repository, or run layermap with --project naming one.",
22264
- LAYERMAP_SQLITE_WITHOUT_FTS5: "This Node.js build has SQLite without FTS5 (as some package managers build it). Run LayerMap with the official Node.js 22.22 or later."
22265
+ LAYERMAP_NOT_A_GIT_REPOSITORY: "LayerMap maps Git repositories, and the agent was started outside one. Start it in a repository, or run layermap with --project naming one."
22265
22266
  };
22266
22267
  var describeMapError = (error51) => error51 instanceof ProjectEvidenceError ? `${error51.code}${HINTS[error51.code] ? `: ${HINTS[error51.code]}` : ""}` : void 0;
22267
22268
  async function runMapTool(map2, name, args, signal) {
@@ -22393,7 +22394,13 @@ function serveMcp(options) {
22393
22394
  title,
22394
22395
  description,
22395
22396
  inputSchema,
22396
- annotations: { readOnlyHint: true, idempotentHint: true, openWorldHint: false }
22397
+ annotations: {
22398
+ title,
22399
+ readOnlyHint: true,
22400
+ destructiveHint: false,
22401
+ idempotentHint: true,
22402
+ openWorldHint: false
22403
+ }
22397
22404
  }))
22398
22405
  }
22399
22406
  });
@@ -22435,6 +22442,8 @@ import { mkdir as mkdir2, readFile as readFile2, writeFile as writeFile2 } from
22435
22442
  import { homedir as homedir2 } from "node:os";
22436
22443
  import path9 from "node:path";
22437
22444
  var SERVER = "layermap";
22445
+ var SETUP_RULE = `mcp__${SERVER}`;
22446
+ var PLUGIN_RULE = `mcp__plugin_${SERVER}_${SERVER}`;
22438
22447
  var BEGIN = "<!-- layermap:begin -->";
22439
22448
  var END = "<!-- layermap:end -->";
22440
22449
  var mcpLaunchCommand = (version2) => {
@@ -22460,8 +22469,7 @@ var run = (command, args, env) => new Promise(
22460
22469
  (error51, stdout, stderr) => resolve({ ok: !error51, output: `${stdout}${stderr}`.trim() })
22461
22470
  )
22462
22471
  );
22463
- async function allowInClaudeSettings(file2) {
22464
- const rule = `mcp__${SERVER}`;
22472
+ async function allowInClaudeSettings(file2, rule = SETUP_RULE) {
22465
22473
  const settings = existsSync5(file2) ? JSON.parse(await readFile2(file2, "utf8")) : {};
22466
22474
  if (typeof settings !== "object" || settings === null || Array.isArray(settings))
22467
22475
  throw new Error(`${file2} is not a settings object.`);
@@ -22521,8 +22529,11 @@ async function disallowInClaudeSettings(file2) {
22521
22529
  if (!existsSync5(file2)) return;
22522
22530
  const settings = JSON.parse(await readFile2(file2, "utf8"));
22523
22531
  const allow = settings?.permissions?.allow;
22524
- if (!Array.isArray(allow) || !allow.includes(`mcp__${SERVER}`)) return;
22525
- settings.permissions.allow = allow.filter((rule) => rule !== `mcp__${SERVER}`);
22532
+ const ours = (rule) => rule === SETUP_RULE || rule === PLUGIN_RULE;
22533
+ if (!Array.isArray(allow) || !allow.some(ours)) return;
22534
+ settings.permissions.allow = allow.filter((rule) => !ours(rule));
22535
+ if (!settings.permissions.allow.length) delete settings.permissions.allow;
22536
+ if (!Object.keys(settings.permissions).length) delete settings.permissions;
22526
22537
  await writeFile2(file2, `${JSON.stringify(settings, null, 2)}
22527
22538
  `);
22528
22539
  }
@@ -22559,7 +22570,7 @@ async function setupAgent(options) {
22559
22570
  if (options.agent === "claude") {
22560
22571
  const scope2 = ["--scope", options.scope];
22561
22572
  log2(`claude mcp add ${scope2.join(" ")} ${SERVER} -- ${quoted.join(" ")}`);
22562
- log2(`allow mcp__${SERVER} in ${settings}`);
22573
+ log2(`allow ${SETUP_RULE} in ${settings}`);
22563
22574
  } else {
22564
22575
  log2(`codex mcp add ${SERVER} -- ${quoted.join(" ")}`);
22565
22576
  log2(`set default_tools_approval_mode = "approve" and tool_timeout_sec = 120 in ${settings}`);
@@ -22584,6 +22595,18 @@ async function setupAgent(options) {
22584
22595
  );
22585
22596
  return true;
22586
22597
  }
22598
+ async function allowAgent(options) {
22599
+ if (options.agent !== "claude") {
22600
+ options.log("The Codex plugin already runs LayerMap's read-only tools without a prompt.");
22601
+ return true;
22602
+ }
22603
+ const { settings } = agentFiles(options);
22604
+ options.log(`allow ${PLUGIN_RULE} in ${settings}`);
22605
+ if (options.dryRun) return true;
22606
+ await allowInClaudeSettings(settings, PLUGIN_RULE);
22607
+ options.log("Done. Claude Code runs the LayerMap plugin's map tools without asking.");
22608
+ return true;
22609
+ }
22587
22610
  async function removeAgent(options) {
22588
22611
  const env = options.env ?? process.env;
22589
22612
  const { settings, instructions } = agentFiles(options);
@@ -22603,6 +22626,8 @@ var USAGE = `LayerMap \u2014 a layered map of a codebase for coding agents.
22603
22626
 
22604
22627
  Usage:
22605
22628
  layermap setup claude|codex [--scope user|project|local] [--no-instructions] [--dry-run]
22629
+ layermap allow claude [--scope user|project|local] [--dry-run]
22630
+ let the plugin's read-only tools run without a prompt
22606
22631
  layermap remove claude|codex [--scope user|project|local] [--dry-run]
22607
22632
  layermap mcp [--project DIR] serve the map tools over MCP (stdio)
22608
22633
  layermap index [--project DIR] build or update the map now
@@ -22666,11 +22691,11 @@ async function main(argv) {
22666
22691
  );
22667
22692
  return map3;
22668
22693
  };
22669
- if (command === "setup" || command === "remove") {
22694
+ if (command === "setup" || command === "allow" || command === "remove") {
22670
22695
  const agent = rest[0];
22671
22696
  if (agent !== "claude" && agent !== "codex") return usage(1);
22672
22697
  if (!["user", "project", "local"].includes(values.scope)) return usage(1);
22673
- const done = await (command === "setup" ? setupAgent : removeAgent)({
22698
+ const done = await { setup: setupAgent, allow: allowAgent, remove: removeAgent }[command]({
22674
22699
  agent,
22675
22700
  scope: values.scope,
22676
22701
  project,
@@ -22749,6 +22774,8 @@ async function main(argv) {
22749
22774
  }
22750
22775
  }
22751
22776
  process.exitCode = await main(process.argv.slice(2)).catch((error51) => {
22752
- log(`layermap: ${error51 instanceof Error ? error51.message : String(error51)}`);
22777
+ log(
22778
+ `layermap: ${describeMapError(error51) ?? (error51 instanceof Error ? error51.message : String(error51))}`
22779
+ );
22753
22780
  return 1;
22754
22781
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "layermap",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "A layered map of a codebase for coding agents: directories, modules and call chains across TypeScript, Go, Python and Java.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -22,6 +22,7 @@
22
22
  "linux"
23
23
  ],
24
24
  "dependencies": {
25
+ "@photostructure/sqlite": "2.6.0",
25
26
  "typescript": "7.0.2"
26
27
  },
27
28
  "homepage": "https://github.com/coffeecoproject/layermap",