@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/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
|
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
|
@@ -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") {
|
package/lib/cli.js
CHANGED
|
@@ -25,6 +25,7 @@ const exporter = require("./export");
|
|
|
25
25
|
const checkpoints = require("./checkpoints");
|
|
26
26
|
const cancel = require("./cancel");
|
|
27
27
|
const watch = require("./watch");
|
|
28
|
+
const updatecheck = require("./updatecheck");
|
|
28
29
|
|
|
29
30
|
const VERSION = require(path.join(__dirname, "..", "package.json")).version;
|
|
30
31
|
|
|
@@ -36,6 +37,7 @@ function help(topic) {
|
|
|
36
37
|
if (t === "session") return `bolt session [list|show <id>|delete <id>|new] — local sessions at ~/.bolt/sessions/\n\n bolt session list\n bolt session show <id>\n bolt export <id> --format md|json|sarif [--output file]\n`;
|
|
37
38
|
if (t === "export") return `bolt export <id> [--format md|json|sarif] [--output file]\n\nmd for humans, json for scripts, sarif for CI code-scanning (GitHub compatible).\n`;
|
|
38
39
|
if (t === "doctor") return `bolt doctor — pre-flight checks: node version, auth, backend reachability, WSL, clipboard.\n\nExits non-zero when a check fails. Run before reporting bugs.\n`;
|
|
40
|
+
if (t === "update") return `bolt update — upgrade the globally installed CLI via npm (runs: npm install -g @bolt-cli/cli).\n\nThe check that notices a new release is automatic and quiet (12h cadence, BOLT_NO_UPDATE_CHECK=1 to disable); the upgrade itself always asks: run bolt update.\n`;
|
|
39
41
|
if (t === "completion") return `bolt completion <bash|zsh|fish|powershell> — print shell completions to stdout.\n\n bolt completion bash >> ~/.bashrc\n bolt completion zsh >> ~/.zshrc\n`;
|
|
40
42
|
if (t === "undo") return `bolt undo <path> — restore the last backup of a file written/edited by the agent.\n\nBackups live under ~/.bolt/backups/ (last 10 kept per file).\n`;
|
|
41
43
|
if (t === "templates") return `bolt templates [name] — printable lab runbooks shipped with Bolt.\n\n bolt templates list (ASLR probe, crash-offset pattern)\n bolt templates aslr-offset-probe.sh print to stdout\n bolt templates README the lab-only guide\n\nAuthorized lab work only; every script prints an authorization notice.\n`;
|
|
@@ -59,9 +61,10 @@ Usage:
|
|
|
59
61
|
bolt templates [name] print lab runbooks (ASLR probe, offsets)
|
|
60
62
|
bolt watch <subcommand> background defensive checks (status|check|start|stop|…)
|
|
61
63
|
bolt doctor pre-flight checks (node, auth, backend, WSL)
|
|
64
|
+
bolt update upgrade the CLI via npm (notice appears when a release ships)
|
|
62
65
|
bolt completion <shell> shell completions (bash|zsh|fish|powershell)
|
|
63
66
|
bolt balance tokens, runs, spend
|
|
64
|
-
bolt help <command> per-command help (run|build|session|export|doctor|completion|undo|watch|templates)
|
|
67
|
+
bolt help <command> per-command help (run|build|session|export|doctor|completion|undo|watch|templates|update)
|
|
65
68
|
|
|
66
69
|
Press Esc during any run to stop it (the session is saved). Out of tokens
|
|
67
70
|
stops the run at once with the top-up link — it never spins forever.
|
|
@@ -457,9 +460,13 @@ async function watchTriageIncident(cfg, incident) {
|
|
|
457
460
|
const clean = redact.redact(evidence);
|
|
458
461
|
const prompt = api.buildPrompt({ objective, evidence: clean.text, mode: "defensive" });
|
|
459
462
|
const stream = ui.createStream(ui.errWrite);
|
|
463
|
+
// Machine syntax that a drifted model emits (tool blocks, XML tags, think
|
|
464
|
+
// reasoning) must never reach the operator's screen, even in triage.
|
|
465
|
+
const filtered = agent.toolFenceWriter((t) => stream.write(t));
|
|
460
466
|
let text = "";
|
|
461
467
|
try {
|
|
462
|
-
await api.streamGenerate({ url: cfg.url, token: cfg.token, prompt, mode: "defensive", source: "watch", onToken: (t) => { text += t;
|
|
468
|
+
await api.streamGenerate({ url: cfg.url, token: cfg.token, prompt, mode: "defensive", source: "watch", onToken: (t) => { text += t; filtered.write(t); } });
|
|
469
|
+
filtered.end();
|
|
463
470
|
stream.end();
|
|
464
471
|
return { ok: true, text: redact.redact(text).text };
|
|
465
472
|
} catch (error) {
|
|
@@ -1056,7 +1063,14 @@ async function executeTurn({ cfg, objective, mode, target, evidence, sess, onTok
|
|
|
1056
1063
|
session: sess ? sess.id : "", account: cfg.email || "",
|
|
1057
1064
|
});
|
|
1058
1065
|
const scrubbed = redact.redact(raw);
|
|
1059
|
-
|
|
1066
|
+
// Even without the tool loop, a drifted model may emit machine syntax —
|
|
1067
|
+
// never show it to the operator.
|
|
1068
|
+
const filtered = onToken ? agent.toolFenceWriter(onToken) : null;
|
|
1069
|
+
const { text, done } = await api.streamGenerate({
|
|
1070
|
+
url: cfg.url, token: cfg.token, prompt: scrubbed.text, mode, signal,
|
|
1071
|
+
onToken: filtered ? (t) => filtered.write(t) : onToken,
|
|
1072
|
+
});
|
|
1073
|
+
if (filtered) filtered.end();
|
|
1060
1074
|
if (sess) session.appendTurn(sess, { prompt: objective, response: text, mode, target });
|
|
1061
1075
|
return { text, done, redactions: scrubbed.count };
|
|
1062
1076
|
}
|
|
@@ -1375,6 +1389,38 @@ async function cmdDoctor() {
|
|
|
1375
1389
|
}
|
|
1376
1390
|
}
|
|
1377
1391
|
|
|
1392
|
+
// ── update ────────────────────────────────────────────────────────────────
|
|
1393
|
+
// `bolt update` shells npm to upgrade the globally installed package. npm's
|
|
1394
|
+
// launcher is a .cmd on Windows, so the child runs through a shell; stdio is
|
|
1395
|
+
// inherited so the npm progress bars show as they are.
|
|
1396
|
+
function cmdUpdate() {
|
|
1397
|
+
console.log(`running: npm install -g @bolt-cli/cli (current: v${VERSION})`);
|
|
1398
|
+
const child = spawn("npm", ["install", "-g", "@bolt-cli/cli"], { stdio: "inherit", shell: process.platform === "win32" });
|
|
1399
|
+
return new Promise((resolve) => {
|
|
1400
|
+
child.on("error", (error) => {
|
|
1401
|
+
ui.err(`update failed: ${error.message} - try: npm install -g @bolt-cli/cli`);
|
|
1402
|
+
resolve();
|
|
1403
|
+
});
|
|
1404
|
+
child.on("close", (code) => {
|
|
1405
|
+
if (code === 0) {
|
|
1406
|
+
// Restart into the new version before the next check: clear the
|
|
1407
|
+
// cached check so the fresh install re-verifies against the registry
|
|
1408
|
+
// instead of greeting itself with a stale notice.
|
|
1409
|
+
try {
|
|
1410
|
+
const cfg = config.load();
|
|
1411
|
+
config.save({ ...cfg, updateCheckedAt: 0, updateLatest: "" });
|
|
1412
|
+
} catch {
|
|
1413
|
+
// Cache hygiene is best-effort; the update itself already succeeded.
|
|
1414
|
+
}
|
|
1415
|
+
ui.ok("update complete - restart bolt to run the new version");
|
|
1416
|
+
} else {
|
|
1417
|
+
ui.err(`update failed (exit ${code}) - try: npm install -g @bolt-cli/cli`);
|
|
1418
|
+
}
|
|
1419
|
+
resolve();
|
|
1420
|
+
});
|
|
1421
|
+
});
|
|
1422
|
+
}
|
|
1423
|
+
|
|
1378
1424
|
function cmdCompletion(rest) {
|
|
1379
1425
|
const shell = rest[0] || "";
|
|
1380
1426
|
if (!shell) throw new Error("Usage: bolt completion <bash|zsh|fish|powershell>");
|
|
@@ -1571,8 +1617,7 @@ function pickTip(n) {
|
|
|
1571
1617
|
// Welcome lines for the REPL box. Hints adapt to terminal capability:
|
|
1572
1618
|
// arrow-key verbs are only promised where raw mode exists, otherwise the
|
|
1573
1619
|
// numbered picker is the path. Pure (ui.c degrades to identity), tested.
|
|
1574
|
-
function replWelcomeLines({ sid,
|
|
1575
|
-
const pickHint = arrowKeys ? "up/down to pick" : "type the number to run";
|
|
1620
|
+
function replWelcomeLines({ sid, host, cwd, tip, update }) {
|
|
1576
1621
|
const lines = [
|
|
1577
1622
|
`${ui.c.primary(ui.c.bold("bolt"))} ${ui.c.muted("interactive")} ${ui.c.muted(ui.GLYPH.dot)} ${ui.c.muted("Bolt backend only - runs bill your token balance")}`,
|
|
1578
1623
|
`${ui.c.muted("session")} ${ui.c.primary(sid)}`,
|
|
@@ -1583,11 +1628,15 @@ function replWelcomeLines({ sid, arrowKeys, host, cwd, tip }) {
|
|
|
1583
1628
|
if (cwd) where.push(`${ui.c.muted("cwd")} ${cwd}`);
|
|
1584
1629
|
lines.push(where.join(` ${ui.c.muted(ui.GLYPH.dot)} `));
|
|
1585
1630
|
}
|
|
1631
|
+
if (update) {
|
|
1632
|
+
lines.push("", `${ui.c.warning("update")} ${update}`);
|
|
1633
|
+
}
|
|
1586
1634
|
lines.push(
|
|
1587
1635
|
"",
|
|
1588
1636
|
ui.bullets([
|
|
1589
1637
|
"type a task and press enter to run it",
|
|
1590
|
-
`${ui.c.bold("/")}
|
|
1638
|
+
`${ui.c.bold("/")} opens the command dropdown ${ui.c.muted(ui.GLYPH.dot)} type to filter, up/down to pick, ${ui.c.bold("Tab")} fills and keeps your place`,
|
|
1639
|
+
`${ui.c.bold("Tab")} completes commands and their arguments ${ui.c.muted(ui.GLYPH.dot)} ${ui.c.bold("@path")} attaches a file ${ui.c.muted(ui.GLYPH.dot)} ${ui.c.bold("/help <cmd>")} detail`,
|
|
1591
1640
|
`${ui.c.bold("/status")} dashboard ${ui.c.muted(ui.GLYPH.dot)} ${ui.c.bold("/sessions")} resume ${ui.c.muted(ui.GLYPH.dot)} ${ui.c.bold("?")} help ${ui.c.muted(ui.GLYPH.dot)} ${ui.c.bold("/keys")} shortcuts ${ui.c.muted(ui.GLYPH.dot)} ${ui.c.bold("/help <cmd>")} detail`,
|
|
1592
1641
|
`${ui.c.bold("/agents")} presets ${ui.c.muted(ui.GLYPH.dot)} ${ui.c.bold("/target")} scope ${ui.c.muted(ui.GLYPH.dot)} ${ui.c.bold("/init")} map repo ${ui.c.muted(ui.GLYPH.dot)} ${ui.c.bold("/mode")} offensive or defensive`,
|
|
1593
1642
|
`${ui.c.bold("/doctor")} health ${ui.c.muted(ui.GLYPH.dot)} ${ui.c.bold("/export")} file ${ui.c.muted(ui.GLYPH.dot)} ${ui.c.bold("/undo")} restore ${ui.c.muted(ui.GLYPH.dot)} ${ui.c.bold("/exit")} save and quit`,
|
|
@@ -1660,6 +1709,39 @@ function completer(line) {
|
|
|
1660
1709
|
const hits = completeFileFrag(frag.trimStart()).map((h) => `/file ${h}`);
|
|
1661
1710
|
return [hits, line];
|
|
1662
1711
|
}
|
|
1712
|
+
if (line.startsWith("/undo ")) {
|
|
1713
|
+
const frag = line.slice(6).trimStart();
|
|
1714
|
+
const hits = completeFileFrag(frag).map((h) => `/undo ${h}`);
|
|
1715
|
+
return [hits, line];
|
|
1716
|
+
}
|
|
1717
|
+
if (line.startsWith("/export ")) {
|
|
1718
|
+
const frag = line.slice(8).trim().toLowerCase();
|
|
1719
|
+
const hits = ["md", "json", "sarif"].filter((f) => f.startsWith(frag)).map((f) => `/export ${f}`);
|
|
1720
|
+
return [hits, line];
|
|
1721
|
+
}
|
|
1722
|
+
if (line.startsWith("/templates ")) {
|
|
1723
|
+
const frag = line.slice(11).trim().toLowerCase();
|
|
1724
|
+
let names = ["README.md"];
|
|
1725
|
+
try {
|
|
1726
|
+
names = ["README.md", ...fs.readdirSync(templateDir()).filter((f) => f !== "README.md" && !f.startsWith("."))];
|
|
1727
|
+
} catch {
|
|
1728
|
+
// install without templates: README alone is still completable
|
|
1729
|
+
}
|
|
1730
|
+
const hits = names.filter((n) => n.toLowerCase().startsWith(frag)).map((n) => `/templates ${n}`);
|
|
1731
|
+
return [hits, line];
|
|
1732
|
+
}
|
|
1733
|
+
if (line.startsWith("/watch ")) {
|
|
1734
|
+
const frag = line.slice(7).trim().toLowerCase();
|
|
1735
|
+
const subs = ["status", "check", "start", "stop", "events", "policy", "playbook", "baseline", "respond"];
|
|
1736
|
+
const hits = subs.filter((s) => s.startsWith(frag)).map((s) => `/watch ${s}`);
|
|
1737
|
+
return [hits, line];
|
|
1738
|
+
}
|
|
1739
|
+
if (line.startsWith("/help ")) {
|
|
1740
|
+
const frag = line.slice(6).trim().toLowerCase();
|
|
1741
|
+
const bases = [...new Set(COMMANDS.map(([cmd]) => cmd.split(" ")[0]))];
|
|
1742
|
+
const hits = bases.filter((b) => b.slice(1).startsWith(frag)).map((b) => `/help ${b.slice(1)}`);
|
|
1743
|
+
return [hits, line];
|
|
1744
|
+
}
|
|
1663
1745
|
if (line.startsWith("/resume ") || line.startsWith("/session ") || line.startsWith("/sessions ")) {
|
|
1664
1746
|
const prefix = line.startsWith("/resume ") ? "/resume " : line.startsWith("/sessions ") ? "/sessions " : "/session ";
|
|
1665
1747
|
const frag = line.slice(prefix.length).trim().toLowerCase();
|
|
@@ -1774,20 +1856,27 @@ async function cmdRepl() {
|
|
|
1774
1856
|
|
|
1775
1857
|
console.log("");
|
|
1776
1858
|
for (const row of ui.LOGO) console.log(ui.c.primary(ui.c.bold(row)));
|
|
1859
|
+
// Update notice comes from the cache first (instant, no network); a stale
|
|
1860
|
+
// cache is refreshed in the background for the next session, and a newly
|
|
1861
|
+
// discovered update prints one line mid-session.
|
|
1862
|
+
const cachedUpdate = updatecheck.cachedNotice(VERSION);
|
|
1777
1863
|
console.log(
|
|
1778
1864
|
ui.box({
|
|
1779
1865
|
title: `bolt v${VERSION}`,
|
|
1780
1866
|
w: ui.width(),
|
|
1781
1867
|
lines: replWelcomeLines({
|
|
1782
1868
|
sid: sess.id,
|
|
1783
|
-
arrowKeys: ui.selectable([{ label: "x" }]),
|
|
1784
1869
|
host: backendHost(cfg.url),
|
|
1785
1870
|
cwd: process.cwd(),
|
|
1786
1871
|
tip: pickTip(Math.floor(Date.now() / 86400000)),
|
|
1872
|
+
update: cachedUpdate || undefined,
|
|
1787
1873
|
}),
|
|
1788
1874
|
}),
|
|
1789
1875
|
);
|
|
1790
1876
|
console.log("");
|
|
1877
|
+
void updatecheck
|
|
1878
|
+
.refresh(VERSION, cachedUpdate ? {} : { onNotice: (notice) => console.log(`\n${ui.c.warning(`! ${notice}`)}`) })
|
|
1879
|
+
.catch(() => undefined);
|
|
1791
1880
|
|
|
1792
1881
|
// Balance is a nice-to-have in the prompt, so failure here must never block
|
|
1793
1882
|
// the session.
|
|
@@ -1919,13 +2008,18 @@ async function cmdRepl() {
|
|
|
1919
2008
|
continue;
|
|
1920
2009
|
}
|
|
1921
2010
|
rl.pause();
|
|
1922
|
-
const { item } = await ui.selectLive({ title: "commands", items: all, initialFilter: "" });
|
|
2011
|
+
const { item, tabFill } = await ui.selectLive({ title: "commands", items: all, initialFilter: "" });
|
|
1923
2012
|
rl.resume();
|
|
1924
2013
|
setPrompt();
|
|
1925
2014
|
if (!item) {
|
|
1926
2015
|
rl.prompt();
|
|
1927
2016
|
continue;
|
|
1928
2017
|
}
|
|
2018
|
+
if (tabFill) {
|
|
2019
|
+
rl.write(`${item.label.split(" <")[0].split(" [")[0]} `);
|
|
2020
|
+
rl.prompt();
|
|
2021
|
+
continue;
|
|
2022
|
+
}
|
|
1929
2023
|
if (item.label === "/" || item.label === "/help") {
|
|
1930
2024
|
printPalette("");
|
|
1931
2025
|
rl.prompt();
|
|
@@ -2015,10 +2109,11 @@ async function cmdRepl() {
|
|
|
2015
2109
|
continue;
|
|
2016
2110
|
}
|
|
2017
2111
|
rl.pause();
|
|
2018
|
-
const { item } = await ui.selectLive({ title: "sessions", items, initialFilter: q });
|
|
2112
|
+
const { item, tabFill } = await ui.selectLive({ title: "sessions", items, initialFilter: q });
|
|
2019
2113
|
rl.resume();
|
|
2020
2114
|
setPrompt();
|
|
2021
|
-
if (!item) {
|
|
2115
|
+
if (!item || tabFill) {
|
|
2116
|
+
if (item && tabFill) rl.write(`${item.label.split(" <")[0].split(" [")[0]} `);
|
|
2022
2117
|
rl.prompt();
|
|
2023
2118
|
continue;
|
|
2024
2119
|
}
|
|
@@ -2056,13 +2151,18 @@ async function cmdRepl() {
|
|
|
2056
2151
|
continue;
|
|
2057
2152
|
}
|
|
2058
2153
|
rl.pause();
|
|
2059
|
-
const { item } = await ui.selectLive({ title: "commands", items: all, initialFilter: q });
|
|
2154
|
+
const { item, tabFill } = await ui.selectLive({ title: "commands", items: all, initialFilter: q });
|
|
2060
2155
|
rl.resume();
|
|
2061
2156
|
setPrompt();
|
|
2062
2157
|
if (!item) {
|
|
2063
2158
|
rl.prompt();
|
|
2064
2159
|
continue;
|
|
2065
2160
|
}
|
|
2161
|
+
if (tabFill) {
|
|
2162
|
+
rl.write(`${item.label.split(" <")[0].split(" [")[0]} `);
|
|
2163
|
+
rl.prompt();
|
|
2164
|
+
continue;
|
|
2165
|
+
}
|
|
2066
2166
|
if (item.label === "/" || item.label === "/help") {
|
|
2067
2167
|
printPalette("");
|
|
2068
2168
|
rl.prompt();
|
|
@@ -2498,7 +2598,7 @@ async function run(argv) {
|
|
|
2498
2598
|
// Piped input with no command: single non-interactive run.
|
|
2499
2599
|
return cmdRun([], { buildMode: false });
|
|
2500
2600
|
}
|
|
2501
|
-
if (flag(argv, "-h", "--help") && (cmd === "run" || cmd === "build" || cmd === "watch" || cmd === "session" || cmd === "auth" || cmd === "signin" || cmd === "-p" || cmd === "--print" || cmd === "export" || cmd === "doctor" || cmd === "completion" || cmd === "undo")) {
|
|
2601
|
+
if (flag(argv, "-h", "--help") && (cmd === "run" || cmd === "build" || cmd === "watch" || cmd === "session" || cmd === "auth" || cmd === "signin" || cmd === "-p" || cmd === "--print" || cmd === "export" || cmd === "doctor" || cmd === "completion" || cmd === "undo" || cmd === "update")) {
|
|
2502
2602
|
console.log(help(cmd === "-p" || cmd === "--print" ? "run" : cmd));
|
|
2503
2603
|
return;
|
|
2504
2604
|
}
|
|
@@ -2525,6 +2625,7 @@ async function run(argv) {
|
|
|
2525
2625
|
if (cmd === "build") return cmdRun(rest, { buildMode: true });
|
|
2526
2626
|
if (cmd === "session") return cmdSession(rest);
|
|
2527
2627
|
if (cmd === "doctor") return cmdDoctor();
|
|
2628
|
+
if (cmd === "update") return cmdUpdate();
|
|
2528
2629
|
if (cmd === "completion") return cmdCompletion(rest);
|
|
2529
2630
|
if (cmd === "export") return cmdExport(rest);
|
|
2530
2631
|
if (cmd === "undo") return cmdUndo(rest);
|
package/lib/completion.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Shell completions for bolt. Static word lists only — no subprocesses,
|
|
3
3
|
// no filesystem access. Emitted to stdout so callers can redirect:
|
|
4
4
|
// bolt completion bash >> ~/.bashrc
|
|
5
|
-
const COMMANDS = ["run", "build", "login", "signin", "auth", "balance", "session", "doctor", "completion", "export", "undo", "help"];
|
|
5
|
+
const COMMANDS = ["run", "build", "login", "signin", "auth", "balance", "session", "doctor", "update", "completion", "export", "undo", "help"];
|
|
6
6
|
const FLAGS = [
|
|
7
7
|
"--target", "-t", "--mode", "-m", "--agent", "--tools", "--dry-run", "--allow-all",
|
|
8
8
|
"--max-iters", "-p", "--print", "--file", "-f", "--evidence", "--session", "-s",
|
package/lib/config.js
CHANGED
|
@@ -27,6 +27,10 @@ function load() {
|
|
|
27
27
|
token: cfg.token || process.env.BOLT_TOKEN || "",
|
|
28
28
|
expiresAt: cfg.expiresAt || "",
|
|
29
29
|
email: cfg.email || "",
|
|
30
|
+
// Update-check cache (lib/updatecheck.js): survives every save unless
|
|
31
|
+
// explicitly overwritten, so an auth save never erases the notice.
|
|
32
|
+
updateCheckedAt: typeof cfg.updateCheckedAt === "number" ? cfg.updateCheckedAt : 0,
|
|
33
|
+
updateLatest: typeof cfg.updateLatest === "string" ? cfg.updateLatest : "",
|
|
30
34
|
};
|
|
31
35
|
} catch {
|
|
32
36
|
return {
|
|
@@ -34,14 +38,31 @@ function load() {
|
|
|
34
38
|
token: process.env.BOLT_TOKEN || "",
|
|
35
39
|
expiresAt: "",
|
|
36
40
|
email: "",
|
|
41
|
+
updateCheckedAt: 0,
|
|
42
|
+
updateLatest: "",
|
|
37
43
|
};
|
|
38
44
|
}
|
|
39
45
|
}
|
|
40
46
|
|
|
41
47
|
function save(cfg) {
|
|
42
48
|
fs.mkdirSync(dir(), { recursive: true, mode: 0o700 });
|
|
49
|
+
// Callers own the auth fields; the update-check cache rides along from the
|
|
50
|
+
// previous file unless this save explicitly passes new values.
|
|
51
|
+
let prev = {};
|
|
52
|
+
try {
|
|
53
|
+
prev = JSON.parse(fs.readFileSync(file(), "utf8"));
|
|
54
|
+
} catch {
|
|
55
|
+
// No previous file (first signin): defaults below apply.
|
|
56
|
+
}
|
|
43
57
|
const data = JSON.stringify(
|
|
44
|
-
{
|
|
58
|
+
{
|
|
59
|
+
url: cfg.url,
|
|
60
|
+
token: cfg.token || "",
|
|
61
|
+
expiresAt: cfg.expiresAt || "",
|
|
62
|
+
email: cfg.email || "",
|
|
63
|
+
updateCheckedAt: cfg.updateCheckedAt !== undefined ? cfg.updateCheckedAt : prev.updateCheckedAt || 0,
|
|
64
|
+
updateLatest: cfg.updateLatest !== undefined ? cfg.updateLatest : prev.updateLatest || "",
|
|
65
|
+
},
|
|
45
66
|
null,
|
|
46
67
|
2,
|
|
47
68
|
);
|