create-principles-disciple 1.149.0 → 1.150.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (229) hide show
  1. package/_release/product-identity.json +1 -1
  2. package/codex-adapter/dist/pd-hook.d.ts +22 -1
  3. package/codex-adapter/dist/pd-hook.js +81 -7
  4. package/codex-adapter/dist/worker/workspace-worker.d.ts +15 -0
  5. package/codex-adapter/dist/worker/workspace-worker.js +7 -36
  6. package/codex-adapter/package.json +1 -1
  7. package/console/dist/server/index.js +14 -0
  8. package/console/dist/server/models/ActivationsConsoleModel.d.ts +3 -17
  9. package/console/dist/server/models/ActivationsConsoleModel.js +5 -44
  10. package/console/dist/server/routes/diagnostician.d.ts +50 -0
  11. package/console/dist/server/routes/diagnostician.js +388 -0
  12. package/console/dist/web/assets/app.js +24 -24
  13. package/core/dist/host/host-installer.d.ts +7 -0
  14. package/core/dist/host/host-installer.d.ts.map +1 -1
  15. package/core/dist/host/host-installer.js.map +1 -1
  16. package/core/dist/runtime/activation/index.d.ts +3 -3
  17. package/core/dist/runtime/activation/index.d.ts.map +1 -1
  18. package/core/dist/runtime/activation/index.js +1 -1
  19. package/core/dist/runtime/activation/index.js.map +1 -1
  20. package/core/dist/runtime/activation/promotion-readiness-evaluator.d.ts +25 -1
  21. package/core/dist/runtime/activation/promotion-readiness-evaluator.d.ts.map +1 -1
  22. package/core/dist/runtime/activation/promotion-readiness-evaluator.js +58 -1
  23. package/core/dist/runtime/activation/promotion-readiness-evaluator.js.map +1 -1
  24. package/core/dist/runtime/activation/promotion-readiness-reader.d.ts.map +1 -1
  25. package/core/dist/runtime/activation/promotion-readiness-reader.js +4 -2
  26. package/core/dist/runtime/activation/promotion-readiness-reader.js.map +1 -1
  27. package/core/dist/runtime/activation/rulecode-owner-decision-service.d.ts +28 -0
  28. package/core/dist/runtime/activation/rulecode-owner-decision-service.d.ts.map +1 -1
  29. package/core/dist/runtime/activation/rulecode-owner-decision-service.js +2 -0
  30. package/core/dist/runtime/activation/rulecode-owner-decision-service.js.map +1 -1
  31. package/core/dist/runtime/admission-gate.d.ts +8 -1
  32. package/core/dist/runtime/admission-gate.d.ts.map +1 -1
  33. package/core/dist/runtime/admission-gate.js +2 -1
  34. package/core/dist/runtime/admission-gate.js.map +1 -1
  35. package/core/dist/runtime/config/pd-config-defaults.d.ts.map +1 -1
  36. package/core/dist/runtime/config/pd-config-defaults.js +20 -2
  37. package/core/dist/runtime/config/pd-config-defaults.js.map +1 -1
  38. package/core/dist/runtime/config/pd-config-validate.d.ts.map +1 -1
  39. package/core/dist/runtime/config/pd-config-validate.js +18 -0
  40. package/core/dist/runtime/config/pd-config-validate.js.map +1 -1
  41. package/core/dist/runtime/context-payload.d.ts +48 -3
  42. package/core/dist/runtime/context-payload.d.ts.map +1 -1
  43. package/core/dist/runtime/context-payload.js +38 -0
  44. package/core/dist/runtime/context-payload.js.map +1 -1
  45. package/core/dist/runtime/diagnostician/rootcause-prompt-builder.d.ts +8 -2
  46. package/core/dist/runtime/diagnostician/rootcause-prompt-builder.d.ts.map +1 -1
  47. package/core/dist/runtime/diagnostician/rootcause-prompt-builder.js +28 -2
  48. package/core/dist/runtime/diagnostician/rootcause-prompt-builder.js.map +1 -1
  49. package/core/dist/runtime/diagnostician-candidate.d.ts +24 -0
  50. package/core/dist/runtime/diagnostician-candidate.d.ts.map +1 -0
  51. package/core/dist/runtime/diagnostician-candidate.js +55 -0
  52. package/core/dist/runtime/diagnostician-candidate.js.map +1 -0
  53. package/core/dist/runtime/evidence-guards.d.ts +10 -4
  54. package/core/dist/runtime/evidence-guards.d.ts.map +1 -1
  55. package/core/dist/runtime/evidence-guards.js +12 -5
  56. package/core/dist/runtime/evidence-guards.js.map +1 -1
  57. package/core/dist/runtime/evolution/evolution-types.d.ts +4 -4
  58. package/core/dist/runtime/evolution/evolution-types.d.ts.map +1 -1
  59. package/core/dist/runtime/evolution/evolution-types.js +1 -0
  60. package/core/dist/runtime/evolution/evolution-types.js.map +1 -1
  61. package/core/dist/runtime/feature-flags/feature-flag-contract.d.ts.map +1 -1
  62. package/core/dist/runtime/feature-flags/feature-flag-contract.js +14 -0
  63. package/core/dist/runtime/feature-flags/feature-flag-contract.js.map +1 -1
  64. package/core/dist/runtime/feature-flags/feature-flag-lifecycle.d.ts.map +1 -1
  65. package/core/dist/runtime/feature-flags/feature-flag-lifecycle.js +16 -0
  66. package/core/dist/runtime/feature-flags/feature-flag-lifecycle.js.map +1 -1
  67. package/core/dist/runtime/index.d.ts +5 -2
  68. package/core/dist/runtime/index.d.ts.map +1 -1
  69. package/core/dist/runtime/index.js +6 -1
  70. package/core/dist/runtime/index.js.map +1 -1
  71. package/core/dist/runtime/internalization/index.d.ts +1 -0
  72. package/core/dist/runtime/internalization/index.d.ts.map +1 -1
  73. package/core/dist/runtime/internalization/index.js +2 -0
  74. package/core/dist/runtime/internalization/index.js.map +1 -1
  75. package/core/dist/runtime/internalization/rule-host-contracts.d.ts +10 -0
  76. package/core/dist/runtime/internalization/rule-host-contracts.d.ts.map +1 -1
  77. package/core/dist/runtime/internalization/rule-host-evaluator.js +10 -10
  78. package/core/dist/runtime/internalization/rule-host-evaluator.js.map +1 -1
  79. package/core/dist/runtime/internalization/rule-host-input-builder.d.ts +7 -6
  80. package/core/dist/runtime/internalization/rule-host-input-builder.d.ts.map +1 -1
  81. package/core/dist/runtime/internalization/rule-host-input-builder.js +6 -2
  82. package/core/dist/runtime/internalization/rule-host-input-builder.js.map +1 -1
  83. package/core/dist/runtime/internalization/rule-host-result-normalizer.d.ts +33 -0
  84. package/core/dist/runtime/internalization/rule-host-result-normalizer.d.ts.map +1 -0
  85. package/core/dist/runtime/internalization/rule-host-result-normalizer.js +61 -0
  86. package/core/dist/runtime/internalization/rule-host-result-normalizer.js.map +1 -0
  87. package/core/dist/runtime/internalization/rule-host-validator.d.ts.map +1 -1
  88. package/core/dist/runtime/internalization/rule-host-validator.js +17 -0
  89. package/core/dist/runtime/internalization/rule-host-validator.js.map +1 -1
  90. package/core/dist/runtime/pain-ingress-payload.d.ts +27 -2
  91. package/core/dist/runtime/pain-ingress-payload.d.ts.map +1 -1
  92. package/core/dist/runtime/pain-ingress-payload.js +45 -3
  93. package/core/dist/runtime/pain-ingress-payload.js.map +1 -1
  94. package/core/dist/runtime/pain-ingress.d.ts +4 -2
  95. package/core/dist/runtime/pain-ingress.d.ts.map +1 -1
  96. package/core/dist/runtime/pain-ingress.js +23 -3
  97. package/core/dist/runtime/pain-ingress.js.map +1 -1
  98. package/core/dist/runtime/pain-severity.d.ts +14 -0
  99. package/core/dist/runtime/pain-severity.d.ts.map +1 -0
  100. package/core/dist/runtime/pain-severity.js +14 -0
  101. package/core/dist/runtime/pain-severity.js.map +1 -0
  102. package/core/dist/runtime/pain-signal-bridge.d.ts +17 -3
  103. package/core/dist/runtime/pain-signal-bridge.d.ts.map +1 -1
  104. package/core/dist/runtime/pain-signal-bridge.js +6 -0
  105. package/core/dist/runtime/pain-signal-bridge.js.map +1 -1
  106. package/core/dist/runtime/pain-signal-observability.d.ts.map +1 -1
  107. package/core/dist/runtime/pain-signal-observability.js +3 -2
  108. package/core/dist/runtime/pain-signal-observability.js.map +1 -1
  109. package/core/dist/runtime/pain-submit-capability.d.ts +164 -0
  110. package/core/dist/runtime/pain-submit-capability.d.ts.map +1 -0
  111. package/core/dist/runtime/pain-submit-capability.js +442 -0
  112. package/core/dist/runtime/pain-submit-capability.js.map +1 -0
  113. package/core/dist/runtime/pain-to-principle-service.d.ts +4 -0
  114. package/core/dist/runtime/pain-to-principle-service.d.ts.map +1 -1
  115. package/core/dist/runtime/pain-to-principle-service.js +2 -0
  116. package/core/dist/runtime/pain-to-principle-service.js.map +1 -1
  117. package/core/dist/runtime/stalled-diagnostician-task-read-model.d.ts +56 -10
  118. package/core/dist/runtime/stalled-diagnostician-task-read-model.d.ts.map +1 -1
  119. package/core/dist/runtime/stalled-diagnostician-task-read-model.js +80 -4
  120. package/core/dist/runtime/stalled-diagnostician-task-read-model.js.map +1 -1
  121. package/core/dist/runtime/store/context/sqlite-context-assembler.d.ts.map +1 -1
  122. package/core/dist/runtime/store/context/sqlite-context-assembler.js +11 -0
  123. package/core/dist/runtime/store/context/sqlite-context-assembler.js.map +1 -1
  124. package/core/dist/runtime/store/run/memory-run-store.d.ts +10 -0
  125. package/core/dist/runtime/store/run/memory-run-store.d.ts.map +1 -1
  126. package/core/dist/runtime/store/run/memory-run-store.js +21 -0
  127. package/core/dist/runtime/store/run/memory-run-store.js.map +1 -1
  128. package/core/dist/runtime/store/run/run-store.d.ts +12 -0
  129. package/core/dist/runtime/store/run/run-store.d.ts.map +1 -1
  130. package/core/dist/runtime/store/run/sqlite-run-store.d.ts +1 -0
  131. package/core/dist/runtime/store/run/sqlite-run-store.d.ts.map +1 -1
  132. package/core/dist/runtime/store/run/sqlite-run-store.js +14 -0
  133. package/core/dist/runtime/store/run/sqlite-run-store.js.map +1 -1
  134. package/core/dist/runtime/task-status.d.ts +9 -0
  135. package/core/dist/runtime/task-status.d.ts.map +1 -1
  136. package/core/dist/runtime/task-status.js +7 -1
  137. package/core/dist/runtime/task-status.js.map +1 -1
  138. package/core/dist/runtime/types/evidence-chain-contract.d.ts +18 -0
  139. package/core/dist/runtime/types/evidence-chain-contract.d.ts.map +1 -1
  140. package/core/dist/runtime/types/evidence-chain-contract.js +37 -7
  141. package/core/dist/runtime/types/evidence-chain-contract.js.map +1 -1
  142. package/core/package.json +5 -1
  143. package/dist/install-summary.d.ts +7 -0
  144. package/dist/install-summary.d.ts.map +1 -1
  145. package/dist/install-summary.js +4 -0
  146. package/dist/install-summary.js.map +1 -1
  147. package/dist/installer.d.ts +34 -1
  148. package/dist/installer.d.ts.map +1 -1
  149. package/dist/installer.js +84 -4
  150. package/dist/installer.js.map +1 -1
  151. package/dist/installers/codex-host-installer.d.ts +88 -1
  152. package/dist/installers/codex-host-installer.d.ts.map +1 -1
  153. package/dist/installers/codex-host-installer.js +350 -11
  154. package/dist/installers/codex-host-installer.js.map +1 -1
  155. package/dist/installers/index.d.ts +23 -0
  156. package/dist/installers/index.d.ts.map +1 -1
  157. package/dist/installers/index.js +38 -1
  158. package/dist/installers/index.js.map +1 -1
  159. package/dist/installers/legacy-workbuddy-skill.d.ts +59 -0
  160. package/dist/installers/legacy-workbuddy-skill.d.ts.map +1 -0
  161. package/dist/installers/legacy-workbuddy-skill.js +168 -0
  162. package/dist/installers/legacy-workbuddy-skill.js.map +1 -0
  163. package/dist/installers/workbuddy-host-installer.d.ts.map +1 -1
  164. package/dist/installers/workbuddy-host-installer.js +7 -0
  165. package/dist/installers/workbuddy-host-installer.js.map +1 -1
  166. package/host-runtime/dist/adaptive-priority-provider.d.ts +94 -0
  167. package/host-runtime/dist/adaptive-priority-provider.js +162 -0
  168. package/host-runtime/dist/adaptive-selection.d.ts +164 -0
  169. package/host-runtime/dist/adaptive-selection.js +506 -0
  170. package/host-runtime/dist/diagnostician-auto-run.d.ts +28 -0
  171. package/host-runtime/dist/diagnostician-auto-run.js +100 -0
  172. package/host-runtime/dist/host-tool-semantic-resolver.d.ts +42 -1
  173. package/host-runtime/dist/host-tool-semantic-resolver.js +80 -14
  174. package/host-runtime/dist/index.d.ts +4 -0
  175. package/host-runtime/dist/index.js +6 -0
  176. package/host-runtime/dist/production-rulehost-gate.js +17 -17
  177. package/host-runtime/dist/rulecode-event-collection.d.ts +31 -0
  178. package/host-runtime/dist/rulecode-event-collection.js +62 -0
  179. package/host-runtime/package.json +1 -1
  180. package/package.json +3 -3
  181. package/pd-cli/dist/commands/diagnose.d.ts +30 -0
  182. package/pd-cli/dist/commands/diagnose.d.ts.map +1 -1
  183. package/pd-cli/dist/commands/diagnose.js +75 -0
  184. package/pd-cli/dist/commands/diagnose.js.map +1 -1
  185. package/pd-cli/dist/commands/pain-record.d.ts.map +1 -1
  186. package/pd-cli/dist/commands/pain-record.js +5 -4
  187. package/pd-cli/dist/commands/pain-record.js.map +1 -1
  188. package/pd-cli/dist/commands/pain-retry.d.ts.map +1 -1
  189. package/pd-cli/dist/commands/pain-retry.js +2 -1
  190. package/pd-cli/dist/commands/pain-retry.js.map +1 -1
  191. package/pd-cli/dist/commands/runtime-activation.d.ts +6 -17
  192. package/pd-cli/dist/commands/runtime-activation.d.ts.map +1 -1
  193. package/pd-cli/dist/commands/runtime-activation.js +42 -48
  194. package/pd-cli/dist/commands/runtime-activation.js.map +1 -1
  195. package/pd-cli/dist/index.js +1 -0
  196. package/pd-cli/dist/index.js.map +1 -1
  197. package/pd-cli/dist/services/delivery-surfaces.js +1 -1
  198. package/pd-cli/dist/services/delivery-surfaces.js.map +1 -1
  199. package/pd-cli/package.json +1 -1
  200. package/pd-mcp-server/dist/budget.d.ts +1 -1
  201. package/pd-mcp-server/dist/budget.js +2 -2
  202. package/pd-mcp-server/dist/envelope.d.ts +15 -0
  203. package/pd-mcp-server/dist/envelope.js +49 -1
  204. package/pd-mcp-server/dist/index.d.ts +2 -0
  205. package/pd-mcp-server/dist/index.js +6 -0
  206. package/pd-mcp-server/dist/server.d.ts +83 -14
  207. package/pd-mcp-server/dist/server.js +251 -4
  208. package/pd-mcp-server/dist/version.d.ts +1 -1
  209. package/pd-mcp-server/dist/version.js +1 -1
  210. package/pd-mcp-server/dist/workspace.d.ts +4 -2
  211. package/pd-mcp-server/dist/workspace.js +5 -2
  212. package/pd-mcp-server/package.json +1 -1
  213. package/plugin/dist/bundle.js +443 -431
  214. package/plugin/dist/core/evolution-reducer.d.ts +2 -2
  215. package/plugin/dist/hooks/hook-tool-semantics.d.ts +25 -0
  216. package/plugin/dist/hooks/pain-ingress-adapter.d.ts +1 -1
  217. package/plugin/dist/openclaw.plugin.json +1 -1
  218. package/plugin/dist/rulehost-evidence.js +1 -1
  219. package/plugin/openclaw.plugin.json +1 -1
  220. package/plugin/package.json +1 -1
  221. package/release-manager/dist/installer.js +84 -4
  222. package/release-manager/dist/installers/codex-host-installer.js +350 -11
  223. package/release-manager/dist/installers/index.js +38 -1
  224. package/release-manager/dist/installers/legacy-workbuddy-skill.js +168 -0
  225. package/release-manager/dist/installers/workbuddy-host-installer.js +7 -0
  226. package/release-manager/package.json +1 -1
  227. package/workbuddy-adapter/dist/pd-hook.js +20 -4
  228. package/workbuddy-adapter/package.json +1 -1
  229. package/workbuddy-adapter/plugin/skills/pd-pain-signal/SKILL.md +123 -20
