@principles/pd-cli 1.152.12 → 1.152.14

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 (305) hide show
  1. package/dist/commands/candidate.d.ts.map +1 -1
  2. package/dist/commands/candidate.js +34 -7
  3. package/dist/commands/candidate.js.map +1 -1
  4. package/dist/commands/diagnose.d.ts.map +1 -1
  5. package/dist/commands/diagnose.js +23 -7
  6. package/dist/commands/diagnose.js.map +1 -1
  7. package/dist/commands/pain-retry.d.ts.map +1 -1
  8. package/dist/commands/pain-retry.js +21 -7
  9. package/dist/commands/pain-retry.js.map +1 -1
  10. package/package.json +13 -7
  11. package/CHANGELOG.md +0 -23
  12. package/dist/commands/__tests__/intent-flag-wiring.test.d.ts +0 -9
  13. package/dist/commands/__tests__/intent-flag-wiring.test.d.ts.map +0 -1
  14. package/dist/commands/__tests__/intent-flag-wiring.test.js +0 -237
  15. package/dist/commands/__tests__/intent-flag-wiring.test.js.map +0 -1
  16. package/dist/commands/__tests__/legacy-cleanup.test.d.ts +0 -18
  17. package/dist/commands/__tests__/legacy-cleanup.test.d.ts.map +0 -1
  18. package/dist/commands/__tests__/legacy-cleanup.test.js +0 -467
  19. package/dist/commands/__tests__/legacy-cleanup.test.js.map +0 -1
  20. package/dist/commands/__tests__/mvp-smoke.test.d.ts +0 -15
  21. package/dist/commands/__tests__/mvp-smoke.test.d.ts.map +0 -1
  22. package/dist/commands/__tests__/mvp-smoke.test.js +0 -262
  23. package/dist/commands/__tests__/mvp-smoke.test.js.map +0 -1
  24. package/dist/commands/__tests__/pain-retry-maxTokens-flag.test.d.ts +0 -2
  25. package/dist/commands/__tests__/pain-retry-maxTokens-flag.test.d.ts.map +0 -1
  26. package/dist/commands/__tests__/pain-retry-maxTokens-flag.test.js +0 -60
  27. package/dist/commands/__tests__/pain-retry-maxTokens-flag.test.js.map +0 -1
  28. package/dist/commands/__tests__/rulecode-flag-wiring.test.d.ts +0 -21
  29. package/dist/commands/__tests__/rulecode-flag-wiring.test.d.ts.map +0 -1
  30. package/dist/commands/__tests__/rulecode-flag-wiring.test.js +0 -186
  31. package/dist/commands/__tests__/rulecode-flag-wiring.test.js.map +0 -1
  32. package/dist/commands/__tests__/rulecode-handler.test.d.ts +0 -16
  33. package/dist/commands/__tests__/rulecode-handler.test.d.ts.map +0 -1
  34. package/dist/commands/__tests__/rulecode-handler.test.js +0 -285
  35. package/dist/commands/__tests__/rulecode-handler.test.js.map +0 -1
  36. package/dist/commands/__tests__/run-rulehost-flag-wiring.test.d.ts +0 -24
  37. package/dist/commands/__tests__/run-rulehost-flag-wiring.test.d.ts.map +0 -1
  38. package/dist/commands/__tests__/run-rulehost-flag-wiring.test.js +0 -232
  39. package/dist/commands/__tests__/run-rulehost-flag-wiring.test.js.map +0 -1
  40. package/dist/commands/__tests__/runtime-activation-nextaction.test.d.ts +0 -15
  41. package/dist/commands/__tests__/runtime-activation-nextaction.test.d.ts.map +0 -1
  42. package/dist/commands/__tests__/runtime-activation-nextaction.test.js +0 -73
  43. package/dist/commands/__tests__/runtime-activation-nextaction.test.js.map +0 -1
  44. package/dist/commands/__tests__/runtime-probe-config.test.d.ts +0 -20
  45. package/dist/commands/__tests__/runtime-probe-config.test.d.ts.map +0 -1
  46. package/dist/commands/__tests__/runtime-probe-config.test.js +0 -389
  47. package/dist/commands/__tests__/runtime-probe-config.test.js.map +0 -1
  48. package/dist/commands/__tests__/telemetry-flag-wiring.test.d.ts +0 -9
  49. package/dist/commands/__tests__/telemetry-flag-wiring.test.d.ts.map +0 -1
  50. package/dist/commands/__tests__/telemetry-flag-wiring.test.js +0 -76
  51. package/dist/commands/__tests__/telemetry-flag-wiring.test.js.map +0 -1
  52. package/dist/commands/__tests__/version.test.d.ts +0 -2
  53. package/dist/commands/__tests__/version.test.d.ts.map +0 -1
  54. package/dist/commands/__tests__/version.test.js +0 -238
  55. package/dist/commands/__tests__/version.test.js.map +0 -1
  56. package/dist/commands/runtime-uat.guard.test.d.ts +0 -2
  57. package/dist/commands/runtime-uat.guard.test.d.ts.map +0 -1
  58. package/dist/commands/runtime-uat.guard.test.js +0 -153
  59. package/dist/commands/runtime-uat.guard.test.js.map +0 -1
  60. package/dist/services/__tests__/cli-output.test.d.ts +0 -18
  61. package/dist/services/__tests__/cli-output.test.d.ts.map +0 -1
  62. package/dist/services/__tests__/cli-output.test.js +0 -103
  63. package/dist/services/__tests__/cli-output.test.js.map +0 -1
  64. package/dist/services/__tests__/evaluator-runner-deps.test.d.ts +0 -2
  65. package/dist/services/__tests__/evaluator-runner-deps.test.d.ts.map +0 -1
  66. package/dist/services/__tests__/evaluator-runner-deps.test.js +0 -343
  67. package/dist/services/__tests__/evaluator-runner-deps.test.js.map +0 -1
  68. package/dist/services/__tests__/rulehost-readiness.test.d.ts +0 -2
  69. package/dist/services/__tests__/rulehost-readiness.test.d.ts.map +0 -1
  70. package/dist/services/__tests__/rulehost-readiness.test.js +0 -311
  71. package/dist/services/__tests__/rulehost-readiness.test.js.map +0 -1
  72. package/dist/services/__tests__/runtime-adapter-resolver.test.d.ts +0 -18
  73. package/dist/services/__tests__/runtime-adapter-resolver.test.d.ts.map +0 -1
  74. package/dist/services/__tests__/runtime-adapter-resolver.test.js +0 -673
  75. package/dist/services/__tests__/runtime-adapter-resolver.test.js.map +0 -1
  76. package/dist/utils/production-workspace-guard.test.d.ts +0 -2
  77. package/dist/utils/production-workspace-guard.test.d.ts.map +0 -1
  78. package/dist/utils/production-workspace-guard.test.js +0 -137
  79. package/dist/utils/production-workspace-guard.test.js.map +0 -1
  80. package/scripts/llm-dogfood.ts +0 -456
  81. package/scripts/migrate-illegal-expected-decision.ts +0 -252
  82. package/src/commands/__tests__/intent-flag-wiring.test.ts +0 -282
  83. package/src/commands/__tests__/legacy-cleanup.test.ts +0 -602
  84. package/src/commands/__tests__/mvp-smoke.test.ts +0 -300
  85. package/src/commands/__tests__/pain-retry-maxTokens-flag.test.ts +0 -73
  86. package/src/commands/__tests__/rulecode-flag-wiring.test.ts +0 -237
  87. package/src/commands/__tests__/rulecode-handler.test.ts +0 -369
  88. package/src/commands/__tests__/run-rulehost-flag-wiring.test.ts +0 -292
  89. package/src/commands/__tests__/runtime-activation-nextaction.test.ts +0 -81
  90. package/src/commands/__tests__/runtime-probe-config.test.ts +0 -432
  91. package/src/commands/__tests__/telemetry-flag-wiring.test.ts +0 -84
  92. package/src/commands/__tests__/version.test.ts +0 -251
  93. package/src/commands/admission-gate.ts +0 -30
  94. package/src/commands/artifact.ts +0 -82
  95. package/src/commands/build-trajectory-evidence.ts +0 -298
  96. package/src/commands/candidate.ts +0 -1250
  97. package/src/commands/codex-ingest-catchup.ts +0 -114
  98. package/src/commands/codex-ingest-quarantine.ts +0 -127
  99. package/src/commands/codex-reconcile.ts +0 -84
  100. package/src/commands/codex-setup.ts +0 -476
  101. package/src/commands/codex-worker.ts +0 -185
  102. package/src/commands/command-helpers.ts +0 -24
  103. package/src/commands/config-doctor.ts +0 -193
  104. package/src/commands/console.ts +0 -797
  105. package/src/commands/context.ts +0 -72
  106. package/src/commands/demo-story-a.ts +0 -241
  107. package/src/commands/diagnose.ts +0 -756
  108. package/src/commands/errors-list.ts +0 -441
  109. package/src/commands/evolution-tasks-list.ts +0 -48
  110. package/src/commands/evolution-tasks-show.ts +0 -62
  111. package/src/commands/flow.ts +0 -60
  112. package/src/commands/health-codex.ts +0 -576
  113. package/src/commands/health.ts +0 -315
  114. package/src/commands/history.ts +0 -63
  115. package/src/commands/intent.ts +0 -457
  116. package/src/commands/legacy-cleanup.ts +0 -531
  117. package/src/commands/legacy-import.ts +0 -104
  118. package/src/commands/mvp-smoke.ts +0 -160
  119. package/src/commands/pain-evidence.ts +0 -226
  120. package/src/commands/pain-list.ts +0 -239
  121. package/src/commands/pain-record.ts +0 -612
  122. package/src/commands/pain-retry.ts +0 -916
  123. package/src/commands/principles-stats.ts +0 -700
  124. package/src/commands/proven-channel-baseline.ts +0 -115
  125. package/src/commands/quality-scorecard.ts +0 -272
  126. package/src/commands/remediation-output.ts +0 -66
  127. package/src/commands/rulecode.ts +0 -465
  128. package/src/commands/run.ts +0 -89
  129. package/src/commands/runtime-activation.ts +0 -1629
  130. package/src/commands/runtime-artifact-repair.ts +0 -524
  131. package/src/commands/runtime-canary.ts +0 -395
  132. package/src/commands/runtime-compatibility-scan.ts +0 -105
  133. package/src/commands/runtime-diagnostics-export.ts +0 -229
  134. package/src/commands/runtime-features.ts +0 -153
  135. package/src/commands/runtime-gfi-snapshot.ts +0 -135
  136. package/src/commands/runtime-health-snapshot.ts +0 -108
  137. package/src/commands/runtime-init.ts +0 -429
  138. package/src/commands/runtime-internalization-enqueue-successors.ts +0 -530
  139. package/src/commands/runtime-internalization-integrity-repair.ts +0 -79
  140. package/src/commands/runtime-internalization-integrity.ts +0 -107
  141. package/src/commands/runtime-internalization-queue.ts +0 -135
  142. package/src/commands/runtime-internalization-retry.ts +0 -191
  143. package/src/commands/runtime-internalization-run-once.ts +0 -791
  144. package/src/commands/runtime-internalization-run-rulehost.ts +0 -749
  145. package/src/commands/runtime-internalization-wake-once.ts +0 -87
  146. package/src/commands/runtime-pain-flood-simulation.ts +0 -121
  147. package/src/commands/runtime-pruning.ts +0 -438
  148. package/src/commands/runtime-recovery-failed-tasks.ts +0 -258
  149. package/src/commands/runtime-recovery.ts +0 -109
  150. package/src/commands/runtime-synthetic-baseline.ts +0 -70
  151. package/src/commands/runtime-uat.guard.test.ts +0 -175
  152. package/src/commands/runtime-uat.ts +0 -380
  153. package/src/commands/runtime.ts +0 -473
  154. package/src/commands/samples-list.ts +0 -39
  155. package/src/commands/samples-review.ts +0 -36
  156. package/src/commands/task.ts +0 -271
  157. package/src/commands/telemetry.ts +0 -349
  158. package/src/commands/trace.ts +0 -174
  159. package/src/commands/trajectory-db-unavailable.ts +0 -19
  160. package/src/commands/trajectory.ts +0 -64
  161. package/src/commands/version.ts +0 -49
  162. package/src/config-reader.ts +0 -122
  163. package/src/index.ts +0 -1276
  164. package/src/legacy/legacy-import.ts +0 -179
  165. package/src/legacy/session-history-import.ts +0 -203
  166. package/src/resolve-workspace.ts +0 -106
  167. package/src/services/__tests__/cli-output.test.ts +0 -130
  168. package/src/services/__tests__/evaluator-runner-deps.test.ts +0 -382
  169. package/src/services/__tests__/rulehost-readiness.test.ts +0 -363
  170. package/src/services/__tests__/runtime-adapter-resolver.test.ts +0 -793
  171. package/src/services/cli-output.ts +0 -95
  172. package/src/services/config-doctor.ts +0 -697
  173. package/src/services/console-launcher.ts +0 -537
  174. package/src/services/demo-rule-compiler.ts +0 -40
  175. package/src/services/demo-story-a-runner.ts +0 -471
  176. package/src/services/mainline-snapshot-assembler.ts +0 -579
  177. package/src/services/pain-flood-simulation-runner.ts +0 -462
  178. package/src/services/pd-config-loader.ts +0 -433
  179. package/src/services/proven-channel-baseline-runner.ts +0 -157
  180. package/src/services/quality-scorecard/data-extractor.ts +0 -150
  181. package/src/services/quality-scorecard/local-evaluator.ts +0 -142
  182. package/src/services/quality-scorecard/strong-model-gate.ts +0 -202
  183. package/src/services/resolve-runtime-from-pd-config.ts +0 -230
  184. package/src/services/rulehost-pipeline-runner.ts +0 -1214
  185. package/src/services/rulehost-readiness.ts +0 -326
  186. package/src/services/runtime-adapter-resolver.ts +0 -364
  187. package/src/services/synthetic-baseline-runner.ts +0 -400
  188. package/src/services/version-report.ts +0 -253
  189. package/src/services/workspace-tool-semantics.ts +0 -26
  190. package/src/utils/path-security.ts +0 -96
  191. package/src/utils/production-workspace-guard.test.ts +0 -157
  192. package/src/utils/production-workspace-guard.ts +0 -210
  193. package/tests/bdd/cli-contract.steps.ts +0 -346
  194. package/tests/bdd/principles-stats.steps.ts +0 -211
  195. package/tests/bdd/support/gherkin-loader.ts +0 -147
  196. package/tests/bdd/support/repo-root.ts +0 -62
  197. package/tests/bdd/support/vitest-bdd.ts +0 -179
  198. package/tests/commands/admission-gate-coverage.test.ts +0 -79
  199. package/tests/commands/build-trajectory-evidence.test.ts +0 -508
  200. package/tests/commands/candidate-audit-repair.test.ts +0 -421
  201. package/tests/commands/candidate-intake.test.ts +0 -732
  202. package/tests/commands/candidate-internalization-backfill.test.ts +0 -548
  203. package/tests/commands/candidate-internalize-lineage.test.ts +0 -628
  204. package/tests/commands/candidate-internalize.test.ts +0 -299
  205. package/tests/commands/candidate-route.test.ts +0 -329
  206. package/tests/commands/candidate-show.test.ts +0 -95
  207. package/tests/commands/cli-command-tree.test.ts +0 -144
  208. package/tests/commands/cli-help-snapshot.test.ts +0 -155
  209. package/tests/commands/cli-skill-contract.test.ts +0 -121
  210. package/tests/commands/codex-consent-reversibility.steps.test.ts +0 -299
  211. package/tests/commands/codex-ingest-quarantine.test.ts +0 -136
  212. package/tests/commands/codex-setup.test.ts +0 -297
  213. package/tests/commands/codex-worker-daemon.test.ts +0 -95
  214. package/tests/commands/codex-worker-registration.test.ts +0 -207
  215. package/tests/commands/config-doctor.test.ts +0 -336
  216. package/tests/commands/console-launcher-edge-cases.test.ts +0 -388
  217. package/tests/commands/console-open.test.ts +0 -1381
  218. package/tests/commands/context.test.ts +0 -114
  219. package/tests/commands/demo-story-a.test.ts +0 -318
  220. package/tests/commands/diagnose.test.ts +0 -1803
  221. package/tests/commands/errors-list.test.ts +0 -679
  222. package/tests/commands/evolution-tasks-list.test.ts +0 -41
  223. package/tests/commands/evolution-tasks-show.test.ts +0 -46
  224. package/tests/commands/health-codex.test.ts +0 -349
  225. package/tests/commands/health-host-wiring.test.ts +0 -76
  226. package/tests/commands/health-reliability.test.ts +0 -99
  227. package/tests/commands/health.test.ts +0 -413
  228. package/tests/commands/intent.test.ts +0 -321
  229. package/tests/commands/legacy-cleanup.test.ts +0 -148
  230. package/tests/commands/pain-evidence.test.ts +0 -518
  231. package/tests/commands/pain-list.test.ts +0 -219
  232. package/tests/commands/pain-record-async.test.ts +0 -335
  233. package/tests/commands/pain-record-session-parser.test.ts +0 -228
  234. package/tests/commands/pain-record.test.ts +0 -851
  235. package/tests/commands/pain-retry.test.ts +0 -1121
  236. package/tests/commands/plugin-config-resolution-cutover.test.ts +0 -229
  237. package/tests/commands/pri-393-runtime-config-unification.test.ts +0 -443
  238. package/tests/commands/principles-stats-wiring.test.ts +0 -135
  239. package/tests/commands/principles-stats.test.ts +0 -274
  240. package/tests/commands/product-path-regression.test.ts +0 -86
  241. package/tests/commands/proven-channel-baseline.test.ts +0 -441
  242. package/tests/commands/rulecode.test.ts +0 -177
  243. package/tests/commands/run-rulehost-handler.test.ts +0 -908
  244. package/tests/commands/runtime-activation-approve-flag-wiring.test.ts +0 -227
  245. package/tests/commands/runtime-activation-deactivate-flag-wiring.test.ts +0 -167
  246. package/tests/commands/runtime-activation-dispatch-flag-wiring.test.ts +0 -262
  247. package/tests/commands/runtime-activation-governance-audit.test.ts +0 -95
  248. package/tests/commands/runtime-activation-list-flag-wiring.test.ts +0 -193
  249. package/tests/commands/runtime-activation-promote-flag-wiring.test.ts +0 -248
  250. package/tests/commands/runtime-activation-shadow-telemetry.test.ts +0 -130
  251. package/tests/commands/runtime-activation.test.ts +0 -2052
  252. package/tests/commands/runtime-artifact-repair-registration.test.ts +0 -74
  253. package/tests/commands/runtime-artifact-repair.test.ts +0 -404
  254. package/tests/commands/runtime-canary.test.ts +0 -430
  255. package/tests/commands/runtime-compatibility-scan.test.ts +0 -146
  256. package/tests/commands/runtime-diagnostics-export.test.ts +0 -175
  257. package/tests/commands/runtime-features.test.ts +0 -249
  258. package/tests/commands/runtime-health-snapshot.test.ts +0 -358
  259. package/tests/commands/runtime-init-empty-workspace.test.ts +0 -252
  260. package/tests/commands/runtime-init.test.ts +0 -420
  261. package/tests/commands/runtime-internalization-enqueue-successors.test.ts +0 -782
  262. package/tests/commands/runtime-internalization-integrity-repair.test.ts +0 -239
  263. package/tests/commands/runtime-internalization-integrity.test.ts +0 -140
  264. package/tests/commands/runtime-internalization-queue.test.ts +0 -380
  265. package/tests/commands/runtime-internalization-retry-owner-authority.test.ts +0 -431
  266. package/tests/commands/runtime-internalization-run-once-evaluator-parity.test.ts +0 -269
  267. package/tests/commands/runtime-internalization-run-once-language.test.ts +0 -303
  268. package/tests/commands/runtime-internalization-run-once-real-config.test.ts +0 -237
  269. package/tests/commands/runtime-internalization-run-once-rollout-parity.test.ts +0 -706
  270. package/tests/commands/runtime-internalization-run-once.test.ts +0 -1791
  271. package/tests/commands/runtime-internalization-wake-once.test.ts +0 -171
  272. package/tests/commands/runtime-internalization.test.ts +0 -53
  273. package/tests/commands/runtime-pain-flood-simulation.test.ts +0 -418
  274. package/tests/commands/runtime-pruning.test.ts +0 -694
  275. package/tests/commands/runtime-recovery-failed-tasks.test.ts +0 -328
  276. package/tests/commands/runtime-recovery.test.ts +0 -120
  277. package/tests/commands/runtime-synthetic-baseline.test.ts +0 -249
  278. package/tests/commands/runtime-uat.test.ts +0 -397
  279. package/tests/commands/runtime.test.ts +0 -392
  280. package/tests/commands/samples-list.test.ts +0 -43
  281. package/tests/commands/samples-review.test.ts +0 -41
  282. package/tests/commands/task.test.ts +0 -153
  283. package/tests/commands/telemetry.test.ts +0 -190
  284. package/tests/commands/trace.test.ts +0 -316
  285. package/tests/config-reader.test.ts +0 -143
  286. package/tests/e2e/candidate-intake-e2e.test.ts +0 -338
  287. package/tests/e2e/cli-full-flow.test.ts +0 -233
  288. package/tests/e2e/cross-package-acceptance.test.ts +0 -635
  289. package/tests/helpers/pd-cli-path.ts +0 -5
  290. package/tests/pd-cli-smoke.test.ts +0 -13
  291. package/tests/resolve-workspace.test.ts +0 -196
  292. package/tests/services/config-doctor-signal-health.test.ts +0 -109
  293. package/tests/services/console-launcher.test.ts +0 -114
  294. package/tests/services/demo-rule-compiler.test.ts +0 -242
  295. package/tests/services/mainline-snapshot-assembler.test.ts +0 -572
  296. package/tests/services/pd-config-loader.test.ts +0 -505
  297. package/tests/services/proven-channel-baseline-runner.test.ts +0 -30
  298. package/tests/services/quality-scorecard/strong-model-gate.test.ts +0 -133
  299. package/tests/services/resolve-runtime-from-pd-config.test.ts +0 -485
  300. package/tests/services/rulehost-pipeline-e2e.test.ts +0 -538
  301. package/tests/services/rulehost-pipeline-runner.test.ts +0 -1242
  302. package/tests/services/workspace-tool-semantics.test.ts +0 -76
  303. package/tests/utils/path-security.test.ts +0 -180
  304. package/tsconfig.json +0 -26
  305. package/vitest.config.ts +0 -10
