create-principles-disciple 1.93.0 → 1.94.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (228) hide show
  1. package/console/dist/server/config/pd-config-store.d.ts +7 -1
  2. package/console/dist/server/config/pd-config-store.js +11 -1
  3. package/console/dist/server/index.js +10 -6
  4. package/console/dist/server/models/ApprovalsConsoleModel.js +4 -12
  5. package/console/dist/server/routes/feedback-reports.js +1 -1
  6. package/core/dist/index.d.ts +2 -2
  7. package/core/dist/index.d.ts.map +1 -1
  8. package/core/dist/index.js +1 -1
  9. package/core/dist/index.js.map +1 -1
  10. package/core/dist/prompt-builder/__tests__/model-config.test.d.ts +2 -0
  11. package/core/dist/prompt-builder/__tests__/model-config.test.d.ts.map +1 -0
  12. package/core/dist/prompt-builder/__tests__/model-config.test.js +158 -0
  13. package/core/dist/prompt-builder/__tests__/model-config.test.js.map +1 -0
  14. package/core/dist/prompt-builder/__tests__/xml-escape.test.d.ts +2 -0
  15. package/core/dist/prompt-builder/__tests__/xml-escape.test.d.ts.map +1 -0
  16. package/core/dist/prompt-builder/__tests__/xml-escape.test.js +42 -0
  17. package/core/dist/prompt-builder/__tests__/xml-escape.test.js.map +1 -0
  18. package/core/dist/prompt-builder/index.d.ts +3 -0
  19. package/core/dist/prompt-builder/index.d.ts.map +1 -1
  20. package/core/dist/prompt-builder/index.js +2 -0
  21. package/core/dist/prompt-builder/index.js.map +1 -1
  22. package/core/dist/prompt-builder/model-config.d.ts +42 -0
  23. package/core/dist/prompt-builder/model-config.d.ts.map +1 -0
  24. package/core/dist/prompt-builder/model-config.js +84 -0
  25. package/core/dist/prompt-builder/model-config.js.map +1 -0
  26. package/core/dist/prompt-builder/xml-escape.d.ts +12 -0
  27. package/core/dist/prompt-builder/xml-escape.d.ts.map +1 -0
  28. package/core/dist/prompt-builder/xml-escape.js +19 -0
  29. package/core/dist/prompt-builder/xml-escape.js.map +1 -0
  30. package/core/dist/runtime-v2/__tests__/architecture-regression.test.js +87 -16
  31. package/core/dist/runtime-v2/__tests__/architecture-regression.test.js.map +1 -1
  32. package/core/dist/runtime-v2/__tests__/pain-signal-bridge-result-shaping.test.d.ts +2 -0
  33. package/core/dist/runtime-v2/__tests__/pain-signal-bridge-result-shaping.test.d.ts.map +1 -0
  34. package/core/dist/runtime-v2/__tests__/pain-signal-bridge-result-shaping.test.js +395 -0
  35. package/core/dist/runtime-v2/__tests__/pain-signal-bridge-result-shaping.test.js.map +1 -0
  36. package/core/dist/runtime-v2/bridge-result-shaper.d.ts +53 -0
  37. package/core/dist/runtime-v2/bridge-result-shaper.d.ts.map +1 -0
  38. package/core/dist/runtime-v2/bridge-result-shaper.js +117 -0
  39. package/core/dist/runtime-v2/bridge-result-shaper.js.map +1 -0
  40. package/core/dist/runtime-v2/detection/__tests__/detection-funnel-policy.test.d.ts +13 -0
  41. package/core/dist/runtime-v2/detection/__tests__/detection-funnel-policy.test.d.ts.map +1 -0
  42. package/core/dist/runtime-v2/detection/__tests__/detection-funnel-policy.test.js +111 -0
  43. package/core/dist/runtime-v2/detection/__tests__/detection-funnel-policy.test.js.map +1 -0
  44. package/core/dist/runtime-v2/detection/detection-funnel-policy.d.ts +103 -0
  45. package/core/dist/runtime-v2/detection/detection-funnel-policy.d.ts.map +1 -0
  46. package/core/dist/runtime-v2/detection/detection-funnel-policy.js +135 -0
  47. package/core/dist/runtime-v2/detection/detection-funnel-policy.js.map +1 -0
  48. package/core/dist/runtime-v2/detection/index.d.ts +10 -0
  49. package/core/dist/runtime-v2/detection/index.d.ts.map +1 -0
  50. package/core/dist/runtime-v2/detection/index.js +9 -0
  51. package/core/dist/runtime-v2/detection/index.js.map +1 -0
  52. package/core/dist/runtime-v2/evidence-triage/__tests__/observation-resolver.test.d.ts +12 -0
  53. package/core/dist/runtime-v2/evidence-triage/__tests__/observation-resolver.test.d.ts.map +1 -0
  54. package/core/dist/runtime-v2/evidence-triage/__tests__/observation-resolver.test.js +181 -0
  55. package/core/dist/runtime-v2/evidence-triage/__tests__/observation-resolver.test.js.map +1 -0
  56. package/core/dist/runtime-v2/evidence-triage/__tests__/triage-policy.test.js +104 -1
  57. package/core/dist/runtime-v2/evidence-triage/__tests__/triage-policy.test.js.map +1 -1
  58. package/core/dist/runtime-v2/evidence-triage/index.d.ts +3 -0
  59. package/core/dist/runtime-v2/evidence-triage/index.d.ts.map +1 -1
  60. package/core/dist/runtime-v2/evidence-triage/index.js +3 -0
  61. package/core/dist/runtime-v2/evidence-triage/index.js.map +1 -1
  62. package/core/dist/runtime-v2/evidence-triage/observation-resolver.d.ts +128 -0
  63. package/core/dist/runtime-v2/evidence-triage/observation-resolver.d.ts.map +1 -0
  64. package/core/dist/runtime-v2/evidence-triage/observation-resolver.js +203 -0
  65. package/core/dist/runtime-v2/evidence-triage/observation-resolver.js.map +1 -0
  66. package/core/dist/runtime-v2/evidence-triage/triage-policy.d.ts +4 -0
  67. package/core/dist/runtime-v2/evidence-triage/triage-policy.d.ts.map +1 -1
  68. package/core/dist/runtime-v2/evidence-triage/triage-policy.js +66 -9
  69. package/core/dist/runtime-v2/evidence-triage/triage-policy.js.map +1 -1
  70. package/core/dist/runtime-v2/evidence-triage/types.d.ts +14 -0
  71. package/core/dist/runtime-v2/evidence-triage/types.d.ts.map +1 -1
  72. package/core/dist/runtime-v2/evidence-triage/types.js.map +1 -1
  73. package/core/dist/runtime-v2/feature-flags/__tests__/feature-flag-contract.test.js +33 -4
  74. package/core/dist/runtime-v2/feature-flags/__tests__/feature-flag-contract.test.js.map +1 -1
  75. package/core/dist/runtime-v2/feature-flags/feature-flag-contract.d.ts.map +1 -1
  76. package/core/dist/runtime-v2/feature-flags/feature-flag-contract.js +9 -2
  77. package/core/dist/runtime-v2/feature-flags/feature-flag-contract.js.map +1 -1
  78. package/core/dist/runtime-v2/feedback/__tests__/redact-sensitive.test.d.ts +15 -0
  79. package/core/dist/runtime-v2/feedback/__tests__/redact-sensitive.test.d.ts.map +1 -0
  80. package/core/dist/runtime-v2/feedback/__tests__/redact-sensitive.test.js +450 -0
  81. package/core/dist/runtime-v2/feedback/__tests__/redact-sensitive.test.js.map +1 -0
  82. package/core/dist/runtime-v2/feedback/__tests__/render-github-url.test.d.ts +13 -0
  83. package/core/dist/runtime-v2/feedback/__tests__/render-github-url.test.d.ts.map +1 -0
  84. package/core/dist/runtime-v2/feedback/__tests__/render-github-url.test.js +243 -0
  85. package/core/dist/runtime-v2/feedback/__tests__/render-github-url.test.js.map +1 -0
  86. package/core/dist/runtime-v2/feedback/__tests__/safe-stringify.test.d.ts +12 -0
  87. package/core/dist/runtime-v2/feedback/__tests__/safe-stringify.test.d.ts.map +1 -0
  88. package/core/dist/runtime-v2/feedback/__tests__/safe-stringify.test.js +172 -0
  89. package/core/dist/runtime-v2/feedback/__tests__/safe-stringify.test.js.map +1 -0
  90. package/core/dist/runtime-v2/index.d.ts +8 -4
  91. package/core/dist/runtime-v2/index.d.ts.map +1 -1
  92. package/core/dist/runtime-v2/index.js +4 -2
  93. package/core/dist/runtime-v2/index.js.map +1 -1
  94. package/core/dist/runtime-v2/internalization/__tests__/c2-live-runner-chain.test.d.ts +2 -0
  95. package/core/dist/runtime-v2/internalization/__tests__/c2-live-runner-chain.test.d.ts.map +1 -0
  96. package/core/dist/runtime-v2/internalization/__tests__/c2-live-runner-chain.test.js +306 -0
  97. package/core/dist/runtime-v2/internalization/__tests__/c2-live-runner-chain.test.js.map +1 -0
  98. package/core/dist/runtime-v2/internalization/index.d.ts +0 -16
  99. package/core/dist/runtime-v2/internalization/index.d.ts.map +1 -1
  100. package/core/dist/runtime-v2/internalization/index.js +0 -8
  101. package/core/dist/runtime-v2/internalization/index.js.map +1 -1
  102. package/core/dist/runtime-v2/pain-gate/__tests__/pain-diagnostic-gate-policy.test.d.ts +15 -0
  103. package/core/dist/runtime-v2/pain-gate/__tests__/pain-diagnostic-gate-policy.test.d.ts.map +1 -0
  104. package/core/dist/runtime-v2/pain-gate/__tests__/pain-diagnostic-gate-policy.test.js +179 -0
  105. package/core/dist/runtime-v2/pain-gate/__tests__/pain-diagnostic-gate-policy.test.js.map +1 -0
  106. package/core/dist/runtime-v2/pain-gate/index.d.ts +10 -0
  107. package/core/dist/runtime-v2/pain-gate/index.d.ts.map +1 -0
  108. package/core/dist/runtime-v2/pain-gate/index.js +9 -0
  109. package/core/dist/runtime-v2/pain-gate/index.js.map +1 -0
  110. package/core/dist/runtime-v2/pain-gate/pain-diagnostic-gate-policy.d.ts +121 -0
  111. package/core/dist/runtime-v2/pain-gate/pain-diagnostic-gate-policy.d.ts.map +1 -0
  112. package/core/dist/runtime-v2/pain-gate/pain-diagnostic-gate-policy.js +157 -0
  113. package/core/dist/runtime-v2/pain-gate/pain-diagnostic-gate-policy.js.map +1 -0
  114. package/core/dist/runtime-v2/pain-signal-bridge.d.ts.map +1 -1
  115. package/core/dist/runtime-v2/pain-signal-bridge.js +14 -88
  116. package/core/dist/runtime-v2/pain-signal-bridge.js.map +1 -1
  117. package/core/dist/runtime-v2/pain-signal-observability.d.ts.map +1 -1
  118. package/core/dist/runtime-v2/pain-signal-observability.js +15 -5
  119. package/core/dist/runtime-v2/pain-signal-observability.js.map +1 -1
  120. package/core/dist/runtime-v2/types/event-types.d.ts +0 -27
  121. package/core/dist/runtime-v2/types/event-types.d.ts.map +1 -1
  122. package/core/dist/runtime-v2/types/event-types.js +2 -17
  123. package/core/dist/runtime-v2/types/event-types.js.map +1 -1
  124. package/core/dist/runtime-v2/types/index.d.ts +2 -2
  125. package/core/dist/runtime-v2/types/index.d.ts.map +1 -1
  126. package/core/dist/runtime-v2/types/index.js +3 -1
  127. package/core/dist/runtime-v2/types/index.js.map +1 -1
  128. package/core/dist/runtime-v2/types/pain-signal.d.ts +2 -2
  129. package/core/dist/runtime-v2/types/pain-signal.js +2 -2
  130. package/dist/mvp-config.d.ts +0 -10
  131. package/dist/mvp-config.d.ts.map +1 -1
  132. package/dist/mvp-config.js +0 -65
  133. package/dist/mvp-config.js.map +1 -1
  134. package/package.json +1 -1
  135. package/pd-cli/dist/commands/mvp-smoke.js +1 -1
  136. package/pd-cli/dist/commands/mvp-smoke.js.map +1 -1
  137. package/pd-cli/dist/commands/rulecode.js +1 -1
  138. package/pd-cli/dist/commands/rulecode.js.map +1 -1
  139. package/pd-cli/dist/commands/runtime-canary.d.ts.map +1 -1
  140. package/pd-cli/dist/commands/runtime-canary.js +10 -11
  141. package/pd-cli/dist/commands/runtime-canary.js.map +1 -1
  142. package/pd-cli/dist/commands/runtime-internalization-queue.d.ts.map +1 -1
  143. package/pd-cli/dist/commands/runtime-internalization-queue.js +13 -16
  144. package/pd-cli/dist/commands/runtime-internalization-queue.js.map +1 -1
  145. package/pd-cli/dist/commands/runtime-internalization-run-once.d.ts.map +1 -1
  146. package/pd-cli/dist/commands/runtime-internalization-run-once.js +3 -0
  147. package/pd-cli/dist/commands/runtime-internalization-run-once.js.map +1 -1
  148. package/pd-cli/dist/commands/runtime-internalization-run-rulehost.d.ts.map +1 -1
  149. package/pd-cli/dist/commands/runtime-internalization-run-rulehost.js +61 -7
  150. package/pd-cli/dist/commands/runtime-internalization-run-rulehost.js.map +1 -1
  151. package/pd-cli/dist/commands/runtime.js +1 -1
  152. package/pd-cli/dist/commands/runtime.js.map +1 -1
  153. package/pd-cli/dist/index.js +67 -34
  154. package/pd-cli/dist/index.js.map +1 -1
  155. package/pd-cli/dist/services/__tests__/rulehost-readiness.test.d.ts +2 -0
  156. package/pd-cli/dist/services/__tests__/rulehost-readiness.test.d.ts.map +1 -0
  157. package/pd-cli/dist/services/__tests__/rulehost-readiness.test.js +314 -0
  158. package/pd-cli/dist/services/__tests__/rulehost-readiness.test.js.map +1 -0
  159. package/pd-cli/dist/services/__tests__/runtime-adapter-resolver.test.js +20 -12
  160. package/pd-cli/dist/services/__tests__/runtime-adapter-resolver.test.js.map +1 -1
  161. package/pd-cli/dist/services/rulehost-readiness.d.ts +62 -0
  162. package/pd-cli/dist/services/rulehost-readiness.d.ts.map +1 -0
  163. package/pd-cli/dist/services/rulehost-readiness.js +214 -0
  164. package/pd-cli/dist/services/rulehost-readiness.js.map +1 -0
  165. package/pd-cli/dist/services/runtime-adapter-resolver.d.ts +1 -1
  166. package/pd-cli/dist/services/runtime-adapter-resolver.js +3 -3
  167. package/pd-cli/dist/services/runtime-adapter-resolver.js.map +1 -1
  168. package/plugin/dist/commands/evolution-status.js +0 -2
  169. package/plugin/dist/core/detection-funnel.d.ts +25 -11
  170. package/plugin/dist/core/detection-funnel.js +32 -80
  171. package/plugin/dist/core/event-log.d.ts +1 -3
  172. package/plugin/dist/core/event-log.js +10 -21
  173. package/plugin/dist/core/evolution-reducer.d.ts +0 -8
  174. package/plugin/dist/core/evolution-reducer.js +9 -19
  175. package/plugin/dist/core/pain-diagnostic-gate.d.ts +37 -28
  176. package/plugin/dist/core/pain-diagnostic-gate.js +53 -89
  177. package/plugin/dist/core/pain.d.ts +0 -63
  178. package/plugin/dist/core/pain.js +0 -167
  179. package/plugin/dist/core/paths.d.ts +0 -1
  180. package/plugin/dist/core/paths.js +2 -1
  181. package/plugin/dist/core/schema/migrations/001-init-trajectory.js +3 -6
  182. package/plugin/dist/core/schema/schema-definitions.js +4 -9
  183. package/plugin/dist/core/trajectory.d.ts +0 -16
  184. package/plugin/dist/core/trajectory.js +9 -60
  185. package/plugin/dist/hooks/after-tool-call-helpers.d.ts +4 -1
  186. package/plugin/dist/hooks/after-tool-call-helpers.js +13 -17
  187. package/plugin/dist/hooks/gate-block-helper.js +57 -17
  188. package/plugin/dist/hooks/lifecycle.js +3 -6
  189. package/plugin/dist/hooks/llm.js +66 -26
  190. package/plugin/dist/hooks/pain.d.ts +3 -1
  191. package/plugin/dist/hooks/pain.js +119 -49
  192. package/plugin/dist/hooks/prompt-helpers.d.ts +87 -0
  193. package/plugin/dist/hooks/prompt-helpers.js +251 -0
  194. package/plugin/dist/hooks/prompt-types.d.ts +66 -0
  195. package/plugin/dist/hooks/prompt-types.js +12 -0
  196. package/plugin/dist/hooks/prompt.d.ts +7 -38
  197. package/plugin/dist/hooks/prompt.js +361 -325
  198. package/plugin/dist/hooks/raw-observation-adapter.d.ts +9 -50
  199. package/plugin/dist/hooks/raw-observation-adapter.js +9 -164
  200. package/plugin/dist/hooks/raw-observation-types.d.ts +6 -57
  201. package/plugin/dist/hooks/raw-observation-types.js +5 -9
  202. package/plugin/dist/hooks/triage-adapter.js +6 -26
  203. package/plugin/dist/hooks/trigger-cooldown-tracker.d.ts +12 -0
  204. package/plugin/dist/hooks/trigger-cooldown-tracker.js +25 -0
  205. package/plugin/dist/service/evolution-worker.js +6 -64
  206. package/plugin/dist/service/runtime-summary-service.d.ts +0 -2
  207. package/plugin/dist/service/runtime-summary-service.js +0 -4
  208. package/plugin/dist/types/event-types.d.ts +1 -1
  209. package/plugin/scripts/sync-plugin.mjs +33 -22
  210. package/plugin/scripts/validate-live-path.ts +0 -18
  211. package/plugin/templates/langs/en/skills/pd-cli-operator/SKILL.md +20 -11
  212. package/plugin/templates/langs/en/skills/pd-runtime-v2/SKILL.md +10 -0
  213. package/plugin/templates/langs/zh/skills/pd-cli-operator/SKILL.md +20 -11
  214. package/plugin/templates/langs/zh/skills/pd-runtime-v2/SKILL.md +10 -0
  215. package/console/dist/server/config/feature-flags.d.ts +0 -25
  216. package/console/dist/server/config/feature-flags.js +0 -101
  217. package/pd-cli/dist/commands/central-sync.d.ts +0 -10
  218. package/pd-cli/dist/commands/central-sync.d.ts.map +0 -1
  219. package/pd-cli/dist/commands/central-sync.js +0 -32
  220. package/pd-cli/dist/commands/central-sync.js.map +0 -1
  221. package/pd-cli/dist/services/feature-flag-loader.d.ts +0 -6
  222. package/pd-cli/dist/services/feature-flag-loader.d.ts.map +0 -1
  223. package/pd-cli/dist/services/feature-flag-loader.js +0 -53
  224. package/pd-cli/dist/services/feature-flag-loader.js.map +0 -1
  225. package/plugin/dist/core/observability.d.ts +0 -40
  226. package/plugin/dist/core/observability.js +0 -164
  227. package/plugin/dist/hooks/subagent.d.ts +0 -9
  228. package/plugin/dist/hooks/subagent.js +0 -122