@@ -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,6 +11,7 @@ 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';
@@ -18,10 +19,13 @@ export * from './production-pain-evidence.js';
18
19
  export * from './governance-observation-store.js';
19
20
  export * from './governance-signal-admission.js';
20
21
  export * from './signal-classifier.js';
22
+ export * from './adaptive-selection.js';
23
+ export * from './adaptive-priority-provider.js';
21
24
  export * from './signal-stage2-cycle.js';
22
25
  export * from './host-liveness-contract.js';
23
26
  export * from './internalization-consumer-governance.js';
24
27
  export * from './internalization-consumer-cycle.js';
28
+ export * from './diagnostician-auto-run.js';
25
29
  export * from './host-tool-declaration.js';
26
30
  export * from './host-tool-semantic-resolver.js';
27
31
  export * from './evaluator-runtime-context.js';
@@ -21,6 +21,9 @@ 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';
@@ -28,12 +31,15 @@ export * from './production-pain-evidence.js';
28
31
  export * from './governance-observation-store.js';
29
32
  export * from './governance-signal-admission.js';
30
33
  export * from './signal-classifier.js';
34
+ export * from './adaptive-selection.js';
35
+ export * from './adaptive-priority-provider.js';
31
36
  export * from './signal-stage2-cycle.js';
32
37
  export * from './host-liveness-contract.js';
