sneakoscope 7.1.0 → 7.3.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 (534) hide show
  1. package/README.md +9 -1
  2. package/config/architecture-budgets.v1.json +1 -8
  3. package/crates/sks-core/Cargo.lock +225 -1
  4. package/crates/sks-core/Cargo.toml +8 -1
  5. package/crates/sks-core/src/main.rs +7 -1
  6. package/crates/sks-core/src/search/files.rs +114 -0
  7. package/crates/sks-core/src/search/mod.rs +274 -0
  8. package/crates/sks-core/src/search/text.rs +175 -0
  9. package/dist/bin/sks-dispatch.js +4 -3
  10. package/dist/cli/command-manifest-lite.js +177 -6
  11. package/dist/cli/command-registry.js +42 -8
  12. package/dist/cli/help.js +30 -0
  13. package/dist/cli/install-helpers-codex-lb-config.js +9 -6
  14. package/dist/cli/install-helpers-codex-lb-selftest-chain.js +1 -1
  15. package/dist/cli/install-helpers-install-support.js +1 -1
  16. package/dist/cli/install-helpers.js +19 -9
  17. package/dist/cli/router.js +16 -3
  18. package/dist/commands/codex-app.js +40 -5
  19. package/dist/commands/doctor-profile.js +78 -0
  20. package/dist/commands/doctor.js +29 -69
  21. package/dist/commands/search.js +4 -0
  22. package/dist/config/skills-manifest.json +53 -60
  23. package/dist/core/agent-bridge/agent-manifest.js +22 -26
  24. package/dist/core/agent-bridge/host-capability-policy.js +109 -8
  25. package/dist/core/agent-bridge/host-capability-runtime.js +178 -50
  26. package/dist/core/agent-guidance/directive-registry.js +123 -0
  27. package/dist/core/agents/agent-effort-policy.js +45 -6
  28. package/dist/core/agents/agent-worker-pipeline.js +1 -3
  29. package/dist/core/agents/native-worker-backend-router.js +43 -19
  30. package/dist/core/auto-review.js +1 -3
  31. package/dist/core/code-structure.js +282 -19
  32. package/dist/core/codex/codex-config-guard.js +14 -4
  33. package/dist/core/codex/codex-config-toml.js +1 -3
  34. package/dist/core/codex-app/codex-agent-role-sync.js +1 -3
  35. package/dist/core/codex-app/codex-app-fast-ui-repair.js +14 -1
  36. package/dist/core/codex-app/codex-app-types.js +2 -3
  37. package/dist/core/codex-app/codex-desktop-routing-ownership.js +91 -0
  38. package/dist/core/codex-app/codex-hook-approval-probe.js +1 -3
  39. package/dist/core/codex-app/codex-hook-lifecycle.js +1 -3
  40. package/dist/core/codex-app/codex-init-deep.js +22 -10
  41. package/dist/core/codex-app/codex-model-catalog.js +384 -0
  42. package/dist/core/codex-app/codex-models-cache.js +160 -0
  43. package/dist/core/codex-app/desktop-routing-snapshot.js +233 -0
  44. package/dist/core/codex-app/glm-profile-installer.js +1 -3
  45. package/dist/core/codex-app/mcp-manager.js +1 -3
  46. package/dist/core/codex-app/menubar/constants.js +3 -0
  47. package/dist/core/codex-app/menubar/installer.js +11 -1
  48. package/dist/core/codex-app/multi-provider-router-support.js +202 -0
  49. package/dist/core/codex-app/multi-provider-router.js +379 -0
  50. package/dist/core/codex-app/openrouter-activate.js +189 -26
  51. package/dist/core/codex-app/openrouter-base-instructions.js +1 -0
  52. package/dist/core/codex-app/openrouter-model-catalog.js +217 -0
  53. package/dist/core/codex-app/role-model-catalog-priority.js +61 -0
  54. package/dist/core/codex-app.js +30 -6
  55. package/dist/core/codex-compat/codex-hook-semantic-validator.js +1 -3
  56. package/dist/core/codex-control/codex-app-server-v2-client.js +39 -2
  57. package/dist/core/codex-lb/codex-lb-env.js +1 -3
  58. package/dist/core/codex-lb/codex-lb-tool-catalog.js +6 -1
  59. package/dist/core/codex-native/codex-native-feature-broker.js +2 -6
  60. package/dist/core/codex-native/codex-native-interop-policy.js +1 -3
  61. package/dist/core/codex-native/codex-native-reference-cache.js +1 -3
  62. package/dist/core/codex-native/codex-native-reference-source.js +1 -3
  63. package/dist/core/codex-native/codex-native-repair-transaction.js +1 -3
  64. package/dist/core/codex-native/core-skill-manifest.js +3 -2
  65. package/dist/core/codex-native/native-capability-repair-matrix.js +1 -3
  66. package/dist/core/codex-plugins/codex-plugin-repair.js +1 -3
  67. package/dist/core/codex-runtime/codex-desktop-config-policy.js +4 -4
  68. package/dist/core/commands/agent-bridge-command.js +24 -3
  69. package/dist/core/commands/image-ux-review-command.js +5 -11
  70. package/dist/core/commands/menubar-command.js +1 -1
  71. package/dist/core/commands/naruto-command.js +40 -13
  72. package/dist/core/commands/pipeline-command.js +5 -2
  73. package/dist/core/commands/release-command.js +63 -1
  74. package/dist/core/commands/remote-command.js +18 -0
  75. package/dist/core/commands/search-command.js +151 -0
  76. package/dist/core/commands/telegram-command.js +251 -108
  77. package/dist/core/commands/uninstall-command.js +1 -1
  78. package/dist/core/config/secret-preservation.js +1 -3
  79. package/dist/core/context7-client.js +2 -1
  80. package/dist/core/db-review.js +704 -0
  81. package/dist/core/db-safety.js +17 -23
  82. package/dist/core/doctor/browser-use-repair.js +1 -3
  83. package/dist/core/doctor/codex-startup-config-repair.js +1 -3
  84. package/dist/core/doctor/computer-use-repair.js +1 -3
  85. package/dist/core/doctor/context7-mcp-repair.js +1 -3
  86. package/dist/core/doctor/current-project-guidance.js +1 -3
  87. package/dist/core/doctor/doctor-codex-startup-repair.js +1 -3
  88. package/dist/core/doctor/doctor-dirty-planner.js +2 -2
  89. package/dist/core/doctor/doctor-native-capability-repair.js +1 -3
  90. package/dist/core/doctor/doctor-transaction.js +1 -3
  91. package/dist/core/doctor/imagegen-repair.js +1 -3
  92. package/dist/core/doctor/legacy-global-hook-cleanup.js +1 -3
  93. package/dist/core/doctor/mcp-transport-collision-repair.js +1 -3
  94. package/dist/core/doctor/retired-managed-residue-private.js +1 -3
  95. package/dist/core/doctor/supabase-mcp-repair.js +1 -3
  96. package/dist/core/engineering-sanity-review.js +186 -0
  97. package/dist/core/errors/message.js +3 -0
  98. package/dist/core/evidence/evidence-schema.js +1 -3
  99. package/dist/core/feature-fixtures.js +1 -0
  100. package/dist/core/feature-registry.js +1 -3
  101. package/dist/core/fsx.js +13 -0
  102. package/dist/core/git-hygiene/shared-memory-publish.js +1 -3
  103. package/dist/core/git-hygiene/validators.js +1 -3
  104. package/dist/core/harness-guard.js +21 -3
  105. package/dist/core/hooks-runtime/hook-context.js +2 -2
  106. package/dist/core/image-ux-review/imagegen-adapter.js +52 -56
  107. package/dist/core/image-ux-review/real-callout-extractor.js +6 -1
  108. package/dist/core/image-ux-review.js +3 -5
  109. package/dist/core/imagegen/codex-lb-imagegen-target.js +70 -0
  110. package/dist/core/imagegen/imagegen-capability.js +11 -11
  111. package/dist/core/imagegen/imagegen-evidence.js +32 -0
  112. package/dist/core/init/skills.js +9 -11
  113. package/dist/core/init.js +4 -6
  114. package/dist/core/json/records.js +9 -0
  115. package/dist/core/json-schema-validator.js +1 -3
  116. package/dist/core/lean-engineering-policy.js +54 -0
  117. package/dist/core/loops/loop-continuation-enforcer.js +1 -3
  118. package/dist/core/mad-sks/sql-plane/mcp-executor.js +2 -1
  119. package/dist/core/mad-sks/sql-plane/policy.js +2 -1
  120. package/dist/core/managed-assets/managed-assets-manifest.js +4 -3
  121. package/dist/core/mcp-config/codex-cli-adapter.js +1 -3
  122. package/dist/core/mcp-config/config-reader.js +2 -3
  123. package/dist/core/mcp-config/guarded-patch.js +1 -1
  124. package/dist/core/mcp-config/health-check.js +2 -1
  125. package/dist/core/mcp-config/mutation.js +1 -1
  126. package/dist/core/mcp-config/restore.js +1 -1
  127. package/dist/core/mcp-config/secret-policy.js +1 -3
  128. package/dist/core/migration/migration-transaction-journal.js +3 -3
  129. package/dist/core/naruto/naruto-concurrency-governor.js +2 -2
  130. package/dist/core/perf/import-graph-budget.js +91 -1
  131. package/dist/core/pipeline/pipeline-plan-writer.js +1 -1
  132. package/dist/core/pipeline-internals/runtime-core.js +121 -23
  133. package/dist/core/pipeline-internals/runtime-gates.js +193 -4
  134. package/dist/core/pipeline.js +1 -1
  135. package/dist/core/ppt-review/slide-imagegen-review.js +7 -7
  136. package/dist/core/ppt.js +3 -3
  137. package/dist/core/product-design-app-server.js +2 -1
  138. package/dist/core/proof/fake-real-proof-policy.js +1 -3
  139. package/dist/core/proof/root-cause-policy.js +1 -3
  140. package/dist/core/proof/validation.js +1 -3
  141. package/dist/core/provider/model-router.js +4 -0
  142. package/dist/core/provider/provider-context.js +1 -3
  143. package/dist/core/providers/openrouter/openrouter-account.js +1 -3
  144. package/dist/core/quality/helper-dedup.js +0 -0
  145. package/dist/core/recallpulse.js +1 -1
  146. package/dist/core/release/file-ownership.js +26 -17
  147. package/dist/core/release/macos-menubar-proof.js +59 -1
  148. package/dist/core/release/main-push-guard.js +288 -24
  149. package/dist/core/release/main-push-receipt.js +10 -45
  150. package/dist/core/release/package-size-budget.js +1 -1
  151. package/dist/core/release/release-gate-contract.js +2 -0
  152. package/dist/core/release/release-pack-receipt.js +1 -1
  153. package/dist/core/release/release-proof-io.js +33 -0
  154. package/dist/core/release/release-upgrade-baseline.js +9 -0
  155. package/dist/core/release/runtime-script-pack-closure.js +153 -4
  156. package/dist/core/release/stage-publish.js +194 -0
  157. package/dist/core/remote/index.js +2 -0
  158. package/dist/core/remote/local-worker-client.js +35 -0
  159. package/dist/core/remote/machine-registry.js +18 -13
  160. package/dist/core/remote/owner-proof.js +1 -3
  161. package/dist/core/remote/protocol.js +1 -3
  162. package/dist/core/remote/readiness.js +1 -3
  163. package/dist/core/remote/session-binding.js +153 -0
  164. package/dist/core/remote/session-index.js +1 -3
  165. package/dist/core/remote/types.js +1 -0
  166. package/dist/core/remote/worker.js +228 -14
  167. package/dist/core/responses-stream.js +151 -0
  168. package/dist/core/routes/dollar-manifest-lite.js +1 -1
  169. package/dist/core/routes.js +8 -8
  170. package/dist/core/rust-accelerator.js +12 -2
  171. package/dist/core/safety/ssot-guard.js +1 -3
  172. package/dist/core/search/benchmark.js +358 -0
  173. package/dist/core/search/cache.js +65 -0
  174. package/dist/core/search/context.js +144 -0
  175. package/dist/core/search/doctor.js +74 -0
  176. package/dist/core/search/files.js +192 -0
  177. package/dist/core/search/index.js +5 -0
  178. package/dist/core/search/ipc.js +64 -0
  179. package/dist/core/search/provider.js +142 -0
  180. package/dist/core/search/rust-bridge.js +24 -0
  181. package/dist/core/search/structure.js +230 -0
  182. package/dist/core/search/symbol.js +272 -0
  183. package/dist/core/search/text.js +146 -0
  184. package/dist/core/search/types.js +22 -0
  185. package/dist/core/search/typescript-ls.js +215 -0
  186. package/dist/core/search-visibility/discovery.js +1 -3
  187. package/dist/core/skill-forge.js +1 -1
  188. package/dist/core/stop-gate/gate-evaluator.js +3 -3
  189. package/dist/core/stop-gate/stop-gate-check.js +1 -3
  190. package/dist/core/structured-output-adapter.js +62 -2
  191. package/dist/core/subagents/agent-catalog.js +56 -43
  192. package/dist/core/subagents/model-policy.js +17 -7
  193. package/dist/core/subagents/naruto-proof-projection.js +2 -6
  194. package/dist/core/subagents/official-subagent-config.js +1 -3
  195. package/dist/core/subagents/official-subagent-preparation.js +73 -10
  196. package/dist/core/subagents/official-subagent-prompt.js +85 -18
  197. package/dist/core/subagents/official-subagent-runner.js +10 -5
  198. package/dist/core/subagents/role-model-preferences.js +202 -44
  199. package/dist/core/subagents/subagent-evidence.js +1 -3
  200. package/dist/core/subagents/thread-budget.js +1 -1
  201. package/dist/core/subagents/triwiki-attention.js +1 -5
  202. package/dist/core/telegram/config.js +29 -12
  203. package/dist/core/telegram/hub.js +8 -2
  204. package/dist/core/telegram/index.js +2 -0
  205. package/dist/core/telegram/messages.js +8 -2
  206. package/dist/core/telegram/runtime-projection.js +8 -5
  207. package/dist/core/telegram/runtime.js +19 -9
  208. package/dist/core/telegram/service.js +181 -0
  209. package/dist/core/telegram/setup.js +220 -0
  210. package/dist/core/text/regex.js +3 -0
  211. package/dist/core/text/strings.js +6 -0
  212. package/dist/core/triwiki-wrongness/image-wrongness.js +1 -3
  213. package/dist/core/triwiki-wrongness/wrongness-ledger.js +1 -3
  214. package/dist/core/triwiki-wrongness/wrongness-proof-linker.js +1 -3
  215. package/dist/core/triwiki-wrongness/wrongness-retrieval.js +1 -3
  216. package/dist/core/triwiki-wrongness/wrongness-schema.js +1 -3
  217. package/dist/core/triwiki-wrongness/wrongness-trust-policy.js +1 -3
  218. package/dist/core/trust-kernel/completion-contract.js +1 -3
  219. package/dist/core/trust-kernel/route-contract.js +1 -3
  220. package/dist/core/update/update-migration-state.js +1 -3
  221. package/dist/core/update-check.js +20 -6
  222. package/dist/core/verification/diff-quality.js +3 -4
  223. package/dist/core/verification/impact-scan.js +36 -89
  224. package/dist/core/verification/mistake-rule-compiler.js +17 -4
  225. package/dist/core/version-manager.js +3 -20
  226. package/dist/core/version.js +1 -1
  227. package/dist/native/sks-menubar/Sources/ControlCenterWindowController.swift +23 -3
  228. package/dist/native/sks-menubar/Sources/ControlKit.swift +102 -0
  229. package/dist/native/sks-menubar/Sources/DiagnosticsViewController.swift +23 -11
  230. package/dist/native/sks-menubar/Sources/MCPServersViewController.swift +7 -3
  231. package/dist/native/sks-menubar/Sources/OperationCoordinator.swift +17 -1
  232. package/dist/native/sks-menubar/Sources/OverviewViewController.swift +22 -15
  233. package/dist/native/sks-menubar/Sources/ProcessClient.swift +15 -5
  234. package/dist/native/sks-menubar/Sources/ProvidersMultiProvider.swift +324 -0
  235. package/dist/native/sks-menubar/Sources/ProvidersOpenRouter.swift +154 -214
  236. package/dist/native/sks-menubar/Sources/ProvidersRoleModels.swift +252 -0
  237. package/dist/native/sks-menubar/Sources/ProvidersViewController.swift +77 -71
  238. package/dist/native/sks-menubar/Sources/RemoteTelegramViewController.swift +167 -51
  239. package/dist/native/sks-menubar/Sources/SettingsViewController.swift +14 -5
  240. package/dist/native/sks-menubar/Sources/SidebarItem.swift +15 -1
  241. package/dist/native/sks-menubar/Sources/StatusItemController.swift +2 -2
  242. package/dist/native/sks-menubar/Sources/UpdatesViewController.swift +16 -12
  243. package/dist/scripts/agent-guidance-dedup-check.js +23 -0
  244. package/dist/scripts/agent-message-bus-reader-check.js +1 -1
  245. package/dist/scripts/all-feature-deep-completion-check.js +1 -1
  246. package/dist/scripts/appshots-thread-attachment-discovery-check.js +1 -1
  247. package/dist/scripts/architecture-guard-check.js +1 -2
  248. package/dist/scripts/certificate-sla-check.js +1 -1
  249. package/dist/scripts/cli-output-consistency-check.js +1 -1
  250. package/dist/scripts/codex-0-134-runner-truth-check.js +1 -1
  251. package/dist/scripts/codex-0138-capability-artifact-check.js +1 -1
  252. package/dist/scripts/codex-0138-capability-check.js +1 -1
  253. package/dist/scripts/codex-0138-doctor-check.js +1 -1
  254. package/dist/scripts/codex-0138-feature-probes-check.js +1 -1
  255. package/dist/scripts/codex-0144-app-server-v2-check.js +1 -1
  256. package/dist/scripts/codex-0144-binary-identity-check.js +1 -1
  257. package/dist/scripts/codex-0144-capability-check.js +1 -1
  258. package/dist/scripts/codex-0144-core-real-probes-check.js +1 -1
  259. package/dist/scripts/codex-0144-manifest-check.js +1 -1
  260. package/dist/scripts/codex-0144-policy-check.js +1 -1
  261. package/dist/scripts/codex-0144-thread-store-check.js +1 -1
  262. package/dist/scripts/codex-agent-role-rich-content-check.js +2 -2
  263. package/dist/scripts/codex-agent-role-sync-check.js +2 -2
  264. package/dist/scripts/codex-agent-type-routing-check.js +2 -2
  265. package/dist/scripts/codex-app-execution-profile-check.js +2 -2
  266. package/dist/scripts/codex-app-handoff-check.js +1 -1
  267. package/dist/scripts/codex-app-handoff-launch-check.js +1 -1
  268. package/dist/scripts/codex-control-tool-output-continuity-audit-check.js +1 -1
  269. package/dist/scripts/codex-lb-fast-ui-preservation-check.js +1 -3
  270. package/dist/scripts/codex-native-feature-broker-blackbox.js +2 -2
  271. package/dist/scripts/codex-native-feature-broker-check.js +2 -2
  272. package/dist/scripts/{sks-3-1-6-directive-check-lib.js → codex-native-gate-lib.js} +5 -5
  273. package/dist/scripts/codex-native-harness-compat-check.js +2 -2
  274. package/dist/scripts/codex-native-hook-lifecycle-proof-check.js +2 -2
  275. package/dist/scripts/codex-plugin-app-template-policy-check.js +1 -1
  276. package/dist/scripts/codex-sdk-backend-router-check.js +1 -1
  277. package/dist/scripts/codex-sdk-capability-check.js +1 -1
  278. package/dist/scripts/context7-evidence-dedupe-check.js +1 -1
  279. package/dist/scripts/core-skill-card-schema-check.js +1 -1
  280. package/dist/scripts/core-skill-deployment-snapshot-check.js +1 -1
  281. package/dist/scripts/core-skill-heldout-validation-check.js +1 -1
  282. package/dist/scripts/core-skill-no-inference-optimizer-check.js +1 -1
  283. package/dist/scripts/core-skill-patch-check.js +1 -1
  284. package/dist/scripts/core-skill-route-runtime-integration-check.js +1 -1
  285. package/dist/scripts/current-command-surface-check.js +1 -1
  286. package/dist/scripts/current-surface-update-e2e-check.js +4 -1
  287. package/dist/scripts/current-upgrade-matrix-check.js +1 -1
  288. package/dist/scripts/dfix-fixture-check.js +1 -1
  289. package/dist/scripts/dfix-patch-handoff-check.js +1 -1
  290. package/dist/scripts/dfix-verification-check.js +1 -1
  291. package/dist/scripts/dfix-verification-recommendation-check.js +1 -1
  292. package/dist/scripts/docs-truthfulness-check.js +16 -3
  293. package/dist/scripts/doctor-codex-app-harness-check.js +2 -2
  294. package/dist/scripts/evidence-flagship-coverage-check.js +1 -1
  295. package/dist/scripts/{sks-1-18-gate-lib.js → gate-lib.js} +1 -1
  296. package/dist/scripts/gate-policy-audit-check.js +4 -1
  297. package/dist/scripts/git-worktree-checkpoint-check.js +1 -1
  298. package/dist/scripts/git-worktree-cross-rebase-check.js +1 -1
  299. package/dist/scripts/git-worktree-diff-envelope-check.js +1 -1
  300. package/dist/scripts/git-worktree-dirty-lock-check.js +1 -1
  301. package/dist/scripts/git-worktree-dirty-main-detection-check.js +1 -1
  302. package/dist/scripts/git-worktree-integration-primary-check.js +1 -1
  303. package/dist/scripts/git-worktree-manifest-append-check.js +1 -1
  304. package/dist/scripts/git-worktree-untracked-diff-check.js +1 -1
  305. package/dist/scripts/harness-benchmark-check.js +1 -1
  306. package/dist/scripts/helper-dedup-check.js +62 -0
  307. package/dist/scripts/hook-latency-budget-check.js +1 -1
  308. package/dist/scripts/image-artifact-path-contract-check.js +1 -1
  309. package/dist/scripts/imagegen-real-smoke-check.js +2 -5
  310. package/dist/scripts/installed-package-smoke-check.js +1 -1
  311. package/dist/scripts/legacy-gate-inventory-check.js +1 -1
  312. package/dist/scripts/legacy-gate-purge-check.js +1 -1
  313. package/dist/scripts/legacy-strong-inventory-check.js +1 -1
  314. package/dist/scripts/lib/codex-sdk-gate-lib.js +1 -1
  315. package/dist/scripts/mad-sks-launch-sql-plane-boundary-check.js +1 -1
  316. package/dist/scripts/mad-sks-sql-plane-capability-check.js +1 -1
  317. package/dist/scripts/mad-sks-sql-plane-lifecycle-hook-decision-check.js +1 -1
  318. package/dist/scripts/mad-sks-sql-plane-result-lifecycle-check.js +1 -1
  319. package/dist/scripts/managed-config-merge-check.js +1 -1
  320. package/dist/scripts/mcp-plugin-inventory-check.js +1 -1
  321. package/dist/scripts/model-call-concurrency-check.js +1 -1
  322. package/dist/scripts/mutation-callsite-coverage-check.js +1 -1
  323. package/dist/scripts/naruto-ssot-gate-aliases-check.js +1 -1
  324. package/dist/scripts/naruto-ssot-pipeline-default-check.js +1 -1
  325. package/dist/scripts/naruto-ssot-route-normalization-check.js +1 -1
  326. package/dist/scripts/naruto-ssot-routing-check.js +1 -1
  327. package/dist/scripts/naruto-worktree-coding-blackbox.js +1 -1
  328. package/dist/scripts/native-capability-repair-matrix-check.js +1 -1
  329. package/dist/scripts/native-image-generation-repair-check.js +1 -1
  330. package/dist/scripts/official-subagent-workflow-check.js +3 -3
  331. package/dist/scripts/package-published-contract-check.js +37 -4
  332. package/dist/scripts/packlist-performance-check.js +17 -1
  333. package/dist/scripts/pipeline-codex-native-doctor-mad-routing-real-blackbox.js +1 -3
  334. package/dist/scripts/ppt-real-export-adapter-check.js +1 -1
  335. package/dist/scripts/ppt-real-imagegen-wiring-check.js +1 -1
  336. package/dist/scripts/ppt-reexport-rereview-check.js +1 -1
  337. package/dist/scripts/prepublish-fast-check.js +1 -1
  338. package/dist/scripts/probe-memoization-check.js +2 -2
  339. package/dist/scripts/prompt-placeholder-guard-check.js +1 -1
  340. package/dist/scripts/qa-loop-app-handoff-capability-check.js +1 -1
  341. package/dist/scripts/qa-loop-app-handoff-check.js +1 -1
  342. package/dist/scripts/qa-loop-app-handoff-cli-check.js +1 -1
  343. package/dist/scripts/qa-loop-app-handoff-confirmation-check.js +1 -1
  344. package/dist/scripts/qa-loop-app-handoff-gate-lifecycle-check.js +1 -1
  345. package/dist/scripts/qa-loop-app-handoff-launch-check.js +1 -1
  346. package/dist/scripts/qa-loop-app-handoff-status-lifecycle-check.js +1 -1
  347. package/dist/scripts/qa-loop-budget-policy-check.js +1 -1
  348. package/dist/scripts/qa-loop-effort-escalation-check.js +1 -1
  349. package/dist/scripts/qa-loop-execution-profile-routing-check.js +2 -2
  350. package/dist/scripts/qa-loop-image-path-exposure-check.js +1 -1
  351. package/dist/scripts/qa-loop-image-path-prompt-injection-check.js +1 -1
  352. package/dist/scripts/{sks-1-12-real-execution-check-lib.js → real-execution-check-lib.js} +1 -1
  353. package/dist/scripts/release-affected-selector-check.js +1 -1
  354. package/dist/scripts/release-aggressive-resource-governor-check.js +1 -1
  355. package/dist/scripts/release-cache-glob-hashing-check.js +1 -1
  356. package/dist/scripts/release-cache-input-classifier-check.js +1 -1
  357. package/dist/scripts/release-cache-neutralization-report-check.js +1 -1
  358. package/dist/scripts/release-cache-version-neutral-fixture-check.js +1 -1
  359. package/dist/scripts/release-dynamic-presets-check.js +2 -2
  360. package/dist/scripts/release-full-parallelism-blackbox.js +1 -1
  361. package/dist/scripts/release-gate-batch-runner-check.js +1 -1
  362. package/dist/scripts/release-gate-budget-check.js +1 -1
  363. package/dist/scripts/release-gate-dag-runner-check.js +1 -1
  364. package/dist/scripts/release-latency-slo-check.js +1 -1
  365. package/dist/scripts/release-metadata-check.js +256 -2
  366. package/dist/scripts/release-parallel-speed-budget-check.js +1 -1
  367. package/dist/scripts/release-proof-truth-check.js +1 -1
  368. package/dist/scripts/release-provenance-check.js +4 -2
  369. package/dist/scripts/release-runtime-truth-matrix-check.js +1 -1
  370. package/dist/scripts/research-blueprint-densifier-check.js +1 -1
  371. package/dist/scripts/research-claim-builder-check.js +1 -1
  372. package/dist/scripts/research-complete-package-fixture-check.js +1 -1
  373. package/dist/scripts/research-execution-profile-routing-check.js +2 -2
  374. package/dist/scripts/research-final-reviewer-blackbox.js +1 -1
  375. package/dist/scripts/{sks-3-1-4-directive-check-lib.js → runtime-domain-gate-lib.js} +2 -2
  376. package/dist/scripts/runtime-proof-summary-check.js +1 -1
  377. package/dist/scripts/runtime-script-pack-closure-check.js +7 -1
  378. package/dist/scripts/scheduler-batch-dispatch-check.js +1 -1
  379. package/dist/scripts/scheduler-parallel-proof-consistency-check.js +1 -1
  380. package/dist/scripts/scheduler-utilization-integral-check.js +1 -1
  381. package/dist/scripts/search-visibility-gate-lib.js +1 -1
  382. package/dist/scripts/secret-preservation-check.js +1 -1
  383. package/dist/scripts/seo-geo-geo-disambiguation-check.js +1 -1
  384. package/dist/scripts/seo-geo-skill-rich-content-check.js +1 -1
  385. package/dist/scripts/side-effect-runtime-report-check.js +1 -1
  386. package/dist/scripts/{sks-3-1-8-check-lib.js → skill-fixture-check-lib.js} +1 -1
  387. package/dist/scripts/skill-name-canonicalizer-check.js +1 -1
  388. package/dist/scripts/skills-manifest-continuity-check.js +1 -1
  389. package/dist/scripts/sks-uninstall-regression-check.js +1 -1
  390. package/dist/scripts/sksd-daemon-check.js +1 -1
  391. package/dist/scripts/super-search-provider-interface-check.js +1 -1
  392. package/dist/scripts/triwiki-cache-key-check.js +1 -1
  393. package/dist/scripts/triwiki-proof-bank-blackbox.js +2 -2
  394. package/dist/scripts/triwiki-proof-bank-check.js +1 -1
  395. package/dist/scripts/triwiki-proof-card-check.js +1 -1
  396. package/dist/scripts/type-surface-codex-app-check.js +2 -2
  397. package/dist/scripts/{sks-3-1-5-directive-check-lib.js → typed-routing-gate-lib.js} +2 -2
  398. package/dist/scripts/ultra-router-auto-router-check.js +1 -1
  399. package/dist/scripts/ux-review-extract-wires-real-extractor-check.js +1 -1
  400. package/dist/scripts/ux-review-patch-diff-recheck-check.js +1 -1
  401. package/dist/scripts/ux-review-run-wires-imagegen-check.js +9 -2
  402. package/package.json +5 -7
  403. package/release-gates.v2.json +66 -11
  404. package/runtime-required-scripts.json +138 -14
  405. package/config/bench-baseline.json +0 -7
  406. package/dist/core/codex-app/sks-menubar.js +0 -1
  407. package/dist/core/release/release-closure-contract.js +0 -30
  408. package/dist/core/release/release-closure-helpers.js +0 -293
  409. package/dist/core/release/release-closure-validation.js +0 -284
  410. package/dist/core/release/release-closure.js +0 -163
  411. package/dist/scripts/build-dist.js +0 -124
  412. package/dist/scripts/build-once-runner-check.js +0 -6
  413. package/dist/scripts/canonical-test-runner.js +0 -234
  414. package/dist/scripts/changelog-check.js +0 -45
  415. package/dist/scripts/check-architecture.js +0 -295
  416. package/dist/scripts/check-cli-entrypoint.js +0 -41
  417. package/dist/scripts/check-command-module-budget.js +0 -77
  418. package/dist/scripts/check-feature-quality.js +0 -51
  419. package/dist/scripts/check-legacy-free.js +0 -64
  420. package/dist/scripts/check-pipeline-budget.js +0 -49
  421. package/dist/scripts/check-pipeline-runtime.js +0 -16
  422. package/dist/scripts/check-publish-tag.js +0 -56
  423. package/dist/scripts/check-route-modularity.js +0 -72
  424. package/dist/scripts/codex-0140-capability-check.js +0 -14
  425. package/dist/scripts/codex-0140-feature-probes-check.js +0 -23
  426. package/dist/scripts/codex-permission-profiles-check.js +0 -34
  427. package/dist/scripts/codex-project-config-policy-splitter-check.js +0 -49
  428. package/dist/scripts/competitor-scorecard-check.js +0 -24
  429. package/dist/scripts/core-skill-no-drift-check.js +0 -23
  430. package/dist/scripts/db-route-materialization-check.js +0 -32
  431. package/dist/scripts/doctor-context7-mcp-repair-blackbox.js +0 -15
  432. package/dist/scripts/doctor-fastpath-check.js +0 -25
  433. package/dist/scripts/doctor-fix-production-blackbox.js +0 -35
  434. package/dist/scripts/doctor-idempotence-check.js +0 -6
  435. package/dist/scripts/doctor-ops-semantics-check.js +0 -83
  436. package/dist/scripts/doctor-startup-config-repair-blackbox.js +0 -18
  437. package/dist/scripts/doctor-supabase-mcp-repair-blackbox.js +0 -13
  438. package/dist/scripts/ensure-bin-executable.js +0 -16
  439. package/dist/scripts/fsx-hotpath-check.js +0 -9
  440. package/dist/scripts/high-risk-contracts-check.js +0 -183
  441. package/dist/scripts/hook-latency-quantum-check.js +0 -120
  442. package/dist/scripts/import-graph-budget-check.js +0 -9
  443. package/dist/scripts/mcp-tool-naming-parity-check.js +0 -14
  444. package/dist/scripts/naruto-codex-e2e-check.js +0 -105
  445. package/dist/scripts/naruto-write-e2e-check.js +0 -31
  446. package/dist/scripts/native-capability-postcheck-check.js +0 -16
  447. package/dist/scripts/ops-diagnostics-bundle-check.js +0 -11
  448. package/dist/scripts/parallel-production-smoke-check.js +0 -20
  449. package/dist/scripts/perf-budget-check.js +0 -12
  450. package/dist/scripts/project-skill-dedupe-blackbox.js +0 -62
  451. package/dist/scripts/release-dag-full-coverage-check.js +0 -98
  452. package/dist/scripts/release-dist-freshness-check.js +0 -6
  453. package/dist/scripts/release-file-ownership-check.js +0 -35
  454. package/dist/scripts/release-gate-script-parity-check.js +0 -148
  455. package/dist/scripts/release-macos-menubar-proof.js +0 -167
  456. package/dist/scripts/release-main-push-guard.js +0 -37
  457. package/dist/scripts/release-main-push-receipt.js +0 -43
  458. package/dist/scripts/release-metadata-1-19-check.js +0 -257
  459. package/dist/scripts/release-version-truth-check.js +0 -138
  460. package/dist/scripts/retention-apply-smoke-check.js +0 -19
  461. package/dist/scripts/retention-budget-check.js +0 -6
  462. package/dist/scripts/retention-dry-run-check.js +0 -8
  463. package/dist/scripts/rollback-recovery-smoke-check.js +0 -70
  464. package/dist/scripts/route-intent-regression-check.js +0 -42
  465. package/dist/scripts/runtime-current-terminal-check.js +0 -108
  466. package/dist/scripts/runtime-dist-parity-check.js +0 -76
  467. package/dist/scripts/runtime-no-src-mjs-check.js +0 -30
  468. package/dist/scripts/runtime-ts-rust-boundary-check.js +0 -58
  469. package/dist/scripts/runtime-ts-source-of-truth-check.js +0 -53
  470. package/dist/scripts/secret-preservation-guard-check.js +0 -36
  471. package/dist/scripts/seo-marketing-truthfulness-check.js +0 -98
  472. package/dist/scripts/seo-metadata-sync-check.js +0 -60
  473. package/dist/scripts/sizecheck.js +0 -148
  474. package/dist/scripts/sks-menubar-install-check.js +0 -333
  475. package/dist/scripts/supabase-secret-preservation-blackbox.js +0 -28
  476. package/dist/scripts/super-search-live-smoke-check.js +0 -115
  477. package/dist/scripts/super-search-local-http-smoke-check.js +0 -16
  478. package/dist/scripts/super-search-offline-contract-check.js +0 -43
  479. package/dist/scripts/update-fastpath-check.js +0 -28
  480. package/dist/scripts/update-preserves-supabase-keys-blackbox.js +0 -26
  481. package/dist/scripts/upgrade-migration-matrix-check.js +0 -351
  482. package/dist/scripts/write-build-manifest.js +0 -70
  483. package/dist/scripts/zellij-capability-check.js +0 -13
  484. package/dist/scripts/zellij-developer-controls-check.js +0 -16
  485. package/dist/scripts/zellij-doctor-readiness-check.js +0 -49
  486. package/dist/scripts/zellij-dynamic-pane-lifecycle-check.js +0 -19
  487. package/dist/scripts/zellij-fake-adapter-check.js +0 -31
  488. package/dist/scripts/zellij-first-slot-down-stack-check.js +0 -20
  489. package/dist/scripts/zellij-first-slot-down-stack-real-check.js +0 -348
  490. package/dist/scripts/zellij-homebrew-policy-check.js +0 -3
  491. package/dist/scripts/zellij-initial-main-only-blackbox.js +0 -21
  492. package/dist/scripts/zellij-lane-renderer-check.js +0 -78
  493. package/dist/scripts/zellij-launch-command-truth-check.js +0 -62
  494. package/dist/scripts/zellij-layout-valid-check.js +0 -120
  495. package/dist/scripts/zellij-pane-creation-lock-metrics-check.js +0 -10
  496. package/dist/scripts/zellij-pane-lock-concurrency-blackbox.js +0 -78
  497. package/dist/scripts/zellij-pane-lock-does-not-block-worker-check.js +0 -12
  498. package/dist/scripts/zellij-pane-lock-open-worker-integration-blackbox.js +0 -134
  499. package/dist/scripts/zellij-qa-app-handoff-status-check.js +0 -7
  500. package/dist/scripts/zellij-right-column-geometry-proof.js +0 -158
  501. package/dist/scripts/zellij-right-column-headless-overflow-check.js +0 -20
  502. package/dist/scripts/zellij-right-column-manager-check.js +0 -24
  503. package/dist/scripts/zellij-self-heal-check.js +0 -3
  504. package/dist/scripts/zellij-self-heal-dry-run-check.js +0 -3
  505. package/dist/scripts/zellij-self-heal-status-contract-check.js +0 -3
  506. package/dist/scripts/zellij-self-heal-typed-blackbox.js +0 -3
  507. package/dist/scripts/zellij-slot-column-anchor-check.js +0 -65
  508. package/dist/scripts/zellij-slot-column-anchor-telemetry-check.js +0 -8
  509. package/dist/scripts/zellij-slot-only-ui-check.js +0 -29
  510. package/dist/scripts/zellij-slot-pane-renderer-check.js +0 -149
  511. package/dist/scripts/zellij-slot-pane-stale-detection-check.js +0 -65
  512. package/dist/scripts/zellij-slot-pane-telemetry-renderer-check.js +0 -11
  513. package/dist/scripts/zellij-slot-renderer-proof-semantics-check.js +0 -58
  514. package/dist/scripts/zellij-slot-telemetry-check.js +0 -38
  515. package/dist/scripts/zellij-slot-telemetry-incremental-check.js +0 -46
  516. package/dist/scripts/zellij-slot-telemetry-live-flush-check.js +0 -55
  517. package/dist/scripts/zellij-slot-telemetry-performance-check.js +0 -32
  518. package/dist/scripts/zellij-slot-telemetry-real-blackbox.js +0 -19
  519. package/dist/scripts/zellij-slot-telemetry-renderer-check.js +0 -11
  520. package/dist/scripts/zellij-slot-telemetry-runtime-check.js +0 -23
  521. package/dist/scripts/zellij-spawn-on-demand-layout-check.js +0 -45
  522. package/dist/scripts/zellij-stacked-capability-routing-check.js +0 -9
  523. package/dist/scripts/zellij-stacked-fallback-integration-blackbox.js +0 -78
  524. package/dist/scripts/zellij-stacked-version-matrix-check.js +0 -29
  525. package/dist/scripts/zellij-stacked-version-parser-check.js +0 -19
  526. package/dist/scripts/zellij-ui-design-check.js +0 -92
  527. package/dist/scripts/zellij-update-missing-self-heal-check.js +0 -3
  528. package/dist/scripts/zellij-update-prompt-matrix-check.js +0 -16
  529. package/dist/scripts/zellij-update-prompt-mode-check.js +0 -18
  530. package/dist/scripts/zellij-update-prompt-safety-check.js +0 -8
  531. package/dist/scripts/zellij-worker-pane-manager-check.js +0 -108
  532. package/dist/scripts/zellij-worker-pane-manager-single-owner-check.js +0 -47
  533. package/dist/scripts/zellij-worker-pane-real-ui-blackbox.js +0 -199
  534. /package/dist/scripts/{sks-1-11-gate-lib.js → sks-cli-gate-lib.js} +0 -0
