create-principles-disciple 1.154.4 → 1.155.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 (409) hide show
  1. package/_release/product-identity.json +2 -2
  2. package/codex-adapter/dist/codec/input-decoder.d.ts +17 -0
  3. package/codex-adapter/dist/codec/input-decoder.js +39 -0
  4. package/codex-adapter/dist/ingestion/explicit-owner-statement.js +125 -1
  5. package/codex-adapter/dist/ingestion/pain-receipt-fallback.d.ts +46 -0
  6. package/codex-adapter/dist/ingestion/pain-receipt-fallback.js +193 -0
  7. package/codex-adapter/dist/ingestion/turn-context.d.ts +10 -15
  8. package/codex-adapter/dist/ingestion/turn-context.js +35 -9
  9. package/codex-adapter/dist/pd-hook.js +57 -1
  10. package/codex-adapter/dist/worker/workspace-worker.d.ts +15 -0
  11. package/codex-adapter/dist/worker/workspace-worker.js +91 -12
  12. package/codex-adapter/package.json +1 -1
  13. package/console/dist/server/index.js +10 -0
  14. package/console/dist/server/models/EvidenceChainConsoleModel.js +31 -0
  15. package/console/dist/server/routes/service-host.d.ts +19 -0
  16. package/console/dist/server/routes/service-host.js +129 -0
  17. package/console/dist/web/assets/app.js +37 -37
  18. package/core/dist/runtime/context-payload.d.ts +48 -0
  19. package/core/dist/runtime/context-payload.d.ts.map +1 -1
  20. package/core/dist/runtime/context-payload.js +12 -0
  21. package/core/dist/runtime/context-payload.js.map +1 -1
  22. package/core/dist/runtime/diagnostician/rootcause-prompt-builder.d.ts.map +1 -1
  23. package/core/dist/runtime/diagnostician/rootcause-prompt-builder.js +18 -0
  24. package/core/dist/runtime/diagnostician/rootcause-prompt-builder.js.map +1 -1
  25. package/core/dist/runtime/diagnostician-candidate.d.ts.map +1 -1
  26. package/core/dist/runtime/diagnostician-candidate.js +18 -2
  27. package/core/dist/runtime/diagnostician-candidate.js.map +1 -1
  28. package/core/dist/runtime/evidence-guards.d.ts +7 -3
  29. package/core/dist/runtime/evidence-guards.d.ts.map +1 -1
  30. package/core/dist/runtime/evidence-guards.js +9 -7
  31. package/core/dist/runtime/evidence-guards.js.map +1 -1
  32. package/core/dist/runtime/feature-flags/feature-flag-contract.d.ts.map +1 -1
  33. package/core/dist/runtime/feature-flags/feature-flag-contract.js +14 -0
  34. package/core/dist/runtime/feature-flags/feature-flag-contract.js.map +1 -1
  35. package/core/dist/runtime/feature-flags/feature-flag-lifecycle.d.ts.map +1 -1
  36. package/core/dist/runtime/feature-flags/feature-flag-lifecycle.js +8 -0
  37. package/core/dist/runtime/feature-flags/feature-flag-lifecycle.js.map +1 -1
  38. package/core/dist/runtime/host-submission-context.d.ts +83 -0
  39. package/core/dist/runtime/host-submission-context.d.ts.map +1 -0
  40. package/core/dist/runtime/host-submission-context.js +183 -0
  41. package/core/dist/runtime/host-submission-context.js.map +1 -0
  42. package/core/dist/runtime/index.d.ts +9 -2
  43. package/core/dist/runtime/index.d.ts.map +1 -1
  44. package/core/dist/runtime/index.js +29 -2
  45. package/core/dist/runtime/index.js.map +1 -1
  46. package/core/dist/runtime/intent/intent-doc.d.ts.map +1 -1
  47. package/core/dist/runtime/intent/intent-doc.js +29 -5
  48. package/core/dist/runtime/intent/intent-doc.js.map +1 -1
  49. package/core/dist/runtime/internalization/diag-distiller-runner.d.ts +9 -0
  50. package/core/dist/runtime/internalization/diag-distiller-runner.d.ts.map +1 -1
  51. package/core/dist/runtime/internalization/diag-distiller-runner.js +13 -0
  52. package/core/dist/runtime/internalization/diag-distiller-runner.js.map +1 -1
  53. package/core/dist/runtime/internalization/diag-rootcause-runner.d.ts +11 -0
  54. package/core/dist/runtime/internalization/diag-rootcause-runner.d.ts.map +1 -1
  55. package/core/dist/runtime/internalization/diag-rootcause-runner.js +10 -0
  56. package/core/dist/runtime/internalization/diag-rootcause-runner.js.map +1 -1
  57. package/core/dist/runtime/internalization/diag-router-runner.d.ts +9 -0
  58. package/core/dist/runtime/internalization/diag-router-runner.d.ts.map +1 -1
  59. package/core/dist/runtime/internalization/diag-router-runner.js +13 -0
  60. package/core/dist/runtime/internalization/diag-router-runner.js.map +1 -1
  61. package/core/dist/runtime/internalization/index.d.ts +1 -1
  62. package/core/dist/runtime/internalization/index.d.ts.map +1 -1
  63. package/core/dist/runtime/internalization/index.js +1 -1
  64. package/core/dist/runtime/internalization/index.js.map +1 -1
  65. package/core/dist/runtime/internalization/intake-to-internalization-bridge.d.ts +19 -0
  66. package/core/dist/runtime/internalization/intake-to-internalization-bridge.d.ts.map +1 -1
  67. package/core/dist/runtime/internalization/intake-to-internalization-bridge.js +24 -0
  68. package/core/dist/runtime/internalization/intake-to-internalization-bridge.js.map +1 -1
  69. package/core/dist/runtime/internalization/internalization-orchestrator.d.ts +8 -0
  70. package/core/dist/runtime/internalization/internalization-orchestrator.d.ts.map +1 -1
  71. package/core/dist/runtime/internalization/internalization-orchestrator.js +36 -4
  72. package/core/dist/runtime/internalization/internalization-orchestrator.js.map +1 -1
  73. package/core/dist/runtime/internalization/source-authorization-boundary.d.ts +39 -0
  74. package/core/dist/runtime/internalization/source-authorization-boundary.d.ts.map +1 -0
  75. package/core/dist/runtime/internalization/source-authorization-boundary.js +57 -0
  76. package/core/dist/runtime/internalization/source-authorization-boundary.js.map +1 -0
  77. package/core/dist/runtime/internalization/split-diagnostician-runner.d.ts.map +1 -1
  78. package/core/dist/runtime/internalization/split-diagnostician-runner.js +72 -5
  79. package/core/dist/runtime/internalization/split-diagnostician-runner.js.map +1 -1
  80. package/core/dist/runtime/pain-admission-disposition.d.ts +60 -0
  81. package/core/dist/runtime/pain-admission-disposition.d.ts.map +1 -0
  82. package/core/dist/runtime/pain-admission-disposition.js +37 -0
  83. package/core/dist/runtime/pain-admission-disposition.js.map +1 -0
  84. package/core/dist/runtime/pain-ingress-payload.d.ts +36 -2
  85. package/core/dist/runtime/pain-ingress-payload.d.ts.map +1 -1
  86. package/core/dist/runtime/pain-ingress-payload.js +63 -6
  87. package/core/dist/runtime/pain-ingress-payload.js.map +1 -1
  88. package/core/dist/runtime/pain-ingress.d.ts.map +1 -1
  89. package/core/dist/runtime/pain-ingress.js +28 -0
  90. package/core/dist/runtime/pain-ingress.js.map +1 -1
  91. package/core/dist/runtime/pain-recall-read-model.d.ts +13 -1
  92. package/core/dist/runtime/pain-recall-read-model.d.ts.map +1 -1
  93. package/core/dist/runtime/pain-recall-read-model.js +50 -7
  94. package/core/dist/runtime/pain-recall-read-model.js.map +1 -1
  95. package/core/dist/runtime/pain-receipt-recovery.d.ts +147 -0
  96. package/core/dist/runtime/pain-receipt-recovery.d.ts.map +1 -0
  97. package/core/dist/runtime/pain-receipt-recovery.js +475 -0
  98. package/core/dist/runtime/pain-receipt-recovery.js.map +1 -0
  99. package/core/dist/runtime/pain-signal-bridge.d.ts +13 -1
  100. package/core/dist/runtime/pain-signal-bridge.d.ts.map +1 -1
  101. package/core/dist/runtime/pain-signal-bridge.js +174 -0
  102. package/core/dist/runtime/pain-signal-bridge.js.map +1 -1
  103. package/core/dist/runtime/pain-signal-runtime-factory.d.ts +9 -0
  104. package/core/dist/runtime/pain-signal-runtime-factory.d.ts.map +1 -1
  105. package/core/dist/runtime/pain-signal-runtime-factory.js +8 -3
  106. package/core/dist/runtime/pain-signal-runtime-factory.js.map +1 -1
  107. package/core/dist/runtime/pain-submit-capability.d.ts +11 -0
  108. package/core/dist/runtime/pain-submit-capability.d.ts.map +1 -1
  109. package/core/dist/runtime/pain-submit-capability.js +77 -3
  110. package/core/dist/runtime/pain-submit-capability.js.map +1 -1
  111. package/core/dist/runtime/pain-target-evidence-reconcile.d.ts +55 -0
  112. package/core/dist/runtime/pain-target-evidence-reconcile.d.ts.map +1 -0
  113. package/core/dist/runtime/pain-target-evidence-reconcile.js +164 -0
  114. package/core/dist/runtime/pain-target-evidence-reconcile.js.map +1 -0
  115. package/core/dist/runtime/pain-to-principle-service.d.ts +8 -0
  116. package/core/dist/runtime/pain-to-principle-service.d.ts.map +1 -1
  117. package/core/dist/runtime/pain-to-principle-service.js +1 -0
  118. package/core/dist/runtime/pain-to-principle-service.js.map +1 -1
  119. package/core/dist/runtime/source-material-authorization.d.ts +166 -0
  120. package/core/dist/runtime/source-material-authorization.d.ts.map +1 -0
  121. package/core/dist/runtime/source-material-authorization.js +250 -0
  122. package/core/dist/runtime/source-material-authorization.js.map +1 -0
  123. package/core/dist/runtime/store/context/index.d.ts +1 -0
  124. package/core/dist/runtime/store/context/index.d.ts.map +1 -1
  125. package/core/dist/runtime/store/context/index.js +1 -0
  126. package/core/dist/runtime/store/context/index.js.map +1 -1
  127. package/core/dist/runtime/store/context/promoted-evidence-reader.d.ts +8 -0
  128. package/core/dist/runtime/store/context/promoted-evidence-reader.d.ts.map +1 -1
  129. package/core/dist/runtime/store/context/promoted-evidence-reader.js +15 -1
  130. package/core/dist/runtime/store/context/promoted-evidence-reader.js.map +1 -1
  131. package/core/dist/runtime/store/context/sqlite-context-assembler.d.ts +22 -0
  132. package/core/dist/runtime/store/context/sqlite-context-assembler.d.ts.map +1 -1
  133. package/core/dist/runtime/store/context/sqlite-context-assembler.js +153 -3
  134. package/core/dist/runtime/store/context/sqlite-context-assembler.js.map +1 -1
  135. package/core/dist/runtime/store/context/trajectory-turn-reader.d.ts +13 -0
  136. package/core/dist/runtime/store/context/trajectory-turn-reader.d.ts.map +1 -1
  137. package/core/dist/runtime/store/lifecycle/lease-manager.d.ts +15 -0
  138. package/core/dist/runtime/store/lifecycle/lease-manager.d.ts.map +1 -1
  139. package/core/dist/runtime/store/lifecycle/lease-manager.js +16 -1
  140. package/core/dist/runtime/store/lifecycle/lease-manager.js.map +1 -1
  141. package/core/dist/runtime/store/runtime-state-manager.d.ts +2 -0
  142. package/core/dist/runtime/store/runtime-state-manager.d.ts.map +1 -1
  143. package/core/dist/runtime/store/runtime-state-manager.js.map +1 -1
  144. package/core/dist/runtime/store/task/memory-task-store.d.ts +1 -0
  145. package/core/dist/runtime/store/task/memory-task-store.d.ts.map +1 -1
  146. package/core/dist/runtime/store/task/memory-task-store.js +37 -0
  147. package/core/dist/runtime/store/task/memory-task-store.js.map +1 -1
  148. package/core/dist/runtime/store/task/sqlite-task-store.d.ts +10 -0
  149. package/core/dist/runtime/store/task/sqlite-task-store.d.ts.map +1 -1
  150. package/core/dist/runtime/store/task/sqlite-task-store.js +20 -0
  151. package/core/dist/runtime/store/task/sqlite-task-store.js.map +1 -1
  152. package/core/dist/runtime/store/task/task-store.d.ts +16 -0
  153. package/core/dist/runtime/store/task/task-store.d.ts.map +1 -1
  154. package/core/dist/runtime/task-status.d.ts +13 -0
  155. package/core/dist/runtime/task-status.d.ts.map +1 -1
  156. package/core/dist/runtime/task-status.js +9 -0
  157. package/core/dist/runtime/task-status.js.map +1 -1
  158. package/core/dist/runtime/types/evidence-chain-contract.d.ts +10 -0
  159. package/core/dist/runtime/types/evidence-chain-contract.d.ts.map +1 -1
  160. package/core/dist/runtime/types/evidence-chain-contract.js +7 -0
  161. package/core/dist/runtime/types/evidence-chain-contract.js.map +1 -1
  162. package/core/package.json +1 -1
  163. package/dist/index.d.ts.map +1 -1
  164. package/dist/index.js +11 -0
  165. package/dist/index.js.map +1 -1
  166. package/dist/installer.d.ts.map +1 -1
  167. package/dist/installer.js +77 -30
  168. package/dist/installer.js.map +1 -1
  169. package/dist/installers/mcp-registration-conflict.d.ts +8 -0
  170. package/dist/installers/mcp-registration-conflict.d.ts.map +1 -1
  171. package/dist/installers/mcp-registration-conflict.js +34 -1
  172. package/dist/installers/mcp-registration-conflict.js.map +1 -1
  173. package/dist/installers/workbuddy-host-installer.d.ts +45 -13
  174. package/dist/installers/workbuddy-host-installer.d.ts.map +1 -1
  175. package/dist/installers/workbuddy-host-installer.js +284 -21
  176. package/dist/installers/workbuddy-host-installer.js.map +1 -1
  177. package/dist/prompts.d.ts +11 -0
  178. package/dist/prompts.d.ts.map +1 -1
  179. package/dist/prompts.js +4 -0
  180. package/dist/prompts.js.map +1 -1
  181. package/dist/service-host-bridge.d.ts +67 -0
  182. package/dist/service-host-bridge.d.ts.map +1 -0
  183. package/dist/service-host-bridge.js +292 -0
  184. package/dist/service-host-bridge.js.map +1 -0
  185. package/dist/uninstaller.d.ts.map +1 -1
  186. package/dist/uninstaller.js +26 -0
  187. package/dist/uninstaller.js.map +1 -1
  188. package/dist/update/install-layout.d.ts +0 -12
  189. package/dist/update/install-layout.d.ts.map +1 -1
  190. package/dist/update/install-layout.js +42 -15
  191. package/dist/update/install-layout.js.map +1 -1
  192. package/host-runtime/dist/diagnostician-auto-run.js +4 -1
  193. package/host-runtime/dist/governance-observation-store.d.ts +7 -0
  194. package/host-runtime/dist/governance-observation-store.js +15 -4
  195. package/host-runtime/dist/governance-signal-admission.d.ts +49 -0
  196. package/host-runtime/dist/governance-signal-admission.js +355 -94
  197. package/host-runtime/dist/governance-trajectory-turn-reader.d.ts +20 -4
  198. package/host-runtime/dist/governance-trajectory-turn-reader.js +77 -5
  199. package/host-runtime/dist/index.d.ts +2 -0
  200. package/host-runtime/dist/index.js +5 -0
  201. package/host-runtime/dist/internalization-consumer-cycle.js +4 -1
  202. package/host-runtime/dist/pd-config.d.ts +10 -0
  203. package/host-runtime/dist/pd-config.js +37 -0
  204. package/host-runtime/dist/signal-stage2-cycle.js +28 -1
  205. package/host-runtime/dist/source-material-authorization.d.ts +53 -0
  206. package/host-runtime/dist/source-material-authorization.js +67 -0
  207. package/host-runtime/dist/source-revocation-sweep.d.ts +172 -0
  208. package/host-runtime/dist/source-revocation-sweep.js +928 -0
  209. package/host-runtime/package.json +5 -1
  210. package/install-layout/dist/background-execution-transition.d.ts +258 -0
  211. package/install-layout/dist/background-execution-transition.js +836 -0
  212. package/install-layout/dist/index.d.ts +8 -0
  213. package/install-layout/dist/index.js +8 -0
  214. package/install-layout/package.json +6 -2
  215. package/package.json +4 -4
  216. package/pd-cli/dist/commands/candidate.d.ts.map +1 -1
  217. package/pd-cli/dist/commands/candidate.js +16 -5
  218. package/pd-cli/dist/commands/candidate.js.map +1 -1
  219. package/pd-cli/dist/commands/codex-setup.d.ts.map +1 -1
  220. package/pd-cli/dist/commands/codex-setup.js +17 -1
  221. package/pd-cli/dist/commands/codex-setup.js.map +1 -1
  222. package/pd-cli/dist/commands/codex-worker.d.ts.map +1 -1
  223. package/pd-cli/dist/commands/codex-worker.js +8 -4
  224. package/pd-cli/dist/commands/codex-worker.js.map +1 -1
  225. package/pd-cli/dist/commands/consent-sweep-revoked.d.ts +20 -0
  226. package/pd-cli/dist/commands/consent-sweep-revoked.d.ts.map +1 -0
  227. package/pd-cli/dist/commands/consent-sweep-revoked.js +85 -0
  228. package/pd-cli/dist/commands/consent-sweep-revoked.js.map +1 -0
  229. package/pd-cli/dist/commands/context.d.ts.map +1 -1
  230. package/pd-cli/dist/commands/context.js +9 -1
  231. package/pd-cli/dist/commands/context.js.map +1 -1
  232. package/pd-cli/dist/commands/diagnose.d.ts.map +1 -1
  233. package/pd-cli/dist/commands/diagnose.js +12 -6
  234. package/pd-cli/dist/commands/diagnose.js.map +1 -1
  235. package/pd-cli/dist/commands/openclaw-worker.d.ts +11 -0
  236. package/pd-cli/dist/commands/openclaw-worker.d.ts.map +1 -0
  237. package/pd-cli/dist/commands/openclaw-worker.js +199 -0
  238. package/pd-cli/dist/commands/openclaw-worker.js.map +1 -0
  239. package/pd-cli/dist/commands/pain-explicit.d.ts.map +1 -1
  240. package/pd-cli/dist/commands/pain-explicit.js +1 -0
  241. package/pd-cli/dist/commands/pain-explicit.js.map +1 -1
  242. package/pd-cli/dist/commands/pain-recall.d.ts +2 -2
  243. package/pd-cli/dist/commands/pain-recall.d.ts.map +1 -1
  244. package/pd-cli/dist/commands/pain-recall.js +7 -1
  245. package/pd-cli/dist/commands/pain-recall.js.map +1 -1
  246. package/pd-cli/dist/commands/pain-retry.d.ts.map +1 -1
  247. package/pd-cli/dist/commands/pain-retry.js +12 -6
  248. package/pd-cli/dist/commands/pain-retry.js.map +1 -1
  249. package/pd-cli/dist/commands/runtime-internalization-enqueue-successors.d.ts.map +1 -1
  250. package/pd-cli/dist/commands/runtime-internalization-enqueue-successors.js +2 -1
  251. package/pd-cli/dist/commands/runtime-internalization-enqueue-successors.js.map +1 -1
  252. package/pd-cli/dist/commands/runtime-internalization-run-once.d.ts +1 -0
  253. package/pd-cli/dist/commands/runtime-internalization-run-once.d.ts.map +1 -1
  254. package/pd-cli/dist/commands/runtime-internalization-run-once.js +32 -8
  255. package/pd-cli/dist/commands/runtime-internalization-run-once.js.map +1 -1
  256. package/pd-cli/dist/commands/runtime-internalization-wake-once.d.ts.map +1 -1
  257. package/pd-cli/dist/commands/runtime-internalization-wake-once.js +2 -1
  258. package/pd-cli/dist/commands/runtime-internalization-wake-once.js.map +1 -1
  259. package/pd-cli/dist/commands/service-handover.d.ts +12 -0
  260. package/pd-cli/dist/commands/service-handover.d.ts.map +1 -0
  261. package/pd-cli/dist/commands/service-handover.js +117 -0
  262. package/pd-cli/dist/commands/service-handover.js.map +1 -0
  263. package/pd-cli/dist/commands/service-lifecycle.d.ts +31 -0
  264. package/pd-cli/dist/commands/service-lifecycle.d.ts.map +1 -0
  265. package/pd-cli/dist/commands/service-lifecycle.js +207 -0
  266. package/pd-cli/dist/commands/service-lifecycle.js.map +1 -0
  267. package/pd-cli/dist/commands/service-run-once.d.ts +96 -0
  268. package/pd-cli/dist/commands/service-run-once.d.ts.map +1 -1
  269. package/pd-cli/dist/commands/service-run-once.js +432 -13
  270. package/pd-cli/dist/commands/service-run-once.js.map +1 -1
  271. package/pd-cli/dist/commands/workbuddy-setup.d.ts.map +1 -1
  272. package/pd-cli/dist/commands/workbuddy-setup.js +22 -2
  273. package/pd-cli/dist/commands/workbuddy-setup.js.map +1 -1
  274. package/pd-cli/dist/program.d.ts.map +1 -1
  275. package/pd-cli/dist/program.js +167 -9
  276. package/pd-cli/dist/program.js.map +1 -1
  277. package/pd-cli/dist/services/admission-write-gate.d.ts +3 -1
  278. package/pd-cli/dist/services/admission-write-gate.d.ts.map +1 -1
  279. package/pd-cli/dist/services/admission-write-gate.js +1 -0
  280. package/pd-cli/dist/services/admission-write-gate.js.map +1 -1
  281. package/pd-cli/dist/services/service-host/coordinator-common.d.ts +49 -0
  282. package/pd-cli/dist/services/service-host/coordinator-common.d.ts.map +1 -0
  283. package/pd-cli/dist/services/service-host/coordinator-common.js +158 -0
  284. package/pd-cli/dist/services/service-host/coordinator-common.js.map +1 -0
  285. package/pd-cli/dist/services/service-host/handover-claims.d.ts +14 -0
  286. package/pd-cli/dist/services/service-host/handover-claims.d.ts.map +1 -0
  287. package/pd-cli/dist/services/service-host/handover-claims.js +50 -0
  288. package/pd-cli/dist/services/service-host/handover-claims.js.map +1 -0
  289. package/pd-cli/dist/services/service-host/index.d.ts +19 -3
  290. package/pd-cli/dist/services/service-host/index.d.ts.map +1 -1
  291. package/pd-cli/dist/services/service-host/index.js +21 -3
  292. package/pd-cli/dist/services/service-host/index.js.map +1 -1
  293. package/pd-cli/dist/services/service-host/install-identity.d.ts +23 -3
  294. package/pd-cli/dist/services/service-host/install-identity.d.ts.map +1 -1
  295. package/pd-cli/dist/services/service-host/install-identity.js +15 -5
  296. package/pd-cli/dist/services/service-host/install-identity.js.map +1 -1
  297. package/pd-cli/dist/services/service-host/locking/service-run-lock.d.ts +130 -9
  298. package/pd-cli/dist/services/service-host/locking/service-run-lock.d.ts.map +1 -1
  299. package/pd-cli/dist/services/service-host/locking/service-run-lock.js +99 -19
  300. package/pd-cli/dist/services/service-host/locking/service-run-lock.js.map +1 -1
  301. package/pd-cli/dist/services/service-host/managed-run.d.ts +75 -0
  302. package/pd-cli/dist/services/service-host/managed-run.d.ts.map +1 -0
  303. package/pd-cli/dist/services/service-host/managed-run.js +550 -0
  304. package/pd-cli/dist/services/service-host/managed-run.js.map +1 -0
  305. package/pd-cli/dist/services/service-host/progress-evidence.d.ts +38 -0
  306. package/pd-cli/dist/services/service-host/progress-evidence.d.ts.map +1 -0
  307. package/pd-cli/dist/services/service-host/progress-evidence.js +155 -0
  308. package/pd-cli/dist/services/service-host/progress-evidence.js.map +1 -0
  309. package/pd-cli/dist/services/service-host/run-once.d.ts.map +1 -1
  310. package/pd-cli/dist/services/service-host/run-once.js +4 -136
  311. package/pd-cli/dist/services/service-host/run-once.js.map +1 -1
  312. package/pd-cli/dist/services/service-host/scheduler/contract.d.ts +184 -0
  313. package/pd-cli/dist/services/service-host/scheduler/contract.d.ts.map +1 -0
  314. package/pd-cli/dist/services/service-host/scheduler/contract.js +86 -0
  315. package/pd-cli/dist/services/service-host/scheduler/contract.js.map +1 -0
  316. package/pd-cli/dist/services/service-host/scheduler/index.d.ts +76 -0
  317. package/pd-cli/dist/services/service-host/scheduler/index.d.ts.map +1 -0
  318. package/pd-cli/dist/services/service-host/scheduler/index.js +128 -0
  319. package/pd-cli/dist/services/service-host/scheduler/index.js.map +1 -0
  320. package/pd-cli/dist/services/service-host/scheduler/linux.d.ts +27 -0
  321. package/pd-cli/dist/services/service-host/scheduler/linux.d.ts.map +1 -0
  322. package/pd-cli/dist/services/service-host/scheduler/linux.js +1010 -0
  323. package/pd-cli/dist/services/service-host/scheduler/linux.js.map +1 -0
  324. package/pd-cli/dist/services/service-host/scheduler/macos.d.ts +13 -0
  325. package/pd-cli/dist/services/service-host/scheduler/macos.d.ts.map +1 -0
  326. package/pd-cli/dist/services/service-host/scheduler/macos.js +819 -0
  327. package/pd-cli/dist/services/service-host/scheduler/macos.js.map +1 -0
  328. package/pd-cli/dist/services/service-host/scheduler/runtime-io.d.ts +13 -0
  329. package/pd-cli/dist/services/service-host/scheduler/runtime-io.d.ts.map +1 -0
  330. package/pd-cli/dist/services/service-host/scheduler/runtime-io.js +141 -0
  331. package/pd-cli/dist/services/service-host/scheduler/runtime-io.js.map +1 -0
  332. package/pd-cli/dist/services/service-host/scheduler/service-status.d.ts +99 -0
  333. package/pd-cli/dist/services/service-host/scheduler/service-status.d.ts.map +1 -0
  334. package/pd-cli/dist/services/service-host/scheduler/service-status.js +202 -0
  335. package/pd-cli/dist/services/service-host/scheduler/service-status.js.map +1 -0
  336. package/pd-cli/dist/services/service-host/scheduler/windows.d.ts +40 -0
  337. package/pd-cli/dist/services/service-host/scheduler/windows.d.ts.map +1 -0
  338. package/pd-cli/dist/services/service-host/scheduler/windows.js +688 -0
  339. package/pd-cli/dist/services/service-host/scheduler/windows.js.map +1 -0
  340. package/pd-cli/dist/services/service-host/shadow-progress-store.d.ts +43 -0
  341. package/pd-cli/dist/services/service-host/shadow-progress-store.d.ts.map +1 -0
  342. package/pd-cli/dist/services/service-host/shadow-progress-store.js +156 -0
  343. package/pd-cli/dist/services/service-host/shadow-progress-store.js.map +1 -0
  344. package/pd-cli/dist/services/service-host/shadow-run.d.ts +87 -0
  345. package/pd-cli/dist/services/service-host/shadow-run.d.ts.map +1 -0
  346. package/pd-cli/dist/services/service-host/shadow-run.js +549 -0
  347. package/pd-cli/dist/services/service-host/shadow-run.js.map +1 -0
  348. package/pd-cli/dist/services/service-host/status/service-run-status.d.ts +114 -4
  349. package/pd-cli/dist/services/service-host/status/service-run-status.d.ts.map +1 -1
  350. package/pd-cli/dist/services/service-host/status/service-run-status.js +37 -0
  351. package/pd-cli/dist/services/service-host/status/service-run-status.js.map +1 -1
  352. package/pd-cli/dist/services/service-host/worker-adapter-codex.d.ts +2 -0
  353. package/pd-cli/dist/services/service-host/worker-adapter-codex.d.ts.map +1 -0
  354. package/pd-cli/dist/services/service-host/worker-adapter-codex.js +76 -0
  355. package/pd-cli/dist/services/service-host/worker-adapter-codex.js.map +1 -0
  356. package/pd-cli/dist/services/service-host/worker-adapter-openclaw.d.ts +2 -0
  357. package/pd-cli/dist/services/service-host/worker-adapter-openclaw.d.ts.map +1 -0
  358. package/pd-cli/dist/services/service-host/worker-adapter-openclaw.js +49 -0
  359. package/pd-cli/dist/services/service-host/worker-adapter-openclaw.js.map +1 -0
  360. package/pd-cli/dist/services/service-host/worker-adapter-workbuddy.d.ts +2 -0
  361. package/pd-cli/dist/services/service-host/worker-adapter-workbuddy.d.ts.map +1 -0
  362. package/pd-cli/dist/services/service-host/worker-adapter-workbuddy.js +36 -0
  363. package/pd-cli/dist/services/service-host/worker-adapter-workbuddy.js.map +1 -0
  364. package/pd-cli/dist/services/service-host/worker-adapter.d.ts +187 -0
  365. package/pd-cli/dist/services/service-host/worker-adapter.d.ts.map +1 -0
  366. package/pd-cli/dist/services/service-host/worker-adapter.js +609 -0
  367. package/pd-cli/dist/services/service-host/worker-adapter.js.map +1 -0
  368. package/pd-cli/dist/services/service-host/worker-env.d.ts +84 -0
  369. package/pd-cli/dist/services/service-host/worker-env.d.ts.map +1 -0
  370. package/pd-cli/dist/services/service-host/worker-env.js +195 -0
  371. package/pd-cli/dist/services/service-host/worker-env.js.map +1 -0
  372. package/pd-cli/dist/services/service-host/worker-process.d.ts +75 -0
  373. package/pd-cli/dist/services/service-host/worker-process.d.ts.map +1 -0
  374. package/pd-cli/dist/services/service-host/worker-process.js +225 -0
  375. package/pd-cli/dist/services/service-host/worker-process.js.map +1 -0
  376. package/pd-cli/dist/services/service-host/workspace-dispatch.d.ts +61 -0
  377. package/pd-cli/dist/services/service-host/workspace-dispatch.d.ts.map +1 -0
  378. package/pd-cli/dist/services/service-host/workspace-dispatch.js +105 -0
  379. package/pd-cli/dist/services/service-host/workspace-dispatch.js.map +1 -0
  380. package/pd-cli/dist/services/service-host/workspace-handover.d.ts +190 -0
  381. package/pd-cli/dist/services/service-host/workspace-handover.d.ts.map +1 -0
  382. package/pd-cli/dist/services/service-host/workspace-handover.js +1393 -0
  383. package/pd-cli/dist/services/service-host/workspace-handover.js.map +1 -0
  384. package/pd-cli/package.json +6 -5
  385. package/pd-mcp-server/dist/submit-assembly.js +159 -42
  386. package/pd-mcp-server/dist/version.d.ts +1 -1
  387. package/pd-mcp-server/dist/version.js +1 -1
  388. package/pd-mcp-server/package.json +1 -1
  389. package/plugin/dist/bundle.js +586 -568
  390. package/plugin/dist/openclaw-worker.d.ts +92 -0
  391. package/plugin/dist/openclaw-worker.js +2439 -0
  392. package/plugin/dist/openclaw.plugin.json +1 -1
  393. package/plugin/dist/service/gateway-consumer-lease.d.ts +142 -0
  394. package/plugin/dist/service/gateway-quiesce-ack.d.ts +40 -0
  395. package/plugin/dist/service/internalization-auto-consumer-service.d.ts +68 -1
  396. package/plugin/openclaw.plugin.json +1 -1
  397. package/plugin/package.json +5 -1
  398. package/release-manager/dist/installer.js +77 -30
  399. package/release-manager/dist/installers/mcp-registration-conflict.js +34 -1
  400. package/release-manager/dist/installers/workbuddy-host-installer.js +284 -21
  401. package/release-manager/dist/service-host-bridge.js +292 -0
  402. package/release-manager/dist/update/install-layout.js +42 -15
  403. package/release-manager/package.json +2 -2
  404. package/workbuddy-adapter/dist/index.d.ts +1 -1
  405. package/workbuddy-adapter/dist/index.js +1 -1
  406. package/workbuddy-adapter/dist/worker/workspace-worker.d.ts +7 -0
  407. package/workbuddy-adapter/dist/worker/workspace-worker.js +179 -10
  408. package/workbuddy-adapter/package.json +1 -1
  409. package/workbuddy-adapter/plugin/.codebuddy-plugin/plugin.json +2 -2
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "schemaVersion": 1,
3
- "productVersion": "2.8.9",
4
- "sourceCommit": "44eb2260606776dc28939a45d5375c2fb29b4a0c"
3
+ "productVersion": "2.8.11",
4
+ "sourceCommit": "5e3b8d53d46dfb3884966a006be3996c1dd34428"
5
5
  }
