@qontinui/shared-types 0.2.4 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (589) hide show
  1. package/README.md +128 -128
  2. package/dist/{Region.d-BbpFAWF4.d.cts → Region.d-DtT3UphX.d.cts} +81 -81
  3. package/dist/{Region.d-BbpFAWF4.d.ts → Region.d-DtT3UphX.d.ts} +81 -81
  4. package/dist/{TaskRunFindingActionType.d-B4VmmbB6.d.cts → TaskRunFindingActionType.d-CNIWogcU.d.cts} +53 -53
  5. package/dist/{TaskRunFindingActionType.d-B4VmmbB6.d.ts → TaskRunFindingActionType.d-CNIWogcU.d.ts} +53 -53
  6. package/dist/accessibility.cjs.map +1 -1
  7. package/dist/accessibility.d.cts +379 -379
  8. package/dist/accessibility.d.ts +379 -379
  9. package/dist/chat.cjs.map +1 -1
  10. package/dist/{chunk-ZK5MJEGT.js → chunk-CTBDIP7K.js} +1 -1
  11. package/dist/chunk-CTBDIP7K.js.map +1 -0
  12. package/dist/{chunk-YXD4WCYQ.js → chunk-ZUZ3OLOH.js} +1 -1
  13. package/dist/chunk-ZUZ3OLOH.js.map +1 -0
  14. package/dist/config.cjs.map +1 -1
  15. package/dist/config.d.cts +105 -105
  16. package/dist/config.d.ts +105 -105
  17. package/dist/constraints.cjs.map +1 -1
  18. package/dist/constraints.d.cts +372 -372
  19. package/dist/constraints.d.ts +372 -372
  20. package/dist/execution.cjs.map +1 -1
  21. package/dist/execution.d.cts +869 -869
  22. package/dist/execution.d.ts +869 -869
  23. package/dist/execution.js +1 -1
  24. package/dist/geometry.cjs.map +1 -1
  25. package/dist/geometry.d.cts +81 -81
  26. package/dist/geometry.d.ts +81 -81
  27. package/dist/index.cjs.map +1 -1
  28. package/dist/index.d.cts +632 -590
  29. package/dist/index.d.ts +632 -590
  30. package/dist/index.js +2 -2
  31. package/dist/index.js.map +1 -1
  32. package/dist/library.cjs.map +1 -1
  33. package/dist/rag.cjs.map +1 -1
  34. package/dist/rag.d.cts +579 -579
  35. package/dist/rag.d.ts +579 -579
  36. package/dist/runner.cjs.map +1 -1
  37. package/dist/runner.d.cts +147 -147
  38. package/dist/runner.d.ts +147 -147
  39. package/dist/scheduler.cjs.map +1 -1
  40. package/dist/scheduler.d.cts +692 -692
  41. package/dist/scheduler.d.ts +692 -692
  42. package/dist/state-machine.cjs.map +1 -1
  43. package/dist/state-machine.d.cts +1128 -1128
  44. package/dist/state-machine.d.ts +1128 -1128
  45. package/dist/targets.cjs.map +1 -1
  46. package/dist/targets.d.cts +270 -270
  47. package/dist/targets.d.ts +270 -270
  48. package/dist/task-run.cjs.map +1 -1
  49. package/dist/task-run.d.cts +1431 -1431
  50. package/dist/task-run.d.ts +1431 -1431
  51. package/dist/tauri-events.cjs.map +1 -1
  52. package/dist/tauri-events.d.cts +310 -310
  53. package/dist/tauri-events.d.ts +310 -310
  54. package/dist/tree-events.cjs.map +1 -1
  55. package/dist/tree-events.d.cts +483 -483
  56. package/dist/tree-events.d.ts +483 -483
  57. package/dist/ui-bridge-ir.cjs +30 -33
  58. package/dist/ui-bridge-ir.cjs.map +1 -1
  59. package/dist/ui-bridge-ir.d.cts +98 -84
  60. package/dist/ui-bridge-ir.d.ts +98 -84
  61. package/dist/ui-bridge-ir.js +30 -33
  62. package/dist/ui-bridge-ir.js.map +1 -1
  63. package/dist/workflow.cjs.map +1 -1
  64. package/dist/workflow.d.cts +1634 -1634
  65. package/dist/workflow.d.ts +1634 -1634
  66. package/dist/workflow.js +1 -1
  67. package/package.json +141 -141
  68. package/src/accessibility/_api.ts +17 -17
  69. package/src/accessibility/index.ts +1 -1
  70. package/src/canvas/index.ts +319 -319
  71. package/src/chat/_api.ts +23 -23
  72. package/src/chat/index.ts +1 -1
  73. package/src/config/_api.ts +13 -13
  74. package/src/config/index.ts +1 -1
  75. package/src/constraints/_api.ts +17 -17
  76. package/src/constraints/index.ts +1 -1
  77. package/src/discovery.ts +188 -188
  78. package/src/execution/_api.ts +483 -483
  79. package/src/execution/index.ts +1 -1
  80. package/src/generated/A11yAction.d.ts +11 -11
  81. package/src/generated/AccessibilityBackend.d.ts +12 -12
  82. package/src/generated/AccessibilityBounds.d.ts +17 -17
  83. package/src/generated/AccessibilityNode.d.ts +73 -73
  84. package/src/generated/AccessibilityRole.d.ts +93 -93
  85. package/src/generated/AccessibilityRoleCriterion.d.ts +13 -13
  86. package/src/generated/AccessibilitySelector.d.ts +76 -76
  87. package/src/generated/AccessibilitySnapshot.d.ts +43 -43
  88. package/src/generated/AccessibilityState.d.ts +67 -67
  89. package/src/generated/ActionExecutionBatch.d.ts +23 -23
  90. package/src/generated/ActionExecutionBatchResponse.d.ts +24 -24
  91. package/src/generated/ActionExecutionCreate.d.ts +124 -124
  92. package/src/generated/ActionExecutionListResponse.d.ts +20 -20
  93. package/src/generated/ActionExecutionResponse.d.ts +24 -24
  94. package/src/generated/ActionReliabilityStats.d.ts +54 -54
  95. package/src/generated/ActionResponse.d.ts +45 -45
  96. package/src/generated/ActionStatus.d.ts +11 -11
  97. package/src/generated/ActionType.d.ts +41 -41
  98. package/src/generated/ActiveStatesResult.d.ts +32 -32
  99. package/src/generated/AgenticPhaseOutput.d.ts +50 -50
  100. package/src/generated/AgenticStatus.d.ts +11 -11
  101. package/src/generated/AiWorkflow.d.ts +76 -76
  102. package/src/generated/ApiAssertion.d.ts +35 -35
  103. package/src/generated/ApiAssertionOperator.d.ts +11 -11
  104. package/src/generated/ApiAssertionType.d.ts +11 -11
  105. package/src/generated/ApiContentType.d.ts +11 -11
  106. package/src/generated/ApiVariableExtraction.d.ts +24 -24
  107. package/src/generated/AssertionMiss.d.ts +22 -0
  108. package/src/generated/AssertionOutcome.d.ts +30 -0
  109. package/src/generated/AssertionResult.d.ts +38 -0
  110. package/src/generated/AssertionScope.d.ts +37 -0
  111. package/src/generated/AssertionSeverityCounts.d.ts +28 -0
  112. package/src/generated/AvailableTransitionsResult.d.ts +34 -34
  113. package/src/generated/BaseStepFields.d.ts +72 -72
  114. package/src/generated/BatchComputeEmbeddingRequest.d.ts +27 -27
  115. package/src/generated/BatchComputeEmbeddingResponse.d.ts +23 -23
  116. package/src/generated/BatchEmbeddingResult.d.ts +23 -23
  117. package/src/generated/BetweenIterations.d.ts +35 -35
  118. package/src/generated/BoundingBox.d.ts +18 -18
  119. package/src/generated/BridgeFingerprint.d.ts +40 -0
  120. package/src/generated/BuildPhaseConfig.d.ts +24 -24
  121. package/src/generated/BuiltinOverrideProposal.d.ts +27 -27
  122. package/src/generated/CandidateMiss.d.ts +39 -0
  123. package/src/generated/CanonicalStep.d.ts +60 -60
  124. package/src/generated/CatchUpPolicy.d.ts +12 -12
  125. package/src/generated/Category.d.ts +24 -24
  126. package/src/generated/CheckIssueDetail.d.ts +40 -40
  127. package/src/generated/CheckType.d.ts +21 -21
  128. package/src/generated/CodeExecutionStep.d.ts +88 -88
  129. package/src/generated/CommandMode.d.ts +11 -11
  130. package/src/generated/CommandStep.d.ts +183 -183
  131. package/src/generated/CommandStepPhase.d.ts +11 -11
  132. package/src/generated/ComponentActionInfo.d.ts +24 -24
  133. package/src/generated/ComponentActionRequest.d.ts +22 -22
  134. package/src/generated/ComputeEmbeddingRequest.d.ts +24 -24
  135. package/src/generated/ComputeEmbeddingResponse.d.ts +38 -38
  136. package/src/generated/ComputeTextEmbeddingRequest.d.ts +20 -20
  137. package/src/generated/ComputeTextEmbeddingResponse.d.ts +32 -32
  138. package/src/generated/ConditionScheduleConfig.d.ts +17 -17
  139. package/src/generated/ConditionStatus.d.ts +29 -29
  140. package/src/generated/Confidence.d.ts +11 -11
  141. package/src/generated/ConfidenceLevel.d.ts +11 -11
  142. package/src/generated/ConjunctEvaluation.d.ts +24 -0
  143. package/src/generated/ConjunctRule.d.ts +55 -0
  144. package/src/generated/Constraint.d.ts +33 -33
  145. package/src/generated/ConstraintCheck.d.ts +64 -64
  146. package/src/generated/ConstraintProposal.d.ts +37 -37
  147. package/src/generated/ConstraintResult.d.ts +32 -32
  148. package/src/generated/ConstraintSeverity.d.ts +16 -16
  149. package/src/generated/ConstraintViolation.d.ts +24 -24
  150. package/src/generated/Context.d.ts +50 -50
  151. package/src/generated/ContextAutoInclude.d.ts +34 -34
  152. package/src/generated/CoordinateSystem.d.ts +12 -12
  153. package/src/generated/Coordinates.d.ts +33 -33
  154. package/src/generated/CostTrendDataPoint.d.ts +36 -36
  155. package/src/generated/CostTrendResponse.d.ts +41 -41
  156. package/src/generated/CoverageData.d.ts +52 -52
  157. package/src/generated/CreateMcpCallInput.d.ts +59 -59
  158. package/src/generated/CreateMcpServerInput.d.ts +48 -48
  159. package/src/generated/CreateOlConfigRequest.d.ts +27 -27
  160. package/src/generated/CreateScheduledTaskRequest.d.ts +63 -63
  161. package/src/generated/CreateTaskRunRequest.d.ts +51 -51
  162. package/src/generated/CriterionOverride.d.ts +39 -39
  163. package/src/generated/CriterionType.d.ts +11 -11
  164. package/src/generated/DagApprovalStep.d.ts +80 -80
  165. package/src/generated/DagCancelStep.d.ts +76 -76
  166. package/src/generated/DagLoopStep.d.ts +80 -80
  167. package/src/generated/DecomposerConfig.d.ts +31 -31
  168. package/src/generated/DiagnosePhaseConfig.d.ts +34 -34
  169. package/src/generated/DiagnosticResult.d.ts +40 -40
  170. package/src/generated/DiscoveredElement.d.ts +48 -48
  171. package/src/generated/DiscoveredState.d.ts +49 -49
  172. package/src/generated/DiscoveredStateImage.d.ts +56 -56
  173. package/src/generated/DiscoveredTransition.d.ts +44 -44
  174. package/src/generated/DiscoveryBoundingBox.d.ts +32 -32
  175. package/src/generated/DiscoveryRequest.d.ts +40 -40
  176. package/src/generated/DiscoveryResponse.d.ts +32 -32
  177. package/src/generated/DiscoverySourceType.d.ts +14 -14
  178. package/src/generated/DiscoveryStrategy.d.ts +13 -13
  179. package/src/generated/DiscoveryTransitionTrigger.d.ts +38 -38
  180. package/src/generated/DisplayNode.d.ts +45 -45
  181. package/src/generated/DomainAssignment.d.ts +50 -50
  182. package/src/generated/DomainKnowledge.d.ts +29 -29
  183. package/src/generated/DomainVerificationResult.d.ts +36 -36
  184. package/src/generated/ElementActionRequest.d.ts +28 -28
  185. package/src/generated/ElementBbox.d.ts +36 -36
  186. package/src/generated/ElementIdentifier.d.ts +40 -40
  187. package/src/generated/ElementRect.d.ts +48 -48
  188. package/src/generated/ElementState.d.ts +47 -47
  189. package/src/generated/ElementType.d.ts +45 -45
  190. package/src/generated/EmbeddedElement.d.ts +36 -36
  191. package/src/generated/EmbeddingItem.d.ts +49 -49
  192. package/src/generated/EmbeddingListResponse.d.ts +22 -22
  193. package/src/generated/EmbeddingResultItem.d.ts +29 -29
  194. package/src/generated/EmbeddingResultsRequest.d.ts +19 -19
  195. package/src/generated/EmbeddingResultsResponse.d.ts +17 -17
  196. package/src/generated/ErrorType.d.ts +18 -18
  197. package/src/generated/ExecutePlaybookStep.d.ts +84 -84
  198. package/src/generated/ExecutionActionType.d.ts +40 -40
  199. package/src/generated/ExecutionIssueBatch.d.ts +19 -19
  200. package/src/generated/ExecutionIssueBatchResponse.d.ts +24 -24
  201. package/src/generated/ExecutionIssueCreate.d.ts +57 -57
  202. package/src/generated/ExecutionIssueDetail.d.ts +89 -89
  203. package/src/generated/ExecutionIssueListResponse.d.ts +26 -26
  204. package/src/generated/ExecutionIssueResponse.d.ts +24 -24
  205. package/src/generated/ExecutionIssueUpdate.d.ts +31 -31
  206. package/src/generated/ExecutionMatchLocation.d.ts +31 -31
  207. package/src/generated/ExecutionRunComplete.d.ts +34 -34
  208. package/src/generated/ExecutionRunCompleteResponse.d.ts +38 -38
  209. package/src/generated/ExecutionRunCreate.d.ts +40 -40
  210. package/src/generated/ExecutionRunDetail.d.ts +76 -76
  211. package/src/generated/ExecutionRunListResponse.d.ts +22 -22
  212. package/src/generated/ExecutionRunResponse.d.ts +41 -41
  213. package/src/generated/ExecutionScreenshotCreate.d.ts +59 -59
  214. package/src/generated/ExecutionScreenshotResponse.d.ts +36 -36
  215. package/src/generated/ExecutionStats.d.ts +56 -56
  216. package/src/generated/ExecutionStep.d.ts +78 -78
  217. package/src/generated/ExecutionTreeResponse.d.ts +42 -42
  218. package/src/generated/ExecutionTrendDataPoint.d.ts +36 -36
  219. package/src/generated/ExecutionTrendResponse.d.ts +46 -46
  220. package/src/generated/ExitCheckResult.d.ts +20 -20
  221. package/src/generated/ExitStrategy.d.ts +27 -27
  222. package/src/generated/ExportResult.d.ts +30 -30
  223. package/src/generated/ExtendIterationsRequest.d.ts +20 -20
  224. package/src/generated/FieldDiff.d.ts +33 -0
  225. package/src/generated/FileChange.d.ts +20 -20
  226. package/src/generated/Finding.d.ts +40 -40
  227. package/src/generated/FindingActionType.d.ts +13 -13
  228. package/src/generated/FindingBatchCreate.d.ts +27 -27
  229. package/src/generated/FindingCategory.d.ts +25 -25
  230. package/src/generated/FindingCodeContext.d.ts +31 -31
  231. package/src/generated/FindingCreate.d.ts +52 -52
  232. package/src/generated/FindingDetail.d.ts +78 -78
  233. package/src/generated/FindingListResponse.d.ts +40 -40
  234. package/src/generated/FindingOutput.d.ts +36 -36
  235. package/src/generated/FindingSeverity.d.ts +14 -14
  236. package/src/generated/FindingStatus.d.ts +15 -15
  237. package/src/generated/FindingSummary.d.ts +53 -53
  238. package/src/generated/FindingUpdate.d.ts +33 -33
  239. package/src/generated/FindingUserInput.d.ts +27 -27
  240. package/src/generated/FindingsSummary.d.ts +47 -47
  241. package/src/generated/FullRunnerStep.d.ts +144 -144
  242. package/src/generated/GUIElementChunk.d.ts +151 -151
  243. package/src/generated/GateEvaluationResult.d.ts +36 -36
  244. package/src/generated/HealthCheckUrl.d.ts +35 -35
  245. package/src/generated/HistoricalActionQuery.d.ts +42 -42
  246. package/src/generated/HistoricalActionResult.d.ts +57 -57
  247. package/src/generated/HttpConfig.d.ts +27 -27
  248. package/src/generated/HttpMethod.d.ts +13 -13
  249. package/src/generated/IdleCondition.d.ts +17 -17
  250. package/src/generated/ImplementFixesConfig.d.ts +25 -25
  251. package/src/generated/IndividualCheckResult.d.ts +50 -50
  252. package/src/generated/InitialStateRef.d.ts +23 -23
  253. package/src/generated/InitialStatesSource.d.ts +18 -18
  254. package/src/generated/IrAssertion.d.ts +26 -0
  255. package/src/generated/IrAssertionTarget.d.ts +28 -0
  256. package/src/generated/IrCrossRef.d.ts +16 -0
  257. package/src/generated/IrElementCriteria.d.ts +29 -0
  258. package/src/generated/IrGroup.d.ts +33 -0
  259. package/src/generated/IrMetadata.d.ts +15 -0
  260. package/src/generated/IrPageSpec.d.ts +51 -0
  261. package/src/generated/IrProvenance.d.ts +28 -0
  262. package/src/generated/IrState.d.ts +36 -0
  263. package/src/generated/IrStateCondition.d.ts +19 -0
  264. package/src/generated/IrTransition.d.ts +34 -0
  265. package/src/generated/IrTransitionAction.d.ts +17 -0
  266. package/src/generated/IrWaitSpec.d.ts +22 -0
  267. package/src/generated/IssueSeverity.d.ts +11 -11
  268. package/src/generated/IssueSource.d.ts +11 -11
  269. package/src/generated/IssueStatus.d.ts +11 -11
  270. package/src/generated/IssueType.d.ts +21 -21
  271. package/src/generated/IterationResult.d.ts +65 -65
  272. package/src/generated/IterationVerificationResults.d.ts +53 -53
  273. package/src/generated/JobItem.d.ts +31 -31
  274. package/src/generated/JobListResponse.d.ts +20 -20
  275. package/src/generated/JobStatus.d.ts +11 -11
  276. package/src/generated/JobSummary.d.ts +30 -30
  277. package/src/generated/LLMCostSummary.d.ts +38 -38
  278. package/src/generated/LLMMetrics.d.ts +42 -42
  279. package/src/generated/LegacyAssertion.d.ts +22 -0
  280. package/src/generated/LegacyAssertionTarget.d.ts +23 -0
  281. package/src/generated/LegacyGroup.d.ts +19 -0
  282. package/src/generated/LegacyProcessStep.d.ts +16 -0
  283. package/src/generated/LegacySpec.d.ts +30 -0
  284. package/src/generated/LegacyStateMachine.d.ts +17 -0
  285. package/src/generated/LegacyStateMachineState.d.ts +21 -0
  286. package/src/generated/LegacyTransition.d.ts +20 -0
  287. package/src/generated/LogSourceSelection.d.ts +25 -25
  288. package/src/generated/LoopInstanceStatus.d.ts +28 -28
  289. package/src/generated/LoopPhase.d.ts +26 -26
  290. package/src/generated/MatchAdjustment.d.ts +23 -23
  291. package/src/generated/MatchLocation.d.ts +22 -22
  292. package/src/generated/MatchMethod.d.ts +11 -11
  293. package/src/generated/MatchOutcome.d.ts +11 -0
  294. package/src/generated/MatchedElement.d.ts +28 -0
  295. package/src/generated/McpCallRecord.d.ts +35 -35
  296. package/src/generated/McpCallsResult.d.ts +44 -44
  297. package/src/generated/McpConnectionRef.d.ts +25 -25
  298. package/src/generated/McpServerConfig.d.ts +77 -77
  299. package/src/generated/McpServerStatus.d.ts +42 -42
  300. package/src/generated/McpToolCallResult.d.ts +38 -38
  301. package/src/generated/McpToolInfo.d.ts +23 -23
  302. package/src/generated/McpToolInputSchema.d.ts +34 -34
  303. package/src/generated/McpTransport.d.ts +15 -15
  304. package/src/generated/MissReason.d.ts +20 -0
  305. package/src/generated/ModelCostBreakdown.d.ts +36 -36
  306. package/src/generated/ModelOverrideConfig.d.ts +47 -47
  307. package/src/generated/Monitor.d.ts +48 -48
  308. package/src/generated/MonitorPosition.d.ts +13 -13
  309. package/src/generated/MouseButton.d.ts +13 -13
  310. package/src/generated/MultiLoopConfig.d.ts +32 -32
  311. package/src/generated/MultiLoopEntry.d.ts +32 -32
  312. package/src/generated/MultiLoopStatus.d.ts +37 -37
  313. package/src/generated/NativeAccessibilityStep.d.ts +121 -121
  314. package/src/generated/NavigationResult.d.ts +40 -40
  315. package/src/generated/NewConstraintProposal.d.ts +20 -20
  316. package/src/generated/NextTaskInfo.d.ts +24 -24
  317. package/src/generated/NodeMetadata.d.ts +47 -47
  318. package/src/generated/NodeStatus.d.ts +11 -11
  319. package/src/generated/NodeType.d.ts +11 -11
  320. package/src/generated/OcrEngine.d.ts +11 -11
  321. package/src/generated/OlConfig.d.ts +48 -48
  322. package/src/generated/OrchestrationLoopConfig.d.ts +87 -87
  323. package/src/generated/OrchestrationLoopStatus.d.ts +59 -59
  324. package/src/generated/Outcome.d.ts +15 -15
  325. package/src/generated/OutputLine.d.ts +23 -23
  326. package/src/generated/OutputStream.d.ts +11 -11
  327. package/src/generated/OverrideCollection.d.ts +18 -18
  328. package/src/generated/Pagination.d.ts +28 -28
  329. package/src/generated/ParserType.d.ts +17 -17
  330. package/src/generated/PathElement.d.ts +17 -17
  331. package/src/generated/PathfindingRequest.d.ts +24 -24
  332. package/src/generated/PathfindingResult.d.ts +30 -30
  333. package/src/generated/PathfindingStep.d.ts +36 -36
  334. package/src/generated/PatternOptions.d.ts +32 -32
  335. package/src/generated/PipelineConfig.d.ts +31 -31
  336. package/src/generated/PlaybackFrameRequest.d.ts +21 -21
  337. package/src/generated/PlaywrightExecutionMode.d.ts +11 -11
  338. package/src/generated/Point.d.ts +20 -20
  339. package/src/generated/PolicyConjunct.d.ts +22 -0
  340. package/src/generated/PolicyEvaluation.d.ts +22 -0
  341. package/src/generated/PolicyStatus.d.ts +11 -0
  342. package/src/generated/PollingConfig.d.ts +14 -14
  343. package/src/generated/ProcessConfig.d.ts +96 -96
  344. package/src/generated/ProcessState.d.ts +15 -15
  345. package/src/generated/ProcessStatus.d.ts +41 -41
  346. package/src/generated/PromptStep.d.ts +92 -92
  347. package/src/generated/PromptStepPhase.d.ts +13 -13
  348. package/src/generated/ProposalStatus.d.ts +13 -0
  349. package/src/generated/RAGDashboardStats.d.ts +26 -26
  350. package/src/generated/RagCompletionEvent.d.ts +25 -25
  351. package/src/generated/RagProcessingStatus.d.ts +11 -11
  352. package/src/generated/RagProgressEvent.d.ts +27 -27
  353. package/src/generated/ReadConfigResponse.d.ts +20 -20
  354. package/src/generated/RecommendedState.d.ts +23 -0
  355. package/src/generated/ReflectionFixOutput.d.ts +20 -20
  356. package/src/generated/Region.d.ts +39 -39
  357. package/src/generated/RepositoryInactiveCondition.d.ts +24 -24
  358. package/src/generated/RepositoryWatch.d.ts +20 -20
  359. package/src/generated/ResolvedInitialStates.d.ts +29 -29
  360. package/src/generated/ResolvedInitialStatesResult.d.ts +40 -40
  361. package/src/generated/ResourceLimits.d.ts +33 -33
  362. package/src/generated/RestartProcessStep.d.ts +88 -88
  363. package/src/generated/RetryPolicy.d.ts +24 -24
  364. package/src/generated/RetrySpec.d.ts +24 -24
  365. package/src/generated/RoleCriterion.d.ts +14 -14
  366. package/src/generated/RootCauseCategory.d.ts +18 -18
  367. package/src/generated/RoutingRule.d.ts +38 -38
  368. package/src/generated/RunPromptRequest.d.ts +56 -56
  369. package/src/generated/RunPromptResponse.d.ts +50 -50
  370. package/src/generated/RunPromptResponseData.d.ts +20 -20
  371. package/src/generated/RunStatus.d.ts +11 -11
  372. package/src/generated/RunType.d.ts +11 -11
  373. package/src/generated/Runner.d.ts +81 -81
  374. package/src/generated/RunnerCrash.d.ts +32 -32
  375. package/src/generated/RunnerFinding.d.ts +48 -48
  376. package/src/generated/RunnerFindingCodeContext.d.ts +20 -20
  377. package/src/generated/RunnerFindingUserInput.d.ts +19 -19
  378. package/src/generated/RunnerMetadata.d.ts +42 -42
  379. package/src/generated/RunnerStatus.d.ts +12 -12
  380. package/src/generated/RunnerUiError.d.ts +28 -28
  381. package/src/generated/RuntimeData.d.ts +40 -40
  382. package/src/generated/SaveWorkflowArtifactStep.d.ts +80 -80
  383. package/src/generated/ScheduleConditions.d.ts +29 -29
  384. package/src/generated/ScheduleExpression.d.ts +39 -39
  385. package/src/generated/ScheduledTask.d.ts +104 -104
  386. package/src/generated/ScheduledTaskStatus.d.ts +19 -19
  387. package/src/generated/ScheduledTaskType.d.ts +126 -126
  388. package/src/generated/SchedulerSettings.d.ts +28 -28
  389. package/src/generated/SchedulerStatus.d.ts +31 -31
  390. package/src/generated/ScreenshotAnnotation.d.ts +39 -39
  391. package/src/generated/ScreenshotAnnotationShape.d.ts +11 -11
  392. package/src/generated/ScreenshotType.d.ts +11 -11
  393. package/src/generated/ScrollDirection.d.ts +13 -13
  394. package/src/generated/SearchOptions.d.ts +33 -33
  395. package/src/generated/SearchResultItem.d.ts +19 -19
  396. package/src/generated/SearchStrategy.d.ts +14 -14
  397. package/src/generated/SemanticSearchRequest.d.ts +26 -26
  398. package/src/generated/SemanticSearchResponse.d.ts +21 -21
  399. package/src/generated/SpecCheckConfidence.d.ts +15 -0
  400. package/src/generated/SpecCheckPolicy.d.ts +23 -0
  401. package/src/generated/SpecCheckResult.d.ts +66 -0
  402. package/src/generated/SpecCheckStepConfig.d.ts +38 -0
  403. package/src/generated/SpecCheckSummary.d.ts +28 -0
  404. package/src/generated/SpecValidation.d.ts +27 -0
  405. package/src/generated/StageCondition.d.ts +37 -37
  406. package/src/generated/StageInput.d.ts +27 -27
  407. package/src/generated/StageOutput.d.ts +20 -20
  408. package/src/generated/StageTransition.d.ts +30 -30
  409. package/src/generated/StallDetectorConfig.d.ts +31 -31
  410. package/src/generated/StandardActionType.d.ts +40 -40
  411. package/src/generated/StateContext.d.ts +17 -17
  412. package/src/generated/StateDiscoveryResult.d.ts +104 -104
  413. package/src/generated/StateDiscoveryResultCreate.d.ts +65 -65
  414. package/src/generated/StateDiscoveryResultListResponse.d.ts +23 -23
  415. package/src/generated/StateDiscoveryResultSummary.d.ts +57 -57
  416. package/src/generated/StateDiscoveryResultUpdate.d.ts +47 -47
  417. package/src/generated/StateFilterItem.d.ts +18 -18
  418. package/src/generated/StateMachineConfig.d.ts +45 -45
  419. package/src/generated/StateMachineConfigCreate.d.ts +20 -20
  420. package/src/generated/StateMachineConfigFull.d.ts +67 -67
  421. package/src/generated/StateMachineConfigUpdate.d.ts +20 -20
  422. package/src/generated/StateMachineExport.d.ts +64 -64
  423. package/src/generated/StateMachineExportFormat.d.ts +39 -39
  424. package/src/generated/StateMachineImport.d.ts +25 -25
  425. package/src/generated/StateMachineState.d.ts +71 -71
  426. package/src/generated/StateMachineStateCreate.d.ts +52 -52
  427. package/src/generated/StateMachineStateUpdate.d.ts +48 -48
  428. package/src/generated/StateMachineTransition.d.ts +75 -75
  429. package/src/generated/StateMachineTransitionCreate.d.ts +53 -53
  430. package/src/generated/StateMachineTransitionUpdate.d.ts +53 -53
  431. package/src/generated/StateMatchResult.d.ts +36 -0
  432. package/src/generated/StateNodeData.d.ts +71 -71
  433. package/src/generated/StatesResponse.d.ts +19 -19
  434. package/src/generated/StdioConfig.d.ts +34 -34
  435. package/src/generated/StepExecutionConfig.d.ts +37 -37
  436. package/src/generated/StructuredFinding.d.ts +32 -32
  437. package/src/generated/StructuredOverride.d.ts +24 -24
  438. package/src/generated/StructuredSignal.d.ts +20 -20
  439. package/src/generated/SuccessCriterion.d.ts +57 -57
  440. package/src/generated/SummarizationConfig.d.ts +35 -35
  441. package/src/generated/TargetConfig.d.ts +108 -108
  442. package/src/generated/TaskCompletionResult.d.ts +90 -90
  443. package/src/generated/TaskExecutionRecord.d.ts +61 -61
  444. package/src/generated/TaskRun.d.ts +88 -88
  445. package/src/generated/TaskRunBackend.d.ts +86 -86
  446. package/src/generated/TaskRunBackendDetail.d.ts +99 -99
  447. package/src/generated/TaskRunCreate.d.ts +62 -62
  448. package/src/generated/TaskRunFilters.d.ts +38 -38
  449. package/src/generated/TaskRunFinding.d.ts +100 -100
  450. package/src/generated/TaskRunFindingActionType.d.ts +11 -11
  451. package/src/generated/TaskRunFindingCategory.d.ts +24 -24
  452. package/src/generated/TaskRunFindingCreate.d.ts +79 -79
  453. package/src/generated/TaskRunFindingFilters.d.ts +28 -28
  454. package/src/generated/TaskRunFindingSeverity.d.ts +11 -11
  455. package/src/generated/TaskRunFindingStatus.d.ts +11 -11
  456. package/src/generated/TaskRunFindingSummary.d.ts +34 -34
  457. package/src/generated/TaskRunFindingUpdate.d.ts +34 -34
  458. package/src/generated/TaskRunFindingsListResponse.d.ts +24 -24
  459. package/src/generated/TaskRunListResponse.d.ts +21 -21
  460. package/src/generated/TaskRunSession.d.ts +40 -40
  461. package/src/generated/TaskRunStatus.d.ts +11 -11
  462. package/src/generated/TaskRunUpdate.d.ts +47 -47
  463. package/src/generated/TaskType.d.ts +11 -11
  464. package/src/generated/TerminalExitEvent.d.ts +26 -26
  465. package/src/generated/TerminalInfo.d.ts +69 -69
  466. package/src/generated/TerminalOutputEvent.d.ts +29 -29
  467. package/src/generated/TestType.d.ts +11 -11
  468. package/src/generated/TextMatchType.d.ts +11 -11
  469. package/src/generated/TextSearchOptions.d.ts +30 -30
  470. package/src/generated/Ticket.d.ts +53 -53
  471. package/src/generated/TicketComment.d.ts +28 -28
  472. package/src/generated/TicketProviderConfig.d.ts +55 -55
  473. package/src/generated/TicketSource.d.ts +17 -17
  474. package/src/generated/TicketState.d.ts +15 -15
  475. package/src/generated/TimingInfo.d.ts +23 -23
  476. package/src/generated/TopMatch.d.ts +17 -17
  477. package/src/generated/TransitionAction.d.ts +93 -93
  478. package/src/generated/TransitionActionValue.d.ts +14 -14
  479. package/src/generated/TransitionEdgeData.d.ts +46 -46
  480. package/src/generated/TransitionExecutionResult.d.ts +30 -30
  481. package/src/generated/TransitionInfo.d.ts +29 -29
  482. package/src/generated/TransitionTriggerType.d.ts +13 -13
  483. package/src/generated/TreeEvent.d.ts +47 -47
  484. package/src/generated/TreeEventCreate.d.ts +30 -30
  485. package/src/generated/TreeEventListResponse.d.ts +30 -30
  486. package/src/generated/TreeEventResponse.d.ts +47 -47
  487. package/src/generated/TreeEventType.d.ts +20 -20
  488. package/src/generated/TreeNode.d.ts +54 -54
  489. package/src/generated/UIBridgeCapturedToast.d.ts +22 -22
  490. package/src/generated/UIBridgeComponent.d.ts +45 -45
  491. package/src/generated/UIBridgeElement.d.ts +90 -62
  492. package/src/generated/UIBridgeModalInfo.d.ts +40 -40
  493. package/src/generated/UIBridgeModalStack.d.ts +19 -19
  494. package/src/generated/UIBridgeSnapshot.d.ts +67 -67
  495. package/src/generated/UIBridgeToastContext.d.ts +17 -17
  496. package/src/generated/UIBridgeUndoContext.d.ts +19 -19
  497. package/src/generated/UiBridgeAction.d.ts +18 -18
  498. package/src/generated/UiBridgeAssertType.d.ts +11 -11
  499. package/src/generated/UiBridgeComparisonMode.d.ts +11 -11
  500. package/src/generated/UiBridgeDesignAuditStep.d.ts +76 -76
  501. package/src/generated/UiBridgeRequestEnvelope.d.ts +45 -45
  502. package/src/generated/UiBridgeResponseEnvelope.d.ts +66 -66
  503. package/src/generated/UiBridgeSeverity.d.ts +11 -11
  504. package/src/generated/UiBridgeStep.d.ts +127 -127
  505. package/src/generated/UiBridgeStepPhase.d.ts +14 -14
  506. package/src/generated/UiBridgeVisualAssertionStep.d.ts +97 -97
  507. package/src/generated/UnifiedStep.d.ts +57 -57
  508. package/src/generated/UnifiedWorkflow.d.ts +411 -411
  509. package/src/generated/UpdateMcpServerInput.d.ts +28 -28
  510. package/src/generated/UpdateOlConfigRequest.d.ts +32 -32
  511. package/src/generated/UpdateScheduledTaskRequest.d.ts +71 -71
  512. package/src/generated/ValidateConfigRequest.d.ts +16 -16
  513. package/src/generated/ValidateConfigResponse.d.ts +28 -28
  514. package/src/generated/VectorSearchResult.d.ts +48 -48
  515. package/src/generated/VerificationAgentContext.d.ts +25 -25
  516. package/src/generated/VerificationCategoryKind.d.ts +19 -19
  517. package/src/generated/VerificationMethod.d.ts +20 -20
  518. package/src/generated/VerificationPhaseResult.d.ts +63 -63
  519. package/src/generated/VerificationPlan.d.ts +43 -43
  520. package/src/generated/VerificationResult.d.ts +44 -44
  521. package/src/generated/VerificationResultResponse.d.ts +65 -65
  522. package/src/generated/VerificationResultsListResponse.d.ts +41 -41
  523. package/src/generated/VerificationStepDetails.d.ts +55 -55
  524. package/src/generated/VerificationStepResult.d.ts +68 -68
  525. package/src/generated/VgaAction.d.ts +61 -61
  526. package/src/generated/VgaActionKind.d.ts +14 -14
  527. package/src/generated/VgaAutomateStep.d.ts +110 -110
  528. package/src/generated/VirtualDesktop.d.ts +23 -23
  529. package/src/generated/VisualAssertionType.d.ts +11 -11
  530. package/src/generated/VisualComparisonResult.d.ts +40 -40
  531. package/src/generated/WaitOptions.d.ts +35 -35
  532. package/src/generated/WorkerCoordinationMessage.d.ts +93 -93
  533. package/src/generated/WorkerDomain.d.ts +29 -29
  534. package/src/generated/WorkerInstance.d.ts +62 -62
  535. package/src/generated/WorkerOutput.d.ts +53 -53
  536. package/src/generated/WorkerSignal.d.ts +48 -48
  537. package/src/generated/WorkerStatus.d.ts +11 -11
  538. package/src/generated/WorkflowArchitecture.d.ts +16 -16
  539. package/src/generated/WorkflowFixupMode.d.ts +11 -11
  540. package/src/generated/WorkflowFixupStep.d.ts +85 -85
  541. package/src/generated/WorkflowInfo.d.ts +28 -28
  542. package/src/generated/WorkflowMetadata.d.ts +44 -44
  543. package/src/generated/WorkflowRefStep.d.ts +94 -94
  544. package/src/generated/WorkflowStage.d.ts +126 -126
  545. package/src/generated/WorkflowStep.d.ts +80 -80
  546. package/src/generated/WorkflowStepPhase.d.ts +11 -11
  547. package/src/generated/WriteConfigRequest.d.ts +20 -20
  548. package/src/generated/WriteConfigResponse.d.ts +24 -24
  549. package/src/generated/index.ts +478 -432
  550. package/src/geometry/_api.ts +16 -16
  551. package/src/geometry/index.ts +1 -1
  552. package/src/index.ts +78 -73
  553. package/src/known-issues/index.ts +179 -179
  554. package/src/library/_api.ts +326 -326
  555. package/src/library/index.ts +1 -1
  556. package/src/rag/_api.ts +47 -47
  557. package/src/rag/index.ts +1 -1
  558. package/src/render-log.ts +371 -371
  559. package/src/runner/_api.ts +14 -14
  560. package/src/runner/index.ts +1 -1
  561. package/src/scheduler/_api.ts +21 -21
  562. package/src/scheduler/index.ts +1 -1
  563. package/src/state-machine/_api.ts +145 -145
  564. package/src/state-machine/index.ts +1 -1
  565. package/src/targets/_api.ts +47 -47
  566. package/src/targets/index.ts +1 -1
  567. package/src/task-run/_api.ts +108 -108
  568. package/src/task-run/index.ts +1 -1
  569. package/src/tauri-events/_api.ts +90 -90
  570. package/src/tauri-events/index.ts +1 -1
  571. package/src/tree-events/_api.ts +42 -42
  572. package/src/tree-events/index.ts +1 -1
  573. package/src/ui-bridge-ir/__tests__/projection.test.ts +1121 -1029
  574. package/src/ui-bridge-ir/adapter.ts +226 -220
  575. package/src/ui-bridge-ir/document.ts +114 -114
  576. package/src/ui-bridge-ir/element-criteria.ts +48 -48
  577. package/src/ui-bridge-ir/group.ts +84 -84
  578. package/src/ui-bridge-ir/index.ts +24 -24
  579. package/src/ui-bridge-ir/ir.schema.json +297 -293
  580. package/src/ui-bridge-ir/primitives.ts +110 -102
  581. package/src/ui-bridge-ir/projection.ts +898 -921
  582. package/src/ui-bridge-ir/state.ts +97 -90
  583. package/src/ui-bridge-ir/transition.ts +92 -92
  584. package/src/workflow/_api.ts +474 -474
  585. package/src/workflow/action-plan.ts +208 -208
  586. package/src/workflow/index.ts +1 -1
  587. package/src/workflow/skill.ts +152 -152
  588. package/dist/chunk-YXD4WCYQ.js.map +0 -1
  589. package/dist/chunk-ZK5MJEGT.js.map +0 -1
