code60-transmission-server 0.1.0-staging.2 → 0.1.0-staging.20

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.
Files changed (94) hide show
  1. package/INTENT.md +47 -0
  2. package/README.md +58 -253
  3. package/dist/src/acp.js +115 -0
  4. package/dist/src/contract.js +108 -0
  5. package/dist/src/engine.js +596 -0
  6. package/dist/src/main.js +72 -22
  7. package/dist/src/repository.js +94 -0
  8. package/dist/src/service.js +188 -0
  9. package/package.json +16 -32
  10. package/reference/openapi.json +834 -0
  11. package/README.engine.md +0 -401
  12. package/dist/src/broker/filesystem.js +0 -385
  13. package/dist/src/broker/index.js +0 -734
  14. package/dist/src/broker/native/README.md +0 -192
  15. package/dist/src/broker/native/build.js +0 -43
  16. package/dist/src/broker/native/fs-helper.c +0 -529
  17. package/dist/src/broker/native/git-helper.c +0 -205
  18. package/dist/src/broker/policy.js +0 -149
  19. package/dist/src/broker/startup-lock.js +0 -14
  20. package/dist/src/broker/types.js +0 -11
  21. package/dist/src/cli/daemon.js +0 -365
  22. package/dist/src/cli/helpers.js +0 -104
  23. package/dist/src/cli/main.js +0 -180
  24. package/dist/src/config/deployment.js +0 -163
  25. package/dist/src/config/documents.js +0 -29
  26. package/dist/src/config/profile-validation.js +0 -123
  27. package/dist/src/config/schema-graph.js +0 -237
  28. package/dist/src/config/schema-loader.js +0 -185
  29. package/dist/src/config/validation-pool.js +0 -105
  30. package/dist/src/config/validation-protocol.js +0 -1
  31. package/dist/src/config/validation-worker.js +0 -106
  32. package/dist/src/config/workflow-language.js +0 -9
  33. package/dist/src/config/workflow-schema.json +0 -534
  34. package/dist/src/config/workflow-types.js +0 -1
  35. package/dist/src/config/workflow-validation.js +0 -95
  36. package/dist/src/engine/budgets.js +0 -50
  37. package/dist/src/engine/clocks.js +0 -27
  38. package/dist/src/engine/commands.js +0 -441
  39. package/dist/src/engine/contracts.js +0 -11
  40. package/dist/src/engine/drain-state.js +0 -31
  41. package/dist/src/engine/effective-permissions.js +0 -120
  42. package/dist/src/engine/instruction-pins.js +0 -205
  43. package/dist/src/engine/retries.js +0 -50
  44. package/dist/src/engine/state.js +0 -1
  45. package/dist/src/engine/timing.js +0 -23
  46. package/dist/src/engine/tool-observations.js +0 -87
  47. package/dist/src/engine/workflow-engine.js +0 -1807
  48. package/dist/src/mcp/catalog.js +0 -71
  49. package/dist/src/mcp/main.js +0 -24
  50. package/dist/src/mcp/server.js +0 -104
  51. package/dist/src/runtime/codex-app-server.js +0 -91
  52. package/dist/src/runtime/containment.js +0 -82
  53. package/dist/src/runtime/engine-driver.js +0 -212
  54. package/dist/src/runtime/json-line-writer.js +0 -192
  55. package/dist/src/runtime/pinned-instruction-sources.js +0 -24
  56. package/dist/src/runtime/protocol-client.js +0 -264
  57. package/dist/src/runtime/protocol-pool.js +0 -183
  58. package/dist/src/runtime/protocol-projection.js +0 -393
  59. package/dist/src/runtime/protocol-types.js +0 -1
  60. package/dist/src/runtime/protocol-worker.js +0 -18
  61. package/dist/src/runtime/provider-bridge.js +0 -288
  62. package/dist/src/runtime/provider-credentials.js +0 -41
  63. package/dist/src/runtime/provider-transport.js +0 -404
  64. package/dist/src/runtime/runtime-broker.js +0 -213
  65. package/dist/src/runtime/workspace-instructions.js +0 -120
  66. package/dist/src/runtime/workspace-view.js +0 -74
  67. package/dist/src/server/api-contract.json +0 -11078
  68. package/dist/src/server/api-types.js +0 -1
  69. package/dist/src/server/application.js +0 -38
  70. package/dist/src/server/auth.js +0 -67
  71. package/dist/src/server/broker-handlers.js +0 -242
  72. package/dist/src/server/control-plane.js +0 -50
  73. package/dist/src/server/deployment.js +0 -237
  74. package/dist/src/server/errors.js +0 -22
  75. package/dist/src/server/history-handlers.js +0 -113
  76. package/dist/src/server/http.js +0 -124
  77. package/dist/src/server/paging.js +0 -56
  78. package/dist/src/server/publication.js +0 -119
  79. package/dist/src/server/tool-event-handler.js +0 -77
  80. package/dist/src/server/workspace-handlers.js +0 -34
  81. package/dist/src/storage/coordinator.js +0 -224
  82. package/dist/src/storage/startup-lock.js +0 -71
  83. package/dist/src/storage/store.js +0 -167
  84. package/dist/src/tools/check-worker.js +0 -81
  85. package/dist/src/tools/checks.js +0 -106
  86. package/dist/src/tools/dns.js +0 -248
  87. package/dist/src/tools/http-contract.js +0 -38
  88. package/dist/src/tools/http.js +0 -358
  89. package/dist/src/tools/index.js +0 -177
  90. package/dist/src/tools/worker-check.js +0 -73
  91. package/dist/src/workspaces/git.js +0 -227
  92. package/dist/src/workspaces/index.js +0 -715
  93. package/examples/deployment.local.json +0 -22
  94. package/scripts/postinstall.mjs +0 -25
