@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,87 +0,0 @@
1
- /**
2
- * pd runtime internalization wake-once command handler.
3
- *
4
- * Usage:
5
- * pd runtime internalization wake-once --workspace <path> --dry-run --json
6
- *
7
- * This command ONLY supports --dry-run mode. Non-dry-run invocations are rejected
8
- * before any state interaction (no lease acquisition, no mutation).
9
- *
10
- * PRI-73 scope: dry-run inspection only; real lease acquisition is future scope.
11
- */
12
- import * as path from 'path';
13
- import { RuntimeStateManager, InternalizationOrchestrator } from '@principles/core/runtime-v2';
14
- import type { WakeOnceResult } from '@principles/core/runtime-v2';
15
- import { resolveWorkspaceDir } from '../resolve-workspace.js';
16
-
17
- interface WakeOnceOptions {
18
- workspace?: string;
19
- dryRun?: boolean;
20
- json?: boolean;
21
- }
22
-
23
- const OWNER = 'pd-cli-internalization-wake-once';
24
- const RUNTIME_KIND = 'local-worker';
25
-
26
- function formatTextOutput(result: WakeOnceResult): string {
27
- switch (result.decision) {
28
- case 'would_lease':
29
- return `would_lease: ${result.taskId} (${result.taskKind})`;
30
- case 'no_ready_tasks':
31
- return `no_ready_tasks: ${result.reason} (inspected: ${result.inspectedCount})`;
32
- case 'blocked':
33
- return `blocked: ${result.taskId} (${result.taskKind}) by [${result.blockedBy.join(', ')}]`;
34
- case 'dependency_failed':
35
- return `dependency_failed: ${result.taskId} (${result.taskKind}) failed deps: [${result.failedDependencies.join(', ')}]`;
36
- case 'lease_conflict':
37
- return `lease_conflict: ${result.taskId} — ${result.conflictReason}`;
38
- case 'invalid_task_metadata':
39
- return `invalid_task_metadata: ${result.taskId} (${result.taskKind})`;
40
- case 'leased':
41
- return `leased: ${result.taskId} (${result.taskKind}) attempt ${result.attemptCount}`;
42
- }
43
- }
44
-
45
- export async function handleRuntimeInternalizationWakeOnce(opts: WakeOnceOptions): Promise<void> {
46
- // REJECT non-dry-run — only dry-run mode is implemented in this issue
47
- if (!opts.dryRun) {
48
- console.error('Error: wake-once without --dry-run is not implemented.');
49
- console.error('Only --dry-run mode is available for operator inspection.');
50
- process.exit(1);
51
- return;
52
- }
53
-
54
- const workspaceDir = opts.workspace ? path.resolve(opts.workspace) : resolveWorkspaceDir();
55
-
56
- const stateManager = new RuntimeStateManager({ workspaceDir });
57
- await stateManager.initialize();
58
-
59
- try {
60
- const orchestrator = new InternalizationOrchestrator(
61
- { stateManager },
62
- { owner: OWNER, runtimeKind: RUNTIME_KIND, dryRun: true },
63
- );
64
-
65
- let result: WakeOnceResult = { decision: 'no_ready_tasks', reason: 'no_candidates', inspectedCount: 0 };
66
- try {
67
- result = await orchestrator.wakeOnce();
68
- } catch (err) {
69
- console.error('Error: wake-once failed:', err);
70
- process.exitCode = 1;
71
- return;
72
- }
73
-
74
- if (opts.json) {
75
- console.log(JSON.stringify(result, null, 2));
76
- } else {
77
- console.log(formatTextOutput(result));
78
- }
79
-
80
- // Exit code 1 when no task could be leased (operator alert condition)
81
- if (result.decision === 'no_ready_tasks' || result.decision === 'lease_conflict') {
82
- process.exitCode = 1;
83
- }
84
- } finally {
85
- await stateManager.close();
86
- }
87
- }
@@ -1,121 +0,0 @@
1
- import * as path from 'path';
2
- import * as os from 'os';
3
- import * as fs from 'fs';
4
- import { runPainFloodSimulation } from '../services/pain-flood-simulation-runner.js';
5
- import type { PainFloodSimulationSummary } from '@principles/core/runtime-v2';
6
-
7
- interface CliPainFloodOptions {
8
- workspace?: string;
9
- json?: boolean;
10
- identicalCount?: number;
11
- similarCount?: number;
12
- stressCount?: number;
13
- }
14
-
15
- function formatTextOutput(summary: PainFloodSimulationSummary): string {
16
- const lines: string[] = [];
17
- const icon = summary.status === 'healthy' ? '✓' : summary.status === 'degraded' ? '⚠' : '✗';
18
-
19
- lines.push('PD Pain Flood Simulation');
20
- lines.push(`generatedAt: ${summary.generatedAt}`);
21
- lines.push(`workspaceMode: ${summary.workspaceMode}`);
22
- lines.push(`OVERALL: ${icon} ${summary.status.toUpperCase()}`);
23
- lines.push('');
24
- lines.push(` inputPainCount: ${summary.inputPainCount}`);
25
- lines.push(` acceptedPainCount: ${summary.acceptedPainCount}`);
26
- lines.push(` skippedDuplicateCount: ${summary.skippedDuplicateCount}`);
27
- lines.push(` failedCount: ${summary.failedCount}`);
28
- lines.push(` candidateCount: ${summary.candidateCount}`);
29
- lines.push(` taskCount: ${summary.taskCount}`);
30
- lines.push(` maxEvidencePreviewLength: ${summary.maxEvidencePreviewLength}`);
31
- lines.push(` contextBudgetSummary: ${summary.contextBudgetSummary}`);
32
- lines.push('');
33
-
34
- for (const stage of summary.stages) {
35
- const stageIcon = stage.status === 'passed' ? '✓' : stage.status === 'skipped' ? '○' : '✗';
36
- lines.push(` ${stageIcon} ${stage.scenarioName}: ${stage.status}`);
37
- lines.push(` input=${stage.inputCount} accepted=${stage.acceptedCount} skipped=${stage.skippedCount} failed=${stage.failedCount} tasks=${stage.taskCount} candidates=${stage.candidateCount}`);
38
- if (stage.reason) {
39
- lines.push(` reason: ${stage.reason}`);
40
- }
41
- }
42
-
43
- if (summary.recommendedNextIssue) {
44
- lines.push('');
45
- lines.push(`Recommended next issue: ${summary.recommendedNextIssue}`);
46
- }
47
-
48
- if (summary.reason) {
49
- lines.push(`reason: ${summary.reason}`);
50
- }
51
-
52
- if (summary.nextAction) {
53
- lines.push(`nextAction: ${summary.nextAction}`);
54
- }
55
-
56
- return lines.join('\n');
57
- }
58
-
59
- export async function handleRuntimePainFlood(opts: CliPainFloodOptions): Promise<void> {
60
- if (opts.workspace) {
61
- if (opts.json) {
62
- console.log(JSON.stringify({ status: 'error', reason: 'Explicit workspace is not allowed for pain flood simulation — this command mutates state and must run in an auto-created temp workspace only.', nextAction: 'Remove --workspace flag and re-run to use a temp workspace.' }));
63
- } else {
64
- console.error('Error: --workspace is not allowed for pain flood simulation. This command mutates state and must run in an auto-created temp workspace only.');
65
- }
66
- process.exitCode = 1;
67
- return;
68
- }
69
-
70
- const countFields: { name: 'identicalCount' | 'similarCount' | 'stressCount'; value: number | undefined; min: number }[] = [
71
- { name: 'identicalCount', value: opts.identicalCount, min: 1 },
72
- { name: 'similarCount', value: opts.similarCount, min: 1 },
73
- { name: 'stressCount', value: opts.stressCount, min: 1 },
74
- ];
75
-
76
- for (const field of countFields) {
77
- if (field.value !== undefined) {
78
- if (!Number.isFinite(field.value) || !Number.isInteger(field.value) || field.value < field.min) {
79
- const reason = `--${field.name === 'identicalCount' ? 'identical-count' : field.name === 'similarCount' ? 'similar-count' : 'stress-count'} must be a finite integer >= ${field.min}, got ${field.value}`;
80
- if (opts.json) {
81
- console.log(JSON.stringify({ status: 'error', reason, nextAction: `Provide a valid --${field.name === 'identicalCount' ? 'identical-count' : field.name === 'similarCount' ? 'similar-count' : 'stress-count'} value` }));
82
- } else {
83
- console.error(`Error: ${reason}`);
84
- }
85
- process.exitCode = 1;
86
- return;
87
- }
88
- }
89
- }
90
-
91
- const workspaceDir = fs.mkdtempSync(path.join(os.tmpdir(), 'pd-pain-flood-'));
92
- const workspaceMode = 'temp' as const;
93
-
94
- try {
95
- const summary = await runPainFloodSimulation({
96
- workspaceDir,
97
- workspaceMode,
98
- identicalCount: opts.identicalCount,
99
- similarCount: opts.similarCount,
100
- stressCount: opts.stressCount,
101
- });
102
-
103
- if (opts.json) {
104
- console.log(JSON.stringify(summary, null, 2));
105
- } else {
106
- console.log(formatTextOutput(summary));
107
- }
108
-
109
- if (summary.status !== 'healthy') {
110
- console.error('');
111
- console.error(`FAIL: status=${summary.status}`);
112
- process.exitCode = 1;
113
- }
114
- } finally {
115
- try {
116
- fs.rmSync(workspaceDir, { recursive: true, force: true });
117
- } catch {
118
- // ignore cleanup errors on Windows
119
- }
120
- }
121
- }
@@ -1,438 +0,0 @@
1
- /**
2
- * pd runtime pruning report command — non-destructive pruning metrics.
3
- *
4
- * Usage: pd runtime pruning report [--workspace <path>] [--json]
5
- *
6
- * Delegates to PruningReadModel (core).
7
- */
8
-
9
- import * as path from 'path';
10
- import { resolveWorkspaceDir } from '../resolve-workspace.js';
11
- import { PruningReadModel, appendPruningReview, listPruningReviews, buildMaskedPrincipleSet, removeOrphanReferencesFromLedger } from '@principles/core/runtime-v2';
12
- import type { PruningReviewDecision, OrphanDerivedCandidate, OrphanDetectionResult } from '@principles/core/runtime-v2';
13
- import { createRemediationResult, remediationAction } from './remediation-output.js';
14
- import type { RemediationResult } from './remediation-output.js';
15
-
16
- interface PruningReportOptions {
17
- workspace?: string;
18
- json?: boolean;
19
- }
20
-
21
- function outputText(
22
- summary: ReturnType<PruningReadModel['getHealthSummary']>,
23
- signals: ReturnType<PruningReadModel['getPrincipleSignals']>,
24
- workspaceDir: string,
25
- ): void {
26
- console.log(`generatedAt: ${summary.generatedAt}`);
27
- console.log(`workspace: ${workspaceDir}`);
28
- console.log(`totalPrinciples: ${summary.totalPrinciples}`);
29
- console.log(`byStatus: ${JSON.stringify(summary.byStatus)}`);
30
- console.log(`orphanDerivedCandidateCount: ${summary.orphanDerivedCandidateCount}`);
31
- console.log(`averageAgeDays: ${summary.averageAgeDays}`);
32
- console.log('');
33
- console.log(`watchCount: ${summary.watchCount}`);
34
- console.log(`reviewCount: ${summary.reviewCount}`);
35
-
36
- if (summary.watchCount > 0) {
37
- console.log('');
38
- console.log('── Principles flagged WATCH ──');
39
- for (const s of signals) {
40
- if (s.riskLevel === 'watch') {
41
- console.log(` [${s.status}] ${s.principleId} (age: ${s.ageDays}d, derivedPainCount: ${s.derivedPainCount})`);
42
- for (const r of s.reasons) {
43
- console.log(` ↳ ${r}`);
44
- }
45
- }
46
- }
47
- }
48
-
49
- if (summary.reviewCount > 0) {
50
- console.log('');
51
- console.log('── Principles flagged REVIEW ──');
52
- for (const s of signals) {
53
- if (s.riskLevel === 'review') {
54
- console.log(` [${s.status}] ${s.principleId} (age: ${s.ageDays}d, derivedPainCount: ${s.derivedPainCount})`);
55
- for (const r of s.reasons) {
56
- console.log(` ↳ ${r}`);
57
- }
58
- }
59
- }
60
- }
61
-
62
- if (summary.watchCount === 0 && summary.reviewCount === 0) {
63
- console.log('');
64
- console.log('No watch or review signals. System is healthy.');
65
- }
66
-
67
- console.log('');
68
- console.log('NOTE: This report is read-only. No principles are modified or deleted.');
69
- }
70
-
71
- export function handlePruningReport(opts: PruningReportOptions): void {
72
- const workspaceDir = opts.workspace
73
- ? path.resolve(opts.workspace)
74
- : resolveWorkspaceDir();
75
-
76
- const model = new PruningReadModel({ workspaceDir });
77
- const signals = model.getPrincipleSignals();
78
- const summary = model.getHealthSummary();
79
-
80
- if (opts.json) {
81
- console.log(JSON.stringify({ generatedAt: summary.generatedAt, workspace: workspaceDir, summary, signals }, null, 2));
82
- return;
83
- }
84
-
85
- outputText(summary, signals, workspaceDir);
86
- }
87
-
88
- // ── Pruning explain ────────────────────────────────────────────────────────────
89
-
90
- export interface PruningExplainOptions {
91
- principleId: string;
92
- workspace?: string;
93
- json?: boolean;
94
- }
95
-
96
- export interface PruningReviewOptions {
97
- principleId: string;
98
- decision: PruningReviewDecision;
99
- note?: string;
100
- reviewer?: string;
101
- workspace?: string;
102
- json?: boolean;
103
- }
104
-
105
- export function handlePruningReview(opts: PruningReviewOptions): void {
106
- const workspaceDir = opts.workspace
107
- ? path.resolve(opts.workspace)
108
- : resolveWorkspaceDir();
109
-
110
- const model = new PruningReadModel({ workspaceDir });
111
- const signals = model.getPrincipleSignals();
112
-
113
- const signal = signals.find((s) => s.principleId === opts.principleId);
114
-
115
- if (!signal) {
116
- if (opts.json) {
117
- console.log(JSON.stringify({ error: `Principle not found: '${opts.principleId}'` }));
118
- } else {
119
- console.error(`Error: Principle not found: '${opts.principleId}'`);
120
- }
121
- process.exit(1);
122
- return; // satisfies TypeScript control flow (process.exit is [noreturn] in tests)
123
- }
124
-
125
- if (opts.decision !== 'keep' && opts.decision !== 'defer' && opts.decision !== 'archive-candidate') {
126
- if (opts.json) {
127
- console.log(JSON.stringify({ error: `Invalid decision: '${opts.decision}'. Must be one of: keep, defer, archive-candidate` }));
128
- } else {
129
- console.error(`Error: Invalid decision: '${opts.decision}'. Must be one of: keep, defer, archive-candidate`);
130
- }
131
- process.exit(1);
132
- return;
133
- }
134
-
135
- if (opts.decision === 'archive-candidate' && !opts.note) {
136
- if (opts.json) {
137
- console.log(JSON.stringify({ error: 'archive-candidate decision requires --note' }));
138
- } else {
139
- console.error('Error: archive-candidate decision requires --note');
140
- }
141
- process.exit(1);
142
- return;
143
- }
144
-
145
- const record = appendPruningReview(workspaceDir, {
146
- principleId: signal.principleId,
147
- decision: opts.decision,
148
- note: opts.note ?? '',
149
- reviewer: opts.reviewer,
150
- signalSnapshot: signal,
151
- });
152
-
153
- if (opts.json) {
154
- console.log(JSON.stringify({
155
- reviewId: record.reviewId,
156
- principleId: record.principleId,
157
- decision: record.decision,
158
- reviewer: record.reviewer,
159
- reviewedAt: record.reviewedAt,
160
- }));
161
- return;
162
- }
163
-
164
- console.log(`reviewId: ${record.reviewId}`);
165
- console.log(`principleId: ${record.principleId}`);
166
- console.log(`decision: ${record.decision}`);
167
- console.log(`reviewer: ${record.reviewer}`);
168
- console.log(`reviewedAt: ${record.reviewedAt}`);
169
- console.log('');
170
- console.log('NOTE: This audit record does not modify the principle.');
171
- }
172
-
173
- export function handlePruningExplain(opts: PruningExplainOptions): void {
174
- const workspaceDir = opts.workspace
175
- ? path.resolve(opts.workspace)
176
- : resolveWorkspaceDir();
177
-
178
- const model = new PruningReadModel({ workspaceDir });
179
- const signals = model.getPrincipleSignals();
180
- const now = new Date().toISOString();
181
-
182
- const signal = signals.find((s) => s.principleId === opts.principleId);
183
-
184
- if (!signal) {
185
- if (opts.json) {
186
- console.log(JSON.stringify({ error: `Principle not found: '${opts.principleId}'`, workspace: workspaceDir, generatedAt: now }, null, 2));
187
- } else {
188
- console.error(`Error: Principle not found: '${opts.principleId}'`);
189
- }
190
- process.exit(1);
191
- return; // unreachable but satisfies TypeScript
192
- }
193
-
194
- if (opts.json) {
195
- console.log(JSON.stringify({ workspace: workspaceDir, principleId: signal.principleId, signal, generatedAt: now }, null, 2));
196
- return;
197
- }
198
-
199
- console.log(`principleId: ${signal.principleId}`);
200
- console.log(`status: ${signal.status}`);
201
- console.log(`riskLevel: ${signal.riskLevel}`);
202
- console.log(`ageDays: ${signal.ageDays}`);
203
- console.log(`derivedPainCount: ${signal.derivedPainCount}`);
204
- console.log(`matchedCandidateCount: ${signal.matchedCandidateCount}`);
205
- console.log(`orphanCandidateCount: ${signal.orphanCandidateCount}`);
206
- console.log(`reasons:`);
207
- for (const r of signal.reasons) {
208
- console.log(` ${r}`);
209
- }
210
- console.log('');
211
- console.log('NOTE: This report is read-only. No principles are modified or deleted.');
212
- }
213
-
214
- // ── Pruning rollback ──────────────────────────────────────────────────────────
215
-
216
- export interface PruningRollbackOptions {
217
- principleId: string;
218
- note?: string;
219
- reviewer?: string;
220
- workspace?: string;
221
- json?: boolean;
222
- }
223
-
224
- export function handlePruningRollback(opts: PruningRollbackOptions): void {
225
- const workspaceDir = opts.workspace
226
- ? path.resolve(opts.workspace)
227
- : resolveWorkspaceDir();
228
-
229
- const reviews = listPruningReviews(workspaceDir, { principleId: opts.principleId });
230
- if (reviews.length === 0) {
231
- if (opts.json) {
232
- console.log(JSON.stringify({ error: `No reviews found for principle: '${opts.principleId}'` }));
233
- } else {
234
- console.error(`Error: No reviews found for principle: '${opts.principleId}'`);
235
- }
236
- process.exit(1);
237
- return;
238
- }
239
-
240
- const maskedIds = buildMaskedPrincipleSet(reviews);
241
- if (!maskedIds.has(opts.principleId)) {
242
- if (opts.json) {
243
- console.log(JSON.stringify({ error: `Principle '${opts.principleId}' is not currently masked (latest decision is not archive-candidate)` }));
244
- } else {
245
- console.error(`Error: Principle '${opts.principleId}' is not currently masked (latest decision is not archive-candidate)`);
246
- }
247
- process.exit(1);
248
- return;
249
- }
250
-
251
- const model = new PruningReadModel({ workspaceDir });
252
- const signals = model.getPrincipleSignals();
253
- const signal = signals.find((s) => s.principleId === opts.principleId) ?? undefined;
254
-
255
- const record = appendPruningReview(workspaceDir, {
256
- principleId: opts.principleId,
257
- decision: 'keep',
258
- note: opts.note ?? 'Rollback: restore principle injection',
259
- reviewer: opts.reviewer,
260
- signalSnapshot: signal,
261
- });
262
-
263
- if (opts.json) {
264
- console.log(JSON.stringify({
265
- reviewId: record.reviewId,
266
- principleId: record.principleId,
267
- decision: record.decision,
268
- reviewer: record.reviewer,
269
- reviewedAt: record.reviewedAt,
270
- }));
271
- return;
272
- }
273
-
274
- console.log(`reviewId: ${record.reviewId}`);
275
- console.log(`principleId: ${record.principleId}`);
276
- console.log(`decision: ${record.decision}`);
277
- console.log(`reviewer: ${record.reviewer}`);
278
- console.log(`reviewedAt: ${record.reviewedAt}`);
279
- console.log('');
280
- console.log('Principle has been restored to injection.');
281
- }
282
-
283
- // ── Pruning orphans ───────────────────────────────────────────────────────────
284
-
285
- export interface PruningOrphansOptions {
286
- workspace?: string;
287
- dryRun?: boolean;
288
- confirm?: boolean;
289
- json?: boolean;
290
- }
291
-
292
- function orphanActions(orphans: OrphanDerivedCandidate[]) {
293
- return orphans.map((orphan) => remediationAction({
294
- action: 'remove_orphan_reference',
295
- targetId: orphan.candidateId,
296
- previousState: orphan.status ?? 'unknown',
297
- nextState: 'removed_from_ledger_reference',
298
- reason: `${orphan.reason} (principle: ${orphan.principleId})`,
299
- }));
300
- }
301
-
302
- export function handlePruningOrphans(opts: PruningOrphansOptions): void {
303
- if (opts.dryRun && opts.confirm) {
304
- console.error('Error: --dry-run and --confirm are mutually exclusive');
305
- process.exit(1);
306
- }
307
-
308
- const workspaceDir = opts.workspace
309
- ? path.resolve(opts.workspace)
310
- : resolveWorkspaceDir();
311
-
312
- const model = new PruningReadModel({ workspaceDir });
313
- const detection: OrphanDetectionResult = model.getOrphanDerivedCandidates();
314
- const orphans = detection.candidates;
315
- const isDryRun = !opts.confirm;
316
-
317
- if (isDryRun) {
318
- const result: RemediationResult = createRemediationResult({
319
- mode: 'dry_run',
320
- repairedCount: 0,
321
- skippedCount: 0,
322
- actions: orphanActions(orphans),
323
- warnings: detection.dbReadable ? [] : ['state.db is unreadable; --confirm will be refused until DB access is restored.'],
324
- safeToConfirm: detection.dbReadable && orphans.length > 0,
325
- includeLegacyDryRun: true,
326
- });
327
-
328
- if (opts.json) {
329
- console.log(JSON.stringify({
330
- ...result,
331
- orphanDerivedCandidateCount: orphans.length,
332
- candidates: orphans,
333
- dbReadable: detection.dbReadable,
334
- }, null, 2));
335
- return;
336
- }
337
-
338
- console.log(`orphanDerivedCandidateCount: ${orphans.length}`);
339
- console.log(`dryRun: true`);
340
- console.log(`dbReadable: ${detection.dbReadable}`);
341
- console.log('');
342
- if (!detection.dbReadable) {
343
- console.log('⚠️ state.db is unreadable — orphan list may include valid candidates.');
344
- console.log(' --confirm will be refused until the DB is accessible.');
345
- console.log('');
346
- }
347
- if (orphans.length === 0) {
348
- console.log('No orphan derived candidates found.');
349
- } else {
350
- console.log('── Orphan derived candidates ──');
351
- for (const o of orphans) {
352
- console.log(` [${o.status ?? 'unknown'}] ${o.candidateId} → principle: ${o.principleId}`);
353
- console.log(` ↳ ${o.reason}`);
354
- }
355
- console.log('');
356
- console.log('NOTE: This is a dry-run. No data was modified. Use --confirm to remove orphan references.');
357
- }
358
- return;
359
- }
360
-
361
- if (!detection.dbReadable) {
362
- const result: RemediationResult = createRemediationResult({
363
- mode: 'confirm',
364
- status: 'refused',
365
- safeToConfirm: false,
366
- repairedCount: 0,
367
- skippedCount: orphans.length,
368
- actions: orphanActions(orphans),
369
- warnings: ['state.db is unreadable; refusing orphan cleanup because candidates cannot be verified.'],
370
- includeLegacyDryRun: true,
371
- });
372
-
373
- if (opts.json) {
374
- console.log(JSON.stringify({
375
- ...result,
376
- orphanDerivedCandidateCount: orphans.length,
377
- candidates: orphans,
378
- dbReadable: false,
379
- }, null, 2));
380
- } else {
381
- console.error('❌ REFUSED: state.db is unreadable — cannot safely confirm orphan cleanup.');
382
- console.error(' All derivedFromPainIds would appear as orphans when the DB is inaccessible.');
383
- console.error(' Fix the DB access issue and re-run.');
384
- }
385
- process.exit(1);
386
- return;
387
- }
388
-
389
- const orphanIdsByPrinciple = new Map<string, Set<string>>();
390
- for (const o of orphans) {
391
- if (!orphanIdsByPrinciple.has(o.principleId)) {
392
- orphanIdsByPrinciple.set(o.principleId, new Set());
393
- }
394
- orphanIdsByPrinciple.get(o.principleId)?.add(o.candidateId);
395
- }
396
-
397
- const stateDir = path.join(workspaceDir, '.state');
398
- const removedFromPrinciples = (() => {
399
- try {
400
- return removeOrphanReferencesFromLedger(stateDir, orphanIdsByPrinciple);
401
- } catch (err) {
402
- console.error(`❌ Failed to save ledger: ${err instanceof Error ? err.message : String(err)}`);
403
- process.exit(1);
404
- return [] as { principleId: string; removedIds: string[] }[];
405
- }
406
- })();
407
-
408
- const removedCount = removedFromPrinciples.reduce((sum, item) => sum + item.removedIds.length, 0);
409
- const result: RemediationResult = createRemediationResult({
410
- mode: 'confirm',
411
- repairedCount: removedCount,
412
- skippedCount: Math.max(0, orphans.length - removedCount),
413
- actions: orphanActions(orphans),
414
- warnings: [],
415
- includeLegacyDryRun: true,
416
- });
417
-
418
- if (opts.json) {
419
- console.log(JSON.stringify({
420
- ...result,
421
- orphanDerivedCandidateCount: orphans.length,
422
- candidates: orphans,
423
- dbReadable: true,
424
- removedFromPrinciples,
425
- }, null, 2));
426
- return;
427
- }
428
-
429
- console.log(`orphanDerivedCandidateCount: ${orphans.length}`);
430
- console.log(`dryRun: false`);
431
- console.log('');
432
- for (const r of removedFromPrinciples) {
433
- console.log(`principle: ${r.principleId}`);
434
- console.log(` removed: ${r.removedIds.join(', ')}`);
435
- }
436
- console.log('');
437
- console.log(`${removedFromPrinciples.length} principles updated. ${orphans.length} orphan references removed.`);
438
- }