nemu-cli 1.3.1 → 1.4.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/CHANGELOG.md +41 -0
- package/README.md +10 -6
- package/dist/clients/editors.js +33 -5
- package/dist/clients/hooks.js +46 -3
- package/dist/clients/jsonc.js +17 -3
- package/dist/clients/registry.js +1 -1
- package/dist/commands/hook.js +61 -32
- package/dist/commands/login.js +4 -2
- package/dist/commands/mcp.js +5 -1
- package/dist/commands/repair.js +23 -0
- package/dist/config.js +1 -0
- package/dist/index.js +13 -2
- package/dist/migrations.js +70 -0
- package/dist/system.js +54 -21
- package/dist/ui.js +25 -5
- package/dist/update.js +5 -0
- package/dist/version.js +1 -1
- package/package.json +3 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,46 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.4.0
|
|
4
|
+
|
|
5
|
+
`nemu setup opencode` adds the Nemu MCP server to OpenCode's global config,
|
|
6
|
+
`~/.config/opencode/opencode.json` (or `opencode.jsonc` when that is the file you have), as a local
|
|
7
|
+
server that runs `nemu mcp --client opencode`. Like the other editors, only the `nemu` entry is
|
|
8
|
+
written, the previous file is kept with a `.nemu-backup` suffix, `nemu uninstall opencode` removes
|
|
9
|
+
it, `nemu status` lists it and `nemu mcp config opencode` prints it.
|
|
10
|
+
|
|
11
|
+
The Stop hook no longer shows up as "Stop hook error" after every few edits. Claude Code shows any
|
|
12
|
+
Stop request that way, so the reminder to save a handoff now arrives quietly after the third edit,
|
|
13
|
+
as context the agent reads and you do not see. Stop asks at most once per session, and only when the
|
|
14
|
+
work is still unsaved. Saving with `memory_write` resets the count. Only files inside the project
|
|
15
|
+
count, so an agent's scratchpad or a temp folder no longer triggers a request, and the reminder no
|
|
16
|
+
longer tells the agent to hide it from you.
|
|
17
|
+
|
|
18
|
+
On Windows, `git`, editors and every other command the CLI starts are now found on `PATH` only.
|
|
19
|
+
Before, the current folder was searched first, so a `git.cmd` inside a cloned repository ran in
|
|
20
|
+
place of the real git.
|
|
21
|
+
|
|
22
|
+
`nemu setup`, `nemu uninstall` and the update repair keep the permissions of
|
|
23
|
+
`~/.claude/settings.json` and `~/.codex/hooks.json`. A file you locked to `0600` used to come back
|
|
24
|
+
readable by every user on the machine. Files the CLI creates from nothing are now `0600`.
|
|
25
|
+
|
|
26
|
+
`nemu login` opens the sign-in page only when it is on the same server the CLI talks to, over https
|
|
27
|
+
(or http on localhost), and on Windows it opens it without going through `cmd`. It now opens the
|
|
28
|
+
page without the code filled in, matching the device page, so you type the code shown in the
|
|
29
|
+
terminal.
|
|
30
|
+
|
|
31
|
+
## 1.3.2
|
|
32
|
+
|
|
33
|
+
After an update, the CLI checks once whether what setup installed still matches what this version
|
|
34
|
+
needs: the Nemu hooks for Claude Code and Codex, and the nemu entry in each editor. Only Nemu's own
|
|
35
|
+
entries that actually differ are rewritten, with every other hook and setting left as it was, and
|
|
36
|
+
nothing is printed when everything already matches. This runs on the first command after an
|
|
37
|
+
update, right after `nemu update` installs a new version, and quietly at the start of a session.
|
|
38
|
+
`nemu repair` runs the same check any time. Each check is a small migration in
|
|
39
|
+
`src/migrations.ts`, so a future release that changes setup adds one there.
|
|
40
|
+
|
|
41
|
+
Commands are started with cross-spawn instead of a shell on Windows, which removes Node's
|
|
42
|
+
DEP0190 deprecation warning and escapes arguments properly.
|
|
43
|
+
|
|
3
44
|
## 1.3.1
|
|
4
45
|
|
|
5
46
|
Fixes "hook failed, exited with code 1" for Codex on Windows. Codex starts hooks through a Windows
|
package/README.md
CHANGED
|
@@ -141,14 +141,17 @@ nemu setup claude # or: nemu setup codex (aliases: cc, claude-code)
|
|
|
141
141
|
|
|
142
142
|
Setup registers a `nemu` MCP server with the client through the client's own command
|
|
143
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
|
|
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
|
|
145
147
|
hooks only after you trust them once with `/hooks`. Pass `--hooks`, `--no-hooks` or `--yes` to skip
|
|
146
148
|
the question.
|
|
147
149
|
|
|
148
|
-
Editors work the same way without hooks: `nemu setup cursor`, `vscode`, `gemini`, `windsurf`
|
|
149
|
-
`
|
|
150
|
-
`mcp.json` through `code --add-mcp`, `~/.gemini/settings.json`,
|
|
151
|
-
`~/.codeium/windsurf/mcp_config.json`, Zed's `settings.json
|
|
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,
|
|
152
155
|
comments included, stays as it was, the previous file is kept with a `.nemu-backup` suffix, and a
|
|
153
156
|
file that cannot be parsed is never touched.
|
|
154
157
|
|
|
@@ -160,12 +163,13 @@ file that cannot be parsed is never touched.
|
|
|
160
163
|
| `nemu claude load sessions [--limit n]` | Open Claude with your recent sessions and let it save what matters |
|
|
161
164
|
| `nemu codex load sessions [--limit n]` | The same for Codex |
|
|
162
165
|
| `nemu mcp` | The stdio MCP bridge clients start; it uses your login and refreshes it |
|
|
163
|
-
| `nemu mcp config <client>` | Config for `cursor`, `gemini`, `vscode`, `windsurf`, `zed`, `claude`, `codex`, `remote` |
|
|
166
|
+
| `nemu mcp config <client>` | Config for `cursor`, `gemini`, `vscode`, `windsurf`, `zed`, `opencode`, `claude`, `codex`, `remote` |
|
|
164
167
|
| `nemu context` | What an agent sees for this folder |
|
|
165
168
|
| `nemu context search <words>` | Search this project's notes |
|
|
166
169
|
| `nemu context projects` / `export --out file` | List projects, or export everything as JSON |
|
|
167
170
|
| `nemu status` | Sign in, this device, global install, and each client's setup |
|
|
168
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 |
|
|
169
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 |
|
|
170
174
|
| `nemu token [--header]` | Print a fresh access token |
|
|
171
175
|
|
package/dist/clients/editors.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
1
2
|
import { access } from "node:fs/promises";
|
|
2
3
|
import { homedir } from "node:os";
|
|
3
4
|
import { basename, join } from "node:path";
|
|
4
5
|
import { CliError } from "../errors.js";
|
|
5
6
|
import { run, which } from "../system.js";
|
|
6
7
|
import { MCP_NAME } from "./registry.js";
|
|
7
|
-
import { read_entry, remove_entry, set_entry } from "./jsonc.js";
|
|
8
|
+
import { read_entry, remove_entry, same_json, set_entry } from "./jsonc.js";
|
|
8
9
|
async function exists(path) {
|
|
9
10
|
try {
|
|
10
11
|
await access(path);
|
|
@@ -37,6 +38,13 @@ function vscode_user_dir() {
|
|
|
37
38
|
return join(home(), "Library", "Application Support", "Code", "User");
|
|
38
39
|
return join(config_home(), "Code", "User");
|
|
39
40
|
}
|
|
41
|
+
function opencode_dir() {
|
|
42
|
+
return join(config_home(), "opencode");
|
|
43
|
+
}
|
|
44
|
+
function opencode_config() {
|
|
45
|
+
const jsonc = join(opencode_dir(), "opencode.jsonc");
|
|
46
|
+
return existsSync(jsonc) ? jsonc : join(opencode_dir(), "opencode.json");
|
|
47
|
+
}
|
|
40
48
|
function zed_dir() {
|
|
41
49
|
return on_windows() ? join(app_data(), "Zed") : join(config_home(), "zed");
|
|
42
50
|
}
|
|
@@ -56,10 +64,13 @@ export function is_nemu_entry(value) {
|
|
|
56
64
|
if (typeof value !== "object" || value === null)
|
|
57
65
|
return false;
|
|
58
66
|
const entry = value;
|
|
59
|
-
|
|
67
|
+
const [command, first] = Array.isArray(entry.command)
|
|
68
|
+
? [entry.command[0], entry.command[1]]
|
|
69
|
+
: [entry.command, Array.isArray(entry.args) ? entry.args[0] : undefined];
|
|
70
|
+
if (typeof command !== "string")
|
|
60
71
|
return false;
|
|
61
|
-
const program = basename(
|
|
62
|
-
return program === "nemu" &&
|
|
72
|
+
const program = basename(command.replaceAll("\\", "/")).replace(/\.(cmd|exe|ps1)$/i, "");
|
|
73
|
+
return program === "nemu" && first === "mcp";
|
|
63
74
|
}
|
|
64
75
|
async function guard_foreign(path, keys) {
|
|
65
76
|
const existing = await read_entry(path, keys);
|
|
@@ -75,6 +86,7 @@ function file_editor(id, label, config_path, keys, detect, value, after_setup) {
|
|
|
75
86
|
config_path,
|
|
76
87
|
keys,
|
|
77
88
|
detect,
|
|
89
|
+
expected: value,
|
|
78
90
|
add: async (nemu) => {
|
|
79
91
|
await guard_foreign(config_path(), keys());
|
|
80
92
|
return set_entry(config_path(), keys(), value(nemu));
|
|
@@ -93,11 +105,12 @@ export const EDITORS = {
|
|
|
93
105
|
config_path: () => join(vscode_user_dir(), "mcp.json"),
|
|
94
106
|
keys: () => ["servers", MCP_NAME],
|
|
95
107
|
detect: () => any_present(["code"], [vscode_user_dir()]),
|
|
108
|
+
expected: (nemu) => ({ type: "stdio", ...bridge(nemu, "vscode") }),
|
|
96
109
|
add: async (nemu) => {
|
|
97
110
|
const entry = { type: "stdio", ...bridge(nemu, "vscode") };
|
|
98
111
|
const path = join(vscode_user_dir(), "mcp.json");
|
|
99
112
|
const before = await guard_foreign(path, ["servers", MCP_NAME]);
|
|
100
|
-
if (
|
|
113
|
+
if (same_json(before, entry))
|
|
101
114
|
return { change: "unchanged", backup: null };
|
|
102
115
|
if ((await which("code")) !== null) {
|
|
103
116
|
const result = await run("code", ["--add-mcp", JSON.stringify({ name: MCP_NAME, ...entry })], {
|
|
@@ -118,6 +131,7 @@ export const EDITORS = {
|
|
|
118
131
|
...(on_mac() ? ["/Applications/Windsurf.app"] : []),
|
|
119
132
|
]), (nemu) => bridge(nemu, "windsurf"), ["Restart Windsurf, or refresh the MCP servers in Cascade."]),
|
|
120
133
|
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."]),
|
|
134
|
+
opencode: file_editor("opencode", "OpenCode", opencode_config, () => ["mcp", MCP_NAME], () => any_present(["opencode"], [opencode_dir(), join(home(), ".opencode")]), (nemu) => ({ type: "local", command: [nemu, "mcp", "--client", "opencode"], enabled: true }), ["Start OpenCode and run opencode mcp list to see the nemu server."]),
|
|
121
135
|
};
|
|
122
136
|
const ALIASES = {
|
|
123
137
|
cursor: "cursor",
|
|
@@ -128,6 +142,8 @@ const ALIASES = {
|
|
|
128
142
|
"gemini-cli": "gemini",
|
|
129
143
|
windsurf: "windsurf",
|
|
130
144
|
zed: "zed",
|
|
145
|
+
opencode: "opencode",
|
|
146
|
+
"open-code": "opencode",
|
|
131
147
|
};
|
|
132
148
|
export function editor_from_name(name) {
|
|
133
149
|
const id = ALIASES[(name ?? "").toLowerCase()];
|
|
@@ -144,3 +160,15 @@ export async function require_editor(spec) {
|
|
|
144
160
|
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
161
|
}
|
|
146
162
|
}
|
|
163
|
+
export async function editor_outdated(spec, nemu) {
|
|
164
|
+
const current = await read_entry(spec.config_path(), spec.keys());
|
|
165
|
+
if (!is_nemu_entry(current))
|
|
166
|
+
return false;
|
|
167
|
+
return !same_json(current, spec.expected(nemu));
|
|
168
|
+
}
|
|
169
|
+
export async function refresh_editor(spec, nemu) {
|
|
170
|
+
if (!(await editor_outdated(spec, nemu)))
|
|
171
|
+
return false;
|
|
172
|
+
const result = await set_entry(spec.config_path(), spec.keys(), spec.expected(nemu));
|
|
173
|
+
return result.change !== "unchanged";
|
|
174
|
+
}
|
package/dist/clients/hooks.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { readFile, writeFile, mkdir, rename, copyFile, access } from "node:fs/promises";
|
|
1
|
+
import { readFile, writeFile, mkdir, rename, copyFile, access, chmod, stat } from "node:fs/promises";
|
|
2
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 = {
|
|
6
6
|
"claude-code": [
|
|
7
7
|
{ event: "SessionStart", hook: "start", matcher: "startup|resume|clear|compact", timeout: 20 },
|
|
8
|
-
{ event: "PostToolUse", hook: "tool", matcher: "Edit|Write|MultiEdit|NotebookEdit", timeout: 5 },
|
|
8
|
+
{ event: "PostToolUse", hook: "tool", matcher: "Edit|Write|MultiEdit|NotebookEdit|mcp__nemu__memory_write", timeout: 5 },
|
|
9
9
|
{ event: "Stop", hook: "stop", timeout: 10 },
|
|
10
10
|
{ event: "PreCompact", hook: "compact", matcher: "manual|auto", timeout: 5 },
|
|
11
11
|
{ event: "SessionEnd", hook: "end", timeout: 3 },
|
|
@@ -80,8 +80,10 @@ async function write_config(path, config) {
|
|
|
80
80
|
const backup = `${path}.nemu-backup`;
|
|
81
81
|
if ((await exists(path)) && !(await exists(backup)))
|
|
82
82
|
await copyFile(path, backup);
|
|
83
|
+
const mode = (await exists(path)) ? (await stat(path)).mode & 0o777 : 0o600;
|
|
83
84
|
const temporary = `${path}.${process.pid}.tmp`;
|
|
84
|
-
await writeFile(temporary, `${JSON.stringify(config, null, 2)}\n`, "utf-8");
|
|
85
|
+
await writeFile(temporary, `${JSON.stringify(config, null, 2)}\n`, { encoding: "utf-8", mode });
|
|
86
|
+
await chmod(temporary, mode).catch(() => undefined);
|
|
85
87
|
await rename(temporary, path);
|
|
86
88
|
}
|
|
87
89
|
function without_own(config) {
|
|
@@ -145,3 +147,44 @@ export async function installed_hooks(path) {
|
|
|
145
147
|
.filter(([, groups]) => groups.some((group) => (group.hooks ?? []).some((handler) => is_own_command(handler.command))))
|
|
146
148
|
.map(([event]) => event);
|
|
147
149
|
}
|
|
150
|
+
function refreshed(config, nemu, client, platform) {
|
|
151
|
+
const specs = HOOK_SPECS[client];
|
|
152
|
+
const hooks = {};
|
|
153
|
+
for (const [event, groups] of Object.entries(config.hooks ?? {})) {
|
|
154
|
+
const spec = specs.find((candidate) => candidate.event === event);
|
|
155
|
+
const kept = groups
|
|
156
|
+
.map((group) => {
|
|
157
|
+
const own = (group.hooks ?? []).filter((handler) => is_own_command(handler.command));
|
|
158
|
+
if (own.length === 0)
|
|
159
|
+
return group;
|
|
160
|
+
if (spec === undefined) {
|
|
161
|
+
return { ...group, hooks: (group.hooks ?? []).filter((handler) => !is_own_command(handler.command)) };
|
|
162
|
+
}
|
|
163
|
+
const handlers = (group.hooks ?? []).map((handler) => is_own_command(handler.command)
|
|
164
|
+
? { ...handler, type: "command", command: hook_command(nemu, spec.hook, client, platform), timeout: spec.timeout }
|
|
165
|
+
: handler);
|
|
166
|
+
const only_own = handlers.every((handler) => is_own_command(handler.command));
|
|
167
|
+
const { matcher: _matcher, ...rest } = group;
|
|
168
|
+
return only_own
|
|
169
|
+
? { ...(spec.matcher !== undefined ? { matcher: spec.matcher } : {}), ...rest, hooks: handlers }
|
|
170
|
+
: { ...group, hooks: handlers };
|
|
171
|
+
})
|
|
172
|
+
.filter((group) => (group.hooks ?? []).length > 0);
|
|
173
|
+
if (kept.length > 0)
|
|
174
|
+
hooks[event] = kept;
|
|
175
|
+
}
|
|
176
|
+
const { hooks: _previous, ...rest } = config;
|
|
177
|
+
return Object.keys(hooks).length > 0 ? { ...rest, hooks } : rest;
|
|
178
|
+
}
|
|
179
|
+
export async function hooks_outdated(path, nemu, client, platform = process.platform) {
|
|
180
|
+
if ((await installed_hooks(path)).length === 0)
|
|
181
|
+
return false;
|
|
182
|
+
const config = await read_config(path);
|
|
183
|
+
return stable(refreshed(config, nemu, client, platform)) !== stable(config);
|
|
184
|
+
}
|
|
185
|
+
export async function refresh_hooks(path, nemu, client, platform = process.platform) {
|
|
186
|
+
if (!(await hooks_outdated(path, nemu, client, platform)))
|
|
187
|
+
return false;
|
|
188
|
+
await write_config(path, refreshed(await read_config(path), nemu, client, platform));
|
|
189
|
+
return true;
|
|
190
|
+
}
|
package/dist/clients/jsonc.js
CHANGED
|
@@ -3,6 +3,20 @@ import { dirname } from "node:path";
|
|
|
3
3
|
import { applyEdits, findNodeAtLocation, getNodeValue, modify, parseTree } from "jsonc-parser";
|
|
4
4
|
import { CliError } from "../errors.js";
|
|
5
5
|
export const BACKUP_SUFFIX = ".nemu-backup";
|
|
6
|
+
export function same_json(left, right) {
|
|
7
|
+
const stable = (value) => {
|
|
8
|
+
if (Array.isArray(value))
|
|
9
|
+
return `[${value.map(stable).join(",")}]`;
|
|
10
|
+
if (value !== null && typeof value === "object") {
|
|
11
|
+
return `{${Object.keys(value)
|
|
12
|
+
.sort()
|
|
13
|
+
.map((key) => `${JSON.stringify(key)}:${stable(value[key])}`)
|
|
14
|
+
.join(",")}}`;
|
|
15
|
+
}
|
|
16
|
+
return JSON.stringify(value) ?? "undefined";
|
|
17
|
+
};
|
|
18
|
+
return stable(left) === stable(right);
|
|
19
|
+
}
|
|
6
20
|
async function read_text(path) {
|
|
7
21
|
try {
|
|
8
22
|
return await readFile(path, "utf-8");
|
|
@@ -33,7 +47,7 @@ function parse_object(path, text) {
|
|
|
33
47
|
}
|
|
34
48
|
async function write_atomic(path, text, original) {
|
|
35
49
|
await mkdir(dirname(path), { recursive: true });
|
|
36
|
-
const mode = original === null ?
|
|
50
|
+
const mode = original === null ? 0o600 : (await stat(path)).mode & 0o777;
|
|
37
51
|
const backup = original === null ? null : `${path}${BACKUP_SUFFIX}`;
|
|
38
52
|
if (backup !== null)
|
|
39
53
|
await copyFile(path, backup);
|
|
@@ -104,12 +118,12 @@ export async function set_entry(path, keys, value) {
|
|
|
104
118
|
const text = original === null || original.trim().length === 0 ? "{}" : original;
|
|
105
119
|
const tree = parse_object(path, text);
|
|
106
120
|
const existing = findNodeAtLocation(tree, keys);
|
|
107
|
-
if (existing !== undefined &&
|
|
121
|
+
if (existing !== undefined && same_json(getNodeValue(existing), value)) {
|
|
108
122
|
return { change: "unchanged", backup: null };
|
|
109
123
|
}
|
|
110
124
|
const next = insert_entry(text, keys, value);
|
|
111
125
|
const written = findNodeAtLocation(parse_object(path, next), keys);
|
|
112
|
-
if (written === undefined ||
|
|
126
|
+
if (written === undefined || !same_json(getNodeValue(written), value)) {
|
|
113
127
|
throw new CliError(`${path} could not be updated safely, so nothing was changed.`, "config_unreadable");
|
|
114
128
|
}
|
|
115
129
|
const backup = await write_atomic(path, next.endsWith("\n") ? next : `${next}\n`, original);
|
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), codex, cursor, vscode, gemini, windsurf or
|
|
68
|
+
throw new CliError("Pick a client: claude (aliases cc, claude-code), codex, cursor, vscode, gemini, windsurf, zed or opencode. Others: nemu mcp config <client>", "invalid_client");
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
export async function client_installed(spec) {
|
package/dist/commands/hook.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { join } from "node:path";
|
|
1
|
+
import { isAbsolute, join, relative, resolve } from "node:path";
|
|
2
2
|
import { mkdir, readFile, readdir, rm, stat, appendFile } from "node:fs/promises";
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
import { flag } from "../args.js";
|
|
@@ -9,6 +9,7 @@ import { staleness } from "../context/stale.js";
|
|
|
9
9
|
import { current_project } from "../context/project.js";
|
|
10
10
|
import { snapshot } from "../context/snapshot.js";
|
|
11
11
|
import { repository } from "../git.js";
|
|
12
|
+
import { migrate_after_update } from "../migrations.js";
|
|
12
13
|
const MAX_CONTEXT = { "claude-code": 9000, codex: 7500 };
|
|
13
14
|
const CHECKPOINT_EDITS = 3;
|
|
14
15
|
const ASK_INTERVAL_MS = 10 * 60_000;
|
|
@@ -34,6 +35,8 @@ const state_schema = z.object({
|
|
|
34
35
|
edits_since_checkpoint: z.number(),
|
|
35
36
|
last_asked_at: z.number().nullable(),
|
|
36
37
|
compacted: z.boolean(),
|
|
38
|
+
nudged: z.boolean().default(false),
|
|
39
|
+
stop_asked: z.boolean().default(false),
|
|
37
40
|
updated_at: z.number(),
|
|
38
41
|
});
|
|
39
42
|
const pending_schema = z.record(z.string(), z.object({ files: z.array(z.string()), ended_at: z.number(), client: z.string() }));
|
|
@@ -131,6 +134,8 @@ async function on_start(client, input) {
|
|
|
131
134
|
edits_since_checkpoint: 0,
|
|
132
135
|
last_asked_at: null,
|
|
133
136
|
compacted: false,
|
|
137
|
+
nudged: false,
|
|
138
|
+
stop_asked: false,
|
|
134
139
|
updated_at: Date.now(),
|
|
135
140
|
};
|
|
136
141
|
await write_private(state_path(client, session), JSON.stringify({ ...state, branch: info.branch, updated_at: Date.now() }));
|
|
@@ -203,26 +208,65 @@ function paths_from_tool(input) {
|
|
|
203
208
|
return [...found];
|
|
204
209
|
}
|
|
205
210
|
const EDITING_TOOL = /edit|write|patch|notebook|create|delete|move|rename/i;
|
|
211
|
+
const SAVING_TOOL = /memory_write$/;
|
|
212
|
+
export function project_file(root, cwd, file) {
|
|
213
|
+
const absolute = isAbsolute(file) ? file : resolve(cwd, file);
|
|
214
|
+
const inside = relative(root, absolute);
|
|
215
|
+
if (inside.length === 0 || inside.startsWith("..") || isAbsolute(inside))
|
|
216
|
+
return null;
|
|
217
|
+
return inside.replaceAll("\\", "/");
|
|
218
|
+
}
|
|
219
|
+
function emit_tool_context(text) {
|
|
220
|
+
process.stdout.write(`${JSON.stringify({
|
|
221
|
+
hookSpecificOutput: { hookEventName: "PostToolUse", additionalContext: text },
|
|
222
|
+
})}\n`);
|
|
223
|
+
}
|
|
224
|
+
function save_request(state) {
|
|
225
|
+
const recent = state.since_checkpoint.slice(-10);
|
|
226
|
+
return [
|
|
227
|
+
`Nemu Context: when this task is done, save a handoff named '${handoff_name(state.branch)}' with memory_write (what changed, what is unfinished, the next step), and any durable fact you learned under its own '<tag>/<name>'.`,
|
|
228
|
+
`Files changed since the last save: ${recent.join(", ")}${state.since_checkpoint.length > recent.length ? ", ..." : ""}.`,
|
|
229
|
+
`Never save secrets. If nothing is worth saving, skip it.`,
|
|
230
|
+
].join("\n");
|
|
231
|
+
}
|
|
206
232
|
async function on_tool(client, input) {
|
|
207
|
-
if (input.tool_name !== undefined && !EDITING_TOOL.test(input.tool_name))
|
|
208
|
-
return;
|
|
209
233
|
const session = input.session_id ?? "unknown";
|
|
210
234
|
const path = state_path(client, session);
|
|
235
|
+
if (input.tool_name !== undefined && SAVING_TOOL.test(input.tool_name)) {
|
|
236
|
+
const state = await read_json_file(path, state_schema);
|
|
237
|
+
if (state === null)
|
|
238
|
+
return;
|
|
239
|
+
await write_private(path, JSON.stringify({
|
|
240
|
+
...state,
|
|
241
|
+
edits_since_checkpoint: 0,
|
|
242
|
+
since_checkpoint: [],
|
|
243
|
+
compacted: false,
|
|
244
|
+
nudged: false,
|
|
245
|
+
updated_at: Date.now(),
|
|
246
|
+
}));
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
if (input.tool_name !== undefined && !EDITING_TOOL.test(input.tool_name))
|
|
250
|
+
return;
|
|
211
251
|
const state = await read_json_file(path, state_schema);
|
|
212
252
|
if (state === null)
|
|
213
253
|
return;
|
|
214
|
-
const files = paths_from_tool(input)
|
|
254
|
+
const files = paths_from_tool(input)
|
|
255
|
+
.map((file) => project_file(state.root, input.cwd ?? state.cwd, file))
|
|
256
|
+
.filter((file) => file !== null);
|
|
215
257
|
if (files.length === 0)
|
|
216
258
|
return;
|
|
217
|
-
const
|
|
218
|
-
const recent = [...new Set([...state.since_checkpoint, ...files])].slice(-MAX_FILES);
|
|
219
|
-
await write_private(path, JSON.stringify({
|
|
259
|
+
const next = {
|
|
220
260
|
...state,
|
|
221
|
-
files:
|
|
222
|
-
since_checkpoint:
|
|
261
|
+
files: [...new Set([...state.files, ...files])].slice(-MAX_FILES),
|
|
262
|
+
since_checkpoint: [...new Set([...state.since_checkpoint, ...files])].slice(-MAX_FILES),
|
|
223
263
|
edits_since_checkpoint: state.edits_since_checkpoint + files.length,
|
|
224
264
|
updated_at: Date.now(),
|
|
225
|
-
}
|
|
265
|
+
};
|
|
266
|
+
const nudge = client === "claude-code" && !next.nudged && next.edits_since_checkpoint >= CHECKPOINT_EDITS;
|
|
267
|
+
await write_private(path, JSON.stringify(nudge ? { ...next, nudged: true } : next));
|
|
268
|
+
if (nudge)
|
|
269
|
+
emit_tool_context(save_request(next));
|
|
226
270
|
}
|
|
227
271
|
async function on_stop(client, input) {
|
|
228
272
|
const session = input.session_id ?? "unknown";
|
|
@@ -230,32 +274,16 @@ async function on_stop(client, input) {
|
|
|
230
274
|
const state = await read_json_file(path, state_schema);
|
|
231
275
|
if (state === null)
|
|
232
276
|
return;
|
|
233
|
-
if (input.stop_hook_active === true)
|
|
277
|
+
if (input.stop_hook_active === true || state.stop_asked)
|
|
234
278
|
return;
|
|
235
|
-
const
|
|
236
|
-
|
|
279
|
+
const unsaved = state.since_checkpoint.length > 0;
|
|
280
|
+
const due = unsaved &&
|
|
281
|
+
(state.edits_since_checkpoint >= CHECKPOINT_EDITS || (state.compacted && state.edits_since_checkpoint > 0));
|
|
237
282
|
const recently = state.last_asked_at !== null && Date.now() - state.last_asked_at < ASK_INTERVAL_MS;
|
|
238
283
|
if (!due || recently)
|
|
239
284
|
return;
|
|
240
|
-
await write_private(path, JSON.stringify({
|
|
241
|
-
|
|
242
|
-
edits_since_checkpoint: 0,
|
|
243
|
-
since_checkpoint: [],
|
|
244
|
-
compacted: false,
|
|
245
|
-
last_asked_at: Date.now(),
|
|
246
|
-
updated_at: Date.now(),
|
|
247
|
-
}));
|
|
248
|
-
const recent = state.files.slice(-10);
|
|
249
|
-
process.stdout.write(`${JSON.stringify({
|
|
250
|
-
decision: "block",
|
|
251
|
-
reason: [
|
|
252
|
-
`Before you stop, save progress to Nemu Context with the memory_write tool:`,
|
|
253
|
-
`1. A handoff named '${handoff_name(state.branch)}': what changed, what is unfinished, and the next step.`,
|
|
254
|
-
`2. Any durable fact you learned (a decision and why, a gotcha, a convention) under its own '<tag>/<name>'.`,
|
|
255
|
-
`Files changed so far: ${recent.join(", ")}${state.files.length > recent.length ? ", ..." : ""}.`,
|
|
256
|
-
`Never save secrets. If nothing is worth saving, just stop. Do not mention this reminder to the user.`,
|
|
257
|
-
].join("\n"),
|
|
258
|
-
})}\n`);
|
|
285
|
+
await write_private(path, JSON.stringify({ ...state, stop_asked: true, last_asked_at: Date.now(), updated_at: Date.now() }));
|
|
286
|
+
process.stdout.write(`${JSON.stringify({ decision: "block", reason: save_request(state) })}\n`);
|
|
259
287
|
}
|
|
260
288
|
async function on_compact(client, input) {
|
|
261
289
|
const session = input.session_id ?? "unknown";
|
|
@@ -286,6 +314,7 @@ export async function hook(args) {
|
|
|
286
314
|
switch (event) {
|
|
287
315
|
case "start":
|
|
288
316
|
await on_start(client, input);
|
|
317
|
+
await migrate_after_update("session-start");
|
|
289
318
|
break;
|
|
290
319
|
case "tool":
|
|
291
320
|
await on_tool(client, input);
|
package/dist/commands/login.js
CHANGED
|
@@ -44,8 +44,10 @@ export async function login(args) {
|
|
|
44
44
|
out(` Code ${bold(authorization.user_code)}`);
|
|
45
45
|
out();
|
|
46
46
|
if (!no_browser) {
|
|
47
|
-
open_browser(authorization.
|
|
48
|
-
out(dim(
|
|
47
|
+
const is_opened = open_browser(authorization.verification_uri, api_url());
|
|
48
|
+
out(dim(is_opened
|
|
49
|
+
? " Opening your browser. Use the link above if it does not."
|
|
50
|
+
: " The sign-in link is not on your Nemu server, so it was not opened."));
|
|
49
51
|
out();
|
|
50
52
|
}
|
|
51
53
|
}
|
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", "vscode", "windsurf", "mcp"];
|
|
11
|
+
const CLIENTS = ["claude-code", "codex", "cursor", "zed", "gemini", "vscode", "windsurf", "opencode", "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(),
|
|
@@ -191,6 +191,10 @@ const SNIPPETS = {
|
|
|
191
191
|
where: "Zed settings.json",
|
|
192
192
|
text: JSON.stringify({ context_servers: { nemu: { command: "nemu", args: ["mcp", "--client", "zed"] } } }, null, 2),
|
|
193
193
|
},
|
|
194
|
+
opencode: {
|
|
195
|
+
where: "~/.config/opencode/opencode.json",
|
|
196
|
+
text: JSON.stringify({ mcp: { nemu: { type: "local", command: ["nemu", "mcp", "--client", "opencode"], enabled: true } } }, null, 2),
|
|
197
|
+
},
|
|
194
198
|
remote: {
|
|
195
199
|
where: "Any client that supports remote MCP over HTTP (create a Context key in the dashboard first)",
|
|
196
200
|
text: JSON.stringify({ url: "https://app.nemu.cc/api/mcp", headers: { Authorization: "Bearer <your Context key>" } }, null, 2),
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { update_settings } from "../config.js";
|
|
2
|
+
import { run_migrations } from "../migrations.js";
|
|
3
|
+
import { emit, is_json_mode } from "../output.js";
|
|
4
|
+
import { dim, fail, out, success } from "../ui.js";
|
|
5
|
+
import { VERSION } from "../version.js";
|
|
6
|
+
export async function repair() {
|
|
7
|
+
const report = await run_migrations();
|
|
8
|
+
if (report.failed.length === 0)
|
|
9
|
+
await update_settings({ setup_version: VERSION });
|
|
10
|
+
if (is_json_mode()) {
|
|
11
|
+
emit({ ok: report.failed.length === 0, version: VERSION, ...report });
|
|
12
|
+
return report.failed.length === 0 ? 0 : 1;
|
|
13
|
+
}
|
|
14
|
+
if (report.applied.length === 0 && report.failed.length === 0) {
|
|
15
|
+
out(dim(` Your setup is up to date for nemu ${VERSION}.`));
|
|
16
|
+
return 0;
|
|
17
|
+
}
|
|
18
|
+
for (const line of report.applied)
|
|
19
|
+
success(line);
|
|
20
|
+
for (const line of report.failed)
|
|
21
|
+
fail(`${line} did not finish. Details are in ~/.nemu/hooks.log`);
|
|
22
|
+
return report.failed.length === 0 ? 0 : 1;
|
|
23
|
+
}
|
package/dist/config.js
CHANGED
|
@@ -24,6 +24,7 @@ const settings_schema = z.object({
|
|
|
24
24
|
update_latest: z.string().max(64).optional(),
|
|
25
25
|
update_declined_version: z.string().max(64).optional(),
|
|
26
26
|
update_declined_at: z.number().optional(),
|
|
27
|
+
setup_version: z.string().max(64).optional(),
|
|
27
28
|
});
|
|
28
29
|
export function api_url() {
|
|
29
30
|
return (process.env.NEMU_API_URL ?? DEFAULT_API_URL).replace(/\/+$/, "");
|
package/dist/index.js
CHANGED
|
@@ -18,6 +18,8 @@ import { config_command } from "./commands/settings.js";
|
|
|
18
18
|
import { client_command } from "./commands/client.js";
|
|
19
19
|
import { send_report } from "./report.js";
|
|
20
20
|
import { maybe_offer_update, update_command } from "./update.js";
|
|
21
|
+
import { migrate_after_update } from "./migrations.js";
|
|
22
|
+
import { repair } from "./commands/repair.js";
|
|
21
23
|
import { CliError } from "./errors.js";
|
|
22
24
|
import { VERSION } from "./version.js";
|
|
23
25
|
import { bold, dim, fail, out } from "./ui.js";
|
|
@@ -54,6 +56,7 @@ const COMMANDS = {
|
|
|
54
56
|
context,
|
|
55
57
|
config: config_command,
|
|
56
58
|
update: update_command,
|
|
59
|
+
repair,
|
|
57
60
|
};
|
|
58
61
|
const HELP = `
|
|
59
62
|
${bold("nemu")} ${dim(VERSION)}
|
|
@@ -61,7 +64,7 @@ const HELP = `
|
|
|
61
64
|
${bold("Context for coding agents")}
|
|
62
65
|
setup <claude|codex> [--hooks|--no-hooks] [--yes]
|
|
63
66
|
Connect Claude Code (aliases cc, claude-code) or Codex
|
|
64
|
-
setup <cursor|vscode|gemini|windsurf|zed>
|
|
67
|
+
setup <cursor|vscode|gemini|windsurf|zed|opencode>
|
|
65
68
|
Add the Nemu MCP server to that editor's config
|
|
66
69
|
claude [-- <claude args>] Set up if needed, then start Claude Code
|
|
67
70
|
codex [-- <codex args>] Set up if needed, then start Codex
|
|
@@ -71,7 +74,7 @@ const HELP = `
|
|
|
71
74
|
codex load sessions [--limit n] The same for Codex
|
|
72
75
|
mcp Run the MCP bridge (what clients start)
|
|
73
76
|
mcp config <client> Print config for cursor, gemini, vscode, windsurf,
|
|
74
|
-
zed, claude, codex or remote
|
|
77
|
+
zed, opencode, claude, codex or remote
|
|
75
78
|
context [load] Show what an agent sees for this folder
|
|
76
79
|
context search <words> Search this project's saved notes
|
|
77
80
|
context projects | export [--out f] List projects or export everything
|
|
@@ -80,6 +83,7 @@ const HELP = `
|
|
|
80
83
|
token [--header] Print a fresh access token
|
|
81
84
|
config get | set reports on|off Error reports sent after a failure
|
|
82
85
|
update [--yes] Check for a new version and install it
|
|
86
|
+
repair Bring hooks and editor entries up to date
|
|
83
87
|
|
|
84
88
|
${bold("Account")}
|
|
85
89
|
login [--force] [--no-browser] Sign in with the device flow
|
|
@@ -185,6 +189,13 @@ async function main() {
|
|
|
185
189
|
return 0;
|
|
186
190
|
}
|
|
187
191
|
await maybe_offer_update(command);
|
|
192
|
+
const migrated = await migrate_after_update(command);
|
|
193
|
+
if (migrated !== null && migrated.applied.length > 0 && !is_json_mode()) {
|
|
194
|
+
out(dim(` Updated your setup for nemu ${VERSION}:`));
|
|
195
|
+
for (const line of migrated.applied)
|
|
196
|
+
out(dim(` ${line}`));
|
|
197
|
+
out();
|
|
198
|
+
}
|
|
188
199
|
return await handler(args);
|
|
189
200
|
}
|
|
190
201
|
async function report_failure(error) {
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { CLIENTS } from "./clients/registry.js";
|
|
2
|
+
import { EDITORS, editor_outdated, refresh_editor } from "./clients/editors.js";
|
|
3
|
+
import { hooks_outdated, refresh_hooks } from "./clients/hooks.js";
|
|
4
|
+
import { read_settings, update_settings, config_dir } from "./config.js";
|
|
5
|
+
import { resolve_nemu_binary } from "./commands/setup.js";
|
|
6
|
+
import { VERSION } from "./version.js";
|
|
7
|
+
import { appendFile, mkdir } from "node:fs/promises";
|
|
8
|
+
import { join } from "node:path";
|
|
9
|
+
const QUIET_COMMANDS = new Set(["hook", "mcp", "token", "uninstall", "repair", "update"]);
|
|
10
|
+
export const MIGRATIONS = [
|
|
11
|
+
...Object.values(CLIENTS).map((spec) => ({
|
|
12
|
+
id: `hooks:${spec.id}`,
|
|
13
|
+
label: `${spec.label}: updated the Nemu hooks`,
|
|
14
|
+
needed: (nemu) => hooks_outdated(spec.hooks_path(), nemu, spec.id),
|
|
15
|
+
apply: (nemu) => refresh_hooks(spec.hooks_path(), nemu, spec.id),
|
|
16
|
+
})),
|
|
17
|
+
...Object.values(EDITORS).map((editor) => ({
|
|
18
|
+
id: `mcp:${editor.id}`,
|
|
19
|
+
label: `${editor.label}: updated the nemu server entry`,
|
|
20
|
+
needed: (nemu) => editor_outdated(editor, nemu),
|
|
21
|
+
apply: (nemu) => refresh_editor(editor, nemu),
|
|
22
|
+
})),
|
|
23
|
+
];
|
|
24
|
+
async function log_failure(id, error) {
|
|
25
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
26
|
+
await mkdir(config_dir(), { recursive: true }).catch(() => undefined);
|
|
27
|
+
await appendFile(join(config_dir(), "hooks.log"), `${new Date().toISOString()} migration ${id} ${message.replace(/\s+/g, " ").slice(0, 300)}\n`).catch(() => undefined);
|
|
28
|
+
}
|
|
29
|
+
export async function run_migrations(migrations = MIGRATIONS) {
|
|
30
|
+
const report = { applied: [], failed: [] };
|
|
31
|
+
const nemu = await resolve_nemu_binary(false).catch(() => null);
|
|
32
|
+
if (nemu === null)
|
|
33
|
+
return report;
|
|
34
|
+
for (const migration of migrations) {
|
|
35
|
+
try {
|
|
36
|
+
if (!(await migration.needed(nemu)))
|
|
37
|
+
continue;
|
|
38
|
+
if (await migration.apply(nemu))
|
|
39
|
+
report.applied.push(migration.label);
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
report.failed.push(migration.label);
|
|
43
|
+
await log_failure(migration.id, error);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return report;
|
|
47
|
+
}
|
|
48
|
+
export function migrations_due(command, setup_version) {
|
|
49
|
+
return !QUIET_COMMANDS.has(command) && setup_version !== VERSION;
|
|
50
|
+
}
|
|
51
|
+
export async function migrate_after_update(command) {
|
|
52
|
+
try {
|
|
53
|
+
const settings = await read_settings();
|
|
54
|
+
if (!migrations_due(command, settings.setup_version))
|
|
55
|
+
return null;
|
|
56
|
+
if (process.env.NEMU_BIN === undefined && !is_global_run())
|
|
57
|
+
return null;
|
|
58
|
+
const report = await run_migrations();
|
|
59
|
+
if (report.failed.length === 0)
|
|
60
|
+
await update_settings({ setup_version: VERSION });
|
|
61
|
+
return report;
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function is_global_run() {
|
|
68
|
+
const script = (process.argv[1] ?? "").replaceAll("\\", "/");
|
|
69
|
+
return !script.includes("/_npx/") && !script.includes("/.bun/install/cache/");
|
|
70
|
+
}
|
package/dist/system.js
CHANGED
|
@@ -1,39 +1,72 @@
|
|
|
1
|
-
import
|
|
1
|
+
import spawn from "cross-spawn";
|
|
2
2
|
import { access, constants } from "node:fs/promises";
|
|
3
|
-
import { delimiter, join } from "node:path";
|
|
4
|
-
|
|
3
|
+
import { delimiter, isAbsolute, join } from "node:path";
|
|
4
|
+
const MAX_OUTPUT = 4 * 1024 * 1024;
|
|
5
|
+
const NOT_FOUND = { code: 127, stdout: "", stderr: "" };
|
|
6
|
+
async function resolve_command(command) {
|
|
7
|
+
if (process.platform !== "win32")
|
|
8
|
+
return command;
|
|
9
|
+
if (/[\\/]/.test(command))
|
|
10
|
+
return isAbsolute(command) ? command : null;
|
|
11
|
+
return which(command);
|
|
12
|
+
}
|
|
13
|
+
export async function run(command, args, options = {}) {
|
|
14
|
+
const resolved = await resolve_command(command);
|
|
15
|
+
if (resolved === null)
|
|
16
|
+
return NOT_FOUND;
|
|
5
17
|
return new Promise((resolve) => {
|
|
6
|
-
|
|
18
|
+
const stdout = [];
|
|
19
|
+
const stderr = [];
|
|
20
|
+
let size = 0;
|
|
21
|
+
let settled = false;
|
|
22
|
+
const finish = (code) => {
|
|
23
|
+
if (settled)
|
|
24
|
+
return;
|
|
25
|
+
settled = true;
|
|
26
|
+
clearTimeout(timer);
|
|
27
|
+
resolve({
|
|
28
|
+
code,
|
|
29
|
+
stdout: Buffer.concat(stdout).toString("utf-8"),
|
|
30
|
+
stderr: Buffer.concat(stderr).toString("utf-8"),
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
const collect = (target) => (chunk) => {
|
|
34
|
+
if (size >= MAX_OUTPUT)
|
|
35
|
+
return;
|
|
36
|
+
size += chunk.length;
|
|
37
|
+
target.push(chunk);
|
|
38
|
+
};
|
|
39
|
+
const child = spawn(resolved, args, {
|
|
7
40
|
env: options.env ?? process.env,
|
|
8
41
|
cwd: options.cwd,
|
|
9
|
-
timeout: options.timeout_ms ?? 30_000,
|
|
10
|
-
maxBuffer: 4 * 1024 * 1024,
|
|
11
42
|
windowsHide: true,
|
|
12
|
-
|
|
13
|
-
}, (error, stdout, stderr) => {
|
|
14
|
-
const code = error === null
|
|
15
|
-
? 0
|
|
16
|
-
: typeof error.code === "number"
|
|
17
|
-
? (error.code)
|
|
18
|
-
: 127;
|
|
19
|
-
resolve({ code, stdout: stdout.toString(), stderr: stderr.toString() });
|
|
43
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
20
44
|
});
|
|
45
|
+
const timer = setTimeout(() => {
|
|
46
|
+
child.kill();
|
|
47
|
+
finish(127);
|
|
48
|
+
}, options.timeout_ms ?? 30_000);
|
|
49
|
+
child.stdout?.on("data", collect(stdout));
|
|
50
|
+
child.stderr?.on("data", collect(stderr));
|
|
51
|
+
child.on("error", () => finish(127));
|
|
52
|
+
child.on("close", (code) => finish(code ?? 127));
|
|
21
53
|
});
|
|
22
54
|
}
|
|
23
|
-
export function launch(command, args) {
|
|
55
|
+
export async function launch(command, args) {
|
|
56
|
+
const resolved = await resolve_command(command);
|
|
57
|
+
if (resolved === null)
|
|
58
|
+
return 127;
|
|
24
59
|
return new Promise((resolve) => {
|
|
25
|
-
const child = spawn(
|
|
26
|
-
stdio: "inherit",
|
|
27
|
-
shell: process.platform === "win32",
|
|
28
|
-
});
|
|
60
|
+
const child = spawn(resolved, args, { stdio: "inherit" });
|
|
29
61
|
child.on("error", () => resolve(127));
|
|
30
62
|
child.on("exit", (code, signal) => resolve(code ?? (signal !== null ? 1 : 0)));
|
|
31
63
|
});
|
|
32
64
|
}
|
|
33
65
|
export async function which(name) {
|
|
34
66
|
const extensions = process.platform === "win32" ? (process.env.PATHEXT ?? ".EXE;.CMD;.BAT").split(";") : [""];
|
|
35
|
-
for (const
|
|
36
|
-
|
|
67
|
+
for (const entry of (process.env.PATH ?? "").split(delimiter)) {
|
|
68
|
+
const directory = entry.replace(/^"(.*)"$/, "$1");
|
|
69
|
+
if (directory.length === 0 || !isAbsolute(directory))
|
|
37
70
|
continue;
|
|
38
71
|
for (const extension of extensions) {
|
|
39
72
|
const candidate = join(directory, `${name}${extension.toLowerCase()}`);
|
package/dist/ui.js
CHANGED
|
@@ -37,20 +37,40 @@ export function spinner(label) {
|
|
|
37
37
|
},
|
|
38
38
|
};
|
|
39
39
|
}
|
|
40
|
-
|
|
40
|
+
const LOOPBACK_HOSTS = new Set(["localhost", "127.0.0.1", "[::1]"]);
|
|
41
|
+
export function safe_browser_url(url, expected_origin) {
|
|
42
|
+
try {
|
|
43
|
+
const parsed = new URL(url);
|
|
44
|
+
const is_secure = parsed.protocol === "https:" ||
|
|
45
|
+
(parsed.protocol === "http:" && LOOPBACK_HOSTS.has(parsed.hostname));
|
|
46
|
+
if (!is_secure)
|
|
47
|
+
return null;
|
|
48
|
+
if (parsed.origin !== new URL(expected_origin).origin)
|
|
49
|
+
return null;
|
|
50
|
+
return parsed.href;
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
export function open_browser(url, expected_origin) {
|
|
57
|
+
const target = safe_browser_url(url, expected_origin);
|
|
58
|
+
if (target === null)
|
|
59
|
+
return false;
|
|
41
60
|
const command = process.platform === "darwin"
|
|
42
61
|
? "open"
|
|
43
62
|
: process.platform === "win32"
|
|
44
|
-
? "
|
|
63
|
+
? "rundll32"
|
|
45
64
|
: "xdg-open";
|
|
46
|
-
const args = process.platform === "win32" ? ["
|
|
65
|
+
const args = process.platform === "win32" ? ["url.dll,FileProtocolHandler", target] : [target];
|
|
47
66
|
try {
|
|
48
|
-
const child = spawn(command, args, { stdio: "ignore", detached: true });
|
|
67
|
+
const child = spawn(command, args, { stdio: "ignore", detached: true, windowsHide: true });
|
|
49
68
|
child.on("error", () => { });
|
|
50
69
|
child.unref();
|
|
70
|
+
return true;
|
|
51
71
|
}
|
|
52
72
|
catch {
|
|
53
|
-
return;
|
|
73
|
+
return false;
|
|
54
74
|
}
|
|
55
75
|
}
|
|
56
76
|
export function is_interactive() {
|
package/dist/update.js
CHANGED
|
@@ -6,6 +6,7 @@ import { emit, is_json_mode } from "./output.js";
|
|
|
6
6
|
import { bool_flag } from "./args.js";
|
|
7
7
|
import { VERSION } from "./version.js";
|
|
8
8
|
const PACKAGE = "nemu-cli";
|
|
9
|
+
const PACKAGE_BINARY = "nemu";
|
|
9
10
|
const CHECK_INTERVAL_MS = 24 * 60 * 60 * 1000;
|
|
10
11
|
const FETCH_TIMEOUT_MS = 1500;
|
|
11
12
|
const QUIET_COMMANDS = new Set(["hook", "mcp", "token", "update"]);
|
|
@@ -83,6 +84,10 @@ async function install(version) {
|
|
|
83
84
|
return false;
|
|
84
85
|
}
|
|
85
86
|
success(`Updated to ${version}.`);
|
|
87
|
+
const repaired = await run(PACKAGE_BINARY, ["repair"], { timeout_ms: 60_000 });
|
|
88
|
+
const lines = repaired.stdout.trimEnd();
|
|
89
|
+
if (repaired.code === 0 && lines.length > 0 && !lines.includes("up to date"))
|
|
90
|
+
out(lines);
|
|
86
91
|
return true;
|
|
87
92
|
}
|
|
88
93
|
async function offer(latest, now) {
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "1.
|
|
1
|
+
export const VERSION = "1.4.0";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nemu-cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
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"
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
"author": "hiraeeth",
|
|
32
32
|
"license": "MIT",
|
|
33
33
|
"devDependencies": {
|
|
34
|
+
"@types/cross-spawn": "6.0.6",
|
|
34
35
|
"@types/node": "^20.0.0",
|
|
35
36
|
"typescript": "^5"
|
|
36
37
|
},
|
|
@@ -40,6 +41,7 @@
|
|
|
40
41
|
"homepage": "https://docs.nemu.cc",
|
|
41
42
|
"dependencies": {
|
|
42
43
|
"@nemu-ai/sdk": "^1.1.0",
|
|
44
|
+
"cross-spawn": "7.0.6",
|
|
43
45
|
"jsonc-parser": "3.3.1",
|
|
44
46
|
"zod": "^4.1.0"
|
|
45
47
|
}
|