create-principles-disciple 1.94.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 (339) hide show
  1. package/console/dist/server/config/WorkspaceConfigStore.js +2 -1
  2. package/console/dist/server/config/pd-config-store.d.ts +33 -0
  3. package/console/dist/server/config/pd-config-store.js +159 -0
  4. package/console/dist/server/index.js +18 -4
  5. package/console/dist/server/models/EvidenceChainConsoleModel.d.ts +0 -2
  6. package/console/dist/server/models/EvidenceChainConsoleModel.js +36 -2
  7. package/console/dist/server/models/HealthCheckModel.js +5 -3
  8. package/console/dist/server/models/IntentDecisionModel.d.ts +66 -0
  9. package/console/dist/server/models/IntentDecisionModel.js +207 -0
  10. package/console/dist/server/models/IntentPageModel.d.ts +18 -0
  11. package/console/dist/server/models/IntentPageModel.js +90 -0
  12. package/console/dist/server/models/PrinciplesConsoleModel.d.ts +2 -0
  13. package/console/dist/server/models/PrinciplesConsoleModel.js +37 -1
  14. package/console/dist/server/models/WorkspaceService.d.ts +0 -28
  15. package/console/dist/server/models/WorkspaceService.js +0 -115
  16. package/console/dist/server/routes/config.js +55 -1
  17. package/console/dist/server/routes/intent-decisions.d.ts +33 -0
  18. package/console/dist/server/routes/intent-decisions.js +499 -0
  19. package/console/dist/server/routes/intent.d.ts +3 -0
  20. package/console/dist/server/routes/intent.js +35 -0
  21. package/console/dist/server/routes/principles.js +67 -1
  22. package/console/dist/server/routes/update.d.ts +0 -1
  23. package/console/dist/server/routes/update.js +14 -11
  24. package/console/dist/ui/App.js +2 -7
  25. package/console/dist/ui/api.d.ts +44 -18
  26. package/console/dist/ui/api.js +44 -5
  27. package/console/dist/ui/components/layout/app-sidebar.js +2 -1
  28. package/console/dist/ui/components/ui/badge.d.ts +1 -1
  29. package/console/dist/ui/components/ui/button.d.ts +1 -1
  30. package/console/dist/ui/components/ui/shiny-text.d.ts +28 -0
  31. package/console/dist/ui/components/ui/shiny-text.js +46 -0
  32. package/console/dist/ui/i18n/en.json +167 -3
  33. package/console/dist/ui/i18n/zh-CN.json +167 -3
  34. package/console/dist/ui/pages/activation/ActivationPage.js +2 -1
  35. package/console/dist/ui/pages/control-center/ControlCenterPage.js +28 -2
  36. package/console/dist/ui/pages/control-center/EmpathyObserverCostHint.d.ts +28 -0
  37. package/console/dist/ui/pages/control-center/EmpathyObserverCostHint.js +38 -0
  38. package/console/dist/ui/pages/debt/DebtPage.js +219 -2
  39. package/console/dist/ui/pages/focus/FocusPage.js +2 -1
  40. package/console/dist/ui/pages/intent/IntentPage.d.ts +1 -0
  41. package/console/dist/ui/pages/intent/IntentPage.js +147 -0
  42. package/console/dist/ui/pages/pain/PainPage.js +234 -4
  43. package/console/dist/ui/pages/pain/pain-card-helpers.d.ts +75 -0
  44. package/console/dist/ui/pages/pain/pain-card-helpers.js +78 -0
  45. package/console/dist/ui/pages/principles/PrinciplesPage.js +2 -1
  46. package/console/dist/ui/utils/validators.d.ts +163 -0
  47. package/console/dist/ui/utils/validators.js +433 -0
  48. package/console/dist/web/assets/app.css +138 -0
  49. package/console/dist/web/assets/app.js +3124 -1288
  50. package/console/package.json +3 -0
  51. package/core/dist/principle-tree-ledger.d.ts +55 -4
  52. package/core/dist/principle-tree-ledger.d.ts.map +1 -1
  53. package/core/dist/principle-tree-ledger.js +472 -13
  54. package/core/dist/principle-tree-ledger.js.map +1 -1
  55. package/core/dist/prompt-builder/__tests__/prompt-builder-core.test.js +58 -0
  56. package/core/dist/prompt-builder/__tests__/prompt-builder-core.test.js.map +1 -1
  57. package/core/dist/prompt-builder/empathy-keyword-matching.d.ts.map +1 -1
  58. package/core/dist/prompt-builder/empathy-keyword-matching.js +9 -6
  59. package/core/dist/prompt-builder/empathy-keyword-matching.js.map +1 -1
  60. package/core/dist/prompt-builder/size-guard.d.ts +1 -0
  61. package/core/dist/prompt-builder/size-guard.d.ts.map +1 -1
  62. package/core/dist/prompt-builder/size-guard.js +21 -0
  63. package/core/dist/prompt-builder/size-guard.js.map +1 -1
  64. package/core/dist/prompt-builder/types.d.ts +2 -0
  65. package/core/dist/prompt-builder/types.d.ts.map +1 -1
  66. package/core/dist/runtime-v2/__tests__/architecture-regression.test.js +118 -32
  67. package/core/dist/runtime-v2/__tests__/architecture-regression.test.js.map +1 -1
  68. package/core/dist/runtime-v2/__tests__/evidence-chain-intent-tension.test.d.ts +2 -0
  69. package/core/dist/runtime-v2/__tests__/evidence-chain-intent-tension.test.d.ts.map +1 -0
  70. package/core/dist/runtime-v2/__tests__/evidence-chain-intent-tension.test.js +284 -0
  71. package/core/dist/runtime-v2/__tests__/evidence-chain-intent-tension.test.js.map +1 -0
  72. package/core/dist/runtime-v2/__tests__/pain-signal-bridge-result-shaping.test.js +105 -0
  73. package/core/dist/runtime-v2/__tests__/pain-signal-bridge-result-shaping.test.js.map +1 -1
  74. package/core/dist/runtime-v2/__tests__/pain-signal-observability.test.js +7 -5
  75. package/core/dist/runtime-v2/__tests__/pain-signal-observability.test.js.map +1 -1
  76. package/core/dist/runtime-v2/__tests__/pi-artifact-store.test.js +11 -0
  77. package/core/dist/runtime-v2/__tests__/pi-artifact-store.test.js.map +1 -1
  78. package/core/dist/runtime-v2/__tests__/proven-channel-baseline.test.js +15 -2
  79. package/core/dist/runtime-v2/__tests__/proven-channel-baseline.test.js.map +1 -1
  80. package/core/dist/runtime-v2/__tests__/schema-float-precision.test.d.ts +2 -0
  81. package/core/dist/runtime-v2/__tests__/schema-float-precision.test.d.ts.map +1 -0
  82. package/core/dist/runtime-v2/__tests__/schema-float-precision.test.js +290 -0
  83. package/core/dist/runtime-v2/__tests__/schema-float-precision.test.js.map +1 -0
  84. package/core/dist/runtime-v2/__tests__/schema-orphan-detection.test.d.ts +2 -0
  85. package/core/dist/runtime-v2/__tests__/schema-orphan-detection.test.d.ts.map +1 -0
  86. package/core/dist/runtime-v2/__tests__/schema-orphan-detection.test.js +158 -0
  87. package/core/dist/runtime-v2/__tests__/schema-orphan-detection.test.js.map +1 -0
  88. package/core/dist/runtime-v2/activation/__tests__/approval-store-extended.test.js +15 -1
  89. package/core/dist/runtime-v2/activation/__tests__/approval-store-extended.test.js.map +1 -1
  90. package/core/dist/runtime-v2/activation/__tests__/sqlite-activation-state-store-fk.test.d.ts +2 -0
  91. package/core/dist/runtime-v2/activation/__tests__/sqlite-activation-state-store-fk.test.d.ts.map +1 -0
  92. package/core/dist/runtime-v2/activation/__tests__/sqlite-activation-state-store-fk.test.js +62 -0
  93. package/core/dist/runtime-v2/activation/__tests__/sqlite-activation-state-store-fk.test.js.map +1 -0
  94. package/core/dist/runtime-v2/activation/__tests__/sqlite-activation-state-store.test.js +12 -2
  95. package/core/dist/runtime-v2/activation/__tests__/sqlite-activation-state-store.test.js.map +1 -1
  96. package/core/dist/runtime-v2/activation/__tests__/sqlite-approval-store-fk.test.d.ts +2 -0
  97. package/core/dist/runtime-v2/activation/__tests__/sqlite-approval-store-fk.test.d.ts.map +1 -0
  98. package/core/dist/runtime-v2/activation/__tests__/sqlite-approval-store-fk.test.js +56 -0
  99. package/core/dist/runtime-v2/activation/__tests__/sqlite-approval-store-fk.test.js.map +1 -0
  100. package/core/dist/runtime-v2/activation/__tests__/sqlite-approval-store.test.js +8 -0
  101. package/core/dist/runtime-v2/activation/__tests__/sqlite-approval-store.test.js.map +1 -1
  102. package/core/dist/runtime-v2/activation/__tests__/story-a-acceptance.test.js +20 -0
  103. package/core/dist/runtime-v2/activation/__tests__/story-a-acceptance.test.js.map +1 -1
  104. package/core/dist/runtime-v2/activation/sqlite-activation-state-store.d.ts.map +1 -1
  105. package/core/dist/runtime-v2/activation/sqlite-activation-state-store.js +6 -0
  106. package/core/dist/runtime-v2/activation/sqlite-activation-state-store.js.map +1 -1
  107. package/core/dist/runtime-v2/activation/sqlite-approval-store.d.ts.map +1 -1
  108. package/core/dist/runtime-v2/activation/sqlite-approval-store.js +86 -32
  109. package/core/dist/runtime-v2/activation/sqlite-approval-store.js.map +1 -1
  110. package/core/dist/runtime-v2/activation/writers/__tests__/rule-host-writer.test.js +65 -1
  111. package/core/dist/runtime-v2/activation/writers/__tests__/rule-host-writer.test.js.map +1 -1
  112. package/core/dist/runtime-v2/activation/writers/rule-host-writer.d.ts.map +1 -1
  113. package/core/dist/runtime-v2/activation/writers/rule-host-writer.js +33 -11
  114. package/core/dist/runtime-v2/activation/writers/rule-host-writer.js.map +1 -1
  115. package/core/dist/runtime-v2/diagnostician/__tests__/diag-rootcause-output.test.js +134 -15
  116. package/core/dist/runtime-v2/diagnostician/__tests__/diag-rootcause-output.test.js.map +1 -1
  117. package/core/dist/runtime-v2/diagnostician/__tests__/intent-tension-schema.test.d.ts +18 -0
  118. package/core/dist/runtime-v2/diagnostician/__tests__/intent-tension-schema.test.d.ts.map +1 -0
  119. package/core/dist/runtime-v2/diagnostician/__tests__/intent-tension-schema.test.js +251 -0
  120. package/core/dist/runtime-v2/diagnostician/__tests__/intent-tension-schema.test.js.map +1 -0
  121. package/core/dist/runtime-v2/diagnostician/__tests__/rootcause-prompt-builder.test.js +73 -0
  122. package/core/dist/runtime-v2/diagnostician/__tests__/rootcause-prompt-builder.test.js.map +1 -1
  123. package/core/dist/runtime-v2/diagnostician/diag-rootcause-output.d.ts +98 -0
  124. package/core/dist/runtime-v2/diagnostician/diag-rootcause-output.d.ts.map +1 -1
  125. package/core/dist/runtime-v2/diagnostician/diag-rootcause-output.js +131 -0
  126. package/core/dist/runtime-v2/diagnostician/diag-rootcause-output.js.map +1 -1
  127. package/core/dist/runtime-v2/diagnostician/rootcause-prompt-builder.d.ts +8 -0
  128. package/core/dist/runtime-v2/diagnostician/rootcause-prompt-builder.d.ts.map +1 -1
  129. package/core/dist/runtime-v2/diagnostician/rootcause-prompt-builder.js +66 -3
  130. package/core/dist/runtime-v2/diagnostician/rootcause-prompt-builder.js.map +1 -1
  131. package/core/dist/runtime-v2/diagnostician-output.d.ts +23 -0
  132. package/core/dist/runtime-v2/diagnostician-output.d.ts.map +1 -1
  133. package/core/dist/runtime-v2/diagnostician-output.js +16 -0
  134. package/core/dist/runtime-v2/diagnostician-output.js.map +1 -1
  135. package/core/dist/runtime-v2/diagnostician-prompt-builder.d.ts +32 -0
  136. package/core/dist/runtime-v2/diagnostician-prompt-builder.d.ts.map +1 -1
  137. package/core/dist/runtime-v2/diagnostician-prompt-builder.js.map +1 -1
  138. package/core/dist/runtime-v2/evidence-triage/source-descriptors.d.ts +1 -1
  139. package/core/dist/runtime-v2/evidence-triage/source-descriptors.js +1 -1
  140. package/core/dist/runtime-v2/feature-flags/__tests__/feature-flag-contract.test.js +23 -0
  141. package/core/dist/runtime-v2/feature-flags/__tests__/feature-flag-contract.test.js.map +1 -1
  142. package/core/dist/runtime-v2/feature-flags/__tests__/intent-engineering-flag.test.d.ts +2 -0
  143. package/core/dist/runtime-v2/feature-flags/__tests__/intent-engineering-flag.test.d.ts.map +1 -0
  144. package/core/dist/runtime-v2/feature-flags/__tests__/intent-engineering-flag.test.js +30 -0
  145. package/core/dist/runtime-v2/feature-flags/__tests__/intent-engineering-flag.test.js.map +1 -0
  146. package/core/dist/runtime-v2/feature-flags/feature-flag-contract.d.ts.map +1 -1
  147. package/core/dist/runtime-v2/feature-flags/feature-flag-contract.js +2 -0
  148. package/core/dist/runtime-v2/feature-flags/feature-flag-contract.js.map +1 -1
  149. package/core/dist/runtime-v2/feature-flags/plugin-surface-registry.d.ts.map +1 -1
  150. package/core/dist/runtime-v2/feature-flags/plugin-surface-registry.js +0 -9
  151. package/core/dist/runtime-v2/feature-flags/plugin-surface-registry.js.map +1 -1
  152. package/core/dist/runtime-v2/index.d.ts +9 -4
  153. package/core/dist/runtime-v2/index.d.ts.map +1 -1
  154. package/core/dist/runtime-v2/index.js +12 -3
  155. package/core/dist/runtime-v2/index.js.map +1 -1
  156. package/core/dist/runtime-v2/intent/__tests__/intent-decision-record.test.d.ts +2 -0
  157. package/core/dist/runtime-v2/intent/__tests__/intent-decision-record.test.d.ts.map +1 -0
  158. package/core/dist/runtime-v2/intent/__tests__/intent-decision-record.test.js +185 -0
  159. package/core/dist/runtime-v2/intent/__tests__/intent-decision-record.test.js.map +1 -0
  160. package/core/dist/runtime-v2/intent/__tests__/intent-doc.test.d.ts +2 -0
  161. package/core/dist/runtime-v2/intent/__tests__/intent-doc.test.d.ts.map +1 -0
  162. package/core/dist/runtime-v2/intent/__tests__/intent-doc.test.js +91 -0
  163. package/core/dist/runtime-v2/intent/__tests__/intent-doc.test.js.map +1 -0
  164. package/core/dist/runtime-v2/intent/__tests__/intent-friction-block.test.d.ts +2 -0
  165. package/core/dist/runtime-v2/intent/__tests__/intent-friction-block.test.d.ts.map +1 -0
  166. package/core/dist/runtime-v2/intent/__tests__/intent-friction-block.test.js +168 -0
  167. package/core/dist/runtime-v2/intent/__tests__/intent-friction-block.test.js.map +1 -0
  168. package/core/dist/runtime-v2/intent/__tests__/intent-patch-proposal.test.d.ts +2 -0
  169. package/core/dist/runtime-v2/intent/__tests__/intent-patch-proposal.test.d.ts.map +1 -0
  170. package/core/dist/runtime-v2/intent/__tests__/intent-patch-proposal.test.js +121 -0
  171. package/core/dist/runtime-v2/intent/__tests__/intent-patch-proposal.test.js.map +1 -0
  172. package/core/dist/runtime-v2/intent/index.d.ts +6 -0
  173. package/core/dist/runtime-v2/intent/index.d.ts.map +1 -0
  174. package/core/dist/runtime-v2/intent/index.js +6 -0
  175. package/core/dist/runtime-v2/intent/index.js.map +1 -0
  176. package/core/dist/runtime-v2/intent/intent-decision-record.d.ts +125 -0
  177. package/core/dist/runtime-v2/intent/intent-decision-record.d.ts.map +1 -0
  178. package/core/dist/runtime-v2/intent/intent-decision-record.js +21 -0
  179. package/core/dist/runtime-v2/intent/intent-decision-record.js.map +1 -0
  180. package/core/dist/runtime-v2/intent/intent-doc-reader-port.d.ts +95 -0
  181. package/core/dist/runtime-v2/intent/intent-doc-reader-port.d.ts.map +1 -0
  182. package/core/dist/runtime-v2/intent/intent-doc-reader-port.js +43 -0
  183. package/core/dist/runtime-v2/intent/intent-doc-reader-port.js.map +1 -0
  184. package/core/dist/runtime-v2/intent/intent-doc.d.ts +19 -0
  185. package/core/dist/runtime-v2/intent/intent-doc.d.ts.map +1 -0
  186. package/core/dist/runtime-v2/intent/intent-doc.js +70 -0
  187. package/core/dist/runtime-v2/intent/intent-doc.js.map +1 -0
  188. package/core/dist/runtime-v2/intent/intent-friction-block.d.ts +63 -0
  189. package/core/dist/runtime-v2/intent/intent-friction-block.d.ts.map +1 -0
  190. package/core/dist/runtime-v2/intent/intent-friction-block.js +129 -0
  191. package/core/dist/runtime-v2/intent/intent-friction-block.js.map +1 -0
  192. package/core/dist/runtime-v2/intent/intent-patch-proposal.d.ts +42 -0
  193. package/core/dist/runtime-v2/intent/intent-patch-proposal.d.ts.map +1 -0
  194. package/core/dist/runtime-v2/intent/intent-patch-proposal.js +81 -0
  195. package/core/dist/runtime-v2/intent/intent-patch-proposal.js.map +1 -0
  196. package/core/dist/runtime-v2/internalization/__tests__/__fixtures__/intent-tension-cases.d.ts +54 -0
  197. package/core/dist/runtime-v2/internalization/__tests__/__fixtures__/intent-tension-cases.d.ts.map +1 -0
  198. package/core/dist/runtime-v2/internalization/__tests__/__fixtures__/intent-tension-cases.js +219 -0
  199. package/core/dist/runtime-v2/internalization/__tests__/__fixtures__/intent-tension-cases.js.map +1 -0
  200. package/core/dist/runtime-v2/internalization/__tests__/diag-rootcause-intent-tension.test.d.ts +2 -0
  201. package/core/dist/runtime-v2/internalization/__tests__/diag-rootcause-intent-tension.test.d.ts.map +1 -0
  202. package/core/dist/runtime-v2/internalization/__tests__/diag-rootcause-intent-tension.test.js +360 -0
  203. package/core/dist/runtime-v2/internalization/__tests__/diag-rootcause-intent-tension.test.js.map +1 -0
  204. package/core/dist/runtime-v2/internalization/__tests__/diag-router-intent-tension.test.d.ts +2 -0
  205. package/core/dist/runtime-v2/internalization/__tests__/diag-router-intent-tension.test.d.ts.map +1 -0
  206. package/core/dist/runtime-v2/internalization/__tests__/diag-router-intent-tension.test.js +333 -0
  207. package/core/dist/runtime-v2/internalization/__tests__/diag-router-intent-tension.test.js.map +1 -0
  208. package/core/dist/runtime-v2/internalization/__tests__/intent-tension-cases.test.d.ts +2 -0
  209. package/core/dist/runtime-v2/internalization/__tests__/intent-tension-cases.test.d.ts.map +1 -0
  210. package/core/dist/runtime-v2/internalization/__tests__/intent-tension-cases.test.js +113 -0
  211. package/core/dist/runtime-v2/internalization/__tests__/intent-tension-cases.test.js.map +1 -0
  212. package/core/dist/runtime-v2/internalization/diag-rootcause-runner.d.ts +13 -0
  213. package/core/dist/runtime-v2/internalization/diag-rootcause-runner.d.ts.map +1 -1
  214. package/core/dist/runtime-v2/internalization/diag-rootcause-runner.js +42 -0
  215. package/core/dist/runtime-v2/internalization/diag-rootcause-runner.js.map +1 -1
  216. package/core/dist/runtime-v2/internalization/diag-router-runner.d.ts.map +1 -1
  217. package/core/dist/runtime-v2/internalization/diag-router-runner.js +27 -0
  218. package/core/dist/runtime-v2/internalization/diag-router-runner.js.map +1 -1
  219. package/core/dist/runtime-v2/pain-signal-observability.d.ts.map +1 -1
  220. package/core/dist/runtime-v2/pain-signal-observability.js +257 -56
  221. package/core/dist/runtime-v2/pain-signal-observability.js.map +1 -1
  222. package/core/dist/runtime-v2/pain-signal-runtime-factory.d.ts +12 -0
  223. package/core/dist/runtime-v2/pain-signal-runtime-factory.d.ts.map +1 -1
  224. package/core/dist/runtime-v2/pain-signal-runtime-factory.js +1 -1
  225. package/core/dist/runtime-v2/pain-signal-runtime-factory.js.map +1 -1
  226. package/core/dist/runtime-v2/pain-to-principle-service.d.ts +6 -0
  227. package/core/dist/runtime-v2/pain-to-principle-service.d.ts.map +1 -1
  228. package/core/dist/runtime-v2/pain-to-principle-service.js +2 -0
  229. package/core/dist/runtime-v2/pain-to-principle-service.js.map +1 -1
  230. package/core/dist/runtime-v2/principle-tree/ledger-codec.js.map +1 -1
  231. package/core/dist/runtime-v2/proven-channel-baseline.js +1 -1
  232. package/core/dist/runtime-v2/proven-channel-baseline.js.map +1 -1
  233. package/core/dist/runtime-v2/store/artifact/__tests__/sqlite-pi-artifact-store-fk.test.d.ts +2 -0
  234. package/core/dist/runtime-v2/store/artifact/__tests__/sqlite-pi-artifact-store-fk.test.d.ts.map +1 -0
  235. package/core/dist/runtime-v2/store/artifact/__tests__/sqlite-pi-artifact-store-fk.test.js +55 -0
  236. package/core/dist/runtime-v2/store/artifact/__tests__/sqlite-pi-artifact-store-fk.test.js.map +1 -0
  237. package/core/dist/runtime-v2/store/artifact/sqlite-pi-artifact-store.d.ts.map +1 -1
  238. package/core/dist/runtime-v2/store/artifact/sqlite-pi-artifact-store.js +6 -0
  239. package/core/dist/runtime-v2/store/artifact/sqlite-pi-artifact-store.js.map +1 -1
  240. package/core/dist/runtime-v2/store/intent/__tests__/sqlite-intent-decision-store.test.d.ts +2 -0
  241. package/core/dist/runtime-v2/store/intent/__tests__/sqlite-intent-decision-store.test.d.ts.map +1 -0
  242. package/core/dist/runtime-v2/store/intent/__tests__/sqlite-intent-decision-store.test.js +272 -0
  243. package/core/dist/runtime-v2/store/intent/__tests__/sqlite-intent-decision-store.test.js.map +1 -0
  244. package/core/dist/runtime-v2/store/intent/index.d.ts +6 -0
  245. package/core/dist/runtime-v2/store/intent/index.d.ts.map +1 -0
  246. package/core/dist/runtime-v2/store/intent/index.js +5 -0
  247. package/core/dist/runtime-v2/store/intent/index.js.map +1 -0
  248. package/core/dist/runtime-v2/store/intent/sqlite-intent-decision-store.d.ts +51 -0
  249. package/core/dist/runtime-v2/store/intent/sqlite-intent-decision-store.d.ts.map +1 -0
  250. package/core/dist/runtime-v2/store/intent/sqlite-intent-decision-store.js +306 -0
  251. package/core/dist/runtime-v2/store/intent/sqlite-intent-decision-store.js.map +1 -0
  252. package/core/dist/runtime-v2/store/sqlite-connection-pragma.test.js +14 -3
  253. package/core/dist/runtime-v2/store/sqlite-connection-pragma.test.js.map +1 -1
  254. package/core/dist/runtime-v2/store/sqlite-connection-schema-version.test.d.ts +2 -0
  255. package/core/dist/runtime-v2/store/sqlite-connection-schema-version.test.d.ts.map +1 -0
  256. package/core/dist/runtime-v2/store/sqlite-connection-schema-version.test.js +72 -0
  257. package/core/dist/runtime-v2/store/sqlite-connection-schema-version.test.js.map +1 -0
  258. package/core/dist/runtime-v2/store/sqlite-connection.d.ts +27 -0
  259. package/core/dist/runtime-v2/store/sqlite-connection.d.ts.map +1 -1
  260. package/core/dist/runtime-v2/store/sqlite-connection.js +124 -12
  261. package/core/dist/runtime-v2/store/sqlite-connection.js.map +1 -1
  262. package/core/dist/runtime-v2/types/event-payload.d.ts +1 -20
  263. package/core/dist/runtime-v2/types/event-payload.d.ts.map +1 -1
  264. package/core/dist/runtime-v2/types/event-payload.js +0 -12
  265. package/core/dist/runtime-v2/types/event-payload.js.map +1 -1
  266. package/core/dist/runtime-v2/types/event-types.d.ts +5 -34
  267. package/core/dist/runtime-v2/types/event-types.d.ts.map +1 -1
  268. package/core/dist/runtime-v2/types/event-types.js +0 -19
  269. package/core/dist/runtime-v2/types/event-types.js.map +1 -1
  270. package/core/dist/runtime-v2/types/evidence-chain-contract.d.ts +63 -0
  271. package/core/dist/runtime-v2/types/evidence-chain-contract.d.ts.map +1 -1
  272. package/core/dist/runtime-v2/types/evidence-chain-contract.js +234 -9
  273. package/core/dist/runtime-v2/types/evidence-chain-contract.js.map +1 -1
  274. package/core/dist/runtime-v2/types/index.d.ts +5 -5
  275. package/core/dist/runtime-v2/types/index.d.ts.map +1 -1
  276. package/core/dist/runtime-v2/types/index.js +5 -3
  277. package/core/dist/runtime-v2/types/index.js.map +1 -1
  278. package/core/dist/runtime-v2/types/ledger-store.d.ts +30 -30
  279. package/core/dist/runtime-v2/types/ledger-store.d.ts.map +1 -1
  280. package/core/dist/runtime-v2/types/ledger-store.js +10 -5
  281. package/core/dist/runtime-v2/types/ledger-store.js.map +1 -1
  282. package/core/dist/workflow-funnel-loader.d.ts +2 -2
  283. package/core/dist/workflow-funnel-loader.d.ts.map +1 -1
  284. package/dist/installer.d.ts.map +1 -1
  285. package/dist/installer.js +16 -0
  286. package/dist/installer.js.map +1 -1
  287. package/package.json +1 -1
  288. package/pd-cli/dist/commands/__tests__/intent-flag-wiring.test.d.ts +9 -0
  289. package/pd-cli/dist/commands/__tests__/intent-flag-wiring.test.d.ts.map +1 -0
  290. package/pd-cli/dist/commands/__tests__/intent-flag-wiring.test.js +166 -0
  291. package/pd-cli/dist/commands/__tests__/intent-flag-wiring.test.js.map +1 -0
  292. package/pd-cli/dist/commands/intent.d.ts +59 -0
  293. package/pd-cli/dist/commands/intent.d.ts.map +1 -0
  294. package/pd-cli/dist/commands/intent.js +350 -0
  295. package/pd-cli/dist/commands/intent.js.map +1 -0
  296. package/pd-cli/dist/commands/runtime-init.d.ts +43 -0
  297. package/pd-cli/dist/commands/runtime-init.d.ts.map +1 -0
  298. package/pd-cli/dist/commands/runtime-init.js +264 -0
  299. package/pd-cli/dist/commands/runtime-init.js.map +1 -0
  300. package/pd-cli/dist/index.js +25 -0
  301. package/pd-cli/dist/index.js.map +1 -1
  302. package/pd-cli/dist/services/demo-story-a-runner.d.ts.map +1 -1
  303. package/pd-cli/dist/services/demo-story-a-runner.js +6 -0
  304. package/pd-cli/dist/services/demo-story-a-runner.js.map +1 -1
  305. package/pd-cli/package.json +1 -0
  306. package/plugin/dist/commands/pain.js +2 -0
  307. package/plugin/dist/core/control-ui-db.d.ts +11 -0
  308. package/plugin/dist/core/control-ui-db.js +40 -16
  309. package/plugin/dist/core/event-log.js +0 -5
  310. package/plugin/dist/core/intent-doc-reader-adapter.d.ts +28 -0
  311. package/plugin/dist/core/intent-doc-reader-adapter.js +56 -0
  312. package/plugin/dist/core/intent-doc-reader.d.ts +80 -0
  313. package/plugin/dist/core/intent-doc-reader.js +189 -0
  314. package/plugin/dist/core/principle-tree-ledger.d.ts +27 -79
  315. package/plugin/dist/core/principle-tree-ledger.js +39 -524
  316. package/plugin/dist/core/reflection/reflection-context.d.ts +2 -2
  317. package/plugin/dist/core/trajectory.d.ts +16 -0
  318. package/plugin/dist/core/trajectory.js +332 -254
  319. package/plugin/dist/core/workspace-context.d.ts +2 -3
  320. package/plugin/dist/hooks/pain.js +5 -0
  321. package/plugin/dist/hooks/prompt-helpers.d.ts +19 -1
  322. package/plugin/dist/hooks/prompt-helpers.js +39 -2
  323. package/plugin/dist/hooks/prompt-types.d.ts +8 -0
  324. package/plugin/dist/hooks/prompt.js +80 -21
  325. package/plugin/dist/index.d.ts +3 -1
  326. package/plugin/dist/index.js +9 -5
  327. package/plugin/dist/service/runtime-summary-service.js +1 -1
  328. package/plugin/dist/service/subagent-workflow/workflow-store.d.ts +14 -0
  329. package/plugin/dist/service/subagent-workflow/workflow-store.js +91 -2
  330. package/plugin/dist/types/event-types.d.ts +1 -1
  331. package/plugin/package.json +6 -3
  332. package/plugin/scripts/acceptance-test.mjs +3 -3
  333. package/plugin/dist/core/principle-tree-ledger-adapter.d.ts +0 -32
  334. package/plugin/dist/core/principle-tree-ledger-adapter.js +0 -125
  335. package/plugin/dist/service/central-database.d.ts +0 -138
  336. package/plugin/dist/service/central-database.js +0 -731
  337. package/plugin/dist/service/central-sync-service.d.ts +0 -8
  338. package/plugin/dist/service/central-sync-service.js +0 -71
  339. package/plugin/scripts/validate-live-path.ts +0 -462
