@bolt-cli/cli 0.12.0 → 0.14.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/lib/tools.js CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- // Local tools for the bolt agent loop (Claude Code / opencode style).
2
+ // Local tools for the bolt agent loop (modern agent CLI style).
3
3
  //
4
4
  // The model asks for tool calls with fenced blocks:
5
5
  //
@@ -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
- const TOOL_NAMES = ["read", "glob", "grep", "list", "write", "edit", "bash", "ask"];
23
- const MAX_TOOL_BLOCKS = 6;
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
@@ -1,12 +1,12 @@
1
1
  "use strict";
2
2
  // Terminal presentation layer. Zero deps: hand-rolled ANSI only.
3
3
  //
4
- // Scope note: this is deliberately *not* a full-screen TUI. opencode renders
5
- // with OpenTUI + SolidJS (native binary, ~50MB of deps); bolt stays dependency
6
- // free so `npm i -g @bolt-cli/cli` is instant. What we reproduce here is the
7
- // vocabulary and feel -- semantic colour tokens with the same names opencode's
8
- // TUI uses, a status-carrying prompt, a thinking indicator, an arrow-key
9
- // command palette, and quiet de-prioritised prose.
4
+ // Scope note: this is deliberately *not* a full-screen TUI. Full-screen
5
+ // terminal interfaces ship native binaries and tens of megabytes of
6
+ // dependencies; bolt stays dependency free so `npm i -g @bolt-cli/cli` is
7
+ // instant. What we reproduce is the vocabulary and feel -- semantic colour
8
+ // tokens with the names polished terminal UIs use, a status-carrying prompt,
9
+ // a thinking indicator, an arrow-key command palette, and quiet prose.
10
10
  //
11
11
  // Every helper degrades to plain text when stdout is not a TTY, when NO_COLOR
12
12
  // is set, or when the terminal only supports 16 colours, so piped output and CI
@@ -168,7 +168,7 @@ function width() {
168
168
  return typeof columns === "number" && columns > 20 ? Math.min(columns, 100) : 78;
169
169
  }
170
170
 
171
- // Block-letter wordmark in the opencode logo.ts spirit: heavy blocks where
171
+ // Heavy block-letter wordmark: solid blocks where
172
172
  // the terminal proves modern, the plain word everywhere else so raster fonts
173
173
  // never show tofu. Rows pad to one width in code (no trailing whitespace in
174
174
  // the literals for linters to flag); every glyph is one cell, so length math
@@ -248,7 +248,7 @@ function rule(w = width()) {
248
248
  return c.border(GLYPH.rule.repeat(Math.max(8, w)));
249
249
  }
250
250
 
