barebox 0.11.0 → 0.12.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 +8 -0
- package/README.md +3 -3
- package/barebox.context.md +8 -5
- package/package.json +1 -1
- package/src/cli.js +14 -7
- package/src/config.js +3 -3
- package/src/prompt.js +51 -26
- package/types/config.d.ts +4 -4
- package/types/prompt.d.ts +5 -4
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,14 @@ 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.12.0] - 2026-11-12
|
|
8
|
+
|
|
9
|
+
### Changed
|
|
10
|
+
|
|
11
|
+
- `sbx run` on a terminal answers at once with `→ sent` and appends the outcome when the proxy decides (`✓ allowed`, `✗ denied`, `✗ timed out (denied)`, ...): a `y` typed just before the `--hold` deadline shows `✗ timed out (denied)`, never `✓ allowed`, and no plain `decided` line repeats it. An answer that cannot be written prints `✗ not sent (<code>)` instead of nothing.
|
|
12
|
+
- After `✗ not sent` the same question stays open for a retry; a second hold never prints into an open `→ sent` line.
|
|
13
|
+
- `sbx run` without a terminal (cron, CI, `--json`, stdin or stderr redirected) now denies a held request after 3 minutes instead of waiting forever; with a terminal it still waits. `--hold` or `holdTimeoutSec` sets either.
|
|
14
|
+
|
|
7
15
|
## [0.11.0] - 2026-11-11
|
|
8
16
|
|
|
9
17
|
### Added
|
package/README.md
CHANGED
|
@@ -80,7 +80,7 @@ The mode (`sbx run --mode ...`) picks which letters pass without asking:
|
|
|
80
80
|
| Blocked | How |
|
|
81
81
|
|---|---|
|
|
82
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) |
|
|
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; set a harmless one such as `XKB_KEYMAP` with `env.set`) |
|
|
84
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
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
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) |
|
|
@@ -97,10 +97,10 @@ A held request asks in the terminal where you ran `sbx run` (`y` allows, anythin
|
|
|
97
97
|
Data: {"amount":35000,"currency":"usd"}
|
|
98
98
|
Allow? [y/N] (hold h1)
|
|
99
99
|
y
|
|
100
|
-
✓ allowed
|
|
100
|
+
→ sent ✓ allowed
|
|
101
101
|
```
|
|
102
102
|
|
|
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;
|
|
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 at a terminal; without one (cron, CI, `--json`, stdin or stderr redirected) it is denied after 3 minutes. `--hold <seconds|never>` or `holdTimeoutSec` changes either, and a timeout is a deny. One held request per agent at a time; up to 16 more wait in line.
|
|
104
104
|
|
|
105
105
|
Demo A's end-of-run summary (from the recorded take):
|
|
106
106
|
|
package/barebox.context.md
CHANGED
|
@@ -60,7 +60,10 @@ When a request needs a decision (see "Modes and the gate" below), it parks.
|
|
|
60
60
|
the sandbox name, what it wants to do and why, the URL, a masked body
|
|
61
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
|
-
appears answers nothing.
|
|
63
|
+
appears answers nothing. `→ sent` prints at once when your answer is written, and the
|
|
64
|
+
outcome is appended on the same line when the proxy decides (`✓ allowed`, `✗ denied`,
|
|
65
|
+
`✗ timed out (denied)`, `✗ agent gone (denied)`, `✗ sandbox closed (denied)`, `✓`/`✗ answered
|
|
66
|
+
elsewhere`), so a `y` that arrives after the deadline shows `→ sent ✗ timed out (denied)`. Name the sandbox with `sbx run --name docs-bot`: the
|
|
64
67
|
name is the agent name and picks the runtime dir
|
|
65
68
|
(`$XDG_RUNTIME_DIR/barebox/<name>`, else `<tmpdir>/sbx-<uid>/<name>`, kept
|
|
66
69
|
after the run), and every other command takes `--name docs-bot` instead of
|
|
@@ -68,7 +71,7 @@ after the run), and every other command takes `--name docs-bot` instead of
|
|
|
68
71
|
|
|
69
72
|
A second terminal can answer at the same time through the file checkpoint
|
|
70
73
|
(`<runtime>/asks` + `<runtime>/answers`); the first answer wins and the
|
|
71
|
-
prompt
|
|
74
|
+
prompt prints `✓ answered elsewhere (allowed)` or `✗ answered elsewhere (<reason>)` when the proxy decides. A write that fails prints `✗ not sent (<code>), try again:` with the same question, and the next line typed retries; the hold also stays open for another terminal or its deadline:
|
|
72
75
|
|
|
73
76
|
```bash
|
|
74
77
|
npx sbx pending --name docs-bot
|
|
@@ -80,7 +83,7 @@ SBX_RUNTIME=/tmp/sbx npx sbx approve h1
|
|
|
80
83
|
SBX_RUNTIME=/tmp/sbx npx sbx deny h2 "reason here"
|
|
81
84
|
```
|
|
82
85
|
|
|
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
|
|
86
|
+
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 when a terminal is attached and denies after 180 s without one (`--hold <seconds|never>` or `holdTimeoutSec` overrides either):
|
|
84
87
|
time spent in line and reading the body counts too, and a request past its
|
|
85
88
|
deadline is denied `hold timeout` whether waiting, sending, or parked. Each
|
|
86
89
|
agent holds at most one request being read or parked; later ones wait in
|
|
@@ -90,7 +93,7 @@ need the proxy to be alive: with no live proxy on the runtime `sbx pending`,
|
|
|
90
93
|
`approve` and `deny` exit 1 and say so, because nothing would read the answer.
|
|
91
94
|
`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
95
|
|
|
93
|
-
Unattended runs (cron, CI,
|
|
96
|
+
Unattended runs (cron, CI, `--json`, stdin or stderr not a TTY; redirecting only stdout still counts as a terminal): nobody answers on the terminal, so by default a held request is denied after 180 s instead of hanging the run. Pass `--hold <seconds|never>` (or set `holdTimeoutSec`) to change that, with or without a terminal.
|
|
94
97
|
|
|
95
98
|
## One call: `run()` and `sbx run`
|
|
96
99
|
|
|
@@ -124,7 +127,7 @@ Its exit code mirrors the agent's.
|
|
|
124
127
|
|
|
125
128
|
`sbx run` reads one optional config file,
|
|
126
129
|
`${XDG_CONFIG_HOME:-$HOME/.config}/barebox/config.json`, with keys `mode`,
|
|
127
|
-
`holdTimeoutSec` (positive integer or `"never"`;
|
|
130
|
+
`holdTimeoutSec` (positive integer or `"never"`; unset: `"never"` with a terminal, 180 without; overridden per run by `--hold`), `heldBodyMaxMB`
|
|
128
131
|
(positive integer) and `localLlm` (array of `"host:port"`). A flag beats the file, the file beats the default; an
|
|
129
132
|
unknown key, bad value or bad JSON exits 2 naming the file and key. The file
|
|
130
133
|
is hidden inside the sandbox wherever it resolves. The library does not read it.
|
package/package.json
CHANGED
package/src/cli.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
// cwd-relative default.
|
|
8
8
|
//
|
|
9
9
|
// Settings (mode, holdTimeoutSec, heldBodyMaxMB, localLlm) come from the one config file, see config.js;
|
|
10
|
-
// a flag beats the file. A bad file is a usage-class error (exit 2).
|
|
10
|
+
// a flag beats the file, the file beats the default (holdTimeoutSec unset: wait with a terminal, 180 s then deny without). A bad file is a usage-class error (exit 2).
|
|
11
11
|
//
|
|
12
12
|
// With a terminal (stdin and stderr TTYs, no --json) `sbx run` asks each hold in place (prompt.js);
|
|
13
13
|
// `--name <n>` names the sandbox (agent name + runtime dir, runtime.js namedRuntime) and every
|
|
@@ -43,6 +43,8 @@ import { DEFAULT_POLL_MS } from './holds.js';
|
|
|
43
43
|
import { diffOverlay, commitOverlay, rollbackOverlay } from './overlay.js';
|
|
44
44
|
import { assertAgentName, createRuntime, namedRuntime, hostNode, runtimePaths, runtimeLive, safe, shellQuote } from './runtime.js';
|
|
45
45
|
|
|
46
|
+
// Seconds a held request waits when no one is at a terminal and neither --hold nor holdTimeoutSec is set.
|
|
47
|
+
const HOLD_NO_TERMINAL_SEC = 180;
|
|
46
48
|
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)';
|
|
47
49
|
|
|
48
50
|
/** Hold ids the CLI accepts: `h<n>` only. Anything else is a usage error, never a path. */
|
|
@@ -216,7 +218,7 @@ async function run(args) {
|
|
|
216
218
|
usage();
|
|
217
219
|
}
|
|
218
220
|
if (values.mode !== undefined && !MODES.includes(values.mode)) usage();
|
|
219
|
-
/** @type {{ mode: string, holdTimeoutSec
|
|
221
|
+
/** @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[] }> }} */
|
|
220
222
|
let cfg;
|
|
221
223
|
try {
|
|
222
224
|
cfg = resolveConfig({ mode: values.mode, hold: values.hold });
|
|
@@ -233,9 +235,14 @@ async function run(args) {
|
|
|
233
235
|
err(e instanceof Error ? e.message : String(e));
|
|
234
236
|
process.exit(2);
|
|
235
237
|
}
|
|
236
|
-
const timeoutMs = cfg.holdTimeoutSec === 'never' ? 'never' : Number(cfg.holdTimeoutSec) * 1000;
|
|
237
238
|
if (!command.length) usage();
|
|
238
239
|
const json = values.json ?? false;
|
|
240
|
+
// A person at this terminal (stdin and stderr are TTYs, not --json) answers
|
|
241
|
+
// holds here; the file channel stays on, so `sbx approve` still works too.
|
|
242
|
+
const interactive = !json && !!process.stdin.isTTY && !!process.stderr.isTTY;
|
|
243
|
+
// No --hold and no holdTimeoutSec: wait for the person at a terminal, else deny after 180 s.
|
|
244
|
+
const hold = cfg.holdTimeoutSec ?? (interactive ? 'never' : HOLD_NO_TERMINAL_SEC);
|
|
245
|
+
const timeoutMs = hold === 'never' ? 'never' : Number(hold) * 1000;
|
|
239
246
|
const overlay = values.overlay ?? false;
|
|
240
247
|
const name = values.name;
|
|
241
248
|
if (name !== undefined) {
|
|
@@ -250,10 +257,8 @@ async function run(args) {
|
|
|
250
257
|
for (const k of keys) if (c[k] != null) c[k] = safe(c[k]);
|
|
251
258
|
return c;
|
|
252
259
|
};
|
|
253
|
-
// A person at this terminal (stdin and stderr are TTYs, not --json) answers
|
|
254
|
-
// holds here; the file channel stays on, so `sbx approve` still works too.
|
|
255
260
|
const errColor = !!process.stderr.isTTY && !process.env.NO_COLOR;
|
|
256
|
-
const prompt =
|
|
261
|
+
const prompt = interactive
|
|
257
262
|
? createTerminalPrompt({
|
|
258
263
|
input: process.stdin,
|
|
259
264
|
output: process.stderr,
|
|
@@ -261,13 +266,15 @@ async function run(args) {
|
|
|
261
266
|
answer: (id, decision, reason) => writeAnswer(runtimePaths(runtime), id, decision, reason),
|
|
262
267
|
})
|
|
263
268
|
: null;
|
|
269
|
+
const prompted = new Set(); // holds the prompt showed: their answer is shown there too
|
|
264
270
|
const emitAsk = (h) => {
|
|
265
|
-
if (prompt?.ask(h)) return;
|
|
271
|
+
if (prompt?.ask(h)) { prompted.add(h.id); return; }
|
|
266
272
|
const c = clean(h, ['id', 'agent', 'method', 'url', 'rule', 'bodyPreview']);
|
|
267
273
|
if (json) out(JSON.stringify({ ev: 'ask', ...c }));
|
|
268
274
|
else out(`ask ${c.id} ${c.agent} ${c.method} ${c.url} rule=${c.rule}`);
|
|
269
275
|
};
|
|
270
276
|
const emitDecided = (e) => {
|
|
277
|
+
if (!json && prompted.delete(e.id)) return;
|
|
271
278
|
const c = clean(e, ['id', 'decision', 'reason']);
|
|
272
279
|
if (json) out(JSON.stringify({ ev: 'decided', id: c.id, decision: c.decision, reason: c.reason }));
|
|
273
280
|
else out(`decided ${c.id} ${c.decision}${c.reason ? ` (${c.reason})` : ''}`);
|
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',
|
|
10
|
+
const DEFAULTS = { mode: 'auto', 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) => {
|
|
@@ -97,7 +97,7 @@ export function configPath(env = process.env) {
|
|
|
97
97
|
* Read the config file over the defaults. No file means defaults.
|
|
98
98
|
*
|
|
99
99
|
* @param {NodeJS.ProcessEnv} [env] environment to read (default `process.env`)
|
|
100
|
-
* @returns {{ mode: string, holdTimeoutSec
|
|
100
|
+
* @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)
|
|
101
101
|
* @throws {Error} naming the file (and the key) on invalid JSON, an unknown key or a bad value
|
|
102
102
|
*/
|
|
103
103
|
export function loadConfig(env = process.env) {
|
|
@@ -139,7 +139,7 @@ export function loadConfig(env = process.env) {
|
|
|
139
139
|
* @param {string} [flags.mode] `--mode`
|
|
140
140
|
* @param {string} [flags.hold] `--hold` (`"never"` or a positive integer of seconds, as typed)
|
|
141
141
|
* @param {NodeJS.ProcessEnv} [env] environment to read (default `process.env`)
|
|
142
|
-
* @returns {{ mode: string, holdTimeoutSec
|
|
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)
|
|
143
143
|
* @throws {Error} as {@link loadConfig}
|
|
144
144
|
*/
|
|
145
145
|
export function resolveConfig(flags = {}, env = process.env) {
|
package/src/prompt.js
CHANGED
|
@@ -71,40 +71,67 @@ export function questionLines(ask, now = Date.now(), color = false) {
|
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
/**
|
|
74
|
-
* The terminal prompt.
|
|
75
|
-
* and returns true, or returns false when
|
|
76
|
-
* is
|
|
77
|
-
*
|
|
74
|
+
* The terminal prompt. It owns one hold from its question to the proxy's
|
|
75
|
+
* verdict. `ask()` opens a question and returns true, or returns false when a
|
|
76
|
+
* hold is still current (asking or awaiting its verdict) or the prompt is
|
|
77
|
+
* closed, so the caller prints the plain `ask` line instead; `decided()`
|
|
78
|
+
* ends the current hold with its outcome line, `close()` releases
|
|
78
79
|
* `input`.
|
|
79
80
|
*
|
|
80
81
|
* @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
|
|
81
82
|
* @returns {{ ask: (ask: AskRecord) => boolean, decided: (e: { id: string, decision: string, reason?: string }) => void, close: () => void }} the prompt
|
|
82
83
|
*/
|
|
83
84
|
export function createTerminalPrompt({ input, output, answer, color = false }) {
|
|
84
|
-
/**
|
|
85
|
-
|
|
85
|
+
/** The one hold this prompt owns, from its question to the proxy's verdict. `typedYes`: true/false once our answer was written, null when another answer won, undefined while still asking.
|
|
86
|
+
* @type {{ ask: AskRecord, state: 'asking'|'sent', typedYes?: boolean|null }|null} */
|
|
87
|
+
let current = null;
|
|
86
88
|
let buf = '';
|
|
87
89
|
let closed = false;
|
|
88
90
|
const say = (/** @type {string} */ s) => { output.write(`${s}\n`); };
|
|
89
91
|
|
|
92
|
+
// The one place that words an outcome. `typedYes` is true/false when our
|
|
93
|
+
// typed answer was written (✓/✗ allowed/denied only when the proxy's verdict
|
|
94
|
+
// matches it), undefined/null when nothing of ours was sent.
|
|
95
|
+
const outcome = (/** @type {{ decision: string, reason?: string }} */ e, /** @type {boolean|null|undefined} */ typedYes) => {
|
|
96
|
+
const why = safe(e.reason);
|
|
97
|
+
return typedYes === true && e.decision === 'allow' ? paint(color, ANSI.green + ANSI.bold, '✓ allowed')
|
|
98
|
+
: typedYes === false && e.decision === 'deny' && why === 'denied at the terminal' ? paint(color, ANSI.red + ANSI.bold, '✗ denied')
|
|
99
|
+
: why === 'hold timeout' ? paint(color, ANSI.red, '✗ timed out (denied)')
|
|
100
|
+
: why === 'client gone' ? paint(color, ANSI.red, '✗ agent gone (denied)')
|
|
101
|
+
: why === 'proxy closing' ? paint(color, ANSI.red, '✗ sandbox closed (denied)')
|
|
102
|
+
: e.decision === 'allow' ? '✓ answered elsewhere (allowed)'
|
|
103
|
+
: `✗ answered elsewhere (${why || 'denied'})`;
|
|
104
|
+
};
|
|
105
|
+
|
|
90
106
|
const onLine = (/** @type {string} */ line) => {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
open = null; // closed before the write: one answer per question
|
|
107
|
+
const hold = current;
|
|
108
|
+
if (!hold || hold.state !== 'asking') return; // unreachable at runtime (onData checks); narrows the type for tsc
|
|
94
109
|
const yes = YES.has(line.trim().toLowerCase());
|
|
110
|
+
let written = false;
|
|
95
111
|
try {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
//
|
|
112
|
+
written = answer(hold.ask.id, yes ? 'allow' : 'deny', yes ? undefined : 'denied at the terminal') !== false;
|
|
113
|
+
} catch (e) {
|
|
114
|
+
// The write failed (disk full, runtime gone, ...); the run goes on and the
|
|
115
|
+
// hold stays open and asking: the next line retries. Say so at once:
|
|
116
|
+
// nothing else would, and a hold with no timeout would wait on a blank
|
|
117
|
+
// line. Never the message: it may hold a path.
|
|
118
|
+
const code = e && typeof e === 'object' && 'code' in e && typeof e.code === 'string' ? e.code : 'error';
|
|
119
|
+
const question = questionLines(hold.ask, Date.now(), color).at(-1)?.trimStart();
|
|
120
|
+
say(`${paint(color, ANSI.red, `✗ not sent (${safe(code)}), try again:`)} ${question}`);
|
|
121
|
+
return;
|
|
101
122
|
}
|
|
123
|
+
// The receipt is instant; the verdict is appended by `decided` once the proxy
|
|
124
|
+
// has read the file (it may still time the hold out first). A lost write
|
|
125
|
+
// (another answer won) prints nothing now, but its `decided` still words the outcome.
|
|
126
|
+
hold.state = 'sent';
|
|
127
|
+
hold.typedYes = written ? yes : null;
|
|
128
|
+
if (written) output.write(`${paint(color, ANSI.dim, '→ sent')} `);
|
|
102
129
|
};
|
|
103
130
|
|
|
104
131
|
const onData = (/** @type {string|Buffer} */ chunk) => {
|
|
105
|
-
if (
|
|
132
|
+
if (current?.state !== 'asking') return;
|
|
106
133
|
buf += String(chunk);
|
|
107
|
-
for (let m = EOL.exec(buf); m &&
|
|
134
|
+
for (let m = EOL.exec(buf); m && current?.state === 'asking'; m = EOL.exec(buf)) {
|
|
108
135
|
const line = buf.slice(0, m.index);
|
|
109
136
|
buf = buf.slice(m.index + m[0].length);
|
|
110
137
|
onLine(line);
|
|
@@ -116,23 +143,21 @@ export function createTerminalPrompt({ input, output, answer, color = false }) {
|
|
|
116
143
|
|
|
117
144
|
return {
|
|
118
145
|
ask(ask) {
|
|
119
|
-
if (closed ||
|
|
120
|
-
|
|
146
|
+
if (closed || current) return false;
|
|
147
|
+
current = { ask, state: 'asking' };
|
|
121
148
|
buf = ''; // a half-typed line from before the question is stale
|
|
122
|
-
for (const l of questionLines(
|
|
149
|
+
for (const l of questionLines(ask, Date.now(), color)) say(l);
|
|
123
150
|
return true;
|
|
124
151
|
},
|
|
125
152
|
decided(e) {
|
|
126
|
-
if (
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
say(
|
|
130
|
-
: why === 'client gone' || why === 'proxy closing' ? paint(color, ANSI.red, `agent gone: ${safe(e.decision)}`)
|
|
131
|
-
: `answered elsewhere: ${safe(e.decision)}${why ? ` (${why})` : ''}`);
|
|
153
|
+
if (current?.ask.id !== e.id) return;
|
|
154
|
+
const typedYes = current.typedYes;
|
|
155
|
+
current = null; // closed before anything else: no answer can follow
|
|
156
|
+
say(outcome(e, typedYes));
|
|
132
157
|
},
|
|
133
158
|
close() {
|
|
134
159
|
closed = true;
|
|
135
|
-
|
|
160
|
+
current = null;
|
|
136
161
|
input.removeListener('data', onData);
|
|
137
162
|
input.pause();
|
|
138
163
|
},
|
package/types/config.d.ts
CHANGED
|
@@ -9,12 +9,12 @@ export function configPath(env?: NodeJS.ProcessEnv): string;
|
|
|
9
9
|
* Read the config file over the defaults. No file means defaults.
|
|
10
10
|
*
|
|
11
11
|
* @param {NodeJS.ProcessEnv} [env] environment to read (default `process.env`)
|
|
12
|
-
* @returns {{ mode: string, holdTimeoutSec
|
|
12
|
+
* @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)
|
|
13
13
|
* @throws {Error} naming the file (and the key) on invalid JSON, an unknown key or a bad value
|
|
14
14
|
*/
|
|
15
15
|
export function loadConfig(env?: NodeJS.ProcessEnv): {
|
|
16
16
|
mode: string;
|
|
17
|
-
holdTimeoutSec
|
|
17
|
+
holdTimeoutSec?: number | string;
|
|
18
18
|
localLlm: string[];
|
|
19
19
|
labels: string[];
|
|
20
20
|
tenants: Record<string, string[]>;
|
|
@@ -36,7 +36,7 @@ export function loadConfig(env?: NodeJS.ProcessEnv): {
|
|
|
36
36
|
* @param {string} [flags.mode] `--mode`
|
|
37
37
|
* @param {string} [flags.hold] `--hold` (`"never"` or a positive integer of seconds, as typed)
|
|
38
38
|
* @param {NodeJS.ProcessEnv} [env] environment to read (default `process.env`)
|
|
39
|
-
* @returns {{ mode: string, holdTimeoutSec
|
|
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)
|
|
40
40
|
* @throws {Error} as {@link loadConfig}
|
|
41
41
|
*/
|
|
42
42
|
export function resolveConfig(flags?: {
|
|
@@ -44,7 +44,7 @@ export function resolveConfig(flags?: {
|
|
|
44
44
|
hold?: string | undefined;
|
|
45
45
|
}, env?: NodeJS.ProcessEnv): {
|
|
46
46
|
mode: string;
|
|
47
|
-
holdTimeoutSec
|
|
47
|
+
holdTimeoutSec?: number | string;
|
|
48
48
|
localLlm: string[];
|
|
49
49
|
labels: string[];
|
|
50
50
|
tenants: Record<string, string[]>;
|
package/types/prompt.d.ts
CHANGED
|
@@ -10,10 +10,11 @@
|
|
|
10
10
|
*/
|
|
11
11
|
export function questionLines(ask: AskRecord, now?: number, color?: boolean): string[];
|
|
12
12
|
/**
|
|
13
|
-
* The terminal prompt.
|
|
14
|
-
* and returns true, or returns false when
|
|
15
|
-
* is
|
|
16
|
-
*
|
|
13
|
+
* The terminal prompt. It owns one hold from its question to the proxy's
|
|
14
|
+
* verdict. `ask()` opens a question and returns true, or returns false when a
|
|
15
|
+
* hold is still current (asking or awaiting its verdict) or the prompt is
|
|
16
|
+
* closed, so the caller prints the plain `ask` line instead; `decided()`
|
|
17
|
+
* ends the current hold with its outcome line, `close()` releases
|
|
17
18
|
* `input`.
|
|
18
19
|
*
|
|
19
20
|
* @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
|