@principles/pd-cli 1.152.12 → 1.152.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (305) hide show
  1. package/dist/commands/candidate.d.ts.map +1 -1
  2. package/dist/commands/candidate.js +34 -7
  3. package/dist/commands/candidate.js.map +1 -1
  4. package/dist/commands/diagnose.d.ts.map +1 -1
  5. package/dist/commands/diagnose.js +23 -7
  6. package/dist/commands/diagnose.js.map +1 -1
  7. package/dist/commands/pain-retry.d.ts.map +1 -1
  8. package/dist/commands/pain-retry.js +21 -7
  9. package/dist/commands/pain-retry.js.map +1 -1
  10. package/package.json +13 -7
  11. package/CHANGELOG.md +0 -23
  12. package/dist/commands/__tests__/intent-flag-wiring.test.d.ts +0 -9
  13. package/dist/commands/__tests__/intent-flag-wiring.test.d.ts.map +0 -1
  14. package/dist/commands/__tests__/intent-flag-wiring.test.js +0 -237
  15. package/dist/commands/__tests__/intent-flag-wiring.test.js.map +0 -1
  16. package/dist/commands/__tests__/legacy-cleanup.test.d.ts +0 -18
  17. package/dist/commands/__tests__/legacy-cleanup.test.d.ts.map +0 -1
  18. package/dist/commands/__tests__/legacy-cleanup.test.js +0 -467
  19. package/dist/commands/__tests__/legacy-cleanup.test.js.map +0 -1
  20. package/dist/commands/__tests__/mvp-smoke.test.d.ts +0 -15
  21. package/dist/commands/__tests__/mvp-smoke.test.d.ts.map +0 -1
  22. package/dist/commands/__tests__/mvp-smoke.test.js +0 -262
  23. package/dist/commands/__tests__/mvp-smoke.test.js.map +0 -1
  24. package/dist/commands/__tests__/pain-retry-maxTokens-flag.test.d.ts +0 -2
  25. package/dist/commands/__tests__/pain-retry-maxTokens-flag.test.d.ts.map +0 -1
  26. package/dist/commands/__tests__/pain-retry-maxTokens-flag.test.js +0 -60
  27. package/dist/commands/__tests__/pain-retry-maxTokens-flag.test.js.map +0 -1
  28. package/dist/commands/__tests__/rulecode-flag-wiring.test.d.ts +0 -21
  29. package/dist/commands/__tests__/rulecode-flag-wiring.test.d.ts.map +0 -1
  30. package/dist/commands/__tests__/rulecode-flag-wiring.test.js +0 -186
  31. package/dist/commands/__tests__/rulecode-flag-wiring.test.js.map +0 -1
  32. package/dist/commands/__tests__/rulecode-handler.test.d.ts +0 -16
  33. package/dist/commands/__tests__/rulecode-handler.test.d.ts.map +0 -1
  34. package/dist/commands/__tests__/rulecode-handler.test.js +0 -285
  35. package/dist/commands/__tests__/rulecode-handler.test.js.map +0 -1
  36. package/dist/commands/__tests__/run-rulehost-flag-wiring.test.d.ts +0 -24
  37. package/dist/commands/__tests__/run-rulehost-flag-wiring.test.d.ts.map +0 -1
  38. package/dist/commands/__tests__/run-rulehost-flag-wiring.test.js +0 -232
  39. package/dist/commands/__tests__/run-rulehost-flag-wiring.test.js.map +0 -1
  40. package/dist/commands/__tests__/runtime-activation-nextaction.test.d.ts +0 -15
  41. package/dist/commands/__tests__/runtime-activation-nextaction.test.d.ts.map +0 -1
  42. package/dist/commands/__tests__/runtime-activation-nextaction.test.js +0 -73
  43. package/dist/commands/__tests__/runtime-activation-nextaction.test.js.map +0 -1
  44. package/dist/commands/__tests__/runtime-probe-config.test.d.ts +0 -20
  45. package/dist/commands/__tests__/runtime-probe-config.test.d.ts.map +0 -1
  46. package/dist/commands/__tests__/runtime-probe-config.test.js +0 -389
  47. package/dist/commands/__tests__/runtime-probe-config.test.js.map +0 -1
  48. package/dist/commands/__tests__/telemetry-flag-wiring.test.d.ts +0 -9
  49. package/dist/commands/__tests__/telemetry-flag-wiring.test.d.ts.map +0 -1
  50. package/dist/commands/__tests__/telemetry-flag-wiring.test.js +0 -76
  51. package/dist/commands/__tests__/telemetry-flag-wiring.test.js.map +0 -1
  52. package/dist/commands/__tests__/version.test.d.ts +0 -2
  53. package/dist/commands/__tests__/version.test.d.ts.map +0 -1
  54. package/dist/commands/__tests__/version.test.js +0 -238
  55. package/dist/commands/__tests__/version.test.js.map +0 -1
  56. package/dist/commands/runtime-uat.guard.test.d.ts +0 -2
  57. package/dist/commands/runtime-uat.guard.test.d.ts.map +0 -1
  58. package/dist/commands/runtime-uat.guard.test.js +0 -153
  59. package/dist/commands/runtime-uat.guard.test.js.map +0 -1
  60. package/dist/services/__tests__/cli-output.test.d.ts +0 -18
  61. package/dist/services/__tests__/cli-output.test.d.ts.map +0 -1
  62. package/dist/services/__tests__/cli-output.test.js +0 -103
  63. package/dist/services/__tests__/cli-output.test.js.map +0 -1
  64. package/dist/services/__tests__/evaluator-runner-deps.test.d.ts +0 -2
  65. package/dist/services/__tests__/evaluator-runner-deps.test.d.ts.map +0 -1
  66. package/dist/services/__tests__/evaluator-runner-deps.test.js +0 -343
  67. package/dist/services/__tests__/evaluator-runner-deps.test.js.map +0 -1
  68. package/dist/services/__tests__/rulehost-readiness.test.d.ts +0 -2
  69. package/dist/services/__tests__/rulehost-readiness.test.d.ts.map +0 -1
  70. package/dist/services/__tests__/rulehost-readiness.test.js +0 -311
  71. package/dist/services/__tests__/rulehost-readiness.test.js.map +0 -1
  72. package/dist/services/__tests__/runtime-adapter-resolver.test.d.ts +0 -18
  73. package/dist/services/__tests__/runtime-adapter-resolver.test.d.ts.map +0 -1
  74. package/dist/services/__tests__/runtime-adapter-resolver.test.js +0 -673
  75. package/dist/services/__tests__/runtime-adapter-resolver.test.js.map +0 -1
  76. package/dist/utils/production-workspace-guard.test.d.ts +0 -2
  77. package/dist/utils/production-workspace-guard.test.d.ts.map +0 -1
  78. package/dist/utils/production-workspace-guard.test.js +0 -137
  79. package/dist/utils/production-workspace-guard.test.js.map +0 -1
  80. package/scripts/llm-dogfood.ts +0 -456
  81. package/scripts/migrate-illegal-expected-decision.ts +0 -252
  82. package/src/commands/__tests__/intent-flag-wiring.test.ts +0 -282
  83. package/src/commands/__tests__/legacy-cleanup.test.ts +0 -602
  84. package/src/commands/__tests__/mvp-smoke.test.ts +0 -300
  85. package/src/commands/__tests__/pain-retry-maxTokens-flag.test.ts +0 -73
  86. package/src/commands/__tests__/rulecode-flag-wiring.test.ts +0 -237
  87. package/src/commands/__tests__/rulecode-handler.test.ts +0 -369
  88. package/src/commands/__tests__/run-rulehost-flag-wiring.test.ts +0 -292
  89. package/src/commands/__tests__/runtime-activation-nextaction.test.ts +0 -81
  90. package/src/commands/__tests__/runtime-probe-config.test.ts +0 -432
  91. package/src/commands/__tests__/telemetry-flag-wiring.test.ts +0 -84
  92. package/src/commands/__tests__/version.test.ts +0 -251
  93. package/src/commands/admission-gate.ts +0 -30
  94. package/src/commands/artifact.ts +0 -82
  95. package/src/commands/build-trajectory-evidence.ts +0 -298
  96. package/src/commands/candidate.ts +0 -1250
  97. package/src/commands/codex-ingest-catchup.ts +0 -114
  98. package/src/commands/codex-ingest-quarantine.ts +0 -127
  99. package/src/commands/codex-reconcile.ts +0 -84
  100. package/src/commands/codex-setup.ts +0 -476
  101. package/src/commands/codex-worker.ts +0 -185
  102. package/src/commands/command-helpers.ts +0 -24
  103. package/src/commands/config-doctor.ts +0 -193
  104. package/src/commands/console.ts +0 -797
  105. package/src/commands/context.ts +0 -72
  106. package/src/commands/demo-story-a.ts +0 -241
  107. package/src/commands/diagnose.ts +0 -756
  108. package/src/commands/errors-list.ts +0 -441
  109. package/src/commands/evolution-tasks-list.ts +0 -48
  110. package/src/commands/evolution-tasks-show.ts +0 -62
  111. package/src/commands/flow.ts +0 -60
  112. package/src/commands/health-codex.ts +0 -576
  113. package/src/commands/health.ts +0 -315
  114. package/src/commands/history.ts +0 -63
  115. package/src/commands/intent.ts +0 -457
  116. package/src/commands/legacy-cleanup.ts +0 -531
  117. package/src/commands/legacy-import.ts +0 -104
  118. package/src/commands/mvp-smoke.ts +0 -160
  119. package/src/commands/pain-evidence.ts +0 -226
  120. package/src/commands/pain-list.ts +0 -239
  121. package/src/commands/pain-record.ts +0 -612
  122. package/src/commands/pain-retry.ts +0 -916
  123. package/src/commands/principles-stats.ts +0 -700
  124. package/src/commands/proven-channel-baseline.ts +0 -115
  125. package/src/commands/quality-scorecard.ts +0 -272
  126. package/src/commands/remediation-output.ts +0 -66
  127. package/src/commands/rulecode.ts +0 -465
  128. package/src/commands/run.ts +0 -89
  129. package/src/commands/runtime-activation.ts +0 -1629
  130. package/src/commands/runtime-artifact-repair.ts +0 -524
  131. package/src/commands/runtime-canary.ts +0 -395
  132. package/src/commands/runtime-compatibility-scan.ts +0 -105
  133. package/src/commands/runtime-diagnostics-export.ts +0 -229
  134. package/src/commands/runtime-features.ts +0 -153
  135. package/src/commands/runtime-gfi-snapshot.ts +0 -135
  136. package/src/commands/runtime-health-snapshot.ts +0 -108
  137. package/src/commands/runtime-init.ts +0 -429
  138. package/src/commands/runtime-internalization-enqueue-successors.ts +0 -530
  139. package/src/commands/runtime-internalization-integrity-repair.ts +0 -79
  140. package/src/commands/runtime-internalization-integrity.ts +0 -107
  141. package/src/commands/runtime-internalization-queue.ts +0 -135
  142. package/src/commands/runtime-internalization-retry.ts +0 -191
  143. package/src/commands/runtime-internalization-run-once.ts +0 -791
  144. package/src/commands/runtime-internalization-run-rulehost.ts +0 -749
  145. package/src/commands/runtime-internalization-wake-once.ts +0 -87
  146. package/src/commands/runtime-pain-flood-simulation.ts +0 -121
  147. package/src/commands/runtime-pruning.ts +0 -438
  148. package/src/commands/runtime-recovery-failed-tasks.ts +0 -258
  149. package/src/commands/runtime-recovery.ts +0 -109
  150. package/src/commands/runtime-synthetic-baseline.ts +0 -70
  151. package/src/commands/runtime-uat.guard.test.ts +0 -175
  152. package/src/commands/runtime-uat.ts +0 -380
  153. package/src/commands/runtime.ts +0 -473
  154. package/src/commands/samples-list.ts +0 -39
  155. package/src/commands/samples-review.ts +0 -36
  156. package/src/commands/task.ts +0 -271
  157. package/src/commands/telemetry.ts +0 -349
  158. package/src/commands/trace.ts +0 -174
  159. package/src/commands/trajectory-db-unavailable.ts +0 -19
  160. package/src/commands/trajectory.ts +0 -64
  161. package/src/commands/version.ts +0 -49
  162. package/src/config-reader.ts +0 -122
  163. package/src/index.ts +0 -1276
  164. package/src/legacy/legacy-import.ts +0 -179
  165. package/src/legacy/session-history-import.ts +0 -203
  166. package/src/resolve-workspace.ts +0 -106
  167. package/src/services/__tests__/cli-output.test.ts +0 -130
  168. package/src/services/__tests__/evaluator-runner-deps.test.ts +0 -382
  169. package/src/services/__tests__/rulehost-readiness.test.ts +0 -363
  170. package/src/services/__tests__/runtime-adapter-resolver.test.ts +0 -793
  171. package/src/services/cli-output.ts +0 -95
  172. package/src/services/config-doctor.ts +0 -697
  173. package/src/services/console-launcher.ts +0 -537
  174. package/src/services/demo-rule-compiler.ts +0 -40
  175. package/src/services/demo-story-a-runner.ts +0 -471
  176. package/src/services/mainline-snapshot-assembler.ts +0 -579
  177. package/src/services/pain-flood-simulation-runner.ts +0 -462
  178. package/src/services/pd-config-loader.ts +0 -433
  179. package/src/services/proven-channel-baseline-runner.ts +0 -157
  180. package/src/services/quality-scorecard/data-extractor.ts +0 -150
  181. package/src/services/quality-scorecard/local-evaluator.ts +0 -142
  182. package/src/services/quality-scorecard/strong-model-gate.ts +0 -202
  183. package/src/services/resolve-runtime-from-pd-config.ts +0 -230
  184. package/src/services/rulehost-pipeline-runner.ts +0 -1214
  185. package/src/services/rulehost-readiness.ts +0 -326
  186. package/src/services/runtime-adapter-resolver.ts +0 -364
  187. package/src/services/synthetic-baseline-runner.ts +0 -400
  188. package/src/services/version-report.ts +0 -253
  189. package/src/services/workspace-tool-semantics.ts +0 -26
  190. package/src/utils/path-security.ts +0 -96
  191. package/src/utils/production-workspace-guard.test.ts +0 -157
  192. package/src/utils/production-workspace-guard.ts +0 -210
  193. package/tests/bdd/cli-contract.steps.ts +0 -346
  194. package/tests/bdd/principles-stats.steps.ts +0 -211
  195. package/tests/bdd/support/gherkin-loader.ts +0 -147
  196. package/tests/bdd/support/repo-root.ts +0 -62
  197. package/tests/bdd/support/vitest-bdd.ts +0 -179
  198. package/tests/commands/admission-gate-coverage.test.ts +0 -79
  199. package/tests/commands/build-trajectory-evidence.test.ts +0 -508
  200. package/tests/commands/candidate-audit-repair.test.ts +0 -421
  201. package/tests/commands/candidate-intake.test.ts +0 -732
  202. package/tests/commands/candidate-internalization-backfill.test.ts +0 -548
  203. package/tests/commands/candidate-internalize-lineage.test.ts +0 -628
  204. package/tests/commands/candidate-internalize.test.ts +0 -299
  205. package/tests/commands/candidate-route.test.ts +0 -329
  206. package/tests/commands/candidate-show.test.ts +0 -95
  207. package/tests/commands/cli-command-tree.test.ts +0 -144
  208. package/tests/commands/cli-help-snapshot.test.ts +0 -155
  209. package/tests/commands/cli-skill-contract.test.ts +0 -121
  210. package/tests/commands/codex-consent-reversibility.steps.test.ts +0 -299
  211. package/tests/commands/codex-ingest-quarantine.test.ts +0 -136
  212. package/tests/commands/codex-setup.test.ts +0 -297
  213. package/tests/commands/codex-worker-daemon.test.ts +0 -95
  214. package/tests/commands/codex-worker-registration.test.ts +0 -207
  215. package/tests/commands/config-doctor.test.ts +0 -336
  216. package/tests/commands/console-launcher-edge-cases.test.ts +0 -388
  217. package/tests/commands/console-open.test.ts +0 -1381
  218. package/tests/commands/context.test.ts +0 -114
  219. package/tests/commands/demo-story-a.test.ts +0 -318
  220. package/tests/commands/diagnose.test.ts +0 -1803
  221. package/tests/commands/errors-list.test.ts +0 -679
  222. package/tests/commands/evolution-tasks-list.test.ts +0 -41
  223. package/tests/commands/evolution-tasks-show.test.ts +0 -46
  224. package/tests/commands/health-codex.test.ts +0 -349
  225. package/tests/commands/health-host-wiring.test.ts +0 -76
  226. package/tests/commands/health-reliability.test.ts +0 -99
  227. package/tests/commands/health.test.ts +0 -413
  228. package/tests/commands/intent.test.ts +0 -321
  229. package/tests/commands/legacy-cleanup.test.ts +0 -148
  230. package/tests/commands/pain-evidence.test.ts +0 -518
  231. package/tests/commands/pain-list.test.ts +0 -219
  232. package/tests/commands/pain-record-async.test.ts +0 -335
  233. package/tests/commands/pain-record-session-parser.test.ts +0 -228
  234. package/tests/commands/pain-record.test.ts +0 -851
  235. package/tests/commands/pain-retry.test.ts +0 -1121
  236. package/tests/commands/plugin-config-resolution-cutover.test.ts +0 -229
  237. package/tests/commands/pri-393-runtime-config-unification.test.ts +0 -443
  238. package/tests/commands/principles-stats-wiring.test.ts +0 -135
  239. package/tests/commands/principles-stats.test.ts +0 -274
  240. package/tests/commands/product-path-regression.test.ts +0 -86
  241. package/tests/commands/proven-channel-baseline.test.ts +0 -441
  242. package/tests/commands/rulecode.test.ts +0 -177
  243. package/tests/commands/run-rulehost-handler.test.ts +0 -908
  244. package/tests/commands/runtime-activation-approve-flag-wiring.test.ts +0 -227
  245. package/tests/commands/runtime-activation-deactivate-flag-wiring.test.ts +0 -167
  246. package/tests/commands/runtime-activation-dispatch-flag-wiring.test.ts +0 -262
  247. package/tests/commands/runtime-activation-governance-audit.test.ts +0 -95
  248. package/tests/commands/runtime-activation-list-flag-wiring.test.ts +0 -193
  249. package/tests/commands/runtime-activation-promote-flag-wiring.test.ts +0 -248
  250. package/tests/commands/runtime-activation-shadow-telemetry.test.ts +0 -130
  251. package/tests/commands/runtime-activation.test.ts +0 -2052
  252. package/tests/commands/runtime-artifact-repair-registration.test.ts +0 -74
  253. package/tests/commands/runtime-artifact-repair.test.ts +0 -404
  254. package/tests/commands/runtime-canary.test.ts +0 -430
  255. package/tests/commands/runtime-compatibility-scan.test.ts +0 -146
  256. package/tests/commands/runtime-diagnostics-export.test.ts +0 -175
  257. package/tests/commands/runtime-features.test.ts +0 -249
  258. package/tests/commands/runtime-health-snapshot.test.ts +0 -358
  259. package/tests/commands/runtime-init-empty-workspace.test.ts +0 -252
  260. package/tests/commands/runtime-init.test.ts +0 -420
  261. package/tests/commands/runtime-internalization-enqueue-successors.test.ts +0 -782
  262. package/tests/commands/runtime-internalization-integrity-repair.test.ts +0 -239
  263. package/tests/commands/runtime-internalization-integrity.test.ts +0 -140
  264. package/tests/commands/runtime-internalization-queue.test.ts +0 -380
  265. package/tests/commands/runtime-internalization-retry-owner-authority.test.ts +0 -431
  266. package/tests/commands/runtime-internalization-run-once-evaluator-parity.test.ts +0 -269
  267. package/tests/commands/runtime-internalization-run-once-language.test.ts +0 -303
  268. package/tests/commands/runtime-internalization-run-once-real-config.test.ts +0 -237
  269. package/tests/commands/runtime-internalization-run-once-rollout-parity.test.ts +0 -706
  270. package/tests/commands/runtime-internalization-run-once.test.ts +0 -1791
  271. package/tests/commands/runtime-internalization-wake-once.test.ts +0 -171
  272. package/tests/commands/runtime-internalization.test.ts +0 -53
  273. package/tests/commands/runtime-pain-flood-simulation.test.ts +0 -418
  274. package/tests/commands/runtime-pruning.test.ts +0 -694
  275. package/tests/commands/runtime-recovery-failed-tasks.test.ts +0 -328
  276. package/tests/commands/runtime-recovery.test.ts +0 -120
  277. package/tests/commands/runtime-synthetic-baseline.test.ts +0 -249
  278. package/tests/commands/runtime-uat.test.ts +0 -397
  279. package/tests/commands/runtime.test.ts +0 -392
  280. package/tests/commands/samples-list.test.ts +0 -43
  281. package/tests/commands/samples-review.test.ts +0 -41
  282. package/tests/commands/task.test.ts +0 -153
  283. package/tests/commands/telemetry.test.ts +0 -190
  284. package/tests/commands/trace.test.ts +0 -316
  285. package/tests/config-reader.test.ts +0 -143
  286. package/tests/e2e/candidate-intake-e2e.test.ts +0 -338
  287. package/tests/e2e/cli-full-flow.test.ts +0 -233
  288. package/tests/e2e/cross-package-acceptance.test.ts +0 -635
  289. package/tests/helpers/pd-cli-path.ts +0 -5
  290. package/tests/pd-cli-smoke.test.ts +0 -13
  291. package/tests/resolve-workspace.test.ts +0 -196
  292. package/tests/services/config-doctor-signal-health.test.ts +0 -109
  293. package/tests/services/console-launcher.test.ts +0 -114
  294. package/tests/services/demo-rule-compiler.test.ts +0 -242
  295. package/tests/services/mainline-snapshot-assembler.test.ts +0 -572
  296. package/tests/services/pd-config-loader.test.ts +0 -505
  297. package/tests/services/proven-channel-baseline-runner.test.ts +0 -30
  298. package/tests/services/quality-scorecard/strong-model-gate.test.ts +0 -133
  299. package/tests/services/resolve-runtime-from-pd-config.test.ts +0 -485
  300. package/tests/services/rulehost-pipeline-e2e.test.ts +0 -538
  301. package/tests/services/rulehost-pipeline-runner.test.ts +0 -1242
  302. package/tests/services/workspace-tool-semantics.test.ts +0 -76
  303. package/tests/utils/path-security.test.ts +0 -180
  304. package/tsconfig.json +0 -26
  305. package/vitest.config.ts +0 -10
