@bolt-cli/cli 0.14.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 +90 -31
- package/lib/present.js +1 -1
- package/lib/ui.js +49 -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");
|
|
@@ -278,7 +278,7 @@ async function cmdSession(rest) {
|
|
|
278
278
|
const s = id ? session.load(id) : null;
|
|
279
279
|
if (!s) throw new Error("Usage: bolt session show <id>");
|
|
280
280
|
for (const [i, t] of s.turns.entries()) {
|
|
281
|
-
console.log(`\n--- turn ${i + 1} [${t.mode}] ${t.at} ---\
|
|
281
|
+
console.log(`\n--- turn ${i + 1} [${t.mode}] ${t.at} ---\n${ui.userTurn(t.prompt)}\nA: ${t.response.slice(0, 2000)}`);
|
|
282
282
|
if (t.tools && t.tools.length) {
|
|
283
283
|
console.log(`tools: ${t.tools.map((tool) => `${tool.tool}${tool.ok === false ? " (failed)" : ""}`).join(", ")}`);
|
|
284
284
|
}
|
|
@@ -921,10 +921,10 @@ function handleToolEvent(event) {
|
|
|
921
921
|
} else {
|
|
922
922
|
toolStarted.set(toolTimingKey(event.call), Date.now());
|
|
923
923
|
const elevated = event.call && event.call.tool === "bash" ? permissions.isElevatedCommand(event.call.command) : false;
|
|
924
|
-
//
|
|
925
|
-
//
|
|
926
|
-
// one thing that must be seen, is.
|
|
927
|
-
ui.status(`${ui.
|
|
924
|
+
// Transcript-style tool row: a quiet mark plus the call, the way a
|
|
925
|
+
// full-screen agent renders activity. The elevated warning keeps its
|
|
926
|
+
// colour so the one thing that must be seen, is.
|
|
927
|
+
ui.status(`${ui.toolLine(tools.describeCall(event.call))}${elevated ? ` ${ui.c.warning("[elevated]")}` : ""}`);
|
|
928
928
|
}
|
|
929
929
|
return;
|
|
930
930
|
}
|
|
@@ -934,9 +934,9 @@ function handleToolEvent(event) {
|
|
|
934
934
|
if (event.call.tool === "(parse error)") {
|
|
935
935
|
ui.warn(`tool request ignored: ${r.summary || "bad block"}`);
|
|
936
936
|
} else {
|
|
937
|
-
// Result rows
|
|
938
|
-
//
|
|
939
|
-
ui.status(
|
|
937
|
+
// Result rows mirror the call row; failure keeps an error tone so a scan
|
|
938
|
+
// down the transcript still catches it.
|
|
939
|
+
ui.status(ui.toolLine(r.ok ? "ok" : "FAILED", r.summary || "", { ok: r.ok, duration: took || undefined }));
|
|
940
940
|
}
|
|
941
941
|
}
|
|
942
942
|
}
|
|
@@ -966,8 +966,7 @@ function takeToolElapsed(call) {
|
|
|
966
966
|
if (!key || !toolStarted.has(key)) return "";
|
|
967
967
|
const ms = Date.now() - toolStarted.get(key);
|
|
968
968
|
toolStarted.delete(key);
|
|
969
|
-
|
|
970
|
-
return text ? ` ${ui.c.muted(`· ${text}`)}` : "";
|
|
969
|
+
return formatElapsed(ms);
|
|
971
970
|
}
|
|
972
971
|
|
|
973
972
|
function copyToClipboard(text) {
|
|
@@ -1395,31 +1394,88 @@ async function cmdDoctor() {
|
|
|
1395
1394
|
}
|
|
1396
1395
|
|
|
1397
1396
|
// ── update ────────────────────────────────────────────────────────────────
|
|
1398
|
-
// `bolt update`
|
|
1399
|
-
//
|
|
1400
|
-
//
|
|
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
|
+
|
|
1401
1441
|
function cmdUpdate() {
|
|
1402
1442
|
console.log(`running: npm install -g @bolt-cli/cli (current: v${VERSION})`);
|
|
1403
|
-
const
|
|
1443
|
+
const inv = npmInvocation(["install", "-g", "@bolt-cli/cli"]);
|
|
1444
|
+
const child = spawn(inv.command, inv.args, { stdio: "inherit", windowsHide: true });
|
|
1404
1445
|
return new Promise((resolve) => {
|
|
1405
1446
|
child.on("error", (error) => {
|
|
1406
1447
|
ui.err(`update failed: ${error.message} - try: npm install -g @bolt-cli/cli`);
|
|
1407
1448
|
resolve();
|
|
1408
1449
|
});
|
|
1409
1450
|
child.on("close", (code) => {
|
|
1410
|
-
if (code
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
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.
|
|
1414
1461
|
try {
|
|
1415
1462
|
const cfg = config.load();
|
|
1416
1463
|
config.save({ ...cfg, updateCheckedAt: 0, updateLatest: "" });
|
|
1417
1464
|
} catch {
|
|
1418
|
-
// 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`);
|
|
1419
1476
|
}
|
|
1420
|
-
ui.ok("update complete - restart bolt to run the new version");
|
|
1421
1477
|
} else {
|
|
1422
|
-
ui.
|
|
1478
|
+
ui.ok("update finished - check with: bolt --version");
|
|
1423
1479
|
}
|
|
1424
1480
|
resolve();
|
|
1425
1481
|
});
|
|
@@ -1619,19 +1675,22 @@ function pickTip(n) {
|
|
|
1619
1675
|
return TIPS[((Number(n) || 0) % TIPS.length + TIPS.length) % TIPS.length];
|
|
1620
1676
|
}
|
|
1621
1677
|
|
|
1622
|
-
//
|
|
1623
|
-
//
|
|
1624
|
-
//
|
|
1625
|
-
//
|
|
1678
|
+
// REPL home surface: half-block wordmark, identity/session chrome, and one
|
|
1679
|
+
// mechanics line. The wordmark is the only decoration; everything else stays
|
|
1680
|
+
// muted so the prompt below remains the focus. Pure (ui.c degrades on a pipe),
|
|
1681
|
+
// tested for the hint phrases the docs promise.
|
|
1626
1682
|
function replWelcomeLines({ sid, version, host, cwd, update }) {
|
|
1627
1683
|
const identity = [version ? `v${version}` : "", host, cwd].filter(Boolean);
|
|
1628
1684
|
const lines = [
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
` ${ui.c.muted(
|
|
1685
|
+
...ui.wordmark(" "),
|
|
1686
|
+
"",
|
|
1687
|
+
` ${ui.c.muted(identity.join(` ${ui.GLYPH.dot} `))}`,
|
|
1688
|
+
` ${ui.c.muted(`session ${sid.slice(0, 8)} ${ui.GLYPH.dot} type a task and press enter`)}`,
|
|
1689
|
+
"",
|
|
1690
|
+
` ${ui.c.primary("/")} ${ui.c.muted("opens the command dropdown")} ${ui.c.muted(ui.GLYPH.dot)} ${ui.c.primary("Tab fills")} ${ui.c.muted("and keeps your place")} ${ui.c.muted(ui.GLYPH.dot)} ${ui.c.primary("@path")} ${ui.c.muted("attaches a file")}`,
|
|
1632
1691
|
];
|
|
1633
1692
|
if (update) {
|
|
1634
|
-
lines.push("",
|
|
1693
|
+
lines.push("", ` ${ui.c.warning("update")} ${update}`);
|
|
1635
1694
|
}
|
|
1636
1695
|
return lines;
|
|
1637
1696
|
}
|
|
@@ -2620,4 +2679,4 @@ async function run(argv) {
|
|
|
2620
2679
|
throw new Error(`Unknown command "${cmd}".\n${help()}`);
|
|
2621
2680
|
}
|
|
2622
2681
|
|
|
2623
|
-
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/lib/present.js
CHANGED
|
@@ -79,7 +79,7 @@ function promptLine({ mode, target, agent, files, balance, tools }) {
|
|
|
79
79
|
if (files) bits.push(ui.c.muted(`${files} file${files === 1 ? "" : "s"}`));
|
|
80
80
|
if (tools !== undefined) bits.push(ui.c.muted(tools ? "tools" : "no-tools"));
|
|
81
81
|
if (balance !== undefined && balance !== null) bits.push(ui.c.muted(`${balance} tok`));
|
|
82
|
-
return `${ui.c.primary(
|
|
82
|
+
return `${ui.c.primary(">")} ${bits.join(ui.c.muted(` ${ui.GLYPH.dot} `))} `;
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
// Palette rows for `select()`; label is what gets typed back into the prompt.
|
package/lib/ui.js
CHANGED
|
@@ -168,21 +168,34 @@ function width() {
|
|
|
168
168
|
return typeof columns === "number" && columns > 20 ? Math.min(columns, 100) : 78;
|
|
169
169
|
}
|
|
170
170
|
|
|
171
|
-
//
|
|
172
|
-
//
|
|
173
|
-
//
|
|
174
|
-
//
|
|
175
|
-
// holds. Pure, tested.
|
|
171
|
+
// Half-block wordmark in the register used by full-screen agent terminals:
|
|
172
|
+
// solid upper blocks, a dim baseline, `_` holes and a `~` shadow. One cell per
|
|
173
|
+
// glyph so visible-length maths holds; `_` is a blank cell, never a literal
|
|
174
|
+
// underscore. Colour degrades to identity on a pipe. Pure, width-tested.
|
|
176
175
|
const LOGO_RAW = [
|
|
177
|
-
"
|
|
178
|
-
"
|
|
179
|
-
"
|
|
180
|
-
"
|
|
181
|
-
"██████╔╝ ██║ ██║ ██║ █",
|
|
182
|
-
"╚═════╝ ╚════╝ ██║▄▄▄▄",
|
|
176
|
+
" ",
|
|
177
|
+
"█▀▀▄ █▀▀█ █___ █▀▀▀",
|
|
178
|
+
"█▄▄▀ █__█ █___ _█__",
|
|
179
|
+
"▀~~▀ ▀▀▀▀ ▀▀▀▀ ▀▀▀▀",
|
|
183
180
|
];
|
|
184
|
-
|
|
185
|
-
|
|
181
|
+
function wordmark(pad = "") {
|
|
182
|
+
if (!U) return [`${pad}bolt`];
|
|
183
|
+
return LOGO_RAW.map((line, i) => {
|
|
184
|
+
const baseline = i === LOGO_RAW.length - 1;
|
|
185
|
+
return (
|
|
186
|
+
pad +
|
|
187
|
+
[...line]
|
|
188
|
+
.map((ch) => {
|
|
189
|
+
if (ch === "_" || ch === " ") return " ";
|
|
190
|
+
if (ch === "~") return c.border("▀");
|
|
191
|
+
if (ch === "▀" && baseline) return c.muted(ch);
|
|
192
|
+
return c.primary(ch);
|
|
193
|
+
})
|
|
194
|
+
.join("")
|
|
195
|
+
);
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
const LOGO = wordmark();
|
|
186
199
|
|
|
187
200
|
// Relative timestamps for pickers and dashboards ("5m ago"). Pure, tested:
|
|
188
201
|
// `now` injects the clock, unparseable input yields "".
|
|
@@ -270,6 +283,26 @@ function bullets(rows, { marker = GLYPH.dot } = {}) {
|
|
|
270
283
|
return rows.map((r) => ` ${c.muted(marker)} ${r}`).join("\n");
|
|
271
284
|
}
|
|
272
285
|
|
|
286
|
+
// Transcript shapes shared by the REPL and the tool-event renderer. A user
|
|
287
|
+
// turn gets a bright `>` marker and default-foreground text; tool activity gets
|
|
288
|
+
// a compact indented row with a semantic mark. Both are pure strings, so a
|
|
289
|
+
// piped log keeps the same readable shape without ANSI.
|
|
290
|
+
function userTurn(text) {
|
|
291
|
+
return String(text ?? "")
|
|
292
|
+
.split("\n")
|
|
293
|
+
.map((line, i) => (i === 0 ? `${c.primary(">")} ${c.bold(line)}` : ` ${line}`))
|
|
294
|
+
.join("\n");
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
function toolLine(name, detail, { ok: state, duration } = {}) {
|
|
298
|
+
const mark = state === undefined ? c.info(GLYPH.dot) : state ? c.success(GLYPH.tick) : c.error(GLYPH.cross);
|
|
299
|
+
const label = state === undefined ? c.primary(name) : state ? c.success(name) : c.error(name);
|
|
300
|
+
const bits = [label];
|
|
301
|
+
if (detail) bits.push(c.muted(String(detail)));
|
|
302
|
+
if (duration) bits.push(c.border(String(duration)));
|
|
303
|
+
return ` ${mark} ${bits.join(` ${c.muted(GLYPH.dot)} `)}`;
|
|
304
|
+
}
|
|
305
|
+
|
|
273
306
|
// ---------------------------------------------------------------- status
|
|
274
307
|
|
|
275
308
|
// Quiet progress line for tool activity: reference terminals render tool traffic as
|
|
@@ -748,6 +781,9 @@ module.exports = {
|
|
|
748
781
|
ESC,
|
|
749
782
|
GLYPH,
|
|
750
783
|
LOGO,
|
|
784
|
+
wordmark,
|
|
785
|
+
userTurn,
|
|
786
|
+
toolLine,
|
|
751
787
|
PALETTE,
|
|
752
788
|
c,
|
|
753
789
|
enabled: c.enabled,
|
package/package.json
CHANGED