@@ -11,3 +11,20 @@ export declare class CodexDecoderError extends Error {
11
11
  constructor(reason: string, nextAction: string);
12
12
  }
13
13
  export declare function decodeCodexInput(raw: unknown): HostEvent;
14
+ /** The MCP server ids whose `pd_submit_pain` the receipt fallback serves:
15
+ * the configured id (`pd-recall`) and its identifier-sanitized spelling. */
16
+ export declare const PAIN_SUBMIT_MCP_SERVER_IDS: ReadonlySet<string>;
17
+ export interface ParsedMcpToolName {
18
+ readonly serverId: string;
19
+ readonly toolId: string;
20
+ }
21
+ /** Decompose a Codex MCP tool name into (serverId, toolId); null when the
22
+ * name is not a namespaced MCP tool name. No substring semantics. */
23
+ export declare function parseCodexMcpToolName(toolName: string): ParsedMcpToolName | null;
24
+ /**
25
+ * Exact gate for the PostToolUse receipt fallback: the tool must be
26
+ * `pd_submit_pain` served by the PD MCP server (`pd-recall`). Every other
27
+ * tool — including an identically-named tool on a DIFFERENT MCP server —
28
+ * fails (equality on both parsed segments, never a substring match).
29
+ */
30
+ export declare function isPainSubmitPostToolUseToolName(toolName: string): boolean;
@@ -111,3 +111,42 @@ export function decodeCodexInput(raw) {
111
111
  const source = `codex:${eventName.replace(/([a-z0-9])([A-Z])/g, '$1_$2').toLowerCase()}`;
112
112
  return { kind, context, rawPayload, source };
113
113
  }
