orkestrator 2.36.5-beta → 2.36.6-beta

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.
@@ -1,3 +1,75 @@
1
+ // ../protocol/src/node/bridge-launch-environment.ts
2
+ import { closeSync, fstatSync, openSync, readSync, rmSync, constants } from "node:fs";
3
+ var BRIDGE_LAUNCH_ENVIRONMENT_ENV = "ORKESTRATOR_BRIDGE_LAUNCH_ENVIRONMENT";
4
+ var BRIDGE_LAUNCH_KEYS_ENV = "ORKESTRATOR_BRIDGE_LAUNCH_KEYS";
5
+ var BRIDGE_LAUNCH_WORKDIR_ENV = "ORKESTRATOR_BRIDGE_LAUNCH_WORKDIR";
6
+ var MAX_SNAPSHOT_BYTES = 1024 * 1024;
7
+ var MAX_SNAPSHOT_ENTRIES = 4096;
8
+ var NAME_PATTERN = /^[A-Za-z_][A-Za-z0-9_%.-]*$/;
9
+ var LAUNCH_ONLY = /(?:_BRIDGE_TOKEN|_TOKEN_SHA256|_AUTHORITY_KEY)$|^ORKESTRATOR_BRIDGE_(?:LAUNCH_|EXECUTION_POLICY$)|^ORKESTRATOR_COORDINATOR_/;
10
+ var NOT_APPLIED = new Set(["PWD", "OLDPWD", "SHLVL", "_", "NODE_PATH"]);
11
+ function readSnapshot(file) {
12
+ let fd;
13
+ try {
14
+ fd = openSync(file, constants.O_RDONLY | constants.O_NOFOLLOW);
15
+ } catch {
16
+ return null;
17
+ }
18
+ try {
19
+ const stat = fstatSync(fd);
20
+ if (!stat.isFile() || stat.size > MAX_SNAPSHOT_BYTES)
21
+ return null;
22
+ const buffer = Buffer.alloc(stat.size);
23
+ let offset = 0;
24
+ while (offset < buffer.length) {
25
+ const read = readSync(fd, buffer, offset, buffer.length - offset, offset);
26
+ if (read === 0)
27
+ break;
28
+ offset += read;
29
+ }
30
+ return buffer.subarray(0, offset);
31
+ } finally {
32
+ closeSync(fd);
33
+ }
34
+ }
35
+ function applyBridgeLaunchEnvironment(env = process.env, chdir = (directory) => process.chdir(directory)) {
36
+ const file = env[BRIDGE_LAUNCH_ENVIRONMENT_ENV];
37
+ if (!file)
38
+ return null;
39
+ const trusted = new Set((env[BRIDGE_LAUNCH_KEYS_ENV] ?? "").split(",").map((name) => name.trim()).filter(Boolean));
40
+ const workdir = env[BRIDGE_LAUNCH_WORKDIR_ENV];
41
+ delete env[BRIDGE_LAUNCH_ENVIRONMENT_ENV];
42
+ delete env[BRIDGE_LAUNCH_KEYS_ENV];
43
+ delete env[BRIDGE_LAUNCH_WORKDIR_ENV];
44
+ const result = { applied: 0, refused: 0 };
45
+ const snapshot = readSnapshot(file);
46
+ rmSync(file, { force: true });
47
+ if (snapshot) {
48
+ const entries = snapshot.toString("utf8").split("\x00").slice(0, MAX_SNAPSHOT_ENTRIES);
49
+ for (const entry of entries) {
50
+ const separator = entry.indexOf("=");
51
+ if (separator <= 0)
52
+ continue;
53
+ const name = entry.slice(0, separator);
54
+ if (!NAME_PATTERN.test(name) || NOT_APPLIED.has(name))
55
+ continue;
56
+ if (trusted.has(name) || LAUNCH_ONLY.test(name)) {
57
+ result.refused += 1;
58
+ continue;
59
+ }
60
+ env[name] = entry.slice(separator + 1);
61
+ result.applied += 1;
62
+ }
63
+ }
64
+ if (workdir) {
65
+ try {
66
+ chdir(workdir);
67
+ } catch {}
68
+ }
69
+ return result;
70
+ }
71
+ applyBridgeLaunchEnvironment();
72
+
1
73
  // ../protocol/src/agent-platforms.ts
