create-principles-disciple 1.121.8 → 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 +3 -1
  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 +2 -3
  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 +6 -1
  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 +2 -1
  440. package/plugin/dist/bundle.js +868 -936
  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
@@ -1,20 +1,19 @@
1
1
  import * as fs from 'node:fs';
2
2
  import * as path from 'node:path';
3
3
  import { Value } from '@sinclair/typebox/value';
4
- import { GovernanceFactsSchema, SqliteConnection, isPDErrorCategory, parsePITaskMetadata, } from '@principles/core/runtime-v2';
5
- const GOVERNANCE_TASK_KINDS = new Set([
4
+ import { GovernanceFactsSchema, SqliteConnection, isPDErrorCategory, parsePITaskMetadata, PD_TASK_STATUSES, PRINCIPLE_STATUSES, isPDTaskStatus, } from '@principles/core/runtime-v2';
5
+ export const GOVERNANCE_TASK_KINDS = new Set([
6
6
  'dreamer', 'philosopher', 'scribe', 'artificer', 'evaluator', 'rollout_reviewer',
7
7
  ]);
8
- const GOVERNANCE_TASK_STATUSES = new Set([
9
- 'pending', 'leased', 'succeeded', 'retry_wait', 'failed', 'needs_human_review',
10
- ]);
11
- const PRINCIPLE_STATES = new Set(['candidate', 'active', 'archived', 'deprecated', 'probation']);
8
+ // PRI-612: both status sets derive from the canonical core authorities.
9
+ export const GOVERNANCE_TASK_STATUSES = new Set(PD_TASK_STATUSES);
10
+ const PRINCIPLE_STATES = new Set(PRINCIPLE_STATUSES);
12
11
  const ISO_UTC = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{3})?Z$/;
13
12
  const MAX_LINEAGE_NODES = 500;
14
- function isRecord(value) {
13
+ export function isRecord(value) {
15
14
  return value !== null && typeof value === 'object' && !Array.isArray(value);
16
15
  }
17
- function readOwnString(record, key) {
16
+ export function readOwnString(record, key) {
18
17
  if (!Object.hasOwn(record, key))
19
18
  return undefined;
20
19
  const value = record[key];
@@ -57,317 +56,356 @@ export class GovernanceProjectionCollector {
57
56
  const principle = this.readPrinciple(principleId, collectionIssues);
58
57
  const dbPath = path.join(this.workspaceDir, '.pd', 'state.db');
59
58
  if (!fs.existsSync(dbPath)) {
60
- collectionIssues.push(issue({ source: 'lineage', reasonCode: 'source_unavailable', nextActionCode: 'initialize_runtime_state' }));
61
- return GovernanceProjectionCollector.finish({ principleId, asOf, principle, collectionIssues });
59
+ return GovernanceProjectionCollector.factsForUnavailableSource({ principleId, asOf, principle, collectionIssues });
62
60
  }
63
- const connection = new SqliteConnection({ workspaceDir: this.workspaceDir, readonly: true });
64
61
  try {
65
- const db = connection.getDb();
66
- const artifactIds = [];
67
- const rootTaskIds = [];
68
- const sourceRefs = [{ type: 'principle', id: principleId }];
69
- const artifactRows = db.prepare(`
70
- SELECT artifact_id, source_task_id, source_principle_id, lineage_artifact_ids, updated_at
71
- FROM pi_artifacts ORDER BY artifact_id ASC
72
- `).all();
73
- const validArtifacts = new Map();
74
- for (const row of artifactRows) {
75
- if (!isRecord(row)) {
76
- collectionIssues.push(issue({ source: 'artifact', reasonCode: 'metadata_malformed', nextActionCode: 'repair_artifact_metadata' }));
77
- continue;
78
- }
79
- const artifactId = readOwnString(row, 'artifact_id');
80
- const sourceTaskId = readOwnString(row, 'source_task_id');
81
- const sourcePrincipleId = readOwnString(row, 'source_principle_id');
82
- const updatedAt = readOwnString(row, 'updated_at');
83
- const lineageJson = readOwnString(row, 'lineage_artifact_ids');
84
- const lineageArtifactIds = GovernanceProjectionCollector.parseStringArrayJson(lineageJson);
85
- const artifactRef = artifactId === undefined ? undefined : { type: 'artifact', id: artifactId };
86
- if (artifactId === undefined || sourceTaskId === undefined || !isTimestamp(updatedAt)
87
- || lineageArtifactIds === null) {
88
- if (sourcePrincipleId === principleId) {
89
- collectionIssues.push(issue(artifactRef === undefined
90
- ? { source: 'artifact', reasonCode: 'metadata_malformed', nextActionCode: 'repair_artifact_metadata' }
91
- : { source: 'artifact', reasonCode: 'metadata_malformed', nextActionCode: 'repair_artifact_metadata', sourceRef: artifactRef }));
92
- }
93
- continue;
94
- }
95
- validArtifacts.set(artifactId, {
96
- artifactId, sourceTaskId, lineageArtifactIds,
97
- ...(sourcePrincipleId === undefined ? {} : { sourcePrincipleId }),
98
- });
62
+ const tables = GovernanceProjectionCollector.readTables(this.workspaceDir);
63
+ return GovernanceProjectionCollector.buildFacts({ principleId, asOf, principle, tables, collectionIssues });
64
+ }
65
+ catch (error) {
66
+ if (error instanceof GovernanceProjectionCollectionError)
67
+ throw error;
68
+ throw new GovernanceProjectionCollectionError('governance_projection_error', 'inspect_runtime_state');
69
+ }
70
+ }
71
+ /** Degraded facts shape used when state.db is unavailable (shared by single + batch collectors). */
72
+ static factsForUnavailableSource(input) {
73
+ const { principleId, asOf, principle, collectionIssues } = input;
74
+ collectionIssues.push(issue({ source: 'lineage', reasonCode: 'source_unavailable', nextActionCode: 'initialize_runtime_state' }));
75
+ return GovernanceProjectionCollector.finish({ principleId, asOf, principle, collectionIssues });
76
+ }
77
+ /** Reads the four projection tables once. Closes its own connection unless one is injected (caller then owns closing). */
78
+ static readTables(workspaceDir, injected) {
79
+ const own = injected === undefined ? new SqliteConnection({ workspaceDir, readonly: true }) : null;
80
+ try {
81
+ const db = (injected ?? own)?.getDb();
82
+ if (db === undefined)
83
+ throw new Error('readTables: no database handle');
84
+ return {
85
+ artifactRows: db.prepare(`
86
+ SELECT artifact_id, source_task_id, source_principle_id, lineage_artifact_ids, updated_at
87
+ FROM pi_artifacts ORDER BY artifact_id ASC
88
+ `).all(),
89
+ taskRows: db.prepare('SELECT * FROM tasks ORDER BY task_id ASC').all(),
90
+ approvalRows: db.prepare('SELECT * FROM approvals ORDER BY approval_id ASC').all(),
91
+ activationRows: db.prepare('SELECT * FROM activations ORDER BY activated_at ASC, activation_id ASC').all(),
92
+ };
93
+ }
94
+ finally {
95
+ own?.close();
96
+ }
97
+ }
98
+ /** Groups pre-fetched raw rows into GovernanceFacts for ONE principle. Pure in-memory. */
99
+ static buildFacts(input) {
100
+ const { principleId, asOf, principle, tables, collectionIssues } = input;
101
+ const artifactIds = [];
102
+ const rootTaskIds = [];
103
+ const sourceRefs = [{ type: 'principle', id: principleId }];
104
+ const { artifactRows } = tables;
105
+ const validArtifacts = new Map();
106
+ for (const row of artifactRows) {
107
+ if (!isRecord(row)) {
108
+ collectionIssues.push(issue({ source: 'artifact', reasonCode: 'metadata_malformed', nextActionCode: 'repair_artifact_metadata' }));
109
+ continue;
99
110
  }
100
- const strongArtifactIds = new Set([...validArtifacts.values()].filter(row => row.sourcePrincipleId === principleId).map(row => row.artifactId));
101
- let addedArtifact = true;
102
- while (addedArtifact) {
103
- addedArtifact = false;
104
- for (const row of validArtifacts.values()) {
105
- if (!strongArtifactIds.has(row.artifactId) && row.lineageArtifactIds.some(id => strongArtifactIds.has(id))) {
106
- strongArtifactIds.add(row.artifactId);
107
- addedArtifact = true;
108
- }
111
+ const artifactId = readOwnString(row, 'artifact_id');
112
+ const sourceTaskId = readOwnString(row, 'source_task_id');
113
+ const sourcePrincipleId = readOwnString(row, 'source_principle_id');
114
+ const updatedAt = readOwnString(row, 'updated_at');
115
+ const lineageJson = readOwnString(row, 'lineage_artifact_ids');
116
+ const lineageArtifactIds = GovernanceProjectionCollector.parseStringArrayJson(lineageJson);
117
+ const artifactRef = artifactId === undefined ? undefined : { type: 'artifact', id: artifactId };
118
+ if (artifactId === undefined || sourceTaskId === undefined || !isTimestamp(updatedAt)
119
+ || lineageArtifactIds === null) {
120
+ if (sourcePrincipleId === principleId) {
121
+ collectionIssues.push(issue(artifactRef === undefined
122
+ ? { source: 'artifact', reasonCode: 'metadata_malformed', nextActionCode: 'repair_artifact_metadata' }
123
+ : { source: 'artifact', reasonCode: 'metadata_malformed', nextActionCode: 'repair_artifact_metadata', sourceRef: artifactRef }));
109
124
  }
125
+ continue;
110
126
  }
111
- for (const artifactId of [...strongArtifactIds].sort()) {
112
- const artifact = validArtifacts.get(artifactId);
113
- if (artifact === undefined)
114
- continue;
115
- artifactIds.push(artifactId);
116
- rootTaskIds.push(artifact.sourceTaskId);
117
- sourceRefs.push({ type: 'artifact', id: artifactId });
118
- }
119
- if (artifactIds.length === 0) {
120
- collectionIssues.push(issue({ source: 'lineage', reasonCode: 'lineage_not_available', nextActionCode: 'wait_for_durable_lineage' }));
121
- return GovernanceProjectionCollector.finish({ principleId, asOf, principle, collectionIssues });
127
+ validArtifacts.set(artifactId, {
128
+ artifactId, sourceTaskId, lineageArtifactIds,
129
+ ...(sourcePrincipleId === undefined ? {} : { sourcePrincipleId }),
130
+ });
131
+ }
132
+ const strongArtifactIds = new Set([...validArtifacts.values()].filter(row => row.sourcePrincipleId === principleId).map(row => row.artifactId));
133
+ let addedArtifact = true;
134
+ while (addedArtifact) {
135
+ addedArtifact = false;
136
+ for (const row of validArtifacts.values()) {
137
+ if (!strongArtifactIds.has(row.artifactId) && row.lineageArtifactIds.some(id => strongArtifactIds.has(id))) {
138
+ strongArtifactIds.add(row.artifactId);
139
+ addedArtifact = true;
140
+ }
122
141
  }
123
- const validTasks = new Map();
124
- const taskRowIssues = [];
125
- const taskRows = db.prepare('SELECT * FROM tasks ORDER BY task_id ASC').all();
126
- for (const row of taskRows) {
127
- const parsed = GovernanceProjectionCollector.parseTaskRow(row, taskRowIssues);
128
- if (parsed !== null)
129
- validTasks.set(parsed.taskId, parsed);
142
+ }
143
+ for (const artifactId of [...strongArtifactIds].sort()) {
144
+ const artifact = validArtifacts.get(artifactId);
145
+ if (artifact === undefined)
146
+ continue;
147
+ artifactIds.push(artifactId);
148
+ rootTaskIds.push(artifact.sourceTaskId);
149
+ sourceRefs.push({ type: 'artifact', id: artifactId });
150
+ }
151
+ if (artifactIds.length === 0) {
152
+ collectionIssues.push(issue({ source: 'lineage', reasonCode: 'lineage_not_available', nextActionCode: 'wait_for_durable_lineage' }));
153
+ return GovernanceProjectionCollector.finish({ principleId, asOf, principle, collectionIssues });
154
+ }
155
+ const validTasks = new Map();
156
+ const taskRowIssues = [];
157
+ const { taskRows } = tables;
158
+ for (const row of taskRows) {
159
+ const parsed = GovernanceProjectionCollector.parseTaskRow(row, taskRowIssues);
160
+ if (parsed !== null)
161
+ validTasks.set(parsed.taskId, parsed);
162
+ }
163
+ const connected = GovernanceProjectionCollector.connectedTaskIds(rootTaskIds, validTasks, collectionIssues);
164
+ const taskLineageConfidence = collectionIssues.some(item => item.reasonCode === 'lineage_cycle' || item.reasonCode === 'lineage_limit_exceeded') ? 'weak' : 'strong';
165
+ for (const taskIssue of taskRowIssues) {
166
+ if (taskIssue.sourceRef?.type === 'task' && connected.has(taskIssue.sourceRef.id)) {
167
+ collectionIssues.push(taskIssue);
130
168
  }
131
- const connected = GovernanceProjectionCollector.connectedTaskIds(rootTaskIds, validTasks, collectionIssues);
132
- const taskLineageConfidence = collectionIssues.some(item => item.reasonCode === 'lineage_cycle' || item.reasonCode === 'lineage_limit_exceeded') ? 'weak' : 'strong';
133
- for (const taskIssue of taskRowIssues) {
134
- if (taskIssue.sourceRef?.type === 'task' && connected.has(taskIssue.sourceRef.id)) {
135
- collectionIssues.push(taskIssue);
136
- }
169
+ }
170
+ const tasks = [];
171
+ const runnerVerdicts = [];
172
+ const derivedRelations = [];
173
+ const revisionIdentities = [];
174
+ const timelineEvents = [];
175
+ const materializedRevisionSources = new Set();
176
+ for (const taskId of connected) {
177
+ const task = validTasks.get(taskId);
178
+ if (task === undefined) {
179
+ collectionIssues.push(issue({ source: 'task', reasonCode: 'metadata_malformed', nextActionCode: 'repair_task_metadata', sourceRef: { type: 'task', id: taskId } }));
180
+ continue;
137
181
  }
138
- const tasks = [];
139
- const runnerVerdicts = [];
140
- const derivedRelations = [];
141
- const revisionIdentities = [];
142
- const timelineEvents = [];
143
- const materializedRevisionSources = new Set();
144
- for (const taskId of connected) {
145
- const task = validTasks.get(taskId);
146
- if (task === undefined) {
147
- collectionIssues.push(issue({ source: 'task', reasonCode: 'metadata_malformed', nextActionCode: 'repair_task_metadata', sourceRef: { type: 'task', id: taskId } }));
182
+ if (task.revisionIdentity !== undefined) {
183
+ const identity = task.revisionIdentity;
184
+ const sourceTaskId = identity.kind === 'evaluator_repair'
185
+ ? identity.sourceEvaluatorTaskId
186
+ : identity.kind === 'rollout_reopen' ? identity.sourceRolloutTaskId : undefined;
187
+ const sourceArtifactId = identity.kind === 'evaluator_repair'
188
+ ? identity.sourceArtificerArtifactId
189
+ : identity.kind === 'rollout_reopen' ? identity.sourceArtifactId : undefined;
190
+ if (sourceTaskId === undefined || sourceArtifactId === undefined
191
+ || !connected.has(sourceTaskId) || !strongArtifactIds.has(sourceArtifactId)) {
192
+ collectionIssues.push(issue({
193
+ source: 'lineage', reasonCode: 'lineage_conflict', nextActionCode: 'repair_revision_lineage',
194
+ sourceRef: { type: 'task', id: task.taskId },
195
+ }));
148
196
  continue;
149
197
  }
150
- if (task.revisionIdentity !== undefined) {
151
- const identity = task.revisionIdentity;
152
- const sourceTaskId = identity.kind === 'evaluator_repair'
153
- ? identity.sourceEvaluatorTaskId
154
- : identity.kind === 'rollout_reopen' ? identity.sourceRolloutTaskId : undefined;
155
- const sourceArtifactId = identity.kind === 'evaluator_repair'
156
- ? identity.sourceArtificerArtifactId
157
- : identity.kind === 'rollout_reopen' ? identity.sourceArtifactId : undefined;
158
- if (sourceTaskId === undefined || sourceArtifactId === undefined
159
- || !connected.has(sourceTaskId) || !strongArtifactIds.has(sourceArtifactId)) {
160
- collectionIssues.push(issue({
161
- source: 'lineage', reasonCode: 'lineage_conflict', nextActionCode: 'repair_revision_lineage',
162
- sourceRef: { type: 'task', id: task.taskId },
163
- }));
164
- continue;
165
- }
166
- revisionIdentities.push(identity);
167
- materializedRevisionSources.add(sourceTaskId);
168
- derivedRelations.push({
169
- schemaVersion: '1', family: 'derived_relation', sourceRef: { type: 'task', id: task.taskId }, principleId,
170
- taskId: task.taskId, lineageConfidence: taskLineageConfidence, recordedAt: task.updatedAt,
171
- revisionIdentity: identity, relation: 'revision_materialized',
172
- evidenceRefs: [
173
- { type: 'task', id: sourceTaskId },
174
- { type: 'artifact', id: sourceArtifactId },
175
- { type: 'task', id: task.taskId },
176
- ],
177
- });
178
- timelineEvents.push({
179
- code: 'revision_reopened', occurredAt: task.createdAt, recordedAt: task.updatedAt,
180
- summaryCode: 'governance.timeline.revision_reopened', sourceRef: { type: 'task', id: task.taskId },
181
- lineageConfidence: taskLineageConfidence,
182
- });
183
- }
184
- const fact = {
185
- schemaVersion: '1', family: 'task', sourceRef: { type: 'task', id: task.taskId }, principleId,
198
+ revisionIdentities.push(identity);
199
+ materializedRevisionSources.add(sourceTaskId);
200
+ derivedRelations.push({
201
+ schemaVersion: '1', family: 'derived_relation', sourceRef: { type: 'task', id: task.taskId }, principleId,
186
202
  taskId: task.taskId, lineageConfidence: taskLineageConfidence, recordedAt: task.updatedAt,
187
- occurredAt: task.createdAt, taskKind: task.taskKind, channel: task.channel, status: task.status,
188
- attemptCount: task.attemptCount, maxAttempts: task.maxAttempts,
189
- };
190
- if (task.leaseExpiresAt !== undefined)
191
- fact.leaseExpiresAt = task.leaseExpiresAt;
192
- if (task.lastErrorCategory !== undefined)
193
- fact.lastErrorCategory = task.lastErrorCategory;
194
- if (task.revisionIdentity !== undefined) {
195
- fact.revisionIdentity = task.revisionIdentity;
196
- }
197
- if (task.completionIntent !== undefined)
198
- fact.completionIntent = task.completionIntent;
199
- tasks.push(fact);
200
- sourceRefs.push(fact.sourceRef);
201
- if ((task.taskKind === 'evaluator' || task.taskKind === 'rollout_reviewer') && task.runnerDecision !== undefined) {
202
- runnerVerdicts.push({
203
- schemaVersion: '1', family: 'runner_verdict', sourceRef: fact.sourceRef, principleId,
204
- taskId: task.taskId, lineageConfidence: taskLineageConfidence, recordedAt: task.updatedAt,
205
- runnerKind: task.taskKind, outcome: task.runnerDecision,
206
- });
207
- timelineEvents.push({
208
- code: 'review_started', occurredAt: task.createdAt, recordedAt: task.updatedAt,
209
- summaryCode: 'governance.timeline.review_started', sourceRef: fact.sourceRef, lineageConfidence: taskLineageConfidence,
210
- });
211
- if (task.runnerDecision === 'needs_revision') {
212
- timelineEvents.push({
213
- code: 'revision_requested', occurredAt: task.updatedAt, recordedAt: task.updatedAt,
214
- summaryCode: 'governance.timeline.revision_requested', sourceRef: fact.sourceRef, lineageConfidence: taskLineageConfidence,
215
- });
216
- }
217
- }
218
- else if ((task.taskKind === 'evaluator' || task.taskKind === 'rollout_reviewer') && task.status === 'succeeded') {
219
- derivedRelations.push({
220
- schemaVersion: '1', family: 'derived_relation', sourceRef: fact.sourceRef, principleId,
221
- taskId: task.taskId, lineageConfidence: taskLineageConfidence, recordedAt: task.updatedAt,
222
- relation: 'verdict_missing', evidenceRefs: [fact.sourceRef],
223
- });
224
- }
225
- if (task.status === 'failed' || task.status === 'needs_human_review') {
226
- const code = task.status === 'failed' ? 'failed' : 'human_review';
203
+ revisionIdentity: identity, relation: 'revision_materialized',
204
+ evidenceRefs: [
205
+ { type: 'task', id: sourceTaskId },
206
+ { type: 'artifact', id: sourceArtifactId },
207
+ { type: 'task', id: task.taskId },
208
+ ],
209
+ });
210
+ timelineEvents.push({
211
+ code: 'revision_reopened', occurredAt: task.createdAt, recordedAt: task.updatedAt,
212
+ summaryCode: 'governance.timeline.revision_reopened', sourceRef: { type: 'task', id: task.taskId },
213
+ lineageConfidence: taskLineageConfidence,
214
+ });
215
+ }
216
+ const fact = {
217
+ schemaVersion: '1', family: 'task', sourceRef: { type: 'task', id: task.taskId }, principleId,
218
+ taskId: task.taskId, lineageConfidence: taskLineageConfidence, recordedAt: task.updatedAt,
219
+ occurredAt: task.createdAt, taskKind: task.taskKind, channel: task.channel, status: task.status,
220
+ attemptCount: task.attemptCount, maxAttempts: task.maxAttempts,
221
+ };
222
+ if (task.leaseExpiresAt !== undefined)
223
+ fact.leaseExpiresAt = task.leaseExpiresAt;
224
+ if (task.lastErrorCategory !== undefined)
225
+ fact.lastErrorCategory = task.lastErrorCategory;
226
+ if (task.revisionIdentity !== undefined) {
227
+ fact.revisionIdentity = task.revisionIdentity;
228
+ }
229
+ if (task.completionIntent !== undefined)
230
+ fact.completionIntent = task.completionIntent;
231
+ tasks.push(fact);
232
+ sourceRefs.push(fact.sourceRef);
233
+ if ((task.taskKind === 'evaluator' || task.taskKind === 'rollout_reviewer') && task.runnerDecision !== undefined) {
234
+ runnerVerdicts.push({
235
+ schemaVersion: '1', family: 'runner_verdict', sourceRef: fact.sourceRef, principleId,
236
+ taskId: task.taskId, lineageConfidence: taskLineageConfidence, recordedAt: task.updatedAt,
237
+ runnerKind: task.taskKind, outcome: task.runnerDecision,
238
+ });
239
+ timelineEvents.push({
240
+ code: 'review_started', occurredAt: task.createdAt, recordedAt: task.updatedAt,
241
+ summaryCode: 'governance.timeline.review_started', sourceRef: fact.sourceRef, lineageConfidence: taskLineageConfidence,
242
+ });
243
+ if (task.runnerDecision === 'needs_revision') {
227
244
  timelineEvents.push({
228
- code, occurredAt: task.updatedAt, recordedAt: task.updatedAt,
229
- summaryCode: `governance.timeline.${code}`, sourceRef: fact.sourceRef, lineageConfidence: taskLineageConfidence,
245
+ code: 'revision_requested', occurredAt: task.updatedAt, recordedAt: task.updatedAt,
246
+ summaryCode: 'governance.timeline.revision_requested', sourceRef: fact.sourceRef, lineageConfidence: taskLineageConfidence,
230
247
  });
231
248
  }
232
249
  }
233
- tasks.sort((left, right) => (left.taskId ?? '').localeCompare(right.taskId ?? ''));
234
- const strongTaskIds = new Set(tasks.filter(task => task.lineageConfidence === 'strong').map(task => task.taskId).filter((taskId) => taskId !== undefined));
235
- for (const task of tasks) {
236
- const { taskId } = task;
237
- if (taskId === undefined || task.completionIntent?.status !== 'pending' || materializedRevisionSources.has(taskId))
238
- continue;
250
+ else if ((task.taskKind === 'evaluator' || task.taskKind === 'rollout_reviewer') && task.status === 'succeeded') {
239
251
  derivedRelations.push({
240
- schemaVersion: '1', family: 'derived_relation', sourceRef: task.sourceRef, principleId,
241
- taskId, lineageConfidence: 'strong', recordedAt: task.recordedAt,
242
- relation: 'revision_pending', evidenceRefs: [task.sourceRef],
252
+ schemaVersion: '1', family: 'derived_relation', sourceRef: fact.sourceRef, principleId,
253
+ taskId: task.taskId, lineageConfidence: taskLineageConfidence, recordedAt: task.updatedAt,
254
+ relation: 'verdict_missing', evidenceRefs: [fact.sourceRef],
243
255
  });
244
256
  }
245
- for (const successor of [...validTasks.values()].sort((left, right) => left.taskId.localeCompare(right.taskId))) {
246
- if (!strongTaskIds.has(successor.taskId))
247
- continue;
248
- for (const dependencyTaskId of [...successor.dependencyTaskIds].sort()) {
249
- if (!strongTaskIds.has(dependencyTaskId))
250
- continue;
251
- derivedRelations.push({
252
- schemaVersion: '1', family: 'derived_relation', sourceRef: { type: 'task', id: dependencyTaskId }, principleId,
253
- taskId: dependencyTaskId, lineageConfidence: 'strong', recordedAt: successor.updatedAt,
254
- relation: 'successor_present',
255
- evidenceRefs: [{ type: 'task', id: dependencyTaskId }, { type: 'task', id: successor.taskId }],
256
- });
257
- }
258
- }
259
- const approvals = [];
260
- const activations = [];
261
- for (const row of db.prepare('SELECT * FROM approvals ORDER BY approval_id ASC').all()) {
262
- if (!isRecord(row))
263
- continue;
264
- const artifactId = readOwnString(row, 'artifact_id');
265
- if (artifactId === undefined || !strongArtifactIds.has(artifactId))
266
- continue;
267
- const approvalId = readOwnString(row, 'approval_id');
268
- const channel = readOwnString(row, 'channel');
269
- const outcome = readOwnString(row, 'status');
270
- const requestedAt = readOwnString(row, 'requested_at');
271
- const decidedAt = readOwnString(row, 'decided_at');
272
- const approvalRef = approvalId === undefined ? undefined : { type: 'approval', id: approvalId };
273
- if (approvalId === undefined || !isGovernanceChannel(channel) || !isTimestamp(requestedAt)
274
- || (outcome !== 'pending' && outcome !== 'approved' && outcome !== 'rejected' && outcome !== 'cancelled')
275
- || (decidedAt !== undefined && !isTimestamp(decidedAt))) {
276
- collectionIssues.push(issue(approvalRef === undefined
277
- ? { source: 'approval', reasonCode: 'metadata_malformed', nextActionCode: 'repair_approval_record' }
278
- : { source: 'approval', reasonCode: 'metadata_malformed', nextActionCode: 'repair_approval_record', sourceRef: approvalRef }));
279
- continue;
280
- }
281
- const strongApprovalRef = { type: 'approval', id: approvalId };
282
- const fact = {
283
- schemaVersion: '1', family: 'approval', sourceRef: strongApprovalRef, principleId, artifactId,
284
- approvalId, channel, outcome, lineageConfidence: 'strong', recordedAt: decidedAt ?? requestedAt,
285
- };
286
- if (decidedAt !== undefined)
287
- fact.occurredAt = decidedAt;
288
- approvals.push(fact);
289
- sourceRefs.push(strongApprovalRef);
290
- if (outcome === 'approved' || outcome === 'rejected') {
291
- timelineEvents.push({
292
- code: outcome, occurredAt: decidedAt ?? requestedAt, recordedAt: decidedAt ?? requestedAt,
293
- summaryCode: `governance.timeline.${outcome}`, sourceRef: strongApprovalRef, lineageConfidence: 'strong',
294
- });
295
- }
257
+ if (task.status === 'failed' || task.status === 'needs_human_review') {
258
+ const code = task.status === 'failed' ? 'failed' : 'human_review';
259
+ timelineEvents.push({
260
+ code, occurredAt: task.updatedAt, recordedAt: task.updatedAt,
261
+ summaryCode: `governance.timeline.${code}`, sourceRef: fact.sourceRef, lineageConfidence: taskLineageConfidence,
262
+ });
296
263
  }
297
- for (const row of db.prepare('SELECT * FROM activations ORDER BY activated_at ASC, activation_id ASC').all()) {
298
- if (!isRecord(row))
299
- continue;
300
- const artifactId = readOwnString(row, 'artifact_id');
301
- if (artifactId === undefined || !strongArtifactIds.has(artifactId))
302
- continue;
303
- const activationId = readOwnString(row, 'activation_id');
304
- const channel = readOwnString(row, 'channel');
305
- const activatedAt = readOwnString(row, 'activated_at');
306
- const deactivatedAt = readOwnString(row, 'deactivated_at');
307
- const activationRef = activationId === undefined ? undefined : { type: 'activation', id: activationId };
308
- if (activationId === undefined || !isGovernanceChannel(channel) || !isTimestamp(activatedAt)
309
- || (deactivatedAt !== undefined && !isTimestamp(deactivatedAt))) {
310
- collectionIssues.push(issue(activationRef === undefined
311
- ? { source: 'activation', reasonCode: 'metadata_malformed', nextActionCode: 'repair_activation_record' }
312
- : { source: 'activation', reasonCode: 'metadata_malformed', nextActionCode: 'repair_activation_record', sourceRef: activationRef }));
264
+ }
265
+ tasks.sort((left, right) => (left.taskId ?? '').localeCompare(right.taskId ?? ''));
266
+ const strongTaskIds = new Set(tasks.filter(task => task.lineageConfidence === 'strong').map(task => task.taskId).filter((taskId) => taskId !== undefined));
267
+ for (const task of tasks) {
268
+ const { taskId } = task;
269
+ if (taskId === undefined || task.completionIntent?.status !== 'pending' || materializedRevisionSources.has(taskId))
270
+ continue;
271
+ derivedRelations.push({
272
+ schemaVersion: '1', family: 'derived_relation', sourceRef: task.sourceRef, principleId,
273
+ taskId, lineageConfidence: 'strong', recordedAt: task.recordedAt,
274
+ relation: 'revision_pending', evidenceRefs: [task.sourceRef],
275
+ });
276
+ }
277
+ for (const successor of [...validTasks.values()].sort((left, right) => left.taskId.localeCompare(right.taskId))) {
278
+ if (!strongTaskIds.has(successor.taskId))
279
+ continue;
280
+ for (const dependencyTaskId of [...successor.dependencyTaskIds].sort()) {
281
+ if (!strongTaskIds.has(dependencyTaskId))
313
282
  continue;
314
- }
315
- const strongActivationRef = { type: 'activation', id: activationId };
316
- const fact = {
317
- schemaVersion: '1', family: 'activation', sourceRef: strongActivationRef, principleId, artifactId,
318
- activationId, channel, outcome: deactivatedAt === undefined ? 'active' : 'deactivated',
319
- activatedAt, lineageConfidence: 'strong', recordedAt: deactivatedAt ?? activatedAt,
320
- };
321
- if (deactivatedAt !== undefined)
322
- fact.deactivatedAt = deactivatedAt;
323
- activations.push(fact);
324
- sourceRefs.push(strongActivationRef);
325
- timelineEvents.push({ code: 'activated', occurredAt: activatedAt, recordedAt: activatedAt, summaryCode: 'governance.timeline.activated', sourceRef: strongActivationRef, lineageConfidence: 'strong' });
326
- if (deactivatedAt !== undefined) {
327
- timelineEvents.push({ code: 'deactivated', occurredAt: deactivatedAt, recordedAt: deactivatedAt, summaryCode: 'governance.timeline.deactivated', sourceRef: strongActivationRef, lineageConfidence: 'strong' });
328
- }
283
+ derivedRelations.push({
284
+ schemaVersion: '1', family: 'derived_relation', sourceRef: { type: 'task', id: dependencyTaskId }, principleId,
285
+ taskId: dependencyTaskId, lineageConfidence: 'strong', recordedAt: successor.updatedAt,
286
+ relation: 'successor_present',
287
+ evidenceRefs: [{ type: 'task', id: dependencyTaskId }, { type: 'task', id: successor.taskId }],
288
+ });
329
289
  }
330
- timelineEvents.sort((left, right) => {
331
- const timeOrder = (left.occurredAt ?? left.recordedAt).localeCompare(right.occurredAt ?? right.recordedAt);
332
- if (timeOrder !== 0)
333
- return timeOrder;
334
- const typeOrder = left.sourceRef.type.localeCompare(right.sourceRef.type);
335
- if (typeOrder !== 0)
336
- return typeOrder;
337
- const idOrder = left.sourceRef.id.localeCompare(right.sourceRef.id);
338
- return idOrder !== 0 ? idOrder : left.code.localeCompare(right.code);
339
- });
340
- return GovernanceProjectionCollector.finish({
341
- principleId, asOf, principle, collectionIssues, artifactIds,
342
- taskIds: tasks.map(task => task.taskId).filter((taskId) => taskId !== undefined).sort(), tasks, revisionIdentities, sourceRefs,
343
- runnerVerdicts, derivedRelations, approvals, activations, timelineEvents,
344
- });
345
290
  }
346
- catch (error) {
347
- if (error instanceof GovernanceProjectionCollectionError)
348
- throw error;
349
- throw new GovernanceProjectionCollectionError('governance_projection_error', 'inspect_runtime_state');
291
+ const approvals = [];
292
+ const activations = [];
293
+ for (const row of tables.approvalRows) {
294
+ if (!isRecord(row))
295
+ continue;
296
+ const artifactId = readOwnString(row, 'artifact_id');
297
+ if (artifactId === undefined || !strongArtifactIds.has(artifactId))
298
+ continue;
299
+ const approvalId = readOwnString(row, 'approval_id');
300
+ const channel = readOwnString(row, 'channel');
301
+ const outcome = readOwnString(row, 'status');
302
+ const requestedAt = readOwnString(row, 'requested_at');
303
+ const decidedAt = readOwnString(row, 'decided_at');
304
+ const approvalRef = approvalId === undefined ? undefined : { type: 'approval', id: approvalId };
305
+ if (approvalId === undefined || !isGovernanceChannel(channel) || !isTimestamp(requestedAt)
306
+ || (outcome !== 'pending' && outcome !== 'approved' && outcome !== 'rejected' && outcome !== 'cancelled')
307
+ || (decidedAt !== undefined && !isTimestamp(decidedAt))) {
308
+ collectionIssues.push(issue(approvalRef === undefined
309
+ ? { source: 'approval', reasonCode: 'metadata_malformed', nextActionCode: 'repair_approval_record' }
310
+ : { source: 'approval', reasonCode: 'metadata_malformed', nextActionCode: 'repair_approval_record', sourceRef: approvalRef }));
311
+ continue;
312
+ }
313
+ const strongApprovalRef = { type: 'approval', id: approvalId };
314
+ const fact = {
315
+ schemaVersion: '1', family: 'approval', sourceRef: strongApprovalRef, principleId, artifactId,
316
+ approvalId, channel, outcome, lineageConfidence: 'strong', recordedAt: decidedAt ?? requestedAt,
317
+ };
318
+ if (decidedAt !== undefined)
319
+ fact.occurredAt = decidedAt;
320
+ approvals.push(fact);
321
+ sourceRefs.push(strongApprovalRef);
322
+ if (outcome === 'approved' || outcome === 'rejected') {
323
+ timelineEvents.push({
324
+ code: outcome, occurredAt: decidedAt ?? requestedAt, recordedAt: decidedAt ?? requestedAt,
325
+ summaryCode: `governance.timeline.${outcome}`, sourceRef: strongApprovalRef, lineageConfidence: 'strong',
326
+ });
327
+ }
350
328
  }
351
- finally {
352
- connection.close();
329
+ for (const row of tables.activationRows) {
330
+ if (!isRecord(row))
331
+ continue;
332
+ const artifactId = readOwnString(row, 'artifact_id');
333
+ if (artifactId === undefined || !strongArtifactIds.has(artifactId))
334
+ continue;
335
+ const activationId = readOwnString(row, 'activation_id');
336
+ const channel = readOwnString(row, 'channel');
337
+ const activatedAt = readOwnString(row, 'activated_at');
338
+ const deactivatedAt = readOwnString(row, 'deactivated_at');
339
+ const activationRef = activationId === undefined ? undefined : { type: 'activation', id: activationId };
340
+ if (activationId === undefined || !isGovernanceChannel(channel) || !isTimestamp(activatedAt)
341
+ || (deactivatedAt !== undefined && !isTimestamp(deactivatedAt))) {
342
+ collectionIssues.push(issue(activationRef === undefined
343
+ ? { source: 'activation', reasonCode: 'metadata_malformed', nextActionCode: 'repair_activation_record' }
344
+ : { source: 'activation', reasonCode: 'metadata_malformed', nextActionCode: 'repair_activation_record', sourceRef: activationRef }));
345
+ continue;
346
+ }
347
+ const strongActivationRef = { type: 'activation', id: activationId };
348
+ const fact = {
349
+ schemaVersion: '1', family: 'activation', sourceRef: strongActivationRef, principleId, artifactId,
350
+ activationId, channel, outcome: deactivatedAt === undefined ? 'active' : 'deactivated',
351
+ activatedAt, lineageConfidence: 'strong', recordedAt: deactivatedAt ?? activatedAt,
352
+ };
353
+ if (deactivatedAt !== undefined)
354
+ fact.deactivatedAt = deactivatedAt;
355
+ activations.push(fact);
356
+ sourceRefs.push(strongActivationRef);
357
+ timelineEvents.push({ code: 'activated', occurredAt: activatedAt, recordedAt: activatedAt, summaryCode: 'governance.timeline.activated', sourceRef: strongActivationRef, lineageConfidence: 'strong' });
358
+ if (deactivatedAt !== undefined) {
359
+ timelineEvents.push({ code: 'deactivated', occurredAt: deactivatedAt, recordedAt: deactivatedAt, summaryCode: 'governance.timeline.deactivated', sourceRef: strongActivationRef, lineageConfidence: 'strong' });
360
+ }
353
361
  }
362
+ timelineEvents.sort((left, right) => {
363
+ const timeOrder = (left.occurredAt ?? left.recordedAt).localeCompare(right.occurredAt ?? right.recordedAt);
364
+ if (timeOrder !== 0)
365
+ return timeOrder;
366
+ const typeOrder = left.sourceRef.type.localeCompare(right.sourceRef.type);
367
+ if (typeOrder !== 0)
368
+ return typeOrder;
369
+ const idOrder = left.sourceRef.id.localeCompare(right.sourceRef.id);
370
+ return idOrder !== 0 ? idOrder : left.code.localeCompare(right.code);
371
+ });
372
+ return GovernanceProjectionCollector.finish({
373
+ principleId, asOf, principle, collectionIssues, artifactIds,
374
+ taskIds: tasks.map(task => task.taskId).filter((taskId) => taskId !== undefined).sort(), tasks, revisionIdentities, sourceRefs,
375
+ runnerVerdicts, derivedRelations, approvals, activations, timelineEvents,
376
+ });
354
377
  }
355
378
  readPrinciple(principleId, issues) {
356
- const ledgerPath = path.join(this.workspaceDir, '.state', 'principle_training_state.json');
357
- let parsed;
379
+ return GovernanceProjectionCollector.principleFactFromLedger(GovernanceProjectionCollector.parsePrincipleLedgerFile(this.workspaceDir), principleId, issues);
380
+ }
381
+ /** Reads and JSON-parses the principle ledger file (shared by single + batch collectors). */
382
+ static parsePrincipleLedgerFile(workspaceDir) {
383
+ const ledgerPath = path.join(workspaceDir, '.state', 'principle_training_state.json');
358
384
  try {
359
- parsed = JSON.parse(fs.readFileSync(ledgerPath, 'utf8'));
385
+ return JSON.parse(fs.readFileSync(ledgerPath, 'utf8'));
360
386
  }
361
387
  catch {
362
388
  throw new GovernanceProjectionCollectionError('principle_not_found', 'check_principle_ledger');
363
389
  }
390
+ }
391
+ /** Extracts the principles record from a parsed ledger; null when the tree is absent/malformed. */
392
+ static principleTreeFromLedger(parsed) {
364
393
  if (!isRecord(parsed))
365
- throw new GovernanceProjectionCollectionError('principle_not_found', 'check_principle_ledger');
394
+ return null;
366
395
  const tree = Object.hasOwn(parsed, '_tree') ? parsed._tree : parsed.tree;
367
- if (!isRecord(tree) || !isRecord(tree.principles) || !Object.hasOwn(tree.principles, principleId)) {
396
+ if (!isRecord(tree) || !isRecord(tree.principles))
397
+ return null;
398
+ return tree.principles;
399
+ }
400
+ /** Validates one principle entry from an already-parsed ledger (shared by single + batch collectors). */
401
+ static principleFactFromLedger(parsed, principleId, issues) {
402
+ if (!isRecord(parsed))
403
+ throw new GovernanceProjectionCollectionError('principle_not_found', 'check_principle_ledger');
404
+ const principles = GovernanceProjectionCollector.principleTreeFromLedger(parsed);
405
+ if (principles === null || !Object.hasOwn(principles, principleId)) {
368
406
  throw new GovernanceProjectionCollectionError('principle_not_found', 'check_principle_id');
369
407
  }
370
- const raw = tree.principles[principleId];
408
+ const raw = principles[principleId];
371
409
  if (!isRecord(raw))
372
410
  throw new GovernanceProjectionCollectionError('principle_not_found', 'repair_principle_ledger');
373
411
  const state = readOwnString(raw, 'status');
@@ -428,7 +466,7 @@ export class GovernanceProjectionCollector {
428
466
  }
429
467
  if (taskKind !== 'dreamer' && taskKind !== 'philosopher' && taskKind !== 'scribe' && taskKind !== 'artificer' && taskKind !== 'evaluator' && taskKind !== 'rollout_reviewer')
430
468
  return null;
431
- if (status !== 'pending' && status !== 'leased' && status !== 'succeeded' && status !== 'retry_wait' && status !== 'failed' && status !== 'needs_human_review')
469
+ if (!isPDTaskStatus(status))
432
470
  return null;
433
471
  const result = { taskId, taskKind, status, createdAt, updatedAt, attemptCount, maxAttempts, channel, dependencyTaskIds: metadata.dependencyTaskIds };
434
472
  const leaseExpiresAt = readOwnString(row, 'lease_expires_at');