@networkbase/cli 2.1.2 → 2.1.3

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.
@@ -214,7 +214,7 @@ export const COMMANDS = [
214
214
  { group: "Tasks", name: "subtask edit", summary: "Rename a subtask", usage: "nb subtask edit <n> \"<title>\" [--task 4]", module: "work", fn: "subtaskEdit", flags: { ...TASK } },
215
215
  { group: "Tasks", name: "subtask delete", summary: "Delete a subtask (asks first)", usage: "nb subtask delete <n> [--task 4]", module: "work", fn: "subtaskDelete", flags: { ...TASK } },
216
216
  { group: "Tasks", name: "subtask move", summary: "Move a subtask to another position", usage: "nb subtask move <n> <position> [--task 4]", module: "work", fn: "subtaskMove", flags: { ...TASK } },
217
- { group: "Tasks", name: "comment add", summary: "Comment on a task", usage: "nb comment add -m \"<text>\" [--task 4] [--reply <id>] [--doc readme]", module: "tasks", fn: "commentAdd", flags: { ...TASK, ...MESSAGE, file: { type: "string", describe: "Comment on lines of a file instead: path:12 or path:12-18", valueName: "path:line" },
217
+ { group: "Tasks", name: "comment add", summary: "Comment on a task", usage: "nb comment add [task] \"<text>\" [--reply <id>] [--doc readme]", module: "tasks", fn: "commentAdd", flags: { ...TASK, ...MESSAGE, file: { type: "string", describe: "Comment on lines of a file instead: path:12 or path:12-18", valueName: "path:line" },
218
218
  reply: { type: "string", describe: "Reply to this comment (its id from nb comment list)", valueName: "id" }, doc: { type: "string", describe: "Comment on a doc instead (readme, …)", valueName: "slug" } },
219
219
  examples: ['nb comment add -m "@sam can you check this?"', 'nb comment add --reply 3f2a9c1e -m "done"', 'nb comment add --doc readme -m "Install step is out of date"'] },
220
220
  { group: "Tasks", name: "comment edit", summary: "Edit your own comment", usage: "nb comment edit <id> -m \"new text\" [--task 4]", module: "tasks", fn: "commentEdit", flags: { ...TASK, ...MESSAGE } },
@@ -92,7 +92,8 @@ export async function list(ctx) {
92
92
  const { applySavedFilter } = await import("./extras.mjs");
93
93
  applySavedFilter(ctx);
94
94
  const workspaceId = ctx.requireWorkspace();
95
- const scope = ctx.flags.all || ctx.flags.to ? "all" : "mine";
95
+ // A label or your stars pick tasks on their own, so they look at everyone's (M4b live check).
96
+ const scope = ctx.flags.all || ctx.flags.to || ctx.flags.label || ctx.flags.starred ? "all" : "mine";
96
97
  const wanted = ctx.flags.status ? new Set(String(ctx.flags.status).split(",").map((s) => s.trim())) : null;
97
98
  const limit = ctx.flags.limit ? Number(ctx.flags.limit) : 50;
98
99
  // Filters run on the server (C2), so open work never falls off a page of done tasks.
@@ -111,7 +112,7 @@ export async function list(ctx) {
111
112
  if (ctx.flags.priority) query.priority = String(ctx.flags.priority);
112
113
  if (ctx.flags.sort) query.sort = String(ctx.flags.sort);
113
114
  if (ctx.flags.label) query.label = String(ctx.flags.label).toLowerCase();
114
- if (ctx.flags.starred) { query.starred = "1"; query.scope = "all"; }
115
+ if (ctx.flags.starred) query.starred = "1";
115
116
  const { tasks } = /** @type {any} */ (await ctx.api.get("/api/v1/extension/workspace-tasks", { query }));
116
117
  let rows = tasks.filter((/** @type {any} */ t) => (wanted ? wanted.has(t.status) || (wanted.has("review") && t.reviewStatus === "pending") : true));
117
118
  const more = Math.max(0, rows.length - limit);
@@ -528,9 +529,12 @@ export async function commentAdd(ctx) {
528
529
  ctx.flags.file = `${doc.nodePath.replace(/^\//, "")}:1`;
529
530
  }
530
531
  if (ctx.flags.file) return (await import("./work.mjs")).commentOnFile(ctx);
531
- const raw = String(ctx.flags.message ?? ctx.positionals.join(" ")).trim();
532
- if (!raw) throw usage('nb comment add -m "<text>" [--task 4] [--reply <id>]');
533
- const task = await resolveTask(ctx, taskRef(ctx, undefined));
532
+ // `nb comment add 4 "looks good"`: a leading task number, when text follows it or comes with -m.
533
+ const lead = !ctx.flags.task && /^#?\d+$/.test(ctx.positionals[0] ?? "") && (ctx.flags.message !== undefined || ctx.positionals.length > 1);
534
+ const words = lead ? ctx.positionals.slice(1) : ctx.positionals;
535
+ const raw = String(ctx.flags.message ?? words.join(" ")).trim();
536
+ if (!raw) throw usage('nb comment add <task> "<text>" [--reply <id>]');
537
+ const task = await resolveTask(ctx, lead ? ctx.positionals[0].replace("#", "") : taskRef(ctx, undefined));
534
538
  const text = await withMentions(ctx, raw);
535
539
  const replyTo = ctx.flags.reply ? commentIdOf(task, String(ctx.flags.reply)) : null;
536
540
  await ctx.api.post("/api/v1/extension/comments", { kind: "task", projectId: ctx.requireWorkspace(), taskId: task.id, text, ...(replyTo ? { replyTo } : {}) });
@@ -566,18 +570,21 @@ function commentIdOf(task, ref) {
566
570
  async function ownComment(ctx, what) {
567
571
  const ref = ctx.positionals[0];
568
572
  if (!ref) throw usage(what === "edit" ? 'nb comment edit <id> -m "new text" [--task 4]' : "nb comment delete <id> [--task 4]", "The ids are in nb comment list");
569
- const task = await resolveTask(ctx, taskRef(ctx, undefined));
570
- const commentId = commentIdOf(task, ref);
573
+ // A full id is enough on its own; the short one from nb comment list is found on the task.
574
+ const full = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(ref) && !ctx.flags.task;
575
+ if (!full && !ctx.flags.task && !ctx.project?.startedTask && !branchTask(ctx.root)) throw usage(`Which task is comment ${ref} on? Add --task <n>`, "Or pass the full comment id from nb comment list --json");
576
+ const task = full ? null : await resolveTask(ctx, taskRef(ctx, undefined));
577
+ const commentId = task ? commentIdOf(task, ref) : ref;
571
578
  if (what === "edit") {
572
579
  const raw = String(ctx.flags.message ?? ctx.positionals.slice(1).join(" ")).trim();
573
580
  if (!raw) throw usage('nb comment edit <id> -m "new text"');
574
581
  await ctx.api.patch("/api/v1/extension/comments", { projectId: ctx.requireWorkspace(), commentId, text: await withMentions(ctx, raw) });
575
582
  } else {
576
583
  const { confirm } = await import("../tui/ask.mjs");
577
- if (!(await confirm(ctx, { key: "delete", question: `Delete your comment ${ref} on #${task.taskNumber}?`, yesLabel: "Delete", defaultYes: false }))) return 130;
584
+ if (!(await confirm(ctx, { key: "delete", question: `Delete your comment ${ref}${task ? ` on #${task.taskNumber}` : ""}?`, yesLabel: "Delete", defaultYes: false }))) return 130;
578
585
  await ctx.api.request("DELETE", "/api/v1/extension/comments", { body: { projectId: ctx.requireWorkspace(), commentId } });
579
586
  }
580
- ctx.out.result(`nb.comment.${what}/1`, { number: task.taskNumber, commentId }, (d) => `${ctx.out.c.success(ctx.out.sym.done)} ${what === "edit" ? "Edited" : "Deleted"} your comment on #${d.number}`);
587
+ ctx.out.result(`nb.comment.${what}/1`, { number: task?.taskNumber ?? null, commentId }, (d) => `${ctx.out.c.success(ctx.out.sym.done)} ${what === "edit" ? "Edited" : "Deleted"} your comment${d.number ? ` on #${d.number}` : ""}`);
581
588
  }
582
589
  /** @param {Context} ctx */
583
590
  export const commentEdit = (ctx) => ownComment(ctx, "edit");
@@ -19,9 +19,10 @@ export async function undo(ctx) {
19
19
  const recent = log.slice().reverse().slice(0, 20);
20
20
  const summaries = await Promise.all(recent.map((e) => ctx.api.get(`/api/v1/undo/${encodeURIComponent(e.token)}`).then((/** @type {any} */ r) => String(r.summary), () => null)));
21
21
  const changes = recent.map((e, i) => ({ n: i + 1, token: e.token, at: new Date(e.at).toISOString(), what: summaries[i] ?? WHAT[e.path] ?? e.path, available: summaries[i] !== null }));
22
+ const { formatWhen } = await import("./tasks.mjs");
22
23
  return ctx.out.result("nb.undo.list/1", { changes }, (d) =>
23
24
  d.changes.length
24
- ? [...d.changes.map((c) => ` ${String(c.n).padStart(2)}. ${ctx.out.c.muted(c.at.slice(11, 16))} ${safe(c.what)}${c.available ? "" : ctx.out.c.muted(" (can't be undone any more)")}`), ctx.out.c.muted(" nb undo <n> undoes that one")]
25
+ ? [...d.changes.map((c) => ` ${String(c.n).padStart(2)}. ${ctx.out.c.muted(formatWhen(c.at).padEnd(10))} ${safe(c.what)}${c.available ? "" : ctx.out.c.muted(" (can't be undone any more)")}`), ctx.out.c.muted(" nb undo <n> undoes that one")]
25
26
  : "Nothing to undo from the last 24 hours");
26
27
  }
27
28
  if (ctx.flags.session) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@networkbase/cli",
3
- "version": "2.1.2",
3
+ "version": "2.1.3",
4
4
  "description": "NetworkBase in your terminal: sync files, work on tasks, edit docs",
5
5
  "type": "module",
6
6
  "homepage": "https://networkbase.in",