@@ -0,0 +1,189 @@
1
+ /**
2
+ * PRI-467 — safeReadIntentDoc: plugin I/O wrapper for reading INTENT.md.
3
+ *
4
+ * Reads `.principles/INTENT.md` with:
5
+ * - Feature flag check FIRST (SPEC §12: flag off → flag_disabled without fs)
6
+ * - TTL + mtime cache (60s TTL, mtime check) mirroring prompt.ts cachedReadFile
7
+ * - 32KB size cap (INTENT_MAX_BYTES)
8
+ * - Never throws — all errors return structured `reason` + `nextAction`
9
+ *
10
+ * Trust boundary (SPEC §12.2):
11
+ * - Raw content is returned for the pure builder to escape; this reader does
12
+ * NOT escape or bound the content for prompt injection. The pure builder
13
+ * `buildIntentFrictionBlock` handles escaping + bounding.
14
+ *
15
+ * ERR checklist:
16
+ * EP-01 / ERR-001, ERR-005: raw content validated with typeof, never `as`
17
+ * EP-02 / ERR-025, ERR-070: production path; plugin I/O file in the whitelist
18
+ * EP-03 / ERR-002, ERR-014: every degraded path returns structured reason + nextAction
19
+ * EP-09: tests use real fs writes in temp dirs
20
+ *
21
+ * Architecture: this file is I/O (fs, path). It is whitelisted in
22
+ * architecture-regression.test.ts KNOWN_PLUGIN_CORE_FILES.
23
+ */
24
+ import * as fs from 'node:fs';
25
+ import * as path from 'node:path';
26
+ import { INTENT_MAX_BYTES, parseIntentDocSections, computeIntentContentHash, validateIntentDocSections, } from '@principles/core/runtime-v2';
27
+ import { loadFeatureFlagFromConfig } from './pd-config-loader.js';
28
+ // ── Constants ────────────────────────────────────────────────────────────────
29
+ const INTENT_FILENAME = 'INTENT.md';
30
+ const INTENT_DIR = '.principles';
31
+ const INTENT_CACHE_TTL_MS = 60_000; // 1 minute (SPEC §12.1)
32
+ // ── Module-level cache (per-workspace) ───────────────────────────────────────
33
+ const _intentDocCache = new Map();
34
+ /**
35
+ * Reset the intent doc cache for test isolation.
36
+ * Call in beforeEach() to ensure tests don't pollute each other.
37
+ */
38
+ export function resetIntentDocCacheForTest(workspaceDir) {
39
+ if (workspaceDir) {
40
+ _intentDocCache.delete(workspaceDir);
41
+ }
42
+ else {
43
+ _intentDocCache.clear();
44
+ }
45
+ }
46
+ // ── Helpers ──────────────────────────────────────────────────────────────────
47
+ function getIntentFilePath(workspaceDir) {
48
+ return path.join(workspaceDir, INTENT_DIR, INTENT_FILENAME);
49
+ }
50
+ function buildDocFromRaw(raw, filePath, readAt) {
51
+ const sections = parseIntentDocSections(raw);
52
+ const warnings = validateIntentDocSections(sections);
53
+ const contentHash = computeIntentContentHash(raw);
54
+ return {
55
+ raw,
56
+ sections,
57
+ contentHash,
58
+ path: filePath,
59
+ readAt,
60
+ warnings,
61
+ };
62
+ }
63
+ // ── Main entrypoint ──────────────────────────────────────────────────────────
64
+ /**
65
+ * Safely read INTENT.md for prompt injection.
66
+ *
67
+ * Contract (SPEC §12):
68
+ * 1. Flag check FIRST via loadFeatureFlagFromConfig. Flag off → flag_disabled
69
+ * WITHOUT any fs access to INTENT.md.
70
+ * 2. Flag on → check TTL + mtime cache. If cached and fresh → return cached.
71
+ * 3. Otherwise → stat the file (oversized check), read, parse, validate, cache.
72
+ * 4. Never throws — all errors return structured reason + nextAction.
73
+ *
74
+ * @param workspaceDir - Absolute path to the workspace root
75
+ * @param options - Optional logger for debug-level diagnostics
76
+ * @returns SafeReadIntentDocResult (never throws)
77
+ */
78
+ export function safeReadIntentDoc(workspaceDir, options) {
79
+ // SPEC §12 — Flag check FIRST. Flag off → no fs access, no cache access.
80
+ const flagResult = loadFeatureFlagFromConfig(workspaceDir, 'intent_engineering', options?.logger);
81
+ if (!flagResult.enabled) {
82
+ return {
83
+ ok: false,
84
+ found: false,
85
+ flagEnabled: false,
86
+ reason: 'flag_disabled',
87
+ nextAction: 'Enable the intent_engineering feature flag in .pd/config.yaml to read INTENT.md.',
88
+ warnings: [],
89
+ };
90
+ }
91
+ const filePath = getIntentFilePath(workspaceDir);
92
+ const now = Date.now();
93
+ // Check cache freshness (TTL + mtime)
94
+ const cached = _intentDocCache.get(workspaceDir);
95
+ if (cached && (now - cached.loadedAt) < INTENT_CACHE_TTL_MS) {
96
+ // Cache is within TTL. Verify mtime hasn't changed.
97
+ try {
98
+ const stat = fs.statSync(filePath);
99
+ if (stat.mtimeMs === cached.mtime) {
100
+ // Cache hit — return cached doc
101
+ return {
102
+ ok: true,
103
+ found: true,
104
+ flagEnabled: true,
105
+ doc: cached.doc,
106
+ warnings: cached.doc.warnings,
107
+ };
108
+ }
109
+ }
110
+ catch {
111
+ // File may have been deleted since caching. Fall through to not_found path.
112
+ // Don't return cached doc if the file no longer exists.
113
+ }
114
+ }
115
+ // Fresh read path
116
+ try {
117
+ // Check existence first
118
+ if (!fs.existsSync(filePath)) {
119
+ // Invalidate stale cache entry if any
120
+ _intentDocCache.delete(workspaceDir);
121
+ return {
122
+ ok: false,
123
+ found: false,
124
+ flagEnabled: true,
125
+ reason: 'not_found',
126
+ nextAction: 'Create .principles/INTENT.md using "pd intent init".',
127
+ warnings: [],
128
+ };
129
+ }
130
+ const stat = fs.statSync(filePath);
131
+ // SPEC §12 — 32KB size cap
132
+ if (stat.size > INTENT_MAX_BYTES) {
133
+ _intentDocCache.delete(workspaceDir);
134
+ return {
135
+ ok: false,
136
+ found: true,
137
+ flagEnabled: true,
138
+ reason: 'oversized',
139
+ nextAction: `INTENT.md exceeds ${INTENT_MAX_BYTES} bytes (${stat.size} bytes). Reduce content.`,
140
+ warnings: [],
141
+ };
142
+ }
143
+ const raw = fs.readFileSync(filePath, 'utf8');
144
+ // PRI-467 review fix (P2): TOCTOU guard — re-check actual byte length
145
+ // after readFileSync. The file may have grown between statSync() and
146
+ // readFileSync(), bypassing the stat.size oversized check. Without this,
147
+ // an oversized file would enter parse/hash/cache as ok:true.
148
+ const actualBytes = Buffer.byteLength(raw, 'utf8');
149
+ if (actualBytes > INTENT_MAX_BYTES) {
150
+ _intentDocCache.delete(workspaceDir);
151
+ return {
152
+ ok: false,
153
+ found: true,
154
+ flagEnabled: true,
155
+ reason: 'oversized',
156
+ nextAction: `INTENT.md exceeds ${INTENT_MAX_BYTES} bytes (${actualBytes} bytes after read). Reduce content.`,
157
+ warnings: [],
158
+ };
159
+ }
160
+ const doc = buildDocFromRaw(raw, filePath, new Date(now).toISOString());
161
+ // Update cache
162
+ _intentDocCache.set(workspaceDir, {
163
+ doc,
164
+ mtime: stat.mtimeMs,
165
+ loadedAt: now,
166
+ });
167
+ return {
168
+ ok: true,
169
+ found: true,
170
+ flagEnabled: true,
171
+ doc,
172
+ warnings: doc.warnings,
173
+ };
174
+ }
175
+ catch (err) {
176
+ // ERR-002 — graceful degradation with reason + nextAction
177
+ _intentDocCache.delete(workspaceDir);
178
+ const message = err instanceof Error ? err.message : String(err);
179
+ options?.logger?.warn?.(`[PD:Intent] safeReadIntentDoc failed: workspace=${workspaceDir}, error=${message}`);
180
+ return {
181
+ ok: false,
182
+ found: false,
183
+ flagEnabled: true,
184
+ reason: 'read_error',
185
+ nextAction: 'Check filesystem permissions for .principles/INTENT.md.',
186
+ warnings: [],
187
+ };
188
+ }
189
+ }
@@ -1,82 +1,30 @@
1
- import type { Implementation, ImplementationLifecycleState, Principle, PrincipleTreeStore, PrincipleValueMetrics, Rule } from '../types/principle-tree-schema.js';
2
- export declare const TREE_NAMESPACE = "_tree";
3
- export interface LegacyPrincipleTrainingState {
4
- principleId: string;
5
- evaluability: 'deterministic' | 'weak_heuristic' | 'manual_only';
6
- applicableOpportunityCount: number;
7
- observedViolationCount: number;
8
- complianceRate: number;
9
- violationTrend: number;
10
- generatedSampleCount: number;
11
- approvedSampleCount: number;
12
- includedTrainRunIds: string[];
13
- deployedCheckpointIds: string[];
14
- lastEvalScore?: number;
15
- internalizationStatus: 'prompt_only' | 'needs_training' | 'in_training' | 'deployed_pending_eval' | 'internalized' | 'regressed';
16
- }
17
- export type LegacyPrincipleTrainingStore = Record<string, LegacyPrincipleTrainingState>;
18
- export interface LedgerPrinciple extends Principle {
19
- suggestedRules?: string[];
20
- }
21
- export interface LedgerRule extends Rule {
22
- implementationIds: string[];
23
- }
24
- export interface LedgerTreeStore extends Omit<PrincipleTreeStore, 'principles' | 'rules'> {
25
- principles: Record<string, LedgerPrinciple>;
26
- rules: Record<string, LedgerRule>;
27
- }
28
- export interface HybridLedgerStore {
29
- trainingStore: LegacyPrincipleTrainingStore;
30
- tree: LedgerTreeStore;
31
- }
32
- export interface PrincipleSubtree {
33
- principle: LedgerPrinciple;
34
- rules: {
35
- rule: LedgerRule;
36
- implementations: Implementation[];
37
- }[];
38
- }
39
- export declare function getLedgerFilePath(stateDir: string): string;
40
- export declare function loadLedger(stateDir: string): HybridLedgerStore;
41
- export declare function saveLedger(stateDir: string, store: HybridLedgerStore): void;
42
- export declare function saveLedgerAsync(stateDir: string, store: HybridLedgerStore): Promise<void>;
43
- export declare function updateTrainingStore(stateDir: string, mutate: (store: LegacyPrincipleTrainingStore) => void): void;
44
1
  /**
45
- * Add a new principle directly to the ledger tree.
46
- * This is the companion to updatePrinciple() — use this when creating a NEW
47
- * principle so the compiler can find it in tree.principles.
2
+ * Principle Tree Ledger plugin adapter (re-export) over @principles/core.
48
3
  *
49
- * Idempotent: if the principle already exists, overwrites (update semantics).
50
- */
51
- export declare function addPrincipleToLedger(stateDir: string, principle: LedgerPrinciple): LedgerPrinciple;
52
- export declare function createRule(stateDir: string, rule: LedgerRule): LedgerRule;
53
- export declare function createImplementation(stateDir: string, implementation: Implementation): Implementation;
54
- export declare function updatePrinciple(stateDir: string, principleId: string, updates: Partial<LedgerPrinciple>): LedgerPrinciple;
55
- export declare function updateRule(stateDir: string, ruleId: string, updates: Partial<LedgerRule>): LedgerRule;
56
- export declare function deleteRule(stateDir: string, ruleId: string): LedgerRule | undefined;
57
- export declare function updateImplementation(stateDir: string, implementationId: string, updates: Partial<Implementation>): Implementation;
58
- export declare function deleteImplementation(stateDir: string, implementationId: string): Implementation | undefined;
59
- export declare function listImplementationsForRule(stateDir: string, ruleId: string): Implementation[];
60
- export declare function getPrincipleSubtree(stateDir: string, principleId: string): PrincipleSubtree | undefined;
61
- export declare function updatePrincipleValueMetrics(stateDir: string, principleId: string, metrics: PrincipleValueMetrics): PrincipleValueMetrics;
62
- /**
63
- * Validate a lifecycle state transition.
64
- * Returns true if the transition is valid, false otherwise.
65
- */
66
- export declare function isValidLifecycleTransition(from: ImplementationLifecycleState, to: ImplementationLifecycleState): boolean;
67
- /**
68
- * Get allowed transitions for a given lifecycle state.
69
- */
70
- export declare function getAllowedTransitions(from: ImplementationLifecycleState): ImplementationLifecycleState[];
71
- /**
72
- * Transition an implementation's lifecycle state with validation.
73
- * Throws on invalid transitions */
74
- export declare function transitionImplementationState(stateDir: string, implementationId: string, newState: ImplementationLifecycleState): Implementation;
75
- /**
76
- * Get implementations in a specific lifecycle state for a given rule.
77
- */
78
- export declare function listRuleImplementationsByState(stateDir: string, ruleId: string, state: ImplementationLifecycleState): Implementation[];
79
- /**
80
- * Find active implementation for a rule (helper for rule host lookup).
4
+ * PRI-459: This file WAS a full duplicate implementation of
5
+ * principle_training_state.json parsing / serialization / mutation (~600
6
+ * lines of inlined parsers, serializers, mutators, and a parallel codec).
7
+ * That dual ownership caused two real failure classes:
8
+ *
9
+ * 1. Lost updates core wrote the file UNLOCKED, the plugin wrote it WITH
10
+ * a lock, and neither knew the other's lock. Concurrent writers (e.g.
11
+ * evolution-worker async + a pd-cli command) could silently drop edits.
12
+ * 2. Silent field loss the two codecs parsed the same bytes at different
13
+ * strictness; a field one side persisted could be dropped on the next
14
+ * load by the other.
15
+ *
16
+ * Both are now fixed by converging on a SINGLE source of truth in core:
17
+ * - parse/serialize: @principles/core/runtime-v2/principle-tree/ledger-codec
18
+ * - mutation (with cross-process file lock): @principles/core/principle-tree-ledger
19
+ *
20
+ * This file is now a thin re-export so existing relative imports
21
+ * (`from './principle-tree-ledger.js'`) keep resolving. Consumers get the
22
+ * exact same API surface, now backed by the locked core implementation.
23
+ *
24
+ * Do NOT reintroduce parsing / serialization / mutation logic here. The
25
+ * architecture-regression guard "PRI-459: single principle_training_state
26
+ * ledger implementation" enforces this.
81
27
  */
82
- export declare function findActiveImplementation(stateDir: string, ruleId: string): Implementation | null;
28
+ export { type Principle, type Rule, type Implementation, type PrincipleValueMetrics, type LedgerPrinciple, type LedgerRule, type LedgerTreeStore, type LegacyPrincipleTrainingState, type LegacyPrincipleTrainingStore, type HybridLedgerStore, type ImplementationLifecycleState, type PrincipleSubtree, TREE_NAMESPACE, LockAcquisitionError, loadLedger, saveLedger, saveLedgerAsync, updateTrainingStore, addPrincipleToLedger, createRule, createImplementation, updatePrinciple, updateRule, deleteRule, updateImplementation, deleteImplementation, listImplementationsForRule, getPrincipleSubtree, updatePrincipleValueMetrics, isValidLifecycleTransition, getAllowedTransitions, transitionImplementationState, listRuleImplementationsByState, findActiveImplementation, } from '@principles/core/principle-tree-ledger';
29
+ import { getLedgerFilePathPublic } from '@principles/core/principle-tree-ledger';
30
+ export declare const getLedgerFilePath: typeof getLedgerFilePathPublic;