114
+ // ── PRI-1274 (B1 / P1-1): MCP tool-name namespace on PostToolUse ─────────────
115
+ //
116
+ // Codex reports MCP tool calls under the server-namespaced form
117
+ // `mcp__<serverId>__<toolId>`. Evidence for the installed codex-cli 0.171.0:
118
+ // the binary's own format template `mcp__{}__{}`, its server-name charset
119
+ // check `^[a-zA-Z0-9_-]+$` with a reserved `mcp__` namespace, and its
120
+ // desktop-context string "MCP tools keep standard MCP identifiers such as
121
+ // `mcp__server__tool`". Runtime capture (Gate 2, 2026-10-31): the server
122
+ // configured as `pd-recall` (plugins/principles-disciple/.mcp.json) surfaced
123
+ // as `mcp__pd_recall__pd_recall_principle_pains` — non-identifier characters
124
+ // in the server id are sanitized to `_`, so BOTH spellings must be accepted.
125
+ //
126
+ // Parsing splits at the FIRST `__` after the `mcp__` prefix: a server id
127
+ // containing `__` would mis-parse, but such a name can never equal the
128
+ // accepted ids below, so foreign servers stay isolated regardless.
129
+ /** The MCP server ids whose `pd_submit_pain` the receipt fallback serves:
130
+ * the configured id (`pd-recall`) and its identifier-sanitized spelling. */
131
+ export const PAIN_SUBMIT_MCP_SERVER_IDS = new Set(['pd-recall', 'pd_recall']);
132
+ /** Decompose a Codex MCP tool name into (serverId, toolId); null when the
133
+ * name is not a namespaced MCP tool name. No substring semantics. */
134
+ export function parseCodexMcpToolName(toolName) {
135
+ if (!toolName.startsWith('mcp__'))
136
+ return null;
137
+ const rest = toolName.slice('mcp__'.length);
138
+ const separator = rest.indexOf('__');
139
+ if (separator <= 0 || separator + 2 >= rest.length)
140
+ return null;
141
+ return { serverId: rest.slice(0, separator), toolId: rest.slice(separator + 2) };
142
+ }
143
+ /**
144
+ * Exact gate for the PostToolUse receipt fallback: the tool must be
145
+ * `pd_submit_pain` served by the PD MCP server (`pd-recall`). Every other
146
+ * tool — including an identically-named tool on a DIFFERENT MCP server —
147
+ * fails (equality on both parsed segments, never a substring match).
148
+ */
149
+ export function isPainSubmitPostToolUseToolName(toolName) {
150
+ const parsed = parseCodexMcpToolName(toolName);
151
+ return parsed !== null && PAIN_SUBMIT_MCP_SERVER_IDS.has(parsed.serverId) && parsed.toolId === 'pd_submit_pain';
152
+ }
@@ -19,10 +19,119 @@
19
19
  * - No LLM runs here: admission + durable enqueue only, well inside the
