code60-transmission-server 0.0.0-stage → 0.1.0-staging.3
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/LICENSE +180 -0
- package/README.engine.md +401 -0
- package/README.md +294 -2
- package/dist/src/broker/filesystem.js +385 -0
- package/dist/src/broker/index.js +734 -0
- package/dist/src/broker/native/README.md +192 -0
- package/dist/src/broker/native/build.js +43 -0
- package/dist/src/broker/native/fs-helper.c +529 -0
- package/dist/src/broker/native/git-helper.c +205 -0
- package/dist/src/broker/policy.js +149 -0
- package/dist/src/broker/startup-lock.js +14 -0
- package/dist/src/broker/types.js +11 -0
- package/dist/src/cli/daemon.js +365 -0
- package/dist/src/cli/helpers.js +104 -0
- package/dist/src/cli/main.js +180 -0
- package/dist/src/config/deployment.js +166 -0
- package/dist/src/config/documents.js +29 -0
- package/dist/src/config/profile-validation.js +123 -0
- package/dist/src/config/schema-graph.js +237 -0
- package/dist/src/config/schema-loader.js +185 -0
- package/dist/src/config/validation-pool.js +105 -0
- package/dist/src/config/validation-protocol.js +1 -0
- package/dist/src/config/validation-worker.js +106 -0
- package/dist/src/config/workflow-language.js +9 -0
- package/dist/src/config/workflow-schema.json +534 -0
- package/dist/src/config/workflow-types.js +1 -0
- package/dist/src/config/workflow-validation.js +95 -0
- package/dist/src/engine/budgets.js +50 -0
- package/dist/src/engine/clocks.js +27 -0
- package/dist/src/engine/commands.js +441 -0
- package/dist/src/engine/contracts.js +11 -0
- package/dist/src/engine/drain-state.js +31 -0
- package/dist/src/engine/effective-permissions.js +120 -0
- package/dist/src/engine/instruction-pins.js +205 -0
- package/dist/src/engine/retries.js +50 -0
- package/dist/src/engine/state.js +1 -0
- package/dist/src/engine/timing.js +23 -0
- package/dist/src/engine/tool-observations.js +87 -0
- package/dist/src/engine/workflow-engine.js +1807 -0
- package/dist/src/main.js +25 -0
- package/dist/src/mcp/catalog.js +71 -0
- package/dist/src/mcp/main.js +24 -0
- package/dist/src/mcp/server.js +116 -0
- package/dist/src/runtime/codex-app-server.js +91 -0
- package/dist/src/runtime/containment.js +82 -0
- package/dist/src/runtime/engine-driver.js +212 -0
- package/dist/src/runtime/json-line-writer.js +192 -0
- package/dist/src/runtime/pinned-instruction-sources.js +24 -0
- package/dist/src/runtime/protocol-client.js +264 -0
- package/dist/src/runtime/protocol-pool.js +183 -0
- package/dist/src/runtime/protocol-projection.js +393 -0
- package/dist/src/runtime/protocol-types.js +1 -0
- package/dist/src/runtime/protocol-worker.js +18 -0
- package/dist/src/runtime/provider-bridge.js +288 -0
- package/dist/src/runtime/provider-credentials.js +41 -0
- package/dist/src/runtime/provider-transport.js +404 -0
- package/dist/src/runtime/runtime-broker.js +213 -0
- package/dist/src/runtime/workspace-instructions.js +120 -0
- package/dist/src/runtime/workspace-view.js +74 -0
- package/dist/src/server/api-contract.json +11086 -0
- package/dist/src/server/api-types.js +1 -0
- package/dist/src/server/application.js +38 -0
- package/dist/src/server/auth.js +67 -0
- package/dist/src/server/broker-handlers.js +242 -0
- package/dist/src/server/control-plane.js +50 -0
- package/dist/src/server/deployment.js +237 -0
- package/dist/src/server/errors.js +22 -0
- package/dist/src/server/history-handlers.js +113 -0
- package/dist/src/server/http.js +124 -0
- package/dist/src/server/paging.js +56 -0
- package/dist/src/server/publication.js +119 -0
- package/dist/src/server/tool-event-handler.js +77 -0
- package/dist/src/server/workspace-handlers.js +34 -0
- package/dist/src/storage/coordinator.js +224 -0
- package/dist/src/storage/startup-lock.js +71 -0
- package/dist/src/storage/store.js +167 -0
- package/dist/src/tools/check-worker.js +81 -0
- package/dist/src/tools/checks.js +106 -0
- package/dist/src/tools/dns.js +248 -0
- package/dist/src/tools/http-contract.js +38 -0
- package/dist/src/tools/http.js +358 -0
- package/dist/src/tools/index.js +177 -0
- package/dist/src/tools/worker-check.js +73 -0
- package/dist/src/workspaces/git.js +227 -0
- package/dist/src/workspaces/index.js +715 -0
- package/examples/deployment.local.json +22 -0
- package/package.json +68 -4
- package/scripts/postinstall.mjs +25 -0
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
# Descriptor-relative filesystem helper
|
|
2
|
+
|
|
3
|
+
This is a small unprivileged POSIX helper for the TypeScript broker, not a general
|
|
4
|
+
shell, filesystem daemon, sandbox, or server. The catalog implements **read_file**,
|
|
5
|
+
**write_file**, **list_files**, **search_files**, **delete_file** and **move_file**.
|
|
6
|
+
Delete/move are advertised only when a private same-filesystem quarantine FD is
|
|
7
|
+
configured. Engine-only directory/mode restoration is not a model-facing tool.
|
|
8
|
+
|
|
9
|
+
## Build and integration
|
|
10
|
+
|
|
11
|
+
Prerequisites: the approved Node 24 runtime and the Mac's existing
|
|
12
|
+
`/usr/bin/clang` (Apple Command Line Tools). No installation, download, npm native
|
|
13
|
+
script bypass, privilege change or setuid program is involved.
|
|
14
|
+
|
|
15
|
+
Normal packaging uses `npm run build` and places the native assets under
|
|
16
|
+
`dist/src/broker/native/.build`.
|
|
17
|
+
The explicit source-development entry point is:
|
|
18
|
+
|
|
19
|
+
```sh
|
|
20
|
+
node --experimental-strip-types -e 'import("./src/broker/native/build.ts").then(m => console.log(m.buildFilesystemHelper()))'
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
This explicitly creates `src/broker/native/.build/fs-helper`. Nothing builds or
|
|
24
|
+
executes on module import. `buildFilesystemHelper({sanitize:true})` builds the
|
|
25
|
+
separate AddressSanitizer/UndefinedBehaviorSanitizer executable with
|
|
26
|
+
`-fno-sanitize-recover=all`. `tsc` alone does not build/copy this executable or the
|
|
27
|
+
C source; use the package build for the complete deployment.
|
|
28
|
+
Pass the absolute trusted executable path to the wrapper as deployment
|
|
29
|
+
configuration.
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
import { constants, openSync } from "node:fs";
|
|
33
|
+
import { NativeFilesystemRoot } from "../filesystem.js";
|
|
34
|
+
|
|
35
|
+
// All values here are engine configuration, never model input.
|
|
36
|
+
const rootFd = openSync(registeredRoot, constants.O_RDONLY |
|
|
37
|
+
constants.O_DIRECTORY | constants.O_NOFOLLOW);
|
|
38
|
+
const filesystem = new NativeFilesystemRoot({
|
|
39
|
+
rootFd, root: "workspace", helperPath: trustedBuiltHelper,
|
|
40
|
+
protectedRootFds: [engineStateFd, otherRegisteredRootFd],
|
|
41
|
+
quarantineFd: enginePrivateSameFilesystemDirectoryFd,
|
|
42
|
+
startupLockFd: alreadyAcquiredStartupWriterBarrierFd,
|
|
43
|
+
});
|
|
44
|
+
const broker = new ActionBroker(database, filesystem.catalog());
|
|
45
|
+
// Bind the session and use the existing broker catalog/invoke facade.
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
The engine owns the borrowed root and additional protected FDs and must keep them
|
|
49
|
+
open and unchanged until the wrapper closes. The wrapper pins their dev/inode
|
|
50
|
+
identity and rejects descriptor replacement. `close()` closes only its own
|
|
51
|
+
installation/helper-directory descriptors, never the borrowed descriptors.
|
|
52
|
+
Caller configuration must protect all engine state, source/build/install roots,
|
|
53
|
+
credential directories, and other registered roots that must not overlap. The
|
|
54
|
+
wrapper automatically protects its actual module installation root and helper
|
|
55
|
+
directory; a deployment with additional source/build/install locations must add
|
|
56
|
+
those directory FDs too.
|
|
57
|
+
|
|
58
|
+
The helper rejects any physical root containment/overlap in either direction,
|
|
59
|
+
including case/path aliases, against those protected FDs. Thus no managed
|
|
60
|
+
tool/reset scope may replace the helper, its source, engine, or state. Reset and
|
|
61
|
+
workspace registration must enforce the same protected scope, not assume a tool
|
|
62
|
+
check makes a later Git cleanup safe. The engine must resolve/register the
|
|
63
|
+
physical root before constructing this object; this helper does not grant a
|
|
64
|
+
model permission to select a root or register a workspace.
|
|
65
|
+
|
|
66
|
+
## Fixed protocol and actual access
|
|
67
|
+
|
|
68
|
+
One request/one process, no command-line options. Child stdio is protocol stdin,
|
|
69
|
+
stdout, stderr; fd 3 is the sole assigned root; fd 4 onward are at most 64 explicit
|
|
70
|
+
protected directory descriptors, including private quarantine when configured.
|
|
71
|
+
The already acquired startup barrier's shared open description follows those
|
|
72
|
+
descriptors. No database or credential descriptors are inherited. The borrowed
|
|
73
|
+
barrier FD is validated for identity, never unlocked or reacquired by an effect
|
|
74
|
+
child. Environment is only fixed `PATH=/usr/bin:/bin` and `LC_ALL=C`, with no
|
|
75
|
+
ambient proxy, loader or secret environment. The wrapper spawns only the trusted
|
|
76
|
+
absolute helper executable, never a shell or PATH-selected model command.
|
|
77
|
+
|
|
78
|
+
Request header is 24 bytes: `C60F`, version byte 1, fixed operation byte, protected
|
|
79
|
+
descriptor count byte, private-quarantine flag byte, then big-endian 32-bit path/identity/content
|
|
80
|
+
lengths and one zero 32-bit word. Body is exact path, identity, content bytes with
|
|
81
|
+
no trailing data. Fixed operations are probe-read (1), read (2), probe-write (3),
|
|
82
|
+
write (4), root validation (5), tree probe/read (6/7), delete probe/effect (8/9),
|
|
83
|
+
move probe/effect (10/11), engine-only directory-delete probe/effect (13/14),
|
|
84
|
+
directory creation (15), mode change (16) and mode probe (17). Operation 12 is
|
|
85
|
+
forbidden. The model never supplies protocol fields. Reply is a 16-byte `C60R` header with version/status/length
|
|
86
|
+
and exact payload. Errors contain fixed codes, not native paths or file metadata.
|
|
87
|
+
|
|
88
|
+
Limits: 4096 path bytes, 64 components, 255 bytes/component, 8191 identity bytes,
|
|
89
|
+
and 1 MiB file/content. A tree is bounded to 1024 entries and excludes `.git`.
|
|
90
|
+
The tree-read identity envelope is separately bounded to 1 MiB. Search authorizes
|
|
91
|
+
every examined entry before reading content, with a 16 MiB scan limit, 1000
|
|
92
|
+
matches and 4096 characters per reported line. The wrapper kills a helper after
|
|
93
|
+
3 seconds and bounds captured output. Oversize inputs/files fail rather than
|
|
94
|
+
truncate. Malformed/truncated/extra input fails before effects.
|
|
95
|
+
|
|
96
|
+
Every operation reopens from the inherited physical root using `openat`,
|
|
97
|
+
`O_NOFOLLOW`, and pinned directory descriptors. Components are normalized relative
|
|
98
|
+
segments, never empty, `.`, `..`, absolute, backslash, or ASCII-case variants of
|
|
99
|
+
`.git`. Directory-entry bytes must match exactly, including filesystem case and
|
|
100
|
+
Unicode normalization aliases. Symlinks, nonregular targets, multiply linked
|
|
101
|
+
files, foreign-owned targets and group/world-writable files/directories fail
|
|
102
|
+
closed. Missing intermediate directories are not automatically created.
|
|
103
|
+
|
|
104
|
+
Identity includes the actual root/ancestor dev/inodes and actual opened file
|
|
105
|
+
dev/inode/mode/uid/gid/link-count/size/nanosecond-mtime/nanosecond-ctime. It is a
|
|
106
|
+
**stat identity**, not a content hash. Absent creation binds the exact checked
|
|
107
|
+
parent chain. Each actual read/write rechecks that identity on the same opened
|
|
108
|
+
file descriptor used for I/O. There is no `realpath`-then-open authority check.
|
|
109
|
+
|
|
110
|
+
No destructive truncate occurs before identity validation. Existing writes use
|
|
111
|
+
`pwrite` and `ftruncate` on the verified FD. New creation uses
|
|
112
|
+
`O_CREAT|O_EXCL|O_NOFOLLOW`, so a target appearing after probe fails rather than
|
|
113
|
+
being overwritten. Writes take a nonblocking advisory lock, sync the data (and
|
|
114
|
+
new-file parent), and verify resulting content. Reads compare pre/post identity
|
|
115
|
+
and do not expose bytes after a detected mutation. Relevant changes before claim
|
|
116
|
+
or dispatch permanently invalidate the old authority, even if the old target is
|
|
117
|
+
later restored.
|
|
118
|
+
|
|
119
|
+
One helper handles each probe/effect and exits; there is no persistent process or
|
|
120
|
+
open target handle to dispose between broker stages. The actual effect helper
|
|
121
|
+
independently validates its expected identity again immediately at I/O.
|
|
122
|
+
Interrupted/partial writes are uncertain and never automatically retried.
|
|
123
|
+
Pre-effect known denials return structured failure; invalid UTF-8 reads fail
|
|
124
|
+
without exposing decoded/replacement content.
|
|
125
|
+
|
|
126
|
+
### Initial denial privacy
|
|
127
|
+
|
|
128
|
+
Helper status codes are trusted internal control flow, not initial model-facing
|
|
129
|
+
diagnostics. Until actual-resource authorization succeeds, the central broker
|
|
130
|
+
coalesces preparation/resolution failures and policy denials into the same durable
|
|
131
|
+
denied action: `resources: []`, no approval, no target-derived reason/status, and
|
|
132
|
+
canonical SHA-256 of that displayed ActionSpec. Empty denied resources mean no
|
|
133
|
+
authorized resource identity is exposed; they are never an executable grant.
|
|
134
|
+
Direct authorization, session action reads and receipt replays use this shape.
|
|
135
|
+
`bound.invoke` reports only `{success:false,text:"broker:denied"}`. Denied handles
|
|
136
|
+
fail claim state checks before any new target resolution.
|
|
137
|
+
|
|
138
|
+
Useful execution diagnostics, such as invalid UTF-8, remain available only after
|
|
139
|
+
actual-resource authorization. Initial missing/unsafe-path details are therefore
|
|
140
|
+
intentionally not disclosed, even if a requested spelling might have been allowed.
|
|
141
|
+
|
|
142
|
+
Trusted operator audit is stored separately in `broker_policy_audit`. It has no
|
|
143
|
+
session-facing accessor and must never be joined/serialized into adapter action,
|
|
144
|
+
receipt, claim or model responses. Future operator HTTP inspection requires
|
|
145
|
+
explicit audience/scope mapping, not generic database row serialization.
|
|
146
|
+
This result-equality policy is not a constant-time/host timing-isolation claim.
|
|
147
|
+
|
|
148
|
+
## Threat boundary and remaining requirements
|
|
149
|
+
|
|
150
|
+
The broker's synchronous final gate records durable started intent and active
|
|
151
|
+
work before invoking this synchronous helper. Applicable engine-controlled
|
|
152
|
+
filesystem operations must share that coordinator. Model/runtime native tools,
|
|
153
|
+
arbitrary subprocesses, unmediated MCP, recovery's old writers and all other
|
|
154
|
+
mutation routes still must be disabled, contained, stopped or mediated. Calling
|
|
155
|
+
an engine-controlled writer "same UID" does not exempt it from enforcement.
|
|
156
|
+
|
|
157
|
+
The helper pins objects and checks before/after identity; it does **not** provide
|
|
158
|
+
a hostile-host atomic snapshot/CAS or mandatory filesystem lock. An unrelated
|
|
159
|
+
independent same-UID process can race multiple kernel syscalls by moving a pinned
|
|
160
|
+
ancestor, introducing hardlinks, or modifying bytes. Advisory locking does not
|
|
161
|
+
stop that actor. This is a documented host limitation, not permission to ignore
|
|
162
|
+
model-induced races, old writers, verifier isolation, or external-edit conflicts.
|
|
163
|
+
|
|
164
|
+
The engine must compare recorded workspace/content identities,
|
|
165
|
+
invalidate affected evaluation, stop on detected external change, and require
|
|
166
|
+
conflict-specific overwrite permission. A fresh action request is not that
|
|
167
|
+
permission. This wrapper does not itself implement workspace ownership,
|
|
168
|
+
registration, Git reset, conflict consent, whole-workspace snapshots, or HTTP
|
|
169
|
+
authentication.
|
|
170
|
+
|
|
171
|
+
Delete/move bind distinct source/destination parent and name identities. Darwin
|
|
172
|
+
rename-excl captures into private same-filesystem quarantine, then verifies the
|
|
173
|
+
captured object before deletion or no-overwrite installation. A conflicting
|
|
174
|
+
capture is restored only without replacing another entry; uncertain captures
|
|
175
|
+
are preserved. This is not conditional unlink-by-file-FD, and no hostile-host
|
|
176
|
+
atomicity claim is made. Unsupported platform primitives fail closed.
|
|
177
|
+
|
|
178
|
+
## Validation
|
|
179
|
+
|
|
180
|
+
```sh
|
|
181
|
+
./node_modules/.bin/vitest run tests/pilot/broker.test.ts tests/pilot/broker-fs.test.ts --cache=false
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
The filesystem suite runs the actual optimized helper and ASan+UBSan helper
|
|
185
|
+
against fresh 0700 `/private/tmp/code60-broker-fs-*` fixtures, outside the actual
|
|
186
|
+
engine installation. It tests actual nested read/create/overwrite/truncation,
|
|
187
|
+
verifier project-read/scratch-write separation, symlinks/hardlinks/special files,
|
|
188
|
+
case/Unicode aliases, switched target/parent restoration, mtime restoration,
|
|
189
|
+
absent-parent creation conflicts, actual protected-root overlap, protocol
|
|
190
|
+
negative cases and 1 MiB worst-case content. It is not arbitrary-host isolation,
|
|
191
|
+
network containment or complete server conformance certification. Extended
|
|
192
|
+
namespace/tree cases are in `tests/broker/extended-filesystem.test.ts`.
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import { chmodSync, mkdirSync, renameSync, rmSync } from "node:fs";
|
|
3
|
+
import { randomUUID } from "node:crypto";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
export function buildFilesystemHelper(options = {}) {
|
|
7
|
+
return build("fs", options);
|
|
8
|
+
}
|
|
9
|
+
export function buildGitHelper(options = {}) {
|
|
10
|
+
return build("git", options);
|
|
11
|
+
}
|
|
12
|
+
function build(kind, options) {
|
|
13
|
+
const directory = fileURLToPath(new URL("./", import.meta.url));
|
|
14
|
+
const outDir = options.outputDirectory ?? join(directory, ".build");
|
|
15
|
+
const output = join(outDir, `${kind}-helper${options.sanitize ? "-sanitized" : ""}`);
|
|
16
|
+
const candidate = `${output}.${randomUUID()}.tmp`;
|
|
17
|
+
mkdirSync(outDir, { recursive: true, mode: 0o700 });
|
|
18
|
+
const flags = options.sanitize ? ["-O1", "-g", "-fsanitize=address,undefined", "-fno-sanitize-recover=all", "-fno-omit-frame-pointer"] : ["-O2"];
|
|
19
|
+
if (options.minimumMacOSVersion)
|
|
20
|
+
flags.push(`-mmacosx-version-min=${options.minimumMacOSVersion}`);
|
|
21
|
+
const built = spawnSync("/usr/bin/clang", ["-std=c17", "-Wall", "-Wextra", "-Werror", ...flags,
|
|
22
|
+
join(directory, `${kind}-helper.c`), "-o", candidate], {
|
|
23
|
+
encoding: "utf8", timeout: 30_000, maxBuffer: 1_048_576, env: { PATH: "/usr/bin:/bin", LC_ALL: "C" },
|
|
24
|
+
});
|
|
25
|
+
if (built.error || built.status !== 0) {
|
|
26
|
+
rmSync(candidate, { force: true });
|
|
27
|
+
if (built.error?.code === "ENOENT") {
|
|
28
|
+
throw new Error("Xcode Command Line Tools (/usr/bin/clang) are required to build Code60 native helpers. Run: xcode-select --install");
|
|
29
|
+
}
|
|
30
|
+
throw new Error(`Filesystem helper build failed: ${built.error?.message ?? built.stderr}`);
|
|
31
|
+
}
|
|
32
|
+
chmodSync(candidate, 0o700);
|
|
33
|
+
// Never truncate an inode another native child may currently execute. Build
|
|
34
|
+
// callers can overlap; publishing a fresh inode also avoids stale macOS
|
|
35
|
+
// executable/code-signing cache state from in-place relinking.
|
|
36
|
+
try {
|
|
37
|
+
renameSync(candidate, output);
|
|
38
|
+
}
|
|
39
|
+
finally {
|
|
40
|
+
rmSync(candidate, { force: true });
|
|
41
|
+
}
|
|
42
|
+
return output;
|
|
43
|
+
}
|