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,326 @@
1
+ import { PrinciplesConsoleModel } from '../models/PrinciplesConsoleModel.js';
2
+ import { writableRootProblem } from './examiner-executor.js';
3
+ import { deriveStudyRuleCodeFacts, gatherProductionSnapshot, isSuiteKey, suiteCaseDefs, } from './examiner-study-inputs.js';
4
+ const EXPERIMENT_MODES = ['isolated_principle', 'full_library_incremental'];
5
+ /** rc-1/rc-2: read a boolean out of an untrusted lab record without `as`. */
6
+ function readBoolean(record, key) {
7
+ const value = record[key];
8
+ return typeof value === 'boolean' ? value : null;
9
+ }
10
+ function readString(record, key) {
11
+ const value = record[key];
12
+ return typeof value === 'string' ? value : null;
13
+ }
14
+ function readRecord(record, key) {
15
+ const value = record[key];
16
+ return typeof value === 'object' && value !== null && !Array.isArray(value)
17
+ ? value
18
+ : null;
19
+ }
20
+ function summarize(principleId, checks) {
21
+ const blocking = checks.find((check) => check.status === 'BLOCKED') ?? null;
22
+ const warnings = checks.filter((check) => check.status === 'WARNING');
23
+ const status = blocking !== null
24
+ ? 'BLOCKED'
25
+ : warnings.length > 0 ? 'DEGRADED' : 'ELIGIBLE';
26
+ const reasonCode = blocking?.reasonCode ?? null;
27
+ const actionable = blocking ?? warnings[0] ?? null;
28
+ const summary = blocking !== null
29
+ ? `This principle cannot be evaluated yet (${blocking.reasonCode}).`
30
+ : warnings.length > 0
31
+ ? `The study can be created, but ${warnings.length} production condition(s) are degraded.`
32
+ : 'The study can be created.';
33
+ return {
34
+ status,
35
+ principleId,
36
+ summary,
37
+ reasonCode,
38
+ blockingReasonCode: reasonCode,
39
+ nextAction: status === 'ELIGIBLE' ? null : (actionable?.nextAction ?? null),
40
+ checks,
41
+ };
42
+ }
43
+ /**
44
+ * An operator payload must never carry a server-side absolute path: it says
45
+ * nothing useful to the Owner, leaks the machine layout, and differs per
46
+ * environment (CI vs local workstation). The rule is enforced at the response
47
+ * boundary so every present and future field is covered — not only the fields
48
+ * that happen to be known today.
49
+ */
50
+ const ABSOLUTE_PATH = /(?:[A-Za-z]:[\\/]|\\\\[^\s\\/]+[\\/]|\/(?:home|Users|root|tmp|var|private|opt|mnt|srv|workspace|github|\.pd-tmp|pd-tmp)\/)[^\s'",;:)\]]*/g;
51
+ function redactAbsolutePaths(value) {
52
+ return value.replace(ABSOLUTE_PATH, '<path>');
53
+ }
54
+ /**
55
+ * Project a verdict into its operator-facing shape. Every HTTP response must
56
+ * use this; the raw verdict stays internal because it also carries the
57
+ * creation inputs (`snapshot` / `ruleCodeFacts`).
58
+ */
59
+ export function toOperatorVerdict(result) {
60
+ const { verdict } = result;
61
+ return {
62
+ ...verdict,
63
+ summary: redactAbsolutePaths(verdict.summary),
64
+ nextAction: verdict.nextAction === null ? null : redactAbsolutePaths(verdict.nextAction),
65
+ checks: verdict.checks.map((check) => ({
66
+ ...check,
67
+ detail: check.detail === null ? null : redactAbsolutePaths(check.detail),
68
+ evidence: check.evidence.map(redactAbsolutePaths),
69
+ nextAction: check.nextAction === null ? null : redactAbsolutePaths(check.nextAction),
70
+ })),
71
+ };
72
+ }
73
+ /** Compile one suite case set with a throwaway id. Returns null when usable. */
74
+ async function probeSuite(labRoot, suiteKey) {
75
+ if (!isSuiteKey(suiteKey))
76
+ return `unknown suite key '${suiteKey}'`;
77
+ try {
78
+ const cases = await suiteCaseDefs(labRoot, 'ELIGIBILITY-PROBE', suiteKey);
79
+ if (!Array.isArray(cases) || cases.length === 0)
80
+ return 'the suite compiled to zero cases';
81
+ return null;
82
+ }
83
+ catch (error) {
84
+ return error instanceof Error ? error.message : String(error);
85
+ }
86
+ }
87
+ export async function evaluateStudyEligibility(args) {
88
+ const checks = [];
89
+ // 1. Experiment mode — the two modes the creation path accepts.
90
+ const mode = EXPERIMENT_MODES.find((candidate) => candidate === args.experimentMode) ?? null;
91
+ checks.push(mode === null
92
+ ? {
93
+ id: 'experiment_mode',
94
+ status: 'BLOCKED',
95
+ reasonCode: 'experiment_mode_unsupported',
96
+ detail: `unknown experiment mode '${args.experimentMode}'`,
97
+ evidence: [...EXPERIMENT_MODES],
98
+ nextAction: 'Choose isolated_principle or full_library_incremental.',
99
+ }
100
+ : {
101
+ id: 'experiment_mode',
102
+ status: 'PASS',
103
+ reasonCode: 'experiment_mode_supported',
104
+ detail: null,
105
+ evidence: [mode],
106
+ nextAction: null,
107
+ });
108
+ // 2. Target presence in the workspace ledger.
109
+ const model = new PrinciplesConsoleModel(args.workspaceDir);
110
+ const list = await model.listPrinciples();
111
+ const ledgerPrinciples = (list.principles ?? []).map((p) => ({
112
+ id: p.id,
113
+ version: 'ledger',
114
+ text: p.text,
115
+ status: p.status,
116
+ ruleCount: p.ruleCount ?? 0,
117
+ }));
118
+ const target = ledgerPrinciples.find((p) => p.id === args.principleId) ?? null;
119
+ checks.push(target === null
120
+ ? {
121
+ id: 'principle_exists',
122
+ status: 'BLOCKED',
123
+ reasonCode: 'principle_not_found',
124
+ detail: `principle '${args.principleId}' is not in the workspace ledger`,
125
+ evidence: [],
126
+ nextAction: 'Return to Principle Governance and confirm the principle id.',
127
+ }
128
+ : {
129
+ id: 'principle_exists',
130
+ status: 'PASS',
131
+ reasonCode: 'principle_found',
132
+ detail: null,
133
+ evidence: [target.id, `status:${target.status}`],
134
+ nextAction: null,
135
+ });
136
+ if (target === null) {
137
+ return { verdict: summarize(args.principleId, checks), inputs: null };
138
+ }
139
+ // 3. Status eligibility — the lab's own rule (never re-implemented here).
140
+ const heps = args.labModules.study.buildHostEffectivePrincipleSet({
141
+ principles: ledgerPrinciples,
142
+ targetPrincipleId: args.principleId,
143
+ host: 'offline-stub',
144
+ });
145
+ const hepsTarget = readRecord(heps, 'target');
146
+ const qualifies = hepsTarget === null ? null : readBoolean(hepsTarget, 'qualifies');
147
+ const exclusionReason = hepsTarget === null ? null : readString(hepsTarget, 'exclusionReason');
148
+ checks.push(qualifies === true
149
+ ? {
150
+ id: 'principle_status',
151
+ status: 'PASS',
152
+ reasonCode: 'principle_status_eligible',
153
+ detail: null,
154
+ evidence: [`status:${target.status}`],
155
+ nextAction: null,
156
+ }
157
+ : {
158
+ id: 'principle_status',
159
+ status: 'BLOCKED',
160
+ reasonCode: 'principle_not_active',
161
+ detail: exclusionReason === null
162
+ ? 'the lab could not confirm that the target principle is eligible'
163
+ : `target eligibility refused: ${exclusionReason}`,
164
+ evidence: [`status:${target.status}`],
165
+ nextAction: 'Only active principles can be studied — complete the governance decision first.',
166
+ });
167
+ // 4. Production snapshot — read-only freeze facts (degraded is observable,
168
+ // never silently treated as "zero activations").
169
+ let snapshot = null;
170
+ try {
171
+ snapshot = await gatherProductionSnapshot(args.workspaceDir, args.principleId, 2000);
172
+ }
173
+ catch (error) {
174
+ checks.push({
175
+ id: 'production_snapshot',
176
+ status: 'BLOCKED',
177
+ reasonCode: 'snapshot_unreadable',
178
+ detail: error instanceof Error ? error.message : String(error),
179
+ evidence: [],
180
+ nextAction: 'Repair the workspace runtime state, then retry the pre-check.',
181
+ });
182
+ }
183
+ if (snapshot !== null) {
184
+ const degraded = snapshot.runtimeActivation.status !== 'ok';
185
+ checks.push({
186
+ id: 'production_snapshot',
187
+ status: 'PASS',
188
+ reasonCode: 'snapshot_readable',
189
+ detail: null,
190
+ evidence: [`ledger_active:${snapshot.ledgerActivePrincipleIds.length}`],
191
+ nextAction: null,
192
+ });
193
+ // One check per id, and never a PASS over unknown evidence: a degraded
194
+ // activation read model means the baseline cannot be confirmed.
195
+ const activationWarning = degraded
196
+ ? {
197
+ id: 'activation_evidence',
198
+ status: 'WARNING',
199
+ reasonCode: 'activation_data_degraded',
200
+ detail: snapshot.runtimeActivation.reason ?? 'the runtime activation read model reported degraded',
201
+ evidence: ['ACTIVATION_DATA_DEGRADED'],
202
+ nextAction: snapshot.runtimeActivation.nextAction ?? 'Inspect the workspace runtime state.',
203
+ }
204
+ : snapshot.targetPrinciple.runtimePromptActive === false
205
+ ? {
206
+ id: 'activation_evidence',
207
+ status: 'WARNING',
208
+ reasonCode: 'runtime_prompt_inactive',
209
+ detail: 'the target principle is ledger-active but has no active runtime prompt activation row',
210
+ evidence: [args.principleId],
211
+ nextAction: 'Activate the principle for the runtime, or treat the offline result as a baseline-only comparison.',
212
+ }
213
+ : null;
214
+ checks.push(activationWarning ?? {
215
+ id: 'activation_evidence',
216
+ status: 'PASS',
217
+ reasonCode: 'activation_evidence_present',
218
+ detail: null,
219
+ evidence: [`runtime_prompt_active:${snapshot.targetPrinciple.runtimePromptActive !== false}`],
220
+ nextAction: null,
221
+ });
222
+ }
223
+ // 5. RuleCode identifiability — the lab's policy over runtime-derived facts.
224
+ let ruleCodeFacts = null;
225
+ if (snapshot !== null) {
226
+ ruleCodeFacts = deriveStudyRuleCodeFacts(snapshot);
227
+ if (mode === null) {
228
+ // Cannot evaluate the policy without a mode; the mode check already blocks.
229
+ }
230
+ else {
231
+ const policy = args.labModules.study.buildRuleCodePolicy({
232
+ mode,
233
+ ruleCodes: ruleCodeFacts.ruleCodes,
234
+ targetPrincipleId: args.principleId,
235
+ principleRuleCodeIndependence: ruleCodeFacts.principleRuleCodeIndependence,
236
+ targetRuleCodeCount: ruleCodeFacts.targetRuleCodeCount,
237
+ });
238
+ const executable = readBoolean(policy, 'executable');
239
+ const identifiability = readString(policy, 'identifiability');
240
+ const couplingReason = readString(policy, 'couplingReason');
241
+ checks.push(executable === true
242
+ ? {
243
+ id: 'rulecode_identifiability',
244
+ status: 'PASS',
245
+ reasonCode: 'intervention_identifiable',
246
+ detail: ruleCodeFacts.evidenceNote,
247
+ evidence: [`target_rulecodes:${ruleCodeFacts.targetRuleCodeCount}`],
248
+ nextAction: null,
249
+ }
250
+ : {
251
+ id: 'rulecode_identifiability',
252
+ status: 'BLOCKED',
253
+ reasonCode: 'intervention_not_identifiable',
254
+ detail: couplingReason ?? `the RuleCode policy is not executable (identifiability: ${identifiability ?? 'unknown'})`,
255
+ evidence: [`target_rulecodes:${ruleCodeFacts.targetRuleCodeCount}`],
256
+ nextAction: 'Resolve the target principle\u2019s RuleCode baseline (or its independence evidence) before evaluating it.',
257
+ });
258
+ }
259
+ }
260
+ // 6. Experiment vs production configuration — a stated difference, never a
261
+ // silent one: it limits what an offline result can be compared against.
262
+ if (snapshot !== null) {
263
+ const { markers } = snapshot.experimentVsProduction;
264
+ checks.push(markers.length > 0
265
+ ? {
266
+ id: 'experiment_configuration',
267
+ status: 'WARNING',
268
+ reasonCode: 'experiment_config_differs',
269
+ detail: 'the experiment configuration differs from the production injection path',
270
+ evidence: markers,
271
+ nextAction: null,
272
+ }
273
+ : {
274
+ id: 'experiment_configuration',
275
+ status: 'PASS',
276
+ reasonCode: 'experiment_configuration_matches',
277
+ detail: null,
278
+ evidence: [],
279
+ nextAction: null,
280
+ });
281
+ }
282
+ // 7. Research suite availability — compile the selected suite once.
283
+ if (args.suiteKey !== undefined) {
284
+ const suiteProblem = await probeSuite(args.labRoot, args.suiteKey);
285
+ checks.push(suiteProblem === null
286
+ ? {
287
+ id: 'suite_available',
288
+ status: 'PASS',
289
+ reasonCode: 'suite_available',
290
+ detail: null,
291
+ evidence: [args.suiteKey],
292
+ nextAction: null,
293
+ }
294
+ : {
295
+ id: 'suite_available',
296
+ status: 'BLOCKED',
297
+ reasonCode: 'suite_unavailable',
298
+ detail: suiteProblem,
299
+ evidence: [args.suiteKey],
300
+ nextAction: 'Choose another research suite from the server-fixed catalog.',
301
+ });
302
+ }
303
+ // 8. Writable study root — creation would refuse here with 409/422.
304
+ const rootProblem = writableRootProblem(args.roots);
305
+ checks.push(rootProblem === null
306
+ ? {
307
+ id: 'study_root_writable',
308
+ status: 'PASS',
309
+ reasonCode: 'study_root_writable',
310
+ detail: null,
311
+ evidence: ['root:isolated'],
312
+ nextAction: null,
313
+ }
314
+ : {
315
+ id: 'study_root_writable',
316
+ status: 'BLOCKED',
317
+ reasonCode: 'study_root_not_writable',
318
+ detail: rootProblem,
319
+ evidence: ['root:not_isolated'],
320
+ nextAction: 'Fix the workspace examiner root isolation before creating a study.',
321
+ });
322
+ return {
323
+ verdict: summarize(args.principleId, checks),
324
+ inputs: snapshot !== null && ruleCodeFacts !== null ? { snapshot, ruleCodeFacts } : null,
325
+ };
326
+ }
@@ -5,7 +5,8 @@ import { sendSuccess, sendError, sendNotFound, sendJson } from '../utils/respons
5
5
  import { PrinciplesConsoleModel } from '../models/PrinciplesConsoleModel.js';
6
6
  import { ExaminerEvidenceModel } from '../models/ExaminerEvidenceModel.js';
7
7
  import { loadLabModules, loadHostCapability, preflightCheck, offlineStudyPass, reportMaterialize, listStudyNames, resolveStudyAccess, resolveStudyRoots, studyReportPayload, materializeConsoleStudy, verifyConsoleOwnership, writableRootProblem, isJsonObject, ExaminerPreflightBlockedError, } from './examiner-executor.js';
8
- import { listSuiteCatalog, isSuiteKey, gatherProductionSnapshot, deriveStudyRuleCodeFacts, readProductionSnapshot, } from './examiner-study-inputs.js';
8
+ import { listSuiteCatalog, isSuiteKey, readProductionSnapshot, } from './examiner-study-inputs.js';
9
+ import { evaluateStudyEligibility, toOperatorVerdict } from './examiner-eligibility.js';
9
10
  import { appendConsoleRunEventLocked, readConsoleRuns, currentConsoleRun, recoverUnfinishedConsoleRuns, acceptConsoleRun, hostDryRunPass, f2AuthorizationGate, CONSOLE_RUN_SCHEMA, CONSOLE_RUN_MODES, ConsoleRunInProgressError, ConsoleLedgerUnreadableError, studyStatusPayload, assertOfflineAdmissionAllowed, } from './examiner-runs.js';
10
11
  /* eslint-disable @typescript-eslint/max-params -- node:http handler signature (req, res, workspaceDir, subPath) matches every other route */
11
12
  const LAB_ENTRY = path.join('lib', 'examiner-study.mjs');
@@ -196,6 +197,39 @@ export async function handleExaminerRoute(req, res, workspaceDir, subPath) {
196
197
  sendSuccess(res, { principles, note: 'study inputs are read from the workspace ledger (read-only); eligibility filtering happens inside the Examiner contract' });
197
198
  return;
198
199
  }
200
+ // ── Phase C: Study eligibility PRE-CHECK (read-only; creates nothing).
201
+ // Answers "would a study for this principle be creatable right now, and with
202
+ // which caveats" using the SAME functions POST /studies re-runs before it
203
+ // materializes anything. /principles/<id>/eligibility
204
+ const eligibilityPrincipleId = subPath.startsWith(evidencePrefix) && subPath.endsWith('/eligibility')
205
+ ? subPath.slice(evidencePrefix.length, subPath.length - '/eligibility'.length)
206
+ : null;
207
+ if (eligibilityPrincipleId !== null && PRINCIPLE_ID_PATTERN.test(eligibilityPrincipleId) && method === 'GET') {
208
+ const requestUrl = new URL(req.url ?? '', 'http://localhost');
209
+ const requestedEligibilityMode = requestUrl.searchParams.get('mode');
210
+ const experimentMode = requestedEligibilityMode === 'isolated_principle' ? 'isolated_principle' : 'full_library_incremental';
211
+ const requestedSuite = requestUrl.searchParams.get('suite');
212
+ // Mirror the creation fallback: an unrecognized/absent suite becomes the
213
+ // v0.9 default, so the pre-check never disagrees with what creation uses.
214
+ const suiteKey = requestedSuite !== null && isSuiteKey(requestedSuite) ? requestedSuite : 'didactic-pair';
215
+ const eligibility = await evaluateStudyEligibility({
216
+ workspaceDir,
217
+ labRoot,
218
+ labModules,
219
+ roots,
220
+ principleId: eligibilityPrincipleId,
221
+ experimentMode,
222
+ suiteKey,
223
+ });
224
+ sendSuccess(res, {
225
+ ...toOperatorVerdict(eligibility),
226
+ experimentMode,
227
+ suiteKey,
228
+ productionSnapshotMarkers: eligibility.inputs?.snapshot.experimentVsProduction.markers ?? [],
229
+ note: 'read-only pre-check: nothing was created; the same checks run again before any study is materialized',
230
+ });
231
+ return;
232
+ }
199
233
  // ── v0.10.1 §9: challenge-suite catalog (server-fixed keys, read-only).
200
234
  if (subPath === '/suites' && method === 'GET') {
201
235
  const suites = await listSuiteCatalog(labRoot);
@@ -249,14 +283,38 @@ export async function handleExaminerRoute(req, res, workspaceDir, subPath) {
249
283
  return;
250
284
  }
251
285
  const isolatedMode = requestedMode === 'isolated_principle';
286
+ const experimentMode = isolatedMode ? 'isolated_principle' : 'full_library_incremental';
252
287
  try {
288
+ // Phase C2: creation runs the SAME eligibility implementation the
289
+ // pre-check endpoint exposes, BEFORE any file is written. A study the
290
+ // pre-check calls BLOCKED is never created; a created study was ELIGIBLE
291
+ // or DEGRADED under exactly those rules.
292
+ const eligibility = await evaluateStudyEligibility({
293
+ workspaceDir,
294
+ labRoot,
295
+ labModules,
296
+ roots,
297
+ principleId: requestedTarget,
298
+ experimentMode,
299
+ suiteKey,
300
+ });
301
+ if (eligibility.verdict.status === 'BLOCKED' || eligibility.inputs === null) {
302
+ const operatorVerdict = toOperatorVerdict(eligibility);
303
+ sendError(res, 422, 'study_creation_refused', 'the eligibility pre-check refused creation (no file was written)', {
304
+ // `error` stays the stable family code; `reason` carries the
305
+ // specific refusal so a client never has to parse prose.
306
+ reason: operatorVerdict.reasonCode,
307
+ nextAction: operatorVerdict.nextAction,
308
+ blockingReasonCode: operatorVerdict.blockingReasonCode,
309
+ eligibility: operatorVerdict,
310
+ });
311
+ return;
312
+ }
253
313
  // v0.10.1 host-backed inputs (SPEC §4/§6/§7): freeze the production
254
- // snapshot, derive RuleCode facts from RUNTIME activation truth,
255
- // carry the real pain lineage and compile the selected suite's cases.
256
- // The study handle is minted inside materializeConsoleStudy, so the
257
- // suite cases are compiled with per-study ids there via a second pass
258
- // (suiteCaseDefs is deterministic; the ids are re-minted below).
259
- const snapshot = await gatherProductionSnapshot(workspaceDir, requestedTarget, 2000);
314
+ // snapshot and the RuleCode facts the pre-check already derived from
315
+ // RUNTIME activation truth, carry the real pain lineage and compile the
316
+ // selected suite's cases.
317
+ const { snapshot, ruleCodeFacts } = eligibility.inputs;
260
318
  const detailOutput = await model.getPrincipleDetail(requestedTarget);
261
319
  const painRefs = detailOutput?.principle.derivedFromPainIds ?? [];
262
320
  const created = await materializeConsoleStudy(labModules, labRoot, roots, {
@@ -267,7 +325,7 @@ export async function handleExaminerRoute(req, res, workspaceDir, subPath) {
267
325
  suiteKey,
268
326
  hostBacked: {
269
327
  productionSnapshot: { ...snapshot },
270
- ruleCodeFacts: deriveStudyRuleCodeFacts(snapshot),
328
+ ruleCodeFacts,
271
329
  painRefs,
272
330
  },
273
331
  });
@@ -578,6 +578,10 @@
578
578
  .table {
579
579
  display: table;
580
580
  }
581
+ .size-3 {
582
+ width: calc(var(--spacing) * 3);
583
+ height: calc(var(--spacing) * 3);
584
+ }
581
585
  .size-3\.5 {
582
586
  width: calc(var(--spacing) * 3.5);
583
587
  height: calc(var(--spacing) * 3.5);
@@ -1392,6 +1396,12 @@
1392
1396
  border-color: color-mix(in oklab, var(--color-destructive) 50%, transparent);
1393
1397
  }
1394
1398
  }
1399
+ .border-emerald-500\/40 {
1400
+ border-color: color-mix(in srgb, oklch(69.6% 0.17 162.48) 40%, transparent);
1401
+ @supports (color: color-mix(in lab, red, red)) {
1402
+ border-color: color-mix(in oklab, var(--color-emerald-500) 40%, transparent);
1403
+ }
1404
+ }
1395
1405
  .border-gov {
1396
1406
  border-color: var(--color-gov);
1397
1407
  }
@@ -1557,6 +1567,12 @@
1557
1567
  .bg-amber-500 {
1558
1568
  background-color: var(--color-amber-500);
1559
1569
  }
1570
+ .bg-amber-500\/5 {
1571
+ background-color: color-mix(in srgb, oklch(76.9% 0.188 70.08) 5%, transparent);
1572
+ @supports (color: color-mix(in lab, red, red)) {
1573
+ background-color: color-mix(in oklab, var(--color-amber-500) 5%, transparent);
1574
+ }
1575
+ }
1560
1576
  .bg-amber-500\/10 {
1561
1577
  background-color: color-mix(in srgb, oklch(76.9% 0.188 70.08) 10%, transparent);
1562
1578
  @supports (color: color-mix(in lab, red, red)) {
@@ -1620,6 +1636,12 @@
1620
1636
  .bg-destructive {
1621
1637
  background-color: var(--color-destructive);
1622
1638
  }
1639
+ .bg-destructive\/5 {
1640
+ background-color: color-mix(in srgb, #8b3a3a 5%, transparent);
1641
+ @supports (color: color-mix(in lab, red, red)) {
1642
+ background-color: color-mix(in oklab, var(--color-destructive) 5%, transparent);
1643
+ }
1644
+ }
1623
1645
  .bg-destructive\/10 {
1624
1646
  background-color: color-mix(in srgb, #8b3a3a 10%, transparent);
1625
1647
  @supports (color: color-mix(in lab, red, red)) {
@@ -1632,6 +1654,12 @@
1632
1654
  background-color: color-mix(in oklab, var(--color-destructive) 15%, transparent);
1633
1655
  }
1634
1656
  }
1657
+ .bg-emerald-500\/10 {
1658
+ background-color: color-mix(in srgb, oklch(69.6% 0.17 162.48) 10%, transparent);
1659
+ @supports (color: color-mix(in lab, red, red)) {
1660
+ background-color: color-mix(in oklab, var(--color-emerald-500) 10%, transparent);
1661
+ }
1662
+ }
1635
1663
  .bg-emerald-500\/15 {
1636
1664
  background-color: color-mix(in srgb, oklch(69.6% 0.17 162.48) 15%, transparent);
1637
1665
  @supports (color: color-mix(in lab, red, red)) {
@@ -1713,6 +1741,12 @@
1713
1741
  background-color: color-mix(in oklab, var(--color-muted) 30%, transparent);
1714
1742
  }
1715
1743
  }
1744
+ .bg-muted\/40 {
1745
+ background-color: color-mix(in srgb, #f2ede3 40%, transparent);
1746
+ @supports (color: color-mix(in lab, red, red)) {
1747
+ background-color: color-mix(in oklab, var(--color-muted) 40%, transparent);
1748
+ }
1749
+ }
1716
1750
  .bg-muted\/50 {
1717
1751
  background-color: color-mix(in srgb, #f2ede3 50%, transparent);
1718
1752
  @supports (color: color-mix(in lab, red, red)) {
@@ -2070,6 +2104,9 @@
2070
2104
  .text-right {
2071
2105
  text-align: right;
2072
2106
  }
2107
+ .align-text-bottom {
2108
+ vertical-align: text-bottom;
2109
+ }
2073
2110
  .font-mono {
2074
2111
  font-family: var(--font-mono);
2075
2112
  }
@@ -2409,6 +2446,9 @@
2409
2446
  .opacity-72 {
2410
2447
  opacity: 72%;
2411
2448
  }
2449
+ .opacity-80 {
2450
+ opacity: 80%;
2451
+ }
2412
2452
  .opacity-100 {
2413
2453
  opacity: 100%;
2414
2454
  }