sneakoscope 8.0.2 → 8.0.3

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 (122) hide show
  1. package/README.md +47 -23
  2. package/config/skills-hash-ledger.v1.json +1 -1
  3. package/crates/sks-core/Cargo.lock +1 -1
  4. package/crates/sks-core/Cargo.toml +1 -1
  5. package/dist/bin/fast-inline.js +55 -13
  6. package/dist/bin/sks-dispatch.js +1 -1
  7. package/dist/cli/command-manifest-lite.js +4 -0
  8. package/dist/cli/command-registry.js +4 -0
  9. package/dist/cli/install-helpers-codex-lb-chain.js +187 -0
  10. package/dist/cli/install-helpers-codex-lb-config.js +74 -8
  11. package/dist/cli/install-helpers.js +89 -44
  12. package/dist/commands/codex-lb.js +117 -19
  13. package/dist/commands/doctor.js +697 -37
  14. package/dist/config/skills-manifest.json +3 -2
  15. package/dist/core/agents/agent-runner-codex-exec.js +5 -3
  16. package/dist/core/codex/codex-config-guard.js +238 -52
  17. package/dist/core/codex-adapter.js +5 -3
  18. package/dist/core/codex-app/menubar/constants.js +10 -1
  19. package/dist/core/codex-app/menubar/global-install.js +288 -0
  20. package/dist/core/codex-app/menubar/installer.js +79 -14
  21. package/dist/core/codex-app/menubar/launch-agent.js +267 -45
  22. package/dist/core/codex-app/menubar/paths.js +3 -0
  23. package/dist/core/codex-app/menubar/rollback.js +55 -7
  24. package/dist/core/codex-app/menubar/status.js +75 -4
  25. package/dist/core/codex-control/codex-0139-image-path-real-probe.js +3 -1
  26. package/dist/core/codex-control/codex-0139-web-search-probe.js +3 -1
  27. package/dist/core/codex-control/codex-app-server-runtime-env.js +13 -4
  28. package/dist/core/codex-control/codex-app-server-v2-client.js +3 -3
  29. package/dist/core/codex-exec-output-schema.js +4 -1
  30. package/dist/core/codex-lb/codex-lb-env.js +63 -72
  31. package/dist/core/codex-lb/codex-lb-setup.js +15 -2
  32. package/dist/core/codex-lb/desktop-center-credentials.js +517 -58
  33. package/dist/core/codex-lb/desktop-controller.js +153 -24
  34. package/dist/core/codex-lb/routing-truth.js +327 -0
  35. package/dist/core/codex-native/core-skill-manifest.js +1 -1
  36. package/dist/core/commands/basic-cli.js +7 -1
  37. package/dist/core/commands/qa-loop-command.js +3 -1
  38. package/dist/core/commands/telegram-command.js +241 -0
  39. package/dist/core/config-adopt/config-adopt-command.js +35 -0
  40. package/dist/core/config-adopt/config-adopt.js +346 -0
  41. package/dist/core/config-adopt/index.js +3 -0
  42. package/dist/core/doctor/command-alias-cleanup.js +4 -1
  43. package/dist/core/doctor/current-project-guidance-nested.js +37 -6
  44. package/dist/core/doctor/current-project-guidance.js +11 -6
  45. package/dist/core/doctor/doctor-readiness-matrix.js +14 -0
  46. package/dist/core/doctor/retired-managed-residue-private.js +1 -1
  47. package/dist/core/doctor/sks-menubar-doctor.js +4 -0
  48. package/dist/core/feature-fixtures.js +8 -0
  49. package/dist/core/hooks-runtime/hook-context.js +9 -0
  50. package/dist/core/hooks-runtime/managed-skill-admission.js +54 -4
  51. package/dist/core/hooks-runtime/official-subagent-lifecycle.js +69 -1
  52. package/dist/core/hooks-runtime/subagent-skill-availability-contract.js +2 -2
  53. package/dist/core/hooks-runtime/subagent-skill-availability-evidence.js +3 -3
  54. package/dist/core/hooks-runtime/subagent-skill-availability-guards.js +43 -5
  55. package/dist/core/hooks-runtime/subagent-skill-availability.js +64 -30
  56. package/dist/core/hooks-runtime/subagent-stop-hook.js +15 -2
  57. package/dist/core/hooks-runtime.js +148 -4
  58. package/dist/core/imagegen/imagegen-capability.js +46 -0
  59. package/dist/core/imagegen/require-imagegen.js +2 -2
  60. package/dist/core/init/skills.js +17 -3
  61. package/dist/core/install/installed-package-smoke.js +8 -2
  62. package/dist/core/naruto/hardware-capacity-probe.js +9 -3
  63. package/dist/core/naruto/naruto-concurrency-governor.js +68 -24
  64. package/dist/core/perf/import-graph-budget.js +0 -1
  65. package/dist/core/product-design-app-server.js +13 -1
  66. package/dist/core/release/package-size-budget.js +2 -2
  67. package/dist/core/release/release-pack-receipt.js +1 -2
  68. package/dist/core/routes/dollar-manifest-lite.js +1 -1
  69. package/dist/core/routes.js +1 -1
  70. package/dist/core/security/private-credential-file.js +209 -0
  71. package/dist/core/subagents/agent-catalog.js +17 -32
  72. package/dist/core/subagents/naruto-help-contract.js +5 -5
  73. package/dist/core/subagents/official-subagent-config.js +16 -6
  74. package/dist/core/subagents/official-subagent-preparation.js +34 -15
  75. package/dist/core/subagents/official-subagent-prompt.js +4 -4
  76. package/dist/core/subagents/official-subagent-runner.js +27 -4
  77. package/dist/core/subagents/thread-budget.js +19 -12
  78. package/dist/core/subagents/wave-lifecycle.js +18 -6
  79. package/dist/core/telegram/access.js +54 -0
  80. package/dist/core/telegram/client.js +144 -0
  81. package/dist/core/telegram/confirmation.js +37 -0
  82. package/dist/core/telegram/doctor.js +151 -0
  83. package/dist/core/telegram/index.js +9 -0
  84. package/dist/core/telegram/keychain.js +265 -0
  85. package/dist/core/telegram/liveness.js +109 -0
  86. package/dist/core/telegram/poller.js +90 -0
  87. package/dist/core/telegram/redaction.js +15 -0
  88. package/dist/core/telegram/types.js +1 -0
  89. package/dist/core/update/update-diagnostics.js +52 -0
  90. package/dist/core/update/update-migration-state.js +5 -1
  91. package/dist/core/update/update-operation.js +2 -1
  92. package/dist/core/update/update-stage-diagnostics.js +38 -0
  93. package/dist/core/update/update-status.js +2 -9
  94. package/dist/core/update-check.js +147 -31
  95. package/dist/core/version.js +1 -1
  96. package/dist/core/zellij/zellij-launcher.js +23 -4
  97. package/dist/native/sks-menubar/Sources/AppDelegate.swift +13 -0
  98. package/dist/native/sks-menubar/Sources/AppIdentity.swift +7 -0
  99. package/dist/native/sks-menubar/Sources/OperationCoordinator.swift +3 -2
  100. package/dist/native/sks-menubar/Sources/ProvidersConnectTest.swift +115 -0
  101. package/dist/native/sks-menubar/Sources/ProvidersFastMode.swift +17 -0
  102. package/dist/native/sks-menubar/Sources/ProvidersRoutingTruth.swift +190 -0
  103. package/dist/native/sks-menubar/Sources/ProvidersViewController.swift +100 -59
  104. package/dist/native/sks-menubar/Sources/SingletonInstanceGuard.swift +328 -0
  105. package/dist/native/sks-menubar/Sources/TelegramPrivateFileStore.swift +320 -0
  106. package/dist/native/sks-menubar/Sources/TelegramPrivateFileSupport.swift +303 -0
  107. package/dist/native/sks-menubar/Sources/TelegramProcessGateway.swift +238 -0
  108. package/dist/native/sks-menubar/Sources/TelegramRuntimeSupport.swift +56 -0
  109. package/dist/native/sks-menubar/Sources/TelegramSupport.swift +56 -0
  110. package/dist/native/sks-menubar/Sources/TelegramTransport.swift +474 -0
  111. package/dist/native/sks-menubar/Sources/main.swift +15 -1
  112. package/dist/native/sks-menubar/Tests/OperationCoordinatorTests.swift +4 -3
  113. package/dist/native/sks-menubar/Tests/ProvidersViewControllerTests.swift +129 -0
  114. package/dist/native/sks-menubar/Tests/SingletonInstanceGuardTests.swift +183 -0
  115. package/dist/native/sks-menubar/Tests/TelegramRuntimeSmokeTests.swift +267 -0
  116. package/dist/native/sks-menubar/Tests/TelegramRuntimeTests.swift +222 -0
  117. package/dist/scripts/codex-lb-fast-mode-truth-check.js +1 -1
  118. package/dist/scripts/codex-lb-fast-ui-preservation-check.js +1 -1
  119. package/dist/scripts/current-command-surface-check.js +2 -4
  120. package/dist/scripts/official-subagent-workflow-check.js +1 -1
  121. package/dist/scripts/packlist-performance-check.js +1 -2
  122. package/package.json +1 -1
