@principles/pd-cli 1.152.11 → 1.152.13

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 (303) hide show
  1. package/dist/commands/candidate.d.ts +3 -3
  2. package/dist/commands/candidate.d.ts.map +1 -1
  3. package/dist/commands/candidate.js +9 -21
  4. package/dist/commands/candidate.js.map +1 -1
  5. package/dist/index.js +0 -0
  6. package/dist/services/rulehost-pipeline-runner.d.ts.map +1 -1
  7. package/dist/services/rulehost-pipeline-runner.js +4 -17
  8. package/dist/services/rulehost-pipeline-runner.js.map +1 -1
  9. package/package.json +13 -7
  10. package/dist/commands/__tests__/intent-flag-wiring.test.d.ts +0 -9
  11. package/dist/commands/__tests__/intent-flag-wiring.test.d.ts.map +0 -1
  12. package/dist/commands/__tests__/intent-flag-wiring.test.js +0 -237
  13. package/dist/commands/__tests__/intent-flag-wiring.test.js.map +0 -1
  14. package/dist/commands/__tests__/legacy-cleanup.test.d.ts +0 -18
  15. package/dist/commands/__tests__/legacy-cleanup.test.d.ts.map +0 -1
  16. package/dist/commands/__tests__/legacy-cleanup.test.js +0 -467
  17. package/dist/commands/__tests__/legacy-cleanup.test.js.map +0 -1
  18. package/dist/commands/__tests__/mvp-smoke.test.d.ts +0 -15
  19. package/dist/commands/__tests__/mvp-smoke.test.d.ts.map +0 -1
  20. package/dist/commands/__tests__/mvp-smoke.test.js +0 -262
  21. package/dist/commands/__tests__/mvp-smoke.test.js.map +0 -1
  22. package/dist/commands/__tests__/pain-retry-maxTokens-flag.test.d.ts +0 -2
  23. package/dist/commands/__tests__/pain-retry-maxTokens-flag.test.d.ts.map +0 -1
  24. package/dist/commands/__tests__/pain-retry-maxTokens-flag.test.js +0 -60
  25. package/dist/commands/__tests__/pain-retry-maxTokens-flag.test.js.map +0 -1
  26. package/dist/commands/__tests__/rulecode-flag-wiring.test.d.ts +0 -21
  27. package/dist/commands/__tests__/rulecode-flag-wiring.test.d.ts.map +0 -1
  28. package/dist/commands/__tests__/rulecode-flag-wiring.test.js +0 -186
  29. package/dist/commands/__tests__/rulecode-flag-wiring.test.js.map +0 -1
  30. package/dist/commands/__tests__/rulecode-handler.test.d.ts +0 -16
  31. package/dist/commands/__tests__/rulecode-handler.test.d.ts.map +0 -1
  32. package/dist/commands/__tests__/rulecode-handler.test.js +0 -285
  33. package/dist/commands/__tests__/rulecode-handler.test.js.map +0 -1
  34. package/dist/commands/__tests__/run-rulehost-flag-wiring.test.d.ts +0 -24
  35. package/dist/commands/__tests__/run-rulehost-flag-wiring.test.d.ts.map +0 -1
  36. package/dist/commands/__tests__/run-rulehost-flag-wiring.test.js +0 -232
  37. package/dist/commands/__tests__/run-rulehost-flag-wiring.test.js.map +0 -1
  38. package/dist/commands/__tests__/runtime-activation-nextaction.test.d.ts +0 -15
  39. package/dist/commands/__tests__/runtime-activation-nextaction.test.d.ts.map +0 -1
  40. package/dist/commands/__tests__/runtime-activation-nextaction.test.js +0 -73
  41. package/dist/commands/__tests__/runtime-activation-nextaction.test.js.map +0 -1
  42. package/dist/commands/__tests__/runtime-probe-config.test.d.ts +0 -20
  43. package/dist/commands/__tests__/runtime-probe-config.test.d.ts.map +0 -1
  44. package/dist/commands/__tests__/runtime-probe-config.test.js +0 -389
  45. package/dist/commands/__tests__/runtime-probe-config.test.js.map +0 -1
  46. package/dist/commands/__tests__/telemetry-flag-wiring.test.d.ts +0 -9
  47. package/dist/commands/__tests__/telemetry-flag-wiring.test.d.ts.map +0 -1
  48. package/dist/commands/__tests__/telemetry-flag-wiring.test.js +0 -76
  49. package/dist/commands/__tests__/telemetry-flag-wiring.test.js.map +0 -1
  50. package/dist/commands/__tests__/version.test.d.ts +0 -2
  51. package/dist/commands/__tests__/version.test.d.ts.map +0 -1
  52. package/dist/commands/__tests__/version.test.js +0 -238
  53. package/dist/commands/__tests__/version.test.js.map +0 -1
  54. package/dist/commands/runtime-uat.guard.test.d.ts +0 -2
  55. package/dist/commands/runtime-uat.guard.test.d.ts.map +0 -1
  56. package/dist/commands/runtime-uat.guard.test.js +0 -153
  57. package/dist/commands/runtime-uat.guard.test.js.map +0 -1
  58. package/dist/services/__tests__/cli-output.test.d.ts +0 -18
  59. package/dist/services/__tests__/cli-output.test.d.ts.map +0 -1
  60. package/dist/services/__tests__/cli-output.test.js +0 -103
  61. package/dist/services/__tests__/cli-output.test.js.map +0 -1
  62. package/dist/services/__tests__/evaluator-runner-deps.test.d.ts +0 -2
  63. package/dist/services/__tests__/evaluator-runner-deps.test.d.ts.map +0 -1
  64. package/dist/services/__tests__/evaluator-runner-deps.test.js +0 -343
  65. package/dist/services/__tests__/evaluator-runner-deps.test.js.map +0 -1
  66. package/dist/services/__tests__/rulehost-readiness.test.d.ts +0 -2
  67. package/dist/services/__tests__/rulehost-readiness.test.d.ts.map +0 -1
  68. package/dist/services/__tests__/rulehost-readiness.test.js +0 -311
  69. package/dist/services/__tests__/rulehost-readiness.test.js.map +0 -1
  70. package/dist/services/__tests__/runtime-adapter-resolver.test.d.ts +0 -18
  71. package/dist/services/__tests__/runtime-adapter-resolver.test.d.ts.map +0 -1
  72. package/dist/services/__tests__/runtime-adapter-resolver.test.js +0 -673
  73. package/dist/services/__tests__/runtime-adapter-resolver.test.js.map +0 -1
  74. package/dist/utils/production-workspace-guard.test.d.ts +0 -2
  75. package/dist/utils/production-workspace-guard.test.d.ts.map +0 -1
  76. package/dist/utils/production-workspace-guard.test.js +0 -137
  77. package/dist/utils/production-workspace-guard.test.js.map +0 -1
  78. package/scripts/llm-dogfood.ts +0 -456
  79. package/scripts/migrate-illegal-expected-decision.ts +0 -252
  80. package/src/commands/__tests__/intent-flag-wiring.test.ts +0 -282
  81. package/src/commands/__tests__/legacy-cleanup.test.ts +0 -602
  82. package/src/commands/__tests__/mvp-smoke.test.ts +0 -300
  83. package/src/commands/__tests__/pain-retry-maxTokens-flag.test.ts +0 -73
  84. package/src/commands/__tests__/rulecode-flag-wiring.test.ts +0 -237
  85. package/src/commands/__tests__/rulecode-handler.test.ts +0 -369
  86. package/src/commands/__tests__/run-rulehost-flag-wiring.test.ts +0 -292
  87. package/src/commands/__tests__/runtime-activation-nextaction.test.ts +0 -81
  88. package/src/commands/__tests__/runtime-probe-config.test.ts +0 -432
  89. package/src/commands/__tests__/telemetry-flag-wiring.test.ts +0 -84
  90. package/src/commands/__tests__/version.test.ts +0 -251
  91. package/src/commands/admission-gate.ts +0 -30
  92. package/src/commands/artifact.ts +0 -82
  93. package/src/commands/build-trajectory-evidence.ts +0 -298
  94. package/src/commands/candidate.ts +0 -1260
  95. package/src/commands/codex-ingest-catchup.ts +0 -114
  96. package/src/commands/codex-ingest-quarantine.ts +0 -127
  97. package/src/commands/codex-reconcile.ts +0 -84
  98. package/src/commands/codex-setup.ts +0 -476
  99. package/src/commands/codex-worker.ts +0 -185
  100. package/src/commands/command-helpers.ts +0 -24
  101. package/src/commands/config-doctor.ts +0 -193
  102. package/src/commands/console.ts +0 -797
  103. package/src/commands/context.ts +0 -72
  104. package/src/commands/demo-story-a.ts +0 -241
  105. package/src/commands/diagnose.ts +0 -756
  106. package/src/commands/errors-list.ts +0 -441
  107. package/src/commands/evolution-tasks-list.ts +0 -48
  108. package/src/commands/evolution-tasks-show.ts +0 -62
  109. package/src/commands/flow.ts +0 -60
  110. package/src/commands/health-codex.ts +0 -576
  111. package/src/commands/health.ts +0 -315
  112. package/src/commands/history.ts +0 -63
  113. package/src/commands/intent.ts +0 -457
  114. package/src/commands/legacy-cleanup.ts +0 -531
  115. package/src/commands/legacy-import.ts +0 -104
  116. package/src/commands/mvp-smoke.ts +0 -160
  117. package/src/commands/pain-evidence.ts +0 -226
  118. package/src/commands/pain-list.ts +0 -239
  119. package/src/commands/pain-record.ts +0 -612
  120. package/src/commands/pain-retry.ts +0 -916
  121. package/src/commands/principles-stats.ts +0 -700
  122. package/src/commands/proven-channel-baseline.ts +0 -115
  123. package/src/commands/quality-scorecard.ts +0 -272
  124. package/src/commands/remediation-output.ts +0 -66
  125. package/src/commands/rulecode.ts +0 -465
  126. package/src/commands/run.ts +0 -89
  127. package/src/commands/runtime-activation.ts +0 -1629
  128. package/src/commands/runtime-artifact-repair.ts +0 -524
  129. package/src/commands/runtime-canary.ts +0 -395
  130. package/src/commands/runtime-compatibility-scan.ts +0 -105
  131. package/src/commands/runtime-diagnostics-export.ts +0 -229
  132. package/src/commands/runtime-features.ts +0 -153
  133. package/src/commands/runtime-gfi-snapshot.ts +0 -135
  134. package/src/commands/runtime-health-snapshot.ts +0 -108
  135. package/src/commands/runtime-init.ts +0 -429
  136. package/src/commands/runtime-internalization-enqueue-successors.ts +0 -530
  137. package/src/commands/runtime-internalization-integrity-repair.ts +0 -79
  138. package/src/commands/runtime-internalization-integrity.ts +0 -107
  139. package/src/commands/runtime-internalization-queue.ts +0 -135
  140. package/src/commands/runtime-internalization-retry.ts +0 -191
  141. package/src/commands/runtime-internalization-run-once.ts +0 -791
  142. package/src/commands/runtime-internalization-run-rulehost.ts +0 -749
  143. package/src/commands/runtime-internalization-wake-once.ts +0 -87
  144. package/src/commands/runtime-pain-flood-simulation.ts +0 -121
  145. package/src/commands/runtime-pruning.ts +0 -438
  146. package/src/commands/runtime-recovery-failed-tasks.ts +0 -258
  147. package/src/commands/runtime-recovery.ts +0 -109
  148. package/src/commands/runtime-synthetic-baseline.ts +0 -70
  149. package/src/commands/runtime-uat.guard.test.ts +0 -175
  150. package/src/commands/runtime-uat.ts +0 -380
  151. package/src/commands/runtime.ts +0 -473
  152. package/src/commands/samples-list.ts +0 -39
  153. package/src/commands/samples-review.ts +0 -36
  154. package/src/commands/task.ts +0 -271
  155. package/src/commands/telemetry.ts +0 -349
  156. package/src/commands/trace.ts +0 -174
  157. package/src/commands/trajectory-db-unavailable.ts +0 -19
  158. package/src/commands/trajectory.ts +0 -64
  159. package/src/commands/version.ts +0 -49
  160. package/src/config-reader.ts +0 -122
  161. package/src/index.ts +0 -1276
  162. package/src/legacy/legacy-import.ts +0 -179
  163. package/src/legacy/session-history-import.ts +0 -203
  164. package/src/resolve-workspace.ts +0 -106
  165. package/src/services/__tests__/cli-output.test.ts +0 -130
  166. package/src/services/__tests__/evaluator-runner-deps.test.ts +0 -382
  167. package/src/services/__tests__/rulehost-readiness.test.ts +0 -363
  168. package/src/services/__tests__/runtime-adapter-resolver.test.ts +0 -793
  169. package/src/services/cli-output.ts +0 -95
  170. package/src/services/config-doctor.ts +0 -697
  171. package/src/services/console-launcher.ts +0 -537
  172. package/src/services/demo-rule-compiler.ts +0 -40
  173. package/src/services/demo-story-a-runner.ts +0 -471
  174. package/src/services/mainline-snapshot-assembler.ts +0 -579
  175. package/src/services/pain-flood-simulation-runner.ts +0 -462
  176. package/src/services/pd-config-loader.ts +0 -433
  177. package/src/services/proven-channel-baseline-runner.ts +0 -157
  178. package/src/services/quality-scorecard/data-extractor.ts +0 -150
  179. package/src/services/quality-scorecard/local-evaluator.ts +0 -142
  180. package/src/services/quality-scorecard/strong-model-gate.ts +0 -202
  181. package/src/services/resolve-runtime-from-pd-config.ts +0 -230
  182. package/src/services/rulehost-pipeline-runner.ts +0 -1216
  183. package/src/services/rulehost-readiness.ts +0 -326
  184. package/src/services/runtime-adapter-resolver.ts +0 -364
  185. package/src/services/synthetic-baseline-runner.ts +0 -400
  186. package/src/services/version-report.ts +0 -253
  187. package/src/services/workspace-tool-semantics.ts +0 -26
  188. package/src/utils/path-security.ts +0 -96
  189. package/src/utils/production-workspace-guard.test.ts +0 -157
  190. package/src/utils/production-workspace-guard.ts +0 -210
  191. package/tests/bdd/cli-contract.steps.ts +0 -346
  192. package/tests/bdd/principles-stats.steps.ts +0 -211
  193. package/tests/bdd/support/gherkin-loader.ts +0 -147
  194. package/tests/bdd/support/repo-root.ts +0 -62
  195. package/tests/bdd/support/vitest-bdd.ts +0 -179
  196. package/tests/commands/admission-gate-coverage.test.ts +0 -79
  197. package/tests/commands/build-trajectory-evidence.test.ts +0 -508
  198. package/tests/commands/candidate-audit-repair.test.ts +0 -421
  199. package/tests/commands/candidate-intake.test.ts +0 -732
  200. package/tests/commands/candidate-internalization-backfill.test.ts +0 -548
  201. package/tests/commands/candidate-internalize-lineage.test.ts +0 -565
  202. package/tests/commands/candidate-internalize.test.ts +0 -299
  203. package/tests/commands/candidate-route.test.ts +0 -329
  204. package/tests/commands/candidate-show.test.ts +0 -95
  205. package/tests/commands/cli-command-tree.test.ts +0 -144
  206. package/tests/commands/cli-help-snapshot.test.ts +0 -155
  207. package/tests/commands/cli-skill-contract.test.ts +0 -121
  208. package/tests/commands/codex-consent-reversibility.steps.test.ts +0 -299
  209. package/tests/commands/codex-ingest-quarantine.test.ts +0 -136
  210. package/tests/commands/codex-setup.test.ts +0 -297
  211. package/tests/commands/codex-worker-daemon.test.ts +0 -95
  212. package/tests/commands/codex-worker-registration.test.ts +0 -207
  213. package/tests/commands/config-doctor.test.ts +0 -336
  214. package/tests/commands/console-launcher-edge-cases.test.ts +0 -388
  215. package/tests/commands/console-open.test.ts +0 -1381
  216. package/tests/commands/context.test.ts +0 -114
  217. package/tests/commands/demo-story-a.test.ts +0 -318
  218. package/tests/commands/diagnose.test.ts +0 -1803
  219. package/tests/commands/errors-list.test.ts +0 -679
  220. package/tests/commands/evolution-tasks-list.test.ts +0 -41
  221. package/tests/commands/evolution-tasks-show.test.ts +0 -46
  222. package/tests/commands/health-codex.test.ts +0 -349
  223. package/tests/commands/health-host-wiring.test.ts +0 -76
  224. package/tests/commands/health-reliability.test.ts +0 -99
  225. package/tests/commands/health.test.ts +0 -413
  226. package/tests/commands/intent.test.ts +0 -321
  227. package/tests/commands/legacy-cleanup.test.ts +0 -148
  228. package/tests/commands/pain-evidence.test.ts +0 -518
  229. package/tests/commands/pain-list.test.ts +0 -219
  230. package/tests/commands/pain-record-async.test.ts +0 -335
  231. package/tests/commands/pain-record-session-parser.test.ts +0 -228
  232. package/tests/commands/pain-record.test.ts +0 -851
  233. package/tests/commands/pain-retry.test.ts +0 -1121
  234. package/tests/commands/plugin-config-resolution-cutover.test.ts +0 -229
  235. package/tests/commands/pri-393-runtime-config-unification.test.ts +0 -443
  236. package/tests/commands/principles-stats-wiring.test.ts +0 -135
  237. package/tests/commands/principles-stats.test.ts +0 -274
  238. package/tests/commands/product-path-regression.test.ts +0 -86
  239. package/tests/commands/proven-channel-baseline.test.ts +0 -441
  240. package/tests/commands/rulecode.test.ts +0 -177
  241. package/tests/commands/run-rulehost-handler.test.ts +0 -908
  242. package/tests/commands/runtime-activation-approve-flag-wiring.test.ts +0 -227
  243. package/tests/commands/runtime-activation-deactivate-flag-wiring.test.ts +0 -167
  244. package/tests/commands/runtime-activation-dispatch-flag-wiring.test.ts +0 -262
  245. package/tests/commands/runtime-activation-governance-audit.test.ts +0 -95
  246. package/tests/commands/runtime-activation-list-flag-wiring.test.ts +0 -193
  247. package/tests/commands/runtime-activation-promote-flag-wiring.test.ts +0 -248
  248. package/tests/commands/runtime-activation-shadow-telemetry.test.ts +0 -130
  249. package/tests/commands/runtime-activation.test.ts +0 -2052
  250. package/tests/commands/runtime-artifact-repair-registration.test.ts +0 -74
  251. package/tests/commands/runtime-artifact-repair.test.ts +0 -404
  252. package/tests/commands/runtime-canary.test.ts +0 -430
  253. package/tests/commands/runtime-compatibility-scan.test.ts +0 -146
  254. package/tests/commands/runtime-diagnostics-export.test.ts +0 -175
  255. package/tests/commands/runtime-features.test.ts +0 -249
  256. package/tests/commands/runtime-health-snapshot.test.ts +0 -358
  257. package/tests/commands/runtime-init-empty-workspace.test.ts +0 -252
  258. package/tests/commands/runtime-init.test.ts +0 -420
  259. package/tests/commands/runtime-internalization-enqueue-successors.test.ts +0 -782
  260. package/tests/commands/runtime-internalization-integrity-repair.test.ts +0 -239
  261. package/tests/commands/runtime-internalization-integrity.test.ts +0 -140
  262. package/tests/commands/runtime-internalization-queue.test.ts +0 -380
  263. package/tests/commands/runtime-internalization-retry-owner-authority.test.ts +0 -431
  264. package/tests/commands/runtime-internalization-run-once-evaluator-parity.test.ts +0 -269
  265. package/tests/commands/runtime-internalization-run-once-language.test.ts +0 -303
  266. package/tests/commands/runtime-internalization-run-once-real-config.test.ts +0 -237
  267. package/tests/commands/runtime-internalization-run-once-rollout-parity.test.ts +0 -706
  268. package/tests/commands/runtime-internalization-run-once.test.ts +0 -1791
  269. package/tests/commands/runtime-internalization-wake-once.test.ts +0 -171
  270. package/tests/commands/runtime-internalization.test.ts +0 -53
  271. package/tests/commands/runtime-pain-flood-simulation.test.ts +0 -418
  272. package/tests/commands/runtime-pruning.test.ts +0 -694
  273. package/tests/commands/runtime-recovery-failed-tasks.test.ts +0 -328
  274. package/tests/commands/runtime-recovery.test.ts +0 -120
  275. package/tests/commands/runtime-synthetic-baseline.test.ts +0 -249
  276. package/tests/commands/runtime-uat.test.ts +0 -397
  277. package/tests/commands/runtime.test.ts +0 -392
  278. package/tests/commands/samples-list.test.ts +0 -43
  279. package/tests/commands/samples-review.test.ts +0 -41
  280. package/tests/commands/task.test.ts +0 -153
  281. package/tests/commands/telemetry.test.ts +0 -190
  282. package/tests/commands/trace.test.ts +0 -316
  283. package/tests/config-reader.test.ts +0 -143
  284. package/tests/e2e/candidate-intake-e2e.test.ts +0 -338
  285. package/tests/e2e/cli-full-flow.test.ts +0 -233
  286. package/tests/e2e/cross-package-acceptance.test.ts +0 -635
  287. package/tests/helpers/pd-cli-path.ts +0 -5
  288. package/tests/pd-cli-smoke.test.ts +0 -13
  289. package/tests/resolve-workspace.test.ts +0 -196
  290. package/tests/services/config-doctor-signal-health.test.ts +0 -109
  291. package/tests/services/console-launcher.test.ts +0 -114
  292. package/tests/services/demo-rule-compiler.test.ts +0 -242
  293. package/tests/services/mainline-snapshot-assembler.test.ts +0 -572
  294. package/tests/services/pd-config-loader.test.ts +0 -505
  295. package/tests/services/proven-channel-baseline-runner.test.ts +0 -30
  296. package/tests/services/quality-scorecard/strong-model-gate.test.ts +0 -133
  297. package/tests/services/resolve-runtime-from-pd-config.test.ts +0 -485
  298. package/tests/services/rulehost-pipeline-e2e.test.ts +0 -538
  299. package/tests/services/rulehost-pipeline-runner.test.ts +0 -1175
  300. package/tests/services/workspace-tool-semantics.test.ts +0 -76
  301. package/tests/utils/path-security.test.ts +0 -180
  302. package/tsconfig.json +0 -26
  303. package/vitest.config.ts +0 -9
