@plimsollmark/client 0.22.0 → 0.24.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/README.md +5 -4
- package/dist/client.d.ts +14 -5
- package/dist/client.js +16 -11
- package/dist/errors.d.ts +6 -4
- package/dist/errors.js +48 -26
- package/dist/record.d.ts +11 -9
- package/dist/record.js +107 -51
- package/dist/sandboxes.js +10 -7
- package/dist/tables.gen.d.ts +13 -0
- package/dist/tables.gen.js +44 -0
- package/dist/wire.d.ts +13 -0
- package/dist/wire.js +17 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -11,7 +11,8 @@ protocol over `fetch` and keeps the promises the Go client keeps:
|
|
|
11
11
|
|
|
12
12
|
- it states the protocol number on every request;
|
|
13
13
|
- it checks every answer's **run record**: it recomputes the request and result digests
|
|
14
|
-
from what it sent and received ([run-records.md](https://github.com/plimsollmark/plimsoll/blob/main/docs/run-records.md)),
|
|
14
|
+
from what it sent and received ([run-records.md](https://github.com/plimsollmark/plimsoll/blob/main/docs/run-records.md)), refuses a
|
|
15
|
+
result of another kind than the request's and a record that ends before it starts, and an
|
|
15
16
|
answer that does not check, or has no record, is a `data_loss` error with the result
|
|
16
17
|
attached, because the code may have run;
|
|
17
18
|
- it checks the reported isolation tier against the caller's floor the same way;
|
|
@@ -74,7 +75,7 @@ directory, before the code runs. Its result adds `interpreterStarted` (this call
|
|
|
74
75
|
a fresh interpreter, so nothing defined earlier exists) and `interpreterEnded`; its exit code
|
|
75
76
|
is 0 when the code ran, 1 when it raised and 124 at the deadline. Python needs `python3` in
|
|
76
77
|
the daemon's image (`plimsoll/sandbox-python` has it, with NumPy and SciPy);
|
|
77
|
-
`describe()` lists the languages
|
|
78
|
+
`describe()` lists the languages a session's cells run in on `sessionEnvironment.languages`.
|
|
78
79
|
|
|
79
80
|
`close()` sends one `CloseSession` however many times it is called, and every later call
|
|
80
81
|
gets the first one's summary or error: the daemon forgets a session at its first close and
|
|
@@ -238,7 +239,7 @@ for the three properties together.
|
|
|
238
239
|
|
|
239
240
|
The model sees only a run record's digest (`recordSha256`). The record itself, checked by
|
|
240
241
|
the client, goes to `onRecord(record, key)`, once for every call that ran: an answered call's,
|
|
241
|
-
and the
|
|
242
|
+
and the record a session call that may have run carries on its error (no result, the error's code). That is where an
|
|
242
243
|
application keeps receipts (a store, or a signer such as plimsoll's `attest` harness); a refusal
|
|
243
244
|
calls nothing, since nothing ran. An `onRecord` that throws, or returns a promise that rejects, is
|
|
244
245
|
logged and never changes the result the model gets.
|
|
@@ -253,7 +254,7 @@ object for a pair). Without `onCloseError`, a `console.warn` names the key only
|
|
|
253
254
|
another's, never by its IDs, because a key can hold a user's ID (an email address, in some
|
|
254
255
|
apps). An `onCloseError` that throws, or returns a promise that rejects, is logged the same
|
|
255
256
|
way: an app's reporting never stops a close, or the open that waited for one to make room. A call that may have run but ended in an error comes with its record
|
|
256
|
-
(`PlimsollError.unanswered`, a
|
|
257
|
+
(`PlimsollError.unanswered`, a record with no result and the error's code); the session checks it, hands it back as
|
|
257
258
|
`PlimsollError.record`, keeps it in its chain and goes on, and so does the conversation's
|
|
258
259
|
sandbox. A call whose answer never arrived carries none, so the client sends nothing more
|
|
259
260
|
on that session (`Session.stopped` says why), and the conversation's next call opens a new
|
package/dist/client.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { type RunRecord } from "./record.ts";
|
|
2
|
+
import { LANGUAGES, OUTCOME_NAMES, TIERS } from "./tables.gen.ts";
|
|
2
3
|
import { type SessionEnd } from "./errors.ts";
|
|
3
4
|
import type { WireCellRun, WireEnvelope, WireOpenSessionResponse, WireSoftwareRule } from "./wire.ts";
|
|
4
5
|
/** The wire protocol number this client speaks (protocol.Number in Go). */
|
|
5
|
-
export declare const PROTOCOL =
|
|
6
|
+
export declare const PROTOCOL = 4;
|
|
6
7
|
/** How strong the boundary is, weakest first. */
|
|
7
|
-
export type Isolation =
|
|
8
|
+
export type Isolation = (typeof TIERS)[number];
|
|
8
9
|
/** Whether a tier the daemon reported meets a floor. An unknown tier meets nothing. */
|
|
9
10
|
export declare function meets(actual: string, floor: Isolation): boolean;
|
|
10
11
|
/** A caller's rule for the selected software: one exact identity, or 1 to 32 approved ones. */
|
|
@@ -23,7 +24,12 @@ export type ClientOptions = {
|
|
|
23
24
|
javascriptGrantProfile?: string;
|
|
24
25
|
/** Named server-side grant profile for projects. */
|
|
25
26
|
projectGrantProfile?: string;
|
|
26
|
-
/**
|
|
27
|
+
/**
|
|
28
|
+
* A fetch implementation; defaults to the global one. It must not retry a request: a
|
|
29
|
+
* retried call can run twice. A failure through a fetch given here is never marked
|
|
30
|
+
* not dispatched, since its error describes only the last attempt it made, and an
|
|
31
|
+
* earlier one may have delivered the code.
|
|
32
|
+
*/
|
|
27
33
|
fetch?: typeof fetch;
|
|
28
34
|
/**
|
|
29
35
|
* Bounds each HTTP exchange, sending and reading the answer, in milliseconds.
|
|
@@ -48,6 +54,8 @@ export type Evidence = {
|
|
|
48
54
|
isolation: string;
|
|
49
55
|
softwareIdentity: string;
|
|
50
56
|
environment: string;
|
|
57
|
+
/** The sandbox instance that ran it, as a typed reference (`k8s-pod-uid:` and a pod's UID), or "" when the provider names none. */
|
|
58
|
+
instance: string;
|
|
51
59
|
durationMs: number;
|
|
52
60
|
/** The checked run record. */
|
|
53
61
|
record: RunRecord;
|
|
@@ -88,7 +96,7 @@ export type ProjectRequest = {
|
|
|
88
96
|
/** Relative paths to capture and return. */
|
|
89
97
|
artifacts?: string[];
|
|
90
98
|
};
|
|
91
|
-
export type ProjectOutcome =
|
|
99
|
+
export type ProjectOutcome = (typeof OUTCOME_NAMES)[number];
|
|
92
100
|
export type StepResult = {
|
|
93
101
|
command: string;
|
|
94
102
|
stdout: string;
|
|
@@ -111,7 +119,7 @@ export type ProjectResult = Evidence & {
|
|
|
111
119
|
advice: AdviceFinding[];
|
|
112
120
|
};
|
|
113
121
|
/** An interpreter language: a cell's, and one an environment states. */
|
|
114
|
-
export type Language =
|
|
122
|
+
export type Language = (typeof LANGUAGES)[number];
|
|
115
123
|
/**
|
|
116
124
|
* Where one payload kind runs. languages are the interpreters the daemon's startup
|
|
117
125
|
* checks proved: what a project's steps can invoke, and in a session what a cell may use.
|
|
@@ -244,6 +252,7 @@ export declare class PlimsollClient {
|
|
|
244
252
|
private readonly base;
|
|
245
253
|
private readonly token;
|
|
246
254
|
private readonly fetchImpl;
|
|
255
|
+
private readonly ownFetch;
|
|
247
256
|
private readonly requestTimeoutMs;
|
|
248
257
|
/** @internal */ readonly jsGrant: string;
|
|
249
258
|
/** @internal */ readonly projectGrant: string;
|
package/dist/client.js
CHANGED
|
@@ -7,14 +7,15 @@
|
|
|
7
7
|
import { createHash, createHmac, randomBytes } from "node:crypto";
|
|
8
8
|
import { isIP } from "node:net";
|
|
9
9
|
import { checkRecord, checkUnanswered, requestDigest, sessionFingerprint, softwareRuleAllows, } from "./record.js";
|
|
10
|
+
import { LANGUAGES, OUTCOME_NAMES, TIERS } from "./tables.gen.js";
|
|
10
11
|
import { errorFromWire, NOT_DISPATCHED_HEADER, PlimsollError, REQUEST_ID_HEADER, sessionEndFromWire, unboundSuccess } from "./errors.js";
|
|
12
|
+
import { wireBytes } from "./wire.js";
|
|
11
13
|
/** The wire protocol number this client speaks (protocol.Number in Go). */
|
|
12
|
-
export const PROTOCOL =
|
|
14
|
+
export const PROTOCOL = 4;
|
|
13
15
|
const SERVICE = "plimsoll.v1.SandboxService";
|
|
14
16
|
// Above the largest legitimate project response, so a misbehaving daemon cannot
|
|
15
17
|
// make the client buffer without bound (the Go client's maxResponseBytes).
|
|
16
18
|
const MAX_RESPONSE_BYTES = 32 << 20;
|
|
17
|
-
const TIERS = ["none", "process", "container", "kernel", "vm"];
|
|
18
19
|
/** Whether a tier the daemon reported meets a floor. An unknown tier meets nothing. */
|
|
19
20
|
export function meets(actual, floor) {
|
|
20
21
|
const a = TIERS.indexOf(actual);
|
|
@@ -98,7 +99,7 @@ function mergeRules(a, b) {
|
|
|
98
99
|
return { mode: ids.length === 1 ? "exact" : "approved", identities: ids };
|
|
99
100
|
}
|
|
100
101
|
const num = (v) => Number(v ?? 0);
|
|
101
|
-
const bytes = (s) => new Uint8Array(
|
|
102
|
+
const bytes = (s) => new Uint8Array(wireBytes(s));
|
|
102
103
|
const text = (b) => Buffer.from(b).toString("utf8");
|
|
103
104
|
function adviceFromWire(a) {
|
|
104
105
|
return (a ?? []).map((f) => ({
|
|
@@ -121,6 +122,7 @@ function evidence(resp, record) {
|
|
|
121
122
|
isolation: resp.isolation ?? "",
|
|
122
123
|
softwareIdentity: resp.softwareIdentity ?? "",
|
|
123
124
|
environment: resp.environment ?? "",
|
|
125
|
+
instance: resp.instance ?? "",
|
|
124
126
|
durationMs: num(resp.durationMs),
|
|
125
127
|
record,
|
|
126
128
|
};
|
|
@@ -143,11 +145,10 @@ function javascriptResult(resp, record) {
|
|
|
143
145
|
};
|
|
144
146
|
}
|
|
145
147
|
function outcomeFromWire(v) {
|
|
146
|
-
const names = ["unspecified", "completed", "setup_failed", "timed_out", "protocol_error"];
|
|
147
148
|
if (typeof v === "number")
|
|
148
|
-
return
|
|
149
|
+
return OUTCOME_NAMES[v] ?? "unspecified";
|
|
149
150
|
const name = (v ?? "").replace(/^PROJECT_OUTCOME_/, "").toLowerCase();
|
|
150
|
-
return
|
|
151
|
+
return OUTCOME_NAMES.includes(name) ? name : "unspecified";
|
|
151
152
|
}
|
|
152
153
|
function projectResult(resp, record) {
|
|
153
154
|
const p = resp.project ?? {};
|
|
@@ -242,6 +243,9 @@ export class PlimsollClient {
|
|
|
242
243
|
base;
|
|
243
244
|
token;
|
|
244
245
|
fetchImpl;
|
|
246
|
+
// Only Node's own fetch, which makes one attempt per POST, has errors that prove a
|
|
247
|
+
// request unsent.
|
|
248
|
+
ownFetch;
|
|
245
249
|
requestTimeoutMs;
|
|
246
250
|
/** @internal */ jsGrant;
|
|
247
251
|
/** @internal */ projectGrant;
|
|
@@ -249,6 +253,7 @@ export class PlimsollClient {
|
|
|
249
253
|
this.base = validateBaseUrl(opts.baseUrl, opts.insecureHttp ?? false);
|
|
250
254
|
this.token = opts.token;
|
|
251
255
|
this.fetchImpl = opts.fetch ?? fetch;
|
|
256
|
+
this.ownFetch = opts.fetch === undefined;
|
|
252
257
|
const rt = opts.requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS;
|
|
253
258
|
if (typeof rt !== "number" || !(rt > 0) || rt > 2 ** 31 - 1) {
|
|
254
259
|
throw new PlimsollError("invalid_argument", "plimsoll: requestTimeoutMs must be a positive number of milliseconds");
|
|
@@ -288,7 +293,7 @@ export class PlimsollClient {
|
|
|
288
293
|
}
|
|
289
294
|
catch (e) {
|
|
290
295
|
throw cut(e) ?? new PlimsollError("unavailable", `plimsoll: ${e.message}`, {
|
|
291
|
-
cause: e, notDispatched: fetchDidNotSend(e) ? "environment" : undefined,
|
|
296
|
+
cause: e, notDispatched: this.ownFetch && fetchDidNotSend(e) ? "environment" : undefined,
|
|
292
297
|
});
|
|
293
298
|
}
|
|
294
299
|
if (res.type === "opaqueredirect" || (res.status >= 300 && res.status < 400)) {
|
|
@@ -433,7 +438,7 @@ export class PlimsollClient {
|
|
|
433
438
|
return decoded(() => this.checked(env, payload, resp));
|
|
434
439
|
}
|
|
435
440
|
checked(env, payload, resp) {
|
|
436
|
-
const checked = checkRecord(requestDigest({ protocol: env.protocol, minimumIsolation: env.minimumIsolation ?? "", timeoutMs: env.timeoutMs ?? 0, softwareRule: env.softwareRule, payload: digestPayload(payload) }),
|
|
441
|
+
const checked = checkRecord(requestDigest({ protocol: env.protocol, minimumIsolation: env.minimumIsolation ?? "", timeoutMs: env.timeoutMs ?? 0, softwareRule: env.softwareRule, payload: digestPayload(payload) }), "javascript" in payload ? "javascript" : "project" in payload ? "project" : "cell", env.softwareRule, resp);
|
|
437
442
|
if ("problem" in checked)
|
|
438
443
|
throw new PlimsollError("data_loss", `plimsoll: ${checked.problem}`, { result: resp });
|
|
439
444
|
const r = checked.record;
|
|
@@ -621,16 +626,16 @@ export class Session {
|
|
|
621
626
|
this.#end = e.sessionEnded;
|
|
622
627
|
throw e;
|
|
623
628
|
}
|
|
624
|
-
return decoded(() => this.#chained(m, env, rule, digest));
|
|
629
|
+
return decoded(() => this.#chained(m, env, rule, digest, "javascript" in payload ? "javascript" : "project" in payload ? "project" : "cell"));
|
|
625
630
|
}
|
|
626
|
-
#chained(m, env, rule, digest) {
|
|
631
|
+
#chained(m, env, rule, digest, kind) {
|
|
627
632
|
const run = m.run;
|
|
628
633
|
if (!run)
|
|
629
634
|
throw new PlimsollError("data_loss", "plimsoll: the session call's answer carries no run");
|
|
630
635
|
const end = sessionEndFromWire(m.ended);
|
|
631
636
|
if (end !== "open")
|
|
632
637
|
this.#end = { reason: end, detail: m.endDetail ?? "" };
|
|
633
|
-
const checked = checkRecord(digest,
|
|
638
|
+
const checked = checkRecord(digest, kind, rule, run);
|
|
634
639
|
if ("problem" in checked)
|
|
635
640
|
throw new PlimsollError("data_loss", `plimsoll: ${checked.problem}`, { result: run });
|
|
636
641
|
const r = checked.record;
|
package/dist/errors.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import type { RunRecord } from "./record.ts";
|
|
2
|
-
import
|
|
2
|
+
import { REFUSAL_NAMES, SESSION_END_NAMES } from "./tables.gen.ts";
|
|
3
|
+
import { type WireError, type WireRecord } from "./wire.ts";
|
|
3
4
|
/** Why a request was refused before any code ran (plimsoll.v1.NotDispatchedReason). */
|
|
4
|
-
export type Refusal =
|
|
5
|
+
export type Refusal = (typeof REFUSAL_NAMES)[number];
|
|
5
6
|
/**
|
|
6
7
|
* Why a session ended (plimsoll.v1.SessionEnd), "open" while it has not. "unknown" is
|
|
7
8
|
* an end this client has no name for (a daemon newer than the client): the session
|
|
8
9
|
* ended, for a reason it cannot name.
|
|
9
10
|
*/
|
|
10
|
-
export type SessionEnd =
|
|
11
|
+
export type SessionEnd = (typeof SESSION_END_NAMES)[number] | "unknown";
|
|
11
12
|
/**
|
|
12
13
|
* Connect's status codes, plus the two this client raises itself:
|
|
13
14
|
* "data_loss" for an answer that does not check (the run may have executed),
|
|
@@ -35,8 +36,9 @@ export declare class PlimsollError extends Error {
|
|
|
35
36
|
readonly result: unknown;
|
|
36
37
|
/**
|
|
37
38
|
* The record the daemon sends with a session call that may have run but ended in
|
|
38
|
-
* an error (
|
|
39
|
+
* an error (an unanswered record, as it came off the wire). The Session checks it
|
|
39
40
|
* and keeps it in its chain, so the session goes on; the call's outcome is unknown.
|
|
41
|
+
* On a single run's error it is kept as it came and checked by nothing.
|
|
40
42
|
*/
|
|
41
43
|
readonly unanswered: WireRecord | undefined;
|
|
42
44
|
/**
|
package/dist/errors.js
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
// anything ran. A refusal raised before dispatch carries the NotDispatched detail
|
|
3
3
|
// and comes back with notDispatched set; anything else may have followed
|
|
4
4
|
// execution and is never a safe automatic retry (docs/run-results.md).
|
|
5
|
+
import { REFUSAL_NAMES, SESSION_END_NAMES } from "./tables.gen.js";
|
|
6
|
+
import { wireBytes } from "./wire.js";
|
|
5
7
|
export class PlimsollError extends Error {
|
|
6
8
|
code;
|
|
7
9
|
/**
|
|
@@ -20,8 +22,9 @@ export class PlimsollError extends Error {
|
|
|
20
22
|
result;
|
|
21
23
|
/**
|
|
22
24
|
* The record the daemon sends with a session call that may have run but ended in
|
|
23
|
-
* an error (
|
|
25
|
+
* an error (an unanswered record, as it came off the wire). The Session checks it
|
|
24
26
|
* and keeps it in its chain, so the session goes on; the call's outcome is unknown.
|
|
27
|
+
* On a single run's error it is kept as it came and checked by nothing.
|
|
25
28
|
*/
|
|
26
29
|
unanswered;
|
|
27
30
|
/**
|
|
@@ -57,20 +60,6 @@ const NOT_BOUND = "the answer does not carry this request's Plimsoll-Request-Id
|
|
|
57
60
|
export function unboundSuccess(method) {
|
|
58
61
|
return new PlimsollError("data_loss", `plimsoll: ${method}: ${NOT_BOUND}; the call may have run`, { answerNotBound: true });
|
|
59
62
|
}
|
|
60
|
-
const REFUSALS = ["unknown", "request", "permission", "protocol", "unsupported", "isolation", "capacity", "environment"];
|
|
61
|
-
const SESSION_ENDS = [
|
|
62
|
-
"open",
|
|
63
|
-
"closed",
|
|
64
|
-
"expired",
|
|
65
|
-
"disk_exceeded",
|
|
66
|
-
"main_process_ended",
|
|
67
|
-
"boundary_failed",
|
|
68
|
-
"sandbox_changed",
|
|
69
|
-
"shutdown",
|
|
70
|
-
"replaced",
|
|
71
|
-
"not_found",
|
|
72
|
-
"unclaimed",
|
|
73
|
-
];
|
|
74
63
|
// Only an absent or unspecified end means open. Any other value says the session
|
|
75
64
|
// ended, so one this client has no name for is "unknown", never "open": read as open,
|
|
76
65
|
// an ended session would be reported as still holding its state and files. The
|
|
@@ -79,11 +68,11 @@ export function sessionEndFromWire(v) {
|
|
|
79
68
|
if (v === undefined || v === 0)
|
|
80
69
|
return "open";
|
|
81
70
|
if (typeof v === "number")
|
|
82
|
-
return
|
|
71
|
+
return SESSION_END_NAMES[v] ?? "unknown";
|
|
83
72
|
const name = v.replace(/^SESSION_END_/, "").toLowerCase();
|
|
84
73
|
if (name === "unspecified")
|
|
85
74
|
return "open";
|
|
86
|
-
return name !== "open" && name !== "unknown" &&
|
|
75
|
+
return name !== "open" && name !== "unknown" && SESSION_END_NAMES.includes(name) ? name : "unknown";
|
|
87
76
|
}
|
|
88
77
|
// Reads one varint at b[i]; returns [value, next index].
|
|
89
78
|
function varint(b, i) {
|
|
@@ -122,6 +111,14 @@ function decodeDetail(b) {
|
|
|
122
111
|
detail = Buffer.from(b.subarray(k, k + n)).toString("utf8");
|
|
123
112
|
i = k + n;
|
|
124
113
|
}
|
|
114
|
+
else if (wire === 1 || wire === 5) {
|
|
115
|
+
// A fixed-width field this client does not know is skipped, as Go and Python skip
|
|
116
|
+
// it, so a newer daemon's extra field does not cost a refusal its mark (review B8,
|
|
117
|
+
// 2026-10-23).
|
|
118
|
+
i += wire === 1 ? 8 : 4;
|
|
119
|
+
if (i > b.length)
|
|
120
|
+
throw new Error("bad length");
|
|
121
|
+
}
|
|
125
122
|
else {
|
|
126
123
|
throw new Error("unexpected wire type");
|
|
127
124
|
}
|
|
@@ -142,7 +139,7 @@ function bigVarint(b, i) {
|
|
|
142
139
|
}
|
|
143
140
|
const RECORD_STRINGS = {
|
|
144
141
|
2: "requestSha256", 3: "resultSha256", 4: "provider", 5: "isolation", 6: "environment", 7: "policy",
|
|
145
|
-
10: "session", 12: "previousSha256", 13: "recordSha256", 14: "softwareIdentity", 15: "softwareRuleId", 16: "unanswered",
|
|
142
|
+
10: "session", 12: "previousSha256", 13: "recordSha256", 14: "softwareIdentity", 15: "softwareRuleId", 16: "unanswered", 17: "instance",
|
|
146
143
|
};
|
|
147
144
|
// Decodes an UnansweredCall detail (field 1, a RunRecord) by hand, into the record's
|
|
148
145
|
// proto3 JSON form, so the record checks exactly as one read off a JSON answer.
|
|
@@ -150,12 +147,37 @@ function decodeUnanswered(b) {
|
|
|
150
147
|
let rec;
|
|
151
148
|
for (let i = 0; i < b.length;) {
|
|
152
149
|
const [tag, j] = varint(b, i);
|
|
153
|
-
const
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
150
|
+
const field = tag >>> 3;
|
|
151
|
+
const wire = tag & 7;
|
|
152
|
+
if (field === 1) {
|
|
153
|
+
if (wire !== 2)
|
|
154
|
+
throw new Error("UnansweredCall.record is not length-delimited");
|
|
155
|
+
const [n, k] = varint(b, j);
|
|
156
|
+
if (k + n > b.length)
|
|
157
|
+
throw new Error("bad detail");
|
|
157
158
|
rec = decodeRecord(b.subarray(k, k + n));
|
|
158
|
-
|
|
159
|
+
i = k + n;
|
|
160
|
+
}
|
|
161
|
+
else if (wire === 0) {
|
|
162
|
+
// A field this client does not know is skipped by its wire type, as Go and Python
|
|
163
|
+
// skip it; every field used to be read as length-delimited, so a scalar a newer
|
|
164
|
+
// daemon adds dropped the record and stopped the session (review, 2026-10-26).
|
|
165
|
+
i = varint(b, j)[1];
|
|
166
|
+
}
|
|
167
|
+
else if (wire === 2) {
|
|
168
|
+
const [n, k] = varint(b, j);
|
|
169
|
+
if (k + n > b.length)
|
|
170
|
+
throw new Error("bad detail");
|
|
171
|
+
i = k + n;
|
|
172
|
+
}
|
|
173
|
+
else if (wire === 1 || wire === 5) {
|
|
174
|
+
i = j + (wire === 1 ? 8 : 4);
|
|
175
|
+
if (i > b.length)
|
|
176
|
+
throw new Error("bad detail");
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
throw new Error("unexpected wire type");
|
|
180
|
+
}
|
|
159
181
|
}
|
|
160
182
|
return rec;
|
|
161
183
|
}
|
|
@@ -219,9 +241,9 @@ export function errorFromWire(httpStatus, body, answer) {
|
|
|
219
241
|
let unanswered;
|
|
220
242
|
for (const d of Array.isArray(wire?.details) ? wire.details : []) {
|
|
221
243
|
try {
|
|
222
|
-
const bytes =
|
|
244
|
+
const bytes = wireBytes(d.value);
|
|
223
245
|
if (d.type === "plimsoll.v1.NotDispatched") {
|
|
224
|
-
notDispatched =
|
|
246
|
+
notDispatched = REFUSAL_NAMES[decodeDetail(bytes).reason] ?? "unknown";
|
|
225
247
|
}
|
|
226
248
|
else if (d.type === "plimsoll.v1.SessionEnded") {
|
|
227
249
|
// The detail itself says the session ended, so an unspecified reason is not "open".
|
|
@@ -238,7 +260,7 @@ export function errorFromWire(httpStatus, body, answer) {
|
|
|
238
260
|
}
|
|
239
261
|
}
|
|
240
262
|
if (notDispatched === undefined && answer.mark) {
|
|
241
|
-
const named =
|
|
263
|
+
const named = REFUSAL_NAMES.find((r) => r !== "unknown" && r === answer.mark);
|
|
242
264
|
if (named)
|
|
243
265
|
notDispatched = named;
|
|
244
266
|
}
|
package/dist/record.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type
|
|
2
|
-
/** The record encoding version
|
|
3
|
-
export declare const RECORD_VERSION =
|
|
4
|
-
/**
|
|
5
|
-
export declare
|
|
1
|
+
import { type WireRecord, type WireRunResponse, type WireSoftwareRule } from "./wire.ts";
|
|
2
|
+
/** The record encoding version this client computes and checks: every field, every time, for an answered call and an unanswered session call alike. */
|
|
3
|
+
export declare const RECORD_VERSION = 4;
|
|
4
|
+
/** A record's instance: "" (the provider names none) or a typed reference such as `k8s-pod-uid:` and a pod's UID. */
|
|
5
|
+
export declare function validInstance(s: string): boolean;
|
|
6
6
|
/** The payload of a request as the digest sees it. */
|
|
7
7
|
export type DigestPayload = {
|
|
8
8
|
kind: "javascript";
|
|
@@ -55,12 +55,14 @@ export type RunRecord = {
|
|
|
55
55
|
session: string;
|
|
56
56
|
sequence: bigint;
|
|
57
57
|
previousSha256: string;
|
|
58
|
-
/** On
|
|
58
|
+
/** On an unanswered call's record, the Connect code a session call that may have run ended with. */
|
|
59
59
|
unanswered: string;
|
|
60
|
+
/** The sandbox instance that ran the call, as the response states it, or "". */
|
|
61
|
+
instance: string;
|
|
60
62
|
sha256: string;
|
|
61
63
|
};
|
|
62
64
|
export declare function recordFromWire(m: WireRecord): RunRecord;
|
|
63
|
-
/** A record's own digest, over every field but its digest. */
|
|
65
|
+
/** A record's own digest, over the fields its version covers (every field but its digest for an unknown version). */
|
|
64
66
|
export declare function recordDigest(r: RunRecord): string;
|
|
65
67
|
/** The SHA-256 of a session ID: what a session call's record carries instead of the ID. */
|
|
66
68
|
export declare function sessionFingerprint(sessionId: string): string;
|
|
@@ -72,7 +74,7 @@ export declare function softwareRuleId(rule: WireSoftwareRule | undefined): stri
|
|
|
72
74
|
export declare function softwareRuleAllows(rule: WireSoftwareRule | undefined, identity: string): boolean;
|
|
73
75
|
/**
|
|
74
76
|
* Checks the record the daemon sends with an unanswered session call's error
|
|
75
|
-
* (record.CheckUnanswered): version
|
|
77
|
+
* (record.CheckUnanswered): the version, no result digest, a Connect code, the digest of
|
|
76
78
|
* the request sent, its software rule and that its software is in it, its own digest,
|
|
77
79
|
* its tier against the call's floor, and its place in the chain.
|
|
78
80
|
* Returns the reason it does not check, or the record.
|
|
@@ -87,7 +89,7 @@ export declare function checkUnanswered(reqDigest: string, floor: string, rule:
|
|
|
87
89
|
* both digests, the evidence the response repeats, the software rule and the
|
|
88
90
|
* record's own digest. Returns the reason it does not check, or undefined.
|
|
89
91
|
*/
|
|
90
|
-
export declare function checkRecord(reqDigest: string,
|
|
92
|
+
export declare function checkRecord(reqDigest: string, kind: "javascript" | "project" | "cell", rule: WireSoftwareRule | undefined, resp: WireRunResponse): {
|
|
91
93
|
record: RunRecord;
|
|
92
94
|
} | {
|
|
93
95
|
problem: string;
|
package/dist/record.js
CHANGED
|
@@ -3,10 +3,15 @@
|
|
|
3
3
|
// The golden vectors in record/record_test.go are checked in test/record.test.ts.
|
|
4
4
|
import { createHash } from "node:crypto";
|
|
5
5
|
import { PlimsollError } from "./errors.js";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
/** The record encoding version
|
|
9
|
-
export const
|
|
6
|
+
import { OUTCOMES, TIERS } from "./tables.gen.js";
|
|
7
|
+
import { wireBytes, WireShapeError } from "./wire.js";
|
|
8
|
+
/** The record encoding version this client computes and checks: every field, every time, for an answered call and an unanswered session call alike. */
|
|
9
|
+
export const RECORD_VERSION = 4;
|
|
10
|
+
const INSTANCE_FORM = /^[a-z][a-z0-9-]{0,31}:[A-Za-z0-9._:-]{1,127}$/;
|
|
11
|
+
/** A record's instance: "" (the provider names none) or a typed reference such as `k8s-pod-uid:` and a pod's UID. */
|
|
12
|
+
export function validInstance(s) {
|
|
13
|
+
return s === "" || INSTANCE_FORM.test(s);
|
|
14
|
+
}
|
|
10
15
|
const UNANSWERED_CODES = new Set([
|
|
11
16
|
"canceled", "unknown", "invalid_argument", "deadline_exceeded", "not_found", "already_exists", "permission_denied",
|
|
12
17
|
"resource_exhausted", "failed_precondition", "aborted", "out_of_range", "unimplemented", "internal", "unavailable",
|
|
@@ -53,11 +58,13 @@ class Encoder {
|
|
|
53
58
|
}
|
|
54
59
|
/** The request digest of a Run request or a session call (the same fields). */
|
|
55
60
|
export function requestDigest(r) {
|
|
56
|
-
|
|
61
|
+
// A protocol 1 request (the records of version 1) has the first encoding: no software rule.
|
|
62
|
+
const first = r.protocol < 2;
|
|
63
|
+
const e = new Encoder(first ? "plimsoll.run-request.v1" : "plimsoll.run-request.v2");
|
|
57
64
|
e.int("protocol", r.protocol);
|
|
58
65
|
e.str("minimum_isolation", r.minimumIsolation);
|
|
59
66
|
e.int("timeout_ms", r.timeoutMs);
|
|
60
|
-
if (
|
|
67
|
+
if (!first) {
|
|
61
68
|
const ids = r.softwareRule?.identities ?? [];
|
|
62
69
|
e.str("software_mode", r.softwareRule?.mode ?? "");
|
|
63
70
|
e.int("software_identities", ids.length);
|
|
@@ -95,22 +102,24 @@ export function requestDigest(r) {
|
|
|
95
102
|
}
|
|
96
103
|
return e.sum();
|
|
97
104
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
};
|
|
105
|
+
/**
|
|
106
|
+
* Why a live answer's record version is refused: a newer daemon (upgrade the client) or an
|
|
107
|
+
* older one. A live answer must carry the current version; it is never called forged.
|
|
108
|
+
*/
|
|
109
|
+
function versionProblem(version) {
|
|
110
|
+
return version > RECORD_VERSION
|
|
111
|
+
? `a newer daemon answered with run record version ${version}; this client reads version ${RECORD_VERSION}: upgrade the client`
|
|
112
|
+
: `the daemon answered with run record version ${version}; this client requires version ${RECORD_VERSION} of a live answer`;
|
|
113
|
+
}
|
|
105
114
|
/** The wire enum's number; an unknown name is undefined, which fails the check. */
|
|
106
115
|
export function outcomeNumber(name) {
|
|
107
116
|
if (name === undefined)
|
|
108
117
|
return 0;
|
|
109
118
|
if (typeof name === "number")
|
|
110
119
|
return name;
|
|
111
|
-
return
|
|
120
|
+
return OUTCOMES[name];
|
|
112
121
|
}
|
|
113
|
-
const b64 =
|
|
122
|
+
const b64 = wireBytes;
|
|
114
123
|
/** The result digest of a Run response as it arrived on the wire. */
|
|
115
124
|
export function resultDigest(resp) {
|
|
116
125
|
const e = new Encoder("plimsoll.run-result.v1");
|
|
@@ -161,8 +170,9 @@ export function resultDigest(resp) {
|
|
|
161
170
|
e.bool("interpreter_ended", c.interpreterEnded ?? false);
|
|
162
171
|
}
|
|
163
172
|
else {
|
|
164
|
-
// A module result, or none: this client sends neither, so the
|
|
165
|
-
// refuses the response
|
|
173
|
+
// A module result, or none: this client sends neither, so the record check
|
|
174
|
+
// refuses the response as not of the request's kind, after this digest is
|
|
175
|
+
// computed and found not to match.
|
|
166
176
|
e.str("kind", "");
|
|
167
177
|
}
|
|
168
178
|
return e.sum();
|
|
@@ -194,31 +204,59 @@ export function recordFromWire(m) {
|
|
|
194
204
|
sequence: big(m.sequence, "sequence"),
|
|
195
205
|
previousSha256: m.previousSha256 ?? "",
|
|
196
206
|
unanswered: m.unanswered ?? "",
|
|
207
|
+
instance: m.instance ?? "",
|
|
197
208
|
sha256: m.recordSha256 ?? "",
|
|
198
209
|
};
|
|
199
210
|
}
|
|
200
|
-
/** A record's own digest, over every field but its digest. */
|
|
211
|
+
/** A record's own digest, over the fields its version covers (every field but its digest for an unknown version). */
|
|
201
212
|
export function recordDigest(r) {
|
|
202
213
|
const e = new Encoder(`plimsoll.run-record.v${r.version}`);
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
e.str("environment", r.environment);
|
|
210
|
-
e.str("policy", r.policy);
|
|
211
|
-
if (r.version >= 2) {
|
|
212
|
-
e.str("software_identity", r.softwareIdentity);
|
|
213
|
-
e.str("software_rule_id", r.softwareRuleId);
|
|
214
|
+
for (const name of RECORD_FIELDS[r.version] ?? RECORD_FIELDS[RECORD_VERSION]) {
|
|
215
|
+
const v = recordField(r, name);
|
|
216
|
+
if (typeof v === "string")
|
|
217
|
+
e.str(name, v);
|
|
218
|
+
else
|
|
219
|
+
e.int(name, v);
|
|
214
220
|
}
|
|
215
|
-
e.int("started_unix_ms", r.startedUnixMs);
|
|
216
|
-
e.int("ended_unix_ms", r.endedUnixMs);
|
|
217
|
-
e.str("session", r.session);
|
|
218
|
-
e.int("sequence", r.sequence);
|
|
219
|
-
e.str("previous_sha256", r.previousSha256);
|
|
220
221
|
return e.sum();
|
|
221
222
|
}
|
|
223
|
+
/**
|
|
224
|
+
* The fields of each published record version's digest, in order (record.published): a
|
|
225
|
+
* version leaves this table only by a dated, announced decision.
|
|
226
|
+
*/
|
|
227
|
+
const RECORD_FIELDS = {
|
|
228
|
+
1: ["request_sha256", "result_sha256", "provider", "isolation", "environment", "policy",
|
|
229
|
+
"started_unix_ms", "ended_unix_ms", "session", "sequence", "previous_sha256"],
|
|
230
|
+
2: ["request_sha256", "result_sha256", "provider", "isolation", "environment", "policy",
|
|
231
|
+
"software_identity", "software_rule_id", "started_unix_ms", "ended_unix_ms", "session", "sequence",
|
|
232
|
+
"previous_sha256"],
|
|
233
|
+
3: ["request_sha256", "result_sha256", "unanswered", "provider", "isolation", "environment", "policy",
|
|
234
|
+
"software_identity", "software_rule_id", "started_unix_ms", "ended_unix_ms", "session", "sequence",
|
|
235
|
+
"previous_sha256"],
|
|
236
|
+
4: ["request_sha256", "result_sha256", "unanswered", "provider", "isolation", "environment", "policy",
|
|
237
|
+
"software_identity", "software_rule_id", "instance", "started_unix_ms", "ended_unix_ms", "session",
|
|
238
|
+
"sequence", "previous_sha256"],
|
|
239
|
+
};
|
|
240
|
+
function recordField(r, name) {
|
|
241
|
+
switch (name) {
|
|
242
|
+
case "request_sha256": return r.requestSha256;
|
|
243
|
+
case "result_sha256": return r.resultSha256;
|
|
244
|
+
case "unanswered": return r.unanswered;
|
|
245
|
+
case "provider": return r.provider;
|
|
246
|
+
case "isolation": return r.isolation;
|
|
247
|
+
case "environment": return r.environment;
|
|
248
|
+
case "policy": return r.policy;
|
|
249
|
+
case "software_identity": return r.softwareIdentity;
|
|
250
|
+
case "software_rule_id": return r.softwareRuleId;
|
|
251
|
+
case "instance": return r.instance;
|
|
252
|
+
case "started_unix_ms": return r.startedUnixMs;
|
|
253
|
+
case "ended_unix_ms": return r.endedUnixMs;
|
|
254
|
+
case "session": return r.session;
|
|
255
|
+
case "sequence": return r.sequence;
|
|
256
|
+
case "previous_sha256": return r.previousSha256;
|
|
257
|
+
}
|
|
258
|
+
throw new Error(`no record field ${name}`);
|
|
259
|
+
}
|
|
222
260
|
/** The SHA-256 of a session ID: what a session call's record carries instead of the ID. */
|
|
223
261
|
export function sessionFingerprint(sessionId) {
|
|
224
262
|
return createHash("sha256").update(sessionId, "utf8").digest("hex");
|
|
@@ -241,19 +279,21 @@ export function softwareRuleAllows(rule, identity) {
|
|
|
241
279
|
return true;
|
|
242
280
|
return identity !== "" && rule.identities.includes(identity);
|
|
243
281
|
}
|
|
244
|
-
// The tiers, weakest first
|
|
245
|
-
const TIER_ORDER =
|
|
282
|
+
// The tiers, weakest first (generated, internal/wiretables).
|
|
283
|
+
const TIER_ORDER = TIERS;
|
|
246
284
|
/**
|
|
247
285
|
* Checks the record the daemon sends with an unanswered session call's error
|
|
248
|
-
* (record.CheckUnanswered): version
|
|
286
|
+
* (record.CheckUnanswered): the version, no result digest, a Connect code, the digest of
|
|
249
287
|
* the request sent, its software rule and that its software is in it, its own digest,
|
|
250
288
|
* its tier against the call's floor, and its place in the chain.
|
|
251
289
|
* Returns the reason it does not check, or the record.
|
|
252
290
|
*/
|
|
253
291
|
export function checkUnanswered(reqDigest, floor, rule, m, fingerprint, prevSeq, prev) {
|
|
254
292
|
const r = recordFromWire(m);
|
|
255
|
-
if (r.version !==
|
|
256
|
-
return { problem:
|
|
293
|
+
if (r.version !== RECORD_VERSION)
|
|
294
|
+
return { problem: versionProblem(r.version) };
|
|
295
|
+
if (!validInstance(r.instance))
|
|
296
|
+
return { problem: "the record's instance is not a typed reference" };
|
|
257
297
|
if (r.resultSha256 !== "" || !UNANSWERED_CODES.has(r.unanswered))
|
|
258
298
|
return { problem: "an unanswered call's record states a result or no error code" };
|
|
259
299
|
if (r.requestSha256 !== reqDigest)
|
|
@@ -276,29 +316,45 @@ export function checkUnanswered(reqDigest, floor, rule, m, fingerprint, prevSeq,
|
|
|
276
316
|
* both digests, the evidence the response repeats, the software rule and the
|
|
277
317
|
* record's own digest. Returns the reason it does not check, or undefined.
|
|
278
318
|
*/
|
|
279
|
-
export function checkRecord(reqDigest,
|
|
319
|
+
export function checkRecord(reqDigest, kind, rule, resp) {
|
|
280
320
|
if (!resp.record)
|
|
281
321
|
return { problem: "the response carries no run record" };
|
|
282
322
|
const r = recordFromWire(resp.record);
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
323
|
+
let result;
|
|
324
|
+
try {
|
|
325
|
+
result = resultDigest(resp);
|
|
326
|
+
}
|
|
327
|
+
catch (e) {
|
|
328
|
+
if (e instanceof WireShapeError)
|
|
329
|
+
return { problem: `the answer is malformed: ${e.message}` };
|
|
330
|
+
throw e;
|
|
331
|
+
}
|
|
332
|
+
if (r.version !== RECORD_VERSION)
|
|
333
|
+
return { problem: versionProblem(r.version) };
|
|
290
334
|
if (r.unanswered !== "")
|
|
291
|
-
return { problem:
|
|
335
|
+
return { problem: "an answered call's record states an unanswered code" };
|
|
336
|
+
// The kind, inside the check as in Go's record.check since 2026-10-26: a result of
|
|
337
|
+
// another kind fails here, before a session's chain moves on, so a daemon caught
|
|
338
|
+
// answering the wrong kind is not used further (review, 2026-10-26).
|
|
339
|
+
const kinds = ["javascript", "project", "module", "cell"].filter((k) => resp[k] !== undefined && resp[k] !== null);
|
|
340
|
+
if (kinds.length > 1)
|
|
341
|
+
return { problem: `the answer holds ${kinds.length} results; a run has one` };
|
|
342
|
+
if (kinds.length !== 1 || kinds[0] !== kind)
|
|
343
|
+
return { problem: `the daemon answered a ${kind} request with ${kinds.length === 1 ? kinds[0] : "no"} result` };
|
|
344
|
+
if (r.endedUnixMs < r.startedUnixMs)
|
|
345
|
+
return { problem: "the record ends before it starts" };
|
|
292
346
|
if (r.requestSha256 !== reqDigest)
|
|
293
347
|
return { problem: `request digest ${r.requestSha256}, the request sent digests to ${reqDigest}` };
|
|
294
348
|
if (r.resultSha256 !== result)
|
|
295
349
|
return { problem: `result digest ${r.resultSha256}, the result received digests to ${result}` };
|
|
296
350
|
if (r.provider !== (resp.sandbox ?? "") || r.isolation !== (resp.isolation ?? ""))
|
|
297
351
|
return { problem: "the record's provider or tier differs from the response's" };
|
|
298
|
-
if (r.
|
|
352
|
+
if (r.environment !== (resp.environment ?? ""))
|
|
299
353
|
return { problem: "the record's environment differs from the response's" };
|
|
300
|
-
if (r.
|
|
301
|
-
|
|
354
|
+
if (r.instance !== (resp.instance ?? "") || !validInstance(r.instance)) {
|
|
355
|
+
return { problem: "the record's instance is not the response's, or not a typed reference" };
|
|
356
|
+
}
|
|
357
|
+
if ((r.softwareIdentity !== (resp.softwareIdentity ?? "") || r.softwareRuleId !== softwareRuleId(rule) || !softwareRuleAllows(rule, r.softwareIdentity))) {
|
|
302
358
|
return { problem: "the selected software or admission rule differs from the request and response" };
|
|
303
359
|
}
|
|
304
360
|
if (r.sha256 !== recordDigest(r))
|
package/dist/sandboxes.js
CHANGED
|
@@ -291,16 +291,19 @@ export class CodeSandboxes {
|
|
|
291
291
|
// The Describe is shared with other calls, so an abort stops this call's wait for
|
|
292
292
|
// it, not the Describe.
|
|
293
293
|
const info = await untilAborted(this.#describe(), signal);
|
|
294
|
-
const proved = info.environments.project.languages;
|
|
295
|
-
// A daemon that states no languages predates the statement: let it try.
|
|
296
|
-
if (proved.length > 0 && !proved.includes(language)) {
|
|
297
|
-
throw new PlimsollError("unimplemented", `plimsoll: the sandbox image has no ${language} interpreter (it runs ${proved.join(", ")})`, {
|
|
298
|
-
notDispatched: "unsupported",
|
|
299
|
-
});
|
|
300
|
-
}
|
|
301
294
|
// Without a key there is no conversation to scope a sandbox to, and sharing
|
|
302
295
|
// one across conversations would hand one user's files to another.
|
|
303
296
|
const persistent = key !== undefined && (await untilAborted(this.persistent(), signal));
|
|
297
|
+
// The languages proved where this call will run: the session's image for a kept
|
|
298
|
+
// sandbox, the project image otherwise (a daemon with neither runs JavaScript
|
|
299
|
+
// snippets, which #fresh checks). Every daemon states them (protocol 4), so one that
|
|
300
|
+
// states none proved none and is refused, never let try (review B9, 2026-10-23).
|
|
301
|
+
const env = persistent ? info.sessionEnvironment : info.supportsProject ? info.environments.project : undefined;
|
|
302
|
+
if (env && !env.languages.includes(language)) {
|
|
303
|
+
throw new PlimsollError("unimplemented", `plimsoll: the sandbox image has no ${language} interpreter (it runs ${env.languages.join(", ") || "none"})`, {
|
|
304
|
+
notDispatched: "unsupported",
|
|
305
|
+
});
|
|
306
|
+
}
|
|
304
307
|
return { key, id, info, language, files, persistent };
|
|
305
308
|
});
|
|
306
309
|
const opts = { timeoutMs: this.#opts.timeoutMs, minimumIsolation: this.#floor, signal };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** plimsoll.v1.ProjectOutcome, by number. */
|
|
2
|
+
export declare const OUTCOMES: Readonly<Record<string, number>>;
|
|
3
|
+
export declare const OUTCOME_NAMES: readonly ["unspecified", "completed", "setup_failed", "timed_out", "protocol_error", "runner_failed"];
|
|
4
|
+
/** plimsoll.v1.SessionEnd, by number. */
|
|
5
|
+
export declare const SESSION_ENDS: Readonly<Record<string, number>>;
|
|
6
|
+
export declare const SESSION_END_NAMES: readonly ["open", "closed", "expired", "disk_exceeded", "main_process_ended", "boundary_failed", "sandbox_changed", "shutdown", "replaced", "not_found", "unclaimed"];
|
|
7
|
+
/** plimsoll.v1.NotDispatchedReason, by number. */
|
|
8
|
+
export declare const REFUSALS: Readonly<Record<string, number>>;
|
|
9
|
+
export declare const REFUSAL_NAMES: readonly ["unknown", "request", "permission", "protocol", "unsupported", "isolation", "capacity", "environment"];
|
|
10
|
+
/** Isolation tiers, weakest first (sandbox.IsolationClass). */
|
|
11
|
+
export declare const TIERS: readonly ["none", "process", "container", "kernel", "vm"];
|
|
12
|
+
/** The languages plimsoll keeps an interpreter for (sandbox.Languages). */
|
|
13
|
+
export declare const LANGUAGES: readonly ["javascript", "python"];
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// Code generated by internal/wiretables (make generate). DO NOT EDIT.
|
|
2
|
+
// The protocol's enums and plimsoll's named values, from proto/plimsoll/v1/sandbox.proto
|
|
3
|
+
// and package sandbox, so this client and the Go and Python ones cannot drift apart.
|
|
4
|
+
/** plimsoll.v1.ProjectOutcome, by number. */
|
|
5
|
+
export const OUTCOMES = {
|
|
6
|
+
PROJECT_OUTCOME_UNSPECIFIED: 0,
|
|
7
|
+
PROJECT_OUTCOME_COMPLETED: 1,
|
|
8
|
+
PROJECT_OUTCOME_SETUP_FAILED: 2,
|
|
9
|
+
PROJECT_OUTCOME_TIMED_OUT: 3,
|
|
10
|
+
PROJECT_OUTCOME_PROTOCOL_ERROR: 4,
|
|
11
|
+
PROJECT_OUTCOME_RUNNER_FAILED: 5,
|
|
12
|
+
};
|
|
13
|
+
export const OUTCOME_NAMES = ["unspecified", "completed", "setup_failed", "timed_out", "protocol_error", "runner_failed"];
|
|
14
|
+
/** plimsoll.v1.SessionEnd, by number. */
|
|
15
|
+
export const SESSION_ENDS = {
|
|
16
|
+
SESSION_END_UNSPECIFIED: 0,
|
|
17
|
+
SESSION_END_CLOSED: 1,
|
|
18
|
+
SESSION_END_EXPIRED: 2,
|
|
19
|
+
SESSION_END_DISK_EXCEEDED: 3,
|
|
20
|
+
SESSION_END_MAIN_PROCESS_ENDED: 4,
|
|
21
|
+
SESSION_END_BOUNDARY_FAILED: 5,
|
|
22
|
+
SESSION_END_SANDBOX_CHANGED: 6,
|
|
23
|
+
SESSION_END_SHUTDOWN: 7,
|
|
24
|
+
SESSION_END_REPLACED: 8,
|
|
25
|
+
SESSION_END_NOT_FOUND: 9,
|
|
26
|
+
SESSION_END_UNCLAIMED: 10,
|
|
27
|
+
};
|
|
28
|
+
export const SESSION_END_NAMES = ["open", "closed", "expired", "disk_exceeded", "main_process_ended", "boundary_failed", "sandbox_changed", "shutdown", "replaced", "not_found", "unclaimed"];
|
|
29
|
+
/** plimsoll.v1.NotDispatchedReason, by number. */
|
|
30
|
+
export const REFUSALS = {
|
|
31
|
+
NOT_DISPATCHED_REASON_UNSPECIFIED: 0,
|
|
32
|
+
NOT_DISPATCHED_REASON_REQUEST: 1,
|
|
33
|
+
NOT_DISPATCHED_REASON_PERMISSION: 2,
|
|
34
|
+
NOT_DISPATCHED_REASON_PROTOCOL: 3,
|
|
35
|
+
NOT_DISPATCHED_REASON_UNSUPPORTED: 4,
|
|
36
|
+
NOT_DISPATCHED_REASON_ISOLATION: 5,
|
|
37
|
+
NOT_DISPATCHED_REASON_CAPACITY: 6,
|
|
38
|
+
NOT_DISPATCHED_REASON_ENVIRONMENT: 7,
|
|
39
|
+
};
|
|
40
|
+
export const REFUSAL_NAMES = ["unknown", "request", "permission", "protocol", "unsupported", "isolation", "capacity", "environment"];
|
|
41
|
+
/** Isolation tiers, weakest first (sandbox.IsolationClass). */
|
|
42
|
+
export const TIERS = ["none", "process", "container", "kernel", "vm"];
|
|
43
|
+
/** The languages plimsoll keeps an interpreter for (sandbox.Languages). */
|
|
44
|
+
export const LANGUAGES = ["javascript", "python"];
|
package/dist/wire.d.ts
CHANGED
|
@@ -54,6 +54,7 @@ export type WireRecord = {
|
|
|
54
54
|
unanswered?: string;
|
|
55
55
|
softwareIdentity?: string;
|
|
56
56
|
softwareRuleId?: string;
|
|
57
|
+
instance?: string;
|
|
57
58
|
recordSha256?: string;
|
|
58
59
|
};
|
|
59
60
|
export type WireAdvice = {
|
|
@@ -116,6 +117,7 @@ export type WireRunResponse = {
|
|
|
116
117
|
record?: WireRecord;
|
|
117
118
|
softwareIdentity?: string;
|
|
118
119
|
environment?: string;
|
|
120
|
+
instance?: string;
|
|
119
121
|
javascript?: WireJavaScriptResult;
|
|
120
122
|
project?: WireProjectResult;
|
|
121
123
|
module?: unknown;
|
|
@@ -190,3 +192,14 @@ export type WireError = {
|
|
|
190
192
|
value?: string;
|
|
191
193
|
}[];
|
|
192
194
|
};
|
|
195
|
+
/** A bytes field that is not base64 text: the answer is not the protocol's. */
|
|
196
|
+
export declare class WireShapeError extends Error {
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Decodes a bytes field of the daemon's answer. Only a string (or an absent field) is
|
|
200
|
+
* accepted: the answer is parsed JSON, and Buffer.from given an object with a
|
|
201
|
+
* "length" allocates that many bytes and reads each index, so a 30-byte
|
|
202
|
+
* {"length":2000000000} would cost 2 GB and a blocked event loop past the
|
|
203
|
+
* response's 32 MiB cap (Claude Security scan, 2026-10-27).
|
|
204
|
+
*/
|
|
205
|
+
export declare function wireBytes(v: unknown): Buffer;
|
package/dist/wire.js
CHANGED
|
@@ -3,4 +3,20 @@
|
|
|
3
3
|
// JSON names; bytes are base64; 64-bit integers arrive as strings; enums as their
|
|
4
4
|
// names; a field at its zero value is omitted, which is why everything read is
|
|
5
5
|
// optional.
|
|
6
|
-
|
|
6
|
+
/** A bytes field that is not base64 text: the answer is not the protocol's. */
|
|
7
|
+
export class WireShapeError extends Error {
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Decodes a bytes field of the daemon's answer. Only a string (or an absent field) is
|
|
11
|
+
* accepted: the answer is parsed JSON, and Buffer.from given an object with a
|
|
12
|
+
* "length" allocates that many bytes and reads each index, so a 30-byte
|
|
13
|
+
* {"length":2000000000} would cost 2 GB and a blocked event loop past the
|
|
14
|
+
* response's 32 MiB cap (Claude Security scan, 2026-10-27).
|
|
15
|
+
*/
|
|
16
|
+
export function wireBytes(v) {
|
|
17
|
+
if (v === undefined || v === null)
|
|
18
|
+
return Buffer.alloc(0);
|
|
19
|
+
if (typeof v !== "string")
|
|
20
|
+
throw new WireShapeError(`a bytes field holds a ${Array.isArray(v) ? "list" : typeof v}, not base64 text`);
|
|
21
|
+
return Buffer.from(v, "base64");
|
|
22
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plimsollmark/client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.24.0",
|
|
4
4
|
"description": "TypeScript client for plimsolld, with AI SDK, Trigger.dev and Mastra executeCode add-ons",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"homepage": "https://github.com/plimsollmark/plimsoll/tree/main/clients/typescript#readme",
|