create-principles-disciple 1.149.0 → 1.150.2

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 (258) hide show
  1. package/_release/product-identity.json +1 -1
  2. package/codex-adapter/dist/ingestion/ingestion.d.ts +9 -7
  3. package/codex-adapter/dist/ingestion/ingestion.js +68 -144
  4. package/codex-adapter/dist/ingestion/transcript-decoder.d.ts +35 -44
  5. package/codex-adapter/dist/ingestion/transcript-decoder.js +23 -84
  6. package/codex-adapter/dist/ingestion/transcript-source.d.ts +29 -0
  7. package/codex-adapter/dist/ingestion/transcript-source.js +65 -0
  8. package/codex-adapter/dist/pd-hook.d.ts +27 -1
  9. package/codex-adapter/dist/pd-hook.js +88 -7
  10. package/codex-adapter/dist/worker/workspace-worker.d.ts +15 -0
  11. package/codex-adapter/dist/worker/workspace-worker.js +7 -36
  12. package/codex-adapter/package.json +1 -1
  13. package/console/dist/server/index.js +14 -0
  14. package/console/dist/server/models/ActivationsConsoleModel.d.ts +3 -17
  15. package/console/dist/server/models/ActivationsConsoleModel.js +5 -44
  16. package/console/dist/server/routes/diagnostician.d.ts +50 -0
  17. package/console/dist/server/routes/diagnostician.js +388 -0
  18. package/console/dist/server/routes/examiner-eligibility.d.ts +73 -0
  19. package/console/dist/server/routes/examiner-eligibility.js +326 -0
  20. package/console/dist/server/routes/examiner.js +66 -8
  21. package/console/dist/web/assets/app.css +40 -0
  22. package/console/dist/web/assets/app.js +30 -30
  23. package/core/dist/host/host-installer.d.ts +7 -0
  24. package/core/dist/host/host-installer.d.ts.map +1 -1
  25. package/core/dist/host/host-installer.js.map +1 -1
  26. package/core/dist/runtime/activation/index.d.ts +3 -3
  27. package/core/dist/runtime/activation/index.d.ts.map +1 -1
  28. package/core/dist/runtime/activation/index.js +1 -1
  29. package/core/dist/runtime/activation/index.js.map +1 -1
  30. package/core/dist/runtime/activation/promotion-readiness-evaluator.d.ts +25 -1
  31. package/core/dist/runtime/activation/promotion-readiness-evaluator.d.ts.map +1 -1
  32. package/core/dist/runtime/activation/promotion-readiness-evaluator.js +58 -1
  33. package/core/dist/runtime/activation/promotion-readiness-evaluator.js.map +1 -1
  34. package/core/dist/runtime/activation/promotion-readiness-reader.d.ts.map +1 -1
  35. package/core/dist/runtime/activation/promotion-readiness-reader.js +4 -2
  36. package/core/dist/runtime/activation/promotion-readiness-reader.js.map +1 -1
  37. package/core/dist/runtime/activation/rulecode-owner-decision-service.d.ts +28 -0
  38. package/core/dist/runtime/activation/rulecode-owner-decision-service.d.ts.map +1 -1
  39. package/core/dist/runtime/activation/rulecode-owner-decision-service.js +2 -0
  40. package/core/dist/runtime/activation/rulecode-owner-decision-service.js.map +1 -1
  41. package/core/dist/runtime/admission-gate.d.ts +8 -1
  42. package/core/dist/runtime/admission-gate.d.ts.map +1 -1
  43. package/core/dist/runtime/admission-gate.js +2 -1
  44. package/core/dist/runtime/admission-gate.js.map +1 -1
  45. package/core/dist/runtime/config/pd-config-defaults.d.ts.map +1 -1
  46. package/core/dist/runtime/config/pd-config-defaults.js +20 -2
  47. package/core/dist/runtime/config/pd-config-defaults.js.map +1 -1
  48. package/core/dist/runtime/config/pd-config-effective.d.ts.map +1 -1
  49. package/core/dist/runtime/config/pd-config-effective.js +5 -2
  50. package/core/dist/runtime/config/pd-config-effective.js.map +1 -1
  51. package/core/dist/runtime/config/pd-config-validate.d.ts.map +1 -1
  52. package/core/dist/runtime/config/pd-config-validate.js +18 -0
  53. package/core/dist/runtime/config/pd-config-validate.js.map +1 -1
  54. package/core/dist/runtime/context-payload.d.ts +48 -3
  55. package/core/dist/runtime/context-payload.d.ts.map +1 -1
  56. package/core/dist/runtime/context-payload.js +38 -0
  57. package/core/dist/runtime/context-payload.js.map +1 -1
  58. package/core/dist/runtime/diagnostician/rootcause-prompt-builder.d.ts +8 -2
  59. package/core/dist/runtime/diagnostician/rootcause-prompt-builder.d.ts.map +1 -1
  60. package/core/dist/runtime/diagnostician/rootcause-prompt-builder.js +28 -2
  61. package/core/dist/runtime/diagnostician/rootcause-prompt-builder.js.map +1 -1
  62. package/core/dist/runtime/diagnostician-candidate.d.ts +24 -0
  63. package/core/dist/runtime/diagnostician-candidate.d.ts.map +1 -0
  64. package/core/dist/runtime/diagnostician-candidate.js +55 -0
  65. package/core/dist/runtime/diagnostician-candidate.js.map +1 -0
  66. package/core/dist/runtime/evidence-guards.d.ts +10 -4
  67. package/core/dist/runtime/evidence-guards.d.ts.map +1 -1
  68. package/core/dist/runtime/evidence-guards.js +12 -5
  69. package/core/dist/runtime/evidence-guards.js.map +1 -1
  70. package/core/dist/runtime/evolution/evolution-types.d.ts +4 -4
  71. package/core/dist/runtime/evolution/evolution-types.d.ts.map +1 -1
  72. package/core/dist/runtime/evolution/evolution-types.js +1 -0
  73. package/core/dist/runtime/evolution/evolution-types.js.map +1 -1
  74. package/core/dist/runtime/feature-flags/feature-flag-contract.d.ts.map +1 -1
  75. package/core/dist/runtime/feature-flags/feature-flag-contract.js +14 -0
  76. package/core/dist/runtime/feature-flags/feature-flag-contract.js.map +1 -1
  77. package/core/dist/runtime/feature-flags/feature-flag-lifecycle.d.ts.map +1 -1
  78. package/core/dist/runtime/feature-flags/feature-flag-lifecycle.js +16 -0
  79. package/core/dist/runtime/feature-flags/feature-flag-lifecycle.js.map +1 -1
  80. package/core/dist/runtime/index.d.ts +5 -2
  81. package/core/dist/runtime/index.d.ts.map +1 -1
  82. package/core/dist/runtime/index.js +6 -1
  83. package/core/dist/runtime/index.js.map +1 -1
  84. package/core/dist/runtime/internalization/index.d.ts +1 -0
  85. package/core/dist/runtime/internalization/index.d.ts.map +1 -1
  86. package/core/dist/runtime/internalization/index.js +2 -0
  87. package/core/dist/runtime/internalization/index.js.map +1 -1
  88. package/core/dist/runtime/internalization/rule-host-contracts.d.ts +10 -0
  89. package/core/dist/runtime/internalization/rule-host-contracts.d.ts.map +1 -1
  90. package/core/dist/runtime/internalization/rule-host-evaluator.js +10 -10
  91. package/core/dist/runtime/internalization/rule-host-evaluator.js.map +1 -1
  92. package/core/dist/runtime/internalization/rule-host-input-builder.d.ts +7 -6
  93. package/core/dist/runtime/internalization/rule-host-input-builder.d.ts.map +1 -1
  94. package/core/dist/runtime/internalization/rule-host-input-builder.js +6 -2
  95. package/core/dist/runtime/internalization/rule-host-input-builder.js.map +1 -1
  96. package/core/dist/runtime/internalization/rule-host-result-normalizer.d.ts +33 -0
  97. package/core/dist/runtime/internalization/rule-host-result-normalizer.d.ts.map +1 -0
  98. package/core/dist/runtime/internalization/rule-host-result-normalizer.js +61 -0
  99. package/core/dist/runtime/internalization/rule-host-result-normalizer.js.map +1 -0
  100. package/core/dist/runtime/internalization/rule-host-validator.d.ts.map +1 -1
  101. package/core/dist/runtime/internalization/rule-host-validator.js +17 -0
  102. package/core/dist/runtime/internalization/rule-host-validator.js.map +1 -1
  103. package/core/dist/runtime/pain-ingress-payload.d.ts +27 -2
  104. package/core/dist/runtime/pain-ingress-payload.d.ts.map +1 -1
  105. package/core/dist/runtime/pain-ingress-payload.js +45 -3
  106. package/core/dist/runtime/pain-ingress-payload.js.map +1 -1
  107. package/core/dist/runtime/pain-ingress.d.ts +4 -2
  108. package/core/dist/runtime/pain-ingress.d.ts.map +1 -1
  109. package/core/dist/runtime/pain-ingress.js +23 -3
  110. package/core/dist/runtime/pain-ingress.js.map +1 -1
  111. package/core/dist/runtime/pain-severity.d.ts +14 -0
  112. package/core/dist/runtime/pain-severity.d.ts.map +1 -0
  113. package/core/dist/runtime/pain-severity.js +14 -0
  114. package/core/dist/runtime/pain-severity.js.map +1 -0
  115. package/core/dist/runtime/pain-signal-bridge.d.ts +17 -3
  116. package/core/dist/runtime/pain-signal-bridge.d.ts.map +1 -1
  117. package/core/dist/runtime/pain-signal-bridge.js +6 -0
  118. package/core/dist/runtime/pain-signal-bridge.js.map +1 -1
  119. package/core/dist/runtime/pain-signal-observability.d.ts.map +1 -1
  120. package/core/dist/runtime/pain-signal-observability.js +3 -2
  121. package/core/dist/runtime/pain-signal-observability.js.map +1 -1
  122. package/core/dist/runtime/pain-submit-capability.d.ts +164 -0
  123. package/core/dist/runtime/pain-submit-capability.d.ts.map +1 -0
  124. package/core/dist/runtime/pain-submit-capability.js +442 -0
  125. package/core/dist/runtime/pain-submit-capability.js.map +1 -0
  126. package/core/dist/runtime/pain-to-principle-service.d.ts +4 -0
  127. package/core/dist/runtime/pain-to-principle-service.d.ts.map +1 -1
  128. package/core/dist/runtime/pain-to-principle-service.js +2 -0
  129. package/core/dist/runtime/pain-to-principle-service.js.map +1 -1
  130. package/core/dist/runtime/stalled-diagnostician-task-read-model.d.ts +56 -10
  131. package/core/dist/runtime/stalled-diagnostician-task-read-model.d.ts.map +1 -1
  132. package/core/dist/runtime/stalled-diagnostician-task-read-model.js +80 -4
  133. package/core/dist/runtime/stalled-diagnostician-task-read-model.js.map +1 -1
  134. package/core/dist/runtime/store/context/sqlite-context-assembler.d.ts.map +1 -1
  135. package/core/dist/runtime/store/context/sqlite-context-assembler.js +11 -0
  136. package/core/dist/runtime/store/context/sqlite-context-assembler.js.map +1 -1
  137. package/core/dist/runtime/store/run/memory-run-store.d.ts +10 -0
  138. package/core/dist/runtime/store/run/memory-run-store.d.ts.map +1 -1
  139. package/core/dist/runtime/store/run/memory-run-store.js +21 -0
  140. package/core/dist/runtime/store/run/memory-run-store.js.map +1 -1
  141. package/core/dist/runtime/store/run/run-store.d.ts +12 -0
  142. package/core/dist/runtime/store/run/run-store.d.ts.map +1 -1
  143. package/core/dist/runtime/store/run/sqlite-run-store.d.ts +1 -0
  144. package/core/dist/runtime/store/run/sqlite-run-store.d.ts.map +1 -1
  145. package/core/dist/runtime/store/run/sqlite-run-store.js +14 -0
  146. package/core/dist/runtime/store/run/sqlite-run-store.js.map +1 -1
  147. package/core/dist/runtime/task-status.d.ts +9 -0
  148. package/core/dist/runtime/task-status.d.ts.map +1 -1
  149. package/core/dist/runtime/task-status.js +7 -1
  150. package/core/dist/runtime/task-status.js.map +1 -1
  151. package/core/dist/runtime/types/evidence-chain-contract.d.ts +18 -0
  152. package/core/dist/runtime/types/evidence-chain-contract.d.ts.map +1 -1
  153. package/core/dist/runtime/types/evidence-chain-contract.js +37 -7
  154. package/core/dist/runtime/types/evidence-chain-contract.js.map +1 -1
  155. package/core/package.json +5 -1
  156. package/dist/install-summary.d.ts +7 -0
  157. package/dist/install-summary.d.ts.map +1 -1
  158. package/dist/install-summary.js +4 -0
  159. package/dist/install-summary.js.map +1 -1
  160. package/dist/installer.d.ts +34 -1
  161. package/dist/installer.d.ts.map +1 -1
  162. package/dist/installer.js +84 -4
  163. package/dist/installer.js.map +1 -1
  164. package/dist/installers/codex-host-installer.d.ts +88 -1
  165. package/dist/installers/codex-host-installer.d.ts.map +1 -1
  166. package/dist/installers/codex-host-installer.js +370 -11
  167. package/dist/installers/codex-host-installer.js.map +1 -1
  168. package/dist/installers/index.d.ts +23 -0
  169. package/dist/installers/index.d.ts.map +1 -1
  170. package/dist/installers/index.js +38 -1
  171. package/dist/installers/index.js.map +1 -1
  172. package/dist/installers/legacy-workbuddy-skill.d.ts +59 -0
  173. package/dist/installers/legacy-workbuddy-skill.d.ts.map +1 -0
  174. package/dist/installers/legacy-workbuddy-skill.js +168 -0
  175. package/dist/installers/legacy-workbuddy-skill.js.map +1 -0
  176. package/dist/installers/workbuddy-host-installer.d.ts.map +1 -1
  177. package/dist/installers/workbuddy-host-installer.js +7 -0
  178. package/dist/installers/workbuddy-host-installer.js.map +1 -1
  179. package/host-runtime/dist/adaptive-priority-provider.d.ts +101 -0
  180. package/host-runtime/dist/adaptive-priority-provider.js +194 -0
  181. package/host-runtime/dist/adaptive-selection.d.ts +164 -0
  182. package/host-runtime/dist/adaptive-selection.js +506 -0
  183. package/host-runtime/dist/adaptive-skip-decision.d.ts +61 -0
  184. package/host-runtime/dist/adaptive-skip-decision.js +114 -0
  185. package/host-runtime/dist/codex-ingestion-consent.d.ts +32 -95
  186. package/host-runtime/dist/codex-ingestion-consent.js +33 -205
  187. package/host-runtime/dist/conversation-ingestion/consent.d.ts +124 -0
  188. package/host-runtime/dist/conversation-ingestion/consent.js +531 -0
  189. package/host-runtime/dist/conversation-ingestion/index.d.ts +12 -0
  190. package/host-runtime/dist/conversation-ingestion/index.js +12 -0
  191. package/host-runtime/dist/conversation-ingestion/pipeline.d.ts +101 -0
  192. package/host-runtime/dist/conversation-ingestion/pipeline.js +162 -0
  193. package/host-runtime/dist/conversation-ingestion/source.d.ts +172 -0
  194. package/host-runtime/dist/conversation-ingestion/source.js +111 -0
  195. package/host-runtime/dist/conversation-ingestion/text-policy.d.ts +51 -0
  196. package/host-runtime/dist/conversation-ingestion/text-policy.js +68 -0
  197. package/host-runtime/dist/diagnostician-auto-run.d.ts +28 -0
  198. package/host-runtime/dist/diagnostician-auto-run.js +100 -0
  199. package/host-runtime/dist/governance-observation-store.d.ts +9 -7
  200. package/host-runtime/dist/governance-observation-store.js +20 -4
  201. package/host-runtime/dist/host-tool-semantic-resolver.d.ts +42 -1
  202. package/host-runtime/dist/host-tool-semantic-resolver.js +80 -14
  203. package/host-runtime/dist/index.d.ts +5 -0
  204. package/host-runtime/dist/index.js +12 -0
  205. package/host-runtime/dist/production-rulehost-gate.js +17 -17
  206. package/host-runtime/dist/rulecode-event-collection.d.ts +31 -0
  207. package/host-runtime/dist/rulecode-event-collection.js +62 -0
  208. package/host-runtime/package.json +1 -1
  209. package/package.json +3 -3
  210. package/pd-cli/dist/commands/diagnose.d.ts +30 -0
  211. package/pd-cli/dist/commands/diagnose.d.ts.map +1 -1
  212. package/pd-cli/dist/commands/diagnose.js +75 -0
  213. package/pd-cli/dist/commands/diagnose.js.map +1 -1
  214. package/pd-cli/dist/commands/pain-record.d.ts.map +1 -1
  215. package/pd-cli/dist/commands/pain-record.js +5 -4
  216. package/pd-cli/dist/commands/pain-record.js.map +1 -1
  217. package/pd-cli/dist/commands/pain-retry.d.ts.map +1 -1
  218. package/pd-cli/dist/commands/pain-retry.js +2 -1
  219. package/pd-cli/dist/commands/pain-retry.js.map +1 -1
  220. package/pd-cli/dist/commands/runtime-activation.d.ts +6 -17
  221. package/pd-cli/dist/commands/runtime-activation.d.ts.map +1 -1
  222. package/pd-cli/dist/commands/runtime-activation.js +42 -48
  223. package/pd-cli/dist/commands/runtime-activation.js.map +1 -1
  224. package/pd-cli/dist/index.js +1 -0
  225. package/pd-cli/dist/index.js.map +1 -1
  226. package/pd-cli/dist/services/delivery-surfaces.js +1 -1
  227. package/pd-cli/dist/services/delivery-surfaces.js.map +1 -1
  228. package/pd-cli/package.json +1 -1
  229. package/pd-mcp-server/dist/budget.d.ts +1 -1
  230. package/pd-mcp-server/dist/budget.js +2 -2
  231. package/pd-mcp-server/dist/envelope.d.ts +15 -0
  232. package/pd-mcp-server/dist/envelope.js +49 -1
  233. package/pd-mcp-server/dist/index.d.ts +2 -0
  234. package/pd-mcp-server/dist/index.js +6 -0
  235. package/pd-mcp-server/dist/server.d.ts +83 -14
  236. package/pd-mcp-server/dist/server.js +251 -4
  237. package/pd-mcp-server/dist/version.d.ts +1 -1
  238. package/pd-mcp-server/dist/version.js +1 -1
  239. package/pd-mcp-server/dist/workspace.d.ts +4 -2
  240. package/pd-mcp-server/dist/workspace.js +5 -2
  241. package/pd-mcp-server/package.json +1 -1
  242. package/plugin/dist/bundle.js +449 -437
  243. package/plugin/dist/core/evolution-reducer.d.ts +2 -2
  244. package/plugin/dist/hooks/hook-tool-semantics.d.ts +25 -0
  245. package/plugin/dist/hooks/pain-ingress-adapter.d.ts +1 -1
  246. package/plugin/dist/openclaw.plugin.json +1 -1
  247. package/plugin/dist/rulehost-evidence.js +1 -1
  248. package/plugin/openclaw.plugin.json +1 -1
  249. package/plugin/package.json +1 -1
  250. package/release-manager/dist/installer.js +84 -4
  251. package/release-manager/dist/installers/codex-host-installer.js +370 -11
  252. package/release-manager/dist/installers/index.js +38 -1
  253. package/release-manager/dist/installers/legacy-workbuddy-skill.js +168 -0
  254. package/release-manager/dist/installers/workbuddy-host-installer.js +7 -0
  255. package/release-manager/package.json +1 -1
  256. package/workbuddy-adapter/dist/pd-hook.js +20 -4
  257. package/workbuddy-adapter/package.json +1 -1
  258. package/workbuddy-adapter/plugin/skills/pd-pain-signal/SKILL.md +123 -20
