@kbediako/codex-orchestrator 0.1.38 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (299) hide show
  1. package/.agents/plugins/marketplace.json +20 -0
  2. package/README.md +70 -301
  3. package/bin/codex-orchestrator.js +161 -0
  4. package/codex.orchestrator.json +149 -13
  5. package/dist/bin/codex-orchestrator.js +795 -1154
  6. package/dist/orchestrator/src/cli/adapters/CommandPlanner.js +22 -4
  7. package/dist/orchestrator/src/cli/adapters/CommandReviewer.js +3 -3
  8. package/dist/orchestrator/src/cli/adapters/CommandTester.js +2 -2
  9. package/dist/orchestrator/src/cli/adapters/cloudFailureDiagnostics.js +183 -11
  10. package/dist/orchestrator/src/cli/coStatusAttachCliShell.js +402 -0
  11. package/dist/orchestrator/src/cli/coStatusCliShell.js +429 -0
  12. package/dist/orchestrator/src/cli/coStatusOperatorAutopilotCliShell.js +120 -0
  13. package/dist/orchestrator/src/cli/codexCliShell.js +72 -0
  14. package/dist/orchestrator/src/cli/codexDefaultsSetup.js +49 -11
  15. package/dist/orchestrator/src/cli/config/delegationConfig.js +317 -5
  16. package/dist/orchestrator/src/cli/config/repoConfigPolicy.js +2 -3
  17. package/dist/orchestrator/src/cli/config/userConfig.js +28 -13
  18. package/dist/orchestrator/src/cli/control/authenticatedControlRouteGate.js +69 -0
  19. package/dist/orchestrator/src/cli/control/authenticatedRouteComposition.js +267 -0
  20. package/dist/orchestrator/src/cli/control/authenticatedRouteController.js +5 -0
  21. package/dist/orchestrator/src/cli/control/authenticatedRouteDispatcher.js +41 -0
  22. package/dist/orchestrator/src/cli/control/compatibilityIssuePresenter.js +1035 -0
  23. package/dist/orchestrator/src/cli/control/confirmationApproveController.js +62 -0
  24. package/dist/orchestrator/src/cli/control/confirmationCreateController.js +69 -0
  25. package/dist/orchestrator/src/cli/control/confirmationIssueConsumeController.js +43 -0
  26. package/dist/orchestrator/src/cli/control/confirmationListController.js +22 -0
  27. package/dist/orchestrator/src/cli/control/confirmationValidateController.js +58 -0
  28. package/dist/orchestrator/src/cli/control/confirmations.js +25 -3
  29. package/dist/orchestrator/src/cli/control/controlActionCancelConfirmation.js +65 -0
  30. package/dist/orchestrator/src/cli/control/controlActionController.js +77 -0
  31. package/dist/orchestrator/src/cli/control/controlActionControllerSequencing.js +161 -0
  32. package/dist/orchestrator/src/cli/control/controlActionExecution.js +142 -0
  33. package/dist/orchestrator/src/cli/control/controlActionFinalization.js +43 -0
  34. package/dist/orchestrator/src/cli/control/controlActionOutcome.js +60 -0
  35. package/dist/orchestrator/src/cli/control/controlActionPreflight.js +476 -0
  36. package/dist/orchestrator/src/cli/control/controlAuthenticatedRouteHandoff.js +57 -0
  37. package/dist/orchestrator/src/cli/control/controlBootstrapAssembly.js +39 -0
  38. package/dist/orchestrator/src/cli/control/controlBootstrapMetadataPersistence.js +16 -0
  39. package/dist/orchestrator/src/cli/control/controlEventTransport.js +49 -0
  40. package/dist/orchestrator/src/cli/control/controlExpiryLifecycle.js +102 -0
  41. package/dist/orchestrator/src/cli/control/controlHostOwnership.js +480 -0
  42. package/dist/orchestrator/src/cli/control/controlHostSupervision.js +608 -0
  43. package/dist/orchestrator/src/cli/control/controlOversightFacade.js +8 -0
  44. package/dist/orchestrator/src/cli/control/controlOversightReadContract.js +1 -0
  45. package/dist/orchestrator/src/cli/control/controlOversightReadService.js +16 -0
  46. package/dist/orchestrator/src/cli/control/controlOversightUpdateContract.js +1 -0
  47. package/dist/orchestrator/src/cli/control/controlPersistenceFiles.js +6 -0
  48. package/dist/orchestrator/src/cli/control/controlQuestionChildResolution.js +18 -0
  49. package/dist/orchestrator/src/cli/control/controlRequestContext.js +42 -0
  50. package/dist/orchestrator/src/cli/control/controlRequestController.js +9 -0
  51. package/dist/orchestrator/src/cli/control/controlRequestPredispatch.js +17 -0
  52. package/dist/orchestrator/src/cli/control/controlRequestRouteDispatch.js +44 -0
  53. package/dist/orchestrator/src/cli/control/controlRuntime.js +992 -0
  54. package/dist/orchestrator/src/cli/control/controlServer.js +23 -1456
  55. package/dist/orchestrator/src/cli/control/controlServerAuditAndErrorHelpers.js +115 -0
  56. package/dist/orchestrator/src/cli/control/controlServerAuthenticatedRouteBranch.js +29 -0
  57. package/dist/orchestrator/src/cli/control/controlServerBootstrapLifecycle.js +30 -0
  58. package/dist/orchestrator/src/cli/control/controlServerBootstrapStartSequence.js +21 -0
  59. package/dist/orchestrator/src/cli/control/controlServerOwnedRuntimeLifecycle.js +67 -0
  60. package/dist/orchestrator/src/cli/control/controlServerPublicLifecycle.js +756 -0
  61. package/dist/orchestrator/src/cli/control/controlServerPublicRouteHelpers.js +86 -0
  62. package/dist/orchestrator/src/cli/control/controlServerReadyInstanceLifecycle.js +25 -0
  63. package/dist/orchestrator/src/cli/control/controlServerReadyInstanceStartup.js +18 -0
  64. package/dist/orchestrator/src/cli/control/controlServerRequestBodyHelpers.js +37 -0
  65. package/dist/orchestrator/src/cli/control/controlServerRequestShell.js +40 -0
  66. package/dist/orchestrator/src/cli/control/controlServerRequestShellBinding.js +17 -0
  67. package/dist/orchestrator/src/cli/control/controlServerSeedLoading.js +27 -0
  68. package/dist/orchestrator/src/cli/control/controlServerSeededRuntimeAssembly.js +186 -0
  69. package/dist/orchestrator/src/cli/control/controlServerStartupInputPreparation.js +31 -0
  70. package/dist/orchestrator/src/cli/control/controlServerStartupSequence.js +49 -0
  71. package/dist/orchestrator/src/cli/control/controlState.js +233 -2
  72. package/dist/orchestrator/src/cli/control/controlStatusDashboard.js +1899 -0
  73. package/dist/orchestrator/src/cli/control/controlTelegramBridgeBootstrapLifecycle.js +22 -0
  74. package/dist/orchestrator/src/cli/control/controlTelegramBridgeLifecycle.js +67 -0
  75. package/dist/orchestrator/src/cli/control/controlTelegramBridgeOversightFacadeFactory.js +8 -0
  76. package/dist/orchestrator/src/cli/control/controlTelegramCommandController.js +49 -0
  77. package/dist/orchestrator/src/cli/control/controlTelegramDispatchRead.js +40 -0
  78. package/dist/orchestrator/src/cli/control/controlTelegramPollingController.js +89 -0
  79. package/dist/orchestrator/src/cli/control/controlTelegramProjectionNotificationController.js +29 -0
  80. package/dist/orchestrator/src/cli/control/controlTelegramPushState.js +63 -0
  81. package/dist/orchestrator/src/cli/control/controlTelegramQuestionRead.js +13 -0
  82. package/dist/orchestrator/src/cli/control/controlTelegramReadController.js +216 -0
  83. package/dist/orchestrator/src/cli/control/controlTelegramUpdateHandler.js +63 -0
  84. package/dist/orchestrator/src/cli/control/controlWatcher.js +73 -5
  85. package/dist/orchestrator/src/cli/control/delegationRegisterController.js +35 -0
  86. package/dist/orchestrator/src/cli/control/dynamicToolBridgePolicy.js +139 -0
  87. package/dist/orchestrator/src/cli/control/eventsSseController.js +12 -0
  88. package/dist/orchestrator/src/cli/control/linearBudgetState.js +1789 -0
  89. package/dist/orchestrator/src/cli/control/linearDispatchSource.js +1137 -0
  90. package/dist/orchestrator/src/cli/control/linearGraphqlClient.js +150 -0
  91. package/dist/orchestrator/src/cli/control/linearRateLimit.js +102 -0
  92. package/dist/orchestrator/src/cli/control/linearWebhookController.js +499 -0
  93. package/dist/orchestrator/src/cli/control/liveLinearAdvisoryRuntime.js +70 -0
  94. package/dist/orchestrator/src/cli/control/observabilityApiController.js +173 -0
  95. package/dist/orchestrator/src/cli/control/observabilityReadModel.js +500 -0
  96. package/dist/orchestrator/src/cli/control/observabilitySurface.js +284 -0
  97. package/dist/orchestrator/src/cli/control/observabilityUpdateNotifier.js +22 -0
  98. package/dist/orchestrator/src/cli/control/operatorDashboardPresenter.js +252 -0
  99. package/dist/orchestrator/src/cli/control/providerAgentCapacity.js +70 -0
  100. package/dist/orchestrator/src/cli/control/providerControlHostFreshnessGauge.js +1068 -0
  101. package/dist/orchestrator/src/cli/control/providerIntakeState.js +473 -0
  102. package/dist/orchestrator/src/cli/control/providerIssueHandoff.js +6811 -0
  103. package/dist/orchestrator/src/cli/control/providerIssueObservability.js +1348 -0
  104. package/dist/orchestrator/src/cli/control/providerIssueRetryQueue.js +84 -0
  105. package/dist/orchestrator/src/cli/control/providerLinearRuntimeProof.js +588 -0
  106. package/dist/orchestrator/src/cli/control/providerLinearScreenshotProof.js +473 -0
  107. package/dist/orchestrator/src/cli/control/providerLinearWorkerTruth.js +383 -0
  108. package/dist/orchestrator/src/cli/control/providerLinearWorkflowAudit.js +254 -0
  109. package/dist/orchestrator/src/cli/control/providerLinearWorkflowFacade.js +5573 -0
  110. package/dist/orchestrator/src/cli/control/providerLinearWorkflowStates.js +115 -0
  111. package/dist/orchestrator/src/cli/control/providerMergeCloseout.js +1868 -0
  112. package/dist/orchestrator/src/cli/control/providerOperatorAutopilot.js +1580 -0
  113. package/dist/orchestrator/src/cli/control/providerOperatorAutopilotLifecycle.js +154 -0
  114. package/dist/orchestrator/src/cli/control/providerOperatorAutopilotLocalRolloutExecution.js +1006 -0
  115. package/dist/orchestrator/src/cli/control/providerPollingHealth.js +435 -0
  116. package/dist/orchestrator/src/cli/control/providerTerminalCleanup.js +516 -0
  117. package/dist/orchestrator/src/cli/control/providerWorkerHosts.js +191 -0
  118. package/dist/orchestrator/src/cli/control/providerWorkflowConfigStore.js +515 -0
  119. package/dist/orchestrator/src/cli/control/questionChildResolutionAdapter.js +361 -0
  120. package/dist/orchestrator/src/cli/control/questionQueueController.js +181 -0
  121. package/dist/orchestrator/src/cli/control/questionReadRetryDeduplication.js +9 -0
  122. package/dist/orchestrator/src/cli/control/questionReadSequence.js +10 -0
  123. package/dist/orchestrator/src/cli/control/securityViolationController.js +27 -0
  124. package/dist/orchestrator/src/cli/control/selectedRunProjection.js +1838 -0
  125. package/dist/orchestrator/src/cli/control/telegramOversightApiClient.js +48 -0
  126. package/dist/orchestrator/src/cli/control/telegramOversightBridge.js +180 -0
  127. package/dist/orchestrator/src/cli/control/telegramOversightBridgeProjectionDeliveryQueue.js +25 -0
  128. package/dist/orchestrator/src/cli/control/telegramOversightBridgeRuntimeLifecycle.js +45 -0
  129. package/dist/orchestrator/src/cli/control/telegramOversightBridgeStateStore.js +77 -0
  130. package/dist/orchestrator/src/cli/control/telegramOversightControlActionApiClient.js +45 -0
  131. package/dist/orchestrator/src/cli/control/trackerDispatchPilot.js +439 -0
  132. package/dist/orchestrator/src/cli/control/uiDataController.js +34 -0
  133. package/dist/orchestrator/src/cli/control/uiSessionController.js +100 -0
  134. package/dist/orchestrator/src/cli/controlHostCliShell.js +860 -0
  135. package/dist/orchestrator/src/cli/controlHostFreshnessGaugeCliShell.js +129 -0
  136. package/dist/orchestrator/src/cli/controlHostSupervisionCliShell.js +2127 -0
  137. package/dist/orchestrator/src/cli/delegationCliShell.js +62 -0
  138. package/dist/orchestrator/src/cli/delegationServer.js +567 -678
  139. package/dist/orchestrator/src/cli/delegationServerCliShell.js +52 -0
  140. package/dist/orchestrator/src/cli/delegationServerQuestionFlowShell.js +228 -0
  141. package/dist/orchestrator/src/cli/delegationServerToolDispatchShell.js +411 -0
  142. package/dist/orchestrator/src/cli/delegationServerTransport.js +274 -0
  143. package/dist/orchestrator/src/cli/delegationSetup.js +51 -171
  144. package/dist/orchestrator/src/cli/devtoolsCliShell.js +34 -0
  145. package/dist/orchestrator/src/cli/doctor.js +542 -122
  146. package/dist/orchestrator/src/cli/doctorCliRequestShell.js +72 -0
  147. package/dist/orchestrator/src/cli/doctorCliShell.js +138 -0
  148. package/dist/orchestrator/src/cli/doctorUsage.js +119 -15
  149. package/dist/orchestrator/src/cli/exec/experience.js +16 -2
  150. package/dist/orchestrator/src/cli/exec/summary.js +3 -0
  151. package/dist/orchestrator/src/cli/execCliShell.js +51 -0
  152. package/dist/orchestrator/src/cli/flowCliRequestShell.js +44 -0
  153. package/dist/orchestrator/src/cli/flowCliShell.js +239 -0
  154. package/dist/orchestrator/src/cli/frontendTestCliRequestShell.js +80 -0
  155. package/dist/orchestrator/src/cli/frontendTestCliShell.js +41 -0
  156. package/dist/orchestrator/src/cli/init.js +1 -0
  157. package/dist/orchestrator/src/cli/initCliShell.js +50 -0
  158. package/dist/orchestrator/src/cli/linearCliShell.js +1200 -0
  159. package/dist/orchestrator/src/cli/mcpEnableCliShell.js +132 -0
  160. package/dist/orchestrator/src/cli/metrics/metricsAggregator.js +3 -2
  161. package/dist/orchestrator/src/cli/metrics/metricsRecorder.js +56 -0
  162. package/dist/orchestrator/src/cli/orchestrator.js +66 -1376
  163. package/dist/orchestrator/src/cli/planCliShell.js +19 -0
  164. package/dist/orchestrator/src/cli/prCliShell.js +41 -0
  165. package/dist/orchestrator/src/cli/providerLinearChildLanePhaseContract.js +204 -0
  166. package/dist/orchestrator/src/cli/providerLinearChildLaneRunner.js +1772 -0
  167. package/dist/orchestrator/src/cli/providerLinearChildLaneShell.js +2420 -0
  168. package/dist/orchestrator/src/cli/providerLinearChildStreamShell.js +385 -0
  169. package/dist/orchestrator/src/cli/providerLinearWorkerRunner.js +5738 -0
  170. package/dist/orchestrator/src/cli/resumeCliShell.js +14 -0
  171. package/dist/orchestrator/src/cli/reviewCliLaunchShell.js +72 -0
  172. package/dist/orchestrator/src/cli/rlm/alignment.js +3 -3
  173. package/dist/orchestrator/src/cli/rlm/context.js +94 -7
  174. package/dist/orchestrator/src/cli/rlm/rlmCodexRuntimeShell.js +546 -0
  175. package/dist/orchestrator/src/cli/rlm/symbolic.js +4 -2
  176. package/dist/orchestrator/src/cli/rlmCliRequestShell.js +42 -0
  177. package/dist/orchestrator/src/cli/rlmCompletionCliShell.js +46 -0
  178. package/dist/orchestrator/src/cli/rlmLaunchCliShell.js +51 -0
  179. package/dist/orchestrator/src/cli/rlmRunner.js +83 -523
  180. package/dist/orchestrator/src/cli/run/blockMemory.js +500 -0
  181. package/dist/orchestrator/src/cli/run/manifest.js +410 -73
  182. package/dist/orchestrator/src/cli/run/manifestPersister.js +45 -14
  183. package/dist/orchestrator/src/cli/run/runMemoryController.js +216 -0
  184. package/dist/orchestrator/src/cli/run/source0.js +690 -0
  185. package/dist/orchestrator/src/cli/run/workspacePath.js +101 -0
  186. package/dist/orchestrator/src/cli/runtime/mode.js +2 -1
  187. package/dist/orchestrator/src/cli/runtime/provider.js +39 -2
  188. package/dist/orchestrator/src/cli/selfCheckCliShell.js +12 -0
  189. package/dist/orchestrator/src/cli/services/commandRunner.js +667 -18
  190. package/dist/orchestrator/src/cli/services/execRuntime.js +66 -1
  191. package/dist/orchestrator/src/cli/services/orchestratorAutoScoutEvidenceRecorder.js +71 -0
  192. package/dist/orchestrator/src/cli/services/orchestratorCloudBranchResolution.js +8 -0
  193. package/dist/orchestrator/src/cli/services/orchestratorCloudEnvironmentResolution.js +22 -0
  194. package/dist/orchestrator/src/cli/services/orchestratorCloudExecutionLifecycleShell.js +39 -0
  195. package/dist/orchestrator/src/cli/services/orchestratorCloudPromptBuilder.js +37 -0
  196. package/dist/orchestrator/src/cli/services/orchestratorCloudRouteFallbackContract.js +45 -0
  197. package/dist/orchestrator/src/cli/services/orchestratorCloudRouteShell.js +36 -0
  198. package/dist/orchestrator/src/cli/services/orchestratorCloudTargetExecutor.js +277 -0
  199. package/dist/orchestrator/src/cli/services/orchestratorControlPlaneLifecycle.js +98 -0
  200. package/dist/orchestrator/src/cli/services/orchestratorControlPlaneLifecycleShell.js +54 -0
  201. package/dist/orchestrator/src/cli/services/orchestratorExecutionLifecycle.js +112 -0
  202. package/dist/orchestrator/src/cli/services/orchestratorExecutionModePolicy.js +27 -0
  203. package/dist/orchestrator/src/cli/services/orchestratorExecutionRouteAdapterShell.js +59 -0
  204. package/dist/orchestrator/src/cli/services/orchestratorExecutionRouteDecisionShell.js +57 -0
  205. package/dist/orchestrator/src/cli/services/orchestratorExecutionRouteState.js +21 -0
  206. package/dist/orchestrator/src/cli/services/orchestratorExecutionRouter.js +2 -0
  207. package/dist/orchestrator/src/cli/services/orchestratorLocalPipelineExecutor.js +149 -0
  208. package/dist/orchestrator/src/cli/services/orchestratorLocalRouteShell.js +63 -0
  209. package/dist/orchestrator/src/cli/services/orchestratorPlanShell.js +54 -0
  210. package/dist/orchestrator/src/cli/services/orchestratorPlanTargetTracker.js +16 -0
  211. package/dist/orchestrator/src/cli/services/orchestratorResumePreparationShell.js +84 -0
  212. package/dist/orchestrator/src/cli/services/orchestratorResumeTokenValidation.js +15 -0
  213. package/dist/orchestrator/src/cli/services/orchestratorRunLifecycleCompletion.js +31 -0
  214. package/dist/orchestrator/src/cli/services/orchestratorRunLifecycleExecutionRegistration.js +37 -0
  215. package/dist/orchestrator/src/cli/services/orchestratorRunLifecycleOrchestrationShell.js +83 -0
  216. package/dist/orchestrator/src/cli/services/orchestratorRunLifecycleTaskManagerShell.js +37 -0
  217. package/dist/orchestrator/src/cli/services/orchestratorRuntimeManifestMutation.js +20 -0
  218. package/dist/orchestrator/src/cli/services/orchestratorStartPreparationShell.js +56 -0
  219. package/dist/orchestrator/src/cli/services/orchestratorStatusShell.js +70 -0
  220. package/dist/orchestrator/src/cli/services/pipelineResolver.js +7 -3
  221. package/dist/orchestrator/src/cli/services/plannerMemory.js +119 -0
  222. package/dist/orchestrator/src/cli/services/runPreparation.js +7 -3
  223. package/dist/orchestrator/src/cli/services/runSummaryWriter.js +9 -0
  224. package/dist/orchestrator/src/cli/setupBootstrapShell.js +114 -0
  225. package/dist/orchestrator/src/cli/setupCliShell.js +51 -0
  226. package/dist/orchestrator/src/cli/skillsCliShell.js +56 -0
  227. package/dist/orchestrator/src/cli/startCliRequestShell.js +53 -0
  228. package/dist/orchestrator/src/cli/startCliShell.js +68 -0
  229. package/dist/orchestrator/src/cli/statusCliShell.js +22 -0
  230. package/dist/orchestrator/src/cli/utils/authProvenanceFingerprint.js +27 -0
  231. package/dist/orchestrator/src/cli/utils/cloudPreflight.js +83 -1
  232. package/dist/orchestrator/src/cli/utils/delegationConfigParser.js +250 -0
  233. package/dist/orchestrator/src/cli/utils/delegationMcpHealth.js +1382 -0
  234. package/dist/orchestrator/src/cli/utils/devtools.js +2 -54
  235. package/dist/orchestrator/src/cli/utils/mcpServerEntry.js +53 -0
  236. package/dist/orchestrator/src/cli/utils/packageProgramResolver.js +151 -0
  237. package/dist/orchestrator/src/cli/utils/providerOverrideEnv.js +71 -0
  238. package/dist/orchestrator/src/cli/utils/trailingJsonObject.js +59 -0
  239. package/dist/orchestrator/src/learning/crystalizer.js +2 -2
  240. package/dist/orchestrator/src/persistence/ExperienceStore.js +233 -49
  241. package/dist/orchestrator/src/persistence/TaskStateStore.js +6 -6
  242. package/dist/orchestrator/src/persistence/lockFile.js +70 -4
  243. package/dist/orchestrator/src/persistence/sanitizeIdentifier.js +39 -0
  244. package/dist/orchestrator/src/sync/createCloudSyncWorker.js +3 -2
  245. package/dist/orchestrator/src/utils/atomicWrite.js +17 -2
  246. package/dist/packages/orchestrator/src/exec/unified-exec.js +99 -6
  247. package/dist/packages/orchestrator/src/instructions/promptPacks.js +150 -19
  248. package/dist/packages/sdk-node/src/orchestrator.js +137 -13
  249. package/dist/packages/shared/config/designConfig.js +8 -1
  250. package/dist/packages/shared/streams/stdio.js +1 -1
  251. package/dist/scripts/design/pipeline/permit.js +15 -0
  252. package/dist/scripts/lib/docs-catalog.js +365 -0
  253. package/dist/scripts/lib/docs-helpers.js +87 -5
  254. package/dist/scripts/lib/pr-watch-merge.js +1088 -80
  255. package/dist/scripts/lib/provider-run-contract.js +26 -0
  256. package/dist/scripts/lib/review-command-intent-classification.js +532 -0
  257. package/dist/scripts/lib/review-command-probe-classification.js +385 -0
  258. package/dist/scripts/lib/review-execution-boundary-preflight.js +279 -0
  259. package/dist/scripts/lib/review-execution-runtime.js +753 -0
  260. package/dist/scripts/lib/review-execution-state.js +1144 -0
  261. package/dist/scripts/lib/review-execution-telemetry.js +215 -0
  262. package/dist/scripts/lib/review-inspection-target-parsing.js +78 -0
  263. package/dist/scripts/lib/review-launch-attempt.js +601 -0
  264. package/dist/scripts/lib/review-meta-surface-boundary-analysis.js +300 -0
  265. package/dist/scripts/lib/review-meta-surface-normalization.js +746 -0
  266. package/dist/scripts/lib/review-non-interactive-handoff.js +61 -0
  267. package/dist/scripts/lib/review-prompt-context.js +376 -0
  268. package/dist/scripts/lib/review-scope-advisory.js +286 -0
  269. package/dist/scripts/lib/review-scope-paths.js +123 -0
  270. package/dist/scripts/lib/review-shell-command-parser.js +389 -0
  271. package/dist/scripts/lib/review-shell-env-interpreter.js +340 -0
  272. package/dist/scripts/lib/run-manifests.js +192 -36
  273. package/dist/scripts/lib/spark-policy-classifier.js +593 -0
  274. package/dist/scripts/run-review.js +507 -1777
  275. package/docs/public/downstream-setup.md +106 -0
  276. package/docs/public/provider-onboarding.md +173 -0
  277. package/package.json +20 -10
  278. package/plugins/codex-orchestrator/.codex-plugin/plugin.json +30 -0
  279. package/plugins/codex-orchestrator/.mcp.json +13 -0
  280. package/plugins/codex-orchestrator/launcher.mjs +359 -0
  281. package/schemas/manifest.json +394 -0
  282. package/skills/collab-subagents-first/SKILL.md +1 -1
  283. package/skills/delegation-usage/DELEGATION_GUIDE.md +24 -11
  284. package/skills/delegation-usage/SKILL.md +19 -13
  285. package/skills/land/SKILL.md +77 -0
  286. package/skills/linear/SKILL.md +255 -0
  287. package/skills/release/SKILL.md +47 -3
  288. package/skills/standalone-review/SKILL.md +6 -1
  289. package/templates/README.md +4 -2
  290. package/templates/codex/.codex/agents/awaiter-high.toml +2 -2
  291. package/templates/codex/.codex/agents/worker-complex.toml +1 -1
  292. package/templates/codex/.codex/config.toml +3 -4
  293. package/templates/codex/.codex/providers/README.md +13 -0
  294. package/templates/codex/.codex/providers/control.example.json +18 -0
  295. package/templates/codex/.codex/providers/provider.env.example +15 -0
  296. package/templates/codex/AGENTS.md +12 -7
  297. package/templates/codex/mcp-client.json +5 -1
  298. package/docs/README.md +0 -310
  299. package/docs/assets/setup.gif +0 -0