20
20
  * 5s hook budget; the receipt carries painId/taskId.
21
21
  */
22
- import { admitGovernanceSignals, ensureGovernanceDiagnosticianTask, promoteAdmittedGovernanceEvidence, } from '@principles/host-runtime';
22
+ import fs from 'node:fs';
23
+ import { admitGovernanceSignals, ensureGovernanceDiagnosticianTask, promoteAdmittedGovernanceEvidence, readSourceMaterialAuthorization, } from '@principles/host-runtime';
23
24
  import { resolveCodexHome } from './codex-home.js';
24
25
  import { validateCodexTranscriptPath } from './transcript-path.js';
25
26
  import { extractFields } from './ingestion-fields.js';
27
+ function isRecord(value) {
28
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
29
+ }
30
+ function own(value, key) {
31
+ return Object.hasOwn(value, key) ? Object.getOwnPropertyDescriptor(value, key)?.value : undefined;
32
+ }
33
+ /** Bounded tail read: the current turn's user record sits at the end. */
34
+ const VERBATIM_VERIFY_MAX_BYTES = 4 * 1024 * 1024;
35
+ /**
36
+ * PRI-1283 round 3 (owner_manual ruling): the trusted Owner interaction
37
+ * record for the agent-assisted (`pd pain explicit`) channel. The submitted
38
+ * statement is confirmed ONLY when it appears VERBATIM inside the CURRENT
39
+ * turn's genuine user message in the host-validated transcript — i.e. the
40
+ * Owner typed exactly those words, so the final submitted content is what
41
+ * the Owner wrote, not an agent's paraphrase, summary or invention.
42
+ *
43
+ * Reads the same two user-turn record shapes the governance decoder
44
+ * projects (response_item user.text / event_msg UserMessage item_completed)
45
+ * so the confirmation is anchored on the SAME host-written substrate —
46
+ * never on anything the agent claimed. Transcript CONTENT is only read here
47
+ * under the conversation-ingestion consent (callers pass the flag); the
48
+ * check fails closed (no confirmation) on any read/parse problem.
49
+ */
50
+ function verifyOwnerVerbatimTurnMatch(args) {
51
+ const needle = args.statementText;
52
+ if (needle.length === 0)
53
+ return false;
54
+ let fd = null;
55
+ try {
56
+ fd = fs.openSync(args.validated.canonicalPath, 'r');
57
+ const stat = fs.fstatSync(fd);
58
+ // Post-open revalidation: same physical file the path validator proved.
59
+ if (stat.dev !== args.validated.identity.dev || stat.ino !== args.validated.identity.ino)
60
+ return false;
61
+ const start = Math.max(0, stat.size - VERBATIM_VERIFY_MAX_BYTES);
62
+ const length = Math.min(VERBATIM_VERIFY_MAX_BYTES, stat.size);
63
+ const buffer = Buffer.alloc(length);
64
+ const read = fs.readSync(fd, buffer, 0, length, start);
65
+ const text = buffer.subarray(0, read).toString('utf8');
66
+ const lines = text.split('\n');
67
+ for (const line of lines) {
68
+ const trimmed = line.trim();
69
+ if (trimmed.length === 0)
70
+ continue;
71
+ let record;
72
+ try {
73
+ record = JSON.parse(trimmed);
74
+ }
75
+ catch {
76
+ continue;
77
+ }
78
+ if (!isRecord(record))
79
+ continue;
80
+ const payload = own(record, 'payload');
81
+ if (!isRecord(payload))
82
+ continue;
83
+ const recordType = own(record, 'type');
84
+ if (recordType === 'response_item' && own(payload, 'type') === 'message' && own(payload, 'role') === 'user') {
85
+ const passthrough = own(payload, 'internal_chat_message_metadata_passthrough');
86
+ if (!isRecord(passthrough) || own(passthrough, 'turn_id') !== args.turnId)
87
+ continue;
88
+ const kinds = own(passthrough, 'content_item_kinds');
89
+ if (!Array.isArray(kinds) || kinds[0] !== 'user.text')
90
+ continue;
91
+ const content = own(payload, 'content');
92
+ if (!Array.isArray(content))
93
+ continue;
94
+ const parts = [];
95
+ for (const item of content) {
96
+ if (isRecord(item) && own(item, 'type') === 'input_text' && typeof own(item, 'text') === 'string')
97
+ parts.push(own(item, 'text'));
98
+ }
99
+ if (parts.join('').includes(needle))
100
+ return true;
101
+ continue;
102
+ }
103
+ if (recordType === 'event_msg' && own(payload, 'type') === 'item_completed' && own(payload, 'turn_id') === args.turnId) {
104
+ const item = own(payload, 'item');
105
+ if (!isRecord(item) || own(item, 'type') !== 'UserMessage')
106
+ continue;
107
+ const content = own(item, 'content');
108
+ if (!Array.isArray(content))
109
+ continue;
110
+ const parts = [];
111
+ for (const entry of content) {
112
+ if (isRecord(entry) && (own(entry, 'type') === 'text' || own(entry, 'type') === 'Text') && typeof own(entry, 'text') === 'string')
113
+ parts.push(own(entry, 'text'));
114
+ }
115
+ if (parts.join('').includes(needle))
116
+ return true;
117
+ }
118
+ }
119
+ return false;
120
+ }
121
+ catch {
122
+ return false;
123
+ }
124
+ finally {
125
+ if (fd !== null) {
126
+ try {
127
+ fs.closeSync(fd);
128
+ }
129
+ catch {
130
+ // best-effort close
131
+ }
132
+ }
133
+ }
134
+ }
26
135
  export { OWNER_STATEMENT_PREFIX as CODEX_OWNER_STATEMENT_PREFIX, MAX_OWNER_STATEMENT_CHARS, parseOwnerStatementPrefix } from '@principles/host-runtime';
