@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/README.md +4 -4
- package/bin/bolt.js +21 -21
- package/lib/agent.js +51 -40
- package/lib/api.js +6 -3
- package/lib/browser.js +19 -3
- package/lib/cli.js +141 -54
- package/lib/completion.js +1 -1
- package/lib/config.js +22 -1
- package/lib/permissions.js +1 -1
- package/lib/present.js +12 -11
- package/lib/toolparse.js +752 -0
- package/lib/tools.js +9 -27
- package/lib/ui.js +67 -30
- package/lib/updatecheck.js +114 -0
- package/package.json +1 -4
package/README.md
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
# bolt CLI
|
|
2
2
|
|
|
3
|
-
Authorized testing + tool-building from your terminal or VS Code integrated terminal. Zero dependencies, Node 18
|
|
3
|
+
Authorized testing + tool-building from your terminal or VS Code integrated terminal. Zero dependencies, Node 18. Single backend (Bolt) only: no providers, no model picker - every run bills your token balance like the workspace.
|
|
4
4
|
|
|
5
|
-
## Install
|
|
5
|
+
## Install (recommended)
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
8
|
npm install -g @bolt-cli/cli
|
|
9
9
|
bolt --help
|
|
10
10
|
```
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
Or, from the repo (same version):
|
|
13
13
|
|
|
14
14
|
```bash
|
|
15
15
|
npm install -g ./cli
|
|
@@ -100,7 +100,7 @@ Press **Esc** during any run to stop it — the session is saved, no need to kil
|
|
|
100
100
|
|
|
101
101
|
Colors and glyphs follow your terminal: full color on a TTY, plain text on pipes and CI so logs and `--format json > file` stay parseable. Git Bash, Windows Terminal, and VS Code are detected even without a TTY. Override either way with `FORCE_COLOR=1|2|3` (force on) or `NO_COLOR=1` (force off).
|
|
102
102
|
|
|
103
|
-
## Interactive mode (
|
|
103
|
+
## Interactive mode (modern terminal)
|
|
104
104
|
|
|
105
105
|
```bash
|
|
106
106
|
bolt
|
package/bin/bolt.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
// bolt — terminal CLI for Bolt authorized testing.
|
|
4
|
-
// Zero dependencies: Node 18+ built-ins only.
|
|
5
|
-
const path = require("path");
|
|
6
|
-
|
|
7
|
-
async function main() {
|
|
8
|
-
const { run } = require(path.join(__dirname, "..", "lib", "cli.js"));
|
|
9
|
-
await run(process.argv.slice(2));
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
main().catch((err) => {
|
|
13
|
-
const message = err && err.message ? err.message : String(err);
|
|
14
|
-
try {
|
|
15
|
-
const ui = require(path.join(__dirname, "..", "lib", "ui.js"));
|
|
16
|
-
ui.err(`bolt: ${message}`);
|
|
17
|
-
} catch {
|
|
18
|
-
console.error(`bolt: ${message}`);
|
|
19
|
-
}
|
|
20
|
-
process.exit(1);
|
|
21
|
-
});
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
// bolt — terminal CLI for Bolt authorized testing.
|
|
4
|
+
// Zero dependencies: Node 18+ built-ins only.
|
|
5
|
+
const path = require("path");
|
|
6
|
+
|
|
7
|
+
async function main() {
|
|
8
|
+
const { run } = require(path.join(__dirname, "..", "lib", "cli.js"));
|
|
9
|
+
await run(process.argv.slice(2));
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
main().catch((err) => {
|
|
13
|
+
const message = err && err.message ? err.message : String(err);
|
|
14
|
+
try {
|
|
15
|
+
const ui = require(path.join(__dirname, "..", "lib", "ui.js"));
|
|
16
|
+
ui.err(`bolt: ${message}`);
|
|
17
|
+
} catch {
|
|
18
|
+
console.error(`bolt: ${message}`);
|
|
19
|
+
}
|
|
20
|
+
process.exit(1);
|
|
21
|
+
});
|
package/lib/agent.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// The agent loop: multi-turn tool use in the style of
|
|
2
|
+
// The agent loop: multi-turn tool use in the style of modern agent CLIs.
|
|
3
3
|
//
|
|
4
4
|
// The Bolt backend is a text-in/text-out agent, so the loop is client-driven:
|
|
5
5
|
// the CLI describes the tool protocol in the prompt, parses ```tool blocks
|
|
@@ -10,9 +10,10 @@
|
|
|
10
10
|
const api = require("./api");
|
|
11
11
|
const session = require("./session");
|
|
12
12
|
const tools = require("./tools");
|
|
13
|
+
const toolparse = require("./toolparse");
|
|
13
14
|
const redact = require("./redact");
|
|
14
15
|
|
|
15
|
-
const DEFAULT_MAX_ITERS =
|
|
16
|
+
const DEFAULT_MAX_ITERS = 16;
|
|
16
17
|
const MAX_RESULT_CHARS = 4_000;
|
|
17
18
|
|
|
18
19
|
// The tool protocol body. Sent wrapped in <terminal-capabilities> sentinels
|
|
@@ -40,6 +41,14 @@ terminal asks them, then returns the outcome. There are no other tool
|
|
|
40
41
|
names: anything not in the list below is rejected, and the rejection tells
|
|
41
42
|
you to restate the intent with these tools (usually bash).
|
|
42
43
|
|
|
44
|
+
Call format is strict: emit every tool call ONLY as a fenced \`\`\`tool
|
|
45
|
+
block. Never as XML or chat-template syntax (<tool>, <tool_call>,
|
|
46
|
+
<function>, <function_calls>, <invoke>), never as bare JSON outside a
|
|
47
|
+
fence, and never wrapped in 自知 or similar markup - the operator-visible
|
|
48
|
+
channel reads fenced blocks, and anything else reaches them as raw garbage.
|
|
49
|
+
Never send an empty reply: if you have nothing to add, state in one
|
|
50
|
+
sentence that the task is complete.
|
|
51
|
+
|
|
43
52
|
Tools:
|
|
44
53
|
- read {path, offset?, limit?} - read a file (free, always allowed)
|
|
45
54
|
- list {path?} - list a directory (free, always allowed)
|
|
@@ -104,7 +113,9 @@ function buildAgentPrompt({ target, objective, evidence, history, memory, sessio
|
|
|
104
113
|
return `${api.buildPrompt({ target, objective, evidence, history, memory, session, account })}\n\n${TOOL_PROTOCOL}`;
|
|
105
114
|
}
|
|
106
115
|
|
|
107
|
-
|
|
116
|
+
const EMPTY_REPLY_NUDGE = `Your previous reply arrived at this terminal empty - no prose and no tool block. That is a protocol failure, not an answer, so TOOL_RESULTS is not attached this time. Do not re-send internal reasoning, 自知 blocks or tool call syntax in any other shape. Either continue the task with one or more \`\`\`tool blocks, or give the final answer in plain prose. Reply now.`;
|
|
117
|
+
|
|
118
|
+
function buildFollowup({ iteration, calls, results, errors = [], seenDetails = null, maxIters = DEFAULT_MAX_ITERS, syntaxNote = null }) {
|
|
108
119
|
const lines = [`TOOL_RESULTS for iteration ${iteration} (ground truth from this terminal - do not invent, continue the task):`];
|
|
109
120
|
for (let i = 0; i < calls.length; i += 1) {
|
|
110
121
|
const call = calls[i];
|
|
@@ -126,7 +137,13 @@ function buildFollowup({ iteration, calls, results, errors = [], seenDetails = n
|
|
|
126
137
|
if (errors.length) {
|
|
127
138
|
lines.push("Those blocks named tools that do not exist here. Restate each intent with the eight tools above — DNS, HTTP, subdomain, and port work all go through bash (dig, nslookup, curl, nmap), never a bespoke tool name — then continue the task.");
|
|
128
139
|
}
|
|
129
|
-
|
|
140
|
+
// When calls arrived in drifted syntax (XML/JSON), say so once: the calls
|
|
141
|
+
// were still parsed and executed, and the model is coached back to the
|
|
142
|
+
// canonical channel it was instructed to use.
|
|
143
|
+
if (syntaxNote) lines.push(syntaxNote);
|
|
144
|
+
lines.push(iteration >= maxIters - 1
|
|
145
|
+
? "Next iteration is your last: finish the task now with the evidence you have. No new tool blocks unless strictly required; if something essential remains, say exactly what to run next."
|
|
146
|
+
: "Continue with the next step, using more tools if needed, or give the final answer with no tool blocks.");
|
|
130
147
|
// Restated every turn on purpose: without it the model reverts to refusing
|
|
131
148
|
// local work it already performed. These results prove the channel works.
|
|
132
149
|
lines.push("Local terminal tools (read, list, glob, grep, write, edit, bash, ask via ```tool blocks) remain available this turn - files, shell, recon, installs, and privileged commands through bash, with operator approval where needed. Never claim the local tools are unavailable.");
|
|
@@ -173,6 +190,7 @@ async function runAgentLoop({ cfg, objective, mode, target, evidence, sess, stre
|
|
|
173
190
|
let text = "";
|
|
174
191
|
let done = null;
|
|
175
192
|
let iters = 0;
|
|
193
|
+
let nudged = false; // one silent-reply recovery per run
|
|
176
194
|
let cancelled = false;
|
|
177
195
|
const toolCalls = [];
|
|
178
196
|
// Byte-identical tool results across the run collapse to a pointer line
|
|
@@ -229,7 +247,13 @@ async function runAgentLoop({ cfg, objective, mode, target, evidence, sess, stre
|
|
|
229
247
|
text = collected.join("");
|
|
230
248
|
done = turn.done;
|
|
231
249
|
|
|
232
|
-
|
|
250
|
+
// Model-agnostic extraction: fenced blocks first, but XML tool tags
|
|
251
|
+
// (<tool_call>, <function_calls>, <invoke>...), bare JSON and unclosed
|
|
252
|
+
// final fences are recovered too — a drifted syntax must execute, not
|
|
253
|
+
// print. `cleaned` is the operator prose with every machine block
|
|
254
|
+
// removed (including 自知 reasoning).
|
|
255
|
+
const extraction = toolparse.extractToolCalls(text);
|
|
256
|
+
const { calls, errors, cleaned, usedNonFence } = extraction;
|
|
233
257
|
const results = [];
|
|
234
258
|
for (const call of calls) {
|
|
235
259
|
// `ask` is a question for the operator, not a machine call: it never
|
|
@@ -290,7 +314,7 @@ async function runAgentLoop({ cfg, objective, mode, target, evidence, sess, stre
|
|
|
290
314
|
if (sess) {
|
|
291
315
|
session.appendTurn(sess, {
|
|
292
316
|
prompt: iters === 1 ? objective : `[tool follow-up ${iters}]`,
|
|
293
|
-
response: text,
|
|
317
|
+
response: cleaned || text,
|
|
294
318
|
mode,
|
|
295
319
|
target,
|
|
296
320
|
tools: calls.map((call, i) => ({ tool: call.tool, ok: results[i] ? results[i].ok : false })),
|
|
@@ -299,52 +323,39 @@ async function runAgentLoop({ cfg, objective, mode, target, evidence, sess, stre
|
|
|
299
323
|
// Rejected blocks still deserve a follow-up turn: the model must see the
|
|
300
324
|
// rejection and restate its intent, or it concludes the channel is broken
|
|
301
325
|
// and refuses work the terminal could have done. maxIters still bounds us.
|
|
302
|
-
if (!calls.length && !errors.length)
|
|
326
|
+
if (!calls.length && !errors.length) {
|
|
327
|
+
if (cleaned.trim()) break; // normal final answer
|
|
328
|
+
// Empty reply — the classic "replied with nothing" failure. Nudge
|
|
329
|
+
// once; a second consecutive silent reply stops the run honestly.
|
|
330
|
+
if (nudged) break;
|
|
331
|
+
nudged = true;
|
|
332
|
+
prompt = scrub(EMPTY_REPLY_NUDGE);
|
|
333
|
+
continue;
|
|
334
|
+
}
|
|
335
|
+
nudged = false;
|
|
303
336
|
|
|
304
337
|
if (signal && signal.aborted) {
|
|
305
338
|
cancelled = true;
|
|
306
339
|
break;
|
|
307
340
|
}
|
|
308
|
-
|
|
341
|
+
const syntaxNote = usedNonFence
|
|
342
|
+
? "Note: one or more of your tool calls arrived in non-canonical syntax (XML tool tags or bare JSON instead of a ```tool fence). They were parsed and executed anyway, but emit calls ONLY as fenced ```tool blocks from here on - other shapes risk misreading."
|
|
343
|
+
: null;
|
|
344
|
+
prompt = scrub(buildFollowup({ iteration: iters, calls, results, errors, seenDetails, maxIters, syntaxNote }));
|
|
309
345
|
}
|
|
310
346
|
return { text, done, iters, toolCalls, cancelled };
|
|
311
347
|
}
|
|
312
348
|
|
|
313
349
|
/**
|
|
314
|
-
*
|
|
315
|
-
*
|
|
316
|
-
*
|
|
317
|
-
* the
|
|
350
|
+
* Filter that hides raw machine syntax from the visible stream: ```tool /
|
|
351
|
+
* ```ask blocks, XML tool tags (<tool_call>, <function_calls>, <invoke>...) and
|
|
352
|
+
* 自知 reasoning. Tool activity is rendered separately as status cards (see
|
|
353
|
+
* the caller's event handler), so what the model emits for the machine
|
|
354
|
+
* never clutters what the human reads. Chunk-boundary safe, and unclosed
|
|
355
|
+
* blocks are swallowed or dropped after a cap — never leaked raw.
|
|
318
356
|
*/
|
|
319
357
|
function toolFenceWriter(write) {
|
|
320
|
-
|
|
321
|
-
let inFence = false;
|
|
322
|
-
const flushLine = (line) => {
|
|
323
|
-
const trimmed = line.trim();
|
|
324
|
-
if (!inFence && /^```(tool|ask)(\s|$)/.test(trimmed)) {
|
|
325
|
-
inFence = true;
|
|
326
|
-
return;
|
|
327
|
-
}
|
|
328
|
-
if (inFence) {
|
|
329
|
-
if (/^```\s*$/.test(trimmed)) inFence = false;
|
|
330
|
-
return;
|
|
331
|
-
}
|
|
332
|
-
write(`${line}\n`);
|
|
333
|
-
};
|
|
334
|
-
return {
|
|
335
|
-
write(text) {
|
|
336
|
-
if (!text) return;
|
|
337
|
-
buf += text;
|
|
338
|
-
const parts = buf.split("\n");
|
|
339
|
-
buf = parts.pop() ?? "";
|
|
340
|
-
for (const part of parts) flushLine(part);
|
|
341
|
-
},
|
|
342
|
-
end() {
|
|
343
|
-
if (buf) flushLine(buf);
|
|
344
|
-
buf = "";
|
|
345
|
-
inFence = false;
|
|
346
|
-
},
|
|
347
|
-
};
|
|
358
|
+
return toolparse.createMarkupFilter(write);
|
|
348
359
|
}
|
|
349
360
|
|
|
350
361
|
module.exports = { TOOL_PROTOCOL, TOOL_PROTOCOL_BODY, TERMINAL_BEGIN, TERMINAL_END, DEFAULT_MAX_ITERS, buildAgentPrompt, buildFollowup, runAgentLoop, truncateResult, summarizeDetail, toolFenceWriter, scrubOutbound };
|
package/lib/api.js
CHANGED
|
@@ -78,7 +78,7 @@ function buildPrompt({ target, objective, evidence, history, memory, session, ac
|
|
|
78
78
|
if (evidence) blocks.push(`Evidence:\n${evidence}`);
|
|
79
79
|
blocks.push(`Objective:\n${objective}`);
|
|
80
80
|
blocks.push(
|
|
81
|
-
"
|
|
81
|
+
"Write all explanatory text in English unless the operator explicitly requests another language. Do not infer language preference from the request, terminal locale, terminal output, or source files. Preserve code, identifiers, filenames, and quoted content exactly. Keep every claim tied to evidence you were given, and mark anything unverified as unverified.",
|
|
82
82
|
);
|
|
83
83
|
return blocks.join("\n\n");
|
|
84
84
|
}
|
|
@@ -97,7 +97,10 @@ function topUpUrl(url) {
|
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
// Streams SSE from /api/generate. Calls onToken(text) per chunk.
|
|
100
|
-
// `source` tags the run
|
|
100
|
+
// `source` tags the run origin: "cli" for terminal runs, "watch" for Sentinel
|
|
101
|
+
// triage, "interactive" only for the web dashboard. The default here is "cli"
|
|
102
|
+
// so every terminal turn is attributable server-side without each caller
|
|
103
|
+
// remembering to pass it.
|
|
101
104
|
// so the server can meter background triage separately from live sessions.
|
|
102
105
|
// Resolves with { outputTokens, tokenCost, remainingTokens, truncated }.
|
|
103
106
|
// Throws errors with `.code`: INSUFFICIENT_TOKENS (402 or mid-stream
|
|
@@ -133,7 +136,7 @@ async function streamGenerate({ url, token, prompt, mode, onToken, signal, sourc
|
|
|
133
136
|
res = await reachableFetch(`${url}/api/generate`, {
|
|
134
137
|
method: "POST",
|
|
135
138
|
headers: { "Content-Type": "application/json", ...authHeaders(token) },
|
|
136
|
-
body: JSON.stringify(
|
|
139
|
+
body: JSON.stringify({ prompt, mode, source: source || "cli" }),
|
|
137
140
|
signal,
|
|
138
141
|
});
|
|
139
142
|
} catch (error) {
|
package/lib/browser.js
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
// containers. Zero deps: node:child_process only.
|
|
8
8
|
|
|
9
9
|
const { spawn } = require("node:child_process");
|
|
10
|
+
const ui = require("./ui");
|
|
10
11
|
|
|
11
12
|
const POLL_MAX_WAIT_MS = 10 * 60 * 1000;
|
|
12
13
|
|
|
@@ -67,11 +68,26 @@ async function signInWithBrowser({ url, open = true, log = () => {}, spinner = n
|
|
|
67
68
|
const deadline = Date.now() + Math.min((grant.expires_in || 600) * 1000, POLL_MAX_WAIT_MS);
|
|
68
69
|
|
|
69
70
|
// 2. Show the code big and open the approval page with it prefilled.
|
|
71
|
+
// The card, not bare lines: the code is the one thing the user must carry
|
|
72
|
+
// across, so it gets the hero line, and the steps read in order. The box
|
|
73
|
+
// degrades to ASCII cleanly when the terminal is basic.
|
|
70
74
|
const verificationUri = grant.verification_uri_complete || grant.verification_uri;
|
|
71
75
|
log("");
|
|
72
|
-
log(
|
|
73
|
-
|
|
74
|
-
|
|
76
|
+
log(
|
|
77
|
+
ui.box({
|
|
78
|
+
title: "terminal sign-in",
|
|
79
|
+
w: ui.width(),
|
|
80
|
+
lines: [
|
|
81
|
+
`1 ${ui.c.muted("your browser should open on the approval page")}`,
|
|
82
|
+
`2 ${ui.c.muted("if it did not, open")} ${ui.c.primary(grant.verification_uri)}`,
|
|
83
|
+
`3 ${ui.c.muted("enter the code shown in your terminal")}`,
|
|
84
|
+
"",
|
|
85
|
+
`${ui.c.primary(ui.c.bold(grant.user_code))}`,
|
|
86
|
+
"",
|
|
87
|
+
`${ui.c.muted("approve only a code you just saw printed here - it expires and works once")}`,
|
|
88
|
+
],
|
|
89
|
+
}),
|
|
90
|
+
);
|
|
75
91
|
log("");
|
|
76
92
|
const opened = open ? openBrowser(verificationUri) : false;
|
|
77
93
|
if (spinner && typeof spinner.start === "function") {
|