nemu-cli 1.5.0 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +198 -116
- package/LICENSE +21 -21
- package/README.md +273 -235
- package/dist/args.js +9 -1
- package/dist/clients/claude-plugin.js +68 -0
- package/dist/clients/registry.js +9 -1
- package/dist/commands/login.js +9 -4
- package/dist/commands/private.js +259 -0
- package/dist/commands/status.js +42 -4
- package/dist/commands/sync.js +207 -0
- package/dist/commands/vault.js +257 -0
- package/dist/device.js +15 -9
- package/dist/http.js +32 -20
- package/dist/index.js +117 -100
- package/dist/vault/api.js +300 -0
- package/dist/vault/connect.js +59 -0
- package/dist/vault/engine.js +636 -0
- package/dist/vault/files.js +187 -0
- package/dist/vault/ignore.js +103 -0
- package/dist/vault/lock.js +85 -0
- package/dist/vault/merge.js +236 -0
- package/dist/vault/paths.js +99 -0
- package/dist/vault/plan.js +279 -0
- package/dist/vault/private/api.js +110 -0
- package/dist/vault/private/crypto.js +212 -0
- package/dist/vault/private/keystore.js +104 -0
- package/dist/vault/private/locks.js +59 -0
- package/dist/vault/private/strength.js +22 -0
- package/dist/vault/state.js +118 -0
- package/dist/vault/watch.js +101 -0
- package/dist/version.js +1 -1
- package/package.json +54 -48
- package/plugin/.claude-plugin/marketplace.json +14 -0
- package/plugin/nemu/.claude-plugin/plugin.json +8 -0
- package/plugin/nemu/.mcp.json +8 -0
- package/plugin/nemu/commands/inspo.md +22 -0
- package/plugin/nemu/commands/remember.md +16 -0
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
import { mkdir, readdir } from "node:fs/promises";
|
|
2
|
+
import { basename, dirname, resolve } from "node:path";
|
|
3
|
+
import { bool_flag, flag } from "../args.js";
|
|
4
|
+
import { CliError } from "../errors.js";
|
|
5
|
+
import { emit, is_json_mode, table } from "../output.js";
|
|
6
|
+
import { bold, dim, out, success } from "../ui.js";
|
|
7
|
+
import { create_vault, list_vaults, VaultApi } from "../vault/api.js";
|
|
8
|
+
import { cli_transport, client_label, signed_in } from "../vault/connect.js";
|
|
9
|
+
import { is_conflict_copy } from "../vault/paths.js";
|
|
10
|
+
import { empty_state, find_root, marker_path, read_marker, read_state, remove_marker, remove_state, state_path_for, write_marker, write_state, } from "../vault/state.js";
|
|
11
|
+
import { is_default_ignored } from "../vault/ignore.js";
|
|
12
|
+
import { load_vault_key } from "../vault/private/keystore.js";
|
|
13
|
+
import { approve_requests, create_private_vault, forget_key, unlock_vault } from "./private.js";
|
|
14
|
+
const USAGE = "Use: nemu vault list | link <folder> [--vault <name|id>] [--create [--private]] [--obsidian] | unlink [folder] | status [folder] | unlock [folder] [--password|--recovery|--approve] | approve [folder] | forget [folder]";
|
|
15
|
+
function size_of(bytes) {
|
|
16
|
+
if (bytes === undefined)
|
|
17
|
+
return "";
|
|
18
|
+
if (bytes < 1024 * 1024)
|
|
19
|
+
return `${Math.ceil(bytes / 1024)} KB`;
|
|
20
|
+
return `${(bytes / 1024 / 1024).toFixed(1)} MB`;
|
|
21
|
+
}
|
|
22
|
+
async function list(args) {
|
|
23
|
+
await signed_in();
|
|
24
|
+
const vaults = await list_vaults(cli_transport(flag(args, "workspace", "w")));
|
|
25
|
+
table(vaults.map((vault) => ({
|
|
26
|
+
id: vault.id,
|
|
27
|
+
name: vault.name,
|
|
28
|
+
notes: vault.notes ?? "",
|
|
29
|
+
size: size_of(vault.stored_bytes),
|
|
30
|
+
})), ["id", "name", "notes", "size"], "No vaults yet. Create one with nemu vault link <folder> --create.");
|
|
31
|
+
return 0;
|
|
32
|
+
}
|
|
33
|
+
function pick_vault(vaults, wanted) {
|
|
34
|
+
if (wanted === undefined)
|
|
35
|
+
return vaults.length === 1 ? vaults[0] : null;
|
|
36
|
+
return (vaults.find((vault) => vault.id === wanted) ??
|
|
37
|
+
vaults.find((vault) => vault.name.toLowerCase() === wanted.toLowerCase()) ??
|
|
38
|
+
null);
|
|
39
|
+
}
|
|
40
|
+
async function link(args) {
|
|
41
|
+
const raw = args.positional[1];
|
|
42
|
+
if (raw === undefined)
|
|
43
|
+
throw new CliError(USAGE, "invalid_arguments");
|
|
44
|
+
const folder = resolve(raw);
|
|
45
|
+
const credentials = await signed_in();
|
|
46
|
+
const workspace = flag(args, "workspace", "w");
|
|
47
|
+
const wanted = flag(args, "vault");
|
|
48
|
+
const create = bool_flag(args, "create");
|
|
49
|
+
const is_private = bool_flag(args, "private");
|
|
50
|
+
if (is_private && !create) {
|
|
51
|
+
throw new CliError("--private makes a new vault, so it goes with --create.", "invalid_arguments");
|
|
52
|
+
}
|
|
53
|
+
const enclosing = await find_root(dirname(folder));
|
|
54
|
+
if (enclosing !== null && enclosing !== folder) {
|
|
55
|
+
throw new CliError(`${folder} is inside ${enclosing}, which is already linked to a vault.`, "already_linked");
|
|
56
|
+
}
|
|
57
|
+
await mkdir(folder, { recursive: true });
|
|
58
|
+
const existing = await read_marker(folder);
|
|
59
|
+
const transport = cli_transport(workspace);
|
|
60
|
+
const vaults = await list_vaults(transport);
|
|
61
|
+
let vault = pick_vault(vaults, wanted);
|
|
62
|
+
if (vault === null && create) {
|
|
63
|
+
vault = is_private
|
|
64
|
+
? await create_private_vault(transport, wanted ?? basename(folder))
|
|
65
|
+
: await create_vault(transport, wanted ?? basename(folder));
|
|
66
|
+
}
|
|
67
|
+
if (vault === null) {
|
|
68
|
+
const names = vaults.map((entry) => `"${entry.name}"`).join(", ");
|
|
69
|
+
throw new CliError(vaults.length === 0
|
|
70
|
+
? "This workspace has no vaults yet. Add --create to make one named after the folder."
|
|
71
|
+
: wanted === undefined
|
|
72
|
+
? `Choose a vault with --vault <name|id>: ${names}. Or add --create for a new one.`
|
|
73
|
+
: `No vault is called "${wanted}". Have: ${names}. Add --create to make it.`, "vault_not_found");
|
|
74
|
+
}
|
|
75
|
+
if (existing !== null && existing.vault_id !== vault.id) {
|
|
76
|
+
throw new CliError(`${folder} is already linked to the vault "${existing.vault_name}". Run nemu vault unlink ${folder} first.`, "already_linked");
|
|
77
|
+
}
|
|
78
|
+
const state_path = state_path_for(vault.id);
|
|
79
|
+
const previous = await read_state(state_path);
|
|
80
|
+
if (previous !== null && previous.root !== folder && (await read_marker(previous.root))?.vault_id === vault.id) {
|
|
81
|
+
throw new CliError(`The vault "${vault.name}" is already synced into ${previous.root} on this computer. Run nemu vault unlink ${previous.root} first.`, "already_linked");
|
|
82
|
+
}
|
|
83
|
+
const info = await new VaultApi(transport, vault.id, client_label()).info();
|
|
84
|
+
const workspace_id = info.workspace_id ?? credentials.workspace?.id ?? workspace ?? null;
|
|
85
|
+
await write_marker(folder, {
|
|
86
|
+
version: 1,
|
|
87
|
+
vault_id: vault.id,
|
|
88
|
+
vault_name: vault.name,
|
|
89
|
+
workspace_id,
|
|
90
|
+
server: credentials.api_url,
|
|
91
|
+
linked_at: new Date().toISOString(),
|
|
92
|
+
mode: info.data.mode === "private" ? "private" : "standard",
|
|
93
|
+
});
|
|
94
|
+
if (previous === null || previous.root !== folder || existing === null) {
|
|
95
|
+
await write_state(state_path, empty_state(vault.id, folder, {
|
|
96
|
+
conflicts: previous?.settings.conflicts,
|
|
97
|
+
obsidian: bool_flag(args, "obsidian") || (previous?.settings.obsidian ?? false),
|
|
98
|
+
}));
|
|
99
|
+
}
|
|
100
|
+
else if (bool_flag(args, "obsidian")) {
|
|
101
|
+
await write_state(state_path, { ...previous, settings: { ...previous.settings, obsidian: true }, full_next: true });
|
|
102
|
+
}
|
|
103
|
+
if (is_json_mode()) {
|
|
104
|
+
emit({ ok: true, folder, vault: { id: vault.id, name: vault.name }, workspace_id, marker: marker_path(folder) });
|
|
105
|
+
return 0;
|
|
106
|
+
}
|
|
107
|
+
success(`Linked ${folder} to the ${info.data.mode === "private" ? "private " : ""}vault ${bold(vault.name)}`);
|
|
108
|
+
if (info.data.mode === "private" && (await load_vault_key(vault.id)) === null) {
|
|
109
|
+
out(dim(` It is locked on this computer. Run nemu vault unlock ${raw} first.`));
|
|
110
|
+
}
|
|
111
|
+
out(dim(` Run nemu sync ${raw} to sync it, or nemu sync ${raw} --watch to keep it in sync.`));
|
|
112
|
+
return 0;
|
|
113
|
+
}
|
|
114
|
+
async function locate(args) {
|
|
115
|
+
const raw = args.positional[1];
|
|
116
|
+
if (raw !== undefined)
|
|
117
|
+
return resolve(raw);
|
|
118
|
+
const found = await find_root(process.cwd());
|
|
119
|
+
if (found === null)
|
|
120
|
+
throw new CliError("This folder is not linked to a vault.", "not_linked");
|
|
121
|
+
return found;
|
|
122
|
+
}
|
|
123
|
+
async function unlink(args) {
|
|
124
|
+
const folder = await locate(args);
|
|
125
|
+
const marker = await read_marker(folder);
|
|
126
|
+
if (marker === null)
|
|
127
|
+
throw new CliError(`${folder} is not linked to a vault.`, "not_linked");
|
|
128
|
+
const state_path = state_path_for(marker.vault_id);
|
|
129
|
+
const state = await read_state(state_path);
|
|
130
|
+
if (state === null || state.root === folder)
|
|
131
|
+
await remove_state(state_path);
|
|
132
|
+
await remove_marker(folder);
|
|
133
|
+
if (is_json_mode()) {
|
|
134
|
+
emit({ ok: true, folder, vault_id: marker.vault_id });
|
|
135
|
+
return 0;
|
|
136
|
+
}
|
|
137
|
+
success(`Unlinked ${folder} from "${marker.vault_name}". Your files are still there.`);
|
|
138
|
+
return 0;
|
|
139
|
+
}
|
|
140
|
+
async function conflict_copies(root, relative = "") {
|
|
141
|
+
const found = [];
|
|
142
|
+
const entries = await readdir(relative === "" ? root : `${root}/${relative}`, { withFileTypes: true }).catch(() => []);
|
|
143
|
+
for (const entry of entries) {
|
|
144
|
+
const path = relative === "" ? entry.name : `${relative}/${entry.name}`;
|
|
145
|
+
if (is_default_ignored(path, false))
|
|
146
|
+
continue;
|
|
147
|
+
if (entry.isDirectory())
|
|
148
|
+
found.push(...(await conflict_copies(root, path)));
|
|
149
|
+
else if (entry.isFile() && is_conflict_copy(path.normalize("NFC")))
|
|
150
|
+
found.push(path);
|
|
151
|
+
}
|
|
152
|
+
return found;
|
|
153
|
+
}
|
|
154
|
+
async function status(args) {
|
|
155
|
+
const folder = await locate(args);
|
|
156
|
+
const marker = await read_marker(folder);
|
|
157
|
+
if (marker === null)
|
|
158
|
+
throw new CliError(`${folder} is not linked to a vault.`, "not_linked");
|
|
159
|
+
const state = await read_state(state_path_for(marker.vault_id));
|
|
160
|
+
const conflicts = await conflict_copies(folder);
|
|
161
|
+
const marker_mode = await vault_mode(marker);
|
|
162
|
+
const summary = {
|
|
163
|
+
folder,
|
|
164
|
+
vault: { id: marker.vault_id, name: marker.vault_name },
|
|
165
|
+
server: marker.server,
|
|
166
|
+
workspace_id: marker.workspace_id,
|
|
167
|
+
tracked: state === null ? 0 : Object.keys(state.files).length,
|
|
168
|
+
last_sync: state?.synced_at ?? null,
|
|
169
|
+
conflicts_mode: state?.settings.conflicts ?? "merge",
|
|
170
|
+
private: marker_mode === "private",
|
|
171
|
+
unlocked: marker_mode === "private" ? (await load_vault_key(marker.vault_id)) !== null : null,
|
|
172
|
+
obsidian_settings: state?.settings.obsidian ?? false,
|
|
173
|
+
obsidian_plugins: state?.settings.obsidian_plugins ?? false,
|
|
174
|
+
conflicts,
|
|
175
|
+
};
|
|
176
|
+
if (is_json_mode()) {
|
|
177
|
+
emit(summary);
|
|
178
|
+
return 0;
|
|
179
|
+
}
|
|
180
|
+
out(` ${bold(marker.vault_name)} ${dim(marker.vault_id)}`);
|
|
181
|
+
out(` ${dim("folder ")} ${folder}`);
|
|
182
|
+
out(` ${dim("files ")} ${summary.tracked}`);
|
|
183
|
+
if (summary.private) {
|
|
184
|
+
out(` ${dim("private ")} ${summary.unlocked === true ? "open on this computer" : "locked on this computer (nemu vault unlock)"}`);
|
|
185
|
+
}
|
|
186
|
+
out(` ${dim("last sync")} ${summary.last_sync ?? "never"}`);
|
|
187
|
+
out(` ${dim("conflicts")} ${summary.conflicts_mode === "merge" ? "merge when possible" : "always write a conflict file"}`);
|
|
188
|
+
out(` ${dim(".obsidian")} ${summary.obsidian_settings ? "synced" : "not synced on this device"}`);
|
|
189
|
+
if (summary.obsidian_settings) {
|
|
190
|
+
out(` ${dim("plugins ")} ${summary.obsidian_plugins ? "synced" : "not synced (plugins are code)"}`);
|
|
191
|
+
}
|
|
192
|
+
if (conflicts.length > 0) {
|
|
193
|
+
out();
|
|
194
|
+
out(` ${bold(`${conflicts.length} open conflict${conflicts.length === 1 ? "" : "s"}`)} ${dim("(delete the copy you do not want)")}`);
|
|
195
|
+
for (const path of conflicts)
|
|
196
|
+
out(` ${path}`);
|
|
197
|
+
}
|
|
198
|
+
return 0;
|
|
199
|
+
}
|
|
200
|
+
async function vault_mode(marker) {
|
|
201
|
+
try {
|
|
202
|
+
await signed_in();
|
|
203
|
+
const info = await new VaultApi(cli_transport(marker.workspace_id), marker.vault_id, client_label()).info();
|
|
204
|
+
return info.data.mode ?? "standard";
|
|
205
|
+
}
|
|
206
|
+
catch {
|
|
207
|
+
return "unknown";
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
async function linked_marker(args) {
|
|
211
|
+
const folder = await locate(args);
|
|
212
|
+
const marker = await read_marker(folder);
|
|
213
|
+
if (marker === null)
|
|
214
|
+
throw new CliError(`${folder} is not linked to a vault.`, "not_linked");
|
|
215
|
+
await signed_in();
|
|
216
|
+
return marker;
|
|
217
|
+
}
|
|
218
|
+
async function unlock(args) {
|
|
219
|
+
const marker = await linked_marker(args);
|
|
220
|
+
await unlock_vault(cli_transport(marker.workspace_id), marker.vault_id, marker.vault_name, {
|
|
221
|
+
password: bool_flag(args, "password"),
|
|
222
|
+
recovery: bool_flag(args, "recovery"),
|
|
223
|
+
approve: bool_flag(args, "approve"),
|
|
224
|
+
});
|
|
225
|
+
return 0;
|
|
226
|
+
}
|
|
227
|
+
async function approve(args) {
|
|
228
|
+
const marker = await linked_marker(args);
|
|
229
|
+
await approve_requests(cli_transport(marker.workspace_id), marker.vault_id, marker.vault_name);
|
|
230
|
+
return 0;
|
|
231
|
+
}
|
|
232
|
+
async function forget(args) {
|
|
233
|
+
const folder = await locate(args);
|
|
234
|
+
const marker = await read_marker(folder);
|
|
235
|
+
if (marker === null)
|
|
236
|
+
throw new CliError(`${folder} is not linked to a vault.`, "not_linked");
|
|
237
|
+
await forget_key(marker.vault_id, marker.vault_name);
|
|
238
|
+
return 0;
|
|
239
|
+
}
|
|
240
|
+
export async function vault(args) {
|
|
241
|
+
const action = args.positional[0] ?? "list";
|
|
242
|
+
if (action === "list")
|
|
243
|
+
return list(args);
|
|
244
|
+
if (action === "link")
|
|
245
|
+
return link(args);
|
|
246
|
+
if (action === "unlink")
|
|
247
|
+
return unlink(args);
|
|
248
|
+
if (action === "status" || action === "conflicts")
|
|
249
|
+
return status(args);
|
|
250
|
+
if (action === "unlock")
|
|
251
|
+
return unlock(args);
|
|
252
|
+
if (action === "approve")
|
|
253
|
+
return approve(args);
|
|
254
|
+
if (action === "forget")
|
|
255
|
+
return forget(args);
|
|
256
|
+
throw new CliError(USAGE, "invalid_arguments");
|
|
257
|
+
}
|
package/dist/device.js
CHANGED
|
@@ -3,7 +3,7 @@ import { read_credentials, read_settings, update_settings } from "./config.js";
|
|
|
3
3
|
import { list_devices, register_device } from "./context/api.js";
|
|
4
4
|
import { VERSION } from "./version.js";
|
|
5
5
|
const PLATFORMS = new Set(["darwin", "linux", "win32", "freebsd"]);
|
|
6
|
-
function device_name() {
|
|
6
|
+
export function device_name() {
|
|
7
7
|
const raw = hostname().replace(/\.local$/, "").replace(/[^\w .-]/g, "").trim();
|
|
8
8
|
return (raw.length > 0 ? raw : "This computer").slice(0, 64);
|
|
9
9
|
}
|
|
@@ -28,16 +28,22 @@ export async function ensure_device(force = false) {
|
|
|
28
28
|
});
|
|
29
29
|
return device.id;
|
|
30
30
|
}
|
|
31
|
-
export async function
|
|
31
|
+
export async function device_state() {
|
|
32
32
|
const credentials = await read_credentials();
|
|
33
33
|
const settings = await read_settings();
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const devices = await list_devices();
|
|
38
|
-
const mine = devices.find((device) => device.id === settings.device_id);
|
|
39
|
-
if (mine !== undefined && mine.revoked_at === null)
|
|
40
|
-
return mine.id;
|
|
34
|
+
const id = settings.device_id;
|
|
35
|
+
if (credentials === null || id === undefined || settings.device_api_url !== credentials.api_url) {
|
|
36
|
+
return { state: "unregistered" };
|
|
41
37
|
}
|
|
38
|
+
const devices = await list_devices();
|
|
39
|
+
const mine = devices.find((device) => device.id === id);
|
|
40
|
+
if (mine === undefined)
|
|
41
|
+
return { state: "unknown", id };
|
|
42
|
+
return { state: mine.revoked_at === null ? "active" : "revoked", id };
|
|
43
|
+
}
|
|
44
|
+
export async function verify_device() {
|
|
45
|
+
const current = await device_state();
|
|
46
|
+
if (current.state === "active")
|
|
47
|
+
return current.id;
|
|
42
48
|
return ensure_device(true);
|
|
43
49
|
}
|
package/dist/http.js
CHANGED
|
@@ -8,7 +8,7 @@ const error_body = z.object({
|
|
|
8
8
|
code: z.string().optional(),
|
|
9
9
|
reference: z.string().optional(),
|
|
10
10
|
});
|
|
11
|
-
export async function
|
|
11
|
+
export async function send(method, path, options = {}) {
|
|
12
12
|
const credentials = await fresh_credentials();
|
|
13
13
|
const settings = await read_settings();
|
|
14
14
|
const url = new URL(`${credentials.api_url}${path}`);
|
|
@@ -20,9 +20,8 @@ export async function api(method, path, schema, options = {}) {
|
|
|
20
20
|
authorization: `Bearer ${credentials.access_token}`,
|
|
21
21
|
"nemu-api-version": API_VERSION,
|
|
22
22
|
"user-agent": `nemu-cli/${VERSION}`,
|
|
23
|
+
...(options.headers ?? {}),
|
|
23
24
|
};
|
|
24
|
-
if (options.body !== undefined)
|
|
25
|
-
headers["content-type"] = "application/json";
|
|
26
25
|
const is_key = credentials.kind === "key";
|
|
27
26
|
if (!is_key &&
|
|
28
27
|
options.device !== false &&
|
|
@@ -30,34 +29,47 @@ export async function api(method, path, schema, options = {}) {
|
|
|
30
29
|
settings.device_api_url === credentials.api_url) {
|
|
31
30
|
headers["x-nemu-device"] = settings.device_id;
|
|
32
31
|
}
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
const workspace = options.workspace ?? settings.context_workspace;
|
|
33
|
+
if (!is_key && workspace !== undefined) {
|
|
34
|
+
headers["x-nemu-workspace"] = workspace;
|
|
35
35
|
}
|
|
36
|
-
let response;
|
|
37
36
|
try {
|
|
38
|
-
response = await fetch(url, {
|
|
37
|
+
const response = await fetch(url, {
|
|
39
38
|
method,
|
|
40
39
|
headers,
|
|
41
|
-
body: options.body
|
|
40
|
+
body: options.body,
|
|
42
41
|
signal: AbortSignal.timeout(options.timeout_ms ?? 20_000),
|
|
43
42
|
});
|
|
43
|
+
return { api_url: credentials.api_url, response };
|
|
44
44
|
}
|
|
45
45
|
catch {
|
|
46
46
|
throw new CliError(`Could not reach ${credentials.api_url}.`, "network_failed");
|
|
47
47
|
}
|
|
48
|
+
}
|
|
49
|
+
export async function failure_of(response) {
|
|
50
|
+
const payload = await response.json().catch(() => null);
|
|
51
|
+
const failure = error_body.safeParse(payload);
|
|
52
|
+
const message = failure.success && failure.data.error !== undefined
|
|
53
|
+
? failure.data.error
|
|
54
|
+
: `Request failed with status ${response.status}`;
|
|
55
|
+
return new CliError(message, failure.success && failure.data.code !== undefined ? failure.data.code : `http_${response.status}`, {
|
|
56
|
+
status: response.status,
|
|
57
|
+
reference: (failure.success ? failure.data.reference : undefined) ??
|
|
58
|
+
response.headers.get("x-nemu-reference") ??
|
|
59
|
+
undefined,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
export async function api(method, path, schema, options = {}) {
|
|
63
|
+
const { response } = await send(method, path, {
|
|
64
|
+
query: options.query,
|
|
65
|
+
headers: options.body !== undefined ? { "content-type": "application/json" } : {},
|
|
66
|
+
body: options.body === undefined ? undefined : JSON.stringify(options.body),
|
|
67
|
+
device: options.device,
|
|
68
|
+
timeout_ms: options.timeout_ms,
|
|
69
|
+
});
|
|
70
|
+
if (!response.ok)
|
|
71
|
+
throw await failure_of(response);
|
|
48
72
|
const payload = await response.json().catch(() => null);
|
|
49
|
-
if (!response.ok) {
|
|
50
|
-
const failure = error_body.safeParse(payload);
|
|
51
|
-
const message = failure.success && failure.data.error !== undefined
|
|
52
|
-
? failure.data.error
|
|
53
|
-
: `Request failed with status ${response.status}`;
|
|
54
|
-
throw new CliError(message, failure.success && failure.data.code !== undefined ? failure.data.code : `http_${response.status}`, {
|
|
55
|
-
status: response.status,
|
|
56
|
-
reference: (failure.success ? failure.data.reference : undefined) ??
|
|
57
|
-
response.headers.get("x-nemu-reference") ??
|
|
58
|
-
undefined,
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
73
|
const parsed = schema.safeParse(payload);
|
|
62
74
|
if (!parsed.success) {
|
|
63
75
|
throw new CliError("Nemu sent an answer this CLI does not understand. Update nemu-cli.", "invalid_response");
|
package/dist/index.js
CHANGED
|
@@ -20,6 +20,8 @@ import { send_report } from "./report.js";
|
|
|
20
20
|
import { maybe_offer_update, update_command } from "./update.js";
|
|
21
21
|
import { migrate_after_update } from "./migrations.js";
|
|
22
22
|
import { repair } from "./commands/repair.js";
|
|
23
|
+
import { vault } from "./commands/vault.js";
|
|
24
|
+
import { sync } from "./commands/sync.js";
|
|
23
25
|
import { CliError } from "./errors.js";
|
|
24
26
|
import { VERSION } from "./version.js";
|
|
25
27
|
import { bold, dim, fail, out } from "./ui.js";
|
|
@@ -57,107 +59,122 @@ const COMMANDS = {
|
|
|
57
59
|
config: config_command,
|
|
58
60
|
update: update_command,
|
|
59
61
|
repair,
|
|
62
|
+
vault,
|
|
63
|
+
sync,
|
|
60
64
|
};
|
|
61
|
-
const HELP = `
|
|
62
|
-
${bold("nemu")} ${dim(VERSION)}
|
|
63
|
-
|
|
64
|
-
${bold("Context for coding agents")}
|
|
65
|
-
setup <claude|codex> [--hooks|--no-hooks] [--yes]
|
|
66
|
-
Connect Claude Code (aliases cc, claude-code) or Codex
|
|
67
|
-
setup <cursor|vscode|gemini|windsurf|zed|opencode>
|
|
68
|
-
Add the Nemu MCP server to that editor's config
|
|
69
|
-
claude [-- <claude args>] Set up if needed, then start Claude Code
|
|
70
|
-
codex [-- <codex args>] Set up if needed, then start Codex
|
|
71
|
-
claude load memories [--all] [--yes]
|
|
72
|
-
Import Claude Code's saved memories
|
|
73
|
-
claude load sessions [--limit n] Have Claude read past sessions and save what matters
|
|
74
|
-
codex load sessions [--limit n] The same for Codex
|
|
75
|
-
mcp Run the MCP bridge (what clients start)
|
|
76
|
-
mcp config <client> Print config for cursor, gemini, vscode, windsurf,
|
|
77
|
-
zed, opencode, claude, codex or remote
|
|
78
|
-
context [load] Show what an agent sees for this folder
|
|
79
|
-
context search <words> Search this project's saved notes
|
|
80
|
-
context projects | export [--out f] List projects or export everything
|
|
81
|
-
status Sign in, device, global install, client setup
|
|
82
|
-
uninstall [client|all] Remove what setup added
|
|
83
|
-
token [--header] Print a fresh access token
|
|
84
|
-
config get | set reports on|off Error reports sent after a failure
|
|
85
|
-
update [--yes] Check for a new version and install it
|
|
86
|
-
repair Bring hooks and editor entries up to date
|
|
87
|
-
|
|
88
|
-
${bold("
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
--
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
65
|
+
const HELP = `
|
|
66
|
+
${bold("nemu")} ${dim(VERSION)}
|
|
67
|
+
|
|
68
|
+
${bold("Context for coding agents")}
|
|
69
|
+
setup <claude|codex> [--hooks|--no-hooks] [--yes]
|
|
70
|
+
Connect Claude Code (aliases cc, claude-code) or Codex
|
|
71
|
+
setup <cursor|vscode|gemini|windsurf|zed|opencode>
|
|
72
|
+
Add the Nemu MCP server to that editor's config
|
|
73
|
+
claude [-- <claude args>] Set up if needed, then start Claude Code
|
|
74
|
+
codex [-- <codex args>] Set up if needed, then start Codex
|
|
75
|
+
claude load memories [--all] [--yes]
|
|
76
|
+
Import Claude Code's saved memories
|
|
77
|
+
claude load sessions [--limit n] Have Claude read past sessions and save what matters
|
|
78
|
+
codex load sessions [--limit n] The same for Codex
|
|
79
|
+
mcp Run the MCP bridge (what clients start)
|
|
80
|
+
mcp config <client> Print config for cursor, gemini, vscode, windsurf,
|
|
81
|
+
zed, opencode, claude, codex or remote
|
|
82
|
+
context [load] Show what an agent sees for this folder
|
|
83
|
+
context search <words> Search this project's saved notes
|
|
84
|
+
context projects | export [--out f] List projects or export everything
|
|
85
|
+
status Sign in, device, global install, client setup
|
|
86
|
+
uninstall [client|all] Remove what setup added
|
|
87
|
+
token [--header] Print a fresh access token
|
|
88
|
+
config get | set reports on|off Error reports sent after a failure
|
|
89
|
+
update [--yes] Check for a new version and install it
|
|
90
|
+
repair Bring hooks and editor entries up to date
|
|
91
|
+
|
|
92
|
+
${bold("Vaults")}
|
|
93
|
+
vault list Vaults in this workspace
|
|
94
|
+
vault link <folder> [--vault <name|id>] [--create [--private]] [--obsidian]
|
|
95
|
+
Link a folder to a vault (writes <folder>/.nemu/vault.json)
|
|
96
|
+
vault unlink [folder] Stop syncing a folder; its files stay
|
|
97
|
+
vault status [folder] Last sync, settings and open conflicts
|
|
98
|
+
vault unlock [folder] Open a private vault on this computer (password, recovery key, or approval)
|
|
99
|
+
vault approve [folder] Let another device open a private vault, after comparing its code
|
|
100
|
+
vault forget [folder] Lock a private vault on this computer again
|
|
101
|
+
sync [folder] [--watch] [--dry-run] [--conflicts=merge|file] [--allow-deletes]
|
|
102
|
+
[--obsidian on|off] [--obsidian-plugins on|off]
|
|
103
|
+
Sync a linked folder with its vault
|
|
104
|
+
|
|
105
|
+
${bold("Account")}
|
|
106
|
+
login [--force] [--no-browser] Sign in with the device flow
|
|
107
|
+
login key Sign in with a workspace API key (asked for, or NEMU_API_KEY)
|
|
108
|
+
logout Delete the stored token
|
|
109
|
+
whoami Show the signed in account
|
|
110
|
+
user Full account record
|
|
111
|
+
scopes Every scope and its actions
|
|
112
|
+
|
|
113
|
+
${bold("Workspaces")}
|
|
114
|
+
workspaces list [--stats]
|
|
115
|
+
workspaces get <id>
|
|
116
|
+
workspaces create <name>
|
|
117
|
+
workspaces rename <id> <name>
|
|
118
|
+
workspaces delete <id> --yes
|
|
119
|
+
workspaces budget [id]
|
|
120
|
+
workspaces set-budget <id> <amount>
|
|
121
|
+
|
|
122
|
+
${bold("Members")}
|
|
123
|
+
members list [-w <workspace>]
|
|
124
|
+
members invite [--email a,b] [--max-uses n] [--expires-in-days n]
|
|
125
|
+
members role <member-id> <ADMIN|MEMBER>
|
|
126
|
+
members remove <member-id>
|
|
127
|
+
|
|
128
|
+
${bold("Providers")}
|
|
129
|
+
providers list [--name] [--compatibility]
|
|
130
|
+
providers get <id>
|
|
131
|
+
providers create <name> --priority 1 [--base-url] [--api-key]
|
|
132
|
+
[--compatibility OPENAI_COMPATIBLE|ANTHROPIC|OPENAI_RESPONSES]
|
|
133
|
+
providers update <id> [--name] [--priority] [--base-url] [--api-key] [--enabled]
|
|
134
|
+
providers delete <id> --yes
|
|
135
|
+
|
|
136
|
+
${bold("Models")}
|
|
137
|
+
models list [--provider <id>] [--type chat] [--name]
|
|
138
|
+
models get <id>
|
|
139
|
+
models create --name --display-name --provider <id> --type chat
|
|
140
|
+
--input-cost --output-cost --context-window
|
|
141
|
+
[--api-name] [--max-output] [--cache-read-cost] [--cache-write-cost]
|
|
142
|
+
models update <id> [--display-name] [--input-cost] [--output-cost] [--enabled]
|
|
143
|
+
models delete <id> --yes
|
|
144
|
+
|
|
145
|
+
${bold("Prompts")}
|
|
146
|
+
prompts list [--name] [--type] [--environment]
|
|
147
|
+
prompts get <id>
|
|
148
|
+
prompts create --name --content [--type SYSTEM] [--model <id>] [--position n]
|
|
149
|
+
prompts update <id> [--name] [--content] [--enabled]
|
|
150
|
+
prompts delete <id> --yes
|
|
151
|
+
|
|
152
|
+
${bold("Mappings")}
|
|
153
|
+
mappings list [--source] [--target]
|
|
154
|
+
mappings get <id>
|
|
155
|
+
mappings create --source <name> --target <model> [--priority n] [--pattern true]
|
|
156
|
+
mappings update <id> [--source] [--target] [--priority] [--enabled]
|
|
157
|
+
mappings delete <id> --yes
|
|
158
|
+
|
|
159
|
+
${bold("Read only")}
|
|
160
|
+
workflows list | get <id>
|
|
161
|
+
metrics list [--page n] [--limit n] [--key <id>] [--start <iso>] [--end <iso>]
|
|
162
|
+
metrics get <request-id>
|
|
163
|
+
indexes list | get <id> | create <url> [--max-pages n] | delete <id> --yes
|
|
164
|
+
quotas list | get <id> | update <id> [--limit n] | delete <id> --yes
|
|
165
|
+
health
|
|
166
|
+
api-version
|
|
167
|
+
|
|
168
|
+
${bold("Escape hatch")}
|
|
169
|
+
api <METHOD> <path> [--data '<json>'] Call any endpoint directly
|
|
170
|
+
|
|
171
|
+
${bold("Global")}
|
|
172
|
+
--json Machine readable output on every command
|
|
173
|
+
-w, --workspace Workspace id or name, defaults to the first
|
|
174
|
+
--version, -v Print the CLI version
|
|
175
|
+
--help, -h Print this message
|
|
176
|
+
|
|
177
|
+
${dim("Docs https://docs.nemu.cc")}
|
|
161
178
|
`;
|
|
162
179
|
function usage() {
|
|
163
180
|
out(HELP);
|