@@ -22,6 +22,14 @@ interface IRProvenance {
22
22
  column?: number;
23
23
  /** Build-plugin version that produced this node, if applicable. */
24
24
  pluginVersion?: string;
25
+ /**
26
+ * Lifecycle status for the Stream E coverage-growth flywheel. Absent =
27
+ * implicitly `"promoted"` (legacy + on-disk specs that predate the field).
28
+ * Set to `"proposed"` by `spec_authoring`, `"pending"` when staged in
29
+ * `_pending/`, `"promoted"` after the 2-green sweep moves the file to
30
+ * `pages/<id>/`.
31
+ */
32
+ status?: "proposed" | "pending" | "promoted";
25
33
  }
26
34
  /**
27
35
  * Human-authored semantic context for an IR node. Aligns with the existing
@@ -129,6 +137,88 @@ interface IRElementCriteria {
129
137
  attributes?: Record<string, string>;
130
138
  }
131
139
 
140
+ /**
141
+ * IR-side group + assertion types.
142
+ *
143
+ * The IR's primary authoring surface is `states + transitions`, which the
144
+ * projection maps into legacy `groups[]` (one group per state). However, the
145
+ * runner's `workflow_generation::spec_synthesis` pipeline produces "free-form"
146
+ * groups from acceptance criteria — these are NOT tied to any state and
147
+ * therefore have no home in the state-derived projection path.
148
+ *
149
+ * `IRGroup` is the dedicated channel for those synthesized groups. The IR
150
+ * carries them in the optional `IRDocument.synthesizedGroups` field; the
151
+ * projection appends them after the state-derived groups, in declared order,
152
+ * to preserve byte-stable output.
153
+ *
154
+ * The shape mirrors the legacy `SpecGroup` / `SpecAssertion` (canonical
155
+ * definitions live in `@qontinui/ui-bridge/specs`), but is re-defined here to
156
+ * keep `qontinui-schemas/ts` free of any runtime dep on `@qontinui/ui-bridge/*`
157
+ * (per the schemas package's "zero ui-bridge deps" policy).
158
+ *
159
+ * Note on field shape: the IR-side `IRAssertion` keeps the legacy assertion's
160
+ * field types as loose as the synthesis path emits them. Strict consumers
161
+ * (e.g. the canonical `SpecAssertion` in `@qontinui/ui-bridge/specs`) can
162
+ * narrow as needed at the consumer boundary; the projection preserves the
163
+ * objects verbatim into the legacy output.
164
+ */
165
+ /**
166
+ * IR-side assertion target. Always `type: "search"` for synthesis-emitted
167
+ * assertions; the wider legacy schema also supports point/region targets but
168
+ * the IR doesn't express those today.
169
+ */
170
+ interface IRAssertionTarget {
171
+ /** Always `"search"` for synthesis-emitted assertions. */
172
+ type: string;
173
+ /**
174
+ * Free-form criteria object. Kept as a loose record so synthesis can emit
175
+ * partially-populated criteria without tripping the schema.
176
+ */
177
+ criteria: Record<string, unknown>;
178
+ label: string;
179
+ }
180
+ /**
181
+ * IR-side assertion. Mirrors the legacy `SpecAssertion` shape.
182
+ */
183
+ interface IRAssertion {
184
+ id: string;
185
+ description: string;
186
+ category: string;
187
+ severity: string;
188
+ assertionType: string;
189
+ target: IRAssertionTarget;
190
+ source: string;
191
+ reviewed: boolean;
192
+ enabled: boolean;
193
+ /**
194
+ * Optional human-readable precondition. Synthesis populates this from the
195
+ * acceptance criterion's verification hint.
196
+ */
197
+ precondition?: string;
198
+ }
199
+ /**
200
+ * IR-side group produced by workflow-criteria synthesis (i.e. NOT derived
201
+ * from `IRState` annotations). Mirrors the legacy `SpecGroup` shape one-to-one
202
+ * so the projection can pass it through to legacy `groups[]` without loss.
203
+ */
204
+ interface IRGroup {
205
+ id: string;
206
+ name: string;
207
+ description: string;
208
+ category: string;
209
+ assertions: IRAssertion[];
210
+ /**
211
+ * Provenance of the group itself (typically `"ai-generated"` for synthesis
212
+ * output, but kept open for future authoring channels).
213
+ */
214
+ source?: string;
215
+ /**
216
+ * Free-form tags. Synthesis emits e.g. `["workflow-generated",
217
+ * "acceptance-criteria"]` so downstream tooling can filter.
218
+ */
219
+ tags?: string[];
220
+ }
221
+
132
222
  /**
133
223
  * IR-level state declaration.
134
224
  *
@@ -159,8 +249,14 @@ interface IRState {
159
249
  id: string;
160
250
  name: string;
161
251
  description?: string;
162
- /** Element criteria that must ALL be satisfied for this state to be active. */
163
- requiredElements: IRElementCriteria[];
252
+ /**
253
+ * State-scoped assertions. Each carries its own assertion_id, description,
254
+ * severity, category, and an IrElementCriteria target via target.criteria.
255
+ * Spec-Check (Plan 02) evaluates these against UI Bridge snapshots; policy
256
+ * filtering via `severity`/`category` is meaningful because each assertion
257
+ * carries its own metadata (no synthesized stubs).
258
+ */
259
+ assertions: IRAssertion[];
164
260
  /** Element criteria where NONE may be satisfied (any match disqualifies). */
