@bolt-cli/cli 0.15.0 → 0.15.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cli.js +70 -13
- package/package.json +1 -1
package/lib/cli.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
const fs = require("fs");
|
|
5
5
|
const os = require("os");
|
|
6
6
|
const path = require("path");
|
|
7
|
-
const { spawn } = require("node:child_process");
|
|
7
|
+
const { spawn, execFileSync } = require("node:child_process");
|
|
8
8
|
const config = require("./config");
|
|
9
9
|
const api = require("./api");
|
|
10
10
|
const browser = require("./browser");
|
|
@@ -1394,31 +1394,88 @@ async function cmdDoctor() {
|
|
|
1394
1394
|
}
|
|
1395
1395
|
|
|
1396
1396
|
// ── update ────────────────────────────────────────────────────────────────
|
|
1397
|
-
// `bolt update`
|
|
1398
|
-
//
|
|
1399
|
-
//
|
|
1397
|
+
// `bolt update` runs npm to upgrade the globally installed package. On Windows
|
|
1398
|
+
// npm is a .cmd: newer Node refuses to spawn it directly (EINVAL), while
|
|
1399
|
+
// `shell: true` triggers DEP0190 and concatenates the arguments unescaped.
|
|
1400
|
+
// cmd.exe with one fixed command line avoids both. No argument here is
|
|
1401
|
+
// user-controlled; stdio is inherited so npm's progress shows as-is.
|
|
1402
|
+
function npmInvocation(args) {
|
|
1403
|
+
return process.platform === "win32"
|
|
1404
|
+
? { command: "cmd.exe", args: ["/d", "/s", "/c", ["npm", ...args].join(" ")] }
|
|
1405
|
+
: { command: "npm", args };
|
|
1406
|
+
}
|
|
1407
|
+
|
|
1408
|
+
// What is actually on disk in the global prefix? A zero npm exit does not
|
|
1409
|
+
// guarantee the package was replaced — Windows can keep the running CLI's
|
|
1410
|
+
// files locked — so the install is verified before claiming success. "" means
|
|
1411
|
+
// the prefix could not be read and no claim is made.
|
|
1412
|
+
function installedCliVersion() {
|
|
1413
|
+
try {
|
|
1414
|
+
const inv = npmInvocation(["root", "-g"]);
|
|
1415
|
+
const root = execFileSync(inv.command, inv.args, { encoding: "utf8", windowsHide: true }).trim();
|
|
1416
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(root, "@bolt-cli", "cli", "package.json"), "utf8"));
|
|
1417
|
+
return String(pkg.version || "");
|
|
1418
|
+
} catch {
|
|
1419
|
+
return "";
|
|
1420
|
+
}
|
|
1421
|
+
}
|
|
1422
|
+
|
|
1423
|
+
// Latest published version, used only to explain an "unchanged" install:
|
|
1424
|
+
// already-current is fine, but being behind means npm failed to replace us.
|
|
1425
|
+
function registryLatest() {
|
|
1426
|
+
try {
|
|
1427
|
+
const inv = npmInvocation(["view", "@bolt-cli/cli", "version"]);
|
|
1428
|
+
return execFileSync(inv.command, inv.args, { encoding: "utf8", timeout: 8000, windowsHide: true }).trim();
|
|
1429
|
+
} catch {
|
|
1430
|
+
return "";
|
|
1431
|
+
}
|
|
1432
|
+
}
|
|
1433
|
+
|
|
1434
|
+
// Pure outcome classifier for the self-update. "unchanged" is the important
|
|
1435
|
+
// case: npm exited zero but the old version is still installed. Tested.
|
|
1436
|
+
function updateOutcome(installed, current) {
|
|
1437
|
+
if (!installed) return "unknown";
|
|
1438
|
+
return String(installed) === String(current) ? "unchanged" : "upgraded";
|
|
1439
|
+
}
|
|
1440
|
+
|
|
1400
1441
|
function cmdUpdate() {
|
|
1401
1442
|
console.log(`running: npm install -g @bolt-cli/cli (current: v${VERSION})`);
|
|
1402
|
-
const
|
|
1443
|
+
const inv = npmInvocation(["install", "-g", "@bolt-cli/cli"]);
|
|
1444
|
+
const child = spawn(inv.command, inv.args, { stdio: "inherit", windowsHide: true });
|
|
1403
1445
|
return new Promise((resolve) => {
|
|
1404
1446
|
child.on("error", (error) => {
|
|
1405
1447
|
ui.err(`update failed: ${error.message} - try: npm install -g @bolt-cli/cli`);
|
|
1406
1448
|
resolve();
|
|
1407
1449
|
});
|
|
1408
1450
|
child.on("close", (code) => {
|
|
1409
|
-
if (code
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1451
|
+
if (code !== 0) {
|
|
1452
|
+
ui.err(`update failed (exit ${code}) - try: npm install -g @bolt-cli/cli`);
|
|
1453
|
+
resolve();
|
|
1454
|
+
return;
|
|
1455
|
+
}
|
|
1456
|
+
const installed = installedCliVersion();
|
|
1457
|
+
const outcome = updateOutcome(installed, VERSION);
|
|
1458
|
+
if (outcome === "upgraded") {
|
|
1459
|
+
// Clear the cached check only after a verified upgrade, so the next
|
|
1460
|
+
// session re-verifies instead of greeting itself with stale news.
|
|
1413
1461
|
try {
|
|
1414
1462
|
const cfg = config.load();
|
|
1415
1463
|
config.save({ ...cfg, updateCheckedAt: 0, updateLatest: "" });
|
|
1416
1464
|
} catch {
|
|
1417
|
-
// Cache hygiene is best-effort; the
|
|
1465
|
+
// Cache hygiene is best-effort; the install itself succeeded.
|
|
1466
|
+
}
|
|
1467
|
+
ui.ok(`update complete - v${installed} installed; restart bolt to run it`);
|
|
1468
|
+
} else if (outcome === "unchanged") {
|
|
1469
|
+
const latest = registryLatest();
|
|
1470
|
+
if (latest && String(latest) === String(installed)) {
|
|
1471
|
+
ui.ok(`already on the latest version (v${installed})`);
|
|
1472
|
+
} else {
|
|
1473
|
+
// Still behind, so the notice stays true. Say what to do rather than
|
|
1474
|
+
// reporting a success that did not take.
|
|
1475
|
+
ui.warn(`npm finished but v${installed} is still installed - run: npm install -g @bolt-cli/cli from a new terminal`);
|
|
1418
1476
|
}
|
|
1419
|
-
ui.ok("update complete - restart bolt to run the new version");
|
|
1420
1477
|
} else {
|
|
1421
|
-
ui.
|
|
1478
|
+
ui.ok("update finished - check with: bolt --version");
|
|
1422
1479
|
}
|
|
1423
1480
|
resolve();
|
|
1424
1481
|
});
|
|
@@ -2622,4 +2679,4 @@ async function run(argv) {
|
|
|
2622
2679
|
throw new Error(`Unknown command "${cmd}".\n${help()}`);
|
|
2623
2680
|
}
|
|
2624
2681
|
|
|
2625
|
-
module.exports = { run, resolveUrl, isLoopbackUrl, backendReachable, completer, completeFileFrag, completeWithDescriptions, filterPaletteItems, isPaletteRunnable, COMMANDS, AGENTS, NO_ARG_COMMANDS, makeAsker, makeAskQuestion, handleToolEvent, estimateTokens, buildDryRunReport, printDryRun, dryRunTools, argvSecretWarning, cmdDoctor, cmdCompletion, cmdTemplates, cmdExport, cmdUndo, reportRunError, warnTruncated, stripBoltPrefix, printPaletteNumbered, resolvePalettePick, replWelcomeLines, printHelpBox, printSessionTable, printKeysBox, pickTip, TIPS, formatElapsed, backendHost };
|
|
2682
|
+
module.exports = { run, resolveUrl, isLoopbackUrl, backendReachable, completer, completeFileFrag, completeWithDescriptions, filterPaletteItems, isPaletteRunnable, COMMANDS, AGENTS, NO_ARG_COMMANDS, makeAsker, makeAskQuestion, handleToolEvent, estimateTokens, buildDryRunReport, printDryRun, dryRunTools, argvSecretWarning, cmdDoctor, cmdCompletion, cmdTemplates, cmdExport, cmdUndo, reportRunError, warnTruncated, stripBoltPrefix, printPaletteNumbered, resolvePalettePick, replWelcomeLines, printHelpBox, printSessionTable, printKeysBox, pickTip, TIPS, formatElapsed, backendHost, updateOutcome };
|
package/package.json
CHANGED