@@ -1,576 +0,0 @@
1
- /**
2
- * pd health --host codex command implementation — Codex Governance Closure
3
- * Slice D (PRI-625; SPEC rev 2 §15 health surface).
4
- *
5
- * Reports the §15 Owner-experience surface for one workspace:
6
- * - adapter/runtime versions + the G1 ingestion minimum Codex version;
7
- * - workspace init (config resolution), hook trust, dual registration;
8
- * - BOTH flag states (host.codex, codex_conversation_ingestion);
9
- * - consent state (decision metadata only — no captured text, ever);
10
- * - worker mode (no Companion ⇒ `manual_action_required`, never auto-closure);
11
- * - per-rollout checkpoints with completeness (incomplete tail / degradation)
12
- * and bounded byte lag against the live transcript file (stat only);
13
- * - operational/promoted/quarantined counts + next expiry + last observation;
14
- * - admission counts incl. admitted-pain-without-task + promotion tails;
15
- * - Diagnostician task counts (pending/leased/retry_wait/needs_human_review);
16
- * - §15 `ready` semantics — "unknown is not reported as healthy".
17
- *
18
- * Read-only throughout: this command never mutates workspace state and never
19
- * opens a transcript (file SIZE stat only, never content).
20
- *
21
- * CLI gate compliance:
22
- * - cli-1: --json outputs exactly one parseable JSON object on stdout.
23
- * - cli-2: exit paths stop execution.
24
- * - cli-5: failure paths do not mutate state (read-only throughout).
25
- * - cli-6: every degraded/unknown section carries reason + nextAction.
26
- */
27
- import * as fs from 'fs';
28
- import * as path from 'path';
29
- import * as os from 'os';
30
- import { createRequire } from 'module';
31
- import { resolveWorkspaceDir } from '../resolve-workspace.js';
32
- import {
33
- loadPdConfigForPlugin,
34
- resolveNearestPdWorkspace,
35
- readCodexIngestionConsent,
36
- deriveCodexIngestionConsentState,
37
- listGovernanceCheckpoints,
38
- readGovernanceObservationStats,
39
- readGovernanceAdmissionCounts,
40
- detectLegacyCodexHookRegistration,
41
- CODEX_INGESTION_DISCLOSURE_VERSION,
42
- } from '@principles/host-runtime';
43
- import {
44
- computeCodexWorkerStatusMode,
45
- locateCodexTranscriptByRolloutIdentity,
46
- CODEX_INGESTION_MIN_VERSION,
47
- CODEX_INGESTION_VERIFIED_VERSION,
48
- } from '@principles/codex-adapter';
49
- import { getInstallLayoutPaths, parseInstallManifest } from '@principles/install-layout';
50
- import { SqliteConnection, SqliteTaskStore, computeFeatureFlagsFromConfig, isFeatureEnabled } from '@principles/core/runtime-v2';
51
-
52
- const require = createRequire(import.meta.url);
53
-
54
- interface CodexHealthOptions {
55
- workspace?: string;
56
- json?: boolean;
57
- }
58
-
59
- type Degradable<T> = T | { reason: string; nextAction: string };
60
-
61
- interface CodexHealthReport {
62
- generatedAt: string;
63
- host: 'codex';
64
- workspace: string;
65
- adapterVersion: string;
66
- runtimeVersion: string;
67
- codexIngestionMinVersion: string;
68
- /** G1-verified Codex version (the frozen contract fixtures come from this CLI). */
69
- codexIngestionVerifiedVersion: string;
70
- featureFlag: {
71
- name: 'host.codex';
72
- enabled: boolean;
73
- source: 'user_config' | 'defaults' | 'malformed';
74
- reason?: string;
75
- nextAction?: string;
76
- };
77
- ingestionFlag: Degradable<{
78
- name: 'codex_conversation_ingestion';
79
- enabled: boolean;
80
- source: 'user_config' | 'defaults' | 'malformed';
81
- }>;
82
- consent: Degradable<{
83
- state: 'granted' | 'revoked' | 'pending' | 'failed' | 'not_present' | 'flag_on_without_grant';
84
- decidedAt?: string;
85
- decidedVia?: string;
86
- disclosureVersion?: string;
87
- disclosureStale: boolean;
88
- }>;
89
- workspaceInit: Degradable<{ initialized: boolean }>;
90
- hooksTrust: {
91
- detectable: boolean;
92
- trusted?: boolean;
93
- reason?: string;
94
- nextAction?: string;
95
- };
96
- dualRegistration: {
97
- detected: boolean;
98
- legacyAsyncPostToolUse?: boolean;
99
- globalHooksPath?: string;
100
- pluginHooksPath?: string;
101
- reason?: string;
102
- nextAction?: string;
103
- };
104
- worker: {
105
- mode: 'ready' | 'manual_action_required' | 'paused' | 'degraded';
106
- registeredInInstallManifest: boolean;
107
- reason?: string;
108
- nextAction?: string;
109
- };
110
- rollouts: Degradable<{
111
- checkpoints: {
112
- rolloutIdentity: string;
113
- byteOffset: number;
114
- lastOrdinal: number;
115
- incompleteTail: boolean;
116
- lastDegradationReason: string | null;
117
- updatedAt: string;
118
- /** bytes past the checkpoint in the live transcript file; null = undetectable */
119
- lagBytes: number | null;
120
- }[];
121
- lagUndetectable: boolean;
122
- }>;
123
- observations: Degradable<{
124
- operational: number;
125
- promoted: number;
126
- quarantined: number;
127
- terminalOther: number;
128
- nextExpiryAt: string | null;
129
- lastObservationAt: string | null;
130
- }>;
131
- admissions: Degradable<{
132
- admitted: number;
133
- admittedWithoutTask: number;
134
- pendingTails: number;
135
- staleTails: number;
136
- completedTails: number;
137
- lastAdmissionAt: string | null;
138
- }>;
139
- diagnosticianTasks: Degradable<{
140
- pending: number;
141
- leased: number;
142
- retryWait: number;
143
- needsHumanReview: number;
144
- }>;
145
- /** §15: ready is true only under the full §15 conjunction; unknown ⇒ not ready. */
146
- ready: boolean;
147
- readyBlockers: string[];
148
- warnings: string[];
149
- }
150
-
151
- function readPackageVersion(packageName: string): string {
152
- try {
153
- const pkgJsonPath = require.resolve(`${packageName}/package.json`);
154
- const pkg = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf8')) as { version?: unknown };
155
- if (typeof pkg.version === 'string') return pkg.version;
156
- return 'unknown';
157
- } catch {
158
- return 'unknown';
159
- }
160
- }
161
-
162
- function detectCodexConfigDir(): string | undefined {
163
- const home = os.homedir();
164
- const codexDir = path.join(home, '.codex');
165
- if (fs.existsSync(codexDir)) return codexDir;
166
- return undefined;
167
- }
168
-
169
- function detectHooksTrust(codexConfigDir: string | undefined): CodexHealthReport['hooksTrust'] {
170
- if (!codexConfigDir) {
171
- return {
172
- detectable: false,
173
- reason: 'codex_config_dir_not_found',
174
- nextAction: 'Install Codex CLI (>= 0.147) and run `codex` once to create ~/.codex/, then re-run `pd health --host codex` to verify hook trust state.',
175
- };
176
- }
177
- // Codex stores hook trust in config.toml under [features] hooks = true|false.
178
- // Best-effort text scan (no TOML parser dependency): find the 'hooks' key,
179
- // then the next '=' and inspect the value token. Deliberately plain string
180
- // operations — no regex over assignment syntax.
181
- const configTomlPath = path.join(codexConfigDir, 'config.toml');
182
- if (!fs.existsSync(configTomlPath)) {
183
- return {
184
- detectable: false,
185
- reason: 'config_toml_not_found',
186
- nextAction: `Open Codex and run /hooks to trust PD hooks, then re-run \`pd health --host codex\`. Expected config at ${configTomlPath}.`,
187
- };
188
- }
189
- try {
190
- const raw = fs.readFileSync(configTomlPath, 'utf8');
191
- // Line-by-line scan: a `hooks = <bool>` assignment inside the file, with
192
- // comment lines skipped — a commented-out `# hooks = false` legacy note
193
- // must not flip the trust verdict (review round 3).
194
- let trusted: boolean | undefined;
195
- for (const rawLine of raw.split('\n')) {
196
- const line = rawLine.trim();
197
- if (line.startsWith('#')) continue;
198
- const lowered = line.toLowerCase();
199
- const hooksIndex = lowered.indexOf('hooks');
200
- if (hooksIndex === -1) continue;
201
- const eqIndex = lowered.indexOf('=', hooksIndex);
202
- if (eqIndex === -1) continue;
203
- const tail = lowered.slice(eqIndex + 1, eqIndex + 12).trim();
204
- if (tail.startsWith('true')) { trusted = true; break; }
205
- if (tail.startsWith('false')) { trusted = false; break; }
206
- }
207
- if (trusted === undefined) {
208
- return {
209
- detectable: false,
210
- reason: 'hooks_setting_not_found_in_config',
211
- nextAction: 'Open Codex and run /hooks to trust PD hooks. Codex config.toml exists but has no `hooks` setting under [features].',
212
- };
213
- }
214
- return { detectable: true, trusted };
215
- } catch (error) {
216
- const message = error instanceof Error ? error.message : String(error);
217
- return {
218
- detectable: false,
219
- reason: `config_toml_read_failed: ${message.slice(0, 200)}`,
220
- nextAction: `Check read permissions on ${configTomlPath} and re-run \`pd health --host codex\`.`,
221
- };
222
- }
223
- }
224
-
225
- /**
226
- * Dual-registration detection for the §15/§17 health surface. The legacy
227
- * predicate itself is the ONE authority in host-runtime
228
- * (detectLegacyCodexHookRegistration) — shared with the retired installer.
229
- */
230
- function detectDualRegistration(codexConfigDir: string | undefined): CodexHealthReport['dualRegistration'] {
231
- const globalHooksPath = codexConfigDir ? path.join(codexConfigDir, 'hooks.json') : undefined;
232
- const globalHooksExists = globalHooksPath ? fs.existsSync(globalHooksPath) : false;
233
- if (globalHooksExists && globalHooksPath) {
234
- const legacy = detectLegacyCodexHookRegistration(globalHooksPath);
235
- return {
236
- detected: true,
237
- legacyAsyncPostToolUse: legacy.legacyAsyncPostToolUse,
238
- globalHooksPath,
239
- reason: 'global_hooks_json_present',
240
- nextAction: legacy.detected
241
- ? 'A legacy PD global hook registration was detected. The Marketplace plugin is the only supported new install path (SPEC §17): remove the legacy registration with `create-principles-disciple uninstall --host codex`, then install the principles-disciple Codex plugin.'
242
- : 'Global ~/.codex/hooks.json is installed. If the PD Codex plugin is also installed via marketplace, this may cause double-registration. Choose ONE: keep global hooks.json (fallback path) OR uninstall it and use the plugin (recommended).',
243
- };
244
- }
245
- return { detected: false };
246
- }
247
-
248
- function readInstallManifestRegistration(workspace: string): { registered: boolean; error?: string } {
249
- try {
250
- const paths = getInstallLayoutPaths(os.homedir());
251
- const raw: unknown = JSON.parse(fs.readFileSync(paths.manifest, 'utf8'));
252
- const parsed = parseInstallManifest(raw);
253
- if (parsed.manifest !== undefined) {
254
- const registered = parsed.manifest.workspaces?.some((entry) => path.resolve(entry) === path.resolve(workspace)) ?? false;
255
- return { registered };
256
- }
257
- return { registered: false, error: parsed.error ?? 'install_manifest_invalid' };
258
- } catch {
259
- return { registered: false, error: 'install_manifest_unreadable' };
260
- }
261
- }
262
-
263
- /**
264
- * §15 Diagnostician counts, read from the Runtime V2 task store
265
- * (taskKind 'diagnostician'). Read-only; degradation is structured.
266
- */
267
- async function readDiagnosticianCounts(workspace: string): Promise<CodexHealthReport['diagnosticianTasks']> {
268
- try {
269
- const connection = new SqliteConnection(workspace);
270
- const taskStore = new SqliteTaskStore(connection);
271
- const count = async (status: 'pending' | 'leased' | 'retry_wait' | 'needs_human_review'): Promise<number> => {
272
- // Bounded reporting: 1000 far exceeds any realistic per-workspace
273
- // Diagnostician backlog; a saturated bucket still blocks readiness via
274
- // needs_human_review/pending semantics rather than hiding.
275
- const tasks = await taskStore.listTasks({ status, taskKind: 'diagnostician', limit: 1000 });
276
- return tasks.length;
277
- };
278
- const [pending, leased, retryWait, needsHumanReview] = await Promise.all([
279
- count('pending'), count('leased'), count('retry_wait'), count('needs_human_review'),
280
- ]);
281
- return { pending, leased, retryWait, needsHumanReview };
282
- } catch (error) {
283
- const message = error instanceof Error ? error.message.slice(0, 160) : String(error);
284
- return {
285
- reason: `diagnostician_counts_unavailable: ${message}`,
286
- nextAction: 'Run `pd runtime init --confirm` if state.db is missing, or inspect the Runtime V2 task store.',
287
- };
288
- }
289
- }
290
-
291
- export async function handleHealthCodex(opts: CodexHealthOptions = {}): Promise<void> {
292
- const generatedAt = new Date().toISOString();
293
- const workspaceDir = opts.workspace ? path.resolve(opts.workspace) : resolveWorkspaceDir();
294
-
295
- const warnings: string[] = [];
296
- const readyBlockers: string[] = [];
297
- const noteReadyBlocker = (label: string, reason?: string): void => {
298
- readyBlockers.push(reason !== undefined ? `${label}: ${reason}` : label);
299
- };
300
-
301
- // ── Workspace config → flags + workspace init ──────────────────────────────
302
- const resolution = resolveNearestPdWorkspace(workspaceDir);
303
- let resolvedWorkspace = workspaceDir;
304
- let featureFlagSource: 'user_config' | 'defaults' | 'malformed';
305
- let hostCodexEnabled = false;
306
- let workspaceInit: CodexHealthReport['workspaceInit'] = { initialized: false, reason: 'workspace_not_resolved', nextAction: 'Run `pd runtime init --confirm` in the workspace.' };
307
- // ONE config load feeds both flag states + workspace init.
308
- const configLoad = loadPdConfigForPlugin(resolution.ok ? resolution.workspaceDir : workspaceDir);
309
-
310
- if (!resolution.ok) {
311
- featureFlagSource = 'defaults';
312
- warnings.push(`workspace_not_resolved: ${resolution.reason} — ${resolution.nextAction}`);
313
- noteReadyBlocker('workspace', resolution.reason);
314
- } else {
315
- resolvedWorkspace = resolution.workspaceDir;
316
- featureFlagSource = configLoad.source;
317
- const flags = computeFeatureFlagsFromConfig(configLoad.effective);
318
- hostCodexEnabled = isFeatureEnabled(flags, 'host.codex');
319
- if (!configLoad.ok) {
320
- workspaceInit = {
321
- initialized: false,
322
- reason: `config_malformed: ${configLoad.errors[0]?.reason ?? 'unknown'}`,
323
- nextAction: configLoad.errors[0]?.nextAction ?? 'Repair .pd/config.yaml.',
324
- };
325
- for (const error of configLoad.errors) warnings.push(`config_error: ${error.reason} — ${error.nextAction}`);
326
- noteReadyBlocker('workspace', 'config_malformed');
327
- } else {
328
- workspaceInit = { initialized: true };
329
- }
330
- }
331
- const ingestionFlag: CodexHealthReport['ingestionFlag'] = configLoad.ok
332
- ? {
333
- name: 'codex_conversation_ingestion',
334
- enabled: isFeatureEnabled(computeFeatureFlagsFromConfig(configLoad.effective), 'codex_conversation_ingestion'),
335
- source: configLoad.source,
336
- }
337
- : { reason: `config_unreadable: ${configLoad.errors[0]?.reason ?? 'unknown'}`, nextAction: 'Repair .pd/config.yaml so the flag state can be evaluated.' };
338
- const ingestionEnabled = 'enabled' in ingestionFlag ? ingestionFlag.enabled : false;
339
-
340
- // ── Consent state (decision metadata only — never captured text) ──────────
341
- let consent: CodexHealthReport['consent'];
342
- {
343
- const read = readCodexIngestionConsent(resolvedWorkspace);
344
- if (!read.ok) {
345
- consent = { reason: read.reason, nextAction: read.nextAction };
346
- noteReadyBlocker('consent', read.reason);
347
- } else {
348
- const state = deriveCodexIngestionConsentState(read.record, ingestionEnabled);
349
- const disclosureStale = read.record !== null && read.record.disclosureVersion !== CODEX_INGESTION_DISCLOSURE_VERSION;
350
- consent = {
351
- state,
352
- disclosureStale,
353
- ...(read.record !== null
354
- ? { decidedAt: read.record.decidedAt, decidedVia: read.record.decidedVia, disclosureVersion: read.record.disclosureVersion }
355
- : {}),
356
- ...(state === 'flag_on_without_grant'
357
- ? {
358
- reason: 'flag_enabled_without_consent_record',
359
- nextAction: 'The ingestion flag was enabled outside the disclosed consent flow. Run `pd codex setup` to present the disclosure and record (or reverse) the decision.',
360
- }
361
- : {}),
362
- ...(disclosureStale
363
- ? { reason: 'consent_recorded_for_older_disclosure', nextAction: 'Run `pd codex setup` to review the current disclosure and re-record the decision.' }
364
- : {}),
365
- };
366
- if (ingestionEnabled && state !== 'granted') noteReadyBlocker('consent', state);
367
- }
368
- }
369
-
370
- // ── Worker mode ────────────────────────────────────────────────────────────
371
- const manifest = readInstallManifestRegistration(resolvedWorkspace);
372
- const workerEvaluation = computeCodexWorkerStatusMode({ workspaceDir: resolvedWorkspace, registeredInInstallManifest: manifest.registered });
373
- const worker: CodexHealthReport['worker'] = {
374
- mode: workerEvaluation.mode,
375
- registeredInInstallManifest: manifest.registered,
376
- ...(workerEvaluation.reason !== undefined ? { reason: workerEvaluation.reason } : {}),
377
- ...(workerEvaluation.nextAction !== undefined ? { nextAction: workerEvaluation.nextAction } : {}),
378
- };
379
- if (workerEvaluation.mode === 'degraded') noteReadyBlocker('worker', workerEvaluation.reason);
380
- if (workerEvaluation.mode === 'manual_action_required') noteReadyBlocker('worker', 'manual_action_required');
381
- if (manifest.error !== undefined) warnings.push(`install_manifest: ${manifest.error}`);
382
-
383
- // ── Hook trust + dual registration ─────────────────────────────────────────
384
- const codexConfigDir = detectCodexConfigDir();
385
- const hooksTrust = detectHooksTrust(codexConfigDir);
386
- const dualRegistration = detectDualRegistration(codexConfigDir);
387
- if (hooksTrust.reason) warnings.push(`hooks_trust: ${hooksTrust.reason}`);
388
- if (dualRegistration.reason) warnings.push(`dual_registration: ${dualRegistration.reason}`);
389
- if (hooksTrust.trusted !== true) noteReadyBlocker('hooks_trust', hooksTrust.reason ?? 'untrusted');
390
-
391
- // ── Per-rollout checkpoints + bounded lag (stat only, never content) ───────
392
- let rollouts: CodexHealthReport['rollouts'];
393
- {
394
- const listed = listGovernanceCheckpoints({ workspaceDir: resolvedWorkspace, hostKind: 'codex' });
395
- if (listed.ok) {
396
- const codexHome = process.env.CODEX_HOME ?? path.join(os.homedir(), '.codex');
397
- let lagUndetectable = false;
398
- const checkpoints = listed.checkpoints.map((checkpoint) => {
399
- let lagBytes: number | null = null;
400
- const lookup = locateCodexTranscriptByRolloutIdentity(codexHome, checkpoint.rolloutIdentity);
401
- if (lookup.ok) {
402
- try {
403
- lagBytes = Math.max(0, fs.statSync(lookup.transcriptPath).size - checkpoint.byteOffset);
404
- } catch {
405
- lagUndetectable = true;
406
- }
407
- } else {
408
- lagUndetectable = true;
409
- }
410
- return {
411
- rolloutIdentity: checkpoint.rolloutIdentity,
412
- byteOffset: checkpoint.byteOffset,
413
- lastOrdinal: checkpoint.lastOrdinal,
414
- incompleteTail: checkpoint.incompleteTail,
415
- lastDegradationReason: checkpoint.lastDegradationReason,
416
- updatedAt: checkpoint.updatedAt,
417
- lagBytes,
418
- };
419
- });
420
- rollouts = { checkpoints, lagUndetectable };
421
- for (const checkpoint of checkpoints) {
422
- if (checkpoint.incompleteTail) noteReadyBlocker('rollout', `${checkpoint.rolloutIdentity} incomplete_tail`);
423
- else if (checkpoint.lagBytes !== null && checkpoint.lagBytes > 0) noteReadyBlocker('rollout', `${checkpoint.rolloutIdentity} lag=${checkpoint.lagBytes}B`);
424
- }
425
- if (checkpoints.length > 0 && lagUndetectable) {
426
- warnings.push('rollout_lag_undetectable: the transcript file for at least one checkpoint could not be located (deleted rollout or non-default CODEX_HOME).');
427
- }
428
- } else {
429
- rollouts = { reason: listed.reason, nextAction: listed.nextAction };
430
- noteReadyBlocker('rollouts', listed.reason);
431
- }
432
- }
433
-
434
- // ── Observation / admission / diagnostician counts ─────────────────────────
435
- let observations: CodexHealthReport['observations'];
436
- {
437
- const stats = readGovernanceObservationStats({ workspaceDir: resolvedWorkspace });
438
- observations = stats.ok ? stats.stats : { reason: stats.reason, nextAction: stats.nextAction };
439
- if (!stats.ok) noteReadyBlocker('observations', stats.reason);
440
- }
441
- let admissions: CodexHealthReport['admissions'];
442
- {
443
- const counts = readGovernanceAdmissionCounts({ workspaceDir: resolvedWorkspace });
444
- admissions = counts.ok ? counts.counts : { reason: counts.reason, nextAction: counts.nextAction };
445
- if (!counts.ok) noteReadyBlocker('admissions', counts.reason);
446
- else if (counts.counts.admittedWithoutTask > 0) {
447
- noteReadyBlocker('admissions', `${counts.counts.admittedWithoutTask} admitted pain(s) without a Diagnostician task; run pd codex reconcile`);
448
- }
449
- }
450
- const diagnosticianTasks = await readDiagnosticianCounts(resolvedWorkspace);
451
- if ('pending' in diagnosticianTasks) {
452
- if (diagnosticianTasks.needsHumanReview > 0) noteReadyBlocker('diagnostician', `${diagnosticianTasks.needsHumanReview} task(s) need human review`);
453
- } else {
454
- noteReadyBlocker('diagnostician', diagnosticianTasks.reason);
455
- }
456
-
457
- // ── §15 ready conjunction ──────────────────────────────────────────────────
458
- if (!hostCodexEnabled) noteReadyBlocker('host.codex', 'disabled');
459
- if (workerEvaluation.mode === 'paused') noteReadyBlocker('worker', workerEvaluation.reason);
460
- const adapterVersion = readPackageVersion('@principles/codex-adapter');
461
- const runtimeVersion = readPackageVersion('@principles/host-runtime');
462
- if (adapterVersion === 'unknown') noteReadyBlocker('adapter', 'version_unknown');
463
- const ready = readyBlockers.length === 0;
464
-
465
- const report: CodexHealthReport = {
466
- generatedAt,
467
- host: 'codex',
468
- workspace: resolvedWorkspace,
469
- adapterVersion,
470
- runtimeVersion,
471
- codexIngestionMinVersion: CODEX_INGESTION_MIN_VERSION,
472
- codexIngestionVerifiedVersion: CODEX_INGESTION_VERIFIED_VERSION,
473
- featureFlag: {
474
- name: 'host.codex',
475
- enabled: hostCodexEnabled,
476
- source: featureFlagSource,
477
- ...(hostCodexEnabled
478
- ? {}
479
- : {
480
- reason: 'host_codex_disabled',
481
- nextAction: `Enable the Codex host adapter by setting features.host.codex.enabled=true in ${resolvedWorkspace}/.pd/config.yaml, then re-run \`pd health --host codex\`.`,
482
- }),
483
- },
484
- ingestionFlag,
485
- consent,
486
- workspaceInit,
487
- hooksTrust,
488
- dualRegistration,
489
- worker,
490
- rollouts,
491
- observations,
492
- admissions,
493
- diagnosticianTasks,
494
- ready,
495
- readyBlockers: readyBlockers.slice(0, 12),
496
- warnings,
497
- };
498
-
499
- if (opts.json) {
500
- // cli-1: exactly one parseable JSON object on stdout.
501
- console.log(JSON.stringify(report, null, 2));
502
- // cli-2: exit paths stop execution. Not-ready is the actionable signal.
503
- if (!ready) process.exitCode = 1;
504
- return;
505
- }
506
-
507
- // Text output — still includes explicit nextAction per cli-6.
508
- const line = (label: string, value: string): void => console.log(`${label}: ${value}`);
509
- line('generatedAt', report.generatedAt);
510
- line('host', report.host);
511
- line('workspace', report.workspace);
512
- line('adapterVersion', report.adapterVersion);
513
- line('runtimeVersion', report.runtimeVersion);
514
- line('codexIngestionMinVersion', report.codexIngestionMinVersion);
515
- line('codexIngestionVerifiedVersion', report.codexIngestionVerifiedVersion);
516
- line('featureFlag.host.codex', `${String(report.featureFlag.enabled)} (${report.featureFlag.source})`);
517
- if ('enabled' in report.ingestionFlag) {
518
- line('ingestionFlag.codex_conversation_ingestion', `${String(report.ingestionFlag.enabled)} (${report.ingestionFlag.source})`);
519
- } else {
520
- line('ingestionFlag', `unknown (${report.ingestionFlag.reason})`);
521
- line('ingestionFlag.nextAction', report.ingestionFlag.nextAction);
522
- }
523
- if ('state' in report.consent) line('consent.state', report.consent.state);
524
- else {
525
- line('consent', `unknown (${report.consent.reason})`);
526
- line('consent.nextAction', report.consent.nextAction);
527
- }
528
- const init = report.workspaceInit as { initialized?: boolean; reason?: string };
529
- line('workspaceInit', init.initialized === true ? 'ok' : `not-initialized (${init.reason ?? 'unknown'})`);
530
- line('hooksTrust', report.hooksTrust.trusted === undefined ? `undetectable (${report.hooksTrust.reason ?? 'unknown'})` : String(report.hooksTrust.trusted));
531
- line('dualRegistration', String(report.dualRegistration.detected));
532
- if (report.dualRegistration.detected) line('dualRegistration.nextAction', report.dualRegistration.nextAction ?? '');
533
- line('worker.mode', `${report.worker.mode}${report.worker.reason !== undefined ? ` (${report.worker.reason})` : ''}`);
534
- if ('checkpoints' in report.rollouts) {
535
- line('rollouts', String(report.rollouts.checkpoints.length));
536
- for (const checkpoint of report.rollouts.checkpoints.slice(0, 10)) {
537
- console.log(` - ${checkpoint.rolloutIdentity} lag=${checkpoint.lagBytes === null ? 'unknown' : `${checkpoint.lagBytes}B`} incompleteTail=${String(checkpoint.incompleteTail)} updatedAt=${checkpoint.updatedAt}`);
538
- }
539
- } else {
540
- line('rollouts', `unknown (${report.rollouts.reason})`);
541
- }
542
- if ('operational' in report.observations) {
543
- line('observations', `operational=${String(report.observations.operational)} promoted=${String(report.observations.promoted)} quarantined=${String(report.observations.quarantined)} terminal=${String(report.observations.terminalOther)}`);
544
- line('observations.nextExpiryAt', report.observations.nextExpiryAt ?? 'n/a');
545
- line('observations.lastObservationAt', report.observations.lastObservationAt ?? 'n/a');
546
- } else {
547
- line('observations', `unknown (${report.observations.reason})`);
548
- }
549
- if ('admitted' in report.admissions) {
550
- line('admissions', `admitted=${String(report.admissions.admitted)} withoutTask=${String(report.admissions.admittedWithoutTask)} tails pending=${String(report.admissions.pendingTails)}/stale=${String(report.admissions.staleTails)}/completed=${String(report.admissions.completedTails)}`);
551
- line('admissions.lastAdmissionAt', report.admissions.lastAdmissionAt ?? 'n/a');
552
- } else {
553
- line('admissions', `unknown (${report.admissions.reason})`);
554
- }
555
- if ('pending' in report.diagnosticianTasks) {
556
- line('diagnosticianTasks', `pending=${String(report.diagnosticianTasks.pending)} leased=${String(report.diagnosticianTasks.leased)} retryWait=${String(report.diagnosticianTasks.retryWait)} needsHumanReview=${String(report.diagnosticianTasks.needsHumanReview)}`);
557
- } else {
558
- line('diagnosticianTasks', `unknown (${report.diagnosticianTasks.reason})`);
559
- }
560
- line('ready', `${String(report.ready)}${report.readyBlockers.length > 0 ? ` (blockers: ${report.readyBlockers.join('; ')})` : ''}`);
561
- if (report.warnings.length > 0) {
562
- console.log('warnings:');
563
- for (const warning of report.warnings) console.log(` - ${warning}`);
564
- }
565
- console.log('');
566
-
567
- // Product-claim boundary (PRI-625): automatic closure readiness is NOT
568
- // cross-host signal parity (PRI-632 tracks that separately).
569
- if (report.ready) {
570
- console.log('rev2 automatic closure is ready for this workspace. This does NOT claim OpenClaw↔Codex signal-modality parity (see PRI-632).');
571
- }
572
- if (!hostCodexEnabled) {
573
- console.warn(`⚠️ host.codex feature flag is disabled. Enable it in ${resolvedWorkspace}/.pd/config.yaml under features.host.codex.enabled to activate Codex hooks.`);
574
- }
575
- if (!report.ready) process.exitCode = 1;
576
- }