@@ -4,7 +4,7 @@ import net from 'node:net';
4
4
  import os from 'node:os';
5
5
  import path from 'node:path';
6
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';
7
+ import { CODEX_LB_DESKTOP_BRIDGE_MARKER, CODEX_LB_DESKTOP_COMPAT_MARKER, CODEX_LB_MODEL_CATALOG_MARKER, CODEX_LB_PROVIDER_SELECTION_MARKER } from '../../cli/install-helpers-codex-lb-config.js';
8
8
  import { codexAuthPath, codexLbConfigPath } from '../../cli/install-helpers-codex-lb-shared.js';
9
9
  import { codexLbResponseChainCapabilityEvidence, checkCodexLbResponseChain } from '../../cli/install-helpers-codex-lb-chain.js';
10
10
  import { probeCodexLbCliImageGeneration } from './probes/cli-image-tool-probe.js';
@@ -20,6 +20,7 @@ import { detectLegacyCodexLbDesktopState, migrateLegacyCodexLbDesktop } from './
20
20
  import { syncDesktopCenterLaunchCredentials } from './desktop-center-credentials.js';
21
21
  import { backupCodexLbMigrationFile, codexLbMigrationReceiptDir, createCodexLbMigrationReceiptId, fileSha256OrMissing, finalizeCodexLbMigrationReceiptFiles, readCodexLbMigrationReceipt, rollbackCodexLbMigrationReceipt, writeCodexLbMigrationReceipt } from './migration-receipt.js';
22
22
  import { CODEX_LB_DEEP_EVIDENCE_VALIDATION_SCHEMA, parseCodexLbDeepEvidenceTrustAnchorSet, validateCodexLbDesktopDeepEvidence } from './trusted-deep-evidence.js';
23
+ import { codexLbRoutingTruthIsActive, measureAndWriteCodexLbRoutingTruth, measureCodexLbRoutingTruth, readCodexLbRoutingTruthReceipt } from './routing-truth.js';
23
24
  export const CODEX_LB_STATUS_SCHEMA_V2 = 'sks.codex-lb-status.v2';
24
25
  export const CODEX_LB_ACTIVATION_SCHEMA_V2 = 'sks.codex-lb-desktop-activation.v2';
