create-principles-disciple 1.144.27 → 1.145.1

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 (347) hide show
  1. package/LICENSE +73 -21
  2. package/NOTICE +2 -0
  3. package/README.md +1 -1
  4. package/_release/product-identity.json +2 -2
  5. package/codex-adapter/dist/index.d.ts +2 -2
  6. package/codex-adapter/dist/index.js +1 -1
  7. package/codex-adapter/dist/ingestion/admission.js +16 -0
  8. package/codex-adapter/dist/ingestion/codex-version.d.ts +10 -4
  9. package/codex-adapter/dist/ingestion/codex-version.js +10 -4
  10. package/codex-adapter/dist/ingestion/explicit-owner-statement.d.ts +48 -0
  11. package/codex-adapter/dist/ingestion/explicit-owner-statement.js +123 -0
  12. package/codex-adapter/dist/ingestion/ingestion.js +50 -1
  13. package/codex-adapter/dist/pd-hook.js +66 -3
  14. package/codex-adapter/dist/worker/workspace-worker.d.ts +14 -0
  15. package/codex-adapter/dist/worker/workspace-worker.js +194 -11
  16. package/codex-adapter/package.json +6 -4
  17. package/console/dist/server/models/ApprovalsConsoleModel.d.ts +2 -2
  18. package/console/dist/server/models/ApprovalsConsoleModel.js +1 -1
  19. package/console/dist/server/models/ApprovalsGroupedConsoleModel.js +1 -1
  20. package/console/dist/server/models/PrinciplesConsoleModel.d.ts +26 -1
  21. package/console/dist/server/models/PrinciplesConsoleModel.js +18 -1
  22. package/console/dist/server/routes/activations.js +4 -4
  23. package/console/dist/server/routes/approvals.js +2 -2
  24. package/console/dist/server/routes/failed-tasks.d.ts +9 -0
  25. package/console/dist/server/routes/failed-tasks.js +116 -7
  26. package/console/dist/server/routes/principles.js +73 -1
  27. package/console/dist/shared/prompt-injection-contract.d.ts +1 -1
  28. package/console/dist/ui/api.d.ts +5 -5
  29. package/console/dist/ui/i18n/en.json +13 -2
  30. package/console/dist/ui/i18n/zh-CN.json +13 -2
  31. package/console/dist/ui/pages/activation/ActivationPage.js +2 -1
  32. package/console/dist/ui/pages/failed-tasks/FailedTasksPage.js +42 -4
  33. package/console/dist/ui/pages/focus/FocusPage.js +3 -3
  34. package/console/dist/ui/pages/principles/PrinciplesPage.js +7 -2
  35. package/console/dist/ui/utils/validators.d.ts +6 -2
  36. package/console/dist/ui/utils/validators.js +19 -4
  37. package/console/dist/web/assets/app.css +26 -0
  38. package/console/dist/web/assets/app.js +24 -24
  39. package/console/package.json +6 -5
  40. package/core/dist/host/host-installer.d.ts +3 -1
  41. package/core/dist/host/host-installer.d.ts.map +1 -1
  42. package/core/dist/host/host-installer.js.map +1 -1
  43. package/core/dist/runtime-v2/admission-gate.d.ts +8 -0
  44. package/core/dist/runtime-v2/admission-gate.d.ts.map +1 -1
  45. package/core/dist/runtime-v2/admission-gate.js +3 -2
  46. package/core/dist/runtime-v2/admission-gate.js.map +1 -1
  47. package/core/dist/runtime-v2/config/pd-config-defaults.d.ts.map +1 -1
  48. package/core/dist/runtime-v2/config/pd-config-defaults.js +16 -1
  49. package/core/dist/runtime-v2/config/pd-config-defaults.js.map +1 -1
  50. package/core/dist/runtime-v2/context-payload.d.ts +43 -3
  51. package/core/dist/runtime-v2/context-payload.d.ts.map +1 -1
  52. package/core/dist/runtime-v2/context-payload.js +15 -1
  53. package/core/dist/runtime-v2/context-payload.js.map +1 -1
  54. package/core/dist/runtime-v2/evidence-guards.d.ts +6 -0
  55. package/core/dist/runtime-v2/evidence-guards.d.ts.map +1 -1
  56. package/core/dist/runtime-v2/evidence-guards.js +11 -0
  57. package/core/dist/runtime-v2/evidence-guards.js.map +1 -1
  58. package/core/dist/runtime-v2/evolution/evolution-types.d.ts +4 -4
  59. package/core/dist/runtime-v2/evolution/evolution-types.d.ts.map +1 -1
  60. package/core/dist/runtime-v2/evolution/evolution-types.js +1 -1
  61. package/core/dist/runtime-v2/evolution/evolution-types.js.map +1 -1
  62. package/core/dist/runtime-v2/feature-flags/feature-flag-contract.d.ts.map +1 -1
  63. package/core/dist/runtime-v2/feature-flags/feature-flag-contract.js +6 -0
  64. package/core/dist/runtime-v2/feature-flags/feature-flag-contract.js.map +1 -1
  65. package/core/dist/runtime-v2/feature-flags/feature-flag-lifecycle.d.ts.map +1 -1
  66. package/core/dist/runtime-v2/feature-flags/feature-flag-lifecycle.js +8 -0
  67. package/core/dist/runtime-v2/feature-flags/feature-flag-lifecycle.js.map +1 -1
  68. package/core/dist/runtime-v2/index.d.ts +5 -2
  69. package/core/dist/runtime-v2/index.d.ts.map +1 -1
  70. package/core/dist/runtime-v2/index.js +3 -1
  71. package/core/dist/runtime-v2/index.js.map +1 -1
  72. package/core/dist/runtime-v2/internalization/evaluator-output.d.ts +11 -0
  73. package/core/dist/runtime-v2/internalization/evaluator-output.d.ts.map +1 -1
  74. package/core/dist/runtime-v2/internalization/evaluator-output.js +10 -0
  75. package/core/dist/runtime-v2/internalization/evaluator-output.js.map +1 -1
  76. package/core/dist/runtime-v2/internalization/evaluator-prompt-builder.d.ts +3 -3
  77. package/core/dist/runtime-v2/internalization/evaluator-prompt-builder.d.ts.map +1 -1
  78. package/core/dist/runtime-v2/internalization/evaluator-prompt-builder.js +49 -5
  79. package/core/dist/runtime-v2/internalization/evaluator-prompt-builder.js.map +1 -1
  80. package/core/dist/runtime-v2/internalization/evaluator-runner.d.ts.map +1 -1
  81. package/core/dist/runtime-v2/internalization/evaluator-runner.js +13 -16
  82. package/core/dist/runtime-v2/internalization/evaluator-runner.js.map +1 -1
  83. package/core/dist/runtime-v2/internalization/owner-decision-review.d.ts.map +1 -1
  84. package/core/dist/runtime-v2/internalization/owner-decision-review.js +5 -1
  85. package/core/dist/runtime-v2/internalization/owner-decision-review.js.map +1 -1
  86. package/core/dist/runtime-v2/internalization/owner-review.d.ts +2 -2
  87. package/core/dist/runtime-v2/internalization/owner-review.js +2 -2
  88. package/core/dist/runtime-v2/internalization/scribe-output.d.ts +12 -0
  89. package/core/dist/runtime-v2/internalization/scribe-output.d.ts.map +1 -1
  90. package/core/dist/runtime-v2/internalization/scribe-output.js +20 -0
  91. package/core/dist/runtime-v2/internalization/scribe-output.js.map +1 -1
  92. package/core/dist/runtime-v2/internalization/scribe-prompt-builder.d.ts +32 -1
  93. package/core/dist/runtime-v2/internalization/scribe-prompt-builder.d.ts.map +1 -1
  94. package/core/dist/runtime-v2/internalization/scribe-prompt-builder.js +38 -1
  95. package/core/dist/runtime-v2/internalization/scribe-prompt-builder.js.map +1 -1
  96. package/core/dist/runtime-v2/internalization-queue-read-model.d.ts +6 -0
  97. package/core/dist/runtime-v2/internalization-queue-read-model.d.ts.map +1 -1
  98. package/core/dist/runtime-v2/internalization-queue-read-model.js +8 -1
  99. package/core/dist/runtime-v2/internalization-queue-read-model.js.map +1 -1
  100. package/core/dist/runtime-v2/intervention-evidence-normalizer.d.ts.map +1 -1
  101. package/core/dist/runtime-v2/intervention-evidence-normalizer.js +10 -3
  102. package/core/dist/runtime-v2/intervention-evidence-normalizer.js.map +1 -1
  103. package/core/dist/runtime-v2/pain-ingress.d.ts +1 -1
  104. package/core/dist/runtime-v2/pain-ingress.d.ts.map +1 -1
  105. package/core/dist/runtime-v2/pain-signal-bridge.d.ts +68 -2
  106. package/core/dist/runtime-v2/pain-signal-bridge.d.ts.map +1 -1
  107. package/core/dist/runtime-v2/pain-signal-bridge.js +541 -18
  108. package/core/dist/runtime-v2/pain-signal-bridge.js.map +1 -1
  109. package/core/dist/runtime-v2/pain-signal-runtime-factory.d.ts.map +1 -1
  110. package/core/dist/runtime-v2/pain-signal-runtime-factory.js +4 -0
  111. package/core/dist/runtime-v2/pain-signal-runtime-factory.js.map +1 -1
  112. package/core/dist/runtime-v2/product-telemetry/snapshot-contract.d.ts +2 -2
  113. package/core/dist/runtime-v2/product-telemetry/snapshot-contract.d.ts.map +1 -1
  114. package/core/dist/runtime-v2/product-telemetry/snapshot-contract.js +2 -2
  115. package/core/dist/runtime-v2/product-telemetry/snapshot-contract.js.map +1 -1
  116. package/core/dist/runtime-v2/store/candidate/admission-document.d.ts +90 -0
  117. package/core/dist/runtime-v2/store/candidate/admission-document.d.ts.map +1 -0
  118. package/core/dist/runtime-v2/store/candidate/admission-document.js +142 -0
  119. package/core/dist/runtime-v2/store/candidate/admission-document.js.map +1 -0
  120. package/core/dist/runtime-v2/store/candidate/candidate-store.d.ts +53 -0
  121. package/core/dist/runtime-v2/store/candidate/candidate-store.d.ts.map +1 -1
  122. package/core/dist/runtime-v2/store/candidate/memory-candidate-store.d.ts +35 -0
  123. package/core/dist/runtime-v2/store/candidate/memory-candidate-store.d.ts.map +1 -1
  124. package/core/dist/runtime-v2/store/candidate/memory-candidate-store.js +48 -0
  125. package/core/dist/runtime-v2/store/candidate/memory-candidate-store.js.map +1 -1
  126. package/core/dist/runtime-v2/store/candidate/sqlite-candidate-store.d.ts +44 -0
  127. package/core/dist/runtime-v2/store/candidate/sqlite-candidate-store.d.ts.map +1 -1
  128. package/core/dist/runtime-v2/store/candidate/sqlite-candidate-store.js +136 -0
  129. package/core/dist/runtime-v2/store/candidate/sqlite-candidate-store.js.map +1 -1
  130. package/core/dist/runtime-v2/store/context/sqlite-context-assembler.js.map +1 -1
  131. package/core/dist/runtime-v2/store/intervention-evidence-schema.js +1 -1
  132. package/core/dist/runtime-v2/store/runtime-state-manager.d.ts +65 -0
  133. package/core/dist/runtime-v2/store/runtime-state-manager.d.ts.map +1 -1
  134. package/core/dist/runtime-v2/store/runtime-state-manager.js +46 -0
  135. package/core/dist/runtime-v2/store/runtime-state-manager.js.map +1 -1
  136. package/core/dist/runtime-v2/store/sqlite-connection.d.ts.map +1 -1
  137. package/core/dist/runtime-v2/store/sqlite-connection.js +42 -0
  138. package/core/dist/runtime-v2/store/sqlite-connection.js.map +1 -1
  139. package/core/dist/runtime-v2/store/sqlite-intervention-evidence-store.d.ts +1 -1
  140. package/core/dist/runtime-v2/store/sqlite-intervention-evidence-store.d.ts.map +1 -1
  141. package/core/dist/runtime-v2/store/sqlite-intervention-evidence-store.js.map +1 -1
  142. package/core/dist/runtime-v2/store/task/sqlite-family-reopen.d.ts +19 -0
  143. package/core/dist/runtime-v2/store/task/sqlite-family-reopen.d.ts.map +1 -0
  144. package/core/dist/runtime-v2/store/task/sqlite-family-reopen.js +36 -0
  145. package/core/dist/runtime-v2/store/task/sqlite-family-reopen.js.map +1 -0
  146. package/core/dist/runtime-v2/store/task/sqlite-task-store.d.ts +23 -0
  147. package/core/dist/runtime-v2/store/task/sqlite-task-store.d.ts.map +1 -1
  148. package/core/dist/runtime-v2/store/task/sqlite-task-store.js +50 -0
  149. package/core/dist/runtime-v2/store/task/sqlite-task-store.js.map +1 -1
  150. package/core/dist/runtime-v2/task-status.d.ts +3 -1
  151. package/core/dist/runtime-v2/task-status.d.ts.map +1 -1
  152. package/core/dist/runtime-v2/task-status.js +1 -1
  153. package/core/dist/runtime-v2/task-status.js.map +1 -1
  154. package/core/dist/runtime-v2/trajectory-schema.d.ts.map +1 -1
  155. package/core/dist/runtime-v2/trajectory-schema.js +11 -0
  156. package/core/dist/runtime-v2/trajectory-schema.js.map +1 -1
  157. package/core/dist/runtime-v2/types/event-types.d.ts +2 -2
  158. package/core/dist/runtime-v2/types/event-types.d.ts.map +1 -1
  159. package/core/dist/runtime-v2/types/event-types.js +1 -1
  160. package/core/dist/runtime-v2/types/event-types.js.map +1 -1
  161. package/core/dist/runtime-v2/types/evidence-chain-contract.d.ts +1 -1
  162. package/core/dist/runtime-v2/types/evidence-chain-contract.d.ts.map +1 -1
  163. package/core/dist/runtime-v2/types/evidence-chain-contract.js +2 -2
  164. package/core/dist/runtime-v2/types/evidence-chain-contract.js.map +1 -1
  165. package/core/dist/runtime-v2/types/intervention-evidence-contract.d.ts +3 -3
  166. package/core/dist/runtime-v2/types/intervention-evidence-contract.d.ts.map +1 -1
  167. package/core/dist/runtime-v2/types/intervention-evidence-contract.js +1 -0
  168. package/core/dist/runtime-v2/types/intervention-evidence-contract.js.map +1 -1
  169. package/core/dist/telemetry-event.d.ts +2 -2
  170. package/core/dist/telemetry-event.d.ts.map +1 -1
  171. package/core/dist/telemetry-event.js +4 -0
  172. package/core/dist/telemetry-event.js.map +1 -1
  173. package/core/dist/trajectory-types.d.ts +2 -2
  174. package/core/dist/trajectory-types.d.ts.map +1 -1
  175. package/core/package.json +7 -5
  176. package/dist/index.d.ts.map +1 -1
  177. package/dist/index.js +84 -8
  178. package/dist/index.js.map +1 -1
  179. package/dist/installer.d.ts +42 -11
  180. package/dist/installer.d.ts.map +1 -1
  181. package/dist/installer.js +140 -36
  182. package/dist/installer.js.map +1 -1
  183. package/dist/installers/index.d.ts +18 -7
  184. package/dist/installers/index.d.ts.map +1 -1
  185. package/dist/installers/index.js +13 -4
  186. package/dist/installers/index.js.map +1 -1
  187. package/dist/installers/workbuddy-host-installer.d.ts +246 -0
  188. package/dist/installers/workbuddy-host-installer.d.ts.map +1 -0
  189. package/dist/installers/workbuddy-host-installer.js +1419 -0
  190. package/dist/installers/workbuddy-host-installer.js.map +1 -0
  191. package/dist/mvp-config.d.ts +24 -0
  192. package/dist/mvp-config.d.ts.map +1 -1
  193. package/dist/mvp-config.js +36 -0
  194. package/dist/mvp-config.js.map +1 -1
  195. package/dist/prompts.d.ts +13 -0
  196. package/dist/prompts.d.ts.map +1 -1
  197. package/dist/prompts.js +45 -8
  198. package/dist/prompts.js.map +1 -1
  199. package/dist/uninstaller.d.ts +1 -1
  200. package/dist/uninstaller.d.ts.map +1 -1
  201. package/dist/uninstaller.js +29 -4
  202. package/dist/uninstaller.js.map +1 -1
  203. package/host-runtime/dist/governance-signal-admission.d.ts +63 -0
  204. package/host-runtime/dist/governance-signal-admission.js +322 -53
  205. package/host-runtime/dist/host-liveness-contract.js +7 -1
  206. package/host-runtime/dist/index.d.ts +1 -0
  207. package/host-runtime/dist/index.js +5 -1
  208. package/host-runtime/dist/internalization-consumer-cycle.d.ts +12 -0
  209. package/host-runtime/dist/internalization-consumer-cycle.js +43 -1
  210. package/host-runtime/dist/intervention-evidence-ingress.d.ts +1 -1
  211. package/host-runtime/dist/product-telemetry/service.js +1 -1
  212. package/host-runtime/dist/production-pain-evidence.d.ts +59 -1
  213. package/host-runtime/dist/production-pain-evidence.js +200 -17
  214. package/host-runtime/dist/prompt-activation-deliverability.js +5 -4
  215. package/host-runtime/dist/prompt-injection-event-evidence.d.ts +1 -1
  216. package/host-runtime/dist/prompt-injection-event-evidence.js +5 -1
  217. package/host-runtime/dist/prompt-injection-projection.d.ts +14 -5
  218. package/host-runtime/dist/prompt-injection-projection.js +30 -16
  219. package/host-runtime/dist/workbuddy-worker-status.d.ts +24 -0
  220. package/host-runtime/dist/workbuddy-worker-status.js +52 -0
  221. package/host-runtime/package.json +7 -5
  222. package/install-layout/dist/index.d.ts +18 -1
  223. package/install-layout/dist/index.js +15 -2
  224. package/install-layout/package.json +5 -3
  225. package/package.json +9 -7
  226. package/pd-cli/dist/commands/candidate.d.ts.map +1 -1
  227. package/pd-cli/dist/commands/candidate.js +44 -4
  228. package/pd-cli/dist/commands/candidate.js.map +1 -1
  229. package/pd-cli/dist/commands/codex-worker.d.ts.map +1 -1
  230. package/pd-cli/dist/commands/codex-worker.js +30 -1
  231. package/pd-cli/dist/commands/codex-worker.js.map +1 -1
  232. package/pd-cli/dist/commands/config-doctor.d.ts.map +1 -1
  233. package/pd-cli/dist/commands/config-doctor.js +19 -4
  234. package/pd-cli/dist/commands/config-doctor.js.map +1 -1
  235. package/pd-cli/dist/commands/diagnose.d.ts.map +1 -1
  236. package/pd-cli/dist/commands/diagnose.js +4 -1
  237. package/pd-cli/dist/commands/diagnose.js.map +1 -1
  238. package/pd-cli/dist/commands/health-codex-install.d.ts +85 -0
  239. package/pd-cli/dist/commands/health-codex-install.d.ts.map +1 -0
  240. package/pd-cli/dist/commands/health-codex-install.js +207 -0
  241. package/pd-cli/dist/commands/health-codex-install.js.map +1 -0
  242. package/pd-cli/dist/commands/health-codex.d.ts.map +1 -1
  243. package/pd-cli/dist/commands/health-codex.js +78 -0
  244. package/pd-cli/dist/commands/health-codex.js.map +1 -1
  245. package/pd-cli/dist/commands/pain-list.d.ts +3 -2
  246. package/pd-cli/dist/commands/pain-list.d.ts.map +1 -1
  247. package/pd-cli/dist/commands/pain-list.js +10 -10
  248. package/pd-cli/dist/commands/pain-list.js.map +1 -1
  249. package/pd-cli/dist/commands/pain-record.d.ts +2 -0
  250. package/pd-cli/dist/commands/pain-record.d.ts.map +1 -1
  251. package/pd-cli/dist/commands/pain-record.js +36 -0
  252. package/pd-cli/dist/commands/pain-record.js.map +1 -1
  253. package/pd-cli/dist/commands/pain-retry.d.ts +6 -0
  254. package/pd-cli/dist/commands/pain-retry.d.ts.map +1 -1
  255. package/pd-cli/dist/commands/pain-retry.js +152 -5
  256. package/pd-cli/dist/commands/pain-retry.js.map +1 -1
  257. package/pd-cli/dist/commands/runtime-activation.d.ts +1 -1
  258. package/pd-cli/dist/commands/runtime-activation.d.ts.map +1 -1
  259. package/pd-cli/dist/commands/runtime-activation.js +3 -3
  260. package/pd-cli/dist/commands/runtime-activation.js.map +1 -1
  261. package/pd-cli/dist/commands/workbuddy-worker.d.ts +19 -0
  262. package/pd-cli/dist/commands/workbuddy-worker.d.ts.map +1 -0
  263. package/pd-cli/dist/commands/workbuddy-worker.js +168 -0
  264. package/pd-cli/dist/commands/workbuddy-worker.js.map +1 -0
  265. package/pd-cli/dist/index.js +29 -1
  266. package/pd-cli/dist/index.js.map +1 -1
  267. package/pd-cli/dist/resolve-workspace.d.ts +14 -2
  268. package/pd-cli/dist/resolve-workspace.d.ts.map +1 -1
  269. package/pd-cli/dist/resolve-workspace.js +88 -21
  270. package/pd-cli/dist/resolve-workspace.js.map +1 -1
  271. package/pd-cli/dist/services/admission-write-gate.d.ts +24 -0
  272. package/pd-cli/dist/services/admission-write-gate.d.ts.map +1 -0
  273. package/pd-cli/dist/services/admission-write-gate.js +41 -0
  274. package/pd-cli/dist/services/admission-write-gate.js.map +1 -0
  275. package/pd-cli/dist/services/pd-config-loader.d.ts +39 -7
  276. package/pd-cli/dist/services/pd-config-loader.d.ts.map +1 -1
  277. package/pd-cli/dist/services/pd-config-loader.js +111 -18
  278. package/pd-cli/dist/services/pd-config-loader.js.map +1 -1
  279. package/pd-cli/dist/services/rulehost-pipeline-runner.d.ts +10 -0
  280. package/pd-cli/dist/services/rulehost-pipeline-runner.d.ts.map +1 -1
  281. package/pd-cli/dist/services/rulehost-pipeline-runner.js +59 -4
  282. package/pd-cli/dist/services/rulehost-pipeline-runner.js.map +1 -1
  283. package/pd-cli/package.json +8 -5
  284. package/plugin/dist/bundle.js +564 -509
  285. package/plugin/dist/governance-audit.js +1 -1
  286. package/plugin/dist/openclaw.plugin.json +1 -1
  287. package/plugin/dist/rulehost-evidence.js +1 -1
  288. package/plugin/openclaw.plugin.json +1 -1
  289. package/plugin/package.json +7 -5
  290. package/release-manager/dist/index.d.ts.map +1 -1
  291. package/release-manager/dist/index.js +84 -8
  292. package/release-manager/dist/index.js.map +1 -1
  293. package/release-manager/dist/installer.d.ts +42 -11
  294. package/release-manager/dist/installer.d.ts.map +1 -1
  295. package/release-manager/dist/installer.js +140 -36
  296. package/release-manager/dist/installer.js.map +1 -1
  297. package/release-manager/dist/installers/index.d.ts +18 -7
  298. package/release-manager/dist/installers/index.d.ts.map +1 -1
  299. package/release-manager/dist/installers/index.js +13 -4
  300. package/release-manager/dist/installers/index.js.map +1 -1
  301. package/release-manager/dist/installers/workbuddy-host-installer.d.ts +246 -0
  302. package/release-manager/dist/installers/workbuddy-host-installer.d.ts.map +1 -0
  303. package/release-manager/dist/installers/workbuddy-host-installer.js +1419 -0
  304. package/release-manager/dist/installers/workbuddy-host-installer.js.map +1 -0
  305. package/release-manager/dist/mvp-config.d.ts +24 -0
  306. package/release-manager/dist/mvp-config.d.ts.map +1 -1
  307. package/release-manager/dist/mvp-config.js +36 -0
  308. package/release-manager/dist/mvp-config.js.map +1 -1
  309. package/release-manager/dist/prompts.d.ts +13 -0
  310. package/release-manager/dist/prompts.d.ts.map +1 -1
  311. package/release-manager/dist/prompts.js +45 -8
  312. package/release-manager/dist/prompts.js.map +1 -1
  313. package/release-manager/dist/uninstaller.d.ts +1 -1
  314. package/release-manager/dist/uninstaller.d.ts.map +1 -1
  315. package/release-manager/dist/uninstaller.js +29 -4
  316. package/release-manager/dist/uninstaller.js.map +1 -1
  317. package/release-manager/package.json +8 -6
  318. package/workbuddy-adapter/dist/codec/index.d.ts +2 -0
  319. package/workbuddy-adapter/dist/codec/index.js +2 -0
  320. package/workbuddy-adapter/dist/codec/input-decoder.d.ts +30 -0
  321. package/workbuddy-adapter/dist/codec/input-decoder.js +232 -0
  322. package/workbuddy-adapter/dist/codec/output-encoder.d.ts +62 -0
  323. package/workbuddy-adapter/dist/codec/output-encoder.js +75 -0
  324. package/workbuddy-adapter/dist/host-adapter.d.ts +33 -0
  325. package/workbuddy-adapter/dist/host-adapter.js +23 -0
  326. package/workbuddy-adapter/dist/index.d.ts +16 -0
  327. package/workbuddy-adapter/dist/index.js +16 -0
  328. package/workbuddy-adapter/dist/pd-hook.d.ts +17 -0
  329. package/workbuddy-adapter/dist/pd-hook.js +505 -0
  330. package/workbuddy-adapter/dist/tool-semantics.d.ts +22 -0
  331. package/workbuddy-adapter/dist/tool-semantics.js +33 -0
  332. package/workbuddy-adapter/dist/workbuddy-evidence-recorder.d.ts +50 -0
  333. package/workbuddy-adapter/dist/workbuddy-evidence-recorder.js +238 -0
  334. package/workbuddy-adapter/dist/worker/workspace-worker.d.ts +41 -0
  335. package/workbuddy-adapter/dist/worker/workspace-worker.js +219 -0
  336. package/workbuddy-adapter/dist/workspace-resolution.d.ts +15 -0
  337. package/workbuddy-adapter/dist/workspace-resolution.js +53 -0
  338. package/workbuddy-adapter/package.json +64 -0
  339. package/workbuddy-adapter/plugin/.codebuddy-plugin/plugin.json +6 -0
  340. package/workbuddy-adapter/plugin/hooks/hooks.json +62 -0
  341. package/workbuddy-adapter/plugin/scripts/wrapper.cjs +79 -0
  342. package/console/dist/ui/utils/navigation.d.ts +0 -9
  343. package/console/dist/ui/utils/navigation.js +0 -7
  344. package/core/dist/runtime-v2/internalization/dimension-coverage-policy.d.ts +0 -54
  345. package/core/dist/runtime-v2/internalization/dimension-coverage-policy.d.ts.map +0 -1
  346. package/core/dist/runtime-v2/internalization/dimension-coverage-policy.js +0 -70
  347. package/core/dist/runtime-v2/internalization/dimension-coverage-policy.js.map +0 -1
