@principles/pd-cli 1.152.11 → 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 (303) hide show
  1. package/dist/commands/candidate.d.ts +3 -3
  2. package/dist/commands/candidate.d.ts.map +1 -1
  3. package/dist/commands/candidate.js +9 -21
  4. package/dist/commands/candidate.js.map +1 -1
  5. package/dist/index.js +0 -0
  6. package/dist/services/rulehost-pipeline-runner.d.ts.map +1 -1
  7. package/dist/services/rulehost-pipeline-runner.js +4 -17
  8. package/dist/services/rulehost-pipeline-runner.js.map +1 -1
  9. package/package.json +13 -7
  10. package/dist/commands/__tests__/intent-flag-wiring.test.d.ts +0 -9
  11. package/dist/commands/__tests__/intent-flag-wiring.test.d.ts.map +0 -1
  12. package/dist/commands/__tests__/intent-flag-wiring.test.js +0 -237
  13. package/dist/commands/__tests__/intent-flag-wiring.test.js.map +0 -1
  14. package/dist/commands/__tests__/legacy-cleanup.test.d.ts +0 -18
  15. package/dist/commands/__tests__/legacy-cleanup.test.d.ts.map +0 -1
  16. package/dist/commands/__tests__/legacy-cleanup.test.js +0 -467
  17. package/dist/commands/__tests__/legacy-cleanup.test.js.map +0 -1
  18. package/dist/commands/__tests__/mvp-smoke.test.d.ts +0 -15
  19. package/dist/commands/__tests__/mvp-smoke.test.d.ts.map +0 -1
  20. package/dist/commands/__tests__/mvp-smoke.test.js +0 -262
  21. package/dist/commands/__tests__/mvp-smoke.test.js.map +0 -1
  22. package/dist/commands/__tests__/pain-retry-maxTokens-flag.test.d.ts +0 -2
  23. package/dist/commands/__tests__/pain-retry-maxTokens-flag.test.d.ts.map +0 -1
  24. package/dist/commands/__tests__/pain-retry-maxTokens-flag.test.js +0 -60
  25. package/dist/commands/__tests__/pain-retry-maxTokens-flag.test.js.map +0 -1
  26. package/dist/commands/__tests__/rulecode-flag-wiring.test.d.ts +0 -21
  27. package/dist/commands/__tests__/rulecode-flag-wiring.test.d.ts.map +0 -1
  28. package/dist/commands/__tests__/rulecode-flag-wiring.test.js +0 -186
  29. package/dist/commands/__tests__/rulecode-flag-wiring.test.js.map +0 -1
  30. package/dist/commands/__tests__/rulecode-handler.test.d.ts +0 -16
  31. package/dist/commands/__tests__/rulecode-handler.test.d.ts.map +0 -1
  32. package/dist/commands/__tests__/rulecode-handler.test.js +0 -285
  33. package/dist/commands/__tests__/rulecode-handler.test.js.map +0 -1
  34. package/dist/commands/__tests__/run-rulehost-flag-wiring.test.d.ts +0 -24
  35. package/dist/commands/__tests__/run-rulehost-flag-wiring.test.d.ts.map +0 -1
  36. package/dist/commands/__tests__/run-rulehost-flag-wiring.test.js +0 -232
  37. package/dist/commands/__tests__/run-rulehost-flag-wiring.test.js.map +0 -1
  38. package/dist/commands/__tests__/runtime-activation-nextaction.test.d.ts +0 -15
  39. package/dist/commands/__tests__/runtime-activation-nextaction.test.d.ts.map +0 -1
  40. package/dist/commands/__tests__/runtime-activation-nextaction.test.js +0 -73
  41. package/dist/commands/__tests__/runtime-activation-nextaction.test.js.map +0 -1
  42. package/dist/commands/__tests__/runtime-probe-config.test.d.ts +0 -20
  43. package/dist/commands/__tests__/runtime-probe-config.test.d.ts.map +0 -1
  44. package/dist/commands/__tests__/runtime-probe-config.test.js +0 -389
  45. package/dist/commands/__tests__/runtime-probe-config.test.js.map +0 -1
  46. package/dist/commands/__tests__/telemetry-flag-wiring.test.d.ts +0 -9
  47. package/dist/commands/__tests__/telemetry-flag-wiring.test.d.ts.map +0 -1
  48. package/dist/commands/__tests__/telemetry-flag-wiring.test.js +0 -76
  49. package/dist/commands/__tests__/telemetry-flag-wiring.test.js.map +0 -1
  50. package/dist/commands/__tests__/version.test.d.ts +0 -2
  51. package/dist/commands/__tests__/version.test.d.ts.map +0 -1
  52. package/dist/commands/__tests__/version.test.js +0 -238
  53. package/dist/commands/__tests__/version.test.js.map +0 -1
  54. package/dist/commands/runtime-uat.guard.test.d.ts +0 -2
  55. package/dist/commands/runtime-uat.guard.test.d.ts.map +0 -1
  56. package/dist/commands/runtime-uat.guard.test.js +0 -153
  57. package/dist/commands/runtime-uat.guard.test.js.map +0 -1
  58. package/dist/services/__tests__/cli-output.test.d.ts +0 -18
  59. package/dist/services/__tests__/cli-output.test.d.ts.map +0 -1
  60. package/dist/services/__tests__/cli-output.test.js +0 -103
  61. package/dist/services/__tests__/cli-output.test.js.map +0 -1
  62. package/dist/services/__tests__/evaluator-runner-deps.test.d.ts +0 -2
  63. package/dist/services/__tests__/evaluator-runner-deps.test.d.ts.map +0 -1
  64. package/dist/services/__tests__/evaluator-runner-deps.test.js +0 -343
  65. package/dist/services/__tests__/evaluator-runner-deps.test.js.map +0 -1
  66. package/dist/services/__tests__/rulehost-readiness.test.d.ts +0 -2
  67. package/dist/services/__tests__/rulehost-readiness.test.d.ts.map +0 -1
  68. package/dist/services/__tests__/rulehost-readiness.test.js +0 -311
  69. package/dist/services/__tests__/rulehost-readiness.test.js.map +0 -1
  70. package/dist/services/__tests__/runtime-adapter-resolver.test.d.ts +0 -18
  71. package/dist/services/__tests__/runtime-adapter-resolver.test.d.ts.map +0 -1
  72. package/dist/services/__tests__/runtime-adapter-resolver.test.js +0 -673
  73. package/dist/services/__tests__/runtime-adapter-resolver.test.js.map +0 -1
  74. package/dist/utils/production-workspace-guard.test.d.ts +0 -2
  75. package/dist/utils/production-workspace-guard.test.d.ts.map +0 -1
  76. package/dist/utils/production-workspace-guard.test.js +0 -137
  77. package/dist/utils/production-workspace-guard.test.js.map +0 -1
  78. package/scripts/llm-dogfood.ts +0 -456
  79. package/scripts/migrate-illegal-expected-decision.ts +0 -252
  80. package/src/commands/__tests__/intent-flag-wiring.test.ts +0 -282
  81. package/src/commands/__tests__/legacy-cleanup.test.ts +0 -602
  82. package/src/commands/__tests__/mvp-smoke.test.ts +0 -300
  83. package/src/commands/__tests__/pain-retry-maxTokens-flag.test.ts +0 -73
  84. package/src/commands/__tests__/rulecode-flag-wiring.test.ts +0 -237
  85. package/src/commands/__tests__/rulecode-handler.test.ts +0 -369
  86. package/src/commands/__tests__/run-rulehost-flag-wiring.test.ts +0 -292
  87. package/src/commands/__tests__/runtime-activation-nextaction.test.ts +0 -81
  88. package/src/commands/__tests__/runtime-probe-config.test.ts +0 -432
  89. package/src/commands/__tests__/telemetry-flag-wiring.test.ts +0 -84
  90. package/src/commands/__tests__/version.test.ts +0 -251
  91. package/src/commands/admission-gate.ts +0 -30
  92. package/src/commands/artifact.ts +0 -82
  93. package/src/commands/build-trajectory-evidence.ts +0 -298
  94. package/src/commands/candidate.ts +0 -1260
  95. package/src/commands/codex-ingest-catchup.ts +0 -114
  96. package/src/commands/codex-ingest-quarantine.ts +0 -127
  97. package/src/commands/codex-reconcile.ts +0 -84
  98. package/src/commands/codex-setup.ts +0 -476
  99. package/src/commands/codex-worker.ts +0 -185
  100. package/src/commands/command-helpers.ts +0 -24
  101. package/src/commands/config-doctor.ts +0 -193
  102. package/src/commands/console.ts +0 -797
  103. package/src/commands/context.ts +0 -72
  104. package/src/commands/demo-story-a.ts +0 -241
  105. package/src/commands/diagnose.ts +0 -756
  106. package/src/commands/errors-list.ts +0 -441
  107. package/src/commands/evolution-tasks-list.ts +0 -48
  108. package/src/commands/evolution-tasks-show.ts +0 -62
  109. package/src/commands/flow.ts +0 -60
  110. package/src/commands/health-codex.ts +0 -576
  111. package/src/commands/health.ts +0 -315
  112. package/src/commands/history.ts +0 -63
  113. package/src/commands/intent.ts +0 -457
  114. package/src/commands/legacy-cleanup.ts +0 -531
  115. package/src/commands/legacy-import.ts +0 -104
  116. package/src/commands/mvp-smoke.ts +0 -160
  117. package/src/commands/pain-evidence.ts +0 -226
  118. package/src/commands/pain-list.ts +0 -239
  119. package/src/commands/pain-record.ts +0 -612
  120. package/src/commands/pain-retry.ts +0 -916
  121. package/src/commands/principles-stats.ts +0 -700
  122. package/src/commands/proven-channel-baseline.ts +0 -115
  123. package/src/commands/quality-scorecard.ts +0 -272
  124. package/src/commands/remediation-output.ts +0 -66
  125. package/src/commands/rulecode.ts +0 -465
  126. package/src/commands/run.ts +0 -89
  127. package/src/commands/runtime-activation.ts +0 -1629
  128. package/src/commands/runtime-artifact-repair.ts +0 -524
  129. package/src/commands/runtime-canary.ts +0 -395
  130. package/src/commands/runtime-compatibility-scan.ts +0 -105
  131. package/src/commands/runtime-diagnostics-export.ts +0 -229
  132. package/src/commands/runtime-features.ts +0 -153
  133. package/src/commands/runtime-gfi-snapshot.ts +0 -135
  134. package/src/commands/runtime-health-snapshot.ts +0 -108
  135. package/src/commands/runtime-init.ts +0 -429
  136. package/src/commands/runtime-internalization-enqueue-successors.ts +0 -530
  137. package/src/commands/runtime-internalization-integrity-repair.ts +0 -79
  138. package/src/commands/runtime-internalization-integrity.ts +0 -107
  139. package/src/commands/runtime-internalization-queue.ts +0 -135
  140. package/src/commands/runtime-internalization-retry.ts +0 -191
  141. package/src/commands/runtime-internalization-run-once.ts +0 -791
  142. package/src/commands/runtime-internalization-run-rulehost.ts +0 -749
  143. package/src/commands/runtime-internalization-wake-once.ts +0 -87
  144. package/src/commands/runtime-pain-flood-simulation.ts +0 -121
  145. package/src/commands/runtime-pruning.ts +0 -438
  146. package/src/commands/runtime-recovery-failed-tasks.ts +0 -258
  147. package/src/commands/runtime-recovery.ts +0 -109
  148. package/src/commands/runtime-synthetic-baseline.ts +0 -70
  149. package/src/commands/runtime-uat.guard.test.ts +0 -175
  150. package/src/commands/runtime-uat.ts +0 -380
  151. package/src/commands/runtime.ts +0 -473
  152. package/src/commands/samples-list.ts +0 -39
  153. package/src/commands/samples-review.ts +0 -36
  154. package/src/commands/task.ts +0 -271
  155. package/src/commands/telemetry.ts +0 -349
  156. package/src/commands/trace.ts +0 -174
  157. package/src/commands/trajectory-db-unavailable.ts +0 -19
  158. package/src/commands/trajectory.ts +0 -64
  159. package/src/commands/version.ts +0 -49
  160. package/src/config-reader.ts +0 -122
  161. package/src/index.ts +0 -1276
  162. package/src/legacy/legacy-import.ts +0 -179
  163. package/src/legacy/session-history-import.ts +0 -203
  164. package/src/resolve-workspace.ts +0 -106
  165. package/src/services/__tests__/cli-output.test.ts +0 -130
  166. package/src/services/__tests__/evaluator-runner-deps.test.ts +0 -382
  167. package/src/services/__tests__/rulehost-readiness.test.ts +0 -363
  168. package/src/services/__tests__/runtime-adapter-resolver.test.ts +0 -793
  169. package/src/services/cli-output.ts +0 -95
  170. package/src/services/config-doctor.ts +0 -697
  171. package/src/services/console-launcher.ts +0 -537
  172. package/src/services/demo-rule-compiler.ts +0 -40
  173. package/src/services/demo-story-a-runner.ts +0 -471
  174. package/src/services/mainline-snapshot-assembler.ts +0 -579
  175. package/src/services/pain-flood-simulation-runner.ts +0 -462
  176. package/src/services/pd-config-loader.ts +0 -433
  177. package/src/services/proven-channel-baseline-runner.ts +0 -157
  178. package/src/services/quality-scorecard/data-extractor.ts +0 -150
  179. package/src/services/quality-scorecard/local-evaluator.ts +0 -142
  180. package/src/services/quality-scorecard/strong-model-gate.ts +0 -202
  181. package/src/services/resolve-runtime-from-pd-config.ts +0 -230
  182. package/src/services/rulehost-pipeline-runner.ts +0 -1216
  183. package/src/services/rulehost-readiness.ts +0 -326
  184. package/src/services/runtime-adapter-resolver.ts +0 -364
  185. package/src/services/synthetic-baseline-runner.ts +0 -400
  186. package/src/services/version-report.ts +0 -253
  187. package/src/services/workspace-tool-semantics.ts +0 -26
  188. package/src/utils/path-security.ts +0 -96
  189. package/src/utils/production-workspace-guard.test.ts +0 -157
  190. package/src/utils/production-workspace-guard.ts +0 -210
  191. package/tests/bdd/cli-contract.steps.ts +0 -346
  192. package/tests/bdd/principles-stats.steps.ts +0 -211
  193. package/tests/bdd/support/gherkin-loader.ts +0 -147
  194. package/tests/bdd/support/repo-root.ts +0 -62
  195. package/tests/bdd/support/vitest-bdd.ts +0 -179
  196. package/tests/commands/admission-gate-coverage.test.ts +0 -79
  197. package/tests/commands/build-trajectory-evidence.test.ts +0 -508
  198. package/tests/commands/candidate-audit-repair.test.ts +0 -421
  199. package/tests/commands/candidate-intake.test.ts +0 -732
  200. package/tests/commands/candidate-internalization-backfill.test.ts +0 -548
  201. package/tests/commands/candidate-internalize-lineage.test.ts +0 -565
  202. package/tests/commands/candidate-internalize.test.ts +0 -299
  203. package/tests/commands/candidate-route.test.ts +0 -329
  204. package/tests/commands/candidate-show.test.ts +0 -95
  205. package/tests/commands/cli-command-tree.test.ts +0 -144
  206. package/tests/commands/cli-help-snapshot.test.ts +0 -155
  207. package/tests/commands/cli-skill-contract.test.ts +0 -121
  208. package/tests/commands/codex-consent-reversibility.steps.test.ts +0 -299
  209. package/tests/commands/codex-ingest-quarantine.test.ts +0 -136
  210. package/tests/commands/codex-setup.test.ts +0 -297
  211. package/tests/commands/codex-worker-daemon.test.ts +0 -95
  212. package/tests/commands/codex-worker-registration.test.ts +0 -207
  213. package/tests/commands/config-doctor.test.ts +0 -336
  214. package/tests/commands/console-launcher-edge-cases.test.ts +0 -388
  215. package/tests/commands/console-open.test.ts +0 -1381
  216. package/tests/commands/context.test.ts +0 -114
  217. package/tests/commands/demo-story-a.test.ts +0 -318
  218. package/tests/commands/diagnose.test.ts +0 -1803
  219. package/tests/commands/errors-list.test.ts +0 -679
  220. package/tests/commands/evolution-tasks-list.test.ts +0 -41
  221. package/tests/commands/evolution-tasks-show.test.ts +0 -46
  222. package/tests/commands/health-codex.test.ts +0 -349
  223. package/tests/commands/health-host-wiring.test.ts +0 -76
  224. package/tests/commands/health-reliability.test.ts +0 -99
  225. package/tests/commands/health.test.ts +0 -413
  226. package/tests/commands/intent.test.ts +0 -321
  227. package/tests/commands/legacy-cleanup.test.ts +0 -148
  228. package/tests/commands/pain-evidence.test.ts +0 -518
  229. package/tests/commands/pain-list.test.ts +0 -219
  230. package/tests/commands/pain-record-async.test.ts +0 -335
  231. package/tests/commands/pain-record-session-parser.test.ts +0 -228
  232. package/tests/commands/pain-record.test.ts +0 -851
  233. package/tests/commands/pain-retry.test.ts +0 -1121
  234. package/tests/commands/plugin-config-resolution-cutover.test.ts +0 -229
  235. package/tests/commands/pri-393-runtime-config-unification.test.ts +0 -443
  236. package/tests/commands/principles-stats-wiring.test.ts +0 -135
  237. package/tests/commands/principles-stats.test.ts +0 -274
  238. package/tests/commands/product-path-regression.test.ts +0 -86
  239. package/tests/commands/proven-channel-baseline.test.ts +0 -441
  240. package/tests/commands/rulecode.test.ts +0 -177
  241. package/tests/commands/run-rulehost-handler.test.ts +0 -908
  242. package/tests/commands/runtime-activation-approve-flag-wiring.test.ts +0 -227
  243. package/tests/commands/runtime-activation-deactivate-flag-wiring.test.ts +0 -167
  244. package/tests/commands/runtime-activation-dispatch-flag-wiring.test.ts +0 -262
  245. package/tests/commands/runtime-activation-governance-audit.test.ts +0 -95
  246. package/tests/commands/runtime-activation-list-flag-wiring.test.ts +0 -193
  247. package/tests/commands/runtime-activation-promote-flag-wiring.test.ts +0 -248
  248. package/tests/commands/runtime-activation-shadow-telemetry.test.ts +0 -130
  249. package/tests/commands/runtime-activation.test.ts +0 -2052
  250. package/tests/commands/runtime-artifact-repair-registration.test.ts +0 -74
  251. package/tests/commands/runtime-artifact-repair.test.ts +0 -404
  252. package/tests/commands/runtime-canary.test.ts +0 -430
  253. package/tests/commands/runtime-compatibility-scan.test.ts +0 -146
  254. package/tests/commands/runtime-diagnostics-export.test.ts +0 -175
  255. package/tests/commands/runtime-features.test.ts +0 -249
  256. package/tests/commands/runtime-health-snapshot.test.ts +0 -358
  257. package/tests/commands/runtime-init-empty-workspace.test.ts +0 -252
  258. package/tests/commands/runtime-init.test.ts +0 -420
  259. package/tests/commands/runtime-internalization-enqueue-successors.test.ts +0 -782
  260. package/tests/commands/runtime-internalization-integrity-repair.test.ts +0 -239
  261. package/tests/commands/runtime-internalization-integrity.test.ts +0 -140
  262. package/tests/commands/runtime-internalization-queue.test.ts +0 -380
  263. package/tests/commands/runtime-internalization-retry-owner-authority.test.ts +0 -431
  264. package/tests/commands/runtime-internalization-run-once-evaluator-parity.test.ts +0 -269
  265. package/tests/commands/runtime-internalization-run-once-language.test.ts +0 -303
  266. package/tests/commands/runtime-internalization-run-once-real-config.test.ts +0 -237
  267. package/tests/commands/runtime-internalization-run-once-rollout-parity.test.ts +0 -706
  268. package/tests/commands/runtime-internalization-run-once.test.ts +0 -1791
  269. package/tests/commands/runtime-internalization-wake-once.test.ts +0 -171
  270. package/tests/commands/runtime-internalization.test.ts +0 -53
  271. package/tests/commands/runtime-pain-flood-simulation.test.ts +0 -418
  272. package/tests/commands/runtime-pruning.test.ts +0 -694
  273. package/tests/commands/runtime-recovery-failed-tasks.test.ts +0 -328
  274. package/tests/commands/runtime-recovery.test.ts +0 -120
  275. package/tests/commands/runtime-synthetic-baseline.test.ts +0 -249
  276. package/tests/commands/runtime-uat.test.ts +0 -397
  277. package/tests/commands/runtime.test.ts +0 -392
  278. package/tests/commands/samples-list.test.ts +0 -43
  279. package/tests/commands/samples-review.test.ts +0 -41
  280. package/tests/commands/task.test.ts +0 -153
  281. package/tests/commands/telemetry.test.ts +0 -190
  282. package/tests/commands/trace.test.ts +0 -316
  283. package/tests/config-reader.test.ts +0 -143
  284. package/tests/e2e/candidate-intake-e2e.test.ts +0 -338
  285. package/tests/e2e/cli-full-flow.test.ts +0 -233
  286. package/tests/e2e/cross-package-acceptance.test.ts +0 -635
  287. package/tests/helpers/pd-cli-path.ts +0 -5
  288. package/tests/pd-cli-smoke.test.ts +0 -13
  289. package/tests/resolve-workspace.test.ts +0 -196
  290. package/tests/services/config-doctor-signal-health.test.ts +0 -109
  291. package/tests/services/console-launcher.test.ts +0 -114
  292. package/tests/services/demo-rule-compiler.test.ts +0 -242
  293. package/tests/services/mainline-snapshot-assembler.test.ts +0 -572
  294. package/tests/services/pd-config-loader.test.ts +0 -505
  295. package/tests/services/proven-channel-baseline-runner.test.ts +0 -30
  296. package/tests/services/quality-scorecard/strong-model-gate.test.ts +0 -133
  297. package/tests/services/resolve-runtime-from-pd-config.test.ts +0 -485
  298. package/tests/services/rulehost-pipeline-e2e.test.ts +0 -538
  299. package/tests/services/rulehost-pipeline-runner.test.ts +0 -1175
  300. package/tests/services/workspace-tool-semantics.test.ts +0 -76
  301. package/tests/utils/path-security.test.ts +0 -180
  302. package/tsconfig.json +0 -26
  303. package/vitest.config.ts +0 -9
