create-principles-disciple 1.101.0 → 1.103.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (317) hide show
  1. package/console/dist/server/config/pd-config-store.d.ts +50 -1
  2. package/console/dist/server/config/pd-config-store.js +364 -1
  3. package/console/dist/server/index.js +9 -0
  4. package/console/dist/server/models/ActivationsConsoleModel.d.ts +44 -5
  5. package/console/dist/server/models/ActivationsConsoleModel.js +118 -16
  6. package/console/dist/server/routes/config.js +92 -2
  7. package/console/dist/server/routes/onboarding.d.ts +34 -0
  8. package/console/dist/server/routes/onboarding.js +324 -0
  9. package/console/dist/ui/App.js +74 -15
  10. package/console/dist/ui/api.d.ts +60 -3
  11. package/console/dist/ui/api.js +63 -2
  12. package/console/dist/ui/components/onboarding/CircuitDiagram.d.ts +8 -0
  13. package/console/dist/ui/components/onboarding/CircuitDiagram.js +18 -0
  14. package/console/dist/ui/components/onboarding/DemoResultView.d.ts +22 -0
  15. package/console/dist/ui/components/onboarding/DemoResultView.js +33 -0
  16. package/console/dist/ui/i18n/en.json +189 -1
  17. package/console/dist/ui/i18n/zh-CN.json +189 -1
  18. package/console/dist/ui/pages/activation/ActivationPage.js +11 -11
  19. package/console/dist/ui/pages/activation/ActivationValidators.js +15 -14
  20. package/console/dist/ui/pages/control-center/AgentCard.js +66 -10
  21. package/console/dist/ui/pages/control-center/ControlCenterPage.js +3 -2
  22. package/console/dist/ui/pages/control-center/RuntimeProfileManager.d.ts +31 -0
  23. package/console/dist/ui/pages/control-center/RuntimeProfileManager.js +234 -0
  24. package/console/dist/ui/pages/debt/DebtPage.js +2 -2
  25. package/console/dist/ui/pages/settings/SettingsPage.js +64 -5
  26. package/console/dist/ui/pages/signal-keywords/KeywordEditDialog.d.ts +12 -0
  27. package/console/dist/ui/pages/signal-keywords/KeywordEditDialog.js +41 -0
  28. package/console/dist/ui/pages/signal-keywords/KeywordListSection.d.ts +10 -0
  29. package/console/dist/ui/pages/signal-keywords/KeywordListSection.js +39 -0
  30. package/console/dist/ui/pages/signal-keywords/PendingTermsSection.d.ts +14 -0
  31. package/console/dist/ui/pages/signal-keywords/PendingTermsSection.js +35 -0
  32. package/console/dist/ui/pages/signal-keywords/SignalKeywordsPage.d.ts +1 -0
  33. package/console/dist/ui/pages/signal-keywords/SignalKeywordsPage.js +49 -0
  34. package/console/dist/ui/pages/welcome/WelcomePage.d.ts +5 -0
  35. package/console/dist/ui/pages/welcome/WelcomePage.js +185 -0
  36. package/console/dist/ui/utils/__tests__/onboarding-state.test.d.ts +1 -0
  37. package/console/dist/ui/utils/__tests__/onboarding-state.test.js +72 -0
  38. package/console/dist/ui/utils/agent-metadata.d.ts +13 -0
  39. package/console/dist/ui/utils/agent-metadata.js +26 -0
  40. package/console/dist/ui/utils/onboarding-state.d.ts +25 -0
  41. package/console/dist/ui/utils/onboarding-state.js +77 -0
  42. package/console/dist/ui/utils/signal-keywords-api.d.ts +68 -0
  43. package/console/dist/ui/utils/signal-keywords-api.js +121 -0
  44. package/console/dist/ui/utils/signal-keywords-types.d.ts +57 -0
  45. package/console/dist/ui/utils/signal-keywords-types.js +10 -0
  46. package/console/dist/ui/utils/signal-keywords-validators.d.ts +20 -0
  47. package/console/dist/ui/utils/signal-keywords-validators.js +114 -0
  48. package/console/dist/ui/utils/validators.d.ts +26 -3
  49. package/console/dist/ui/utils/validators.js +23 -6
  50. package/console/dist/web/assets/app.css +442 -0
  51. package/console/dist/web/assets/app.js +7793 -1966
  52. package/core/dist/index.d.ts +2 -0
  53. package/core/dist/index.d.ts.map +1 -1
  54. package/core/dist/index.js +1 -0
  55. package/core/dist/index.js.map +1 -1
  56. package/core/dist/runtime-v2/__tests__/architecture-regression.test.js +14 -2
  57. package/core/dist/runtime-v2/__tests__/architecture-regression.test.js.map +1 -1
  58. package/core/dist/runtime-v2/__tests__/evaluator-runner-vslice-v2.test.js +28 -0
  59. package/core/dist/runtime-v2/__tests__/evaluator-runner-vslice-v2.test.js.map +1 -1
  60. package/core/dist/runtime-v2/__tests__/pain-to-principle-service.test.js +8 -0
  61. package/core/dist/runtime-v2/__tests__/pain-to-principle-service.test.js.map +1 -1
  62. package/core/dist/runtime-v2/__tests__/resolve-runtime-config-from-pd-config.test.js +8 -10
  63. package/core/dist/runtime-v2/__tests__/resolve-runtime-config-from-pd-config.test.js.map +1 -1
  64. package/core/dist/runtime-v2/activation/index.d.ts +1 -1
  65. package/core/dist/runtime-v2/activation/index.d.ts.map +1 -1
  66. package/core/dist/runtime-v2/activation/index.js +1 -1
  67. package/core/dist/runtime-v2/activation/index.js.map +1 -1
  68. package/core/dist/runtime-v2/activation/writers/__tests__/rule-host-writer.test.js +240 -1
  69. package/core/dist/runtime-v2/activation/writers/__tests__/rule-host-writer.test.js.map +1 -1
  70. package/core/dist/runtime-v2/activation/writers/rule-host-writer.d.ts +12 -0
  71. package/core/dist/runtime-v2/activation/writers/rule-host-writer.d.ts.map +1 -1
  72. package/core/dist/runtime-v2/activation/writers/rule-host-writer.js +81 -1
  73. package/core/dist/runtime-v2/activation/writers/rule-host-writer.js.map +1 -1
  74. package/core/dist/runtime-v2/adapter/__tests__/l2-resolve-model-compat.test.d.ts +2 -0
  75. package/core/dist/runtime-v2/adapter/__tests__/l2-resolve-model-compat.test.d.ts.map +1 -0
  76. package/core/dist/runtime-v2/adapter/__tests__/l2-resolve-model-compat.test.js +81 -0
  77. package/core/dist/runtime-v2/adapter/__tests__/l2-resolve-model-compat.test.js.map +1 -0
  78. package/core/dist/runtime-v2/adapter/__tests__/pi-ai-runtime-adapter.test.js +19 -0
  79. package/core/dist/runtime-v2/adapter/__tests__/pi-ai-runtime-adapter.test.js.map +1 -1
  80. package/core/dist/runtime-v2/adapter/pi-ai-runtime-adapter.d.ts +8 -0
  81. package/core/dist/runtime-v2/adapter/pi-ai-runtime-adapter.d.ts.map +1 -1
  82. package/core/dist/runtime-v2/adapter/pi-ai-runtime-adapter.js +4 -1
  83. package/core/dist/runtime-v2/adapter/pi-ai-runtime-adapter.js.map +1 -1
  84. package/core/dist/runtime-v2/candidate-intake-service.d.ts.map +1 -1
  85. package/core/dist/runtime-v2/candidate-intake-service.js +92 -6
  86. package/core/dist/runtime-v2/candidate-intake-service.js.map +1 -1
  87. package/core/dist/runtime-v2/candidate-intake.d.ts +38 -0
  88. package/core/dist/runtime-v2/candidate-intake.d.ts.map +1 -1
  89. package/core/dist/runtime-v2/candidate-intake.js +48 -0
  90. package/core/dist/runtime-v2/candidate-intake.js.map +1 -1
  91. package/core/dist/runtime-v2/config/__tests__/internal-agent-names.test.d.ts +2 -0
  92. package/core/dist/runtime-v2/config/__tests__/internal-agent-names.test.d.ts.map +1 -0
  93. package/core/dist/runtime-v2/config/__tests__/internal-agent-names.test.js +15 -0
  94. package/core/dist/runtime-v2/config/__tests__/internal-agent-names.test.js.map +1 -0
  95. package/core/dist/runtime-v2/config/__tests__/pd-config-agent-binding.test.js +33 -1
  96. package/core/dist/runtime-v2/config/__tests__/pd-config-agent-binding.test.js.map +1 -1
  97. package/core/dist/runtime-v2/config/__tests__/pd-config-contract.test.js +10 -5
  98. package/core/dist/runtime-v2/config/__tests__/pd-config-contract.test.js.map +1 -1
  99. package/core/dist/runtime-v2/config/__tests__/pd-config-redaction-deep.test.js +1 -0
  100. package/core/dist/runtime-v2/config/__tests__/pd-config-redaction-deep.test.js.map +1 -1
  101. package/core/dist/runtime-v2/config/__tests__/pd-config-validation-edge-cases.test.js +54 -33
  102. package/core/dist/runtime-v2/config/__tests__/pd-config-validation-edge-cases.test.js.map +1 -1
  103. package/core/dist/runtime-v2/config/index.d.ts +5 -3
  104. package/core/dist/runtime-v2/config/index.d.ts.map +1 -1
  105. package/core/dist/runtime-v2/config/index.js +8 -2
  106. package/core/dist/runtime-v2/config/index.js.map +1 -1
  107. package/core/dist/runtime-v2/config/pd-config-agent-binding.d.ts +2 -0
  108. package/core/dist/runtime-v2/config/pd-config-agent-binding.d.ts.map +1 -1
  109. package/core/dist/runtime-v2/config/pd-config-agent-binding.js +3 -0
  110. package/core/dist/runtime-v2/config/pd-config-agent-binding.js.map +1 -1
  111. package/core/dist/runtime-v2/config/pd-config-defaults.d.ts +8 -3
  112. package/core/dist/runtime-v2/config/pd-config-defaults.d.ts.map +1 -1
  113. package/core/dist/runtime-v2/config/pd-config-defaults.js +39 -3
  114. package/core/dist/runtime-v2/config/pd-config-defaults.js.map +1 -1
  115. package/core/dist/runtime-v2/config/pd-config-effective.d.ts.map +1 -1
  116. package/core/dist/runtime-v2/config/pd-config-effective.js +25 -1
  117. package/core/dist/runtime-v2/config/pd-config-effective.js.map +1 -1
  118. package/core/dist/runtime-v2/config/pd-config-redaction.d.ts.map +1 -1
  119. package/core/dist/runtime-v2/config/pd-config-redaction.js +14 -2
  120. package/core/dist/runtime-v2/config/pd-config-redaction.js.map +1 -1
  121. package/core/dist/runtime-v2/config/pd-config-types.d.ts +116 -1
  122. package/core/dist/runtime-v2/config/pd-config-types.d.ts.map +1 -1
  123. package/core/dist/runtime-v2/config/pd-config-types.js +7 -0
  124. package/core/dist/runtime-v2/config/pd-config-types.js.map +1 -1
  125. package/core/dist/runtime-v2/config/pd-config-validate.d.ts.map +1 -1
  126. package/core/dist/runtime-v2/config/pd-config-validate.js +125 -7
  127. package/core/dist/runtime-v2/config/pd-config-validate.js.map +1 -1
  128. package/core/dist/runtime-v2/config/pd-profile-constants.d.ts +27 -0
  129. package/core/dist/runtime-v2/config/pd-profile-constants.d.ts.map +1 -0
  130. package/core/dist/runtime-v2/config/pd-profile-constants.js +145 -0
  131. package/core/dist/runtime-v2/config/pd-profile-constants.js.map +1 -0
  132. package/core/dist/runtime-v2/config/pd-validate-profile.d.ts +28 -0
  133. package/core/dist/runtime-v2/config/pd-validate-profile.d.ts.map +1 -0
  134. package/core/dist/runtime-v2/config/pd-validate-profile.js +482 -0
  135. package/core/dist/runtime-v2/config/pd-validate-profile.js.map +1 -0
  136. package/core/dist/runtime-v2/feature-flags/__tests__/feature-flag-contract.test.js +26 -0
  137. package/core/dist/runtime-v2/feature-flags/__tests__/feature-flag-contract.test.js.map +1 -1
  138. package/core/dist/runtime-v2/feature-flags/feature-flag-contract.d.ts.map +1 -1
  139. package/core/dist/runtime-v2/feature-flags/feature-flag-contract.js +8 -0
  140. package/core/dist/runtime-v2/feature-flags/feature-flag-contract.js.map +1 -1
  141. package/core/dist/runtime-v2/index.d.ts +7 -4
  142. package/core/dist/runtime-v2/index.d.ts.map +1 -1
  143. package/core/dist/runtime-v2/index.js +5 -2
  144. package/core/dist/runtime-v2/index.js.map +1 -1
  145. package/core/dist/runtime-v2/internalization/__tests__/artificer-prompt-builder-v2.test.js +32 -0
  146. package/core/dist/runtime-v2/internalization/__tests__/artificer-prompt-builder-v2.test.js.map +1 -1
  147. package/core/dist/runtime-v2/internalization/__tests__/artificer-rule-output.test.js +139 -0
  148. package/core/dist/runtime-v2/internalization/__tests__/artificer-rule-output.test.js.map +1 -1
  149. package/core/dist/runtime-v2/internalization/__tests__/diag-chain-e2e.test.js +20 -1
  150. package/core/dist/runtime-v2/internalization/__tests__/diag-chain-e2e.test.js.map +1 -1
  151. package/core/dist/runtime-v2/internalization/__tests__/diag-rootcause-intent-tension.test.js +7 -0
  152. package/core/dist/runtime-v2/internalization/__tests__/diag-rootcause-intent-tension.test.js.map +1 -1
  153. package/core/dist/runtime-v2/internalization/__tests__/diag-rootcause-runner.test.js +7 -6
  154. package/core/dist/runtime-v2/internalization/__tests__/diag-rootcause-runner.test.js.map +1 -1
  155. package/core/dist/runtime-v2/internalization/__tests__/internalization-task-guards.test.js +1 -53
  156. package/core/dist/runtime-v2/internalization/__tests__/internalization-task-guards.test.js.map +1 -1
  157. package/core/dist/runtime-v2/internalization/__tests__/rule-host-input-builder.test.js +23 -0
  158. package/core/dist/runtime-v2/internalization/__tests__/rule-host-input-builder.test.js.map +1 -1
  159. package/core/dist/runtime-v2/internalization/artificer-output.d.ts +7 -0
  160. package/core/dist/runtime-v2/internalization/artificer-output.d.ts.map +1 -1
  161. package/core/dist/runtime-v2/internalization/artificer-output.js +22 -1
  162. package/core/dist/runtime-v2/internalization/artificer-output.js.map +1 -1
  163. package/core/dist/runtime-v2/internalization/artificer-prompt-builder.d.ts.map +1 -1
  164. package/core/dist/runtime-v2/internalization/artificer-prompt-builder.js +2 -0
  165. package/core/dist/runtime-v2/internalization/artificer-prompt-builder.js.map +1 -1
  166. package/core/dist/runtime-v2/internalization/artificer-runner.d.ts.map +1 -1
  167. package/core/dist/runtime-v2/internalization/artificer-runner.js +13 -0
  168. package/core/dist/runtime-v2/internalization/artificer-runner.js.map +1 -1
  169. package/core/dist/runtime-v2/internalization/diag-distiller-runner.js +4 -4
  170. package/core/dist/runtime-v2/internalization/diag-distiller-runner.js.map +1 -1
  171. package/core/dist/runtime-v2/internalization/diag-rootcause-runner.js +5 -5
  172. package/core/dist/runtime-v2/internalization/diag-rootcause-runner.js.map +1 -1
  173. package/core/dist/runtime-v2/internalization/diag-router-runner.js +4 -4
  174. package/core/dist/runtime-v2/internalization/diag-router-runner.js.map +1 -1
  175. package/core/dist/runtime-v2/internalization/evaluator-runner.d.ts.map +1 -1
  176. package/core/dist/runtime-v2/internalization/evaluator-runner.js +7 -1
  177. package/core/dist/runtime-v2/internalization/evaluator-runner.js.map +1 -1
  178. package/core/dist/runtime-v2/internalization/index.d.ts +1 -1
  179. package/core/dist/runtime-v2/internalization/index.d.ts.map +1 -1
  180. package/core/dist/runtime-v2/internalization/index.js +1 -1
  181. package/core/dist/runtime-v2/internalization/index.js.map +1 -1
  182. package/core/dist/runtime-v2/internalization/internalization-task-guards.d.ts +0 -19
  183. package/core/dist/runtime-v2/internalization/internalization-task-guards.d.ts.map +1 -1
  184. package/core/dist/runtime-v2/internalization/internalization-task-guards.js +1 -29
  185. package/core/dist/runtime-v2/internalization/internalization-task-guards.js.map +1 -1
  186. package/core/dist/runtime-v2/pain-signal-runtime-factory.d.ts +2 -0
  187. package/core/dist/runtime-v2/pain-signal-runtime-factory.d.ts.map +1 -1
  188. package/core/dist/runtime-v2/pain-signal-runtime-factory.js +2 -0
  189. package/core/dist/runtime-v2/pain-signal-runtime-factory.js.map +1 -1
  190. package/core/dist/runtime-v2/signal-collector/__tests__/keyword-stage.test.d.ts +2 -0
  191. package/core/dist/runtime-v2/signal-collector/__tests__/keyword-stage.test.d.ts.map +1 -0
  192. package/core/dist/runtime-v2/signal-collector/__tests__/keyword-stage.test.js +39 -0
  193. package/core/dist/runtime-v2/signal-collector/__tests__/keyword-stage.test.js.map +1 -0
  194. package/core/dist/runtime-v2/signal-collector/__tests__/llm-stage.test.d.ts +2 -0
  195. package/core/dist/runtime-v2/signal-collector/__tests__/llm-stage.test.d.ts.map +1 -0
  196. package/core/dist/runtime-v2/signal-collector/__tests__/llm-stage.test.js +34 -0
  197. package/core/dist/runtime-v2/signal-collector/__tests__/llm-stage.test.js.map +1 -0
  198. package/core/dist/runtime-v2/signal-collector/__tests__/signal-collector.test.d.ts +2 -0
  199. package/core/dist/runtime-v2/signal-collector/__tests__/signal-collector.test.d.ts.map +1 -0
  200. package/core/dist/runtime-v2/signal-collector/__tests__/signal-collector.test.js +222 -0
  201. package/core/dist/runtime-v2/signal-collector/__tests__/signal-collector.test.js.map +1 -0
  202. package/core/dist/runtime-v2/signal-collector/__tests__/types.test.d.ts +2 -0
  203. package/core/dist/runtime-v2/signal-collector/__tests__/types.test.d.ts.map +1 -0
  204. package/core/dist/runtime-v2/signal-collector/__tests__/types.test.js +35 -0
  205. package/core/dist/runtime-v2/signal-collector/__tests__/types.test.js.map +1 -0
  206. package/core/dist/runtime-v2/signal-collector/index.d.ts +5 -0
  207. package/core/dist/runtime-v2/signal-collector/index.d.ts.map +1 -0
  208. package/core/dist/runtime-v2/signal-collector/index.js +5 -0
  209. package/core/dist/runtime-v2/signal-collector/index.js.map +1 -0
  210. package/core/dist/runtime-v2/signal-collector/keyword-stage.d.ts +20 -0
  211. package/core/dist/runtime-v2/signal-collector/keyword-stage.d.ts.map +1 -0
  212. package/core/dist/runtime-v2/signal-collector/keyword-stage.js +61 -0
  213. package/core/dist/runtime-v2/signal-collector/keyword-stage.js.map +1 -0
  214. package/core/dist/runtime-v2/signal-collector/llm-stage.d.ts +16 -0
  215. package/core/dist/runtime-v2/signal-collector/llm-stage.d.ts.map +1 -0
  216. package/core/dist/runtime-v2/signal-collector/llm-stage.js +34 -0
  217. package/core/dist/runtime-v2/signal-collector/llm-stage.js.map +1 -0
  218. package/core/dist/runtime-v2/signal-collector/signal-collector.d.ts +16 -0
  219. package/core/dist/runtime-v2/signal-collector/signal-collector.d.ts.map +1 -0
  220. package/core/dist/runtime-v2/signal-collector/signal-collector.js +71 -0
  221. package/core/dist/runtime-v2/signal-collector/signal-collector.js.map +1 -0
  222. package/core/dist/runtime-v2/signal-collector/types.d.ts +61 -0
  223. package/core/dist/runtime-v2/signal-collector/types.d.ts.map +1 -0
  224. package/core/dist/runtime-v2/signal-collector/types.js +45 -0
  225. package/core/dist/runtime-v2/signal-collector/types.js.map +1 -0
  226. package/core/dist/runtime-v2/store/schema-conformance.test.js +43 -0
  227. package/core/dist/runtime-v2/store/schema-conformance.test.js.map +1 -1
  228. package/core/dist/runtime-v2/types/event-types.d.ts +40 -3
  229. package/core/dist/runtime-v2/types/event-types.d.ts.map +1 -1
  230. package/core/dist/runtime-v2/types/event-types.js +9 -0
  231. package/core/dist/runtime-v2/types/event-types.js.map +1 -1
  232. package/core/dist/runtime-v2/types/index.d.ts +2 -2
  233. package/core/dist/runtime-v2/types/index.d.ts.map +1 -1
  234. package/core/dist/runtime-v2/types/index.js +1 -1
  235. package/core/dist/runtime-v2/types/index.js.map +1 -1
  236. package/core/dist/workflow-funnel-loader.js +1 -1
  237. package/core/dist/workflow-funnel-loader.js.map +1 -1
  238. package/dist/i18n.d.ts.map +1 -1
  239. package/dist/i18n.js +6 -0
  240. package/dist/i18n.js.map +1 -1
  241. package/dist/index.js +12 -3
  242. package/dist/index.js.map +1 -1
  243. package/dist/installer.d.ts +3 -0
  244. package/dist/installer.d.ts.map +1 -1
  245. package/dist/installer.js +150 -1
  246. package/dist/installer.js.map +1 -1
  247. package/dist/mvp-config.d.ts +8 -0
  248. package/dist/mvp-config.d.ts.map +1 -1
  249. package/dist/mvp-config.js +34 -12
  250. package/dist/mvp-config.js.map +1 -1
  251. package/package.json +1 -1
  252. package/pd-cli/dist/commands/__tests__/runtime-probe-config.test.js +2 -2
  253. package/pd-cli/dist/commands/__tests__/runtime-probe-config.test.js.map +1 -1
  254. package/pd-cli/dist/commands/demo-story-a.d.ts.map +1 -1
  255. package/pd-cli/dist/commands/demo-story-a.js +4 -2
  256. package/pd-cli/dist/commands/demo-story-a.js.map +1 -1
  257. package/pd-cli/dist/commands/proven-channel-baseline.d.ts.map +1 -1
  258. package/pd-cli/dist/commands/proven-channel-baseline.js +4 -2
  259. package/pd-cli/dist/commands/proven-channel-baseline.js.map +1 -1
  260. package/pd-cli/dist/commands/runtime-activation.d.ts +4 -0
  261. package/pd-cli/dist/commands/runtime-activation.d.ts.map +1 -1
  262. package/pd-cli/dist/commands/runtime-activation.js +187 -10
  263. package/pd-cli/dist/commands/runtime-activation.js.map +1 -1
  264. package/pd-cli/dist/commands/runtime-canary.d.ts.map +1 -1
  265. package/pd-cli/dist/commands/runtime-canary.js +4 -2
  266. package/pd-cli/dist/commands/runtime-canary.js.map +1 -1
  267. package/pd-cli/dist/commands/runtime-health-snapshot.d.ts.map +1 -1
  268. package/pd-cli/dist/commands/runtime-health-snapshot.js +4 -2
  269. package/pd-cli/dist/commands/runtime-health-snapshot.js.map +1 -1
  270. package/pd-cli/dist/commands/runtime-internalization-integrity.d.ts.map +1 -1
  271. package/pd-cli/dist/commands/runtime-internalization-integrity.js +4 -2
  272. package/pd-cli/dist/commands/runtime-internalization-integrity.js.map +1 -1
  273. package/pd-cli/dist/index.js +5 -63
  274. package/pd-cli/dist/index.js.map +1 -1
  275. package/pd-cli/dist/services/config-doctor.d.ts.map +1 -1
  276. package/pd-cli/dist/services/config-doctor.js +9 -2
  277. package/pd-cli/dist/services/config-doctor.js.map +1 -1
  278. package/pd-cli/dist/services/runtime-adapter-resolver.d.ts.map +1 -1
  279. package/pd-cli/dist/services/runtime-adapter-resolver.js +1 -0
  280. package/pd-cli/dist/services/runtime-adapter-resolver.js.map +1 -1
  281. package/plugin/dist/commands/context.js +17 -11
  282. package/plugin/dist/commands/samples.js +25 -0
  283. package/plugin/dist/core/event-log.d.ts +11 -1
  284. package/plugin/dist/core/event-log.js +13 -0
  285. package/plugin/dist/core/init.js +3 -4
  286. package/plugin/dist/core/rule-host.d.ts +50 -0
  287. package/plugin/dist/core/rule-host.js +116 -19
  288. package/plugin/dist/core/signal-collector-host.d.ts +105 -0
  289. package/plugin/dist/core/signal-collector-host.js +337 -0
  290. package/plugin/dist/hooks/gate.js +1 -1
  291. package/plugin/dist/hooks/prompt.d.ts +3 -2
  292. package/plugin/dist/hooks/prompt.js +48 -586
  293. package/plugin/dist/service/evolution-dedup.d.ts +1 -1
  294. package/plugin/dist/service/evolution-worker.d.ts +7 -31
  295. package/plugin/dist/service/evolution-worker.js +17 -36
  296. package/plugin/dist/service/queue-io.js +14 -2
  297. package/plugin/dist/service/queue-migration.d.ts +27 -26
  298. package/plugin/dist/service/queue-migration.js +57 -0
  299. package/plugin/dist/types/event-types.d.ts +1 -1
  300. package/plugin/dist/types.d.ts +5 -25
  301. package/plugin/dist/types.js +4 -9
  302. package/plugin/dist/utils/hashing.js +1 -1
  303. package/plugin/templates/langs/en/core/AGENTS.md +2 -2
  304. package/plugin/templates/langs/en/core/TOOLS.md +1 -1
  305. package/plugin/templates/langs/zh/core/AGENTS.md +2 -2
  306. package/plugin/templates/langs/zh/core/TOOLS.md +1 -1
  307. package/templates/langs/en/core/AGENTS.md +2 -2
  308. package/templates/langs/en/core/TOOLS.md +1 -1
  309. package/templates/langs/zh/core/AGENTS.md +2 -2
  310. package/templates/langs/zh/core/TOOLS.md +1 -1
  311. package/plugin/dist/constants/diagnostician.d.ts +0 -12
  312. package/plugin/dist/constants/diagnostician.js +0 -65
  313. package/plugin/dist/service/evolution-queue-migration.d.ts +0 -128
  314. package/plugin/dist/service/evolution-queue-migration.js +0 -53
  315. package/plugin/templates/langs/en/skills/pd-diagnostician/SKILL.md +0 -466
  316. package/plugin/templates/langs/zh/skills/pd-diagnostician/SKILL.md +0 -391
  317. package/templates/langs/zh/skills/pd-diagnostician/SKILL.md +0 -287
