nemu-cli 1.2.0 → 1.3.1
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/CHANGELOG.md +20 -0
- package/README.md +8 -1
- package/dist/clients/editors.js +146 -0
- package/dist/clients/hooks.js +21 -5
- package/dist/clients/jsonc.js +136 -0
- package/dist/clients/registry.js +1 -1
- package/dist/commands/client.js +9 -1
- package/dist/commands/mcp.js +4 -4
- package/dist/commands/setup.js +29 -1
- package/dist/commands/status.js +24 -1
- package/dist/commands/uninstall.js +20 -3
- package/dist/index.js +3 -1
- package/dist/version.js +1 -1
- package/package.json +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.3.1
|
|
4
|
+
|
|
5
|
+
Fixes "hook failed, exited with code 1" for Codex on Windows. Codex starts hooks through a Windows
|
|
6
|
+
shell that cannot launch a command whose program path is quoted, and setup wrote the path to
|
|
7
|
+
`nemu.cmd` in quotes. The Codex hooks now name the program unquoted (or as `nemu.cmd` when its
|
|
8
|
+
path has spaces). `nemu codex` repairs hooks written by an earlier version before it starts Codex,
|
|
9
|
+
`nemu setup codex --hooks` does the same, and `nemu status` says when a repair is needed. Claude
|
|
10
|
+
Code runs hooks through Git Bash on Windows and is unchanged.
|
|
11
|
+
|
|
12
|
+
## 1.3.0
|
|
13
|
+
|
|
14
|
+
`nemu setup cursor`, `nemu setup vscode`, `nemu setup gemini`, `nemu setup windsurf` and
|
|
15
|
+
`nemu setup zed` add the Nemu MCP server to that editor's own config. Only the `nemu` entry is
|
|
16
|
+
written: every other server, setting, comment and the file's indentation stay exactly as they
|
|
17
|
+
were, the previous file is kept next to it with a `.nemu-backup` suffix, a file that cannot be
|
|
18
|
+
parsed is left alone, and a different server already called `nemu` is never overwritten. VS Code
|
|
19
|
+
uses its own `code --add-mcp` when it is on the PATH. `nemu uninstall <editor>` removes only
|
|
20
|
+
that entry, and `nemu status` lists the editors it finds. Hooks remain Claude Code and Codex
|
|
21
|
+
only.
|
|
22
|
+
|
|
3
23
|
## 1.2.0
|
|
4
24
|
|
|
5
25
|
The CLI tells you when a newer version is out: "There is a new version available (1.2.0 -> 1.3.0).
|
package/README.md
CHANGED
|
@@ -145,6 +145,13 @@ project's notes when a session starts and ask the agent to save a handoff before
|
|
|
145
145
|
hooks only after you trust them once with `/hooks`. Pass `--hooks`, `--no-hooks` or `--yes` to skip
|
|
146
146
|
the question.
|
|
147
147
|
|
|
148
|
+
Editors work the same way without hooks: `nemu setup cursor`, `vscode`, `gemini`, `windsurf` or
|
|
149
|
+
`zed` writes only the `nemu` entry into that editor's config (`~/.cursor/mcp.json`, VS Code's user
|
|
150
|
+
`mcp.json` through `code --add-mcp`, `~/.gemini/settings.json`,
|
|
151
|
+
`~/.codeium/windsurf/mcp_config.json`, Zed's `settings.json`). Everything else in the file,
|
|
152
|
+
comments included, stays as it was, the previous file is kept with a `.nemu-backup` suffix, and a
|
|
153
|
+
file that cannot be parsed is never touched.
|
|
154
|
+
|
|
148
155
|
| Command | Does |
|
|
149
156
|
| --- | --- |
|
|
150
157
|
| `nemu claude [-- args]` | Set up if needed, then start Claude Code with the args after `--` |
|
|
@@ -158,7 +165,7 @@ the question.
|
|
|
158
165
|
| `nemu context search <words>` | Search this project's notes |
|
|
159
166
|
| `nemu context projects` / `export --out file` | List projects, or export everything as JSON |
|
|
160
167
|
| `nemu status` | Sign in, this device, global install, and each client's setup |
|
|
161
|
-
| `nemu uninstall [
|
|
168
|
+
| `nemu uninstall [client\|all]` | Remove exactly what setup added, for any client or editor |
|
|
162
169
|
| `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 |
|
|
163
170
|
| `nemu token [--header]` | Print a fresh access token |
|
|
164
171
|
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { access } from "node:fs/promises";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { basename, join } from "node:path";
|
|
4
|
+
import { CliError } from "../errors.js";
|
|
5
|
+
import { run, which } from "../system.js";
|
|
6
|
+
import { MCP_NAME } from "./registry.js";
|
|
7
|
+
import { read_entry, remove_entry, set_entry } from "./jsonc.js";
|
|
8
|
+
async function exists(path) {
|
|
9
|
+
try {
|
|
10
|
+
await access(path);
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function home() {
|
|
18
|
+
const value = process.env.HOME;
|
|
19
|
+
return process.platform !== "win32" && value !== undefined && value.length > 0 ? value : homedir();
|
|
20
|
+
}
|
|
21
|
+
function config_home() {
|
|
22
|
+
return process.env.XDG_CONFIG_HOME ?? join(home(), ".config");
|
|
23
|
+
}
|
|
24
|
+
function app_data() {
|
|
25
|
+
return process.env.APPDATA ?? join(home(), "AppData", "Roaming");
|
|
26
|
+
}
|
|
27
|
+
function on_mac() {
|
|
28
|
+
return process.platform === "darwin";
|
|
29
|
+
}
|
|
30
|
+
function on_windows() {
|
|
31
|
+
return process.platform === "win32";
|
|
32
|
+
}
|
|
33
|
+
function vscode_user_dir() {
|
|
34
|
+
if (on_windows())
|
|
35
|
+
return join(app_data(), "Code", "User");
|
|
36
|
+
if (on_mac())
|
|
37
|
+
return join(home(), "Library", "Application Support", "Code", "User");
|
|
38
|
+
return join(config_home(), "Code", "User");
|
|
39
|
+
}
|
|
40
|
+
function zed_dir() {
|
|
41
|
+
return on_windows() ? join(app_data(), "Zed") : join(config_home(), "zed");
|
|
42
|
+
}
|
|
43
|
+
async function any_present(binaries, paths) {
|
|
44
|
+
for (const binary of binaries)
|
|
45
|
+
if ((await which(binary)) !== null)
|
|
46
|
+
return true;
|
|
47
|
+
for (const path of paths)
|
|
48
|
+
if (await exists(path))
|
|
49
|
+
return true;
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
function bridge(nemu, client) {
|
|
53
|
+
return { command: nemu, args: ["mcp", "--client", client] };
|
|
54
|
+
}
|
|
55
|
+
export function is_nemu_entry(value) {
|
|
56
|
+
if (typeof value !== "object" || value === null)
|
|
57
|
+
return false;
|
|
58
|
+
const entry = value;
|
|
59
|
+
if (typeof entry.command !== "string" || !Array.isArray(entry.args))
|
|
60
|
+
return false;
|
|
61
|
+
const program = basename(entry.command.replaceAll("\\", "/")).replace(/\.(cmd|exe|ps1)$/i, "");
|
|
62
|
+
return program === "nemu" && entry.args[0] === "mcp";
|
|
63
|
+
}
|
|
64
|
+
async function guard_foreign(path, keys) {
|
|
65
|
+
const existing = await read_entry(path, keys);
|
|
66
|
+
if (existing !== undefined && !is_nemu_entry(existing)) {
|
|
67
|
+
throw new CliError(`${path} already has a different server named "${MCP_NAME}", so nothing was changed. Rename or remove it, then run setup again.`, "config_conflict");
|
|
68
|
+
}
|
|
69
|
+
return existing;
|
|
70
|
+
}
|
|
71
|
+
function file_editor(id, label, config_path, keys, detect, value, after_setup) {
|
|
72
|
+
return {
|
|
73
|
+
id,
|
|
74
|
+
label,
|
|
75
|
+
config_path,
|
|
76
|
+
keys,
|
|
77
|
+
detect,
|
|
78
|
+
add: async (nemu) => {
|
|
79
|
+
await guard_foreign(config_path(), keys());
|
|
80
|
+
return set_entry(config_path(), keys(), value(nemu));
|
|
81
|
+
},
|
|
82
|
+
after_setup,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
export const EDITORS = {
|
|
86
|
+
cursor: file_editor("cursor", "Cursor", () => join(home(), ".cursor", "mcp.json"), () => ["mcpServers", MCP_NAME], () => any_present(["cursor"], [
|
|
87
|
+
join(home(), ".cursor"),
|
|
88
|
+
...(on_mac() ? ["/Applications/Cursor.app"] : []),
|
|
89
|
+
]), (nemu) => bridge(nemu, "cursor"), ["Restart Cursor, or open Cursor Settings, MCP, to see the nemu server."]),
|
|
90
|
+
vscode: {
|
|
91
|
+
id: "vscode",
|
|
92
|
+
label: "VS Code",
|
|
93
|
+
config_path: () => join(vscode_user_dir(), "mcp.json"),
|
|
94
|
+
keys: () => ["servers", MCP_NAME],
|
|
95
|
+
detect: () => any_present(["code"], [vscode_user_dir()]),
|
|
96
|
+
add: async (nemu) => {
|
|
97
|
+
const entry = { type: "stdio", ...bridge(nemu, "vscode") };
|
|
98
|
+
const path = join(vscode_user_dir(), "mcp.json");
|
|
99
|
+
const before = await guard_foreign(path, ["servers", MCP_NAME]);
|
|
100
|
+
if (JSON.stringify(before) === JSON.stringify(entry))
|
|
101
|
+
return { change: "unchanged", backup: null };
|
|
102
|
+
if ((await which("code")) !== null) {
|
|
103
|
+
const result = await run("code", ["--add-mcp", JSON.stringify({ name: MCP_NAME, ...entry })], {
|
|
104
|
+
timeout_ms: 60_000,
|
|
105
|
+
});
|
|
106
|
+
if (result.code === 0)
|
|
107
|
+
return { change: before === undefined ? "added" : "updated", backup: null };
|
|
108
|
+
}
|
|
109
|
+
return set_entry(path, ["servers", MCP_NAME], entry);
|
|
110
|
+
},
|
|
111
|
+
after_setup: [
|
|
112
|
+
"In VS Code, run MCP: List Servers and start nemu. VS Code asks you to trust it the first time.",
|
|
113
|
+
],
|
|
114
|
+
},
|
|
115
|
+
gemini: file_editor("gemini", "Gemini CLI", () => join(home(), ".gemini", "settings.json"), () => ["mcpServers", MCP_NAME], () => any_present(["gemini"], [join(home(), ".gemini")]), (nemu) => bridge(nemu, "gemini"), ["Start Gemini CLI and run /mcp to see the nemu server."]),
|
|
116
|
+
windsurf: file_editor("windsurf", "Windsurf", () => join(home(), ".codeium", "windsurf", "mcp_config.json"), () => ["mcpServers", MCP_NAME], () => any_present(["windsurf"], [
|
|
117
|
+
join(home(), ".codeium", "windsurf"),
|
|
118
|
+
...(on_mac() ? ["/Applications/Windsurf.app"] : []),
|
|
119
|
+
]), (nemu) => bridge(nemu, "windsurf"), ["Restart Windsurf, or refresh the MCP servers in Cascade."]),
|
|
120
|
+
zed: file_editor("zed", "Zed", () => join(zed_dir(), "settings.json"), () => ["context_servers", MCP_NAME], () => any_present(["zed"], [zed_dir(), ...(on_mac() ? ["/Applications/Zed.app"] : [])]), (nemu) => ({ ...bridge(nemu, "zed"), env: {} }), ["Zed picks the server up by itself. Open the Agent panel settings to check it is running."]),
|
|
121
|
+
};
|
|
122
|
+
const ALIASES = {
|
|
123
|
+
cursor: "cursor",
|
|
124
|
+
vscode: "vscode",
|
|
125
|
+
"vs-code": "vscode",
|
|
126
|
+
code: "vscode",
|
|
127
|
+
gemini: "gemini",
|
|
128
|
+
"gemini-cli": "gemini",
|
|
129
|
+
windsurf: "windsurf",
|
|
130
|
+
zed: "zed",
|
|
131
|
+
};
|
|
132
|
+
export function editor_from_name(name) {
|
|
133
|
+
const id = ALIASES[(name ?? "").toLowerCase()];
|
|
134
|
+
return id === undefined ? null : EDITORS[id];
|
|
135
|
+
}
|
|
136
|
+
export async function editor_has_nemu(spec) {
|
|
137
|
+
return is_nemu_entry(await read_entry(spec.config_path(), spec.keys()));
|
|
138
|
+
}
|
|
139
|
+
export async function remove_from_editor(spec) {
|
|
140
|
+
return (await remove_entry(spec.config_path(), spec.keys(), is_nemu_entry)) === "removed";
|
|
141
|
+
}
|
|
142
|
+
export async function require_editor(spec) {
|
|
143
|
+
if (!(await spec.detect())) {
|
|
144
|
+
throw new CliError(`${spec.label} was not found on this computer. Install it first, or print the config with: nemu mcp config ${spec.id}`, "client_missing");
|
|
145
|
+
}
|
|
146
|
+
}
|
package/dist/clients/hooks.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { readFile, writeFile, mkdir, rename, copyFile, access } from "node:fs/promises";
|
|
2
|
-
import { dirname } from "node:path";
|
|
2
|
+
import { dirname, win32 } from "node:path";
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
import { CliError } from "../errors.js";
|
|
5
5
|
export const HOOK_SPECS = {
|
|
@@ -34,8 +34,18 @@ export function is_own_command(command) {
|
|
|
34
34
|
function quote(path) {
|
|
35
35
|
return /[\s"'$`\\]/.test(path) ? `"${path.replace(/(["\\$`])/g, "\\$1")}"` : path;
|
|
36
36
|
}
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
const WINDOWS_UNSAFE = /[\s"'&|<>^%()!`]/;
|
|
38
|
+
function windows_program(nemu) {
|
|
39
|
+
return WINDOWS_UNSAFE.test(nemu) ? win32.basename(nemu) : nemu;
|
|
40
|
+
}
|
|
41
|
+
export function hook_command(nemu, hook, client, platform = process.platform) {
|
|
42
|
+
const rest = `hook ${hook} --client ${client}`;
|
|
43
|
+
if (client === "codex" && platform === "win32")
|
|
44
|
+
return `${windows_program(nemu)} ${rest}`;
|
|
45
|
+
return `${quote(nemu)} ${rest}`;
|
|
46
|
+
}
|
|
47
|
+
export function has_quoted_program(command) {
|
|
48
|
+
return command !== undefined && /^\s*["']/.test(command) && is_own_command(command);
|
|
39
49
|
}
|
|
40
50
|
async function exists(path) {
|
|
41
51
|
try {
|
|
@@ -90,13 +100,19 @@ function without_own(config) {
|
|
|
90
100
|
const { hooks: _previous, ...rest } = config;
|
|
91
101
|
return Object.keys(cleaned).length > 0 ? { ...rest, hooks: cleaned } : rest;
|
|
92
102
|
}
|
|
93
|
-
export async function
|
|
103
|
+
export async function needs_repair(path, platform = process.platform) {
|
|
104
|
+
if (platform !== "win32")
|
|
105
|
+
return false;
|
|
106
|
+
const config = await read_config(path).catch(() => ({}));
|
|
107
|
+
return Object.values(config.hooks ?? {}).some((groups) => groups.some((group) => (group.hooks ?? []).some((handler) => has_quoted_program(handler.command))));
|
|
108
|
+
}
|
|
109
|
+
export async function install_hooks(path, nemu, client, platform = process.platform) {
|
|
94
110
|
const config = without_own(await read_config(path));
|
|
95
111
|
const hooks = { ...(config.hooks ?? {}) };
|
|
96
112
|
for (const spec of HOOK_SPECS[client]) {
|
|
97
113
|
const group = {
|
|
98
114
|
...(spec.matcher !== undefined ? { matcher: spec.matcher } : {}),
|
|
99
|
-
hooks: [{ type: "command", command: hook_command(nemu, spec.hook, client), timeout: spec.timeout }],
|
|
115
|
+
hooks: [{ type: "command", command: hook_command(nemu, spec.hook, client, platform), timeout: spec.timeout }],
|
|
100
116
|
};
|
|
101
117
|
hooks[spec.event] = [...(hooks[spec.event] ?? []), group];
|
|
102
118
|
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { copyFile, mkdir, readFile, rename, stat, writeFile, chmod } from "node:fs/promises";
|
|
2
|
+
import { dirname } from "node:path";
|
|
3
|
+
import { applyEdits, findNodeAtLocation, getNodeValue, modify, parseTree } from "jsonc-parser";
|
|
4
|
+
import { CliError } from "../errors.js";
|
|
5
|
+
export const BACKUP_SUFFIX = ".nemu-backup";
|
|
6
|
+
async function read_text(path) {
|
|
7
|
+
try {
|
|
8
|
+
return await readFile(path, "utf-8");
|
|
9
|
+
}
|
|
10
|
+
catch (error) {
|
|
11
|
+
if (error.code === "ENOENT")
|
|
12
|
+
return null;
|
|
13
|
+
throw error;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function indentation(text) {
|
|
17
|
+
const eol = text.includes("\r\n") ? "\r\n" : "\n";
|
|
18
|
+
const indented = text.split(/\r?\n/).find((line) => /^[ \t]+\S/.test(line));
|
|
19
|
+
if (indented === undefined)
|
|
20
|
+
return { insertSpaces: true, tabSize: 2, eol };
|
|
21
|
+
if (indented.startsWith("\t"))
|
|
22
|
+
return { insertSpaces: false, tabSize: 1, eol };
|
|
23
|
+
const width = indented.length - indented.trimStart().length;
|
|
24
|
+
return { insertSpaces: true, tabSize: width === 4 ? 4 : 2, eol };
|
|
25
|
+
}
|
|
26
|
+
function parse_object(path, text) {
|
|
27
|
+
const errors = [];
|
|
28
|
+
const tree = parseTree(text, errors, { allowTrailingComma: true, disallowComments: false });
|
|
29
|
+
if (errors.length > 0 || tree === undefined || tree.type !== "object") {
|
|
30
|
+
throw new CliError(`${path} could not be read safely, so nothing was changed. Fix the file or add Nemu by hand: nemu mcp config`, "config_unreadable");
|
|
31
|
+
}
|
|
32
|
+
return tree;
|
|
33
|
+
}
|
|
34
|
+
async function write_atomic(path, text, original) {
|
|
35
|
+
await mkdir(dirname(path), { recursive: true });
|
|
36
|
+
const mode = original === null ? 0o644 : (await stat(path)).mode & 0o777;
|
|
37
|
+
const backup = original === null ? null : `${path}${BACKUP_SUFFIX}`;
|
|
38
|
+
if (backup !== null)
|
|
39
|
+
await copyFile(path, backup);
|
|
40
|
+
const temporary = `${path}.${process.pid}.nemu-tmp`;
|
|
41
|
+
await writeFile(temporary, text, { encoding: "utf-8", mode });
|
|
42
|
+
await chmod(temporary, mode).catch(() => undefined);
|
|
43
|
+
await rename(temporary, path);
|
|
44
|
+
return backup;
|
|
45
|
+
}
|
|
46
|
+
export async function read_entry(path, keys) {
|
|
47
|
+
const text = await read_text(path);
|
|
48
|
+
if (text === null)
|
|
49
|
+
return undefined;
|
|
50
|
+
const errors = [];
|
|
51
|
+
const tree = parseTree(text, errors, { allowTrailingComma: true, disallowComments: false });
|
|
52
|
+
if (errors.length > 0 || tree === undefined)
|
|
53
|
+
return undefined;
|
|
54
|
+
const node = findNodeAtLocation(tree, keys);
|
|
55
|
+
return node === undefined ? undefined : getNodeValue(node);
|
|
56
|
+
}
|
|
57
|
+
function line_indent(text, offset) {
|
|
58
|
+
const start = text.lastIndexOf("\n", offset - 1) + 1;
|
|
59
|
+
const match = /^[ \t]*/.exec(text.slice(start));
|
|
60
|
+
return match === null ? "" : match[0];
|
|
61
|
+
}
|
|
62
|
+
function pretty(value, indent, unit) {
|
|
63
|
+
return JSON.stringify(value, null, unit).replaceAll("\n", `\n${indent}`);
|
|
64
|
+
}
|
|
65
|
+
function splice(text, offset, length, content) {
|
|
66
|
+
return `${text.slice(0, offset)}${content}${text.slice(offset + length)}`;
|
|
67
|
+
}
|
|
68
|
+
function insert_entry(text, keys, value) {
|
|
69
|
+
const tree = parse_object("", text);
|
|
70
|
+
const style = indentation(text);
|
|
71
|
+
const unit = style.insertSpaces ? " ".repeat(style.tabSize) : "\t";
|
|
72
|
+
const existing = findNodeAtLocation(tree, keys);
|
|
73
|
+
if (existing !== undefined) {
|
|
74
|
+
const indent = line_indent(text, existing.offset);
|
|
75
|
+
return splice(text, existing.offset, existing.length, pretty(value, indent, unit));
|
|
76
|
+
}
|
|
77
|
+
let depth = keys.length - 1;
|
|
78
|
+
while (depth > 0 && findNodeAtLocation(tree, keys.slice(0, depth))?.type !== "object")
|
|
79
|
+
depth -= 1;
|
|
80
|
+
const parent = depth === 0 ? tree : findNodeAtLocation(tree, keys.slice(0, depth));
|
|
81
|
+
if (parent === undefined || parent.type !== "object") {
|
|
82
|
+
throw new CliError("The config has an unexpected shape, so nothing was changed.", "config_unreadable");
|
|
83
|
+
}
|
|
84
|
+
const missing = keys.slice(depth);
|
|
85
|
+
const nested = missing.slice(1).reduceRight((inner, key) => ({ [key]: inner }), value);
|
|
86
|
+
const parent_indent = line_indent(text, parent.offset);
|
|
87
|
+
const child_indent = `${parent_indent}${unit}`;
|
|
88
|
+
const property = `${JSON.stringify(missing[0])}: ${pretty(nested, child_indent, unit)}`;
|
|
89
|
+
const children = parent.children ?? [];
|
|
90
|
+
const last = children[children.length - 1];
|
|
91
|
+
if (last !== undefined) {
|
|
92
|
+
return splice(text, last.offset + last.length, 0, `,${style.eol}${child_indent}${property}`);
|
|
93
|
+
}
|
|
94
|
+
const inner_start = parent.offset + 1;
|
|
95
|
+
const inner_end = parent.offset + parent.length - 1;
|
|
96
|
+
const inner = text.slice(inner_start, inner_end);
|
|
97
|
+
const content = inner.trim().length === 0
|
|
98
|
+
? `${style.eol}${child_indent}${property}${style.eol}${parent_indent}`
|
|
99
|
+
: `${inner.replace(/\s+$/, "")}${style.eol}${child_indent}${property}${style.eol}${parent_indent}`;
|
|
100
|
+
return splice(text, inner_start, inner_end - inner_start, content);
|
|
101
|
+
}
|
|
102
|
+
export async function set_entry(path, keys, value) {
|
|
103
|
+
const original = await read_text(path);
|
|
104
|
+
const text = original === null || original.trim().length === 0 ? "{}" : original;
|
|
105
|
+
const tree = parse_object(path, text);
|
|
106
|
+
const existing = findNodeAtLocation(tree, keys);
|
|
107
|
+
if (existing !== undefined && JSON.stringify(getNodeValue(existing)) === JSON.stringify(value)) {
|
|
108
|
+
return { change: "unchanged", backup: null };
|
|
109
|
+
}
|
|
110
|
+
const next = insert_entry(text, keys, value);
|
|
111
|
+
const written = findNodeAtLocation(parse_object(path, next), keys);
|
|
112
|
+
if (written === undefined || JSON.stringify(getNodeValue(written)) !== JSON.stringify(value)) {
|
|
113
|
+
throw new CliError(`${path} could not be updated safely, so nothing was changed.`, "config_unreadable");
|
|
114
|
+
}
|
|
115
|
+
const backup = await write_atomic(path, next.endsWith("\n") ? next : `${next}\n`, original);
|
|
116
|
+
return { change: existing === undefined ? "added" : "updated", backup };
|
|
117
|
+
}
|
|
118
|
+
export async function remove_entry(path, keys, is_ours) {
|
|
119
|
+
const original = await read_text(path);
|
|
120
|
+
if (original === null)
|
|
121
|
+
return "absent";
|
|
122
|
+
const tree = parse_object(path, original);
|
|
123
|
+
const existing = findNodeAtLocation(tree, keys);
|
|
124
|
+
if (existing === undefined || !is_ours(getNodeValue(existing)))
|
|
125
|
+
return "absent";
|
|
126
|
+
let next = applyEdits(original, modify(original, keys, undefined, {}));
|
|
127
|
+
for (let depth = keys.length - 1; depth >= 1; depth -= 1) {
|
|
128
|
+
const parent = findNodeAtLocation(parse_object(path, next), keys.slice(0, depth));
|
|
129
|
+
if (parent === undefined || parent.type !== "object" || (parent.children ?? []).length > 0)
|
|
130
|
+
break;
|
|
131
|
+
next = applyEdits(next, modify(next, keys.slice(0, depth), undefined, {}));
|
|
132
|
+
}
|
|
133
|
+
parse_object(path, next);
|
|
134
|
+
await write_atomic(path, next, original);
|
|
135
|
+
return "removed";
|
|
136
|
+
}
|
package/dist/clients/registry.js
CHANGED
|
@@ -65,7 +65,7 @@ export function client_from_name(name) {
|
|
|
65
65
|
case "codex":
|
|
66
66
|
return CLIENTS.codex;
|
|
67
67
|
default:
|
|
68
|
-
throw new CliError("Pick a client: claude (aliases cc, claude-code) or
|
|
68
|
+
throw new CliError("Pick a client: claude (aliases cc, claude-code), codex, cursor, vscode, gemini, windsurf or zed. Others: nemu mcp config <client>", "invalid_client");
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
export async function client_installed(spec) {
|
package/dist/commands/client.js
CHANGED
|
@@ -2,7 +2,8 @@ import { client_from_name } from "../clients/registry.js";
|
|
|
2
2
|
import { launch } from "../system.js";
|
|
3
3
|
import { out, dim } from "../ui.js";
|
|
4
4
|
import { load } from "./load.js";
|
|
5
|
-
import { run_setup } from "./setup.js";
|
|
5
|
+
import { resolve_nemu_binary, run_setup } from "./setup.js";
|
|
6
|
+
import { install_hooks, needs_repair } from "../clients/hooks.js";
|
|
6
7
|
export function client_command(name) {
|
|
7
8
|
return async (args) => {
|
|
8
9
|
const spec = client_from_name(name);
|
|
@@ -14,6 +15,13 @@ export function client_command(name) {
|
|
|
14
15
|
out(dim(` Connecting ${spec.label} to Nemu Context first.`));
|
|
15
16
|
await run_setup(spec, args);
|
|
16
17
|
}
|
|
18
|
+
else if (spec.id === "codex" && (await needs_repair(spec.hooks_path()))) {
|
|
19
|
+
const nemu = await resolve_nemu_binary(false).catch(() => null);
|
|
20
|
+
if (nemu !== null) {
|
|
21
|
+
await install_hooks(spec.hooks_path(), nemu, spec.id);
|
|
22
|
+
out(dim(" Repaired the Nemu hooks so Codex on Windows can run them."));
|
|
23
|
+
}
|
|
24
|
+
}
|
|
17
25
|
return launch(spec.binary, args.positional);
|
|
18
26
|
};
|
|
19
27
|
}
|
package/dist/commands/mcp.js
CHANGED
|
@@ -8,7 +8,7 @@ import { current_project } from "../context/project.js";
|
|
|
8
8
|
import { repository } from "../git.js";
|
|
9
9
|
import { VERSION } from "../version.js";
|
|
10
10
|
import { out } from "../ui.js";
|
|
11
|
-
const CLIENTS = ["claude-code", "codex", "cursor", "zed", "gemini", "mcp"];
|
|
11
|
+
const CLIENTS = ["claude-code", "codex", "cursor", "zed", "gemini", "vscode", "windsurf", "mcp"];
|
|
12
12
|
const rpc_schema = z.object({
|
|
13
13
|
jsonrpc: z.literal("2.0"),
|
|
14
14
|
id: z.union([z.string(), z.number()]).optional(),
|
|
@@ -180,12 +180,12 @@ const SNIPPETS = {
|
|
|
180
180
|
text: JSON.stringify({ mcpServers: { nemu: { command: "nemu", args: ["mcp", "--client", "gemini"] } } }, null, 2),
|
|
181
181
|
},
|
|
182
182
|
vscode: {
|
|
183
|
-
where: ".vscode/mcp.json in
|
|
184
|
-
text: JSON.stringify({ servers: { nemu: { type: "stdio", command: "nemu", args: ["mcp"] } } }, null, 2),
|
|
183
|
+
where: "VS Code user mcp.json (MCP: Open User Configuration), or .vscode/mcp.json in a project",
|
|
184
|
+
text: JSON.stringify({ servers: { nemu: { type: "stdio", command: "nemu", args: ["mcp", "--client", "vscode"] } } }, null, 2),
|
|
185
185
|
},
|
|
186
186
|
windsurf: {
|
|
187
187
|
where: "~/.codeium/windsurf/mcp_config.json",
|
|
188
|
-
text: JSON.stringify({ mcpServers: { nemu: { command: "nemu", args: ["mcp"] } } }, null, 2),
|
|
188
|
+
text: JSON.stringify({ mcpServers: { nemu: { command: "nemu", args: ["mcp", "--client", "windsurf"] } } }, null, 2),
|
|
189
189
|
},
|
|
190
190
|
zed: {
|
|
191
191
|
where: "Zed settings.json",
|
package/dist/commands/setup.js
CHANGED
|
@@ -8,6 +8,7 @@ import { bold, confirm, dim, is_interactive, out, success } from "../ui.js";
|
|
|
8
8
|
import { emit, is_json_mode } from "../output.js";
|
|
9
9
|
import { install_hooks } from "../clients/hooks.js";
|
|
10
10
|
import { client_from_name, client_installed } from "../clients/registry.js";
|
|
11
|
+
import { editor_from_name, require_editor } from "../clients/editors.js";
|
|
11
12
|
import { login } from "./login.js";
|
|
12
13
|
function newer_or_equal(found, wanted) {
|
|
13
14
|
const parse = (value) => value.split(/[.-]/).slice(0, 3).map((part) => Number.parseInt(part, 10) || 0);
|
|
@@ -30,7 +31,7 @@ export async function resolve_nemu_binary(interactive_install) {
|
|
|
30
31
|
}
|
|
31
32
|
const verb = found === null ? "install" : "update";
|
|
32
33
|
const accepted = interactive_install &&
|
|
33
|
-
(await confirm(`
|
|
34
|
+
(await confirm(`Your agents start nemu on every session, so it needs a global install. ${verb === "install" ? "Install" : "Update"} it now with npm i -g nemu-cli@${VERSION}?`, true));
|
|
34
35
|
if (!accepted) {
|
|
35
36
|
throw new CliError(`Install the CLI globally first: npm i -g nemu-cli@${VERSION} (or bun add -g nemu-cli@${VERSION})`, "global_install_required");
|
|
36
37
|
}
|
|
@@ -85,7 +86,34 @@ export async function run_setup(spec, args) {
|
|
|
85
86
|
await install_hooks(spec.hooks_path(), nemu, spec.id);
|
|
86
87
|
return { client: spec.id, hooks, nemu, device_id };
|
|
87
88
|
}
|
|
89
|
+
async function setup_editor(editor, args) {
|
|
90
|
+
await require_editor(editor);
|
|
91
|
+
await ensure_signed_in();
|
|
92
|
+
const device_id = await ensure_device(bool_flag(args, "new-device"));
|
|
93
|
+
const nemu = await resolve_nemu_binary(is_interactive() && !bool_flag(args, "no-install"));
|
|
94
|
+
const { change, backup } = await editor.add(nemu);
|
|
95
|
+
if (is_json_mode()) {
|
|
96
|
+
emit({ ok: true, client: editor.id, change, config: editor.config_path(), backup, nemu, device_id });
|
|
97
|
+
return 0;
|
|
98
|
+
}
|
|
99
|
+
out();
|
|
100
|
+
success(`${editor.label} is connected to Nemu Context`);
|
|
101
|
+
out(dim(change === "unchanged"
|
|
102
|
+
? ` The nemu server was already in ${editor.config_path()}`
|
|
103
|
+
: ` MCP server "nemu" ${change === "added" ? "added to" : "updated in"} ${editor.config_path()}`));
|
|
104
|
+
if (backup !== null)
|
|
105
|
+
out(dim(` The file as it was before is saved at ${backup}`));
|
|
106
|
+
for (const line of editor.after_setup)
|
|
107
|
+
out(` ${line}`);
|
|
108
|
+
if (bool_flag(args, "hooks"))
|
|
109
|
+
out(dim(` Hooks are only available for Claude Code and Codex.`));
|
|
110
|
+
out(dim(` Check it any time with: ${bold("nemu status")}`));
|
|
111
|
+
return 0;
|
|
112
|
+
}
|
|
88
113
|
export async function setup(args) {
|
|
114
|
+
const editor = editor_from_name(args.positional[0]);
|
|
115
|
+
if (editor !== null)
|
|
116
|
+
return setup_editor(editor, args);
|
|
89
117
|
const spec = client_from_name(args.positional[0]);
|
|
90
118
|
const result = await run_setup(spec, args);
|
|
91
119
|
if (is_json_mode()) {
|
package/dist/commands/status.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { has_scope, read_credentials, read_settings, api_url } from "../config.js";
|
|
2
|
-
import { installed_hooks, HOOK_SPECS } from "../clients/hooks.js";
|
|
2
|
+
import { installed_hooks, needs_repair, HOOK_SPECS } from "../clients/hooks.js";
|
|
3
3
|
import { CLIENTS, client_installed } from "../clients/registry.js";
|
|
4
|
+
import { EDITORS, editor_has_nemu } from "../clients/editors.js";
|
|
4
5
|
import { run, which } from "../system.js";
|
|
5
6
|
import { VERSION } from "../version.js";
|
|
6
7
|
import { bold, dim, green, out, red } from "../ui.js";
|
|
@@ -24,9 +25,20 @@ export async function status() {
|
|
|
24
25
|
mcp,
|
|
25
26
|
hooks,
|
|
26
27
|
hooks_complete: hooks.length === HOOK_SPECS[spec.id].length,
|
|
28
|
+
hooks_need_repair: spec.id === "codex" && installed ? await needs_repair(spec.hooks_path()) : false,
|
|
27
29
|
hooks_path: spec.hooks_path(),
|
|
28
30
|
};
|
|
29
31
|
}));
|
|
32
|
+
const editors = await Promise.all(Object.values(EDITORS).map(async (editor) => {
|
|
33
|
+
const installed = await editor.detect();
|
|
34
|
+
return {
|
|
35
|
+
id: editor.id,
|
|
36
|
+
label: editor.label,
|
|
37
|
+
installed,
|
|
38
|
+
mcp: installed ? await editor_has_nemu(editor) : false,
|
|
39
|
+
config: editor.config_path(),
|
|
40
|
+
};
|
|
41
|
+
}));
|
|
30
42
|
const report = {
|
|
31
43
|
version: VERSION,
|
|
32
44
|
api_url: credentials?.api_url ?? api_url(),
|
|
@@ -38,6 +50,7 @@ export async function status() {
|
|
|
38
50
|
global_install: global,
|
|
39
51
|
global_version,
|
|
40
52
|
clients,
|
|
53
|
+
editors,
|
|
41
54
|
};
|
|
42
55
|
if (is_json_mode()) {
|
|
43
56
|
emit(report);
|
|
@@ -57,6 +70,16 @@ export async function status() {
|
|
|
57
70
|
continue;
|
|
58
71
|
out(` MCP server ${mark(client.mcp)}${client.mcp ? "" : dim(` nemu setup ${client.id === "codex" ? "codex" : "claude"}`)}`);
|
|
59
72
|
out(` Hooks ${client.hooks.length === 0 ? dim("none") : client.hooks_complete ? green("all") : `${client.hooks.join(", ")}`}`);
|
|
73
|
+
if (client.hooks_need_repair)
|
|
74
|
+
out(` ${red("Hooks cannot start on Windows.")} ${dim("Repair with: nemu setup codex --hooks")}`);
|
|
75
|
+
}
|
|
76
|
+
const found = editors.filter((editor) => editor.installed);
|
|
77
|
+
if (found.length > 0) {
|
|
78
|
+
out();
|
|
79
|
+
out(` ${bold("Editors")}`);
|
|
80
|
+
for (const editor of found) {
|
|
81
|
+
out(` ${editor.label.padEnd(15)}${mark(editor.mcp)}${editor.mcp ? "" : dim(` nemu setup ${editor.id}`)}`);
|
|
82
|
+
}
|
|
60
83
|
}
|
|
61
84
|
out();
|
|
62
85
|
return 0;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { remove_hooks } from "../clients/hooks.js";
|
|
2
2
|
import { CLIENTS, client_from_name, client_installed } from "../clients/registry.js";
|
|
3
3
|
import { CliError } from "../errors.js";
|
|
4
|
+
import { EDITORS, editor_from_name, remove_from_editor } from "../clients/editors.js";
|
|
4
5
|
import { dim, out, success } from "../ui.js";
|
|
5
6
|
import { emit, is_json_mode } from "../output.js";
|
|
6
7
|
async function remove_from(spec) {
|
|
@@ -9,18 +10,34 @@ async function remove_from(spec) {
|
|
|
9
10
|
const hooks = await remove_hooks(spec.hooks_path());
|
|
10
11
|
return { client: spec.id, mcp_removed: mcp, hooks_removed: hooks };
|
|
11
12
|
}
|
|
13
|
+
async function remove_editor(editor) {
|
|
14
|
+
return { client: editor.id, label: editor.label, mcp_removed: await remove_from_editor(editor) };
|
|
15
|
+
}
|
|
12
16
|
export async function uninstall(args) {
|
|
13
17
|
const target = args.positional[0] ?? "all";
|
|
14
|
-
const
|
|
15
|
-
|
|
18
|
+
const editor = target === "all" ? null : editor_from_name(target);
|
|
19
|
+
const specs = target === "all" ? Object.values(CLIENTS) : editor !== null ? [] : [client_from_name(target)];
|
|
20
|
+
const editors = target === "all" ? Object.values(EDITORS) : editor !== null ? [editor] : [];
|
|
21
|
+
if (specs.length === 0 && editors.length === 0)
|
|
16
22
|
throw new CliError("Nothing to uninstall.", "invalid_arguments");
|
|
17
23
|
const results = [];
|
|
18
24
|
for (const spec of specs)
|
|
19
25
|
results.push(await remove_from(spec));
|
|
26
|
+
const editor_results = [];
|
|
27
|
+
for (const item of editors)
|
|
28
|
+
editor_results.push(await remove_editor(item));
|
|
20
29
|
if (is_json_mode()) {
|
|
21
|
-
emit({ ok: true, results });
|
|
30
|
+
emit({ ok: true, results, editors: editor_results });
|
|
22
31
|
return 0;
|
|
23
32
|
}
|
|
33
|
+
for (const result of editor_results) {
|
|
34
|
+
if (!result.mcp_removed) {
|
|
35
|
+
if (target !== "all")
|
|
36
|
+
out(dim(` ${result.label}: nothing from Nemu was installed`));
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
success(`${result.label}: removed the MCP server`);
|
|
40
|
+
}
|
|
24
41
|
for (const result of results) {
|
|
25
42
|
const label = CLIENTS[result.client].label;
|
|
26
43
|
if (!result.mcp_removed && !result.hooks_removed) {
|
package/dist/index.js
CHANGED
|
@@ -61,6 +61,8 @@ const HELP = `
|
|
|
61
61
|
${bold("Context for coding agents")}
|
|
62
62
|
setup <claude|codex> [--hooks|--no-hooks] [--yes]
|
|
63
63
|
Connect Claude Code (aliases cc, claude-code) or Codex
|
|
64
|
+
setup <cursor|vscode|gemini|windsurf|zed>
|
|
65
|
+
Add the Nemu MCP server to that editor's config
|
|
64
66
|
claude [-- <claude args>] Set up if needed, then start Claude Code
|
|
65
67
|
codex [-- <codex args>] Set up if needed, then start Codex
|
|
66
68
|
claude load memories [--all] [--yes]
|
|
@@ -74,7 +76,7 @@ const HELP = `
|
|
|
74
76
|
context search <words> Search this project's saved notes
|
|
75
77
|
context projects | export [--out f] List projects or export everything
|
|
76
78
|
status Sign in, device, global install, client setup
|
|
77
|
-
uninstall [
|
|
79
|
+
uninstall [client|all] Remove what setup added
|
|
78
80
|
token [--header] Print a fresh access token
|
|
79
81
|
config get | set reports on|off Error reports sent after a failure
|
|
80
82
|
update [--yes] Check for a new version and install it
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "1.
|
|
1
|
+
export const VERSION = "1.3.1";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nemu-cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "Command line access to Nemu, and portable project memory for Claude Code, Codex and any MCP client.",
|
|
5
5
|
"bin": {
|
|
6
6
|
"nemu": "./dist/index.js"
|
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
"homepage": "https://docs.nemu.cc",
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@nemu-ai/sdk": "^1.1.0",
|
|
43
|
+
"jsonc-parser": "3.3.1",
|
|
43
44
|
"zod": "^4.1.0"
|
|
44
45
|
}
|
|
45
46
|
}
|