25
26
  export function inferCodexLbDesktopModeFromConfig(text) {
@@ -51,6 +52,42 @@ export async function codexLbDesktopStatusV2(options = {}) {
51
52
  });
52
53
  const capabilityStatus = shapeCodexLbDesktopCapabilityStatus(capabilityReport);
53
54
  const provider = providerStatus(context.config, context.mode);
55
+ const selectedProvider = topLevelTomlString(context.config, 'model_provider');
56
+ const routingSelected = selectedProvider === 'codex-lb'
57
+ || context.mode === 'desktop-native-bridge';
58
+ const routingMode = context.mode === 'desktop-native-bridge'
59
+ ? 'bridge'
60
+ : 'cli-provider';
61
+ const routingAuthTransport = routingTruthAuthTransport(context.mode, context.gatewayAuthTransport);
62
+ const routingBaseUrl = context.loadedEnv.base_url;
63
+ const configuredHost = publicHost(routingBaseUrl);
64
+ const receiptOptions = {
65
+ home: context.home,
66
+ ...(options.routingTruthReceiptPath ? { receiptPath: options.routingTruthReceiptPath } : {}),
67
+ expectedMode: routingMode,
68
+ expectedSelected: routingSelected,
69
+ expectedConfiguredHost: configuredHost,
70
+ expectedAuthTransport: routingAuthTransport
71
+ };
72
+ const routingTruth = options.networkProbes === true
73
+ ? await measureAndWriteCodexLbRoutingTruth({
74
+ mode: routingMode,
75
+ selected: routingSelected,
76
+ baseUrl: routingBaseUrl,
77
+ apiKey: context.loadedEnv.secret_api_key,
78
+ authTransport: routingAuthTransport,
79
+ ...(options.fetchImpl ? { fetchImpl: options.fetchImpl } : {}),
80
+ ...(options.capabilityTimeoutMs ? { timeoutMs: options.capabilityTimeoutMs } : {})
81
+ }, receiptOptions)
82
+ : await readCodexLbRoutingTruthReceipt(receiptOptions)
83
+ || await measureCodexLbRoutingTruth({
84
+ mode: routingMode,
85
+ selected: routingSelected,
86
+ baseUrl: routingBaseUrl,
87
+ apiKey: context.loadedEnv.secret_api_key,
88
+ authTransport: routingAuthTransport,
89
+ measure: false
90
+ });
54
91
  const blockers = [
55
92
  ...context.modeBlockers,
56
93
  ...(modeRequiresChatGptOAuth(context.mode) && !context.oauthPresent
@@ -60,21 +97,26 @@ export async function codexLbDesktopStatusV2(options = {}) {
60
97
  ...(context.mode === 'desktop-native-bridge' && !context.bridge.ok
61
98
  ? context.bridge.blockers
62
99
  : []),
100
+ ...(routingSelected && !codexLbRoutingTruthIsActive(routingTruth)
101
+ ? routingTruth.blockers
102
+ : []),
63
103
  ...Object.values(capabilityStatus.blocked).flat()
64
104
  ];
65
105
  const uniqueBlockers = uniqueStrings(blockers);
66
106
  const overallBlocked = capabilityReport.overall === 'blocked'
67
107
  || capabilityReport.overall === 'unsupported';
68
- const selectedProvider = topLevelTomlString(context.config, 'model_provider');
69
- const legacyCodexLbSelected = selectedProvider === 'codex-lb';
108
+ const legacyCodexLbSelected = selectedProvider === 'codex-lb'
109
+ && !hasTopLevelLine(context.config, CODEX_LB_PROVIDER_SELECTION_MARKER);
70
110
  const credentialsReady = context.loadedEnv.configured && provider.contract_ok;
71
- const routingActive = codexLbRoutingActive({
111
+ const configuredRoutingActive = codexLbRoutingActive({
72
112
  mode: context.mode,
73
113
  configured: context.loadedEnv.configured,
74
114
  oauthPresent: context.oauthPresent,
75
115
  provider,
76
116
  bridgeRunning: context.bridge.running
77
117
  });
118
+ const routingActive = configuredRoutingActive
119
+ && codexLbRoutingTruthIsActive(routingTruth);
78
120
  const diagnosticOk = uniqueBlockers.length === 0 && !overallBlocked;
79
121
  const effectiveGatewayAuthTransport = context.mode === 'cli-provider'
80
122
  ? 'authorization-bearer'
@@ -98,6 +140,11 @@ export async function codexLbDesktopStatusV2(options = {}) {
98
140
  activation_required: credentialsReady && !routingActive,
99
141
  setup_needed: !context.loadedEnv.configured,
100
142
  mode: context.mode,
143
+ secret_resolution: {
144
+ source: context.loadedEnv.source,
145
+ path: context.loadedEnv.source === 'env-file' ? context.loadedEnv.env_paths[0] || null : null,
146
+ prompt_risk: 'none'
147
+ },
101
148
  desktop_mode: context.mode,
102
149
  chatgpt_oauth_present: context.oauthPresent,
103
150
  legacy_codex_lb_selected: legacyCodexLbSelected,
@@ -132,6 +179,7 @@ export async function codexLbDesktopStatusV2(options = {}) {
132
179
  deep_evidence_validation: capabilityReport.deep_evidence_validation,
133
180
  overall: capabilityReport.overall,
134
181
  full_capability_verified: capabilityReport.overall === 'verified',
182
+ routing_truth: routingTruth,
135
183
  blockers: uniqueBlockers,
136
184
  guidance: statusGuidance(context.mode, context.loadedEnv.configured, uniqueBlockers)
137
185
  };
@@ -241,7 +289,7 @@ export async function activateCodexLbDesktopMode(input) {
241
289
  if (bridge.running)
242
290
  throw new Error('desktop_bridge_stop_failed_during_compat_switch');
243
291
  }
244
- const centerCredentialsSynced = await syncDesktopCenterLaunchCredentials({
292
+ const centerCredentialsSynced = await (input.syncCenterCredentialsImpl || syncDesktopCenterLaunchCredentials)({
245
293
  mode: input.mode,
246
294
  home: context.home,
247
295
  loadedEnv: context.loadedEnv,
@@ -285,7 +333,7 @@ export async function activateCodexLbDesktopMode(input) {
285
333
  home: context.home,
286
334
  configPath: context.configPath,
287
335
  authPath: context.authPath,
288
- networkProbes: false,
336
+ networkProbes: true,
289
337
  deepEvidence: null
290
338
  });
291
339
  const postcondition = codexLbActivationPostcondition(postActivationStatus, input.mode);
@@ -402,7 +450,7 @@ export async function disableCodexLbDesktopRouting(input = {}) {
402
450
  if (bridge.running || !bridge.ok) {
403
451
  throw new Error(bridge.blockers[0] || 'desktop_bridge_cleanup_failed');
404
452
  }
405
- const centerCredentials = await syncDesktopCenterLaunchCredentials({
453
+ const centerCredentials = await (input.syncCenterCredentialsImpl || syncDesktopCenterLaunchCredentials)({
406
454
  mode: 'disabled',
407
455
  home: context.home,
408
456
  loadedEnv: context.loadedEnv,
@@ -488,32 +536,92 @@ export async function disableCodexLbDesktopRouting(input = {}) {
488
536
  }
489
537
  export async function configureCodexLbCliMode(input = {}) {
490
538
  const context = await loadDesktopContext(input);
491
- if (!context.loadedEnv.base_url) {
539
+ const selectedBefore = topLevelTomlString(context.config, 'model_provider') === 'codex-lb';
540
+ const routingTruth = await measureAndWriteCodexLbRoutingTruth({
541
+ mode: 'cli-provider',
542
+ selected: true,
543
+ baseUrl: context.loadedEnv.base_url,
544
+ apiKey: context.loadedEnv.secret_api_key,
545
+ authTransport: 'authorization-bearer',
546
+ ...(input.fetchImpl ? { fetchImpl: input.fetchImpl } : {}),
547
+ ...(input.capabilityTimeoutMs ? { timeoutMs: input.capabilityTimeoutMs } : {})
548
+ }, {
549
+ home: context.home,
550
+ ...(input.routingTruthReceiptPath ? { receiptPath: input.routingTruthReceiptPath } : {})
551
+ });
552
+ if (!codexLbRoutingTruthIsActive(routingTruth)) {
492
553
  return {
493
554
  schema: 'sks.codex-lb-cli-mode.v2',
494
555
  ok: false,
495
- status: 'missing_remote_base_url',
556
+ status: routingTruth.status,
496
557
  mode: 'cli-provider',
497
558
  oauth_preserved: true,
498
- blockers: ['codex_lb_missing:CODEX_LB_BASE_URL']
559
+ routing_active: false,
560
+ fail_closed: selectedBefore,
561
+ fallback_provider_selected: false,
562
+ routing_truth: routingTruth,
563
+ blockers: routingTruth.blockers
499
564
  };
500
565
  }
501
566
  const result = await configureCodexLbCliProvider({
502
567
  home: context.home,
503
568
  configPath: context.configPath,
504
569
  authPath: context.authPath,
505
- remoteBaseUrl: context.loadedEnv.base_url,
506
- selectGlobally: false
570
+ remoteBaseUrl: String(context.loadedEnv.base_url),
571
+ selectGlobally: true
507
572
  });
573
+ if (!result.ok) {
574
+ return {
575
+ ...result,
576
+ schema: 'sks.codex-lb-cli-mode.v2',
577
+ provider_ready: false,
578
+ routing_active: false,
579
+ activation_required: true,
580
+ command: 'codex',
581
+ global_desktop_selection_changed: false,
582
+ fail_closed: selectedBefore,
583
+ fallback_provider_selected: false,
584
+ center_credentials: null,
585
+ routing_truth: routingTruth
586
+ };
587
+ }
588
+ const centerCredentials = await (input.syncCenterCredentialsImpl || syncDesktopCenterLaunchCredentials)({
589
+ mode: 'cli-provider',
590
+ home: context.home,
591
+ loadedEnv: context.loadedEnv,
592
+ ...(input.platform ? { platform: input.platform } : {})
593
+ });
594
+ if (!centerCredentials.ok) {
595
+ return {
596
+ ...result,
597
+ schema: 'sks.codex-lb-cli-mode.v2',
598
+ ok: false,
599
+ status: centerCredentials.status,
600
+ provider_ready: true,
601
+ routing_active: true,
602
+ activation_required: true,
603
+ command: 'codex',
604
+ global_desktop_selection_changed: !selectedBefore,
605
+ fail_closed: true,
606
+ fallback_provider_selected: false,
607
+ center_credentials: centerCredentials,
608
+ routing_truth: routingTruth,
609
+ blockers: uniqueStrings(centerCredentials.blockers)
610
+ };
611
+ }
508
612
  return {
509
613
  ...result,
510
614
  schema: 'sks.codex-lb-cli-mode.v2',
511
- status: result.ok ? 'ready_unselected' : result.status,
615
+ status: result.ok ? 'active' : result.status,
512
616
  provider_ready: result.ok,
513
- routing_active: false,
514
- activation_required: result.ok,
515
- command: `codex --config model_provider='"codex-lb"'`,
516
- global_desktop_selection_changed: false
617
+ routing_active: result.ok,
618
+ activation_required: false,
619
+ command: 'codex',
620
+ global_desktop_selection_changed: result.ok && !selectedBefore,
621
+ fail_closed: result.ok,
622
+ fallback_provider_selected: false,
623
+ center_credentials: centerCredentials,
624
+ routing_truth: routingTruth
517
625
  };
518
626
  }
519
627
  export function codexLbActivationPostcondition(status, expectedMode) {
@@ -1042,7 +1150,8 @@ async function loadDesktopContext(options) {
1042
1150
  modeBlockers.push('codex_lb_gateway_auth_transport_invalid');
1043
1151
  }
1044
1152
  if (topLevelTomlString(config, 'model_provider') === 'codex-lb'
1045
- && !hasTopLevelLine(config, CODEX_LB_DESKTOP_COMPAT_MARKER)) {
1153
+ && !hasTopLevelLine(config, CODEX_LB_DESKTOP_COMPAT_MARKER)
1154
+ && !hasTopLevelLine(config, CODEX_LB_PROVIDER_SELECTION_MARKER)) {
1046
1155
  modeBlockers.push('legacy_codex_lb_desktop_config_requires_migration');
1047
1156
  }
1048
1157
  if (legacy.legacy_destructive_mode) {
@@ -1092,11 +1201,11 @@ function providerStatus(config, mode) {
1092
1201
  && hasTomlBoolean(provider, 'supports_websockets', true);
1093
1202
  if (mode === 'cli-provider') {
1094
1203
  return {
1095
- id: 'openai',
1096
- built_in: true,
1204
+ id: selected === 'codex-lb' ? 'codex-lb' : 'openai',
1205
+ built_in: selected !== 'codex-lb',
1097
1206
  contract: provider ? 'codex-lb-cli' : 'missing',
1098
1207
  contract_ok: cliContractOk,
1099
- selected: selected !== 'codex-lb'
1208
+ selected: selected === 'codex-lb'
1100
1209
  };
1101
1210
  }
1102
1211
  return {
@@ -1531,8 +1640,10 @@ function redactRemoteOrigin(baseUrl) {
1531
1640
  function statusGuidance(mode, configured, blockers) {
1532
1641
  if (!configured) {
1533
1642
  return [
1534
- 'Run: sks codex-lb setup --host <domain> --api-key-stdin --yes --desktop-mode cli-provider',
1535
- 'Then choose Desktop routing explicitly with: sks codex-lb use-desktop-full'
1643
+ 'Store the key in ~/.codex/sks-codex-lb.env (owner-only mode 0600).',
1644
+ 'Run: sks codex-lb setup --host <domain> --api-key-stdin --yes',
1645
+ 'Alternatively, provide CODEX_LB_API_KEY in the launching environment.',
1646
+ 'Then activate the atomic CLI provider with: sks codex-lb use-cli'
1536
1647
  ];
1537
1648
  }
1538
1649
  if (blockers.includes('legacy_codex_lb_desktop_config_requires_migration')) {
@@ -1560,12 +1671,16 @@ function statusGuidance(mode, configured, blockers) {
1560
1671
  }
1561
1672
  return [
1562
1673
  'Desktop remains on built-in OpenAI/ChatGPT OAuth.',
1563
- 'Enable routing explicitly with: sks codex-lb use-desktop-full'
1674
+ 'Activate the atomic CLI provider with: sks codex-lb use-cli',
1675
+ 'Advanced bridge mode (keeps ChatGPT sign-in): sks codex-lb use-desktop-full'
1564
1676
  ];
1565
1677
  }
1566
1678
  function codexLbRoutingActive(input) {
1567
1679
  if (!input.configured)
1568
1680
  return false;
1681
+ if (input.mode === 'cli-provider') {
1682
+ return input.provider.contract_ok && input.provider.selected;
1683
+ }
1569
1684
  if (input.mode === 'desktop-native-bridge') {
1570
1685
  return input.oauthPresent
1571
1686
  && input.provider.contract_ok
@@ -1590,3 +1705,17 @@ function isRecord(value) {
1590
1705
  function desktopCompatModeUnavailable(mode) {
1591
1706
  return mode === 'desktop-dual-auth-compat';
1592
1707
  }
1708
+ function routingTruthAuthTransport(mode, gatewayAuthTransport) {
1709
+ if (mode === 'desktop-native-bridge' && gatewayAuthTransport === 'x-codex-lb-api-key') {
1710
+ return 'x-codex-lb-api-key';
1711
+ }
1712
+ return 'authorization-bearer';
1713
+ }
1714
+ function publicHost(baseUrl) {
1715
+ try {
1716
+ return baseUrl ? new URL(baseUrl).host : null;
1717
+ }
1718
+ catch {
1719
+ return null;
1720
+ }
1721
+ }
@@ -0,0 +1,327 @@
1
+ import os from 'node:os';
2
+ import path from 'node:path';
3
+ import { readJson, writeJsonAtomic } from '../fsx.js';
4
+ import { codexLbBaseUrlSecurityBlocker, normalizeCodexLbBaseUrl } from './codex-lb-env.js';
5
+ export const CODEX_LB_ROUTING_TRUTH_SCHEMA = 'sks.codex-lb-routing-truth.v1';
6
+ export const CODEX_LB_ROUTING_TRUTH_RECEIPT = 'sks-codex-lb-routing-truth.json';
7
+ export const CODEX_LB_ROUTING_TRUTH_STAMP = CODEX_LB_ROUTING_TRUTH_RECEIPT;
8
+ export const CODEX_LB_ROUTING_TRUTH_STALE_AFTER_MS = 5 * 60 * 1_000;
9
+ export function codexLbRoutingTruthReceiptPath(home = process.env.HOME || os.homedir()) {
10
+ return path.join(home, '.codex', CODEX_LB_ROUTING_TRUTH_RECEIPT);
11
+ }
12
+ export const codexLbRoutingTruthStampPath = codexLbRoutingTruthReceiptPath;
13
+ export async function measureCodexLbRoutingTruth(options) {
14
+ const now = options.now || Date.now;
15
+ const measuredAt = options.nowIso?.() || new Date(now()).toISOString();
16
+ const baseUrl = normalizeCodexLbBaseUrl(options.baseUrl || '');
17
+ const configured = safePublicUrl(baseUrl);
18
+ const mode = options.mode || 'cli-provider';
19
+ const probeBaseUrl = normalizeCodexLbBaseUrl(options.probeBaseUrl || '');
20
+ const bridgeLoopbackProbe = Boolean(probeBaseUrl);
21
+ const authTransport = options.authTransport || 'authorization-bearer';
22
+ const base = {
23
+ schema: CODEX_LB_ROUTING_TRUTH_SCHEMA,
24
+ mode,
25
+ selected: options.selected,
26
+ fresh: false,
27
+ stale_after_ms: CODEX_LB_ROUTING_TRUTH_STALE_AFTER_MS,
28
+ age_ms: 0,
29
+ configured_base_url: configured?.url || null,
30
+ configured_host: configured?.host || null,
31
+ actual_url: null,
32
+ actual_host: null,
33
+ measurement_path: bridgeLoopbackProbe ? 'bridge-loopback' : 'direct',
34
+ auth_transport: authTransport,
35
+ http_status: null,
36
+ measured_at: measuredAt,
37
+ checked_at: measuredAt,
38
+ latency_ms: null
39
+ };
40
+ if (!baseUrl) {
41
+ return {
42
+ ...base,
43
+ ok: false,
44
+ status: 'missing_base_url',
45
+ measured: false,
46
+ auth_outcome: 'not_attempted',
47
+ blockers: ['codex_lb_missing:CODEX_LB_BASE_URL']
48
+ };
49
+ }
50
+ const transportBlocker = codexLbBaseUrlSecurityBlocker(baseUrl);
51
+ if (transportBlocker) {
52
+ return {
53
+ ...base,
54
+ ok: false,
55
+ status: 'transport_blocked',
56
+ measured: false,
57
+ auth_outcome: 'not_attempted',
58
+ blockers: [transportBlocker]
59
+ };
60
+ }
61
+ if (bridgeLoopbackProbe && (mode !== 'bridge' || !isHttpLoopbackUrl(probeBaseUrl))) {
62
+ return {
63
+ ...base,
64
+ ok: false,
65
+ status: 'transport_blocked',
66
+ measured: false,
67
+ auth_outcome: 'not_attempted',
68
+ blockers: ['codex_lb_bridge_probe_target_not_loopback']
69
+ };
70
+ }
71
+ const apiKey = String(options.apiKey || '').trim();
72
+ if (!apiKey) {
73
+ return {
74
+ ...base,
75
+ ok: false,
76
+ status: 'missing_api_key',
77
+ measured: false,
78
+ auth_outcome: 'not_attempted',
79
+ blockers: ['codex_lb_missing:CODEX_LB_API_KEY']
80
+ };
81
+ }
82
+ if (options.measure === false) {
83
+ return {
84
+ ...base,
85
+ ok: !options.selected,
86
+ status: options.selected ? 'selected_unmeasured' : 'ready_unselected',
87
+ measured: false,
88
+ auth_outcome: 'not_attempted',
89
+ blockers: options.selected ? ['codex_lb_routing_truth_unmeasured'] : []
90
+ };
91
+ }
92
+ if (!options.selected) {
93
+ return {
94
+ ...base,
95
+ ok: true,
96
+ status: 'ready_unselected',
97
+ measured: false,
98
+ auth_outcome: 'not_attempted',
99
+ blockers: []
100
+ };
101
+ }
102
+ const measurementBaseUrl = bridgeLoopbackProbe ? probeBaseUrl : baseUrl;
103
+ const measurementTarget = safePublicUrl(measurementBaseUrl);
104
+ const endpoint = `${measurementBaseUrl.replace(/\/+$/, '')}/models`;
105
+ const startedAt = now();
106
+ try {
107
+ const headers = authTransport === 'x-codex-lb-api-key'
108
+ ? { 'X-Codex-LB-API-Key': apiKey }
109
+ : { Authorization: `Bearer ${apiKey}` };
110
+ const response = await (options.fetchImpl || globalThis.fetch)(endpoint, {
111
+ method: 'GET',
112
+ headers,
113
+ redirect: 'error',
114
+ signal: AbortSignal.timeout(Math.max(250, Number(options.timeoutMs || 8_000)))
115
+ });
116
+ const finishedAt = now();
117
+ const actual = safePublicUrl(response.url || endpoint);
118
+ const authRejected = response.status === 401 || response.status === 403;
119
+ const ok = response.ok && !authRejected && actual?.host === measurementTarget?.host;
120
+ const status = authRejected
121
+ ? 'auth_rejected'
122
+ : response.ok && actual?.host !== measurementTarget?.host
123
+ ? 'endpoint_unreachable'
124
+ : response.ok
125
+ ? 'verified'
126
+ : 'http_error';
127
+ return {
128
+ ...base,
129
+ ok,
130
+ status,
131
+ measured: true,
132
+ fresh: true,
133
+ actual_url: actual?.url || null,
134
+ actual_host: actual?.host || null,
135
+ auth_outcome: authRejected ? 'rejected' : response.ok ? 'accepted' : 'indeterminate',
136
+ http_status: response.status,
137
+ latency_ms: Math.max(0, finishedAt - startedAt),
138
+ blockers: ok
139
+ ? []
140
+ : [authRejected
141
+ ? 'codex_lb_auth_rejected'
142
+ : response.ok
143
+ ? 'codex_lb_actual_host_mismatch'
144
+ : `codex_lb_models_http_${response.status}`]
145
+ };
146
+ }
147
+ catch {
148
+ const finishedAt = now();
149
+ return {
150
+ ...base,
151
+ ok: false,
152
+ status: 'endpoint_unreachable',
153
+ measured: true,
154
+ fresh: true,
155
+ auth_outcome: 'indeterminate',
156
+ latency_ms: Math.max(0, finishedAt - startedAt),
157
+ blockers: ['codex_lb_endpoint_unreachable']
158
+ };
159
+ }
160
+ }
161
+ export async function writeCodexLbRoutingTruthReceipt(truth, options = {}) {
162
+ const receiptPath = options.receiptPath || codexLbRoutingTruthReceiptPath(options.home);
163
+ const canonical = parseReceipt(truth);
164
+ if (!canonical)
165
+ throw new Error('codex_lb_routing_truth_invalid');
166
+ await writeJsonAtomic(receiptPath, canonical, { mode: 0o600 });
167
+ return canonical;
168
+ }
169
+ export async function readCodexLbRoutingTruthReceipt(options = {}) {
170
+ const receiptPath = options.receiptPath || codexLbRoutingTruthReceiptPath(options.home);
171
+ const parsed = parseReceipt(await readJson(receiptPath, null));
172
+ if (!parsed)
173
+ return null;
174
+ if (options.expectedMode !== undefined && parsed.mode !== options.expectedMode)
175
+ return null;
176
+ if (options.expectedSelected !== undefined && parsed.selected !== options.expectedSelected)
177
+ return null;
178
+ if (options.expectedConfiguredHost !== undefined
179
+ && parsed.configured_host !== options.expectedConfiguredHost)
180
+ return null;
181
+ if (options.expectedAuthTransport !== undefined
182
+ && parsed.auth_transport !== options.expectedAuthTransport)
183
+ return null;
184
+ return withFreshness(parsed, options);
185
+ }
186
+ export async function readFreshCodexLbRoutingTruthStamp(options = {}) {
187
+ const truth = await readCodexLbRoutingTruthReceipt(options);
188
+ return truth?.measured === true && truth.fresh === true ? truth : null;
189
+ }
190
+ export const writeCodexLbRoutingTruthStamp = writeCodexLbRoutingTruthReceipt;
191
+ export const readCodexLbRoutingTruthStamp = readCodexLbRoutingTruthReceipt;
192
+ export async function measureAndWriteCodexLbRoutingTruth(measureOptions, receiptOptions = {}) {
193
+ const truth = await measureCodexLbRoutingTruth(measureOptions);
194
+ try {
195
+ return await writeCodexLbRoutingTruthReceipt(truth, receiptOptions);
196
+ }
197
+ catch {
198
+ if (!truth.selected)
199
+ return truth;
200
+ return {
201
+ ...truth,
202
+ ok: false,
203
+ status: 'receipt_write_failed',
204
+ observed_status: truth.status,
205
+ blockers: uniqueStrings([...truth.blockers, 'codex_lb_routing_truth_receipt_write_failed'])
206
+ };
207
+ }
208
+ }
209
+ export function codexLbRoutingTruthIsActive(truth) {
210
+ return truth?.selected === true
211
+ && truth.measured === true
212
+ && truth.fresh === true
213
+ && truth.ok === true
214
+ && truth.status === 'verified';
215
+ }
216
+ function withFreshness(truth, options) {
217
+ const nowMs = (options.now || Date.now)();
218
+ const measuredMs = Date.parse(truth.measured_at);
219
+ const staleAfterMs = Math.max(1_000, Number(options.staleAfterMs || CODEX_LB_ROUTING_TRUTH_STALE_AFTER_MS));
220
+ const ageMs = Number.isFinite(measuredMs) ? Math.max(0, nowMs - measuredMs) : Number.POSITIVE_INFINITY;
221
+ const fresh = truth.measured && Number.isFinite(ageMs) && ageMs <= staleAfterMs;
222
+ if (fresh || !truth.selected) {
223
+ return { ...truth, fresh, stale_after_ms: staleAfterMs, age_ms: Number.isFinite(ageMs) ? ageMs : null };
224
+ }
225
+ return {
226
+ ...truth,
227
+ ok: false,
228
+ status: 'stale',
229
+ observed_status: truth.status,
230
+ fresh: false,
231
+ stale_after_ms: staleAfterMs,
232
+ age_ms: Number.isFinite(ageMs) ? ageMs : null,
233
+ blockers: uniqueStrings([...truth.blockers, 'codex_lb_routing_truth_stale'])
234
+ };
235
+ }
236
+ function parseReceipt(value) {
237
+ if (!value || typeof value !== 'object' || Array.isArray(value))
238
+ return null;
239
+ const input = value;
240
+ if (input.schema !== CODEX_LB_ROUTING_TRUTH_SCHEMA)
241
+ return null;
242
+ const status = String(input.status || '');
243
+ const statuses = [
244
+ 'verified', 'selected_unmeasured', 'ready_unselected', 'missing_base_url', 'missing_api_key',
245
+ 'transport_blocked', 'endpoint_unreachable', 'auth_rejected', 'http_error', 'stale',
246
+ 'receipt_write_failed'
247
+ ];
248
+ const authTransport = String(input.auth_transport || '');
249
+ const mode = String(input.mode || 'cli-provider');
250
+ const authOutcome = String(input.auth_outcome || '');
251
+ const measuredAt = stringOrNull(input.measured_at) || stringOrNull(input.checked_at);
252
+ if (!statuses.includes(status)
253
+ || !['bridge', 'cli-provider'].includes(mode)
254
+ || !['authorization-bearer', 'x-codex-lb-api-key'].includes(authTransport)
255
+ || !['accepted', 'rejected', 'not_attempted', 'indeterminate'].includes(authOutcome)
256
+ || !measuredAt
257
+ || !Array.isArray(input.blockers))
258
+ return null;
259
+ return {
260
+ schema: CODEX_LB_ROUTING_TRUTH_SCHEMA,
261
+ ok: input.ok === true,
262
+ status,
263
+ ...(typeof input.observed_status === 'string'
264
+ ? { observed_status: input.observed_status }
265
+ : {}),
266
+ mode,
267
+ selected: input.selected === true,
268
+ measured: input.measured === true,
269
+ fresh: input.fresh === true,
270
+ stale_after_ms: finiteNumberOrNull(input.stale_after_ms) || CODEX_LB_ROUTING_TRUTH_STALE_AFTER_MS,
271
+ age_ms: finiteNumberOrNull(input.age_ms),
272
+ configured_base_url: safeReceiptUrl(input.configured_base_url),
273
+ configured_host: stringOrNull(input.configured_host),
274
+ actual_url: safeReceiptUrl(input.actual_url),
275
+ actual_host: stringOrNull(input.actual_host),
276
+ measurement_path: input.measurement_path === 'bridge-loopback'
277
+ ? 'bridge-loopback'
278
+ : 'direct',
279
+ auth_transport: authTransport,
280
+ auth_outcome: authOutcome,
281
+ http_status: finiteNumberOrNull(input.http_status),
282
+ measured_at: measuredAt,
283
+ checked_at: measuredAt,
284
+ latency_ms: finiteNumberOrNull(input.latency_ms),
285
+ blockers: uniqueStrings(input.blockers.map(String))
286
+ };
287
+ }
288
+ function safeReceiptUrl(input) {
289
+ if (typeof input !== 'string')
290
+ return null;
291
+ return safePublicUrl(input)?.url || null;
292
+ }
293
+ function stringOrNull(input) {
294
+ return typeof input === 'string' && input ? input : null;
295
+ }
296
+ function finiteNumberOrNull(input) {
297
+ return typeof input === 'number' && Number.isFinite(input) && input >= 0 ? input : null;
298
+ }
299
+ function uniqueStrings(values) {
300
+ return [...new Set(values.filter(Boolean))];
301
+ }
302
+ function safePublicUrl(input) {
303
+ try {
304
+ const parsed = new URL(input);
305
+ parsed.username = '';
306
+ parsed.password = '';
307
+ parsed.search = '';
308
+ parsed.hash = '';
309
+ return {
310
+ url: parsed.toString().replace(/\/$/, ''),
311
+ host: parsed.host
312
+ };
313
+ }
314
+ catch {
315
+ return null;
316
+ }
317
+ }
318
+ function isHttpLoopbackUrl(input) {
319
+ try {
320
+ const parsed = new URL(input);
321
+ return parsed.protocol === 'http:'
322
+ && (parsed.hostname === '127.0.0.1' || parsed.hostname === '::1');
323
+ }
324
+ catch {
325
+ return false;
326
+ }
327
+ }
@@ -24,7 +24,7 @@ const CORE_SKILL_DEFINITIONS = [
24
24
  route: '$Naruto',
25
25
  purpose: 'run a Codex official subagent workflow with official agent threads while parent integration remains owner.',
26
26
  when: 'Use when the user explicitly invokes $Naruto or the selected route requires bounded parallel delegation.',
27
- workflow: 'Run sks naruto run "<task>" [--agents N] [--max-threads N] [--json] with Codex official subagent threads only. The parent owns decomposition, per-wave capacity, later root-owned waves, integration, and final verification. Automatic targets begin at 4/6/8/16 by task size: bounded, explicit parallel, large-scale, then mass cheap-model fan-out on the Luna/Terra lanes. Normal expansion ceilings at 12, while mass-lane expansion ceilings at 64 when independent useful slices and healthy host capacity remain positive; max_threads defaults to a 12-thread frame budget cap, never a target, the absolute hard frame cap is 256, and multi-wave scheduling reuses capacity for requested counts beyond the first wave. Route tiny mechanical and mass shards to Luna Max, broad search and exploration shards to Terra Medium, and implementation or judgment to Sol; max_depth=1 blocks nested delegation. Wait for every planned thread before final. In an active Codex App Naruto mission, commit the strict parent evidence with sks naruto parent-summary --mission <id> --stdin, then return localized Markdown without exposing the JSON.',
27
+ workflow: 'Run sks naruto run "<task>" [--agents N] [--max-threads N] [--json] with Codex official subagent threads only. The parent owns decomposition, per-wave capacity, later root-owned waves, integration, and final verification. Automatic targets begin at 4/6/8/16 by task size: bounded, explicit parallel, large-scale, then mass cheap-model fan-out on the Luna/Terra lanes. After decomposition both lanes may expand to the SKS-owned 256-child ceiling when independent useful slices and real host capacity remain positive; max_threads defaults to a 256-child frame budget cap, never a target. A measured lower Codex host cap or explicit provider/API budget remains authoritative, and multi-wave scheduling reuses returned capacity. Route tiny mechanical and mass shards to Luna Max, broad search and exploration shards to Terra Medium, and implementation or judgment to Sol; max_depth=1 blocks nested delegation. Wait for every planned thread before final. In an active Codex App Naruto mission, commit the strict parent evidence with sks naruto parent-summary --mission <id> --stdin, then return localized Markdown without exposing the JSON.',
28
28
  safety: 'Preserve user-authored content, inherit the parent permission mode, do not spawn nested subagents, do not inject the full pack or the full TriWiki context into every child, and do not fall back to another model, process runtime, custom scheduler, or worker pool. The historical Naruto process runtime is removed; stop with explicit blocker evidence when the official path is unavailable.',
29
29
  cli: 'sks naruto run "<task>" [--agents N] [--max-threads N] [--json]; sks naruto status|subagents|proof [--mission <id>] [--json]; sks naruto parent-summary --mission <id> --stdin [--json]',
30
30
  evidence: 'subagent-plan.json, subagent-events.jsonl, subagent-parent-summary.json, subagent-evidence.json, naruto-summary.json, and naruto-gate.json.',