@principles/pd-cli 1.73.0

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 (298) hide show
  1. package/README.md +90 -0
  2. package/dist/commands/artifact.d.ts +14 -0
  3. package/dist/commands/artifact.d.ts.map +1 -0
  4. package/dist/commands/artifact.js +67 -0
  5. package/dist/commands/artifact.js.map +1 -0
  6. package/dist/commands/candidate.d.ts +83 -0
  7. package/dist/commands/candidate.d.ts.map +1 -0
  8. package/dist/commands/candidate.js +891 -0
  9. package/dist/commands/candidate.js.map +1 -0
  10. package/dist/commands/central-sync.d.ts +10 -0
  11. package/dist/commands/central-sync.d.ts.map +1 -0
  12. package/dist/commands/central-sync.js +32 -0
  13. package/dist/commands/central-sync.js.map +1 -0
  14. package/dist/commands/console.d.ts +9 -0
  15. package/dist/commands/console.d.ts.map +1 -0
  16. package/dist/commands/console.js +114 -0
  17. package/dist/commands/console.js.map +1 -0
  18. package/dist/commands/context.d.ts +7 -0
  19. package/dist/commands/context.d.ts.map +1 -0
  20. package/dist/commands/context.js +55 -0
  21. package/dist/commands/context.js.map +1 -0
  22. package/dist/commands/demo-story-a.d.ts +12 -0
  23. package/dist/commands/demo-story-a.d.ts.map +1 -0
  24. package/dist/commands/demo-story-a.js +175 -0
  25. package/dist/commands/demo-story-a.js.map +1 -0
  26. package/dist/commands/diagnose.d.ts +35 -0
  27. package/dist/commands/diagnose.d.ts.map +1 -0
  28. package/dist/commands/diagnose.js +390 -0
  29. package/dist/commands/diagnose.js.map +1 -0
  30. package/dist/commands/evolution-tasks-list.d.ts +15 -0
  31. package/dist/commands/evolution-tasks-list.d.ts.map +1 -0
  32. package/dist/commands/evolution-tasks-list.js +34 -0
  33. package/dist/commands/evolution-tasks-list.js.map +1 -0
  34. package/dist/commands/evolution-tasks-show.d.ts +14 -0
  35. package/dist/commands/evolution-tasks-show.d.ts.map +1 -0
  36. package/dist/commands/evolution-tasks-show.js +52 -0
  37. package/dist/commands/evolution-tasks-show.js.map +1 -0
  38. package/dist/commands/flow.d.ts +7 -0
  39. package/dist/commands/flow.d.ts.map +1 -0
  40. package/dist/commands/flow.js +57 -0
  41. package/dist/commands/flow.js.map +1 -0
  42. package/dist/commands/health.d.ts +16 -0
  43. package/dist/commands/health.d.ts.map +1 -0
  44. package/dist/commands/health.js +150 -0
  45. package/dist/commands/health.js.map +1 -0
  46. package/dist/commands/history.d.ts +11 -0
  47. package/dist/commands/history.d.ts.map +1 -0
  48. package/dist/commands/history.js +50 -0
  49. package/dist/commands/history.js.map +1 -0
  50. package/dist/commands/legacy-cleanup.d.ts +27 -0
  51. package/dist/commands/legacy-cleanup.d.ts.map +1 -0
  52. package/dist/commands/legacy-cleanup.js +171 -0
  53. package/dist/commands/legacy-cleanup.js.map +1 -0
  54. package/dist/commands/legacy-import.d.ts +7 -0
  55. package/dist/commands/legacy-import.d.ts.map +1 -0
  56. package/dist/commands/legacy-import.js +86 -0
  57. package/dist/commands/legacy-import.js.map +1 -0
  58. package/dist/commands/pain-record.d.ts +10 -0
  59. package/dist/commands/pain-record.d.ts.map +1 -0
  60. package/dist/commands/pain-record.js +162 -0
  61. package/dist/commands/pain-record.js.map +1 -0
  62. package/dist/commands/proven-channel-baseline.d.ts +12 -0
  63. package/dist/commands/proven-channel-baseline.d.ts.map +1 -0
  64. package/dist/commands/proven-channel-baseline.js +97 -0
  65. package/dist/commands/proven-channel-baseline.js.map +1 -0
  66. package/dist/commands/remediation-output.d.ts +40 -0
  67. package/dist/commands/remediation-output.d.ts.map +1 -0
  68. package/dist/commands/remediation-output.js +23 -0
  69. package/dist/commands/remediation-output.js.map +1 -0
  70. package/dist/commands/run.d.ts +10 -0
  71. package/dist/commands/run.d.ts.map +1 -0
  72. package/dist/commands/run.js +68 -0
  73. package/dist/commands/run.js.map +1 -0
  74. package/dist/commands/runtime-activation.d.ts +11 -0
  75. package/dist/commands/runtime-activation.d.ts.map +1 -0
  76. package/dist/commands/runtime-activation.js +150 -0
  77. package/dist/commands/runtime-activation.js.map +1 -0
  78. package/dist/commands/runtime-canary.d.ts +30 -0
  79. package/dist/commands/runtime-canary.d.ts.map +1 -0
  80. package/dist/commands/runtime-canary.js +343 -0
  81. package/dist/commands/runtime-canary.js.map +1 -0
  82. package/dist/commands/runtime-diagnostics-export.d.ts +20 -0
  83. package/dist/commands/runtime-diagnostics-export.d.ts.map +1 -0
  84. package/dist/commands/runtime-diagnostics-export.js +177 -0
  85. package/dist/commands/runtime-diagnostics-export.js.map +1 -0
  86. package/dist/commands/runtime-features.d.ts +26 -0
  87. package/dist/commands/runtime-features.d.ts.map +1 -0
  88. package/dist/commands/runtime-features.js +70 -0
  89. package/dist/commands/runtime-features.js.map +1 -0
  90. package/dist/commands/runtime-gfi-snapshot.d.ts +7 -0
  91. package/dist/commands/runtime-gfi-snapshot.d.ts.map +1 -0
  92. package/dist/commands/runtime-gfi-snapshot.js +101 -0
  93. package/dist/commands/runtime-gfi-snapshot.js.map +1 -0
  94. package/dist/commands/runtime-health-snapshot.d.ts +7 -0
  95. package/dist/commands/runtime-health-snapshot.d.ts.map +1 -0
  96. package/dist/commands/runtime-health-snapshot.js +93 -0
  97. package/dist/commands/runtime-health-snapshot.js.map +1 -0
  98. package/dist/commands/runtime-idle-trigger.d.ts +12 -0
  99. package/dist/commands/runtime-idle-trigger.d.ts.map +1 -0
  100. package/dist/commands/runtime-idle-trigger.js +102 -0
  101. package/dist/commands/runtime-idle-trigger.js.map +1 -0
  102. package/dist/commands/runtime-internalization-enqueue-successors.d.ts +9 -0
  103. package/dist/commands/runtime-internalization-enqueue-successors.d.ts.map +1 -0
  104. package/dist/commands/runtime-internalization-enqueue-successors.js +393 -0
  105. package/dist/commands/runtime-internalization-enqueue-successors.js.map +1 -0
  106. package/dist/commands/runtime-internalization-integrity-repair.d.ts +9 -0
  107. package/dist/commands/runtime-internalization-integrity-repair.d.ts.map +1 -0
  108. package/dist/commands/runtime-internalization-integrity-repair.js +54 -0
  109. package/dist/commands/runtime-internalization-integrity-repair.js.map +1 -0
  110. package/dist/commands/runtime-internalization-integrity.d.ts +7 -0
  111. package/dist/commands/runtime-internalization-integrity.d.ts.map +1 -0
  112. package/dist/commands/runtime-internalization-integrity.js +53 -0
  113. package/dist/commands/runtime-internalization-integrity.js.map +1 -0
  114. package/dist/commands/runtime-internalization-queue.d.ts +7 -0
  115. package/dist/commands/runtime-internalization-queue.d.ts.map +1 -0
  116. package/dist/commands/runtime-internalization-queue.js +85 -0
  117. package/dist/commands/runtime-internalization-queue.js.map +1 -0
  118. package/dist/commands/runtime-internalization-run-once.d.ts +12 -0
  119. package/dist/commands/runtime-internalization-run-once.d.ts.map +1 -0
  120. package/dist/commands/runtime-internalization-run-once.js +546 -0
  121. package/dist/commands/runtime-internalization-run-once.js.map +1 -0
  122. package/dist/commands/runtime-internalization-wake-once.d.ts +8 -0
  123. package/dist/commands/runtime-internalization-wake-once.d.ts.map +1 -0
  124. package/dist/commands/runtime-internalization-wake-once.js +72 -0
  125. package/dist/commands/runtime-internalization-wake-once.js.map +1 -0
  126. package/dist/commands/runtime-pain-flood-simulation.d.ts +10 -0
  127. package/dist/commands/runtime-pain-flood-simulation.d.ts.map +1 -0
  128. package/dist/commands/runtime-pain-flood-simulation.js +104 -0
  129. package/dist/commands/runtime-pain-flood-simulation.js.map +1 -0
  130. package/dist/commands/runtime-pruning.d.ts +45 -0
  131. package/dist/commands/runtime-pruning.d.ts.map +1 -0
  132. package/dist/commands/runtime-pruning.js +355 -0
  133. package/dist/commands/runtime-pruning.js.map +1 -0
  134. package/dist/commands/runtime-recovery.d.ts +9 -0
  135. package/dist/commands/runtime-recovery.d.ts.map +1 -0
  136. package/dist/commands/runtime-recovery.js +94 -0
  137. package/dist/commands/runtime-recovery.js.map +1 -0
  138. package/dist/commands/runtime-synthetic-baseline.d.ts +7 -0
  139. package/dist/commands/runtime-synthetic-baseline.d.ts.map +1 -0
  140. package/dist/commands/runtime-synthetic-baseline.js +59 -0
  141. package/dist/commands/runtime-synthetic-baseline.js.map +1 -0
  142. package/dist/commands/runtime-uat.d.ts +52 -0
  143. package/dist/commands/runtime-uat.d.ts.map +1 -0
  144. package/dist/commands/runtime-uat.js +274 -0
  145. package/dist/commands/runtime-uat.js.map +1 -0
  146. package/dist/commands/runtime.d.ts +20 -0
  147. package/dist/commands/runtime.d.ts.map +1 -0
  148. package/dist/commands/runtime.js +256 -0
  149. package/dist/commands/runtime.js.map +1 -0
  150. package/dist/commands/samples-list.d.ts +11 -0
  151. package/dist/commands/samples-list.d.ts.map +1 -0
  152. package/dist/commands/samples-list.js +37 -0
  153. package/dist/commands/samples-list.js.map +1 -0
  154. package/dist/commands/samples-review.d.ts +14 -0
  155. package/dist/commands/samples-review.d.ts.map +1 -0
  156. package/dist/commands/samples-review.js +22 -0
  157. package/dist/commands/samples-review.js.map +1 -0
  158. package/dist/commands/task.d.ts +14 -0
  159. package/dist/commands/task.d.ts.map +1 -0
  160. package/dist/commands/task.js +92 -0
  161. package/dist/commands/task.js.map +1 -0
  162. package/dist/commands/trace.d.ts +19 -0
  163. package/dist/commands/trace.d.ts.map +1 -0
  164. package/dist/commands/trace.js +154 -0
  165. package/dist/commands/trace.js.map +1 -0
  166. package/dist/commands/trajectory.d.ts +11 -0
  167. package/dist/commands/trajectory.d.ts.map +1 -0
  168. package/dist/commands/trajectory.js +47 -0
  169. package/dist/commands/trajectory.js.map +1 -0
  170. package/dist/index.d.ts +9 -0
  171. package/dist/index.d.ts.map +1 -0
  172. package/dist/index.js +736 -0
  173. package/dist/index.js.map +1 -0
  174. package/dist/legacy/legacy-import.d.ts +15 -0
  175. package/dist/legacy/legacy-import.d.ts.map +1 -0
  176. package/dist/legacy/legacy-import.js +141 -0
  177. package/dist/legacy/legacy-import.js.map +1 -0
  178. package/dist/legacy/session-history-import.d.ts +26 -0
  179. package/dist/legacy/session-history-import.d.ts.map +1 -0
  180. package/dist/legacy/session-history-import.js +151 -0
  181. package/dist/legacy/session-history-import.js.map +1 -0
  182. package/dist/principle-tree-ledger-adapter.d.ts +12 -0
  183. package/dist/principle-tree-ledger-adapter.d.ts.map +1 -0
  184. package/dist/principle-tree-ledger-adapter.js +12 -0
  185. package/dist/principle-tree-ledger-adapter.js.map +1 -0
  186. package/dist/resolve-workspace.d.ts +12 -0
  187. package/dist/resolve-workspace.d.ts.map +1 -0
  188. package/dist/resolve-workspace.js +20 -0
  189. package/dist/resolve-workspace.js.map +1 -0
  190. package/dist/services/demo-story-a-runner.d.ts +8 -0
  191. package/dist/services/demo-story-a-runner.d.ts.map +1 -0
  192. package/dist/services/demo-story-a-runner.js +369 -0
  193. package/dist/services/demo-story-a-runner.js.map +1 -0
  194. package/dist/services/feature-flag-loader.d.ts +6 -0
  195. package/dist/services/feature-flag-loader.d.ts.map +1 -0
  196. package/dist/services/feature-flag-loader.js +54 -0
  197. package/dist/services/feature-flag-loader.js.map +1 -0
  198. package/dist/services/pain-flood-simulation-runner.d.ts +10 -0
  199. package/dist/services/pain-flood-simulation-runner.d.ts.map +1 -0
  200. package/dist/services/pain-flood-simulation-runner.js +289 -0
  201. package/dist/services/pain-flood-simulation-runner.js.map +1 -0
  202. package/dist/services/proven-channel-baseline-runner.d.ts +12 -0
  203. package/dist/services/proven-channel-baseline-runner.d.ts.map +1 -0
  204. package/dist/services/proven-channel-baseline-runner.js +114 -0
  205. package/dist/services/proven-channel-baseline-runner.js.map +1 -0
  206. package/dist/services/synthetic-baseline-runner.d.ts +8 -0
  207. package/dist/services/synthetic-baseline-runner.d.ts.map +1 -0
  208. package/dist/services/synthetic-baseline-runner.js +251 -0
  209. package/dist/services/synthetic-baseline-runner.js.map +1 -0
  210. package/package.json +35 -0
  211. package/src/commands/artifact.ts +82 -0
  212. package/src/commands/candidate.ts +1117 -0
  213. package/src/commands/central-sync.ts +44 -0
  214. package/src/commands/console.ts +121 -0
  215. package/src/commands/context.ts +72 -0
  216. package/src/commands/demo-story-a.ts +195 -0
  217. package/src/commands/diagnose.ts +452 -0
  218. package/src/commands/evolution-tasks-list.ts +44 -0
  219. package/src/commands/evolution-tasks-show.ts +60 -0
  220. package/src/commands/flow.ts +60 -0
  221. package/src/commands/health.ts +189 -0
  222. package/src/commands/history.ts +63 -0
  223. package/src/commands/legacy-cleanup.ts +206 -0
  224. package/src/commands/legacy-import.ts +104 -0
  225. package/src/commands/pain-record.ts +167 -0
  226. package/src/commands/proven-channel-baseline.ts +113 -0
  227. package/src/commands/remediation-output.ts +66 -0
  228. package/src/commands/run.ts +89 -0
  229. package/src/commands/runtime-activation.ts +176 -0
  230. package/src/commands/runtime-canary.ts +371 -0
  231. package/src/commands/runtime-diagnostics-export.ts +229 -0
  232. package/src/commands/runtime-features.ts +103 -0
  233. package/src/commands/runtime-gfi-snapshot.ts +135 -0
  234. package/src/commands/runtime-health-snapshot.ts +106 -0
  235. package/src/commands/runtime-internalization-enqueue-successors.ts +479 -0
  236. package/src/commands/runtime-internalization-integrity-repair.ts +69 -0
  237. package/src/commands/runtime-internalization-integrity.ts +63 -0
  238. package/src/commands/runtime-internalization-queue.ts +106 -0
  239. package/src/commands/runtime-internalization-run-once.ts +658 -0
  240. package/src/commands/runtime-internalization-wake-once.ts +87 -0
  241. package/src/commands/runtime-pain-flood-simulation.ts +121 -0
  242. package/src/commands/runtime-pruning.ts +438 -0
  243. package/src/commands/runtime-recovery.ts +107 -0
  244. package/src/commands/runtime-synthetic-baseline.ts +70 -0
  245. package/src/commands/runtime-uat.ts +339 -0
  246. package/src/commands/runtime.ts +281 -0
  247. package/src/commands/samples-list.ts +43 -0
  248. package/src/commands/samples-review.ts +32 -0
  249. package/src/commands/task.ts +130 -0
  250. package/src/commands/trace.ts +174 -0
  251. package/src/commands/trajectory.ts +64 -0
  252. package/src/index.ts +829 -0
  253. package/src/legacy/legacy-import.ts +179 -0
  254. package/src/legacy/session-history-import.ts +231 -0
  255. package/src/principle-tree-ledger-adapter.ts +13 -0
  256. package/src/resolve-workspace.ts +20 -0
  257. package/src/services/demo-story-a-runner.ts +472 -0
  258. package/src/services/feature-flag-loader.ts +73 -0
  259. package/src/services/pain-flood-simulation-runner.ts +354 -0
  260. package/src/services/proven-channel-baseline-runner.ts +150 -0
  261. package/src/services/synthetic-baseline-runner.ts +291 -0
  262. package/tests/commands/candidate-audit-repair.test.ts +338 -0
  263. package/tests/commands/candidate-intake.test.ts +589 -0
  264. package/tests/commands/candidate-internalization-backfill.test.ts +480 -0
  265. package/tests/commands/candidate-internalize.test.ts +272 -0
  266. package/tests/commands/candidate-route.test.ts +328 -0
  267. package/tests/commands/candidate-show.test.ts +95 -0
  268. package/tests/commands/cli-command-tree.test.ts +64 -0
  269. package/tests/commands/context.test.ts +114 -0
  270. package/tests/commands/demo-story-a.test.ts +255 -0
  271. package/tests/commands/diagnose.test.ts +792 -0
  272. package/tests/commands/health.test.ts +330 -0
  273. package/tests/commands/pain-record.test.ts +316 -0
  274. package/tests/commands/plugin-config-resolution-cutover.test.ts +220 -0
  275. package/tests/commands/proven-channel-baseline.test.ts +441 -0
  276. package/tests/commands/runtime-activation.test.ts +168 -0
  277. package/tests/commands/runtime-canary.test.ts +369 -0
  278. package/tests/commands/runtime-diagnostics-export.test.ts +170 -0
  279. package/tests/commands/runtime-features.test.ts +114 -0
  280. package/tests/commands/runtime-health-snapshot.test.ts +357 -0
  281. package/tests/commands/runtime-internalization-enqueue-successors.test.ts +803 -0
  282. package/tests/commands/runtime-internalization-integrity-repair.test.ts +169 -0
  283. package/tests/commands/runtime-internalization-integrity.test.ts +102 -0
  284. package/tests/commands/runtime-internalization-queue.test.ts +252 -0
  285. package/tests/commands/runtime-internalization-run-once.test.ts +1318 -0
  286. package/tests/commands/runtime-internalization-wake-once.test.ts +170 -0
  287. package/tests/commands/runtime-internalization.test.ts +52 -0
  288. package/tests/commands/runtime-pain-flood-simulation.test.ts +418 -0
  289. package/tests/commands/runtime-pruning.test.ts +693 -0
  290. package/tests/commands/runtime-recovery.test.ts +96 -0
  291. package/tests/commands/runtime-synthetic-baseline.test.ts +249 -0
  292. package/tests/commands/runtime-uat.test.ts +397 -0
  293. package/tests/commands/runtime.test.ts +262 -0
  294. package/tests/commands/trace.test.ts +314 -0
  295. package/tests/e2e/candidate-intake-e2e.test.ts +316 -0
  296. package/tests/services/feature-flag-loader.test.ts +207 -0
  297. package/tests/services/proven-channel-baseline-runner.test.ts +30 -0
  298. package/tsconfig.json +26 -0