@@ -1,16 +1,19 @@
1
1
  import path from 'node:path';
2
2
  import os from 'node:os';
3
- import { ensureDir, readText, nowIso } from '../fsx.js';
3
+ import { ensureDir, exists, readText, nowIso } from '../fsx.js';
4
4
  import { openRouterSecretPaths, resolveOpenRouterApiKey } from '../providers/openrouter/openrouter-secret-store.js';
5
- import { OPENROUTER_AUTH_COMMAND, OPENROUTER_AUTH_REFRESH_INTERVAL_MS, OPENROUTER_AUTH_TIMEOUT_MS, openRouterAuthCommandArgs, OPENROUTER_DEFAULT_MODEL, OPENROUTER_PROVIDER_ID, normalizeOpenRouterModelId } from './openrouter-provider.js';
5
+ import { OPENROUTER_AUTH_COMMAND, OPENROUTER_AUTH_REFRESH_INTERVAL_MS, OPENROUTER_AUTH_TIMEOUT_MS, openRouterAuthCommandArgs, OPENROUTER_PROVIDER_ID, normalizeOpenRouterModelId } from './openrouter-provider.js';
6
6
  import { installCodexAppGlmProfile } from './glm-profile-installer.js';
7
7
  import { restartCodexApp } from './codex-app-restart.js';
