barebox 0.8.0 → 0.10.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/CHANGELOG.md +24 -0
- package/README.md +113 -86
- package/barebox.context.md +7 -4
- package/package.json +1 -1
- package/src/cli.js +66 -11
- package/src/config.js +13 -2
- package/src/holds.js +5 -0
- package/src/prompt.js +34 -12
- package/src/runtime.js +3 -1
- package/types/config.d.ts +2 -0
- package/types/prompt.d.ts +16 -3
- package/types/runtime.d.ts +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,30 @@ All notable changes to this project will be documented in this file.
|
|
|
4
4
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|
6
6
|
|
|
7
|
+
## [0.10.0] - 2026-11-10
|
|
8
|
+
|
|
9
|
+
Docs only; no code or behaviour changes.
|
|
10
|
+
|
|
11
|
+
### Changed
|
|
12
|
+
|
|
13
|
+
- README rewritten: what barebox is and its scope (up to 40 agents per proxy), how it works (one proxy for HTTP and HTTPS, one gate, one `gate.jsonl` audit file you can stream), how letters `r`/`w`/`x` are assigned and what each of the three modes lets through, what it blocks by default, real output samples (the terminal question, a run summary, an audit line), one table of measured numbers, known limits, and how to replay Demo A and Demo B from a clone. The roadmap section is removed.
|
|
14
|
+
- The PRD is split into a current spec and four reference pages (built modules M0-M7, evidence and memory budget, the hackathon plan, scope and questions); the previous version is archived unchanged. The spec now carries the post-hackathon build order (M8-M16) and the known gaps it closes.
|
|
15
|
+
|
|
16
|
+
## [0.9.0] - 2026-11-03
|
|
17
|
+
|
|
18
|
+
### Added
|
|
19
|
+
|
|
20
|
+
- `sbx run --hold <seconds|never>` sets how long a held request waits, per run, overriding the `holdTimeoutSec` config key.
|
|
21
|
+
- Terminal colors in the `sbx run` question and answers, only when stderr is a terminal and `NO_COLOR` is unset: yellow header with the agent name in bold, bold labels, cyan URL, dim data and hold id, green for allowed, red for denied or timed out. `--json` and piped output stay plain.
|
|
22
|
+
- The hold id shows in the question as `(hold hN)`.
|
|
23
|
+
- `sbx approve` and `sbx deny` on a hold that already ended print `<id> already decided` and exit 1; when the answer is written but the proxy has not read it yet, they print `<id>: answer written, the proxy has not read it yet`.
|
|
24
|
+
- `--name` for a sandbox that never ran exits 1 with `no sandbox named <n>` and creates nothing.
|
|
25
|
+
- Demo A (`examples/demo-a`): a scripted flight-booking run in ask, auto and trust modes, and a live driver (`--driver muse`) where you answer the holds. The README carries the measured numbers and a captioned demo.
|
|
26
|
+
|
|
27
|
+
### Changed
|
|
28
|
+
|
|
29
|
+
- `sbx run` waits for your answer by default (was 120 s); `--hold <seconds|never>` sets a deadline per run, and the `holdTimeoutSec` config key sets one for all runs. The library's `createHolds`/`createProxy` default stays 120 s. Unattended runs need `--hold <seconds>`.
|
|
30
|
+
|
|
7
31
|
## [0.8.0] - 2026-11-02
|
|
8
32
|
|
|
9
33
|
### Added
|
package/README.md
CHANGED
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
barebox
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
>
|
|
12
|
-
>
|
|
11
|
+
> A lightweight sandbox you spawn per agent, to control what it may do. Reads pass, file writes can be undone, and anything irreversible (pay, send, publish, push) waits for your yes.
|
|
12
|
+
> Many sandboxes, one proxy, one gate, one audit file. Up to 40 agents per proxy: for a laptop or a small VPS, not for big swarms.
|
|
13
13
|
|
|
14
14
|
<p align="center">
|
|
15
15
|
<img src="https://img.shields.io/github/package-json/v/hamr0/barebox?label=version&color=2a4f8c" alt="version (auto from package.json)">
|
|
@@ -17,108 +17,149 @@
|
|
|
17
17
|
<img src="https://img.shields.io/badge/platform-Linux-2a4f8c" alt="platform: Linux">
|
|
18
18
|
</p>
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+

