@shumkov/orchestra 0.10.19 → 0.10.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.
- package/docs/2026-08-17-001-u23-hook-trust-characterization-findings.md +964 -0
- package/lib/codex/app-server-client.js +444 -125
- package/lib/codex/preflight.js +43 -0
- package/lib/codex/protocol-schema.json +8 -0
- package/lib/process/codex-process.js +34 -0
- package/lib/process/factory.js +5 -0
- package/package.json +1 -1
package/lib/codex/preflight.js
CHANGED
|
@@ -6,6 +6,7 @@ const path = require('node:path');
|
|
|
6
6
|
const {
|
|
7
7
|
CodexAppServerClient,
|
|
8
8
|
buildCodexAppServerEnv,
|
|
9
|
+
normalizeCodexHookManifest,
|
|
9
10
|
protocolSchema,
|
|
10
11
|
resolveCodexTargetPin,
|
|
11
12
|
} = require('./app-server-client');
|
|
@@ -64,10 +65,14 @@ const EXPECTED_PROFILE_KEYS = new Set([
|
|
|
64
65
|
'effort',
|
|
65
66
|
'sessionLauncher',
|
|
66
67
|
'sessionLauncherSha256',
|
|
68
|
+
'hookManifest',
|
|
69
|
+
'hookArtifactsSha256',
|
|
67
70
|
]);
|
|
68
71
|
const OPTIONAL_EXPECTED_PROFILE_KEYS = new Set([
|
|
69
72
|
'sessionLauncher',
|
|
70
73
|
'sessionLauncherSha256',
|
|
74
|
+
'hookManifest',
|
|
75
|
+
'hookArtifactsSha256',
|
|
71
76
|
]);
|
|
72
77
|
const PREFLIGHT_RESULT_KEYS = new Set([
|
|
73
78
|
'runtime',
|
|
@@ -301,6 +306,24 @@ function normalizeExpectedProfile(value) {
|
|
|
301
306
|
if (sessionLauncher !== null && !path.isAbsolute(sessionLauncher)) {
|
|
302
307
|
throw new TypeError('Codex preflight session launcher must be absolute');
|
|
303
308
|
}
|
|
309
|
+
const suppliedManifest = source.hookManifest ?? null;
|
|
310
|
+
const suppliedArtifactsSha256 = source.hookArtifactsSha256 ?? null;
|
|
311
|
+
if ((suppliedManifest === null) !== (suppliedArtifactsSha256 === null)) {
|
|
312
|
+
throw new TypeError(
|
|
313
|
+
'Codex preflight hook manifest and artifact digest must be paired',
|
|
314
|
+
);
|
|
315
|
+
}
|
|
316
|
+
const hookManifest = suppliedManifest === null
|
|
317
|
+
? null
|
|
318
|
+
: normalizeCodexHookManifest(suppliedManifest);
|
|
319
|
+
const hookArtifactsSha256 = suppliedArtifactsSha256 === null
|
|
320
|
+
? null
|
|
321
|
+
: requiredSha256(suppliedArtifactsSha256, 'hookArtifactsSha256');
|
|
322
|
+
if (hookManifest !== null && hookManifest.ownedCwd !== cwd) {
|
|
323
|
+
throw new TypeError(
|
|
324
|
+
'Codex preflight hook manifest must own the configured workspace',
|
|
325
|
+
);
|
|
326
|
+
}
|
|
304
327
|
if (
|
|
305
328
|
target !== targetReceipt.target
|
|
306
329
|
|| binarySha256 !== targetReceipt.binarySha256
|
|
@@ -409,6 +432,9 @@ function normalizeExpectedProfile(value) {
|
|
|
409
432
|
effort: requiredString(source.effort, 'effort'),
|
|
410
433
|
sessionLauncher,
|
|
411
434
|
sessionLauncherSha256,
|
|
435
|
+
// Absent, not null: a profile prepared without hooks keeps exactly the key
|
|
436
|
+
// set, object model and fingerprint it had before hooks existed.
|
|
437
|
+
...(hookManifest === null ? {} : { hookManifest, hookArtifactsSha256 }),
|
|
412
438
|
};
|
|
413
439
|
|
|
414
440
|
assertExpectedPolicy(profile);
|
|
@@ -700,6 +726,12 @@ function staticAttestation(profile, configRead, requirements, profiles) {
|
|
|
700
726
|
sessionLauncherPathSha256: digest(profile.sessionLauncher),
|
|
701
727
|
sessionLauncherSha256: profile.sessionLauncherSha256,
|
|
702
728
|
}),
|
|
729
|
+
// Hook material joins the identity only when a manifest is carried, so a
|
|
730
|
+
// profile prepared without hooks keeps the fingerprint it always had.
|
|
731
|
+
...(profile.hookManifest == null ? {} : {
|
|
732
|
+
hookManifestSha256: digest(profile.hookManifest),
|
|
733
|
+
hookArtifactsSha256: profile.hookArtifactsSha256,
|
|
734
|
+
}),
|
|
703
735
|
credentialHomeSha256: digest(profile.codexHome),
|
|
704
736
|
workspaceSha256: digest(profile.cwd),
|
|
705
737
|
allowlistedEnvironmentFingerprint:
|
|
@@ -942,6 +974,10 @@ async function runPreflight(profile, client) {
|
|
|
942
974
|
permissionProfiles,
|
|
943
975
|
} = await readAndAssertStaticPolicy(profile, client);
|
|
944
976
|
|
|
977
|
+
if (profile.hookManifest != null) {
|
|
978
|
+
await client.verifyHooks({ phase: 'trusted' });
|
|
979
|
+
}
|
|
980
|
+
|
|
945
981
|
const account = plainObject(
|
|
946
982
|
await client.request('account/read', { refreshToken: false }),
|
|
947
983
|
'account result',
|
|
@@ -1034,6 +1070,9 @@ async function preflightCodexRuntime(
|
|
|
1034
1070
|
cwd: profile.cwd,
|
|
1035
1071
|
codexHome: profile.codexHome,
|
|
1036
1072
|
env: profile.env,
|
|
1073
|
+
...(profile.hookManifest == null
|
|
1074
|
+
? {}
|
|
1075
|
+
: { hookManifest: profile.hookManifest }),
|
|
1037
1076
|
expectedConfigSha256: profile.ownedConfigSha256,
|
|
1038
1077
|
onNotification: async () => {
|
|
1039
1078
|
throw new CodexPreflightError(
|
|
@@ -1052,6 +1091,10 @@ async function preflightCodexRuntime(
|
|
|
1052
1091
|
|| typeof client.request !== 'function'
|
|
1053
1092
|
|| typeof client.close !== 'function'
|
|
1054
1093
|
|| typeof client.waitForFault !== 'function'
|
|
1094
|
+
|| (
|
|
1095
|
+
profile.hookManifest != null
|
|
1096
|
+
&& typeof client.verifyHooks !== 'function'
|
|
1097
|
+
)
|
|
1055
1098
|
) {
|
|
1056
1099
|
throw new TypeError('Codex preflight clientFactory returned an invalid client');
|
|
1057
1100
|
}
|
|
@@ -106,6 +106,14 @@
|
|
|
106
106
|
"optional": [],
|
|
107
107
|
"stateChanging": true
|
|
108
108
|
},
|
|
109
|
+
"hooks/list": {
|
|
110
|
+
"required": [
|
|
111
|
+
"cwds"
|
|
112
|
+
],
|
|
113
|
+
"optional": [],
|
|
114
|
+
"internal": true,
|
|
115
|
+
"stateChanging": false
|
|
116
|
+
},
|
|
109
117
|
"thread/backgroundTerminals/list": {
|
|
110
118
|
"required": [
|
|
111
119
|
"threadId"
|
|
@@ -280,6 +280,7 @@ class CodexProcess extends Process {
|
|
|
280
280
|
cwd,
|
|
281
281
|
clientFactory,
|
|
282
282
|
staticPolicyAttestor = async () => {},
|
|
283
|
+
hookVerifier = null,
|
|
283
284
|
checkpointSink,
|
|
284
285
|
hostIdentity,
|
|
285
286
|
bootSessionIdentity,
|
|
@@ -318,6 +319,9 @@ class CodexProcess extends Process {
|
|
|
318
319
|
'CodexProcess: staticPolicyAttestor must be a function',
|
|
319
320
|
);
|
|
320
321
|
}
|
|
322
|
+
if (hookVerifier !== null && typeof hookVerifier !== 'function') {
|
|
323
|
+
throw new TypeError('CodexProcess: hookVerifier must be a function');
|
|
324
|
+
}
|
|
321
325
|
if (typeof generationIdFactory !== 'function') {
|
|
322
326
|
throw new TypeError('CodexProcess: generationIdFactory must be a function');
|
|
323
327
|
}
|
|
@@ -353,6 +357,7 @@ class CodexProcess extends Process {
|
|
|
353
357
|
|
|
354
358
|
this.clientFactory = clientFactory;
|
|
355
359
|
this.staticPolicyAttestor = staticPolicyAttestor;
|
|
360
|
+
this.hookVerifier = hookVerifier;
|
|
356
361
|
this.checkpointSink = checkpointSink;
|
|
357
362
|
this.hostIdentity = nonEmptyString(hostIdentity, 'hostIdentity');
|
|
358
363
|
this.bootSessionIdentity = nonEmptyString(
|
|
@@ -613,6 +618,10 @@ class CodexProcess extends Process {
|
|
|
613
618
|
|| typeof this.client.request !== 'function'
|
|
614
619
|
|| typeof this.client.close !== 'function'
|
|
615
620
|
|| typeof this.client.waitForFault !== 'function'
|
|
621
|
+
|| (
|
|
622
|
+
this.hookVerifier !== null
|
|
623
|
+
&& typeof this.client.verifyHooks !== 'function'
|
|
624
|
+
)
|
|
616
625
|
) {
|
|
617
626
|
throw new TypeError(
|
|
618
627
|
'CodexProcess: clientFactory returned an invalid client',
|
|
@@ -620,6 +629,10 @@ class CodexProcess extends Process {
|
|
|
620
629
|
}
|
|
621
630
|
await this.client.start();
|
|
622
631
|
this._assertLifecycle(lifecycle);
|
|
632
|
+
// A resumed thread executes hooks exactly as a fresh one does, so trust
|
|
633
|
+
// is proven before either kind of attachment.
|
|
634
|
+
await this._verifyHookTrust();
|
|
635
|
+
this._assertLifecycle(lifecycle);
|
|
623
636
|
this.state = 'AttachingThread';
|
|
624
637
|
this.attachingThreadId = existingSessionId;
|
|
625
638
|
const result = await this._withSettingsGate(async () => (
|
|
@@ -740,6 +753,19 @@ class CodexProcess extends Process {
|
|
|
740
753
|
}
|
|
741
754
|
}
|
|
742
755
|
|
|
756
|
+
async _verifyHookTrust() {
|
|
757
|
+
if (!this.hookVerifier) return;
|
|
758
|
+
try {
|
|
759
|
+
await this.hookVerifier(this.client, 'trusted');
|
|
760
|
+
} catch (cause) {
|
|
761
|
+
throw processError(
|
|
762
|
+
'Codex hook trust could not be verified',
|
|
763
|
+
cause?.code ?? 'CODEX_HOOK_TRUST_UNVERIFIED',
|
|
764
|
+
{ cause },
|
|
765
|
+
);
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
|
|
743
769
|
async _verifyStartupRelease() {
|
|
744
770
|
if (!this.client) {
|
|
745
771
|
this.startupReleaseSafe = true;
|
|
@@ -1181,6 +1207,14 @@ class CodexProcess extends Process {
|
|
|
1181
1207
|
error.deliveryState = 'not-sent';
|
|
1182
1208
|
throw error;
|
|
1183
1209
|
}
|
|
1210
|
+
// A long-lived session must not drift between attachment and its
|
|
1211
|
+
// next turn, so trust is re-proven for every turn.
|
|
1212
|
+
try {
|
|
1213
|
+
await this._verifyHookTrust();
|
|
1214
|
+
} catch (cause) {
|
|
1215
|
+
cause.deliveryState = 'not-sent';
|
|
1216
|
+
throw cause;
|
|
1217
|
+
}
|
|
1184
1218
|
const assertTurnStartAdmission = () => {
|
|
1185
1219
|
if (
|
|
1186
1220
|
pending.startCancellationRequested
|
package/lib/process/factory.js
CHANGED
|
@@ -352,6 +352,11 @@ function createCodexProcess({
|
|
|
352
352
|
staticPolicyAttestor: (client) => (
|
|
353
353
|
reattestCodexStaticPolicy(profile, client)
|
|
354
354
|
),
|
|
355
|
+
// Only a profile that carries hook material asks for verification; without
|
|
356
|
+
// it the session runs the request sequence it always ran.
|
|
357
|
+
...(profile.hookManifest == null ? {} : {
|
|
358
|
+
hookVerifier: (client, phase) => client.verifyHooks({ phase }),
|
|
359
|
+
}),
|
|
355
360
|
checkpointSink,
|
|
356
361
|
hostIdentity,
|
|
357
362
|
bootSessionIdentity,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shumkov/orchestra",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.20",
|
|
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",
|