251
- function box({ title = "", lines = [], w = width(), tone = "primary" }) {
251
+ function box({ title = "", lines = [], w = width(), tone = "border" }) {
252
252
  const paint = c[tone] || c.primary;
253
253
  const inner = w - 4;
254
254
  const head = title ? ` ${c.bold(title)} ` : "";
@@ -272,8 +272,11 @@ function bullets(rows, { marker = GLYPH.dot } = {}) {
272
272
 
273
273
  // ---------------------------------------------------------------- status
274
274
 
275
+ // Quiet progress line for tool activity: reference terminals render tool traffic as
276
+ // plain dim text, not branded announcements, so no wordmark here either.
277
+ // Callers pass pre-styled text.
275
278
  function status(text) {
276
- errWrite(`${c.primary("bolt")} ${c.muted(GLYPH.dot)} ${text}\n`);
279
+ errWrite(`${text}\n`);
277
280
  }
278
281
 
279
282
  function ok(text) {
@@ -453,6 +456,25 @@ function selectable(items) {
453
456
  return isTTY() && items.length > 0 && typeof process.stdin.setRawMode === "function";
454
457
  }
455
458
 
459
+ // Scroll window for a picker whose rows outnumber `max`: the selected row
460
+ // stays visible by sliding the viewport, selection-menu style. Pure, tested:
461
+ // returns the [start, end) slice bounds to display. When everything fits the
462
+ // whole list shows; a non-positive max degrades to the whole list too.
463
+ function pickWindow(index, total, max) {
464
+ const i = Number.isFinite(index) ? Math.max(0, Math.floor(index)) : 0;
465
+ const n = Number.isFinite(total) ? Math.max(0, Math.floor(total)) : 0;
466
+ const m = Number.isFinite(max) ? Math.floor(max) : 0;
467
+ if (m <= 0 || n <= m) return { start: 0, end: n };
468
+ const start = Math.min(Math.max(0, i - Math.floor((m - 1) / 2)), n - m);
469
+ return { start, end: start + m };
470
+ }
471
+
472
+ // The keybind footer under a picker: keys in the accent colour, verbs muted,
473
+ // so the eye lands on what to press. Degrades to plain text off-unicode.
474
+ function keyHints(pairs) {
475
+ return pairs.map(([key, verb]) => `${c.primary(key)} ${c.muted(verb)}`).join(` ${c.muted(GLYPH.dot)} `);
476
+ }
477
+
456
478
  // Full-screen-ish command picker. Rendered as a block under the prompt that we
457
479
  // redraw in place; the caller owns stdin for the duration via raw mode.
458
480
  function select({ title = "", items = [], max = 12 }) {
@@ -468,16 +490,17 @@ function select({ title = "", items = [], max = 12 }) {
468
490
  const build = () => {
469
491
  const out = [];
470
492
  if (title) out.push(` ${c.accent(GLYPH.arrow)} ${c.bold(title)}`);
471
- const visible = items.slice(0, max);
472
- visible.forEach((item, i) => {
473
- const on = i === index;
493
+ const { start, end } = pickWindow(index, items.length, max);
494
+ items.slice(start, end).forEach((item, i) => {
495
+ const at = start + i;
496
+ const on = at === index;
474
497
  const mark = on ? c.primary(GLYPH.sel) : " ";
475
498
  const label = on ? c.primary(c.bold(item.label)) : item.label;
476
499
  const hint = item.hint ? ` ${c.muted(item.hint)}` : "";
477
500
  out.push(` ${mark} ${label}${hint}`);
478
501
  });
479
- if (items.length > max) out.push(` ${c.muted(`${items.length - max} more${items.length - max === 1 ? "" : "s"}`)}`);
480
- out.push(` ${c.muted(`up/down move ${GLYPH.dot} enter select ${GLYPH.dot} esc cancel`)}`);
502
+ if (items.length > max) out.push(` ${c.muted(`${index + 1}/${items.length}`)}`);
503
+ out.push(` ${keyHints([["up/down", "move"], ["enter", "select"], ["esc", "cancel"]])}`);
481
504
  return out;
482
505
  };
483
506
 
@@ -533,9 +556,11 @@ function select({ title = "", items = [], max = 12 }) {
533
556
  // Live filter-as-you-type palette. Starts with `initialFilter` (the text
534
557
  // after the slash so far) and lets the operator keep typing to narrow the
535
558
  // list: printable keys append to the filter, backspace removes one, up/down
536
- // moves, enter picks, esc cancels. Resolves {index, item, filter} where
537
- // index is into the original `items` array (-1 on cancel). `filterFn` maps
538
- // a filter string to the visible subset; by default it matches label+hint.
559
+ // moves (the viewport scrolls to keep the selection visible), enter picks,
560
+ // tab fills the highlighted row into the prompt and leaves, esc cancels.
561
+ // Resolves {index, item, filter, tabFill} where index is into the original
562
+ // `items` array (-1 on cancel). `filterFn` maps a filter string to the
563
+ // visible subset; by default it matches label+hint.
539
564
  function selectLive({ title = "", items = [], max = 12, initialFilter = "", filterFn = null }) {
540
565
  const base = Array.isArray(items) ? items : [];
541
566
  const match = typeof filterFn === "function"
@@ -545,7 +570,7 @@ function selectLive({ title = "", items = [], max = 12, initialFilter = "", filt
545
570
  if (!needle) return base;
546
571
  return base.filter((it) => `${it.label || ""} ${it.hint || ""}`.toLowerCase().includes(needle));
547
572
  };
548
- if (!selectable(base)) return Promise.resolve({ index: -1, item: null, filter: String(initialFilter || "") });
573
+ if (!selectable(base)) return Promise.resolve({ index: -1, item: null, filter: String(initialFilter || ""), tabFill: false });
549
574
  const input = process.stdin;
550
575
  const hadRaw = Boolean(input.isRaw);
551
576
 
@@ -558,19 +583,22 @@ function selectLive({ title = "", items = [], max = 12, initialFilter = "", filt
558
583
 
559
584
  const build = () => {
560
585
  const out = [];
561
- const head = title ? ` ${c.accent(GLYPH.arrow)} ${c.bold(title)}` : "";
562
- out.push(head ? `${head} ${c.muted(`/${filter}`)}` : ` ${c.muted(`/${filter}`)}`);
563
- const slice = visible.slice(0, max);
564
- slice.forEach((item, i) => {
565
- const on = i === index;
586
+ const count = filter || visible.length !== base.length ? ` ${c.muted(`${visible.length}/${base.length}`)}` : "";
587
+ const head = title
588
+ ? ` ${c.accent(GLYPH.arrow)} ${c.bold(title)} ${c.muted(`/${filter}`)}${count}`
589
+ : ` ${c.muted(`/${filter}`)}${count}`;
590
+ out.push(head);
591
+ const { start, end } = pickWindow(index, visible.length, max);
592
+ visible.slice(start, end).forEach((item, i) => {
593
+ const at = start + i;
594
+ const on = at === index;
566
595
  const mark = on ? c.primary(GLYPH.sel) : " ";
567
596
  const label = on ? c.primary(c.bold(item.label)) : item.label;
568
597
  const hint = item.hint ? ` ${c.muted(item.hint)}` : "";
569
598
  out.push(` ${mark} ${label}${hint}`);
570
599
  });
571
600
  if (!visible.length) out.push(` ${c.muted(`no match - keep typing or esc to cancel`)}`);
572
- else if (visible.length > max) out.push(` ${c.muted(`${visible.length - max} more${visible.length - max === 1 ? "" : "s"}`)}`);
573
- out.push(` ${c.muted(`type to filter ${GLYPH.dot} up/down move ${GLYPH.dot} enter select ${GLYPH.dot} esc cancel`)}`);
601
+ out.push(` ${keyHints([["type", "filter"], ["up/down", "move"], ["enter", "run"], ["tab", "fill"], ["esc", "cancel"]])}`);
574
602
  return out;
575
603
  };
576
604
 
@@ -611,9 +639,17 @@ function selectLive({ title = "", items = [], max = 12, initialFilter = "", filt
611
639
  if (s === "\r" || s === "\n") {
612
640
  const item = visible[index] || null;
613
641
  const original = item ? base.indexOf(item) : -1;
614
- return finish(original, item);
642
+ return finish(original, item, false);
643
+ }
644
+ // Tab fills the highlighted row into the prompt and leaves the picker
645
+ // up, so a command that takes arguments keeps the operator typing.
646
+ if (s === "\t") {
647
+ const item = visible[index] || null;
648
+ if (!item) return;
649
+ const original = base.indexOf(item);
650
+ return finish(original, item, true);
615
651
  }
616
- if (s === "\u001b" || s === "\u0003" || s === "\u0004") return finish(-1, null);
652
+ if (s === "\u001b" || s === "\u0003" || s === "\u0004") return finish(-1, null, false);
617
653
  if (s === "\u007f" || s === "\b" || s === "\u0008") {
618
654
  filter = filter.slice(0, -1);
619
655
  index = 0;
@@ -644,14 +680,14 @@ function selectLive({ title = "", items = [], max = 12, initialFilter = "", filt
644
680
  }
645
681
  };
646
682
 
647
- function finish(original, item) {
683
+ function finish(original, item, tabFill) {
648
684
  if (done) return;
649
685
  done = true;
650
686
  input.removeListener("data", onData);
651
687
  clear();
652
688
  if (!hadRaw && input.setRawMode) input.setRawMode(false);
653
689
  input.pause();
654
- resolve({ index: original, item, filter });
690
+ resolve({ index: original, item, filter, tabFill: Boolean(tabFill) });
655
691
  }
656
692
 
657
693
  input.setRawMode(true);
@@ -664,7 +700,7 @@ function selectLive({ title = "", items = [], max = 12, initialFilter = "", filt
664
700
 
665
701
  // ---------------------------------------------------------------- approvals
666
702
 
667
- // Permission options for a tool approval, Claude Code / opencode style.
703
+ // Permission options for a tool approval, modern agent CLI style.
668
704
  // Elevated commands (sudo, system installs) get the shield treatment and no
669
705
  // silent path; installers only offer once/deny (never always).
670
706
  function permissionItems({ elevated = false, install = false } = {}) {
@@ -719,6 +755,7 @@ module.exports = {
719
755
  resolveDepth,
720
756
  supportsUnicode,
721
757
  selectable,
758
+ pickWindow,
722
759
  unicode: U,
723
760
  width,
724
761
  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.12.0",
3
+ "version": "0.14.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
  },