@kbediako/codex-orchestrator 0.1.38 → 0.2.1

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 (311) hide show
  1. package/.agents/plugins/marketplace.json +20 -0
  2. package/README.md +46 -317
  3. package/bin/codex-orchestrator.js +161 -0
  4. package/codex.orchestrator.json +149 -13
  5. package/dist/bin/codex-orchestrator.js +797 -1154
  6. package/dist/orchestrator/src/cli/adapters/CommandBuilder.js +50 -0
  7. package/dist/orchestrator/src/cli/adapters/CommandPlanner.js +22 -4
  8. package/dist/orchestrator/src/cli/adapters/CommandReviewer.js +3 -3
  9. package/dist/orchestrator/src/cli/adapters/CommandTester.js +2 -2
  10. package/dist/orchestrator/src/cli/adapters/cloudFailureDiagnostics.js +295 -11
  11. package/dist/orchestrator/src/cli/coStatusAttachCliShell.js +402 -0
  12. package/dist/orchestrator/src/cli/coStatusCliShell.js +451 -0
  13. package/dist/orchestrator/src/cli/coStatusOperatorAutopilotCliShell.js +120 -0
  14. package/dist/orchestrator/src/cli/codexCliShell.js +119 -0
  15. package/dist/orchestrator/src/cli/codexDefaultsSetup.js +265 -36
  16. package/dist/orchestrator/src/cli/config/delegationConfig.js +317 -5
  17. package/dist/orchestrator/src/cli/config/repoConfigPolicy.js +2 -3
  18. package/dist/orchestrator/src/cli/config/userConfig.js +28 -13
  19. package/dist/orchestrator/src/cli/control/authenticatedControlRouteGate.js +69 -0
  20. package/dist/orchestrator/src/cli/control/authenticatedRouteComposition.js +267 -0
  21. package/dist/orchestrator/src/cli/control/authenticatedRouteController.js +5 -0
  22. package/dist/orchestrator/src/cli/control/authenticatedRouteDispatcher.js +41 -0
  23. package/dist/orchestrator/src/cli/control/compatibilityIssuePresenter.js +1035 -0
  24. package/dist/orchestrator/src/cli/control/confirmationApproveController.js +62 -0
  25. package/dist/orchestrator/src/cli/control/confirmationCreateController.js +69 -0
  26. package/dist/orchestrator/src/cli/control/confirmationIssueConsumeController.js +43 -0
  27. package/dist/orchestrator/src/cli/control/confirmationListController.js +22 -0
  28. package/dist/orchestrator/src/cli/control/confirmationValidateController.js +58 -0
  29. package/dist/orchestrator/src/cli/control/confirmations.js +25 -3
  30. package/dist/orchestrator/src/cli/control/controlActionCancelConfirmation.js +65 -0
  31. package/dist/orchestrator/src/cli/control/controlActionController.js +77 -0
  32. package/dist/orchestrator/src/cli/control/controlActionControllerSequencing.js +161 -0
  33. package/dist/orchestrator/src/cli/control/controlActionExecution.js +142 -0
  34. package/dist/orchestrator/src/cli/control/controlActionFinalization.js +43 -0
  35. package/dist/orchestrator/src/cli/control/controlActionOutcome.js +60 -0
  36. package/dist/orchestrator/src/cli/control/controlActionPreflight.js +476 -0
  37. package/dist/orchestrator/src/cli/control/controlAuthenticatedRouteHandoff.js +57 -0
  38. package/dist/orchestrator/src/cli/control/controlBootstrapAssembly.js +39 -0
  39. package/dist/orchestrator/src/cli/control/controlBootstrapMetadataPersistence.js +16 -0
  40. package/dist/orchestrator/src/cli/control/controlEventTransport.js +49 -0
  41. package/dist/orchestrator/src/cli/control/controlExpiryLifecycle.js +102 -0
  42. package/dist/orchestrator/src/cli/control/controlHostOwnership.js +480 -0
  43. package/dist/orchestrator/src/cli/control/controlHostSupervision.js +630 -0
  44. package/dist/orchestrator/src/cli/control/controlOversightFacade.js +8 -0
  45. package/dist/orchestrator/src/cli/control/controlOversightReadContract.js +1 -0
  46. package/dist/orchestrator/src/cli/control/controlOversightReadService.js +16 -0
  47. package/dist/orchestrator/src/cli/control/controlOversightUpdateContract.js +1 -0
  48. package/dist/orchestrator/src/cli/control/controlPersistenceFiles.js +6 -0
  49. package/dist/orchestrator/src/cli/control/controlQuestionChildResolution.js +18 -0
  50. package/dist/orchestrator/src/cli/control/controlRequestContext.js +42 -0
  51. package/dist/orchestrator/src/cli/control/controlRequestController.js +9 -0
  52. package/dist/orchestrator/src/cli/control/controlRequestPredispatch.js +17 -0
  53. package/dist/orchestrator/src/cli/control/controlRequestRouteDispatch.js +44 -0
  54. package/dist/orchestrator/src/cli/control/controlRuntime.js +1003 -0
  55. package/dist/orchestrator/src/cli/control/controlServer.js +23 -1456
  56. package/dist/orchestrator/src/cli/control/controlServerAuditAndErrorHelpers.js +115 -0
  57. package/dist/orchestrator/src/cli/control/controlServerAuthenticatedRouteBranch.js +29 -0
  58. package/dist/orchestrator/src/cli/control/controlServerBootstrapLifecycle.js +30 -0
  59. package/dist/orchestrator/src/cli/control/controlServerBootstrapStartSequence.js +21 -0
  60. package/dist/orchestrator/src/cli/control/controlServerOwnedRuntimeLifecycle.js +67 -0
  61. package/dist/orchestrator/src/cli/control/controlServerPublicLifecycle.js +756 -0
  62. package/dist/orchestrator/src/cli/control/controlServerPublicRouteHelpers.js +86 -0
  63. package/dist/orchestrator/src/cli/control/controlServerReadyInstanceLifecycle.js +25 -0
  64. package/dist/orchestrator/src/cli/control/controlServerReadyInstanceStartup.js +18 -0
  65. package/dist/orchestrator/src/cli/control/controlServerRequestBodyHelpers.js +37 -0
  66. package/dist/orchestrator/src/cli/control/controlServerRequestShell.js +40 -0
  67. package/dist/orchestrator/src/cli/control/controlServerRequestShellBinding.js +17 -0
  68. package/dist/orchestrator/src/cli/control/controlServerSeedLoading.js +27 -0
  69. package/dist/orchestrator/src/cli/control/controlServerSeededRuntimeAssembly.js +186 -0
  70. package/dist/orchestrator/src/cli/control/controlServerStartupInputPreparation.js +31 -0
  71. package/dist/orchestrator/src/cli/control/controlServerStartupSequence.js +49 -0
  72. package/dist/orchestrator/src/cli/control/controlState.js +233 -2
  73. package/dist/orchestrator/src/cli/control/controlStatusDashboard.js +1904 -0
  74. package/dist/orchestrator/src/cli/control/controlTelegramBridgeBootstrapLifecycle.js +22 -0
  75. package/dist/orchestrator/src/cli/control/controlTelegramBridgeLifecycle.js +67 -0
  76. package/dist/orchestrator/src/cli/control/controlTelegramBridgeOversightFacadeFactory.js +8 -0
  77. package/dist/orchestrator/src/cli/control/controlTelegramCommandController.js +49 -0
  78. package/dist/orchestrator/src/cli/control/controlTelegramDispatchRead.js +40 -0
  79. package/dist/orchestrator/src/cli/control/controlTelegramPollingController.js +89 -0
  80. package/dist/orchestrator/src/cli/control/controlTelegramProjectionNotificationController.js +29 -0
  81. package/dist/orchestrator/src/cli/control/controlTelegramPushState.js +63 -0
  82. package/dist/orchestrator/src/cli/control/controlTelegramQuestionRead.js +13 -0
  83. package/dist/orchestrator/src/cli/control/controlTelegramReadController.js +216 -0
  84. package/dist/orchestrator/src/cli/control/controlTelegramUpdateHandler.js +63 -0
  85. package/dist/orchestrator/src/cli/control/controlWatcher.js +73 -5
  86. package/dist/orchestrator/src/cli/control/delegationRegisterController.js +35 -0
  87. package/dist/orchestrator/src/cli/control/dynamicToolBridgePolicy.js +139 -0
  88. package/dist/orchestrator/src/cli/control/eventsSseController.js +12 -0
  89. package/dist/orchestrator/src/cli/control/linearBudgetState.js +1789 -0
  90. package/dist/orchestrator/src/cli/control/linearDispatchSource.js +1137 -0
  91. package/dist/orchestrator/src/cli/control/linearGraphqlClient.js +150 -0
  92. package/dist/orchestrator/src/cli/control/linearRateLimit.js +102 -0
  93. package/dist/orchestrator/src/cli/control/linearWebhookController.js +499 -0
  94. package/dist/orchestrator/src/cli/control/liveLinearAdvisoryRuntime.js +70 -0
  95. package/dist/orchestrator/src/cli/control/observabilityApiController.js +173 -0
  96. package/dist/orchestrator/src/cli/control/observabilityReadModel.js +500 -0
  97. package/dist/orchestrator/src/cli/control/observabilitySurface.js +284 -0
  98. package/dist/orchestrator/src/cli/control/observabilityUpdateNotifier.js +22 -0
  99. package/dist/orchestrator/src/cli/control/operatorDashboardPresenter.js +252 -0
  100. package/dist/orchestrator/src/cli/control/providerAgentCapacity.js +70 -0
  101. package/dist/orchestrator/src/cli/control/providerControlHostFreshnessGauge.js +1068 -0
  102. package/dist/orchestrator/src/cli/control/providerIntakeState.js +473 -0
  103. package/dist/orchestrator/src/cli/control/providerIssueHandoff.js +6811 -0
  104. package/dist/orchestrator/src/cli/control/providerIssueObservability.js +1348 -0
  105. package/dist/orchestrator/src/cli/control/providerIssueRetryQueue.js +84 -0
  106. package/dist/orchestrator/src/cli/control/providerLinearRuntimeProof.js +588 -0
  107. package/dist/orchestrator/src/cli/control/providerLinearScreenshotProof.js +473 -0
  108. package/dist/orchestrator/src/cli/control/providerLinearWorkerTruth.js +383 -0
  109. package/dist/orchestrator/src/cli/control/providerLinearWorkflowAudit.js +254 -0
  110. package/dist/orchestrator/src/cli/control/providerLinearWorkflowFacade.js +5573 -0
  111. package/dist/orchestrator/src/cli/control/providerLinearWorkflowStates.js +115 -0
  112. package/dist/orchestrator/src/cli/control/providerMergeCloseout.js +1868 -0
  113. package/dist/orchestrator/src/cli/control/providerOperatorAutopilot.js +1580 -0
  114. package/dist/orchestrator/src/cli/control/providerOperatorAutopilotLifecycle.js +154 -0
  115. package/dist/orchestrator/src/cli/control/providerOperatorAutopilotLocalRolloutExecution.js +1006 -0
  116. package/dist/orchestrator/src/cli/control/providerPollingHealth.js +435 -0
  117. package/dist/orchestrator/src/cli/control/providerTerminalCleanup.js +516 -0
  118. package/dist/orchestrator/src/cli/control/providerWorkerHosts.js +191 -0
  119. package/dist/orchestrator/src/cli/control/providerWorkflowConfigStore.js +515 -0
  120. package/dist/orchestrator/src/cli/control/questionChildResolutionAdapter.js +361 -0
  121. package/dist/orchestrator/src/cli/control/questionQueueController.js +181 -0
  122. package/dist/orchestrator/src/cli/control/questionReadRetryDeduplication.js +9 -0
  123. package/dist/orchestrator/src/cli/control/questionReadSequence.js +10 -0
  124. package/dist/orchestrator/src/cli/control/securityViolationController.js +27 -0
  125. package/dist/orchestrator/src/cli/control/selectedRunProjection.js +1885 -0
  126. package/dist/orchestrator/src/cli/control/telegramOversightApiClient.js +48 -0
  127. package/dist/orchestrator/src/cli/control/telegramOversightBridge.js +180 -0
  128. package/dist/orchestrator/src/cli/control/telegramOversightBridgeProjectionDeliveryQueue.js +25 -0
  129. package/dist/orchestrator/src/cli/control/telegramOversightBridgeRuntimeLifecycle.js +45 -0
  130. package/dist/orchestrator/src/cli/control/telegramOversightBridgeStateStore.js +77 -0
  131. package/dist/orchestrator/src/cli/control/telegramOversightControlActionApiClient.js +45 -0
  132. package/dist/orchestrator/src/cli/control/trackerDispatchPilot.js +439 -0
  133. package/dist/orchestrator/src/cli/control/uiDataController.js +34 -0
  134. package/dist/orchestrator/src/cli/control/uiSessionController.js +100 -0
  135. package/dist/orchestrator/src/cli/controlHostCliShell.js +860 -0
  136. package/dist/orchestrator/src/cli/controlHostFreshnessGaugeCliShell.js +129 -0
  137. package/dist/orchestrator/src/cli/controlHostSupervisionCliShell.js +2127 -0
  138. package/dist/orchestrator/src/cli/delegationCliShell.js +62 -0
  139. package/dist/orchestrator/src/cli/delegationServer.js +567 -678
  140. package/dist/orchestrator/src/cli/delegationServerCliShell.js +52 -0
  141. package/dist/orchestrator/src/cli/delegationServerQuestionFlowShell.js +228 -0
  142. package/dist/orchestrator/src/cli/delegationServerToolDispatchShell.js +411 -0
  143. package/dist/orchestrator/src/cli/delegationServerTransport.js +274 -0
  144. package/dist/orchestrator/src/cli/delegationSetup.js +51 -171
  145. package/dist/orchestrator/src/cli/devtoolsCliShell.js +34 -0
  146. package/dist/orchestrator/src/cli/doctor.js +678 -164
  147. package/dist/orchestrator/src/cli/doctorCliRequestShell.js +72 -0
  148. package/dist/orchestrator/src/cli/doctorCliShell.js +138 -0
  149. package/dist/orchestrator/src/cli/doctorUsage.js +119 -15
  150. package/dist/orchestrator/src/cli/exec/experience.js +16 -2
  151. package/dist/orchestrator/src/cli/exec/summary.js +3 -0
  152. package/dist/orchestrator/src/cli/execCliShell.js +51 -0
  153. package/dist/orchestrator/src/cli/flowCliRequestShell.js +44 -0
  154. package/dist/orchestrator/src/cli/flowCliShell.js +239 -0
  155. package/dist/orchestrator/src/cli/frontendTestCliRequestShell.js +80 -0
  156. package/dist/orchestrator/src/cli/frontendTestCliShell.js +41 -0
  157. package/dist/orchestrator/src/cli/init.js +95 -1
  158. package/dist/orchestrator/src/cli/initCliShell.js +50 -0
  159. package/dist/orchestrator/src/cli/linearCliShell.js +1200 -0
  160. package/dist/orchestrator/src/cli/mcpEnableCliShell.js +132 -0
  161. package/dist/orchestrator/src/cli/metrics/metricsAggregator.js +3 -2
  162. package/dist/orchestrator/src/cli/metrics/metricsRecorder.js +56 -0
  163. package/dist/orchestrator/src/cli/orchestrator.js +66 -1376
  164. package/dist/orchestrator/src/cli/planCliShell.js +19 -0
  165. package/dist/orchestrator/src/cli/prCliShell.js +41 -0
  166. package/dist/orchestrator/src/cli/providerLinearChildLanePhaseContract.js +204 -0
  167. package/dist/orchestrator/src/cli/providerLinearChildLaneRunner.js +1835 -0
  168. package/dist/orchestrator/src/cli/providerLinearChildLaneShell.js +2420 -0
  169. package/dist/orchestrator/src/cli/providerLinearChildStreamShell.js +385 -0
  170. package/dist/orchestrator/src/cli/providerLinearWorkerRunner.js +6834 -0
  171. package/dist/orchestrator/src/cli/resumeCliShell.js +14 -0
  172. package/dist/orchestrator/src/cli/reviewCliLaunchShell.js +72 -0
  173. package/dist/orchestrator/src/cli/rlm/alignment.js +3 -3
  174. package/dist/orchestrator/src/cli/rlm/context.js +94 -7
  175. package/dist/orchestrator/src/cli/rlm/rlmCodexRuntimeShell.js +546 -0
  176. package/dist/orchestrator/src/cli/rlm/symbolic.js +4 -2
  177. package/dist/orchestrator/src/cli/rlmCliRequestShell.js +42 -0
  178. package/dist/orchestrator/src/cli/rlmCompletionCliShell.js +46 -0
  179. package/dist/orchestrator/src/cli/rlmLaunchCliShell.js +51 -0
  180. package/dist/orchestrator/src/cli/rlmRunner.js +83 -523
  181. package/dist/orchestrator/src/cli/run/blockMemory.js +500 -0
  182. package/dist/orchestrator/src/cli/run/manifest.js +410 -73
  183. package/dist/orchestrator/src/cli/run/manifestPersister.js +45 -14
  184. package/dist/orchestrator/src/cli/run/runMemoryController.js +216 -0
  185. package/dist/orchestrator/src/cli/run/source0.js +690 -0
  186. package/dist/orchestrator/src/cli/run/workspacePath.js +101 -0
  187. package/dist/orchestrator/src/cli/runtime/mode.js +2 -1
  188. package/dist/orchestrator/src/cli/runtime/provider.js +39 -2
  189. package/dist/orchestrator/src/cli/selfCheckCliShell.js +12 -0
  190. package/dist/orchestrator/src/cli/services/commandRunner.js +698 -18
  191. package/dist/orchestrator/src/cli/services/execRuntime.js +66 -1
  192. package/dist/orchestrator/src/cli/services/orchestratorAutoScoutEvidenceRecorder.js +71 -0
  193. package/dist/orchestrator/src/cli/services/orchestratorCloudBranchResolution.js +8 -0
  194. package/dist/orchestrator/src/cli/services/orchestratorCloudEnvironmentResolution.js +22 -0
  195. package/dist/orchestrator/src/cli/services/orchestratorCloudExecutionLifecycleShell.js +39 -0
  196. package/dist/orchestrator/src/cli/services/orchestratorCloudPromptBuilder.js +37 -0
  197. package/dist/orchestrator/src/cli/services/orchestratorCloudRouteFallbackContract.js +45 -0
  198. package/dist/orchestrator/src/cli/services/orchestratorCloudRouteShell.js +36 -0
  199. package/dist/orchestrator/src/cli/services/orchestratorCloudTargetExecutor.js +277 -0
  200. package/dist/orchestrator/src/cli/services/orchestratorControlPlaneLifecycle.js +98 -0
  201. package/dist/orchestrator/src/cli/services/orchestratorControlPlaneLifecycleShell.js +54 -0
  202. package/dist/orchestrator/src/cli/services/orchestratorExecutionLifecycle.js +112 -0
  203. package/dist/orchestrator/src/cli/services/orchestratorExecutionModePolicy.js +27 -0
  204. package/dist/orchestrator/src/cli/services/orchestratorExecutionRouteAdapterShell.js +59 -0
  205. package/dist/orchestrator/src/cli/services/orchestratorExecutionRouteDecisionShell.js +57 -0
  206. package/dist/orchestrator/src/cli/services/orchestratorExecutionRouteState.js +21 -0
  207. package/dist/orchestrator/src/cli/services/orchestratorExecutionRouter.js +2 -0
  208. package/dist/orchestrator/src/cli/services/orchestratorLocalPipelineExecutor.js +149 -0
  209. package/dist/orchestrator/src/cli/services/orchestratorLocalRouteShell.js +63 -0
  210. package/dist/orchestrator/src/cli/services/orchestratorPlanShell.js +54 -0
  211. package/dist/orchestrator/src/cli/services/orchestratorPlanTargetTracker.js +16 -0
  212. package/dist/orchestrator/src/cli/services/orchestratorResumePreparationShell.js +84 -0
  213. package/dist/orchestrator/src/cli/services/orchestratorResumeTokenValidation.js +15 -0
  214. package/dist/orchestrator/src/cli/services/orchestratorRunLifecycleCompletion.js +31 -0
  215. package/dist/orchestrator/src/cli/services/orchestratorRunLifecycleExecutionRegistration.js +37 -0
  216. package/dist/orchestrator/src/cli/services/orchestratorRunLifecycleOrchestrationShell.js +83 -0
  217. package/dist/orchestrator/src/cli/services/orchestratorRunLifecycleTaskManagerShell.js +37 -0
  218. package/dist/orchestrator/src/cli/services/orchestratorRuntimeManifestMutation.js +20 -0
  219. package/dist/orchestrator/src/cli/services/orchestratorStartPreparationShell.js +56 -0
  220. package/dist/orchestrator/src/cli/services/orchestratorStatusShell.js +70 -0
  221. package/dist/orchestrator/src/cli/services/pipelineResolver.js +7 -3
  222. package/dist/orchestrator/src/cli/services/plannerMemory.js +119 -0
  223. package/dist/orchestrator/src/cli/services/runPreparation.js +7 -3
  224. package/dist/orchestrator/src/cli/services/runSummaryWriter.js +9 -0
  225. package/dist/orchestrator/src/cli/setupBootstrapShell.js +114 -0
  226. package/dist/orchestrator/src/cli/setupCliShell.js +51 -0
  227. package/dist/orchestrator/src/cli/skillsCliShell.js +56 -0
  228. package/dist/orchestrator/src/cli/startCliRequestShell.js +53 -0
  229. package/dist/orchestrator/src/cli/startCliShell.js +68 -0
  230. package/dist/orchestrator/src/cli/statusCliShell.js +22 -0
  231. package/dist/orchestrator/src/cli/utils/authProvenanceFingerprint.js +27 -0
  232. package/dist/orchestrator/src/cli/utils/cloudPreflight.js +285 -7
  233. package/dist/orchestrator/src/cli/utils/codexFeatures.js +60 -0
  234. package/dist/orchestrator/src/cli/utils/delegationConfigParser.js +250 -0
  235. package/dist/orchestrator/src/cli/utils/delegationMcpHealth.js +1382 -0
  236. package/dist/orchestrator/src/cli/utils/devtools.js +2 -54
  237. package/dist/orchestrator/src/cli/utils/mcpServerEntry.js +53 -0
  238. package/dist/orchestrator/src/cli/utils/packageProgramResolver.js +151 -0
  239. package/dist/orchestrator/src/cli/utils/providerOverrideEnv.js +71 -0
  240. package/dist/orchestrator/src/cli/utils/trailingJsonObject.js +59 -0
  241. package/dist/orchestrator/src/learning/crystalizer.js +2 -2
  242. package/dist/orchestrator/src/manager.js +74 -4
  243. package/dist/orchestrator/src/persistence/ExperienceStore.js +233 -49
  244. package/dist/orchestrator/src/persistence/TaskStateStore.js +6 -6
  245. package/dist/orchestrator/src/persistence/lockFile.js +70 -4
  246. package/dist/orchestrator/src/persistence/sanitizeIdentifier.js +39 -0
  247. package/dist/orchestrator/src/sync/createCloudSyncWorker.js +3 -2
  248. package/dist/orchestrator/src/utils/atomicWrite.js +17 -2
  249. package/dist/packages/orchestrator/src/exec/unified-exec.js +99 -6
  250. package/dist/packages/orchestrator/src/instructions/promptPacks.js +150 -19
  251. package/dist/packages/sdk-node/src/orchestrator.js +137 -13
  252. package/dist/packages/shared/config/designConfig.js +8 -1
  253. package/dist/packages/shared/streams/stdio.js +1 -1
  254. package/dist/scripts/design/pipeline/permit.js +15 -0
  255. package/dist/scripts/lib/docs-catalog.js +399 -0
  256. package/dist/scripts/lib/docs-helpers.js +87 -5
  257. package/dist/scripts/lib/pr-watch-merge.js +1088 -80
  258. package/dist/scripts/lib/provider-run-contract.js +26 -0
  259. package/dist/scripts/lib/review-command-intent-classification.js +532 -0
  260. package/dist/scripts/lib/review-command-probe-classification.js +385 -0
  261. package/dist/scripts/lib/review-execution-boundary-preflight.js +279 -0
  262. package/dist/scripts/lib/review-execution-runtime.js +753 -0
  263. package/dist/scripts/lib/review-execution-state.js +1144 -0
  264. package/dist/scripts/lib/review-execution-telemetry.js +215 -0
  265. package/dist/scripts/lib/review-inspection-target-parsing.js +78 -0
  266. package/dist/scripts/lib/review-launch-attempt.js +601 -0
  267. package/dist/scripts/lib/review-meta-surface-boundary-analysis.js +300 -0
  268. package/dist/scripts/lib/review-meta-surface-normalization.js +746 -0
  269. package/dist/scripts/lib/review-non-interactive-handoff.js +61 -0
  270. package/dist/scripts/lib/review-prompt-context.js +376 -0
  271. package/dist/scripts/lib/review-scope-advisory.js +286 -0
  272. package/dist/scripts/lib/review-scope-paths.js +123 -0
  273. package/dist/scripts/lib/review-shell-command-parser.js +389 -0
  274. package/dist/scripts/lib/review-shell-env-interpreter.js +340 -0
  275. package/dist/scripts/lib/run-manifests.js +192 -36
  276. package/dist/scripts/lib/spark-policy-classifier.js +593 -0
  277. package/dist/scripts/run-review.js +507 -1777
  278. package/docs/README.md +43 -20
  279. package/docs/book/README.md +19 -0
  280. package/docs/book/codex-cli-0124-adoption.md +68 -0
  281. package/docs/book/local-hook-impact.md +73 -0
  282. package/docs/book/operations.md +60 -0
  283. package/docs/book/public-posture.md +34 -0
  284. package/docs/book/setup.md +91 -0
  285. package/docs/book/skills.md +11 -0
  286. package/docs/guides/codex-version-policy.md +104 -0
  287. package/docs/public/downstream-setup.md +113 -0
  288. package/docs/public/provider-onboarding.md +173 -0
  289. package/package.json +23 -10
  290. package/plugins/codex-orchestrator/.codex-plugin/plugin.json +30 -0
  291. package/plugins/codex-orchestrator/.mcp.json +13 -0
  292. package/plugins/codex-orchestrator/launcher.mjs +361 -0
  293. package/schemas/manifest.json +411 -0
  294. package/skills/README.md +26 -0
  295. package/skills/collab-subagents-first/SKILL.md +1 -1
  296. package/skills/delegation-usage/DELEGATION_GUIDE.md +30 -12
  297. package/skills/delegation-usage/SKILL.md +25 -14
  298. package/skills/land/SKILL.md +77 -0
  299. package/skills/linear/SKILL.md +255 -0
  300. package/skills/release/SKILL.md +47 -3
  301. package/skills/standalone-review/SKILL.md +6 -1
  302. package/templates/README.md +4 -2
  303. package/templates/codex/.codex/agents/awaiter-high.toml +2 -2
  304. package/templates/codex/.codex/agents/worker-complex.toml +1 -1
  305. package/templates/codex/.codex/config.toml +3 -4
  306. package/templates/codex/.codex/providers/README.md +13 -0
  307. package/templates/codex/.codex/providers/control.example.json +18 -0
  308. package/templates/codex/.codex/providers/provider.env.example +15 -0
  309. package/templates/codex/AGENTS.md +15 -8
  310. package/templates/codex/mcp-client.json +5 -1
  311. package/docs/assets/setup.gif +0 -0
