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,350 @@
1
+ /**
2
+ * pd intent — Owner-authored INTENT.md management (PRI-466).
3
+ *
4
+ * Subcommands:
5
+ * - init : create .principles/INTENT.md from the canonical template
6
+ * - show : display a read-only summary of INTENT.md (sections, hash, warnings)
7
+ *
8
+ * `init` is not gated by the intent_engineering flag — the Owner can
9
+ * initialise the intent doc at any time. `show` IS gated: flag-off returns
10
+ * a structured `flag_disabled` result without touching the filesystem,
11
+ * matching the Console backend contract.
12
+ *
13
+ * JSON mode is strict: --json outputs exactly one parseable JSON object on
14
+ * stdout (CLI Operator Gate rule 1). Failure paths include structured
15
+ * reason + nextAction (rule 6).
16
+ *
17
+ * ERR refs:
18
+ * - ERR-001 (no any): all types explicit
19
+ * - ERR-005 (no as bypass): no type casts on untrusted data
20
+ * - ERR-002 (graceful degradation with reason): all failure paths include
21
+ * reason + nextAction
22
+ * - ERR-009 (fail loud): missing file / flag-off surfaced explicitly
23
+ */
24
+ import * as fs from 'node:fs';
25
+ import * as path from 'node:path';
26
+ import { INTENT_MAX_BYTES, INTENT_DOC_TEMPLATE, parseIntentDocSections, computeIntentContentHash, validateIntentDocSections, isFeatureEnabled, } from '@principles/core/runtime-v2';
27
+ import { resolveWorkspaceDir } from '../resolve-workspace.js';
28
+ import { loadPdConfig, computeFlagsFromLoadResult } from '../services/pd-config-loader.js';
29
+ import { emitResult } from '../services/cli-output.js';
30
+ // ── Constants ────────────────────────────────────────────────────────────────
31
+ const INTENT_DIR = '.principles';
32
+ const INTENT_FILENAME = 'INTENT.md';
33
+ // ── Helpers ──────────────────────────────────────────────────────────────────
34
+ function getIntentFilePath(workspaceDir) {
35
+ return path.join(workspaceDir, INTENT_DIR, INTENT_FILENAME);
36
+ }
37
+ function sectionsToRecord(sections) {
38
+ const record = {};
39
+ if (sections.why !== undefined) {
40
+ record.why = sections.why;
41
+ }
42
+ if (sections.desiredOutcome !== undefined) {
43
+ record.desiredOutcome = sections.desiredOutcome;
44
+ }
45
+ if (sections.nonNegotiables !== undefined) {
46
+ record.nonNegotiables = sections.nonNegotiables;
47
+ }
48
+ if (sections.stopEscalation !== undefined) {
49
+ record.stopEscalation = sections.stopEscalation;
50
+ }
51
+ if (sections.currentStrategicFocus !== undefined) {
52
+ record.currentStrategicFocus = sections.currentStrategicFocus;
53
+ }
54
+ return record;
55
+ }
56
+ function formatIntentShowText(o) {
57
+ const lines = [];
58
+ lines.push(`INTENT.md — ${o.path}`);
59
+ lines.push(`Content hash: ${o.contentHash}`);
60
+ lines.push(`Last edited: ${o.lastEditedAt}`);
61
+ lines.push('');
62
+ if (o.sections) {
63
+ if (o.sections.why) {
64
+ lines.push('## 1. Why');
65
+ lines.push(o.sections.why);
66
+ lines.push('');
67
+ }
68
+ if (o.sections.desiredOutcome) {
69
+ lines.push('## 2. Desired Outcome');
70
+ lines.push(o.sections.desiredOutcome);
71
+ lines.push('');
72
+ }
73
+ if (o.sections.nonNegotiables) {
74
+ lines.push('## 3. Non-negotiables');
75
+ lines.push(o.sections.nonNegotiables);
76
+ lines.push('');
77
+ }
78
+ if (o.sections.stopEscalation) {
79
+ lines.push('## 4. Stop / Escalation');
80
+ lines.push(o.sections.stopEscalation);
81
+ lines.push('');
82
+ }
83
+ if (o.sections.currentStrategicFocus) {
84
+ lines.push('## 5. Current Strategic Focus');
85
+ lines.push(o.sections.currentStrategicFocus);
86
+ lines.push('');
87
+ }
88
+ }
89
+ if (o.warnings.length > 0) {
90
+ lines.push('Warnings:');
91
+ for (const w of o.warnings) {
92
+ lines.push(` [${w.code}] ${w.message}`);
93
+ }
94
+ }
95
+ else {
96
+ lines.push('No warnings.');
97
+ }
98
+ return lines.join('\n');
99
+ }
100
+ export async function handleIntentInit(opts) {
101
+ // CLI Gate rule 4: --dry-run and --confirm must be mutually exclusive.
102
+ if (opts.dryRun && opts.confirm) {
103
+ const output = {
104
+ status: 'skipped',
105
+ path: '',
106
+ overwritten: false,
107
+ reason: 'flag_conflict',
108
+ nextAction: 'Use either --dry-run or --confirm, not both.',
109
+ };
110
+ emitResult(output, {
111
+ json: opts.json ?? false,
112
+ formatText: (o) => `Error: ${o.reason}\n→ ${o.nextAction}`,
113
+ });
114
+ process.exitCode = 1;
115
+ return;
116
+ }
117
+ // CLI Gate rule 6: workspace resolution inside try/catch so failures emit
118
+ // structured JSON with reason + nextAction instead of an uncaught stack trace.
119
+ let workspaceDir;
120
+ let filePath;
121
+ let dir;
122
+ try {
123
+ workspaceDir = resolveWorkspaceDir(opts.workspace);
124
+ filePath = getIntentFilePath(workspaceDir);
125
+ dir = path.dirname(filePath);
126
+ }
127
+ catch (err) {
128
+ const reason = err instanceof Error ? err.message : String(err);
129
+ const output = {
130
+ status: 'read_error',
131
+ path: '',
132
+ overwritten: false,
133
+ reason,
134
+ nextAction: 'Provide a valid --workspace <path> argument.',
135
+ };
136
+ emitResult(output, {
137
+ json: opts.json ?? false,
138
+ formatText: (o) => `Error: ${o.reason}\n→ ${o.nextAction}`,
139
+ });
140
+ process.exitCode = 1;
141
+ return;
142
+ }
143
+ // CLI Gate rule 4: state-mutating command defaults to dry-run unless --confirm.
144
+ const isDryRun = opts.dryRun === true || opts.confirm !== true;
145
+ try {
146
+ if (fs.existsSync(filePath) && !opts.force) {
147
+ const output = {
148
+ status: 'skipped',
149
+ path: filePath,
150
+ overwritten: false,
151
+ reason: 'file_exists',
152
+ nextAction: `Use --force to overwrite: pd intent init --force --confirm --workspace "${workspaceDir}"`,
153
+ };
154
+ emitResult(output, {
155
+ json: opts.json ?? false,
156
+ formatText: (o) => `INTENT.md already exists at ${o.path}\n→ ${o.nextAction}`,
157
+ });
158
+ process.exitCode = 1;
159
+ return;
160
+ }
161
+ if (isDryRun) {
162
+ const output = {
163
+ status: 'dry_run',
164
+ path: filePath,
165
+ overwritten: opts.force === true,
166
+ reason: 'dry_run',
167
+ nextAction: `Confirm write: pd intent init --confirm${opts.force ? ' --force' : ''} --workspace "${workspaceDir}"`,
168
+ };
169
+ emitResult(output, {
170
+ json: opts.json ?? false,
171
+ formatText: (o) => `[dry-run] Would create INTENT.md at ${o.path}${o.overwritten ? ' (overwritten)' : ''}\n→ ${o.nextAction}`,
172
+ });
173
+ return;
174
+ }
175
+ fs.mkdirSync(dir, { recursive: true });
176
+ fs.writeFileSync(filePath, INTENT_DOC_TEMPLATE, 'utf8');
177
+ const output = {
178
+ status: 'ok',
179
+ path: filePath,
180
+ overwritten: opts.force === true,
181
+ };
182
+ emitResult(output, {
183
+ json: opts.json ?? false,
184
+ formatText: (o) => `Created INTENT.md at ${o.path}${o.overwritten ? ' (overwritten)' : ''}\nNext: edit the file to declare your project intent, then run "pd intent show".`,
185
+ });
186
+ }
187
+ catch (err) {
188
+ const reason = err instanceof Error ? err.message : String(err);
189
+ // CLI Gate rule 1: route through emitResult for consistent IntentInitOutput shape.
190
+ const output = {
191
+ status: 'read_error',
192
+ path: filePath,
193
+ overwritten: false,
194
+ reason,
195
+ nextAction: `Check filesystem permissions for ${filePath}`,
196
+ };
197
+ emitResult(output, {
198
+ json: opts.json ?? false,
199
+ formatText: (o) => `Error: ${o.reason}\n→ ${o.nextAction}`,
200
+ });
201
+ process.exitCode = 1;
202
+ }
203
+ }
204
+ export async function handleIntentShow(opts) {
205
+ // CLI Gate rule 6: workspace resolution inside try/catch for structured errors.
206
+ let workspaceDir;
207
+ try {
208
+ workspaceDir = resolveWorkspaceDir(opts.workspace);
209
+ }
210
+ catch (err) {
211
+ const reason = err instanceof Error ? err.message : String(err);
212
+ const output = {
213
+ status: 'read_error',
214
+ flagEnabled: false,
215
+ found: false,
216
+ warnings: [],
217
+ reason,
218
+ nextAction: 'Provide a valid --workspace <path> argument.',
219
+ };
220
+ emitResult(output, {
221
+ json: opts.json ?? false,
222
+ formatText: (o) => `Error: ${o.reason}\n→ ${o.nextAction}`,
223
+ });
224
+ process.exitCode = 1;
225
+ return;
226
+ }
227
+ // Flag check — flag-off short-circuits without fs access
228
+ const configResult = loadPdConfig(workspaceDir);
229
+ const flagsResult = computeFlagsFromLoadResult(configResult);
230
+ const flagEnabled = isFeatureEnabled(flagsResult, 'intent_engineering');
231
+ if (!flagEnabled) {
232
+ const output = {
233
+ status: 'flag_disabled',
234
+ flagEnabled: false,
235
+ found: false,
236
+ warnings: [],
237
+ reason: 'flag_disabled',
238
+ nextAction: 'Enable the intent_engineering feature flag in .pd/config.yaml to read INTENT.md.',
239
+ };
240
+ emitResult(output, {
241
+ json: opts.json ?? false,
242
+ formatText: (o) => `Intent Engineering is disabled (flag off).\n→ ${o.nextAction}`,
243
+ });
244
+ return;
245
+ }
246
+ const filePath = getIntentFilePath(workspaceDir);
247
+ try {
248
+ if (!fs.existsSync(filePath)) {
249
+ const output = {
250
+ status: 'not_found',
251
+ flagEnabled: true,
252
+ found: false,
253
+ warnings: [],
254
+ reason: 'not_found',
255
+ nextAction: `Create INTENT.md: pd intent init --workspace "${workspaceDir}"`,
256
+ };
257
+ emitResult(output, {
258
+ json: opts.json ?? false,
259
+ formatText: (o) => `INTENT.md not found.\n→ ${o.nextAction}`,
260
+ });
261
+ return;
262
+ }
263
+ const stat = fs.statSync(filePath);
264
+ if (stat.size > INTENT_MAX_BYTES) {
265
+ const output = {
266
+ status: 'oversized',
267
+ flagEnabled: true,
268
+ found: true,
269
+ warnings: [],
270
+ reason: 'oversized',
271
+ nextAction: `INTENT.md exceeds ${INTENT_MAX_BYTES} bytes (${stat.size} bytes). Reduce content.`,
272
+ };
273
+ emitResult(output, {
274
+ json: opts.json ?? false,
275
+ formatText: (o) => `INTENT.md is too large.\n→ ${o.nextAction}`,
276
+ });
277
+ return;
278
+ }
279
+ const raw = fs.readFileSync(filePath, 'utf8');
280
+ const sections = parseIntentDocSections(raw);
281
+ const warnings = validateIntentDocSections(sections);
282
+ const contentHash = computeIntentContentHash(raw);
283
+ const output = {
284
+ status: 'ok',
285
+ flagEnabled: true,
286
+ found: true,
287
+ path: filePath,
288
+ contentHash,
289
+ lastEditedAt: stat.mtime.toISOString(),
290
+ sections: sectionsToRecord(sections),
291
+ warnings,
292
+ };
293
+ emitResult(output, {
294
+ json: opts.json ?? false,
295
+ formatText: (o) => formatIntentShowText(o),
296
+ });
297
+ }
298
+ catch (err) {
299
+ const reason = err instanceof Error ? err.message : String(err);
300
+ const output = {
301
+ status: 'read_error',
302
+ flagEnabled: true,
303
+ found: false,
304
+ warnings: [],
305
+ reason,
306
+ nextAction: `Check filesystem permissions for ${filePath}`,
307
+ };
308
+ emitResult(output, {
309
+ json: opts.json ?? false,
310
+ formatText: (o) => `Error reading INTENT.md: ${o.reason}\n→ ${o.nextAction}`,
311
+ });
312
+ process.exitCode = 1;
313
+ }
314
+ }
315
+ // ── Command registration ─────────────────────────────────────────────────────
316
+ export function registerIntentCommand(parentCmd) {
317
+ const intentCmd = parentCmd
318
+ .command('intent')
319
+ .description('Owner-authored INTENT.md management (init, show)');
320
+ intentCmd
321
+ .command('init')
322
+ .description('Create .principles/INTENT.md from the canonical template')
323
+ .option('-w, --workspace <path>', 'Workspace directory')
324
+ .option('--force', 'Overwrite existing INTENT.md')
325
+ .option('--dry-run', 'Show what would happen without writing (default)')
326
+ .option('--confirm', 'Actually write the file (required to create INTENT.md)')
327
+ .option('--json', 'Output raw JSON')
328
+ .action(async (opts) => {
329
+ await handleIntentInit({
330
+ workspace: opts.workspace,
331
+ force: opts.force === true,
332
+ json: opts.json === true,
333
+ dryRun: opts.dryRun === true,
334
+ confirm: opts.confirm === true,
335
+ });
336
+ });
337
+ intentCmd
338
+ .command('show')
339
+ .description('Display a read-only summary of INTENT.md (sections, hash, warnings)')
340
+ .option('-w, --workspace <path>', 'Workspace directory')
341
+ .option('--json', 'Output raw JSON')
342
+ .action(async (opts) => {
343
+ await handleIntentShow({
344
+ workspace: opts.workspace,
345
+ json: opts.json === true,
346
+ });
347
+ });
348
+ return intentCmd;
349
+ }
350
+ //# sourceMappingURL=intent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"intent.js","sourceRoot":"","sources":["../../src/commands/intent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAElC,OAAO,EACL,gBAAgB,EAChB,mBAAmB,EACnB,sBAAsB,EACtB,wBAAwB,EACxB,yBAAyB,EACzB,gBAAgB,GACjB,MAAM,6BAA6B,CAAC;AAErC,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAC;AAC3F,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAEvD,gFAAgF;AAEhF,MAAM,UAAU,GAAG,aAAa,CAAC;AACjC,MAAM,eAAe,GAAG,WAAW,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AAE;QACrB,MAAM,gBAAgB,CAAC;YACrB,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,KAAK,EAAE,IAAI,CAAC,KAAK,KAAK,IAAI;YAC1B,IAAI,EAAE,IAAI,CAAC,IAAI,KAAK,IAAI;YACxB,MAAM,EAAE,IAAI,CAAC,MAAM,KAAK,IAAI;YAC5B,OAAO,EAAE,IAAI,CAAC,OAAO,KAAK,IAAI;SAC/B,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEL,SAAS;SACN,OAAO,CAAC,MAAM,CAAC;SACf,WAAW,CAAC,qEAAqE,CAAC;SAClF,MAAM,CAAC,wBAAwB,EAAE,qBAAqB,CAAC;SACvD,MAAM,CAAC,QAAQ,EAAE,iBAAiB,CAAC;SACnC,MAAM,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;QACrB,MAAM,gBAAgB,CAAC;YACrB,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,IAAI,EAAE,IAAI,CAAC,IAAI,KAAK,IAAI;SACzB,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEL,OAAO,SAAS,CAAC;AACnB,CAAC"}
@@ -0,0 +1,43 @@
1
+ /**
2
+ * pd runtime init — Initialize all PD SQLite databases for a workspace.
3
+ *
4
+ * Creates state.db, trajectory.db, and subagent_workflows.db with full schema
5
+ * (tables + indexes + views + migrations). Idempotent: safe to run on existing
6
+ * workspaces (all CREATE statements use IF NOT EXISTS).
7
+ *
8
+ * Output contract (cli-1 strict-json, cli-4 dry-run/confirm mutex, cli-6 nextAction):
9
+ * - Default mode is --dry-run (no writes); use --confirm to actually initialize.
10
+ * - --json emits a single parseable JSON object on stdout.
11
+ * - Failures emit { ok: false, reason, nextAction } with exit code 1.
12
+ *
13
+ * ERR refs:
14
+ * - ERR-001/ERR-005: no `as` casts; DB rows typed via type guards
15
+ * - ERR-002: degraded paths include reason + nextAction
16
+ * - ERR-009/ERR-010: missing required fields fail loud
17
+ * - ERR-014: safe JSON.stringify on known output shapes
18
+ */
19
+ export interface DatabaseInitResult {
20
+ name: string;
21
+ path: string;
22
+ tables: string[];
23
+ status: 'initialized' | 'verified' | 'skipped' | 'failed';
24
+ warnings: string[];
25
+ }
26
+ export interface RuntimeInitOutput {
27
+ ok: boolean;
28
+ mode: 'dry-run' | 'confirm';
29
+ workspace: string;
30
+ databases: DatabaseInitResult[];
31
+ warnings: string[];
32
+ reason?: string;
33
+ nextAction?: string;
34
+ }
35
+ export declare function buildRuntimeInitOutput(workspaceDir: string, confirm: boolean): RuntimeInitOutput;
36
+ export interface RuntimeInitOptions {
37
+ workspace?: string;
38
+ dryRun?: boolean;
39
+ confirm?: boolean;
40
+ json?: boolean;
41
+ }
42
+ export declare function handleRuntimeInit(opts: RuntimeInitOptions): Promise<void>;
43
+ //# sourceMappingURL=runtime-init.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-init.d.ts","sourceRoot":"","sources":["../../src/commands/runtime-init.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAWH,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,MAAM,EAAE,aAAa,GAAG,UAAU,GAAG,SAAS,GAAG,QAAQ,CAAC;IAC1D,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAED,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,OAAO,CAAC;IACZ,IAAI,EAAE,SAAS,GAAG,SAAS,CAAC;IAC5B,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,kBAAkB,EAAE,CAAC;IAChC,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAUD,wBAAgB,sBAAsB,CAAC,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,iBAAiB,CAwKhG;AA+CD,MAAM,WAAW,kBAAkB;IACjC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,wBAAsB,iBAAiB,CAAC,IAAI,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC,CA2B/E"}
@@ -0,0 +1,264 @@
1
+ /**
2
+ * pd runtime init — Initialize all PD SQLite databases for a workspace.
3
+ *
4
+ * Creates state.db, trajectory.db, and subagent_workflows.db with full schema
5
+ * (tables + indexes + views + migrations). Idempotent: safe to run on existing
6
+ * workspaces (all CREATE statements use IF NOT EXISTS).
7
+ *
8
+ * Output contract (cli-1 strict-json, cli-4 dry-run/confirm mutex, cli-6 nextAction):
9
+ * - Default mode is --dry-run (no writes); use --confirm to actually initialize.
10
+ * - --json emits a single parseable JSON object on stdout.
11
+ * - Failures emit { ok: false, reason, nextAction } with exit code 1.
12
+ *
13
+ * ERR refs:
14
+ * - ERR-001/ERR-005: no `as` casts; DB rows typed via type guards
15
+ * - ERR-002: degraded paths include reason + nextAction
16
+ * - ERR-009/ERR-010: missing required fields fail loud
17
+ * - ERR-014: safe JSON.stringify on known output shapes
18
+ */
19
+ import * as path from 'path';
20
+ import { SqliteConnection } from '@principles/core/runtime-v2';
21
+ import { SchemaConformanceReadModel } from '@principles/core/runtime-v2';
22
+ import { initTrajectorySchema, initWorkflowSchema } from 'principles-disciple';
23
+ import { resolveWorkspaceDir } from '../resolve-workspace.js';
24
+ import { emitResult, emitFlagConflict, emitError } from '../services/cli-output.js';
25
+ // ── Build output ─────────────────────────────────────────────────────────────
26
+ const DB_NAMES = {
27
+ state: 'state.db',
28
+ trajectory: 'trajectory.db',
29
+ workflow: 'subagent_workflows.db',
30
+ };
31
+ export function buildRuntimeInitOutput(workspaceDir, confirm) {
32
+ const resolvedWorkspace = path.resolve(workspaceDir);
33
+ const warnings = [];
34
+ const databases = [];
35
+ // 1. state.db (via SqliteConnection, which triggers initSchema + migrateSchema)
36
+ const stateDbPath = path.join(resolvedWorkspace, '.pd', 'state.db');
37
+ if (!confirm) {
38
+ // dry-run: report what would be initialized without touching disk
39
+ databases.push({
40
+ name: DB_NAMES.state,
41
+ path: stateDbPath,
42
+ tables: ['tasks', 'runs', 'artifacts', 'commits', 'principle_candidates',
43
+ 'pi_artifacts', 'approvals', 'activations', 'intent_decisions', 'schema_version'],
44
+ status: 'skipped',
45
+ warnings: [],
46
+ });
47
+ }
48
+ else {
49
+ try {
50
+ const conn = new SqliteConnection({ workspaceDir: resolvedWorkspace, readonly: false });
51
+ try {
52
+ conn.getDb(); // triggers initSchema + migrateSchema
53
+ const connWarnings = conn.getSchemaInitWarnings();
54
+ if (connWarnings.length > 0) {
55
+ warnings.push(...connWarnings.map(w => `${DB_NAMES.state}: ${w}`));
56
+ }
57
+ databases.push({
58
+ name: DB_NAMES.state,
59
+ path: stateDbPath,
60
+ tables: ['tasks', 'runs', 'artifacts', 'commits', 'principle_candidates',
61
+ 'pi_artifacts', 'approvals', 'activations', 'intent_decisions', 'schema_version'],
62
+ status: 'initialized',
63
+ warnings: connWarnings,
64
+ });
65
+ }
66
+ finally {
67
+ conn.close();
68
+ }
69
+ }
70
+ catch (err) {
71
+ const reason = err instanceof Error ? err.message : String(err);
72
+ databases.push({
73
+ name: DB_NAMES.state,
74
+ path: stateDbPath,
75
+ tables: [],
76
+ status: 'failed',
77
+ warnings: [reason],
78
+ });
79
+ return {
80
+ ok: false,
81
+ mode: 'confirm',
82
+ workspace: resolvedWorkspace,
83
+ databases,
84
+ warnings,
85
+ reason: `state.db initialization failed: ${reason}`,
86
+ nextAction: 'Check workspace directory permissions and disk space, then retry.',
87
+ };
88
+ }
89
+ }
90
+ // 2. trajectory.db (via initTrajectorySchema)
91
+ if (!confirm) {
92
+ databases.push({
93
+ name: DB_NAMES.trajectory,
94
+ path: path.join(resolvedWorkspace, '.state', 'trajectory.db'),
95
+ tables: ['schema_version', 'ingest_checkpoint', 'sessions', 'assistant_turns',
96
+ 'user_turns', 'tool_calls', 'pain_events', 'gate_blocks', 'trust_changes',
97
+ 'principle_events', 'task_outcomes', 'correction_samples', 'sample_reviews',
98
+ 'exports_audit', 'evolution_tasks', 'evolution_events'],
99
+ status: 'skipped',
100
+ warnings: [],
101
+ });
102
+ }
103
+ else {
104
+ try {
105
+ const result = initTrajectorySchema(resolvedWorkspace);
106
+ if (result.warnings.length > 0) {
107
+ warnings.push(...result.warnings.map(w => `${DB_NAMES.trajectory}: ${w}`));
108
+ }
109
+ databases.push({
110
+ name: DB_NAMES.trajectory,
111
+ path: path.join(resolvedWorkspace, '.state', 'trajectory.db'),
112
+ tables: result.tables,
113
+ status: 'initialized',
114
+ warnings: result.warnings,
115
+ });
116
+ }
117
+ catch (err) {
118
+ const reason = err instanceof Error ? err.message : String(err);
119
+ databases.push({
120
+ name: DB_NAMES.trajectory,
121
+ path: path.join(resolvedWorkspace, '.state', 'trajectory.db'),
122
+ tables: [],
123
+ status: 'failed',
124
+ warnings: [reason],
125
+ });
126
+ return {
127
+ ok: false,
128
+ mode: 'confirm',
129
+ workspace: resolvedWorkspace,
130
+ databases,
131
+ warnings,
132
+ reason: `trajectory.db initialization failed: ${reason}`,
133
+ nextAction: 'Check workspace directory permissions and disk space, then retry.',
134
+ };
135
+ }
136
+ }
137
+ // 3. subagent_workflows.db (via initWorkflowSchema)
138
+ if (!confirm) {
139
+ databases.push({
140
+ name: DB_NAMES.workflow,
141
+ path: path.join(resolvedWorkspace, '.state', 'subagent_workflows.db'),
142
+ tables: ['schema_version', 'subagent_workflows', 'subagent_workflow_events'],
143
+ status: 'skipped',
144
+ warnings: [],
145
+ });
146
+ }
147
+ else {
148
+ try {
149
+ const result = initWorkflowSchema(resolvedWorkspace);
150
+ if (result.warnings.length > 0) {
151
+ warnings.push(...result.warnings.map(w => `${DB_NAMES.workflow}: ${w}`));
152
+ }
153
+ databases.push({
154
+ name: DB_NAMES.workflow,
155
+ path: path.join(resolvedWorkspace, '.state', 'subagent_workflows.db'),
156
+ tables: result.tables,
157
+ status: 'initialized',
158
+ warnings: result.warnings,
159
+ });
160
+ }
161
+ catch (err) {
162
+ const reason = err instanceof Error ? err.message : String(err);
163
+ databases.push({
164
+ name: DB_NAMES.workflow,
165
+ path: path.join(resolvedWorkspace, '.state', 'subagent_workflows.db'),
166
+ tables: [],
167
+ status: 'failed',
168
+ warnings: [reason],
169
+ });
170
+ return {
171
+ ok: false,
172
+ mode: 'confirm',
173
+ workspace: resolvedWorkspace,
174
+ databases,
175
+ warnings,
176
+ reason: `subagent_workflows.db initialization failed: ${reason}`,
177
+ nextAction: 'Check workspace directory permissions and disk space, then retry.',
178
+ };
179
+ }
180
+ }
181
+ // Verify state.db schema conformance after initialization (confirm mode only)
182
+ if (confirm) {
183
+ try {
184
+ const conformance = new SchemaConformanceReadModel({ workspaceDir: resolvedWorkspace });
185
+ const result = conformance.check();
186
+ if (result.overallStatus === 'error') {
187
+ warnings.push(`state.db schema conformance check returned 'error' — some tables or indexes may be missing`);
188
+ }
189
+ }
190
+ catch (err) {
191
+ // Non-fatal: schema conformance check is a post-verification step
192
+ warnings.push(`schema conformance verification skipped: ${err instanceof Error ? err.message : String(err)}`);
193
+ }
194
+ }
195
+ return {
196
+ ok: true,
197
+ mode: confirm ? 'confirm' : 'dry-run',
198
+ workspace: resolvedWorkspace,
199
+ databases,
200
+ warnings,
201
+ };
202
+ }
203
+ // ── Text formatting ──────────────────────────────────────────────────────────
204
+ function formatTextOutput(output) {
205
+ const lines = [];
206
+ lines.push('PD Runtime Init');
207
+ lines.push(`mode: ${output.mode}`);
208
+ lines.push(`workspace: ${output.workspace}`);
209
+ lines.push('');
210
+ for (const db of output.databases) {
211
+ const icon = db.status === 'initialized' ? '[+]' :
212
+ db.status === 'verified' ? '[v]' :
213
+ db.status === 'skipped' ? '[ ]' : '[x]';
214
+ lines.push(`${icon} ${db.name} (${db.status})`);
215
+ lines.push(` path: ${db.path}`);
216
+ if (db.tables.length > 0) {
217
+ lines.push(` tables: ${db.tables.length} (${db.tables.slice(0, 5).join(', ')}${db.tables.length > 5 ? ', ...' : ''})`);
218
+ }
219
+ for (const w of db.warnings) {
220
+ lines.push(` warning: ${w}`);
221
+ }
222
+ }
223
+ if (output.warnings.length > 0) {
224
+ lines.push('');
225
+ lines.push('Warnings:');
226
+ for (const w of output.warnings) {
227
+ lines.push(` [!] ${w}`);
228
+ }
229
+ }
230
+ if (!output.ok && output.reason) {
231
+ lines.push('');
232
+ lines.push(`Error: ${output.reason}`);
233
+ if (output.nextAction) {
234
+ lines.push(`→ ${output.nextAction}`);
235
+ }
236
+ }
237
+ return lines.join('\n');
238
+ }
239
+ export async function handleRuntimeInit(opts) {
240
+ // cli-4: --dry-run and --confirm are mutually exclusive
241
+ if (opts.dryRun && opts.confirm) {
242
+ process.exitCode = emitFlagConflict({ json: opts.json ?? false });
243
+ return;
244
+ }
245
+ const workspaceDir = opts.workspace
246
+ ? path.resolve(opts.workspace)
247
+ : resolveWorkspaceDir();
248
+ // Default is dry-run; --confirm opts in to actual initialization
249
+ const confirm = opts.confirm === true;
250
+ try {
251
+ const output = buildRuntimeInitOutput(workspaceDir, confirm);
252
+ emitResult(output, { json: opts.json ?? false, formatText: formatTextOutput });
253
+ if (!output.ok) {
254
+ process.exitCode = 1; // cli-2: set exit code, no process.exit()
255
+ }
256
+ }
257
+ catch (err) {
258
+ process.exitCode = emitError(err, {
259
+ json: opts.json ?? false,
260
+ nextAction: 'Check workspace directory and permissions, then retry.',
261
+ });
262
+ }
263
+ }
264
+ //# sourceMappingURL=runtime-init.js.map