package/dist/index.js ADDED
@@ -0,0 +1,736 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * pd CLI — Principles Disciple command-line interface.
4
+ *
5
+ * Usage:
6
+ * pd pain record --reason <text> [--score N] [--source manual]
7
+ */
8
+ import { Command } from 'commander';
9
+ import { handlePainRecord } from './commands/pain-record.js';
10
+ import { handleSamplesList } from './commands/samples-list.js';
11
+ import { handleSamplesReview } from './commands/samples-review.js';
12
+ import { handleEvolutionTasksList } from './commands/evolution-tasks-list.js';
13
+ import { handleEvolutionTasksShow } from './commands/evolution-tasks-show.js';
14
+ import { handleHealth } from './commands/health.js';
15
+ import { handleCentralSync } from './commands/central-sync.js';
16
+ import { handleTaskList, handleTaskShow } from './commands/task.js';
17
+ import { handleRunList, handleRunShow } from './commands/run.js';
18
+ import { handleTrajectoryLocate } from './commands/trajectory.js';
19
+ import { handleHistoryQuery } from './commands/history.js';
20
+ import { handleContextBuild } from './commands/context.js';
21
+ import { handleLegacyImportOpenClaw } from './commands/legacy-import.js';
22
+ import { handleLegacyCleanup } from './commands/legacy-cleanup.js';
23
+ import { handleDiagnoseStatus, handleDiagnoseRun } from './commands/diagnose.js';
24
+ import { handleRuntimeProbe } from './commands/runtime.js';
25
+ import { handleFlowShow } from './commands/flow.js';
26
+ import { handleTraceShow } from './commands/trace.js';
27
+ import { handlePruningReport, handlePruningExplain, handlePruningReview, handlePruningRollback, handlePruningOrphans } from './commands/runtime-pruning.js';
28
+ import { handleRuntimeHealthSnapshot } from './commands/runtime-health-snapshot.js';
29
+ import { handleRuntimeGfiSnapshot } from './commands/runtime-gfi-snapshot.js';
30
+ import { handleRuntimeUat } from './commands/runtime-uat.js';
31
+ import { handleRuntimeInternalizationQueue } from './commands/runtime-internalization-queue.js';
32
+ import { handleRuntimeInternalizationWakeOnce } from './commands/runtime-internalization-wake-once.js';
33
+ import { handleRuntimeInternalizationRunOnce } from './commands/runtime-internalization-run-once.js';
34
+ import { handleCandidateList, handleCandidateShow, handleCandidateIntake, handleCandidateAudit, handleCandidateRepair, handleCandidateRoute, handleCandidateInternalize, handleCandidateInternalizationBackfill } from './commands/candidate.js';
35
+ import { handleArtifactShow } from './commands/artifact.js';
36
+ import { handleRuntimeCanary } from './commands/runtime-canary.js';
37
+ import { handleRuntimeSyntheticBaseline } from './commands/runtime-synthetic-baseline.js';
38
+ import { handleRuntimePainFlood } from './commands/runtime-pain-flood-simulation.js';
39
+ import { handleRuntimeInternalizationIntegrity } from './commands/runtime-internalization-integrity.js';
40
+ import { handleRuntimeInternalizationIntegrityRepair } from './commands/runtime-internalization-integrity-repair.js';
41
+ import { handleRuntimeInternalizationEnqueueSuccessors } from './commands/runtime-internalization-enqueue-successors.js';
42
+ import { handleRuntimeDiagnosticsExport } from './commands/runtime-diagnostics-export.js';
43
+ import { handleRuntimeRecoverySweep } from './commands/runtime-recovery.js';
44
+ import { handleRuntimeActivationDispatch } from './commands/runtime-activation.js';
45
+ import { handleProvenChannelBaseline } from './commands/proven-channel-baseline.js';
46
+ import { handleDemoStoryA } from './commands/demo-story-a.js';
47
+ import { handleRuntimeFeaturesStatus } from './commands/runtime-features.js';
48
+ const program = new Command();
49
+ program
50
+ .name('pd')
51
+ .description('PD CLI — Pain recording, sample management, and evolution tasks')
52
+ .version('0.1.0');
53
+ const painCmd = program
54
+ .command('pain')
55
+ .description('Pain signal management');
56
+ painCmd
57
+ .command('record')
58
+ .description('Record a pain signal via Runtime v2 bridge')
59
+ .option('-r, --reason <text>', 'Reason for the pain signal (required)')
60
+ .option('-s, --score <number>', 'Pain score 0-100', parseInt)
61
+ .option('-S, --source <text>', 'Source of the pain signal', 'manual')
62
+ .option('-w, --workspace <path>', 'Workspace directory')
63
+ .option('--json', 'Output raw JSON')
64
+ .action(async (opts) => {
65
+ await handlePainRecord(opts);
66
+ });
67
+ const samplesCmd = program
68
+ .command('samples')
69
+ .description('Correction sample management');
70
+ samplesCmd
71
+ .command('list')
72
+ .description('List correction samples')
73
+ .option('-s, --status <pending|approved|rejected>', 'Filter by review status', 'pending')
74
+ .action(async (opts) => {
75
+ await handleSamplesList(opts);
76
+ });
77
+ samplesCmd
78
+ .command('review')
79
+ .description('Review a correction sample')
80
+ .argument('<sample-id>', 'The sample ID to review')
81
+ .argument('<approve|reject>', 'Review decision')
82
+ .argument('[note]', 'Optional review note')
83
+ .action(async (sampleId, decision, note) => {
84
+ if (decision !== 'approve' && decision !== 'reject') {
85
+ console.error('Error: decision must be "approve" or "reject"');
86
+ process.exit(1);
87
+ }
88
+ await handleSamplesReview({ sampleId, decision: decision === 'approve' ? 'approved' : 'rejected', note });
89
+ });
90
+ const evolutionCmd = program
91
+ .command('evolution')
92
+ .description('Evolution task management');
93
+ const tasksCmd = evolutionCmd
94
+ .command('tasks')
95
+ .description('List and show evolution tasks');
96
+ tasksCmd
97
+ .command('list')
98
+ .description('List evolution tasks')
99
+ .option('-s, --status <status>', 'Filter by status (pending|in_progress|completed|all)', 'all')
100
+ .option('-l, --limit <number>', 'Maximum tasks to return', parseInt, 50)
101
+ .option('-f, --date-from <date>', 'Filter tasks created on or after this date')
102
+ .option('-t, --date-to <date>', 'Filter tasks created on or before this date')
103
+ .action(async (opts) => {
104
+ await handleEvolutionTasksList(opts);
105
+ });
106
+ tasksCmd
107
+ .command('show')
108
+ .description('Show full details for an evolution task')
109
+ .argument('<id>', 'Task ID (numeric or string taskId)')
110
+ .action(async (id, _opts) => {
111
+ await handleEvolutionTasksShow({ id });
112
+ });
113
+ program
114
+ .command('health')
115
+ .description('Show health diagnostics for all workspaces')
116
+ .option('-w, --workspace <path>', 'Workspace directory')
117
+ .option('--json', 'Output raw JSON')
118
+ .action(async (opts) => {
119
+ await handleHealth(opts);
120
+ });
121
+ const centralCmd = program
122
+ .command('central')
123
+ .description('Central server management');
124
+ centralCmd
125
+ .command('sync')
126
+ .description('Trigger a sync cycle and report results')
127
+ .action(async () => {
128
+ await handleCentralSync();
129
+ });
130
+ // ── Runtime v2 task/run commands ──────────────────────────────────────────────
131
+ const rtTaskCmd = program
132
+ .command('task')
133
+ .description('Runtime v2 task inspection');
134
+ rtTaskCmd
135
+ .command('list')
136
+ .description('List runtime tasks')
137
+ .option('-s, --status <status>', 'Filter by status (pending, leased, retry_wait, succeeded, failed)')
138
+ .option('-k, --kind <kind>', 'Filter by task kind')
139
+ .option('-l, --limit <number>', 'Limit number of results', parseInt, 50)
140
+ .action(async (opts) => {
141
+ await handleTaskList(opts);
142
+ });
143
+ rtTaskCmd
144
+ .command('show <taskId>')
145
+ .description('Show detailed task information')
146
+ .option('-w, --workspace <path>', 'Workspace directory')
147
+ .option('--json', 'Output raw JSON')
148
+ .action(async (taskId, opts) => {
149
+ await handleTaskShow({ id: taskId, json: opts.json, workspace: opts.workspace });
150
+ });
151
+ const rtRunCmd = program
152
+ .command('run')
153
+ .description('Runtime v2 run inspection');
154
+ rtRunCmd
155
+ .command('list <taskId>')
156
+ .description('List all runs for a task')
157
+ .action(async (taskId) => {
158
+ await handleRunList({ taskId });
159
+ });
160
+ rtRunCmd
161
+ .command('show <runId>')
162
+ .description('Show detailed run information')
163
+ .action(async (runId) => {
164
+ await handleRunShow({ id: runId });
165
+ });
166
+ // ── Runtime v2 trajectory/history/context commands ───────────────────────────
167
+ const trajectoryCmd = program
168
+ .command('trajectory')
169
+ .description('Runtime v2 trajectory location');
170
+ trajectoryCmd
171
+ .command('locate')
172
+ .description('Locate a trajectory by task ID, run ID, or time range')
173
+ .option('-t, --task <taskId>', 'Locate by task ID')
174
+ .option('-r, --run <runId>', 'Locate by run ID')
175
+ .option('--from <date>', 'Start of time range (ISO string)')
176
+ .option('--to <date>', 'End of time range (ISO string)')
177
+ .option('-w, --workspace <path>', 'Workspace directory')
178
+ .option('--json', 'Output raw JSON')
179
+ .action(async (opts) => {
180
+ await handleTrajectoryLocate(opts);
181
+ });
182
+ const historyCmd = program
183
+ .command('history')
184
+ .description('Runtime v2 history query');
185
+ historyCmd
186
+ .command('query <taskId>')
187
+ .description('Query run history for a task')
188
+ .option('-l, --limit <number>', 'Limit number of entries', parseInt)
189
+ .option('-c, --cursor <cursor>', 'Pagination cursor')
190
+ .option('--from <date>', 'Start of time range (ISO string)')
191
+ .option('--to <date>', 'End of time range (ISO string)')
192
+ .option('-w, --workspace <path>', 'Workspace directory')
193
+ .option('--json', 'Output raw JSON')
194
+ .action(async (taskId, opts) => {
195
+ await handleHistoryQuery(taskId, opts);
196
+ });
197
+ const contextCmd = program
198
+ .command('context')
199
+ .description('Runtime v2 context assembly');
200
+ contextCmd
201
+ .command('build <taskId>')
202
+ .description('Assemble diagnostician context for a task')
203
+ .option('-w, --workspace <path>', 'Workspace directory')
204
+ .option('--json', 'Output raw JSON')
205
+ .action(async (taskId, opts) => {
206
+ await handleContextBuild(taskId, opts);
207
+ });
208
+ // ── Legacy import command ───────────────────────────────────────────────────────
209
+ const legacyCmd = program
210
+ .command('legacy')
211
+ .description('Legacy data management (import and cleanup)');
212
+ const importCmd = legacyCmd.command('import');
213
+ importCmd
214
+ .command('openclaw')
215
+ .description('Import OpenClaw legacy data into PD Runtime v2 SQLite. ' +
216
+ 'Run this once per workspace before using trajectory/history/context commands.')
217
+ .option('-w, --workspace <path>', 'Workspace directory (required)')
218
+ .option('--json', 'Output raw JSON')
219
+ .action(async (opts) => {
220
+ await handleLegacyImportOpenClaw(opts);
221
+ });
222
+ // ── Diagnostician run/status commands ─────────────────────────────────────
223
+ const diagnoseCmd = program
224
+ .command('diagnose')
225
+ .description('Diagnostician execution and status inspection');
226
+ diagnoseCmd
227
+ .command('status')
228
+ .description('Inspect diagnostician task status')
229
+ .requiredOption('-t, --task-id <taskId>', 'Task ID to inspect')
230
+ .option('-w, --workspace <path>', 'Workspace directory')
231
+ .option('--json', 'Output raw JSON')
232
+ .action(async (opts) => {
233
+ await handleDiagnoseStatus(opts);
234
+ });
235
+ diagnoseCmd
236
+ .command('run')
237
+ .description('Execute diagnostician runner for a task')
238
+ .requiredOption('-t, --task-id <taskId>', 'Task ID to execute')
239
+ .option('-w, --workspace <path>', 'Workspace directory')
240
+ .option('-r, --runtime <kind>', "Runtime kind: 'openclaw-cli', 'test-double', 'pi-ai'")
241
+ .option('--openclaw-local', 'Use local OpenClaw (mutually exclusive with --openclaw-gateway)')
242
+ .option('--openclaw-gateway', 'Use gateway OpenClaw (mutually exclusive with --openclaw-local)')
243
+ .option('-a, --agent <agentId>', 'Agent ID to invoke')
244
+ .option('--provider <name>', 'LLM provider (e.g., openrouter) — for pi-ai, falls back to policy')
245
+ .option('--model <id>', 'Model ID (e.g., anthropic/claude-sonnet-4) — for pi-ai, falls back to policy')
246
+ .option('--apiKeyEnv <name>', 'Env var name for API key — for pi-ai, falls back to policy')
247
+ .option('--baseUrl <url>', 'Custom base URL — for pi-ai, falls back to policy')
248
+ .option('--maxRetries <n>', 'Max retry attempts for LLM failures — for pi-ai, falls back to policy', parseInt)
249
+ .option('--timeoutMs <ms>', 'Timeout in milliseconds — for pi-ai, falls back to policy', parseInt)
250
+ .option('--no-intake', 'Skip candidate intake after successful diagnosis')
251
+ .option('--json', 'Output raw JSON')
252
+ .action(async (opts) => {
253
+ await handleDiagnoseRun(opts);
254
+ });
255
+ // ── Runtime probe command (HG-01 HARD GATE) ─────────────────────────────────
256
+ const runtimeCmd = program
257
+ .command('runtime')
258
+ .description('Runtime inspection and health checks');
259
+ runtimeCmd
260
+ .command('canary')
261
+ .description('One-shot control plane health canary')
262
+ .option('-w, --workspace <path>', 'Workspace directory')
263
+ .option('--json', 'Output raw JSON')
264
+ .action(async (opts) => {
265
+ await handleRuntimeCanary({ workspace: opts.workspace, json: opts.json });
266
+ });
267
+ const synthCmd = runtimeCmd
268
+ .command('synthetic')
269
+ .description('Synthetic workload baseline commands');
270
+ synthCmd
271
+ .command('baseline')
272
+ .description('Run synthetic PD workload baseline (PRI-206) — deterministic, no LLM required')
273
+ .option('-w, --workspace <path>', 'Workspace directory (default: temp workspace)')
274
+ .option('--json', 'Output raw JSON')
275
+ .action(async (opts) => {
276
+ await handleRuntimeSyntheticBaseline({ workspace: opts.workspace, json: opts.json });
277
+ });
278
+ synthCmd
279
+ .command('flood')
280
+ .description('Run pain flood simulation (PRI-208) — deterministic dedup/stress test, no LLM required')
281
+ .option('-w, --workspace <path>', 'Workspace directory (default: temp workspace)')
282
+ .option('--json', 'Output raw JSON')
283
+ .option('--identical-count <n>', 'Number of identical pain signals (default: 10)', parseInt)
284
+ .option('--similar-count <n>', 'Number of similar pain signals (default: 10)', parseInt)
285
+ .option('--stress-count <n>', 'Number of stress test pain signals (default: 50)', parseInt)
286
+ .action(async (opts) => {
287
+ await handleRuntimePainFlood({
288
+ workspace: opts.workspace,
289
+ json: opts.json,
290
+ identicalCount: opts.identicalCount,
291
+ similarCount: opts.similarCount,
292
+ stressCount: opts.stressCount,
293
+ });
294
+ });
295
+ synthCmd
296
+ .command('proven-channel')
297
+ .description('Run MVP activation continuity baseline (PRI-240) — deterministic, no LLM required')
298
+ .option('-w, --workspace <path>', 'Workspace directory (default: temp workspace)')
299
+ .option('--json', 'Output raw JSON')
300
+ .option('--channels <channels>', 'Comma-separated channel list (prompt,code_tool_hook,defer_archive)')
301
+ .action(async (opts) => {
302
+ await handleProvenChannelBaseline({
303
+ workspace: opts.workspace,
304
+ json: opts.json,
305
+ channels: opts.channels,
306
+ });
307
+ });
308
+ runtimeCmd
309
+ .command('features')
310
+ .description('Show feature flag status (PRI-239)')
311
+ .option('-w, --workspace <path>', 'Workspace directory')
312
+ .option('--json', 'Output raw JSON')
313
+ .action(async (opts) => {
314
+ await handleRuntimeFeaturesStatus({
315
+ workspace: opts.workspace,
316
+ json: opts.json,
317
+ });
318
+ });
319
+ const demoCmd = program
320
+ .command('demo')
321
+ .description('Demo scenarios for MVP validation');
322
+ demoCmd
323
+ .command('story-a')
324
+ .description('Run Story A\' proven-channel demo (PRI-246) — full evidence→proposal→approval→activation→observation chain')
325
+ .option('-w, --workspace <path>', 'Workspace directory (default: temp workspace)')
326
+ .option('--json', 'Output raw JSON')
327
+ .option('--channels <channels>', 'Comma-separated channel list (prompt,code_tool_hook,defer_archive)')
328
+ .action(async (opts) => {
329
+ await handleDemoStoryA({
330
+ workspace: opts.workspace,
331
+ json: opts.json,
332
+ channels: opts.channels,
333
+ });
334
+ });
335
+ runtimeCmd
336
+ .command('probe')
337
+ .description('Probe runtime health and capabilities (HG-01 HARD GATE)')
338
+ .requiredOption('-r, --runtime <kind>', "Runtime kind: 'openclaw-cli' or 'pi-ai'")
339
+ .option('--openclaw-local', 'Use local OpenClaw (mutually exclusive with --openclaw-gateway)')
340
+ .option('--openclaw-gateway', 'Use gateway OpenClaw (mutually exclusive with --openclaw-local)')
341
+ .option('-a, --agent <agentId>', 'Agent ID to probe')
342
+ .option('--provider <name>', 'LLM provider (e.g., openrouter) — for pi-ai, falls back to --workspace workflows.yaml')
343
+ .option('--model <id>', 'Model ID (e.g., anthropic/claude-sonnet-4) — for pi-ai, falls back to --workspace workflows.yaml')
344
+ .option('--apiKeyEnv <name>', 'Env var name for API key (e.g., OPENROUTER_API_KEY) — for pi-ai, falls back to --workspace workflows.yaml')
345
+ .option('--baseUrl <url>', 'Custom base URL for OpenAI-compatible providers — for pi-ai, falls back to --workspace workflows.yaml')
346
+ .option('--maxRetries <n>', 'Max retry attempts for LLM failures', parseInt)
347
+ .option('--timeoutMs <ms>', 'Timeout in milliseconds for probe', parseInt)
348
+ .option('-w, --workspace <path>', 'Workspace directory — loads pi-ai policy from .state/workflows.yaml')
349
+ .option('--json', 'Output raw JSON')
350
+ .action(async (opts) => {
351
+ await handleRuntimeProbe(opts);
352
+ });
353
+ const flowCmd = runtimeCmd
354
+ .command('flow')
355
+ .description('Workflow funnel inspection');
356
+ flowCmd
357
+ .command('show')
358
+ .description('Show all workflow funnel definitions from workflows.yaml')
359
+ .option('-w, --workspace <path>', 'Workspace directory')
360
+ .option('--json', 'Output raw JSON')
361
+ .action(async (opts) => {
362
+ await handleFlowShow(opts);
363
+ });
364
+ const traceCmd = runtimeCmd
365
+ .command('trace')
366
+ .description('Trace full pain-to-ledger chain');
367
+ traceCmd
368
+ .command('show')
369
+ .description('Show full trace for a pain ID')
370
+ .requiredOption('--pain-id <id>', 'Pain ID to trace')
371
+ .option('-w, --workspace <path>', 'Workspace directory')
372
+ .option('--json', 'Output raw JSON')
373
+ .action(async (opts) => {
374
+ await handleTraceShow({ painId: opts.painId, workspace: opts.workspace, json: opts.json });
375
+ });
376
+ runtimeCmd
377
+ .command('uat')
378
+ .description('Runtime V2 chain UAT baseline runner')
379
+ .option('-w, --workspace <path>', 'Workspace directory')
380
+ .option('--count <n>', 'Number of iterations (default: 5, max: 50)', parseInt)
381
+ .option('--min-success-rate <rate>', 'Minimum success rate threshold (default: 1.0)', parseFloat)
382
+ .option('--json', 'Output machine-readable JSON summary')
383
+ .action(async (opts) => {
384
+ await handleRuntimeUat({
385
+ workspace: opts.workspace,
386
+ count: opts.count,
387
+ minSuccessRate: opts.minSuccessRate,
388
+ json: opts.json,
389
+ });
390
+ });
391
+ const runtimeHealthCmd = runtimeCmd
392
+ .command('health')
393
+ .description('Runtime V2 health inspection');
394
+ runtimeHealthCmd
395
+ .command('snapshot')
396
+ .description('Operator health snapshot combining chain, ledger, and pruning status')
397
+ .option('-w, --workspace <path>', 'Workspace directory')
398
+ .option('--json', 'Output raw JSON')
399
+ .action(async (opts) => {
400
+ await handleRuntimeHealthSnapshot({ workspace: opts.workspace, json: opts.json });
401
+ });
402
+ runtimeHealthCmd
403
+ .command('gfi')
404
+ .description('GFI workspace snapshot — active vs stale session breakdown')
405
+ .option('-w, --workspace <path>', 'Workspace directory')
406
+ .option('--json', 'Output raw JSON')
407
+ .action(async (opts) => {
408
+ await handleRuntimeGfiSnapshot({ workspace: opts.workspace, json: opts.json });
409
+ });
410
+ // PRI-82: pd runtime gfi snapshot — canonical operator command (alias of runtime health gfi)
411
+ runtimeCmd
412
+ .command('gfi')
413
+ .description('GFI workspace snapshot — active vs stale session breakdown')
414
+ .command('snapshot')
415
+ .description('GFI workspace snapshot for the operator (alias: pd runtime health gfi)')
416
+ .option('-w, --workspace <path>', 'Workspace directory')
417
+ .option('--json', 'Output raw JSON')
418
+ .action(async (opts) => {
419
+ await handleRuntimeGfiSnapshot({ workspace: opts.workspace, json: opts.json });
420
+ });
421
+ const internalizationCmd = runtimeCmd
422
+ .command('internalization')
423
+ .description('Internalization Engine operator visibility');
424
+ internalizationCmd
425
+ .command('queue')
426
+ .description('Show PI task queue health snapshot')
427
+ .option('-w, --workspace <path>', 'Workspace directory')
428
+ .option('--json', 'Output raw JSON')
429
+ .action(async (opts) => {
430
+ await handleRuntimeInternalizationQueue({ workspace: opts.workspace, json: opts.json });
431
+ });
432
+ internalizationCmd
433
+ .command('wake-once')
434
+ .description('Dry-run lease evaluation for the next leasable PI task')
435
+ .option('-w, --workspace <path>', 'Workspace directory')
436
+ .option('--dry-run', 'Evaluate lease without acquiring (required)', false)
437
+ .option('--json', 'Output raw JSON')
438
+ .action(async (opts) => {
439
+ await handleRuntimeInternalizationWakeOnce({ workspace: opts.workspace, dryRun: opts.dryRun, json: opts.json });
440
+ });
441
+ internalizationCmd
442
+ .command('run-once')
443
+ .description('Wake-and-run: lease the next PI task and execute it')
444
+ .option('-w, --workspace <path>', 'Workspace directory')
445
+ .option('--runner <kind>', 'Runner kind to execute (default: dreamer)', 'dreamer')
446
+ .option('--runtime <kind>', 'Runtime adapter kind: config (from workflows.yaml), pi-ai, openclaw-cli, test-double (default: config)', 'config')
447
+ .option('--allow-test-double', 'Acknowledge that test-double runtime will mutate real queue state')
448
+ .option('--enqueue-next', 'After successful runner execution, commit successor task to queue')
449
+ .option('--timeout-ms <ms>', 'Runner timeout in milliseconds (default: 300000, overrides workflows.yaml)', parseInt)
450
+ .option('--json', 'Output raw JSON')
451
+ .action(async (opts) => {
452
+ await handleRuntimeInternalizationRunOnce({ workspace: opts.workspace, json: opts.json, runtime: opts.runtime, runner: opts.runner, allowTestDouble: opts.allowTestDouble, enqueueNext: opts.enqueueNext, timeoutMs: opts.timeoutMs });
453
+ });
454
+ internalizationCmd
455
+ .command('integrity')
456
+ .description('Check internalization chain integrity')
457
+ .option('-w, --workspace <path>', 'Workspace directory')
458
+ .option('--json', 'Output raw JSON')
459
+ .action(async (opts) => {
460
+ await handleRuntimeInternalizationIntegrity({ workspace: opts.workspace, json: opts.json });
461
+ });
462
+ internalizationCmd
463
+ .command('integrity-repair')
464
+ .description('Repair broken internalization chain links (operator repair path)')
465
+ .option('-w, --workspace <path>', 'Workspace directory')
466
+ .option('--dry-run', 'Report only, no modifications')
467
+ .option('--confirm', 'Actually repair broken links')
468
+ .option('--json', 'Output raw JSON')
469
+ .action(async (opts) => {
470
+ await handleRuntimeInternalizationIntegrityRepair({ workspace: opts.workspace, confirm: opts.confirm, dryRun: opts.dryRun, json: opts.json });
471
+ });
472
+ internalizationCmd
473
+ .command('enqueue-successors')
474
+ .description('Enqueue successor tasks for succeeded internalization tasks missing successors')
475
+ .option('-w, --workspace <path>', 'Workspace directory')
476
+ .option('--dry-run', 'Report only, no modifications (default)')
477
+ .option('--confirm', 'Actually create successor tasks')
478
+ .option('--json', 'Output raw JSON')
479
+ .action(async (opts) => {
480
+ await handleRuntimeInternalizationEnqueueSuccessors({ workspace: opts.workspace, dryRun: opts.dryRun, confirm: opts.confirm, json: opts.json });
481
+ });
482
+ const activationCmd = runtimeCmd
483
+ .command('activation')
484
+ .description('Activation dispatch operations');
485
+ activationCmd
486
+ .command('dispatch')
487
+ .description('Dispatch an activation for a rollout-reviewed artifact')
488
+ .requiredOption('-a, --artifact-id <id>', 'PIArtifact ID to activate')
489
+ .option('-w, --workspace <path>', 'Workspace directory')
490
+ .option('-c, --channel <channel>', 'Activation channel (prompt|defer_archive)', 'prompt')
491
+ .option('--dry-run', 'Dry-run mode (default, no writes)')
492
+ .option('--confirm', 'Confirm and write activation record')
493
+ .option('--json', 'Output raw JSON')
494
+ .action(async (opts) => {
495
+ await handleRuntimeActivationDispatch({
496
+ workspace: opts.workspace,
497
+ artifactId: opts.artifactId,
498
+ channel: opts.channel,
499
+ dryRun: opts.dryRun,
500
+ confirm: opts.confirm,
501
+ json: opts.json,
502
+ });
503
+ });
504
+ const diagnosticsCmd = runtimeCmd
505
+ .command('diagnostics')
506
+ .description('Control plane diagnostic bundle operations');
507
+ const recoveryCmd = runtimeCmd
508
+ .command('recovery')
509
+ .description('Runtime V2 lease recovery operations');
510
+ recoveryCmd
511
+ .command('sweep')
512
+ .description('Detect and optionally recover expired leases')
513
+ .option('-w, --workspace <path>', 'Workspace directory')
514
+ .option('--dry-run', 'Report only, no modifications (default)')
515
+ .option('--confirm', 'Actually recover expired leases')
516
+ .option('--json', 'Output raw JSON')
517
+ .action(async (opts) => {
518
+ await handleRuntimeRecoverySweep({ workspace: opts.workspace, dryRun: opts.dryRun, confirm: opts.confirm, json: opts.json });
519
+ });
520
+ diagnosticsCmd
521
+ .command('export')
522
+ .description('Export diagnostic bundle for AI assistant analysis')
523
+ .option('-w, --workspace <path>', 'Workspace directory')
524
+ .option('--out <dir>', 'Output directory (must be within workspace)')
525
+ .option('--json', 'Output raw JSON')
526
+ .action(async (opts) => {
527
+ await handleRuntimeDiagnosticsExport({ workspace: opts.workspace, out: opts.out, json: opts.json });
528
+ });
529
+ const pruningCmd = runtimeCmd
530
+ .command('pruning')
531
+ .description('Non-destructive pruning metrics and health signals');
532
+ pruningCmd
533
+ .command('report')
534
+ .description('Show pruning health report — watch/review principle signals')
535
+ .option('-w, --workspace <path>', 'Workspace directory')
536
+ .option('--json', 'Output raw JSON')
537
+ .action((opts) => {
538
+ handlePruningReport({ workspace: opts.workspace, json: opts.json });
539
+ });
540
+ pruningCmd
541
+ .command('explain')
542
+ .description('Explain why a specific principle was flagged')
543
+ .requiredOption('--principle-id <id>', 'Principle ID to explain')
544
+ .option('-w, --workspace <path>', 'Workspace directory')
545
+ .option('--json', 'Output raw JSON')
546
+ .action((opts) => {
547
+ handlePruningExplain({ principleId: opts.principleId, workspace: opts.workspace, json: opts.json });
548
+ });
549
+ pruningCmd
550
+ .command('review')
551
+ .description('Record a human pruning decision for a flagged principle')
552
+ .requiredOption('--principle-id <id>', 'Principle ID to review')
553
+ .requiredOption('--decision <decision>', "Decision: keep, defer, or archive-candidate")
554
+ .option('--note <text>', 'Review note (required for archive-candidate)')
555
+ .option('--reviewer <name>', 'Reviewer name', 'operator')
556
+ .option('-w, --workspace <path>', 'Workspace directory')
557
+ .option('--json', 'Output raw JSON')
558
+ .action((opts) => {
559
+ handlePruningReview({
560
+ principleId: opts.principleId,
561
+ decision: opts.decision,
562
+ note: opts.note,
563
+ reviewer: opts.reviewer,
564
+ workspace: opts.workspace,
565
+ json: opts.json,
566
+ });
567
+ });
568
+ pruningCmd
569
+ .command('rollback')
570
+ .description('Restore a masked principle to injection by overriding archive-candidate')
571
+ .requiredOption('--principle-id <id>', 'Principle ID to restore')
572
+ .option('--note <text>', 'Reason for rollback')
573
+ .option('--reviewer <name>', 'Reviewer name', 'operator')
574
+ .option('-w, --workspace <path>', 'Workspace directory')
575
+ .option('--json', 'Output raw JSON')
576
+ .action((opts) => {
577
+ handlePruningRollback({
578
+ principleId: opts.principleId,
579
+ note: opts.note,
580
+ reviewer: opts.reviewer,
581
+ workspace: opts.workspace,
582
+ json: opts.json,
583
+ });
584
+ });
585
+ pruningCmd
586
+ .command('orphans')
587
+ .description('List orphan derived candidates not found in state.db')
588
+ .option('-w, --workspace <path>', 'Workspace directory')
589
+ .option('--dry-run', 'Report only, no modifications (default)')
590
+ .option('--confirm', 'Actually remove orphan references from ledger')
591
+ .option('--json', 'Output raw JSON')
592
+ .action((opts) => {
593
+ handlePruningOrphans({
594
+ workspace: opts.workspace,
595
+ dryRun: opts.dryRun,
596
+ confirm: opts.confirm,
597
+ json: opts.json,
598
+ });
599
+ });
600
+ // ── Candidate inspection commands ───────────────────────────────────────────
601
+ const candidateCmd = program
602
+ .command('candidate')
603
+ .description('Principle candidate inspection');
604
+ candidateCmd
605
+ .command('list')
606
+ .description('List principle candidates for a task')
607
+ .requiredOption('-t, --task-id <taskId>', 'Task ID to query')
608
+ .option('-w, --workspace <path>', 'Workspace directory')
609
+ .option('--json', 'Output raw JSON')
610
+ .action(async (opts) => {
611
+ await handleCandidateList(opts);
612
+ });
613
+ candidateCmd
614
+ .command('show [candidateId]')
615
+ .description('Show detail for a single principle candidate')
616
+ .requiredOption('-w, --workspace <path>', 'Workspace directory')
617
+ .option('--candidate-id <id>', 'Candidate ID (alternative to positional arg)')
618
+ .option('--json', 'Output raw JSON')
619
+ .action(async (candidateId, opts) => {
620
+ const resolvedId = opts.candidateId ?? candidateId;
621
+ if (!resolvedId) {
622
+ console.error('Error: candidate ID is required (positional or --candidate-id)');
623
+ process.exitCode = 1;
624
+ return;
625
+ }
626
+ if (candidateId && opts.candidateId && candidateId !== opts.candidateId) {
627
+ console.error(`Error: conflicting candidate IDs: positional="${candidateId}", --candidate-id="${opts.candidateId}"`);
628
+ process.exitCode = 1;
629
+ return;
630
+ }
631
+ await handleCandidateShow({ candidateId: resolvedId, ...opts });
632
+ });
633
+ candidateCmd
634
+ .command('intake')
635
+ .description('Intake a principle candidate into the ledger')
636
+ .requiredOption('--candidate-id <id>', 'Candidate ID to intake')
637
+ .option('-w, --workspace <path>', 'Workspace directory')
638
+ .option('--json', 'Output as JSON')
639
+ .option('--dry-run', 'Show what would be written without writing')
640
+ .action(async (opts) => {
641
+ await handleCandidateIntake(opts);
642
+ });
643
+ candidateCmd
644
+ .command('audit')
645
+ .description('Audit candidate/ledger consistency for Runtime v2')
646
+ .option('-w, --workspace <path>', 'Workspace directory')
647
+ .option('--json', 'Output as JSON')
648
+ .action(async (opts) => {
649
+ await handleCandidateAudit(opts);
650
+ });
651
+ candidateCmd
652
+ .command('repair')
653
+ .description('Repair consumed candidate with missing ledger entry')
654
+ .requiredOption('--candidate-id <id>', 'Candidate ID to repair')
655
+ .option('-w, --workspace <path>', 'Workspace directory')
656
+ .option('--json', 'Output as JSON')
657
+ .action(async (opts) => {
658
+ await handleCandidateRepair(opts);
659
+ });
660
+ candidateCmd
661
+ .command('route')
662
+ .description('Show internalization route decision for a candidate')
663
+ .requiredOption('--candidate-id <id>', 'Candidate ID to inspect')
664
+ .option('-w, --workspace <path>', 'Workspace directory')
665
+ .option('--json', 'Output as JSON')
666
+ .action(async (opts) => {
667
+ await handleCandidateRoute(opts);
668
+ });
669
+ candidateCmd
670
+ .command('internalize')
671
+ .description('Seed internalization Dreamer task from a candidate')
672
+ .requiredOption('--candidate-id <id>', 'Candidate ID to internalize')
673
+ .option('-w, --workspace <path>', 'Workspace directory')
674
+ .option('--json', 'Output as JSON')
675
+ .option('--dry-run', 'Preview without writing to database')
676
+ .action(async (opts) => {
677
+ await handleCandidateInternalize(opts);
678
+ });
679
+ const candidateInternalizationCmd = candidateCmd
680
+ .command('internalization')
681
+ .description('Internalization pipeline operations for candidates');
682
+ candidateInternalizationCmd
683
+ .command('backfill')
684
+ .description('Backfill dreamer tasks for consumed candidates created before Internalization Engine')
685
+ .option('-w, --workspace <path>', 'Workspace directory')
686
+ .option('--dry-run', 'Report only, no modifications (default)')
687
+ .option('--confirm', 'Actually create missing dreamer tasks')
688
+ .option('--include-pending', 'Include pending candidates (intake first, then seed dreamer)')
689
+ .option('--json', 'Output as JSON')
690
+ .action(async (opts) => {
691
+ await handleCandidateInternalizationBackfill({ workspace: opts.workspace, dryRun: opts.dryRun, confirm: opts.confirm, includePending: opts.includePending, json: opts.json });
692
+ });
693
+ // ── Artifact inspection commands ────────────────────────────────────────────
694
+ const artifactCmd = program
695
+ .command('artifact')
696
+ .description('Artifact registry inspection');
697
+ artifactCmd
698
+ .command('show <artifactId>')
699
+ .description('Show artifact content and its associated candidates')
700
+ .requiredOption('-w, --workspace <path>', 'Workspace directory')
701
+ .option('--json', 'Output raw JSON')
702
+ .action(async (artifactId, opts) => {
703
+ await handleArtifactShow({ artifactId, ...opts });
704
+ });
705
+ const _legacyCleanupCmd = legacyCmd
706
+ .command('cleanup')
707
+ .description('Clean legacy empathy/diagnostician artifacts from workspace')
708
+ .requiredOption('-w, --workspace <path>', 'Workspace directory')
709
+ .option('--dry-run', 'Show what would be cleaned without applying', false)
710
+ .option('--apply', 'Actually apply the cleanup', false)
711
+ .action(async (opts) => {
712
+ const apply = opts.apply ?? false;
713
+ if (!apply && !opts.dryRun) {
714
+ console.error('Specify --dry-run or --apply');
715
+ process.exit(1);
716
+ }
717
+ await handleLegacyCleanup(opts.workspace, apply);
718
+ });
719
+ program
720
+ .command('console')
721
+ .description('Start the pd-console web UI for principle review')
722
+ .option('-w, --workspace <path>', 'Workspace directory')
723
+ .option('-p, --port <port>', 'Port to listen on', '3100')
724
+ .option('--no-auth', 'Disable authentication (local dev only)', false)
725
+ .option('--json', 'Output JSON status', false)
726
+ .action(async (opts) => {
727
+ const { handleConsole } = await import('./commands/console.js');
728
+ await handleConsole({
729
+ workspace: opts.workspace,
730
+ port: opts.port,
731
+ noAuth: opts.noAuth,
732
+ json: opts.json,
733
+ });
734
+ });
735
+ program.parse();
736
+ //# sourceMappingURL=index.js.map