|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
Demo A, a live unedited run: Meta's muse model books a trip. 31 requests, 23 went out with no question, 8 stopped for a person (3 allowed, 5 denied); the real payment key reached the server once, after a yes. Full captioned take: [assets/demo-a.webm](assets/demo-a.webm).
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
- **Heavy isolation.** Docker or a VM: images, a daemon, root, and the agent can't use your installed toolchain. Most people skip it.
|
|
24
|
+
**Replay it** (Linux, from a clone; needs network, httpbin.org stands in for the real services):
|
|
26
25
|
|
|
27
|
-
|
|
26
|
+
```
|
|
27
|
+
git clone https://github.com/hamr0/barebox && cd barebox && npm install
|
|
28
|
+
bash examples/demo-a/run.sh # Demo A scripted: book a trip, all three modes, every cell asserted
|
|
29
|
+
bash examples/demo-a/run.sh --driver muse --live --mode auto # the live run above; needs BASETEN_API_KEY, you answer the holds
|
|
30
|
+
bash examples/demo-b/run.sh # Demo B: a prompt-injected agent tries 3 exfiltrations in every mode
|
|
31
|
+
```
|
|
28
32
|
|
|
29
|
-
##
|
|
33
|
+
## How it works
|
|
30
34
|
|
|
31
|
-
|
|
35
|
+
```
|
|
36
|
+
agent (your real node, python, git, claude ...)
|
|
37
|
+
|
|
|
38
|
+
+-----+-------- bwrap sandbox (unprivileged, one per agent) --------+
|
|
39
|
+
| files: your project, read-only + an undo layer (--overlay) |
|
|
40
|
+
| locked: ~/.ssh, cloud creds, token files -> empty |
|
|
41
|
+
| network: none of its own; 127.0.0.1:3128 -> its unix socket |
|
|
42
|
+
+-----+-------------------------------------------------------------+
|
|
43
|
+
| one unix socket per agent (the socket is the identity, not a header)
|
|
44
|
+
v
|
|
45
|
+
ONE proxy, HTTP and HTTPS -> ONE gate (bareguard) -> world
|
|
46
|
+
| |
|
|
47
|
+
| '-> gate.jsonl, one audit line per decision
|
|
48
|
+
'-> held request: asks you in the terminal, forwards or 403
|
|
49
|
+
```
|
|
32
50
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
| `x` | can't be undone: send, pay, publish, push | holds it at the door until you decide | at the moment it happens |
|
|
51
|
+
- **Walls:** [bubblewrap](https://github.com/containers/bubblewrap), no root, no daemon, no image. The agent uses your installed tools.
|
|
52
|
+
- **One proxy for all sandboxes**, plain HTTP and HTTPS. HTTPS is read through a local CA that exists only inside the sandbox, so the gate sees method, URL, headers and body.
|
|
53
|
+
- **One gate decides every request** by its letter and the mode (below). It is a simple policy for spawning sandboxed agents on the fly: one flag, no rule files.
|
|
54
|
+
- **One audit file**, `<runtime>/gate.jsonl`, one JSON line per decision in [bareguard](https://github.com/hamr0/bareguard)'s shape. It is append-only, so `tail -f` it, pipe it to `jq`, or ship it to your log stack.
|
|
38
55
|
|
|
39
|
-
|
|
56
|
+
## r, w, x and the three modes
|
|
40
57
|
|
|
41
|
-
|
|
42
|
-
- **Locked drawers (r).** It reads most things. Keys and password stores (`~/.ssh`, `~/secrets`, `~/.gnupg`, `~/.password-store`, keyrings), browser profiles, cloud and cluster credentials (`~/.aws`, `~/.azure`, `~/.config/gcloud`, `~/.kube`, `~/.docker`, `~/.config/gh`, `~/.config/op`) and token files (`~/.netrc`, `~/.npmrc`, `~/.pypirc`, `~/.git-credentials`, `~/.cargo/credentials.toml`) stay shut. The agent's own model credentials (`~/.claude`) do not (a known gap: those tokens refresh themselves).
|
|
43
|
-
- **One front door with a doorman (x).** No network of its own. Lookups pass; anything that sends, pays, or publishes waits for your yes.
|
|
44
|
-
- **Keys it never holds.** The agent types a placeholder; the doorman puts the real API key in the request header only after the request is allowed, and only for the hosts that key is bound to. Your environment does not reach the sandbox.
|
|
58
|
+
Every request gets one letter:
|
|
45
59
|
|
|
46
|
-
|
|
60
|
+
| Letter | What | How barebox gets the letter |
|
|
61
|
+
|---|---|---|
|
|
62
|
+
| `r` | reads, changes nothing | `GET`, `HEAD`, and calls to model APIs (Anthropic, OpenAI, a `localLlm`) |
|
|
63
|
+
| `w` | a change that can be set back | only where an [rwxmap](https://github.com/hamr0/rwxmap) label for that API says so |
|
|
64
|
+
| `x` | can't be undone: send, pay, publish, push, delete | every other `POST`, `PUT`, `PATCH`, `DELETE`; any other method is denied |
|
|
47
65
|
|
|
48
|
-
|
|
49
|
-
- No Docker, no VM, no cluster, no cloud control plane. Your box or a cheap VPS.
|
|
50
|
-
- Not a content filter and not intent detection — the doorman sees requests, not intent. Cert-pinned apps, non-HTTP egress and UDP are denied, not inspected.
|
|
66
|
+
File writes are a separate layer: with `--overlay` every change lands on an undo layer, and at the end you `sbx diff`, `sbx commit` or `sbx rollback`.
|
|
51
67
|
|
|
52
|
-
|
|
68
|
+
The mode (`sbx run --mode ...`) picks which letters pass without asking:
|
|
69
|
+
|
|
70
|
+
| Mode | Passes | Asks |
|
|
71
|
+
|---|---|---|
|
|
72
|
+
| `ask` | `r` | `w`, `x` |
|
|
73
|
+
| `auto` (default) | `r`, `w` | `x` |
|
|
74
|
+
| `trust` | `r`, `w`, `x` | nothing |
|
|
75
|
+
|
|
76
|
+
**The floor asks in every mode, `trust` included:** a card number (Luhn) in a body of 64 KB or less, or a payment path (`/checkout`, `/payment`, `/orders`, `/purchase`).
|
|
77
|
+
|
|
78
|
+
## What it blocks by default
|
|
79
|
+
|
|
80
|
+
| Blocked | How |
|
|
81
|
+
|---|---|
|
|
82
|
+
| Keys and credentials: `~/.ssh`, `~/.gnupg`, `~/.password-store`, `~/secrets`, keyrings, browser profiles, `~/.aws`, `~/.azure`, `~/.config/gcloud`, `~/.kube`, `~/.docker`, `~/.config/gh`, `~/.config/op`, `~/.netrc`, `~/.npmrc`, `~/.pypirc`, `~/.git-credentials`, `~/.cargo/credentials.toml` | masked inside the sandbox: they read as empty |
|
|
83
|
+
| Your environment | cleared; only a short safe list (`TERM`, `LANG`, `LC_*`, `TZ`, `USER`, `SHELL`, ...) and names you list in `env.pass` get in (names like `*_TOKEN`, `*_KEY` are refused) |
|
|
84
|
+
| Any network but the proxy | the sandbox has no network of its own. `--noproxy`, unset proxy env, a direct IP or a raw socket fail closed; UDP and non-HTTP traffic are denied |
|
|
85
|
+
| Private and local addresses | the proxy checks every resolved IP (IPv6 spellings of IPv4 included) and refuses private ranges and names that don't resolve |
|
|
86
|
+
| Real API keys | the agent holds a per-run placeholder; the proxy swaps in the real key after the gate allows the request, over HTTPS, and only for the key's bound hosts (see below) |
|
|
87
|
+
| Answering its own questions | the ask and answer files live outside the sandbox and are masked from it |
|
|
88
|
+
|
|
89
|
+
## What you see
|
|
90
|
+
|
|
91
|
+
A held request asks in the terminal where you ran `sbx run` (`y` allows, anything else denies):
|
|
53
92
|
|
|
54
93
|
```
|
|
55
|
-
agent
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
| socat inside: 127.0.0.1:3128 -> per-agent unix socket |
|
|
63
|
-
+-----+------------------------------------------------------------+
|
|
64
|
-
| per-agent unix socket (the connection = the agent's identity)
|
|
65
|
-
v
|
|
66
|
-
ONE shared proxy (Node, in-process: rwxmap + bareguard)
|
|
67
|
-
|-- r -> forward
|
|
68
|
-
|-- x -> hold, ask the human, forward or 403
|
|
69
|
-
'-- unknown -> per-mode default
|
|
94
|
+
⏸ auto-agent-1 wants to SEND data to httpbin.org
|
|
95
|
+
Why: the address looks like a payment
|
|
96
|
+
URL: POST https://httpbin.org/anything/v1/payment_intents
|
|
97
|
+
Data: {"amount":35000,"currency":"usd"}
|
|
98
|
+
Allow? [y/N] (hold h1)
|
|
99
|
+
y
|
|
100
|
+
✓ allowed
|
|
70
101
|
```
|
|
71
102
|
|
|
72
|
-
|
|
73
|
-
- **Identity** is the socket, not a header the agent could fake. One socket per agent, all into one proxy.
|
|
74
|
-
- **HTTPS inspection** uses a local CA that exists only inside the sandbox; the proxy reads method, URL, headers and body, then forwards.
|
|
75
|
-
- **The doorman's x-rules**, strongest first: card numbers in the body (Luhn) → payment paths (`/checkout`, `/payment`, `/orders`, `/purchase`; a list of payment domains is not built) → rwxmap labels for known APIs → every other request by its letter and the mode (`ask`, `auto`, `trust`; see `barebox.context.md`). The card and payment floor asks in every mode, `trust` included (calls to a model endpoint are not card-scanned); card numbers are checked in bodies of 64 KB or less.
|
|
76
|
-
- **Approvals** are asked in the terminal where you ran `sbx run`, in plain words (`agent wants to SEND data to httpbin.org … Allow? [y/N]`); `y` allows, anything else denies. Name the sandbox (`sbx run --name docs-bot -- <cmd>`) and a second terminal can answer too (`sbx pending --name docs-bot`, `sbx approve <id> --name docs-bot`, `sbx deny <id> --name docs-bot`); the first answer wins. Timeout means deny, with a clear `403` reason. One held request per agent at a time: later ones wait in line (16 at most, then `429 hold queue full`), and the deadline counts from arrival.
|
|
103
|
+
Name the sandbox (`--name docs-bot`) and a second terminal can answer too: `sbx pending --name docs-bot`, `sbx approve h1 --name docs-bot`. A hold waits until you answer; for unattended runs (cron, CI) pass `--hold <seconds>`, and a timeout is a deny. One held request per agent at a time; up to 16 more wait in line.
|
|
77
104
|
|
|
78
|
-
|
|
105
|
+
Demo A's end-of-run summary (from the recorded take):
|
|
106
|
+
|
|
107
|
+
```
|
|
108
|
+
-- what barebox decided:
|
|
109
|
+
total 31 requests to the network: 23 free, 8 held for you (3 allowed, 5 denied) (model calls included)
|
|
110
|
+
search 3 free
|
|
111
|
+
pay 1 held: 1 allowed
|
|
112
|
+
POST /anything/hotels/checkout 1 held: 0 allowed, 1 denied
|
|
113
|
+
DELETE /anything/bookings/old-123 1 held: 0 allowed, 1 denied
|
|
114
|
+
model calls 18 free (labelled read-only)
|
|
115
|
+
key swaps 1 (the real test key went into the header only after your yes; the agent only ever had the placeholder)
|
|
116
|
+
```
|
|
79
117
|
|
|
80
|
-
|
|
118
|
+
An audit line from `gate.jsonl` (a POST held, then denied on timeout):
|
|
119
|
+
|
|
120
|
+
```json
|
|
121
|
+
{"ts":"2026-11-03T21:41:04.869Z","seq":8,"aid":"1a541f36","phase":"gate","action":{"type":"net","tool":"http.POST","url":"https://httpbin.org/post","method":"POST","agent":"rdme","rid":"r2"},"decision":"deny","rule":"rwx.ask","reason":"hold timeout"}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## Keys the agent never holds
|
|
81
125
|
|
|
82
126
|
```json
|
|
83
127
|
{
|
|
84
128
|
"secrets": {
|
|
85
129
|
"STRIPE_API_KEY": { "fromEnv": "REAL_STRIPE_KEY", "hosts": ["api.stripe.com"] }
|
|
86
|
-
}
|
|
87
|
-
"env": { "pass": ["MY_TOOL_HOME"] }
|
|
130
|
+
}
|
|
88
131
|
}
|
|
89
132
|
```
|
|
90
133
|
|
|
91
|
-
|
|
134
|
+
In `~/.config/barebox/config.json`. Inside, `$STRIPE_API_KEY` is a random placeholder, new each run, and the agent uses it like the key (`curl -H "Authorization: Bearer $STRIPE_API_KEY" ...`). The real value goes into the request header only after the gate allows it, only to `api.stripe.com`, only over HTTPS. Anywhere else the placeholder is refused (`403 denied: secret.host`, `secret.scheme`, `secret.url`).
|
|
92
135
|
|
|
93
136
|
## Numbers
|
|
94
137
|
|
|
95
|
-
Measured, not estimated
|
|
138
|
+
Measured, not estimated: Fedora, kernel 7.2, bubblewrap 0.12.0, Node 22. Method and raw runs: [findings](docs/logs/findings.md).
|
|
96
139
|
|
|
97
|
-
| | barebox
|
|
140
|
+
| | barebox | [srt](https://github.com/anthropic-experimental/sandbox-runtime) 0.0.81 |
|
|
98
141
|
|---|---|---|
|
|
99
|
-
| Memory per sandbox | **7.8 MB** mean, 8.0 MB max | ~100 MB (
|
|
100
|
-
|
|
|
101
|
-
|
|
|
102
|
-
|
|
|
103
|
-
|
|
|
104
|
-
|
|
|
142
|
+
| Memory per sandbox | **7.8 MB** mean, 8.0 MB max | ~100 MB (a proxy per sandbox) |
|
|
143
|
+
| Shared proxy, normal use (HTTPS, 10-40 agents) | **95-160 MB** | one per sandbox |
|
|
144
|
+
| Shared proxy, worst case (HTTPS, every agent with a held request, a full line and a full body slot) | **117 / 133-151 / 177-207 / 207-241 MB** at 10 / 20 / 30 / 40 agents | |
|
|
145
|
+
| Total, worst case (proxy + walls) | ~195-200 MB at 10, ~295-310 MB at 20, ~525-560 MB at 40 agents | ~1 GB at 10, ~2 GB at 20 |
|
|
146
|
+
| Start to exit, `sbx run -- true` | **0.70 s** median (0.80 s with `--overlay`; bwrap alone 6 ms) | 1.87-2.05 s |
|
|
147
|
+
| One real agent (Claude Code) | 248 MB inside vs 249 MB bare; barebox adds ~91 MB for the first agent, ~11 MB per further one | not measured |
|
|
148
|
+
| Agents per proxy | **40 max**, enforced (the 41st is refused; run another proxy) | |
|
|
149
|
+
| Demo B, 3 exfiltration attempts | **3 of 3 blocked** in every mode | |
|
|
105
150
|
|
|
106
|
-
|
|
151
|
+
Ranges run from a quiet machine to a busy one.
|
|
107
152
|
|
|
108
|
-
##
|
|
153
|
+
## Known limits
|
|
109
154
|
|
|
110
|
-
|
|
111
|
-
|---|---|
|
|
112
|
-
| M0 | Walls + front door |
|
|
113
|
-
| M1 | Proxy sees inside HTTPS (curl, node, python requests, git) |
|
|
114
|
-
| M2 | Hold one `x` request, ask, keep everything else running |
|
|
115
|
-
| M3 | Decide r/w/x deterministically (rwxmap + bareguard), audit log |
|
|
116
|
-
| M4 | Undo layer: `diff`, `commit`, `rollback`, conflict flagging |
|
|
117
|
-
| M5 | Keys the agent never holds |
|
|
118
|
-
| M6 | Scale run: 20 agents + shared proxy |
|
|
119
|
-
| M7 | Demos: payment held for approval; prompt-injected `~/.ssh` exfil blocked |
|
|
155
|
+
barebox is a guardrail against mistakes and prompt-injected agents, not a security boundary against a determined attacker: the kernel is shared, so use a VM for that. Known gaps, each with a planned fix in [the PRD](docs/product/agent-sandbox-prd.md) (section 10):
|
|
120
156
|
|
|
121
|
-
|
|
157
|
+
- Data in a `GET` URL goes out free: reads are `r`.
|
|
158
|
+
- The proxy resolves DNS before the gate decides, so data hidden in a hostname can leak.
|
|
159
|
+
- Model API calls pass with any key, an attacker's included.
|
|
160
|
+
- Bodies over 64 KB and compressed bodies are not scanned for card numbers.
|
|
161
|
+
- `~/.claude` stays readable: Claude Code's tokens refresh themselves.
|
|
162
|
+
- Writes over local sockets (a Postgres, a Docker daemon) are not on the undo layer.
|
|
122
163
|
|
|
123
164
|
## Install
|
|
124
165
|
|
|
@@ -126,19 +167,7 @@ M0–M2 are the go/no-go. Later: macOS (`sandbox-exec` + APFS clones), Windows v
|
|
|
126
167
|
npm install barebox
|
|
127
168
|
```
|
|
128
169
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
## Try the POCs
|
|
132
|
-
|
|
133
|
-
Linux only, with `bwrap` (>= 0.11.0 only for the overlay), `socat`, `openssl`, Node >= 22.21 and Python 3. Needs a normal shell (namespaces + listening sockets), not a tool sandbox. The POCs are throwaway proofs, not the product.
|
|
134
|
-
|
|
135
|
-
```
|
|
136
|
-
git clone https://github.com/hamr0/barebox && cd barebox
|
|
137
|
-
npm run poc:m0 # 20 sandboxes, bypass suite
|
|
138
|
-
npm run redteam:m0 # breaks each wall on purpose; passes iff all detected
|
|
139
|
-
bash poc/m1/run-m1.sh local # HTTPS inspection against a local TLS echo server
|
|
140
|
-
bash poc/m1/run-m1.sh real # same, real internet, incl. git over https
|
|
141
|
-
```
|
|
170
|
+
Linux. Node.js >= 22.21, `bwrap`, `socat`, `openssl`; bubblewrap >= 0.11.0 for `--overlay` (Ubuntu 24.04 ships 0.9.0). Two dependencies, [bareguard](https://npmjs.com/package/bareguard) and [rwxmap](https://npmjs.com/package/rwxmap), pinned exactly. The `sbx` CLI comes with it; the API is in [`barebox.context.md`](barebox.context.md).
|
|
142
171
|
|
|
143
172
|
## The bare ecosystem
|
|
144
173
|
|
|
@@ -149,7 +178,7 @@ mix and match, each module works standalone.
|
|
|
149
178
|
|
|
150
179
|
- **[bareagent](https://npmjs.com/package/bare-agent)** — the think→act→observe loop. *Goal in → coordinated actions out.* Replaces LangChain, CrewAI, AutoGen.
|
|
151
180
|
- **[bareguard](https://npmjs.com/package/bareguard)** — the single gate every action passes through. *Action in → allow / deny / ask-a-human out. Work in → green / red.* Replaces hand-rolled allowlists and scattered policy code.
|
|
152
|
-
- **[barebox](https://github.com/hamr0/barebox)**
|
|
181
|
+
- **[barebox](https://github.com/hamr0/barebox)** — the walls and the front door, this repo. *Agent in → contained run out: writes undoable, irreversible actions held for a human.* Replaces Docker/VM isolation and approve-everything prompts.
|
|
153
182
|
- **[litectx](https://npmjs.com/package/litectx)** — tree-sitter code + memory graph with activation decay, plus lightweight context engineering (write · select · compress · isolate). *Query in → ranked context out.*
|
|
154
183
|
|
|
155
184
|
**Add-on for bareguard** — labels API operations for the gate.
|
|
@@ -162,8 +191,6 @@ mix and match, each module works standalone.
|
|
|
162
191
|
- **[baremobile](https://npmjs.com/package/baremobile)** — Android + iOS device control. *Screen in → pruned snapshot out.* Replaces Appium, Espresso, XCUITest.
|
|
163
192
|
- **[beeperbox](https://github.com/hamr0/beeperbox)** — 50+ messaging networks via one MCP server (headless Beeper Desktop in Docker). *Chat in → unified message stream out.* Replaces Twilio, per-platform bot APIs.
|
|
164
193
|
|
|
165
|
-
bareguard decides the action; barebox contains where it runs.
|
|
166
|
-
|
|
167
194
|
## License
|
|
168
195
|
|
|
169
196
|
Apache 2.0. See [LICENSE](LICENSE).
|
package/barebox.context.md
CHANGED
|
@@ -58,7 +58,7 @@ await proxy.close();
|
|
|
58
58
|
When a request needs a decision (see "Modes and the gate" below), it parks.
|
|
59
59
|
`sbx run` with a terminal (stdin and stderr are TTYs, no `--json`) asks in place:
|
|
60
60
|
the sandbox name, what it wants to do and why, the URL, a masked body
|
|
61
|
-
preview, then `Allow? [y/N] (h3)`. `y` or `yes` allows; anything else, Enter
|
|
61
|
+
preview, then `Allow? [y/N] (hold h3)`. `y` or `yes` allows; anything else, Enter
|
|
62
62
|
included, denies with `denied at the terminal`. A line typed before a question
|
|
63
63
|
appears answers nothing. Name the sandbox with `sbx run --name docs-bot`: the
|
|
64
64
|
name is the agent name and picks the runtime dir
|
|
@@ -80,7 +80,7 @@ SBX_RUNTIME=/tmp/sbx npx sbx approve h1
|
|
|
80
80
|
SBX_RUNTIME=/tmp/sbx npx sbx deny h2 "reason here"
|
|
81
81
|
```
|
|
82
82
|
|
|
83
|
-
Held requests wait
|
|
83
|
+
Held requests wait, counting from arrival, until a deadline: the library's default is 120 s (`createHolds`/`createProxy`; `'never'` supported), while `sbx run` waits until answered by default (`holdTimeoutSec` `"never"`; `--hold <seconds|never>` or the config key sets a deadline):
|
|
84
84
|
time spent in line and reading the body counts too, and a request past its
|
|
85
85
|
deadline is denied `hold timeout` whether waiting, sending, or parked. Each
|
|
86
86
|
agent holds at most one request being read or parked; later ones wait in
|
|
@@ -88,6 +88,9 @@ line, unread, in order — at most 16, the next gets `429 hold queue full`.
|
|
|
88
88
|
Approve forwards, deny and timeout answer 403 with the reason. A held body is spooled to `<runtime>/held/<id>` (never kept in memory, deleted when the hold ends); one over `hold.maxBody` (default 50 MB) is denied `403 body too large to hold`. These commands
|
|
89
89
|
need the proxy to be alive: with no live proxy on the runtime `sbx pending`,
|
|
90
90
|
`approve` and `deny` exit 1 and say so, because nothing would read the answer.
|
|
91
|
+
`approve` and `deny` wait briefly to learn what the proxy did: an answer for a hold that already ended exits 1 with `<id> already decided`; if the proxy has not read it yet they print `answer written, the proxy has not read it yet` and still report `approved` / `denied`. `--name` for a sandbox that never ran exits 1 with `no sandbox named <n>` and creates nothing. The terminal question is colored only when stderr is a TTY and `NO_COLOR` is unset.
|
|
92
|
+
|
|
93
|
+
Unattended runs (cron, CI, no TTY, `--json`): nobody answers on the terminal, and `sbx run` waits forever by default, so a held request would hang the run. Pass `--hold <seconds>` (or set `holdTimeoutSec`) so a hold times out as a deny.
|
|
91
94
|
|
|
92
95
|
## One call: `run()` and `sbx run`
|
|
93
96
|
|
|
@@ -109,7 +112,7 @@ const { exit, asks, audit, diff, runtime } = await run({
|
|
|
109
112
|
```
|
|
110
113
|
|
|
111
114
|
```bash
|
|
112
|
-
sbx run [--name <n>] [--mode ask|auto|trust] [--json] [--overlay] -- <cmd> [...]
|
|
115
|
+
sbx run [--name <n>] [--mode ask|auto|trust] [--hold <seconds|never>] [--json] [--overlay] -- <cmd> [...]
|
|
113
116
|
```
|
|
114
117
|
|
|
115
118
|
`sbx run` uses the current directory as the project and `--name`'s runtime or
|
|
@@ -121,7 +124,7 @@ Its exit code mirrors the agent's.
|
|
|
121
124
|
|
|
122
125
|
`sbx run` reads one optional config file,
|
|
123
126
|
`${XDG_CONFIG_HOME:-$HOME/.config}/barebox/config.json`, with keys `mode`,
|
|
124
|
-
`holdTimeoutSec` (positive integer or `"never"`), `heldBodyMaxMB`
|
|
127
|
+
`holdTimeoutSec` (positive integer or `"never"`; default `"never"`, overridden per run by `--hold`), `heldBodyMaxMB`
|
|
125
128
|
(positive integer) and `localLlm` (array of `"host:port"`). A flag beats the file, the file beats the default; an
|
|
126
129
|
unknown key, bad value or bad JSON exits 2 naming the file and key. The file
|
|
127
130
|
is hidden inside the sandbox wherever it resolves. The library does not read it.
|
package/package.json
CHANGED
package/src/cli.js
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
// `--name <n>` names the sandbox (agent name + runtime dir, runtime.js namedRuntime) and every
|
|
14
14
|
// command takes `--name` instead of SBX_RUNTIME (both together: exit 2).
|
|
15
15
|
//
|
|
16
|
-
// sbx run [--mode ask|auto|trust] [--name <n>] [--json] [--overlay] -- <cmd> [...]
|
|
16
|
+
// sbx run [--mode ask|auto|trust] [--hold <seconds|never>] [--name <n>] [--json] [--overlay] -- <cmd> [...]
|
|
17
17
|
// Runs one sandboxed agent start-to-finish in this process (project = cwd).
|
|
18
18
|
// The runtime is SBX_RUNTIME when set, else a short temp dir (printed to
|
|
19
19
|
// stderr so a second terminal can approve from it). With --json, stdout
|
|
@@ -38,11 +38,12 @@ import { resolveConfig } from './config.js';
|
|
|
38
38
|
import { loadLabels } from './labels.js';
|
|
39
39
|
import { MODES } from './policy.js';
|
|
40
40
|
import { run as sandboxRun } from './run.js';
|
|
41
|
-
import { createTerminalPrompt } from './prompt.js';
|
|
41
|
+
import { createTerminalPrompt, paint, ANSI } from './prompt.js';
|
|
42
|
+
import { DEFAULT_POLL_MS } from './holds.js';
|
|
42
43
|
import { diffOverlay, commitOverlay, rollbackOverlay } from './overlay.js';
|
|
43
44
|
import { assertAgentName, createRuntime, namedRuntime, hostNode, runtimePaths, runtimeLive, safe, shellQuote } from './runtime.js';
|
|
44
45
|
|
|
45
|
-
const USAGE = 'usage: sbx [--help] | run [--mode ask|auto|trust] [--name <n>] [--json] [--overlay] -- <cmd> [...] | pending|diff|rollback [--name <n>] | approve <id> [--name <n>] | deny <id> [reason] [--name <n>] | commit [--name <n>] [--skip-conflicts] (--name replaces SBX_RUNTIME; --agent stays for diff/commit/rollback)';
|
|
46
|
+
const USAGE = 'usage: sbx [--help] | run [--mode ask|auto|trust] [--hold <seconds|never>] [--name <n>] [--json] [--overlay] -- <cmd> [...] | pending|diff|rollback [--name <n>] | approve <id> [--name <n>] | deny <id> [reason] [--name <n>] | commit [--name <n>] [--skip-conflicts] (--name replaces SBX_RUNTIME; --agent stays for diff/commit/rollback)';
|
|
46
47
|
|
|
47
48
|
/** Hold ids the CLI accepts: `h<n>` only. Anything else is a usage error, never a path. */
|
|
48
49
|
const HOLD_ID_RE = /^h\d+$/;
|
|
@@ -78,12 +79,18 @@ function needRuntime(name, create = false) {
|
|
|
78
79
|
err('give --name or SBX_RUNTIME, not both');
|
|
79
80
|
process.exit(2);
|
|
80
81
|
}
|
|
82
|
+
let dir;
|
|
81
83
|
try {
|
|
82
|
-
|
|
84
|
+
dir = namedRuntime(name, process.env, { create });
|
|
83
85
|
} catch (e) {
|
|
84
86
|
err(e instanceof Error ? e.message : String(e));
|
|
85
87
|
process.exit(2);
|
|
86
88
|
}
|
|
89
|
+
if (!create && !fs.existsSync(dir)) {
|
|
90
|
+
err(`no sandbox named ${name} (start one with 'sbx run --name ${name} -- …')`);
|
|
91
|
+
process.exit(1);
|
|
92
|
+
}
|
|
93
|
+
return dir;
|
|
87
94
|
}
|
|
88
95
|
const runtime = process.env.SBX_RUNTIME;
|
|
89
96
|
if (!runtime) usage();
|
|
@@ -190,7 +197,7 @@ async function run(args) {
|
|
|
190
197
|
if (sep < 0) usage();
|
|
191
198
|
const flags = args.slice(0, sep);
|
|
192
199
|
const command = args.slice(sep + 1);
|
|
193
|
-
/** @type {{ name?: string, mode?: string, json?: boolean, overlay?: boolean }} */
|
|
200
|
+
/** @type {{ name?: string, mode?: string, hold?: string, json?: boolean, overlay?: boolean }} */
|
|
194
201
|
let values;
|
|
195
202
|
try {
|
|
196
203
|
({ values } = parseArgs({
|
|
@@ -198,6 +205,7 @@ async function run(args) {
|
|
|
198
205
|
options: {
|
|
199
206
|
name: { type: 'string' },
|
|
200
207
|
mode: { type: 'string' },
|
|
208
|
+
hold: { type: 'string' },
|
|
201
209
|
json: { type: 'boolean' },
|
|
202
210
|
overlay: { type: 'boolean' },
|
|
203
211
|
},
|
|
@@ -211,7 +219,7 @@ async function run(args) {
|
|
|
211
219
|
/** @type {{ mode: string, holdTimeoutSec: number|string, localLlm: string[], labels: string[], tenants: Record<string, string[]>, heldBodyMaxMB?: number, env?: { pass?: string[], set?: Record<string, string> }, secrets?: Record<string, { fromEnv?: string, value?: string, hosts: string[] }> }} */
|
|
212
220
|
let cfg;
|
|
213
221
|
try {
|
|
214
|
-
cfg = resolveConfig({ mode: values.mode });
|
|
222
|
+
cfg = resolveConfig({ mode: values.mode, hold: values.hold });
|
|
215
223
|
} catch (e) {
|
|
216
224
|
err(e instanceof Error ? e.message : String(e));
|
|
217
225
|
process.exit(2);
|
|
@@ -244,10 +252,12 @@ async function run(args) {
|
|
|
244
252
|
};
|
|
245
253
|
// A person at this terminal (stdin and stderr are TTYs, not --json) answers
|
|
246
254
|
// holds here; the file channel stays on, so `sbx approve` still works too.
|
|
255
|
+
const errColor = !!process.stderr.isTTY && !process.env.NO_COLOR;
|
|
247
256
|
const prompt = !json && process.stdin.isTTY && process.stderr.isTTY
|
|
248
257
|
? createTerminalPrompt({
|
|
249
258
|
input: process.stdin,
|
|
250
259
|
output: process.stderr,
|
|
260
|
+
color: errColor,
|
|
251
261
|
answer: (id, decision, reason) => writeAnswer(runtimePaths(runtime), id, decision, reason),
|
|
252
262
|
})
|
|
253
263
|
: null;
|
|
@@ -262,7 +272,11 @@ async function run(args) {
|
|
|
262
272
|
if (json) out(JSON.stringify({ ev: 'decided', id: c.id, decision: c.decision, reason: c.reason }));
|
|
263
273
|
else out(`decided ${c.id} ${c.decision}${c.reason ? ` (${c.reason})` : ''}`);
|
|
264
274
|
};
|
|
265
|
-
|
|
275
|
+
if (name !== undefined && errColor) {
|
|
276
|
+
// Colored line: only the dynamic name is sanitized; `err` would strip the escapes.
|
|
277
|
+
const n = safe(name);
|
|
278
|
+
console.error(`sandbox ${paint(true, ANSI.bold, n)}${ANSI.dim} (answer from another terminal: sbx approve --name ${n} <id>)${ANSI.reset}`);
|
|
279
|
+
} else err(name !== undefined
|
|
266
280
|
? `sandbox ${name} (answer from another terminal: sbx approve --name ${name} <id>)`
|
|
267
281
|
: `runtime ${runtime} (answer with: SBX_RUNTIME=${shellQuote(runtime)} sbx approve <id>)`);
|
|
268
282
|
/** @type {{ exit: number, diff: { path: string }[] } | null} */
|
|
@@ -472,16 +486,57 @@ function alreadyAnswered(id) {
|
|
|
472
486
|
process.exit(1);
|
|
473
487
|
}
|
|
474
488
|
|
|
489
|
+
/**
|
|
490
|
+
* After our answer is linked, learn what the proxy did with it. The proxy
|
|
491
|
+
* writes `answers/<id>.stale` before it consumes an answer for a hold it no
|
|
492
|
+
* longer has, so once our answer file is gone the marker is the whole truth.
|
|
493
|
+
* Bounded at 4 poll intervals; a proxy that has not read it by then is
|
|
494
|
+
* reported, not guessed at.
|
|
495
|
+
*
|
|
496
|
+
* @param {ReturnType<typeof runtimePaths>} paths runtime paths
|
|
497
|
+
* @param {string} id hold id
|
|
498
|
+
* @returns {Promise<'settled'|'stale'|'unread'>} the outcome
|
|
499
|
+
*/
|
|
500
|
+
async function outcomeOf(paths, id) {
|
|
501
|
+
const end = Date.now() + 4 * DEFAULT_POLL_MS;
|
|
502
|
+
while (fs.existsSync(paths.answerFile(id))) {
|
|
503
|
+
if (Date.now() > end) return 'unread';
|
|
504
|
+
await new Promise((r) => setTimeout(r, 10));
|
|
505
|
+
}
|
|
506
|
+
try {
|
|
507
|
+
fs.unlinkSync(paths.staleFile(id));
|
|
508
|
+
return 'stale';
|
|
509
|
+
} catch {
|
|
510
|
+
return 'settled';
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
/**
|
|
515
|
+
* @param {ReturnType<typeof runtimePaths>} paths runtime paths
|
|
516
|
+
* @param {string} id hold id
|
|
517
|
+
* @param {'allow'|'deny'} decision the answer
|
|
518
|
+
* @param {string} [reason] deny reason
|
|
519
|
+
* @returns {Promise<void>} resolves when the answer settled the hold (or the proxy has not read it yet); exits 1 otherwise
|
|
520
|
+
*/
|
|
521
|
+
async function answerHold(paths, id, decision, reason) {
|
|
522
|
+
if (!writeAnswer(paths, id, decision, reason)) alreadyAnswered(id);
|
|
523
|
+
const outcome = await outcomeOf(paths, id);
|
|
524
|
+
if (outcome === 'stale') {
|
|
525
|
+
err(`${id} already decided`);
|
|
526
|
+
process.exit(1);
|
|
527
|
+
}
|
|
528
|
+
if (outcome === 'unread') err(`${id}: answer written, the proxy has not read it yet`);
|
|
529
|
+
out(`${decision === 'allow' ? 'approved' : 'denied'} ${id}`);
|
|
530
|
+
}
|
|
531
|
+
|
|
475
532
|
/** @param {string[]} rest @returns {Promise<void>} */
|
|
476
533
|
async function approve(rest) {
|
|
477
534
|
const { id, paths } = await answerTarget(rest);
|
|
478
|
-
|
|
479
|
-
out(`approved ${id}`);
|
|
535
|
+
await answerHold(paths, id, 'allow');
|
|
480
536
|
}
|
|
481
537
|
|
|
482
538
|
/** @param {string[]} rest @returns {Promise<void>} */
|
|
483
539
|
async function deny(rest) {
|
|
484
540
|
const { id, reason, paths } = await answerTarget(rest);
|
|
485
|
-
|
|
486
|
-
out(`denied ${id}`);
|
|
541
|
+
await answerHold(paths, id, 'deny', reason);
|
|
487
542
|
}
|
package/src/config.js
CHANGED
|
@@ -7,7 +7,7 @@ import os from 'node:os';
|
|
|
7
7
|
import path from 'node:path';
|
|
8
8
|
import { MODES } from './policy.js';
|
|
9
9
|
|
|
10
|
-
const DEFAULTS = { mode: 'auto', holdTimeoutSec:
|
|
10
|
+
const DEFAULTS = { mode: 'auto', holdTimeoutSec: 'never', localLlm: [], labels: [], tenants: {} };
|
|
11
11
|
|
|
12
12
|
/** One `host:port` (host without a colon, port 1-65535). @param {unknown} v @returns {boolean} */
|
|
13
13
|
const isHostPort = (v) => {
|
|
@@ -137,11 +137,22 @@ export function loadConfig(env = process.env) {
|
|
|
137
137
|
*
|
|
138
138
|
* @param {object} [flags] values given on the command line
|
|
139
139
|
* @param {string} [flags.mode] `--mode`
|
|
140
|
+
* @param {string} [flags.hold] `--hold` (`"never"` or a positive integer of seconds, as typed)
|
|
140
141
|
* @param {NodeJS.ProcessEnv} [env] environment to read (default `process.env`)
|
|
141
142
|
* @returns {{ mode: string, holdTimeoutSec: number|string, localLlm: string[], labels: string[], tenants: Record<string, string[]>, heldBodyMaxMB?: number, env?: { pass?: string[], set?: Record<string, string> }, secrets?: Record<string, { fromEnv?: string, value?: string, hosts: string[] }> }} effective settings (`heldBodyMaxMB` absent means the library default)
|
|
142
143
|
* @throws {Error} as {@link loadConfig}
|
|
143
144
|
*/
|
|
144
145
|
export function resolveConfig(flags = {}, env = process.env) {
|
|
145
146
|
const cfg = loadConfig(env);
|
|
146
|
-
|
|
147
|
+
let hold;
|
|
148
|
+
if (flags.hold !== undefined) {
|
|
149
|
+
hold = flags.hold === 'never' ? 'never' : /^\d+$/.test(flags.hold) ? Number(flags.hold) : flags.hold;
|
|
150
|
+
const bad = KEYS.holdTimeoutSec(hold);
|
|
151
|
+
if (bad) throw new Error(`--hold ${bad}`);
|
|
152
|
+
}
|
|
153
|
+
return {
|
|
154
|
+
...cfg,
|
|
155
|
+
...(flags.mode !== undefined ? { mode: flags.mode } : {}),
|
|
156
|
+
...(hold !== undefined ? { holdTimeoutSec: hold } : {}),
|
|
157
|
+
};
|
|
147
158
|
}
|
package/src/holds.js
CHANGED
|
@@ -487,6 +487,11 @@ export function createHolds({ log, timeoutMs = 120000,
|
|
|
487
487
|
for (const name of names) {
|
|
488
488
|
if (!name.endsWith('.json')) continue;
|
|
489
489
|
const id = name.slice(0, -'.json'.length);
|
|
490
|
+
// Not held: say so (the marker `sbx approve` reads) before the answer
|
|
491
|
+
// is consumed, so "answer gone" always means the marker is already there.
|
|
492
|
+
if (!queue.has(id)) {
|
|
493
|
+
try { writeFileAtomic(paths.staleFile(id), ''); } catch {}
|
|
494
|
+
}
|
|
490
495
|
const text = consumeFile(paths.answerFile(id));
|
|
491
496
|
if (text === null) continue;
|
|
492
497
|
const norm = normalizeDecision(parseAnswer(text), { approveAlias: true });
|
package/src/prompt.js
CHANGED
|
@@ -13,6 +13,20 @@ const BODY_CHARS = 200;
|
|
|
13
13
|
const EOL = /\r\n|\r|\n/;
|
|
14
14
|
const YES = new Set(['y', 'yes']);
|
|
15
15
|
|
|
16
|
+
// Plain ANSI. Escapes are added only around text that already went through
|
|
17
|
+
// `safe()`, which strips every escape from agent bytes; never paint raw text.
|
|
18
|
+
export const ANSI = { bold: '\x1b[1m', dim: '\x1b[2m', red: '\x1b[31m', green: '\x1b[32m', yellow: '\x1b[33m', cyan: '\x1b[36m', unbold: '\x1b[22m', reset: '\x1b[0m' };
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Wrap already-sanitized text in escapes when `on`; plain text otherwise.
|
|
22
|
+
*
|
|
23
|
+
* @param {boolean} on whether color is enabled
|
|
24
|
+
* @param {string} codes one or more ANSI.* escapes
|
|
25
|
+
* @param {string} text sanitized text
|
|
26
|
+
* @returns {string} the painted text
|
|
27
|
+
*/
|
|
28
|
+
export const paint = (on, codes, text) => (on ? `${codes}${text}${ANSI.reset}` : text);
|
|
29
|
+
|
|
16
30
|
/** @typedef {{ id: string, agent?: string, method: string, url: string, rule: string, letter: string, bodyPreview?: string, expiresAt?: string|null }} AskRecord */
|
|
17
31
|
|
|
18
32
|
/**
|
|
@@ -21,9 +35,11 @@ const YES = new Set(['y', 'yes']);
|
|
|
21
35
|
*
|
|
22
36
|
* @param {AskRecord} ask the parked request
|
|
23
37
|
* @param {number} [now] clock for the countdown, injectable
|
|
38
|
+
* @param {boolean} [color] paint with ANSI escapes (off by default)
|
|
24
39
|
* @returns {string[]} the question, one string per line
|
|
25
40
|
*/
|
|
26
|
-
export function questionLines(ask, now = Date.now()) {
|
|
41
|
+
export function questionLines(ask, now = Date.now(), color = false) {
|
|
42
|
+
const { bold, dim, red, green, yellow, cyan, unbold } = ANSI;
|
|
27
43
|
const method = safe(ask.method).toUpperCase();
|
|
28
44
|
let host;
|
|
29
45
|
try { host = safe(new URL(ask.url).host); } catch { host = safe(ask.url); }
|
|
@@ -38,14 +54,19 @@ export function questionLines(ask, now = Date.now()) {
|
|
|
38
54
|
: ask.letter === 'x' ? "a change barebox can't undo"
|
|
39
55
|
: rule;
|
|
40
56
|
const left = ask.expiresAt ? Math.max(0, Math.round((Date.parse(ask.expiresAt) - now) / 1000)) : null;
|
|
57
|
+
const name = safe(ask.agent) || 'agent';
|
|
58
|
+
const head = color
|
|
59
|
+
? paint(true, yellow, `⏸ ${bold}${name}${unbold} wants to ${verb} ${host}`)
|
|
60
|
+
: `⏸ ${name} wants to ${verb} ${host}`;
|
|
41
61
|
const lines = [
|
|
42
|
-
|
|
43
|
-
` Why: ${why}`,
|
|
44
|
-
` URL: ${method} ${safe(ask.url)}`,
|
|
62
|
+
head,
|
|
63
|
+
` ${paint(color, bold, 'Why:')} ${why}`,
|
|
64
|
+
` ${paint(color, bold, 'URL:')} ${paint(color, cyan, `${method} ${safe(ask.url)}`)}`,
|
|
45
65
|
];
|
|
46
66
|
const body = safe(ask.bodyPreview).slice(0, BODY_CHARS);
|
|
47
|
-
if (body) lines.push(` Data: ${body}`);
|
|
48
|
-
|
|
67
|
+
if (body) lines.push(` ${paint(color, bold, 'Data:')} ${paint(color, dim, body)}`);
|
|
68
|
+
const tail = `(hold ${safe(ask.id)})${left === null || Number.isNaN(left) ? '' : ` — no answer in ${left} s means No`}`;
|
|
69
|
+
lines.push(` ${paint(color, bold, 'Allow? [y/N]')} ${paint(color, dim, tail)}`);
|
|
49
70
|
return lines;
|
|
50
71
|
}
|
|
51
72
|
|
|
@@ -56,10 +77,10 @@ export function questionLines(ask, now = Date.now()) {
|
|
|
56
77
|
* closes the question when the hold ended some other way, `close()` releases
|
|
57
78
|
* `input`.
|
|
58
79
|
*
|
|
59
|
-
* @param {{ input: import('node:stream').Readable, output: { write: (s: string) => unknown }, answer: (id: string, decision: 'allow'|'deny', reason?: string) => boolean|void }} opts streams and the answer writer
|
|
80
|
+
* @param {{ input: import('node:stream').Readable, output: { write: (s: string) => unknown }, color?: boolean, answer: (id: string, decision: 'allow'|'deny', reason?: string) => boolean|void }} opts streams and the answer writer
|
|
60
81
|
* @returns {{ ask: (ask: AskRecord) => boolean, decided: (e: { id: string, decision: string, reason?: string }) => void, close: () => void }} the prompt
|
|
61
82
|
*/
|
|
62
|
-
export function createTerminalPrompt({ input, output, answer }) {
|
|
83
|
+
export function createTerminalPrompt({ input, output, answer, color = false }) {
|
|
63
84
|
/** @type {AskRecord|null} */
|
|
64
85
|
let open = null;
|
|
65
86
|
let buf = '';
|
|
@@ -73,7 +94,8 @@ export function createTerminalPrompt({ input, output, answer }) {
|
|
|
73
94
|
const yes = YES.has(line.trim().toLowerCase());
|
|
74
95
|
try {
|
|
75
96
|
const written = answer(id, yes ? 'allow' : 'deny', yes ? undefined : 'denied at the terminal') !== false;
|
|
76
|
-
say(!written ? 'answered elsewhere'
|
|
97
|
+
say(!written ? 'answered elsewhere'
|
|
98
|
+
: yes ? paint(color, ANSI.green + ANSI.bold, '✓ allowed') : paint(color, ANSI.red + ANSI.bold, '✗ denied'));
|
|
77
99
|
} catch {
|
|
78
100
|
// The hold ended (or the runtime went) before this write; the run goes on.
|
|
79
101
|
}
|
|
@@ -97,15 +119,15 @@ export function createTerminalPrompt({ input, output, answer }) {
|
|
|
97
119
|
if (closed || open) return false;
|
|
98
120
|
open = ask;
|
|
99
121
|
buf = ''; // a half-typed line from before the question is stale
|
|
100
|
-
for (const l of questionLines(open)) say(l);
|
|
122
|
+
for (const l of questionLines(open, Date.now(), color)) say(l);
|
|
101
123
|
return true;
|
|
102
124
|
},
|
|
103
125
|
decided(e) {
|
|
104
126
|
if (open?.id !== e.id) return;
|
|
105
127
|
open = null; // closed before anything else: no answer can follow
|
|
106
128
|
const why = safe(e.reason);
|
|
107
|
-
say(why === 'hold timeout' ? `timed out: ${safe(e.decision)}`
|
|
108
|
-
: why === 'client gone' || why === 'proxy closing' ? `agent gone: ${safe(e.decision)}`
|
|
129
|
+
say(why === 'hold timeout' ? paint(color, ANSI.red, `timed out: ${safe(e.decision)}`)
|
|
130
|
+
: why === 'client gone' || why === 'proxy closing' ? paint(color, ANSI.red, `agent gone: ${safe(e.decision)}`)
|
|
109
131
|
: `answered elsewhere: ${safe(e.decision)}${why ? ` (${why})` : ''}`);
|
|
110
132
|
},
|
|
111
133
|
close() {
|
package/src/runtime.js
CHANGED
|
@@ -334,7 +334,7 @@ export function shellQuote(s) {
|
|
|
334
334
|
* Every path in a runtime dir. The one place that names them.
|
|
335
335
|
*
|
|
336
336
|
* @param {string} runtime runtime dir
|
|
337
|
-
* @returns {{ socket: (agent: string) => string, asksDir: string, answersDir: string, askFile: (id: string) => string, answerFile: (id: string) => string, heldDir: string, heldFile: (id: string) => string, certsDir: string, caBundle: string, audit: string, owner: string, overlay: (agent: string) => { base: string, upper: string, work: string, manifest: string } }} layout
|
|
337
|
+
* @returns {{ socket: (agent: string) => string, asksDir: string, answersDir: string, askFile: (id: string) => string, answerFile: (id: string) => string, staleFile: (id: string) => string, heldDir: string, heldFile: (id: string) => string, certsDir: string, caBundle: string, audit: string, owner: string, overlay: (agent: string) => { base: string, upper: string, work: string, manifest: string } }} layout
|
|
338
338
|
*/
|
|
339
339
|
export function runtimePaths(runtime) {
|
|
340
340
|
const asksDir = path.join(runtime, 'asks');
|
|
@@ -346,6 +346,8 @@ export function runtimePaths(runtime) {
|
|
|
346
346
|
answersDir,
|
|
347
347
|
askFile: (id) => path.join(asksDir, `${id}.json`),
|
|
348
348
|
answerFile: (id) => path.join(answersDir, `${id}.json`),
|
|
349
|
+
// The proxy's note that an answer for `id` arrived after the hold settled; written before the answer is consumed.
|
|
350
|
+
staleFile: (id) => path.join(answersDir, `${id}.stale`),
|
|
349
351
|
heldDir,
|
|
350
352
|
// A held request's body, spooled to disk while it waits for a decision.
|
|
351
353
|
heldFile: (id) => path.join(heldDir, id),
|
package/types/config.d.ts
CHANGED
|
@@ -34,12 +34,14 @@ export function loadConfig(env?: NodeJS.ProcessEnv): {
|
|
|
34
34
|
*
|
|
35
35
|
* @param {object} [flags] values given on the command line
|
|
36
36
|
* @param {string} [flags.mode] `--mode`
|
|
37
|
+
* @param {string} [flags.hold] `--hold` (`"never"` or a positive integer of seconds, as typed)
|
|
37
38
|
* @param {NodeJS.ProcessEnv} [env] environment to read (default `process.env`)
|
|
38
39
|
* @returns {{ mode: string, holdTimeoutSec: number|string, localLlm: string[], labels: string[], tenants: Record<string, string[]>, heldBodyMaxMB?: number, env?: { pass?: string[], set?: Record<string, string> }, secrets?: Record<string, { fromEnv?: string, value?: string, hosts: string[] }> }} effective settings (`heldBodyMaxMB` absent means the library default)
|
|
39
40
|
* @throws {Error} as {@link loadConfig}
|
|
40
41
|
*/
|
|
41
42
|
export function resolveConfig(flags?: {
|
|
42
43
|
mode?: string | undefined;
|
|
44
|
+
hold?: string | undefined;
|
|
43
45
|
}, env?: NodeJS.ProcessEnv): {
|
|
44
46
|
mode: string;
|
|
45
47
|
holdTimeoutSec: number | string;
|
package/types/prompt.d.ts
CHANGED
|
@@ -5,9 +5,10 @@
|
|
|
5
5
|
*
|
|
6
6
|
* @param {AskRecord} ask the parked request
|
|
7
7
|
* @param {number} [now] clock for the countdown, injectable
|
|
8
|
+
* @param {boolean} [color] paint with ANSI escapes (off by default)
|
|
8
9
|
* @returns {string[]} the question, one string per line
|
|
9
10
|
*/
|
|
10
|
-
export function questionLines(ask: AskRecord, now?: number): string[];
|
|
11
|
+
export function questionLines(ask: AskRecord, now?: number, color?: boolean): string[];
|
|
11
12
|
/**
|
|
12
13
|
* The terminal prompt. One question open at a time. `ask()` opens a question
|
|
13
14
|
* and returns true, or returns false when one is already open (or the prompt
|
|
@@ -15,14 +16,15 @@ export function questionLines(ask: AskRecord, now?: number): string[];
|
|
|
15
16
|
* closes the question when the hold ended some other way, `close()` releases
|
|
16
17
|
* `input`.
|
|
17
18
|
*
|
|
18
|
-
* @param {{ input: import('node:stream').Readable, output: { write: (s: string) => unknown }, answer: (id: string, decision: 'allow'|'deny', reason?: string) => boolean|void }} opts streams and the answer writer
|
|
19
|
+
* @param {{ input: import('node:stream').Readable, output: { write: (s: string) => unknown }, color?: boolean, answer: (id: string, decision: 'allow'|'deny', reason?: string) => boolean|void }} opts streams and the answer writer
|
|
19
20
|
* @returns {{ ask: (ask: AskRecord) => boolean, decided: (e: { id: string, decision: string, reason?: string }) => void, close: () => void }} the prompt
|
|
20
21
|
*/
|
|
21
|
-
export function createTerminalPrompt({ input, output, answer }: {
|
|
22
|
+
export function createTerminalPrompt({ input, output, answer, color }: {
|
|
22
23
|
input: import("node:stream").Readable;
|
|
23
24
|
output: {
|
|
24
25
|
write: (s: string) => unknown;
|
|
25
26
|
};
|
|
27
|
+
color?: boolean;
|
|
26
28
|
answer: (id: string, decision: "allow" | "deny", reason?: string) => boolean | void;
|
|
27
29
|
}): {
|
|
28
30
|
ask: (ask: AskRecord) => boolean;
|
|
@@ -33,6 +35,17 @@ export function createTerminalPrompt({ input, output, answer }: {
|
|
|
33
35
|
}) => void;
|
|
34
36
|
close: () => void;
|
|
35
37
|
};
|
|
38
|
+
export namespace ANSI {
|
|
39
|
+
let bold: string;
|
|
40
|
+
let dim: string;
|
|
41
|
+
let red: string;
|
|
42
|
+
let green: string;
|
|
43
|
+
let yellow: string;
|
|
44
|
+
let cyan: string;
|
|
45
|
+
let unbold: string;
|
|
46
|
+
let reset: string;
|
|
47
|
+
}
|
|
48
|
+
export function paint(on: boolean, codes: string, text: string): string;
|
|
36
49
|
export type AskRecord = {
|
|
37
50
|
id: string;
|
|
38
51
|
agent?: string;
|
package/types/runtime.d.ts
CHANGED
|
@@ -155,7 +155,7 @@ export function shellQuote(s: string): string;
|
|
|
155
155
|
* Every path in a runtime dir. The one place that names them.
|
|
156
156
|
*
|
|
157
157
|
* @param {string} runtime runtime dir
|
|
158
|
-
* @returns {{ socket: (agent: string) => string, asksDir: string, answersDir: string, askFile: (id: string) => string, answerFile: (id: string) => string, heldDir: string, heldFile: (id: string) => string, certsDir: string, caBundle: string, audit: string, owner: string, overlay: (agent: string) => { base: string, upper: string, work: string, manifest: string } }} layout
|
|
158
|
+
* @returns {{ socket: (agent: string) => string, asksDir: string, answersDir: string, askFile: (id: string) => string, answerFile: (id: string) => string, staleFile: (id: string) => string, heldDir: string, heldFile: (id: string) => string, certsDir: string, caBundle: string, audit: string, owner: string, overlay: (agent: string) => { base: string, upper: string, work: string, manifest: string } }} layout
|
|
159
159
|
*/
|
|
160
160
|
export function runtimePaths(runtime: string): {
|
|
161
161
|
socket: (agent: string) => string;
|
|
@@ -163,6 +163,7 @@ export function runtimePaths(runtime: string): {
|
|
|
163
163
|
answersDir: string;
|
|
164
164
|
askFile: (id: string) => string;
|
|
165
165
|
answerFile: (id: string) => string;
|
|
166
|
+
staleFile: (id: string) => string;
|
|
166
167
|
heldDir: string;
|
|
167
168
|
heldFile: (id: string) => string;
|
|
168
169
|
certsDir: string;
|