create-principles-disciple 1.150.3 → 1.150.6

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 (646) hide show
  1. package/_release/product-identity.json +1 -1
  2. package/codex-adapter/dist/ingestion/admission.js +2 -0
  3. package/codex-adapter/dist/ingestion/ingestion.js +25 -4
  4. package/codex-adapter/dist/ingestion/transcript-decoder.d.ts +5 -3
  5. package/codex-adapter/dist/ingestion/transcript-decoder.js +61 -5
  6. package/codex-adapter/dist/pd-hook.d.ts +7 -5
  7. package/codex-adapter/dist/pd-hook.js +18 -7
  8. package/codex-adapter/dist/tool-semantics.js +5 -1
  9. package/codex-adapter/dist/worker/workspace-worker.js +4 -2
  10. package/codex-adapter/package.json +1 -1
  11. package/console/dist/lib/utils.js +16 -1
  12. package/console/dist/server/index.js +14 -2
  13. package/console/dist/server/models/ActivationsConsoleModel.js +3 -2
  14. package/console/dist/server/models/ApprovalsConsoleModel.js +2 -1
  15. package/console/dist/server/models/ApprovalsGroupedConsoleModel.js +2 -1
  16. package/console/dist/server/models/EvidenceChainConsoleModel.d.ts +46 -0
  17. package/console/dist/server/models/EvidenceChainConsoleModel.js +121 -2
  18. package/console/dist/server/models/GovernanceConsoleModel.js +3 -2
  19. package/console/dist/server/models/GovernanceExperienceCollector.js +2 -1
  20. package/console/dist/server/models/GovernanceProjectionCollector.js +2 -1
  21. package/console/dist/server/models/IngestionHealthModel.d.ts +34 -0
  22. package/console/dist/server/models/IngestionHealthModel.js +254 -0
  23. package/console/dist/server/models/IntentDecisionModel.js +2 -2
  24. package/console/dist/server/models/IntentPageModel.js +2 -1
  25. package/console/dist/server/models/OwnerDecisionConsoleModel.js +3 -3
  26. package/console/dist/server/models/OwnerDecisionViewModel.js +2 -2
  27. package/console/dist/server/models/PrincipleTrajectoryModel.js +2 -1
  28. package/console/dist/server/models/ReceiptsConsoleModel.js +2 -2
  29. package/console/dist/server/models/RuleCandidateBindingConsoleModel.js +3 -2
  30. package/console/dist/server/routes/diagnostician.js +2 -1
  31. package/console/dist/server/routes/evidence-chain.d.ts +4 -0
  32. package/console/dist/server/routes/evidence-chain.js +22 -0
  33. package/console/dist/server/routes/failed-tasks.js +78 -2
  34. package/console/dist/server/routes/health.d.ts +8 -0
  35. package/console/dist/server/routes/health.js +72 -0
  36. package/console/dist/server/routes/owner-identity.d.ts +6 -0
  37. package/console/dist/server/routes/owner-identity.js +7 -3
  38. package/console/dist/server/routes/principles.js +3 -3
  39. package/console/dist/web/assets/app.css +150 -46
  40. package/console/dist/web/assets/app.js +37 -32
  41. package/console/package.json +2 -0
  42. package/core/dist/runtime/activation/adaptive-selection-output.d.ts +0 -21
  43. package/core/dist/runtime/activation/adaptive-selection-output.d.ts.map +1 -1
  44. package/core/dist/runtime/activation/adaptive-selection-output.js.map +1 -1
  45. package/core/dist/runtime/activation/index.d.ts +2 -6
  46. package/core/dist/runtime/activation/index.d.ts.map +1 -1
  47. package/core/dist/runtime/activation/index.js.map +1 -1
  48. package/core/dist/runtime/activation/production-gate-deps.d.ts +2 -1
  49. package/core/dist/runtime/activation/production-gate-deps.d.ts.map +1 -1
  50. package/core/dist/runtime/activation/prompt-activation-reader-contract.d.ts +2 -1
  51. package/core/dist/runtime/activation/prompt-activation-reader-contract.d.ts.map +1 -1
  52. package/core/dist/runtime/activation/writers/index.d.ts +0 -1
  53. package/core/dist/runtime/activation/writers/index.d.ts.map +1 -1
  54. package/core/dist/runtime/activation/writers/rule-host-writer.d.ts.map +1 -1
  55. package/core/dist/runtime/activation/writers/rule-host-writer.js +15 -6
  56. package/core/dist/runtime/activation/writers/rule-host-writer.js.map +1 -1
  57. package/core/dist/runtime/activation-compatibility-read-model.d.ts +3 -2
  58. package/core/dist/runtime/activation-compatibility-read-model.d.ts.map +1 -1
  59. package/core/dist/runtime/activation-compatibility-read-model.js +2 -1
  60. package/core/dist/runtime/activation-compatibility-read-model.js.map +1 -1
  61. package/core/dist/runtime/adapter/context-budget.d.ts +3 -14
  62. package/core/dist/runtime/adapter/context-budget.d.ts.map +1 -1
  63. package/core/dist/runtime/adapter/context-budget.js +2 -2
  64. package/core/dist/runtime/adapter/context-budget.js.map +1 -1
  65. package/core/dist/runtime/adapter/index.d.ts +1 -2
  66. package/core/dist/runtime/adapter/index.d.ts.map +1 -1
  67. package/core/dist/runtime/adapter/index.js +1 -1
  68. package/core/dist/runtime/adapter/index.js.map +1 -1
  69. package/core/dist/runtime/adapter/output-repair-contract.d.ts +18 -1
  70. package/core/dist/runtime/adapter/output-repair-contract.d.ts.map +1 -1
  71. package/core/dist/runtime/adapter/output-repair-contract.js +94 -0
  72. package/core/dist/runtime/adapter/output-repair-contract.js.map +1 -1
  73. package/core/dist/runtime/adapter/pi-ai-runtime-adapter.d.ts +2 -3
  74. package/core/dist/runtime/adapter/pi-ai-runtime-adapter.d.ts.map +1 -1
  75. package/core/dist/runtime/adapter/pi-ai-runtime-adapter.js +111 -21
  76. package/core/dist/runtime/adapter/pi-ai-runtime-adapter.js.map +1 -1
  77. package/core/dist/runtime/adapter/principle-tree-ledger-adapter.d.ts +1 -1
  78. package/core/dist/runtime/adapter/principle-tree-ledger-adapter.d.ts.map +1 -1
  79. package/core/dist/runtime/adapter/schema-prompt-adapter.d.ts +0 -1
  80. package/core/dist/runtime/adapter/schema-prompt-adapter.d.ts.map +1 -1
  81. package/core/dist/runtime/adapter/schema-prompt-adapter.js +43 -1
  82. package/core/dist/runtime/adapter/schema-prompt-adapter.js.map +1 -1
  83. package/core/dist/runtime/bridge-result-shaper.d.ts +1 -1
  84. package/core/dist/runtime/bridge-result-shaper.d.ts.map +1 -1
  85. package/core/dist/runtime/candidate-audit.d.ts.map +1 -1
  86. package/core/dist/runtime/candidate-audit.js +2 -1
  87. package/core/dist/runtime/candidate-audit.js.map +1 -1
  88. package/core/dist/runtime/candidate-intake-service.d.ts +2 -1
  89. package/core/dist/runtime/candidate-intake-service.d.ts.map +1 -1
  90. package/core/dist/runtime/cli/diagnose.d.ts +4 -3
  91. package/core/dist/runtime/cli/diagnose.d.ts.map +1 -1
  92. package/core/dist/runtime/config/index.d.ts +2 -2
  93. package/core/dist/runtime/config/index.d.ts.map +1 -1
  94. package/core/dist/runtime/config/index.js +3 -3
  95. package/core/dist/runtime/config/index.js.map +1 -1
  96. package/core/dist/runtime/config/pd-config-defaults.d.ts +0 -2
  97. package/core/dist/runtime/config/pd-config-defaults.d.ts.map +1 -1
  98. package/core/dist/runtime/config/pd-config-defaults.js +2 -2
  99. package/core/dist/runtime/config/pd-config-defaults.js.map +1 -1
  100. package/core/dist/runtime/config/pd-config-effective.d.ts.map +1 -1
  101. package/core/dist/runtime/config/pd-config-effective.js +2 -0
  102. package/core/dist/runtime/config/pd-config-effective.js.map +1 -1
  103. package/core/dist/runtime/config/pd-config-types.d.ts +54 -0
  104. package/core/dist/runtime/config/pd-config-types.d.ts.map +1 -1
  105. package/core/dist/runtime/config/pd-config-types.js.map +1 -1
  106. package/core/dist/runtime/config/pd-config-validate.d.ts.map +1 -1
  107. package/core/dist/runtime/config/pd-config-validate.js +143 -0
  108. package/core/dist/runtime/config/pd-config-validate.js.map +1 -1
  109. package/core/dist/runtime/config/pd-profile-constants.d.ts +1 -7
  110. package/core/dist/runtime/config/pd-profile-constants.d.ts.map +1 -1
  111. package/core/dist/runtime/config/pd-profile-constants.js +5 -6
  112. package/core/dist/runtime/config/pd-profile-constants.js.map +1 -1
  113. package/core/dist/runtime/config/pd-validate-profile.d.ts +3 -2
  114. package/core/dist/runtime/config/pd-validate-profile.d.ts.map +1 -1
  115. package/core/dist/runtime/context-payload.d.ts +0 -7
  116. package/core/dist/runtime/context-payload.d.ts.map +1 -1
  117. package/core/dist/runtime/context-payload.js +1 -1
  118. package/core/dist/runtime/context-payload.js.map +1 -1
  119. package/core/dist/runtime/core-principles/index.d.ts +1 -1
  120. package/core/dist/runtime/core-principles/index.d.ts.map +1 -1
  121. package/core/dist/runtime/correction/correction-types.d.ts +0 -10
  122. package/core/dist/runtime/correction/correction-types.d.ts.map +1 -1
  123. package/core/dist/runtime/correction/correction-types.js.map +1 -1
  124. package/core/dist/runtime/diagnostician/diag-distiller-output.d.ts +0 -3
  125. package/core/dist/runtime/diagnostician/diag-distiller-output.d.ts.map +1 -1
  126. package/core/dist/runtime/diagnostician/diag-distiller-output.js +1 -1
  127. package/core/dist/runtime/diagnostician/diag-distiller-output.js.map +1 -1
  128. package/core/dist/runtime/diagnostician/diag-rootcause-output.d.ts +3 -11
  129. package/core/dist/runtime/diagnostician/diag-rootcause-output.d.ts.map +1 -1
  130. package/core/dist/runtime/diagnostician/diag-rootcause-output.js +3 -3
  131. package/core/dist/runtime/diagnostician/diag-rootcause-output.js.map +1 -1
  132. package/core/dist/runtime/diagnostician/distiller-prompt-builder.d.ts +5 -4
  133. package/core/dist/runtime/diagnostician/distiller-prompt-builder.d.ts.map +1 -1
  134. package/core/dist/runtime/diagnostician/evidence-ref-binding.d.ts +2 -1
  135. package/core/dist/runtime/diagnostician/evidence-ref-binding.d.ts.map +1 -1
  136. package/core/dist/runtime/diagnostician/rootcause-prompt-builder.d.ts +2 -1
  137. package/core/dist/runtime/diagnostician/rootcause-prompt-builder.d.ts.map +1 -1
  138. package/core/dist/runtime/diagnostician/router-prompt-builder.d.ts +22 -3
  139. package/core/dist/runtime/diagnostician/router-prompt-builder.d.ts.map +1 -1
  140. package/core/dist/runtime/diagnostician/router-prompt-builder.js +11 -1
  141. package/core/dist/runtime/diagnostician/router-prompt-builder.js.map +1 -1
  142. package/core/dist/runtime/diagnostician-association-shadow.d.ts +2 -2
  143. package/core/dist/runtime/diagnostician-association-shadow.d.ts.map +1 -1
  144. package/core/dist/runtime/diagnostician-association-validation.d.ts +3 -2
  145. package/core/dist/runtime/diagnostician-association-validation.d.ts.map +1 -1
  146. package/core/dist/runtime/diagnostician-output.d.ts +32 -5
  147. package/core/dist/runtime/diagnostician-output.d.ts.map +1 -1
  148. package/core/dist/runtime/diagnostician-output.js +47 -4
  149. package/core/dist/runtime/diagnostician-output.js.map +1 -1
  150. package/core/dist/runtime/diagnostician-prompt-builder.d.ts +2 -1
  151. package/core/dist/runtime/diagnostician-prompt-builder.d.ts.map +1 -1
  152. package/core/dist/runtime/error-categories.d.ts.map +1 -1
  153. package/core/dist/runtime/error-categories.js +10 -1
  154. package/core/dist/runtime/error-categories.js.map +1 -1
  155. package/core/dist/runtime/evidence-sanitizer.d.ts +8 -1
  156. package/core/dist/runtime/evidence-sanitizer.d.ts.map +1 -1
  157. package/core/dist/runtime/evidence-sanitizer.js +10 -3
  158. package/core/dist/runtime/evidence-sanitizer.js.map +1 -1
  159. package/core/dist/runtime/evolution/evolution-types.d.ts +0 -26
  160. package/core/dist/runtime/evolution/evolution-types.d.ts.map +1 -1
  161. package/core/dist/runtime/evolution/evolution-types.js.map +1 -1
  162. package/core/dist/runtime/feature-flags/feature-flag-contract.d.ts.map +1 -1
  163. package/core/dist/runtime/feature-flags/feature-flag-contract.js +8 -0
  164. package/core/dist/runtime/feature-flags/feature-flag-contract.js.map +1 -1
  165. package/core/dist/runtime/feature-flags/feature-flag-lifecycle.d.ts.map +1 -1
  166. package/core/dist/runtime/feature-flags/feature-flag-lifecycle.js +24 -0
  167. package/core/dist/runtime/feature-flags/feature-flag-lifecycle.js.map +1 -1
  168. package/core/dist/runtime/feature-flags/index.d.ts +0 -1
  169. package/core/dist/runtime/feature-flags/index.d.ts.map +1 -1
  170. package/core/dist/runtime/feature-flags/index.js.map +1 -1
  171. package/core/dist/runtime/golden-trace.d.ts +9 -1
  172. package/core/dist/runtime/golden-trace.d.ts.map +1 -1
  173. package/core/dist/runtime/golden-trace.js +7 -0
  174. package/core/dist/runtime/golden-trace.js.map +1 -1
  175. package/core/dist/runtime/governance-projection-contract.d.ts +0 -6
  176. package/core/dist/runtime/governance-projection-contract.d.ts.map +1 -1
  177. package/core/dist/runtime/governance-projection-contract.js +3 -3
  178. package/core/dist/runtime/governance-projection-contract.js.map +1 -1
  179. package/core/dist/runtime/index.d.ts +2 -0
  180. package/core/dist/runtime/index.d.ts.map +1 -1
  181. package/core/dist/runtime/index.js +2 -0
  182. package/core/dist/runtime/index.js.map +1 -1
  183. package/core/dist/runtime/internalization/artifact-summary.d.ts +5 -4
  184. package/core/dist/runtime/internalization/artifact-summary.d.ts.map +1 -1
  185. package/core/dist/runtime/internalization/artifact-summary.js +1 -1
  186. package/core/dist/runtime/internalization/artifact-summary.js.map +1 -1
  187. package/core/dist/runtime/internalization/artificer-intent-preflight.d.ts +1 -1
  188. package/core/dist/runtime/internalization/artificer-intent-preflight.d.ts.map +1 -1
  189. package/core/dist/runtime/internalization/artificer-output.d.ts +0 -2
  190. package/core/dist/runtime/internalization/artificer-output.d.ts.map +1 -1
  191. package/core/dist/runtime/internalization/artificer-output.js +17 -0
  192. package/core/dist/runtime/internalization/artificer-output.js.map +1 -1
  193. package/core/dist/runtime/internalization/artificer-prompt-builder.d.ts +14 -3
  194. package/core/dist/runtime/internalization/artificer-prompt-builder.d.ts.map +1 -1
  195. package/core/dist/runtime/internalization/artificer-prompt-builder.js +13 -1
  196. package/core/dist/runtime/internalization/artificer-prompt-builder.js.map +1 -1
  197. package/core/dist/runtime/internalization/artificer-run-correlation.d.ts +3 -2
  198. package/core/dist/runtime/internalization/artificer-run-correlation.d.ts.map +1 -1
  199. package/core/dist/runtime/internalization/consumer-evidence-preflight.d.ts +2 -1
  200. package/core/dist/runtime/internalization/consumer-evidence-preflight.d.ts.map +1 -1
  201. package/core/dist/runtime/internalization/diag-distiller-runner.d.ts +1 -1
  202. package/core/dist/runtime/internalization/diag-distiller-runner.d.ts.map +1 -1
  203. package/core/dist/runtime/internalization/diag-rootcause-runner.d.ts +1 -1
  204. package/core/dist/runtime/internalization/diag-rootcause-runner.d.ts.map +1 -1
  205. package/core/dist/runtime/internalization/diag-router-runner.d.ts +11 -1
  206. package/core/dist/runtime/internalization/diag-router-runner.d.ts.map +1 -1
  207. package/core/dist/runtime/internalization/diag-router-runner.js +105 -1
  208. package/core/dist/runtime/internalization/diag-router-runner.js.map +1 -1
  209. package/core/dist/runtime/internalization/dreamer-output.d.ts +0 -9
  210. package/core/dist/runtime/internalization/dreamer-output.d.ts.map +1 -1
  211. package/core/dist/runtime/internalization/dreamer-output.js +1 -1
  212. package/core/dist/runtime/internalization/dreamer-output.js.map +1 -1
  213. package/core/dist/runtime/internalization/dreamer-prompt-builder.d.ts +3 -2
  214. package/core/dist/runtime/internalization/dreamer-prompt-builder.d.ts.map +1 -1
  215. package/core/dist/runtime/internalization/dreamer-runner.d.ts +1 -1
  216. package/core/dist/runtime/internalization/dreamer-runner.d.ts.map +1 -1
  217. package/core/dist/runtime/internalization/evaluator-output.d.ts +7 -17
  218. package/core/dist/runtime/internalization/evaluator-output.d.ts.map +1 -1
  219. package/core/dist/runtime/internalization/evaluator-output.js +2 -2
  220. package/core/dist/runtime/internalization/evaluator-output.js.map +1 -1
  221. package/core/dist/runtime/internalization/evaluator-prompt-builder.d.ts +3 -9
  222. package/core/dist/runtime/internalization/evaluator-prompt-builder.d.ts.map +1 -1
  223. package/core/dist/runtime/internalization/evaluator-prompt-builder.js +1 -1
  224. package/core/dist/runtime/internalization/evaluator-prompt-builder.js.map +1 -1
  225. package/core/dist/runtime/internalization/formation-context.d.ts +4 -6
  226. package/core/dist/runtime/internalization/formation-context.d.ts.map +1 -1
  227. package/core/dist/runtime/internalization/formation-context.js +3 -3
  228. package/core/dist/runtime/internalization/formation-context.js.map +1 -1
  229. package/core/dist/runtime/internalization/index.d.ts +2 -4
  230. package/core/dist/runtime/internalization/index.d.ts.map +1 -1
  231. package/core/dist/runtime/internalization/index.js +8 -1
  232. package/core/dist/runtime/internalization/index.js.map +1 -1
  233. package/core/dist/runtime/internalization/intake-to-internalization-bridge.d.ts +2 -1
  234. package/core/dist/runtime/internalization/intake-to-internalization-bridge.d.ts.map +1 -1
  235. package/core/dist/runtime/internalization/intent-contract.d.ts +2 -1
  236. package/core/dist/runtime/internalization/intent-contract.d.ts.map +1 -1
  237. package/core/dist/runtime/internalization/internalization-job-graph.d.ts +1 -1
  238. package/core/dist/runtime/internalization/internalization-job-graph.d.ts.map +1 -1
  239. package/core/dist/runtime/internalization/internalization-route.d.ts +2 -1
  240. package/core/dist/runtime/internalization/internalization-route.d.ts.map +1 -1
  241. package/core/dist/runtime/internalization/owner-decision-review.d.ts +3 -2
  242. package/core/dist/runtime/internalization/owner-decision-review.d.ts.map +1 -1
  243. package/core/dist/runtime/internalization/owner-resolution-service.d.ts +2 -1
  244. package/core/dist/runtime/internalization/owner-resolution-service.d.ts.map +1 -1
  245. package/core/dist/runtime/internalization/owner-retry.d.ts +2 -1
  246. package/core/dist/runtime/internalization/owner-retry.d.ts.map +1 -1
  247. package/core/dist/runtime/internalization/owner-review.d.ts +2 -21
  248. package/core/dist/runtime/internalization/owner-review.d.ts.map +1 -1
  249. package/core/dist/runtime/internalization/owner-review.js +2 -2
  250. package/core/dist/runtime/internalization/owner-review.js.map +1 -1
  251. package/core/dist/runtime/internalization/peer-runner-contracts.d.ts +2 -5
  252. package/core/dist/runtime/internalization/peer-runner-contracts.d.ts.map +1 -1
  253. package/core/dist/runtime/internalization/peer-runner-contracts.js +1 -1
  254. package/core/dist/runtime/internalization/peer-runner-contracts.js.map +1 -1
  255. package/core/dist/runtime/internalization/philosopher-output.d.ts +0 -8
  256. package/core/dist/runtime/internalization/philosopher-output.d.ts.map +1 -1
  257. package/core/dist/runtime/internalization/philosopher-output.js +1 -1
  258. package/core/dist/runtime/internalization/philosopher-output.js.map +1 -1
  259. package/core/dist/runtime/internalization/philosopher-prompt-builder.d.ts +3 -2
  260. package/core/dist/runtime/internalization/philosopher-prompt-builder.d.ts.map +1 -1
  261. package/core/dist/runtime/internalization/pitask-metadata.d.ts +1 -1
  262. package/core/dist/runtime/internalization/pitask-metadata.d.ts.map +1 -1
  263. package/core/dist/runtime/internalization/repair-replay-resolver.d.ts +4 -3
  264. package/core/dist/runtime/internalization/repair-replay-resolver.d.ts.map +1 -1
  265. package/core/dist/runtime/internalization/rollout-reviewer-output.d.ts +2 -3
  266. package/core/dist/runtime/internalization/rollout-reviewer-output.d.ts.map +1 -1
  267. package/core/dist/runtime/internalization/rollout-reviewer-output.js.map +1 -1
  268. package/core/dist/runtime/internalization/rollout-reviewer-prompt-builder.d.ts +0 -1
  269. package/core/dist/runtime/internalization/rollout-reviewer-prompt-builder.d.ts.map +1 -1
  270. package/core/dist/runtime/internalization/rollout-reviewer-prompt-builder.js +1 -1
  271. package/core/dist/runtime/internalization/rollout-reviewer-prompt-builder.js.map +1 -1
  272. package/core/dist/runtime/internalization/router-context-reconstruction.d.ts +3 -3
  273. package/core/dist/runtime/internalization/router-context-reconstruction.d.ts.map +1 -1
  274. package/core/dist/runtime/internalization/rule-activation-contract.d.ts +3 -2
  275. package/core/dist/runtime/internalization/rule-activation-contract.d.ts.map +1 -1
  276. package/core/dist/runtime/internalization/rule-host-input-builder.d.ts +16 -0
  277. package/core/dist/runtime/internalization/rule-host-input-builder.d.ts.map +1 -1
  278. package/core/dist/runtime/internalization/rule-host-input-builder.js +18 -0
  279. package/core/dist/runtime/internalization/rule-host-input-builder.js.map +1 -1
  280. package/core/dist/runtime/internalization/rule-reliability-validation.d.ts +13 -18
  281. package/core/dist/runtime/internalization/rule-reliability-validation.d.ts.map +1 -1
  282. package/core/dist/runtime/internalization/rule-reliability-validation.js +43 -1
  283. package/core/dist/runtime/internalization/rule-reliability-validation.js.map +1 -1
  284. package/core/dist/runtime/internalization/scribe-output.d.ts +2 -15
  285. package/core/dist/runtime/internalization/scribe-output.d.ts.map +1 -1
  286. package/core/dist/runtime/internalization/scribe-output.js +2 -2
  287. package/core/dist/runtime/internalization/scribe-output.js.map +1 -1
  288. package/core/dist/runtime/internalization/scribe-prompt-builder.d.ts +3 -3
  289. package/core/dist/runtime/internalization/scribe-prompt-builder.d.ts.map +1 -1
  290. package/core/dist/runtime/internalization/scribe-prompt-builder.js +0 -1
  291. package/core/dist/runtime/internalization/scribe-prompt-builder.js.map +1 -1
  292. package/core/dist/runtime/internalization/split-diagnostician-runner.d.ts +25 -1
  293. package/core/dist/runtime/internalization/split-diagnostician-runner.d.ts.map +1 -1
  294. package/core/dist/runtime/internalization/split-diagnostician-runner.js +122 -5
  295. package/core/dist/runtime/internalization/split-diagnostician-runner.js.map +1 -1
  296. package/core/dist/runtime/internalization/textual-basis-anchor.d.ts +3 -6
  297. package/core/dist/runtime/internalization/textual-basis-anchor.d.ts.map +1 -1
  298. package/core/dist/runtime/internalization/textual-basis-anchor.js +2 -2
  299. package/core/dist/runtime/internalization/textual-basis-anchor.js.map +1 -1
  300. package/core/dist/runtime/internalization/tool-semantic-registry.d.ts +26 -0
  301. package/core/dist/runtime/internalization/tool-semantic-registry.d.ts.map +1 -1
  302. package/core/dist/runtime/internalization/tool-semantic-registry.js +55 -5
  303. package/core/dist/runtime/internalization/tool-semantic-registry.js.map +1 -1
  304. package/core/dist/runtime/internalization-chain-integrity-read-model.d.ts.map +1 -1
  305. package/core/dist/runtime/internalization-chain-integrity-read-model.js +2 -2
  306. package/core/dist/runtime/internalization-chain-integrity-read-model.js.map +1 -1
  307. package/core/dist/runtime/internalization-integrity-remediation.d.ts.map +1 -1
  308. package/core/dist/runtime/internalization-integrity-remediation.js +2 -2
  309. package/core/dist/runtime/internalization-integrity-remediation.js.map +1 -1
  310. package/core/dist/runtime/language-directive.d.ts +2 -1
  311. package/core/dist/runtime/language-directive.d.ts.map +1 -1
  312. package/core/dist/runtime/operator-health-read-model.d.ts.map +1 -1
  313. package/core/dist/runtime/operator-health-read-model.js +2 -2
  314. package/core/dist/runtime/operator-health-read-model.js.map +1 -1
  315. package/core/dist/runtime/owner-decision/owner-decision-view-contract.d.ts +3 -29
  316. package/core/dist/runtime/owner-decision/owner-decision-view-contract.d.ts.map +1 -1
  317. package/core/dist/runtime/owner-decision/owner-decision-view-contract.js +4 -5
  318. package/core/dist/runtime/owner-decision/owner-decision-view-contract.js.map +1 -1
  319. package/core/dist/runtime/owner-decision/owner-decision-view.d.ts +0 -49
  320. package/core/dist/runtime/owner-decision/owner-decision-view.d.ts.map +1 -1
  321. package/core/dist/runtime/owner-decision/owner-decision-view.js +5 -5
  322. package/core/dist/runtime/owner-decision/owner-decision-view.js.map +1 -1
  323. package/core/dist/runtime/owner-decision/semantic-selector.d.ts +3 -2
  324. package/core/dist/runtime/owner-decision/semantic-selector.d.ts.map +1 -1
  325. package/core/dist/runtime/owner-identity.d.ts +12 -1
  326. package/core/dist/runtime/owner-identity.d.ts.map +1 -1
  327. package/core/dist/runtime/owner-identity.js +19 -1
  328. package/core/dist/runtime/owner-identity.js.map +1 -1
  329. package/core/dist/runtime/pain-ingress-payload.d.ts +0 -39
  330. package/core/dist/runtime/pain-ingress-payload.d.ts.map +1 -1
  331. package/core/dist/runtime/pain-ingress-payload.js +4 -4
  332. package/core/dist/runtime/pain-ingress-payload.js.map +1 -1
  333. package/core/dist/runtime/pain-ingress.d.ts +1 -1
  334. package/core/dist/runtime/pain-ingress.d.ts.map +1 -1
  335. package/core/dist/runtime/pain-ingress.js.map +1 -1
  336. package/core/dist/runtime/pain-recall-read-model.d.ts.map +1 -1
  337. package/core/dist/runtime/pain-recall-read-model.js +4 -3
  338. package/core/dist/runtime/pain-recall-read-model.js.map +1 -1
  339. package/core/dist/runtime/pain-signal-bridge.d.ts +0 -2
  340. package/core/dist/runtime/pain-signal-bridge.d.ts.map +1 -1
  341. package/core/dist/runtime/pain-signal-bridge.js +1 -1
  342. package/core/dist/runtime/pain-signal-bridge.js.map +1 -1
  343. package/core/dist/runtime/pain-signal-runtime-factory.d.ts +3 -3
  344. package/core/dist/runtime/pain-signal-runtime-factory.d.ts.map +1 -1
  345. package/core/dist/runtime/pain-signal-runtime-factory.js +1 -1
  346. package/core/dist/runtime/pain-signal-runtime-factory.js.map +1 -1
  347. package/core/dist/runtime/principle-reuse/reuse-proposal.d.ts +3 -2
  348. package/core/dist/runtime/principle-reuse/reuse-proposal.d.ts.map +1 -1
  349. package/core/dist/runtime/principle-reuse/reuse-retrieval.d.ts +0 -10
  350. package/core/dist/runtime/principle-reuse/reuse-retrieval.d.ts.map +1 -1
  351. package/core/dist/runtime/principle-reuse/reuse-retrieval.js +1 -1
  352. package/core/dist/runtime/principle-reuse/reuse-retrieval.js.map +1 -1
  353. package/core/dist/runtime/principle-reuse/reuse-shortlist.d.ts +1 -8
  354. package/core/dist/runtime/principle-reuse/reuse-shortlist.d.ts.map +1 -1
  355. package/core/dist/runtime/principle-reuse/reuse-shortlist.js +1 -1
  356. package/core/dist/runtime/principle-reuse/reuse-shortlist.js.map +1 -1
  357. package/core/dist/runtime/product-telemetry/snapshot-contract.d.ts +3 -2
  358. package/core/dist/runtime/product-telemetry/snapshot-contract.d.ts.map +1 -1
  359. package/core/dist/runtime/pruning-read-model.d.ts.map +1 -1
  360. package/core/dist/runtime/pruning-read-model.js +3 -2
  361. package/core/dist/runtime/pruning-read-model.js.map +1 -1
  362. package/core/dist/runtime/risk/risk-calculator-policy.d.ts +12 -2
  363. package/core/dist/runtime/risk/risk-calculator-policy.d.ts.map +1 -1
  364. package/core/dist/runtime/risk/risk-calculator-policy.js +33 -22
  365. package/core/dist/runtime/risk/risk-calculator-policy.js.map +1 -1
  366. package/core/dist/runtime/runner/base-peer-runner.d.ts +32 -0
  367. package/core/dist/runtime/runner/base-peer-runner.d.ts.map +1 -1
  368. package/core/dist/runtime/runner/base-peer-runner.js +168 -16
  369. package/core/dist/runtime/runner/base-peer-runner.js.map +1 -1
  370. package/core/dist/runtime/runner/default-validator.d.ts +0 -1
  371. package/core/dist/runtime/runner/default-validator.d.ts.map +1 -1
  372. package/core/dist/runtime/runner/default-validator.js +11 -3
  373. package/core/dist/runtime/runner/default-validator.js.map +1 -1
  374. package/core/dist/runtime/runner/peer-runner-types.d.ts +11 -0
  375. package/core/dist/runtime/runner/peer-runner-types.d.ts.map +1 -1
  376. package/core/dist/runtime/schema-conformance-read-model.js +2 -2
  377. package/core/dist/runtime/schema-conformance-read-model.js.map +1 -1
  378. package/core/dist/runtime/storage-paths.d.ts +15 -0
  379. package/core/dist/runtime/storage-paths.d.ts.map +1 -0
  380. package/core/dist/runtime/storage-paths.js +15 -0
  381. package/core/dist/runtime/storage-paths.js.map +1 -0
  382. package/core/dist/runtime/store/artifact/index.d.ts +1 -1
  383. package/core/dist/runtime/store/artifact/index.d.ts.map +1 -1
  384. package/core/dist/runtime/store/candidate/admission-document.d.ts +4 -3
  385. package/core/dist/runtime/store/candidate/admission-document.d.ts.map +1 -1
  386. package/core/dist/runtime/store/commit/index.d.ts +0 -1
  387. package/core/dist/runtime/store/commit/index.d.ts.map +1 -1
  388. package/core/dist/runtime/store/commit/index.js.map +1 -1
  389. package/core/dist/runtime/store/design-gate/sqlite-design-gate-store.d.ts +4 -3
  390. package/core/dist/runtime/store/design-gate/sqlite-design-gate-store.d.ts.map +1 -1
  391. package/core/dist/runtime/store/lifecycle/lease-manager.d.ts +2 -1
  392. package/core/dist/runtime/store/lifecycle/lease-manager.d.ts.map +1 -1
  393. package/core/dist/runtime/store/runtime-state-manager.d.ts +1 -2
  394. package/core/dist/runtime/store/runtime-state-manager.d.ts.map +1 -1
  395. package/core/dist/runtime/store/runtime-state-manager.js.map +1 -1
  396. package/core/dist/runtime/store/sqlite-connection.d.ts +2 -6
  397. package/core/dist/runtime/store/sqlite-connection.d.ts.map +1 -1
  398. package/core/dist/runtime/store/sqlite-connection.js +4 -12
  399. package/core/dist/runtime/store/sqlite-connection.js.map +1 -1
  400. package/core/dist/runtime/store/storage-paths.d.ts +17 -0
  401. package/core/dist/runtime/store/storage-paths.d.ts.map +1 -0
  402. package/core/dist/runtime/store/storage-paths.js +52 -0
  403. package/core/dist/runtime/store/storage-paths.js.map +1 -0
  404. package/core/dist/runtime/store/task/sqlite-family-reopen.d.ts +2 -1
  405. package/core/dist/runtime/store/task/sqlite-family-reopen.d.ts.map +1 -1
  406. package/core/dist/runtime/store/task/sqlite-task-store.d.ts +2 -1
  407. package/core/dist/runtime/store/task/sqlite-task-store.d.ts.map +1 -1
  408. package/core/dist/runtime/story-a-demo.d.ts.map +1 -1
  409. package/core/dist/runtime/story-a-demo.js +4 -1
  410. package/core/dist/runtime/story-a-demo.js.map +1 -1
  411. package/core/dist/runtime/tools/agent-tool-contract.d.ts +1 -2
  412. package/core/dist/runtime/tools/agent-tool-contract.d.ts.map +1 -1
  413. package/core/dist/runtime/tools/agent-tool-contract.js +0 -2
  414. package/core/dist/runtime/tools/agent-tool-contract.js.map +1 -1
  415. package/core/dist/runtime/tools/artificer-l2-tool-contract.d.ts +0 -2
  416. package/core/dist/runtime/tools/artificer-l2-tool-contract.d.ts.map +1 -1
  417. package/core/dist/runtime/tools/artificer-l2-tool-contract.js +0 -2
  418. package/core/dist/runtime/tools/artificer-l2-tool-contract.js.map +1 -1
  419. package/core/dist/runtime/trajectory-retention.d.ts +257 -0
  420. package/core/dist/runtime/trajectory-retention.d.ts.map +1 -0
  421. package/core/dist/runtime/trajectory-retention.js +598 -0
  422. package/core/dist/runtime/trajectory-retention.js.map +1 -0
  423. package/core/dist/runtime/types/event-payload.d.ts +0 -2
  424. package/core/dist/runtime/types/event-payload.d.ts.map +1 -1
  425. package/core/dist/runtime/types/event-payload.js.map +1 -1
  426. package/core/dist/runtime/types/evidence-chain-contract.d.ts +66 -2
  427. package/core/dist/runtime/types/evidence-chain-contract.d.ts.map +1 -1
  428. package/core/dist/runtime/types/evidence-chain-contract.js +69 -4
  429. package/core/dist/runtime/types/evidence-chain-contract.js.map +1 -1
  430. package/core/dist/runtime/types/hygiene-types.d.ts +0 -6
  431. package/core/dist/runtime/types/hygiene-types.d.ts.map +1 -1
  432. package/core/dist/runtime/types/hygiene-types.js.map +1 -1
  433. package/core/dist/runtime/types/index.d.ts +1 -1
  434. package/core/dist/runtime/types/index.d.ts.map +1 -1
  435. package/core/dist/runtime/types/index.js.map +1 -1
  436. package/core/dist/runtime/types/intervention-evidence-contract.d.ts +5 -5
  437. package/core/dist/runtime/types/intervention-evidence-contract.d.ts.map +1 -1
  438. package/core/dist/runtime/types/intervention-evidence-contract.js +0 -2
  439. package/core/dist/runtime/types/intervention-evidence-contract.js.map +1 -1
  440. package/core/dist/runtime/types/principle-dependency.d.ts +0 -2
  441. package/core/dist/runtime/types/principle-dependency.d.ts.map +1 -1
  442. package/core/dist/runtime/types/principle-dependency.js.map +1 -1
  443. package/core/dist/runtime/types/principle-lifecycle-event.d.ts +0 -2
  444. package/core/dist/runtime/types/principle-lifecycle-event.d.ts.map +1 -1
  445. package/core/dist/runtime/types/principle-lifecycle-event.js.map +1 -1
  446. package/core/dist/runtime/types/principle-schema.d.ts +0 -26
  447. package/core/dist/runtime/types/principle-schema.d.ts.map +1 -1
  448. package/core/dist/runtime/types/principle-schema.js +2 -2
  449. package/core/dist/runtime/types/principle-schema.js.map +1 -1
  450. package/core/dist/runtime/types/principle-tree-store.d.ts +0 -2
  451. package/core/dist/runtime/types/principle-tree-store.d.ts.map +1 -1
  452. package/core/dist/runtime/types/principle-tree-store.js.map +1 -1
  453. package/core/dist/runtime/types/principle-value-metrics.d.ts +0 -2
  454. package/core/dist/runtime/types/principle-value-metrics.d.ts.map +1 -1
  455. package/core/dist/runtime/types/principle-value-metrics.js.map +1 -1
  456. package/core/dist/runtime/types/rule-candidate-binding.d.ts +2 -1
  457. package/core/dist/runtime/types/rule-candidate-binding.d.ts.map +1 -1
  458. package/core/dist/telemetry-event.d.ts +2 -2
  459. package/core/dist/telemetry-event.d.ts.map +1 -1
  460. package/core/dist/telemetry-event.js +11 -0
  461. package/core/dist/telemetry-event.js.map +1 -1
  462. package/core/dist/trajectory-store.d.ts +9 -9
  463. package/core/dist/trajectory-store.d.ts.map +1 -1
  464. package/core/dist/trajectory-store.js +9 -12
  465. package/core/dist/trajectory-store.js.map +1 -1
  466. package/core/package.json +5 -1
  467. package/dist/installers/codex-host-installer.d.ts +9 -0
  468. package/dist/installers/codex-host-installer.d.ts.map +1 -1
  469. package/dist/installers/codex-host-installer.js +127 -6
  470. package/dist/installers/codex-host-installer.js.map +1 -1
  471. package/dist/installers/mcp-binding-shape-mirror.d.ts +27 -0
  472. package/dist/installers/mcp-binding-shape-mirror.d.ts.map +1 -0
  473. package/dist/installers/mcp-binding-shape-mirror.js +105 -0
  474. package/dist/installers/mcp-binding-shape-mirror.js.map +1 -0
  475. package/dist/skill-catalog.d.ts +35 -0
  476. package/dist/skill-catalog.d.ts.map +1 -0
  477. package/dist/skill-catalog.js +85 -0
  478. package/dist/skill-catalog.js.map +1 -0
  479. package/dist/skill-delivery-parity.d.ts +22 -0
  480. package/dist/skill-delivery-parity.d.ts.map +1 -0
  481. package/dist/skill-delivery-parity.js +31 -0
  482. package/dist/skill-delivery-parity.js.map +1 -0
  483. package/dist/update/product-identity.d.ts.map +1 -1
  484. package/dist/update/product-identity.js +5 -1
  485. package/dist/update/product-identity.js.map +1 -1
  486. package/host-runtime/dist/active-principle-prompt.d.ts +13 -0
  487. package/host-runtime/dist/active-principle-prompt.js +87 -10
  488. package/host-runtime/dist/adaptive-decision-protocol.d.ts +129 -0
  489. package/host-runtime/dist/adaptive-decision-protocol.js +176 -0
  490. package/host-runtime/dist/adaptive-priority-provider.d.ts +38 -13
  491. package/host-runtime/dist/adaptive-priority-provider.js +70 -66
  492. package/host-runtime/dist/adaptive-selection.d.ts +71 -64
  493. package/host-runtime/dist/adaptive-selection.js +220 -329
  494. package/host-runtime/dist/adaptive-skip-decision.d.ts +26 -14
  495. package/host-runtime/dist/adaptive-skip-decision.js +33 -29
  496. package/host-runtime/dist/codex-disclosure.d.ts +12 -7
  497. package/host-runtime/dist/codex-disclosure.js +12 -7
  498. package/host-runtime/dist/codex-rule-context-provider.js +4 -1
  499. package/host-runtime/dist/conversation-ingestion/pipeline.d.ts +8 -0
  500. package/host-runtime/dist/conversation-ingestion/pipeline.js +6 -1
  501. package/host-runtime/dist/conversation-ingestion/text-policy.d.ts +3 -4
  502. package/host-runtime/dist/conversation-ingestion/text-policy.js +3 -4
  503. package/host-runtime/dist/governance-observation-store.d.ts +73 -1
  504. package/host-runtime/dist/governance-observation-store.js +251 -14
  505. package/host-runtime/dist/governance-signal-admission.d.ts +19 -3
  506. package/host-runtime/dist/governance-signal-admission.js +12 -4
  507. package/host-runtime/dist/host-tool-declaration.d.ts +18 -2
  508. package/host-runtime/dist/host-tool-declaration.js +67 -11
  509. package/host-runtime/dist/host-tool-semantic-resolver.d.ts +7 -0
  510. package/host-runtime/dist/host-tool-semantic-resolver.js +22 -2
  511. package/host-runtime/dist/index.d.ts +3 -0
  512. package/host-runtime/dist/index.js +17 -0
  513. package/host-runtime/dist/production-rulehost-gate.d.ts +36 -1
  514. package/host-runtime/dist/production-rulehost-gate.js +106 -4
  515. package/host-runtime/dist/trajectory-retention.d.ts +147 -0
  516. package/host-runtime/dist/trajectory-retention.js +907 -0
  517. package/host-runtime/package.json +1 -1
  518. package/install-layout/dist/index.d.ts +9 -2
  519. package/install-layout/dist/index.js +26 -9
  520. package/install-layout/dist/mcp-binding-contract.d.ts +91 -0
  521. package/install-layout/dist/mcp-binding-contract.js +230 -0
  522. package/install-layout/package.json +1 -1
  523. package/package.json +4 -4
  524. package/pd-cli/dist/commands/build-trajectory-evidence.d.ts.map +1 -1
  525. package/pd-cli/dist/commands/build-trajectory-evidence.js +17 -11
  526. package/pd-cli/dist/commands/build-trajectory-evidence.js.map +1 -1
  527. package/pd-cli/dist/commands/codex-reconcile.d.ts +7 -0
  528. package/pd-cli/dist/commands/codex-reconcile.d.ts.map +1 -1
  529. package/pd-cli/dist/commands/codex-reconcile.js +11 -2
  530. package/pd-cli/dist/commands/codex-reconcile.js.map +1 -1
  531. package/pd-cli/dist/commands/codex-worker.d.ts.map +1 -1
  532. package/pd-cli/dist/commands/codex-worker.js +35 -0
  533. package/pd-cli/dist/commands/codex-worker.js.map +1 -1
  534. package/pd-cli/dist/commands/command-helpers.d.ts +1 -1
  535. package/pd-cli/dist/commands/command-helpers.js +1 -1
  536. package/pd-cli/dist/commands/diagnose.js +1 -1
  537. package/pd-cli/dist/commands/diagnose.js.map +1 -1
  538. package/pd-cli/dist/commands/errors-list.d.ts +1 -1
  539. package/pd-cli/dist/commands/errors-list.js +1 -1
  540. package/pd-cli/dist/commands/health-ingestion.d.ts +96 -0
  541. package/pd-cli/dist/commands/health-ingestion.d.ts.map +1 -0
  542. package/pd-cli/dist/commands/health-ingestion.js +473 -0
  543. package/pd-cli/dist/commands/health-ingestion.js.map +1 -0
  544. package/pd-cli/dist/commands/health-mcp.d.ts +23 -1
  545. package/pd-cli/dist/commands/health-mcp.d.ts.map +1 -1
  546. package/pd-cli/dist/commands/health-mcp.js +81 -22
  547. package/pd-cli/dist/commands/health-mcp.js.map +1 -1
  548. package/pd-cli/dist/commands/health.d.ts +1 -1
  549. package/pd-cli/dist/commands/health.d.ts.map +1 -1
  550. package/pd-cli/dist/commands/health.js +22 -5
  551. package/pd-cli/dist/commands/health.js.map +1 -1
  552. package/pd-cli/dist/commands/principles-stats.d.ts +1 -1
  553. package/pd-cli/dist/commands/principles-stats.js +1 -1
  554. package/pd-cli/dist/commands/trajectory-retention.d.ts +23 -0
  555. package/pd-cli/dist/commands/trajectory-retention.d.ts.map +1 -0
  556. package/pd-cli/dist/commands/trajectory-retention.js +159 -0
  557. package/pd-cli/dist/commands/trajectory-retention.js.map +1 -0
  558. package/pd-cli/dist/commands/workbuddy-setup.d.ts +69 -0
  559. package/pd-cli/dist/commands/workbuddy-setup.d.ts.map +1 -0
  560. package/pd-cli/dist/commands/workbuddy-setup.js +379 -0
  561. package/pd-cli/dist/commands/workbuddy-setup.js.map +1 -0
  562. package/pd-cli/dist/commands/workbuddy-worker.d.ts.map +1 -1
  563. package/pd-cli/dist/commands/workbuddy-worker.js +42 -6
  564. package/pd-cli/dist/commands/workbuddy-worker.js.map +1 -1
  565. package/pd-cli/dist/index.d.ts +1 -7
  566. package/pd-cli/dist/index.d.ts.map +1 -1
  567. package/pd-cli/dist/index.js +15 -1201
  568. package/pd-cli/dist/index.js.map +1 -1
  569. package/pd-cli/dist/program.d.ts +17 -0
  570. package/pd-cli/dist/program.d.ts.map +1 -0
  571. package/pd-cli/dist/program.js +1263 -0
  572. package/pd-cli/dist/program.js.map +1 -0
  573. package/pd-cli/dist/services/delivery-surfaces.d.ts.map +1 -1
  574. package/pd-cli/dist/services/delivery-surfaces.js +7 -5
  575. package/pd-cli/dist/services/delivery-surfaces.js.map +1 -1
  576. package/pd-cli/dist/services/demo-story-a-runner.js +1 -1
  577. package/pd-cli/dist/services/demo-story-a-runner.js.map +1 -1
  578. package/pd-cli/dist/services/version-report.d.ts.map +1 -1
  579. package/pd-cli/dist/services/version-report.js +35 -5
  580. package/pd-cli/dist/services/version-report.js.map +1 -1
  581. package/pd-cli/package.json +1 -1
  582. package/pd-mcp-server/dist/version.d.ts +1 -1
  583. package/pd-mcp-server/dist/version.js +1 -1
  584. package/pd-mcp-server/package.json +3 -1
  585. package/plugin/dist/bundle.js +529 -468
  586. package/plugin/dist/constants/tools.d.ts +8 -1
  587. package/plugin/dist/core/experiment-workspace-guard.d.ts +25 -0
  588. package/plugin/dist/core/trajectory-retention-trigger.d.ts +13 -0
  589. package/plugin/dist/core/trajectory.d.ts +14 -0
  590. package/plugin/dist/hooks/gate-block-helper.d.ts +17 -0
  591. package/plugin/dist/hooks/gate.d.ts +6 -1
  592. package/plugin/dist/host-runtime/openclaw-host-runtime.d.ts +1 -0
  593. package/plugin/dist/index.d.ts +5 -0
  594. package/plugin/dist/openclaw.plugin.json +1 -1
  595. package/plugin/dist/rulehost-evidence.js +29 -23
  596. package/plugin/dist/templates/langs/en/skills/pd-cli-operator/SKILL.md +16 -5
  597. package/plugin/dist/templates/langs/en/skills/pd-control/SKILL.md +7 -6
  598. package/plugin/dist/templates/langs/en/skills/pd-pain-signal/SKILL.md +141 -28
  599. package/plugin/dist/templates/langs/en/skills/pd-review/SKILL.md +15 -1
  600. package/plugin/dist/templates/langs/zh/skills/pd-cli-operator/SKILL.md +16 -5
  601. package/plugin/dist/templates/langs/zh/skills/pd-control/SKILL.md +7 -6
  602. package/plugin/dist/templates/langs/zh/skills/pd-pain-signal/SKILL.md +142 -29
  603. package/plugin/dist/templates/langs/zh/skills/pd-review/SKILL.md +15 -1
  604. package/plugin/openclaw.plugin.json +1 -1
  605. package/plugin/package.json +1 -1
  606. package/plugin/templates/langs/en/skills/pd-cli-operator/SKILL.md +16 -5
  607. package/plugin/templates/langs/en/skills/pd-control/SKILL.md +7 -6
  608. package/plugin/templates/langs/en/skills/pd-pain-signal/SKILL.md +141 -28
  609. package/plugin/templates/langs/en/skills/pd-review/SKILL.md +15 -1
  610. package/plugin/templates/langs/zh/skills/pd-cli-operator/SKILL.md +16 -5
  611. package/plugin/templates/langs/zh/skills/pd-control/SKILL.md +7 -6
  612. package/plugin/templates/langs/zh/skills/pd-pain-signal/SKILL.md +142 -29
  613. package/plugin/templates/langs/zh/skills/pd-review/SKILL.md +15 -1
  614. package/release-manager/dist/installers/codex-host-installer.js +127 -6
  615. package/release-manager/dist/installers/mcp-binding-shape-mirror.js +105 -0
  616. package/release-manager/dist/update/product-identity.js +5 -1
  617. package/release-manager/package.json +1 -1
  618. package/workbuddy-adapter/dist/codec/input-decoder.d.ts +10 -0
  619. package/workbuddy-adapter/dist/codec/input-decoder.js +62 -5
  620. package/workbuddy-adapter/dist/host-adapter.js +1 -0
  621. package/workbuddy-adapter/dist/index.d.ts +1 -0
  622. package/workbuddy-adapter/dist/index.js +1 -0
  623. package/workbuddy-adapter/dist/ingestion/catch-up.d.ts +36 -0
  624. package/workbuddy-adapter/dist/ingestion/catch-up.js +166 -0
  625. package/workbuddy-adapter/dist/ingestion/encode-cwd.d.ts +6 -0
  626. package/workbuddy-adapter/dist/ingestion/encode-cwd.js +39 -0
  627. package/workbuddy-adapter/dist/ingestion/index.d.ts +13 -0
  628. package/workbuddy-adapter/dist/ingestion/index.js +13 -0
  629. package/workbuddy-adapter/dist/ingestion/ingestion.d.ts +46 -0
  630. package/workbuddy-adapter/dist/ingestion/ingestion.js +135 -0
  631. package/workbuddy-adapter/dist/ingestion/transcript-decoder.d.ts +70 -0
  632. package/workbuddy-adapter/dist/ingestion/transcript-decoder.js +554 -0
  633. package/workbuddy-adapter/dist/ingestion/transcript-path.d.ts +39 -0
  634. package/workbuddy-adapter/dist/ingestion/transcript-path.js +117 -0
  635. package/workbuddy-adapter/dist/ingestion/transcript-source.d.ts +15 -0
  636. package/workbuddy-adapter/dist/ingestion/transcript-source.js +152 -0
  637. package/workbuddy-adapter/dist/pd-hook.d.ts +8 -0
  638. package/workbuddy-adapter/dist/pd-hook.js +59 -2
  639. package/workbuddy-adapter/dist/worker/workspace-worker.d.ts +9 -0
  640. package/workbuddy-adapter/dist/worker/workspace-worker.js +46 -17
  641. package/workbuddy-adapter/package.json +1 -1
  642. package/workbuddy-adapter/plugin/hooks/hooks.json +11 -0
  643. package/workbuddy-adapter/plugin/skills/pd-cli-operator/SKILL.md +57 -19
  644. package/workbuddy-adapter/plugin/skills/pd-control/SKILL.md +21 -9
  645. package/workbuddy-adapter/plugin/skills/pd-pain-signal/SKILL.md +72 -61
  646. package/workbuddy-adapter/plugin/skills/pd-review/SKILL.md +27 -12
