create-principles-disciple 1.93.0 → 1.95.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 (526) hide show
  1. package/console/dist/server/config/WorkspaceConfigStore.js +2 -1
  2. package/console/dist/server/config/pd-config-store.d.ts +40 -1
  3. package/console/dist/server/config/pd-config-store.js +170 -1
  4. package/console/dist/server/index.js +28 -10
  5. package/console/dist/server/models/ApprovalsConsoleModel.js +4 -12
  6. package/console/dist/server/models/EvidenceChainConsoleModel.d.ts +0 -2
  7. package/console/dist/server/models/EvidenceChainConsoleModel.js +36 -2
  8. package/console/dist/server/models/HealthCheckModel.js +5 -3
  9. package/console/dist/server/models/IntentDecisionModel.d.ts +66 -0
  10. package/console/dist/server/models/IntentDecisionModel.js +207 -0
  11. package/console/dist/server/models/IntentPageModel.d.ts +18 -0
  12. package/console/dist/server/models/IntentPageModel.js +90 -0
  13. package/console/dist/server/models/PrinciplesConsoleModel.d.ts +2 -0
  14. package/console/dist/server/models/PrinciplesConsoleModel.js +37 -1
  15. package/console/dist/server/models/WorkspaceService.d.ts +0 -28
  16. package/console/dist/server/models/WorkspaceService.js +0 -115
  17. package/console/dist/server/routes/config.js +55 -1
  18. package/console/dist/server/routes/feedback-reports.js +1 -1
  19. package/console/dist/server/routes/intent-decisions.d.ts +33 -0
  20. package/console/dist/server/routes/intent-decisions.js +499 -0
  21. package/console/dist/server/routes/intent.d.ts +3 -0
  22. package/console/dist/server/routes/intent.js +35 -0
  23. package/console/dist/server/routes/principles.js +67 -1
  24. package/console/dist/server/routes/update.d.ts +0 -1
  25. package/console/dist/server/routes/update.js +14 -11
  26. package/console/dist/ui/App.js +2 -7
  27. package/console/dist/ui/api.d.ts +44 -18
  28. package/console/dist/ui/api.js +44 -5
  29. package/console/dist/ui/components/layout/app-sidebar.js +2 -1
  30. package/console/dist/ui/components/ui/badge.d.ts +1 -1
  31. package/console/dist/ui/components/ui/button.d.ts +1 -1
  32. package/console/dist/ui/components/ui/shiny-text.d.ts +28 -0
  33. package/console/dist/ui/components/ui/shiny-text.js +46 -0
  34. package/console/dist/ui/i18n/en.json +167 -3
  35. package/console/dist/ui/i18n/zh-CN.json +167 -3
  36. package/console/dist/ui/pages/activation/ActivationPage.js +2 -1
  37. package/console/dist/ui/pages/control-center/ControlCenterPage.js +28 -2
  38. package/console/dist/ui/pages/control-center/EmpathyObserverCostHint.d.ts +28 -0
  39. package/console/dist/ui/pages/control-center/EmpathyObserverCostHint.js +38 -0
  40. package/console/dist/ui/pages/debt/DebtPage.js +219 -2
  41. package/console/dist/ui/pages/focus/FocusPage.js +2 -1
  42. package/console/dist/ui/pages/intent/IntentPage.d.ts +1 -0
  43. package/console/dist/ui/pages/intent/IntentPage.js +147 -0
  44. package/console/dist/ui/pages/pain/PainPage.js +234 -4
  45. package/console/dist/ui/pages/pain/pain-card-helpers.d.ts +75 -0
  46. package/console/dist/ui/pages/pain/pain-card-helpers.js +78 -0
  47. package/console/dist/ui/pages/principles/PrinciplesPage.js +2 -1
  48. package/console/dist/ui/utils/validators.d.ts +163 -0
  49. package/console/dist/ui/utils/validators.js +433 -0
  50. package/console/dist/web/assets/app.css +138 -0
  51. package/console/dist/web/assets/app.js +3124 -1288
  52. package/console/package.json +3 -0
  53. package/core/dist/index.d.ts +2 -2
  54. package/core/dist/index.d.ts.map +1 -1
  55. package/core/dist/index.js +1 -1
  56. package/core/dist/index.js.map +1 -1
  57. package/core/dist/principle-tree-ledger.d.ts +55 -4
  58. package/core/dist/principle-tree-ledger.d.ts.map +1 -1
  59. package/core/dist/principle-tree-ledger.js +472 -13
  60. package/core/dist/principle-tree-ledger.js.map +1 -1
  61. package/core/dist/prompt-builder/__tests__/model-config.test.d.ts +2 -0
  62. package/core/dist/prompt-builder/__tests__/model-config.test.d.ts.map +1 -0
  63. package/core/dist/prompt-builder/__tests__/model-config.test.js +158 -0
  64. package/core/dist/prompt-builder/__tests__/model-config.test.js.map +1 -0
  65. package/core/dist/prompt-builder/__tests__/prompt-builder-core.test.js +58 -0
  66. package/core/dist/prompt-builder/__tests__/prompt-builder-core.test.js.map +1 -1
  67. package/core/dist/prompt-builder/__tests__/xml-escape.test.d.ts +2 -0
  68. package/core/dist/prompt-builder/__tests__/xml-escape.test.d.ts.map +1 -0
  69. package/core/dist/prompt-builder/__tests__/xml-escape.test.js +42 -0
  70. package/core/dist/prompt-builder/__tests__/xml-escape.test.js.map +1 -0
  71. package/core/dist/prompt-builder/empathy-keyword-matching.d.ts.map +1 -1
  72. package/core/dist/prompt-builder/empathy-keyword-matching.js +9 -6
  73. package/core/dist/prompt-builder/empathy-keyword-matching.js.map +1 -1
  74. package/core/dist/prompt-builder/index.d.ts +3 -0
  75. package/core/dist/prompt-builder/index.d.ts.map +1 -1
  76. package/core/dist/prompt-builder/index.js +2 -0
  77. package/core/dist/prompt-builder/index.js.map +1 -1
  78. package/core/dist/prompt-builder/model-config.d.ts +42 -0
  79. package/core/dist/prompt-builder/model-config.d.ts.map +1 -0
  80. package/core/dist/prompt-builder/model-config.js +84 -0
  81. package/core/dist/prompt-builder/model-config.js.map +1 -0
  82. package/core/dist/prompt-builder/size-guard.d.ts +1 -0
  83. package/core/dist/prompt-builder/size-guard.d.ts.map +1 -1
  84. package/core/dist/prompt-builder/size-guard.js +21 -0
  85. package/core/dist/prompt-builder/size-guard.js.map +1 -1
  86. package/core/dist/prompt-builder/types.d.ts +2 -0
  87. package/core/dist/prompt-builder/types.d.ts.map +1 -1
  88. package/core/dist/prompt-builder/xml-escape.d.ts +12 -0
  89. package/core/dist/prompt-builder/xml-escape.d.ts.map +1 -0
  90. package/core/dist/prompt-builder/xml-escape.js +19 -0
  91. package/core/dist/prompt-builder/xml-escape.js.map +1 -0
  92. package/core/dist/runtime-v2/__tests__/architecture-regression.test.js +205 -48
  93. package/core/dist/runtime-v2/__tests__/architecture-regression.test.js.map +1 -1
  94. package/core/dist/runtime-v2/__tests__/evidence-chain-intent-tension.test.d.ts +2 -0
  95. package/core/dist/runtime-v2/__tests__/evidence-chain-intent-tension.test.d.ts.map +1 -0
  96. package/core/dist/runtime-v2/__tests__/evidence-chain-intent-tension.test.js +284 -0
  97. package/core/dist/runtime-v2/__tests__/evidence-chain-intent-tension.test.js.map +1 -0
  98. package/core/dist/runtime-v2/__tests__/pain-signal-bridge-result-shaping.test.d.ts +2 -0
  99. package/core/dist/runtime-v2/__tests__/pain-signal-bridge-result-shaping.test.d.ts.map +1 -0
  100. package/core/dist/runtime-v2/__tests__/pain-signal-bridge-result-shaping.test.js +500 -0
  101. package/core/dist/runtime-v2/__tests__/pain-signal-bridge-result-shaping.test.js.map +1 -0
  102. package/core/dist/runtime-v2/__tests__/pain-signal-observability.test.js +7 -5
  103. package/core/dist/runtime-v2/__tests__/pain-signal-observability.test.js.map +1 -1
  104. package/core/dist/runtime-v2/__tests__/pi-artifact-store.test.js +11 -0
  105. package/core/dist/runtime-v2/__tests__/pi-artifact-store.test.js.map +1 -1
  106. package/core/dist/runtime-v2/__tests__/proven-channel-baseline.test.js +15 -2
  107. package/core/dist/runtime-v2/__tests__/proven-channel-baseline.test.js.map +1 -1
  108. package/core/dist/runtime-v2/__tests__/schema-float-precision.test.d.ts +2 -0
  109. package/core/dist/runtime-v2/__tests__/schema-float-precision.test.d.ts.map +1 -0
  110. package/core/dist/runtime-v2/__tests__/schema-float-precision.test.js +290 -0
  111. package/core/dist/runtime-v2/__tests__/schema-float-precision.test.js.map +1 -0
  112. package/core/dist/runtime-v2/__tests__/schema-orphan-detection.test.d.ts +2 -0
  113. package/core/dist/runtime-v2/__tests__/schema-orphan-detection.test.d.ts.map +1 -0
  114. package/core/dist/runtime-v2/__tests__/schema-orphan-detection.test.js +158 -0
  115. package/core/dist/runtime-v2/__tests__/schema-orphan-detection.test.js.map +1 -0
  116. package/core/dist/runtime-v2/activation/__tests__/approval-store-extended.test.js +15 -1
  117. package/core/dist/runtime-v2/activation/__tests__/approval-store-extended.test.js.map +1 -1
  118. package/core/dist/runtime-v2/activation/__tests__/sqlite-activation-state-store-fk.test.d.ts +2 -0
  119. package/core/dist/runtime-v2/activation/__tests__/sqlite-activation-state-store-fk.test.d.ts.map +1 -0
  120. package/core/dist/runtime-v2/activation/__tests__/sqlite-activation-state-store-fk.test.js +62 -0
  121. package/core/dist/runtime-v2/activation/__tests__/sqlite-activation-state-store-fk.test.js.map +1 -0
  122. package/core/dist/runtime-v2/activation/__tests__/sqlite-activation-state-store.test.js +12 -2
  123. package/core/dist/runtime-v2/activation/__tests__/sqlite-activation-state-store.test.js.map +1 -1
  124. package/core/dist/runtime-v2/activation/__tests__/sqlite-approval-store-fk.test.d.ts +2 -0
  125. package/core/dist/runtime-v2/activation/__tests__/sqlite-approval-store-fk.test.d.ts.map +1 -0
  126. package/core/dist/runtime-v2/activation/__tests__/sqlite-approval-store-fk.test.js +56 -0
  127. package/core/dist/runtime-v2/activation/__tests__/sqlite-approval-store-fk.test.js.map +1 -0
  128. package/core/dist/runtime-v2/activation/__tests__/sqlite-approval-store.test.js +8 -0
  129. package/core/dist/runtime-v2/activation/__tests__/sqlite-approval-store.test.js.map +1 -1
  130. package/core/dist/runtime-v2/activation/__tests__/story-a-acceptance.test.js +20 -0
  131. package/core/dist/runtime-v2/activation/__tests__/story-a-acceptance.test.js.map +1 -1
  132. package/core/dist/runtime-v2/activation/sqlite-activation-state-store.d.ts.map +1 -1
  133. package/core/dist/runtime-v2/activation/sqlite-activation-state-store.js +6 -0
  134. package/core/dist/runtime-v2/activation/sqlite-activation-state-store.js.map +1 -1
  135. package/core/dist/runtime-v2/activation/sqlite-approval-store.d.ts.map +1 -1
  136. package/core/dist/runtime-v2/activation/sqlite-approval-store.js +86 -32
  137. package/core/dist/runtime-v2/activation/sqlite-approval-store.js.map +1 -1
  138. package/core/dist/runtime-v2/activation/writers/__tests__/rule-host-writer.test.js +65 -1
  139. package/core/dist/runtime-v2/activation/writers/__tests__/rule-host-writer.test.js.map +1 -1
  140. package/core/dist/runtime-v2/activation/writers/rule-host-writer.d.ts.map +1 -1
  141. package/core/dist/runtime-v2/activation/writers/rule-host-writer.js +33 -11
  142. package/core/dist/runtime-v2/activation/writers/rule-host-writer.js.map +1 -1
  143. package/core/dist/runtime-v2/bridge-result-shaper.d.ts +53 -0
  144. package/core/dist/runtime-v2/bridge-result-shaper.d.ts.map +1 -0
  145. package/core/dist/runtime-v2/bridge-result-shaper.js +117 -0
  146. package/core/dist/runtime-v2/bridge-result-shaper.js.map +1 -0
  147. package/core/dist/runtime-v2/detection/__tests__/detection-funnel-policy.test.d.ts +13 -0
  148. package/core/dist/runtime-v2/detection/__tests__/detection-funnel-policy.test.d.ts.map +1 -0
  149. package/core/dist/runtime-v2/detection/__tests__/detection-funnel-policy.test.js +111 -0
  150. package/core/dist/runtime-v2/detection/__tests__/detection-funnel-policy.test.js.map +1 -0
  151. package/core/dist/runtime-v2/detection/detection-funnel-policy.d.ts +103 -0
  152. package/core/dist/runtime-v2/detection/detection-funnel-policy.d.ts.map +1 -0
  153. package/core/dist/runtime-v2/detection/detection-funnel-policy.js +135 -0
  154. package/core/dist/runtime-v2/detection/detection-funnel-policy.js.map +1 -0
  155. package/core/dist/runtime-v2/detection/index.d.ts +10 -0
  156. package/core/dist/runtime-v2/detection/index.d.ts.map +1 -0
  157. package/core/dist/runtime-v2/detection/index.js +9 -0
  158. package/core/dist/runtime-v2/detection/index.js.map +1 -0
  159. package/core/dist/runtime-v2/diagnostician/__tests__/diag-rootcause-output.test.js +134 -15
  160. package/core/dist/runtime-v2/diagnostician/__tests__/diag-rootcause-output.test.js.map +1 -1
  161. package/core/dist/runtime-v2/diagnostician/__tests__/intent-tension-schema.test.d.ts +18 -0
  162. package/core/dist/runtime-v2/diagnostician/__tests__/intent-tension-schema.test.d.ts.map +1 -0
  163. package/core/dist/runtime-v2/diagnostician/__tests__/intent-tension-schema.test.js +251 -0
  164. package/core/dist/runtime-v2/diagnostician/__tests__/intent-tension-schema.test.js.map +1 -0
  165. package/core/dist/runtime-v2/diagnostician/__tests__/rootcause-prompt-builder.test.js +73 -0
  166. package/core/dist/runtime-v2/diagnostician/__tests__/rootcause-prompt-builder.test.js.map +1 -1
  167. package/core/dist/runtime-v2/diagnostician/diag-rootcause-output.d.ts +98 -0
  168. package/core/dist/runtime-v2/diagnostician/diag-rootcause-output.d.ts.map +1 -1
  169. package/core/dist/runtime-v2/diagnostician/diag-rootcause-output.js +131 -0
  170. package/core/dist/runtime-v2/diagnostician/diag-rootcause-output.js.map +1 -1
  171. package/core/dist/runtime-v2/diagnostician/rootcause-prompt-builder.d.ts +8 -0
  172. package/core/dist/runtime-v2/diagnostician/rootcause-prompt-builder.d.ts.map +1 -1
  173. package/core/dist/runtime-v2/diagnostician/rootcause-prompt-builder.js +66 -3
  174. package/core/dist/runtime-v2/diagnostician/rootcause-prompt-builder.js.map +1 -1
  175. package/core/dist/runtime-v2/diagnostician-output.d.ts +23 -0
  176. package/core/dist/runtime-v2/diagnostician-output.d.ts.map +1 -1
  177. package/core/dist/runtime-v2/diagnostician-output.js +16 -0
  178. package/core/dist/runtime-v2/diagnostician-output.js.map +1 -1
  179. package/core/dist/runtime-v2/diagnostician-prompt-builder.d.ts +32 -0
  180. package/core/dist/runtime-v2/diagnostician-prompt-builder.d.ts.map +1 -1
  181. package/core/dist/runtime-v2/diagnostician-prompt-builder.js.map +1 -1
  182. package/core/dist/runtime-v2/evidence-triage/__tests__/observation-resolver.test.d.ts +12 -0
  183. package/core/dist/runtime-v2/evidence-triage/__tests__/observation-resolver.test.d.ts.map +1 -0
  184. package/core/dist/runtime-v2/evidence-triage/__tests__/observation-resolver.test.js +181 -0
  185. package/core/dist/runtime-v2/evidence-triage/__tests__/observation-resolver.test.js.map +1 -0
  186. package/core/dist/runtime-v2/evidence-triage/__tests__/triage-policy.test.js +104 -1
  187. package/core/dist/runtime-v2/evidence-triage/__tests__/triage-policy.test.js.map +1 -1
  188. package/core/dist/runtime-v2/evidence-triage/index.d.ts +3 -0
  189. package/core/dist/runtime-v2/evidence-triage/index.d.ts.map +1 -1
  190. package/core/dist/runtime-v2/evidence-triage/index.js +3 -0
  191. package/core/dist/runtime-v2/evidence-triage/index.js.map +1 -1
  192. package/core/dist/runtime-v2/evidence-triage/observation-resolver.d.ts +128 -0
  193. package/core/dist/runtime-v2/evidence-triage/observation-resolver.d.ts.map +1 -0
  194. package/core/dist/runtime-v2/evidence-triage/observation-resolver.js +203 -0
  195. package/core/dist/runtime-v2/evidence-triage/observation-resolver.js.map +1 -0
  196. package/core/dist/runtime-v2/evidence-triage/source-descriptors.d.ts +1 -1
  197. package/core/dist/runtime-v2/evidence-triage/source-descriptors.js +1 -1
  198. package/core/dist/runtime-v2/evidence-triage/triage-policy.d.ts +4 -0
  199. package/core/dist/runtime-v2/evidence-triage/triage-policy.d.ts.map +1 -1
  200. package/core/dist/runtime-v2/evidence-triage/triage-policy.js +66 -9
  201. package/core/dist/runtime-v2/evidence-triage/triage-policy.js.map +1 -1
  202. package/core/dist/runtime-v2/evidence-triage/types.d.ts +14 -0
  203. package/core/dist/runtime-v2/evidence-triage/types.d.ts.map +1 -1
  204. package/core/dist/runtime-v2/evidence-triage/types.js.map +1 -1
  205. package/core/dist/runtime-v2/feature-flags/__tests__/feature-flag-contract.test.js +56 -4
  206. package/core/dist/runtime-v2/feature-flags/__tests__/feature-flag-contract.test.js.map +1 -1
  207. package/core/dist/runtime-v2/feature-flags/__tests__/intent-engineering-flag.test.d.ts +2 -0
  208. package/core/dist/runtime-v2/feature-flags/__tests__/intent-engineering-flag.test.d.ts.map +1 -0
  209. package/core/dist/runtime-v2/feature-flags/__tests__/intent-engineering-flag.test.js +30 -0
  210. package/core/dist/runtime-v2/feature-flags/__tests__/intent-engineering-flag.test.js.map +1 -0
  211. package/core/dist/runtime-v2/feature-flags/feature-flag-contract.d.ts.map +1 -1
  212. package/core/dist/runtime-v2/feature-flags/feature-flag-contract.js +11 -2
  213. package/core/dist/runtime-v2/feature-flags/feature-flag-contract.js.map +1 -1
  214. package/core/dist/runtime-v2/feature-flags/plugin-surface-registry.d.ts.map +1 -1
  215. package/core/dist/runtime-v2/feature-flags/plugin-surface-registry.js +0 -9
  216. package/core/dist/runtime-v2/feature-flags/plugin-surface-registry.js.map +1 -1
  217. package/core/dist/runtime-v2/feedback/__tests__/redact-sensitive.test.d.ts +15 -0
  218. package/core/dist/runtime-v2/feedback/__tests__/redact-sensitive.test.d.ts.map +1 -0
  219. package/core/dist/runtime-v2/feedback/__tests__/redact-sensitive.test.js +450 -0
  220. package/core/dist/runtime-v2/feedback/__tests__/redact-sensitive.test.js.map +1 -0
  221. package/core/dist/runtime-v2/feedback/__tests__/render-github-url.test.d.ts +13 -0
  222. package/core/dist/runtime-v2/feedback/__tests__/render-github-url.test.d.ts.map +1 -0
  223. package/core/dist/runtime-v2/feedback/__tests__/render-github-url.test.js +243 -0
  224. package/core/dist/runtime-v2/feedback/__tests__/render-github-url.test.js.map +1 -0
  225. package/core/dist/runtime-v2/feedback/__tests__/safe-stringify.test.d.ts +12 -0
  226. package/core/dist/runtime-v2/feedback/__tests__/safe-stringify.test.d.ts.map +1 -0
  227. package/core/dist/runtime-v2/feedback/__tests__/safe-stringify.test.js +172 -0
  228. package/core/dist/runtime-v2/feedback/__tests__/safe-stringify.test.js.map +1 -0
  229. package/core/dist/runtime-v2/index.d.ts +15 -6
  230. package/core/dist/runtime-v2/index.d.ts.map +1 -1
  231. package/core/dist/runtime-v2/index.js +15 -4
  232. package/core/dist/runtime-v2/index.js.map +1 -1
  233. package/core/dist/runtime-v2/intent/__tests__/intent-decision-record.test.d.ts +2 -0
  234. package/core/dist/runtime-v2/intent/__tests__/intent-decision-record.test.d.ts.map +1 -0
  235. package/core/dist/runtime-v2/intent/__tests__/intent-decision-record.test.js +185 -0
  236. package/core/dist/runtime-v2/intent/__tests__/intent-decision-record.test.js.map +1 -0
  237. package/core/dist/runtime-v2/intent/__tests__/intent-doc.test.d.ts +2 -0
  238. package/core/dist/runtime-v2/intent/__tests__/intent-doc.test.d.ts.map +1 -0
  239. package/core/dist/runtime-v2/intent/__tests__/intent-doc.test.js +91 -0
  240. package/core/dist/runtime-v2/intent/__tests__/intent-doc.test.js.map +1 -0
  241. package/core/dist/runtime-v2/intent/__tests__/intent-friction-block.test.d.ts +2 -0
  242. package/core/dist/runtime-v2/intent/__tests__/intent-friction-block.test.d.ts.map +1 -0
  243. package/core/dist/runtime-v2/intent/__tests__/intent-friction-block.test.js +168 -0
  244. package/core/dist/runtime-v2/intent/__tests__/intent-friction-block.test.js.map +1 -0
  245. package/core/dist/runtime-v2/intent/__tests__/intent-patch-proposal.test.d.ts +2 -0
  246. package/core/dist/runtime-v2/intent/__tests__/intent-patch-proposal.test.d.ts.map +1 -0
  247. package/core/dist/runtime-v2/intent/__tests__/intent-patch-proposal.test.js +121 -0
  248. package/core/dist/runtime-v2/intent/__tests__/intent-patch-proposal.test.js.map +1 -0
  249. package/core/dist/runtime-v2/intent/index.d.ts +6 -0
  250. package/core/dist/runtime-v2/intent/index.d.ts.map +1 -0
  251. package/core/dist/runtime-v2/intent/index.js +6 -0
  252. package/core/dist/runtime-v2/intent/index.js.map +1 -0
  253. package/core/dist/runtime-v2/intent/intent-decision-record.d.ts +125 -0
  254. package/core/dist/runtime-v2/intent/intent-decision-record.d.ts.map +1 -0
  255. package/core/dist/runtime-v2/intent/intent-decision-record.js +21 -0
  256. package/core/dist/runtime-v2/intent/intent-decision-record.js.map +1 -0
  257. package/core/dist/runtime-v2/intent/intent-doc-reader-port.d.ts +95 -0
  258. package/core/dist/runtime-v2/intent/intent-doc-reader-port.d.ts.map +1 -0
  259. package/core/dist/runtime-v2/intent/intent-doc-reader-port.js +43 -0
  260. package/core/dist/runtime-v2/intent/intent-doc-reader-port.js.map +1 -0
  261. package/core/dist/runtime-v2/intent/intent-doc.d.ts +19 -0
  262. package/core/dist/runtime-v2/intent/intent-doc.d.ts.map +1 -0
  263. package/core/dist/runtime-v2/intent/intent-doc.js +70 -0
  264. package/core/dist/runtime-v2/intent/intent-doc.js.map +1 -0
  265. package/core/dist/runtime-v2/intent/intent-friction-block.d.ts +63 -0
  266. package/core/dist/runtime-v2/intent/intent-friction-block.d.ts.map +1 -0
  267. package/core/dist/runtime-v2/intent/intent-friction-block.js +129 -0
  268. package/core/dist/runtime-v2/intent/intent-friction-block.js.map +1 -0
  269. package/core/dist/runtime-v2/intent/intent-patch-proposal.d.ts +42 -0
  270. package/core/dist/runtime-v2/intent/intent-patch-proposal.d.ts.map +1 -0
  271. package/core/dist/runtime-v2/intent/intent-patch-proposal.js +81 -0
  272. package/core/dist/runtime-v2/intent/intent-patch-proposal.js.map +1 -0
  273. package/core/dist/runtime-v2/internalization/__tests__/__fixtures__/intent-tension-cases.d.ts +54 -0
  274. package/core/dist/runtime-v2/internalization/__tests__/__fixtures__/intent-tension-cases.d.ts.map +1 -0
  275. package/core/dist/runtime-v2/internalization/__tests__/__fixtures__/intent-tension-cases.js +219 -0
  276. package/core/dist/runtime-v2/internalization/__tests__/__fixtures__/intent-tension-cases.js.map +1 -0
  277. package/core/dist/runtime-v2/internalization/__tests__/c2-live-runner-chain.test.d.ts +2 -0
  278. package/core/dist/runtime-v2/internalization/__tests__/c2-live-runner-chain.test.d.ts.map +1 -0
  279. package/core/dist/runtime-v2/internalization/__tests__/c2-live-runner-chain.test.js +306 -0
  280. package/core/dist/runtime-v2/internalization/__tests__/c2-live-runner-chain.test.js.map +1 -0
  281. package/core/dist/runtime-v2/internalization/__tests__/diag-rootcause-intent-tension.test.d.ts +2 -0
  282. package/core/dist/runtime-v2/internalization/__tests__/diag-rootcause-intent-tension.test.d.ts.map +1 -0
  283. package/core/dist/runtime-v2/internalization/__tests__/diag-rootcause-intent-tension.test.js +360 -0
  284. package/core/dist/runtime-v2/internalization/__tests__/diag-rootcause-intent-tension.test.js.map +1 -0
  285. package/core/dist/runtime-v2/internalization/__tests__/diag-router-intent-tension.test.d.ts +2 -0
  286. package/core/dist/runtime-v2/internalization/__tests__/diag-router-intent-tension.test.d.ts.map +1 -0
  287. package/core/dist/runtime-v2/internalization/__tests__/diag-router-intent-tension.test.js +333 -0
  288. package/core/dist/runtime-v2/internalization/__tests__/diag-router-intent-tension.test.js.map +1 -0
  289. package/core/dist/runtime-v2/internalization/__tests__/intent-tension-cases.test.d.ts +2 -0
  290. package/core/dist/runtime-v2/internalization/__tests__/intent-tension-cases.test.d.ts.map +1 -0
  291. package/core/dist/runtime-v2/internalization/__tests__/intent-tension-cases.test.js +113 -0
  292. package/core/dist/runtime-v2/internalization/__tests__/intent-tension-cases.test.js.map +1 -0
  293. package/core/dist/runtime-v2/internalization/diag-rootcause-runner.d.ts +13 -0
  294. package/core/dist/runtime-v2/internalization/diag-rootcause-runner.d.ts.map +1 -1
  295. package/core/dist/runtime-v2/internalization/diag-rootcause-runner.js +42 -0
  296. package/core/dist/runtime-v2/internalization/diag-rootcause-runner.js.map +1 -1
  297. package/core/dist/runtime-v2/internalization/diag-router-runner.d.ts.map +1 -1
  298. package/core/dist/runtime-v2/internalization/diag-router-runner.js +27 -0
  299. package/core/dist/runtime-v2/internalization/diag-router-runner.js.map +1 -1
  300. package/core/dist/runtime-v2/internalization/index.d.ts +0 -16
  301. package/core/dist/runtime-v2/internalization/index.d.ts.map +1 -1
  302. package/core/dist/runtime-v2/internalization/index.js +0 -8
  303. package/core/dist/runtime-v2/internalization/index.js.map +1 -1
  304. package/core/dist/runtime-v2/pain-gate/__tests__/pain-diagnostic-gate-policy.test.d.ts +15 -0
  305. package/core/dist/runtime-v2/pain-gate/__tests__/pain-diagnostic-gate-policy.test.d.ts.map +1 -0
  306. package/core/dist/runtime-v2/pain-gate/__tests__/pain-diagnostic-gate-policy.test.js +179 -0
  307. package/core/dist/runtime-v2/pain-gate/__tests__/pain-diagnostic-gate-policy.test.js.map +1 -0
  308. package/core/dist/runtime-v2/pain-gate/index.d.ts +10 -0
  309. package/core/dist/runtime-v2/pain-gate/index.d.ts.map +1 -0
  310. package/core/dist/runtime-v2/pain-gate/index.js +9 -0
  311. package/core/dist/runtime-v2/pain-gate/index.js.map +1 -0
  312. package/core/dist/runtime-v2/pain-gate/pain-diagnostic-gate-policy.d.ts +121 -0
  313. package/core/dist/runtime-v2/pain-gate/pain-diagnostic-gate-policy.d.ts.map +1 -0
  314. package/core/dist/runtime-v2/pain-gate/pain-diagnostic-gate-policy.js +157 -0
  315. package/core/dist/runtime-v2/pain-gate/pain-diagnostic-gate-policy.js.map +1 -0
  316. package/core/dist/runtime-v2/pain-signal-bridge.d.ts.map +1 -1
  317. package/core/dist/runtime-v2/pain-signal-bridge.js +14 -88
  318. package/core/dist/runtime-v2/pain-signal-bridge.js.map +1 -1
  319. package/core/dist/runtime-v2/pain-signal-observability.d.ts.map +1 -1
  320. package/core/dist/runtime-v2/pain-signal-observability.js +272 -61
  321. package/core/dist/runtime-v2/pain-signal-observability.js.map +1 -1
  322. package/core/dist/runtime-v2/pain-signal-runtime-factory.d.ts +12 -0
  323. package/core/dist/runtime-v2/pain-signal-runtime-factory.d.ts.map +1 -1
  324. package/core/dist/runtime-v2/pain-signal-runtime-factory.js +1 -1
  325. package/core/dist/runtime-v2/pain-signal-runtime-factory.js.map +1 -1
  326. package/core/dist/runtime-v2/pain-to-principle-service.d.ts +6 -0
  327. package/core/dist/runtime-v2/pain-to-principle-service.d.ts.map +1 -1
  328. package/core/dist/runtime-v2/pain-to-principle-service.js +2 -0
  329. package/core/dist/runtime-v2/pain-to-principle-service.js.map +1 -1
  330. package/core/dist/runtime-v2/principle-tree/ledger-codec.js.map +1 -1
  331. package/core/dist/runtime-v2/proven-channel-baseline.js +1 -1
  332. package/core/dist/runtime-v2/proven-channel-baseline.js.map +1 -1
  333. package/core/dist/runtime-v2/store/artifact/__tests__/sqlite-pi-artifact-store-fk.test.d.ts +2 -0
  334. package/core/dist/runtime-v2/store/artifact/__tests__/sqlite-pi-artifact-store-fk.test.d.ts.map +1 -0
  335. package/core/dist/runtime-v2/store/artifact/__tests__/sqlite-pi-artifact-store-fk.test.js +55 -0
  336. package/core/dist/runtime-v2/store/artifact/__tests__/sqlite-pi-artifact-store-fk.test.js.map +1 -0
  337. package/core/dist/runtime-v2/store/artifact/sqlite-pi-artifact-store.d.ts.map +1 -1
  338. package/core/dist/runtime-v2/store/artifact/sqlite-pi-artifact-store.js +6 -0
  339. package/core/dist/runtime-v2/store/artifact/sqlite-pi-artifact-store.js.map +1 -1
  340. package/core/dist/runtime-v2/store/intent/__tests__/sqlite-intent-decision-store.test.d.ts +2 -0
  341. package/core/dist/runtime-v2/store/intent/__tests__/sqlite-intent-decision-store.test.d.ts.map +1 -0
  342. package/core/dist/runtime-v2/store/intent/__tests__/sqlite-intent-decision-store.test.js +272 -0
  343. package/core/dist/runtime-v2/store/intent/__tests__/sqlite-intent-decision-store.test.js.map +1 -0
  344. package/core/dist/runtime-v2/store/intent/index.d.ts +6 -0
  345. package/core/dist/runtime-v2/store/intent/index.d.ts.map +1 -0
  346. package/core/dist/runtime-v2/store/intent/index.js +5 -0
  347. package/core/dist/runtime-v2/store/intent/index.js.map +1 -0
  348. package/core/dist/runtime-v2/store/intent/sqlite-intent-decision-store.d.ts +51 -0
  349. package/core/dist/runtime-v2/store/intent/sqlite-intent-decision-store.d.ts.map +1 -0
  350. package/core/dist/runtime-v2/store/intent/sqlite-intent-decision-store.js +306 -0
  351. package/core/dist/runtime-v2/store/intent/sqlite-intent-decision-store.js.map +1 -0
  352. package/core/dist/runtime-v2/store/sqlite-connection-pragma.test.js +14 -3
  353. package/core/dist/runtime-v2/store/sqlite-connection-pragma.test.js.map +1 -1
  354. package/core/dist/runtime-v2/store/sqlite-connection-schema-version.test.d.ts +2 -0
  355. package/core/dist/runtime-v2/store/sqlite-connection-schema-version.test.d.ts.map +1 -0
  356. package/core/dist/runtime-v2/store/sqlite-connection-schema-version.test.js +72 -0
  357. package/core/dist/runtime-v2/store/sqlite-connection-schema-version.test.js.map +1 -0
  358. package/core/dist/runtime-v2/store/sqlite-connection.d.ts +27 -0
  359. package/core/dist/runtime-v2/store/sqlite-connection.d.ts.map +1 -1
  360. package/core/dist/runtime-v2/store/sqlite-connection.js +124 -12
  361. package/core/dist/runtime-v2/store/sqlite-connection.js.map +1 -1
  362. package/core/dist/runtime-v2/types/event-payload.d.ts +1 -20
  363. package/core/dist/runtime-v2/types/event-payload.d.ts.map +1 -1
  364. package/core/dist/runtime-v2/types/event-payload.js +0 -12
  365. package/core/dist/runtime-v2/types/event-payload.js.map +1 -1
  366. package/core/dist/runtime-v2/types/event-types.d.ts +5 -61
  367. package/core/dist/runtime-v2/types/event-types.d.ts.map +1 -1
  368. package/core/dist/runtime-v2/types/event-types.js +2 -36
  369. package/core/dist/runtime-v2/types/event-types.js.map +1 -1
  370. package/core/dist/runtime-v2/types/evidence-chain-contract.d.ts +63 -0
  371. package/core/dist/runtime-v2/types/evidence-chain-contract.d.ts.map +1 -1
  372. package/core/dist/runtime-v2/types/evidence-chain-contract.js +234 -9
  373. package/core/dist/runtime-v2/types/evidence-chain-contract.js.map +1 -1
  374. package/core/dist/runtime-v2/types/index.d.ts +5 -5
  375. package/core/dist/runtime-v2/types/index.d.ts.map +1 -1
  376. package/core/dist/runtime-v2/types/index.js +7 -3
  377. package/core/dist/runtime-v2/types/index.js.map +1 -1
  378. package/core/dist/runtime-v2/types/ledger-store.d.ts +30 -30
  379. package/core/dist/runtime-v2/types/ledger-store.d.ts.map +1 -1
  380. package/core/dist/runtime-v2/types/ledger-store.js +10 -5
  381. package/core/dist/runtime-v2/types/ledger-store.js.map +1 -1
  382. package/core/dist/runtime-v2/types/pain-signal.d.ts +2 -2
  383. package/core/dist/runtime-v2/types/pain-signal.js +2 -2
  384. package/core/dist/workflow-funnel-loader.d.ts +2 -2
  385. package/core/dist/workflow-funnel-loader.d.ts.map +1 -1
  386. package/dist/installer.d.ts.map +1 -1
  387. package/dist/installer.js +16 -0
  388. package/dist/installer.js.map +1 -1
  389. package/dist/mvp-config.d.ts +0 -10
  390. package/dist/mvp-config.d.ts.map +1 -1
  391. package/dist/mvp-config.js +0 -65
  392. package/dist/mvp-config.js.map +1 -1
  393. package/package.json +1 -1
  394. package/pd-cli/dist/commands/__tests__/intent-flag-wiring.test.d.ts +9 -0
  395. package/pd-cli/dist/commands/__tests__/intent-flag-wiring.test.d.ts.map +1 -0
  396. package/pd-cli/dist/commands/__tests__/intent-flag-wiring.test.js +166 -0
  397. package/pd-cli/dist/commands/__tests__/intent-flag-wiring.test.js.map +1 -0
  398. package/pd-cli/dist/commands/intent.d.ts +59 -0
  399. package/pd-cli/dist/commands/intent.d.ts.map +1 -0
  400. package/pd-cli/dist/commands/intent.js +350 -0
  401. package/pd-cli/dist/commands/intent.js.map +1 -0
  402. package/pd-cli/dist/commands/mvp-smoke.js +1 -1
  403. package/pd-cli/dist/commands/mvp-smoke.js.map +1 -1
  404. package/pd-cli/dist/commands/rulecode.js +1 -1
  405. package/pd-cli/dist/commands/rulecode.js.map +1 -1
  406. package/pd-cli/dist/commands/runtime-canary.d.ts.map +1 -1
  407. package/pd-cli/dist/commands/runtime-canary.js +10 -11
  408. package/pd-cli/dist/commands/runtime-canary.js.map +1 -1
  409. package/pd-cli/dist/commands/runtime-init.d.ts +43 -0
  410. package/pd-cli/dist/commands/runtime-init.d.ts.map +1 -0
  411. package/pd-cli/dist/commands/runtime-init.js +264 -0
  412. package/pd-cli/dist/commands/runtime-init.js.map +1 -0
  413. package/pd-cli/dist/commands/runtime-internalization-queue.d.ts.map +1 -1
  414. package/pd-cli/dist/commands/runtime-internalization-queue.js +13 -16
  415. package/pd-cli/dist/commands/runtime-internalization-queue.js.map +1 -1
  416. package/pd-cli/dist/commands/runtime-internalization-run-once.d.ts.map +1 -1
  417. package/pd-cli/dist/commands/runtime-internalization-run-once.js +3 -0
  418. package/pd-cli/dist/commands/runtime-internalization-run-once.js.map +1 -1
  419. package/pd-cli/dist/commands/runtime-internalization-run-rulehost.d.ts.map +1 -1
  420. package/pd-cli/dist/commands/runtime-internalization-run-rulehost.js +61 -7
  421. package/pd-cli/dist/commands/runtime-internalization-run-rulehost.js.map +1 -1
  422. package/pd-cli/dist/commands/runtime.js +1 -1
  423. package/pd-cli/dist/commands/runtime.js.map +1 -1
  424. package/pd-cli/dist/index.js +92 -34
  425. package/pd-cli/dist/index.js.map +1 -1
  426. package/pd-cli/dist/services/__tests__/rulehost-readiness.test.d.ts +2 -0
  427. package/pd-cli/dist/services/__tests__/rulehost-readiness.test.d.ts.map +1 -0
  428. package/pd-cli/dist/services/__tests__/rulehost-readiness.test.js +314 -0
  429. package/pd-cli/dist/services/__tests__/rulehost-readiness.test.js.map +1 -0
  430. package/pd-cli/dist/services/__tests__/runtime-adapter-resolver.test.js +20 -12
  431. package/pd-cli/dist/services/__tests__/runtime-adapter-resolver.test.js.map +1 -1
  432. package/pd-cli/dist/services/demo-story-a-runner.d.ts.map +1 -1
  433. package/pd-cli/dist/services/demo-story-a-runner.js +6 -0
  434. package/pd-cli/dist/services/demo-story-a-runner.js.map +1 -1
  435. package/pd-cli/dist/services/rulehost-readiness.d.ts +62 -0
  436. package/pd-cli/dist/services/rulehost-readiness.d.ts.map +1 -0
  437. package/pd-cli/dist/services/rulehost-readiness.js +214 -0
  438. package/pd-cli/dist/services/rulehost-readiness.js.map +1 -0
  439. package/pd-cli/dist/services/runtime-adapter-resolver.d.ts +1 -1
  440. package/pd-cli/dist/services/runtime-adapter-resolver.js +3 -3
  441. package/pd-cli/dist/services/runtime-adapter-resolver.js.map +1 -1
  442. package/pd-cli/package.json +1 -0
  443. package/plugin/dist/commands/evolution-status.js +0 -2
  444. package/plugin/dist/commands/pain.js +2 -0
  445. package/plugin/dist/core/control-ui-db.d.ts +11 -0
  446. package/plugin/dist/core/control-ui-db.js +40 -16
  447. package/plugin/dist/core/detection-funnel.d.ts +25 -11
  448. package/plugin/dist/core/detection-funnel.js +32 -80
  449. package/plugin/dist/core/event-log.d.ts +1 -3
  450. package/plugin/dist/core/event-log.js +5 -21
  451. package/plugin/dist/core/evolution-reducer.d.ts +0 -8
  452. package/plugin/dist/core/evolution-reducer.js +9 -19
  453. package/plugin/dist/core/intent-doc-reader-adapter.d.ts +28 -0
  454. package/plugin/dist/core/intent-doc-reader-adapter.js +56 -0
  455. package/plugin/dist/core/intent-doc-reader.d.ts +80 -0
  456. package/plugin/dist/core/intent-doc-reader.js +189 -0
  457. package/plugin/dist/core/pain-diagnostic-gate.d.ts +37 -28
  458. package/plugin/dist/core/pain-diagnostic-gate.js +53 -89
  459. package/plugin/dist/core/pain.d.ts +0 -63
  460. package/plugin/dist/core/pain.js +0 -167
  461. package/plugin/dist/core/paths.d.ts +0 -1
  462. package/plugin/dist/core/paths.js +2 -1
  463. package/plugin/dist/core/principle-tree-ledger.d.ts +27 -79
  464. package/plugin/dist/core/principle-tree-ledger.js +39 -524
  465. package/plugin/dist/core/reflection/reflection-context.d.ts +2 -2
  466. package/plugin/dist/core/schema/migrations/001-init-trajectory.js +3 -6
  467. package/plugin/dist/core/schema/schema-definitions.js +4 -9
  468. package/plugin/dist/core/trajectory.d.ts +16 -16
  469. package/plugin/dist/core/trajectory.js +338 -311
  470. package/plugin/dist/core/workspace-context.d.ts +2 -3
  471. package/plugin/dist/hooks/after-tool-call-helpers.d.ts +4 -1
  472. package/plugin/dist/hooks/after-tool-call-helpers.js +13 -17
  473. package/plugin/dist/hooks/gate-block-helper.js +57 -17
  474. package/plugin/dist/hooks/lifecycle.js +3 -6
  475. package/plugin/dist/hooks/llm.js +66 -26
  476. package/plugin/dist/hooks/pain.d.ts +3 -1
  477. package/plugin/dist/hooks/pain.js +124 -49
  478. package/plugin/dist/hooks/prompt-helpers.d.ts +105 -0
  479. package/plugin/dist/hooks/prompt-helpers.js +288 -0
  480. package/plugin/dist/hooks/prompt-types.d.ts +74 -0
  481. package/plugin/dist/hooks/prompt-types.js +12 -0
  482. package/plugin/dist/hooks/prompt.d.ts +7 -38
  483. package/plugin/dist/hooks/prompt.js +433 -338
  484. package/plugin/dist/hooks/raw-observation-adapter.d.ts +9 -50
  485. package/plugin/dist/hooks/raw-observation-adapter.js +9 -164
  486. package/plugin/dist/hooks/raw-observation-types.d.ts +6 -57
  487. package/plugin/dist/hooks/raw-observation-types.js +5 -9
  488. package/plugin/dist/hooks/triage-adapter.js +6 -26
  489. package/plugin/dist/hooks/trigger-cooldown-tracker.d.ts +12 -0
  490. package/plugin/dist/hooks/trigger-cooldown-tracker.js +25 -0
  491. package/plugin/dist/index.d.ts +3 -1
  492. package/plugin/dist/index.js +9 -5
  493. package/plugin/dist/service/evolution-worker.js +6 -64
  494. package/plugin/dist/service/runtime-summary-service.d.ts +0 -2
  495. package/plugin/dist/service/runtime-summary-service.js +1 -5
  496. package/plugin/dist/service/subagent-workflow/workflow-store.d.ts +14 -0
  497. package/plugin/dist/service/subagent-workflow/workflow-store.js +91 -2
  498. package/plugin/dist/types/event-types.d.ts +1 -1
  499. package/plugin/package.json +6 -3
  500. package/plugin/scripts/acceptance-test.mjs +3 -3
  501. package/plugin/scripts/sync-plugin.mjs +33 -22
  502. package/plugin/templates/langs/en/skills/pd-cli-operator/SKILL.md +20 -11
  503. package/plugin/templates/langs/en/skills/pd-runtime-v2/SKILL.md +10 -0
  504. package/plugin/templates/langs/zh/skills/pd-cli-operator/SKILL.md +20 -11
  505. package/plugin/templates/langs/zh/skills/pd-runtime-v2/SKILL.md +10 -0
  506. package/console/dist/server/config/feature-flags.d.ts +0 -25
  507. package/console/dist/server/config/feature-flags.js +0 -101
  508. package/pd-cli/dist/commands/central-sync.d.ts +0 -10
  509. package/pd-cli/dist/commands/central-sync.d.ts.map +0 -1
  510. package/pd-cli/dist/commands/central-sync.js +0 -32
  511. package/pd-cli/dist/commands/central-sync.js.map +0 -1
  512. package/pd-cli/dist/services/feature-flag-loader.d.ts +0 -6
  513. package/pd-cli/dist/services/feature-flag-loader.d.ts.map +0 -1
  514. package/pd-cli/dist/services/feature-flag-loader.js +0 -53
  515. package/pd-cli/dist/services/feature-flag-loader.js.map +0 -1
  516. package/plugin/dist/core/observability.d.ts +0 -40
  517. package/plugin/dist/core/observability.js +0 -164
  518. package/plugin/dist/core/principle-tree-ledger-adapter.d.ts +0 -32
  519. package/plugin/dist/core/principle-tree-ledger-adapter.js +0 -125
  520. package/plugin/dist/hooks/subagent.d.ts +0 -9
  521. package/plugin/dist/hooks/subagent.js +0 -122
  522. package/plugin/dist/service/central-database.d.ts +0 -138
  523. package/plugin/dist/service/central-database.js +0 -731
  524. package/plugin/dist/service/central-sync-service.d.ts +0 -8
  525. package/plugin/dist/service/central-sync-service.js +0 -71
  526. package/plugin/scripts/validate-live-path.ts +0 -480