@@ -0,0 +1,1003 @@
1
+ import { readProviderPollingHealth, resolveControlPollingNextRefreshProjection } from './providerPollingHealth.js';
2
+ import { normalizeControlHostOwnershipPollingPayload } from './controlHostOwnership.js';
3
+ import { buildProviderIntakeSummary, isRecordLike } from './providerIntakeState.js';
4
+ import { buildTrackedLinearPayload, } from './observabilityReadModel.js';
5
+ import { buildCompatibilityProjectionSnapshot } from './compatibilityIssuePresenter.js';
6
+ import { createLiveLinearAdvisoryRuntime } from './liveLinearAdvisoryRuntime.js';
7
+ import { createObservabilityUpdateNotifier } from './observabilityUpdateNotifier.js';
8
+ import { resolveProviderPollDispatchLimits } from './providerAgentCapacity.js';
9
+ import { isProviderLinearWorkerProofFreshForStage } from './providerLinearWorkerTruth.js';
10
+ import { buildProviderIssueDebugSnapshot } from './providerIssueObservability.js';
11
+ import { classifyProviderLinearWorkflowState } from './providerLinearWorkflowStates.js';
12
+ import { createSelectedRunProjectionReader, discoverAuthoritativeRetryCollectionContexts, discoverCompatibilityCollectionContexts } from './selectedRunProjection.js';
13
+ const NULL_PROVIDER_RUNNING_FRESHNESS_MS = 10 * 60 * 1000;
14
+ const PROVIDER_RELEASED_PENDING_REOPEN_PREFIX = 'provider_issue_released_pending_reopen:';
15
+ const SYNTHETIC_LINEAR_TASK_ID_PATTERN = /^linear-[a-z0-9]+(?:-[a-z0-9]+)*$/i;
16
+ export function createControlRuntime(context, notifier = createObservabilityUpdateNotifier()) {
17
+ let cachedSnapshot = null;
18
+ let liveLinearAdvisoryRuntime = createLiveLinearAdvisoryRuntime({
19
+ controlStore: context.controlStore,
20
+ env: context.env
21
+ });
22
+ const ensureSnapshot = () => {
23
+ cachedSnapshot ??= createControlRuntimeSnapshot(context, liveLinearAdvisoryRuntime);
24
+ return cachedSnapshot;
25
+ };
26
+ const refreshSnapshot = async () => {
27
+ const nextAdvisoryRuntime = createLiveLinearAdvisoryRuntime({
28
+ controlStore: context.controlStore,
29
+ env: context.env
30
+ });
31
+ const nextSnapshot = createControlRuntimeSnapshot(context, nextAdvisoryRuntime);
32
+ await nextSnapshot.prime();
33
+ liveLinearAdvisoryRuntime = nextAdvisoryRuntime;
34
+ cachedSnapshot = nextSnapshot;
35
+ return nextSnapshot;
36
+ };
37
+ return {
38
+ snapshot() {
39
+ return ensureSnapshot();
40
+ },
41
+ async requestRefresh() {
42
+ await refreshSnapshot();
43
+ },
44
+ publish(input) {
45
+ cachedSnapshot = null;
46
+ liveLinearAdvisoryRuntime = createLiveLinearAdvisoryRuntime({
47
+ controlStore: context.controlStore,
48
+ env: context.env
49
+ });
50
+ notifier.publish(input);
51
+ },
52
+ subscribe(listener) {
53
+ return notifier.subscribe(listener);
54
+ }
55
+ };
56
+ }
57
+ function createControlRuntimeSnapshot(context, liveLinearAdvisoryRuntime) {
58
+ const selectedRunProjection = createSelectedRunProjectionReader(context);
59
+ const compatibilityProjectionSource = createSelectedRunProjectionReader(context);
60
+ let selectedRunSnapshotPromise = null;
61
+ let compatibilityRuntimeSnapshotPromise = null;
62
+ let compatibilityProjectionPromise = null;
63
+ let dispatchEvaluationPromise = null;
64
+ async function readSelectedRunSnapshot() {
65
+ selectedRunSnapshotPromise ??= (async () => {
66
+ const selected = enrichProjectionSourceWithProviderRetryState(suppressConflictingProjectionTrackedPayload(await selectedRunProjection.buildSelectedRunContext()), context.providerIntakeState);
67
+ const issueIdentifier = selected?.issueIdentifier ?? selected?.taskId ?? selected?.runId ?? null;
68
+ const dispatchPilotSummary = liveLinearAdvisoryRuntime.readSnapshotSummary(issueIdentifier);
69
+ const tracked = resolveRuntimeTrackedPayload(selected, context.linearAdvisoryState);
70
+ const providerIntake = buildProviderIntakeSummary(context.providerIntakeState);
71
+ const providerWorkflow = context.providerWorkflowConfigStore
72
+ ? await context.providerWorkflowConfigStore.refresh()
73
+ : null;
74
+ return {
75
+ selected,
76
+ dispatchPilot: dispatchPilotSummary.configured ? dispatchPilotSummary : null,
77
+ tracked,
78
+ providerIntake,
79
+ providerWorkflow
80
+ };
81
+ })();
82
+ return selectedRunSnapshotPromise;
83
+ }
84
+ async function readCompatibilityRuntimeSnapshot() {
85
+ compatibilityRuntimeSnapshotPromise ??= (async () => {
86
+ const selectedManifest = await compatibilityProjectionSource.readSelectedRunManifestSnapshot();
87
+ const selected = enrichProjectionSourceWithProviderRetryState(suppressConflictingProjectionTrackedPayload(await compatibilityProjectionSource.buildCompatibilitySourceContext(selectedManifest)), context.providerIntakeState);
88
+ const discoveredCollections = await discoverCompatibilityCollectionContexts(context);
89
+ const authoritativeRetrying = (await discoverAuthoritativeRetryCollectionContexts(context))
90
+ .map((source) => suppressConflictingProjectionTrackedPayload(source))
91
+ .filter((source) => source !== null);
92
+ const discoveredSources = discoveredCollections.all
93
+ .map((source) => suppressConflictingProjectionTrackedPayload(source))
94
+ .map((source) => enrichProjectionSourceWithProviderRetryState(source, context.providerIntakeState))
95
+ .filter((source) => source !== null);
96
+ const fallbackRetrying = discoveredCollections.retrying
97
+ .concat(isSelectedManifestRetryFallbackCandidate(selectedManifest, selected) ? [selected] : [])
98
+ .map((source) => suppressConflictingProjectionTrackedPayload(source))
99
+ .map((source) => enrichProjectionSourceWithProviderRetryState(source, context.providerIntakeState))
100
+ .filter((source) => source !== null);
101
+ const issueIdentifier = selected?.issueIdentifier ?? selected?.taskId ?? selected?.runId ?? null;
102
+ const dispatchPilotSummary = liveLinearAdvisoryRuntime.readSnapshotSummary(issueIdentifier);
103
+ const tracked = resolveRuntimeTrackedPayload(selected, context.linearAdvisoryState);
104
+ const providerIntake = buildProviderIntakeSummary(context.providerIntakeState);
105
+ const polling = readProviderPollingSnapshot(context);
106
+ const providerWorkflow = context.providerWorkflowConfigStore
107
+ ? await context.providerWorkflowConfigStore.refresh()
108
+ : null;
109
+ const running = [
110
+ ...(isAuthoritativeSelectedCurrentRunningSource(selected, context.providerIntakeState)
111
+ ? [selected]
112
+ : []),
113
+ ...discoveredSources.filter((source) => source.rawStatus === 'in_progress' &&
114
+ isAuthoritativeCurrentRunningSource(source, context.providerIntakeState))
115
+ ].filter((entry, index, collection) => collection.findIndex((candidate) => candidate.runId === entry.runId) === index);
116
+ const retryingSource = (context.providerIntakeState?.claims.length ?? 0) > 0 ? authoritativeRetrying : fallbackRetrying;
117
+ const retrying = retryingSource.filter((entry, index, collection) => collection.findIndex((candidate) => candidate.issueIdentifier === entry.issueIdentifier) === index);
118
+ const telemetrySources = buildCompatibilityTelemetrySources({
119
+ selected,
120
+ running,
121
+ retrying
122
+ });
123
+ const { codexTotals, rateLimits } = buildCompatibilityTelemetrySnapshot(telemetrySources, polling);
124
+ return {
125
+ selected,
126
+ running,
127
+ retrying,
128
+ maxConcurrentAgents: resolveProviderPollDispatchLimits(context.controlStore.snapshot().feature_toggles, {
129
+ localWorkerOnly: (providerWorkflow?.worker_hosts?.length ?? 0) === 0
130
+ }).maxConcurrentAgents,
131
+ codexTotals,
132
+ rateLimits,
133
+ dispatchPilot: dispatchPilotSummary.configured ? dispatchPilotSummary : null,
134
+ tracked,
135
+ providerIntake,
136
+ providerWorkflow,
137
+ polling
138
+ };
139
+ })();
140
+ return compatibilityRuntimeSnapshotPromise;
141
+ }
142
+ async function readCompatibilityProjection() {
143
+ const runtimeSnapshot = await readCompatibilityRuntimeSnapshot();
144
+ // Cache the stable projection shape once, but re-derive polling-backed rate limits on every
145
+ // read so current Linear budget data is reflected without invalidating the rest of the snapshot.
146
+ compatibilityProjectionPromise ??= Promise.resolve(buildCompatibilityProjectionSnapshot(runtimeSnapshot));
147
+ const polling = readProviderPollingSnapshot(context);
148
+ const telemetrySources = buildCompatibilityTelemetrySources({
149
+ selected: runtimeSnapshot.selected,
150
+ running: runtimeSnapshot.running,
151
+ retrying: runtimeSnapshot.retrying
152
+ });
153
+ const { rateLimits } = buildCompatibilityTelemetrySnapshot(telemetrySources, polling);
154
+ return {
155
+ ...(await compatibilityProjectionPromise),
156
+ rateLimits,
157
+ polling
158
+ };
159
+ }
160
+ async function readDispatchEvaluation() {
161
+ if (dispatchEvaluationPromise) {
162
+ return dispatchEvaluationPromise;
163
+ }
164
+ const promise = (async () => {
165
+ const snapshot = await readSelectedRunSnapshot();
166
+ const selectedIssueIdentifier = snapshot.selected?.issueIdentifier ?? null;
167
+ const evaluation = await liveLinearAdvisoryRuntime.readDispatchEvaluation(selectedIssueIdentifier);
168
+ return {
169
+ issueIdentifier: evaluation.recommendation?.tracked_issue?.identifier ??
170
+ evaluation.recommendation?.issue_identifier ??
171
+ null,
172
+ evaluation
173
+ };
174
+ })();
175
+ const wrappedPromise = promise.catch((error) => {
176
+ if (dispatchEvaluationPromise === wrappedPromise) {
177
+ dispatchEvaluationPromise = null;
178
+ }
179
+ throw error;
180
+ });
181
+ dispatchEvaluationPromise = wrappedPromise;
182
+ return dispatchEvaluationPromise;
183
+ }
184
+ return {
185
+ readSelectedRunSnapshot,
186
+ readCompatibilityProjection,
187
+ readDispatchEvaluation,
188
+ async prime() {
189
+ await readSelectedRunSnapshot();
190
+ }
191
+ };
192
+ }
193
+ function readProviderPollingSnapshot(context) {
194
+ const livePolling = readProviderPollingHealth(context.readProviderIssueHandoff?.() ?? null);
195
+ const persistedPolling = normalizePersistedProviderPollingSnapshot(context.providerIntakeState?.polling);
196
+ if (persistedPolling && livePolling?.updated_at === null) {
197
+ return persistedPolling;
198
+ }
199
+ return livePolling ?? persistedPolling;
200
+ }
201
+ function normalizePersistedProviderPollingSnapshot(polling) {
202
+ if (!isRecordLike(polling)) {
203
+ return null;
204
+ }
205
+ const linearBudget = normalizeLinearBudgetSnapshot(polling.linear_budget);
206
+ const nextRefresh = resolveControlPollingNextRefreshProjection({
207
+ checking: polling.checking === true,
208
+ nextPollAt: typeof polling.next_poll_at === 'string' ? polling.next_poll_at : null,
209
+ nextPollInMs: typeof polling.next_poll_in_ms === 'number' && Number.isFinite(polling.next_poll_in_ms)
210
+ ? polling.next_poll_in_ms
211
+ : null,
212
+ operationStartedAt: typeof polling.operation_started_at === 'string' ? polling.operation_started_at : null,
213
+ linearBudget
214
+ });
215
+ return {
216
+ enabled: polling.enabled !== false,
217
+ interval_ms: typeof polling.interval_ms === 'number' && Number.isFinite(polling.interval_ms)
218
+ ? polling.interval_ms
219
+ : null,
220
+ checking: polling.checking === true,
221
+ queued: polling.queued === true,
222
+ last_mode: polling.last_mode === 'poll' || polling.last_mode === 'refresh' ? polling.last_mode : null,
223
+ last_requested_at: typeof polling.last_requested_at === 'string' ? polling.last_requested_at : null,
224
+ last_completed_at: typeof polling.last_completed_at === 'string' ? polling.last_completed_at : null,
225
+ last_success_at: typeof polling.last_success_at === 'string' ? polling.last_success_at : null,
226
+ last_error_at: typeof polling.last_error_at === 'string' ? polling.last_error_at : null,
227
+ last_error: typeof polling.last_error === 'string' ? polling.last_error : null,
228
+ next_poll_at: typeof polling.next_poll_at === 'string' ? polling.next_poll_at : null,
229
+ next_poll_in_ms: typeof polling.next_poll_in_ms === 'number' && Number.isFinite(polling.next_poll_in_ms)
230
+ ? polling.next_poll_in_ms
231
+ : null,
232
+ next_refresh_state: nextRefresh.state,
233
+ next_refresh_at: nextRefresh.at,
234
+ next_refresh_in_ms: nextRefresh.in_ms,
235
+ source_updated_at: typeof polling.source_updated_at === 'string' ? polling.source_updated_at : null,
236
+ updated_at: typeof polling.updated_at === 'string' ? polling.updated_at : null,
237
+ operation_started_at: typeof polling.operation_started_at === 'string' ? polling.operation_started_at : null,
238
+ operation_elapsed_ms: typeof polling.operation_elapsed_ms === 'number' && Number.isFinite(polling.operation_elapsed_ms)
239
+ ? polling.operation_elapsed_ms
240
+ : null,
241
+ stalled_after_ms: typeof polling.stalled_after_ms === 'number' && Number.isFinite(polling.stalled_after_ms)
242
+ ? polling.stalled_after_ms
243
+ : null,
244
+ refresh_phase: normalizeOptionalPollingString(polling.refresh_phase),
245
+ refresh_request_class: normalizeOptionalPollingString(polling.refresh_request_class),
246
+ refresh_provider_keys: normalizePollingStringArray(polling.refresh_provider_keys),
247
+ refresh_counts: normalizePollingRefreshCounts(polling.refresh_counts),
248
+ stuck: polling.stuck === true,
249
+ stuck_since_at: typeof polling.stuck_since_at === 'string' ? polling.stuck_since_at : null,
250
+ restart_required: polling.restart_required === true,
251
+ reason: typeof polling.reason === 'string' ? polling.reason : null,
252
+ linear_budget: linearBudget,
253
+ control_host_owner: normalizeControlHostOwnershipPollingPayload(polling.control_host_owner)
254
+ };
255
+ }
256
+ function normalizePollingRefreshCounts(value) {
257
+ if (!isRecordLike(value)) {
258
+ return null;
259
+ }
260
+ const normalized = {};
261
+ for (const [rawKey, count] of Object.entries(value)) {
262
+ const key = rawKey.trim();
263
+ if (key.length === 0 || typeof count !== 'number' || !Number.isFinite(count)) {
264
+ continue;
265
+ }
266
+ normalized[key] = count;
267
+ }
268
+ return Object.keys(normalized).length > 0 ? normalized : null;
269
+ }
270
+ function normalizePollingStringArray(value) {
271
+ if (!Array.isArray(value)) {
272
+ return null;
273
+ }
274
+ const normalized = value
275
+ .map((entry) => normalizeOptionalPollingString(entry))
276
+ .filter((entry) => entry !== null);
277
+ return normalized.length > 0 ? normalized : null;
278
+ }
279
+ function normalizeOptionalPollingString(value) {
280
+ return typeof value === 'string' && value.trim().length > 0 ? value.trim() : null;
281
+ }
282
+ function normalizeLinearBudgetSnapshot(value) {
283
+ if (!isRecordLike(value)) {
284
+ return null;
285
+ }
286
+ if (typeof value.observed_at !== 'string') {
287
+ return null;
288
+ }
289
+ return {
290
+ observed_at: value.observed_at,
291
+ source: typeof value.source === 'string' ? value.source : 'unknown',
292
+ request_id: typeof value.request_id === 'string' ? value.request_id : null,
293
+ retry_after_seconds: typeof value.retry_after_seconds === 'number' && Number.isFinite(value.retry_after_seconds)
294
+ ? value.retry_after_seconds
295
+ : null,
296
+ cooldown_until: typeof value.cooldown_until === 'string' ? value.cooldown_until : null,
297
+ cooldown_active: value.cooldown_active === true,
298
+ suppression: value.suppression === 'cooldown' ||
299
+ value.suppression === 'exhausted' ||
300
+ value.suppression === 'low' ||
301
+ value.suppression === 'constrained'
302
+ ? value.suppression
303
+ : 'none',
304
+ suppression_reason: typeof value.suppression_reason === 'string' ? value.suppression_reason : null,
305
+ scope_kind: value.scope_kind === 'user' ? 'user' : 'token',
306
+ scope_key: typeof value.scope_key === 'string' && value.scope_key.trim().length > 0 ? value.scope_key : 'legacy',
307
+ viewer_id: typeof value.viewer_id === 'string' ? value.viewer_id : null,
308
+ workspace_id: typeof value.workspace_id === 'string' ? value.workspace_id : null,
309
+ token_fingerprints: Array.isArray(value.token_fingerprints)
310
+ ? value.token_fingerprints.filter((entry) => typeof entry === 'string' && entry.length > 0)
311
+ : [],
312
+ requests: normalizeLinearBudgetBucketSnapshot(value.requests),
313
+ endpoint_requests: normalizeLinearBudgetBucketSnapshot(value.endpoint_requests),
314
+ complexity: normalizeLinearBudgetBucketSnapshot(value.complexity),
315
+ endpoint_complexity: normalizeLinearBudgetBucketSnapshot(value.endpoint_complexity),
316
+ endpoint_name: typeof value.endpoint_name === 'string' ? value.endpoint_name : null,
317
+ selected_endpoint_key: typeof value.selected_endpoint_key === 'string' ? value.selected_endpoint_key : null,
318
+ request_complexity: typeof value.request_complexity === 'number' && Number.isFinite(value.request_complexity)
319
+ ? value.request_complexity
320
+ : null,
321
+ // `endpoints: {}` and `reservations: []` are intentionally discarded here:
322
+ // runtime state is rebuilt from live budget data and only metadata such as
323
+ // `reservations_active` is preserved from persisted snapshots.
324
+ endpoints: {},
325
+ reservations: [],
326
+ reservations_active: typeof value.reservations_active === 'number' && Number.isFinite(value.reservations_active)
327
+ ? value.reservations_active
328
+ : 0
329
+ };
330
+ }
331
+ function normalizeLinearBudgetBucketSnapshot(value) {
332
+ if (!isRecordLike(value)) {
333
+ return null;
334
+ }
335
+ const limit = typeof value.limit === 'number' && Number.isFinite(value.limit) ? value.limit : null;
336
+ const remaining = typeof value.remaining === 'number' && Number.isFinite(value.remaining) ? value.remaining : null;
337
+ const resetAt = typeof value.reset_at === 'string' ? value.reset_at : null;
338
+ if (limit === null && remaining === null && resetAt === null) {
339
+ return null;
340
+ }
341
+ return {
342
+ limit,
343
+ remaining,
344
+ reset_at: resetAt
345
+ };
346
+ }
347
+ function enrichProjectionSourceWithProviderRetryState(source, providerIntakeState) {
348
+ if (!source || !providerIntakeState) {
349
+ return source;
350
+ }
351
+ const claim = findMatchingProviderIntakeClaim(providerIntakeState, source);
352
+ const retryState = buildProviderRetryState(claim);
353
+ const providerProof = source.providerLinearWorkerProof &&
354
+ isProviderLinearWorkerProofFreshForStage(source.providerLinearWorkerProof, source.startedAt) &&
355
+ !hasStaleLocalProviderInProgressProof(source.providerLinearWorkerProof, source.startedAt)
356
+ ? source.providerLinearWorkerProof
357
+ : null;
358
+ const providerDebugSnapshot = claim !== null
359
+ ? buildProviderIssueDebugSnapshot({
360
+ tracked_issue: source.tracked?.linear ?? null,
361
+ claim,
362
+ proof: providerProof,
363
+ rehydrated_at: providerIntakeState.rehydrated_at ?? null
364
+ }) ?? source.providerDebugSnapshot ?? null
365
+ : source.providerDebugSnapshot ?? null;
366
+ if (!retryState && providerDebugSnapshot === source.providerDebugSnapshot) {
367
+ return source;
368
+ }
369
+ return {
370
+ ...source,
371
+ ...(providerDebugSnapshot ? { providerDebugSnapshot } : {}),
372
+ ...(retryState ? { providerRetryState: retryState } : {})
373
+ };
374
+ }
375
+ function buildProviderRetryState(claim) {
376
+ if (!claim) {
377
+ return null;
378
+ }
379
+ const active = claim.retry_queued === true;
380
+ const attempt = claim.retry_attempt ?? null;
381
+ const dueAt = claim.retry_due_at ?? null;
382
+ const error = claim.retry_error ?? null;
383
+ if (!active && attempt === null && dueAt === null && error === null) {
384
+ return null;
385
+ }
386
+ return {
387
+ active,
388
+ attempt,
389
+ due_at: dueAt,
390
+ error
391
+ };
392
+ }
393
+ function isAuthoritativeSelectedCurrentRunningSource(source, providerIntakeState) {
394
+ if (!source || source.rawStatus !== 'in_progress') {
395
+ return false;
396
+ }
397
+ if (!providerIntakeState) {
398
+ if (source.taskId !== 'local-mcp') {
399
+ return true;
400
+ }
401
+ return (!isControlHostSelectedFallbackSource(source) && isFreshNullProviderRunningSource(source));
402
+ }
403
+ const claim = findMatchingProviderIntakeClaim(providerIntakeState, source);
404
+ if (claim !== null) {
405
+ if (isProviderIntakeClaimActiveForSourceCurrentActivity(claim, source)) {
406
+ return true;
407
+ }
408
+ const claimBoundToSource = isProviderIntakeClaimBoundToCompatibilitySource(claim, source);
409
+ const claimMatchesSelectedTask = isAuthoritativeProviderTaskIdMatch(claim, source);
410
+ if ((claimBoundToSource || claimMatchesSelectedTask) &&
411
+ claim.state === 'released' &&
412
+ isProviderIssueReleasedLiveWorkerRehydrateReason(claim.reason) &&
413
+ !isProviderStartedWorkerSourceIssueState(claim, source)) {
414
+ return false;
415
+ }
416
+ if ((claimBoundToSource || claimMatchesSelectedTask) &&
417
+ hasStaleLocalProviderInProgressProof(source.providerLinearWorkerProof, source.startedAt)) {
418
+ return false;
419
+ }
420
+ if (claimBoundToSource) {
421
+ return false;
422
+ }
423
+ }
424
+ if (source.taskId !== 'local-mcp') {
425
+ return true;
426
+ }
427
+ if (source.taskId === 'local-mcp' && !hasExplicitCompatibilityIssueIdentity(source)) {
428
+ return false;
429
+ }
430
+ return isFreshNullProviderRunningSource(source);
431
+ }
432
+ function isControlHostSelectedFallbackSource(source) {
433
+ return (source.issueProvider === null &&
434
+ source.taskId === 'local-mcp' &&
435
+ !hasExplicitCompatibilityIssueIdentity(source));
436
+ }
437
+ function findMatchingProviderIntakeClaim(providerIntakeState, source) {
438
+ let bestClaim = null;
439
+ let bestScore = 0;
440
+ for (const claim of providerIntakeState.claims) {
441
+ const score = scoreProviderClaimMatch(claim, source);
442
+ if (score > bestScore) {
443
+ bestScore = score;
444
+ bestClaim = claim;
445
+ continue;
446
+ }
447
+ if (score === bestScore && score > 0 && bestClaim) {
448
+ if (compareIsoTimestamp(claim.updated_at, bestClaim.updated_at) > 0) {
449
+ bestClaim = claim;
450
+ }
451
+ }
452
+ }
453
+ return bestScore > 0 ? bestClaim : null;
454
+ }
455
+ function isProviderIntakeClaimBoundToCompatibilitySource(claim, source) {
456
+ const manifestBinding = claim.run_manifest_path && source.manifestPath
457
+ ? claim.run_manifest_path === source.manifestPath
458
+ : null;
459
+ if (manifestBinding !== null) {
460
+ return manifestBinding;
461
+ }
462
+ const runBinding = claim.run_id && source.runId
463
+ ? claim.run_id === source.runId && claim.task_id === source.taskId
464
+ : null;
465
+ if (runBinding !== null) {
466
+ return runBinding;
467
+ }
468
+ return isAuthoritativeProviderTaskIdMatch(claim, source);
469
+ }
470
+ function scoreProviderClaimMatch(claim, source) {
471
+ let score = 0;
472
+ const allowRunBindingMatch = canScoreProviderRunBindingMatch(claim, source);
473
+ const authoritativeIssueId = readAuthoritativeProviderIssueId(source);
474
+ const authoritativeIssueIdentifier = readAuthoritativeProviderIssueIdentifier(source);
475
+ if (claim.issue_id && authoritativeIssueId && claim.issue_id === authoritativeIssueId) {
476
+ score += 16;
477
+ }
478
+ if (claim.issue_identifier && authoritativeIssueIdentifier && claim.issue_identifier === authoritativeIssueIdentifier) {
479
+ score += 12;
480
+ }
481
+ if (isAuthoritativeProviderTaskIdMatch(claim, source)) {
482
+ score += 8;
483
+ }
484
+ if (allowRunBindingMatch && claim.run_id && source.runId && claim.run_id === source.runId) {
485
+ score += 6;
486
+ }
487
+ if (allowRunBindingMatch &&
488
+ claim.run_manifest_path &&
489
+ source.manifestPath &&
490
+ claim.run_manifest_path === source.manifestPath) {
491
+ score += 10;
492
+ }
493
+ return score;
494
+ }
495
+ function canScoreProviderRunBindingMatch(claim, source) {
496
+ if (source.taskId !== 'local-mcp') {
497
+ return true;
498
+ }
499
+ if (!hasExplicitCompatibilityIssueIdentity(source)) {
500
+ return true;
501
+ }
502
+ return hasMatchingProviderIssueIdentity(claim, source);
503
+ }
504
+ function isAuthoritativeProviderTaskIdMatch(claim, source) {
505
+ if (!claim.task_id || !source.taskId || claim.task_id !== source.taskId) {
506
+ return false;
507
+ }
508
+ if (source.taskId !== 'local-mcp') {
509
+ return true;
510
+ }
511
+ const authoritativeIssueId = readAuthoritativeProviderIssueId(source);
512
+ const authoritativeIssueIdentifier = readAuthoritativeProviderIssueIdentifier(source);
513
+ return ((claim.issue_id != null && authoritativeIssueId != null && claim.issue_id === authoritativeIssueId) ||
514
+ (claim.issue_identifier != null &&
515
+ authoritativeIssueIdentifier != null &&
516
+ claim.issue_identifier === authoritativeIssueIdentifier));
517
+ }
518
+ function isSelectedManifestRetryFallbackCandidate(selectedManifest, selected) {
519
+ if (!selectedManifest || !selected || selected.completedAt !== null) {
520
+ return false;
521
+ }
522
+ const manifestRecord = selectedManifest.manifestRecord;
523
+ const provider = normalizeManifestString(manifestRecord.issue_provider) ??
524
+ normalizeManifestString(manifestRecord.issueProvider);
525
+ const status = normalizeManifestString(manifestRecord.status);
526
+ return provider === 'linear' && (status === 'failed' || status === 'cancelled');
527
+ }
528
+ function normalizeManifestString(value) {
529
+ if (typeof value !== 'string') {
530
+ return null;
531
+ }
532
+ const trimmed = value.trim();
533
+ return trimmed.length > 0 ? trimmed : null;
534
+ }
535
+ function compareIsoTimestamp(left, right) {
536
+ const leftValue = Date.parse(left ?? '');
537
+ const rightValue = Date.parse(right ?? '');
538
+ if (!Number.isFinite(leftValue) && !Number.isFinite(rightValue)) {
539
+ return 0;
540
+ }
541
+ if (!Number.isFinite(leftValue)) {
542
+ return -1;
543
+ }
544
+ if (!Number.isFinite(rightValue)) {
545
+ return 1;
546
+ }
547
+ return leftValue - rightValue;
548
+ }
549
+ function isAuthoritativeCurrentRunningSource(source, providerIntakeState) {
550
+ if (!providerIntakeState) {
551
+ return (source.issueProvider !== null ||
552
+ (hasExplicitCompatibilityIssueIdentity(source) && isFreshNullProviderRunningSource(source)));
553
+ }
554
+ const claim = findMatchingProviderIntakeClaim(providerIntakeState, source);
555
+ if (source.issueProvider === null) {
556
+ if (claim !== null) {
557
+ return isProviderIntakeClaimActiveForSourceCurrentActivity(claim, source);
558
+ }
559
+ return (hasExplicitCompatibilityIssueIdentity(source) &&
560
+ isFreshNullProviderRunningSource(source));
561
+ }
562
+ if (!isProviderIntakeScopedRunningSource(source)) {
563
+ return true;
564
+ }
565
+ return claim !== null && isProviderIntakeClaimActiveForSourceCurrentActivity(claim, source);
566
+ }
567
+ function isProviderIntakeScopedRunningSource(source) {
568
+ return source.issueProvider === 'linear';
569
+ }
570
+ function hasMatchingProviderIssueIdentity(claim, source) {
571
+ const authoritativeIssueId = readAuthoritativeProviderIssueId(source);
572
+ const authoritativeIssueIdentifier = readAuthoritativeProviderIssueIdentifier(source);
573
+ return ((claim.issue_id != null &&
574
+ authoritativeIssueId != null &&
575
+ claim.issue_id === authoritativeIssueId) ||
576
+ (claim.issue_identifier != null &&
577
+ authoritativeIssueIdentifier != null &&
578
+ claim.issue_identifier === authoritativeIssueIdentifier));
579
+ }
580
+ function readAuthoritativeProviderIssueId(source) {
581
+ const issueId = source.issueId ?? null;
582
+ if (!issueId) {
583
+ return null;
584
+ }
585
+ return isFallbackCompatibilityIdentityValue(issueId, source) ? null : issueId;
586
+ }
587
+ function readAuthoritativeProviderIssueIdentifier(source) {
588
+ const issueIdentifier = source.issueIdentifier ?? null;
589
+ if (!issueIdentifier) {
590
+ return null;
591
+ }
592
+ return isFallbackCompatibilityIdentityValue(issueIdentifier, source) ? null : issueIdentifier;
593
+ }
594
+ function isFallbackCompatibilityIdentityValue(value, source) {
595
+ return (isFallbackCompatibilityIdentityAlias(value, source.taskId, source) ||
596
+ isFallbackCompatibilityIdentityAlias(value, source.runId, source));
597
+ }
598
+ function isFallbackCompatibilityIdentityAlias(value, candidate, source) {
599
+ if (!candidate) {
600
+ return false;
601
+ }
602
+ if (value === candidate) {
603
+ return true;
604
+ }
605
+ return (hasSyntheticLinearFallbackProvenance(source) &&
606
+ SYNTHETIC_LINEAR_TASK_ID_PATTERN.test(value) &&
607
+ candidate.startsWith(`${value}-`));
608
+ }
609
+ function resolveRuntimeTrackedPayload(selected, advisoryState) {
610
+ if (selected?.tracked) {
611
+ if (linearTrackedIssueConflictsWithAuthoritativeIdentity(selected, selected.tracked.linear)) {
612
+ return null;
613
+ }
614
+ return selected.tracked;
615
+ }
616
+ if (advisoryState.stale_source) {
617
+ return null;
618
+ }
619
+ const advisoryTrackedIssue = advisoryState.tracked_issue;
620
+ if (!advisoryTrackedIssue) {
621
+ return null;
622
+ }
623
+ if (linearTrackedIssueConflictsWithAuthoritativeIdentity(selected, advisoryTrackedIssue)) {
624
+ return null;
625
+ }
626
+ return buildTrackedLinearPayload(advisoryTrackedIssue);
627
+ }
628
+ function suppressConflictingProjectionTrackedPayload(source) {
629
+ if (!source?.tracked) {
630
+ return source;
631
+ }
632
+ if (!linearTrackedIssueConflictsWithAuthoritativeIdentity(source, source.tracked.linear)) {
633
+ return source;
634
+ }
635
+ const shouldResetDisplayStatus = source.compatibilityState !== null &&
636
+ source.compatibilityState !== undefined &&
637
+ source.displayStatus === source.compatibilityState;
638
+ const providerDebugSnapshot = clearProviderDebugLiveLinearState(source.providerDebugSnapshot ?? null);
639
+ return {
640
+ ...source,
641
+ displayStatus: shouldResetDisplayStatus ? source.rawStatus : source.displayStatus,
642
+ statusReason: shouldResetDisplayStatus ? null : source.statusReason,
643
+ latestEvent: resetAdvisoryDerivedLatestEvent(source, providerDebugSnapshot),
644
+ tracked: { linear: null },
645
+ compatibilityState: null,
646
+ providerDebugSnapshot
647
+ };
648
+ }
649
+ function clearProviderDebugLiveLinearState(snapshot) {
650
+ if (!snapshot) {
651
+ return snapshot;
652
+ }
653
+ const shouldClearAdvisoryDerivedProgress = snapshot.progress?.kind === 'workflow';
654
+ return {
655
+ ...snapshot,
656
+ live_linear_state: {
657
+ state: null,
658
+ state_type: null,
659
+ updated_at: null
660
+ },
661
+ ...(shouldClearAdvisoryDerivedProgress
662
+ ? {
663
+ progress: null,
664
+ last_semantic_progress_at: snapshot.last_audit_operation?.recorded_at ?? null,
665
+ stall_classification: null,
666
+ stall_reason: null,
667
+ recovery_recommendation: null
668
+ }
669
+ : {})
670
+ };
671
+ }
672
+ function resetAdvisoryDerivedLatestEvent(source, providerDebugSnapshot) {
673
+ if (source.latestEvent?.source !== 'provider_debug_progress' ||
674
+ providerDebugSnapshot?.progress !== null) {
675
+ return source.latestEvent;
676
+ }
677
+ return {
678
+ at: source.updatedAt,
679
+ event: source.rawStatus,
680
+ message: source.summary,
681
+ source: 'run_summary',
682
+ messageRecordedAt: null,
683
+ sourceUpdatedAt: source.updatedAt,
684
+ candidates: [],
685
+ requestedBy: null,
686
+ reason: null
687
+ };
688
+ }
689
+ function linearTrackedIssueConflictsWithAuthoritativeIdentity(selected, linear) {
690
+ if (!selected || !linear || !hasExplicitCompatibilityIssueIdentity(selected)) {
691
+ return false;
692
+ }
693
+ const authoritativeIssueId = readAuthoritativeProviderIssueId(selected);
694
+ const authoritativeIssueIdentifier = readAuthoritativeProviderIssueIdentifier(selected);
695
+ if (authoritativeIssueId !== null && linear.id === authoritativeIssueId) {
696
+ return false;
697
+ }
698
+ if (authoritativeIssueIdentifier !== null && linear.identifier === authoritativeIssueIdentifier) {
699
+ return false;
700
+ }
701
+ return authoritativeIssueId !== null || authoritativeIssueIdentifier !== null;
702
+ }
703
+ function hasExplicitCompatibilityIssueIdentity(source) {
704
+ if (source.issueIdentifier &&
705
+ !isFallbackCompatibilityIdentityValue(source.issueIdentifier, source)) {
706
+ return true;
707
+ }
708
+ if (source.issueId && !isFallbackCompatibilityIdentityValue(source.issueId, source)) {
709
+ return true;
710
+ }
711
+ return false;
712
+ }
713
+ function hasSyntheticLinearFallbackProvenance(source) {
714
+ if (source.issueProvider !== null && source.issueProvider !== 'linear') {
715
+ return false;
716
+ }
717
+ return (source.pipelineId === 'provider-linear-worker' ||
718
+ source.pipelineTitle === 'Provider Linear Worker' ||
719
+ source.providerLinearWorkerProof != null ||
720
+ (source.issueProvider === 'linear' &&
721
+ (source.pipelineId === 'docs-review' ||
722
+ source.pipelineId === 'implementation-gate' ||
723
+ source.pipelineId === 'docs-relevance-advisory' ||
724
+ source.pipelineId === 'provider-linear-child-lane')));
725
+ }
726
+ function isFreshNullProviderRunningSource(source) {
727
+ const updatedAt = Date.parse(source.updatedAt ?? '');
728
+ const startedAt = Date.parse(source.startedAt ?? '');
729
+ const freshestTimestamp = Math.max(Number.isFinite(updatedAt) ? updatedAt : Number.NEGATIVE_INFINITY, Number.isFinite(startedAt) ? startedAt : Number.NEGATIVE_INFINITY);
730
+ if (!Number.isFinite(freshestTimestamp)) {
731
+ return false;
732
+ }
733
+ return Date.now() - freshestTimestamp <= NULL_PROVIDER_RUNNING_FRESHNESS_MS;
734
+ }
735
+ function isProviderIntakeClaimActiveCurrentActivity(claim) {
736
+ if (claim.state === 'accepted' ||
737
+ claim.state === 'starting' ||
738
+ claim.state === 'running' ||
739
+ claim.state === 'resuming') {
740
+ return true;
741
+ }
742
+ if (claim.state === 'released' &&
743
+ isProviderIssueReleasedPendingReopen(claim.reason) &&
744
+ isProviderStartedWorkerIssueState({
745
+ state: claim.issue_state,
746
+ state_type: claim.issue_state_type
747
+ })) {
748
+ return true;
749
+ }
750
+ return false;
751
+ }
752
+ function isProviderIntakeClaimActiveForSourceCurrentActivity(claim, source) {
753
+ if (isStaleTerminalReleasedProviderSource(claim, source)) {
754
+ return false;
755
+ }
756
+ if (isAcceptedPendingRevalidationSourceWithInactiveLocalProof(claim, source)) {
757
+ return false;
758
+ }
759
+ if (source.rawStatus === 'in_progress' &&
760
+ claim.state === 'released' &&
761
+ isProviderIssueReleasedLiveWorkerRehydrateReason(claim.reason) &&
762
+ isProviderStartedWorkerSourceIssueState(claim, source) &&
763
+ !hasStaleLocalProviderInProgressProof(source.providerLinearWorkerProof, source.startedAt)) {
764
+ return true;
765
+ }
766
+ return isProviderIntakeClaimActiveCurrentActivity(claim);
767
+ }
768
+ function isAcceptedPendingRevalidationSourceWithInactiveLocalProof(claim, source) {
769
+ return (source.rawStatus === 'in_progress' &&
770
+ claim.state === 'accepted' &&
771
+ claim.reason === 'provider_issue_rehydration_pending_revalidation' &&
772
+ source.providerLinearWorkerProof !== null &&
773
+ (!isProviderLinearWorkerProofFreshForStage(source.providerLinearWorkerProof, source.startedAt) || hasStaleLocalProviderInProgressProof(source.providerLinearWorkerProof, source.startedAt)));
774
+ }
775
+ function isProviderStartedWorkerSourceIssueState(claim, source) {
776
+ const trackedIssue = source.tracked?.linear ?? null;
777
+ if (trackedIssue) {
778
+ const trackedUpdatedAt = Date.parse(trackedIssue.updated_at ?? '');
779
+ const claimIssueUpdatedAt = Date.parse(claim.issue_updated_at ?? '');
780
+ const trackedIssueIsCurrent = Number.isFinite(trackedUpdatedAt) &&
781
+ (!Number.isFinite(claimIssueUpdatedAt) || trackedUpdatedAt >= claimIssueUpdatedAt);
782
+ if (trackedIssueIsCurrent) {
783
+ return isProviderStartedWorkerIssueState({
784
+ state: trackedIssue.state,
785
+ state_type: trackedIssue.state_type
786
+ });
787
+ }
788
+ }
789
+ return (isProviderIssueReleasedPendingReopen(claim.reason) &&
790
+ isProviderStartedWorkerIssueState({
791
+ state: claim.issue_state,
792
+ state_type: claim.issue_state_type
793
+ }));
794
+ }
795
+ function isStaleTerminalReleasedProviderSource(claim, source) {
796
+ if (claim.state !== 'released' ||
797
+ !isProviderIssueReleasedLiveWorkerRehydrateReason(claim.reason) ||
798
+ !isProviderStartedWorkerIssueState({
799
+ state: claim.issue_state,
800
+ state_type: claim.issue_state_type
801
+ })) {
802
+ return false;
803
+ }
804
+ if (!hasFreshTerminalSelectedTrackedIssue(source.tracked, claim)) {
805
+ return false;
806
+ }
807
+ return hasStaleLocalProviderInProgressProof(source.providerLinearWorkerProof, source.startedAt);
808
+ }
809
+ function hasFreshTerminalSelectedTrackedIssue(tracked, claim) {
810
+ const linear = tracked?.linear ?? null;
811
+ if (!linear) {
812
+ return false;
813
+ }
814
+ if (!classifyProviderLinearWorkflowState({
815
+ state: linear.state,
816
+ state_type: linear.state_type
817
+ }).isTerminal) {
818
+ return false;
819
+ }
820
+ const trackedUpdatedAt = Date.parse(linear.updated_at ?? '');
821
+ const claimIssueUpdatedAt = Date.parse(claim.issue_updated_at ?? '');
822
+ if (!Number.isFinite(trackedUpdatedAt) || !Number.isFinite(claimIssueUpdatedAt)) {
823
+ return false;
824
+ }
825
+ return trackedUpdatedAt >= claimIssueUpdatedAt;
826
+ }
827
+ function hasStaleLocalProviderInProgressProof(proof, startedAt) {
828
+ if (!proof) {
829
+ return false;
830
+ }
831
+ if (!isProviderLinearWorkerProofFreshForStage(proof, startedAt)) {
832
+ return false;
833
+ }
834
+ if ((proof.owner_status && proof.owner_status !== 'in_progress') ||
835
+ proof.owner_phase === 'ended') {
836
+ return false;
837
+ }
838
+ if (normalizeManifestString(proof.worker_host) !== null) {
839
+ return false;
840
+ }
841
+ const pid = readProviderProofPid(proof.pid);
842
+ return pid !== null && pid > 0 && !isLocalProcessAlive(pid);
843
+ }
844
+ function readProviderProofPid(pid) {
845
+ if (typeof pid === 'number') {
846
+ return Number.isInteger(pid) ? pid : null;
847
+ }
848
+ if (typeof pid !== 'string') {
849
+ return null;
850
+ }
851
+ const trimmed = pid.trim();
852
+ if (!/^\d+$/.test(trimmed)) {
853
+ return null;
854
+ }
855
+ const parsed = Number.parseInt(trimmed, 10);
856
+ return Number.isSafeInteger(parsed) ? parsed : null;
857
+ }
858
+ function isLocalProcessAlive(pid) {
859
+ try {
860
+ process.kill(pid, 0);
861
+ return true;
862
+ }
863
+ catch (error) {
864
+ return error?.code !== 'ESRCH';
865
+ }
866
+ }
867
+ function isProviderIssueReleasedPendingReopen(reason) {
868
+ return typeof reason === 'string' && reason.startsWith(PROVIDER_RELEASED_PENDING_REOPEN_PREFIX);
869
+ }
870
+ function isProviderIssueReleasedLiveWorkerRehydrateReason(reason) {
871
+ return (isProviderIssueReleasedPendingReopen(reason) ||
872
+ reason === 'provider_issue_released:not_active');
873
+ }
874
+ function isProviderStartedWorkerIssueState(input) {
875
+ const workflowState = classifyProviderLinearWorkflowState(input);
876
+ return workflowState.isActive && !workflowState.isTodo;
877
+ }
878
+ function buildCompatibilityTelemetrySnapshot(sources, polling) {
879
+ const now = Date.now();
880
+ let inputTokens = 0;
881
+ let hasInputTokens = false;
882
+ let outputTokens = 0;
883
+ let hasOutputTokens = false;
884
+ let totalTokens = 0;
885
+ let hasTotalTokens = false;
886
+ let reasoningOutputTokens = 0;
887
+ let hasReasoningOutputTokens = false;
888
+ let secondsRunning = 0;
889
+ let latestAuthoritativeRateLimits = polling?.linear_budget
890
+ ? { ...polling.linear_budget }
891
+ : null;
892
+ let latestAuthoritativeRateLimitsAt = Number.NEGATIVE_INFINITY;
893
+ if (polling?.linear_budget?.observed_at) {
894
+ latestAuthoritativeRateLimitsAt = Date.parse(polling.linear_budget.observed_at) || Number.NEGATIVE_INFINITY;
895
+ }
896
+ let latestCodexRateLimits = null;
897
+ let latestCodexRateLimitsAt = Number.NEGATIVE_INFINITY;
898
+ for (const source of sources) {
899
+ const proof = source.providerLinearWorkerProof ?? null;
900
+ const tokenUsage = proof?.tokens ?? null;
901
+ if (typeof tokenUsage?.input_tokens === 'number' && Number.isFinite(tokenUsage.input_tokens)) {
902
+ inputTokens += Math.max(0, tokenUsage.input_tokens);
903
+ hasInputTokens = true;
904
+ }
905
+ if (typeof tokenUsage?.output_tokens === 'number' && Number.isFinite(tokenUsage.output_tokens)) {
906
+ outputTokens += Math.max(0, tokenUsage.output_tokens);
907
+ hasOutputTokens = true;
908
+ }
909
+ if (typeof tokenUsage?.total_tokens === 'number' && Number.isFinite(tokenUsage.total_tokens)) {
910
+ totalTokens += Math.max(0, tokenUsage.total_tokens);
911
+ hasTotalTokens = true;
912
+ }
913
+ if (typeof tokenUsage?.reasoning_output_tokens === 'number' &&
914
+ Number.isFinite(tokenUsage.reasoning_output_tokens)) {
915
+ reasoningOutputTokens += Math.max(0, tokenUsage.reasoning_output_tokens);
916
+ hasReasoningOutputTokens = true;
917
+ }
918
+ secondsRunning += computeCompatibilityRuntimeSeconds(source, now);
919
+ const linearBudget = proof?.linear_budget ? { ...proof.linear_budget } : null;
920
+ if (linearBudget) {
921
+ const candidateTimestamp = Date.parse(linearBudget.observed_at ?? proof?.updated_at ?? source.updatedAt ?? '') ||
922
+ Number.NEGATIVE_INFINITY;
923
+ if (candidateTimestamp >= latestAuthoritativeRateLimitsAt) {
924
+ latestAuthoritativeRateLimits = linearBudget;
925
+ latestAuthoritativeRateLimitsAt = candidateTimestamp;
926
+ }
927
+ }
928
+ if (proof?.rate_limits) {
929
+ const candidateTimestamp = resolveProviderLinearWorkerRateLimitsRecordedAt(proof, source);
930
+ if (candidateTimestamp >= latestCodexRateLimitsAt) {
931
+ latestCodexRateLimits = proof.rate_limits;
932
+ latestCodexRateLimitsAt = candidateTimestamp;
933
+ }
934
+ }
935
+ }
936
+ const codexTotals = {
937
+ input_tokens: hasInputTokens ? inputTokens : null,
938
+ output_tokens: hasOutputTokens ? outputTokens : null,
939
+ total_tokens: hasTotalTokens ? totalTokens : null,
940
+ seconds_running: Number(secondsRunning.toFixed(3))
941
+ };
942
+ if (hasReasoningOutputTokens) {
943
+ codexTotals.reasoning_output_tokens = reasoningOutputTokens;
944
+ }
945
+ return {
946
+ codexTotals,
947
+ rateLimits: combineCompatibilityRateLimits({
948
+ codex: latestCodexRateLimits,
949
+ linearBudget: latestAuthoritativeRateLimits
950
+ })
951
+ };
952
+ }
953
+ function resolveProviderLinearWorkerRateLimitsRecordedAt(proof, source) {
954
+ let semanticLatest = Number.NEGATIVE_INFINITY;
955
+ for (const candidate of [
956
+ proof.last_event_at,
957
+ proof.current_turn_activity?.recorded_at
958
+ ]) {
959
+ const parsed = Date.parse(candidate ?? '');
960
+ if (Number.isFinite(parsed)) {
961
+ semanticLatest = Math.max(semanticLatest, parsed);
962
+ }
963
+ }
964
+ if (Number.isFinite(semanticLatest)) {
965
+ return semanticLatest;
966
+ }
967
+ let fallbackLatest = Number.NEGATIVE_INFINITY;
968
+ for (const candidate of [
969
+ source.updatedAt,
970
+ proof.updated_at
971
+ ]) {
972
+ const parsed = Date.parse(candidate ?? '');
973
+ if (Number.isFinite(parsed)) {
974
+ fallbackLatest = Math.max(fallbackLatest, parsed);
975
+ }
976
+ }
977
+ return fallbackLatest;
978
+ }
979
+ function combineCompatibilityRateLimits(input) {
980
+ if (input.codex && input.linearBudget) {
981
+ return {
982
+ codex: input.codex,
983
+ linear_budget: input.linearBudget
984
+ };
985
+ }
986
+ return input.codex ?? input.linearBudget ?? null;
987
+ }
988
+ function buildCompatibilityTelemetrySources(snapshot) {
989
+ return snapshot.running;
990
+ }
991
+ function computeCompatibilityRuntimeSeconds(source, now) {
992
+ const startedAt = Date.parse(source.startedAt ?? '');
993
+ if (!Number.isFinite(startedAt)) {
994
+ return 0;
995
+ }
996
+ const proofUpdatedAt = Date.parse(source.providerLinearWorkerProof?.updated_at ?? '');
997
+ const completedAt = Date.parse(source.completedAt ?? '');
998
+ const updatedAt = Date.parse(source.updatedAt ?? '');
999
+ const endAt = source.rawStatus === 'in_progress'
1000
+ ? now
1001
+ : completedAt || proofUpdatedAt || updatedAt || now;
1002
+ return Math.max(0, (endAt - startedAt) / 1000);
1003
+ }