sneakoscope 6.5.1 → 7.0.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.
Files changed (111) hide show
  1. package/README.md +9 -7
  2. package/crates/sks-core/Cargo.lock +1 -1
  3. package/crates/sks-core/Cargo.toml +1 -1
  4. package/dist/cli/command-manifest-lite.js +2 -2
  5. package/dist/cli/command-registry.js +2 -2
  6. package/dist/cli/install-helpers-codex-lb-config.js +71 -0
  7. package/dist/cli/install-helpers-codex-lb-selftest.js +11 -14
  8. package/dist/cli/install-helpers.js +305 -53
  9. package/dist/config/skills-manifest.json +62 -62
  10. package/dist/core/agents/agent-effort-policy.js +13 -7
  11. package/dist/core/agents/agent-orchestrator.js +56 -11
  12. package/dist/core/agents/agent-output-validator.js +2 -1
  13. package/dist/core/agents/agent-patch-queue-store.js +0 -8
  14. package/dist/core/agents/agent-roster.js +4 -2
  15. package/dist/core/agents/agent-worker-pipeline.js +12 -6
  16. package/dist/core/agents/native-worker-backend-router.js +1 -1
  17. package/dist/core/bench.js +1 -1
  18. package/dist/core/codex/official-goal-mode.js +4 -2
  19. package/dist/core/codex-app/codex-app-fast-ui-repair.js +18 -1
  20. package/dist/core/codex-app/codex-app-ui-state-snapshot.js +16 -0
  21. package/dist/core/codex-app.js +52 -6
  22. package/dist/core/codex-control/codex-control-proof.js +1 -0
  23. package/dist/core/codex-control/codex-fake-sdk-adapter.js +1 -1
  24. package/dist/core/codex-control/codex-lb-launch-recovery.js +7 -3
  25. package/dist/core/codex-control/codex-sdk-adapter.js +8 -7
  26. package/dist/core/codex-control/codex-sdk-config-policy.js +4 -24
  27. package/dist/core/codex-control/codex-sdk-env-policy.js +396 -11
  28. package/dist/core/codex-control/codex-task-runner.js +112 -57
  29. package/dist/core/codex-control/gpt-final-arbiter.js +1 -2
  30. package/dist/core/codex-control/python-codex-sdk-adapter.js +38 -15
  31. package/dist/core/codex-native/core-skill-manifest.js +4 -7
  32. package/dist/core/codex-runtime/resolve-codex-runtime.js +199 -0
  33. package/dist/core/commands/command-utils.js +2 -2
  34. package/dist/core/commands/eval-command.js +19 -2
  35. package/dist/core/commands/goal-command.js +37 -86
  36. package/dist/core/commands/naruto-command.js +189 -135
  37. package/dist/core/evaluation.js +83 -21
  38. package/dist/core/feature-fixtures.js +4 -3
  39. package/dist/core/fsx.js +141 -12
  40. package/dist/core/goal-workflow.js +71 -140
  41. package/dist/core/hooks-runtime/hook-io.js +2 -2
  42. package/dist/core/hooks-runtime.js +304 -52
  43. package/dist/core/init/skills.js +7 -6
  44. package/dist/core/init.js +52 -33
  45. package/dist/core/lean-engineering-policy.js +25 -23
  46. package/dist/core/locks/file-lock.js +5 -4
  47. package/dist/core/managed-assets/managed-assets-manifest.js +1 -1
  48. package/dist/core/mission.js +99 -3
  49. package/dist/core/pipeline-internals/runtime-core.js +67 -95
  50. package/dist/core/pipeline-internals/runtime-gates.js +25 -6
  51. package/dist/core/proof/fake-real-proof-policy.js +32 -9
  52. package/dist/core/proof/route-proof-gate.js +49 -1
  53. package/dist/core/provider/model-router.js +2 -0
  54. package/dist/core/questions.js +31 -5
  55. package/dist/core/recallpulse.js +1 -1
  56. package/dist/core/release/canonical-test-proof.js +135 -0
  57. package/dist/core/release/package-size-budget.js +1 -1
  58. package/dist/core/release/release-closure-contract.js +1 -0
  59. package/dist/core/release/release-closure-validation.js +25 -12
  60. package/dist/core/release/release-closure.js +34 -5
  61. package/dist/core/release/release-gate-contract.js +0 -3
  62. package/dist/core/release/release-gate-dag.js +4 -2
  63. package/dist/core/release/release-real-contract.js +41 -2
  64. package/dist/core/retention.js +90 -1
  65. package/dist/core/routes/dollar-manifest-lite.js +1 -1
  66. package/dist/core/routes.js +17 -18
  67. package/dist/core/safety/ssot-guard.js +1 -54
  68. package/dist/core/stop-gate/stop-gate-check.js +0 -14
  69. package/dist/core/stop-gate/stop-gate-writer.js +0 -4
  70. package/dist/core/subagents/agent-catalog.js +28 -5
  71. package/dist/core/subagents/model-policy.js +52 -11
  72. package/dist/core/subagents/naruto-proof-projection.js +40 -9
  73. package/dist/core/subagents/official-subagent-config.js +8 -5
  74. package/dist/core/subagents/official-subagent-preparation.js +364 -53
  75. package/dist/core/subagents/official-subagent-prompt.js +18 -7
  76. package/dist/core/subagents/official-subagent-runner.js +122 -11
  77. package/dist/core/subagents/subagent-evidence.js +44 -8
  78. package/dist/core/subagents/wave-lifecycle.js +258 -0
  79. package/dist/core/subagents/wave-parent-guidance.js +42 -0
  80. package/dist/core/verification/machine-feedback.js +39 -19
  81. package/dist/core/version.js +1 -1
  82. package/dist/native/sks-menubar/Sources/AppIdentity.swift +3 -1
  83. package/dist/native/sks-menubar/Sources/ControlCenterWindowController.swift +14 -8
  84. package/dist/native/sks-menubar/Sources/DiagnosticsViewController.swift +71 -7
  85. package/dist/native/sks-menubar/Sources/MCPServersViewController.swift +50 -9
  86. package/dist/native/sks-menubar/Sources/OverviewViewController.swift +254 -31
  87. package/dist/native/sks-menubar/Sources/ProcessClient.swift +47 -5
  88. package/dist/native/sks-menubar/Sources/ProvidersViewController.swift +120 -29
  89. package/dist/native/sks-menubar/Sources/RemoteTelegramViewController.swift +58 -23
  90. package/dist/native/sks-menubar/Sources/SettingsViewController.swift +41 -7
  91. package/dist/native/sks-menubar/Sources/StatusItemController.swift +34 -3
  92. package/dist/native/sks-menubar/Sources/UpdatesViewController.swift +38 -8
  93. package/dist/scripts/architecture-guard-check.js +1 -9
  94. package/dist/scripts/canonical-test-runner.js +51 -8
  95. package/dist/scripts/codex-0144-binary-identity-check.js +10 -4
  96. package/dist/scripts/codex-0144-policy-check.js +4 -0
  97. package/dist/scripts/codex-sdk-real-smoke-check.js +20 -2
  98. package/dist/scripts/current-command-surface-check.js +1 -1
  99. package/dist/scripts/docs-truthfulness-check.js +4 -2
  100. package/dist/scripts/doctor-fixes-codex-app-fast-ui-check.js +7 -3
  101. package/dist/scripts/gate-policy-audit-check.js +7 -1
  102. package/dist/scripts/loop-directive-check-lib.js +14 -13
  103. package/dist/scripts/product-design-plugin-routing-check.js +4 -9
  104. package/dist/scripts/release-affected-selector-check.js +7 -1
  105. package/dist/scripts/release-check-stamp.js +151 -18
  106. package/dist/scripts/release-dynamic-presets-check.js +5 -2
  107. package/dist/scripts/release-real-check.js +21 -3
  108. package/package.json +1 -1
  109. package/release-gates.v2.json +19 -20
  110. package/schemas/codex/agent-result.schema.json +4 -0
  111. package/dist/core/loops/goal-to-loop-compat.js +0 -22
