nemu-cli 1.0.0 → 1.2.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 +27 -0
- package/README.md +55 -1
- package/dist/auth/token.js +115 -0
- package/dist/clients/hooks.js +131 -0
- package/dist/clients/paths.js +17 -0
- package/dist/clients/registry.js +74 -0
- package/dist/commands/client.js +19 -0
- package/dist/commands/context.js +65 -0
- package/dist/commands/hook.js +312 -0
- package/dist/commands/load.js +328 -0
- package/dist/commands/login.js +14 -1
- package/dist/commands/mcp.js +210 -0
- package/dist/commands/settings.js +23 -0
- package/dist/commands/setup.js +104 -0
- package/dist/commands/status.js +63 -0
- package/dist/commands/token.js +16 -0
- package/dist/commands/uninstall.js +34 -0
- package/dist/config.js +52 -20
- package/dist/context/api.js +99 -0
- package/dist/context/project.js +58 -0
- package/dist/context/redact.js +32 -0
- package/dist/context/snapshot.js +85 -0
- package/dist/context/stale.js +70 -0
- package/dist/device.js +43 -0
- package/dist/errors.js +24 -0
- package/dist/git.js +39 -0
- package/dist/http.js +61 -0
- package/dist/index.js +72 -9
- package/dist/report.js +79 -0
- package/dist/session.js +11 -6
- package/dist/system.js +50 -0
- package/dist/ui.js +20 -0
- package/dist/update.js +141 -0
- package/dist/version.js +1 -0
- package/package.json +9 -4
package/dist/system.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { execFile, spawn } from "node:child_process";
|
|
2
|
+
import { access, constants } from "node:fs/promises";
|
|
3
|
+
import { delimiter, join } from "node:path";
|
|
4
|
+
export function run(command, args, options = {}) {
|
|
5
|
+
return new Promise((resolve) => {
|
|
6
|
+
execFile(command, args, {
|
|
7
|
+
env: options.env ?? process.env,
|
|
8
|
+
cwd: options.cwd,
|
|
9
|
+
timeout: options.timeout_ms ?? 30_000,
|
|
10
|
+
maxBuffer: 4 * 1024 * 1024,
|
|
11
|
+
windowsHide: true,
|
|
12
|
+
shell: process.platform === "win32",
|
|
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() });
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
export function launch(command, args) {
|
|
24
|
+
return new Promise((resolve) => {
|
|
25
|
+
const child = spawn(command, args, {
|
|
26
|
+
stdio: "inherit",
|
|
27
|
+
shell: process.platform === "win32",
|
|
28
|
+
});
|
|
29
|
+
child.on("error", () => resolve(127));
|
|
30
|
+
child.on("exit", (code, signal) => resolve(code ?? (signal !== null ? 1 : 0)));
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
export async function which(name) {
|
|
34
|
+
const extensions = process.platform === "win32" ? (process.env.PATHEXT ?? ".EXE;.CMD;.BAT").split(";") : [""];
|
|
35
|
+
for (const directory of (process.env.PATH ?? "").split(delimiter)) {
|
|
36
|
+
if (directory.length === 0)
|
|
37
|
+
continue;
|
|
38
|
+
for (const extension of extensions) {
|
|
39
|
+
const candidate = join(directory, `${name}${extension.toLowerCase()}`);
|
|
40
|
+
try {
|
|
41
|
+
await access(candidate, constants.X_OK);
|
|
42
|
+
return candidate;
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return null;
|
|
50
|
+
}
|
package/dist/ui.js
CHANGED
|
@@ -53,3 +53,23 @@ export function open_browser(url) {
|
|
|
53
53
|
return;
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
|
+
export function is_interactive() {
|
|
57
|
+
return process.stdin.isTTY === true && process.stdout.isTTY === true;
|
|
58
|
+
}
|
|
59
|
+
export async function confirm(question, fallback) {
|
|
60
|
+
if (!is_interactive())
|
|
61
|
+
return fallback;
|
|
62
|
+
const { createInterface } = await import("node:readline/promises");
|
|
63
|
+
const reader = createInterface({ input: process.stdin, output: process.stdout });
|
|
64
|
+
try {
|
|
65
|
+
const answer = (await reader.question(` ${question} ${fallback ? "[Y/n]" : "[y/N]"} `))
|
|
66
|
+
.trim()
|
|
67
|
+
.toLowerCase();
|
|
68
|
+
if (answer.length === 0)
|
|
69
|
+
return fallback;
|
|
70
|
+
return answer === "y" || answer === "yes";
|
|
71
|
+
}
|
|
72
|
+
finally {
|
|
73
|
+
reader.close();
|
|
74
|
+
}
|
|
75
|
+
}
|
package/dist/update.js
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { read_settings, update_settings } from "./config.js";
|
|
3
|
+
import { run, which } from "./system.js";
|
|
4
|
+
import { confirm, dim, fail, is_interactive, out, spinner, success } from "./ui.js";
|
|
5
|
+
import { emit, is_json_mode } from "./output.js";
|
|
6
|
+
import { bool_flag } from "./args.js";
|
|
7
|
+
import { VERSION } from "./version.js";
|
|
8
|
+
const PACKAGE = "nemu-cli";
|
|
9
|
+
const CHECK_INTERVAL_MS = 24 * 60 * 60 * 1000;
|
|
10
|
+
const FETCH_TIMEOUT_MS = 1500;
|
|
11
|
+
const QUIET_COMMANDS = new Set(["hook", "mcp", "token", "update"]);
|
|
12
|
+
const SEMVER = /^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?$/;
|
|
13
|
+
const registry_schema = z.object({ version: z.string().regex(SEMVER) });
|
|
14
|
+
function registry_url() {
|
|
15
|
+
const base = (process.env.NEMU_REGISTRY_URL ?? "https://registry.npmjs.org").replace(/\/+$/, "");
|
|
16
|
+
return `${base}/${PACKAGE}/latest`;
|
|
17
|
+
}
|
|
18
|
+
export function is_newer(candidate, current) {
|
|
19
|
+
const next = SEMVER.exec(candidate);
|
|
20
|
+
const now = SEMVER.exec(current);
|
|
21
|
+
if (next === null || now === null)
|
|
22
|
+
return false;
|
|
23
|
+
for (let i = 1; i <= 3; i += 1) {
|
|
24
|
+
const difference = Number(next[i]) - Number(now[i]);
|
|
25
|
+
if (difference !== 0)
|
|
26
|
+
return difference > 0;
|
|
27
|
+
}
|
|
28
|
+
if (next[4] === undefined && now[4] !== undefined)
|
|
29
|
+
return true;
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
export async function fetch_latest() {
|
|
33
|
+
try {
|
|
34
|
+
const response = await fetch(registry_url(), {
|
|
35
|
+
headers: { accept: "application/json" },
|
|
36
|
+
signal: AbortSignal.timeout(FETCH_TIMEOUT_MS),
|
|
37
|
+
});
|
|
38
|
+
if (!response.ok)
|
|
39
|
+
return null;
|
|
40
|
+
const parsed = registry_schema.safeParse(await response.json());
|
|
41
|
+
return parsed.success ? parsed.data.version : null;
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
export async function latest_version(force, now = Date.now()) {
|
|
48
|
+
const settings = await read_settings();
|
|
49
|
+
const fresh = settings.update_checked_at !== undefined && now - settings.update_checked_at < CHECK_INTERVAL_MS;
|
|
50
|
+
if (!force && fresh && settings.update_latest !== undefined)
|
|
51
|
+
return settings.update_latest;
|
|
52
|
+
const latest = await fetch_latest();
|
|
53
|
+
await update_settings({
|
|
54
|
+
update_checked_at: now,
|
|
55
|
+
...(latest !== null ? { update_latest: latest } : {}),
|
|
56
|
+
}).catch(() => undefined);
|
|
57
|
+
return latest ?? (fresh ? (settings.update_latest ?? null) : null);
|
|
58
|
+
}
|
|
59
|
+
function is_ephemeral_run() {
|
|
60
|
+
const script = (process.argv[1] ?? "").replaceAll("\\", "/");
|
|
61
|
+
return script.includes("/_npx/") || script.includes("/.bun/install/cache/");
|
|
62
|
+
}
|
|
63
|
+
function should_check(command) {
|
|
64
|
+
if (QUIET_COMMANDS.has(command))
|
|
65
|
+
return false;
|
|
66
|
+
if (is_json_mode() || !is_interactive())
|
|
67
|
+
return false;
|
|
68
|
+
if (process.env.CI !== undefined || process.env.NEMU_NO_UPDATE_CHECK === "1")
|
|
69
|
+
return false;
|
|
70
|
+
return !is_ephemeral_run();
|
|
71
|
+
}
|
|
72
|
+
async function install(version) {
|
|
73
|
+
const command = `npm i -g ${PACKAGE}@${version}`;
|
|
74
|
+
if ((await which("npm")) === null) {
|
|
75
|
+
fail(`npm was not found. Update by hand: ${command}`);
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
const progress = spinner(`Installing ${PACKAGE} ${version}`);
|
|
79
|
+
const result = await run("npm", ["install", "-g", `${PACKAGE}@${version}`], { timeout_ms: 180_000 });
|
|
80
|
+
progress.stop();
|
|
81
|
+
if (result.code !== 0) {
|
|
82
|
+
fail(`The update did not install. Run it yourself: ${command}`);
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
success(`Updated to ${version}.`);
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
async function offer(latest, now) {
|
|
89
|
+
out(` There is a new version available (${VERSION} -> ${latest}).`);
|
|
90
|
+
const accepted = await confirm("Do you want to upgrade?", true);
|
|
91
|
+
if (!accepted) {
|
|
92
|
+
await update_settings({ update_declined_version: latest, update_declined_at: now }).catch(() => undefined);
|
|
93
|
+
out(dim(` Later: nemu update`));
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
return install(latest);
|
|
97
|
+
}
|
|
98
|
+
export async function maybe_offer_update(command, now = Date.now()) {
|
|
99
|
+
try {
|
|
100
|
+
if (!should_check(command))
|
|
101
|
+
return;
|
|
102
|
+
const latest = await latest_version(false, now);
|
|
103
|
+
if (latest === null || !is_newer(latest, VERSION))
|
|
104
|
+
return;
|
|
105
|
+
const settings = await read_settings();
|
|
106
|
+
const declined_recently = settings.update_declined_version === latest &&
|
|
107
|
+
settings.update_declined_at !== undefined &&
|
|
108
|
+
now - settings.update_declined_at < CHECK_INTERVAL_MS;
|
|
109
|
+
if (declined_recently)
|
|
110
|
+
return;
|
|
111
|
+
if (await offer(latest, now))
|
|
112
|
+
out();
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
export async function update_command(args) {
|
|
119
|
+
const latest = await latest_version(true);
|
|
120
|
+
if (latest === null) {
|
|
121
|
+
fail("Could not reach the npm registry. Try again, or run: npm i -g nemu-cli@latest");
|
|
122
|
+
return 1;
|
|
123
|
+
}
|
|
124
|
+
const available = is_newer(latest, VERSION);
|
|
125
|
+
if (is_json_mode()) {
|
|
126
|
+
emit({ current: VERSION, latest, update_available: available });
|
|
127
|
+
return 0;
|
|
128
|
+
}
|
|
129
|
+
if (!available) {
|
|
130
|
+
out(` nemu ${VERSION} is the latest version.`);
|
|
131
|
+
return 0;
|
|
132
|
+
}
|
|
133
|
+
if (bool_flag(args, "yes", "y"))
|
|
134
|
+
return (await install(latest)) ? 0 : 1;
|
|
135
|
+
if (!is_interactive()) {
|
|
136
|
+
out(` There is a new version available (${VERSION} -> ${latest}). Run: npm i -g ${PACKAGE}@${latest}`);
|
|
137
|
+
return 0;
|
|
138
|
+
}
|
|
139
|
+
await offer(latest, Date.now());
|
|
140
|
+
return 0;
|
|
141
|
+
}
|
package/dist/version.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const VERSION = "1.2.0";
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nemu-cli",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "Command line access to Nemu
|
|
3
|
+
"version": "1.2.0",
|
|
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"
|
|
7
7
|
},
|
|
@@ -22,7 +22,11 @@
|
|
|
22
22
|
"ai",
|
|
23
23
|
"cli",
|
|
24
24
|
"oauth",
|
|
25
|
-
"device-flow"
|
|
25
|
+
"device-flow",
|
|
26
|
+
"mcp",
|
|
27
|
+
"claude-code",
|
|
28
|
+
"codex",
|
|
29
|
+
"memory"
|
|
26
30
|
],
|
|
27
31
|
"author": "hiraeeth",
|
|
28
32
|
"license": "MIT",
|
|
@@ -35,6 +39,7 @@
|
|
|
35
39
|
},
|
|
36
40
|
"homepage": "https://docs.nemu.cc",
|
|
37
41
|
"dependencies": {
|
|
38
|
-
"@nemu-ai/sdk": "^1.1.0"
|
|
42
|
+
"@nemu-ai/sdk": "^1.1.0",
|
|
43
|
+
"zod": "^4.1.0"
|
|
39
44
|
}
|
|
40
45
|
}
|