@@ -13,7 +13,7 @@
13
13
  * - ERR-013: Object.hasOwn() for untrusted keys
14
14
  * - ERR-045: ANY-segment redaction for sensitive keys
15
15
  */
16
- import type { EffectivePdConfig, RedactedPdConfigSummary, InternalAgentName, FeatureFlagsResult } from '@principles/core/runtime-v2';
16
+ import type { EffectivePdConfig, RedactedPdConfigSummary, InternalAgentName, RuntimeProfile, FeatureFlagsResult } from '@principles/core/runtime-v2';
17
17
  export interface ConfigLoadResultOk {
18
18
  ok: true;
19
19
  effective: EffectivePdConfig;
@@ -171,4 +171,53 @@ export type FeatureFlagUpdateResult = FeatureFlagUpdateResultOk | FeatureFlagUpd
171
171
  * - ERR-015/018/019: load-validate-merge-write-reload, no stale cache
172
172
  */
173
173
  export declare function updateFeatureFlag(workspaceDir: string, featureName: string, enabled: boolean): FeatureFlagUpdateResult;
174
+ export interface RuntimeProfileCrudResultOk {
175
+ ok: true;
176
+ profileId: string;
177
+ profile: RuntimeProfile;
178
+ }
179
+ export interface RuntimeProfileCrudResultErr {
180
+ ok: false;
181
+ statusCode: number;
182
+ error: string;
183
+ message: string;
184
+ nextAction?: string;
185
+ }
186
+ export type RuntimeProfileCrudResult = RuntimeProfileCrudResultOk | RuntimeProfileCrudResultErr;
187
+ /**
188
+ * Create a new runtime profile in .pd/config.yaml.
189
+ *
190
+ * - Rejects duplicate profile IDs (400 bad_request)
191
+ * - Validates profile structure (type + required fields via validatePdConfig)
192
+ * - Persists atomically, preserving unknown config sections
193
+ *
194
+ * ERR entries:
195
+ * - ERR-001/ERR-005: No `as` bypasses; payload validated as unknown
196
+ * - ERR-002: Graceful degradation includes reason + nextAction
197
+ * - ERR-009/ERR-010: Required fields fail loud
198
+ * - ERR-013: Object.hasOwn() for untrusted keys
199
+ */
200
+ export declare function createRuntimeProfile(workspaceDir: string, profileId: string, payload: unknown): RuntimeProfileCrudResult;
201
+ /**
202
+ * Update an existing runtime profile in .pd/config.yaml.
203
+ *
204
+ * - Rejects non-existent profile (404 not_found)
205
+ * - Rejects type changes (400 bad_request — type change = delete + create)
206
+ * - Merges patch into existing profile, only known fields are persisted
207
+ * - Persists atomically, preserving unknown config sections
208
+ *
209
+ * ERR entries: same as createRuntimeProfile.
210
+ */
211
+ export declare function updateRuntimeProfile(workspaceDir: string, profileId: string, patch: unknown): RuntimeProfileCrudResult;
212
+ /**
213
+ * Delete a runtime profile from .pd/config.yaml.
214
+ *
215
+ * - Rejects non-existent profile (404 not_found)
216
+ * - Rejects if profile is the defaultRuntime (400 bad_request)
217
+ * - Rejects if any agent binding references the profile (400 bad_request, lists agents)
218
+ * - Persists atomically, preserving unknown config sections
219
+ *
220
+ * ERR entries: same as createRuntimeProfile.
221
+ */
222
+ export declare function deleteRuntimeProfile(workspaceDir: string, profileId: string): RuntimeProfileCrudResult;
174
223
  export declare function checkReadiness(workspaceDir: string, agentName: string, getEnvVar?: (name: string) => string | undefined): ReadinessResult | ReadinessError;
@@ -16,7 +16,7 @@
16
16
  import * as fs from 'fs';
17
17
  import * as path from 'path';
18
18
  import yaml from 'js-yaml';
19
- import { validatePdConfig, computeEffectivePdConfig, computeFeatureFlagsFromConfig, redactPdConfig, checkAgentRuntimeReadiness, resolveAgentRuntimeBinding, INTERNAL_AGENT_NAMES, } from '@principles/core/runtime-v2';
19
+ import { validatePdConfig, computeEffectivePdConfig, computeFeatureFlagsFromConfig, redactPdConfig, checkAgentRuntimeReadiness, resolveAgentRuntimeBinding, INTERNAL_AGENT_NAMES, VALID_PROFILE_TYPES, } from '@principles/core/runtime-v2';
20
20
  // ── Constants ────────────────────────────────────────────────────────────────
21
21
  const PD_CONFIG_DIR = '.pd';
22
22
  const PD_CONFIG_FILENAME = 'config.yaml';
@@ -802,6 +802,369 @@ export function updateFeatureFlag(workspaceDir, featureName, enabled) {
802
802
  enabled: confirmedEnabled,
803
803
  };
804
804
  }