package/README.md CHANGED
@@ -18,16 +18,18 @@ Proof-first orchestration for Codex CLI, ChatGPT Desktop, AI coding agents, mult
18
18
  Sneakoscope Codex (`sks`) is an open-source trust layer for Codex CLI and ChatGPT Desktop. It coordinates bounded AI coding agents, records machine-verifiable evidence, preserves project memory, and blocks release claims that are not supported by current tests or artifacts. Search visibility outcomes are measured separately; SKS does not promise rankings or traffic.
19
19
  <!-- END SKS SEARCH VISIBILITY MARKETING -->
20
20
 
21
- Current release: **SKS 6.5.1**, validated against the official stable **Codex CLI 0.144.5** release from July 16, 2026. It keeps the Control Center alive through self-update completion, restores SKS-hidden Chat/Pro model access in the latest Codex desktop surface, makes Fast mode independently visible and selectable from the menu bar, and stabilizes same-mission Naruto admission, deterministic proof receipts, and project-scoped MCP inheritance. The `0.145.0-alpha` line is intentionally excluded from the stable release baseline. See [CHANGELOG.md](CHANGELOG.md).
21
+ Current release: **SKS 7.0.0**, validated against the official stable **Codex CLI 0.144.5** release from July 16, 2026. It makes the Control Center Overview report build, install, cache, rebuild, and probe health from their real authorities; adds root-owned Naruto follow-up waves with recovered thread capacity; separates Terra Medium exploration, Sol High implementation, and Sol Max judgment; and replaces duplicated global guidance with one concise Core Engineering Directive. The `0.145.0-alpha` line is intentionally excluded from the stable release baseline. See [CHANGELOG.md](CHANGELOG.md).
22
22
 