@@ -1,4 +1,5 @@
1
1
  import { evaluateRefinerRuleHostGate } from '../../internalization/refiner-rulehost-gate.js';
2
+ import { validateGoldenTrace } from '../../golden-trace.js';
2
3
  const DESTRUCTIVE_TOOL_PREFIXES = ['edit', 'write', 'delete', 'bash', 'exec', 'remove'];
3
4
  function parseContentJson(contentJson) {
4
5
  try {
@@ -19,19 +20,39 @@ function extractImplementationCode(parsed) {
19
20
  }
20
21
  return null;
21
22
  }
23
+ /**
24
+ * Extract and validate the goldenTrace field from parsed artifact contentJson.
25
+ *
26
+ * ERR-001/ERR-005 (rc-1/rc-2): the previous implementation used
27
+ * `as unknown as GoldenTrace` to cast the parsed object without calling
28
+ * `validateGoldenTrace()`. This bypassed schema validation, allowing
29
+ * artifacts with illegal `expectedDecision` values (e.g. "requireApproval",
30
+ * which is a RuleHostDecision runtime enum, not a GoldenTraceDecision test
31
+ * expectation) to pass canActivate and only fail later inside the sandbox
32
+ * with an opaque `gate_decision_not_accepted_shadow:rejected_validation_failed`
33
+ * error. The owner had no way to understand the real cause.
34
+ *
35
+ * Now we run the canonical `validateGoldenTrace()` validator and surface a
36
+ * clear reason pointing at the offending field when validation fails.
37
+ */
22
38
  function extractGoldenTrace(parsed) {
23
39
  const trace = parsed.goldenTrace;
24
40
  if (typeof trace !== 'object' || trace === null || Array.isArray(trace)) {
25
- return null;
26
- }
27
- const traceObj = trace;
28
- if (!Array.isArray(traceObj.cases) || traceObj.cases.length === 0) {
29
- return null;
41
+ return { ok: false, reason: 'no_golden_trace' };
30
42
  }
31
- if (typeof traceObj.traceId !== 'string' || traceObj.traceId.trim().length === 0) {
32
- return null;
43
+ // Once we have an object, defer ALL field-level validation to the canonical
44
+ // validator. The previous intermediate checks (cases non-empty, traceId
45
+ // non-empty) masked schema errors as 'no_golden_trace', giving the owner
46
+ // a less actionable reason than 'golden_trace_schema_invalid: <detail>'.
47
+ const validation = validateGoldenTrace(trace);
48
+ if (!validation.valid) {
49
+ const detail = validation.errors.slice(0, 3).join('; ');
50
+ return {
51
+ ok: false,
52
+ reason: `golden_trace_schema_invalid: ${detail}`,
53
+ };
33
54
  }
34
- return trace;
55
+ return { ok: true, trace: trace };
35
56
  }
36
57
  function extractRuleHostGateDecision(parsed) {
37
58
  const decision = parsed.ruleHostGateDecision;
@@ -74,10 +95,11 @@ export class RuleHostWriter {
74
95
  if (!implementationCode) {
75
96
  return { ok: false, reason: 'no_implementation_code', riskLevel: 'high' };
76
97
  }
77
- const goldenTrace = extractGoldenTrace(parsed);
78
- if (!goldenTrace) {
79
- return { ok: false, reason: 'no_golden_trace', riskLevel: 'high' };
98
+ const goldenTraceResult = extractGoldenTrace(parsed);
99
+ if (!goldenTraceResult.ok) {
100
+ return { ok: false, reason: goldenTraceResult.reason, riskLevel: 'high' };
80
101
  }
102
+ const goldenTrace = goldenTraceResult.trace;
81
103
  const gateDecision = extractRuleHostGateDecision(parsed);
82
104
  if (gateDecision !== 'accepted_shadow') {
83
105
  return { ok: false, reason: 'gate_decision_not_accepted_shadow', riskLevel: 'high' };
@@ -1 +1 @@
1
- {"version":3,"file":"rule-host-writer.js","sourceRoot":"","sources":["../../../../src/runtime-v2/activation/writers/rule-host-writer.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,2BAA2B,EAAE,MAAM,gDAAgD,CAAC;AAG7F,MAAM,yBAAyB,GAAsB,CAAC,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;AAM3G,SAAS,gBAAgB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Aa,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,eAAe,EAAE,CAAC;IAC/F,CAAC;CACF"}
@@ -0,0 +1,53 @@
1
+ /**
2
+ * PRI-456: Pure result-shaping function for PainSignalBridge.
3
+ *
4
+ * Extracts the duplicated status-decision tree from:
5
+ * - PainSignalBridge.onDiagnosisComplete() (fresh diagnosis path)
6
+ * - PainSignalBridge.buildExistingResult() (idempotent existing-task path)
7
+ *
8
+ * Both paths decide: no candidates → failed; admitted-but-no-ledger → failed;
9
+ * gated/partial → degraded; otherwise succeeded. But they differ in message
10
+ * strings and the fresh path has admission results + degraded states.
11
+ *
12
+ * This function is pure: zero I/O, zero side effects. Callers pass all
13
+ * computed values; the function never re-derives lineage fields.
14
+ *
15
+ * ERR gate:
16
+ * - ERR-007 / EP-02: single source for status decision — branches can't diverge
17
+ * - ERR-002 / EP-03: every degraded/failed branch keeps its structured message
18
+ * - ERR-004 / ERR-008 / EP-07: lineage fields are received, never re-derived
19
+ */
20
+ import type { PainSignalBridgeResult } from './pain-signal-bridge.js';
21
+ import type { CandidateAdmissionResult } from './admission-gate.js';
22
+ /** Base fields shared by both fresh and existing paths. */
23
+ interface ShapeBridgeResultBase {
24
+ painId: string;
25
+ taskId: string;
26
+ candidateIds: string[];
27
+ ledgerEntryIds: string[];
28
+ runId?: string;
29
+ artifactId?: string;
30
+ autoIntakeEnabled: boolean;
31
+ }
32
+ /** Fresh diagnosis path — has admission results and seed failure notes. */
33
+ export interface ShapeBridgeResultFreshInput extends ShapeBridgeResultBase {
34
+ path: 'fresh';
35
+ admissionResults: CandidateAdmissionResult[];
36
+ /** Non-empty string when dreamer seed failed; empty string otherwise. */
37
+ seedFailureNote: string;
38
+ }
39
+ /** Existing-task idempotent path — ledger-existence-derived, no admissions. */
40
+ export interface ShapeBridgeResultExistingInput extends ShapeBridgeResultBase {
41
+ path: 'existing';
42
+ }
43
+ export type ShapeBridgeResultInput = ShapeBridgeResultFreshInput | ShapeBridgeResultExistingInput;
44
+ /**
45
+ * Derive the final PainSignalBridgeResult from computed inputs.
46
+ *
47
+ * Byte-for-byte identical to the original inline logic in both call sites.
48
+ * The `path` discriminator selects the appropriate message strings and
49
+ * decision branches.
50
+ */
51
+ export declare function shapeBridgeResult(input: ShapeBridgeResultInput): PainSignalBridgeResult;
52
+ export {};
53
+ //# sourceMappingURL=bridge-result-shaper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bridge-result-shaper.d.ts","sourceRoot":"","sources":["../../src/runtime-v2/bridge-result-shaper.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AACtE,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAEpE,2DAA2D;AAC3D,UAAU,qBAAqB;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,iBAAiB,EAAE,OAAO,CAAC;CAC5B;AAED,2EAA2E;AAC3E,MAAM,WAAW,2BAA4B,SAAQ,qBAAqB;IACxE,IAAI,EAAE,OAAO,CAAC;IACd,gBAAgB,EAAE,wBAAwB,EAAE,CAAC;IAC7C,yEAAyE;IACzE,eAAe,EAAE,MAAM,CAAC;CACzB;AAED,+EAA+E;AAC/E,MAAM,WAAW,8BAA+B,SAAQ,qBAAqB;IAC3E,IAAI,EAAE,UAAU,CAAC;CAClB;AAED,MAAM,MAAM,sBAAsB,GAC9B,2BAA2B,GAC3B,8BAA8B,CAAC;AAEnC;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,sBAAsB,GAAG,sBAAsB,CAoHvF"}
@@ -0,0 +1,117 @@
1
+ /**
2
+ * Derive the final PainSignalBridgeResult from computed inputs.
3
+ *
4
+ * Byte-for-byte identical to the original inline logic in both call sites.
5
+ * The `path` discriminator selects the appropriate message strings and
6
+ * decision branches.
7
+ */
8
+ export function shapeBridgeResult(input) {
9
+ const { painId, taskId, candidateIds, ledgerEntryIds, runId, artifactId, autoIntakeEnabled } = input;
10
+ // Common: no candidates → failed (message differs by path)
11
+ if (candidateIds.length === 0) {
12
+ if (input.path === 'fresh') {
13
+ return {
14
+ status: 'failed',
15
+ painId,
16
+ taskId,
17
+ runId,
18
+ candidateIds,
19
+ ledgerEntryIds,
20
+ admissionResults: input.admissionResults,
21
+ message: 'Diagnostician succeeded but produced no principle candidates',
22
+ };
23
+ }
24
+ return {
25
+ status: 'failed',
26
+ painId,
27
+ taskId,
28
+ runId,
29
+ candidateIds,
30
+ ledgerEntryIds,
31
+ message: 'Task has no principle candidates — treating as failed',
32
+ };
33
+ }
34
+ if (input.path === 'fresh') {
35
+ const { admissionResults, seedFailureNote } = input;
36
+ const admittedCount = admissionResults.filter((a) => a.admission.decision === 'admitted').length;
37
+ const nonAdmittedCount = admissionResults.length - admittedCount;
38
+ // Admitted candidates exist but intake produced no ledger entries
39
+ if (autoIntakeEnabled && admittedCount > 0 && ledgerEntryIds.length === 0) {
40
+ return {
41
+ status: 'failed',
42
+ painId,
43
+ taskId,
44
+ runId,
45
+ artifactId,
46
+ candidateIds,
47
+ ledgerEntryIds,
48
+ admissionResults,
49
+ message: 'Candidate intake did not produce a ledger entry',
50
+ };
51
+ }
52
+ // All candidates gated (none admitted)
53
+ if (nonAdmittedCount > 0 && admittedCount === 0) {
54
+ return {
55
+ status: 'degraded',
56
+ painId,
57
+ taskId,
58
+ runId,
59
+ artifactId,
60
+ candidateIds,
61
+ ledgerEntryIds,
62
+ admissionResults,
63
+ message: `all_candidates_gated:${admissionResults.map((a) => `${a.candidateId}=${a.admission.decision}`).join(',')}${seedFailureNote ? `; ${seedFailureNote}` : ''}`,
64
+ };
65
+ }
66
+ // Partial admission (some admitted, some gated)
67
+ if (nonAdmittedCount > 0 && admittedCount > 0) {
68
+ return {
69
+ status: 'degraded',
70
+ painId,
71
+ taskId,
72
+ runId,
73
+ artifactId,
74
+ candidateIds,
75
+ ledgerEntryIds,
76
+ admissionResults,
77
+ message: `partial_admission:${admittedCount}_admitted_${nonAdmittedCount}_gated${seedFailureNote ? `; ${seedFailureNote}` : ''}`,
78
+ };
79
+ }
80
+ // Success (or degraded if seed failure occurred)
81
+ return {
82
+ status: seedFailureNote ? 'degraded' : 'succeeded',
83
+ painId,
84
+ taskId,
85
+ runId,
86
+ artifactId,
87
+ candidateIds,
88
+ ledgerEntryIds,
89
+ admissionResults,
90
+ message: seedFailureNote || undefined,
91
+ };
92
+ }
93
+ // Existing path: no admission results, simpler decision tree
94
+ if (autoIntakeEnabled && ledgerEntryIds.length === 0) {
95
+ return {
96
+ status: 'failed',
97
+ painId,
98
+ taskId,
99
+ runId,
100
+ artifactId,
101
+ candidateIds,
102
+ ledgerEntryIds,
103
+ message: 'Candidate intake did not produce a ledger entry — treating as failed',
104
+ };
105
+ }
106
+ return {
107
+ status: 'succeeded',
108
+ painId,
109
+ taskId,
110
+ runId,
111
+ artifactId,
112
+ candidateIds,
113
+ ledgerEntryIds,
114
+ message: 'Task already succeeded',
115
+ };
116
+ }
117
+ //# sourceMappingURL=bridge-result-shaper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bridge-result-shaper.js","sourceRoot":"","sources":["../../src/runtime-v2/bridge-result-shaper.ts"],"names":[],"mappings":"AAkDA;;;;;;GAMG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAA6B;IAC7D,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,cAAc,EAAE,KAAK,EAAE,UAAU,EAAE,iBAAiB,EAAE,GAAG,KAAK,CAAC;IAErG,2DAA2D;IAC3D,IAAI,YAAY,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC9B,IAAI,KAAK,CAAC,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@@ -0,0 +1,13 @@
1
+ /**
2
+ * Detection Funnel Policy Tests — PRI-446
3
+ *
4
+ * Tests the pure core DetectionFunnelCore directly with injected stubs for
5
+ * matcher/hasher/gate (no crypto, no dictionary). The plugin's
6
+ * detection-funnel-characterization.test.ts (10 tests) exercises the same logic
7
+ * through the wired adapter; this file gives core its own direct coverage.
8
+ *
9
+ * ERR checklist:
10
+ * - ERR-025: tests the real DetectionFunnelCore path.
11
+ */
12
+ export {};
13
+ //# sourceMappingURL=detection-funnel-policy.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"detection-funnel-policy.test.d.ts","sourceRoot":"","sources":["../../../../src/runtime-v2/detection/__tests__/detection-funnel-policy.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG"}
@@ -0,0 +1,111 @@
1
+ /**
2
+ * Detection Funnel Policy Tests — PRI-446
3
+ *
4
+ * Tests the pure core DetectionFunnelCore directly with injected stubs for
5
+ * matcher/hasher/gate (no crypto, no dictionary). The plugin's
6
+ * detection-funnel-characterization.test.ts (10 tests) exercises the same logic
7
+ * through the wired adapter; this file gives core its own direct coverage.
8
+ *
9
+ * ERR checklist:
10
+ * - ERR-025: tests the real DetectionFunnelCore path.
11
+ */
12
+ import { describe, it, expect } from 'vitest';
13
+ import { DetectionFunnelCore, SimpleLRU, } from '../detection-funnel-policy.js';
14
+ function makeConfig(overrides = {}) {
15
+ return {
16
+ match: () => undefined,
17
+ hash: (t) => `hash:${t}`,
18
+ shouldIgnoreProtocol: () => false,
19
+ ...overrides,
20
+ };
21
+ }
22
+ describe('DetectionFunnelCore: L1 exact', () => {
23
+ it('returns l1_exact with ruleId+severity on match', () => {
24
+ const funnel = new DetectionFunnelCore(makeConfig({
25
+ match: (t) => (t === 'i am confused' ? { ruleId: 'P_CONFUSION_EN', severity: 35 } : undefined),
26
+ }));
27
+ const r = funnel.detect('i am confused');
28
+ expect(r).toEqual({ detected: true, severity: 35, ruleId: 'P_CONFUSION_EN', source: 'l1_exact' });
29
+ });
30
+ it('protocol token gate short-circuits before L1', () => {
31
+ const funnel = new DetectionFunnelCore(makeConfig({
32
+ match: () => ({ ruleId: 'X', severity: 10 }),
33
+ shouldIgnoreProtocol: (t) => t === 'HEARTBEAT_OK',
34
+ }));
35
+ const r = funnel.detect('HEARTBEAT_OK');
36
+ expect(r).toEqual({ detected: false, source: 'l1_exact' });
37
+ });
38
+ });
39
+ describe('DetectionFunnelCore: L3 async queue', () => {
40
+ it('no match + no cache → l3_async_queued', () => {
41
+ const funnel = new DetectionFunnelCore(makeConfig());
42
+ expect(funnel.detect('unseen')).toEqual({ detected: false, source: 'l3_async_queued' });
43
+ });
44
+ it('flushQueue returns queued texts and clears', () => {
45
+ const funnel = new DetectionFunnelCore(makeConfig());
46
+ funnel.detect('a');
47
+ funnel.detect('b');
48
+ expect(funnel.flushQueue()).toEqual(['a', 'b']);
49
+ expect(funnel.flushQueue()).toEqual([]);
50
+ });
51
+ });
52
+ describe('DetectionFunnelCore: L2 cache', () => {
53
+ it('updateCache then detect returns l2_cache with stored result', () => {
54
+ const funnel = new DetectionFunnelCore(makeConfig());
55
+ funnel.updateCache('text', { detected: true, severity: 72 });
56
+ const r = funnel.detect('text');
57
+ expect(r.source).toBe('l2_cache');
58
+ expect(r).toMatchObject({ detected: true, severity: 72 });
59
+ });
60
+ it('L1 takes precedence over a poisoned L2 cache', () => {
61
+ const funnel = new DetectionFunnelCore(makeConfig({
62
+ match: (t) => (t === 'x' ? { ruleId: 'R', severity: 35 } : undefined),
63
+ }));
64
+ funnel.updateCache('x', { detected: false });
65
+ const r = funnel.detect('x');
66
+ expect(r.source).toBe('l1_exact');
67
+ expect(r.detected).toBe(true);
68
+ });
69
+ });
70
+ describe('DetectionFunnelCore: LRU eviction', () => {
71
+ it('evicts oldest beyond capacity', () => {
72
+ const funnel = new DetectionFunnelCore(makeConfig({ cacheSize: 2 }));
73
+ funnel.updateCache('a', { detected: true });
74
+ funnel.updateCache('b', { detected: true });
75
+ funnel.updateCache('c', { detected: true }); // evicts 'a'
76
+ expect(funnel.detect('a').source).toBe('l3_async_queued');
77
+ expect(funnel.detect('c').source).toBe('l2_cache');
78
+ });
79
+ it('refreshes LRU position on get', () => {
80
+ const funnel = new DetectionFunnelCore(makeConfig({ cacheSize: 2 }));
81
+ funnel.updateCache('a', { detected: true });
82
+ funnel.updateCache('b', { detected: true });
83
+ funnel.detect('a'); // refresh 'a' -> now 'b' is oldest
84
+ funnel.updateCache('c', { detected: true }); // evicts 'b'
85
+ expect(funnel.detect('a').source).toBe('l2_cache');
86
+ expect(funnel.detect('b').source).toBe('l3_async_queued');
87
+ });
88
+ });
89
+ describe('DetectionFunnelCore: queue capacity', () => {
90
+ it('bounds the queue at queueCapacity', () => {
91
+ const funnel = new DetectionFunnelCore(makeConfig({ queueCapacity: 2 }));
92
+ funnel.detect('a');
93
+ funnel.detect('b');
94
+ funnel.detect('c'); // exceeds capacity, dropped
95
+ expect(funnel.flushQueue()).toEqual(['a', 'b']);
96
+ });
97
+ });
98
+ describe('SimpleLRU', () => {
99
+ it('get returns undefined for missing key', () => {
100
+ const lru = new SimpleLRU(10);
101
+ expect(lru.get('missing')).toBeUndefined();
102
+ });
103
+ it('default capacity is 100', () => {
104
+ const lru = new SimpleLRU();
105
+ for (let i = 0; i < 150; i++)
106
+ lru.set(`k${i}`, i);
107
+ expect(lru.get('k0')).toBeUndefined(); // evicted
108
+ expect(lru.get('k149')).toBe(149);
109
+ });
110
+ });
111
+ //# sourceMappingURL=detection-funnel-policy.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"detection-funnel-policy.test.js","sourceRoot":"","sources":["../../../../src/runtime-v2/detection/__tests__/detection-funnel-policy.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EACL,mBAAmB,EACnB,SAAS,GAEV,MAAM,+BAA+B,CAAC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rated from the plugin adapter)
3
+ *
4
+ * Pure three-layer detection funnel logic:
5
+ * L1 — exact dictionary match (sync, delegated via injected matchFn)
6
+ * L2 — LRU cache of prior L3 resolutions (sync)
7
+ * L3 — async semantic queue (caller drains via flushQueue + updateCache)
8
+ *
9
+ * This module is fully pure: no I/O, no crypto, no plugin imports. The two
10
+ * environment-coupled dependencies — the dictionary matcher and the text hasher —
11
+ * are injected, so core owns the funnel *logic* while the plugin owns the
12
+ * concrete crypto.createHash and the PainDictionary.
13
+ *
14
+ * The plugin-side detection-funnel.ts is now a thin shell that wires
15
+ * DetectionFunnelCore with crypto + dictionary and re-exports the DetectionFunnel
16
+ * name, so DetectionService and evolution-worker keep working unchanged.
17
+ *
18
+ * ERR checklist:
19
+ * - ERR-001: no `as` casts; cache reads validated.
20
+ * - ERR-002: results carry structured source + severity.
21
+ * - EP-01: queue is bounded.
22
+ */
23
+ export interface DetectionResult {
24
+ detected: boolean;
25
+ severity?: number;
26
+ ruleId?: string;
27
+ source: 'l1_exact' | 'l2_cache' | 'l3_async_queued' | 'l3_semantic_hit';
28
+ }
29
+ /** A matched pain rule (subset of PainDictionary's match return). */
30
+ export interface PainMatchResult {
31
+ ruleId: string;
32
+ severity: number;
33
+ }
34
+ /**
35
+ * Matcher contract injected by the plugin (backed by PainDictionary).
36
+ * Returns the matched rule + severity for L1 exact matching, or undefined.
37
+ */
38
+ export type PainMatcher = (text: string) => PainMatchResult | undefined;
39
+ /**
40
+ * Hash function injected by the plugin (backed by crypto.createHash).
41
+ * Used for L2 cache keys.
42
+ */
43
+ export type TextHasher = (text: string) => string;
44
+ /**
45
+ * Predicate injected by the plugin (backed by shouldIgnorePainProtocolText).
46
+ * Returns true for protocol tokens that short-circuit before any layer.
47
+ */
48
+ export type ProtocolTokenGate = (text: string) => boolean;
49
+ /**
50
+ * A simple LRU Cache implementation using Map.
51
+ * Migrated verbatim from the prior plugin detection-funnel.ts.
52
+ */
53
+ export declare class SimpleLRU<K, V> {
54
+ private readonly cache;
55
+ private readonly maxSize;
56
+ constructor(maxSize?: number);
57
+ get(key: K): V | undefined;
58
+ set(key: K, value: V): void;
59
+ }
60
+ export interface DetectionFunnelConfig {
61
+ /** L1 exact-match delegate. */
62
+ match: PainMatcher;
63
+ /** Text hasher for L2 cache keys. */
64
+ hash: TextHasher;
65
+ /** Protocol-token gate that runs before any layer. */
66
+ shouldIgnoreProtocol: ProtocolTokenGate;
67
+ /** L2 cache capacity. Default 100. */
68
+ cacheSize?: number;
69
+ /** L3 async queue capacity. Default 1000. */
70
+ queueCapacity?: number;
71
+ }
72
+ /**
73
+ * Orchestrates the three-layer detection funnel for pain signals.
74
+ *
75
+ * Pure logic: holds only in-memory cache and queue state. All environment
76
+ * coupling (dictionary, crypto) is injected via config.
77
+ */
78
+ export declare class DetectionFunnelCore {
79
+ private readonly cache;
80
+ private asyncQueue;
81
+ private readonly match;
82
+ private readonly hash;
83
+ private readonly shouldIgnoreProtocol;
84
+ private readonly queueCapacity;
85
+ constructor(config: DetectionFunnelConfig);
86
+ /**
87
+ * Detects pain in the given text using L1 (Exact), L2 (Cache), and L3 (Async).
88
+ */
89
+ detect(text: string): DetectionResult;
90
+ private enqueueAsync;
91
+ /**
92
+ * Internal method for the worker to update the cache after a semantic hit.
93
+ */
94
+ updateCache(text: string, result: {
95
+ detected: boolean;
96
+ severity?: number;
97
+ }): void;
98
+ /**
99
+ * Retrieves and clears the current asynchronous queue.
100
+ */
101
+ flushQueue(): string[];
102
+ }
103
+ //# sourceMappingURL=detection-funnel-policy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"detection-funnel-policy.d.ts","sourceRoot":"","sources":["../../../src/runtime-v2/detection/detection-funnel-policy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAIH,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CA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