@@ -1,385 +0,0 @@
1
- import { spawnSync } from "node:child_process";
2
- import { randomUUID } from "node:crypto";
3
- import { closeSync, constants, fstatSync, lstatSync, openSync } from "node:fs";
4
- import { dirname, isAbsolute } from "node:path";
5
- import { fileURLToPath } from "node:url";
6
- import { BrokerError } from "./types.js";
7
- import { digest, relativePath } from "./policy.js";
8
- import { startupLockIdentity } from "./startup-lock.js";
9
- const MAX_DATA = 1_048_576;
10
- const MAX_PATH = 4096;
11
- const MAX_ID = 8192;
12
- const environment = Object.freeze({ PATH: "/usr/bin:/bin", LC_ALL: "C" });
13
- const decoder = new TextDecoder("utf-8", { fatal: true });
14
- export class FilesystemHelperError extends Error {
15
- code;
16
- uncertain;
17
- constructor(code, uncertain) {
18
- super(`filesystem:${code}`);
19
- this.code = code;
20
- this.uncertain = uncertain;
21
- }
22
- }
23
- /** Fixed six-tool catalog using actual descriptor-relative native operations.
24
- * No model-controlled root, flags, helper executable, shell or environment.
25
- * Node path validation is only input validation, never the access enforcement. */
26
- export class NativeFilesystemRoot {
27
- options;
28
- rootIdentity;
29
- protectedDescriptors;
30
- ownedDescriptors;
31
- protectedIdentities;
32
- lockIdentity;
33
- closed = false;
34
- constructor(options) {
35
- this.options = Object.freeze({ ...options, protectedRootFds: Object.freeze([...(options.protectedRootFds ?? [])]) });
36
- this.lockIdentity = options.startupLockFd === undefined ? undefined : startupLockIdentity(options.startupLockFd);
37
- if (!Number.isInteger(options.rootFd) || options.rootFd < 0 ||
38
- !["workspace", "scratch", "deployment"].includes(options.root) ||
39
- (options.root === "deployment" ? !options.rootId : options.rootId !== undefined))
40
- throw new BrokerError("invalid_filesystem_root", 422);
41
- const root = fstatSync(options.rootFd, { bigint: true });
42
- if (!root.isDirectory())
43
- throw new BrokerError("invalid_filesystem_root", 422);
44
- this.rootIdentity = `${root.dev}:${root.ino}`;
45
- if (!isAbsolute(options.helperPath))
46
- throw new BrokerError("untrusted_filesystem_helper", 422);
47
- const executable = lstatSync(options.helperPath);
48
- if (!executable.isFile() || executable.isSymbolicLink() || executable.nlink !== 1 ||
49
- executable.uid !== process.geteuid?.() || (executable.mode & 0o6022))
50
- throw new BrokerError("untrusted_filesystem_helper", 422);
51
- const owned = [];
52
- try {
53
- // Protect actual engine installation and helper directory, not caller path spelling.
54
- for (const path of [fileURLToPath(new URL("../../", import.meta.url)), dirname(options.helperPath)]) {
55
- owned.push(openSync(path, constants.O_RDONLY | constants.O_DIRECTORY | constants.O_NOFOLLOW));
56
- }
57
- const protectedDescriptors = [...owned, ...(options.protectedRootFds ?? []),
58
- ...(options.quarantineFd === undefined ? [] : [options.quarantineFd])];
59
- if (protectedDescriptors.length > 64)
60
- throw new BrokerError("too_many_protected_roots", 422);
61
- this.protectedIdentities = protectedDescriptors.map(fd => {
62
- const s = fstatSync(fd, { bigint: true });
63
- if (!s.isDirectory())
64
- throw new BrokerError("invalid_protected_root", 422);
65
- return `${s.dev}:${s.ino}`;
66
- });
67
- this.ownedDescriptors = owned;
68
- this.protectedDescriptors = protectedDescriptors;
69
- this.run(5, "");
70
- }
71
- catch (error) {
72
- for (const fd of owned)
73
- closeSync(fd);
74
- throw error;
75
- }
76
- }
77
- close() {
78
- if (!this.closed)
79
- for (const fd of this.ownedDescriptors)
80
- closeSync(fd);
81
- this.closed = true;
82
- } // Borrowed root/protected FDs remain engine-owned.
83
- run(operation, path, identity = "", content = Buffer.alloc(0)) {
84
- if (this.closed)
85
- throw new BrokerError("filesystem_root_closed");
86
- if (this.options.startupLockFd !== undefined && startupLockIdentity(this.options.startupLockFd) !== this.lockIdentity) {
87
- throw new BrokerError("startup_lock_changed");
88
- }
89
- const root = fstatSync(this.options.rootFd, { bigint: true });
90
- if (!root.isDirectory() || `${root.dev}:${root.ino}` !== this.rootIdentity)
91
- throw new BrokerError("filesystem_root_changed");
92
- for (let i = 0; i < this.protectedDescriptors.length; i++) {
93
- const s = fstatSync(this.protectedDescriptors[i], { bigint: true });
94
- if (!s.isDirectory() || `${s.dev}:${s.ino}` !== this.protectedIdentities[i])
95
- throw new BrokerError("protected_root_changed");
96
- }
97
- const pathBytes = Buffer.from(path, "utf8"), identityBytes = Buffer.from(identity, "utf8");
98
- if ((operation !== 5 && !pathBytes.length) || pathBytes.length > MAX_PATH ||
99
- identityBytes.length > (operation === 7 ? MAX_DATA : MAX_ID - 1) || content.length > MAX_DATA) {
100
- throw new BrokerError("filesystem_request_too_large", 422);
101
- }
102
- const header = Buffer.alloc(24);
103
- header.write("C60F", 0, "ascii");
104
- header[4] = 1;
105
- header[5] = operation;
106
- header[6] = this.protectedDescriptors.length;
107
- header[7] = this.options.quarantineFd === undefined ? 0 : 1;
108
- header.writeUInt32BE(pathBytes.length, 8);
109
- header.writeUInt32BE(identityBytes.length, 12);
110
- header.writeUInt32BE(content.length, 16);
111
- const response = spawnSync(this.options.helperPath, [], {
112
- input: Buffer.concat([header, pathBytes, identityBytes, content]),
113
- stdio: ["pipe", "pipe", "pipe", this.options.rootFd, ...this.protectedDescriptors,
114
- ...(this.options.startupLockFd === undefined ? [] : [this.options.startupLockFd])],
115
- env: environment, timeout: 3000, maxBuffer: MAX_DATA + MAX_ID + 32,
116
- });
117
- if (response.error || response.status !== 0 || response.signal || response.stderr?.length) {
118
- throw new FilesystemHelperError("helper_interrupted", [4, 9, 11].includes(operation));
119
- }
120
- const out = response.stdout;
121
- if (!out || out.length < 16 || out.toString("ascii", 0, 4) !== "C60R" || out[4] !== 1 ||
122
- out[6] || out[7] || out.readUInt32BE(12) || out.readUInt32BE(8) !== out.length - 16) {
123
- throw new FilesystemHelperError("invalid_helper_response", [4, 9, 11].includes(operation));
124
- }
125
- const payload = out.subarray(16), status = out[5];
126
- if (status !== 0)
127
- throw new FilesystemHelperError(payload.toString("ascii"), status === 7);
128
- return payload;
129
- }
130
- /** Engine-only raw snapshot APIs. Never exported in model/session views. */
131
- inspectTree(path = ".") {
132
- return this.tree(path).entries;
133
- }
134
- tree(path) {
135
- relativePath(path);
136
- const raw = decoder.decode(this.run(6, path));
137
- const entries = JSON.parse(raw);
138
- if (!Array.isArray(entries) || entries.length > 1024 || entries.some(entry => !entry || typeof entry.path !== "string" || !["file", "directory"].includes(entry.type) || typeof entry.identity !== "string")) {
139
- throw new FilesystemHelperError("invalid_tree_response", false);
140
- }
141
- return { raw, entries };
142
- }
143
- readBytes(path, identity) {
144
- relativePath(path);
145
- return this.run(2, path, identity ?? this.run(1, path).toString("ascii"));
146
- }
147
- writeBytes(path, content, identity) {
148
- relativePath(path);
149
- this.run(4, path, identity ?? this.run(3, path).toString("ascii"), content);
150
- }
151
- absentIdentity(path) {
152
- const identity = this.run(3, relativePath(path)).toString("ascii");
153
- if (!identity.endsWith("|absent"))
154
- throw new FilesystemHelperError("unexpected_existing_target", false);
155
- return identity;
156
- }
157
- makeDirectory(path) {
158
- relativePath(path);
159
- this.run(15, path, this.run(3, path).toString("ascii"));
160
- }
161
- setMode(path, mode) {
162
- relativePath(path);
163
- if (!Number.isInteger(mode) || mode < 0 || mode > 0o777 || (mode & 0o22))
164
- throw new BrokerError("unsafe_mode", 422);
165
- const data = Buffer.alloc(4);
166
- data.writeUInt32BE(mode);
167
- this.run(16, path, this.run(17, path).toString("ascii"), data);
168
- }
169
- remove(path, directory = false, expectedIdentity) {
170
- relativePath(path);
171
- const identity = expectedIdentity ?? this.run(directory ? 13 : 8, path).toString("ascii");
172
- this.run(directory ? 14 : 9, path, identity, Buffer.from(`q-${randomUUID()}`));
173
- }
174
- resource(path, operation, identity) {
175
- return { kind: "filesystem", root: this.options.root,
176
- ...(this.options.rootId === undefined ? {} : { rootId: this.options.rootId }),
177
- path, operation, identityDigest: digest(identity) };
178
- }
179
- treeEffect(input, searching) {
180
- if (!input || typeof input !== "object" || Array.isArray(input) ||
181
- Object.keys(input).some(k => !["path", ...(searching ? ["query", "caseSensitive"] : [])].includes(k)) ||
182
- (input.path !== undefined && typeof input.path !== "string") ||
183
- (searching && (typeof input.query !== "string" || !input.query || input.query.length > 256)) ||
184
- (input.caseSensitive !== undefined && typeof input.caseSensitive !== "boolean"))
185
- throw new BrokerError("invalid_tool_arguments", 400);
186
- const path = relativePath(input.path ?? ".");
187
- const initial = this.tree(path);
188
- const resources = (entries) => entries.map(entry => this.resource(entry.path, "read", entry.identity));
189
- let used = false;
190
- return {
191
- resources: resources(initial.entries),
192
- revalidate: () => {
193
- try {
194
- return resources(this.tree(path).entries);
195
- }
196
- catch {
197
- return [this.resource(path, "read", "unresolvable-tree")];
198
- }
199
- },
200
- execute: () => {
201
- if (used)
202
- throw new BrokerError("effect_already_used");
203
- used = true;
204
- try {
205
- this.run(7, path, initial.raw);
206
- if (!searching)
207
- return { success: true, text: JSON.stringify(initial.entries.map(({ path, type }) => ({ path, type }))) };
208
- const matches = [], binaryFilesSkipped = [];
209
- const query = input.caseSensitive ? input.query : input.query.toLowerCase();
210
- let bytes = 0, truncated = false;
211
- // Every file examined was declared and authorized, including files
212
- // with no matches. No content is read during prepare/revalidate.
213
- for (const entry of initial.entries)
214
- if (entry.type === "file") {
215
- const content = this.readBytes(entry.path, entry.identity);
216
- bytes += content.length;
217
- if (bytes > 16 * MAX_DATA)
218
- throw new FilesystemHelperError("search_too_large", false);
219
- let text;
220
- try {
221
- text = decoder.decode(content);
222
- }
223
- catch {
224
- binaryFilesSkipped.push(entry.path);
225
- continue;
226
- }
227
- text.split("\n").forEach((line, index) => {
228
- if ((input.caseSensitive ? line : line.toLowerCase()).includes(query)) {
229
- if (matches.length < 1000)
230
- matches.push({ path: entry.path, line: index + 1, text: line.slice(0, 4096) });
231
- else
232
- truncated = true;
233
- }
234
- });
235
- }
236
- this.run(7, path, initial.raw);
237
- return { success: true, text: JSON.stringify({ matches, binaryFilesSkipped, truncated }) };
238
- }
239
- catch (error) {
240
- if (error instanceof FilesystemHelperError && !error.uncertain)
241
- return { success: false, text: error.message };
242
- throw error;
243
- }
244
- },
245
- };
246
- }
247
- namespaceEffect(input, moving) {
248
- if (this.options.quarantineFd === undefined)
249
- throw new BrokerError("filesystem_quarantine_required", 422);
250
- if (!input || typeof input !== "object" || Array.isArray(input) ||
251
- Object.keys(input).some(k => !["path", ...(moving ? ["destination"] : [])].includes(k)) ||
252
- typeof input.path !== "string" || (moving && typeof input.destination !== "string"))
253
- throw new BrokerError("invalid_tool_arguments", 400);
254
- const path = relativePath(input.path), destination = moving ? relativePath(input.destination) : "";
255
- const data = Buffer.from(destination), probe = moving ? 10 : 8;
256
- const identity = this.run(probe, path, "", data).toString("ascii");
257
- const resources = (actual) => {
258
- const [source, target] = actual.split("\n");
259
- return [this.resource(path, "delete", source), ...(moving ? [this.resource(destination, "write", target)] : [])];
260
- };
261
- let used = false;
262
- return {
263
- resources: resources(identity),
264
- revalidate: () => {
265
- try {
266
- return resources(this.run(probe, path, "", data).toString("ascii"));
267
- }
268
- catch {
269
- return [this.resource(path, "delete", "unresolvable-namespace")];
270
- }
271
- },
272
- execute: () => {
273
- if (used)
274
- throw new BrokerError("effect_already_used");
275
- used = true;
276
- const token = Buffer.from(`q-${randomUUID()}`);
277
- let content = token;
278
- if (moving) {
279
- const header = Buffer.alloc(4);
280
- header.writeUInt32BE(data.length);
281
- content = Buffer.concat([header, data, token]);
282
- }
283
- try {
284
- this.run(moving ? 11 : 9, path, identity, content);
285
- return { success: true, text: moving ? "File moved." : "File deleted." };
286
- }
287
- catch (error) {
288
- if (error instanceof FilesystemHelperError && !error.uncertain)
289
- return { success: false, text: error.message };
290
- throw error;
291
- }
292
- },
293
- };
294
- }
295
- arguments(input, writing) {
296
- if (!input || typeof input !== "object" || Array.isArray(input) ||
297
- Object.keys(input).some(k => !["path", ...(writing ? ["content"] : [])].includes(k)) ||
298
- typeof input.path !== "string" || (writing && typeof input.content !== "string")) {
299
- throw new BrokerError("invalid_tool_arguments", 400);
300
- }
301
- const path = relativePath(input.path);
302
- if (path === "." || decoder.decode(Buffer.from(path)) !== path)
303
- throw new BrokerError("invalid_tool_arguments", 400);
304
- const content = writing ? Buffer.from(input.content, "utf8") : Buffer.alloc(0);
305
- if ((writing && decoder.decode(content) !== input.content) || content.length > MAX_DATA)
306
- throw new BrokerError("invalid_tool_arguments", 400);
307
- return { path, content };
308
- }
309
- prepare(input, writing) {
310
- const { path, content } = this.arguments(input, writing);
311
- const probe = writing ? 3 : 1;
312
- let identity;
313
- try {
314
- identity = this.run(probe, path).toString("ascii");
315
- }
316
- catch (error) {
317
- if (error instanceof FilesystemHelperError)
318
- throw new BrokerError(`filesystem_${error.code}`, 422);
319
- throw error;
320
- }
321
- const resource = (actual) => ({
322
- kind: "filesystem", root: this.options.root,
323
- ...(this.options.rootId === undefined ? {} : { rootId: this.options.rootId }),
324
- path, operation: writing ? "write" : "read", identityDigest: digest(actual),
325
- });
326
- return {
327
- resources: [resource(identity)],
328
- revalidate: () => {
329
- try {
330
- return [resource(this.run(probe, path).toString("ascii"))];
331
- }
332
- catch (error) {
333
- // An unresolvable target can never revive an earlier allowed handle.
334
- // Returning a distinct trusted failed-resolution identity makes the
335
- // core durably invalidate the old action before any effect dispatch.
336
- if (error instanceof FilesystemHelperError)
337
- return [resource(`unresolvable:${error.code}`)];
338
- throw error;
339
- }
340
- },
341
- execute: () => {
342
- try {
343
- const result = this.run(writing ? 4 : 2, path, identity, content);
344
- if (writing)
345
- return { success: true, text: "File written." };
346
- try {
347
- return { success: true, text: decoder.decode(result) };
348
- }
349
- catch {
350
- return { success: false, text: "filesystem:invalid_utf8" };
351
- }
352
- }
353
- catch (error) {
354
- if (error instanceof FilesystemHelperError && !error.uncertain)
355
- return { success: false, text: error.message };
356
- throw error;
357
- }
358
- },
359
- };
360
- }
361
- catalog() {
362
- return new Map([...filesystemToolDefinitions()].filter(([name]) => this.options.quarantineFd !== undefined || !["delete_file", "move_file"].includes(name)).map(([name, definition]) => [name, { ...definition, prepare: (input) => name === "read_file" || name === "write_file" ? this.prepare(input, name === "write_file") :
363
- name === "list_files" || name === "search_files" ? this.treeEffect(input, name === "search_files") : this.namespaceEffect(input, name === "move_file") }]));
364
- }
365
- }
366
- /** Pure metadata for runtime discovery before any workspace/session exists. */
367
- export function filesystemToolDefinitions() {
368
- return new Map([
369
- ["read_file", { name: "read_file", description: "Read a UTF-8 regular file under the assigned root.",
370
- inputSchema: { type: "object", properties: { path: { type: "string" } }, required: ["path"], additionalProperties: false } }],
371
- ["write_file", { name: "write_file", description: "Write UTF-8 content to one regular file under the assigned root.",
372
- inputSchema: { type: "object", properties: { path: { type: "string" }, content: { type: "string" } },
373
- required: ["path", "content"], additionalProperties: false } }],
374
- ["list_files", { name: "list_files", description: "List a bounded recursive regular-file/directory tree; excludes .git and rejects unsafe entries.",
375
- inputSchema: { type: "object", properties: { path: { type: "string" } }, additionalProperties: false } }],
376
- ["search_files", { name: "search_files", description: "Search UTF-8 files for a literal substring, authorizing every examined file first.",
377
- inputSchema: { type: "object", properties: { path: { type: "string" }, query: { type: "string", minLength: 1, maxLength: 256 },
378
- caseSensitive: { type: "boolean" } }, required: ["query"], additionalProperties: false } }],
379
- ["delete_file", { name: "delete_file", description: "Delete one regular file using verified private quarantine capture.",
380
- inputSchema: { type: "object", properties: { path: { type: "string" } }, required: ["path"], additionalProperties: false } }],
381
- ["move_file", { name: "move_file", description: "Move one regular file to an absent name. Never overwrite an existing destination.",
382
- inputSchema: { type: "object", properties: { path: { type: "string" }, destination: { type: "string" } },
383
- required: ["path", "destination"], additionalProperties: false } }],
384
- ]);
385
- }