@@ -0,0 +1,601 @@
1
+ import { spawn } from 'node:child_process';
2
+ import { mkdir, readFile, writeFile } from 'node:fs/promises';
3
+ import path from 'node:path';
4
+ import { createRuntimeCodexCommandContext, parseRuntimeMode, resolveRuntimeCodexCommand } from '../../orchestrator/src/cli/runtime/index.js';
5
+ import { runDoctor } from '../../orchestrator/src/cli/doctor.js';
6
+ import { formatDoctorIssueLogSummary, writeDoctorIssueLog } from '../../orchestrator/src/cli/doctorIssueLog.js';
7
+ import { ReviewExecutionState } from './review-execution-state.js';
8
+ import { formatCommandIntentViolationLabel } from './review-command-intent-classification.js';
9
+ import { CodexReviewError, signalChildProcess } from './review-execution-runtime.js';
10
+ import { formatReviewOutcomeSummary } from './review-execution-telemetry.js';
11
+ const REVIEW_COMMAND_CHECK_TIMEOUT_MS = 30_000;
12
+ const REVIEW_ARTIFACTS_DIRNAME = 'review';
13
+ const REVIEW_DISABLE_DELEGATION_CONFIG_OVERRIDE = 'mcp_servers.delegation.enabled=false';
14
+ const REVIEW_READ_ONLY_SANDBOX_CONFIG_OVERRIDE = 'sandbox_mode="read-only"';
15
+ const REVIEW_PARTIAL_OUTPUT_HINT_BOUNDARY_KINDS = new Set(['timeout', 'stall', 'startup-loop']);
16
+ const COMMAND_INTENT_RETRY_PROMPT_PREFIX = [
17
+ 'Strict bounded review retry.',
18
+ 'A previous bounded review attempt crossed the command-intent boundary by trying to run validation or another disallowed orchestration command.',
19
+ 'Do not run validation commands, nested review/pipeline commands, or delegation control commands in this retry.',
20
+ 'Use read-only inspection only. If validation would improve confidence, list the command as a follow-up instead of executing it.',
21
+ 'Return a review verdict: start with concrete findings, or state that you found no actionable issues.'
22
+ ].join('\n');
23
+ export async function resolveReviewRuntimeContext(params) {
24
+ const runId = await resolveReviewRunId(params.manifestPath);
25
+ const requestedMode = params.options.runtimeMode ??
26
+ parseRuntimeMode(params.env.CODEX_ORCHESTRATOR_RUNTIME_MODE_ACTIVE ??
27
+ params.env.CODEX_ORCHESTRATOR_RUNTIME_MODE ??
28
+ null);
29
+ return await createRuntimeCodexCommandContext({
30
+ requestedMode,
31
+ executionMode: 'mcp',
32
+ repoRoot: params.repoRoot,
33
+ env: params.env,
34
+ runId: runId ?? `review-${Date.now()}`
35
+ });
36
+ }
37
+ export async function prepareReviewArtifacts(manifestPath, prompt, repoRoot) {
38
+ const reviewDir = resolveReviewArtifactsDir(manifestPath, repoRoot);
39
+ await mkdir(reviewDir, { recursive: true });
40
+ const promptPath = path.join(reviewDir, 'prompt.txt');
41
+ const outputLogPath = path.join(reviewDir, 'output.log');
42
+ const telemetryPath = path.join(reviewDir, 'telemetry.json');
43
+ await writeFile(promptPath, `${prompt}\n`, 'utf8');
44
+ return { reviewDir, promptPath, outputLogPath, telemetryPath };
45
+ }
46
+ export async function runReviewLaunchAttemptShell(options) {
47
+ // Keep review launch retries centralized here while run-review, non-interactive handoff,
48
+ // and execution-boundary preflight still share the same launch semantics.
49
+ const ensureCommandAvailable = options.ensureReviewCommandAvailableFn ?? ensureReviewCommandAvailable;
50
+ const resolveCommand = options.resolveReviewCommandFn ?? resolveReviewCommand;
51
+ const captureReviewFailureIssueLog = options.captureReviewFailureIssueLogFn ?? maybeCaptureReviewFailureIssueLog;
52
+ await ensureCommandAvailable(options.runtimeContext);
53
+ const disableDelegationMcp = options.cliOptions.disableDelegationMcp ??
54
+ (options.cliOptions.enableDelegationMcp === undefined ? false : !options.cliOptions.enableDelegationMcp);
55
+ if (disableDelegationMcp) {
56
+ console.log('[run-review] delegation MCP disabled for this review (explicit opt-out via --disable-delegation-mcp or CODEX_REVIEW_DISABLE_DELEGATION_MCP=1).');
57
+ }
58
+ else {
59
+ console.log('[run-review] delegation MCP enabled for this review (default; set --disable-delegation-mcp or CODEX_REVIEW_DISABLE_DELEGATION_MCP=1 to disable).');
60
+ }
61
+ const scopedReviewArgs = buildReviewArgs(options.cliOptions, options.prompt, {
62
+ includeScopeFlags: true,
63
+ disableDelegationMcp
64
+ });
65
+ const scopedLaunchContext = buildReviewLaunchContext(options.cliOptions, {
66
+ includeScopeFlags: true
67
+ });
68
+ const resolvedScoped = resolveCommand(scopedReviewArgs, options.runtimeContext);
69
+ const launchedWithExplicitScope = scopedReviewArgs.some((arg) => arg === '--base' || arg === '--commit' || arg === '--uncommitted');
70
+ console.log(`Review prompt saved to: ${path.relative(options.repoRoot, options.artifactPaths.promptPath)}`);
71
+ console.log(`Review output log: ${path.relative(options.repoRoot, options.artifactPaths.outputLogPath)}`);
72
+ console.log(`Launching Codex review (evidence: ${path.relative(options.repoRoot, options.manifestPath)})`);
73
+ if (scopedLaunchContext.prompt_delivery === 'artifact-only' &&
74
+ scopedLaunchContext.scope_flag_mode !== null) {
75
+ if (scopedLaunchContext.reviewer_visible_context_transport === 'scoped-title') {
76
+ const titleSourceLabel = scopedLaunchContext.reviewer_visible_title_source === 'user'
77
+ ? 'user-provided --title'
78
+ : 'bounded NOTES+surface title';
79
+ console.log(`[run-review] explicit ${scopedLaunchContext.scope_flag_mode} scope keeps full prompt context in the saved artifact; current codex review still rejects inline prompt transport under scope flags, so this launch omits any prompt argument and uses ${titleSourceLabel} for reviewer-visible context.`);
80
+ }
81
+ else {
82
+ console.log(`[run-review] explicit ${scopedLaunchContext.scope_flag_mode} scope keeps prompt context in the saved artifact only; current codex review still treats stdin ("-") as [PROMPT], so this launch omits any prompt argument.`);
83
+ }
84
+ }
85
+ const reportSuccess = async (execution, launchContext, preservedTerminationBoundary) => {
86
+ const telemetryPayload = await options.writeTelemetry(execution.state, 'succeeded', null, preservedTerminationBoundary ?? execution.terminationBoundary ?? null, launchContext);
87
+ console.log(`Review output saved to: ${path.relative(options.repoRoot, options.artifactPaths.outputLogPath)}`);
88
+ if (telemetryPayload) {
89
+ console.log(`[run-review] review outcome: ${formatReviewOutcomeSummary(telemetryPayload)}.`);
90
+ console.log(`Review telemetry saved to: ${path.relative(options.repoRoot, options.artifactPaths.telemetryPath)}`);
91
+ }
92
+ else {
93
+ console.warn('[run-review] review telemetry unavailable (persistence failed); see earlier telemetry error logs.');
94
+ }
95
+ };
96
+ const reportFailure = async (error, launchContext) => {
97
+ await captureReviewFailureIssueLog({
98
+ enabled: options.autoIssueLogEnabled,
99
+ error,
100
+ taskFilter: options.cliOptions.task ?? null,
101
+ manifestPath: options.manifestPath,
102
+ outputLogPath: options.artifactPaths.outputLogPath,
103
+ repoRoot: options.repoRoot
104
+ });
105
+ const errorMessage = error instanceof Error ? error.message : String(error);
106
+ const failureState = error instanceof CodexReviewError &&
107
+ 'reviewState' in error &&
108
+ error.reviewState instanceof ReviewExecutionState
109
+ ? error.reviewState
110
+ : null;
111
+ const failureTerminationBoundary = error instanceof CodexReviewError ? error.terminationBoundary : null;
112
+ const telemetryPayload = failureState
113
+ ? await options.writeTelemetry(failureState, 'failed', errorMessage, failureTerminationBoundary, launchContext)
114
+ : null;
115
+ if (telemetryPayload) {
116
+ options.logTelemetrySummary(telemetryPayload, path.relative(options.repoRoot, options.artifactPaths.telemetryPath), {
117
+ debugTelemetry: options.telemetryDebugEnabled,
118
+ telemetryDebugEnvKey: options.telemetryDebugEnvKey
119
+ });
120
+ }
121
+ else if (failureState) {
122
+ options.logTerminationBoundaryFallback(failureTerminationBoundary ?? failureState.getTerminationBoundaryRecord(errorMessage));
123
+ }
124
+ if (shouldLogPartialReviewOutput(failureTerminationBoundary)) {
125
+ console.error(`Review output log (partial): ${path.relative(options.repoRoot, options.artifactPaths.outputLogPath)}`);
126
+ }
127
+ };
128
+ const maybeRetryAfterCommandIntentBoundary = async (error, launchContext, resolvedFailedLaunch) => {
129
+ if (!shouldRetryAfterCommandIntentBoundary(error, launchContext)) {
130
+ return false;
131
+ }
132
+ const commandIntentBoundary = error instanceof CodexReviewError ? error.terminationBoundary : null;
133
+ const commandIntentFailureState = error instanceof CodexReviewError && error.reviewState instanceof ReviewExecutionState
134
+ ? error.reviewState
135
+ : null;
136
+ const commandIntentRetryOptions = buildCommandIntentRetryOptions(options.cliOptions);
137
+ const commandIntentRetryPrompt = buildCommandIntentRetryPrompt(options.prompt, commandIntentFailureState, options.cliOptions);
138
+ const commandIntentRetryArgs = buildReviewArgs(commandIntentRetryOptions, commandIntentRetryPrompt, {
139
+ includeScopeFlags: false,
140
+ disableDelegationMcp,
141
+ inlineReadOnlySandbox: true
142
+ });
143
+ const commandIntentRetryLaunchContext = buildReviewLaunchContext(commandIntentRetryOptions, {
144
+ includeScopeFlags: false
145
+ });
146
+ const resolvedCommandIntentRetry = resolveCommand(commandIntentRetryArgs, options.runtimeContext);
147
+ if (resolvedReviewCommandsEqual(resolvedFailedLaunch, resolvedCommandIntentRetry)) {
148
+ await reportFailure(error, launchContext);
149
+ throw error;
150
+ }
151
+ console.log('[run-review] bounded review blocked a validation command; retrying once with reviewer-visible inline no-validation context so the reviewer can produce a verdict without running validation.');
152
+ console.log('[run-review] command-intent retry keeps the original scope in the inline prompt and adds a read-only sandbox override; another validation command remains a fail-closed boundary.');
153
+ try {
154
+ const retryExecution = await options.runReview(resolvedCommandIntentRetry);
155
+ if (commandIntentFailureState) {
156
+ retryExecution.state.recordCommandIntentViolationsFrom(commandIntentFailureState);
157
+ }
158
+ await reportSuccess(retryExecution, commandIntentRetryLaunchContext, commandIntentBoundary);
159
+ return true;
160
+ }
161
+ catch (retryError) {
162
+ await reportFailure(retryError, commandIntentRetryLaunchContext);
163
+ throw retryError;
164
+ }
165
+ };
166
+ try {
167
+ const execution = await options.runReview(resolvedScoped);
168
+ await reportSuccess(execution, scopedLaunchContext);
169
+ return;
170
+ }
171
+ catch (error) {
172
+ if (await maybeRetryAfterCommandIntentBoundary(error, scopedLaunchContext, resolvedScoped)) {
173
+ return;
174
+ }
175
+ if (shouldRetryScopedWithoutSynthesizedTitle(error, options.cliOptions)) {
176
+ const scopedArtifactOnlyOptions = {
177
+ ...options.cliOptions,
178
+ title: undefined,
179
+ titleSource: undefined
180
+ };
181
+ const scopedArtifactOnlyArgs = buildReviewArgs(scopedArtifactOnlyOptions, options.prompt, {
182
+ includeScopeFlags: true,
183
+ disableDelegationMcp
184
+ });
185
+ const scopedArtifactOnlyLaunchContext = buildReviewLaunchContext(scopedArtifactOnlyOptions, {
186
+ includeScopeFlags: true
187
+ });
188
+ const resolvedScopedArtifactOnly = resolveCommand(scopedArtifactOnlyArgs, options.runtimeContext);
189
+ if (resolvedReviewCommandsEqual(resolvedScoped, resolvedScopedArtifactOnly)) {
190
+ await reportFailure(error, scopedLaunchContext);
191
+ throw error;
192
+ }
193
+ console.log('[run-review] codex CLI rejected synthesized scoped --title transport; retrying the same explicit scope without --title and falling back to artifact-only reviewer-visible context.');
194
+ try {
195
+ const retryExecution = await options.runReview(resolvedScopedArtifactOnly);
196
+ await reportSuccess(retryExecution, scopedArtifactOnlyLaunchContext);
197
+ return;
198
+ }
199
+ catch (retryError) {
200
+ if (await maybeRetryAfterCommandIntentBoundary(retryError, scopedArtifactOnlyLaunchContext, resolvedScopedArtifactOnly)) {
201
+ return;
202
+ }
203
+ await reportFailure(retryError, scopedArtifactOnlyLaunchContext);
204
+ throw retryError;
205
+ }
206
+ }
207
+ if (scopedLaunchContext.prompt_delivery !== 'inline' &&
208
+ isPromptScopeIncompatibility(error)) {
209
+ await reportFailure(error, scopedLaunchContext);
210
+ throw error;
211
+ }
212
+ if (shouldRetryWithoutScopeFlags(error)) {
213
+ if (launchedWithExplicitScope) {
214
+ if (options.retryWithoutScopeFlagsGateError &&
215
+ shouldRewriteRetryFailureAsScopeGate(error, options.cliOptions)) {
216
+ const retryGateError = buildRetryWithoutScopeFlagsGateError(error, options.repoRoot, options.retryWithoutScopeFlagsGateError);
217
+ await reportFailure(retryGateError, scopedLaunchContext);
218
+ throw retryGateError;
219
+ }
220
+ await reportFailure(error, scopedLaunchContext);
221
+ throw error;
222
+ }
223
+ if (options.retryWithoutScopeFlagsGateError &&
224
+ shouldRewriteRetryFailureAsScopeGate(error, options.cliOptions)) {
225
+ const retryGateError = buildRetryWithoutScopeFlagsGateError(error, options.repoRoot, options.retryWithoutScopeFlagsGateError);
226
+ await reportFailure(retryGateError, scopedLaunchContext);
227
+ throw retryGateError;
228
+ }
229
+ const unscopedArgs = buildReviewArgs(options.cliOptions, options.prompt, {
230
+ includeScopeFlags: false,
231
+ disableDelegationMcp
232
+ });
233
+ const unscopedLaunchContext = buildReviewLaunchContext(options.cliOptions, {
234
+ includeScopeFlags: false
235
+ });
236
+ const resolvedUnscoped = resolveCommand(unscopedArgs, options.runtimeContext);
237
+ if (resolvedReviewCommandsEqual(resolvedScoped, resolvedUnscoped)) {
238
+ await reportFailure(error, scopedLaunchContext);
239
+ throw error;
240
+ }
241
+ console.log('[run-review] codex CLI rejected scope flags with a custom prompt; retrying without flags.');
242
+ try {
243
+ const retryExecution = await options.runReview(resolvedUnscoped);
244
+ await reportSuccess(retryExecution, unscopedLaunchContext);
245
+ return;
246
+ }
247
+ catch (retryError) {
248
+ await reportFailure(retryError, unscopedLaunchContext);
249
+ throw retryError;
250
+ }
251
+ }
252
+ await reportFailure(error, scopedLaunchContext);
253
+ throw error;
254
+ }
255
+ }
256
+ async function ensureReviewCommandAvailable(context) {
257
+ const resolved = resolveRuntimeCodexCommand(['--help'], context);
258
+ const hasReview = await new Promise((resolve, reject) => {
259
+ const detached = process.platform !== 'win32';
260
+ const child = spawn(resolved.command, resolved.args, { stdio: ['ignore', 'pipe', 'pipe'], detached });
261
+ let output = '';
262
+ let settled = false;
263
+ let hardKillArmed = false;
264
+ let killHandle;
265
+ const timeoutHandle = setTimeout(() => {
266
+ if (settled) {
267
+ return;
268
+ }
269
+ signalChildProcess(child, 'SIGTERM', detached);
270
+ hardKillArmed = true;
271
+ killHandle = setTimeout(() => {
272
+ if (child.exitCode === null) {
273
+ signalChildProcess(child, 'SIGKILL', detached);
274
+ }
275
+ }, 5000);
276
+ killHandle.unref();
277
+ settled = true;
278
+ reject(new Error('codex --help timed out while checking the review subcommand.'));
279
+ }, REVIEW_COMMAND_CHECK_TIMEOUT_MS);
280
+ timeoutHandle.unref();
281
+ const finalize = (outcome) => {
282
+ if (settled) {
283
+ return;
284
+ }
285
+ settled = true;
286
+ clearTimeout(timeoutHandle);
287
+ if (killHandle && !hardKillArmed) {
288
+ clearTimeout(killHandle);
289
+ }
290
+ if ('error' in outcome) {
291
+ reject(outcome.error);
292
+ }
293
+ else {
294
+ resolve(outcome.ok);
295
+ }
296
+ };
297
+ child.stdout?.on('data', (chunk) => {
298
+ output += chunk.toString();
299
+ });
300
+ child.stderr?.on('data', (chunk) => {
301
+ output += chunk.toString();
302
+ });
303
+ child.once('error', (error) => finalize({ error: error instanceof Error ? error : new Error(String(error)) }));
304
+ child.once('close', () => {
305
+ finalize({ ok: output.includes(' review') });
306
+ });
307
+ });
308
+ if (!hasReview) {
309
+ throw new Error('codex CLI is missing the `review` subcommand (or is not installed).');
310
+ }
311
+ }
312
+ async function resolveReviewRunId(manifestPath) {
313
+ try {
314
+ const raw = await readFile(manifestPath, 'utf8');
315
+ const parsed = JSON.parse(raw);
316
+ return typeof parsed.run_id === 'string' && parsed.run_id.trim().length > 0
317
+ ? parsed.run_id.trim()
318
+ : null;
319
+ }
320
+ catch {
321
+ return null;
322
+ }
323
+ }
324
+ function resolveScopeFlag(options) {
325
+ if (options.commit) {
326
+ return { mode: 'commit', args: ['--commit', options.commit] };
327
+ }
328
+ if (options.base) {
329
+ return { mode: 'base', args: ['--base', options.base] };
330
+ }
331
+ if (options.uncommitted) {
332
+ return { mode: 'uncommitted', args: ['--uncommitted'] };
333
+ }
334
+ return null;
335
+ }
336
+ function buildReviewArgs(options, prompt, opts) {
337
+ const args = [];
338
+ if (opts.disableDelegationMcp) {
339
+ args.push('-c', REVIEW_DISABLE_DELEGATION_CONFIG_OVERRIDE);
340
+ }
341
+ if (opts.inlineReadOnlySandbox) {
342
+ args.push('-c', REVIEW_READ_ONLY_SANDBOX_CONFIG_OVERRIDE);
343
+ }
344
+ args.push('review');
345
+ const reviewTitle = resolveReviewTitle(options);
346
+ if (reviewTitle.title) {
347
+ args.push('--title', reviewTitle.title);
348
+ }
349
+ const scopeFlag = resolveScopeFlag(options);
350
+ if (opts.includeScopeFlags && scopeFlag) {
351
+ args.push(...scopeFlag.args);
352
+ }
353
+ const launchContext = buildReviewLaunchContext(options, opts);
354
+ if (launchContext.prompt_delivery === 'inline') {
355
+ args.push(prompt);
356
+ }
357
+ return args;
358
+ }
359
+ function buildReviewLaunchContext(options, opts) {
360
+ const scopedFlag = opts.includeScopeFlags ? resolveScopeFlag(options) : null;
361
+ const reviewTitle = resolveReviewTitle(options);
362
+ return {
363
+ scope_flag_mode: scopedFlag?.mode ?? null,
364
+ prompt_delivery: scopedFlag ? 'artifact-only' : 'inline',
365
+ reviewer_visible_context_transport: scopedFlag
366
+ ? reviewTitle.source
367
+ ? 'scoped-title'
368
+ : 'artifact-only'
369
+ : 'inline-prompt',
370
+ reviewer_visible_title_source: scopedFlag ? reviewTitle.source : null
371
+ };
372
+ }
373
+ function resolveReviewTitle(options) {
374
+ const rawTitle = typeof options.title === 'string' ? options.title.trim() : '';
375
+ if (rawTitle.length === 0) {
376
+ return { title: null, source: null };
377
+ }
378
+ return {
379
+ title: rawTitle,
380
+ source: options.titleSource ?? 'user'
381
+ };
382
+ }
383
+ function resolveReviewCommand(reviewArgs, context) {
384
+ return resolveRuntimeCodexCommand(reviewArgs, context);
385
+ }
386
+ function resolveReviewArtifactsDir(manifestPath, repoRoot) {
387
+ const configuredRunDir = process.env.CODEX_ORCHESTRATOR_RUN_DIR?.trim();
388
+ if (configuredRunDir && configuredRunDir.length > 0) {
389
+ const resolvedRunDir = path.resolve(repoRoot, configuredRunDir);
390
+ const configuredManifestPath = path.join(resolvedRunDir, 'manifest.json');
391
+ if (configuredManifestPath === path.resolve(manifestPath)) {
392
+ return path.join(resolvedRunDir, REVIEW_ARTIFACTS_DIRNAME);
393
+ }
394
+ }
395
+ return path.join(path.dirname(manifestPath), REVIEW_ARTIFACTS_DIRNAME);
396
+ }
397
+ async function maybeCaptureReviewFailureIssueLog(options) {
398
+ if (!options.enabled) {
399
+ return null;
400
+ }
401
+ const errorMessage = options.error instanceof Error ? options.error.message : String(options.error);
402
+ const issueNotes = [
403
+ 'Automatic failure capture for standalone review wrapper.',
404
+ `Error: ${errorMessage}`,
405
+ `Manifest: ${path.relative(options.repoRoot, options.manifestPath)}`,
406
+ `Output log: ${path.relative(options.repoRoot, options.outputLogPath)}`
407
+ ].join(' | ');
408
+ try {
409
+ const issueLog = await writeDoctorIssueLog({
410
+ doctor: runDoctor(),
411
+ issueTitle: 'Auto issue log: standalone review failed',
412
+ issueNotes,
413
+ taskFilter: options.taskFilter
414
+ });
415
+ console.error('[run-review] captured review failure issue log:');
416
+ for (const line of formatDoctorIssueLogSummary(issueLog)) {
417
+ console.error(`[run-review] ${line}`);
418
+ }
419
+ return issueLog;
420
+ }
421
+ catch (issueError) {
422
+ const message = issueError instanceof Error ? issueError.message : String(issueError);
423
+ console.error(`[run-review] failed to capture review issue log: ${message}`);
424
+ return null;
425
+ }
426
+ }
427
+ function shouldLogPartialReviewOutput(terminationBoundary) {
428
+ return (terminationBoundary !== null &&
429
+ REVIEW_PARTIAL_OUTPUT_HINT_BOUNDARY_KINDS.has(terminationBoundary.kind));
430
+ }
431
+ function resolvedReviewCommandsEqual(left, right) {
432
+ return (left.command === right.command &&
433
+ left.args.length === right.args.length &&
434
+ left.args.every((arg, index) => arg === right.args[index]));
435
+ }
436
+ function shouldRetryAfterCommandIntentBoundary(error, launchContext) {
437
+ return (error instanceof CodexReviewError &&
438
+ error.terminationBoundary?.kind === 'command-intent' &&
439
+ launchContext.prompt_delivery === 'artifact-only' &&
440
+ launchContext.scope_flag_mode !== null);
441
+ }
442
+ function buildCommandIntentRetryOptions(options) {
443
+ return {
444
+ ...options,
445
+ title: undefined,
446
+ titleSource: undefined
447
+ };
448
+ }
449
+ function buildCommandIntentRetryPrompt(prompt, failureState, options) {
450
+ const boundaryState = failureState?.getCommandIntentBoundaryState() ?? null;
451
+ const blockedAttemptLine = boundaryState?.violationKind
452
+ ? `Blocked attempt: ${formatCommandIntentViolationLabel(boundaryState.violationKind)}.`
453
+ : 'Blocked attempt: bounded command-intent boundary.';
454
+ const blockedSampleLine = boundaryState?.violationSample
455
+ ? `Treat this as a follow-up command only, not something to rerun: ${boundaryState.violationSample}`
456
+ : 'Treat any validation or nested review command you considered as a follow-up command only, not something to rerun.';
457
+ const scopeLine = formatCommandIntentRetryScopeLine(options);
458
+ return [
459
+ COMMAND_INTENT_RETRY_PROMPT_PREFIX,
460
+ scopeLine,
461
+ blockedAttemptLine,
462
+ blockedSampleLine,
463
+ '',
464
+ prompt
465
+ ].join('\n');
466
+ }
467
+ function formatCommandIntentRetryScopeLine(options) {
468
+ const scopeFlag = resolveScopeFlag(options);
469
+ if (!scopeFlag) {
470
+ return 'Retry review scope: wrapper default review scope.';
471
+ }
472
+ return `Retry review scope: ${scopeFlag.args.join(' ')}. Use this same logical scope while inspecting the diff.`;
473
+ }
474
+ function shouldRetryWithoutScopeFlags(error) {
475
+ if (!error || typeof error !== 'object') {
476
+ return false;
477
+ }
478
+ const preview = 'outputPreview' in error ? String(error.outputPreview ?? '') : '';
479
+ const message = 'message' in error ? String(error.message ?? '') : '';
480
+ const combined = `${message}\n${preview}`.toLowerCase();
481
+ return (combined.includes('unknown option') ||
482
+ combined.includes('unknown flag') ||
483
+ combined.includes('unrecognized option') ||
484
+ combined.includes('cannot be used with') ||
485
+ combined.includes('cannot be combined') ||
486
+ combined.includes('incompatible with') ||
487
+ combined.includes('prompt cannot') ||
488
+ combined.includes('custom prompt') ||
489
+ combined.includes('with a prompt'));
490
+ }
491
+ function shouldRetryScopedWithoutSynthesizedTitle(error, cliOptions) {
492
+ if (cliOptions.titleSource !== 'notes-surface') {
493
+ return false;
494
+ }
495
+ if (!resolveScopeFlag(cliOptions)) {
496
+ return false;
497
+ }
498
+ if (!error || typeof error !== 'object') {
499
+ return false;
500
+ }
501
+ const preview = 'outputPreview' in error ? String(error.outputPreview ?? '') : '';
502
+ const message = 'message' in error ? String(error.message ?? '') : '';
503
+ const combined = `${message}\n${preview}`.toLowerCase();
504
+ const lines = combined
505
+ .split(/\r?\n/)
506
+ .map((line) => line.trim())
507
+ .filter((line) => line.length > 0);
508
+ return (hasExplicitScopeFlagRejectionSignal(lines, '--title') ||
509
+ lines.some((line) => line.includes('--title') && hasPromptScopeFlagRejectionSignal(line)));
510
+ }
511
+ function isPromptScopeIncompatibility(error) {
512
+ if (!error || typeof error !== 'object') {
513
+ return false;
514
+ }
515
+ const preview = 'outputPreview' in error ? String(error.outputPreview ?? '') : '';
516
+ const message = 'message' in error ? String(error.message ?? '') : '';
517
+ const combined = `${message}\n${preview}`.toLowerCase();
518
+ return (combined.includes('prompt cannot') ||
519
+ combined.includes('custom prompt') ||
520
+ combined.includes('with a prompt'));
521
+ }
522
+ function shouldRewriteRetryFailureAsScopeGate(error, cliOptions) {
523
+ if (!error || typeof error !== 'object') {
524
+ return false;
525
+ }
526
+ const scopeFlag = resolveScopeFlag(cliOptions);
527
+ const scopeFlagToken = scopeFlag?.args[0]?.toLowerCase() ?? null;
528
+ if (!scopeFlagToken) {
529
+ return false;
530
+ }
531
+ const preview = 'outputPreview' in error ? String(error.outputPreview ?? '') : '';
532
+ const message = 'message' in error ? String(error.message ?? '') : '';
533
+ const combined = `${message}\n${preview}`.toLowerCase();
534
+ const lines = combined
535
+ .split(/\r?\n/)
536
+ .map((line) => line.trim())
537
+ .filter((line) => line.length > 0);
538
+ return (hasExplicitScopeFlagRejectionSignal(lines, scopeFlagToken) ||
539
+ lines.some((line) => line.includes(scopeFlagToken) &&
540
+ hasPromptScopeFlagRejectionSignal(line)) ||
541
+ hasPromptScopeIncompatibilitySignal(lines, scopeFlagToken));
542
+ }
543
+ function hasExplicitScopeFlagRejectionSignal(lines, scopeFlagToken) {
544
+ const escapedScopeFlagToken = escapeForRegExp(scopeFlagToken);
545
+ const quotedOrBareScopeFlagToken = `(?:['"]${escapedScopeFlagToken}['"]|${escapedScopeFlagToken})`;
546
+ const tokenBoundary = `(?=$|\\s|[),.:;])`;
547
+ const directScopeRejectionPatterns = [
548
+ new RegExp(`(?:unknown option|unknown flag|unrecognized option)\\s+${quotedOrBareScopeFlagToken}${tokenBoundary}`),
549
+ new RegExp(`^(?:option\\s+)?${quotedOrBareScopeFlagToken}\\s+(?:cannot be used with|cannot be combined|is incompatible with)`),
550
+ new RegExp(`^(?:flag\\s+)?${quotedOrBareScopeFlagToken}\\s+(?:cannot be used with|cannot be combined|is incompatible with)`),
551
+ new RegExp(`.+(?:cannot be used with|cannot be combined|incompatible with)\\s+${quotedOrBareScopeFlagToken}${tokenBoundary}`)
552
+ ];
553
+ return lines.some((line) => directScopeRejectionPatterns.some((pattern) => pattern.test(line)));
554
+ }
555
+ function hasPromptScopeFlagRejectionSignal(line) {
556
+ const mentionsPrompt = line.includes('prompt cannot') ||
557
+ line.includes('custom prompt') ||
558
+ line.includes('with a prompt');
559
+ if (!mentionsPrompt) {
560
+ return false;
561
+ }
562
+ return (line.includes('unknown option') ||
563
+ line.includes('unknown flag') ||
564
+ line.includes('unrecognized option') ||
565
+ line.includes('cannot be used with') ||
566
+ line.includes('cannot be combined') ||
567
+ line.includes('incompatible with') ||
568
+ line.includes('prompt cannot') ||
569
+ line.includes('custom prompt') ||
570
+ line.includes('with a prompt'));
571
+ }
572
+ function hasPromptScopeIncompatibilitySignal(lines, _scopeFlagToken) {
573
+ return lines.some((line) => {
574
+ const mentionsPrompt = line.includes('prompt cannot') ||
575
+ line.includes('custom prompt') ||
576
+ line.includes('with a prompt');
577
+ if (!mentionsPrompt) {
578
+ return false;
579
+ }
580
+ return (line.includes('diff scoping') ||
581
+ line.includes('diff-scoping') ||
582
+ line.includes('review scope') ||
583
+ line.includes('scope flags'));
584
+ });
585
+ }
586
+ function buildRetryWithoutScopeFlagsGateError(error, repoRoot, retryWithoutScopeFlagsGateError) {
587
+ const originalError = error instanceof CodexReviewError ? error : null;
588
+ return new CodexReviewError(`codex CLI rejected the explicit review scope flags, and retrying without them would remove explicit review scope. ${retryWithoutScopeFlagsGateError}`, {
589
+ exitCode: typeof originalError?.exitCode === 'number' && originalError.exitCode > 0
590
+ ? originalError.exitCode
591
+ : 1,
592
+ signal: originalError?.signal ?? null,
593
+ timedOut: false,
594
+ outputPreview: originalError?.outputPreview ?? '',
595
+ reviewState: originalError?.reviewState ?? new ReviewExecutionState({ repoRoot }),
596
+ terminationBoundary: originalError?.terminationBoundary ?? null
597
+ });
598
+ }
599
+ function escapeForRegExp(value) {
600
+ return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
601
+ }