@@ -0,0 +1,214 @@
1
+ /**
2
+ * RuleHost Readiness Resolver — PRI-461
3
+ *
4
+ * Checks all preconditions for `run-rulehost` BEFORE constructing adapters,
5
+ * returning one of three user-visible statuses:
6
+ * - `ready`: all agents enabled with pi-ai profiles and API keys; code-rule capability ON
7
+ * - `text_principle_only`: dreamer/philosopher/scribe ready, but code-rule capability OFF
8
+ * (flag disabled, or artificer/evaluator not ready)
9
+ * - `refused`: dreamer/philosopher/scribe chain broken (disabled, wrong profile, missing API key,
10
+ * or config malformed)
11
+ *
12
+ * This module NEVER throws. It always returns a structured result with reason + nextAction,
13
+ * so the CLI handler can emit a clear status instead of an opaque adapter-resolution failure.
14
+ *
15
+ * ERR refs:
16
+ * - EP-02 / ERR-024, ERR-025: wired into the production handler path (runtime-internalization-run-rulehost.ts)
17
+ * - EP-03: refused/text_principle_only include reason + nextAction
18
+ * - EP-07: uses the same config source as the pipeline (resolveRuntimeFromPdConfig)
19
+ * - EP-09: tests cover the default installed config pattern
20
+ */
21
+ import { resolveAgentRuntimeBinding, checkAgentRuntimeReadiness, computeFeatureFlagsFromConfig, isFeatureEnabled, } from '@principles/core/runtime-v2';
22
+ import { resolveRuntimeFromPdConfig } from './resolve-runtime-from-pd-config.js';
23
+ // ── Constants ─────────────────────────────────────────────────────────────────
24
+ /**
25
+ * Agents required for the text-principle path (dreamer → philosopher → scribe).
26
+ * If any of these is not ready, the pipeline cannot produce even text principles.
27
+ */
28
+ const REQUIRED_AGENTS = ['dreamer', 'philosopher', 'scribe'];
29
+ /**
30
+ * Agents required for the code-rule capability (artificer + evaluator).
31
+ * Both must be ready for the adversarial loop to run.
32
+ */
33
+ const CODE_RULE_AGENTS = ['artificer', 'evaluator'];
34
+ // ── Implementation ────────────────────────────────────────────────────────────
35
+ /**
36
+ * Check a single agent's readiness for the RuleHost pipeline.
37
+ *
38
+ * Checks (in order):
39
+ * 1. Agent enabled (via resolveAgentRuntimeBinding)
40
+ * 2. Profile exists (via resolveAgentRuntimeBinding)
41
+ * 3. Profile type is 'pi-ai' (RuleHost needs PiAiRuntimeAdapter)
42
+ * 4. Profile is ready (via checkAgentRuntimeReadiness — provider/model/apiKeyEnv set, env var exists)
43
+ *
44
+ * Returns a structured AgentReadiness result. Never throws.
45
+ */
46
+ function checkAgentReadiness(effective, agentName, getEnvVar) {
47
+ const binding = resolveAgentRuntimeBinding(effective, agentName);
48
+ if (!binding.ok) {
49
+ return {
50
+ status: binding.readiness === 'disabled' ? 'disabled' : binding.readiness === 'needs_setup' ? 'needs_setup' : 'not_ready',
51
+ reason: binding.reason,
52
+ nextAction: binding.nextAction,
53
+ };
54
+ }
55
+ const profile = binding.profile;
56
+ const profileType = profile.type;
57
+ // RuleHost pipeline constructs PiAiRuntimeAdapter instances, so the profile
58
+ // must be pi-ai. OpenClaw profiles delegate to OpenClaw's own runtime, which
59
+ // is not available in the RuleHost pipeline context.
60
+ if (profileType !== 'pi-ai') {
61
+ return {
62
+ status: 'wrong_profile_type',
63
+ reason: `Agent '${agentName}' uses profile '${binding.profileId}' with type '${profileType}', but RuleHost requires pi-ai profile type`,
64
+ nextAction: `Add a pi-ai runtime profile to .pd/config.yaml and assign it to ${agentName} via internalAgents.agents.${agentName}.runtimeProfile`,
65
+ profileId: binding.profileId,
66
+ profileType,
67
+ };
68
+ }
69
+ const readiness = checkAgentRuntimeReadiness(profile, getEnvVar);
70
+ if (readiness.readiness !== 'ready') {
71
+ return {
72
+ status: readiness.readiness === 'needs_setup' ? 'needs_setup' : 'not_ready',
73
+ reason: readiness.reason,
74
+ nextAction: readiness.nextAction,
75
+ profileId: binding.profileId,
76
+ profileType,
77
+ };
78
+ }
79
+ return {
80
+ status: 'ready',
81
+ profileId: binding.profileId,
82
+ profileType,
83
+ };
84
+ }
85
+ function emptyAgentStatuses() {
86
+ const empty = { status: 'not_ready', reason: 'not checked' };
87
+ return {
88
+ dreamer: empty,
89
+ philosopher: empty,
90
+ scribe: empty,
91
+ artificer: empty,
92
+ evaluator: empty,
93
+ };
94
+ }
95
+ function buildRefusedResult(reason, nextAction, parts) {
96
+ return {
97
+ status: 'refused',
98
+ reason,
99
+ nextAction,
100
+ agentStatuses: parts.agentStatuses,
101
+ codeRuleCapability: parts.codeRuleCapability,
102
+ };
103
+ }
104
+ function buildTextPrincipleOnlyResult(reason, nextAction, parts) {
105
+ return {
106
+ status: 'text_principle_only',
107
+ reason,
108
+ nextAction,
109
+ agentStatuses: parts.agentStatuses,
110
+ codeRuleCapability: parts.codeRuleCapability,
111
+ };
112
+ }
113
+ function resolveRuleHostReadinessUnchecked(workspaceDir, getEnvVar) {
114
+ // ── Step 1: Load config ──
115
+ const { configLoadResult } = resolveRuntimeFromPdConfig(workspaceDir, getEnvVar);
116
+ if (!configLoadResult.ok) {
117
+ const [firstError] = configLoadResult.errors;
118
+ const reason = `config_malformed: ${firstError?.reason ?? 'unknown config error'}`;
119
+ const nextAction = firstError?.nextAction ?? 'Fix .pd/config.yaml syntax and retry';
120
+ return buildRefusedResult(reason, nextAction, {
121
+ agentStatuses: emptyAgentStatuses(),
122
+ codeRuleCapability: { enabled: false, disabledReason: 'config_malformed' },
123
+ });
124
+ }
125
+ const { effective } = configLoadResult;
126
+ // ── Step 2: Check required agents (dreamer, philosopher, scribe) ──
127
+ // Start with all 5 keys set to 'not checked'; updated as each agent is checked.
128
+ const agentStatuses = emptyAgentStatuses();
129
+ const requiredFailures = [];
130
+ for (const agentName of REQUIRED_AGENTS) {
131
+ const readiness = checkAgentReadiness(effective, agentName, getEnvVar);
132
+ agentStatuses[agentName] = readiness;
133
+ if (readiness.status !== 'ready') {
134
+ requiredFailures.push(`${agentName}: ${readiness.reason ?? readiness.status}`);
135
+ }
136
+ }
137
+ if (requiredFailures.length > 0) {
138
+ const reason = `required_agents_not_ready: ${requiredFailures.join('; ')}`;
139
+ const nextAction = `Fix the following agent issues in .pd/config.yaml: ${requiredFailures.join('; ')}. RuleHost requires dreamer, philosopher, and scribe agents to be enabled with pi-ai runtime profiles and valid API keys.`;
140
+ return buildRefusedResult(reason, nextAction, {
141
+ agentStatuses,
142
+ codeRuleCapability: { enabled: false, disabledReason: 'required_agents_not_ready' },
143
+ });
144
+ }
145
+ // ── Step 3: Check code_rule_capability feature flag ──
146
+ const featureFlags = computeFeatureFlagsFromConfig(effective);
147
+ if (!isFeatureEnabled(featureFlags, 'code_rule_capability')) {
148
+ const reason = 'code_rule_capability feature flag is disabled';
149
+ const nextAction = "Enable code_rule_capability in .pd/config.yaml features.code_rule_capability.enabled to run the full adversarial pipeline. Text-principle-only mode is available.";
150
+ // Still check artificer/evaluator for reporting, but they don't affect the status
151
+ for (const agentName of CODE_RULE_AGENTS) {
152
+ agentStatuses[agentName] = checkAgentReadiness(effective, agentName, getEnvVar);
153
+ }
154
+ return buildTextPrincipleOnlyResult(reason, nextAction, {
155
+ agentStatuses,
156
+ codeRuleCapability: { enabled: false, disabledReason: reason },
157
+ });
158
+ }
159
+ // ── Step 4: Check code-rule agents (artificer, evaluator) ──
160
+ const codeRuleFailures = [];
161
+ for (const agentName of CODE_RULE_AGENTS) {
162
+ const readiness = checkAgentReadiness(effective, agentName, getEnvVar);
163
+ agentStatuses[agentName] = readiness;
164
+ if (readiness.status !== 'ready') {
165
+ codeRuleFailures.push(`${agentName}: ${readiness.reason ?? readiness.status}`);
166
+ }
167
+ }
168
+ if (codeRuleFailures.length > 0) {
169
+ const reason = `code_rule_agents_not_ready: ${codeRuleFailures.join('; ')}`;
170
+ const nextAction = `Fix the following agent issues to enable code-rule capability: ${codeRuleFailures.join('; ')}. Text-principle-only mode is available with the current configuration.`;
171
+ return buildTextPrincipleOnlyResult(reason, nextAction, {
172
+ agentStatuses,
173
+ codeRuleCapability: { enabled: false, disabledReason: reason },
174
+ });
175
+ }
176
+ // ── Step 5: All checks pass → ready ──
177
+ return {
178
+ status: 'ready',
179
+ reason: 'All agents ready with pi-ai profiles and valid API keys. Code-rule capability is ON.',
180
+ nextAction: 'Pass --confirm to run the full pipeline.',
181
+ agentStatuses,
182
+ codeRuleCapability: { enabled: true },
183
+ };
184
+ }
185
+ /**
186
+ * Resolve RuleHost readiness from the workspace's .pd/config.yaml.
187
+ *
188
+ * This is the production entry point called by the `run-rulehost` handler
189
+ * BEFORE constructing any adapters. It returns a structured result so the
190
+ * handler can emit a clear status instead of an opaque adapter-resolution failure.
191
+ *
192
+ * This function NEVER throws. Any unexpected exception from config loading,
193
+ * feature-flag computation, agent checks, or getEnvVar is caught and converted
194
+ * to a `refused` result with reason + nextAction (Runtime Contract #9).
195
+ *
196
+ * @param workspaceDir - The workspace directory containing .pd/config.yaml
197
+ * @param getEnvVar - Env var accessor, defaults to process.env. Injected for testability.
198
+ * @returns Structured readiness result. Never throws.
199
+ */
200
+ export function resolveRuleHostReadiness(workspaceDir, getEnvVar = (name) => process.env[name]) {
201
+ try {
202
+ return resolveRuleHostReadinessUnchecked(workspaceDir, getEnvVar);
203
+ }
204
+ catch (error) {
205
+ const message = error instanceof Error && error.message.length > 0
206
+ ? error.message
207
+ : 'unknown readiness resolution error';
208
+ return buildRefusedResult(`readiness_resolution_failed: ${message}`, 'Fix the readiness resolution error and retry. Run `pd config doctor` for diagnostics.', {
209
+ agentStatuses: emptyAgentStatuses(),
210
+ codeRuleCapability: { enabled: false, disabledReason: 'readiness_resolution_failed' },
211
+ });
212
+ }
213
+ }
214
+ //# sourceMappingURL=rulehost-readiness.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rulehost-readiness.js","sourceRoot":"","sources":["../../src/services/rulehost-readiness.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EACL,0BAA0B,EAC1B,0BAA0B,EAC1B,6BAA6B,EAC7B,gBAAgB,GACjB,MAAM,6BAA6B,CAAC;AAKrC,OAAO,EAAE,0BAA0B,EAAE,MAAM,qCAAqC,CAAC;AAmDjF,iFAAiF;AAEjF;;;GAGG;AACH,MAAM,eAAe,GAAiC,CAAC,SAAS,EAAE,aAAa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C;QAC1L,OAAO,4BAA4B,CAAC,MAAM,EAAE,UAAU,EAAE;YACtD,aAAa;YACb,kBAAkB,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,EAAE;SAC/D,CAAC,CAAC;IACL,CAAC;IAED,wCAAwC;IACxC,OAAO;QACL,MAAM,EAAE,OAAO;QACf,MAAM,EAAE,sFAAsF;QAC9F,UAAU,EAAE,0CAA0C;QACtD,aAAa;QACb,kBAAkB,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE;KACtC,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,wBAAwB,CACtC,YAAoB,EACpB,YAAkD,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC;IAE7E,IAAI,CAAC;QACH,OAAO,iCAAiC,CAAC,YAAY,EAAE,SAAS,CAAC,CAAC;IACpE,CAAC;IAAC,OAAO,KAAc,EAAE,CAAC;QACxB,MAAM,OAAO,GACX,KAAK,YAAY,KAAK,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC;YAChD,CAAC,CAAC,KAAK,CAAC,OAAO;YACf,CAAC,CAAC,oCAAoC,CAAC;QAC3C,OAAO,kBAAkB,CACvB,gCAAgC,OAAO,EAAE,EACzC,uFAAuF,EACvF;YACE,aAAa,EAAE,kBAAkB,EAAE;YACnC,kBAAkB,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,6BAA6B,EAAE;SACtF,CACF,CAAC;IACJ,CAAC;AACH,CAAC"}
@@ -13,7 +13,7 @@
13
13
  * - CLI-gate concerns (process.exit, telemetry, help text) stay at call sites.