@@ -0,0 +1,100 @@
1
+ /**
2
+ * L3 — one bounded automatic-diagnosis round (SPEC-PD-AGENT-PAIN-INGRESS-001
3
+ * §8.4 / TECHNICAL-DESIGN §8.4).
4
+ *
5
+ * The degradation ladder is: L2 Console request-driven, L3 OpenClaw automatic,
6
+ * L4 offline/manual. This module is ONLY the L3 body: it is called from the
7
+ * existing `internalization_auto_consumer` timer (no new timer, no new
8
+ * background process) and serves at most one diagnostician task per call.
9
+ *
10
+ * Three preconditions, each with its own reason so the Owner can tell WHY
11
+ * nothing happened:
12
+ * 1. `serviceStarted` — the tick that calls us is by definition the service;
13
+ * the flag exists so a non-service caller can state it is not running.
14
+ * 2. `openclaw_diagnostician_consumer` flag (quiet, default on).
15
+ * 3. Diagnostician capability (`internalAgents.agents.diagnostician.enabled`).
16
+ *
17
+ * A skip is never a failure: the task keeps its pending state and L2 can still
18
+ * serve it. Nothing is marked, mutated or deleted on any skip path.
19
+ */
20
+ import * as path from 'node:path';
21
+ import { PrincipleTreeLedgerAdapter, createPainSignalBridge, createRuntimeStateHandle, pickDiagnosticianCandidate, resolveDiagnosticianCapability, } from '@principles/core/runtime';
22
+ import { loadFeatureFlagFromConfig, loadPdConfigForPlugin } from './pd-config.js';
23
+ /** Quiet flag that owns the L3 half of the ladder. */
24
+ export const DIAGNOSTICIAN_AUTO_RUN_FLAG = 'openclaw_diagnostician_consumer';
25
+ /** Owner string used for the diagnostics this module starts. */
26
+ export const DIAGNOSTICIAN_AUTO_RUN_OWNER = 'pd-auto-diagnostician';
27
+ const DEFAULT_CANDIDATE_LIMIT = 1;
28
+ export async function runPendingDiagnosticianOnce(options) {
29
+ if (options.serviceStarted === false) {
30
+ return {
31
+ served: false,
32
+ reason: 'service_not_running',
33
+ message: 'the internalization_auto_consumer service is not running',
34
+ nextAction: 'Start the OpenClaw service, or diagnose from Console (L2) which does not need a timer.',
35
+ };
36
+ }
37
+ const config = loadPdConfigForPlugin(options.workspaceDir);
38
+ const flag = loadFeatureFlagFromConfig(options.workspaceDir, DIAGNOSTICIAN_AUTO_RUN_FLAG);
39
+ if (!flag.enabled) {
40
+ return {
41
+ served: false,
42
+ reason: 'flag_off',
43
+ message: `features.${DIAGNOSTICIAN_AUTO_RUN_FLAG} is off`,
44
+ nextAction: 'Tasks stay pending for the Console request-driven path (L2); set the flag to true to re-enable automatic diagnosis.',
45
+ };
46
+ }
47
+ const capability = resolveDiagnosticianCapability(config.effective);
48
+ if (!capability.available) {
49
+ return {
50
+ served: false,
51
+ reason: 'capability_disabled',
52
+ message: capability.message,
53
+ nextAction: capability.nextAction,
54
+ };
55
+ }
56
+ const handle = await createRuntimeStateHandle({ workspaceDir: options.workspaceDir, readonly: false });
57
+ try {
58
+ const now = options.now ?? new Date().toISOString();
59
+ const candidate = await pickDiagnosticianCandidate(handle.stateManager, options.limit ?? DEFAULT_CANDIDATE_LIMIT, now);
60
+ if (candidate === null) {
61
+ return { served: false, reason: 'no_candidate' };
62
+ }
63
+ const stateDir = path.join(options.workspaceDir, '.state');
64
+ try {
65
+ const bridge = await createPainSignalBridge({
66
+ workspaceDir: options.workspaceDir,
67
+ stateDir,
68
+ ledgerAdapter: new PrincipleTreeLedgerAdapter({ stateDir }),
69
+ owner: options.owner ?? DIAGNOSTICIAN_AUTO_RUN_OWNER,
70
+ effectiveConfig: config.effective,
71
+ getEnvVar: options.getEnvVar ?? ((name) => process.env[name]),
72
+ });
73
+ const executed = await bridge.executePendingDiagnosis({ taskId: candidate.taskId });
74
+ if (executed.status === 'failed') {
75
+ return {
76
+ served: false,
77
+ taskId: candidate.taskId,
78
+ reason: 'execution_failed',
79
+ ...(executed.message !== undefined ? { message: executed.message.slice(0, 200) } : {}),
80
+ nextAction: 'Inspect the workspace runtime profile; the task keeps its pending/retry state for the next tick or Console (L2).',
81
+ };
82
+ }
83
+ return { served: true, taskId: candidate.taskId };
84
+ }
85
+ catch (error) {
86
+ // A missing/!invalid runtime profile must not throw out of the timer that
87
+ // hosts us, and must not silently look like "no work" (rc-9).
88
+ return {
89
+ served: false,
90
+ taskId: candidate.taskId,
91
+ reason: 'execution_failed',
92
+ message: error instanceof Error ? error.message.slice(0, 200) : String(error).slice(0, 200),
93
+ nextAction: 'Configure the workspace runtime profile; the task keeps its pending state for the next tick or Console (L2).',
94
+ };
95
+ }
96
+ }
97
+ finally {
98
+ await handle.close().catch(() => undefined);
99
+ }
100
+ }
@@ -3,13 +3,15 @@ export declare const GOVERNANCE_RETENTION_MAX_TURNS = 32;
3
3
  export declare const GOVERNANCE_RETENTION_MAX_AGE_MS: number;
