@shumkov/orchestra 0.8.0 → 0.10.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/docs/codex-app-server-compatibility.md +75 -9
- package/index.js +2 -1
- package/lib/codex/app-server-client.js +65 -12
- package/lib/codex/preflight.js +8 -2
- package/lib/codex/protocol-schema.json +4 -0
- package/lib/tmux/orphan-sweep.js +28 -10
- package/lib/tmux/tmux-runner.js +60 -5
- package/package.json +1 -1
|
@@ -33,10 +33,23 @@ reads without a legacy `workspaceWrite` request policy.
|
|
|
33
33
|
- Orchestra baseline: `v0.5.0`, commit
|
|
34
34
|
`b788efb1f99e5fbf8669d4efa7ce5a1f9c0f7dcb`.
|
|
35
35
|
- Codex: `codex-cli 0.145.0`.
|
|
36
|
-
-
|
|
37
|
-
`
|
|
38
|
-
-
|
|
36
|
+
- Reviewed native target receipts:
|
|
37
|
+
- `aarch64-apple-darwin`:
|
|
38
|
+
`codex-cli 0.145.0`,
|
|
39
|
+
`1da3f4e0e96028b8a771814293c3033dafd1971f943f6c7e79b0897fe705f590`;
|
|
40
|
+
- `x86_64-unknown-linux-musl`:
|
|
41
|
+
`codex-cli 0.145.0`,
|
|
42
|
+
`a2a05dafaa1acb002a45eaec0a462de5b13694fcfcd7bc43305f14781ce7be14`.
|
|
43
|
+
- The deprecated scalar binary checksum remains macOS-arm64 provenance.
|
|
44
|
+
Runtime checks resolve the current target receipt lazily.
|
|
45
|
+
- Target-specific raw hashes pin the four deterministic stable and experimental
|
|
46
|
+
`ClientRequest.json` and legacy protocol files in
|
|
39
47
|
`tests/fixtures/codex-app-server-0.145.0/manifest.json`.
|
|
48
|
+
- The nondeterministically serialized stable and experimental v2 bundles are
|
|
49
|
+
enforced only through their shared recursively canonical hashes:
|
|
50
|
+
`02d8bf6651cd504bff0335f566c011e51ba77c5cc0538cb64ca7ac57739a1597`
|
|
51
|
+
and
|
|
52
|
+
`1bc09dedc506075562d4d49b702ecab6d947dd5a8c2a9014a5cde592a0938efb`.
|
|
40
53
|
- `turn/steer` still requires `threadId`, `input`, and `expectedTurnId`.
|
|
41
54
|
- The authenticated direct-binary checker passed every named-profile evidence
|
|
42
55
|
bit on 2026-07-26. This Mac has no configured session launcher, so the local
|
|
@@ -69,14 +82,41 @@ node scripts/spikes/codex-app-server-real.mjs \
|
|
|
69
82
|
--binary /absolute/versioned/path/to/codex \
|
|
70
83
|
--codex-home /absolute/non-temporary/codex-home \
|
|
71
84
|
--workspace /absolute/workspace \
|
|
72
|
-
--
|
|
85
|
+
--tmpdir /absolute/private/child-tmpdir \
|
|
86
|
+
--daemon-secret-root /absolute/private/child-tmpdir \
|
|
87
|
+
--external-network-host 1.1.1.1 \
|
|
88
|
+
--external-network-port 443
|
|
73
89
|
```
|
|
74
90
|
|
|
75
91
|
Environment fallbacks are `POLYGRAM_CODEX_BIN`, `ORCHESTRA_CODEX_HOME`,
|
|
76
|
-
`ORCHESTRA_CODEX_WORKSPACE`, `
|
|
77
|
-
path-delimited
|
|
92
|
+
`ORCHESTRA_CODEX_WORKSPACE`, `ORCHESTRA_CODEX_TMPDIR`,
|
|
93
|
+
`ORCHESTRA_SESSION_LAUNCHER`, and the path-delimited
|
|
94
|
+
`ORCHESTRA_CODEX_DAEMON_SECRET_ROOTS`. Linux also requires
|
|
95
|
+
`ORCHESTRA_CODEX_EXTERNAL_NETWORK_HOST` and
|
|
96
|
+
`ORCHESTRA_CODEX_EXTERNAL_NETWORK_PORT` when the corresponding flags are not
|
|
97
|
+
passed. The endpoint must be an operator-approved, globally routable numeric
|
|
98
|
+
IPv4 address and port that are reachable from the service environment; a
|
|
99
|
+
hostname or private, loopback, link-local, benchmark, or documentation address
|
|
100
|
+
is rejected. The checker requires the same endpoint to remain reachable from
|
|
101
|
+
the host immediately before and after the sandbox-denial probe.
|
|
78
102
|
Each synthetic daemon-secret root must contain an owner-only regular
|
|
79
103
|
`.orchestra-codex-u1a-deny-probe` sentinel with no symlink or hard-link alias.
|
|
104
|
+
On Linux, the child `TMPDIR` must be an existing canonical service-user-owned
|
|
105
|
+
directory with exact mode `0700`, separate from both the workspace and
|
|
106
|
+
`CODEX_HOME`. The same exact directory must also be supplied as a
|
|
107
|
+
`--daemon-secret-root`, so the filesystem enforcement probe proves that its
|
|
108
|
+
sentinel is unreadable from `command/exec`. Darwin does not require or validate
|
|
109
|
+
this additional child-temp input.
|
|
110
|
+
|
|
111
|
+
Before Linux app-server startup, the checker requires the reviewed profile to
|
|
112
|
+
run a bounded harmless command using the Codex 0.145.0 CLI surface:
|
|
113
|
+
|
|
114
|
+
```text
|
|
115
|
+
codex sandbox --permission-profile polygram-session -- /bin/true
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
The checker does not trace bubblewrap. The final bounded VPS operational gate
|
|
119
|
+
must separately prove that this exact invocation reaches `/usr/bin/bwrap`.
|
|
80
120
|
|
|
81
121
|
The checker never creates, copies, reads, hashes, or prints authentication
|
|
82
122
|
contents. `CODEX_HOME` must already exist, be canonical, non-temporary, owned
|
|
@@ -192,15 +232,22 @@ direct-binary run; it does not clear the broader hosted-tool enforcement gate.
|
|
|
192
232
|
|
|
193
233
|
## Profile provenance
|
|
194
234
|
|
|
195
|
-
|
|
235
|
+
Two live pinned-runtime rollout runs found the exact profile at top-level
|
|
196
236
|
`activePermissionProfile` in both `thread/start` and `thread/resume`
|
|
197
237
|
responses. The value is fixture-pinned as `{id: "polygram-session",
|
|
198
238
|
extends: null}`. Both attachment responses also return exactly one concrete
|
|
199
239
|
`runtimeWorkspaceRoots` entry equal to the owned cwd. Orchestra exposes that
|
|
200
240
|
entry only as `{count: 1, sha256: [sha256(ownedCwd)]}`.
|
|
201
241
|
|
|
202
|
-
|
|
203
|
-
|
|
242
|
+
Neither rollout run emitted `thread/settings/updated` during fresh or resume
|
|
243
|
+
attachment within the bounded wait. An exact attachment response is therefore
|
|
244
|
+
sufficient profile provenance. If an attachment-time notification does appear,
|
|
245
|
+
the checker still requires its complete static settings view to be exact.
|
|
246
|
+
Notifications caused by explicit experimental `thread/settings/update` calls
|
|
247
|
+
are characterized separately and do not establish attachment-time emission.
|
|
248
|
+
|
|
249
|
+
Fresh and resume responses, and any observed `thread/settings/updated`, use the
|
|
250
|
+
same legacy compatibility envelope:
|
|
204
251
|
|
|
205
252
|
```json
|
|
206
253
|
{
|
|
@@ -323,6 +370,25 @@ passed every control and denial. The Unix-socket control uses a short,
|
|
|
323
370
|
explicitly length-guarded macOS pathname and an asynchronous host runner so
|
|
324
371
|
the control cannot false-fail while Node's listener is blocked.
|
|
325
372
|
|
|
373
|
+
On Linux x64, the same gate additionally requires host-positive and
|
|
374
|
+
sandbox-negative reads of the owned process's `/proc` command line,
|
|
375
|
+
environment, and inherited file descriptor, plus a bounded `strace` attach
|
|
376
|
+
probe. Local TCP, UDP, DNS-protocol, Unix-socket, and direct inherited-FD
|
|
377
|
+
checks remain mandatory. Only the macOS Keychain checks are explicitly
|
|
378
|
+
inapplicable on Linux; an unavailable Linux process, IPC, or network probe
|
|
379
|
+
stops the gate.
|
|
380
|
+
|
|
381
|
+
UDP and DNS listeners remain active until their command completes and for a
|
|
382
|
+
bounded settle interval afterward, so delayed packets cannot be classified as
|
|
383
|
+
denied early. An exact Linux `strace` ESRCH/`No such process` result counts as
|
|
384
|
+
PID-namespace denial only when host-side process liveness and attach controls
|
|
385
|
+
pass both before and after the sandbox attempt; helper failures remain
|
|
386
|
+
fail-closed. The direct inherited-FD probe intentionally checks the production
|
|
387
|
+
app-server spawn boundary, which receives only stdio pipes. The separate
|
|
388
|
+
`/proc/<pid>/fd` probe checks whether a sandboxed same-UID command can recover a
|
|
389
|
+
descriptor inherited by another owned process; no secret descriptor is
|
|
390
|
+
deliberately passed to app-server.
|
|
391
|
+
|
|
326
392
|
## Transport-cut classification is deterministic; persistence is unproved
|
|
327
393
|
|
|
328
394
|
The checker now tracks every currently allowlisted state-changing request
|
package/index.js
CHANGED
|
@@ -25,6 +25,7 @@ const {
|
|
|
25
25
|
CodexAppServerClient,
|
|
26
26
|
CodexAppServerError,
|
|
27
27
|
protocolSchema: codexProtocolSchema,
|
|
28
|
+
resolveCodexTargetPin,
|
|
28
29
|
} = require('./lib/codex/app-server-client');
|
|
29
30
|
const sdkProcess = require('./lib/process/sdk-process');
|
|
30
31
|
const { SdkProcess, extractAssistantText, sumUsage, makeInputController } = sdkProcess;
|
|
@@ -52,7 +53,7 @@ const approvalsStore = require('./lib/approvals/store');
|
|
|
52
53
|
|
|
53
54
|
module.exports = {
|
|
54
55
|
// pool + driver
|
|
55
|
-
Process, UnsupportedOperationError, ProcessManager, CALLBACK_TO_EVENT, CliProcess, CodexProcess, CodexAppServerClient, CodexAppServerError, CodexPreflightError, SdkProcess, extractAssistantText, sumUsage, makeInputController, createProcessFactory, pickBackend, preflightCodexRuntime, reattestCodexStaticPolicy, createCodexSpawnProfile, assertCodexSpawnProfile, attestPinnedCodexHome, buildCodexAppServerEnv, codexProtocolSchema,
|
|
56
|
+
Process, UnsupportedOperationError, ProcessManager, CALLBACK_TO_EVENT, CliProcess, CodexProcess, CodexAppServerClient, CodexAppServerError, CodexPreflightError, SdkProcess, extractAssistantText, sumUsage, makeInputController, createProcessFactory, pickBackend, preflightCodexRuntime, reattestCodexStaticPolicy, createCodexSpawnProfile, assertCodexSpawnProfile, attestPinnedCodexHome, buildCodexAppServerEnv, resolveCodexTargetPin, codexProtocolSchema,
|
|
56
57
|
// channels bridge (MCP injection protocol)
|
|
57
58
|
ChannelsBridgeServer, bridgeProtocol,
|
|
58
59
|
// tmux lifecycle
|
|
@@ -104,6 +104,9 @@ function assertProtocolSchema() {
|
|
|
104
104
|
.filter(([, spec]) => spec.experimental)
|
|
105
105
|
.map(([method]) => method)
|
|
106
106
|
.sort();
|
|
107
|
+
const binaryTargets = Object.keys(
|
|
108
|
+
protocolSchema.binarySha256ByTarget ?? {},
|
|
109
|
+
).sort();
|
|
107
110
|
if (
|
|
108
111
|
JSON.stringify(experimental) !== JSON.stringify([
|
|
109
112
|
'thread/backgroundTerminals/clean',
|
|
@@ -114,6 +117,17 @@ function assertProtocolSchema() {
|
|
|
114
117
|
|| protocolSchema.requestIdTypes.join(',') !== 'integer,string'
|
|
115
118
|
|| typeof protocolSchema.generatedProtocolV2CanonicalSha256 !== 'string'
|
|
116
119
|
|| !/^[a-f0-9]{64}$/.test(protocolSchema.generatedProtocolV2CanonicalSha256)
|
|
120
|
+
|| JSON.stringify(binaryTargets) !== JSON.stringify([
|
|
121
|
+
'aarch64-apple-darwin',
|
|
122
|
+
'x86_64-unknown-linux-musl',
|
|
123
|
+
])
|
|
124
|
+
|| binaryTargets.some(
|
|
125
|
+
(target) => !/^[a-f0-9]{64}$/.test(
|
|
126
|
+
protocolSchema.binarySha256ByTarget[target],
|
|
127
|
+
),
|
|
128
|
+
)
|
|
129
|
+
|| protocolSchema.binarySha256
|
|
130
|
+
!== protocolSchema.binarySha256ByTarget['aarch64-apple-darwin']
|
|
117
131
|
) {
|
|
118
132
|
throw new Error('Codex app-server protocol pin is inconsistent');
|
|
119
133
|
}
|
|
@@ -141,6 +155,37 @@ class CodexAppServerError extends Error {
|
|
|
141
155
|
}
|
|
142
156
|
}
|
|
143
157
|
|
|
158
|
+
const CODEX_TARGET_BY_HOST = Object.freeze({
|
|
159
|
+
'darwin/arm64': 'aarch64-apple-darwin',
|
|
160
|
+
'linux/x64': 'x86_64-unknown-linux-musl',
|
|
161
|
+
});
|
|
162
|
+
const CODEX_TARGET_RECEIPTS = Object.freeze(Object.fromEntries(
|
|
163
|
+
Object.entries(protocolSchema.binarySha256ByTarget).map(
|
|
164
|
+
([target, binarySha256]) => [
|
|
165
|
+
target,
|
|
166
|
+
Object.freeze({
|
|
167
|
+
target,
|
|
168
|
+
cliVersion: protocolSchema.cliVersion,
|
|
169
|
+
binarySha256,
|
|
170
|
+
}),
|
|
171
|
+
],
|
|
172
|
+
),
|
|
173
|
+
));
|
|
174
|
+
|
|
175
|
+
function resolveCodexTargetPin(
|
|
176
|
+
platform = process.platform,
|
|
177
|
+
arch = process.arch,
|
|
178
|
+
) {
|
|
179
|
+
const target = CODEX_TARGET_BY_HOST[`${platform}/${arch}`];
|
|
180
|
+
if (!target) {
|
|
181
|
+
throw new CodexAppServerError(
|
|
182
|
+
'The native Codex app-server beta does not support this platform',
|
|
183
|
+
'CODEX_UNSUPPORTED_PLATFORM',
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
return CODEX_TARGET_RECEIPTS[target];
|
|
187
|
+
}
|
|
188
|
+
|
|
144
189
|
function buildCodexAppServerEnv(codexHome, hostEnv = process.env) {
|
|
145
190
|
return Object.fromEntries(
|
|
146
191
|
Object.entries({
|
|
@@ -185,7 +230,16 @@ async function hashFile(binary) {
|
|
|
185
230
|
return hash.digest('hex');
|
|
186
231
|
}
|
|
187
232
|
|
|
188
|
-
async function attestPinnedCodexBinary(
|
|
233
|
+
async function attestPinnedCodexBinary(
|
|
234
|
+
binary,
|
|
235
|
+
targetReceipt = resolveCodexTargetPin(),
|
|
236
|
+
) {
|
|
237
|
+
if (targetReceipt !== resolveCodexTargetPin()) {
|
|
238
|
+
throw new CodexAppServerError(
|
|
239
|
+
'pinned Codex target receipt mismatch',
|
|
240
|
+
'CODEX_BINARY_MISMATCH',
|
|
241
|
+
);
|
|
242
|
+
}
|
|
189
243
|
if (realpathSync(binary) !== binary) {
|
|
190
244
|
throw new CodexAppServerError(
|
|
191
245
|
'pinned Codex binary path is not canonical',
|
|
@@ -221,7 +275,7 @@ async function attestPinnedCodexBinary(binary) {
|
|
|
221
275
|
);
|
|
222
276
|
}
|
|
223
277
|
const sha256 = await hashFile(binary);
|
|
224
|
-
if (sha256 !==
|
|
278
|
+
if (sha256 !== targetReceipt.binarySha256) {
|
|
225
279
|
throw new CodexAppServerError(
|
|
226
280
|
'pinned Codex binary hash mismatch',
|
|
227
281
|
'CODEX_BINARY_MISMATCH',
|
|
@@ -241,7 +295,7 @@ async function attestPinnedCodexBinary(binary) {
|
|
|
241
295
|
'CODEX_BINARY_MISMATCH',
|
|
242
296
|
);
|
|
243
297
|
}
|
|
244
|
-
if (stdout.trim() !==
|
|
298
|
+
if (stdout.trim() !== targetReceipt.cliVersion) {
|
|
245
299
|
throw new CodexAppServerError(
|
|
246
300
|
'pinned Codex binary version mismatch',
|
|
247
301
|
'CODEX_BINARY_MISMATCH',
|
|
@@ -249,6 +303,7 @@ async function attestPinnedCodexBinary(binary) {
|
|
|
249
303
|
}
|
|
250
304
|
return {
|
|
251
305
|
path: binary,
|
|
306
|
+
target: targetReceipt.target,
|
|
252
307
|
sha256,
|
|
253
308
|
version: stdout.trim(),
|
|
254
309
|
fingerprint,
|
|
@@ -1732,12 +1787,7 @@ class CodexAppServerClient extends EventEmitter {
|
|
|
1732
1787
|
'CodexAppServerClient: expectedConfigSha256 must be a lowercase SHA-256',
|
|
1733
1788
|
);
|
|
1734
1789
|
}
|
|
1735
|
-
|
|
1736
|
-
throw new CodexAppServerError(
|
|
1737
|
-
'The native Codex app-server beta does not support Windows',
|
|
1738
|
-
'CODEX_UNSUPPORTED_PLATFORM',
|
|
1739
|
-
);
|
|
1740
|
-
}
|
|
1790
|
+
const targetReceipt = resolveCodexTargetPin();
|
|
1741
1791
|
for (const [value, label] of [
|
|
1742
1792
|
[cwd, 'cwd'],
|
|
1743
1793
|
[codexHome, 'codexHome'],
|
|
@@ -1824,6 +1874,7 @@ class CodexAppServerClient extends EventEmitter {
|
|
|
1824
1874
|
onFault,
|
|
1825
1875
|
attestBinaryFn,
|
|
1826
1876
|
attestCodexHomeFn,
|
|
1877
|
+
targetReceipt,
|
|
1827
1878
|
expectedConfigSha256,
|
|
1828
1879
|
requestTimeoutMs,
|
|
1829
1880
|
sinkTimeoutMs,
|
|
@@ -1889,7 +1940,7 @@ class CodexAppServerClient extends EventEmitter {
|
|
|
1889
1940
|
];
|
|
1890
1941
|
try {
|
|
1891
1942
|
const [attestation, homeAttestation] = await Promise.all([
|
|
1892
|
-
this.attestBinaryFn(this.binary),
|
|
1943
|
+
this.attestBinaryFn(this.binary, this.targetReceipt),
|
|
1893
1944
|
this.attestCodexHomeFn(
|
|
1894
1945
|
this.codexHome,
|
|
1895
1946
|
this.expectedConfigSha256,
|
|
@@ -1898,8 +1949,9 @@ class CodexAppServerClient extends EventEmitter {
|
|
|
1898
1949
|
if (
|
|
1899
1950
|
!attestation
|
|
1900
1951
|
|| attestation.path !== this.binary
|
|
1901
|
-
|| attestation.
|
|
1902
|
-
|| attestation.
|
|
1952
|
+
|| attestation.target !== this.targetReceipt.target
|
|
1953
|
+
|| attestation.sha256 !== this.targetReceipt.binarySha256
|
|
1954
|
+
|| attestation.version !== this.targetReceipt.cliVersion
|
|
1903
1955
|
) {
|
|
1904
1956
|
throw new CodexAppServerError(
|
|
1905
1957
|
'pinned Codex binary attestation was inconsistent',
|
|
@@ -2931,4 +2983,5 @@ module.exports = {
|
|
|
2931
2983
|
attestPinnedCodexHome,
|
|
2932
2984
|
buildCodexAppServerEnv,
|
|
2933
2985
|
protocolSchema,
|
|
2986
|
+
resolveCodexTargetPin,
|
|
2934
2987
|
};
|
package/lib/codex/preflight.js
CHANGED
|
@@ -7,6 +7,7 @@ const {
|
|
|
7
7
|
CodexAppServerClient,
|
|
8
8
|
buildCodexAppServerEnv,
|
|
9
9
|
protocolSchema,
|
|
10
|
+
resolveCodexTargetPin,
|
|
10
11
|
} = require('./app-server-client');
|
|
11
12
|
|
|
12
13
|
const MAX_PAGES = 16;
|
|
@@ -22,6 +23,7 @@ const SHA256_RE = /^[a-f0-9]{64}$/;
|
|
|
22
23
|
const EXPECTED_PROFILE_KEYS = new Set([
|
|
23
24
|
'runtime',
|
|
24
25
|
'binary',
|
|
26
|
+
'target',
|
|
25
27
|
'binarySha256',
|
|
26
28
|
'cliVersion',
|
|
27
29
|
'protocolSchemaSha256',
|
|
@@ -218,6 +220,7 @@ function exact(actual, expected, label) {
|
|
|
218
220
|
}
|
|
219
221
|
|
|
220
222
|
function normalizeExpectedProfile(value) {
|
|
223
|
+
const targetReceipt = resolveCodexTargetPin();
|
|
221
224
|
const source = plainObject(value, 'expectedStaticProfile');
|
|
222
225
|
for (const key of Object.keys(source)) {
|
|
223
226
|
if (!EXPECTED_PROFILE_KEYS.has(key)) {
|
|
@@ -246,14 +249,16 @@ function normalizeExpectedProfile(value) {
|
|
|
246
249
|
source.binarySha256,
|
|
247
250
|
'binarySha256',
|
|
248
251
|
);
|
|
252
|
+
const target = requiredString(source.target, 'target');
|
|
249
253
|
const cliVersion = requiredString(source.cliVersion, 'cliVersion');
|
|
250
254
|
const protocolSchemaSha256 = requiredSha256(
|
|
251
255
|
source.protocolSchemaSha256,
|
|
252
256
|
'protocolSchemaSha256',
|
|
253
257
|
);
|
|
254
258
|
if (
|
|
255
|
-
|
|
256
|
-
||
|
|
259
|
+
target !== targetReceipt.target
|
|
260
|
+
|| binarySha256 !== targetReceipt.binarySha256
|
|
261
|
+
|| cliVersion !== targetReceipt.cliVersion
|
|
257
262
|
|| protocolSchemaSha256
|
|
258
263
|
!== protocolSchema.generatedProtocolV2CanonicalSha256
|
|
259
264
|
) {
|
|
@@ -326,6 +331,7 @@ function normalizeExpectedProfile(value) {
|
|
|
326
331
|
const profile = {
|
|
327
332
|
runtime: 'codex',
|
|
328
333
|
binary,
|
|
334
|
+
target,
|
|
329
335
|
binarySha256,
|
|
330
336
|
cliVersion,
|
|
331
337
|
protocolSchemaSha256,
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"cliVersion": "codex-cli 0.145.0",
|
|
3
3
|
"binarySha256": "1da3f4e0e96028b8a771814293c3033dafd1971f943f6c7e79b0897fe705f590",
|
|
4
|
+
"binarySha256ByTarget": {
|
|
5
|
+
"aarch64-apple-darwin": "1da3f4e0e96028b8a771814293c3033dafd1971f943f6c7e79b0897fe705f590",
|
|
6
|
+
"x86_64-unknown-linux-musl": "a2a05dafaa1acb002a45eaec0a462de5b13694fcfcd7bc43305f14781ce7be14"
|
|
7
|
+
},
|
|
4
8
|
"generatedProtocolV2CanonicalSha256": "1bc09dedc506075562d4d49b702ecab6d947dd5a8c2a9014a5cde592a0938efb",
|
|
5
9
|
"requestIdTypes": [
|
|
6
10
|
"integer",
|
package/lib/tmux/orphan-sweep.js
CHANGED
|
@@ -31,10 +31,17 @@ const { createTmuxRunner } = require('./tmux-runner');
|
|
|
31
31
|
* @param {object} opts
|
|
32
32
|
* @param {string} opts.botName — only sweep sessions for THIS bot
|
|
33
33
|
* @param {object} [opts.runner] — injected TmuxRunner (for tests)
|
|
34
|
+
* @param {string} [opts.socketName] — dedicated tmux server to enumerate, when
|
|
35
|
+
* no runner is injected. Must match the caller's own runner.
|
|
34
36
|
* @param {object} [opts.logger=console]
|
|
35
|
-
* @returns {Promise<{ swept: string[], errors: Array<{name:string, error:string}
|
|
37
|
+
* @returns {Promise<{ swept: string[], errors: Array<{name:string, error:string}>,
|
|
38
|
+
* listFailed: boolean, listError?: string }>} `listFailed` is true when the
|
|
39
|
+
* host could not be enumerated at all — distinct from an empty `swept`, which
|
|
40
|
+
* means the host was reachable and genuinely had no orphans.
|
|
36
41
|
*/
|
|
37
|
-
async function sweepTmuxOrphans({
|
|
42
|
+
async function sweepTmuxOrphans({
|
|
43
|
+
botName, runner, logger = console, socketName = null,
|
|
44
|
+
} = {}) {
|
|
38
45
|
if (!botName) throw new TypeError('sweepTmuxOrphans: botName required');
|
|
39
46
|
// SECURITY (audit M2): dashes in bot names risk prefix-match
|
|
40
47
|
// collision when two bots share a prefix (e.g. `shumabit` matches
|
|
@@ -49,32 +56,43 @@ async function sweepTmuxOrphans({ botName, runner, logger = console } = {}) {
|
|
|
49
56
|
+ `prefix. Consider renaming (e.g. use _ instead).`,
|
|
50
57
|
);
|
|
51
58
|
}
|
|
52
|
-
|
|
59
|
+
// The fallback runner must target the SAME tmux server the caller uses.
|
|
60
|
+
// Without forwarding socketName it would enumerate the default socket while
|
|
61
|
+
// the app's sessions live on a dedicated one — finding nothing and reporting a
|
|
62
|
+
// clean host, which is the very fail-open this function was hardened against.
|
|
63
|
+
const r = runner || createTmuxRunner({ logger, socketName });
|
|
53
64
|
let names;
|
|
54
65
|
try {
|
|
55
|
-
names = await r.listPolygramSessions(botName);
|
|
66
|
+
names = await r.listPolygramSessions(botName, { strict: true });
|
|
56
67
|
} catch (err) {
|
|
57
|
-
//
|
|
58
|
-
|
|
59
|
-
|
|
68
|
+
// "Could not ask" is NOT "nothing to sweep". Enumerating strictly and
|
|
69
|
+
// reporting the failure lets the caller decide: with a dedicated socket and
|
|
70
|
+
// `-N`, an unreachable server means the tmux unit never came up, and booting
|
|
71
|
+
// on would leave the daemon blind to sessions it is supposed to own.
|
|
72
|
+
logger.warn?.(`[orphan-sweep] list-sessions failed (${err.message}); cannot determine whether orphans exist`);
|
|
73
|
+
return { swept: [], errors: [], listFailed: true, listError: err.message };
|
|
60
74
|
}
|
|
61
75
|
if (names.length === 0) {
|
|
62
76
|
logger.log?.(`[orphan-sweep] no orphan tmux sessions for ${botName}`);
|
|
63
|
-
return { swept: [], errors: [] };
|
|
77
|
+
return { swept: [], errors: [], listFailed: false };
|
|
64
78
|
}
|
|
65
79
|
logger.log?.(`[orphan-sweep] killing ${names.length} orphan tmux session(s): ${names.join(', ')}`);
|
|
66
80
|
const errors = [];
|
|
67
81
|
const swept = [];
|
|
68
82
|
for (const name of names) {
|
|
69
83
|
try {
|
|
70
|
-
|
|
84
|
+
// strict: this loop REPORTS what it reaped. Non-strict killSession
|
|
85
|
+
// resolves even when tmux refused, so every session would be logged as
|
|
86
|
+
// swept and the `errors` array below could never be populated — a stale
|
|
87
|
+
// session then survives and collides with the next spawn of that name.
|
|
88
|
+
await r.killSession(name, { strict: true });
|
|
71
89
|
swept.push(name);
|
|
72
90
|
} catch (err) {
|
|
73
91
|
errors.push({ name, error: err.message });
|
|
74
92
|
logger.warn?.(`[orphan-sweep] kill ${name} failed: ${err.message}`);
|
|
75
93
|
}
|
|
76
94
|
}
|
|
77
|
-
return { swept, errors };
|
|
95
|
+
return { swept, errors, listFailed: false };
|
|
78
96
|
}
|
|
79
97
|
|
|
80
98
|
module.exports = { sweepTmuxOrphans };
|
package/lib/tmux/tmux-runner.js
CHANGED
|
@@ -84,6 +84,12 @@ const CONTROL_CHAR_RE = /[\x00-\x08\x0b-\x1f\x7f]/g;
|
|
|
84
84
|
// SIGTERM. 10s is generous headroom over the sub-second norm.
|
|
85
85
|
const TMUX_RUN_TIMEOUT_MS = 10_000;
|
|
86
86
|
|
|
87
|
+
// A tmux socket name becomes a bare CLI argument. execFile means this is not a
|
|
88
|
+
// shell-injection vector, but a value starting with '-' would be parsed by tmux
|
|
89
|
+
// as another server flag, and a path separator would silently select a
|
|
90
|
+
// different socket directory. Same reasoning as the paneWidth guard in spawn().
|
|
91
|
+
const SOCKET_NAME_RE = /^[A-Za-z0-9][A-Za-z0-9_.-]{0,63}$/;
|
|
92
|
+
|
|
87
93
|
/**
|
|
88
94
|
* Promise-wrapped childProcess.execFile. Returns { stdout, stderr }.
|
|
89
95
|
* Rejects on non-zero exit (or timeout) with err.stdout + err.stderr
|
|
@@ -183,15 +189,37 @@ function ensureLogDir(logPath) {
|
|
|
183
189
|
* @param {object} [opts.logger=console]
|
|
184
190
|
* @param {Function} [opts.runFn] — override the underlying execFile
|
|
185
191
|
* wrapper (for tests). Same signature: (cmd, args, opts?) → Promise.
|
|
192
|
+
* @param {string} [opts.socketName] — run against a dedicated tmux server
|
|
193
|
+
* (`tmux -L <name>`) instead of the shared default socket.
|
|
186
194
|
*/
|
|
187
195
|
function createTmuxRunner({
|
|
188
196
|
sessionPrefix = 'orchestra',
|
|
189
197
|
logger = console,
|
|
190
198
|
runFn = run,
|
|
191
199
|
requireExistingServer = false,
|
|
200
|
+
socketName = null,
|
|
192
201
|
} = {}) {
|
|
202
|
+
if (socketName != null && !SOCKET_NAME_RE.test(socketName)) {
|
|
203
|
+
throw new TypeError(
|
|
204
|
+
`socketName must match ${SOCKET_NAME_RE} (got ${JSON.stringify(socketName)})`,
|
|
205
|
+
);
|
|
206
|
+
}
|
|
193
207
|
const runnerPrefix = sessionPrefix;
|
|
194
|
-
|
|
208
|
+
// Server-scope flags, in tmux's required position: before the command word.
|
|
209
|
+
//
|
|
210
|
+
// `-L <name>` gives this app its own tmux server. Without it orchestra shares
|
|
211
|
+
// the DEFAULT socket with the operator's interactive sessions, so one
|
|
212
|
+
// `tmux kill-server` — from a unit's ExecStop or from a human at a prompt —
|
|
213
|
+
// reaches every bot, water and the admin session at once.
|
|
214
|
+
//
|
|
215
|
+
// Blast-radius control, not a privilege boundary: every server here runs under
|
|
216
|
+
// the same uid, so any process that knows the name can still run
|
|
217
|
+
// `tmux -L <name>` against it.
|
|
218
|
+
const serverArgs = [
|
|
219
|
+
...(socketName ? ['-L', socketName] : []),
|
|
220
|
+
...(requireExistingServer ? ['-N'] : []),
|
|
221
|
+
];
|
|
222
|
+
const runTmux = (args, opts) => runFn('tmux', serverArgs.length ? [...serverArgs, ...args] : args, opts);
|
|
195
223
|
async function spawn({
|
|
196
224
|
name,
|
|
197
225
|
cwd,
|
|
@@ -387,21 +415,48 @@ function createTmuxRunner({
|
|
|
387
415
|
}
|
|
388
416
|
}
|
|
389
417
|
|
|
390
|
-
|
|
391
|
-
|
|
418
|
+
/**
|
|
419
|
+
* Kill a tmux session. Best-effort by default (teardown paths race normal
|
|
420
|
+
* exits and must not throw). Pass `{ strict: true }` when the caller reports
|
|
421
|
+
* success or failure to someone: silently swallowing here makes a stale
|
|
422
|
+
* session look reaped, and the next spawn then collides with the name.
|
|
423
|
+
*/
|
|
424
|
+
async function killSession(name, { strict = false } = {}) {
|
|
425
|
+
try {
|
|
426
|
+
await runTmux(['kill-session', '-t', name]);
|
|
427
|
+
} catch (err) {
|
|
428
|
+
if (strict) {
|
|
429
|
+
throw Object.assign(new Error(`tmux kill-session failed: ${err.message}`), {
|
|
430
|
+
code: 'TMUX_KILL_FAILED',
|
|
431
|
+
cause: err,
|
|
432
|
+
});
|
|
433
|
+
}
|
|
434
|
+
}
|
|
392
435
|
}
|
|
393
436
|
|
|
394
437
|
/**
|
|
395
438
|
* List polygram-managed tmux sessions on the host. Optional `botName`
|
|
396
439
|
* narrows the prefix; without it returns all `water-*` sessions.
|
|
440
|
+
*
|
|
441
|
+
* Default is best-effort: an unreachable tmux server reads as an empty host.
|
|
442
|
+
* Pass `{ strict: true }` when the caller must distinguish "no sessions" from
|
|
443
|
+
* "could not ask" — with a dedicated socket and `-N` (never auto-start), an
|
|
444
|
+
* unreachable server means the tmux unit failed to come up, and treating that
|
|
445
|
+
* as "nothing here" hides it.
|
|
397
446
|
*/
|
|
398
|
-
async function listPolygramSessions(botName = null) {
|
|
447
|
+
async function listPolygramSessions(botName = null, { strict = false } = {}) {
|
|
399
448
|
try {
|
|
400
449
|
const { stdout } = await runTmux(['list-sessions', '-F', '#{session_name}']);
|
|
401
450
|
const all = stdout.trim().split('\n').filter(Boolean);
|
|
402
451
|
const prefix = botName ? `${runnerPrefix}-${String(botName).replace(/[^\w-]/g, '_')}-` : `${runnerPrefix}-`;
|
|
403
452
|
return all.filter((n) => n.startsWith(prefix));
|
|
404
|
-
} catch {
|
|
453
|
+
} catch (err) {
|
|
454
|
+
if (strict) {
|
|
455
|
+
throw Object.assign(new Error(`tmux list-sessions failed: ${err.message}`), {
|
|
456
|
+
code: 'TMUX_LIST_FAILED',
|
|
457
|
+
cause: err,
|
|
458
|
+
});
|
|
459
|
+
}
|
|
405
460
|
return [];
|
|
406
461
|
}
|
|
407
462
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shumkov/orchestra",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "Transport-agnostic session engine for Claude Code and the native Codex app-server: spawn, steer, supervise, observe turns, and recover.",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "index.js",
|