@@ -4,46 +4,42 @@
4
4
  * ONE implementation of the bounded "current turn → pick at most one candidate"
5
5
  * protocol, shared by the selector lab and the production host runtimes.
6
6
  *
7
- * Contract highlights (PRI-1122 measurement findings):
8
- * - Candidates are sent with a LOCALLY PRECOMPUTED digest. The model can only
9
- * copy it; it is never asked to compute a hash. A payload without digests
10
- * makes every `selected` answer invalid by construction.
7
+ * PRI-1182 replaced the free-form chat-completions selector with the verified
8
+ * Decisions scoring protocol (`scripts/dev/adaptive-selector-lab/diagnostic.mjs`):
9
+ * one POST carries every candidate's applicability condition plus one
10
+ * "insufficient context" condition; the model returns an INDEPENDENT score per
11
+ * question; PD validates and adjudicates locally
12
+ * (`adaptive-decision-protocol.ts`). The model is never asked to emit a
13
+ * decision, a ref, or a digest.
14
+ *
15
+ * Contract highlights, unchanged from PRI-1122:
11
16
  * - The incremental deadline is a FIRST-BYTE deadline, not a whole-generation
12
17
  * wall clock. Once the endpoint has started answering, generation is bounded
13
18
  * by its own window; late completions are still discarded.