2
74
  var AGENT_PLATFORMS = Object.freeze([
3
75
  "claude",
@@ -1394,6 +1466,7 @@ var DESKTOP_LOG_AREAS = defineLogAreas({
1394
1466
  events: {
1395
1467
  "attention-failed": "A dialog could not ask for the user's attention.",
1396
1468
  closed: "A native dialog closed.",
1469
+ "hidden-cancelled": "A hidden profile cancelled a dialog without opening native UI.",
1397
1470
  "open-failed": "A dialog could not open; it was answered as cancelled.",
1398
1471
  opening: "A native dialog is opening.",
1399
1472
  "preview-beforeunload-ignored": "A browser preview's beforeunload handler was ignored.",
@@ -1479,6 +1552,7 @@ var ENVIRONMENT_LOG_AREAS = defineLogAreas({
1479
1552
  "orphan-session.reaped": "A native session no tab references was torn down.",
1480
1553
  "handoff-sweep.failed": "Sweeping transferred transcripts no tab references failed.",
1481
1554
  "delete.terminals-survived": "Terminal process trees outlived termination, so the deletion stops.",
1555
+ "delete.step-deadline": "A deletion step that runs child processes passed its deadline; they are stopped and the deletion fails once they have.",
1482
1556
  "delete.artifacts-left": "Graph run artifact directories were not removed.",
1483
1557
  "delete.worktrees-kept": "Graph runs kept branch worktrees.",
1484
1558
  "delete.step-failed": "One best-effort part of deleting an environment failed; `step` says which, and the rest goes on.",
@@ -1513,6 +1587,7 @@ var GATEWAY_LOG_AREAS = defineLogAreas({
1513
1587
  "host.refused": "A request named a host this gateway does not answer to. Logged once per name, up to a limit.",
1514
1588
  "port.fallback": "The preferred port was taken, so a nearby one is used.",
1515
1589
  "port.fallback-distant": "The preferred port and those nearby were taken, so another is used.",
1590
+ "request-auth.fallback": "A desktop request-auth hook failed closed. Phase only; no request or error content.",
1516
1591
  "request.failed": "A gateway request failed. Throttled: repeats are counted, not written.",
1517
1592
  "websocket.upgrade-failed": "A WebSocket upgrade failed.",
1518
1593
  "events.client-dropped": "An event-stream client buffered too much and was dropped; it reconnects and refetches.",
@@ -1571,6 +1646,11 @@ var LOCAL_SERVER_LOG_AREAS = defineLogAreas({
1571
1646
  requested: "boolean"
1572
1647
  }
1573
1648
  },
1649
+ "bridge.orphans-reaped": {
1650
+ description: "Processes a bridge left in its process group after exiting on its own (its agent CLI, mid-turn) were stopped. `warn` when they left; `error` when one survived SIGKILL.",
1651
+ essential: true,
1652
+ fields: { key: "label", pid: "number", result: "label" }
1653
+ },
1574
1654
  "reaper.tmux-list-failed": "Orphaned claude-tmux sessions could not be listed.",
1575
1655
  "reaper.tmux-kill-failed": "An orphaned tmux session could not be killed.",
1576
1656
  "reaper.tmux-reaped": "Orphaned claude-tmux sessions of a deleted environment were killed.",
@@ -2404,7 +2484,11 @@ var DOCKER_LOG_AREAS = defineLogAreas({
2404
2484
  "network.list-failed": "Docker networks could not be listed.",
2405
2485
  "network.inspect-failed": "A Docker network could not be inspected.",
2406
2486
  "stale-containers.removing": "Stale probe containers are being removed.",
2407
- "stale-networks.removing": "Stale probe networks are being removed."
2487
+ "stale-networks.removing": "Stale probe networks are being removed.",
2488
+ "peers.refused": "The agent tools server closed connections from addresses outside loopback and this backend's Docker networks (at most one entry a minute, with a count).",
2489
+ "peers.subnets-loaded": "The Docker subnets the agent tools server admits were reloaded.",
2490
+ "port.loopback-taken": "The agent tools server gave up a port because another process holds it on 127.0.0.1, where host agents call; it moves to a free port.",
2491
+ "peers.subnets-load-failed": "The Docker subnets the agent tools server admits could not be read; cached permissions are cleared and only loopback is admitted until a successful retry."
2408
2492
  }
2409
2493
  }
2410
2494
  });
@@ -3127,7 +3211,7 @@ var MAX_FRAME_CHARS = 240;
3127
3211
  var MAX_RAW_FRAME_CHARS = 1024;
3128
3212
  var MAX_CAUSE_DEPTH = 2;
3129
3213
  var TRUNCATED_MARKER = "...[truncated]";
3130
- var NAME_PATTERN = /^[A-Za-z_$][\w$.-]{0,63}$/;
3214
+ var NAME_PATTERN2 = /^[A-Za-z_$][\w$.-]{0,63}$/;
3131
3215
  var CODE_PATTERN = /^[\w.:-]{1,64}$/;
3132
3216
  var SYSCALL_PATTERN = /^[\w./ -]{1,128}$/;
3133
3217
  var COMMAND_OUTPUT_FIELDS = ["stdout", "stderr", "cmd", "spawnargs"];
@@ -3205,7 +3289,7 @@ function describe(error, includeStack, includeMessage, depth) {
3205
3289
  if (!(error instanceof Error) && typeof rawMessage !== "string") {
3206
3290
  return { name: "NonError", message: "[object]" };
3207
3291
  }
3208
- const name = matching(read(error, "name"), NAME_PATTERN) ?? "Error";
3292
+ const name = matching(read(error, "name"), NAME_PATTERN2) ?? "Error";
3209
3293
  const message = typeof rawMessage === "string" ? rawMessage : undefined;
3210
3294
  const commandFailure = isCommandFailure(error, name, message);
3211
3295
  const stackHoldsMessage = message !== undefined && String(read(error, "stack") ?? "").includes(message);
@@ -3260,7 +3344,7 @@ function logErrorKind(error) {
3260
3344
  const safeCode = finite(code) ?? matching(code, CODE_PATTERN);
3261
3345
  if (safeCode !== undefined)
3262
3346
  return String(safeCode);
3263
- return matching(read(error, "name"), NAME_PATTERN) ?? "Error";
3347
+ return matching(read(error, "name"), NAME_PATTERN2) ?? "Error";
3264
3348
  }
3265
3349
 
3266
3350
  // ../protocol/src/log-essential-labels.ts
@@ -3887,34 +3971,219 @@ function parseBridgeLogPolicy(value) {
3887
3971
  }
3888
3972
 
3889
3973
  // ../protocol/src/node/bridge-credential.ts
3890
- import { createHash, randomBytes, timingSafeEqual } from "node:crypto";
3974
+ import { createHash as createHash2, randomBytes as randomBytes2, timingSafeEqual } from "node:crypto";
3891
3975
  import { createRequire } from "node:module";
3976
+
3977
+ // ../protocol/src/node/bridge-authority.ts
3978
+ import {
3979
+ createHash,
3980
+ createPrivateKey,
3981
+ createPublicKey,
3982
+ generateKeyPairSync,
3983
+ randomBytes,
3984
+ sign,
3985
+ verify
3986
+ } from "node:crypto";
3987
+ var BRIDGE_AUTHORITY_HEADER = "x-orkestrator-authority";
3988
+ var BRIDGE_AUTHORITY_REFUSED_CODE = "authority-signature-required";
3989
+ var BRIDGE_AUTHORITY_WINDOW_MS = 5 * 60000;
3990
+ var BRIDGE_AUTHORITY_MAX_NONCES = 8192;
3991
+ var BRIDGE_AUTHORITY_MAX_BODY_BYTES = 64 * 1024 * 1024;
3992
+ var SCHEME = "orkestrator-bridge-authority-v1";
3993
+ var KEY_PATTERN = /^[A-Za-z0-9_-]{40,200}$/;
3994
+ var HEADER_PATTERN = /^v1 t=(\d{1,16}) n=([A-Za-z0-9_-]{22}) s=([A-Za-z0-9_-]{86})$/;
3995
+ var READ_METHODS = new Set(["GET", "HEAD", "OPTIONS"]);
3996
+ var UNSIGNED_ROUTES = [
3997
+ /^\/session\/[^/]+\/close$/,
3998
+ /^\/sessions\/activity$/,
3999
+ /^\/debug\/log-policy$/
4000
+ ];
4001
+ function bridgeAuthorityKeyEnv(tokenEnv) {
4002
+ return `${tokenEnv}_AUTHORITY_KEY`;
4003
+ }
4004
+ function isBridgeAuthorityKey(value) {
4005
+ return typeof value === "string" && KEY_PATTERN.test(value);
4006
+ }
4007
+ function publicKeyFrom(encoded) {
4008
+ if (!isBridgeAuthorityKey(encoded))
4009
+ return null;
4010
+ try {
4011
+ const key = createPublicKey({
4012
+ key: Buffer.from(encoded, "base64url"),
4013
+ format: "der",
4014
+ type: "spki"
4015
+ });
4016
+ return key.asymmetricKeyType === "ed25519" ? key : null;
4017
+ } catch {
4018
+ return null;
4019
+ }
4020
+ }
4021
+ function bridgeAuthorityTarget(url) {
4022
+ const parsed = new URL(url, "http://bridge.invalid");
4023
+ return `${parsed.pathname}${parsed.search}`;
4024
+ }
4025
+ function bridgeRequestNeedsAuthority(method, target) {
4026
+ if (READ_METHODS.has(method.toUpperCase()))
4027
+ return false;
4028
+ const pathname = bridgeAuthorityTarget(target).split("?", 1)[0];
4029
+ return !UNSIGNED_ROUTES.some((pattern) => pattern.test(pathname));
4030
+ }
4031
+ function bodyDigest(body) {
4032
+ return createHash("sha256").update(body ?? "").digest("hex");
4033
+ }
4034
+ function signedMessage(method, target, issuedAt, nonce, digest) {
4035
+ return Buffer.from([SCHEME, method.toUpperCase(), target, String(issuedAt), nonce, digest].join(`
4036
+ `));
4037
+ }
4038
+ var UNENFORCED = {
4039
+ enforced: false,
4040
+ requires: () => false,
4041
+ check: () => ({ ok: true })
4042
+ };
4043
+ function bridgeAuthorityFromPublicKey(publicKey, options = {}) {
4044
+ if (publicKey === undefined)
4045
+ return UNENFORCED;
4046
+ const key = publicKeyFrom(publicKey);
4047
+ const now = options.now ?? Date.now;
4048
+ const maxNonces = options.maxNonces ?? BRIDGE_AUTHORITY_MAX_NONCES;
4049
+ const seen = new Map;
4050
+ let floor = -Infinity;
4051
+ const remember = (nonce, issuedAt, current) => {
4052
+ for (const [oldNonce, oldIssuedAt] of seen) {
4053
+ if (seen.size < maxNonces && oldIssuedAt >= current - BRIDGE_AUTHORITY_WINDOW_MS)
4054
+ break;
4055
+ seen.delete(oldNonce);
4056
+ floor = Math.max(floor, oldIssuedAt);
4057
+ }
4058
+ seen.set(nonce, issuedAt);
4059
+ };
4060
+ return {
4061
+ enforced: true,
4062
+ requires: bridgeRequestNeedsAuthority,
4063
+ check(request) {
4064
+ if (!request.header)
4065
+ return { ok: false, reason: "missing" };
4066
+ const match = HEADER_PATTERN.exec(request.header.trim());
4067
+ if (!match)
4068
+ return { ok: false, reason: "malformed" };
4069
+ const issuedAt = Number(match[1]);
4070
+ const nonce = match[2];
4071
+ const current = now();
4072
+ if (Math.abs(current - issuedAt) > BRIDGE_AUTHORITY_WINDOW_MS || issuedAt <= floor) {
4073
+ return { ok: false, reason: "stale" };
4074
+ }
4075
+ if (!key)
4076
+ return { ok: false, reason: "invalid" };
4077
+ const valid = verify(null, signedMessage(request.method, bridgeAuthorityTarget(request.url), issuedAt, nonce, bodyDigest(request.body)), key, Buffer.from(match[3], "base64url"));
4078
+ if (!valid)
4079
+ return { ok: false, reason: "invalid" };
4080
+ if (seen.has(nonce))
4081
+ return { ok: false, reason: "replayed" };
4082
+ remember(nonce, issuedAt, current);
4083
+ return { ok: true };
4084
+ }
4085
+ };
4086
+ }
4087
+ function loadBridgeAuthority(tokenEnv, options = {}) {
4088
+ const env = options.env ?? process.env;
4089
+ const name = bridgeAuthorityKeyEnv(tokenEnv);
4090
+ const value = env[name]?.trim();
4091
+ delete env[name];
4092
+ return bridgeAuthorityFromPublicKey(value || undefined, { now: options.now });
4093
+ }
4094
+ function refusal(reason) {
4095
+ return {
4096
+ status: 403,
4097
+ body: {
4098
+ error: "This request changes an agent's authority and needs the backend's signature",
4099
+ code: BRIDGE_AUTHORITY_REFUSED_CODE,
4100
+ reason
4101
+ }
4102
+ };
4103
+ }
4104
+ var TOO_LARGE = {
4105
+ status: 413,
4106
+ body: { error: "Request body is too large" }
4107
+ };
4108
+ var admittedBodies = new WeakMap;
4109
+ async function readBounded(request, maxBodyBytes) {
4110
+ const declared = Number(request.headers.get("content-length") ?? NaN);
4111
+ if (Number.isFinite(declared) && declared > maxBodyBytes)
4112
+ return null;
4113
+ if (!request.body)
4114
+ return new Uint8Array;
4115
+ const reader = request.body.getReader();
4116
+ const chunks = [];
4117
+ let total = 0;
4118
+ for (;; ) {
4119
+ const { done, value } = await reader.read();
4120
+ if (done)
4121
+ break;
4122
+ total += value.byteLength;
4123
+ if (total > maxBodyBytes) {
4124
+ await reader.cancel().catch(() => {
4125
+ return;
4126
+ });
4127
+ return null;
4128
+ }
4129
+ chunks.push(value);
4130
+ }
4131
+ return Buffer.concat(chunks);
4132
+ }
4133
+ async function admitFetchBridgeRequest(authority, original, maxBodyBytes = BRIDGE_AUTHORITY_MAX_BODY_BYTES) {
4134
+ if (!authority.requires(original.method, original.url))
4135
+ return {};
4136
+ const header = original.headers.get(BRIDGE_AUTHORITY_HEADER);
4137
+ if (!header)
4138
+ return { refusal: refusal("missing") };
4139
+ const body = await readBounded(original, maxBodyBytes);
4140
+ if (!body)
4141
+ return { refusal: TOO_LARGE };
4142
+ const result = authority.check({ method: original.method, url: original.url, header, body });
4143
+ if (!result.ok)
4144
+ return { refusal: refusal(result.reason) };
4145
+ const headers = new Headers(original.headers);
4146
+ headers.set("content-length", String(body.byteLength));
4147
+ headers.delete("transfer-encoding");
4148
+ return {
4149
+ request: new Request(original.url, {
4150
+ method: original.method,
4151
+ headers,
4152
+ body: body.byteLength > 0 ? new Uint8Array(body) : undefined,
4153
+ signal: original.signal
4154
+ })
4155
+ };
4156
+ }
4157
+
4158
+ // ../protocol/src/node/bridge-credential.ts
3892
4159
  var BRIDGE_TOKEN_PREFIX = "okb_";
3893
4160
  var PR_SET_DUMPABLE = 4;
3894
4161
  var VERIFIER_PATTERN = /^[0-9a-f]{64}$/;
3895
4162
  var log = createLogger("bridge.lifecycle");
3896
4163
  function mintBridgeToken() {
3897
- return `${BRIDGE_TOKEN_PREFIX}${randomBytes(32).toString("base64url")}`;
4164
+ return `${BRIDGE_TOKEN_PREFIX}${randomBytes2(32).toString("base64url")}`;
3898
4165
  }
3899
4166
  function bridgeTokenVerifier(token) {
3900
- return createHash("sha256").update(token).digest("hex");
4167
+ return createHash2("sha256").update(token).digest("hex");
3901
4168
  }
3902
4169
  function bridgeTokenVerifierEnv(tokenEnv) {
3903
4170
  return `${tokenEnv}_SHA256`;
3904
4171
  }
3905
- function credentialFromVerifier(verifier, plainToken) {
4172
+ function credentialFromVerifier(verifier, plainToken, authority = UNENFORCED_AUTHORITY) {
3906
4173
  const expected = Buffer.from(verifier, "hex");
3907
4174
  return {
3908
4175
  plainToken,
4176
+ authority,
3909
4177
  matches(candidate) {
3910
4178
  if (!candidate)
3911
4179
  return false;
3912
- return timingSafeEqual(expected, createHash("sha256").update(candidate).digest());
4180
+ return timingSafeEqual(expected, createHash2("sha256").update(candidate).digest());
3913
4181
  }
3914
4182
  };
3915
4183
  }
3916
- function bridgeCredentialFromToken(token) {
3917
- return credentialFromVerifier(bridgeTokenVerifier(token), token);
4184
+ var UNENFORCED_AUTHORITY = loadBridgeAuthority("", { env: {} });
4185
+ function bridgeCredentialFromToken(token, authority = UNENFORCED_AUTHORITY) {
4186
+ return credentialFromVerifier(bridgeTokenVerifier(token), token, authority);
3918
4187
  }
3919
4188
  function markProcessNonDumpable(loadFfi = () => createRequire(import.meta.url)("bun:ffi")) {
3920
4189
  if (process.platform !== "linux" || !process.versions.bun)
@@ -3946,11 +4215,12 @@ function loadBridgeCredential(tokenEnv, options = {}) {
3946
4215
  const token = env[tokenEnv]?.trim();
3947
4216
  delete env[verifierEnv];
3948
4217
  delete env[tokenEnv];
4218
+ const authority = loadBridgeAuthority(tokenEnv, { env });
3949
4219
  if (verifier) {
3950
4220
  (options.harden ?? markProcessNonDumpable)();
3951
- return VERIFIER_PATTERN.test(verifier) ? credentialFromVerifier(verifier, undefined) : bridgeCredentialFromToken(mintBridgeToken());
4221
+ return VERIFIER_PATTERN.test(verifier) ? credentialFromVerifier(verifier, undefined, authority) : bridgeCredentialFromToken(mintBridgeToken(), authority);
3952
4222
  }
3953
- return bridgeCredentialFromToken(token || mintBridgeToken());
4223
+ return bridgeCredentialFromToken(token || mintBridgeToken(), authority);
3954
4224
  }
3955
4225
 
3956
4226
  // ../protocol/src/node/logger-environment.ts
@@ -4029,7 +4299,7 @@ function applyLogDetail(detail, env = process.env) {
4029
4299
  }
4030
4300
 
4031
4301
  // ../protocol/src/node/bridge-diagnostics.ts
4032
- import { createHash as createHash2 } from "node:crypto";
4302
+ import { createHash as createHash3 } from "node:crypto";
4033
4303
 
4034
4304
  // ../protocol/src/event-loop-stall-monitor.ts
4035
4305
  var log2 = createLogger("event-loop");
@@ -4128,7 +4398,7 @@ function sameSet(a, b) {
4128
4398
  function identity(value) {
4129
4399
  if (typeof value !== "string" || !value || value.length > MAX_ID_LENGTH)
4130
4400
  return;
4131
- return createHash2("sha256").update(value).digest("hex").slice(0, 16);
4401
+ return createHash3("sha256").update(value).digest("hex").slice(0, 16);
4132
4402
  }
4133
4403
  function readBridgeDebugFlag(value) {
4134
4404
  return value?.trim() === "1";
@@ -4582,7 +4852,7 @@ var X_ALREADY_SENT = "x-hono-already-sent";
4582
4852
 
4583
4853
  // ../../node_modules/.bun/@hono+node-server@2.1.5+c539cad7f494f5c9/node_modules/@hono/node-server/dist/index.mjs
4584
4854
  import { STATUS_CODES, ServerResponse, createServer } from "node:http";
4585
- import { Http2ServerRequest, constants } from "node:http2";
4855
+ import { Http2ServerRequest, constants as constants2 } from "node:http2";
4586
4856
  import { Readable } from "node:stream";
4587
4857
 
4588
4858
  // ../../node_modules/.bun/hono@4.13.13/node_modules/hono/dist/helper/websocket/index.js
@@ -5501,7 +5771,7 @@ var drainIncoming = (incoming) => {
5501
5771
  incomingWithDrainState[incomingDraining] = true;
5502
5772
  if (incoming instanceof Http2ServerRequest) {
5503
5773
  try {
5504
- incoming.stream?.close?.(constants.NGHTTP2_NO_ERROR);
5774
+ incoming.stream?.close?.(constants2.NGHTTP2_NO_ERROR);
5505
5775
  } catch {}
5506
5776
  return;
5507
5777
  }
@@ -7997,7 +8267,7 @@ function structuredOutputFailure(provider, code, message, options = {}) {
7997
8267
 
7998
8268
  // ../protocol/src/node/workspace-change-probe.ts
7999
8269
  import { randomUUID as randomUUID2 } from "node:crypto";
8000
- import { rmSync } from "node:fs";
8270
+ import { rmSync as rmSync2 } from "node:fs";
8001
8271
  import { copyFile, lstat, mkdtemp, rm } from "node:fs/promises";
8002
8272
  import { tmpdir } from "node:os";
8003
8273
  import { delimiter, isAbsolute, join, resolve } from "node:path";
@@ -8210,6 +8480,7 @@ function classifyCommandFailure(error, options = {}) {
8210
8480
  import { createRequire as createRequire2 } from "node:module";
8211
8481
 
8212
8482
  // ../protocol/src/node/shell-process-state.ts
8483
+ import { spawnSync } from "node:child_process";
8213
8484
  import { readdirSync, readFileSync } from "node:fs";
8214
8485
  import { constants as osConstants } from "node:os";
8215
8486
  var PROCESS_INSPECTION_OPTIONS = {
@@ -8279,8 +8550,11 @@ function linuxGroupHasLiveMember(pgid) {
8279
8550
  return false;
8280
8551
  }
8281
8552
  function psGroupHasLiveMember(pgid) {
8282
- const result = bunRuntime()?.spawnSync(["/bin/ps", "-A", "-o", "pgid=,stat="], PROCESS_INSPECTION_OPTIONS);
8283
- if (!result?.success)
8553
+ const argv = ["-A", "-o", "pgid=,stat="];
8554
+ const bun = bunRuntime();
8555
+ const result = bun ? bun.spawnSync(["/bin/ps", ...argv], PROCESS_INSPECTION_OPTIONS) : spawnSync("/bin/ps", argv, PROCESS_INSPECTION_OPTIONS);
8556
+ const succeeded = "success" in result ? result.success : result.status === 0 && !result.error;
8557
+ if (!succeeded)
8284
8558
  return true;
8285
8559
  return result.stdout.toString().split(`
8286
8560
  `).some((line) => {
@@ -8642,6 +8916,7 @@ function executeCommandBytes(command, args, options, timeoutMs, outputLimit, std
8642
8916
  let limitTimer;
8643
8917
  let stopExitWatch = () => {};
8644
8918
  let commandExit;
8919
+ let pendingFailure;
8645
8920
  const finishCapture = () => {
8646
8921
  settled = true;
8647
8922
  clearTimeout(timeoutTimer);
@@ -8663,13 +8938,33 @@ function executeCommandBytes(command, args, options, timeoutMs, outputLimit, std
8663
8938
  releaseCaptureFds();
8664
8939
  }
8665
8940
  };
8666
- const fail = (error) => {
8667
- if (settled)
8668
- return;
8941
+ const rejectFailure = (error) => {
8669
8942
  const output = finishCapture();
8670
8943
  if (output)
8671
8944
  reject(Object.assign(error, { ...output, killed: timedOut }));
8672
8945
  };
8946
+ const awaitTermination = (delayMs) => {
8947
+ clearTimeout(groupTimer);
8948
+ if (settled)
8949
+ return;
8950
+ if ((commandExit || exitReported(child)) && !commandGroupAlive(child)) {
8951
+ rejectFailure(pendingFailure);
8952
+ return;
8953
+ }
8954
+ groupTimer = setTimeout(awaitTermination, delayMs, Math.min(delayMs * 2, COMMAND_GROUP_POLL_MAX_MS));
8955
+ };
8956
+ const fail = (error) => {
8957
+ if (settled || pendingFailure)
8958
+ return;
8959
+ if (options.waitForTermination && child.pid !== undefined) {
8960
+ pendingFailure = error;
8961
+ signalCommand(child, "SIGKILL");
8962
+ clearTimeout(timeoutTimer);
8963
+ clearInterval(limitTimer);
8964
+ awaitTermination(COMMAND_GROUP_POLL_MS);
8965
+ } else
8966
+ rejectFailure(error);
8967
+ };
8673
8968
  const abort = () => {
8674
8969
  timedOut = true;
8675
8970
  signalCommand(child, "SIGKILL");
@@ -8696,11 +8991,11 @@ function executeCommandBytes(command, args, options, timeoutMs, outputLimit, std
8696
8991
  }
8697
8992
  };
8698
8993
  limitTimer = setInterval(() => {
8699
- if (!settled && !timedOut)
8994
+ if (!settled && !timedOut && !pendingFailure)
8700
8995
  failIfOverLimit();
8701
8996
  }, COMMAND_OUTPUT_CHECK_MS);
8702
8997
  const settleOnExit = () => {
8703
- if (settled || timedOut || failIfOverLimit())
8998
+ if (settled || timedOut || pendingFailure || failIfOverLimit())
8704
8999
  return;
8705
9000
  if (commandExit?.code !== 0 || commandExit.signal !== null) {
8706
9001
  fail(Object.assign(new Error(`Command failed: ${[command, ...args].join(" ")}`), {
@@ -8714,7 +9009,7 @@ function executeCommandBytes(command, args, options, timeoutMs, outputLimit, std
8714
9009
  resolve(output);
8715
9010
  };
8716
9011
  const awaitGroupExit = (delayMs) => {
8717
- if (settled || timedOut)
9012
+ if (settled || timedOut || pendingFailure)
8718
9013
  return;
8719
9014
  if (commandGroupAlive(child)) {
8720
9015
  groupTimer = setTimeout(awaitGroupExit, delayMs, Math.min(delayMs * 2, COMMAND_GROUP_POLL_MAX_MS));
@@ -8727,14 +9022,16 @@ function executeCommandBytes(command, args, options, timeoutMs, outputLimit, std
8727
9022
  return;
8728
9023
  commandExit = exit;
8729
9024
  stopExitWatch();
8730
- if (options.waitForDescendants)
9025
+ if (pendingFailure)
9026
+ awaitTermination(COMMAND_GROUP_POLL_MS);
9027
+ else if (options.waitForDescendants)
8731
9028
  awaitGroupExit(COMMAND_GROUP_POLL_MS);
8732
9029
  else
8733
9030
  settleOnExit();
8734
9031
  };
8735
9032
  child.exited.then(onCommandExit, (error) => fail(error instanceof Error ? error : new Error(String(error))));
8736
9033
  stopExitWatch = watchForLostExit(child.pid, (exit) => {
8737
- if (!settled && !timedOut)
9034
+ if (!settled)
8738
9035
  onCommandExit(exit);
8739
9036
  });
8740
9037
  if (timeoutMs > 0) {
@@ -8826,7 +9123,7 @@ var temporaryObjectDirectories = new Set;
8826
9123
  process.once("exit", () => {
8827
9124
  for (const directory of temporaryObjectDirectories) {
8828
9125
  try {
8829
- rmSync(directory, { recursive: true, force: true });
9126
+ rmSync2(directory, { recursive: true, force: true });
8830
9127
  } catch {}
8831
9128
  }
8832
9129
  });
@@ -9901,7 +10198,7 @@ function registerSessionActivityBatchRoute(app, runtime) {
9901
10198
  import { randomUUID as randomUUID3 } from "node:crypto";
9902
10199
 
9903
10200
  // ../protocol/src/node/revised-rows.ts
9904
- import { createHash as createHash3 } from "node:crypto";
10201
+ import { createHash as createHash4 } from "node:crypto";
9905
10202
  var RECENTLY_REVISED_ROWS_MAX = 128;
9906
10203
 
9907
10204
  class RecentlyRevisedRows {
@@ -9939,7 +10236,7 @@ class RecentlyRevisedRows {
9939
10236
  function revisedRowsReconciliationToken(overflowVersion, omitted) {
9940
10237
  if (overflowVersion === 0 && omitted.length === 0)
9941
10238
  return;
9942
- const digest = createHash3("sha256").update(String(overflowVersion));
10239
+ const digest = createHash4("sha256").update(String(overflowVersion));
9943
10240
  for (const row of omitted)
9944
10241
  digest.update(JSON.stringify(row) ?? "null");
9945
10242
  return digest.digest("hex");
@@ -9947,7 +10244,7 @@ function revisedRowsReconciliationToken(overflowVersion, omitted) {
9947
10244
 
9948
10245
  // ../protocol/src/node/bridge-transcript-summary.ts
9949
10246
  import { Buffer as Buffer3 } from "node:buffer";
9950
- import { createHash as createHash4 } from "node:crypto";
10247
+ import { createHash as createHash5 } from "node:crypto";
9951
10248
 
9952
10249
  // ../protocol/src/node/progressive-transcript.ts
9953
10250
  var BRIDGE_TRANSCRIPT_MAX_MESSAGES = 100;
@@ -10113,7 +10410,7 @@ function digestPayload(payload) {
10113
10410
  const serialized = JSON.stringify(payload);
10114
10411
  return {
10115
10412
  bytes: Buffer3.byteLength(serialized),
10116
- digest: createHash4("sha256").update(serialized).digest("base64url").slice(0, 32)
10413
+ digest: createHash5("sha256").update(serialized).digest("base64url").slice(0, 32)
10117
10414
  };
10118
10415
  }
10119
10416
  function topLevelKey(part, index) {
@@ -10558,7 +10855,7 @@ function registerCodexChangeEvidenceRoutes(app, spool) {
10558
10855
  }
10559
10856
 
10560
10857
  // ../../bridges/codex-bridge/src/change-evidence.ts
10561
- import { createHash as createHash6 } from "node:crypto";
10858
+ import { createHash as createHash7 } from "node:crypto";
10562
10859
  import { existsSync as existsSync2 } from "node:fs";
10563
10860
  import { basename, join as join8 } from "node:path";
10564
10861
 
@@ -10965,7 +11262,7 @@ function workspaceObservationReportIssues(value) {
10965
11262
  }
10966
11263
 
10967
11264
  // ../protocol/src/node/change-tracking/evidence-spool.ts
10968
- import { createHash as createHash5, randomUUID as randomUUID4 } from "node:crypto";
11265
+ import { createHash as createHash6, randomUUID as randomUUID4 } from "node:crypto";
10969
11266
  import { readdirSync as readdirSync2, readFileSync as readFileSync2 } from "node:fs";
10970
11267
  import { appendFile, mkdir, rename, rm as rm2, writeFile } from "node:fs/promises";
10971
11268
  import { join as join3 } from "node:path";
@@ -10981,10 +11278,10 @@ var DEFAULT_EVIDENCE_SPOOL_LIMITS = {
10981
11278
  var ENTRIES_FILE = "entries.jsonl";
10982
11279
  var BODY_DIRECTORY = "bodies";
10983
11280
  function evidenceBodyId(bytes) {
10984
- return `sha256:${createHash5("sha256").update(bytes).digest("hex")}`;
11281
+ return `sha256:${createHash6("sha256").update(bytes).digest("hex")}`;
10985
11282
  }
10986
11283
  function stableEvidenceId(...parts) {
10987
- const hash = createHash5("sha256");
11284
+ const hash = createHash6("sha256");
10988
11285
  for (const part of parts)
10989
11286
  hash.update(`${part ?? ""}\x00`);
10990
11287
  return hash.digest("hex").slice(0, 40);
@@ -12198,13 +12495,13 @@ import {
12198
12495
  readFileSync as readFileSync3,
12199
12496
  readdirSync as readdirSync3,
12200
12497
  renameSync,
12201
- rmSync as rmSync2,
12498
+ rmSync as rmSync3,
12202
12499
  statSync,
12203
12500
  writeFileSync
12204
12501
  } from "node:fs";
12205
12502
  import { join as join7, resolve as resolve2 } from "node:path";
12206
12503
  import { isDeepStrictEqual } from "node:util";
12207
- function readBounded(path, limit) {
12504
+ function readBounded2(path, limit) {
12208
12505
  if (statSync(path).size > limit)
12209
12506
  throw new Error("Evidence migration exceeds storage capacity");
12210
12507
  const bytes = readFileSync3(path);
@@ -12218,7 +12515,7 @@ function publishFile(path, contents) {
12218
12515
  writeFileSync(temporary, contents, { mode: 384 });
12219
12516
  renameSync(temporary, path);
12220
12517
  } finally {
12221
- rmSync2(temporary, { force: true });
12518
+ rmSync3(temporary, { force: true });
12222
12519
  }
12223
12520
  }
12224
12521
  function migrateCodexChangeEvidence(legacy, shared) {
@@ -12233,7 +12530,7 @@ function migrateCodexChangeEvidence(legacy, shared) {
12233
12530
  const file = join7(directory, "entries.jsonl");
12234
12531
  if (!existsSync(file))
12235
12532
  continue;
12236
- for (const line of readBounded(file, DEFAULT_EVIDENCE_SPOOL_LIMITS.maxQueuedBytes).toString("utf8").split(`
12533
+ for (const line of readBounded2(file, DEFAULT_EVIDENCE_SPOOL_LIMITS.maxQueuedBytes).toString("utf8").split(`
12237
12534
  `)) {
12238
12535
  if (!line)
12239
12536
  continue;
@@ -12274,7 +12571,7 @@ function migrateCodexChangeEvidence(legacy, shared) {
12274
12571
  for (const id of bodyIds) {
12275
12572
  const name = id.replace(/[^A-Za-z0-9]/g, "_");
12276
12573
  const target = join7(shared, "bodies", name);
12277
- const bytes = readBounded(existsSync(target) ? target : join7(legacy, "bodies", name), DEFAULT_EVIDENCE_SPOOL_LIMITS.maxSingleBodyBytes);
12574
+ const bytes = readBounded2(existsSync(target) ? target : join7(legacy, "bodies", name), DEFAULT_EVIDENCE_SPOOL_LIMITS.maxSingleBodyBytes);
12278
12575
  if (evidenceBodyId(bytes) !== id)
12279
12576
  throw new Error("Evidence migration body integrity failed");
12280
12577
  bodyBytes += bytes.length;
@@ -12286,11 +12583,11 @@ function migrateCodexChangeEvidence(legacy, shared) {
12286
12583
  const retainedNames = new Set([...bodyIds].map((id) => id.replace(/[^A-Za-z0-9]/g, "_")));
12287
12584
  for (const name of readdirSync3(join7(shared, "bodies"))) {
12288
12585
  if (/^sha256_[a-f0-9]{64}$/.test(name) && !retainedNames.has(name)) {
12289
- rmSync2(join7(shared, "bodies", name));
12586
+ rmSync3(join7(shared, "bodies", name));
12290
12587
  }
12291
12588
  }
12292
12589
  publishFile(join7(shared, "entries.jsonl"), contents);
12293
- rmSync2(legacyFile);
12590
+ rmSync3(legacyFile);
12294
12591
  }
12295
12592
 
12296
12593
  // ../../bridges/codex-bridge/src/change-evidence.ts
@@ -12529,7 +12826,7 @@ function suppliedMovePath(change) {
12529
12826
  return supplied?.kind === "update" ? supplied.movePath : change.move_path;
12530
12827
  }
12531
12828
  function codexChangeEvidenceDir(codexHome, cwd) {
12532
- const cwdHash = createHash6("sha256").update(cwd).digest("hex").slice(0, 16);
12829
+ const cwdHash = createHash7("sha256").update(cwd).digest("hex").slice(0, 16);
12533
12830
  return join8(codexBridgeStateDir(codexHome), "change-evidence", cwdHash);
12534
12831
  }
12535
12832
  function createCodexChangeEvidence(options) {
@@ -13198,13 +13495,13 @@ function humanPromptObservation(messages, tasks) {
13198
13495
  var USAGE_LIMIT_ERROR_CODE = "usage-limit";
13199
13496
 
13200
13497
  // ../../bridges/codex-bridge/src/sessions/typed-prompts.ts
13201
- import { createHash as createHash7, randomUUID as randomUUID6 } from "node:crypto";
13498
+ import { createHash as createHash8, randomUUID as randomUUID6 } from "node:crypto";
13202
13499
  import { mkdir as mkdir4, open, opendir, rename as rename3, rm as rm4, writeFile as writeFile3 } from "node:fs/promises";
13203
13500
  import { dirname as dirname2, join as join10 } from "node:path";
13204
13501
  var MAX_TYPED_PROMPT_CHARS = 32000;
13205
13502
  var MAX_RECORD_BYTES = 6 * MAX_TYPED_PROMPT_CHARS + 2048;
13206
13503
  function typedPromptDigest(sentText) {
13207
- return createHash7("sha256").update(sentText.trim()).digest("hex");
13504
+ return createHash8("sha256").update(sentText.trim()).digest("hex");
13208
13505
  }
13209
13506
  function typedPromptFor(record, sentText) {
13210
13507
  return record?.sent === typedPromptDigest(sentText) ? record.typed : undefined;
@@ -15424,7 +15721,7 @@ async function deriveTranscriptSubagentPartsForTurn({
15424
15721
  }
15425
15722
 
15426
15723
  // ../../bridges/codex-bridge/src/history/rollout.ts
15427
- import { createHash as createHash8 } from "node:crypto";
15724
+ import { createHash as createHash9 } from "node:crypto";
15428
15725
  import { readdir, stat as stat5 } from "node:fs/promises";
15429
15726
  import { homedir } from "node:os";
15430
15727
  import { basename as basename2, join as join11 } from "node:path";
@@ -16909,6 +17206,24 @@ function mcpToolCallParts(item) {
16909
17206
  }
16910
17207
  ];
16911
17208
  }
17209
+ function commandExecutionParts(item) {
17210
+ const output = capCommandOutput(item.aggregated_output);
17211
+ const failed = item.status === "failed";
17212
+ return [
17213
+ {
17214
+ type: "tool-invocation",
17215
+ toolUseId: item.id,
17216
+ content: item.command,
17217
+ toolName: "bash",
17218
+ toolArgs: { command: item.command },
17219
+ toolState: item.status === "failed" ? "failure" : item.status === "completed" ? "success" : "pending",
17220
+ toolTitle: item.command,
17221
+ toolOutput: failed ? undefined : output || undefined,
17222
+ toolError: failed ? output || "Command failed" : undefined,
17223
+ ...finishedDuration(item)
17224
+ }
17225
+ ];
17226
+ }
16912
17227
  async function itemToParts(item, cwd, fileChangeContext) {
16913
17228
  switch (item.type) {
16914
17229
  case "agent_message":
@@ -16931,24 +17246,8 @@ async function itemToParts(item, cwd, fileChangeContext) {
16931
17246
  return [{ type: "text", content: agentMessageDisplayText(item) }];
16932
17247
  case "reasoning":
16933
17248
  return hasVisibleText(item.text) ? [{ type: "thinking", content: item.text }] : [];
16934
- case "command_execution": {
16935
- const output = capCommandOutput(item.aggregated_output);
16936
- const failed = item.status === "failed";
16937
- return [
16938
- {
16939
- type: "tool-invocation",
16940
- toolUseId: item.id,
16941
- content: item.command,
16942
- toolName: "bash",
16943
- toolArgs: { command: item.command },
16944
- toolState: item.status === "failed" ? "failure" : item.status === "completed" ? "success" : "pending",
16945
- toolTitle: item.command,
16946
- toolOutput: failed ? undefined : output || undefined,
16947
- toolError: failed ? output || "Command failed" : undefined,
16948
- ...finishedDuration(item)
16949
- }
16950
- ];
16951
- }
17249
+ case "command_execution":
17250
+ return commandExecutionParts(item);
16952
17251
  case "file_change":
16953
17252
  return item.changes.map((change, index) => ({
16954
17253
  type: "tool-invocation",
@@ -17255,6 +17554,35 @@ function codeModeMcpCallPart(call, toolUseId) {
17255
17554
  })[0];
17256
17555
  }
17257
17556
 
17557
+ // ../../bridges/codex-bridge/src/history/code-mode-commands.ts
17558
+ var ROLLOUT_COMMAND_EXECUTION_ITEM_TYPE = "CommandExecution";
17559
+ var PLAIN_WORD = /^[A-Za-z0-9_@%+=:,./-]+$/;
17560
+ function joinCommandArguments(argv) {
17561
+ return argv.map((word) => word === "" ? "''" : PLAIN_WORD.test(word) ? word : `'${word.replaceAll("'", `'"'"'`)}'`).join(" ");
17562
+ }
17563
+ function isRecord8(value) {
17564
+ return !!value && typeof value === "object" && !Array.isArray(value);
17565
+ }
17566
+ function rolloutCommandExecutionParts(item) {
17567
+ if (!isRecord8(item) || item.type !== ROLLOUT_COMMAND_EXECUTION_ITEM_TYPE)
17568
+ return null;
17569
+ if (typeof item.id !== "string" || item.id.length === 0)
17570
+ return null;
17571
+ const command = Array.isArray(item.command) ? item.command.every((word) => typeof word === "string") ? joinCommandArguments(item.command) : undefined : typeof item.command === "string" ? item.command : undefined;
17572
+ if (command === undefined)
17573
+ return null;
17574
+ const { item: adapted } = adaptAppServerItem({
17575
+ id: item.id,
17576
+ type: "commandExecution",
17577
+ command,
17578
+ aggregatedOutput: item.aggregated_output,
17579
+ status: item.status,
17580
+ exitCode: item.exit_code,
17581
+ durationMs: rolloutDurationMs(item.duration) ?? null
17582
+ });
17583
+ return adapted?.type === "command_execution" ? commandExecutionParts(adapted) : null;
17584
+ }
17585
+
17258
17586
  // ../protocol/src/coordinator.ts
17259
17587
  var COORDINATOR_CODEX_USER_SKILLS_DIR_ENV = "ORKESTRATOR_COORDINATOR_CODEX_USER_SKILLS_DIR";
17260
17588
  var COORDINATOR_OTHER_ENVIRONMENTS_SETTING_LABEL = "Let the coordinator use environments it did not create";
@@ -18321,7 +18649,7 @@ var NON_TOOL_TURN_ITEM_TYPES = new Set([
18321
18649
  ]);
18322
18650
  var MAX_OPEN_CODE_MODE_CELLS = 256;
18323
18651
  function replayedRowId(threadId, scope, kind, ordinal) {
18324
- const digest = createHash8("sha256").update(`${threadId}\x00${scope}\x00${kind}\x00${ordinal}`).digest("hex");
18652
+ const digest = createHash9("sha256").update(`${threadId}\x00${scope}\x00${kind}\x00${ordinal}`).digest("hex");
18325
18653
  return `msg-r-${digest.slice(0, 32)}`;
18326
18654
  }
18327
18655
  async function forEachHistoryBatch(snapshot, visit) {
@@ -18385,6 +18713,7 @@ async function replayPersistedRollout(threadId, snapshot, meta, structuredTurns)
18385
18713
  const spawnPartSlots = new Map;
18386
18714
  const messages = [];
18387
18715
  const toolPartsByCallId = new Map;
18716
+ const turnCallIds = new Set;
18388
18717
  const transcriptCwd = asNonEmptyString2(meta.cwd) ?? getWorkingDirectory();
18389
18718
  let currentTurnId;
18390
18719
  let currentTurnModel;
@@ -18464,6 +18793,10 @@ async function replayPersistedRollout(threadId, snapshot, meta, structuredTurns)
18464
18793
  const { toolState: _inFlight, ...settled } = cell.message.parts[call.partIndex];
18465
18794
  cell.message.parts[call.partIndex] = outcome?.failed ? { ...settled, toolState: "failure" } : settled;
18466
18795
  }
18796
+ if (cell.sawCommandRecord && cell.sourceCalls.length === 0 && !cell.keepExecRow && !outcome?.refused) {
18797
+ toolPartsByCallId.delete(cell.callId);
18798
+ dropPart(cell.message, cell.execPartIndex);
18799
+ }
18467
18800
  };
18468
18801
  const settleOpenCells = () => {
18469
18802
  for (const cell of openCells.values())
@@ -18494,13 +18827,32 @@ async function replayPersistedRollout(threadId, snapshot, meta, structuredTurns)
18494
18827
  callees: codeModeMcpCallees(source),
18495
18828
  sourceCalls,
18496
18829
  sawMcpRecord: false,
18830
+ sawCommandRecord: false,
18497
18831
  keepExecRow: false
18498
18832
  });
18499
18833
  };
18834
+ const visitCommandRecord = (item) => {
18835
+ const open = [...openCells.values()];
18836
+ const parts = rolloutCommandExecutionParts(item);
18837
+ const id = asNonEmptyString2(item.id);
18838
+ const direct = id !== undefined && turnCallIds.has(id);
18839
+ if (!parts || direct || open.length !== 1) {
18840
+ for (const cell of open)
18841
+ cell.keepExecRow = true;
18842
+ return;
18843
+ }
18844
+ const cell = open[0];
18845
+ cell.sawCommandRecord = true;
18846
+ cell.message.parts.push(...parts);
18847
+ };
18500
18848
  const visitCompletedItem = (item, timestamp) => {
18501
18849
  if (!item || typeof item !== "object" || Array.isArray(item))
18502
18850
  return;
18503
18851
  const fields = item;
18852
+ if (fields.type === ROLLOUT_COMMAND_EXECUTION_ITEM_TYPE) {
18853
+ visitCommandRecord(fields);
18854
+ return;
18855
+ }
18504
18856
  if (fields.type !== ROLLOUT_MCP_TOOL_CALL_ITEM_TYPE) {
18505
18857
  if (typeof fields.type === "string" && !NON_TOOL_TURN_ITEM_TYPES.has(fields.type)) {
18506
18858
  for (const cell of openCells.values())
@@ -18615,6 +18967,7 @@ async function replayPersistedRollout(threadId, snapshot, meta, structuredTurns)
18615
18967
  if (recordTurnId && recordTurnId !== currentTurnId) {
18616
18968
  settleOpenCells();
18617
18969
  currentTurnId = recordTurnId;
18970
+ turnCallIds.clear();
18618
18971
  typedPromptConsumed = false;
18619
18972
  currentTurnModel = undefined;
18620
18973
  closeAssistantRow();
@@ -18662,6 +19015,11 @@ async function replayPersistedRollout(threadId, snapshot, meta, structuredTurns)
18662
19015
  }
18663
19016
  if (ROLLOUT_TOOL_CALL_TYPES.has(String(payload.type)))
18664
19017
  currentRowCalledTool = true;
19018
+ if (ROLLOUT_TOOL_CALL_TYPES.has(String(payload.type))) {
19019
+ const callId = asNonEmptyString2(payload.call_id);
19020
+ if (callId)
19021
+ turnCallIds.add(callId);
19022
+ }
18665
19023
  if (payload.type === "function_call" || payload.type === "custom_tool_call") {
18666
19024
  const assistantMessage = ensureAssistantMessage(timestamp);
18667
19025
  const callId = asNonEmptyString2(payload.call_id);
@@ -19482,7 +19840,7 @@ function openModelResponseRow(context, state, turn, event, now) {
19482
19840
  });
19483
19841
  return true;
19484
19842
  }
19485
- function segmentNeedsRender(turn, segment, historical, now = Date.now()) {
19843
+ function segmentNeedsRender(turn, segment, historical, now = Date.now(), probeIntervalMs = SUBAGENT_TRANSCRIPT_PROBE_INTERVAL_MS) {
19486
19844
  if (turn.assistantSegmentVersion(segment.assistantMessageId) !== historical.renderedItemVersion) {
19487
19845
  return true;
19488
19846
  }
@@ -19494,15 +19852,36 @@ function segmentNeedsRender(turn, segment, historical, now = Date.now()) {
19494
19852
  return false;
19495
19853
  }
19496
19854
  const probedAt = historical.render.subagentProbedAt;
19497
- return probedAt === 0 || now - probedAt >= SUBAGENT_TRANSCRIPT_PROBE_INTERVAL_MS;
19855
+ return probedAt === 0 || now - probedAt >= probeIntervalMs;
19856
+ }
19857
+ function scheduleSubagentProbe(state, turn, intervalMs, onDue) {
19858
+ const waiting = !turn.isTerminal() && (state.render.subagentActivity && !state.render.subagentSettled || Array.from(state.historicalAssistantSegments.values()).some((row) => !row.retiring && awaitsSubagent(row)));
19859
+ if (!waiting) {
19860
+ cancelSubagentProbe(state);
19861
+ return;
19862
+ }
19863
+ if (state.subagentProbeTimer)
19864
+ return;
19865
+ state.subagentProbeTimer = setTimeout(() => {
19866
+ state.subagentProbeTimer = undefined;
19867
+ onDue();
19868
+ }, intervalMs);
19869
+ state.subagentProbeTimer.unref?.();
19870
+ }
19871
+ function cancelSubagentProbe(state) {
19872
+ if (!state.subagentProbeTimer)
19873
+ return;
19874
+ clearTimeout(state.subagentProbeTimer);
19875
+ state.subagentProbeTimer = undefined;
19498
19876
  }
19499
19877
  async function publishAssistantRows(context, state, turn, options) {
19500
19878
  const now = Date.now();
19879
+ const probeIntervalMs = options.subagentProbeIntervalMs ?? SUBAGENT_TRANSCRIPT_PROBE_INTERVAL_MS;
19501
19880
  trackChangedRows(context, state, turn, now);
19502
19881
  const due = [];
19503
19882
  for (const [id, historical] of state.historicalAssistantSegments) {
19504
19883
  const segment = turn.findAssistantSegment(id);
19505
- if (segment && segmentNeedsRender(turn, segment, historical, now)) {
19884
+ if (segment && segmentNeedsRender(turn, segment, historical, now, probeIntervalMs)) {
19506
19885
  due.push(id);
19507
19886
  } else if (historical.retiring) {
19508
19887
  releaseRow(state, turn, id, historical);
@@ -19527,7 +19906,7 @@ async function publishAssistantRows(context, state, turn, options) {
19527
19906
  cwd: options.cwd,
19528
19907
  state: renderState,
19529
19908
  segment,
19530
- subagentProbeIntervalMs: SUBAGENT_TRANSCRIPT_PROBE_INTERVAL_MS,
19909
+ subagentProbeIntervalMs: probeIntervalMs,
19531
19910
  ...startedHistorical && !renderState.subagentActivity ? { skipSubagentProbe: true } : {}
19532
19911
  });
19533
19912
  const isCurrent = id === turn.assistantMessageId;
@@ -19598,7 +19977,7 @@ async function publishAssistantRows(context, state, turn, options) {
19598
19977
  }
19599
19978
 
19600
19979
  // ../../bridges/codex-bridge/src/app-server-runtime-sessions.ts
19601
- import { createHash as createHash13, randomUUID as randomUUID9 } from "node:crypto";
19980
+ import { createHash as createHash14, randomUUID as randomUUID9 } from "node:crypto";
19602
19981
 
19603
19982
  // ../protocol/src/agent-mail.ts
19604
19983
  var AGENT_MAIL_MAX_BODY_BYTES = 32 * 1024;
@@ -19934,7 +20313,7 @@ var ORKESTRATOR_ARTIFACT_MCP_PATH = "/artifact-mcp";
19934
20313
 
19935
20314
  // ../../bridges/codex-bridge/src/engine/app-server-engine.ts
19936
20315
  import { open as open9 } from "node:fs/promises";
19937
- import { createHash as createHash12 } from "node:crypto";
20316
+ import { createHash as createHash13 } from "node:crypto";
19938
20317
  import { isAbsolute as isAbsolute9, join as join20 } from "node:path";
19939
20318
 
19940
20319
  // ../../bridges/codex-bridge/src/app-server/process-supervisor.ts
@@ -20108,14 +20487,14 @@ var PREVIEW_LIMIT = 200;
20108
20487
  function preview(value) {
20109
20488
  return value.length > PREVIEW_LIMIT ? `${value.slice(0, PREVIEW_LIMIT)}…` : value;
20110
20489
  }
20111
- function isRecord8(value) {
20490
+ function isRecord9(value) {
20112
20491
  return !!value && typeof value === "object" && !Array.isArray(value);
20113
20492
  }
20114
20493
  function isValidId(value) {
20115
20494
  return typeof value === "string" || typeof value === "number" && Number.isFinite(value);
20116
20495
  }
20117
20496
  function parseErrorBody(value) {
20118
- if (!isRecord8(value))
20497
+ if (!isRecord9(value))
20119
20498
  return null;
20120
20499
  const code = typeof value.code === "number" ? value.code : null;
20121
20500
  if (code === null)
@@ -20127,7 +20506,7 @@ function parseErrorBody(value) {
20127
20506
  };
20128
20507
  }
20129
20508
  function classifyInbound(value) {
20130
- if (!isRecord8(value)) {
20509
+ if (!isRecord9(value)) {
20131
20510
  return {
20132
20511
  kind: "invalid",
20133
20512
  detail: "envelope is not an object",
@@ -20194,11 +20573,11 @@ function parseInboundLine(line) {
20194
20573
  return classifyInbound(parsed);
20195
20574
  }
20196
20575
  function extractThreadId(params) {
20197
- if (!isRecord8(params))
20576
+ if (!isRecord9(params))
20198
20577
  return null;
20199
20578
  if (typeof params.threadId === "string" && params.threadId.length > 0)
20200
20579
  return params.threadId;
20201
- if (isRecord8(params.thread) && typeof params.thread.id === "string")
20580
+ if (isRecord9(params.thread) && typeof params.thread.id === "string")
20202
20581
  return params.thread.id;
20203
20582
  return null;
20204
20583
  }
@@ -20774,7 +21153,7 @@ function createRecorderFromEnv(options) {
20774
21153
 
20775
21154
  // ../../bridges/codex-bridge/src/runtime-env.ts
20776
21155
  import { execFile as execFileCallback } from "node:child_process";
20777
- import { createHash as createHash9 } from "node:crypto";
21156
+ import { createHash as createHash10 } from "node:crypto";
20778
21157
  import { promisify } from "node:util";
20779
21158
  var log9 = createLogger("bridge.codex");
20780
21159
  var execFile = promisify(execFileCallback);
@@ -20861,7 +21240,7 @@ async function refreshRuntimeEnvironment(run = execFile) {
20861
21240
  }
20862
21241
  }
20863
21242
  function fingerprintRuntimeEnvironment(env = process.env) {
20864
- const hash = createHash9("sha256");
21243
+ const hash = createHash10("sha256");
20865
21244
  for (const name of [...RUNTIME_ENV_VARIABLES].sort()) {
20866
21245
  hash.update(name);
20867
21246
  hash.update("\x00");
@@ -21871,14 +22250,14 @@ function proposedPrefix(value) {
21871
22250
  }
21872
22251
  return [...value];
21873
22252
  }
21874
- function isRecord9(value) {
22253
+ function isRecord10(value) {
21875
22254
  return !!value && typeof value === "object" && !Array.isArray(value);
21876
22255
  }
21877
22256
  function str2(value) {
21878
22257
  return typeof value === "string" && value.length > 0 ? value : undefined;
21879
22258
  }
21880
22259
  function changeKind2(value) {
21881
- const type = isRecord9(value) ? value.type : value;
22260
+ const type = isRecord10(value) ? value.type : value;
21882
22261
  return type === "add" ? "add" : type === "delete" ? "delete" : "update";
21883
22262
  }
21884
22263
  function commandText(value) {
@@ -21893,23 +22272,23 @@ function commandText(value) {
21893
22272
  function commandActionsText(value) {
21894
22273
  if (!Array.isArray(value))
21895
22274
  return;
21896
- const commands = value.map((entry) => isRecord9(entry) ? str2(entry.command) : undefined).filter((entry) => entry !== undefined);
22275
+ const commands = value.map((entry) => isRecord10(entry) ? str2(entry.command) : undefined).filter((entry) => entry !== undefined);
21897
22276
  return commands.length > 0 ? [...new Set(commands)].join(`
21898
22277
  `) : undefined;
21899
22278
  }
21900
22279
  function describeApproval(options) {
21901
- const params = isRecord9(options.params) ? options.params : {};
22280
+ const params = isRecord10(options.params) ? options.params : {};
21902
22281
  const kind = options.method === "item/permissions/requestApproval" ? "permissions" : options.method === "item/fileChange/requestApproval" || options.method === "applyPatchApproval" ? "file-change" : "command";
21903
- const changes = isRecord9(params.fileChanges) ? Object.entries(params.fileChanges).map(([path, change]) => ({
22282
+ const changes = isRecord10(params.fileChanges) ? Object.entries(params.fileChanges).map(([path, change]) => ({
21904
22283
  path,
21905
- kind: changeKind2(isRecord9(change) ? change.type : undefined),
21906
- ...isRecord9(change) && change.move_path != null ? { movePath: typeof change.move_path === "string" ? change.move_path : "" } : {}
22284
+ kind: changeKind2(isRecord10(change) ? change.type : undefined),
22285
+ ...isRecord10(change) && change.move_path != null ? { movePath: typeof change.move_path === "string" ? change.move_path : "" } : {}
21907
22286
  })) : undefined;
21908
- const permissions = isRecord9(params.permissions) ? {
22287
+ const permissions = isRecord10(params.permissions) ? {
21909
22288
  network: params.permissions.network != null,
21910
22289
  fileSystem: params.permissions.fileSystem != null
21911
22290
  } : undefined;
21912
- const networkContext = isRecord9(params.networkApprovalContext) ? str2(params.networkApprovalContext.host) : undefined;
22291
+ const networkContext = isRecord10(params.networkApprovalContext) ? str2(params.networkApprovalContext.host) : undefined;
21913
22292
  const command = commandText(params.command) ?? commandActionsText(params.commandActions);
21914
22293
  const v2Command = options.method === "item/commandExecution/requestApproval" && (params.kind === undefined || params.kind === null || params.kind === "command");
21915
22294
  const exactCommand = v2Command && typeof params.command === "string" && params.command.length > 0;
@@ -21960,8 +22339,8 @@ function buildApprovalResponse(method, decision, rawParams) {
21960
22339
  };
21961
22340
  }
21962
22341
  case "item/permissions/requestApproval": {
21963
- const params = isRecord9(rawParams) ? rawParams : {};
21964
- const requested = isRecord9(params.permissions) ? params.permissions : {};
22342
+ const params = isRecord10(rawParams) ? rawParams : {};
22343
+ const requested = isRecord10(params.permissions) ? params.permissions : {};
21965
22344
  const granting = isGrantingApprovalDecision(decision);
21966
22345
  return {
21967
22346
  result: {
@@ -22712,7 +23091,7 @@ function asString2(value) {
22712
23091
  function assertNever(value) {}
22713
23092
 
22714
23093
  // ../../bridges/codex-bridge/src/app-server/event-reducer.ts
22715
- function isRecord10(value) {
23094
+ function isRecord11(value) {
22716
23095
  return !!value && typeof value === "object" && !Array.isArray(value);
22717
23096
  }
22718
23097
  function str3(value) {
@@ -22740,7 +23119,7 @@ function epochSecondsToIso(value) {
22740
23119
  return new Date(ms).toISOString();
22741
23120
  }
22742
23121
  function toTurnError(raw) {
22743
- if (!isRecord10(raw)) {
23122
+ if (!isRecord11(raw)) {
22744
23123
  return { message: typeof raw === "string" ? raw : "Codex reported an error" };
22745
23124
  }
22746
23125
  const code = codexErrorInfoToCode(raw.codexErrorInfo);
@@ -22819,13 +23198,13 @@ function isIgnoredNotification(method) {
22819
23198
  function reduceNotification(notification, generation, handle) {
22820
23199
  const params = notification.params;
22821
23200
  const base = { engineGeneration: generation, ...handle ? { handle } : {} };
22822
- const threadId = isRecord10(params) ? str3(params.threadId) ?? null : null;
22823
- const turnId = isRecord10(params) ? str3(params.turnId) : undefined;
23201
+ const threadId = isRecord11(params) ? str3(params.threadId) ?? null : null;
23202
+ const turnId = isRecord11(params) ? str3(params.turnId) : undefined;
22824
23203
  switch (notification.method) {
22825
23204
  case "skills/changed":
22826
23205
  return { events: [{ kind: "skills.changed", ...base }] };
22827
23206
  case "thread/settings/updated": {
22828
- const settings = isRecord10(params) && isRecord10(params.threadSettings) ? params.threadSettings : undefined;
23207
+ const settings = isRecord11(params) && isRecord11(params.threadSettings) ? params.threadSettings : undefined;
22829
23208
  const model = settings ? str3(settings.model)?.trim() : undefined;
22830
23209
  if (!threadId || !model)
22831
23210
  return { events: [] };
@@ -22841,7 +23220,7 @@ function reduceNotification(notification, generation, handle) {
22841
23220
  };
22842
23221
  }
22843
23222
  case "model/rerouted": {
22844
- const model = isRecord10(params) ? str3(params.toModel)?.trim() : undefined;
23223
+ const model = isRecord11(params) ? str3(params.toModel)?.trim() : undefined;
22845
23224
  if (!threadId || !turnId || !model)
22846
23225
  return { events: [] };
22847
23226
  return {
@@ -22858,7 +23237,7 @@ function reduceNotification(notification, generation, handle) {
22858
23237
  }
22859
23238
  case "modelProvider/authRecoveryStarted":
22860
23239
  case "modelProvider/authRecoveryCompleted": {
22861
- if (!threadId || !isRecord10(params))
23240
+ if (!threadId || !isRecord11(params))
22862
23241
  return { events: [] };
22863
23242
  const message = str3(params.message)?.trim().slice(0, 300);
22864
23243
  const provider = str3(params.provider)?.trim().slice(0, 64);
@@ -22876,11 +23255,11 @@ function reduceNotification(notification, generation, handle) {
22876
23255
  };
22877
23256
  }
22878
23257
  case "thread/tokenUsage/updated": {
22879
- if (!isRecord10(params) || !threadId || !turnId || !isRecord10(params.tokenUsage)) {
23258
+ if (!isRecord11(params) || !threadId || !turnId || !isRecord11(params.tokenUsage)) {
22880
23259
  return { events: [] };
22881
23260
  }
22882
- const total = isRecord10(params.tokenUsage.total) ? params.tokenUsage.total : {};
22883
- const last = isRecord10(params.tokenUsage.last) ? params.tokenUsage.last : {};
23261
+ const total = isRecord11(params.tokenUsage.total) ? params.tokenUsage.total : {};
23262
+ const last = isRecord11(params.tokenUsage.last) ? params.tokenUsage.last : {};
22884
23263
  const contextWindow = num(params.tokenUsage.modelContextWindow) ?? 0;
22885
23264
  const usedTokens = num(last.totalTokens) ?? 0;
22886
23265
  return {
@@ -22923,7 +23302,7 @@ function reduceNotification(notification, generation, handle) {
22923
23302
  };
22924
23303
  }
22925
23304
  case "account/rateLimits/updated": {
22926
- if (!isRecord10(params) || !isRecord10(params.rateLimits))
23305
+ if (!isRecord11(params) || !isRecord11(params.rateLimits))
22927
23306
  return { events: [] };
22928
23307
  const snapshot = params.rateLimits;
22929
23308
  const limitId = str3(snapshot.limitId);
@@ -22931,14 +23310,14 @@ function reduceNotification(notification, generation, handle) {
22931
23310
  return { events: [] };
22932
23311
  const windows = [];
22933
23312
  const limitName = typeof snapshot.limitName === "string" && snapshot.limitName.length > 0 ? snapshot.limitName : undefined;
22934
- if (!isRecord10(snapshot.primary) && limitName !== undefined) {
23313
+ if (!isRecord11(snapshot.primary) && limitName !== undefined) {
22935
23314
  windows.push({ slot: "primary", label: limitName });
22936
23315
  }
22937
23316
  for (const [key, label] of [
22938
23317
  ["primary", "Primary"],
22939
23318
  ["secondary", "Secondary"]
22940
23319
  ]) {
22941
- const window = isRecord10(snapshot[key]) ? snapshot[key] : undefined;
23320
+ const window = isRecord11(snapshot[key]) ? snapshot[key] : undefined;
22942
23321
  if (!window)
22943
23322
  continue;
22944
23323
  const resetsAt = epochSecondsToIso(window.resetsAt);
@@ -22963,8 +23342,8 @@ function reduceNotification(notification, generation, handle) {
22963
23342
  };
22964
23343
  }
22965
23344
  case "thread/started": {
22966
- const thread = isRecord10(params) ? params.thread : undefined;
22967
- const id = isRecord10(thread) ? str3(thread.id) : undefined;
23345
+ const thread = isRecord11(params) ? params.thread : undefined;
23346
+ const id = isRecord11(thread) ? str3(thread.id) : undefined;
22968
23347
  if (!id)
22969
23348
  return { events: [] };
22970
23349
  return { events: [{ kind: "thread.started", threadId: id, ...base }] };
@@ -22982,19 +23361,19 @@ function reduceNotification(notification, generation, handle) {
22982
23361
  case "thread/name/updated": {
22983
23362
  if (!threadId)
22984
23363
  return { events: [] };
22985
- const name = isRecord10(params) ? str3(params.threadName) : undefined;
23364
+ const name = isRecord11(params) ? str3(params.threadName) : undefined;
22986
23365
  return { events: [{ kind: "thread.name.updated", threadId, name, ...base }] };
22987
23366
  }
22988
23367
  case "turn/started": {
22989
- const turn = isRecord10(params) ? params.turn : undefined;
22990
- const id = isRecord10(turn) ? str3(turn.id) : undefined;
23368
+ const turn = isRecord11(params) ? params.turn : undefined;
23369
+ const id = isRecord11(turn) ? str3(turn.id) : undefined;
22991
23370
  if (!id)
22992
23371
  return { events: [] };
22993
23372
  return { events: [{ kind: "turn.started", threadId, turnId: id, ...base }] };
22994
23373
  }
22995
23374
  case "turn/completed": {
22996
- const turn = isRecord10(params) ? params.turn : undefined;
22997
- if (!isRecord10(turn))
23375
+ const turn = isRecord11(params) ? params.turn : undefined;
23376
+ if (!isRecord11(turn))
22998
23377
  return { events: [] };
22999
23378
  const id = str3(turn.id);
23000
23379
  if (!id)
@@ -23014,7 +23393,7 @@ function reduceNotification(notification, generation, handle) {
23014
23393
  };
23015
23394
  }
23016
23395
  case "error": {
23017
- if (!isRecord10(params))
23396
+ if (!isRecord11(params))
23018
23397
  return { events: [] };
23019
23398
  return {
23020
23399
  events: [
@@ -23031,7 +23410,7 @@ function reduceNotification(notification, generation, handle) {
23031
23410
  }
23032
23411
  case "item/started":
23033
23412
  case "item/completed": {
23034
- if (!isRecord10(params) || !turnId)
23413
+ if (!isRecord11(params) || !turnId)
23035
23414
  return { events: [] };
23036
23415
  const { item, unsupportedType } = adaptAppServerItem(params.item);
23037
23416
  if (!item)
@@ -23054,7 +23433,7 @@ function reduceNotification(notification, generation, handle) {
23054
23433
  };
23055
23434
  }
23056
23435
  case "item/agentMessage/delta": {
23057
- if (!isRecord10(params) || !turnId)
23436
+ if (!isRecord11(params) || !turnId)
23058
23437
  return { events: [] };
23059
23438
  const itemId = str3(params.itemId);
23060
23439
  const delta = typeof params.delta === "string" ? params.delta : undefined;
@@ -23066,7 +23445,7 @@ function reduceNotification(notification, generation, handle) {
23066
23445
  }
23067
23446
  case "item/reasoning/summaryTextDelta":
23068
23447
  case "item/reasoning/textDelta": {
23069
- if (!isRecord10(params) || !turnId)
23448
+ if (!isRecord11(params) || !turnId)
23070
23449
  return { events: [] };
23071
23450
  const itemId = str3(params.itemId);
23072
23451
  const delta = typeof params.delta === "string" ? params.delta : undefined;
@@ -23091,7 +23470,7 @@ function reduceNotification(notification, generation, handle) {
23091
23470
  case "item/reasoning/summaryPartAdded":
23092
23471
  return { events: [] };
23093
23472
  case "serverRequest/resolved": {
23094
- if (!isRecord10(params))
23473
+ if (!isRecord11(params))
23095
23474
  return { events: [] };
23096
23475
  const requestId = params.requestId;
23097
23476
  if (typeof requestId !== "string" && typeof requestId !== "number")
@@ -23103,7 +23482,7 @@ function reduceNotification(notification, generation, handle) {
23103
23482
  case "item/mcpToolCall/progress":
23104
23483
  case "item/fileChange/outputDelta":
23105
23484
  case "item/plan/delta": {
23106
- if (!isRecord10(params) || !turnId)
23485
+ if (!isRecord11(params) || !turnId)
23107
23486
  return { events: [] };
23108
23487
  const itemId = str3(params.itemId);
23109
23488
  const message = str3(params.message) ?? str3(params.delta);
@@ -23114,7 +23493,7 @@ function reduceNotification(notification, generation, handle) {
23114
23493
  };
23115
23494
  }
23116
23495
  case "item/commandExecution/outputDelta": {
23117
- if (!isRecord10(params) || !turnId)
23496
+ if (!isRecord11(params) || !turnId)
23118
23497
  return { events: [] };
23119
23498
  const itemId = str3(params.itemId);
23120
23499
  const delta = typeof params.delta === "string" ? params.delta : undefined;
@@ -23130,13 +23509,13 @@ function reduceNotification(notification, generation, handle) {
23130
23509
  return { events: [{ kind: "model.tool.called", threadId, turnId, ...base }] };
23131
23510
  }
23132
23511
  case "rawResponseItem/completed": {
23133
- if (!isRecord10(params) || !threadId || !turnId || !isRecord10(params.item)) {
23512
+ if (!isRecord11(params) || !threadId || !turnId || !isRecord11(params.item)) {
23134
23513
  return { events: [] };
23135
23514
  }
23136
23515
  const rawItem = params.item;
23137
23516
  const payloadType = str3(rawItem.type);
23138
23517
  if (payloadType === "configuration_update") {
23139
- const reasoning = isRecord10(rawItem.reasoning) ? rawItem.reasoning : undefined;
23518
+ const reasoning = isRecord11(rawItem.reasoning) ? rawItem.reasoning : undefined;
23140
23519
  const reasoningEffort = reasoning ? str3(reasoning.effort)?.trim() : undefined;
23141
23520
  if (!reasoningEffort)
23142
23521
  return { events: [] };
@@ -23195,7 +23574,7 @@ function reduceNotification(notification, generation, handle) {
23195
23574
  return { events: boundary };
23196
23575
  }
23197
23576
  case "item/fileChange/patchUpdated": {
23198
- if (!isRecord10(params) || !turnId)
23577
+ if (!isRecord11(params) || !turnId)
23199
23578
  return { events: [] };
23200
23579
  const itemId = str3(params.itemId);
23201
23580
  if (!itemId)
@@ -23211,7 +23590,7 @@ function reduceNotification(notification, generation, handle) {
23211
23590
  return { events: [{ kind: "item.updated", threadId, turnId, item, ...base }] };
23212
23591
  }
23213
23592
  case "turn/plan/updated": {
23214
- if (!isRecord10(params) || !turnId)
23593
+ if (!isRecord11(params) || !turnId)
23215
23594
  return { events: [] };
23216
23595
  const item = planUpdateToTodoList(turnId, params.plan);
23217
23596
  if (!item)
@@ -23219,7 +23598,7 @@ function reduceNotification(notification, generation, handle) {
23219
23598
  return { events: [{ kind: "item.updated", threadId, turnId, item, ...base }] };
23220
23599
  }
23221
23600
  case "turn/diff/updated": {
23222
- if (!isRecord10(params) || !turnId)
23601
+ if (!isRecord11(params) || !turnId)
23223
23602
  return { events: [] };
23224
23603
  const diff = typeof params.diff === "string" ? params.diff : undefined;
23225
23604
  if (diff === undefined)
@@ -23243,7 +23622,7 @@ function reduceHistoricalTurns(turns, generation, threadId, handle) {
23243
23622
  return { events, unsupportedItemTypes };
23244
23623
  const base = { engineGeneration: generation, ...handle ? { handle } : {} };
23245
23624
  for (const turn of turns) {
23246
- if (!isRecord10(turn))
23625
+ if (!isRecord11(turn))
23247
23626
  continue;
23248
23627
  const turnId = str3(turn.id);
23249
23628
  if (!turnId)
@@ -23274,12 +23653,12 @@ function reduceHistoricalTurns(turns, generation, threadId, handle) {
23274
23653
  }
23275
23654
 
23276
23655
  // ../../bridges/codex-bridge/src/sessions/dispatch-journal.ts
23277
- import { createHash as createHash11 } from "node:crypto";
23656
+ import { createHash as createHash12 } from "node:crypto";
23278
23657
  import { mkdir as mkdir8, open as open7, rename as rename6, rm as rm7, writeFile as writeFile5 } from "node:fs/promises";
23279
23658
  import { join as join16 } from "node:path";
23280
23659
 
23281
23660
  // ../../bridges/codex-bridge/src/sessions/persistence.ts
23282
- import { createHash as createHash10, randomUUID as randomUUID8 } from "node:crypto";
23661
+ import { createHash as createHash11, randomUUID as randomUUID8 } from "node:crypto";
23283
23662
  import {
23284
23663
  chmod,
23285
23664
  link as link2,
@@ -23374,7 +23753,7 @@ function isPersistedSessionTombstone(value) {
23374
23753
  return tombstone.deleted === true && typeof tombstone.bridgeSessionId === "string" && tombstone.bridgeSessionId.length > 0 && typeof tombstone.deletedAt === "string" && Number.isFinite(Date.parse(tombstone.deletedAt));
23375
23754
  }
23376
23755
  function hashCwd(cwd) {
23377
- return createHash10("sha256").update(cwd).digest("hex").slice(0, 16);
23756
+ return createHash11("sha256").update(cwd).digest("hex").slice(0, 16);
23378
23757
  }
23379
23758
  var DEFAULT_RETENTION_MS = 7 * 24 * 60 * 60 * 1000;
23380
23759
  var RECORD_FILE_MISSING = Symbol("record-file-missing");
@@ -23408,7 +23787,7 @@ class BridgeSessionStore {
23408
23787
  return directory === this.recordsDir() ? undefined : directory;
23409
23788
  }
23410
23789
  recordKey(bridgeSessionId) {
23411
- return createHash10("sha256").update(bridgeSessionId).digest("hex");
23790
+ return createHash11("sha256").update(bridgeSessionId).digest("hex");
23412
23791
  }
23413
23792
  recordPath(bridgeSessionId) {
23414
23793
  return join15(this.recordsDir(), `${this.recordKey(bridgeSessionId)}.json`);
@@ -24071,7 +24450,7 @@ class DispatchJournal {
24071
24450
  this.filterAdd(requestId);
24072
24451
  }
24073
24452
  filterPositions(requestId) {
24074
- const digest = createHash11("sha256").update(requestId, "utf8").digest();
24453
+ const digest = createHash12("sha256").update(requestId, "utf8").digest();
24075
24454
  const positions = [];
24076
24455
  for (let index = 0;index < UNTRACKED_FILTER_HASHES; index += 1) {
24077
24456
  positions.push(digest.readUInt32BE(index * 4) % UNTRACKED_FILTER_BITS);
@@ -24315,7 +24694,7 @@ import { homedir as homedir3 } from "node:os";
24315
24694
  import { isAbsolute as isAbsolute8, join as join18, relative as relative3, sep } from "node:path";
24316
24695
 
24317
24696
  // ../../bridges/codex-bridge/src/shell-exclusions.ts
24318
- import { closeSync as closeSync2, openSync as openSync2, readSync as readSync2, fstatSync as fstatSync2 } from "node:fs";
24697
+ import { closeSync as closeSync3, openSync as openSync3, readSync as readSync3, fstatSync as fstatSync3 } from "node:fs";
24319
24698
  import { homedir as homedir2 } from "node:os";
24320
24699
  import { dirname as dirname3, join as join17, resolve as resolve3 } from "node:path";
24321
24700
  function configuredShellExclusions(env) {
@@ -24337,21 +24716,21 @@ function configuredShellExclusions(env) {
24337
24716
  for (const path of paths) {
24338
24717
  let fd;
24339
24718
  try {
24340
- fd = openSync2(path, "r");
24719
+ fd = openSync3(path, "r");
24341
24720
  } catch (error) {
24342
24721
  if (error.code === "ENOENT")
24343
24722
  continue;
24344
24723
  throw new Error("Cannot read Codex shell exclusions");
24345
24724
  }
24346
24725
  try {
24347
- const stat = fstatSync2(fd);
24726
+ const stat = fstatSync3(fd);
24348
24727
  if (!stat.isFile() || stat.size > 1024 * 1024) {
24349
24728
  throw new Error("Invalid Codex configuration file");
24350
24729
  }
24351
24730
  const buffer = Buffer.alloc(1024 * 1024 + 1);
24352
24731
  let length = 0;
24353
24732
  while (length < buffer.length) {
24354
- const count = readSync2(fd, buffer, length, buffer.length - length, null);
24733
+ const count = readSync3(fd, buffer, length, buffer.length - length, null);
24355
24734
  if (count === 0)
24356
24735
  break;
24357
24736
  length += count;
@@ -24363,7 +24742,7 @@ function configuredShellExclusions(env) {
24363
24742
  } catch {
24364
24743
  throw new Error("Cannot load Codex shell exclusions");
24365
24744
  } finally {
24366
- closeSync2(fd);
24745
+ closeSync3(fd);
24367
24746
  }
24368
24747
  }
24369
24748
  return [...exclusions];
@@ -25321,7 +25700,7 @@ async function readStoredLoginFingerprint(codexHome) {
25321
25700
  const apiKey = typeof root.OPENAI_API_KEY === "string" ? root.OPENAI_API_KEY : "";
25322
25701
  if (!refreshToken && !apiKey)
25323
25702
  return;
25324
- return createHash12("sha256").update(JSON.stringify([refreshToken, apiKey])).digest("hex");
25703
+ return createHash13("sha256").update(JSON.stringify([refreshToken, apiKey])).digest("hex");
25325
25704
  } catch {
25326
25705
  return;
25327
25706
  }
@@ -25450,6 +25829,7 @@ class AppServerEngine {
25450
25829
  onInvariantViolation: () => this.supervisor.recordUnknownServerRequest(),
25451
25830
  onUnknownRequest: () => this.supervisor.recordUnknownServerRequest(),
25452
25831
  ...options.approvalTimeoutMs === undefined ? {} : { approvalTimeoutMs: options.approvalTimeoutMs },
25832
+ ...options.interactionClock === undefined ? {} : { clock: options.interactionClock },
25453
25833
  presentApproval: (request) => this.approvalHandler?.(request) === true,
25454
25834
  onApprovalResolved: (request, decision, resolution) => this.approvalResolvedHandler?.(request, decision, resolution),
25455
25835
  presentInteraction: (request) => this.interactionHandler?.(request) === true,
@@ -27039,7 +27419,7 @@ class CodexRuntimeSessions {
27039
27419
  }
27040
27420
  createSession(body) {
27041
27421
  const clientSessionKey = typeof body.clientSessionKey === "string" && body.clientSessionKey.trim().length > 0 && body.clientSessionKey.length <= 512 ? body.clientSessionKey : undefined;
27042
- const sessionId = clientSessionKey ? `session-client-${createHash13("sha256").update(this.ctx.options.cwd).update("\x00").update(clientSessionKey).digest("hex").slice(0, 32)}` : createSessionId();
27422
+ const sessionId = clientSessionKey ? `session-client-${createHash14("sha256").update(this.ctx.options.cwd).update("\x00").update(clientSessionKey).digest("hex").slice(0, 32)}` : createSessionId();
27043
27423
  const existing = this.ctx.registry.getSession(sessionId);
27044
27424
  if (existing) {
27045
27425
  this.ctx.registry.touch(sessionId);
@@ -27361,7 +27741,7 @@ class CodexRuntimeSessions {
27361
27741
  return "not-found";
27362
27742
  if (this.sessionAdmissionClosed(session))
27363
27743
  return "closing";
27364
- const inputDigest = createHash13("sha256").update(input).digest("hex");
27744
+ const inputDigest = createHash14("sha256").update(input).digest("hex");
27365
27745
  const previous = this.ctx.steerRequests.get(requestId);
27366
27746
  if (previous) {
27367
27747
  if (previous.threadId !== session.threadId || previous.turnId !== expectedTurnId || previous.inputDigest !== inputDigest) {
@@ -28389,7 +28769,7 @@ function parseCommandToken(text, sigils = ["/"]) {
28389
28769
  }
28390
28770
 
28391
28771
  // ../../bridges/codex-bridge/src/prompts/template-discovery.ts
28392
- import { createHash as createHash14 } from "node:crypto";
28772
+ import { createHash as createHash15 } from "node:crypto";
28393
28773
  import { open as open10, readdir as readdir3, stat as stat8 } from "node:fs/promises";
28394
28774
  import { join as join21 } from "node:path";
28395
28775
  var TEMPLATE_LIMITS = Object.freeze({
@@ -28422,7 +28802,7 @@ function templateBindingRevision(origin, relativePath) {
28422
28802
  return commandBindingRevision(["template", origin, relativePath]);
28423
28803
  }
28424
28804
  function fingerprintOf(bytes) {
28425
- return createHash14("sha256").update(bytes).digest("hex").slice(0, 32);
28805
+ return createHash15("sha256").update(bytes).digest("hex").slice(0, 32);
28426
28806
  }
28427
28807
  function nameFromRelativePath(relativePath) {
28428
28808
  return `/${relativePath.replace(/\.md$/i, "")}`;
@@ -28436,7 +28816,7 @@ function isReservedName(name) {
28436
28816
  }
28437
28817
  var metadataCache = new Map;
28438
28818
  var METADATA_CACHE_MAX = 1024;
28439
- async function readBounded2(absolutePath, maxBytes) {
28819
+ async function readBounded3(absolutePath, maxBytes) {
28440
28820
  const handle = await open10(absolutePath, "r");
28441
28821
  try {
28442
28822
  const info = await handle.stat();
@@ -28579,7 +28959,7 @@ async function scanPromptTemplates(roots, limits = TEMPLATE_LIMITS) {
28579
28959
  if (candidate.size > limits.maxTemplateBytes)
28580
28960
  return null;
28581
28961
  try {
28582
- const { bytes, oversized } = await readBounded2(candidate.absolutePath, limits.maxTemplateBytes);
28962
+ const { bytes, oversized } = await readBounded3(candidate.absolutePath, limits.maxTemplateBytes);
28583
28963
  if (oversized)
28584
28964
  return null;
28585
28965
  if (bytes.length === 0)
@@ -28656,7 +29036,7 @@ async function loadTemplateBody(entry, limits = TEMPLATE_LIMITS) {
28656
29036
  }
28657
29037
  let loaded;
28658
29038
  try {
28659
- loaded = await readBounded2(entry.absolutePath, limits.maxTemplateBytes);
29039
+ loaded = await readBounded3(entry.absolutePath, limits.maxTemplateBytes);
28660
29040
  } catch {
28661
29041
  return {
28662
29042
  ok: false,
@@ -28701,7 +29081,7 @@ var SCOPE_ORIGINS = {
28701
29081
  system: "system",
28702
29082
  admin: "admin"
28703
29083
  };
28704
- function isRecord11(value) {
29084
+ function isRecord12(value) {
28705
29085
  return !!value && typeof value === "object" && !Array.isArray(value);
28706
29086
  }
28707
29087
  function nonEmpty(value) {
@@ -28717,12 +29097,12 @@ function usableSkillName(name) {
28717
29097
  return !/\s/.test(name) && utf8ByteLength(`${SKILL_ALIAS_PREFIX}${name}`) <= 255;
28718
29098
  }
28719
29099
  function normalizeSkillsList(raw, context) {
28720
- const data = isRecord11(raw) && Array.isArray(raw.data) ? raw.data : [];
29100
+ const data = isRecord12(raw) && Array.isArray(raw.data) ? raw.data : [];
28721
29101
  const byPath = new Map;
28722
- let partial = !isRecord11(raw) || !Array.isArray(raw.data);
29102
+ let partial = !isRecord12(raw) || !Array.isArray(raw.data);
28723
29103
  let truncated = false;
28724
29104
  for (const entry of data) {
28725
- if (!isRecord11(entry)) {
29105
+ if (!isRecord12(entry)) {
28726
29106
  partial = true;
28727
29107
  continue;
28728
29108
  }
@@ -28730,7 +29110,7 @@ function normalizeSkillsList(raw, context) {
28730
29110
  partial = true;
28731
29111
  const skills = Array.isArray(entry.skills) ? entry.skills : [];
28732
29112
  for (const candidate of skills) {
28733
- if (!isRecord11(candidate)) {
29113
+ if (!isRecord12(candidate)) {
28734
29114
  truncated = true;
28735
29115
  continue;
28736
29116
  }
@@ -28748,7 +29128,7 @@ function normalizeSkillsList(raw, context) {
28748
29128
  }
28749
29129
  const scope = typeof candidate.scope === "string" && candidate.scope in SCOPE_ORIGINS ? candidate.scope : "unknown";
28750
29130
  const pluginId = nonEmpty(candidate.pluginId) ?? null;
28751
- const skillInterface = isRecord11(candidate.interface) ? candidate.interface : {};
29131
+ const skillInterface = isRecord12(candidate.interface) ? candidate.interface : {};
28752
29132
  const description = nonEmpty(skillInterface.shortDescription) ?? nonEmpty(candidate.shortDescription) ?? nonEmpty(candidate.description);
28753
29133
  byPath.set(path, {
28754
29134
  id: skillCommandId(path),
@@ -30217,6 +30597,7 @@ class CodexRuntimeLifecycle {
30217
30597
  if (!state)
30218
30598
  return;
30219
30599
  state.coalescer.stop();
30600
+ cancelSubagentProbe(state);
30220
30601
  state.orderedEvents.length = 0;
30221
30602
  state.orderedEventBytes = 0;
30222
30603
  state.orderedReconcilePending = false;
@@ -31443,8 +31824,10 @@ class CodexRuntimeLifecycle {
31443
31824
  const turn = context.activeTurn;
31444
31825
  if (!turn)
31445
31826
  return;
31827
+ const probeIntervalMs = this.ctx.options.subagentProbeIntervalMs ?? SUBAGENT_TRANSCRIPT_PROBE_INTERVAL_MS;
31446
31828
  await publishAssistantRows(context, state, turn, {
31447
31829
  cwd: context.cwd ?? this.ctx.options.cwd,
31830
+ subagentProbeIntervalMs: probeIntervalMs,
31448
31831
  emit: (event) => this.ctx.options.emit(event),
31449
31832
  bumpMessageRevision: (target, revised) => this.ctx.callbacks.bumpMessageRevision(target, revised),
31450
31833
  onRendered: (message) => {
@@ -31457,6 +31840,10 @@ class CodexRuntimeLifecycle {
31457
31840
  }
31458
31841
  }
31459
31842
  });
31843
+ scheduleSubagentProbe(state, turn, probeIntervalMs, () => {
31844
+ if (this.ctx.threadState.get(threadId) === state)
31845
+ state.coalescer.schedule(this.ctx.now());
31846
+ });
31460
31847
  }
31461
31848
  emitStatus(context) {
31462
31849
  this.ctx.callbacks.notifyThreadActivity();
@@ -34177,6 +34564,12 @@ app.use("*", async (c, next) => {
34177
34564
  if (!tokenMatches(dedicatedHeaderToken) && !tokenMatches(headerToken) && !tokenMatches(eventToken)) {
34178
34565
  return c.json({ error: "Unauthorized" }, 401);
34179
34566
  }
34567
+ const admission = await admitFetchBridgeRequest(bridgeCredential.authority, c.req.raw);
34568
+ if ("refusal" in admission) {
34569
+ return c.json(admission.refusal.body, admission.refusal.status);
34570
+ }
34571
+ if (admission.request)
34572
+ c.req.raw = admission.request;
34180
34573
  }
34181
34574
  await next();
34182
34575
  });