@@ -1,791 +0,0 @@
1
- import * as path from 'path';
2
- import {
3
- RuntimeStateManager,
4
- InternalizationOrchestrator,
5
- DreamerRunner,
6
- PhilosopherRunner,
7
- ScribeRunner,
8
- ArtificerRunner,
9
- EvaluatorRunner,
10
- RolloutReviewerRunner,
11
- StoreEventEmitter,
12
- DefaultDreamerValidator,
13
- DefaultPhilosopherValidator,
14
- DefaultScribeValidator,
15
- DefaultArtificerValidator,
16
- DefaultEvaluatorValidator,
17
- DefaultRolloutReviewerValidator,
18
- TestDoubleRuntimeAdapter,
19
- } from '@principles/core/runtime-v2';
20
- import type { WakeOnceResult, DreamerRunnerResult, PhilosopherRunnerResult, ScribeRunnerResult, ArtificerRunnerResult, EvaluatorRunnerResult, RolloutReviewerRunnerResult, PDRuntimeAdapter, PeerRunnerKind, OutputLanguage, ArtificerHostSemanticContext } from '@principles/core/runtime-v2';
21
- import { resolveRuntimeConfigForAgent, AGENT_NAME_FOR_TASK_KIND, isRuntimeConfigError, buildArtificerHostSemanticContext } from '@principles/core/runtime-v2';
22
- import { resolveWorkspaceDir } from '../resolve-workspace.js';
23
- import { readOutputLanguageFromWorkspace } from '../config-reader.js';
24
- import { loadPdConfig } from '../services/pd-config-loader.js';
25
- import type { EffectivePdConfig } from '@principles/core/runtime-v2';
26
- import {
27
- resolveRuntimeAdapterFromConfig,
28
- ConfigResolutionError,
29
- } from '../services/runtime-adapter-resolver.js';
30
- // PRI-510 (DEFECT-004): centralize EvaluatorRunnerDeps construction so the
31
- // repair-loop wiring (isRepairLoopEnabled + seeder) is invoked in this CLI
32
- // path. EP-02: prior code passed only the 5 base deps, leaving the repair
33
- // loop as dead code at runtime.
34
- import { createEvaluatorRunnerDeps } from '../services/rulehost-pipeline-runner.js';
35
- // PRI-708: the canonical rollout governance factory — the ONE builder the
36
- // consumer cycle spreads (internalization-consumer-cycle.ts). Host-neutral
37
- // CLI entries wire the same reopen semantics instead of hand-rolling them.
38
- // PRI-713: same factory now also supplies dispatchActivation; the durable
39
- // workspace host-tool-semantics resolver is the shared provenance source.
40
- import { createEvaluatorRuntimeContext, createRolloutGovernanceDeps, resolveWorkspaceHostToolSemantics } from '@principles/host-runtime';
41
- import type { RefinerRuleHostGateDeps } from '@principles/core/runtime-v2';
42
-
43
- interface RunOnceOptions {
44
- workspace?: string;
45
- json?: boolean;
46
- runtime?: string;
47
- runner?: string;
48
- allowTestDouble?: boolean;
49
- enqueueNext?: boolean;
50
- timeoutMs?: number;
51
- }
52
-
53
- const OWNER = 'pd-cli-internalization-run-once';
54
- const RUNTIME_KIND = 'local-worker';
55
-
56
- // PRI-458: philosopher, evaluator, rollout_reviewer are MVP-Quiet (default off).
57
- // They remain supported via --runner for manual operation but are not auto-dispatched.
58
- // See docs/plans/2026-06-mvp-slimming-candidates-1-2/c2-live-runner-chain.md
59
- const SUPPORTED_RUNNERS = new Set(['dreamer', 'philosopher', 'scribe', 'artificer', 'evaluator', 'rollout_reviewer']);
60
-
61
- interface RunOnceOutput {
62
- decision: string;
63
- runnerKind?: string;
64
- taskId?: string;
65
- taskKind?: string;
66
- attemptCount?: number;
67
- runId?: string;
68
- artifactId?: string;
69
- resultRef?: string;
70
- runnerResult?: DreamerRunnerResult | PhilosopherRunnerResult | ScribeRunnerResult | ArtificerRunnerResult | EvaluatorRunnerResult | RolloutReviewerRunnerResult;
71
- skipReason?: string;
72
- conflictReason?: string;
73
- reason?: string;
74
- inspectedCount?: number;
75
- successorEnqueueAttempted?: boolean;
76
- successorTasksCreated?: number;
77
- successorTaskIds?: string[];
78
- successorKind?: string;
79
- enqueueDecision?: string;
80
- enqueueReason?: string;
81
- nextAction?: string;
82
- effectiveTimeoutMs?: number;
83
- timeoutSource?: string;
84
- }
85
-
86
- function buildOutput(wakeResult: WakeOnceResult, runnerResult?: DreamerRunnerResult | PhilosopherRunnerResult | ScribeRunnerResult | ArtificerRunnerResult | EvaluatorRunnerResult | RolloutReviewerRunnerResult, skipReason?: string): RunOnceOutput {
87
- const base: RunOnceOutput = { decision: wakeResult.decision };
88
-
89
- switch (wakeResult.decision) {
90
- case 'leased':
91
- base.taskId = wakeResult.taskId;
92
- base.taskKind = wakeResult.taskKind;
93
- base.attemptCount = wakeResult.attemptCount;
94
- if (runnerResult) base.runnerResult = runnerResult;
95
- if (skipReason) base.skipReason = skipReason;
96
- break;
97
- case 'would_lease':
98
- base.taskId = wakeResult.taskId;
99
- base.taskKind = wakeResult.taskKind;
100
- if (runnerResult) {
101
- base.runnerResult = runnerResult;
102
- base.runId = runnerResult.runId;
103
- base.artifactId = runnerResult.artifactId;
104
- base.resultRef = runnerResult.resultRef;
105
- }
106
- if (skipReason) base.skipReason = skipReason;
107
- break;
108
- case 'no_ready_tasks':
109
- base.reason = wakeResult.reason;
110
- base.inspectedCount = wakeResult.inspectedCount;
111
- break;
112
- case 'blocked':
113
- base.taskId = wakeResult.taskId;
114
- base.taskKind = wakeResult.taskKind;
115
- break;
116
- case 'dependency_failed':
117
- base.taskId = wakeResult.taskId;
118
- base.taskKind = wakeResult.taskKind;
119
- break;
120
- case 'lease_conflict':
121
- base.taskId = wakeResult.taskId;
122
- base.conflictReason = wakeResult.conflictReason;
123
- break;
124
- case 'invalid_task_metadata':
125
- base.taskId = wakeResult.taskId;
126
- base.taskKind = wakeResult.taskKind;
127
- break;
128
- default:
129
- break;
130
- }
131
-
132
- return base;
133
- }
134
-
135
- function formatTextOutput(output: RunOnceOutput): string {
136
- const lines: string[] = [];
137
-
138
- lines.push(`Internalization Run-Once: ${output.decision}`);
139
-
140
- if (output.runnerKind) {
141
- lines.push(` runner: ${output.runnerKind}`);
142
- }
143
-
144
- if (output.taskId) {
145
- lines.push(` task: ${output.taskId} (${output.taskKind ?? 'unknown'})`);
146
- }
147
-
148
- if (output.runnerResult) {
149
- lines.push(` runner: ${output.runnerResult.status}`);
150
- if (output.runId) {
151
- lines.push(` runId: ${output.runId}`);
152
- }
153
- if (output.artifactId) {
154
- lines.push(` artifactId: ${output.artifactId}`);
155
- }
156
- if (output.resultRef) {
157
- lines.push(` resultRef: ${output.resultRef}`);
158
- }
159
- if (output.runnerResult.errorCategory) {
160
- lines.push(` error: ${output.runnerResult.errorCategory}`);
161
- }
162
- if (output.runnerResult.failureReason) {
163
- lines.push(` reason: ${output.runnerResult.failureReason}`);
164
- }
165
- }
166
-
167
- if (output.skipReason) {
168
- lines.push(` skip: ${output.skipReason}`);
169
- }
170
-
171
- if (output.conflictReason) {
172
- lines.push(` conflict: ${output.conflictReason}`);
173
- }
174
-
175
- if (output.reason) {
176
- lines.push(` reason: ${output.reason}`);
177
- }
178
-
179
- if (output.successorTaskIds && output.successorTaskIds.length > 0) {
180
- lines.push(` successor: ${output.successorTaskIds.join(', ')} (${output.successorKind ?? 'unknown'})`);
181
- }
182
-
183
- if (output.successorEnqueueAttempted !== undefined) {
184
- lines.push(` enqueue_attempted: ${output.successorEnqueueAttempted}`);
185
- }
186
-
187
- if (output.successorTasksCreated !== undefined) {
188
- lines.push(` successors_created: ${output.successorTasksCreated}`);
189
- }
190
-
191
- if (output.enqueueDecision) {
192
- lines.push(` enqueue: ${output.enqueueDecision}`);
193
- }
194
-
195
- if (output.enqueueReason) {
196
- lines.push(` enqueue_reason: ${output.enqueueReason}`);
197
- }
198
-
199
- if (output.nextAction) {
200
- lines.push(` nextAction: ${output.nextAction}`);
201
- }
202
-
203
- if (output.effectiveTimeoutMs) {
204
- lines.push(` timeout: ${output.effectiveTimeoutMs}ms`);
205
- }
206
-
207
- if (output.timeoutSource) {
208
- lines.push(` timeoutSource: ${output.timeoutSource}`);
209
- }
210
-
211
- return lines.join('\n');
212
- }
213
-
214
- /**
215
- * PRI-431: Local test-double payload builder.
216
- * The 6 runner-specific payloads are unique to run-once.ts; the shared resolver
217
- * calls this via `testDoublePayloadBuilder` callback.
218
- */
219
- function buildTestDoubleAdapter(runnerKind: string, taskId: string): PDRuntimeAdapter {
220
- if (runnerKind === 'philosopher') {
221
- return new TestDoubleRuntimeAdapter({
222
- onPollRun: (_runId: string) => ({
223
- runId: _runId,
224
- status: 'succeeded',
225
- startedAt: new Date().toISOString(),
226
- endedAt: new Date().toISOString(),
227
- }),
228
- onFetchOutput: (_runId: string) => ({
229
- runId: _runId,
230
- payload: {
231
- taskId,
232
- sourceDreamerArtifactId: 'pi-art-test-dreamer',
233
- thesis: 'Test thesis from test-double',
234
- principleCandidate: {
235
- title: 'Test Principle',
236
- rationale: 'Test rationale',
237
- scope: 'Test scope',
238
- confidence: 0.8,
239
- },
240
- risks: [],
241
- generatedAt: new Date().toISOString(),
242
- },
243
- }),
244
- });
245
- }
246
- if (runnerKind === 'scribe') {
247
- return new TestDoubleRuntimeAdapter({
248
- onPollRun: (_runId: string) => ({
249
- runId: _runId,
250
- status: 'succeeded',
251
- startedAt: new Date().toISOString(),
252
- endedAt: new Date().toISOString(),
253
- }),
254
- onFetchOutput: (_runId: string) => ({
255
- runId: _runId,
256
- payload: {
257
- taskId,
258
- sourcePhilosopherArtifactId: 'pi-art-test-philosopher',
259
- principleDraft: {
260
- title: 'Test Principle Draft',
261
- statement: 'Test principle statement',
262
- rationale: 'Test rationale',
263
- applicability: ['All operations'],
264
- antiPatterns: ['Ignoring validation'],
265
- confidence: 0.8,
266
- },
267
- sourceTrace: {
268
- philosopherArtifactId: 'pi-art-test-philosopher',
269
- },
270
- risks: [],
271
- generatedAt: new Date().toISOString(),
272
- },
273
- }),
274
- });
275
- }
276
- if (runnerKind === 'artificer') {
277
- let capturedSourceScribeArtifactId = 'pi-art-test-scribe';
278
- return new TestDoubleRuntimeAdapter({
279
- onStartRun: (input) => {
280
- try {
281
- const payloadStr = typeof input.inputPayload === 'string' ? input.inputPayload : JSON.stringify(input.inputPayload);
282
- const parsed = JSON.parse(payloadStr);
283
- if (typeof parsed.sourceScribeArtifactId === 'string' && parsed.sourceScribeArtifactId.trim() !== '') {
284
- capturedSourceScribeArtifactId = parsed.sourceScribeArtifactId;
285
- }
286
- } catch { /* use default */ }
287
- return { runId: `td-artificer-${Date.now()}`, runtimeKind: 'test-double', startedAt: new Date().toISOString() };
288
- },
289
- onPollRun: (_runId: string) => ({
290
- runId: _runId,
291
- status: 'succeeded',
292
- startedAt: new Date().toISOString(),
293
- endedAt: new Date().toISOString(),
294
- }),
295
- onFetchOutput: (_runId: string) => ({
296
- runId: _runId,
297
- payload: {
298
- taskId,
299
- sourceScribeArtifactId: capturedSourceScribeArtifactId,
300
- implementationPlan: {
301
- summary: 'Test implementation summary',
302
- targetSurface: 'src/test/*.ts',
303
- changes: ['Add validation to test module'],
304
- tests: ['Unit test for validation'],
305
- rolloutNotes: ['Deploy behind feature flag'],
306
- confidence: 0.8,
307
- },
308
- sourceTrace: {
309
- scribeArtifactId: capturedSourceScribeArtifactId,
310
- },
311
- risks: [],
312
- generatedAt: new Date().toISOString(),
313
- },
314
- }),
315
- });
316
- }
317
- if (runnerKind === 'evaluator') {
318
- let capturedSourceArtificerArtifactId = 'pi-art-test-artificer';
319
- return new TestDoubleRuntimeAdapter({
320
- onStartRun: (input) => {
321
- try {
322
- const payloadStr = typeof input.inputPayload === 'string' ? input.inputPayload : JSON.stringify(input.inputPayload);
323
- const parsed = JSON.parse(payloadStr);
324
- if (typeof parsed.sourceArtificerArtifactId === 'string' && parsed.sourceArtificerArtifactId.trim() !== '') {
325
- capturedSourceArtificerArtifactId = parsed.sourceArtificerArtifactId;
326
- }
327
- } catch { /* use default */ }
328
- return { runId: `td-evaluator-${Date.now()}`, runtimeKind: 'test-double', startedAt: new Date().toISOString() };
329
- },
330
- onPollRun: (_runId: string) => ({
331
- runId: _runId,
332
- status: 'succeeded',
333
- startedAt: new Date().toISOString(),
334
- endedAt: new Date().toISOString(),
335
- }),
336
- onFetchOutput: (_runId: string) => ({
337
- runId: _runId,
338
- payload: {
339
- taskId,
340
- sourceArtificerArtifactId: capturedSourceArtificerArtifactId,
341
- evaluation: {
342
- decision: 'approved',
343
- summary: 'Test evaluation summary',
344
- score: 0.85,
345
- strengths: ['Well-structured plan'],
346
- concerns: [],
347
- requiredChanges: [],
348
- },
349
- sourceTrace: {
350
- artificerArtifactId: capturedSourceArtificerArtifactId,
351
- },
352
- risks: [],
353
- generatedAt: new Date().toISOString(),
354
- },
355
- }),
356
- });
357
- }
358
- if (runnerKind === 'rollout_reviewer') {
359
- let capturedSourceEvaluatorArtifactId = 'pi-art-test-evaluator';
360
- return new TestDoubleRuntimeAdapter({
361
- onStartRun: (input) => {
362
- try {
363
- const payloadStr = typeof input.inputPayload === 'string' ? input.inputPayload : JSON.stringify(input.inputPayload);
364
- const parsed = JSON.parse(payloadStr);
365
- if (typeof parsed.sourceEvaluatorArtifactId === 'string' && parsed.sourceEvaluatorArtifactId.trim() !== '') {
366
- capturedSourceEvaluatorArtifactId = parsed.sourceEvaluatorArtifactId;
367
- }
368
- } catch { /* use default */ }
369
- return { runId: `td-rollout-reviewer-${Date.now()}`, runtimeKind: 'test-double', startedAt: new Date().toISOString() };
370
- },
371
- onPollRun: (_runId: string) => ({
372
- runId: _runId,
373
- status: 'succeeded',
374
- startedAt: new Date().toISOString(),
375
- endedAt: new Date().toISOString(),
376
- }),
377
- onFetchOutput: (_runId: string) => ({
378
- runId: _runId,
379
- payload: {
380
- taskId,
381
- sourceEvaluatorArtifactId: capturedSourceEvaluatorArtifactId,
382
- review: {
383
- decision: 'approve_rollout',
384
- summary: 'Test rollout review summary',
385
- confidence: 0.9,
386
- requiredChanges: [],
387
- rolloutRisks: [],
388
- safetyChecks: ['Verify feature flag is properly configured'],
389
- },
390
- sourceTrace: {
391
- evaluatorArtifactId: capturedSourceEvaluatorArtifactId,
392
- },
393
- risks: [],
394
- generatedAt: new Date().toISOString(),
395
- },
396
- }),
397
- });
398
- }
399
- // dreamer / default
400
- return new TestDoubleRuntimeAdapter({
401
- onPollRun: (_runId: string) => ({
402
- runId: _runId,
403
- status: 'succeeded',
404
- startedAt: new Date().toISOString(),
405
- endedAt: new Date().toISOString(),
406
- }),
407
- onFetchOutput: (_runId: string) => ({
408
- runId: _runId,
409
- payload: {
410
- valid: true,
411
- taskId,
412
- candidates: [{
413
- candidateIndex: 0,
414
- badDecision: 'Ignored input validation requirement',
415
- betterDecision: 'Validate all inputs against schema before processing',
416
- rationale: 'Input validation prevents downstream errors and data corruption',
417
- confidence: 0.85,
418
- riskLevel: 'low',
419
- strategicPerspective: 'defensive-programming',
420
- }],
421
- contextRefs: [],
422
- generatedAt: new Date().toISOString(),
423
- },
424
- }),
425
- });
426
- }
427
-
428
- export async function handleRuntimeInternalizationRunOnce(opts: RunOnceOptions): Promise<void> {
429
- const workspaceDir = opts.workspace ? path.resolve(opts.workspace) : resolveWorkspaceDir();
430
- const runtimeKind = opts.runtime ?? 'config';
431
- const runnerKind = opts.runner ?? 'dreamer';
432
-
433
- // Resolve effective timeout (PRI-670): CLI flag > runtimeProfile.timeoutMs
434
- // (via the shared resolver, same value the auto-consumer now forwards) >
435
- // 300s default. Before, the profile timeout only reached the adapter and
436
- // the runner deadline was hardcoded 300s — slow/local models could never
437
- // finish dreamer/evaluator stages.
438
- const cliTimeoutMs = opts.timeoutMs;
439
- if (cliTimeoutMs !== undefined && (!Number.isFinite(cliTimeoutMs) || cliTimeoutMs <= 0)) {
440
- console.error(`Error: --timeout-ms must be a positive integer, got: ${opts.timeoutMs}`);
441
- process.exitCode = 1;
442
- return;
443
- }
444
- const FALLBACK_RUNNER_TIMEOUT_MS = 300_000;
445
-
446
- if (runtimeKind === 'test-double' && !opts.allowTestDouble) {
447
- console.error('Error: test-double runtime mutates real queue state (leases tasks, marks them succeeded with empty output).');
448
- console.error('Use --runtime test-double --allow-test-double to acknowledge this risk.');
449
- console.error('For production use, use --runtime config (reads from .pd/config.yaml) or --runtime pi-ai / openclaw-cli.');
450
- process.exitCode = 1;
451
- return;
452
- }
453
-
454
- if (!SUPPORTED_RUNNERS.has(runnerKind)) {
455
- console.error(`Error: unsupported runner kind: ${runnerKind}. Supported: ${[...SUPPORTED_RUNNERS].join(', ')}`);
456
- process.exitCode = 1;
457
- return;
458
- }
459
-
460
- // PRI-661: the evaluator's deterministic adversarial replay needs the
461
- // production gate context (workspace root + host tool registry from durable
462
- // provenance) — the SAME context the consumer cycle replays with. Refuse
463
- // BEFORE leasing any task (cli-5: no mutation on refusal) with the same
464
- // structured semantics as runtime-activation's code_tool_hook refusal.
465
- let evaluatorGateDeps: RefinerRuleHostGateDeps | undefined;
466
- let evaluatorHostSemanticContext: ArtificerHostSemanticContext | undefined;
467
- if (runnerKind === 'evaluator') {
468
- const evaluatorContext = createEvaluatorRuntimeContext({ workspaceDir });
469
- if (!evaluatorContext.ok) {
470
- const refused = {
471
- decision: 'refused',
472
- reason: evaluatorContext.reason,
473
- nextAction: evaluatorContext.nextAction,
474
- };
475
- if (opts.json) {
476
- console.log(JSON.stringify(refused, null, 2));
477
- } else {
478
- console.log(`Run-once: refused`);
479
- console.log(` reason: ${refused.reason}`);
480
- console.log(` nextAction: ${refused.nextAction}`);
481
- }
482
- process.exitCode = 1;
483
- return;
484
- }
485
- evaluatorGateDeps = evaluatorContext.gateDeps;
486
- // PRI-741 (review round): the projection derives from the SAME registry
487
- // snapshot the gateDeps were built from — never a second independent read
488
- // of the durable declaration (snapshot divergence would let the sandbox
489
- // and the parity case disagree on canonical kinds).
490
- evaluatorHostSemanticContext = buildArtificerHostSemanticContext(evaluatorContext.registry, evaluatorContext.hostKinds ?? []);
491
- }
492
-
493
- const stateManager = new RuntimeStateManager({ workspaceDir });
494
- await stateManager.initialize();
495
-
496
- // Issue 2: resolve effective config for feature-flag-aware runners
497
- // (e.g. `artificer_output_retry`). Mirrors rulehost-pipeline-runner.
498
- const configLoad = loadPdConfig(workspaceDir);
499
- const effectiveConfig: EffectivePdConfig | undefined = configLoad.ok ? configLoad.effective : configLoad.defaults;
500
-
501
- // PRI-714: resolve outputLanguage ONCE for every runner branch below —
502
- // before, only the scribe branch read the workspace language (PRI-336),
503
- // so dreamer/philosopher/artificer/evaluator/rollout_reviewer prompts
504
- // never carried the directive. readOutputLanguageFromWorkspace (the same
505
- // resolver the scribe branch uses) keeps the malformed-config degradation
506
- // semantics (ERR-002/ERR-009) on this path.
507
- const outputLangResult = readOutputLanguageFromWorkspace(workspaceDir);
508
- const outputLanguage: OutputLanguage | undefined = outputLangResult.outputLanguage;
509
-
510
- // PRI-670: profile timeout fallback for the runner deadline. PRI-719: the
511
- // profile resolves for the SELECTED RUNNER's agent binding — the shared
512
- // resolver used to read the diagnostician binding for every stage, silently
513
- // ignoring per-agent runtimeProfile declarations (EP002-R2 F4). On any
514
- // resolution error, fall back to the 300s default rather than refusing the
515
- // run: the flag-off/legacy behavior was 300s.
516
- // PRI-719 review: explicit run-once is a PEER execution path — its scope
517
- // is the internalization_full_chain flag, not agents[kind].enabled (the
518
- // shipped default disables evaluator/rolloutReviewer, which must not block
519
- // an explicit stage run). Same ignoreAgentEnabled semantics as the
520
- // auto-consumer; `enabled` keeps gating the diagnostician bridge.
521
- const runnerAgentName = AGENT_NAME_FOR_TASK_KIND[runnerKind];
522
- let profileTimeoutMs: number | undefined;
523
- if (effectiveConfig && runnerAgentName !== undefined) {
524
- const resolved = resolveRuntimeConfigForAgent(effectiveConfig, runnerAgentName, {
525
- getEnvVar: (name) => process.env[name],
526
- ignoreAgentEnabled: true,
527
- });
528
- if (!isRuntimeConfigError(resolved)) {
529
- profileTimeoutMs = resolved.timeoutMs;
530
- }
531
- }
532
- const effectiveTimeoutMs = cliTimeoutMs ?? profileTimeoutMs ?? FALLBACK_RUNNER_TIMEOUT_MS;
533
-
534
- try {
535
- const orchestrator = new InternalizationOrchestrator(
536
- { stateManager },
537
- { owner: OWNER, runtimeKind: RUNTIME_KIND, dryRun: true },
538
- );
539
-
540
- let wakeResult: WakeOnceResult = { decision: 'no_ready_tasks', reason: 'no_candidates', inspectedCount: 0 };
541
- try {
542
- wakeResult = await orchestrator.wakeOnce(runnerKind as PeerRunnerKind);
543
- } catch (err) {
544
- const message = err instanceof Error ? err.message : String(err);
545
- console.error(`Error: wake-once failed: ${message}`);
546
- process.exitCode = 1;
547
- return;
548
- }
549
-
550
- let runnerResult: DreamerRunnerResult | PhilosopherRunnerResult | ScribeRunnerResult | ArtificerRunnerResult | EvaluatorRunnerResult | RolloutReviewerRunnerResult | undefined = undefined;
551
- let skipReason: string | undefined = undefined;
552
-
553
- if (wakeResult.decision === 'would_lease') {
554
- if (wakeResult.taskKind !== runnerKind) {
555
- throw new Error(`Invariant violation: wakeOnce returned taskKind=${wakeResult.taskKind} but runnerKind=${runnerKind}`);
556
- }
557
-
558
- const eventEmitter = new StoreEventEmitter();
559
- const artifactStore = stateManager.piArtifactStore;
560
- const runtimeAdapter = resolveRuntimeAdapterFromConfig({
561
- runtimeKind,
562
- workspaceDir,
563
- runnerKind,
564
- // PRI-719: resolve the SELECTED runner's own agent binding so its
565
- // declared runtimeProfile governs the adapter — with the SAME
566
- // ignoreAgentEnabled peer semantics as the timeout resolution above
567
- // (declared profile == timeout profile == adapter profile).
568
- ...(runnerAgentName !== undefined ? { agentName: runnerAgentName, ignoreAgentEnabled: true } : {}),
569
- timeoutMs: cliTimeoutMs,
570
- allowTestDouble: true,
571
- testDoublePayloadBuilder: () => buildTestDoubleAdapter(runnerKind, wakeResult.taskId),
572
- // PRI-419: pass the L2 readers so the resolver can build an L2AgentLoopAdapter
573
- // when l2_dreamer is enabled. Only consumed for dreamer; harmless for other runners.
574
- l2ArtifactReader: artifactStore,
575
- l2StateDir: `${workspaceDir}/.state`,
576
- });
577
-
578
- try {
579
- if (runnerKind === 'dreamer') {
580
- const validator = new DefaultDreamerValidator();
581
- const runner = new DreamerRunner(
582
- { stateManager, runtimeAdapter, eventEmitter, validator, artifactStore },
583
- { owner: OWNER, runtimeKind: runtimeAdapter.kind(), pollIntervalMs: 100, timeoutMs: effectiveTimeoutMs, outputLanguage },
584
- );
585
- runnerResult = await runner.run(wakeResult.taskId);
586
- } else if (runnerKind === 'philosopher') {
587
- const validator = new DefaultPhilosopherValidator();
588
- const runner = new PhilosopherRunner(
589
- { stateManager, runtimeAdapter, eventEmitter, validator, artifactStore },
590
- { owner: OWNER, runtimeKind: runtimeAdapter.kind(), pollIntervalMs: 100, timeoutMs: effectiveTimeoutMs, outputLanguage },
591
- );
592
- runnerResult = await runner.run(wakeResult.taskId);
593
- } else if (runnerKind === 'scribe') {
594
- const validator = new DefaultScribeValidator();
595
- const runner = new ScribeRunner(
596
- { stateManager, runtimeAdapter, eventEmitter, validator, artifactStore },
597
- { owner: OWNER, runtimeKind: runtimeAdapter.kind(), pollIntervalMs: 100, timeoutMs: effectiveTimeoutMs, outputLanguage },
598
- );
599
- runnerResult = await runner.run(wakeResult.taskId);
600
- } else if (runnerKind === 'artificer') {
601
- const validator = new DefaultArtificerValidator();
602
- // PRI-741: artificer generation anchors on the workspace host
603
- // declaration (same durable provenance the evaluator gate uses).
604
- // Unresolvable provenance degrades OBSERVABLY (rc-9/EP-03) to a
605
- // prompt without the host block — never a silent wrong-host guess.
606
- const hostSemantics = resolveWorkspaceHostToolSemantics(workspaceDir);
607
- if (!hostSemantics.ok) {
608
- console.error(`[PD:run-once] artificer prompt without host tool semantics: ${hostSemantics.reason} — ${hostSemantics.nextAction}`);
609
- }
610
- const runner = new ArtificerRunner(
611
- { stateManager, runtimeAdapter, eventEmitter, validator, artifactStore },
612
- {
613
- owner: OWNER,
614
- runtimeKind: runtimeAdapter.kind(),
615
- pollIntervalMs: 100,
616
- timeoutMs: effectiveTimeoutMs,
617
- effectiveConfig,
618
- outputLanguage,
619
- ...(hostSemantics.ok
620
- ? { hostSemanticContext: buildArtificerHostSemanticContext(hostSemantics.registry, hostSemantics.hostKinds) }
621
- : {}),
622
- },
623
- );
624
- runnerResult = await runner.run(wakeResult.taskId);
625
- } else if (runnerKind === 'evaluator') {
626
- const validator = new DefaultEvaluatorValidator();
627
- // PRI-510 (DEFECT-004): use createEvaluatorRunnerDeps so the repair
628
- // loop is wired in this CLI path (EP-02: production path must
629
- // invoke core logic, not just construct the runner).
630
- const runner = new EvaluatorRunner(
631
- createEvaluatorRunnerDeps({
632
- stateManager,
633
- runtimeAdapter,
634
- eventEmitter,
635
- validator,
636
- artifactStore,
637
- workspaceDir,
638
- }),
639
- // PRI-661: gateDeps resolved ABOVE via the ONE
640
- // createEvaluatorRuntimeContext builder (durable workspace
641
- // provenance + workspace root) — replay/production parity with
642
- // the consumer cycle. Options argument (2nd), never deps (1st).
643
- {
644
- owner: OWNER,
645
- runtimeKind: runtimeAdapter.kind(),
646
- pollIntervalMs: 100,
647
- timeoutMs: effectiveTimeoutMs,
648
- effectiveConfig,
649
- gateDeps: evaluatorGateDeps,
650
- // PRI-741: host-name parity replay case (same provenance as
651
- // gateDeps; undefined = observable skip event in the runner).
652
- ...(evaluatorHostSemanticContext !== undefined ? { hostSemanticContext: evaluatorHostSemanticContext } : {}),
653
- outputLanguage,
654
- },
655
- );
656
- runnerResult = await runner.run(wakeResult.taskId);
657
- } else if (runnerKind === 'rollout_reviewer') {
658
- const validator = new DefaultRolloutReviewerValidator();
659
- // PRI-708: canonical rollout revision routing — the SAME reopen
660
- // callback (causeId-idempotent reopenTaskForRevision) the consumer
661
- // cycle injects, so a manual needs_revision here reopens the
662
- // scribe/artificer revision target instead of dead-ending in the
663
- // recovery-only `rollout_revision_routing_not_wired` NHR (INV-04:
664
- // needs_revision never enters the approval queue).
665
- // PRI-713: canonical activation dispatch — the SAME
666
- // dispatchActivation (approve_rollout → ActivationDispatcher:
667
- // PRI-811 Phase B — every recommendation enqueues approvals.pending;
668
- // activation only after Owner approval) the
669
- // consumer cycle injects from this one factory, so a manual
670
- // approve_rollout completes governance instead of dead-ending in
671
- // the recovery-only `rollout_dispatch_not_wired` NHR. The Owner
672
- // gate is NOT bypassed: all channels enqueue
673
- // approvals.pending inside the dispatcher. toolSemantics comes
674
- // from the durable workspace provenance (PRI-661 pattern — same
675
- // resolver the evaluator context uses); when no declaration is
676
- // persisted the dispatch wires without it, mirroring the consumer
677
- // cycle's optional host port, with the structured reason surfaced
678
- // on stderr (never a silent baseline fallback).
679
- const dispatchSemantics = resolveWorkspaceHostToolSemantics(workspaceDir);
680
- if (!dispatchSemantics.ok) {
681
- console.error(`[PD:run-once] rollout dispatch without host tool semantics: ${dispatchSemantics.reason} — ${dispatchSemantics.nextAction}`);
682
- }
683
- const { dispatchActivation, reopenRevisionTarget } = createRolloutGovernanceDeps(
684
- workspaceDir,
685
- orchestrator,
686
- dispatchSemantics.ok ? { toolSemantics: dispatchSemantics.registry } : {},
687
- );
688
- const runner = new RolloutReviewerRunner(
689
- { stateManager, runtimeAdapter, eventEmitter, validator, artifactStore, dispatchActivation, reopenRevisionTarget },
690
- { owner: OWNER, runtimeKind: runtimeAdapter.kind(), pollIntervalMs: 100, timeoutMs: effectiveTimeoutMs, outputLanguage },
691
- );
692
- runnerResult = await runner.run(wakeResult.taskId);
693
- } else {
694
- skipReason = 'no_runner_implemented';
695
- }
696
- } catch (runErr) {
697
- console.error(`Error: runner crashed: ${runErr instanceof Error ? runErr.message : String(runErr)}`);
698
- try {
699
- const task = await stateManager.getTask(wakeResult.taskId);
700
- const failureReason = `Unhandled runner crash: ${runErr instanceof Error ? runErr.message : String(runErr)}`;
701
- if (task && stateManager.getRetryPolicy().shouldRetry(task)) {
702
- await stateManager.markTaskRetryWait(wakeResult.taskId, 'execution_failed', failureReason);
703
- } else {
704
- await stateManager.markTaskFailed(wakeResult.taskId, 'execution_failed', failureReason);
705
- }
706
- } catch (dbErr) {
707
- console.error(`Error: failed to update task state in DB: ${String(dbErr)}`);
708
- }
709
- throw runErr;
710
- }
711
- }
712
-
713
- const output = buildOutput(wakeResult, runnerResult, skipReason);
714
- output.runnerKind = runnerKind;
715
- output.effectiveTimeoutMs = effectiveTimeoutMs;
716
- if (runnerResult?.failureReason?.includes('timeoutSource=')) {
717
- const match = /timeoutSource=(\w+)/.exec(runnerResult.failureReason);
718
- if (match) {
719
- const [, source] = match;
720
- output.timeoutSource = source;
721
- }
722
- }
723
-
724
- // Default: auto-enqueue successor on runner success (unless opted out via --no-enqueue-next)
725
- const shouldEnqueue = opts.enqueueNext !== false;
726
-
727
- if (shouldEnqueue && runnerResult?.status === 'succeeded' && wakeResult.decision === 'would_lease') {
728
- output.successorEnqueueAttempted = true;
729
- try {
730
- const commitResult = await orchestrator.commitNextTaskProposal(wakeResult.taskId);
731
- output.enqueueDecision = commitResult.decision;
732
- output.successorTasksCreated = 0;
733
- output.successorTaskIds = [];
734
- if (commitResult.decision === 'successor_created' || commitResult.decision === 'successor_exists') {
735
- output.successorKind = commitResult.successorKind;
736
- output.successorTaskIds.push(commitResult.successorTaskId);
737
- output.successorTasksCreated = commitResult.decision === 'successor_created' ? 1 : 0;
738
- } else if (commitResult.decision === 'no_successor') {
739
- output.enqueueReason = commitResult.reason;
740
- output.nextAction = 'No successor in job graph for this task kind and channel. This is expected for terminal runners.';
741
- } else {
742
- output.enqueueReason = `Unexpected commitNextTaskProposal decision: ${commitResult.decision}`;
743
- output.nextAction = 'Investigate orchestrator logic; re-run with --no-enqueue-next to skip auto-enqueue.';
744
- }
745
- } catch (enqueueErr: unknown) {
746
- const enqueueMessage = enqueueErr instanceof Error ? enqueueErr.message : String(enqueueErr);
747
- output.enqueueDecision = 'enqueue_failed';
748
- output.enqueueReason = enqueueMessage;
749
- output.successorTasksCreated = 0;
750
- output.successorTaskIds = [];
751
- output.nextAction = `Runner succeeded but successor enqueue failed. Run: pd runtime internalization enqueue-successors --workspace ${workspaceDir} --confirm`;
752
- // Runner success is real; downgrade to partial_success, not error
753
- if (output.decision === 'would_lease') {
754
- output.decision = 'partial_success';
755
- }
756
- }
757
- } else if (!shouldEnqueue) {
758
- output.successorEnqueueAttempted = false;
759
- if (runnerResult?.status === 'succeeded' && wakeResult.decision === 'would_lease') {
760
- output.nextAction = 'Successor auto-enqueue was skipped (--no-enqueue-next). To enqueue: pd runtime internalization enqueue-successors --confirm';
761
- }
762
- }
763
-
764
- if (opts.json) {
765
- console.log(JSON.stringify(output, null, 2));
766
- } else {
767
- console.log(formatTextOutput(output));
768
- }
769
-
770
- if (wakeResult.decision === 'no_ready_tasks' || wakeResult.decision === 'lease_conflict') {
771
- process.exitCode = 1;
772
- }
773
- } catch (err: unknown) {
774
- const message = err instanceof Error ? err.message : String(err);
775
- const isConfigError = err instanceof ConfigResolutionError;
776
- if (opts.json) {
777
- console.log(JSON.stringify({
778
- decision: isConfigError ? 'config_error' : 'runtime_error',
779
- reason: message,
780
- nextAction: isConfigError
781
- ? 'Fix the .pd/config.yaml runtime profile, or use --runtime pi-ai / openclaw-cli with explicit flags'
782
- : 'Check runner logs and workspace state; re-run with --runtime test-double to isolate',
783
- }, null, 2));
784
- } else {
785
- console.error(`Error: ${message}`);
786
- }
787
- process.exitCode = 1;
788
- } finally {
789
- await stateManager.close();
790
- }
791
- }