@shumkov/orchestra 0.7.2 → 0.7.4

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.
@@ -195,8 +195,30 @@ direct-binary run; it does not clear the broader hosted-tool enforcement gate.
195
195
  Live pinned-runtime characterization found the exact profile at top-level
196
196
  `activePermissionProfile` in both `thread/start` and `thread/resume`
197
197
  responses. The value is fixture-pinned as `{id: "polygram-session",
198
- extends: null}`. The generated stable response schemas do not declare that
199
- field, and no matching `thread/settings/updated` notification was observed.
198
+ extends: null}`. Both attachment responses also return exactly one concrete
199
+ `runtimeWorkspaceRoots` entry equal to the owned cwd. Orchestra exposes that
200
+ entry only as `{count: 1, sha256: [sha256(ownedCwd)]}`.
201
+
202
+ Fresh, resume, and `thread/settings/updated` all return the same legacy
203
+ compatibility envelope:
204
+
205
+ ```json
206
+ {
207
+ "type": "workspaceWrite",
208
+ "networkAccess": false,
209
+ "excludeSlashTmp": true,
210
+ "excludeTmpdirEnvVar": true,
211
+ "writableRootCount": 0,
212
+ "writableRootSha256": []
213
+ }
214
+ ```
215
+
216
+ The zero count means there are no additional legacy writable roots; the
217
+ concrete named-profile workspace grant is attested separately by
218
+ `runtimeWorkspaceRoots`. Settings notifications do not include
219
+ `runtimeWorkspaceRoots`, so Orchestra compares them against a distinct static
220
+ view while retaining the admitted attachment as the concrete-root proof. The
221
+ generated stable response schemas do not declare `activePermissionProfile`.
200
222
 
201
223
  The named-profile subgate accepts this only as a pinned fresh-plus-resume pair
202
224
  and reports:
@@ -205,8 +227,10 @@ and reports:
205
227
  - `provenanceSchemaDeclared: false`;
206
228
  - `provenanceFragile: true`.
207
229
 
208
- A missing, different, or one-sided value remains a stop. Every Codex pin change
209
- must regenerate the schema and rerun this live characterization.
230
+ A missing, different, duplicated, additional, outside-workspace, or one-sided
231
+ runtime root remains a stop. Any legacy network, temp-exclusion, type, or
232
+ additional-root drift also remains a stop. Every Codex pin change must
233
+ regenerate the schema and rerun this live characterization.
210
234
 
211
235
  ## Active-turn steering capability passed; smoke setup remains fragile
212
236
 
@@ -576,6 +576,12 @@ function projectNotification(message, ownedCwd) {
576
576
  source.threadSettings,
577
577
  'thread settings',
578
578
  );
579
+ if (Object.hasOwn(settings, 'runtimeWorkspaceRoots')) {
580
+ throw new CodexAppServerError(
581
+ 'app-server thread settings unexpectedly included runtime workspace roots',
582
+ 'CODEX_PROTOCOL_ERROR',
583
+ );
584
+ }
579
585
  if (settings.cwd !== ownedCwd) {
580
586
  throw new CodexAppServerError(
581
587
  'app-server thread settings changed the owned workspace',
@@ -1040,6 +1046,15 @@ function projectSandbox(value, ownedCwd) {
1040
1046
  projected.networkAccess = sandbox.networkAccess;
1041
1047
  }
1042
1048
  if (type === 'workspaceWrite') {
1049
+ for (const key of ['excludeSlashTmp', 'excludeTmpdirEnvVar']) {
1050
+ if (sandbox[key] !== undefined && typeof sandbox[key] !== 'boolean') {
1051
+ throw new CodexAppServerError(
1052
+ 'app-server sandbox temp exclusion is malformed',
1053
+ 'CODEX_PROTOCOL_ERROR',
1054
+ );
1055
+ }
1056
+ if (sandbox[key] !== undefined) projected[key] = sandbox[key];
1057
+ }
1043
1058
  if (
1044
1059
  sandbox.writableRoots !== undefined
1045
1060
  && !Array.isArray(sandbox.writableRoots)
@@ -1077,6 +1092,40 @@ function projectSandbox(value, ownedCwd) {
1077
1092
  return projected;
1078
1093
  }
1079
1094
 
1095
+ function projectRuntimeWorkspaceRoots(value, ownedCwd) {
1096
+ if (!Array.isArray(value) || value.length > 64) {
1097
+ throw new CodexAppServerError(
1098
+ 'app-server runtime workspace roots are malformed',
1099
+ 'CODEX_PROTOCOL_ERROR',
1100
+ );
1101
+ }
1102
+ const roots = value.map((root) => (
1103
+ protocolRequiredString(root, 'runtime workspace root', MAX_TEXT_BYTES)
1104
+ ));
1105
+ if (roots.some((root) => (
1106
+ !path.isAbsolute(root)
1107
+ || path.normalize(root) !== root
1108
+ || !isWithin(ownedCwd, root)
1109
+ ))) {
1110
+ throw new CodexAppServerError(
1111
+ 'app-server runtime workspace root escaped the owned workspace',
1112
+ 'CODEX_PROTOCOL_ERROR',
1113
+ );
1114
+ }
1115
+ if (roots.length !== 1 || roots[0] !== ownedCwd) {
1116
+ throw new CodexAppServerError(
1117
+ 'app-server runtime workspace roots did not match the owned workspace',
1118
+ 'CODEX_PROTOCOL_ERROR',
1119
+ );
1120
+ }
1121
+ return {
1122
+ count: roots.length,
1123
+ sha256: roots
1124
+ .map((root) => createHash('sha256').update(root).digest('hex'))
1125
+ .sort(),
1126
+ };
1127
+ }
1128
+
1080
1129
  function projectRpcResult(method, value, ownedCwd) {
1081
1130
  const result = protocolObject(value, `${method} result`);
1082
1131
  if (method === 'initialize') {
@@ -1312,6 +1361,10 @@ function projectRpcResult(method, value, ownedCwd) {
1312
1361
  ),
1313
1362
  approvalPolicy: projectApprovalPolicy(result.approvalPolicy),
1314
1363
  approvalsReviewer: result.approvalsReviewer,
1364
+ runtimeWorkspaceRoots: projectRuntimeWorkspaceRoots(
1365
+ result.runtimeWorkspaceRoots,
1366
+ ownedCwd,
1367
+ ),
1315
1368
  sandbox: projectSandbox(result.sandbox, ownedCwd),
1316
1369
  };
1317
1370
  projected.thread = projectThread(
@@ -376,9 +376,8 @@ function assertExpectedPolicy(profile) {
376
376
  || config.mcpServers?.keySha256?.length !== 0
377
377
  || config.plugins?.count !== 0
378
378
  || config.plugins?.keySha256?.length !== 0
379
- || config.modelProviders?.count !== 1
380
- || config.modelProviders?.keySha256?.length !== 1
381
- || config.modelProviders.keySha256[0] !== digest('openai')
379
+ || config.modelProviders?.count !== 0
380
+ || config.modelProviders?.keySha256?.length !== 0
382
381
  ) {
383
382
  throw new CodexPreflightError(
384
383
  'Codex expected policy is outside the native beta contract',
@@ -84,14 +84,18 @@ function dynamicSettings(source) {
84
84
  );
85
85
  }
86
86
 
87
- function staticThreadPolicy(source) {
88
- return {
87
+ function staticThreadPolicy(source, { includeRuntimeWorkspaceRoots = false } = {}) {
88
+ const policy = {
89
89
  modelProvider: source?.modelProvider,
90
90
  approvalPolicy: source?.approvalPolicy,
91
91
  approvalsReviewer: source?.approvalsReviewer,
92
92
  sandbox: source?.sandbox ?? source?.sandboxPolicy,
93
93
  permissionProfile: source?.activePermissionProfile,
94
94
  };
95
+ if (includeRuntimeWorkspaceRoots) {
96
+ policy.runtimeWorkspaceRoots = source?.runtimeWorkspaceRoots;
97
+ }
98
+ return policy;
95
99
  }
96
100
 
97
101
  function isDeepFrozen(value) {
@@ -260,6 +264,11 @@ class CodexProcess extends Process {
260
264
  );
261
265
  }
262
266
  this.expectedStaticPolicy = resolvedStaticPolicy;
267
+ const {
268
+ runtimeWorkspaceRoots: _runtimeWorkspaceRoots,
269
+ ...expectedSettingsPolicy
270
+ } = resolvedStaticPolicy;
271
+ this.expectedSettingsPolicy = Object.freeze(expectedSettingsPolicy);
263
272
  this.expectedPermissionProfileId = nonEmptyString(
264
273
  resolvedStaticPolicy.permissionProfile?.id,
265
274
  'expectedStaticPolicy.permissionProfile.id',
@@ -578,12 +587,26 @@ class CodexProcess extends Process {
578
587
  'CODEX_PROTOCOL_ERROR',
579
588
  );
580
589
  }
581
- this._validateAndObserveThreadPolicy(result, { attaching: true });
590
+ this._validateAndObserveThreadPolicy(result, {
591
+ attaching: true,
592
+ attachmentPolicy: true,
593
+ });
582
594
  }
583
595
 
584
- _validateAndObserveThreadPolicy(source, { attaching = false } = {}) {
585
- const actualStaticPolicy = staticThreadPolicy(source);
586
- if (!isDeepStrictEqual(actualStaticPolicy, this.expectedStaticPolicy)) {
596
+ _validateAndObserveThreadPolicy(
597
+ source,
598
+ { attaching = false, attachmentPolicy = false } = {},
599
+ ) {
600
+ const actualStaticPolicy = staticThreadPolicy(source, {
601
+ includeRuntimeWorkspaceRoots: (
602
+ attachmentPolicy
603
+ && Object.hasOwn(this.expectedStaticPolicy, 'runtimeWorkspaceRoots')
604
+ ),
605
+ });
606
+ const expectedStaticPolicy = attachmentPolicy
607
+ ? this.expectedStaticPolicy
608
+ : this.expectedSettingsPolicy;
609
+ if (!isDeepStrictEqual(actualStaticPolicy, expectedStaticPolicy)) {
587
610
  throw processError(
588
611
  'Codex thread did not attest the exact trusted static policy',
589
612
  'CODEX_THREAD_POLICY_MISMATCH',
@@ -843,6 +866,20 @@ class CodexProcess extends Process {
843
866
  error.deliveryState = 'not-sent';
844
867
  throw error;
845
868
  }
869
+ const assertTurnStartAdmission = () => {
870
+ if (
871
+ pending.startCancellationRequested
872
+ || this.settingsAdmissionClosed
873
+ || this.state === 'Quiescing'
874
+ ) {
875
+ if (pending.turnId) return;
876
+ throw processError(
877
+ 'Codex turn start was cancelled before dispatch',
878
+ 'CODEX_RPC_NOT_SENT',
879
+ );
880
+ }
881
+ this._assertLifecycle(lifecycle);
882
+ };
846
883
  const result = await this._mutation('turn/start', params, {
847
884
  source: pending.context?.sourceMsgId ?? null,
848
885
  clientUserMessageId: pending.clientUserMessageId,
@@ -854,19 +891,8 @@ class CodexProcess extends Process {
854
891
  pending.startResponseOutcome = outcome;
855
892
  }
856
893
  },
857
- assertCanWrite: () => {
858
- if (
859
- pending.startCancellationRequested
860
- || this.settingsAdmissionClosed
861
- || this.state === 'Quiescing'
862
- ) {
863
- if (pending.turnId) return;
864
- throw processError(
865
- 'Codex turn start was cancelled before dispatch',
866
- 'CODEX_RPC_NOT_SENT',
867
- );
868
- }
869
- },
894
+ assertCanWrite: assertTurnStartAdmission,
895
+ assertCanCommit: assertTurnStartAdmission,
870
896
  });
871
897
  this._assertLifecycle(lifecycle);
872
898
  const turnId = result?.turn?.id;
@@ -1674,6 +1700,7 @@ class CodexProcess extends Process {
1674
1700
  this.stateChangingWriteCommitted = true;
1675
1701
  detail.onDeliveryState?.('write-attempted');
1676
1702
  },
1703
+ detail.assertCanCommit,
1677
1704
  );
1678
1705
  },
1679
1706
  onResponseObserved: async (transport) => {
@@ -1687,7 +1714,13 @@ class CodexProcess extends Process {
1687
1714
  });
1688
1715
  }
1689
1716
 
1690
- async _transportCheckpoint(kind, detail, transport, onCommitted = null) {
1717
+ async _transportCheckpoint(
1718
+ kind,
1719
+ detail,
1720
+ transport,
1721
+ onCommitted = null,
1722
+ assertCanCommit = null,
1723
+ ) {
1691
1724
  transport.assertActive?.();
1692
1725
  const payload = this._checkpointPayload(kind, {
1693
1726
  ...detail,
@@ -1704,9 +1737,16 @@ class CodexProcess extends Process {
1704
1737
  },
1705
1738
  };
1706
1739
  let writeCommitted = false;
1740
+ let commitRejection = null;
1707
1741
  const markWriteCommitted = () => {
1708
1742
  transport.assertActive?.();
1709
1743
  if (writeCommitted) return;
1744
+ try {
1745
+ assertCanCommit?.();
1746
+ } catch (error) {
1747
+ commitRejection = error;
1748
+ throw error;
1749
+ }
1710
1750
  transport.markWriteCommitted?.();
1711
1751
  writeCommitted = true;
1712
1752
  onCommitted?.();
@@ -1720,9 +1760,8 @@ class CodexProcess extends Process {
1720
1760
  Object.defineProperties(payload, properties);
1721
1761
  try {
1722
1762
  await this.checkpointSink(payload);
1723
- if (kind === 'request-write-attempted') markWriteCommitted();
1724
- transport.assertActive?.();
1725
1763
  } catch (error) {
1764
+ if (error === commitRejection) throw error;
1726
1765
  const durability = processError(
1727
1766
  `Codex checkpoint ${kind} failed`,
1728
1767
  'CODEX_DURABILITY_FAILED',
@@ -1745,6 +1784,10 @@ class CodexProcess extends Process {
1745
1784
  }
1746
1785
  throw durability;
1747
1786
  }
1787
+ if (kind === 'request-write-attempted') {
1788
+ markWriteCommitted();
1789
+ }
1790
+ transport.assertActive?.();
1748
1791
  }
1749
1792
 
1750
1793
  async _checkpoint(kind, detail = {}, fence = null) {
@@ -2343,6 +2386,7 @@ class CodexProcess extends Process {
2343
2386
  excludedPending = null,
2344
2387
  fence = null,
2345
2388
  ) {
2389
+ this._closeSettingsAdmission();
2346
2390
  if (this.state === 'ContainmentFailed') return;
2347
2391
  this._clearBackgroundWatchdog();
2348
2392
  const ownedTurnId = this.activeTurnId
@@ -146,13 +146,19 @@ function expectedStaticThreadPolicy(profile) {
146
146
  modelProvider: 'openai',
147
147
  approvalPolicy: 'never',
148
148
  approvalsReviewer: 'user',
149
+ runtimeWorkspaceRoots: {
150
+ count: 1,
151
+ sha256: [
152
+ createHash('sha256').update(profile.cwd).digest('hex'),
153
+ ],
154
+ },
149
155
  sandbox: {
150
156
  type: 'workspaceWrite',
151
157
  networkAccess: false,
152
- writableRootCount: 1,
153
- writableRootSha256: [
154
- createHash('sha256').update(profile.cwd).digest('hex'),
155
- ],
158
+ excludeSlashTmp: true,
159
+ excludeTmpdirEnvVar: true,
160
+ writableRootCount: 0,
161
+ writableRootSha256: [],
156
162
  },
157
163
  permissionProfile: {
158
164
  id: profile.permissionProfileId,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shumkov/orchestra",
3
- "version": "0.7.2",
3
+ "version": "0.7.4",
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",