barebox 0.13.0 → 0.15.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 +22 -0
- package/README.md +58 -127
- package/barebox.context.md +32 -4
- package/package.json +1 -1
- package/primitives.json +1 -1
- package/src/cli.js +20 -10
- package/src/config.js +21 -2
- package/src/holds.js +63 -20
- package/src/launcher.js +1 -1
- package/src/lists.js +1 -1
- package/src/policy.js +5 -1
- package/src/prompt.js +39 -2
- package/src/proxy.js +330 -44
- package/src/run.js +10 -4
- package/types/config.d.ts +12 -2
- package/types/holds.d.ts +24 -4
- package/types/lists.d.ts +1 -0
- package/types/policy.d.ts +2 -0
- package/types/prompt.d.ts +19 -1
- package/types/proxy.d.ts +17 -3
- package/types/run.d.ts +21 -2
package/types/config.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ 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?: number|string, localLlm: string[], labels: string[], tenants: Record<string, string[]>, heldBodyMaxMB?: number, floor?: { pay?: string[], send?: string[] }, env?: { pass?: string[], set?: Record<string, string> }, secrets?: Record<string, { fromEnv?: string, value?: string, hosts: string[] }> }} effective settings (`heldBodyMaxMB` absent means the library default)
|
|
12
|
+
* @returns {{ mode: string, holdTimeoutSec?: number|string, localLlm: string[], labels: string[], tenants: Record<string, string[]>, heldBodyMaxMB?: number, floor?: { pay?: string[], send?: string[] }, hosts?: { allow?: string[], deny?: string[], unknown?: 'ask'|'deny' }, 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): {
|
|
@@ -23,6 +23,11 @@ export function loadConfig(env?: NodeJS.ProcessEnv): {
|
|
|
23
23
|
pay?: string[];
|
|
24
24
|
send?: string[];
|
|
25
25
|
};
|
|
26
|
+
hosts?: {
|
|
27
|
+
allow?: string[];
|
|
28
|
+
deny?: string[];
|
|
29
|
+
unknown?: "ask" | "deny";
|
|
30
|
+
};
|
|
26
31
|
env?: {
|
|
27
32
|
pass?: string[];
|
|
28
33
|
set?: Record<string, string>;
|
|
@@ -40,7 +45,7 @@ export function loadConfig(env?: NodeJS.ProcessEnv): {
|
|
|
40
45
|
* @param {string} [flags.mode] `--mode`
|
|
41
46
|
* @param {string} [flags.hold] `--hold` (`"never"` or a positive integer of seconds, as typed)
|
|
42
47
|
* @param {NodeJS.ProcessEnv} [env] environment to read (default `process.env`)
|
|
43
|
-
* @returns {{ mode: string, holdTimeoutSec?: number|string, localLlm: string[], labels: string[], tenants: Record<string, string[]>, heldBodyMaxMB?: number, floor?: { pay?: string[], send?: string[] }, env?: { pass?: string[], set?: Record<string, string> }, secrets?: Record<string, { fromEnv?: string, value?: string, hosts: string[] }> }} effective settings (`heldBodyMaxMB` absent means the library default)
|
|
48
|
+
* @returns {{ mode: string, holdTimeoutSec?: number|string, localLlm: string[], labels: string[], tenants: Record<string, string[]>, heldBodyMaxMB?: number, floor?: { pay?: string[], send?: string[] }, hosts?: { allow?: string[], deny?: string[], unknown?: 'ask'|'deny' }, env?: { pass?: string[], set?: Record<string, string> }, secrets?: Record<string, { fromEnv?: string, value?: string, hosts: string[] }> }} effective settings (`heldBodyMaxMB` absent means the library default)
|
|
44
49
|
* @throws {Error} as {@link loadConfig}
|
|
45
50
|
*/
|
|
46
51
|
export function resolveConfig(flags?: {
|
|
@@ -57,6 +62,11 @@ export function resolveConfig(flags?: {
|
|
|
57
62
|
pay?: string[];
|
|
58
63
|
send?: string[];
|
|
59
64
|
};
|
|
65
|
+
hosts?: {
|
|
66
|
+
allow?: string[];
|
|
67
|
+
deny?: string[];
|
|
68
|
+
unknown?: "ask" | "deny";
|
|
69
|
+
};
|
|
60
70
|
env?: {
|
|
61
71
|
pass?: string[];
|
|
62
72
|
set?: Record<string, string>;
|
package/types/holds.d.ts
CHANGED
|
@@ -46,6 +46,8 @@ export function bodyPreview(head: Buffer): string;
|
|
|
46
46
|
* @property {boolean} truncated true when the body exceeded ASK_BODY_LIMIT
|
|
47
47
|
* @property {{ kind: 'pay'|'send'|string, entry: string }} [floor] present when the request hit a domain the user listed in config `floor` (kind: which list, entry: the matching entry)
|
|
48
48
|
* @property {import('./effect.js').Effect} [effect] present on a floor request with a body: the recipient, amount and currency fields found in it (values masked for card numbers), or why it was not read
|
|
49
|
+
* @property {string} [keyLast4] present on a model call whose key is not this run's: the key's last 4 characters (never more)
|
|
50
|
+
* @property {'none'|'other'} [modelKey] present on a model call whose key is not this run's: 'none' (no key header) or 'other' (a key, possibly too short for a last 4)
|
|
49
51
|
* @property {number} waitingSec 0 at park; readers use the file mtime for a live value
|
|
50
52
|
* @property {string|null} expiresAt ISO-8601 UTC deadline, or null when `timeoutMs: 'never'`
|
|
51
53
|
*/
|
|
@@ -54,6 +56,15 @@ export function bodyPreview(head: Buffer): string;
|
|
|
54
56
|
*
|
|
55
57
|
* @typedef {(ask: AskPayload) => Promise<{ decision: string, reason?: string }>} OnAsk
|
|
56
58
|
*/
|
|
59
|
+
/**
|
|
60
|
+
* Write `text` to a fresh 0600 temp file next to `file` (parent made on demand).
|
|
61
|
+
* The caller renames or links it into place.
|
|
62
|
+
*
|
|
63
|
+
* @param {string} file destination path the temp file sits beside
|
|
64
|
+
* @param {string} text content
|
|
65
|
+
* @returns {string} path of the temp file
|
|
66
|
+
*/
|
|
67
|
+
export function writeTmpFile(file: string, text: string): string;
|
|
57
68
|
/**
|
|
58
69
|
* Atomic write: tmp file + rename, so readers never see a partial payload.
|
|
59
70
|
*
|
|
@@ -99,8 +110,8 @@ export function normalizeDecision(input: {
|
|
|
99
110
|
* @param {number} [opts.pollMs] answer poll interval in ms for the default file checkpoint (default 250, PRD Q9)
|
|
100
111
|
* @param {OnEvent|null} [opts.onEvent] event callback: `{ type: 'ask' }` on park, `{ type: 'decided' }` on settle or abandon
|
|
101
112
|
* @param {(entry: object) => void} opts.onApprove forward the parked request upstream
|
|
102
|
-
* @param {(entry: object, reason: string) => void} opts.onDeny refuse the parked request
|
|
103
|
-
* @returns {{ add: (entry: object) => string|null, dropBody: (id: string) => void, reserve: (agent: string, cbs: { onReady: () => void, onExpire: (reason: string) => void }) => { state: 'now'|'queued'|'full', id: string, arrivedAt: number, cancel: () => void }, abandon: (id: string) => void, abandonSocket: (sock: object) => void, pending: () => HeldRequest[], close: () => void }} queue handle
|
|
113
|
+
* @param {(entry: object, reason: string, answered: boolean, timedOut: boolean) => void} opts.onDeny refuse the parked request; `answered`: a person's answer or the hold timeout ended it (not a cancel, a close or a channel failure); `timedOut`: the hold timeout ended it (so `answered && !timedOut` is a person's answer)
|
|
114
|
+
* @returns {{ add: (entry: object) => string|null, dropBody: (id: string) => void, reserve: (agent: string, cbs: { onReady: () => void, onExpire: (reason: string, answered?: boolean, timedOut?: boolean) => void }) => { state: 'now'|'queued'|'full', id: string, arrivedAt: number, cancel: () => void }, abandon: (id: string) => void, abandonSocket: (sock: object) => void, wait: (agent: string) => (() => void)|null, pending: () => HeldRequest[], close: () => void }} queue handle
|
|
104
115
|
*/
|
|
105
116
|
export function createHolds({ log, timeoutMs, maxBody, runtime, onAsk, pollMs, onEvent, onApprove, onDeny }: {
|
|
106
117
|
log: (o: Record<string, unknown>) => void;
|
|
@@ -111,13 +122,13 @@ export function createHolds({ log, timeoutMs, maxBody, runtime, onAsk, pollMs, o
|
|
|
111
122
|
pollMs?: number | undefined;
|
|
112
123
|
onEvent?: OnEvent | null | undefined;
|
|
113
124
|
onApprove: (entry: object) => void;
|
|
114
|
-
onDeny: (entry: object, reason: string) => void;
|
|
125
|
+
onDeny: (entry: object, reason: string, answered: boolean, timedOut: boolean) => void;
|
|
115
126
|
}): {
|
|
116
127
|
add: (entry: object) => string | null;
|
|
117
128
|
dropBody: (id: string) => void;
|
|
118
129
|
reserve: (agent: string, cbs: {
|
|
119
130
|
onReady: () => void;
|
|
120
|
-
onExpire: (reason: string) => void;
|
|
131
|
+
onExpire: (reason: string, answered?: boolean, timedOut?: boolean) => void;
|
|
121
132
|
}) => {
|
|
122
133
|
state: "now" | "queued" | "full";
|
|
123
134
|
id: string;
|
|
@@ -126,6 +137,7 @@ export function createHolds({ log, timeoutMs, maxBody, runtime, onAsk, pollMs, o
|
|
|
126
137
|
};
|
|
127
138
|
abandon: (id: string) => void;
|
|
128
139
|
abandonSocket: (sock: object) => void;
|
|
140
|
+
wait: (agent: string) => (() => void) | null;
|
|
129
141
|
pending: () => HeldRequest[];
|
|
130
142
|
close: () => void;
|
|
131
143
|
};
|
|
@@ -232,6 +244,14 @@ export type AskPayload = {
|
|
|
232
244
|
* present on a floor request with a body: the recipient, amount and currency fields found in it (values masked for card numbers), or why it was not read
|
|
233
245
|
*/
|
|
234
246
|
effect?: import("./effect.js").Effect | undefined;
|
|
247
|
+
/**
|
|
248
|
+
* present on a model call whose key is not this run's: the key's last 4 characters (never more)
|
|
249
|
+
*/
|
|
250
|
+
keyLast4?: string | undefined;
|
|
251
|
+
/**
|
|
252
|
+
* present on a model call whose key is not this run's: 'none' (no key header) or 'other' (a key, possibly too short for a last 4)
|
|
253
|
+
*/
|
|
254
|
+
modelKey?: "none" | "other" | undefined;
|
|
235
255
|
/**
|
|
236
256
|
* 0 at park; readers use the file mtime for a live value
|
|
237
257
|
*/
|
package/types/lists.d.ts
CHANGED
package/types/policy.d.ts
CHANGED
|
@@ -78,6 +78,8 @@ export function gateFor({ agent, mode, auditPath, humanChannel, tools }: {
|
|
|
78
78
|
}): Promise<Gate>;
|
|
79
79
|
/** The mode names, in the order the CLI and config list them. */
|
|
80
80
|
export const MODES: string[];
|
|
81
|
+
/** Hosts of the built-in model endpoints: never a first-contact host ask (M14). */
|
|
82
|
+
export const MODEL_HOSTS: Set<string>;
|
|
81
83
|
/** The matcher used when no label files are loaded: every request is request-only. */
|
|
82
84
|
export const emptyMatcher: {
|
|
83
85
|
match: (method: string, url: string) => import("rwxmap/match").MatchResult;
|
package/types/prompt.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** @typedef {{ id: string, agent?: string, method: string, url: string, rule: string, letter: string, bodyPreview?: string, expiresAt?: string|null, floor?: { kind: string, entry: string }, effect?: import('./effect.js').Effect }} AskRecord */
|
|
1
|
+
/** @typedef {{ id: string, agent?: string, method: string, url: string, rule: string, letter: string, bodyPreview?: string, expiresAt?: string|null, floor?: { kind: string, entry: string }, effect?: import('./effect.js').Effect, keyLast4?: string, modelKey?: 'none'|'other' }} AskRecord */
|
|
2
2
|
/**
|
|
3
3
|
* The `To:` / `Amount:` / `Currency:` lines of a floor request, or one `Effect:` line saying why none was read.
|
|
4
4
|
* Up to LIST_MAX fields are all listed; more than that lists none (too many to tell the real one).
|
|
@@ -8,6 +8,15 @@
|
|
|
8
8
|
* @returns {string[]} zero or more lines
|
|
9
9
|
*/
|
|
10
10
|
export function effectLines(effect: AskRecord["effect"], color: boolean): string[];
|
|
11
|
+
/**
|
|
12
|
+
* The URL of an ask, sanitized. For a first-contact host ask (`flags.newHost`) everything after the
|
|
13
|
+
* scheme (userinfo, host, path and query) has card numbers masked, then is cut to 200 characters and the
|
|
14
|
+
* full length is added, so a long URL is visible but bounded. The question's header line shows the true host.
|
|
15
|
+
*
|
|
16
|
+
* @param {AskRecord} ask the parked request
|
|
17
|
+
* @returns {string} the URL text, safe for a terminal
|
|
18
|
+
*/
|
|
19
|
+
export function askUrl(ask: AskRecord): string;
|
|
11
20
|
/**
|
|
12
21
|
* The ` floor=<kind> entry=<entry>` tail of a one-line ask (`sbx pending`, the non-terminal `ask` line); empty without a floor hit.
|
|
13
22
|
*
|
|
@@ -15,6 +24,13 @@ export function effectLines(effect: AskRecord["effect"], color: boolean): string
|
|
|
15
24
|
* @returns {string} the tail, or ''
|
|
16
25
|
*/
|
|
17
26
|
export function floorTail(ask: AskRecord): string;
|
|
27
|
+
/**
|
|
28
|
+
* The ` key=…<last 4>` tail of a one-line ask (`sbx pending`, the non-terminal `ask` line); ` key=none` or ` key=other` when there is no last 4 to show; empty unless the ask is a model call with another key.
|
|
29
|
+
*
|
|
30
|
+
* @param {AskRecord} ask the parked request
|
|
31
|
+
* @returns {string} the tail, or ''
|
|
32
|
+
*/
|
|
33
|
+
export function keyTail(ask: AskRecord): string;
|
|
18
34
|
/**
|
|
19
35
|
* Plain-language lines for one ask record. Every agent-controlled byte goes
|
|
20
36
|
* through `safe()`.
|
|
@@ -77,4 +93,6 @@ export type AskRecord = {
|
|
|
77
93
|
entry: string;
|
|
78
94
|
};
|
|
79
95
|
effect?: import("./effect.js").Effect;
|
|
96
|
+
keyLast4?: string;
|
|
97
|
+
modelKey?: "none" | "other";
|
|
80
98
|
};
|
package/types/proxy.d.ts
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
* @property {{ matcher: { match: (method: string, url: string) => { key: string, source: string } }, tools: Record<string, any> }} [labels] the loaded label files (see `loadLabels`); omitted means no labels, only the built-in model endpoints
|
|
11
11
|
* @property {string[]} [allowLocal] exact `host:port` pairs (the `localLlm` setting) that may pass the wall's private/loopback check; any other local destination is still denied
|
|
12
12
|
* @property {{ pay?: string[], send?: string[] }} [floor] the config `floor` key (M11): a write to a listed host or `*.domain`, or a request matching a listed `"METHOD host/path"`, asks in every mode (the gate flag `floor`); the question shows the recipient, amount and currency found in the body. Omitted means no floor lists.
|
|
13
|
+
* @property {{ allow?: string[], deny?: string[], unknown?: 'ask' | 'deny' | 'allow' }} [hosts] M14: `deny` hosts (exact or `*.domain`) are refused before DNS in every mode; `allow` hosts never get the first-contact ask; any other host follows `unknown`: `'ask'` asks once per host (allow for this run, or deny), `'deny'` refuses it at once, `'allow'` (the default here) lets it through. Model endpoint hosts, each secret's hosts and the `allowLocal` hosts are never asked. Needs `gateFor` for `'ask'`; without it `'ask'` refuses.
|
|
13
14
|
* @property {HoldOptions} [hold] hold queue config (deadline, caps, ask seam)
|
|
14
15
|
* @property {number} [upstreamTimeoutMs] give up on an upstream response after this (default 120000)
|
|
15
16
|
* @property {object} [unsafeTestOnly] TEST-ONLY escape hatch: everything under
|
|
@@ -21,7 +22,7 @@
|
|
|
21
22
|
* DNS stub: replaces the wall's resolver so rebinding is testable. Production omits it.
|
|
22
23
|
* @property {import('./secrets.js').Secret[]} [secrets] the loaded secrets (`loadSecrets`): a request carrying a secret's placeholder in a header gets the real value there only after the gate allowed it and only for a bound host; for any other host it is refused `403 denied: secret.host`. The value never reaches the audit file, an ask or an error body.
|
|
23
24
|
* @property {number} [clientIdleMs] kill a client tunnel idle this long; never fires mid-request (default 60000)
|
|
24
|
-
* @property {(entry: Record<string, unknown>) => Record<string, unknown>} [redact] log redaction hook, applied after built-in secret scrubbing; its result becomes the `meta` of an `annotate` line (default: identity)
|
|
25
|
+
* @property {(entry: Record<string, unknown>) => Record<string, unknown>} [redact] log redaction hook, applied after built-in secret scrubbing; its result becomes the `meta` of an `annotate` line, and the `url` it sees already has userinfo and card numbers masked (default: identity)
|
|
25
26
|
*/
|
|
26
27
|
/**
|
|
27
28
|
* Anything with bareguard's `check`: a `Gate`, or a plain object for tests. An
|
|
@@ -61,7 +62,7 @@
|
|
|
61
62
|
* @typedef {ReturnType<typeof createProxy>} Proxy
|
|
62
63
|
*/
|
|
63
64
|
/**
|
|
64
|
-
* Start the front-door proxy. Every request is audited with its method and URL, and a request with a body also with its byte count and SHA-256 (never headers or body text); bytes go upstream untouched. Requests the hold rule
|
|
65
|
+
* Start the front-door proxy. Every request is audited with its method and URL, and a request with a body also with its byte count and SHA-256 (never headers or body text); barebox's own audit lines mask userinfo and card numbers in the URL, the gate's decision lines keep it as sent; bytes go upstream untouched. Requests the hold rule
|
|
65
66
|
* flags park for a human decision instead of forwarding.
|
|
66
67
|
*
|
|
67
68
|
* @param {ProxyOptions} opts
|
|
@@ -82,6 +83,11 @@ export function createProxy(opts: ProxyOptions): {
|
|
|
82
83
|
addAgent: (name: any) => string;
|
|
83
84
|
removeAgent: (name: any) => void;
|
|
84
85
|
pending: () => import("./holds.js").HeldRequest[];
|
|
86
|
+
/** M14: hosts a person allowed this run, and hosts refused by `unknown: 'deny'`; each sorted and unique. @returns {{ allowed: string[], refused: string[] }} */
|
|
87
|
+
hostsReport: () => {
|
|
88
|
+
allowed: string[];
|
|
89
|
+
refused: string[];
|
|
90
|
+
};
|
|
85
91
|
readonly caFile: string;
|
|
86
92
|
};
|
|
87
93
|
/**
|
|
@@ -137,6 +143,14 @@ export type ProxyOptions = {
|
|
|
137
143
|
pay?: string[];
|
|
138
144
|
send?: string[];
|
|
139
145
|
} | undefined;
|
|
146
|
+
/**
|
|
147
|
+
* M14: `deny` hosts (exact or `*.domain`) are refused before DNS in every mode; `allow` hosts never get the first-contact ask; any other host follows `unknown`: `'ask'` asks once per host (allow for this run, or deny), `'deny'` refuses it at once, `'allow'` (the default here) lets it through. Model endpoint hosts, each secret's hosts and the `allowLocal` hosts are never asked. Needs `gateFor` for `'ask'`; without it `'ask'` refuses.
|
|
148
|
+
*/
|
|
149
|
+
hosts?: {
|
|
150
|
+
allow?: string[];
|
|
151
|
+
deny?: string[];
|
|
152
|
+
unknown?: "ask" | "deny" | "allow";
|
|
153
|
+
} | undefined;
|
|
140
154
|
/**
|
|
141
155
|
* hold queue config (deadline, caps, ask seam)
|
|
142
156
|
*/
|
|
@@ -170,7 +184,7 @@ export type ProxyOptions = {
|
|
|
170
184
|
*/
|
|
171
185
|
clientIdleMs?: number | undefined;
|
|
172
186
|
/**
|
|
173
|
-
* log redaction hook, applied after built-in secret scrubbing; its result becomes the `meta` of an `annotate` line (default: identity)
|
|
187
|
+
* log redaction hook, applied after built-in secret scrubbing; its result becomes the `meta` of an `annotate` line, and the `url` it sees already has userinfo and card numbers masked (default: identity)
|
|
174
188
|
*/
|
|
175
189
|
redact?: ((entry: Record<string, unknown>) => Record<string, unknown>) | undefined;
|
|
176
190
|
};
|
package/types/run.d.ts
CHANGED
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
* @property {{ matcher: any, tools: Record<string, any>, dirs?: string[] }} [labels] the loaded label files (`loadLabels`); their folders are masked from the sandbox
|
|
31
31
|
* @property {string[]} [allowLocal] exact `host:port` pairs (for example a local model server) that may pass the wall's private/loopback check (the `localLlm` setting)
|
|
32
32
|
* @property {{ pay?: string[], send?: string[] }} [floor] the config `floor` key (M11): hosts, `*.domain` or `"METHOD host/path"` entries that ask in every mode, `trust` included (see `createProxy`)
|
|
33
|
+
* @property {{ allow?: string[], deny?: string[], unknown?: 'ask'|'deny' }} [hosts] the config `hosts` key (M14): `deny` hosts are refused before DNS in every mode; `allow` hosts never get the first-contact ask; any other host asks once (`unknown` `ask`, the default) or is refused (`deny`). `trust` lets other hosts through, a `deny` host still refused (see `createProxy`)
|
|
33
34
|
* @property {object} [unsafeTestOnly] TEST-ONLY escape hatch, forwarded to the proxy (see `createProxy`): everything under it weakens the sandbox wall
|
|
34
35
|
* @property {NodeJS.WritableStream} [stdout] where the agent's stdout goes (default process.stdout)
|
|
35
36
|
* @property {NodeJS.WritableStream} [stderr] where the agent's stderr goes (default process.stderr)
|
|
@@ -54,6 +55,7 @@
|
|
|
54
55
|
* @param {{ matcher: any, tools: Record<string, any>, dirs?: string[] }|null} [opts.labels] the loaded label files (`loadLabels`); their folders are masked from the sandbox
|
|
55
56
|
* @param {string[]} [opts.allowLocal] exact `host:port` pairs (for example a local model server) that may pass the wall's private/loopback check (the `localLlm` setting)
|
|
56
57
|
* @param {{ pay?: string[], send?: string[] }|null} [opts.floor] the config `floor` key (M11): hosts, `*.domain` or `"METHOD host/path"` entries that ask in every mode, `trust` included (see `createProxy`)
|
|
58
|
+
* @param {{ allow?: string[], deny?: string[], unknown?: 'ask'|'deny' }|null} [opts.hosts] the config `hosts` key (M14); see {@link RunOptions}
|
|
57
59
|
* @param {object|null} [opts.unsafeTestOnly] TEST-ONLY escape hatch, forwarded to the proxy (see `createProxy`)
|
|
58
60
|
* @param {NodeJS.WritableStream|null} [opts.stdout] where the agent's stdout goes (default process.stdout)
|
|
59
61
|
* @param {NodeJS.WritableStream|null} [opts.stderr] where the agent's stderr goes (default process.stderr)
|
|
@@ -61,14 +63,14 @@
|
|
|
61
63
|
* @param {{ pass?: string[], set?: Record<string, string> }|null} [opts.env] the sandbox's environment (M5), the config `env` shape; see {@link RunOptions}
|
|
62
64
|
* @param {boolean} [opts.overlay] when true, mount a per-run overlay upper over the project instead of binding it read-only; the result's `diff` lists the run's changes for commit/rollback
|
|
63
65
|
* @param {string[]} [opts.overlayIgnore] path segments invisible to the overlay (default `node_modules`; see overlay.js Q3)
|
|
64
|
-
* @returns {Promise<{ exit: number, asks: AskRecord[], audit: string, diff: import('./overlay.js').OverlayChange[], runtime: string }>} the agent process exit code, the collected ask records, the JSONL audit log path, the run's overlay diff (M4),
|
|
66
|
+
* @returns {Promise<{ exit: number, asks: AskRecord[], audit: string, diff: import('./overlay.js').OverlayChange[], runtime: string, hosts: { allowed: string[], refused: string[] } }>} the agent process exit code, the collected ask records, the JSONL audit log path, the run's overlay diff (M4), the runtime dir addressing it, and the hosts a person allowed or `unknown: 'deny'` refused (M14)
|
|
65
67
|
* @when Reach for this to HARNESS-ONLY run one sandboxed agent start-to-finish in a single call: it starts the proxy, sandboxes the command, answers holds, and returns the exit code with the ask and audit trail (plus the overlay diff once M4 exists).
|
|
66
68
|
* @fails Rejects on a missing/unreadable `proj`, an empty `command`, a bad `mode`, a misshapen `onAsk`, a `secrets` entry with no value (a `fromEnv` variable missing from this process's environment; the message names the secret, never a value), a proxy that never becomes ready, a `launch` that throws (uncommitted overlay changes, a runtime inside the project — the proxy is closed first), or an overlay diff that cannot be read. The agent's own nonzero exit is returned as `exit`, never thrown.
|
|
67
69
|
* @example
|
|
68
70
|
* import { run } from "barebox";
|
|
69
71
|
* const { exit, asks, audit } = await run({ proj: "/tmp/proj", command: ["bash", "-c", "echo hi"] });
|
|
70
72
|
*/
|
|
71
|
-
export function run({ proj, command, mode, onAsk, onEvent, runtime, agent, timeoutMs, heldBodyMaxBytes, allowLocal, floor, labels, unsafeTestOnly, stdout, stderr, overlay, overlayIgnore, secrets, env }: {
|
|
73
|
+
export function run({ proj, command, mode, onAsk, onEvent, runtime, agent, timeoutMs, heldBodyMaxBytes, allowLocal, floor, hosts, labels, unsafeTestOnly, stdout, stderr, overlay, overlayIgnore, secrets, env }: {
|
|
72
74
|
proj: string;
|
|
73
75
|
command: string[];
|
|
74
76
|
mode?: string | undefined;
|
|
@@ -88,6 +90,11 @@ export function run({ proj, command, mode, onAsk, onEvent, runtime, agent, timeo
|
|
|
88
90
|
pay?: string[];
|
|
89
91
|
send?: string[];
|
|
90
92
|
} | null | undefined;
|
|
93
|
+
hosts?: {
|
|
94
|
+
allow?: string[];
|
|
95
|
+
deny?: string[];
|
|
96
|
+
unknown?: "ask" | "deny";
|
|
97
|
+
} | null | undefined;
|
|
91
98
|
unsafeTestOnly?: object | null;
|
|
92
99
|
stdout?: NodeJS.WritableStream | null | undefined;
|
|
93
100
|
stderr?: NodeJS.WritableStream | null | undefined;
|
|
@@ -108,6 +115,10 @@ export function run({ proj, command, mode, onAsk, onEvent, runtime, agent, timeo
|
|
|
108
115
|
audit: string;
|
|
109
116
|
diff: import("./overlay.js").OverlayChange[];
|
|
110
117
|
runtime: string;
|
|
118
|
+
hosts: {
|
|
119
|
+
allowed: string[];
|
|
120
|
+
refused: string[];
|
|
121
|
+
};
|
|
111
122
|
}>;
|
|
112
123
|
/**
|
|
113
124
|
* A collected ask record: the parked ask plus how it was decided.
|
|
@@ -217,6 +228,14 @@ export type RunOptions = {
|
|
|
217
228
|
pay?: string[];
|
|
218
229
|
send?: string[];
|
|
219
230
|
} | undefined;
|
|
231
|
+
/**
|
|
232
|
+
* the config `hosts` key (M14): `deny` hosts are refused before DNS in every mode; `allow` hosts never get the first-contact ask; any other host asks once (`unknown` `ask`, the default) or is refused (`deny`). `trust` lets other hosts through, a `deny` host still refused (see `createProxy`)
|
|
233
|
+
*/
|
|
234
|
+
hosts?: {
|
|
235
|
+
allow?: string[];
|
|
236
|
+
deny?: string[];
|
|
237
|
+
unknown?: "ask" | "deny";
|
|
238
|
+
} | undefined;
|
|
220
239
|
/**
|
|
221
240
|
* TEST-ONLY escape hatch, forwarded to the proxy (see `createProxy`): everything under it weakens the sandbox wall
|
|
222
241
|
*/
|