14
19
  * - One real send per turn, zero retries, zero repair, zero provider fallback.
20
+ * - The host deadline can only shorten the request's own short limit.
15
21
  * - Diagnostics never carry the raw prompt, the raw response, or credentials.
16
22
  */
17
23
  import crypto from 'node:crypto';
18
- import { PDRuntimeError, PiAiRuntimeAdapter, StoreEventEmitter, } from '@principles/core/runtime';
19
- import { readPromptActivationCandidates } from './active-principle-prompt.js';
20
24
  import { revalidateAdaptivePrinciple } from './adaptive-principle-revalidation.js';
25
+ import { ADAPTIVE_DECISION_MAX_CANDIDATE_CHARS, adjudicateDecision, buildDecisionRequest, validateDecisionResponse, } from './adaptive-decision-protocol.js';
21
26
  export const ADAPTIVE_SELECTION_LIMITS = {
22
27
  maxCandidates: 12,
23
- maxCandidateChars: 600,
28
+ maxCandidateChars: ADAPTIVE_DECISION_MAX_CANDIDATE_CHARS,
24
29
  maxPriorMessages: 4,
25
30
  maxPriorMessageChars: 1200,
26
31
  maxInputChars: 6000,
27
- /** Admission (time-to-first-byte) deadline for the incremental step. */
28
- firstByteTimeoutMs: 10_000,
29
- /** Bounded completion window once the endpoint has started answering. */
30
- generationTimeoutMs: 10_000,
31
- maxOutputTokens: 512,
32
+ /** Total time from sending a decision request to validating the full response. */
33
+ requestTimeoutMs: 2000,
34
+ /** Bounded outbound payload (current instruction + candidate snapshot + conditions). */
35
+ maxPayloadChars: 20_000,
36
+ /** Bounded response body; a Decisions answer table is a few KB at most. */
37
+ maxResponseBytes: 65_536,
38
+ /** Bounded provider usage projection is unnecessary: only token counts are kept. */
32
39
  };
