@bolt-cli/cli 0.15.6 → 0.15.8
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 +30 -3
- package/lib/agent.js +98 -65
- package/lib/cli.js +94 -17
- package/lib/present.js +1 -1
- package/lib/session.js +30 -2
- package/lib/toolparse.js +1 -1
- package/lib/tools.js +23 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -84,6 +84,32 @@ bolt run "get admin endpoints on subdomains of tesla.com" --target tesla.com --t
|
|
|
84
84
|
|
|
85
85
|
`bolt build` saves `*.nse`, `*.py`, `*.sh`, etc. into `--out` (default `./bolt-out`) so you can run them from your own Kali/WSL. Bolt does read-only checks server-side; it writes scripts, you execute them.
|
|
86
86
|
|
|
87
|
+
## Build a real project in a folder
|
|
88
|
+
|
|
89
|
+
Open a VS Code integrated terminal (`Ctrl+``) in the directory where you want the project to live, then:
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
bolt project "a small Flask API with /health and tests" --dir flask-api
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Bolt builds **on disk**, not in chat:
|
|
96
|
+
|
|
97
|
+
1. Creates the project folder (and nested folders like `src/`, `tests/`) with the `mkdir` tool.
|
|
98
|
+
2. Writes every source, config and README file with `write` (paths like `flask-api/src/index.js`).
|
|
99
|
+
3. Installs dependencies and runs the project with `bash`, using `workdir` to stay inside the folder.
|
|
100
|
+
4. Uses `list`/`glob` to prove the files exist and `bash` to capture the real run output.
|
|
101
|
+
5. If a run fails, reads the error, fixes the file with `edit`/`write`, and runs it again.
|
|
102
|
+
|
|
103
|
+
The final answer reports the folder, the files created, the exact run command, and what the run actually printed — a pasted code fence is never treated as a deliverable in this mode.
|
|
104
|
+
|
|
105
|
+
- `--dir <folder>` (or `-d`) scopes every file to that folder inside the directory you launched `bolt` from. `../` escapes and absolute paths outside the project directory are refused before any tokens are spent.
|
|
106
|
+
- Omit `--dir` and Bolt picks a short descriptive folder name itself.
|
|
107
|
+
- Works from a plain terminal or the VS Code integrated terminal. No extension needed.
|
|
108
|
+
- On Windows, shell steps run through WSL when available, so Linux tooling (pip, nvm, cmake, …) works as expected.
|
|
109
|
+
- Every folder, file and command asks for approval unless you pass `--allow-all` or approve for the session. Every `write`/`edit` is backed up (`bolt undo <path>` restores).
|
|
110
|
+
|
|
111
|
+
In interactive mode, arm it with `/project <describe>` (or `/agent project` then your description) and the same build-on-disk flow runs in the REPL.
|
|
112
|
+
|
|
87
113
|
## Health, completions, export, undo
|
|
88
114
|
|
|
89
115
|
```bash
|
|
@@ -106,7 +132,7 @@ Colors and glyphs follow your terminal: full color on a TTY, plain text on pipes
|
|
|
106
132
|
bolt
|
|
107
133
|
```
|
|
108
134
|
|
|
109
|
-
Bare `bolt` opens an interactive agent on the Bolt backend only — no providers, no model picker. It reads, lists, and searches your project freely, and asks before editing files or running shell commands. Type `/` then Enter to browse commands: arrow keys pick where the terminal supports them, otherwise every row has a number — type it to run, `/text` to narrow, anything else to cancel. Tab completes, and `@path` attaches a file inline (Tab completes paths). `/agents` lists task agents, `/agent <name>` arms one for the next prompt, `/init` explores the project and writes `BOLT.md`, `/resume` picks a saved session back up, `/sessions` lists them in a picker with ages, `/retry` re-runs the last prompt, `/export` saves the session (`md|json|sarif`), `/undo <path>` restores a file, `/doctor` runs pre-flight checks, `/tools` toggles local tools, `/allow-all` skips every approval, `/permissions` manages always-allowed tools, `/status` shows the session dashboard, `?` (or `/keys`) shows the keyboard cheat sheet, and `/help <cmd>` explains one command. Also: `/help`, `/models`, `/mode`, `/target`, `/file`, `/clear`, `/session`, `/copy`, `/balance`, `/exit`.
|
|
135
|
+
Bare `bolt` opens an interactive agent on the Bolt backend only — no providers, no model picker. It reads, lists, and searches your project freely, and asks before editing files or running shell commands. Type `/` then Enter to browse commands: arrow keys pick where the terminal supports them, otherwise every row has a number — type it to run, `/text` to narrow, anything else to cancel. Tab completes, and `@path` attaches a file inline (Tab completes paths). `/agents` lists task agents, `/agent <name>` arms one for the next prompt, `/project <describe>` creates folders, writes files and runs the project in the current directory, `/init` explores the project and writes `BOLT.md`, `/resume` picks a saved session back up, `/sessions` lists them in a picker with ages, `/retry` re-runs the last prompt, `/export` saves the session (`md|json|sarif`), `/undo <path>` restores a file, `/doctor` runs pre-flight checks, `/tools` toggles local tools, `/allow-all` skips every approval, `/permissions` manages always-allowed tools, `/status` shows the session dashboard, `?` (or `/keys`) shows the keyboard cheat sheet, and `/help <cmd>` explains one command. Also: `/help`, `/models`, `/mode`, `/target`, `/file`, `/clear`, `/session`, `/copy`, `/balance`, `/exit`.
|
|
110
136
|
|
|
111
137
|
Prompt history persists across restarts at `~/.bolt/history` (a leading space keeps a line out of the file — handy for pasted secrets). End a line with `\` to continue a long task on the next line. Answers render as terminal markdown (headings, bold, code, quotes, lists), and every tool call reports its elapsed time. When the model needs you to decide, it opens a dropdown; the last row is always "Type a custom answer…" so free text stays possible.
|
|
112
138
|
|
|
@@ -124,11 +150,12 @@ The agent loop works like Claude Code: the model requests local tools, the termi
|
|
|
124
150
|
| `list` | list a directory | never asked |
|
|
125
151
|
| `glob` | find files (`src/**/*.ts`) | never asked |
|
|
126
152
|
| `grep` | search contents (regex) | never asked |
|
|
127
|
-
| `
|
|
153
|
+
| `mkdir` | create a folder (and parents) | asked (once or for the session) |
|
|
154
|
+
| `write` | create/overwrite a file (parents created automatically) | asked (once or for the session) |
|
|
128
155
|
| `edit` | exact-match replacement | asked (once or for the session) |
|
|
129
156
|
| `bash` | shell command (120s cap) | asked, unless read-only (`git status`, `ls`, …) |
|
|
130
157
|
|
|
131
|
-
Two hard rules, no overrides: writes, edits and the shell stay inside the directory you started `bolt` in (`../` escapes refused), and destructive commands (`mkfs`, `dd` to devices, fork bombs, shutdown, `chmod -R 777 /`, …) are refused outright. Raw tool JSON never litters the transcript — calls render as status lines. Without a TTY (`-p`, pipes) mutations are denied unless you pass `--allow-all`, which approves everything without asking.
|
|
158
|
+
Two hard rules, no overrides: `mkdir`, writes, edits and the shell stay inside the directory you started `bolt` in (`../` escapes refused), and destructive commands (`mkfs`, `dd` to devices, fork bombs, shutdown, `chmod -R 777 /`, …) are refused outright. Raw tool JSON never litters the transcript — calls render as status lines. Without a TTY (`-p`, pipes) mutations are denied unless you pass `--allow-all`, which approves everything without asking.
|
|
132
159
|
|
|
133
160
|
Secrets never leave the machine by accident: likely secrets (AWS keys, GitHub/Slack tokens, private keys, `password = "…"` assignments in configs) are scrubbed from prompts and tool results before sending — the terminal tells you how many it redacted, and the model is told not to ask for them back.
|
|
134
161
|
|
package/lib/agent.js
CHANGED
|
@@ -14,7 +14,11 @@ const toolparse = require("./toolparse");
|
|
|
14
14
|
const redact = require("./redact");
|
|
15
15
|
const usage = require("./usage");
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
// Each iteration is a separately billed run (the relay is stateless, so the
|
|
18
|
+
// whole prompt is re-sent every turn). Eight keeps a normal run affordable;
|
|
19
|
+
// the help text and README have always promised eight, and --max-iters raises
|
|
20
|
+
// it to 32 for builds that genuinely need more.
|
|
21
|
+
const DEFAULT_MAX_ITERS = 8;
|
|
18
22
|
const MAX_RESULT_CHARS = 4_000;
|
|
19
23
|
|
|
20
24
|
// The tool protocol body. Sent wrapped in <terminal-capabilities> sentinels
|
|
@@ -23,57 +27,32 @@ const MAX_RESULT_CHARS = 4_000;
|
|
|
23
27
|
// so the model stops ruling its own tool channel out as injected
|
|
24
28
|
// instructions. Old backends ignore the sentinels and read the body as
|
|
25
29
|
// before; old CLIs send no sentinels and get today's behavior.
|
|
26
|
-
const TOOL_PROTOCOL_BODY = `Local tools are available in this terminal session.
|
|
27
|
-
|
|
28
|
-
\`\`\`tool
|
|
29
|
-
{"tool": "read", "path": "src/app.ts", "limit": 80}
|
|
30
|
-
\`\`\`
|
|
31
|
-
|
|
32
|
-
These local tools ARE your file and shell access for
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
sentence that the task is complete.
|
|
53
|
-
|
|
54
|
-
Tools:
|
|
55
|
-
- read {path, offset?, limit?} - read a file (free, always allowed)
|
|
56
|
-
- list {path?} - list a directory (free, always allowed)
|
|
57
|
-
- glob {pattern} - find files, e.g. {"tool": "glob", "pattern": "src/**/*.ts"}
|
|
58
|
-
- grep {pattern, path?} - search file contents (regex, case-insensitive)
|
|
59
|
-
- write {path, content} - create or overwrite a file (terminal asks first, backed up for undo)
|
|
60
|
-
- edit {path, oldString, newString} - exact unique replacement (terminal asks first, backed up for undo)
|
|
61
|
-
- bash {command, workdir?} - run a shell command: recon, installs, builds, scanners, sudo-privileged commands (terminal asks first; destructive commands are refused outright)
|
|
62
|
-
- ask {question, options[]} - ask the operator to choose (2-6 options). Use when scope, target or strategy is ambiguous instead of guessing.
|
|
63
|
-
|
|
64
|
-
When you need the operator to decide, emit e.g.:
|
|
65
|
-
\`\`\`tool
|
|
66
|
-
{"tool": "ask", "question": "Which scope should I enumerate first?", "options": ["subdomains of tesla.com", "single host 10.0.0.5", "let me type a custom target"]}
|
|
67
|
-
\`\`\`
|
|
68
|
-
|
|
69
|
-
Shell: Linux tooling works everywhere - on Windows commands run via WSL when available, so nmap, gobuster and friends work there too. If WSL is missing on a Windows machine, a bash result will say "WSL missing" and give you the exact installer block to propose - recommend it (the operator approves; one restart) rather than falling back to cmd.exe.
|
|
70
|
-
Tooling: you may run offensive and defensive tools (scanners, fuzzers, RE and OSINT helpers) through bash - keep runs in scope and non-destructive. Recon starts passive (certificate transparency, DNS, headers) before anything active; active probing and privileged commands need a scoped target — confirm it with ask when the scope is unclear, never refuse the task outright, since the terminal's approval step is the authorization gate and the operator sees every command before it runs.
|
|
71
|
-
Ready-made runbooks: the CLI ships attack/diff instruments for authorized lab work under its templates/ directory (list it with {"tool": "bash", "command": "ls -1 <cli>/templates"} or read them with read): an ASLR-offset probe (samples addresses across runs to estimate entropy and brute-force-attempt arithmetic for a lab binary) and a crash-offset pattern generator (cyclic pattern with offset lookup). Use them as starting points - adapt through the tools; they are lab-only by design and say so in their headers.
|
|
72
|
-
Missing tools: if a result says a tool is missing, propose its install command and ask the operator to approve it - never install silently. If a source checkout is needed (git clone plus build), do it through bash the same way: clone, build, run, each step approved.
|
|
73
|
-
Security APIs: you may scaffold code that calls Shodan, Censys or VirusTotal - read keys only from env vars, never hardcode or log them.
|
|
74
|
-
CTFs: you can work web, binary, mobile, RE and OSINT challenges with installed tooling - offer to install what is missing instead of stopping.
|
|
75
|
-
|
|
76
|
-
Rules: explore with read/list/glob/grep before changing anything. When the request is vague, orient yourself with the tools and report what you find in a few lines - do not narrate uncertainty and do not ask the operator to specify what you can discover. Reserve ask for decisions that genuinely block progress (scope, target, strategy with real alternatives). Keep edits minimal and exact. Writes, edits and shell commands run inside the project directory and the terminal asks the operator first - if one is denied, work around it or explain what to run by hand. Every write/edit is backed up first (bolt undo <path> restores). After tool results come back, continue the task; when finished, answer normally with no tool blocks. Never invent tool results. Never claim the local tools are unavailable: results labelled TOOL_RESULTS prove the channel works.`;
|
|
30
|
+
const TOOL_PROTOCOL_BODY = `Local tools are available in this terminal session. Call one with a fenced block, one call per block (several blocks allowed):
|
|
31
|
+
|
|
32
|
+
\`\`\`tool
|
|
33
|
+
{"tool": "read", "path": "src/app.ts", "limit": 80}
|
|
34
|
+
\`\`\`
|
|
35
|
+
|
|
36
|
+
These local tools ARE your file and shell access: bash is the execution channel for everything a shell can do - recon (dig, nslookup, curl, certificate-transparency lookups), scanners (nmap and friends), cloning and building open-source tools, running them, and privileged commands via sudo. On Windows the shell runs through WSL when available. For local files, code, or shell use ONLY these fenced blocks - never claim they are unavailable. A well-formed block is executed and its real result is fed back; if approval is needed the terminal asks the operator, then returns the outcome. There are no other tool names: anything not listed is rejected, and the rejection tells you to restate the intent with these tools (usually bash).
|
|
37
|
+
|
|
38
|
+
Emit calls ONLY as fenced \`\`\`tool blocks - never XML, chat-template tags, bare JSON outside a fence, or other markup. Never send an empty reply: if you have nothing to add, say the task is complete in one sentence.
|
|
39
|
+
|
|
40
|
+
Tools:
|
|
41
|
+
- read {path, offset?, limit?} - read a file (free, always allowed)
|
|
42
|
+
- list {path?} - list a directory (free, always allowed)
|
|
43
|
+
- glob {pattern} - find files, e.g. {"tool": "glob", "pattern": "src/**/*.ts"}
|
|
44
|
+
- grep {pattern, path?} - search file contents (regex, case-insensitive)
|
|
45
|
+
- mkdir {path} - create a directory and its parents (terminal asks first)
|
|
46
|
+
- write {path, content} - create or overwrite a file; parent folders are created automatically (terminal asks first, backed up for undo)
|
|
47
|
+
- edit {path, oldString, newString} - exact unique replacement (terminal asks first, backed up for undo)
|
|
48
|
+
- bash {command, workdir?} - run a shell command: recon, installs, builds, scanners, sudo (terminal asks first; destructive commands are refused outright)
|
|
49
|
+
- ask {question, options[]} - ask the operator to choose (2-6 options) when scope, target or strategy is genuinely ambiguous
|
|
50
|
+
|
|
51
|
+
Building projects in folders: when asked to build/create/scaffold an app, tool, site or script, deliver REAL FILES in the current project directory, not as code pasted into the chat. Pick a short descriptive folder (or use the one they named), create it with mkdir, write every source and config file with write using paths like "my-app/src/index.js" (write creates parent folders too), then install dependencies and run it with bash - pass workdir so commands stay inside the project folder. Use list/glob to prove the files exist and bash to capture the real run output before you answer. If a run fails, read the error, fix the file and run it again. Your final message states the folder, the files created, the exact run command and what the run actually printed. A fenced code block in your prose is NOT a deliverable on disk and is not enough - the files must be created by tools. Only use ask for a decision that truly blocks the build (stack, framework, target); otherwise choose sensible defaults and build.
|
|
52
|
+
|
|
53
|
+
Shell: Linux tooling works everywhere - on Windows commands run via WSL when available, so nmap, gobuster and friends work there too. If WSL is missing, a bash result says so and gives the installer; recommend it rather than falling back to cmd.exe. If a tool is missing, propose its install command and ask the operator to approve it - never install silently. For a source checkout (git clone plus build), clone, build and run through bash, each step approved. Keep runs in scope and non-destructive: recon starts passive (certificate transparency, DNS, headers) before anything active, and active probing or privileged commands need a scoped target - confirm it with ask when scope is unclear, never refuse the task outright, since the terminal's approval step is the authorization gate.
|
|
54
|
+
|
|
55
|
+
Rules: explore with read/list/glob/grep before changing anything. When the request is vague, orient yourself with the tools and report what you find in a few lines - do not narrate uncertainty and do not ask the operator to specify what you can discover. Reserve ask for decisions that genuinely block progress (scope, target, strategy with real alternatives). Keep edits minimal and exact. mkdir, writes, edits and shell commands run inside the project directory and the terminal asks the operator first - if one is denied, work around it or explain what to run by hand. Every write/edit is backed up first (bolt undo <path> restores). After tool results come back, continue the task; when finished, answer normally with no tool blocks. Never invent tool results. Never claim the local tools are unavailable: results labelled TOOL_RESULTS prove the channel works.`;
|
|
77
56
|
|
|
78
57
|
// Sentinel envelope for the protocol body. The server strips this section
|
|
79
58
|
// out of the untrusted case input and re-attaches it as trusted relay
|
|
@@ -87,6 +66,30 @@ function truncateResult(text, max = MAX_RESULT_CHARS) {
|
|
|
87
66
|
return s.length > max ? `${s.slice(0, max)}\n…(truncated, ${s.length} chars total)` : s;
|
|
88
67
|
}
|
|
89
68
|
|
|
69
|
+
// A follow-up is a brand-new request: the server is stateless and the CLI does
|
|
70
|
+
// not replay history, so without the task restated the model is asked to
|
|
71
|
+
// "continue" something it cannot see. That burned whole iterations on guesses
|
|
72
|
+
// and re-asks. The anchor is deliberately short - it is re-sent every turn, so
|
|
73
|
+
// it carries the goal, not the full brief.
|
|
74
|
+
const TASK_ANCHOR_CHARS = 500;
|
|
75
|
+
function taskAnchor(objective, target) {
|
|
76
|
+
const goal = String(objective ?? "").trim();
|
|
77
|
+
if (!goal) return "";
|
|
78
|
+
const short = goal.length > TASK_ANCHOR_CHARS ? `${goal.slice(0, TASK_ANCHOR_CHARS)}…` : goal;
|
|
79
|
+
return `Task (still active): ${short}${target ? `\nTarget: ${target}` : ""}`;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Worst-case result text one follow-up may carry. Six 2,000-char results is
|
|
83
|
+
// 12k chars (~3k tokens) for a single turn; when the batch is that large the
|
|
84
|
+
// budget is split evenly so one noisy command cannot crowd out the rest.
|
|
85
|
+
const MAX_FOLLOWUP_DETAIL_CHARS = 6_000;
|
|
86
|
+
function clampDetail(text, max) {
|
|
87
|
+
const s = String(text ?? "");
|
|
88
|
+
if (s.length <= max) return s;
|
|
89
|
+
const head = Math.max(200, max - 300);
|
|
90
|
+
return `${s.slice(0, head)}\n…[middle elided to fit this turn's context budget, ${s.length - max} chars]…\n${s.slice(-300)}`;
|
|
91
|
+
}
|
|
92
|
+
|
|
90
93
|
// Token efficiency for multi-iteration runs, two rules that always hold:
|
|
91
94
|
//
|
|
92
95
|
// 1. Big results are summed, not truncated cold: keep the head (where most
|
|
@@ -112,7 +115,7 @@ function summarizeDetail(detail, seenDetails = null) {
|
|
|
112
115
|
}
|
|
113
116
|
|
|
114
117
|
// The reply-discipline line sits at the VERY END of the first prompt, after
|
|
115
|
-
// the
|
|
118
|
+
// the tool protocol. Every saved session showed the same failure: turn 1
|
|
116
119
|
// returned zero tokens, then the empty-reply nudge (also at the end) made the
|
|
117
120
|
// model work immediately. The relay runs a reasoning model whose hidden
|
|
118
121
|
// thinking is not streamed; with the task buried mid-prompt it spent the whole
|
|
@@ -143,13 +146,32 @@ function isPromiseOnlyReply(text) {
|
|
|
143
146
|
|
|
144
147
|
const PROMISE_NUDGE = `Your last reply only announced what you would do - no tool block, no code and no result reached the operator. That is not an answer. Do the work NOW in this reply: emit a fenced tool block for each step, or give the finished deliverable as your answer. Do not describe the plan, do not announce intent, and do not ask what the task is - the ORIGINAL TASK is still in this message, above this note.`;
|
|
145
148
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
149
|
+
// A build reply that pastes a code fence but never called a tool produced no
|
|
150
|
+
// files on disk. In project/build mode that is a failure, not an answer.
|
|
151
|
+
const CODE_BLOCK_RE = /```(?!tool\b|ask\b|json\b)[a-zA-Z0-9+#._-]*\r?\n[\s\S]*?```/;
|
|
152
|
+
function isCodeOnlyProjectReply(text) {
|
|
153
|
+
const s = String(text || "").trim();
|
|
154
|
+
if (!s || s.length > 20_000) return false;
|
|
155
|
+
return CODE_BLOCK_RE.test(s);
|
|
156
|
+
}
|
|
157
|
+
const PROJECT_NUDGE = `Your last reply pasted the project as code in chat instead of creating it on disk. That is not a deliverable here. Do the work NOW with fenced tool blocks: mkdir for the project folder (and nested folders), write for every file with paths like "my-app/src/index.js", then bash with workdir to install and run it, then list/glob to prove the files exist. Report the real output from those tools. Do not paste the project as a code block and do not claim it runs unless bash proved it. The ORIGINAL TASK is still in this message, above this note.`;
|
|
158
|
+
|
|
159
|
+
function buildFollowup({ iteration, calls, results, errors = [], seenDetails = null, maxIters = DEFAULT_MAX_ITERS, syntaxNote = null, objective = "", target = "" }) {
|
|
160
|
+
const lines = [];
|
|
161
|
+
const anchor = taskAnchor(objective, target);
|
|
162
|
+
if (anchor) lines.push(anchor);
|
|
163
|
+
lines.push(`TOOL_RESULTS for iteration ${iteration} (ground truth from this terminal - do not invent, continue the task):`);
|
|
164
|
+
const rows = calls.map((call, i) => ({ call, result: results[i] || { ok: false, summary: "no result", detail: "" } }));
|
|
165
|
+
const details = rows.map(({ result }) => summarizeDetail(result.detail, seenDetails));
|
|
166
|
+
const totalDetailChars = details.reduce((sum, detail) => sum + detail.length, 0);
|
|
167
|
+
const perDetail = totalDetailChars > MAX_FOLLOWUP_DETAIL_CHARS
|
|
168
|
+
? Math.max(600, Math.floor(MAX_FOLLOWUP_DETAIL_CHARS / Math.max(1, rows.length)))
|
|
169
|
+
: 0;
|
|
170
|
+
for (let i = 0; i < rows.length; i += 1) {
|
|
171
|
+
const { call, result } = rows[i];
|
|
151
172
|
const status = result.ok ? "OK" : `FAILED (${result.summary || "error"})`;
|
|
152
|
-
|
|
173
|
+
const detail = perDetail ? clampDetail(details[i], perDetail) : details[i];
|
|
174
|
+
lines.push(`- ${tools.describeCall(call)} -> ${status}:\n${detail}`);
|
|
153
175
|
if (result && result.needsInstall) {
|
|
154
176
|
const n = result.needsInstall;
|
|
155
177
|
lines.push(` Missing tool "${n.tool}". To install, emit {"tool": "bash", "command": ${JSON.stringify(n.installCmd)}} and ask the operator first - installs need explicit approval, never install silently.`);
|
|
@@ -158,12 +180,12 @@ function buildFollowup({ iteration, calls, results, errors = [], seenDetails = n
|
|
|
158
180
|
// Rejected blocks are fed back, not swallowed: without this the model
|
|
159
181
|
// repeats unknown tool names, concludes the channel is broken, and refuses
|
|
160
182
|
// work the terminal could have done. Every rejection restates the fix —
|
|
161
|
-
// translate the intent into the
|
|
183
|
+
// translate the intent into the nine tools above (recon via bash).
|
|
162
184
|
for (const error of errors) {
|
|
163
185
|
lines.push(`- BLOCK REJECTED (${error.error || "bad block"}): ${truncateResult(error.raw || "", 200)}`);
|
|
164
186
|
}
|
|
165
187
|
if (errors.length) {
|
|
166
|
-
lines.push("Those blocks named tools that do not exist here. Restate each intent with the
|
|
188
|
+
lines.push("Those blocks named tools that do not exist here. Restate each intent with the nine 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.");
|
|
167
189
|
}
|
|
168
190
|
// When calls arrived in drifted syntax (XML/JSON), say so once: the calls
|
|
169
191
|
// were still parsed and executed, and the model is coached back to the
|
|
@@ -172,9 +194,12 @@ function buildFollowup({ iteration, calls, results, errors = [], seenDetails = n
|
|
|
172
194
|
lines.push(iteration >= maxIters - 1
|
|
173
195
|
? "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."
|
|
174
196
|
: "Continue with the next step, using more tools if needed, or give the final answer with no tool blocks.");
|
|
197
|
+
// Tool-call turns are billed output too. A preamble before the fenced block
|
|
198
|
+
// ("Let me check...") buys nothing and is hidden from the operator anyway.
|
|
199
|
+
lines.push("When you call a tool, emit only the fenced block(s) - no preamble, plan or narration.");
|
|
175
200
|
// Restated every turn on purpose: without it the model reverts to refusing
|
|
176
201
|
// local work it already performed. These results prove the channel works.
|
|
177
|
-
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.");
|
|
202
|
+
lines.push("Local terminal tools (read, list, glob, grep, mkdir, write, edit, bash, ask via ```tool blocks) remain available this turn - folders, files, shell, recon, installs, and privileged commands through bash, with operator approval where needed. Never claim the local tools are unavailable.");
|
|
178
203
|
return lines.join("\n");
|
|
179
204
|
}
|
|
180
205
|
|
|
@@ -200,7 +225,7 @@ function scrubOutbound(prompt) {
|
|
|
200
225
|
* (Esc/Ctrl-C via lib/cancel.js). Resolves {text, done, iters, toolCalls,
|
|
201
226
|
* cancelled}.
|
|
202
227
|
*/
|
|
203
|
-
async function runAgentLoop({ cfg, objective, mode, target, evidence, sess, stream, events, policy, maxIters = DEFAULT_MAX_ITERS, memory = "", signal, session: sessionId, account }) {
|
|
228
|
+
async function runAgentLoop({ cfg, objective, mode, target, evidence, sess, stream, events, policy, maxIters = DEFAULT_MAX_ITERS, projectMode = false, memory = "", signal, session: sessionId, account }) {
|
|
204
229
|
const emit = (event) => {
|
|
205
230
|
try {
|
|
206
231
|
if (typeof events === "function") events(event);
|
|
@@ -225,6 +250,7 @@ async function runAgentLoop({ cfg, objective, mode, target, evidence, sess, stre
|
|
|
225
250
|
let iters = 0;
|
|
226
251
|
let nudged = false; // one silent-reply recovery per run
|
|
227
252
|
let promiseNudged = false; // one promise-only recovery per run
|
|
253
|
+
let projectNudged = false; // one code-instead-of-files recovery per run
|
|
228
254
|
let cancelled = false;
|
|
229
255
|
const toolCalls = [];
|
|
230
256
|
// Byte-identical tool results across the run collapse to a pointer line
|
|
@@ -374,6 +400,12 @@ async function runAgentLoop({ cfg, objective, mode, target, evidence, sess, stre
|
|
|
374
400
|
prompt = `${basePrompt}\n\n${PROMISE_NUDGE}`;
|
|
375
401
|
continue;
|
|
376
402
|
}
|
|
403
|
+
if (projectMode && isCodeOnlyProjectReply(visible) && !projectNudged && iters < maxIters) {
|
|
404
|
+
projectNudged = true;
|
|
405
|
+
emit({ type: "retry", reason: "code-only", message: "reply pasted code instead of writing files - creating the project on disk" });
|
|
406
|
+
prompt = `${basePrompt}\n\n${PROJECT_NUDGE}`;
|
|
407
|
+
continue;
|
|
408
|
+
}
|
|
377
409
|
break; // normal final answer
|
|
378
410
|
}
|
|
379
411
|
// Empty reply — the classic "replied with nothing" failure. Nudge
|
|
@@ -388,6 +420,7 @@ async function runAgentLoop({ cfg, objective, mode, target, evidence, sess, stre
|
|
|
388
420
|
}
|
|
389
421
|
nudged = false;
|
|
390
422
|
promiseNudged = false;
|
|
423
|
+
projectNudged = false;
|
|
391
424
|
|
|
392
425
|
if (signal && signal.aborted) {
|
|
393
426
|
cancelled = true;
|
|
@@ -396,7 +429,7 @@ async function runAgentLoop({ cfg, objective, mode, target, evidence, sess, stre
|
|
|
396
429
|
const syntaxNote = usedNonFence
|
|
397
430
|
? "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."
|
|
398
431
|
: null;
|
|
399
|
-
prompt = scrub(buildFollowup({ iteration: iters, calls, results, errors, seenDetails, maxIters, syntaxNote }));
|
|
432
|
+
prompt = scrub(buildFollowup({ iteration: iters, calls, results, errors, seenDetails, maxIters, syntaxNote, objective, target }));
|
|
400
433
|
}
|
|
401
434
|
return { text, done, iters, toolCalls, cancelled };
|
|
402
435
|
}
|
|
@@ -413,4 +446,4 @@ function toolFenceWriter(write) {
|
|
|
413
446
|
return toolparse.createMarkupFilter(write);
|
|
414
447
|
}
|
|
415
448
|
|
|
416
|
-
module.exports = { TOOL_PROTOCOL, TOOL_PROTOCOL_BODY, TERMINAL_BEGIN, TERMINAL_END, OUTPUT_DIRECTIVE, isPromiseOnlyReply, DEFAULT_MAX_ITERS, buildAgentPrompt, buildFollowup, runAgentLoop, truncateResult, summarizeDetail, toolFenceWriter, scrubOutbound };
|
|
449
|
+
module.exports = { TOOL_PROTOCOL, TOOL_PROTOCOL_BODY, TERMINAL_BEGIN, TERMINAL_END, OUTPUT_DIRECTIVE, isPromiseOnlyReply, isCodeOnlyProjectReply, DEFAULT_MAX_ITERS, buildAgentPrompt, buildFollowup, runAgentLoop, truncateResult, summarizeDetail, toolFenceWriter, scrubOutbound };
|
package/lib/cli.js
CHANGED
|
@@ -33,8 +33,9 @@ const VERSION = require(path.join(__dirname, "..", "package.json")).version;
|
|
|
33
33
|
function help(topic) {
|
|
34
34
|
if (topic) {
|
|
35
35
|
const t = String(topic).toLowerCase();
|
|
36
|
-
if (t === "run") return `bolt run "<prompt>" [options] — single autonomous run\n\n --target, -t <domain> in-scope target\n --mode, -m <mode> offensive (default) | defensive\n --agent <name> sweep|probe|build|plan|validate|triage\n --tools agent loop (read, list,
|
|
36
|
+
if (t === "run") return `bolt run "<prompt>" [options] — single autonomous run\n\n --target, -t <domain> in-scope target\n --mode, -m <mode> offensive (default) | defensive\n --agent <name> sweep|probe|build|project|plan|validate|triage\n --dir, -d <folder> folder to build the project in (with --agent project)\n --tools agent loop (read, list, mkdir, write, edit, shell)\n --max-iters <n> cap iterations (default 8, max 32)\n --format <fmt> text (default) | json | md\n --output <file> write the final answer to a file\n --budget <tokens> refuse to send when estimated input exceeds N tokens\n -p, --print print mode: final answer only\n -f, --file <path> attach file as evidence (repeatable)\n -s, --session <id> continue a session\n -c, --continue continue the most recent session\n --title <text> title for a new session\n --dry-run preview tokens/files/memory, spend nothing\n --allow-all approve every tool call (dangerous)\n\nExamples:\n bolt run "get admin endpoints" --target tesla.com --format json --output out.json\n bolt run "triage alert" --mode defensive -f alert.json --budget 8000\n`;
|
|
37
37
|
if (t === "build") return `bolt build "<what>" --target <domain> [--out ./bolt-out] [--format json] [--output report.md]\n\nBuild mode runs the agent loop and extracts fenced code blocks to disk.\nEvery write/edit is backed up first — bolt undo <path> restores.\n`;
|
|
38
|
+
if (t === "project") return `bolt project "<what to build>" [--dir <folder>] [--target <domain>] [--max-iters <n>]\n\nBuilds a real project in a folder under the directory you launched bolt from.\nThe agent creates folders (mkdir), writes every file (write), installs and runs\nthe project (bash), then reports the folder, files, run command and real output.\nNothing is pasted as code and left for you to assemble. Writes are backed up\n(bolt undo <path> restores); every folder/file and command asks first unless\nyou pass --allow-all or approve for the session. On Windows, shell steps run\nthrough WSL when available.\n\nExample:\n cd C:\\work\\my-projects\n bolt project "a small Flask API with /health and tests" --dir flask-api\n`;
|
|
38
39
|
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`;
|
|
39
40
|
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`;
|
|
40
41
|
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`;
|
|
@@ -55,6 +56,7 @@ Usage:
|
|
|
55
56
|
bolt auth status | logout session info, sign out this machine
|
|
56
57
|
bolt run "<prompt>" [options] single autonomous run
|
|
57
58
|
bolt build "<what>" --target <domain> [--out ./bolt-out]
|
|
59
|
+
bolt project "<what>" [--dir <folder>] scaffold a runnable project in a folder, then run it
|
|
58
60
|
bolt -p "<prompt>" print mode: agent loop, final answer only
|
|
59
61
|
bolt session [list|show|delete|new]
|
|
60
62
|
bolt export <id> [--format md|json|sarif] [--output file]
|
|
@@ -65,7 +67,7 @@ Usage:
|
|
|
65
67
|
bolt update upgrade the CLI via npm (notice appears when a release ships)
|
|
66
68
|
bolt completion <shell> shell completions (bash|zsh|fish|powershell)
|
|
67
69
|
bolt balance tokens, runs, spend
|
|
68
|
-
bolt help <command> per-command help (run|build|session|export|doctor|completion|undo|watch|templates|update)
|
|
70
|
+
bolt help <command> per-command help (run|build|project|session|export|doctor|completion|undo|watch|templates|update)
|
|
69
71
|
|
|
70
72
|
Press Esc during any run to stop it (the session is saved). Out of tokens
|
|
71
73
|
stops the run at once with the top-up link — it never spins forever.
|
|
@@ -77,8 +79,9 @@ Sign-in options:
|
|
|
77
79
|
Run options:
|
|
78
80
|
--target, -t <domain> in-scope target
|
|
79
81
|
--mode, -m <mode> offensive (default) | defensive
|
|
80
|
-
--agent <name> arm an agent (sweep|probe|build|plan|validate|triage)
|
|
81
|
-
--
|
|
82
|
+
--agent <name> arm an agent (sweep|probe|build|project|plan|validate|triage)
|
|
83
|
+
--dir, -d <folder> folder to create files in (with --agent project)
|
|
84
|
+
--tools agent loop: read, list, mkdir, write, edit, shell
|
|
82
85
|
(interactive shows Allow / Always allow / Deny;
|
|
83
86
|
elevated commands get a shield card; piped runs deny)
|
|
84
87
|
--dry-run show what would be sent (tokens, files, memory)
|
|
@@ -106,6 +109,7 @@ Examples:
|
|
|
106
109
|
bolt run "get admin endpoints" --target tesla.com --format json --output out.json
|
|
107
110
|
bolt -p "what does this repo do?" --allow-all
|
|
108
111
|
bolt build "nmap NSE script to detect exposed admin logins" --target tesla.com
|
|
112
|
+
bolt project "a small Flask API with /health and tests" --dir flask-api
|
|
109
113
|
bolt export <session-id> --format sarif --output findings.sarif
|
|
110
114
|
bolt completion bash >> ~/.bashrc
|
|
111
115
|
bolt undo src/auth.ts
|
|
@@ -675,7 +679,7 @@ function stripBoltPrefix(input) {
|
|
|
675
679
|
}
|
|
676
680
|
|
|
677
681
|
function positionalPrompt(rest) {
|
|
678
|
-
const skipValues = new Set(["--target", "-t", "--mode", "-m", "--agent", "--file", "-f", "--evidence", "--session", "-s", "--title", "--out", "-o", "--max-iters", "--format", "--output", "--budget", "--url"]);
|
|
682
|
+
const skipValues = new Set(["--target", "-t", "--mode", "-m", "--agent", "--file", "-f", "--evidence", "--session", "-s", "--title", "--out", "-o", "--dir", "-d", "--max-iters", "--format", "--output", "--budget", "--url"]);
|
|
679
683
|
return rest
|
|
680
684
|
.filter((a, i) => !a.startsWith("-") && !skipValues.has(rest[i - 1]))
|
|
681
685
|
.join(" ")
|
|
@@ -700,6 +704,11 @@ const AGENTS = {
|
|
|
700
704
|
needsTarget: true,
|
|
701
705
|
make: (t, o) => `Build a complete runnable tool for ${t || "the target below"}: ${o || "an nmap NSE script to detect exposed admin login pages"}. Provide the full file(s), exact run commands, safe validation, expected output, cleanup, and stop conditions.`,
|
|
702
706
|
},
|
|
707
|
+
project: {
|
|
708
|
+
desc: "create a project folder, write its files, then run and verify it",
|
|
709
|
+
needsTarget: false,
|
|
710
|
+
make: (t, o) => `Build this project as real files on disk, not as code in chat: ${o || "a small runnable project"}. Work under the directory bolt launched in. First create a short descriptive project folder with mkdir (and nested folders such as src/, tests/ where useful), then write every source, config and README file with write using paths like "my-app/src/index.js". Install dependencies and run the project with bash, passing workdir so commands stay inside the project folder. Use list or glob to prove the files exist and bash to capture the real output. If a run fails, read the error, fix the file with edit or write, and run it again. Finish by reporting the folder path, the files created, the exact run command, and what the run actually printed. Do not paste the project as a code block and do not claim it runs unless bash proved it.${t ? `\nTarget or scope: ${t}` : ""}`,
|
|
711
|
+
},
|
|
703
712
|
plan: {
|
|
704
713
|
desc: "authorized test plan with phases and stop conditions",
|
|
705
714
|
needsTarget: false,
|
|
@@ -724,6 +733,17 @@ function applyAgent(name, objective, target) {
|
|
|
724
733
|
return agent.make(target, objective);
|
|
725
734
|
}
|
|
726
735
|
|
|
736
|
+
// Validate the --dir flag against the same sandbox the write/mkdir tools use,
|
|
737
|
+
// then turn it into the note appended to the project agent's objective. Kept
|
|
738
|
+
// pure and exported so validation is testable without auth or a network call.
|
|
739
|
+
function resolveProjectDir(root, dirFlag) {
|
|
740
|
+
if (!dirFlag) return { ok: true, note: "" };
|
|
741
|
+
const checked = tools.resolveInRoot(root, dirFlag);
|
|
742
|
+
if (!checked.ok) return { ok: false, error: `--dir must be a folder inside the current project: ${checked.error}` };
|
|
743
|
+
const clean = String(dirFlag).replace(/\\/g, "/").replace(/^\.\//, "").replace(/\/$/, "");
|
|
744
|
+
return { ok: true, folder: clean, note: `\n\nCreate the project in the folder "${clean}" under the current directory. Put every file inside that folder.` };
|
|
745
|
+
}
|
|
746
|
+
|
|
727
747
|
const COMMANDS = [
|
|
728
748
|
["/help", "commands, grouped (try /help <cmd>)"],
|
|
729
749
|
["/status", "session dashboard: mode, tools, tokens"],
|
|
@@ -732,7 +752,8 @@ const COMMANDS = [
|
|
|
732
752
|
["/keys", "keyboard shortcuts cheat sheet"],
|
|
733
753
|
["/agents", "list task agents"],
|
|
734
754
|
["/agent <name>", "arm an agent for the next prompt"],
|
|
735
|
-
["/
|
|
755
|
+
["/project <describe>", "create folders, write files and run the project"],
|
|
756
|
+
["/tools [on|off]", "local tools: read, list, mkdir, write, edit, shell"],
|
|
736
757
|
["/allow-all", "approve every tool call without asking (dangerous)"],
|
|
737
758
|
["/permissions", "list always-allowed tools (revoke, clear)"],
|
|
738
759
|
["/init", "explore this project and write BOLT.md"],
|
|
@@ -1166,9 +1187,14 @@ function printDryRun(report, { mem, files, agentName, contextLabel }) {
|
|
|
1166
1187
|
console.log(report.preview.length >= 1500 ? `${report.preview}\n …(truncated)` : report.preview);
|
|
1167
1188
|
}
|
|
1168
1189
|
|
|
1169
|
-
async function cmdRun(rest, { buildMode, printMode: forcePrint }) {
|
|
1190
|
+
async function cmdRun(rest, { buildMode, printMode: forcePrint, forceAgent } = {}) {
|
|
1170
1191
|
const dryRun = flag(rest, "--dry-run");
|
|
1171
1192
|
const printMode = Boolean(forcePrint) || flag(rest, "-p", "--print");
|
|
1193
|
+
// --dir is the folder the project agent must build into. Validate it before
|
|
1194
|
+
// auth/network: ../ escapes and absolute paths outside the project directory
|
|
1195
|
+
// are refused before a single token is spent.
|
|
1196
|
+
const dir = resolveProjectDir(process.cwd(), arg(rest, "--dir", "-d"));
|
|
1197
|
+
if (!dir.ok) throw new Error(dir.error);
|
|
1172
1198
|
// Dry runs spend nothing and touch neither the network nor the session
|
|
1173
1199
|
// store, so they need no auth. Everything else authenticates first.
|
|
1174
1200
|
const cfg = dryRun ? null : await ensureAuth();
|
|
@@ -1180,17 +1206,24 @@ async function cmdRun(rest, { buildMode, printMode: forcePrint }) {
|
|
|
1180
1206
|
if (argvWarning) ui.warn(argvWarning);
|
|
1181
1207
|
let objective = argvPrompt;
|
|
1182
1208
|
if (!objective) objective = await readStdin();
|
|
1183
|
-
if (!objective)
|
|
1209
|
+
if (!objective) {
|
|
1210
|
+
if (buildMode) throw new Error('Usage: bolt build "<what to build>" --target <domain> [--out ./bolt-out]');
|
|
1211
|
+
if (forceAgent === "project" || arg(rest, "--agent") === "project") throw new Error('Usage: bolt project "<what to build>" [--dir <folder>]');
|
|
1212
|
+
throw new Error('Usage: bolt run "<prompt>" [--target <domain>]');
|
|
1213
|
+
}
|
|
1184
1214
|
const target = arg(rest, "--target", "-t");
|
|
1185
1215
|
const mode = arg(rest, "--mode", "-m") || "offensive";
|
|
1186
1216
|
if (mode !== "offensive" && mode !== "defensive") throw new Error("--mode must be offensive or defensive");
|
|
1187
|
-
const agentName = arg(rest, "--agent") || (buildMode ? "build" : "");
|
|
1188
|
-
|
|
1217
|
+
const agentName = arg(rest, "--agent") || forceAgent || (buildMode ? "build" : "");
|
|
1218
|
+
const dirNote = dir.note;
|
|
1219
|
+
if (agentName) objective = applyAgent(agentName, objective, target) + dirNote;
|
|
1220
|
+
else objective += dirNote;
|
|
1221
|
+
const projectMode = Boolean(buildMode || agentName === "project");
|
|
1189
1222
|
const mentions = tools.resolveMentions(objective, process.cwd());
|
|
1190
1223
|
const evidence = [readEvidence(rest), mentions.evidence].filter(Boolean).join("\n\n");
|
|
1191
1224
|
const outDir = arg(rest, "--out", "-o") || (buildMode ? "./bolt-out" : "");
|
|
1192
1225
|
const mem = memory.loadMemory(process.cwd());
|
|
1193
|
-
const useTools = printMode || dryRunTools(rest, buildMode) || (buildMode && !flag(rest, "--no-tools"));
|
|
1226
|
+
const useTools = printMode || dryRunTools(rest, buildMode) || agentName === "project" || (buildMode && !flag(rest, "--no-tools"));
|
|
1194
1227
|
const iters = maxIters(rest);
|
|
1195
1228
|
const format = (arg(rest, "--format") || "text").toLowerCase();
|
|
1196
1229
|
if (!["text", "json", "md"].includes(format)) throw new Error('--format must be text | json | md');
|
|
@@ -1271,6 +1304,7 @@ async function cmdRun(rest, { buildMode, printMode: forcePrint }) {
|
|
|
1271
1304
|
let text = "";
|
|
1272
1305
|
let done = null;
|
|
1273
1306
|
let cancelled = false;
|
|
1307
|
+
let toolWroteFiles = false;
|
|
1274
1308
|
try {
|
|
1275
1309
|
if (useTools) {
|
|
1276
1310
|
const alwaysStore = permissions.load();
|
|
@@ -1295,6 +1329,7 @@ async function cmdRun(rest, { buildMode, printMode: forcePrint }) {
|
|
|
1295
1329
|
persistAlways: allowAll ? null : persistAlways,
|
|
1296
1330
|
},
|
|
1297
1331
|
maxIters: iters,
|
|
1332
|
+
projectMode,
|
|
1298
1333
|
memory: mem.text,
|
|
1299
1334
|
signal: canceller.signal,
|
|
1300
1335
|
});
|
|
@@ -1311,6 +1346,7 @@ async function cmdRun(rest, { buildMode, printMode: forcePrint }) {
|
|
|
1311
1346
|
return;
|
|
1312
1347
|
}
|
|
1313
1348
|
({ text, done } = loopResult);
|
|
1349
|
+
toolWroteFiles = (loopResult.toolCalls || []).some((c) => (c.tool === "write" || c.tool === "mkdir") && c.ok);
|
|
1314
1350
|
if (loopResult.cancelled || canceller.cancelled) {
|
|
1315
1351
|
try {
|
|
1316
1352
|
turn.cancel();
|
|
@@ -1383,11 +1419,13 @@ async function cmdRun(rest, { buildMode, printMode: forcePrint }) {
|
|
|
1383
1419
|
}
|
|
1384
1420
|
|
|
1385
1421
|
if (buildMode || outDir) {
|
|
1386
|
-
|
|
1422
|
+
// When the agent already wrote files with tools, do not dump the same
|
|
1423
|
+
// code a second time into --out: the disk is the deliverable.
|
|
1424
|
+
const blocks = toolWroteFiles ? [] : output.extractCodeBlocks(text);
|
|
1387
1425
|
if (blocks.length && outDir) {
|
|
1388
1426
|
const saved = output.saveTools(blocks, path.resolve(outDir));
|
|
1389
1427
|
for (const f of saved) process.stderr.write(`bolt: saved ${f}\n`);
|
|
1390
|
-
} else if (buildMode && !blocks.length) {
|
|
1428
|
+
} else if (buildMode && !blocks.length && !toolWroteFiles) {
|
|
1391
1429
|
process.stderr.write("bolt: no fenced code blocks found — see raw output above.\n");
|
|
1392
1430
|
}
|
|
1393
1431
|
}
|
|
@@ -1450,8 +1488,27 @@ function updateOutcome(installed, current) {
|
|
|
1450
1488
|
return String(installed) === String(current) ? "unchanged" : "upgraded";
|
|
1451
1489
|
}
|
|
1452
1490
|
|
|
1491
|
+
// A build installed from a local checkout (`npm install -g ./cli`) can be
|
|
1492
|
+
// ahead of the registry. Blindly installing the "latest" tag then silently
|
|
1493
|
+
// downgrades it - which is exactly how a 0.15.7 local build became 0.15.6.
|
|
1494
|
+
// Only install when the registry really is newer. An empty string means the
|
|
1495
|
+
// lookup failed, and the explicit update the operator asked for still runs.
|
|
1496
|
+
function shouldSelfUpdate(latest, current) {
|
|
1497
|
+
if (!latest) return true;
|
|
1498
|
+
return updatecheck.isNewer(latest, current);
|
|
1499
|
+
}
|
|
1500
|
+
|
|
1453
1501
|
function cmdUpdate() {
|
|
1454
|
-
|
|
1502
|
+
const latest = registryLatest();
|
|
1503
|
+
if (!shouldSelfUpdate(latest, VERSION)) {
|
|
1504
|
+
if (latest && updatecheck.compareVersions(VERSION, latest) > 0) {
|
|
1505
|
+
ui.ok(`v${VERSION} is ahead of the published v${latest} - nothing to update`);
|
|
1506
|
+
} else {
|
|
1507
|
+
ui.ok(`already on the latest version (v${VERSION})`);
|
|
1508
|
+
}
|
|
1509
|
+
return Promise.resolve();
|
|
1510
|
+
}
|
|
1511
|
+
console.log(`running: npm install -g @bolt-cli/cli${latest ? ` (v${latest})` : ""} (current: v${VERSION})`);
|
|
1455
1512
|
const inv = npmInvocation(["install", "-g", "@bolt-cli/cli"]);
|
|
1456
1513
|
const child = spawn(inv.command, inv.args, { stdio: "inherit", windowsHide: true });
|
|
1457
1514
|
return new Promise((resolve) => {
|
|
@@ -2200,7 +2257,7 @@ async function cmdRepl() {
|
|
|
2200
2257
|
// A partial command opens the live arrow-key palette instead of dumping
|
|
2201
2258
|
// a static list: type to filter, backspace refines, up/down moves, enter
|
|
2202
2259
|
// runs a complete command or fills the line for one needing args.
|
|
2203
|
-
const exactCommands = ["/exit", "/help", "/commands", "/status", "/stats", "/sessions", "/keys", "/watch", "/agents", "/models", "/balance", "/clear", "/session", "/tools", "/allow-all", "/permissions", "/init", "/resume", "/copy", "/mode", "/target", "/file", "/agent", "/undo", "/retry", "/export", "/doctor", "/templates"];
|
|
2260
|
+
const exactCommands = ["/exit", "/help", "/commands", "/status", "/stats", "/sessions", "/keys", "/watch", "/agents", "/models", "/balance", "/clear", "/session", "/tools", "/allow-all", "/permissions", "/init", "/resume", "/copy", "/mode", "/target", "/file", "/agent", "/project", "/undo", "/retry", "/export", "/doctor", "/templates"];
|
|
2204
2261
|
if (input.startsWith("/") && !input.includes(" ") && !exactCommands.includes(input)) {
|
|
2205
2262
|
const q = input.slice(1);
|
|
2206
2263
|
const all = present.paletteItems(COMMANDS, AGENTS);
|
|
@@ -2537,6 +2594,19 @@ async function cmdRepl() {
|
|
|
2537
2594
|
rl.prompt();
|
|
2538
2595
|
continue;
|
|
2539
2596
|
}
|
|
2597
|
+
if (input === "/project" || input.startsWith("/project ")) {
|
|
2598
|
+
// Arm the project agent and, when a description follows, run it right
|
|
2599
|
+
// away. The normal run path below creates folders, files and executes.
|
|
2600
|
+
const described = input.slice(8).trim();
|
|
2601
|
+
armedAgent = "project";
|
|
2602
|
+
setPrompt();
|
|
2603
|
+
ui.ok("project agent armed — Bolt will create folders, write files and run the project");
|
|
2604
|
+
if (!described) {
|
|
2605
|
+
rl.prompt();
|
|
2606
|
+
continue;
|
|
2607
|
+
}
|
|
2608
|
+
input = described;
|
|
2609
|
+
}
|
|
2540
2610
|
if (input.startsWith("/")) {
|
|
2541
2611
|
ui.err(`unknown command ${input}`);
|
|
2542
2612
|
ui.info("press / to open the command palette");
|
|
@@ -2558,6 +2628,9 @@ async function cmdRepl() {
|
|
|
2558
2628
|
const evidenceText = [parts.join("\n\n"), mentions.evidence].filter(Boolean).join("\n\n");
|
|
2559
2629
|
let objective = input;
|
|
2560
2630
|
if (armedAgent) objective = applyAgent(armedAgent, input, target);
|
|
2631
|
+
// A project-agent turn must build on disk, so enable the code-only
|
|
2632
|
+
// recovery nudge (pasted fences are not a deliverable in this mode).
|
|
2633
|
+
const projectMode = armedAgent === "project";
|
|
2561
2634
|
// Readline must not compete with the stream for the cursor, so it pauses
|
|
2562
2635
|
// for the duration of the turn. The old code left it live, which is why
|
|
2563
2636
|
// the prompt could interleave mid-answer.
|
|
@@ -2586,6 +2659,7 @@ async function cmdRepl() {
|
|
|
2586
2659
|
persistAlways: allowAll ? null : persistAlways,
|
|
2587
2660
|
},
|
|
2588
2661
|
maxIters: agent.DEFAULT_MAX_ITERS,
|
|
2662
|
+
projectMode,
|
|
2589
2663
|
memory: mem.text,
|
|
2590
2664
|
signal: canceller.signal,
|
|
2591
2665
|
});
|
|
@@ -2668,7 +2742,7 @@ async function run(argv) {
|
|
|
2668
2742
|
// Piped input with no command: single non-interactive run.
|
|
2669
2743
|
return cmdRun([], { buildMode: false });
|
|
2670
2744
|
}
|
|
2671
|
-
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")) {
|
|
2745
|
+
if (flag(argv, "-h", "--help") && (cmd === "run" || cmd === "build" || cmd === "project" || cmd === "watch" || cmd === "session" || cmd === "auth" || cmd === "signin" || cmd === "-p" || cmd === "--print" || cmd === "export" || cmd === "doctor" || cmd === "completion" || cmd === "undo" || cmd === "update")) {
|
|
2672
2746
|
console.log(help(cmd === "-p" || cmd === "--print" ? "run" : cmd));
|
|
2673
2747
|
return;
|
|
2674
2748
|
}
|
|
@@ -2693,6 +2767,9 @@ async function run(argv) {
|
|
|
2693
2767
|
// printed. Mutations are denied without --allow-all.
|
|
2694
2768
|
if (cmd === "-p" || cmd === "--print") return cmdRun(rest, { buildMode: false, printMode: true });
|
|
2695
2769
|
if (cmd === "build") return cmdRun(rest, { buildMode: true });
|
|
2770
|
+
// `bolt project` is the folder-first build: the agent creates the project
|
|
2771
|
+
// folder, writes files, runs it, and reports the real output.
|
|
2772
|
+
if (cmd === "project") return cmdRun(rest, { buildMode: false, forceAgent: "project" });
|
|
2696
2773
|
if (cmd === "session") return cmdSession(rest);
|
|
2697
2774
|
if (cmd === "doctor") return cmdDoctor();
|
|
2698
2775
|
if (cmd === "update") return cmdUpdate();
|
|
@@ -2704,4 +2781,4 @@ async function run(argv) {
|
|
|
2704
2781
|
throw new Error(`Unknown command "${cmd}".\n${help()}`);
|
|
2705
2782
|
}
|
|
2706
2783
|
|
|
2707
|
-
module.exports = { run, resolveUrl, isLoopbackUrl, backendReachable, completer, completeFileFrag, completeWithDescriptions, filterPaletteItems, isPaletteRunnable, COMMANDS, AGENTS, NO_ARG_COMMANDS, makeAsker, makeAskQuestion, handleToolEvent, estimateTokens, buildDryRunReport, printDryRun, dryRunTools, argvSecretWarning, cmdDoctor, cmdCompletion, cmdTemplates, cmdExport, cmdUndo, reportRunError, warnTruncated, stripBoltPrefix, printPaletteNumbered, resolvePalettePick, replWelcomeLines, printHelpBox, printSessionTable, printKeysBox, pickTip, TIPS, formatElapsed, backendHost, updateOutcome };
|
|
2784
|
+
module.exports = { run, resolveUrl, isLoopbackUrl, backendReachable, completer, completeFileFrag, completeWithDescriptions, filterPaletteItems, isPaletteRunnable, COMMANDS, AGENTS, NO_ARG_COMMANDS, resolveProjectDir, makeAsker, makeAskQuestion, handleToolEvent, estimateTokens, buildDryRunReport, printDryRun, dryRunTools, argvSecretWarning, cmdDoctor, cmdCompletion, cmdTemplates, cmdExport, cmdUndo, reportRunError, warnTruncated, stripBoltPrefix, printPaletteNumbered, resolvePalettePick, replWelcomeLines, printHelpBox, printSessionTable, printKeysBox, pickTip, TIPS, formatElapsed, backendHost, updateOutcome, shouldSelfUpdate };
|
package/lib/present.js
CHANGED
|
@@ -115,7 +115,7 @@ function filterPalette(query, commands, agents) {
|
|
|
115
115
|
// menus (run, session, safety, system) instead of one flat list. Pure:
|
|
116
116
|
// group membership is by command base, rows keep their COMMANDS text.
|
|
117
117
|
const HELP_GROUPS = [
|
|
118
|
-
["Run", ["/agents", "/agent", "/mode", "/target", "/file", "/init", "/retry", "/resume"]],
|
|
118
|
+
["Run", ["/agents", "/agent", "/project", "/mode", "/target", "/file", "/init", "/retry", "/resume"]],
|
|
119
119
|
["Session", ["/session", "/sessions", "/stats", "/export", "/undo", "/clear", "/copy", "/balance", "/status"]],
|
|
120
120
|
["Tools & safety", ["/tools", "/allow-all", "/permissions", "/templates"]],
|
|
121
121
|
["System", ["/models", "/doctor", "/watch", "/keys", "/help", "/exit"]],
|
package/lib/session.js
CHANGED
|
@@ -169,8 +169,36 @@ function digestTurn(t, index, total) {
|
|
|
169
169
|
return `Turn ${index + 1} of ${total} summary: ${head} | tools: ${toolText} | outcome: ${outcome}`;
|
|
170
170
|
}
|
|
171
171
|
|
|
172
|
+
// A run writes one turn per agent iteration so /stats can show the tool work,
|
|
173
|
+
// but a user turn is the whole run, not each internal step. Replaying the
|
|
174
|
+
// internal `[tool follow-up N]` turns as conversation (as this used to) pushed
|
|
175
|
+
// the real question and answer out of the newest-two window and sent a page of
|
|
176
|
+
// tool-result digests on every resume. Collapse them into the run that owns
|
|
177
|
+
// them: the objective stays the question, the last non-empty response is the
|
|
178
|
+
// answer, and tool outcomes merge (bounded to the same 8 the writer keeps).
|
|
179
|
+
const INTERNAL_TURN_RE = /^\[tool follow-up \d+\]$/;
|
|
180
|
+
function logicalTurns(turns) {
|
|
181
|
+
const out = [];
|
|
182
|
+
for (const turn of Array.isArray(turns) ? turns : []) {
|
|
183
|
+
const prompt = String((turn && turn.prompt) || "");
|
|
184
|
+
if (INTERNAL_TURN_RE.test(prompt) && out.length) {
|
|
185
|
+
const last = out[out.length - 1];
|
|
186
|
+
const response = String((turn && turn.response) || "");
|
|
187
|
+
if (response.trim()) last.response = response;
|
|
188
|
+
if (Array.isArray(turn && turn.tools)) {
|
|
189
|
+
last.tools = [...(Array.isArray(last.tools) ? last.tools : []), ...turn.tools].slice(0, 8);
|
|
190
|
+
}
|
|
191
|
+
last.mode = (turn && turn.mode) || last.mode;
|
|
192
|
+
last.target = (turn && turn.target) || last.target;
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
195
|
+
out.push({ ...turn });
|
|
196
|
+
}
|
|
197
|
+
return out;
|
|
198
|
+
}
|
|
199
|
+
|
|
172
200
|
function contextBlock(session, maxChars = 6000) {
|
|
173
|
-
const turns = (session.turns
|
|
201
|
+
const turns = logicalTurns(session.turns).slice(-8);
|
|
174
202
|
if (!turns.length) return "";
|
|
175
203
|
const older = turns.slice(0, -2);
|
|
176
204
|
const recent = turns.slice(-2);
|
|
@@ -183,4 +211,4 @@ function contextBlock(session, maxChars = 6000) {
|
|
|
183
211
|
return `Previous turns in this session (most recent last; older turns summarized, latest two in full):\n${joined}`;
|
|
184
212
|
}
|
|
185
213
|
|
|
186
|
-
module.exports = { create, load, save, appendTurn, list, latest, remove, contextBlock };
|
|
214
|
+
module.exports = { create, load, save, appendTurn, list, latest, remove, contextBlock, logicalTurns };
|
package/lib/toolparse.js
CHANGED
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
//
|
|
23
23
|
// Zero deps. toolparse must not require tools.js (tools.js requires this).
|
|
24
24
|
|
|
25
|
-
const TOOL_NAMES = ["read", "glob", "grep", "list", "write", "edit", "bash", "ask"];
|
|
25
|
+
const TOOL_NAMES = ["read", "glob", "grep", "list", "mkdir", "write", "edit", "bash", "ask"];
|
|
26
26
|
const MAX_TOOL_BLOCKS = 6;
|
|
27
27
|
|
|
28
28
|
const MAX_DEPTH = 3;
|
package/lib/tools.js
CHANGED
|
@@ -67,6 +67,8 @@ function describeCall(call) {
|
|
|
67
67
|
return `grep ${call.pattern || "(missing pattern)"}${call.path ? ` in ${call.path}` : ""}`;
|
|
68
68
|
case "list":
|
|
69
69
|
return `list ${call.path || "."}`;
|
|
70
|
+
case "mkdir":
|
|
71
|
+
return `mkdir ${call.path || "(missing path)"}`;
|
|
70
72
|
case "write":
|
|
71
73
|
return `write ${call.path || "(missing path)"} (${(call.content || "").length} chars)`;
|
|
72
74
|
case "edit":
|
|
@@ -283,6 +285,22 @@ function applyEdit(root, filePath, oldString, newString) {
|
|
|
283
285
|
return { ok: true, summary: "edited", detail: `Edited ${filePath}.` };
|
|
284
286
|
}
|
|
285
287
|
|
|
288
|
+
// Explicit folder creation. writeFile already creates parent directories, but
|
|
289
|
+
// a build needs a `mkdir` the model can name directly — otherwise projects get
|
|
290
|
+
// flattened into one folder or the model gives up when it cannot "make a
|
|
291
|
+
// directory". Same sandbox as every other mutation: recursive creation is
|
|
292
|
+
// convenient, path traversal is not.
|
|
293
|
+
function makeDir(root, input) {
|
|
294
|
+
const target = resolveInRoot(root, input);
|
|
295
|
+
if (!target.ok) return { ok: false, summary: "refused", detail: target.error };
|
|
296
|
+
try {
|
|
297
|
+
fs.mkdirSync(target.path, { recursive: true });
|
|
298
|
+
} catch {
|
|
299
|
+
return { ok: false, summary: "mkdir failed", detail: `Cannot create directory ${input}.` };
|
|
300
|
+
}
|
|
301
|
+
return { ok: true, summary: "created", detail: `Created directory ${input}.` };
|
|
302
|
+
}
|
|
303
|
+
|
|
286
304
|
function writeFile(root, filePath, content) {
|
|
287
305
|
const target = resolveInRoot(root, filePath);
|
|
288
306
|
if (!target.ok) return { ok: false, summary: "refused", detail: target.error };
|
|
@@ -466,8 +484,8 @@ function runBash(root, command, workdir) {
|
|
|
466
484
|
}
|
|
467
485
|
|
|
468
486
|
/**
|
|
469
|
-
* Approval policy. Reads, searches and `ask` run free; writes, edits
|
|
470
|
-
* shell commands ask unless the operator allowed the tool for the session,
|
|
487
|
+
* Approval policy. Reads, searches and `ask` run free; mkdir, writes, edits
|
|
488
|
+
* and shell commands ask unless the operator allowed the tool for the session,
|
|
471
489
|
* allowed it always (persisted in ~/.bolt/permissions.json), or passed
|
|
472
490
|
* --allow-all. Without an asker (piped output, --print) mutations are denied
|
|
473
491
|
* rather than guessed — the model is told so and works around it.
|
|
@@ -569,6 +587,8 @@ async function executeCall(call, ctx) {
|
|
|
569
587
|
return grepFiles(root, call.pattern, call.path);
|
|
570
588
|
case "list":
|
|
571
589
|
return listDir(root, call.path);
|
|
590
|
+
case "mkdir":
|
|
591
|
+
return makeDir(root, call.path);
|
|
572
592
|
case "write":
|
|
573
593
|
return writeFile(root, call.path, call.content);
|
|
574
594
|
case "edit":
|
|
@@ -601,6 +621,7 @@ module.exports = {
|
|
|
601
621
|
checkApproval,
|
|
602
622
|
executeCall,
|
|
603
623
|
listDir,
|
|
624
|
+
makeDir,
|
|
604
625
|
runBash,
|
|
605
626
|
truncate,
|
|
606
627
|
};
|
package/package.json
CHANGED