@mayurdluffy/cbm-cli 1.0.7

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 mayurdluffy
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,377 @@
1
+ <h1 align="center">Codebase Memory Manager</h1>
2
+
3
+ [![GitHub release](https://img.shields.io/github/v/release/mayurdluffy/cbm-cli?logo=github)](https://github.com/mayurdluffy/cbm-cli/releases)
4
+ [![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT)
5
+ [![CI](https://img.shields.io/github/actions/workflow/status/mayurdluffy/cbm-cli/publish.yml?branch=main&label=Publish%20to%20npm&logo=github)](https://github.com/mayurdluffy/cbm-cli/actions/workflows/publish.yml)
6
+
7
+ ---
8
+
9
+ ## Why CBM?
10
+
11
+ [`codebase-memory-mcp`](https://github.com/DeusData/codebase-memory-mcp) is a beast. It indexes your entire codebase into a queryable knowledge graph — functions, call chains, HTTP routes, cross-service links — and answers structural queries in under a millisecond after initial indexing. It cuts agent token usage by **10–100x** depending on query type and supports **158 languages** via tree-sitter, with deep semantic analysis for 12 major languages.
12
+
13
+ But getting it installed, keeping the binary updated, configuring a dozen different agents, and sharing the indexed graph with your team involves a lot of moving parts.
14
+
15
+ **CBM handles all of that for you.**
16
+
17
+ Think of CBM as the project-level manager that wraps the engine. One command to install the binary. One command to index your repo. One command for your teammates to jump in. No manual config file editing. No "works on my machine."
18
+
19
+ ---
20
+
21
+ ## What CBM Does
22
+
23
+ 1. **Installs & manages** the `codebase-memory-mcp` binary for you.
24
+ 2. **Indexes your project** into a shareable `graph.db.zst` artifact.
25
+ 3. **Auto-configures 11 coding agents** with an interactive menu — no copy-pasting JSON.
26
+
27
+ ---
28
+
29
+ ## Limitations
30
+
31
+ - **Best for structural queries** — call chains, symbol discovery, blast radius analysis
32
+ - **Not for semantic questions** — "is this algorithm correct?" still requires reading code
33
+ - **Tiny projects** (<20 files) — grep may be faster than indexing
34
+ - **Stale graphs** — re-index after large refactors with `cbm re-index`
35
+ - **Config/non-code files** — `.env`, Dockerfiles not indexed
36
+ - **Answer quality** — 83% vs 92% for raw file exploration ([arxiv paper](https://arxiv.org/abs/2603.27277))
37
+
38
+ ---
39
+
40
+ ## Installation
41
+
42
+ ### Via npm (Recommended)
43
+
44
+ ```bash
45
+ npm install -g @mayurdluffy/cbm-cli
46
+ ```
47
+
48
+ ### Via npx (No install)
49
+
50
+ ```bash
51
+ npx @mayurdluffy/cbm-cli install
52
+ ```
53
+
54
+ ### Via curl (macOS / Linux)
55
+
56
+ ```bash
57
+ curl -fsSL https://raw.githubusercontent.com/mayurdluffy/cbm-cli/main/install.sh | bash
58
+ ```
59
+
60
+ ### Windows
61
+
62
+ ```bash
63
+ npm install -g @mayurdluffy/cbm-cli
64
+ # or
65
+ npx @mayurdluffy/cbm-cli install
66
+ ```
67
+
68
+ ### Security
69
+
70
+ The `codebase-memory-mcp` binary is closed-source but each release is signed, checksummed, and scanned. All processing is local — your code never leaves your machine. See [upstream SECURITY.md](https://github.com/DeusData/codebase-memory-mcp/blob/main/SECURITY.md).
71
+
72
+ ---
73
+
74
+ ## Uninstalling
75
+
76
+ ### Remove the `codebase-memory-mcp` binary only
77
+
78
+ ```bash
79
+ cbm uninstall
80
+ ```
81
+
82
+ This removes the binary, cache, and config — but keeps `cbm` installed.
83
+
84
+ ### Remove `cbm` entirely
85
+
86
+ **npm:**
87
+ ```bash
88
+ npm uninstall -g @mayurdluffy/cbm-cli
89
+ ```
90
+
91
+ **curl (macOS / Linux):**
92
+ ```bash
93
+ npm uninstall -g @mayurdluffy/cbm-cli
94
+ ```
95
+ The curl installer uses npm under the hood, so the uninstall command is the same.
96
+
97
+ ---
98
+
99
+ ## Quick Start
100
+
101
+ ```bash
102
+ # 1. Install the engine + select your agents
103
+ cbm install
104
+
105
+ # 2. Index your project and create a shareable graph
106
+ cd ~/projects/my-awesome-api
107
+ cbm build
108
+
109
+ # 3. Commit the graph so your team skips re-indexing
110
+ git add .codebase-memory/graph.db.zst
111
+ git commit -m "Add shareable codebase graph"
112
+ git push
113
+
114
+ # 4. Teammates clone and go
115
+ cbm use
116
+ ```
117
+
118
+ ---
119
+
120
+ ## CLI at a Glance
121
+
122
+ ```text
123
+ @lucifer:~$ cbm
124
+
125
+ ██████╗ ██████╗ ███╗ ███╗
126
+ ██╔════╝ ██╔══██╗████╗ ████║
127
+ ██║ ██████╔╝██╔████╔██║
128
+ ██║ ██╔══██╗██║╚██╔╝██║
129
+ ╚██████╗ ██████╔╝██║ ╚═╝ ██║
130
+ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝
131
+
132
+ Codebase Memory Manager
133
+ - Supercharge your agentic coding — without the token bleed
134
+
135
+ Usage: cbm [command]
136
+
137
+ Setup:
138
+ install (i) Install codebase-memory-mcp + select agents
139
+ update (up) Update to latest version
140
+ uninstall Remove from system
141
+ version (-V, -v) Show version info
142
+ kill (k) Stop running server
143
+ help (-h, --help) Show help
144
+
145
+ Project:
146
+ build (b) Index + create shareable graph + select agents
147
+ use (u) Use shared graph (no indexing needed)
148
+ re-index (ri) Force re-index + fresh artifact
149
+ status (s) Show project graph status
150
+
151
+ Options:
152
+ --version, -V, -v Show version
153
+ --help, -h Show help
154
+ --yes, -y Skip prompts
155
+ --agents, -a Specify agents (comma-separated)
156
+
157
+ Raw CLI:
158
+ cbm <cmd> Any codebase-memory-mcp CLI command
159
+ Example: cbm cli search_graph '{"name_pattern": ".*"}'
160
+
161
+ Supported Agents:
162
+ Claude Code, Codex CLI, Gemini CLI, Zed, OpenCode,
163
+ Antigravity, Aider, KiloCode, VS Code, OpenClaw, Kiro
164
+
165
+ Notes:
166
+ • Aider: No native MCP config — use ./cbm-aider wrapper
167
+ • Antigravity: Shares Gemini CLI config file
168
+
169
+ Workflow:
170
+ cbm install → select agents → cbm build → select agents → git push
171
+ ```
172
+
173
+ ---
174
+
175
+ ## Commands
176
+
177
+ ### Setup
178
+
179
+ | Command | Alias | Description |
180
+ |---|---|---|
181
+ | `cbm install` | `i` | Install `codebase-memory-mcp` + select agents |
182
+ | `cbm update` | `up` | Update to latest version |
183
+ | `cbm uninstall` | | Remove from system |
184
+ | `cbm version` | `-V`, `-v` | Show version info |
185
+ | `cbm kill` | `k` | Stop running server |
186
+ | `cbm help` | `-h`, `--help` | Show help |
187
+
188
+ ### Project
189
+
190
+ | Command | Alias | Description |
191
+ |---|---|---|
192
+ | `cbm build` | `b` | Index + create shareable `graph.db.zst` + select agents |
193
+ | `cbm use` | `u` | Use shared graph (no indexing needed) |
194
+ | `cbm re-index` | `ri` | Force re-index + fresh artifact |
195
+ | `cbm status` | `s` | Show project graph status |
196
+
197
+ ### Raw CLI
198
+
199
+ Any command not recognized by `cbm` is passed to `codebase-memory-mcp`:
200
+
201
+ ```bash
202
+ cbm cli search_graph '{"name_pattern": ".*Handler"}'
203
+ cbm cli get_architecture '{}'
204
+ cbm config get auto_index
205
+ cbm --version
206
+ ```
207
+
208
+ ---
209
+
210
+ ## Non-Interactive / CI Mode
211
+
212
+ Use `--yes` to skip prompts and select all agents, or `--agents` to specify a comma-separated list:
213
+
214
+ ```bash
215
+ # Install and configure all agents without prompting
216
+ cbm install --yes
217
+
218
+ # Build and configure only Claude Code (1) and OpenCode (5)
219
+ cbm build --agents 1,5
220
+
221
+ # Use shared graph and configure only VS Code (9)
222
+ cbm use --agents 9
223
+ ```
224
+
225
+ **Agent numbers:**
226
+ 1. Claude Code
227
+ 2. Codex CLI
228
+ 3. Gemini CLI
229
+ 4. Zed
230
+ 5. OpenCode
231
+ 6. Antigravity
232
+ 7. Aider
233
+ 8. KiloCode
234
+ 9. VS Code
235
+ 10. OpenClaw
236
+ 11. Kiro
237
+
238
+ ---
239
+
240
+ ## Interactive Agent Selection
241
+
242
+ CBM features an **interactive arrow-key menu** for selecting coding agents:
243
+
244
+ ```
245
+ Configure which agents for this project?
246
+
247
+ ↑↓ navigate · space toggle · a all · n none · enter confirm
248
+
249
+ ❯ ○ Claude Code
250
+ ○ Codex CLI
251
+ ● Zed ← toggled
252
+ ○ OpenCode
253
+ ● VS Code ← toggled
254
+ ...
255
+ ```
256
+
257
+ ---
258
+
259
+ ## Workflows
260
+
261
+ ### Owner Workflow
262
+
263
+ ```bash
264
+ cd ~/projects/my-api
265
+ cbm build # Index + create artifact
266
+ git add .codebase-memory/graph.db.zst
267
+ git commit -m "Add codebase graph"
268
+ git push
269
+ ```
270
+
271
+ ### Teammate Workflow
272
+
273
+ ```bash
274
+ git clone <repo>
275
+ cd <repo>
276
+ cbm use # No indexing needed!
277
+ # Restart agent and code
278
+ ```
279
+
280
+ ### Refactor Workflow
281
+
282
+ ```bash
283
+ cd ~/projects/my-api
284
+ cbm re-index # Fresh graph after big changes
285
+ git add .codebase-memory/graph.db.zst
286
+ git commit -m "Update graph after refactor"
287
+ git push
288
+ ```
289
+
290
+ ---
291
+
292
+ ## What Gets Created
293
+
294
+ ```
295
+ my-awesome-api/
296
+ ├── .codebase-memory/
297
+ │ ├── cbm-server.sh ← MCP wrapper (committed)
298
+ │ └── graph.db.zst ← Shareable graph (committed)
299
+ ├── .opencode/ ← if OpenCode selected
300
+ │ └── opencode.json ← OpenCode config (committed)
301
+ ├── .claude/ ← if Claude Code selected
302
+ │ └── .mcp.json ← Claude Code config (committed)
303
+ ├── .vscode/ ← if VS Code selected
304
+ │ └── mcp.json ← VS Code config (committed)
305
+ ├── CONVENTIONS.md ← Aider conventions (if Aider selected)
306
+ ├── cbm-aider ← Aider wrapper (if Aider selected)
307
+ ├── .gitignore ← Ignores live DB
308
+ └── .gitattributes ← Prevents merge conflicts
309
+ ```
310
+
311
+ ---
312
+
313
+ ## Cross-Platform
314
+
315
+ | OS | Status |
316
+ |---|---|
317
+ | macOS | ✅ Fully supported |
318
+ | Linux | ✅ Fully supported |
319
+ | Windows | ✅ Supported (npm, PowerShell, Git Bash, WSL) |
320
+ | CI/CD | ✅ Non-interactive fallback with `--yes` / `--agents` |
321
+
322
+ ---
323
+
324
+ ## Pro Tips
325
+
326
+ ### 1. The Graph Travels With the Code
327
+
328
+ Commit `graph.db.zst` and CI can use it:
329
+
330
+ ```yaml
331
+ # .github/workflows/ci.yml
332
+ - name: Use codebase graph
333
+ run: |
334
+ npm install -g @mayurdluffy/cbm-cli
335
+ cbm use --yes
336
+ # run structural tests
337
+ ```
338
+
339
+ ### 2. Keep It Updated
340
+
341
+ After large refactors, run `cbm re-index` and commit the new `graph.db.zst` so teammates stay in sync.
342
+
343
+ ### 3. Aider Users
344
+
345
+ Aider has no native MCP config file. Use the generated `./cbm-aider` wrapper to launch Aider with `codebase-memory-mcp` attached.
346
+
347
+ ---
348
+
349
+ ## Troubleshooting
350
+
351
+ | Issue | Fix |
352
+ |---|---|
353
+ | `command not found: cbm` | `npm install -g @mayurdluffy/cbm-cli` or use `npx @mayurdluffy/cbm-cli` |
354
+ | `codebase-memory-mcp not found` | `cbm install` |
355
+ | Agent doesn't see tools | Restart agent; check `cbm status` |
356
+ | `graph.db.zst` missing | Run `cbm build` |
357
+ | Server won't start | `cbm kill` then restart agent |
358
+ | Stale graph | `cbm re-index` and commit |
359
+ | Interactive menu hangs in CI | Use `cbm <cmd> --yes` or `--agents N,M` |
360
+
361
+ ---
362
+
363
+ ## Contributing
364
+
365
+ This is a community project. Contributions, issues, and feedback are welcome!
366
+
367
+ ## License
368
+
369
+ MIT — see [LICENSE](LICENSE).
370
+
371
+ ---
372
+
373
+ <p align="center">
374
+ <strong>Built with ❤️ for teams that move fast.</strong><br>
375
+ <a href="https://github.com/mayurdluffy/cbm-cli">GitHub</a> •
376
+ <a href="https://www.npmjs.com/package/@mayurdluffy/cbm-cli">npm</a>
377
+ </p>
package/bin/cbm.js ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env node
2
+ // =============================================================================
3
+ // cbm — The Ultimate codebase-memory-mcp Manager (Node.js)
4
+ // =============================================================================
5
+ // Cross-platform: macOS · Linux · Windows
6
+ // Interactive arrow-key agent selection
7
+ // Supports all 11 coding agents that codebase-memory-mcp supports
8
+ // Project-level scope only
9
+ // =============================================================================
10
+
11
+ const { main } = require("../lib/index");
12
+
13
+ main().catch((err) => {
14
+ console.error(err.message);
15
+ process.exit(1);
16
+ });
package/lib/agents.js ADDED
@@ -0,0 +1,290 @@
1
+ const fs = require("fs");
2
+ const path = require("path");
3
+ const { C, log } = require("./logger");
4
+ const { AGENTS } = require("./constants");
5
+ const { getHomeDir } = require("./system");
6
+
7
+ const SERVER_WRAPPER = `#!/usr/bin/env bash
8
+ SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
9
+ export CBM_CACHE_DIR="$SCRIPT_DIR"
10
+ exec codebase-memory-mcp serve
11
+ `;
12
+
13
+ const AIDER_CONVENTIONS = `# Codebase Memory MCP — Project Conventions
14
+
15
+ This project uses \`codebase-memory-mcp\` for code intelligence.
16
+
17
+ ## Available MCP Tools
18
+
19
+ - \`index_repository\` — Index or re-index the project
20
+ - \`search_graph\` — Structural search (regex name patterns, label filters)
21
+ - \`trace_path\` — BFS call graph traversal (who calls what)
22
+ - \`get_architecture\` — Overview: languages, packages, routes, hotspots
23
+ - \`detect_changes\` — Map git diff to affected symbols + blast radius
24
+ - \`query_graph\` — Cypher-like graph queries (read-only)
25
+ - \`search_code\` — Graph-augmented grep over indexed files
26
+ - \`get_code_snippet\` — Read source by qualified name
27
+ - \`manage_adr\` — Architecture Decision Records
28
+ - \`semantic_query\` — Vector search across the graph
29
+ - \`dead_code\` — Find functions with zero callers
30
+ - \`list_projects\` — List indexed projects
31
+
32
+ ## Workflow
33
+
34
+ 1. Say "Index this project" to build the knowledge graph (or run \`cbm build\`)
35
+ 2. Ask structural questions: "What calls ProcessOrder?", "Find all HTTP routes"
36
+ 3. Use \`trace_path\` for call chains, \`search_graph\` for symbol discovery
37
+
38
+ ## Tips
39
+
40
+ - Use \`search_graph(name_pattern=".*PartialName.*")\` to find exact qualified names
41
+ - Add \`project="PROJECT_NAME"\` parameter when querying
42
+ - Run \`get_graph_schema\` first to understand the graph structure
43
+ `;
44
+
45
+ const AIDER_WRAPPER = `#!/usr/bin/env bash
46
+ # CBM Aider wrapper — launches Aider with codebase-memory-mcp
47
+ # Usage: ./cbm-aider [other-aider-args...]
48
+ SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
49
+ export CBM_CACHE_DIR="$SCRIPT_DIR/.codebase-memory"
50
+ exec aider --mcp-server "codebase-memory-mcp serve" "$@"
51
+ `;
52
+
53
+ function createWrapper(dir) {
54
+ const isWin = process.platform === "win32";
55
+ const wrapperPath = path.join(dir, "cbm-server.sh");
56
+
57
+ fs.writeFileSync(wrapperPath, SERVER_WRAPPER, { mode: 0o755 });
58
+
59
+ if (isWin) {
60
+ const cmdPath = path.join(dir, "cbm-server.cmd");
61
+ fs.writeFileSync(
62
+ cmdPath,
63
+ '@echo off\nset "CBM_CACHE_DIR=%~dp0"\ncodebase-memory-mcp serve\n',
64
+ );
65
+ }
66
+
67
+ return wrapperPath;
68
+ }
69
+
70
+ function createAiderConventions(projectDir) {
71
+ const conventionsPath = path.join(projectDir, "CONVENTIONS.md");
72
+ fs.writeFileSync(conventionsPath, AIDER_CONVENTIONS);
73
+ log.ok(`Created ${C.dim}CONVENTIONS.md${C.reset} for Aider`);
74
+ }
75
+
76
+ function createAiderWrapper(projectDir) {
77
+ const isWin = process.platform === "win32";
78
+ const aiderWrapperPath = path.join(projectDir, "cbm-aider");
79
+
80
+ fs.writeFileSync(aiderWrapperPath, AIDER_WRAPPER, { mode: 0o755 });
81
+ log.ok(`Created ${C.dim}cbm-aider${C.reset} wrapper script`);
82
+
83
+ if (isWin) {
84
+ const cmdPath = path.join(projectDir, "cbm-aider.cmd");
85
+ fs.writeFileSync(
86
+ cmdPath,
87
+ '@echo off\nset "CBM_CACHE_DIR=%~dp0.codebase-memory"\naider --mcp-server "codebase-memory-mcp serve" %*\n',
88
+ );
89
+ }
90
+ }
91
+
92
+ function generateConfig(agent, cmd) {
93
+ const configs = {
94
+ toml: () => `[mcp_servers.codebase-memory]\ncommand = "${cmd}"\nargs = []\n`,
95
+
96
+ jsonc: () =>
97
+ `{\n // codebase-memory-mcp\n "context_servers": {\n "codebase-memory": {\n "command": "${cmd}",\n "args": []\n }\n }\n}\n`,
98
+
99
+ "opencode-json": () =>
100
+ JSON.stringify(
101
+ {
102
+ mcp: {
103
+ "codebase-memory": {
104
+ type: "local",
105
+ command: [cmd],
106
+ enabled: true,
107
+ },
108
+ },
109
+ },
110
+ null,
111
+ 2,
112
+ ) + "\n",
113
+
114
+ "vscode-json": () =>
115
+ JSON.stringify(
116
+ {
117
+ servers: {
118
+ "codebase-memory": {
119
+ command: cmd,
120
+ args: [],
121
+ },
122
+ },
123
+ },
124
+ null,
125
+ 2,
126
+ ) + "\n",
127
+
128
+ "openclaw-json": () =>
129
+ JSON.stringify(
130
+ {
131
+ mcp: {
132
+ servers: {
133
+ "codebase-memory": {
134
+ command: cmd,
135
+ args: [],
136
+ transport: "stdio",
137
+ },
138
+ },
139
+ },
140
+ },
141
+ null,
142
+ 2,
143
+ ) + "\n",
144
+
145
+ "kilo-jsonc": () =>
146
+ JSON.stringify(
147
+ {
148
+ mcp: {
149
+ "codebase-memory": {
150
+ type: "local",
151
+ command: [cmd],
152
+ enabled: true,
153
+ },
154
+ },
155
+ },
156
+ null,
157
+ 2,
158
+ ) + "\n",
159
+
160
+ yml: () =>
161
+ `# Aider Configuration\nmcp_servers:\n codebase-memory:\n command: "${cmd}"\n args: []\n`,
162
+
163
+ json: () =>
164
+ JSON.stringify(
165
+ {
166
+ mcpServers: {
167
+ "codebase-memory": {
168
+ command: cmd,
169
+ args: [],
170
+ },
171
+ },
172
+ },
173
+ null,
174
+ 2,
175
+ ) + "\n",
176
+ };
177
+
178
+ return (configs[agent.format] || configs.json)();
179
+ }
180
+
181
+ function createAgentConfig(agentIdx, projectDir) {
182
+ const agent = AGENTS[agentIdx];
183
+
184
+ if (agent.name === "Aider") {
185
+ createAiderConventions(projectDir);
186
+ createAiderWrapper(projectDir);
187
+ log.warn(
188
+ `${agent.name}: ${C.yellow}No native MCP config — use ${C.cyan}./cbm-aider${C.yellow} to launch${C.reset}`,
189
+ );
190
+ return;
191
+ }
192
+
193
+ const configPath = path.join(projectDir, agent.config);
194
+ const configDir = path.dirname(configPath);
195
+ const wrapperPath = path.join(
196
+ projectDir,
197
+ ".codebase-memory",
198
+ "cbm-server.sh",
199
+ );
200
+ const cmd = wrapperPath.replace(/\\/g, "/");
201
+
202
+ if (configDir !== projectDir) {
203
+ fs.mkdirSync(configDir, { recursive: true });
204
+ }
205
+
206
+ if (agent.sharesConfigWith) {
207
+ return handleSharedConfig(agent, configPath, cmd);
208
+ }
209
+
210
+ const content = generateConfig(agent, cmd);
211
+ fs.writeFileSync(configPath, content);
212
+ log.ok(`${agent.name}: ${C.dim}${agent.config}${C.reset}`);
213
+ }
214
+
215
+ function handleSharedConfig(agent, configPath, cmd) {
216
+ if (!fs.existsSync(configPath)) {
217
+ const content = generateConfig(agent, cmd);
218
+ fs.writeFileSync(configPath, content);
219
+ log.ok(`${agent.name}: ${C.dim}${agent.config}${C.reset}`);
220
+ return;
221
+ }
222
+
223
+ try {
224
+ const existing = JSON.parse(fs.readFileSync(configPath, "utf8"));
225
+ if (!existing.mcpServers) existing.mcpServers = {};
226
+ if (!existing.mcpServers["codebase-memory"]) {
227
+ existing.mcpServers["codebase-memory"] = { command: cmd, args: [] };
228
+ fs.writeFileSync(
229
+ configPath,
230
+ JSON.stringify(existing, null, 2) + "\n",
231
+ );
232
+ log.ok(
233
+ `${agent.name}: ${C.dim}merged into ${agent.config}${C.reset} (shared with ${agent.sharesConfigWith})`,
234
+ );
235
+ } else {
236
+ log.ok(
237
+ `${agent.name}: ${C.dim}already configured in ${agent.config}${C.reset}`,
238
+ );
239
+ }
240
+ } catch {
241
+ const content = generateConfig(agent, cmd);
242
+ fs.writeFileSync(configPath, content);
243
+ log.ok(`${agent.name}: ${C.dim}${agent.config}${C.reset}`);
244
+ }
245
+ }
246
+
247
+ function createGlobalConfig(agent) {
248
+ const globalDir = agent.globalDir();
249
+ fs.mkdirSync(globalDir, { recursive: true });
250
+
251
+ if (agent.name === "Aider") {
252
+ const conventionsPath = path.join(getHomeDir(), "CONVENTIONS.md");
253
+ if (!fs.existsSync(conventionsPath)) {
254
+ createAiderConventions(getHomeDir());
255
+ log.ok(`Global: ${agent.name} (CONVENTIONS.md)`);
256
+ }
257
+ return;
258
+ }
259
+
260
+ const cmd = "codebase-memory-mcp";
261
+ let configFile;
262
+
263
+ const globalPaths = {
264
+ toml: () => path.join(globalDir, "config.toml"),
265
+ jsonc: () => path.join(globalDir, "settings.json"),
266
+ "opencode-json": () => path.join(globalDir, "opencode.json"),
267
+ "vscode-json": () => path.join(globalDir, "mcp.json"),
268
+ "openclaw-json": () => path.join(globalDir, "openclaw.json"),
269
+ "kilo-jsonc": () => path.join(globalDir, "kilo.jsonc"),
270
+ json: () => path.join(globalDir, "mcp.json"),
271
+ yml: () => path.join(globalDir, "mcp.json"),
272
+ };
273
+
274
+ configFile = (globalPaths[agent.format] || globalPaths.json)();
275
+
276
+ if (fs.existsSync(configFile)) return;
277
+
278
+ const content = generateConfig({ ...agent, format: agent.format }, cmd);
279
+ fs.writeFileSync(configFile, content);
280
+ log.ok(`Global: ${agent.name}`);
281
+ }
282
+
283
+ module.exports = {
284
+ createWrapper,
285
+ createAgentConfig,
286
+ createGlobalConfig,
287
+ createAiderConventions,
288
+ createAiderWrapper,
289
+ generateConfig,
290
+ };