14
14
  * This resolver throws structured `ConfigResolutionError` that handlers translate.
15
15
  * - Lives in pd-cli/services (NOT core) because it constructs adapters and reads
16
- * CLI feature flags via `loadEffectiveFeatureFlags`, which is a pd-cli service.
16
+ * PD config via `loadPdConfig` + `computeFlagsFromLoadResult`, which are pd-cli services.
17
17
  *
18
18
  * ERR refs:
19
19
  * - ERR-001 (no any): all types explicit
@@ -13,7 +13,7 @@
13
13
  * - CLI-gate concerns (process.exit, telemetry, help text) stay at call sites.
14
14
  * This resolver throws structured `ConfigResolutionError` that handlers translate.
15
15
  * - Lives in pd-cli/services (NOT core) because it constructs adapters and reads
16
- * CLI feature flags via `loadEffectiveFeatureFlags`, which is a pd-cli service.
16
+ * PD config via `loadPdConfig` + `computeFlagsFromLoadResult`, which are pd-cli services.
17
17
  *
18
18
  * ERR refs:
19
19
  * - ERR-001 (no any): all types explicit
@@ -24,7 +24,7 @@
24
24
  */
25
25
  import { TestDoubleRuntimeAdapter, PiAiRuntimeAdapter, OpenClawCliRuntimeAdapter, L2AgentLoopAdapter, buildL2PrincipleReaderFromLedger, isRuntimeConfigError, validateRuntimeConfig, } from '@principles/core/runtime-v2';