23
- ## What 6.5.1 Fixes
23
+ ## What 7.0.0 Ships
24
24
 
25
- | Problem | 6.5.1 behavior |
25
+ | Problem | 7.0.0 behavior |
26
26
  | --- | --- |
27
- | Control Center disappeared during an update | The new package is installed and verified without killing the active Control Center; the final receipt is synchronized before a detached menu-bar relaunch. |
28
- | Chat entry and Pro model access disappeared in Codex Desktop | SKS removes only provenance-marked global provider/model locks that it owns, while preserving user-owned providers, credentials, and explicit settings. |
29
- | Fast mode was missing from Codex Desktop and the menu bar | Desktop Fast selection is repaired without conflating it with reasoning effort, and the menu bar exposes current Fast status plus direct On/Off actions. |
30
- | Concurrent hosts could duplicate a Naruto mission or reinterpret its proof | One mission admits one standalone Codex parent, terminal bundles are reused immutably, proof returns a deterministic six-artifact fingerprint, and trusted project MCP configuration is inherited by the parent. |
27
+ | Overview mixed Menu Bar, installed SKS, and cached registry versions | Each value is labeled by authority, stale or unavailable probes remain explicit, and Refresh forces a bounded update-status refresh. |
28
+ | Naruto stopped creating children after its first wave | The root parent records settled waves, recovers open-thread capacity, rescans the ready DAG, and can launch later direct-child waves under the same workflow run. |
29
+ | Most delegated work drifted to Sol Max | Read-heavy discovery uses Terra Medium, ordinary implementation uses Sol High, and Sol Max is reserved for focused high-risk or final judgment slices. |
30
+ | Goal creation started a second SKS-owned mission and loop | Codex native Goal is the only persisted owner; create/edit objectives are detailed and bounded, while SKS writes no Goal state or fallback loop. |
31
+ | Global instructions accumulated duplicated route rules and forced synthetic tests | One Core Engineering Directive anchors all work, route-specific details stay with their route, and verification targets normal behavior, meaningful boundaries, and plausible failures. |
32
+ | GUI-launched status commands could hang or contaminate real update state during tests | Menu Bar commands use a safe HOME cwd, closed stdin, and timeouts; update fixtures use isolated HOME and cache paths. |
31
33
 
32
34
  ## Install In One Command
33
35
 