@@ -1,471 +0,0 @@
1
- import {
2
- RuntimeStateManager,
3
- ActivationDispatcher,
4
- PromptWriter,
5
- DeferArchiveWriter,
6
- RuleHostWriter,
7
- SqliteActivationStateStore,
8
- SqliteApprovalQueueStore,
9
- ApprovalCompletionService,
10
- STORY_A_CHANNELS,
11
- makeRunId,
12
- makePrincipleArtifactRecord,
13
- makeRuleArtifactRecord,
14
- computeDemoStatus,
15
- buildFollowUpObservation,
16
- buildDemoNarrative,
17
- validateDemoChannels,
18
- evaluateDemoGoldenTrace,
19
- } from '@principles/core/runtime-v2';
20
- import type {
21
- MvpChannel,
22
- StoryADemoResult,
23
- StoryADemoStage,
24
- StoryADemoChannelOutcome,
25
- ActivationDecision,
26
- PIArtifactSnapshot,
27
- DispatchInput,
28
- ApprovalDecisionResult,
29
- } from '@principles/core/runtime-v2';
30
- import type { PIArtifactRecord } from '@principles/core/runtime-v2';
31
-
32
- function toSnapshot(record: PIArtifactRecord): PIArtifactSnapshot {
33
- return {
34
- artifactId: record.artifactId,
35
- artifactKind: record.artifactKind,
36
- sourceTaskId: record.sourceTaskId,
37
- sourcePrincipleId: record.sourcePrincipleId,
38
- sourceRuleId: record.sourceRuleId,
39
- lineageArtifactIds: record.lineageArtifactIds,
40
- validationStatus: record.validationStatus,
41
- contentJson: record.contentJson,
42
- createdAt: record.createdAt,
43
- updatedAt: record.updatedAt,
44
- };
45
- }
46
-
47
- export interface DemoStoryARunnerOptions {
48
- channels?: MvpChannel[];
49
- runId?: string;
50
- workspaceDir: string;
51
- }
52
-
53
- interface DispatchContext {
54
- stateManager: RuntimeStateManager;
55
- snapshotCache: Map<string, PIArtifactSnapshot>;
56
- runId: string;
57
- }
58
-
59
- function makeArtifactReadModel(ctx: DispatchContext) {
60
- return {
61
- getArtifactById: async (id: string): Promise<PIArtifactSnapshot | null> => {
62
- const cached = ctx.snapshotCache.get(id);
63
- if (cached) return cached;
64
- const record = await ctx.stateManager.piArtifactStore.getArtifactById(id);
65
- if (!record) return null;
66
- const snapshot = toSnapshot(record);
67
- ctx.snapshotCache.set(id, snapshot);
68
- return snapshot;
69
- },
70
- };
71
- }
72
-
73
- async function dispatchChannel(
74
- channel: MvpChannel,
75
- artifactRecord: PIArtifactRecord,
76
- ctx: DispatchContext,
77
- ): Promise<{ dispatchDecision: ActivationDecision; approvalId?: string }> {
78
- const snapshot = toSnapshot(artifactRecord);
79
- ctx.snapshotCache.set(artifactRecord.artifactId, snapshot);
80
-
81
- const artifactReadModel = makeArtifactReadModel(ctx);
82
- const activationStateStore = new SqliteActivationStateStore(ctx.stateManager.connection);
83
- const approvalStore = new SqliteApprovalQueueStore(ctx.stateManager.connection);
84
-
85
- const writers = channel === 'code_tool_hook'
86
- ? [new RuleHostWriter({ gateDeps: { evaluateInSandbox: () => ({ success: true, failedCases: [], executionTimeMs: 1, forbiddenPatternViolations: [] }) } })]
87
- : channel === 'prompt'
88
- ? [new PromptWriter()]
89
- : [new DeferArchiveWriter()];
90
-
91
- const dispatcher = new ActivationDispatcher(
92
- artifactReadModel,
93
- activationStateStore,
94
- { writers, approvalQueueStore: approvalStore },
95
- );
96
-
97
- const dispatchInput: DispatchInput = {
98
- artifactId: artifactRecord.artifactId,
99
- channel,
100
- rolloutDecision: channel === 'code_tool_hook' ? 'require_approval' : 'auto_activate',
101
- actor: { kind: 'human', userId: 'demo-owner' },
102
- idempotencyKey: `story-a-${ctx.runId}::${channel}`,
103
- now: new Date().toISOString(),
104
- confirm: true,
105
- };
106
-
107
- const decision = await dispatcher.dispatch(dispatchInput);
108
-
109
- const {approvalId} = (decision as { approvalId?: string });
110
- return { dispatchDecision: decision, approvalId };
111
- }
112
-
113
- interface ChannelDispatchInput {
114
- channel: MvpChannel;
115
- artifactRecord: PIArtifactRecord;
116
- ctx: DispatchContext;
117
- }
118
-
119
- // Post-approval activation via the production ApprovalCompletionService.
120
- // PRI-811 Phase B: EVERY channel queues first (a rollout recommendation never
121
- // self-executes), so the demo completes queued items for all channels through
122
- // the same verified approve→dispatch('approved') path production uses.
123
- async function completePostApprovalActivation(
124
- approvalId: string,
125
- input: ChannelDispatchInput,
126
- ): Promise<ActivationDecision> {
127
- const { channel, artifactRecord, ctx } = input;
128
- const approvalStore = new SqliteApprovalQueueStore(ctx.stateManager.connection);
129
- const activationStateStore = new SqliteActivationStateStore(ctx.stateManager.connection);
130
- const approveResult: ApprovalDecisionResult = await approvalStore.approve(approvalId, 'demo-owner', 'Demo: owner approves activation');
131
- if (!approveResult.ok) {
132
- return { decision: 'refused', reason: `approval_failed: ${approveResult.error}`, channel };
133
- }
134
-
135
- const snapshot = toSnapshot(artifactRecord);
136
- ctx.snapshotCache.set(artifactRecord.artifactId, snapshot);
137
-
138
- const writers = channel === 'code_tool_hook'
139
- ? [new RuleHostWriter({ gateDeps: { evaluateInSandbox: () => ({ success: true, failedCases: [], executionTimeMs: 1, forbiddenPatternViolations: [] }) } })]
140
- : channel === 'prompt'
141
- ? [new PromptWriter()]
142
- : [new DeferArchiveWriter()];
143
- const dispatcher = new ActivationDispatcher(
144
- makeArtifactReadModel(ctx),
145
- activationStateStore,
146
- { writers, approvalQueueStore: approvalStore },
147
- );
148
- const completionService = new ApprovalCompletionService(approvalStore, dispatcher, activationStateStore);
149
- const completion = await completionService.completeApproval({
150
- approvalId,
151
- actor: { kind: 'human', userId: 'demo-owner' },
152
- now: new Date().toISOString(),
153
- });
154
- if (!completion.ok) {
155
- return { decision: 'refused', reason: completion.reason, channel };
156
- }
157
- return completion.decision;
158
- }
159
-
160
- function classifyDecision(decision: ActivationDecision): 'activated' | 'queued' | 'refused' | 'already' | 'other' {
161
- if (decision.decision === 'activated' || decision.decision === 'would_activate') return 'activated';
162
- if (decision.decision === 'queued_for_approval') return 'queued';
163
- if (decision.decision === 'refused' || decision.decision === 'invalid_artifact') return 'refused';
164
- if (decision.decision === 'already_activated') return 'already';
165
- return 'other';
166
- }
167
-
168
- interface ChannelOutcomeInput {
169
- channel: MvpChannel;
170
- principleRecord: PIArtifactRecord;
171
- ruleRecord: PIArtifactRecord;
172
- ctx: DispatchContext;
173
- }
174
-
175
- async function runChannelOutcome(
176
- input: ChannelOutcomeInput,
177
- ): Promise<StoryADemoChannelOutcome> {
178
- const { channel, principleRecord, ruleRecord, ctx } = input;
179
- const artifactRecord = channel === 'code_tool_hook' ? ruleRecord : principleRecord;
180
- const principleId = principleRecord.sourcePrincipleId ?? 'unknown';
181
- const riskLevel = channel === 'code_tool_hook' ? 'high' as const : 'low' as const;
182
-
183
- try {
184
- const { dispatchDecision: firstDecision, approvalId } = await dispatchChannel(
185
- channel, artifactRecord, ctx,
186
- );
187
-
188
- // PRI-811 Phase B: first dispatch queues for EVERY channel (a rollout
189
- // recommendation never self-executes). Demo approves and completes the
190
- // activation through the production ApprovalCompletionService.
191
- if (classifyDecision(firstDecision) === 'queued' && approvalId) {
192
- const postApprovalDecision = await completePostApprovalActivation(
193
- approvalId, { channel, artifactRecord, ctx },
194
- );
195
-
196
- if (classifyDecision(postApprovalDecision) === 'activated') {
197
- return {
198
- channel,
199
- status: 'passed',
200
- activationDecision: postApprovalDecision,
201
- canActivateResult: { ok: true, riskLevel },
202
- evidence: {
203
- approvalId,
204
- approvedBy: 'demo-owner',
205
- activationId: (postApprovalDecision as { activationId?: string }).activationId,
206
- path: 'dispatch→queued → real_approve → ApprovalCompletionService(approved dispatch)',
207
- },
208
- evidenceSource: `ActivationDispatcher.dispatch→queued + SqliteApprovalQueueStore.approve + ApprovalCompletionService(${channel})`,
209
- principleId,
210
- };
211
- }
212
-
213
- // Approval succeeded but activation failed
214
- return {
215
- channel,
216
- status: 'degraded',
217
- activationDecision: postApprovalDecision,
218
- canActivateResult: { ok: true, riskLevel },
219
- evidence: {
220
- approvalId,
221
- approvedBy: 'demo-owner',
222
- activationDecision: postApprovalDecision.decision,
223
- },
224
- evidenceSource: 'ActivationDispatcher.dispatch→queued + ApprovalCompletionService (activation incomplete)',
225
- principleId,
226
- failureReason: `Channel ${channel} approved but post-activation dispatch returned: ${postApprovalDecision.decision}`,
227
- nextAction: `Check ${channel} writer canActivate and artifact contract`,
228
- };
229
- }
230
-
231
- const kind = classifyDecision(firstDecision);
232
-
233
- if (kind === 'activated') {
234
- return {
235
- channel,
236
- status: 'passed',
237
- activationDecision: firstDecision,
238
- canActivateResult: { ok: true, riskLevel },
239
- evidence: {
240
- activationId: (firstDecision as { activationId?: string }).activationId,
241
- },
242
- evidenceSource: `ActivationDispatcher.dispatch → ${channel === 'prompt' ? 'PromptWriter' : 'DeferArchiveWriter'}`,
243
- principleId,
244
- };
245
- }
246
-
247
- if (kind === 'already') {
248
- return {
249
- channel,
250
- status: 'passed',
251
- activationDecision: firstDecision,
252
- canActivateResult: { ok: true, riskLevel },
253
- evidence: { activationId: (firstDecision as { activationId: string }).activationId },
254
- evidenceSource: `ActivationDispatcher.dispatch → ${channel} (idempotent)`,
255
- principleId,
256
- };
257
- }
258
-
259
- // refused or other
260
- const refusedReason = firstDecision.decision === 'refused'
261
- ? (firstDecision as { reason: string }).reason
262
- : firstDecision.decision;
263
- return {
264
- channel,
265
- status: 'failed',
266
- activationDecision: firstDecision,
267
- canActivateResult: { ok: false, reason: refusedReason, riskLevel },
268
- evidence: { decision: firstDecision },
269
- evidenceSource: 'ActivationDispatcher.dispatch',
270
- principleId,
271
- failureReason: `Channel ${channel} dispatch refused: ${refusedReason}`,
272
- nextAction: `Check ${channel} writer canActivate and artifact contract`,
273
- };
274
- } catch (err) {
275
- const msg = err instanceof Error ? err.message : String(err);
276
- return {
277
- channel,
278
- status: 'failed',
279
- activationDecision: { decision: 'refused', reason: 'demo_exception', channel },
280
- canActivateResult: { ok: false, reason: 'exception', riskLevel },
281
- evidence: { error: msg },
282
- evidenceSource: 'exception',
283
- principleId,
284
- failureReason: `Channel ${channel} threw: ${msg}`,
285
- nextAction: `Inspect ${channel} demo exception`,
286
- };
287
- }
288
- }
289
-
290
- export async function runStoryADemo(opts: DemoStoryARunnerOptions): Promise<StoryADemoResult> {
291
- const runId = makeRunId(opts);
292
- const generatedAt = new Date().toISOString();
293
- const channels = opts.channels ?? [...STORY_A_CHANNELS];
294
-
295
- // Input validation
296
- const validationFailure = validateDemoChannels(channels);
297
- if (validationFailure) {
298
- const isUnknown = validationFailure.reason === 'unknown_channels';
299
- return {
300
- status: 'failed',
301
- generatedAt,
302
- narrative: `Story A' demo failed: ${validationFailure.reason}.`,
303
- storyDescription: isUnknown ? `Unknown channels: ${(validationFailure as { unknownChannels: string[] }).unknownChannels.join(', ')}` : 'Demo requires at least one MVP channel.',
304
- stages: [],
305
- channelOutcomes: [],
306
- isRuntimeV2Exclusive: true,
307
- workspaceDir: opts.workspaceDir,
308
- inputValidationFailure: validationFailure,
309
- };
310
- }
311
-
312
- const stateManager = new RuntimeStateManager({ workspaceDir: opts.workspaceDir });
313
- await stateManager.initialize();
314
-
315
- try {
316
- // Persist artifacts to real workspace DB
317
- const principleRecord = makePrincipleArtifactRecord(runId);
318
- const ruleRecord = makeRuleArtifactRecord(runId, principleRecord);
319
- // P1-3: Seed parent task record for FK validation. Both demo artifacts share
320
- // sourceTaskId = `task-demo-${runId}`; createArtifact rejects it unless the
321
- // task exists in the tasks table (ERR-009/ERR-010/ERR-002).
322
- const demoTaskId = principleRecord.sourceTaskId;
323
- stateManager.connection.getDb().prepare(
324
- "INSERT OR IGNORE INTO tasks (task_id, task_kind, status, created_at, updated_at)" +
325
- " VALUES (?, 'diagnosis', 'pending', ?, ?)",
326
- ).run(demoTaskId, principleRecord.createdAt, principleRecord.createdAt);
327
- await stateManager.piArtifactStore.createArtifact(principleRecord);
328
- await stateManager.piArtifactStore.createArtifact(ruleRecord);
329
-
330
- const principleId = principleRecord.sourcePrincipleId ?? `demo-principle-${runId}`;
331
- const snapshotCache = new Map<string, PIArtifactSnapshot>();
332
- const ctx: DispatchContext = { stateManager, snapshotCache, runId };
333
- const stages: StoryADemoStage[] = [];
334
-
335
- // Stage 1: Evidence seed — verify artifacts exist in DB
336
- const storedPrinciple = await stateManager.piArtifactStore.getArtifactById(principleRecord.artifactId);
337
- stages.push({
338
- name: 'evidence_seed',
339
- status: storedPrinciple ? 'passed' : 'failed',
340
- evidenceRef: `pain://demo-${runId}`,
341
- evidence: {
342
- painId: `demo-${runId}`,
343
- reason: 'Agent repeatedly wrote to /etc/passwd despite owner corrections',
344
- occurrenceCount: 3,
345
- evidenceType: 'repeated_owner_correction',
346
- artifactPersisted: !!storedPrinciple,
347
- artifactId: principleRecord.artifactId,
348
- simulated: true,
349
- simulatedNote: 'Pain evidence is a narrative fixture; artifact persistence is real DB I/O',
350
- },
351
- ...(storedPrinciple ? {} : {
352
- reason: 'Failed to persist principle artifact to workspace DB',
353
- nextAction: 'Check workspace directory permissions and state.db',
354
- }),
355
- });
356
-
357
- // Stage 2: Principle proposal — verify both artifacts queryable
358
- const storedRule = await stateManager.piArtifactStore.getArtifactById(ruleRecord.artifactId);
359
- stages.push({
360
- name: 'principle_proposal',
361
- status: storedRule ? 'passed' : 'failed',
362
- evidenceRef: principleRecord.artifactId,
363
- evidence: {
364
- artifactId: principleRecord.artifactId,
365
- principleId,
366
- principleText: 'Prevent writing to system-critical directories',
367
- confidence: 0.95,
368
- ruleArtifactId: ruleRecord.artifactId,
369
- rulePersisted: !!storedRule,
370
- },
371
- ...(storedRule ? {} : {
372
- reason: 'Failed to persist rule artifact to workspace DB',
373
- nextAction: 'Check workspace directory permissions and state.db',
374
- }),
375
- });
376
-
377
- // Stage 3: Owner review (demo owner approves)
378
- stages.push({
379
- name: 'owner_review',
380
- status: 'passed',
381
- evidenceRef: `review-${runId}`,
382
- evidence: {
383
- ownerDecided: true,
384
- decidedBy: 'demo-owner',
385
- decision: 'approve',
386
- availableChannels: ['prompt', 'code_tool_hook', 'defer_archive'],
387
- note: 'Demo: owner approves the principle for all three MVP channels',
388
- simulated: true,
389
- simulatedNote: 'Owner decision is a scripted approval; no real human review',
390
- },
391
- });
392
-
393
- // Stage 4: Activation (per channel, with real dispatcher + real DB)
394
- const channelOutcomes: StoryADemoChannelOutcome[] = [];
395
- for (const channel of channels) {
396
- channelOutcomes.push(await runChannelOutcome({ channel, principleRecord, ruleRecord, ctx }));
397
- }
398
-
399
- const activationPassed = channelOutcomes.every(o => o.status === 'passed');
400
- stages.push({
401
- name: 'activation',
402
- status: activationPassed ? 'passed' : channelOutcomes.some(o => o.status === 'failed') ? 'failed' : 'degraded',
403
- evidenceRef: `activation-${runId}`,
404
- evidence: {
405
- channelsActivated: channelOutcomes.map(o => ({
406
- channel: o.channel,
407
- decision: o.activationDecision.decision,
408
- evidenceSource: o.evidenceSource,
409
- })),
410
- simulated: false,
411
- },
412
- ...(activationPassed ? {} : {
413
- reason: `Some channels did not pass: ${channelOutcomes.filter(o => o.status !== 'passed').map(o => o.channel).join(', ')}`,
414
- nextAction: 'Check individual channel outcomes for failure details',
415
- }),
416
- });
417
-
418
- // Stage 5: Follow-up observation
419
- const followUpEvidences = channelOutcomes.map(o => {
420
- const sandboxResult = o.channel === 'code_tool_hook'
421
- ? evaluateDemoGoldenTrace(ruleRecord)
422
- : undefined;
423
- return {
424
- channel: o.channel,
425
- ...buildFollowUpObservation(o.channel, o, sandboxResult).evidence,
426
- };
427
- });
428
- const followUpPassed = channelOutcomes.every(o => o.status === 'passed');
429
- stages.push({
430
- name: 'follow_up_observation',
431
- status: followUpPassed ? 'passed' : 'degraded',
432
- evidenceRef: `followup-${runId}`,
433
- evidence: { observations: followUpEvidences, simulated: false },
434
- ...(followUpPassed ? {} : {
435
- reason: 'Some follow-up observations degraded',
436
- nextAction: 'Check channel outcomes',
437
- }),
438
- });
439
-
440
- // Stage 6: Rollback proof
441
- stages.push({
442
- name: 'rollback_proof',
443
- status: 'passed',
444
- evidenceRef: `rollback-${runId}`,
445
- evidence: {
446
- rollbackAvailable: true,
447
- paths: [
448
- { channel: 'prompt', method: 'Principle can be deactivated via ledger update' },
449
- { channel: 'code_tool_hook', method: 'Rule can be removed from tool hook registry' },
450
- { channel: 'defer_archive', method: 'Archived principle can be reactivated if needed' },
451
- ],
452
- },
453
- });
454
-
455
- const status = computeDemoStatus(stages, channelOutcomes);
456
- const narrative = buildDemoNarrative({ runId, principleId, channels, channelOutcomes });
457
-
458
- return {
459
- status,
460
- generatedAt,
461
- narrative,
462
- storyDescription: 'Demo proves: (1) artifact persistence via SqlitePIArtifactStore, (2) activation dispatch via ActivationDispatcher.dispatch() with real gate logic, (3) approval queue via SqliteApprovalQueueStore.approve() + ApprovalCompletionService approved dispatch (PRI-811 Phase B: every channel queues for Owner approval), (4) sandbox enforcement via evaluateInRefinerSandbox against golden trace. Evidence seed and owner review are narrative fixtures (simulated: true).',
463
- stages,
464
- channelOutcomes,
465
- isRuntimeV2Exclusive: true,
466
- workspaceDir: opts.workspaceDir,
467
- };
468
- } finally {
469
- await stateManager.close();
470
- }
471
- }