sneakoscope 7.3.0 → 7.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +129 -10
- package/crates/sks-core/Cargo.lock +1 -1
- package/crates/sks-core/Cargo.toml +1 -1
- package/dist/cli/codex-app-command.js +1 -1
- package/dist/cli/command-manifest-lite.js +4 -1
- package/dist/cli/command-registry.js +2 -0
- package/dist/cli/install-helpers-codex-lb-chain.js +42 -0
- package/dist/cli/install-helpers-codex-lb-config.js +114 -9
- package/dist/cli/install-helpers-install-support.js +6 -16
- package/dist/cli/install-helpers.js +788 -600
- package/dist/cli/router.js +30 -2
- package/dist/commands/codex-app.js +37 -1
- package/dist/commands/codex-lb.js +491 -300
- package/dist/config/skills-manifest.json +57 -71
- package/dist/core/align/align-route.js +127 -0
- package/dist/core/codex-app/codex-app-fast-ui-repair.js +8 -4
- package/dist/core/codex-app/codex-app-restart.js +83 -0
- package/dist/core/codex-app/codex-app-ui-state-snapshot.js +8 -4
- package/dist/core/codex-app/desktop-routing-snapshot.js +1 -1
- package/dist/core/codex-app/menubar/constants.js +5 -0
- package/dist/core/codex-app/menubar/generation-transaction-journal.js +1 -3
- package/dist/core/codex-app/menubar/installer.js +18 -0
- package/dist/core/codex-app/multi-provider-router.js +22 -10
- package/dist/core/codex-app/openrouter-activate.js +26 -1
- package/dist/core/codex-app.js +118 -26
- package/dist/core/codex-control/codex-app-server-runtime-env.js +86 -0
- package/dist/core/codex-control/codex-app-server-v2-client.js +78 -8
- package/dist/core/codex-control/codex-task-runner.js +2 -2
- package/dist/core/codex-lb/capability-runner.js +204 -0
- package/dist/core/codex-lb/capability-types.js +1 -0
- package/dist/core/codex-lb/codex-lb-env.js +9 -13
- package/dist/core/codex-lb/codex-lb-setup.js +45 -8
- package/dist/core/codex-lb/codex-lb-tool-catalog.js +52 -74
- package/dist/core/codex-lb/codex-lb-tool-output-recovery.js +1 -1
- package/dist/core/codex-lb/desktop-auth-invariant.js +185 -0
- package/dist/core/codex-lb/desktop-bridge/client.js +34 -0
- package/dist/core/codex-lb/desktop-bridge/header-policy.js +106 -0
- package/dist/core/codex-lb/desktop-bridge/http-forward.js +101 -0
- package/dist/core/codex-lb/desktop-bridge/index.js +10 -0
- package/dist/core/codex-lb/desktop-bridge/launchd.js +81 -0
- package/dist/core/codex-lb/desktop-bridge/location-rewrite.js +27 -0
- package/dist/core/codex-lb/desktop-bridge/security.js +274 -0
- package/dist/core/codex-lb/desktop-bridge/server.js +179 -0
- package/dist/core/codex-lb/desktop-bridge/state.js +119 -0
- package/dist/core/codex-lb/desktop-bridge/types.js +16 -0
- package/dist/core/codex-lb/desktop-bridge/websocket-forward.js +151 -0
- package/dist/core/codex-lb/desktop-center-credentials.js +189 -0
- package/dist/core/codex-lb/desktop-controller.js +1410 -0
- package/dist/core/codex-lb/desktop-mode.js +32 -0
- package/dist/core/codex-lb/desktop-real-evidence.js +168 -0
- package/dist/core/codex-lb/desktop-service.js +613 -0
- package/dist/core/codex-lb/legacy-migration.js +575 -0
- package/dist/core/codex-lb/migration-receipt.js +246 -0
- package/dist/core/codex-lb/probes/auxiliary-surfaces-probe.js +60 -0
- package/dist/core/codex-lb/probes/bridge-probe.js +75 -0
- package/dist/core/codex-lb/probes/catalog-probe.js +128 -0
- package/dist/core/codex-lb/probes/computer-use-probe.js +50 -0
- package/dist/core/codex-lb/probes/image-generation-probe.js +47 -0
- package/dist/core/codex-lb/probes/probe-evidence.js +39 -0
- package/dist/core/codex-lb/probes/voice-realtime-probe.js +44 -0
- package/dist/core/codex-lb/trusted-deep-evidence.js +403 -0
- package/dist/core/codex-native/core-skill-manifest.js +22 -6
- package/dist/core/codex-runtime/codex-desktop-config-policy.js +2 -1
- package/dist/core/commands/align-command.js +220 -0
- package/dist/core/commands/image-ux-review-command.js +280 -68
- package/dist/core/commands/naruto-command.js +257 -8
- package/dist/core/commands/ppt-command.js +2 -2
- package/dist/core/commands/telegram-command.js +402 -34
- package/dist/core/commands/triwiki-command.js +11 -1
- package/dist/core/commands/triwiki-graph-command.js +160 -0
- package/dist/core/commands/wiki-command.js +100 -20
- package/dist/core/doctor/skill-legacy-surface.js +1 -3
- package/dist/core/errors/message.js +3 -0
- package/dist/core/evidence/evidence-freshness.js +14 -0
- package/dist/core/feature-fixtures.js +9 -1
- package/dist/core/feature-registry.js +5 -3
- package/dist/core/fsx.js +7 -3
- package/dist/core/hooks-runtime/codex-commit-hooks-selftest.js +82 -0
- package/dist/core/hooks-runtime/context-graph-freshness-preflight.js +113 -0
- package/dist/core/hooks-runtime/hook-context.js +15 -2
- package/dist/core/hooks-runtime/managed-skill-generation-heal.js +46 -0
- package/dist/core/hooks-runtime/naruto-terminal-finalization.js +1 -0
- package/dist/core/hooks-runtime/official-subagent-lifecycle.js +1 -1
- package/dist/core/hooks-runtime/tool-output-quarantine.js +1 -1
- package/dist/core/hooks-runtime.js +33 -89
- package/dist/core/image-ux-review/callout-extraction.js +6 -0
- package/dist/core/image-ux-review/imagegen-adapter.js +64 -23
- package/dist/core/image-ux-review/real-callout-extractor.js +1 -0
- package/dist/core/image-ux-review.js +230 -12
- package/dist/core/imagegen/codex-lb-imagegen-target.js +21 -7
- package/dist/core/imagegen/imagegen-capability.js +10 -4
- package/dist/core/imagegen/require-imagegen.js +29 -5
- package/dist/core/init/skills.js +25 -13
- package/dist/core/init.js +1 -1
- package/dist/core/install/installed-package-smoke.js +157 -4
- package/dist/core/managed-assets/managed-assets-manifest.js +2 -1
- package/dist/core/managed-path-safety.js +8 -10
- package/dist/core/mcp-config/backup.js +2 -4
- package/dist/core/mcp-config/config-reader.js +2 -4
- package/dist/core/mcp-config/scope.js +3 -5
- package/dist/core/naruto/context-graph-advisor-scope.js +242 -0
- package/dist/core/naruto/context-graph-advisor.js +0 -0
- package/dist/core/perf/release-latency-slo.js +12 -6
- package/dist/core/pipeline-internals/runtime-core.js +78 -0
- package/dist/core/pipeline-internals/runtime-gates.js +5 -2
- package/dist/core/policy/latest-version-guidance.js +113 -0
- package/dist/core/ppt.js +8 -8
- package/dist/core/preflight/parallel-preflight-engine.js +1 -1
- package/dist/core/proof/auto-finalize.js +98 -6
- package/dist/core/proof/route-proof-gate.js +12 -1
- package/dist/core/proof/route-proof-policy.js +8 -8
- package/dist/core/release/gate-manifest.js +32 -1
- package/dist/core/release/npm-stage-contract.js +21 -0
- package/dist/core/release/package-size-budget.js +2 -2
- package/dist/core/release/release-gate-contract.js +5 -0
- package/dist/core/release/release-proof-io.js +1 -3
- package/dist/core/release/release-real-contract.js +5 -4
- package/dist/core/release/release-stamp-proof.js +1 -3
- package/dist/core/release/stage-publish.js +27 -0
- package/dist/core/remote/audit-idempotency.js +50 -18
- package/dist/core/remote/codex-public-activity.js +283 -0
- package/dist/core/remote/index.js +1 -0
- package/dist/core/remote/ssh-worker-client.js +4 -1
- package/dist/core/remote/worker.js +206 -27
- package/dist/core/research/research-adversarial-review.js +1 -3
- package/dist/core/research/research-claim-synthesizer.js +1 -3
- package/dist/core/research/research-falsification-runner.js +1 -3
- package/dist/core/research/research-source-evidence.js +1 -3
- package/dist/core/responses-stream.js +65 -19
- package/dist/core/routes/constants.js +1 -1
- package/dist/core/routes/design-policy.js +7 -2
- package/dist/core/routes/dollar-manifest-lite.js +2 -4
- package/dist/core/routes/evidence.js +1 -1
- package/dist/core/routes.js +30 -10
- package/dist/core/safety/command-contract/contracts.js +2 -0
- package/dist/core/safety/command-contract/types.js +1 -1
- package/dist/core/search/context-graph-seeds.js +205 -0
- package/dist/core/search/context.js +0 -0
- package/dist/core/search/provider.js +2 -2
- package/dist/core/secret-redaction.js +6 -0
- package/dist/core/subagents/naruto-help-contract.js +2 -1
- package/dist/core/subagents/naruto-host-credentials.js +161 -0
- package/dist/core/subagents/official-subagent-preparation.js +4 -1
- package/dist/core/subagents/official-subagent-prompt.js +44 -2
- package/dist/core/subagents/official-subagent-runner.js +26 -8
- package/dist/core/subagents/triwiki-attention.js +135 -123
- package/dist/core/telegram/bot-api.js +85 -10
- package/dist/core/telegram/center-snapshot.js +718 -0
- package/dist/core/telegram/config.js +158 -31
- package/dist/core/telegram/hub.js +288 -33
- package/dist/core/telegram/index.js +2 -0
- package/dist/core/telegram/ingress-spool.js +419 -0
- package/dist/core/telegram/ledgers.js +188 -29
- package/dist/core/telegram/messages.js +26 -6
- package/dist/core/telegram/owner-lock.js +10 -7
- package/dist/core/telegram/runtime-projection.js +38 -3
- package/dist/core/telegram/runtime.js +298 -63
- package/dist/core/telegram/service.js +137 -8
- package/dist/core/telegram/setup.js +291 -73
- package/dist/core/text/strings.js +3 -0
- package/dist/core/triwiki/code-pack.js +12 -120
- package/dist/core/triwiki/context-graph/compiler/cache-key.js +277 -0
- package/dist/core/triwiki/context-graph/compiler/extract.js +104 -0
- package/dist/core/triwiki/context-graph/compiler/freshness.js +108 -0
- package/dist/core/triwiki/context-graph/compiler/index.js +237 -0
- package/dist/core/triwiki/context-graph/compiler/merge.js +0 -0
- package/dist/core/triwiki/context-graph/compiler/serialize.js +115 -0
- package/dist/core/triwiki/context-graph/contracts.js +236 -0
- package/dist/core/triwiki/context-graph/extractors/code/builders.js +150 -0
- package/dist/core/triwiki/context-graph/extractors/code/declarations.js +161 -0
- package/dist/core/triwiki/context-graph/extractors/code/index.js +265 -0
- package/dist/core/triwiki/context-graph/extractors/code/inventory.js +237 -0
- package/dist/core/triwiki/context-graph/extractors/code/module-graph.js +252 -0
- package/dist/core/triwiki/context-graph/extractors/code/modules.js +79 -0
- package/dist/core/triwiki/context-graph/extractors/code/references.js +184 -0
- package/dist/core/triwiki/context-graph/extractors/code/selection.js +100 -0
- package/dist/core/triwiki/context-graph/extractors/code/ts-config.js +161 -0
- package/dist/core/triwiki/context-graph/extractors/code/types.js +18 -0
- package/dist/core/triwiki/context-graph/extractors/evidence/claims.js +289 -0
- package/dist/core/triwiki/context-graph/extractors/evidence/index.js +54 -0
- package/dist/core/triwiki/context-graph/extractors/evidence/proof-index.js +213 -0
- package/dist/core/triwiki/context-graph/extractors/evidence/proofs.js +266 -0
- package/dist/core/triwiki/context-graph/extractors/evidence/redaction.js +177 -0
- package/dist/core/triwiki/context-graph/extractors/evidence/shared.js +0 -0
- package/dist/core/triwiki/context-graph/extractors/evidence/sources.js +154 -0
- package/dist/core/triwiki/context-graph/extractors/index.js +7 -0
- package/dist/core/triwiki/context-graph/extractors/topology/commands.js +207 -0
- package/dist/core/triwiki/context-graph/extractors/topology/gate-edges.js +201 -0
- package/dist/core/triwiki/context-graph/extractors/topology/gates.js +182 -0
- package/dist/core/triwiki/context-graph/extractors/topology/globs.js +124 -0
- package/dist/core/triwiki/context-graph/extractors/topology/index.js +92 -0
- package/dist/core/triwiki/context-graph/extractors/topology/routes.js +135 -0
- package/dist/core/triwiki/context-graph/extractors/topology/shared.js +215 -0
- package/dist/core/triwiki/context-graph/graph-index.js +143 -0
- package/dist/core/triwiki/context-graph/ids.js +0 -0
- package/dist/core/triwiki/context-graph/lint/index.js +0 -0
- package/dist/core/triwiki/context-graph/lint/rules.js +232 -0
- package/dist/core/triwiki/context-graph/lint/warnings.js +93 -0
- package/dist/core/triwiki/context-graph/paths.js +116 -0
- package/dist/core/triwiki/context-graph/profiles.js +78 -0
- package/dist/core/triwiki/context-graph/projections/anchors.js +91 -0
- package/dist/core/triwiki/context-graph/projections/attention.js +58 -0
- package/dist/core/triwiki/context-graph/projections/code-pack-workspace.js +62 -0
- package/dist/core/triwiki/context-graph/projections/code-pack.js +144 -0
- package/dist/core/triwiki/context-graph/projections/index.js +7 -0
- package/dist/core/triwiki/context-graph/projections/module-view.js +140 -0
- package/dist/core/triwiki/context-graph/projections/node-summary.js +118 -0
- package/dist/core/triwiki/context-graph/projections/pack-contract.js +6 -0
- package/dist/core/triwiki/context-graph/query/explain.js +0 -0
- package/dist/core/triwiki/context-graph/query/index.js +178 -0
- package/dist/core/triwiki/context-graph/query/load.js +116 -0
- package/dist/core/triwiki/context-graph/query/pack.js +117 -0
- package/dist/core/triwiki/context-graph/query/rank.js +142 -0
- package/dist/core/triwiki/context-graph/query/ranking-config.js +64 -0
- package/dist/core/triwiki/context-graph/query/seeds.js +241 -0
- package/dist/core/triwiki/context-graph/query/snapshot-cache.js +72 -0
- package/dist/core/triwiki/context-graph/query/traverse.js +154 -0
- package/dist/core/triwiki/context-graph/query-types.js +29 -0
- package/dist/core/triwiki/context-graph/store/compile-lock.js +21 -0
- package/dist/core/triwiki/context-graph/store/event-log.js +48 -0
- package/dist/core/triwiki/context-graph/store/fragment-cache.js +85 -0
- package/dist/core/triwiki/context-graph/store/graph-status.js +85 -0
- package/dist/core/triwiki/context-graph/store/snapshot-store.js +155 -0
- package/dist/core/triwiki/triwiki-proof-bank-index-repair.js +115 -0
- package/dist/core/triwiki/triwiki-proof-bank-index-store.js +290 -0
- package/dist/core/triwiki/triwiki-proof-bank-index.js +126 -0
- package/dist/core/triwiki/triwiki-proof-bank.js +7 -1
- package/dist/core/verification/context-graph-affected.js +271 -0
- package/dist/core/version.js +1 -1
- package/dist/native/sks-menubar/Sources/AlertFactory.swift +11 -3
- package/dist/native/sks-menubar/Sources/AppDelegate.swift +9 -0
- package/dist/native/sks-menubar/Sources/ControlCenterWindowController.swift +25 -3
- package/dist/native/sks-menubar/Sources/ControlKit.swift +19 -8
- package/dist/native/sks-menubar/Sources/DiagnosticsViewController.swift +1 -2
- package/dist/native/sks-menubar/Sources/MCPServersViewController.swift +45 -17
- package/dist/native/sks-menubar/Sources/OverviewSummary.swift +162 -0
- package/dist/native/sks-menubar/Sources/OverviewViewController.swift +136 -190
- package/dist/native/sks-menubar/Sources/ProcessClient.swift +107 -11
- package/dist/native/sks-menubar/Sources/ProvidersMultiProvider.swift +5 -1
- package/dist/native/sks-menubar/Sources/ProvidersOpenRouter.swift +16 -4
- package/dist/native/sks-menubar/Sources/ProvidersRoleModels.swift +4 -1
- package/dist/native/sks-menubar/Sources/ProvidersRoutingTruth.swift +131 -0
- package/dist/native/sks-menubar/Sources/ProvidersViewController.swift +288 -341
- package/dist/native/sks-menubar/Sources/RemoteTelegramCenterState.swift +447 -0
- package/dist/native/sks-menubar/Sources/RemoteTelegramRendering.swift +484 -0
- package/dist/native/sks-menubar/Sources/RemoteTelegramViewController.swift +364 -115
- package/dist/native/sks-menubar/Sources/SettingsViewController.swift +73 -12
- package/dist/native/sks-menubar/Sources/SidebarItem.swift +3 -3
- package/dist/native/sks-menubar/Sources/StatusItemController.swift +13 -13
- package/dist/native/sks-menubar/Sources/TelegramHubSupervisor.swift +469 -0
- package/dist/native/sks-menubar/Sources/UpdatesViewController.swift +1 -6
- package/dist/native/sks-menubar/Tests/AppRuntimeTestSupport.swift +12 -0
- package/dist/native/sks-menubar/Tests/NativeTelegramRegressionRunner.swift +55 -0
- package/dist/native/sks-menubar/Tests/ProcessClientTests.swift +33 -0
- package/dist/native/sks-menubar/Tests/ProvidersViewControllerTests.swift +142 -0
- package/dist/native/sks-menubar/Tests/RemoteTelegramCenterStateTests.swift +56 -0
- package/dist/native/sks-menubar/Tests/TelegramHubSupervisorTests.swift +55 -0
- package/dist/scripts/codex-lb-catalog-passthrough-check.js +120 -0
- package/dist/scripts/codex-lb-desktop-auth-invariant-check.js +169 -0
- package/dist/scripts/codex-lb-desktop-bridge-check.js +394 -0
- package/dist/scripts/codex-lb-desktop-bridge-latency-check.js +196 -0
- package/dist/scripts/codex-lb-desktop-capabilities-check.js +287 -0
- package/dist/scripts/codex-lb-desktop-real-evidence-check.js +123 -0
- package/dist/scripts/codex-lb-fast-mode-truth-check.js +10 -3
- package/dist/scripts/codex-lb-fast-ui-preservation-check.js +81 -40
- package/dist/scripts/codex-lb-gpt56-fast-profile-check.js +99 -37
- package/dist/scripts/context-graph-check.js +191 -0
- package/dist/scripts/doctor-fixes-codex-app-fast-ui-check.js +1 -1
- package/dist/scripts/gate-policy-audit-check.js +1 -1
- package/dist/scripts/helper-dedup-check.js +0 -2
- package/dist/scripts/installed-package-smoke-check.js +4 -1
- package/dist/scripts/latest-version-guidance-check.js +74 -0
- package/dist/scripts/release-metadata-check.js +21 -4
- package/dist/scripts/release-real-check.js +7 -0
- package/dist/scripts/ux-review-imagegen-blackbox-check.js +25 -1
- package/dist/scripts/ux-review-run-wires-imagegen-check.js +9 -1
- package/package.json +8 -3
- package/release-gates.v2.json +176 -1
- package/runtime-required-scripts.json +30 -0
- package/schemas/triwiki/context-graph.schema.json +119 -0
- package/dist/cli/install-helpers-codex-lb-selftest-chain.js +0 -112
- package/dist/cli/install-helpers-codex-lb-selftest.js +0 -481
- package/dist/core/triwiki/code-index-scanner.js +0 -309
|
@@ -0,0 +1,1410 @@
|
|
|
1
|
+
import { createHash, randomBytes } from 'node:crypto';
|
|
2
|
+
import fsp from 'node:fs/promises';
|
|
3
|
+
import net from 'node:net';
|
|
4
|
+
import os from 'node:os';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import { configureCodexLbCliProvider, configureCodexLbDesktopRouting } from '../../cli/install-helpers.js';
|
|
7
|
+
import { CODEX_LB_DESKTOP_BRIDGE_MARKER, CODEX_LB_DESKTOP_COMPAT_MARKER, CODEX_LB_MODEL_CATALOG_MARKER } from '../../cli/install-helpers-codex-lb-config.js';
|
|
8
|
+
import { codexAuthPath, codexLbConfigPath } from '../../cli/install-helpers-codex-lb-shared.js';
|
|
9
|
+
import { codexLbResponseChainCapabilityEvidence, checkCodexLbResponseChain } from '../../cli/install-helpers-codex-lb-chain.js';
|
|
10
|
+
import { quitCodexApp, restartCodexApp } from '../codex-app/codex-app-restart.js';
|
|
11
|
+
import { readJson, readText } from '../fsx.js';
|
|
12
|
+
import { assertDesktopOAuthSemanticIdentity, captureCodexAuthSnapshot } from './desktop-auth-invariant.js';
|
|
13
|
+
import { runCodexLbDesktopCapabilityReport, shapeCodexLbDesktopCapabilityStatus } from './capability-runner.js';
|
|
14
|
+
import { codexLbEnvPath, codexLbMetadataPath, loadCodexLbEnv, normalizeCodexLbBaseUrl } from './codex-lb-env.js';
|
|
15
|
+
import { normalizeCodexLbToolCatalog } from './codex-lb-tool-catalog.js';
|
|
16
|
+
import { bootstrapExistingDesktopBridgeService, desktopBridgeServicePaths, desktopBridgeServiceStatus, installAndStartDesktopBridgeService, resolveDesktopBridgeActivationSettings, stopDesktopBridgeService } from './desktop-service.js';
|
|
17
|
+
import { DEFAULT_CODEX_LB_GATEWAY_AUTH_TRANSPORT, modeRequiresChatGptOAuth, parseCodexLbGatewayAuthTransport } from './desktop-mode.js';
|
|
18
|
+
import { detectLegacyCodexLbDesktopState, migrateLegacyCodexLbDesktop } from './legacy-migration.js';
|
|
19
|
+
import { syncDesktopCenterLaunchCredentials } from './desktop-center-credentials.js';
|
|
20
|
+
import { backupCodexLbMigrationFile, codexLbMigrationReceiptDir, createCodexLbMigrationReceiptId, fileSha256OrMissing, finalizeCodexLbMigrationReceiptFiles, readCodexLbMigrationReceipt, rollbackCodexLbMigrationReceipt, writeCodexLbMigrationReceipt } from './migration-receipt.js';
|
|
21
|
+
import { CODEX_LB_DEEP_EVIDENCE_VALIDATION_SCHEMA, parseCodexLbDeepEvidenceTrustAnchorSet, validateCodexLbDesktopDeepEvidence } from './trusted-deep-evidence.js';
|
|
22
|
+
export const CODEX_LB_STATUS_SCHEMA_V2 = 'sks.codex-lb-status.v2';
|
|
23
|
+
export const CODEX_LB_ACTIVATION_SCHEMA_V2 = 'sks.codex-lb-desktop-activation.v2';
|
|
24
|
+
export function inferCodexLbDesktopModeFromConfig(text) {
|
|
25
|
+
const config = String(text || '');
|
|
26
|
+
const selected = topLevelTomlString(config, 'model_provider');
|
|
27
|
+
const openAiBaseUrl = topLevelTomlString(config, 'openai_base_url');
|
|
28
|
+
if (hasTopLevelLine(config, CODEX_LB_DESKTOP_BRIDGE_MARKER)
|
|
29
|
+
&& isLoopbackCodexBaseUrl(openAiBaseUrl)) {
|
|
30
|
+
return 'desktop-native-bridge';
|
|
31
|
+
}
|
|
32
|
+
if (hasTopLevelLine(config, CODEX_LB_DESKTOP_COMPAT_MARKER)
|
|
33
|
+
&& selected === 'codex-lb') {
|
|
34
|
+
return 'desktop-dual-auth-compat';
|
|
35
|
+
}
|
|
36
|
+
if (tomlTable(config, 'model_providers.codex-lb').trim())
|
|
37
|
+
return 'cli-provider';
|
|
38
|
+
return 'disabled';
|
|
39
|
+
}
|
|
40
|
+
export async function codexLbDesktopStatusV2(options = {}) {
|
|
41
|
+
const context = await loadDesktopContext(options);
|
|
42
|
+
const capabilityReport = await buildCodexLbDesktopCapabilities({
|
|
43
|
+
...options,
|
|
44
|
+
home: context.home,
|
|
45
|
+
configPath: context.configPath,
|
|
46
|
+
authPath: context.authPath,
|
|
47
|
+
networkProbes: false,
|
|
48
|
+
deepEvidence: null,
|
|
49
|
+
level: 'shallow'
|
|
50
|
+
});
|
|
51
|
+
const capabilityStatus = shapeCodexLbDesktopCapabilityStatus(capabilityReport);
|
|
52
|
+
const provider = providerStatus(context.config, context.mode);
|
|
53
|
+
const blockers = [
|
|
54
|
+
...context.modeBlockers,
|
|
55
|
+
...(modeRequiresChatGptOAuth(context.mode) && !context.oauthPresent
|
|
56
|
+
? ['chatgpt_oauth_required_for_desktop']
|
|
57
|
+
: []),
|
|
58
|
+
...(context.loadedEnv.configured ? [] : context.loadedEnv.missing.map((entry) => `codex_lb_missing:${entry}`)),
|
|
59
|
+
...(context.mode === 'desktop-native-bridge' && !context.bridge.ok
|
|
60
|
+
? context.bridge.blockers
|
|
61
|
+
: []),
|
|
62
|
+
...Object.values(capabilityStatus.blocked).flat()
|
|
63
|
+
];
|
|
64
|
+
const uniqueBlockers = uniqueStrings(blockers);
|
|
65
|
+
const overallBlocked = capabilityReport.overall === 'blocked'
|
|
66
|
+
|| capabilityReport.overall === 'unsupported';
|
|
67
|
+
const selectedProvider = topLevelTomlString(context.config, 'model_provider');
|
|
68
|
+
const legacyCodexLbSelected = selectedProvider === 'codex-lb';
|
|
69
|
+
return {
|
|
70
|
+
schema: CODEX_LB_STATUS_SCHEMA_V2,
|
|
71
|
+
ok: uniqueBlockers.length === 0 && !overallBlocked,
|
|
72
|
+
configured: context.loadedEnv.configured,
|
|
73
|
+
setup_needed: !context.loadedEnv.configured,
|
|
74
|
+
mode: context.mode,
|
|
75
|
+
desktop_mode: context.mode,
|
|
76
|
+
chatgpt_oauth_present: context.oauthPresent,
|
|
77
|
+
legacy_codex_lb_selected: legacyCodexLbSelected,
|
|
78
|
+
oauth: {
|
|
79
|
+
present: context.oauthPresent,
|
|
80
|
+
preserved: context.oauthPresent,
|
|
81
|
+
mode: context.auth.mode,
|
|
82
|
+
sha256: context.auth.sha256,
|
|
83
|
+
sha256_changed: null,
|
|
84
|
+
baseline_available: false
|
|
85
|
+
},
|
|
86
|
+
provider,
|
|
87
|
+
bridge: {
|
|
88
|
+
supported: context.bridge.supported,
|
|
89
|
+
installed: context.bridge.installed,
|
|
90
|
+
loaded: context.bridge.loaded,
|
|
91
|
+
running: context.bridge.running,
|
|
92
|
+
status: context.bridge.status,
|
|
93
|
+
listen_origin: context.bridge.state?.listen_origin || null,
|
|
94
|
+
remote_origin_redacted: redactRemoteOrigin(context.loadedEnv.base_url),
|
|
95
|
+
key_fingerprint: context.loadedEnv.api_key.fingerprint
|
|
96
|
+
? `sha256:${context.loadedEnv.api_key.fingerprint}`
|
|
97
|
+
: null,
|
|
98
|
+
gateway_auth_transport: context.gatewayAuthTransport,
|
|
99
|
+
blockers: context.bridge.blockers
|
|
100
|
+
},
|
|
101
|
+
capabilities: capabilityStatus,
|
|
102
|
+
deep_evidence_validation: capabilityReport.deep_evidence_validation,
|
|
103
|
+
overall: capabilityReport.overall,
|
|
104
|
+
full_capability_verified: capabilityReport.overall === 'verified',
|
|
105
|
+
blockers: uniqueBlockers,
|
|
106
|
+
guidance: statusGuidance(context.mode, context.loadedEnv.configured, uniqueBlockers)
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
export async function activateCodexLbDesktopMode(input) {
|
|
110
|
+
const context = await loadDesktopContext(input);
|
|
111
|
+
const gatewayAuthTransport = input.mode === 'desktop-dual-auth-compat'
|
|
112
|
+
? 'x-codex-lb-api-key'
|
|
113
|
+
: parseCodexLbGatewayAuthTransport(input.gatewayAuthTransport || context.gatewayAuthTransport);
|
|
114
|
+
if (context.modeBlockers.includes('legacy_codex_lb_desktop_config_requires_migration')) {
|
|
115
|
+
return {
|
|
116
|
+
schema: CODEX_LB_ACTIVATION_SCHEMA_V2,
|
|
117
|
+
ok: false,
|
|
118
|
+
status: 'legacy_migration_required',
|
|
119
|
+
mode: input.mode,
|
|
120
|
+
identity_plane: 'unavailable',
|
|
121
|
+
routing_plane: 'unchanged',
|
|
122
|
+
gateway_auth_transport: gatewayAuthTransport,
|
|
123
|
+
oauth_preserved: false,
|
|
124
|
+
bridge_started: false,
|
|
125
|
+
config_committed: false,
|
|
126
|
+
restart_requested: input.restartApp === true,
|
|
127
|
+
restart_performed: false,
|
|
128
|
+
routing: null,
|
|
129
|
+
bridge: null,
|
|
130
|
+
restart_app: null,
|
|
131
|
+
blockers: ['legacy_codex_lb_desktop_config_requires_migration'],
|
|
132
|
+
guidance: ['Run: sks codex-lb migrate-legacy-desktop --restart-app']
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
const receipt = await beginDesktopTransaction(context, input.receiptDir);
|
|
136
|
+
const previousBridgeRunning = context.bridge.running;
|
|
137
|
+
let bridge = null;
|
|
138
|
+
let routing = null;
|
|
139
|
+
let restart = null;
|
|
140
|
+
let centerCredentials = null;
|
|
141
|
+
try {
|
|
142
|
+
if (!context.loadedEnv.base_url || !context.loadedEnv.secret_api_key || !context.loadedEnv.configured) {
|
|
143
|
+
throw new Error(context.loadedEnv.credential_binding.blockers[0]
|
|
144
|
+
|| context.loadedEnv.missing[0]
|
|
145
|
+
|| 'codex_lb_credentials_unavailable');
|
|
146
|
+
}
|
|
147
|
+
if (!context.oauthPresent)
|
|
148
|
+
throw new Error('chatgpt_oauth_required_for_desktop');
|
|
149
|
+
if (input.mode === 'desktop-native-bridge') {
|
|
150
|
+
bridge = await (input.installBridgeImpl || installAndStartDesktopBridgeService)({
|
|
151
|
+
...input,
|
|
152
|
+
home: context.home,
|
|
153
|
+
settings: {
|
|
154
|
+
gateway_auth_transport: gatewayAuthTransport
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
if (!bridge.ok || !bridge.state) {
|
|
158
|
+
throw new Error(bridge.blockers[0] || 'desktop_bridge_start_failed');
|
|
159
|
+
}
|
|
160
|
+
routing = await configureCodexLbDesktopRouting({
|
|
161
|
+
mode: 'desktop-native-bridge',
|
|
162
|
+
home: context.home,
|
|
163
|
+
configPath: context.configPath,
|
|
164
|
+
authPath: context.authPath,
|
|
165
|
+
bridgeBaseUrl: bridge.state.codex_base_url,
|
|
166
|
+
remoteBaseUrl: context.loadedEnv.base_url,
|
|
167
|
+
gatewayAuthTransport
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
routing = await configureCodexLbDesktopRouting({
|
|
172
|
+
mode: 'desktop-dual-auth-compat',
|
|
173
|
+
home: context.home,
|
|
174
|
+
configPath: context.configPath,
|
|
175
|
+
authPath: context.authPath,
|
|
176
|
+
remoteBaseUrl: context.loadedEnv.base_url,
|
|
177
|
+
gatewayAuthTransport
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
if (!routing.ok)
|
|
181
|
+
throw new Error(routing.error || routing.blockers[0] || routing.status);
|
|
182
|
+
if (input.mode === 'desktop-dual-auth-compat' && previousBridgeRunning) {
|
|
183
|
+
bridge = await (input.stopBridgeImpl || stopDesktopBridgeService)({
|
|
184
|
+
...input,
|
|
185
|
+
home: context.home,
|
|
186
|
+
removePlist: true,
|
|
187
|
+
removeSettings: true
|
|
188
|
+
});
|
|
189
|
+
if (bridge.running)
|
|
190
|
+
throw new Error('desktop_bridge_stop_failed_during_compat_switch');
|
|
191
|
+
}
|
|
192
|
+
const centerCredentialsSynced = await syncDesktopCenterLaunchCredentials({
|
|
193
|
+
mode: input.mode,
|
|
194
|
+
home: context.home,
|
|
195
|
+
loadedEnv: context.loadedEnv,
|
|
196
|
+
...(input.platform ? { platform: input.platform } : {})
|
|
197
|
+
});
|
|
198
|
+
centerCredentials = centerCredentialsSynced;
|
|
199
|
+
if (!centerCredentialsSynced.ok) {
|
|
200
|
+
throw new Error(centerCredentialsSynced.blockers[0] || centerCredentialsSynced.status);
|
|
201
|
+
}
|
|
202
|
+
const report = await buildCodexLbDesktopCapabilities({
|
|
203
|
+
...input,
|
|
204
|
+
home: context.home,
|
|
205
|
+
configPath: context.configPath,
|
|
206
|
+
authPath: context.authPath,
|
|
207
|
+
level: 'transport',
|
|
208
|
+
networkProbes: true,
|
|
209
|
+
deepEvidence: null
|
|
210
|
+
});
|
|
211
|
+
if (input.mode === 'desktop-native-bridge'
|
|
212
|
+
&& report.bridge.state !== 'verified') {
|
|
213
|
+
throw new Error(report.bridge.blockers[0]
|
|
214
|
+
|| 'desktop_bridge_transport_unverified');
|
|
215
|
+
}
|
|
216
|
+
restart = await performOptionalRestart({
|
|
217
|
+
...input,
|
|
218
|
+
home: context.home,
|
|
219
|
+
authPath: context.authPath
|
|
220
|
+
}, context.auth);
|
|
221
|
+
if (restart.ok === false)
|
|
222
|
+
throw new Error(restart.blockers[0] || restart.status);
|
|
223
|
+
const finalizedReceipt = await finishDesktopTransaction(receipt, {
|
|
224
|
+
fromMode: context.mode,
|
|
225
|
+
toMode: input.mode,
|
|
226
|
+
oauthPreserved: true,
|
|
227
|
+
capabilitySummary: {
|
|
228
|
+
overall: report.overall,
|
|
229
|
+
gateway_auth_transport: gatewayAuthTransport,
|
|
230
|
+
identity_plane: 'chatgpt_oauth',
|
|
231
|
+
routing_plane: input.mode === 'desktop-native-bridge'
|
|
232
|
+
? 'desktop_native_bridge'
|
|
233
|
+
: 'desktop_compat_provider'
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
return {
|
|
237
|
+
schema: CODEX_LB_ACTIVATION_SCHEMA_V2,
|
|
238
|
+
ok: true,
|
|
239
|
+
status: routing.status,
|
|
240
|
+
mode: input.mode,
|
|
241
|
+
identity_plane: 'chatgpt_oauth',
|
|
242
|
+
routing_plane: routing.routing_plane,
|
|
243
|
+
gateway_auth_transport: gatewayAuthTransport,
|
|
244
|
+
oauth_preserved: true,
|
|
245
|
+
bridge_started: input.mode === 'desktop-native-bridge' ? bridge?.ok === true : false,
|
|
246
|
+
config_committed: true,
|
|
247
|
+
restart_requested: input.restartApp === true,
|
|
248
|
+
restart_performed: restart.status === 'restarted',
|
|
249
|
+
transport_capabilities_verified: report.bridge.state === 'verified',
|
|
250
|
+
capabilities: report,
|
|
251
|
+
rollback_receipt: finalizedReceipt.path,
|
|
252
|
+
rollback_receipt_id: finalizedReceipt.receipt.id,
|
|
253
|
+
routing,
|
|
254
|
+
bridge,
|
|
255
|
+
restart_app: restart,
|
|
256
|
+
center_credentials: centerCredentials,
|
|
257
|
+
blockers: []
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
catch (error) {
|
|
261
|
+
if (input.mode === 'desktop-native-bridge') {
|
|
262
|
+
await (input.stopBridgeImpl || stopDesktopBridgeService)({
|
|
263
|
+
...input,
|
|
264
|
+
home: context.home,
|
|
265
|
+
removePlist: true,
|
|
266
|
+
removeSettings: true
|
|
267
|
+
}).catch(() => undefined);
|
|
268
|
+
}
|
|
269
|
+
const rollback = await rollbackDesktopTransaction(receipt, {
|
|
270
|
+
...input,
|
|
271
|
+
home: context.home,
|
|
272
|
+
restartPreviousBridge: previousBridgeRunning,
|
|
273
|
+
restartAppAfterRollback: restart !== null && input.restartApp === true,
|
|
274
|
+
authBefore: context.auth
|
|
275
|
+
});
|
|
276
|
+
return {
|
|
277
|
+
schema: CODEX_LB_ACTIVATION_SCHEMA_V2,
|
|
278
|
+
ok: false,
|
|
279
|
+
status: 'activation_failed',
|
|
280
|
+
mode: input.mode,
|
|
281
|
+
identity_plane: context.oauthPresent ? 'chatgpt_oauth' : 'unavailable',
|
|
282
|
+
routing_plane: 'unchanged',
|
|
283
|
+
gateway_auth_transport: gatewayAuthTransport,
|
|
284
|
+
oauth_preserved: true,
|
|
285
|
+
bridge_started: bridge?.ok === true,
|
|
286
|
+
config_committed: false,
|
|
287
|
+
restart_requested: input.restartApp === true,
|
|
288
|
+
restart_performed: restart?.status === 'restarted',
|
|
289
|
+
routing,
|
|
290
|
+
bridge,
|
|
291
|
+
restart_app: restart,
|
|
292
|
+
rollback,
|
|
293
|
+
blockers: uniqueStrings([
|
|
294
|
+
safeControllerError(error),
|
|
295
|
+
...(rollback.ok ? [] : ['desktop_activation_rollback_failed']),
|
|
296
|
+
...(rollback.bridge_restart && !rollback.bridge_restart.ok
|
|
297
|
+
? rollback.bridge_restart.blockers
|
|
298
|
+
: []),
|
|
299
|
+
...(rollback.app_restart && rollback.app_restart.ok === false
|
|
300
|
+
? rollback.app_restart.blockers
|
|
301
|
+
: [])
|
|
302
|
+
])
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
export async function disableCodexLbDesktopRouting(input = {}) {
|
|
307
|
+
const context = await loadDesktopContext(input);
|
|
308
|
+
const receipt = await beginDesktopTransaction(context, input.receiptDir);
|
|
309
|
+
let routing = null;
|
|
310
|
+
let bridge = null;
|
|
311
|
+
let restart = null;
|
|
312
|
+
try {
|
|
313
|
+
routing = await configureCodexLbDesktopRouting({
|
|
314
|
+
mode: 'disabled',
|
|
315
|
+
home: context.home,
|
|
316
|
+
configPath: context.configPath,
|
|
317
|
+
authPath: context.authPath,
|
|
318
|
+
gatewayAuthTransport: context.gatewayAuthTransport
|
|
319
|
+
});
|
|
320
|
+
if (!routing.ok)
|
|
321
|
+
throw new Error(routing.error || routing.blockers[0] || routing.status);
|
|
322
|
+
bridge = await (input.stopBridgeImpl || stopDesktopBridgeService)({
|
|
323
|
+
...input,
|
|
324
|
+
home: context.home,
|
|
325
|
+
removePlist: true,
|
|
326
|
+
removeSettings: true
|
|
327
|
+
});
|
|
328
|
+
if (bridge.running || !bridge.ok) {
|
|
329
|
+
throw new Error(bridge.blockers[0] || 'desktop_bridge_cleanup_failed');
|
|
330
|
+
}
|
|
331
|
+
const centerCredentials = await syncDesktopCenterLaunchCredentials({
|
|
332
|
+
mode: 'disabled',
|
|
333
|
+
home: context.home,
|
|
334
|
+
loadedEnv: context.loadedEnv,
|
|
335
|
+
...(input.platform ? { platform: input.platform } : {})
|
|
336
|
+
});
|
|
337
|
+
if (!centerCredentials.ok) {
|
|
338
|
+
throw new Error(centerCredentials.blockers[0] || centerCredentials.status);
|
|
339
|
+
}
|
|
340
|
+
restart = await performOptionalRestart({
|
|
341
|
+
...input,
|
|
342
|
+
home: context.home,
|
|
343
|
+
authPath: context.authPath
|
|
344
|
+
}, context.auth);
|
|
345
|
+
if (restart.ok === false)
|
|
346
|
+
throw new Error(restart.blockers[0] || restart.status);
|
|
347
|
+
const afterAuth = await captureCodexAuthSnapshot({
|
|
348
|
+
home: context.home,
|
|
349
|
+
authPath: context.authPath
|
|
350
|
+
});
|
|
351
|
+
assertDesktopOAuthSemanticIdentity(context.auth, afterAuth);
|
|
352
|
+
const finalizedReceipt = await finishDesktopTransaction(receipt, {
|
|
353
|
+
fromMode: context.mode,
|
|
354
|
+
toMode: 'disabled',
|
|
355
|
+
oauthPreserved: true,
|
|
356
|
+
capabilitySummary: {
|
|
357
|
+
identity_plane: context.oauthPresent ? 'chatgpt_oauth' : 'unchanged',
|
|
358
|
+
routing_plane: 'disabled'
|
|
359
|
+
}
|
|
360
|
+
});
|
|
361
|
+
return {
|
|
362
|
+
schema: 'sks.codex-lb-desktop-disable.v2',
|
|
363
|
+
ok: true,
|
|
364
|
+
status: 'desktop_routing_disabled',
|
|
365
|
+
mode: 'disabled',
|
|
366
|
+
oauth_preserved: true,
|
|
367
|
+
config_committed: true,
|
|
368
|
+
bridge_stopped: true,
|
|
369
|
+
restart_requested: input.restartApp === true,
|
|
370
|
+
restart_performed: restart.status === 'restarted',
|
|
371
|
+
rollback_receipt: finalizedReceipt.path,
|
|
372
|
+
rollback_receipt_id: finalizedReceipt.receipt.id,
|
|
373
|
+
routing,
|
|
374
|
+
bridge,
|
|
375
|
+
restart_app: restart,
|
|
376
|
+
center_credentials: centerCredentials,
|
|
377
|
+
blockers: []
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
catch (error) {
|
|
381
|
+
const rollback = await rollbackDesktopTransaction(receipt, {
|
|
382
|
+
...input,
|
|
383
|
+
home: context.home,
|
|
384
|
+
restartPreviousBridge: context.bridge.running,
|
|
385
|
+
restartAppAfterRollback: restart !== null && input.restartApp === true,
|
|
386
|
+
authBefore: context.auth
|
|
387
|
+
});
|
|
388
|
+
return {
|
|
389
|
+
schema: 'sks.codex-lb-desktop-disable.v2',
|
|
390
|
+
ok: false,
|
|
391
|
+
status: 'desktop_routing_disable_failed',
|
|
392
|
+
mode: context.mode,
|
|
393
|
+
oauth_preserved: true,
|
|
394
|
+
config_committed: false,
|
|
395
|
+
bridge_stopped: false,
|
|
396
|
+
restart_requested: input.restartApp === true,
|
|
397
|
+
restart_performed: restart?.status === 'restarted',
|
|
398
|
+
routing,
|
|
399
|
+
bridge,
|
|
400
|
+
restart_app: restart,
|
|
401
|
+
rollback,
|
|
402
|
+
blockers: uniqueStrings([
|
|
403
|
+
safeControllerError(error),
|
|
404
|
+
...(rollback.ok ? [] : ['desktop_disable_rollback_failed']),
|
|
405
|
+
...(rollback.bridge_restart && !rollback.bridge_restart.ok
|
|
406
|
+
? rollback.bridge_restart.blockers
|
|
407
|
+
: []),
|
|
408
|
+
...(rollback.app_restart && rollback.app_restart.ok === false
|
|
409
|
+
? rollback.app_restart.blockers
|
|
410
|
+
: [])
|
|
411
|
+
])
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
export async function configureCodexLbCliMode(input = {}) {
|
|
416
|
+
const context = await loadDesktopContext(input);
|
|
417
|
+
if (!context.loadedEnv.base_url) {
|
|
418
|
+
return {
|
|
419
|
+
schema: 'sks.codex-lb-cli-mode.v2',
|
|
420
|
+
ok: false,
|
|
421
|
+
status: 'missing_remote_base_url',
|
|
422
|
+
mode: 'cli-provider',
|
|
423
|
+
oauth_preserved: true,
|
|
424
|
+
blockers: ['codex_lb_missing:CODEX_LB_BASE_URL']
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
const result = await configureCodexLbCliProvider({
|
|
428
|
+
home: context.home,
|
|
429
|
+
configPath: context.configPath,
|
|
430
|
+
authPath: context.authPath,
|
|
431
|
+
remoteBaseUrl: context.loadedEnv.base_url,
|
|
432
|
+
selectGlobally: false
|
|
433
|
+
});
|
|
434
|
+
return {
|
|
435
|
+
...result,
|
|
436
|
+
schema: 'sks.codex-lb-cli-mode.v2',
|
|
437
|
+
command: `codex --config model_provider='"codex-lb"'`,
|
|
438
|
+
global_desktop_selection_changed: false
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
export async function buildCodexLbDesktopCapabilities(input = {}) {
|
|
442
|
+
const level = input.level || 'shallow';
|
|
443
|
+
const context = await loadDesktopContext(input);
|
|
444
|
+
const target = capabilityTarget(context);
|
|
445
|
+
const deepEvidenceValidation = input.deepEvidence == null || target
|
|
446
|
+
? validateCodexLbDesktopDeepEvidence(input.deepEvidence ?? null, {
|
|
447
|
+
expectedMode: context.mode,
|
|
448
|
+
expectedEndpoint: target?.baseUrl || 'http://127.0.0.1/',
|
|
449
|
+
trustAnchors: input.deepEvidenceTrustAnchors || []
|
|
450
|
+
})
|
|
451
|
+
: blockedDeepEvidenceValidation('codex_lb_deep_evidence_target_unavailable');
|
|
452
|
+
const deep = level === 'deep' && deepEvidenceValidation.evidence
|
|
453
|
+
? deepEvidenceValidation.evidence
|
|
454
|
+
: {};
|
|
455
|
+
const deepEvidenceBlockers = level === 'deep' && deepEvidenceValidation.state === 'blocked'
|
|
456
|
+
? deepEvidenceValidation.blockers
|
|
457
|
+
: [];
|
|
458
|
+
const fixture = deep.fixture === true;
|
|
459
|
+
const networkProbes = input.networkProbes !== false;
|
|
460
|
+
const transportRequested = level === 'transport' || level === 'deep';
|
|
461
|
+
let manifest = null;
|
|
462
|
+
let catalogPayload = null;
|
|
463
|
+
let manifestResult = null;
|
|
464
|
+
let catalogResult = null;
|
|
465
|
+
let webSocketResult = null;
|
|
466
|
+
if (networkProbes && target) {
|
|
467
|
+
manifestResult = await fetchGatewayJson(`${target.baseUrl}/capabilities`, target.headers, input.fetchImpl, input.capabilityTimeoutMs);
|
|
468
|
+
if (manifestResult.ok && isRecord(manifestResult.payload))
|
|
469
|
+
manifest = manifestResult.payload;
|
|
470
|
+
if (transportRequested) {
|
|
471
|
+
catalogResult = await fetchGatewayJson(`${target.baseUrl}/models`, target.headers, input.fetchImpl, input.capabilityTimeoutMs);
|
|
472
|
+
if (catalogResult.ok)
|
|
473
|
+
catalogPayload = catalogResult.payload;
|
|
474
|
+
}
|
|
475
|
+
if (transportRequested && context.mode === 'desktop-native-bridge') {
|
|
476
|
+
webSocketResult = await (input.webSocketProbeImpl
|
|
477
|
+
|| probeLoopbackWebSocketTransport)(target.baseUrl, input.capabilityTimeoutMs || 8_000);
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
const transportObserved = Boolean(manifestResult?.ok || catalogResult?.ok);
|
|
481
|
+
const normalizedCatalog = catalogPayload ? normalizeCodexLbToolCatalog(catalogPayload) : null;
|
|
482
|
+
const model = normalizedCatalog?.catalog.models.find((row) => row.supported_in_api === true)?.slug || null;
|
|
483
|
+
let textResponses = {
|
|
484
|
+
skipped: true,
|
|
485
|
+
source: 'config',
|
|
486
|
+
evidence: { reason: transportRequested ? 'text_responses_model_unavailable' : 'transport_probe_not_requested' }
|
|
487
|
+
};
|
|
488
|
+
if (transportRequested && target && model) {
|
|
489
|
+
if (context.mode !== 'desktop-native-bridge' && target.transport === 'x-codex-lb-api-key') {
|
|
490
|
+
textResponses = {
|
|
491
|
+
configured: true,
|
|
492
|
+
blockers: ['text_responses_custom_header_adapter_required'],
|
|
493
|
+
evidence: { gateway_auth_transport: target.transport }
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
else {
|
|
497
|
+
const chain = await checkCodexLbResponseChain({
|
|
498
|
+
base_url: target.baseUrl,
|
|
499
|
+
provider_base_url_matches_credential: true
|
|
500
|
+
}, {
|
|
501
|
+
force: true,
|
|
502
|
+
cache: false,
|
|
503
|
+
recordCircuit: false,
|
|
504
|
+
baseUrl: target.baseUrl,
|
|
505
|
+
apiKey: context.loadedEnv.secret_api_key,
|
|
506
|
+
model,
|
|
507
|
+
fetch: input.fetchImpl || globalThis.fetch,
|
|
508
|
+
timeoutMs: input.capabilityTimeoutMs || 8_000
|
|
509
|
+
});
|
|
510
|
+
textResponses = capabilityEvidenceToSignal(codexLbResponseChainCapabilityEvidence(chain));
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
const providerContract = providerStatus(context.config, context.mode);
|
|
514
|
+
const providerBlockers = [
|
|
515
|
+
...(providerContract.contract_ok ? [] : ['codex_lb_provider_contract_drift']),
|
|
516
|
+
...(modeRequiresChatGptOAuth(context.mode) && !context.oauthPresent
|
|
517
|
+
? ['chatgpt_oauth_identity_not_preserved']
|
|
518
|
+
: []),
|
|
519
|
+
...deepEvidenceBlockers
|
|
520
|
+
];
|
|
521
|
+
const localCatalogBound = hasTopLevelLine(context.config, CODEX_LB_MODEL_CATALOG_MARKER)
|
|
522
|
+
&& Boolean(topLevelTomlString(context.config, 'model_catalog_json'));
|
|
523
|
+
const bridgeTransportAttempted = transportRequested
|
|
524
|
+
&& networkProbes
|
|
525
|
+
&& context.mode === 'desktop-native-bridge';
|
|
526
|
+
const bridgeHttpRoundTrip = context.mode === 'desktop-native-bridge' && transportObserved;
|
|
527
|
+
const bridgeWebSocketRoundTrip = webSocketResult?.ok === true;
|
|
528
|
+
const gatewayObserved = transportObserved;
|
|
529
|
+
return runCodexLbDesktopCapabilityReport({
|
|
530
|
+
mode: context.mode,
|
|
531
|
+
level,
|
|
532
|
+
configured: context.loadedEnv.configured && context.mode !== 'disabled',
|
|
533
|
+
oauthPreserved: context.oauthPresent,
|
|
534
|
+
manifest,
|
|
535
|
+
gatewayAuth: {
|
|
536
|
+
transport: context.gatewayAuthTransport,
|
|
537
|
+
configured: context.loadedEnv.configured,
|
|
538
|
+
observed: gatewayObserved,
|
|
539
|
+
fixture,
|
|
540
|
+
legacyCompatibilityExplicit: context.gatewayAuthTransport === 'authorization-bearer-compat',
|
|
541
|
+
blockers: [
|
|
542
|
+
...(manifestResult && !manifestResult.ok && manifestResult.httpStatus !== 404
|
|
543
|
+
? [manifestResult.blocker || 'capability_manifest_unavailable']
|
|
544
|
+
: [])
|
|
545
|
+
]
|
|
546
|
+
},
|
|
547
|
+
providerIdentity: {
|
|
548
|
+
configured: providerContract.contract_ok,
|
|
549
|
+
attempted: level === 'deep',
|
|
550
|
+
verified: level === 'deep' && deep.provider_identity_verified === true,
|
|
551
|
+
fixture,
|
|
552
|
+
source: level === 'deep' && deep.provider_identity_verified === true ? 'deep_probe' : 'config',
|
|
553
|
+
requiresOauth: modeRequiresChatGptOAuth(context.mode),
|
|
554
|
+
blockers: providerBlockers,
|
|
555
|
+
evidence: {
|
|
556
|
+
provider_id: providerContract.id,
|
|
557
|
+
built_in: providerContract.built_in,
|
|
558
|
+
contract_ok: providerContract.contract_ok,
|
|
559
|
+
auth_mode: context.auth.mode
|
|
560
|
+
}
|
|
561
|
+
},
|
|
562
|
+
bridge: {
|
|
563
|
+
configured: context.mode === 'desktop-native-bridge',
|
|
564
|
+
processRunning: context.bridge.running,
|
|
565
|
+
transportAttempted: bridgeTransportAttempted,
|
|
566
|
+
httpRoundTrip: bridgeHttpRoundTrip,
|
|
567
|
+
websocketRoundTrip: bridgeWebSocketRoundTrip,
|
|
568
|
+
fixture,
|
|
569
|
+
blockers: context.mode === 'desktop-native-bridge'
|
|
570
|
+
? [
|
|
571
|
+
...context.bridge.blockers,
|
|
572
|
+
...(webSocketResult && !webSocketResult.ok && webSocketResult.blocker
|
|
573
|
+
? [webSocketResult.blocker]
|
|
574
|
+
: [])
|
|
575
|
+
]
|
|
576
|
+
: []
|
|
577
|
+
},
|
|
578
|
+
catalog: {
|
|
579
|
+
catalog: catalogPayload,
|
|
580
|
+
localCatalogBound,
|
|
581
|
+
configuredServiceTier: deep.configured_service_tier || topLevelTomlString(context.config, 'service_tier') || null,
|
|
582
|
+
pickerControlVisible: deep.picker_control_visible ?? null,
|
|
583
|
+
pickerSelectedModel: deep.picker_selected_model || null,
|
|
584
|
+
requestServiceTier: deep.request_service_tier || null,
|
|
585
|
+
responseActualServiceTier: deep.response_actual_service_tier || null,
|
|
586
|
+
fixture,
|
|
587
|
+
blockers: deepEvidenceBlockers
|
|
588
|
+
},
|
|
589
|
+
textResponses,
|
|
590
|
+
imageGeneration: {
|
|
591
|
+
route: deep.image_route || null,
|
|
592
|
+
requestToolsPresent: deep.image_request_tools_present,
|
|
593
|
+
events: deep.image_events || [],
|
|
594
|
+
artifactMaterialized: deep.image_artifact_materialized,
|
|
595
|
+
attempted: level === 'deep' && Boolean(deep.image_events?.length),
|
|
596
|
+
fixture,
|
|
597
|
+
blockers: deepEvidenceBlockers
|
|
598
|
+
},
|
|
599
|
+
computerUse: {
|
|
600
|
+
events: deep.computer_events || [],
|
|
601
|
+
localExecutorCompleted: deep.computer_executor_completed,
|
|
602
|
+
outputSubmitted: deep.computer_output_submitted,
|
|
603
|
+
followUpCompleted: deep.computer_follow_up_completed,
|
|
604
|
+
sessionAffinityPreserved: deep.computer_session_affinity_preserved,
|
|
605
|
+
attempted: level === 'deep' && Boolean(deep.computer_events?.length),
|
|
606
|
+
fixture,
|
|
607
|
+
blockers: deepEvidenceBlockers
|
|
608
|
+
},
|
|
609
|
+
browserUse: {
|
|
610
|
+
configured: true,
|
|
611
|
+
attempted: level === 'deep',
|
|
612
|
+
verified: level === 'deep' && deep.browser_use_verified === true,
|
|
613
|
+
fixture,
|
|
614
|
+
source: level === 'deep' && deep.browser_use_verified === true ? 'deep_probe' : 'config',
|
|
615
|
+
blockers: deepEvidenceBlockers,
|
|
616
|
+
evidence: {
|
|
617
|
+
independent_from_auth_mode: true,
|
|
618
|
+
independent_from_computer_use: true,
|
|
619
|
+
live_regression_verified: deep.browser_use_verified === true
|
|
620
|
+
}
|
|
621
|
+
},
|
|
622
|
+
voiceMode: {
|
|
623
|
+
createRouteVerified: deep.voice_create_verified,
|
|
624
|
+
locationReceived: deep.voice_location_received,
|
|
625
|
+
locationRewritten: deep.voice_location_rewritten,
|
|
626
|
+
websocketUpgraded: deep.voice_websocket_upgraded,
|
|
627
|
+
serverEventSeen: deep.voice_server_event_seen,
|
|
628
|
+
cleanClose: deep.voice_clean_close,
|
|
629
|
+
ownerBindingVerified: deep.voice_owner_binding_verified,
|
|
630
|
+
attempted: level === 'deep' && (deep.voice_create_verified !== undefined
|
|
631
|
+
|| deep.voice_websocket_upgraded !== undefined),
|
|
632
|
+
fixture,
|
|
633
|
+
blockers: deepEvidenceBlockers
|
|
634
|
+
},
|
|
635
|
+
plugins: {
|
|
636
|
+
configured: true,
|
|
637
|
+
attempted: level === 'deep',
|
|
638
|
+
verified: level === 'deep' && deep.plugins_verified === true,
|
|
639
|
+
fixture,
|
|
640
|
+
source: level === 'deep' && deep.plugins_verified === true ? 'deep_probe' : 'config',
|
|
641
|
+
blockers: deepEvidenceBlockers,
|
|
642
|
+
evidence: {
|
|
643
|
+
independent_from_auth_mode: true,
|
|
644
|
+
discovery_verified: deep.plugins_verified === true
|
|
645
|
+
}
|
|
646
|
+
},
|
|
647
|
+
auxiliarySurfaces: {
|
|
648
|
+
inputEvents: deep.auxiliary_events || [],
|
|
649
|
+
outputEvents: deep.auxiliary_output_events || deep.auxiliary_events || [],
|
|
650
|
+
requestBodyHashPreserved: deep.auxiliary_request_body_hash_preserved,
|
|
651
|
+
sessionAffinityPreserved: deep.auxiliary_owner_affinity_verified,
|
|
652
|
+
attempted: level === 'deep' && Boolean(deep.auxiliary_routes_observed?.length || deep.auxiliary_events?.length),
|
|
653
|
+
fixture,
|
|
654
|
+
blockers: deepEvidenceBlockers
|
|
655
|
+
},
|
|
656
|
+
deepEvidenceValidation
|
|
657
|
+
});
|
|
658
|
+
}
|
|
659
|
+
export async function migrateLegacyCodexLbDesktopMode(input = {}) {
|
|
660
|
+
const context = await loadDesktopContext(input);
|
|
661
|
+
if (!context.loadedEnv.base_url) {
|
|
662
|
+
return {
|
|
663
|
+
schema: 'sks.codex-lb-legacy-migration-command.v2',
|
|
664
|
+
ok: false,
|
|
665
|
+
status: 'missing_remote_base_url',
|
|
666
|
+
blockers: ['codex_lb_missing:CODEX_LB_BASE_URL']
|
|
667
|
+
};
|
|
668
|
+
}
|
|
669
|
+
const targetMode = input.mode === 'desktop-dual-auth-compat'
|
|
670
|
+
? 'desktop-dual-auth-compat'
|
|
671
|
+
: 'desktop-native-bridge';
|
|
672
|
+
const settings = await resolveDesktopBridgeActivationSettings({
|
|
673
|
+
...input,
|
|
674
|
+
home: context.home,
|
|
675
|
+
settings: {
|
|
676
|
+
...(input.settings || {}),
|
|
677
|
+
gateway_auth_transport: input.gatewayAuthTransport || context.gatewayAuthTransport
|
|
678
|
+
}
|
|
679
|
+
});
|
|
680
|
+
const bridgeBaseUrl = `http://${settings.listen_host === '::1' ? '[::1]' : settings.listen_host}:${settings.listen_port}/backend-api/codex`;
|
|
681
|
+
const servicePaths = desktopBridgeServicePaths(context.home);
|
|
682
|
+
const result = await migrateLegacyCodexLbDesktop({
|
|
683
|
+
home: context.home,
|
|
684
|
+
configPath: context.configPath,
|
|
685
|
+
authPath: context.authPath,
|
|
686
|
+
...(input.receiptDir ? { receiptDir: input.receiptDir } : {}),
|
|
687
|
+
bridgeBaseUrl,
|
|
688
|
+
bridgeStatePath: servicePaths.state_path,
|
|
689
|
+
bridgeSettingsPath: servicePaths.settings_path,
|
|
690
|
+
bridgeLaunchAgentPath: servicePaths.launch_agent_path,
|
|
691
|
+
remoteBaseUrl: context.loadedEnv.base_url,
|
|
692
|
+
targetMode,
|
|
693
|
+
...(context.loadedEnv.secret_api_key
|
|
694
|
+
? { gatewayApiKey: context.loadedEnv.secret_api_key }
|
|
695
|
+
: {}),
|
|
696
|
+
gatewayAuthTransport: targetMode === 'desktop-dual-auth-compat'
|
|
697
|
+
? 'x-codex-lb-api-key'
|
|
698
|
+
: settings.gateway_auth_transport,
|
|
699
|
+
quitApp: async () => {
|
|
700
|
+
const quit = await (input.quitAppImpl || quitCodexApp)({
|
|
701
|
+
enabled: true,
|
|
702
|
+
...(input.platform ? { platform: input.platform } : {}),
|
|
703
|
+
...(input.env ? { env: input.env } : {})
|
|
704
|
+
});
|
|
705
|
+
return { ...quit };
|
|
706
|
+
},
|
|
707
|
+
startBridge: async () => {
|
|
708
|
+
const status = await (input.installBridgeImpl || installAndStartDesktopBridgeService)({
|
|
709
|
+
...input,
|
|
710
|
+
home: context.home,
|
|
711
|
+
settings
|
|
712
|
+
});
|
|
713
|
+
return { ...status };
|
|
714
|
+
},
|
|
715
|
+
stopBridge: async () => {
|
|
716
|
+
const status = await (input.stopBridgeImpl || stopDesktopBridgeService)({
|
|
717
|
+
...input,
|
|
718
|
+
home: context.home,
|
|
719
|
+
removePlist: true,
|
|
720
|
+
removeSettings: true
|
|
721
|
+
});
|
|
722
|
+
return { ...status };
|
|
723
|
+
},
|
|
724
|
+
...(input.restartApp === true
|
|
725
|
+
? {
|
|
726
|
+
restartApp: async () => {
|
|
727
|
+
const restart = await (input.restartAppImpl || restartCodexApp)({
|
|
728
|
+
enabled: true,
|
|
729
|
+
...(input.platform ? { platform: input.platform } : {}),
|
|
730
|
+
...(input.env ? { env: input.env } : {})
|
|
731
|
+
});
|
|
732
|
+
return {
|
|
733
|
+
ok: restart.ok,
|
|
734
|
+
status: restart.status,
|
|
735
|
+
blockers: restart.blockers,
|
|
736
|
+
...(restart.reason ? { reason: restart.reason } : {})
|
|
737
|
+
};
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
: {}),
|
|
741
|
+
verifyCapabilities: async () => {
|
|
742
|
+
const report = await buildCodexLbDesktopCapabilities({
|
|
743
|
+
...input,
|
|
744
|
+
home: context.home,
|
|
745
|
+
configPath: context.configPath,
|
|
746
|
+
authPath: context.authPath,
|
|
747
|
+
level: targetMode === 'desktop-dual-auth-compat' ? 'shallow' : 'transport',
|
|
748
|
+
networkProbes: targetMode === 'desktop-native-bridge',
|
|
749
|
+
deepEvidence: null
|
|
750
|
+
});
|
|
751
|
+
if (targetMode === 'desktop-dual-auth-compat') {
|
|
752
|
+
const provider = providerStatus(await readText(context.configPath, ''), 'desktop-dual-auth-compat');
|
|
753
|
+
const ok = provider.contract_ok && provider.selected;
|
|
754
|
+
return {
|
|
755
|
+
ok,
|
|
756
|
+
summary: {
|
|
757
|
+
desktop_mode: 'desktop-dual-auth-compat',
|
|
758
|
+
provider_contract: provider.contract_ok ? 'ok' : 'failed',
|
|
759
|
+
gateway_auth_transport: 'x-codex-lb-api-key'
|
|
760
|
+
},
|
|
761
|
+
blockers: ok ? [] : ['desktop_compat_provider_contract_failed']
|
|
762
|
+
};
|
|
763
|
+
}
|
|
764
|
+
const ok = report.bridge.state === 'verified';
|
|
765
|
+
const adoption = desktopAdoptionEvidence(report.deep_evidence_validation.evidence);
|
|
766
|
+
return {
|
|
767
|
+
ok,
|
|
768
|
+
summary: {
|
|
769
|
+
bridge_http: report.bridge.evidence.http_round_trip === true ? 'verified' : 'unverified',
|
|
770
|
+
bridge_websocket: report.bridge.evidence.websocket_round_trip === true ? 'verified' : 'unverified',
|
|
771
|
+
desktop_adoption: adoption.ok ? 'verified' : 'unverified',
|
|
772
|
+
gateway_auth_transport: settings.gateway_auth_transport
|
|
773
|
+
},
|
|
774
|
+
blockers: uniqueStrings([
|
|
775
|
+
...(report.bridge.state === 'verified' ? [] : report.bridge.blockers)
|
|
776
|
+
])
|
|
777
|
+
};
|
|
778
|
+
}
|
|
779
|
+
});
|
|
780
|
+
return {
|
|
781
|
+
...result,
|
|
782
|
+
schema: 'sks.codex-lb-legacy-migration-command.v2'
|
|
783
|
+
};
|
|
784
|
+
}
|
|
785
|
+
export async function rollbackCodexLbDesktopMode(receiptId, input = {}) {
|
|
786
|
+
const safeId = String(receiptId || '').trim();
|
|
787
|
+
if (!/^[A-Za-z0-9_-]+$/.test(safeId)) {
|
|
788
|
+
return {
|
|
789
|
+
schema: 'sks.codex-lb-desktop-rollback-command.v2',
|
|
790
|
+
ok: false,
|
|
791
|
+
status: 'invalid_receipt_id',
|
|
792
|
+
receipt_id: null,
|
|
793
|
+
blockers: ['invalid_receipt_id']
|
|
794
|
+
};
|
|
795
|
+
}
|
|
796
|
+
const home = input.home || input.env?.HOME || process.env.HOME || os.homedir();
|
|
797
|
+
const receiptDir = input.receiptDir || codexLbMigrationReceiptDir(home);
|
|
798
|
+
const receiptPath = path.join(receiptDir, `${safeId}.json`);
|
|
799
|
+
const preflight = await preflightDesktopRollbackReceipt(receiptPath);
|
|
800
|
+
if (!preflight.ok) {
|
|
801
|
+
return {
|
|
802
|
+
...preflight,
|
|
803
|
+
schema: 'sks.codex-lb-desktop-rollback-command.v2',
|
|
804
|
+
bridge: null,
|
|
805
|
+
blockers: uniqueStrings([
|
|
806
|
+
...preflight.conflicts.map((entry) => entry.reason),
|
|
807
|
+
...(preflight.status === 'invalid_receipt'
|
|
808
|
+
? [preflight.error || 'invalid_receipt']
|
|
809
|
+
: [])
|
|
810
|
+
])
|
|
811
|
+
};
|
|
812
|
+
}
|
|
813
|
+
await (input.stopBridgeImpl || stopDesktopBridgeService)({
|
|
814
|
+
...input,
|
|
815
|
+
home,
|
|
816
|
+
removePlist: false,
|
|
817
|
+
removeSettings: false
|
|
818
|
+
}).catch(() => undefined);
|
|
819
|
+
const rollback = await rollbackCodexLbMigrationReceipt({ receiptPath });
|
|
820
|
+
let bridge = null;
|
|
821
|
+
if (rollback.ok) {
|
|
822
|
+
const configPath = input.configPath || codexLbConfigPath(home);
|
|
823
|
+
const restoredConfig = await readText(configPath, '');
|
|
824
|
+
if (inferCodexLbDesktopModeFromConfig(restoredConfig) === 'desktop-native-bridge') {
|
|
825
|
+
bridge = await (input.bootstrapBridgeImpl || bootstrapExistingDesktopBridgeService)({
|
|
826
|
+
...input,
|
|
827
|
+
home
|
|
828
|
+
});
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
return {
|
|
832
|
+
...rollback,
|
|
833
|
+
schema: 'sks.codex-lb-desktop-rollback-command.v2',
|
|
834
|
+
bridge,
|
|
835
|
+
blockers: rollback.ok ? (bridge && !bridge.ok ? bridge.blockers : []) : rollback.conflicts.map((entry) => entry.reason)
|
|
836
|
+
};
|
|
837
|
+
}
|
|
838
|
+
export async function readCodexLbDesktopDeepEvidence(file) {
|
|
839
|
+
const resolved = path.resolve(file);
|
|
840
|
+
const value = await readJson(resolved);
|
|
841
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
842
|
+
throw new Error('codex_lb_deep_evidence_invalid');
|
|
843
|
+
}
|
|
844
|
+
return value;
|
|
845
|
+
}
|
|
846
|
+
export async function readCodexLbDesktopDeepEvidenceTrustAnchors(file) {
|
|
847
|
+
const resolved = path.resolve(file);
|
|
848
|
+
const value = await readJson(resolved);
|
|
849
|
+
const parsed = parseCodexLbDeepEvidenceTrustAnchorSet(value);
|
|
850
|
+
if (!parsed.ok) {
|
|
851
|
+
throw new Error(parsed.blockers[0] || 'codex_lb_deep_evidence_trust_anchor_set_invalid');
|
|
852
|
+
}
|
|
853
|
+
return parsed.anchors;
|
|
854
|
+
}
|
|
855
|
+
async function loadDesktopContext(options) {
|
|
856
|
+
const home = options.home || options.env?.HOME || process.env.HOME || os.homedir();
|
|
857
|
+
const configPath = options.configPath || codexLbConfigPath(home);
|
|
858
|
+
const authPath = options.authPath || codexAuthPath(home);
|
|
859
|
+
const config = await readText(configPath, '');
|
|
860
|
+
const mode = inferCodexLbDesktopModeFromConfig(config);
|
|
861
|
+
const auth = await captureCodexAuthSnapshot({ home, authPath });
|
|
862
|
+
const loadedEnv = await loadCodexLbEnv({
|
|
863
|
+
home,
|
|
864
|
+
envPath: options.envPath || codexLbEnvPath(home),
|
|
865
|
+
metadataPath: options.metadataPath || codexLbMetadataPath(home),
|
|
866
|
+
...(options.env ? { processEnv: options.env } : {})
|
|
867
|
+
});
|
|
868
|
+
const bridge = await (options.bridgeStatusImpl || desktopBridgeServiceStatus)({
|
|
869
|
+
...options,
|
|
870
|
+
home
|
|
871
|
+
});
|
|
872
|
+
const legacy = await detectLegacyCodexLbDesktopState({
|
|
873
|
+
home,
|
|
874
|
+
configPath,
|
|
875
|
+
authPath,
|
|
876
|
+
...(options.receiptDir ? { receiptDir: options.receiptDir } : {}),
|
|
877
|
+
...(loadedEnv.base_url ? { remoteBaseUrl: loadedEnv.base_url } : {}),
|
|
878
|
+
...(loadedEnv.secret_api_key ? { expectedGatewayApiKey: loadedEnv.secret_api_key } : {})
|
|
879
|
+
});
|
|
880
|
+
const metadata = await readJson(options.metadataPath || codexLbMetadataPath(home), {});
|
|
881
|
+
const rawTransport = options.gatewayAuthTransport
|
|
882
|
+
|| bridge.state?.gateway_auth_transport
|
|
883
|
+
|| bridge.settings?.gateway_auth_transport
|
|
884
|
+
|| metadata.gateway_auth_transport
|
|
885
|
+
|| DEFAULT_CODEX_LB_GATEWAY_AUTH_TRANSPORT;
|
|
886
|
+
let gatewayAuthTransport;
|
|
887
|
+
const modeBlockers = [];
|
|
888
|
+
try {
|
|
889
|
+
gatewayAuthTransport = parseCodexLbGatewayAuthTransport(rawTransport);
|
|
890
|
+
}
|
|
891
|
+
catch {
|
|
892
|
+
gatewayAuthTransport = DEFAULT_CODEX_LB_GATEWAY_AUTH_TRANSPORT;
|
|
893
|
+
modeBlockers.push('codex_lb_gateway_auth_transport_invalid');
|
|
894
|
+
}
|
|
895
|
+
if (topLevelTomlString(config, 'model_provider') === 'codex-lb'
|
|
896
|
+
&& !hasTopLevelLine(config, CODEX_LB_DESKTOP_COMPAT_MARKER)) {
|
|
897
|
+
modeBlockers.push('legacy_codex_lb_desktop_config_requires_migration');
|
|
898
|
+
}
|
|
899
|
+
if (legacy.legacy_destructive_mode) {
|
|
900
|
+
modeBlockers.push('legacy_codex_lb_desktop_config_requires_migration');
|
|
901
|
+
}
|
|
902
|
+
return {
|
|
903
|
+
home,
|
|
904
|
+
configPath,
|
|
905
|
+
authPath,
|
|
906
|
+
config,
|
|
907
|
+
mode,
|
|
908
|
+
modeBlockers,
|
|
909
|
+
auth,
|
|
910
|
+
oauthPresent: auth.mode === 'chatgpt_oauth' || auth.mode === 'mixed',
|
|
911
|
+
loadedEnv,
|
|
912
|
+
bridge,
|
|
913
|
+
gatewayAuthTransport
|
|
914
|
+
};
|
|
915
|
+
}
|
|
916
|
+
function providerStatus(config, mode) {
|
|
917
|
+
const selected = topLevelTomlString(config, 'model_provider');
|
|
918
|
+
const provider = tomlTable(config, 'model_providers.codex-lb');
|
|
919
|
+
if (mode === 'desktop-dual-auth-compat') {
|
|
920
|
+
const contractOk = Boolean(provider)
|
|
921
|
+
&& hasTomlString(provider, 'name', 'OpenAI')
|
|
922
|
+
&& hasTomlString(provider, 'wire_api', 'responses')
|
|
923
|
+
&& hasTomlBoolean(provider, 'requires_openai_auth', true)
|
|
924
|
+
&& hasTomlBoolean(provider, 'supports_websockets', true)
|
|
925
|
+
&& /"X-Codex-LB-API-Key"\s*=\s*"CODEX_LB_API_KEY"/.test(provider)
|
|
926
|
+
&& !/(?:^|\n)\s*env_key\s*=/.test(provider);
|
|
927
|
+
return {
|
|
928
|
+
id: 'codex-lb',
|
|
929
|
+
built_in: false,
|
|
930
|
+
contract: 'codex-lb-compat',
|
|
931
|
+
contract_ok: contractOk,
|
|
932
|
+
selected: selected === 'codex-lb'
|
|
933
|
+
};
|
|
934
|
+
}
|
|
935
|
+
const cliContractOk = Boolean(provider)
|
|
936
|
+
&& hasTomlString(provider, 'name', 'codex-lb')
|
|
937
|
+
&& hasTomlString(provider, 'wire_api', 'responses')
|
|
938
|
+
&& hasTomlString(provider, 'env_key', 'CODEX_LB_API_KEY')
|
|
939
|
+
&& hasTomlBoolean(provider, 'requires_openai_auth', false)
|
|
940
|
+
&& hasTomlBoolean(provider, 'supports_websockets', true);
|
|
941
|
+
if (mode === 'cli-provider') {
|
|
942
|
+
return {
|
|
943
|
+
id: 'openai',
|
|
944
|
+
built_in: true,
|
|
945
|
+
contract: provider ? 'codex-lb-cli' : 'missing',
|
|
946
|
+
contract_ok: cliContractOk,
|
|
947
|
+
selected: selected !== 'codex-lb'
|
|
948
|
+
};
|
|
949
|
+
}
|
|
950
|
+
return {
|
|
951
|
+
id: 'openai',
|
|
952
|
+
built_in: true,
|
|
953
|
+
contract: 'builtin-openai',
|
|
954
|
+
contract_ok: mode === 'disabled' ? true : cliContractOk,
|
|
955
|
+
selected: selected !== 'codex-lb'
|
|
956
|
+
};
|
|
957
|
+
}
|
|
958
|
+
async function probeLoopbackWebSocketTransport(baseUrl, timeoutMs) {
|
|
959
|
+
let target;
|
|
960
|
+
try {
|
|
961
|
+
target = new URL(`${String(baseUrl).replace(/\/+$/, '')}/realtime/capability-probe`);
|
|
962
|
+
}
|
|
963
|
+
catch {
|
|
964
|
+
return { ok: false, blocker: 'desktop_bridge_websocket_url_invalid', status_code: null };
|
|
965
|
+
}
|
|
966
|
+
if (target.protocol !== 'http:'
|
|
967
|
+
|| (target.hostname !== '127.0.0.1' && target.hostname !== '::1')) {
|
|
968
|
+
return {
|
|
969
|
+
ok: false,
|
|
970
|
+
blocker: 'desktop_bridge_websocket_target_not_loopback',
|
|
971
|
+
status_code: null
|
|
972
|
+
};
|
|
973
|
+
}
|
|
974
|
+
const key = randomBytes(16).toString('base64');
|
|
975
|
+
const expectedAccept = createHash('sha1')
|
|
976
|
+
.update(`${key}258EAFA5-E914-47DA-95CA-C5AB0DC85B11`)
|
|
977
|
+
.digest('base64');
|
|
978
|
+
const port = Number(target.port || 80);
|
|
979
|
+
const hostHeader = target.hostname === '::1'
|
|
980
|
+
? `[::1]:${port}`
|
|
981
|
+
: `${target.hostname}:${port}`;
|
|
982
|
+
return new Promise((resolve) => {
|
|
983
|
+
const socket = net.connect({ host: target.hostname, port });
|
|
984
|
+
let settled = false;
|
|
985
|
+
let responseHead = Buffer.alloc(0);
|
|
986
|
+
const settle = (result) => {
|
|
987
|
+
if (settled)
|
|
988
|
+
return;
|
|
989
|
+
settled = true;
|
|
990
|
+
clearTimeout(timer);
|
|
991
|
+
socket.destroy();
|
|
992
|
+
resolve(result);
|
|
993
|
+
};
|
|
994
|
+
const timer = setTimeout(() => settle({
|
|
995
|
+
ok: false,
|
|
996
|
+
blocker: 'desktop_bridge_websocket_timeout',
|
|
997
|
+
status_code: null
|
|
998
|
+
}), Math.max(250, timeoutMs));
|
|
999
|
+
timer.unref();
|
|
1000
|
+
socket.once('connect', () => {
|
|
1001
|
+
socket.write([
|
|
1002
|
+
`GET ${target.pathname}${target.search} HTTP/1.1`,
|
|
1003
|
+
`Host: ${hostHeader}`,
|
|
1004
|
+
'Connection: Upgrade',
|
|
1005
|
+
'Upgrade: websocket',
|
|
1006
|
+
`Sec-WebSocket-Key: ${key}`,
|
|
1007
|
+
'Sec-WebSocket-Version: 13',
|
|
1008
|
+
'Sec-WebSocket-Protocol: codex.realtime.v1',
|
|
1009
|
+
'Origin: app://codex',
|
|
1010
|
+
'',
|
|
1011
|
+
''
|
|
1012
|
+
].join('\r\n'));
|
|
1013
|
+
});
|
|
1014
|
+
socket.on('data', (chunk) => {
|
|
1015
|
+
responseHead = Buffer.concat([responseHead, chunk]);
|
|
1016
|
+
if (responseHead.length > 64 * 1024) {
|
|
1017
|
+
settle({
|
|
1018
|
+
ok: false,
|
|
1019
|
+
blocker: 'desktop_bridge_websocket_response_too_large',
|
|
1020
|
+
status_code: null
|
|
1021
|
+
});
|
|
1022
|
+
return;
|
|
1023
|
+
}
|
|
1024
|
+
const boundary = responseHead.indexOf('\r\n\r\n');
|
|
1025
|
+
if (boundary < 0)
|
|
1026
|
+
return;
|
|
1027
|
+
const head = responseHead.subarray(0, boundary).toString('latin1');
|
|
1028
|
+
const statusCode = Number(head.match(/^HTTP\/1\.[01]\s+(\d{3})/i)?.[1] || 0) || null;
|
|
1029
|
+
const accept = head.match(/\r\nSec-WebSocket-Accept:\s*([^\r\n]+)/i)?.[1]?.trim() || '';
|
|
1030
|
+
const upgraded = statusCode === 101
|
|
1031
|
+
&& /\r\nUpgrade:\s*websocket\s*\r\n/i.test(`\r\n${head}\r\n`)
|
|
1032
|
+
&& accept === expectedAccept;
|
|
1033
|
+
settle({
|
|
1034
|
+
ok: upgraded,
|
|
1035
|
+
blocker: upgraded ? null : 'desktop_bridge_websocket_upgrade_failed',
|
|
1036
|
+
status_code: statusCode
|
|
1037
|
+
});
|
|
1038
|
+
});
|
|
1039
|
+
socket.once('error', () => settle({
|
|
1040
|
+
ok: false,
|
|
1041
|
+
blocker: 'desktop_bridge_websocket_unavailable',
|
|
1042
|
+
status_code: null
|
|
1043
|
+
}));
|
|
1044
|
+
socket.once('close', () => {
|
|
1045
|
+
if (!settled) {
|
|
1046
|
+
settle({
|
|
1047
|
+
ok: false,
|
|
1048
|
+
blocker: 'desktop_bridge_websocket_closed_before_upgrade',
|
|
1049
|
+
status_code: null
|
|
1050
|
+
});
|
|
1051
|
+
}
|
|
1052
|
+
});
|
|
1053
|
+
});
|
|
1054
|
+
}
|
|
1055
|
+
async function fetchGatewayJson(url, headers, fetchImpl, timeoutMs = 5_000) {
|
|
1056
|
+
const request = fetchImpl || globalThis.fetch;
|
|
1057
|
+
if (typeof request !== 'function') {
|
|
1058
|
+
return { ok: false, httpStatus: null, payload: null, blocker: 'fetch_unavailable' };
|
|
1059
|
+
}
|
|
1060
|
+
try {
|
|
1061
|
+
const response = await request(url, {
|
|
1062
|
+
headers,
|
|
1063
|
+
redirect: 'error',
|
|
1064
|
+
signal: AbortSignal.timeout(Math.max(250, timeoutMs))
|
|
1065
|
+
});
|
|
1066
|
+
const text = await response.text();
|
|
1067
|
+
if (Buffer.byteLength(text) > 8 * 1024 * 1024) {
|
|
1068
|
+
return {
|
|
1069
|
+
ok: false,
|
|
1070
|
+
httpStatus: response.status,
|
|
1071
|
+
payload: null,
|
|
1072
|
+
blocker: 'codex_lb_capability_payload_too_large'
|
|
1073
|
+
};
|
|
1074
|
+
}
|
|
1075
|
+
let payload = null;
|
|
1076
|
+
try {
|
|
1077
|
+
payload = text ? JSON.parse(text) : null;
|
|
1078
|
+
}
|
|
1079
|
+
catch {
|
|
1080
|
+
return {
|
|
1081
|
+
ok: false,
|
|
1082
|
+
httpStatus: response.status,
|
|
1083
|
+
payload: null,
|
|
1084
|
+
blocker: 'codex_lb_capability_payload_invalid_json'
|
|
1085
|
+
};
|
|
1086
|
+
}
|
|
1087
|
+
return {
|
|
1088
|
+
ok: response.ok,
|
|
1089
|
+
httpStatus: response.status,
|
|
1090
|
+
payload,
|
|
1091
|
+
blocker: response.ok ? null : `codex_lb_capability_http_${response.status}`
|
|
1092
|
+
};
|
|
1093
|
+
}
|
|
1094
|
+
catch (error) {
|
|
1095
|
+
return {
|
|
1096
|
+
ok: false,
|
|
1097
|
+
httpStatus: null,
|
|
1098
|
+
payload: null,
|
|
1099
|
+
blocker: error instanceof Error && error.name === 'TimeoutError'
|
|
1100
|
+
? 'codex_lb_capability_timeout'
|
|
1101
|
+
: 'codex_lb_capability_unavailable'
|
|
1102
|
+
};
|
|
1103
|
+
}
|
|
1104
|
+
}
|
|
1105
|
+
function desktopAdoptionEvidence(evidence) {
|
|
1106
|
+
const fixture = evidence?.fixture === true;
|
|
1107
|
+
const verified = evidence?.desktop_adoption_verified === true
|
|
1108
|
+
&& evidence?.desktop_adoption_source === 'codex_desktop_runtime'
|
|
1109
|
+
&& !fixture;
|
|
1110
|
+
return {
|
|
1111
|
+
ok: verified,
|
|
1112
|
+
blockers: verified
|
|
1113
|
+
? []
|
|
1114
|
+
: [
|
|
1115
|
+
fixture
|
|
1116
|
+
? 'desktop_adoption_fixture_not_accepted'
|
|
1117
|
+
: 'desktop_adoption_evidence_required'
|
|
1118
|
+
]
|
|
1119
|
+
};
|
|
1120
|
+
}
|
|
1121
|
+
function blockedDeepEvidenceValidation(blocker) {
|
|
1122
|
+
return {
|
|
1123
|
+
schema: CODEX_LB_DEEP_EVIDENCE_VALIDATION_SCHEMA,
|
|
1124
|
+
state: 'blocked',
|
|
1125
|
+
trusted: false,
|
|
1126
|
+
evidence: null,
|
|
1127
|
+
producer_id: null,
|
|
1128
|
+
created_at: null,
|
|
1129
|
+
content_sha256: null,
|
|
1130
|
+
trust_anchor_id: null,
|
|
1131
|
+
blockers: [blocker],
|
|
1132
|
+
warnings: []
|
|
1133
|
+
};
|
|
1134
|
+
}
|
|
1135
|
+
async function preflightDesktopRollbackReceipt(receiptPath) {
|
|
1136
|
+
let receipt;
|
|
1137
|
+
try {
|
|
1138
|
+
receipt = await readCodexLbMigrationReceipt(receiptPath);
|
|
1139
|
+
}
|
|
1140
|
+
catch (error) {
|
|
1141
|
+
return {
|
|
1142
|
+
schema: 'sks.codex-lb-migration-rollback.v1',
|
|
1143
|
+
ok: false,
|
|
1144
|
+
status: 'invalid_receipt',
|
|
1145
|
+
receipt_id: null,
|
|
1146
|
+
restored_files: [],
|
|
1147
|
+
conflicts: [],
|
|
1148
|
+
error: safeControllerError(error)
|
|
1149
|
+
};
|
|
1150
|
+
}
|
|
1151
|
+
const conflicts = [];
|
|
1152
|
+
for (const file of receipt.files) {
|
|
1153
|
+
const currentSha = await fileSha256OrMissing(file.path).catch(() => '__unreadable__');
|
|
1154
|
+
if (currentSha !== file.after_sha256) {
|
|
1155
|
+
conflicts.push({
|
|
1156
|
+
path: file.path,
|
|
1157
|
+
expected_after_sha256: file.after_sha256,
|
|
1158
|
+
current_sha256: currentSha === '__unreadable__' ? null : currentSha,
|
|
1159
|
+
reason: 'current_file_changed_after_migration'
|
|
1160
|
+
});
|
|
1161
|
+
continue;
|
|
1162
|
+
}
|
|
1163
|
+
if (file.before_sha256 === null)
|
|
1164
|
+
continue;
|
|
1165
|
+
if (!file.backup_path) {
|
|
1166
|
+
conflicts.push({
|
|
1167
|
+
path: file.path,
|
|
1168
|
+
expected_after_sha256: file.after_sha256,
|
|
1169
|
+
current_sha256: currentSha,
|
|
1170
|
+
reason: 'before_backup_missing'
|
|
1171
|
+
});
|
|
1172
|
+
continue;
|
|
1173
|
+
}
|
|
1174
|
+
let backupBytes;
|
|
1175
|
+
try {
|
|
1176
|
+
backupBytes = await fsp.readFile(file.backup_path);
|
|
1177
|
+
}
|
|
1178
|
+
catch {
|
|
1179
|
+
conflicts.push({
|
|
1180
|
+
path: file.path,
|
|
1181
|
+
expected_after_sha256: file.after_sha256,
|
|
1182
|
+
current_sha256: currentSha,
|
|
1183
|
+
reason: 'before_backup_missing'
|
|
1184
|
+
});
|
|
1185
|
+
continue;
|
|
1186
|
+
}
|
|
1187
|
+
if (createHash('sha256').update(backupBytes).digest('hex') !== file.before_sha256) {
|
|
1188
|
+
conflicts.push({
|
|
1189
|
+
path: file.path,
|
|
1190
|
+
expected_after_sha256: file.after_sha256,
|
|
1191
|
+
current_sha256: currentSha,
|
|
1192
|
+
reason: 'before_backup_hash_mismatch'
|
|
1193
|
+
});
|
|
1194
|
+
}
|
|
1195
|
+
}
|
|
1196
|
+
return conflicts.length
|
|
1197
|
+
? {
|
|
1198
|
+
schema: 'sks.codex-lb-migration-rollback.v1',
|
|
1199
|
+
ok: false,
|
|
1200
|
+
status: 'rollback_conflict',
|
|
1201
|
+
receipt_id: receipt.id,
|
|
1202
|
+
restored_files: [],
|
|
1203
|
+
conflicts
|
|
1204
|
+
}
|
|
1205
|
+
: {
|
|
1206
|
+
schema: 'sks.codex-lb-migration-rollback.v1',
|
|
1207
|
+
ok: true,
|
|
1208
|
+
status: 'rolled_back',
|
|
1209
|
+
receipt_id: receipt.id,
|
|
1210
|
+
restored_files: [],
|
|
1211
|
+
conflicts: []
|
|
1212
|
+
};
|
|
1213
|
+
}
|
|
1214
|
+
function capabilityTarget(context) {
|
|
1215
|
+
if (!context.loadedEnv.base_url || !context.loadedEnv.secret_api_key)
|
|
1216
|
+
return null;
|
|
1217
|
+
if (context.mode === 'desktop-native-bridge' && context.bridge.state?.codex_base_url) {
|
|
1218
|
+
return {
|
|
1219
|
+
baseUrl: context.bridge.state.codex_base_url.replace(/\/+$/, ''),
|
|
1220
|
+
headers: {},
|
|
1221
|
+
transport: context.gatewayAuthTransport
|
|
1222
|
+
};
|
|
1223
|
+
}
|
|
1224
|
+
const headers = context.gatewayAuthTransport === 'x-codex-lb-api-key'
|
|
1225
|
+
? { 'X-Codex-LB-API-Key': context.loadedEnv.secret_api_key }
|
|
1226
|
+
: { Authorization: `Bearer ${context.loadedEnv.secret_api_key}` };
|
|
1227
|
+
return {
|
|
1228
|
+
baseUrl: normalizeCodexLbBaseUrl(context.loadedEnv.base_url).replace(/\/+$/, ''),
|
|
1229
|
+
headers,
|
|
1230
|
+
transport: context.gatewayAuthTransport
|
|
1231
|
+
};
|
|
1232
|
+
}
|
|
1233
|
+
async function beginDesktopTransaction(context, receiptDirOverride) {
|
|
1234
|
+
const id = createCodexLbMigrationReceiptId();
|
|
1235
|
+
const receiptDir = receiptDirOverride || codexLbMigrationReceiptDir(context.home);
|
|
1236
|
+
const backupDir = path.join(receiptDir, id, 'files');
|
|
1237
|
+
const servicePaths = desktopBridgeServicePaths(context.home);
|
|
1238
|
+
const targets = [
|
|
1239
|
+
{ path: context.configPath, owned: false },
|
|
1240
|
+
{ path: servicePaths.settings_path, owned: true },
|
|
1241
|
+
{ path: servicePaths.launch_agent_path, owned: true },
|
|
1242
|
+
{ path: servicePaths.state_path, owned: true }
|
|
1243
|
+
];
|
|
1244
|
+
const backups = [];
|
|
1245
|
+
for (const target of targets) {
|
|
1246
|
+
backups.push(await backupCodexLbMigrationFile(target.path, backupDir, target.owned));
|
|
1247
|
+
}
|
|
1248
|
+
return { id, receiptDir, backups };
|
|
1249
|
+
}
|
|
1250
|
+
async function finishDesktopTransaction(transaction, input) {
|
|
1251
|
+
const receipt = {
|
|
1252
|
+
schema: 'sks.codex-lb-migration-receipt.v1',
|
|
1253
|
+
id: transaction.id,
|
|
1254
|
+
created_at: new Date().toISOString(),
|
|
1255
|
+
from_mode: input.fromMode,
|
|
1256
|
+
to_mode: input.toMode,
|
|
1257
|
+
files: await finalizeCodexLbMigrationReceiptFiles(transaction.backups),
|
|
1258
|
+
bridge_state_path: transaction.backups.find((entry) => entry.path.endsWith('codex-lb-desktop-bridge.json'))?.path || null,
|
|
1259
|
+
oauth_preserved: input.oauthPreserved,
|
|
1260
|
+
capability_summary: input.capabilitySummary
|
|
1261
|
+
};
|
|
1262
|
+
const receiptPath = await writeCodexLbMigrationReceipt(receipt, { receiptDir: transaction.receiptDir });
|
|
1263
|
+
return { receipt, path: receiptPath };
|
|
1264
|
+
}
|
|
1265
|
+
async function rollbackDesktopTransaction(transaction, options) {
|
|
1266
|
+
const receipt = {
|
|
1267
|
+
schema: 'sks.codex-lb-migration-receipt.v1',
|
|
1268
|
+
id: transaction.id,
|
|
1269
|
+
created_at: new Date().toISOString(),
|
|
1270
|
+
from_mode: 'activation-attempt',
|
|
1271
|
+
to_mode: 'rolled-back',
|
|
1272
|
+
files: await finalizeCodexLbMigrationReceiptFiles(transaction.backups),
|
|
1273
|
+
bridge_state_path: null,
|
|
1274
|
+
oauth_preserved: true,
|
|
1275
|
+
capability_summary: {}
|
|
1276
|
+
};
|
|
1277
|
+
const rollback = await rollbackCodexLbMigrationReceipt({ receipt });
|
|
1278
|
+
if (!rollback.ok)
|
|
1279
|
+
return rollback;
|
|
1280
|
+
const bridgeRestart = options.restartPreviousBridge
|
|
1281
|
+
? await (options.bootstrapBridgeImpl || bootstrapExistingDesktopBridgeService)(options)
|
|
1282
|
+
: undefined;
|
|
1283
|
+
const appRestart = options.restartAppAfterRollback
|
|
1284
|
+
? await performOptionalRestart({
|
|
1285
|
+
...options,
|
|
1286
|
+
restartApp: true
|
|
1287
|
+
}, options.authBefore).catch((error) => ({
|
|
1288
|
+
schema: 'sks.codex-app-restart.v1',
|
|
1289
|
+
ok: false,
|
|
1290
|
+
status: 'failed',
|
|
1291
|
+
skipped: false,
|
|
1292
|
+
app_name: 'Codex',
|
|
1293
|
+
blockers: [safeControllerError(error)]
|
|
1294
|
+
}))
|
|
1295
|
+
: undefined;
|
|
1296
|
+
return {
|
|
1297
|
+
...rollback,
|
|
1298
|
+
...(bridgeRestart ? { bridge_restart: bridgeRestart } : {}),
|
|
1299
|
+
...(appRestart ? { app_restart: appRestart } : {})
|
|
1300
|
+
};
|
|
1301
|
+
}
|
|
1302
|
+
async function performOptionalRestart(input, authBefore) {
|
|
1303
|
+
if (input.restartApp !== true) {
|
|
1304
|
+
return {
|
|
1305
|
+
schema: 'sks.codex-app-restart.v1',
|
|
1306
|
+
ok: true,
|
|
1307
|
+
status: 'skipped',
|
|
1308
|
+
skipped: true,
|
|
1309
|
+
reason: 'not_requested',
|
|
1310
|
+
app_name: 'ChatGPT',
|
|
1311
|
+
blockers: []
|
|
1312
|
+
};
|
|
1313
|
+
}
|
|
1314
|
+
const restart = await (input.restartAppImpl || restartCodexApp)({ enabled: true });
|
|
1315
|
+
if (restart.ok) {
|
|
1316
|
+
const after = await captureCodexAuthSnapshot({
|
|
1317
|
+
...(input.home ? { home: input.home } : {}),
|
|
1318
|
+
...(input.authPath ? { authPath: input.authPath } : {})
|
|
1319
|
+
});
|
|
1320
|
+
assertDesktopOAuthSemanticIdentity(authBefore, after);
|
|
1321
|
+
}
|
|
1322
|
+
return restart;
|
|
1323
|
+
}
|
|
1324
|
+
function capabilityEvidenceToSignal(evidence) {
|
|
1325
|
+
return {
|
|
1326
|
+
configured: evidence.state !== 'skipped',
|
|
1327
|
+
attempted: evidence.source === 'transport' || evidence.source === 'deep_probe',
|
|
1328
|
+
verified: evidence.state === 'verified',
|
|
1329
|
+
source: evidence.source,
|
|
1330
|
+
blockers: evidence.blockers,
|
|
1331
|
+
warnings: evidence.warnings,
|
|
1332
|
+
evidence: evidence.evidence
|
|
1333
|
+
};
|
|
1334
|
+
}
|
|
1335
|
+
function topLevelTomlString(text, key) {
|
|
1336
|
+
const topLevel = String(text || '').split(/\n\s*\[/)[0] || '';
|
|
1337
|
+
return topLevel.match(new RegExp(`(?:^|\\n)\\s*${escapeRegExp(key)}\\s*=\\s*"([^"]+)"\\s*(?:#.*)?(?=\\n|$)`))?.[1] || '';
|
|
1338
|
+
}
|
|
1339
|
+
function tomlTable(text, table) {
|
|
1340
|
+
return String(text || '').match(new RegExp(`(?:^|\\n)\\[${escapeRegExp(table)}\\]([\\s\\S]*?)(?=\\n\\[[^\\]]+\\]|\\s*$)`))?.[1] || '';
|
|
1341
|
+
}
|
|
1342
|
+
function hasTomlString(text, key, value) {
|
|
1343
|
+
return new RegExp(`(?:^|\\n)\\s*${escapeRegExp(key)}\\s*=\\s*"${escapeRegExp(value)}"\\s*(?:#.*)?(?=\\n|$)`).test(text);
|
|
1344
|
+
}
|
|
1345
|
+
function hasTomlBoolean(text, key, value) {
|
|
1346
|
+
return new RegExp(`(?:^|\\n)\\s*${escapeRegExp(key)}\\s*=\\s*${value ? 'true' : 'false'}\\s*(?:#.*)?(?=\\n|$)`).test(text);
|
|
1347
|
+
}
|
|
1348
|
+
function hasTopLevelLine(text, line) {
|
|
1349
|
+
const topLevel = String(text || '').split(/\n\s*\[/)[0] || '';
|
|
1350
|
+
return topLevel.split(/\r?\n/).some((entry) => entry.trim() === line);
|
|
1351
|
+
}
|
|
1352
|
+
function isLoopbackCodexBaseUrl(value) {
|
|
1353
|
+
try {
|
|
1354
|
+
const url = new URL(value);
|
|
1355
|
+
return url.protocol === 'http:'
|
|
1356
|
+
&& (url.hostname === '127.0.0.1' || url.hostname === '::1')
|
|
1357
|
+
&& url.pathname.replace(/\/+$/, '') === '/backend-api/codex';
|
|
1358
|
+
}
|
|
1359
|
+
catch {
|
|
1360
|
+
return false;
|
|
1361
|
+
}
|
|
1362
|
+
}
|
|
1363
|
+
function redactRemoteOrigin(baseUrl) {
|
|
1364
|
+
if (!baseUrl)
|
|
1365
|
+
return null;
|
|
1366
|
+
try {
|
|
1367
|
+
const url = new URL(baseUrl);
|
|
1368
|
+
return `${url.protocol}//<redacted>${url.pathname}`;
|
|
1369
|
+
}
|
|
1370
|
+
catch {
|
|
1371
|
+
return null;
|
|
1372
|
+
}
|
|
1373
|
+
}
|
|
1374
|
+
function statusGuidance(mode, configured, blockers) {
|
|
1375
|
+
if (!configured) {
|
|
1376
|
+
return [
|
|
1377
|
+
'Run: sks codex-lb setup --host <domain> --api-key-stdin --yes --desktop-mode cli-provider',
|
|
1378
|
+
'Then choose Desktop routing explicitly with: sks codex-lb use-desktop-full'
|
|
1379
|
+
];
|
|
1380
|
+
}
|
|
1381
|
+
if (blockers.includes('legacy_codex_lb_desktop_config_requires_migration')) {
|
|
1382
|
+
return ['Run: sks codex-lb migrate-legacy-desktop --restart-app'];
|
|
1383
|
+
}
|
|
1384
|
+
if (mode === 'desktop-native-bridge') {
|
|
1385
|
+
return ['Run: sks codex-lb capabilities --level transport'];
|
|
1386
|
+
}
|
|
1387
|
+
if (mode === 'desktop-dual-auth-compat') {
|
|
1388
|
+
return [
|
|
1389
|
+
'Compatibility mode is explicit and does not prove full Desktop capability.',
|
|
1390
|
+
'Run: sks codex-lb capabilities --level transport'
|
|
1391
|
+
];
|
|
1392
|
+
}
|
|
1393
|
+
return [
|
|
1394
|
+
'Desktop remains on built-in OpenAI/ChatGPT OAuth.',
|
|
1395
|
+
'Enable routing explicitly with: sks codex-lb use-desktop-full'
|
|
1396
|
+
];
|
|
1397
|
+
}
|
|
1398
|
+
function safeControllerError(error) {
|
|
1399
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1400
|
+
return /^[a-z0-9_:-]+$/i.test(message) ? message : 'codex_lb_desktop_controller_failed';
|
|
1401
|
+
}
|
|
1402
|
+
function uniqueStrings(values) {
|
|
1403
|
+
return [...new Set(values.map((value) => String(value || '').trim()).filter(Boolean))];
|
|
1404
|
+
}
|
|
1405
|
+
function escapeRegExp(value) {
|
|
1406
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
1407
|
+
}
|
|
1408
|
+
function isRecord(value) {
|
|
1409
|
+
return Boolean(value && typeof value === 'object' && !Array.isArray(value));
|
|
1410
|
+
}
|