@networkbase/cli 2.0.4 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/nb.mjs +6 -1
- package/lib/args.mjs +37 -17
- package/lib/commands/account.mjs +15 -4
- package/lib/commands/browse.mjs +24 -2
- package/lib/commands/extras.mjs +1 -1
- package/lib/commands/files.mjs +73 -5
- package/lib/commands/inbox.mjs +33 -1
- package/lib/commands/link.mjs +33 -1
- package/lib/commands/misc.mjs +72 -13
- package/lib/commands/table.mjs +37 -10
- package/lib/commands/tasks.mjs +164 -22
- package/lib/commands/undo.mjs +1 -1
- package/lib/commands/work.mjs +55 -18
- package/lib/config.mjs +1 -1
- package/lib/context.mjs +7 -0
- package/lib/dates.mjs +47 -0
- package/lib/error-fixes.mjs +60 -0
- package/lib/mcp/tools.mjs +40 -21
- package/lib/print/notices.mjs +6 -0
- package/lib/print/out.mjs +4 -2
- package/lib/print/style.mjs +2 -0
- package/lib/sync/queue.mjs +1 -1
- package/package.json +1 -1
package/lib/dates.mjs
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// Natural dates for --due and friends (report C2): "today", "tomorrow", "friday", "next week", "in 3 days",
|
|
2
|
+
// "2026-12-01". Read in the person's own time zone; the result is a calendar date (YYYY-MM-DD).
|
|
3
|
+
|
|
4
|
+
const DAYS = ["sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"];
|
|
5
|
+
const iso = (/** @type {Date} */ d) => `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}-${String(d.getDate()).padStart(2, "0")}`;
|
|
6
|
+
const plus = (/** @type {Date} */ d, /** @type {number} */ days) => new Date(d.getFullYear(), d.getMonth(), d.getDate() + days);
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A calendar date for words people type, or null when it isn't one.
|
|
10
|
+
* @param {string} text @param {Date} [now]
|
|
11
|
+
*/
|
|
12
|
+
export function parseDate(text, now = new Date()) {
|
|
13
|
+
const t = String(text ?? "").trim().toLowerCase().replace(/\s+/g, " ");
|
|
14
|
+
if (!t) return null;
|
|
15
|
+
if (/^\d{4}-\d{2}-\d{2}$/.test(t)) {
|
|
16
|
+
const [y, m, d] = t.split("-").map(Number);
|
|
17
|
+
const date = new Date(y, m - 1, d);
|
|
18
|
+
return date.getMonth() === m - 1 && date.getDate() === d ? t : null;
|
|
19
|
+
}
|
|
20
|
+
if (t === "today" || t === "eod") return iso(now);
|
|
21
|
+
if (t === "tomorrow" || t === "tmrw") return iso(plus(now, 1));
|
|
22
|
+
if (t === "next week") return iso(plus(now, ((8 - now.getDay()) % 7) || 7));
|
|
23
|
+
const inN = /^in (\d{1,3}) (day|days|week|weeks)$/.exec(t);
|
|
24
|
+
if (inN) return iso(plus(now, Number(inN[1]) * (inN[2].startsWith("week") ? 7 : 1)));
|
|
25
|
+
const day = DAYS.findIndex((d) => d === t.replace(/^(next |this )/, "") || d.slice(0, 3) === t.replace(/^(next |this )/, ""));
|
|
26
|
+
if (day >= 0) {
|
|
27
|
+
// "friday" is the coming one (today counts only as "this friday"); "next friday" is the one after.
|
|
28
|
+
const ahead = (day - now.getDay() + 7) % 7;
|
|
29
|
+
const base = t.startsWith("this ") ? ahead : ahead || 7;
|
|
30
|
+
return iso(plus(now, t.startsWith("next ") && ahead !== 0 ? base + 7 : base));
|
|
31
|
+
}
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* `--due today|week|overdue` (or a date) as the instants the server filters on, in the person's own day (C2).
|
|
37
|
+
* @param {string} word @param {Date} [now] @returns {{ after?: string, before?: string } | null}
|
|
38
|
+
*/
|
|
39
|
+
export function dueRange(word, now = new Date()) {
|
|
40
|
+
const w = String(word ?? "").trim().toLowerCase();
|
|
41
|
+
if (w === "overdue") return { before: now.toISOString() };
|
|
42
|
+
if (w === "week") return { after: now.toISOString(), before: new Date(now.getTime() + 7 * 86_400_000).toISOString() };
|
|
43
|
+
const date = parseDate(w === "today" ? "today" : w, now);
|
|
44
|
+
if (!date) return null;
|
|
45
|
+
const [y, m, d] = date.split("-").map(Number);
|
|
46
|
+
return { after: new Date(y, m - 1, d).toISOString(), before: new Date(y, m - 1, d + 1).toISOString() };
|
|
47
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// Generated by scripts/api/export-schemas.ts from src/lib/api/errors.ts. Do not edit.
|
|
2
|
+
/** Each error code's next step (report C5); every code here has an entry on /docs/cli. */
|
|
3
|
+
export const FIXES = /** @type {Record<string, string>} */ ({
|
|
4
|
+
"BAD_REQUEST": "Check the command's flags; nb help <command>",
|
|
5
|
+
"VALIDATION": "Fix the value named in the message",
|
|
6
|
+
"UNAUTHORIZED": "nb login",
|
|
7
|
+
"FORBIDDEN": "Check you're a member of the workspace: nb whoami",
|
|
8
|
+
"SCOPE_MISSING": "Sign in again with nb login, or make a token with more access in Settings",
|
|
9
|
+
"ACCESS_REQUESTED": "Tell the person; once they answer, try the same request again",
|
|
10
|
+
"ACCESS_DENIED_BY_PERSON": "Leave it to the person for now",
|
|
11
|
+
"WORKSPACE_NOT_ALLOWED": "Use the folder linked to that workspace, or approve a new agent sign-in",
|
|
12
|
+
"AGENT_NOT_ALLOWED": "Do this one yourself, or ask the organization's admins",
|
|
13
|
+
"AGENTS_PAUSED": "Turn agents back on in workspace settings",
|
|
14
|
+
"STEP_UP_REQUIRED": "Confirm it in the browser, then try again",
|
|
15
|
+
"NOT_FOUND": "Check the number or path: nb task list, nb file list",
|
|
16
|
+
"EXPIRED": "Start again",
|
|
17
|
+
"CONFLICT": "Look at it again, then retry",
|
|
18
|
+
"VERSION_CONFLICT": "nb pull, then push again, or nb resolve <path>",
|
|
19
|
+
"TASK_CHANGED": "nb task view <n>, then retry",
|
|
20
|
+
"FILE_LOCKED": "Wait for them to finish, or ask them",
|
|
21
|
+
"CLIENT_TOO_OLD": "npm i -g @networkbase/cli@latest",
|
|
22
|
+
"NEEDS_CONFIRMATION": "Show the summary; on a yes, send the same request with the confirm token (--confirm)",
|
|
23
|
+
"SECRET_DETECTED": "Remove it, or push with --confirm-secrets if it's safe (agents can't)",
|
|
24
|
+
"CONTENT_MISMATCH": "Run the command again",
|
|
25
|
+
"CONTENT_HASH_MISMATCH": "Run the command again",
|
|
26
|
+
"RATE_LIMITED": "Wait for the time in Retry-After",
|
|
27
|
+
"NOT_SUPPORTED": "Use the app for now",
|
|
28
|
+
"UNAVAILABLE": "Try again in a minute",
|
|
29
|
+
"INTERNAL_ERROR": "Try again; if it keeps happening, nb feedback",
|
|
30
|
+
"USAGE": "nb <command> --help shows what it takes",
|
|
31
|
+
"UNKNOWN_COMMAND": "nb help lists them; the error suggests the closest one",
|
|
32
|
+
"UNKNOWN_FLAG": "nb <command> --help lists its flags",
|
|
33
|
+
"NOT_SIGNED_IN": "nb login",
|
|
34
|
+
"NOT_LINKED": "nb init <workspace>, or pass --workspace",
|
|
35
|
+
"WORKSPACE_NOT_FOUND": "nb workspace list",
|
|
36
|
+
"TASK_NOT_FOUND": "nb task list --all",
|
|
37
|
+
"DOC_NOT_FOUND": "nb doc list",
|
|
38
|
+
"NOT_A_TASK": "nb inbox open <n>",
|
|
39
|
+
"NOTHING_TO_APPROVE": "nb inbox open <n>",
|
|
40
|
+
"NEEDS_INPUT": "Answer with --answer key=value, or --yes for the recommended choice",
|
|
41
|
+
"CANCELLED": "Run the command again when ready",
|
|
42
|
+
"OFFLINE": "nb doctor checks the connection; nb sync sends the queue",
|
|
43
|
+
"TIMEOUT": "Try again; nb doctor checks the connection",
|
|
44
|
+
"SERVER_ERROR": "Try again in a minute; nb doctor checks the connection",
|
|
45
|
+
"UNEXPECTED_RESPONSE": "Update: npm i -g @networkbase/cli@latest",
|
|
46
|
+
"LOCAL_CONFLICT": "nb resolve <path> --mine|--theirs|--both",
|
|
47
|
+
"READ_ONLY": "Ask the owner for edit access",
|
|
48
|
+
"PLAN_LIMIT_FILE_SIZE": "Make it smaller, or see the limits in Settings → Plan",
|
|
49
|
+
"LOCKED": "Wait for it to finish, then run this again",
|
|
50
|
+
"UNSAFE_PATH": "Rename the file in the app, then nb pull",
|
|
51
|
+
"RESERVED_NAME": "Rename the file in the app, then nb pull",
|
|
52
|
+
"CORRUPT_STATE": "nb doctor; relinking with nb init keeps your files",
|
|
53
|
+
"CORRUPT_DOWNLOAD": "Run nb pull again",
|
|
54
|
+
"UPLOAD_FAILED": "Run nb push again; it picks up where it stopped",
|
|
55
|
+
"CONFIRMATION_INVALID": "Run the command without --confirm to get a new one",
|
|
56
|
+
"GIT_FAILED": "Run the git command yourself to see why",
|
|
57
|
+
"EDITOR_FAILED": "Set your editor: export EDITOR=nano",
|
|
58
|
+
"UNKNOWN_TOOL": "Restart the agent so it reads the current tool list",
|
|
59
|
+
"INTERNAL": "If it keeps happening, tell us: nb feedback"
|
|
60
|
+
});
|
package/lib/mcp/tools.mjs
CHANGED
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
// in-process, so agents get the same checks, conflicts and errors as people. Questions come back as needs_input;
|
|
3
3
|
// anything that needs a person's yes comes back as needs_confirmation with a one-time token.
|
|
4
4
|
import crypto from "node:crypto";
|
|
5
|
+
import path from "node:path";
|
|
5
6
|
|
|
6
7
|
import { COMMANDS } from "../commands/table.mjs";
|
|
8
|
+
import { currentProfile, globalDir, readJson, writeAtomic } from "../config.mjs";
|
|
7
9
|
import { createContext } from "../context.mjs";
|
|
8
10
|
import { CliError } from "../errors.mjs";
|
|
9
11
|
|
|
@@ -67,7 +69,7 @@ export const TOOLS = [
|
|
|
67
69
|
return pick(rank(r.data.workspaces, a.query, (w) => [w.slug, w.id], (w) => w.title), "workspace", (w) => `${w.title} (${w.slug})`, (w) => w.slug);
|
|
68
70
|
} },
|
|
69
71
|
{ name: "networkbase_task_count", title: "Count my tasks", tier: "read", props: {},
|
|
70
|
-
description: `Count the user's open NetworkBase tasks by status
|
|
72
|
+
description: `Count the user's open NetworkBase tasks across all their workspaces, by status and per workspace. Use for "how many tasks do I have". The totals are for every workspace, not only this folder's: say which workspace each overdue task is in (data.workspaces).`,
|
|
71
73
|
run: (nb) => nb("task count") },
|
|
72
74
|
{ name: "networkbase_task_list", title: "List tasks", tier: "read",
|
|
73
75
|
props: { workspace: workspaceProp, all: { type: "boolean", description: "Include tasks assigned to others" }, status: { type: "string", description: "Comma list of todo, in_progress, blocked, review, done" }, limit: { type: "number", description: "At most this many (default 50)" } },
|
|
@@ -222,28 +224,45 @@ export const TOOLS = [
|
|
|
222
224
|
];
|
|
223
225
|
|
|
224
226
|
/**
|
|
225
|
-
*
|
|
226
|
-
*
|
|
227
|
+
* Local yes tokens (report D24): signed like the server's (HMAC, 10 minutes, bound to the tool and its exact
|
|
228
|
+
* arguments, used once), with a key made from this computer's sign-in. Any nb process signed in the same way can
|
|
229
|
+
* check one, so a headless agent (`claude -p --continue`, CI) that starts a new MCP server each turn can still
|
|
230
|
+
* confirm. No "." in them: a dotted token is the server's and goes to the server.
|
|
227
231
|
*/
|
|
228
|
-
const confirmations = new Map();
|
|
229
232
|
/** @param {string} name @param {any} args */
|
|
230
233
|
const fingerprint = (name, args) => {
|
|
231
234
|
const { confirmToken: _t, answers: _a, ...rest } = args ?? {};
|
|
232
235
|
return crypto.createHash("sha256").update(`${name}\n${JSON.stringify(rest, Object.keys(rest).sort())}`).digest("hex");
|
|
233
236
|
};
|
|
234
|
-
/**
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
237
|
+
/** Without a saved sign-in there is nothing to share, so the key stays in this process. */
|
|
238
|
+
const processKey = crypto.randomBytes(32).toString("hex");
|
|
239
|
+
/** @param {NodeJS.ProcessEnv} env */
|
|
240
|
+
const yesKey = (env) => crypto.createHash("sha256").update(`nb-local-yes\n${currentProfile({ flags: {}, env, project: null }).token ?? processKey}`).digest();
|
|
241
|
+
/** @param {NodeJS.ProcessEnv} env @param {string} print @param {string} expires @param {string} nonce */
|
|
242
|
+
const yesMac = (env, print, expires, nonce) => crypto.createHmac("sha256", yesKey(env)).update(`${print}|${expires}|${nonce}`).digest("hex").slice(0, 32);
|
|
243
|
+
/** @param {string} name @param {any} args @param {NodeJS.ProcessEnv} env */
|
|
244
|
+
function issueConfirmation(name, args, env) {
|
|
245
|
+
const expires = (Date.now() + 10 * 60_000).toString(36);
|
|
246
|
+
const nonce = crypto.randomBytes(9).toString("hex");
|
|
247
|
+
return `y_${expires}_${nonce}_${yesMac(env, fingerprint(name, args), expires, nonce)}`;
|
|
239
248
|
}
|
|
240
|
-
/** @param {string} name @param {any} args */
|
|
241
|
-
function takeConfirmation(name, args) {
|
|
249
|
+
/** @param {string} name @param {any} args @param {NodeJS.ProcessEnv} env */
|
|
250
|
+
function takeConfirmation(name, args, env) {
|
|
242
251
|
const token = args?.confirmToken;
|
|
243
252
|
if (!token) return false;
|
|
244
|
-
const
|
|
245
|
-
|
|
246
|
-
if (!
|
|
253
|
+
const invalid = () => new CliError("CONFIRMATION_INVALID", "That confirmToken doesn't match this call or has expired", { hint: "Call again without confirmToken to get a new one, and show it to the user" });
|
|
254
|
+
const [, expires = "", nonce = "", mac = ""] = /^y_([0-9a-z]+)_([0-9a-f]{18})_([0-9a-f]{32})$/.exec(String(token)) ?? [];
|
|
255
|
+
if (!mac || parseInt(expires, 36) < Date.now()) throw invalid();
|
|
256
|
+
const want = yesMac(env, fingerprint(name, args), expires, nonce);
|
|
257
|
+
if (!crypto.timingSafeEqual(Buffer.from(want), Buffer.from(mac))) throw invalid();
|
|
258
|
+
// Once only, across processes: used nonces are kept until they'd have expired anyway.
|
|
259
|
+
const file = path.join(globalDir(env), "used-yes.json");
|
|
260
|
+
/** @type {Record<string, number>} */
|
|
261
|
+
let used = {};
|
|
262
|
+
try { used = readJson(file) ?? {}; } catch { used = {}; }
|
|
263
|
+
if (used[nonce]) throw invalid();
|
|
264
|
+
const now = Date.now();
|
|
265
|
+
try { writeAtomic(file, JSON.stringify(Object.fromEntries([...Object.entries(used).filter(([, until]) => until > now), [nonce, parseInt(expires, 36)]]))); } catch { /* read-only home: once per process at least */ }
|
|
247
266
|
return true;
|
|
248
267
|
}
|
|
249
268
|
|
|
@@ -276,11 +295,11 @@ export async function callTool(name, args = {}, where) {
|
|
|
276
295
|
try {
|
|
277
296
|
// A server-issued yes (signed, contains a dot) goes to the server as X-NB-Confirm; it decides.
|
|
278
297
|
const serverYes = typeof args.confirmToken === "string" && args.confirmToken.includes(".") ? args.confirmToken : null;
|
|
279
|
-
const confirmed = serverYes ? false : takeConfirmation(name, args);
|
|
298
|
+
const confirmed = serverYes ? false : takeConfirmation(name, args, where.env);
|
|
280
299
|
// With an agent token the server holds big changes itself (report §26.6), so asking here too would ask twice.
|
|
281
300
|
const agentToken = String(createContext({ flags: {}, positionals: [], cwd: where.cwd, env: where.env, io: { stdout: /** @type {any} */ ({ write: () => true }), stderr: process.stderr } }).profile.token ?? "").startsWith("nb_agt_");
|
|
282
301
|
const summary = !confirmed && !serverYes && !agentToken && tool.needsYes ? tool.needsYes(args) : null;
|
|
283
|
-
if (summary) return confirmationResult(name, args, summary, undefined);
|
|
302
|
+
if (summary) return confirmationResult(name, args, summary, undefined, where.env);
|
|
284
303
|
const answers = Object.entries(args.answers ?? {}).map(([k, v]) => `${k}=${v}`);
|
|
285
304
|
const nb = executor(where, { ...(confirmed || serverYes ? { yes: true } : {}), ...(serverYes ? { confirm: serverYes } : {}), ...(answers.length ? { answer: answers } : {}) });
|
|
286
305
|
const r = await tool.run(nb, args);
|
|
@@ -294,7 +313,7 @@ export async function callTool(name, args = {}, where) {
|
|
|
294
313
|
structuredContent: { status: "needs_confirmation", summary: held.summary ?? "this change needs a yes", ...(held.preview ? { preview: held.preview } : {}), confirmToken: held.confirmToken, by: "server" },
|
|
295
314
|
};
|
|
296
315
|
}
|
|
297
|
-
if (error instanceof CliError && error.code === "NEEDS_CONFIRMATION") return confirmationResult(name, args, error.message, /** @type {any} */ (error.details)?.questions?.[0]?.preview);
|
|
316
|
+
if (error instanceof CliError && error.code === "NEEDS_CONFIRMATION") return confirmationResult(name, args, error.message, /** @type {any} */ (error.details)?.questions?.[0]?.preview, where.env);
|
|
298
317
|
if (error instanceof CliError && error.code === "NEEDS_INPUT") {
|
|
299
318
|
const questions = /** @type {any} */ (error.details)?.questions ?? [];
|
|
300
319
|
const lines = questions.map((/** @type {any} */ q) => `${q.question} (answers.${q.key}: ${q.options.map((/** @type {any} */ o) => `${o.value}${o.recommended ? " [recommended]" : ""}`).join(" | ")})`);
|
|
@@ -321,7 +340,7 @@ export async function callTool(name, args = {}, where) {
|
|
|
321
340
|
}
|
|
322
341
|
|
|
323
342
|
/** Permissions in the words the approval page uses (report A2). */
|
|
324
|
-
const SCOPE_WORDS = /** @type {Record<string, string>} */ ({ "task:complete": "finish tasks", "file:final": "change final files", "doc:write": "edit docs", "task:review": "approve or return reviews" });
|
|
343
|
+
const SCOPE_WORDS = /** @type {Record<string, string>} */ ({ "task:complete": "finish tasks", "file:final": "change final files", "doc:write": "edit docs", "task:write": "change tasks", "file:write": "save files", "task:review": "approve or return reviews" });
|
|
325
344
|
/** Tools whose main job needs a permission an agent preset may leave out. */
|
|
326
345
|
const NEEDS_SCOPE = /** @type {Record<string, string>} */ ({ networkbase_task_done: "task:complete", networkbase_doc_update: "doc:write" });
|
|
327
346
|
|
|
@@ -352,9 +371,9 @@ export function accessCard(a) {
|
|
|
352
371
|
].join("\n");
|
|
353
372
|
}
|
|
354
373
|
|
|
355
|
-
/** @param {string} name @param {any} args @param {string} summary @param {string | undefined} preview */
|
|
356
|
-
function confirmationResult(name, args, summary, preview) {
|
|
357
|
-
const confirmToken = issueConfirmation(name, args);
|
|
374
|
+
/** @param {string} name @param {any} args @param {string} summary @param {string | undefined} preview @param {NodeJS.ProcessEnv} env */
|
|
375
|
+
function confirmationResult(name, args, summary, preview, env) {
|
|
376
|
+
const confirmToken = issueConfirmation(name, args, env);
|
|
358
377
|
return {
|
|
359
378
|
content: [{ type: "text", text: `needs_confirmation: ${summary}${preview ? `\n\n${preview}` : ""}\n\nShow this to the user. Only if they agree, call ${name} again with the same arguments and confirmToken "${confirmToken}".` }],
|
|
360
379
|
structuredContent: { status: "needs_confirmation", summary, ...(preview ? { preview } : {}), confirmToken },
|
package/lib/print/notices.mjs
CHANGED
|
@@ -22,6 +22,12 @@ export function newer(a, b) {
|
|
|
22
22
|
|
|
23
23
|
/** @param {import("../context.mjs").Context} ctx */
|
|
24
24
|
export async function afterCommand(ctx) {
|
|
25
|
+
// 7 days before this computer's sign-in ends, once a day (C6); nb login renews the same sign-in.
|
|
26
|
+
const ends = ctx.profile.profile?.source === "file" ? Date.parse(ctx.profile.profile.expiresAt ?? "") : NaN;
|
|
27
|
+
if (ends > Date.now() && ends - Date.now() < 7 * DAY) {
|
|
28
|
+
const { remindOnce } = await import("./remind.mjs");
|
|
29
|
+
remindOnce(ctx, "sign-in-ends", `Your sign-in on this computer ends ${new Date(ends).toLocaleDateString("en-GB", { day: "numeric", month: "short" })}: nb login renews it`);
|
|
30
|
+
}
|
|
25
31
|
if (ctx.out.json || ctx.flags.quiet || ctx.env.CI || ctx.env.NB_NO_UPDATE_CHECK || !process.stderr.isTTY) return;
|
|
26
32
|
const file = path.join(globalDir(ctx.env), "update.json");
|
|
27
33
|
/** @type {{ lastRun?: string, checkedAt?: number, latest?: string }} */
|
package/lib/print/out.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// The only place the CLI writes to the terminal (report A4.5, A4.7, A4.8, A13.1). stdout carries results
|
|
2
2
|
// (text or one JSON envelope); stderr carries progress, hints, warnings and prompts.
|
|
3
|
+
import { FIXES } from "../error-fixes.mjs";
|
|
3
4
|
import { spawnSync } from "node:child_process";
|
|
4
5
|
|
|
5
6
|
import { colorLevel, palette, pad, safe, symbols, truncateEnd, truncateMiddle, asciiOnly, width, hyperlinks } from "./style.mjs";
|
|
@@ -92,8 +93,9 @@ export function createOutput(mode, io = {}) {
|
|
|
92
93
|
},
|
|
93
94
|
/** @param {import("../errors.mjs").CliError} error */
|
|
94
95
|
error(error) {
|
|
95
|
-
//
|
|
96
|
-
const docs = error.
|
|
96
|
+
// Every catalogued code links to its entry on /docs/cli (report A2.6, C5), and ends with a next step.
|
|
97
|
+
const docs = FIXES[error.code] && error.code !== "CANCELLED" ? `https://networkbase.in/docs/cli#error-${error.code}` : null;
|
|
98
|
+
if (!error.hint && FIXES[error.code] && error.code !== "CANCELLED") error.hint = FIXES[error.code];
|
|
97
99
|
if (json) {
|
|
98
100
|
const body = { ok: false, error: { code: error.code, message: error.message, ...(error.hint ? { hint: error.hint } : {}), ...(error.details !== undefined ? { details: error.details } : {}), ...(docs ? { docs } : {}) } };
|
|
99
101
|
stdout.write(`${JSON.stringify(body)}\n`);
|
package/lib/print/style.mjs
CHANGED
|
@@ -63,6 +63,8 @@ export function symbols(ascii) {
|
|
|
63
63
|
const CONTROL = /[\u0000-\u0008\u000b-\u001f\u007f-\u009f]/g;
|
|
64
64
|
/** @param {unknown} value */
|
|
65
65
|
export const safe = (value) => String(value ?? "").replace(CONTROL, "");
|
|
66
|
+
/** Comment text as people read it: the stored mention `@{id|Rama}` reads `@Rama` (found live in M4a). @param {unknown} value */
|
|
67
|
+
export const commentText = (value) => safe(value).replace(/@\{[^|}]+\|([^}]+)\}/g, "@$1");
|
|
66
68
|
|
|
67
69
|
|
|
68
70
|
const ANSI = /\x1b\[[0-9;?]*[A-Za-z]|\x1b\][^\x07\x1b]*(?:\x07|\x1b\\)/g;
|
package/lib/sync/queue.mjs
CHANGED
|
@@ -7,7 +7,7 @@ import { DIR_NAME, readJson, writeAtomic } from "../config.mjs";
|
|
|
7
7
|
|
|
8
8
|
export const QUEUE_TTL_MS = 7 * 24 * 60 * 60 * 1000;
|
|
9
9
|
|
|
10
|
-
/** @typedef {{ id: string, op: "push", paths: string[], flags: Record<string, any>, queuedAt: string }} QueueEntry */
|
|
10
|
+
/** @typedef {{ id: string, op: "push", paths: string[], flags: Record<string, any>, queuedAt: string, reason?: string }} QueueEntry */
|
|
11
11
|
|
|
12
12
|
/** @param {string} root */
|
|
13
13
|
const file = (root) => path.join(root, DIR_NAME, "queue.json");
|