@tangle-network/sdk-provider-codex 0.4.87 → 0.4.89

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/dist/index.d.mts CHANGED
@@ -215,6 +215,8 @@ declare abstract class CodexNativeLaunchAdapter extends CliProviderAdapterBase<C
215
215
  //#region src/codex-secret-profile.d.ts
216
216
  declare abstract class CodexSecretProfileAdapter extends CodexNativeLaunchAdapter {
217
217
  protected readonly supportsSecretProfileRevisions = true;
218
+ protected readonly referencesSharedEnvironmentSecrets = true;
219
+ protected spawnExecutionProcess(request: CliTurnSpawn<CodexConfig, CodexEvent>): CliTurnProcess | Promise<CliTurnProcess>;
218
220
  private binary?;
219
221
  private refuse;
220
222
  protected getCliPath(): string;
@@ -225,11 +227,17 @@ declare abstract class CodexSecretProfileAdapter extends CodexNativeLaunchAdapte
225
227
  protected nativeArgs(input: AgentExecutionInput & {
226
228
  managedQuoteVersion?: string;
227
229
  }, plan: WorkspacePlanApplication | undefined, mcp?: Record<string, unknown>): string[];
228
- protected prepareSecretCodexTurn(input: AgentExecutionInput, plan: WorkspacePlanApplication, sessionId: string, mcpInput: AgentExecutionInput, retainRelease: (release: SecretProfileMcpLease) => void): Promise<{
229
- cwd: string;
230
+ protected prepareSecretCodexTurn(input: AgentExecutionInput, plan: WorkspacePlanApplication, sessionId: string, mcpInput: AgentExecutionInput, retainRelease: (release: SecretProfileMcpLease) => void, shared?: {
231
+ args: string[];
230
232
  env: Record<string, string | undefined>;
233
+ cwd: string;
234
+ }): Promise<{
235
+ cwd: string;
236
+ env: {
237
+ [x: string]: string | undefined;
238
+ };
231
239
  args: string[];
232
- validate: (bridge: RpcBridge, extra: Record<string, unknown>) => Promise<Record<string, NativeMcp>>;
240
+ validate: ((bridge: RpcBridge, extra: Record<string, unknown>) => Promise<Record<string, NativeMcp>>) | undefined;
233
241
  }>;
234
242
  shutdown(): Promise<void>;
235
243
  }
package/dist/index.mjs CHANGED
@@ -2,10 +2,11 @@ import { randomUUID } from "node:crypto";
2
2
  import { InteractionKind, ProxySecretBindingSchema, ProxySecretGrantSchema, ProxySecretReceiptSchema, ProxySecretUpdateControlsSchema, ProxySecretsSchema, isProxySecretScopeAttenuation, ownPropertyRecordSchema, proxySecretPresentationsEqual, resolveTangleRouterDefaults } from "@tangle-network/agent-interface";
3
3
  import { z } from "zod";
4
4
  import { HELD_SPARE_IDLE_MS, createDeferredParser, createHeldSpareRegistry, launchDifferences, resolveRawCapturePath, spawnRpcBridge } from "@tangle-network/sdk-cli-runner";
5
- import { CODEX_DISABLED_FEATURE_ARGS, CliProviderAdapterBase, InteractionBroker, McpInteractionSupport, NATIVE_SESSION_CONTRACTS, PROMPT_SECTION_SEPARATOR, SEALED_NATIVE_HOME_LAYOUT, SECRET_REFERENCE_PREFIX, assertSealedNativeHome, assertSealedNativeSearchPath, codexDeveloperInstructionArgs, deriveFilePart, directStdioMcpServers, executionCorrelationHeaders, failureAfterCleanup, forgetSessionScopes, interactionToggleEnabled, isLoopbackEndpoint, isPlainRecord, jsonEventParser, localMcpArgv, localMcpEnv, nativeEffortArgs, partitionImageAttachments, provenStoreBinary, reasoningEvents, recordCliTokenUsage, refuseSecretLaunch, resolveExecutableRealpath, secretMcpScope, secretSessionTurnQueue, servableMcpServer, servableStdioServer, sessionObservedEvents, streamPartBase, textDeltaEvents, toolResultEvents, toolStartEvents, trackFilePart, turnEndReason, untilSettledOrAborted, withTurnInteractions } from "@tangle-network/sdk-provider-cli-base";
5
+ import { CODEX_DISABLED_FEATURE_ARGS, CliProviderAdapterBase, InteractionBroker, McpInteractionSupport, NATIVE_SESSION_CONTRACTS, PROMPT_SECTION_SEPARATOR, SEALED_NATIVE_HOME_LAYOUT, SECRET_REFERENCE_PREFIX, assertSealedNativeHome, assertSealedNativeSearchPath, codexDeveloperInstructionArgs, deriveFilePart, directStdioMcpServers, executionCorrelationHeaders, failureAfterCleanup, forgetSessionScopes, interactionToggleEnabled, isLoopbackEndpoint, isPlainRecord, jsonEventParser, localMcpArgv, localMcpEnv, nativeEffortArgs, partitionImageAttachments, provenStoreBinary, reasoningEvents, recordCliTokenUsage, refuseSecretLaunch, resolveExecutableRealpath, secretMcpScope, secretSessionTurnQueue, servableMcpServer, servableStdioServer, sessionObservedEvents, sharedSecretMcpRefused, spawnUnderSecretMcpLease, streamPartBase, textDeltaEvents, toolResultEvents, toolStartEvents, trackFilePart, turnEndReason, untilSettledOrAborted, withTurnInteractions } from "@tangle-network/sdk-provider-cli-base";
6
6
  import { existsSync } from "node:fs";
7
7
  import path, { join } from "node:path";
8
8
  import { isDeepStrictEqual } from "node:util";
9
+ import { parse } from "smol-toml";
9
10
  const TURN_KEY_PLACEHOLDER_PREFIX = "tangle-turn-key";
10
11
  const MODEL_KEY_PROXY_PATH_PREFIX = "/v1/";
11
12
  const LOOPBACK_BASE_URL = /^http:\/\/127\.0\.0\.1:[0-9]+$/;
@@ -1205,6 +1206,25 @@ var CodexNativeLaunchAdapter = class extends CliProviderAdapterBase {
1205
1206
  //#region src/codex-secret-profile.ts
1206
1207
  var CodexSecretProfileAdapter = class extends CodexNativeLaunchAdapter {
1207
1208
  supportsSecretProfileRevisions = true;
1209
+ referencesSharedEnvironmentSecrets = true;
1210
+ spawnExecutionProcess(request) {
1211
+ if (!request.profilePlan || !this.secretProfileReferences(request.profilePlan)) return super.spawnExecutionProcess(request);
1212
+ let launch;
1213
+ return spawnUnderSecretMcpLease(secretMcpScope(request.sessionId, this.subprocessIdentity()?.uid, this.mcpOwner), request.signal, async (retain) => {
1214
+ launch = await this.prepareSecretCodexTurn(request.input, request.profilePlan, request.sessionId, request.input, retain, {
1215
+ args: request.execArgs.args,
1216
+ env: request.env,
1217
+ cwd: request.workspaceRoot
1218
+ });
1219
+ }, () => super.spawnExecutionProcess({
1220
+ ...request,
1221
+ env: launch.env,
1222
+ execArgs: {
1223
+ ...request.execArgs,
1224
+ args: launch.args
1225
+ }
1226
+ }));
1227
+ }
1208
1228
  binary;
1209
1229
  refuse(reason, path = this.config.runtimeHome) {
1210
1230
  return refuseSecretLaunch(`Secret Codex ${reason}`, { path });
@@ -1306,34 +1326,53 @@ var CodexSecretProfileAdapter = class extends CodexNativeLaunchAdapter {
1306
1326
  ...mcp === void 0 ? [] : ["-c", `mcp_servers=${inlineToml(mcp)}`]
1307
1327
  ];
1308
1328
  }
1309
- async prepareSecretCodexTurn(input, plan, sessionId, mcpInput, retainRelease) {
1310
- const native = await this.readNativeConfig(input, plan);
1311
- const cwd = this.bindSecretProfileSessionView(native.cwd, sessionId);
1312
- assertSealedNativeSearchPath(cwd, [".codex", ".agents"]);
1329
+ async prepareSecretCodexTurn(input, plan, sessionId, mcpInput, retainRelease, shared) {
1330
+ const native = shared ? {
1331
+ ...shared,
1332
+ servers: parse(plan.spawn.flags.find((flag) => flag.startsWith("mcp_servers=")) ?? "mcp_servers={}").mcp_servers
1333
+ } : await this.readNativeConfig(input, plan);
1334
+ const cwd = shared ? native.cwd : this.bindSecretProfileSessionView(native.cwd, sessionId);
1335
+ if (!shared) assertSealedNativeSearchPath(cwd, [".codex", ".agents"]);
1313
1336
  const refs = this.secretProfileReferences(plan) ?? {};
1314
1337
  const served = [];
1315
1338
  const inherited = (entries) => Object.fromEntries(entries.map(([name, key]) => [name, native.env[key]]));
1316
1339
  for (const [name, entry] of Object.entries(native.servers)) {
1317
1340
  if (entry.enabled === false) continue;
1341
+ const inheritedHeaders = inherited(Object.entries(entry.env_http_headers ?? {}));
1342
+ const inheritedEnv = inherited((entry.env_vars ?? []).map((key) => [key, key]));
1343
+ if (shared && !JSON.stringify([inheritedHeaders, inheritedEnv]).includes(`{env:${SECRET_REFERENCE_PREFIX}`)) continue;
1318
1344
  const server = entry.url ? servableMcpServer(name, {
1319
1345
  url: entry.url,
1320
1346
  headers: {
1321
1347
  ...entry.http_headers,
1322
- ...inherited(Object.entries(entry.env_http_headers ?? {}))
1348
+ ...inheritedHeaders
1323
1349
  }
1324
1350
  }, refs) : servableStdioServer(name, {
1325
1351
  command: [entry.command, ...entry.args ?? []],
1352
+ ...shared ? { cwd: entry.cwd } : {},
1326
1353
  environment: {
1327
1354
  ...entry.env,
1328
- ...inherited((entry.env_vars ?? []).map((key) => [key, key]))
1355
+ ...inheritedEnv
1329
1356
  }
1330
- }, refs);
1357
+ }, refs, shared ? {
1358
+ files: this.secretProfileMounts(plan),
1359
+ workspaceRoot: cwd
1360
+ } : void 0);
1331
1361
  if (typeof server === "string") this.refuse(`cannot serve MCP ${name}: ${server}`, cwd);
1332
1362
  served.push(server);
1333
1363
  }
1334
- const uid = this.config.subprocessUser?.uid;
1364
+ const uid = this.subprocessIdentity()?.uid;
1365
+ if (shared && (!this.mcpOwner.proxy || sharedSecretMcpRefused(served, uid))) this.refuse("profile secrets need an MCP proxy and a root sidecar running the agent under another UID", cwd);
1366
+ const referenced = new Set(Object.values(native.servers).flatMap((entry) => [...Object.values(entry.env_http_headers ?? {}), ...entry.env_vars ?? []]));
1367
+ const env = { ...native.env };
1368
+ if (shared) for (const [name, value] of Object.entries(env)) {
1369
+ if (!value?.includes(`{env:${SECRET_REFERENCE_PREFIX}`)) continue;
1370
+ if (!referenced.has(name)) this.refuse("secret is outside MCP", cwd);
1371
+ delete env[name];
1372
+ }
1373
+ if (shared && Object.values(env).some((value) => Object.values(refs).some((credential) => value?.includes(credential)))) this.refuse("launch environment holds a profile credential", cwd);
1335
1374
  const scope = secretMcpScope(sessionId, uid, this.mcpOwner);
1336
- const servers = {};
1375
+ const servers = shared ? { ...native.servers } : {};
1337
1376
  if (served.length) {
1338
1377
  if (!this.mcpOwner.proxy) this.refuse("requires an MCP proxy", cwd);
1339
1378
  const endpoint = await this.mcpOwner.proxy.endpoint(scope, served.map((server) => server.name));
@@ -1359,7 +1398,9 @@ var CodexSecretProfileAdapter = class extends CodexNativeLaunchAdapter {
1359
1398
  if (served.length && typeof release !== "function") this.refuse("MCP lease was not acknowledged", cwd);
1360
1399
  if (release) retainRelease(release);
1361
1400
  input.abortSignal?.throwIfAborted();
1362
- for (const server of directStdioMcpServers(release, served).values()) {
1401
+ const direct = directStdioMcpServers(release, served);
1402
+ if (shared && direct.size) this.refuse("shared stdio requires the sidecar bridge", cwd);
1403
+ for (const server of direct.values()) {
1363
1404
  const { url: _url, http_headers: _headers, ...controls } = servers[server.name];
1364
1405
  servers[server.name] = {
1365
1406
  ...controls,
@@ -1370,9 +1411,9 @@ var CodexSecretProfileAdapter = class extends CodexNativeLaunchAdapter {
1370
1411
  }
1371
1412
  return {
1372
1413
  cwd,
1373
- env: native.env,
1374
- args: this.nativeArgs(input, plan, servers),
1375
- validate: (bridge, extra) => this.readNativeControls(bridge, plan, cwd, {
1414
+ env,
1415
+ args: shared ? shared.args.map((arg) => arg.startsWith("mcp_servers=") ? `mcp_servers=${inlineToml(servers)}` : arg) : this.nativeArgs(input, plan, servers),
1416
+ validate: shared ? void 0 : (bridge, extra) => this.readNativeControls(bridge, plan, cwd, {
1376
1417
  ...servers,
1377
1418
  ...extra
1378
1419
  })
@@ -1433,7 +1474,7 @@ var CodexAppServerAdapter = class extends CodexSecretProfileAdapter {
1433
1474
  async executeViaAppServer(input, services, onEvent, mcpInput = input) {
1434
1475
  const prepared = await this.prepareAppServerTurn(input, services, onEvent, mcpInput);
1435
1476
  if (prepared.cached !== void 0) return prepared.cached;
1436
- const queue = this.config.secretProfileRevisionRoot ? secretSessionTurnQueue(this.secretProfileSessionView(prepared.sessionId).view) : void 0;
1477
+ const queue = this.config.secretProfileRevisionRoot ? secretSessionTurnQueue(this.secretProfileSessionView(prepared.sessionId).view) : this.secretProfileReferences(prepared.profilePlan) ? secretSessionTurnQueue(secretMcpScope(prepared.sessionId, this.subprocessIdentity()?.uid, this.mcpOwner)) : void 0;
1437
1478
  let bridge;
1438
1479
  let result;
1439
1480
  let closing;
@@ -1516,15 +1557,19 @@ var CodexAppServerAdapter = class extends CodexSecretProfileAdapter {
1516
1557
  }
1517
1558
  async launchAppServerTurn(context) {
1518
1559
  const { input, profilePlan, run } = context;
1519
- const secret = this.config.secretProfileRevisionRoot && profilePlan ? await this.prepareSecretCodexTurn(input, profilePlan, context.sessionId, context.mcpInput, (release) => {
1560
+ const secret = profilePlan && (this.config.secretProfileRevisionRoot || this.secretProfileReferences(profilePlan)) ? await this.prepareSecretCodexTurn(input, profilePlan, context.sessionId, context.mcpInput, (release) => {
1520
1561
  context.releaseMcp = release;
1562
+ }, this.config.secretProfileRevisionRoot ? void 0 : {
1563
+ args: this.nativeArgs(input, profilePlan),
1564
+ env: this.buildAppServerEnv(profilePlan, run.cwd),
1565
+ cwd: run.cwd
1521
1566
  }) : void 0;
1522
1567
  const env = secret?.env ?? this.buildAppServerEnv(profilePlan, run.cwd);
1523
1568
  run.cwd = secret?.cwd ?? run.cwd;
1524
1569
  const args = secret?.args ?? this.nativeArgs(input, profilePlan);
1525
1570
  const extraMcp = await this.bindPlanMcp(context, args, env);
1526
- if (secret) run.initialize = async (initialized) => {
1527
- await secret.validate(initialized, extraMcp);
1571
+ if (secret?.validate) run.initialize = async (initialized) => {
1572
+ await secret.validate?.(initialized, extraMcp);
1528
1573
  if (existsSync(join(run.cwd, ".codex/skills"))) await initialized.request("skills/extraRoots/set", { extraRoots: [join(run.cwd, ".codex/skills")] });
1529
1574
  };
1530
1575
  return this.spawnAppServer(input, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tangle-network/sdk-provider-codex",
3
- "version": "0.4.87",
3
+ "version": "0.4.89",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -18,8 +18,9 @@
18
18
  "@tangle-network/agent-backend-types": "1.3.3",
19
19
  "@tangle-network/agent-interface": "^5.10.27",
20
20
  "@tangle-network/sdk-cli-runner": "0.3.12",
21
- "@tangle-network/sdk-provider-cli-base": "0.13.109",
21
+ "@tangle-network/sdk-provider-cli-base": "0.13.111",
22
22
  "@tangle-network/sdk-session-persistence": "0.7.13",
23
+ "smol-toml": "^1.9.0",
23
24
  "zod": "4.6.7"
24
25
  },
25
26
  "devDependencies": {
@@ -34,8 +35,8 @@
34
35
  "registry": "https://registry.npmjs.org"
35
36
  },
36
37
  "tangleRelease": {
37
- "sourceSha": "2bff5bb99292ab3af6b5aa5ac656feafd846f712",
38
- "mergedAt": "2026-11-16T21:21:04-08:00"
38
+ "sourceSha": "4fc8137ed2738d89cf2a1e227db41470df7f2150",
39
+ "mergedAt": "2026-11-16T22:21:12-08:00"
39
40
  },
40
41
  "scripts": {
41
42
  "build": "tsdown",