nemu-cli 1.4.0 → 1.5.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 +8 -0
- package/LICENSE +0 -0
- package/README.md +0 -0
- package/dist/auth/token.js +1 -1
- package/dist/commands/key.js +95 -0
- package/dist/commands/login.js +3 -0
- package/dist/commands/mcp.js +2 -2
- package/dist/commands/whoami.js +19 -0
- package/dist/config.js +5 -0
- package/dist/context/api.js +9 -9
- package/dist/http.js +6 -1
- package/dist/index.js +1 -0
- package/dist/ui.js +35 -0
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.5.0
|
|
4
|
+
|
|
5
|
+
`nemu login key` signs in with a workspace API key, the same `sk_` key that calls the gateway. It
|
|
6
|
+
asks for the key, or reads `NEMU_API_KEY`, and shows the workspace and access the key has. Context
|
|
7
|
+
and vault commands use the unified routes under `/api/v1`, and work in the workspace you choose, so
|
|
8
|
+
members share the workspace's Context. Earlier versions call routes that no longer exist and need
|
|
9
|
+
this update.
|
|
10
|
+
|
|
3
11
|
## 1.4.0
|
|
4
12
|
|
|
5
13
|
`nemu setup opencode` adds the Nemu MCP server to OpenCode's global config,
|
package/LICENSE
CHANGED
|
File without changes
|
package/README.md
CHANGED
|
File without changes
|
package/dist/auth/token.js
CHANGED
|
@@ -97,7 +97,7 @@ export async function fresh_credentials() {
|
|
|
97
97
|
if (current === null) {
|
|
98
98
|
throw new CliError("Not signed in. Run nemu login.", "not_signed_in");
|
|
99
99
|
}
|
|
100
|
-
if (is_fresh(current))
|
|
100
|
+
if (current.kind === "key" || is_fresh(current))
|
|
101
101
|
return current;
|
|
102
102
|
const release = await acquire_lock();
|
|
103
103
|
try {
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { API_VERSION, api_url, write_credentials } from "../config.js";
|
|
3
|
+
import { CliError } from "../errors.js";
|
|
4
|
+
import { VERSION } from "../version.js";
|
|
5
|
+
import { done, is_json_mode } from "../output.js";
|
|
6
|
+
import { ask_secret, bold, dim, is_interactive, out, success } from "../ui.js";
|
|
7
|
+
const KEY_PATTERN = /^sk_[a-z]{5}-[a-z]{5}\.[A-Za-z0-9]{40}$/;
|
|
8
|
+
const description_schema = z.object({
|
|
9
|
+
data: z.object({
|
|
10
|
+
kind: z.literal("key"),
|
|
11
|
+
name: z.string(),
|
|
12
|
+
workspace: z.object({ id: z.string(), name: z.string() }),
|
|
13
|
+
expires_at: z.string().nullable(),
|
|
14
|
+
scopes: z.array(z.string()),
|
|
15
|
+
access: z.array(z.object({ scope: z.string(), label: z.string(), granted: z.boolean() })),
|
|
16
|
+
}),
|
|
17
|
+
});
|
|
18
|
+
async function read_stdin() {
|
|
19
|
+
const chunks = [];
|
|
20
|
+
for await (const chunk of process.stdin) {
|
|
21
|
+
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(String(chunk)));
|
|
22
|
+
}
|
|
23
|
+
return Buffer.concat(chunks).toString("utf8");
|
|
24
|
+
}
|
|
25
|
+
async function read_key() {
|
|
26
|
+
const from_env = process.env.NEMU_API_KEY;
|
|
27
|
+
if (from_env !== undefined && from_env.trim().length > 0)
|
|
28
|
+
return from_env.trim();
|
|
29
|
+
if (is_interactive())
|
|
30
|
+
return (await ask_secret("API key:")).trim();
|
|
31
|
+
return (await read_stdin()).trim();
|
|
32
|
+
}
|
|
33
|
+
export async function describe_key(url, key) {
|
|
34
|
+
let response;
|
|
35
|
+
try {
|
|
36
|
+
response = await fetch(`${url}/api/v1/key`, {
|
|
37
|
+
headers: {
|
|
38
|
+
authorization: `Bearer ${key}`,
|
|
39
|
+
"nemu-api-version": API_VERSION,
|
|
40
|
+
"user-agent": `nemu-cli/${VERSION}`,
|
|
41
|
+
},
|
|
42
|
+
signal: AbortSignal.timeout(20_000),
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
throw new CliError(`Could not reach ${url}.`, "network_failed");
|
|
47
|
+
}
|
|
48
|
+
if (response.status === 401 || response.status === 403) {
|
|
49
|
+
throw new CliError("This key is invalid, disabled, expired or not allowed from this address.", "key_rejected");
|
|
50
|
+
}
|
|
51
|
+
const parsed = description_schema.safeParse(await response.json().catch(() => null));
|
|
52
|
+
if (!response.ok || !parsed.success) {
|
|
53
|
+
throw new CliError("Nemu could not describe this key.", "key_describe_failed", {
|
|
54
|
+
status: response.status,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
return parsed.data.data;
|
|
58
|
+
}
|
|
59
|
+
export async function login_key() {
|
|
60
|
+
const url = api_url();
|
|
61
|
+
const key = await read_key();
|
|
62
|
+
if (!KEY_PATTERN.test(key)) {
|
|
63
|
+
throw new CliError("That is not a Nemu API key. Keys look like sk_xxxxx-xxxxx. followed by 40 letters and digits.", "invalid_key_format");
|
|
64
|
+
}
|
|
65
|
+
const description = await describe_key(url, key);
|
|
66
|
+
await write_credentials({
|
|
67
|
+
kind: "key",
|
|
68
|
+
access_token: key,
|
|
69
|
+
expires_at: Number.MAX_SAFE_INTEGER,
|
|
70
|
+
scope: description.scopes.join(" "),
|
|
71
|
+
api_url: url,
|
|
72
|
+
account: `key ${description.name}`,
|
|
73
|
+
workspace: description.workspace,
|
|
74
|
+
});
|
|
75
|
+
if (is_json_mode()) {
|
|
76
|
+
done("Signed in with an API key", {
|
|
77
|
+
key: description.name,
|
|
78
|
+
workspace: description.workspace,
|
|
79
|
+
scopes: description.scopes,
|
|
80
|
+
expires_at: description.expires_at,
|
|
81
|
+
});
|
|
82
|
+
return 0;
|
|
83
|
+
}
|
|
84
|
+
success(`Signed in with the key ${bold(description.name)} for the workspace ${bold(description.workspace.name)}`);
|
|
85
|
+
out();
|
|
86
|
+
for (const row of description.access) {
|
|
87
|
+
out(` ${row.granted ? "yes" : " no"} ${row.label}`);
|
|
88
|
+
}
|
|
89
|
+
out();
|
|
90
|
+
if (description.expires_at !== null) {
|
|
91
|
+
out(dim(` The key expires on ${description.expires_at.slice(0, 10)}.`));
|
|
92
|
+
}
|
|
93
|
+
out(dim(" The key is stored only on this machine. nemu logout removes it."));
|
|
94
|
+
return 0;
|
|
95
|
+
}
|
package/dist/commands/login.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { NemuDeviceError } from "@nemu-ai/sdk";
|
|
2
2
|
import { api_url, is_expired, read_credentials, write_credentials, } from "../config.js";
|
|
3
3
|
import { device_client } from "../session.js";
|
|
4
|
+
import { login_key } from "./key.js";
|
|
4
5
|
import { verify_device } from "../device.js";
|
|
5
6
|
import { bool_flag } from "../args.js";
|
|
6
7
|
import { done, is_json_mode } from "../output.js";
|
|
@@ -15,6 +16,8 @@ async function account_name(nemu) {
|
|
|
15
16
|
}
|
|
16
17
|
}
|
|
17
18
|
export async function login(args) {
|
|
19
|
+
if (args.positional[0] === "key")
|
|
20
|
+
return login_key();
|
|
18
21
|
const url = api_url();
|
|
19
22
|
const force = bool_flag(args, "force", "f");
|
|
20
23
|
const no_browser = bool_flag(args, "no-browser");
|
package/dist/commands/mcp.js
CHANGED
|
@@ -196,8 +196,8 @@ const SNIPPETS = {
|
|
|
196
196
|
text: JSON.stringify({ mcp: { nemu: { type: "local", command: ["nemu", "mcp", "--client", "opencode"], enabled: true } } }, null, 2),
|
|
197
197
|
},
|
|
198
198
|
remote: {
|
|
199
|
-
where: "Any client that supports remote MCP over HTTP (create
|
|
200
|
-
text: JSON.stringify({ url: "https://app.nemu.cc/api/mcp", headers: { Authorization: "Bearer <your
|
|
199
|
+
where: "Any client that supports remote MCP over HTTP (create an API key with Context access on the Keys page first)",
|
|
200
|
+
text: JSON.stringify({ url: "https://app.nemu.cc/api/mcp", headers: { Authorization: "Bearer <your API key>" } }, null, 2),
|
|
201
201
|
},
|
|
202
202
|
};
|
|
203
203
|
function mcp_config(args) {
|
package/dist/commands/whoami.js
CHANGED
|
@@ -2,6 +2,7 @@ import { is_expired, read_credentials } from "../config.js";
|
|
|
2
2
|
import { client } from "../session.js";
|
|
3
3
|
import { detail, is_json_mode } from "../output.js";
|
|
4
4
|
import { bold, dim, out } from "../ui.js";
|
|
5
|
+
import { describe_key } from "./key.js";
|
|
5
6
|
export async function whoami() {
|
|
6
7
|
const credentials = await read_credentials();
|
|
7
8
|
if (credentials === null) {
|
|
@@ -16,6 +17,24 @@ export async function whoami() {
|
|
|
16
17
|
out("Your session has expired. Run nemu login.");
|
|
17
18
|
return 1;
|
|
18
19
|
}
|
|
20
|
+
if (credentials.kind === "key") {
|
|
21
|
+
const key = await describe_key(credentials.api_url, credentials.access_token);
|
|
22
|
+
if (is_json_mode()) {
|
|
23
|
+
detail({
|
|
24
|
+
signed_in: true,
|
|
25
|
+
kind: "key",
|
|
26
|
+
key: key.name,
|
|
27
|
+
workspace: key.workspace,
|
|
28
|
+
scopes: key.scopes,
|
|
29
|
+
api_url: credentials.api_url,
|
|
30
|
+
});
|
|
31
|
+
return 0;
|
|
32
|
+
}
|
|
33
|
+
out(`${bold(`key ${key.name}`)} ${dim(`in ${key.workspace.name}`)}`);
|
|
34
|
+
out(dim(` ${credentials.api_url}`));
|
|
35
|
+
out(dim(` access ${key.scopes.join(", ") || "none"}`));
|
|
36
|
+
return 0;
|
|
37
|
+
}
|
|
19
38
|
const nemu = await client();
|
|
20
39
|
const account = await nemu.user.get();
|
|
21
40
|
if (is_json_mode()) {
|
package/dist/config.js
CHANGED
|
@@ -6,12 +6,16 @@ export const DEFAULT_API_URL = "https://app.nemu.cc";
|
|
|
6
6
|
export const DEFAULT_CLIENT_ID = "nemu_cli";
|
|
7
7
|
export const API_VERSION = "2026-07-14";
|
|
8
8
|
const credentials_schema = z.object({
|
|
9
|
+
kind: z.enum(["oauth", "key"]).default("oauth"),
|
|
9
10
|
access_token: z.string().min(1),
|
|
10
11
|
refresh_token: z.string().min(1).optional(),
|
|
11
12
|
expires_at: z.number(),
|
|
12
13
|
scope: z.string(),
|
|
13
14
|
api_url: z.string().url(),
|
|
14
15
|
account: z.string().optional(),
|
|
16
|
+
workspace: z
|
|
17
|
+
.object({ id: z.string().min(1), name: z.string() })
|
|
18
|
+
.optional(),
|
|
15
19
|
});
|
|
16
20
|
const settings_schema = z.object({
|
|
17
21
|
device_id: z
|
|
@@ -25,6 +29,7 @@ const settings_schema = z.object({
|
|
|
25
29
|
update_declined_version: z.string().max(64).optional(),
|
|
26
30
|
update_declined_at: z.number().optional(),
|
|
27
31
|
setup_version: z.string().max(64).optional(),
|
|
32
|
+
context_workspace: z.string().min(1).max(64).optional(),
|
|
28
33
|
});
|
|
29
34
|
export function api_url() {
|
|
30
35
|
return (process.env.NEMU_API_URL ?? DEFAULT_API_URL).replace(/\/+$/, "");
|
package/dist/context/api.js
CHANGED
|
@@ -52,23 +52,23 @@ const device_schema = z.object({
|
|
|
52
52
|
name: z.string(),
|
|
53
53
|
});
|
|
54
54
|
export async function open_project(identity) {
|
|
55
|
-
const result = await api("POST", "/api/v1/
|
|
55
|
+
const result = await api("POST", "/api/v1/projects", z.object({ data: project_schema }), { body: identity });
|
|
56
56
|
return result.data;
|
|
57
57
|
}
|
|
58
58
|
export async function list_projects() {
|
|
59
|
-
const result = await api("GET", "/api/v1/
|
|
59
|
+
const result = await api("GET", "/api/v1/projects", z.object({ data: z.array(project_schema) }));
|
|
60
60
|
return result.data;
|
|
61
61
|
}
|
|
62
62
|
export async function load_project(project_id, branch) {
|
|
63
|
-
const result = await api("GET", `/api/v1/
|
|
63
|
+
const result = await api("GET", `/api/v1/projects/${encodeURIComponent(project_id)}/load`, z.object({ data: load_schema }), { query: { branch } });
|
|
64
64
|
return result.data;
|
|
65
65
|
}
|
|
66
66
|
export async function search_project(project_id, query, limit = 10) {
|
|
67
|
-
const result = await api("GET", `/api/v1/
|
|
67
|
+
const result = await api("GET", `/api/v1/projects/${encodeURIComponent(project_id)}/search`, z.object({ data: z.array(entry_schema) }), { query: { q: query, limit } });
|
|
68
68
|
return result.data;
|
|
69
69
|
}
|
|
70
70
|
export async function write_batch(project_id, entries) {
|
|
71
|
-
const result = await api("POST", `/api/v1/
|
|
71
|
+
const result = await api("POST", `/api/v1/projects/${encodeURIComponent(project_id)}/entries/batch`, z.object({
|
|
72
72
|
data: z.array(z.object({
|
|
73
73
|
name: z.string(),
|
|
74
74
|
status: z.enum(["created", "updated", "skipped"]),
|
|
@@ -79,21 +79,21 @@ export async function write_batch(project_id, entries) {
|
|
|
79
79
|
return result.data;
|
|
80
80
|
}
|
|
81
81
|
export async function register_device(input) {
|
|
82
|
-
const result = await api("POST", "/api/v1/
|
|
82
|
+
const result = await api("POST", "/api/v1/devices", z.object({ data: device_schema }), { body: input, device: false });
|
|
83
83
|
return result.data;
|
|
84
84
|
}
|
|
85
85
|
export async function mark_stale(project_id, stale, fresh) {
|
|
86
86
|
if (stale.length === 0 && fresh.length === 0)
|
|
87
87
|
return;
|
|
88
|
-
await api("POST", `/api/v1/
|
|
88
|
+
await api("POST", `/api/v1/projects/${encodeURIComponent(project_id)}/stale`, z.object({ marked: z.number(), cleared: z.number() }), { body: { stale: stale.slice(0, 400), fresh: fresh.slice(0, 400) } });
|
|
89
89
|
}
|
|
90
90
|
export async function list_devices() {
|
|
91
|
-
const result = await api("GET", "/api/v1/
|
|
91
|
+
const result = await api("GET", "/api/v1/devices", z.object({
|
|
92
92
|
data: z.array(z.object({ id: z.string(), name: z.string(), revoked_at: z.string().nullable() })),
|
|
93
93
|
}), { device: false });
|
|
94
94
|
return result.data;
|
|
95
95
|
}
|
|
96
96
|
export async function export_all() {
|
|
97
|
-
const result = await api("GET", "/api/v1/
|
|
97
|
+
const result = await api("GET", "/api/v1/projects/export", z.object({ data: z.unknown() }));
|
|
98
98
|
return result.data;
|
|
99
99
|
}
|
package/dist/http.js
CHANGED
|
@@ -23,11 +23,16 @@ export async function api(method, path, schema, options = {}) {
|
|
|
23
23
|
};
|
|
24
24
|
if (options.body !== undefined)
|
|
25
25
|
headers["content-type"] = "application/json";
|
|
26
|
-
|
|
26
|
+
const is_key = credentials.kind === "key";
|
|
27
|
+
if (!is_key &&
|
|
28
|
+
options.device !== false &&
|
|
27
29
|
settings.device_id !== undefined &&
|
|
28
30
|
settings.device_api_url === credentials.api_url) {
|
|
29
31
|
headers["x-nemu-device"] = settings.device_id;
|
|
30
32
|
}
|
|
33
|
+
if (!is_key && settings.context_workspace !== undefined) {
|
|
34
|
+
headers["x-nemu-workspace"] = settings.context_workspace;
|
|
35
|
+
}
|
|
31
36
|
let response;
|
|
32
37
|
try {
|
|
33
38
|
response = await fetch(url, {
|
package/dist/index.js
CHANGED
|
@@ -87,6 +87,7 @@ const HELP = `
|
|
|
87
87
|
|
|
88
88
|
${bold("Account")}
|
|
89
89
|
login [--force] [--no-browser] Sign in with the device flow
|
|
90
|
+
login key Sign in with a workspace API key (asked for, or NEMU_API_KEY)
|
|
90
91
|
logout Delete the stored token
|
|
91
92
|
whoami Show the signed in account
|
|
92
93
|
user Full account record
|
package/dist/ui.js
CHANGED
|
@@ -93,3 +93,38 @@ export async function confirm(question, fallback) {
|
|
|
93
93
|
reader.close();
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
|
+
export async function ask_secret(question) {
|
|
97
|
+
const input = process.stdin;
|
|
98
|
+
process.stdout.write(` ${question} `);
|
|
99
|
+
input.setRawMode(true);
|
|
100
|
+
input.resume();
|
|
101
|
+
input.setEncoding("utf8");
|
|
102
|
+
return new Promise((resolve, reject) => {
|
|
103
|
+
let value = "";
|
|
104
|
+
const finish = (error) => {
|
|
105
|
+
input.setRawMode(false);
|
|
106
|
+
input.pause();
|
|
107
|
+
input.removeListener("data", on_data);
|
|
108
|
+
process.stdout.write("\n");
|
|
109
|
+
if (error === null)
|
|
110
|
+
resolve(value);
|
|
111
|
+
else
|
|
112
|
+
reject(error);
|
|
113
|
+
};
|
|
114
|
+
const on_data = (chunk) => {
|
|
115
|
+
for (const character of chunk) {
|
|
116
|
+
if (character === "\r" || character === "\n")
|
|
117
|
+
return finish(null);
|
|
118
|
+
if (character === "\u0003")
|
|
119
|
+
return finish(new Error("Cancelled."));
|
|
120
|
+
if (character === "\u007f" || character === "\b") {
|
|
121
|
+
value = value.slice(0, -1);
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
if (character >= " ")
|
|
125
|
+
value += character;
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
input.on("data", on_data);
|
|
129
|
+
});
|
|
130
|
+
}
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "1.
|
|
1
|
+
export const VERSION = "1.5.0";
|