33
38
  // PRI-624 Slice C: shared internalization consumer execution (OpenClaw
34
39
  // auto-consumer + Companion workspace worker call the same cycle).
35
40
  export * from './internalization-consumer-governance.js';
36
41
  export * from './internalization-consumer-cycle.js';
42
+ export * from './diagnostician-auto-run.js';
37
43
  // PRI-634-F R2: durable host-authored tool declaration — hosts persist, host-
38
44
  // neutral consumers (pd-cli/pd-console) resolve through the ONE resolver.
39
45
  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.3.1",
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.1",
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": "8851a3be8c3bcacb732609143bfe3d2ac4ba4ea5"
105
105
  }
@@ -16,7 +16,37 @@ interface DiagnoseRunOptions {
16
16
  maxRetries?: number;
17
17
  timeoutMs?: number;
18
18
  intake?: boolean;
19
+ preflight?: boolean;
19
20
  }
21
+ /**
22
+ * Read-only preflight verdict for `pd diagnose run --preflight`
23
+ * (SPEC v0.8 §9.2 check 7 snapshot).
24
+ *
25
+ * It answers only "would a run be accepted right now?" from configuration.
26
+ * It deliberately opens no state store, takes no lease, resolves no test
27
+ * double, contacts no provider, and writes nothing — the Console L2 route
28
+ * calls this before spawning the real run so a refusal never leaves a trace.
29
+ */
30
+ export interface DiagnosePreflightResult {
31
+ readonly ok: boolean;
32
+ readonly taskId: string;
33
+ readonly workspaceDir: string;
34
+ readonly reason?: 'capability_disabled' | 'config_malformed' | 'runtime_unbound';
35
+ readonly message?: string;
36
+ readonly nextAction?: string;
37
+ readonly runtimeKind?: string;
38
+ readonly runtimeProfileId?: string | null;
39
+ readonly runtimeProfileLabel?: string | null;
40
+ readonly provider?: string;
41
+ readonly model?: string;
42
+ }
43
+ /**
44
+ * Resolve the preflight verdict from configuration alone.
45
+ *
46
+ * The capability kill switch is checked before runtime binding so an Owner
47
+ * disable is never mislabelled as a missing runtime (PRI-638 semantics).
48
+ */
49
+ export declare function resolveDiagnosePreflight(taskId: string, workspaceDir: string): DiagnosePreflightResult;
20
50
  /**
21
51
  * pd diagnose status --task-id <taskId> [--workspace <path>] [--json]
22
52
  *
@@ -1 +1 @@
1
- {"version":3,"file":"diagnose.d.ts","sourceRoot":"","sources":["../../src/commands/diagnose.ts"],"names":[],"mappings":"AAmEA,UAAU,qBAAqB;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED,UAAU,kBAAkB;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED;;;;GAIG;AACH,wBAAsB,oBAAoB,CAAC,IAAI,EAAE,qBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC,CAmErF;AAkCD;;;;GAIG;AACH,wBAAsB,iBAAiB,CAAC,IAAI,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC,CAssB/E"}
1
+ {"version":3,"file":"diagnose.d.ts","sourceRoot":"","sources":["../../src/commands/diagnose.ts"],"names":[],"mappings":"AAmEA,UAAU,qBAAqB;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED,UAAU,kBAAkB;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,EAAE,EAAE,OAAO,CAAC;IACrB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,MAAM,CAAC,EAAE,qBAAqB,GAAG,kBAAkB,GAAG,iBAAiB,CAAC;IACjF,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1C,QAAQ,CAAC,mBAAmB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7C,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,uBAAuB,CAiDtG;AAED;;;;GAIG;AACH,wBAAsB,oBAAoB,CAAC,IAAI,EAAE,qBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC,CAmErF;AAkCD;;;;GAIG;AACH,wBAAsB,iBAAiB,CAAC,IAAI,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC,CA6tB/E"}
@@ -31,6 +31,58 @@ function validateStalledThreshold(val) {
31
31
  }
32
32
  return num;
33
33
  }
34
+ /**
35
+ * Resolve the preflight verdict from configuration alone.
36
+ *
37
+ * The capability kill switch is checked before runtime binding so an Owner
38
+ * disable is never mislabelled as a missing runtime (PRI-638 semantics).
39
+ */
40
+ export function resolveDiagnosePreflight(taskId, workspaceDir) {
41
+ const resolved = resolveRuntimeFromPdConfig(workspaceDir);
42
+ const { configLoadResult } = resolved;
43
+ if (!configLoadResult.ok) {
44
+ const [firstError] = configLoadResult.errors;
45
+ return {
46
+ ok: false,
47
+ taskId,
48
+ workspaceDir,
49
+ reason: 'config_malformed',
50
+ message: firstError?.reason ?? '.pd/config.yaml is malformed',
51
+ nextAction: firstError?.nextAction ?? 'Fix .pd/config.yaml syntax and retry',
52
+ };
53
+ }
54
+ const capability = resolveDiagnosticianCapability(configLoadResult.effective);
55
+ if (!capability.available) {
56
+ return {
57
+ ok: false,
58
+ taskId,
59
+ workspaceDir,
60
+ reason: 'capability_disabled',
61
+ message: capability.message,
62
+ nextAction: capability.nextAction,
63
+ };
64
+ }
65
+ if (isRuntimeConfigError(resolved.result)) {
66
+ return {
67
+ ok: false,
68
+ taskId,
69
+ workspaceDir,
70
+ reason: 'runtime_unbound',
71
+ message: resolved.result.message,
72
+ nextAction: resolved.result.nextAction,
73
+ };
74
+ }
75
+ return {
76
+ ok: true,
77
+ taskId,
78
+ workspaceDir,
79
+ runtimeKind: resolved.result.runtimeKind,
80
+ runtimeProfileId: resolved.runtimeProfileId,
81
+ runtimeProfileLabel: resolved.runtimeProfileLabel,
82
+ provider: resolved.result.provider,
83
+ model: resolved.result.model,
84
+ };
85
+ }
34
86
  /**
35
87
  * pd diagnose status --task-id <taskId> [--workspace <path>] [--json]
36
88
  *
@@ -140,6 +192,29 @@ function buildDiagnosticianTestDouble(taskId) {
140
192
  */
