@principles/pd-cli 1.152.12 → 1.152.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (296) hide show
  1. package/package.json +13 -7
  2. package/CHANGELOG.md +0 -23
  3. package/dist/commands/__tests__/intent-flag-wiring.test.d.ts +0 -9
  4. package/dist/commands/__tests__/intent-flag-wiring.test.d.ts.map +0 -1
  5. package/dist/commands/__tests__/intent-flag-wiring.test.js +0 -237
  6. package/dist/commands/__tests__/intent-flag-wiring.test.js.map +0 -1
  7. package/dist/commands/__tests__/legacy-cleanup.test.d.ts +0 -18
  8. package/dist/commands/__tests__/legacy-cleanup.test.d.ts.map +0 -1
  9. package/dist/commands/__tests__/legacy-cleanup.test.js +0 -467
  10. package/dist/commands/__tests__/legacy-cleanup.test.js.map +0 -1
  11. package/dist/commands/__tests__/mvp-smoke.test.d.ts +0 -15
  12. package/dist/commands/__tests__/mvp-smoke.test.d.ts.map +0 -1
  13. package/dist/commands/__tests__/mvp-smoke.test.js +0 -262
  14. package/dist/commands/__tests__/mvp-smoke.test.js.map +0 -1
  15. package/dist/commands/__tests__/pain-retry-maxTokens-flag.test.d.ts +0 -2
  16. package/dist/commands/__tests__/pain-retry-maxTokens-flag.test.d.ts.map +0 -1
  17. package/dist/commands/__tests__/pain-retry-maxTokens-flag.test.js +0 -60
  18. package/dist/commands/__tests__/pain-retry-maxTokens-flag.test.js.map +0 -1
  19. package/dist/commands/__tests__/rulecode-flag-wiring.test.d.ts +0 -21
  20. package/dist/commands/__tests__/rulecode-flag-wiring.test.d.ts.map +0 -1
  21. package/dist/commands/__tests__/rulecode-flag-wiring.test.js +0 -186
  22. package/dist/commands/__tests__/rulecode-flag-wiring.test.js.map +0 -1
  23. package/dist/commands/__tests__/rulecode-handler.test.d.ts +0 -16
  24. package/dist/commands/__tests__/rulecode-handler.test.d.ts.map +0 -1
  25. package/dist/commands/__tests__/rulecode-handler.test.js +0 -285
  26. package/dist/commands/__tests__/rulecode-handler.test.js.map +0 -1
  27. package/dist/commands/__tests__/run-rulehost-flag-wiring.test.d.ts +0 -24
  28. package/dist/commands/__tests__/run-rulehost-flag-wiring.test.d.ts.map +0 -1
  29. package/dist/commands/__tests__/run-rulehost-flag-wiring.test.js +0 -232
  30. package/dist/commands/__tests__/run-rulehost-flag-wiring.test.js.map +0 -1
  31. package/dist/commands/__tests__/runtime-activation-nextaction.test.d.ts +0 -15
  32. package/dist/commands/__tests__/runtime-activation-nextaction.test.d.ts.map +0 -1
  33. package/dist/commands/__tests__/runtime-activation-nextaction.test.js +0 -73
  34. package/dist/commands/__tests__/runtime-activation-nextaction.test.js.map +0 -1
  35. package/dist/commands/__tests__/runtime-probe-config.test.d.ts +0 -20
  36. package/dist/commands/__tests__/runtime-probe-config.test.d.ts.map +0 -1
  37. package/dist/commands/__tests__/runtime-probe-config.test.js +0 -389
  38. package/dist/commands/__tests__/runtime-probe-config.test.js.map +0 -1
  39. package/dist/commands/__tests__/telemetry-flag-wiring.test.d.ts +0 -9
  40. package/dist/commands/__tests__/telemetry-flag-wiring.test.d.ts.map +0 -1
  41. package/dist/commands/__tests__/telemetry-flag-wiring.test.js +0 -76
  42. package/dist/commands/__tests__/telemetry-flag-wiring.test.js.map +0 -1
  43. package/dist/commands/__tests__/version.test.d.ts +0 -2
  44. package/dist/commands/__tests__/version.test.d.ts.map +0 -1
  45. package/dist/commands/__tests__/version.test.js +0 -238
  46. package/dist/commands/__tests__/version.test.js.map +0 -1
  47. package/dist/commands/runtime-uat.guard.test.d.ts +0 -2
  48. package/dist/commands/runtime-uat.guard.test.d.ts.map +0 -1
  49. package/dist/commands/runtime-uat.guard.test.js +0 -153
  50. package/dist/commands/runtime-uat.guard.test.js.map +0 -1
  51. package/dist/services/__tests__/cli-output.test.d.ts +0 -18
  52. package/dist/services/__tests__/cli-output.test.d.ts.map +0 -1
  53. package/dist/services/__tests__/cli-output.test.js +0 -103
  54. package/dist/services/__tests__/cli-output.test.js.map +0 -1
  55. package/dist/services/__tests__/evaluator-runner-deps.test.d.ts +0 -2
  56. package/dist/services/__tests__/evaluator-runner-deps.test.d.ts.map +0 -1
  57. package/dist/services/__tests__/evaluator-runner-deps.test.js +0 -343
  58. package/dist/services/__tests__/evaluator-runner-deps.test.js.map +0 -1
  59. package/dist/services/__tests__/rulehost-readiness.test.d.ts +0 -2
  60. package/dist/services/__tests__/rulehost-readiness.test.d.ts.map +0 -1
  61. package/dist/services/__tests__/rulehost-readiness.test.js +0 -311
  62. package/dist/services/__tests__/rulehost-readiness.test.js.map +0 -1
  63. package/dist/services/__tests__/runtime-adapter-resolver.test.d.ts +0 -18
  64. package/dist/services/__tests__/runtime-adapter-resolver.test.d.ts.map +0 -1
  65. package/dist/services/__tests__/runtime-adapter-resolver.test.js +0 -673
  66. package/dist/services/__tests__/runtime-adapter-resolver.test.js.map +0 -1
  67. package/dist/utils/production-workspace-guard.test.d.ts +0 -2
  68. package/dist/utils/production-workspace-guard.test.d.ts.map +0 -1
  69. package/dist/utils/production-workspace-guard.test.js +0 -137
  70. package/dist/utils/production-workspace-guard.test.js.map +0 -1
  71. package/scripts/llm-dogfood.ts +0 -456
  72. package/scripts/migrate-illegal-expected-decision.ts +0 -252
  73. package/src/commands/__tests__/intent-flag-wiring.test.ts +0 -282
  74. package/src/commands/__tests__/legacy-cleanup.test.ts +0 -602
  75. package/src/commands/__tests__/mvp-smoke.test.ts +0 -300
  76. package/src/commands/__tests__/pain-retry-maxTokens-flag.test.ts +0 -73
  77. package/src/commands/__tests__/rulecode-flag-wiring.test.ts +0 -237
  78. package/src/commands/__tests__/rulecode-handler.test.ts +0 -369
  79. package/src/commands/__tests__/run-rulehost-flag-wiring.test.ts +0 -292
  80. package/src/commands/__tests__/runtime-activation-nextaction.test.ts +0 -81
  81. package/src/commands/__tests__/runtime-probe-config.test.ts +0 -432
  82. package/src/commands/__tests__/telemetry-flag-wiring.test.ts +0 -84
  83. package/src/commands/__tests__/version.test.ts +0 -251
  84. package/src/commands/admission-gate.ts +0 -30
  85. package/src/commands/artifact.ts +0 -82
  86. package/src/commands/build-trajectory-evidence.ts +0 -298
  87. package/src/commands/candidate.ts +0 -1250
  88. package/src/commands/codex-ingest-catchup.ts +0 -114
  89. package/src/commands/codex-ingest-quarantine.ts +0 -127
  90. package/src/commands/codex-reconcile.ts +0 -84
  91. package/src/commands/codex-setup.ts +0 -476
  92. package/src/commands/codex-worker.ts +0 -185
  93. package/src/commands/command-helpers.ts +0 -24
  94. package/src/commands/config-doctor.ts +0 -193
  95. package/src/commands/console.ts +0 -797
  96. package/src/commands/context.ts +0 -72
  97. package/src/commands/demo-story-a.ts +0 -241
  98. package/src/commands/diagnose.ts +0 -756
  99. package/src/commands/errors-list.ts +0 -441
  100. package/src/commands/evolution-tasks-list.ts +0 -48
  101. package/src/commands/evolution-tasks-show.ts +0 -62
  102. package/src/commands/flow.ts +0 -60
  103. package/src/commands/health-codex.ts +0 -576
  104. package/src/commands/health.ts +0 -315
  105. package/src/commands/history.ts +0 -63
  106. package/src/commands/intent.ts +0 -457
  107. package/src/commands/legacy-cleanup.ts +0 -531
  108. package/src/commands/legacy-import.ts +0 -104
  109. package/src/commands/mvp-smoke.ts +0 -160
  110. package/src/commands/pain-evidence.ts +0 -226
  111. package/src/commands/pain-list.ts +0 -239
  112. package/src/commands/pain-record.ts +0 -612
  113. package/src/commands/pain-retry.ts +0 -916
  114. package/src/commands/principles-stats.ts +0 -700
  115. package/src/commands/proven-channel-baseline.ts +0 -115
  116. package/src/commands/quality-scorecard.ts +0 -272
  117. package/src/commands/remediation-output.ts +0 -66
  118. package/src/commands/rulecode.ts +0 -465
  119. package/src/commands/run.ts +0 -89
  120. package/src/commands/runtime-activation.ts +0 -1629
  121. package/src/commands/runtime-artifact-repair.ts +0 -524
  122. package/src/commands/runtime-canary.ts +0 -395
  123. package/src/commands/runtime-compatibility-scan.ts +0 -105
  124. package/src/commands/runtime-diagnostics-export.ts +0 -229
  125. package/src/commands/runtime-features.ts +0 -153
  126. package/src/commands/runtime-gfi-snapshot.ts +0 -135
  127. package/src/commands/runtime-health-snapshot.ts +0 -108
  128. package/src/commands/runtime-init.ts +0 -429
  129. package/src/commands/runtime-internalization-enqueue-successors.ts +0 -530
  130. package/src/commands/runtime-internalization-integrity-repair.ts +0 -79
  131. package/src/commands/runtime-internalization-integrity.ts +0 -107
  132. package/src/commands/runtime-internalization-queue.ts +0 -135
  133. package/src/commands/runtime-internalization-retry.ts +0 -191
  134. package/src/commands/runtime-internalization-run-once.ts +0 -791
  135. package/src/commands/runtime-internalization-run-rulehost.ts +0 -749
  136. package/src/commands/runtime-internalization-wake-once.ts +0 -87
  137. package/src/commands/runtime-pain-flood-simulation.ts +0 -121
  138. package/src/commands/runtime-pruning.ts +0 -438
  139. package/src/commands/runtime-recovery-failed-tasks.ts +0 -258
  140. package/src/commands/runtime-recovery.ts +0 -109
  141. package/src/commands/runtime-synthetic-baseline.ts +0 -70
  142. package/src/commands/runtime-uat.guard.test.ts +0 -175
  143. package/src/commands/runtime-uat.ts +0 -380
  144. package/src/commands/runtime.ts +0 -473
  145. package/src/commands/samples-list.ts +0 -39
  146. package/src/commands/samples-review.ts +0 -36
  147. package/src/commands/task.ts +0 -271
  148. package/src/commands/telemetry.ts +0 -349
  149. package/src/commands/trace.ts +0 -174
  150. package/src/commands/trajectory-db-unavailable.ts +0 -19
  151. package/src/commands/trajectory.ts +0 -64
  152. package/src/commands/version.ts +0 -49
  153. package/src/config-reader.ts +0 -122
  154. package/src/index.ts +0 -1276
  155. package/src/legacy/legacy-import.ts +0 -179
  156. package/src/legacy/session-history-import.ts +0 -203
  157. package/src/resolve-workspace.ts +0 -106
  158. package/src/services/__tests__/cli-output.test.ts +0 -130
  159. package/src/services/__tests__/evaluator-runner-deps.test.ts +0 -382
  160. package/src/services/__tests__/rulehost-readiness.test.ts +0 -363
  161. package/src/services/__tests__/runtime-adapter-resolver.test.ts +0 -793
  162. package/src/services/cli-output.ts +0 -95
  163. package/src/services/config-doctor.ts +0 -697
  164. package/src/services/console-launcher.ts +0 -537
  165. package/src/services/demo-rule-compiler.ts +0 -40
  166. package/src/services/demo-story-a-runner.ts +0 -471
  167. package/src/services/mainline-snapshot-assembler.ts +0 -579
  168. package/src/services/pain-flood-simulation-runner.ts +0 -462
  169. package/src/services/pd-config-loader.ts +0 -433
  170. package/src/services/proven-channel-baseline-runner.ts +0 -157
  171. package/src/services/quality-scorecard/data-extractor.ts +0 -150
  172. package/src/services/quality-scorecard/local-evaluator.ts +0 -142
  173. package/src/services/quality-scorecard/strong-model-gate.ts +0 -202
  174. package/src/services/resolve-runtime-from-pd-config.ts +0 -230
  175. package/src/services/rulehost-pipeline-runner.ts +0 -1214
  176. package/src/services/rulehost-readiness.ts +0 -326
  177. package/src/services/runtime-adapter-resolver.ts +0 -364
  178. package/src/services/synthetic-baseline-runner.ts +0 -400
  179. package/src/services/version-report.ts +0 -253
  180. package/src/services/workspace-tool-semantics.ts +0 -26
  181. package/src/utils/path-security.ts +0 -96
  182. package/src/utils/production-workspace-guard.test.ts +0 -157
  183. package/src/utils/production-workspace-guard.ts +0 -210
  184. package/tests/bdd/cli-contract.steps.ts +0 -346
  185. package/tests/bdd/principles-stats.steps.ts +0 -211
  186. package/tests/bdd/support/gherkin-loader.ts +0 -147
  187. package/tests/bdd/support/repo-root.ts +0 -62
  188. package/tests/bdd/support/vitest-bdd.ts +0 -179
  189. package/tests/commands/admission-gate-coverage.test.ts +0 -79
  190. package/tests/commands/build-trajectory-evidence.test.ts +0 -508
  191. package/tests/commands/candidate-audit-repair.test.ts +0 -421
  192. package/tests/commands/candidate-intake.test.ts +0 -732
  193. package/tests/commands/candidate-internalization-backfill.test.ts +0 -548
  194. package/tests/commands/candidate-internalize-lineage.test.ts +0 -628
  195. package/tests/commands/candidate-internalize.test.ts +0 -299
  196. package/tests/commands/candidate-route.test.ts +0 -329
  197. package/tests/commands/candidate-show.test.ts +0 -95
  198. package/tests/commands/cli-command-tree.test.ts +0 -144
  199. package/tests/commands/cli-help-snapshot.test.ts +0 -155
  200. package/tests/commands/cli-skill-contract.test.ts +0 -121
  201. package/tests/commands/codex-consent-reversibility.steps.test.ts +0 -299
  202. package/tests/commands/codex-ingest-quarantine.test.ts +0 -136
  203. package/tests/commands/codex-setup.test.ts +0 -297
  204. package/tests/commands/codex-worker-daemon.test.ts +0 -95
  205. package/tests/commands/codex-worker-registration.test.ts +0 -207
  206. package/tests/commands/config-doctor.test.ts +0 -336
  207. package/tests/commands/console-launcher-edge-cases.test.ts +0 -388
  208. package/tests/commands/console-open.test.ts +0 -1381
  209. package/tests/commands/context.test.ts +0 -114
  210. package/tests/commands/demo-story-a.test.ts +0 -318
  211. package/tests/commands/diagnose.test.ts +0 -1803
  212. package/tests/commands/errors-list.test.ts +0 -679
  213. package/tests/commands/evolution-tasks-list.test.ts +0 -41
  214. package/tests/commands/evolution-tasks-show.test.ts +0 -46
  215. package/tests/commands/health-codex.test.ts +0 -349
  216. package/tests/commands/health-host-wiring.test.ts +0 -76
  217. package/tests/commands/health-reliability.test.ts +0 -99
  218. package/tests/commands/health.test.ts +0 -413
  219. package/tests/commands/intent.test.ts +0 -321
  220. package/tests/commands/legacy-cleanup.test.ts +0 -148
  221. package/tests/commands/pain-evidence.test.ts +0 -518
  222. package/tests/commands/pain-list.test.ts +0 -219
  223. package/tests/commands/pain-record-async.test.ts +0 -335
  224. package/tests/commands/pain-record-session-parser.test.ts +0 -228
  225. package/tests/commands/pain-record.test.ts +0 -851
  226. package/tests/commands/pain-retry.test.ts +0 -1121
  227. package/tests/commands/plugin-config-resolution-cutover.test.ts +0 -229
  228. package/tests/commands/pri-393-runtime-config-unification.test.ts +0 -443
  229. package/tests/commands/principles-stats-wiring.test.ts +0 -135
  230. package/tests/commands/principles-stats.test.ts +0 -274
  231. package/tests/commands/product-path-regression.test.ts +0 -86
  232. package/tests/commands/proven-channel-baseline.test.ts +0 -441
  233. package/tests/commands/rulecode.test.ts +0 -177
  234. package/tests/commands/run-rulehost-handler.test.ts +0 -908
  235. package/tests/commands/runtime-activation-approve-flag-wiring.test.ts +0 -227
  236. package/tests/commands/runtime-activation-deactivate-flag-wiring.test.ts +0 -167
  237. package/tests/commands/runtime-activation-dispatch-flag-wiring.test.ts +0 -262
  238. package/tests/commands/runtime-activation-governance-audit.test.ts +0 -95
  239. package/tests/commands/runtime-activation-list-flag-wiring.test.ts +0 -193
  240. package/tests/commands/runtime-activation-promote-flag-wiring.test.ts +0 -248
  241. package/tests/commands/runtime-activation-shadow-telemetry.test.ts +0 -130
  242. package/tests/commands/runtime-activation.test.ts +0 -2052
  243. package/tests/commands/runtime-artifact-repair-registration.test.ts +0 -74
  244. package/tests/commands/runtime-artifact-repair.test.ts +0 -404
  245. package/tests/commands/runtime-canary.test.ts +0 -430
  246. package/tests/commands/runtime-compatibility-scan.test.ts +0 -146
  247. package/tests/commands/runtime-diagnostics-export.test.ts +0 -175
  248. package/tests/commands/runtime-features.test.ts +0 -249
  249. package/tests/commands/runtime-health-snapshot.test.ts +0 -358
  250. package/tests/commands/runtime-init-empty-workspace.test.ts +0 -252
  251. package/tests/commands/runtime-init.test.ts +0 -420
  252. package/tests/commands/runtime-internalization-enqueue-successors.test.ts +0 -782
  253. package/tests/commands/runtime-internalization-integrity-repair.test.ts +0 -239
  254. package/tests/commands/runtime-internalization-integrity.test.ts +0 -140
  255. package/tests/commands/runtime-internalization-queue.test.ts +0 -380
  256. package/tests/commands/runtime-internalization-retry-owner-authority.test.ts +0 -431
  257. package/tests/commands/runtime-internalization-run-once-evaluator-parity.test.ts +0 -269
  258. package/tests/commands/runtime-internalization-run-once-language.test.ts +0 -303
  259. package/tests/commands/runtime-internalization-run-once-real-config.test.ts +0 -237
  260. package/tests/commands/runtime-internalization-run-once-rollout-parity.test.ts +0 -706
  261. package/tests/commands/runtime-internalization-run-once.test.ts +0 -1791
  262. package/tests/commands/runtime-internalization-wake-once.test.ts +0 -171
  263. package/tests/commands/runtime-internalization.test.ts +0 -53
  264. package/tests/commands/runtime-pain-flood-simulation.test.ts +0 -418
  265. package/tests/commands/runtime-pruning.test.ts +0 -694
  266. package/tests/commands/runtime-recovery-failed-tasks.test.ts +0 -328
  267. package/tests/commands/runtime-recovery.test.ts +0 -120
  268. package/tests/commands/runtime-synthetic-baseline.test.ts +0 -249
  269. package/tests/commands/runtime-uat.test.ts +0 -397
  270. package/tests/commands/runtime.test.ts +0 -392
  271. package/tests/commands/samples-list.test.ts +0 -43
  272. package/tests/commands/samples-review.test.ts +0 -41
  273. package/tests/commands/task.test.ts +0 -153
  274. package/tests/commands/telemetry.test.ts +0 -190
  275. package/tests/commands/trace.test.ts +0 -316
  276. package/tests/config-reader.test.ts +0 -143
  277. package/tests/e2e/candidate-intake-e2e.test.ts +0 -338
  278. package/tests/e2e/cli-full-flow.test.ts +0 -233
  279. package/tests/e2e/cross-package-acceptance.test.ts +0 -635
  280. package/tests/helpers/pd-cli-path.ts +0 -5
  281. package/tests/pd-cli-smoke.test.ts +0 -13
  282. package/tests/resolve-workspace.test.ts +0 -196
  283. package/tests/services/config-doctor-signal-health.test.ts +0 -109
  284. package/tests/services/console-launcher.test.ts +0 -114
  285. package/tests/services/demo-rule-compiler.test.ts +0 -242
  286. package/tests/services/mainline-snapshot-assembler.test.ts +0 -572
  287. package/tests/services/pd-config-loader.test.ts +0 -505
  288. package/tests/services/proven-channel-baseline-runner.test.ts +0 -30
  289. package/tests/services/quality-scorecard/strong-model-gate.test.ts +0 -133
  290. package/tests/services/resolve-runtime-from-pd-config.test.ts +0 -485
  291. package/tests/services/rulehost-pipeline-e2e.test.ts +0 -538
  292. package/tests/services/rulehost-pipeline-runner.test.ts +0 -1242
  293. package/tests/services/workspace-tool-semantics.test.ts +0 -76
  294. package/tests/utils/path-security.test.ts +0 -180
  295. package/tsconfig.json +0 -26
  296. package/vitest.config.ts +0 -10