33
40
  export function hash(value) {
34
41
  return crypto.createHash('sha256').update(value, 'utf8').digest('hex');
35
42
  }
36
- export const ADAPTIVE_SELECTOR_SYSTEM = [
37
- '你是 Principles Disciple 的原则选择器。只判断:当前用户输入是否需要追加一条已批准原则。',
38
- '候选只在「当前输入明确要求交付、实现、修复、审查或验证,且这条原则会改变你这一步的做法」时才算适用。',
39
- '通用礼貌、闲聊、元问题、与当前任务无关的原则一律不选。',
40
- '只能返回下面三种 JSON 之一,不要 Markdown、不要解释:',
41
- '{"status":"selected","id":"候选引用(例如 c1)","digest":"该候选随附的 digest 原样复制;不要计算或改写","reason":"一句话理由"}',
42
- '{"status":"none_applicable","id":null,"digest":null,"reason":"一句话理由"}',
43
- '{"status":"uncertain","id":null,"digest":null,"reason":"一句话理由"}',
44
- 'digest 由本地预计算并随候选下发;必须逐字符原样返回所选候选的 digest。',
45
- '最多只能选一条。',
46
- ].join('\n');
47
43
  function boundText(value, max) {
48
44
  const text = value.replace(/\s+/gu, ' ').trim();
49
45
  if (text.length <= max)
@@ -71,11 +67,14 @@ export function buildBoundedSelectionInput(input) {
71
67
  if (!principle.text.trim())
72
68
  continue;
73
69
  const candidateText = boundText(principle.text, ADAPTIVE_SELECTION_LIMITS.maxCandidateChars);
70
+ const outgoing = input.replacementByActivationId?.get(principle.activationId);
74
71
  entries.push({
72
+ ...(outgoing ? { replaces: boundText(outgoing.text, ADAPTIVE_SELECTION_LIMITS.maxCandidateChars) } : {}),
75
73
  ref: `c${entries.length + 1}`,
76
74
  text: candidateText,
77
- // Digest the body exactly as it goes on the wire, so the model can copy it
78
- // and anyone can recompute it from the request it actually received.
75
+ // The digest stays part of the frozen candidate snapshot even though the
76
+ // Decisions protocol scores question ids instead of asking for a ref: it
77
+ // lets a later reader recompute exactly what was sent.
79
78
  digest: hash(candidateText),
80
79
  principle,
81
80
  });
@@ -90,8 +89,7 @@ export function buildBoundedSelectionInput(input) {
90
89
  payload: {
91
90
  currentInstruction,
92
91
  priorMessages: boundedPrior,
93
- // The digest is part of the outbound contract: the model copies it.
94
- candidates: entries.map((entry) => ({ ref: entry.ref, text: entry.text, digest: entry.digest })),
92
+ candidates: entries.map(({ ref, text, digest, replaces }) => ({ ref, text, digest, ...(replaces !== undefined ? { replaces } : {}) })),
95
93
  },
96
94
  entries,
97
95
  priorDropped: Math.max(0, priorMessages.length - selectedPrior.length),
@@ -102,152 +100,92 @@ export function buildBoundedSelectionInput(input) {
102
100
  function isRecord(value) {
103
101
  return value !== null && typeof value === 'object' && !Array.isArray(value);
104
102
  }
105
- export function parseSelectionShape(value) {
106
- if (!isRecord(value)) {
107
- return { ok: false, reason: 'SELECTION_OUTPUT_INVALID' };
108
- }
109
- const { status } = value;
110
- const { id } = value;
111
- const { digest } = value;
112
- if (status === 'selected') {
113
- if (typeof id !== 'string' || !id)
114
- return { ok: false, reason: 'SELECTION_OUTPUT_INVALID' };
115
- if (typeof digest !== 'string' || !digest)
116
- return { ok: false, reason: 'SELECTION_DIGEST_INVALID' };
117
- return { ok: true, selection: { status: 'selected', id, digest } };
118
- }
119
- if (status === 'none_applicable' || status === 'uncertain') {
120
- if (id !== null && id !== undefined)
121
- return { ok: false, reason: 'SELECTION_OUTPUT_INVALID' };
122
- if (digest !== null && digest !== undefined)
123
- return { ok: false, reason: 'SELECTION_OUTPUT_INVALID' };
124
- return { ok: true, selection: { status, id: null, digest: null } };
125
- }
126
- return { ok: false, reason: 'SELECTION_OUTPUT_INVALID' };
127
- }
128
- export function validateSelectionResult(value, entries) {
129
- const parsed = parseSelectionShape(value);
130
- if (!parsed.ok) {
131
- return {
132
- ok: false,
133
- reason: parsed.reason,
134
- refValid: null,
135
- digestValid: null,
136
- };
137
- }
138
- const { selection } = parsed;
139
- if (selection.status !== 'selected') {
140
- return {
141
- ok: true,
142
- selected: null,
143
- outcome: selection.status === 'uncertain' ? 'uncertain' : 'no_increment',
144
- };
145
- }
146
- const entry = entries.find((candidate) => candidate.ref === selection.id);
147
- if (!entry) {
148
- return { ok: false, reason: 'SELECTION_REFERENCE_INVALID', refValid: false, digestValid: null };
149
- }
150
- // Two independent computations of the wire-body digest must agree: the value
151
- // frozen into the candidate table and a fresh hash of the frozen body.
152
- if (selection.digest !== entry.digest || selection.digest !== hash(entry.text)) {
153
- return { ok: false, reason: 'SELECTION_DIGEST_INVALID', refValid: true, digestValid: false };
154
- }
155
- if (entries.some((candidate) => candidate !== entry && candidate.principle.principleId === entry.principle.principleId)) {
156
- return { ok: false, reason: 'SELECTION_AMBIGUOUS', refValid: true, digestValid: true };
157
- }
158
- return { ok: true, selected: entry, outcome: 'selected' };
159
- }
160
- export function localFailureCode(reason) {
161
- if (reason === 'SELECTION_OUTPUT_INVALID')
162
- return 'SELECTION_OUTPUT_INVALID';
163
- if (reason === 'SELECTION_DIGEST_INVALID')
164
- return 'SELECTION_DIGEST_INVALID';
165
- if (reason === 'SELECTION_REFERENCE_INVALID')
166
- return 'SELECTION_REFERENCE_INVALID';
167
- if (reason === 'SELECTION_AMBIGUOUS')
168
- return 'SELECTION_AMBIGUOUS';
169
- if (reason === 'SELECTION_EXPIRED')
170
- return 'SELECTION_EXPIRED';
171
- return 'SELECTION_OUTPUT_INVALID';
172
- }
173
103
  function outerDeadlineReached(now, outerDeadlineAt, signal) {
174
104
  // Without an outer deadline this is an ordinary caller signal; keep the
175
105
  // previous SELECTION_EXPIRED / TRANSPORT_FAILED classification for it.
176
106
  return outerDeadlineAt !== undefined && (signal?.aborted === true || now() >= outerDeadlineAt);
177
107
  }
178
- function emptyDiagnostics(admissionDeadlineAt) {
108
+ /**
109
+ * The provider caps every model window at the host deadline, so the host
110
+ * deadline can ALSO be the admission/generation deadline. Two timers then end
111
+ * at the same instant: either may run first, and `Date.now()` can still read
112
+ * one millisecond short of the deadline, which made "which controller
113
+ * aborted" decide the diagnostic. The expired window's own deadline is the
114
+ * authority (P4): when it is the host window, the host window is the cause.
115
+ */
116
+ function deadlineIsHostWindow(outerDeadlineAt, expiredAt) {
117
+ return outerDeadlineAt !== undefined && expiredAt !== null && expiredAt >= outerDeadlineAt;
118
+ }
119
+ function emptyDiagnostics() {
179
120
  return {
180
121
  stage: 'idle',
181
- admissionDeadlineAt,
122
+ requestDeadlineAt: null,
123
+ requestSentAt: null,
182
124
  completionDeadlineAt: null,
183
125
  firstByteAt: null,
184
126
  generationEndedAt: null,
127
+ validatedAt: null,
185
128
  cancelledAt: null,
186
129
  httpStatus: null,
187
130
  finishReason: 'unknown',
131
+ modelObserved: null,
132
+ providerObserved: null,
188
133
  usage: null,
134
+ decision: null,
189
135
  failures: [],
190
136
  };
191
137
  }
192
- function parseFinishMetadata(raw) {
193
- const result = { finishReason: 'unknown', usage: null };
194
- const absorb = (parsed) => {
195
- if (!isRecord(parsed))
196
- return;
197
- const { choices } = parsed;
198
- if (Array.isArray(choices) && choices.length > 0) {
199
- const [first] = choices;
200
- if (isRecord(first)) {
201
- const finish = first.finish_reason;
202
- if (typeof finish === 'string' && finish)
203
- result.finishReason = finish;
204
- }
205
- }
206
- const { usage } = parsed;
207
- if (isRecord(usage)) {
208
- const input = usage.prompt_tokens ?? usage.input_tokens;
209
- const output = usage.completion_tokens ?? usage.output_tokens;
210
- result.usage = {
211
- inputTokens: typeof input === 'number' ? input : null,
212
- outputTokens: typeof output === 'number' ? output : null,
213
- };
214
- }
138
+ function projectUsage(value) {
139
+ if (!isRecord(value))
140
+ return null;
141
+ const input = value.input_tokens ?? value.prompt_tokens;
142
+ const output = value.output_tokens ?? value.completion_tokens;
143
+ return {
144
+ inputTokens: typeof input === 'number' && Number.isFinite(input) ? input : null,
145
+ outputTokens: typeof output === 'number' && Number.isFinite(output) ? output : null,
215
146
  };
216
- const trimmed = raw.trim();
217
- if (!trimmed)
218
- return result;
219
- if (trimmed.startsWith('{') || trimmed.startsWith('[')) {
220
- try {
221
- absorb(JSON.parse(trimmed));
222
- return result;
223
- }
224
- catch {
225
- return result;
147
+ }
148
+ async function readBoundedBody(response, maxBytes, controller) {
149
+ if (!response.body) {
150
+ const text = await response.text();
151
+ if (Buffer.byteLength(text, 'utf8') > maxBytes) {
152
+ controller.abort(new Error('RESPONSE_TOO_LARGE'));
153
+ throw new Error('SELECTION_OUTPUT_INVALID');
226
154
  }
155
+ return text;
227
156
  }
228
- for (const line of trimmed.split(/\r?\n/u)) {
229
- const payload = line.startsWith('data:') ? line.slice(5).trim() : '';
230
- if (!payload || payload === '[DONE]')
231
- continue;
232
- try {
233
- absorb(JSON.parse(payload));
234
- }
235
- catch {
236
- // Ignore non-JSON keep-alives; diagnostics stay 'unknown' rather than guessing.
157
+ const reader = response.body.getReader();
158
+ const chunks = [];
159
+ let bytes = 0;
160
+ try {
161
+ for (;;) {
162
+ const part = await reader.read();
163
+ if (part.done)
164
+ break;
165
+ bytes += part.value.byteLength;
166
+ if (bytes > maxBytes) {
167
+ controller.abort(new Error('RESPONSE_TOO_LARGE'));
168
+ throw new Error('SELECTION_OUTPUT_INVALID');
169
+ }
170
+ chunks.push(Buffer.from(part.value));
237
171
  }
172
+ return Buffer.concat(chunks).toString('utf8');
173
+ }
174
+ finally {
175
+ reader.releaseLock();
238
176
  }
239
- return result;
240
177
  }
241
- export function createSingleModelSelector(options) {
178
+ /**
179
+ * One Decisions POST per turn. Every failure is classified at the transport
180
+ * edge; the caller never sees provider text, headers or credentials.
181
+ */
182
+ export function createDecisionSelector(options) {
242
183
  const now = options.now ?? Date.now;
243
- const Adapter = options.PiAiRuntimeAdapterImpl ?? PiAiRuntimeAdapter;
244
- const generationTimeoutMs = options.generationTimeoutMs ?? ADAPTIVE_SELECTION_LIMITS.generationTimeoutMs;
245
- const maxTokens = options.maxTokens ?? ADAPTIVE_SELECTION_LIMITS.maxOutputTokens;
246
- const diagnostics = emptyDiagnostics(options.admissionDeadlineAt);
184
+ const requestTimeoutMs = options.requestTimeoutMs ?? ADAPTIVE_SELECTION_LIMITS.requestTimeoutMs;
185
+ const diagnostics = emptyDiagnostics();
247
186
  let sends = 0;
248
187
  let status = 'not_sent';
249
188
  let failure = null;
250
- let finishMetadata = Promise.resolve({ finishReason: 'unknown', usage: null });
251
189
  const fail = (code) => {
252
190
  failure = code;
253
191
  status = 'failed';
@@ -261,179 +199,123 @@ export function createSingleModelSelector(options) {
261
199
  diagnostics.cancelledAt = now();
262
200
  fail('TURN_DEADLINE_EXCEEDED');
263
201
  }
264
- if (now() >= options.admissionDeadlineAt) {
265
- diagnostics.cancelledAt = now();
266
- fail('SELECTION_EXPIRED');
202
+ const apiKey = process.env[options.model.apiKeyEnv];
203
+ if (!apiKey)
204
+ fail('DECISION_CREDENTIAL_MISSING');
205
+ const body = JSON.stringify(input.body);
206
+ const sentAt = now();
207
+ if (outerDeadlineReached(() => sentAt, options.outerDeadlineAt, options.signal)) {
208
+ diagnostics.cancelledAt = sentAt;
209
+ fail('TURN_DEADLINE_EXCEEDED');
267
210
  }
268
- const remainingAdmission = Math.max(1, options.admissionDeadlineAt - now());
269
- const ttfbController = new AbortController();
270
- const ttfbTimer = setTimeout(() => ttfbController.abort(new Error('ADMISSION_DEADLINE')), remainingAdmission);
271
- ttfbTimer.unref?.();
272
- let firstByteAt = null;
273
- let completionDeadlineAt = null;
274
- const guardedFetch = async (resource, init) => {
275
- const url = resource instanceof Request ? resource.url : String(resource);
276
- const requestInit = init ?? {};
277
- if (options.model.url) {
278
- if (url !== options.model.url)
279
- fail('TRANSPORT_NOT_SENT');
280
- }
281
- else if (options.model.baseUrl) {
282
- if (!url.startsWith(options.model.baseUrl))
283
- fail('TRANSPORT_NOT_SENT');
284
- }
285
- else if (!url.startsWith('https://')) {
286
- fail('TRANSPORT_NOT_SENT');
287
- }
288
- let body;
289
- try {
290
- const parsed = typeof requestInit.body === 'string' ? JSON.parse(requestInit.body) : null;
291
- body = isRecord(parsed) ? parsed : null;
292
- }
293
- catch {
294
- body = null;
295
- }
296
- if (!body || body.model !== options.model.model)
297
- fail('TRANSPORT_NOT_SENT');
298
- if (body.max_tokens !== maxTokens)
299
- fail('TRANSPORT_NOT_SENT');
300
- const apiKey = process.env[options.model.apiKeyEnv];
301
- if (!apiKey)
302
- fail('TRANSPORT_NOT_SENT');
303
- sends += 1;
304
- status = 'sent';
305
- diagnostics.stage = 'admission';
306
- const combined = AbortSignal.any([
307
- ...(requestInit.signal ? [requestInit.signal] : []),
308
- ttfbController.signal,
309
- ...(options.signal ? [options.signal] : []),
310
- ]);
211
+ const deadlineAt = Math.min(sentAt + requestTimeoutMs, options.outerDeadlineAt ?? Infinity);
212
+ const controller = new AbortController();
213
+ const deadlineError = new Error('DECISION_DEADLINE');
214
+ const timer = setTimeout(() => controller.abort(deadlineError), Math.max(1, deadlineAt - sentAt));
215
+ timer.unref?.();
216
+ const signal = options.signal
217
+ ? AbortSignal.any([options.signal, controller.signal])
218
+ : controller.signal;
219
+ const expire = () => {
220
+ controller.abort(deadlineError);
221
+ diagnostics.cancelledAt = now();
222
+ return fail(outerDeadlineReached(now, options.outerDeadlineAt, options.signal)
223
+ || deadlineIsHostWindow(options.outerDeadlineAt, deadlineAt)
224
+ ? 'TURN_DEADLINE_EXCEEDED'
225
+ : 'SELECTION_EXPIRED');
226
+ };
227
+ const checkDeadline = () => {
228
+ if (outerDeadlineReached(now, options.outerDeadlineAt, options.signal)
229
+ || controller.signal.reason === deadlineError || now() >= deadlineAt)
230
+ expire();
231
+ };
232
+ sends += 1;
233
+ status = 'sent';
234
+ diagnostics.stage = 'admission';
235
+ diagnostics.requestSentAt = sentAt;
236
+ diagnostics.requestDeadlineAt = deadlineAt;
237
+ try {
311
238
  let response;
312
239
  try {
313
- response = await (options.fetchImpl ?? fetch)(url, { ...requestInit, signal: combined, redirect: 'error' });
240
+ response = await (options.fetchImpl ?? fetch)(options.model.endpoint, {
241
+ method: 'POST',
242
+ headers: {
243
+ 'Content-Type': 'application/json',
244
+ Authorization: `Bearer ${apiKey}`,
245
+ },
246
+ body,
247
+ signal,
248
+ redirect: 'error',
249
+ });
314
250
  }
315
- catch (error) {
316
- diagnostics.cancelledAt = now();
317
- diagnostics.stage = 'admission';
318
- fail(outerDeadlineReached(now, options.outerDeadlineAt, options.signal)
319
- ? 'TURN_DEADLINE_EXCEEDED'
320
- : ttfbController.signal.aborted ? 'SELECTION_EXPIRED' : 'TRANSPORT_FAILED');
321
- throw error;
251
+ catch {
252
+ checkDeadline();
253
+ return fail('TRANSPORT_FAILED');
322
254
  }
323
- // First byte is here: stop the admission clock, start the completion window.
324
- firstByteAt = now();
325
- diagnostics.firstByteAt = firstByteAt;
255
+ diagnostics.firstByteAt = now();
326
256
  diagnostics.httpStatus = response.status;
327
- clearTimeout(ttfbTimer);
328
- if (outerDeadlineReached(now, options.outerDeadlineAt, options.signal)) {
329
- diagnostics.cancelledAt = firstByteAt;
330
- fail('TURN_DEADLINE_EXCEEDED');
331
- }
332
- if (firstByteAt >= options.admissionDeadlineAt) {
333
- diagnostics.cancelledAt = firstByteAt;
334
- fail('SELECTION_EXPIRED');
257
+ checkDeadline();
258
+ if (!response.ok) {
259
+ controller.abort();
260
+ return fail('TRANSPORT_HTTP_ERROR');
335
261
  }
336
- // Headers arriving is not completion: the generation window may never
337
- // extend past the host deadline.
338
- completionDeadlineAt = options.outerDeadlineAt === undefined
339
- ? firstByteAt + generationTimeoutMs
340
- : Math.min(firstByteAt + generationTimeoutMs, options.outerDeadlineAt);
341
- diagnostics.completionDeadlineAt = completionDeadlineAt;
342
262
  diagnostics.stage = 'generation';
263
+ diagnostics.completionDeadlineAt = deadlineAt;
264
+ let raw;
343
265
  try {
344
- const clone = response.clone();
345
- finishMetadata = clone
346
- .text()
347
- .then((raw) => parseFinishMetadata(raw))
348
- .catch(() => ({ finishReason: 'unknown', usage: null }));
266
+ raw = await readBoundedBody(response, ADAPTIVE_SELECTION_LIMITS.maxResponseBytes, controller);
349
267
  }
350
268
  catch {
351
- finishMetadata = Promise.resolve({ finishReason: 'unknown', usage: null });
269
+ checkDeadline();
270
+ return fail('SELECTION_OUTPUT_INVALID');
352
271
  }
353
- return response;
354
- };
355
- try {
356
- const adapter = new Adapter({
357
- provider: options.model.provider,
358
- model: options.model.model,
359
- ...(options.model.baseUrl ? { baseUrl: options.model.baseUrl } : {}),
360
- apiKeyEnv: options.model.apiKeyEnv,
361
- maxRetries: 0,
362
- maxRepairAttempts: 0,
363
- outputPathStrategy: 'free_form_only',
364
- reasoning: 'low',
365
- timeoutMs: remainingAdmission + generationTimeoutMs,
366
- maxTokens,
367
- fetch: guardedFetch,
368
- eventEmitter: new StoreEventEmitter(),
369
- });
370
- let run;
272
+ checkDeadline();
273
+ let parsed;
371
274
  try {
372
- run = await adapter.startRun({
373
- agentSpec: { agentId: 'adaptive-principle-selector', schemaVersion: 'current' },
374
- inputPayload: input.payload,
375
- contextItems: [],
376
- // S5: the last caller that reached the adapter without a schema ref.
377
- // `adaptive-selection-output` is registered in OUTPUT_SCHEMA_REGISTRY
378
- // (principles-core), so the structural shape is validated by the
379
- // shared path instead of relying on the host guard alone.
380
- // Scope note: this is the ONLY change here. The admission/completion
381
- // deadline semantics are owned by PRI-1170 (merged as 030d0035,
382
- // #2513); they are intentionally untouched to avoid a second timing
383
- // system in this file.
384
- outputSchemaRef: 'adaptive-selection-output',
385
- timeoutMs: remainingAdmission + generationTimeoutMs,
386
- maxTokens,
387
- systemPrompt: ADAPTIVE_SELECTOR_SYSTEM,
388
- });
275
+ parsed = JSON.parse(raw);
389
276
  }
390
- catch (error) {
391
- // S5: now that the adapter validates the selection shape, a
392
- // structurally incomplete answer (e.g. `selected` without a digest)
393
- // is rejected there — before the host guard could label it
394
- // SELECTION_DIGEST_INVALID / SELECTION_REFERENCE_INVALID. Map it to
395
- // the host contract code so the reason stays diagnosable instead of
396
- // degrading to TRANSPORT_FAILED in runAdaptiveSelection (rc-9).
397
- if (error instanceof PDRuntimeError && error.category === 'output_invalid') {
398
- // An unregistered schema ref is a deployment fault, not a malformed
399
- // answer. Keeping the codes distinct stops operators from debugging
400
- // the model when the registry is the actual problem.
401
- fail(error.details?.parseFailureReason === 'unknown_output_schema_ref'
402
- ? 'SELECTION_SCHEMA_UNAVAILABLE'
403
- : 'SELECTION_OUTPUT_INVALID');
404
- }
405
- throw error;
277
+ catch {
278
+ return fail('SELECTION_OUTPUT_INVALID');
406
279
  }
407
- const output = await adapter.fetchOutput(run.runId);
408
280
  const endedAt = now();
409
281
  diagnostics.generationEndedAt = endedAt;
410
- if (outerDeadlineReached(now, options.outerDeadlineAt, options.signal)) {
411
- diagnostics.cancelledAt = endedAt;
412
- fail('TURN_DEADLINE_EXCEEDED');
413
- }
414
- if (!output)
415
- fail('SELECTION_OUTPUT_INVALID');
416
- if (completionDeadlineAt !== null && endedAt > completionDeadlineAt) {
417
- diagnostics.cancelledAt = endedAt;
418
- fail('SELECTION_EXPIRED');
282
+ checkDeadline();
283
+ diagnostics.usage = projectUsage(isRecord(parsed) ? parsed.usage : undefined);
284
+ // Record what the endpoint actually claimed BEFORE validating it, so the
285
+ // acceptance report can state observed model/provider instead of
286
+ // inferring a route from the request.
287
+ if (isRecord(parsed)) {
288
+ diagnostics.modelObserved = typeof parsed.model === 'string' ? parsed.model : null;
289
+ diagnostics.providerObserved = typeof parsed.provider === 'string' ? parsed.provider : null;
419
290
  }
420
- const metadata = await finishMetadata;
421
- diagnostics.finishReason = metadata.finishReason;
422
- diagnostics.usage = metadata.usage;
423
291
  diagnostics.stage = 'validate';
424
- return output.payload;
425
- }
426
- catch (error) {
427
- // An abort can surface while the adapter reads the body (the fetch call
428
- // itself already resolved), so classify it here, at the transport edge.
429
- if (outerDeadlineReached(now, options.outerDeadlineAt, options.signal)) {
430
- diagnostics.cancelledAt = now();
431
- fail('TURN_DEADLINE_EXCEEDED');
432
- }
433
- throw error;
292
+ const validated = validateDecisionResponse(parsed, {
293
+ model: options.model.model,
294
+ questionIds: input.questionIds,
295
+ ...(options.model.provider !== undefined ? { provider: options.model.provider } : {}),
296
+ ...(options.model.allowedResponseModels !== undefined
297
+ ? { allowedResponseModels: options.model.allowedResponseModels }
298
+ : {}),
299
+ });
300
+ if (!validated.ok)
301
+ return fail(validated.reason);
302
+ // The envelope is measured to a VALIDATED table, not to the last byte:
303
+ // a table that only parses after the completion deadline is expired even
304
+ // though the body arrived, so the caller never applies a late decision.
305
+ diagnostics.validatedAt = now();
306
+ checkDeadline();
307
+ diagnostics.finishReason = 'decisions';
308
+ const outcome = adjudicateDecision(validated.scores, input.candidates);
309
+ diagnostics.decision = {
310
+ status: outcome.status,
311
+ ref: outcome.ref,
312
+ reason: outcome.reason,
313
+ scores: validated.scores,
314
+ };
315
+ return outcome;
434
316
  }
435
317
  finally {
436
- clearTimeout(ttfbTimer);
318
+ clearTimeout(timer);
437
319
  }
438
320
  };
439
321
  return {
@@ -442,45 +324,48 @@ export function createSingleModelSelector(options) {
442
324
  };
443
325
  }
444
326
  /**
445
- * Minimal host-facing selection step: read the current frozen candidates,
446
- * make at most one bounded model call, verify ref+digest, then independently
447
- * revalidate the chosen principle's content/revision/authorization.
327
+ * Minimal host-facing selection step: use the current frozen Native gap,
328
+ * make at most one bounded Decisions request, adjudicate locally, then
329
+ * independently revalidate the chosen principle's content/revision/authorization.
448
330
  */
449
331
  export async function runAdaptiveSelection(options) {
450
- const earlyDiagnostics = emptyDiagnostics(options.admissionDeadlineAt);
332
+ const earlyDiagnostics = emptyDiagnostics();
451
333
  const unavailable = (reason, stage) => {
452
334
  earlyDiagnostics.stage = stage;
453
335
  return { status: 'unavailable', target: null, reason, sends: 0, diagnostics: earlyDiagnostics };
454
336
  };
455
- const read = await readPromptActivationCandidates({
456
- workspaceDir: options.workspaceDir,
457
- includeAuthority: true,
458
- });
459
- if (read.aborted || read.warnings.length > 0) {
460
- return unavailable(`candidates_unavailable:${read.warnings[0] ?? 'aborted'}`, 'idle');
461
- }
462
337
  const built = buildBoundedSelectionInput({
463
338
  currentInput: options.currentPrompt,
464
- candidates: read.principles,
339
+ candidates: options.candidates,
340
+ replacementByActivationId: options.replacementByActivationId,
465
341
  });
466
342
  if (!built.ok)
467
343
  return unavailable(built.reason, 'idle');
468
- const selector = createSingleModelSelector({
469
- admissionDeadlineAt: options.admissionDeadlineAt,
344
+ const request = buildDecisionRequest({
345
+ model: options.model.model,
346
+ ...(options.model.provider !== undefined ? { provider: options.model.provider } : {}),
347
+ currentInstruction: built.input.payload.currentInstruction,
348
+ priorMessages: built.input.payload.priorMessages,
349
+ candidates: built.input.payload.candidates,
350
+ maxPayloadChars: ADAPTIVE_SELECTION_LIMITS.maxPayloadChars,
351
+ });
352
+ if (!request.ok)
353
+ return unavailable(request.reason, 'idle');
354
+ const selector = createDecisionSelector({
470
355
  model: options.model,
471
- ...(options.generationTimeoutMs !== undefined ? { generationTimeoutMs: options.generationTimeoutMs } : {}),
472
- ...(options.maxTokens !== undefined ? { maxTokens: options.maxTokens } : {}),
356
+ ...(options.requestTimeoutMs !== undefined ? { requestTimeoutMs: options.requestTimeoutMs } : {}),
473
357
  ...(options.signal ? { signal: options.signal } : {}),
474
358
  ...(options.outerDeadlineAt !== undefined ? { outerDeadlineAt: options.outerDeadlineAt } : {}),
475
359
  ...(options.now ? { now: options.now } : {}),
476
360
  ...(options.fetchImpl ? { fetchImpl: options.fetchImpl } : {}),
477
- ...(options.PiAiRuntimeAdapterImpl
478
- ? { PiAiRuntimeAdapterImpl: options.PiAiRuntimeAdapterImpl }
479
- : {}),
480
361
  });
481
- let payload;
362
+ let decision;
482
363
  try {
483
- payload = await selector.select(built.input);
364
+ decision = await selector.select({
365
+ body: request.body,
366
+ questionIds: request.questionIds,
367
+ candidates: built.input.entries,
368
+ });
484
369
  }
485
370
  catch {
486
371
  const report = selector.report();
@@ -496,20 +381,26 @@ export async function runAdaptiveSelection(options) {
496
381
  const report = selector.report();
497
382
  const { diagnostics } = report;
498
383
  const { sends } = report;
499
- const validated = validateSelectionResult(payload, built.input.entries);
500
- if (!validated.ok) {
501
- diagnostics.stage = 'validate';
502
- diagnostics.failures.push(localFailureCode(validated.reason));
503
- return { status: 'none', target: null, reason: validated.reason, sends, diagnostics };
504
- }
505
- if (!validated.selected) {
384
+ if (decision.status !== 'selected') {
506
385
  diagnostics.stage = 'done';
507
- return { status: 'none', target: null, reason: validated.outcome, sends, diagnostics };
386
+ return {
387
+ status: 'none',
388
+ target: null,
389
+ reason: decision.status === 'uncertain' ? 'uncertain' : 'no_increment',
390
+ sends,
391
+ diagnostics,
392
+ };
393
+ }
394
+ const selected = built.input.entries.find((entry) => entry.ref === decision.ref);
395
+ if (!selected) {
396
+ diagnostics.stage = 'validate';
397
+ diagnostics.failures.push('SELECTION_OUTPUT_INVALID');
398
+ return { status: 'none', target: null, reason: 'SELECTION_OUTPUT_INVALID', sends, diagnostics };
508
399
  }
509
- const target = validated.selected.principle;
400
+ const target = selected.principle;
510
401
  diagnostics.stage = 'revalidate';
511
402
  const now = options.now ?? Date.now;
512
- const revalidationBudgetMs = options.generationTimeoutMs ?? ADAPTIVE_SELECTION_LIMITS.generationTimeoutMs;
403
+ const revalidationBudgetMs = options.requestTimeoutMs ?? ADAPTIVE_SELECTION_LIMITS.requestTimeoutMs;
513
404
  const signal = options.signal ?? AbortSignal.timeout(options.outerDeadlineAt === undefined
514
405
  ? revalidationBudgetMs
515
406
  : Math.max(1, Math.min(revalidationBudgetMs, options.outerDeadlineAt - now())));