165
261
  excludedElements?: IRElementCriteria[];
166
262
  /** Additional property checks on matched elements. */
@@ -281,88 +377,6 @@ interface IRTransition {
281
377
  crossRefs?: IRCrossRef[];
282
378
  }
283
379
 
284
- /**
285
- * IR-side group + assertion types.
286
- *
287
- * The IR's primary authoring surface is `states + transitions`, which the
288
- * projection maps into legacy `groups[]` (one group per state). However, the
289
- * runner's `workflow_generation::spec_synthesis` pipeline produces "free-form"
290
- * groups from acceptance criteria — these are NOT tied to any state and
291
- * therefore have no home in the state-derived projection path.
292
- *
293
- * `IRGroup` is the dedicated channel for those synthesized groups. The IR
294
- * carries them in the optional `IRDocument.synthesizedGroups` field; the
295
- * projection appends them after the state-derived groups, in declared order,
296
- * to preserve byte-stable output.
297
- *
298
- * The shape mirrors the legacy `SpecGroup` / `SpecAssertion` (canonical
299
- * definitions live in `@qontinui/ui-bridge/specs`), but is re-defined here to
300
- * keep `qontinui-schemas/ts` free of any runtime dep on `@qontinui/ui-bridge/*`
301
- * (per the schemas package's "zero ui-bridge deps" policy).
302
- *
303
- * Note on field shape: the IR-side `IRAssertion` keeps the legacy assertion's
304
- * field types as loose as the synthesis path emits them. Strict consumers
305
- * (e.g. the canonical `SpecAssertion` in `@qontinui/ui-bridge/specs`) can
306
- * narrow as needed at the consumer boundary; the projection preserves the
307
- * objects verbatim into the legacy output.
308
- */
309
- /**
310
- * IR-side assertion target. Always `type: "search"` for synthesis-emitted
311
- * assertions; the wider legacy schema also supports point/region targets but
312
- * the IR doesn't express those today.
313
- */
314
- interface IRAssertionTarget {
315
- /** Always `"search"` for synthesis-emitted assertions. */
316
- type: string;
317
- /**
318
- * Free-form criteria object. Kept as a loose record so synthesis can emit
319
- * partially-populated criteria without tripping the schema.
320
- */
321
- criteria: Record<string, unknown>;
322
- label: string;
323
- }
324
- /**
325
- * IR-side assertion. Mirrors the legacy `SpecAssertion` shape.
326
- */
327
- interface IRAssertion {
328
- id: string;
329
- description: string;
330
- category: string;
331
- severity: string;
332
- assertionType: string;
333
- target: IRAssertionTarget;
334
- source: string;
335
- reviewed: boolean;
336
- enabled: boolean;
337
- /**
338
- * Optional human-readable precondition. Synthesis populates this from the
339
- * acceptance criterion's verification hint.
340
- */
341
- precondition?: string;
342
- }
343
- /**
344
- * IR-side group produced by workflow-criteria synthesis (i.e. NOT derived
345
- * from `IRState` annotations). Mirrors the legacy `SpecGroup` shape one-to-one
346
- * so the projection can pass it through to legacy `groups[]` without loss.
347
- */
348
- interface IRGroup {
349
- id: string;
350
- name: string;
351
- description: string;
352
- category: string;
353
- assertions: IRAssertion[];
354
- /**
355
- * Provenance of the group itself (typically `"ai-generated"` for synthesis
356
- * output, but kept open for future authoring channels).
357
- */
358
- source?: string;
359
- /**
360
- * Free-form tags. Synthesis emits e.g. `["workflow-generated",
361
- * "acceptance-criteria"]` so downstream tooling can filter.
362
- */
363
- tags?: string[];
364
- }
365
-
366
380
  /**
367
381
  * Top-level IR document.
368
382
  *
@@ -4,7 +4,9 @@ function adaptIRState(state) {
4
4
  const out = {
5
5
  id: state.id,
6
6
  name: state.name,
7
- requiredElements: state.requiredElements
7
+ requiredElements: state.assertions.map(
8
+ (a) => a.target.criteria
9
+ )
8
10
  };
9
11
  if (state.description !== void 0) out.description = state.description;
10
12
  if (state.excludedElements !== void 0) out.excludedElements = state.excludedElements;
@@ -108,34 +110,8 @@ function convertCriteria(criteria) {
108
110
  if (criteria.attributes !== void 0) out.dataAttributes = criteria.attributes;
109
111
  return out;
110
112
  }
111
- function buildAssertion(state, index, criteria) {
112
- const description = state.metadata?.description ?? `Required element ${index} for state ${state.name}`;
113
- const targetCriteria = convertCriteria(criteria);
114
- const assertion = {
115
- id: `${state.id}-elem-${index}`,
116
- description,
117
- category: "element-presence",
118
- severity: "critical",
119
- assertionType: "exists",
120
- target: {
121
- type: "search",
122
- criteria: targetCriteria,
123
- label: `Required element for ${state.name}`
124
- },
125
- source: "ai-generated",
126
- reviewed: false,
127
- enabled: true
128
- };
129
- if (state.precondition !== void 0) {
130
- assertion.precondition = state.precondition;
131
- }
132
- return assertion;
133
- }
134
113
  function buildGroup(state) {
135
- const elems = state.requiredElements ?? [];
136
- const assertions = elems.map(
137
- (c, i) => buildAssertion(state, i, c)
138
- );
114
+ const assertions = state.assertions.map(synthesizedAssertionToLegacy);
139
115
  return {
140
116
  id: state.id,
141
117
  name: state.name,
@@ -206,7 +182,10 @@ function buildStateMachineState(state, transitions, doc) {
206
182
  id: state.id,
207
183
  name: state.name,
208
184
  description: state.description ?? "",
209
- elements: (state.requiredElements ?? []).map(convertCriteria),
185
+ // Project legacy `elements[]` from each assertion's target.criteria.
186
+ elements: state.assertions.map(
187
+ (a) => convertCriteria(a.target.criteria)
188
+ ),
210
189
  isInitial,
211
190
  transitions: outgoing
212
191
  };
@@ -258,15 +237,33 @@ function firstPrecondition(group) {
258
237
  return void 0;
259
238
  }
260
239
  function buildIRState(group, smState) {
261
- const requiredElements = group.assertions.map(
262
- (a) => invertCriteria(a.target?.criteria)
263
- );
240
+ const assertions = group.assertions.map((a) => {
241
+ const ir = {
242
+ id: a.id,
243
+ description: a.description,
244
+ category: a.category,
245
+ severity: a.severity,
246
+ assertionType: a.assertionType,
247
+ target: {
248
+ type: "search",
249
+ criteria: invertCriteria(a.target?.criteria),
250
+ label: a.target?.label ?? a.description
251
+ },
252
+ source: a.source,
253
+ reviewed: a.reviewed,
254
+ enabled: a.enabled
255
+ };
256
+ if (a.precondition !== void 0) {
257
+ ir.precondition = a.precondition;
258
+ }
259
+ return ir;
260
+ });
264
261
  const description = group.description !== void 0 && group.description.length > 0 ? group.description : smState?.description;
265
262
  const precondition = firstPrecondition(group);
266
263
  const state = {
267
264
  id: group.id,
268
265
  name: smState?.name ?? group.name,
269
- requiredElements
266
+ assertions
270
267
  };
271
268
  if (description !== void 0 && description.length > 0) {
272
269
  state.description = description;
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/ui-bridge-ir/adapter.ts","../src/ui-bridge-ir/projection.ts"],"sourcesContent":["/**\r\n * IR -> WorkflowConfig adapter.\r\n *\r\n * Single point of translation between authoring-time IR (with provenance,\r\n * metadata, effect, crossRefs, visualRefs) and the runtime/storage shape\r\n * that ui-bridge-auto consumes. See ADR-001 (decision #6 / #7) for the\r\n * boundary rationale.\r\n *\r\n * The output is intentionally typed structurally — this module has no\r\n * runtime dependency on ui-bridge-auto. ui-bridge-auto's own tests verify\r\n * end-to-end compatibility with `engine.defineStates(...)` /\r\n * `engine.defineTransitions(...)` (see\r\n * `ui-bridge-auto/src/__tests__/spike-ir-contract.test.ts`).\r\n */\r\n\r\nimport type { IRElementCriteria } from \"./element-criteria\";\r\nimport type { IRDocument } from \"./document\";\r\nimport type { IRState, IRStateCondition } from \"./state\";\r\nimport type { IRTransition, IRTransitionAction, IRWaitSpec } from \"./transition\";\r\n\r\n// ---------------------------------------------------------------------------\r\n// Output shapes — structural mirrors of ui-bridge-auto's WorkflowConfig.\r\n// Kept in sync via ui-bridge-auto's regression test, NOT compile-time\r\n// imports (qontinui-schemas has no runtime deps by design).\r\n// ---------------------------------------------------------------------------\r\n\r\n/** Mirrors `StateConfig` from ui-bridge-auto/src/config/workflow.ts:47. */\r\nexport interface AdaptedState {\r\n id: string;\r\n name: string;\r\n description?: string;\r\n requiredElements: IRElementCriteria[];\r\n excludedElements?: IRElementCriteria[];\r\n conditions?: IRStateCondition[];\r\n isInitial?: boolean;\r\n isTerminal?: boolean;\r\n blocking?: boolean;\r\n group?: string;\r\n pathCost?: number;\r\n}\r\n\r\n/**\r\n * Mirrors the runtime `TransitionDefinition` shape from\r\n * ui-bridge-auto/src/state/state-machine.ts:40.\r\n *\r\n * Note: ui-bridge-auto has two related Transition shapes — the storage shape\r\n * (`TransitionConfig` in config/workflow.ts:54, with action field named\r\n * `type`) and the runtime engine shape (`TransitionDefinition` in\r\n * state-machine.ts:40, with action field named `action`). The runtime engine\r\n * is what consumers actually pass adapter output into via\r\n * `engine.defineTransitions(...)`, so the adapter targets the runtime shape.\r\n */\r\nexport interface AdaptedTransition {\r\n id: string;\r\n name: string;\r\n description?: string;\r\n fromStates: string[];\r\n activateStates: string[];\r\n /** Adapter normalizes IR's optional `exitStates` to a required array. */\r\n exitStates: string[];\r\n actions: AdaptedTransitionAction[];\r\n pathCost?: number;\r\n bidirectional?: boolean;\r\n}\r\n\r\n/**\r\n * Mirrors the runtime `TransitionAction` from\r\n * ui-bridge-auto/src/state/state-machine.ts:55.\r\n *\r\n * The IR uses `type` for the action verb (matching the storage-shape\r\n * convention); the adapter renames it to `action` for the runtime engine.\r\n *\r\n * `waitAfter` is narrower than `IRWaitSpec` — the runtime engine accepts\r\n * only a subset of wait types and a subset of fields. The adapter drops\r\n * IR-only wait variants (e.g., `state`, `condition`) and IR-only fields\r\n * (e.g., `property`, `quietPeriodMs`). Authors can still express richer\r\n * waits in the IR; they just don't survive the runtime contract.\r\n */\r\nexport interface AdaptedWaitAfter {\r\n type: \"idle\" | \"element\" | \"time\" | \"vanish\" | \"change\" | \"stable\";\r\n query?: IRElementCriteria;\r\n ms?: number;\r\n timeout?: number;\r\n}\r\n\r\nexport interface AdaptedTransitionAction {\r\n /** Action verb — renamed from IR's `type` to match the runtime contract. */\r\n action: string;\r\n target: IRElementCriteria;\r\n params?: Record<string, unknown>;\r\n waitAfter?: AdaptedWaitAfter;\r\n}\r\n\r\n/** Mirrors `WorkflowConfig` from ui-bridge-auto/src/config/workflow.ts:67. */\r\nexport interface AdaptedWorkflowConfig {\r\n id: string;\r\n name: string;\r\n description?: string;\r\n version?: string;\r\n states: AdaptedState[];\r\n transitions: AdaptedTransition[];\r\n initialState?: string;\r\n}\r\n\r\n// ---------------------------------------------------------------------------\r\n// Adapter implementation\r\n// ---------------------------------------------------------------------------\r\n\r\nconst SUPPORTED_IR_VERSIONS = new Set<string>([\"1.0\"]);\r\n\r\n/**\r\n * Convert an IR state declaration into the runtime/storage state shape.\r\n * Strips IR-only fields (metadata, provenance, elementIds,\r\n * incomingTransitions, crossRefs, visualRefs).\r\n */\r\nexport function adaptIRState(state: IRState): AdaptedState {\r\n const out: AdaptedState = {\r\n id: state.id,\r\n name: state.name,\r\n requiredElements: state.requiredElements,\r\n };\r\n if (state.description !== undefined) out.description = state.description;\r\n if (state.excludedElements !== undefined) out.excludedElements = state.excludedElements;\r\n if (state.conditions !== undefined) out.conditions = state.conditions;\r\n if (state.isInitial !== undefined) out.isInitial = state.isInitial;\r\n if (state.isTerminal !== undefined) out.isTerminal = state.isTerminal;\r\n if (state.blocking !== undefined) out.blocking = state.blocking;\r\n if (state.group !== undefined) out.group = state.group;\r\n if (state.pathCost !== undefined) out.pathCost = state.pathCost;\r\n return out;\r\n}\r\n\r\n/**\r\n * Wait types the runtime engine accepts. IR-authored waits with other types\r\n * (e.g., `state`, `condition`) are dropped from the adapter output.\r\n */\r\nconst RUNTIME_WAIT_TYPES = new Set<AdaptedWaitAfter[\"type\"]>([\r\n \"idle\",\r\n \"element\",\r\n \"time\",\r\n \"vanish\",\r\n \"change\",\r\n \"stable\",\r\n]);\r\n\r\nfunction adaptIRWaitAfter(wait: IRWaitSpec): AdaptedWaitAfter | undefined {\r\n if (!RUNTIME_WAIT_TYPES.has(wait.type as AdaptedWaitAfter[\"type\"])) {\r\n // IR-authored wait is richer than runtime supports — drop it.\r\n // Runtime defaults (default idle behaviour) take over.\r\n return undefined;\r\n }\r\n const out: AdaptedWaitAfter = { type: wait.type as AdaptedWaitAfter[\"type\"] };\r\n if (wait.query !== undefined) out.query = wait.query;\r\n if (wait.ms !== undefined) out.ms = wait.ms;\r\n if (wait.timeout !== undefined) out.timeout = wait.timeout;\r\n return out;\r\n}\r\n\r\n/**\r\n * Convert an IR transition action into the runtime action shape.\r\n * Renames IR's `type` to runtime's `action`; narrows `waitAfter` to the\r\n * runtime-accepted subset.\r\n */\r\nexport function adaptIRTransitionAction(action: IRTransitionAction): AdaptedTransitionAction {\r\n const out: AdaptedTransitionAction = {\r\n action: action.type,\r\n target: action.target,\r\n };\r\n if (action.params !== undefined) out.params = action.params;\r\n if (action.waitAfter !== undefined) {\r\n const adaptedWait = adaptIRWaitAfter(action.waitAfter);\r\n if (adaptedWait !== undefined) out.waitAfter = adaptedWait;\r\n }\r\n return out;\r\n}\r\n\r\n/**\r\n * Convert an IR transition declaration into the runtime/storage transition\r\n * shape. Strips IR-only fields (effect, metadata, provenance, crossRefs)\r\n * and defaults `exitStates` to `[]` when omitted.\r\n */\r\nexport function adaptIRTransition(transition: IRTransition): AdaptedTransition {\r\n const out: AdaptedTransition = {\r\n id: transition.id,\r\n name: transition.name,\r\n fromStates: transition.fromStates,\r\n activateStates: transition.activateStates,\r\n exitStates: transition.exitStates ?? [],\r\n actions: transition.actions.map(adaptIRTransitionAction),\r\n };\r\n if (transition.description !== undefined) out.description = transition.description;\r\n if (transition.pathCost !== undefined) out.pathCost = transition.pathCost;\r\n if (transition.bidirectional !== undefined) out.bidirectional = transition.bidirectional;\r\n return out;\r\n}\r\n\r\n/**\r\n * Convert a top-level IR document into the runtime `WorkflowConfig` shape.\r\n *\r\n * Throws on unknown IR versions to fail loudly rather than silently emit\r\n * stale shapes.\r\n */\r\nexport function adaptIRDocumentToWorkflowConfig(doc: IRDocument): AdaptedWorkflowConfig {\r\n if (!SUPPORTED_IR_VERSIONS.has(doc.version)) {\r\n throw new Error(\r\n `adaptIRDocumentToWorkflowConfig: unsupported IR version \"${doc.version}\". ` +\r\n `Supported: ${Array.from(SUPPORTED_IR_VERSIONS).join(\", \")}`,\r\n );\r\n }\r\n\r\n const out: AdaptedWorkflowConfig = {\r\n id: doc.id,\r\n name: doc.name,\r\n states: doc.states.map(adaptIRState),\r\n transitions: doc.transitions.map(adaptIRTransition),\r\n };\r\n if (doc.description !== undefined) out.description = doc.description;\r\n if (doc.initialState !== undefined) out.initialState = doc.initialState;\r\n return out;\r\n}\r\n","/**\r\n * IR -> Bundled-Page Legacy Spec projection.\r\n *\r\n * Single point of translation between authoring-time IR (`IRDocument`) and the\r\n * legacy `*.spec.uibridge.json` shape that existing tooling still consumes\r\n * (`/update-spec`, runner spec drift / verify, error monitor curator,\r\n * spec experimentation, AI session). See ADR-001 (decision #6 / #7) for the\r\n * boundary rationale; section 2 of the UI Bridge redesign for the projection's\r\n * role in keeping legacy consumers working through the migration.\r\n *\r\n * The projection is a PURE FUNCTION — same input always produces byte-identical\r\n * output. Keys within objects are sorted lexicographically, arrays preserve\r\n * input order, and no timestamps / random IDs are introduced. Downstream tests\r\n * may hash the JSON output for byte-stable assertions.\r\n *\r\n * ---------------------------------------------------------------------------\r\n * Mapping rules (worked example below)\r\n * ---------------------------------------------------------------------------\r\n *\r\n * IRDocument LegacySpec\r\n * ---------- ----------\r\n * doc.id -> metadata.component\r\n * doc.metadata?.purpose ?? doc.id -> metadata.component (purpose wins if present)\r\n * doc.description ?? doc.name -> description\r\n * doc.metadata?.tags -> metadata.tags\r\n *\r\n * For each IRState:\r\n * state -> one entry in groups[]\r\n * state.id -> group.id\r\n * state.name -> group.name\r\n * state.description ??\r\n * state.metadata?.description -> group.description\r\n * \"element-presence\" -> group.category (default)\r\n * state.provenance?.source ??\r\n * \"ai-generated\" -> group.source\r\n *\r\n * For each requiredElement of state:\r\n * (state, criteria, index) -> one assertion in group.assertions[]\r\n * \"${state.id}-elem-${index}\" -> assertion.id\r\n * state.metadata?.description ?? -> assertion.description\r\n * \"Required element ${index} ...\"\r\n * \"element-presence\" -> assertion.category\r\n * \"critical\" -> assertion.severity\r\n * \"exists\" -> assertion.assertionType\r\n * {\r\n * type: \"search\",\r\n * criteria: convert(criteria), -> assertion.target\r\n * label: \"Required element ...\"\r\n * }\r\n * \"ai-generated\" -> assertion.source\r\n * false -> assertion.reviewed\r\n * true -> assertion.enabled\r\n *\r\n * If state has zero requiredElements, the projected `group.assertions[]`\r\n * is the empty array — legacy specs ship architecture-only groups with\r\n * empty assertions, and the inverse projection's identity round-trip\r\n * depends on preserving that emptiness. (Earlier versions emitted a\r\n * placeholder assertion here, which silently grew the assertion count\r\n * during round-trip and tripped `check-spec-pairing`.)\r\n *\r\n * Each IRState -> one entry in stateMachine.states[]\r\n * state.id -> sm-state.id\r\n * state.name -> sm-state.name\r\n * state.description ?? \"\" -> sm-state.description\r\n * state.requiredElements (converted) -> sm-state.elements\r\n * state.isInitial ??\r\n * (state.id === doc.initialState) -> sm-state.isInitial\r\n * transitions originating from state -> sm-state.transitions\r\n *\r\n * For each IRTransition:\r\n * For each fromState in transition.fromStates:\r\n * transition -> one entry in\r\n * stateMachine.states[fromState].transitions[]\r\n * transition.id -> sm-transition.id\r\n * transition.name -> sm-transition.name\r\n * transition.activateStates -> sm-transition.activateStates\r\n * transition.exitStates ?? [] -> sm-transition.deactivateStates\r\n * (exitStates.length === 0) -> sm-transition.staysVisible\r\n *\r\n * For each action in transition.actions:\r\n * action.type -> process[].action (rename type -> action)\r\n * action.target -> process[].target (criteria converted)\r\n * action.waitAfter -> process[].waitAfter (passed through)\r\n *\r\n * Element-criteria conversion (IRElementCriteria -> legacy criteria):\r\n * text -> textContent\r\n * ariaLabel -> accessibleName\r\n * attributes -> dataAttributes\r\n * (others — role, textContains, id — pass through unchanged)\r\n *\r\n * ---------------------------------------------------------------------------\r\n * Worked example\r\n * ---------------------------------------------------------------------------\r\n *\r\n * const ir: IRDocument = {\r\n * version: \"1.0\",\r\n * id: \"active\",\r\n * name: \"Active Dashboard\",\r\n * description: \"Real-time monitoring hub\",\r\n * metadata: { tags: [\"monitoring\", \"tier-1\"] },\r\n * states: [\r\n * {\r\n * id: \"running\",\r\n * name: \"Running\",\r\n * description: \"Workflow executing\",\r\n * requiredElements: [{ role: \"button\", text: \"Stop\" }],\r\n * isInitial: false,\r\n * },\r\n * ],\r\n * transitions: [\r\n * {\r\n * id: \"running-to-idle\",\r\n * name: \"Stop\",\r\n * fromStates: [\"running\"],\r\n * activateStates: [\"idle\"],\r\n * exitStates: [\"running\"],\r\n * actions: [\r\n * {\r\n * type: \"click\",\r\n * target: { role: \"button\", text: \"Stop\" },\r\n * waitAfter: { type: \"idle\", timeout: 3000 },\r\n * },\r\n * ],\r\n * },\r\n * ],\r\n * initialState: \"idle\",\r\n * };\r\n *\r\n * projectIRToBundledPage(ir, \"Notes from author\")\r\n * // -> {\r\n * // version: \"1.0.0\",\r\n * // description: \"Real-time monitoring hub\\n\\nNotes from author\",\r\n * // groups: [{\r\n * // id: \"running\",\r\n * // name: \"Running\",\r\n * // description: \"Workflow executing\",\r\n * // category: \"element-presence\",\r\n * // assertions: [{\r\n * // id: \"running-elem-0\",\r\n * // description: \"Required element 0 for state Running\",\r\n * // category: \"element-presence\",\r\n * // severity: \"critical\",\r\n * // assertionType: \"exists\",\r\n * // target: {\r\n * // type: \"search\",\r\n * // criteria: { role: \"button\", textContent: \"Stop\" },\r\n * // label: \"Required element for Running\",\r\n * // },\r\n * // source: \"ai-generated\",\r\n * // reviewed: false,\r\n * // enabled: true,\r\n * // }],\r\n * // source: \"ai-generated\",\r\n * // }],\r\n * // stateMachine: {\r\n * // states: [{\r\n * // id: \"running\",\r\n * // name: \"Running\",\r\n * // description: \"Workflow executing\",\r\n * // elements: [{ role: \"button\", textContent: \"Stop\" }],\r\n * // isInitial: false,\r\n * // transitions: [{\r\n * // id: \"running-to-idle\",\r\n * // name: \"Stop\",\r\n * // activateStates: [\"idle\"],\r\n * // deactivateStates: [\"running\"],\r\n * // staysVisible: false,\r\n * // process: [{\r\n * // action: \"click\",\r\n * // target: { role: \"button\", textContent: \"Stop\" },\r\n * // waitAfter: { type: \"idle\", timeout: 3000 },\r\n * // }],\r\n * // }],\r\n * // }],\r\n * // },\r\n * // metadata: { component: \"active\", tags: [\"monitoring\", \"tier-1\"] },\r\n * // }\r\n */\r\n\r\nimport type { IRElementCriteria } from \"./element-criteria\";\r\nimport type { IRDocument } from \"./document\";\r\nimport type { IRAssertion, IRGroup } from \"./group\";\r\nimport type { IRState } from \"./state\";\r\nimport type { IRTransition, IRTransitionAction, IRWaitSpec } from \"./transition\";\r\n\r\n/**\r\n * Projection version. Bump on shape changes that consumers must adapt to.\r\n * Independent from `IRVersion` because the legacy spec shape and the IR shape\r\n * evolve on different cadences.\r\n */\r\nexport const projectionVersion = \"1.0\";\r\n\r\n// ---------------------------------------------------------------------------\r\n// Legacy spec shapes — derived from active.spec.uibridge.json (the reference\r\n// the projection's output must structurally match).\r\n// ---------------------------------------------------------------------------\r\n\r\n/**\r\n * Legacy element-criteria shape (after conversion from `IRElementCriteria`).\r\n *\r\n * The differences from `IRElementCriteria`:\r\n * - `text` -> `textContent`\r\n * - `ariaLabel` -> `accessibleName` (when IR has no explicit `accessibleName`)\r\n * - `attributes` -> `dataAttributes`\r\n *\r\n * Other fields (`role`, `tagName`, `textContains`, `accessibleName`, `id`)\r\n * pass through unchanged. Index signature stays open for legacy fields the\r\n * IR doesn't yet model.\r\n */\r\nexport interface LegacyCriteria {\r\n role?: string;\r\n tagName?: string;\r\n textContent?: string;\r\n textContains?: string;\r\n accessibleName?: string;\r\n id?: string;\r\n dataAttributes?: Record<string, string>;\r\n [key: string]: unknown;\r\n}\r\n\r\n/**\r\n * Legacy assertion target. Always `type: \"search\"` for the projection — the\r\n * legacy schema also supports point/region targets, but the IR doesn't\r\n * express those.\r\n */\r\nexport interface LegacyAssertionTarget {\r\n type: \"search\";\r\n criteria: LegacyCriteria;\r\n label: string;\r\n}\r\n\r\n/**\r\n * Legacy assertion. Mirrors the shape used by `groups[].assertions[]` in\r\n * `*.spec.uibridge.json`.\r\n */\r\nexport interface LegacyAssertion {\r\n id: string;\r\n description: string;\r\n category: string;\r\n severity: \"critical\" | \"warning\" | \"info\";\r\n assertionType: string;\r\n target: LegacyAssertionTarget;\r\n source: string;\r\n reviewed: boolean;\r\n enabled: boolean;\r\n precondition?: string;\r\n}\r\n\r\n/**\r\n * Legacy group. One per IR state.\r\n */\r\nexport interface LegacyGroup {\r\n id: string;\r\n name: string;\r\n description: string;\r\n category: string;\r\n assertions: LegacyAssertion[];\r\n source: string;\r\n}\r\n\r\n/**\r\n * Process step within a transition. Note `action` (not `type`) — matches the\r\n * runtime engine's `TransitionAction` shape.\r\n */\r\nexport interface LegacyProcessStep {\r\n action: string;\r\n target: LegacyCriteria;\r\n waitAfter?: IRWaitSpec;\r\n}\r\n\r\n/**\r\n * Legacy state-machine transition.\r\n */\r\nexport interface LegacyTransition {\r\n id: string;\r\n name: string;\r\n activateStates: string[];\r\n deactivateStates: string[];\r\n staysVisible: boolean;\r\n process: LegacyProcessStep[];\r\n}\r\n\r\n/**\r\n * Legacy state-machine state.\r\n */\r\nexport interface LegacyStateMachineState {\r\n id: string;\r\n name: string;\r\n description: string;\r\n elements: LegacyCriteria[];\r\n isInitial: boolean;\r\n transitions: LegacyTransition[];\r\n}\r\n\r\n/**\r\n * Legacy state-machine block.\r\n */\r\nexport interface LegacyStateMachine {\r\n states: LegacyStateMachineState[];\r\n}\r\n\r\n/**\r\n * Legacy spec metadata block. The projection writes a deterministic subset;\r\n * downstream tooling may layer additional keys on hand-authored specs.\r\n */\r\nexport interface LegacyMetadata {\r\n component: string;\r\n tags?: string[];\r\n [key: string]: unknown;\r\n}\r\n\r\n/**\r\n * Top-level legacy spec shape.\r\n */\r\nexport interface LegacySpec {\r\n version: string;\r\n description: string;\r\n groups: LegacyGroup[];\r\n stateMachine: LegacyStateMachine;\r\n metadata: LegacyMetadata;\r\n}\r\n\r\n// ---------------------------------------------------------------------------\r\n// Internal helpers\r\n// ---------------------------------------------------------------------------\r\n\r\n/**\r\n * Recursively sort object keys lexicographically. Arrays preserve input order\r\n * (ordering is meaningful for groups / assertions / transitions).\r\n *\r\n * Used as the final stage of every projected output to guarantee byte-stable\r\n * JSON serialization downstream.\r\n */\r\nfunction sortKeys<T>(value: T): T {\r\n if (Array.isArray(value)) {\r\n return value.map(sortKeys) as unknown as T;\r\n }\r\n if (value !== null && typeof value === \"object\") {\r\n const sorted: Record<string, unknown> = {};\r\n const keys = Object.keys(value as Record<string, unknown>).sort();\r\n for (const key of keys) {\r\n sorted[key] = sortKeys((value as Record<string, unknown>)[key]);\r\n }\r\n return sorted as unknown as T;\r\n }\r\n return value;\r\n}\r\n\r\n/**\r\n * Convert IR element criteria to legacy criteria. Renames `text` ->\r\n * `textContent`, `attributes` -> `dataAttributes`. `accessibleName` (or\r\n * `ariaLabel` as a fallback) maps to legacy `accessibleName`. `tagName`,\r\n * `role`, `textContains`, `id` pass through unchanged.\r\n */\r\nfunction convertCriteria(criteria: IRElementCriteria): LegacyCriteria {\r\n const out: LegacyCriteria = {};\r\n if (criteria.role !== undefined) out.role = criteria.role;\r\n if (criteria.tagName !== undefined) out.tagName = criteria.tagName;\r\n if (criteria.text !== undefined) out.textContent = criteria.text;\r\n if (criteria.textContains !== undefined) out.textContains = criteria.textContains;\r\n // Prefer explicit `accessibleName` when present; fall back to `ariaLabel`\r\n // for IR documents authored against the section-1 shape.\r\n if (criteria.accessibleName !== undefined) {\r\n out.accessibleName = criteria.accessibleName;\r\n } else if (criteria.ariaLabel !== undefined) {\r\n out.accessibleName = criteria.ariaLabel;\r\n }\r\n if (criteria.id !== undefined) out.id = criteria.id;\r\n if (criteria.attributes !== undefined) out.dataAttributes = criteria.attributes;\r\n return out;\r\n}\r\n\r\n/**\r\n * Build a single legacy assertion from a state + index + criteria.\r\n *\r\n * Always produces one assertion per requiredElement; the caller is responsible\r\n * for iterating `state.requiredElements`. Empty `requiredElements` produces an\r\n * empty `assertions[]` — legitimate legacy specs (e.g. architecture-only\r\n * groups in `graphql-infrastructure`, `activity-timeline`, `opik-integration`,\r\n * `watchers`) ship with empty `assertions[]`, and the inverse projection\r\n * round-trip must preserve that emptiness or `check-spec-pairing` flags an\r\n * assertion-count drift.\r\n */\r\nfunction buildAssertion(\r\n state: IRState,\r\n index: number,\r\n criteria: IRElementCriteria,\r\n): LegacyAssertion {\r\n const description =\r\n state.metadata?.description ?? `Required element ${index} for state ${state.name}`;\r\n const targetCriteria: LegacyCriteria = convertCriteria(criteria);\r\n const assertion: LegacyAssertion = {\r\n id: `${state.id}-elem-${index}`,\r\n description,\r\n category: \"element-presence\",\r\n severity: \"critical\",\r\n assertionType: \"exists\",\r\n target: {\r\n type: \"search\",\r\n criteria: targetCriteria,\r\n label: `Required element for ${state.name}`,\r\n },\r\n source: \"ai-generated\",\r\n reviewed: false,\r\n enabled: true,\r\n };\r\n if (state.precondition !== undefined) {\r\n assertion.precondition = state.precondition;\r\n }\r\n return assertion;\r\n}\r\n\r\n/**\r\n * Build the legacy `groups[]` entry for one IR state. Emits exactly one\r\n * assertion per `requiredElement`; states with zero requiredElements project\r\n * to a group with an empty `assertions[]` array. Legacy consumers (runner\r\n * spec drift / verify, error monitor curator, AI session) tolerate empty\r\n * groups — multiple shipping legacy specs already use them for\r\n * architecture-only / documentation-only groups.\r\n */\r\nfunction buildGroup(state: IRState): LegacyGroup {\r\n const elems = state.requiredElements ?? [];\r\n const assertions: LegacyAssertion[] = elems.map((c, i) =>\r\n buildAssertion(state, i, c),\r\n );\r\n return {\r\n id: state.id,\r\n name: state.name,\r\n description: state.description ?? state.metadata?.description ?? \"\",\r\n category: \"element-presence\",\r\n assertions,\r\n source: state.provenance?.source ?? \"ai-generated\",\r\n };\r\n}\r\n\r\n/**\r\n * Convert an `IRAssertion` (IR-side, free-form criteria) into a `LegacyAssertion`.\r\n * The shapes are near-identical; the only meaningful difference is that the\r\n * IR-side `target.criteria` is `Record<string, unknown>` while the legacy\r\n * shape is `LegacyCriteria` (a typed but extensible record). We pass the\r\n * criteria object through verbatim — the open `[key: string]: unknown` index\r\n * signature on `LegacyCriteria` accepts any record shape.\r\n */\r\nfunction synthesizedAssertionToLegacy(assertion: IRAssertion): LegacyAssertion {\r\n const target: LegacyAssertionTarget = {\r\n type: \"search\",\r\n criteria: assertion.target.criteria as LegacyCriteria,\r\n label: assertion.target.label,\r\n };\r\n const out: LegacyAssertion = {\r\n id: assertion.id,\r\n description: assertion.description,\r\n category: assertion.category,\r\n severity: assertion.severity as LegacyAssertion[\"severity\"],\r\n assertionType: assertion.assertionType,\r\n target,\r\n source: assertion.source,\r\n reviewed: assertion.reviewed,\r\n enabled: assertion.enabled,\r\n };\r\n if (assertion.precondition !== undefined) {\r\n out.precondition = assertion.precondition;\r\n }\r\n return out;\r\n}\r\n\r\n/**\r\n * Convert a synthesized `IRGroup` into a `LegacyGroup`. Mirrors the legacy\r\n * shape one-to-one (modulo the free-form criteria pass-through described in\r\n * `synthesizedAssertionToLegacy`). The synthesized group always carries a\r\n * `source` (synthesis emits `\"ai-generated\"`); fall back to `\"ai-generated\"`\r\n * for hand-written IR documents that omit it.\r\n */\r\nfunction synthesizedGroupToLegacy(group: IRGroup): LegacyGroup {\r\n return {\r\n id: group.id,\r\n name: group.name,\r\n description: group.description,\r\n category: group.category,\r\n assertions: group.assertions.map(synthesizedAssertionToLegacy),\r\n source: group.source ?? \"ai-generated\",\r\n };\r\n}\r\n\r\n/**\r\n * Convert an IR transition action into the legacy `process[]` step shape.\r\n * Renames IR's `type` to legacy `action` (matches the runtime engine\r\n * convention — same as the IR -> WorkflowConfig adapter does for runtime).\r\n */\r\nfunction buildProcessStep(action: IRTransitionAction): LegacyProcessStep {\r\n const out: LegacyProcessStep = {\r\n action: action.type,\r\n target: convertCriteria(action.target),\r\n };\r\n if (action.waitAfter !== undefined) out.waitAfter = action.waitAfter;\r\n return out;\r\n}\r\n\r\n/**\r\n * Convert one IR transition into the legacy state-machine transition shape.\r\n * Each fromState gets its own copy in the projected output (legacy specs put\r\n * the transition under each originating state's `transitions[]`).\r\n */\r\nfunction buildTransition(transition: IRTransition): LegacyTransition {\r\n const exitStates = transition.exitStates ?? [];\r\n return {\r\n id: transition.id,\r\n name: transition.name,\r\n activateStates: transition.activateStates,\r\n deactivateStates: exitStates,\r\n // Modal-style transitions (no exit states) stay visible behind the\r\n // activated state. Otherwise the originating state(s) deactivate, so the\r\n // page no longer shows them.\r\n staysVisible: exitStates.length === 0,\r\n process: transition.actions.map(buildProcessStep),\r\n };\r\n}\r\n\r\n/**\r\n * Build the legacy `stateMachine.states[]` entry for one IR state. Includes\r\n * any transitions that originate from this state (i.e. where state.id is in\r\n * transition.fromStates).\r\n */\r\nfunction buildStateMachineState(\r\n state: IRState,\r\n transitions: IRTransition[],\r\n doc: IRDocument,\r\n): LegacyStateMachineState {\r\n const outgoing = transitions\r\n .filter((t) => t.fromStates.includes(state.id))\r\n .map(buildTransition);\r\n const isInitial =\r\n state.isInitial !== undefined ? state.isInitial : state.id === doc.initialState;\r\n return {\r\n id: state.id,\r\n name: state.name,\r\n description: state.description ?? \"\",\r\n elements: (state.requiredElements ?? []).map(convertCriteria),\r\n isInitial,\r\n transitions: outgoing,\r\n };\r\n}\r\n\r\n// ---------------------------------------------------------------------------\r\n// Public entry point\r\n// ---------------------------------------------------------------------------\r\n\r\n/**\r\n * Project an IR document into the legacy bundled-page spec shape.\r\n *\r\n * Pure / deterministic: same input always produces structurally identical\r\n * output (and byte-identical when JSON-serialized via the standard\r\n * `JSON.stringify` ordering). Arrays preserve input order; object keys are\r\n * sorted lexicographically.\r\n *\r\n * @param doc The IR document to project.\r\n * @param notes Optional human-authored notes (carried in the page's\r\n * `notes.md` companion file). Appended to `description` as a\r\n * separate paragraph (separator: two newlines).\r\n */\r\nexport function projectIRToBundledPage(doc: IRDocument, notes?: string): LegacySpec {\r\n const baseDescription = doc.description ?? doc.name;\r\n const description =\r\n notes !== undefined && notes.length > 0\r\n ? `${baseDescription}\\n\\n${notes}`\r\n : baseDescription;\r\n\r\n const component = doc.metadata?.purpose ?? doc.id;\r\n const metadata: LegacyMetadata = { component };\r\n if (doc.metadata?.tags !== undefined) metadata.tags = doc.metadata.tags;\r\n\r\n const groups: LegacyGroup[] = doc.states.map(buildGroup);\r\n if (doc.synthesizedGroups !== undefined) {\r\n // Append synthesis-produced groups AFTER state-derived ones, in declared\r\n // order. Byte-stable output (see file header) requires this exact ordering\r\n // — anything else breaks `check-spec-pairing` style hashes.\r\n for (const g of doc.synthesizedGroups) {\r\n groups.push(synthesizedGroupToLegacy(g));\r\n }\r\n }\r\n const smStates: LegacyStateMachineState[] = doc.states.map((s) =>\r\n buildStateMachineState(s, doc.transitions, doc),\r\n );\r\n\r\n const spec: LegacySpec = {\r\n version: \"1.0.0\",\r\n description,\r\n groups,\r\n stateMachine: { states: smStates },\r\n metadata,\r\n };\r\n\r\n return sortKeys(spec);\r\n}\r\n\r\n// ---------------------------------------------------------------------------\r\n// Inverse projection — Legacy spec -> IR document\r\n// ---------------------------------------------------------------------------\r\n\r\n/**\r\n * Options for the inverse projection.\r\n *\r\n * - `docId` — explicit IRDocument.id override. Falls back to\r\n * `legacy.metadata.component` (or `fallbackName` if absent).\r\n * - `fallbackName` — used when `legacy.metadata.component` is missing AND no\r\n * `docId` was supplied.\r\n */\r\nexport interface ProjectLegacyToIROptions {\r\n docId?: string;\r\n fallbackName?: string;\r\n}\r\n\r\n/**\r\n * Best-effort field-by-field invert of `LegacyCriteria` back into\r\n * `IRElementCriteria`.\r\n *\r\n * Rename map (the structural inverse of `convertCriteria`):\r\n * textContent -> text\r\n * accessibleName -> accessibleName (passes through; the forward direction\r\n * collapses ariaLabel into accessibleName,\r\n * so we cannot reliably distinguish them\r\n * on the inverse — pick accessibleName).\r\n * dataAttributes -> attributes\r\n * role / tagName / textContains / id pass through unchanged.\r\n *\r\n * Unknown legacy keys are dropped (lossy, but documented). Document-level\r\n * unknown criteria are rare; if they show up we'll surface them in Phase A4.\r\n */\r\nfunction invertCriteria(criteria: LegacyCriteria | undefined): IRElementCriteria {\r\n if (criteria === undefined || criteria === null) return {};\r\n const out: IRElementCriteria = {};\r\n if (criteria.role !== undefined) out.role = criteria.role;\r\n if (criteria.tagName !== undefined) out.tagName = criteria.tagName;\r\n if (criteria.textContent !== undefined) out.text = criteria.textContent;\r\n if (criteria.textContains !== undefined) out.textContains = criteria.textContains;\r\n if (criteria.accessibleName !== undefined) out.accessibleName = criteria.accessibleName;\r\n if (criteria.id !== undefined) out.id = criteria.id;\r\n if (criteria.dataAttributes !== undefined) out.attributes = criteria.dataAttributes;\r\n return out;\r\n}\r\n\r\n/**\r\n * Pick the first non-empty `precondition` across a group's assertions. Legacy\r\n * groups carry preconditions on individual assertions; IR carries it on the\r\n * state. If multiple distinct preconditions exist we keep the first\r\n * (deterministic, mirrors input ordering) — Phase A4 review will surface\r\n * conflicts for hand-fix.\r\n */\r\nfunction firstPrecondition(group: LegacyGroup): string | undefined {\r\n for (const a of group.assertions) {\r\n if (a.precondition !== undefined && a.precondition.length > 0) {\r\n return a.precondition;\r\n }\r\n }\r\n return undefined;\r\n}\r\n\r\n/**\r\n * Build an `IRState` from one legacy group + its corresponding state-machine\r\n * state (when present).\r\n *\r\n * IMPORTANT: `requiredElements` is sourced from the GROUP's assertion criteria\r\n * (one criteria per assertion, in input order), NOT from `smState.elements`.\r\n * This preserves the round-trip identity for the assertion-count check —\r\n * legacy specs sometimes carry an SM block whose `elements[]` is a coarse\r\n * page-state fingerprint (1-2 entries) while the group has many assertions.\r\n * Using `smState.elements` would silently collapse those into one\r\n * requiredElement per state, then the forward direction would emit only one\r\n * assertion per group.\r\n *\r\n * `smState` (when present and matched by id) contributes:\r\n * - `name` override (legacy `smState.name` is human-readable; group.name is\r\n * also human-readable but may differ — prefer smState's name since the\r\n * forward direction's `buildStateMachineState` echoes `state.name` to\r\n * `smState.name`).\r\n * - `description` fallback (when group.description is empty).\r\n * - `isInitial` (the only place this lives in legacy specs).\r\n */\r\nfunction buildIRState(\r\n group: LegacyGroup,\r\n smState: LegacyStateMachineState | undefined,\r\n): IRState {\r\n // Always one requiredElement per assertion so the forward projection emits\r\n // the same number of assertions on the round-trip.\r\n const requiredElements: IRElementCriteria[] = group.assertions.map((a) =>\r\n invertCriteria(a.target?.criteria),\r\n );\r\n\r\n const description =\r\n group.description !== undefined && group.description.length > 0\r\n ? group.description\r\n : smState?.description;\r\n const precondition = firstPrecondition(group);\r\n\r\n const state: IRState = {\r\n id: group.id,\r\n name: smState?.name ?? group.name,\r\n requiredElements,\r\n };\r\n if (description !== undefined && description.length > 0) {\r\n state.description = description;\r\n }\r\n if (smState?.isInitial === true) {\r\n state.isInitial = true;\r\n } else if (smState?.isInitial === false) {\r\n state.isInitial = false;\r\n }\r\n if (precondition !== undefined) {\r\n state.precondition = precondition;\r\n }\r\n state.provenance = { source: \"migrated\" };\r\n return state;\r\n}\r\n\r\n/**\r\n * Convert one legacy `process[]` step back into `IRTransitionAction`. Renames\r\n * `action` -> `type`. Legacy specs occasionally omit a target on no-op steps;\r\n * we coerce to an empty criteria object in that case.\r\n */\r\nfunction invertProcessStep(step: LegacyProcessStep): IRTransitionAction {\r\n const out: IRTransitionAction = {\r\n type: step.action,\r\n target: invertCriteria(step.target),\r\n };\r\n if (step.waitAfter !== undefined) out.waitAfter = step.waitAfter;\r\n return out;\r\n}\r\n\r\n/**\r\n * Collapse duplicate transitions across multiple originating states. The\r\n * forward projection emits the same transition under EACH `fromState`'s\r\n * `transitions[]` entry; the inverse must merge them back into ONE\r\n * `IRTransition` whose `fromStates` lists every originator.\r\n *\r\n * Same-id transitions are assumed to be byte-identical except for the\r\n * (implicit) originating state. If they differ in `process[]` /\r\n * `activateStates` / `deactivateStates`, we keep the first occurrence and\r\n * append the additional fromState. (Genuine divergence here is a defect to\r\n * surface in Phase A4 review.)\r\n */\r\nfunction buildIRTransitions(stateMachine: LegacyStateMachine | undefined): IRTransition[] {\r\n if (stateMachine === undefined || !Array.isArray(stateMachine.states)) return [];\r\n const byId = new Map<string, IRTransition>();\r\n // Preserve insertion order — first state's transitions come first.\r\n const order: string[] = [];\r\n\r\n for (const smState of stateMachine.states) {\r\n const transitions = Array.isArray(smState.transitions) ? smState.transitions : [];\r\n for (const t of transitions) {\r\n const existing = byId.get(t.id);\r\n if (existing !== undefined) {\r\n if (!existing.fromStates.includes(smState.id)) {\r\n existing.fromStates.push(smState.id);\r\n }\r\n continue;\r\n }\r\n const ir: IRTransition = {\r\n id: t.id,\r\n name: t.name,\r\n fromStates: [smState.id],\r\n activateStates: Array.isArray(t.activateStates) ? [...t.activateStates] : [],\r\n actions: Array.isArray(t.process) ? t.process.map(invertProcessStep) : [],\r\n };\r\n // The forward direction maps `exitStates` -> `deactivateStates`; preserve\r\n // the field whenever it's present in legacy form (even if empty array)\r\n // so modal-style transitions (staysVisible: true, deactivateStates: [])\r\n // round-trip predictably.\r\n if (Array.isArray(t.deactivateStates)) {\r\n ir.exitStates = [...t.deactivateStates];\r\n }\r\n ir.provenance = { source: \"migrated\" };\r\n byId.set(t.id, ir);\r\n order.push(t.id);\r\n }\r\n }\r\n\r\n return order.map((id) => byId.get(id)!);\r\n}\r\n\r\n/**\r\n * Project a legacy bundled-page spec back into IR.\r\n *\r\n * Pure / deterministic: same input always produces structurally identical\r\n * output. Collapses transition duplicates (forward emits one copy per\r\n * `fromState`), preserves group/assertion ordering, and tags every node with\r\n * `provenance.source = \"migrated\"` so downstream tooling can distinguish\r\n * migrated content from hand-authored.\r\n *\r\n * The mapping is the structural inverse of `projectIRToBundledPage`:\r\n *\r\n * LegacySpec IRDocument\r\n * ---------- ----------\r\n * metadata.component -> id (or opts.docId override)\r\n * metadata.tags -> metadata.tags\r\n * description -> description (kept verbatim;\r\n * authored notes appended via\r\n * forward `notes` arg are not\r\n * stripped — that round-trip is\r\n * best-effort and Phase A4 will\r\n * split them back out)\r\n *\r\n * groups[] -> states[] (one per group)\r\n * group.id / name / description -> state.id / name / description\r\n * assertion.target.criteria -> state.requiredElements[i] (or,\r\n * preferred, smState.elements when\r\n * the stateMachine block is present)\r\n * first-found assertion.precondition -> state.precondition\r\n *\r\n * stateMachine.states[] -> contributes isInitial + elements\r\n * smState.transitions[] -> transitions[] (deduped by id)\r\n * transition.activateStates -> transition.activateStates\r\n * transition.deactivateStates -> transition.exitStates\r\n * transition.process[] -> transition.actions[]\r\n * step.action -> action.type\r\n * step.target -> action.target (criteria inverted)\r\n * step.waitAfter -> action.waitAfter\r\n *\r\n * Documented losses (acceptable for Phase A2):\r\n * - Legacy assertion ids (`{stateId}-elem-{i}`) are NOT preserved across the\r\n * round-trip — the forward direction regenerates them from index, so any\r\n * hand-edited ids are lost. See Phase A4.\r\n * - Legacy `assertionType` / `severity` / `category` / `source` per\r\n * assertion are reduced to defaults on round-trip.\r\n * - Legacy `expected` / `assertionType: \"count\"` and `notExists` semantics\r\n * are not modeled in IR — the assertion's criteria still survive (as a\r\n * state requiredElement) but the assertion-flavor metadata is dropped.\r\n * - Legacy `testing` block + extra metadata keys outside `component` /\r\n * `tags` are ignored. Authors keep them via the legacy spec file directly\r\n * during Phase A2 — they will move into IR companion files in Phase A4.\r\n * - The forward `notes` argument's appended paragraph is currently kept\r\n * in `description`; Phase A4 will split it back out into a dedicated\r\n * companion file.\r\n *\r\n * @param legacy The legacy spec to invert.\r\n * @param opts Optional doc-level overrides.\r\n */\r\nexport function projectLegacyToIR(\r\n legacy: LegacySpec,\r\n opts?: ProjectLegacyToIROptions,\r\n): IRDocument {\r\n const component =\r\n opts?.docId ??\r\n legacy.metadata?.component ??\r\n opts?.fallbackName ??\r\n \"legacy-spec\";\r\n const name = legacy.metadata?.component ?? opts?.fallbackName ?? component;\r\n\r\n // Index state-machine states by id for quick lookup when building IR states\r\n // out of groups. Older specs may not have a stateMachine block.\r\n const smByGroupId = new Map<string, LegacyStateMachineState>();\r\n if (legacy.stateMachine !== undefined && Array.isArray(legacy.stateMachine.states)) {\r\n for (const s of legacy.stateMachine.states) {\r\n smByGroupId.set(s.id, s);\r\n }\r\n }\r\n\r\n const groups = Array.isArray(legacy.groups) ? legacy.groups : [];\r\n const states: IRState[] = groups.map((group) =>\r\n buildIRState(group, smByGroupId.get(group.id)),\r\n );\r\n\r\n // NOTE: Some legacy specs declare `stateMachine.states[]` whose ids do NOT\r\n // correspond to any `groups[]` entry (e.g., page-level states like\r\n // `wrappers-installed-tab` vs assertion-category groups like\r\n // `page-structure`). The IR's group-state mapping is 1:1 with groups by\r\n // construction (the forward projection emits one group per IR state), so\r\n // these orphan SM states cannot survive the round-trip cleanly. They are\r\n // dropped here as a documented loss — Phase A4 will revisit by either\r\n // (a) introducing a separate IR concept for \"page state\" vs\r\n // \"assertion group\", or (b) hand-merging the legacy specs so groups and\r\n // SM states share ids.\r\n // Transitions originating from orphan SM states are likewise omitted from\r\n // IR (their fromStates would dangle). We filter them below.\r\n const groupIds = new Set(groups.map((g) => g.id));\r\n\r\n // Build transitions only from SM states whose ids appear in groups[]. Any\r\n // transition with a fromState that isn't a known group is dropped — the\r\n // forward direction would have nowhere to emit it.\r\n let filteredStateMachine: LegacyStateMachine | undefined = legacy.stateMachine;\r\n if (\r\n legacy.stateMachine !== undefined &&\r\n Array.isArray(legacy.stateMachine.states) &&\r\n legacy.stateMachine.states.some((s) => !groupIds.has(s.id))\r\n ) {\r\n filteredStateMachine = {\r\n states: legacy.stateMachine.states.filter((s) => groupIds.has(s.id)),\r\n };\r\n }\r\n const transitions = buildIRTransitions(filteredStateMachine);\r\n\r\n // Initial state: first state with isInitial:true wins (mirrors how the\r\n // forward direction picks the document's `initialState`). Only consider\r\n // SM states that correspond to a group (so initialState references a real\r\n // IR state).\r\n let initialState: string | undefined;\r\n if (legacy.stateMachine !== undefined && Array.isArray(legacy.stateMachine.states)) {\r\n const initial = legacy.stateMachine.states.find(\r\n (s) => s.isInitial === true && groupIds.has(s.id),\r\n );\r\n if (initial !== undefined) initialState = initial.id;\r\n }\r\n\r\n const doc: IRDocument = {\r\n version: \"1.0\",\r\n id: component,\r\n name,\r\n states,\r\n transitions,\r\n provenance: { source: \"migrated\" },\r\n };\r\n if (legacy.description !== undefined && legacy.description.length > 0) {\r\n doc.description = legacy.description;\r\n }\r\n if (legacy.metadata !== undefined && legacy.metadata.tags !== undefined) {\r\n doc.metadata = { tags: legacy.metadata.tags };\r\n }\r\n if (initialState !== undefined) {\r\n doc.initialState = initialState;\r\n }\r\n return doc;\r\n}\r\n"],"mappings":";AA4GA,IAAM,wBAAwB,oBAAI,IAAY,CAAC,KAAK,CAAC;AAO9C,SAAS,aAAa,OAA8B;AACzD,QAAM,MAAoB;AAAA,IACxB,IAAI,MAAM;AAAA,IACV,MAAM,MAAM;AAAA,IACZ,kBAAkB,MAAM;AAAA,EAC1B;AACA,MAAI,MAAM,gBAAgB,OAAW,KAAI,cAAc,MAAM;AAC7D,MAAI,MAAM,qBAAqB,OAAW,KAAI,mBAAmB,MAAM;AACvE,MAAI,MAAM,eAAe,OAAW,KAAI,aAAa,MAAM;AAC3D,MAAI,MAAM,cAAc,OAAW,KAAI,YAAY,MAAM;AACzD,MAAI,MAAM,eAAe,OAAW,KAAI,aAAa,MAAM;AAC3D,MAAI,MAAM,aAAa,OAAW,KAAI,WAAW,MAAM;AACvD,MAAI,MAAM,UAAU,OAAW,KAAI,QAAQ,MAAM;AACjD,MAAI,MAAM,aAAa,OAAW,KAAI,WAAW,MAAM;AACvD,SAAO;AACT;AAMA,IAAM,qBAAqB,oBAAI,IAA8B;AAAA,EAC3D;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAED,SAAS,iBAAiB,MAAgD;AACxE,MAAI,CAAC,mBAAmB,IAAI,KAAK,IAAgC,GAAG;AAGlE,WAAO;AAAA,EACT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,OAAO,KAAK,CAAC,MAAM,CAAC,SAAS,IAAI,EAAE,EAAE,CAAC,GAC1D;AACA,2BAAuB;AAAA,MACrB,QAAQ,OAAO,aAAa,OAAO,OAAO,CAAC,MAAM,SAAS,IAAI,EAAE,EAAE,CAAC;AAAA,IACrE;AAAA,EACF;AACA,QAAM,cAAc,mBAAmB,oBAAoB;AAM3D,MAAI;AACJ,MAAI,OAAO,iBAAiB,UAAa,MAAM,QAAQ,OAAO,aAAa,MAAM,GAAG;AAClF,UAAM,UAAU,OAAO,aAAa,OAAO;AAAA,MACzC,CAAC,MAAM,EAAE,cAAc,QAAQ,SAAS,IAAI,EAAE,EAAE;AAAA,IAClD;AACA,QAAI,YAAY,OAAW,gBAAe,QAAQ;AAAA,EACpD;AAEA,QAAM,MAAkB;AAAA,IACtB,SAAS;AAAA,IACT,IAAI;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA,YAAY,EAAE,QAAQ,WAAW;AAAA,EACnC;AACA,MAAI,OAAO,gBAAgB,UAAa,OAAO,YAAY,SAAS,GAAG;AACrE,QAAI,cAAc,OAAO;AAAA,EAC3B;AACA,MAAI,OAAO,aAAa,UAAa,OAAO,SAAS,SAAS,QAAW;AACvE,QAAI,WAAW,EAAE,MAAM,OAAO,SAAS,KAAK;AAAA,EAC9C;AACA,MAAI,iBAAiB,QAAW;AAC9B,QAAI,eAAe;AAAA,EACrB;AACA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../src/ui-bridge-ir/adapter.ts","../src/ui-bridge-ir/projection.ts"],"sourcesContent":["/**\n * IR -> WorkflowConfig adapter.\n *\n * Single point of translation between authoring-time IR (with provenance,\n * metadata, effect, crossRefs, visualRefs) and the runtime/storage shape\n * that ui-bridge-auto consumes. See ADR-001 (decision #6 / #7) for the\n * boundary rationale.\n *\n * The output is intentionally typed structurally — this module has no\n * runtime dependency on ui-bridge-auto. ui-bridge-auto's own tests verify\n * end-to-end compatibility with `engine.defineStates(...)` /\n * `engine.defineTransitions(...)` (see\n * `ui-bridge-auto/src/__tests__/spike-ir-contract.test.ts`).\n */\n\nimport type { IRElementCriteria } from \"./element-criteria\";\nimport type { IRDocument } from \"./document\";\nimport type { IRState, IRStateCondition } from \"./state\";\nimport type { IRTransition, IRTransitionAction, IRWaitSpec } from \"./transition\";\n\n// ---------------------------------------------------------------------------\n// Output shapes — structural mirrors of ui-bridge-auto's WorkflowConfig.\n// Kept in sync via ui-bridge-auto's regression test, NOT compile-time\n// imports (qontinui-schemas has no runtime deps by design).\n// ---------------------------------------------------------------------------\n\n/** Mirrors `StateConfig` from ui-bridge-auto/src/config/workflow.ts:47. */\nexport interface AdaptedState {\n id: string;\n name: string;\n description?: string;\n requiredElements: IRElementCriteria[];\n excludedElements?: IRElementCriteria[];\n conditions?: IRStateCondition[];\n isInitial?: boolean;\n isTerminal?: boolean;\n blocking?: boolean;\n group?: string;\n pathCost?: number;\n}\n\n/**\n * Mirrors the runtime `TransitionDefinition` shape from\n * ui-bridge-auto/src/state/state-machine.ts:40.\n *\n * Note: ui-bridge-auto has two related Transition shapes — the storage shape\n * (`TransitionConfig` in config/workflow.ts:54, with action field named\n * `type`) and the runtime engine shape (`TransitionDefinition` in\n * state-machine.ts:40, with action field named `action`). The runtime engine\n * is what consumers actually pass adapter output into via\n * `engine.defineTransitions(...)`, so the adapter targets the runtime shape.\n */\nexport interface AdaptedTransition {\n id: string;\n name: string;\n description?: string;\n fromStates: string[];\n activateStates: string[];\n /** Adapter normalizes IR's optional `exitStates` to a required array. */\n exitStates: string[];\n actions: AdaptedTransitionAction[];\n pathCost?: number;\n bidirectional?: boolean;\n}\n\n/**\n * Mirrors the runtime `TransitionAction` from\n * ui-bridge-auto/src/state/state-machine.ts:55.\n *\n * The IR uses `type` for the action verb (matching the storage-shape\n * convention); the adapter renames it to `action` for the runtime engine.\n *\n * `waitAfter` is narrower than `IRWaitSpec` — the runtime engine accepts\n * only a subset of wait types and a subset of fields. The adapter drops\n * IR-only wait variants (e.g., `state`, `condition`) and IR-only fields\n * (e.g., `property`, `quietPeriodMs`). Authors can still express richer\n * waits in the IR; they just don't survive the runtime contract.\n */\nexport interface AdaptedWaitAfter {\n type: \"idle\" | \"element\" | \"time\" | \"vanish\" | \"change\" | \"stable\";\n query?: IRElementCriteria;\n ms?: number;\n timeout?: number;\n}\n\nexport interface AdaptedTransitionAction {\n /** Action verb — renamed from IR's `type` to match the runtime contract. */\n action: string;\n target: IRElementCriteria;\n params?: Record<string, unknown>;\n waitAfter?: AdaptedWaitAfter;\n}\n\n/** Mirrors `WorkflowConfig` from ui-bridge-auto/src/config/workflow.ts:67. */\nexport interface AdaptedWorkflowConfig {\n id: string;\n name: string;\n description?: string;\n version?: string;\n states: AdaptedState[];\n transitions: AdaptedTransition[];\n initialState?: string;\n}\n\n// ---------------------------------------------------------------------------\n// Adapter implementation\n// ---------------------------------------------------------------------------\n\nconst SUPPORTED_IR_VERSIONS = new Set<string>([\"1.0\"]);\n\n/**\n * Convert an IR state declaration into the runtime/storage state shape.\n * Strips IR-only fields (metadata, provenance, elementIds,\n * incomingTransitions, crossRefs, visualRefs).\n */\nexport function adaptIRState(state: IRState): AdaptedState {\n // Project rich IR assertions down to the runtime's flat element-criteria\n // list. The runtime engine (ui-bridge-auto's WorkflowConfig.StateConfig)\n // doesn't carry per-element severity/category — those metadata fields stay\n // IR-side, consumed by Spec-Check policies.\n const out: AdaptedState = {\n id: state.id,\n name: state.name,\n requiredElements: state.assertions.map(\n (a) => a.target.criteria as unknown as IRElementCriteria,\n ),\n };\n if (state.description !== undefined) out.description = state.description;\n if (state.excludedElements !== undefined) out.excludedElements = state.excludedElements;\n if (state.conditions !== undefined) out.conditions = state.conditions;\n if (state.isInitial !== undefined) out.isInitial = state.isInitial;\n if (state.isTerminal !== undefined) out.isTerminal = state.isTerminal;\n if (state.blocking !== undefined) out.blocking = state.blocking;\n if (state.group !== undefined) out.group = state.group;\n if (state.pathCost !== undefined) out.pathCost = state.pathCost;\n return out;\n}\n\n/**\n * Wait types the runtime engine accepts. IR-authored waits with other types\n * (e.g., `state`, `condition`) are dropped from the adapter output.\n */\nconst RUNTIME_WAIT_TYPES = new Set<AdaptedWaitAfter[\"type\"]>([\n \"idle\",\n \"element\",\n \"time\",\n \"vanish\",\n \"change\",\n \"stable\",\n]);\n\nfunction adaptIRWaitAfter(wait: IRWaitSpec): AdaptedWaitAfter | undefined {\n if (!RUNTIME_WAIT_TYPES.has(wait.type as AdaptedWaitAfter[\"type\"])) {\n // IR-authored wait is richer than runtime supports — drop it.\n // Runtime defaults (default idle behaviour) take over.\n return undefined;\n }\n const out: AdaptedWaitAfter = { type: wait.type as AdaptedWaitAfter[\"type\"] };\n if (wait.query !== undefined) out.query = wait.query;\n if (wait.ms !== undefined) out.ms = wait.ms;\n if (wait.timeout !== undefined) out.timeout = wait.timeout;\n return out;\n}\n\n/**\n * Convert an IR transition action into the runtime action shape.\n * Renames IR's `type` to runtime's `action`; narrows `waitAfter` to the\n * runtime-accepted subset.\n */\nexport function adaptIRTransitionAction(action: IRTransitionAction): AdaptedTransitionAction {\n const out: AdaptedTransitionAction = {\n action: action.type,\n target: action.target,\n };\n if (action.params !== undefined) out.params = action.params;\n if (action.waitAfter !== undefined) {\n const adaptedWait = adaptIRWaitAfter(action.waitAfter);\n if (adaptedWait !== undefined) out.waitAfter = adaptedWait;\n }\n return out;\n}\n\n/**\n * Convert an IR transition declaration into the runtime/storage transition\n * shape. Strips IR-only fields (effect, metadata, provenance, crossRefs)\n * and defaults `exitStates` to `[]` when omitted.\n */\nexport function adaptIRTransition(transition: IRTransition): AdaptedTransition {\n const out: AdaptedTransition = {\n id: transition.id,\n name: transition.name,\n fromStates: transition.fromStates,\n activateStates: transition.activateStates,\n exitStates: transition.exitStates ?? [],\n actions: transition.actions.map(adaptIRTransitionAction),\n };\n if (transition.description !== undefined) out.description = transition.description;\n if (transition.pathCost !== undefined) out.pathCost = transition.pathCost;\n if (transition.bidirectional !== undefined) out.bidirectional = transition.bidirectional;\n return out;\n}\n\n/**\n * Convert a top-level IR document into the runtime `WorkflowConfig` shape.\n *\n * Throws on unknown IR versions to fail loudly rather than silently emit\n * stale shapes.\n */\nexport function adaptIRDocumentToWorkflowConfig(doc: IRDocument): AdaptedWorkflowConfig {\n if (!SUPPORTED_IR_VERSIONS.has(doc.version)) {\n throw new Error(\n `adaptIRDocumentToWorkflowConfig: unsupported IR version \"${doc.version}\". ` +\n `Supported: ${Array.from(SUPPORTED_IR_VERSIONS).join(\", \")}`,\n );\n }\n\n const out: AdaptedWorkflowConfig = {\n id: doc.id,\n name: doc.name,\n states: doc.states.map(adaptIRState),\n transitions: doc.transitions.map(adaptIRTransition),\n };\n if (doc.description !== undefined) out.description = doc.description;\n if (doc.initialState !== undefined) out.initialState = doc.initialState;\n return out;\n}\n","/**\n * IR -> Bundled-Page Legacy Spec projection.\n *\n * Single point of translation between authoring-time IR (`IRDocument`) and the\n * legacy `*.spec.uibridge.json` shape that existing tooling still consumes\n * (`/update-spec`, runner spec drift / verify, error monitor curator,\n * spec experimentation, AI session). See ADR-001 (decision #6 / #7) for the\n * boundary rationale; section 2 of the UI Bridge redesign for the projection's\n * role in keeping legacy consumers working through the migration.\n *\n * The projection is a PURE FUNCTION — same input always produces byte-identical\n * output. Keys within objects are sorted lexicographically, arrays preserve\n * input order, and no timestamps / random IDs are introduced. Downstream tests\n * may hash the JSON output for byte-stable assertions.\n *\n * ---------------------------------------------------------------------------\n * Mapping rules (worked example below)\n * ---------------------------------------------------------------------------\n *\n * IRDocument LegacySpec\n * ---------- ----------\n * doc.id -> metadata.component\n * doc.metadata?.purpose ?? doc.id -> metadata.component (purpose wins if present)\n * doc.description ?? doc.name -> description\n * doc.metadata?.tags -> metadata.tags\n *\n * For each IRState:\n * state -> one entry in groups[]\n * state.id -> group.id\n * state.name -> group.name\n * state.description ??\n * state.metadata?.description -> group.description\n * \"element-presence\" -> group.category (default)\n * state.provenance?.source ??\n * \"ai-generated\" -> group.source\n *\n * For each requiredElement of state:\n * (state, criteria, index) -> one assertion in group.assertions[]\n * \"${state.id}-elem-${index}\" -> assertion.id\n * state.metadata?.description ?? -> assertion.description\n * \"Required element ${index} ...\"\n * \"element-presence\" -> assertion.category\n * \"critical\" -> assertion.severity\n * \"exists\" -> assertion.assertionType\n * {\n * type: \"search\",\n * criteria: convert(criteria), -> assertion.target\n * label: \"Required element ...\"\n * }\n * \"ai-generated\" -> assertion.source\n * false -> assertion.reviewed\n * true -> assertion.enabled\n *\n * If state has zero requiredElements, the projected `group.assertions[]`\n * is the empty array — legacy specs ship architecture-only groups with\n * empty assertions, and the inverse projection's identity round-trip\n * depends on preserving that emptiness. (Earlier versions emitted a\n * placeholder assertion here, which silently grew the assertion count\n * during round-trip and tripped `check-spec-pairing`.)\n *\n * Each IRState -> one entry in stateMachine.states[]\n * state.id -> sm-state.id\n * state.name -> sm-state.name\n * state.description ?? \"\" -> sm-state.description\n * state.requiredElements (converted) -> sm-state.elements\n * state.isInitial ??\n * (state.id === doc.initialState) -> sm-state.isInitial\n * transitions originating from state -> sm-state.transitions\n *\n * For each IRTransition:\n * For each fromState in transition.fromStates:\n * transition -> one entry in\n * stateMachine.states[fromState].transitions[]\n * transition.id -> sm-transition.id\n * transition.name -> sm-transition.name\n * transition.activateStates -> sm-transition.activateStates\n * transition.exitStates ?? [] -> sm-transition.deactivateStates\n * (exitStates.length === 0) -> sm-transition.staysVisible\n *\n * For each action in transition.actions:\n * action.type -> process[].action (rename type -> action)\n * action.target -> process[].target (criteria converted)\n * action.waitAfter -> process[].waitAfter (passed through)\n *\n * Element-criteria conversion (IRElementCriteria -> legacy criteria):\n * text -> textContent\n * ariaLabel -> accessibleName\n * attributes -> dataAttributes\n * (others — role, textContains, id — pass through unchanged)\n *\n * ---------------------------------------------------------------------------\n * Worked example\n * ---------------------------------------------------------------------------\n *\n * const ir: IRDocument = {\n * version: \"1.0\",\n * id: \"active\",\n * name: \"Active Dashboard\",\n * description: \"Real-time monitoring hub\",\n * metadata: { tags: [\"monitoring\", \"tier-1\"] },\n * states: [\n * {\n * id: \"running\",\n * name: \"Running\",\n * description: \"Workflow executing\",\n * requiredElements: [{ role: \"button\", text: \"Stop\" }],\n * isInitial: false,\n * },\n * ],\n * transitions: [\n * {\n * id: \"running-to-idle\",\n * name: \"Stop\",\n * fromStates: [\"running\"],\n * activateStates: [\"idle\"],\n * exitStates: [\"running\"],\n * actions: [\n * {\n * type: \"click\",\n * target: { role: \"button\", text: \"Stop\" },\n * waitAfter: { type: \"idle\", timeout: 3000 },\n * },\n * ],\n * },\n * ],\n * initialState: \"idle\",\n * };\n *\n * projectIRToBundledPage(ir, \"Notes from author\")\n * // -> {\n * // version: \"1.0.0\",\n * // description: \"Real-time monitoring hub\\n\\nNotes from author\",\n * // groups: [{\n * // id: \"running\",\n * // name: \"Running\",\n * // description: \"Workflow executing\",\n * // category: \"element-presence\",\n * // assertions: [{\n * // id: \"running-elem-0\",\n * // description: \"Required element 0 for state Running\",\n * // category: \"element-presence\",\n * // severity: \"critical\",\n * // assertionType: \"exists\",\n * // target: {\n * // type: \"search\",\n * // criteria: { role: \"button\", textContent: \"Stop\" },\n * // label: \"Required element for Running\",\n * // },\n * // source: \"ai-generated\",\n * // reviewed: false,\n * // enabled: true,\n * // }],\n * // source: \"ai-generated\",\n * // }],\n * // stateMachine: {\n * // states: [{\n * // id: \"running\",\n * // name: \"Running\",\n * // description: \"Workflow executing\",\n * // elements: [{ role: \"button\", textContent: \"Stop\" }],\n * // isInitial: false,\n * // transitions: [{\n * // id: \"running-to-idle\",\n * // name: \"Stop\",\n * // activateStates: [\"idle\"],\n * // deactivateStates: [\"running\"],\n * // staysVisible: false,\n * // process: [{\n * // action: \"click\",\n * // target: { role: \"button\", textContent: \"Stop\" },\n * // waitAfter: { type: \"idle\", timeout: 3000 },\n * // }],\n * // }],\n * // }],\n * // },\n * // metadata: { component: \"active\", tags: [\"monitoring\", \"tier-1\"] },\n * // }\n */\n\nimport type { IRElementCriteria } from \"./element-criteria\";\nimport type { IRDocument } from \"./document\";\nimport type { IRAssertion, IRGroup } from \"./group\";\nimport type { IRState } from \"./state\";\nimport type { IRTransition, IRTransitionAction, IRWaitSpec } from \"./transition\";\n\n/**\n * Projection version. Bump on shape changes that consumers must adapt to.\n * Independent from `IRVersion` because the legacy spec shape and the IR shape\n * evolve on different cadences.\n */\nexport const projectionVersion = \"1.0\";\n\n// ---------------------------------------------------------------------------\n// Legacy spec shapes — derived from active.spec.uibridge.json (the reference\n// the projection's output must structurally match).\n// ---------------------------------------------------------------------------\n\n/**\n * Legacy element-criteria shape (after conversion from `IRElementCriteria`).\n *\n * The differences from `IRElementCriteria`:\n * - `text` -> `textContent`\n * - `ariaLabel` -> `accessibleName` (when IR has no explicit `accessibleName`)\n * - `attributes` -> `dataAttributes`\n *\n * Other fields (`role`, `tagName`, `textContains`, `accessibleName`, `id`)\n * pass through unchanged. Index signature stays open for legacy fields the\n * IR doesn't yet model.\n */\nexport interface LegacyCriteria {\n role?: string;\n tagName?: string;\n textContent?: string;\n textContains?: string;\n accessibleName?: string;\n id?: string;\n dataAttributes?: Record<string, string>;\n [key: string]: unknown;\n}\n\n/**\n * Legacy assertion target. Always `type: \"search\"` for the projection — the\n * legacy schema also supports point/region targets, but the IR doesn't\n * express those.\n */\nexport interface LegacyAssertionTarget {\n type: \"search\";\n criteria: LegacyCriteria;\n label: string;\n}\n\n/**\n * Legacy assertion. Mirrors the shape used by `groups[].assertions[]` in\n * `*.spec.uibridge.json`.\n */\nexport interface LegacyAssertion {\n id: string;\n description: string;\n category: string;\n severity: \"critical\" | \"warning\" | \"info\";\n assertionType: string;\n target: LegacyAssertionTarget;\n source: string;\n reviewed: boolean;\n enabled: boolean;\n precondition?: string;\n}\n\n/**\n * Legacy group. One per IR state.\n */\nexport interface LegacyGroup {\n id: string;\n name: string;\n description: string;\n category: string;\n assertions: LegacyAssertion[];\n source: string;\n}\n\n/**\n * Process step within a transition. Note `action` (not `type`) — matches the\n * runtime engine's `TransitionAction` shape.\n */\nexport interface LegacyProcessStep {\n action: string;\n target: LegacyCriteria;\n waitAfter?: IRWaitSpec;\n}\n\n/**\n * Legacy state-machine transition.\n */\nexport interface LegacyTransition {\n id: string;\n name: string;\n activateStates: string[];\n deactivateStates: string[];\n staysVisible: boolean;\n process: LegacyProcessStep[];\n}\n\n/**\n * Legacy state-machine state.\n */\nexport interface LegacyStateMachineState {\n id: string;\n name: string;\n description: string;\n elements: LegacyCriteria[];\n isInitial: boolean;\n transitions: LegacyTransition[];\n}\n\n/**\n * Legacy state-machine block.\n */\nexport interface LegacyStateMachine {\n states: LegacyStateMachineState[];\n}\n\n/**\n * Legacy spec metadata block. The projection writes a deterministic subset;\n * downstream tooling may layer additional keys on hand-authored specs.\n */\nexport interface LegacyMetadata {\n component: string;\n tags?: string[];\n [key: string]: unknown;\n}\n\n/**\n * Top-level legacy spec shape.\n */\nexport interface LegacySpec {\n version: string;\n description: string;\n groups: LegacyGroup[];\n stateMachine: LegacyStateMachine;\n metadata: LegacyMetadata;\n}\n\n// ---------------------------------------------------------------------------\n// Internal helpers\n// ---------------------------------------------------------------------------\n\n/**\n * Recursively sort object keys lexicographically. Arrays preserve input order\n * (ordering is meaningful for groups / assertions / transitions).\n *\n * Used as the final stage of every projected output to guarantee byte-stable\n * JSON serialization downstream.\n */\nfunction sortKeys<T>(value: T): T {\n if (Array.isArray(value)) {\n return value.map(sortKeys) as unknown as T;\n }\n if (value !== null && typeof value === \"object\") {\n const sorted: Record<string, unknown> = {};\n const keys = Object.keys(value as Record<string, unknown>).sort();\n for (const key of keys) {\n sorted[key] = sortKeys((value as Record<string, unknown>)[key]);\n }\n return sorted as unknown as T;\n }\n return value;\n}\n\n/**\n * Convert IR element criteria to legacy criteria. Renames `text` ->\n * `textContent`, `attributes` -> `dataAttributes`. `accessibleName` (or\n * `ariaLabel` as a fallback) maps to legacy `accessibleName`. `tagName`,\n * `role`, `textContains`, `id` pass through unchanged.\n */\nfunction convertCriteria(criteria: IRElementCriteria): LegacyCriteria {\n const out: LegacyCriteria = {};\n if (criteria.role !== undefined) out.role = criteria.role;\n if (criteria.tagName !== undefined) out.tagName = criteria.tagName;\n if (criteria.text !== undefined) out.textContent = criteria.text;\n if (criteria.textContains !== undefined) out.textContains = criteria.textContains;\n // Prefer explicit `accessibleName` when present; fall back to `ariaLabel`\n // for IR documents authored against the section-1 shape.\n if (criteria.accessibleName !== undefined) {\n out.accessibleName = criteria.accessibleName;\n } else if (criteria.ariaLabel !== undefined) {\n out.accessibleName = criteria.ariaLabel;\n }\n if (criteria.id !== undefined) out.id = criteria.id;\n if (criteria.attributes !== undefined) out.dataAttributes = criteria.attributes;\n return out;\n}\n\n/**\n * Build the legacy `groups[]` entry for one IR state. With IrState.assertions\n * carrying first-class assertion metadata (id/description/severity/category/\n * target), this is now a direct shape-conversion per assertion — no more\n * synthesizing IDs or defaulting severity.\n */\nfunction buildGroup(state: IRState): LegacyGroup {\n const assertions: LegacyAssertion[] = state.assertions.map(synthesizedAssertionToLegacy);\n return {\n id: state.id,\n name: state.name,\n description: state.description ?? state.metadata?.description ?? \"\",\n category: \"element-presence\",\n assertions,\n source: state.provenance?.source ?? \"ai-generated\",\n };\n}\n\n/**\n * Convert an `IRAssertion` (IR-side, free-form criteria) into a `LegacyAssertion`.\n * The shapes are near-identical; the only meaningful difference is that the\n * IR-side `target.criteria` is `Record<string, unknown>` while the legacy\n * shape is `LegacyCriteria` (a typed but extensible record). We pass the\n * criteria object through verbatim — the open `[key: string]: unknown` index\n * signature on `LegacyCriteria` accepts any record shape.\n */\nfunction synthesizedAssertionToLegacy(assertion: IRAssertion): LegacyAssertion {\n const target: LegacyAssertionTarget = {\n type: \"search\",\n criteria: assertion.target.criteria as LegacyCriteria,\n label: assertion.target.label,\n };\n const out: LegacyAssertion = {\n id: assertion.id,\n description: assertion.description,\n category: assertion.category,\n severity: assertion.severity as LegacyAssertion[\"severity\"],\n assertionType: assertion.assertionType,\n target,\n source: assertion.source,\n reviewed: assertion.reviewed,\n enabled: assertion.enabled,\n };\n if (assertion.precondition !== undefined) {\n out.precondition = assertion.precondition;\n }\n return out;\n}\n\n/**\n * Convert a synthesized `IRGroup` into a `LegacyGroup`. Mirrors the legacy\n * shape one-to-one (modulo the free-form criteria pass-through described in\n * `synthesizedAssertionToLegacy`). The synthesized group always carries a\n * `source` (synthesis emits `\"ai-generated\"`); fall back to `\"ai-generated\"`\n * for hand-written IR documents that omit it.\n */\nfunction synthesizedGroupToLegacy(group: IRGroup): LegacyGroup {\n return {\n id: group.id,\n name: group.name,\n description: group.description,\n category: group.category,\n assertions: group.assertions.map(synthesizedAssertionToLegacy),\n source: group.source ?? \"ai-generated\",\n };\n}\n\n/**\n * Convert an IR transition action into the legacy `process[]` step shape.\n * Renames IR's `type` to legacy `action` (matches the runtime engine\n * convention — same as the IR -> WorkflowConfig adapter does for runtime).\n */\nfunction buildProcessStep(action: IRTransitionAction): LegacyProcessStep {\n const out: LegacyProcessStep = {\n action: action.type,\n target: convertCriteria(action.target),\n };\n if (action.waitAfter !== undefined) out.waitAfter = action.waitAfter;\n return out;\n}\n\n/**\n * Convert one IR transition into the legacy state-machine transition shape.\n * Each fromState gets its own copy in the projected output (legacy specs put\n * the transition under each originating state's `transitions[]`).\n */\nfunction buildTransition(transition: IRTransition): LegacyTransition {\n const exitStates = transition.exitStates ?? [];\n return {\n id: transition.id,\n name: transition.name,\n activateStates: transition.activateStates,\n deactivateStates: exitStates,\n // Modal-style transitions (no exit states) stay visible behind the\n // activated state. Otherwise the originating state(s) deactivate, so the\n // page no longer shows them.\n staysVisible: exitStates.length === 0,\n process: transition.actions.map(buildProcessStep),\n };\n}\n\n/**\n * Build the legacy `stateMachine.states[]` entry for one IR state. Includes\n * any transitions that originate from this state (i.e. where state.id is in\n * transition.fromStates).\n */\nfunction buildStateMachineState(\n state: IRState,\n transitions: IRTransition[],\n doc: IRDocument,\n): LegacyStateMachineState {\n const outgoing = transitions\n .filter((t) => t.fromStates.includes(state.id))\n .map(buildTransition);\n const isInitial =\n state.isInitial !== undefined ? state.isInitial : state.id === doc.initialState;\n return {\n id: state.id,\n name: state.name,\n description: state.description ?? \"\",\n // Project legacy `elements[]` from each assertion's target.criteria.\n elements: state.assertions.map((a) =>\n convertCriteria(a.target.criteria as IRElementCriteria),\n ),\n isInitial,\n transitions: outgoing,\n };\n}\n\n// ---------------------------------------------------------------------------\n// Public entry point\n// ---------------------------------------------------------------------------\n\n/**\n * Project an IR document into the legacy bundled-page spec shape.\n *\n * Pure / deterministic: same input always produces structurally identical\n * output (and byte-identical when JSON-serialized via the standard\n * `JSON.stringify` ordering). Arrays preserve input order; object keys are\n * sorted lexicographically.\n *\n * @param doc The IR document to project.\n * @param notes Optional human-authored notes (carried in the page's\n * `notes.md` companion file). Appended to `description` as a\n * separate paragraph (separator: two newlines).\n */\nexport function projectIRToBundledPage(doc: IRDocument, notes?: string): LegacySpec {\n const baseDescription = doc.description ?? doc.name;\n const description =\n notes !== undefined && notes.length > 0\n ? `${baseDescription}\\n\\n${notes}`\n : baseDescription;\n\n const component = doc.metadata?.purpose ?? doc.id;\n const metadata: LegacyMetadata = { component };\n if (doc.metadata?.tags !== undefined) metadata.tags = doc.metadata.tags;\n\n const groups: LegacyGroup[] = doc.states.map(buildGroup);\n if (doc.synthesizedGroups !== undefined) {\n // Append synthesis-produced groups AFTER state-derived ones, in declared\n // order. Byte-stable output (see file header) requires this exact ordering\n // — anything else breaks `check-spec-pairing` style hashes.\n for (const g of doc.synthesizedGroups) {\n groups.push(synthesizedGroupToLegacy(g));\n }\n }\n const smStates: LegacyStateMachineState[] = doc.states.map((s) =>\n buildStateMachineState(s, doc.transitions, doc),\n );\n\n const spec: LegacySpec = {\n version: \"1.0.0\",\n description,\n groups,\n stateMachine: { states: smStates },\n metadata,\n };\n\n return sortKeys(spec);\n}\n\n// ---------------------------------------------------------------------------\n// Inverse projection — Legacy spec -> IR document\n// ---------------------------------------------------------------------------\n\n/**\n * Options for the inverse projection.\n *\n * - `docId` — explicit IRDocument.id override. Falls back to\n * `legacy.metadata.component` (or `fallbackName` if absent).\n * - `fallbackName` — used when `legacy.metadata.component` is missing AND no\n * `docId` was supplied.\n */\nexport interface ProjectLegacyToIROptions {\n docId?: string;\n fallbackName?: string;\n}\n\n/**\n * Best-effort field-by-field invert of `LegacyCriteria` back into\n * `IRElementCriteria`.\n *\n * Rename map (the structural inverse of `convertCriteria`):\n * textContent -> text\n * accessibleName -> accessibleName (passes through; the forward direction\n * collapses ariaLabel into accessibleName,\n * so we cannot reliably distinguish them\n * on the inverse — pick accessibleName).\n * dataAttributes -> attributes\n * role / tagName / textContains / id pass through unchanged.\n *\n * Unknown legacy keys are dropped (lossy, but documented). Document-level\n * unknown criteria are rare; if they show up we'll surface them in Phase A4.\n */\nfunction invertCriteria(criteria: LegacyCriteria | undefined): IRElementCriteria {\n if (criteria === undefined || criteria === null) return {};\n const out: IRElementCriteria = {};\n if (criteria.role !== undefined) out.role = criteria.role;\n if (criteria.tagName !== undefined) out.tagName = criteria.tagName;\n if (criteria.textContent !== undefined) out.text = criteria.textContent;\n if (criteria.textContains !== undefined) out.textContains = criteria.textContains;\n if (criteria.accessibleName !== undefined) out.accessibleName = criteria.accessibleName;\n if (criteria.id !== undefined) out.id = criteria.id;\n if (criteria.dataAttributes !== undefined) out.attributes = criteria.dataAttributes;\n return out;\n}\n\n/**\n * Pick the first non-empty `precondition` across a group's assertions. Legacy\n * groups carry preconditions on individual assertions; IR carries it on the\n * state. If multiple distinct preconditions exist we keep the first\n * (deterministic, mirrors input ordering) — Phase A4 review will surface\n * conflicts for hand-fix.\n */\nfunction firstPrecondition(group: LegacyGroup): string | undefined {\n for (const a of group.assertions) {\n if (a.precondition !== undefined && a.precondition.length > 0) {\n return a.precondition;\n }\n }\n return undefined;\n}\n\n/**\n * Build an `IRState` from one legacy group + its corresponding state-machine\n * state (when present).\n *\n * IMPORTANT: `requiredElements` is sourced from the GROUP's assertion criteria\n * (one criteria per assertion, in input order), NOT from `smState.elements`.\n * This preserves the round-trip identity for the assertion-count check —\n * legacy specs sometimes carry an SM block whose `elements[]` is a coarse\n * page-state fingerprint (1-2 entries) while the group has many assertions.\n * Using `smState.elements` would silently collapse those into one\n * requiredElement per state, then the forward direction would emit only one\n * assertion per group.\n *\n * `smState` (when present and matched by id) contributes:\n * - `name` override (legacy `smState.name` is human-readable; group.name is\n * also human-readable but may differ — prefer smState's name since the\n * forward direction's `buildStateMachineState` echoes `state.name` to\n * `smState.name`).\n * - `description` fallback (when group.description is empty).\n * - `isInitial` (the only place this lives in legacy specs).\n */\nfunction buildIRState(\n group: LegacyGroup,\n smState: LegacyStateMachineState | undefined,\n): IRState {\n // Map each LegacyAssertion to an IRAssertion, preserving id/description/\n // severity/category. target.criteria is normalized via invertCriteria so\n // the criteria shape matches what the IR side stores.\n const assertions: IRAssertion[] = group.assertions.map((a) => {\n const ir: IRAssertion = {\n id: a.id,\n description: a.description,\n category: a.category,\n severity: a.severity,\n assertionType: a.assertionType,\n target: {\n type: \"search\",\n criteria: invertCriteria(a.target?.criteria) as unknown as Record<string, unknown>,\n label: a.target?.label ?? a.description,\n },\n source: a.source,\n reviewed: a.reviewed,\n enabled: a.enabled,\n };\n if (a.precondition !== undefined) {\n ir.precondition = a.precondition;\n }\n return ir;\n });\n\n const description =\n group.description !== undefined && group.description.length > 0\n ? group.description\n : smState?.description;\n const precondition = firstPrecondition(group);\n\n const state: IRState = {\n id: group.id,\n name: smState?.name ?? group.name,\n assertions,\n };\n if (description !== undefined && description.length > 0) {\n state.description = description;\n }\n if (smState?.isInitial === true) {\n state.isInitial = true;\n } else if (smState?.isInitial === false) {\n state.isInitial = false;\n }\n if (precondition !== undefined) {\n state.precondition = precondition;\n }\n state.provenance = { source: \"migrated\" };\n return state;\n}\n\n/**\n * Convert one legacy `process[]` step back into `IRTransitionAction`. Renames\n * `action` -> `type`. Legacy specs occasionally omit a target on no-op steps;\n * we coerce to an empty criteria object in that case.\n */\nfunction invertProcessStep(step: LegacyProcessStep): IRTransitionAction {\n const out: IRTransitionAction = {\n type: step.action,\n target: invertCriteria(step.target),\n };\n if (step.waitAfter !== undefined) out.waitAfter = step.waitAfter;\n return out;\n}\n\n/**\n * Collapse duplicate transitions across multiple originating states. The\n * forward projection emits the same transition under EACH `fromState`'s\n * `transitions[]` entry; the inverse must merge them back into ONE\n * `IRTransition` whose `fromStates` lists every originator.\n *\n * Same-id transitions are assumed to be byte-identical except for the\n * (implicit) originating state. If they differ in `process[]` /\n * `activateStates` / `deactivateStates`, we keep the first occurrence and\n * append the additional fromState. (Genuine divergence here is a defect to\n * surface in Phase A4 review.)\n */\nfunction buildIRTransitions(stateMachine: LegacyStateMachine | undefined): IRTransition[] {\n if (stateMachine === undefined || !Array.isArray(stateMachine.states)) return [];\n const byId = new Map<string, IRTransition>();\n // Preserve insertion order — first state's transitions come first.\n const order: string[] = [];\n\n for (const smState of stateMachine.states) {\n const transitions = Array.isArray(smState.transitions) ? smState.transitions : [];\n for (const t of transitions) {\n const existing = byId.get(t.id);\n if (existing !== undefined) {\n if (!existing.fromStates.includes(smState.id)) {\n existing.fromStates.push(smState.id);\n }\n continue;\n }\n const ir: IRTransition = {\n id: t.id,\n name: t.name,\n fromStates: [smState.id],\n activateStates: Array.isArray(t.activateStates) ? [...t.activateStates] : [],\n actions: Array.isArray(t.process) ? t.process.map(invertProcessStep) : [],\n };\n // The forward direction maps `exitStates` -> `deactivateStates`; preserve\n // the field whenever it's present in legacy form (even if empty array)\n // so modal-style transitions (staysVisible: true, deactivateStates: [])\n // round-trip predictably.\n if (Array.isArray(t.deactivateStates)) {\n ir.exitStates = [...t.deactivateStates];\n }\n ir.provenance = { source: \"migrated\" };\n byId.set(t.id, ir);\n order.push(t.id);\n }\n }\n\n return order.map((id) => byId.get(id)!);\n}\n\n/**\n * Project a legacy bundled-page spec back into IR.\n *\n * Pure / deterministic: same input always produces structurally identical\n * output. Collapses transition duplicates (forward emits one copy per\n * `fromState`), preserves group/assertion ordering, and tags every node with\n * `provenance.source = \"migrated\"` so downstream tooling can distinguish\n * migrated content from hand-authored.\n *\n * The mapping is the structural inverse of `projectIRToBundledPage`:\n *\n * LegacySpec IRDocument\n * ---------- ----------\n * metadata.component -> id (or opts.docId override)\n * metadata.tags -> metadata.tags\n * description -> description (kept verbatim;\n * authored notes appended via\n * forward `notes` arg are not\n * stripped — that round-trip is\n * best-effort and Phase A4 will\n * split them back out)\n *\n * groups[] -> states[] (one per group)\n * group.id / name / description -> state.id / name / description\n * assertion.target.criteria -> state.requiredElements[i] (or,\n * preferred, smState.elements when\n * the stateMachine block is present)\n * first-found assertion.precondition -> state.precondition\n *\n * stateMachine.states[] -> contributes isInitial + elements\n * smState.transitions[] -> transitions[] (deduped by id)\n * transition.activateStates -> transition.activateStates\n * transition.deactivateStates -> transition.exitStates\n * transition.process[] -> transition.actions[]\n * step.action -> action.type\n * step.target -> action.target (criteria inverted)\n * step.waitAfter -> action.waitAfter\n *\n * Documented losses (acceptable for Phase A2):\n * - Legacy assertion ids (`{stateId}-elem-{i}`) are NOT preserved across the\n * round-trip — the forward direction regenerates them from index, so any\n * hand-edited ids are lost. See Phase A4.\n * - Legacy `assertionType` / `severity` / `category` / `source` per\n * assertion are reduced to defaults on round-trip.\n * - Legacy `expected` / `assertionType: \"count\"` and `notExists` semantics\n * are not modeled in IR — the assertion's criteria still survive (as a\n * state requiredElement) but the assertion-flavor metadata is dropped.\n * - Legacy `testing` block + extra metadata keys outside `component` /\n * `tags` are ignored. Authors keep them via the legacy spec file directly\n * during Phase A2 — they will move into IR companion files in Phase A4.\n * - The forward `notes` argument's appended paragraph is currently kept\n * in `description`; Phase A4 will split it back out into a dedicated\n * companion file.\n *\n * @param legacy The legacy spec to invert.\n * @param opts Optional doc-level overrides.\n */\nexport function projectLegacyToIR(\n legacy: LegacySpec,\n opts?: ProjectLegacyToIROptions,\n): IRDocument {\n const component =\n opts?.docId ??\n legacy.metadata?.component ??\n opts?.fallbackName ??\n \"legacy-spec\";\n const name = legacy.metadata?.component ?? opts?.fallbackName ?? component;\n\n // Index state-machine states by id for quick lookup when building IR states\n // out of groups. Older specs may not have a stateMachine block.\n const smByGroupId = new Map<string, LegacyStateMachineState>();\n if (legacy.stateMachine !== undefined && Array.isArray(legacy.stateMachine.states)) {\n for (const s of legacy.stateMachine.states) {\n smByGroupId.set(s.id, s);\n }\n }\n\n const groups = Array.isArray(legacy.groups) ? legacy.groups : [];\n const states: IRState[] = groups.map((group) =>\n buildIRState(group, smByGroupId.get(group.id)),\n );\n\n // NOTE: Some legacy specs declare `stateMachine.states[]` whose ids do NOT\n // correspond to any `groups[]` entry (e.g., page-level states like\n // `wrappers-installed-tab` vs assertion-category groups like\n // `page-structure`). The IR's group-state mapping is 1:1 with groups by\n // construction (the forward projection emits one group per IR state), so\n // these orphan SM states cannot survive the round-trip cleanly. They are\n // dropped here as a documented loss — Phase A4 will revisit by either\n // (a) introducing a separate IR concept for \"page state\" vs\n // \"assertion group\", or (b) hand-merging the legacy specs so groups and\n // SM states share ids.\n // Transitions originating from orphan SM states are likewise omitted from\n // IR (their fromStates would dangle). We filter them below.\n const groupIds = new Set(groups.map((g) => g.id));\n\n // Build transitions only from SM states whose ids appear in groups[]. Any\n // transition with a fromState that isn't a known group is dropped — the\n // forward direction would have nowhere to emit it.\n let filteredStateMachine: LegacyStateMachine | undefined = legacy.stateMachine;\n if (\n legacy.stateMachine !== undefined &&\n Array.isArray(legacy.stateMachine.states) &&\n legacy.stateMachine.states.some((s) => !groupIds.has(s.id))\n ) {\n filteredStateMachine = {\n states: legacy.stateMachine.states.filter((s) => groupIds.has(s.id)),\n };\n }\n const transitions = buildIRTransitions(filteredStateMachine);\n\n // Initial state: first state with isInitial:true wins (mirrors how the\n // forward direction picks the document's `initialState`). Only consider\n // SM states that correspond to a group (so initialState references a real\n // IR state).\n let initialState: string | undefined;\n if (legacy.stateMachine !== undefined && Array.isArray(legacy.stateMachine.states)) {\n const initial = legacy.stateMachine.states.find(\n (s) => s.isInitial === true && groupIds.has(s.id),\n );\n if (initial !== undefined) initialState = initial.id;\n }\n\n const doc: IRDocument = {\n version: \"1.0\",\n id: component,\n name,\n states,\n transitions,\n provenance: { source: \"migrated\" },\n };\n if (legacy.description !== undefined && legacy.description.length > 0) {\n doc.description = legacy.description;\n }\n if (legacy.metadata !== undefined && legacy.metadata.tags !== undefined) {\n doc.metadata = { tags: legacy.metadata.tags };\n }\n if (initialState !== undefined) {\n doc.initialState = initialState;\n }\n return doc;\n}\n"],"mappings":";AA4GA,IAAM,wBAAwB,oBAAI,IAAY,CAAC,KAAK,CAAC;AAO9C,SAAS,aAAa,OAA8B;AAKzD,QAAM,MAAoB;AAAA,IACxB,IAAI,MAAM;AAAA,IACV,MAAM,MAAM;AAAA,IACZ,kBAAkB,MAAM,WAAW;AAAA,MACjC,CAAC,MAAM,EAAE,OAAO;AAAA,IAClB;AAAA,EACF;AACA,MAAI,MAAM,gBAAgB,OAAW,KAAI,cAAc,MAAM;AAC7D,MAAI,MAAM,qBAAqB,OAAW,KAAI,mBAAmB,MAAM;AACvE,MAAI,MAAM,eAAe,OAAW,KAAI,aAAa,MAAM;AAC3D,MAAI,MAAM,cAAc,OAAW,KAAI,YAAY,MAAM;AACzD,MAAI,MAAM,eAAe,OAAW,KAAI,aAAa,MAAM;AAC3D,MAAI,MAAM,aAAa,OAAW,KAAI,WAAW,MAAM;AACvD,MAAI,MAAM,UAAU,OAAW,KAAI,QAAQ,MAAM;AACjD,MAAI,MAAM,aAAa,OAAW,KAAI,WAAW,MAAM;AACvD,SAAO;AACT;AAMA,IAAM,qBAAqB,oBAAI,IAA8B;AAAA,EAC3D;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAED,SAAS,iBAAiB,MAAgD;AACxE,MAAI,CAAC,mBAAmB,IAAI,KAAK,IAAgC,GAAG;AAGlE,WAAO;AAAA,EACT;AACA,QAAM,MAAwB,EAAE,MAAM,KAAK,KAAiC;AAC5E,MAAI,KAAK,UAAU,OAAW,KAAI,QAAQ,KAAK;AAC/C,M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