@bitkyc08/opencodex 2.96.0 → 2.98.0-preview.20261107
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/bin/ocx.mjs +215 -20
- package/gui/dist/assets/App-6TFtZsUF.css +1 -0
- package/gui/dist/assets/App-B8_sOxoz.js +59 -0
- package/gui/dist/assets/Tray-DpWEp6ee.js +1 -0
- package/gui/dist/assets/WantedSansVariable.split.0-Dwvb1WRx.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.1-1wKD2RxI.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.10-CAKA6LIP.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.11-k5H85R4b.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.12-BHboLsUv.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.13-9GV377ix.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.14-DovDXnrj.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.15-DTdykCig.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.16-CKz2ccgK.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.17-Z2RD_KRZ.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.18-BcKtfonJ.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.19-DEQPOSZn.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.2-DryboyuA.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.20-Bia5JMls.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.21-Cr4jFw-E.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.22-DjjB69TZ.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.23-CvUzJskt.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.24-i_eMg5ox.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.25-2aKHwPX-.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.26-B6wXoCEL.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.27-D4h1WfGM.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.28-kvRPCStd.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.29-DHAiwleD.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.3-7H--eyZi.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.30-C66cfAY2.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.31-FDmtiNim.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.32-DouHt2Dd.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.33-B8HVvkJX.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.34-BtkRu1FN.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.35-DBylQbtk.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.36-Sg089Kgh.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.37-CYtvbriS.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.38-DKkSLf8Z.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.39-CecotKZD.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.4-Bv8O3ZMb.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.40-DdCvkmOU.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.41-ESn674Hc.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.42-DL9V7NNV.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.43-yipO0cyk.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.44-6rTmLZhm.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.45-BJAj8lrm.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.46-BDTzMn2c.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.47-Bxd4wGgi.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.48-DxnFBLnH.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.49-DnVD0aOD.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.5-B1wI2pp5.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.50-D9JlkZd6.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.51-D9Vw6Bu3.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.52-ClEJk4kn.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.53-BSXU0vh-.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.54-EcuxkR9v.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.55-CYiFhQX8.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.56--Gk9g8BK.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.57-DnkOPZcy.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.58-9MB8504z.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.59-ByxIsN72.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.6-Bmk0dRVw.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.60-Bxwx_aWQ.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.61-DA2z5sm7.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.62-C5iJPJZn.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.63-DAqrmaEc.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.64-BgXFsljb.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.65-DKiWujvu.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.66-8po4vUZ4.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.67-Cy5qyI9O.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.68-BKny7Fy3.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.69-B4VU4u_b.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.7-BuqwNpgA.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.70-BCd4n346.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.71-CkQppaWn.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.72-Db7vaoFs.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.73-DI80TYWl.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.74-tMCtDAHB.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.75-Ciw0D5WG.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.76-DoLjFgp-.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.77-CpT2uvMy.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.78-CkcJ4iZ1.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.79-DsOUJjEM.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.8-DsjypPd6.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.80-C0VwHTte.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.81-DTelu57i.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.82-BiMndGN1.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.83-CVcC6eDG.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.84-DlhZVt_O.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.85-S8I2D3pA.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.86-DozXXpH5.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.87-Dsn0Vuuo.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.88-iNwxxDCr.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.89-B63u_9CZ.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.9-Bi3IzpMI.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.90-ByeH1Pqf.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.91-UQLlagpm.woff2 +0 -0
- package/gui/dist/assets/brand-mark-VPhzz-WE.js +1 -0
- package/gui/dist/assets/geist-cyrillic-ext-wght-normal-DjL33-gN.woff2 +0 -0
- package/gui/dist/assets/geist-cyrillic-wght-normal-BEAKL7Jp.woff2 +0 -0
- package/gui/dist/assets/geist-latin-ext-wght-normal-DC-KSUi6.woff2 +0 -0
- package/gui/dist/assets/geist-latin-wght-normal-BgDaEnEv.woff2 +0 -0
- package/gui/dist/assets/geist-mono-cyrillic-ext-wght-normal-X_5orZeX.woff2 +0 -0
- package/gui/dist/assets/geist-mono-cyrillic-wght-normal-DiZS0aHC.woff2 +0 -0
- package/gui/dist/assets/geist-mono-latin-ext-wght-normal-Bwz-egvJ.woff2 +0 -0
- package/gui/dist/assets/geist-mono-latin-wght-normal-XN7g48iV.woff2 +0 -0
- package/gui/dist/assets/geist-mono-symbols2-wght-normal-CO5SzqOn.woff2 +0 -0
- package/gui/dist/assets/geist-mono-vietnamese-wght-normal-DadHysG0.woff2 +0 -0
- package/gui/dist/assets/geist-vietnamese-wght-normal-6IgcOCM7.woff2 +0 -0
- package/gui/dist/assets/index-5REODpG3.css +2 -0
- package/gui/dist/assets/index-BWKBeK77.js +94 -0
- package/gui/dist/assets/segment-thumb-features-BQYzrze9.js +1 -0
- package/gui/dist/classic/assets/App-Bz65x1J6.js +58 -0
- package/gui/dist/{assets/Tray-BOPQyDbH.js → classic/assets/Tray-kk7mdO6I.js} +1 -1
- package/gui/dist/classic/assets/index-Dp2j8bSc.js +94 -0
- package/gui/dist/classic/assets/quota-summary-CvamtHjB.js +1 -0
- package/gui/dist/classic/index.html +47 -0
- package/gui/dist/favicon.png +0 -0
- package/gui/dist/favicon.svg +14 -0
- package/gui/dist/index.html +15 -2
- package/package.json +1 -1
- package/src/adapters/anthropic.ts +17 -8
- package/src/adapters/command-code.ts +15 -16
- package/src/adapters/cursor/transport-retry.ts +2 -2
- package/src/adapters/devin/cloud-direct/chat.ts +15 -6
- package/src/adapters/google.ts +7 -7
- package/src/adapters/kiro/adapter.ts +18 -3
- package/src/adapters/kiro/conversation.ts +8 -8
- package/src/adapters/kiro/payload.ts +45 -12
- package/src/adapters/kiro/stream.ts +230 -14
- package/src/adapters/kiro/structured-output-json.ts +191 -0
- package/src/adapters/kiro/structured-output-schema.ts +542 -0
- package/src/adapters/kiro/structured-output.ts +367 -0
- package/src/adapters/kiro-constants.ts +24 -1
- package/src/adapters/kiro-events.ts +31 -1
- package/src/adapters/kiro-retry.ts +3 -3
- package/src/adapters/kiro-tools.ts +14 -9
- package/src/adapters/kiro-wire.ts +9 -5
- package/src/adapters/ollama-native.ts +11 -1
- package/src/adapters/openai-chat/messages.ts +58 -5
- package/src/adapters/openai-chat/mistral-image-limit.ts +50 -0
- package/src/adapters/openai-chat/passthrough.ts +5 -3
- package/src/adapters/openai-chat/tool-schema.ts +83 -13
- package/src/adapters/openai-responses/empty-assistant.ts +15 -3
- package/src/adapters/openai-responses/opengateway-input.ts +18 -6
- package/src/adapters/openai-responses/passthrough.ts +5 -4
- package/src/adapters/openai-responses/reasoning.ts +9 -4
- package/src/adapters/openai-responses/request-strips.ts +1 -1
- package/src/adapters/openai-responses/tool-output-recovery.ts +79 -0
- package/src/adapters/physical-send.ts +3 -3
- package/src/adapters/qoder/live-models.ts +115 -1
- package/src/adapters/zed-openai-stream.ts +2 -1
- package/src/bridge/errors.ts +11 -2
- package/src/bridge/response-json.ts +2 -1
- package/src/bridge/sse.ts +14 -6
- package/src/chat/failure-verdict.ts +21 -0
- package/src/chat/outbound.ts +139 -21
- package/src/claude/failure-verdict.ts +21 -0
- package/src/claude/inbound-content-options.ts +15 -2
- package/src/claude/inbound-model-options.ts +2 -1
- package/src/claude/inbound-records.ts +2 -0
- package/src/claude/inbound.ts +17 -11
- package/src/claude/outbound.ts +98 -22
- package/src/cli/capabilities-access-remote.ts +13 -0
- package/src/cli/capabilities-base.ts +26 -3
- package/src/cli/capabilities-command.ts +12 -3
- package/src/cli/capabilities-provider-models.ts +3 -3
- package/src/cli/capability-contracts.ts +2 -0
- package/src/cli/codex-launch-auth.ts +30 -1
- package/src/cli/codex-launcher.ts +12 -5
- package/src/cli/codex-shim-autorestore.ts +12 -4
- package/src/cli/config-command.ts +11 -2
- package/src/cli/connect.ts +17 -2
- package/src/cli/dispatch.ts +14 -177
- package/src/cli/doctor.ts +95 -7
- package/src/cli/help.ts +2 -2
- package/src/cli/index.ts +17 -8
- package/src/cli/link-apply-restart.ts +9 -2
- package/src/cli/link.ts +1 -1
- package/src/cli/models.ts +124 -38
- package/src/cli/registry.ts +12 -4
- package/src/cli/restart-failure.ts +17 -0
- package/src/cli/root.ts +8 -0
- package/src/cli/stop-approval.ts +2 -2
- package/src/cli/sync-command.ts +243 -0
- package/src/cli/sync-fanout-process.ts +92 -0
- package/src/cli/sync-fanout.ts +161 -0
- package/src/cli/sync-flags.ts +10 -0
- package/src/cli/sync-link-status.ts +39 -0
- package/src/cli/sync-update-guard.ts +18 -0
- package/src/cli/system-restart-client.ts +5 -0
- package/src/cli/uninstall-client-state.ts +12 -1
- package/src/cli/update-restart-child.ts +13 -3
- package/src/cli/update-restart-home.ts +6 -3
- package/src/cli/update-restart.ts +36 -19
- package/src/client/connect.ts +35 -15
- package/src/client/hub-client.ts +5 -0
- package/src/client/link-home.ts +3 -2
- package/src/client/link-management-relay.ts +39 -2
- package/src/client/link-readiness.ts +3 -1
- package/src/client/machine-api.ts +2 -1
- package/src/client/machine-listener.ts +10 -0
- package/src/client/orphan-token-recovery.ts +322 -0
- package/src/client/restore-ownership.ts +19 -1
- package/src/client/runtime-restart.ts +12 -4
- package/src/client/runtime.ts +40 -11
- package/src/client/stop-routing.ts +62 -0
- package/src/client/sync-runtime.ts +65 -0
- package/src/clients/config-export.ts +32 -3
- package/src/codex/auth-context.ts +49 -103
- package/src/codex/catalog/antigravity-discovery.ts +16 -5
- package/src/codex/catalog/provider-models.ts +18 -12
- package/src/codex/forward-transport-headers.ts +35 -6
- package/src/codex/inject/config-toml.ts +88 -0
- package/src/codex/inject/multi-agent-v2.ts +30 -4
- package/src/codex/inject/plan.ts +34 -7
- package/src/codex/inject-coordination.ts +11 -0
- package/src/codex/inject.ts +18 -7
- package/src/codex/lineage.ts +13 -7
- package/src/codex/native-profile-api.ts +27 -1
- package/src/codex/quota.ts +22 -6
- package/src/codex/request-owned-affinity-key.ts +11 -0
- package/src/codex/request-owned-affinity.ts +118 -0
- package/src/codex/request-owned-main-pin.ts +86 -0
- package/src/codex/role-capability.ts +52 -41
- package/src/codex/routing/active-account.ts +13 -5
- package/src/codex/routing/selection.ts +40 -1
- package/src/codex/routing/thread-affinity-store.ts +916 -0
- package/src/codex/routing/thread-affinity.ts +90 -12
- package/src/codex/shim-diagnostics.ts +7 -0
- package/src/codex/shim-legacy-record.ts +290 -0
- package/src/codex/shim-windows-refresh.ts +9 -2
- package/src/codex/shim-wrapper-write.ts +7 -0
- package/src/codex/shim.ts +80 -21
- package/src/codex/toml-source-lines.ts +72 -13
- package/src/combos/failover.ts +6 -109
- package/src/combos/request.ts +2 -2
- package/src/combos/resolve.ts +29 -11
- package/src/config/diagnostics.ts +9 -9
- package/src/config/load-degrade.ts +27 -27
- package/src/config/process-state.ts +5 -0
- package/src/config/provider-validation.ts +9 -2
- package/src/config/removed-opencode-free-backup.ts +6 -3
- package/src/config/schema/leaf-validators.ts +1 -0
- package/src/config/tracked-runtime-inspection.ts +3 -3
- package/src/generated/compatibility-version.json +595 -255
- package/src/images/loop.ts +4 -3
- package/src/lib/client-error-body.ts +215 -0
- package/src/lib/client-retry-after.ts +66 -0
- package/src/lib/config-ownership-removal.ts +422 -0
- package/src/lib/config-ownership.ts +650 -81
- package/src/lib/context-overflow-verdict.ts +113 -0
- package/src/lib/crash-guard.ts +4 -2
- package/src/lib/desktop-cli-handoff.d.mts +4 -5
- package/src/lib/desktop-cli-handoff.mjs +18 -17
- package/src/lib/empty-tool-catalog.ts +25 -3
- package/src/lib/error-destination.ts +47 -0
- package/src/lib/errors.ts +1 -0
- package/src/lib/failure-detail.ts +66 -0
- package/src/lib/local-management-capability.ts +3 -1
- package/src/lib/messages-error-body.ts +162 -0
- package/src/lib/messages-sse-error-presentation.ts +93 -0
- package/src/lib/model-identity.ts +44 -0
- package/src/lib/passive-read.ts +9 -4
- package/src/lib/private-sqlite-path.ts +124 -0
- package/src/lib/response-service-tier.ts +17 -0
- package/src/lib/retry-after.ts +3 -0
- package/src/lib/socks5-fetch.ts +21 -9
- package/src/lib/spend-ledger-owner.ts +43 -4
- package/src/lib/upstream-condition.ts +142 -0
- package/src/lib/upstream-retry.ts +95 -12
- package/src/lib/windows-owner-acl.ts +22 -9
- package/src/lib/winsw.ts +5 -5
- package/src/lib/workflow-budget.ts +3 -1
- package/src/link/remote-platform.ts +14 -0
- package/src/link/remote-windows.ts +51 -9
- package/src/link/ssh-argv.ts +63 -10
- package/src/oauth/generic-account-failover.ts +13 -11
- package/src/oauth/index.ts +42 -73
- package/src/oauth/oauth-errors.ts +67 -0
- package/src/oauth/store.ts +21 -11
- package/src/protocols/codecs/messages-ir.ts +15 -9
- package/src/protocols/codecs/ollama.ts +197 -0
- package/src/protocols/encoders/adapter-events.ts +30 -7
- package/src/protocols/encoders/chat.ts +18 -10
- package/src/protocols/encoders/messages.ts +72 -28
- package/src/protocols/trace.ts +18 -0
- package/src/providers/antigravity-models.ts +45 -12
- package/src/providers/fastwire.ts +3 -2
- package/src/providers/free-directory.ts +2 -2
- package/src/providers/quota/anthropic-usage-windows.ts +13 -3
- package/src/providers/quota/vendor-probes-key.ts +60 -24
- package/src/providers/reasoning-metadata.ts +2 -1
- package/src/providers/registry/entries-extended.ts +9 -0
- package/src/providers/request-pacing.ts +3 -2
- package/src/reasoning-effort.ts +7 -2
- package/src/remote/hub-usage.ts +3 -0
- package/src/responses/apply-patch-envelope.ts +45 -19
- package/src/responses/compaction-history-framing.ts +5 -1
- package/src/responses/freeform-wrapper-scan.ts +5 -3
- package/src/responses/progressive-freeform-input.ts +354 -45
- package/src/routing/fallback-policy.ts +3 -1
- package/src/server/admission-model-scope.ts +17 -6
- package/src/server/admitted-http-turn.ts +57 -0
- package/src/server/anthropic-rate-limit-headers.ts +75 -3
- package/src/server/auth-cors.ts +5 -0
- package/src/server/chat-completions.ts +45 -20
- package/src/server/chat-native-sse.ts +52 -7
- package/src/server/chat-native.ts +60 -35
- package/src/server/claude-bridge-pool-session.ts +59 -0
- package/src/server/claude-messages.ts +174 -84
- package/src/server/context-history.ts +5 -1
- package/src/server/gui-static.ts +4 -1
- package/src/server/hub-usage.ts +7 -2
- package/src/server/inbound-body-admission.ts +11 -4
- package/src/server/index/link-management.ts +8 -0
- package/src/server/index/ollama-routes.ts +91 -0
- package/src/server/index/serve-options.ts +44 -24
- package/src/server/index/startup-warnings.ts +5 -12
- package/src/server/index/websocket-handler.ts +5 -2
- package/src/server/index.ts +6 -36
- package/src/server/inference/client-encoder-delivery.ts +9 -3
- package/src/server/json-serialized-bytes.ts +44 -0
- package/src/server/management/agent-settings-routes.ts +24 -21
- package/src/server/management/codex-cli-update-routes.ts +2 -1
- package/src/server/management/logs-usage-routes.ts +89 -4
- package/src/server/management/provider-routes.ts +2 -22
- package/src/server/management/qoder-provider-probe.ts +105 -0
- package/src/server/management/route-registry.ts +4 -1
- package/src/server/management/usage-aggregate-cache.ts +15 -5
- package/src/server/management/usage-source-facets.ts +38 -0
- package/src/server/messages-native-scope.ts +2 -1
- package/src/server/messages-native-tool-guard.ts +12 -4
- package/src/server/messages-native.ts +123 -47
- package/src/server/messages-response-headers.ts +25 -11
- package/src/server/messages-shared.ts +99 -65
- package/src/server/messages-sse-error-filter.ts +199 -0
- package/src/server/native-final-log.ts +93 -0
- package/src/server/ollama-inbound.ts +349 -0
- package/src/server/ollama-native-paths.ts +21 -0
- package/src/server/ollama-route-policy.ts +73 -0
- package/src/server/relay.ts +22 -3
- package/src/server/request-decompress.ts +4 -2
- package/src/server/request-log-failure-attribution.ts +22 -0
- package/src/server/request-log-failure-detail.ts +80 -0
- package/src/server/request-log-terminal-status.ts +4 -2
- package/src/server/request-log.ts +91 -42
- package/src/server/response-log-body.ts +6 -1
- package/src/server/responses/account-change-state.ts +17 -6
- package/src/server/responses/adapter-continuation.ts +17 -6
- package/src/server/responses/adapter-delivery.ts +17 -10
- package/src/server/responses/adapter-dispatch.ts +32 -31
- package/src/server/responses/anthropic-thinking-recovery.ts +3 -0
- package/src/server/responses/codex-auth-error.ts +24 -19
- package/src/server/responses/codex-ws-exchange.ts +11 -8
- package/src/server/responses/codex-ws-metadata.ts +94 -21
- package/src/server/responses/codex-ws-request.ts +3 -1
- package/src/server/responses/codex-ws-wire.ts +19 -3
- package/src/server/responses/compact.ts +57 -24
- package/src/server/responses/compaction-recovery.ts +4 -2
- package/src/server/responses/compaction-routing.ts +9 -4
- package/src/server/responses/core-auth.ts +32 -14
- package/src/server/responses/core-codex-account.ts +17 -6
- package/src/server/responses/core-combo-failure.ts +7 -1
- package/src/server/responses/core-combo-native.ts +2 -1
- package/src/server/responses/core-combo.ts +43 -27
- package/src/server/responses/core-errors.ts +24 -21
- package/src/server/responses/core-lifetime.ts +6 -3
- package/src/server/responses/core-normalize.ts +1 -0
- package/src/server/responses/core-options.ts +9 -0
- package/src/server/responses/core-pipeline.ts +4 -3
- package/src/server/responses/empty-completion-guard.ts +4 -1
- package/src/server/responses/fetch-helpers.ts +7 -1
- package/src/server/responses/input-admission.ts +28 -2
- package/src/server/responses/native-injection.ts +1 -1
- package/src/server/responses/native-response-json.ts +13 -4
- package/src/server/responses/native-response-output.ts +1 -2
- package/src/server/responses/non-replayable-error.ts +2 -1
- package/src/server/responses/pacing-overload.ts +3 -2
- package/src/server/responses/passthrough-delivery.ts +55 -14
- package/src/server/responses/passthrough-dispatch.ts +20 -18
- package/src/server/responses/passthrough-error.ts +9 -9
- package/src/server/responses/policy-fallback.ts +2 -1
- package/src/server/responses/request-prepare.ts +69 -48
- package/src/server/responses/request-transport.ts +36 -31
- package/src/server/responses/response-effects.ts +3 -2
- package/src/server/responses/run-turn-execution.ts +6 -6
- package/src/server/responses/sidecar-execution.ts +16 -12
- package/src/server/responses/spend-storage-error.ts +2 -1
- package/src/server/responses/terminal-guard.ts +30 -0
- package/src/server/responses/ws-upstream.ts +9 -0
- package/src/server/responses-custom-tool-repair.ts +14 -3
- package/src/server/responses-terminal-repair.ts +5 -2
- package/src/server/responses-undeclared-tool-guard.ts +39 -16
- package/src/server/restart-replacement.ts +3 -1
- package/src/server/safe-response-headers.ts +162 -13
- package/src/server/sse-payload-rewrite.ts +23 -11
- package/src/server/turn-state-handles.ts +164 -0
- package/src/server/workflow-refusal.ts +2 -1
- package/src/server/ws-bridge.ts +4 -0
- package/src/service/definition.ts +36 -4
- package/src/service/launchd.ts +89 -32
- package/src/service/logging.ts +34 -7
- package/src/service/ownership-mutation-lease.d.mts +11 -2
- package/src/service/ownership-mutation-lease.mjs +53 -11
- package/src/service/plist-xml.ts +59 -0
- package/src/service/state.ts +8 -0
- package/src/service/systemd-env.ts +2 -0
- package/src/service/systemd.ts +31 -7
- package/src/service/windows-taskxml.ts +16 -7
- package/src/service-manager-probe.ts +4 -10
- package/src/types/config.ts +2 -0
- package/src/types/provider.ts +2 -0
- package/src/types/request.ts +13 -1
- package/src/update/config-preflight.ts +48 -0
- package/src/update/index.ts +148 -26
- package/src/update/npm-install.d.mts +8 -0
- package/src/update/npm-install.mjs +20 -1
- package/src/update/orchestrated-admission.d.mts +4 -0
- package/src/update/orchestrated-admission.mjs +12 -0
- package/src/update/orchestrated-arguments.d.mts +12 -0
- package/src/update/orchestrated-arguments.mjs +64 -0
- package/src/update/orchestrated-child.d.mts +12 -0
- package/src/update/orchestrated-child.mjs +70 -0
- package/src/update/orchestrated-entry.ts +234 -0
- package/src/update/orchestrated-identity-probe-entry.ts +20 -0
- package/src/update/orchestrated-identity.ts +53 -0
- package/src/update/orchestrated-live-identity.ts +48 -0
- package/src/update/orchestrated-node-driver.mjs +99 -0
- package/src/update/orchestrated-outcome.d.mts +21 -0
- package/src/update/orchestrated-outcome.mjs +40 -0
- package/src/update/orchestrated-plan.ts +49 -0
- package/src/update/orchestrated-pnpm.d.mts +8 -0
- package/src/update/orchestrated-pnpm.mjs +33 -0
- package/src/update/orchestrated-session.d.mts +37 -0
- package/src/update/orchestrated-session.mjs +264 -0
- package/src/update/orchestrated-token.d.mts +10 -0
- package/src/update/orchestrated-token.mjs +21 -0
- package/src/update/orchestrated-token.ts +3 -0
- package/src/update/orchestrated-tree.d.mts +1 -0
- package/src/update/orchestrated-tree.mjs +14 -0
- package/src/update/pnpm-global-install.d.mts +6 -0
- package/src/update/pnpm-global-install.mjs +9 -2
- package/src/update/posix-install-supervisor-entry.mjs +6 -0
- package/src/update/posix-install-supervisor.d.mts +10 -0
- package/src/update/posix-install-supervisor.mjs +88 -0
- package/src/update/sync-update-mutex.d.mts +10 -0
- package/src/update/sync-update-mutex.mjs +164 -0
- package/src/update/sync-update-mutex.ts +1 -0
- package/src/update/test-home-guard.mjs +33 -0
- package/src/update/transactional-install.mjs +2 -2
- package/src/usage/client.ts +43 -0
- package/src/usage/error-detail.ts +225 -0
- package/src/usage/log.ts +64 -27
- package/src/usage/source-facets.ts +51 -0
- package/src/usage/source-filter.ts +65 -0
- package/src/usage/summary.ts +50 -8
- package/src/web-search/anthropic-executor.ts +105 -24
- package/src/web-search/executor.ts +5 -3
- package/src/web-search/loop.ts +33 -6
- package/src/web-search/progress-stream.ts +64 -5
- package/gui/dist/assets/App-bwugJRKn.js +0 -58
- package/gui/dist/assets/index-ebuVUtB7.js +0 -94
- package/gui/dist/assets/quota-summary-6HsrHQAy.js +0 -1
- /package/gui/dist/{assets → classic/assets}/App-B4j-Txmb.css +0 -0
- /package/gui/dist/{assets → classic/assets}/index-CHWwDo9L.css +0 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
|
+
import { isIP } from "node:net";
|
|
2
3
|
import { getRuntimePortPath, readRuntimePort } from "../config/process-state";
|
|
3
4
|
import { packageVersion } from "../lib/package-version";
|
|
4
5
|
import { parseStrictSemver } from "../lib/strict-semver";
|
|
@@ -10,12 +11,21 @@ export const UPDATE_RESTART_CHILD_ENV = "OCX_UPDATE_RESTART_CHILD";
|
|
|
10
11
|
export interface UpdateRestartChildMarker { home: UpdateRestartHome; version: string; port: number; hostname: string; deadlineAt: number }
|
|
11
12
|
export interface UpdateRestartChildGuard { check(port?: number, hostname?: string): void; complete(): void }
|
|
12
13
|
|
|
13
|
-
function
|
|
14
|
+
function safeBindHost(host: string): boolean {
|
|
15
|
+
if (!host || host.length > 255 || host !== host.trim()) return false;
|
|
16
|
+
if (host.startsWith("[") || host.endsWith("]")) {
|
|
17
|
+
return host.startsWith("[") && host.endsWith("]") && isIP(host.slice(1, -1)) === 6;
|
|
18
|
+
}
|
|
19
|
+
return isIP(host) !== 0 || /^(?:\*|0|(0+\.){3}0+)\.?$/.test(host);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function parseUpdateRestartMarker(raw: string): UpdateRestartChildMarker {
|
|
14
23
|
if (raw.length > 8192) throw new Error("update_restart_child_marker_invalid");
|
|
15
24
|
const value = JSON.parse(raw) as UpdateRestartChildMarker;
|
|
16
25
|
if (!value || !Number.isSafeInteger(value.deadlineAt) || !Number.isInteger(value.port)
|
|
17
|
-
|| typeof value.hostname !== "string" || value.port < 1 || value.port > 65535 || typeof value.version !== "string"
|
|
26
|
+
|| typeof value.hostname !== "string" || !safeBindHost(value.hostname) || value.port < 1 || value.port > 65535 || typeof value.version !== "string"
|
|
18
27
|
|| value.version === "0.0.0" || !parseStrictSemver(value.version) || !value.home
|
|
28
|
+
|| !(value.home.diagnosedHostname === null || (typeof value.home.diagnosedHostname === "string" && safeBindHost(value.home.diagnosedHostname)))
|
|
19
29
|
|| !Number.isSafeInteger(value.home.revision) || value.home.serviceRecord?.schema !== 1
|
|
20
30
|
|| typeof value.home.serviceRecord.digest !== "string" || !/^[a-f0-9]{64}$/.test(value.home.serviceRecord.digest)) throw new Error("update_restart_child_marker_invalid");
|
|
21
31
|
for (const directory of [value.home.config, value.home.codex]) {
|
|
@@ -49,7 +59,7 @@ export function admitUpdateRestartChild(argv: string[], io: UpdateRestartChildIo
|
|
|
49
59
|
if (raw === undefined) return undefined;
|
|
50
60
|
delete env[UPDATE_RESTART_CHILD_ENV];
|
|
51
61
|
delete env[OWNERSHIP_MUTATION_LEASE_TOKEN_ENV];
|
|
52
|
-
const marker =
|
|
62
|
+
const marker = parseUpdateRestartMarker(raw);
|
|
53
63
|
if (argv.length !== 3 || argv[0] !== "start" || argv[1] !== "--port" || argv[2] !== String(marker.port)) {
|
|
54
64
|
throw new Error("update_restart_child_command_changed");
|
|
55
65
|
}
|
|
@@ -18,6 +18,7 @@ export interface UpdateRestartHome {
|
|
|
18
18
|
codex: UpdateRestartDirectory;
|
|
19
19
|
revision: number;
|
|
20
20
|
serviceRecord: UpdateRestartServiceRecord;
|
|
21
|
+
diagnosedHostname: string | null;
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
export type UpdateRestartDirectoryStat = Pick<BigIntStats, "dev" | "ino" | "isDirectory">;
|
|
@@ -44,7 +45,9 @@ export function readUpdateRestartHome(deps: UpdateRestartHomeDeps = {}): UpdateR
|
|
|
44
45
|
throw new Error("update_restart_owner_unverified");
|
|
45
46
|
}
|
|
46
47
|
const stat = deps.statDirectory ?? (path => statSync(path, { bigint: true }));
|
|
47
|
-
|
|
48
|
+
const diagnostics = readConfigDiagnostics({ passive: true });
|
|
49
|
+
if (diagnostics.error) throw new Error("update_restart_configuration_unverified");
|
|
50
|
+
return { config: physicalDirectory(getConfigDir(), stat), codex: physicalDirectory(currentCodexHome(), stat), revision: owner.revision, serviceRecord, diagnosedHostname: diagnostics.config.hostname ?? null };
|
|
48
51
|
}
|
|
49
52
|
|
|
50
53
|
export function assertUpdateRestartHome(expected: UpdateRestartHome, deadlineAt = Date.now() + 2000, deps: UpdateRestartHomeDeps = {}): void {
|
|
@@ -62,7 +65,7 @@ export function assertUpdateRestartHome(expected: UpdateRestartHome, deadlineAt
|
|
|
62
65
|
|
|
63
66
|
/** Read-only eligibility shared by parent pre-stop and child admission. */
|
|
64
67
|
export function assertUpdateRestartConfiguration(hostname: string): void {
|
|
65
|
-
const diagnostics = readConfigDiagnostics();
|
|
68
|
+
const diagnostics = readConfigDiagnostics({ passive: true });
|
|
66
69
|
if (readClientConnectionState().kind !== "disconnected" || diagnostics.error
|
|
67
|
-
|| (diagnostics.config.hostname
|
|
70
|
+
|| (diagnostics.config.hostname === undefined ? hostname !== "127.0.0.1" : diagnostics.config.hostname !== hostname)) throw new Error("update_restart_configuration_changed");
|
|
68
71
|
}
|
|
@@ -12,7 +12,8 @@ import { acquireOwnershipMutationLease, unprivilegedOwnershipMutationEnvironment
|
|
|
12
12
|
import { serviceStatePaths } from "../service/state";
|
|
13
13
|
import { findLiveProxy, probeEndpointLiveness, probeHostname, type LiveProxy } from "../server/proxy-liveness";
|
|
14
14
|
import { waitForPortAvailable } from "../server/ports";
|
|
15
|
-
import {
|
|
15
|
+
import { normalizeBindHostname } from "../server/bind-host";
|
|
16
|
+
import { UPDATE_RESTART_CHILD_ENV, parseUpdateRestartMarker, type UpdateRestartChildMarker } from "./update-restart-child";
|
|
16
17
|
import { assertUpdateRestartConfiguration, assertUpdateRestartHome, readUpdateRestartHome, type UpdateRestartHome, type UpdateRestartHomeDeps } from "./update-restart-home";
|
|
17
18
|
import { observeAttestedUpdateReplacement, stopAttestedUpdateTarget } from "./update-restart-transport";
|
|
18
19
|
import type { UpdateRestartCandidate } from "./update-restart-candidate";
|
|
@@ -39,7 +40,7 @@ export interface UpdateRestartIo {
|
|
|
39
40
|
wait(ms: number): Promise<void>;
|
|
40
41
|
}
|
|
41
42
|
const ELIGIBILITY_REASONS = ["windows", "unsupported_platform", "foreground", "service", "shared_or_client",
|
|
42
|
-
"package_tree_fenced", "unverifiable_ancestry", "target_changed", "configuration_changed", "desktop"] as const;
|
|
43
|
+
"package_tree_fenced", "unverifiable_ancestry", "target_changed", "configuration_changed", "desktop", "blank_runtime_hostname"] as const;
|
|
43
44
|
export type UpdateRestartEligibilityReason = (typeof ELIGIBILITY_REASONS)[number];
|
|
44
45
|
|
|
45
46
|
/** Carries only a closed reason code across the eligibility/transport boundary. */
|
|
@@ -74,6 +75,13 @@ export async function runUpdateRestart(candidate: UpdateRestartCandidate, deadli
|
|
|
74
75
|
lease = io.acquire();
|
|
75
76
|
const home = candidate.home;
|
|
76
77
|
if (JSON.stringify(io.home()) !== JSON.stringify(home)) throw new Error("home_changed");
|
|
78
|
+
if (candidate.runtime.hostname !== undefined && !candidate.runtime.hostname.trim()) {
|
|
79
|
+
eligibilityReason = "blank_runtime_hostname";
|
|
80
|
+
throw new Error("target");
|
|
81
|
+
}
|
|
82
|
+
const marker = parseUpdateRestartMarker(JSON.stringify({ home, version: candidate.cliVersion, port: candidate.target.port,
|
|
83
|
+
hostname: normalizeBindHostname(candidate.runtime.hostname), deadlineAt }));
|
|
84
|
+
if (normalizeBindHostname(candidate.target.hostname) !== marker.hostname) throw new Error("target");
|
|
77
85
|
const revalidate = () => {
|
|
78
86
|
withinDeadline();
|
|
79
87
|
io.checkHome(home);
|
|
@@ -122,7 +130,7 @@ export async function runUpdateRestart(candidate: UpdateRestartCandidate, deadli
|
|
|
122
130
|
withinDeadline();
|
|
123
131
|
io.checkHome(home);
|
|
124
132
|
phase = "start";
|
|
125
|
-
const child = io.start(
|
|
133
|
+
const child = io.start(marker);
|
|
126
134
|
// The child must acquire its own lease and validate this frozen handoff before preflight.
|
|
127
135
|
lease.release();
|
|
128
136
|
lease = undefined;
|
|
@@ -136,7 +144,7 @@ export async function runUpdateRestart(candidate: UpdateRestartCandidate, deadli
|
|
|
136
144
|
if (live) {
|
|
137
145
|
io.checkHome(home);
|
|
138
146
|
if (live.source !== "runtime" || live.pid !== child.pid || live.port !== candidate.target.port
|
|
139
|
-
||
|
|
147
|
+
|| !live.hostname || normalizeBindHostname(live.hostname) !== marker.hostname || live.role === "client"
|
|
140
148
|
|| live.packageTreeFenced || live.version !== candidate.cliVersion) throw new Error("replacement_mismatch");
|
|
141
149
|
return { ok: true, live };
|
|
142
150
|
}
|
|
@@ -165,6 +173,7 @@ export function describeUpdateRestartFailure(code: string, reason?: UpdateRestar
|
|
|
165
173
|
case "unverifiable_ancestry": return "The proxy's process ancestry or manager could not be verified. Run `ocx status` to identify its owner before restarting.";
|
|
166
174
|
case "configuration_changed": return "The selected configuration or connection changed. Run `ocx status` to inspect the intended proxy before restarting.";
|
|
167
175
|
case "target_changed": return "The captured proxy identity changed. Run `ocx status` to inspect the intended proxy before restarting.";
|
|
176
|
+
case "blank_runtime_hostname": return "The running proxy's runtime record has a blank hostname, so its bind address cannot be verified. Use `ocx status` and `ocx service status` as clues, not proof of ownership or bind address. Once ownership is verified, for a service use the owning installation's `ocx service restart`; for Desktop, use the app; for a foreground proxy, use its terminal. For a detached standalone proxy, independently verify its process, home, supervisor and actual bind. If verified and forced termination is acceptable, the owner can run `ocx stop` from that installation and home; it may refuse or force termination if graceful shutdown fails. Independently confirm the process has exited, its supervisor will not restart it, and the intended address and port are free before running `ocx start` with the intended settings. If any step is uncertain or fails, stop and ask the owner or administrator; do not edit the runtime record or kill unrelated processes.";
|
|
168
177
|
}
|
|
169
178
|
})();
|
|
170
179
|
return `${action} Nothing was stopped by this restart attempt.`;
|
|
@@ -191,6 +200,10 @@ export function describeUpdateRestartFailure(code: string, reason?: UpdateRestar
|
|
|
191
200
|
}
|
|
192
201
|
}
|
|
193
202
|
|
|
203
|
+
export function reportUpdateRestartFailure(result: Extract<UpdateRestartResult, { ok: false }>): void {
|
|
204
|
+
console.error(`❌ ${describeUpdateRestartFailure(result.code, result.reason)} (${result.code})`);
|
|
205
|
+
}
|
|
206
|
+
|
|
194
207
|
export interface UpdateRestartStandaloneDeps {
|
|
195
208
|
platform?: NodeJS.Platform;
|
|
196
209
|
expectedHome?: UpdateRestartHome;
|
|
@@ -253,6 +266,24 @@ export function standalone(target: UpdateRestartCandidate["target"], deadlineAt:
|
|
|
253
266
|
}
|
|
254
267
|
|
|
255
268
|
/** Production composition keeps stop/start side effects out of cli/index.ts. */
|
|
269
|
+
/** Verify the new runtime record, its own proof, and an exact reread after attestation. */
|
|
270
|
+
export async function observeUpdateRestartReplacement(candidate: UpdateRestartCandidate, deadline: number, childPid: number,
|
|
271
|
+
deps: { findLive: typeof findLiveProxy; readRuntime: typeof readRuntimePort; attest: typeof observeAttestedUpdateReplacement } =
|
|
272
|
+
{ findLive: findLiveProxy, readRuntime: readRuntimePort, attest: observeAttestedUpdateReplacement }): Promise<LiveProxy | null> {
|
|
273
|
+
const live = await deps.findLive({ deadlineAt: deadline, attempts: 1 });
|
|
274
|
+
if (!live) return null;
|
|
275
|
+
if (live.pid !== childPid) throw new Error("update_restart_replacement_changed");
|
|
276
|
+
const runtime = deps.readRuntime(childPid);
|
|
277
|
+
if (!runtime?.attestationSecret || runtime.pid !== childPid || runtime.port !== candidate.target.port
|
|
278
|
+
|| !runtime.hostname || normalizeBindHostname(runtime.hostname) !== normalizeBindHostname(candidate.runtime.hostname) || runtime.siblingOfPort !== undefined) {
|
|
279
|
+
throw new Error("update_restart_replacement_unattested");
|
|
280
|
+
}
|
|
281
|
+
const attested = await deps.attest({ target: { ...live, pid: childPid },
|
|
282
|
+
secret: runtime.attestationSecret, version: candidate.cliVersion, deadlineAt: deadline });
|
|
283
|
+
if (JSON.stringify(deps.readRuntime(childPid)) !== JSON.stringify(runtime)) throw new Error("update_restart_replacement_changed");
|
|
284
|
+
return attested;
|
|
285
|
+
}
|
|
286
|
+
|
|
256
287
|
export function restartFromCurrentInstallation(candidate: UpdateRestartCandidate, deadlineAt: number, environment: NodeJS.ProcessEnv): Promise<UpdateRestartResult> {
|
|
257
288
|
const argv = startArgv(candidate.target.port);
|
|
258
289
|
const executable = process.execPath;
|
|
@@ -286,21 +317,7 @@ export function restartFromCurrentInstallation(candidate: UpdateRestartCandidate
|
|
|
286
317
|
child.unref();
|
|
287
318
|
return child;
|
|
288
319
|
},
|
|
289
|
-
observe:
|
|
290
|
-
const live = await findLiveProxy({ deadlineAt: deadline, attempts: 1 });
|
|
291
|
-
if (!live) return null;
|
|
292
|
-
if (live.pid !== childPid) throw new Error("update_restart_replacement_changed");
|
|
293
|
-
const runtime = readRuntimePort(childPid);
|
|
294
|
-
if (!runtime?.attestationSecret || runtime.port !== candidate.target.port
|
|
295
|
-
|| runtime.hostname !== candidate.runtime.hostname || runtime.siblingOfPort !== undefined) {
|
|
296
|
-
throw new Error("update_restart_replacement_unattested");
|
|
297
|
-
}
|
|
298
|
-
const attested = await observeAttestedUpdateReplacement({ target: { ...live, pid: childPid },
|
|
299
|
-
secret: runtime.attestationSecret, version: candidate.cliVersion, deadlineAt: deadline });
|
|
300
|
-
const current = readRuntimePort(childPid);
|
|
301
|
-
if (JSON.stringify(current) !== JSON.stringify(runtime)) throw new Error("update_restart_replacement_changed");
|
|
302
|
-
return attested;
|
|
303
|
-
},
|
|
320
|
+
observe: (deadline, childPid) => observeUpdateRestartReplacement(candidate, deadline, childPid),
|
|
304
321
|
wait: ms => Bun.sleep(ms),
|
|
305
322
|
});
|
|
306
323
|
}
|
package/src/client/connect.ts
CHANGED
|
@@ -18,7 +18,8 @@ import {
|
|
|
18
18
|
withClientLifecycle, withClientLifecycleSync,
|
|
19
19
|
type ClientLifecycleHeld, type ClientLifecycleLockDeps,
|
|
20
20
|
} from "./lifecycle-lock";
|
|
21
|
-
import { invalidateCodexModelsCache } from "../codex/catalog/sync";
|
|
21
|
+
import { invalidateCodexModelsCache, invalidateCodexModelsCacheWithPermit } from "../codex/catalog/sync";
|
|
22
|
+
import { withCatalogWriteSerialization } from "../codex/catalog-write-serialization";
|
|
22
23
|
import {
|
|
23
24
|
injectCodexConfig,
|
|
24
25
|
currentExternalCodexModelProvider,
|
|
@@ -30,7 +31,7 @@ import {
|
|
|
30
31
|
journalOwner,
|
|
31
32
|
restoreJournalState,
|
|
32
33
|
} from "../codex/journal";
|
|
33
|
-
import { DEFAULT_CATALOG_PATH } from "../codex/paths";
|
|
34
|
+
import { DEFAULT_CATALOG_PATH, getCodexHome } from "../codex/paths";
|
|
34
35
|
import {
|
|
35
36
|
readServiceApiTokenState,
|
|
36
37
|
readTokenBackupState,
|
|
@@ -95,6 +96,7 @@ import {
|
|
|
95
96
|
import { hubStateCachePath } from "./hub-state";
|
|
96
97
|
import { ClientLinkStateError, clearClientLinkState, readClientLinkState } from "./link-state";
|
|
97
98
|
import { isLinkPort } from "../link/ports";
|
|
99
|
+
import { clientSyncRuntimeGuard, ClientSyncRuntimeError } from "./sync-runtime";
|
|
98
100
|
|
|
99
101
|
class RotationRecoveryRequiredError extends Error {
|
|
100
102
|
constructor(message: string, options?: ErrorOptions) {
|
|
@@ -554,6 +556,9 @@ function assertConnectingState(expectedTokenFingerprint?: string): void {
|
|
|
554
556
|
const token = readServiceApiTokenState();
|
|
555
557
|
if (expectedTokenFingerprint === undefined ? token.kind !== "absent"
|
|
556
558
|
: token.kind !== "present" || token.fingerprint !== expectedTokenFingerprint) {
|
|
559
|
+
if (expectedTokenFingerprint === undefined && token.kind === "present") {
|
|
560
|
+
throw new Error("client_token_changed: if this is not a Hub and no admission secret or installed service uses the token, inspect it and use ocx disconnect --orphaned-token --yes before retrying");
|
|
561
|
+
}
|
|
557
562
|
throw new Error("client_token_changed");
|
|
558
563
|
}
|
|
559
564
|
}
|
|
@@ -901,7 +906,15 @@ async function syncConnectedClientUnlocked(
|
|
|
901
906
|
if (state.kind !== "connected" || state.value.pendingOperation) throw new Error("client_sync_unavailable");
|
|
902
907
|
const token = readServiceApiTokenState();
|
|
903
908
|
if (token.kind !== "present" || token.fingerprint !== state.value.tokenFingerprint) throw new Error("client_token_changed");
|
|
904
|
-
|
|
909
|
+
let assertRuntimeCurrent = () => {};
|
|
910
|
+
try { if (isLinkConnection(state.value)) assertRuntimeCurrent = clientSyncRuntimeGuard(); }
|
|
911
|
+
catch (error) {
|
|
912
|
+
if (options.expect && error instanceof ClientSyncRuntimeError && error.code === "client_runtime_stopping") {
|
|
913
|
+
throw new ClientSyncExpectationError(options.expect, "pending_operation");
|
|
914
|
+
}
|
|
915
|
+
throw error;
|
|
916
|
+
}
|
|
917
|
+
return { connection: state.value, token, assertRuntimeCurrent };
|
|
905
918
|
}), deps.lifecycleLockDeps);
|
|
906
919
|
let downloaded: Awaited<ReturnType<typeof downloadClientCatalog>> | undefined;
|
|
907
920
|
let stale = false;
|
|
@@ -918,6 +931,7 @@ async function syncConnectedClientUnlocked(
|
|
|
918
931
|
// they were, which is the known-good state.
|
|
919
932
|
if (downloaded) assertClientCatalogCompatible(downloaded.body, deps.catalogCompatibility);
|
|
920
933
|
const next = withClientLifecycleSync(() => withConfigMutationLockSync(() => {
|
|
934
|
+
initial.assertRuntimeCurrent();
|
|
921
935
|
assertClientConnectionUnchanged(initial.connection);
|
|
922
936
|
const token = readServiceApiTokenState();
|
|
923
937
|
if (token.kind !== "present" || token.fingerprint !== initial.token.fingerprint) throw new Error("client_token_changed");
|
|
@@ -933,10 +947,12 @@ async function syncConnectedClientUnlocked(
|
|
|
933
947
|
}), deps.lifecycleLockDeps);
|
|
934
948
|
// Read-only: injection invokes this while N/C are held. Acquiring L here would invert C→L.
|
|
935
949
|
const beforeClientWrite = () => {
|
|
950
|
+
initial.assertRuntimeCurrent();
|
|
936
951
|
assertClientConnectionUnchanged(next);
|
|
937
952
|
const token = readServiceApiTokenState();
|
|
938
953
|
if (next.pendingOperation || token.kind !== "present" || token.fingerprint !== next.tokenFingerprint) throw new Error("client_token_changed");
|
|
939
954
|
};
|
|
955
|
+
const withClientWrite = <T>(write: () => T): T => withConfigMutationLockSync(() => { beforeClientWrite(); return write(); });
|
|
940
956
|
let injected = false;
|
|
941
957
|
let homeSettings: HomeCodexSettingsSource | undefined;
|
|
942
958
|
let appliedRecord: HomeCodexSettingsRecord | undefined;
|
|
@@ -945,12 +961,15 @@ async function syncConnectedClientUnlocked(
|
|
|
945
961
|
let config = loadConfig();
|
|
946
962
|
// #6957: a link Child applies the Home's OpenCodex-owned Codex settings with the catalog.
|
|
947
963
|
if (isLinkConnection(next)) {
|
|
948
|
-
homeSettings = await resolveHomeCodexSettings(next, initial.token.token, deps.linkHome);
|
|
964
|
+
homeSettings = await resolveHomeCodexSettings(next, initial.token.token, { ...deps.linkHome, withWriteGuard: withClientWrite });
|
|
949
965
|
if (homeSettings.source !== "local") config = overlayHomeCodexSettings(config, homeSettings.document.settings);
|
|
950
966
|
// About to write different settings: until their record commits, report no applied digest
|
|
951
967
|
// rather than the previous one (OCX-6). A failed injection then reads "unknown", never a
|
|
952
968
|
// digest of values Codex no longer has or never got.
|
|
953
|
-
if (homeSettings.source === "home" && next.link)
|
|
969
|
+
if (homeSettings.source === "home" && next.link) {
|
|
970
|
+
const { linkId } = next.link, { document } = homeSettings;
|
|
971
|
+
withClientWrite(() => withdrawChangingHomeCodexSettingsRecord(linkId, document));
|
|
972
|
+
}
|
|
954
973
|
}
|
|
955
974
|
const result = await injectCodexConfig(config.port, { ...config, syncResumeHistory: false }, {
|
|
956
975
|
routingTarget: routingTarget(next.serverUrl, isLinkConnection(next) ? config.port : undefined, config), catalogPath: DEFAULT_CATALOG_PATH,
|
|
@@ -962,23 +981,24 @@ async function syncConnectedClientUnlocked(
|
|
|
962
981
|
const linkId = next.link.linkId;
|
|
963
982
|
const settings = homeSettings;
|
|
964
983
|
try {
|
|
965
|
-
appliedRecord = withClientLifecycleSync(() =>
|
|
966
|
-
|
|
967
|
-
return recordHomeCodexSettings(linkId, settings, deps.now) ?? readHomeCodexSettingsRecord(linkId) ?? undefined;
|
|
968
|
-
}, deps.lifecycleLockDeps);
|
|
984
|
+
appliedRecord = withClientLifecycleSync(() => withClientWrite(() =>
|
|
985
|
+
recordHomeCodexSettings(linkId, settings, deps.now) ?? readHomeCodexSettingsRecord(linkId) ?? undefined), deps.lifecycleLockDeps);
|
|
969
986
|
} catch (error) {
|
|
970
987
|
// An ownership change is not a disk problem: report it as itself.
|
|
971
|
-
if (error instanceof Error && (error.message === "client_token_changed" || error.message === "client_connection_changed")) throw error;
|
|
988
|
+
if (error instanceof ClientSyncRuntimeError || (error instanceof Error && (error.message === "client_token_changed" || error.message === "client_connection_changed"))) throw error;
|
|
972
989
|
// The injection committed, so the cache refresh below still runs; the caller reports this.
|
|
973
|
-
try { clearHomeCodexSettingsRecord
|
|
990
|
+
try { withClientWrite(clearHomeCodexSettingsRecord); } catch { /* status already reads no recorded apply or reports the write */ }
|
|
974
991
|
applyRecordFailed = true;
|
|
975
992
|
}
|
|
976
993
|
}
|
|
977
994
|
}
|
|
978
995
|
const cacheSynced = withClientLifecycleSync(() => {
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
996
|
+
// Acquire K before the guarded C commit; never acquire K from inside C.
|
|
997
|
+
const owningHome = getCodexHome();
|
|
998
|
+
const result = withCatalogWriteSerialization(owningHome, permit => withClientWrite(() =>
|
|
999
|
+
invalidateCodexModelsCacheWithPermit(permit, owningHome, { allowWhenDesiredDisabled: true })),
|
|
1000
|
+
{ intent: "cache", writer: "cache-invalidate" });
|
|
1001
|
+
return result.kind === "completed" && result.value;
|
|
982
1002
|
}, deps.lifecycleLockDeps);
|
|
983
1003
|
return {
|
|
984
1004
|
catalogWritten: downloaded !== undefined, cacheSynced, injected, stale,
|
|
@@ -1104,7 +1124,7 @@ export async function disconnectClient(
|
|
|
1104
1124
|
writeDesktopDisconnectReceipt(held, previous, receipt);
|
|
1105
1125
|
}
|
|
1106
1126
|
} else if (state.kind !== "disconnected" || !receipt || !disconnectAtLeast(receipt, "clearing_connection")) {
|
|
1107
|
-
throw new Error("disconnect refused: no recoverable connected state");
|
|
1127
|
+
throw new Error("disconnect refused: no recoverable connected state; if this is not a Hub and no admission secret or installed service uses the token, inspect it and use ocx disconnect --orphaned-token --yes");
|
|
1108
1128
|
}
|
|
1109
1129
|
if (!receipt || receipt.keepCatalog !== keepCatalog) throw new Error("client_disconnect_options_changed");
|
|
1110
1130
|
return { receipt, connection };
|
package/src/client/hub-client.ts
CHANGED
|
@@ -513,6 +513,11 @@ export async function fetchHubUsage(
|
|
|
513
513
|
const text = await boundedText(response, MAX_HUB_USAGE_BYTES, { inactivityTimeoutMs: safeTimeout(options.timeoutMs) });
|
|
514
514
|
const report = parseHubUsage(parseJson(text, "hub_usage_invalid"));
|
|
515
515
|
if (!report) throw new HubClientError("hub_usage_invalid", "Hub usage response was invalid");
|
|
516
|
+
const requestedClient = query.get("client");
|
|
517
|
+
if (requestedClient !== null && (query.getAll("client").length !== 1
|
|
518
|
+
|| report.sourceFilter?.client !== requestedClient || report.sourceFilter.scope !== "authenticated-key")) {
|
|
519
|
+
throw new HubClientError("hub_usage_invalid", "Hub usage source filter was not confirmed");
|
|
520
|
+
}
|
|
516
521
|
return report;
|
|
517
522
|
}
|
|
518
523
|
|
package/src/client/link-home.ts
CHANGED
|
@@ -299,7 +299,7 @@ export type HomeCodexSettingsSource =
|
|
|
299
299
|
export async function resolveHomeCodexSettings(
|
|
300
300
|
connection: LinkHomeConnection,
|
|
301
301
|
admissionKey: string,
|
|
302
|
-
deps: LinkHomeDeps & { now?: () => Date } = {},
|
|
302
|
+
deps: LinkHomeDeps & { now?: () => Date; withWriteGuard?: <T>(write: () => T) => T } = {},
|
|
303
303
|
): Promise<HomeCodexSettingsSource> {
|
|
304
304
|
const linkId = connection.link?.linkId;
|
|
305
305
|
if (!linkId) return { source: "local", reason: "not a Remote Link Child" };
|
|
@@ -308,7 +308,8 @@ export async function resolveHomeCodexSettings(
|
|
|
308
308
|
return { source: "home", document: fetched.document, fetchedAt: (deps.now ?? (() => new Date()))().toISOString() };
|
|
309
309
|
}
|
|
310
310
|
if (fetched.kind === "unsupported") {
|
|
311
|
-
|
|
311
|
+
if (deps.withWriteGuard) deps.withWriteGuard(clearHomeCodexSettingsRecord);
|
|
312
|
+
else clearHomeCodexSettingsRecord();
|
|
312
313
|
return { source: "local", reason: "the Home does not publish Codex settings; upgrade the Home" };
|
|
313
314
|
}
|
|
314
315
|
const cached = readHomeCodexSettingsRecord(linkId);
|
|
@@ -8,9 +8,11 @@
|
|
|
8
8
|
* which attaches the link key only after the tunnel listener proves the link identity. Anything
|
|
9
9
|
* outside the shared read allowlist is refused here, before a request exists.
|
|
10
10
|
*/
|
|
11
|
-
import { HUB_RELAY_RESPONSE_BODY_MAX_BYTES } from "./hub-relay";
|
|
11
|
+
import { HUB_RELAY_DEFAULT_TIMEOUT_MS, HUB_RELAY_RESPONSE_BODY_MAX_BYTES } from "./hub-relay";
|
|
12
12
|
import type { LinkIngress } from "./link-ingress";
|
|
13
13
|
import { relayLinkDataRequest } from "./link-relay";
|
|
14
|
+
import { parseUsageSource } from "../usage/source-filter";
|
|
15
|
+
import { readBoundedResponseBytes } from "../lib/bounded-body";
|
|
14
16
|
import {
|
|
15
17
|
LINK_MANAGEMENT_PREFIX,
|
|
16
18
|
linkChildManagementRefusal,
|
|
@@ -41,6 +43,15 @@ export async function relayLinkManagementRead(
|
|
|
41
43
|
if (!linkManagementReadAllowed(req.method, pathname, new URLSearchParams(search.slice(1)))) {
|
|
42
44
|
return linkChildRefusalResponse(homePhrase, linkId, `${req.method.toUpperCase()} ${pathname}`);
|
|
43
45
|
}
|
|
46
|
+
const source = pathname === "/api/usage" ? parseUsageSource(new URLSearchParams(search.slice(1))) : { kind: "legacy" as const };
|
|
47
|
+
if (source.kind !== "legacy") {
|
|
48
|
+
if (source.kind !== "filtered" || source.filter.device.kind !== "key"
|
|
49
|
+
|| !ingress.apiKeyId || source.filter.device.id !== ingress.apiKeyId) {
|
|
50
|
+
return Response.json({ error: "link_usage_scope_refused" }, { status: 403 });
|
|
51
|
+
}
|
|
52
|
+
// HEAD has no body in which the Home can confirm the filter; never present it as verified.
|
|
53
|
+
if (req.method.toUpperCase() === "HEAD") return new Response(null, { status: 405 });
|
|
54
|
+
}
|
|
44
55
|
const admissionKey = ingress.linkKey();
|
|
45
56
|
if (!admissionKey) return Response.json({ error: "link_credential_unavailable" }, { status: 503 });
|
|
46
57
|
const outbound = new Request(`http://127.0.0.1${LINK_MANAGEMENT_PREFIX}${pathname}${search}`, {
|
|
@@ -48,7 +59,7 @@ export async function relayLinkManagementRead(
|
|
|
48
59
|
headers: { accept: "application/json" },
|
|
49
60
|
signal: req.signal,
|
|
50
61
|
});
|
|
51
|
-
|
|
62
|
+
const response = await relayLinkDataRequest(outbound, {
|
|
52
63
|
tunnelPort: ingress.tunnelPort,
|
|
53
64
|
admissionKey,
|
|
54
65
|
linkId: ingress.linkId,
|
|
@@ -58,4 +69,30 @@ export async function relayLinkManagementRead(
|
|
|
58
69
|
bodyLimitBytes: HUB_RELAY_RESPONSE_BODY_MAX_BYTES,
|
|
59
70
|
routeAllowed: linkManagementRouteAllowed,
|
|
60
71
|
});
|
|
72
|
+
if (source.kind !== "filtered" || !response.ok) return response;
|
|
73
|
+
const contentType = response.headers.get("content-type")?.split(";", 1)[0]?.trim().toLowerCase();
|
|
74
|
+
if (contentType !== "application/json" && !contentType?.endsWith("+json")) {
|
|
75
|
+
try { void response.body?.cancel().catch(() => {}); } catch { /* best effort */ }
|
|
76
|
+
return Response.json({ error: "link_usage_filter_unconfirmed" }, { status: 502 });
|
|
77
|
+
}
|
|
78
|
+
try {
|
|
79
|
+
const requestedTimeout = ingress.relay?.headerTimeoutMs;
|
|
80
|
+
const deadline = requestedTimeout && requestedTimeout > 0
|
|
81
|
+
? Math.min(requestedTimeout, HUB_RELAY_DEFAULT_TIMEOUT_MS) : HUB_RELAY_DEFAULT_TIMEOUT_MS;
|
|
82
|
+
const result = await readBoundedResponseBytes(response, { maxBytes: HUB_RELAY_RESPONSE_BODY_MAX_BYTES,
|
|
83
|
+
signal: AbortSignal.any([req.signal, AbortSignal.timeout(deadline)]), inactivityTimeoutMs: deadline });
|
|
84
|
+
if (result.oversized) throw new Error("response too large");
|
|
85
|
+
const body: unknown = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(result.bytes));
|
|
86
|
+
if (!body || typeof body !== "object" || Array.isArray(body)) throw new Error("invalid response");
|
|
87
|
+
const echo = (body as Record<string, unknown>).sourceFilter;
|
|
88
|
+
if (!echo || typeof echo !== "object" || Array.isArray(echo)) throw new Error("missing source filter");
|
|
89
|
+
const value = echo as Record<string, unknown>;
|
|
90
|
+
const device = value.device;
|
|
91
|
+
if (value.client !== source.filter.client || !device || typeof device !== "object" || Array.isArray(device)
|
|
92
|
+
|| (device as Record<string, unknown>).kind !== "key"
|
|
93
|
+
|| (device as Record<string, unknown>).id !== ingress.apiKeyId) throw new Error("source filter mismatch");
|
|
94
|
+
return Response.json(body, { status: response.status, headers: response.headers });
|
|
95
|
+
} catch {
|
|
96
|
+
return Response.json({ error: "link_usage_filter_unconfirmed" }, { status: 502 });
|
|
97
|
+
}
|
|
61
98
|
}
|
|
@@ -20,7 +20,9 @@ import type { ClientLinkSupervisorStatus } from "./link-tunnel";
|
|
|
20
20
|
export type LinkReadinessReason =
|
|
21
21
|
| "tunnel_idle" | "tunnel_connecting" | "tunnel_failed" | "tunnel_unavailable" | "sidecar_invalid"
|
|
22
22
|
| "home_unreachable" | "home_unauthorized" | "link_auth_failed" | "link_credential_unavailable"
|
|
23
|
-
| "link_unverified"
|
|
23
|
+
| "link_unverified"
|
|
24
|
+
/** The Child's durable connection no longer matches the one this runtime started with. */
|
|
25
|
+
| "client_state_changed";
|
|
24
26
|
|
|
25
27
|
export type LinkReadiness = { ready: true } | { ready: false; reason: LinkReadinessReason };
|
|
26
28
|
|
|
@@ -131,7 +131,8 @@ export async function handleMachineApi(
|
|
|
131
131
|
}
|
|
132
132
|
try {
|
|
133
133
|
const result = input.action === "uninstall" ? await uninstallCodexShimAsync() : await installCodexShimAsync();
|
|
134
|
-
|
|
134
|
+
// 200 either way so the dashboard re-reads the shim diagnosis; a refusal is not a success.
|
|
135
|
+
return Response.json({ success: !result.refused, action: input.action, result, shim: diagnoseCodexShim() });
|
|
135
136
|
} catch (error) {
|
|
136
137
|
return Response.json({ success: false, error: error instanceof Error ? error.message : "shim action failed" }, { status: 409 });
|
|
137
138
|
}
|
|
@@ -41,6 +41,7 @@ import { linkRouteAllowed } from "../link/routes";
|
|
|
41
41
|
import { linkHomeName, linkHomePhrase } from "./link-home";
|
|
42
42
|
import { relayLinkManagementRead } from "./link-management-relay";
|
|
43
43
|
import type { ClientRestartAdmission } from "./runtime-restart";
|
|
44
|
+
import { clientRestartRollbackAction } from "./runtime-restart";
|
|
44
45
|
import { isLinkConnectionGeneration } from "../link/relay-auth";
|
|
45
46
|
|
|
46
47
|
const VERSION = packageVersion("0.0.0");
|
|
@@ -136,6 +137,7 @@ export function startMachineListener(
|
|
|
136
137
|
return state.value;
|
|
137
138
|
})();
|
|
138
139
|
const linkMode = isLinkConnection(connection);
|
|
140
|
+
const connectionChanged = () => clientRestartRollbackAction(connection, readClientConnectionState()) === "recycle";
|
|
139
141
|
if (linkMode && !connection.link) throw new Error("link machine listener requires link transport metadata");
|
|
140
142
|
const managementAuth = deps.managementAuthState ?? initializeManagementAuthState(config);
|
|
141
143
|
let hubReachability: HubReachability = "unknown";
|
|
@@ -202,6 +204,8 @@ export function startMachineListener(
|
|
|
202
204
|
if (linkMode && deps.linkReadiness) {
|
|
203
205
|
try { link = await deps.linkReadiness(); } catch { link = { ready: false, reason: "link_unverified" }; }
|
|
204
206
|
}
|
|
207
|
+
// Read durable ownership once, after any probe, so a change during the probe still shows.
|
|
208
|
+
if (linkMode && connectionChanged()) link = { ready: false, reason: "client_state_changed" };
|
|
205
209
|
if (link && !link.ready) {
|
|
206
210
|
// The /readyz contract: not ready is 503 with Retry-After and status pending or failed.
|
|
207
211
|
return Response.json({ ...identity, status: "pending", ...facts, link: { state: "unavailable", reason: link.reason } },
|
|
@@ -253,6 +257,9 @@ export function startMachineListener(
|
|
|
253
257
|
if (managementPrincipal(req, managementAuth, config) !== "gui-session") {
|
|
254
258
|
return Response.json({ error: "opencodex machine GUI session required" }, { status: 401 });
|
|
255
259
|
}
|
|
260
|
+
if (linkMode && (url.pathname === "/api/machine/status" || url.pathname === "/api/machine/clients" || url.pathname === "/api/link/status") && connectionChanged()) {
|
|
261
|
+
return Response.json({ error: "client_state_changed" }, { status: 503, headers: { "Cache-Control": "no-store" } });
|
|
262
|
+
}
|
|
256
263
|
// A loopback dashboard session proves possession, not user presence: any local
|
|
257
264
|
// process can fetch the dashboard bootstrap and replay its token and CSRF value.
|
|
258
265
|
// Keep the connected listener useful for status/diagnostics, but never let that
|
|
@@ -324,6 +331,9 @@ async function handleBoundRestart(
|
|
|
324
331
|
);
|
|
325
332
|
if (!authorized) return Response.json({ success: false, error: "restart capability required" }, { status: 401, headers: noStore });
|
|
326
333
|
const admission = await restart.request();
|
|
334
|
+
if (admission.kind === "stopping") {
|
|
335
|
+
return Response.json({ success: false, error: { code: "runtime_stopping" } }, { status: 409, headers: noStore });
|
|
336
|
+
}
|
|
327
337
|
if (admission.kind === "supervised") {
|
|
328
338
|
return Response.json({
|
|
329
339
|
success: false,
|