@principles/pd-cli 1.152.12 → 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 (296) hide show
  1. package/package.json +13 -7
  2. package/CHANGELOG.md +0 -23
  3. package/dist/commands/__tests__/intent-flag-wiring.test.d.ts +0 -9
  4. package/dist/commands/__tests__/intent-flag-wiring.test.d.ts.map +0 -1
  5. package/dist/commands/__tests__/intent-flag-wiring.test.js +0 -237
  6. package/dist/commands/__tests__/intent-flag-wiring.test.js.map +0 -1
  7. package/dist/commands/__tests__/legacy-cleanup.test.d.ts +0 -18
  8. package/dist/commands/__tests__/legacy-cleanup.test.d.ts.map +0 -1
  9. package/dist/commands/__tests__/legacy-cleanup.test.js +0 -467
  10. package/dist/commands/__tests__/legacy-cleanup.test.js.map +0 -1
  11. package/dist/commands/__tests__/mvp-smoke.test.d.ts +0 -15
  12. package/dist/commands/__tests__/mvp-smoke.test.d.ts.map +0 -1
  13. package/dist/commands/__tests__/mvp-smoke.test.js +0 -262
  14. package/dist/commands/__tests__/mvp-smoke.test.js.map +0 -1
  15. package/dist/commands/__tests__/pain-retry-maxTokens-flag.test.d.ts +0 -2
  16. package/dist/commands/__tests__/pain-retry-maxTokens-flag.test.d.ts.map +0 -1
  17. package/dist/commands/__tests__/pain-retry-maxTokens-flag.test.js +0 -60
  18. package/dist/commands/__tests__/pain-retry-maxTokens-flag.test.js.map +0 -1
  19. package/dist/commands/__tests__/rulecode-flag-wiring.test.d.ts +0 -21
  20. package/dist/commands/__tests__/rulecode-flag-wiring.test.d.ts.map +0 -1
  21. package/dist/commands/__tests__/rulecode-flag-wiring.test.js +0 -186
  22. package/dist/commands/__tests__/rulecode-flag-wiring.test.js.map +0 -1
  23. package/dist/commands/__tests__/rulecode-handler.test.d.ts +0 -16
  24. package/dist/commands/__tests__/rulecode-handler.test.d.ts.map +0 -1
  25. package/dist/commands/__tests__/rulecode-handler.test.js +0 -285
  26. package/dist/commands/__tests__/rulecode-handler.test.js.map +0 -1
  27. package/dist/commands/__tests__/run-rulehost-flag-wiring.test.d.ts +0 -24
  28. package/dist/commands/__tests__/run-rulehost-flag-wiring.test.d.ts.map +0 -1
  29. package/dist/commands/__tests__/run-rulehost-flag-wiring.test.js +0 -232
  30. package/dist/commands/__tests__/run-rulehost-flag-wiring.test.js.map +0 -1
  31. package/dist/commands/__tests__/runtime-activation-nextaction.test.d.ts +0 -15
  32. package/dist/commands/__tests__/runtime-activation-nextaction.test.d.ts.map +0 -1
  33. package/dist/commands/__tests__/runtime-activation-nextaction.test.js +0 -73
  34. package/dist/commands/__tests__/runtime-activation-nextaction.test.js.map +0 -1
  35. package/dist/commands/__tests__/runtime-probe-config.test.d.ts +0 -20
  36. package/dist/commands/__tests__/runtime-probe-config.test.d.ts.map +0 -1
  37. package/dist/commands/__tests__/runtime-probe-config.test.js +0 -389
  38. package/dist/commands/__tests__/runtime-probe-config.test.js.map +0 -1
  39. package/dist/commands/__tests__/telemetry-flag-wiring.test.d.ts +0 -9
  40. package/dist/commands/__tests__/telemetry-flag-wiring.test.d.ts.map +0 -1
  41. package/dist/commands/__tests__/telemetry-flag-wiring.test.js +0 -76
  42. package/dist/commands/__tests__/telemetry-flag-wiring.test.js.map +0 -1
  43. package/dist/commands/__tests__/version.test.d.ts +0 -2
  44. package/dist/commands/__tests__/version.test.d.ts.map +0 -1
  45. package/dist/commands/__tests__/version.test.js +0 -238
  46. package/dist/commands/__tests__/version.test.js.map +0 -1
  47. package/dist/commands/runtime-uat.guard.test.d.ts +0 -2
  48. package/dist/commands/runtime-uat.guard.test.d.ts.map +0 -1
  49. package/dist/commands/runtime-uat.guard.test.js +0 -153
  50. package/dist/commands/runtime-uat.guard.test.js.map +0 -1
  51. package/dist/services/__tests__/cli-output.test.d.ts +0 -18
  52. package/dist/services/__tests__/cli-output.test.d.ts.map +0 -1
  53. package/dist/services/__tests__/cli-output.test.js +0 -103
  54. package/dist/services/__tests__/cli-output.test.js.map +0 -1
  55. package/dist/services/__tests__/evaluator-runner-deps.test.d.ts +0 -2
  56. package/dist/services/__tests__/evaluator-runner-deps.test.d.ts.map +0 -1
  57. package/dist/services/__tests__/evaluator-runner-deps.test.js +0 -343
  58. package/dist/services/__tests__/evaluator-runner-deps.test.js.map +0 -1
  59. package/dist/services/__tests__/rulehost-readiness.test.d.ts +0 -2
  60. package/dist/services/__tests__/rulehost-readiness.test.d.ts.map +0 -1
  61. package/dist/services/__tests__/rulehost-readiness.test.js +0 -311
  62. package/dist/services/__tests__/rulehost-readiness.test.js.map +0 -1
  63. package/dist/services/__tests__/runtime-adapter-resolver.test.d.ts +0 -18
  64. package/dist/services/__tests__/runtime-adapter-resolver.test.d.ts.map +0 -1
  65. package/dist/services/__tests__/runtime-adapter-resolver.test.js +0 -673
  66. package/dist/services/__tests__/runtime-adapter-resolver.test.js.map +0 -1
  67. package/dist/utils/production-workspace-guard.test.d.ts +0 -2
  68. package/dist/utils/production-workspace-guard.test.d.ts.map +0 -1
  69. package/dist/utils/production-workspace-guard.test.js +0 -137
  70. package/dist/utils/production-workspace-guard.test.js.map +0 -1
  71. package/scripts/llm-dogfood.ts +0 -456
  72. package/scripts/migrate-illegal-expected-decision.ts +0 -252
  73. package/src/commands/__tests__/intent-flag-wiring.test.ts +0 -282
  74. package/src/commands/__tests__/legacy-cleanup.test.ts +0 -602
  75. package/src/commands/__tests__/mvp-smoke.test.ts +0 -300
  76. package/src/commands/__tests__/pain-retry-maxTokens-flag.test.ts +0 -73
  77. package/src/commands/__tests__/rulecode-flag-wiring.test.ts +0 -237
  78. package/src/commands/__tests__/rulecode-handler.test.ts +0 -369
  79. package/src/commands/__tests__/run-rulehost-flag-wiring.test.ts +0 -292
  80. package/src/commands/__tests__/runtime-activation-nextaction.test.ts +0 -81
  81. package/src/commands/__tests__/runtime-probe-config.test.ts +0 -432
  82. package/src/commands/__tests__/telemetry-flag-wiring.test.ts +0 -84
  83. package/src/commands/__tests__/version.test.ts +0 -251
  84. package/src/commands/admission-gate.ts +0 -30
  85. package/src/commands/artifact.ts +0 -82
  86. package/src/commands/build-trajectory-evidence.ts +0 -298
  87. package/src/commands/candidate.ts +0 -1250
  88. package/src/commands/codex-ingest-catchup.ts +0 -114
  89. package/src/commands/codex-ingest-quarantine.ts +0 -127
  90. package/src/commands/codex-reconcile.ts +0 -84
  91. package/src/commands/codex-setup.ts +0 -476
  92. package/src/commands/codex-worker.ts +0 -185
  93. package/src/commands/command-helpers.ts +0 -24
  94. package/src/commands/config-doctor.ts +0 -193
  95. package/src/commands/console.ts +0 -797
  96. package/src/commands/context.ts +0 -72
  97. package/src/commands/demo-story-a.ts +0 -241
  98. package/src/commands/diagnose.ts +0 -756
  99. package/src/commands/errors-list.ts +0 -441
  100. package/src/commands/evolution-tasks-list.ts +0 -48
  101. package/src/commands/evolution-tasks-show.ts +0 -62
  102. package/src/commands/flow.ts +0 -60
  103. package/src/commands/health-codex.ts +0 -576
  104. package/src/commands/health.ts +0 -315
  105. package/src/commands/history.ts +0 -63
  106. package/src/commands/intent.ts +0 -457
  107. package/src/commands/legacy-cleanup.ts +0 -531
  108. package/src/commands/legacy-import.ts +0 -104
  109. package/src/commands/mvp-smoke.ts +0 -160
  110. package/src/commands/pain-evidence.ts +0 -226
  111. package/src/commands/pain-list.ts +0 -239
  112. package/src/commands/pain-record.ts +0 -612
  113. package/src/commands/pain-retry.ts +0 -916
  114. package/src/commands/principles-stats.ts +0 -700
  115. package/src/commands/proven-channel-baseline.ts +0 -115
  116. package/src/commands/quality-scorecard.ts +0 -272
  117. package/src/commands/remediation-output.ts +0 -66
  118. package/src/commands/rulecode.ts +0 -465
  119. package/src/commands/run.ts +0 -89
  120. package/src/commands/runtime-activation.ts +0 -1629
  121. package/src/commands/runtime-artifact-repair.ts +0 -524
  122. package/src/commands/runtime-canary.ts +0 -395
  123. package/src/commands/runtime-compatibility-scan.ts +0 -105
  124. package/src/commands/runtime-diagnostics-export.ts +0 -229
  125. package/src/commands/runtime-features.ts +0 -153
  126. package/src/commands/runtime-gfi-snapshot.ts +0 -135
  127. package/src/commands/runtime-health-snapshot.ts +0 -108
  128. package/src/commands/runtime-init.ts +0 -429
  129. package/src/commands/runtime-internalization-enqueue-successors.ts +0 -530
  130. package/src/commands/runtime-internalization-integrity-repair.ts +0 -79
  131. package/src/commands/runtime-internalization-integrity.ts +0 -107
  132. package/src/commands/runtime-internalization-queue.ts +0 -135
  133. package/src/commands/runtime-internalization-retry.ts +0 -191
  134. package/src/commands/runtime-internalization-run-once.ts +0 -791
  135. package/src/commands/runtime-internalization-run-rulehost.ts +0 -749
  136. package/src/commands/runtime-internalization-wake-once.ts +0 -87
  137. package/src/commands/runtime-pain-flood-simulation.ts +0 -121
  138. package/src/commands/runtime-pruning.ts +0 -438
  139. package/src/commands/runtime-recovery-failed-tasks.ts +0 -258
  140. package/src/commands/runtime-recovery.ts +0 -109
  141. package/src/commands/runtime-synthetic-baseline.ts +0 -70
  142. package/src/commands/runtime-uat.guard.test.ts +0 -175
  143. package/src/commands/runtime-uat.ts +0 -380
  144. package/src/commands/runtime.ts +0 -473
  145. package/src/commands/samples-list.ts +0 -39
  146. package/src/commands/samples-review.ts +0 -36
  147. package/src/commands/task.ts +0 -271
  148. package/src/commands/telemetry.ts +0 -349
  149. package/src/commands/trace.ts +0 -174
  150. package/src/commands/trajectory-db-unavailable.ts +0 -19
  151. package/src/commands/trajectory.ts +0 -64
  152. package/src/commands/version.ts +0 -49
  153. package/src/config-reader.ts +0 -122
  154. package/src/index.ts +0 -1276
  155. package/src/legacy/legacy-import.ts +0 -179
  156. package/src/legacy/session-history-import.ts +0 -203
  157. package/src/resolve-workspace.ts +0 -106
  158. package/src/services/__tests__/cli-output.test.ts +0 -130
  159. package/src/services/__tests__/evaluator-runner-deps.test.ts +0 -382
  160. package/src/services/__tests__/rulehost-readiness.test.ts +0 -363
  161. package/src/services/__tests__/runtime-adapter-resolver.test.ts +0 -793
  162. package/src/services/cli-output.ts +0 -95
  163. package/src/services/config-doctor.ts +0 -697
  164. package/src/services/console-launcher.ts +0 -537
  165. package/src/services/demo-rule-compiler.ts +0 -40
  166. package/src/services/demo-story-a-runner.ts +0 -471
  167. package/src/services/mainline-snapshot-assembler.ts +0 -579
  168. package/src/services/pain-flood-simulation-runner.ts +0 -462
  169. package/src/services/pd-config-loader.ts +0 -433
  170. package/src/services/proven-channel-baseline-runner.ts +0 -157
  171. package/src/services/quality-scorecard/data-extractor.ts +0 -150
  172. package/src/services/quality-scorecard/local-evaluator.ts +0 -142
  173. package/src/services/quality-scorecard/strong-model-gate.ts +0 -202
  174. package/src/services/resolve-runtime-from-pd-config.ts +0 -230
  175. package/src/services/rulehost-pipeline-runner.ts +0 -1214
  176. package/src/services/rulehost-readiness.ts +0 -326
  177. package/src/services/runtime-adapter-resolver.ts +0 -364
  178. package/src/services/synthetic-baseline-runner.ts +0 -400
  179. package/src/services/version-report.ts +0 -253
  180. package/src/services/workspace-tool-semantics.ts +0 -26
  181. package/src/utils/path-security.ts +0 -96
  182. package/src/utils/production-workspace-guard.test.ts +0 -157
  183. package/src/utils/production-workspace-guard.ts +0 -210
  184. package/tests/bdd/cli-contract.steps.ts +0 -346
  185. package/tests/bdd/principles-stats.steps.ts +0 -211
  186. package/tests/bdd/support/gherkin-loader.ts +0 -147
  187. package/tests/bdd/support/repo-root.ts +0 -62
  188. package/tests/bdd/support/vitest-bdd.ts +0 -179
  189. package/tests/commands/admission-gate-coverage.test.ts +0 -79
  190. package/tests/commands/build-trajectory-evidence.test.ts +0 -508
  191. package/tests/commands/candidate-audit-repair.test.ts +0 -421
  192. package/tests/commands/candidate-intake.test.ts +0 -732
  193. package/tests/commands/candidate-internalization-backfill.test.ts +0 -548
  194. package/tests/commands/candidate-internalize-lineage.test.ts +0 -628
  195. package/tests/commands/candidate-internalize.test.ts +0 -299
  196. package/tests/commands/candidate-route.test.ts +0 -329
  197. package/tests/commands/candidate-show.test.ts +0 -95
  198. package/tests/commands/cli-command-tree.test.ts +0 -144
  199. package/tests/commands/cli-help-snapshot.test.ts +0 -155
  200. package/tests/commands/cli-skill-contract.test.ts +0 -121
  201. package/tests/commands/codex-consent-reversibility.steps.test.ts +0 -299
  202. package/tests/commands/codex-ingest-quarantine.test.ts +0 -136
  203. package/tests/commands/codex-setup.test.ts +0 -297
  204. package/tests/commands/codex-worker-daemon.test.ts +0 -95
  205. package/tests/commands/codex-worker-registration.test.ts +0 -207
  206. package/tests/commands/config-doctor.test.ts +0 -336
  207. package/tests/commands/console-launcher-edge-cases.test.ts +0 -388
  208. package/tests/commands/console-open.test.ts +0 -1381
  209. package/tests/commands/context.test.ts +0 -114
  210. package/tests/commands/demo-story-a.test.ts +0 -318
  211. package/tests/commands/diagnose.test.ts +0 -1803
  212. package/tests/commands/errors-list.test.ts +0 -679
  213. package/tests/commands/evolution-tasks-list.test.ts +0 -41
  214. package/tests/commands/evolution-tasks-show.test.ts +0 -46
  215. package/tests/commands/health-codex.test.ts +0 -349
  216. package/tests/commands/health-host-wiring.test.ts +0 -76
  217. package/tests/commands/health-reliability.test.ts +0 -99
  218. package/tests/commands/health.test.ts +0 -413
  219. package/tests/commands/intent.test.ts +0 -321
  220. package/tests/commands/legacy-cleanup.test.ts +0 -148
  221. package/tests/commands/pain-evidence.test.ts +0 -518
  222. package/tests/commands/pain-list.test.ts +0 -219
  223. package/tests/commands/pain-record-async.test.ts +0 -335
  224. package/tests/commands/pain-record-session-parser.test.ts +0 -228
  225. package/tests/commands/pain-record.test.ts +0 -851
  226. package/tests/commands/pain-retry.test.ts +0 -1121
  227. package/tests/commands/plugin-config-resolution-cutover.test.ts +0 -229
  228. package/tests/commands/pri-393-runtime-config-unification.test.ts +0 -443
  229. package/tests/commands/principles-stats-wiring.test.ts +0 -135
  230. package/tests/commands/principles-stats.test.ts +0 -274
  231. package/tests/commands/product-path-regression.test.ts +0 -86
  232. package/tests/commands/proven-channel-baseline.test.ts +0 -441
  233. package/tests/commands/rulecode.test.ts +0 -177
  234. package/tests/commands/run-rulehost-handler.test.ts +0 -908
  235. package/tests/commands/runtime-activation-approve-flag-wiring.test.ts +0 -227
  236. package/tests/commands/runtime-activation-deactivate-flag-wiring.test.ts +0 -167
  237. package/tests/commands/runtime-activation-dispatch-flag-wiring.test.ts +0 -262
  238. package/tests/commands/runtime-activation-governance-audit.test.ts +0 -95
  239. package/tests/commands/runtime-activation-list-flag-wiring.test.ts +0 -193
  240. package/tests/commands/runtime-activation-promote-flag-wiring.test.ts +0 -248
  241. package/tests/commands/runtime-activation-shadow-telemetry.test.ts +0 -130
  242. package/tests/commands/runtime-activation.test.ts +0 -2052
  243. package/tests/commands/runtime-artifact-repair-registration.test.ts +0 -74
  244. package/tests/commands/runtime-artifact-repair.test.ts +0 -404
  245. package/tests/commands/runtime-canary.test.ts +0 -430
  246. package/tests/commands/runtime-compatibility-scan.test.ts +0 -146
  247. package/tests/commands/runtime-diagnostics-export.test.ts +0 -175
  248. package/tests/commands/runtime-features.test.ts +0 -249
  249. package/tests/commands/runtime-health-snapshot.test.ts +0 -358
  250. package/tests/commands/runtime-init-empty-workspace.test.ts +0 -252
  251. package/tests/commands/runtime-init.test.ts +0 -420
  252. package/tests/commands/runtime-internalization-enqueue-successors.test.ts +0 -782
  253. package/tests/commands/runtime-internalization-integrity-repair.test.ts +0 -239
  254. package/tests/commands/runtime-internalization-integrity.test.ts +0 -140
  255. package/tests/commands/runtime-internalization-queue.test.ts +0 -380
  256. package/tests/commands/runtime-internalization-retry-owner-authority.test.ts +0 -431
  257. package/tests/commands/runtime-internalization-run-once-evaluator-parity.test.ts +0 -269
  258. package/tests/commands/runtime-internalization-run-once-language.test.ts +0 -303
  259. package/tests/commands/runtime-internalization-run-once-real-config.test.ts +0 -237
  260. package/tests/commands/runtime-internalization-run-once-rollout-parity.test.ts +0 -706
  261. package/tests/commands/runtime-internalization-run-once.test.ts +0 -1791
  262. package/tests/commands/runtime-internalization-wake-once.test.ts +0 -171
  263. package/tests/commands/runtime-internalization.test.ts +0 -53
  264. package/tests/commands/runtime-pain-flood-simulation.test.ts +0 -418
  265. package/tests/commands/runtime-pruning.test.ts +0 -694
  266. package/tests/commands/runtime-recovery-failed-tasks.test.ts +0 -328
  267. package/tests/commands/runtime-recovery.test.ts +0 -120
  268. package/tests/commands/runtime-synthetic-baseline.test.ts +0 -249
  269. package/tests/commands/runtime-uat.test.ts +0 -397
  270. package/tests/commands/runtime.test.ts +0 -392
  271. package/tests/commands/samples-list.test.ts +0 -43
  272. package/tests/commands/samples-review.test.ts +0 -41
  273. package/tests/commands/task.test.ts +0 -153
  274. package/tests/commands/telemetry.test.ts +0 -190
  275. package/tests/commands/trace.test.ts +0 -316
  276. package/tests/config-reader.test.ts +0 -143
  277. package/tests/e2e/candidate-intake-e2e.test.ts +0 -338
  278. package/tests/e2e/cli-full-flow.test.ts +0 -233
  279. package/tests/e2e/cross-package-acceptance.test.ts +0 -635
  280. package/tests/helpers/pd-cli-path.ts +0 -5
  281. package/tests/pd-cli-smoke.test.ts +0 -13
  282. package/tests/resolve-workspace.test.ts +0 -196
  283. package/tests/services/config-doctor-signal-health.test.ts +0 -109
  284. package/tests/services/console-launcher.test.ts +0 -114
  285. package/tests/services/demo-rule-compiler.test.ts +0 -242
  286. package/tests/services/mainline-snapshot-assembler.test.ts +0 -572
  287. package/tests/services/pd-config-loader.test.ts +0 -505
  288. package/tests/services/proven-channel-baseline-runner.test.ts +0 -30
  289. package/tests/services/quality-scorecard/strong-model-gate.test.ts +0 -133
  290. package/tests/services/resolve-runtime-from-pd-config.test.ts +0 -485
  291. package/tests/services/rulehost-pipeline-e2e.test.ts +0 -538
  292. package/tests/services/rulehost-pipeline-runner.test.ts +0 -1242
  293. package/tests/services/workspace-tool-semantics.test.ts +0 -76
  294. package/tests/utils/path-security.test.ts +0 -180
  295. package/tsconfig.json +0 -26
  296. package/vitest.config.ts +0 -10
