@networkbase/cli 2.0.4 → 2.1.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/bin/nb.mjs +6 -1
- package/lib/args.mjs +37 -17
- package/lib/commands/account.mjs +15 -4
- package/lib/commands/browse.mjs +19 -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 +36 -9
- package/lib/commands/tasks.mjs +162 -20
- package/lib/commands/undo.mjs +1 -1
- package/lib/commands/work.mjs +53 -16
- 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/sync/queue.mjs +1 -1
- package/package.json +1 -1
package/lib/commands/table.mjs
CHANGED
|
@@ -35,6 +35,11 @@ const FILTERS = {
|
|
|
35
35
|
all: { type: "boolean", describe: "Include tasks assigned to others" },
|
|
36
36
|
status: { type: "string", describe: "todo,in_progress,blocked,review,done", valueName: "list" },
|
|
37
37
|
limit: { type: "string", describe: "At most this many", valueName: "n" },
|
|
38
|
+
due: { type: "string", describe: "today, week, overdue, or a date", valueName: "when" },
|
|
39
|
+
to: { type: "string", describe: "Assigned to @username, me or none (looks at everyone's tasks)", valueName: "person" },
|
|
40
|
+
sprint: { type: "string", describe: "A sprint name, current, or id", valueName: "sprint" },
|
|
41
|
+
priority: { type: "string", describe: "low,medium,high,urgent", valueName: "list" },
|
|
42
|
+
sort: { type: "string", describe: "due, priority or updated (default)", valueName: "by" },
|
|
38
43
|
};
|
|
39
44
|
/** 1.x status flags: still accepted so old scripts run, never shown (P2.9). @type {Record<string, FlagSpec>} */
|
|
40
45
|
const OLD_STATUS = {
|
|
@@ -69,6 +74,7 @@ export const COMMANDS = [
|
|
|
69
74
|
flags: { repair: { type: "boolean", describe: "Fix what can be fixed (lock, temp files)" } } },
|
|
70
75
|
{ group: "Account and setup", name: "open", summary: "Open the workspace, a task or a file in the browser", usage: "nb open [task|path]", module: "misc", fn: "open" },
|
|
71
76
|
{ group: "Account and setup", name: "version", summary: "CLI, Node and server versions", usage: "nb version", module: "misc", fn: "version" },
|
|
77
|
+
{ group: "Account and setup", name: "home", hidden: true, summary: "Where you are and what to do next", usage: "nb", module: "misc", fn: "home", exit: [0, 3, 4, 8] },
|
|
72
78
|
{ group: "Account and setup", name: "help", summary: "Help for a command", usage: "nb help [command]", module: "misc", fn: "help" },
|
|
73
79
|
{ group: "Account and setup", name: "completion", summary: "Shell completion script", usage: "nb completion zsh|bash|fish|powershell", module: "misc", fn: "completion" },
|
|
74
80
|
{ group: "Account and setup", name: "setup shell", summary: "Add completions to your shell (asks first)", usage: "nb setup shell [zsh|bash|fish|powershell]", module: "misc", fn: "setupShell" },
|
|
@@ -89,9 +95,13 @@ export const COMMANDS = [
|
|
|
89
95
|
"keep-both": { type: "boolean", describe: "A changed file whose name is taken goes in as name (2).ext" },
|
|
90
96
|
force: { type: "boolean", describe: "Replace a newer server version after a conflict (asks first)" },
|
|
91
97
|
recreate: { type: "boolean", describe: "Upload again files that were deleted on the server but you still have" },
|
|
98
|
+
"no-task": { type: "boolean", describe: "Don't link these files to the task you started" },
|
|
92
99
|
"from-git": { type: "boolean", describe: "Push what the last git commit changed (its NetworkBase-Task trailer picks the task)" },
|
|
93
100
|
"confirm-secrets": { type: "boolean", describe: "Upload even though a file looks like it holds a password or key" } },
|
|
94
101
|
examples: ["nb push src/app.ts -m \"Fix login\"", "nb push report.pdf --task 4 --as final", "nb push shots/ --task 5 --as reference"], exit: [0, 2, 4, 5, 7, 8] },
|
|
102
|
+
{ group: "Files", name: "queue", summary: "Pushes waiting to send while offline: what, since when, why", usage: "nb queue", module: "files", fn: "queue" },
|
|
103
|
+
{ group: "Files", name: "queue retry", summary: "Send the queued pushes now", usage: "nb queue retry", module: "files", fn: "queueRetry", exit: [0, 4, 8] },
|
|
104
|
+
{ group: "Files", name: "queue drop", summary: "Forget queued pushes (your files stay as they are)", usage: "nb queue drop <n…> | --all", module: "files", fn: "queueDrop", flags: { all: { type: "boolean", describe: "Every queued push" } } },
|
|
95
105
|
{ group: "Files", name: "sync", summary: "Pull, then push changed tracked files", usage: "nb sync", module: "files", fn: "sync", flags: { ...MESSAGE, ...OLD_STATUS }, exit: [0, 4, 8] },
|
|
96
106
|
{ group: "Files", name: "resolve", summary: "Settle a conflict", usage: "nb resolve <path> --mine|--theirs|--both", module: "resolve", fn: "resolve",
|
|
97
107
|
flags: { mine: { type: "boolean", describe: "Keep yours and push it" }, theirs: { type: "boolean", describe: "Take the server's version" }, both: { type: "boolean", describe: "Keep both as separate files" } } },
|
|
@@ -101,9 +111,12 @@ export const COMMANDS = [
|
|
|
101
111
|
flags: { unread: { type: "boolean", describe: "Only unread" }, follow: { type: "boolean", describe: "Keep waiting and print new ones" }, notify: { type: "boolean", describe: "With --follow: also a desktop notification" } },
|
|
102
112
|
examples: ["nb inbox --unread", "nb inbox --follow --notify"] },
|
|
103
113
|
{ group: "Account and setup", name: "inbox read", summary: "Mark inbox items read", usage: "nb inbox read <n…> | --all", module: "inbox", fn: "inboxRead", flags: { all: { type: "boolean", describe: "Every unread item" } } },
|
|
114
|
+
{ group: "Account and setup", name: "inbox reply", summary: "Reply on an inbox item's task", usage: "nb inbox reply <n> \"text\"", module: "inbox", fn: "inboxReply", flags: { ...MESSAGE }, examples: ["nb inbox reply 1 \"fixed, thanks\""] },
|
|
115
|
+
{ group: "Account and setup", name: "inbox approve", summary: "Approve the task an inbox item asks you to review", usage: "nb inbox approve <n>", module: "inbox", fn: "inboxApprove" },
|
|
104
116
|
{ group: "Account and setup", name: "inbox open", summary: "Open an inbox item in the browser", usage: "nb inbox open <n>", module: "inbox", fn: "inboxOpen" },
|
|
105
117
|
{ group: "Files", name: "file list", summary: "Files in the workspace", usage: "nb file list [folder] [--task 4]", module: "docs", fn: "fileList", flags: { ...TASK } },
|
|
106
|
-
{ group: "Files", name: "file history", summary: "A file's versions: who, when,
|
|
118
|
+
{ group: "Files", name: "file history", summary: "A file's versions: who, when, based on, which is active", usage: "nb file history <path>", module: "browse", fn: "fileHistory" },
|
|
119
|
+
{ group: "Files", name: "file use", summary: "Make an earlier version active (as Use this version in the app)", usage: "nb file use <path> v<n>", module: "browse", fn: "fileUse", examples: ["nb file use report.md v1"] },
|
|
107
120
|
{ group: "Files", name: "file move", summary: "Move a file to another folder (asks first)", usage: "nb file move <path> <folder>", module: "browse", fn: "fileMove" },
|
|
108
121
|
{ group: "Files", name: "file rename", summary: "Rename a file (asks first)", usage: "nb file rename <path> <new name>", module: "browse", fn: "fileRename" },
|
|
109
122
|
{ group: "Files", name: "file delete", summary: "Move a file to the workspace Trash (asks first)", usage: "nb file delete <path>", module: "browse", fn: "fileDelete" },
|
|
@@ -112,27 +125,33 @@ export const COMMANDS = [
|
|
|
112
125
|
{ group: "Files", name: "file view", summary: "Print a file (pipe-safe)", usage: "nb file view <path>", module: "docs", fn: "fileView" },
|
|
113
126
|
|
|
114
127
|
// Tasks
|
|
115
|
-
{ group: "Tasks", name: "task list", summary: "Tasks (default: yours, not done)", usage: "nb task list [@saved] [--mine|--all] [--status list] [--save name]", module: "tasks", fn: "list",
|
|
116
|
-
flags: { ...FILTERS, save: { type: "string", describe: "Save these filters under a name (nb task list @name)", valueName: "name" } }, examples: ["nb task list --all --status blocked --save stuck", "nb task list @stuck"] },
|
|
128
|
+
{ group: "Tasks", name: "task list", summary: "Tasks (default: yours, not done)", usage: "nb task list [@saved] [--mine|--all] [--status list] [--due week] [--to @sam] [--sprint current] [--priority high] [--sort due] [--save name]", module: "tasks", fn: "list",
|
|
129
|
+
flags: { ...FILTERS, save: { type: "string", describe: "Save these filters under a name (nb task list @name)", valueName: "name" } }, examples: ["nb task list --due week --sort due", "nb task list --all --status blocked --save stuck", "nb task list @stuck"] },
|
|
130
|
+
{ group: "Tasks", name: "next", summary: "What to work on now: overdue, due soon, in progress", usage: "nb next [--limit 5]", module: "tasks", fn: "next",
|
|
131
|
+
flags: { limit: { type: "string", describe: "At most this many (default 5)", valueName: "n" } } },
|
|
117
132
|
{ group: "Tasks", name: "task count", summary: "How many open tasks you have", usage: "nb task count", module: "tasks", fn: "count" },
|
|
118
133
|
{ group: "Tasks", name: "task view", summary: "A task's details (--context: brief for an AI agent)", usage: "nb task view <task> [--context]", module: "tasks", fn: "view",
|
|
119
134
|
flags: { context: { type: "boolean", describe: "Print the task brief for pasting into an AI agent" } } },
|
|
120
|
-
{ group: "Tasks", name: "task create", summary: "Create a task", usage: "nb task create \"<title>\" [-m description] [--priority high]", module: "tasks", fn: "create",
|
|
121
|
-
flags: { ...MESSAGE, priority: { type: "string", describe: "low, medium, high or urgent", valueName: "level" },
|
|
135
|
+
{ group: "Tasks", name: "task create", summary: "Create a task (yours unless --to says otherwise)", usage: "nb task create \"<title>\" [-m description] [--priority high] [--due friday] [--to @sam] [--sprint current]", module: "tasks", fn: "create",
|
|
136
|
+
flags: { ...MESSAGE, priority: { type: "string", describe: "low, medium, high or urgent", valueName: "level" },
|
|
137
|
+
due: { type: "string", describe: "When it's due: today, tomorrow, friday, next week, in 3 days, or 2026-12-01", valueName: "date" },
|
|
138
|
+
to: { type: "string", describe: "Who it's for: @username, me, or none (default: you)", valueName: "person" },
|
|
139
|
+
sprint: { type: "string", describe: "A sprint by name, or current", valueName: "sprint" }, subtask: { type: "string", multiple: true, describe: "Add a subtask (repeatable)", valueName: "title" },
|
|
122
140
|
from: { type: "string", describe: "Create one task per heading in a Markdown file; - [ ] lines become subtasks", valueName: "file.md" } },
|
|
123
|
-
examples: ["nb task create \"Fix login\" --priority high", "nb task create \"Write report\" --subtask Outline --subtask Draft", "nb task create --from tasks.md"] },
|
|
141
|
+
examples: ["nb task create \"Fix login\" --priority high", "nb task create \"Update the logo\" --due friday --to @sam --sprint current", "nb task create \"Write report\" --subtask Outline --subtask Draft", "nb task create --from tasks.md"] },
|
|
124
142
|
{ group: "Tasks", name: "task start", summary: "Make it this folder's task and move it to In progress", usage: "nb task start <task> [--branch]", module: "tasks", fn: "start",
|
|
125
143
|
flags: { branch: { type: "boolean", describe: "Also switch to a git branch for it (nb/4-fix-login)" } }, examples: ["nb task start 4 --branch"] },
|
|
126
144
|
{ group: "Tasks", name: "task stop", summary: "Clear this folder's task (status unchanged)", usage: "nb task stop", module: "tasks", fn: "stop" },
|
|
127
|
-
{ group: "Tasks", name: "task move", summary: "Move to todo, in_progress or blocked", usage: "nb task move <task
|
|
145
|
+
{ group: "Tasks", name: "task move", summary: "Move to todo, in_progress or blocked", usage: "nb task move <task…> <status> [--reason text]", module: "tasks", fn: "move",
|
|
128
146
|
flags: { reason: { type: "string", describe: "Why (needed for blocked)", valueName: "text" } } },
|
|
129
147
|
{ group: "Tasks", name: "task done", summary: "Finish a task (sends it for review when required)", usage: "nb task done [task] [-m summary] [--check name=pass]", module: "tasks", fn: "done",
|
|
130
148
|
flags: { ...MESSAGE, check: { type: "string", multiple: true, describe: "A check you ran: name=pass|fail[:note]", valueName: "check" } } },
|
|
131
149
|
{ group: "Tasks", name: "task review", summary: "Approve or ask for changes (reviewers)", usage: "nb task review <task> approve|changes [-m reason]", module: "tasks", fn: "review", flags: { ...MESSAGE } },
|
|
132
150
|
{ group: "Tasks", name: "task resubmit", summary: "Send for review again after changes", usage: "nb task resubmit <task>", module: "tasks", fn: "resubmit" },
|
|
133
|
-
{ group: "Tasks", name: "task edit", summary: "Change a task's title, description, priority or due date", usage: "nb task edit <task
|
|
151
|
+
{ group: "Tasks", name: "task edit", summary: "Change a task's title, description, priority or due date", usage: "nb task edit <task…> [--title text] [-m description] [--priority high] [--due friday|none]", module: "work", fn: "taskEdit",
|
|
134
152
|
flags: { title: { type: "string", describe: "New title", valueName: "text" }, ...MESSAGE, priority: { type: "string", describe: "low, medium, high or urgent", valueName: "level" }, due: { type: "string", describe: "A date, or none", valueName: "date" } } },
|
|
135
|
-
{ group: "Tasks", name: "task assign", summary: "Assign
|
|
153
|
+
{ group: "Tasks", name: "task assign", summary: "Assign tasks to someone, you, or nobody", usage: "nb task assign <task…> <@username|me|none> | --to @sam", module: "work", fn: "taskAssign",
|
|
154
|
+
flags: { to: { type: "string", describe: "Who: @username, me or none (for several tasks)", valueName: "person" } }, examples: ["nb task assign 4 @sam", "nb task assign 3 4 5 --to me"] },
|
|
136
155
|
{ group: "Tasks", name: "task report", summary: "Report progress with checks, without finishing", usage: "nb task report <task> -m summary [--check name=pass]", module: "work", fn: "taskReport",
|
|
137
156
|
flags: { ...MESSAGE, check: { type: "string", multiple: true, describe: "A check you ran: name=pass|fail[:note]", valueName: "check" } } },
|
|
138
157
|
{ group: "Tasks", name: "task delete", summary: "Delete a task (owner; asks first)", usage: "nb task delete <task>", module: "work", fn: "taskDelete", exit: [0, 3, 7, 130] },
|
|
@@ -225,6 +244,14 @@ export const ALIASES = {
|
|
|
225
244
|
ws: "workspace list",
|
|
226
245
|
};
|
|
227
246
|
|
|
247
|
+
/** Short names people expect (report C1); each says its full name once. Not renamed, so no "until 3.0". */
|
|
248
|
+
export const SHORTCUTS = {
|
|
249
|
+
ls: "file list",
|
|
250
|
+
done: "task done",
|
|
251
|
+
add: "task add",
|
|
252
|
+
"task add": "task create",
|
|
253
|
+
};
|
|
254
|
+
|
|
228
255
|
/** 1.x commands removed on purpose (report D2, D6), with the reason printed instead. */
|
|
229
256
|
export const REMOVED = {
|
|
230
257
|
"hook install": "nb hook install was removed in 2.0: it replaced your git hook and scanned the wrong files.",
|
package/lib/commands/tasks.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// Tasks, subtasks and comments (report §17.4, §42.10, findings 1–3, 7–9, 24, 51–58).
|
|
2
|
+
import { dueRange, parseDate } from "../dates.mjs";
|
|
2
3
|
import crypto from "node:crypto";
|
|
3
4
|
import fs from "node:fs";
|
|
4
5
|
import path from "node:path";
|
|
@@ -17,23 +18,61 @@ const ROLE = /** @type {Record<string, string>} */ ({ deliverable: "final", work
|
|
|
17
18
|
|
|
18
19
|
/**
|
|
19
20
|
* A task by number (4, #4, T-4) or id, with subtasks and files (report A2.7).
|
|
20
|
-
* @param {Context} ctx @param {string} ref
|
|
21
|
+
* @param {Context} ctx @param {string} ref @param {{ brief?: boolean }} [opts] brief: the task row only (no subtasks or files)
|
|
21
22
|
*/
|
|
22
|
-
export async function resolveTask(ctx, ref) {
|
|
23
|
+
export async function resolveTask(ctx, ref, { brief = false } = {}) {
|
|
23
24
|
const workspaceId = ctx.requireWorkspace();
|
|
24
25
|
const cleaned = ref.trim().replace(/^(T-|#)/i, "");
|
|
25
26
|
const isUuid = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(cleaned);
|
|
26
|
-
if (!isUuid && !/^\d+$/.test(cleaned))
|
|
27
|
-
const detail = /** @type {any} */ (await ctx.api.get("/api/v1/extension/task-detail", { query: { projectId: workspaceId, ...(isUuid ? { taskId: cleaned } : { taskNumber: cleaned }) } }).catch((error) => {
|
|
27
|
+
if (!isUuid && !/^\d+$/.test(cleaned)) return resolveTask(ctx, await taskByWords(ctx, ref), { brief });
|
|
28
|
+
const detail = /** @type {any} */ (await ctx.api.get("/api/v1/extension/task-detail", { query: { projectId: workspaceId, ...(isUuid ? { taskId: cleaned } : { taskNumber: cleaned }), ...(brief ? { brief: "1" } : {}) } }).catch((error) => {
|
|
28
29
|
if (error instanceof CliError && (error.status === 404 || error.code === "NOT_FOUND")) throw new CliError("TASK_NOT_FOUND", `No task ${ref} in this workspace`, { hint: "See nb task list" });
|
|
29
30
|
throw error;
|
|
30
31
|
}));
|
|
31
32
|
return { ...detail.task, subtasks: detail.subtasks ?? [], files: detail.files ?? [], comments: detail.comments ?? [], pushes: detail.pushes ?? [] };
|
|
32
33
|
}
|
|
33
34
|
|
|
34
|
-
/**
|
|
35
|
+
/**
|
|
36
|
+
* Tasks by words (C2): one open match is that task; several ask in a terminal, or exit 6 with the choices.
|
|
37
|
+
* @param {Context} ctx @param {string} words @returns {Promise<string>} the task number
|
|
38
|
+
*/
|
|
39
|
+
async function taskByWords(ctx, words) {
|
|
40
|
+
const { tasks } = /** @type {any} */ (await ctx.api.get("/api/v1/extension/workspace-tasks", { query: { projectId: ctx.requireWorkspace(), scope: "all", open: "1", q: words, limit: "10" } }));
|
|
41
|
+
if (!tasks.length) {
|
|
42
|
+
// "Did you mean" for task names too (C1): open tasks with a title word one or two letters off.
|
|
43
|
+
const { didYouMean } = await import("../args.mjs");
|
|
44
|
+
const { tasks: open } = /** @type {any} */ (await ctx.api.get("/api/v1/extension/workspace-tasks", { query: { projectId: ctx.requireWorkspace(), scope: "all", open: "1", limit: "50" } }));
|
|
45
|
+
const want = words.toLowerCase().split(/\s+/).filter((w) => w.length >= 4);
|
|
46
|
+
const near = open.filter((/** @type {any} */ t) => want.some((w) => didYouMean(w, String(t.title).toLowerCase().split(/[^a-z0-9]+/).filter(Boolean)) !== null)).slice(0, 3);
|
|
47
|
+
throw new CliError("TASK_NOT_FOUND", `No open task matches "${words}"`, { hint: near.length ? `Did you mean ${near.map((/** @type {any} */ t) => `#${t.taskNumber} ${safe(t.title)}`).join(", or ")}?` : "Try fewer words, or nb task list --all" });
|
|
48
|
+
}
|
|
49
|
+
if (tasks.length === 1) return String(tasks[0].taskNumber);
|
|
50
|
+
const { ask } = await import("../tui/ask.mjs");
|
|
51
|
+
return ask(ctx, { key: "task", header: "Task", question: `Which task do you mean by "${words}"?`, options: tasks.slice(0, 4).map((/** @type {any} */ t, /** @type {number} */ i) => ({ value: String(t.taskNumber), label: `#${t.taskNumber} ${safe(t.title)}`, recommended: i === 0 })) });
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* The task number in this folder's git branch, when it's one `nb task start --branch` made (nb/4-login-bug), C8.
|
|
56
|
+
* Reads .git/HEAD directly (a worktree's .git file points at its own); no git process, so it's cheap.
|
|
57
|
+
* @param {string | null} dir @returns {string | null}
|
|
58
|
+
*/
|
|
59
|
+
export function branchTask(dir) {
|
|
60
|
+
for (let d = dir; d; d = path.dirname(d) === d ? null : path.dirname(d)) {
|
|
61
|
+
const dotGit = path.join(d, ".git");
|
|
62
|
+
if (!fs.existsSync(dotGit)) continue;
|
|
63
|
+
try {
|
|
64
|
+
const gitDir = fs.statSync(dotGit).isFile() ? path.resolve(d, fs.readFileSync(dotGit, "utf8").replace(/^gitdir:\s*/, "").trim()) : dotGit;
|
|
65
|
+
return /^ref: refs\/heads\/nb\/(\d+)-/.exec(fs.readFileSync(path.join(gitDir, "HEAD"), "utf8"))?.[1] ?? null;
|
|
66
|
+
} catch {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** The task a command means (C8): an argument, --task, the folder's started task, or its nb/<n>- git branch. @param {Context} ctx @param {string | undefined} given */
|
|
35
74
|
export function taskRef(ctx, given) {
|
|
36
|
-
const ref = given ?? ctx.flags.task ?? (ctx.project?.startedTask?.number ? String(ctx.project.startedTask.number) : ctx.project?.startedTask?.id);
|
|
75
|
+
const ref = given ?? ctx.flags.task ?? (ctx.project?.startedTask?.number ? String(ctx.project.startedTask.number) : ctx.project?.startedTask?.id) ?? branchTask(ctx.root);
|
|
37
76
|
if (!ref) throw usage("Which task?", "Pass a task number, --task <n>, or start one with nb task start <n>");
|
|
38
77
|
return String(ref);
|
|
39
78
|
}
|
|
@@ -53,11 +92,26 @@ export async function list(ctx) {
|
|
|
53
92
|
const { applySavedFilter } = await import("./extras.mjs");
|
|
54
93
|
applySavedFilter(ctx);
|
|
55
94
|
const workspaceId = ctx.requireWorkspace();
|
|
56
|
-
const scope = ctx.flags.all ? "all" : "mine";
|
|
57
|
-
const { tasks } = /** @type {any} */ (await ctx.api.get("/api/v1/extension/workspace-tasks", { query: { projectId: workspaceId, scope } }));
|
|
95
|
+
const scope = ctx.flags.all || ctx.flags.to ? "all" : "mine";
|
|
58
96
|
const wanted = ctx.flags.status ? new Set(String(ctx.flags.status).split(",").map((s) => s.trim())) : null;
|
|
59
|
-
let rows = tasks.filter((/** @type {any} */ t) => (wanted ? wanted.has(t.status) || (wanted.has("review") && t.reviewStatus === "pending") : t.status !== "done" || t.reviewStatus === "pending"));
|
|
60
97
|
const limit = ctx.flags.limit ? Number(ctx.flags.limit) : 50;
|
|
98
|
+
// Filters run on the server (C2), so open work never falls off a page of done tasks.
|
|
99
|
+
const due = ctx.flags.due ? dueRange(String(ctx.flags.due)) : null;
|
|
100
|
+
if (ctx.flags.due && !due) throw usage(`--due ${ctx.flags.due} isn't a range I know`, "Use today, week, overdue, or a date like friday or 2026-12-01");
|
|
101
|
+
if (ctx.flags.sort && !["due", "priority", "updated"].includes(String(ctx.flags.sort))) throw usage(`--sort ${ctx.flags.sort}: use due, priority or updated`);
|
|
102
|
+
const { resolvePerson } = ctx.flags.to ? await import("./work.mjs") : { resolvePerson: null };
|
|
103
|
+
/** @type {Record<string, string>} */
|
|
104
|
+
const query = { projectId: workspaceId, scope, limit: String(Math.min(100, limit + 1)) };
|
|
105
|
+
if (!wanted) query.open = "1";
|
|
106
|
+
else if (!wanted.has("review")) query.status = [...wanted].join(",");
|
|
107
|
+
if (due?.after) query.dueAfter = due.after;
|
|
108
|
+
if (due?.before) query.dueBefore = due.before;
|
|
109
|
+
if (resolvePerson) query.assignee = (await resolvePerson(ctx, String(ctx.flags.to))) ?? "none";
|
|
110
|
+
if (ctx.flags.sprint) query.sprint = await resolveSprint(ctx, String(ctx.flags.sprint));
|
|
111
|
+
if (ctx.flags.priority) query.priority = String(ctx.flags.priority);
|
|
112
|
+
if (ctx.flags.sort) query.sort = String(ctx.flags.sort);
|
|
113
|
+
const { tasks } = /** @type {any} */ (await ctx.api.get("/api/v1/extension/workspace-tasks", { query }));
|
|
114
|
+
let rows = tasks.filter((/** @type {any} */ t) => (wanted ? wanted.has(t.status) || (wanted.has("review") && t.reviewStatus === "pending") : true));
|
|
61
115
|
const more = Math.max(0, rows.length - limit);
|
|
62
116
|
rows = rows.slice(0, limit);
|
|
63
117
|
const data = { scope, tasks: rows.map((/** @type {any} */ t) => ({ id: t.id, number: t.taskNumber, title: t.title, status: t.status, reviewStatus: t.reviewStatus ?? null, priority: t.priority ?? null, dueDate: t.dueDate ?? null, assignee: t.assigneeUsername ?? t.assigneeName ?? null, subtasks: t.subtaskSummary ?? null })), more };
|
|
@@ -66,13 +120,49 @@ export async function list(ctx) {
|
|
|
66
120
|
const started = ctx.project?.startedTask?.id;
|
|
67
121
|
return [
|
|
68
122
|
...ctx.out.table([
|
|
69
|
-
|
|
123
|
+
// The started task gets a marker and a space, so plain output never reads as "-1" (C16 #4).
|
|
124
|
+
{ title: "#", value: (t) => `${t.id === started ? ctx.out.c.brand(ctx.out.sym.cursor) : " "} ${t.number ?? ""}`, align: "right" },
|
|
70
125
|
{ title: "Task", value: (t) => safe(t.title), flex: true },
|
|
71
126
|
{ title: "Status", value: (t) => statusWord(t) },
|
|
72
127
|
{ title: "Due", value: (t) => (t.dueDate ? formatDate(t.dueDate) : "—"), optional: true },
|
|
73
128
|
{ title: "Assignee", value: (t) => (t.assignee ? `@${safe(t.assignee)}` : "—"), optional: true },
|
|
74
129
|
], d.tasks),
|
|
75
|
-
ctx.out.c.muted(` ${d.tasks.length} ${d.tasks.length === 1 ? "task" : "tasks"}${d.more ? ` (
|
|
130
|
+
ctx.out.c.muted(` ${d.tasks.length} ${d.tasks.length === 1 ? "task" : "tasks"}${d.more ? ` (more: --limit ${Math.min(100, limit * 2)})` : ""} · nb task view <n>`),
|
|
131
|
+
];
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* What to work on now (C2), in the report's order: overdue, due soon, blocked work to unblock, reviews waiting for
|
|
137
|
+
* you, assignments due; then what's in progress and to do. Each item says the command that starts on it.
|
|
138
|
+
* @param {Context} ctx
|
|
139
|
+
*/
|
|
140
|
+
export async function next(ctx) {
|
|
141
|
+
const limit = Number(ctx.flags.limit ?? 5) || 5;
|
|
142
|
+
const workspaceId = ctx.requireWorkspace();
|
|
143
|
+
const [{ tasks }, home] = await Promise.all([
|
|
144
|
+
/** @type {Promise<any>} */ (ctx.api.get("/api/v1/extension/workspace-tasks", { query: { projectId: workspaceId, scope: "mine", open: "1", sort: "due", limit: "100" } })),
|
|
145
|
+
/** @type {Promise<any>} */ (ctx.api.get("/api/v1/home").catch(() => ({ reviews: [], assignments: [] }))),
|
|
146
|
+
]);
|
|
147
|
+
const now = Date.now();
|
|
148
|
+
const due = (/** @type {any} */ t) => (t.dueDate ? Date.parse(t.dueDate) : Infinity);
|
|
149
|
+
const why = (/** @type {any} */ t) => (t.reviewStatus === "pending" ? "waiting for review" : due(t) < now ? "overdue" : due(t) < now + 7 * 86_400_000 ? "due soon" : t.status === "blocked" ? "blocked" : t.status === "in_progress" ? "in progress" : "to do");
|
|
150
|
+
const RANK = ["overdue", "assignment late", "due soon", "blocked", "review waiting", "assignment due", "in progress", "to do", "waiting for review"];
|
|
151
|
+
const elsewhere = (/** @type {any} */ r) => (r.workspaceId && r.workspaceId !== workspaceId ? ` -w ${r.workspaceSlug ?? r.workspaceId}` : "");
|
|
152
|
+
const items = [
|
|
153
|
+
...tasks.map((/** @type {any} */ t) => ({ kind: "task", id: t.id, number: t.taskNumber, title: t.title, dueDate: t.dueDate ?? null, why: why(t), next: `nb task start ${t.taskNumber}` })),
|
|
154
|
+
...(home.reviews ?? []).map((/** @type {any} */ r) => ({ kind: "review", id: r.id, number: r.number, title: r.title, dueDate: null, why: "review waiting", where: r.workspaceId !== workspaceId ? r.workspaceTitle : null, next: `nb task review ${r.number} approve${elsewhere(r)}` })),
|
|
155
|
+
...(home.assignments ?? []).map((/** @type {any} */ a) => ({ kind: "assignment", id: a.id, number: a.number, title: a.title, dueDate: a.due, why: a.late ? "assignment late" : "assignment due", where: a.org, next: `nb assignment view ${a.number}` })),
|
|
156
|
+
]
|
|
157
|
+
.sort((a, b) => RANK.indexOf(a.why) - RANK.indexOf(b.why) || due(a) - due(b) || (a.number ?? 0) - (b.number ?? 0))
|
|
158
|
+
.slice(0, limit);
|
|
159
|
+
const { c } = ctx.out;
|
|
160
|
+
ctx.out.result("nb.next/1", { items }, (d) => {
|
|
161
|
+
if (!d.items.length) return "Nothing open is yours · nb task list --all for everyone's";
|
|
162
|
+
return [
|
|
163
|
+
...d.items.map((/** @type {any} */ t, /** @type {number} */ i) => ` ${i + 1}. #${t.number} ${safe(t.title)}${t.where ? c.muted(` (${safe(t.where)})`) : ""} ${c.muted("·")} ${t.why === "overdue" || t.why === "assignment late" ? c.warning(t.why) : c.muted(t.why)}${t.dueDate ? c.muted(` (${formatDate(t.dueDate)})`) : ""}`),
|
|
164
|
+
"",
|
|
165
|
+
c.muted(` Next: ${d.items[0].next}`),
|
|
76
166
|
];
|
|
77
167
|
});
|
|
78
168
|
}
|
|
@@ -93,7 +183,13 @@ export async function count(ctx) {
|
|
|
93
183
|
const counts = /** @type {any} */ (await ctx.api.get("/api/v1/tasks/count"));
|
|
94
184
|
ctx.out.result("nb.task.count/1", counts, (c) => {
|
|
95
185
|
const parts = [["in progress", c.byStatus.in_progress], ["to do", c.byStatus.todo], ["blocked", c.byStatus.blocked], ["in review", c.byStatus.in_review]].filter(([, n]) => n).map(([w, n]) => `${n} ${w}`);
|
|
96
|
-
|
|
186
|
+
// Which workspaces these cover (D24), so "1 overdue" is never read as this folder's.
|
|
187
|
+
const where = (c.workspaces ?? []).filter((/** @type {any} */ w) => w.open);
|
|
188
|
+
return [
|
|
189
|
+
`${c.open} open ${c.open === 1 ? "task" : "tasks"}${where.length > 1 ? " across all your workspaces" : where.length === 1 ? ` in ${safe(where[0].title)}` : ""}${parts.length ? `: ${parts.join(", ")}` : ""}`,
|
|
190
|
+
...(c.overdue || c.dueThisWeek ? [`${c.overdue ? `${c.overdue} overdue` : ""}${c.overdue && c.dueThisWeek ? " · " : ""}${c.dueThisWeek ? `${c.dueThisWeek} due this week` : ""}`] : []),
|
|
191
|
+
...(where.length > 1 ? where.map((/** @type {any} */ w) => ` ${safe(w.title)}: ${w.open} open${w.overdue ? `, ${w.overdue} overdue` : ""}${w.dueThisWeek ? `, ${w.dueThisWeek} due this week` : ""}`) : []),
|
|
192
|
+
];
|
|
97
193
|
});
|
|
98
194
|
}
|
|
99
195
|
|
|
@@ -170,22 +266,50 @@ export async function create(ctx) {
|
|
|
170
266
|
const priority = ctx.flags.priority;
|
|
171
267
|
if (priority && !["low", "medium", "high", "urgent"].includes(priority)) throw usage("--priority must be low, medium, high or urgent");
|
|
172
268
|
const projectId = ctx.requireWorkspace();
|
|
173
|
-
|
|
269
|
+
// Everything at once (report C2): a due date in words, who it's for, and the sprint.
|
|
270
|
+
const dueDate = ctx.flags.due === undefined ? undefined : parseDate(String(ctx.flags.due));
|
|
271
|
+
if (dueDate === null) throw usage(`--due ${ctx.flags.due} isn't a date I know`, "Try today, tomorrow, friday, next week, in 3 days, or 2026-12-01");
|
|
272
|
+
const { resolvePerson } = await import("./work.mjs");
|
|
273
|
+
const assigneeId = ctx.flags.to === undefined ? undefined : await resolvePerson(ctx, String(ctx.flags.to));
|
|
274
|
+
const sprintId = ctx.flags.sprint === undefined ? undefined : await resolveSprint(ctx, String(ctx.flags.sprint));
|
|
275
|
+
const res = /** @type {any} */ (await ctx.api.post("/api/v1/extension/create-task", { projectId, title, ...(ctx.flags.message ? { description: ctx.flags.message } : {}), ...(priority ? { priority } : {}),
|
|
276
|
+
...(dueDate ? { dueDate } : {}), ...(assigneeId !== undefined ? { assigneeId } : {}), ...(sprintId ? { sprintId } : {}) }));
|
|
174
277
|
const task = res.task ?? res;
|
|
175
278
|
for (const sub of /** @type {string[]} */ (ctx.flags.subtask ?? [])) await ctx.api.post("/api/v1/extension/task-subtask", { projectId, taskId: task.id, title: sub });
|
|
176
|
-
ctx.out.result("nb.task.create/1", { id: task.id, number: task.taskNumber, title: task.title ?? title, subtasks: (ctx.flags.subtask ?? []).length
|
|
279
|
+
ctx.out.result("nb.task.create/1", { id: task.id, number: task.taskNumber, title: task.title ?? title, subtasks: (ctx.flags.subtask ?? []).length, dueDate: dueDate ?? null }, (d) => [
|
|
280
|
+
`${ctx.out.c.success(ctx.out.sym.done)} Created #${d.number} ${safe(d.title)}${d.subtasks ? ` with ${d.subtasks} subtasks` : ""}${d.dueDate ? ` · due ${d.dueDate}` : ""}`,
|
|
281
|
+
// The next step (C16 #8).
|
|
282
|
+
ctx.out.c.muted(` Next: nb task start ${d.number}`),
|
|
283
|
+
]);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/** A sprint by id, name, or "current" (the active one). @param {Context} ctx @param {string} ref */
|
|
287
|
+
async function resolveSprint(ctx, ref) {
|
|
288
|
+
if (/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(ref)) return ref;
|
|
289
|
+
const { sprints } = /** @type {any} */ (await ctx.api.get(`/api/v1/workspaces/${encodeURIComponent(ctx.requireWorkspace())}/sprints`));
|
|
290
|
+
const want = ref.toLowerCase();
|
|
291
|
+
const hit = want === "current" ? sprints.find((/** @type {any} */ s) => s.status === "active") : sprints.find((/** @type {any} */ s) => String(s.name).toLowerCase() === want);
|
|
292
|
+
if (!hit) throw new CliError("NOT_FOUND", want === "current" ? "No sprint is running here" : `No sprint called ${ref}`, { hint: "nb sprint list" });
|
|
293
|
+
return hit.id;
|
|
177
294
|
}
|
|
178
295
|
|
|
179
296
|
/** Make it this folder's task and move it to In progress — and say so (finding 24). @param {Context} ctx */
|
|
180
297
|
export async function start(ctx) {
|
|
181
298
|
const { root, project } = ctx.requireRoot();
|
|
182
|
-
const task = await resolveTask(ctx, taskRef(ctx, ctx.positionals[0]));
|
|
299
|
+
const task = await resolveTask(ctx, taskRef(ctx, ctx.positionals[0]), { brief: true });
|
|
183
300
|
writeProjectConfig(root, { ...project, startedTask: { id: task.id, number: task.taskNumber, title: task.title } });
|
|
301
|
+
// The move checks updatedAt, so it goes before the assign (which changes it).
|
|
184
302
|
let moved = null;
|
|
185
303
|
if (task.status === "todo") {
|
|
186
304
|
const res = await setStatus(ctx, task, "in_progress").catch((error) => ({ error: error instanceof Error ? error.message : String(error) }));
|
|
187
305
|
moved = res?.error ? { ok: false, message: res.error } : { ok: true, status: "in_progress" };
|
|
188
306
|
}
|
|
307
|
+
// Starting an unassigned task makes it yours (C16 #3), so it shows in your nb task list.
|
|
308
|
+
let assigned = false;
|
|
309
|
+
if (!task.assignee && !task.assigneeId && !task.assigneeUsername) {
|
|
310
|
+
const me = ctx.profile.profile?.user?.id ?? /** @type {any} */ (await ctx.api.get("/api/v1/me")).user.id;
|
|
311
|
+
assigned = await ctx.api.patch("/api/v1/extension/task-update", { kind: "assign", projectId: ctx.requireWorkspace(), taskId: task.id, assigneeId: me }).then(() => true, () => false);
|
|
312
|
+
}
|
|
189
313
|
// --branch: a git branch per task (finding 146), created the first time.
|
|
190
314
|
let branch = null;
|
|
191
315
|
if (ctx.flags.branch) {
|
|
@@ -193,8 +317,8 @@ export async function start(ctx) {
|
|
|
193
317
|
const name = branchName(task.taskNumber, task.title);
|
|
194
318
|
branch = { name, did: await switchToBranch(root, name) };
|
|
195
319
|
}
|
|
196
|
-
ctx.out.result("nb.task.start/1", { id: task.id, number: task.taskNumber, title: task.title, moved, branch }, (d) => [
|
|
197
|
-
`${ctx.out.c.success(ctx.out.sym.done)} Started #${d.number} ${safe(d.title)}`,
|
|
320
|
+
ctx.out.result("nb.task.start/1", { id: task.id, number: task.taskNumber, title: task.title, moved, branch, assigned }, (d) => [
|
|
321
|
+
`${ctx.out.c.success(ctx.out.sym.done)} Started #${d.number} ${safe(d.title)}${d.assigned ? " · assigned to you" : ""}`,
|
|
198
322
|
...(d.moved ? [d.moved.ok ? " Moved to In progress" : ctx.out.c.warning(` Status not changed: ${safe(d.moved.message)}`)] : []),
|
|
199
323
|
...(d.branch ? [` On branch ${d.branch.name} (${d.branch.did}). Link commits: git commit --trailer "NetworkBase-Task: ${d.number}"`] : []),
|
|
200
324
|
ctx.out.c.muted(` nb push <files> links to it · nb task done when finished`),
|
|
@@ -211,16 +335,34 @@ export async function stop(ctx) {
|
|
|
211
335
|
|
|
212
336
|
/** @param {Context} ctx */
|
|
213
337
|
export async function move(ctx) {
|
|
214
|
-
const
|
|
215
|
-
|
|
216
|
-
|
|
338
|
+
const refs = ctx.positionals.slice(0, -1);
|
|
339
|
+
const to = ctx.positionals.at(-1);
|
|
340
|
+
const [ref] = refs;
|
|
341
|
+
if (!ref || !to) throw usage("nb task move <task…> todo|in_progress|blocked");
|
|
217
342
|
if (to === "blocked" && !ctx.flags.reason) throw usage("Say why it's blocked: --reason \"waiting for API keys\"");
|
|
343
|
+
// Several at once (C2): one request, all or nothing, one undo. Done is allowed here, as in the app's bulk move.
|
|
344
|
+
if (refs.length > 1) {
|
|
345
|
+
if (!["todo", "in_progress", "blocked", "done"].includes(to)) throw usage("Move to todo, in_progress, blocked or done");
|
|
346
|
+
const d = await bulkChange(ctx, refs, { kind: "status", status: to, ...(ctx.flags.reason ? { note: String(ctx.flags.reason) } : {}) });
|
|
347
|
+
ctx.out.result("nb.task.move/1", { numbers: d.tasks.map((/** @type {any} */ t) => t.number), status: to }, (r) => `${ctx.out.c.success(ctx.out.sym.done)} ${r.numbers.map((/** @type {number} */ n) => `#${n}`).join(", ")} ${r.numbers.length === 1 ? "is" : "are"} ${STATUS_WORDS[r.status]} · nb undo puts them back`);
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
if (!["todo", "in_progress", "blocked"].includes(to)) throw usage(`Move to todo, in_progress or blocked (use nb task done to finish)`);
|
|
218
351
|
const task = await resolveTask(ctx, ref);
|
|
219
352
|
await setStatus(ctx, task, to);
|
|
220
353
|
if (to === "blocked") await ctx.api.post("/api/v1/extension/comments", { kind: "task", projectId: ctx.requireWorkspace(), taskId: task.id, text: `Blocked: ${ctx.flags.reason}` });
|
|
221
354
|
ctx.out.result("nb.task.move/1", { number: task.taskNumber, status: to }, (d) => `${ctx.out.c.success(ctx.out.sym.done)} #${d.number} is ${STATUS_WORDS[d.status]}`);
|
|
222
355
|
}
|
|
223
356
|
|
|
357
|
+
/**
|
|
358
|
+
* One change to several tasks (report C2): POST /api/v1/tasks/bulk, all or nothing, one undo.
|
|
359
|
+
* @param {Context} ctx @param {string[]} refs @param {Record<string, unknown>} change
|
|
360
|
+
*/
|
|
361
|
+
export async function bulkChange(ctx, refs, change) {
|
|
362
|
+
const tasks = await Promise.all(refs.map((r) => resolveTask(ctx, r, { brief: true })));
|
|
363
|
+
return /** @type {any} */ (await ctx.api.post("/api/v1/tasks/bulk", { projectId: ctx.requireWorkspace(), taskIds: tasks.map((t) => t.id), change }));
|
|
364
|
+
}
|
|
365
|
+
|
|
224
366
|
/**
|
|
225
367
|
* Checks people ran (--check "npm test=pass[:note]") become review evidence the reviewer sees (report §13, F52).
|
|
226
368
|
* @param {string[]} raw @param {string} summary
|
package/lib/commands/undo.mjs
CHANGED
|
@@ -44,7 +44,7 @@ export async function undo(ctx) {
|
|
|
44
44
|
try {
|
|
45
45
|
const res = /** @type {any} */ (await ctx.api.post(`/api/v1/undo/${encodeURIComponent(entry.token)}`, {}));
|
|
46
46
|
dropUndo(ctx.env, entry.token);
|
|
47
|
-
ctx.out.result("nb.undo/1", { token: entry.token, undone: res.undone, result: res.result }, (d) => `${ctx.out.c.success(ctx.out.sym.done)}
|
|
47
|
+
ctx.out.result("nb.undo/1", { token: entry.token, undone: res.undone, result: res.result }, (d) => `${ctx.out.c.success(ctx.out.sym.done)} ${safe(d.result || `Undid: ${d.undone}`)}`);
|
|
48
48
|
} catch (error) {
|
|
49
49
|
if (error instanceof CliError && error.status === 410) dropUndo(ctx.env, entry.token);
|
|
50
50
|
throw error;
|
package/lib/commands/work.mjs
CHANGED
|
@@ -7,7 +7,8 @@ import path from "node:path";
|
|
|
7
7
|
import { CliError, EXIT, usage } from "../errors.mjs";
|
|
8
8
|
import { safe } from "../print/style.mjs";
|
|
9
9
|
import { confirm } from "../tui/ask.mjs";
|
|
10
|
-
import {
|
|
10
|
+
import { parseDate } from "../dates.mjs";
|
|
11
|
+
import { bulkChange, resolveTask, taskRef } from "./tasks.mjs";
|
|
11
12
|
|
|
12
13
|
/** @typedef {import("../context.mjs").Context} Context */
|
|
13
14
|
|
|
@@ -16,7 +17,6 @@ const update = (ctx, body) => ctx.api.patch("/api/v1/extension/task-update", { p
|
|
|
16
17
|
|
|
17
18
|
/** @param {Context} ctx */
|
|
18
19
|
export async function taskEdit(ctx) {
|
|
19
|
-
const task = await resolveTask(ctx, taskRef(ctx, ctx.positionals[0]));
|
|
20
20
|
/** @type {Array<[string, string | null]>} */
|
|
21
21
|
const changes = [];
|
|
22
22
|
if (ctx.flags.title) changes.push(["title", String(ctx.flags.title)]);
|
|
@@ -26,29 +26,66 @@ export async function taskEdit(ctx) {
|
|
|
26
26
|
changes.push(["priority", ctx.flags.priority]);
|
|
27
27
|
}
|
|
28
28
|
if (ctx.flags.due) {
|
|
29
|
+
// Natural dates everywhere a date is taken (C2): friday, next week, in 3 days, 2026-12-01.
|
|
29
30
|
const due = String(ctx.flags.due);
|
|
30
|
-
|
|
31
|
-
|
|
31
|
+
const date = due === "none" ? null : parseDate(due);
|
|
32
|
+
if (due !== "none" && !date) throw usage(`--due ${due} isn't a date I know`, "Use today, tomorrow, friday, next week, in 3 days, 2026-12-01, or none");
|
|
33
|
+
changes.push(["dueDate", date]);
|
|
34
|
+
}
|
|
35
|
+
if (!changes.length) throw usage("nb task edit <task…> [--title text] [-m description] [--priority high] [--due friday|none]");
|
|
36
|
+
if (ctx.positionals.length > 1) {
|
|
37
|
+
if (changes.some(([f]) => f === "title" || f === "description")) throw usage("Several tasks take --priority and --due; change a title one task at a time");
|
|
38
|
+
let numbers = [];
|
|
39
|
+
for (const [field, value] of changes) numbers = (await bulkChange(ctx, ctx.positionals, { kind: "edit", field, value })).tasks.map((/** @type {any} */ t) => t.number);
|
|
40
|
+
ctx.out.result("nb.task.edit/1", { numbers, changed: changes.map(([f]) => f) }, (d) => `${ctx.out.c.success(ctx.out.sym.done)} Changed ${d.changed.join(", ")} on ${d.numbers.map((/** @type {number} */ n) => `#${n}`).join(", ")}`);
|
|
41
|
+
return;
|
|
32
42
|
}
|
|
33
|
-
|
|
43
|
+
const task = await resolveTask(ctx, taskRef(ctx, ctx.positionals[0]));
|
|
34
44
|
for (const [field, value] of changes) await update(ctx, { kind: "edit", taskId: task.id, field, value });
|
|
35
45
|
ctx.out.result("nb.task.edit/1", { number: task.taskNumber, changed: changes.map(([f]) => f) }, (d) => `${ctx.out.c.success(ctx.out.sym.done)} Changed ${d.changed.join(", ")} on #${d.number}`);
|
|
36
46
|
}
|
|
37
47
|
|
|
48
|
+
/** A person for --to and task assign: @username, me, or none (null). @param {Context} ctx @param {string} who */
|
|
49
|
+
export async function resolvePerson(ctx, who) {
|
|
50
|
+
if (who === "none") return null;
|
|
51
|
+
if (who === "me") return /** @type {any} */ (await ctx.api.get("/api/v1/me")).user.id;
|
|
52
|
+
const name = who.replace(/^@/, "").toLowerCase();
|
|
53
|
+
const { members } = /** @type {any} */ (await ctx.api.get(`/api/v1/workspaces/${encodeURIComponent(ctx.requireWorkspace())}/members`, { query: { q: name } }));
|
|
54
|
+
const hit = members.find((/** @type {any} */ m) => String(m.username ?? "").toLowerCase() === name);
|
|
55
|
+
if (!hit) throw new CliError("NOT_FOUND", `No member @${name} in this workspace`, { hint: "nb member list" });
|
|
56
|
+
return hit.id;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* A picker when the person is left out (C2): in a terminal, choose; scripts and agents get exit 6 with the choices.
|
|
61
|
+
* @param {Context} ctx @returns {Promise<string>}
|
|
62
|
+
*/
|
|
63
|
+
async function pickPerson(ctx) {
|
|
64
|
+
const { members } = /** @type {any} */ (await ctx.api.get(`/api/v1/workspaces/${encodeURIComponent(ctx.requireWorkspace())}/members`));
|
|
65
|
+
const { ask } = await import("../tui/ask.mjs");
|
|
66
|
+
return ask(ctx, { key: "person", header: "Assign to", question: "Who should do it?", options: [
|
|
67
|
+
{ value: "me", label: "Me", recommended: true },
|
|
68
|
+
...members.filter((/** @type {any} */ m) => m.username).slice(0, 7).map((/** @type {any} */ m) => ({ value: `@${m.username}`, label: safe(m.fullName ?? m.username), description: `@${m.username}` })),
|
|
69
|
+
{ value: "none", label: "Nobody" },
|
|
70
|
+
] });
|
|
71
|
+
}
|
|
72
|
+
|
|
38
73
|
/** @param {Context} ctx */
|
|
39
74
|
export async function taskAssign(ctx) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
75
|
+
// nb task assign 4 @sam, or several: nb task assign 3 4 --to sam (C2). Left out: choose from the members.
|
|
76
|
+
const picking = !ctx.flags.to && ctx.positionals.length === 1;
|
|
77
|
+
const refs = ctx.flags.to || picking ? ctx.positionals : ctx.positionals.slice(0, -1);
|
|
78
|
+
const who = ctx.flags.to ? String(ctx.flags.to) : picking ? await pickPerson(ctx) : ctx.positionals.at(-1);
|
|
79
|
+
const [ref] = refs;
|
|
80
|
+
if (!ref || !who) throw usage("nb task assign <task…> <@username|me|none>, or --to @sam");
|
|
81
|
+
if (refs.length > 1) {
|
|
82
|
+
const assigneeId = await resolvePerson(ctx, who);
|
|
83
|
+
const d = await bulkChange(ctx, refs, { kind: "assign", assigneeId });
|
|
84
|
+
ctx.out.result("nb.task.assign/1", { numbers: d.tasks.map((/** @type {any} */ t) => t.number), assignee: who === "none" ? null : who.replace(/^@/, "") }, (r) => `${ctx.out.c.success(ctx.out.sym.done)} ${r.numbers.map((/** @type {number} */ n) => `#${n}`).join(", ")} ${r.assignee ? `assigned to ${r.assignee === "me" ? "you" : `@${safe(r.assignee)}`}` : "unassigned"}`);
|
|
85
|
+
return;
|
|
51
86
|
}
|
|
87
|
+
const task = await resolveTask(ctx, ref);
|
|
88
|
+
const assigneeId = await resolvePerson(ctx, who);
|
|
52
89
|
await update(ctx, { kind: "assign", taskId: task.id, assigneeId });
|
|
53
90
|
ctx.out.result("nb.task.assign/1", { number: task.taskNumber, assignee: who === "none" ? null : who.replace(/^@/, "") }, (d) => `${ctx.out.c.success(ctx.out.sym.done)} #${d.number} ${d.assignee ? `is assigned to ${d.assignee === "me" ? "you" : `@${safe(d.assignee)}`}` : "is unassigned"}`);
|
|
54
91
|
}
|
package/lib/config.mjs
CHANGED
|
@@ -73,7 +73,7 @@ export function normalizeOrigin(origin) {
|
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
/**
|
|
76
|
-
* @typedef {{ origin: string, token: string, user?: { id: string, username?: string | null, email?: string | null } | null, savedAt?: string, source?: "file" | "env", storage?: "keychain" | "secret-service" | "dpapi" | "file", sealed?: string }} Profile
|
|
76
|
+
* @typedef {{ origin: string, token: string, user?: { id: string, username?: string | null, email?: string | null } | null, savedAt?: string, expiresAt?: string, source?: "file" | "env", storage?: "keychain" | "secret-service" | "dpapi" | "file", sealed?: string }} Profile
|
|
77
77
|
*/
|
|
78
78
|
|
|
79
79
|
/** Settings: flag > environment > project > user > default. @param {{ profile?: string }} [flags] @param {NodeJS.ProcessEnv} [env] @param {any} [project] */
|
package/lib/context.mjs
CHANGED
|
@@ -32,6 +32,11 @@ export function createContext({ flags, positionals, cwd = process.cwd(), env = p
|
|
|
32
32
|
onRetry: ({ waitMs, reason }) => out.note(out.c.muted(`${reason}; retrying in ${Math.max(1, Math.round(waitMs / 1000))} s`)),
|
|
33
33
|
});
|
|
34
34
|
|
|
35
|
+
// The first step comes first (C1): signed out, "link this folder" is the wrong advice.
|
|
36
|
+
const signedInFirst = () => {
|
|
37
|
+
if (!profile.token) throw new CliError("NOT_SIGNED_IN", "Sign in first: nb login", { hint: "Then run this again" });
|
|
38
|
+
};
|
|
39
|
+
|
|
35
40
|
return {
|
|
36
41
|
out,
|
|
37
42
|
flags,
|
|
@@ -45,6 +50,7 @@ export function createContext({ flags, positionals, cwd = process.cwd(), env = p
|
|
|
45
50
|
version: VERSION,
|
|
46
51
|
/** Workspace id from --workspace or the link; an error naming the fix otherwise. */
|
|
47
52
|
requireWorkspace() {
|
|
53
|
+
signedInFirst();
|
|
48
54
|
if (flags.workspace) return /** @type {string} */ (flags.workspace);
|
|
49
55
|
if (project?.workspaceId) return project.workspaceId;
|
|
50
56
|
// A default for scripts, CI and the hosted MCP server (an agent token's own workspace).
|
|
@@ -63,6 +69,7 @@ export function createContext({ flags, positionals, cwd = process.cwd(), env = p
|
|
|
63
69
|
},
|
|
64
70
|
/** The linked folder; commands that sync files need one. */
|
|
65
71
|
requireRoot() {
|
|
72
|
+
signedInFirst();
|
|
66
73
|
if (!root || !project) throw new CliError("NOT_LINKED", "This folder isn't linked to a workspace", { hint: "Run nb init <workspace> here" });
|
|
67
74
|
return { root, project };
|
|
68
75
|
},
|
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
|
+
}
|