Commit c5165e4
feat(installer): multi-target — Claude Code, Cursor, Codex CLI, opencode
Closes the Claude-locked installer behind upstream issue
colbymchenry#137 ("Codex / Cursor support — needs global
support for the agent whatever the agent is"). The runtime MCP
server was already agent-agnostic (stdio); only the installer was
locked. After this refactor, `codegraph install` can write per-agent
MCP config + instructions for any combination of supported agents.
## What ships
Four agent targets, each implementing the new `AgentTarget`
interface:
- **Claude Code** — `~/.claude.json`, `~/.claude/settings.json`,
`~/.claude/CLAUDE.md` (or local equivalents). Behaviour preserved
from the original installer; existing installs upgrade in place.
- **Cursor** — `~/.cursor/mcp.json` (g) or `./.cursor/mcp.json` (l)
+ project-local `./.cursor/rules/codegraph.mdc` with the
always-on frontmatter Cursor expects. No global rules surface
exists yet.
- **Codex CLI** — `~/.codex/config.toml` with the dotted-key table
`[mcp_servers.codegraph]` + `~/.codex/AGENTS.md`. Global only —
Codex has no project-local config concept as of 2026-05.
TOML is hand-rolled in `src/installer/targets/toml.ts` (no
dependency added — the surface is one table block).
- **opencode** — `~/.config/opencode/opencode.json` (XDG-aware) or
`./opencode.json`. Different config shape (`mcp.<name>` instead of
`mcpServers`), command + args as a single string array.
Adding a 5th agent (Continue, Zed, Windsurf, ...) is now a single
new file in `src/installer/targets/` plus one entry in
`registry.ts`. No other changes needed.
## CLI changes
`codegraph install` is no longer Claude-only:
```
codegraph install # interactive multi-select
codegraph install --yes # auto-detect, install global
codegraph install --target=cursor,claude --yes # explicit list
codegraph install --target=auto --location=local # detected, project-local
codegraph install --target=none # skip agent writes entirely
codegraph install --print-config codex # dump snippet, no writes
```
| Flag | Values | Default |
|---|---|---|
| `--target` | `auto`, `all`, `none`, csv | prompt |
| `--location` | `global`, `local` | prompt |
| `--yes` | (boolean) | prompt |
| `--no-permissions` | (boolean) — Claude only | permissions on |
| `--print-config <id>` | dump snippet for one agent | — |
Bare `codegraph install` (TTY) still works — interactive prompt now
includes a multi-select for agents, defaulting to detected. Bare
behavior with nothing detected = `['claude']` so existing users see
no surprise.
## Architecture
```
src/installer/
├── instructions-template.ts # neutral name; legacy claude-md-template re-exports
├── targets/
│ ├── types.ts # AgentTarget, Location, WriteResult
│ ├── shared.ts # readJsonFile/writeJsonFile/atomicWrite/markers
│ ├── toml.ts # narrow [mcp_servers.codegraph] serializer
│ ├── claude.ts # extracted from old config-writer.ts
│ ├── cursor.ts
│ ├── codex.ts
│ ├── opencode.ts
│ └── registry.ts # ALL_TARGETS, getTarget, detectAll, resolveTargetFlag
├── index.ts # runInstallerWithOptions(opts) orchestrator
├── config-writer.ts # @deprecated shim — re-exports per-file helpers
└── claude-md-template.ts # @deprecated shim — re-exports the template module
```
Backwards compat: every export from the old `config-writer.ts`
(`writeMcpConfig`, `writePermissions`, `writeClaudeMd`,
`hasMcpConfig`, `hasPermissions`, `hasClaudeMdSection`) is preserved
as an `@deprecated` shim that delegates to the per-file helpers in
`targets/claude.ts`. Each shim writes ONLY the named file (no
silent multi-file side effects).
## Reviewer-driven fixes (caught + landed in this commit)
- **`--no-permissions` defaulting bug**: commander's negate-form
leaves `opts.permissions = true` by default, so the original
`autoAllow: opts.permissions` always passed a boolean and silently
bypassed the interactive prompt. Now mapped explicitly:
`opts.permissions === false ? false : opts.yes ? true : undefined`.
- **Shim semantic drift**: refactored to expose
`writeMcpEntry / writePermissionsEntry / writeInstructionsEntry`
from `targets/claude.ts` so each `config-writer.ts` shim calls
only the per-file helper it names.
- **Codex TOCTOU**: `writeMcpEntry` was calling `fs.existsSync(file)`
twice across a `readFileSync`. Now uses `existing.length === 0`
derived from the single read.
## Tests (+47, suite 1117 -> 1164)
- `__tests__/installer-targets.test.ts` (47 tests)
- Parameterized contract test across all 4 targets x supported
locations: install writes files, second install is byte-identical
(all-`unchanged`), pre-existing sibling MCP servers preserved,
uninstall reverses install, printConfig writes nothing.
- Partial-state idempotency for Codex: AGENTS.md wiped after first
install -> second pass restores only the missing file, third
pass is fully unchanged.
- User-added key inside `[mcp_servers.codegraph]` overwritten on
re-install (locks in the "we own the codegraph block exclusively"
contract).
- Standalone TOML serializer tests: empty insert, idempotent
re-insert, replace-in-place preserving siblings, removal
preserving siblings, `[[array_of_tables]]` preserved.
- Registry: getTarget by id, resolveTargetFlag handling
auto/all/none/csv, unknown-id rejection.
- `__tests__/installer.test.ts`: one assertion relaxed (the new code
correctly returns `unchanged` for byte-identical re-runs instead
of `updated`); the test's actual contract — surrounding custom
content preserved — is unchanged.
`os.homedir` is non-configurable so the test mocks home via
`process.env.HOME` / `process.env.USERPROFILE` (matches what
`os.homedir()` reads internally).
## What this does NOT do
- **Continue, Zed, Windsurf** — deliberately deferred. Each is a new
file in `targets/`; the next person to want one writes one.
- **Per-target instructions formats beyond Cursor's `.mdc`** —
Codex/Claude both use the marker-delimited markdown body
unchanged. opencode has no built-in instructions surface, so
nothing is written for it.
- **Migration of existing global Claude installs** — the on-disk
layout is byte-identical to what the original installer wrote, so
no migration needed. Detection sees existing installs as
`alreadyConfigured: true` and re-running is a no-op.
## Uninstall behavior change (worth a release note)
`bin/uninstall.ts` now loops `ALL_TARGETS.uninstall('global')` on
`npm uninstall -g`. Previously only Claude paths were cleaned. A
user who manually configured `~/.codex/config.toml` with our block
will have it silently removed on package uninstall — acceptable
trade-off since we only target the dotted-key table we own, not the
whole file.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 56569cb commit c5165e4
18 files changed
Lines changed: 2079 additions & 527 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
121 | 121 | | |
122 | 122 | | |
123 | 123 | | |
124 | | - | |
125 | | - | |
126 | | - | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
127 | 127 | | |
128 | 128 | | |
129 | | - | |
| 129 | + | |
130 | 130 | | |
131 | | - | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
132 | 149 | | |
133 | 150 | | |
134 | 151 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
125 | 125 | | |
126 | 126 | | |
127 | 127 | | |
128 | | - | |
129 | | - | |
130 | | - | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
131 | 132 | | |
132 | 133 | | |
133 | 134 | | |
| |||
0 commit comments