layermap 0.1.1 → 0.1.3
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 +137 -55
- package/analyzers/project-map-java/java-map.jar +0 -0
- package/dist/cli.mjs +135 -14
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,106 +1,188 @@
|
|
|
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
|
-
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
**English** · [中文](https://github.com/coffeecoproject/layermap/blob/main/README.zh-CN.md)
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/layermap)
|
|
8
|
+
[](https://github.com/coffeecoproject/layermap/blob/main/LICENSE)
|
|
9
|
+
|
|
10
|
+
A layered map of your codebase for coding agents. LayerMap gives Claude Code, Codex, DeepSeek
|
|
11
|
+
Harness and other MCP 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?**
|
|
8
|
-
|
|
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?**
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
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
|
-
|
|
94
|
+
**Codex**
|
|
26
95
|
|
|
27
96
|
```
|
|
28
97
|
codex plugin marketplace add coffeecoproject/layermap
|
|
29
98
|
codex plugin add layermap@layermap
|
|
30
99
|
```
|
|
31
100
|
|
|
32
|
-
|
|
33
|
-
helps; you do not need to mention it.
|
|
34
|
-
|
|
35
|
-
### Other MCP clients, or without plugins
|
|
101
|
+
**DeepSeek Harness**
|
|
36
102
|
|
|
37
103
|
```
|
|
38
|
-
npx layermap setup
|
|
104
|
+
npx layermap setup dsh
|
|
39
105
|
```
|
|
40
106
|
|
|
41
|
-
|
|
42
|
-
|
|
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.
|
|
107
|
+
This adds LayerMap to every dsh profile. Each session maps the project dsh was started in, and
|
|
108
|
+
`npx layermap remove dsh` undoes it.
|
|
46
109
|
|
|
47
|
-
|
|
110
|
+
In every agent, start a new session in a Git repository and ask as usual. LayerMap tells the agent
|
|
111
|
+
when the map helps. On first launch, npx downloads the pinned `layermap` package from npm.
|
|
48
112
|
|
|
49
|
-
|
|
113
|
+
Claude Code asks once before each map tool runs in a project. Choose "don't ask again", or run
|
|
114
|
+
`npx layermap allow claude` to allow the plugin's read-only tools everywhere.
|
|
50
115
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
- **Git**: LayerMap maps a Git work tree, the one around the directory the agent starts in.
|
|
54
|
-
- **Java projects only:** a JDK 21 or later (found through `LAYERMAP_JAVA_HOME`, `JAVA_HOME`, `PATH`,
|
|
55
|
-
Homebrew or SDKMAN). Without one, Java files are listed but have no declarations or calls.
|
|
116
|
+
**Without plugins:** run `npx layermap setup claude` or `npx layermap setup codex`. Setup does three
|
|
117
|
+
things:
|
|
56
118
|
|
|
57
|
-
|
|
119
|
+
- registers the server;
|
|
120
|
+
- lets its read-only tools run without a prompt;
|
|
121
|
+
- adds one marked sentence to the agent's instructions file.
|
|
58
122
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
files first and re-analyzes only what changed, so the map always matches the working tree.
|
|
123
|
+
Use `--scope project` to set it up for a whole team, and `npx layermap remove …` to undo it. For any
|
|
124
|
+
other MCP client, run `npx -y layermap mcp` as a stdio server in the repository.
|
|
62
125
|
|
|
63
|
-
|
|
64
|
-
or `~/.cache/layermap` on Linux, or `LAYERMAP_CACHE`), never in the repository. A project keeps
|
|
65
|
-
its three latest map versions; a map unused for 30 days is removed.
|
|
126
|
+
**Requirements:**
|
|
66
127
|
|
|
67
|
-
|
|
68
|
-
|
|
128
|
+
- Node.js 22.22 or later.
|
|
129
|
+
- macOS or Linux (x64 or arm64).
|
|
130
|
+
- A Git repository.
|
|
131
|
+
- For Java projects, a JDK 21 or later.
|
|
132
|
+
|
|
133
|
+
## How it works
|
|
69
134
|
|
|
70
|
-
|
|
135
|
+
The first call in a repository builds its map: seconds for a small project, a few minutes for a
|
|
136
|
+
large one. Later calls re-analyze only what changed, so the map always matches the working tree.
|
|
137
|
+
|
|
138
|
+
Maps stay in your user cache (`~/Library/Caches/layermap`, `~/.cache/layermap` or
|
|
139
|
+
`LAYERMAP_CACHE`), never in the repository. LayerMap runs entirely on your machine and sends
|
|
140
|
+
nothing anywhere ([privacy](https://github.com/coffeecoproject/layermap/blob/main/PRIVACY.md),
|
|
141
|
+
[security](https://github.com/coffeecoproject/layermap/blob/main/SECURITY.md)).
|
|
71
142
|
|
|
72
143
|
| Tool | Use |
|
|
73
144
|
|---|---|
|
|
74
|
-
| `project_explore_map` |
|
|
145
|
+
| `project_explore_map` | A directory, a file, or a declaration's callers and callees (`direction` INCOMING or OUTGOING, `depth` up to 8). |
|
|
75
146
|
| `project_search_map` | Find declarations by words in their names, paths or documentation. |
|
|
76
147
|
| `project_find_references` | Every usage of a declaration, compiled from current source. |
|
|
77
148
|
|
|
78
|
-
The
|
|
79
|
-
dynamic dispatch, framework wiring, reflection and computed names need source reading, and a
|
|
80
|
-
missing relationship does not prove absence. The tools say where a trace stops.
|
|
81
|
-
|
|
82
|
-
## Command line
|
|
149
|
+
The same from the command line:
|
|
83
150
|
|
|
84
151
|
```
|
|
85
|
-
npx layermap index # build or update the map now
|
|
86
152
|
npx layermap explore src/api/users.ts --name createUser --direction INCOMING --depth 8
|
|
87
153
|
npx layermap search "invoice total"
|
|
88
154
|
npx layermap refs src/billing/tax.ts calculateTax
|
|
89
155
|
```
|
|
90
156
|
|
|
157
|
+
## FAQ
|
|
158
|
+
|
|
159
|
+
**How long does the first map take?** On a recent Mac:
|
|
160
|
+
|
|
161
|
+
- Miniflux (400 Go files): about 3 s.
|
|
162
|
+
- Polar's server (1,900 Python files): about a minute.
|
|
163
|
+
- Conductor (1,500 Java and 1,300 TypeScript files): under two minutes.
|
|
164
|
+
|
|
165
|
+
**What can't it see?** Calls the compiler cannot resolve statically: dependency injection, unknown
|
|
166
|
+
framework routing, reflection and computed names. The tools say where a trace stops, and a missing
|
|
167
|
+
relationship does not prove absence.
|
|
168
|
+
|
|
169
|
+
**Windows?** Not yet.
|
|
170
|
+
|
|
171
|
+
**How do I remove it?**
|
|
172
|
+
|
|
173
|
+
- Claude Code: `/plugin uninstall layermap@layermap`.
|
|
174
|
+
- Codex: `codex plugin remove layermap@layermap`.
|
|
175
|
+
- Then delete the cache directory.
|
|
176
|
+
|
|
91
177
|
## Development
|
|
92
178
|
|
|
93
|
-
|
|
94
|
-
analyzer; a missing toolchain leaves its language unanalyzed.
|
|
179
|
+
You need pnpm, Go 1.24 and a JDK 21+. A missing toolchain leaves its language unanalyzed.
|
|
95
180
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
pnpm
|
|
99
|
-
pnpm typecheck
|
|
100
|
-
pnpm lint
|
|
101
|
-
pnpm package # the npm package, into .pack/
|
|
102
|
-
```
|
|
181
|
+
Run `pnpm install`, then `pnpm test`, `pnpm typecheck` or `pnpm lint`.
|
|
182
|
+
|
|
183
|
+
`pnpm package` builds the npm package.
|
|
103
184
|
|
|
104
185
|
## License
|
|
105
186
|
|
|
106
|
-
Apache-2.0. See [LICENSE](LICENSE) and
|
|
187
|
+
Apache-2.0. See [LICENSE](https://github.com/coffeecoproject/layermap/blob/main/LICENSE) and
|
|
188
|
+
[NOTICE](https://github.com/coffeecoproject/layermap/blob/main/NOTICE).
|
|
Binary file
|
package/dist/cli.mjs
CHANGED
|
@@ -22321,9 +22321,12 @@ function serveMcp(options) {
|
|
|
22321
22321
|
opened ??= options.open();
|
|
22322
22322
|
return opened;
|
|
22323
22323
|
};
|
|
22324
|
+
const session = new AbortController();
|
|
22324
22325
|
let warm;
|
|
22325
22326
|
const warmUp = () => {
|
|
22326
|
-
warm ??= map2().then((layermap) => layermap.refresh(
|
|
22327
|
+
warm ??= map2().then((layermap) => layermap.refresh(session.signal)).catch((error51) => {
|
|
22328
|
+
if (!session.signal.aborted) log2(`LayerMap could not build the map: ${String(error51)}`);
|
|
22329
|
+
});
|
|
22327
22330
|
return warm;
|
|
22328
22331
|
};
|
|
22329
22332
|
const call = async (id2, params) => {
|
|
@@ -22394,7 +22397,13 @@ function serveMcp(options) {
|
|
|
22394
22397
|
title,
|
|
22395
22398
|
description,
|
|
22396
22399
|
inputSchema,
|
|
22397
|
-
annotations: {
|
|
22400
|
+
annotations: {
|
|
22401
|
+
title,
|
|
22402
|
+
readOnlyHint: true,
|
|
22403
|
+
destructiveHint: false,
|
|
22404
|
+
idempotentHint: true,
|
|
22405
|
+
openWorldHint: false
|
|
22406
|
+
}
|
|
22398
22407
|
}))
|
|
22399
22408
|
}
|
|
22400
22409
|
});
|
|
@@ -22422,6 +22431,7 @@ function serveMcp(options) {
|
|
|
22422
22431
|
}
|
|
22423
22432
|
});
|
|
22424
22433
|
lines.on("close", async () => {
|
|
22434
|
+
session.abort();
|
|
22425
22435
|
for (const controller of calls.values()) controller.abort();
|
|
22426
22436
|
if (opened) await (await opened.catch(() => void 0))?.close().catch(() => void 0);
|
|
22427
22437
|
resolve();
|
|
@@ -22432,10 +22442,12 @@ function serveMcp(options) {
|
|
|
22432
22442
|
// src/agent/setup.ts
|
|
22433
22443
|
import { execFile as execFile2 } from "node:child_process";
|
|
22434
22444
|
import { existsSync as existsSync5 } from "node:fs";
|
|
22435
|
-
import { mkdir as mkdir2, readFile as readFile2, writeFile as writeFile2 } from "node:fs/promises";
|
|
22445
|
+
import { mkdir as mkdir2, readFile as readFile2, rm as rm2, writeFile as writeFile2 } from "node:fs/promises";
|
|
22436
22446
|
import { homedir as homedir2 } from "node:os";
|
|
22437
22447
|
import path9 from "node:path";
|
|
22438
22448
|
var SERVER = "layermap";
|
|
22449
|
+
var SETUP_RULE = `mcp__${SERVER}`;
|
|
22450
|
+
var PLUGIN_RULE = `mcp__plugin_${SERVER}_${SERVER}`;
|
|
22439
22451
|
var BEGIN = "<!-- layermap:begin -->";
|
|
22440
22452
|
var END = "<!-- layermap:end -->";
|
|
22441
22453
|
var mcpLaunchCommand = (version2) => {
|
|
@@ -22461,8 +22473,7 @@ var run = (command, args, env) => new Promise(
|
|
|
22461
22473
|
(error51, stdout, stderr) => resolve({ ok: !error51, output: `${stdout}${stderr}`.trim() })
|
|
22462
22474
|
)
|
|
22463
22475
|
);
|
|
22464
|
-
async function allowInClaudeSettings(file2) {
|
|
22465
|
-
const rule = `mcp__${SERVER}`;
|
|
22476
|
+
async function allowInClaudeSettings(file2, rule = SETUP_RULE) {
|
|
22466
22477
|
const settings = existsSync5(file2) ? JSON.parse(await readFile2(file2, "utf8")) : {};
|
|
22467
22478
|
if (typeof settings !== "object" || settings === null || Array.isArray(settings))
|
|
22468
22479
|
throw new Error(`${file2} is not a settings object.`);
|
|
@@ -22516,21 +22527,90 @@ async function removeInstructionNote(file2) {
|
|
|
22516
22527
|
const end = text.indexOf(END);
|
|
22517
22528
|
if (start < 0 || end < start) return;
|
|
22518
22529
|
const before = text.slice(0, start).replace(/\n\n$/u, "\n");
|
|
22519
|
-
|
|
22530
|
+
const rest = `${before}${text.slice(end + END.length).replace(/^\n/u, "")}`;
|
|
22531
|
+
if (!rest.trim()) await rm2(file2);
|
|
22532
|
+
else await writeFile2(file2, rest);
|
|
22520
22533
|
}
|
|
22521
22534
|
async function disallowInClaudeSettings(file2) {
|
|
22522
22535
|
if (!existsSync5(file2)) return;
|
|
22523
22536
|
const settings = JSON.parse(await readFile2(file2, "utf8"));
|
|
22524
22537
|
const allow = settings?.permissions?.allow;
|
|
22525
|
-
|
|
22526
|
-
|
|
22538
|
+
const ours = (rule) => rule === SETUP_RULE || rule === PLUGIN_RULE;
|
|
22539
|
+
if (!Array.isArray(allow) || !allow.some(ours)) return;
|
|
22540
|
+
settings.permissions.allow = allow.filter((rule) => !ours(rule));
|
|
22527
22541
|
if (!settings.permissions.allow.length) delete settings.permissions.allow;
|
|
22528
22542
|
if (!Object.keys(settings.permissions).length) delete settings.permissions;
|
|
22529
22543
|
await writeFile2(file2, `${JSON.stringify(settings, null, 2)}
|
|
22530
22544
|
`);
|
|
22531
22545
|
}
|
|
22546
|
+
var YAML_BEGIN = "# layermap:begin";
|
|
22547
|
+
var YAML_END = "# layermap:end";
|
|
22548
|
+
var nodeDirectory = (env = process.env) => (env.PATH ?? "").split(path9.delimiter).find(
|
|
22549
|
+
(directory) => path9.isAbsolute(directory) && existsSync5(path9.join(directory, "node")) && existsSync5(path9.join(directory, "npx"))
|
|
22550
|
+
) ?? path9.dirname(process.execPath);
|
|
22551
|
+
var dshPatchBlock = (command, env) => {
|
|
22552
|
+
const node = nodeDirectory(env);
|
|
22553
|
+
const npx = path9.join(node, "npx");
|
|
22554
|
+
const [program = "", ...args] = command[0] === "npx" && existsSync5(npx) ? [npx, ...command.slice(1)] : command;
|
|
22555
|
+
const searchPath = `${JSON.stringify(`${node}${path9.delimiter}`)} + process.env.PATH`;
|
|
22556
|
+
return [
|
|
22557
|
+
`${YAML_BEGIN} (written by \`layermap setup dsh\`; \`layermap remove dsh\` deletes it)`,
|
|
22558
|
+
"- insert:",
|
|
22559
|
+
" - id: layermap",
|
|
22560
|
+
" name: '@deepseek-ai/dsh-mcp-client'",
|
|
22561
|
+
" config:",
|
|
22562
|
+
" serverName: layermap",
|
|
22563
|
+
" transport: stdio",
|
|
22564
|
+
` command: ${JSON.stringify(program)}`,
|
|
22565
|
+
` args: ${JSON.stringify(args)}`,
|
|
22566
|
+
" env:",
|
|
22567
|
+
` PATH: !!js ${JSON.stringify(searchPath)}`,
|
|
22568
|
+
" cwd: !!js process.cwd()",
|
|
22569
|
+
" toolCallTimeoutMs: 120000",
|
|
22570
|
+
YAML_END
|
|
22571
|
+
].join("\n");
|
|
22572
|
+
};
|
|
22573
|
+
async function writeDshPatch(file2, block) {
|
|
22574
|
+
const text = existsSync5(file2) ? await readFile2(file2, "utf8") : "";
|
|
22575
|
+
const start = text.indexOf(YAML_BEGIN);
|
|
22576
|
+
const end = text.indexOf(YAML_END);
|
|
22577
|
+
let next;
|
|
22578
|
+
if (start >= 0 && end > start)
|
|
22579
|
+
next = `${text.slice(0, start)}${block}${text.slice(end + YAML_END.length)}`;
|
|
22580
|
+
else {
|
|
22581
|
+
const content = text.split("\n").filter((line) => line.trim() && !line.trim().startsWith("#"));
|
|
22582
|
+
if (content.length === 1 && content[0]?.trim() === "[]")
|
|
22583
|
+
next = text.replace(/^[ \t]*\[\][ \t]*$/mu, block);
|
|
22584
|
+
else if (content.some((line) => line.trim().startsWith("[")))
|
|
22585
|
+
throw new Error(`${file2} is a flow-style YAML list; add LayerMap's entry to it by hand.`);
|
|
22586
|
+
else next = `${text}${text && !text.endsWith("\n") ? "\n" : ""}${block}
|
|
22587
|
+
`;
|
|
22588
|
+
}
|
|
22589
|
+
if (next === text) return;
|
|
22590
|
+
await mkdir2(path9.dirname(file2), { recursive: true });
|
|
22591
|
+
await writeFile2(file2, next);
|
|
22592
|
+
}
|
|
22593
|
+
async function removeDshPatch(file2) {
|
|
22594
|
+
if (!existsSync5(file2)) return;
|
|
22595
|
+
const text = await readFile2(file2, "utf8");
|
|
22596
|
+
const start = text.indexOf(YAML_BEGIN);
|
|
22597
|
+
const end = text.indexOf(YAML_END);
|
|
22598
|
+
if (start < 0 || end < start) return;
|
|
22599
|
+
const rest = `${text.slice(0, start)}${text.slice(end + YAML_END.length).replace(/^\n/u, "")}`;
|
|
22600
|
+
if (!rest.trim()) return rm2(file2);
|
|
22601
|
+
const content = rest.split("\n").some((line) => line.trim() && !line.trim().startsWith("#"));
|
|
22602
|
+
await writeFile2(file2, content ? rest : `${rest}${rest.endsWith("\n") ? "" : "\n"}[]
|
|
22603
|
+
`);
|
|
22604
|
+
}
|
|
22532
22605
|
var agentFiles = (options) => {
|
|
22533
22606
|
const env = options.env ?? process.env;
|
|
22607
|
+
if (options.agent === "dsh") {
|
|
22608
|
+
const home = env.DSH_HOME || path9.join(homedir2(), ".dsh");
|
|
22609
|
+
return {
|
|
22610
|
+
settings: path9.join(home, "cordis.patch.yml"),
|
|
22611
|
+
instructions: path9.join(home, "AGENTS.md")
|
|
22612
|
+
};
|
|
22613
|
+
}
|
|
22534
22614
|
if (options.agent === "codex") {
|
|
22535
22615
|
const home = env.CODEX_HOME ?? path9.join(homedir2(), ".codex");
|
|
22536
22616
|
return { settings: path9.join(home, "config.toml"), instructions: path9.join(home, "AGENTS.md") };
|
|
@@ -22559,10 +22639,25 @@ async function setupAgent(options) {
|
|
|
22559
22639
|
const quoted = command.map((part) => /^[\w./:@=-]+$/u.test(part) ? part : JSON.stringify(part));
|
|
22560
22640
|
const { settings, instructions } = agentFiles(options);
|
|
22561
22641
|
const note = options.instructions !== false;
|
|
22642
|
+
if (options.agent === "dsh") {
|
|
22643
|
+
if (options.scope !== "user") {
|
|
22644
|
+
log2("DeepSeek Harness is set up for all its profiles at once; --scope does not apply.");
|
|
22645
|
+
return false;
|
|
22646
|
+
}
|
|
22647
|
+
log2(`add the ${SERVER} MCP server to ${settings}`);
|
|
22648
|
+
if (note) log2(`add a note naming the map tools to ${instructions}`);
|
|
22649
|
+
if (options.dryRun) return true;
|
|
22650
|
+
await writeDshPatch(settings, dshPatchBlock(command, env));
|
|
22651
|
+
if (note) await writeInstructionNote(instructions);
|
|
22652
|
+
log2(
|
|
22653
|
+
"Done. DeepSeek Harness reloads its settings by itself; its sessions have the mcp__layermap__project_* tools for the project dsh was started in."
|
|
22654
|
+
);
|
|
22655
|
+
return true;
|
|
22656
|
+
}
|
|
22562
22657
|
if (options.agent === "claude") {
|
|
22563
22658
|
const scope2 = ["--scope", options.scope];
|
|
22564
22659
|
log2(`claude mcp add ${scope2.join(" ")} ${SERVER} -- ${quoted.join(" ")}`);
|
|
22565
|
-
log2(`allow
|
|
22660
|
+
log2(`allow ${SETUP_RULE} in ${settings}`);
|
|
22566
22661
|
} else {
|
|
22567
22662
|
log2(`codex mcp add ${SERVER} -- ${quoted.join(" ")}`);
|
|
22568
22663
|
log2(`set default_tools_approval_mode = "approve" and tool_timeout_sec = 120 in ${settings}`);
|
|
@@ -22587,9 +22682,33 @@ async function setupAgent(options) {
|
|
|
22587
22682
|
);
|
|
22588
22683
|
return true;
|
|
22589
22684
|
}
|
|
22685
|
+
async function allowAgent(options) {
|
|
22686
|
+
if (options.agent !== "claude") {
|
|
22687
|
+
options.log(
|
|
22688
|
+
options.agent === "codex" ? "The Codex plugin already runs LayerMap's read-only tools without a prompt." : "DeepSeek Harness runs MCP tools without a prompt."
|
|
22689
|
+
);
|
|
22690
|
+
return true;
|
|
22691
|
+
}
|
|
22692
|
+
const { settings } = agentFiles(options);
|
|
22693
|
+
options.log(`allow ${PLUGIN_RULE} in ${settings}`);
|
|
22694
|
+
if (options.dryRun) return true;
|
|
22695
|
+
await allowInClaudeSettings(settings, PLUGIN_RULE);
|
|
22696
|
+
options.log("Done. Claude Code runs the LayerMap plugin's map tools without asking.");
|
|
22697
|
+
return true;
|
|
22698
|
+
}
|
|
22590
22699
|
async function removeAgent(options) {
|
|
22591
22700
|
const env = options.env ?? process.env;
|
|
22592
22701
|
const { settings, instructions } = agentFiles(options);
|
|
22702
|
+
if (options.agent === "dsh") {
|
|
22703
|
+
options.log(
|
|
22704
|
+
`remove the ${SERVER} MCP server from ${settings} and its note from ${instructions}`
|
|
22705
|
+
);
|
|
22706
|
+
if (options.dryRun) return true;
|
|
22707
|
+
await removeDshPatch(settings);
|
|
22708
|
+
await removeInstructionNote(instructions);
|
|
22709
|
+
options.log("Removed.");
|
|
22710
|
+
return true;
|
|
22711
|
+
}
|
|
22593
22712
|
const scope = options.agent === "claude" ? ["--scope", options.scope] : [];
|
|
22594
22713
|
options.log(`${options.agent} mcp remove ${SERVER} ${scope.join(" ")}`.trim());
|
|
22595
22714
|
options.log(`remove LayerMap's approval from ${settings} and its note from ${instructions}`);
|
|
@@ -22605,8 +22724,10 @@ async function removeAgent(options) {
|
|
|
22605
22724
|
var USAGE = `LayerMap \u2014 a layered map of a codebase for coding agents.
|
|
22606
22725
|
|
|
22607
22726
|
Usage:
|
|
22608
|
-
layermap setup claude|codex [--scope user|project|local] [--no-instructions] [--dry-run]
|
|
22609
|
-
layermap
|
|
22727
|
+
layermap setup claude|codex|dsh [--scope user|project|local] [--no-instructions] [--dry-run]
|
|
22728
|
+
layermap allow claude [--scope user|project|local] [--dry-run]
|
|
22729
|
+
let the plugin's read-only tools run without a prompt
|
|
22730
|
+
layermap remove claude|codex|dsh [--scope user|project|local] [--dry-run]
|
|
22610
22731
|
layermap mcp [--project DIR] serve the map tools over MCP (stdio)
|
|
22611
22732
|
layermap index [--project DIR] build or update the map now
|
|
22612
22733
|
layermap explore [PATH] [--name NAME] [--line N] [--direction INCOMING|OUTGOING|BOTH]
|
|
@@ -22669,11 +22790,11 @@ async function main(argv) {
|
|
|
22669
22790
|
);
|
|
22670
22791
|
return map3;
|
|
22671
22792
|
};
|
|
22672
|
-
if (command === "setup" || command === "remove") {
|
|
22793
|
+
if (command === "setup" || command === "allow" || command === "remove") {
|
|
22673
22794
|
const agent = rest[0];
|
|
22674
|
-
if (agent !== "claude" && agent !== "codex") return usage(1);
|
|
22795
|
+
if (agent !== "claude" && agent !== "codex" && agent !== "dsh") return usage(1);
|
|
22675
22796
|
if (!["user", "project", "local"].includes(values.scope)) return usage(1);
|
|
22676
|
-
const done = await
|
|
22797
|
+
const done = await { setup: setupAgent, allow: allowAgent, remove: removeAgent }[command]({
|
|
22677
22798
|
agent,
|
|
22678
22799
|
scope: values.scope,
|
|
22679
22800
|
project,
|
package/package.json
CHANGED