@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
package/src/service/logging.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { closeSync, constants, fstatSync, fsyncSync, ftruncateSync, lstatSync, openSync, readSync, realpathSync, renameSync, statSync, writeSync, type BigIntStats } from "node:fs";
|
|
2
2
|
import { formatWithOptions } from "node:util";
|
|
3
3
|
import { basename, dirname, join } from "node:path";
|
|
4
|
-
import { recordOwnedConfigPath } from "../lib/config-ownership";
|
|
4
|
+
import { ConfigUninstallInProgressError, recordOwnedConfigPath } from "../lib/config-ownership";
|
|
5
5
|
|
|
6
6
|
export const SERVICE_LOG_MAX_BYTES = 20 * 1024 * 1024;
|
|
7
7
|
export const SERVICE_LOG_CHECK_INTERVAL_MS = 60_000;
|
|
8
|
+
/** Consecutive failed registrations after which rotation goes ahead unrecorded. */
|
|
9
|
+
export const SERVICE_LOG_MAX_REGISTRATION_SKIPS = 3;
|
|
8
10
|
|
|
9
11
|
function regularLeaf(path: string): BigIntStats | undefined {
|
|
10
12
|
try {
|
|
@@ -28,7 +30,7 @@ function matchesDescriptor(path: string, fd: number, expected: BigIntStats): boo
|
|
|
28
30
|
}
|
|
29
31
|
|
|
30
32
|
/** Preserve the manager's open append descriptor; retain at most two bounded archives. */
|
|
31
|
-
export function rotateServiceLog(requestedPath: string, maxBytes = SERVICE_LOG_MAX_BYTES): boolean {
|
|
33
|
+
export function rotateServiceLog(requestedPath: string, maxBytes = SERVICE_LOG_MAX_BYTES, archiveEnabled = true): boolean {
|
|
32
34
|
let source: number | undefined;
|
|
33
35
|
let archive: number | undefined;
|
|
34
36
|
try {
|
|
@@ -59,6 +61,11 @@ export function rotateServiceLog(requestedPath: string, maxBytes = SERVICE_LOG_M
|
|
|
59
61
|
if (!matches("", source, original)) return false;
|
|
60
62
|
const size = Number(fstatSync(source, { bigint: true }).size);
|
|
61
63
|
if (!Number.isSafeInteger(size) || size <= maxBytes) return false;
|
|
64
|
+
if (!archiveEnabled) {
|
|
65
|
+
if (!matches("", source, original)) return false;
|
|
66
|
+
ftruncateSync(source, 0);
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
62
69
|
const previous = regularLeaf(`${path}.1`);
|
|
63
70
|
const oldest = regularLeaf(`${path}.2`);
|
|
64
71
|
if (!matches("", source, original)) return false;
|
|
@@ -125,11 +132,31 @@ export function startServiceLogging(
|
|
|
125
132
|
};
|
|
126
133
|
restore.push(() => { console[method] = original; });
|
|
127
134
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
135
|
+
// Rotation creates the .1/.2 files, so every rotation registers them first. Once recorded this
|
|
136
|
+
// is one stat, and it still sees an uninstall tombstone written after logging started. A thrown
|
|
137
|
+
// uninstall refusal truncates only the active inode without creating archives. Any other failure (a busy or broken ownership lock)
|
|
138
|
+
// skips it and retries next tick, but only a few times in a row: a fault that persists must not
|
|
139
|
+
// let the log grow without bound, so rotation then goes ahead unrecorded.
|
|
140
|
+
// A `false` result still rotates: a home without ownership metadata has nothing to register, and
|
|
141
|
+
// on a full manifest the unrecorded generations are reported by uninstall as residual paths.
|
|
142
|
+
let failedRegistrations = 0;
|
|
143
|
+
const rotate = () => {
|
|
144
|
+
try {
|
|
145
|
+
for (const suffix of [".1", ".2"]) recordOwnedConfigPath(dirname(path), `${path}${suffix}`);
|
|
146
|
+
failedRegistrations = 0;
|
|
147
|
+
} catch (error) {
|
|
148
|
+
// Ownership bookkeeping must not break logging.
|
|
149
|
+
if (error instanceof ConfigUninstallInProgressError) {
|
|
150
|
+
rotateServiceLog(path, SERVICE_LOG_MAX_BYTES, false);
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
failedRegistrations += 1;
|
|
154
|
+
if (failedRegistrations < SERVICE_LOG_MAX_REGISTRATION_SKIPS) return;
|
|
155
|
+
}
|
|
156
|
+
rotateServiceLog(path);
|
|
157
|
+
};
|
|
158
|
+
rotate();
|
|
159
|
+
const timer = setInterval(rotate, intervalMs);
|
|
133
160
|
timer.unref();
|
|
134
161
|
return () => { clearInterval(timer); for (const reset of restore) reset(); };
|
|
135
162
|
}
|
|
@@ -7,6 +7,11 @@ export interface OwnershipMutationLeaseOptions {
|
|
|
7
7
|
readonly joinToken?: string;
|
|
8
8
|
/** Names the current executable at the recorded PID, identity unverified; uses `ps` on POSIX and omits the default image lookup on Windows. */
|
|
9
9
|
readonly processImage?: (pid: number) => string | null;
|
|
10
|
+
/** Isolated locks cannot re-enter or inherit ownership delegation. */
|
|
11
|
+
readonly isolated?: boolean;
|
|
12
|
+
readonly holderKind?: "sync" | "update";
|
|
13
|
+
/** Explicit canonical lock path for isolated callers with no state-file authority. */
|
|
14
|
+
readonly lockPath?: string;
|
|
10
15
|
}
|
|
11
16
|
|
|
12
17
|
/** The recorded lease owner, identity unverified, read for diagnostics; never used to reclaim it. */
|
|
@@ -14,8 +19,11 @@ export interface OwnershipMutationLeaseHolder {
|
|
|
14
19
|
readonly path: string;
|
|
15
20
|
/** The recorded PID; null when the directory holds no parseable owner. */
|
|
16
21
|
readonly pid: number | null;
|
|
22
|
+
readonly delegatePid: number | null;
|
|
23
|
+
readonly holderAlive: boolean | null;
|
|
17
24
|
/** Liveness of the current process at the recorded PID; identity is not verified. */
|
|
18
25
|
readonly alive: boolean | null;
|
|
26
|
+
readonly holderKind: "sync" | "update" | null;
|
|
19
27
|
/** The current executable at the recorded PID when alive and readable; identity is not verified. */
|
|
20
28
|
readonly image: string | null;
|
|
21
29
|
/** Milliseconds since the owner was written, on the clock stale recovery uses. */
|
|
@@ -23,9 +31,10 @@ export interface OwnershipMutationLeaseHolder {
|
|
|
23
31
|
readonly record: "complete" | "incomplete" | "empty" | "unreadable";
|
|
24
32
|
}
|
|
25
33
|
|
|
26
|
-
export interface OwnershipMutationLease { readonly token: string; release(): void }
|
|
34
|
+
export interface OwnershipMutationLease { readonly token: string; addDelegate(pid: number): void; release(): void }
|
|
27
35
|
|
|
28
36
|
export declare const OWNERSHIP_MUTATION_LEASE_TOKEN_ENV: "OCX_OWNERSHIP_MUTATION_LEASE_TOKEN";
|
|
37
|
+
export declare function ownershipMutationLeasePath(statePaths: readonly string[]): string;
|
|
29
38
|
|
|
30
39
|
export declare function ownershipMutationLeaseChildEnvironment(
|
|
31
40
|
environment: NodeJS.ProcessEnv,
|
|
@@ -49,7 +58,7 @@ export declare function withOwnershipMutationLease<T>(
|
|
|
49
58
|
|
|
50
59
|
export declare function inspectOwnershipMutationLease(
|
|
51
60
|
statePaths: readonly string[],
|
|
52
|
-
options?: Pick<OwnershipMutationLeaseOptions, "now" | "processAlive" | "processImage">,
|
|
61
|
+
options?: Pick<OwnershipMutationLeaseOptions, "now" | "processAlive" | "processImage" | "lockPath">,
|
|
53
62
|
): OwnershipMutationLeaseHolder | null;
|
|
54
63
|
|
|
55
64
|
export declare function ownershipMutationLeaseStatusLine(
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
readFileSync,
|
|
11
11
|
readdirSync,
|
|
12
12
|
realpathSync,
|
|
13
|
+
renameSync,
|
|
13
14
|
rmdirSync,
|
|
14
15
|
unlinkSync,
|
|
15
16
|
writeFileSync,
|
|
@@ -51,6 +52,9 @@ function leasePath(statePaths) {
|
|
|
51
52
|
}
|
|
52
53
|
}
|
|
53
54
|
|
|
55
|
+
/** The same path used by acquisition, for conservative read-only inspection. */
|
|
56
|
+
export function ownershipMutationLeasePath(statePaths) { return leasePath(statePaths); }
|
|
57
|
+
|
|
54
58
|
function ownerName(record) {
|
|
55
59
|
return `v1-${record.pid}-${record.processInstance}-${record.token}.json`;
|
|
56
60
|
}
|
|
@@ -138,12 +142,18 @@ function leaseHolder(path, now, alive, image) {
|
|
|
138
142
|
if (!observed && !incomplete && !existsSync(path)) return null;
|
|
139
143
|
const pid = observed?.record.pid ?? incomplete?.pid ?? null;
|
|
140
144
|
const since = observed ? Math.max(observed.record.createdAt, observed.mtimeMs) : incomplete?.mtimeMs ?? null;
|
|
141
|
-
const
|
|
145
|
+
const delegate = observed?.record.delegatePid;
|
|
146
|
+
const delegateValid = delegate === undefined || (Number.isSafeInteger(delegate) && delegate > 0);
|
|
147
|
+
const holderAlive = pid === null ? null : alive(pid);
|
|
148
|
+
const live = !delegateValid ? null : holderAlive === null ? null : holderAlive || (delegate !== undefined && alive(delegate));
|
|
142
149
|
return {
|
|
143
150
|
path,
|
|
144
151
|
pid,
|
|
152
|
+
delegatePid: delegateValid ? delegate ?? null : null,
|
|
153
|
+
holderAlive,
|
|
145
154
|
alive: live,
|
|
146
|
-
|
|
155
|
+
holderKind: observed?.record.holderKind ?? null,
|
|
156
|
+
image: holderAlive ? image(pid) : null,
|
|
147
157
|
ageMs: since === null ? null : Math.max(0, now() - since),
|
|
148
158
|
record: observed ? "complete" : incomplete?.ownerPath ? "incomplete" : incomplete ? "empty" : "unreadable",
|
|
149
159
|
};
|
|
@@ -153,16 +163,21 @@ function describeHolder(holder) {
|
|
|
153
163
|
const age = holder.ageMs === null ? "" : `, lease age ${Math.round(holder.ageMs / 1_000)}s`;
|
|
154
164
|
if (holder.record === "unreadable") return "holder unknown: the lock directory does not hold exactly one owner file";
|
|
155
165
|
if (holder.record === "empty") return `no owner file written yet${age}`;
|
|
156
|
-
const state = holder.
|
|
166
|
+
const state = holder.holderAlive ? ["alive", ...(holder.image ? [holder.image] : [])].join(", ") : "not alive";
|
|
157
167
|
const partial = holder.record === "incomplete" ? ", owner record incomplete" : "";
|
|
158
|
-
|
|
168
|
+
const delegate = holder.delegatePid === null ? "" : `, delegate PID ${holder.delegatePid} (identity unverified)`;
|
|
169
|
+
return `recorded PID ${holder.pid} [${state}, identity unverified${partial}]${delegate}${age}`;
|
|
159
170
|
}
|
|
160
171
|
|
|
161
172
|
const RECLAIM_HINT = `stale leases are reclaimed after ${STALE_MS / 1_000}s once the recorded PID is no longer alive`;
|
|
173
|
+
function reclaimHint(holder) {
|
|
174
|
+
return holder.delegatePid !== null || (holder.record === "complete" && holder.alive === null)
|
|
175
|
+
? `${RECLAIM_HINT} and any delegate is known absent or no longer alive` : RECLAIM_HINT;
|
|
176
|
+
}
|
|
162
177
|
|
|
163
178
|
/** The recorded lease owner for `statePaths`, identity unverified, or null if free. Reads only; never reclaims. */
|
|
164
179
|
export function inspectOwnershipMutationLease(statePaths, options = {}) {
|
|
165
|
-
return leaseHolder(leasePath(statePaths), options.now ?? Date.now, options.processAlive ?? processAlive,
|
|
180
|
+
return leaseHolder(options.lockPath ?? leasePath(statePaths), options.now ?? Date.now, options.processAlive ?? processAlive,
|
|
166
181
|
options.processImage ?? processImage);
|
|
167
182
|
}
|
|
168
183
|
|
|
@@ -171,13 +186,32 @@ export function ownershipMutationLeaseStatusLine(statePaths, options = {}) {
|
|
|
171
186
|
const holder = inspectOwnershipMutationLease(statePaths, options);
|
|
172
187
|
if (!holder) return null;
|
|
173
188
|
return `Runtime mutation lease busy at ${holder.path} (${describeHolder(holder)}); `
|
|
174
|
-
+ `opencodex waits for it to start or change service state, and ${
|
|
189
|
+
+ `opencodex waits for it to start or change service state, and ${reclaimHint(holder)}.`;
|
|
175
190
|
}
|
|
176
191
|
|
|
177
192
|
function createLeaseHandle(path, generation, token, options) {
|
|
178
193
|
let released = false;
|
|
179
194
|
return {
|
|
180
195
|
token,
|
|
196
|
+
addDelegate: pid => {
|
|
197
|
+
if (!Number.isSafeInteger(pid) || pid <= 0) throw new Error("invalid mutation lease delegate pid");
|
|
198
|
+
const current = held.get(path);
|
|
199
|
+
const observed = readOwner(path);
|
|
200
|
+
if (released || !current || current.generation !== generation || current.delegated || !observed || !sameOwner(current.snapshot, observed)) throw new Error("mutation lease is no longer held");
|
|
201
|
+
const temporary = `${path}.${randomUUID()}.tmp`;
|
|
202
|
+
let created = false;
|
|
203
|
+
try {
|
|
204
|
+
writeFileSync(temporary, `${JSON.stringify({ ...observed.record, delegatePid: pid })}\n`, { flag: "wx", mode: 0o600 });
|
|
205
|
+
created = true;
|
|
206
|
+
renameSync(temporary, observed.ownerPath);
|
|
207
|
+
created = false;
|
|
208
|
+
const updated = readOwner(path);
|
|
209
|
+
if (!updated || updated.record.token !== token || updated.record.delegatePid !== pid) throw new Error("mutation lease delegate could not be verified");
|
|
210
|
+
current.snapshot = updated;
|
|
211
|
+
} finally {
|
|
212
|
+
if (created) { try { unlinkSync(temporary); } catch (error) { if (error?.code !== "ENOENT") throw error; } }
|
|
213
|
+
}
|
|
214
|
+
},
|
|
181
215
|
release: () => {
|
|
182
216
|
if (released) return;
|
|
183
217
|
released = true;
|
|
@@ -192,6 +226,8 @@ function reclaim(path, now, alive) {
|
|
|
192
226
|
if (!observed && !incomplete) return false;
|
|
193
227
|
const createdAt = observed ? Math.max(observed.record.createdAt, observed.mtimeMs) : incomplete.mtimeMs;
|
|
194
228
|
const pid = observed?.record.pid ?? incomplete.pid;
|
|
229
|
+
const delegate = observed?.record.delegatePid;
|
|
230
|
+
if (delegate !== undefined && (!Number.isSafeInteger(delegate) || delegate <= 0 || alive(delegate))) return false;
|
|
195
231
|
if (now() - createdAt <= STALE_MS || (pid !== null && alive(pid))) return false;
|
|
196
232
|
if (observed) {
|
|
197
233
|
const current = readOwner(path);
|
|
@@ -209,17 +245,23 @@ export function acquireOwnershipMutationLease(
|
|
|
209
245
|
statePaths,
|
|
210
246
|
options = {},
|
|
211
247
|
) {
|
|
212
|
-
const path = leasePath(statePaths);
|
|
248
|
+
const path = options.lockPath ?? leasePath(statePaths);
|
|
213
249
|
const nested = held.get(path);
|
|
214
250
|
if (nested) {
|
|
251
|
+
if (options.isolated) {
|
|
252
|
+
const error = new Error("another operation owns the isolated mutation lease");
|
|
253
|
+
error.code = "OWNERSHIP_MUTATION_LEASE_BUSY";
|
|
254
|
+
error.holder = leaseHolder(path, options.now ?? Date.now, options.processAlive ?? processAlive, options.processImage ?? processImage);
|
|
255
|
+
throw error;
|
|
256
|
+
}
|
|
215
257
|
nested.depth += 1;
|
|
216
258
|
return createLeaseHandle(path, nested.generation, nested.snapshot.record.token, options);
|
|
217
259
|
}
|
|
218
260
|
const now = options.now ?? Date.now;
|
|
219
261
|
const alive = options.processAlive ?? processAlive;
|
|
220
262
|
const explicitJoinToken = options.joinToken;
|
|
221
|
-
const envJoinToken = process.env[OWNERSHIP_MUTATION_LEASE_TOKEN_ENV];
|
|
222
|
-
const joinToken = explicitJoinToken ?? envJoinToken ?? delegatedTokens.get(path);
|
|
263
|
+
const envJoinToken = options.isolated ? undefined : process.env[OWNERSHIP_MUTATION_LEASE_TOKEN_ENV];
|
|
264
|
+
const joinToken = options.isolated ? undefined : explicitJoinToken ?? envJoinToken ?? delegatedTokens.get(path);
|
|
223
265
|
if (joinToken) {
|
|
224
266
|
const owner = readOwner(path);
|
|
225
267
|
if (owner?.record.token === joinToken && alive(owner.record.pid)) {
|
|
@@ -237,7 +279,7 @@ export function acquireOwnershipMutationLease(
|
|
|
237
279
|
const deadline = now() + wait;
|
|
238
280
|
if (!existsSync(dirname(path))) mkdirSync(dirname(path), { recursive: true, mode: 0o700 });
|
|
239
281
|
for (;;) {
|
|
240
|
-
const record = { version: 1, pid: process.pid, processInstance: PROCESS_INSTANCE, token: randomUUID(), createdAt: now() };
|
|
282
|
+
const record = { version: 1, pid: process.pid, processInstance: PROCESS_INSTANCE, token: randomUUID(), createdAt: now(), ...(options.holderKind ? { holderKind: options.holderKind } : {}) };
|
|
241
283
|
const ownerPath = join(path, ownerName(record));
|
|
242
284
|
let madeDirectory = false;
|
|
243
285
|
let descriptor = null;
|
|
@@ -265,7 +307,7 @@ export function acquireOwnershipMutationLease(
|
|
|
265
307
|
if (now() >= deadline) {
|
|
266
308
|
const holder = leaseHolder(path, now, alive, options.processImage ?? processImage);
|
|
267
309
|
const error = new Error(`another process owns the runtime mutation lease at ${path}`
|
|
268
|
-
+ (holder ? ` (${describeHolder(holder)}; ${
|
|
310
|
+
+ (holder ? ` (${describeHolder(holder)}; ${reclaimHint(holder)})` : ""));
|
|
269
311
|
error.code = "OWNERSHIP_MUTATION_LEASE_BUSY";
|
|
270
312
|
error.holder = holder;
|
|
271
313
|
throw error;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Text encoding for the `<string>` and `<key>` values a generated launchd plist carries.
|
|
3
|
+
*
|
|
4
|
+
* XML 1.0 normalizes line ends in element content: a conforming parser reads a literal CR,
|
|
5
|
+
* or a CR LF pair, as one LF. CoreFoundation keeps the CR, but a value must not depend on
|
|
6
|
+
* which parser reads it, so CR, LF and tab are written as character references, which every
|
|
7
|
+
* parser returns unchanged. Characters XML 1.0 cannot represent at all are refused: a plist
|
|
8
|
+
* carrying one would be rejected or silently truncated by the parser that loads it.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const XML_FORBIDDEN = /[\u0000-\u0008\u000B\u000C\u000E-\u001F\uFFFE\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/;
|
|
12
|
+
|
|
13
|
+
const ENCODED: Record<string, string> = {
|
|
14
|
+
"&": "&",
|
|
15
|
+
"<": "<",
|
|
16
|
+
">": ">",
|
|
17
|
+
'"': """,
|
|
18
|
+
"'": "'",
|
|
19
|
+
"\t": "	",
|
|
20
|
+
"\n": " ",
|
|
21
|
+
"\r": " ",
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Encode one plist text value. `field` names the value in the refusal; the value itself is
|
|
26
|
+
* never echoed, because proxy environment values can carry credentials.
|
|
27
|
+
*/
|
|
28
|
+
export function encodePlistString(value: string, field: string): string {
|
|
29
|
+
const forbidden = XML_FORBIDDEN.exec(value);
|
|
30
|
+
if (forbidden) {
|
|
31
|
+
const code = forbidden[0].charCodeAt(0).toString(16).toUpperCase().padStart(4, "0");
|
|
32
|
+
throw new Error(
|
|
33
|
+
`refusing to write the launchd plist: ${field} contains U+${code}, which an XML 1.0 plist cannot represent. `
|
|
34
|
+
+ `Remove that character from ${field} and retry.`,
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
return value.replace(/[&<>"'\t\n\r]/g, ch => ENCODED[ch]!);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const NAMED: Record<string, string> = { amp: "&", lt: "<", gt: ">", quot: '"', apos: "'" };
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Decode a plist text value in one pass, so `&lt;` stays `<`. Unknown or invalid
|
|
44
|
+
* references are left as written.
|
|
45
|
+
*/
|
|
46
|
+
export function decodePlistString(raw: string): string {
|
|
47
|
+
return raw.replace(/&(#x[0-9a-fA-F]+|#[0-9]+|amp|lt|gt|quot|apos);/g, (match, ref: string) => {
|
|
48
|
+
if (!ref.startsWith("#")) return NAMED[ref]!;
|
|
49
|
+
const code = ref.startsWith("#x") ? parseInt(ref.slice(2), 16) : Number(ref.slice(1));
|
|
50
|
+
return code <= 0x10FFFF ? String.fromCodePoint(code) : match;
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** `<key>NAME</key><string>VALUE</string>` from a plist body, decoded, or null. */
|
|
55
|
+
export function plistKeyedString(body: string, key: string): string | null {
|
|
56
|
+
const escaped = key.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
57
|
+
const match = new RegExp(`<key>\\s*${escaped}\\s*</key>\\s*<string>([^<]*)</string>`).exec(body);
|
|
58
|
+
return match ? decodePlistString(match[1]!) : null;
|
|
59
|
+
}
|
package/src/service/state.ts
CHANGED
|
@@ -222,6 +222,14 @@ export function currentCodexHome(deps: CodexHomeDeps = {}): string {
|
|
|
222
222
|
return resolveCodexHomeDir(deps);
|
|
223
223
|
}
|
|
224
224
|
|
|
225
|
+
/** Resolve an explicit CODEX_HOME using Windows path rules for generated service artifacts. */
|
|
226
|
+
export function currentWindowsServiceCodexHome(): string {
|
|
227
|
+
const raw = process.env.CODEX_HOME?.trim();
|
|
228
|
+
if (!raw) return currentCodexHome();
|
|
229
|
+
const expanded = expandUserPath(raw);
|
|
230
|
+
return win32.isAbsolute(expanded) ? win32.normalize(expanded) : resolve(expanded);
|
|
231
|
+
}
|
|
232
|
+
|
|
225
233
|
export function currentCodexSqliteHomeAbsolute(target: "native" | "windows" = "native"): string | undefined {
|
|
226
234
|
const raw = process.env.CODEX_SQLITE_HOME?.trim();
|
|
227
235
|
if (!raw) return undefined;
|
|
@@ -12,6 +12,8 @@ function decodeQuoted(value: string): string | undefined {
|
|
|
12
12
|
} else if (char === "\\") {
|
|
13
13
|
const escaped = value[++index];
|
|
14
14
|
if (escaped === "n") decoded += "\n";
|
|
15
|
+
else if (escaped === "r") decoded += "\r";
|
|
16
|
+
else if (escaped === "t") decoded += "\t";
|
|
15
17
|
else if (escaped === "\\" || escaped === '"') decoded += escaped;
|
|
16
18
|
else return undefined;
|
|
17
19
|
} else if (char === '"' || char === "\0") {
|
package/src/service/systemd.ts
CHANGED
|
@@ -8,9 +8,9 @@ import { BUN_RUNTIME_PATH_ENV, BUN_RUNTIME_SOURCE_ENV, durableBunRuntime, type D
|
|
|
8
8
|
import { recordOwnedConfigPath } from "../lib/config-ownership";
|
|
9
9
|
import { systemdProperty } from "../service-manager-probe";
|
|
10
10
|
import { writeServiceApiTokenFile, sh } from "./guards";
|
|
11
|
-
import { shellQuote, buildServiceShellCommand, buildServiceLauncherShellCommand, resolvedProxyEnv } from "./definition";
|
|
11
|
+
import { shellQuote, buildServiceShellCommand, buildServiceLauncherShellCommand, resolvedProxyEnv, pinnedServiceHomeShellAssignments } from "./definition";
|
|
12
12
|
import type { ServiceInstallCleanupOps } from "./orchestration";
|
|
13
|
-
import { SERVICE_MANAGED_ENV, TASK, cliEntry, filterTransientServicePath, stableLauncherEntry, logPath, serviceStatePath, currentCodexSqliteHomeAbsolute, writeServiceInstallState } from "./state";
|
|
13
|
+
import { SERVICE_MANAGED_ENV, TASK, cliEntry, filterTransientServicePath, stableLauncherEntry, logPath, serviceStatePath, currentCodexSqliteHomeAbsolute, currentCodexHome, currentOpenCodexHome, writeServiceInstallState } from "./state";
|
|
14
14
|
import { writeServiceDefinitionFile } from "./windows-ops";
|
|
15
15
|
|
|
16
16
|
/** The `--port <n>` baked into the installed systemd user unit. Linux only. */
|
|
@@ -26,12 +26,29 @@ export function systemdListenPort(deps: { readUnit?: () => string } = {}): numbe
|
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
/**
|
|
30
|
+
* Quote one word for a systemd unit setting. systemd unquotes double-quoted words with C-style
|
|
31
|
+
* escapes (systemd.syntax), so backslash, double quote and line breaks are escaped, and it
|
|
32
|
+
* resolves `%` specifiers in every setting used here, so a literal `%` becomes `%%`.
|
|
33
|
+
*/
|
|
29
34
|
function systemdQuote(value: string): string {
|
|
30
35
|
return `"${value
|
|
31
36
|
.replace(/\\/g, "\\\\")
|
|
32
37
|
.replace(/"/g, "\\\"")
|
|
33
38
|
.replace(/%/g, "%%")
|
|
34
|
-
.replace(/\n/g, "\\n")
|
|
39
|
+
.replace(/\n/g, "\\n")
|
|
40
|
+
.replace(/\r/g, "\\r")
|
|
41
|
+
.replace(/\t/g, "\\t")}"`;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Quote one ExecStart= word. On top of {@link systemdQuote}, ExecStart= expands `$NAME` and
|
|
46
|
+
* `${NAME}` from the unit environment before the program runs (systemd.service, "Command
|
|
47
|
+
* lines"), so a literal `$` must be written `$$`. Environment= does not expand variables,
|
|
48
|
+
* which is why this escape stays out of the shared quoting.
|
|
49
|
+
*/
|
|
50
|
+
function systemdExecQuote(value: string): string {
|
|
51
|
+
return systemdQuote(value).replace(/\$/g, "$$$$");
|
|
35
52
|
}
|
|
36
53
|
|
|
37
54
|
function systemdEnvironmentAssignment(name: string, value: string | undefined): string | null {
|
|
@@ -60,9 +77,16 @@ export function buildUnit(
|
|
|
60
77
|
const launcher = deps.launcher ?? null;
|
|
61
78
|
const log = logPath();
|
|
62
79
|
const path = filterTransientServicePath(process.env.PATH ?? "/usr/local/bin:/usr/bin:/bin", ":", "linux");
|
|
63
|
-
|
|
80
|
+
// Resolve each home once: the default Codex home follows filesystem state (a retargeted
|
|
81
|
+
// ~/.codex link), so a second resolution could write two different homes into one unit.
|
|
82
|
+
const codexHomeValue = currentCodexHome();
|
|
83
|
+
const opencodexHomeValue = currentOpenCodexHome();
|
|
84
|
+
const codexHome = systemdEnvironmentAssignment("CODEX_HOME", codexHomeValue);
|
|
64
85
|
const codexSqliteHome = systemdEnvironmentAssignment("CODEX_SQLITE_HOME", currentCodexSqliteHomeAbsolute());
|
|
65
|
-
const opencodexHome = systemdEnvironmentAssignment("OPENCODEX_HOME",
|
|
86
|
+
const opencodexHome = systemdEnvironmentAssignment("OPENCODEX_HOME", opencodexHomeValue);
|
|
87
|
+
// The Environment= lines are a first pin only: ExecStart is /bin/sh -lc, so a login profile
|
|
88
|
+
// can re-export the homes after systemd supplies them. The command re-assigns both after
|
|
89
|
+
// profile initialization and before exec, with the same shell quoting the rest of the line uses.
|
|
66
90
|
const envLines = [
|
|
67
91
|
systemdEnvironmentAssignment("OCX_SERVICE", "1"),
|
|
68
92
|
systemdEnvironmentAssignment(SERVICE_MANAGED_ENV, "1"),
|
|
@@ -82,7 +106,7 @@ export function buildUnit(
|
|
|
82
106
|
opencodexHome,
|
|
83
107
|
...proxyEnv.map(({ name, value }) => systemdEnvironmentAssignment(name, value)),
|
|
84
108
|
].filter((line): line is string => Boolean(line)).join("\n");
|
|
85
|
-
const command = `${launcher ? buildServiceLauncherShellCommand(launcher) : buildServiceShellCommand(bun, cli)} >> ${shellQuote(log)} 2>&1`;
|
|
109
|
+
const command = `${pinnedServiceHomeShellAssignments(codexHomeValue, opencodexHomeValue)} ${launcher ? buildServiceLauncherShellCommand(launcher) : buildServiceShellCommand(bun, cli)} >> ${shellQuote(log)} 2>&1`;
|
|
86
110
|
return `[Unit]
|
|
87
111
|
Description=OpenCodex Proxy Server
|
|
88
112
|
After=network-online.target
|
|
@@ -90,7 +114,7 @@ Wants=network-online.target
|
|
|
90
114
|
|
|
91
115
|
[Service]
|
|
92
116
|
Type=simple
|
|
93
|
-
ExecStart=${
|
|
117
|
+
ExecStart=${systemdExecQuote("/bin/sh")} -lc ${systemdExecQuote(command)}
|
|
94
118
|
Restart=on-failure
|
|
95
119
|
RestartSec=5
|
|
96
120
|
${envLines}
|
|
@@ -9,12 +9,19 @@ import { serviceApiTokenFilePath } from "../lib/service-secrets";
|
|
|
9
9
|
import { windowsEnvIndirectBatchPathList, windowsEnvIndirectBatchValue } from "../lib/win-paths";
|
|
10
10
|
import { cachedCurrentWindowsIdentity, resolveCurrentWindowsPrincipal, WINDOWS_PRINCIPAL_LOOKUP_TIMEOUT_MS } from "../lib/windows-user-principal";
|
|
11
11
|
import { resolveServiceListenPort, resolvedProxyEnv } from "./definition";
|
|
12
|
-
import { cliEntry, filterTransientServicePath, serviceLogPath, currentCodexSqliteHomeAbsolute } from "./state";
|
|
12
|
+
import { cliEntry, filterTransientServicePath, serviceLogPath, currentCodexSqliteHomeAbsolute, currentWindowsServiceCodexHome, currentOpenCodexHome } from "./state";
|
|
13
13
|
|
|
14
|
+
/**
|
|
15
|
+
* Escape a value for the quoted `set "NAME=value"` form every wrapper assignment uses.
|
|
16
|
+
* Inside the quotes cmd treats `^`, `&`, `|`, `<`, `>` and parentheses as literal, so a
|
|
17
|
+
* caret must stay single: doubling it would point the variable at a different path. Percent
|
|
18
|
+
* expansion still runs in a batch file, so `%` becomes `%%`. `!` is literal because the
|
|
19
|
+
* wrapper runs under DisableDelayedExpansion. A quote or line break cannot be represented
|
|
20
|
+
* and is dropped.
|
|
21
|
+
*/
|
|
14
22
|
function windowsBatchValue(value: string): string {
|
|
15
23
|
return value
|
|
16
24
|
.replace(/%/g, "%%")
|
|
17
|
-
.replace(/\^/g, "^^")
|
|
18
25
|
.replace(/"/g, "")
|
|
19
26
|
.replace(/[\r\n]/g, "");
|
|
20
27
|
}
|
|
@@ -80,12 +87,14 @@ export function buildWindowsServiceScript(
|
|
|
80
87
|
windowsBatchSet(BUN_RUNTIME_SOURCE_ENV, bunRuntimeSource),
|
|
81
88
|
windowsBatchSet(BUN_RUNTIME_PATH_ENV, bun, "path"),
|
|
82
89
|
windowsBatchSet("PATH", path, "pathList"),
|
|
83
|
-
windowsBatchSet("CODEX_HOME",
|
|
84
|
-
windowsBatchSet("CODEX_SQLITE_HOME", currentCodexSqliteHomeAbsolute("windows")
|
|
85
|
-
windowsBatchSet("OPENCODEX_HOME",
|
|
90
|
+
windowsBatchSet("CODEX_HOME", currentWindowsServiceCodexHome()),
|
|
91
|
+
windowsBatchSet("CODEX_SQLITE_HOME", currentCodexSqliteHomeAbsolute("windows")),
|
|
92
|
+
windowsBatchSet("OPENCODEX_HOME", currentOpenCodexHome()),
|
|
86
93
|
...proxyEnv.map(({ name, value }) => windowsBatchSet(name, value)),
|
|
87
|
-
|
|
88
|
-
|
|
94
|
+
// Absolute like the homes above: a profile-variable form could read the token, or write
|
|
95
|
+
// the log, under another profile than the home the proxy is pinned to.
|
|
96
|
+
windowsBatchSet("OCX_API_TOKEN_FILE", serviceApiTokenFilePath()),
|
|
97
|
+
windowsBatchSet("OCX_SERVICE_LOG", serviceLogPath()),
|
|
89
98
|
windowsBatchSet("OCX_BUN", bun, "path"),
|
|
90
99
|
windowsBatchSet("OCX_CLI", cli ?? undefined, "path"),
|
|
91
100
|
// Standalone executables have no npm package tree; recovery is "replace the executable", so no OCX_PKG_DIR/restore_backup wiring.
|
|
@@ -28,6 +28,7 @@ import {
|
|
|
28
28
|
} from "./lib/windows-elevation";
|
|
29
29
|
import { decodeWindowsTextBytes } from "./lib/windows-text";
|
|
30
30
|
import { WINSW_SERVICE_ID } from "./lib/winsw";
|
|
31
|
+
import { decodePlistString } from "./service/plist-xml";
|
|
31
32
|
import { BUN_RUNTIME_PATH_ENV, BUN_RUNTIME_SOURCE_ENV } from "./lib/bun-runtime";
|
|
32
33
|
import { REAL_BUN_MIN_BYTES } from "./lib/bun-binary-validator.mjs";
|
|
33
34
|
import { WINDOWS_WRAPPER_PROTOCOL_ENV, WINDOWS_WRAPPER_STAY_OUT_EXIT_CODE } from "./service/windows-wrapper-exit";
|
|
@@ -247,16 +248,9 @@ function unknown(reason: string): ServiceManagerInstallation {
|
|
|
247
248
|
return { kind: "unknown", reason };
|
|
248
249
|
}
|
|
249
250
|
|
|
250
|
-
/** Decode the entities buildPlist's
|
|
251
|
-
* literal `&lt;` written by a double-escaped value stays `<`. */
|
|
252
|
-
|
|
253
|
-
return raw
|
|
254
|
-
.replace(/</g, "<")
|
|
255
|
-
.replace(/>/g, ">")
|
|
256
|
-
.replace(/"/g, "\"")
|
|
257
|
-
.replace(/'/g, "'")
|
|
258
|
-
.replace(/&/g, "&");
|
|
259
|
-
}
|
|
251
|
+
/** Decode the entities and character references buildPlist's encoder applies, in one pass,
|
|
252
|
+
* so a literal `&lt;` written by a double-escaped value stays `<`. */
|
|
253
|
+
const plistStringValue = decodePlistString;
|
|
260
254
|
|
|
261
255
|
/** Pull `<key>NAME</key><string>VALUE</string>` out of a plist body. */
|
|
262
256
|
function plistEnvValue(body: string, key: string): string | null {
|
package/src/types/config.ts
CHANGED
|
@@ -1851,6 +1851,8 @@ export interface OcxWebSearchSidecarConfig {
|
|
|
1851
1851
|
export interface OcxCodexPoolConfig {
|
|
1852
1852
|
/** Start idle Codex windows when the pool is initialized. */
|
|
1853
1853
|
startIdleWindows?: boolean;
|
|
1854
|
+
/** Enable process-local affinity for caller-owned credentials; defaults off. */
|
|
1855
|
+
requestOwnedAffinity?: boolean;
|
|
1854
1856
|
/**
|
|
1855
1857
|
* Plan keys ordinary rotation skips, matched case-insensitively against the plan stored on each
|
|
1856
1858
|
* account. Absent or empty means no policy.
|
package/src/types/provider.ts
CHANGED
|
@@ -294,6 +294,8 @@ export interface ModelCapabilities extends ReasoningCapabilities {
|
|
|
294
294
|
video?: { processing?: "static" | "agentic" };
|
|
295
295
|
/** Opt in exact first-party DeepSeek models to one-hour image file persistence. */
|
|
296
296
|
deepseekImageFiles?: boolean;
|
|
297
|
+
/** Images a first-party Mistral Chat request may carry for this model; older ones are pruned. */
|
|
298
|
+
mistralMaxImages?: number;
|
|
297
299
|
}
|
|
298
300
|
|
|
299
301
|
/**
|
package/src/types/request.ts
CHANGED
|
@@ -86,6 +86,11 @@ export interface OcxParsedRequest {
|
|
|
86
86
|
* followed them (`call:<tool_use id>` / `text:<text>`). Same audience as `_anthropicServerTools`.
|
|
87
87
|
*/
|
|
88
88
|
_anthropicServerReplay?: ReadonlyMap<string, readonly Record<string, unknown>[]>;
|
|
89
|
+
/**
|
|
90
|
+
* The caller's `instructions` prefix through its last cache-marked system block. The anthropic
|
|
91
|
+
* adapter ends a system block there so the breakpoint stays off the per-turn tail.
|
|
92
|
+
*/
|
|
93
|
+
_anthropicSystemCachePrefix?: string;
|
|
89
94
|
/**
|
|
90
95
|
* Boundary between replayed history and this turn's newly appended input. Usually the
|
|
91
96
|
* items the proxy restored from local previous_response_id state; also set when the
|
|
@@ -180,6 +185,13 @@ export interface OcxParsedRequest {
|
|
|
180
185
|
* answer/"Sources:" text can't bleed into and corrupt the model's schema-constrained output.
|
|
181
186
|
*/
|
|
182
187
|
_structuredOutput?: boolean;
|
|
188
|
+
/**
|
|
189
|
+
* True for a Claude Messages `output_config.format` json_schema. Anthropic promises an answer
|
|
190
|
+
* that conforms to that schema, whatever `strict` the Responses translation states for
|
|
191
|
+
* OpenAI-compatible destinations, so an emulating adapter (Kiro) holds it to full conformance.
|
|
192
|
+
* Process-local; never forwarded.
|
|
193
|
+
*/
|
|
194
|
+
_structuredOutputConformance?: boolean;
|
|
183
195
|
/**
|
|
184
196
|
* True when the input carried `{type:"compaction_trigger"}` — Codex remote compaction v2 asking
|
|
185
197
|
* this turn to produce a `{type:"compaction"}` output item. Routed adapters can't natively;
|
|
@@ -414,7 +426,7 @@ export interface OcxRequestOptions {
|
|
|
414
426
|
* upstream wire has an equivalent. The openai-chat adapter re-nests it as chat
|
|
415
427
|
* `response_format`, the exact inverse of responseFormatToText in src/chat/inbound.ts.
|
|
416
428
|
* The native passthrough ignores it (it forwards `_rawBody.text` verbatim) and Kiro
|
|
417
|
-
*
|
|
429
|
+
* emulates it through a private structured-output tool (src/adapters/kiro/structured-output.ts).
|
|
418
430
|
*/
|
|
419
431
|
textFormat?: {
|
|
420
432
|
type: "json_schema" | "json_object";
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { closeSync, constants, fstatSync, lstatSync, openSync, readFileSync } from "node:fs";
|
|
2
|
+
import { configDiagnosticsFromRaw } from "../config/diagnostics";
|
|
3
|
+
|
|
4
|
+
export interface ConfigPreflightResult {
|
|
5
|
+
ok: boolean;
|
|
6
|
+
reason?: "fallback" | "read_error";
|
|
7
|
+
error?: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/** Observe the same opened file for type and passive runtime loadability. */
|
|
11
|
+
export function runConfigPreflight(configPath: string, open: typeof openSync = openSync, close: typeof closeSync = closeSync): ConfigPreflightResult {
|
|
12
|
+
let fd: number;
|
|
13
|
+
try {
|
|
14
|
+
// Nonblocking open avoids hanging on a FIFO before its type can be checked.
|
|
15
|
+
fd = open(configPath, constants.O_RDONLY | constants.O_NONBLOCK);
|
|
16
|
+
} catch (error: unknown) {
|
|
17
|
+
if ((error as NodeJS.ErrnoException).code === "ENOENT") {
|
|
18
|
+
try {
|
|
19
|
+
// A dangling link occupies the path even though opening its target failed.
|
|
20
|
+
lstatSync(configPath);
|
|
21
|
+
} catch (entryError: unknown) {
|
|
22
|
+
if ((entryError as NodeJS.ErrnoException).code === "ENOENT") return { ok: true };
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return { ok: false, reason: "read_error", error: "Configuration cannot be read as a regular file." };
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
let result: ConfigPreflightResult;
|
|
29
|
+
try {
|
|
30
|
+
if (!fstatSync(fd).isFile()) {
|
|
31
|
+
result = { ok: false, reason: "read_error", error: "Configuration is not a regular file." };
|
|
32
|
+
} else {
|
|
33
|
+
const raw = readFileSync(fd, "utf8");
|
|
34
|
+
result = runtimeAcceptsConfig(raw) ? { ok: true } : { ok: false, reason: "fallback", error: "Configuration failed to load." };
|
|
35
|
+
}
|
|
36
|
+
} catch {
|
|
37
|
+
result = { ok: false, reason: "read_error", error: "Configuration cannot be read as a regular file." };
|
|
38
|
+
} finally {
|
|
39
|
+
try { close(fd); } catch { result = { ok: false, reason: "read_error", error: "Configuration cannot be read as a regular file." }; }
|
|
40
|
+
}
|
|
41
|
+
return result;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function runtimeAcceptsConfig(raw: string): boolean {
|
|
45
|
+
// Imported text takes the same passive path as disk diagnostics, without a backup.
|
|
46
|
+
// Discard configuration-derived warnings, including provider and model names.
|
|
47
|
+
return configDiagnosticsFromRaw(raw, { warn: () => {} }).source === "file";
|
|
48
|
+
}
|