@@ -76,7 +76,7 @@ dependencies = [
76
76
 
77
77
  [[package]]
78
78
  name = "sks-core"
79
- version = "6.5.1"
79
+ version = "7.0.0"
80
80
  dependencies = [
81
81
  "serde_json",
82
82
  ]
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "sks-core"
3
- version = "6.5.1"
3
+ version = "7.0.0"
4
4
  edition = "2021"
5
5
 
6
6
  [dependencies]
@@ -37,7 +37,7 @@ export const COMMAND_MANIFEST_LITE = [
37
37
  { name: 'menubar', summary: 'Inspect/install/restart/uninstall SKS menu bar', maturity: 'beta', allowedDuringActiveRoute: true, diagnostic: true },
38
38
  { name: 'remote', summary: 'Inspect official Remote readiness and run the proof-aware SSH stdio worker', maturity: 'beta' },
39
39
  { name: 'telegram', summary: 'Inspect and run the private proof-aware Telegram Hub', maturity: 'beta' },
40
- { name: 'hooks', summary: 'Explain and inspect Codex hooks', maturity: 'beta' },
40
+ { name: 'hooks', summary: 'Explain and inspect Codex hooks', maturity: 'beta', skipMigrationGate: true },
41
41
  { name: 'zellij-lane', summary: 'Render a Zellij lane frame for SKS sessions', maturity: 'beta' },
42
42
  { name: 'zellij-slot-pane', summary: 'Render a compact Zellij worker slot pane', maturity: 'beta' },
43
43
  { name: 'zellij-monitor-pane', summary: 'Render the live Zellij MAD/Naruto monitor pane', maturity: 'beta', readonly: true, skipMigrationGate: true, allowedDuringActiveRoute: true, diagnostic: true },
@@ -73,7 +73,7 @@ export const COMMAND_MANIFEST_LITE = [
73
73
  { name: 'reasoning', summary: 'Show reasoning route', maturity: 'labs' },
74
74
  { name: 'aliases', summary: 'Show command aliases', maturity: 'stable' },
75
75
  { name: 'selftest', summary: 'Run local mock selftest', maturity: 'stable' },
76
- { name: 'goal', summary: 'Manage Goal bridge workflow', maturity: 'beta', mutatesRouteState: true },
76
+ { name: 'goal', summary: 'Print stateless Codex native Goal controls', maturity: 'beta' },
77
77
  { name: 'seo-geo-optimizer', summary: 'Run unified SEO/GEO optimizer audit/research/strategy/plan/apply/verify with optional --include-marketing on the search-visibility kernel', maturity: 'beta' },
78
78
  { name: 'hook', summary: 'Codex hook entrypoint', maturity: 'beta', skipMigrationGate: true },
79
79
  { name: 'profile', summary: 'Inspect/set profile', maturity: 'labs' },
@@ -158,7 +158,7 @@ const COMMAND_DEFINITIONS = {
158
158
  menubar: activeRouteDiagnostic(entry('beta', 'Inspect/install/restart/uninstall SKS menu bar', 'dist/core/commands/menubar-command.js', subcommand(() => import('../core/commands/menubar-command.js'), 'menubarCommand', 'dist/core/commands/menubar-command.js', 'status'))),
159
159
  remote: entry('beta', 'Inspect official Remote readiness and run the proof-aware SSH stdio worker', 'dist/core/commands/remote-command.js', argsCommand(() => import('../core/commands/remote-command.js'), 'remoteCommand', 'dist/core/commands/remote-command.js')),
160
160
  telegram: entry('beta', 'Inspect and run the private proof-aware Telegram Hub', 'dist/core/commands/telegram-command.js', argsCommand(() => import('../core/commands/telegram-command.js'), 'telegramCommand', 'dist/core/commands/telegram-command.js')),
161
- hooks: entry('beta', 'Explain and inspect Codex hooks', 'dist/commands/hooks.js', directCommand(() => import('../commands/hooks.js'), 'dist/commands/hooks.js')),
161
+ hooks: skipMigrationGate(entry('beta', 'Explain and inspect Codex hooks', 'dist/commands/hooks.js', directCommand(() => import('../commands/hooks.js'), 'dist/commands/hooks.js'))),
162
162
  'zellij-lane': entry('beta', 'Render a Zellij lane frame for SKS sessions', 'dist/commands/zellij-lane.js', directCommand(() => import('../commands/zellij-lane.js'), 'dist/commands/zellij-lane.js')),
163
163
  'zellij-slot-pane': entry('beta', 'Render a compact Zellij worker slot pane', 'dist/commands/zellij-slot-pane.js', directCommand(() => import('../commands/zellij-slot-pane.js'), 'dist/commands/zellij-slot-pane.js')),
164
164
  'zellij-monitor-pane': skipMigrationGate(readOnly(entry('beta', 'Render the live Zellij MAD/Naruto monitor pane', 'dist/commands/zellij-monitor-pane.js', directCommand(() => import('../commands/zellij-monitor-pane.js'), 'dist/commands/zellij-monitor-pane.js')))),
@@ -194,7 +194,7 @@ const COMMAND_DEFINITIONS = {
194
194
  reasoning: entry('labs', 'Show reasoning route', 'dist/core/commands/basic-cli.js', basicArgs('reasoningCommand')),
195
195
  aliases: entry('stable', 'Show command aliases', 'dist/core/commands/basic-cli.js', basicNoArgs('aliasesCommand')),
196
196
  selftest: entry('stable', 'Run local mock selftest', 'dist/core/commands/basic-cli.js', basicArgs('selftestCommand')),
197
- goal: routeStateMutator(entry('beta', 'Manage Goal bridge workflow', 'dist/core/commands/goal-command.js', subcommand(() => import('../core/commands/goal-command.js'), 'goalCommand', 'dist/core/commands/goal-command.js')), ['loop-graph-proof.json']),
197
+ goal: entry('beta', 'Print stateless Codex native Goal controls', 'dist/core/commands/goal-command.js', subcommand(() => import('../core/commands/goal-command.js'), 'goalCommand', 'dist/core/commands/goal-command.js')),
198
198
  'seo-geo-optimizer': entry('beta', 'Run unified SEO/GEO optimizer audit/plan/apply/verify on the search-visibility kernel', 'dist/core/commands/seo-command.js', argsCommand(() => import('../core/commands/seo-command.js'), 'seoGeoOptimizerCommand', 'dist/core/commands/seo-command.js')),
199
199
  hook: skipMigrationGate(entry('beta', 'Codex hook entrypoint', 'dist/commands/hook.js', directCommand(() => import('../commands/hook.js'), 'dist/commands/hook.js'))),
200
200
  profile: entry('labs', 'Inspect/set profile', 'dist/commands/profile.js', directCommand(() => import('../commands/profile.js'), 'dist/commands/profile.js')),
@@ -21,6 +21,50 @@ export function upsertCodexLbConfig(text = '', baseUrl, selectDefault = true) {
21
21
  next = upsertTomlTable(next, 'model_providers.codex-lb', block);
22
22
  return `${next.trim()}\n`;
23
23
  }
24
+ const CODEX_LB_SHARED_OPENAI_ROUTING_MARKER = '# sks-codex-lb-managed-openai-base-url';
25
+ // Codex App can retain a per-thread `model_provider = "openai"` selection even
26
+ // after the global provider changes. While SKS places the codex-lb key in the
27
+ // shared OpenAI auth store, pin the built-in provider to the same LB endpoint so
28
+ // that stale threads cannot send that key to api.openai.com. A different existing
29
+ // override is user-owned and must never be clobbered.
30
+ export function codexLbSharedOpenAiRoutingState(text = '', baseUrl = '') {
31
+ const expectedBaseUrl = normalizeCodexLbBaseUrl(baseUrl);
32
+ const configuredBaseUrl = topLevelTomlString(text, 'openai_base_url');
33
+ return {
34
+ status: !configuredBaseUrl ? 'missing' : configuredBaseUrl === expectedBaseUrl ? 'matched' : 'conflict',
35
+ expected_base_url: expectedBaseUrl,
36
+ configured_base_url: configuredBaseUrl || null,
37
+ managed: topLevelHasLine(text, CODEX_LB_SHARED_OPENAI_ROUTING_MARKER)
38
+ };
39
+ }
40
+ export function upsertCodexLbSharedOpenAiRouting(text = '', baseUrl = '') {
41
+ const state = codexLbSharedOpenAiRoutingState(text, baseUrl);
42
+ if (!state.expected_base_url)
43
+ return { ...state, routing_status: state.status, ok: false, status: 'missing_base_url', text: String(text || '') };
44
+ if (state.status === 'conflict')
45
+ return { ...state, routing_status: state.status, ok: false, status: 'conflicting_user_openai_base_url', text: String(text || '') };
46
+ if (state.status === 'matched' && state.managed) {
47
+ return { ...state, routing_status: state.status, ok: true, status: 'present', text: String(text || '') };
48
+ }
49
+ // Matched-but-unmanaged means the URL already points at codex-lb. Claim the SKS
50
+ // marker so release/unselect can remove only this activation pin later.
51
+ const withValue = state.status === 'matched'
52
+ ? String(text || '')
53
+ : upsertTopLevelTomlString(text, 'openai_base_url', state.expected_base_url);
54
+ const next = addTopLevelMarkerBeforeKey(withValue, 'openai_base_url', CODEX_LB_SHARED_OPENAI_ROUTING_MARKER);
55
+ return { ...state, routing_status: state.status, ok: true, status: 'added', text: `${next.trim()}\n`, managed: true };
56
+ }
57
+ export function removeCodexLbSharedOpenAiRouting(text = '', baseUrl = '') {
58
+ const state = codexLbSharedOpenAiRoutingState(text, baseUrl);
59
+ if (state.status !== 'matched' || !state.managed)
60
+ return { ...state, changed: false, text: String(text || '') };
61
+ const withoutValue = removeTopLevelTomlKeyIfValue(text, 'openai_base_url', state.expected_base_url);
62
+ return {
63
+ ...state,
64
+ changed: true,
65
+ text: removeTopLevelLine(withoutValue, CODEX_LB_SHARED_OPENAI_ROUTING_MARKER)
66
+ };
67
+ }
24
68
  export function upsertCodexAppGlmConfig(text = '') {
25
69
  let next = String(text || '');
26
70
  const providerBlock = [
@@ -189,3 +233,30 @@ export async function sha256Text(value = '') {
189
233
  function escapeRegExp(value) {
190
234
  return String(value).replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
191
235
  }
236
+ function topLevelTomlString(text = '', key) {
237
+ const topLevel = String(text || '').split(/\n\s*\[/)[0] || '';
238
+ return topLevel.match(new RegExp(`(^|\\n)\\s*${escapeRegExp(key)}\\s*=\\s*"([^"]+)"\\s*(?:#.*)?(?=\\n|$)`))?.[2] || '';
239
+ }
240
+ function topLevelHasLine(text = '', line) {
241
+ const topLevel = String(text || '').split(/\n\s*\[/)[0] || '';
242
+ return topLevel.split(/\r?\n/).some((candidate) => candidate.trim() === line);
243
+ }
244
+ function addTopLevelMarkerBeforeKey(text = '', key, marker) {
245
+ const lines = String(text || '').split('\n');
246
+ const firstTable = lines.findIndex((line) => /^\s*\[/.test(line));
247
+ const end = firstTable === -1 ? lines.length : firstTable;
248
+ const keyIndex = lines.slice(0, end).findIndex((line) => new RegExp(`^\\s*${escapeRegExp(key)}\\s*=`).test(line));
249
+ if (keyIndex >= 0 && !lines.slice(0, end).some((line) => line.trim() === marker))
250
+ lines.splice(keyIndex, 0, marker);
251
+ return lines.join('\n');
252
+ }
253
+ function removeTopLevelLine(text = '', target) {
254
+ const lines = String(text || '').split('\n');
255
+ const firstTable = lines.findIndex((line) => /^\s*\[/.test(line));
256
+ const end = firstTable === -1 ? lines.length : firstTable;
257
+ for (let index = end - 1; index >= 0; index -= 1) {
258
+ if (lines[index]?.trim() === target)
259
+ lines.splice(index, 1);
260
+ }
261
+ return lines.join('\n').replace(/^\n+/, '').replace(/\n{3,}/g, '\n\n');
262
+ }
@@ -234,11 +234,11 @@ export async function selftestCodexLb(tmp) {
234
234
  const codexLbReconcileRestoreJson = JSON.parse(codexLbReconcileRestoreRepair.stdout);
235
235
  const codexLbReconcileRestoreAuth = await safeReadText(path.join(codexLbHome, '.codex', 'auth.json'));
236
236
  const codexLbReconcileRestoreConfig = await safeReadText(path.join(codexLbHome, '.codex', 'config.toml'));
237
- if (codexLbReconcileRestoreJson.auth_reconcile?.status !== 'oauth_restored' || !codexLbReconcileRestoreAuth.includes('oauth-id') || codexLbReconcileRestoreAuth.includes('sk-test') || !hasTopLevelCodexLbSelected(codexLbReconcileRestoreConfig))
238
- throw new Error('selftest: codex-lb oauth restore should replace apikey auth.json with ChatGPT OAuth backup while keeping codex-lb selected');
237
+ if (codexLbReconcileRestoreJson.auth_reconcile?.status !== 'oauth_restored' || !codexLbReconcileRestoreAuth.includes('oauth-id') || codexLbReconcileRestoreAuth.includes('sk-test') || hasTopLevelCodexLbSelected(codexLbReconcileRestoreConfig) || /sks-codex-lb-managed-openai-base-url/.test(codexLbReconcileRestoreConfig))
238
+ throw new Error('selftest: codex-lb oauth restore should replace apikey auth.json with ChatGPT OAuth backup and leave an unselected, unpinned provider state');
239
239
  // codex-lb auth: release flow — restore ChatGPT OAuth from backup so the user can return to
240
- // the official ChatGPT account login. Default deselects model_provider; flags control whether
241
- // the provider stays selected and whether the backup file is removed after restore.
240
+ // the official ChatGPT account login. Default deselects model_provider; keeping codex-lb
241
+ // selected with shared OAuth is rejected because it would route OAuth credentials to the LB.
242
242
  const codexLbReleaseConfig = 'model_provider = "codex-lb"\n\n[model_providers.codex-lb]\nname = "openai"\nbase_url = "https://lb.example.test/backend-api/codex"\nwire_api = "responses"\nenv_key = "CODEX_LB_API_KEY"\nsupports_websockets = true\nrequires_openai_auth = true\n';
243
243
  const codexLbReleaseEnv = "export CODEX_LB_BASE_URL='https://lb.example.test/backend-api/codex'\nexport CODEX_LB_API_KEY='sk-test'\n";
244
244
  const codexLbReleaseApikeyAuth = '{"auth_mode":"apikey","OPENAI_API_KEY":"sk-test"}\n';
@@ -257,17 +257,16 @@ export async function selftestCodexLb(tmp) {
257
257
  const codexLbReleaseConfigAfter = await safeReadText(path.join(codexLbHome, '.codex', 'config.toml'));
258
258
  if (codexLbReleaseJson.status !== 'released' || codexLbReleaseJson.provider_unselected !== true || codexLbReleaseJson.backup_removed !== false || !codexLbReleaseAuth.includes('oauth-id') || !codexLbReleaseAuth.includes('oauth-refresh') || codexLbReleaseAuth.includes('apikey') || !codexLbReleaseBackupAfter.includes('oauth-id') || hasTopLevelCodexLbSelected(codexLbReleaseConfigAfter))
259
259
  throw new Error('selftest: codex-lb release happy path did not restore OAuth, preserve backup, and deselect model_provider');
260
- // --keep-provider: restore auth.json but leave model_provider = "codex-lb" alone.
260
+ // --keep-provider is unsafe with shared OpenAI auth and must fail without changing either file.
261
261
  await writeTextAtomic(path.join(codexLbHome, '.codex', 'auth.json'), codexLbReleaseApikeyAuth);
262
262
  await writeTextAtomic(path.join(codexLbHome, '.codex', 'auth.chatgpt-backup.json'), codexLbReleaseOauthBackup);
263
263
  await writeTextAtomic(path.join(codexLbHome, '.codex', 'config.toml'), codexLbReleaseConfig);
264
264
  const codexLbReleaseKeepRun = await runProcess(process.execPath, [packagedSksEntrypoint(), 'codex-lb', 'release', '--keep-provider', '--json'], { cwd: tmp, env: codexLbEnvForSelftest, timeoutMs: 15000, maxOutputBytes: 64 * 1024 });
265
- if (codexLbReleaseKeepRun.code !== 0)
266
- throw new Error(`selftest: codex-lb release --keep-provider exited ${codexLbReleaseKeepRun.code}: ${codexLbReleaseKeepRun.stderr}`);
267
265
  const codexLbReleaseKeepJson = JSON.parse(codexLbReleaseKeepRun.stdout);
268
266
  const codexLbReleaseKeepConfig = await safeReadText(path.join(codexLbHome, '.codex', 'config.toml'));
269
- if (codexLbReleaseKeepJson.status !== 'released' || codexLbReleaseKeepJson.provider_unselected !== false || !hasTopLevelCodexLbSelected(codexLbReleaseKeepConfig))
270
- throw new Error('selftest: codex-lb release --keep-provider should leave model_provider = "codex-lb" intact');
267
+ const codexLbReleaseKeepAuth = await safeReadText(path.join(codexLbHome, '.codex', 'auth.json'));
268
+ if (codexLbReleaseKeepRun.code === 0 || codexLbReleaseKeepJson.status !== 'failed' || codexLbReleaseKeepJson.reason !== 'keep_provider_unsafe_with_shared_auth' || !hasTopLevelCodexLbSelected(codexLbReleaseKeepConfig) || !codexLbReleaseKeepAuth.includes('apikey'))
269
+ throw new Error('selftest: codex-lb release --keep-provider should fail closed without changing the coherent codex-lb state');
271
270
  // --delete-backup: restore auth.json and remove the backup file.
272
271
  await writeTextAtomic(path.join(codexLbHome, '.codex', 'auth.json'), codexLbReleaseApikeyAuth);
273
272
  await writeTextAtomic(path.join(codexLbHome, '.codex', 'auth.chatgpt-backup.json'), codexLbReleaseOauthBackup);
@@ -288,17 +287,15 @@ export async function selftestCodexLb(tmp) {
288
287
  const codexLbReleaseMissingAuth = await safeReadText(path.join(codexLbHome, '.codex', 'auth.json'));
289
288
  if (codexLbReleaseMissingRun.code === 0 || codexLbReleaseMissingJson.status !== 'no_backup' || !codexLbReleaseMissingAuth.includes('apikey'))
290
289
  throw new Error('selftest: codex-lb release with no backup should exit non-zero and report no_backup without touching auth.json');
291
- // unselect: flip model_provider off without touching auth.json or env file.
290
+ // unselect must refuse while the shared auth store still contains the codex-lb key.
292
291
  await writeTextAtomic(path.join(codexLbHome, '.codex', 'auth.json'), codexLbReleaseApikeyAuth);
293
292
  await writeTextAtomic(path.join(codexLbHome, '.codex', 'config.toml'), codexLbReleaseConfig);
294
293
  const codexLbUnselectRun = await runProcess(process.execPath, [packagedSksEntrypoint(), 'codex-lb', 'unselect', '--json'], { cwd: tmp, env: codexLbEnvForSelftest, timeoutMs: 15000, maxOutputBytes: 64 * 1024 });
295
- if (codexLbUnselectRun.code !== 0)
296
- throw new Error(`selftest: codex-lb unselect exited ${codexLbUnselectRun.code}: ${codexLbUnselectRun.stderr}`);
297
294
  const codexLbUnselectJson = JSON.parse(codexLbUnselectRun.stdout);
298
295
  const codexLbUnselectConfig = await safeReadText(path.join(codexLbHome, '.codex', 'config.toml'));
299
296
  const codexLbUnselectAuth = await safeReadText(path.join(codexLbHome, '.codex', 'auth.json'));
300
- if (codexLbUnselectJson.status !== 'unselected' || hasTopLevelCodexLbSelected(codexLbUnselectConfig) || !codexLbUnselectConfig.includes('[model_providers.codex-lb]') || !codexLbUnselectAuth.includes('apikey'))
301
- throw new Error('selftest: codex-lb unselect should drop model_provider but preserve [model_providers.codex-lb] and auth.json');
297
+ if (codexLbUnselectRun.code === 0 || codexLbUnselectJson.status !== 'failed' || codexLbUnselectJson.reason !== 'shared_codex_lb_auth_active' || !hasTopLevelCodexLbSelected(codexLbUnselectConfig) || !codexLbUnselectAuth.includes('apikey'))
298
+ throw new Error('selftest: codex-lb unselect should fail closed while shared codex-lb auth is active');
302
299
  // Restore the doctor-test auth.json shape so downstream selftest assertions still hold.
303
300
  await writeTextAtomic(path.join(codexLbHome, '.codex', 'auth.json'), '{"auth_mode":"browser"}\n');
304
301
  await fsp.rm(path.join(codexLbHome, '.codex', 'auth.chatgpt-backup.json'), { force: true });