805
+ /**
806
+ * Validate the basic structure of a runtime profile payload (type field).
807
+ * Full field validation is delegated to validatePdConfig after merge.
808
+ * Uses Object.hasOwn() for untrusted key checks (ERR-013).
809
+ */
810
+ function validateProfileStructure(payload) {
811
+ if (!isRecord(payload)) {
812
+ return { ok: false, error: 'bad_request', message: 'Profile must be a JSON object with a type field' };
813
+ }
814
+ const typeRaw = Object.hasOwn(payload, 'type') ? payload.type : undefined;
815
+ if (typeRaw === undefined) {
816
+ return { ok: false, error: 'bad_request', message: `Profile missing required field: type (must be one of: ${VALID_PROFILE_TYPES.join(', ')})` };
817
+ }
818
+ if (typeof typeRaw !== 'string' || !VALID_PROFILE_TYPES.includes(typeRaw)) {
819
+ return { ok: false, error: 'bad_request', message: `Profile type must be one of: ${VALID_PROFILE_TYPES.join(', ')}. Got: ${String(typeRaw)}` };
820
+ }
821
+ return { ok: true, type: typeRaw };
822
+ }
823
+ /**
824
+ * Extract only known, correctly-typed fields from a profile payload.
825
+ * Prevents unknown fields from being persisted to .pd/config.yaml.
826
+ * Uses Object.hasOwn() for untrusted key checks (ERR-013).
827
+ */
828
+ function extractProfileFields(payload, type) {
829
+ const result = { type };
830
+ if (Object.hasOwn(payload, 'provider') && typeof payload.provider === 'string') {
831
+ result.provider = payload.provider;
832
+ }
833
+ if (Object.hasOwn(payload, 'model') && typeof payload.model === 'string') {
834
+ result.model = payload.model;
835
+ }
836
+ if (type === 'openclaw') {
837
+ if (Object.hasOwn(payload, 'source') && typeof payload.source === 'string') {
838
+ result.source = payload.source;
839
+ }
840
+ }
841
+ else {
842
+ // pi-ai
843
+ if (Object.hasOwn(payload, 'apiKeyEnv') && typeof payload.apiKeyEnv === 'string') {
844
+ result.apiKeyEnv = payload.apiKeyEnv;
845
+ }
846
+ if (Object.hasOwn(payload, 'baseUrl') && typeof payload.baseUrl === 'string') {
847
+ result.baseUrl = payload.baseUrl;
848
+ }
849
+ if (Object.hasOwn(payload, 'timeoutMs') && typeof payload.timeoutMs === 'number') {
850
+ result.timeoutMs = payload.timeoutMs;
851
+ }
852
+ if (Object.hasOwn(payload, 'maxRetries') && typeof payload.maxRetries === 'number') {
853
+ result.maxRetries = payload.maxRetries;
854
+ }
855
+ }
856
+ return result;
857
+ }
858
+ /**
859
+ * Read raw config file preserving unknown root sections.
860
+ * Returns an empty record if the file does not exist.
861
+ * Treats parsed YAML as unknown (ERR-001).
862
+ */
863
+ function readRawConfig(configPath) {
864
+ if (!fs.existsSync(configPath)) {
865
+ return {};
866
+ }
867
+ const rawContent = fs.readFileSync(configPath, 'utf8');
868
+ const rawParsed = yaml.load(rawContent, { schema: yaml.JSON_SCHEMA });
869
+ if (isRecord(rawParsed)) {
870
+ return { ...rawParsed };
871
+ }
872
+ return {};
873
+ }
874
+ /**
875
+ * Create a new runtime profile in .pd/config.yaml.
876
+ *
877
+ * - Rejects duplicate profile IDs (400 bad_request)
878
+ * - Validates profile structure (type + required fields via validatePdConfig)
879
+ * - Persists atomically, preserving unknown config sections
880
+ *
881
+ * ERR entries:
882
+ * - ERR-001/ERR-005: No `as` bypasses; payload validated as unknown
883
+ * - ERR-002: Graceful degradation includes reason + nextAction
884
+ * - ERR-009/ERR-010: Required fields fail loud
885
+ * - ERR-013: Object.hasOwn() for untrusted keys
886
+ */
887
+ export function createRuntimeProfile(workspaceDir, profileId, payload) {
888
+ // 1. Validate profileId
889
+ if (typeof profileId !== 'string' || profileId.length === 0) {
890
+ return { ok: false, statusCode: 400, error: 'bad_request', message: 'profileId must be a non-empty string' };
891
+ }
892
+ // 2. Validate profile structure (type field)
893
+ const structResult = validateProfileStructure(payload);
894
+ if (!structResult.ok) {
895
+ return { ok: false, statusCode: 400, error: structResult.error, message: structResult.message };
896
+ }
897
+ // 3. Load existing config — refuse to write on malformed (rc-9)
898
+ const loadResult = loadPdConfig(workspaceDir);
899
+ if (!loadResult.ok) {
900
+ return {
901
+ ok: false,
902
+ statusCode: 409,
903
+ error: 'conflict',
904
+ message: `Cannot create runtime profile: existing .pd/config.yaml is malformed. Fix config errors first. Errors: ${loadResult.errors.map(e => e.reason).join('; ')}`,
905
+ };
906
+ }
907
+ const { effective } = loadResult;
908
+ // 4. Reject duplicate profile ID
909
+ if (Object.hasOwn(effective.config.runtimeProfiles, profileId)) {
910
+ return {
911
+ ok: false,
912
+ statusCode: 400,
913
+ error: 'bad_request',
914
+ message: `Runtime profile '${profileId}' already exists. Use PATCH to update it.`,
915
+ nextAction: `Use PATCH /api/v1/config/profiles/${encodeURIComponent(profileId)} to update the existing profile`,
916
+ };
917
+ }
918
+ // 5. Extract only known fields from payload (prevents unknown field persistence)
919
+ const profileRecord = extractProfileFields(payload, structResult.type);
920
+ // 6. Read raw config to preserve unknown sections, add new profile
921
+ const configPath = getPdConfigPath(workspaceDir);
922
+ const rawConfig = readRawConfig(configPath);
923
+ const profilesMap = isRecord(rawConfig.runtimeProfiles)
924
+ ? { ...rawConfig.runtimeProfiles }
925
+ : { ...effective.config.runtimeProfiles };
926
+ profilesMap[profileId] = profileRecord;
927
+ rawConfig.runtimeProfiles = profilesMap;
928
+ // 7. Validate the full updated config (catches missing required fields etc.)
929
+ const validation = validatePdConfig(rawConfig);
930
+ if (!validation.ok) {
931
+ return {
932
+ ok: false,
933
+ statusCode: 400,
934
+ error: 'bad_request',
935
+ message: `Profile validation failed: ${validation.errors.map(e => e.reason).join('; ')}`,
936
+ nextAction: 'Fix profile fields and retry',
937
+ };
938
+ }
939
+ // 8. Atomic write
940
+ try {
941
+ writeConfigAtomic(configPath, rawConfig);
942
+ }
943
+ catch (err) {
944
+ const message = err instanceof Error ? err.message : String(err);
945
+ return { ok: false, statusCode: 500, error: 'write_error', message: `Failed to write config: ${message}`, nextAction: 'Check disk space and file permissions for .pd/config.yaml' };
946
+ }
947
+ // 9. Return the validated profile from the config
948
+ // Defensive guard: Object.hasOwn() doesn't narrow TS type, so extract and verify.
949
+ const createdProfile = validation.value.runtimeProfiles[profileId];
950
+ if (!createdProfile) {
951
+ return { ok: false, statusCode: 500, error: 'internal_error',
952
+ message: `Profile '${profileId}' was written but could not be read back from config.`,
953
+ nextAction: 'This is a bug in PD config persistence. Please report it.' };
954
+ }
955
+ return {
956
+ ok: true,
957
+ profileId,
958
+ profile: createdProfile,
959
+ };
960
+ }
961
+ /**
962
+ * Update an existing runtime profile in .pd/config.yaml.
963
+ *
964
+ * - Rejects non-existent profile (404 not_found)
965
+ * - Rejects type changes (400 bad_request — type change = delete + create)
966
+ * - Merges patch into existing profile, only known fields are persisted
967
+ * - Persists atomically, preserving unknown config sections
968
+ *
969
+ * ERR entries: same as createRuntimeProfile.
970
+ */
971
+ export function updateRuntimeProfile(workspaceDir, profileId, patch) {
972
+ // 1. Validate profileId
973
+ if (typeof profileId !== 'string' || profileId.length === 0) {
974
+ return { ok: false, statusCode: 400, error: 'bad_request', message: 'profileId must be a non-empty string' };
975
+ }
976
+ // 2. Validate patch is a record
977
+ if (!isRecord(patch)) {
978
+ return { ok: false, statusCode: 400, error: 'bad_request', message: 'Patch payload must be a JSON object' };
979
+ }
980
+ // 3. Load existing config — refuse to write on malformed (rc-9)
981
+ const loadResult = loadPdConfig(workspaceDir);
982
+ if (!loadResult.ok) {
983
+ return {
984
+ ok: false,
985
+ statusCode: 409,
986
+ error: 'conflict',
987
+ message: `Cannot update runtime profile: existing .pd/config.yaml is malformed. Fix config errors first. Errors: ${loadResult.errors.map(e => e.reason).join('; ')}`,
988
+ };
989
+ }
990
+ const { effective } = loadResult;
991
+ // 4. Reject if profile doesn't exist (404)
992
+ if (!Object.hasOwn(effective.config.runtimeProfiles, profileId)) {
993
+ return {
994
+ ok: false,
995
+ statusCode: 404,
996
+ error: 'not_found',
997
+ message: `Runtime profile '${profileId}' does not exist. Available profiles: ${Object.keys(effective.config.runtimeProfiles).join(', ')}`,
998
+ nextAction: 'Use POST /api/v1/config/profiles to create a new profile',
999
+ };
1000
+ }
1001
+ const existingProfile = effective.config.runtimeProfiles[profileId];
1002
+ // Defensive guard: Object.hasOwn() above doesn't narrow TS type.
1003
+ if (!existingProfile) {
1004
+ return { ok: false, statusCode: 500, error: 'internal_error',
1005
+ message: `Profile '${profileId}' existence check passed but value is undefined.`,
1006
+ nextAction: 'This is a bug in PD config resolution. Please report it.' };
1007
+ }
1008
+ // 5. Reject type change (type change = delete + create)
1009
+ if (Object.hasOwn(patch, 'type')) {
1010
+ const patchType = patch.type;
1011
+ if (typeof patchType !== 'string' || patchType !== existingProfile.type) {
1012
+ return {
1013
+ ok: false,
1014
+ statusCode: 400,
1015
+ error: 'bad_request',
1016
+ message: `Cannot change profile type (existing: '${existingProfile.type}', requested: '${String(patchType)}'). Type change equals delete + create. Delete this profile and create a new one instead.`,
1017
+ nextAction: `DELETE /api/v1/config/profiles/${encodeURIComponent(profileId)} then POST /api/v1/config/profiles with the new type`,
1018
+ };
1019
+ }
1020
+ }
1021
+ // 6. Merge patch into existing profile, then extract only known fields
1022
+ const mergedSource = { ...existingProfile, ...patch };
1023
+ const mergedRecord = extractProfileFields(mergedSource, existingProfile.type);
1024
+ // 7. Read raw config to preserve unknown sections, update the profile
1025
+ const configPath = getPdConfigPath(workspaceDir);
1026
+ const rawConfig = readRawConfig(configPath);
1027
+ const profilesMap = isRecord(rawConfig.runtimeProfiles)
1028
+ ? { ...rawConfig.runtimeProfiles }
1029
+ : { ...effective.config.runtimeProfiles };
1030
+ profilesMap[profileId] = mergedRecord;
1031
+ rawConfig.runtimeProfiles = profilesMap;
1032
+ // 8. Validate the full updated config
1033
+ const validation = validatePdConfig(rawConfig);
1034
+ if (!validation.ok) {
1035
+ return {
1036
+ ok: false,
1037
+ statusCode: 400,
1038
+ error: 'bad_request',
1039
+ message: `Profile validation failed: ${validation.errors.map(e => e.reason).join('; ')}`,
1040
+ nextAction: 'Fix profile fields and retry',
1041
+ };
1042
+ }
1043
+ // 9. Atomic write
1044
+ try {
1045
+ writeConfigAtomic(configPath, rawConfig);
1046
+ }
1047
+ catch (err) {
1048
+ const message = err instanceof Error ? err.message : String(err);
1049
+ return { ok: false, statusCode: 500, error: 'write_error', message: `Failed to write config: ${message}`, nextAction: 'Check disk space and file permissions for .pd/config.yaml' };
1050
+ }
1051
+ // 10. Return the validated updated profile
1052
+ // Defensive guard: Object.hasOwn() doesn't narrow TS type.
1053
+ const updatedProfile = validation.value.runtimeProfiles[profileId];
1054
+ if (!updatedProfile) {
1055
+ return { ok: false, statusCode: 500, error: 'internal_error',
1056
+ message: `Profile '${profileId}' was updated but could not be read back from config.`,
1057
+ nextAction: 'This is a bug in PD config persistence. Please report it.' };
1058
+ }
1059
+ return {
1060
+ ok: true,
1061
+ profileId,
1062
+ profile: updatedProfile,
1063
+ };
1064
+ }
1065
+ /**
1066
+ * Delete a runtime profile from .pd/config.yaml.
1067
+ *
1068
+ * - Rejects non-existent profile (404 not_found)
1069
+ * - Rejects if profile is the defaultRuntime (400 bad_request)
1070
+ * - Rejects if any agent binding references the profile (400 bad_request, lists agents)
1071
+ * - Persists atomically, preserving unknown config sections
1072
+ *
1073
+ * ERR entries: same as createRuntimeProfile.
1074
+ */
1075
+ export function deleteRuntimeProfile(workspaceDir, profileId) {
1076
+ // 1. Validate profileId
1077
+ if (typeof profileId !== 'string' || profileId.length === 0) {
1078
+ return { ok: false, statusCode: 400, error: 'bad_request', message: 'profileId must be a non-empty string' };
1079
+ }
1080
+ // 2. Load existing config — refuse to write on malformed (rc-9)
1081
+ const loadResult = loadPdConfig(workspaceDir);
1082
+ if (!loadResult.ok) {
1083
+ return {
1084
+ ok: false,
1085
+ statusCode: 409,
1086
+ error: 'conflict',
1087
+ message: `Cannot delete runtime profile: existing .pd/config.yaml is malformed. Fix config errors first. Errors: ${loadResult.errors.map(e => e.reason).join('; ')}`,
1088
+ };
1089
+ }
1090
+ const { effective } = loadResult;
1091
+ // 3. Reject if profile doesn't exist (404)
1092
+ if (!Object.hasOwn(effective.config.runtimeProfiles, profileId)) {
1093
+ return {
1094
+ ok: false,
1095
+ statusCode: 404,
1096
+ error: 'not_found',
1097
+ message: `Runtime profile '${profileId}' does not exist. Available profiles: ${Object.keys(effective.config.runtimeProfiles).join(', ')}`,
1098
+ };
1099
+ }
1100
+ // Capture the profile snapshot BEFORE deletion (for return value).
1101
+ // Defensive guard: Object.hasOwn() doesn't narrow TS type.
1102
+ const deletedProfile = effective.config.runtimeProfiles[profileId];
1103
+ if (!deletedProfile) {
1104
+ return { ok: false, statusCode: 500, error: 'internal_error',
1105
+ message: `Profile '${profileId}' existence check passed but value is undefined.`,
1106
+ nextAction: 'This is a bug in PD config resolution. Please report it.' };
1107
+ }
1108
+ // 4. Reject if profile is the defaultRuntime
1109
+ if (effective.config.internalAgents.defaultRuntime === profileId) {
1110
+ return {
1111
+ ok: false,
1112
+ statusCode: 400,
1113
+ error: 'bad_request',
1114
+ message: `Cannot delete runtime profile '${profileId}' because it is the default runtime. Change the default runtime first.`,
1115
+ nextAction: 'Use PATCH /api/v1/config/default-runtime to change the default to another profile before deleting',
1116
+ };
1117
+ }
1118
+ // 5. Reject if any agent binding references this profile (list the agents)
1119
+ const referencingAgents = [];
1120
+ for (const agentName of INTERNAL_AGENT_NAMES) {
1121
+ const binding = effective.config.internalAgents.agents[agentName];
1122
+ if (binding && binding.runtimeProfile === profileId) {
1123
+ referencingAgents.push(agentName);
1124
+ }
1125
+ }
1126
+ if (referencingAgents.length > 0) {
1127
+ return {
1128
+ ok: false,
1129
+ statusCode: 400,
1130
+ error: 'bad_request',
1131
+ message: `Cannot delete runtime profile '${profileId}' because it is referenced by agents: ${referencingAgents.join(', ')}. Update their bindings first.`,
1132
+ nextAction: `Use PATCH /api/v1/config/agents/:agentName/binding to reassign: ${referencingAgents.join(', ')}`,
1133
+ };
1134
+ }
1135
+ // 6. Read raw config to preserve unknown sections, remove the profile
1136
+ const configPath = getPdConfigPath(workspaceDir);
1137
+ const rawConfig = readRawConfig(configPath);
1138
+ const profilesMap = isRecord(rawConfig.runtimeProfiles)
1139
+ ? { ...rawConfig.runtimeProfiles }
1140
+ : {};
1141
+ delete profilesMap[profileId];
1142
+ rawConfig.runtimeProfiles = profilesMap;
1143
+ // 7. Validate the updated config
1144
+ const validation = validatePdConfig(rawConfig);
1145
+ if (!validation.ok) {
1146
+ return {
1147
+ ok: false,
1148
+ statusCode: 400,
1149
+ error: 'bad_request',
1150
+ message: `Updated config would be invalid after deletion: ${validation.errors.map(e => e.reason).join('; ')}`,
1151
+ };
1152
+ }
1153
+ // 8. Atomic write
1154
+ try {
1155
+ writeConfigAtomic(configPath, rawConfig);
1156
+ }
1157
+ catch (err) {
1158
+ const message = err instanceof Error ? err.message : String(err);
1159
+ return { ok: false, statusCode: 500, error: 'write_error', message: `Failed to write config: ${message}`, nextAction: 'Check disk space and file permissions for .pd/config.yaml' };
1160
+ }
1161
+ // 9. Return the deleted profile snapshot for client confirmation
1162
+ return {
1163
+ ok: true,
1164
+ profileId,
1165
+ profile: deletedProfile,
1166
+ };
1167
+ }
805
1168
  // ── Check Readiness ──────────────────────────────────────────────────────────
