@bolt-cli/cli 0.12.0 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/bin/bolt.js +21 -21
- package/lib/agent.js +50 -39
- package/lib/api.js +6 -3
- package/lib/browser.js +19 -3
- package/lib/cli.js +113 -12
- package/lib/completion.js +1 -1
- package/lib/config.js +22 -1
- package/lib/toolparse.js +752 -0
- package/lib/tools.js +8 -26
- package/lib/ui.js +54 -20
- package/lib/updatecheck.js +114 -0
- package/package.json +1 -4
package/lib/tools.js
CHANGED
|
@@ -18,9 +18,11 @@ const path = require("path");
|
|
|
18
18
|
const { execFile } = require("node:child_process");
|
|
19
19
|
const bootstrap = require("./bootstrap");
|
|
20
20
|
const checkpoints = require("./checkpoints");
|
|
21
|
+
const toolparse = require("./toolparse");
|
|
21
22
|
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
// Tool names and the per-turn block cap live in toolparse.js (the parser
|
|
24
|
+
// validates against them); re-exported here for every existing consumer.
|
|
25
|
+
const { TOOL_NAMES, MAX_TOOL_BLOCKS } = toolparse;
|
|
24
26
|
const MAX_READ_CHARS = 12_000;
|
|
25
27
|
const MAX_RESULT_CHARS = 4_000;
|
|
26
28
|
const BASH_TIMEOUT_MS = 120_000;
|
|
@@ -47,31 +49,11 @@ const SAFE_COMMAND = [
|
|
|
47
49
|
/^git\s+(status|diff|diff\s+--stat|log|show)\b/,
|
|
48
50
|
];
|
|
49
51
|
|
|
52
|
+
// Legacy fence-only parser, kept for callers/tests that only need
|
|
53
|
+
// {calls, errors}. The real extraction is model-agnostic (fences, XML tool
|
|
54
|
+
// tags, bare JSON, think stripping) — see toolparse.extractToolCalls.
|
|
50
55
|
function parseToolBlocks(text) {
|
|
51
|
-
const calls =
|
|
52
|
-
const errors = [];
|
|
53
|
-
const fence = /```(tool|ask)\s*\n([\s\S]*?)```/g;
|
|
54
|
-
let m;
|
|
55
|
-
while ((m = fence.exec(text)) !== null) {
|
|
56
|
-
if (calls.length + errors.length >= MAX_TOOL_BLOCKS) break;
|
|
57
|
-
const kind = m[1];
|
|
58
|
-
const raw = (m[2] || "").trim();
|
|
59
|
-
if (!raw) continue;
|
|
60
|
-
let parsed;
|
|
61
|
-
try {
|
|
62
|
-
parsed = JSON.parse(raw);
|
|
63
|
-
} catch {
|
|
64
|
-
errors.push({ raw: raw.slice(0, 200), error: "tool block is not valid JSON" });
|
|
65
|
-
continue;
|
|
66
|
-
}
|
|
67
|
-
// ```ask fences without an explicit tool default to the ask tool.
|
|
68
|
-
if (kind === "ask" && parsed && typeof parsed === "object" && !parsed.tool) parsed.tool = "ask";
|
|
69
|
-
if (!parsed || typeof parsed !== "object" || !TOOL_NAMES.includes(parsed.tool)) {
|
|
70
|
-
errors.push({ raw: raw.slice(0, 200), error: `unknown tool (want one of: ${TOOL_NAMES.join(", ")})` });
|
|
71
|
-
continue;
|
|
72
|
-
}
|
|
73
|
-
calls.push(parsed);
|
|
74
|
-
}
|
|
56
|
+
const { calls, errors } = toolparse.extractToolCalls(text);
|
|
75
57
|
return { calls, errors };
|
|
76
58
|
}
|
|
77
59
|
|
package/lib/ui.js
CHANGED
|
@@ -453,6 +453,25 @@ function selectable(items) {
|
|
|
453
453
|
return isTTY() && items.length > 0 && typeof process.stdin.setRawMode === "function";
|
|
454
454
|
}
|
|
455
455
|
|
|
456
|
+
// Scroll window for a picker whose rows outnumber `max`: the selected row
|
|
457
|
+
// stays visible by sliding the viewport, opencode-menu style. Pure, tested:
|
|
458
|
+
// returns the [start, end) slice bounds to display. When everything fits the
|
|
459
|
+
// whole list shows; a non-positive max degrades to the whole list too.
|
|
460
|
+
function pickWindow(index, total, max) {
|
|
461
|
+
const i = Number.isFinite(index) ? Math.max(0, Math.floor(index)) : 0;
|
|
462
|
+
const n = Number.isFinite(total) ? Math.max(0, Math.floor(total)) : 0;
|
|
463
|
+
const m = Number.isFinite(max) ? Math.floor(max) : 0;
|
|
464
|
+
if (m <= 0 || n <= m) return { start: 0, end: n };
|
|
465
|
+
const start = Math.min(Math.max(0, i - Math.floor((m - 1) / 2)), n - m);
|
|
466
|
+
return { start, end: start + m };
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
// The keybind footer under a picker: keys in the accent colour, verbs muted,
|
|
470
|
+
// so the eye lands on what to press. Degrades to plain text off-unicode.
|
|
471
|
+
function keyHints(pairs) {
|
|
472
|
+
return pairs.map(([key, verb]) => `${c.primary(key)} ${c.muted(verb)}`).join(` ${c.muted(GLYPH.dot)} `);
|
|
473
|
+
}
|
|
474
|
+
|
|
456
475
|
// Full-screen-ish command picker. Rendered as a block under the prompt that we
|
|
457
476
|
// redraw in place; the caller owns stdin for the duration via raw mode.
|
|
458
477
|
function select({ title = "", items = [], max = 12 }) {
|
|
@@ -468,16 +487,17 @@ function select({ title = "", items = [], max = 12 }) {
|
|
|
468
487
|
const build = () => {
|
|
469
488
|
const out = [];
|
|
470
489
|
if (title) out.push(` ${c.accent(GLYPH.arrow)} ${c.bold(title)}`);
|
|
471
|
-
const
|
|
472
|
-
|
|
473
|
-
const
|
|
490
|
+
const { start, end } = pickWindow(index, items.length, max);
|
|
491
|
+
items.slice(start, end).forEach((item, i) => {
|
|
492
|
+
const at = start + i;
|
|
493
|
+
const on = at === index;
|
|
474
494
|
const mark = on ? c.primary(GLYPH.sel) : " ";
|
|
475
495
|
const label = on ? c.primary(c.bold(item.label)) : item.label;
|
|
476
496
|
const hint = item.hint ? ` ${c.muted(item.hint)}` : "";
|
|
477
497
|
out.push(` ${mark} ${label}${hint}`);
|
|
478
498
|
});
|
|
479
|
-
if (items.length > max) out.push(` ${c.muted(`${
|
|
480
|
-
out.push(` ${
|
|
499
|
+
if (items.length > max) out.push(` ${c.muted(`${index + 1}/${items.length}`)}`);
|
|
500
|
+
out.push(` ${keyHints([["up/down", "move"], ["enter", "select"], ["esc", "cancel"]])}`);
|
|
481
501
|
return out;
|
|
482
502
|
};
|
|
483
503
|
|
|
@@ -533,9 +553,11 @@ function select({ title = "", items = [], max = 12 }) {
|
|
|
533
553
|
// Live filter-as-you-type palette. Starts with `initialFilter` (the text
|
|
534
554
|
// after the slash so far) and lets the operator keep typing to narrow the
|
|
535
555
|
// list: printable keys append to the filter, backspace removes one, up/down
|
|
536
|
-
// moves
|
|
537
|
-
//
|
|
538
|
-
//
|
|
556
|
+
// moves (the viewport scrolls to keep the selection visible), enter picks,
|
|
557
|
+
// tab fills the highlighted row into the prompt and leaves, esc cancels.
|
|
558
|
+
// Resolves {index, item, filter, tabFill} where index is into the original
|
|
559
|
+
// `items` array (-1 on cancel). `filterFn` maps a filter string to the
|
|
560
|
+
// visible subset; by default it matches label+hint.
|
|
539
561
|
function selectLive({ title = "", items = [], max = 12, initialFilter = "", filterFn = null }) {
|
|
540
562
|
const base = Array.isArray(items) ? items : [];
|
|
541
563
|
const match = typeof filterFn === "function"
|
|
@@ -545,7 +567,7 @@ function selectLive({ title = "", items = [], max = 12, initialFilter = "", filt
|
|
|
545
567
|
if (!needle) return base;
|
|
546
568
|
return base.filter((it) => `${it.label || ""} ${it.hint || ""}`.toLowerCase().includes(needle));
|
|
547
569
|
};
|
|
548
|
-
if (!selectable(base)) return Promise.resolve({ index: -1, item: null, filter: String(initialFilter || "") });
|
|
570
|
+
if (!selectable(base)) return Promise.resolve({ index: -1, item: null, filter: String(initialFilter || ""), tabFill: false });
|
|
549
571
|
const input = process.stdin;
|
|
550
572
|
const hadRaw = Boolean(input.isRaw);
|
|
551
573
|
|
|
@@ -558,19 +580,22 @@ function selectLive({ title = "", items = [], max = 12, initialFilter = "", filt
|
|
|
558
580
|
|
|
559
581
|
const build = () => {
|
|
560
582
|
const out = [];
|
|
561
|
-
const
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
583
|
+
const count = filter || visible.length !== base.length ? ` ${c.muted(`${visible.length}/${base.length}`)}` : "";
|
|
584
|
+
const head = title
|
|
585
|
+
? ` ${c.accent(GLYPH.arrow)} ${c.bold(title)} ${c.muted(`/${filter}`)}${count}`
|
|
586
|
+
: ` ${c.muted(`/${filter}`)}${count}`;
|
|
587
|
+
out.push(head);
|
|
588
|
+
const { start, end } = pickWindow(index, visible.length, max);
|
|
589
|
+
visible.slice(start, end).forEach((item, i) => {
|
|
590
|
+
const at = start + i;
|
|
591
|
+
const on = at === index;
|
|
566
592
|
const mark = on ? c.primary(GLYPH.sel) : " ";
|
|
567
593
|
const label = on ? c.primary(c.bold(item.label)) : item.label;
|
|
568
594
|
const hint = item.hint ? ` ${c.muted(item.hint)}` : "";
|
|
569
595
|
out.push(` ${mark} ${label}${hint}`);
|
|
570
596
|
});
|
|
571
597
|
if (!visible.length) out.push(` ${c.muted(`no match - keep typing or esc to cancel`)}`);
|
|
572
|
-
|
|
573
|
-
out.push(` ${c.muted(`type to filter ${GLYPH.dot} up/down move ${GLYPH.dot} enter select ${GLYPH.dot} esc cancel`)}`);
|
|
598
|
+
out.push(` ${keyHints([["type", "filter"], ["up/down", "move"], ["enter", "run"], ["tab", "fill"], ["esc", "cancel"]])}`);
|
|
574
599
|
return out;
|
|
575
600
|
};
|
|
576
601
|
|
|
@@ -611,9 +636,17 @@ function selectLive({ title = "", items = [], max = 12, initialFilter = "", filt
|
|
|
611
636
|
if (s === "\r" || s === "\n") {
|
|
612
637
|
const item = visible[index] || null;
|
|
613
638
|
const original = item ? base.indexOf(item) : -1;
|
|
614
|
-
return finish(original, item);
|
|
639
|
+
return finish(original, item, false);
|
|
640
|
+
}
|
|
641
|
+
// Tab fills the highlighted row into the prompt and leaves the picker
|
|
642
|
+
// up, so a command that takes arguments keeps the operator typing.
|
|
643
|
+
if (s === "\t") {
|
|
644
|
+
const item = visible[index] || null;
|
|
645
|
+
if (!item) return;
|
|
646
|
+
const original = base.indexOf(item);
|
|
647
|
+
return finish(original, item, true);
|
|
615
648
|
}
|
|
616
|
-
if (s === "\u001b" || s === "\u0003" || s === "\u0004") return finish(-1, null);
|
|
649
|
+
if (s === "\u001b" || s === "\u0003" || s === "\u0004") return finish(-1, null, false);
|
|
617
650
|
if (s === "\u007f" || s === "\b" || s === "\u0008") {
|
|
618
651
|
filter = filter.slice(0, -1);
|
|
619
652
|
index = 0;
|
|
@@ -644,14 +677,14 @@ function selectLive({ title = "", items = [], max = 12, initialFilter = "", filt
|
|
|
644
677
|
}
|
|
645
678
|
};
|
|
646
679
|
|
|
647
|
-
function finish(original, item) {
|
|
680
|
+
function finish(original, item, tabFill) {
|
|
648
681
|
if (done) return;
|
|
649
682
|
done = true;
|
|
650
683
|
input.removeListener("data", onData);
|
|
651
684
|
clear();
|
|
652
685
|
if (!hadRaw && input.setRawMode) input.setRawMode(false);
|
|
653
686
|
input.pause();
|
|
654
|
-
resolve({ index: original, item, filter });
|
|
687
|
+
resolve({ index: original, item, filter, tabFill: Boolean(tabFill) });
|
|
655
688
|
}
|
|
656
689
|
|
|
657
690
|
input.setRawMode(true);
|
|
@@ -719,6 +752,7 @@ module.exports = {
|
|
|
719
752
|
resolveDepth,
|
|
720
753
|
supportsUnicode,
|
|
721
754
|
selectable,
|
|
755
|
+
pickWindow,
|
|
722
756
|
unicode: U,
|
|
723
757
|
width,
|
|
724
758
|
relTime,
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Update check: one quiet npm-registry lookup per 12h per machine. The result
|
|
3
|
+
// is cached in ~/.bolt/config.json, so the next session greets the operator
|
|
4
|
+
// with the notice even if the check itself happened offline mid-session.
|
|
5
|
+
// Never blocking, never throwing: a failed fetch simply means no notice today
|
|
6
|
+
// and a retry next session. Opt out with BOLT_NO_UPDATE_CHECK=1.
|
|
7
|
+
const config = require("./config");
|
|
8
|
+
|
|
9
|
+
const REGISTRY_URL = "https://registry.npmjs.org/@bolt-cli/cli/latest";
|
|
10
|
+
const CHECK_INTERVAL_MS = 12 * 60 * 60 * 1000;
|
|
11
|
+
const FETCH_TIMEOUT_MS = 4000;
|
|
12
|
+
|
|
13
|
+
function optOut() {
|
|
14
|
+
return process.env.BOLT_NO_UPDATE_CHECK === "1";
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function parseVersion(value) {
|
|
18
|
+
const raw = String(value || "").trim().replace(/^v/i, "");
|
|
19
|
+
const dash = raw.indexOf("-");
|
|
20
|
+
const core = dash === -1 ? raw : raw.slice(0, dash);
|
|
21
|
+
const pre = dash === -1 ? "" : raw.slice(dash + 1);
|
|
22
|
+
const nums = core
|
|
23
|
+
.split(".")
|
|
24
|
+
.map((part) => (/^\d+$/.test(part) ? Number(part) : 0));
|
|
25
|
+
return { nums, pre };
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Numeric dot-compare with semver prerelease awareness (0.13.0-rc1 sorts
|
|
30
|
+
* below 0.13.0). Unknown shapes degrade to 0, never to a false upgrade.
|
|
31
|
+
*/
|
|
32
|
+
function compareVersions(a, b) {
|
|
33
|
+
const va = parseVersion(a);
|
|
34
|
+
const vb = parseVersion(b);
|
|
35
|
+
const len = Math.max(va.nums.length, vb.nums.length);
|
|
36
|
+
for (let i = 0; i < len; i++) {
|
|
37
|
+
const na = va.nums[i] || 0;
|
|
38
|
+
const nb = vb.nums[i] || 0;
|
|
39
|
+
if (na !== nb) return na > nb ? 1 : -1;
|
|
40
|
+
}
|
|
41
|
+
if (va.pre !== vb.pre) {
|
|
42
|
+
// Same core: a prerelease sorts below the release it belongs to.
|
|
43
|
+
if (!va.pre) return 1;
|
|
44
|
+
if (!vb.pre) return -1;
|
|
45
|
+
return va.pre > vb.pre ? 1 : -1;
|
|
46
|
+
}
|
|
47
|
+
return 0;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function isNewer(latest, current) {
|
|
51
|
+
return compareVersions(latest, current) > 0;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function noticeText(current, latest) {
|
|
55
|
+
return `Update available: v${current} -> v${latest} - run: npm update -g @bolt-cli/cli (or: bolt update)`;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** The notice from the cached state only. Synchronous, zero network. */
|
|
59
|
+
function cachedNotice(current, store) {
|
|
60
|
+
if (optOut()) return null;
|
|
61
|
+
const cfg = (store || config).load();
|
|
62
|
+
if (!cfg.updateLatest || !isNewer(cfg.updateLatest, current)) return null;
|
|
63
|
+
return noticeText(current, cfg.updateLatest);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** npm registry "latest" version, or "" on any failure/timeout. */
|
|
67
|
+
async function fetchLatest(fetchImpl) {
|
|
68
|
+
const doFetch = fetchImpl || globalThis.fetch;
|
|
69
|
+
if (!doFetch) return "";
|
|
70
|
+
const controller = new AbortController();
|
|
71
|
+
const timer = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);
|
|
72
|
+
try {
|
|
73
|
+
const res = await doFetch(REGISTRY_URL, { signal: controller.signal, headers: { accept: "application/json" } });
|
|
74
|
+
if (!res.ok) return "";
|
|
75
|
+
const body = await res.json();
|
|
76
|
+
return body && typeof body.version === "string" ? body.version.trim() : "";
|
|
77
|
+
} catch {
|
|
78
|
+
return "";
|
|
79
|
+
} finally {
|
|
80
|
+
clearTimeout(timer);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Refresh the cached latest-version. Fired detached at REPL start; onNotice
|
|
86
|
+
* only fires when an upgrade is newly discovered this session, so a notice
|
|
87
|
+
* already rendered from cache is never printed twice.
|
|
88
|
+
*/
|
|
89
|
+
async function refresh(current, opts = {}) {
|
|
90
|
+
if (optOut()) return { available: false, latest: "", notice: null };
|
|
91
|
+
const store = opts.store || config;
|
|
92
|
+
const cfg = store.load();
|
|
93
|
+
const now = Date.now();
|
|
94
|
+
if (cfg.updateCheckedAt && now - cfg.updateCheckedAt < CHECK_INTERVAL_MS) {
|
|
95
|
+
// Fresh cache decides without a network call.
|
|
96
|
+
if (cfg.updateLatest && isNewer(cfg.updateLatest, current)) {
|
|
97
|
+
const notice = noticeText(current, cfg.updateLatest);
|
|
98
|
+
if (opts.onNotice) opts.onNotice(notice);
|
|
99
|
+
return { available: true, latest: cfg.updateLatest, notice };
|
|
100
|
+
}
|
|
101
|
+
return { available: false, latest: cfg.updateLatest, notice: null };
|
|
102
|
+
}
|
|
103
|
+
const latest = await fetchLatest(opts.fetchImpl);
|
|
104
|
+
// Explicit fields win over the merge-preservation in config.save.
|
|
105
|
+
store.save({ ...cfg, updateCheckedAt: now, updateLatest: latest });
|
|
106
|
+
if (latest && isNewer(latest, current)) {
|
|
107
|
+
const notice = noticeText(current, latest);
|
|
108
|
+
if (opts.onNotice) opts.onNotice(notice);
|
|
109
|
+
return { available: true, latest, notice };
|
|
110
|
+
}
|
|
111
|
+
return { available: false, latest, notice: null };
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
module.exports = { cachedNotice, refresh, noticeText, compareVersions, isNewer, fetchLatest, REGISTRY_URL, CHECK_INTERVAL_MS };
|
package/package.json
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bolt-cli/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"description": "Bolt terminal CLI — authorized testing and tool-building from your terminal or VS Code.",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"type": "commonjs",
|
|
7
|
-
"publishConfig": {
|
|
8
|
-
"access": "public"
|
|
9
|
-
},
|
|
10
7
|
"engines": {
|
|
11
8
|
"node": ">=18"
|
|
12
9
|
},
|