141
193
  export async function handleDiagnoseRun(opts) {
142
194
  const workspaceDir = resolveWorkspaceDir(opts.workspace);
195
+ // SPEC v0.8 §9.2: `--preflight` is a strict no-op probe. It runs BEFORE any
196
+ // state store, lease, adapter or telemetry construction, so a verdict can
197
+ // never leave a mutation behind (T32: 403/415/404/409 must not change state).
198
+ if (opts.preflight === true) {
199
+ const preflight = resolveDiagnosePreflight(opts.taskId, workspaceDir);
200
+ if (opts.json) {
201
+ console.log(JSON.stringify(preflight, null, 2));
202
+ }
203
+ else if (preflight.ok) {
204
+ console.log(`Preflight OK for task: ${preflight.taskId}`);
205
+ console.log(`Workspace: ${preflight.workspaceDir}`);
206
+ console.log(`Runtime: ${preflight.runtimeKind}${preflight.runtimeProfileLabel ? ` (${preflight.runtimeProfileLabel})` : ''}`);
207
+ }
208
+ else {
209
+ console.error(`error: ${preflight.message}`);
210
+ console.error(`reason: ${preflight.reason}`);
211
+ console.error(`nextAction: ${preflight.nextAction}`);
212
+ }
213
+ if (!preflight.ok) {
214
+ process.exit(1);
215
+ }
216
+ return;
217
+ }
143
218
  // PRI-720: resolve the full-chain override once per invocation.
144
219
  const seedPipelineMode = resolvePromptFullPipelineSeedMode(workspaceDir);
145
220
  // PRI-638: this is the CLI's ONLY capability disable check. It reads the