26
26
  import { loadLedger } from '@principles/core/principle-tree-ledger';
27
- import { loadEffectiveFeatureFlags } from './feature-flag-loader.js';
27
+ import { loadPdConfig, computeFlagsFromLoadResult } from './pd-config-loader.js';
28
28
  import { resolveRuntimeFromPdConfig } from './resolve-runtime-from-pd-config.js';
29
29
  export class ConfigResolutionError extends Error {
30
30
  kind;
@@ -126,7 +126,7 @@ export function resolveRuntimeAdapterFromConfig(opts) {
126
126
  // dreamer runner, route through the L2 multi-turn agent loop adapter.
127
127
  // Other runners (philosopher/scribe/...) stay on L1.
128
128
  if (opts.runnerKind === 'dreamer' && opts.l2ArtifactReader && opts.l2StateDir) {
129
- const effectiveFlags = loadEffectiveFeatureFlags(opts.workspaceDir);
129
+ const effectiveFlags = computeFlagsFromLoadResult(loadPdConfig(opts.workspaceDir));
130
130
  const l2FlagDef = Object.hasOwn(effectiveFlags.flags, 'l2_dreamer')
131
131
  ? effectiveFlags.flags.l2_dreamer
132
132
  : undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"runtime-adapter-resolver.js","sourceRoot":"","sources":["../../src/services/runtime-adapter-resolver.ts"],"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CAAC,CAAC;IAC5D,CAAC;IAED,0EAA0E;IAC1E,MAAM,IAAI,KAAK,CACb,6BAA6B,IAAI,CAAC,WAAW,uDAAuD,CACrG,CAAC;AACJ,CAAC;AAKD,OAAO,EAAE,wBAAwB,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,CAAC"}
1
+ {"version":3,"file":"runtime-adapter-resolver.js","sourceRoot":"","sources":["../../src/services/runtime-adapter-resolver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EACL,wBAAwB,EACxB,kBAAkB,EAClB,yBAAyB,EACzB,kBAAkB,EAClB,gCAAgC,EAChC,oBAAoB,EACpB,qBAAqB,GACtB,MAAM,6BAA6B,CAAC;AAErC,OAAO,EAAE,UAAU,EAAE,MAAM,wCAAwC,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,0BAA0B,EAAE,MAAM,uBAAuB,CAAC;AACjF,OAAO,EAAE,0BAA0B,EAAE,MAAM,qCAAqC,CAAC;AAkBjF,MAAM,OAAO,qBAAsB,SAAQ,KAAK;IACrC,IAAI,CAA4B;IAChC,OAAO,CAAY;IACnB,UAAU,CAAU;IAE7B,YACE,OAAe,EACf,IAA+B,EAC/B,OAAsC;QAEtC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;QACpC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,OAAO,GAAG,OAAO,EAAE,OAAO,CAAC;QAChC,IAAI,CAAC,UAAU,GAAG,OAAO,EAAE,UAAU,CAAC;IACxC,CAAC;CACF;AAkED,8EAA8E;AAE9E,MAAM,UAAU,+BAA+B,CAAC,IAA2B;IACzE,2EAA2E;IAC3E,IAAI,IAAI,CAAC,WAAW,KAAK,aAAa,EAAE,CAAC;QACvC,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,CAAC;YAC1B,MAAM,IAAI,qBAAqB,CAC7B,0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AC9H,CACF,CAAC;QACJ,CAAC;QACD,iGAAiG;QACjG,MAAM,mBAAmB,GAIrB;YACF,WAAW,EAAE,YAAY;YACzB,YAAY,EAAE,IAAI,CAAC,YAAY;SAChC,CAAC;QACF,IAAI,IAAI,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;YAC/B,mBAAmB,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;QAC7C,CAAC;QACD,OAAO,IAAI,yBAAyB,CAAC,mBAAmB,CAAC,CAAC;IAC5D,CAAC;IAED,0EAA0E;IAC1E,MAAM,IAAI,KAAK,CACb,6BAA6B,IAAI,CAAC,WAAW,uDAAuD,CACrG,CAAC;AACJ,CAAC;AAKD,OAAO,EAAE,wBAAwB,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,CAAC"}
@@ -38,7 +38,6 @@ function buildEnglishOutput(workspaceDir, sessionId, warnings, stats, summary, r
38
38
  'Control Plane',
39
39
  `- Session GFI: current ${formatNumber(summary.gfi.current)}, peak ${formatNumber(summary.gfi.peak)} (${summary.gfi.dataQuality})`,
40
40
  `- GFI Sources: ${formatSources(summary.gfi.sources)}`,
41
- `- Pain Flag: ${summary.pain.activeFlag ? 'active' : 'inactive'}${summary.pain.activeFlagSource ? ` (${summary.pain.activeFlagSource})` : ''}`,
42
41
  `- Last Pain Signal: ${summary.pain.lastSignal ? `${summary.pain.lastSignal.source}${summary.pain.lastSignal.reason ? ` - ${summary.pain.lastSignal.reason}` : ''}` : '--'}`,
43
42
  `- Gate Events: blocks ${formatNumber(summary.gate.recentBlocks)}, bypasses ${formatNumber(summary.gate.recentBypasses)} (${summary.gate.dataQuality})`,
44
43
  '',
@@ -97,7 +96,6 @@ function buildChineseOutput(workspaceDir, sessionId, warnings, stats, summary, r
97
96
  '控制面',
98
97
  `- 会话 GFI: 当前 ${formatNumber(summary.gfi.current)},峰值 ${formatNumber(summary.gfi.peak)} (${summary.gfi.dataQuality})`,
99
98
  `- GFI 来源: ${formatSources(summary.gfi.sources)}`,
100
- `- Pain Flag: ${summary.pain.activeFlag ? 'active' : 'inactive'}${summary.pain.activeFlagSource ? ` (${summary.pain.activeFlagSource})` : ''}`,
101
99
  `- 最近 Pain 信号: ${summary.pain.lastSignal ? `${summary.pain.lastSignal.source}${summary.pain.lastSignal.reason ? ` - ${summary.pain.lastSignal.reason}` : ''}` : '--'}`,
102
100
  `- Gate 事件: block ${formatNumber(summary.gate.recentBlocks)},bypass ${formatNumber(summary.gate.recentBypasses)} (${summary.gate.dataQuality})`,
103
101
  '',
@@ -1,24 +1,38 @@
1
+ /**
2
+ * Detection Funnel — PRI-446 thin adapter
3
+ *
4
+ * The pure three-layer funnel logic (LRU cache, async queue, layer dispatch)
5
+ * now lives in principles-core
6
+ * (runtime-v2/detection/detection-funnel-policy.ts). This file is a thin shell
7
+ * that wires DetectionFunnelCore with the two environment-coupled dependencies
8
+ * the plugin owns:
9
+ * - crypto.createHash (the L2 cache key hasher)
10
+ * - PainDictionary.match (the L1 exact matcher)
11
+ * - shouldIgnorePainProtocolText (the protocol-token gate)
12
+ *
13
+ * It re-exports DetectionFunnel (same class name + constructor signature) and
14
+ * DetectionResult so DetectionService, llm.ts, and evolution-worker keep working
15
+ * unchanged.
16
+ *
17
+ * ERR checklist:
18
+ * - ERR-011: this is a thin adapter delegating to core pure logic.
19
+ */
1
20
  import { type PainDictionary } from './dictionary.js';
2
- export interface DetectionResult {
3
- detected: boolean;
4
- severity?: number;
5
- ruleId?: string;
6
- source: 'l1_exact' | 'l2_cache' | 'l3_async_queued' | 'l3_semantic_hit';
7
- }
21
+ import { type DetectionResult } from '@principles/core/runtime-v2';
22
+ export type { DetectionResult };
8
23
  /**
9
24
  * Orchestrates the three-layer detection funnel for pain signals.
25
+ *
26
+ * Delegates to the core DetectionFunnelCore, injecting the crypto hasher,
27
+ * the dictionary matcher, and the protocol-token gate.
10
28
  */
11
29
  export declare class DetectionFunnel {
12
- private readonly cache;
13
- private asyncQueue;
14
- private readonly dictionary;
30
+ private readonly core;
15
31
  constructor(dictionary: PainDictionary);
16
32
  /**
17
33
  * Detects pain in the given text using L1 (Exact), L2 (Cache), and L3 (Async).
18
34
  */
19
35
  detect(text: string): DetectionResult;
20
- private static computeHash;
21
- private enqueueAsync;
22
36
  /**
23
37
  * Internal method for the worker to update the cache after a semantic hit.
24
38
  */
@@ -1,104 +1,56 @@
1
- import { createHash } from 'crypto';
2
- import { shouldIgnorePainProtocolText } from './dictionary.js';
3
1
  /**
4
- * A simple LRU Cache implementation using Map.
2
+ * Detection Funnel — PRI-446 thin adapter
3
+ *
4
+ * The pure three-layer funnel logic (LRU cache, async queue, layer dispatch)
5
+ * now lives in principles-core
6
+ * (runtime-v2/detection/detection-funnel-policy.ts). This file is a thin shell
7
+ * that wires DetectionFunnelCore with the two environment-coupled dependencies
8
+ * the plugin owns:
9
+ * - crypto.createHash (the L2 cache key hasher)
10
+ * - PainDictionary.match (the L1 exact matcher)
11
+ * - shouldIgnorePainProtocolText (the protocol-token gate)
12
+ *
13
+ * It re-exports DetectionFunnel (same class name + constructor signature) and
14
+ * DetectionResult so DetectionService, llm.ts, and evolution-worker keep working
15
+ * unchanged.
16
+ *
17
+ * ERR checklist:
18
+ * - ERR-011: this is a thin adapter delegating to core pure logic.
5
19
  */
6
- class SimpleLRU {
7
- cache;
8
- maxSize;
9
- constructor(maxSize = 100) {
10
- this.cache = new Map();
11
- this.maxSize = maxSize;
12
- }
13
- get(key) {
14
- const item = this.cache.get(key);
15
- if (item !== undefined) {
16
- // Refresh: delete and re-insert
17
- this.cache.delete(key);
18
- this.cache.set(key, item);
19
- }
20
- return item;
21
- }
22
- set(key, value) {
23
- if (this.cache.has(key)) {
24
- this.cache.delete(key);
25
- }
26
- else if (this.cache.size >= this.maxSize) {
27
- // Remove the oldest (first) item
28
- const firstKey = this.cache.keys().next().value;
29
- if (firstKey !== undefined) {
30
- this.cache.delete(firstKey);
31
- }
32
- }
33
- this.cache.set(key, value);
34
- }
35
- }
20
+ import { createHash } from 'crypto';
21
+ import { shouldIgnorePainProtocolText } from './dictionary.js';
22
+ import { DetectionFunnelCore, } from '@principles/core/runtime-v2';
36
23
  /**
37
24
  * Orchestrates the three-layer detection funnel for pain signals.
25
+ *
26
+ * Delegates to the core DetectionFunnelCore, injecting the crypto hasher,
27
+ * the dictionary matcher, and the protocol-token gate.
38
28
  */
39
29
  export class DetectionFunnel {
40
- cache = new SimpleLRU(100);
41
- asyncQueue = [];
42
- dictionary;
30
+ core;
43
31
  constructor(dictionary) {
44
- this.dictionary = dictionary;
32
+ this.core = new DetectionFunnelCore({
33
+ match: (text) => dictionary.match(text),
34
+ hash: (text) => createHash('sha256').update(text).digest('hex'),
35
+ shouldIgnoreProtocol: shouldIgnorePainProtocolText,
36
+ });
45
37
  }
46
38
  /**
47
39
  * Detects pain in the given text using L1 (Exact), L2 (Cache), and L3 (Async).
48
40
  */
49
41
  detect(text) {
50
- if (shouldIgnorePainProtocolText(text)) {
51
- return { detected: false, source: 'l1_exact' };
52
- }
53
- // --- Layer 1: Exact Match (Sync) ---
54
- const exactMatch = this.dictionary.match(text);
55
- if (exactMatch) {
56
- return {
57
- detected: true,
58
- severity: exactMatch.severity,
59
- ruleId: exactMatch.ruleId,
60
- source: 'l1_exact'
61
- };
62
- }
63
- // --- Layer 2: LRU Cache (Sync) ---
64
- const hash = DetectionFunnel.computeHash(text);
65
- const cached = this.cache.get(hash);
66
- if (cached) {
67
- return {
68
- detected: cached.detected,
69
- severity: cached.severity,
70
- source: 'l2_cache'
71
- };
72
- }
73
- // --- Layer 3: Async Semantic Queue ---
74
- this.enqueueAsync(text);
75
- return {
76
- detected: false,
77
- source: 'l3_async_queued'
78
- };
79
- }
80
- static computeHash(text) {
81
- return createHash('sha256').update(text).digest('hex');
82
- }
83
- enqueueAsync(text) {
84
- if (this.asyncQueue.length < 1000) {
85
- this.asyncQueue.push(text);
86
- }
87
- // Worker will pick this up and perform semantic search via createMemorySearchTool
42
+ return this.core.detect(text);
88
43
  }
89
44
  /**
90
45
  * Internal method for the worker to update the cache after a semantic hit.
91
46
  */
92
47
  updateCache(text, result) {
93
- const hash = DetectionFunnel.computeHash(text);
94
- this.cache.set(hash, result);
48
+ this.core.updateCache(text, result);
95
49
  }
96
50
  /**
97
51
  * Retrieves and clears the current asynchronous queue.
98
52
  */
99
53
  flushQueue() {
100
- const queue = [...this.asyncQueue];
101
- this.asyncQueue = [];
102
- return queue;
54
+ return this.core.flushQueue();
103
55
  }
104
56
  }
@@ -1,4 +1,4 @@
1
- import type { EventLogEntry, DailyStats, EmpathyEventStats, ToolCallEventData, PainSignalEventData, RuleMatchEventData, RulePromotionEventData, HookExecutionEventData, GateBlockEventData, GateBypassEventData, PlanApprovalEventData, EvolutionTaskEventData, EmpathyRollbackEventData, DiagnosisTaskEventData, HeartbeatDiagnosisEventData, DiagnosticianReportEventData, PrincipleCandidateEventData, RuleEnforcedEventData, RuleHostEvaluatedEventData, RuleHostBlockedEventData, RuleHostRequireApprovalEventData, RuleHostAutoCorrectProposedEventData, RuleHostAutoCorrectAppliedEventData, RuntimeV2PromptActivationsInjectedEventData, RuleHostUnhealthyEventData } from '../types/event-types.js';
1
+ import type { EventLogEntry, DailyStats, EmpathyEventStats, ToolCallEventData, PainSignalEventData, RulePromotionEventData, HookExecutionEventData, GateBlockEventData, GateBypassEventData, PlanApprovalEventData, EvolutionTaskEventData, EmpathyRollbackEventData, DiagnosisTaskEventData, HeartbeatDiagnosisEventData, DiagnosticianReportEventData, PrincipleCandidateEventData, RuleEnforcedEventData, RuleHostEvaluatedEventData, RuleHostBlockedEventData, RuleHostRequireApprovalEventData, RuleHostAutoCorrectProposedEventData, RuleHostAutoCorrectAppliedEventData, RuntimeV2PromptActivationsInjectedEventData, RuleHostUnhealthyEventData } from '../types/event-types.js';
2
2
  import type { PluginLogger } from '../openclaw-sdk.js';
3
3
  export declare class EventLog {
4
4
  private readonly logsDir;
@@ -11,7 +11,6 @@ export declare class EventLog {
11
11
  private flushTimer?;
12
12
  private currentEventsFile;
13
13
  private currentDate;
14
- private readonly painScoreSums;
15
14
  constructor(stateDir: string, logger?: PluginLogger);
16
15
  private getEventsFile;
17
16
  private getTodayStr;
@@ -19,7 +18,6 @@ export declare class EventLog {
19
18
  private cleanupOldEventFiles;
20
19
  recordToolCall(sessionId: string | undefined, data: ToolCallEventData): void;
21
20
  recordPainSignal(sessionId: string | undefined, data: PainSignalEventData): void;
22
- recordRuleMatch(sessionId: string | undefined, data: RuleMatchEventData): void;
23
21
  recordRulePromotion(data: RulePromotionEventData): void;
24
22
  recordHookExecution(data: HookExecutionEventData, opts?: {
25
23
  flushImmediately?: boolean;
@@ -15,7 +15,8 @@ export class EventLog {
15
15
  flushTimer;
16
16
  currentEventsFile;
17
17
  currentDate;
18
- painScoreSums = new Map();
18
+ // painScoreSums map removed (PRI-451 Wave 1.5): it only fed the dead
19
+ // stats.pain.avgScore counter, which is also removed.
19
20
  constructor(stateDir, logger) {
20
21
  this.logsDir = path.join(stateDir, 'logs');
21
22
  if (!fs.existsSync(this.logsDir)) {
@@ -68,9 +69,8 @@ export class EventLog {
68
69
  recordPainSignal(sessionId, data) {
69
70
  this.record('pain_signal', 'detected', sessionId, data);
70
71
  }
71
- recordRuleMatch(sessionId, data) {
72
- this.record('rule_match', 'detected', sessionId, data);
73
- }
72
+ // recordRuleMatch removed (PRI-451 Wave 1): dead code. Its only effect was
73
+ // incrementing stats.pain.rulesMatched (also dead, removed in Wave 1.5).
74
74
  recordRulePromotion(data) {
75
75
  this.record('rule_promotion', 'promoted', undefined, data);
76
76
  }
@@ -293,16 +293,8 @@ export class EventLog {
293
293
  }
294
294
  else if (entry.type === 'pain_signal') {
295
295
  const data = entry.data;
296
- stats.pain.signalsDetected++;
297
- stats.pain.maxScore = Math.max(stats.pain.maxScore, data.score);
298
- if (data.source) {
299
- stats.pain.signalsBySource[data.source] = (stats.pain.signalsBySource[data.source] || 0) + 1;
300
- }
301
- const currentSum = this.painScoreSums.get(entry.date) ?? 0;
302
- this.painScoreSums.set(entry.date, currentSum + (data.score || 0));
303
- stats.pain.avgScore = stats.pain.signalsDetected > 0
304
- ? Math.round((currentSum + (data.score || 0)) / stats.pain.signalsDetected)
305
- : 0;
296
+ // stats.pain.* counters removed (PRI-451 Wave 1.5): no live reader.
297
+ // The user_empathy aggregation below (stats.empathy.*) is LIVE and stays.
306
298
  if (data.source === 'user_empathy') {
307
299
  if (data.deduped) {
308
300
  stats.empathy.dedupedCount++;
@@ -358,14 +350,11 @@ export class EventLog {
358
350
  stats.empathy.rollbackCount++;
359
351
  stats.empathy.rolledBackScore += data.originalScore || 0;
360
352
  }
361
- else if (entry.type === 'rule_match') {
362
- const data = entry.data;
363
- if (data.ruleId) {
364
- stats.pain.rulesMatched[data.ruleId] = (stats.pain.rulesMatched[data.ruleId] || 0) + 1;
365
- }
366
- }
353
+ // rule_match handler removed (PRI-451 Wave 1.5): recordRuleMatch is gone
354
+ // (Wave 1.1), so no rule_match events are emitted; stats.pain.rulesMatched
355
+ // was its only consumer and is also removed.
367
356
  else if (entry.type === 'rule_promotion') {
368
- stats.pain.candidatesPromoted++;
357
+ // stats.pain.candidatesPromoted removed (PRI-451 Wave 1.5): dead counter.
369
358
  stats.evolution.rulesPromoted++;
370
359
  }
371
360
  else if (entry.type === 'evolution_task') {
@@ -52,20 +52,12 @@ export declare class EvolutionReducerImpl implements EvolutionReducer {
52
52
  private readonly failureStreak;
53
53
  private lastPromotedAt;
54
54
  private isReplaying;
55
- /** Registered pain_detected callbacks (e.g., PainSignalBridge). */
56
- private readonly _painCallbacks;
57
55
  constructor(opts: {
58
56
  workspaceDir: string;
59
57
  stateDir?: string;
60
58
  });
61
59
  emit(event: EvolutionLoopEvent): void;
62
60
  emitSync(event: EvolutionLoopEvent): void;
63
- /**
64
- * Register a callback for 'pain_detected' events.
65
- * The callback is invoked synchronously within emitSync() after applyEvent completes.
66
- * HG-4: Callbacks are fire-and-forget from the emitSync perspective.
67
- */
68
- on(callback: (event: EvolutionLoopEvent) => void): void;
69
61
  getEventLog(): EvolutionLoopEvent[];
70
62
  getCandidatePrinciples(): Principle[];
71
63
  getProbationPrinciples(): Principle[];
@@ -38,8 +38,9 @@ export class EvolutionReducerImpl {
38
38
  failureStreak = new Map();
39
39
  lastPromotedAt = null;
40
40
  isReplaying = false;
41
- /** Registered pain_detected callbacks (e.g., PainSignalBridge). */
42
- _painCallbacks = [];
41
+ // _painCallbacks pub/sub removed (PRI-451 Wave 1): no code ever registered a
42
+ // callback via .on(). The pain_detected → PainSignalBridge bridge happens via
43
+ // emitPainDetectedEvent (hooks/pain.ts), not this pub/sub layer.
43
44
  constructor(opts) {
44
45
  this.workspaceDir = opts.workspaceDir;
45
46
  this.stateDir = opts.stateDir;
@@ -77,14 +78,9 @@ export class EvolutionReducerImpl {
77
78
  }
78
79
  // Performance: sweepExpiredProbation() moved to getProbationPrinciples() for lazy cleanup
79
80
  }
80
- /**
81
- * Register a callback for 'pain_detected' events.
82
- * The callback is invoked synchronously within emitSync() after applyEvent completes.
83
- * HG-4: Callbacks are fire-and-forget from the emitSync perspective.
84
- */
85
- on(callback) {
86
- this._painCallbacks.push(callback);
87
- }
81
+ // on(callback) pub/sub registration removed (PRI-451 Wave 1): dead code —
82
+ // no caller ever registered a callback. pain_detected events still flow via
83
+ // emitPainDetectedEvent → PainSignalBridge, unaffected.
88
84
  getEventLog() {
89
85
  return [...this.memoryEvents];
90
86
  }
@@ -522,15 +518,9 @@ export class EvolutionReducerImpl {
522
518
  if (!this.isReplaying) {
523
519
  this.onPainDetected(event.data, event.ts);
524
520
  }
525
- // PainSignalBridge subscriptions: invoke registered callbacks (fire-and-forget)
526
- for (const cb of this._painCallbacks) {
527
- try {
528
- cb(event);
529
- }
530
- catch {
531
- // Keep the evolution loop resilient — callback errors must not propagate
532
- }
533
- }
521
+ // _painCallbacks dispatch removed (PRI-451 Wave 1): no callback was ever
522
+ // registered via .on() (also removed). The pain_detected → PainSignalBridge
523
+ // bridge flows through emitPainDetectedEvent (hooks/pain.ts), not here.
534
524
  return;
535
525
  case 'candidate_created':
536
526
  this.onCandidateCreated(event.data, event.ts);