806
1169
  export function checkReadiness(workspaceDir, agentName, getEnvVar = (name) => process.env[name]) {
807
1170
  // 1. Validate agent name
@@ -17,6 +17,7 @@ import { handleGovernanceRoute, disposeGovernanceModels } from './routes/governa
17
17
  import { handleEvidenceChainRoute, disposeEvidenceChainModels } from './routes/evidence-chain.js';
18
18
  import { handleIntentRoute, disposeIntentModels } from './routes/intent.js';
19
19
  import { handleIntentDecisionsRoute, disposeIntentDecisionModels } from './routes/intent-decisions.js';
20
+ import { handleOnboardingRoute, disposeOnboardingModels } from './routes/onboarding.js';
20
21
  import { createWorkspacesRoutes } from './routes/workspaces.js';
21
22
  import { handleUpdateRoute } from './routes/update.js';
22
23
  import { handleUpdateHistoryRoute } from './routes/update-history.js';
@@ -229,6 +230,7 @@ async function closeServices() {
229
230
  disposeEvidenceChainModels();
230
231
  disposeIntentModels();
231
232
  disposeIntentDecisionModels();
233
+ disposeOnboardingModels();
232
234
  }
233
235
  // ── Route handler ───────────────────────────────────────────────────────────
234
236
  function handleRequest(services) {
@@ -340,6 +342,13 @@ function handleRequest(services) {
340
342
  asyncHandler(() => handleIntentDecisionsRoute(req, res, services.workspaceDir, subPath))(req, res);
341
343
  return;
342
344
  }
345
+ // Onboarding wizard: POST /api/v1/onboarding/run-demo — spawns `pd demo story-a`
346
+ // (spec 2026-06-30-new-user-onboarding-design.md §6.3 改动 5)
347
+ if (urlPath === '/api/v1/onboarding' || urlPath.startsWith('/api/v1/onboarding/')) {
348
+ const subPath = urlPath === '/api/v1/onboarding' ? '' : urlPath.slice('/api/v1/onboarding'.length);
349
+ asyncHandler(() => handleOnboardingRoute(req, res, { workspaceDir: services.workspaceDir, subPath }))(req, res);
350
+ return;
351
+ }
343
352
  // PRI-331: GET /api/v1/evidence-chain
344
353
  if (urlPath === '/api/v1/evidence-chain') {
345
354
  asyncHandler(() => handleEvidenceChainRoute(req, res, services.workspaceDir))(req, res);
@@ -1,18 +1,57 @@
1
+ /**
2
+ * PRI-491 — owner-observable activation record.
3
+ *
4
+ * Mirrors the CLI's `AnnotatedActivation` so the Console surfaces the same
5
+ * mode / status / contextVersion / evidenceRefs / nextAction fields the owner
6
+ * sees in `pd activation list`. Without this enrichment the Console would
7
+ * hide suspended-by-flag state, silently showing v2 activations as "active"
8
+ * even when the rulecode_context_v2 flag is off.
9
+ */
1
10
  export interface ActivationRecord {
2
- id: string;
11
+ activationId: string;
3
12
  artifactId: string;
4
13
  principleId: string;
5
14
  channel: string;
6
15
  action: string;
7
16
  targetRef: string;
8
17
  activatedAt: string | null;
9
- status: 'active' | 'inactive';
18
+ /** When this activation was promoted from shadow to live (null for never-promoted). */
19
+ promotedAt: string | null;
20
+ /** When this activation was deactivated (null for active). */
21
+ deactivatedAt: string | null;
22
+ /**
23
+ * Lifecycle mode derived from action.
24
+ * - 'shadow' for code_tool_hook_shadow_activate
25
+ * - 'live' for code_tool_hook_live_activate
26
+ * - undefined for unrecognized actions (cannot be safely mode-tagged).
27
+ */
28
+ mode?: 'shadow' | 'live';
29
+ /**
30
+ * Owner-visible status. Precedence: deactivated > suspended_by_flag > active.
31
+ * - 'deactivated' — deactivatedAt is non-null.
32
+ * - 'suspended_by_flag' — v2 artifact but rulecode_context_v2 flag is off.
33
+ * - 'active' — loaded and (for v2) flag is on.
34
+ */
35
+ status: 'active' | 'deactivated' | 'suspended_by_flag';
36
+ /** Artifact context version derived from requiresContextVersion field. */
37
+ contextVersion?: 'v1' | 'v2';
38
+ /** Owner-labelled evidence refs preserved from the artifact (PRI-490). */
39
+ evidenceRefs?: string[];
40
+ /** Human-readable summary of evidenceRefs for display. */
41
+ evidenceSummary?: string;
42
+ /** Next CLI command the owner should run to act on this activation. */
43
+ nextAction?: string;
44
+ /** Present when the activation references a non-existent artifact. */
45
+ warning?: string;
10
46
  }
11
47
  export interface ActivationsResponse {
12
48
  activations: ActivationRecord[];
13
- generatedAt: string;
14
- /** Present when data is degraded/missing rather than genuinely empty */
15
- note?: string;
49
+ /** 'ok' on success, 'degraded' when data is incomplete/missing. */
50
+ status: 'ok' | 'degraded';
51
+ /** Present when status is 'degraded' — explains why. */
52
+ reason?: string;
53
+ /** Present when status is 'degraded' — next operator action. */
54
+ nextAction?: string;
16
55
  }
17
56
  export declare class ActivationsConsoleModel {
18
57
  private readonly workspaceDir;