@@ -1,258 +0,0 @@
1
- import * as path from 'path';
2
- import {
3
- createRecoverySweepService,
4
- isPeerRunnerKind,
5
- isDiagnosticianStageKind,
6
- type RecoverySweepServiceHandle,
7
- } from '@principles/core/runtime-v2';
8
- import { resolveWorkspaceDir } from '../resolve-workspace.js';
9
-
10
- interface RecoveryFailedTasksOptions {
11
- workspace?: string;
12
- dryRun?: boolean;
13
- confirm?: boolean;
14
- force?: boolean;
15
- json?: boolean;
16
- }
17
-
18
- interface TaskDetail {
19
- taskId: string;
20
- taskKind: string;
21
- status: string;
22
- attemptCount: number;
23
- maxAttempts: number;
24
- action: string;
25
- reason: string;
26
- nextAction: string;
27
- }
28
-
29
- /** Stage-task ID convention prefix → the remainder is the parent task ID. */
30
- const DIAG_STAGE_ID_PREFIXES = ['diag_rootcause-', 'diag_distiller-', 'diag_router-'] as const;
31
-
32
- /**
33
- * PRI-674 review P2: per-kind execution guidance must point at commands that
34
- * actually support the recovered task kind (cli-6-output-next-action).
35
- *
36
- * Verified against real command surfaces:
37
- * - `pd runtime internalization run-once` supports ONLY the 6 peer runner
38
- * kinds (SUPPORTED_RUNNERS in runtime-internalization-run-once.ts).
39
- * - `pd diagnose run --task-id <id>` is the only diagnostician execution
40
- * entry (SplitDiagnosticianRunner runs the full A→B→C pipeline from the
41
- * PARENT task; running a diag_* stage as parent would create bogus nested
42
- * stage tasks).
43
- * - diag_* stage linkage: persisted inputRef = parent task ID
44
- * (SplitDiagnosticianRunner.ensureSubTask), with the
45
- * diag_<stage>-<parentTaskId> ID convention as fallback. When the parent
46
- * cannot be resolved we say so instead of printing a guessed command.
47
- */
48
- function buildExecutionNextAction(t: { taskId: string; taskKind: string; inputRef: string | null }): string {
49
- // Branch on the authoritative taskKind, never on taskId shape.
50
- if (isDiagnosticianStageKind(t.taskKind)) {
51
- // Parent from persisted inputRef; fallback: diag_<stage>-<parentTaskId>
52
- // ID convention (plain prefix split — no regex needed for fixed literals).
53
- const matchedPrefix = DIAG_STAGE_ID_PREFIXES.find((p) => t.taskId.startsWith(p));
54
- const parentTaskId = t.inputRef && t.inputRef.trim() !== ''
55
- ? t.inputRef
56
- : matchedPrefix
57
- ? t.taskId.slice(matchedPrefix.length).trim() || undefined
58
- : undefined;
59
- if (parentTaskId) {
60
- return `Stage task of diagnostician parent "${parentTaskId}". Recover the parent, then run: pd diagnose run --task-id ${parentTaskId} (runs the full pipeline including this stage)`;
61
- }
62
- return `Stage task whose diagnostician parent could not be resolved (no inputRef linkage, task ID does not follow diag_<stage>-<parentTaskId>). Inspect: pd diagnose status --task-id ${t.taskId} — do not run a stage task directly as a parent`;
63
- }
64
- if (t.taskKind === 'diagnostician') {
65
- return `Run: pd diagnose run --task-id ${t.taskId} (executes the full diag_rootcause→diag_distiller→diag_router pipeline)`;
66
- }
67
- if (isPeerRunnerKind(t.taskKind)) {
68
- return `Run: pd runtime internalization run-once --runner ${t.taskKind} (executes the next ready ${t.taskKind} task)`;
69
- }
70
- return `Task kind ${t.taskKind} has no registered CLI execution entry. Inspect: pd diagnose status --task-id ${t.taskId}, or use the Console failed-tasks page`;
71
- }
72
-
73
- export async function handleRuntimeRecoveryFailedTasks(opts: RecoveryFailedTasksOptions): Promise<void> {
74
- if (opts.dryRun && opts.confirm) {
75
- if (opts.json) {
76
- console.log(JSON.stringify({
77
- ok: false,
78
- reason: 'Error: --dry-run and --confirm are mutually exclusive',
79
- nextAction: 'Specify only one of --dry-run or --confirm',
80
- }, null, 2));
81
- } else {
82
- console.error('Error: --dry-run and --confirm are mutually exclusive');
83
- }
84
- process.exitCode = 1;
85
- return;
86
- }
87
- const isConfirm = opts.confirm ?? false;
88
- const isDryRun = !isConfirm;
89
-
90
- let serviceHandle: RecoverySweepServiceHandle | null = null;
91
-
92
- try {
93
- const workspaceDir = opts.workspace ? path.resolve(opts.workspace) : resolveWorkspaceDir();
94
- const handle = await createRecoverySweepService({ workspaceDir });
95
- serviceHandle = handle;
96
-
97
- const failedTasks = await handle.service.detectFailedTasks();
98
- const taskDetails: TaskDetail[] = [];
99
- let recoveredCount = 0;
100
- let skippedCount = 0;
101
-
102
- for (const t of failedTasks) {
103
- if (t.isExhausted && !opts.force) {
104
- taskDetails.push({
105
- taskId: t.taskId,
106
- taskKind: t.taskKind,
107
- status: t.status,
108
- attemptCount: t.attemptCount,
109
- maxAttempts: t.maxAttempts,
110
- action: 'skipped',
111
- reason: `Task has exhausted max attempts (${t.attemptCount}/${t.maxAttempts})`,
112
- nextAction: 'Run with --force to recover this task',
113
- });
114
- skippedCount++;
115
- } else {
116
- if (isConfirm) {
117
- const result = await handle.service.recoverFailedTask(t.taskId, opts.force);
118
- if (result) {
119
- recoveredCount++;
120
- taskDetails.push({
121
- taskId: t.taskId,
122
- taskKind: t.taskKind,
123
- status: t.status,
124
- attemptCount: t.attemptCount,
125
- maxAttempts: t.maxAttempts,
126
- action: 'recovered',
127
- reason: t.isExhausted
128
- ? `Task exhausted max attempts (${t.attemptCount}/${t.maxAttempts}) but --force specified — reset to pending`
129
- : `Task failed and attempts remain (${t.attemptCount}/${t.maxAttempts}) — reset to pending`,
130
- nextAction: `Task recovered to pending. ${buildExecutionNextAction({ taskId: t.taskId, taskKind: t.taskKind, inputRef: t.inputRef })}`,
131
- });
132
- } else {
133
- skippedCount++;
134
- taskDetails.push({
135
- taskId: t.taskId,
136
- taskKind: t.taskKind,
137
- status: t.status,
138
- attemptCount: t.attemptCount,
139
- maxAttempts: t.maxAttempts,
140
- action: 'skipped',
141
- reason: 'Task recovery skipped (task no longer failed or concurrently modified)',
142
- nextAction: 'Verify task status using task list',
143
- });
144
- }
145
- } else {
146
- recoveredCount++;
147
- taskDetails.push({
148
- taskId: t.taskId,
149
- taskKind: t.taskKind,
150
- status: t.status,
151
- attemptCount: t.attemptCount,
152
- maxAttempts: t.maxAttempts,
153
- action: 'would_recover',
154
- reason: t.isExhausted
155
- ? `Task exhausted max attempts (${t.attemptCount}/${t.maxAttempts}) but --force specified — reset to pending`
156
- : `Task failed and attempts remain (${t.attemptCount}/${t.maxAttempts}) — reset to pending`,
157
- nextAction: 'Run with --confirm to recover this task',
158
- });
159
- }
160
- }
161
- }
162
-
163
- const mode = isDryRun ? 'dry_run' : 'confirm';
164
- let summaryReason = '';
165
- let summaryNextAction = '';
166
-
167
- if (isDryRun) {
168
- if (taskDetails.length === 0) {
169
- summaryReason = 'No failed internalization or diagnostician tasks found';
170
- summaryNextAction = 'Nothing to recover';
171
- } else {
172
- summaryReason = `Found ${recoveredCount} recoverable and ${skippedCount} exhausted failed tasks`;
173
- summaryNextAction = `Run with --confirm to recover tasks, and use --force to recover exhausted tasks`;
174
- }
175
- } else {
176
- summaryReason = `Successfully recovered ${recoveredCount} failed tasks, skipped ${skippedCount} tasks`;
177
- // PRI-674 review P2: mixed recoveries span different executors — split
178
- // the summary by actual command surface instead of one command for all.
179
- if (recoveredCount > 0) {
180
- const diagParents: string[] = [];
181
- const diagStages: string[] = [];
182
- const peerTasks: string[] = [];
183
- const otherTasks: string[] = [];
184
- for (const t of taskDetails) {
185
- if (t.action !== 'recovered') continue;
186
- if (t.taskKind === 'diagnostician') diagParents.push(t.taskId);
187
- else if (isDiagnosticianStageKind(t.taskKind)) diagStages.push(t.taskId);
188
- else if (isPeerRunnerKind(t.taskKind)) peerTasks.push(t.taskId);
189
- else otherTasks.push(t.taskId);
190
- }
191
- const lines: string[] = [];
192
- if (diagParents.length > 0) {
193
- lines.push(`For diagnostician parent task(s) (${diagParents.join(', ')}): pd diagnose run --task-id <taskId>`);
194
- }
195
- if (diagStages.length > 0) {
196
- lines.push(`For diag_* stage task(s) (${diagStages.join(', ')}): recover the parent diagnostician task, then pd diagnose run --task-id <parentTaskId> (each stage's parent is in its per-task nextAction)`);
197
- }
198
- if (peerTasks.length > 0) {
199
- lines.push(`For internalization task(s) (${peerTasks.join(', ')}): pd runtime internalization run-once --runner <kind>`);
200
- }
201
- if (otherTasks.length > 0) {
202
- lines.push(`For other task(s) (${otherTasks.join(', ')}): no registered CLI execution entry — see per-task nextAction`);
203
- }
204
- summaryNextAction = `Tasks recovered to pending. Execute by kind: ${lines.join('; ')}`;
205
- } else {
206
- summaryNextAction = 'No tasks recovered';
207
- }
208
- }
209
-
210
- if (opts.json) {
211
- console.log(JSON.stringify({
212
- ok: true,
213
- mode,
214
- recoveredCount,
215
- skippedCount,
216
- tasks: taskDetails,
217
- reason: summaryReason,
218
- nextAction: summaryNextAction,
219
- }, null, 2));
220
- } else {
221
- console.log(`Failed Tasks Recovery (${mode.toUpperCase()})`);
222
- console.log(` reason: ${summaryReason}`);
223
- console.log(` nextAction: ${summaryNextAction}`);
224
- console.log(` recovered: ${recoveredCount}`);
225
- console.log(` skipped: ${skippedCount}`);
226
- console.log('');
227
- if (taskDetails.length > 0) {
228
- console.log('Tasks:');
229
- for (const t of taskDetails) {
230
- console.log(` - ${t.taskId} (${t.taskKind})`);
231
- console.log(` action: ${t.action}`);
232
- console.log(` reason: ${t.reason}`);
233
- console.log(` nextAction: ${t.nextAction}`);
234
- }
235
- console.log('');
236
- }
237
- }
238
-
239
- if (recoveredCount > 0 && isDryRun) {
240
- process.exitCode = 1;
241
- }
242
- } catch (err: unknown) {
243
- if (opts.json) {
244
- console.log(JSON.stringify({
245
- ok: false,
246
- reason: err instanceof Error ? err.message : String(err),
247
- nextAction: 'Check workspace path and DB connectivity',
248
- }, null, 2));
249
- } else {
250
- console.error(`Error: ${err instanceof Error ? err.message : String(err)}`);
251
- }
252
- process.exitCode = 1;
253
- } finally {
254
- if (serviceHandle) {
255
- await serviceHandle.close();
256
- }
257
- }
258
- }
@@ -1,109 +0,0 @@
1
- import * as path from 'path';
2
- import { createRecoverySweepService } from '@principles/core/runtime-v2';
3
- import { resolveWorkspaceDir } from '../resolve-workspace.js';
4
- import { createRemediationResult, remediationAction } from './remediation-output.js';
5
- import type { RemediationResult } from './remediation-output.js';
6
- import { emitResult, emitFlagConflict } from '../services/cli-output.js';
7
-
8
- interface RecoverySweepOptions {
9
- workspace?: string;
10
- dryRun?: boolean;
11
- confirm?: boolean;
12
- json?: boolean;
13
- }
14
-
15
- function formatTextOutput(output: RemediationResult): string {
16
- const lines: string[] = [];
17
-
18
- lines.push(`Recovery Sweep (${output.mode})`);
19
- lines.push(` status: ${output.status}`);
20
- lines.push(` safeToConfirm: ${output.safeToConfirm}`);
21
- lines.push(` repairedCount: ${output.repairedCount}`);
22
- lines.push(` skippedCount: ${output.skippedCount}`);
23
-
24
- if (output.warnings.length > 0) {
25
- lines.push(` warnings:`);
26
- for (const warning of output.warnings) lines.push(` - ${warning}`);
27
- }
28
- for (const action of output.actions.slice(0, 5)) {
29
- lines.push(` ${action.targetId}: ${action.previousState ?? '(unknown)'} → ${action.nextState ?? '(unknown)'}`);
30
- lines.push(` action: ${action.action}`);
31
- lines.push(` reason: ${action.reason}`);
32
- }
33
- if (output.mode === 'dry_run' && output.actions.length > 0) {
34
- lines.push(` (use --confirm to recover expired leases)`);
35
- } else if (output.actions.length === 0) {
36
- lines.push(` no expired leases found`);
37
- }
38
-
39
- return lines.join('\n');
40
- }
41
-
42
- export async function handleRuntimeRecoverySweep(opts: RecoverySweepOptions): Promise<void> {
43
- if (opts.dryRun && opts.confirm) {
44
- // PRI-432: Bug fix — flag conflict now emits JSON when --json is set
45
- // (previously always used console.error, violating CLI Operator Gate rule #1)
46
- const exitCode = emitFlagConflict({ json: opts.json ?? false });
47
- process.exit(exitCode);
48
- return;
49
- }
50
- const workspaceDir = opts.workspace ? path.resolve(opts.workspace) : resolveWorkspaceDir();
51
- const isConfirm = opts.confirm ?? false;
52
- const isDryRun = !isConfirm;
53
-
54
- const { service, close } = await createRecoverySweepService({ workspaceDir });
55
-
56
- try {
57
- const expiredLeaseTaskIds = await service.detectExpiredLeases();
58
-
59
- const actions = expiredLeaseTaskIds.map((taskId) => remediationAction({
60
- action: 'recover_expired_lease',
61
- targetId: taskId,
62
- previousState: 'leased',
63
- nextState: 'retry_wait',
64
- reason: 'Task lease is expired and can be recovered by the operator sweep.',
65
- }));
66
- const warnings: string[] = [];
67
- let repairedCount = 0;
68
- let failedCount = 0;
69
-
70
- if (isConfirm && expiredLeaseTaskIds.length > 0) {
71
- for (const taskId of expiredLeaseTaskIds) {
72
- try {
73
- const result = await service.recoverTask(taskId);
74
- if (result) {
75
- repairedCount++;
76
- const action = actions.find((a) => a.targetId === taskId);
77
- if (action) {
78
- action.previousState = result.previousStatus;
79
- action.nextState = result.newStatus;
80
- }
81
- }
82
- } catch (err) {
83
- failedCount++;
84
- warnings.push(`${taskId}: ${err instanceof Error ? err.message : String(err)}`);
85
- }
86
- }
87
- }
88
- const output = createRemediationResult({
89
- mode: isDryRun ? 'dry_run' : 'confirm',
90
- repairedCount,
91
- skippedCount: failedCount,
92
- actions,
93
- warnings,
94
- status: failedCount > 0 && repairedCount === 0 ? 'error' : undefined,
95
- safeToConfirm: isDryRun && expiredLeaseTaskIds.length > 0,
96
- });
97
-
98
- emitResult(output, {
99
- json: opts.json ?? false,
100
- formatText: formatTextOutput,
101
- });
102
-
103
- if (expiredLeaseTaskIds.length > 0 && isDryRun) {
104
- process.exitCode = 1;
105
- }
106
- } finally {
107
- await close();
108
- }
109
- }
@@ -1,70 +0,0 @@
1
- import * as path from 'path';
2
- import * as os from 'os';
3
- import * as fs from 'fs';
4
- import { runSyntheticBaseline } from '../services/synthetic-baseline-runner.js';
5
- import type { SyntheticBaselineSummary } from '@principles/core/runtime-v2';
6
-
7
- interface CliSyntheticBaselineOptions {
8
- workspace?: string;
9
- json?: boolean;
10
- }
11
-
12
- function formatTextOutput(summary: SyntheticBaselineSummary): string {
13
- const lines: string[] = [];
14
- const icon = summary.status === 'passed' ? '✓' : summary.status === 'degraded' ? '⚠' : '✗';
15
-
16
- lines.push('PD Synthetic Workload Baseline');
17
- lines.push(`generatedAt: ${summary.generatedAt}`);
18
- lines.push(`workspaceMode: ${summary.workspaceMode}`);
19
- lines.push(`OVERALL: ${icon} ${summary.status.toUpperCase()}`);
20
- lines.push('');
21
-
22
- for (const stage of summary.stages) {
23
- const stageIcon = stage.status === 'passed' ? '✓' : stage.status === 'skipped' ? '○' : '✗';
24
- lines.push(` ${stageIcon} ${stage.name}: ${stage.status}`);
25
- if (stage.reason) {
26
- lines.push(` reason: ${stage.reason}`);
27
- }
28
- }
29
-
30
- if (summary.recommendedNextIssue) {
31
- lines.push('');
32
- lines.push(`Recommended next issue: ${summary.recommendedNextIssue}`);
33
- }
34
-
35
- return lines.join('\n');
36
- }
37
-
38
- export async function handleRuntimeSyntheticBaseline(opts: CliSyntheticBaselineOptions): Promise<void> {
39
- const workspaceDir = opts.workspace
40
- ? path.resolve(opts.workspace)
41
- : fs.mkdtempSync(path.join(os.tmpdir(), 'pd-synth-baseline-'));
42
- const workspaceMode: 'temp' | 'explicit_workspace' = opts.workspace ? 'explicit_workspace' : 'temp';
43
-
44
- try {
45
- const summary = await runSyntheticBaseline({
46
- workspaceDir,
47
- workspaceMode,
48
- });
49
-
50
- if (opts.json) {
51
- console.log(JSON.stringify(summary, null, 2));
52
- } else {
53
- console.log(formatTextOutput(summary));
54
- }
55
-
56
- if (summary.status !== 'passed') {
57
- console.error('');
58
- console.error(`FAIL: status=${summary.status}`);
59
- process.exitCode = 1;
60
- }
61
- } finally {
62
- if (workspaceMode === 'temp') {
63
- try {
64
- fs.rmSync(workspaceDir, { recursive: true, force: true });
65
- } catch {
66
- // ignore cleanup errors on Windows
67
- }
68
- }
69
- }
70
- }
@@ -1,175 +0,0 @@
1
- /**
2
- * PRI-334: Runtime UAT guard — command-level integration tests.
3
- *
4
- * These tests verify the guard is wired into the real Commander command
5
- * and that refused paths do NOT call execFileSync (mutation prevention).
6
- */
7
- import { describe, it, expect, vi, beforeEach, afterAll, beforeAll } from 'vitest';
8
- import { Command } from 'commander';
9
- import * as path from 'path';
10
- import * as os from 'os';
11
-
12
- // ─── Mocks ─────────────────────────────────────────────────────────────────
13
- const mockExecFileSync = vi.fn();
14
- vi.mock('child_process', () => ({
15
- execFileSync: mockExecFileSync,
16
- }));
17
-
18
- const { handleRuntimeUat } = await import('./runtime-uat.js');
19
- const { guardUatWorkspace } = await import('../utils/production-workspace-guard.js');
20
-
21
- // ─── Cross-platform production workspace path ─────────────────────────────────
22
- // Mirrors the default in production-workspace-guard.ts: ~/.openclaw/workspace.
23
- // Using this instead of hardcoded "D:\..." paths ensures tests work on Linux/macOS CI.
24
- const PROD_WORKSPACE = path.join(os.homedir(), '.openclaw', 'workspace');
25
-
26
- // ─── Test Setup ─────────────────────────────────────────────────────────────
27
- const capturedStderr: string[] = [];
28
- const capturedStdout: string[] = [];
29
- let capturedExitCode: number | null = null;
30
-
31
- const originalExit = process.exit;
32
- const originalError = console.error;
33
- const originalLog = console.log;
34
- const originalEnv = { ...process.env };
35
-
36
- beforeAll(() => {
37
- process.exit = vi.fn(((code?: number) => {
38
- capturedExitCode = code ?? 0;
39
- }) as typeof process.exit);
40
- console.error = vi.fn((...args: unknown[]) => { capturedStderr.push(args.join(' ')); });
41
- console.log = vi.fn((...args: unknown[]) => { capturedStdout.push(args.join(' ')); });
42
- });
43
-
44
- afterAll(() => {
45
- process.exit = originalExit;
46
- console.error = originalError;
47
- console.log = originalLog;
48
- process.env = originalEnv;
49
- });
50
-
51
- beforeEach(() => {
52
- capturedExitCode = null;
53
- capturedStderr.length = 0;
54
- capturedStdout.length = 0;
55
- mockExecFileSync.mockReset();
56
- process.env = { ...process.env, MINIMAX_CN_API_KEY: 'test-key-for-pri-334' };
57
- });
58
-
59
- // ─── Tests ──────────────────────────────────────────────────────────────────
60
- describe('PRI-334: production workspace refusal', () => {
61
- it('refuses default production workspace with exit code 1', async () => {
62
- mockExecFileSync.mockClear();
63
- await handleRuntimeUat({ workspace: PROD_WORKSPACE, count: 1 });
64
- expect(capturedExitCode).toBe(1);
65
- expect(mockExecFileSync).not.toHaveBeenCalled();
66
- });
67
-
68
- it('refuses production workspace subdirectory with exit code 1', async () => {
69
- mockExecFileSync.mockClear();
70
- await handleRuntimeUat({ workspace: path.join(PROD_WORKSPACE, 'sub', 'path'), count: 1 });
71
- expect(capturedExitCode).toBe(1);
72
- expect(mockExecFileSync).not.toHaveBeenCalled();
73
- });
74
- });
75
-
76
- describe('PRI-334: allowed paths (guard level)', () => {
77
- it('allows temp workspace', () => {
78
- const tempPath = path.join(os.tmpdir(), 'pd-test-' + Date.now());
79
- expect(guardUatWorkspace(tempPath, 'test').refused).toBe(false);
80
- });
81
-
82
- it('allows workspace-test sibling (ERR-030)', () => {
83
- expect(guardUatWorkspace(path.join(os.homedir(), '.openclaw', 'workspace-test'), 'test').refused).toBe(false);
84
- });
85
-
86
- it('allows workspace-backup sibling (ERR-030)', () => {
87
- expect(guardUatWorkspace(path.join(os.homedir(), '.openclaw', 'workspace-backup'), 'test').refused).toBe(false);
88
- });
89
- });
90
-
91
- describe('PRI-334: JSON output (EP-04)', () => {
92
- it('outputs single JSON object with reason and nextAction', async () => {
93
- mockExecFileSync.mockClear();
94
- capturedStdout.length = 0;
95
- await handleRuntimeUat({ workspace: PROD_WORKSPACE, count: 1, json: true });
96
- expect(capturedExitCode).toBe(1);
97
- expect(mockExecFileSync).not.toHaveBeenCalled();
98
-
99
- const jsonOutput = capturedStdout.join('');
100
- const parsed = JSON.parse(jsonOutput);
101
- expect(parsed).toMatchObject({
102
- status: 'refused', reason: expect.any(String), nextAction: expect.any(String),
103
- workspace: expect.any(String), isProduction: true,
104
- });
105
- expect(Array.isArray(parsed)).toBe(false);
106
- });
107
- });
108
-
109
- describe('PRI-334: escape hatch', () => {
110
- it('warns when allow-production-workspace-for-uat flag is set', async () => {
111
- mockExecFileSync.mockClear();
112
- mockExecFileSync.mockImplementation(() => '{"painId":"test","taskId":"t1","runId":"r1","candidateIds":["c1"],"ledgerEntryIds":["l1"]}');
113
- capturedStderr.length = 0;
114
- capturedExitCode = null;
115
-
116
- await handleRuntimeUat({ workspace: PROD_WORKSPACE, count: 1, allowProductionWorkspaceForUat: true });
117
- const stderrText = capturedStderr.join('\n');
118
- expect(stderrText).toContain('WARNING');
119
- expect(stderrText).toContain('--allow-production-workspace-for-uat');
120
- });
121
- });
122
-
123
- describe('PRI-334: mutation prevention', () => {
124
- it('does not call execFileSync after guard refusal', async () => {
125
- mockExecFileSync.mockClear();
126
- await handleRuntimeUat({ workspace: PROD_WORKSPACE, count: 1 });
127
- expect(mockExecFileSync).not.toHaveBeenCalled();
128
- });
129
- });
130
-
131
- describe('PRI-334: Commander flag wiring (ERR-063)', () => {
132
- it('parses --allow-production-workspace-for-uat', () => {
133
- const program = new Command();
134
- const rt = program.command('runtime');
135
- rt.command('uat')
136
- .option('--allow-production-workspace-for-uat', 'Escape hatch')
137
- .action(() => { /* noop */ });
138
- const cmd = rt.commands.find((c) => c.name() === 'uat') as Command;
139
- const opt = cmd.options.find((o) => o.long === '--allow-production-workspace-for-uat');
140
- expect(opt).toBeDefined();
141
- expect(opt?.long).toBe('--allow-production-workspace-for-uat');
142
- });
143
-
144
- it('negated form is NOT registered', () => {
145
- const program = new Command();
146
- const rt = program.command('runtime');
147
- rt.command('uat')
148
- .option('--allow-production-workspace-for-uat', 'Escape hatch')
149
- .action(() => { /* noop */ });
150
- const cmd = rt.commands.find((c) => c.name() === 'uat') as Command;
151
- const noForm = cmd.options.find((o) => o.long === '--no-allow-production-workspace-for-uat');
152
- expect(noForm).toBeUndefined();
153
- });
154
- });
155
-
156
- describe('PRI-334: shouldExitWithError exit path (EP-04)', () => {
157
- it('exits 1 and does not print ALL CHECKS PASSED when shouldExitWithError is true', async () => {
158
- const tempWorkspace = path.join(os.tmpdir(), 'pd-exit-test-' + Date.now());
159
- mockExecFileSync.mockClear();
160
- // Make all iterations fail (execFileSync throws) so shouldExitWithError returns true
161
- mockExecFileSync.mockRejectedValue(new Error('simulated failure'));
162
- capturedStderr.length = 0;
163
- capturedExitCode = null;
164
-
165
- await handleRuntimeUat({
166
- workspace: tempWorkspace,
167
- count: 1,
168
- minSuccessRate: 1.0,
169
- });
170
-
171
- expect(capturedExitCode).toBe(1);
172
- const stderrText = capturedStderr.join('\n');
173
- expect(stderrText).not.toContain('ALL CHECKS PASSED');
174
- });
175
- });