@networkbase/cli 1.0.1 → 1.0.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.
- package/bin/nb.mjs +607 -72
- 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.
|
|
14
|
+
const CLI_VERSION = "1.0.3";
|
|
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");
|
|
@@ -1368,9 +1368,28 @@ async function loginWithBrowser(apiUrl, flags = {}) {
|
|
|
1368
1368
|
let timeoutHandle;
|
|
1369
1369
|
const server = http.createServer(async (req, res) => {
|
|
1370
1370
|
try {
|
|
1371
|
+
const origin = req.headers.origin || "";
|
|
1372
|
+
const isAllowedOrigin =
|
|
1373
|
+
origin.startsWith("https://networkbase.in") ||
|
|
1374
|
+
origin.startsWith("https://networkbase.app") ||
|
|
1375
|
+
origin.startsWith("http://localhost:3000") ||
|
|
1376
|
+
origin.startsWith("http://127.0.0.1");
|
|
1377
|
+
|
|
1378
|
+
const corsHeaders = {
|
|
1379
|
+
"Access-Control-Allow-Origin": isAllowedOrigin ? origin : "*",
|
|
1380
|
+
"Access-Control-Allow-Methods": "GET, OPTIONS",
|
|
1381
|
+
"Access-Control-Allow-Headers": "Content-Type, Authorization, Accept, X-Requested-With",
|
|
1382
|
+
};
|
|
1383
|
+
|
|
1384
|
+
if (req.method === "OPTIONS") {
|
|
1385
|
+
res.writeHead(204, corsHeaders);
|
|
1386
|
+
res.end();
|
|
1387
|
+
return;
|
|
1388
|
+
}
|
|
1389
|
+
|
|
1371
1390
|
const reqUrl = new URL(req.url || "/", "http://127.0.0.1");
|
|
1372
1391
|
if (reqUrl.pathname !== "/auth-callback") {
|
|
1373
|
-
res.writeHead(404, { "Content-Type": "text/plain" });
|
|
1392
|
+
res.writeHead(404, { ...corsHeaders, "Content-Type": "text/plain" });
|
|
1374
1393
|
res.end("Not found");
|
|
1375
1394
|
return;
|
|
1376
1395
|
}
|
|
@@ -1379,14 +1398,39 @@ async function loginWithBrowser(apiUrl, flags = {}) {
|
|
|
1379
1398
|
const message = reqUrl.searchParams.get("message");
|
|
1380
1399
|
const code = reqUrl.searchParams.get("code");
|
|
1381
1400
|
const returnedState = reqUrl.searchParams.get("state");
|
|
1401
|
+
const isAjax =
|
|
1402
|
+
req.headers["sec-fetch-mode"] === "cors" ||
|
|
1403
|
+
(req.headers.accept && req.headers.accept.includes("application/json"));
|
|
1382
1404
|
|
|
1383
1405
|
if (error) {
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1406
|
+
if (isAjax) {
|
|
1407
|
+
res.writeHead(400, { ...corsHeaders, "Content-Type": "application/json; charset=utf-8" });
|
|
1408
|
+
res.end(JSON.stringify({ ok: false, error: message || error }));
|
|
1409
|
+
} else {
|
|
1410
|
+
res.writeHead(400, { ...corsHeaders, "Content-Type": "text/html; charset=utf-8" });
|
|
1411
|
+
res.end(`<!doctype html>
|
|
1412
|
+
<html lang="en">
|
|
1413
|
+
<head>
|
|
1414
|
+
<meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
1415
|
+
<title>Authorization Cancelled · NetworkBase</title>
|
|
1416
|
+
<link rel="icon" type="image/svg+xml" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Crect width='32' height='32' rx='6' fill='%23c05638'/%3E%3C/svg%3E" />
|
|
1417
|
+
<style>
|
|
1418
|
+
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; background: #09090b; color: #fafafa; display: flex; align-items: center; justify-content: center; min-height: 100vh; margin: 0; padding: 24px; }
|
|
1419
|
+
.card { width: 100%; max-width: 420px; background: #121215; border: 1px solid #27272a; border-radius: 12px; padding: 32px 28px; text-align: center; }
|
|
1420
|
+
h2 { font-size: 18px; margin: 0 0 8px; font-weight: 600; }
|
|
1421
|
+
p { font-size: 13px; color: #a1a1aa; line-height: 1.5; margin: 0 0 20px; }
|
|
1422
|
+
.btn { display: block; width: 100%; height: 40px; line-height: 40px; background: #fafafa; color: #000; font-size: 13px; font-weight: 500; border: none; border-radius: 6px; cursor: pointer; }
|
|
1423
|
+
</style>
|
|
1424
|
+
</head>
|
|
1425
|
+
<body>
|
|
1426
|
+
<div class="card">
|
|
1427
|
+
<h2>Authorization Cancelled</h2>
|
|
1428
|
+
<p>${message || error || "Please restart sign-in from your terminal."}</p>
|
|
1429
|
+
<button class="btn" onclick="window.close()">Close Window</button>
|
|
1430
|
+
</div>
|
|
1431
|
+
</body>
|
|
1432
|
+
</html>`);
|
|
1433
|
+
}
|
|
1390
1434
|
clearTimeout(timeoutHandle);
|
|
1391
1435
|
server.close();
|
|
1392
1436
|
reject(new Error(message || `Browser authorization failed: ${error}`));
|
|
@@ -1394,25 +1438,223 @@ async function loginWithBrowser(apiUrl, flags = {}) {
|
|
|
1394
1438
|
}
|
|
1395
1439
|
|
|
1396
1440
|
if (!code || returnedState !== state) {
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1441
|
+
if (isAjax) {
|
|
1442
|
+
res.writeHead(400, { ...corsHeaders, "Content-Type": "application/json; charset=utf-8" });
|
|
1443
|
+
res.end(JSON.stringify({ ok: false, error: "Invalid state or missing authorization code." }));
|
|
1444
|
+
} else {
|
|
1445
|
+
res.writeHead(400, { ...corsHeaders, "Content-Type": "text/html; charset=utf-8" });
|
|
1446
|
+
res.end(`<!doctype html>
|
|
1447
|
+
<html lang="en">
|
|
1448
|
+
<head>
|
|
1449
|
+
<meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
1450
|
+
<title>Invalid Callback State · NetworkBase</title>
|
|
1451
|
+
<link rel="icon" type="image/svg+xml" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Crect width='32' height='32' rx='6' fill='%23c05638'/%3E%3C/svg%3E" />
|
|
1452
|
+
<style>
|
|
1453
|
+
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; background: #09090b; color: #fafafa; display: flex; align-items: center; justify-content: center; min-height: 100vh; margin: 0; padding: 24px; }
|
|
1454
|
+
.card { width: 100%; max-width: 420px; background: #121215; border: 1px solid #27272a; border-radius: 12px; padding: 32px 28px; text-align: center; }
|
|
1455
|
+
h2 { font-size: 18px; margin: 0 0 8px; font-weight: 600; }
|
|
1456
|
+
p { font-size: 13px; color: #a1a1aa; line-height: 1.5; margin: 0 0 20px; }
|
|
1457
|
+
.btn { display: block; width: 100%; height: 40px; line-height: 40px; background: #fafafa; color: #000; font-size: 13px; font-weight: 500; border: none; border-radius: 6px; cursor: pointer; }
|
|
1458
|
+
</style>
|
|
1459
|
+
</head>
|
|
1460
|
+
<body>
|
|
1461
|
+
<div class="card">
|
|
1462
|
+
<h2>Invalid Callback State</h2>
|
|
1463
|
+
<p>Please restart sign-in from your terminal.</p>
|
|
1464
|
+
<button class="btn" onclick="window.close()">Close Window</button>
|
|
1465
|
+
</div>
|
|
1466
|
+
</body>
|
|
1467
|
+
</html>`);
|
|
1468
|
+
}
|
|
1402
1469
|
clearTimeout(timeoutHandle);
|
|
1403
1470
|
server.close();
|
|
1404
1471
|
reject(new Error("Invalid state or missing authorization code from browser callback."));
|
|
1405
1472
|
return;
|
|
1406
1473
|
}
|
|
1407
1474
|
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1475
|
+
if (isAjax) {
|
|
1476
|
+
res.writeHead(200, {
|
|
1477
|
+
...corsHeaders,
|
|
1478
|
+
"Content-Type": "application/json; charset=utf-8",
|
|
1479
|
+
});
|
|
1480
|
+
res.end(JSON.stringify({ ok: true, status: "connected", message: "NetworkBase CLI Connected" }));
|
|
1481
|
+
} else {
|
|
1482
|
+
res.writeHead(200, {
|
|
1483
|
+
...corsHeaders,
|
|
1484
|
+
"Content-Type": "text/html; charset=utf-8",
|
|
1485
|
+
});
|
|
1486
|
+
res.end(`<!doctype html>
|
|
1487
|
+
<html lang="en">
|
|
1488
|
+
<head>
|
|
1489
|
+
<meta charset="utf-8" />
|
|
1490
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
1491
|
+
<title>NetworkBase CLI Connected · NetworkBase</title>
|
|
1492
|
+
<link rel="icon" type="image/svg+xml" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Crect width='32' height='32' rx='6' fill='%23c05638'/%3E%3Cpath d='M9 16.5l4.5 4.5 9.5-9.5' fill='none' stroke='%23ffffff' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E" />
|
|
1493
|
+
<style>
|
|
1494
|
+
:root {
|
|
1495
|
+
--background: #09090b;
|
|
1496
|
+
--card: #121215;
|
|
1497
|
+
--border: #27272a;
|
|
1498
|
+
--foreground: #fafafa;
|
|
1499
|
+
--muted: #a1a1aa;
|
|
1500
|
+
--accent: #c05638;
|
|
1501
|
+
--emerald: #10b981;
|
|
1502
|
+
}
|
|
1503
|
+
* { box-sizing: border-box; margin: 0; padding: 0; }
|
|
1504
|
+
body {
|
|
1505
|
+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
|
1506
|
+
background-color: var(--background);
|
|
1507
|
+
color: var(--foreground);
|
|
1508
|
+
min-height: 100vh;
|
|
1509
|
+
display: flex;
|
|
1510
|
+
align-items: center;
|
|
1511
|
+
justify-content: center;
|
|
1512
|
+
padding: 24px;
|
|
1513
|
+
-webkit-font-smoothing: antialiased;
|
|
1514
|
+
}
|
|
1515
|
+
.card {
|
|
1516
|
+
width: 100%;
|
|
1517
|
+
max-width: 440px;
|
|
1518
|
+
background-color: var(--card);
|
|
1519
|
+
border: 1px solid var(--border);
|
|
1520
|
+
border-radius: 12px;
|
|
1521
|
+
padding: 32px 28px;
|
|
1522
|
+
text-align: center;
|
|
1523
|
+
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
|
|
1524
|
+
}
|
|
1525
|
+
.brand {
|
|
1526
|
+
display: inline-flex;
|
|
1527
|
+
align-items: center;
|
|
1528
|
+
gap: 8px;
|
|
1529
|
+
font-size: 13px;
|
|
1530
|
+
font-weight: 600;
|
|
1531
|
+
letter-spacing: -0.01em;
|
|
1532
|
+
color: var(--foreground);
|
|
1533
|
+
margin-bottom: 24px;
|
|
1534
|
+
}
|
|
1535
|
+
.brand-dot {
|
|
1536
|
+
width: 10px;
|
|
1537
|
+
height: 10px;
|
|
1538
|
+
background-color: var(--accent);
|
|
1539
|
+
border-radius: 2px;
|
|
1540
|
+
}
|
|
1541
|
+
.icon-container {
|
|
1542
|
+
width: 52px;
|
|
1543
|
+
height: 52px;
|
|
1544
|
+
margin: 0 auto 16px;
|
|
1545
|
+
display: flex;
|
|
1546
|
+
align-items: center;
|
|
1547
|
+
justify-content: center;
|
|
1548
|
+
border-radius: 50%;
|
|
1549
|
+
background: rgba(16, 185, 129, 0.12);
|
|
1550
|
+
border: 1px solid rgba(16, 185, 129, 0.25);
|
|
1551
|
+
color: var(--emerald);
|
|
1552
|
+
}
|
|
1553
|
+
.title {
|
|
1554
|
+
font-size: 18px;
|
|
1555
|
+
font-weight: 600;
|
|
1556
|
+
letter-spacing: -0.02em;
|
|
1557
|
+
margin-bottom: 8px;
|
|
1558
|
+
}
|
|
1559
|
+
.subtitle {
|
|
1560
|
+
font-size: 13px;
|
|
1561
|
+
color: var(--muted);
|
|
1562
|
+
line-height: 1.5;
|
|
1563
|
+
margin-bottom: 24px;
|
|
1564
|
+
}
|
|
1565
|
+
.details {
|
|
1566
|
+
background: rgba(255, 255, 255, 0.02);
|
|
1567
|
+
border: 1px solid var(--border);
|
|
1568
|
+
border-radius: 8px;
|
|
1569
|
+
padding: 12px 14px;
|
|
1570
|
+
margin-bottom: 24px;
|
|
1571
|
+
text-align: left;
|
|
1572
|
+
font-size: 12px;
|
|
1573
|
+
}
|
|
1574
|
+
.details-row {
|
|
1575
|
+
display: flex;
|
|
1576
|
+
justify-content: space-between;
|
|
1577
|
+
align-items: center;
|
|
1578
|
+
padding: 4px 0;
|
|
1579
|
+
}
|
|
1580
|
+
.details-label { color: var(--muted); }
|
|
1581
|
+
.details-value { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; }
|
|
1582
|
+
.badge-connected {
|
|
1583
|
+
color: var(--emerald);
|
|
1584
|
+
background: rgba(16, 185, 129, 0.15);
|
|
1585
|
+
border: 1px solid rgba(16, 185, 129, 0.3);
|
|
1586
|
+
padding: 2px 6px;
|
|
1587
|
+
border-radius: 4px;
|
|
1588
|
+
font-weight: 500;
|
|
1589
|
+
}
|
|
1590
|
+
.btn {
|
|
1591
|
+
display: block;
|
|
1592
|
+
width: 100%;
|
|
1593
|
+
height: 40px;
|
|
1594
|
+
line-height: 40px;
|
|
1595
|
+
background: var(--foreground);
|
|
1596
|
+
color: #000;
|
|
1597
|
+
font-size: 13px;
|
|
1598
|
+
font-weight: 500;
|
|
1599
|
+
border: none;
|
|
1600
|
+
border-radius: 6px;
|
|
1601
|
+
cursor: pointer;
|
|
1602
|
+
text-decoration: none;
|
|
1603
|
+
transition: opacity 0.15s ease;
|
|
1604
|
+
}
|
|
1605
|
+
.btn:hover { opacity: 0.9; }
|
|
1606
|
+
.countdown {
|
|
1607
|
+
margin-top: 14px;
|
|
1608
|
+
font-size: 11px;
|
|
1609
|
+
color: var(--muted);
|
|
1610
|
+
}
|
|
1611
|
+
</style>
|
|
1612
|
+
</head>
|
|
1613
|
+
<body>
|
|
1614
|
+
<div class="card">
|
|
1615
|
+
<div class="brand">
|
|
1616
|
+
<span class="brand-dot"></span>
|
|
1617
|
+
<span>NetworkBase</span>
|
|
1618
|
+
</div>
|
|
1619
|
+
<div class="icon-container">
|
|
1620
|
+
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
|
|
1621
|
+
<path d="M20 6L9 17l-5-5"/>
|
|
1622
|
+
</svg>
|
|
1623
|
+
</div>
|
|
1624
|
+
<h1 class="title">NetworkBase CLI Connected</h1>
|
|
1625
|
+
<p class="subtitle">Your terminal session is now authenticated. You can safely close this window.</p>
|
|
1626
|
+
<div class="details">
|
|
1627
|
+
<div class="details-row">
|
|
1628
|
+
<span class="details-label">Client</span>
|
|
1629
|
+
<span class="details-value">NetworkBase CLI</span>
|
|
1630
|
+
</div>
|
|
1631
|
+
<div class="details-row">
|
|
1632
|
+
<span class="details-label">Server</span>
|
|
1633
|
+
<span class="details-value">networkbase.in</span>
|
|
1634
|
+
</div>
|
|
1635
|
+
<div class="details-row">
|
|
1636
|
+
<span class="details-label">Status</span>
|
|
1637
|
+
<span class="badge-connected">● CONNECTED</span>
|
|
1638
|
+
</div>
|
|
1639
|
+
</div>
|
|
1640
|
+
<button class="btn" onclick="window.close()">Close Window</button>
|
|
1641
|
+
<p class="countdown">Closing automatically in <span id="sec">3</span>s…</p>
|
|
1642
|
+
</div>
|
|
1643
|
+
<script>
|
|
1644
|
+
let s = 3;
|
|
1645
|
+
const el = document.getElementById('sec');
|
|
1646
|
+
const t = setInterval(() => {
|
|
1647
|
+
s--;
|
|
1648
|
+
if (el) el.textContent = s;
|
|
1649
|
+
if (s <= 0) {
|
|
1650
|
+
clearInterval(t);
|
|
1651
|
+
window.close();
|
|
1652
|
+
}
|
|
1653
|
+
}, 1000);
|
|
1654
|
+
</script>
|
|
1655
|
+
</body>
|
|
1656
|
+
</html>`);
|
|
1657
|
+
}
|
|
1416
1658
|
|
|
1417
1659
|
clearTimeout(timeoutHandle);
|
|
1418
1660
|
server.close();
|
|
@@ -1971,7 +2213,9 @@ async function handleStatus(flags) {
|
|
|
1971
2213
|
outputResult(statusPayload, flags, (res) => {
|
|
1972
2214
|
const identity = res.authenticated
|
|
1973
2215
|
? `${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}`
|
|
1974
|
-
:
|
|
2216
|
+
: creds?.token && (creds?.user || creds?.sessionId)
|
|
2217
|
+
? `${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}`
|
|
2218
|
+
: `${c.amber}○ Not signed in${c.reset}`;
|
|
1975
2219
|
|
|
1976
2220
|
const wsDisplay = res.workspace?.projectId
|
|
1977
2221
|
? `${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}`
|
|
@@ -1996,6 +2240,67 @@ async function handleStatus(flags) {
|
|
|
1996
2240
|
return statusPayload;
|
|
1997
2241
|
}
|
|
1998
2242
|
|
|
2243
|
+
async function ensureWorkspaceLinked(flags = {}, cwd = process.cwd()) {
|
|
2244
|
+
const cfg = getLocalConfig(cwd);
|
|
2245
|
+
const explicitWorkspace = typeof flags.workspace === "string" ? flags.workspace.trim() : null;
|
|
2246
|
+
const projectId = explicitWorkspace || cfg.projectId;
|
|
2247
|
+
|
|
2248
|
+
if (projectId) {
|
|
2249
|
+
return { projectId, cfg };
|
|
2250
|
+
}
|
|
2251
|
+
|
|
2252
|
+
// Not linked locally. Attempt to discover accessible workspaces.
|
|
2253
|
+
let workspaces = [];
|
|
2254
|
+
try {
|
|
2255
|
+
const creds = getCredentials();
|
|
2256
|
+
const apiUrl = await resolveBestApiUrl(typeof flags.url === "string" ? flags.url : creds?.apiUrl);
|
|
2257
|
+
const res = await apiRequest("/api/v1/extension/workspaces", { apiUrl });
|
|
2258
|
+
workspaces = res?.workspaces || res?.projects || [];
|
|
2259
|
+
} catch {
|
|
2260
|
+
// Session may be missing or unauthenticated
|
|
2261
|
+
}
|
|
2262
|
+
|
|
2263
|
+
if (workspaces.length === 0) {
|
|
2264
|
+
throw new Error(
|
|
2265
|
+
"No workspace linked in this directory. Run `nb login` followed by `nb init` to link a workspace.",
|
|
2266
|
+
);
|
|
2267
|
+
}
|
|
2268
|
+
|
|
2269
|
+
// If in interactive TTY and not json, offer immediate 1-click workspace selection
|
|
2270
|
+
if (process.stdin.isTTY && !flags.json) {
|
|
2271
|
+
renderBrandHeader({ subtitle: "Workspace Setup · Select a Workspace" });
|
|
2272
|
+
const chosen = await tuiSelect({
|
|
2273
|
+
title: "No workspace is linked to this directory. Choose one to link:",
|
|
2274
|
+
stepLabel: "Workspace",
|
|
2275
|
+
searchable: workspaces.length > 5,
|
|
2276
|
+
items: workspaces.map((w) => ({
|
|
2277
|
+
label: w.title,
|
|
2278
|
+
badge: formatStatusBadge(w.role || "member"),
|
|
2279
|
+
description: `ID: ${w.id}${w.slug ? ` · /${w.slug}` : ""}`,
|
|
2280
|
+
value: w,
|
|
2281
|
+
})),
|
|
2282
|
+
});
|
|
2283
|
+
|
|
2284
|
+
if (chosen) {
|
|
2285
|
+
const updatedCfg = {
|
|
2286
|
+
...cfg,
|
|
2287
|
+
projectId: chosen.id,
|
|
2288
|
+
title: chosen.title,
|
|
2289
|
+
slug: chosen.slug,
|
|
2290
|
+
};
|
|
2291
|
+
saveLocalConfig(updatedCfg, cwd);
|
|
2292
|
+
printStepDone("Linked Workspace", `${chosen.title} (${chosen.id})`);
|
|
2293
|
+
return { projectId: chosen.id, cfg: updatedCfg };
|
|
2294
|
+
}
|
|
2295
|
+
}
|
|
2296
|
+
|
|
2297
|
+
// Non-interactive or cancelled: output accessible workspaces so user or agent can select immediately
|
|
2298
|
+
const wsList = workspaces.map((w) => ` - ${w.title} (${w.id})`).join("\n");
|
|
2299
|
+
throw new Error(
|
|
2300
|
+
`No workspace linked. Run \`nb init\` or pass \`--workspace <id>\`.\nAvailable workspaces:\n${wsList}`,
|
|
2301
|
+
);
|
|
2302
|
+
}
|
|
2303
|
+
|
|
1999
2304
|
async function handleWorkspace(sub, positional, flags) {
|
|
2000
2305
|
if (sub === "switch" || (!sub && process.stdin.isTTY && !flags.json)) {
|
|
2001
2306
|
const target = positional[0] || flags.workspace;
|
|
@@ -2025,9 +2330,9 @@ async function handleWorkspace(sub, positional, flags) {
|
|
|
2025
2330
|
}
|
|
2026
2331
|
|
|
2027
2332
|
if (sub === "info") {
|
|
2028
|
-
const
|
|
2029
|
-
|
|
2030
|
-
const summary = await apiRequest(`/api/v1/extension/workspace-summary?projectId=${
|
|
2333
|
+
const cwd = process.cwd();
|
|
2334
|
+
const { projectId, cfg } = await ensureWorkspaceLinked(flags, cwd);
|
|
2335
|
+
const summary = await apiRequest(`/api/v1/extension/workspace-summary?projectId=${projectId}`);
|
|
2031
2336
|
outputResult({ workspace: cfg, summary }, flags, (res) => {
|
|
2032
2337
|
renderBrandHeader({
|
|
2033
2338
|
subtitle: "Workspace Summary",
|
|
@@ -2067,16 +2372,23 @@ async function hydrateTaskAttachedFiles(projectId, attachedFiles, cwd = process.
|
|
|
2067
2372
|
const cleanRel = normPath.replace(/^\/+/, "");
|
|
2068
2373
|
const mirrorDest = path.join(mirrorDir, cleanRel);
|
|
2069
2374
|
const expectedHash = (f.contentHash || manifestFiles[normPath]?.contentHash || "").toLowerCase();
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2375
|
+
const expectedVersion = f.currentVersion || f.version;
|
|
2376
|
+
const manifestVersion = manifestFiles[normPath]?.version;
|
|
2377
|
+
|
|
2378
|
+
if (fs.existsSync(mirrorDest)) {
|
|
2379
|
+
if (expectedHash) {
|
|
2380
|
+
try {
|
|
2381
|
+
const localHash = computeFileSha256(mirrorDest).hash.toLowerCase();
|
|
2382
|
+
if (localHash === expectedHash) {
|
|
2383
|
+
hydratedCount++;
|
|
2384
|
+
return;
|
|
2385
|
+
}
|
|
2386
|
+
} catch {
|
|
2387
|
+
// Re-download if unreadable
|
|
2077
2388
|
}
|
|
2078
|
-
}
|
|
2079
|
-
|
|
2389
|
+
} else if (expectedVersion && manifestVersion && expectedVersion === manifestVersion) {
|
|
2390
|
+
hydratedCount++;
|
|
2391
|
+
return;
|
|
2080
2392
|
}
|
|
2081
2393
|
}
|
|
2082
2394
|
|
|
@@ -2231,8 +2543,8 @@ function renderTaskDetailCard(res, cfg, hydratedCount = 0) {
|
|
|
2231
2543
|
|
|
2232
2544
|
async function handleTask(sub, positional, flags) {
|
|
2233
2545
|
const cwd = process.cwd();
|
|
2234
|
-
|
|
2235
|
-
|
|
2546
|
+
let cfg = getLocalConfig(cwd);
|
|
2547
|
+
let projectId = typeof flags.workspace === "string" ? flags.workspace : cfg.projectId;
|
|
2236
2548
|
|
|
2237
2549
|
// Support `nb task list --all` / `nb task --all-workspaces` across all accessible workspaces
|
|
2238
2550
|
if ((!sub || sub === "list" || sub === "ls") && (flags.all || flags["all-workspaces"])) {
|
|
@@ -2281,7 +2593,7 @@ async function handleTask(sub, positional, flags) {
|
|
|
2281
2593
|
return;
|
|
2282
2594
|
}
|
|
2283
2595
|
|
|
2284
|
-
|
|
2596
|
+
({ projectId, cfg } = await ensureWorkspaceLinked(flags, cwd));
|
|
2285
2597
|
|
|
2286
2598
|
// Allow shorthand `nb task #4` or `nb task 4` to directly open `nb task view #4`
|
|
2287
2599
|
if (sub && (/^#?\d+$/.test(sub) || /^[0-9a-f]{8}-[0-9a-f]{4}-/i.test(sub))) {
|
|
@@ -2289,6 +2601,73 @@ async function handleTask(sub, positional, flags) {
|
|
|
2289
2601
|
sub = "view";
|
|
2290
2602
|
}
|
|
2291
2603
|
|
|
2604
|
+
if (sub === "create" || sub === "new" || sub === "add") {
|
|
2605
|
+
let title = typeof flags.title === "string" ? flags.title : positional.join(" ").trim();
|
|
2606
|
+
if (!title && process.stdin.isTTY && !flags.json) {
|
|
2607
|
+
renderBrandHeader({ subtitle: `Create Sprint Task · ${cfg.title || projectId}` });
|
|
2608
|
+
title = await tuiInput({
|
|
2609
|
+
title: "Enter task title",
|
|
2610
|
+
stepLabel: "Task Title",
|
|
2611
|
+
placeholder: "e.g., Implement OAuth callback flow",
|
|
2612
|
+
});
|
|
2613
|
+
}
|
|
2614
|
+
if (!title) {
|
|
2615
|
+
throw new Error('Usage: nb task create "<title>" [-m description] [--priority low|medium|high|urgent]');
|
|
2616
|
+
}
|
|
2617
|
+
|
|
2618
|
+
const description =
|
|
2619
|
+
typeof flags.message === "string"
|
|
2620
|
+
? flags.message
|
|
2621
|
+
: typeof flags.description === "string"
|
|
2622
|
+
? flags.description
|
|
2623
|
+
: undefined;
|
|
2624
|
+
const priority =
|
|
2625
|
+
flags.priority && ["low", "medium", "high", "urgent"].includes(flags.priority.toLowerCase())
|
|
2626
|
+
? flags.priority.toLowerCase()
|
|
2627
|
+
: "medium";
|
|
2628
|
+
|
|
2629
|
+
const createdRes = await withSpinner(
|
|
2630
|
+
"Creating sprint task…",
|
|
2631
|
+
() =>
|
|
2632
|
+
apiRequest("/api/v1/extension/create-task", {
|
|
2633
|
+
method: "POST",
|
|
2634
|
+
body: {
|
|
2635
|
+
projectId,
|
|
2636
|
+
title,
|
|
2637
|
+
description,
|
|
2638
|
+
priority,
|
|
2639
|
+
},
|
|
2640
|
+
}),
|
|
2641
|
+
{ silent: Boolean(flags.json) },
|
|
2642
|
+
);
|
|
2643
|
+
|
|
2644
|
+
// Refresh local tasks and TASKS.md immediately
|
|
2645
|
+
try {
|
|
2646
|
+
const refreshed = await apiRequest(`/api/v1/extension/workspace-tasks?projectId=${projectId}&scope=all`);
|
|
2647
|
+
writeLocalTaskIntelligence(projectId, cfg.title || projectId, refreshed.tasks || [], cwd);
|
|
2648
|
+
} catch {}
|
|
2649
|
+
|
|
2650
|
+
const createdTask = createdRes.task || createdRes;
|
|
2651
|
+
outputResult(
|
|
2652
|
+
createdRes,
|
|
2653
|
+
flags,
|
|
2654
|
+
() => {
|
|
2655
|
+
console.log(RAIL);
|
|
2656
|
+
console.log(
|
|
2657
|
+
`${STEP_DONE} ${c.bold}${c.ink}Created Task ${createdTask.taskNumber ? `#${createdTask.taskNumber}` : createdTask.id}${c.reset} ${formatPriorityBadge(priority)} ${formatStatusBadge("todo")}`,
|
|
2658
|
+
);
|
|
2659
|
+
console.log(`${RAIL} ${c.ink}${createdTask.title || title}${c.reset}`);
|
|
2660
|
+
if (description) {
|
|
2661
|
+
console.log(`${RAIL} ${c.muted}${description.slice(0, 100)}${c.reset}`);
|
|
2662
|
+
}
|
|
2663
|
+
console.log(
|
|
2664
|
+
`${c.dim}╰─${c.reset} Run ${c.accent}nb task work ${createdTask.taskNumber ? `#${createdTask.taskNumber}` : createdTask.id}${c.reset} to begin working on it.\n`,
|
|
2665
|
+
);
|
|
2666
|
+
},
|
|
2667
|
+
);
|
|
2668
|
+
return;
|
|
2669
|
+
}
|
|
2670
|
+
|
|
2292
2671
|
if (sub === "work") {
|
|
2293
2672
|
let rawTarget = positional[0];
|
|
2294
2673
|
if (!rawTarget && process.stdin.isTTY && !flags.json) {
|
|
@@ -2546,6 +2925,77 @@ async function handleTask(sub, positional, flags) {
|
|
|
2546
2925
|
return;
|
|
2547
2926
|
}
|
|
2548
2927
|
|
|
2928
|
+
if (sub === "subtask" || sub === "subtasks") {
|
|
2929
|
+
const action = positional[0];
|
|
2930
|
+
if (action === "add" || action === "create" || action === "new") {
|
|
2931
|
+
let args = positional.slice(1);
|
|
2932
|
+
const rawTask = flags.task ? String(flags.task) : null;
|
|
2933
|
+
let targetTaskId = rawTask ? resolveTaskIdentifier(rawTask, cwd) : null;
|
|
2934
|
+
|
|
2935
|
+
// Check if next arg is a task identifier (e.g. #4, 4, or UUID)
|
|
2936
|
+
if (!targetTaskId && args.length > 1 && (/^#?\d+$/.test(args[0]) || /^[0-9a-f]{8}-[0-9a-f]{4}-/i.test(args[0]))) {
|
|
2937
|
+
targetTaskId = resolveTaskIdentifier(args.shift(), cwd);
|
|
2938
|
+
}
|
|
2939
|
+
if (!targetTaskId) {
|
|
2940
|
+
const inferred = inferActiveTaskId(flags, cwd);
|
|
2941
|
+
if (inferred) targetTaskId = resolveTaskIdentifier(inferred, cwd);
|
|
2942
|
+
}
|
|
2943
|
+
|
|
2944
|
+
if (!targetTaskId) {
|
|
2945
|
+
throw new Error("No active task bound. Specify task with `#<number>` or pass `--task <#number>`.");
|
|
2946
|
+
}
|
|
2947
|
+
|
|
2948
|
+
const title = flags.title || flags.message || args.join(" ").trim();
|
|
2949
|
+
if (!title) {
|
|
2950
|
+
throw new Error('Usage: nb task subtask add [#number] "<subtask title>"');
|
|
2951
|
+
}
|
|
2952
|
+
|
|
2953
|
+
const detail = await apiRequest(
|
|
2954
|
+
`/api/v1/extension/task-detail?projectId=${projectId}&taskId=${encodeURIComponent(targetTaskId)}`,
|
|
2955
|
+
);
|
|
2956
|
+
const task = detail.task;
|
|
2957
|
+
|
|
2958
|
+
const created = await withSpinner(
|
|
2959
|
+
`Creating subtask on "${task.title}"…`,
|
|
2960
|
+
() =>
|
|
2961
|
+
apiRequest("/api/v1/extension/task-subtask", {
|
|
2962
|
+
method: "POST",
|
|
2963
|
+
body: {
|
|
2964
|
+
projectId,
|
|
2965
|
+
taskId: task.id,
|
|
2966
|
+
title,
|
|
2967
|
+
},
|
|
2968
|
+
}),
|
|
2969
|
+
{ silent: Boolean(flags.json) },
|
|
2970
|
+
);
|
|
2971
|
+
|
|
2972
|
+
// Refresh local tasks and TASKS.md immediately
|
|
2973
|
+
try {
|
|
2974
|
+
const refreshed = await apiRequest(`/api/v1/extension/workspace-tasks?projectId=${projectId}&scope=all`);
|
|
2975
|
+
writeLocalTaskIntelligence(projectId, cfg.title || projectId, refreshed.tasks || [], cwd);
|
|
2976
|
+
} catch {}
|
|
2977
|
+
|
|
2978
|
+
outputResult(
|
|
2979
|
+
{
|
|
2980
|
+
taskId: task.id,
|
|
2981
|
+
taskNumber: task.taskNumber,
|
|
2982
|
+
taskTitle: task.title,
|
|
2983
|
+
subtask: created.subtask,
|
|
2984
|
+
},
|
|
2985
|
+
flags,
|
|
2986
|
+
(res) => {
|
|
2987
|
+
console.log(RAIL);
|
|
2988
|
+
console.log(
|
|
2989
|
+
`${STEP_DONE} ${c.bold}${c.ink}Created subtask on Task ${res.taskNumber ? `#${res.taskNumber}` : res.taskId}${c.reset} ${c.muted}("${res.taskTitle}")${c.reset}`,
|
|
2990
|
+
);
|
|
2991
|
+
console.log(`${RAIL} ${c.muted}[ ]${c.reset} ${c.ink}${res.subtask.title}${c.reset}`);
|
|
2992
|
+
console.log(`${c.dim}╰─${c.reset} Subtask added and synced to .networkbase/tasks/TASKS.md\n`);
|
|
2993
|
+
},
|
|
2994
|
+
);
|
|
2995
|
+
return;
|
|
2996
|
+
}
|
|
2997
|
+
}
|
|
2998
|
+
|
|
2549
2999
|
if (sub === "check" || sub === "subtask" || sub === "subtasks") {
|
|
2550
3000
|
const rawTaskTarget = flags.task ? String(flags.task) : inferActiveTaskId(flags, cwd);
|
|
2551
3001
|
let targetTaskId = rawTaskTarget ? resolveTaskIdentifier(rawTaskTarget, cwd) : null;
|
|
@@ -2693,6 +3143,11 @@ async function handleTask(sub, positional, flags) {
|
|
|
2693
3143
|
expectedUpdatedAt: new Date(task.updatedAt).toISOString(),
|
|
2694
3144
|
},
|
|
2695
3145
|
});
|
|
3146
|
+
// Refresh local tasks and TASKS.md immediately
|
|
3147
|
+
try {
|
|
3148
|
+
const refreshed = await apiRequest(`/api/v1/extension/workspace-tasks?projectId=${projectId}&scope=all`);
|
|
3149
|
+
writeLocalTaskIntelligence(projectId, cfg.title || projectId, refreshed.tasks || [], cwd);
|
|
3150
|
+
} catch {}
|
|
2696
3151
|
outputResult(updated, flags, () => {
|
|
2697
3152
|
console.log(
|
|
2698
3153
|
`\n${c.emerald}✔${c.reset} Task ${c.bold}${c.ink}"${task.title}"${c.reset} marked as ${formatStatusBadge("done")}\n`,
|
|
@@ -2761,6 +3216,11 @@ async function handleTask(sub, positional, flags) {
|
|
|
2761
3216
|
method: "POST",
|
|
2762
3217
|
body: { taskId: detail.task.id, content },
|
|
2763
3218
|
});
|
|
3219
|
+
// Refresh local tasks and TASKS.md immediately
|
|
3220
|
+
try {
|
|
3221
|
+
const refreshed = await apiRequest(`/api/v1/extension/workspace-tasks?projectId=${projectId}&scope=all`);
|
|
3222
|
+
writeLocalTaskIntelligence(projectId, cfg.title || projectId, refreshed.tasks || [], cwd);
|
|
3223
|
+
} catch {}
|
|
2764
3224
|
outputResult(created, flags, () => {
|
|
2765
3225
|
console.log(`\n${c.emerald}✔${c.reset} Posted comment to task "${detail.task.title}"\n`);
|
|
2766
3226
|
});
|
|
@@ -2822,9 +3282,8 @@ async function downloadRemoteFileBuffer(projectId, remotePath, options = {}) {
|
|
|
2822
3282
|
}
|
|
2823
3283
|
|
|
2824
3284
|
async function handleFile(sub, positional, flags) {
|
|
2825
|
-
const
|
|
2826
|
-
const projectId = flags
|
|
2827
|
-
if (!projectId) throw new Error("No workspace linked. Run `nb init` first.");
|
|
3285
|
+
const cwd = process.cwd();
|
|
3286
|
+
const { projectId, cfg } = await ensureWorkspaceLinked(flags, cwd);
|
|
2828
3287
|
|
|
2829
3288
|
if (sub === "ls" || !sub) {
|
|
2830
3289
|
const filterQuery = positional[0] || "";
|
|
@@ -2976,9 +3435,9 @@ async function handleFile(sub, positional, flags) {
|
|
|
2976
3435
|
throw new Error(`Unknown file subcommand: ${sub}`);
|
|
2977
3436
|
}
|
|
2978
3437
|
|
|
2979
|
-
function prepareLocalFilesForPush(targetPaths, flags, cwd = process.cwd()) {
|
|
3438
|
+
function prepareLocalFilesForPush(targetPaths, flags, cwd = process.cwd(), explicitProjectId = null) {
|
|
2980
3439
|
const cfg = getLocalConfig(cwd);
|
|
2981
|
-
const projectId = flags.workspace || cfg.projectId;
|
|
3440
|
+
const projectId = explicitProjectId || flags.workspace || cfg.projectId;
|
|
2982
3441
|
if (!projectId) {
|
|
2983
3442
|
throw new Error("No workspace linked in this directory. Run `nb init` first.");
|
|
2984
3443
|
}
|
|
@@ -3064,7 +3523,7 @@ function prepareLocalFilesForPush(targetPaths, flags, cwd = process.cwd()) {
|
|
|
3064
3523
|
};
|
|
3065
3524
|
}
|
|
3066
3525
|
|
|
3067
|
-
async function executePrePushAnalysis(targetPaths, flags, cwd = process.cwd()) {
|
|
3526
|
+
async function executePrePushAnalysis(targetPaths, flags, cwd = process.cwd(), explicitProjectId = null) {
|
|
3068
3527
|
const {
|
|
3069
3528
|
projectId,
|
|
3070
3529
|
taskId,
|
|
@@ -3072,7 +3531,7 @@ async function executePrePushAnalysis(targetPaths, flags, cwd = process.cwd()) {
|
|
|
3072
3531
|
allPreparedCount,
|
|
3073
3532
|
skippedByLocalManifestCount,
|
|
3074
3533
|
secretViolations,
|
|
3075
|
-
} = prepareLocalFilesForPush(targetPaths, flags, cwd);
|
|
3534
|
+
} = prepareLocalFilesForPush(targetPaths, flags, cwd, explicitProjectId);
|
|
3076
3535
|
|
|
3077
3536
|
const analysis = await apiRequest("/api/v1/extension/pre-push", {
|
|
3078
3537
|
method: "POST",
|
|
@@ -3157,7 +3616,8 @@ async function executeFastPushRequest({
|
|
|
3157
3616
|
}
|
|
3158
3617
|
|
|
3159
3618
|
async function handlePush(positional, flags, { skipHeader = false } = {}) {
|
|
3160
|
-
const
|
|
3619
|
+
const cwd = process.cwd();
|
|
3620
|
+
const { projectId, cfg } = await ensureWorkspaceLinked(flags, cwd);
|
|
3161
3621
|
if (!flags.json && !skipHeader && !flags["dry-run"]) {
|
|
3162
3622
|
renderBrandHeader({
|
|
3163
3623
|
subtitle: `High-EQ Smart Push · ${cfg.title || flags.workspace || "Workspace"}`,
|
|
@@ -3165,20 +3625,20 @@ async function handlePush(positional, flags, { skipHeader = false } = {}) {
|
|
|
3165
3625
|
}
|
|
3166
3626
|
|
|
3167
3627
|
const explicitRole = resolveRoleFromFlags(flags);
|
|
3628
|
+
const isAuto = Boolean(flags.yes || flags.y || flags.auto || !process.stdin.isTTY);
|
|
3168
3629
|
const transitionFromFlags = flags.done ? "done" : flags.wip ? "in_progress" : undefined;
|
|
3169
3630
|
|
|
3170
3631
|
// ULTRA-FAST 1-ROUND-TRIP PATH:
|
|
3171
|
-
// When role is already specified (e.g. --deliverable / --draft / --reference / --json)
|
|
3632
|
+
// When role is already specified (e.g. --deliverable / --draft / --reference / --json) or auto/non-TTY,
|
|
3172
3633
|
// skip /pre-push completely and execute atomic /fast-push in 1 single HTTP round-trip!
|
|
3173
|
-
if (!flags["dry-run"] && (explicitRole || flags.json ||
|
|
3634
|
+
if (!flags["dry-run"] && (explicitRole || flags.json || isAuto)) {
|
|
3174
3635
|
const {
|
|
3175
|
-
projectId,
|
|
3176
3636
|
taskId,
|
|
3177
3637
|
preparedFiles,
|
|
3178
3638
|
allPreparedCount,
|
|
3179
3639
|
skippedByLocalManifestCount,
|
|
3180
3640
|
secretViolations,
|
|
3181
|
-
} = prepareLocalFilesForPush(positional, flags);
|
|
3641
|
+
} = prepareLocalFilesForPush(positional, flags, cwd, projectId);
|
|
3182
3642
|
|
|
3183
3643
|
if (secretViolations.length > 0 && !flags["allow-secrets"]) {
|
|
3184
3644
|
const errPayload = {
|
|
@@ -3280,12 +3740,17 @@ async function handlePush(positional, flags, { skipHeader = false } = {}) {
|
|
|
3280
3740
|
console.log(`${c.dim}╰─${c.reset} ${c.emerald}✔${c.reset} Sync complete.\n`);
|
|
3281
3741
|
}
|
|
3282
3742
|
});
|
|
3743
|
+
if (projectId) {
|
|
3744
|
+
try {
|
|
3745
|
+
const refreshed = await apiRequest(`/api/v1/extension/workspace-tasks?projectId=${projectId}&scope=all`);
|
|
3746
|
+
writeLocalTaskIntelligence(projectId, cfg.title || projectId, refreshed.tasks || [], cwd);
|
|
3747
|
+
} catch {}
|
|
3748
|
+
}
|
|
3283
3749
|
return finalFast;
|
|
3284
3750
|
}
|
|
3285
3751
|
}
|
|
3286
3752
|
|
|
3287
3753
|
const {
|
|
3288
|
-
projectId,
|
|
3289
3754
|
taskId,
|
|
3290
3755
|
preparedFiles,
|
|
3291
3756
|
skippedByLocalManifestCount,
|
|
@@ -3293,7 +3758,7 @@ async function handlePush(positional, flags, { skipHeader = false } = {}) {
|
|
|
3293
3758
|
analysis,
|
|
3294
3759
|
} = await withSpinner(
|
|
3295
3760
|
"Analyzing local files & SHA-256 manifest…",
|
|
3296
|
-
() => executePrePushAnalysis(positional, flags),
|
|
3761
|
+
() => executePrePushAnalysis(positional, flags, cwd, projectId),
|
|
3297
3762
|
{ silent: Boolean(flags.json) },
|
|
3298
3763
|
);
|
|
3299
3764
|
|
|
@@ -3357,7 +3822,7 @@ async function handlePush(positional, flags, { skipHeader = false } = {}) {
|
|
|
3357
3822
|
let selectedRole = explicitRole;
|
|
3358
3823
|
|
|
3359
3824
|
// Interactive Multi-File Selection & Role Classification when running in a terminal without flags
|
|
3360
|
-
if (process.stdin.isTTY && !flags.json && !selectedRole) {
|
|
3825
|
+
if (process.stdin.isTTY && !flags.json && !selectedRole && !isAuto) {
|
|
3361
3826
|
if (changedAnalysisFiles.length > 1) {
|
|
3362
3827
|
const chosenPaths = await tuiMultiSelect({
|
|
3363
3828
|
title: "Select changed files to include in this push",
|
|
@@ -3427,7 +3892,8 @@ async function handlePush(positional, flags, { skipHeader = false } = {}) {
|
|
|
3427
3892
|
selectedRole === "deliverable" &&
|
|
3428
3893
|
!transitionStatus &&
|
|
3429
3894
|
process.stdin.isTTY &&
|
|
3430
|
-
!flags.json
|
|
3895
|
+
!flags.json &&
|
|
3896
|
+
!isAuto
|
|
3431
3897
|
) {
|
|
3432
3898
|
const taskTitle = analysis.task?.title || taskId;
|
|
3433
3899
|
const markDone = await tuiConfirm({
|
|
@@ -3662,13 +4128,19 @@ async function handlePush(positional, flags, { skipHeader = false } = {}) {
|
|
|
3662
4128
|
}
|
|
3663
4129
|
});
|
|
3664
4130
|
|
|
4131
|
+
if (projectId) {
|
|
4132
|
+
try {
|
|
4133
|
+
const refreshed = await apiRequest(`/api/v1/extension/workspace-tasks?projectId=${projectId}&scope=all`);
|
|
4134
|
+
writeLocalTaskIntelligence(projectId, cfg.title || projectId, refreshed.tasks || [], cwd);
|
|
4135
|
+
} catch {}
|
|
4136
|
+
}
|
|
4137
|
+
|
|
3665
4138
|
return finalPayload;
|
|
3666
4139
|
}
|
|
3667
4140
|
|
|
3668
4141
|
async function handlePull(positional, flags, { skipHeader = false } = {}) {
|
|
3669
|
-
const
|
|
3670
|
-
const projectId = flags
|
|
3671
|
-
if (!projectId) throw new Error("No workspace linked. Run `nb init` first.");
|
|
4142
|
+
const cwd = process.cwd();
|
|
4143
|
+
const { projectId, cfg } = await ensureWorkspaceLinked(flags, cwd);
|
|
3672
4144
|
|
|
3673
4145
|
if (!flags.json && !skipHeader) {
|
|
3674
4146
|
renderBrandHeader({ subtitle: `Pull Workspace Files · ${cfg.title || projectId}` });
|
|
@@ -3898,18 +4370,7 @@ async function hydrateWorkspaceMirror(projectId, { cwd = process.cwd(), force =
|
|
|
3898
4370
|
|
|
3899
4371
|
async function handleSync(positional, flags) {
|
|
3900
4372
|
const cwd = process.cwd();
|
|
3901
|
-
let cfg =
|
|
3902
|
-
|
|
3903
|
-
// Allow switching workspace in the same single `nb sync --workspace <slug-or-id>` call
|
|
3904
|
-
if (typeof flags.workspace === "string" && flags.workspace.trim() && flags.workspace !== cfg.projectId) {
|
|
3905
|
-
await handleInit([flags.workspace.trim()], { ...flags, "no-task": true, silent: true }, { skipHeader: true });
|
|
3906
|
-
cfg = getLocalConfig(cwd);
|
|
3907
|
-
}
|
|
3908
|
-
|
|
3909
|
-
const projectId = cfg.projectId;
|
|
3910
|
-
if (!projectId) {
|
|
3911
|
-
throw new Error("No workspace linked. Run `nb init` first.");
|
|
3912
|
-
}
|
|
4373
|
+
let { projectId, cfg } = await ensureWorkspaceLinked(flags, cwd);
|
|
3913
4374
|
|
|
3914
4375
|
if (!flags.json) {
|
|
3915
4376
|
renderBrandHeader({ subtitle: `Unified One-Permission Sync · ${cfg.title || projectId}` });
|
|
@@ -4035,9 +4496,7 @@ async function handleSync(positional, flags) {
|
|
|
4035
4496
|
|
|
4036
4497
|
async function handleWatch(positional, flags) {
|
|
4037
4498
|
const cwd = process.cwd();
|
|
4038
|
-
const cfg =
|
|
4039
|
-
const projectId = flags.workspace || cfg.projectId;
|
|
4040
|
-
if (!projectId) throw new Error("No workspace linked. Run `nb init` first.");
|
|
4499
|
+
const { projectId, cfg } = await ensureWorkspaceLinked(flags, cwd);
|
|
4041
4500
|
|
|
4042
4501
|
const isDaemonWorker = Boolean(flags["daemon-worker"]);
|
|
4043
4502
|
const role = resolveRoleFromFlags(flags) || "deliverable";
|
|
@@ -4478,6 +4937,31 @@ async function startMcpServer() {
|
|
|
4478
4937
|
properties: { paths: { type: "array", items: { type: "string" } } },
|
|
4479
4938
|
},
|
|
4480
4939
|
},
|
|
4940
|
+
{
|
|
4941
|
+
name: "nb_subtask_create",
|
|
4942
|
+
description: "Create a new subtask checklist item on a Sprint Task in NetworkBase.",
|
|
4943
|
+
inputSchema: {
|
|
4944
|
+
type: "object",
|
|
4945
|
+
properties: {
|
|
4946
|
+
taskId: { type: "string", description: "Task UUID or task number (e.g. #4 or 4)" },
|
|
4947
|
+
title: { type: "string", description: "Subtask title / description" },
|
|
4948
|
+
},
|
|
4949
|
+
required: ["taskId", "title"],
|
|
4950
|
+
},
|
|
4951
|
+
},
|
|
4952
|
+
{
|
|
4953
|
+
name: "nb_task_create",
|
|
4954
|
+
description: "Create a new Sprint Task in the active NetworkBase workspace.",
|
|
4955
|
+
inputSchema: {
|
|
4956
|
+
type: "object",
|
|
4957
|
+
properties: {
|
|
4958
|
+
title: { type: "string", description: "Task title" },
|
|
4959
|
+
description: { type: "string", description: "Optional markdown description" },
|
|
4960
|
+
priority: { type: "string", enum: ["low", "medium", "high", "urgent"] },
|
|
4961
|
+
},
|
|
4962
|
+
required: ["title"],
|
|
4963
|
+
},
|
|
4964
|
+
},
|
|
4481
4965
|
],
|
|
4482
4966
|
});
|
|
4483
4967
|
return;
|
|
@@ -4663,6 +5147,51 @@ async function startMcpServer() {
|
|
|
4663
5147
|
return;
|
|
4664
5148
|
}
|
|
4665
5149
|
|
|
5150
|
+
if (toolName === "nb_subtask_create") {
|
|
5151
|
+
const cfg = getLocalConfig();
|
|
5152
|
+
const targetId = resolveTaskIdentifier(args.taskId || getLocalState()?.activeTaskId);
|
|
5153
|
+
const detail = await apiRequest(
|
|
5154
|
+
`/api/v1/extension/task-detail?projectId=${cfg.projectId}&taskId=${encodeURIComponent(targetId)}`,
|
|
5155
|
+
);
|
|
5156
|
+
const res = await apiRequest("/api/v1/extension/task-subtask", {
|
|
5157
|
+
method: "POST",
|
|
5158
|
+
body: {
|
|
5159
|
+
projectId: cfg.projectId,
|
|
5160
|
+
taskId: detail.task.id,
|
|
5161
|
+
title: args.title,
|
|
5162
|
+
},
|
|
5163
|
+
});
|
|
5164
|
+
try {
|
|
5165
|
+
const refreshed = await apiRequest(`/api/v1/extension/workspace-tasks?projectId=${cfg.projectId}&scope=all`);
|
|
5166
|
+
writeLocalTaskIntelligence(cfg.projectId, cfg.title || cfg.projectId, refreshed.tasks || []);
|
|
5167
|
+
} catch {}
|
|
5168
|
+
sendJsonRpc(id, {
|
|
5169
|
+
content: [{ type: "text", text: JSON.stringify(res, null, 2) }],
|
|
5170
|
+
});
|
|
5171
|
+
return;
|
|
5172
|
+
}
|
|
5173
|
+
|
|
5174
|
+
if (toolName === "nb_task_create") {
|
|
5175
|
+
const cfg = getLocalConfig();
|
|
5176
|
+
const res = await apiRequest("/api/v1/extension/create-task", {
|
|
5177
|
+
method: "POST",
|
|
5178
|
+
body: {
|
|
5179
|
+
projectId: cfg.projectId,
|
|
5180
|
+
title: args.title,
|
|
5181
|
+
description: args.description,
|
|
5182
|
+
priority: args.priority || "medium",
|
|
5183
|
+
},
|
|
5184
|
+
});
|
|
5185
|
+
try {
|
|
5186
|
+
const refreshed = await apiRequest(`/api/v1/extension/workspace-tasks?projectId=${cfg.projectId}&scope=all`);
|
|
5187
|
+
writeLocalTaskIntelligence(cfg.projectId, cfg.title || cfg.projectId, refreshed.tasks || []);
|
|
5188
|
+
} catch {}
|
|
5189
|
+
sendJsonRpc(id, {
|
|
5190
|
+
content: [{ type: "text", text: JSON.stringify(res, null, 2) }],
|
|
5191
|
+
});
|
|
5192
|
+
return;
|
|
5193
|
+
}
|
|
5194
|
+
|
|
4666
5195
|
sendJsonRpc(id, null, { code: -32601, message: `Unknown tool: ${toolName}` });
|
|
4667
5196
|
}
|
|
4668
5197
|
} catch (err) {
|
|
@@ -4694,15 +5223,21 @@ Core Commands:
|
|
|
4694
5223
|
nb auth setup-git Configure Git HTTPS credential helper
|
|
4695
5224
|
nb workspace list | switch List or switch active NetworkBase workspaces
|
|
4696
5225
|
nb task [list] [--all | --mine] View project tasks, descriptions, subtasks & attached files
|
|
5226
|
+
nb task <#number|id> Shorthand to inspect task details & mirror attached files
|
|
4697
5227
|
nb task view <#number|id> Inspect task description, subtasks & mirror attached files
|
|
4698
5228
|
nb task work <#number|id> Bind active task, transition to in_progress & mirror files
|
|
4699
|
-
nb task
|
|
5229
|
+
nb task create "<title>" [-m] Create a new sprint task (--priority low|medium|high|urgent)
|
|
5230
|
+
nb task subtask add [#id] <t> Add a new subtask checklist item to active or specified task
|
|
5231
|
+
nb task check [#id] [1 2|--all] Toggle subtasks interactively (Space) or via CLI numbers
|
|
4700
5232
|
nb task done [#number|id] Mark active or specified task as Done
|
|
5233
|
+
nb task comment <#id> <message> Add a comment to active or specified task
|
|
5234
|
+
nb task status View sprint & task health metrics and completion rate
|
|
4701
5235
|
nb file ls | log | diff | lock Inspect workspace files, history, diffs, or CLI locks
|
|
4702
5236
|
nb hook install Install local .git/hooks/pre-push secret scanner
|
|
4703
5237
|
nb pull [paths...] Download remote workspace files to local directory
|
|
4704
5238
|
nb watch [paths...] Live debounced auto-sync watcher (1-RTT fast-push on save)
|
|
4705
5239
|
nb push [paths...] High-EQ Smart Push (SHA-256 diff + v1->v2 bump + task link)
|
|
5240
|
+
-y, --yes, --auto Non-interactive push with smart defaults (no prompt blocking)
|
|
4706
5241
|
--deliverable Classify pushed files as Final Deliverable (#deliverable)
|
|
4707
5242
|
--draft Classify pushed files as Working Draft (#editor_working)
|
|
4708
5243
|
--reference Classify pushed files as Reference Material (#reference)
|