orkestrator 2.36.3-beta → 2.36.5-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.
- package/README.md +18 -0
- package/dist/client.js +12281 -10234
- package/dist/main.js +214701 -204516
- package/package.json +3 -3
- package/resources/acp-bridge/dist/index.js +1244 -206
- package/resources/claude-bridge/dist/index.js +1699 -247
- package/resources/codex-bridge/dist/index.js +1364 -259
- package/resources/cursor-bridge/dist/index.js +30616 -29465
- package/resources/cursor-bridge/runtime/install.json +1 -1
- package/resources/pi-bridge/dist/index.js +30502 -29337
- package/resources/pi-bridge/runtime/install.json +1 -1
- package/resources/release-runtime/bun.lock +305 -0
- package/resources/release-runtime/package.json +9 -0
|
@@ -1054,6 +1054,12 @@ var BACKEND_LOG_AREAS = defineLogAreas({
|
|
|
1054
1054
|
"startup.looped-review-pending": "Cleanup of the retired Looped Review stays pending.",
|
|
1055
1055
|
"notice.failed": "A background notice after a turn or prompt failed; `step` says which.",
|
|
1056
1056
|
"artifacts.live-unavailable": "Live interactive artifacts are unavailable.",
|
|
1057
|
+
"previous-run": {
|
|
1058
|
+
description: "This start read how the previous run ended: `outcome` is `clean` when it reached the end of shutdown and `crashed` when it did not, `ranForMs` its length and `lastSeenAgoMs` the time since its last health row.",
|
|
1059
|
+
essential: true,
|
|
1060
|
+
fields: { outcome: "label", ranForMs: "number", lastSeenAgoMs: "number" }
|
|
1061
|
+
},
|
|
1062
|
+
"health.write-failed": "A health summary row could not be written or read; the next sample retries.",
|
|
1057
1063
|
"shutdown.step-failed": "One part of shutdown failed and the rest went on; `step` says which.",
|
|
1058
1064
|
"shutdown.signal-received": {
|
|
1059
1065
|
description: "A signal started shutdown, which tells a clean quit from the backend being killed.",
|
|
@@ -1097,7 +1103,8 @@ var BRIDGE_LOG_AREAS = defineLogAreas({
|
|
|
1097
1103
|
description: "What every long-lived bridge does the same way: its sweep and its shutdown.",
|
|
1098
1104
|
events: {
|
|
1099
1105
|
"idle-sweep.failed": "An idle sweep threw; the next tick retries.",
|
|
1100
|
-
"shutdown.failed": "Releasing the bridge failed during shutdown; it still exits."
|
|
1106
|
+
"shutdown.failed": "Releasing the bridge failed during shutdown; it still exits.",
|
|
1107
|
+
"credential.not-hardened": "The bridge could not mark itself non-dumpable, so a same-uid process can read its memory; `reason` says why."
|
|
1101
1108
|
}
|
|
1102
1109
|
},
|
|
1103
1110
|
"bridge.acp": {
|
|
@@ -1231,7 +1238,6 @@ var BRIDGE_LOG_AREAS = defineLogAreas({
|
|
|
1231
1238
|
"parent.gone": "The backend that launched this bridge has gone; stopping turns and shutting down.",
|
|
1232
1239
|
"queue.overflow": "The notification queue passed a bound and dropped its backlog.",
|
|
1233
1240
|
"queue.task-failed": "A task on a per-thread queue failed.",
|
|
1234
|
-
"raw-log.write-failed": "Appending to the raw Codex log failed.",
|
|
1235
1241
|
"recorder.notice": "The notification recorder needs attention: it is on, or was asked for without its confirmation.",
|
|
1236
1242
|
"recorder.threw": "The notification recorder threw.",
|
|
1237
1243
|
"recorder.write-failed": "Writing a notification recording failed; its lines were dropped.",
|
|
@@ -1437,6 +1443,7 @@ var ENVIRONMENT_LOG_AREAS = defineLogAreas({
|
|
|
1437
1443
|
environment: {
|
|
1438
1444
|
description: "Environment naming, setup, status, moves, deletion and cleanup afterwards.",
|
|
1439
1445
|
events: {
|
|
1446
|
+
"cleanup.sessions-failed": "Session metadata cleanup failed during environment deletion; deletion continues.",
|
|
1440
1447
|
"cleanup.branch-kept": "A deleted environment's local branch was kept, as it may hold unmerged work.",
|
|
1441
1448
|
"rename.failed": "Naming an environment from its pending prompt failed for the first time.",
|
|
1442
1449
|
"rename.still-failing": "That rename is still failing; written at the 2nd, 4th, 8th... failure.",
|
|
@@ -1510,6 +1517,7 @@ var GATEWAY_LOG_AREAS = defineLogAreas({
|
|
|
1510
1517
|
"websocket.upgrade-failed": "A WebSocket upgrade failed.",
|
|
1511
1518
|
"events.client-dropped": "An event-stream client buffered too much and was dropped; it reconnects and refetches.",
|
|
1512
1519
|
"proxy.client-disconnected": "A proxy client went away, so its upstream request was aborted.",
|
|
1520
|
+
"traffic.burst": "Connections or requests spiked. Counts by source address, route class, client family, listener and registered invoke command; never request content.",
|
|
1513
1521
|
"throttle.suppressed": "Repeats of the throttled `site` were counted over a window, not written.",
|
|
1514
1522
|
"throttle.recovered": "The throttled `site` succeeded again, so its fault has cleared.",
|
|
1515
1523
|
"throttle.evicted": "The tracked-key limit dropped the `site`, so no recovered line follows unless it fails again."
|
|
@@ -1613,6 +1621,8 @@ var LOGGING_LOG_AREAS = defineLogAreas({
|
|
|
1613
1621
|
},
|
|
1614
1622
|
"essential.write-failed": "Writing the essential log failed. Its entries are counted, and a marker reports them at the next write that works.",
|
|
1615
1623
|
"policy.changed": "The logging settings changed: saving, retention and levels, with no content.",
|
|
1624
|
+
"policy.detail-expired": "Raised log detail reached its expiry, so the backend set its raised levels back to info. Saving is unchanged.",
|
|
1625
|
+
"policy.expiry-failed": "Checking or applying the log detail expiry failed; the next check, a minute later, tries again.",
|
|
1616
1626
|
"policy.bridge-predates-route": "A running bridge has no logging settings route; it applies them at its next start.",
|
|
1617
1627
|
"policy.push-failed": "A running bridge did not take the logging settings after retries; its next start resends them.",
|
|
1618
1628
|
"prune.failed": "Removing expired log files failed; the next sweep retries.",
|
|
@@ -1620,6 +1630,23 @@ var LOGGING_LOG_AREAS = defineLogAreas({
|
|
|
1620
1630
|
"unknown-area": "Code outside the type checker asked for an area that is not listed.",
|
|
1621
1631
|
...THROTTLE_LOG_EVENTS
|
|
1622
1632
|
}
|
|
1633
|
+
},
|
|
1634
|
+
"renderer-errors": {
|
|
1635
|
+
description: "Renderer failures a desktop window reported from its error ring: class, boundary, surface, count and fingerprint, never a message or stack.",
|
|
1636
|
+
events: {
|
|
1637
|
+
"error.recorded": {
|
|
1638
|
+
description: "A renderer reported `count` new occurrences of one failure since its last report.",
|
|
1639
|
+
essential: true,
|
|
1640
|
+
fields: {
|
|
1641
|
+
errorClass: "label",
|
|
1642
|
+
boundary: "label",
|
|
1643
|
+
route: "label",
|
|
1644
|
+
fingerprint: "label",
|
|
1645
|
+
count: "number"
|
|
1646
|
+
}
|
|
1647
|
+
},
|
|
1648
|
+
"report.rate-limited": "Renderer error entries arrived faster than the backend records them, so `dropped` were counted and not written."
|
|
1649
|
+
}
|
|
1623
1650
|
}
|
|
1624
1651
|
});
|
|
1625
1652
|
|
|
@@ -1643,6 +1670,7 @@ var NATIVE_AGENT_LOG_AREAS = defineLogAreas({
|
|
|
1643
1670
|
"native-agent": {
|
|
1644
1671
|
description: "Native agent sessions and what the backend reads from their bridges.",
|
|
1645
1672
|
events: {
|
|
1673
|
+
"session.bridge-replaced-for-policy": "An idle bridge was stopped so a resume could apply the user's wider execution policy.",
|
|
1646
1674
|
"catalogue.outdated-bridge": "A bridge predates the command catalogue, so its commands stay unavailable.",
|
|
1647
1675
|
"compact.instructions-ignored": "A bridge compacted without confirming the instructions sent with /compact: it predates them.",
|
|
1648
1676
|
"handoff.summary-read-failed": "Change summaries could not be read for a handoff, so the carrier says they are unmeasured.",
|
|
@@ -1676,6 +1704,8 @@ var NATIVE_AGENT_LOG_AREAS = defineLogAreas({
|
|
|
1676
1704
|
"usage-limit.notice-failed": "A usage-limit stop's outcome could not be read for its notice.",
|
|
1677
1705
|
"usage-limit.resend-failed": "Resending after a usage limit failed. An unknown send stays in the journal.",
|
|
1678
1706
|
"title.strategy-failed": "A session title strategy failed, so the next is tried. Content-free: the error can quote the prompt.",
|
|
1707
|
+
"steer.qualification-failed": "A bridge's steer qualification failed or answered non-OK, so steering is not offered. Agent and status code or error class only.",
|
|
1708
|
+
"steer.capability-cleared": "A projection cleared `actions.steer` because its bridge did not qualify. Identifiers and turn status only.",
|
|
1679
1709
|
...THROTTLE_LOG_EVENTS
|
|
1680
1710
|
}
|
|
1681
1711
|
},
|
|
@@ -1708,7 +1738,8 @@ var NATIVE_AGENT_LOG_AREAS = defineLogAreas({
|
|
|
1708
1738
|
"coordinator-servers.unavailable": "OpenCode coordinator research servers are unavailable.",
|
|
1709
1739
|
"monitor.reconnecting": "The request monitor lost its stream and is reconnecting. Error class only.",
|
|
1710
1740
|
"worker-limit.reached": "The bounded request workers are full, so the stream restarts and a snapshot reconciles.",
|
|
1711
|
-
"request.failed": "Handling a request event failed, so the stream restarts. Error class only."
|
|
1741
|
+
"request.failed": "Handling a request event failed, so the stream restarts. Error class only.",
|
|
1742
|
+
"credential-plugin.skipped": "A host OpenCode server started without the credential plugin, so its tools inherit its password; `reason` says why."
|
|
1712
1743
|
}
|
|
1713
1744
|
}
|
|
1714
1745
|
});
|
|
@@ -1736,6 +1767,7 @@ var PREVIEW_LOG_AREAS = defineLogAreas({
|
|
|
1736
1767
|
"publication.start-failed": "Private preview publication did not start.",
|
|
1737
1768
|
"publication.reconfigure-failed": "Preview publication could not be reconfigured.",
|
|
1738
1769
|
"publication.listening": "Private preview origins are listening.",
|
|
1770
|
+
"publication.same-site": "The preview domain is the same site as the application; publication runs with a warning.",
|
|
1739
1771
|
"certificate.reloaded": "The preview certificate was reloaded.",
|
|
1740
1772
|
"access.revoked-close-failed": "A revoked preview resource could not be closed. Error class only.",
|
|
1741
1773
|
"registry.invalid-definition": "An invalid stored preview service definition was ignored.",
|
|
@@ -1774,6 +1806,9 @@ var RUNTIME_LOG_AREAS = defineLogAreas({
|
|
|
1774
1806
|
essential: true,
|
|
1775
1807
|
fields: { origin: "label", ...ESSENTIAL_ERROR_FIELDS }
|
|
1776
1808
|
},
|
|
1809
|
+
"child.reaped": "A macOS child whose exit Bun lost was reaped after its command settled, so it no longer waits as a zombie.",
|
|
1810
|
+
"child.reap-abandoned": "A child whose exit Bun lost was left unreaped: `reason` says whether it was never seen as a zombie (`not-a-zombie`), too many were pending (`capacity`), or `waitpid` failed.",
|
|
1811
|
+
"child.reap-unavailable": "waitpid could not be loaded, so children whose exit Bun lost stay zombies until this process exits.",
|
|
1777
1812
|
...THROTTLE_LOG_EVENTS
|
|
1778
1813
|
}
|
|
1779
1814
|
}
|
|
@@ -2044,10 +2079,19 @@ var STORAGE_LOG_AREAS = defineLogAreas({
|
|
|
2044
2079
|
"retired.turn-cleanup-pending": "Cleanup of a retired Looped Review turn did not finish and stays pending.",
|
|
2045
2080
|
"handoffs.prune-failed": "Pruning agent handoffs that nothing references failed; a later prune retries.",
|
|
2046
2081
|
"desktop-connections.malformed": "Stored desktop connection settings were malformed, so the local connection is used.",
|
|
2082
|
+
"config.restrict-mode-failed": "A config file holding provider secrets could not be set to owner-only; the backend carries on.",
|
|
2047
2083
|
"legacy-json.moved": "JSON store files written after the SQLite migration were archived, not imported.",
|
|
2048
2084
|
"legacy-json.archive-failed": "Imported JSON store files could not be archived.",
|
|
2085
|
+
"lease.timed-out": "A waiter gave up on a lease; `lease` and `family` name it, `holderAgeMs` is the time since its holder's last heartbeat (null when the holder had just gone), `waitedMs` how long the waiter waited.",
|
|
2049
2086
|
"lease.heartbeat-failed": "A held lease's heartbeat failed, which shortens the lease; the next one retries.",
|
|
2050
|
-
"scrub.
|
|
2087
|
+
"scrub.vacuum-failed": "Deleted-content page reclamation failed; the checkpoint is attempted independently.",
|
|
2088
|
+
"scrub.checkpoint-failed": "Deleted content could not be scrubbed from the WAL yet because the truncating checkpoint failed or a reader held an older snapshot; it is retried without waiting until it succeeds.",
|
|
2089
|
+
"upkeep.vacuum-failed": "Periodic page reclamation failed; the next upkeep pass retries.",
|
|
2090
|
+
"optimize.failed": "Refreshing the query planner's statistics failed; queries still run and the next check retries.",
|
|
2091
|
+
"ledger.moved": "The change-tracking ledger was moved out of the main database into its own file; `rows` and `durationMs` say how much and how long.",
|
|
2092
|
+
"snapshot.top-tables-failed": "The sampled table sizes from a finished snapshot could not be saved; the snapshot stands and the next one retries.",
|
|
2093
|
+
"snapshot.ledger-skipped": "The daily change-tracking ledger snapshot was skipped because the disk or the snapshot budget lacks room; `retryAt` says when it tries again.",
|
|
2094
|
+
"snapshot.ledger-failed": "The daily change-tracking ledger snapshot failed; `retryAt` says when it tries again, if known.",
|
|
2051
2095
|
...THROTTLE_LOG_EVENTS
|
|
2052
2096
|
}
|
|
2053
2097
|
}
|
|
@@ -2064,6 +2108,7 @@ var BUILD_PIPELINE_LOG_AREAS = defineLogAreas({
|
|
|
2064
2108
|
"consolidation.consume-deferred": "Consuming a review consolidation result failed; it stays pending and is retried.",
|
|
2065
2109
|
"dispatch.prepare-failed": "Attaching the agent before dispatch failed; the prompt request does the same work and answers authoritatively.",
|
|
2066
2110
|
"interaction.resolved": "A human interaction on a pipeline stage resolved. Metadata only.",
|
|
2111
|
+
"user-message.background-send-refused": "The bridge refused a queued user message during a background wait; it stays queued and is retried.",
|
|
2067
2112
|
"transcripts.migrated": "A transcript migration pass moved stage transcripts; counts only.",
|
|
2068
2113
|
"transcripts.maintenance-failed": "Migrating or sweeping stage transcripts failed; the next start retries.",
|
|
2069
2114
|
"restore.skipped": "A pipeline could not be restored at startup and was skipped.",
|
|
@@ -2101,6 +2146,8 @@ var CHANGE_TRACKING_LOG_AREAS = defineLogAreas({
|
|
|
2101
2146
|
description: "Change tracking: turn capture, evidence pulls and measurements.",
|
|
2102
2147
|
events: {
|
|
2103
2148
|
"journal-import.failed": "Importing surviving OpenCode command journals as legacy summaries failed.",
|
|
2149
|
+
"measurement-drain.failed": "Draining an owner's superseded measurements failed; the retention pass retries.",
|
|
2150
|
+
"retention.failed": "A retention pass failed partway; what it deleted stands and the next pass goes on.",
|
|
2104
2151
|
"projection.failed": "Projecting a change event onto its environment failed.",
|
|
2105
2152
|
"startup.reconcile-failed": "Reconciling change tracking at startup failed.",
|
|
2106
2153
|
"turn-start.capture-failed": "Capturing a turn's start failed, so the turn is untracked.",
|
|
@@ -2131,7 +2178,16 @@ var COORDINATOR_LOG_AREAS = defineLogAreas({
|
|
|
2131
2178
|
coordinator: {
|
|
2132
2179
|
description: "Coordinators: delegations, status wakes and their store.",
|
|
2133
2180
|
events: {
|
|
2181
|
+
...THROTTLE_LOG_EVENTS,
|
|
2134
2182
|
"delegation.open-failed": "A delegation could not be opened; `source` says for what.",
|
|
2183
|
+
"delegation.reconcile-failed": "One delegation could not be settled; the rest of the pass still ran and the next one retries.",
|
|
2184
|
+
"delegation.wake-failed": "One delegation's wake could not be delivered; the rest of the pass still ran and the next one retries.",
|
|
2185
|
+
"delegation.wake-held": "A wake is waiting on a state the user can change (messaging off, conversation limit), and is not counted as a failure.",
|
|
2186
|
+
"delegation.wake-pass-failed": "A delegation wake pass could not run; the next sweep retries.",
|
|
2187
|
+
"delegation.wake-retire-failed": "A wake that keeps failing could not be given up on; the next pass retries.",
|
|
2188
|
+
"delegation.wake-retire-notice-failed": "The one notice for a wake being retired could not be sent; the wake stays owed and the next pass retries.",
|
|
2189
|
+
"delegation.wake-retired": "A wake kept failing and was given up on; `kind` is the last failure.",
|
|
2190
|
+
"mail.reconcile-failed": "One coordinator's mail could not be reconciled; the sweep carried on with the others.",
|
|
2135
2191
|
"deliver-now.drain-failed": "The mail delivery pass after deliverNow failed; the next sweep delivers.",
|
|
2136
2192
|
"mail.move-failed": "Mail could not move to the new main coordinator.",
|
|
2137
2193
|
"work.move-failed": "Work could not move to the main coordinator.",
|
|
@@ -2159,6 +2215,13 @@ var COORDINATOR_LOG_AREAS = defineLogAreas({
|
|
|
2159
2215
|
"store.workflows-cleared": "The workflow store was full, so a batch of its oldest finished records was removed.",
|
|
2160
2216
|
"store.workflows-in-use": "The workflow store was full and every record was still in use, so new work was refused.",
|
|
2161
2217
|
"remote-worker.settle-failed": "A remote worker could not be settled.",
|
|
2218
|
+
"node-release.failed": "Work on a node that was forgotten or handed over could not be closed; the sweep's registry check retries.",
|
|
2219
|
+
"node-release.reconcile-failed": "The sweep could not check records against the node registry; the next sweep retries.",
|
|
2220
|
+
"node-release.unregistered": "Records named a node the registry no longer holds, so their work was closed here.",
|
|
2221
|
+
"node-release.notice-failed": "The notice for work closed on a released node could not be sent; it stays owed and the sweep retries.",
|
|
2222
|
+
"node-release.no-coordinator": "Work closed on a released node belonged to a coordinator that no longer exists, so nobody was told.",
|
|
2223
|
+
"node-offline.notice-failed": "The notice that a node has been unreachable for a day could not be sent; the next failed read retries.",
|
|
2224
|
+
"node-offline.check-failed": "Whether a long-unreachable node's coordinators were told could not be checked; the next read retries.",
|
|
2162
2225
|
"checkout.merge-followed": "After an environment's PR merged, the project checkout was fast-forwarded, or `outcome` says why not.",
|
|
2163
2226
|
"checkout.merge-follow-failed": "Fast-forwarding the project checkout failed, after an environment's PR merged or before mail woke the main coordinator.",
|
|
2164
2227
|
"checkout.mail-follow": "Before mail woke the main coordinator, the project checkout was fast-forwarded (`fast-forwarded-fetched` when the fetch was slow or failed and the upstream commit already fetched was merged), or `outcome` says why not (`timed-out`, `failed`).",
|
|
@@ -2255,7 +2318,10 @@ var DOCKER_LOG_AREAS = defineLogAreas({
|
|
|
2255
2318
|
events: {
|
|
2256
2319
|
"portable-inputs.relay-missing": "Docker is rootless and the image predates the staged-input relay, so the container cannot read them until rebuilt.",
|
|
2257
2320
|
"git-mirror.mount-unavailable": "A new container gets no project Git mirror, so its clone goes to the remote.",
|
|
2321
|
+
"git-mirror.mount-withheld": "A new restricted container gets no project Git mirror because its firewall would not let it reach the project's remote, so it cannot read what the remote serves through the mirror either.",
|
|
2258
2322
|
"git-mirror.refreshed": "A project's Git mirror was built or updated.",
|
|
2323
|
+
"git-mirror.seeded": "A project's Git mirror was built from its host checkout and only what the remote added to it.",
|
|
2324
|
+
"git-mirror.seed-skipped": "A project's host checkout could not seed its Git mirror, so the build downloads everything.",
|
|
2259
2325
|
"git-mirror.refresh-failed": "A project's Git mirror could not be updated. New clones still work, from the mirror as it was or from the remote.",
|
|
2260
2326
|
"git-mirror.low-disk": "A project's Git mirror was not updated: the disk is nearly full.",
|
|
2261
2327
|
"git-mirror.oversized": "A project's repository is too large for a Git mirror, so its environments keep the blobless clone.",
|
|
@@ -2267,6 +2333,7 @@ var DOCKER_LOG_AREAS = defineLogAreas({
|
|
|
2267
2333
|
"git-mirror.clone-fallback": "A new environment could not clone from its project's Git mirror and cloned from the remote.",
|
|
2268
2334
|
"project-seed.refused": "A project .env, .env.local or opencode.json was not copied into a new container: a link, not a regular file, outside the project, too large or unreadable.",
|
|
2269
2335
|
"opencode.warm-incomplete": "OpenCode did not finish loading /workspace in a container.",
|
|
2336
|
+
"log-driver.unbounded": "The Docker daemon offers neither the local nor the json-file log driver, so new containers keep its default driver, whose log may be uncapped. Written once per backend.",
|
|
2270
2337
|
"lifecycle-event.reconcile-failed": "Reconciling an environment after a container start or stop event failed; the next status read retries.",
|
|
2271
2338
|
"login-keeper.pass-failed": "A Claude login keeper pass failed; the next interval retries.",
|
|
2272
2339
|
"login-keeper.refresh-failed": "Refreshing the host Claude login failed. Fixed text: CLI output can hold credentials.",
|
|
@@ -2290,6 +2357,7 @@ var DOCKER_LOG_AREAS = defineLogAreas({
|
|
|
2290
2357
|
essential: true,
|
|
2291
2358
|
fields: { staleForMs: "number" }
|
|
2292
2359
|
},
|
|
2360
|
+
"writer-lease.listener-failed": "The callback told about a lost registry writer lease threw, so the schedules settings learn of the loss only at their next read.",
|
|
2293
2361
|
"writer-lease.not-acquired": {
|
|
2294
2362
|
description: "This backend started without the registry writer lease, for the fixed `reason` given. A second backend on one data directory is normal: it serves reads, runs no schedules and refuses container changes.",
|
|
2295
2363
|
essential: true,
|
|
@@ -2427,6 +2495,7 @@ var NODES_LOG_AREAS = defineLogAreas({
|
|
|
2427
2495
|
"verification.record-failed": "A node verification could not be recorded.",
|
|
2428
2496
|
"profile.record-failed": "A node profile could not be recorded.",
|
|
2429
2497
|
"detach.unconfirmed": "A forgotten node has not confirmed the detach yet.",
|
|
2498
|
+
"grant.revocation-listener-failed": "A connection could not be told its client grant was removed; the grant is still gone.",
|
|
2430
2499
|
"handover.recovery-pending": "Command handover recovery is still pending.",
|
|
2431
2500
|
"ticket-sync.work-record-failed": "A remote build started but its ticket work location could not be saved.",
|
|
2432
2501
|
"ticket-sync.failed": "A Kanban sync with a node failed; it is retried.",
|
|
@@ -2479,7 +2548,9 @@ var HOST_LOG_AREAS = defineLogAreas({
|
|
|
2479
2548
|
"tool.missing": "A host tool was not found.",
|
|
2480
2549
|
"maintenance.listener-failed": "A host maintenance listener threw; the others still run.",
|
|
2481
2550
|
"suspend.reconcile-failed": "Reconciling due work after a host suspension failed.",
|
|
2482
|
-
"load.sample-failed": "Sampling machine load failed; the next sample retries."
|
|
2551
|
+
"load.sample-failed": "Sampling machine load failed; the next sample retries.",
|
|
2552
|
+
"usage.source-stalled": "A usage source (scope: disk or gpu-sysfs) did not answer in time; its figure is missing from the sample until it does.",
|
|
2553
|
+
...THROTTLE_LOG_EVENTS
|
|
2483
2554
|
}
|
|
2484
2555
|
}
|
|
2485
2556
|
});
|
|
@@ -2944,6 +3015,7 @@ var WEB_SYNC_LOG_AREAS = defineLogAreas({
|
|
|
2944
3015
|
events: {
|
|
2945
3016
|
"events.disconnected": "The main event stream dropped; it reconnects and replays.",
|
|
2946
3017
|
"terminal-stream.disconnected": "A terminal event stream dropped; it reconnects.",
|
|
3018
|
+
"relayed-stream.disconnected": "The relayed node event stream dropped; it reconnects.",
|
|
2947
3019
|
"connection-listener.failed": "A main stream connection state listener threw.",
|
|
2948
3020
|
"event-listener.failed": "A listener for a gateway event threw.",
|
|
2949
3021
|
"stream-listener.failed": "A listener for the stream-connected notice threw."
|
|
@@ -3028,6 +3100,7 @@ var TEXT_RULES = [
|
|
|
3028
3100
|
pattern: /\beyJ[A-Za-z0-9_-]{6,}\.[A-Za-z0-9_-]{6,}\.[A-Za-z0-9_-]{6,}/g,
|
|
3029
3101
|
replacement: "[redacted]"
|
|
3030
3102
|
},
|
|
3103
|
+
{ pattern: /\bok[ab]_[A-Za-z0-9_-]{16,}/g, replacement: "[redacted]" },
|
|
3031
3104
|
{ pattern: /\bgh[pousr]_[A-Za-z0-9]{16,}/g, replacement: "[redacted]" },
|
|
3032
3105
|
{ pattern: /\bgithub_pat_[A-Za-z0-9_]{20,}/g, replacement: "[redacted]" },
|
|
3033
3106
|
{ pattern: /\b(?:sk|rk|pk)-[A-Za-z0-9_-]{12,}/g, replacement: "[redacted]" },
|
|
@@ -3800,6 +3873,7 @@ function effectiveLogLevel(detail, area) {
|
|
|
3800
3873
|
return detail.level;
|
|
3801
3874
|
}
|
|
3802
3875
|
}
|
|
3876
|
+
var LOG_DETAIL_EXPIRY_MS = 24 * 60 * 60 * 1000;
|
|
3803
3877
|
function logDetailEnablesBridgeDiagnostics(detail) {
|
|
3804
3878
|
return LEVEL_DETAIL[effectiveLogLevel(detail, BRIDGE_DIAGNOSTICS_LOG_AREA)] >= LEVEL_DETAIL.debug;
|
|
3805
3879
|
}
|
|
@@ -3812,6 +3886,73 @@ function parseBridgeLogPolicy(value) {
|
|
|
3812
3886
|
return Number.isSafeInteger(seq) && seq >= 0 ? { ...detail, seq } : null;
|
|
3813
3887
|
}
|
|
3814
3888
|
|
|
3889
|
+
// ../protocol/src/node/bridge-credential.ts
|
|
3890
|
+
import { createHash, randomBytes, timingSafeEqual } from "node:crypto";
|
|
3891
|
+
import { createRequire } from "node:module";
|
|
3892
|
+
var BRIDGE_TOKEN_PREFIX = "okb_";
|
|
3893
|
+
var PR_SET_DUMPABLE = 4;
|
|
3894
|
+
var VERIFIER_PATTERN = /^[0-9a-f]{64}$/;
|
|
3895
|
+
var log = createLogger("bridge.lifecycle");
|
|
3896
|
+
function mintBridgeToken() {
|
|
3897
|
+
return `${BRIDGE_TOKEN_PREFIX}${randomBytes(32).toString("base64url")}`;
|
|
3898
|
+
}
|
|
3899
|
+
function bridgeTokenVerifier(token) {
|
|
3900
|
+
return createHash("sha256").update(token).digest("hex");
|
|
3901
|
+
}
|
|
3902
|
+
function bridgeTokenVerifierEnv(tokenEnv) {
|
|
3903
|
+
return `${tokenEnv}_SHA256`;
|
|
3904
|
+
}
|
|
3905
|
+
function credentialFromVerifier(verifier, plainToken) {
|
|
3906
|
+
const expected = Buffer.from(verifier, "hex");
|
|
3907
|
+
return {
|
|
3908
|
+
plainToken,
|
|
3909
|
+
matches(candidate) {
|
|
3910
|
+
if (!candidate)
|
|
3911
|
+
return false;
|
|
3912
|
+
return timingSafeEqual(expected, createHash("sha256").update(candidate).digest());
|
|
3913
|
+
}
|
|
3914
|
+
};
|
|
3915
|
+
}
|
|
3916
|
+
function bridgeCredentialFromToken(token) {
|
|
3917
|
+
return credentialFromVerifier(bridgeTokenVerifier(token), token);
|
|
3918
|
+
}
|
|
3919
|
+
function markProcessNonDumpable(loadFfi = () => createRequire(import.meta.url)("bun:ffi")) {
|
|
3920
|
+
if (process.platform !== "linux" || !process.versions.bun)
|
|
3921
|
+
return false;
|
|
3922
|
+
try {
|
|
3923
|
+
const { dlopen, FFIType } = loadFfi();
|
|
3924
|
+
const libc = dlopen("libc.so.6", {
|
|
3925
|
+
prctl: {
|
|
3926
|
+
args: [FFIType.i32, FFIType.u64, FFIType.u64, FFIType.u64, FFIType.u64],
|
|
3927
|
+
returns: FFIType.i32
|
|
3928
|
+
}
|
|
3929
|
+
});
|
|
3930
|
+
try {
|
|
3931
|
+
if (libc.symbols.prctl(PR_SET_DUMPABLE, 0n, 0n, 0n, 0n) === 0)
|
|
3932
|
+
return true;
|
|
3933
|
+
} finally {
|
|
3934
|
+
libc.close();
|
|
3935
|
+
}
|
|
3936
|
+
log.warn("credential.not-hardened", { reason: "prctl-refused" });
|
|
3937
|
+
} catch {
|
|
3938
|
+
log.warn("credential.not-hardened", { reason: "ffi-unavailable" });
|
|
3939
|
+
}
|
|
3940
|
+
return false;
|
|
3941
|
+
}
|
|
3942
|
+
function loadBridgeCredential(tokenEnv, options = {}) {
|
|
3943
|
+
const env = options.env ?? process.env;
|
|
3944
|
+
const verifierEnv = bridgeTokenVerifierEnv(tokenEnv);
|
|
3945
|
+
const verifier = env[verifierEnv]?.trim();
|
|
3946
|
+
const token = env[tokenEnv]?.trim();
|
|
3947
|
+
delete env[verifierEnv];
|
|
3948
|
+
delete env[tokenEnv];
|
|
3949
|
+
if (verifier) {
|
|
3950
|
+
(options.harden ?? markProcessNonDumpable)();
|
|
3951
|
+
return VERIFIER_PATTERN.test(verifier) ? credentialFromVerifier(verifier, undefined) : bridgeCredentialFromToken(mintBridgeToken());
|
|
3952
|
+
}
|
|
3953
|
+
return bridgeCredentialFromToken(token || mintBridgeToken());
|
|
3954
|
+
}
|
|
3955
|
+
|
|
3815
3956
|
// ../protocol/src/node/logger-environment.ts
|
|
3816
3957
|
var LOG_LEVEL_ENV = "ORKESTRATOR_LOG_LEVEL";
|
|
3817
3958
|
var LOG_FORMAT_ENV = "ORKESTRATOR_LOG_FORMAT";
|
|
@@ -3888,14 +4029,14 @@ function applyLogDetail(detail, env = process.env) {
|
|
|
3888
4029
|
}
|
|
3889
4030
|
|
|
3890
4031
|
// ../protocol/src/node/bridge-diagnostics.ts
|
|
3891
|
-
import { createHash } from "node:crypto";
|
|
4032
|
+
import { createHash as createHash2 } from "node:crypto";
|
|
3892
4033
|
|
|
3893
4034
|
// ../protocol/src/event-loop-stall-monitor.ts
|
|
3894
|
-
var
|
|
4035
|
+
var log2 = createLogger("event-loop");
|
|
3895
4036
|
var EVENT_LOOP_STALL_ALWAYS_LOG_MS = 1e4;
|
|
3896
4037
|
|
|
3897
4038
|
// ../protocol/src/node/bridge-diagnostics.ts
|
|
3898
|
-
var
|
|
4039
|
+
var log3 = createLogger("bridge.diagnostics");
|
|
3899
4040
|
var BRIDGE_DIAGNOSTICS_INTERVAL_MS = 60000;
|
|
3900
4041
|
var INTERVAL_MS = BRIDGE_DIAGNOSTICS_INTERVAL_MS;
|
|
3901
4042
|
var STALL_NO_DELTA_MS = 2 * INTERVAL_MS;
|
|
@@ -3987,7 +4128,7 @@ function sameSet(a, b) {
|
|
|
3987
4128
|
function identity(value) {
|
|
3988
4129
|
if (typeof value !== "string" || !value || value.length > MAX_ID_LENGTH)
|
|
3989
4130
|
return;
|
|
3990
|
-
return
|
|
4131
|
+
return createHash2("sha256").update(value).digest("hex").slice(0, 16);
|
|
3991
4132
|
}
|
|
3992
4133
|
function readBridgeDebugFlag(value) {
|
|
3993
4134
|
return value?.trim() === "1";
|
|
@@ -4060,16 +4201,16 @@ function safeDiagnosticMetrics(value) {
|
|
|
4060
4201
|
return result;
|
|
4061
4202
|
}
|
|
4062
4203
|
function bridgeDiagnosticsChangesEnabled() {
|
|
4063
|
-
return
|
|
4204
|
+
return log3.isEnabled("trace");
|
|
4064
4205
|
}
|
|
4065
4206
|
function writeBridgeDiagnostic({ bridge, event, payload }) {
|
|
4066
4207
|
return tryWriteLog("info", "bridge.diagnostics", event, { bridge, payload });
|
|
4067
4208
|
}
|
|
4068
4209
|
function bridgeDiagnosticsActive() {
|
|
4069
|
-
return
|
|
4210
|
+
return log3.isEnabled("info");
|
|
4070
4211
|
}
|
|
4071
4212
|
function bridgeDiagnosticsStreamEnabled(bridge) {
|
|
4072
|
-
return bridgeDebugEnabled(bridge) ||
|
|
4213
|
+
return bridgeDebugEnabled(bridge) || log3.isEnabled("debug");
|
|
4073
4214
|
}
|
|
4074
4215
|
function writeDiagnostic(bridge, event, payload, write) {
|
|
4075
4216
|
try {
|
|
@@ -4432,8 +4573,7 @@ async function readBridgeLogPolicyBody(request) {
|
|
|
4432
4573
|
|
|
4433
4574
|
// ../../bridges/codex-bridge/src/index.ts
|
|
4434
4575
|
import { execFile as execFileCallback2 } from "node:child_process";
|
|
4435
|
-
import {
|
|
4436
|
-
import { appendFile as appendFile5, mkdir as mkdir9, readFile as readFile7, writeFile as writeFile6 } from "node:fs/promises";
|
|
4576
|
+
import { mkdir as mkdir9, readFile as readFile7, writeFile as writeFile6 } from "node:fs/promises";
|
|
4437
4577
|
import { join as join23 } from "node:path";
|
|
4438
4578
|
import { promisify as promisify2 } from "node:util";
|
|
4439
4579
|
|
|
@@ -7856,12 +7996,823 @@ function structuredOutputFailure(provider, code, message, options = {}) {
|
|
|
7856
7996
|
}
|
|
7857
7997
|
|
|
7858
7998
|
// ../protocol/src/node/workspace-change-probe.ts
|
|
7859
|
-
import {
|
|
7860
|
-
import { randomUUID } from "node:crypto";
|
|
7999
|
+
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
7861
8000
|
import { rmSync } from "node:fs";
|
|
7862
8001
|
import { copyFile, lstat, mkdtemp, rm } from "node:fs/promises";
|
|
7863
8002
|
import { tmpdir } from "node:os";
|
|
7864
8003
|
import { delimiter, isAbsolute, join, resolve } from "node:path";
|
|
8004
|
+
|
|
8005
|
+
// ../protocol/src/node/command-capture.ts
|
|
8006
|
+
import { spawn } from "node:child_process";
|
|
8007
|
+
import { randomUUID } from "node:crypto";
|
|
8008
|
+
import { constants as fsConstants } from "node:fs";
|
|
8009
|
+
import * as captureFs from "node:fs";
|
|
8010
|
+
import os from "node:os";
|
|
8011
|
+
import path from "node:path";
|
|
8012
|
+
import { inspect } from "node:util";
|
|
8013
|
+
|
|
8014
|
+
// ../protocol/src/node/command-failure-reason.ts
|
|
8015
|
+
var MAX_MATCHED_CHARS = 16 * 1024;
|
|
8016
|
+
var SIGNAL_PATTERN = /^SIG[A-Z0-9]{1,16}$/;
|
|
8017
|
+
var TOOL_RULES = {
|
|
8018
|
+
git: [
|
|
8019
|
+
["branch-exists", /a branch named .* already exists/i],
|
|
8020
|
+
["ref-conflict", /exists; cannot create|cannot lock ref .* is at .* but expected/i],
|
|
8021
|
+
["lock-held", /could not lock config file [^\n]*: File exists/i],
|
|
8022
|
+
["lock-held", /(?:unable to create '[^\n]*\.lock'|cannot lock ref)[^\n]*: File exists/i],
|
|
8023
|
+
["lock-held", /another git process/i],
|
|
8024
|
+
["worktree-conflict", /already (?:checked out|used by worktree)|used by worktree at/i],
|
|
8025
|
+
["invalid-ref", /not a valid (?:branch name|object name)|bad (?:revision|object)/i],
|
|
8026
|
+
["invalid-ref", /unknown revision|ambiguous argument|invalid reference/i],
|
|
8027
|
+
["branch-not-found", /no branch named|refname .* not found|branch '.*' not found/i],
|
|
8028
|
+
["branch-not-found", /did not match any file\(s\) known to git/i],
|
|
8029
|
+
["dubious-ownership", /detected dubious ownership/i],
|
|
8030
|
+
["no-remote", /does not appear to be a git repository|no such remote/i],
|
|
8031
|
+
["no-remote", /repository (?:.* )?not found/i],
|
|
8032
|
+
["not-a-repository", /not a git repository/i],
|
|
8033
|
+
["remote-ref-missing", /could(?:n't| not) find remote ref|not our ref/i],
|
|
8034
|
+
["merge-conflict", /\bCONFLICT \(|merge conflict|could not apply|unmerged files/i],
|
|
8035
|
+
["dirty-worktree", /local changes .* would be overwritten|commit your changes or stash/i],
|
|
8036
|
+
["nothing-to-commit", /nothing to commit|no changes added to commit/i],
|
|
8037
|
+
["push-rejected", /\[(?:remote )?rejected\]|non-fast-forward/i],
|
|
8038
|
+
["identity-unknown", /please tell me who you are|unable to auto-detect email/i],
|
|
8039
|
+
[
|
|
8040
|
+
"worktree-has-changes",
|
|
8041
|
+
/^fatal: [^\n]*['"] contains modified or untracked files(?:, use --force to delete it)?\.?\s*$/im
|
|
8042
|
+
],
|
|
8043
|
+
["not-a-worktree", /^fatal: [^\n]*['"] is not a working tree\.?\s*$/im],
|
|
8044
|
+
["branch-not-merged", /^(?:error|fatal): [^\n]*['"] is not fully merged\.?\s*$/im]
|
|
8045
|
+
],
|
|
8046
|
+
gh: [
|
|
8047
|
+
["pull-request-exists", /a pull request for branch .* already exists/i],
|
|
8048
|
+
["no-pull-request", /no (?:pull requests? (?:found|match)|open pull requests?\b)/i],
|
|
8049
|
+
["rate-limited", /rate limit|http 429/i],
|
|
8050
|
+
["forbidden", /http 403|resource not accessible/i],
|
|
8051
|
+
["resource-not-found", /http 404|could not resolve to a/i],
|
|
8052
|
+
["server-error", /http 5\d\d/i]
|
|
8053
|
+
],
|
|
8054
|
+
docker: [
|
|
8055
|
+
["daemon-unavailable", /cannot connect to the docker daemon|error during connect/i],
|
|
8056
|
+
[
|
|
8057
|
+
"daemon-unavailable",
|
|
8058
|
+
/is the docker daemon running|docker desktop is (?:not running|unable)/i
|
|
8059
|
+
],
|
|
8060
|
+
["container-not-found", /no such container/i],
|
|
8061
|
+
["container-not-running", /container .* is (?:not running|paused|restarting)/i],
|
|
8062
|
+
["container-name-conflict", /name .* is already in use/i],
|
|
8063
|
+
["image-not-found", /no such image|pull access denied|manifest .* not found/i],
|
|
8064
|
+
["image-not-found", /manifest unknown|repository does not exist/i],
|
|
8065
|
+
["removal-in-progress", /removal of container .* is already in progress/i],
|
|
8066
|
+
[
|
|
8067
|
+
"image-in-use",
|
|
8068
|
+
/image is (?:being used|referenced)|unable to (?:remove|delete) .*must be forced/i
|
|
8069
|
+
],
|
|
8070
|
+
["volume-in-use", /volume is in use/i],
|
|
8071
|
+
["volume-not-found", /no such volume/i],
|
|
8072
|
+
["network-in-use", /has active endpoints/i],
|
|
8073
|
+
["network-not-found", /network .* not found/i]
|
|
8074
|
+
],
|
|
8075
|
+
tmux: [
|
|
8076
|
+
["session-exists", /duplicate session/i],
|
|
8077
|
+
[
|
|
8078
|
+
"server-not-running",
|
|
8079
|
+
/no server running|failed to connect to server|no sessions|server exited|lost server/i
|
|
8080
|
+
],
|
|
8081
|
+
[
|
|
8082
|
+
"server-not-running",
|
|
8083
|
+
/error connecting to \/[^\n]* \((?:No such file or directory|Connection refused)\)/i
|
|
8084
|
+
],
|
|
8085
|
+
["session-not-found", /can't find (?:session|window|pane)|session not found/i]
|
|
8086
|
+
]
|
|
8087
|
+
};
|
|
8088
|
+
var ALL_TOOLS = Object.keys(TOOL_RULES);
|
|
8089
|
+
var SHARED_RULES = [
|
|
8090
|
+
["disk-full", /no space left|enospc|disk quota exceeded/i],
|
|
8091
|
+
["auth-failed", /authentication (?:failed|required)|could not read (?:username|password)/i],
|
|
8092
|
+
["auth-failed", /terminal prompts disabled|invalid username or password|bad credentials/i],
|
|
8093
|
+
["auth-failed", /permission denied \(|permission to \S+ denied|host key verification failed/i],
|
|
8094
|
+
["auth-failed", /gh auth login|not logged in|unauthorized|http 401|returned error: 40[13]/i],
|
|
8095
|
+
["network-failed", /could not resolve host|connection (?:timed out|refused|reset)/i],
|
|
8096
|
+
["network-failed", /network is unreachable|no route to host|temporary failure in name/i],
|
|
8097
|
+
["network-failed", /early eof|failed to connect|remote end hung up/i],
|
|
8098
|
+
["network-failed", /unable to access ['"]?https?:\/\//i],
|
|
8099
|
+
["network-failed", /tls handshake|i\/o timeout/i],
|
|
8100
|
+
[
|
|
8101
|
+
"network-failed",
|
|
8102
|
+
/error connecting to (?:https?:\/\/)?[a-z0-9](?:[a-z0-9.-]*[a-z0-9])?(?::\d+)?(?:[\s/:]|$)/i
|
|
8103
|
+
],
|
|
8104
|
+
["port-in-use", /port is already allocated|address already in use/i],
|
|
8105
|
+
["permission-denied", /permission denied|operation not permitted|read-only file system/i],
|
|
8106
|
+
["command-not-found", /command not found/i],
|
|
8107
|
+
["path-not-found", /no such file or directory/i],
|
|
8108
|
+
["invalid-usage", /^usage: |unknown (?:option|flag|command|shorthand flag)|invalid option/im]
|
|
8109
|
+
];
|
|
8110
|
+
var TOOL_EXIT_CODES = {
|
|
8111
|
+
git: { 129: "invalid-usage" },
|
|
8112
|
+
gh: { 2: "aborted", 4: "auth-failed" },
|
|
8113
|
+
docker: { 125: "daemon-error" },
|
|
8114
|
+
tmux: {}
|
|
8115
|
+
};
|
|
8116
|
+
var SHARED_EXIT_CODES = {
|
|
8117
|
+
124: "timed-out",
|
|
8118
|
+
126: "not-executable",
|
|
8119
|
+
127: "command-not-found",
|
|
8120
|
+
137: "killed",
|
|
8121
|
+
143: "killed"
|
|
8122
|
+
};
|
|
8123
|
+
function read2(target, key) {
|
|
8124
|
+
return target[key];
|
|
8125
|
+
}
|
|
8126
|
+
function boundedForMatching(text) {
|
|
8127
|
+
if (text.length <= MAX_MATCHED_CHARS)
|
|
8128
|
+
return text;
|
|
8129
|
+
const half = MAX_MATCHED_CHARS / 2;
|
|
8130
|
+
return `${text.slice(0, half)}
|
|
8131
|
+
${text.slice(-half)}`;
|
|
8132
|
+
}
|
|
8133
|
+
function failureText(error) {
|
|
8134
|
+
const stderr = read2(error, "stderr");
|
|
8135
|
+
if (Buffer.isBuffer(stderr) && stderr.length > 0) {
|
|
8136
|
+
return boundedForMatching(stderr.subarray(-MAX_MATCHED_CHARS).toString());
|
|
8137
|
+
}
|
|
8138
|
+
if (typeof stderr === "string" && stderr.length > 0)
|
|
8139
|
+
return boundedForMatching(stderr);
|
|
8140
|
+
const message = read2(error, "message");
|
|
8141
|
+
if (typeof message !== "string")
|
|
8142
|
+
return "";
|
|
8143
|
+
return message.startsWith("Command failed") ? "" : boundedForMatching(message);
|
|
8144
|
+
}
|
|
8145
|
+
function isRawSpawnEnoent(error) {
|
|
8146
|
+
const syscall = read2(error, "syscall");
|
|
8147
|
+
return read2(error, "code") === "ENOENT" && typeof syscall === "string" && /^(?:spawn(?:Sync)?(?:\s|$)|posix_spawnp?$)/.test(syscall);
|
|
8148
|
+
}
|
|
8149
|
+
function classifiedReason(error, exitCode, signal, options) {
|
|
8150
|
+
if (read2(error, "aborted") === true)
|
|
8151
|
+
return "aborted";
|
|
8152
|
+
if (read2(error, "outputLimitExceeded") === true)
|
|
8153
|
+
return "output-too-large";
|
|
8154
|
+
if (read2(error, "timedOut") === true)
|
|
8155
|
+
return "timed-out";
|
|
8156
|
+
if (read2(error, "executableMissing") === true || isRawSpawnEnoent(error)) {
|
|
8157
|
+
return "executable-missing";
|
|
8158
|
+
}
|
|
8159
|
+
const named = exitCode === null ? undefined : options.exitCodes?.[exitCode];
|
|
8160
|
+
if (named)
|
|
8161
|
+
return named;
|
|
8162
|
+
if (signal)
|
|
8163
|
+
return "killed";
|
|
8164
|
+
const text = failureText(error);
|
|
8165
|
+
for (const tool of options.tools ?? ALL_TOOLS) {
|
|
8166
|
+
for (const [reason, pattern] of TOOL_RULES[tool]) {
|
|
8167
|
+
if (pattern.test(text))
|
|
8168
|
+
return reason;
|
|
8169
|
+
}
|
|
8170
|
+
}
|
|
8171
|
+
for (const [reason, pattern] of SHARED_RULES) {
|
|
8172
|
+
if (pattern.test(text))
|
|
8173
|
+
return reason;
|
|
8174
|
+
}
|
|
8175
|
+
if (exitCode !== null) {
|
|
8176
|
+
for (const tool of options.tools ?? []) {
|
|
8177
|
+
const reason = TOOL_EXIT_CODES[tool][exitCode];
|
|
8178
|
+
if (reason)
|
|
8179
|
+
return reason;
|
|
8180
|
+
}
|
|
8181
|
+
const reason = SHARED_EXIT_CODES[exitCode];
|
|
8182
|
+
if (reason)
|
|
8183
|
+
return reason;
|
|
8184
|
+
}
|
|
8185
|
+
return "unclassified";
|
|
8186
|
+
}
|
|
8187
|
+
function numericExitCode(error) {
|
|
8188
|
+
for (const key of ["exitCode", "code"]) {
|
|
8189
|
+
const value = read2(error, key);
|
|
8190
|
+
if (typeof value === "number" && Number.isFinite(value))
|
|
8191
|
+
return value;
|
|
8192
|
+
}
|
|
8193
|
+
return null;
|
|
8194
|
+
}
|
|
8195
|
+
function classifyCommandFailure(error, options = {}) {
|
|
8196
|
+
if (typeof error !== "object" || error === null) {
|
|
8197
|
+
return { reason: "unclassified", exitCode: null, signal: null };
|
|
8198
|
+
}
|
|
8199
|
+
try {
|
|
8200
|
+
const exitCode = numericExitCode(error);
|
|
8201
|
+
const rawSignal = read2(error, "signal");
|
|
8202
|
+
const signal = typeof rawSignal === "string" && SIGNAL_PATTERN.test(rawSignal) ? rawSignal : null;
|
|
8203
|
+
return { reason: classifiedReason(error, exitCode, signal, options), exitCode, signal };
|
|
8204
|
+
} catch {
|
|
8205
|
+
return { reason: "unclassified", exitCode: null, signal: null };
|
|
8206
|
+
}
|
|
8207
|
+
}
|
|
8208
|
+
|
|
8209
|
+
// ../protocol/src/node/lost-exit-reaper.ts
|
|
8210
|
+
import { createRequire as createRequire2 } from "node:module";
|
|
8211
|
+
|
|
8212
|
+
// ../protocol/src/node/shell-process-state.ts
|
|
8213
|
+
import { readdirSync, readFileSync } from "node:fs";
|
|
8214
|
+
import { constants as osConstants } from "node:os";
|
|
8215
|
+
var PROCESS_INSPECTION_OPTIONS = {
|
|
8216
|
+
timeout: 100,
|
|
8217
|
+
killSignal: "SIGKILL",
|
|
8218
|
+
maxBuffer: 1024 * 1024
|
|
8219
|
+
};
|
|
8220
|
+
function bunRuntime() {
|
|
8221
|
+
return globalThis.Bun;
|
|
8222
|
+
}
|
|
8223
|
+
function decodeWaitStatus(status) {
|
|
8224
|
+
const signalNumber = status & 127;
|
|
8225
|
+
if (signalNumber === 0)
|
|
8226
|
+
return { code: status >> 8 & 255, signal: null };
|
|
8227
|
+
const name = Object.entries(osConstants.signals).find(([, value]) => value === signalNumber)?.[0];
|
|
8228
|
+
return { code: null, signal: name ?? "SIGKILL" };
|
|
8229
|
+
}
|
|
8230
|
+
function readZombieExit(pid) {
|
|
8231
|
+
try {
|
|
8232
|
+
const result = bunRuntime()?.spawnSync(["/bin/ps", "-o", "stat=,xstat=", "-p", String(pid)], PROCESS_INSPECTION_OPTIONS);
|
|
8233
|
+
if (!result?.success)
|
|
8234
|
+
return;
|
|
8235
|
+
const { stdout } = result;
|
|
8236
|
+
const match = /^Z\S*\s+([0-9a-f]+)\s*$/i.exec(stdout.toString().trim());
|
|
8237
|
+
return match ? decodeWaitStatus(Number.parseInt(match[1], 16)) : undefined;
|
|
8238
|
+
} catch {
|
|
8239
|
+
return;
|
|
8240
|
+
}
|
|
8241
|
+
}
|
|
8242
|
+
var EXIT_WATCH_MS = 1000;
|
|
8243
|
+
var EXIT_WATCH_MAX_MS = 16000;
|
|
8244
|
+
function watchForLostExit(pid, onExit) {
|
|
8245
|
+
if (process.platform !== "darwin" || pid === undefined || !bunRuntime())
|
|
8246
|
+
return () => {
|
|
8247
|
+
return;
|
|
8248
|
+
};
|
|
8249
|
+
let timer;
|
|
8250
|
+
const watch = (delayMs) => {
|
|
8251
|
+
timer = setTimeout(() => {
|
|
8252
|
+
const exit = readZombieExit(pid);
|
|
8253
|
+
if (exit)
|
|
8254
|
+
onExit(exit);
|
|
8255
|
+
else
|
|
8256
|
+
watch(Math.min(delayMs * 2, EXIT_WATCH_MAX_MS));
|
|
8257
|
+
}, delayMs);
|
|
8258
|
+
};
|
|
8259
|
+
watch(EXIT_WATCH_MS);
|
|
8260
|
+
return () => clearTimeout(timer);
|
|
8261
|
+
}
|
|
8262
|
+
function isLiveMember(state, groupId, pgid) {
|
|
8263
|
+
return Number(groupId) === pgid && state !== undefined && !/^[ZX]/.test(state);
|
|
8264
|
+
}
|
|
8265
|
+
function linuxGroupHasLiveMember(pgid) {
|
|
8266
|
+
for (const entry of readdirSync("/proc")) {
|
|
8267
|
+
if (!/^\d+$/.test(entry))
|
|
8268
|
+
continue;
|
|
8269
|
+
let stat;
|
|
8270
|
+
try {
|
|
8271
|
+
stat = readFileSync(`/proc/${entry}/stat`, "latin1");
|
|
8272
|
+
} catch {
|
|
8273
|
+
continue;
|
|
8274
|
+
}
|
|
8275
|
+
const [state, , groupId] = stat.slice(stat.lastIndexOf(")") + 2).split(" ");
|
|
8276
|
+
if (isLiveMember(state, groupId, pgid))
|
|
8277
|
+
return true;
|
|
8278
|
+
}
|
|
8279
|
+
return false;
|
|
8280
|
+
}
|
|
8281
|
+
function psGroupHasLiveMember(pgid) {
|
|
8282
|
+
const result = bunRuntime()?.spawnSync(["/bin/ps", "-A", "-o", "pgid=,stat="], PROCESS_INSPECTION_OPTIONS);
|
|
8283
|
+
if (!result?.success)
|
|
8284
|
+
return true;
|
|
8285
|
+
return result.stdout.toString().split(`
|
|
8286
|
+
`).some((line) => {
|
|
8287
|
+
const [groupId, state] = line.trim().split(/\s+/);
|
|
8288
|
+
return isLiveMember(state, groupId, pgid);
|
|
8289
|
+
});
|
|
8290
|
+
}
|
|
8291
|
+
function groupHasLiveMember(pgid) {
|
|
8292
|
+
try {
|
|
8293
|
+
return process.platform === "linux" ? linuxGroupHasLiveMember(pgid) : psGroupHasLiveMember(pgid);
|
|
8294
|
+
} catch {
|
|
8295
|
+
return true;
|
|
8296
|
+
}
|
|
8297
|
+
}
|
|
8298
|
+
|
|
8299
|
+
// ../protocol/src/node/lost-exit-reaper.ts
|
|
8300
|
+
var log4 = createLogger("process");
|
|
8301
|
+
var REAP_GRACE_MS = 2000;
|
|
8302
|
+
var REAP_MAX_CHECK_MS = 30000;
|
|
8303
|
+
var REAP_MAX_CHECKS = 12;
|
|
8304
|
+
var REAP_MAX_PENDING = 256;
|
|
8305
|
+
function createLostExitReaper(options) {
|
|
8306
|
+
const { system } = options;
|
|
8307
|
+
const graceMs = options.graceMs ?? REAP_GRACE_MS;
|
|
8308
|
+
const maxCheckMs = options.maxCheckMs ?? REAP_MAX_CHECK_MS;
|
|
8309
|
+
const maxChecks = options.maxChecks ?? REAP_MAX_CHECKS;
|
|
8310
|
+
const maxPending = options.maxPending ?? REAP_MAX_PENDING;
|
|
8311
|
+
const pending = new Map;
|
|
8312
|
+
let reaped = 0;
|
|
8313
|
+
let abandoned = 0;
|
|
8314
|
+
const abandon = (pid, reason) => {
|
|
8315
|
+
abandoned += 1;
|
|
8316
|
+
log4.warn("child.reap-abandoned", { pid, reason });
|
|
8317
|
+
};
|
|
8318
|
+
const check = (pid, reported, startedAt) => {
|
|
8319
|
+
if (reported())
|
|
8320
|
+
return false;
|
|
8321
|
+
const found = system.inspect(pid);
|
|
8322
|
+
if (found === undefined)
|
|
8323
|
+
return true;
|
|
8324
|
+
if (found === "gone" || found.ppid !== system.selfPid)
|
|
8325
|
+
return false;
|
|
8326
|
+
if (!found.state.startsWith("Z"))
|
|
8327
|
+
return true;
|
|
8328
|
+
const result = system.waitNoHang(pid);
|
|
8329
|
+
if (result === pid) {
|
|
8330
|
+
reaped += 1;
|
|
8331
|
+
log4.info("child.reaped", { pid, waitedMs: Date.now() - startedAt });
|
|
8332
|
+
return false;
|
|
8333
|
+
}
|
|
8334
|
+
if (result === 0)
|
|
8335
|
+
return true;
|
|
8336
|
+
abandon(pid, "waitpid-failed");
|
|
8337
|
+
return false;
|
|
8338
|
+
};
|
|
8339
|
+
const schedule = (pid, reported, startedAt, delayMs, checks) => {
|
|
8340
|
+
const timer = setTimeout(() => {
|
|
8341
|
+
pending.delete(pid);
|
|
8342
|
+
let again;
|
|
8343
|
+
try {
|
|
8344
|
+
again = check(pid, reported, startedAt);
|
|
8345
|
+
} catch {
|
|
8346
|
+
again = true;
|
|
8347
|
+
}
|
|
8348
|
+
if (!again)
|
|
8349
|
+
return;
|
|
8350
|
+
if (checks + 1 >= maxChecks) {
|
|
8351
|
+
abandon(pid, "not-a-zombie");
|
|
8352
|
+
return;
|
|
8353
|
+
}
|
|
8354
|
+
schedule(pid, reported, startedAt, Math.min(delayMs * 2, maxCheckMs), checks + 1);
|
|
8355
|
+
}, delayMs);
|
|
8356
|
+
timer.unref?.();
|
|
8357
|
+
pending.set(pid, timer);
|
|
8358
|
+
};
|
|
8359
|
+
return {
|
|
8360
|
+
reap(pid, reported) {
|
|
8361
|
+
if (!Number.isSafeInteger(pid) || pid <= 1 || pid === system.selfPid)
|
|
8362
|
+
return;
|
|
8363
|
+
if (pending.has(pid) || reported())
|
|
8364
|
+
return;
|
|
8365
|
+
if (pending.size >= maxPending) {
|
|
8366
|
+
abandon(pid, "capacity");
|
|
8367
|
+
return;
|
|
8368
|
+
}
|
|
8369
|
+
schedule(pid, reported, Date.now(), graceMs, 0);
|
|
8370
|
+
},
|
|
8371
|
+
stats: () => ({ pending: pending.size, reaped, abandoned }),
|
|
8372
|
+
stop() {
|
|
8373
|
+
for (const timer of pending.values())
|
|
8374
|
+
clearTimeout(timer);
|
|
8375
|
+
pending.clear();
|
|
8376
|
+
}
|
|
8377
|
+
};
|
|
8378
|
+
}
|
|
8379
|
+
var WNOHANG = 1;
|
|
8380
|
+
function loadDarwinWaitpid(loadFfi = () => createRequire2(import.meta.url)("bun:ffi")) {
|
|
8381
|
+
try {
|
|
8382
|
+
const { dlopen, FFIType } = loadFfi();
|
|
8383
|
+
const libSystem = dlopen("/usr/lib/libSystem.B.dylib", {
|
|
8384
|
+
waitpid: { args: [FFIType.i32, FFIType.ptr, FFIType.i32], returns: FFIType.i32 }
|
|
8385
|
+
});
|
|
8386
|
+
const status = new Int32Array(1);
|
|
8387
|
+
return (pid) => libSystem.symbols.waitpid(pid, status, WNOHANG);
|
|
8388
|
+
} catch {
|
|
8389
|
+
return;
|
|
8390
|
+
}
|
|
8391
|
+
}
|
|
8392
|
+
function darwinReaperSystem(loadFfi) {
|
|
8393
|
+
const waitNoHang = loadDarwinWaitpid(loadFfi);
|
|
8394
|
+
if (!waitNoHang)
|
|
8395
|
+
return;
|
|
8396
|
+
return {
|
|
8397
|
+
selfPid: process.pid,
|
|
8398
|
+
inspect(pid) {
|
|
8399
|
+
const result = bunRuntime()?.spawnSync(["/bin/ps", "-o", "ppid=,stat=", "-p", String(pid)], PROCESS_INSPECTION_OPTIONS);
|
|
8400
|
+
if (!result)
|
|
8401
|
+
return;
|
|
8402
|
+
const output = result.stdout.toString().trim();
|
|
8403
|
+
if (!result.success)
|
|
8404
|
+
return result.exitCode === 1 && output === "" ? "gone" : undefined;
|
|
8405
|
+
const match = /^(\d+)\s+(\S+)$/.exec(output);
|
|
8406
|
+
return match ? { ppid: Number(match[1]), state: match[2] } : undefined;
|
|
8407
|
+
},
|
|
8408
|
+
waitNoHang
|
|
8409
|
+
};
|
|
8410
|
+
}
|
|
8411
|
+
var defaultReaper;
|
|
8412
|
+
function createDarwinLostExitReaper(loadFfi) {
|
|
8413
|
+
const system = darwinReaperSystem(loadFfi);
|
|
8414
|
+
if (!system)
|
|
8415
|
+
log4.warn("child.reap-unavailable");
|
|
8416
|
+
return system ? createLostExitReaper({ system }) : null;
|
|
8417
|
+
}
|
|
8418
|
+
function sharedReaper() {
|
|
8419
|
+
if (defaultReaper === undefined) {
|
|
8420
|
+
defaultReaper = createDarwinLostExitReaper();
|
|
8421
|
+
}
|
|
8422
|
+
return defaultReaper ?? undefined;
|
|
8423
|
+
}
|
|
8424
|
+
function reapAfterLostExit(pid, reported) {
|
|
8425
|
+
if (process.platform !== "darwin" || pid === undefined || !bunRuntime())
|
|
8426
|
+
return;
|
|
8427
|
+
sharedReaper()?.reap(pid, reported);
|
|
8428
|
+
}
|
|
8429
|
+
|
|
8430
|
+
// ../protocol/src/node/command-capture.ts
|
|
8431
|
+
class CommandFailedError extends Error {
|
|
8432
|
+
stdout;
|
|
8433
|
+
stdoutBytes;
|
|
8434
|
+
stderr;
|
|
8435
|
+
timedOut;
|
|
8436
|
+
outputCloseTimedOut;
|
|
8437
|
+
executableMissing;
|
|
8438
|
+
aborted;
|
|
8439
|
+
outputLimitExceeded;
|
|
8440
|
+
exitCode;
|
|
8441
|
+
signal;
|
|
8442
|
+
constructor(message, details = {}) {
|
|
8443
|
+
super(message);
|
|
8444
|
+
this.name = "CommandFailedError";
|
|
8445
|
+
this.stdout = details.stdout ?? "";
|
|
8446
|
+
this.stdoutBytes = details.stdoutBytes ?? Buffer.alloc(0);
|
|
8447
|
+
this.stderr = details.stderr ?? "";
|
|
8448
|
+
this.timedOut = details.timedOut ?? false;
|
|
8449
|
+
this.outputCloseTimedOut = details.outputCloseTimedOut ?? false;
|
|
8450
|
+
this.executableMissing = details.executableMissing ?? false;
|
|
8451
|
+
this.aborted = details.aborted ?? false;
|
|
8452
|
+
this.outputLimitExceeded = details.outputLimitExceeded ?? false;
|
|
8453
|
+
this.exitCode = details.exitCode ?? null;
|
|
8454
|
+
this.signal = details.signal ?? null;
|
|
8455
|
+
}
|
|
8456
|
+
toJSON() {
|
|
8457
|
+
return { ...formatLogError(this), ...classifyCommandFailure(this) };
|
|
8458
|
+
}
|
|
8459
|
+
[inspect.custom]() {
|
|
8460
|
+
const { name, reason, exitCode, signal, stack } = this.toJSON();
|
|
8461
|
+
const frames = stack?.length ? ` | ${stack.join(" | ")}` : "";
|
|
8462
|
+
return `${name} reason=${reason} exitCode=${exitCode} signal=${signal} outputOmitted=true${frames}`;
|
|
8463
|
+
}
|
|
8464
|
+
}
|
|
8465
|
+
function redactCommandValues(value, redactValues) {
|
|
8466
|
+
const secrets = Array.from(new Set((redactValues ?? []).filter((secret) => typeof secret === "string" && secret.length > 0))).sort((left, right) => right.length - left.length);
|
|
8467
|
+
return secrets.reduce((redacted, secret) => redacted.split(secret).join("[REDACTED]"), value);
|
|
8468
|
+
}
|
|
8469
|
+
var COMMAND_ABORTED_MESSAGE = "Command aborted";
|
|
8470
|
+
var OUTPUT_LIMIT_MESSAGE = "maxBuffer length exceeded";
|
|
8471
|
+
function commandFailureOutcome(error) {
|
|
8472
|
+
const details = error ?? {};
|
|
8473
|
+
const message = typeof details.message === "string" ? details.message : "";
|
|
8474
|
+
return {
|
|
8475
|
+
timedOut: details.killed === true,
|
|
8476
|
+
executableMissing: details.code === "ENOENT",
|
|
8477
|
+
aborted: message === COMMAND_ABORTED_MESSAGE,
|
|
8478
|
+
outputLimitExceeded: details.outputLimitExceeded === true,
|
|
8479
|
+
exitCode: typeof details.code === "number" ? details.code : null,
|
|
8480
|
+
signal: details.signal ?? null
|
|
8481
|
+
};
|
|
8482
|
+
}
|
|
8483
|
+
var commandInvocations = new Map;
|
|
8484
|
+
var commandCaptureMetrics;
|
|
8485
|
+
var commandObservers = new Map;
|
|
8486
|
+
function nonInteractiveGitEnv(env) {
|
|
8487
|
+
const merged = { ...env ?? process.env };
|
|
8488
|
+
merged.GIT_TERMINAL_PROMPT ??= "0";
|
|
8489
|
+
if (process.platform !== "win32") {
|
|
8490
|
+
merged.SSH_ASKPASS ??= "/usr/bin/false";
|
|
8491
|
+
merged.SSH_ASKPASS_REQUIRE ??= "force";
|
|
8492
|
+
}
|
|
8493
|
+
return merged;
|
|
8494
|
+
}
|
|
8495
|
+
var MAX_COMMAND_OUTPUT_BYTES = 50 * 1024 * 1024;
|
|
8496
|
+
var COMMAND_KILL_GRACE_MS = 100;
|
|
8497
|
+
var COMMAND_OUTPUT_CHECK_MS = 100;
|
|
8498
|
+
var COMMAND_GROUP_POLL_MS = 5;
|
|
8499
|
+
var COMMAND_GROUP_POLL_MAX_MS = 200;
|
|
8500
|
+
function openCaptureFile() {
|
|
8501
|
+
const filePath = path.join(os.tmpdir(), `orkestrator-capture-${randomUUID()}`);
|
|
8502
|
+
const fd = captureFs.openSync(filePath, fsConstants.O_CREAT | fsConstants.O_EXCL | fsConstants.O_RDWR | fsConstants.O_APPEND, 384);
|
|
8503
|
+
try {
|
|
8504
|
+
captureFs.unlinkSync(filePath);
|
|
8505
|
+
return fd;
|
|
8506
|
+
} catch (error) {
|
|
8507
|
+
captureFs.closeSync(fd);
|
|
8508
|
+
throw error;
|
|
8509
|
+
}
|
|
8510
|
+
}
|
|
8511
|
+
function readCaptureFile(fd, limit) {
|
|
8512
|
+
const size = Math.min(captureFs.fstatSync(fd).size, limit);
|
|
8513
|
+
const buffer = Buffer.allocUnsafe(size);
|
|
8514
|
+
let offset = 0;
|
|
8515
|
+
while (offset < size) {
|
|
8516
|
+
const bytesRead = captureFs.readSync(fd, buffer, offset, size - offset, offset);
|
|
8517
|
+
if (bytesRead === 0)
|
|
8518
|
+
break;
|
|
8519
|
+
offset += bytesRead;
|
|
8520
|
+
}
|
|
8521
|
+
return buffer.subarray(0, offset);
|
|
8522
|
+
}
|
|
8523
|
+
function spawnCaptured(command, args, options, stdoutFd, stderrFd) {
|
|
8524
|
+
const payload = options.stdin?.length ? Buffer.from(options.stdin) : undefined;
|
|
8525
|
+
const env = command === "git" ? nonInteractiveGitEnv(options.env) : options.env ?? process.env;
|
|
8526
|
+
const detached = process.platform !== "win32";
|
|
8527
|
+
const bun = bunRuntime();
|
|
8528
|
+
if (bun) {
|
|
8529
|
+
const child = bun.spawn([command, ...args], {
|
|
8530
|
+
cwd: options.cwd,
|
|
8531
|
+
env,
|
|
8532
|
+
detached,
|
|
8533
|
+
windowsHide: true,
|
|
8534
|
+
stdin: payload ?? "pipe",
|
|
8535
|
+
stdout: stdoutFd,
|
|
8536
|
+
stderr: stderrFd
|
|
8537
|
+
});
|
|
8538
|
+
if (!payload)
|
|
8539
|
+
closeStdin(child.stdin);
|
|
8540
|
+
const current = () => ({ code: child.exitCode, signal: child.signalCode });
|
|
8541
|
+
return {
|
|
8542
|
+
pid: child.pid,
|
|
8543
|
+
exited: child.exited.then(current),
|
|
8544
|
+
current,
|
|
8545
|
+
kill: (signal) => child.kill(signal)
|
|
8546
|
+
};
|
|
8547
|
+
}
|
|
8548
|
+
const child = spawn(command, args, {
|
|
8549
|
+
cwd: options.cwd,
|
|
8550
|
+
env,
|
|
8551
|
+
detached,
|
|
8552
|
+
windowsHide: true,
|
|
8553
|
+
stdio: [payload ? "pipe" : "ignore", stdoutFd, stderrFd]
|
|
8554
|
+
});
|
|
8555
|
+
if (payload) {
|
|
8556
|
+
child.stdin?.on("error", () => {
|
|
8557
|
+
return;
|
|
8558
|
+
});
|
|
8559
|
+
child.stdin?.end(payload);
|
|
8560
|
+
}
|
|
8561
|
+
return {
|
|
8562
|
+
pid: child.pid,
|
|
8563
|
+
exited: new Promise((resolve, reject) => {
|
|
8564
|
+
child.once("exit", (code, signal) => resolve({ code, signal }));
|
|
8565
|
+
child.once("error", reject);
|
|
8566
|
+
}),
|
|
8567
|
+
current: () => ({ code: child.exitCode, signal: child.signalCode }),
|
|
8568
|
+
kill: (signal) => {
|
|
8569
|
+
child.kill(signal);
|
|
8570
|
+
}
|
|
8571
|
+
};
|
|
8572
|
+
}
|
|
8573
|
+
function closeStdin(stdin) {
|
|
8574
|
+
try {
|
|
8575
|
+
Promise.resolve(stdin.end()).catch(() => {
|
|
8576
|
+
return;
|
|
8577
|
+
});
|
|
8578
|
+
} catch {}
|
|
8579
|
+
}
|
|
8580
|
+
function exitReported(child) {
|
|
8581
|
+
const { code, signal } = child.current();
|
|
8582
|
+
return code !== null || signal !== null;
|
|
8583
|
+
}
|
|
8584
|
+
function signalCommand(child, signal) {
|
|
8585
|
+
if (child.pid === undefined)
|
|
8586
|
+
return;
|
|
8587
|
+
try {
|
|
8588
|
+
if (process.platform !== "win32") {
|
|
8589
|
+
process.kill(-child.pid, signal);
|
|
8590
|
+
} else {
|
|
8591
|
+
child.kill(signal);
|
|
8592
|
+
}
|
|
8593
|
+
} catch {}
|
|
8594
|
+
}
|
|
8595
|
+
function commandGroupAlive(child) {
|
|
8596
|
+
if (process.platform === "win32" || child.pid === undefined)
|
|
8597
|
+
return false;
|
|
8598
|
+
try {
|
|
8599
|
+
process.kill(-child.pid, 0);
|
|
8600
|
+
} catch (error) {
|
|
8601
|
+
if (error.code === "ESRCH")
|
|
8602
|
+
return false;
|
|
8603
|
+
}
|
|
8604
|
+
return groupHasLiveMember(child.pid);
|
|
8605
|
+
}
|
|
8606
|
+
function executeCommandBytes(command, args, options, timeoutMs, outputLimit, stderrLimit) {
|
|
8607
|
+
return new Promise((resolve, reject) => {
|
|
8608
|
+
if (options.signal?.aborted) {
|
|
8609
|
+
reject(Object.assign(new Error(COMMAND_ABORTED_MESSAGE), { killed: true }));
|
|
8610
|
+
return;
|
|
8611
|
+
}
|
|
8612
|
+
const captureFds = [];
|
|
8613
|
+
const releaseCaptureFds = () => {
|
|
8614
|
+
for (const fd of captureFds.splice(0)) {
|
|
8615
|
+
try {
|
|
8616
|
+
captureFs.closeSync(fd);
|
|
8617
|
+
} catch {}
|
|
8618
|
+
}
|
|
8619
|
+
};
|
|
8620
|
+
try {
|
|
8621
|
+
captureFds.push(openCaptureFile());
|
|
8622
|
+
captureFds.push(openCaptureFile());
|
|
8623
|
+
} catch (error) {
|
|
8624
|
+
releaseCaptureFds();
|
|
8625
|
+
const code = error.code ?? "unknown";
|
|
8626
|
+
reject(new Error(`Could not open a command output file in the temporary directory: ${code}`));
|
|
8627
|
+
return;
|
|
8628
|
+
}
|
|
8629
|
+
const [stdoutFd, stderrFd] = captureFds;
|
|
8630
|
+
let child;
|
|
8631
|
+
try {
|
|
8632
|
+
child = spawnCaptured(command, args, options, stdoutFd, stderrFd);
|
|
8633
|
+
} catch (error) {
|
|
8634
|
+
releaseCaptureFds();
|
|
8635
|
+
reject(error);
|
|
8636
|
+
return;
|
|
8637
|
+
}
|
|
8638
|
+
let settled = false;
|
|
8639
|
+
let timedOut = false;
|
|
8640
|
+
let timeoutTimer;
|
|
8641
|
+
let groupTimer;
|
|
8642
|
+
let limitTimer;
|
|
8643
|
+
let stopExitWatch = () => {};
|
|
8644
|
+
let commandExit;
|
|
8645
|
+
const finishCapture = () => {
|
|
8646
|
+
settled = true;
|
|
8647
|
+
clearTimeout(timeoutTimer);
|
|
8648
|
+
clearTimeout(groupTimer);
|
|
8649
|
+
clearInterval(limitTimer);
|
|
8650
|
+
stopExitWatch();
|
|
8651
|
+
options.signal?.removeEventListener("abort", abort);
|
|
8652
|
+
if (!exitReported(child))
|
|
8653
|
+
reapAfterLostExit(child.pid, () => exitReported(child));
|
|
8654
|
+
try {
|
|
8655
|
+
return {
|
|
8656
|
+
stdout: readCaptureFile(stdoutFd, outputLimit),
|
|
8657
|
+
stderr: readCaptureFile(stderrFd, stderrLimit)
|
|
8658
|
+
};
|
|
8659
|
+
} catch (error) {
|
|
8660
|
+
reject(error);
|
|
8661
|
+
return;
|
|
8662
|
+
} finally {
|
|
8663
|
+
releaseCaptureFds();
|
|
8664
|
+
}
|
|
8665
|
+
};
|
|
8666
|
+
const fail = (error) => {
|
|
8667
|
+
if (settled)
|
|
8668
|
+
return;
|
|
8669
|
+
const output = finishCapture();
|
|
8670
|
+
if (output)
|
|
8671
|
+
reject(Object.assign(error, { ...output, killed: timedOut }));
|
|
8672
|
+
};
|
|
8673
|
+
const abort = () => {
|
|
8674
|
+
timedOut = true;
|
|
8675
|
+
signalCommand(child, "SIGKILL");
|
|
8676
|
+
fail(new Error(COMMAND_ABORTED_MESSAGE));
|
|
8677
|
+
};
|
|
8678
|
+
options.signal?.addEventListener("abort", abort, { once: true });
|
|
8679
|
+
const checkOutputLimit = () => {
|
|
8680
|
+
const stream = captureFs.fstatSync(stdoutFd).size > outputLimit ? "stdout" : captureFs.fstatSync(stderrFd).size > stderrLimit ? "stderr" : undefined;
|
|
8681
|
+
if (stream === undefined)
|
|
8682
|
+
return false;
|
|
8683
|
+
signalCommand(child, "SIGKILL");
|
|
8684
|
+
fail(Object.assign(new Error(`${stream} ${OUTPUT_LIMIT_MESSAGE}`), {
|
|
8685
|
+
outputLimitExceeded: true
|
|
8686
|
+
}));
|
|
8687
|
+
return true;
|
|
8688
|
+
};
|
|
8689
|
+
const failIfOverLimit = () => {
|
|
8690
|
+
try {
|
|
8691
|
+
return checkOutputLimit();
|
|
8692
|
+
} catch (error) {
|
|
8693
|
+
signalCommand(child, "SIGKILL");
|
|
8694
|
+
fail(error instanceof Error ? error : new Error(String(error)));
|
|
8695
|
+
return true;
|
|
8696
|
+
}
|
|
8697
|
+
};
|
|
8698
|
+
limitTimer = setInterval(() => {
|
|
8699
|
+
if (!settled && !timedOut)
|
|
8700
|
+
failIfOverLimit();
|
|
8701
|
+
}, COMMAND_OUTPUT_CHECK_MS);
|
|
8702
|
+
const settleOnExit = () => {
|
|
8703
|
+
if (settled || timedOut || failIfOverLimit())
|
|
8704
|
+
return;
|
|
8705
|
+
if (commandExit?.code !== 0 || commandExit.signal !== null) {
|
|
8706
|
+
fail(Object.assign(new Error(`Command failed: ${[command, ...args].join(" ")}`), {
|
|
8707
|
+
code: commandExit?.code,
|
|
8708
|
+
signal: commandExit?.signal
|
|
8709
|
+
}));
|
|
8710
|
+
return;
|
|
8711
|
+
}
|
|
8712
|
+
const output = finishCapture();
|
|
8713
|
+
if (output)
|
|
8714
|
+
resolve(output);
|
|
8715
|
+
};
|
|
8716
|
+
const awaitGroupExit = (delayMs) => {
|
|
8717
|
+
if (settled || timedOut)
|
|
8718
|
+
return;
|
|
8719
|
+
if (commandGroupAlive(child)) {
|
|
8720
|
+
groupTimer = setTimeout(awaitGroupExit, delayMs, Math.min(delayMs * 2, COMMAND_GROUP_POLL_MAX_MS));
|
|
8721
|
+
return;
|
|
8722
|
+
}
|
|
8723
|
+
settleOnExit();
|
|
8724
|
+
};
|
|
8725
|
+
const onCommandExit = (exit) => {
|
|
8726
|
+
if (commandExit)
|
|
8727
|
+
return;
|
|
8728
|
+
commandExit = exit;
|
|
8729
|
+
stopExitWatch();
|
|
8730
|
+
if (options.waitForDescendants)
|
|
8731
|
+
awaitGroupExit(COMMAND_GROUP_POLL_MS);
|
|
8732
|
+
else
|
|
8733
|
+
settleOnExit();
|
|
8734
|
+
};
|
|
8735
|
+
child.exited.then(onCommandExit, (error) => fail(error instanceof Error ? error : new Error(String(error))));
|
|
8736
|
+
stopExitWatch = watchForLostExit(child.pid, (exit) => {
|
|
8737
|
+
if (!settled && !timedOut)
|
|
8738
|
+
onCommandExit(exit);
|
|
8739
|
+
});
|
|
8740
|
+
if (timeoutMs > 0) {
|
|
8741
|
+
timeoutTimer = setTimeout(() => {
|
|
8742
|
+
timedOut = true;
|
|
8743
|
+
signalCommand(child, "SIGTERM");
|
|
8744
|
+
timeoutTimer = setTimeout(() => {
|
|
8745
|
+
signalCommand(child, "SIGKILL");
|
|
8746
|
+
fail(Object.assign(new Error(`Command timed out after ${timeoutMs} ms`), {
|
|
8747
|
+
code: child.current().code,
|
|
8748
|
+
signal: child.current().signal
|
|
8749
|
+
}));
|
|
8750
|
+
}, COMMAND_KILL_GRACE_MS);
|
|
8751
|
+
}, timeoutMs);
|
|
8752
|
+
}
|
|
8753
|
+
});
|
|
8754
|
+
}
|
|
8755
|
+
async function runCommandBytes(command, args = [], options = {}) {
|
|
8756
|
+
const timeoutMs = options.timeoutMs ?? 60000;
|
|
8757
|
+
if (!Number.isSafeInteger(timeoutMs) || timeoutMs < 0 || timeoutMs > 2147483647) {
|
|
8758
|
+
throw new RangeError("timeoutMs must be an integer between 0 and 2147483647");
|
|
8759
|
+
}
|
|
8760
|
+
const outputLimit = options.maxOutputBytes ?? MAX_COMMAND_OUTPUT_BYTES;
|
|
8761
|
+
if (!Number.isSafeInteger(outputLimit) || outputLimit <= 0) {
|
|
8762
|
+
throw new RangeError("maxOutputBytes must be a positive integer");
|
|
8763
|
+
}
|
|
8764
|
+
const stderrLimit = options.maxStderrBytes ?? outputLimit;
|
|
8765
|
+
if (!Number.isSafeInteger(stderrLimit) || stderrLimit <= 0) {
|
|
8766
|
+
throw new RangeError("maxStderrBytes must be a positive integer");
|
|
8767
|
+
}
|
|
8768
|
+
if (commandInvocations.size < 64 || commandInvocations.has(command)) {
|
|
8769
|
+
commandInvocations.set(command, (commandInvocations.get(command) ?? 0) + 1);
|
|
8770
|
+
}
|
|
8771
|
+
for (const observer of commandObservers.get(command) ?? [])
|
|
8772
|
+
observer(args);
|
|
8773
|
+
commandCaptureMetrics?.started(command, args);
|
|
8774
|
+
try {
|
|
8775
|
+
const { stdout, stderr } = await executeCommandBytes(command, args, options, timeoutMs, outputLimit, stderrLimit);
|
|
8776
|
+
commandCaptureMetrics?.capturedBytes(stdout.length);
|
|
8777
|
+
return {
|
|
8778
|
+
stdout: Buffer.isBuffer(stdout) ? stdout : Buffer.from(stdout),
|
|
8779
|
+
stderr: Buffer.isBuffer(stderr) ? stderr : Buffer.from(stderr)
|
|
8780
|
+
};
|
|
8781
|
+
} catch (error) {
|
|
8782
|
+
const outcome = commandFailureOutcome(error);
|
|
8783
|
+
const redacting = options.redactValues?.some((value) => typeof value === "string" && value.length > 0);
|
|
8784
|
+
if (error && typeof error === "object" && "stdout" in error && "stderr" in error) {
|
|
8785
|
+
const withOutput = error;
|
|
8786
|
+
const stderr = withOutput.stderr?.toString() ?? "";
|
|
8787
|
+
const stdout = withOutput.stdout?.toString() ?? "";
|
|
8788
|
+
const message = (stderr || stdout || withOutput.message || "Command failed").trim();
|
|
8789
|
+
throw new CommandFailedError(redactCommandValues(message, options.redactValues), {
|
|
8790
|
+
...outcome,
|
|
8791
|
+
stdout: redactCommandValues(stdout, options.redactValues),
|
|
8792
|
+
stderr: redactCommandValues(stderr, options.redactValues),
|
|
8793
|
+
...!redacting && Buffer.isBuffer(withOutput.stdout) ? { stdoutBytes: withOutput.stdout } : {}
|
|
8794
|
+
});
|
|
8795
|
+
}
|
|
8796
|
+
if (redacting) {
|
|
8797
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
8798
|
+
throw new CommandFailedError(redactCommandValues(message || "Command failed", options.redactValues), outcome);
|
|
8799
|
+
}
|
|
8800
|
+
if (outcome.timedOut || outcome.executableMissing) {
|
|
8801
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
8802
|
+
throw new CommandFailedError(message || "Command failed", outcome);
|
|
8803
|
+
}
|
|
8804
|
+
throw error;
|
|
8805
|
+
}
|
|
8806
|
+
}
|
|
8807
|
+
async function runCommand(command, args = [], options = {}) {
|
|
8808
|
+
const { stdout, stderr } = await runCommandBytes(command, args, options);
|
|
8809
|
+
return {
|
|
8810
|
+
stdout: redactCommandValues(stdout.toString(), options.redactValues),
|
|
8811
|
+
stderr: redactCommandValues(stderr.toString(), options.redactValues)
|
|
8812
|
+
};
|
|
8813
|
+
}
|
|
8814
|
+
|
|
8815
|
+
// ../protocol/src/node/workspace-change-probe.ts
|
|
7865
8816
|
var DEFAULT_MAX_UNTRACKED_FILE_BYTES = 2 * 1024 * 1024;
|
|
7866
8817
|
var DEFAULT_MAX_UNTRACKED_FILES = 5000;
|
|
7867
8818
|
var DEFAULT_SLOW_SNAPSHOT_MS = 500;
|
|
@@ -7879,27 +8830,16 @@ process.once("exit", () => {
|
|
|
7879
8830
|
} catch {}
|
|
7880
8831
|
}
|
|
7881
8832
|
});
|
|
7882
|
-
var runGit = (args, options) =>
|
|
7883
|
-
const
|
|
7884
|
-
|
|
7885
|
-
|
|
7886
|
-
|
|
7887
|
-
|
|
7888
|
-
|
|
7889
|
-
let stdout = "";
|
|
7890
|
-
let stdoutBytes = 0;
|
|
7891
|
-
child.stdout.setEncoding("utf8");
|
|
7892
|
-
child.stdout.on("data", (chunk) => {
|
|
7893
|
-
stdoutBytes += chunk.length;
|
|
7894
|
-
if (stdoutBytes <= GIT_MAX_BUFFER)
|
|
7895
|
-
stdout += chunk;
|
|
8833
|
+
var runGit = async (args, options) => {
|
|
8834
|
+
const { stdout } = await runCommand("git", args, {
|
|
8835
|
+
cwd: options.cwd,
|
|
8836
|
+
env: { ...process.env, ...options.env, GIT_OPTIONAL_LOCKS: "0" },
|
|
8837
|
+
timeoutMs: GIT_TIMEOUT_MS,
|
|
8838
|
+
maxOutputBytes: GIT_MAX_BUFFER,
|
|
8839
|
+
...options.stdin === undefined ? {} : { stdin: options.stdin }
|
|
7896
8840
|
});
|
|
7897
|
-
|
|
7898
|
-
|
|
7899
|
-
child.on("close", (code) => code === 0 ? resolvePromise({ stdout }) : reject(new Error(`git exited with ${code}`)));
|
|
7900
|
-
child.stdin.on("error", () => {});
|
|
7901
|
-
child.stdin.end(options.stdin);
|
|
7902
|
-
});
|
|
8841
|
+
return { stdout };
|
|
8842
|
+
};
|
|
7903
8843
|
|
|
7904
8844
|
class WorkspaceChangeProbe {
|
|
7905
8845
|
git;
|
|
@@ -8187,7 +9127,7 @@ class WorkspaceChangeProbe {
|
|
|
8187
9127
|
return;
|
|
8188
9128
|
const { root, indexPath } = repo.location;
|
|
8189
9129
|
const started = this.now();
|
|
8190
|
-
const tempIndex = join(this.tempDir, `orkestrator-probe-${
|
|
9130
|
+
const tempIndex = join(this.tempDir, `orkestrator-probe-${randomUUID2()}.index`);
|
|
8191
9131
|
const objectDirectory = await mkdtemp(join(this.tempDir, "orkestrator-probe-objects-"));
|
|
8192
9132
|
temporaryObjectDirectories.add(objectDirectory);
|
|
8193
9133
|
let retained = false;
|
|
@@ -8958,10 +9898,10 @@ function registerSessionActivityBatchRoute(app, runtime) {
|
|
|
8958
9898
|
}
|
|
8959
9899
|
|
|
8960
9900
|
// ../../bridges/codex-bridge/src/transcript-routes.ts
|
|
8961
|
-
import { randomUUID as
|
|
9901
|
+
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
8962
9902
|
|
|
8963
9903
|
// ../protocol/src/node/revised-rows.ts
|
|
8964
|
-
import { createHash as
|
|
9904
|
+
import { createHash as createHash3 } from "node:crypto";
|
|
8965
9905
|
var RECENTLY_REVISED_ROWS_MAX = 128;
|
|
8966
9906
|
|
|
8967
9907
|
class RecentlyRevisedRows {
|
|
@@ -8999,7 +9939,7 @@ class RecentlyRevisedRows {
|
|
|
8999
9939
|
function revisedRowsReconciliationToken(overflowVersion, omitted) {
|
|
9000
9940
|
if (overflowVersion === 0 && omitted.length === 0)
|
|
9001
9941
|
return;
|
|
9002
|
-
const digest =
|
|
9942
|
+
const digest = createHash3("sha256").update(String(overflowVersion));
|
|
9003
9943
|
for (const row of omitted)
|
|
9004
9944
|
digest.update(JSON.stringify(row) ?? "null");
|
|
9005
9945
|
return digest.digest("hex");
|
|
@@ -9007,7 +9947,7 @@ function revisedRowsReconciliationToken(overflowVersion, omitted) {
|
|
|
9007
9947
|
|
|
9008
9948
|
// ../protocol/src/node/bridge-transcript-summary.ts
|
|
9009
9949
|
import { Buffer as Buffer3 } from "node:buffer";
|
|
9010
|
-
import { createHash as
|
|
9950
|
+
import { createHash as createHash4 } from "node:crypto";
|
|
9011
9951
|
|
|
9012
9952
|
// ../protocol/src/node/progressive-transcript.ts
|
|
9013
9953
|
var BRIDGE_TRANSCRIPT_MAX_MESSAGES = 100;
|
|
@@ -9173,7 +10113,7 @@ function digestPayload(payload) {
|
|
|
9173
10113
|
const serialized = JSON.stringify(payload);
|
|
9174
10114
|
return {
|
|
9175
10115
|
bytes: Buffer3.byteLength(serialized),
|
|
9176
|
-
digest:
|
|
10116
|
+
digest: createHash4("sha256").update(serialized).digest("base64url").slice(0, 32)
|
|
9177
10117
|
};
|
|
9178
10118
|
}
|
|
9179
10119
|
function topLevelKey(part, index) {
|
|
@@ -9567,7 +10507,7 @@ function changeEvidenceAckRouteBody(spool, body) {
|
|
|
9567
10507
|
}
|
|
9568
10508
|
|
|
9569
10509
|
// ../../bridges/codex-bridge/src/transcript-routes.ts
|
|
9570
|
-
var TRANSCRIPT_PROCESS =
|
|
10510
|
+
var TRANSCRIPT_PROCESS = randomUUID3();
|
|
9571
10511
|
function codexTranscriptSource(runtime, sessionId) {
|
|
9572
10512
|
const status = runtime.getStatus(sessionId, false);
|
|
9573
10513
|
const cached = runtime.getCachedMessages(sessionId);
|
|
@@ -9618,7 +10558,7 @@ function registerCodexChangeEvidenceRoutes(app, spool) {
|
|
|
9618
10558
|
}
|
|
9619
10559
|
|
|
9620
10560
|
// ../../bridges/codex-bridge/src/change-evidence.ts
|
|
9621
|
-
import { createHash as
|
|
10561
|
+
import { createHash as createHash6 } from "node:crypto";
|
|
9622
10562
|
import { existsSync as existsSync2 } from "node:fs";
|
|
9623
10563
|
import { basename, join as join8 } from "node:path";
|
|
9624
10564
|
|
|
@@ -10025,8 +10965,8 @@ function workspaceObservationReportIssues(value) {
|
|
|
10025
10965
|
}
|
|
10026
10966
|
|
|
10027
10967
|
// ../protocol/src/node/change-tracking/evidence-spool.ts
|
|
10028
|
-
import { createHash as
|
|
10029
|
-
import { readdirSync, readFileSync } from "node:fs";
|
|
10968
|
+
import { createHash as createHash5, randomUUID as randomUUID4 } from "node:crypto";
|
|
10969
|
+
import { readdirSync as readdirSync2, readFileSync as readFileSync2 } from "node:fs";
|
|
10030
10970
|
import { appendFile, mkdir, rename, rm as rm2, writeFile } from "node:fs/promises";
|
|
10031
10971
|
import { join as join3 } from "node:path";
|
|
10032
10972
|
var DEFAULT_EVIDENCE_SPOOL_LIMITS = {
|
|
@@ -10041,10 +10981,10 @@ var DEFAULT_EVIDENCE_SPOOL_LIMITS = {
|
|
|
10041
10981
|
var ENTRIES_FILE = "entries.jsonl";
|
|
10042
10982
|
var BODY_DIRECTORY = "bodies";
|
|
10043
10983
|
function evidenceBodyId(bytes) {
|
|
10044
|
-
return `sha256:${
|
|
10984
|
+
return `sha256:${createHash5("sha256").update(bytes).digest("hex")}`;
|
|
10045
10985
|
}
|
|
10046
10986
|
function stableEvidenceId(...parts) {
|
|
10047
|
-
const hash =
|
|
10987
|
+
const hash = createHash5("sha256");
|
|
10048
10988
|
for (const part of parts)
|
|
10049
10989
|
hash.update(`${part ?? ""}\x00`);
|
|
10050
10990
|
return hash.digest("hex").slice(0, 40);
|
|
@@ -10071,7 +11011,7 @@ class ChangeEvidenceSpool {
|
|
|
10071
11011
|
restoring = false;
|
|
10072
11012
|
constructor(options = {}) {
|
|
10073
11013
|
this.limits = { ...DEFAULT_EVIDENCE_SPOOL_LIMITS, ...options.limits };
|
|
10074
|
-
this.runtimeEpoch = options.runtimeEpoch ??
|
|
11014
|
+
this.runtimeEpoch = options.runtimeEpoch ?? randomUUID4();
|
|
10075
11015
|
this.directory = options.directory;
|
|
10076
11016
|
if (this.directory) {
|
|
10077
11017
|
this.restoring = true;
|
|
@@ -10174,7 +11114,7 @@ class ChangeEvidenceSpool {
|
|
|
10174
11114
|
return;
|
|
10175
11115
|
if (this.entries.length >= this.limits.maxEntries - 1)
|
|
10176
11116
|
return;
|
|
10177
|
-
const gapId =
|
|
11117
|
+
const gapId = randomUUID4();
|
|
10178
11118
|
const coverage = this.droppedUnknown ? {
|
|
10179
11119
|
kind: "unknown-range",
|
|
10180
11120
|
bindingId: this.gapBindingId || "unknown",
|
|
@@ -10336,8 +11276,8 @@ class ChangeEvidenceSpool {
|
|
|
10336
11276
|
restore(directory) {
|
|
10337
11277
|
const bodyDirectory = join3(directory, BODY_DIRECTORY);
|
|
10338
11278
|
try {
|
|
10339
|
-
for (const name of
|
|
10340
|
-
const bytes = new Uint8Array(
|
|
11279
|
+
for (const name of readdirSync2(bodyDirectory)) {
|
|
11280
|
+
const bytes = new Uint8Array(readFileSync2(join3(bodyDirectory, name)));
|
|
10341
11281
|
const id = evidenceBodyId(bytes);
|
|
10342
11282
|
if (bodyFileName(id) !== name)
|
|
10343
11283
|
continue;
|
|
@@ -10349,7 +11289,7 @@ class ChangeEvidenceSpool {
|
|
|
10349
11289
|
} catch {}
|
|
10350
11290
|
let text = "";
|
|
10351
11291
|
try {
|
|
10352
|
-
text =
|
|
11292
|
+
text = readFileSync2(join3(directory, ENTRIES_FILE), "utf8");
|
|
10353
11293
|
} catch {
|
|
10354
11294
|
return;
|
|
10355
11295
|
}
|
|
@@ -11251,12 +12191,12 @@ async function inheritCommandChanges(codexHome, parentThreadId, forkThreadId, me
|
|
|
11251
12191
|
}
|
|
11252
12192
|
|
|
11253
12193
|
// ../../bridges/codex-bridge/src/change-evidence-migration.ts
|
|
11254
|
-
import { randomUUID as
|
|
12194
|
+
import { randomUUID as randomUUID5 } from "node:crypto";
|
|
11255
12195
|
import {
|
|
11256
12196
|
existsSync,
|
|
11257
12197
|
mkdirSync,
|
|
11258
|
-
readFileSync as
|
|
11259
|
-
readdirSync as
|
|
12198
|
+
readFileSync as readFileSync3,
|
|
12199
|
+
readdirSync as readdirSync3,
|
|
11260
12200
|
renameSync,
|
|
11261
12201
|
rmSync as rmSync2,
|
|
11262
12202
|
statSync,
|
|
@@ -11267,13 +12207,13 @@ import { isDeepStrictEqual } from "node:util";
|
|
|
11267
12207
|
function readBounded(path, limit) {
|
|
11268
12208
|
if (statSync(path).size > limit)
|
|
11269
12209
|
throw new Error("Evidence migration exceeds storage capacity");
|
|
11270
|
-
const bytes =
|
|
12210
|
+
const bytes = readFileSync3(path);
|
|
11271
12211
|
if (bytes.length > limit)
|
|
11272
12212
|
throw new Error("Evidence migration exceeds storage capacity");
|
|
11273
12213
|
return bytes;
|
|
11274
12214
|
}
|
|
11275
12215
|
function publishFile(path, contents) {
|
|
11276
|
-
const temporary = `${path}.${
|
|
12216
|
+
const temporary = `${path}.${randomUUID5()}.tmp`;
|
|
11277
12217
|
try {
|
|
11278
12218
|
writeFileSync(temporary, contents, { mode: 384 });
|
|
11279
12219
|
renameSync(temporary, path);
|
|
@@ -11344,7 +12284,7 @@ function migrateCodexChangeEvidence(legacy, shared) {
|
|
|
11344
12284
|
publishFile(target, bytes);
|
|
11345
12285
|
}
|
|
11346
12286
|
const retainedNames = new Set([...bodyIds].map((id) => id.replace(/[^A-Za-z0-9]/g, "_")));
|
|
11347
|
-
for (const name of
|
|
12287
|
+
for (const name of readdirSync3(join7(shared, "bodies"))) {
|
|
11348
12288
|
if (/^sha256_[a-f0-9]{64}$/.test(name) && !retainedNames.has(name)) {
|
|
11349
12289
|
rmSync2(join7(shared, "bodies", name));
|
|
11350
12290
|
}
|
|
@@ -11589,7 +12529,7 @@ function suppliedMovePath(change) {
|
|
|
11589
12529
|
return supplied?.kind === "update" ? supplied.movePath : change.move_path;
|
|
11590
12530
|
}
|
|
11591
12531
|
function codexChangeEvidenceDir(codexHome, cwd) {
|
|
11592
|
-
const cwdHash =
|
|
12532
|
+
const cwdHash = createHash6("sha256").update(cwd).digest("hex").slice(0, 16);
|
|
11593
12533
|
return join8(codexBridgeStateDir(codexHome), "change-evidence", cwdHash);
|
|
11594
12534
|
}
|
|
11595
12535
|
function createCodexChangeEvidence(options) {
|
|
@@ -12191,6 +13131,18 @@ function toBridgeModel(model) {
|
|
|
12191
13131
|
}
|
|
12192
13132
|
// ../protocol/src/human-prompts.ts
|
|
12193
13133
|
var HUMAN_PROMPT_SCAN_BYTES = 16 * 1024;
|
|
13134
|
+
var HUMAN_PROMPT_KINDS = new Set([
|
|
13135
|
+
"sign-in",
|
|
13136
|
+
"device-code",
|
|
13137
|
+
"press-enter",
|
|
13138
|
+
"secret",
|
|
13139
|
+
"host-key"
|
|
13140
|
+
]);
|
|
13141
|
+
var HUMAN_PROMPT_SOURCES = new Set([
|
|
13142
|
+
"user-command",
|
|
13143
|
+
"agent-tool",
|
|
13144
|
+
"agent-background-task"
|
|
13145
|
+
]);
|
|
12194
13146
|
var HUMAN_PROMPT_OBSERVATION_ROWS = 64;
|
|
12195
13147
|
function humanPromptObservation(messages, tasks) {
|
|
12196
13148
|
const object = (value) => !!value && typeof value === "object" && !Array.isArray(value);
|
|
@@ -12242,14 +13194,17 @@ function humanPromptObservation(messages, tasks) {
|
|
|
12242
13194
|
return { messages: [{ parts }], backgroundTasks };
|
|
12243
13195
|
}
|
|
12244
13196
|
|
|
13197
|
+
// ../protocol/src/agent-usage-limits.ts
|
|
13198
|
+
var USAGE_LIMIT_ERROR_CODE = "usage-limit";
|
|
13199
|
+
|
|
12245
13200
|
// ../../bridges/codex-bridge/src/sessions/typed-prompts.ts
|
|
12246
|
-
import { createHash as
|
|
13201
|
+
import { createHash as createHash7, randomUUID as randomUUID6 } from "node:crypto";
|
|
12247
13202
|
import { mkdir as mkdir4, open, opendir, rename as rename3, rm as rm4, writeFile as writeFile3 } from "node:fs/promises";
|
|
12248
13203
|
import { dirname as dirname2, join as join10 } from "node:path";
|
|
12249
13204
|
var MAX_TYPED_PROMPT_CHARS = 32000;
|
|
12250
13205
|
var MAX_RECORD_BYTES = 6 * MAX_TYPED_PROMPT_CHARS + 2048;
|
|
12251
13206
|
function typedPromptDigest(sentText) {
|
|
12252
|
-
return
|
|
13207
|
+
return createHash7("sha256").update(sentText.trim()).digest("hex");
|
|
12253
13208
|
}
|
|
12254
13209
|
function typedPromptFor(record, sentText) {
|
|
12255
13210
|
return record?.sent === typedPromptDigest(sentText) ? record.typed : undefined;
|
|
@@ -12287,7 +13242,7 @@ var writes = new Map;
|
|
|
12287
13242
|
async function writeRecord(path, record) {
|
|
12288
13243
|
const pending = (writes.get(path) ?? Promise.resolve()).then(async () => {
|
|
12289
13244
|
await mkdir4(dirname2(path), { recursive: true, mode: 448 });
|
|
12290
|
-
const temp = `${path}.${
|
|
13245
|
+
const temp = `${path}.${randomUUID6()}.tmp`;
|
|
12291
13246
|
try {
|
|
12292
13247
|
await writeFile3(temp, JSON.stringify(record), { mode: 384, flag: "wx" });
|
|
12293
13248
|
await rename3(temp, path);
|
|
@@ -14469,7 +15424,7 @@ async function deriveTranscriptSubagentPartsForTurn({
|
|
|
14469
15424
|
}
|
|
14470
15425
|
|
|
14471
15426
|
// ../../bridges/codex-bridge/src/history/rollout.ts
|
|
14472
|
-
import { createHash as
|
|
15427
|
+
import { createHash as createHash8 } from "node:crypto";
|
|
14473
15428
|
import { readdir, stat as stat5 } from "node:fs/promises";
|
|
14474
15429
|
import { homedir } from "node:os";
|
|
14475
15430
|
import { basename as basename2, join as join11 } from "node:path";
|
|
@@ -16302,6 +17257,8 @@ function codeModeMcpCallPart(call, toolUseId) {
|
|
|
16302
17257
|
|
|
16303
17258
|
// ../protocol/src/coordinator.ts
|
|
16304
17259
|
var COORDINATOR_CODEX_USER_SKILLS_DIR_ENV = "ORKESTRATOR_COORDINATOR_CODEX_USER_SKILLS_DIR";
|
|
17260
|
+
var COORDINATOR_OTHER_ENVIRONMENTS_SETTING_LABEL = "Let the coordinator use environments it did not create";
|
|
17261
|
+
var COORDINATOR_ENVIRONMENT_ORIGIN_REFUSAL = `Not done: this coordinator did not create that environment, so it may not send it work. Do not retry. Use an environment this coordinator launched, or start a new one. If the user wants this coordinator to work in environments it did not create, tell them to turn on "${COORDINATOR_OTHER_ENVIRONMENTS_SETTING_LABEL}" in this project's settings, under Coordinator.`;
|
|
16305
17262
|
var COORDINATOR_CONTROL_TOOL_NAMES = Object.freeze([
|
|
16306
17263
|
"ack_message",
|
|
16307
17264
|
"add_ticket_comment",
|
|
@@ -16341,13 +17298,11 @@ var COORDINATOR_CONTROL_TOOL_NAMES = Object.freeze([
|
|
|
16341
17298
|
"launch_graph",
|
|
16342
17299
|
"launch_job",
|
|
16343
17300
|
"launch_multi_review",
|
|
16344
|
-
"launch_node_environment",
|
|
16345
17301
|
"launch_terminal",
|
|
16346
17302
|
"list_agents",
|
|
16347
17303
|
"list_environments",
|
|
16348
17304
|
"list_graph_templates",
|
|
16349
17305
|
"list_mailboxes",
|
|
16350
|
-
"list_node_environments",
|
|
16351
17306
|
"list_nodes",
|
|
16352
17307
|
"list_projects",
|
|
16353
17308
|
"list_provider_accounts",
|
|
@@ -16376,16 +17331,11 @@ var COORDINATOR_CONTROL_TOOL_NAMES = Object.freeze([
|
|
|
16376
17331
|
"resume_schedule",
|
|
16377
17332
|
"run_worker_command",
|
|
16378
17333
|
"send_message",
|
|
16379
|
-
"send_node_message",
|
|
16380
|
-
"send_prompt_to_node_tab",
|
|
16381
17334
|
"send_prompt_to_tab",
|
|
16382
17335
|
"set_worker_goal",
|
|
16383
17336
|
"start_build_pipeline",
|
|
16384
17337
|
"start_environment",
|
|
16385
|
-
"start_multi_review",
|
|
16386
|
-
"start_node_environment",
|
|
16387
17338
|
"stop_environment",
|
|
16388
|
-
"stop_node_environment",
|
|
16389
17339
|
"stop_worker_turn",
|
|
16390
17340
|
"switch_provider_account",
|
|
16391
17341
|
"set_account_auto_switch",
|
|
@@ -16778,7 +17728,7 @@ async function readSessionIndex(path) {
|
|
|
16778
17728
|
}
|
|
16779
17729
|
|
|
16780
17730
|
// ../../bridges/codex-bridge/src/history/rollout.ts
|
|
16781
|
-
var
|
|
17731
|
+
var log5 = createLogger("bridge.codex");
|
|
16782
17732
|
function getCodexHomeDir() {
|
|
16783
17733
|
return process.env.CODEX_HOME || join11(homedir(), ".codex");
|
|
16784
17734
|
}
|
|
@@ -17347,7 +18297,7 @@ async function hydrateMessagesFromPersistedSession(threadId, options = {}) {
|
|
|
17347
18297
|
};
|
|
17348
18298
|
}
|
|
17349
18299
|
}
|
|
17350
|
-
|
|
18300
|
+
log5.warn("rollout.hydrate-failed", { threadId });
|
|
17351
18301
|
return {
|
|
17352
18302
|
messages: [],
|
|
17353
18303
|
title: meta.title,
|
|
@@ -17371,7 +18321,7 @@ var NON_TOOL_TURN_ITEM_TYPES = new Set([
|
|
|
17371
18321
|
]);
|
|
17372
18322
|
var MAX_OPEN_CODE_MODE_CELLS = 256;
|
|
17373
18323
|
function replayedRowId(threadId, scope, kind, ordinal) {
|
|
17374
|
-
const digest =
|
|
18324
|
+
const digest = createHash8("sha256").update(`${threadId}\x00${scope}\x00${kind}\x00${ordinal}`).digest("hex");
|
|
17375
18325
|
return `msg-r-${digest.slice(0, 32)}`;
|
|
17376
18326
|
}
|
|
17377
18327
|
async function forEachHistoryBatch(snapshot, visit) {
|
|
@@ -17836,7 +18786,7 @@ async function replayPersistedRollout(threadId, snapshot, meta, structuredTurns)
|
|
|
17836
18786
|
}
|
|
17837
18787
|
|
|
17838
18788
|
// ../../bridges/codex-bridge/src/messages/render-turn.ts
|
|
17839
|
-
var
|
|
18789
|
+
var log6 = createLogger("bridge.codex");
|
|
17840
18790
|
var TRUNCATION_NOTICE = `
|
|
17841
18791
|
… output truncated`;
|
|
17842
18792
|
var SUBAGENT_TRANSCRIPT_PROBE_INTERVAL_MS = 2000;
|
|
@@ -18257,7 +19207,7 @@ async function renderTurn(turn, options) {
|
|
|
18257
19207
|
loadSnapshot = latestSnapshot;
|
|
18258
19208
|
}
|
|
18259
19209
|
} catch (error) {
|
|
18260
|
-
|
|
19210
|
+
log6.warn("subagent.activity-load-failed", { error: formatLogError(error) });
|
|
18261
19211
|
}
|
|
18262
19212
|
}
|
|
18263
19213
|
const { items, itemsByKey, accumulatorsByKey, versionsByKey, itemKeys } = collectTurnItems(turn, options.segment);
|
|
@@ -18648,7 +19598,7 @@ async function publishAssistantRows(context, state, turn, options) {
|
|
|
18648
19598
|
}
|
|
18649
19599
|
|
|
18650
19600
|
// ../../bridges/codex-bridge/src/app-server-runtime-sessions.ts
|
|
18651
|
-
import { createHash as
|
|
19601
|
+
import { createHash as createHash13, randomUUID as randomUUID9 } from "node:crypto";
|
|
18652
19602
|
|
|
18653
19603
|
// ../protocol/src/agent-mail.ts
|
|
18654
19604
|
var AGENT_MAIL_MAX_BODY_BYTES = 32 * 1024;
|
|
@@ -18702,10 +19652,178 @@ function agentMailCapabilities(tabType, agent, locked = true) {
|
|
|
18702
19652
|
}
|
|
18703
19653
|
var NATIVE_AGENT_MAIL_CAPABILITIES = Object.freeze(Object.fromEntries(AGENT_PLATFORMS.map((agent) => [agent, agentMailCapabilities("agent-native", agent)])));
|
|
18704
19654
|
|
|
19655
|
+
// ../protocol/src/rich-content-policy.ts
|
|
19656
|
+
var KIB = 1024;
|
|
19657
|
+
var MIB = 1024 * KIB;
|
|
19658
|
+
var CODE_BLOCK_POLICY = {
|
|
19659
|
+
maxHighlightBytes: 32 * KIB,
|
|
19660
|
+
maxHighlightLines: 2000,
|
|
19661
|
+
initialVisualLines: 24
|
|
19662
|
+
};
|
|
19663
|
+
var MERMAID_POLICY = {
|
|
19664
|
+
maxSourceBytes: 32 * KIB,
|
|
19665
|
+
maxEdges: 250,
|
|
19666
|
+
maxSvgBytes: 1 * MIB,
|
|
19667
|
+
maxSvgElements: 5000,
|
|
19668
|
+
renderTimeoutMs: 5000
|
|
19669
|
+
};
|
|
19670
|
+
var CHART_POLICY = {
|
|
19671
|
+
maxPayloadBytes: 256 * KIB,
|
|
19672
|
+
maxSeries: 6,
|
|
19673
|
+
maxBarCategories: 100,
|
|
19674
|
+
maxCartesianPoints: 2000,
|
|
19675
|
+
maxDonutSlices: 24,
|
|
19676
|
+
maxTitleCharacters: 200,
|
|
19677
|
+
maxLabelCharacters: 200,
|
|
19678
|
+
maxDescriptionCharacters: 2000,
|
|
19679
|
+
maxSourceNotes: 8,
|
|
19680
|
+
maxSourceNoteCharacters: 500,
|
|
19681
|
+
maxIdCharacters: 64,
|
|
19682
|
+
maxUnitCharacters: 32,
|
|
19683
|
+
maxAbsoluteValue: 1000000000000000,
|
|
19684
|
+
maxJsonDepth: 16
|
|
19685
|
+
};
|
|
19686
|
+
var WORKFLOW_SNAPSHOT_POLICY = {
|
|
19687
|
+
maxNormalizedBytes: 256 * KIB,
|
|
19688
|
+
maxNodes: 200,
|
|
19689
|
+
maxEdges: 400,
|
|
19690
|
+
maxIdCharacters: 128,
|
|
19691
|
+
maxLabelCharacters: 200,
|
|
19692
|
+
maxDescriptionCharacters: 2000,
|
|
19693
|
+
maxRawStatusCharacters: 100,
|
|
19694
|
+
maxLinksPerNode: 8
|
|
19695
|
+
};
|
|
19696
|
+
var STATIC_HTML_POLICY = {
|
|
19697
|
+
maxSourceBytes: 256 * KIB,
|
|
19698
|
+
maxPreparedBytes: 16 * MIB,
|
|
19699
|
+
maxElements: 5000
|
|
19700
|
+
};
|
|
19701
|
+
var STATIC_PRESENTATION_POLICY = {
|
|
19702
|
+
maxDocumentBytes: STATIC_HTML_POLICY.maxSourceBytes,
|
|
19703
|
+
maxElements: STATIC_HTML_POLICY.maxElements,
|
|
19704
|
+
maxFramesPerWindow: 4,
|
|
19705
|
+
renderTimeoutMs: 15000,
|
|
19706
|
+
maxSizeChangesPerWindow: 16,
|
|
19707
|
+
sizeChangeWindowMs: 5000,
|
|
19708
|
+
maxRefusedMessages: 100,
|
|
19709
|
+
maxSearchTextCharacters: 64 * KIB,
|
|
19710
|
+
searchTextChunkCharacters: 2 * KIB
|
|
19711
|
+
};
|
|
19712
|
+
var INTERACTIVE_HTML_POLICY = {
|
|
19713
|
+
maxAuthoredBytes: 512 * KIB,
|
|
19714
|
+
maxAssets: 32,
|
|
19715
|
+
maxAssetBytesTotal: 10 * MIB,
|
|
19716
|
+
maxDependencies: 4,
|
|
19717
|
+
maxPreparedBytes: 16 * MIB,
|
|
19718
|
+
maxRuntimeElements: 1e4,
|
|
19719
|
+
maxProbeSteps: 20,
|
|
19720
|
+
maxProbeStepMs: 2000,
|
|
19721
|
+
defaultWaitVisibleMs: 1000,
|
|
19722
|
+
maxProbeTextCharacters: 1024,
|
|
19723
|
+
probeTargetPattern: /^[A-Za-z][A-Za-z0-9_-]{0,63}$/
|
|
19724
|
+
};
|
|
19725
|
+
var PREVIEW_CAPTURE_POLICY = {
|
|
19726
|
+
maxPngBytes: 8 * MIB,
|
|
19727
|
+
maxPixels: 12000000,
|
|
19728
|
+
maxDimension: 4096,
|
|
19729
|
+
minDimension: 240,
|
|
19730
|
+
maxCapturesPerReceipt: 3,
|
|
19731
|
+
defaultViewport: { width: 960, height: 640, deviceScaleFactor: 1 }
|
|
19732
|
+
};
|
|
19733
|
+
var PREVIEW_ADMISSION_POLICY = {
|
|
19734
|
+
runningPerEnvironment: 1,
|
|
19735
|
+
runningGlobal: 2,
|
|
19736
|
+
queuedPerEnvironment: 8,
|
|
19737
|
+
queuedGlobal: 16,
|
|
19738
|
+
nonterminalPerConversation: 2,
|
|
19739
|
+
queuedMetadataBytesGlobal: 8 * MIB,
|
|
19740
|
+
queueWaitMs: 15000,
|
|
19741
|
+
workerWallMs: 30000,
|
|
19742
|
+
readinessMs: 5000,
|
|
19743
|
+
operationDeadlineMs: 45000,
|
|
19744
|
+
cleanupGraceMs: 2000,
|
|
19745
|
+
workerMemoryBytes: 1024 * MIB,
|
|
19746
|
+
workerCpus: 2,
|
|
19747
|
+
workerPids: 128
|
|
19748
|
+
};
|
|
19749
|
+
var FRONTEND_RENDER_POLICY = {
|
|
19750
|
+
highlightConcurrency: 2,
|
|
19751
|
+
diagramConcurrency: 1,
|
|
19752
|
+
maxQueuedJobs: 32,
|
|
19753
|
+
maxQueuedSourceBytes: 2 * MIB,
|
|
19754
|
+
maxSettledCacheEntries: 128,
|
|
19755
|
+
maxSettledCacheBytes: 16 * MIB,
|
|
19756
|
+
maxInactiveViewStateEntries: 500,
|
|
19757
|
+
maxActiveViewStateEntries: 200,
|
|
19758
|
+
maxPinnedViewStateEntries: 50,
|
|
19759
|
+
liveExecutableHostsPerWindow: 1,
|
|
19760
|
+
imageDecodeMaxPixels: 40000000,
|
|
19761
|
+
pdfPreviewMaxPages: 100,
|
|
19762
|
+
pdfPreviewMaxBytes: 20 * MIB
|
|
19763
|
+
};
|
|
19764
|
+
var PDF_POLICY = {
|
|
19765
|
+
maxPages: 100,
|
|
19766
|
+
maxBytes: 20 * MIB,
|
|
19767
|
+
thumbnailMaxDimension: 1024,
|
|
19768
|
+
thumbnailMaxPngBytes: 4 * MIB,
|
|
19769
|
+
imageDecodeMaxPixels: 40000000,
|
|
19770
|
+
printMarginMm: 10,
|
|
19771
|
+
previewCacheEntries: 32,
|
|
19772
|
+
previewCacheBytes: 16 * MIB
|
|
19773
|
+
};
|
|
19774
|
+
var DIAGNOSTIC_POLICY = {
|
|
19775
|
+
maxPersistedEntries: 50,
|
|
19776
|
+
maxEntryBytes: 2 * KIB,
|
|
19777
|
+
maxPersistedBytes: 32 * KIB,
|
|
19778
|
+
maxToolFieldErrors: 20,
|
|
19779
|
+
maxToolDiagnosticBytes: 8 * KIB
|
|
19780
|
+
};
|
|
19781
|
+
var ARTIFACT_TOOL_POLICY = {
|
|
19782
|
+
maxResultBytes: 16 * KIB,
|
|
19783
|
+
maxSourceSliceBytes: 8 * KIB,
|
|
19784
|
+
maxTitleCharacters: 120,
|
|
19785
|
+
maxSummaryCharacters: 400,
|
|
19786
|
+
maxRequestKeyCharacters: 128,
|
|
19787
|
+
maxRepairRevisions: 2,
|
|
19788
|
+
maxTransientRetries: 2,
|
|
19789
|
+
maxUnpublishedArtifactsPerConversation: 100,
|
|
19790
|
+
maxRevisionsPerArtifact: 100,
|
|
19791
|
+
assetStoreBytesPerEnvironment: 1024 * MIB,
|
|
19792
|
+
scopeCapabilityTtlMs: 24 * 60 * 60 * 1000
|
|
19793
|
+
};
|
|
19794
|
+
var ARTIFACT_RETENTION_POLICY = {
|
|
19795
|
+
cleanupIntervalMs: 60 * 60 * 1000,
|
|
19796
|
+
abandonedStagingMs: 60 * 60 * 1000,
|
|
19797
|
+
unpublishedDraftMs: 7 * 24 * 60 * 60 * 1000,
|
|
19798
|
+
unreferencedPreviewAssetMs: 24 * 60 * 60 * 1000
|
|
19799
|
+
};
|
|
19800
|
+
var FRAME_CHANNEL_POLICY = {
|
|
19801
|
+
maxMessageBytes: 8 * KIB,
|
|
19802
|
+
messagesPerSecond: 20,
|
|
19803
|
+
burst: 40,
|
|
19804
|
+
sizeUpdatesPerSecond: 4,
|
|
19805
|
+
minInlineHeight: 120,
|
|
19806
|
+
maxInlineHeight: 1600,
|
|
19807
|
+
maxLinkCharacters: 2048,
|
|
19808
|
+
maxLinkLabelCharacters: 200
|
|
19809
|
+
};
|
|
19810
|
+
|
|
18705
19811
|
// ../protocol/src/agent-system-instructions.ts
|
|
18706
|
-
var AGENT_IMAGE_PREVIEW_INSTRUCTION = "Orkestrator renders Markdown images inline in the transcript. When you show the user an image in your reply (a screenshot, rendered preview, or
|
|
19812
|
+
var AGENT_IMAGE_PREVIEW_INSTRUCTION = "Orkestrator renders Markdown images inline in the transcript. When you show the user an image in your reply (a photograph, screenshot, rendered preview, or a requested image file) using Markdown image syntax, reference it by its absolute path. In a managed worktree or container environment, save the file inside the working directory, preferably in a git-ignored folder so preview files stay out of the change set. Local image previews are limited to Orkestrator-managed workspace storage or the container's /workspace. Project-home checkouts are excluded from host preview reads, even when they are the working directory, so images saved there cannot be previewed from a local Markdown path. Paths outside previewable storage, such as /tmp, also show a placeholder.";
|
|
18707
19813
|
var AGENT_DOCUMENT_INSTRUCTION = "When the user asks for a document (a report, design doc, plan, analysis, guide, or other writing to keep), prefer writing it as a Markdown file in a `docs/` folder at the root of the working directory, and tell the user the file's path. Project instructions (such as AGENTS.md or CLAUDE.md), local skills, and the user's own request take priority over this default when they say where or how to write documents.";
|
|
19814
|
+
var AGENT_CHART_SPEC_SHAPES = "bar adds xAxis:{kind:'category',label}, yAxis:{label,unit?}, categories:[{id,label}], series:[{id,label,points:[{categoryId,value|null}]}] (one point per category); " + "line/area/scatter add xAxis:{kind:'number'|'utc-time',label,unit?}, yAxis:{label,unit?}, series:[{id,label,points:[{x,y|null}]}]; " + "donut adds valueLabel, unit?, slices:[{id,label,value}]";
|
|
19815
|
+
var AGENT_CHART_FENCE_EXAMPLE = '{"schemaVersion":1,"kind":"bar","title":"Passing tests","description":"Passing tests per suite.","xAxis":{"kind":"category","label":"Suite"},"yAxis":{"label":"Tests"},"categories":[{"id":"unit","label":"Unit"},{"id":"browser","label":"Browser"}],"series":[{"id":"passed","label":"Passed","points":[{"categoryId":"unit","value":40},{"categoryId":"browser","value":8}]}]}';
|
|
19816
|
+
var AGENT_VISUAL_OUTPUT_INSTRUCTION = [
|
|
19817
|
+
"Orkestrator displays rich visuals directly in the conversation; choose one when it helps answer the question.",
|
|
19818
|
+
`Flows, architecture, sequences and relationships: a \`mermaid\` code fence. Standard bar, line, area, scatter and donut charts: a \`chart\` code fence holding one ChartSpecV1 JSON object with schemaVersion 1, kind, title and description; ${AGENT_CHART_SPEC_SHAPES}. For example: ${AGENT_CHART_FENCE_EXAMPLE}.`,
|
|
19819
|
+
"When this session has the Orkestrator artifact tools, use them for durable visuals: create_artifact, preview_artifact, get_artifact_operation to inspect the diagnostics and capture, then publish_artifact, and respect their repair limits.",
|
|
19820
|
+
`A custom report, timeline or layout combining text and graphics is an html-static artifact: self-contained HTML, CSS and inline SVG, with no scripts or network resources. Its verified document is displayed in the transcript as real, selectable content, so keep it within ${STATIC_PRESENTATION_POLICY.maxDocumentBytes / 1024} KiB and ${STATIC_PRESENTATION_POLICY.maxElements} elements, use fluid widths, let content set the height (no 100vh on the root), and colour it with the --ork-foreground, --ork-muted-foreground, --ork-background, --ork-border, --ork-primary and --ork-chart-1 to --ork-chart-8 CSS variables, which follow the application theme. Always give them a fallback, such as var(--ork-foreground, #18181b), because the preview defines none of them.`,
|
|
19821
|
+
"Behaviour that needs authored JavaScript, such as a calculator or a filterable dashboard, is an html-interactive artifact; it runs when the reader activates it.",
|
|
19822
|
+
"Use ordinary images only for photographs, screenshots and requested image files.",
|
|
19823
|
+
"HTML, SVG and JavaScript code fences are shown as source and a file path alone publishes nothing: a visual is in the conversation only once publish_artifact succeeds. If verification is unavailable, say so and use a supported form such as a Mermaid or chart fence."
|
|
19824
|
+
].join(" ");
|
|
18708
19825
|
var GENERAL_AGENT_INSTRUCTIONS = [
|
|
19826
|
+
AGENT_VISUAL_OUTPUT_INSTRUCTION,
|
|
18709
19827
|
AGENT_IMAGE_PREVIEW_INSTRUCTION,
|
|
18710
19828
|
AGENT_DOCUMENT_INSTRUCTION
|
|
18711
19829
|
];
|
|
@@ -18816,12 +19934,12 @@ var ORKESTRATOR_ARTIFACT_MCP_PATH = "/artifact-mcp";
|
|
|
18816
19934
|
|
|
18817
19935
|
// ../../bridges/codex-bridge/src/engine/app-server-engine.ts
|
|
18818
19936
|
import { open as open9 } from "node:fs/promises";
|
|
18819
|
-
import { createHash as
|
|
19937
|
+
import { createHash as createHash12 } from "node:crypto";
|
|
18820
19938
|
import { isAbsolute as isAbsolute9, join as join20 } from "node:path";
|
|
18821
19939
|
|
|
18822
19940
|
// ../../bridges/codex-bridge/src/app-server/process-supervisor.ts
|
|
18823
|
-
import { execFile as
|
|
18824
|
-
import { randomUUID as
|
|
19941
|
+
import { execFile as execFile2, spawn as spawn2 } from "node:child_process";
|
|
19942
|
+
import { randomUUID as randomUUID7 } from "node:crypto";
|
|
18825
19943
|
import {
|
|
18826
19944
|
link,
|
|
18827
19945
|
mkdir as mkdir6,
|
|
@@ -19086,7 +20204,7 @@ function extractThreadId(params) {
|
|
|
19086
20204
|
}
|
|
19087
20205
|
|
|
19088
20206
|
// ../../bridges/codex-bridge/src/app-server/jsonl-rpc-client.ts
|
|
19089
|
-
var
|
|
20207
|
+
var log7 = createLogger("bridge.codex");
|
|
19090
20208
|
var DEFAULT_MAX_INBOUND_LINE_BYTES = 64 * 1024 * 1024;
|
|
19091
20209
|
var DEFAULT_MAX_OUTBOUND_LINE_BYTES = 32 * 1024 * 1024;
|
|
19092
20210
|
var DEFAULT_REQUEST_TIMEOUT_MS = 60000;
|
|
@@ -19198,7 +20316,7 @@ class JsonlRpcClient {
|
|
|
19198
20316
|
try {
|
|
19199
20317
|
this.options.recordInboundLine(line);
|
|
19200
20318
|
} catch (error) {
|
|
19201
|
-
|
|
20319
|
+
log7.error("recorder.threw", { error: formatLogError(error) });
|
|
19202
20320
|
}
|
|
19203
20321
|
}
|
|
19204
20322
|
const message = parseInboundLine(line);
|
|
@@ -19230,7 +20348,7 @@ class JsonlRpcClient {
|
|
|
19230
20348
|
try {
|
|
19231
20349
|
this.options.onServerRequest(message);
|
|
19232
20350
|
} catch (error) {
|
|
19233
|
-
|
|
20351
|
+
log7.error("server-request.handoff-failed", { error: formatLogError(error) });
|
|
19234
20352
|
}
|
|
19235
20353
|
return;
|
|
19236
20354
|
}
|
|
@@ -19239,7 +20357,7 @@ class JsonlRpcClient {
|
|
|
19239
20357
|
try {
|
|
19240
20358
|
this.options.onNotification(message, extractThreadId(message.params), Buffer.byteLength(line, "utf8"));
|
|
19241
20359
|
} catch (error) {
|
|
19242
|
-
|
|
20360
|
+
log7.error("notification.enqueue-failed", { error: formatLogError(error) });
|
|
19243
20361
|
}
|
|
19244
20362
|
return;
|
|
19245
20363
|
}
|
|
@@ -19421,7 +20539,7 @@ class SerialQueue {
|
|
|
19421
20539
|
run(key, task, bytes = 0) {
|
|
19422
20540
|
if (this.depth >= this.maxDepth || this.bytes + bytes > this.maxBytes) {
|
|
19423
20541
|
const overflow = { depth: this.depth, bytes: this.bytes };
|
|
19424
|
-
|
|
20542
|
+
log7.error("queue.overflow", overflow);
|
|
19425
20543
|
this.clear();
|
|
19426
20544
|
this.onOverflow?.(overflow);
|
|
19427
20545
|
return;
|
|
@@ -19501,16 +20619,16 @@ class SerialQueue {
|
|
|
19501
20619
|
queue.waiters.splice(0, resolved);
|
|
19502
20620
|
}
|
|
19503
20621
|
reportTaskFailure(key, error) {
|
|
19504
|
-
|
|
20622
|
+
log7.error("queue.task-failed", { key, error: formatLogError(error) });
|
|
19505
20623
|
}
|
|
19506
20624
|
}
|
|
19507
20625
|
|
|
19508
20626
|
// ../../bridges/codex-bridge/src/app-server/notification-recorder.ts
|
|
19509
20627
|
import { appendFile as appendFile4, mkdir as mkdir5 } from "node:fs/promises";
|
|
19510
20628
|
import { join as join13 } from "node:path";
|
|
19511
|
-
var
|
|
20629
|
+
var log8 = createLogger("bridge.codex");
|
|
19512
20630
|
function recorderNotice(message) {
|
|
19513
|
-
|
|
20631
|
+
log8.warn("recorder.notice", { detail: message });
|
|
19514
20632
|
}
|
|
19515
20633
|
var DEFAULT_MAX_RECORDING_BYTES = 64 * 1024 * 1024;
|
|
19516
20634
|
var DEFAULT_FLUSH_INTERVAL_MS = 250;
|
|
@@ -19623,7 +20741,7 @@ class NotificationRecorder {
|
|
|
19623
20741
|
} catch (error) {
|
|
19624
20742
|
this.stats.writeErrors += 1;
|
|
19625
20743
|
this.stats.linesDropped += pending.length;
|
|
19626
|
-
|
|
20744
|
+
log8.error("recorder.write-failed", { error: formatLogError(error, { stack: false }) });
|
|
19627
20745
|
}
|
|
19628
20746
|
}
|
|
19629
20747
|
async close() {
|
|
@@ -19656,10 +20774,10 @@ function createRecorderFromEnv(options) {
|
|
|
19656
20774
|
|
|
19657
20775
|
// ../../bridges/codex-bridge/src/runtime-env.ts
|
|
19658
20776
|
import { execFile as execFileCallback } from "node:child_process";
|
|
19659
|
-
import { createHash as
|
|
20777
|
+
import { createHash as createHash9 } from "node:crypto";
|
|
19660
20778
|
import { promisify } from "node:util";
|
|
19661
|
-
var
|
|
19662
|
-
var
|
|
20779
|
+
var log9 = createLogger("bridge.codex");
|
|
20780
|
+
var execFile = promisify(execFileCallback);
|
|
19663
20781
|
var RUNTIME_ENV_SCRIPT_ENV = "ORKESTRATOR_RUNTIME_ENV_SCRIPT";
|
|
19664
20782
|
var DEFAULT_RUNTIME_ENV_SCRIPT = "/usr/local/bin/orkestrator-runtime-env.sh";
|
|
19665
20783
|
var RUNTIME_ENV_CREDENTIAL_VARIABLES = new Set([
|
|
@@ -19721,7 +20839,7 @@ function applyRuntimeEnvironmentOutput(output) {
|
|
|
19721
20839
|
}
|
|
19722
20840
|
return updated;
|
|
19723
20841
|
}
|
|
19724
|
-
async function refreshRuntimeEnvironment(run =
|
|
20842
|
+
async function refreshRuntimeEnvironment(run = execFile) {
|
|
19725
20843
|
try {
|
|
19726
20844
|
const runtimeEnvScript = getRuntimeEnvironmentScriptPath();
|
|
19727
20845
|
const { stdout } = await run("/bin/sh", [
|
|
@@ -19736,14 +20854,14 @@ async function refreshRuntimeEnvironment(run = execFile2) {
|
|
|
19736
20854
|
});
|
|
19737
20855
|
const updated = applyRuntimeEnvironmentOutput(stdout);
|
|
19738
20856
|
if (updated.length > 0) {
|
|
19739
|
-
|
|
20857
|
+
log9.info("runtime-env.refreshed", { names: updated.join(", ") });
|
|
19740
20858
|
}
|
|
19741
20859
|
} catch (error) {
|
|
19742
|
-
|
|
20860
|
+
log9.warn("runtime-env.refresh-failed", { error: formatLogError(error) });
|
|
19743
20861
|
}
|
|
19744
20862
|
}
|
|
19745
20863
|
function fingerprintRuntimeEnvironment(env = process.env) {
|
|
19746
|
-
const hash =
|
|
20864
|
+
const hash = createHash9("sha256");
|
|
19747
20865
|
for (const name of [...RUNTIME_ENV_VARIABLES].sort()) {
|
|
19748
20866
|
hash.update(name);
|
|
19749
20867
|
hash.update("\x00");
|
|
@@ -19759,7 +20877,7 @@ function runtimeEnvironmentSnapshot(env = process.env) {
|
|
|
19759
20877
|
}
|
|
19760
20878
|
|
|
19761
20879
|
// ../../bridges/codex-bridge/src/app-server/process-supervisor.ts
|
|
19762
|
-
var
|
|
20880
|
+
var log10 = createLogger("bridge.codex");
|
|
19763
20881
|
|
|
19764
20882
|
class AppServerOwnershipUnavailableError extends AppServerUnavailableError {
|
|
19765
20883
|
ownershipContention = true;
|
|
@@ -19814,7 +20932,7 @@ class AppServerSupervisor {
|
|
|
19814
20932
|
unknownNotifications = 0;
|
|
19815
20933
|
unknownServerRequests = 0;
|
|
19816
20934
|
drainPromise = null;
|
|
19817
|
-
pidOwnerToken =
|
|
20935
|
+
pidOwnerToken = randomUUID7();
|
|
19818
20936
|
pidOwnershipHeld = false;
|
|
19819
20937
|
constructor(options) {
|
|
19820
20938
|
this.options = options;
|
|
@@ -19978,7 +21096,7 @@ class AppServerSupervisor {
|
|
|
19978
21096
|
if (this.stopping)
|
|
19979
21097
|
throw new AppServerUnavailableError("stopped");
|
|
19980
21098
|
const environmentFingerprint = this.fingerprintEnvironment();
|
|
19981
|
-
const instanceId =
|
|
21099
|
+
const instanceId = randomUUID7();
|
|
19982
21100
|
const instanceStartedAt = this.now();
|
|
19983
21101
|
if (this.options.pidFileEnabled !== false && !this.pidOwnershipHeld) {
|
|
19984
21102
|
const available = await this.acquirePidFileOwnership(instanceId);
|
|
@@ -20045,7 +21163,7 @@ class AppServerSupervisor {
|
|
|
20045
21163
|
if (describedLines >= STDERR_METADATA_LINE_BUDGET)
|
|
20046
21164
|
return;
|
|
20047
21165
|
describedLines += 1;
|
|
20048
|
-
|
|
21166
|
+
log10.info("app-server.stderr", () => ({
|
|
20049
21167
|
generation: generationId,
|
|
20050
21168
|
detail: describeChildStderrLine(line)
|
|
20051
21169
|
}));
|
|
@@ -20069,7 +21187,7 @@ class AppServerSupervisor {
|
|
|
20069
21187
|
stderrTail = "";
|
|
20070
21188
|
if (suppressedLines === 0)
|
|
20071
21189
|
return;
|
|
20072
|
-
|
|
21190
|
+
log10.info("app-server.stderr-suppressed", {
|
|
20073
21191
|
generation: generationId,
|
|
20074
21192
|
lines: suppressedLines,
|
|
20075
21193
|
payloadBytes: suppressedBytes
|
|
@@ -20079,7 +21197,7 @@ class AppServerSupervisor {
|
|
|
20079
21197
|
};
|
|
20080
21198
|
const recorder = (this.options.createRecorder ?? ((generation) => createRecorderFromEnv({ generation })))(generationId);
|
|
20081
21199
|
if (recorder) {
|
|
20082
|
-
|
|
21200
|
+
log10.warn("app-server.recording", {
|
|
20083
21201
|
generation: generationId,
|
|
20084
21202
|
fileName: recorder.getStats().fileName
|
|
20085
21203
|
});
|
|
@@ -20092,7 +21210,7 @@ class AppServerSupervisor {
|
|
|
20092
21210
|
onServerRequest: (request) => this.options.onServerRequest(request, generationId),
|
|
20093
21211
|
onProtocolViolation: (detail) => {
|
|
20094
21212
|
this.unknownNotifications += 1;
|
|
20095
|
-
|
|
21213
|
+
log10.warn("app-server.protocol-violation", { generation: generationId, detail });
|
|
20096
21214
|
},
|
|
20097
21215
|
...recorder ? { recordInboundLine: (line) => recorder.record(line) } : {}
|
|
20098
21216
|
});
|
|
@@ -20170,7 +21288,7 @@ class AppServerSupervisor {
|
|
|
20170
21288
|
return;
|
|
20171
21289
|
const exited = this.current;
|
|
20172
21290
|
this.current = null;
|
|
20173
|
-
|
|
21291
|
+
log10.warn("app-server.exited", {
|
|
20174
21292
|
generation: generationId,
|
|
20175
21293
|
code,
|
|
20176
21294
|
signal,
|
|
@@ -20190,7 +21308,7 @@ class AppServerSupervisor {
|
|
|
20190
21308
|
const reason = "notification queue overflowed";
|
|
20191
21309
|
this.lastError = reason;
|
|
20192
21310
|
this.restartNow(reason).catch((error) => {
|
|
20193
|
-
|
|
21311
|
+
log10.error("app-server.overflow-restart-failed", { error: formatLogError(error) });
|
|
20194
21312
|
});
|
|
20195
21313
|
}
|
|
20196
21314
|
async ensureEnvironmentIsCurrent(options) {
|
|
@@ -20443,7 +21561,7 @@ class AppServerSupervisor {
|
|
|
20443
21561
|
if (outcome === "contended")
|
|
20444
21562
|
return true;
|
|
20445
21563
|
if (matches && pid !== null) {
|
|
20446
|
-
|
|
21564
|
+
log10.info("app-server.stale-reaped", { pid });
|
|
20447
21565
|
(this.options.signalPidFileProcess ?? signalStaleProcessTree)(pid);
|
|
20448
21566
|
}
|
|
20449
21567
|
return true;
|
|
@@ -20556,7 +21674,7 @@ class AppServerSupervisor {
|
|
|
20556
21674
|
}
|
|
20557
21675
|
function runPs(args) {
|
|
20558
21676
|
return new Promise((resolve, reject) => {
|
|
20559
|
-
|
|
21677
|
+
execFile2("/bin/ps", args, {
|
|
20560
21678
|
maxBuffer: 1024 * 1024,
|
|
20561
21679
|
env: { ...runtimeEnvironmentSnapshot(), LC_ALL: "C", LANG: "C", TZ: process.env.TZ }
|
|
20562
21680
|
}, (error, stdout) => {
|
|
@@ -21120,7 +22238,7 @@ function buildInteractionResponse(request, answer) {
|
|
|
21120
22238
|
}
|
|
21121
22239
|
|
|
21122
22240
|
// ../../bridges/codex-bridge/src/app-server/server-request-router.ts
|
|
21123
|
-
var
|
|
22241
|
+
var log11 = createLogger("bridge.codex");
|
|
21124
22242
|
var DEFAULT_RESPONSE_TIMEOUT_MS = 1e4;
|
|
21125
22243
|
var DEFAULT_APPROVAL_TIMEOUT_MS = AGENT_INTERACTION_DEFAULT_TIMEOUT_MS;
|
|
21126
22244
|
|
|
@@ -21280,7 +22398,7 @@ class ServerRequestRouter {
|
|
|
21280
22398
|
record.timedOut = true;
|
|
21281
22399
|
this.counts.timedOut += 1;
|
|
21282
22400
|
if (this.sendStarted.has(key)) {
|
|
21283
|
-
|
|
22401
|
+
log11.error("server-request.flush-timeout", {
|
|
21284
22402
|
method: record.method,
|
|
21285
22403
|
timeoutMs: this.responseTimeoutMs
|
|
21286
22404
|
});
|
|
@@ -21384,7 +22502,7 @@ class ServerRequestRouter {
|
|
|
21384
22502
|
accepted = this.options.presentApproval?.(approval) === true;
|
|
21385
22503
|
} catch (error) {
|
|
21386
22504
|
deadline.settle();
|
|
21387
|
-
|
|
22505
|
+
log11.error("approval.present-failed", { error: formatLogError(error) });
|
|
21388
22506
|
return false;
|
|
21389
22507
|
}
|
|
21390
22508
|
if (!accepted) {
|
|
@@ -21421,7 +22539,7 @@ class ServerRequestRouter {
|
|
|
21421
22539
|
try {
|
|
21422
22540
|
this.options.onApprovalResolved?.(parked.request, decision, resolution);
|
|
21423
22541
|
} catch (error) {
|
|
21424
|
-
|
|
22542
|
+
log11.error("approval.resolved-callback-failed", { error: formatLogError(error) });
|
|
21425
22543
|
}
|
|
21426
22544
|
if (options.skipSend) {
|
|
21427
22545
|
this.pending.delete(parked.key);
|
|
@@ -21442,7 +22560,7 @@ class ServerRequestRouter {
|
|
|
21442
22560
|
try {
|
|
21443
22561
|
this.options.onApprovalResolved?.(parked.request, "withdrawn", "withdrawn");
|
|
21444
22562
|
} catch (error) {
|
|
21445
|
-
|
|
22563
|
+
log11.error("approval.resolved-callback-failed", { error: formatLogError(error) });
|
|
21446
22564
|
}
|
|
21447
22565
|
this.pending.delete(parked.key);
|
|
21448
22566
|
this.sendStarted.delete(parked.key);
|
|
@@ -21484,7 +22602,7 @@ class ServerRequestRouter {
|
|
|
21484
22602
|
accepted = this.options.presentInteraction?.(interaction) === true;
|
|
21485
22603
|
} catch (error) {
|
|
21486
22604
|
deadline?.settle();
|
|
21487
|
-
|
|
22605
|
+
log11.error("interaction.present-failed", { error: formatLogError(error) });
|
|
21488
22606
|
return false;
|
|
21489
22607
|
}
|
|
21490
22608
|
if (!accepted) {
|
|
@@ -21520,7 +22638,7 @@ class ServerRequestRouter {
|
|
|
21520
22638
|
try {
|
|
21521
22639
|
this.options.onInteractionResolved?.(parked.request, answer, resolution);
|
|
21522
22640
|
} catch (error) {
|
|
21523
|
-
|
|
22641
|
+
log11.error("interaction.resolved-callback-failed", { error: formatLogError(error) });
|
|
21524
22642
|
}
|
|
21525
22643
|
if (options.skipSend) {
|
|
21526
22644
|
this.pending.delete(parked.key);
|
|
@@ -21553,7 +22671,7 @@ class ServerRequestRouter {
|
|
|
21553
22671
|
try {
|
|
21554
22672
|
await send();
|
|
21555
22673
|
} catch (error) {
|
|
21556
|
-
|
|
22674
|
+
log11.error("server-request.answer-failed", {
|
|
21557
22675
|
method: record.method,
|
|
21558
22676
|
error: formatLogError(error, { stack: false })
|
|
21559
22677
|
});
|
|
@@ -21570,7 +22688,7 @@ class ServerRequestRouter {
|
|
|
21570
22688
|
}
|
|
21571
22689
|
violation(method, detail) {
|
|
21572
22690
|
this.options.onInvariantViolation?.(method, detail);
|
|
21573
|
-
|
|
22691
|
+
log11.error("app-server.invariant-violation", { method, detail });
|
|
21574
22692
|
}
|
|
21575
22693
|
explain(record, message) {
|
|
21576
22694
|
this.options.reportToTranscript?.({
|
|
@@ -22156,12 +23274,12 @@ function reduceHistoricalTurns(turns, generation, threadId, handle) {
|
|
|
22156
23274
|
}
|
|
22157
23275
|
|
|
22158
23276
|
// ../../bridges/codex-bridge/src/sessions/dispatch-journal.ts
|
|
22159
|
-
import { createHash as
|
|
23277
|
+
import { createHash as createHash11 } from "node:crypto";
|
|
22160
23278
|
import { mkdir as mkdir8, open as open7, rename as rename6, rm as rm7, writeFile as writeFile5 } from "node:fs/promises";
|
|
22161
23279
|
import { join as join16 } from "node:path";
|
|
22162
23280
|
|
|
22163
23281
|
// ../../bridges/codex-bridge/src/sessions/persistence.ts
|
|
22164
|
-
import { createHash as
|
|
23282
|
+
import { createHash as createHash10, randomUUID as randomUUID8 } from "node:crypto";
|
|
22165
23283
|
import {
|
|
22166
23284
|
chmod,
|
|
22167
23285
|
link as link2,
|
|
@@ -22174,7 +23292,7 @@ import {
|
|
|
22174
23292
|
writeFile as writeFile4
|
|
22175
23293
|
} from "node:fs/promises";
|
|
22176
23294
|
import { join as join15 } from "node:path";
|
|
22177
|
-
var
|
|
23295
|
+
var log12 = createLogger("bridge.codex");
|
|
22178
23296
|
var BRIDGE_SESSION_REGISTRY_VERSION = 2;
|
|
22179
23297
|
var SESSION_TITLE_SOURCES = new Set([
|
|
22180
23298
|
"codex",
|
|
@@ -22256,7 +23374,7 @@ function isPersistedSessionTombstone(value) {
|
|
|
22256
23374
|
return tombstone.deleted === true && typeof tombstone.bridgeSessionId === "string" && tombstone.bridgeSessionId.length > 0 && typeof tombstone.deletedAt === "string" && Number.isFinite(Date.parse(tombstone.deletedAt));
|
|
22257
23375
|
}
|
|
22258
23376
|
function hashCwd(cwd) {
|
|
22259
|
-
return
|
|
23377
|
+
return createHash10("sha256").update(cwd).digest("hex").slice(0, 16);
|
|
22260
23378
|
}
|
|
22261
23379
|
var DEFAULT_RETENTION_MS = 7 * 24 * 60 * 60 * 1000;
|
|
22262
23380
|
var RECORD_FILE_MISSING = Symbol("record-file-missing");
|
|
@@ -22290,7 +23408,7 @@ class BridgeSessionStore {
|
|
|
22290
23408
|
return directory === this.recordsDir() ? undefined : directory;
|
|
22291
23409
|
}
|
|
22292
23410
|
recordKey(bridgeSessionId) {
|
|
22293
|
-
return
|
|
23411
|
+
return createHash10("sha256").update(bridgeSessionId).digest("hex");
|
|
22294
23412
|
}
|
|
22295
23413
|
recordPath(bridgeSessionId) {
|
|
22296
23414
|
return join15(this.recordsDir(), `${this.recordKey(bridgeSessionId)}.json`);
|
|
@@ -22442,7 +23560,7 @@ class BridgeSessionStore {
|
|
|
22442
23560
|
await this.ensurePrivateStorage();
|
|
22443
23561
|
await Promise.all(sessions.map(async (session) => {
|
|
22444
23562
|
const target = this.recordPath(session.bridgeSessionId);
|
|
22445
|
-
const temporary = `${target}.${process.pid}.${
|
|
23563
|
+
const temporary = `${target}.${process.pid}.${randomUUID8()}.tmp`;
|
|
22446
23564
|
await writeFile4(temporary, `${JSON.stringify(session, null, 2)}
|
|
22447
23565
|
`, {
|
|
22448
23566
|
encoding: "utf8",
|
|
@@ -22473,7 +23591,7 @@ class BridgeSessionStore {
|
|
|
22473
23591
|
await Promise.all(names.map(async (name) => {
|
|
22474
23592
|
const from = join15(source, name);
|
|
22475
23593
|
const target = join15(this.recordsDir(), name);
|
|
22476
|
-
const temporary = `${target}.${process.pid}.${
|
|
23594
|
+
const temporary = `${target}.${process.pid}.${randomUUID8()}.tmp`;
|
|
22477
23595
|
await writeFile4(temporary, await readFile6(from), { mode: PRIVATE_FILE_MODE });
|
|
22478
23596
|
await chmod(temporary, PRIVATE_FILE_MODE);
|
|
22479
23597
|
try {
|
|
@@ -22498,7 +23616,7 @@ class BridgeSessionStore {
|
|
|
22498
23616
|
`);
|
|
22499
23617
|
}
|
|
22500
23618
|
async writeAtomicPath(path, payload) {
|
|
22501
|
-
const temporary = `${path}.${process.pid}.${
|
|
23619
|
+
const temporary = `${path}.${process.pid}.${randomUUID8()}.tmp`;
|
|
22502
23620
|
await writeFile4(temporary, payload, {
|
|
22503
23621
|
encoding: "utf8",
|
|
22504
23622
|
mode: PRIVATE_FILE_MODE
|
|
@@ -22513,7 +23631,7 @@ class BridgeSessionStore {
|
|
|
22513
23631
|
await chmod(path, PRIVATE_FILE_MODE);
|
|
22514
23632
|
}
|
|
22515
23633
|
warnPersistenceFailure(error) {
|
|
22516
|
-
|
|
23634
|
+
log12.warn("registry.persist-failed", { error: formatLogError(error, { stack: false }) });
|
|
22517
23635
|
}
|
|
22518
23636
|
toRecord(options) {
|
|
22519
23637
|
const { agentMcp: _agentMcp, ...persistedConfig } = options.config;
|
|
@@ -22537,7 +23655,7 @@ class BridgeSessionStore {
|
|
|
22537
23655
|
}
|
|
22538
23656
|
|
|
22539
23657
|
// ../../bridges/codex-bridge/src/sessions/dispatch-journal.ts
|
|
22540
|
-
var
|
|
23658
|
+
var log13 = createLogger("bridge.codex");
|
|
22541
23659
|
var DISPATCH_JOURNAL_VERSION = 1;
|
|
22542
23660
|
var DISPATCH_COMPLETENESS_VERSION = 1;
|
|
22543
23661
|
var MAX_FRESH_SESSION_MARKERS = 256;
|
|
@@ -22953,7 +24071,7 @@ class DispatchJournal {
|
|
|
22953
24071
|
this.filterAdd(requestId);
|
|
22954
24072
|
}
|
|
22955
24073
|
filterPositions(requestId) {
|
|
22956
|
-
const digest =
|
|
24074
|
+
const digest = createHash11("sha256").update(requestId, "utf8").digest();
|
|
22957
24075
|
const positions = [];
|
|
22958
24076
|
for (let index = 0;index < UNTRACKED_FILTER_HASHES; index += 1) {
|
|
22959
24077
|
positions.push(digest.readUInt32BE(index * 4) % UNTRACKED_FILTER_BITS);
|
|
@@ -23076,7 +24194,7 @@ class DispatchJournal {
|
|
|
23076
24194
|
throw error;
|
|
23077
24195
|
});
|
|
23078
24196
|
} catch (error) {
|
|
23079
|
-
|
|
24197
|
+
log13.warn("journal.persist-failed", { error: formatLogError(error, { stack: false }) });
|
|
23080
24198
|
if (options.failClosed)
|
|
23081
24199
|
throw error;
|
|
23082
24200
|
}
|
|
@@ -23192,12 +24310,12 @@ function coordinatorCapabilityPolicy(mode) {
|
|
|
23192
24310
|
}
|
|
23193
24311
|
|
|
23194
24312
|
// ../../bridges/codex-bridge/src/codex-config.ts
|
|
23195
|
-
import { existsSync as existsSync3, readdirSync as
|
|
24313
|
+
import { existsSync as existsSync3, readdirSync as readdirSync4, realpathSync, statSync as statSync2 } from "node:fs";
|
|
23196
24314
|
import { homedir as homedir3 } from "node:os";
|
|
23197
24315
|
import { isAbsolute as isAbsolute8, join as join18, relative as relative3, sep } from "node:path";
|
|
23198
24316
|
|
|
23199
24317
|
// ../../bridges/codex-bridge/src/shell-exclusions.ts
|
|
23200
|
-
import { closeSync, openSync, readSync, fstatSync } from "node:fs";
|
|
24318
|
+
import { closeSync as closeSync2, openSync as openSync2, readSync as readSync2, fstatSync as fstatSync2 } from "node:fs";
|
|
23201
24319
|
import { homedir as homedir2 } from "node:os";
|
|
23202
24320
|
import { dirname as dirname3, join as join17, resolve as resolve3 } from "node:path";
|
|
23203
24321
|
function configuredShellExclusions(env) {
|
|
@@ -23219,21 +24337,21 @@ function configuredShellExclusions(env) {
|
|
|
23219
24337
|
for (const path of paths) {
|
|
23220
24338
|
let fd;
|
|
23221
24339
|
try {
|
|
23222
|
-
fd =
|
|
24340
|
+
fd = openSync2(path, "r");
|
|
23223
24341
|
} catch (error) {
|
|
23224
24342
|
if (error.code === "ENOENT")
|
|
23225
24343
|
continue;
|
|
23226
24344
|
throw new Error("Cannot read Codex shell exclusions");
|
|
23227
24345
|
}
|
|
23228
24346
|
try {
|
|
23229
|
-
const stat =
|
|
24347
|
+
const stat = fstatSync2(fd);
|
|
23230
24348
|
if (!stat.isFile() || stat.size > 1024 * 1024) {
|
|
23231
24349
|
throw new Error("Invalid Codex configuration file");
|
|
23232
24350
|
}
|
|
23233
24351
|
const buffer = Buffer.alloc(1024 * 1024 + 1);
|
|
23234
24352
|
let length = 0;
|
|
23235
24353
|
while (length < buffer.length) {
|
|
23236
|
-
const count =
|
|
24354
|
+
const count = readSync2(fd, buffer, length, buffer.length - length, null);
|
|
23237
24355
|
if (count === 0)
|
|
23238
24356
|
break;
|
|
23239
24357
|
length += count;
|
|
@@ -23245,7 +24363,7 @@ function configuredShellExclusions(env) {
|
|
|
23245
24363
|
} catch {
|
|
23246
24364
|
throw new Error("Cannot load Codex shell exclusions");
|
|
23247
24365
|
} finally {
|
|
23248
|
-
|
|
24366
|
+
closeSync2(fd);
|
|
23249
24367
|
}
|
|
23250
24368
|
}
|
|
23251
24369
|
return [...exclusions];
|
|
@@ -23415,7 +24533,7 @@ function codexCoordinatorSkillReadRoots(env = process.env, home = env.HOME?.trim
|
|
|
23415
24533
|
grants.add(real);
|
|
23416
24534
|
let entries;
|
|
23417
24535
|
try {
|
|
23418
|
-
entries =
|
|
24536
|
+
entries = readdirSync4(real).filter((name) => !name.startsWith("."));
|
|
23419
24537
|
} catch {
|
|
23420
24538
|
continue;
|
|
23421
24539
|
}
|
|
@@ -23828,7 +24946,7 @@ var APP_SERVER_CAPABILITIES = {
|
|
|
23828
24946
|
};
|
|
23829
24947
|
|
|
23830
24948
|
// ../../bridges/codex-bridge/src/engine/app-server-engine.ts
|
|
23831
|
-
var
|
|
24949
|
+
var log14 = createLogger("bridge.codex");
|
|
23832
24950
|
var AGENT_MAIL_TOOL_APPROVALS = Object.fromEntries([
|
|
23833
24951
|
...AGENT_MAIL_TOOL_NAMES,
|
|
23834
24952
|
...ARTIFACT_TOOL_NAMES,
|
|
@@ -24203,7 +25321,7 @@ async function readStoredLoginFingerprint(codexHome) {
|
|
|
24203
25321
|
const apiKey = typeof root.OPENAI_API_KEY === "string" ? root.OPENAI_API_KEY : "";
|
|
24204
25322
|
if (!refreshToken && !apiKey)
|
|
24205
25323
|
return;
|
|
24206
|
-
return
|
|
25324
|
+
return createHash12("sha256").update(JSON.stringify([refreshToken, apiKey])).digest("hex");
|
|
24207
25325
|
} catch {
|
|
24208
25326
|
return;
|
|
24209
25327
|
}
|
|
@@ -24413,7 +25531,7 @@ class AppServerEngine {
|
|
|
24413
25531
|
try {
|
|
24414
25532
|
listener(event);
|
|
24415
25533
|
} catch (error) {
|
|
24416
|
-
|
|
25534
|
+
log14.error("engine.listener-failed", { error: formatLogError(error) });
|
|
24417
25535
|
}
|
|
24418
25536
|
}
|
|
24419
25537
|
}
|
|
@@ -24538,7 +25656,7 @@ class AppServerEngine {
|
|
|
24538
25656
|
const sequence = ++this.accountCheckSequence;
|
|
24539
25657
|
const generation = this.supervisor.getGeneration();
|
|
24540
25658
|
this.supervisor.request("account/read", { refreshToken }).catch(signedOutAccountRead).then((response) => this.applyAccountRead(response, sequence, generation, accountReplaced)).catch((error) => {
|
|
24541
|
-
|
|
25659
|
+
log14.warn("account.sign-in-check-failed", {
|
|
24542
25660
|
error: formatLogError(error, { stack: false })
|
|
24543
25661
|
});
|
|
24544
25662
|
});
|
|
@@ -25125,7 +26243,7 @@ class AppServerEngine {
|
|
|
25125
26243
|
const generation = this.supervisor.getGeneration();
|
|
25126
26244
|
const response = await this.supervisor.request("account/read", { refreshToken: false }).catch(signedOutAccountRead);
|
|
25127
26245
|
this.applyAccountRead(response, sequence, generation, false).catch((error) => {
|
|
25128
|
-
|
|
26246
|
+
log14.warn("account.connector-recovery-failed", {
|
|
25129
26247
|
error: formatLogError(error, { stack: false })
|
|
25130
26248
|
});
|
|
25131
26249
|
});
|
|
@@ -25338,7 +26456,7 @@ class AppServerEngine {
|
|
|
25338
26456
|
await this.supervisor.request("thread/name/set", { threadId, name });
|
|
25339
26457
|
return true;
|
|
25340
26458
|
} catch (error) {
|
|
25341
|
-
|
|
26459
|
+
log14.warn("thread.rename-failed", { error: formatLogError(error, { stack: false }) });
|
|
25342
26460
|
return false;
|
|
25343
26461
|
}
|
|
25344
26462
|
}
|
|
@@ -25358,7 +26476,7 @@ class AppServerEngine {
|
|
|
25358
26476
|
} catch (error) {
|
|
25359
26477
|
if (requireConfirmation)
|
|
25360
26478
|
throw error;
|
|
25361
|
-
|
|
26479
|
+
log14.warn("thread.unsubscribe-failed", { error: formatLogError(error, { stack: false }) });
|
|
25362
26480
|
}
|
|
25363
26481
|
this.accountProofTurns.delete(threadId);
|
|
25364
26482
|
this.rolloutPaths.delete(threadId);
|
|
@@ -25828,7 +26946,7 @@ class ThreadRegistry {
|
|
|
25828
26946
|
if (busy)
|
|
25829
26947
|
throw new OverlappingTurnError(context.threadId);
|
|
25830
26948
|
}
|
|
25831
|
-
setPhase(context, phase, error) {
|
|
26949
|
+
setPhase(context, phase, error, errorCode) {
|
|
25832
26950
|
if (phase === "starting") {
|
|
25833
26951
|
context.turnStartedAt = new Date(this.now()).toISOString();
|
|
25834
26952
|
} else if ((phase === "running" || phase === "cancelling" || phase === "recovering") && context.turnStartedAt === undefined && context.activeTurn) {
|
|
@@ -25838,6 +26956,7 @@ class ThreadRegistry {
|
|
|
25838
26956
|
}
|
|
25839
26957
|
context.phase = phase;
|
|
25840
26958
|
context.error = phase === "failed" ? error : undefined;
|
|
26959
|
+
context.errorCode = phase === "failed" ? errorCode : undefined;
|
|
25841
26960
|
}
|
|
25842
26961
|
sessionsForThread(threadId) {
|
|
25843
26962
|
const context = this.threads.get(threadId);
|
|
@@ -25903,9 +27022,9 @@ function externalRevertCut(messages, survivingTurnIds, running) {
|
|
|
25903
27022
|
}
|
|
25904
27023
|
|
|
25905
27024
|
// ../../bridges/codex-bridge/src/app-server-runtime-sessions.ts
|
|
25906
|
-
var
|
|
27025
|
+
var log15 = createLogger("bridge.codex");
|
|
25907
27026
|
var SESSION_CLOSING_ERROR = "Session is closing";
|
|
25908
|
-
var ACTIVITY_PROCESS =
|
|
27027
|
+
var ACTIVITY_PROCESS = randomUUID9();
|
|
25909
27028
|
|
|
25910
27029
|
class CodexRuntimeSessions {
|
|
25911
27030
|
ctx;
|
|
@@ -25920,7 +27039,7 @@ class CodexRuntimeSessions {
|
|
|
25920
27039
|
}
|
|
25921
27040
|
createSession(body) {
|
|
25922
27041
|
const clientSessionKey = typeof body.clientSessionKey === "string" && body.clientSessionKey.trim().length > 0 && body.clientSessionKey.length <= 512 ? body.clientSessionKey : undefined;
|
|
25923
|
-
const sessionId = clientSessionKey ? `session-client-${
|
|
27042
|
+
const sessionId = clientSessionKey ? `session-client-${createHash13("sha256").update(this.ctx.options.cwd).update("\x00").update(clientSessionKey).digest("hex").slice(0, 32)}` : createSessionId();
|
|
25924
27043
|
const existing = this.ctx.registry.getSession(sessionId);
|
|
25925
27044
|
if (existing) {
|
|
25926
27045
|
this.ctx.registry.touch(sessionId);
|
|
@@ -26058,7 +27177,7 @@ class CodexRuntimeSessions {
|
|
|
26058
27177
|
try {
|
|
26059
27178
|
fork = await this.ctx.options.engine.forkThread(parent.threadId, parent.config, lastTurnId);
|
|
26060
27179
|
} catch (error) {
|
|
26061
|
-
|
|
27180
|
+
log15.warn("thread.fork-failed", {
|
|
26062
27181
|
threadId: parent.threadId,
|
|
26063
27182
|
error: formatLogError(error, { stack: false })
|
|
26064
27183
|
});
|
|
@@ -26110,7 +27229,7 @@ class CodexRuntimeSessions {
|
|
|
26110
27229
|
await this.ctx.callbacks.deleteSession(child.id).catch(() => {
|
|
26111
27230
|
return;
|
|
26112
27231
|
});
|
|
26113
|
-
|
|
27232
|
+
log15.warn("thread.fork-hydrate-failed", {
|
|
26114
27233
|
threadId: parent.threadId,
|
|
26115
27234
|
error: formatLogError(error, { stack: false })
|
|
26116
27235
|
});
|
|
@@ -26125,7 +27244,7 @@ class CodexRuntimeSessions {
|
|
|
26125
27244
|
});
|
|
26126
27245
|
turns = thread?.turns;
|
|
26127
27246
|
} catch (error) {
|
|
26128
|
-
|
|
27247
|
+
log15.warn("thread.turns-read-failed", {
|
|
26129
27248
|
threadId: context.threadId,
|
|
26130
27249
|
error: formatLogError(error, { stack: false })
|
|
26131
27250
|
});
|
|
@@ -26242,7 +27361,7 @@ class CodexRuntimeSessions {
|
|
|
26242
27361
|
return "not-found";
|
|
26243
27362
|
if (this.sessionAdmissionClosed(session))
|
|
26244
27363
|
return "closing";
|
|
26245
|
-
const inputDigest =
|
|
27364
|
+
const inputDigest = createHash13("sha256").update(input).digest("hex");
|
|
26246
27365
|
const previous = this.ctx.steerRequests.get(requestId);
|
|
26247
27366
|
if (previous) {
|
|
26248
27367
|
if (previous.threadId !== session.threadId || previous.turnId !== expectedTurnId || previous.inputDigest !== inputDigest) {
|
|
@@ -26460,6 +27579,7 @@ class CodexRuntimeSessions {
|
|
|
26460
27579
|
}
|
|
26461
27580
|
const phaseBeforeReview = context.phase;
|
|
26462
27581
|
const errorBeforeReview = context.error;
|
|
27582
|
+
const errorCodeBeforeReview = context.errorCode;
|
|
26463
27583
|
context.dispatchInFlight = true;
|
|
26464
27584
|
this.ctx.registry.setPhase(context, "starting");
|
|
26465
27585
|
await this.ctx.callbacks.primeCommandChanges(context);
|
|
@@ -26525,7 +27645,7 @@ class CodexRuntimeSessions {
|
|
|
26525
27645
|
});
|
|
26526
27646
|
}
|
|
26527
27647
|
if (context.phase === "starting") {
|
|
26528
|
-
this.ctx.registry.setPhase(context, phaseBeforeReview, errorBeforeReview);
|
|
27648
|
+
this.ctx.registry.setPhase(context, phaseBeforeReview, errorBeforeReview, errorCodeBeforeReview);
|
|
26529
27649
|
}
|
|
26530
27650
|
this.lifecycle.emitStatus(context);
|
|
26531
27651
|
const message = error instanceof Error ? error.message : "Native review failed";
|
|
@@ -26616,7 +27736,7 @@ class CodexRuntimeSessions {
|
|
|
26616
27736
|
try {
|
|
26617
27737
|
turns = (await this.ctx.options.engine.readThread(context.threadId, { includeTurns: true }))?.turns;
|
|
26618
27738
|
} catch (error) {
|
|
26619
|
-
|
|
27739
|
+
log15.warn("thread.turns-read-after-revert-failed", {
|
|
26620
27740
|
threadId: context.threadId,
|
|
26621
27741
|
error: formatLogError(error, { stack: false })
|
|
26622
27742
|
});
|
|
@@ -26717,7 +27837,7 @@ class CodexRuntimeSessions {
|
|
|
26717
27837
|
}
|
|
26718
27838
|
} catch (error) {
|
|
26719
27839
|
await restoreEngineConfig();
|
|
26720
|
-
|
|
27840
|
+
log15.warn("session.config-apply-failed", {
|
|
26721
27841
|
sessionId,
|
|
26722
27842
|
error: formatLogError(error, { stack: false })
|
|
26723
27843
|
});
|
|
@@ -26760,7 +27880,7 @@ class CodexRuntimeSessions {
|
|
|
26760
27880
|
try {
|
|
26761
27881
|
context = await this.ctx.callbacks.ensureAttached(sessionId);
|
|
26762
27882
|
} catch (error) {
|
|
26763
|
-
|
|
27883
|
+
log15.warn("transcript.serving-last-known", {
|
|
26764
27884
|
sessionId,
|
|
26765
27885
|
error: formatLogError(error, { stack: false })
|
|
26766
27886
|
});
|
|
@@ -26844,6 +27964,7 @@ class CodexRuntimeSessions {
|
|
|
26844
27964
|
phase,
|
|
26845
27965
|
title: session.titleSource === "prompt" ? undefined : session.title,
|
|
26846
27966
|
error,
|
|
27967
|
+
...phase === "failed" && error !== undefined && context?.errorCode === "usageLimitExceeded" ? { errorCode: USAGE_LIMIT_ERROR_CODE } : {},
|
|
26847
27968
|
...phase === "failed" && session.restartFailure && error === CODEX_RESTARTED_MID_TURN_MESSAGE ? {
|
|
26848
27969
|
interruption: "restart",
|
|
26849
27970
|
...interruptedRequestId ? { interruptedRequestId } : {}
|
|
@@ -26962,7 +28083,7 @@ class CodexRuntimeSessions {
|
|
|
26962
28083
|
}
|
|
26963
28084
|
return "unpublished";
|
|
26964
28085
|
}
|
|
26965
|
-
|
|
28086
|
+
log15.warn("registry.persist-failed", { error: formatLogError(error, { stack: false }) });
|
|
26966
28087
|
}
|
|
26967
28088
|
if (this.ctx.registry.getSession(sessionId) !== session)
|
|
26968
28089
|
return "released";
|
|
@@ -27056,7 +28177,7 @@ class CodexRuntimeSessions {
|
|
|
27056
28177
|
}
|
|
27057
28178
|
}
|
|
27058
28179
|
// ../../bridges/codex-bridge/src/app-server-runtime-approvals.ts
|
|
27059
|
-
var
|
|
28180
|
+
var log16 = createLogger("bridge.codex");
|
|
27060
28181
|
|
|
27061
28182
|
class CodexRuntimeApprovals {
|
|
27062
28183
|
ctx;
|
|
@@ -27147,7 +28268,7 @@ class CodexRuntimeApprovals {
|
|
|
27147
28268
|
if (this.ctx.options.engine.resolveApproval(approvalId, decision)) {
|
|
27148
28269
|
if (decision === "cancel") {
|
|
27149
28270
|
this.ctx.callbacks.abort(sessionId).catch((error) => {
|
|
27150
|
-
|
|
28271
|
+
log16.error("approval.cancel-failed", { error: formatLogError(error) });
|
|
27151
28272
|
});
|
|
27152
28273
|
}
|
|
27153
28274
|
return "applied";
|
|
@@ -27268,7 +28389,7 @@ function parseCommandToken(text, sigils = ["/"]) {
|
|
|
27268
28389
|
}
|
|
27269
28390
|
|
|
27270
28391
|
// ../../bridges/codex-bridge/src/prompts/template-discovery.ts
|
|
27271
|
-
import { createHash as
|
|
28392
|
+
import { createHash as createHash14 } from "node:crypto";
|
|
27272
28393
|
import { open as open10, readdir as readdir3, stat as stat8 } from "node:fs/promises";
|
|
27273
28394
|
import { join as join21 } from "node:path";
|
|
27274
28395
|
var TEMPLATE_LIMITS = Object.freeze({
|
|
@@ -27301,7 +28422,7 @@ function templateBindingRevision(origin, relativePath) {
|
|
|
27301
28422
|
return commandBindingRevision(["template", origin, relativePath]);
|
|
27302
28423
|
}
|
|
27303
28424
|
function fingerprintOf(bytes) {
|
|
27304
|
-
return
|
|
28425
|
+
return createHash14("sha256").update(bytes).digest("hex").slice(0, 32);
|
|
27305
28426
|
}
|
|
27306
28427
|
function nameFromRelativePath(relativePath) {
|
|
27307
28428
|
return `/${relativePath.replace(/\.md$/i, "")}`;
|
|
@@ -28554,7 +29675,7 @@ class UpdateCoalescer {
|
|
|
28554
29675
|
|
|
28555
29676
|
// ../../bridges/codex-bridge/src/app-server-runtime-capacity-retry.ts
|
|
28556
29677
|
import { stat as stat9 } from "node:fs/promises";
|
|
28557
|
-
var
|
|
29678
|
+
var log17 = createLogger("bridge.codex");
|
|
28558
29679
|
|
|
28559
29680
|
class CodexCapacityRetry {
|
|
28560
29681
|
ctx;
|
|
@@ -28668,7 +29789,7 @@ class CodexCapacityRetry {
|
|
|
28668
29789
|
}
|
|
28669
29790
|
entry.stage = "starting";
|
|
28670
29791
|
const work = this.startContinuation(context, turn, entry).catch((error) => {
|
|
28671
|
-
|
|
29792
|
+
log17.error("turn.capacity-retry-failed", {
|
|
28672
29793
|
turnId: turn.turnId,
|
|
28673
29794
|
error: formatLogError(error, { stack: false })
|
|
28674
29795
|
});
|
|
@@ -28740,7 +29861,7 @@ class CodexCapacityRetry {
|
|
|
28740
29861
|
});
|
|
28741
29862
|
return;
|
|
28742
29863
|
}
|
|
28743
|
-
await this.ctx.journal.markAccepted(requestId, { threadId: context.threadId, turnId: started.turnId }).catch((error) =>
|
|
29864
|
+
await this.ctx.journal.markAccepted(requestId, { threadId: context.threadId, turnId: started.turnId }).catch((error) => log17.warn("turn.capacity-retry-journal-failed", {
|
|
28744
29865
|
requestId,
|
|
28745
29866
|
error: formatLogError(error, { stack: false })
|
|
28746
29867
|
}));
|
|
@@ -28811,7 +29932,7 @@ class CodexCapacityRetry {
|
|
|
28811
29932
|
}
|
|
28812
29933
|
|
|
28813
29934
|
// ../../bridges/codex-bridge/src/app-server-runtime-lifecycle.ts
|
|
28814
|
-
var
|
|
29935
|
+
var log18 = createLogger("bridge.codex");
|
|
28815
29936
|
function artifactConnectionToken(value) {
|
|
28816
29937
|
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
28817
29938
|
return;
|
|
@@ -28996,7 +30117,7 @@ class CodexRuntimeLifecycle {
|
|
|
28996
30117
|
this.ctx.registry.setPhase(existing, "recovering");
|
|
28997
30118
|
this.emitStatus(existing);
|
|
28998
30119
|
this.ctx.callbacks.scheduleRecoveryBackstop(existing);
|
|
28999
|
-
|
|
30120
|
+
log18.warn("dispatch.restore-failed", {
|
|
29000
30121
|
requestId: record.requestId,
|
|
29001
30122
|
error: formatLogError(error, { stack: false })
|
|
29002
30123
|
});
|
|
@@ -29175,7 +30296,7 @@ class CodexRuntimeLifecycle {
|
|
|
29175
30296
|
});
|
|
29176
30297
|
}));
|
|
29177
30298
|
}
|
|
29178
|
-
|
|
30299
|
+
log18.warn("thread.reattach-failed", {
|
|
29179
30300
|
threadId,
|
|
29180
30301
|
rolloutMissing: isMissingRolloutError(error),
|
|
29181
30302
|
error: formatLogError(error, { stack: false })
|
|
@@ -29256,7 +30377,7 @@ class CodexRuntimeLifecycle {
|
|
|
29256
30377
|
coalescer: new UpdateCoalescer({
|
|
29257
30378
|
intervalMs: this.ctx.options.coalesceIntervalMs ?? (() => messageSnapshotIntervalMs(this.ctx.threadState.get(threadId)?.lastPublishedSnapshotChars ?? 0)),
|
|
29258
30379
|
publish: () => this.ctx.callbacks.publishAssistantMessage(threadId),
|
|
29259
|
-
onError: (error) =>
|
|
30380
|
+
onError: (error) => log18.error("message.publish-failed", { error: formatLogError(error) })
|
|
29260
30381
|
})
|
|
29261
30382
|
};
|
|
29262
30383
|
this.ctx.threadState.set(threadId, state);
|
|
@@ -29292,7 +30413,7 @@ class CodexRuntimeLifecycle {
|
|
|
29292
30413
|
this.ctx.commandCatalogue.withdrawGeneration(event.generation);
|
|
29293
30414
|
const recovery = this.ctx.generationRecovery.then(() => this.ctx.callbacks.recoverAfterGenerationChange(event.generation));
|
|
29294
30415
|
this.ctx.generationRecovery = recovery.catch((error) => {
|
|
29295
|
-
|
|
30416
|
+
log18.error("generation.recovery-failed", { error: formatLogError(error) });
|
|
29296
30417
|
});
|
|
29297
30418
|
return;
|
|
29298
30419
|
}
|
|
@@ -29312,7 +30433,7 @@ class CodexRuntimeLifecycle {
|
|
|
29312
30433
|
}
|
|
29313
30434
|
if (event.kind === "account.reload.requested") {
|
|
29314
30435
|
this.ctx.callbacks.reloadStoredAccountLogin().catch((error) => {
|
|
29315
|
-
|
|
30436
|
+
log18.warn("account.login-reload-failed", { error: formatLogError(error, { stack: false }) });
|
|
29316
30437
|
});
|
|
29317
30438
|
return;
|
|
29318
30439
|
}
|
|
@@ -29615,7 +30736,7 @@ class CodexRuntimeLifecycle {
|
|
|
29615
30736
|
}
|
|
29616
30737
|
this.ctx.options.changeEvidence?.turn(this.evidenceSource(context, turn), event.status);
|
|
29617
30738
|
const finalize = () => this.runFinalization(context, turn).catch((error) => {
|
|
29618
|
-
|
|
30739
|
+
log18.error("turn.finalize-failed", {
|
|
29619
30740
|
turnId: turn.turnId,
|
|
29620
30741
|
error: formatLogError(error, { stack: false })
|
|
29621
30742
|
});
|
|
@@ -29833,7 +30954,7 @@ class CodexRuntimeLifecycle {
|
|
|
29833
30954
|
}
|
|
29834
30955
|
trackCommandChangeWork(work) {
|
|
29835
30956
|
const tracked = work.catch((error) => {
|
|
29836
|
-
|
|
30957
|
+
log18.warn("command-changes.record-failed", { error: formatLogError(error, { stack: false }) });
|
|
29837
30958
|
});
|
|
29838
30959
|
this.ctx.pendingCommandChanges.add(tracked);
|
|
29839
30960
|
tracked.finally(() => this.ctx.pendingCommandChanges.delete(tracked));
|
|
@@ -30045,6 +31166,7 @@ class CodexRuntimeLifecycle {
|
|
|
30045
31166
|
}
|
|
30046
31167
|
const phaseBeforeRebind = context.phase;
|
|
30047
31168
|
const errorBeforeRebind = context.error;
|
|
31169
|
+
const errorCodeBeforeRebind = context.errorCode;
|
|
30048
31170
|
const turn = context.activeTurn;
|
|
30049
31171
|
try {
|
|
30050
31172
|
if (!context.materialized) {
|
|
@@ -30070,7 +31192,7 @@ class CodexRuntimeLifecycle {
|
|
|
30070
31192
|
context.unsubscribed = false;
|
|
30071
31193
|
context.engineGeneration = generation;
|
|
30072
31194
|
if (!turn) {
|
|
30073
|
-
this.ctx.registry.setPhase(context, phaseBeforeRebind === "failed" ? "failed" : "idle", phaseBeforeRebind === "failed" ? errorBeforeRebind : undefined);
|
|
31195
|
+
this.ctx.registry.setPhase(context, phaseBeforeRebind === "failed" ? "failed" : "idle", phaseBeforeRebind === "failed" ? errorBeforeRebind : undefined, phaseBeforeRebind === "failed" ? errorCodeBeforeRebind : undefined);
|
|
30074
31196
|
this.emitStatus(context);
|
|
30075
31197
|
continue;
|
|
30076
31198
|
}
|
|
@@ -30195,7 +31317,7 @@ class CodexRuntimeLifecycle {
|
|
|
30195
31317
|
await Promise.all(restartNoticeSessions.map((session) => this.ctx.callbacks.persistSession(session)));
|
|
30196
31318
|
}
|
|
30197
31319
|
context.activeTurn = null;
|
|
30198
|
-
this.ctx.registry.setPhase(context, turn.phase === "failed" ? "failed" : "idle", turn.error?.message);
|
|
31320
|
+
this.ctx.registry.setPhase(context, turn.phase === "failed" ? "failed" : "idle", turn.error?.message, turn.error?.code);
|
|
30199
31321
|
state.assistantMessageId = undefined;
|
|
30200
31322
|
this.ctx.callbacks.notifyThreadActivity();
|
|
30201
31323
|
for (const sessionId of context.bridgeSessionIds) {
|
|
@@ -30276,7 +31398,7 @@ class CodexRuntimeLifecycle {
|
|
|
30276
31398
|
try {
|
|
30277
31399
|
await state.coalescer.flushNow();
|
|
30278
31400
|
} catch (error) {
|
|
30279
|
-
|
|
31401
|
+
log18.error("ordered-events.flush-failed", { error: formatLogError(error) });
|
|
30280
31402
|
}
|
|
30281
31403
|
state.orderedReconcilePending = false;
|
|
30282
31404
|
for (const sessionId of this.ctx.sessionIdsForThread(threadId)) {
|
|
@@ -30295,7 +31417,7 @@ class CodexRuntimeLifecycle {
|
|
|
30295
31417
|
await state.coalescer.flushNow();
|
|
30296
31418
|
event.publish();
|
|
30297
31419
|
} catch (error) {
|
|
30298
|
-
|
|
31420
|
+
log18.error("ordered-events.publish-failed", { error: formatLogError(error) });
|
|
30299
31421
|
state.orderedEvents.length = 0;
|
|
30300
31422
|
state.orderedEventBytes = 0;
|
|
30301
31423
|
state.orderedReconcilePending = true;
|
|
@@ -30304,7 +31426,7 @@ class CodexRuntimeLifecycle {
|
|
|
30304
31426
|
}
|
|
30305
31427
|
}
|
|
30306
31428
|
} catch (error) {
|
|
30307
|
-
|
|
31429
|
+
log18.error("ordered-events.reconcile-failed", { error: formatLogError(error) });
|
|
30308
31430
|
} finally {
|
|
30309
31431
|
state.orderedEventDraining = false;
|
|
30310
31432
|
if ((state.orderedReconcilePending || state.orderedEvents.length > 0) && this.ctx.threadState.get(threadId) === state) {
|
|
@@ -30420,7 +31542,7 @@ function isTabInitialPromptRequestId(requestId) {
|
|
|
30420
31542
|
}
|
|
30421
31543
|
|
|
30422
31544
|
// ../../bridges/codex-bridge/src/app-server-runtime-prompt.ts
|
|
30423
|
-
var
|
|
31545
|
+
var log19 = createLogger("bridge.codex");
|
|
30424
31546
|
function commandRefusal(message) {
|
|
30425
31547
|
return { ok: false, status: 422, error: message, kind: "command-unavailable" };
|
|
30426
31548
|
}
|
|
@@ -31082,7 +32204,7 @@ class CodexRuntimePrompt {
|
|
|
31082
32204
|
try {
|
|
31083
32205
|
outcome = await this.ctx.options.engine.reconcileRequest(context.threadId, accumulator.providerRequestId);
|
|
31084
32206
|
} catch (error) {
|
|
31085
|
-
|
|
32207
|
+
log19.warn("dispatch.reconcile-failed", {
|
|
31086
32208
|
requestId,
|
|
31087
32209
|
threadId: context.threadId,
|
|
31088
32210
|
error: formatLogError(error, { stack: false })
|
|
@@ -31357,7 +32479,7 @@ class CodexRuntimePrompt {
|
|
|
31357
32479
|
if (this.ctx.stopping || this.shouldAbandonDrain(expectedGeneration))
|
|
31358
32480
|
return;
|
|
31359
32481
|
if (Date.now() >= deadline) {
|
|
31360
|
-
|
|
32482
|
+
log19.warn("app-server.drain-expired");
|
|
31361
32483
|
return;
|
|
31362
32484
|
}
|
|
31363
32485
|
await this.waitForThreadActivity();
|
|
@@ -31391,7 +32513,7 @@ class CodexRuntimePrompt {
|
|
|
31391
32513
|
|
|
31392
32514
|
// ../../bridges/codex-bridge/src/app-server-runtime-tail.ts
|
|
31393
32515
|
import { join as join22, relative as relative4, isAbsolute as isAbsolute11 } from "node:path";
|
|
31394
|
-
var
|
|
32516
|
+
var log20 = createLogger("bridge.codex");
|
|
31395
32517
|
|
|
31396
32518
|
class CodexRuntimeTail {
|
|
31397
32519
|
ctx;
|
|
@@ -31540,7 +32662,7 @@ class CodexRuntimeTail {
|
|
|
31540
32662
|
};
|
|
31541
32663
|
}
|
|
31542
32664
|
} catch (error) {
|
|
31543
|
-
|
|
32665
|
+
log20.warn("models.list-failed", { error: formatLogError(error, { stack: false }) });
|
|
31544
32666
|
}
|
|
31545
32667
|
return this.ctx.options.loadCachedModels();
|
|
31546
32668
|
}
|
|
@@ -31566,7 +32688,7 @@ class CodexRuntimeTail {
|
|
|
31566
32688
|
});
|
|
31567
32689
|
}
|
|
31568
32690
|
} catch (error) {
|
|
31569
|
-
|
|
32691
|
+
log20.warn("threads.list-failed", { error: formatLogError(error, { stack: false }) });
|
|
31570
32692
|
}
|
|
31571
32693
|
const archived = new Set;
|
|
31572
32694
|
try {
|
|
@@ -31651,7 +32773,7 @@ class CodexRuntimeTail {
|
|
|
31651
32773
|
else
|
|
31652
32774
|
await this.ctx.options.engine.unarchiveThread(threadId);
|
|
31653
32775
|
} catch (error) {
|
|
31654
|
-
|
|
32776
|
+
log20.warn("thread.archive-failed", {
|
|
31655
32777
|
archived,
|
|
31656
32778
|
error: formatLogError(error, { stack: false })
|
|
31657
32779
|
});
|
|
@@ -31984,7 +33106,7 @@ class AppServerRuntime {
|
|
|
31984
33106
|
}
|
|
31985
33107
|
}
|
|
31986
33108
|
|
|
31987
|
-
//
|
|
33109
|
+
// ../protocol/src/node/event-ring.ts
|
|
31988
33110
|
var DEFAULT_RING_CAPACITY = 512;
|
|
31989
33111
|
|
|
31990
33112
|
class EventRing {
|
|
@@ -32023,6 +33145,32 @@ class EventRing {
|
|
|
32023
33145
|
}
|
|
32024
33146
|
append(event) {
|
|
32025
33147
|
this.revision += 1;
|
|
33148
|
+
this.retain(event);
|
|
33149
|
+
return this.revision;
|
|
33150
|
+
}
|
|
33151
|
+
appendAt(revision, event) {
|
|
33152
|
+
this.skipTo(revision - 1);
|
|
33153
|
+
this.revision = revision;
|
|
33154
|
+
this.retain(event);
|
|
33155
|
+
}
|
|
33156
|
+
advance() {
|
|
33157
|
+
this.advanceTo(this.revision + 1);
|
|
33158
|
+
return this.revision;
|
|
33159
|
+
}
|
|
33160
|
+
advanceTo(revision) {
|
|
33161
|
+
this.skipTo(revision);
|
|
33162
|
+
this.revision = revision;
|
|
33163
|
+
}
|
|
33164
|
+
skipTo(revision) {
|
|
33165
|
+
if (!Number.isSafeInteger(revision) || revision < this.revision) {
|
|
33166
|
+
throw new RangeError("EventRing: revisions must not go backwards");
|
|
33167
|
+
}
|
|
33168
|
+
if (revision > this.revision && this.buffer.length > 0) {
|
|
33169
|
+
this.droppedEvents += this.buffer.length;
|
|
33170
|
+
this.clear();
|
|
33171
|
+
}
|
|
33172
|
+
}
|
|
33173
|
+
retain(event) {
|
|
32026
33174
|
if (this.supersede)
|
|
32027
33175
|
this.collapseSuperseded(event);
|
|
32028
33176
|
this.retainedBytes += Math.max(0, this.measureBytes(event));
|
|
@@ -32034,11 +33182,6 @@ class EventRing {
|
|
|
32034
33182
|
this.retainedBytes -= Math.max(0, this.measureBytes(removed.event));
|
|
32035
33183
|
this.droppedEvents += 1;
|
|
32036
33184
|
}
|
|
32037
|
-
return this.revision;
|
|
32038
|
-
}
|
|
32039
|
-
advance() {
|
|
32040
|
-
this.revision += 1;
|
|
32041
|
-
return this.revision;
|
|
32042
33185
|
}
|
|
32043
33186
|
collapseSuperseded(incoming) {
|
|
32044
33187
|
const supersede = this.supersede;
|
|
@@ -32049,10 +33192,11 @@ class EventRing {
|
|
|
32049
33192
|
const replacement = supersede(incoming, entry.event);
|
|
32050
33193
|
if (replacement === null)
|
|
32051
33194
|
continue;
|
|
33195
|
+
if (replacement === entry.event)
|
|
33196
|
+
return;
|
|
32052
33197
|
this.retainedBytes -= Math.max(0, this.measureBytes(entry.event));
|
|
32053
33198
|
entry.event = replacement;
|
|
32054
33199
|
this.retainedBytes += Math.max(0, this.measureBytes(replacement));
|
|
32055
|
-
return;
|
|
32056
33200
|
}
|
|
32057
33201
|
}
|
|
32058
33202
|
since(cursor) {
|
|
@@ -32147,6 +33291,7 @@ function installFatalRejectionGuard(options) {
|
|
|
32147
33291
|
const APP_PATH = /(?:^|\/)((?:apps\/(?:backend|desktop|web|web-public)|packages\/(?:protocol|cli|toolchain)|bridges\/[\w-]+|[\w-]+-bridge)\/.*)$/;
|
|
32148
33292
|
const PACKAGED_PATH = /\/((?:app\.asar(?:\.unpacked)?|resources)\/.*)$/i;
|
|
32149
33293
|
const CREDENTIALS = [
|
|
33294
|
+
{ pattern: /\bok[ab]_[A-Za-z0-9_-]{16,}/g, replacement: "[redacted]" },
|
|
32150
33295
|
{
|
|
32151
33296
|
pattern: /([a-z][a-z0-9+.-]*:\/\/)[^/\s:@]+(?::[^/\s@]*)?@/gi,
|
|
32152
33297
|
replacement: "$1[redacted]@"
|
|
@@ -32274,9 +33419,9 @@ function installFatalRejectionGuard(options) {
|
|
|
32274
33419
|
}
|
|
32275
33420
|
|
|
32276
33421
|
// ../protocol/src/node/process-failure-log.ts
|
|
32277
|
-
var
|
|
33422
|
+
var log21 = createLogger("process");
|
|
32278
33423
|
function logUnhandledRejection(reason) {
|
|
32279
|
-
|
|
33424
|
+
log21.throttled("error", "rejection.unhandled", {
|
|
32280
33425
|
error: reason,
|
|
32281
33426
|
fields: () => ({ error: formatLogError(reason, { message: false }) })
|
|
32282
33427
|
});
|
|
@@ -32301,7 +33446,7 @@ var CODEX_FALLBACK_MODEL_CATALOG = [
|
|
|
32301
33446
|
];
|
|
32302
33447
|
|
|
32303
33448
|
// ../../bridges/codex-bridge/src/models-cache.ts
|
|
32304
|
-
var
|
|
33449
|
+
var log22 = createLogger("bridge.codex");
|
|
32305
33450
|
var MODEL_REASONING_EFFORTS = new Set([
|
|
32306
33451
|
"minimal",
|
|
32307
33452
|
"low",
|
|
@@ -32448,13 +33593,13 @@ class ModelCatalogCache {
|
|
|
32448
33593
|
await this.opts.writePersistedCache(models);
|
|
32449
33594
|
}
|
|
32450
33595
|
} catch (error) {
|
|
32451
|
-
|
|
33596
|
+
log22.warn("models.refresh-failed", { error: formatLogError(error, { stack: false }) });
|
|
32452
33597
|
}
|
|
32453
33598
|
}
|
|
32454
33599
|
}
|
|
32455
33600
|
|
|
32456
33601
|
// ../../bridges/codex-bridge/src/index.ts
|
|
32457
|
-
var
|
|
33602
|
+
var log23 = createLogger("bridge.codex");
|
|
32458
33603
|
configureBridgeLogger();
|
|
32459
33604
|
var WORKFLOW_RESULT_TOOL_NAMES2 = new Set(WORKFLOW_RESULT_KINDS.map(workflowResultToolName));
|
|
32460
33605
|
function isWorkflowResultTool(value) {
|
|
@@ -32484,14 +33629,14 @@ function isScopedAgentMcp(value) {
|
|
|
32484
33629
|
var app = new Hono2;
|
|
32485
33630
|
app.onError((error, c) => {
|
|
32486
33631
|
if (error instanceof PolicyWideningRefusedError) {
|
|
32487
|
-
|
|
33632
|
+
log23.warn("session.policy-widening-refused", { widened: error.widened.join(",") });
|
|
32488
33633
|
return c.json(error.refusal(), 403);
|
|
32489
33634
|
}
|
|
32490
33635
|
if ("getResponse" in error) {
|
|
32491
33636
|
const response = error.getResponse();
|
|
32492
33637
|
return c.newResponse(response.body, response);
|
|
32493
33638
|
}
|
|
32494
|
-
|
|
33639
|
+
log23.error("http.request-failed", {
|
|
32495
33640
|
method: c.req.method,
|
|
32496
33641
|
path: c.req.path,
|
|
32497
33642
|
error: formatLogError(error)
|
|
@@ -32505,12 +33650,11 @@ function boundCodexTranscriptResponse(messages, tailMessages) {
|
|
|
32505
33650
|
}
|
|
32506
33651
|
var BRIDGE_TOKEN_ENV = "CODEX_BRIDGE_TOKEN";
|
|
32507
33652
|
var BRIDGE_ALLOWED_ORIGINS_ENV = "CODEX_BRIDGE_ALLOWED_ORIGINS";
|
|
32508
|
-
var
|
|
32509
|
-
delete process.env[BRIDGE_TOKEN_ENV];
|
|
33653
|
+
var bridgeCredential = loadBridgeCredential(BRIDGE_TOKEN_ENV);
|
|
32510
33654
|
var bridgeAuthEnabledOverrideForTesting = null;
|
|
32511
33655
|
var sseRouteTestHooks = null;
|
|
32512
33656
|
var BRIDGE_VERSION = "1.0.0";
|
|
32513
|
-
var
|
|
33657
|
+
var execFile3 = promisify2(execFileCallback2);
|
|
32514
33658
|
var subscribers = new Set;
|
|
32515
33659
|
var observers = new Set;
|
|
32516
33660
|
function observationFrameData(sessionId) {
|
|
@@ -32520,10 +33664,10 @@ function notifyObservers(event, revision) {
|
|
|
32520
33664
|
for (const observer of observers) {
|
|
32521
33665
|
try {
|
|
32522
33666
|
Promise.resolve(observer(event, revision, "{}")).catch((error) => {
|
|
32523
|
-
|
|
33667
|
+
log23.warn("sse.observer-failed", { error: formatLogError(error) });
|
|
32524
33668
|
});
|
|
32525
33669
|
} catch (error) {
|
|
32526
|
-
|
|
33670
|
+
log23.warn("sse.observer-failed", { error: formatLogError(error) });
|
|
32527
33671
|
}
|
|
32528
33672
|
}
|
|
32529
33673
|
}
|
|
@@ -32590,11 +33734,6 @@ function acquireReplayRetention() {
|
|
|
32590
33734
|
}
|
|
32591
33735
|
scheduleReplayRetentionDrop();
|
|
32592
33736
|
var CLEANUP_INTERVAL_MS = 5 * 60 * 1000;
|
|
32593
|
-
var codexRawLogDir = normalizeOptionalEnvPath("ORKESTRATOR_CODEX_RAW_LOG_DIR");
|
|
32594
|
-
function normalizeOptionalEnvPath(name) {
|
|
32595
|
-
const value = process.env[name]?.trim();
|
|
32596
|
-
return value ? value : null;
|
|
32597
|
-
}
|
|
32598
33737
|
function isBridgeAuthEnabled() {
|
|
32599
33738
|
if (bridgeAuthEnabledOverrideForTesting !== null) {
|
|
32600
33739
|
return bridgeAuthEnabledOverrideForTesting;
|
|
@@ -32602,11 +33741,7 @@ function isBridgeAuthEnabled() {
|
|
|
32602
33741
|
return !(process.env.CODEX_BRIDGE_NO_SERVER === "1" && process.env.CODEX_BRIDGE_AUTH_DISABLED_FOR_TESTING === "1");
|
|
32603
33742
|
}
|
|
32604
33743
|
function tokenMatches(candidate) {
|
|
32605
|
-
|
|
32606
|
-
return false;
|
|
32607
|
-
const expected = Buffer.from(bridgeAuthToken);
|
|
32608
|
-
const actual = Buffer.from(candidate);
|
|
32609
|
-
return expected.length === actual.length && timingSafeEqual(expected, actual);
|
|
33744
|
+
return bridgeCredential.matches(candidate);
|
|
32610
33745
|
}
|
|
32611
33746
|
function bearerToken(header) {
|
|
32612
33747
|
if (!header)
|
|
@@ -32632,33 +33767,6 @@ function isTrustedBridgeOrigin(origin) {
|
|
|
32632
33767
|
function isPublicHealthRequest(method, path) {
|
|
32633
33768
|
return method === "GET" && path === "/global/health";
|
|
32634
33769
|
}
|
|
32635
|
-
function sanitizeLogFileComponent(value) {
|
|
32636
|
-
return value.replace(/[^a-zA-Z0-9._-]/g, "_");
|
|
32637
|
-
}
|
|
32638
|
-
function normalizeLogPayload(value) {
|
|
32639
|
-
try {
|
|
32640
|
-
return JSON.parse(JSON.stringify(value));
|
|
32641
|
-
} catch {
|
|
32642
|
-
return stringifyUnknown(value);
|
|
32643
|
-
}
|
|
32644
|
-
}
|
|
32645
|
-
async function writeCodexRawLog(sessionId, entry, logDir = codexRawLogDir) {
|
|
32646
|
-
if (!logDir) {
|
|
32647
|
-
return;
|
|
32648
|
-
}
|
|
32649
|
-
try {
|
|
32650
|
-
await mkdir9(logDir, { recursive: true });
|
|
32651
|
-
const filename = `${sanitizeLogFileComponent(sessionId)}.jsonl`;
|
|
32652
|
-
await appendFile5(join23(logDir, filename), `${JSON.stringify({
|
|
32653
|
-
timestamp: new Date().toISOString(),
|
|
32654
|
-
sessionId,
|
|
32655
|
-
...entry
|
|
32656
|
-
})}
|
|
32657
|
-
`, "utf8");
|
|
32658
|
-
} catch (error) {
|
|
32659
|
-
log21.warn("raw-log.write-failed", { error: formatLogError(error) });
|
|
32660
|
-
}
|
|
32661
|
-
}
|
|
32662
33770
|
function createShutdownHandler(timer, clearTimer = clearInterval, exit = (code) => process.exit(code), stopEngine = () => stopSelectedEngine()) {
|
|
32663
33771
|
let shuttingDown = false;
|
|
32664
33772
|
return () => {
|
|
@@ -32667,12 +33775,12 @@ function createShutdownHandler(timer, clearTimer = clearInterval, exit = (code)
|
|
|
32667
33775
|
shuttingDown = true;
|
|
32668
33776
|
clearTimer(timer);
|
|
32669
33777
|
stopEngine().catch((error) => {
|
|
32670
|
-
|
|
33778
|
+
log23.warn("engine.stop-failed", { error: formatLogError(error) });
|
|
32671
33779
|
}).finally(() => exit(0));
|
|
32672
33780
|
};
|
|
32673
33781
|
}
|
|
32674
33782
|
function createParentExitHandler(interrupt, shutdown, report = (turns, ms) => {
|
|
32675
|
-
|
|
33783
|
+
log23.info("turns.stopped", { turns, elapsedMs: ms });
|
|
32676
33784
|
}) {
|
|
32677
33785
|
return async () => {
|
|
32678
33786
|
const detectedAt = performance.now();
|
|
@@ -32703,7 +33811,7 @@ function serializeSseEventData(event) {
|
|
|
32703
33811
|
...event.data
|
|
32704
33812
|
});
|
|
32705
33813
|
} catch {
|
|
32706
|
-
|
|
33814
|
+
log23.error("sse.payload-serialize-failed");
|
|
32707
33815
|
return JSON.stringify({
|
|
32708
33816
|
sessionId: event.sessionId,
|
|
32709
33817
|
error: "payload could not be serialized"
|
|
@@ -32768,7 +33876,7 @@ function emit(event) {
|
|
|
32768
33876
|
messageId = retainedMessageId(event.type, payload);
|
|
32769
33877
|
bytes = eager === null ? estimateSsePayloadBytes(payload) : Buffer.byteLength(eager, "utf8");
|
|
32770
33878
|
} catch {
|
|
32771
|
-
|
|
33879
|
+
log23.error("sse.payload-snapshot-failed");
|
|
32772
33880
|
payload = { error: "payload could not be serialized" };
|
|
32773
33881
|
eager = subscribers.size > 0 ? serializeSseEventData({ sessionId, data: payload }) : null;
|
|
32774
33882
|
messageId = undefined;
|
|
@@ -32785,10 +33893,10 @@ function emit(event) {
|
|
|
32785
33893
|
for (const subscriber of subscribers) {
|
|
32786
33894
|
try {
|
|
32787
33895
|
Promise.resolve(subscriber(event, revision, eager ?? "{}")).catch((error) => {
|
|
32788
|
-
|
|
33896
|
+
log23.warn("sse.subscriber-failed", { error: formatLogError(error) });
|
|
32789
33897
|
});
|
|
32790
33898
|
} catch (error) {
|
|
32791
|
-
|
|
33899
|
+
log23.warn("sse.subscriber-failed", { error: formatLogError(error) });
|
|
32792
33900
|
}
|
|
32793
33901
|
}
|
|
32794
33902
|
}
|
|
@@ -32815,7 +33923,7 @@ async function writePersistedBridgeCache(models) {
|
|
|
32815
33923
|
await mkdir9(bridgeCacheDir(), { recursive: true });
|
|
32816
33924
|
await writeFile6(bridgeCachePath(), JSON.stringify({ version: BRIDGE_MODEL_CACHE_VERSION, at: Date.now(), models }, null, 2));
|
|
32817
33925
|
} catch (error) {
|
|
32818
|
-
|
|
33926
|
+
log23.warn("models.cache-persist-failed", { error: formatLogError(error, { stack: false }) });
|
|
32819
33927
|
}
|
|
32820
33928
|
}
|
|
32821
33929
|
async function readCodexCliModelCache() {
|
|
@@ -32827,7 +33935,7 @@ async function readCodexCliModelCache() {
|
|
|
32827
33935
|
return null;
|
|
32828
33936
|
}
|
|
32829
33937
|
}
|
|
32830
|
-
async function fetchLiveModelsFromCli(run =
|
|
33938
|
+
async function fetchLiveModelsFromCli(run = execFile3, env = process.env) {
|
|
32831
33939
|
const codexPath = env.CODEX_PATH || "codex";
|
|
32832
33940
|
try {
|
|
32833
33941
|
const { stdout } = await run(codexPath, ["debug", "models"], {
|
|
@@ -32837,7 +33945,7 @@ async function fetchLiveModelsFromCli(run = execFile4, env = process.env) {
|
|
|
32837
33945
|
const models = parseModelCatalog(stdout);
|
|
32838
33946
|
return models.length > 0 ? models : null;
|
|
32839
33947
|
} catch (error) {
|
|
32840
|
-
|
|
33948
|
+
log23.warn("models.debug-read-failed", { error: formatLogError(error, { stack: false }) });
|
|
32841
33949
|
return null;
|
|
32842
33950
|
}
|
|
32843
33951
|
}
|
|
@@ -32882,7 +33990,7 @@ async function sweepIdleThreads(runtime = appServerRuntime) {
|
|
|
32882
33990
|
try {
|
|
32883
33991
|
await runtime.sweepIdle();
|
|
32884
33992
|
} catch (error) {
|
|
32885
|
-
|
|
33993
|
+
log23.warn("idle-sweep.failed", { error: formatLogError(error) });
|
|
32886
33994
|
}
|
|
32887
33995
|
}
|
|
32888
33996
|
function createCodexProcessDiagnostics(runtime = appServerRuntime) {
|
|
@@ -32918,9 +34026,9 @@ async function startSelectedEngine(env = process.env, runtime = appServerRuntime
|
|
|
32918
34026
|
}
|
|
32919
34027
|
try {
|
|
32920
34028
|
await runtime.start();
|
|
32921
|
-
|
|
34029
|
+
log23.info("engine.ready", { codexVersion: runtime.getHealth().codexVersion ?? "unknown" });
|
|
32922
34030
|
} catch (error) {
|
|
32923
|
-
|
|
34031
|
+
log23.error("engine.start-failed", { error: formatLogError(error, { stack: false }) });
|
|
32924
34032
|
}
|
|
32925
34033
|
}
|
|
32926
34034
|
var __testing = {
|
|
@@ -32958,7 +34066,6 @@ var __testing = {
|
|
|
32958
34066
|
hydrateMessagesFromPersistedSessionForTesting: hydrateMessagesFromPersistedSession,
|
|
32959
34067
|
listPersistedSessionsForCwdForTesting: listPersistedSessionsForCwd,
|
|
32960
34068
|
mergePersistedSessionMetaForTesting: mergePersistedSessionMeta,
|
|
32961
|
-
normalizeLogPayloadForTesting: normalizeLogPayload,
|
|
32962
34069
|
readPersistedBridgeCache,
|
|
32963
34070
|
readCodexCliModelCache,
|
|
32964
34071
|
readTextFileIfPresentForTesting: readTextFileIfPresent,
|
|
@@ -32969,11 +34076,10 @@ var __testing = {
|
|
|
32969
34076
|
bridgeAuthEnabledOverrideForTesting = null;
|
|
32970
34077
|
return;
|
|
32971
34078
|
}
|
|
32972
|
-
|
|
34079
|
+
bridgeCredential = bridgeCredentialFromToken(token);
|
|
32973
34080
|
bridgeAuthEnabledOverrideForTesting = true;
|
|
32974
34081
|
},
|
|
32975
34082
|
isTrustedBridgeOriginForTesting: isTrustedBridgeOrigin,
|
|
32976
|
-
sanitizeLogFileComponentForTesting: sanitizeLogFileComponent,
|
|
32977
34083
|
serializeSseEventDataForTesting: serializeSseEventData,
|
|
32978
34084
|
setSseRouteTestHooksForTesting: (hooks) => {
|
|
32979
34085
|
sseRouteTestHooks = hooks;
|
|
@@ -32991,7 +34097,6 @@ var __testing = {
|
|
|
32991
34097
|
releaseReplayRetention();
|
|
32992
34098
|
};
|
|
32993
34099
|
},
|
|
32994
|
-
writeCodexRawLogForTesting: writeCodexRawLog,
|
|
32995
34100
|
writePersistedBridgeCache
|
|
32996
34101
|
};
|
|
32997
34102
|
function startSseKeepalive(writeSSE, intervalMs = 5000, shouldSendAtActiveCadence = () => true, idleIntervalMs = 30000) {
|
|
@@ -33006,7 +34111,7 @@ function startSseKeepalive(writeSSE, intervalMs = 5000, shouldSendAtActiveCadenc
|
|
|
33006
34111
|
id: String(eventRing.latestRevision),
|
|
33007
34112
|
data: "{}"
|
|
33008
34113
|
}).catch((error) => {
|
|
33009
|
-
|
|
34114
|
+
log23.warn("sse.keepalive-failed", { error: formatLogError(error, { stack: false }) });
|
|
33010
34115
|
});
|
|
33011
34116
|
}, intervalMs);
|
|
33012
34117
|
}
|
|
@@ -33262,7 +34367,7 @@ app.get("/session/:id/usage", async (c) => {
|
|
|
33262
34367
|
return c.json({ error: "Session not found" }, 404);
|
|
33263
34368
|
return c.json({ contextUsage });
|
|
33264
34369
|
} catch (error) {
|
|
33265
|
-
|
|
34370
|
+
log23.warn("account.usage-read-failed", { error: formatLogError(error, { stack: false }) });
|
|
33266
34371
|
return c.json({ error: "Account usage is temporarily unavailable" }, 503);
|
|
33267
34372
|
}
|
|
33268
34373
|
});
|
|
@@ -33673,7 +34778,7 @@ app.get("/event/subscribe", (c) => {
|
|
|
33673
34778
|
if (!open)
|
|
33674
34779
|
return;
|
|
33675
34780
|
open = false;
|
|
33676
|
-
|
|
34781
|
+
log23.info("sse.closed", { reason });
|
|
33677
34782
|
resolveConnectionClosed();
|
|
33678
34783
|
};
|
|
33679
34784
|
const writeWhileOpen = createSerializedSseWriter(createOpenSseWriter(() => open, (event) => stream.writeSSE(event)), { onOverflow: () => failSlowSubscriber("write backlog exceeded its cap") });
|
|
@@ -33821,7 +34926,7 @@ if (parentPid !== null) {
|
|
|
33821
34926
|
startParentWatchdog({
|
|
33822
34927
|
parentPid,
|
|
33823
34928
|
onParentExit: () => {
|
|
33824
|
-
|
|
34929
|
+
log23.warn("parent.gone", { parentPid });
|
|
33825
34930
|
createParentExitHandler((budgetMs) => appServerRuntime.interruptForParentExit(budgetMs), shutdownHandler)();
|
|
33826
34931
|
}
|
|
33827
34932
|
});
|