4
4
  export declare const GOVERNANCE_PROMOTION_PRECEDING_TURNS = 12;
5
5
  export declare const GOVERNANCE_PENDING_TAIL_STALE_MS: number;
6
+ /** Host taxonomy for governance observations (schema v4; PRI-1171 unification). */
7
+ export type GovernanceObservationHostKind = 'codex' | 'workbuddy' | 'openclaw';
6
8
  export type GovernanceObservationKind = 'user_turn' | 'assistant_turn' | 'tool_call';
7
9
  export type GovernanceObservationSource = 'live_hook' | 'transcript';
8
10
  export type GovernanceObservationCompleteness = 'complete' | 'partial';
9
11
  /** `quarantined` (Slice D §15): audited, permanently-invalid row; bodies dropped, metadata kept. */
10
12
  export type GovernanceRetentionClass = 'operational' | 'promoted' | 'expired' | 'rolled_back' | 'quarantined';
11
13
  export interface GovernanceObservationInput {
12
- readonly hostKind: 'codex';
14
+ readonly hostKind: GovernanceObservationHostKind;
13
15
  readonly rolloutIdentity: string;
14
16
  readonly rootSessionId: string;
15
17
  readonly parentRolloutIdentity?: string;
@@ -45,7 +47,7 @@ export interface GovernanceObservationInput {
45
47
  readonly observedAt: string;
46
48
  }
47
49
  export interface GovernanceCheckpointInput {
48
- readonly hostKind: 'codex';
50
+ readonly hostKind: GovernanceObservationHostKind;
49
51
  readonly rolloutIdentity: string;
50
52
  readonly byteOffset: number;
51
53
  readonly lastOrdinal: number;
@@ -104,7 +106,7 @@ export interface GovernanceObservationRecord {
104
106
  }
105
107
  export interface PromoteGovernanceEvidenceInput {
106
108
  readonly workspaceDir: string;
107
- readonly hostKind: 'codex';
109
+ readonly hostKind: GovernanceObservationHostKind;
108
110
  readonly rolloutIdentity: string;
109
111
  readonly triggerLogicalKey: string;
110
112
  /** Caller-provided pain reference. Slice A never mints a pain identity (SPEC §18). */
@@ -136,7 +138,7 @@ type Degradation = {
136
138
  nextAction: string;
137
139
  };
138
140
  export interface GovernanceRolloutDescriptor {
139
- readonly hostKind: 'codex';
141
+ readonly hostKind: GovernanceObservationHostKind;
140
142
  readonly rolloutIdentity: string;
141
143
  readonly rootSessionId: string;
142
144
  readonly parentRolloutIdentity?: string;
@@ -159,14 +161,14 @@ export interface IngestGovernanceObservationsInput {
159
161
  export declare function ingestGovernanceObservations(input: IngestGovernanceObservationsInput): IngestGovernanceObservationsResult;
160
162
  export interface ReadGovernanceCheckpointArgs {
161
163
  readonly workspaceDir: string;
162
- readonly hostKind: 'codex';
164
+ readonly hostKind: GovernanceObservationHostKind;
163
165
  readonly rolloutIdentity: string;
164
166
  readonly databaseFactory?: ObservationDatabaseFactory;
165
167
  }
166
168
  export declare function readGovernanceCheckpoint(args: ReadGovernanceCheckpointArgs): GovernanceCheckpointRecord | null | Degradation;
167
169
  export interface ListGovernanceCheckpointsArgs {
168
170
  readonly workspaceDir: string;
169
- readonly hostKind: 'codex';
171
+ readonly hostKind: GovernanceObservationHostKind;
170
172
  readonly databaseFactory?: ObservationDatabaseFactory;
171
173
  }
172
174
  export type ListGovernanceCheckpointsResult = {
@@ -196,7 +198,7 @@ export declare function listGovernanceObservations(input: ListGovernanceObservat
196
198
  export declare function promoteGovernanceEvidence(input: PromoteGovernanceEvidenceInput): PromoteGovernanceEvidenceResult;
197
199
  export interface QuarantineGovernanceObservationArgs {
198
200
  readonly workspaceDir: string;
199
- readonly hostKind: 'codex';
201
+ readonly hostKind: GovernanceObservationHostKind;
200
202
  readonly rolloutIdentity: string;
201
203
  /** governance_observations.id — `pd codex ingest quarantine --record <id>`. */
202
204
  readonly recordId: number;
@@ -34,7 +34,12 @@ export const GOVERNANCE_RETENTION_MAX_TURNS = 32;
34
34
  export const GOVERNANCE_RETENTION_MAX_AGE_MS = 7 * 24 * 60 * 60 * 1000;
35
35
  export const GOVERNANCE_PROMOTION_PRECEDING_TURNS = 12;
36
36
  export const GOVERNANCE_PENDING_TAIL_STALE_MS = 7 * 24 * 60 * 60 * 1000;
37
- const GOVERNANCE_OBSERVATION_SCHEMA_VERSION = 3;
37
+ // Schema v4 (PRI-1171): additive contract widening over v3 — host_kind admits
38
+ // 'workbuddy'/'openclaw' (app-layer union; the DDL keeps unconstrained TEXT),
39
+ // and the checkpoint upsert is MAX-monotonic (concurrent Stop × worker
40
+ // catch-up must never drag a committed water mark backwards). No v3 DDL is
41
+ // rewritten; existing stores bump the version row on next open.
42
+ const GOVERNANCE_OBSERVATION_SCHEMA_VERSION = 4;
38
43
  const MAX_TEXT_BOUND = 200; // matches MAX_EVIDENCE_VALUE_CHARS; guards stored identity fields
39
44
  const MAX_JSON_COLUMN = 8_000;
40
45
  function isRecord(value) {
@@ -426,13 +431,24 @@ export function ingestGovernanceObservations(input) {
426
431
  : firstDegradation
427
432
  ? { reason: firstDegradation.reason, ordinal: firstDegradation.ordinal ?? null }
428
433
  : null;
434
+ // Monotonic checkpoint (PRI-1171 review): a stale concurrent writer
435
+ // (Stop × worker catch-up) can neither drag the water mark back NOR
436
+ // refresh its companion fields — root_session_id, incomplete_tail,
437
+ // degradation bookkeeping, and updated_at advance only with a
438
+ // non-regressing byte_offset, so health-page state stays consistent
439
+ // with the committed mark.
429
440
  db.prepare(`INSERT INTO governance_transcript_checkpoints
430
441
  (host_kind, rollout_identity, byte_offset, last_ordinal, cli_version, root_session_id, incomplete_tail, last_degradation_reason, last_degradation_ordinal, updated_at)
431
442
  VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
432
443
  ON CONFLICT(host_kind, rollout_identity) DO UPDATE SET
433
- byte_offset = excluded.byte_offset, last_ordinal = excluded.last_ordinal, cli_version = COALESCE(excluded.cli_version, cli_version),
434
- root_session_id = excluded.root_session_id, incomplete_tail = excluded.incomplete_tail,
435
- last_degradation_reason = excluded.last_degradation_reason, last_degradation_ordinal = excluded.last_degradation_ordinal, updated_at = excluded.updated_at`)
444
+ byte_offset = MAX(governance_transcript_checkpoints.byte_offset, excluded.byte_offset),
445
+ last_ordinal = MAX(governance_transcript_checkpoints.last_ordinal, excluded.last_ordinal),
446
+ cli_version = COALESCE(excluded.cli_version, cli_version),
447
+ root_session_id = CASE WHEN excluded.byte_offset >= governance_transcript_checkpoints.byte_offset THEN excluded.root_session_id ELSE governance_transcript_checkpoints.root_session_id END,
448
+ incomplete_tail = CASE WHEN excluded.byte_offset >= governance_transcript_checkpoints.byte_offset THEN excluded.incomplete_tail ELSE governance_transcript_checkpoints.incomplete_tail END,
449
+ last_degradation_reason = CASE WHEN excluded.byte_offset >= governance_transcript_checkpoints.byte_offset THEN excluded.last_degradation_reason ELSE governance_transcript_checkpoints.last_degradation_reason END,
450
+ last_degradation_ordinal = CASE WHEN excluded.byte_offset >= governance_transcript_checkpoints.byte_offset THEN excluded.last_degradation_ordinal ELSE governance_transcript_checkpoints.last_degradation_ordinal END,
451
+ updated_at = CASE WHEN excluded.byte_offset >= governance_transcript_checkpoints.byte_offset THEN excluded.updated_at ELSE governance_transcript_checkpoints.updated_at END`)
436
452
  .run(input.checkpoint.hostKind, input.checkpoint.rolloutIdentity, byteOffset, input.checkpoint.lastOrdinal, input.checkpoint.cliVersion ?? null, input.checkpoint.rootSessionId, input.checkpoint.incompleteTail ? 1 : 0, lastDegradation?.reason ?? null, lastDegradation?.ordinal ?? null, now);
437
453
  }
438
454
  // Marker semantics: compaction replaces logical history (tombstone every
@@ -15,6 +15,9 @@
15
15
  * on the Console)
16
16
  * - auto-consumer / codex worker (host-threaded registries, already
17
17
  * host-exact; the resolver exists for host-neutral entries)
18
+ * - B3: `resolveHostToolSemanticsForHook` — the realtime hook entry point
19
+ * (OpenClaw gate, Codex / WorkBuddy pd-hook) resolves the SAME durable
20
+ * declarations replay reads, instead of only its compiled-in list.
18
21
  *
19
22
  * Multi-host semantics (R2 P1-2): declarations are PER-HOST files under
20
23
  * `.pd/host-tool-semantics/<hostKind>.json` (last-writer-wins on a shared
@@ -25,7 +28,7 @@
25
28
  *
26
29
  * Pure logic + declared-file I/O only. Merging is order-independent.
27
30
  */
28
- import { type ToolSemanticRegistry } from '@principles/core/runtime';
31
+ import { type ToolSemanticMappingV1, type ToolSemanticRegistry } from '@principles/core/runtime';
29
32
  import { saveHostToolDeclaration, type HostToolDeclaration } from './host-tool-declaration.js';
30
33
  export type HostToolSemanticResolution = {
31
34
  readonly ok: true;
@@ -43,5 +46,43 @@ export type HostToolSemanticResolution = {
43
46
  * against baseline names is a forged proof; ERR-114).
44
47
  */
45
48
  export declare function resolveWorkspaceHostToolSemantics(workspaceDir: string): HostToolSemanticResolution;
49
+ /** Where the hook-facing registry got its host layer from. */
50
+ export type HookToolSemanticsSource = 'workspace-declaration' | 'host-static';
51
+ export type HookToolSemanticsResolution = {
52
+ readonly ok: true;
53
+ readonly registry: ToolSemanticRegistry;
54
+ readonly source: HookToolSemanticsSource;
55
+ } | {
56
+ readonly ok: false;
57
+ readonly reason: string;
58
+ readonly nextAction: string;
59
+ };
60
+ export interface HookToolSemanticsOptions {
61
+ readonly workspaceDir: string;
62
+ /** The calling host's identity label (also the declaration filename). */
63
+ readonly hostKind: string;
64
+ /** The host's compiled-in declaration — the fallback data source. */
65
+ readonly staticMappings: readonly ToolSemanticMappingV1[];
66
+ }
67
+ /**
68
+ * B3 — the ONE entry point the realtime hook uses to resolve tool semantics.
69
+ *
70
+ * Precedence (plan §4.2): workspace declaration → host static declaration →
71
+ * core baseline. Replay/evidence/Console already read the declarations via
72
+ * `resolveWorkspaceHostToolSemantics`; before B3 the hook read the compiled-in
73
+ * static list only, so a workspace declaration could disagree with production
74
+ * on the same event.
75
+ *
76
+ * - no declaration persisted → the host static registry (`source:
77
+ * 'host-static'`): the pre-B3 behavior, and the normal state before a host
78
+ * has started once in this workspace.
79
+ * - declaration persisted → its names win (they are what replay resolves),
80
+ * and static names the declaration does not carry are still filled in so a
81
+ * stale file cannot amputate the host's current surface.
82
+ * - malformed / conflicting declaration → typed refusal, never a silent
83
+ * static fallback and never an empty registry. Consumers must surface the
84
+ * reason (rc-9) and may fall back to their static registry for availability.
85
+ */
86
+ export declare function resolveHostToolSemanticsForHook(options: HookToolSemanticsOptions): HookToolSemanticsResolution;
46
87
  export { saveHostToolDeclaration };
47
88
  export type { HostToolDeclaration };
@@ -15,6 +15,9 @@
15
15
  * on the Console)
16
16
  * - auto-consumer / codex worker (host-threaded registries, already
17
17
  * host-exact; the resolver exists for host-neutral entries)
18
+ * - B3: `resolveHostToolSemanticsForHook` — the realtime hook entry point
19
+ * (OpenClaw gate, Codex / WorkBuddy pd-hook) resolves the SAME durable
20
+ * declarations replay reads, instead of only its compiled-in list.
18
21
  *
19
22
  * Multi-host semantics (R2 P1-2): declarations are PER-HOST files under
20
23
  * `.pd/host-tool-semantics/<hostKind>.json` (last-writer-wins on a shared
@@ -28,22 +31,16 @@
28
31
  import { buildToolSemanticRegistry, } from '@principles/core/runtime';
29
32
  import { loadHostToolDeclarations, saveHostToolDeclaration, } from './host-tool-declaration.js';
30
33
  /**
31
- * Resolve the merged workspace registry from durable host provenance.
32
- * Fails loud when no declaration is persisted or any persisted declaration
33
- * is malformed — never falls back to the core baseline (an existence check
34
- * against baseline names is a forged proof; ERR-114).
34
+ * Union every declared host's mappings, order-independently.
35
+ *
36
+ * Same raw name from two hosts must agree on kind; a conflict means a host
37
+ * declared a name it does not own — fail loud rather than pick a winner by
38
+ * startup order (P4 one-source-of-truth).
35
39
  */
36
- export function resolveWorkspaceHostToolSemantics(workspaceDir) {
37
- const loaded = loadHostToolDeclarations(workspaceDir);
38
- if (!loaded.ok) {
39
- return { ok: false, reason: loaded.reason, nextAction: loaded.nextAction };
40
- }
40
+ function mergeDeclarations(declarations) {
41
41
  const mappings = [];
42
- for (const declaration of loaded.declarations) {
42
+ for (const declaration of declarations) {
43
43
  for (const mapping of declaration.mappings) {
44
- // Same raw name from two hosts must agree on kind; a conflict means a
45
- // host declared a name it does not own — fail loud rather than pick a
46
- // winner by startup order (P4 one-source-of-truth).
47
44
  const existing = mappings.find((m) => m.rawToolName === mapping.rawToolName);
48
45
  if (existing && existing.canonicalKind !== mapping.canonicalKind) {
49
46
  return {
@@ -56,7 +53,23 @@ export function resolveWorkspaceHostToolSemantics(workspaceDir) {
56
53
  mappings.push(mapping);
57
54
  }
58
55
  }
59
- const built = buildToolSemanticRegistry(mappings);
56
+ return { ok: true, mappings };
57
+ }
58
+ /**
59
+ * Resolve the merged workspace registry from durable host provenance.
60
+ * Fails loud when no declaration is persisted or any persisted declaration
61
+ * is malformed — never falls back to the core baseline (an existence check
62
+ * against baseline names is a forged proof; ERR-114).
63
+ */
64
+ export function resolveWorkspaceHostToolSemantics(workspaceDir) {
65
+ const loaded = loadHostToolDeclarations(workspaceDir);
66
+ if (!loaded.ok) {
67
+ return { ok: false, reason: loaded.reason, nextAction: loaded.nextAction };
68
+ }
69
+ const merged = mergeDeclarations(loaded.declarations);
70
+ if (!merged.ok)
71
+ return merged;
72
+ const built = buildToolSemanticRegistry(merged.mappings);
60
73
  if (!built.ok) {
61
74
  return {
62
75
  ok: false,
@@ -70,4 +83,57 @@ export function resolveWorkspaceHostToolSemantics(workspaceDir) {
70
83
  hostKinds: loaded.declarations.map((d) => d.hostKind).sort(),
71
84
  };
72
85
  }
86
+ /**
87
+ * B3 — the ONE entry point the realtime hook uses to resolve tool semantics.
88
+ *
89
+ * Precedence (plan §4.2): workspace declaration → host static declaration →
90
+ * core baseline. Replay/evidence/Console already read the declarations via
91
+ * `resolveWorkspaceHostToolSemantics`; before B3 the hook read the compiled-in
92
+ * static list only, so a workspace declaration could disagree with production
93
+ * on the same event.
94
+ *
95
+ * - no declaration persisted → the host static registry (`source:
96
+ * 'host-static'`): the pre-B3 behavior, and the normal state before a host
97
+ * has started once in this workspace.
98
+ * - declaration persisted → its names win (they are what replay resolves),
99
+ * and static names the declaration does not carry are still filled in so a
100
+ * stale file cannot amputate the host's current surface.
101
+ * - malformed / conflicting declaration → typed refusal, never a silent
102
+ * static fallback and never an empty registry. Consumers must surface the
103
+ * reason (rc-9) and may fall back to their static registry for availability.
104
+ */
105
+ export function resolveHostToolSemanticsForHook(options) {
106
+ const builtStatic = buildToolSemanticRegistry(options.staticMappings);
107
+ if (!builtStatic.ok) {
108
+ return {
109
+ ok: false,
110
+ reason: `host_tool_semantics_static_invalid (${options.hostKind})`,
111
+ nextAction: `fix the '${options.hostKind}' compiled-in tool declaration: ${builtStatic.errors.slice(0, 3).join('; ')}`,
112
+ };
113
+ }
114
+ const loaded = loadHostToolDeclarations(options.workspaceDir);
115
+ if (!loaded.ok) {
116
+ if (loaded.reason === 'host_tool_declaration_missing') {
117
+ return { ok: true, registry: builtStatic.registry, source: 'host-static' };
118
+ }
119
+ return { ok: false, reason: loaded.reason, nextAction: loaded.nextAction };
120
+ }
121
+ const merged = mergeDeclarations(loaded.declarations);
122
+ if (!merged.ok)
123
+ return merged;
124
+ const mappings = [...merged.mappings];
125
+ for (const mapping of options.staticMappings) {
126
+ if (!mappings.some((m) => m.rawToolName === mapping.rawToolName))
127
+ mappings.push(mapping);
128
+ }
129
+ const built = buildToolSemanticRegistry(mappings);
130
+ if (!built.ok) {
131
+ return {
132
+ ok: false,
133
+ reason: `host_tool_semantics_static_invalid (${options.hostKind})`,
134
+ nextAction: `merged tool mappings invalid: ${built.errors.slice(0, 3).join('; ')}`,
135
+ };
136
+ }
137
+ return { ok: true, registry: built.registry, source: 'workspace-declaration' };
138
+ }
73
139
  export { saveHostToolDeclaration };
@@ -11,17 +11,22 @@ export * from './prompt-activation-deliverability.js';
11
11
  export * from './prompt-injection-status.js';
12
12
  export * from './prompt-injection-event-evidence.js';
13
13
  export * from './prompt-injection-budget-observation.js';
14
+ export * from './rulecode-event-collection.js';
14
15
  export * from './pd-config.js';
15
16
  export * from './production-rulehost-gate.js';
16
17
  export * from './rule-implementation-runtime.js';
17
18
  export * from './production-pain-evidence.js';
18
19
  export * from './governance-observation-store.js';
20
+ export * from './conversation-ingestion/index.js';
19
21
  export * from './governance-signal-admission.js';
20
22
  export * from './signal-classifier.js';
23
+ export * from './adaptive-selection.js';
24
+ export * from './adaptive-priority-provider.js';
21
25
  export * from './signal-stage2-cycle.js';
22
26
  export * from './host-liveness-contract.js';
23
27
  export * from './internalization-consumer-governance.js';
24
28
  export * from './internalization-consumer-cycle.js';
29
+ export * from './diagnostician-auto-run.js';
25
30
  export * from './host-tool-declaration.js';
26
31
  export * from './host-tool-semantic-resolver.js';
27
32
  export * from './evaluator-runtime-context.js';
@@ -21,19 +21,31 @@ export * from './prompt-injection-event-evidence.js';
21
21
  // events — console surfaces forecast under the budget the last real
22
22
  // injection used (SPEC §6.1), labelled with source + observation time.
23
23
  export * from './prompt-injection-budget-observation.js';
24
+ // RuleCode shadow telemetry scan: ONE filesystem reader for CLI promotion
25
+ // review and the Console Owner review (5B deduplication).
26
+ export * from './rulecode-event-collection.js';
24
27
  export * from './pd-config.js';
25
28
  export * from './production-rulehost-gate.js';
26
29
  export * from './rule-implementation-runtime.js';
27
30
  export * from './production-pain-evidence.js';
28
31
  export * from './governance-observation-store.js';
32
+ // PRI-1171: unified conversation-ingestion seam — the ONE host-neutral entry
33
+ // for transcript trajectory ingestion (source contract + shared pipeline +
34
+ // consent ledger v3 + text policy). Host decoders stay in their adapter
35
+ // packages; a new host implements TranscriptSourceAdapter with zero changes
36
+ // here.
37
+ export * from './conversation-ingestion/index.js';
29
38
  export * from './governance-signal-admission.js';
30
39
  export * from './signal-classifier.js';
40
+ export * from './adaptive-selection.js';
41
+ export * from './adaptive-priority-provider.js';
31
42
  export * from './signal-stage2-cycle.js';
32
43
  export * from './host-liveness-contract.js';
33
44
  // PRI-624 Slice C: shared internalization consumer execution (OpenClaw
34
45
  // auto-consumer + Companion workspace worker call the same cycle).
35
46
  export * from './internalization-consumer-governance.js';
36
47
  export * from './internalization-consumer-cycle.js';
48
+ export * from './diagnostician-auto-run.js';
37
49
  // PRI-634-F R2: durable host-authored tool declaration — hosts persist, host-
38
50
  // neutral consumers (pd-cli/pd-console) resolve through the ONE resolver.
39
51
  export * from './host-tool-declaration.js';
@@ -1,6 +1,6 @@
1
1
  import fs from 'node:fs';
2
2
  import path from 'node:path';
3
- import { buildRuleHostAction, buildToolSemanticRegistry, deriveToolHintsFromCanonicalKind, estimateLineChanges, mergeDecisions, SqliteConnection, UNAVAILABLE_RULE_CONTEXT, validateRuleContextV2, validateRuleHostResult, verifyPiArtifactRowDigest, RECOVERY_CONTROL_SURFACES, } from '@principles/core/runtime';
3
+ import { buildRuleHostAction, buildToolSemanticRegistry, deriveToolHintsFromCanonicalKind, estimateLineChanges, mergeDecisions, normalizeRuleHostResult, SqliteConnection, UNAVAILABLE_RULE_CONTEXT, validateRuleContextV2, verifyPiArtifactRowDigest, RECOVERY_CONTROL_SURFACES, } from '@principles/core/runtime';
4
4
  import { isSensitiveSystemPath } from '@principles/core/runtime/internalization/rule-host-input-builder';
5
5
  import { classifyBashRisk } from '@principles/core/runtime/internalization/bash-risk';
6
6
  import { scanRetiredContractSymbols } from './legacy-rule-contract-symbols.js';
@@ -76,9 +76,6 @@ function isRuleMeta(value) {
76
76
  function isRuleContext(value) {
77
77
  return validateRuleContextV2(value).valid;
78
78
  }
79
- function isRuleResult(value) {
80
- return validateRuleHostResult(value).valid;
81
- }
82
79
  const baselineToolSemanticsResult = buildToolSemanticRegistry();
83
80
  // Static baseline input — always builds; throwing here is a programming error.
84
81
  if (!baselineToolSemanticsResult.ok) {
@@ -588,14 +585,14 @@ export function createProductionRuleHostGate(options = {}) {
588
585
  addWarning(warnings, `implementation_unhealthy: ${batchResult && !batchResult.ok ? batchResult.error ?? 'unknown child error' : 'rule_batch_result_missing'}`, 'fix the shadow RuleCode and reactivate the rule; live enforcement is unaffected');
589
586
  continue;
590
587
  }
591
- const validation = validateRuleHostResult(batchResult.result);
592
- if (!isRuleResult(batchResult.result)) {
593
- addWarning(warnings, `invalid RuleHostResult: ${validation.errors.join('; ')}`, 'fix the shadow RuleCode result and reactivate the rule; live enforcement is unaffected');
588
+ const normalized = normalizeRuleHostResult(batchResult.result);
589
+ if (normalized.degraded !== undefined) {
590
+ addWarning(warnings, `invalid RuleHostResult: ${normalized.degraded.notes ?? 'unknown invalid result'}`, 'fix the shadow RuleCode result and reactivate the rule; live enforcement is unaffected');
594
591
  continue;
595
592
  }
596
- const shadowResult = batchResult.result.matched
597
- ? { ...batchResult.result, ruleId: candidate.ruleId, principleId: candidate.principleId }
598
- : batchResult.result;
593
+ const shadowResult = normalized.matched
594
+ ? { ...normalized, ruleId: candidate.ruleId, principleId: candidate.principleId }
595
+ : normalized;
599
596
  shadowEvaluations.push({
600
597
  toolName: input.toolName,
601
598
  filePath: action.normalizedPath,
@@ -623,14 +620,17 @@ export function createProductionRuleHostGate(options = {}) {
623
620
  addWarning(warnings, `implementation_unhealthy: ${batchResult.error ?? 'unknown child error'}`, 'fix the RuleCode and reactivate the rule');
624
621
  continue;
625
622
  }
626
- const validation = validateRuleHostResult(batchResult.result);
627
- if (!isRuleResult(batchResult.result)) {
628
- addWarning(warnings, `invalid RuleHostResult: ${validation.errors.join('; ')}`, 'fix the RuleCode result and reactivate the rule');
629
- continue;
623
+ // B1: one reading of unusable output. Previously this branch warned and
624
+ // `continue`d, so the rule silently stopped participating and another
625
+ // rule's allow could win the merge. Normalization keeps it in the merge
626
+ // as a contract-level fail-closed requireApproval marked `degraded`.
627
+ const normalized = normalizeRuleHostResult(batchResult.result);
628
+ if (normalized.degraded !== undefined) {
629
+ addWarning(warnings, `invalid RuleHostResult: ${normalized.degraded.notes ?? 'unknown invalid result'}`, 'fix the RuleCode result and reactivate the rule; invalid output is normalized to requireApproval (fail-closed in the contract, not enforced as a block by this gate)');
630
630
  }
631
- const validatedResult = batchResult.result.matched
632
- ? { ...batchResult.result, ruleId: candidate.ruleId, principleId: candidate.principleId }
633
- : batchResult.result;
631
+ const validatedResult = normalized.matched
632
+ ? { ...normalized, ruleId: candidate.ruleId, principleId: candidate.principleId }
633
+ : normalized;
634
634
  implementations.push({ ...candidate, evaluate: () => validatedResult });
635
635
  liveEvaluatedResults.push(validatedResult);
636
636
  }
@@ -0,0 +1,31 @@
1
+ export interface CollectedRuleCodeEventEntries {
2
+ entries: unknown[];
3
+ /** Number of candidate directories that actually exist on disk. */
4
+ sourceDirsFound: number;
5
+ }
6
+ /**
7
+ * PRI-577: RuleCode event telemetry candidate directories, in priority order.
8
+ *
9
+ * Runtime convention is `.pd/logs`, but the v1 EventLog writer
10
+ * (openclaw-plugin `src/core/event-log.ts`) still emits `events_*.jsonl` under
11
+ * `.state/logs`. No production code ever created `.pd/logs`, so scanning only
12
+ * that path made every shadow metric report "unavailable" while 2500+ real
13
+ * evaluations sat unread in `.state/logs`. Readers scan both candidates until
14
+ * the writer migrates (ERR-031: every reader derives from the host-runtime
15
+ * constant `RUNTIME_EVENT_LOG_CANDIDATE_DIRS`, so they cannot drift).
16
+ */
17
+ export declare const RULECODE_EVENT_LOG_CANDIDATE_DIRS: readonly string[];
18
+ /**
19
+ * Collect rulehost telemetry entries from all candidate log directories.
20
+ * Malformed lines are excluded individually. A directory counts as a source
21
+ * only after it can be enumerated, so an unreadable path cannot be mistaken
22
+ * for a healthy channel with zero events (ERR-002).
23
+ *
24
+ * Exact lines copied between candidate directories are deduplicated by
25
+ * priority. Different events in same-named daily files are retained.
26
+ *
27
+ * ONE implementation: this is the host-side filesystem reader the CLI
28
+ * (`runtime activation promote`) and the Console Owner review both consume, so
29
+ * a fix to the scan cannot land in one consumer and silently lag in the other.
30
+ */
31
+ export declare function collectRuleCodeEventEntries(workspaceDir: string): CollectedRuleCodeEventEntries;
@@ -0,0 +1,62 @@
1
+ import * as fs from 'node:fs';
2
+ import * as path from 'node:path';
3
+ import { RUNTIME_EVENT_LOG_CANDIDATE_DIRS } from './prompt-injection-budget-observation.js';
4
+ /**
5
+ * PRI-577: RuleCode event telemetry candidate directories, in priority order.
6
+ *
7
+ * Runtime convention is `.pd/logs`, but the v1 EventLog writer
8
+ * (openclaw-plugin `src/core/event-log.ts`) still emits `events_*.jsonl` under
9
+ * `.state/logs`. No production code ever created `.pd/logs`, so scanning only
10
+ * that path made every shadow metric report "unavailable" while 2500+ real
11
+ * evaluations sat unread in `.state/logs`. Readers scan both candidates until
12
+ * the writer migrates (ERR-031: every reader derives from the host-runtime
13
+ * constant `RUNTIME_EVENT_LOG_CANDIDATE_DIRS`, so they cannot drift).
14
+ */
15
+ export const RULECODE_EVENT_LOG_CANDIDATE_DIRS = RUNTIME_EVENT_LOG_CANDIDATE_DIRS;
16
+ /**
17
+ * Collect rulehost telemetry entries from all candidate log directories.
18
+ * Malformed lines are excluded individually. A directory counts as a source
19
+ * only after it can be enumerated, so an unreadable path cannot be mistaken
20
+ * for a healthy channel with zero events (ERR-002).
21
+ *
22
+ * Exact lines copied between candidate directories are deduplicated by
23
+ * priority. Different events in same-named daily files are retained.
24
+ *
25
+ * ONE implementation: this is the host-side filesystem reader the CLI
26
+ * (`runtime activation promote`) and the Console Owner review both consume, so
27
+ * a fix to the scan cannot land in one consumer and silently lag in the other.
28
+ */
29
+ export function collectRuleCodeEventEntries(workspaceDir) {
30
+ const entries = [];
31
+ let sourceDirsFound = 0;
32
+ const higherPriorityLines = new Set();
33
+ for (const candidate of RULECODE_EVENT_LOG_CANDIDATE_DIRS) {
34
+ const logsDir = path.join(workspaceDir, ...candidate.split('/'));
35
+ if (!fs.existsSync(logsDir))
36
+ continue;
37
+ try {
38
+ const files = fs.readdirSync(logsDir)
39
+ .filter(name => /^events_.*\.jsonl$/.test(name))
40
+ .sort()
41
+ .slice(-7);
42
+ sourceDirsFound += 1;
43
+ const currentSourceLines = [];
44
+ for (const file of files) {
45
+ const lines = fs.readFileSync(path.join(logsDir, file), 'utf8').split('\n').filter(Boolean);
46
+ for (const line of lines) {
47
+ currentSourceLines.push(line);
48
+ if (higherPriorityLines.has(line))
49
+ continue;
50
+ try {
51
+ entries.push(JSON.parse(line));
52
+ }
53
+ catch { /* exclude malformed telemetry */ }
54
+ }
55
+ }
56
+ for (const line of currentSourceLines)
57
+ higherPriorityLines.add(line);
58
+ }
59
+ catch { /* unreadable directory contributes no entries */ }
60
+ }
61
+ return { entries, sourceDirsFound };
62
+ }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@principles/host-runtime",
3
- "version": "3.2.2",
3
+ "version": "3.4.0",
4
4
  "description": "Shared host-neutral orchestration for Principles Disciple MVP-Core hook paths.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-principles-disciple",
3
- "version": "1.149.0",
3
+ "version": "1.150.2",
4
4
  "description": "Interactive CLI installer for Principles Disciple OpenClaw plugin",
5
5
  "type": "module",
6
6
  "bin": {
@@ -99,7 +99,7 @@
99
99
  "directory": "packages/create-principles-disciple"
100
100
  },
101
101
  "pd": {
102
- "bundledPluginVersion": "3.1.5"
102
+ "bundledPluginVersion": "3.2.1"
103
103
  },
104
- "gitHead": "7ad401c6ecb8a3f50d53783c0091fcf65dccadd9"
104
+ "gitHead": "3d6e2af3cf55ad63b7bb388c005adf4b923eb383"
105
105
  }