27
136
  /**
28
137
  * Persist one explicit Owner statement. The consent-gated conversation
@@ -69,6 +178,21 @@ export async function recordExplicitOwnerStatement(args) {
69
178
  observedAt: new Date().toISOString(),
70
179
  explicitOwnerStatement: true,
71
180
  ...(args.explicitChannel !== undefined ? { explicitChannel: args.explicitChannel } : {}),
181
+ // PRI-1283 round 3 (owner_manual ruling): an agent-assisted statement is
182
+ // owner_manual ONLY when the submitted text matches the Owner's own words
183
+ // in the current turn's transcript record. The check reads transcript
184
+ // CONTENT, so it runs only under the conversation-ingestion consent;
185
+ // when consent is off (or the match fails) the statement persists as
186
+ // Agent-derived — classified down, never rejected outright.
187
+ ...(args.explicitChannel === 'codex_explicit_agent' && args.conversationIngestionEnabled
188
+ // Transcript content is consent-governed material: the feature flag
189
+ // alone is not the authority — the consent ledger must still grant
190
+ // codex ingestion before any confirmation reads transcript content
191
+ // (a revoked-but-still-flagged workspace must not mint exemptions).
192
+ && readSourceMaterialAuthorization({ workspaceDir: args.workspaceDir, hostKind: 'codex' }).status === 'authorized'
193
+ && verifyOwnerVerbatimTurnMatch({ validated, turnId: fields.turnId, statementText: args.statementText })
194
+ ? { ownerVerbatimConfirmed: true }
195
+ : {}),
72
196
  };
73
197
  const admitted = admitGovernanceSignals({ workspaceDir: args.workspaceDir, candidates: [candidate] });
74
198
  if (!admitted.ok) {
@@ -0,0 +1,46 @@
1
+ import { type PainReceiptRecoveryOutcome } from '@principles/core/runtime';
2
+ /** The MCP tool id this fallback processes (the server gate lives in the
3
+ * codec parser — exact match on both namespace segments, never a pattern). */
4
+ export declare const PAIN_SUBMIT_TOOL_NAME: 'pd_submit_pain';
5
+ export type PainReceiptFallbackResult = {
6
+ readonly status: 'not_applicable';
7
+ } | {
8
+ readonly status: 'attempted';
9
+ readonly outcome: PainReceiptRecoveryOutcome;
10
+ };
11
+ export interface PainReceiptFallbackInput {
12
+ readonly workspaceDir: string;
13
+ /** Raw host event `tool_name` — gated by the codec MCP namespace parser
14
+ * before anything else happens (P1-1). */
15
+ readonly toolName: string;
16
+ /** Raw `tool_response` from the PostToolUse payload. */
17
+ readonly toolResponse: unknown;
18
+ /** Host-authoritative identity from the event itself. */
19
+ readonly identity: {
20
+ readonly sessionId: string;
21
+ readonly turnId?: string;
22
+ readonly toolCallId: string;
23
+ };
24
+ /** Caller-resolved `host_identity_minimal_metadata` flag verdict. */
25
+ readonly minimalMetadataGranted: boolean;
26
+ readonly now?: () => Date;
27
+ }
28
+ /**
29
+ * P1-3: does the authorized governance store already hold readable text for
30
+ * the EXACT (session, turn)? Shared by the receipt fallback (disposition
31
+ * choice) and the workspace worker's waiting-task reconcile (the flip) —
32
+ * the diagnosis itself re-reads the turn through the same store.
33
+ * Unreadable ⇒ missing.
34
+ */
35
+ export declare function codexTargetTurnTextAvailable(workspaceDir: string, sessionId: string, turnId: string): boolean;
36
+ /**
37
+ * Attempt the receipt fallback for one PostToolUse event. Never throws —
38
+ * every failure is a structured result the hook surfaces as one bounded
39
+ * diagnostic (rc-9); the hook result itself is unaffected (fail-open belt).
40
+ */
41
+ export declare function attemptPainReceiptFallback(input: PainReceiptFallbackInput): Promise<PainReceiptFallbackResult>;
42
+ /**
43
+ * One bounded stderr diagnostic line for the hook (ids and codes only —
44
+ * never receipt content, prompts or tool input/output).
45
+ */
46
+ export declare function painReceiptFallbackDiagnostic(result: PainReceiptFallbackResult): string | null;
@@ -0,0 +1,193 @@
1
+ /**
2
+ * PRI-1274 (B1) — Codex PostToolUse structured-receipt fallback.
3
+ *
4
+ * When a `pd_submit_pain` MCP request carried no trusted host `_meta`, the
5
+ * original Pain/Task was legally persisted unbound. Codex's formal
6
+ * PostToolUse completion event then carries PD's own structured receipt in
7
+ * `tool_response` — the MCP envelope is a SINGLE text content block with the
8
+ * JSON in `content[0].text` (never `structuredContent`; the adapter owns
9
+ * this host envelope shape and must not extrapolate it to other hosts).
10
+ * Together with the event's own host-authoritative identity
11
+ * (`session_id` / `turn_id` / `tool_use_id` — never model parameters), this
12
+ * module restores the SAME original task's submission identity through the
13
+ * Core CAS recovery.
14
+ *
15
+ * P1-1 (review round 2): Codex reports MCP tools under the server
16
+ * namespace — the gate is an exact parse of `mcp__<server>__<tool>` against
17
+ * the PD server (`pd-recall`, sanitized `pd_recall`) + `pd_submit_pain`
18
+ * (see codec/input-decoder.ts for the format evidence). A bare
19
+ * `pd_submit_pain` or an identically-named tool on another MCP server never
20
+ * enters this path.
21
+ *
22
+ * Authorization: the Workspace-level `host_identity_minimal_metadata` quiet
23
+ * flag — deliberately INDEPENDENT of `codex_conversation_ingestion` (full
24
+ * conversation ingestion may stay off; this path reads no transcript and
25
+ * persists ids only).
26
+ *
27
+ * No recovery is EVER attempted from free text, ordinary EventLog
28
+ * `tool_call` rows, or look-alike strings (SPEC TD §1.3).
29
+ */
30
+ import * as path from 'node:path';
31
+ import { listGovernanceObservations } from '@principles/host-runtime';
32
+ import { isSentinelSessionId } from '@principles/core/runtime';
33
+ import { recoverTaskIdentityFromReceipt, validatePainSubmitReceipt, } from '@principles/core/runtime';
34
+ import { isPainSubmitPostToolUseToolName } from '../codec/input-decoder.js';
35
+ /** The MCP tool id this fallback processes (the server gate lives in the
36
+ * codec parser — exact match on both namespace segments, never a pattern). */
37
+ export const PAIN_SUBMIT_TOOL_NAME = 'pd_submit_pain';
38
+ /** MCP CallToolResult content block shape (single text block contract).
39
+ * P2 review round: more than one content block is AMBIGUOUS — two text
40
+ * blocks could each carry a different task's receipt, so the whole envelope
41
+ * is rejected instead of quietly trusting the first block. */
42
+ function extractReceiptText(toolResponse) {
43
+ if (typeof toolResponse !== 'object' || toolResponse === null || Array.isArray(toolResponse)) {
44
+ return { ok: false, reasonCode: 'receipt_envelope_not_an_object' };
45
+ }
46
+ if (!Object.hasOwn(toolResponse, 'content')) {
47
+ return { ok: false, reasonCode: 'receipt_envelope_content_missing' };
48
+ }
49
+ const { content } = toolResponse;
50
+ if (!Array.isArray(content) || content.length === 0) {
51
+ return { ok: false, reasonCode: 'receipt_envelope_content_missing' };
52
+ }
53
+ if (content.length > 1) {
54
+ return { ok: false, reasonCode: 'receipt_envelope_ambiguous_content' };
55
+ }
56
+ const [first] = content;
57
+ if (typeof first !== 'object' || first === null || Array.isArray(first)) {
58
+ return { ok: false, reasonCode: 'receipt_envelope_block_invalid' };
59
+ }
60
+ if (!Object.hasOwn(first, 'type') || !Object.hasOwn(first, 'text')) {
61
+ return { ok: false, reasonCode: 'receipt_envelope_not_text_block' };
62
+ }
63
+ const { type, text } = first;
64
+ if (type !== 'text' || typeof text !== 'string') {
65
+ return { ok: false, reasonCode: 'receipt_envelope_not_text_block' };
66
+ }
67
+ return { ok: true, text };
68
+ }
69
+ /** Normalize host ids at the adapter boundary, matching the trusted `_meta`
70
+ * reader. `null` means malformed; `undefined` means absent (or an empty
71
+ * optional id). Only the normalized value may cross into Core. */
72
+ function normalizeEventId(value, opts) {
73
+ if (value === undefined)
74
+ return undefined;
75
+ if (typeof value !== 'string')
76
+ return null;
77
+ const id = value.trim();
78
+ if (opts.allowEmpty && id.length === 0)
79
+ return undefined;
80
+ return id.length > 0 && id.length <= 200 && !isSentinelSessionId(id) ? id : null;
81
+ }
82
+ /**
83
+ * P1-3: does the authorized governance store already hold readable text for
84
+ * the EXACT (session, turn)? Shared by the receipt fallback (disposition
85
+ * choice) and the workspace worker's waiting-task reconcile (the flip) —
86
+ * the diagnosis itself re-reads the turn through the same store.
87
+ * Unreadable ⇒ missing.
88
+ */
89
+ export function codexTargetTurnTextAvailable(workspaceDir, sessionId, turnId) {
90
+ try {
91
+ const result = listGovernanceObservations({
92
+ workspaceDir,
93
+ hostKind: 'codex',
94
+ rolloutIdentity: sessionId,
95
+ hostTurnId: turnId,
96
+ limit: 8,
97
+ });
98
+ if (!result.ok)
99
+ return false;
100
+ return result.observations.some((row) => (row.kind === 'user_turn' || row.kind === 'assistant_turn')
101
+ && (row.retentionClass === 'operational' || row.retentionClass === 'promoted')
102
+ && typeof row.visibleText === 'string'
103
+ && row.visibleText.trim() !== '');
104
+ }
105
+ catch {
106
+ return false;
107
+ }
108
+ }
109
+ /**
110
+ * Attempt the receipt fallback for one PostToolUse event. Never throws —
111
+ * every failure is a structured result the hook surfaces as one bounded
112
+ * diagnostic (rc-9); the hook result itself is unaffected (fail-open belt).
113
+ */
114
+ export async function attemptPainReceiptFallback(input) {
115
+ // P1-1: exact namespace gate first — only the PD MCP server's
116
+ // `pd_submit_pain` completion may enter the recovery path.
117
+ if (!isPainSubmitPostToolUseToolName(input.toolName)) {
118
+ return { status: 'not_applicable' };
119
+ }
120
+ // P2: validate AND normalize at the host boundary. Validating a trimmed
121
+ // copy while forwarding the raw value would create a second identity
122
+ // spelling in Core/SQLite (and make exact target-turn joins miss).
123
+ const sessionId = normalizeEventId(input.identity.sessionId, { allowEmpty: false });
124
+ const toolCallId = normalizeEventId(input.identity.toolCallId, { allowEmpty: false });
125
+ const turnId = normalizeEventId(input.identity.turnId, { allowEmpty: true });
126
+ if (sessionId === null || toolCallId === null || turnId === null) {
127
+ return { status: 'attempted', outcome: { status: 'rejected', reasonCode: 'event_identity_invalid' } };
128
+ }
129
+ if (sessionId === undefined || toolCallId === undefined) {
130
+ return { status: 'attempted', outcome: { status: 'rejected', reasonCode: 'event_identity_missing' } };
131
+ }
132
+ const envelope = extractReceiptText(input.toolResponse);
133
+ if (!envelope.ok) {
134
+ return { status: 'attempted', outcome: { status: 'rejected', reasonCode: envelope.reasonCode } };
135
+ }
136
+ let parsed;
137
+ try {
138
+ parsed = JSON.parse(envelope.text);
139
+ }
140
+ catch {
141
+ // Degraded transport forms (plain-text statement) and foreign payloads
142
+ // are not receipts — no recovery from free text.
143
+ return { status: 'attempted', outcome: { status: 'rejected', reasonCode: 'receipt_text_not_json' } };
144
+ }
145
+ // P2: normalize the workspace spellings BEFORE validation — the same
146
+ // directory written differently (`/w/p` vs `/w/p/.`) is the same
147
+ // workspace; a genuinely different directory is still rejected by the
148
+ // validated exact comparison. Platform path knowledge stays in the
149
+ // adapter (Core stays path-free).
150
+ const normalizedWorkspace = path.resolve(input.workspaceDir);
151
+ if (typeof parsed === 'object' && parsed !== null && !Array.isArray(parsed)) {
152
+ const parsedRecord = parsed;
153
+ const rawDir = Object.hasOwn(parsedRecord, 'workspaceDir') ? parsedRecord.workspaceDir : undefined;
154
+ if (typeof rawDir === 'string' && rawDir.length > 0) {
155
+ parsed = { ...parsedRecord, workspaceDir: path.resolve(rawDir) };
156
+ }
157
+ }
158
+ const validated = validatePainSubmitReceipt(parsed, { workspaceDir: normalizedWorkspace });
159
+ if (!validated.ok) {
160
+ return { status: 'attempted', outcome: { status: 'rejected', reasonCode: validated.reasonCode } };
161
+ }
162
+ const outcome = await recoverTaskIdentityFromReceipt({
163
+ workspaceDir: normalizedWorkspace,
164
+ hostKind: 'codex',
165
+ receipt: validated.receipt,
166
+ identity: {
167
+ sessionId,
168
+ ...(turnId === undefined ? {} : { submissionTurnId: turnId }),
169
+ toolCallId,
170
+ },
171
+ authorization: { minimalMetadataGranted: input.minimalMetadataGranted },
172
+ targetTurnTextAvailable: (hostSessionId, targetTurnId) => codexTargetTurnTextAvailable(normalizedWorkspace, hostSessionId, targetTurnId),
173
+ ...(input.now !== undefined ? { now: input.now } : {}),
174
+ });
175
+ return { status: 'attempted', outcome };
176
+ }
177
+ /**
178
+ * One bounded stderr diagnostic line for the hook (ids and codes only —
179
+ * never receipt content, prompts or tool input/output).
180
+ */
181
+ export function painReceiptFallbackDiagnostic(result) {
182
+ if (result.status === 'not_applicable')
183
+ return null;
184
+ const { outcome } = result;
185
+ switch (outcome.status) {
186
+ case 'recovered':
187
+ return `pain_receipt_recovered:taskId=${outcome.taskId}:state=${outcome.disposition.state}`;
188
+ case 'already_bound':
189
+ return `pain_receipt_idempotent:taskId=${outcome.taskId}`;
190
+ case 'rejected':
191
+ return `pain_receipt_rejected:${outcome.reasonCode}${outcome.detail !== undefined ? `:detail=${Array.from(outcome.detail).slice(0, 80).join('')}` : ''}${outcome.taskId !== undefined ? `:taskId=${outcome.taskId}` : ''}`;
192
+ }
193
+ }
@@ -1,6 +1,6 @@
1
1
  import { type RecordOwnerStatementResult } from './explicit-owner-statement.js';