8
8
  import { codexLbConfigPath, ensureGlobalCodexAppGlmProfile, unselectCodexLbProvider } from '../../cli/install-helpers.js';
9
- import { ensureTrailingNewline, safeWriteCodexConfigToml, upsertTopLevelTomlString } from '../codex-runtime/codex-desktop-config-policy.js';
10
- function topLevelTomlString(text, key) {
11
- const match = String(text || '').match(new RegExp(`(?:^|\\n)${key}\\s*=\\s*\"([^\"]*)\"`));
12
- return match?.[1] ?? null;
13
- }
9
+ import { ensureTrailingNewline, normalizeCodexFastModeUiConfig, safeWriteCodexConfigToml, upsertTopLevelTomlString } from '../codex-runtime/codex-desktop-config-policy.js';
10
+ import { readTopLevelTomlString, sksOpenRouterCatalogPath } from './codex-model-catalog.js';
11
+ import { resolveCatalogPath } from './multi-provider-router-support.js';
12
+ import { openRouterCatalogBindDecision, writeOpenRouterManagedCatalog } from './openrouter-model-catalog.js';
13
+ import { classifyCodexDesktopRouting } from './codex-desktop-routing-ownership.js';
14
+ import { desktopPickerStatusFromCache, invalidateCodexModelsCache } from './codex-models-cache.js';
15
+ import { assessThreadVisibilityImpact, captureDesktopRoutingSnapshot, desktopRoutingSnapshotPath, readDesktopRoutingSnapshot, remapThreadCatalogProvider, restoreDesktopRoutingSnapshot, writeDesktopRoutingSnapshot } from './desktop-routing-snapshot.js';
16
+ import { escapeRegExp } from '../text/regex.js';
14
17
  export async function openRouterStatus(input = {}) {
15
18
  const home = input.home || process.env.HOME || os.homedir();
16
19
  const configPath = input.configPath || codexLbConfigPath(home);
@@ -30,8 +33,12 @@ export async function openRouterStatus(input = {}) {
30
33
  && hasTomlStringArray(authBody, 'args', authArgs)
31
34
  && hasTomlInteger(authBody, 'timeout_ms', OPENROUTER_AUTH_TIMEOUT_MS)
32
35
  && hasTomlInteger(authBody, 'refresh_interval_ms', OPENROUTER_AUTH_REFRESH_INTERVAL_MS);
33
- const selected = topLevelTomlString(config, 'model_provider') === OPENROUTER_PROVIDER_ID;
34
- const model = topLevelTomlString(config, 'model');
36
+ const selected = readTopLevelTomlString(config, 'model_provider') === OPENROUTER_PROVIDER_ID;
37
+ const model = readTopLevelTomlString(config, 'model');
38
+ const managedCatalogPath = sksOpenRouterCatalogPath({ home, env });
39
+ const configuredCatalogPath = readTopLevelTomlString(config, 'model_catalog_json');
40
+ const modelCatalogBound = Boolean(configuredCatalogPath
41
+ && resolveCatalogPath(configuredCatalogPath, { home, env, configPath }) === path.resolve(managedCatalogPath));
35
42
  const blockers = [];
36
43
  if (!key.key)
37
44
  blockers.push('openrouter_key_missing');
@@ -43,9 +50,29 @@ export async function openRouterStatus(input = {}) {
43
50
  blockers.push('openrouter_provider_auth_missing');
44
51
  else if (!providerAuthValid)
45
52
  blockers.push('openrouter_provider_auth_invalid');
53
+ if (selected && !model)
54
+ blockers.push('openrouter_model_missing');
55
+ const ownership = classifyCodexDesktopRouting(config, { home, env, configPath });
56
+ const currentProvider = readTopLevelTomlString(config, 'model_provider');
57
+ const threadVisibility = assessThreadVisibilityImpact({
58
+ home,
59
+ env,
60
+ currentProvider,
61
+ targetProvider: selected ? OPENROUTER_PROVIDER_ID : (currentProvider || 'openai')
62
+ });
63
+ const previousSnapshot = await readDesktopRoutingSnapshot({ home, env });
64
+ const previousRoutingRestoreAvailable = Boolean(previousSnapshot && previousSnapshot.model_provider !== OPENROUTER_PROVIDER_ID);
65
+ const warnings = [
66
+ ...(selected && !modelCatalogBound ? ['openrouter_model_catalog_not_bound'] : []),
67
+ ...ownership.warnings,
68
+ ...(selected && threadVisibility.hidden_if_switched > 0
69
+ ? ['desktop_other_provider_threads_hidden_until_restore']
70
+ : []),
71
+ ...(previousRoutingRestoreAvailable ? ['desktop_routing_snapshot_restore_available'] : [])
72
+ ];
46
73
  return {
47
74
  schema: 'sks.codex-app-openrouter-status.v1',
48
- ok: blockers.length === 0 && (selected ? Boolean(model) : true),
75
+ ok: blockers.length === 0,
49
76
  key_present: Boolean(key.key),
50
77
  key_source: key.source || null,
51
78
  provider_present: providerPresent,
@@ -54,15 +81,25 @@ export async function openRouterStatus(input = {}) {
54
81
  provider_auth_conflict: providerAuthConflict,
55
82
  provider_auth_valid: providerAuthValid,
56
83
  selected,
57
- model: model || (selected ? OPENROUTER_DEFAULT_MODEL : null),
58
- model_source: model ? 'config' : selected ? 'default' : null,
84
+ model,
85
+ model_source: model ? 'config' : null,
86
+ model_catalog_path: managedCatalogPath,
87
+ model_catalog_bound: modelCatalogBound,
59
88
  config_path: configPath,
89
+ routing_ownership: ownership,
90
+ desktop_picker: desktopPickerStatusFromCache({
91
+ catalogOk: modelCatalogBound,
92
+ cache: null,
93
+ restartAppRequested: false
94
+ }),
95
+ thread_visibility: threadVisibility,
96
+ previous_routing_restore_available: previousRoutingRestoreAvailable,
60
97
  blockers,
61
- warnings: []
98
+ warnings
62
99
  };
63
100
  }
64
101
  export async function useOpenRouter(input) {
65
- const model = normalizeOpenRouterModelId(input.model || OPENROUTER_DEFAULT_MODEL);
102
+ const model = normalizeOpenRouterModelId(input.model);
66
103
  if (!model) {
67
104
  return {
68
105
  schema: 'sks.codex-app-use-openrouter.v1',
@@ -72,7 +109,7 @@ export async function useOpenRouter(input) {
72
109
  mode: 'openrouter',
73
110
  blockers: ['openrouter_model_invalid'],
74
111
  warnings: [],
75
- hint: 'Pass --model <openrouter-model-id>, for example z-ai/glm-5.2'
112
+ hint: 'Choose a catalog model or pass --model <openrouter-model-id>.'
76
113
  };
77
114
  }
78
115
  const home = input.home || process.env.HOME || os.homedir();
@@ -100,6 +137,13 @@ export async function useOpenRouter(input) {
100
137
  env,
101
138
  configPath
102
139
  });
140
+ const activationProfile = {
141
+ ...profile,
142
+ profile: {
143
+ ...profile.profile,
144
+ model
145
+ }
146
+ };
103
147
  if (!profile.ok) {
104
148
  return {
105
149
  schema: 'sks.codex-app-use-openrouter.v1',
@@ -108,21 +152,58 @@ export async function useOpenRouter(input) {
108
152
  status: 'blocked',
109
153
  mode: 'openrouter',
110
154
  model,
111
- profile,
155
+ profile: activationProfile,
112
156
  blockers: profile.blockers,
113
157
  warnings: profile.warnings || []
114
158
  };
115
159
  }
160
+ const configExistedBefore = await exists(configPath);
161
+ const currentBeforeSwitch = await readText(configPath, '');
162
+ const previousProvider = readTopLevelTomlString(currentBeforeSwitch, 'model_provider');
163
+ const threadVisibility = assessThreadVisibilityImpact({
164
+ home,
165
+ env,
166
+ currentProvider: previousProvider,
167
+ targetProvider: OPENROUTER_PROVIDER_ID
168
+ });
169
+ const preserveThreadSidebar = input.preserveThreadSidebar !== false;
170
+ const routingSnapshot = captureDesktopRoutingSnapshot(currentBeforeSwitch, {
171
+ reason: 'use-openrouter'
172
+ });
173
+ let snapshotWrite;
174
+ if (routingSnapshot.model_provider === OPENROUTER_PROVIDER_ID) {
175
+ const existingSnapshot = await readDesktopRoutingSnapshot({ home, env });
176
+ const crossProviderSnapshotPreserved = Boolean(existingSnapshot && existingSnapshot.model_provider !== OPENROUTER_PROVIDER_ID);
177
+ snapshotWrite = {
178
+ ok: crossProviderSnapshotPreserved,
179
+ path: desktopRoutingSnapshotPath({ home, env }),
180
+ skipped: crossProviderSnapshotPreserved
181
+ ? 'preserved_existing_cross_provider_snapshot'
182
+ : 'self_referential_snapshot_not_written'
183
+ };
184
+ }
185
+ else {
186
+ snapshotWrite = await writeDesktopRoutingSnapshot(routingSnapshot, { home, env });
187
+ }
116
188
  const unselect = await unselectCodexLbProvider({
117
189
  home,
118
190
  configPath,
119
191
  allowActiveSharedAuthTransition: true
120
192
  }).catch((err) => ({ ok: false, status: 'failed', provider_error: err?.message || String(err) }));
193
+ const modelCatalog = await writeOpenRouterManagedCatalog({ model, home, env });
121
194
  const current = await readText(configPath, '');
195
+ const catalogBind = openRouterCatalogBindDecision(current, { home, env, configPath });
122
196
  let next = upsertTopLevelTomlString(current, 'model_provider', OPENROUTER_PROVIDER_ID);
123
197
  next = upsertTopLevelTomlString(next, 'model', model);
198
+ if (modelCatalog.ok && catalogBind.bindable) {
199
+ next = upsertTopLevelTomlString(next, 'model_catalog_json', modelCatalog.path);
200
+ }
201
+ next = normalizeCodexFastModeUiConfig(next);
124
202
  next = ensureTrailingNewline(next);
125
- const write = await safeWriteCodexConfigToml(configPath, current, next, 'openrouter-use');
203
+ const write = await safeWriteCodexConfigToml(configPath, current, next, 'openrouter-use', {
204
+ verifyUnchangedBeforeWrite: true,
205
+ expectedBeforeExists: configExistedBefore
206
+ });
126
207
  if (!write.ok) {
127
208
  return {
128
209
  schema: 'sks.codex-app-use-openrouter.v1',
@@ -133,17 +214,61 @@ export async function useOpenRouter(input) {
133
214
  model,
134
215
  write,
135
216
  unselect,
217
+ routing_snapshot: routingSnapshot,
218
+ routing_snapshot_write: snapshotWrite,
219
+ thread_visibility: threadVisibility,
220
+ thread_sidebar_remap: null,
136
221
  blockers: [String(write.status || 'openrouter_config_write_blocked')],
137
222
  warnings: []
138
223
  };
139
224
  }
225
+ let threadSidebarRemap = null;
226
+ let threadSidebarMeta;
227
+ if (preserveThreadSidebar
228
+ && previousProvider
229
+ && previousProvider !== OPENROUTER_PROVIDER_ID) {
230
+ threadSidebarRemap = remapThreadCatalogProvider({
231
+ home,
232
+ env,
233
+ fromProvider: previousProvider,
234
+ toProvider: OPENROUTER_PROVIDER_ID
235
+ });
236
+ if (threadSidebarRemap.ok && threadSidebarRemap.remapped > 0) {
237
+ threadSidebarMeta = {
238
+ remapped: true,
239
+ from_provider: previousProvider,
240
+ to_provider: OPENROUTER_PROVIDER_ID,
241
+ thread_ids: threadSidebarRemap.thread_ids,
242
+ catalog_db: threadSidebarRemap.catalog_db
243
+ };
244
+ await writeDesktopRoutingSnapshot(captureDesktopRoutingSnapshot(currentBeforeSwitch, {
245
+ reason: 'use-openrouter',
246
+ threadSidebar: threadSidebarMeta
247
+ }), { home, env });
248
+ }
249
+ }
140
250
  const restart = await (input.restartImpl || restartCodexApp)({ enabled: Boolean(input.restartApp) });
251
+ const cache = modelCatalog?.models_cache
252
+ || await invalidateCodexModelsCache({
253
+ home,
254
+ env,
255
+ catalogPath: modelCatalog.ok ? modelCatalog.path : null,
256
+ seedMode: 'merge'
257
+ });
141
258
  const status = await openRouterStatus({ home, configPath, env });
259
+ const modelCatalogApplied = Boolean(modelCatalog.ok
260
+ && (!catalogBind.bindable || status.model_catalog_bound));
142
261
  const configApplied = Boolean(status.selected
143
262
  && status.key_present
144
263
  && status.provider_present
145
264
  && status.provider_auth_valid
146
- && status.model === model);
265
+ && status.model === model
266
+ && modelCatalogApplied);
267
+ const desktopPicker = desktopPickerStatusFromCache({
268
+ catalogOk: modelCatalogApplied,
269
+ cache,
270
+ restartAppRequested: Boolean(input.restartApp)
271
+ });
147
272
  return {
148
273
  schema: 'sks.codex-app-use-openrouter.v1',
149
274
  generated_at: nowIso(),
@@ -151,13 +276,26 @@ export async function useOpenRouter(input) {
151
276
  status: configApplied ? (restart.ok ? 'active' : 'active_restart_blocked') : 'activation_incomplete',
152
277
  mode: 'openrouter',
153
278
  model,
154
- profile,
279
+ profile: activationProfile,
155
280
  unselect,
156
281
  write,
157
282
  restart_app: restart,
158
283
  config_applied: configApplied,
159
284
  restart_ok: restart.ok,
160
- openrouter: status,
285
+ openrouter: {
286
+ ...status,
287
+ desktop_picker: desktopPicker
288
+ },
289
+ model_catalog: modelCatalog,
290
+ model_catalog_bind: catalogBind,
291
+ models_cache: cache,
292
+ desktop_picker: desktopPicker,
293
+ routing_ownership: status.routing_ownership,
294
+ routing_snapshot: routingSnapshot,
295
+ routing_snapshot_write: snapshotWrite,
296
+ previous_routing_restore_available: Boolean(snapshotWrite.ok),
297
+ thread_visibility: threadVisibility,
298
+ thread_sidebar_remap: threadSidebarRemap,
161
299
  readiness: {
162
300
  selected: status.selected,
163
301
  key_present: status.key_present,
@@ -165,22 +303,50 @@ export async function useOpenRouter(input) {
165
303
  provider_auth_present: status.provider_auth_present,
166
304
  provider_auth_valid: status.provider_auth_valid,
167
305
  model: status.model,
306
+ model_catalog_ok: modelCatalog.ok,
307
+ model_catalog_bound: status.model_catalog_bound,
308
+ features_normalized: true,
168
309
  config_applied: configApplied,
169
310
  restart_ok: restart.ok,
311
+ models_cache_invalidated: desktopPicker.models_cache_invalidated,
170
312
  ok: configApplied
171
313
  },
172
314
  blockers: [
173
315
  ...(status.selected ? [] : ['openrouter_not_selected']),
174
316
  ...(status.model === model ? [] : ['openrouter_model_not_applied']),
175
- ...(status.provider_auth_valid ? [] : ['openrouter_provider_auth_not_applied'])
317
+ ...(status.provider_auth_valid ? [] : ['openrouter_provider_auth_not_applied']),
318
+ ...(modelCatalogApplied
319
+ ? []
320
+ : (modelCatalog.blockers.length ? modelCatalog.blockers : ['openrouter_model_catalog_not_applied']))
176
321
  ],
177
322
  warnings: [
178
323
  ...(unselect?.ok === false ? [`codex_lb_unselect:${unselect.provider_error || unselect.status}`] : []),
179
324
  ...(restart.ok ? [] : (restart.blockers || ['openrouter_restart_blocked']).map((blocker) => `restart:${blocker}`)),
180
- ...(profile.warnings || [])
181
- ]
325
+ ...(profile.warnings || []),
326
+ ...(catalogBind.bindable ? [] : ['openrouter_model_catalog_user_catalog_preserved']),
327
+ ...modelCatalog.warnings,
328
+ ...cache.warnings,
329
+ ...(desktopPicker.models_cache_invalidated ? [] : ['openrouter_models_cache_not_invalidated']),
330
+ ...(threadSidebarRemap && !threadSidebarRemap.ok
331
+ ? [`thread_sidebar_remap_failed:${threadSidebarRemap.error || 'unknown'}`]
332
+ : []),
333
+ ...(threadVisibility.hidden_if_switched > 0 && !(threadSidebarMeta?.remapped)
334
+ ? [`desktop_hides_${threadVisibility.hidden_if_switched}_other_provider_threads`]
335
+ : []),
336
+ ...(snapshotWrite.ok
337
+ ? []
338
+ : [snapshotWrite.skipped
339
+ ? `routing_snapshot_not_written:${snapshotWrite.skipped}`
340
+ : `routing_snapshot_write_failed:${snapshotWrite.error || 'unknown'}`]),
341
+ 'desktop_picker_restart_recommended_after_catalog_change',
342
+ 'restore_previous_provider_via_sks_codex_app_restore_desktop_routing'
343
+ ],
344
+ hint: snapshotWrite.ok
345
+ ? 'Other-provider Desktop chats stay visible when sidebar remap succeeds; otherwise restore with: sks codex-app restore-desktop-routing --restart-app'
346
+ : 'If Desktop chats disappeared, run: sks codex-app restore-desktop-routing --restart-app'
182
347
  };
183
348
  }
349
+ export { restoreDesktopRoutingSnapshot };
184
350
  export async function ensureOpenRouterProviderInstalled(opts = {}) {
185
351
  return ensureGlobalCodexAppGlmProfile(opts);
186
352
  }
@@ -212,6 +378,3 @@ function hasTomlStringArray(text, key, values) {
212
378
  function hasTomlInteger(text, key, value) {
213
379
  return new RegExp(`^\\s*${escapeRegExp(key)}\\s*=\\s*${value}\\s*(?:#.*)?$`, 'm').test(text);
214
380
  }
215
- function escapeRegExp(value) {
216
- return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
217
- }
@@ -0,0 +1 @@
1
+ export const OPENROUTER_CATALOG_BASE_INSTRUCTIONS = "You are a coding agent running in the Codex CLI, a terminal-based coding assistant. Codex CLI is an open source project led by OpenAI. You are expected to be precise, safe, and helpful.\n\nYour capabilities:\n\n- Receive user prompts and other context provided by the harness, such as files in the workspace.\n- Communicate with the user by streaming thinking & responses, and by making & updating plans.\n- Emit function calls to run terminal commands and apply patches. Depending on how this specific run is configured, you can request that these function calls be escalated to the user for approval before running. More on this in the \"Sandbox and approvals\" section.\n\nWithin this context, Codex refers to the open-source agentic coding interface (not the old Codex language model built by OpenAI).\n\n# How you work\n\n## Personality\n\nYour default personality and tone is concise, direct, and friendly. You communicate efficiently, always keeping the user clearly informed about ongoing actions without unnecessary detail. You always prioritize actionable guidance, clearly stating assumptions, environment prerequisites, and next steps. Unless explicitly asked, you avoid excessively verbose explanations about your work.\n\n# AGENTS.md spec\n- Repos often contain AGENTS.md files. These files can appear anywhere within the repository.\n- These files are a way for humans to give you (the agent) instructions or tips for working within the container.\n- Some examples might be: coding conventions, info about how code is organized, or instructions for how to run or test code.\n- Instructions in AGENTS.md files:\n - The scope of an AGENTS.md file is the entire directory tree rooted at the folder that contains it.\n - For every file you touch in the final patch, you must obey instructions in any AGENTS.md file whose scope includes that file.\n - Instructions about code style, structure, naming, etc. apply only to code within the AGENTS.md file's scope, unless the file states otherwise.\n - More-deeply-nested AGENTS.md files take precedence in the case of conflicting instructions.\n - Direct system/developer/user instructions (as part of a prompt) take precedence over AGENTS.md instructions.\n- The contents of the AGENTS.md file at the root of the repo and any directories from the CWD up to the root are included with the developer message and don't need to be re-read. When working in a subdirectory of CWD, or a directory outside the CWD, check for any AGENTS.md files that may be applicable.\n\n## Responsiveness\n\n### Preamble messages\n\nBefore making tool calls, send a brief preamble to the user explaining what you\u2019re about to do. When sending preamble messages, follow these principles and examples:\n\n- **Logically group related actions**: if you\u2019re about to run several related commands, describe them together in one preamble rather than sending a separate note for each.\n- **Keep it concise**: be no more than 1-2 sentences, focused on immediate, tangible next steps. (8\u201312 words for quick updates).\n- **Build on prior context**: if this is not your first tool call, use the preamble message to connect the dots with what\u2019s been done so far and create a sense of momentum and clarity for the user to understand your next actions.\n- **Keep your tone light, friendly and curious**: add small touches of personality in preambles feel collaborative and engaging.\n- **Exception**: Avoid adding a preamble for every trivial read (e.g., `cat` a single file) unless it\u2019s part of a larger grouped action.\n\n**Examples:**\n\n- \u201cI\u2019ve explored the repo; now checking the API route definitions.\u201d\n- \u201cNext, I\u2019ll patch the config and update the related tests.\u201d\n- \u201cI\u2019m about to scaffold the CLI commands and helper functions.\u201d\n- \u201cOk cool, so I\u2019ve wrapped my head around the repo. Now digging into the API routes.\u201d\n- \u201cConfig\u2019s looking tidy. Next up is patching helpers to keep things in sync.\u201d\n- \u201cFinished poking at the DB gateway. I will now chase down error handling.\u201d\n- \u201cAlright, build pipeline order is interesting. Checking how it reports failures.\u201d\n- \u201cSpotted a clever caching util; now hunting where it gets used.\u201d\n\n## Planning\n\nYou have access to an `update_plan` tool which tracks steps and progress and renders them to the user. Using the tool helps demonstrate that you've understood the task and convey how you're approaching it. Plans can help to make complex, ambiguous, or multi-phase work clearer and more collaborative for the user. A good plan should break the task into meaningful, logically ordered steps that are easy to verify as you go.\n\nNote that plans are not for padding out simple work with filler steps or stating the obvious. The content of your plan should not involve doing anything that you aren't capable of doing (i.e. don't try to test things that you can't test). Do not use plans for simple or single-step queries that you can just do or answer immediately.\n\nDo not repeat the full contents of the plan after an `update_plan` call \u2014 the harness already displays it. Instead, summarize the change made and highlight any important context or next step.\n\nBefore running a command, consider whether or not you have completed the previous step, and make sure to mark it as completed before moving on to the next step. It may be the case that you complete all steps in your plan after a single pass of implementation. If this is the case, you can simply mark all the planned steps as completed. Sometimes, you may need to change plans in the middle of a task: call `update_plan` with the updated plan and make sure to provide an `explanation` of the rationale when doing so.\n\nUse a plan when:\n\n- The task is non-trivial and will require multiple actions over a long time horizon.\n- There are logical phases or dependencies where sequencing matters.\n- The work has ambiguity that benefits from outlining high-level goals.\n- You want intermediate checkpoints for feedback and validation.\n- When the user asked you to do more than one thing in a single prompt\n- The user has asked you to use the plan tool (aka \"TODOs\")\n- You generate additional steps while working, and plan to do them before yielding to the user\n\n### Examples\n\n**High-quality plans**\n\nExample 1:\n\n1. Add CLI entry with file args\n2. Parse Markdown via CommonMark library\n3. Apply semantic HTML template\n4. Handle code blocks, images, links\n5. Add error handling for invalid files\n\nExample 2:\n\n1. Define CSS variables for colors\n2. Add toggle with localStorage state\n3. Refactor components to use variables\n4. Verify all views for readability\n5. Add smooth theme-change transition\n\nExample 3:\n\n1. Set up Node.js + WebSocket server\n2. Add join/leave broadcast events\n3. Implement messaging with timestamps\n4. Add usernames + mention highlighting\n5. Persist messages in lightweight DB\n6. Add typing indicators + unread count\n\n**Low-quality plans**\n\nExample 1:\n\n1. Create CLI tool\n2. Add Markdown parser\n3. Convert to HTML\n\nExample 2:\n\n1. Add dark mode toggle\n2. Save preference\n3. Make styles look good\n\nExample 3:\n\n1. Create single-file HTML game\n2. Run quick sanity check\n3. Summarize usage instructions\n\nIf you need to write a plan, only write high quality plans, not low quality ones.\n\n## Task execution\n\nYou are a coding agent. Please keep going until the query is completely resolved, before ending your turn and yielding back to the user. Only terminate your turn when you are sure that the problem is solved. Autonomously resolve the query to the best of your ability, using the tools available to you, before coming back to the user. Do NOT guess or make up an answer.\n\nYou MUST adhere to the following criteria when solving queries:\n\n- Working on the repo(s) in the current environment is allowed, even if they are proprietary.\n- Analyzing code for vulnerabilities is allowed.\n- Showing user code and tool call details is allowed.\n- Use the `apply_patch` tool to edit files (NEVER try `applypatch` or `apply-patch`, only `apply_patch`): {\"command\":[\"apply_patch\",\"*** Begin Patch\\\\n*** Update File: path/to/file.py\\\\n@@ def example():\\\\n- pass\\\\n+ return 123\\\\n*** End Patch\"]}\n\nIf completing the user's task requires writing or modifying files, your code and final answer should follow these coding guidelines, though user instructions (i.e. AGENTS.md) may override these guidelines:\n\n- Fix the problem at the root cause rather than applying surface-level patches, when possible.\n- Avoid unneeded complexity in your solution.\n- Do not attempt to fix unrelated bugs or broken tests. It is not your responsibility to fix them. (You may mention them to the user in your final message though.)\n- Update documentation as necessary.\n- Keep changes consistent with the style of the existing codebase. Changes should be minimal and focused on the task.\n- Use `git log` and `git blame` to search the history of the codebase if additional context is required.\n- NEVER add copyright or license headers unless specifically requested.\n- Do not waste tokens by re-reading files after calling `apply_patch` on them. The tool call will fail if it didn't work. The same goes for making folders, deleting folders, etc.\n- Do not `git commit` your changes or create new git branches unless explicitly requested.\n- Do not add inline comments within code unless explicitly requested.\n- Do not use one-letter variable names unless explicitly requested.\n- NEVER output inline citations like \"\u3010F:README.md\u2020L5-L14\u3011\" in your outputs. The CLI is not able to render these so they will just be broken in the UI. Instead, if you output valid filepaths, users will be able to click on them to open the files in their editor.\n\n## Validating your work\n\nIf the codebase has tests or the ability to build or run, consider using them to verify that your work is complete. \n\nWhen testing, your philosophy should be to start as specific as possible to the code you changed so that you can catch issues efficiently, then make your way to broader tests as you build confidence. If there's no test for the code you changed, and if the adjacent patterns in the codebases show that there's a logical place for you to add a test, you may do so. However, do not add tests to codebases with no tests.\n\nSimilarly, once you're confident in correctness, you can suggest or use formatting commands to ensure that your code is well formatted. If there are issues you can iterate up to 3 times to get formatting right, but if you still can't manage it's better to save the user time and present them a correct solution where you call out the formatting in your final message. If the codebase does not have a formatter configured, do not add one.\n\nFor all of testing, running, building, and formatting, do not attempt to fix unrelated bugs. It is not your responsibility to fix them. (You may mention them to the user in your final message though.)\n\nBe mindful of whether to run validation commands proactively. In the absence of behavioral guidance:\n\n- When running in the non-interactive approval mode **never**, proactively run tests, lint and do whatever you need to ensure you've completed the task.\n- When working in interactive approval modes like **untrusted**, or **on-request**, hold off on running tests or lint commands until the user is ready for you to finalize your output, because these commands take time to run and slow down iteration. Instead suggest what you want to do next, and let the user confirm first.\n- When working on test-related tasks, such as adding tests, fixing tests, or reproducing a bug to verify behavior, you may proactively run tests regardless of approval mode. Use your judgement to decide whether this is a test-related task.\n\n## Ambition vs. precision\n\nFor tasks that have no prior context (i.e. the user is starting something brand new), you should feel free to be ambitious and demonstrate creativity with your implementation.\n\nIf you're operating in an existing codebase, you should make sure you do exactly what the user asks with surgical precision. Treat the surrounding codebase with respect, and don't overstep (i.e. changing filenames or variables unnecessarily). You should balance being sufficiently ambitious and proactive when completing tasks of this nature.\n\nYou should use judicious initiative to decide on the right level of detail and complexity to deliver based on the user's needs. This means showing good judgment that you're capable of doing the right extras without gold-plating. This might be demonstrated by high-value, creative touches when scope of the task is vague; while being surgical and targeted when scope is tightly specified.\n\n## Sharing progress updates\n\nFor especially longer tasks that you work on (i.e. requiring many tool calls, or a plan with multiple steps), you should provide progress updates back to the user at reasonable intervals. These updates should be structured as a concise sentence or two (no more than 8-10 words long) recapping progress so far in plain language: this update demonstrates your understanding of what needs to be done, progress so far (i.e. files explores, subtasks complete), and where you're going next.\n\nBefore doing large chunks of work that may incur latency as experienced by the user (i.e. writing a new file), you should send a concise message to the user with an update indicating what you're about to do to ensure they know what you're spending time on. Don't start editing or writing large files before informing the user what you are doing and why.\n\nThe messages you send before tool calls should describe what is immediately about to be done next in very concise language. If there was previous work done, this preamble message should also include a note about the work done so far to bring the user along.\n\n## Presenting your work and final message\n\nYour final message should read naturally, like an update from a concise teammate. For casual conversation, brainstorming tasks, or quick questions from the user, respond in a friendly, conversational tone. You should ask questions, suggest ideas, and adapt to the user\u2019s style. If you've finished a large amount of work, when describing what you've done to the user, you should follow the final answer formatting guidelines to communicate substantive changes. You don't need to add structured formatting for one-word answers, greetings, or purely conversational exchanges.\n\nYou can skip heavy formatting for single, simple actions or confirmations. In these cases, respond in plain sentences with any relevant next step or quick option. Reserve multi-section structured responses for results that need grouping or explanation.\n\nThe user is working on the same computer as you, and has access to your work. As such there's no need to show the full contents of large files you have already written unless the user explicitly asks for them. Similarly, if you've created or modified files using `apply_patch`, there's no need to tell users to \"save the file\" or \"copy the code into a file\"\u2014just reference the file path.\n\nIf there's something that you think you could help with as a logical next step, concisely ask the user if they want you to do so. Good examples of this are running tests, committing changes, or building out the next logical component. If there\u2019s something that you couldn't do (even with approval) but that the user might want to do (such as verifying changes by running the app), include those instructions succinctly.\n\nBrevity is very important as a default. You should be very concise (i.e. no more than 10 lines), but can relax this requirement for tasks where additional detail and comprehensiveness is important for the user's understanding.\n\n### Final answer structure and style guidelines\n\nYou are producing plain text that will later be styled by the CLI. Follow these rules exactly. Formatting should make results easy to scan, but not feel mechanical. Use judgment to decide how much structure adds value.\n\n**Section Headers**\n\n- Use only when they improve clarity \u2014 they are not mandatory for every answer.\n- Choose descriptive names that fit the content\n- Keep headers short (1\u20133 words) and in `**Title Case**`. Always start headers with `**` and end with `**`\n- Leave no blank line before the first bullet under a header.\n- Section headers should only be used where they genuinely improve scanability; avoid fragmenting the answer.\n\n**Bullets**\n\n- Use `-` followed by a space for every bullet.\n- Merge related points when possible; avoid a bullet for every trivial detail.\n- Keep bullets to one line unless breaking for clarity is unavoidable.\n- Group into short lists (4\u20136 bullets) ordered by importance.\n- Use consistent keyword phrasing and formatting across sections.\n\n**Monospace**\n\n- Wrap all commands, file paths, env vars, and code identifiers in backticks (`` `...` ``).\n- Apply to inline examples and to bullet keywords if the keyword itself is a literal file/command.\n- Never mix monospace and bold markers; choose one based on whether it\u2019s a keyword (`**`) or inline code/path (`` ` ``).\n\n**File References**\nWhen referencing files in your response, make sure to include the relevant start line and always follow the below rules:\n * Use inline code to make file paths clickable.\n * Each reference should have a stand alone path. Even if it's the same file.\n * Accepted: absolute, workspace\u2011relative, a/ or b/ diff prefixes, or bare filename/suffix.\n * Line/column (1\u2011based, optional): :line[:column] or #Lline[Ccolumn] (column defaults to 1).\n * Do not use URIs like file://, vscode://, or https://.\n * Do not provide range of lines\n * Examples: src/app.ts, src/app.ts:42, b/server/index.js#L10, C:\\repo\\project\\main.rs:12:5\n\n**Structure**\n\n- Place related bullets together; don\u2019t mix unrelated concepts in the same section.\n- Order sections from general \u2192 specific \u2192 supporting info.\n- For subsections (e.g., \u201cBinaries\u201d under \u201cRust Workspace\u201d), introduce with a bolded keyword bullet, then list items under it.\n- Match structure to complexity:\n - Multi-part or detailed results \u2192 use clear headers and grouped bullets.\n - Simple results \u2192 minimal headers, possibly just a short list or paragraph.\n\n**Tone**\n\n- Keep the voice collaborative and natural, like a coding partner handing off work.\n- Be concise and factual \u2014 no filler or conversational commentary and avoid unnecessary repetition\n- Use present tense and active voice (e.g., \u201cRuns tests\u201d not \u201cThis will run tests\u201d).\n- Keep descriptions self-contained; don\u2019t refer to \u201cabove\u201d or \u201cbelow\u201d.\n- Use parallel structure in lists for consistency.\n\n**Don\u2019t**\n\n- Don\u2019t use literal words \u201cbold\u201d or \u201cmonospace\u201d in the content.\n- Don\u2019t nest bullets or create deep hierarchies.\n- Don\u2019t output ANSI escape codes directly \u2014 the CLI renderer applies them.\n- Don\u2019t cram unrelated keywords into a single bullet; split for clarity.\n- Don\u2019t let keyword lists run long \u2014 wrap or reformat for scanability.\n\nGenerally, ensure your final answers adapt their shape and depth to the request. For example, answers to code explanations should have a precise, structured explanation with code references that answer the question directly. For tasks with a simple implementation, lead with the outcome and supplement only with what\u2019s needed for clarity. Larger changes can be presented as a logical walkthrough of your approach, grouping related steps, explaining rationale where it adds value, and highlighting next actions to accelerate the user. Your answers should provide the right level of detail while being easily scannable.\n\nFor casual greetings, acknowledgements, or other one-off conversational messages that are not delivering substantive information or structured results, respond naturally without section headers or bullet formatting.\n\n# Tool Guidelines\n\n## Shell commands\n\nWhen using the shell, you must adhere to the following guidelines:\n\n- When searching for text or files, prefer using `rg` or `rg --files` respectively because `rg` is much faster than alternatives like `grep`. (If the `rg` command is not found, then use alternatives.)\n- Do not use python scripts to attempt to output larger chunks of a file.\n\n## `update_plan`\n\nA tool named `update_plan` is available to you. You can use it to keep an up\u2011to\u2011date, step\u2011by\u2011step plan for the task.\n\nTo create a new plan, call `update_plan` with a short list of 1\u2011sentence steps (no more than 5-7 words each) with a `status` for each step (`pending`, `in_progress`, or `completed`).\n\nWhen steps have been completed, use `update_plan` to mark each finished step as `completed` and the next step you are working on as `in_progress`. There should always be exactly one `in_progress` step until everything is done. You can mark multiple items as complete in a single `update_plan` call.\n\nIf all steps are complete, ensure you call `update_plan` to mark all steps as `completed`.\n";
@@ -0,0 +1,217 @@
1
+ import os from 'node:os';
2
+ import path from 'node:path';
3
+ import { nowIso, readText, writeTextAtomic } from '../fsx.js';
4
+ import { CODEX_MODEL_CATALOG_MAX_MODELS, catalogModelRowBlockers, normalizeCodexModelId, readCodexModelCatalogFile, readTopLevelTomlString, sksOpenRouterCatalogPath } from './codex-model-catalog.js';
5
+ import { isSksManagedCatalogPath, resolveCatalogPath } from './multi-provider-router-support.js';
6
+ import { OPENROUTER_SELECTABLE_REASONING_EFFORTS } from './openrouter-provider.js';
7
+ import { OPENROUTER_CATALOG_BASE_INSTRUCTIONS } from './openrouter-base-instructions.js';
8
+ import { ensureTrailingNewline, removeTopLevelTomlKeyIfValue, safeWriteCodexConfigToml, upsertTopLevelTomlString } from '../codex-runtime/codex-desktop-config-policy.js';
9
+ import { readRoleModelPreferences } from '../subagents/role-model-preferences.js';
10
+ import { stampRoleModelCatalogPriorities } from './role-model-catalog-priority.js';
11
+ import { invalidateCodexModelsCache } from './codex-models-cache.js';
12
+ const OPENROUTER_REASONING_LEVEL_DESCRIPTIONS = {
13
+ none: 'No extra reasoning pass',
14
+ minimal: 'Fastest responses with minimal reasoning',
15
+ low: 'Fast responses with lighter reasoning',
16
+ medium: 'Balances speed and reasoning depth for everyday tasks',
17
+ high: 'Greater reasoning depth for complex problems',
18
+ xhigh: 'Extra high reasoning depth for complex problems'
19
+ };
20
+ export function openRouterCatalogModelRow(model) {
21
+ return {
22
+ slug: model,
23
+ display_name: model,
24
+ description: 'OpenRouter model activated by SKS',
25
+ default_reasoning_level: 'medium',
26
+ supported_reasoning_levels: OPENROUTER_SELECTABLE_REASONING_EFFORTS.map((effort) => ({
27
+ effort,
28
+ description: OPENROUTER_REASONING_LEVEL_DESCRIPTIONS[effort] || `${effort} reasoning`
29
+ })),
30
+ shell_type: 'default',
31
+ visibility: 'list',
32
+ supported_in_api: true,
33
+ priority: 0,
34
+ base_instructions: OPENROUTER_CATALOG_BASE_INSTRUCTIONS,
35
+ default_reasoning_summary: 'auto',
36
+ supports_reasoning_summaries: true,
37
+ support_verbosity: false,
38
+ truncation_policy: { mode: 'bytes', limit: 10_000 },
39
+ supports_parallel_tool_calls: true,
40
+ experimental_supported_tools: [],
41
+ input_modalities: ['text'],
42
+ context_window: 272_000,
43
+ max_context_window: 272_000,
44
+ multi_agent_version: 'v2'
45
+ };
46
+ }
47
+ export async function writeOpenRouterManagedCatalog(input) {
48
+ const env = input.env || process.env;
49
+ const home = input.home || env.HOME || os.homedir();
50
+ const catalogPath = sksOpenRouterCatalogPath({ home, env });
51
+ const model = normalizeCodexModelId(input.model);
52
+ if (!model) {
53
+ return {
54
+ schema: 'sks.openrouter-model-catalog-write.v1',
55
+ ok: false,
56
+ status: 'failed',
57
+ path: catalogPath,
58
+ models: [],
59
+ catalog: null,
60
+ blockers: ['openrouter_model_invalid'],
61
+ warnings: []
62
+ };
63
+ }
64
+ const warnings = [];
65
+ const existingRows = [];
66
+ const seenSlugs = new Set([model]);
67
+ const existingText = await readText(catalogPath, '');
68
+ if (existingText.trim()) {
69
+ try {
70
+ const parsed = JSON.parse(existingText);
71
+ if (parsed && typeof parsed === 'object' && Array.isArray(parsed.models)) {
72
+ for (const row of parsed.models) {
73
+ if (!row || typeof row !== 'object' || Array.isArray(row))
74
+ continue;
75
+ const slug = normalizeCodexModelId(row.slug);
76
+ if (!slug || seenSlugs.has(slug))
77
+ continue;
78
+ if (catalogModelRowBlockers(row).length) {
79
+ warnings.push(`openrouter_model_catalog_previous_row_dropped:${slug}`);
80
+ continue;
81
+ }
82
+ seenSlugs.add(slug);
83
+ existingRows.push(row);
84
+ }
85
+ }
86
+ else {
87
+ warnings.push('openrouter_model_catalog_previous_shape_invalid');
88
+ }
89
+ }
90
+ catch {
91
+ warnings.push('openrouter_model_catalog_previous_invalid_json');
92
+ }
93
+ }
94
+ const baseRows = [openRouterCatalogModelRow(model), ...existingRows].slice(0, CODEX_MODEL_CATALOG_MAX_MODELS);
95
+ const rolePrefs = await readRoleModelPreferences({ env }).catch(() => null);
96
+ const stamped = stampRoleModelCatalogPriorities(baseRows, rolePrefs?.store || null);
97
+ if (stamped.missing_from_catalog.length) {
98
+ warnings.push(...stamped.missing_from_catalog.map((slug) => `role_model_not_in_openrouter_catalog:${slug}`));
99
+ }
100
+ const rows = stamped.rows;
101
+ const nextText = `${JSON.stringify({ generated_at: nowIso(), generated_by: 'sks-openrouter-activation', models: rows }, null, 2)}\n`;
102
+ try {
103
+ await writeTextAtomic(catalogPath, nextText, { mode: 0o600 });
104
+ }
105
+ catch (err) {
106
+ return {
107
+ schema: 'sks.openrouter-model-catalog-write.v1',
108
+ ok: false,
109
+ status: 'failed',
110
+ path: catalogPath,
111
+ models: rows.map((row) => String(row.slug)),
112
+ catalog: null,
113
+ blockers: [`openrouter_model_catalog_write_failed:${err?.code || err?.message || 'unknown'}`],
114
+ warnings
115
+ };
116
+ }
117
+ const cache = await invalidateCodexModelsCache({ home, env, catalogPath, seedMode: 'merge' });
118
+ if (!cache.ok)
119
+ warnings.push(...cache.blockers);
120
+ else
121
+ warnings.push(...cache.warnings);
122
+ const catalog = await readCodexModelCatalogFile({ filePath: catalogPath, configured: true });
123
+ return {
124
+ schema: 'sks.openrouter-model-catalog-write.v1',
125
+ ok: catalog.ok && catalog.models.some((entry) => entry.model === model),
126
+ status: existingText.trim() === nextText.trim() ? 'current' : 'written',
127
+ path: catalogPath,
128
+ models: catalog.models.map((entry) => entry.model),
129
+ catalog,
130
+ models_cache: cache,
131
+ role_model_priority: {
132
+ stamped: stamped.stamped,
133
+ stamped_models: stamped.stamped_models,
134
+ missing_from_catalog: stamped.missing_from_catalog
135
+ },
136
+ blockers: catalog.blockers,
137
+ warnings
138
+ };
139
+ }
140
+ export function openRouterCatalogBindDecision(configText, input = {}) {
141
+ const env = input.env || process.env;
142
+ const home = input.home || env.HOME || os.homedir();
143
+ const catalogPath = sksOpenRouterCatalogPath({ home, env });
144
+ const configured = readTopLevelTomlString(String(configText || ''), 'model_catalog_json');
145
+ if (!configured)
146
+ return { bindable: true, bound: false, configured_path: null, reason: 'unconfigured' };
147
+ const resolved = resolveCatalogPath(configured, {
148
+ home,
149
+ env,
150
+ ...(input.configPath === undefined ? {} : { configPath: input.configPath })
151
+ });
152
+ if (resolved === path.resolve(catalogPath)) {
153
+ return { bindable: true, bound: true, configured_path: configured, reason: 'already_bound' };
154
+ }
155
+ if (isSksManagedCatalogPath(resolved, { home, env })) {
156
+ return { bindable: true, bound: false, configured_path: configured, reason: 'sks_managed_replaceable' };
157
+ }
158
+ return { bindable: false, bound: false, configured_path: configured, reason: 'user_catalog_preserved' };
159
+ }
160
+ export async function ensureOpenRouterModelCatalog(input) {
161
+ const env = input.env || process.env;
162
+ const home = input.home || env.HOME || os.homedir();
163
+ const current = await readText(input.configPath, '');
164
+ const selectedProvider = readTopLevelTomlString(current, 'model_provider');
165
+ if (selectedProvider !== 'openrouter') {
166
+ const bind = openRouterCatalogBindDecision(current, { home, env, configPath: input.configPath });
167
+ if (bind.bound) {
168
+ const configured = readTopLevelTomlString(current, 'model_catalog_json') || '';
169
+ const next = ensureTrailingNewline(removeTopLevelTomlKeyIfValue(current, 'model_catalog_json', configured));
170
+ const safeWrite = await safeWriteCodexConfigToml(input.configPath, current, next, 'openrouter-model-catalog-unbind');
171
+ return {
172
+ schema: 'sks.openrouter-model-catalog-repair.v1',
173
+ ok: safeWrite.ok,
174
+ status: safeWrite.ok ? 'unbound_dangling' : String(safeWrite.status || 'config_write_blocked'),
175
+ selected_provider: selectedProvider,
176
+ write: safeWrite,
177
+ blockers: safeWrite.ok ? [] : [String(safeWrite.status || 'openrouter_model_catalog_unbind_failed')],
178
+ warnings: []
179
+ };
180
+ }
181
+ return { schema: 'sks.openrouter-model-catalog-repair.v1', ok: true, status: 'skipped', reason: 'openrouter_not_selected' };
182
+ }
183
+ const model = normalizeCodexModelId(readTopLevelTomlString(current, 'model'));
184
+ if (!model) {
185
+ return { schema: 'sks.openrouter-model-catalog-repair.v1', ok: false, status: 'blocked', blockers: ['openrouter_model_missing'] };
186
+ }
187
+ const write = await writeOpenRouterManagedCatalog({ model, home, env });
188
+ const bind = openRouterCatalogBindDecision(current, { home, env, configPath: input.configPath });
189
+ if (!write.ok || !bind.bindable || bind.bound) {
190
+ return {
191
+ schema: 'sks.openrouter-model-catalog-repair.v1',
192
+ ok: write.ok,
193
+ status: write.ok ? (bind.bound ? 'current' : 'catalog_written_not_bound') : 'failed',
194
+ model,
195
+ catalog: write,
196
+ bind,
197
+ blockers: write.blockers,
198
+ warnings: [
199
+ ...write.warnings,
200
+ ...(bind.bindable || bind.bound ? [] : ['openrouter_model_catalog_user_catalog_preserved'])
201
+ ]
202
+ };
203
+ }
204
+ const next = ensureTrailingNewline(upsertTopLevelTomlString(current, 'model_catalog_json', write.path));
205
+ const safeWrite = await safeWriteCodexConfigToml(input.configPath, current, next, 'openrouter-model-catalog');
206
+ return {
207
+ schema: 'sks.openrouter-model-catalog-repair.v1',
208
+ ok: safeWrite.ok,
209
+ status: safeWrite.ok ? 'bound' : String(safeWrite.status || 'config_write_blocked'),
210
+ model,
211
+ catalog: write,
212
+ bind,
213
+ write: safeWrite,
214
+ blockers: safeWrite.ok ? [] : [String(safeWrite.status || 'openrouter_model_catalog_bind_failed')],
215
+ warnings: write.warnings
216
+ };
217
+ }
@@ -0,0 +1,61 @@
1
+ import { normalizeCodexModelId } from './codex-model-catalog.js';
2
+ export const CODEX_SUBAGENT_PICKER_PRIORITY_SLOTS = 5;
3
+ export function stampRoleModelCatalogPriorities(rows, store) {
4
+ const preferred = [];
5
+ const seen = new Set();
6
+ for (const preference of Object.values(store?.roles || {})) {
7
+ const model = normalizeCodexModelId(preference?.model);
8
+ if (!model || seen.has(model))
9
+ continue;
10
+ seen.add(model);
11
+ preferred.push(model);
12
+ }
13
+ const preferredLimited = preferred.slice(0, CODEX_SUBAGENT_PICKER_PRIORITY_SLOTS);
14
+ const preferredSet = new Set(preferredLimited);
15
+ const stampedModels = [];
16
+ const missing = preferredLimited.filter((model) => !rows.some((row) => normalizeCodexModelId(row.slug) === model));
17
+ const preferredRows = [];
18
+ const otherRows = [];
19
+ for (const row of rows) {
20
+ const slug = normalizeCodexModelId(row.slug);
21
+ if (slug && preferredSet.has(slug))
22
+ preferredRows.push({ ...row });
23
+ else
24
+ otherRows.push({ ...row });
25
+ }
26
+ preferredRows.sort((a, b) => {
27
+ const am = normalizeCodexModelId(a.slug) || '';
28
+ const bm = normalizeCodexModelId(b.slug) || '';
29
+ return preferredLimited.indexOf(am) - preferredLimited.indexOf(bm);
30
+ });
31
+ const next = [];
32
+ preferredRows.forEach((row, index) => {
33
+ const slug = normalizeCodexModelId(row.slug);
34
+ if (slug)
35
+ stampedModels.push(slug);
36
+ next.push({
37
+ ...row,
38
+ visibility: row.visibility === 'hide' ? 'list' : (row.visibility || 'list'),
39
+ supported_in_api: true,
40
+ multi_agent_version: row.multi_agent_version || 'v2',
41
+ priority: index
42
+ });
43
+ });
44
+ otherRows.forEach((row, index) => {
45
+ const previous = typeof row.priority === 'number' && Number.isFinite(row.priority)
46
+ ? Number(row.priority)
47
+ : CODEX_SUBAGENT_PICKER_PRIORITY_SLOTS + index;
48
+ next.push({
49
+ ...row,
50
+ priority: Math.max(CODEX_SUBAGENT_PICKER_PRIORITY_SLOTS, previous)
51
+ });
52
+ });
53
+ return {
54
+ schema: 'sks.role-model-catalog-priority-stamp.v1',
55
+ stamped: stampedModels.length > 0,
56
+ preferred_models: preferredLimited,
57
+ stamped_models: stampedModels,
58
+ missing_from_catalog: missing,
59
+ rows: next
60
+ };
61
+ }