@@ -1,612 +0,0 @@
1
- /**
2
- * pd pain record command — Runtime v2 pain signal entry point.
3
- *
4
- * Uses PainToPrincipleService as the single write-side orchestration API.
5
- * PRI-642 (review blocker 1): the ingress semantic interpretation — origin,
6
- * bound/unbound correlation, provenance derivation, sentinel handling,
7
- * submit/degrade/refuse semantics and painIngress.v1 construction — comes
8
- * from the SHARED evaluator `evaluatePainIngress` in @principles/core
9
- * (the same authority the OpenClaw funnel uses). This adapter only does
10
- * host-specific ACQUISITION: read --session, validate it against this
11
- * workspace's trajectory.db, and collect raw evidence entries.
12
- *
13
- * Usage:
14
- * pd pain record --reason <text> [--score N] [--source manual] [--workspace <path>] [--session <id>] [--host openclaw|codex] [--rollout-id <id> --host-turn-id <id>] [--json]
15
- *
16
- * PRI-743: `--host` makes host attribution explicit instead of assumed.
17
- * `--host openclaw` records the default attribution without the disclosure
18
- * warning. `--host codex` requires the caller to supply the REAL Codex
19
- * lineage — `--rollout-id` / `--host-turn-id`, with `--session` as the Codex
20
- * root session — because the shared ingress evaluator only writes
21
- * `host_kind=codex` for a bound correlation carrying the complete lineage
22
- * tuple (rc-6). The CLI never synthesises that tuple: an unverifiable Codex
23
- * attribution would be a PRI-642 recurrence in another shape (Evidence Over
24
- * Assumption). `--logical-key` overrides the derived observation key; a key
25
- * that does not embed the given rollout identity is refused by the evaluator
26
- * (lineage_mismatch). The correlation schema itself is NOT changed —
27
- * PainIngressCorrelationV1 bound branches only admit openclaw/codex.
28
- */
29
- import {
30
- PainToPrincipleService,
31
- PrincipleTreeLedgerAdapter,
32
- resolveRuntimeConfig,
33
- isRuntimeConfigError,
34
- isFeatureEnabled,
35
- isBuiltinPiAiProvider,
36
- evaluatePainIngress,
37
- } from '@principles/core/runtime-v2';
38
- import type { PainIngressDecision, IngressEvidenceEntry, PainEvidenceEntry, PainCorrelation } from '@principles/core/runtime-v2';
39
- import { resolveWorkspaceDir } from '../resolve-workspace.js';
40
- import { loadPdConfig, computeFlagsFromLoadResult } from '../services/pd-config-loader.js';
41
- import { acquireTrajectoryEvidenceFromDb } from './build-trajectory-evidence.js';
42
-
43
- interface RecordOptions {
44
- reason?: string;
45
- score?: number;
46
- source?: string;
47
- workspace?: string;
48
- json?: boolean;
49
- session?: string;
50
- wait?: boolean;
51
- /** PRI-743: explicit host attribution for a bound --session pain. */
52
- host?: string;
53
- /** PRI-743 follow-up: Codex rollout identity — required by --host codex. */
54
- rolloutId?: string;
55
- /** PRI-743 follow-up: Codex turn id — required by --host codex. */
56
- hostTurnId?: string;
57
- /** PRI-743 follow-up: Codex logical observation key override for --host codex. */
58
- logicalKey?: string;
59
- }
60
-
61
- function emitSessionBindingFailure(
62
- opts: RecordOptions,
63
- failure: { reason: string; message: string; nextAction: string },
64
- ): void {
65
- if (opts.json) {
66
- console.log(JSON.stringify({
67
- status: 'failed',
68
- reason: failure.reason,
69
- message: failure.message,
70
- nextAction: failure.nextAction,
71
- }, null, 2));
72
- } else {
73
- console.error(`Error: ${failure.message}`);
74
- console.error(`Reason: ${failure.reason}`);
75
- console.error(`Next action: ${failure.nextAction}`);
76
- }
77
- process.exit(1);
78
- }
79
-
80
- function toIngressEntry(entry: PainEvidenceEntry): IngressEvidenceEntry {
81
- // Trajectory evidence references observed behavior (owner messages,
82
- // assistant turns, tool-call failures) — behavior traces.
83
- return { kind: 'behavior_trace', sourceRef: entry.sourceRef, note: entry.note };
84
- }
85
-
86
- /**
87
- * PRI-642 (SPEC §7.3/§7.4, review blocker 1): build the report from this
88
- * adapter's host-specific facts and let the SHARED evaluator decide.
89
- *
90
- * Per-channel policy (SPEC §7.3/§8.2 vs OpenClaw):
91
- *
92
- * - explicit `--session` + acquisition available (real session + real entries):
93
- * → cli_explicit_session + bound → submit with real evidence.
94
- * - explicit `--session` + acquisition unavailable with the binding VERIFIED
95
- * (empty_trajectory / evidence-table-level evidence_read_failed — the
96
- * sessions table was queried and DID contain the id; SPEC §8.2: binding
97
- * failure and evidence failure are separate axes, a real session with
98
- * unusable evidence is bound + unavailable, not unbound):
99
- * → cli_explicit_session + bound → shared evaluator DEGRADES (row 4):
100
- * submit with honest empty evidence; the admission gate owns what
101
- * empty evidence is worth. PRI-783 Owner directive: a correct current
102
- * session id is sufficient — empty evidence must not hard-refuse.
103
- * - explicit `--session` + acquisition unavailable with the binding
104
- * UNVERIFIED (session_not_found / trajectory_unavailable / DB-open-level
105
- * evidence_read_failed — SPEC §8.2's "real session" premise does not
106
- * hold: the CLI verifies session ids against trajectory.db itself, so
107
- * when that DB is missing or unopenable the id is unproven):
108
- * → cli_explicit_session + unbound → shared evaluator REFUSES (row 5)
109
- * before any LLM/task/candidate mutation. Claiming bound here would
110
- * also let the observability writer persist the unverified id into a
111
- * freshly created trajectory.db — laundering an unproven fact into
112
- * future "evidence" (PRI-783 review P1, self-proving loop).
113
- * - no `--session` → unbound Owner report (matrix row 6) → submit with
114
- * disclosure; no sentinel session, no placeholder evidence, no trajectory
115
- * projection (the CLI skips observability when the ingress yields no
116
- * bound session — SPEC §7.4).
117
- */
118
- function resolveIngressDecision(
119
- input: { opts: RecordOptions; stateDir: string; workspaceDir: string; painId: string },
120
- ): { decision: PainIngressDecision; acquisitionDetail: string | null; acquisitionReason: string | null } {
121
- const { opts, stateDir, workspaceDir, painId } = input;
122
- const score = opts.score ?? 80;
123
- const base = {
124
- identity: { kind: 'manual_pain_id' as const, painId },
125
- painType: 'user_frustration' as const,
126
- source: opts.source ?? 'manual',
127
- reason: opts.reason ?? '',
128
- score,
129
- };
130
-
131
- // PRI-743 follow-up: an explicit Codex attribution. The lineage ids are the
132
- // caller's (presence validated in handlePainRecord); the logical observation
133
- // key is derived with the SAME rule the Codex ingestion path uses
134
- // (codex-adapter admission.ts buildLiveCorrectionCandidate →
135
- // `codex|<rolloutIdentity>|<turnId>|user`) unless --logical-key overrides it.
136
- // The CLI cannot read the Codex trajectory (that is the ingestion path's
137
- // job), so the evidence class is honestly 'unavailable': the shared
138
- // evaluator takes its bound+unavailable 'degrade' branch and submits the
139
- // pain with real lineage and empty evidence rather than fabricating either.
140
- if (opts.host === 'codex') {
141
- const rolloutIdentity = opts.rolloutId as string;
142
- const hostTurnId = opts.hostTurnId as string;
143
- const rootSessionId = opts.session as string;
144
- const correlation: PainCorrelation = {
145
- status: 'bound',
146
- hostKind: 'codex',
147
- rootSessionId,
148
- rolloutIdentity,
149
- logicalObservationKey: opts.logicalKey ?? `codex|${rolloutIdentity}|${hostTurnId}|user`,
150
- hostTurnId,
151
- };
152
- const decision = evaluatePainIngress({
153
- ...base,
154
- origin: { kind: 'owner_manual', channel: 'cli_explicit_session' },
155
- correlation,
156
- evidence: { status: 'unavailable', reason: 'trajectory_unavailable' },
157
- });
158
- return { decision, acquisitionDetail: null, acquisitionReason: null };
159
- }
160
-
161
- if (!opts.session) {
162
- // No --session: external unbound Owner report (matrix row 6). Allowed
163
- // by SPEC §7.4 with a disclosure warning; never claims host binding.
164
- const decision = evaluatePainIngress({
165
- ...base,
166
- origin: { kind: 'owner_manual', channel: 'external_cli_unbound' },
167
- correlation: { status: 'unbound', reason: 'external_cli' },
168
- evidence: { status: 'unavailable', reason: 'not_applicable_unbound' },
169
- });
170
- return { decision, acquisitionDetail: null, acquisitionReason: null };
171
- }
172
-
173
- // --session: SPEC §7.3/§8.2. Binding failure and evidence failure are
174
- // separate axes, and the acquisition result carries the binding fact
175
- // directly (PRI-783 review): 'verified' = the sessions table was queried
176
- // and DID contain the id; 'unverified' = missing/unopenable DB or absent
177
- // id. Only a VERIFIED binding may degrade to a bound submission (row 4);
178
- // an unverified one is refused (row 5) — claiming bound for an unverified
179
- // id would let the observability writer persist that id into a freshly
180
- // created trajectory.db (self-proving loop). Per-channel policy differs;
181
- // semantic authority is shared.
182
- const acquisition = acquireTrajectoryEvidenceFromDb(stateDir, opts.session, workspaceDir);
183
- if (acquisition.status === 'unavailable') {
184
- const { reasonCode, binding } = acquisition;
185
- if (binding === 'verified') {
186
- // empty_trajectory / evidence-table-level evidence_read_failed —
187
- // bound + unavailable (row 4): degrade to an honest empty-evidence
188
- // submission; the admission gate decides what empty evidence is worth.
189
- const decision = evaluatePainIngress({
190
- ...base,
191
- origin: { kind: 'owner_manual', channel: 'cli_explicit_session' },
192
- correlation: { status: 'bound', hostKind: 'openclaw', sessionId: opts.session },
193
- evidence: { status: 'unavailable', reason: reasonCode },
194
- });
195
- return { decision, acquisitionDetail: acquisition.detail, acquisitionReason: reasonCode };
196
- }
197
- // binding 'unverified' (session_not_found / trajectory_unavailable /
198
- // DB-open-level evidence_read_failed) — the binding claim could not be
199
- // validated: refuse (row 5) before any mutation.
200
- const decision = evaluatePainIngress({
201
- ...base,
202
- origin: { kind: 'owner_manual', channel: 'cli_explicit_session' },
203
- correlation: { status: 'unbound', reason: 'external_cli' },
204
- evidence: { status: 'unavailable', reason: 'not_applicable_unbound' },
205
- });
206
- if (decision.action === 'refuse') {
207
- return { decision, acquisitionDetail: acquisition.detail, acquisitionReason: reasonCode };
208
- }
209
- }
210
-
211
- // Available evidence: a real session with real entries — submit, bound.
212
- if (acquisition.status === 'available') {
213
- // PRI-743: host attribution is explicit when --host openclaw is given;
214
- // absent --host keeps the pre-PRI-743 'openclaw' default (validated and
215
- // disclosed by handlePainRecord — rc-9). --host codex never reaches this
216
- // point — it returns from its own branch above and must not read the
217
- // OpenClaw trajectory — so the bound correlation here is the openclaw shape.
218
- const hostKind = 'openclaw' as const;
219
- const decision = evaluatePainIngress({
220
- ...base,
221
- origin: { kind: 'owner_manual', channel: 'cli_explicit_session' },
222
- correlation: { status: 'bound', hostKind, sessionId: opts.session },
223
- evidence: { status: 'available', entries: acquisition.entries.map(toIngressEntry) as [IngressEvidenceEntry, ...IngressEvidenceEntry[]] },
224
- });
225
- return { decision, acquisitionDetail: null, acquisitionReason: null };
226
- }
227
-
228
- // Exhaustive — acquireTrajectoryEvidenceFromDb returns {available, unavailable}
229
- // only. Unavailable either returned above (degrade for verified bindings,
230
- // refuse for unverified ones); a future-added reason must be classified
231
- // explicitly here rather than silently degrading.
232
- const decision = evaluatePainIngress({
233
- ...base,
234
- origin: { kind: 'owner_manual', channel: 'cli_explicit_session' },
235
- correlation: { status: 'unbound', reason: 'external_cli' },
236
- evidence: { status: 'unavailable', reason: 'not_applicable_unbound' },
237
- });
238
- return { decision, acquisitionDetail: null, acquisitionReason: null };
239
- }
240
-
241
- export async function handlePainRecord(opts: RecordOptions): Promise<void> {
242
- // PRI-743: fail loud on an unknown --host before any mutation (cli-5/cli-6).
243
- if (opts.host !== undefined && opts.host !== 'openclaw' && opts.host !== 'codex') {
244
- const message = `invalid --host: expected openclaw | codex, got ${opts.host}`;
245
- if (opts.json) {
246
- console.log(JSON.stringify({
247
- status: 'failed',
248
- reason: 'invalid_host_kind',
249
- message,
250
- nextAction: 'Pass --host openclaw or --host codex, or omit --host (defaults to openclaw).',
251
- }, null, 2));
252
- } else {
253
- console.error(`Error: ${message}`);
254
- console.error('Next action: pass --host openclaw or --host codex, or omit --host (defaults to openclaw).');
255
- }
256
- process.exit(1);
257
- return; // guard: test stubs of process.exit continue execution (cli-2-exit-stops)
258
- }
259
-
260
- // PRI-743 follow-up: --host codex must carry the REAL Codex lineage. The
261
- // shared ingress evaluator only attributes `host_kind=codex` to a bound
262
- // correlation holding the complete tuple (rootSessionId / rolloutIdentity /
263
- // logicalObservationKey / hostTurnId — rc-6); the CLI never synthesises that
264
- // tuple, because an unverifiable Codex attribution would itself be the
265
- // misattribution PRI-743 exists to remove. Missing lineage fails loud before
266
- // any mutation (cli-5/cli-6) — the caller owns those ids.
267
- if (opts.host === 'codex') {
268
- const missing: string[] = [];
269
- if (!opts.session) missing.push('--session <codex root session id>');
270
- if (!opts.rolloutId) missing.push('--rollout-id <codex rollout identity>');
271
- if (!opts.hostTurnId) missing.push('--host-turn-id <codex turn id>');
272
- if (missing.length > 0) {
273
- const message = `--host codex requires the real Codex lineage — missing ${missing.join(', ')}`;
274
- const nextAction = 'Pass --session <root session id> --rollout-id <rollout identity> --host-turn-id <turn id> so the pain carries verifiable Codex lineage, or use --host openclaw for OpenClaw-attributed sessions.';
275
- if (opts.json) {
276
- console.log(JSON.stringify({
277
- status: 'failed',
278
- reason: 'codex_lineage_required',
279
- message,
280
- nextAction,
281
- }, null, 2));
282
- } else {
283
- console.error(`Error: ${message}`);
284
- console.error(`Next action: ${nextAction}`);
285
- }
286
- process.exit(1);
287
- return; // guard: test stubs of process.exit continue execution (cli-2-exit-stops)
288
- }
289
- }
290
-
291
- if (!opts.reason) {
292
- console.error('Error: --reason <text> is required');
293
- console.error('Usage: pd pain record --reason <text> [--score N] [--source manual] [--workspace <path>] [--session <id>] [--host openclaw|codex] [--rollout-id <id> --host-turn-id <id>] [--json]');
294
- process.exit(1);
295
- return;
296
- }
297
-
298
- // Bug-P fix: enforce reason length limit to prevent oversized data entering the pipeline.
299
- // Consistent with pain-flood-simulation.ts (MAX_REASON_LENGTH = 500) and synthetic-baseline.ts.
300
- // CodeRabbit review fix: emit JSON on --json and stop execution after exit (cli-1, cli-2, cli-5).
301
- const MAX_REASON_LENGTH = 500;
302
- if (opts.reason.length > MAX_REASON_LENGTH) {
303
- if (opts.json) {
304
- console.log(JSON.stringify({
305
- status: 'failed',
306
- reason: 'reason_too_long',
307
- message: `--reason must be at most ${MAX_REASON_LENGTH} characters (got ${opts.reason.length})`,
308
- nextAction: 'Shorten the reason text or split it into multiple pain records.',
309
- }, null, 2));
310
- } else {
311
- console.error(`Error: --reason must be at most ${MAX_REASON_LENGTH} characters (got ${opts.reason.length})`);
312
- console.error('Next action: shorten the reason text or split it into multiple pain records.');
313
- }
314
- process.exit(1);
315
- return;
316
- }
317
-
318
- if (opts.score !== undefined && (isNaN(opts.score) || opts.score < 0 || opts.score > 100)) {
319
- if (opts.json) {
320
- console.log(JSON.stringify({
321
- status: 'failed',
322
- reason: 'score_invalid',
323
- message: '--score must be a number between 0 and 100',
324
- nextAction: 'Provide --score as an integer from 0 to 100, or omit it for the default (80).',
325
- }, null, 2));
326
- } else {
327
- console.error('Error: --score must be a number between 0 and 100');
328
- console.error('Next action: provide --score as an integer from 0 to 100, or omit it for the default (80).');
329
- }
330
- process.exit(1);
331
- return;
332
- }
333
-
334
- const workspaceDir = resolveWorkspaceDir(opts.workspace);
335
- const stateDir = `${workspaceDir}/.state`;
336
- const painId = `manual_${Date.now()}_${Math.random().toString(36).slice(2, 10)}`;
337
-
338
- // PRI-642: run the SHARED ingress evaluator before any service/LLM/task
339
- // mutation; the decision (submit/degrade/refuse) is not made here.
340
- const { decision, acquisitionDetail, acquisitionReason } = resolveIngressDecision({ opts, stateDir, workspaceDir, painId });
341
-
342
- if (decision.action === 'refuse') {
343
- // SPEC §7.3: the CLI must surface the specific acquisition reason —
344
- // the shared evaluator produces the refuse decision; we map the
345
- // acquisition detail to the Operator reason. PRI-783: the evaluator's
346
- // generic next action suggests `pd pain record --session` — the exact
347
- // path that just failed — so every CLI acquisition refuse gets honest,
348
- // reason-specific guidance instead.
349
- const reason = opts.session !== undefined && acquisitionReason !== null
350
- ? acquisitionReason
351
- : decision.reasonCode;
352
- const detailSuffix = acquisitionDetail !== null ? ` (${acquisitionDetail})` : '';
353
- const nextAction =
354
- reason === 'session_not_found'
355
- ? 'Check the session id — it is not present in this workspace trajectory — or drop --session to record an unbound Owner report.'
356
- : reason === 'trajectory_unavailable'
357
- ? 'No trajectory.db exists in this workspace, so the session id could not be verified — point --workspace at the workspace that owns the session, or drop --session to record an unbound Owner report.'
358
- : reason === 'evidence_read_failed'
359
- ? 'The workspace trajectory could not be read, so the session id could not be verified — resolve access to .state/trajectory.db, or drop --session to record an unbound Owner report.'
360
- : decision.nextAction;
361
- emitSessionBindingFailure(opts, {
362
- reason,
363
- message: `${decision.warning}${detailSuffix}`,
364
- nextAction,
365
- });
366
- return;
367
- }
368
-
369
- const binding = decision.legacy;
370
- // SPEC §7.4: without a bound session the trajectory projection is skipped
371
- // (disclosed below) instead of fabricating the sentinel session 'cli'.
372
- const recordObservability = binding.sessionId !== undefined;
373
-
374
- const ledgerAdapter = new PrincipleTreeLedgerAdapter({ stateDir });
375
- // PRI-306: Load .pd/config.yaml for config-driven runtime binding
376
- const configResult = loadPdConfig(workspaceDir);
377
- if (!configResult.ok) {
378
- // ERR-009 / Runtime Contract Rule 9: fail loud with reason, don't silently swallow
379
- console.error(`Warning: .pd/config.yaml has errors — using defaults:`);
380
- for (const e of configResult.errors) {
381
- console.error(` ${e.path}: ${e.reason}`);
382
- if (e.nextAction) console.error(` nextAction: ${e.nextAction}`);
383
- }
384
- }
385
- const effectiveConfig = configResult.ok ? configResult.effective : configResult.defaults;
386
-
387
- // PRI-369: Determine async mode from feature flag + --wait override
388
- const featureFlags = computeFlagsFromLoadResult(configResult);
389
- const asyncFlagEnabled = isFeatureEnabled(featureFlags, 'diagnostician_async_cli');
390
- const asyncMode = asyncFlagEnabled && !opts.wait; // --wait overrides flag to force sync
391
-
392
- const service = new PainToPrincipleService({
393
- workspaceDir,
394
- stateDir,
395
- ledgerAdapter,
396
- owner: 'pd-cli',
397
- autoIntakeEnabled: true,
398
- effectiveConfig,
399
- getEnvVar: (name: string) => process.env[name],
400
- asyncMode,
401
- });
402
-
403
- const result = await service.recordPain({
404
- painId,
405
- painType: 'user_frustration',
406
- source: opts.source ?? 'manual',
407
- reason: opts.reason,
408
- score: opts.score ?? 80,
409
- sessionId: binding.sessionId,
410
- agentId: 'pd-cli',
411
- provenance: binding.provenance,
412
- hostKind: binding.hostKind,
413
- evidence: binding.evidence,
414
- recordObservability,
415
- painIngress: binding.painIngress,
416
- });
417
-
418
- // Show diagnostic info for config failures
419
- if (result.failureCategory === 'config_missing') {
420
- const legacyConfig = resolveRuntimeConfig(stateDir);
421
- if (isRuntimeConfigError(legacyConfig)) {
422
- if (opts.json) {
423
- console.log(JSON.stringify({
424
- status: 'failed',
425
- painId: result.painId,
426
- taskId: result.taskId,
427
- failureCategory: result.failureCategory,
428
- message: result.message,
429
- configError: {
430
- reason: legacyConfig.reason,
431
- message: legacyConfig.message,
432
- nextAction: legacyConfig.nextAction,
433
- },
434
- }, null, 2));
435
- } else {
436
- console.error(` Config resolution failed: ${legacyConfig.reason}`);
437
- console.error(` ${legacyConfig.message}`);
438
- console.error(` nextAction: ${legacyConfig.nextAction}`);
439
- }
440
- process.exit(1);
441
- return;
442
- }
443
- const config = legacyConfig;
444
- const missing: string[] = [];
445
- if (!config.provider) missing.push('provider');
446
- if (!config.model) missing.push('model');
447
- if (!config.apiKeyEnv) missing.push('apiKeyEnv');
448
- if (config.provider) {
449
- // PRI-621 PR2 review: the pi-ai catalog lookup is a core capability —
450
- // the CLI queries it through @principles/core and must not depend on
451
- // pi-ai directly (EP-06).
452
- if (!isBuiltinPiAiProvider(config.provider) && !config.baseUrl) {
453
- missing.push('baseUrl');
454
- }
455
- }
456
-
457
- if (missing.length > 0 || config.provider || config.apiKeyEnv) {
458
- console.error('Error: Pain signal failed\n');
459
-
460
- if (missing.length > 0) {
461
- console.error(' Missing configuration:');
462
- for (const m of missing) {
463
- console.error(` - ${m}`);
464
- }
465
- console.error('');
466
- }
467
-
468
- if (config.provider || config.model || config.apiKeyEnv || config.baseUrl) {
469
- console.error(' Current workflow policy (pd-runtime-v2-diagnosis):');
470
- console.error(` runtimeKind: ${config.runtimeKind}`);
471
- if (config.provider) console.error(` provider: ${config.provider}`);
472
- if (config.model) console.error(` model: ${config.model}`);
473
- if (config.apiKeyEnv) console.error(` apiKeyEnv: ${config.apiKeyEnv}`);
474
- if (config.baseUrl) console.error(` baseUrl: ${config.baseUrl}`);
475
- console.error('');
476
- }
477
-
478
- console.error(' To diagnose and configure your runtime, run:');
479
- console.error(' pd runtime probe --runtime pi-ai --provider <name> --model <id> --apiKeyEnv <name>');
480
- console.error('');
481
-
482
- if (result.message) console.error(` Details: ${result.message}`);
483
- process.exit(1);
484
- return;
485
- }
486
- }
487
-
488
- // PRI-642 (SPEC §12.1.6): generated-but-unadmitted candidates must never
489
- // read as completed internalization — surface the admission disposition.
490
- const admissionDecisions = result.admissionResults?.map(r => r.admission.decision) ?? [];
491
- const admittedCount = admissionDecisions.filter(d => d === 'admitted').length;
492
- const gatedWarning = result.status === 'succeeded'
493
- && result.candidateIds.length > 0
494
- && admittedCount === 0
495
- ? `admitted: 0 of ${result.candidateIds.length} candidates (all gated — needs_evidence/deferred); `
496
- + 'nothing was internalized. See admissionResults for per-candidate reasons; add --session evidence or Owner context to raise confidence above the admission threshold.'
497
- : null;
498
- // PRI-642: the ingress decision's own disclosures (degrade warning /
499
- // unbound context_unbound warning) are surfaced to the operator.
500
- const decisionWarnings = decision.action === 'degrade'
501
- ? [`${decision.warning} Next action: ${decision.nextAction}`]
502
- : decision.action === 'submit'
503
- ? decision.warnings
504
- : [];
505
- const cliWarnings = [...decisionWarnings, gatedWarning].filter((w): w is string => w !== null && w !== undefined);
506
-
507
- // PRI-743: the pre-existing 'openclaw' default is an assumption, not
508
- // evidence — disclose it whenever it actually applies (rc-9), so host
509
- // attribution can never silently distort PRI-743-style host comparisons.
510
- // Unbound reports (no --session) keep host_kind NULL: they carry no host
511
- // trace at all, so labelling them 'openclaw' would be a fresh misattribution
512
- // rather than a compatibility default.
513
- const hostDefaultWarning = binding.sessionId !== undefined && opts.host === undefined
514
- ? 'host kind not specified, defaulting to openclaw; pass --host codex with --rollout-id/--host-turn-id to attribute this pain to the Codex host.'
515
- : null;
516
- if (hostDefaultWarning !== null) cliWarnings.push(hostDefaultWarning);
517
-
518
- if (opts.json) {
519
- const out: Record<string, unknown> = { ...result };
520
- // PRI-743: surface the effective host attribution explicitly in --json
521
- // (machine consumers doing host comparisons must not re-derive it).
522
- if (binding.sessionId !== undefined) {
523
- out.hostAttribution = binding.hostKind;
524
- }
525
- // Ensure nextAction is present for actionable states
526
- if (out.status === 'submitted') {
527
- if (!out.nextAction) {
528
- out.nextAction = `pd diagnose run --task-id ${out.taskId} --workspace "${workspaceDir}" --runtime pi-ai --json`;
529
- }
530
- if (!out.reason) {
531
- out.reason = out.message;
532
- }
533
- }
534
- // PRI-570: async submission has NO automatic consumer — the
535
- // internalization auto-consumer's runner kinds (dreamer..rollout_reviewer)
536
- // do not include 'diagnostician', so a submitted task stays pending until
537
- // the owner runs the diagnose command. Never let that stay implicit (rc-9).
538
- // PRI-642: unbound/gated disclosures join the same warnings channel.
539
- const submittedWarning = out.status === 'submitted'
540
- ? 'Async mode: no background consumer picks up diagnostician tasks. '
541
- + `Run ${out.nextAction} or the pain signal will remain pending indefinitely. `
542
- + 'Use --wait to diagnose synchronously instead.'
543
- : null;
544
- const allWarnings = [...cliWarnings];
545
- if (submittedWarning !== null) allWarnings.unshift(submittedWarning);
546
- if (allWarnings.length > 0) {
547
- out.warning = allWarnings.join(' ');
548
- out.warnings = allWarnings;
549
- }
550
- console.log(JSON.stringify(out, null, 2));
551
- if (result.status !== 'succeeded' && result.status !== 'skipped' && result.status !== 'retried' && result.status !== 'submitted') {
552
- process.exit(1);
553
- return;
554
- }
555
- } else {
556
- if (result.status === 'succeeded') {
557
- console.log('[OK] Pain signal recorded via PainToPrincipleService');
558
- console.log(` Pain ID: ${result.painId}`);
559
- console.log(` Task ID: ${result.taskId}`);
560
- if (result.runId) console.log(` Run ID: ${result.runId}`);
561
- if (result.artifactId) console.log(` Artifact ID: ${result.artifactId}`);
562
- if (result.candidateIds.length > 0) console.log(` Candidate IDs: ${result.candidateIds.join(', ')}`);
563
- if (result.ledgerEntryIds.length > 0) console.log(` Ledger Entry IDs: ${result.ledgerEntryIds.join(', ')}`);
564
- if (result.progress && result.progress.seededTaskIds.length > 0) {
565
- console.log(` Seeded Task IDs: ${result.progress.seededTaskIds.join(', ')}`);
566
- }
567
- console.log(` Reason: ${opts.reason}`);
568
- console.log(` Score: ${opts.score ?? 80}`);
569
- console.log(` Source: ${opts.source ?? 'manual'}`);
570
- console.log(` Workspace: ${workspaceDir}`);
571
- if (binding.sessionId) {
572
- console.log(` Session: ${binding.sessionId} (bound, host=${binding.hostKind}, ${binding.evidence.length} evidence entries)`);
573
- } else {
574
- console.log(' Session: unbound (Owner report; no trajectory evidence)');
575
- }
576
- if (result.admissionResults && result.admissionResults.length > 0) {
577
- console.log(` Admission: ${admittedCount} of ${result.admissionResults.length} candidates admitted`);
578
- for (const r of result.admissionResults) {
579
- console.log(` - ${r.candidateId}: ${r.admission.decision} (${r.admission.reason})`);
580
- }
581
- }
582
- if (result.latencyMs !== undefined) console.log(` Latency: ${result.latencyMs}ms`);
583
- for (const w of cliWarnings) {
584
- console.warn(` ⚠️ ${w}`);
585
- }
586
- console.log(`\nDiagnostician pipeline running. Check progress with:`);
587
- console.log(` pd task show ${result.taskId} --workspace "${workspaceDir}"`);
588
- } else if (result.status === 'submitted') {
589
- console.log('[SUBMITTED] Pain signal submitted for async diagnosis');
590
- console.log(` Pain ID: ${result.painId}`);
591
- console.log(` Task ID: ${result.taskId}`);
592
- console.log(` Status: submitted`);
593
- // PRI-570: no background consumer picks up diagnostician tasks — say so
594
- // explicitly instead of implying async diagnosis happens on its own (rc-9).
595
- console.error(' WARNING: async mode has no automatic consumer for diagnostician tasks.');
596
- console.error(` Run: pd diagnose run --task-id ${result.taskId} --workspace "${workspaceDir}" --runtime pi-ai`);
597
- console.error(' Or re-record with --wait to diagnose synchronously. Without this, the task stays pending indefinitely.');
598
- } else if (result.status === 'skipped') {
599
- console.log(`[SKIP] Task already in progress: ${result.message ?? 'unknown'}`);
600
- console.log(` Pain ID: ${result.painId}`);
601
- console.log(` Task ID: ${result.taskId}`);
602
- } else if (result.status === 'retried') {
603
- console.log(`[RETRY] Task retried: ${result.message ?? 'unknown'}`);
604
- console.log(` Pain ID: ${result.painId}`);
605
- console.log(` Task ID: ${result.taskId}`);
606
- } else {
607
- console.error('[FAIL] Pain signal failed:', result.message);
608
- process.exit(1);
609
- return;
610
- }
611
- }
612
- }