2
2
  export declare const TURN_CONTEXT_FILENAME_PREFIX = "pd_current_turn_context_";
3
- export declare const TURN_CONTEXT_SCHEMA_VERSION = 1;
3
+ export declare const TURN_CONTEXT_SCHEMA_VERSION = 2;
4
4
  /**
5
5
  * Staleness bound for the turn context. Stop/SessionStart withdraw the file,
6
6
  * but any early exit on those paths (decode/config failure, host.codex flag
@@ -10,7 +10,7 @@ export declare const TURN_CONTEXT_SCHEMA_VERSION = 1;
10
10
  * legitimate in-turn registration latency.
11
11
  */
12
12
  export declare const TURN_CONTEXT_MAX_AGE_MS: number;
13
- /** Host-written identity of the CURRENT Codex turn. Ids and paths only. */
13
+ /** Host-written identity of the CURRENT Codex turn: ids, paths and one closed-set intent marker. */
14
14
  export interface CodexTurnContext {
15
15
  readonly schemaVersion: number;
16
16
  readonly writtenAt: string;
@@ -19,6 +19,8 @@ export interface CodexTurnContext {
19
19
  readonly transcriptPath: string;
20
20
  readonly codexHome: string;
21
21
  readonly workspaceDir: string;
22
+ /** Host-derived from a direct current-turn Owner request; never caller-supplied. */
23
+ readonly ownerIntent: 'explicit_pain_registration' | null;
22
24
  }
23
25
  interface CodexCallerEnvironment {
24
26
  CODEX_HOME?: string | undefined;
@@ -43,14 +45,6 @@ export declare function clearCurrentTurnContext(args: {
43
45
  sessionId: string;
44
46
  turnId?: string;
45
47
  }): TurnContextClearResult;
46
- /**
47
- * Publish (or withdraw) the current turn context. Called from the
48
- * UserPromptSubmit branch of the hook. A payload without complete lineage
49
- * (session/turn/transcript) clears any previous file instead of leaving a
50
- * stale turn bindable — the invariant is "file exists ⟺ the current turn
51
- * carries full lineage". Fail-open: a write failure degrades the
52
- * agent-assisted entry only (the prefix entry never needed this file).
53
- */
54
48
  export declare function writeCurrentTurnContext(args: {
55
49
  rawPayload: unknown;
56
50
  workspaceDir: string;
@@ -58,15 +52,16 @@ export declare function writeCurrentTurnContext(args: {
58
52
  }): TurnContextWriteResult;
59
53
  export type RegisterCurrentTurnResult = RecordOwnerStatementResult | {
60
54
  status: 'rejected';
61
- reason: 'turn_context_missing' | 'turn_context_invalid' | 'turn_context_stale' | 'turn_context_workspace_mismatch' | 'turn_context_session_mismatch' | 'caller_session_missing' | 'caller_session_conflict' | 'conversation_ingestion_config_invalid';
55
+ reason: 'turn_context_missing' | 'turn_context_invalid' | 'turn_context_stale' | 'turn_context_workspace_mismatch' | 'turn_context_session_mismatch' | 'caller_session_missing' | 'caller_session_conflict' | 'conversation_ingestion_config_invalid' | 'owner_intent_missing';
62
56
  nextAction: string;
63
57
  };
64
58
  /**
65
59
  * Register one explicit Owner statement through the LIVE turn context — the
66
- * agent-assisted counterpart of the prefix entry. The statement must be the
67
- * Owner's verbatim words from the CURRENT conversation turn (1–500 chars,
68
- * rejected when over the limit — never truncated); lineage comes exclusively
69
- * from the host-written context file, never from caller-supplied ids.
60
+ * agent-assisted counterpart of the prefix entry. The current Owner turn
61
+ * must explicitly request this registration. Supplied wording is Agent-derived
62
+ * unless a consent-authorized transcript match verifies it as Owner-verbatim.
63
+ * The intent marker authorizes this submission, not authorship. Lineage comes
64
+ * only from the host-written context file.
70
65
  */
71
66
  export declare function registerCurrentTurnOwnerStatement(args: {
72
67
  workspaceDir: string;
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Live-turn context bridge for agent-assisted explicit Owner pain
3
- * registration (no `PD记录痛苦:` prefix).
3
+ * registration gated by a host-derived current-turn Owner-intent marker.
4
4
  *
5
5
  * The hook writes the CURRENT turn's host-verified identity — session id,
6
6
  * turn id, transcript path, CODEX_HOME, workspace — to a file partitioned by
@@ -15,9 +15,9 @@
15
15
  * the transcript path (existence + CODEX_HOME containment + rollout identity)
16
16
  * at registration time. A cleared or stale context fails closed.
17
17
  *
18
- * Privacy: each file carries identifiers and paths only — never prompt text,
19
- * never transcript content. Session ids are hashed in filenames. The
20
- * conversation-ingestion flag does not gate context publication.
18
+ * Privacy: each file carries identifiers, paths and a closed-set intent marker only.
19
+ * It never persists prompt text or transcript content; session ids are hashed in filenames.
20
+ * The conversation-ingestion flag does not gate context publication.
21
21
  */
22
22
  import fs from 'node:fs';
23
23
  import { createHash, randomUUID } from 'node:crypto';
@@ -28,7 +28,7 @@ import { resolveCodexHome } from './codex-home.js';
28
28
  import { extractFields, isRecord } from './ingestion-fields.js';
29
29
  import { recordExplicitOwnerStatement, MAX_OWNER_STATEMENT_CHARS } from './explicit-owner-statement.js';
30
30
  export const TURN_CONTEXT_FILENAME_PREFIX = 'pd_current_turn_context_';
31
- export const TURN_CONTEXT_SCHEMA_VERSION = 1;
31
+ export const TURN_CONTEXT_SCHEMA_VERSION = 2;
32
32
  /**
33
33
  * Staleness bound for the turn context. Stop/SessionStart withdraw the file,
34
34
  * but any early exit on those paths (decode/config failure, host.codex flag
@@ -128,6 +128,13 @@ const CLEAR_FAILURE_NEXT_ACTION = 'The previous turn context could not be withdr
128
128
  * carries full lineage". Fail-open: a write failure degrades the
129
129
  * agent-assisted entry only (the prefix entry never needed this file).
130
130
  */
131
+ const OWNER_PAIN_REQUEST_PREFIXES = ['PD代录痛苦:', 'PD代录痛苦:', 'PD记录痛苦:', 'PD记录痛苦:'];
132
+ function resolveOwnerPainIntent(rawPayload) {
133
+ if (!isRecord(rawPayload) || typeof rawPayload.prompt !== 'string')
134
+ return null;
135
+ const prompt = rawPayload.prompt.trimStart();
136
+ return OWNER_PAIN_REQUEST_PREFIXES.some((prefix) => prompt.startsWith(prefix) && prompt.slice(prefix.length).trim().length > 0) ? 'explicit_pain_registration' : null;
137
+ }
131
138
  export function writeCurrentTurnContext(args) {
132
139
  const fields = extractFields(args.rawPayload);
133
140
  if (fields === null || fields.sessionId.length === 0) {
@@ -158,6 +165,7 @@ export function writeCurrentTurnContext(args) {
158
165
  transcriptPath: fields.transcriptPath,
159
166
  codexHome: home.home,
160
167
  workspaceDir: args.workspaceDir,
168
+ ownerIntent: resolveOwnerPainIntent(args.rawPayload),
161
169
  };
162
170
  const target = turnContextPath(args.workspaceDir, fields.sessionId);
163
171
  const temp = `${target}.tmp-${process.pid}`;
@@ -185,6 +193,11 @@ function requireStringField(record, key) {
185
193
  const value = Object.hasOwn(record, key) ? record[key] : undefined;
186
194
  return typeof value === 'string' && value.length > 0 ? value : null;
187
195
  }
196
+ /**
197
+ * A tool invocation is not proof that the Owner requested it. The UserPromptSubmit
198
+ * hook records only this closed-set marker from the current Owner message. It
199
+ * deliberately stores no prompt text and does not inspect historical turns.
200
+ */
188
201
  function readTurnContext(workspaceDir, sessionId) {
189
202
  let raw;
190
203
  try {
@@ -208,6 +221,10 @@ function readTurnContext(workspaceDir, sessionId) {
208
221
  const transcriptPath = requireStringField(parsed, 'transcriptPath');
209
222
  const codexHome = requireStringField(parsed, 'codexHome');
210
223
  const contextWorkspaceDir = requireStringField(parsed, 'workspaceDir');
224
+ const { ownerIntent } = parsed;
225
+ if (!Object.hasOwn(parsed, 'ownerIntent') || (ownerIntent !== null && ownerIntent !== 'explicit_pain_registration')) {
226
+ return { error: 'turn_context_invalid' };
227
+ }
211
228
  if (writtenAt === null || contextSessionId === null || turnId === null || transcriptPath === null || codexHome === null || contextWorkspaceDir === null) {
212
229
  return { error: 'turn_context_invalid' };
213
230
  }
@@ -224,14 +241,16 @@ function readTurnContext(workspaceDir, sessionId) {
224
241
  transcriptPath,
225
242
  codexHome,
226
243
  workspaceDir: contextWorkspaceDir,
244
+ ownerIntent,
227
245
  };
228
246
  }
229
247
  /**
230
248
  * Register one explicit Owner statement through the LIVE turn context — the
231
- * agent-assisted counterpart of the prefix entry. The statement must be the
232
- * Owner's verbatim words from the CURRENT conversation turn (1–500 chars,
233
- * rejected when over the limit — never truncated); lineage comes exclusively
234
- * from the host-written context file, never from caller-supplied ids.
249
+ * agent-assisted counterpart of the prefix entry. The current Owner turn
250
+ * must explicitly request this registration. Supplied wording is Agent-derived
251
+ * unless a consent-authorized transcript match verifies it as Owner-verbatim.
252
+ * The intent marker authorizes this submission, not authorship. Lineage comes
253
+ * only from the host-written context file.
235
254
  */
236
255
  export async function registerCurrentTurnOwnerStatement(args) {
237
256
  const caller = resolveCallerSessionId(process.env);
@@ -271,6 +290,13 @@ export async function registerCurrentTurnOwnerStatement(args) {
271
290
  nextAction: 'The turn context does not belong to this host-bound Codex session; nothing was recorded. Retry from the session that supplied the Owner statement.',
272
291
  };
273
292
  }
293
+ if (context.ownerIntent !== 'explicit_pain_registration') {
294
+ return {
295
+ status: 'rejected',
296
+ reason: 'owner_intent_missing',
297
+ nextAction: 'An agent/tool invocation is not Owner approval. The current Owner message must begin with PD代录痛苦:<request> (or PD记录痛苦:<Owner words> for direct submission). Start a new Owner turn with that explicit prefix; no history was read and nothing was recorded.',
298
+ };
299
+ }
274
300
  const statement = args.statementText.trim();
275
301
  if (statement.length === 0) {
276
302
  return { status: 'rejected', reason: 'statement_empty', nextAction: 'The Owner statement is empty; nothing was recorded. Pass the Owner verbatim words (1–500 characters).' };