create-principles-disciple 1.121.7 → 1.121.9

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 (461) hide show
  1. package/README.md +13 -1
  2. package/console/dist/server/config/pd-config-store.d.ts +1 -3
  3. package/console/dist/server/config/pd-config-store.js +4 -4
  4. package/console/dist/server/feedback/channels.d.ts +2 -8
  5. package/console/dist/server/feedback/channels.js +0 -11
  6. package/console/dist/server/index.js +34 -5
  7. package/console/dist/server/models/ActivationsConsoleModel.d.ts +28 -1
  8. package/console/dist/server/models/ActivationsConsoleModel.js +72 -30
  9. package/console/dist/server/models/GovernanceExperienceCollector.d.ts +28 -0
  10. package/console/dist/server/models/GovernanceExperienceCollector.js +305 -0
  11. package/console/dist/server/models/GovernanceProjectionCollector.d.ts +60 -2
  12. package/console/dist/server/models/GovernanceProjectionCollector.js +323 -285
  13. package/console/dist/server/models/PrincipleClassifier.d.ts +1 -1
  14. package/console/dist/server/models/PrincipleClassifier.js +7 -4
  15. package/console/dist/server/models/PrinciplesConsoleModel.d.ts +2 -1
  16. package/console/dist/server/models/ReceiptsConsoleModel.d.ts +5 -0
  17. package/console/dist/server/models/ReceiptsConsoleModel.js +140 -13
  18. package/console/dist/server/routes/activations.js +1 -1
  19. package/console/dist/server/routes/failed-tasks.js +28 -11
  20. package/console/dist/server/routes/governance.d.ts +26 -0
  21. package/console/dist/server/routes/governance.js +51 -0
  22. package/console/dist/server/routes/owner-identity.d.ts +31 -0
  23. package/console/dist/server/routes/owner-identity.js +76 -0
  24. package/console/dist/server/routes/update-history.d.ts +5 -0
  25. package/console/dist/server/routes/update-history.js +50 -4
  26. package/console/dist/server/routes/update.js +186 -32
  27. package/console/dist/shared/feedback-channel-ids.d.ts +13 -0
  28. package/console/dist/shared/feedback-channel-ids.js +12 -0
  29. package/console/dist/shared/feedback-contract.d.ts +46 -0
  30. package/console/dist/shared/feedback-contract.js +45 -0
  31. package/console/dist/ui/App.js +1 -1
  32. package/console/dist/ui/api.d.ts +22 -3
  33. package/console/dist/ui/api.js +63 -3
  34. package/console/dist/ui/components/receipts/ReceiptCoverageDisclosure.d.ts +6 -0
  35. package/console/dist/ui/components/receipts/ReceiptCoverageDisclosure.js +66 -0
  36. package/console/dist/ui/i18n/en.json +198 -2
  37. package/console/dist/ui/i18n/zh-CN.json +196 -0
  38. package/console/dist/ui/pages/activation/ActivationPage.js +14 -2
  39. package/console/dist/ui/pages/failed-tasks/FailedTasksPage.js +25 -5
  40. package/console/dist/ui/pages/focus/FocusPage.d.ts +28 -1
  41. package/console/dist/ui/pages/focus/FocusPage.js +128 -15
  42. package/console/dist/ui/pages/principles/PrincipleDetailPage.d.ts +30 -0
  43. package/console/dist/ui/pages/principles/PrincipleDetailPage.js +49 -6
  44. package/console/dist/ui/pages/settings/SettingsPage.js +67 -2
  45. package/console/dist/ui/pages/settings/UpdatePage.js +7 -7
  46. package/console/dist/ui/utils/enum-labels.js +0 -1
  47. package/console/dist/ui/utils/validators.d.ts +53 -21
  48. package/console/dist/ui/utils/validators.js +248 -21
  49. package/console/dist/web/assets/app.css +6 -0
  50. package/console/dist/web/assets/app.js +2721 -1664
  51. package/console/package.json +4 -2
  52. package/core/dist/host/host-adapter.d.ts +1 -1
  53. package/core/dist/host/host-adapter.d.ts.map +1 -1
  54. package/core/dist/host/host-adapter.js +1 -0
  55. package/core/dist/host/host-adapter.js.map +1 -1
  56. package/core/dist/runtime-v2/__tests__/architecture-regression.test.js +12 -2
  57. package/core/dist/runtime-v2/__tests__/architecture-regression.test.js.map +1 -1
  58. package/core/dist/runtime-v2/__tests__/attack-e2e-pipeline-smoke.test.js +1 -1
  59. package/core/dist/runtime-v2/__tests__/attack-e2e-pipeline-smoke.test.js.map +1 -1
  60. package/core/dist/runtime-v2/__tests__/governance-experience.test.d.ts +2 -0
  61. package/core/dist/runtime-v2/__tests__/governance-experience.test.d.ts.map +1 -0
  62. package/core/dist/runtime-v2/__tests__/governance-experience.test.js +300 -0
  63. package/core/dist/runtime-v2/__tests__/governance-experience.test.js.map +1 -0
  64. package/core/dist/runtime-v2/__tests__/owner-identity.test.d.ts +2 -0
  65. package/core/dist/runtime-v2/__tests__/owner-identity.test.d.ts.map +1 -0
  66. package/core/dist/runtime-v2/__tests__/owner-identity.test.js +147 -0
  67. package/core/dist/runtime-v2/__tests__/owner-identity.test.js.map +1 -0
  68. package/core/dist/runtime-v2/__tests__/product-telemetry-contract.test.d.ts +18 -0
  69. package/core/dist/runtime-v2/__tests__/product-telemetry-contract.test.d.ts.map +1 -0
  70. package/core/dist/runtime-v2/__tests__/product-telemetry-contract.test.js +303 -0
  71. package/core/dist/runtime-v2/__tests__/product-telemetry-contract.test.js.map +1 -0
  72. package/core/dist/runtime-v2/__tests__/recovery-actions-log.test.js +40 -0
  73. package/core/dist/runtime-v2/__tests__/recovery-actions-log.test.js.map +1 -1
  74. package/core/dist/runtime-v2/__tests__/status-contract.test.d.ts +2 -0
  75. package/core/dist/runtime-v2/__tests__/status-contract.test.d.ts.map +1 -0
  76. package/core/dist/runtime-v2/__tests__/status-contract.test.js +107 -0
  77. package/core/dist/runtime-v2/__tests__/status-contract.test.js.map +1 -0
  78. package/core/dist/runtime-v2/activation/__tests__/promotion-evidence-snapshot.test.d.ts +2 -0
  79. package/core/dist/runtime-v2/activation/__tests__/promotion-evidence-snapshot.test.d.ts.map +1 -0
  80. package/core/dist/runtime-v2/activation/__tests__/promotion-evidence-snapshot.test.js +104 -0
  81. package/core/dist/runtime-v2/activation/__tests__/promotion-evidence-snapshot.test.js.map +1 -0
  82. package/core/dist/runtime-v2/activation/__tests__/promotion-readiness-evaluator.test.js +19 -0
  83. package/core/dist/runtime-v2/activation/__tests__/promotion-readiness-evaluator.test.js.map +1 -1
  84. package/core/dist/runtime-v2/activation/__tests__/rulecode-owner-decision-service.test.js +20 -0
  85. package/core/dist/runtime-v2/activation/__tests__/rulecode-owner-decision-service.test.js.map +1 -1
  86. package/core/dist/runtime-v2/activation/__tests__/sqlite-activation-safety-store.test.js +40 -0
  87. package/core/dist/runtime-v2/activation/__tests__/sqlite-activation-safety-store.test.js.map +1 -1
  88. package/core/dist/runtime-v2/activation/index.d.ts +2 -0
  89. package/core/dist/runtime-v2/activation/index.d.ts.map +1 -1
  90. package/core/dist/runtime-v2/activation/index.js +1 -0
  91. package/core/dist/runtime-v2/activation/index.js.map +1 -1
  92. package/core/dist/runtime-v2/activation/promotion-evidence-snapshot.d.ts +30 -0
  93. package/core/dist/runtime-v2/activation/promotion-evidence-snapshot.d.ts.map +1 -0
  94. package/core/dist/runtime-v2/activation/promotion-evidence-snapshot.js +87 -0
  95. package/core/dist/runtime-v2/activation/promotion-evidence-snapshot.js.map +1 -0
  96. package/core/dist/runtime-v2/activation/promotion-readiness-evaluator.d.ts.map +1 -1
  97. package/core/dist/runtime-v2/activation/promotion-readiness-evaluator.js +3 -0
  98. package/core/dist/runtime-v2/activation/promotion-readiness-evaluator.js.map +1 -1
  99. package/core/dist/runtime-v2/activation/promotion-readiness-reader.d.ts +1 -1
  100. package/core/dist/runtime-v2/activation/promotion-readiness-reader.d.ts.map +1 -1
  101. package/core/dist/runtime-v2/activation/promotion-readiness-reader.js +2 -2
  102. package/core/dist/runtime-v2/activation/promotion-readiness-reader.js.map +1 -1
  103. package/core/dist/runtime-v2/activation/rulecode-owner-decision-service.d.ts.map +1 -1
  104. package/core/dist/runtime-v2/activation/rulecode-owner-decision-service.js +18 -9
  105. package/core/dist/runtime-v2/activation/rulecode-owner-decision-service.js.map +1 -1
  106. package/core/dist/runtime-v2/adapter/__tests__/chaos-json-repair.test.js +1 -1
  107. package/core/dist/runtime-v2/adapter/__tests__/chaos-json-repair.test.js.map +1 -1
  108. package/core/dist/runtime-v2/adapter/__tests__/json-extractor.test.js +91 -1
  109. package/core/dist/runtime-v2/adapter/__tests__/json-extractor.test.js.map +1 -1
  110. package/core/dist/runtime-v2/adapter/__tests__/pi-ai-runtime-adapter.test.js +59 -12
  111. package/core/dist/runtime-v2/adapter/__tests__/pi-ai-runtime-adapter.test.js.map +1 -1
  112. package/core/dist/runtime-v2/adapter/__tests__/runtime-config-contract.test.js +10 -9
  113. package/core/dist/runtime-v2/adapter/__tests__/runtime-config-contract.test.js.map +1 -1
  114. package/core/dist/runtime-v2/adapter/__tests__/structured-output-repair.test.js +42 -1
  115. package/core/dist/runtime-v2/adapter/__tests__/structured-output-repair.test.js.map +1 -1
  116. package/core/dist/runtime-v2/adapter/json-extractor.d.ts +25 -0
  117. package/core/dist/runtime-v2/adapter/json-extractor.d.ts.map +1 -1
  118. package/core/dist/runtime-v2/adapter/json-extractor.js +126 -0
  119. package/core/dist/runtime-v2/adapter/json-extractor.js.map +1 -1
  120. package/core/dist/runtime-v2/adapter/l2-agent-loop-adapter.d.ts +9 -4
  121. package/core/dist/runtime-v2/adapter/l2-agent-loop-adapter.d.ts.map +1 -1
  122. package/core/dist/runtime-v2/adapter/l2-agent-loop-adapter.js +9 -4
  123. package/core/dist/runtime-v2/adapter/l2-agent-loop-adapter.js.map +1 -1
  124. package/core/dist/runtime-v2/adapter/output-repair-contract.d.ts +5 -1
  125. package/core/dist/runtime-v2/adapter/output-repair-contract.d.ts.map +1 -1
  126. package/core/dist/runtime-v2/adapter/output-repair-contract.js +4 -1
  127. package/core/dist/runtime-v2/adapter/output-repair-contract.js.map +1 -1
  128. package/core/dist/runtime-v2/adapter/pi-ai-catalog.d.ts +7 -0
  129. package/core/dist/runtime-v2/adapter/pi-ai-catalog.d.ts.map +1 -0
  130. package/core/dist/runtime-v2/adapter/pi-ai-catalog.js +19 -0
  131. package/core/dist/runtime-v2/adapter/pi-ai-catalog.js.map +1 -0
  132. package/core/dist/runtime-v2/adapter/pi-ai-runtime-adapter.d.ts +13 -15
  133. package/core/dist/runtime-v2/adapter/pi-ai-runtime-adapter.d.ts.map +1 -1
  134. package/core/dist/runtime-v2/adapter/pi-ai-runtime-adapter.js +104 -37
  135. package/core/dist/runtime-v2/adapter/pi-ai-runtime-adapter.js.map +1 -1
  136. package/core/dist/runtime-v2/adapter/structured-output-repair.d.ts +16 -1
  137. package/core/dist/runtime-v2/adapter/structured-output-repair.d.ts.map +1 -1
  138. package/core/dist/runtime-v2/adapter/structured-output-repair.js +38 -6
  139. package/core/dist/runtime-v2/adapter/structured-output-repair.js.map +1 -1
  140. package/core/dist/runtime-v2/adapter/tools/diagnostician-tool.d.ts +1 -1
  141. package/core/dist/runtime-v2/adapter/tools/diagnostician-tool.d.ts.map +1 -1
  142. package/core/dist/runtime-v2/config/__tests__/pd-config-agent-binding.test.js +8 -9
  143. package/core/dist/runtime-v2/config/__tests__/pd-config-agent-binding.test.js.map +1 -1
  144. package/core/dist/runtime-v2/config/__tests__/pd-config-contract.test.js +27 -3
  145. package/core/dist/runtime-v2/config/__tests__/pd-config-contract.test.js.map +1 -1
  146. package/core/dist/runtime-v2/config/__tests__/pd-config-principles.test.d.ts +11 -0
  147. package/core/dist/runtime-v2/config/__tests__/pd-config-principles.test.d.ts.map +1 -0
  148. package/core/dist/runtime-v2/config/__tests__/pd-config-principles.test.js +93 -0
  149. package/core/dist/runtime-v2/config/__tests__/pd-config-principles.test.js.map +1 -0
  150. package/core/dist/runtime-v2/config/__tests__/pd-config-workspace.test.js +41 -0
  151. package/core/dist/runtime-v2/config/__tests__/pd-config-workspace.test.js.map +1 -1
  152. package/core/dist/runtime-v2/config/index.d.ts +2 -2
  153. package/core/dist/runtime-v2/config/index.d.ts.map +1 -1
  154. package/core/dist/runtime-v2/config/index.js +2 -0
  155. package/core/dist/runtime-v2/config/index.js.map +1 -1
  156. package/core/dist/runtime-v2/config/pd-config-agent-binding.d.ts.map +1 -1
  157. package/core/dist/runtime-v2/config/pd-config-agent-binding.js +4 -13
  158. package/core/dist/runtime-v2/config/pd-config-agent-binding.js.map +1 -1
  159. package/core/dist/runtime-v2/config/pd-config-effective.d.ts.map +1 -1
  160. package/core/dist/runtime-v2/config/pd-config-effective.js +14 -7
  161. package/core/dist/runtime-v2/config/pd-config-effective.js.map +1 -1
  162. package/core/dist/runtime-v2/config/pd-config-feature-flags.d.ts.map +1 -1
  163. package/core/dist/runtime-v2/config/pd-config-feature-flags.js +5 -12
  164. package/core/dist/runtime-v2/config/pd-config-feature-flags.js.map +1 -1
  165. package/core/dist/runtime-v2/config/pd-config-types.d.ts +8 -0
  166. package/core/dist/runtime-v2/config/pd-config-types.d.ts.map +1 -1
  167. package/core/dist/runtime-v2/config/pd-config-types.js +2 -0
  168. package/core/dist/runtime-v2/config/pd-config-types.js.map +1 -1
  169. package/core/dist/runtime-v2/config/pd-config-validate.d.ts.map +1 -1
  170. package/core/dist/runtime-v2/config/pd-config-validate.js +48 -3
  171. package/core/dist/runtime-v2/config/pd-config-validate.js.map +1 -1
  172. package/core/dist/runtime-v2/core-principles/__tests__/core-axiom-block.test.js +36 -8
  173. package/core/dist/runtime-v2/core-principles/__tests__/core-axiom-block.test.js.map +1 -1
  174. package/core/dist/runtime-v2/core-principles/__tests__/core-principle-registry.test.js +36 -12
  175. package/core/dist/runtime-v2/core-principles/__tests__/core-principle-registry.test.js.map +1 -1
  176. package/core/dist/runtime-v2/core-principles/core-axiom-block.d.ts +22 -8
  177. package/core/dist/runtime-v2/core-principles/core-axiom-block.d.ts.map +1 -1
  178. package/core/dist/runtime-v2/core-principles/core-axiom-block.js +28 -13
  179. package/core/dist/runtime-v2/core-principles/core-axiom-block.js.map +1 -1
  180. package/core/dist/runtime-v2/core-principles/core-principle-registry.d.ts +29 -4
  181. package/core/dist/runtime-v2/core-principles/core-principle-registry.d.ts.map +1 -1
  182. package/core/dist/runtime-v2/core-principles/core-principle-registry.js +68 -33
  183. package/core/dist/runtime-v2/core-principles/core-principle-registry.js.map +1 -1
  184. package/core/dist/runtime-v2/core-principles/index.d.ts +3 -3
  185. package/core/dist/runtime-v2/core-principles/index.d.ts.map +1 -1
  186. package/core/dist/runtime-v2/core-principles/index.js +1 -1
  187. package/core/dist/runtime-v2/core-principles/index.js.map +1 -1
  188. package/core/dist/runtime-v2/evolution/evolution-types.d.ts +2 -1
  189. package/core/dist/runtime-v2/evolution/evolution-types.d.ts.map +1 -1
  190. package/core/dist/runtime-v2/evolution/evolution-types.js.map +1 -1
  191. package/core/dist/runtime-v2/feature-flags/__tests__/anonymous-product-telemetry-flag.test.d.ts +2 -0
  192. package/core/dist/runtime-v2/feature-flags/__tests__/anonymous-product-telemetry-flag.test.d.ts.map +1 -0
  193. package/core/dist/runtime-v2/feature-flags/__tests__/anonymous-product-telemetry-flag.test.js +48 -0
  194. package/core/dist/runtime-v2/feature-flags/__tests__/anonymous-product-telemetry-flag.test.js.map +1 -0
  195. package/core/dist/runtime-v2/feature-flags/__tests__/codex-conversation-ingestion-flag.test.d.ts +2 -0
  196. package/core/dist/runtime-v2/feature-flags/__tests__/codex-conversation-ingestion-flag.test.d.ts.map +1 -0
  197. package/core/dist/runtime-v2/feature-flags/__tests__/codex-conversation-ingestion-flag.test.js +46 -0
  198. package/core/dist/runtime-v2/feature-flags/__tests__/codex-conversation-ingestion-flag.test.js.map +1 -0
  199. package/core/dist/runtime-v2/feature-flags/__tests__/feature-flag-contract.test.js +86 -31
  200. package/core/dist/runtime-v2/feature-flags/__tests__/feature-flag-contract.test.js.map +1 -1
  201. package/core/dist/runtime-v2/feature-flags/__tests__/feature-flag-lifecycle.test.d.ts +2 -0
  202. package/core/dist/runtime-v2/feature-flags/__tests__/feature-flag-lifecycle.test.d.ts.map +1 -0
  203. package/core/dist/runtime-v2/feature-flags/__tests__/feature-flag-lifecycle.test.js +83 -0
  204. package/core/dist/runtime-v2/feature-flags/__tests__/feature-flag-lifecycle.test.js.map +1 -0
  205. package/core/dist/runtime-v2/feature-flags/feature-flag-contract.d.ts +19 -1
  206. package/core/dist/runtime-v2/feature-flags/feature-flag-contract.d.ts.map +1 -1
  207. package/core/dist/runtime-v2/feature-flags/feature-flag-contract.js +128 -10
  208. package/core/dist/runtime-v2/feature-flags/feature-flag-contract.js.map +1 -1
  209. package/core/dist/runtime-v2/feature-flags/feature-flag-lifecycle.d.ts +37 -0
  210. package/core/dist/runtime-v2/feature-flags/feature-flag-lifecycle.d.ts.map +1 -0
  211. package/core/dist/runtime-v2/feature-flags/feature-flag-lifecycle.js +304 -0
  212. package/core/dist/runtime-v2/feature-flags/feature-flag-lifecycle.js.map +1 -0
  213. package/core/dist/runtime-v2/feature-flags/index.d.ts +4 -2
  214. package/core/dist/runtime-v2/feature-flags/index.d.ts.map +1 -1
  215. package/core/dist/runtime-v2/feature-flags/index.js +3 -1
  216. package/core/dist/runtime-v2/feature-flags/index.js.map +1 -1
  217. package/core/dist/runtime-v2/governance-experience-contract.d.ts +468 -0
  218. package/core/dist/runtime-v2/governance-experience-contract.d.ts.map +1 -0
  219. package/core/dist/runtime-v2/governance-experience-contract.js +208 -0
  220. package/core/dist/runtime-v2/governance-experience-contract.js.map +1 -0
  221. package/core/dist/runtime-v2/governance-experience.d.ts +11 -0
  222. package/core/dist/runtime-v2/governance-experience.d.ts.map +1 -0
  223. package/core/dist/runtime-v2/governance-experience.js +276 -0
  224. package/core/dist/runtime-v2/governance-experience.js.map +1 -0
  225. package/core/dist/runtime-v2/index.d.ts +20 -8
  226. package/core/dist/runtime-v2/index.d.ts.map +1 -1
  227. package/core/dist/runtime-v2/index.js +20 -6
  228. package/core/dist/runtime-v2/index.js.map +1 -1
  229. package/core/dist/runtime-v2/internalization/__tests__/artificer-output-retry-flag.test.js +29 -10
  230. package/core/dist/runtime-v2/internalization/__tests__/artificer-output-retry-flag.test.js.map +1 -1
  231. package/core/dist/runtime-v2/owner-identity.d.ts +69 -0
  232. package/core/dist/runtime-v2/owner-identity.d.ts.map +1 -0
  233. package/core/dist/runtime-v2/owner-identity.js +179 -0
  234. package/core/dist/runtime-v2/owner-identity.js.map +1 -0
  235. package/core/dist/runtime-v2/pain-signal-runtime-factory.d.ts.map +1 -1
  236. package/core/dist/runtime-v2/pain-signal-runtime-factory.js +2 -3
  237. package/core/dist/runtime-v2/pain-signal-runtime-factory.js.map +1 -1
  238. package/core/dist/runtime-v2/product-telemetry/daily-identity.d.ts +70 -0
  239. package/core/dist/runtime-v2/product-telemetry/daily-identity.d.ts.map +1 -0
  240. package/core/dist/runtime-v2/product-telemetry/daily-identity.js +89 -0
  241. package/core/dist/runtime-v2/product-telemetry/daily-identity.js.map +1 -0
  242. package/core/dist/runtime-v2/product-telemetry/snapshot-contract.d.ts +110 -0
  243. package/core/dist/runtime-v2/product-telemetry/snapshot-contract.d.ts.map +1 -0
  244. package/core/dist/runtime-v2/product-telemetry/snapshot-contract.js +250 -0
  245. package/core/dist/runtime-v2/product-telemetry/snapshot-contract.js.map +1 -0
  246. package/core/dist/runtime-v2/pruning-read-model.d.ts +2 -1
  247. package/core/dist/runtime-v2/pruning-read-model.d.ts.map +1 -1
  248. package/core/dist/runtime-v2/pruning-read-model.js.map +1 -1
  249. package/core/dist/runtime-v2/receipt-coverage.d.ts +63 -0
  250. package/core/dist/runtime-v2/receipt-coverage.d.ts.map +1 -0
  251. package/core/dist/runtime-v2/receipt-coverage.js +19 -0
  252. package/core/dist/runtime-v2/receipt-coverage.js.map +1 -0
  253. package/core/dist/runtime-v2/recovery-actions-log.d.ts +7 -0
  254. package/core/dist/runtime-v2/recovery-actions-log.d.ts.map +1 -1
  255. package/core/dist/runtime-v2/recovery-actions-log.js +6 -0
  256. package/core/dist/runtime-v2/recovery-actions-log.js.map +1 -1
  257. package/core/dist/runtime-v2/runtime-protocol.js +1 -1
  258. package/core/dist/runtime-v2/runtime-protocol.js.map +1 -1
  259. package/core/dist/runtime-v2/store/task/__tests__/sqlite-task-store.failed-tasks.test.js +17 -1
  260. package/core/dist/runtime-v2/store/task/__tests__/sqlite-task-store.failed-tasks.test.js.map +1 -1
  261. package/core/dist/runtime-v2/store/task/sqlite-task-store.d.ts.map +1 -1
  262. package/core/dist/runtime-v2/store/task/sqlite-task-store.js +10 -0
  263. package/core/dist/runtime-v2/store/task/sqlite-task-store.js.map +1 -1
  264. package/core/dist/runtime-v2/store/task/task-types.d.ts +2 -0
  265. package/core/dist/runtime-v2/store/task/task-types.d.ts.map +1 -1
  266. package/core/dist/runtime-v2/task-status.d.ts +9 -5
  267. package/core/dist/runtime-v2/task-status.d.ts.map +1 -1
  268. package/core/dist/runtime-v2/task-status.js +15 -7
  269. package/core/dist/runtime-v2/task-status.js.map +1 -1
  270. package/core/dist/runtime-v2/types/event-types.d.ts +4 -0
  271. package/core/dist/runtime-v2/types/event-types.d.ts.map +1 -1
  272. package/core/dist/runtime-v2/types/event-types.js.map +1 -1
  273. package/core/dist/runtime-v2/types/index.d.ts +1 -1
  274. package/core/dist/runtime-v2/types/index.d.ts.map +1 -1
  275. package/core/dist/runtime-v2/types/index.js +1 -1
  276. package/core/dist/runtime-v2/types/index.js.map +1 -1
  277. package/core/dist/runtime-v2/types/principle-enums.d.ts +3 -2
  278. package/core/dist/runtime-v2/types/principle-enums.d.ts.map +1 -1
  279. package/core/dist/runtime-v2/types/principle-enums.js +11 -5
  280. package/core/dist/runtime-v2/types/principle-enums.js.map +1 -1
  281. package/core/dist/runtime-v2/types/principle-schema.d.ts +1 -1
  282. package/core/dist/runtime-v2/types/principle-tree-store.d.ts +1 -1
  283. package/core/dist/runtime-v2/utils/cli-process-runner.d.ts.map +1 -1
  284. package/core/dist/runtime-v2/utils/cli-process-runner.js +3 -2
  285. package/core/dist/runtime-v2/utils/cli-process-runner.js.map +1 -1
  286. package/core/package.json +4 -5
  287. package/dist/i18n.d.ts.map +1 -1
  288. package/dist/i18n.js +4 -2
  289. package/dist/i18n.js.map +1 -1
  290. package/dist/index.d.ts +2 -0
  291. package/dist/index.d.ts.map +1 -1
  292. package/dist/index.js +47 -11
  293. package/dist/index.js.map +1 -1
  294. package/dist/installer.d.ts +31 -5
  295. package/dist/installer.d.ts.map +1 -1
  296. package/dist/installer.js +472 -161
  297. package/dist/installer.js.map +1 -1
  298. package/dist/installers/codex-host-installer.d.ts.map +1 -1
  299. package/dist/installers/codex-host-installer.js +4 -0
  300. package/dist/installers/codex-host-installer.js.map +1 -1
  301. package/dist/mvp-config.d.ts +10 -0
  302. package/dist/mvp-config.d.ts.map +1 -1
  303. package/dist/mvp-config.js +30 -3
  304. package/dist/mvp-config.js.map +1 -1
  305. package/dist/uninstaller.d.ts +9 -1
  306. package/dist/uninstaller.d.ts.map +1 -1
  307. package/dist/uninstaller.js +103 -23
  308. package/dist/uninstaller.js.map +1 -1
  309. package/dist/update/atomic-file.d.ts +35 -0
  310. package/dist/update/atomic-file.d.ts.map +1 -0
  311. package/dist/update/atomic-file.js +120 -0
  312. package/dist/update/atomic-file.js.map +1 -0
  313. package/dist/update/bootstrap-protocol.d.ts +55 -0
  314. package/dist/update/bootstrap-protocol.d.ts.map +1 -0
  315. package/dist/update/bootstrap-protocol.js +132 -0
  316. package/dist/update/bootstrap-protocol.js.map +1 -0
  317. package/dist/update/channel-metadata.d.ts +28 -0
  318. package/dist/update/channel-metadata.d.ts.map +1 -0
  319. package/dist/update/channel-metadata.js +90 -0
  320. package/dist/update/channel-metadata.js.map +1 -0
  321. package/dist/update/channel-promotion.d.ts +39 -0
  322. package/dist/update/channel-promotion.d.ts.map +1 -0
  323. package/dist/update/channel-promotion.js +55 -0
  324. package/dist/update/channel-promotion.js.map +1 -0
  325. package/dist/update/data-compatibility.d.ts +35 -0
  326. package/dist/update/data-compatibility.d.ts.map +1 -0
  327. package/dist/update/data-compatibility.js +45 -0
  328. package/dist/update/data-compatibility.js.map +1 -0
  329. package/dist/update/install-layout.d.ts +59 -0
  330. package/dist/update/install-layout.d.ts.map +1 -0
  331. package/dist/update/install-layout.js +127 -0
  332. package/dist/update/install-layout.js.map +1 -0
  333. package/dist/update/legacy-migration.d.ts +56 -0
  334. package/dist/update/legacy-migration.d.ts.map +1 -0
  335. package/dist/update/legacy-migration.js +254 -0
  336. package/dist/update/legacy-migration.js.map +1 -0
  337. package/dist/update/product-identity.d.ts +50 -0
  338. package/dist/update/product-identity.d.ts.map +1 -0
  339. package/dist/update/product-identity.js +63 -0
  340. package/dist/update/product-identity.js.map +1 -0
  341. package/dist/update/release-asset-manifest.d.ts +31 -0
  342. package/dist/update/release-asset-manifest.d.ts.map +1 -0
  343. package/dist/update/release-asset-manifest.js +161 -0
  344. package/dist/update/release-asset-manifest.js.map +1 -0
  345. package/dist/update/release-identity.d.ts +33 -0
  346. package/dist/update/release-identity.d.ts.map +1 -0
  347. package/dist/update/release-identity.js +108 -0
  348. package/dist/update/release-identity.js.map +1 -0
  349. package/dist/update/release-manager.d.ts +96 -0
  350. package/dist/update/release-manager.d.ts.map +1 -0
  351. package/dist/update/release-manager.js +253 -0
  352. package/dist/update/release-manager.js.map +1 -0
  353. package/dist/update/release-metadata.d.ts +57 -0
  354. package/dist/update/release-metadata.d.ts.map +1 -0
  355. package/dist/update/release-metadata.js +200 -0
  356. package/dist/update/release-metadata.js.map +1 -0
  357. package/dist/update/release-policy.d.ts +51 -0
  358. package/dist/update/release-policy.d.ts.map +1 -0
  359. package/dist/update/release-policy.js +103 -0
  360. package/dist/update/release-policy.js.map +1 -0
  361. package/dist/update/rollback-policy.d.ts +56 -0
  362. package/dist/update/rollback-policy.d.ts.map +1 -0
  363. package/dist/update/rollback-policy.js +61 -0
  364. package/dist/update/rollback-policy.js.map +1 -0
  365. package/dist/update/transaction-journal.d.ts +121 -0
  366. package/dist/update/transaction-journal.d.ts.map +1 -0
  367. package/dist/update/transaction-journal.js +333 -0
  368. package/dist/update/transaction-journal.js.map +1 -0
  369. package/dist/update/trust-metadata.d.ts +55 -0
  370. package/dist/update/trust-metadata.d.ts.map +1 -0
  371. package/dist/update/trust-metadata.js +170 -0
  372. package/dist/update/trust-metadata.js.map +1 -0
  373. package/dist/update/update-history.d.ts +46 -0
  374. package/dist/update/update-history.d.ts.map +1 -0
  375. package/dist/update/update-history.js +123 -0
  376. package/dist/update/update-history.js.map +1 -0
  377. package/dist/utils/env.d.ts +7 -0
  378. package/dist/utils/env.d.ts.map +1 -1
  379. package/dist/utils/env.js +134 -44
  380. package/dist/utils/env.js.map +1 -1
  381. package/host-runtime/dist/governance-observation-store.d.ts +172 -0
  382. package/host-runtime/dist/governance-observation-store.js +649 -0
  383. package/host-runtime/dist/index.d.ts +6 -0
  384. package/host-runtime/dist/index.js +8 -0
  385. package/host-runtime/dist/product-telemetry/consent-store.d.ts +107 -0
  386. package/host-runtime/dist/product-telemetry/consent-store.js +329 -0
  387. package/host-runtime/dist/product-telemetry/eligibility.d.ts +53 -0
  388. package/host-runtime/dist/product-telemetry/eligibility.js +69 -0
  389. package/host-runtime/dist/product-telemetry/exporter.d.ts +46 -0
  390. package/host-runtime/dist/product-telemetry/exporter.js +71 -0
  391. package/host-runtime/dist/product-telemetry/milestone-readers.d.ts +61 -0
  392. package/host-runtime/dist/product-telemetry/milestone-readers.js +234 -0
  393. package/host-runtime/dist/product-telemetry/service.d.ts +142 -0
  394. package/host-runtime/dist/product-telemetry/service.js +532 -0
  395. package/host-runtime/dist/product-telemetry/workspace-scope.d.ts +38 -0
  396. package/host-runtime/dist/product-telemetry/workspace-scope.js +64 -0
  397. package/host-runtime/package.json +7 -2
  398. package/install-layout/dist/index.d.ts +48 -0
  399. package/install-layout/dist/index.js +81 -0
  400. package/install-layout/dist/index.test.d.ts +1 -0
  401. package/install-layout/dist/index.test.js +34 -0
  402. package/install-layout/package.json +33 -0
  403. package/package.json +16 -6
  404. package/pd-cli/dist/commands/__tests__/telemetry-flag-wiring.test.d.ts +9 -0
  405. package/pd-cli/dist/commands/__tests__/telemetry-flag-wiring.test.d.ts.map +1 -0
  406. package/pd-cli/dist/commands/__tests__/telemetry-flag-wiring.test.js +76 -0
  407. package/pd-cli/dist/commands/__tests__/telemetry-flag-wiring.test.js.map +1 -0
  408. package/pd-cli/dist/commands/__tests__/version.test.d.ts +2 -0
  409. package/pd-cli/dist/commands/__tests__/version.test.d.ts.map +1 -0
  410. package/pd-cli/dist/commands/__tests__/version.test.js +134 -0
  411. package/pd-cli/dist/commands/__tests__/version.test.js.map +1 -0
  412. package/pd-cli/dist/commands/console.d.ts.map +1 -1
  413. package/pd-cli/dist/commands/console.js +29 -10
  414. package/pd-cli/dist/commands/console.js.map +1 -1
  415. package/pd-cli/dist/commands/pain-record.d.ts.map +1 -1
  416. package/pd-cli/dist/commands/pain-record.js +6 -15
  417. package/pd-cli/dist/commands/pain-record.js.map +1 -1
  418. package/pd-cli/dist/commands/runtime-activation.d.ts +29 -0
  419. package/pd-cli/dist/commands/runtime-activation.d.ts.map +1 -1
  420. package/pd-cli/dist/commands/runtime-activation.js +70 -31
  421. package/pd-cli/dist/commands/runtime-activation.js.map +1 -1
  422. package/pd-cli/dist/commands/runtime-internalization-enqueue-successors.d.ts.map +1 -1
  423. package/pd-cli/dist/commands/runtime-internalization-enqueue-successors.js +2 -2
  424. package/pd-cli/dist/commands/runtime-internalization-enqueue-successors.js.map +1 -1
  425. package/pd-cli/dist/commands/telemetry.d.ts +82 -0
  426. package/pd-cli/dist/commands/telemetry.d.ts.map +1 -0
  427. package/pd-cli/dist/commands/telemetry.js +268 -0
  428. package/pd-cli/dist/commands/telemetry.js.map +1 -0
  429. package/pd-cli/dist/commands/version.d.ts +11 -0
  430. package/pd-cli/dist/commands/version.d.ts.map +1 -0
  431. package/pd-cli/dist/commands/version.js +48 -0
  432. package/pd-cli/dist/commands/version.js.map +1 -0
  433. package/pd-cli/dist/index.js +35 -2
  434. package/pd-cli/dist/index.js.map +1 -1
  435. package/pd-cli/dist/services/version-report.d.ts +44 -0
  436. package/pd-cli/dist/services/version-report.d.ts.map +1 -0
  437. package/pd-cli/dist/services/version-report.js +152 -0
  438. package/pd-cli/dist/services/version-report.js.map +1 -0
  439. package/pd-cli/package.json +3 -2
  440. package/plugin/dist/bundle.js +870 -932
  441. package/plugin/dist/core/init.d.ts +2 -1
  442. package/plugin/dist/core/principle-application-ledger.d.ts +10 -0
  443. package/plugin/dist/core/product-telemetry-trigger.d.ts +14 -0
  444. package/plugin/dist/core/thinking-os-parser.d.ts +5 -2
  445. package/plugin/dist/governance-audit.js +386 -0
  446. package/plugin/dist/hooks/gate-block-helper.d.ts +25 -1
  447. package/plugin/dist/hooks/gate.d.ts +22 -0
  448. package/plugin/dist/openclaw.plugin.json +1 -1
  449. package/plugin/dist/rulehost-evidence.js +832 -0
  450. package/plugin/dist/templates/langs/en/principles/THINKING_OS.md +53 -45
  451. package/plugin/dist/templates/langs/en/skills/pd-mentor/SKILL.md +1 -1
  452. package/plugin/dist/templates/langs/zh/principles/THINKING_OS.md +62 -46
  453. package/plugin/dist/templates/langs/zh/skills/pd-mentor/SKILL.md +1 -1
  454. package/plugin/dist/templates/workspace/.principles/THINKING_OS.md +66 -38
  455. package/plugin/openclaw.plugin.json +1 -1
  456. package/plugin/package.json +1 -1
  457. package/plugin/templates/langs/en/principles/THINKING_OS.md +53 -45
  458. package/plugin/templates/langs/en/skills/pd-mentor/SKILL.md +1 -1
  459. package/plugin/templates/langs/zh/principles/THINKING_OS.md +62 -46
  460. package/plugin/templates/langs/zh/skills/pd-mentor/SKILL.md +1 -1
  461. package/plugin/templates/workspace/.principles/THINKING_OS.md +66 -38
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Bounded asynchronous telemetry export client — Anonymous Product Telemetry
3
+ * v1 (PRI-599, SPEC §29-§34).
4
+ *
5
+ * One HTTPS POST per invocation, bounded by AbortController, never throwing.
6
+ * Failure mapping is coarse (SPEC §34): codes only, never messages, stacks,
7
+ * or response bodies. The injectable fetchFn keeps unit tests offline.
8
+ */
9
+ export const DEFAULT_PRODUCT_TELEMETRY_ENDPOINT = 'https://principles-website.pages.dev/api/product-telemetry/snapshot';
10
+ export const PRODUCT_TELEMETRY_TIMEOUT_MS = 8000;
11
+ export const PRODUCT_TELEMETRY_MAX_BODY_BYTES = 4096;
12
+ function defaultFetchFn(url, init) {
13
+ // fetch must be invoked against globalThis inside workers/gateway runtimes
14
+ // ("Illegal invocation" otherwise — same constraint as website relay-core).
15
+ return fetch.call(globalThis, url, init);
16
+ }
17
+ /**
18
+ * Export one snapshot. Never throws; every failure maps to a coarse code
19
+ * with a retryable hint the service uses for backoff.
20
+ */
21
+ export async function exportSnapshot(args) {
22
+ const endpoint = args.endpoint ?? DEFAULT_PRODUCT_TELEMETRY_ENDPOINT;
23
+ const timeoutMs = args.timeoutMs ?? PRODUCT_TELEMETRY_TIMEOUT_MS;
24
+ const fetchFn = args.fetchFn ?? defaultFetchFn;
25
+ const body = JSON.stringify(args.snapshot);
26
+ if (Buffer.byteLength(body, 'utf8') > PRODUCT_TELEMETRY_MAX_BODY_BYTES) {
27
+ // Safety net: the strict schema keeps snapshots far below 4 KB; a
28
+ // violation here is a programmer error, never worth a network round trip.
29
+ return { ok: false, code: 'invalid_response', retryable: false };
30
+ }
31
+ const controller = new AbortController();
32
+ const timer = setTimeout(() => controller.abort(), timeoutMs);
33
+ try {
34
+ const response = await fetchFn(endpoint, {
35
+ method: 'POST',
36
+ headers: { 'content-type': 'application/json' },
37
+ body,
38
+ signal: controller.signal,
39
+ });
40
+ const { status } = response;
41
+ if (status >= 200 && status < 300) {
42
+ return { ok: true, status };
43
+ }
44
+ if (status === 400)
45
+ return { ok: false, code: 'http_400', retryable: false };
46
+ if (status === 429)
47
+ return { ok: false, code: 'http_429', retryable: true };
48
+ if (status >= 500)
49
+ return { ok: false, code: 'http_5xx', retryable: true };
50
+ return { ok: false, code: 'http_unexpected_status', retryable: false };
51
+ }
52
+ catch (error) {
53
+ if (error instanceof Error && error.name === 'AbortError') {
54
+ return { ok: false, code: 'timeout', retryable: true };
55
+ }
56
+ // fetch rejects with TypeError on DNS failure / connection refused /
57
+ // TLS errors — indistinguishable at this boundary and equally retryable.
58
+ return { ok: false, code: 'network_error', retryable: true };
59
+ }
60
+ finally {
61
+ clearTimeout(timer);
62
+ }
63
+ }
64
+ /**
65
+ * First failure retries after 1h; any further failure within 24h backs off 6h.
66
+ * Combined with the service's dailyAttemptCount hard cap this bounds a bad day
67
+ * to at most 5 attempts (0h/1h/7h/13h/19h), independent of clock skew.
68
+ */
69
+ export function nextRetryDelayMs(previousFailureWithin24h) {
70
+ return previousFailureWithin24h ? 6 * 60 * 60 * 1000 : 60 * 60 * 1000;
71
+ }
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Durable-fact milestone readers — Anonymous Product Telemetry v1
3
+ * (PRI-598, SPEC §21-§31; review remediation: tri-state facts).
4
+ *
5
+ * Read-only derivation of the six milestone facts from the authoritative
6
+ * durable sources verified in the Phase 0 authority matrix
7
+ * (docs/audit/anonymous-product-telemetry-feasibility.md §4):
8
+ *
9
+ * initialized <ws>/.pd/state.db schema_version populated
10
+ * painObserved <ws>/.state/trajectory.db pain_events EXISTS
11
+ * principleObserved principle tree ledger non-empty OR state.db principle_candidates EXISTS
12
+ * activationObserved state.db activations EXISTS
13
+ * presenceReceiptObserved state.db principle_applications level='presence' EXISTS
14
+ * effectReceiptObserved state.db principle_applications level='effect' EXISTS
15
+ *
16
+ * Readers never throw (telemetry must not break PD). Facts are TRI-STATE
17
+ * ("Unknown ≠ false"):
18
+ *
19
+ * true = source evaluable AND evidence observed
20
+ * false = source evaluable AND definitively no evidence (e.g. the DB file
21
+ * does not exist at all — absence of any record IS the answer)
22
+ * null = source not currently evaluable (file exists but unreadable,
23
+ * required table missing in an old schema, receipt collection
24
+ * disabled) — recorded in local-only notes, never exported as
25
+ * "observed false"
26
+ *
27
+ * Per-milestone evaluability (not all-or-nothing): each milestone consults
28
+ * only ITS authority/fallback sources; e.g. a malformed principle ledger
29
+ * does not make `initialized` unknown while state.db is readable.
30
+ * `principleObserved` combines its two evidence populations (pipeline
31
+ * candidates ∪ tree principles) with a three-valued OR: either source
32
+ * observing evidence yields true, false only when BOTH populations are
33
+ * definitively empty, and null whenever a population is unknown and the
34
+ * other did not observe evidence (Kleene OR — an evaluated-empty source
35
+ * can never resolve another source's unknown).
36
+ *
37
+ * `initializationFailed` can only be TRUE from an explicit readable-DB fact
38
+ * (state.db exists, opens, and its schema is definitively not initialized).
39
+ * An unreadable DB is an UNKNOWN, never a reported initialization failure —
40
+ * a read failure must not fabricate release-health signal.
41
+ *
42
+ * Receipt gating: when the `principle_receipt_ledger` flag is disabled, no
43
+ * receipt rows are being written, so absence of rows proves nothing — the
44
+ * receipt milestones render `null` (unavailable), not false.
45
+ *
46
+ * Every connection is closed before return (leaked handles would block
47
+ * Windows file cleanup and accumulate in the gateway process).
48
+ */
49
+ import type { ProductTelemetryMilestoneInput, TelemetryFact } from '@principles/core/runtime-v2';
50
+ export interface MilestoneFacts extends ProductTelemetryMilestoneInput {
51
+ initializationFailed: TelemetryFact;
52
+ }
53
+ export interface MilestoneReadResult {
54
+ facts: MilestoneFacts;
55
+ /** Local-only observability notes (never exported). */
56
+ notes: string[];
57
+ }
58
+ /**
59
+ * Derive milestone facts for one workspace. Never throws.
60
+ */
61
+ export declare function readMilestoneFacts(workspaceDir: string): MilestoneReadResult;
@@ -0,0 +1,234 @@
1
+ /**
2
+ * Durable-fact milestone readers — Anonymous Product Telemetry v1
3
+ * (PRI-598, SPEC §21-§31; review remediation: tri-state facts).
4
+ *
5
+ * Read-only derivation of the six milestone facts from the authoritative
6
+ * durable sources verified in the Phase 0 authority matrix
7
+ * (docs/audit/anonymous-product-telemetry-feasibility.md §4):
8
+ *
9
+ * initialized <ws>/.pd/state.db schema_version populated
10
+ * painObserved <ws>/.state/trajectory.db pain_events EXISTS
11
+ * principleObserved principle tree ledger non-empty OR state.db principle_candidates EXISTS
12
+ * activationObserved state.db activations EXISTS
13
+ * presenceReceiptObserved state.db principle_applications level='presence' EXISTS
14
+ * effectReceiptObserved state.db principle_applications level='effect' EXISTS
15
+ *
16
+ * Readers never throw (telemetry must not break PD). Facts are TRI-STATE
17
+ * ("Unknown ≠ false"):
18
+ *
19
+ * true = source evaluable AND evidence observed
20
+ * false = source evaluable AND definitively no evidence (e.g. the DB file
21
+ * does not exist at all — absence of any record IS the answer)
22
+ * null = source not currently evaluable (file exists but unreadable,
23
+ * required table missing in an old schema, receipt collection
24
+ * disabled) — recorded in local-only notes, never exported as
25
+ * "observed false"
26
+ *
27
+ * Per-milestone evaluability (not all-or-nothing): each milestone consults
28
+ * only ITS authority/fallback sources; e.g. a malformed principle ledger
29
+ * does not make `initialized` unknown while state.db is readable.
30
+ * `principleObserved` combines its two evidence populations (pipeline
31
+ * candidates ∪ tree principles) with a three-valued OR: either source
32
+ * observing evidence yields true, false only when BOTH populations are
33
+ * definitively empty, and null whenever a population is unknown and the
34
+ * other did not observe evidence (Kleene OR — an evaluated-empty source
35
+ * can never resolve another source's unknown).
36
+ *
37
+ * `initializationFailed` can only be TRUE from an explicit readable-DB fact
38
+ * (state.db exists, opens, and its schema is definitively not initialized).
39
+ * An unreadable DB is an UNKNOWN, never a reported initialization failure —
40
+ * a read failure must not fabricate release-health signal.
41
+ *
42
+ * Receipt gating: when the `principle_receipt_ledger` flag is disabled, no
43
+ * receipt rows are being written, so absence of rows proves nothing — the
44
+ * receipt milestones render `null` (unavailable), not false.
45
+ *
46
+ * Every connection is closed before return (leaked handles would block
47
+ * Windows file cleanup and accumulate in the gateway process).
48
+ */
49
+ import fs from 'node:fs';
50
+ import path from 'node:path';
51
+ import Database from 'better-sqlite3';
52
+ import { loadLedger } from '@principles/core/principle-tree-ledger';
53
+ import { loadFeatureFlagFromConfig } from '../pd-config.js';
54
+ /** Feature flag whose absence of writes makes receipt absence unprovable. */
55
+ const RECEIPT_LEDGER_FLAG = 'principle_receipt_ledger';
56
+ /**
57
+ * Three-valued OR for the principle milestone's two evidence populations
58
+ * (pipeline candidates ∪ tree principles). `false` from one source means
59
+ * "its population is definitively empty" — it can never resolve the OTHER
60
+ * source's unknown, so any null keeps the existence claim unknown:
61
+ * true OR anything → true (evidence observed somewhere)
62
+ * false AND false → false (both populations definitively empty)
63
+ * otherwise → null
64
+ * Review round 4: an authority-first variant that let a single definite
65
+ * `false` override a `null` silently degraded "unknown" into
66
+ * "observed false".
67
+ */
68
+ function kleeneOr(a, b) {
69
+ if (a === true || b === true)
70
+ return true;
71
+ if (a === false && b === false)
72
+ return false;
73
+ return null;
74
+ }
75
+ /**
76
+ * Run EXISTS queries against one readonly DB. Opens, queries, closes —
77
+ * the connection never outlives the call. Per-query tri-state:
78
+ * a missing DB file is a DEFINITE false for every query (no record of any
79
+ * kind exists); an unreadable DB or a failing query (missing table in an
80
+ * older schema) is null — the source exists but cannot be evaluated.
81
+ */
82
+ function existsQueries(dbPath, queries, context) {
83
+ const { notes, unavailableNote } = context;
84
+ const results = {};
85
+ try {
86
+ if (!fs.existsSync(dbPath)) {
87
+ for (const key of Object.keys(queries))
88
+ results[key] = false;
89
+ return results;
90
+ }
91
+ }
92
+ catch {
93
+ for (const key of Object.keys(queries))
94
+ results[key] = null;
95
+ notes.push(unavailableNote);
96
+ return results;
97
+ }
98
+ let db;
99
+ try {
100
+ db = new Database(dbPath, { readonly: true });
101
+ }
102
+ catch (error) {
103
+ const message = error instanceof Error ? error.message.split('\n')[0] : String(error);
104
+ for (const key of Object.keys(queries))
105
+ results[key] = null;
106
+ notes.push(`${unavailableNote}: ${message}`);
107
+ return results;
108
+ }
109
+ try {
110
+ for (const [key, sql] of Object.entries(queries)) {
111
+ try {
112
+ results[key] = db.prepare(sql).pluck().get() === 1;
113
+ }
114
+ catch (error) {
115
+ const message = error instanceof Error ? error.message.split('\n')[0] : String(error);
116
+ results[key] = null;
117
+ notes.push(`${unavailableNote}: ${message}`);
118
+ }
119
+ }
120
+ }
121
+ finally {
122
+ db.close();
123
+ }
124
+ return results;
125
+ }
126
+ /**
127
+ * Derive milestone facts for one workspace. Never throws.
128
+ */
129
+ export function readMilestoneFacts(workspaceDir) {
130
+ const notes = [];
131
+ const facts = {
132
+ initialized: false,
133
+ painObserved: false,
134
+ principleObserved: false,
135
+ activationObserved: false,
136
+ presenceReceiptObserved: false,
137
+ effectReceiptObserved: false,
138
+ initializationFailed: false,
139
+ };
140
+ const workspace = path.resolve(workspaceDir);
141
+ const stateDbPath = path.join(workspace, '.pd', 'state.db');
142
+ // existsSync never throws (errors render as false) — safe inside the
143
+ // never-throws contract; the single lookup is shared by the note and the
144
+ // initializationFailed derivation below.
145
+ const stateDbExists = fs.existsSync(stateDbPath);
146
+ // The table-existence and populated checks are SEPARATE queries: a compound
147
+ // `EXISTS(sqlite_master…) AND EXISTS(schema_version)` errors out when the
148
+ // table is missing, which would erase the definitive "table absent" fact
149
+ // and render a readable DB unknown.
150
+ const stateResults = existsQueries(stateDbPath, {
151
+ schemaTableExists: "SELECT EXISTS(SELECT 1 FROM sqlite_master WHERE type='table' AND name='schema_version')",
152
+ schemaVersionPopulated: 'SELECT EXISTS(SELECT 1 FROM schema_version)',
153
+ principleCandidates: 'SELECT EXISTS(SELECT 1 FROM principle_candidates)',
154
+ activations: 'SELECT EXISTS(SELECT 1 FROM activations)',
155
+ presenceReceipts: "SELECT EXISTS(SELECT 1 FROM principle_applications WHERE level='presence')",
156
+ effectReceipts: "SELECT EXISTS(SELECT 1 FROM principle_applications WHERE level='effect')",
157
+ }, { notes, unavailableNote: 'state_db_unreadable' });
158
+ if (!stateDbExists) {
159
+ // Distinct from unreadable: no DB at all means PD never ran here — a
160
+ // definite negative, not a degraded source.
161
+ notes.push('state_db_missing');
162
+ }
163
+ // noUncheckedIndexedAccess: a missing key would be a programmer error in
164
+ // the query table above; it degrades to null (unavailable), never false.
165
+ const schemaTableExists = stateResults.schemaTableExists ?? null;
166
+ const schemaVersionPopulated = stateResults.schemaVersionPopulated ?? null;
167
+ facts.initialized = schemaTableExists === null ? null : schemaTableExists === false ? false : schemaVersionPopulated ?? null;
168
+ // initializationFailed is claimable ONLY from a readable DB whose schema is
169
+ // DEFINITIVELY not initialized (explicit failure fact). A missing DB means
170
+ // PD was never brought up in this workspace (false); an unreadable or
171
+ // unevaluable schema query means we cannot know (null) — a read failure
172
+ // must never be recorded as an initialization failure.
173
+ facts.initializationFailed = !stateDbExists ? false : facts.initialized === null ? null : !facts.initialized;
174
+ facts.principleObserved = stateResults.principleCandidates ?? null;
175
+ facts.activationObserved = stateResults.activations ?? null;
176
+ // Receipt gating: with the ledger flag off, no receipt rows are written,
177
+ // so "no rows" is not evidence of "no receipts" — unavailable, not false.
178
+ const receiptFlag = loadFeatureFlagFromConfig(workspace, RECEIPT_LEDGER_FLAG);
179
+ if (!receiptFlag.enabled) {
180
+ facts.presenceReceiptObserved = null;
181
+ facts.effectReceiptObserved = null;
182
+ notes.push('receipt_collection_disabled');
183
+ }
184
+ else {
185
+ facts.presenceReceiptObserved = stateResults.presenceReceipts ?? null;
186
+ facts.effectReceiptObserved = stateResults.effectReceipts ?? null;
187
+ }
188
+ const trajectoryResults = existsQueries(path.join(workspace, '.state', 'trajectory.db'), { painEvents: 'SELECT EXISTS(SELECT 1 FROM pain_events)' }, { notes, unavailableNote: 'trajectory_db_unreadable' });
189
+ facts.painObserved = trajectoryResults.painEvents ?? null;
190
+ // Ledger fallback. loadLedger is fail-soft by contract (returns an empty
191
+ // tree for anything it cannot read), which would silently render a
192
+ // malformed ledger as "definitely no principles" — exactly the unknown→false
193
+ // collapse this remediation removes. Preflight the raw file so parse
194
+ // failures surface as null; loadLedger still owns the shape interpretation.
195
+ let ledgerFact = false;
196
+ const stateDir = path.join(workspace, '.state');
197
+ const ledgerPath = path.join(stateDir, 'principle_training_state.json');
198
+ const ledgerFilePresent = (() => {
199
+ try {
200
+ return fs.existsSync(ledgerPath);
201
+ }
202
+ catch {
203
+ return false;
204
+ }
205
+ })();
206
+ if (ledgerFilePresent) {
207
+ const preflightOk = (() => {
208
+ try {
209
+ JSON.parse(fs.readFileSync(ledgerPath, 'utf8'));
210
+ return true;
211
+ }
212
+ catch {
213
+ return false;
214
+ }
215
+ })();
216
+ if (!preflightOk) {
217
+ ledgerFact = null;
218
+ notes.push('principle_ledger_malformed');
219
+ }
220
+ else {
221
+ try {
222
+ const ledger = loadLedger(stateDir);
223
+ const principles = ledger?.tree?.principles;
224
+ ledgerFact = principles !== null && typeof principles === 'object' && Object.keys(principles).length > 0 ? true : false;
225
+ }
226
+ catch {
227
+ ledgerFact = null;
228
+ notes.push('principle_ledger_malformed');
229
+ }
230
+ }
231
+ }
232
+ facts.principleObserved = kleeneOr(facts.principleObserved, ledgerFact);
233
+ return { facts, notes };
234
+ }
@@ -0,0 +1,142 @@
1
+ /**
2
+ * Product telemetry service — Anonymous Product Telemetry v1
3
+ * (PRI-597/598/599 orchestration; review remediation: workspace unit).
4
+ *
5
+ * Single seam for the CLI control plane (`pd telemetry status/enable/disable/
6
+ * preview/reset`) and the two fire-and-forget export triggers (OpenClaw plugin
7
+ * workspace init, pd-console startup). Export requires ALL gates:
8
+ *
9
+ * canExport = feature flag anonymous_product_telemetry (workspace config)
10
+ * AND consent granted (~/.pd/product-telemetry.json)
11
+ * AND environment not suppressed (eligibility.ts)
12
+ *
13
+ * Scope model (review remediation P1-1): the MEASUREMENT UNIT is the
14
+ * workspace. Consent, consentVersion, and the telemetry secret are
15
+ * machine-scope; the daily identity, dedup, retry bookkeeping, and export
16
+ * lock are workspace-scope. One workspace's success/backoff/lock never
17
+ * suppresses another workspace on the same installation.
18
+ */
19
+ import { type ProductTelemetrySnapshotV1 } from '@principles/core/runtime-v2';
20
+ import { type ProductTelemetryConsent } from './consent-store.js';
21
+ import { type TelemetrySuppressionReason } from './eligibility.js';
22
+ import { type TelemetryFetchFn } from './exporter.js';
23
+ export declare const ANONYMOUS_PRODUCT_TELEMETRY_FLAG = "anonymous_product_telemetry";
24
+ export declare const PD_TELEMETRY_DISABLED_ENV = "PD_TELEMETRY_DISABLED";
25
+ export declare const PREVIEW_BANNER = "Preview only. Nothing was sent.";
26
+ /** Hard cap on export attempts per UTC day per workspace (1 initial + 4 retries; review round 2). */
27
+ export declare const MAX_DAILY_EXPORT_ATTEMPTS = 5;
28
+ export interface ProductTelemetryServiceDeps {
29
+ /** Installation home dir. Default os.homedir(). */
30
+ homeDir?: string;
31
+ /** Environment snapshot. Default process.env (injected in tests). */
32
+ env?: Record<string, string | undefined>;
33
+ /** Executing module dir for repo-checkout detection. Default this file's dir. */
34
+ moduleDir?: string;
35
+ fetchFn?: TelemetryFetchFn;
36
+ endpoint?: string;
37
+ now?: () => number;
38
+ logger?: {
39
+ info?: (message: string) => void;
40
+ warn?: (message: string) => void;
41
+ };
42
+ }
43
+ export interface TelemetryGates {
44
+ flagEnabled: boolean | null;
45
+ flagSource: string | null;
46
+ consent: ProductTelemetryConsent;
47
+ environmentSuppressed: boolean;
48
+ suppressionReasons: TelemetrySuppressionReason[];
49
+ /** All gates open right now (for the resolved workspace). */
50
+ canExport: boolean;
51
+ blockers: string[];
52
+ }
53
+ export interface ProductTelemetryStatusView extends TelemetryGates {
54
+ consentVersion: string;
55
+ hasSecret: boolean;
56
+ lastAttemptedAt?: string;
57
+ lastSucceededAt?: string;
58
+ lastFailureCode?: string;
59
+ nextRetryAt?: string;
60
+ endpoint: string;
61
+ nextAction?: string;
62
+ }
63
+ export interface ProductTelemetryPreview {
64
+ banner: typeof PREVIEW_BANNER;
65
+ snapshot: ProductTelemetrySnapshotV1;
66
+ gates: TelemetryGates;
67
+ /** Local-only reader notes (source degraded reasons) — never exported. */
68
+ notes: string[];
69
+ /** True when no stored secret exists yet and an ephemeral one was derived for display. */
70
+ secretEphemeral: boolean;
71
+ }
72
+ export type MaybeExportOutcome = {
73
+ attempted: true;
74
+ ok: boolean;
75
+ httpStatus?: number;
76
+ failureCode?: string;
77
+ } | {
78
+ attempted: false;
79
+ skipReason: string;
80
+ };
81
+ export declare function createProductTelemetryService(deps?: ProductTelemetryServiceDeps): {
82
+ /** Status for `pd telemetry status`. Never exposes the secret. */
83
+ getStatus(workspaceDir?: string): {
84
+ ok: true;
85
+ view: ProductTelemetryStatusView;
86
+ } | {
87
+ ok: false;
88
+ reason: string;
89
+ nextAction: string;
90
+ };
91
+ /** Exact outbound payload for `pd telemetry preview`. Never sends. */
92
+ preview(workspaceDir: string): ProductTelemetryPreview;
93
+ /** `pd telemetry enable --confirm`: explicit granted consent (+ secret). */
94
+ enable(): {
95
+ ok: true;
96
+ consent: 'granted';
97
+ } | {
98
+ ok: false;
99
+ reason: string;
100
+ nextAction: string;
101
+ };
102
+ /** `pd telemetry disable --confirm`: deny consent and delete export identity. */
103
+ disable(): {
104
+ ok: true;
105
+ consent: 'denied';
106
+ } | {
107
+ ok: false;
108
+ reason: string;
109
+ nextAction: string;
110
+ };
111
+ /** `pd telemetry reset --confirm`: delete identity; fresh secret only if still enabled. */
112
+ reset(): {
113
+ ok: true;
114
+ consent: ProductTelemetryConsent;
115
+ } | {
116
+ ok: false;
117
+ reason: string;
118
+ nextAction: string;
119
+ };
120
+ /**
121
+ * One gate-checked export attempt for a normal-activity trigger.
122
+ * Never throws; every path returns a structured outcome.
123
+ *
124
+ * Concurrency: a per-workspace lock file
125
+ * (`product-telemetry.json.export-lock.<scopeId>`) closes the read→send→
126
+ * write race between simultaneous triggers (OpenClaw gateway init +
127
+ * pd-console startup in different processes) WITHOUT coupling unrelated
128
+ * workspaces. Stale locks (crashed holder) are taken over after
129
+ * EXPORT_LOCK_STALE_MS.
130
+ */
131
+ maybeExportDaily(workspaceDir: string): Promise<MaybeExportOutcome>;
132
+ };
133
+ export type ProductTelemetryService = ReturnType<typeof createProductTelemetryService>;
134
+ /**
135
+ * Fire-and-forget scheduling for normal-activity triggers. The timer is
136
+ * unref'd so it never keeps a host process alive, and every failure path is
137
+ * contained — telemetry can never block or crash PD startup or hooks.
138
+ */
139
+ export declare function scheduleProductTelemetryExport(service: ProductTelemetryService, workspaceDir: string, scheduleLogger?: {
140
+ info?: (message: string) => void;
141
+ warn?: (message: string) => void;
142
+ }): void;