code60-transmission-server 0.1.0-staging.6 → 0.1.1
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/INTENT.md +47 -0
- package/README.md +87 -308
- package/dist/src/acp.js +130 -0
- package/dist/src/contract.js +133 -0
- package/dist/src/engine.js +650 -0
- package/dist/src/linux.js +84 -0
- package/dist/src/main.js +81 -25
- package/dist/src/repository.js +94 -0
- package/dist/src/service.js +196 -0
- package/package.json +19 -35
- package/reference/openapi.json +1073 -0
- package/README.engine.md +0 -463
- package/dist/src/broker/filesystem.js +0 -385
- package/dist/src/broker/index.js +0 -734
- package/dist/src/broker/native/README.md +0 -207
- package/dist/src/broker/native/build.js +0 -46
- package/dist/src/broker/native/command-helper.c +0 -93
- package/dist/src/broker/native/fs-helper.c +0 -529
- package/dist/src/broker/native/git-helper.c +0 -205
- package/dist/src/broker/policy.js +0 -149
- package/dist/src/broker/startup-lock.js +0 -14
- package/dist/src/broker/types.js +0 -11
- package/dist/src/cli/configure.js +0 -193
- package/dist/src/cli/daemon.js +0 -369
- package/dist/src/cli/helpers.js +0 -112
- package/dist/src/cli/main.js +0 -189
- package/dist/src/cli/runtime-build.js +0 -38
- package/dist/src/config/coding-policy.js +0 -4
- package/dist/src/config/deployment.js +0 -182
- package/dist/src/config/documents.js +0 -29
- package/dist/src/config/profile-validation.js +0 -123
- package/dist/src/config/schema-graph.js +0 -237
- package/dist/src/config/schema-loader.js +0 -185
- package/dist/src/config/validation-pool.js +0 -105
- package/dist/src/config/validation-protocol.js +0 -1
- package/dist/src/config/validation-worker.js +0 -106
- package/dist/src/config/workflow-language.js +0 -9
- package/dist/src/config/workflow-schema.json +0 -545
- package/dist/src/config/workflow-types.js +0 -1
- package/dist/src/config/workflow-validation.js +0 -95
- package/dist/src/engine/budgets.js +0 -50
- package/dist/src/engine/clocks.js +0 -27
- package/dist/src/engine/commands.js +0 -472
- package/dist/src/engine/contracts.js +0 -11
- package/dist/src/engine/drain-state.js +0 -31
- package/dist/src/engine/effective-permissions.js +0 -120
- package/dist/src/engine/instruction-pins.js +0 -205
- package/dist/src/engine/retries.js +0 -50
- package/dist/src/engine/state.js +0 -1
- package/dist/src/engine/timing.js +0 -23
- package/dist/src/engine/tool-observations.js +0 -87
- package/dist/src/engine/workflow-engine.js +0 -1862
- package/dist/src/mcp/catalog.js +0 -71
- package/dist/src/mcp/main.js +0 -26
- package/dist/src/mcp/server.js +0 -147
- package/dist/src/runtime/codex-app-server.js +0 -91
- package/dist/src/runtime/containment.js +0 -82
- package/dist/src/runtime/engine-driver.js +0 -221
- package/dist/src/runtime/json-line-writer.js +0 -192
- package/dist/src/runtime/pinned-instruction-sources.js +0 -24
- package/dist/src/runtime/protocol-client.js +0 -264
- package/dist/src/runtime/protocol-pool.js +0 -183
- package/dist/src/runtime/protocol-projection.js +0 -393
- package/dist/src/runtime/protocol-types.js +0 -1
- package/dist/src/runtime/protocol-worker.js +0 -18
- package/dist/src/runtime/provider-bridge.js +0 -290
- package/dist/src/runtime/provider-credentials.js +0 -41
- package/dist/src/runtime/provider-transport.js +0 -406
- package/dist/src/runtime/runtime-broker.js +0 -213
- package/dist/src/runtime/workspace-instructions.js +0 -120
- package/dist/src/runtime/workspace-view.js +0 -74
- package/dist/src/server/api-contract.json +0 -11614
- package/dist/src/server/api-types.js +0 -1
- package/dist/src/server/application.js +0 -44
- package/dist/src/server/auth.js +0 -67
- package/dist/src/server/broker-handlers.js +0 -242
- package/dist/src/server/coding.js +0 -254
- package/dist/src/server/control-plane.js +0 -50
- package/dist/src/server/deployment.js +0 -249
- package/dist/src/server/errors.js +0 -22
- package/dist/src/server/history-handlers.js +0 -127
- package/dist/src/server/http.js +0 -124
- package/dist/src/server/paging.js +0 -56
- package/dist/src/server/publication.js +0 -119
- package/dist/src/server/tool-event-handler.js +0 -77
- package/dist/src/server/workspace-handlers.js +0 -34
- package/dist/src/storage/coordinator.js +0 -224
- package/dist/src/storage/startup-lock.js +0 -71
- package/dist/src/storage/store.js +0 -167
- package/dist/src/tools/check-worker.js +0 -81
- package/dist/src/tools/checks.js +0 -117
- package/dist/src/tools/command-check.js +0 -34
- package/dist/src/tools/commands.js +0 -310
- package/dist/src/tools/developer.js +0 -351
- package/dist/src/tools/dns.js +0 -248
- package/dist/src/tools/http-contract.js +0 -38
- package/dist/src/tools/http.js +0 -358
- package/dist/src/tools/index.js +0 -194
- package/dist/src/tools/worker-check.js +0 -73
- package/dist/src/workspaces/git.js +0 -227
- package/dist/src/workspaces/index.js +0 -937
- package/dist/src/workspaces/source.js +0 -295
- package/examples/deployment.local.json +0 -22
- package/scripts/postinstall.mjs +0 -26
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
import { randomUUID } from 'node:crypto';
|
|
2
|
-
import { canonical, digest } from '../broker/policy.js';
|
|
3
|
-
import { ApiError } from '../server/errors.js';
|
|
4
|
-
export class HttpReceiptReplay extends Error {
|
|
5
|
-
receipt;
|
|
6
|
-
constructor(receipt) {
|
|
7
|
-
super('http_receipt_replay');
|
|
8
|
-
this.receipt = receipt;
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
export const ENGINE_MIGRATION = {
|
|
12
|
-
id: 'engine.foundation.v1',
|
|
13
|
-
sql: `
|
|
14
|
-
CREATE TABLE engine_resources (
|
|
15
|
-
seq INTEGER PRIMARY KEY AUTOINCREMENT, kind TEXT NOT NULL, id TEXT NOT NULL,
|
|
16
|
-
run_id TEXT, parent_id TEXT, revision INTEGER NOT NULL, body TEXT NOT NULL,
|
|
17
|
-
UNIQUE(kind,id));
|
|
18
|
-
CREATE INDEX engine_resource_collection ON engine_resources(kind,run_id,parent_id,seq);
|
|
19
|
-
CREATE TABLE engine_private (scope TEXT NOT NULL, id TEXT NOT NULL, body TEXT NOT NULL, PRIMARY KEY(scope,id));
|
|
20
|
-
CREATE TABLE engine_http_receipts (scope TEXT NOT NULL, key TEXT NOT NULL, digest TEXT NOT NULL, body TEXT NOT NULL, PRIMARY KEY(scope,key));
|
|
21
|
-
CREATE TABLE engine_sequences (run_id TEXT PRIMARY KEY, value INTEGER NOT NULL);
|
|
22
|
-
CREATE TABLE engine_tokens (
|
|
23
|
-
digest TEXT PRIMARY KEY, principal_id TEXT NOT NULL, audience TEXT NOT NULL,
|
|
24
|
-
session_id TEXT, epoch INTEGER, role TEXT, workspace_scope TEXT NOT NULL, revoked INTEGER NOT NULL DEFAULT 0);
|
|
25
|
-
CREATE TABLE engine_cursors (
|
|
26
|
-
id TEXT PRIMARY KEY, collection TEXT NOT NULL, principal_id TEXT NOT NULL,
|
|
27
|
-
last_seq INTEGER NOT NULL, expires_at INTEGER NOT NULL);
|
|
28
|
-
`,
|
|
29
|
-
};
|
|
30
|
-
/** Public DTOs and private orchestration records are separate by construction.
|
|
31
|
-
* Never put broker audit rows, FDs, tokens or resolved credentials in this map. */
|
|
32
|
-
export class EngineStore {
|
|
33
|
-
coordinator;
|
|
34
|
-
#eventWaiters = new Map();
|
|
35
|
-
#waiterCount = 0;
|
|
36
|
-
constructor(coordinator) {
|
|
37
|
-
this.coordinator = coordinator;
|
|
38
|
-
}
|
|
39
|
-
get(kind, id) {
|
|
40
|
-
const row = this.coordinator.db.prepare('SELECT body,revision,seq FROM engine_resources WHERE kind=? AND id=?').get(kind, id);
|
|
41
|
-
if (!row)
|
|
42
|
-
throw new ApiError(404, 'not_found', 'Resource not found.');
|
|
43
|
-
return JSON.parse(row.body);
|
|
44
|
-
}
|
|
45
|
-
find(kind, id) {
|
|
46
|
-
try {
|
|
47
|
-
return this.get(kind, id);
|
|
48
|
-
}
|
|
49
|
-
catch (error) {
|
|
50
|
-
if (error instanceof ApiError && error.status === 404)
|
|
51
|
-
return undefined;
|
|
52
|
-
throw error;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
etag(kind, id) {
|
|
56
|
-
const row = this.coordinator.db.prepare('SELECT revision FROM engine_resources WHERE kind=? AND id=?').get(kind, id);
|
|
57
|
-
if (!row)
|
|
58
|
-
throw new ApiError(404, 'not_found', 'Resource not found.');
|
|
59
|
-
return `"${kind}:${id}:${row.revision}"`;
|
|
60
|
-
}
|
|
61
|
-
expectMatch(kind, id, supplied) {
|
|
62
|
-
if (!supplied)
|
|
63
|
-
throw new ApiError(428, 'precondition_required', 'If-Match is required.');
|
|
64
|
-
if (supplied !== this.etag(kind, id))
|
|
65
|
-
throw new ApiError(412, 'precondition_failed', 'The resource revision is stale.');
|
|
66
|
-
}
|
|
67
|
-
put(kind, value, options = {}) {
|
|
68
|
-
this.coordinator.atomic(() => {
|
|
69
|
-
const prior = this.coordinator.db.prepare('SELECT body FROM engine_resources WHERE kind=? AND id=?').get(kind, value.id);
|
|
70
|
-
const body = canonical(value);
|
|
71
|
-
if (prior && options.immutable) {
|
|
72
|
-
if (prior.body !== body)
|
|
73
|
-
throw new ApiError(409, 'immutable_resource', 'Immutable resource content cannot change.');
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
this.coordinator.db.prepare(`INSERT INTO engine_resources(kind,id,run_id,parent_id,revision,body) VALUES (?,?,?,?,1,?)
|
|
77
|
-
ON CONFLICT(kind,id) DO UPDATE SET body=excluded.body, revision=revision+1`).run(kind, value.id, options.runId ?? null, options.parentId ?? null, body);
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
list(kind, filter = {}) {
|
|
81
|
-
return this.coordinator.db.prepare(`SELECT body,seq,revision FROM engine_resources WHERE kind=?
|
|
82
|
-
AND (? IS NULL OR run_id=?) AND (? IS NULL OR parent_id=?) AND seq>? AND seq<=? ORDER BY seq LIMIT ?`).all(kind, filter.runId ?? null, filter.runId ?? null, filter.parentId ?? null, filter.parentId ?? null, filter.after ?? 0, filter.through ?? Number.MAX_SAFE_INTEGER, filter.limit ?? 201).map(row => ({ value: JSON.parse(row.body), seq: row.seq }));
|
|
83
|
-
}
|
|
84
|
-
watchEvents(runId, timeoutMs, signal) {
|
|
85
|
-
this.coordinator.assertOutsideTransaction();
|
|
86
|
-
if (!Number.isInteger(timeoutMs) || timeoutMs < 0 || timeoutMs > 30_000)
|
|
87
|
-
throw new ApiError(400, 'invalid_wait', 'Event wait must be from 0 through 30000 milliseconds.');
|
|
88
|
-
if (this.#waiterCount >= 1024)
|
|
89
|
-
throw new ApiError(503, 'event_wait_overloaded', 'The event wait capacity is exhausted.', true);
|
|
90
|
-
let close;
|
|
91
|
-
const done = new Promise(resolve => {
|
|
92
|
-
const set = this.#eventWaiters.get(runId) ?? new Set();
|
|
93
|
-
this.#eventWaiters.set(runId, set);
|
|
94
|
-
this.#waiterCount++;
|
|
95
|
-
const timer = setTimeout(() => close(), timeoutMs);
|
|
96
|
-
let closed = false;
|
|
97
|
-
close = () => {
|
|
98
|
-
if (closed)
|
|
99
|
-
return;
|
|
100
|
-
closed = true;
|
|
101
|
-
clearTimeout(timer);
|
|
102
|
-
signal.removeEventListener('abort', close);
|
|
103
|
-
set.delete(close);
|
|
104
|
-
this.#waiterCount--;
|
|
105
|
-
if (!set.size)
|
|
106
|
-
this.#eventWaiters.delete(runId);
|
|
107
|
-
resolve();
|
|
108
|
-
};
|
|
109
|
-
set.add(close);
|
|
110
|
-
if (signal.aborted)
|
|
111
|
-
close();
|
|
112
|
-
else
|
|
113
|
-
signal.addEventListener('abort', close, { once: true });
|
|
114
|
-
});
|
|
115
|
-
return { done, close };
|
|
116
|
-
}
|
|
117
|
-
private(scope, id) {
|
|
118
|
-
const row = this.coordinator.db.prepare('SELECT body FROM engine_private WHERE scope=? AND id=?').get(scope, id);
|
|
119
|
-
return row ? JSON.parse(row.body) : undefined;
|
|
120
|
-
}
|
|
121
|
-
setPrivate(scope, id, value) {
|
|
122
|
-
this.coordinator.atomic(() => {
|
|
123
|
-
this.coordinator.db.prepare('INSERT INTO engine_private VALUES (?,?,?) ON CONFLICT(scope,id) DO UPDATE SET body=excluded.body').run(scope, id, canonical(value));
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
receipt(identity) {
|
|
127
|
-
if (!identity.key || identity.key.length > 200)
|
|
128
|
-
throw new ApiError(400, 'invalid_idempotency_key', 'Idempotency-Key must contain 1 to 200 characters.');
|
|
129
|
-
const scope = canonical([identity.principal, identity.method.toUpperCase(), identity.path]);
|
|
130
|
-
const row = this.coordinator.db.prepare('SELECT digest,body FROM engine_http_receipts WHERE scope=? AND key=?').get(scope, identity.key);
|
|
131
|
-
if (!row)
|
|
132
|
-
return undefined;
|
|
133
|
-
if (row.digest !== digest(identity.body))
|
|
134
|
-
throw new ApiError(409, 'idempotency_conflict', 'Idempotency key was used with a different body.');
|
|
135
|
-
return JSON.parse(row.body);
|
|
136
|
-
}
|
|
137
|
-
saveReceipt(identity, receipt) {
|
|
138
|
-
this.coordinator.atomic(() => {
|
|
139
|
-
const existing = this.receipt(identity);
|
|
140
|
-
if (existing)
|
|
141
|
-
throw new HttpReceiptReplay(existing);
|
|
142
|
-
const scope = canonical([identity.principal, identity.method.toUpperCase(), identity.path]);
|
|
143
|
-
this.coordinator.db.prepare('INSERT INTO engine_http_receipts VALUES (?,?,?,?)').run(scope, identity.key, digest(identity.body), canonical(receipt));
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
command(identity, apply) {
|
|
147
|
-
return this.coordinator.atomic(() => {
|
|
148
|
-
const existing = this.receipt(identity);
|
|
149
|
-
if (existing)
|
|
150
|
-
return { receipt: existing, replay: true };
|
|
151
|
-
const receipt = apply();
|
|
152
|
-
this.saveReceipt(identity, receipt);
|
|
153
|
-
return { receipt, replay: false };
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
event(runId, type, resourceType, resourceId, data, now = Date.now()) {
|
|
157
|
-
return this.coordinator.atomic(() => {
|
|
158
|
-
this.coordinator.db.prepare('INSERT INTO engine_sequences VALUES (?,1) ON CONFLICT(run_id) DO UPDATE SET value=value+1').run(runId);
|
|
159
|
-
const sequence = this.coordinator.db.prepare('SELECT value FROM engine_sequences WHERE run_id=?').get(runId).value;
|
|
160
|
-
const event = { id: randomUUID(), runId, sequence, occurredAt: new Date(now).toISOString(), type, resourceType, resourceId, data };
|
|
161
|
-
this.put('events', event, { runId, immutable: true });
|
|
162
|
-
this.coordinator.afterCommit(() => { for (const close of [...this.#eventWaiters.get(runId) ?? []])
|
|
163
|
-
close(); });
|
|
164
|
-
return event;
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { parentPort, workerData } from "node:worker_threads";
|
|
2
|
-
import { Ajv2020 } from "ajv/dist/2020.js";
|
|
3
|
-
import { createRequire } from "node:module";
|
|
4
|
-
const addFormats = createRequire(import.meta.url)("ajv-formats");
|
|
5
|
-
/** Ordinary Draft 2020 artifact policy matches the source schema graph: ignore
|
|
6
|
-
* $async only at schema locations, never within const/default/example data or
|
|
7
|
-
* a property's literal name. This mutates only the worker's private clone. */
|
|
8
|
-
function ordinaryArtifactSchema(input) {
|
|
9
|
-
const object = (value) => !!value && typeof value === "object" && !Array.isArray(value);
|
|
10
|
-
const visit = (node) => {
|
|
11
|
-
if (!object(node))
|
|
12
|
-
return;
|
|
13
|
-
delete node.$async;
|
|
14
|
-
for (const key of ["additionalProperties", "unevaluatedProperties", "propertyNames", "contains", "items", "unevaluatedItems", "if", "then", "else", "not", "contentSchema"])
|
|
15
|
-
visit(node[key]);
|
|
16
|
-
for (const key of ["allOf", "anyOf", "oneOf", "prefixItems"])
|
|
17
|
-
if (Array.isArray(node[key]))
|
|
18
|
-
for (const child of node[key])
|
|
19
|
-
visit(child);
|
|
20
|
-
for (const key of ["properties", "patternProperties", "dependentSchemas", "dependencies", "$defs", "definitions"])
|
|
21
|
-
if (object(node[key]))
|
|
22
|
-
for (const child of Object.values(node[key]))
|
|
23
|
-
visit(child);
|
|
24
|
-
};
|
|
25
|
-
visit(input);
|
|
26
|
-
return input;
|
|
27
|
-
}
|
|
28
|
-
// Fixed trusted pure implementation. No model code, module path, eval/command
|
|
29
|
-
// arguments, environment credentials, filesystem, network or subprocess API.
|
|
30
|
-
const input = workerData;
|
|
31
|
-
try {
|
|
32
|
-
let pass = false;
|
|
33
|
-
if (input.predicate.kind === "text_includes") {
|
|
34
|
-
parentPort.postMessage({ event: "started" });
|
|
35
|
-
pass = input.artifact.content.includes(input.predicate.needle);
|
|
36
|
-
}
|
|
37
|
-
else if (input.predicate.kind === "json_pointer_equals") {
|
|
38
|
-
let value = input.artifact.decoded, found = true;
|
|
39
|
-
const parts = input.predicate.pointer === "" ? [] : input.predicate.pointer.slice(1).split("/").map(part => part.replaceAll("~1", "/").replaceAll("~0", "~"));
|
|
40
|
-
for (const part of parts) {
|
|
41
|
-
if (!value || typeof value !== "object" || (Array.isArray(value) && !/^(?:0|[1-9][0-9]*)$/.test(part)) ||
|
|
42
|
-
!Object.hasOwn(value, part)) {
|
|
43
|
-
found = false;
|
|
44
|
-
break;
|
|
45
|
-
}
|
|
46
|
-
value = value[part];
|
|
47
|
-
}
|
|
48
|
-
const equal = (a, b) => {
|
|
49
|
-
if (Object.is(a, b))
|
|
50
|
-
return true;
|
|
51
|
-
if (!a || !b || typeof a !== "object" || typeof b !== "object" || Array.isArray(a) !== Array.isArray(b))
|
|
52
|
-
return false;
|
|
53
|
-
const keys = Object.keys(a).sort(), other = Object.keys(b).sort();
|
|
54
|
-
return keys.length === other.length && keys.every((key, i) => key === other[i] &&
|
|
55
|
-
equal(a[key], b[key]));
|
|
56
|
-
};
|
|
57
|
-
parentPort.postMessage({ event: "started" });
|
|
58
|
-
pass = found && equal(value, input.predicate.expected);
|
|
59
|
-
}
|
|
60
|
-
else if (input.predicate.kind === "json_schema") {
|
|
61
|
-
const ajv = new Ajv2020({ strict: false, allErrors: false, coerceTypes: false, useDefaults: false,
|
|
62
|
-
removeAdditional: false });
|
|
63
|
-
addFormats(ajv);
|
|
64
|
-
const validate = ajv.compile(ordinaryArtifactSchema(input.predicate.schema));
|
|
65
|
-
parentPort.postMessage({ event: "started" });
|
|
66
|
-
const result = validate(input.artifact.decoded);
|
|
67
|
-
if (typeof result !== "boolean")
|
|
68
|
-
throw new Error("async_check_schema");
|
|
69
|
-
pass = result;
|
|
70
|
-
}
|
|
71
|
-
else
|
|
72
|
-
throw new Error("unknown_predicate");
|
|
73
|
-
parentPort.postMessage({ status: pass ? "pass" : "fail", explanation: pass ? "Registered artifact predicate passed." : "Registered artifact predicate failed." });
|
|
74
|
-
}
|
|
75
|
-
catch {
|
|
76
|
-
parentPort.postMessage({ status: "infrastructure_error", code: "check_worker_invalid_configuration", retryable: false,
|
|
77
|
-
explanation: "Registered pure check could not evaluate its deployment configuration." });
|
|
78
|
-
}
|
|
79
|
-
finally {
|
|
80
|
-
parentPort.close();
|
|
81
|
-
}
|
package/dist/src/tools/checks.js
DELETED
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import { randomUUID } from "node:crypto";
|
|
2
|
-
import { canonical, jsonCopy } from "../broker/policy.js";
|
|
3
|
-
export class CheckRegistryError extends Error {
|
|
4
|
-
code;
|
|
5
|
-
constructor(code) {
|
|
6
|
-
super(code);
|
|
7
|
-
this.code = code;
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
/** Deployment code registrations only. No workflow/model shell, expression,
|
|
11
|
-
* inline function, module path, command or unknown check is executed. */
|
|
12
|
-
export class TrustedCheckRegistry {
|
|
13
|
-
options;
|
|
14
|
-
checks = new Map();
|
|
15
|
-
running = new Map();
|
|
16
|
-
constructor(options) {
|
|
17
|
-
this.options = options;
|
|
18
|
-
for (const check of options.checks) {
|
|
19
|
-
if (!check.id || !check.description || !check.version || typeof check.execute !== "function" || this.checks.has(check.id)) {
|
|
20
|
-
throw new CheckRegistryError("invalid_check_registration");
|
|
21
|
-
}
|
|
22
|
-
if (check.parametersSchema !== undefined)
|
|
23
|
-
canonical(check.parametersSchema);
|
|
24
|
-
this.checks.set(check.id, Object.freeze({ id: check.id, description: check.description, version: check.version, ...(check.timeoutMs === undefined ? {} : { timeoutMs: check.timeoutMs }),
|
|
25
|
-
...(check.parametersSchema === undefined ? {} : { parametersSchema: jsonCopy(check.parametersSchema) }),
|
|
26
|
-
execute: (request, signal) => this.execute(check, request, signal) }));
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
list() {
|
|
30
|
-
return [...this.checks.values()].map(check => ({ name: check.id, description: check.description, version: check.version,
|
|
31
|
-
...(check.parametersSchema === undefined ? {} : { parametersSchema: jsonCopy(check.parametersSchema) }) }));
|
|
32
|
-
}
|
|
33
|
-
get(id) { return this.checks.get(id); }
|
|
34
|
-
register(check) {
|
|
35
|
-
if (!check.id || !check.description || !check.version || typeof check.execute !== 'function')
|
|
36
|
-
throw new CheckRegistryError('invalid_check_registration');
|
|
37
|
-
const prior = this.checks.get(check.id);
|
|
38
|
-
if (prior) {
|
|
39
|
-
if (prior.version !== check.version)
|
|
40
|
-
throw new CheckRegistryError('check_version_conflict');
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
this.checks.set(check.id, Object.freeze({ ...check, execute: (request, signal) => this.execute(check, request, signal) }));
|
|
44
|
-
}
|
|
45
|
-
preflight(ids) {
|
|
46
|
-
if (new Set(ids).size !== ids.length || ids.some(id => !this.checks.has(id)))
|
|
47
|
-
throw new CheckRegistryError("unknown_named_check");
|
|
48
|
-
}
|
|
49
|
-
/** A timed-out implementation which ignores AbortSignal stays active until
|
|
50
|
-
* it actually settles. The engine's GLOBAL quiescence probe must include this. */
|
|
51
|
-
activeWork(runId) { return [...this.running].filter(([, run]) => run === runId).map(([id]) => id); }
|
|
52
|
-
async execute(check, request, signal) {
|
|
53
|
-
this.options.coordinator.assertOutsideTransaction();
|
|
54
|
-
const now = this.options.now ?? Date.now;
|
|
55
|
-
if (!request.runId || !request.stepExecutionId || !request.leaseId || !request.workspaceRevisionId || !request.artifactId ||
|
|
56
|
-
!Number.isFinite(request.deadlineAt) || request.deadlineAt <= now() || signal.aborted) {
|
|
57
|
-
return { status: "infrastructure_error", code: "check_deadline_or_scope", retryable: false, explanation: "Check cannot start in this scope or after its deadline." };
|
|
58
|
-
}
|
|
59
|
-
const validation = this.options.validateRequest?.(request);
|
|
60
|
-
if (validation && typeof validation === "object" && "then" in validation)
|
|
61
|
-
throw new CheckRegistryError("async_check_scope_validation");
|
|
62
|
-
const controller = new AbortController(), combined = AbortSignal.any([signal, controller.signal]);
|
|
63
|
-
const id = randomUUID();
|
|
64
|
-
this.running.set(id, request.runId);
|
|
65
|
-
let timer;
|
|
66
|
-
const actual = Promise.resolve().then(() => {
|
|
67
|
-
if (combined.aborted || request.deadlineAt <= now())
|
|
68
|
-
throw new CheckRegistryError("check_aborted");
|
|
69
|
-
return check.execute(jsonCopy(request), combined);
|
|
70
|
-
}).then(result => this.result(result)).catch(() => ({ status: "infrastructure_error", code: "check_execution_error",
|
|
71
|
-
retryable: true, explanation: "Registered check did not complete successfully." }))
|
|
72
|
-
.finally(() => { this.running.delete(id); if (timer)
|
|
73
|
-
clearTimeout(timer); });
|
|
74
|
-
const timeout = new Promise(resolve => {
|
|
75
|
-
let finished = false;
|
|
76
|
-
const finish = () => {
|
|
77
|
-
if (finished)
|
|
78
|
-
return;
|
|
79
|
-
finished = true;
|
|
80
|
-
if (timer)
|
|
81
|
-
clearTimeout(timer);
|
|
82
|
-
controller.abort();
|
|
83
|
-
resolve({ status: "infrastructure_error", code: "check_aborted_or_timed_out",
|
|
84
|
-
retryable: true, explanation: "Registered check exceeded its deadline or was cancelled." });
|
|
85
|
-
};
|
|
86
|
-
const arm = () => {
|
|
87
|
-
if (finished)
|
|
88
|
-
return;
|
|
89
|
-
const remaining = request.deadlineAt - now();
|
|
90
|
-
if (remaining <= 0)
|
|
91
|
-
finish();
|
|
92
|
-
else
|
|
93
|
-
timer = setTimeout(arm, Math.min(2_147_483_647, Math.ceil(remaining)));
|
|
94
|
-
};
|
|
95
|
-
combined.addEventListener("abort", finish, { once: true });
|
|
96
|
-
arm();
|
|
97
|
-
void actual.finally(() => combined.removeEventListener("abort", finish));
|
|
98
|
-
});
|
|
99
|
-
return Promise.race([actual, timeout]);
|
|
100
|
-
}
|
|
101
|
-
result(result) {
|
|
102
|
-
if (!result || !["pass", "fail", "infrastructure_error"].includes(result.status) ||
|
|
103
|
-
typeof result.explanation !== "string" || !result.explanation || result.explanation.length > 16384) {
|
|
104
|
-
return { status: "infrastructure_error", code: "invalid_check_result", retryable: false, explanation: "Registered check returned an invalid result." };
|
|
105
|
-
}
|
|
106
|
-
if (result.status === "infrastructure_error") {
|
|
107
|
-
if (!/^[a-z0-9_]{1,80}$/.test(result.code) || typeof result.retryable !== "boolean")
|
|
108
|
-
throw new CheckRegistryError("invalid_check_result");
|
|
109
|
-
return { status: result.status, code: result.code, retryable: result.retryable, explanation: result.explanation };
|
|
110
|
-
}
|
|
111
|
-
if (result.evidenceArtifactIds !== undefined && (result.evidenceArtifactIds.length > 32 ||
|
|
112
|
-
result.evidenceArtifactIds.some(id => typeof id !== "string" || !id || id.length > 200)))
|
|
113
|
-
throw new CheckRegistryError("invalid_check_result");
|
|
114
|
-
return { status: result.status, explanation: result.explanation,
|
|
115
|
-
...(result.evidenceArtifactIds === undefined ? {} : { evidenceArtifactIds: [...result.evidenceArtifactIds] }) };
|
|
116
|
-
}
|
|
117
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { createHash, randomUUID } from 'node:crypto';
|
|
2
|
-
export function createCommandCheck(definition, options) {
|
|
3
|
-
const pinned = structuredClone(definition), definitionDigest = createHash('sha256').update(JSON.stringify(pinned)).digest('hex');
|
|
4
|
-
return { id: pinned.id, description: pinned.description, version: pinned.version, timeoutMs: pinned.timeoutMs ?? 600_000,
|
|
5
|
-
async execute(request, signal) {
|
|
6
|
-
const submission = options.store.list('submissions', { runId: request.runId, limit: Number.MAX_SAFE_INTEGER }).find(s => s.value.artifactId === request.artifactId)?.value;
|
|
7
|
-
if (!submission || signal.aborted)
|
|
8
|
-
return { status: 'infrastructure_error', code: 'check_assignment_unavailable', retryable: false, explanation: 'The exact candidate is unavailable.' };
|
|
9
|
-
const authority = options.store.private('session_authority', submission.sessionId);
|
|
10
|
-
const command = await options.runner.start(authority.binding, { command: pinned.command, ...(pinned.cwd === undefined ? {} : { cwd: pinned.cwd }), ...(pinned.env === undefined ? {} : { env: pinned.env }), timeoutMs: Math.max(1, Math.min(pinned.timeoutMs ?? 600_000, request.deadlineAt - Date.now())), readOnly: true, background: true });
|
|
11
|
-
const abort = () => { void options.runner.stop(command.id); };
|
|
12
|
-
signal.addEventListener('abort', abort, { once: true });
|
|
13
|
-
let record = options.runner.get(command.id);
|
|
14
|
-
try {
|
|
15
|
-
while (record.state === 'running') {
|
|
16
|
-
await new Promise(resolve => setTimeout(resolve, 25));
|
|
17
|
-
record = options.runner.get(command.id);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
finally {
|
|
21
|
-
signal.removeEventListener('abort', abort);
|
|
22
|
-
}
|
|
23
|
-
const stdout = options.runner.output(record.id, 'stdout', 0, 16_384).text, stderr = options.runner.output(record.id, 'stderr', 0, 16_384).text;
|
|
24
|
-
const content = JSON.stringify({ checkId: pinned.id, definitionDigest, environment: pinned.env ?? {}, workspaceRevisionId: request.workspaceRevisionId, command: record, stdout, stderr });
|
|
25
|
-
const id = randomUUID();
|
|
26
|
-
options.store.put('artifacts', { id, runId: request.runId, stepExecutionId: request.stepExecutionId, kind: 'check_evidence', document: { mediaType: 'application/json', content }, contentDigest: createHash('sha256').update(content).digest('hex'), state: 'accepted', createdAt: new Date().toISOString() }, { runId: request.runId, immutable: true });
|
|
27
|
-
options.assignEvidence(submission.sessionId, id);
|
|
28
|
-
options.store.setPrivate('check_evidence', `${request.runId}:${request.workspaceRevisionId}:${pinned.id}`, { artifactId: id, definitionDigest, commandId: record.id, status: record.state === 'completed' ? 'pass' : 'fail' });
|
|
29
|
-
options.store.event(request.runId, 'check_completed', 'artifact', id, { checkId: pinned.id, commandId: record.id, workspaceRevisionId: request.workspaceRevisionId, status: record.state });
|
|
30
|
-
if (record.state === 'uncertain')
|
|
31
|
-
return { status: 'infrastructure_error', code: 'check_process_uncertain', retryable: false, explanation: 'Command settlement requires reconciliation.' };
|
|
32
|
-
return { status: record.state === 'completed' ? 'pass' : 'fail', evidenceArtifactIds: [id], explanation: `${pinned.description}: ${record.state}, exit ${record.exitCode}.\n${stderr || stdout || '(No output)'}` };
|
|
33
|
-
} };
|
|
34
|
-
}
|