nemu-cli 1.6.1 → 1.8.0

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,273 +1,273 @@
1
- # nemu-cli
2
-
3
- Command line access to Nemu. The package is `nemu-cli` and the command it installs is `nemu`,
4
- because `nemu` itself was taken on npm in 2016.
5
-
6
- ```bash
7
- bunx nemu-cli login
8
- ```
9
-
10
- Or install it once and drop the package name:
11
-
12
- ```bash
13
- bun add -g nemu-cli
14
- nemu login
15
- ```
16
-
17
- ## Signing in
18
-
19
- `nemu login` uses the OAuth device authorization grant, so nothing is typed into the terminal and no
20
- secret is baked into this package.
21
-
22
- ```
23
- $ nemu login
24
-
25
- Open https://app.nemu.cc/device
26
- Code BDXW-KRTQ
27
-
28
- Waiting for approval...
29
- ✓ Logged in as hiraeeth
30
- Token saved to ~/.nemu/auth.json
31
- ```
32
-
33
- The browser opens on its own. Pass `--no-browser` when there is no browser to open, which is the case
34
- over SSH and inside a container, and open the printed link from any other device. The code expires
35
- after 15 minutes. `--force` signs in again when a session already exists.
36
-
37
- ## Commands
38
-
39
- Every command takes `--json`, which is what you want when something other than a person is reading
40
- the output. Failures exit non zero and print `{"ok": false, "error": "..."}` under `--json`.
41
-
42
- Anything workspace scoped takes `-w` or `--workspace`, by id or by name. Left off, it uses your first
43
- workspace.
44
-
45
- ### Account
46
-
47
- | Command | Does |
48
- | --- | --- |
49
- | `nemu login` | Sign in on this machine |
50
- | `nemu logout` | Delete the stored token |
51
- | `nemu whoami` | Show the signed in account |
52
- | `nemu user` | Full account record |
53
- | `nemu scopes` | Every scope and the actions it covers |
54
- | `nemu health` | Service health |
55
- | `nemu api-version` | Supported API versions |
56
-
57
- ### Workspaces and members
58
-
59
- ```bash
60
- nemu workspaces list
61
- nemu workspaces get <id>
62
- nemu workspaces create "My workspace"
63
- nemu workspaces rename <id> "New name"
64
- nemu workspaces delete <id> --yes
65
- nemu workspaces budget
66
- nemu workspaces set-budget <id> 50
67
-
68
- nemu members list
69
- nemu members invite --email a@b.com,c@d.com --max-uses 5 --expires-in-days 30
70
- nemu members role <member-id> ADMIN
71
- nemu members remove <member-id>
72
- ```
73
-
74
- ### Providers and models
75
-
76
- ```bash
77
- nemu providers list
78
- nemu providers create myprovider --priority 1 \
79
- --base-url https://api.openai.com/v1 \
80
- --api-key sk-... \
81
- --compatibility OPENAI_COMPATIBLE
82
- nemu providers update <id> --priority 5 --enabled false
83
- nemu providers delete <id> --yes
84
-
85
- nemu models list --provider <provider-id> --type chat
86
- nemu models create --name gpt-5 --display-name "GPT 5" \
87
- --provider <provider-id> --type chat \
88
- --input-cost 0.00001 --output-cost 0.00003 --context-window 128000
89
- nemu models update <id> --output-cost 0.00004
90
- nemu models delete <id> --yes
91
- ```
92
-
93
- `--compatibility` is `OPENAI_COMPATIBLE`, `ANTHROPIC` or `OPENAI_RESPONSES`. Model `--type` is
94
- `chat`, `embedding`, `moderation`, `vision`, `audio` or `image`.
95
-
96
- ### Prompts and mappings
97
-
98
- ```bash
99
- nemu prompts create --name house-style --content "Answer plainly."
100
- nemu prompts list --type SYSTEM
101
- nemu prompts update <id> --content "Answer very plainly."
102
- nemu prompts delete <id> --yes
103
-
104
- nemu mappings create --source "gpt-4*" --target myprovider/gpt-5 --priority 10
105
- nemu mappings list
106
- nemu mappings delete <id> --yes
107
- ```
108
-
109
- ### Reading
110
-
111
- ```bash
112
- nemu metrics list --limit 20 --start 2026-09-01T00:00:00Z
113
- nemu metrics get <request-id>
114
- nemu quotas list
115
- nemu quotas update <id> --limit 5000
116
- nemu indexes create https://example.com --max-pages 20
117
- nemu workflows list
118
- ```
119
-
120
- ### Anything else
121
-
122
- ```bash
123
- nemu api GET api/v1/workspaces
124
- nemu api POST api/v1/providers --data '{"name":"x","priority":1}'
125
- ```
126
-
127
- `api` signs the request with your token and prints the raw JSON, so an endpoint with no dedicated
128
- command is still one line away.
129
-
130
- ## Context for coding agents
131
-
132
- Nemu Context keeps notes about a project (decisions, gotchas, conventions, and a handoff saying where
133
- work stopped) and gives them back to whichever agent opens the project next, on any machine. Your own
134
- agent reads and writes them; Nemu never calls a model.
135
-
136
- ```bash
137
- npm i -g nemu-cli # clients start nemu on every session, so install it globally
138
- nemu login
139
- nemu setup claude # or: nemu setup codex (aliases: cc, claude-code)
140
- ```
141
-
142
- Setup registers a `nemu` MCP server with the client through the client's own command
143
- (`claude mcp add --scope user`, `codex mcp add`) and asks whether to install hooks. Hooks load the
144
- project's notes when a session starts and, after a few edits inside the project, remind the agent to
145
- save a handoff when it finishes. If the work is still unsaved when the agent stops, the Stop hook asks
146
- once per session (Claude Code shows that one request as "Stop hook error"). Codex runs
147
- hooks only after you trust them once with `/hooks`. Pass `--hooks`, `--no-hooks` or `--yes` to skip
148
- the question.
149
-
150
- Editors work the same way without hooks: `nemu setup cursor`, `vscode`, `gemini`, `windsurf`, `zed`
151
- or `opencode` writes only the `nemu` entry into that editor's config (`~/.cursor/mcp.json`, VS Code's
152
- user `mcp.json` through `code --add-mcp`, `~/.gemini/settings.json`,
153
- `~/.codeium/windsurf/mcp_config.json`, Zed's `settings.json`, OpenCode's
154
- `~/.config/opencode/opencode.json` or `opencode.jsonc`). Everything else in the file,
155
- comments included, stays as it was, the previous file is kept with a `.nemu-backup` suffix, and a
156
- file that cannot be parsed is never touched.
157
-
158
- | Command | Does |
159
- | --- | --- |
160
- | `nemu claude [-- args]` | Set up if needed, then start Claude Code with the args after `--` |
161
- | `nemu codex [-- args]` | The same for Codex |
162
- | `nemu claude load memories [--all] [--yes]` | Import Claude Code's saved memories for this project (or all) |
163
- | `nemu claude load sessions [--limit n]` | Open Claude with your recent sessions and let it save what matters |
164
- | `nemu codex load sessions [--limit n]` | The same for Codex |
165
- | `nemu mcp` | The stdio MCP bridge clients start; it uses your login and refreshes it |
166
- | `nemu mcp config <client>` | Config for `cursor`, `gemini`, `vscode`, `windsurf`, `zed`, `opencode`, `claude`, `codex`, `remote` |
167
- | `nemu context` | What an agent sees for this folder |
168
- | `nemu context search <words>` | Search this project's notes |
169
- | `nemu context projects` / `export --out file` | List projects, or export everything as JSON |
170
- | `nemu status` | Sign in, this device, global install, and each client's setup |
171
- | `nemu uninstall [client\|all]` | Remove exactly what setup added, for any client or editor |
172
- | `nemu repair` | Bring the Nemu hooks and editor entries up to date for this version; also runs by itself once after each update |
173
- | `nemu update [--yes]` | Check for a newer version and install it. The CLI also asks by itself, at most once a day; `NEMU_NO_UPDATE_CHECK=1` turns that off |
174
- | `nemu token [--header]` | Print a fresh access token |
175
-
176
- A project is recognised by its first git commit, so the same repository shares notes on every machine
177
- you sign in from. Session transcripts never leave your machine: `load sessions` hands them to your
178
- own agent, which decides what to save. Secrets are removed before anything is saved, on your machine
179
- and again on the server, and saved notes are always given to agents as data, never as instructions.
180
-
181
- Each computer you sign in from is registered as a device. Revoke one in the console under Context to
182
- stop it reading or writing; what it already saved stays.
183
-
184
- ## Syncing a folder with a vault
185
-
186
- A vault is an Obsidian compatible folder of Markdown notes kept in your workspace's Context.
187
- `nemu sync` keeps a folder on this computer in step with one.
188
-
189
- ```bash
190
- nemu vault link ~/Notes --vault "Notes" # or --create for a new vault named after the folder
191
- nemu sync ~/Notes # one run
192
- nemu sync ~/Notes --watch # keep syncing until Ctrl C
193
- ```
194
-
195
- | Command | Does |
196
- | --- | --- |
197
- | `nemu vault list` | Vaults in the workspace |
198
- | `nemu vault link <folder> [--vault <name\|id>] [--create] [--obsidian]` | Link a folder; writes `<folder>/.nemu/vault.json` |
199
- | `nemu sync [folder] [--watch] [--dry-run] [--conflicts=merge\|file] [--allow-deletes]` | Sync a linked folder (the current one, or the nearest parent that is linked) |
200
- | `nemu vault status [folder]` | Last sync, device settings and open conflict copies |
201
- | `nemu vault unlink [folder]` | Stop syncing; the files stay |
202
-
203
- Files are compared by content, never by modification time. A note changed on both sides is merged
204
- line by line when the edits do not overlap; otherwise the vault's version keeps the name and yours
205
- is saved beside it as `Note (conflict, <device>, <date> <time>).md`. Conflict markers are never
206
- written into a note. `--conflicts=file` always writes the conflict file instead of merging, and is
207
- remembered for this device. An edit wins over a delete, and a rename keeps the note's history.
208
-
209
- Sync refuses to run without `.nemu/vault.json`, so an unmounted drive never reads as "everything was
210
- deleted". A run that would delete more than 10 files, every file, or at least 3 files and more than
211
- 10% of the vault stops and deletes nothing; pass `--allow-deletes` if you meant it. Symbolic links,
212
- files above the plan's size, case clashes and names Windows cannot hold are skipped and listed.
213
- `.git/`, `node_modules/`, `.trash/`, `.DS_Store`, `._*` and `.obsidian/workspace*.json` are never
214
- synced, the rest of `.obsidian/` only with `--obsidian`, and a `.nemuignore` file adds patterns.
215
- What each folder last agreed with its vault is kept in `~/.nemu/vaults/<vault id>.json`.
216
-
217
- `tests/sim/simulate.ts` runs several fake devices with random edits, moves, deletes, crashes and
218
- duplicated requests against a development platform and checks that they converge without losing a
219
- byte. It does nothing unless `NEMU_SIM_API_URL`, `NEMU_SIM_API_KEY` and `NEMU_SIM_ROOT` are set, so
220
- `bun test` stays offline.
221
-
222
- ## Error references
223
-
224
- After you sign in, a command that fails sends a small report and prints a reference like
225
- `NMU-7F3K-2Q9D` to quote if you contact support@nemu.cc. A report holds the command and flag names
226
- (never their values), the CLI, OS and Node versions, and the error with secrets and your home folder
227
- removed. Turn it off with `nemu config set reports off` or `NEMU_NO_REPORTS=1`.
228
-
229
- ## Deleting
230
-
231
- Every destructive command needs `--yes`. Without it the CLI refuses and tells you what it was about
232
- to remove. Setup and imports ask before changing anything when run in a terminal, and never ask when
233
- run from a script.
234
-
235
- Some things the CLI deliberately cannot do. It never asks for `workspaces:delete` or `keys:write`, so
236
- it cannot delete a workspace you reached through it or mint a gateway key. Workflows and metrics are
237
- read only through the API. Quota rules can be read, changed and removed but not created.
238
-
239
- ## Where the token lives
240
-
241
- `~/.nemu/auth.json`. On Linux and macOS it is written `0600`, readable only by you. Windows has no
242
- equivalent mode, so it inherits the permissions of your user profile directory.
243
-
244
- `nemu logout` deletes the file from this machine. It does not revoke anything on the server, so if the
245
- machine is not yours, revoke the grant in your account settings as well.
246
-
247
- ## Environment
248
-
249
- | Variable | Default | Purpose |
250
- | --- | --- | --- |
251
- | `NEMU_API_URL` | `https://app.nemu.cc` | Point the CLI at another console |
252
- | `NEMU_CLIENT_ID` | `nemu_cli` | Use a different OAuth client |
253
- | `NEMU_CONFIG_DIR` | `~/.nemu` | Store the token somewhere else |
254
- | `NEMU_NO_REPORTS` | unset | `1` turns off error reports |
255
- | `NEMU_BIN` | unset | Command setup writes into client configs instead of the global `nemu` |
256
- | `CLAUDE_CONFIG_DIR`, `CODEX_HOME` | client defaults | Honoured when setup writes hooks |
257
- | `NO_COLOR` | unset | Turn off colour |
258
-
259
- ## If something fails
260
-
261
- `This build is not a recognised client` means the console you are pointed at does not know
262
- `nemu_cli`. Check `NEMU_API_URL`.
263
-
264
- `The code expired before it was approved` means more than 15 minutes passed. Run `nemu login` again.
265
-
266
- `The request was rejected in the browser` means Reject was pressed. Nothing was authorized.
267
-
268
- On Git Bash for Windows, a path beginning with `/` is rewritten into a Windows path before the CLI
269
- sees it, so `nemu api GET /api/v1/user` fails. Drop the leading slash and use `api/v1/user`.
270
-
271
- ## Licence
272
-
273
- MIT
1
+ # nemu-cli
2
+
3
+ Command line access to Nemu. The package is `nemu-cli` and the command it installs is `nemu`,
4
+ because `nemu` itself was taken on npm in 2016.
5
+
6
+ ```bash
7
+ bunx nemu-cli login
8
+ ```
9
+
10
+ Or install it once and drop the package name:
11
+
12
+ ```bash
13
+ bun add -g nemu-cli
14
+ nemu login
15
+ ```
16
+
17
+ ## Signing in
18
+
19
+ `nemu login` uses the OAuth device authorization grant, so nothing is typed into the terminal and no
20
+ secret is baked into this package.
21
+
22
+ ```
23
+ $ nemu login
24
+
25
+ Open https://app.nemu.cc/device
26
+ Code BDXW-KRTQ
27
+
28
+ Waiting for approval...
29
+ ✓ Logged in as hiraeeth
30
+ Token saved to ~/.nemu/auth.json
31
+ ```
32
+
33
+ The browser opens on its own. Pass `--no-browser` when there is no browser to open, which is the case
34
+ over SSH and inside a container, and open the printed link from any other device. The code expires
35
+ after 15 minutes. `--force` signs in again when a session already exists.
36
+
37
+ ## Commands
38
+
39
+ Every command takes `--json`, which is what you want when something other than a person is reading
40
+ the output. Failures exit non zero and print `{"ok": false, "error": "..."}` under `--json`.
41
+
42
+ Anything workspace scoped takes `-w` or `--workspace`, by id or by name. Left off, it uses your first
43
+ workspace.
44
+
45
+ ### Account
46
+
47
+ | Command | Does |
48
+ | --- | --- |
49
+ | `nemu login` | Sign in on this machine |
50
+ | `nemu logout` | Delete the stored token |
51
+ | `nemu whoami` | Show the signed in account |
52
+ | `nemu user` | Full account record |
53
+ | `nemu scopes` | Every scope and the actions it covers |
54
+ | `nemu health` | Service health |
55
+ | `nemu api-version` | Supported API versions |
56
+
57
+ ### Workspaces and members
58
+
59
+ ```bash
60
+ nemu workspaces list
61
+ nemu workspaces get <id>
62
+ nemu workspaces create "My workspace"
63
+ nemu workspaces rename <id> "New name"
64
+ nemu workspaces delete <id> --yes
65
+ nemu workspaces budget
66
+ nemu workspaces set-budget <id> 50
67
+
68
+ nemu members list
69
+ nemu members invite --email a@b.com,c@d.com --max-uses 5 --expires-in-days 30
70
+ nemu members role <member-id> ADMIN
71
+ nemu members remove <member-id>
72
+ ```
73
+
74
+ ### Providers and models
75
+
76
+ ```bash
77
+ nemu providers list
78
+ nemu providers create myprovider --priority 1 \
79
+ --base-url https://api.openai.com/v1 \
80
+ --api-key sk-... \
81
+ --compatibility OPENAI_COMPATIBLE
82
+ nemu providers update <id> --priority 5 --enabled false
83
+ nemu providers delete <id> --yes
84
+
85
+ nemu models list --provider <provider-id> --type chat
86
+ nemu models create --name gpt-5 --display-name "GPT 5" \
87
+ --provider <provider-id> --type chat \
88
+ --input-cost 0.00001 --output-cost 0.00003 --context-window 128000
89
+ nemu models update <id> --output-cost 0.00004
90
+ nemu models delete <id> --yes
91
+ ```
92
+
93
+ `--compatibility` is `OPENAI_COMPATIBLE`, `ANTHROPIC` or `OPENAI_RESPONSES`. Model `--type` is
94
+ `chat`, `embedding`, `moderation`, `vision`, `audio` or `image`.
95
+
96
+ ### Prompts and mappings
97
+
98
+ ```bash
99
+ nemu prompts create --name house-style --content "Answer plainly."
100
+ nemu prompts list --type SYSTEM
101
+ nemu prompts update <id> --content "Answer very plainly."
102
+ nemu prompts delete <id> --yes
103
+
104
+ nemu mappings create --source "gpt-4*" --target myprovider/gpt-5 --priority 10
105
+ nemu mappings list
106
+ nemu mappings delete <id> --yes
107
+ ```
108
+
109
+ ### Reading
110
+
111
+ ```bash
112
+ nemu metrics list --limit 20 --start 2026-09-01T00:00:00Z
113
+ nemu metrics get <request-id>
114
+ nemu quotas list
115
+ nemu quotas update <id> --limit 5000
116
+ nemu indexes create https://example.com --max-pages 20
117
+ nemu workflows list
118
+ ```
119
+
120
+ ### Anything else
121
+
122
+ ```bash
123
+ nemu api GET api/v1/workspaces
124
+ nemu api POST api/v1/providers --data '{"name":"x","priority":1}'
125
+ ```
126
+
127
+ `api` signs the request with your token and prints the raw JSON, so an endpoint with no dedicated
128
+ command is still one line away.
129
+
130
+ ## Context for coding agents
131
+
132
+ Nemu Context keeps notes about a project (decisions, gotchas, conventions, and a handoff saying where
133
+ work stopped) and gives them back to whichever agent opens the project next, on any machine. Your own
134
+ agent reads and writes them; Nemu never calls a model.
135
+
136
+ ```bash
137
+ npm i -g nemu-cli # clients start nemu on every session, so install it globally
138
+ nemu login
139
+ nemu setup claude # or: nemu setup codex (aliases: cc, claude-code)
140
+ ```
141
+
142
+ Setup registers a `nemu` MCP server with the client through the client's own command
143
+ (`claude mcp add --scope user`, `codex mcp add`) and asks whether to install hooks. Hooks load the
144
+ project's notes when a session starts and, after a few edits inside the project, remind the agent to
145
+ save a handoff when it finishes. If the work is still unsaved when the agent stops, the Stop hook asks
146
+ once per session (Claude Code shows that one request as "Stop hook error"). Codex runs
147
+ hooks only after you trust them once with `/hooks`. Pass `--hooks`, `--no-hooks` or `--yes` to skip
148
+ the question.
149
+
150
+ Editors work the same way without hooks: `nemu setup cursor`, `vscode`, `gemini`, `windsurf`, `zed`
151
+ or `opencode` writes only the `nemu` entry into that editor's config (`~/.cursor/mcp.json`, VS Code's
152
+ user `mcp.json` through `code --add-mcp`, `~/.gemini/settings.json`,
153
+ `~/.codeium/windsurf/mcp_config.json`, Zed's `settings.json`, OpenCode's
154
+ `~/.config/opencode/opencode.json` or `opencode.jsonc`). Everything else in the file,
155
+ comments included, stays as it was, the previous file is kept with a `.nemu-backup` suffix, and a
156
+ file that cannot be parsed is never touched.
157
+
158
+ | Command | Does |
159
+ | --- | --- |
160
+ | `nemu claude [-- args]` | Set up if needed, then start Claude Code with the args after `--` |
161
+ | `nemu codex [-- args]` | The same for Codex |
162
+ | `nemu claude load memories [--all] [--yes]` | Import Claude Code's saved memories for this project (or all) |
163
+ | `nemu claude load sessions [--limit n]` | Open Claude with your recent sessions and let it save what matters |
164
+ | `nemu codex load sessions [--limit n]` | The same for Codex |
165
+ | `nemu mcp` | The stdio MCP bridge clients start; it uses your login and refreshes it |
166
+ | `nemu mcp config <client>` | Config for `cursor`, `gemini`, `vscode`, `windsurf`, `zed`, `opencode`, `claude`, `codex`, `remote` |
167
+ | `nemu context` | What an agent sees for this folder |
168
+ | `nemu context search <words>` | Search this project's notes |
169
+ | `nemu context projects` / `export --out file` | List projects, or export everything as JSON |
170
+ | `nemu status` | Sign in, this device, global install, and each client's setup |
171
+ | `nemu uninstall [client\|all]` | Remove exactly what setup added, for any client or editor |
172
+ | `nemu repair` | Bring the Nemu hooks and editor entries up to date for this version; also runs by itself once after each update |
173
+ | `nemu update [--yes]` | Check for a newer version and install it. The CLI also asks by itself, at most once a day; `NEMU_NO_UPDATE_CHECK=1` turns that off |
174
+ | `nemu token [--header]` | Print a fresh access token |
175
+
176
+ A project is recognised by its first git commit, so the same repository shares notes on every machine
177
+ you sign in from. Session transcripts never leave your machine: `load sessions` hands them to your
178
+ own agent, which decides what to save. Secrets are removed before anything is saved, on your machine
179
+ and again on the server, and saved notes are always given to agents as data, never as instructions.
180
+
181
+ Each computer you sign in from is registered as a device. Revoke one in the console under Context to
182
+ stop it reading or writing; what it already saved stays.
183
+
184
+ ## Syncing a folder with a vault
185
+
186
+ A vault is an Obsidian compatible folder of Markdown notes kept in your workspace's Context.
187
+ `nemu sync` keeps a folder on this computer in step with one.
188
+
189
+ ```bash
190
+ nemu vault link ~/Notes --vault "Notes" # or --create for a new vault named after the folder
191
+ nemu sync ~/Notes # one run
192
+ nemu sync ~/Notes --watch # keep syncing until Ctrl C
193
+ ```
194
+
195
+ | Command | Does |
196
+ | --- | --- |
197
+ | `nemu vault list` | Vaults in the workspace |
198
+ | `nemu vault link <folder> [--vault <name\|id>] [--create] [--obsidian]` | Link a folder; writes `<folder>/.nemu/vault.json` |
199
+ | `nemu sync [folder] [--watch] [--dry-run] [--conflicts=merge\|file] [--allow-deletes]` | Sync a linked folder (the current one, or the nearest parent that is linked) |
200
+ | `nemu vault status [folder]` | Last sync, device settings and open conflict copies |
201
+ | `nemu vault unlink [folder]` | Stop syncing; the files stay |
202
+
203
+ Files are compared by content, never by modification time. A note changed on both sides is merged
204
+ line by line when the edits do not overlap; otherwise the vault's version keeps the name and yours
205
+ is saved beside it as `Note (conflict, <device>, <date> <time>).md`. Conflict markers are never
206
+ written into a note. `--conflicts=file` always writes the conflict file instead of merging, and is
207
+ remembered for this device. An edit wins over a delete, and a rename keeps the note's history.
208
+
209
+ Sync refuses to run without `.nemu/vault.json`, so an unmounted drive never reads as "everything was
210
+ deleted". A run that would delete more than 10 files, every file, or at least 3 files and more than
211
+ 10% of the vault stops and deletes nothing; pass `--allow-deletes` if you meant it. Symbolic links,
212
+ files above the plan's size, case clashes and names Windows cannot hold are skipped and listed.
213
+ `.git/`, `node_modules/`, `.trash/`, `.DS_Store`, `._*` and `.obsidian/workspace*.json` are never
214
+ synced, the rest of `.obsidian/` only with `--obsidian`, and a `.nemuignore` file adds patterns.
215
+ What each folder last agreed with its vault is kept in `~/.nemu/vaults/<vault id>.json`.
216
+
217
+ `tests/sim/simulate.ts` runs several fake devices with random edits, moves, deletes, crashes and
218
+ duplicated requests against a development platform and checks that they converge without losing a
219
+ byte. It does nothing unless `NEMU_SIM_API_URL`, `NEMU_SIM_API_KEY` and `NEMU_SIM_ROOT` are set, so
220
+ `bun test` stays offline.
221
+
222
+ ## Error references
223
+
224
+ After you sign in, a command that fails sends a small report and prints a reference like
225
+ `NMU-7F3K-2Q9D` to quote if you contact support@nemu.cc. A report holds the command and flag names
226
+ (never their values), the CLI, OS and Node versions, and the error with secrets and your home folder
227
+ removed. Turn it off with `nemu config set reports off` or `NEMU_NO_REPORTS=1`.
228
+
229
+ ## Deleting
230
+
231
+ Every destructive command needs `--yes`. Without it the CLI refuses and tells you what it was about
232
+ to remove. Setup and imports ask before changing anything when run in a terminal, and never ask when
233
+ run from a script.
234
+
235
+ Some things the CLI deliberately cannot do. It never asks for `workspaces:delete` or `keys:write`, so
236
+ it cannot delete a workspace you reached through it or mint a gateway key. Workflows and metrics are
237
+ read only through the API. Quota rules can be read, changed and removed but not created.
238
+
239
+ ## Where the token lives
240
+
241
+ `~/.nemu/auth.json`. On Linux and macOS it is written `0600`, readable only by you. Windows has no
242
+ equivalent mode, so it inherits the permissions of your user profile directory.
243
+
244
+ `nemu logout` deletes the file from this machine. It does not revoke anything on the server, so if the
245
+ machine is not yours, revoke the grant in your account settings as well.
246
+
247
+ ## Environment
248
+
249
+ | Variable | Default | Purpose |
250
+ | --- | --- | --- |
251
+ | `NEMU_API_URL` | `https://app.nemu.cc` | Point the CLI at another console |
252
+ | `NEMU_CLIENT_ID` | `nemu_cli` | Use a different OAuth client |
253
+ | `NEMU_CONFIG_DIR` | `~/.nemu` | Store the token somewhere else |
254
+ | `NEMU_NO_REPORTS` | unset | `1` turns off error reports |
255
+ | `NEMU_BIN` | unset | Command setup writes into client configs instead of the global `nemu` |
256
+ | `CLAUDE_CONFIG_DIR`, `CODEX_HOME` | client defaults | Honoured when setup writes hooks |
257
+ | `NO_COLOR` | unset | Turn off colour |
258
+
259
+ ## If something fails
260
+
261
+ `This build is not a recognised client` means the console you are pointed at does not know
262
+ `nemu_cli`. Check `NEMU_API_URL`.
263
+
264
+ `The code expired before it was approved` means more than 15 minutes passed. Run `nemu login` again.
265
+
266
+ `The request was rejected in the browser` means Reject was pressed. Nothing was authorized.
267
+
268
+ On Git Bash for Windows, a path beginning with `/` is rewritten into a Windows path before the CLI
269
+ sees it, so `nemu api GET /api/v1/user` fails. Drop the leading slash and use `api/v1/user`.
270
+
271
+ ## Licence
272
+
273
+ MIT
@@ -0,0 +1,68 @@
1
+ import { cp, mkdir, rm, writeFile } from "node:fs/promises";
2
+ import { join } from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+ import { config_dir } from "../config.js";
5
+ import { CliError } from "../errors.js";
6
+ import { run } from "../system.js";
7
+ export const PLUGIN_ID = "nemu@nemu";
8
+ const MARKETPLACE = "nemu";
9
+ function bundled_plugin() {
10
+ return fileURLToPath(new URL("../../plugin", import.meta.url));
11
+ }
12
+ export function installed_plugin_dir() {
13
+ return join(config_dir(), "claude-plugin");
14
+ }
15
+ export async function supports_plugins() {
16
+ const result = await run("claude", ["plugin", "--help"]);
17
+ return result.code === 0 && /marketplace/.test(result.stdout);
18
+ }
19
+ async function stage_plugin(nemu) {
20
+ const target = installed_plugin_dir();
21
+ await rm(target, { recursive: true, force: true });
22
+ await mkdir(target, { recursive: true });
23
+ await cp(bundled_plugin(), target, {
24
+ recursive: true,
25
+ filter: (source) => !/(^|[\\/])\._[^\\/]*$/.test(source) && !source.endsWith(".DS_Store"),
26
+ });
27
+ const servers = {
28
+ mcpServers: { nemu: { command: nemu, args: ["mcp", "--client", "claude-code"] } },
29
+ };
30
+ await writeFile(join(target, "nemu", ".mcp.json"), `${JSON.stringify(servers, null, 2)}\n`);
31
+ return target;
32
+ }
33
+ async function must(args, what) {
34
+ const result = await run("claude", args);
35
+ if (result.code === 0)
36
+ return;
37
+ const detail = (result.stderr || result.stdout).trim().split("\n").pop() ?? "";
38
+ throw new CliError(`${what} failed${detail.length > 0 ? `: ${detail}` : ""}`, "client_command_failed");
39
+ }
40
+ export async function install_plugin(nemu) {
41
+ const source = await stage_plugin(nemu);
42
+ await run("claude", ["plugin", "uninstall", PLUGIN_ID]);
43
+ await run("claude", ["plugin", "marketplace", "remove", MARKETPLACE]);
44
+ await must(["plugin", "marketplace", "add", source], "Adding the Nemu plugin marketplace to Claude Code");
45
+ await must(["plugin", "install", PLUGIN_ID, "--scope", "user"], "Installing the Nemu plugin in Claude Code");
46
+ }
47
+ export async function remove_plugin() {
48
+ const removed = await run("claude", ["plugin", "uninstall", PLUGIN_ID]);
49
+ await run("claude", ["plugin", "marketplace", "remove", MARKETPLACE]);
50
+ await rm(installed_plugin_dir(), { recursive: true, force: true });
51
+ return removed.code === 0;
52
+ }
53
+ export async function has_plugin() {
54
+ const result = await run("claude", ["plugin", "list", "--json"]);
55
+ if (result.code !== 0)
56
+ return false;
57
+ try {
58
+ const listed = JSON.parse(result.stdout);
59
+ return (Array.isArray(listed) &&
60
+ listed.some((entry) => typeof entry === "object" &&
61
+ entry !== null &&
62
+ Reflect.get(entry, "id") === PLUGIN_ID &&
63
+ Reflect.get(entry, "enabled") !== false));
64
+ }
65
+ catch {
66
+ return false;
67
+ }
68
+ }
@@ -2,6 +2,7 @@ import { CliError } from "../errors.js";
2
2
  import { run } from "../system.js";