@@ -1,441 +0,0 @@
1
- /**
2
- * pd errors list — List PD pipeline errors (failed tasks + worker errors).
3
- *
4
- * Usage:
5
- * pd errors list [--json] [--kind <runnerKind>] [--since <hours>] [--limit <n>] [--workspace <path>]
6
- *
7
- * Aggregates two error sources into a single operator-facing read-only view:
8
- * 1. SQLite state.db tasks where status IN ('failed', 'needs_human_review')
9
- * (via SqliteTaskStore.listFailedTasks — Task 8).
10
- * 2. worker-status.json `errors` array written by EvolutionWorker
11
- * (Task 2 extended the entry shape to { at, kind, principleId, error } | string).
12
- *
13
- * CLI gate compliance:
14
- * - cli-1-strict-json: --json stdout is exactly one parseable JSON object.
15
- * - cli-2-exit-stops: every process.exit(...) is immediately followed by return.
16
- * - cli-6-output-next-action: empty result includes a `nextAction` field.
17
- * - cli-4-dry-run-confirm-mutex: N/A (read-only command).
18
- *
19
- * Runtime contract compliance:
20
- * - rc-1-treat-as-unknown: worker-status.json parsed content is treated as unknown.
21
- * - rc-2-no-as-bypass: no `as` casts; runtime validation via typeof / Array.isArray.
22
- * - rc-4-validate-array-elements: errors array elements are validated element-wise.
23
- * - rc-5-object-hasown-not-in: Object.hasOwn used for untrusted object key checks.
24
- * - rc-9-no-silent-fallback: missing worker-status.json → workerErrors=[]
25
- * silently (expected steady state — the writer retired in PRI-737);
26
- * parse failures surface a `workerStatusWarning`.
27
- */
28
- import * as path from 'path';
29
- import * as fs from 'fs';
30
- import type { Command } from 'commander';
31
- import { SqliteConnection, SqliteTaskStore } from '@principles/core';
32
- import { resolveWorkspaceDir } from '../resolve-workspace.js';
33
-
34
- /**
35
- * Options accepted by the `pd errors list` command.
36
- *
37
- * `since` is in hours (CLI surface); converted to a Unix-ms timestamp when
38
- * passed to SqliteTaskStore.listFailedTasks.
39
- */
40
- export interface ErrorsListOptions {
41
- workspace?: string;
42
- json?: boolean;
43
- kind?: string;
44
- since?: number; // hours
45
- limit?: number;
46
- }
47
-
48
- /** Default and maximum values for --limit. */
49
- const DEFAULT_LIMIT = 50;
50
- const MAX_LIMIT = 200;
51
-
52
- /**
53
- * Type guard: narrow `unknown` to a plain record (rc-2: no `as` bypass).
54
- * Returns true only for non-null, non-array objects.
55
- */
56
- function isRecord(value: unknown): value is Record<string, unknown> {
57
- return value !== null && typeof value === 'object' && !Array.isArray(value);
58
- }
59
-
60
- /**
61
- * Normalized worker-status.json error entry (legacy evolution worker,
62
- * retired in PRI-737). Structured entries are `{ at, kind, principleId, error }`;
63
- * legacy entries are bare strings. We normalize both shapes to a structured
64
- * form for output. The writer is gone, so this section reports
65
- * workerStatusMissing on any workspace that never ran the legacy worker.
66
- */
67
- interface WorkerErrorEntry {
68
- at: string | null;
69
- kind: string | null;
70
- principleId: string | null;
71
- error: string;
72
- rawForm: 'object' | 'string';
73
- }
74
-
75
- /** Aggregated result returned by the command (JSON or text-rendered). */
76
- interface ErrorsListResult {
77
- tasks: unknown[];
78
- workerErrors: WorkerErrorEntry[];
79
- total: number;
80
- workerStatusPath: string;
81
- workerStatusWarning?: string;
82
- nextAction?: string;
83
- }
84
-
85
- /**
86
- * Validate and normalize a single worker-status.json errors entry.
87
- *
88
- * rc-1: input is `unknown` (parsed from JSON).
89
- * rc-2: no `as` — uses typeof / Object.hasOwn guards.
90
- * rc-5: Object.hasOwn for key checks (not `in`).
91
- *
92
- * Accepts:
93
- * - string → { error: <string>, rawForm: 'string', others null }
94
- * - { at, kind, principleId, error } → normalized object
95
- * Anything else → null (skipped; caller records a warning).
96
- */
97
- function normalizeWorkerErrorEntry(entry: unknown): WorkerErrorEntry | null {
98
- if (typeof entry === 'string') {
99
- return {
100
- at: null,
101
- kind: null,
102
- principleId: null,
103
- error: entry,
104
- rawForm: 'string',
105
- };
106
- }
107
- // rc-2: type guard instead of `as` cast (isRecord narrows unknown → record).
108
- if (!isRecord(entry)) {
109
- return null;
110
- }
111
- // rc-5: use Object.hasOwn, not `in`, for untrusted object key checks.
112
- const at = Object.hasOwn(entry, 'at') && typeof entry.at === 'string' ? entry.at : null;
113
- const kind = Object.hasOwn(entry, 'kind') && typeof entry.kind === 'string' ? entry.kind : null;
114
- const principleId =
115
- Object.hasOwn(entry, 'principleId') && typeof entry.principleId === 'string' ? entry.principleId : null;
116
- // `error` is the only required field for the object form; if missing or
117
- // non-string, fall back to JSON.stringify so we don't lose the entry.
118
- let errorStr: string;
119
- if (Object.hasOwn(entry, 'error') && typeof entry.error === 'string') {
120
- errorStr = entry.error;
121
- } else {
122
- try {
123
- errorStr = JSON.stringify(entry);
124
- } catch {
125
- errorStr = '[unserializable worker-status error entry]';
126
- }
127
- }
128
- return {
129
- at,
130
- kind,
131
- principleId,
132
- error: errorStr,
133
- rawForm: 'object',
134
- };
135
- }
136
-
137
- /**
138
- * Read and validate the worker-status.json `errors` array.
139
- *
140
- * Returns `{ entries, missing, warning }`:
141
- * - `missing: true` if the file does not exist (not an error — worker hasn't run).
142
- * - `warning: string` if the file exists but is unparseable / wrong shape
143
- * (rc-9: surface the reason, do not silently swallow).
144
- * - `entries: WorkerErrorEntry[]` validated element-wise (rc-4).
145
- */
146
- function readWorkerStatusErrors(stateDir: string): {
147
- entries: WorkerErrorEntry[];
148
- missing: boolean;
149
- warning: string | null;
150
- } {
151
- const statusPath = path.join(stateDir, 'worker-status.json');
152
- if (!fs.existsSync(statusPath)) {
153
- return { entries: [], missing: true, warning: null };
154
- }
155
- let raw: string;
156
- try {
157
- raw = fs.readFileSync(statusPath, 'utf8');
158
- } catch (err) {
159
- return {
160
- entries: [],
161
- missing: false,
162
- warning: `Failed to read worker-status.json: ${err instanceof Error ? err.message : String(err)}`,
163
- };
164
- }
165
- // rc-1: parsed JSON is unknown.
166
- let parsed: unknown;
167
- try {
168
- parsed = JSON.parse(raw);
169
- } catch (err) {
170
- return {
171
- entries: [],
172
- missing: false,
173
- warning: `Failed to parse worker-status.json: ${err instanceof Error ? err.message : String(err)}`,
174
- };
175
- }
176
- if (!isRecord(parsed)) {
177
- return {
178
- entries: [],
179
- missing: false,
180
- warning: 'worker-status.json root is not a JSON object',
181
- };
182
- }
183
- // rc-5: Object.hasOwn for untrusted key check.
184
- if (!Object.hasOwn(parsed, 'errors')) {
185
- // No `errors` field — treat as empty (older worker-status.json may lack it).
186
- return { entries: [], missing: false, warning: null };
187
- }
188
- const errorsField = parsed.errors;
189
- if (!Array.isArray(errorsField)) {
190
- return {
191
- entries: [],
192
- missing: false,
193
- warning: 'worker-status.json `errors` field is not an array',
194
- };
195
- }
196
- // rc-4: validate array element types; skip malformed entries.
197
- const entries: WorkerErrorEntry[] = [];
198
- let skipped = 0;
199
- for (const item of errorsField) {
200
- const normalized = normalizeWorkerErrorEntry(item);
201
- if (normalized === null) {
202
- skipped++;
203
- continue;
204
- }
205
- entries.push(normalized);
206
- }
207
- const warning =
208
- skipped > 0
209
- ? `Skipped ${skipped} malformed worker-status.json error entr${skipped === 1 ? 'y' : 'ies'}`
210
- : null;
211
- return { entries, missing: false, warning };
212
- }
213
-
214
- function formatTextOutput(result: ErrorsListResult, workspaceDir: string): string {
215
- const lines: string[] = [];
216
- lines.push('PD Errors List');
217
- lines.push(` workspace: ${workspaceDir}`);
218
- lines.push(` total: ${result.total} (tasks: ${result.tasks.length}, workerErrors: ${result.workerErrors.length})`);
219
- lines.push('');
220
- if (result.workerStatusWarning) {
221
- lines.push(` workerStatus: WARNING — ${result.workerStatusWarning}`);
222
- }
223
- if (result.tasks.length > 0) {
224
- lines.push('');
225
- lines.push('Failed tasks:');
226
- for (const t of result.tasks) {
227
- // rc-2: type guard instead of `as` cast — tasks come from SqliteTaskStore
228
- // which returns FailedTaskSummary[], but we typed tasks as unknown[] to
229
- // keep the result interface decoupled from core's type exports.
230
- const task = isRecord(t) ? t : null;
231
- const taskId = task && typeof task.taskId === 'string' ? task.taskId : '?';
232
- const taskKind = task && typeof task.taskKind === 'string' ? task.taskKind : '?';
233
- const status = task && typeof task.status === 'string' ? task.status : '?';
234
- const lastError = task && typeof task.lastError === 'string' ? task.lastError : '-';
235
- const attemptCount = task && typeof task.attemptCount === 'number' ? task.attemptCount : 0;
236
- const painId = task && typeof task.painId === 'string' ? task.painId : '-';
237
- const lastAttemptAt = task && typeof task.lastAttemptAt === 'string' ? task.lastAttemptAt : '-';
238
- lines.push(` - ${taskId} (${taskKind}) [${status}]`);
239
- lines.push(` painId: ${painId}`);
240
- lines.push(` lastError: ${lastError}`);
241
- lines.push(` attemptCount: ${attemptCount}`);
242
- lines.push(` lastAttemptAt: ${lastAttemptAt}`);
243
- }
244
- }
245
- if (result.workerErrors.length > 0) {
246
- lines.push('');
247
- lines.push('Worker errors:');
248
- for (const e of result.workerErrors) {
249
- const at = e.at ?? '-';
250
- const kind = e.kind ?? '-';
251
- const pid = e.principleId ?? '-';
252
- lines.push(` - [${at}] kind=${kind} principleId=${pid}`);
253
- lines.push(` error: ${e.error}`);
254
- }
255
- }
256
- if (result.total === 0) {
257
- lines.push('');
258
- lines.push('No errors found. PD pipeline is healthy.');
259
- }
260
- return lines.join('\n');
261
- }
262
-
263
- export async function handleErrorsList(opts: ErrorsListOptions): Promise<void> {
264
- const workspaceDir = opts.workspace ? path.resolve(opts.workspace) : resolveWorkspaceDir();
265
- const stateDir = path.join(workspaceDir, '.pd');
266
- const stateDbPath = path.join(stateDir, 'state.db');
267
-
268
- // Pre-check: if state.db does not exist, fail loud (cli-2-exit-stops + rc-9).
269
- if (!fs.existsSync(stateDbPath)) {
270
- const msg = `Error: state.db not found at ${stateDbPath}. Workspace may not be initialized.`;
271
- if (opts.json) {
272
- // cli-1: even error JSON is a single object on stdout? No — cli-2 says
273
- // failure paths write to stderr. JSON error envelope goes to stderr too
274
- // so stdout stays clean (cli-1-strict-json guarantees stdout is parseable).
275
- process.stderr.write(
276
- JSON.stringify(
277
- {
278
- ok: false,
279
- reason: msg,
280
- nextAction: 'Run "pd runtime init --confirm --workspace <dir>" to initialize databases, then retry.',
281
- },
282
- null,
283
- 2,
284
- ) + '\n',
285
- );
286
- } else {
287
- process.stderr.write(msg + '\n');
288
- }
289
- process.exitCode = 1;
290
- return; // cli-2-exit-stops
291
- }
292
-
293
- // Resolve and validate --limit.
294
- let limit = DEFAULT_LIMIT;
295
- if (opts.limit !== undefined) {
296
- if (!Number.isFinite(opts.limit) || opts.limit <= 0) {
297
- const msg = `Error: --limit must be a positive integer, got ${opts.limit}`;
298
- // cli-6-output-next-action: mirror the state.db missing branch — when
299
- // opts.json is true, emit a structured { ok:false, reason, nextAction }
300
- // envelope to stderr instead of plain text.
301
- if (opts.json) {
302
- process.stderr.write(
303
- JSON.stringify(
304
- {
305
- ok: false,
306
- reason: msg,
307
- nextAction: 'Pass --limit as a positive integer (e.g. --limit 50). Maximum is 500.',
308
- },
309
- null,
310
- 2,
311
- ) + '\n',
312
- );
313
- } else {
314
- process.stderr.write(msg + '\n');
315
- }
316
- process.exitCode = 1;
317
- return; // cli-2-exit-stops
318
- }
319
- limit = Math.min(opts.limit, MAX_LIMIT);
320
- }
321
-
322
- // Resolve --since (hours → Unix-ms timestamp).
323
- let sinceMs: number | undefined;
324
- if (opts.since !== undefined) {
325
- if (!Number.isFinite(opts.since) || opts.since < 0) {
326
- const msg = `Error: --since must be a non-negative number of hours, got ${opts.since}`;
327
- // cli-6-output-next-action: same JSON envelope pattern as --limit above.
328
- if (opts.json) {
329
- process.stderr.write(
330
- JSON.stringify(
331
- {
332
- ok: false,
333
- reason: msg,
334
- nextAction: 'Pass --since as a non-negative number of hours (e.g. --since 24 for the last 24h).',
335
- },
336
- null,
337
- 2,
338
- ) + '\n',
339
- );
340
- } else {
341
- process.stderr.write(msg + '\n');
342
- }
343
- process.exitCode = 1;
344
- return; // cli-2-exit-stops
345
- }
346
- sinceMs = Date.now() - opts.since * 3600 * 1000;
347
- }
348
-
349
- const connection = new SqliteConnection({ workspaceDir, readonly: true });
350
- try {
351
- const taskStore = new SqliteTaskStore(connection);
352
- const tasks = await taskStore.listFailedTasks({
353
- kind: opts.kind,
354
- since: sinceMs,
355
- limit,
356
- });
357
-
358
- // PRI-737: the worker-status.json writer (legacy evolution worker) is
359
- // retired, so a missing file is the expected steady state — only genuine
360
- // parse/read failures surface as workerStatusWarning. The
361
- // workerStatusMissing flag is no longer set.
362
- const { entries: workerErrors, warning } = readWorkerStatusErrors(stateDir);
363
-
364
- const total = tasks.length + workerErrors.length;
365
- const result: ErrorsListResult = {
366
- tasks,
367
- workerErrors,
368
- total,
369
- workerStatusPath: path.join(stateDir, 'worker-status.json'),
370
- };
371
- if (warning) {
372
- result.workerStatusWarning = warning;
373
- }
374
- // cli-6-output-next-action: include nextAction only when there are no errors.
375
- if (total === 0) {
376
- result.nextAction = 'No errors found. PD pipeline is healthy.';
377
- }
378
-
379
- if (opts.json) {
380
- // cli-1-strict-json: stdout is exactly one parseable JSON object.
381
- console.log(JSON.stringify(result, null, 2));
382
- } else {
383
- console.log(formatTextOutput(result, workspaceDir));
384
- }
385
- } catch (err: unknown) {
386
- const message = err instanceof Error ? err.message : String(err);
387
- if (opts.json) {
388
- process.stderr.write(
389
- JSON.stringify(
390
- {
391
- ok: false,
392
- reason: `Failed to list errors: ${message}`,
393
- nextAction: 'Check workspace path and state.db readability, then retry.',
394
- },
395
- null,
396
- 2,
397
- ) + '\n',
398
- );
399
- } else {
400
- process.stderr.write(`Error: ${message}\n`);
401
- }
402
- process.exitCode = 1;
403
- return; // cli-2-exit-stops
404
- } finally {
405
- connection.close();
406
- }
407
- }
408
-
409
- /**
410
- * Register the `errors` command group with `list` subcommand on a Commander
411
- * program. Used by both production CLI (src/index.ts) and parser-level tests
412
- * (cli-7-test-wiring).
413
- *
414
- * The `errors` command group is hidden from `pd --help` (operator diagnostic,
415
- * same convention as `legacy` / `artifact` / `runtime recovery`).
416
- */
417
- export function registerErrorsListCommand(program: Command): Command {
418
- const errorsCmd = program
419
- .command('errors', { hidden: true })
420
- .description('PD pipeline error inspection (failed tasks + worker errors)');
421
-
422
- errorsCmd
423
- .command('list')
424
- .description('List PD pipeline errors — failed tasks + worker-status.json errors')
425
- .option('-w, --workspace <path>', 'Workspace directory')
426
- .option('--json', 'Output raw JSON (cli-1-strict-json: stdout is exactly one JSON object)')
427
- .option('--kind <runnerKind>', 'Filter failed tasks by task_kind (e.g. diagnostician, dreamer)')
428
- .option('--since <hours>', 'Only show errors from the last N hours (non-negative number)', parseInt)
429
- .option('--limit <n>', 'Max failed tasks to return (default: 50, max: 200)', parseInt)
430
- .action(async (opts) => {
431
- await handleErrorsList({
432
- workspace: opts.workspace,
433
- json: opts.json === true,
434
- kind: opts.kind,
435
- since: opts.since,
436
- limit: opts.limit,
437
- });
438
- });
439
-
440
- return errorsCmd;
441
- }
@@ -1,48 +0,0 @@
1
- /**
2
- * pd evolution tasks list command implementation.
3
- *
4
- * Usage: pd evolution tasks list [--status pending|in_progress|completed|all]
5
- * [--limit <number>] [--date-from <date>] [--date-to <date>]
6
- */
7
-
8
- import { listEvolutionTasks, TrajectoryDbUnavailableError } from '@principles/core/evolution-store';
9
- import { resolveWorkspaceDir } from '../resolve-workspace.js';
10
- import { exitWithTrajectoryDbUnavailable } from './trajectory-db-unavailable.js';
11
-
12
- interface EvolutionTasksListOptions {
13
- status?: string;
14
- limit?: number;
15
- dateFrom?: string;
16
- dateTo?: string;
17
- }
18
-
19
- export async function handleEvolutionTasksList(opts: EvolutionTasksListOptions): Promise<void> {
20
- const workspaceDir = resolveWorkspaceDir();
21
-
22
- let tasks;
23
- try {
24
- tasks = listEvolutionTasks(workspaceDir, {
25
- status: opts.status === 'all' ? undefined : opts.status,
26
- limit: opts.limit,
27
- dateFrom: opts.dateFrom,
28
- dateTo: opts.dateTo,
29
- });
30
- } catch (err) {
31
- if (err instanceof TrajectoryDbUnavailableError) {
32
- return exitWithTrajectoryDbUnavailable(err);
33
- }
34
- throw err;
35
- }
36
-
37
- if (tasks.length === 0) {
38
- console.log('No evolution tasks found.');
39
- return;
40
- }
41
- for (const task of tasks) {
42
- const enqueuedAt = task.enqueuedAt ?? 'null';
43
- console.log(
44
- `[${task.status}] ${task.taskId} (${task.taskKind}) score=${task.score} source=${task.source} enqueued=${enqueuedAt}`
45
- );
46
- }
47
- console.log(`${tasks.length} task(s)`);
48
- }
@@ -1,62 +0,0 @@
1
- /**
2
- * pd evolution tasks show command implementation.
3
- *
4
- * Usage: pd evolution tasks show <id>
5
- *
6
- * Displays full details for a single evolution task.
7
- * Accepts both numeric id and string taskId.
8
- */
9
-
10
- import { getEvolutionTask, TrajectoryDbUnavailableError } from '@principles/core/evolution-store';
11
- import { resolveWorkspaceDir } from '../resolve-workspace.js';
12
- import { exitWithTrajectoryDbUnavailable } from './trajectory-db-unavailable.js';
13
-
14
- interface EvolutionTasksShowOptions {
15
- id: string;
16
- }
17
-
18
- export async function handleEvolutionTasksShow(opts: EvolutionTasksShowOptions): Promise<void> {
19
- const workspaceDir = resolveWorkspaceDir();
20
-
21
- let foundTask;
22
- try {
23
- const numericId = isNaN(Number(opts.id)) ? undefined : Number(opts.id);
24
- foundTask = getEvolutionTask(workspaceDir, numericId ?? opts.id);
25
- } catch (err) {
26
- if (err instanceof TrajectoryDbUnavailableError) {
27
- return exitWithTrajectoryDbUnavailable(err);
28
- }
29
- throw err;
30
- }
31
-
32
- if (!foundTask) {
33
- console.error(`Task not found: ${opts.id}`);
34
- process.exit(1);
35
- }
36
-
37
- const fields = [
38
- ['id', String(foundTask.id)],
39
- ['taskId', foundTask.taskId],
40
- ['traceId', foundTask.traceId],
41
- ['source', foundTask.source],
42
- ['reason', foundTask.reason ?? 'null'],
43
- ['score', String(foundTask.score)],
44
- ['status', foundTask.status],
45
- ['enqueuedAt', foundTask.enqueuedAt ?? 'null'],
46
- ['startedAt', foundTask.startedAt ?? 'null'],
47
- ['completedAt', foundTask.completedAt ?? 'null'],
48
- ['resolution', foundTask.resolution ?? 'null'],
49
- ['taskKind', foundTask.taskKind ?? 'null'],
50
- ['priority', foundTask.priority ?? 'null'],
51
- ['retryCount', foundTask.retryCount != null ? String(foundTask.retryCount) : 'null'],
52
- ['maxRetries', foundTask.maxRetries != null ? String(foundTask.maxRetries) : 'null'],
53
- ['lastError', foundTask.lastError ?? 'null'],
54
- ['resultRef', foundTask.resultRef ?? 'null'],
55
- ['createdAt', foundTask.createdAt],
56
- ['updatedAt', foundTask.updatedAt],
57
- ];
58
-
59
- for (const [key, value] of fields) {
60
- console.log(`${key}: ${value}`);
61
- }
62
- }
@@ -1,60 +0,0 @@
1
- /**
2
- * pd runtime flow show command — Display workflow funnel definitions from workflows.yaml.
3
- *
4
- * Usage:
5
- * pd runtime flow show [--workspace <path>] [--json]
6
- */
7
- import * as path from 'path';
8
- import { WorkflowFunnelLoader } from '@principles/core';
9
-
10
- interface FlowShowOptions {
11
- workspace?: string;
12
- json?: boolean;
13
- }
14
-
15
- export async function handleFlowShow(opts: FlowShowOptions): Promise<void> {
16
- const workspaceDir = opts.workspace ?? process.cwd();
17
- const stateDir = path.join(workspaceDir, '.state');
18
-
19
- const loader = new WorkflowFunnelLoader(stateDir);
20
-
21
- if (opts.json) {
22
- const all = loader.getAllFunnelsWithPolicy();
23
- console.log(JSON.stringify({ status: 'ok', funnels: [...all.values()] }, null, 2));
24
- return;
25
- }
26
-
27
- const all = loader.getAllFunnelsWithPolicy();
28
- const funnels = [...all.values()];
29
-
30
- if (funnels.length === 0) {
31
- console.log('Workflows: (no funnels defined)\n');
32
- return;
33
- }
34
-
35
- console.log(`Workflows (${funnels.length} funnel${funnels.length !== 1 ? 's' : ''}):\n`);
36
-
37
- for (const funnel of funnels) {
38
- console.log(` ${funnel.workflowId}`);
39
- if (funnel.policy) {
40
- const p = funnel.policy;
41
- if (p.timeoutMs) console.log(` timeoutMs: ${p.timeoutMs}`);
42
- if (p.stageOrder) console.log(` stageOrder: ${p.stageOrder}`);
43
- if (p.legacyDisabled !== undefined) console.log(` legacyDisabled: ${p.legacyDisabled}`);
44
- if (p.observability?.enabled !== undefined) console.log(` observability: ${p.observability.enabled}`);
45
- if (p.observability?.logLevel) console.log(` logLevel: ${p.observability.logLevel}`);
46
- if (p.observability?.emitEvents?.length) {
47
- console.log(` emitEvents: ${p.observability.emitEvents.join(', ')}`);
48
- }
49
- }
50
- console.log(` stages (${funnel.stages.length}):`);
51
- for (const stage of funnel.stages) {
52
- const parts = [` - ${stage.name}`];
53
- if (stage.timeoutMs) parts.push(` timeoutMs=${stage.timeoutMs}`);
54
- if (stage.successCriteria) parts.push(` successCriteria="${stage.successCriteria}"`);
55
- if (stage.legacyDisabled) parts.push(` legacyDisabled`);
56
- console.log(parts.join(''));
57
- }
58
- console.log('');
59
- }
60
- }