@@ -0,0 +1,238 @@
1
+ /**
2
+ * WorkBuddy Evidence Recorder — the WorkBuddy source adapter for the PD v2
3
+ * evidence ledger (ADR-0027; SPEC workbuddy-host-adapter §4.6). Ports the
4
+ * codex-adapter recorder pattern onto the frozen
5
+ * `workbuddy_pd_hook_event_log` source kind with WorkBuddy's PROBE-VERIFIED
6
+ * honesty boundaries:
7
+ *
8
+ * - agent_context_delivery: supported, max confirmation 'submitted' — the
9
+ * UserPromptSubmit additionalContext channel was verified in model-visible
10
+ * context by probe P04, but the adapter proves only submission on stdout;
11
+ * - enforcement_delivery: supported, max confirmation 'runtime_loaded' —
12
+ * probe P02 VERIFIED a deny permissionDecision actually blocks the tool
13
+ * (target file not written), so unlike Codex (suspended, PRI-780) this
14
+ * host can honestly claim runtime enforcement for v1 live rules;
15
+ * - application_self_report: unsupported — no self-report capture channel;
16
+ * - v2 rule context: like Codex, WorkBuddy supplies NO runtime context
17
+ * provider, so v2 rules stay suspended (rule_context_v2_unavailable);
18
+ * nothing here claims v2 enforcement.
19
+ *
20
+ * All writes flow through the shared host-runtime ingress (SPEC §13.7 single
21
+ * entry). Best-effort: degradation produces a bounded stderr diagnostic and
22
+ * never changes an already computed tool decision (P02: an already-encoded
23
+ * deny must survive evidence failure).
24
+ */
25
+ import { getInterventionEvidenceIngress } from '@principles/host-runtime';
26
+ /** Evidence adapter surface version (matches the frozen core contract test expectations). */
27
+ export const WORKBUDDY_EVIDENCE_ADAPTER_VERSION = 'workbuddy-adapter@0.1.0';
28
+ export function workbuddyCapabilityDeclarations() {
29
+ return [
30
+ {
31
+ hostKind: 'workbuddy', capability: 'agent_context_delivery', status: 'supported',
32
+ adapterVersion: WORKBUDDY_EVIDENCE_ADAPTER_VERSION, channel: 'pd-hook:UserPromptSubmit',
33
+ maxConfirmation: 'submitted',
34
+ note: 'P04 probe: additionalContext verified in model-visible context as a hook system-reminder; stdout submission is the proof boundary',
35
+ },
36
+ {
37
+ hostKind: 'workbuddy', capability: 'enforcement_delivery', status: 'supported',
38
+ adapterVersion: WORKBUDDY_EVIDENCE_ADAPTER_VERSION, channel: 'code_tool_hook',
39
+ maxConfirmation: 'runtime_loaded',
40
+ note: 'P02 probe: PreToolUse deny verified to block tool execution (target file not written); v2 rules stay suspended (no context provider)',
41
+ },
42
+ {
43
+ hostKind: 'workbuddy', capability: 'application_self_report', status: 'unsupported',
44
+ adapterVersion: WORKBUDDY_EVIDENCE_ADAPTER_VERSION, channel: 'pd-hook',
45
+ note: 'no self-report capture channel exists on the WorkBuddy host; nothing is claimed',
46
+ },
47
+ {
48
+ hostKind: 'workbuddy', capability: 'behavior_observation', status: 'unknown',
49
+ adapterVersion: WORKBUDDY_EVIDENCE_ADAPTER_VERSION, channel: 'pd-hook:PostToolUse',
50
+ note: 'tool episodes are recorded through the shared pain path; no automated outcome source exists yet',
51
+ },
52
+ {
53
+ hostKind: 'workbuddy', capability: 'outcome_observation', status: 'unknown',
54
+ adapterVersion: WORKBUDDY_EVIDENCE_ADAPTER_VERSION, channel: 'console',
55
+ note: 'no automated outcome source; outcomes enter via Owner console input only',
56
+ },
57
+ ];
58
+ }
59
+ function appendWorkbuddyBatch(workspaceDir, observations, warn) {
60
+ if (observations.length === 0)
61
+ return;
62
+ const ingress = getInterventionEvidenceIngress();
63
+ const batch = {
64
+ evidenceScopeId: ingress.evidenceScopeIdFor(workspaceDir),
65
+ sourceKind: 'workbuddy_pd_hook_event_log',
66
+ adapterVersion: WORKBUDDY_EVIDENCE_ADAPTER_VERSION,
67
+ recordedAt: new Date().toISOString(),
68
+ observations,
69
+ capabilityDeclarations: workbuddyCapabilityDeclarations(),
70
+ };
71
+ const result = ingress.appendObservationBatch({ workspaceDir, batch });
72
+ if (!result.ok) {
73
+ warn(`[PD:Evidence] workbuddy append degraded: ${result.reason ?? 'unknown'}; next: ${result.nextAction ?? 'replay from durable source'}`);
74
+ }
75
+ }
76
+ /**
77
+ * Record one agent-context delivery attempt per injected principle after the
78
+ * raw injected-event line has been appended to the durable WorkBuddy event
79
+ * log — confirmation 'submitted', outcome 'attempted' (submitted ≠ delivered,
80
+ * SPEC §4.6).
81
+ */
82
+ export function recordWorkbuddyPromptDeliveryEvidence(input) {
83
+ if (!input.evidenceEnabled || input.injected.length === 0)
84
+ return;
85
+ const ingress = getInterventionEvidenceIngress();
86
+ const observations = [];
87
+ for (const entry of input.injected) {
88
+ const observationKey = `workbuddy|delivery|agent_context|${input.sessionId}|${input.turnId ?? '-'}|${entry.activationId}`;
89
+ const sourceLocator = `workbuddy-pd-hook-event-log:${input.sessionId}`;
90
+ const existing = ingress.existingObservationRefs(input.workspaceDir, {
91
+ sourceKind: 'workbuddy_pd_hook_event_log', sourceLocator, observationKey,
92
+ principleId: entry.principleId, activationId: entry.activationId, ...(entry.artifactId ? { artifactId: entry.artifactId } : {}),
93
+ });
94
+ const activationRef = existing?.activationRef ?? ingress.resolveActivationOccurrenceRef(input.workspaceDir, entry.activationId);
95
+ if (!activationRef) {
96
+ input.warn(`[PD:Evidence] workbuddy prompt delivery skipped for activation ${entry.activationId}: occurrence snapshot unresolvable`);
97
+ continue;
98
+ }
99
+ if (entry.artifactId !== undefined && activationRef.artifactId !== entry.artifactId) {
100
+ input.warn(`[PD:Evidence] workbuddy prompt delivery skipped for activation ${entry.activationId}: source artifact does not match occurrence`);
101
+ continue;
102
+ }
103
+ const contentRef = existing?.contentRef ?? ingress.resolveInterventionContentRef(input.workspaceDir, activationRef, entry.principleId);
104
+ observations.push({
105
+ observationKey,
106
+ sourceLocator,
107
+ kind: 'delivery',
108
+ nativeRefs: {
109
+ hostKind: 'workbuddy',
110
+ sessionId: input.sessionId,
111
+ ...(input.turnId ? { turnId: input.turnId } : {}),
112
+ },
113
+ principleId: entry.principleId,
114
+ contentRef: {
115
+ principleId: entry.principleId,
116
+ ...(activationRef.artifactId ? { artifactId: activationRef.artifactId } : {}),
117
+ ...(contentRef?.payloadDigest ? { payloadDigest: contentRef.payloadDigest } : {}),
118
+ // A stored contentRef is an OBJECT — its truthiness must not upgrade
119
+ // resolution: only a digest-carrying reference counts as resolved.
120
+ resolution: contentRef?.payloadDigest !== undefined ? 'resolved' : 'revision_reference_unresolved',
121
+ },
122
+ activationRef,
123
+ payload: { targetKind: 'agent_context', confirmation: 'submitted', outcome: 'attempted' },
124
+ });
125
+ }
126
+ appendWorkbuddyBatch(input.workspaceDir, observations, input.warn);
127
+ }
128
+ /**
129
+ * Record the enforcement chain for an ATTRIBUTED deny that was successfully
130
+ * encoded to the WorkBuddy stdout channel. The proof boundary is the encoded
131
+ * permissionDecision (probe P02 verified the host honors it by blocking the
132
+ * tool) — PD claims exactly that, nothing broader.
133
+ *
134
+ * Episode identity requires the per-call toolCallId (WorkBuddy call_id).
135
+ * Without it the chain is skipped: a hash fallback would mint an episode
136
+ * with NO native event key, which the normalizer rejects and drops the
137
+ * whole batch.
138
+ */
139
+ export function recordWorkbuddyDenyEvidence(input) {
140
+ if (!input.activationId || !input.principleId)
141
+ return;
142
+ if (!input.toolCallId) {
143
+ input.warn('[PD:Evidence] workbuddy deny chain skipped: no toolCallId — episode identity would lack a native event key');
144
+ return;
145
+ }
146
+ if (!input.evidenceEnabled)
147
+ return;
148
+ const ingress = getInterventionEvidenceIngress();
149
+ const toolKey = input.toolCallId;
150
+ const sessionPart = input.sessionId ?? '-';
151
+ const deliveryKey = `workbuddy|delivery|enforcement|${sessionPart}|${toolKey}|${input.activationId}`;
152
+ const sourceLocator = `workbuddy-pd-hook-event-log:${sessionPart}`;
153
+ const existing = ingress.existingObservationRefs(input.workspaceDir, {
154
+ sourceKind: 'workbuddy_pd_hook_event_log', sourceLocator, observationKey: deliveryKey,
155
+ principleId: input.principleId, activationId: input.activationId,
156
+ });
157
+ const activationRef = existing?.activationRef ?? ingress.resolveActivationOccurrenceRef(input.workspaceDir, input.activationId);
158
+ if (!activationRef) {
159
+ input.warn(`[PD:Evidence] workbuddy deny chain skipped for activation ${input.activationId}: occurrence snapshot unresolvable`);
160
+ return;
161
+ }
162
+ const episodeKey = `workbuddy|episode|${sessionPart}|${toolKey}`;
163
+ const content = existing?.contentRef ?? ingress.resolveInterventionContentRef(input.workspaceDir, activationRef, input.principleId);
164
+ const contentRef = {
165
+ principleId: input.principleId,
166
+ ...(activationRef.artifactId ? { artifactId: activationRef.artifactId } : {}),
167
+ ...(content?.payloadDigest ? { payloadDigest: content.payloadDigest } : {}),
168
+ resolution: content?.payloadDigest !== undefined ? 'resolved' : 'revision_reference_unresolved',
169
+ };
170
+ const observations = [
171
+ {
172
+ observationKey: deliveryKey,
173
+ sourceLocator,
174
+ kind: 'delivery',
175
+ nativeRefs: {
176
+ hostKind: 'workbuddy',
177
+ ...(input.sessionId ? { sessionId: input.sessionId } : {}),
178
+ toolCallId: input.toolCallId,
179
+ toolName: input.toolName,
180
+ },
181
+ principleId: input.principleId,
182
+ contentRef,
183
+ activationRef,
184
+ payload: { targetKind: 'runtime_enforcement', confirmation: 'runtime_loaded', outcome: 'delivered' },
185
+ },
186
+ {
187
+ observationKey: `workbuddy|application|runtime_verified|${sessionPart}|${toolKey}|${input.activationId}`,
188
+ sourceLocator,
189
+ kind: 'application',
190
+ nativeRefs: {
191
+ hostKind: 'workbuddy',
192
+ ...(input.sessionId ? { sessionId: input.sessionId } : {}),
193
+ toolCallId: input.toolCallId,
194
+ toolName: input.toolName,
195
+ },
196
+ principleId: input.principleId,
197
+ activationRef,
198
+ episodeKey,
199
+ payload: { proofMethod: 'runtime_verified', action: 'tool_blocked', enforcementBoundary: 'workbuddy_permission_decision_encoded_p02_verified' },
200
+ },
201
+ {
202
+ observationKey: episodeKey,
203
+ sourceLocator,
204
+ kind: 'behavior_episode',
205
+ nativeRefs: {
206
+ hostKind: 'workbuddy',
207
+ ...(input.sessionId ? { sessionId: input.sessionId } : {}),
208
+ toolCallId: input.toolCallId,
209
+ toolName: input.toolName,
210
+ },
211
+ payload: {
212
+ status: 'closed',
213
+ actionSummary: `${input.toolName} denied by rule ${input.ruleId ?? 'unknown'}`,
214
+ resultSummary: 'deny encoded to WorkBuddy permission decision (P02 verified blocking)',
215
+ },
216
+ },
217
+ {
218
+ observationKey: `workbuddy|effect|${sessionPart}|${toolKey}|${input.activationId}`,
219
+ sourceLocator,
220
+ kind: 'effect',
221
+ nativeRefs: {
222
+ hostKind: 'workbuddy',
223
+ ...(input.sessionId ? { sessionId: input.sessionId } : {}),
224
+ toolCallId: input.toolCallId,
225
+ toolName: input.toolName,
226
+ },
227
+ principleId: input.principleId,
228
+ episodeKey,
229
+ contentRef,
230
+ activationRef,
231
+ payload: {
232
+ status: 'observed',
233
+ observationSummary: `rule ${input.ruleId ?? 'unknown'} denied ${input.toolName}`,
234
+ },
235
+ },
236
+ ];
237
+ appendWorkbuddyBatch(input.workspaceDir, observations, input.warn);
238
+ }
@@ -0,0 +1,41 @@
1
+ import { type AdmitBareHostPainsResult, type InternalizationConsumerCycleOutcome, type ConsumerCycleLogger, type ReconcileGovernanceContinuationResult } from '@principles/host-runtime';
2
+ export type WorkbuddyWorkerMode = 'ready' | 'manual_action_required' | 'paused' | 'degraded';
3
+ export interface WorkbuddyWorkerCycleStepReport {
4
+ readonly reconcile: ReconcileGovernanceContinuationResult;
5
+ /**
6
+ * Bare-pain admission sweep (review R2/P1): the WorkBuddy hook writes bare
7
+ * failure pains with no inline admission, so the worker admits them into the
8
+ * shared governance queue before the diagnostician step.
9
+ */
10
+ readonly admission: AdmitBareHostPainsResult;
11
+ /** At most ONE diagnostician execution per cycle (bounded work). */
12
+ readonly diagnostician: {
13
+ readonly taskId: string;
14
+ readonly status: 'succeeded' | 'failed' | 'retried' | 'skipped' | 'degraded';
15
+ readonly message?: string;
16
+ readonly errorCategory?: string;
17
+ readonly nextAction?: string;
18
+ } | null;
19
+ readonly downstream: InternalizationConsumerCycleOutcome | null;
20
+ }
21
+ export interface WorkbuddyWorkerCycleResult {
22
+ readonly workspaceDir: string;
23
+ readonly mode: WorkbuddyWorkerMode;
24
+ readonly reason?: string;
25
+ readonly nextAction?: string;
26
+ readonly report?: WorkbuddyWorkerCycleStepReport;
27
+ }
28
+ export interface WorkbuddyWorkerCycleOptions {
29
+ readonly workspaceDir: string;
30
+ readonly now?: Date;
31
+ readonly logger?: ConsumerCycleLogger;
32
+ readonly emitEvent?: (event: string, payloadJson: string) => void;
33
+ /** Cap on diagnostician candidates inspected per cycle (default 5). */
34
+ readonly diagnosticianCandidateLimit?: number;
35
+ }
36
+ /**
37
+ * Run ONE bounded worker cycle for a canonical governance workspace. Never
38
+ * throws: every failure becomes a structured degraded result with a
39
+ * nextAction.
40
+ */
41
+ export declare function runWorkbuddyWorkspaceWorkerCycle(options: WorkbuddyWorkerCycleOptions): Promise<WorkbuddyWorkerCycleResult>;
@@ -0,0 +1,219 @@
1
+ /**
2
+ * WorkBuddy Workspace worker cycle (SPEC workbuddy-host-adapter §5 Part 5;
3
+ * ADR-0020 §11.1 shape, third host instance).
4
+ *
5
+ * ONE Workspace-scoped worker cycle with exactly two background
6
+ * responsibilities — the Codex catch-up step is DELIBERATELY ABSENT because
7
+ * the WorkBuddy MVP excludes transcript ingestion (SPEC §1 Excluded; the
8
+ * hook itself is the only evidence producer):
9
+ *
10
+ * 1. run the idempotent reconciliation pass (shared host-runtime authority),
11
+ * then admit the hook's BARE failure pains into the same governance
12
+ * queue (review R2/P1 — no inline admission exists on this host; the
13
+ * sweep reuses the ONE admission table and the crash-safe task ensure)
14
+ * 2. lease + run one Diagnostician execution, then ONE bounded downstream
15
+ * consumer cycle through the SHARED host-neutral executor
16
+ * (internalization_auto_consumer = workspace execution authority)
17
+ *
18
+ * Every step reuses existing authority: reconciliation reuses
19
+ * `reconcileGovernanceContinuation`, the diagnostician reuses the
20
+ * PainSignalBridge lease/runner contract, downstream reuses the same
21
+ * `runInternalizationConsumerCycle` the OpenClaw auto-consumer and the Codex
22
+ * worker run. No new task store, no private retry queue, no second
23
+ * scheduler state — and no Codex flag, path or transcript semantics are
24
+ * borrowed (SPEC §5: 不借用 Codex flag/日志伪装归因).
25
+ *
26
+ * Correctness under concurrent consumers (Companion-spawned `pd workbuddy
27
+ * worker` + manual `pd runtime internalization run-once`) is owned by the
28
+ * durable Runtime V2 task lease — never by process-local state. The
29
+ * governance workspace is the single canonical directory
30
+ * (`~/.workbuddy/pd-workspace`), so two projects never double-schedule:
31
+ * they share one workspace and the lease serialises consumption.
32
+ */
33
+ import fs from 'node:fs';
34
+ import path from 'node:path';
35
+ import { computeFeatureFlagsFromConfig, createRuntimeStateHandle, createPainSignalBridge, isRetryWaitBackoffElapsed, PrincipleTreeLedgerAdapter, resolveDiagnosticianCapability, } from '@principles/core/runtime-v2';
36
+ import { admitBareHostPains, loadPdConfigForPlugin, loadFeatureFlagFromConfig, reconcileGovernanceContinuation, runInternalizationConsumerCycle, saveHostToolDeclaration, } from '@principles/host-runtime';
37
+ import { WORKBUDDY_TOOL_SEMANTICS, WORKBUDDY_TOOL_SEMANTIC_MAPPINGS } from '../tool-semantics.js';
38
+ const WORKER_OWNER = 'companion-worker';
39
+ const DEFAULT_DIAG_CANDIDATE_LIMIT = 5;
40
+ function workerLogger(logger) {
41
+ return logger ?? {
42
+ info: () => undefined,
43
+ warn: () => undefined,
44
+ error: () => undefined,
45
+ };
46
+ }
47
+ function directoryExists(dir) {
48
+ try {
49
+ return fs.statSync(dir).isDirectory();
50
+ }
51
+ catch {
52
+ return false;
53
+ }
54
+ }
55
+ /**
56
+ * Oldest pending diagnostician first; retry_wait candidates are filtered to
57
+ * those whose backoff window has ELAPSED (same discipline as the Codex
58
+ * worker — an old-but-waiting task cannot starve a younger eligible one).
59
+ */
60
+ async function pickDiagnosticianCandidate(stateManager, limit) {
61
+ const pending = await stateManager.listTasks({ taskKind: 'diagnostician', status: 'pending', orderBy: 'updated_at_asc', limit });
62
+ const [first] = pending;
63
+ if (first !== undefined)
64
+ return first;
65
+ const retrying = await stateManager.listTasks({ taskKind: 'diagnostician', status: 'retry_wait', orderBy: 'updated_at_asc', limit });
66
+ for (const candidate of retrying) {
67
+ if (isRetryWaitBackoffElapsed(candidate.status, candidate.leaseExpiresAt)) {
68
+ return candidate;
69
+ }
70
+ }
71
+ return null;
72
+ }
73
+ /**
74
+ * Run ONE bounded worker cycle for a canonical governance workspace. Never
75
+ * throws: every failure becomes a structured degraded result with a
76
+ * nextAction.
77
+ */
78
+ export async function runWorkbuddyWorkspaceWorkerCycle(options) {
79
+ const workspaceDir = path.resolve(options.workspaceDir);
80
+ const logger = workerLogger(options.logger);
81
+ const emitEvent = options.emitEvent ?? ((_event, _payload) => undefined);
82
+ const base = { workspaceDir };
83
+ // Step 1 — Workspace eligibility.
84
+ if (!directoryExists(workspaceDir)) {
85
+ return { ...base, mode: 'degraded', reason: 'workspace_missing', nextAction: 'The governance workspace directory no longer exists; run the WorkBuddy setup flow to re-initialize it. No PD state was mutated.' };
86
+ }
87
+ const config = loadPdConfigForPlugin(workspaceDir);
88
+ if (!config.ok) {
89
+ const [first] = config.errors;
90
+ return { ...base, mode: 'degraded', reason: `pd_config_invalid:${first?.reason ?? 'unknown'}`, nextAction: first?.nextAction ?? 'Repair the governance workspace .pd/config.yaml.' };
91
+ }
92
+ const { flags } = computeFeatureFlagsFromConfig(config.effective);
93
+ if (flags['host.workbuddy']?.enabled !== true) {
94
+ return { ...base, mode: 'paused', reason: 'host.workbuddy_disabled', nextAction: 'Set features.host.workbuddy.enabled=true in the governance workspace .pd/config.yaml to enable WorkBuddy PD behavior.' };
95
+ }
96
+ const consumerFlag = loadFeatureFlagFromConfig(workspaceDir, 'internalization_auto_consumer', { info: (m) => logger.info(m), warn: (m) => logger.warn(m) });
97
+ // The Diagnostician capability gate resolves from the same canonical
98
+ // authority as the runtime factory. An Owner-disabled agent is an
99
+ // intentional governance state: no candidate picking, no provider calls,
100
+ // no degraded mode; reconciliation and downstream keep running.
101
+ const capability = resolveDiagnosticianCapability(config.effective);
102
+ const diagnosticianDisabled = !capability.available;
103
+ // Step 2 — Idempotent reconciliation (always runs; creates no LLM work).
104
+ const reconcile = await reconcileGovernanceContinuation({ workspaceDir });
105
+ // Step 2b — Bare-pain admission (review R2/P1): the hook leaves bare
106
+ // workbuddy failure pains that no inline admission exists for. Without this
107
+ // sweep the evidence rows never reach the diagnostician queue. Runs AFTER
108
+ // reconcile (which continues already-admitted markers) and ensures tasks
109
+ // through the same crash-safe seam; bounded and idempotent.
110
+ const admission = await admitBareHostPains({ workspaceDir, hostKind: 'workbuddy' });
111
+ // Steps 3–5 — execution authority: internalization_auto_consumer.
112
+ let diagnostician = null;
113
+ if (diagnosticianDisabled) {
114
+ diagnostician = {
115
+ taskId: '',
116
+ status: 'skipped',
117
+ message: 'capability_disabled',
118
+ nextAction: capability.available ? undefined : capability.nextAction,
119
+ };
120
+ }
121
+ else if (!consumerFlag.enabled) {
122
+ return {
123
+ ...base,
124
+ mode: 'paused',
125
+ reason: 'internalization_auto_consumer_disabled',
126
+ nextAction: 'Automatic internalization execution is paused for this governance workspace; manual commands remain available: pd diagnose, pd runtime internalization run-once.',
127
+ report: { reconcile, admission, diagnostician: null, downstream: null },
128
+ };
129
+ }
130
+ else {
131
+ try {
132
+ const handle = await createRuntimeStateHandle({ workspaceDir, readonly: false });
133
+ try {
134
+ const sweep = await handle.stateManager.runRecoverySweep();
135
+ if (sweep.recovered > 0 || sweep.errors.length > 0) {
136
+ emitEvent('WORKBUDDY_WORKER_RECOVERY_SWEEP', JSON.stringify({ recovered: sweep.recovered, failed: sweep.errors.length }));
137
+ }
138
+ const candidate = await pickDiagnosticianCandidate(handle.stateManager, options.diagnosticianCandidateLimit ?? DEFAULT_DIAG_CANDIDATE_LIMIT);
139
+ if (candidate !== null) {
140
+ const stateDir = path.join(workspaceDir, '.state');
141
+ const bridge = await createPainSignalBridge({
142
+ workspaceDir,
143
+ stateDir,
144
+ ledgerAdapter: new PrincipleTreeLedgerAdapter({ stateDir }),
145
+ owner: WORKER_OWNER,
146
+ effectiveConfig: config.effective,
147
+ getEnvVar: (name) => process.env[name],
148
+ });
149
+ const executed = await bridge.executePendingDiagnosis({ taskId: candidate.taskId });
150
+ diagnostician = {
151
+ taskId: candidate.taskId,
152
+ status: executed.status,
153
+ ...(executed.message !== undefined ? { message: executed.message.slice(0, 200) } : {}),
154
+ ...(executed.errorCategory !== undefined ? { errorCategory: executed.errorCategory } : {}),
155
+ };
156
+ }
157
+ else {
158
+ const waiting = await handle.stateManager.listTasks({ taskKind: 'diagnostician', status: 'retry_wait', orderBy: 'updated_at_asc', limit: 1 });
159
+ const [oldestWaiting] = waiting;
160
+ if (oldestWaiting !== undefined && !isRetryWaitBackoffElapsed(oldestWaiting.status, oldestWaiting.leaseExpiresAt)) {
161
+ diagnostician = { taskId: oldestWaiting.taskId, status: 'skipped', message: 'retry_wait_pending' };
162
+ }
163
+ }
164
+ }
165
+ finally {
166
+ await handle.close().catch(() => undefined);
167
+ }
168
+ }
169
+ catch (error) {
170
+ const detail = error instanceof Error ? error.message.slice(0, 200) : String(error).slice(0, 200);
171
+ return {
172
+ ...base,
173
+ mode: 'degraded',
174
+ reason: `diagnostician_execution_failed:${detail}`,
175
+ nextAction: 'Inspect the governance workspace runtime profile and provider configuration; the task keeps its pending/retry state and no evidence was mutated.',
176
+ report: { reconcile, admission, diagnostician: null, downstream: null },
177
+ };
178
+ }
179
+ }
180
+ // Step 6 — ONE bounded downstream consumer cycle via the shared executor,
181
+ // with the WorkBuddy host declaration (probe-verified tool names: Read /
182
+ // Write / Edit / Bash are capitalized) persisted for host-neutral consumers.
183
+ const declared = saveHostToolDeclaration(workspaceDir, {
184
+ version: 1,
185
+ hostKind: 'workbuddy',
186
+ mappings: WORKBUDDY_TOOL_SEMANTIC_MAPPINGS,
187
+ declaredAt: new Date().toISOString(),
188
+ });
189
+ if (!declared.ok) {
190
+ logger.warn?.(`[PD:WorkbuddyWorker] Failed to persist WorkBuddy tool declaration: ${declared.reason} — host-neutral consumers will not find it (rc-9)`);
191
+ return {
192
+ ...base,
193
+ mode: 'degraded',
194
+ reason: `host_tool_declaration_persist_failed:${declared.reason}`,
195
+ nextAction: 'Repair WorkBuddy host declaration persistence (.pd/host-tool-semantics/workbuddy.json) before running the downstream internalization cycle; the worker retries automatically on the next cycle.',
196
+ report: { reconcile, admission, diagnostician, downstream: null },
197
+ };
198
+ }
199
+ const downstream = await runInternalizationConsumerCycle(workspaceDir, {
200
+ owner: WORKER_OWNER,
201
+ logLabel: 'WorkbuddyWorker',
202
+ logger,
203
+ emitEvent,
204
+ toolSemantics: WORKBUDDY_TOOL_SEMANTICS,
205
+ hostKinds: ['workbuddy'],
206
+ });
207
+ const degradedReason = !reconcile.ok ? `reconcile:${reconcile.reason ?? 'failed'}`
208
+ : !admission.ok ? `admission:${admission.reason ?? 'failed'}`
209
+ : diagnostician?.status === 'failed' && diagnostician.errorCategory !== 'lease_conflict' ? `diagnostician_failed:${diagnostician.message ?? 'max_attempts_exceeded'}`
210
+ : diagnostician?.status === 'degraded' ? `diagnostician_degraded:${diagnostician.message ?? 'unknown'}`
211
+ : downstream.skipReason === 'runtime_config_error' || downstream.skipReason === 'cycle_error' || downstream.skipReason === 'config_malformed' ? `downstream:${downstream.skipReason}`
212
+ : undefined;
213
+ return {
214
+ ...base,
215
+ mode: degradedReason !== undefined ? 'degraded' : 'ready',
216
+ ...(degradedReason !== undefined ? { reason: degradedReason, nextAction: 'Inspect the governance workspace .pd/config.yaml runtime profile and the per-step report above; the worker retries automatically on the next cycle.' } : {}),
217
+ report: { reconcile, admission, diagnostician, downstream },
218
+ };
219
+ }
@@ -0,0 +1,15 @@
1
+ export type WorkbuddyWorkspaceResolution = {
2
+ status: 'ok';
3
+ workspaceDir: string;
4
+ } | {
5
+ status: 'uninitialized';
6
+ workspaceDir: string;
7
+ reason: 'workbuddy_workspace_not_initialized';
8
+ nextAction: string;
9
+ } | {
10
+ status: 'degraded';
11
+ workspaceDir: string;
12
+ reason: 'workbuddy_workspace_config_invalid' | 'workbuddy_workspace_config_unreadable';
13
+ nextAction: string;
14
+ };
15
+ export declare function resolveWorkbuddyWorkspace(homeDir: string): WorkbuddyWorkspaceResolution;
@@ -0,0 +1,53 @@
1
+ /**
2
+ * WorkBuddy governance workspace resolution (SPEC §4.1 / OD-07, frozen by
3
+ * Phase 0 probe P06 2026-10-12).
4
+ *
5
+ * One explicit user-level governance directory shared across projects:
6
+ * getWorkbuddyWorkspaceDir(homeDir) = <home>/.workbuddy/pd-workspace
7
+ * (the SSoT lives in @principles/install-layout — this module only consumes
8
+ * it). projectDir (the host cwd) stays separate and is used solely for tool
9
+ * path judgment by the shared gate.
10
+ *
11
+ * P06 semantics frozen here:
12
+ * - UNINITIALIZED (the governance config does not exist) is a normal,
13
+ * actionable state: report the setup action, never fall back to another
14
+ * host's database and never auto-create;
15
+ * - BAD CONFIG (config path exists but is not a readable regular file) is a
16
+ * DEGRADED state: report and stop — no silent switch to another library.
17
+ */
18
+ import { statSync } from 'node:fs';
19
+ import path from 'node:path';
20
+ import { getWorkbuddyWorkspaceDir } from '@principles/install-layout';
21
+ export function resolveWorkbuddyWorkspace(homeDir) {
22
+ const workspaceDir = getWorkbuddyWorkspaceDir(homeDir);
23
+ const configPath = path.join(workspaceDir, '.pd', 'config.yaml');
24
+ let stat;
25
+ try {
26
+ stat = statSync(configPath);
27
+ }
28
+ catch (error) {
29
+ if (error instanceof Error && Object.hasOwn(error, 'code') && Reflect.get(error, 'code') === 'ENOENT') {
30
+ return {
31
+ status: 'uninitialized',
32
+ workspaceDir,
33
+ reason: 'workbuddy_workspace_not_initialized',
34
+ nextAction: `Run the PD WorkBuddy setup to initialize ${workspaceDir} (no other host's database is ever reused).`,
35
+ };
36
+ }
37
+ return {
38
+ status: 'degraded',
39
+ workspaceDir,
40
+ reason: 'workbuddy_workspace_config_unreadable',
41
+ nextAction: `Restore read access to ${configPath}; PD will not fall back to another workspace while it is unreadable.`,
42
+ };
43
+ }
44
+ if (!stat.isFile()) {
45
+ return {
46
+ status: 'degraded',
47
+ workspaceDir,
48
+ reason: 'workbuddy_workspace_config_invalid',
49
+ nextAction: `Repair ${configPath} (expected a regular config file); PD will not fall back to another workspace.`,
50
+ };
51
+ }
52
+ return { status: 'ok', workspaceDir };
53
+ }
@@ -0,0 +1,64 @@
1
+ {
2
+ "name": "@principles/workbuddy-adapter",
3
+ "version": "0.2.1",
4
+ "description": "WorkBuddy host adapter for Principles Disciple — implements the HostAdapter interface for WorkBuddy's Git Bash command-hook model (ADR-0020 third host, SPEC workbuddy-host-adapter v0.3.0).",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "default": "./dist/index.js"
12
+ },
13
+ "./pd-hook": {
14
+ "types": "./dist/pd-hook.d.ts",
15
+ "default": "./dist/pd-hook.js"
16
+ },
17
+ "./host-adapter": {
18
+ "types": "./dist/host-adapter.d.ts",
19
+ "default": "./dist/host-adapter.js"
20
+ },
21
+ "./workspace-resolution": {
22
+ "types": "./dist/workspace-resolution.d.ts",
23
+ "default": "./dist/workspace-resolution.js"
24
+ },
25
+ "./tool-semantics": {
26
+ "types": "./dist/tool-semantics.d.ts",
27
+ "default": "./dist/tool-semantics.js"
28
+ },
29
+ "./package.json": "./package.json"
30
+ },
31
+ "files": [
32
+ "dist",
33
+ "plugin",
34
+ "README.md",
35
+ "LICENSE",
36
+ "NOTICE"
37
+ ],
38
+ "scripts": {
39
+ "build": "tsc",
40
+ "test": "npm run build && vitest run",
41
+ "test:coverage": "vitest run --coverage",
42
+ "lint": "eslint \"src/**/*.ts\""
43
+ },
44
+ "dependencies": {
45
+ "@principles/core": "file:../core",
46
+ "@principles/host-runtime": "file:../host-runtime",
47
+ "@principles/install-layout": "file:../install-layout"
48
+ },
49
+ "devDependencies": {
50
+ "@types/node": "^26.4.1",
51
+ "typescript": "^7.0.2",
52
+ "vite": "^8.3.0",
53
+ "vitest": "^5.0.0"
54
+ },
55
+ "license": "Apache-2.0",
56
+ "repository": {
57
+ "type": "git",
58
+ "url": "git+https://github.com/csuzngjh/principles.git",
59
+ "directory": "packages/workbuddy-adapter"
60
+ },
61
+ "publishConfig": {
62
+ "access": "public"
63
+ }
64
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "name": "principles-disciple",
3
+ "version": "0.1.0",
4
+ "description": "Principles Disciple — Owner-governed behavior internalization for AI agents (WorkBuddy host adapter, ADR-0020 third host). Requires explicit setup and host.workbuddy feature enablement; inactive until then.",
5
+ "defaultEnabled": false
6
+ }