@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,383 @@
1
+ const AUXILIARY_PROOF_HARNESS_SUMMARY = 'manual live proof harness';
2
+ const AUXILIARY_PROOF_HARNESS_RUN_ID_SUFFIX = '-manual-live-proof';
3
+ const FOLLOW_UP_PARITY_MATRIX_SUPPRESSION_CODES = new Set([
4
+ 'linear_follow_up_parity_matrix_missing',
5
+ 'linear_follow_up_parity_matrix_retry_suppressed'
6
+ ]);
7
+ const CHILD_LANE_PARENT_DIRTY_SUPPRESSION_CODES = new Set([
8
+ 'provider_worker_child_lane_parent_dirty',
9
+ 'provider_worker_child_lane_parent_dirty_retry_suppressed'
10
+ ]);
11
+ export function isAuxiliaryProviderProofHarnessManifest(manifest) {
12
+ const runId = readStringValue(manifest, 'run_id', 'runId');
13
+ const summary = readStringValue(manifest, 'summary');
14
+ return (summary === AUXILIARY_PROOF_HARNESS_SUMMARY ||
15
+ (typeof runId === 'string' && runId.endsWith(AUXILIARY_PROOF_HARNESS_RUN_ID_SUFFIX)));
16
+ }
17
+ export function resolveProviderLinearWorkerTerminalStatus(proof) {
18
+ if (!proof) {
19
+ return null;
20
+ }
21
+ if (readStringValue(proof, 'owner_phase') !== 'ended') {
22
+ return null;
23
+ }
24
+ const ownerStatus = readStringValue(proof, 'owner_status');
25
+ return ownerStatus === 'failed' || ownerStatus === 'succeeded' ? ownerStatus : null;
26
+ }
27
+ export function resolveProviderLinearWorkerTerminalReason(proof) {
28
+ if (!resolveProviderLinearWorkerTerminalStatus(proof)) {
29
+ return null;
30
+ }
31
+ return readStringValue(proof ?? {}, 'end_reason');
32
+ }
33
+ export function resolveProviderLinearWorkerAttemptStartedAt(proof) {
34
+ return readStringValue(proof ?? {}, 'attempt_started_at');
35
+ }
36
+ export function isProviderLinearWorkerProofFreshForStage(proof, stageStartedAt) {
37
+ if (!proof) {
38
+ return false;
39
+ }
40
+ const stageStartedAtMs = readTimestampMs({
41
+ started_at: stageStartedAt ?? null
42
+ }, 'started_at');
43
+ if (!Number.isFinite(stageStartedAtMs)) {
44
+ return true;
45
+ }
46
+ const proofAttemptStartedAtMs = readTimestampMs(proof ?? {}, 'attempt_started_at');
47
+ if (Number.isFinite(proofAttemptStartedAtMs)) {
48
+ return proofAttemptStartedAtMs >= stageStartedAtMs;
49
+ }
50
+ const proofUpdatedAtMs = readTimestampMs(proof ?? {}, 'updated_at');
51
+ return Number.isFinite(proofUpdatedAtMs) && proofUpdatedAtMs >= stageStartedAtMs;
52
+ }
53
+ export function shouldUseProviderLinearWorkerTerminalProofForSelectedRun(manifest, proof) {
54
+ const proofStatus = resolveProviderLinearWorkerTerminalStatus(proof);
55
+ if (!proofStatus) {
56
+ return false;
57
+ }
58
+ const proofUpdatedAtMs = readTimestampMs(proof ?? {}, 'updated_at');
59
+ if (!Number.isFinite(proofUpdatedAtMs)) {
60
+ return false;
61
+ }
62
+ const manifestStatus = readStringValue(manifest, 'status');
63
+ const manifestUpdatedAtMs = readTimestampMs(manifest, 'updated_at', 'updatedAt', 'started_at', 'startedAt');
64
+ if (!manifestStatus || manifestStatus === 'in_progress') {
65
+ return !Number.isFinite(manifestUpdatedAtMs) || proofUpdatedAtMs >= manifestUpdatedAtMs;
66
+ }
67
+ if (manifestStatus === proofStatus) {
68
+ return !Number.isFinite(manifestUpdatedAtMs) || proofUpdatedAtMs >= manifestUpdatedAtMs;
69
+ }
70
+ return proofStatus === 'failed' && (!Number.isFinite(manifestUpdatedAtMs) || proofUpdatedAtMs > manifestUpdatedAtMs);
71
+ }
72
+ export function buildProviderLinearWorkerTerminalSummary(input) {
73
+ const baseSummary = formatProviderLinearWorkerTerminalBaseSummary(input.status, input.endReason);
74
+ const annotations = [input.reviewOutcomeSummary ?? null, input.degradationSummary ?? null].filter((value) => Boolean(value));
75
+ if (annotations.length === 0) {
76
+ return baseSummary;
77
+ }
78
+ return `${baseSummary} (${annotations.join('; ')})`;
79
+ }
80
+ export function deriveDeterministicProviderMutationSuppressions(audit, options = {}) {
81
+ if (!audit) {
82
+ return [];
83
+ }
84
+ const latestByOperation = audit.latest_by_operation;
85
+ if (!latestByOperation || typeof latestByOperation !== 'object') {
86
+ return [];
87
+ }
88
+ const recordedAtNotBeforeMs = readTimestampMs({
89
+ recorded_at: options.recordedAtNotBefore ?? null
90
+ }, 'recorded_at');
91
+ if (!Number.isFinite(recordedAtNotBeforeMs)) {
92
+ return [];
93
+ }
94
+ const issueId = normalizeOptionalString(options.issueId);
95
+ const entries = selectProviderLinearMutationEntries(audit, latestByOperation)
96
+ .filter((entry) => Boolean(entry))
97
+ .filter((entry) => !issueId || entry.issue_id === issueId)
98
+ .filter((entry) => readTimestampMs(entry, 'recorded_at') >= recordedAtNotBeforeMs)
99
+ .filter((entry) => entry.ok === false && isDeterministicProviderMutationFailure(entry))
100
+ .reduce((latestByOperationAndAction, entry) => {
101
+ latestByOperationAndAction.set(buildProviderLinearMutationEntryKey(entry), entry);
102
+ return latestByOperationAndAction;
103
+ }, new Map());
104
+ return Array.from(entries.values())
105
+ .sort((left, right) => {
106
+ const operationOrder = left.operation.localeCompare(right.operation);
107
+ if (operationOrder !== 0) {
108
+ return operationOrder;
109
+ }
110
+ const leftAction = normalizeAuditAction(left.action) ?? '';
111
+ const rightAction = normalizeAuditAction(right.action) ?? '';
112
+ return leftAction.localeCompare(rightAction);
113
+ })
114
+ .map((entry) => buildDeterministicProviderMutationSuppression(entry));
115
+ }
116
+ export function findDeterministicProviderMutationSuppression(audit, operation, options = {}) {
117
+ const requestedAction = normalizeAuditAction(options.action);
118
+ return (deriveDeterministicProviderMutationSuppressions(audit, options).find((suppression) => suppression.operation === operation &&
119
+ (!requestedAction || suppression.action === requestedAction)) ?? null);
120
+ }
121
+ export function isFollowUpParityMatrixSuppressionCode(errorCode) {
122
+ const normalized = normalizeOptionalString(errorCode);
123
+ return normalized ? FOLLOW_UP_PARITY_MATRIX_SUPPRESSION_CODES.has(normalized) : false;
124
+ }
125
+ export function isChildLaneParentDirtySuppressionCode(errorCode) {
126
+ const normalized = normalizeOptionalString(errorCode);
127
+ return normalized ? CHILD_LANE_PARENT_DIRTY_SUPPRESSION_CODES.has(normalized) : false;
128
+ }
129
+ export function formatDeterministicProviderMutationDegradationSummary(suppressions) {
130
+ if (suppressions.length === 0) {
131
+ return null;
132
+ }
133
+ if (suppressions.length === 1) {
134
+ return suppressions[0]?.summary ?? null;
135
+ }
136
+ const labels = suppressions.map((suppression) => suppression.error_code ? `${suppression.operation}:${suppression.error_code}` : suppression.operation);
137
+ return `${suppressions.length} deterministic provider mutations were suppressed for this attempt: ${labels.join(', ')}`;
138
+ }
139
+ function buildDeterministicProviderMutationSuppression(entry) {
140
+ const action = normalizeAuditAction(entry.action);
141
+ const errorCode = normalizeOptionalString(entry.error_code);
142
+ const errorMessage = normalizeOptionalString(entry.error_message);
143
+ switch (entry.operation) {
144
+ case 'create-follow-up':
145
+ return {
146
+ operation: entry.operation,
147
+ action,
148
+ error_code: errorCode,
149
+ error_message: errorMessage,
150
+ instruction: isFollowUpParityMatrixSuppressionCode(errorCode)
151
+ ? 'Do not retry `create-follow-up` in this attempt unless you first add the required parity matrix or explicitly reclassify the follow-up as non-parity/alignment and omit `--parity-lane`.'
152
+ : buildGenericSuppressionInstruction(entry.operation, errorCode, errorMessage),
153
+ summary: isFollowUpParityMatrixSuppressionCode(errorCode)
154
+ ? 'deterministic provider mutation suppressed: create-follow-up retry is blocked until a parity matrix is added or the follow-up is reclassified as non-parity/alignment with --parity-lane omitted'
155
+ : buildGenericSuppressionSummary(entry.operation, errorCode, errorMessage)
156
+ };
157
+ case 'child-lane':
158
+ if (errorCode === 'provider_worker_child_lane_provenance_invalid') {
159
+ const launchTimeControlHostProvenanceFailure = action === 'launch' || errorMessage?.includes('control-host provenance') === true;
160
+ return {
161
+ operation: entry.operation,
162
+ action,
163
+ error_code: errorCode,
164
+ error_message: errorMessage,
165
+ instruction: launchTimeControlHostProvenanceFailure
166
+ ? `Do not retry \`${entry.operation}\` until you first confirm the parent provider-worker run now has matching control-host provenance recorded in the manifest and active environment; if that provenance has already been repaired since the failed audit entry, you may retry once without restarting the attempt. Preserve the fail-closed provenance contract instead of forcing the launch.`
167
+ : 'Do not retry `child-lane` until you first confirm the pending child-lane record now matches the expected parent-owned pipeline, task, and issue binding; if that binding has already been repaired since the failed audit entry, you may retry once without restarting the attempt. Preserve the fail-closed provenance contract instead of forcing the decision.',
168
+ summary: launchTimeControlHostProvenanceFailure
169
+ ? `deterministic provider mutation suppressed: ${entry.operation} fail-closed provenance mismatch must be repaired before retry`
170
+ : 'deterministic provider mutation suppressed: child-lane fail-closed provenance mismatch must be reconciled before retry'
171
+ };
172
+ }
173
+ return {
174
+ operation: entry.operation,
175
+ action,
176
+ error_code: errorCode,
177
+ error_message: errorMessage,
178
+ instruction: isChildLaneParentDirtySuppressionCode(errorCode)
179
+ ? buildChildLaneParentDirtySuppressionInstruction(action)
180
+ : buildGenericSuppressionInstruction(entry.operation, errorCode, errorMessage),
181
+ summary: isChildLaneParentDirtySuppressionCode(errorCode)
182
+ ? buildChildLaneParentDirtySuppressionSummary(action)
183
+ : buildGenericSuppressionSummary(entry.operation, errorCode, errorMessage)
184
+ };
185
+ case 'transition':
186
+ case 'upsert-workpad':
187
+ if (errorCode === 'linear_issue_not_mutable') {
188
+ return {
189
+ operation: entry.operation,
190
+ action,
191
+ error_code: errorCode,
192
+ error_message: errorMessage,
193
+ instruction: `Do not retry \`${entry.operation}\` in this attempt until the Linear issue is restored to a mutable active state.`,
194
+ summary: `deterministic provider mutation suppressed: ${entry.operation} cannot run while the Linear issue is archived or trashed`
195
+ };
196
+ }
197
+ return {
198
+ operation: entry.operation,
199
+ action,
200
+ error_code: errorCode,
201
+ error_message: errorMessage,
202
+ instruction: buildGenericSuppressionInstruction(entry.operation, errorCode, errorMessage),
203
+ summary: buildGenericSuppressionSummary(entry.operation, errorCode, errorMessage)
204
+ };
205
+ case 'child-stream':
206
+ if (errorCode === 'provider_worker_child_stream_provenance_invalid') {
207
+ return {
208
+ operation: entry.operation,
209
+ action,
210
+ error_code: errorCode,
211
+ error_message: errorMessage,
212
+ instruction: `Do not retry \`${entry.operation}\` until you first confirm the parent provider-worker run now has matching control-host provenance recorded in the manifest and active environment; if that provenance has already been repaired since the failed audit entry, you may retry once without restarting the attempt. Preserve the fail-closed provenance contract instead of forcing the launch.`,
213
+ summary: `deterministic provider mutation suppressed: ${entry.operation} fail-closed provenance mismatch must be repaired before retry`
214
+ };
215
+ }
216
+ return {
217
+ operation: entry.operation,
218
+ action,
219
+ error_code: errorCode,
220
+ error_message: errorMessage,
221
+ instruction: buildGenericSuppressionInstruction(entry.operation, errorCode, errorMessage),
222
+ summary: buildGenericSuppressionSummary(entry.operation, errorCode, errorMessage)
223
+ };
224
+ default:
225
+ return {
226
+ operation: entry.operation,
227
+ action,
228
+ error_code: errorCode,
229
+ error_message: errorMessage,
230
+ instruction: buildGenericSuppressionInstruction(entry.operation, errorCode, errorMessage),
231
+ summary: buildGenericSuppressionSummary(entry.operation, errorCode, errorMessage)
232
+ };
233
+ }
234
+ }
235
+ function buildGenericSuppressionInstruction(operation, errorCode, errorMessage) {
236
+ const detail = [errorCode, errorMessage].filter((value) => Boolean(value)).join(': ');
237
+ return detail.length > 0
238
+ ? `Do not retry \`${operation}\` in this attempt until you first fix the deterministic validation error (${detail}).`
239
+ : `Do not retry \`${operation}\` in this attempt until you first fix the deterministic validation error.`;
240
+ }
241
+ function buildGenericSuppressionSummary(operation, errorCode, errorMessage) {
242
+ const detail = [errorCode, errorMessage].filter((value) => Boolean(value)).join(': ');
243
+ return detail.length > 0
244
+ ? `deterministic provider mutation suppressed: ${operation} failed with ${detail}`
245
+ : `deterministic provider mutation suppressed: ${operation} failed validation`;
246
+ }
247
+ function buildChildLaneParentDirtySuppressionInstruction(action) {
248
+ if (action === 'accept') {
249
+ return 'Do not retry `child-lane --action accept` in this attempt while the parent workspace still has in-scope dirty files. Reconcile those parent changes or move scratch artifacts outside the repo, then accept only after the requested patch scope is clean.';
250
+ }
251
+ return 'Do not retry `child-lane --action launch` in this attempt while the parent workspace still has in-scope dirty files. Reconcile those parent changes or move scratch artifacts outside the repo, then relaunch only after the requested scope is clean.';
252
+ }
253
+ function buildChildLaneParentDirtySuppressionSummary(action) {
254
+ if (action === 'accept') {
255
+ return 'deterministic provider mutation suppressed: child-lane accept retry is blocked until the parent workspace is clean for the requested patch scope';
256
+ }
257
+ return 'deterministic provider mutation suppressed: child-lane launch retry is blocked until the parent workspace is clean for the requested scope';
258
+ }
259
+ function isDeterministicProviderMutationFailure(entry) {
260
+ const errorCode = normalizeOptionalString(entry.error_code);
261
+ if (!errorCode) {
262
+ return false;
263
+ }
264
+ if (isFollowUpParityMatrixSuppressionCode(errorCode)) {
265
+ return true;
266
+ }
267
+ if (isChildLaneParentDirtySuppressionCode(errorCode)) {
268
+ return true;
269
+ }
270
+ if (errorCode === 'linear_workpad_comment_id_invalid') {
271
+ return true;
272
+ }
273
+ if (errorCode === 'workpad_body_missing') {
274
+ return true;
275
+ }
276
+ if (errorCode === 'workpad_marker_missing') {
277
+ return true;
278
+ }
279
+ if (errorCode === 'workpad_structure_invalid') {
280
+ return true;
281
+ }
282
+ if (errorCode === 'workpad_section_empty') {
283
+ return true;
284
+ }
285
+ if (errorCode === 'workpad_checklist_required') {
286
+ return true;
287
+ }
288
+ if (errorCode === 'workpad_validation_requirements_missing') {
289
+ return true;
290
+ }
291
+ if (errorCode === 'linear_issue_id_missing') {
292
+ return true;
293
+ }
294
+ if (errorCode === 'linear_issue_not_mutable') {
295
+ return true;
296
+ }
297
+ if (errorCode === 'provider_worker_child_lane_provenance_invalid') {
298
+ return true;
299
+ }
300
+ if (errorCode === 'provider_worker_child_stream_provenance_invalid') {
301
+ return true;
302
+ }
303
+ return /^linear_follow_up_.*_missing$/u.test(errorCode);
304
+ }
305
+ function formatProviderLinearWorkerTerminalBaseSummary(status, endReason) {
306
+ if (status === 'failed') {
307
+ if (endReason) {
308
+ const codexExitMatch = endReason.match(/^codex_exit_(.+)$/u);
309
+ if (codexExitMatch) {
310
+ return `Provider linear worker failed with Codex exit code ${codexExitMatch[1] ?? 'unknown'}.`;
311
+ }
312
+ switch (endReason) {
313
+ case 'tracked_issue_rate_limited':
314
+ return 'Provider linear worker failed because tracked issue rereads remained rate limited.';
315
+ case 'tracked_issue_read_failed':
316
+ return 'Provider linear worker failed because tracked issue rereads did not succeed.';
317
+ case 'exec_runner_failed':
318
+ return 'Provider linear worker failed because the Codex exec runner could not start or complete.';
319
+ case 'runtime_parity_command_unavailable':
320
+ return 'Provider linear worker failed because the requested runtime executable was unavailable under the current environment.';
321
+ case 'thread_id_missing':
322
+ return 'Provider linear worker failed because Codex did not emit a thread identifier.';
323
+ case 'provider_linear_worker_proof_missing_or_unreadable':
324
+ return 'Provider linear worker failed because authoritative proof was missing or unreadable.';
325
+ default:
326
+ return `Provider linear worker failed (${endReason}).`;
327
+ }
328
+ }
329
+ return 'Provider linear worker failed.';
330
+ }
331
+ switch (endReason) {
332
+ case 'issue_review_handoff':
333
+ return 'Provider linear worker reached review handoff.';
334
+ case 'issue_inactive':
335
+ return 'Provider linear worker stopped because the issue was no longer active.';
336
+ case 'max_turns_reached_issue_still_active':
337
+ return 'Provider linear worker exhausted the max turn budget while the issue remained active.';
338
+ case 'worker_completed':
339
+ return 'Provider linear worker completed.';
340
+ default:
341
+ return endReason ? `Provider linear worker completed (${endReason}).` : 'Provider linear worker completed.';
342
+ }
343
+ }
344
+ function readTimestampMs(record, ...keys) {
345
+ const value = readStringValue(record, ...keys);
346
+ if (!value) {
347
+ return Number.NaN;
348
+ }
349
+ return Date.parse(value);
350
+ }
351
+ function readStringValue(record, ...keys) {
352
+ for (const key of keys) {
353
+ const value = normalizeOptionalString(record[key]);
354
+ if (value) {
355
+ return value;
356
+ }
357
+ }
358
+ return null;
359
+ }
360
+ function normalizeOptionalString(value) {
361
+ if (typeof value !== 'string') {
362
+ return null;
363
+ }
364
+ const trimmed = value.trim();
365
+ return trimmed.length > 0 ? trimmed : null;
366
+ }
367
+ function selectProviderLinearMutationEntries(audit, latestByOperation) {
368
+ if (Array.isArray(audit.entries) && audit.entries.length > 0) {
369
+ return audit.entries.filter((entry) => Boolean(entry));
370
+ }
371
+ return Object.values(latestByOperation).filter((entry) => Boolean(entry));
372
+ }
373
+ function buildProviderLinearMutationEntryKey(entry) {
374
+ return `${entry.operation}:${normalizeAuditAction(entry.action) ?? ''}`;
375
+ }
376
+ function normalizeAuditAction(value) {
377
+ const normalized = normalizeOptionalString(value);
378
+ if (!normalized) {
379
+ return null;
380
+ }
381
+ const separatorIndex = normalized.indexOf(':');
382
+ return separatorIndex >= 0 ? normalized.slice(0, separatorIndex) : normalized;
383
+ }
@@ -0,0 +1,254 @@
1
+ import { appendFile, mkdir, readFile } from 'node:fs/promises';
2
+ import { dirname } from 'node:path';
3
+ export const PROVIDER_LINEAR_AUDIT_ENV_VAR = 'CODEX_PROVIDER_LINEAR_AUDIT_PATH';
4
+ export const PROVIDER_LINEAR_PARALLELIZATION_REASONS = {
5
+ parallelize_now: ['independent_scope_available'],
6
+ stay_serial: [
7
+ 'single_bounded_change',
8
+ 'overlapping_scope',
9
+ 'existing_child_lane_active',
10
+ 'review_or_validation_only'
11
+ ],
12
+ forbid_parallel: ['parent_only_mutation', 'merge_or_handoff_state', 'blocked_by_dependency']
13
+ };
14
+ export function isProviderLinearParallelizationDecision(value) {
15
+ return value === 'parallelize_now' || value === 'stay_serial' || value === 'forbid_parallel';
16
+ }
17
+ export function isProviderLinearParallelizationReason(value) {
18
+ return (value === 'independent_scope_available' ||
19
+ value === 'single_bounded_change' ||
20
+ value === 'overlapping_scope' ||
21
+ value === 'existing_child_lane_active' ||
22
+ value === 'review_or_validation_only' ||
23
+ value === 'parent_only_mutation' ||
24
+ value === 'merge_or_handoff_state' ||
25
+ value === 'blocked_by_dependency');
26
+ }
27
+ export function isProviderLinearParallelizationReasonAllowed(decision, reason) {
28
+ return PROVIDER_LINEAR_PARALLELIZATION_REASONS[decision].includes(reason);
29
+ }
30
+ export function readProviderLinearParallelizationSnapshots(audit, options = {}) {
31
+ const issueId = normalizeOptionalString(options.issueId);
32
+ const recordedAtNotBefore = normalizeOptionalString(options.recordedAtNotBefore);
33
+ return selectProviderLinearParallelizationEntries(audit)
34
+ .filter((entry) => entry.ok)
35
+ .filter((entry) => !issueId || entry.issue_id === issueId)
36
+ .filter((entry) => !recordedAtNotBefore || compareIsoTimestamp(entry.recorded_at, recordedAtNotBefore) >= 0)
37
+ .flatMap((entry) => {
38
+ const decision = normalizeOptionalString(entry.action);
39
+ const reason = normalizeOptionalString(entry.state);
40
+ if (!isProviderLinearParallelizationDecision(decision) ||
41
+ !isProviderLinearParallelizationReason(reason) ||
42
+ !isProviderLinearParallelizationReasonAllowed(decision, reason)) {
43
+ return [];
44
+ }
45
+ return [{
46
+ decision,
47
+ reason,
48
+ summary: normalizeOptionalString(entry.via),
49
+ recorded_at: entry.recorded_at
50
+ }];
51
+ })
52
+ .sort((left, right) => compareIsoTimestamp(left.recorded_at, right.recorded_at));
53
+ }
54
+ export function readProviderLinearParallelizationSnapshot(audit, options = {}) {
55
+ return readProviderLinearParallelizationSnapshots(audit, options).at(-1) ?? null;
56
+ }
57
+ export function resolveProviderLinearAuditPath(env) {
58
+ const value = env[PROVIDER_LINEAR_AUDIT_ENV_VAR];
59
+ if (typeof value !== 'string') {
60
+ return null;
61
+ }
62
+ const trimmed = value.trim();
63
+ return trimmed.length > 0 ? trimmed : null;
64
+ }
65
+ export async function appendProviderLinearAuditEntry(auditPath, entry) {
66
+ await mkdir(dirname(auditPath), { recursive: true });
67
+ await appendFile(auditPath, `${JSON.stringify(entry)}\n`, 'utf8');
68
+ }
69
+ export async function summarizeProviderLinearAuditPath(auditPath) {
70
+ const summary = buildEmptyProviderLinearAuditSummary(auditPath);
71
+ let raw;
72
+ try {
73
+ raw = await readFile(auditPath, 'utf8');
74
+ }
75
+ catch {
76
+ return summary;
77
+ }
78
+ for (const line of raw.split(/\r?\n/u)) {
79
+ if (line.trim().length === 0) {
80
+ continue;
81
+ }
82
+ let parsed;
83
+ try {
84
+ parsed = JSON.parse(line);
85
+ }
86
+ catch {
87
+ continue;
88
+ }
89
+ const entry = normalizeProviderLinearAuditEntry(parsed);
90
+ if (!entry) {
91
+ continue;
92
+ }
93
+ summary.attempted_count += 1;
94
+ if (entry.ok) {
95
+ summary.success_count += 1;
96
+ }
97
+ else {
98
+ summary.failure_count += 1;
99
+ }
100
+ summary.entries?.push(entry);
101
+ summary.latest_by_operation[entry.operation] = entry;
102
+ if (entry.operation === 'parallelization') {
103
+ summary.parallelization_entries.push(entry);
104
+ }
105
+ summary.latest_recorded_at = entry.recorded_at;
106
+ }
107
+ return summary;
108
+ }
109
+ function buildEmptyProviderLinearAuditSummary(auditPath) {
110
+ return {
111
+ path: auditPath,
112
+ attempted_count: 0,
113
+ success_count: 0,
114
+ failure_count: 0,
115
+ latest_recorded_at: null,
116
+ latest_by_operation: {},
117
+ parallelization_entries: [],
118
+ entries: []
119
+ };
120
+ }
121
+ function selectProviderLinearParallelizationEntries(audit) {
122
+ if (Array.isArray(audit?.parallelization_entries) && audit.parallelization_entries.length > 0) {
123
+ return audit.parallelization_entries.filter((entry) => Boolean(entry));
124
+ }
125
+ const latestEntry = audit?.latest_by_operation?.parallelization ?? null;
126
+ return latestEntry ? [latestEntry] : [];
127
+ }
128
+ function normalizeProviderLinearAuditEntry(value) {
129
+ if (!value || typeof value !== 'object') {
130
+ return null;
131
+ }
132
+ const entry = value;
133
+ const operation = entry.operation;
134
+ if (operation !== 'issue-context'
135
+ && operation !== 'upsert-workpad'
136
+ && operation !== 'delete-workpad'
137
+ && operation !== 'transition'
138
+ && operation !== 'attach-pr'
139
+ && operation !== 'parallelization'
140
+ && operation !== 'screenshot-proof'
141
+ && operation !== 'runtime-proof'
142
+ && operation !== 'create-follow-up'
143
+ && operation !== 'child-stream'
144
+ && operation !== 'child-lane') {
145
+ return null;
146
+ }
147
+ const recordedAt = normalizeOptionalString(entry.recorded_at);
148
+ if (!recordedAt) {
149
+ return null;
150
+ }
151
+ return {
152
+ recorded_at: recordedAt,
153
+ operation,
154
+ ok: entry.ok === true,
155
+ issue_id: normalizeOptionalString(entry.issue_id),
156
+ issue_identifier: normalizeOptionalString(entry.issue_identifier),
157
+ source_setup: normalizeSourceSetup(entry.source_setup),
158
+ action: normalizeOptionalString(entry.action),
159
+ via: normalizeOptionalString(entry.via),
160
+ state: normalizeOptionalString(entry.state),
161
+ follow_up_issue_id: normalizeOptionalString(entry.follow_up_issue_id),
162
+ follow_up_issue_identifier: normalizeOptionalString(entry.follow_up_issue_identifier),
163
+ failed_relation_type: normalizeOptionalString(entry.failed_relation_type),
164
+ comment_id: normalizeOptionalString(entry.comment_id),
165
+ attachment_id: normalizeOptionalString(entry.attachment_id),
166
+ ...(Array.isArray(entry.asset_urls)
167
+ ? {
168
+ asset_urls: entry.asset_urls
169
+ .map((value) => normalizeOptionalString(value))
170
+ .filter((value) => value !== null)
171
+ }
172
+ : {}),
173
+ ...(Object.prototype.hasOwnProperty.call(entry, 'previous_state')
174
+ ? { previous_state: normalizeOptionalString(entry.previous_state) }
175
+ : {}),
176
+ ...(Object.prototype.hasOwnProperty.call(entry, 'previous_state_type')
177
+ ? { previous_state_type: normalizeOptionalString(entry.previous_state_type) }
178
+ : {}),
179
+ ...(Object.prototype.hasOwnProperty.call(entry, 'target_state')
180
+ ? { target_state: normalizeOptionalString(entry.target_state) }
181
+ : {}),
182
+ ...(Object.prototype.hasOwnProperty.call(entry, 'target_state_type')
183
+ ? { target_state_type: normalizeOptionalString(entry.target_state_type) }
184
+ : {}),
185
+ ...(Object.prototype.hasOwnProperty.call(entry, 'issue_updated_at')
186
+ ? { issue_updated_at: normalizeOptionalString(entry.issue_updated_at) }
187
+ : {}),
188
+ ...(Object.prototype.hasOwnProperty.call(entry, 'expected_state')
189
+ ? { expected_state: normalizeOptionalString(entry.expected_state) }
190
+ : {}),
191
+ ...(Object.prototype.hasOwnProperty.call(entry, 'expected_state_type')
192
+ ? { expected_state_type: normalizeOptionalString(entry.expected_state_type) }
193
+ : {}),
194
+ ...(Object.prototype.hasOwnProperty.call(entry, 'expected_updated_at')
195
+ ? { expected_updated_at: normalizeOptionalString(entry.expected_updated_at) }
196
+ : {}),
197
+ ...(Object.prototype.hasOwnProperty.call(entry, 'force')
198
+ && typeof entry.force === 'boolean'
199
+ ? { force: entry.force }
200
+ : {}),
201
+ ...(Object.prototype.hasOwnProperty.call(entry, 'force_reason')
202
+ ? { force_reason: normalizeOptionalString(entry.force_reason) }
203
+ : {}),
204
+ error_code: normalizeOptionalString(entry.error_code),
205
+ error_message: normalizeOptionalString(entry.error_message)
206
+ };
207
+ }
208
+ function normalizeSourceSetup(value) {
209
+ if (!value || typeof value !== 'object') {
210
+ return null;
211
+ }
212
+ const record = value;
213
+ if (record.provider !== 'linear') {
214
+ return null;
215
+ }
216
+ return {
217
+ provider: 'linear',
218
+ workspace_id: normalizeOptionalString(record.workspace_id),
219
+ team_id: normalizeOptionalString(record.team_id),
220
+ project_id: normalizeOptionalString(record.project_id)
221
+ };
222
+ }
223
+ function normalizeOptionalString(value) {
224
+ if (typeof value !== 'string') {
225
+ return null;
226
+ }
227
+ const trimmed = value.trim();
228
+ return trimmed.length > 0 ? trimmed : null;
229
+ }
230
+ function compareIsoTimestamp(left, right) {
231
+ const leftValue = normalizeOptionalString(left);
232
+ const rightValue = normalizeOptionalString(right);
233
+ if (leftValue === rightValue) {
234
+ return 0;
235
+ }
236
+ if (!leftValue) {
237
+ return -1;
238
+ }
239
+ if (!rightValue) {
240
+ return 1;
241
+ }
242
+ const leftMs = Date.parse(leftValue);
243
+ const rightMs = Date.parse(rightValue);
244
+ if (Number.isFinite(leftMs) && Number.isFinite(rightMs)) {
245
+ return leftMs - rightMs;
246
+ }
247
+ if (Number.isFinite(leftMs)) {
248
+ return 1;
249
+ }
250
+ if (Number.isFinite(rightMs)) {
251
+ return -1;
252
+ }
253
+ return leftValue.localeCompare(rightValue);
254
+ }