@networkbase/cli 1.0.2 → 1.0.4

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.
Files changed (2) hide show
  1. package/bin/nb.mjs +390 -57
  2. package/package.json +1 -1
package/bin/nb.mjs CHANGED
@@ -11,7 +11,7 @@ import { fileURLToPath } from "node:url";
11
11
 
12
12
  const CLI_SCRIPT_PATH = fileURLToPath(import.meta.url);
13
13
 
14
- const CLI_VERSION = "1.0.2";
14
+ const CLI_VERSION = "1.0.4";
15
15
  const DEFAULT_API_URL = process.env.NETWORKBASE_API_URL || "https://networkbase.in";
16
16
  const GLOBAL_CONFIG_DIR = path.join(os.homedir(), ".networkbase");
17
17
  const GLOBAL_CREDENTIALS_PATH = path.join(GLOBAL_CONFIG_DIR, "credentials.json");
@@ -391,6 +391,33 @@ function saveCredentials(creds) {
391
391
  });
392
392
  }
393
393
 
394
+ const BOOLEAN_FLAGS = new Set([
395
+ "json",
396
+ "force",
397
+ "dry-run",
398
+ "deliverable",
399
+ "draft",
400
+ "reference",
401
+ "done",
402
+ "wip",
403
+ "all",
404
+ "mine",
405
+ "yes",
406
+ "y",
407
+ "auto",
408
+ "reauth",
409
+ "allow-secrets",
410
+ "help",
411
+ "h",
412
+ "version",
413
+ "v",
414
+ "no-task",
415
+ "all-workspaces",
416
+ "uncheck",
417
+ "pull-only",
418
+ "daemon-worker",
419
+ ]);
420
+
394
421
  function parseFlags(argv) {
395
422
  const positional = [];
396
423
  const flags = {};
@@ -402,18 +429,31 @@ function parseFlags(argv) {
402
429
  flags[arg.slice(2, eqIdx)] = arg.slice(eqIdx + 1);
403
430
  } else {
404
431
  const key = arg.slice(2);
405
- const next = argv[i + 1];
406
- if (next && !next.startsWith("-")) {
407
- flags[key] = next;
408
- i++;
409
- } else {
432
+ if (BOOLEAN_FLAGS.has(key)) {
410
433
  flags[key] = true;
434
+ } else {
435
+ const next = argv[i + 1];
436
+ if (next && !next.startsWith("-")) {
437
+ flags[key] = next;
438
+ i++;
439
+ } else {
440
+ flags[key] = true;
441
+ }
411
442
  }
412
443
  }
413
444
  } else if (arg === "-m" && argv[i + 1]) {
414
445
  flags.message = argv[++i];
415
446
  } else if (arg === "-j") {
416
447
  flags.json = true;
448
+ } else if (arg === "-y" || arg === "-Y") {
449
+ flags.yes = true;
450
+ flags.y = true;
451
+ } else if (arg === "-h") {
452
+ flags.help = true;
453
+ flags.h = true;
454
+ } else if (arg === "-v") {
455
+ flags.version = true;
456
+ flags.v = true;
417
457
  } else {
418
458
  positional.push(arg);
419
459
  }
@@ -2213,7 +2253,9 @@ async function handleStatus(flags) {
2213
2253
  outputResult(statusPayload, flags, (res) => {
2214
2254
  const identity = res.authenticated
2215
2255
  ? `${c.emerald}●${c.reset} ${c.bold}${c.ink}${res.user?.username ? `@${res.user.username}` : res.user?.email || res.sessionId}${c.reset} ${c.muted}(${res.tokenType || "device"})${c.reset}`
2216
- : `${c.amber}○ Not signed in${c.reset}`;
2256
+ : creds?.token && (creds?.user || creds?.sessionId)
2257
+ ? `${c.emerald}●${c.reset} ${c.bold}${c.ink}${creds.user?.username ? `@${creds.user.username}` : creds.user?.email || creds.sessionId}${c.reset} ${c.muted}(${creds.tokenType || "device"})${c.reset}`
2258
+ : `${c.amber}○ Not signed in${c.reset}`;
2217
2259
 
2218
2260
  const wsDisplay = res.workspace?.projectId
2219
2261
  ? `${c.bold}${c.ink}${res.workspace.title || res.workspace.projectId}${c.reset} ${c.muted}(${res.workspace.slug || res.workspace.projectId.slice(0, 8)})${c.reset}`
@@ -2238,6 +2280,67 @@ async function handleStatus(flags) {
2238
2280
  return statusPayload;
2239
2281
  }
2240
2282
 
2283
+ async function ensureWorkspaceLinked(flags = {}, cwd = process.cwd()) {
2284
+ const cfg = getLocalConfig(cwd);
2285
+ const explicitWorkspace = typeof flags.workspace === "string" ? flags.workspace.trim() : null;
2286
+ const projectId = explicitWorkspace || cfg.projectId;
2287
+
2288
+ if (projectId) {
2289
+ return { projectId, cfg };
2290
+ }
2291
+
2292
+ // Not linked locally. Attempt to discover accessible workspaces.
2293
+ let workspaces = [];
2294
+ try {
2295
+ const creds = getCredentials();
2296
+ const apiUrl = await resolveBestApiUrl(typeof flags.url === "string" ? flags.url : creds?.apiUrl);
2297
+ const res = await apiRequest("/api/v1/extension/workspaces", { apiUrl });
2298
+ workspaces = res?.workspaces || res?.projects || [];
2299
+ } catch {
2300
+ // Session may be missing or unauthenticated
2301
+ }
2302
+
2303
+ if (workspaces.length === 0) {
2304
+ throw new Error(
2305
+ "No workspace linked in this directory. Run `nb login` followed by `nb init` to link a workspace.",
2306
+ );
2307
+ }
2308
+
2309
+ // If in interactive TTY and not json, offer immediate 1-click workspace selection
2310
+ if (process.stdin.isTTY && !flags.json) {
2311
+ renderBrandHeader({ subtitle: "Workspace Setup · Select a Workspace" });
2312
+ const chosen = await tuiSelect({
2313
+ title: "No workspace is linked to this directory. Choose one to link:",
2314
+ stepLabel: "Workspace",
2315
+ searchable: workspaces.length > 5,
2316
+ items: workspaces.map((w) => ({
2317
+ label: w.title,
2318
+ badge: formatStatusBadge(w.role || "member"),
2319
+ description: `ID: ${w.id}${w.slug ? ` · /${w.slug}` : ""}`,
2320
+ value: w,
2321
+ })),
2322
+ });
2323
+
2324
+ if (chosen) {
2325
+ const updatedCfg = {
2326
+ ...cfg,
2327
+ projectId: chosen.id,
2328
+ title: chosen.title,
2329
+ slug: chosen.slug,
2330
+ };
2331
+ saveLocalConfig(updatedCfg, cwd);
2332
+ printStepDone("Linked Workspace", `${chosen.title} (${chosen.id})`);
2333
+ return { projectId: chosen.id, cfg: updatedCfg };
2334
+ }
2335
+ }
2336
+
2337
+ // Non-interactive or cancelled: output accessible workspaces so user or agent can select immediately
2338
+ const wsList = workspaces.map((w) => ` - ${w.title} (${w.id})`).join("\n");
2339
+ throw new Error(
2340
+ `No workspace linked. Run \`nb init\` or pass \`--workspace <id>\`.\nAvailable workspaces:\n${wsList}`,
2341
+ );
2342
+ }
2343
+
2241
2344
  async function handleWorkspace(sub, positional, flags) {
2242
2345
  if (sub === "switch" || (!sub && process.stdin.isTTY && !flags.json)) {
2243
2346
  const target = positional[0] || flags.workspace;
@@ -2267,9 +2370,9 @@ async function handleWorkspace(sub, positional, flags) {
2267
2370
  }
2268
2371
 
2269
2372
  if (sub === "info") {
2270
- const cfg = getLocalConfig();
2271
- if (!cfg.projectId) throw new Error("No workspace linked. Run `nb init` first.");
2272
- const summary = await apiRequest(`/api/v1/extension/workspace-summary?projectId=${cfg.projectId}`);
2373
+ const cwd = process.cwd();
2374
+ const { projectId, cfg } = await ensureWorkspaceLinked(flags, cwd);
2375
+ const summary = await apiRequest(`/api/v1/extension/workspace-summary?projectId=${projectId}`);
2273
2376
  outputResult({ workspace: cfg, summary }, flags, (res) => {
2274
2377
  renderBrandHeader({
2275
2378
  subtitle: "Workspace Summary",
@@ -2309,16 +2412,23 @@ async function hydrateTaskAttachedFiles(projectId, attachedFiles, cwd = process.
2309
2412
  const cleanRel = normPath.replace(/^\/+/, "");
2310
2413
  const mirrorDest = path.join(mirrorDir, cleanRel);
2311
2414
  const expectedHash = (f.contentHash || manifestFiles[normPath]?.contentHash || "").toLowerCase();
2312
-
2313
- if (expectedHash && fs.existsSync(mirrorDest)) {
2314
- try {
2315
- const localHash = computeFileSha256(mirrorDest).hash.toLowerCase();
2316
- if (localHash === expectedHash) {
2317
- hydratedCount++;
2318
- return;
2415
+ const expectedVersion = f.currentVersion || f.version;
2416
+ const manifestVersion = manifestFiles[normPath]?.version;
2417
+
2418
+ if (fs.existsSync(mirrorDest)) {
2419
+ if (expectedHash) {
2420
+ try {
2421
+ const localHash = computeFileSha256(mirrorDest).hash.toLowerCase();
2422
+ if (localHash === expectedHash) {
2423
+ hydratedCount++;
2424
+ return;
2425
+ }
2426
+ } catch {
2427
+ // Re-download if unreadable
2319
2428
  }
2320
- } catch {
2321
- // Re-download if unreadable
2429
+ } else if (expectedVersion && manifestVersion && expectedVersion === manifestVersion) {
2430
+ hydratedCount++;
2431
+ return;
2322
2432
  }
2323
2433
  }
2324
2434
 
@@ -2473,8 +2583,8 @@ function renderTaskDetailCard(res, cfg, hydratedCount = 0) {
2473
2583
 
2474
2584
  async function handleTask(sub, positional, flags) {
2475
2585
  const cwd = process.cwd();
2476
- const cfg = getLocalConfig(cwd);
2477
- const projectId = typeof flags.workspace === "string" ? flags.workspace : cfg.projectId;
2586
+ let cfg = getLocalConfig(cwd);
2587
+ let projectId = typeof flags.workspace === "string" ? flags.workspace : cfg.projectId;
2478
2588
 
2479
2589
  // Support `nb task list --all` / `nb task --all-workspaces` across all accessible workspaces
2480
2590
  if ((!sub || sub === "list" || sub === "ls") && (flags.all || flags["all-workspaces"])) {
@@ -2523,7 +2633,7 @@ async function handleTask(sub, positional, flags) {
2523
2633
  return;
2524
2634
  }
2525
2635
 
2526
- if (!projectId) throw new Error("No workspace linked. Run `nb init` first.");
2636
+ ({ projectId, cfg } = await ensureWorkspaceLinked(flags, cwd));
2527
2637
 
2528
2638
  // Allow shorthand `nb task #4` or `nb task 4` to directly open `nb task view #4`
2529
2639
  if (sub && (/^#?\d+$/.test(sub) || /^[0-9a-f]{8}-[0-9a-f]{4}-/i.test(sub))) {
@@ -2531,6 +2641,73 @@ async function handleTask(sub, positional, flags) {
2531
2641
  sub = "view";
2532
2642
  }
2533
2643
 
2644
+ if (sub === "create" || sub === "new" || sub === "add") {
2645
+ let title = typeof flags.title === "string" ? flags.title : positional.join(" ").trim();
2646
+ if (!title && process.stdin.isTTY && !flags.json) {
2647
+ renderBrandHeader({ subtitle: `Create Sprint Task · ${cfg.title || projectId}` });
2648
+ title = await tuiInput({
2649
+ title: "Enter task title",
2650
+ stepLabel: "Task Title",
2651
+ placeholder: "e.g., Implement OAuth callback flow",
2652
+ });
2653
+ }
2654
+ if (!title) {
2655
+ throw new Error('Usage: nb task create "<title>" [-m description] [--priority low|medium|high|urgent]');
2656
+ }
2657
+
2658
+ const description =
2659
+ typeof flags.message === "string"
2660
+ ? flags.message
2661
+ : typeof flags.description === "string"
2662
+ ? flags.description
2663
+ : undefined;
2664
+ const priority =
2665
+ flags.priority && ["low", "medium", "high", "urgent"].includes(flags.priority.toLowerCase())
2666
+ ? flags.priority.toLowerCase()
2667
+ : "medium";
2668
+
2669
+ const createdRes = await withSpinner(
2670
+ "Creating sprint task…",
2671
+ () =>
2672
+ apiRequest("/api/v1/extension/create-task", {
2673
+ method: "POST",
2674
+ body: {
2675
+ projectId,
2676
+ title,
2677
+ description,
2678
+ priority,
2679
+ },
2680
+ }),
2681
+ { silent: Boolean(flags.json) },
2682
+ );
2683
+
2684
+ // Refresh local tasks and TASKS.md immediately
2685
+ try {
2686
+ const refreshed = await apiRequest(`/api/v1/extension/workspace-tasks?projectId=${projectId}&scope=all`);
2687
+ writeLocalTaskIntelligence(projectId, cfg.title || projectId, refreshed.tasks || [], cwd);
2688
+ } catch {}
2689
+
2690
+ const createdTask = createdRes.task || createdRes;
2691
+ outputResult(
2692
+ createdRes,
2693
+ flags,
2694
+ () => {
2695
+ console.log(RAIL);
2696
+ console.log(
2697
+ `${STEP_DONE} ${c.bold}${c.ink}Created Task ${createdTask.taskNumber ? `#${createdTask.taskNumber}` : createdTask.id}${c.reset} ${formatPriorityBadge(priority)} ${formatStatusBadge("todo")}`,
2698
+ );
2699
+ console.log(`${RAIL} ${c.ink}${createdTask.title || title}${c.reset}`);
2700
+ if (description) {
2701
+ console.log(`${RAIL} ${c.muted}${description.slice(0, 100)}${c.reset}`);
2702
+ }
2703
+ console.log(
2704
+ `${c.dim}╰─${c.reset} Run ${c.accent}nb task work ${createdTask.taskNumber ? `#${createdTask.taskNumber}` : createdTask.id}${c.reset} to begin working on it.\n`,
2705
+ );
2706
+ },
2707
+ );
2708
+ return;
2709
+ }
2710
+
2534
2711
  if (sub === "work") {
2535
2712
  let rawTarget = positional[0];
2536
2713
  if (!rawTarget && process.stdin.isTTY && !flags.json) {
@@ -2788,6 +2965,77 @@ async function handleTask(sub, positional, flags) {
2788
2965
  return;
2789
2966
  }
2790
2967
 
2968
+ if (sub === "subtask" || sub === "subtasks") {
2969
+ const action = positional[0];
2970
+ if (action === "add" || action === "create" || action === "new") {
2971
+ let args = positional.slice(1);
2972
+ const rawTask = flags.task ? String(flags.task) : null;
2973
+ let targetTaskId = rawTask ? resolveTaskIdentifier(rawTask, cwd) : null;
2974
+
2975
+ // Check if next arg is a task identifier (e.g. #4, 4, or UUID)
2976
+ if (!targetTaskId && args.length > 1 && (/^#?\d+$/.test(args[0]) || /^[0-9a-f]{8}-[0-9a-f]{4}-/i.test(args[0]))) {
2977
+ targetTaskId = resolveTaskIdentifier(args.shift(), cwd);
2978
+ }
2979
+ if (!targetTaskId) {
2980
+ const inferred = inferActiveTaskId(flags, cwd);
2981
+ if (inferred) targetTaskId = resolveTaskIdentifier(inferred, cwd);
2982
+ }
2983
+
2984
+ if (!targetTaskId) {
2985
+ throw new Error("No active task bound. Specify task with `#<number>` or pass `--task <#number>`.");
2986
+ }
2987
+
2988
+ const title = flags.title || flags.message || args.join(" ").trim();
2989
+ if (!title) {
2990
+ throw new Error('Usage: nb task subtask add [#number] "<subtask title>"');
2991
+ }
2992
+
2993
+ const detail = await apiRequest(
2994
+ `/api/v1/extension/task-detail?projectId=${projectId}&taskId=${encodeURIComponent(targetTaskId)}`,
2995
+ );
2996
+ const task = detail.task;
2997
+
2998
+ const created = await withSpinner(
2999
+ `Creating subtask on "${task.title}"…`,
3000
+ () =>
3001
+ apiRequest("/api/v1/extension/task-subtask", {
3002
+ method: "POST",
3003
+ body: {
3004
+ projectId,
3005
+ taskId: task.id,
3006
+ title,
3007
+ },
3008
+ }),
3009
+ { silent: Boolean(flags.json) },
3010
+ );
3011
+
3012
+ // Refresh local tasks and TASKS.md immediately
3013
+ try {
3014
+ const refreshed = await apiRequest(`/api/v1/extension/workspace-tasks?projectId=${projectId}&scope=all`);
3015
+ writeLocalTaskIntelligence(projectId, cfg.title || projectId, refreshed.tasks || [], cwd);
3016
+ } catch {}
3017
+
3018
+ outputResult(
3019
+ {
3020
+ taskId: task.id,
3021
+ taskNumber: task.taskNumber,
3022
+ taskTitle: task.title,
3023
+ subtask: created.subtask,
3024
+ },
3025
+ flags,
3026
+ (res) => {
3027
+ console.log(RAIL);
3028
+ console.log(
3029
+ `${STEP_DONE} ${c.bold}${c.ink}Created subtask on Task ${res.taskNumber ? `#${res.taskNumber}` : res.taskId}${c.reset} ${c.muted}("${res.taskTitle}")${c.reset}`,
3030
+ );
3031
+ console.log(`${RAIL} ${c.muted}[ ]${c.reset} ${c.ink}${res.subtask.title}${c.reset}`);
3032
+ console.log(`${c.dim}╰─${c.reset} Subtask added and synced to .networkbase/tasks/TASKS.md\n`);
3033
+ },
3034
+ );
3035
+ return;
3036
+ }
3037
+ }
3038
+
2791
3039
  if (sub === "check" || sub === "subtask" || sub === "subtasks") {
2792
3040
  const rawTaskTarget = flags.task ? String(flags.task) : inferActiveTaskId(flags, cwd);
2793
3041
  let targetTaskId = rawTaskTarget ? resolveTaskIdentifier(rawTaskTarget, cwd) : null;
@@ -2935,6 +3183,11 @@ async function handleTask(sub, positional, flags) {
2935
3183
  expectedUpdatedAt: new Date(task.updatedAt).toISOString(),
2936
3184
  },
2937
3185
  });
3186
+ // Refresh local tasks and TASKS.md immediately
3187
+ try {
3188
+ const refreshed = await apiRequest(`/api/v1/extension/workspace-tasks?projectId=${projectId}&scope=all`);
3189
+ writeLocalTaskIntelligence(projectId, cfg.title || projectId, refreshed.tasks || [], cwd);
3190
+ } catch {}
2938
3191
  outputResult(updated, flags, () => {
2939
3192
  console.log(
2940
3193
  `\n${c.emerald}✔${c.reset} Task ${c.bold}${c.ink}"${task.title}"${c.reset} marked as ${formatStatusBadge("done")}\n`,
@@ -3003,6 +3256,11 @@ async function handleTask(sub, positional, flags) {
3003
3256
  method: "POST",
3004
3257
  body: { taskId: detail.task.id, content },
3005
3258
  });
3259
+ // Refresh local tasks and TASKS.md immediately
3260
+ try {
3261
+ const refreshed = await apiRequest(`/api/v1/extension/workspace-tasks?projectId=${projectId}&scope=all`);
3262
+ writeLocalTaskIntelligence(projectId, cfg.title || projectId, refreshed.tasks || [], cwd);
3263
+ } catch {}
3006
3264
  outputResult(created, flags, () => {
3007
3265
  console.log(`\n${c.emerald}✔${c.reset} Posted comment to task "${detail.task.title}"\n`);
3008
3266
  });
@@ -3064,9 +3322,8 @@ async function downloadRemoteFileBuffer(projectId, remotePath, options = {}) {
3064
3322
  }
3065
3323
 
3066
3324
  async function handleFile(sub, positional, flags) {
3067
- const cfg = getLocalConfig();
3068
- const projectId = flags.workspace || cfg.projectId;
3069
- if (!projectId) throw new Error("No workspace linked. Run `nb init` first.");
3325
+ const cwd = process.cwd();
3326
+ const { projectId, cfg } = await ensureWorkspaceLinked(flags, cwd);
3070
3327
 
3071
3328
  if (sub === "ls" || !sub) {
3072
3329
  const filterQuery = positional[0] || "";
@@ -3218,9 +3475,9 @@ async function handleFile(sub, positional, flags) {
3218
3475
  throw new Error(`Unknown file subcommand: ${sub}`);
3219
3476
  }
3220
3477
 
3221
- function prepareLocalFilesForPush(targetPaths, flags, cwd = process.cwd()) {
3478
+ function prepareLocalFilesForPush(targetPaths, flags, cwd = process.cwd(), explicitProjectId = null) {
3222
3479
  const cfg = getLocalConfig(cwd);
3223
- const projectId = flags.workspace || cfg.projectId;
3480
+ const projectId = explicitProjectId || flags.workspace || cfg.projectId;
3224
3481
  if (!projectId) {
3225
3482
  throw new Error("No workspace linked in this directory. Run `nb init` first.");
3226
3483
  }
@@ -3306,7 +3563,7 @@ function prepareLocalFilesForPush(targetPaths, flags, cwd = process.cwd()) {
3306
3563
  };
3307
3564
  }
3308
3565
 
3309
- async function executePrePushAnalysis(targetPaths, flags, cwd = process.cwd()) {
3566
+ async function executePrePushAnalysis(targetPaths, flags, cwd = process.cwd(), explicitProjectId = null) {
3310
3567
  const {
3311
3568
  projectId,
3312
3569
  taskId,
@@ -3314,7 +3571,7 @@ async function executePrePushAnalysis(targetPaths, flags, cwd = process.cwd()) {
3314
3571
  allPreparedCount,
3315
3572
  skippedByLocalManifestCount,
3316
3573
  secretViolations,
3317
- } = prepareLocalFilesForPush(targetPaths, flags, cwd);
3574
+ } = prepareLocalFilesForPush(targetPaths, flags, cwd, explicitProjectId);
3318
3575
 
3319
3576
  const analysis = await apiRequest("/api/v1/extension/pre-push", {
3320
3577
  method: "POST",
@@ -3399,7 +3656,8 @@ async function executeFastPushRequest({
3399
3656
  }
3400
3657
 
3401
3658
  async function handlePush(positional, flags, { skipHeader = false } = {}) {
3402
- const cfg = getLocalConfig();
3659
+ const cwd = process.cwd();
3660
+ const { projectId, cfg } = await ensureWorkspaceLinked(flags, cwd);
3403
3661
  if (!flags.json && !skipHeader && !flags["dry-run"]) {
3404
3662
  renderBrandHeader({
3405
3663
  subtitle: `High-EQ Smart Push · ${cfg.title || flags.workspace || "Workspace"}`,
@@ -3407,20 +3665,20 @@ async function handlePush(positional, flags, { skipHeader = false } = {}) {
3407
3665
  }
3408
3666
 
3409
3667
  const explicitRole = resolveRoleFromFlags(flags);
3668
+ const isAuto = Boolean(flags.yes || flags.y || flags.auto || !process.stdin.isTTY);
3410
3669
  const transitionFromFlags = flags.done ? "done" : flags.wip ? "in_progress" : undefined;
3411
3670
 
3412
3671
  // ULTRA-FAST 1-ROUND-TRIP PATH:
3413
- // When role is already specified (e.g. --deliverable / --draft / --reference / --json) and not dry-run,
3672
+ // When role is already specified (e.g. --deliverable / --draft / --reference / --json) or auto/non-TTY,
3414
3673
  // skip /pre-push completely and execute atomic /fast-push in 1 single HTTP round-trip!
3415
- if (!flags["dry-run"] && (explicitRole || flags.json || !process.stdin.isTTY)) {
3674
+ if (!flags["dry-run"] && (explicitRole || flags.json || isAuto)) {
3416
3675
  const {
3417
- projectId,
3418
3676
  taskId,
3419
3677
  preparedFiles,
3420
3678
  allPreparedCount,
3421
3679
  skippedByLocalManifestCount,
3422
3680
  secretViolations,
3423
- } = prepareLocalFilesForPush(positional, flags);
3681
+ } = prepareLocalFilesForPush(positional, flags, cwd, projectId);
3424
3682
 
3425
3683
  if (secretViolations.length > 0 && !flags["allow-secrets"]) {
3426
3684
  const errPayload = {
@@ -3522,12 +3780,17 @@ async function handlePush(positional, flags, { skipHeader = false } = {}) {
3522
3780
  console.log(`${c.dim}╰─${c.reset} ${c.emerald}✔${c.reset} Sync complete.\n`);
3523
3781
  }
3524
3782
  });
3783
+ if (projectId) {
3784
+ try {
3785
+ const refreshed = await apiRequest(`/api/v1/extension/workspace-tasks?projectId=${projectId}&scope=all`);
3786
+ writeLocalTaskIntelligence(projectId, cfg.title || projectId, refreshed.tasks || [], cwd);
3787
+ } catch {}
3788
+ }
3525
3789
  return finalFast;
3526
3790
  }
3527
3791
  }
3528
3792
 
3529
3793
  const {
3530
- projectId,
3531
3794
  taskId,
3532
3795
  preparedFiles,
3533
3796
  skippedByLocalManifestCount,
@@ -3535,7 +3798,7 @@ async function handlePush(positional, flags, { skipHeader = false } = {}) {
3535
3798
  analysis,
3536
3799
  } = await withSpinner(
3537
3800
  "Analyzing local files & SHA-256 manifest…",
3538
- () => executePrePushAnalysis(positional, flags),
3801
+ () => executePrePushAnalysis(positional, flags, cwd, projectId),
3539
3802
  { silent: Boolean(flags.json) },
3540
3803
  );
3541
3804
 
@@ -3599,7 +3862,7 @@ async function handlePush(positional, flags, { skipHeader = false } = {}) {
3599
3862
  let selectedRole = explicitRole;
3600
3863
 
3601
3864
  // Interactive Multi-File Selection & Role Classification when running in a terminal without flags
3602
- if (process.stdin.isTTY && !flags.json && !selectedRole) {
3865
+ if (process.stdin.isTTY && !flags.json && !selectedRole && !isAuto) {
3603
3866
  if (changedAnalysisFiles.length > 1) {
3604
3867
  const chosenPaths = await tuiMultiSelect({
3605
3868
  title: "Select changed files to include in this push",
@@ -3669,7 +3932,8 @@ async function handlePush(positional, flags, { skipHeader = false } = {}) {
3669
3932
  selectedRole === "deliverable" &&
3670
3933
  !transitionStatus &&
3671
3934
  process.stdin.isTTY &&
3672
- !flags.json
3935
+ !flags.json &&
3936
+ !isAuto
3673
3937
  ) {
3674
3938
  const taskTitle = analysis.task?.title || taskId;
3675
3939
  const markDone = await tuiConfirm({
@@ -3904,13 +4168,19 @@ async function handlePush(positional, flags, { skipHeader = false } = {}) {
3904
4168
  }
3905
4169
  });
3906
4170
 
4171
+ if (projectId) {
4172
+ try {
4173
+ const refreshed = await apiRequest(`/api/v1/extension/workspace-tasks?projectId=${projectId}&scope=all`);
4174
+ writeLocalTaskIntelligence(projectId, cfg.title || projectId, refreshed.tasks || [], cwd);
4175
+ } catch {}
4176
+ }
4177
+
3907
4178
  return finalPayload;
3908
4179
  }
3909
4180
 
3910
4181
  async function handlePull(positional, flags, { skipHeader = false } = {}) {
3911
- const cfg = getLocalConfig();
3912
- const projectId = flags.workspace || cfg.projectId;
3913
- if (!projectId) throw new Error("No workspace linked. Run `nb init` first.");
4182
+ const cwd = process.cwd();
4183
+ const { projectId, cfg } = await ensureWorkspaceLinked(flags, cwd);
3914
4184
 
3915
4185
  if (!flags.json && !skipHeader) {
3916
4186
  renderBrandHeader({ subtitle: `Pull Workspace Files · ${cfg.title || projectId}` });
@@ -4140,18 +4410,7 @@ async function hydrateWorkspaceMirror(projectId, { cwd = process.cwd(), force =
4140
4410
 
4141
4411
  async function handleSync(positional, flags) {
4142
4412
  const cwd = process.cwd();
4143
- let cfg = getLocalConfig(cwd);
4144
-
4145
- // Allow switching workspace in the same single `nb sync --workspace <slug-or-id>` call
4146
- if (typeof flags.workspace === "string" && flags.workspace.trim() && flags.workspace !== cfg.projectId) {
4147
- await handleInit([flags.workspace.trim()], { ...flags, "no-task": true, silent: true }, { skipHeader: true });
4148
- cfg = getLocalConfig(cwd);
4149
- }
4150
-
4151
- const projectId = cfg.projectId;
4152
- if (!projectId) {
4153
- throw new Error("No workspace linked. Run `nb init` first.");
4154
- }
4413
+ let { projectId, cfg } = await ensureWorkspaceLinked(flags, cwd);
4155
4414
 
4156
4415
  if (!flags.json) {
4157
4416
  renderBrandHeader({ subtitle: `Unified One-Permission Sync · ${cfg.title || projectId}` });
@@ -4277,9 +4536,7 @@ async function handleSync(positional, flags) {
4277
4536
 
4278
4537
  async function handleWatch(positional, flags) {
4279
4538
  const cwd = process.cwd();
4280
- const cfg = getLocalConfig(cwd);
4281
- const projectId = flags.workspace || cfg.projectId;
4282
- if (!projectId) throw new Error("No workspace linked. Run `nb init` first.");
4539
+ const { projectId, cfg } = await ensureWorkspaceLinked(flags, cwd);
4283
4540
 
4284
4541
  const isDaemonWorker = Boolean(flags["daemon-worker"]);
4285
4542
  const role = resolveRoleFromFlags(flags) || "deliverable";
@@ -4720,6 +4977,31 @@ async function startMcpServer() {
4720
4977
  properties: { paths: { type: "array", items: { type: "string" } } },
4721
4978
  },
4722
4979
  },
4980
+ {
4981
+ name: "nb_subtask_create",
4982
+ description: "Create a new subtask checklist item on a Sprint Task in NetworkBase.",
4983
+ inputSchema: {
4984
+ type: "object",
4985
+ properties: {
4986
+ taskId: { type: "string", description: "Task UUID or task number (e.g. #4 or 4)" },
4987
+ title: { type: "string", description: "Subtask title / description" },
4988
+ },
4989
+ required: ["taskId", "title"],
4990
+ },
4991
+ },
4992
+ {
4993
+ name: "nb_task_create",
4994
+ description: "Create a new Sprint Task in the active NetworkBase workspace.",
4995
+ inputSchema: {
4996
+ type: "object",
4997
+ properties: {
4998
+ title: { type: "string", description: "Task title" },
4999
+ description: { type: "string", description: "Optional markdown description" },
5000
+ priority: { type: "string", enum: ["low", "medium", "high", "urgent"] },
5001
+ },
5002
+ required: ["title"],
5003
+ },
5004
+ },
4723
5005
  ],
4724
5006
  });
4725
5007
  return;
@@ -4905,6 +5187,51 @@ async function startMcpServer() {
4905
5187
  return;
4906
5188
  }
4907
5189
 
5190
+ if (toolName === "nb_subtask_create") {
5191
+ const cfg = getLocalConfig();
5192
+ const targetId = resolveTaskIdentifier(args.taskId || getLocalState()?.activeTaskId);
5193
+ const detail = await apiRequest(
5194
+ `/api/v1/extension/task-detail?projectId=${cfg.projectId}&taskId=${encodeURIComponent(targetId)}`,
5195
+ );
5196
+ const res = await apiRequest("/api/v1/extension/task-subtask", {
5197
+ method: "POST",
5198
+ body: {
5199
+ projectId: cfg.projectId,
5200
+ taskId: detail.task.id,
5201
+ title: args.title,
5202
+ },
5203
+ });
5204
+ try {
5205
+ const refreshed = await apiRequest(`/api/v1/extension/workspace-tasks?projectId=${cfg.projectId}&scope=all`);
5206
+ writeLocalTaskIntelligence(cfg.projectId, cfg.title || cfg.projectId, refreshed.tasks || []);
5207
+ } catch {}
5208
+ sendJsonRpc(id, {
5209
+ content: [{ type: "text", text: JSON.stringify(res, null, 2) }],
5210
+ });
5211
+ return;
5212
+ }
5213
+
5214
+ if (toolName === "nb_task_create") {
5215
+ const cfg = getLocalConfig();
5216
+ const res = await apiRequest("/api/v1/extension/create-task", {
5217
+ method: "POST",
5218
+ body: {
5219
+ projectId: cfg.projectId,
5220
+ title: args.title,
5221
+ description: args.description,
5222
+ priority: args.priority || "medium",
5223
+ },
5224
+ });
5225
+ try {
5226
+ const refreshed = await apiRequest(`/api/v1/extension/workspace-tasks?projectId=${cfg.projectId}&scope=all`);
5227
+ writeLocalTaskIntelligence(cfg.projectId, cfg.title || cfg.projectId, refreshed.tasks || []);
5228
+ } catch {}
5229
+ sendJsonRpc(id, {
5230
+ content: [{ type: "text", text: JSON.stringify(res, null, 2) }],
5231
+ });
5232
+ return;
5233
+ }
5234
+
4908
5235
  sendJsonRpc(id, null, { code: -32601, message: `Unknown tool: ${toolName}` });
4909
5236
  }
4910
5237
  } catch (err) {
@@ -4936,15 +5263,21 @@ Core Commands:
4936
5263
  nb auth setup-git Configure Git HTTPS credential helper
4937
5264
  nb workspace list | switch List or switch active NetworkBase workspaces
4938
5265
  nb task [list] [--all | --mine] View project tasks, descriptions, subtasks & attached files
5266
+ nb task <#number|id> Shorthand to inspect task details & mirror attached files
4939
5267
  nb task view <#number|id> Inspect task description, subtasks & mirror attached files
4940
5268
  nb task work <#number|id> Bind active task, transition to in_progress & mirror files
4941
- nb task check [1 2 | --all] Toggle subtasks interactively (Space) or via CLI numbers
5269
+ nb task create "<title>" [-m] Create a new sprint task (--priority low|medium|high|urgent)
5270
+ nb task subtask add [#id] <t> Add a new subtask checklist item to active or specified task
5271
+ nb task check [#id] [1 2|--all] Toggle subtasks interactively (Space) or via CLI numbers
4942
5272
  nb task done [#number|id] Mark active or specified task as Done
5273
+ nb task comment <#id> <message> Add a comment to active or specified task
5274
+ nb task status View sprint & task health metrics and completion rate
4943
5275
  nb file ls | log | diff | lock Inspect workspace files, history, diffs, or CLI locks
4944
5276
  nb hook install Install local .git/hooks/pre-push secret scanner
4945
5277
  nb pull [paths...] Download remote workspace files to local directory
4946
5278
  nb watch [paths...] Live debounced auto-sync watcher (1-RTT fast-push on save)
4947
5279
  nb push [paths...] High-EQ Smart Push (SHA-256 diff + v1->v2 bump + task link)
5280
+ -y, --yes, --auto Non-interactive push with smart defaults (no prompt blocking)
4948
5281
  --deliverable Classify pushed files as Final Deliverable (#deliverable)
4949
5282
  --draft Classify pushed files as Working Draft (#editor_working)
4950
5283
  --reference Classify pushed files as Reference Material (#reference)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@networkbase/cli",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "NetworkBase CLI, Local Mirror Sync, Git Credential Helper & AI MCP Server",
5
5
  "type": "module",
6
6
  "homepage": "https://networkbase.in",