@bolt-cli/cli 0.15.1 → 0.15.3
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/agent.js +21 -4
- package/lib/api.js +9 -2
- package/lib/cancel.js +63 -9
- package/lib/cli.js +6 -0
- package/lib/session.js +33 -5
- package/package.json +36 -36
package/lib/agent.js
CHANGED
|
@@ -109,11 +109,20 @@ function summarizeDetail(detail, seenDetails = null) {
|
|
|
109
109
|
return s;
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
+
// The reply-discipline line sits at the VERY END of the first prompt, after
|
|
113
|
+
// the ~12KB protocol. Every saved session showed the same failure: turn 1
|
|
114
|
+
// returned zero tokens, then the empty-reply nudge (also at the end) made the
|
|
115
|
+
// model work immediately. The relay runs a reasoning model whose hidden
|
|
116
|
+
// thinking is not streamed; with the task buried mid-prompt it spent the whole
|
|
117
|
+
// reply there and emitted nothing. This says, in the position that demonstrably
|
|
118
|
+
// works, to answer visibly now - removing the wasted ~30s inference entirely.
|
|
119
|
+
const OUTPUT_DIRECTIVE = `The operator's task above is still active - do it in THIS reply. Emit operator-visible text only: either plain prose or a fenced tool block. Internal reasoning and hidden thinking are NOT delivered to the operator and leave them staring at an empty screen - do not spend the reply on them. If you need to think, first emit a short visible progress line, then continue. Never end a turn with no visible output.`;
|
|
120
|
+
|
|
112
121
|
function buildAgentPrompt({ target, objective, evidence, history, memory, session, account }) {
|
|
113
|
-
return `${api.buildPrompt({ target, objective, evidence, history, memory, session, account })}\n\n${TOOL_PROTOCOL}`;
|
|
122
|
+
return `${api.buildPrompt({ target, objective, evidence, history, memory, session, account })}\n\n${TOOL_PROTOCOL}\n\n${OUTPUT_DIRECTIVE}`;
|
|
114
123
|
}
|
|
115
124
|
|
|
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,
|
|
125
|
+
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. The ORIGINAL TASK is still in this message, above this note: do it now. Do not ask what the task is, do not ask for a target, and do not describe what you could do. 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 finished answer in plain prose.`;
|
|
117
126
|
|
|
118
127
|
function buildFollowup({ iteration, calls, results, errors = [], seenDetails = null, maxIters = DEFAULT_MAX_ITERS, syntaxNote = null }) {
|
|
119
128
|
const lines = [`TOOL_RESULTS for iteration ${iteration} (ground truth from this terminal - do not invent, continue the task):`];
|
|
@@ -187,6 +196,11 @@ async function runAgentLoop({ cfg, objective, mode, target, evidence, sess, stre
|
|
|
187
196
|
};
|
|
188
197
|
const ctx = () => ({ session: sessionId || (sess ? sess.id : ""), account: account || (cfg && cfg.email) || "" });
|
|
189
198
|
let prompt = scrub(buildAgentPrompt({ target, objective, evidence, history: sess ? session.contextBlock(sess) : "", memory, ...ctx() }));
|
|
199
|
+
// Kept verbatim for the one empty-reply recovery. Nudging with only the
|
|
200
|
+
// recovery note used to erase the objective, so the model answered "what
|
|
201
|
+
// would you like me to do?" after a 40-second round trip. The retry now
|
|
202
|
+
// resends the whole original task plus the note.
|
|
203
|
+
const basePrompt = prompt;
|
|
190
204
|
let text = "";
|
|
191
205
|
let done = null;
|
|
192
206
|
let iters = 0;
|
|
@@ -327,9 +341,12 @@ async function runAgentLoop({ cfg, objective, mode, target, evidence, sess, stre
|
|
|
327
341
|
if (cleaned.trim()) break; // normal final answer
|
|
328
342
|
// Empty reply — the classic "replied with nothing" failure. Nudge
|
|
329
343
|
// once; a second consecutive silent reply stops the run honestly.
|
|
344
|
+
// Resend the original objective WITH the note: a bare nudge costs two
|
|
345
|
+
// full inference round trips and still loses the task.
|
|
330
346
|
if (nudged) break;
|
|
331
347
|
nudged = true;
|
|
332
|
-
|
|
348
|
+
emit({ type: "retry", reason: "empty", message: "empty reply from the model - retrying with the original task" });
|
|
349
|
+
prompt = `${basePrompt}\n\n${EMPTY_REPLY_NUDGE}`;
|
|
333
350
|
continue;
|
|
334
351
|
}
|
|
335
352
|
nudged = false;
|
|
@@ -358,4 +375,4 @@ function toolFenceWriter(write) {
|
|
|
358
375
|
return toolparse.createMarkupFilter(write);
|
|
359
376
|
}
|
|
360
377
|
|
|
361
|
-
module.exports = { TOOL_PROTOCOL, TOOL_PROTOCOL_BODY, TERMINAL_BEGIN, TERMINAL_END, DEFAULT_MAX_ITERS, buildAgentPrompt, buildFollowup, runAgentLoop, truncateResult, summarizeDetail, toolFenceWriter, scrubOutbound };
|
|
378
|
+
module.exports = { TOOL_PROTOCOL, TOOL_PROTOCOL_BODY, TERMINAL_BEGIN, TERMINAL_END, OUTPUT_DIRECTIVE, DEFAULT_MAX_ITERS, buildAgentPrompt, buildFollowup, runAgentLoop, truncateResult, summarizeDetail, toolFenceWriter, scrubOutbound };
|
package/lib/api.js
CHANGED
|
@@ -157,8 +157,15 @@ async function streamGenerate({ url, token, prompt, mode, onToken, signal, sourc
|
|
|
157
157
|
const waitSec = retryAfterSecFrom(res, data);
|
|
158
158
|
if (waitSec > 0) {
|
|
159
159
|
try {
|
|
160
|
-
|
|
161
|
-
|
|
160
|
+
// Keep one live line counting down instead of a single frozen
|
|
161
|
+
// estimate followed by a silent wait that looks like a hang.
|
|
162
|
+
const live = Boolean(process.stderr.isTTY);
|
|
163
|
+
const report = (sec) => {
|
|
164
|
+
if (live) process.stderr.write(`\rRate-limited - retrying in ~${sec}s...`);
|
|
165
|
+
};
|
|
166
|
+
report(Math.ceil(waitSec));
|
|
167
|
+
await cancel.sleep(waitSec * 1000, { signal, onTick: report });
|
|
168
|
+
if (live) process.stderr.write("\r\u001b[2K");
|
|
162
169
|
} catch (error) {
|
|
163
170
|
if (error && error.code === "CANCELLED") throw error;
|
|
164
171
|
}
|
package/lib/cancel.js
CHANGED
|
@@ -31,22 +31,75 @@ function canWatchKeys() {
|
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
+
// A lone Esc cancels; an Esc that starts an arrow/function/Alt sequence does
|
|
35
|
+
// not. Treating every ESC byte as a cancel made Up/Down/Home during a run kill
|
|
36
|
+
// it. Pure so the classification is pinned by tests without a real terminal.
|
|
37
|
+
// "escape" means a bare ESC arrived: it is only a cancel if nothing else
|
|
38
|
+
// follows within the grace window (terminals may split a sequence across
|
|
39
|
+
// writes).
|
|
40
|
+
const ESC_GRACE_MS = 40;
|
|
41
|
+
|
|
42
|
+
// Patterns are built from character codes so the source contains no literal
|
|
43
|
+
// control bytes (linters reject those in regex literals, and they are easy to
|
|
44
|
+
// lose in an editor).
|
|
45
|
+
const ESC = String.fromCharCode(27);
|
|
46
|
+
const BEL = String.fromCharCode(7);
|
|
47
|
+
const CTRL_C = String.fromCharCode(3);
|
|
48
|
+
const CSI_RE = new RegExp(`${ESC}\\[[0-9;?]*[ -/]*[@-Z\\^-~]`, "g");
|
|
49
|
+
const SS3_RE = new RegExp(`${ESC}O[A-P]`, "g");
|
|
50
|
+
const OSC_RE = new RegExp(`${ESC}\\][^${BEL}${ESC}]*(?:${BEL}|${ESC}\\\\)`, "g");
|
|
51
|
+
const ALT_RE = new RegExp(`${ESC}[ -Z\\^-~]`, "g");
|
|
52
|
+
|
|
53
|
+
function classifyInput(chunk) {
|
|
54
|
+
const s = String(chunk ?? "");
|
|
55
|
+
if (s.includes(CTRL_C)) return "abort";
|
|
56
|
+
const bare = s
|
|
57
|
+
.replace(CSI_RE, "") // arrows, Home, PageUp, etc.
|
|
58
|
+
.replace(SS3_RE, "") // application-mode arrows
|
|
59
|
+
.replace(OSC_RE, "") // terminal title / clipboard replies
|
|
60
|
+
.replace(ALT_RE, ""); // Alt+printable (leaves a split CSI pending)
|
|
61
|
+
return bare.includes(ESC) ? "escape" : "ignore";
|
|
62
|
+
}
|
|
63
|
+
|
|
34
64
|
function createCanceller() {
|
|
35
65
|
const controller = new AbortController();
|
|
36
66
|
let attached = false;
|
|
37
67
|
let wasRaw = false;
|
|
38
68
|
let handler = null;
|
|
69
|
+
let escTimer = null;
|
|
70
|
+
|
|
71
|
+
function abortNow() {
|
|
72
|
+
try {
|
|
73
|
+
controller.abort();
|
|
74
|
+
} catch {
|
|
75
|
+
// abort() never throws in practice; cancellation must not crash.
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function clearEsc() {
|
|
80
|
+
if (escTimer) clearTimeout(escTimer);
|
|
81
|
+
escTimer = null;
|
|
82
|
+
}
|
|
39
83
|
|
|
40
84
|
function onData(chunk) {
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
85
|
+
const intent = classifyInput(chunk);
|
|
86
|
+
if (intent === "abort") {
|
|
87
|
+
clearEsc();
|
|
88
|
+
abortNow();
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
if (intent === "escape") {
|
|
92
|
+
clearEsc();
|
|
93
|
+
escTimer = setTimeout(() => {
|
|
94
|
+
escTimer = null;
|
|
95
|
+
abortNow();
|
|
96
|
+
}, ESC_GRACE_MS);
|
|
97
|
+
if (escTimer.unref) escTimer.unref();
|
|
98
|
+
return;
|
|
49
99
|
}
|
|
100
|
+
// An escape sequence completed across two writes: its tail cancels the
|
|
101
|
+
// pending lone-Esc abort.
|
|
102
|
+
clearEsc();
|
|
50
103
|
}
|
|
51
104
|
|
|
52
105
|
function attach() {
|
|
@@ -68,6 +121,7 @@ function createCanceller() {
|
|
|
68
121
|
}
|
|
69
122
|
|
|
70
123
|
function detach() {
|
|
124
|
+
clearEsc();
|
|
71
125
|
if (!attached) return;
|
|
72
126
|
try {
|
|
73
127
|
if (handler) process.stdin.removeListener("data", handler);
|
|
@@ -150,4 +204,4 @@ function sleep(ms, { signal, onTick } = {}) {
|
|
|
150
204
|
});
|
|
151
205
|
}
|
|
152
206
|
|
|
153
|
-
module.exports = { createCanceller, isCancelError, cancelError, canWatchKeys, sleep };
|
|
207
|
+
module.exports = { createCanceller, isCancelError, cancelError, canWatchKeys, classifyInput, ESC_GRACE_MS, sleep };
|
package/lib/cli.js
CHANGED
|
@@ -914,6 +914,12 @@ function handleToolEvent(event) {
|
|
|
914
914
|
if (n > 0) ui.info(`redacted ${n} possible secret${n === 1 ? "" : "s"} from the prompt before sending`);
|
|
915
915
|
return;
|
|
916
916
|
}
|
|
917
|
+
if (event.type === "retry") {
|
|
918
|
+
// Say why the second round trip is happening instead of leaving a long
|
|
919
|
+
// silent gap that looks like a hang.
|
|
920
|
+
ui.info(String(event.message || "retrying after an empty reply"));
|
|
921
|
+
return;
|
|
922
|
+
}
|
|
917
923
|
if (event.type === "call") {
|
|
918
924
|
if (!event.approved) {
|
|
919
925
|
if (event.reason && event.reason.startsWith("refused")) ui.warn(`blocked ${tools.describeCall(event.call)} — destructive, no approval path`);
|
package/lib/session.js
CHANGED
|
@@ -40,17 +40,45 @@ function create(title) {
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
function load(id) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
const target = file(id);
|
|
44
|
+
// A process killed mid-save can leave the main file truncated. The staged
|
|
45
|
+
// copy is complete by construction, so recover from it instead of silently
|
|
46
|
+
// treating the session as gone.
|
|
47
|
+
for (const candidate of [target, `${target}.tmp`]) {
|
|
48
|
+
try {
|
|
49
|
+
return JSON.parse(fs.readFileSync(candidate, "utf8"));
|
|
50
|
+
} catch {
|
|
51
|
+
// try the other copy
|
|
52
|
+
}
|
|
47
53
|
}
|
|
54
|
+
return null;
|
|
48
55
|
}
|
|
49
56
|
|
|
50
57
|
function save(session) {
|
|
51
58
|
fs.mkdirSync(dir(), { recursive: true, mode: 0o700 });
|
|
52
59
|
session.updatedAt = new Date().toISOString();
|
|
53
|
-
|
|
60
|
+
const target = file(session.id);
|
|
61
|
+
const staged = `${target}.tmp`;
|
|
62
|
+
// Write the whole document to a sibling file first, then move it into
|
|
63
|
+
// place. A direct write truncates the only copy before the new bytes land,
|
|
64
|
+
// so an Esc/Ctrl-C or a power loss at the wrong moment loses the session.
|
|
65
|
+
fs.writeFileSync(staged, JSON.stringify(session, null, 2), { mode: 0o600 });
|
|
66
|
+
try {
|
|
67
|
+
fs.renameSync(staged, target);
|
|
68
|
+
} catch (error) {
|
|
69
|
+
// Some Windows filesystems refuse a rename over an open destination.
|
|
70
|
+
try {
|
|
71
|
+
fs.copyFileSync(staged, target);
|
|
72
|
+
fs.unlinkSync(staged);
|
|
73
|
+
} catch {
|
|
74
|
+
try {
|
|
75
|
+
fs.unlinkSync(staged);
|
|
76
|
+
} catch {
|
|
77
|
+
// best effort
|
|
78
|
+
}
|
|
79
|
+
throw error;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
54
82
|
return session;
|
|
55
83
|
}
|
|
56
84
|
|
package/package.json
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@bolt-cli/cli",
|
|
3
|
-
"version": "0.15.
|
|
4
|
-
"description": "Bolt terminal CLI — authorized testing and tool-building from your terminal or VS Code.",
|
|
5
|
-
"license": "SEE LICENSE IN LICENSE",
|
|
6
|
-
"type": "commonjs",
|
|
7
|
-
"engines": {
|
|
8
|
-
"node": ">=18"
|
|
9
|
-
},
|
|
10
|
-
"bin": {
|
|
11
|
-
"bolt": "bin/bolt.js"
|
|
12
|
-
},
|
|
13
|
-
"files": [
|
|
14
|
-
"bin/",
|
|
15
|
-
"lib/",
|
|
16
|
-
"templates/",
|
|
17
|
-
"README.md",
|
|
18
|
-
"LICENSE"
|
|
19
|
-
],
|
|
20
|
-
"keywords": [
|
|
21
|
-
"security",
|
|
22
|
-
"pentest",
|
|
23
|
-
"red-team",
|
|
24
|
-
"nmap",
|
|
25
|
-
"bolt"
|
|
26
|
-
],
|
|
27
|
-
"repository": {
|
|
28
|
-
"type": "git",
|
|
29
|
-
"url": "git+https://github.com/WarrenMu/Beera-Cyber-new-.git",
|
|
30
|
-
"directory": "cli"
|
|
31
|
-
},
|
|
32
|
-
"homepage": "https://github.com/WarrenMu/Beera-Cyber-new-#readme",
|
|
33
|
-
"publishConfig": {
|
|
34
|
-
"access": "public"
|
|
35
|
-
}
|
|
36
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@bolt-cli/cli",
|
|
3
|
+
"version": "0.15.3",
|
|
4
|
+
"description": "Bolt terminal CLI — authorized testing and tool-building from your terminal or VS Code.",
|
|
5
|
+
"license": "SEE LICENSE IN LICENSE",
|
|
6
|
+
"type": "commonjs",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": ">=18"
|
|
9
|
+
},
|
|
10
|
+
"bin": {
|
|
11
|
+
"bolt": "bin/bolt.js"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"bin/",
|
|
15
|
+
"lib/",
|
|
16
|
+
"templates/",
|
|
17
|
+
"README.md",
|
|
18
|
+
"LICENSE"
|
|
19
|
+
],
|
|
20
|
+
"keywords": [
|
|
21
|
+
"security",
|
|
22
|
+
"pentest",
|
|
23
|
+
"red-team",
|
|
24
|
+
"nmap",
|
|
25
|
+
"bolt"
|
|
26
|
+
],
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "git+https://github.com/WarrenMu/Beera-Cyber-new-.git",
|
|
30
|
+
"directory": "cli"
|
|
31
|
+
},
|
|
32
|
+
"homepage": "https://github.com/WarrenMu/Beera-Cyber-new-#readme",
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"access": "public"
|
|
35
|
+
}
|
|
36
|
+
}
|