3
3
  import { mkdir } from "node:fs/promises";
4
4
  import { claude_settings, codex_dir, codex_hooks } from "./paths.js";
5
+ import { has_plugin, install_plugin, remove_plugin, supports_plugins } from "./claude-plugin.js";
5
6
  export const MCP_NAME = "nemu";
6
7
  async function must(binary, args, what) {
7
8
  const result = await run(binary, args);
@@ -20,13 +21,20 @@ export const CLIENTS = {
20
21
  after_setup: ["Start Claude Code with: nemu claude (or just claude)"],
21
22
  add_mcp: async (nemu) => {
22
23
  await run("claude", ["mcp", "remove", "--scope", "user", MCP_NAME]);
24
+ if (await supports_plugins()) {
25
+ await install_plugin(nemu);
26
+ return;
27
+ }
23
28
  await must("claude", ["mcp", "add", "--scope", "user", MCP_NAME, "--", nemu, "mcp", "--client", "claude-code"], "Registering the Nemu MCP server with Claude Code");
24
29
  },
25
30
  remove_mcp: async () => {
31
+ const plugin = await remove_plugin();
26
32
  const result = await run("claude", ["mcp", "remove", "--scope", "user", MCP_NAME]);
27
- return result.code === 0;
33
+ return plugin || result.code === 0;
28
34
  },
29
35
  has_mcp: async () => {
36
+ if (await has_plugin())
37
+ return true;
30
38
  const result = await run("claude", ["mcp", "get", MCP_NAME]);
31
39
  return result.code === 0 && /nemu/.test(result.stdout) && /\bmcp\b/.test(result.stdout);
32
40
  },