@rehearsal-db/core 0.1.0-beta.14 → 0.1.0-beta.16

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 (236) hide show
  1. package/CHANGELOG.md +51 -1
  2. package/README.md +1 -0
  3. package/dist/package.json +101 -0
  4. package/dist/scripts/install/create_root_config.d.mts +3 -0
  5. package/dist/scripts/install/create_root_config.mjs +13 -0
  6. package/dist/scripts/runtime/manage_database.d.mts +6 -0
  7. package/{scripts → dist/scripts}/runtime/manage_database.mjs +6 -8
  8. package/dist/src/application/session.d.mts +96 -0
  9. package/dist/src/application/session.mjs +380 -0
  10. package/dist/src/baseline/artifact.d.mts +119 -0
  11. package/dist/src/baseline/artifact.mjs +522 -0
  12. package/dist/src/baseline/builder.d.mts +19 -0
  13. package/dist/src/baseline/builder.mjs +142 -0
  14. package/dist/src/baseline/input_discovery.d.mts +13 -0
  15. package/dist/src/baseline/input_discovery.mjs +149 -0
  16. package/dist/src/baseline/policy_review.d.mts +56 -0
  17. package/dist/src/baseline/policy_review.mjs +73 -0
  18. package/dist/src/baseline/preparation.d.mts +63 -0
  19. package/dist/src/baseline/preparation.mjs +295 -0
  20. package/dist/src/baseline/privacy_contract.d.mts +147 -0
  21. package/dist/src/baseline/privacy_contract.mjs +2 -0
  22. package/dist/src/baseline/privacy_dependency_graph.d.mts +7 -0
  23. package/dist/src/baseline/privacy_dependency_graph.mjs +110 -0
  24. package/dist/src/baseline/privacy_engine.d.mts +5 -0
  25. package/dist/src/baseline/privacy_engine.mjs +4 -0
  26. package/dist/src/baseline/privacy_key.d.mts +7 -0
  27. package/dist/src/baseline/privacy_key.mjs +42 -0
  28. package/dist/src/baseline/privacy_pipeline.d.mts +7 -0
  29. package/dist/src/baseline/privacy_pipeline.mjs +127 -0
  30. package/dist/src/baseline/privacy_policy.d.mts +6 -0
  31. package/dist/src/baseline/privacy_policy.mjs +237 -0
  32. package/dist/src/baseline/privacy_recipe_validation.d.mts +5 -0
  33. package/dist/src/baseline/privacy_recipe_validation.mjs +289 -0
  34. package/dist/src/baseline/privacy_rule_registry.d.mts +18 -0
  35. package/dist/src/baseline/privacy_rule_registry.mjs +143 -0
  36. package/dist/src/baseline/privacy_structured_json.d.mts +66 -0
  37. package/dist/src/baseline/privacy_structured_json.mjs +464 -0
  38. package/dist/src/baseline/privacy_transforms.d.mts +18 -0
  39. package/dist/src/baseline/privacy_transforms.mjs +142 -0
  40. package/dist/src/baseline/privacy_validation_shared.d.mts +31 -0
  41. package/dist/src/baseline/privacy_validation_shared.mjs +127 -0
  42. package/dist/src/baseline/sanitization_policy.d.mts +69 -0
  43. package/dist/src/baseline/sanitization_policy.mjs +227 -0
  44. package/dist/src/baseline/schema_snapshot.d.mts +19 -0
  45. package/dist/src/baseline/schema_snapshot.mjs +79 -0
  46. package/dist/src/cli/application_command_handlers.d.mts +8 -0
  47. package/dist/src/cli/application_command_handlers.mjs +52 -0
  48. package/dist/src/cli/arguments.d.mts +38 -0
  49. package/dist/src/cli/arguments.mjs +128 -0
  50. package/dist/src/cli/basic_command_handlers.d.mts +4 -0
  51. package/dist/src/cli/basic_command_handlers.mjs +56 -0
  52. package/dist/src/cli/cli_commands.d.mts +14 -0
  53. package/dist/src/cli/cli_commands.mjs +32 -0
  54. package/dist/src/cli/command_contract.d.mts +57 -0
  55. package/dist/src/cli/command_contract.mjs +39 -0
  56. package/dist/src/cli/command_output.d.mts +12 -0
  57. package/dist/src/cli/command_output.mjs +20 -0
  58. package/dist/src/cli/command_registry.d.mts +7 -0
  59. package/dist/src/cli/command_registry.mjs +14 -0
  60. package/dist/src/cli/guided.d.mts +53 -0
  61. package/dist/src/cli/guided.mjs +719 -0
  62. package/dist/src/cli/identity_command_handlers.d.mts +8 -0
  63. package/dist/src/cli/identity_command_handlers.mjs +43 -0
  64. package/dist/src/cli/init_command.d.mts +21 -0
  65. package/dist/src/cli/init_command.mjs +90 -0
  66. package/dist/src/cli/inspection_command_handlers.d.mts +3 -0
  67. package/dist/src/cli/inspection_command_handlers.mjs +79 -0
  68. package/dist/src/cli/project_command_handlers.d.mts +11 -0
  69. package/dist/src/cli/project_command_handlers.mjs +92 -0
  70. package/dist/src/cli/project_commands.d.mts +159 -0
  71. package/dist/src/cli/project_commands.mjs +183 -0
  72. package/dist/src/cli/rehearsal.d.mts +7 -0
  73. package/dist/src/cli/rehearsal.mjs +190 -0
  74. package/dist/src/cli/renderers.d.mts +299 -0
  75. package/dist/src/cli/renderers.mjs +554 -0
  76. package/dist/src/cli/runtime_action_handlers.d.mts +12 -0
  77. package/dist/src/cli/runtime_action_handlers.mjs +201 -0
  78. package/dist/src/cli/runtime_commands.d.mts +269 -0
  79. package/dist/src/cli/runtime_commands.mjs +601 -0
  80. package/dist/src/cli/source_command_handlers.d.mts +8 -0
  81. package/dist/src/cli/source_command_handlers.mjs +62 -0
  82. package/dist/src/cli/source_commands.d.mts +436 -0
  83. package/dist/src/cli/source_commands.mjs +301 -0
  84. package/dist/src/cli/terminal.d.mts +59 -0
  85. package/dist/src/cli/terminal.mjs +230 -0
  86. package/dist/src/identity/claim.d.mts +5 -0
  87. package/dist/src/identity/claim.mjs +4 -0
  88. package/dist/src/identity/claim_contract.d.mts +135 -0
  89. package/dist/src/identity/claim_contract.mjs +6 -0
  90. package/dist/src/identity/claim_executor.d.mts +10 -0
  91. package/dist/src/identity/claim_executor.mjs +358 -0
  92. package/dist/src/identity/claim_identity_lookup.d.mts +17 -0
  93. package/dist/src/identity/claim_identity_lookup.mjs +125 -0
  94. package/dist/src/identity/claim_plan.d.mts +8 -0
  95. package/dist/src/identity/claim_plan.mjs +61 -0
  96. package/dist/src/identity/claim_policy.d.mts +3 -0
  97. package/dist/src/identity/claim_policy.mjs +377 -0
  98. package/dist/src/identity/claim_sql.d.mts +10 -0
  99. package/dist/src/identity/claim_sql.mjs +46 -0
  100. package/dist/src/identity/claim_verification.d.mts +13 -0
  101. package/dist/src/identity/claim_verification.mjs +35 -0
  102. package/dist/src/identity/provider_configuration.d.mts +37 -0
  103. package/dist/src/identity/provider_configuration.mjs +132 -0
  104. package/dist/src/identity/storage.d.mts +21 -0
  105. package/dist/src/identity/storage.mjs +122 -0
  106. package/dist/src/index.d.mts +4 -0
  107. package/dist/src/index.mjs +3 -0
  108. package/dist/src/project/configuration.d.mts +13 -0
  109. package/dist/src/project/configuration.mjs +9 -0
  110. package/dist/src/project/configuration_contract.d.mts +125 -0
  111. package/dist/src/project/configuration_contract.mjs +27 -0
  112. package/dist/src/project/configuration_discovery.d.mts +7 -0
  113. package/dist/src/project/configuration_discovery.mjs +37 -0
  114. package/dist/src/project/configuration_normalization.d.mts +107 -0
  115. package/dist/src/project/configuration_normalization.mjs +302 -0
  116. package/dist/src/project/configuration_rendering.d.mts +14 -0
  117. package/dist/src/project/configuration_rendering.mjs +224 -0
  118. package/dist/src/project/configuration_resolution.d.mts +125 -0
  119. package/dist/src/project/configuration_resolution.mjs +81 -0
  120. package/dist/src/project/configuration_schema.d.mts +22 -0
  121. package/dist/src/project/configuration_schema.mjs +160 -0
  122. package/dist/src/project/configuration_validation.d.mts +22 -0
  123. package/dist/src/project/configuration_validation.mjs +136 -0
  124. package/dist/src/project/install_scaffold.d.mts +42 -0
  125. package/dist/src/project/install_scaffold.mjs +263 -0
  126. package/dist/src/project/project_detection.d.mts +14 -0
  127. package/dist/src/project/project_detection.mjs +47 -0
  128. package/dist/src/project/setup.d.mts +87 -0
  129. package/dist/src/project/setup.mjs +414 -0
  130. package/dist/src/project/support_report.d.mts +88 -0
  131. package/dist/src/project/support_report.mjs +83 -0
  132. package/dist/src/runtime/cleanup.d.mts +85 -0
  133. package/dist/src/runtime/cleanup.mjs +311 -0
  134. package/dist/src/runtime/lifecycle_engine.d.mts +63 -0
  135. package/dist/src/runtime/lifecycle_engine.mjs +114 -0
  136. package/dist/src/runtime/migration_history.d.mts +51 -0
  137. package/dist/src/runtime/migration_history.mjs +170 -0
  138. package/dist/src/runtime/plan.d.mts +134 -0
  139. package/dist/src/runtime/plan.mjs +637 -0
  140. package/dist/src/runtime/policy.d.mts +66 -0
  141. package/dist/src/runtime/policy.mjs +369 -0
  142. package/dist/src/runtime/restore.d.mts +22 -0
  143. package/dist/src/runtime/restore.mjs +276 -0
  144. package/dist/src/runtime/service_environment.d.mts +11 -0
  145. package/dist/src/runtime/service_environment.mjs +58 -0
  146. package/dist/src/runtime/topology.d.mts +51 -0
  147. package/dist/src/runtime/topology.mjs +128 -0
  148. package/dist/src/shared/diagnostics.d.mts +97 -0
  149. package/dist/src/shared/diagnostics.mjs +170 -0
  150. package/dist/src/shared/human_output.d.mts +2 -0
  151. package/{src → dist/src}/shared/human_output.mjs +1 -3
  152. package/dist/src/shared/node_runtime.d.mts +14 -0
  153. package/dist/src/shared/node_runtime.mjs +25 -0
  154. package/dist/src/shared/operation_guard.d.mts +22 -0
  155. package/dist/src/shared/operation_guard.mjs +150 -0
  156. package/dist/src/shared/process_environment.d.mts +15 -0
  157. package/dist/src/shared/process_environment.mjs +50 -0
  158. package/dist/src/source/access.d.mts +165 -0
  159. package/dist/src/source/access.mjs +602 -0
  160. package/dist/src/source/asset_transfer.d.mts +27 -0
  161. package/dist/src/source/asset_transfer.mjs +202 -0
  162. package/dist/src/source/baseline.d.mts +66 -0
  163. package/dist/src/source/baseline.mjs +372 -0
  164. package/dist/src/source/external_reader.d.mts +42 -0
  165. package/dist/src/source/external_reader.mjs +278 -0
  166. package/dist/src/source/postgresql_access.d.mts +86 -0
  167. package/dist/src/source/postgresql_access.mjs +454 -0
  168. package/dist/src/source/privacy_paths.d.mts +10 -0
  169. package/dist/src/source/privacy_paths.mjs +27 -0
  170. package/dist/src/targets/driver.d.mts +2 -0
  171. package/dist/src/targets/driver.mjs +13 -0
  172. package/dist/src/targets/postgresql.d.mts +5 -0
  173. package/dist/src/targets/postgresql.mjs +620 -0
  174. package/dist/src/targets/supabase.d.mts +8 -0
  175. package/dist/src/targets/supabase.mjs +627 -0
  176. package/dist/src/targets/supabase_environment.d.mts +49 -0
  177. package/dist/src/targets/supabase_environment.mjs +162 -0
  178. package/dist/src/targets/target.d.mts +33 -0
  179. package/dist/src/targets/target.mjs +39 -0
  180. package/docs/README.md +1 -0
  181. package/docs/architecture.md +133 -10
  182. package/docs/configuration.md +9 -3
  183. package/docs/index.md +1 -0
  184. package/docs/releasing.md +8 -3
  185. package/docs/typescript.md +134 -0
  186. package/package.json +36 -29
  187. package/types/configuration.d.mts +5 -0
  188. package/scripts/install/create_root_config.mjs +0 -19
  189. package/src/README.md +0 -17
  190. package/src/application/session.mjs +0 -435
  191. package/src/baseline/artifact.mjs +0 -684
  192. package/src/baseline/builder.mjs +0 -164
  193. package/src/baseline/input_discovery.mjs +0 -155
  194. package/src/baseline/policy_review.mjs +0 -92
  195. package/src/baseline/preparation.mjs +0 -323
  196. package/src/baseline/privacy_engine.mjs +0 -1399
  197. package/src/baseline/privacy_structured_json.mjs +0 -554
  198. package/src/baseline/sanitization_policy.mjs +0 -299
  199. package/src/baseline/schema_snapshot.mjs +0 -113
  200. package/src/cli/arguments.mjs +0 -126
  201. package/src/cli/guided.mjs +0 -814
  202. package/src/cli/init_command.mjs +0 -94
  203. package/src/cli/rehearsal.mjs +0 -972
  204. package/src/cli/renderers.mjs +0 -638
  205. package/src/cli/runtime_commands.mjs +0 -707
  206. package/src/cli/source_commands.mjs +0 -355
  207. package/src/cli/terminal.mjs +0 -275
  208. package/src/identity/claim.mjs +0 -1165
  209. package/src/identity/provider_configuration.mjs +0 -177
  210. package/src/identity/storage.mjs +0 -165
  211. package/src/project/configuration.d.mts +0 -164
  212. package/src/project/configuration.mjs +0 -1337
  213. package/src/project/install_scaffold.mjs +0 -325
  214. package/src/project/setup.mjs +0 -474
  215. package/src/project/support_report.mjs +0 -105
  216. package/src/runtime/cleanup.mjs +0 -381
  217. package/src/runtime/migration_history.mjs +0 -220
  218. package/src/runtime/plan.mjs +0 -722
  219. package/src/runtime/policy.mjs +0 -438
  220. package/src/runtime/restore.mjs +0 -337
  221. package/src/runtime/service_environment.mjs +0 -82
  222. package/src/runtime/topology.mjs +0 -177
  223. package/src/shared/diagnostics.mjs +0 -207
  224. package/src/shared/node_runtime.mjs +0 -31
  225. package/src/shared/operation_guard.mjs +0 -162
  226. package/src/shared/process_environment.mjs +0 -68
  227. package/src/source/access.mjs +0 -798
  228. package/src/source/asset_transfer.mjs +0 -259
  229. package/src/source/baseline.mjs +0 -482
  230. package/src/source/external_reader.mjs +0 -368
  231. package/src/source/postgresql_access.mjs +0 -638
  232. package/src/source/privacy_paths.mjs +0 -38
  233. package/src/targets/postgresql.mjs +0 -808
  234. package/src/targets/supabase.mjs +0 -840
  235. package/src/targets/supabase_environment.mjs +0 -229
  236. package/src/targets/target.mjs +0 -66
@@ -1,972 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * Purpose: Run the versioned, project-configured Rehearsal developer CLI for
4
- * initialization, readiness, planning, inspection, and verified local execution.
5
- * Run: `npm run rehearsal -- doctor` or `npm run rehearsal -- explain`.
6
- */
7
-
8
- import { createHash } from "node:crypto";
9
- import { readFile } from "node:fs/promises";
10
- import { join, relative } from "node:path";
11
- import { performance } from "node:perf_hooks";
12
- import { parseEnv } from "node:util";
13
- import { fileURLToPath } from "node:url";
14
- import * as prompts from "@clack/prompts";
15
- import {
16
- createRehearsalResult,
17
- normalizeRehearsalError,
18
- REHEARSAL_VERSION,
19
- renderHumanError,
20
- serializeRehearsalError,
21
- } from "../shared/diagnostics.mjs";
22
- import { loadRehearsalConfig } from "../project/configuration.mjs";
23
- import {
24
- inspectRehearsalBaseline,
25
- inspectRehearsalMigrations,
26
- runRehearsalDoctor,
27
- } from "../runtime/plan.mjs";
28
- import { createSyntheticBaselineFromFiles } from "../baseline/builder.mjs";
29
- import {
30
- applyBaselinePreparation,
31
- inspectBaselineInputFiles,
32
- planBaselinePreparation,
33
- summarizeBaselinePreparation,
34
- } from "../baseline/preparation.mjs";
35
- import {
36
- applyRehearsalSetup,
37
- planRehearsalSetup,
38
- summarizeRehearsalSetup,
39
- } from "../project/setup.mjs";
40
- import { formatCount } from "../shared/human_output.mjs";
41
- import { collectRehearsalSupportReport } from "../project/support_report.mjs";
42
- import {
43
- applyRehearsalCleanup,
44
- planRehearsalCleanup,
45
- } from "../runtime/cleanup.mjs";
46
- import { loadRuntimeTopology } from "../runtime/topology.mjs";
47
- import { createPrivacyKey } from "../baseline/privacy_engine.mjs";
48
- import { createSourceAccessPlan } from "../source/access.mjs";
49
- import {
50
- buildApplicationEnvironment,
51
- runHttpProofs,
52
- startApplicationSession,
53
- } from "../application/session.mjs";
54
- import {
55
- applyIdentityClaim,
56
- createIdentityClaimPlan,
57
- validateIdentityPolicy,
58
- } from "../identity/claim.mjs";
59
- import { createSupabaseStorageTransfer } from "../identity/storage.mjs";
60
- import {
61
- acquireProjectOperation,
62
- assertInstalledPackageFingerprint,
63
- createInstalledPackageFingerprint,
64
- } from "../shared/operation_guard.mjs";
65
- import {
66
- commandMutatesProject,
67
- parseArguments,
68
- resetGuidedFlags,
69
- } from "./arguments.mjs";
70
- import {
71
- formatDuration,
72
- installGuidedExitShortcut,
73
- isHumanTerminal,
74
- terminalStyle,
75
- useStyledPrompts,
76
- } from "./terminal.mjs";
77
- import { createGuidedHome } from "./guided.mjs";
78
- import {
79
- buildRefreshWorkflowPlan,
80
- createRefreshWorkflow,
81
- loadPreparationContext,
82
- runSourceAccess,
83
- runSourceBaselineRefresh,
84
- runSourceRetirement,
85
- } from "./source_commands.mjs";
86
- import {
87
- buildRuntimeStackPlan,
88
- createRuntimeCommands,
89
- runRuntimeStackDoctor,
90
- topologyCandidateSummary,
91
- topologyCommandEnvironment,
92
- topologyEnvironmentFiles,
93
- } from "./runtime_commands.mjs";
94
- import {
95
- renderBaseline,
96
- renderBaselineInputInspection,
97
- renderBaselinePreparation,
98
- renderCandidates,
99
- renderCleanup,
100
- renderDoctor,
101
- formatBytes,
102
- renderIdentityPlan,
103
- renderInit,
104
- renderMigrations,
105
- renderPlan,
106
- renderRefreshWorkflow,
107
- renderSetup,
108
- renderSourceAccessPlan,
109
- renderSourceRetirement,
110
- renderSupportReport,
111
- } from "./renderers.mjs";
112
- import { runRehearsalInit } from "./init_command.mjs";
113
-
114
- const packageRoot = fileURLToPath(new URL("../..", import.meta.url));
115
- const projectRoot = process.cwd();
116
- let activePackageFingerprint = null;
117
- const commandStartedAt = new Date();
118
- const commandStartedMs = performance.now();
119
- const managerPath = join(packageRoot, "scripts/runtime/manage_database.mjs");
120
- let lastGuidedDetails;
121
-
122
- const {
123
- openRuntimeApplication,
124
- prepareCandidateConfirmation,
125
- prepareDependentTargets,
126
- proveRuntimeStack,
127
- runManager,
128
- runRuntimeStack,
129
- } = createRuntimeCommands({
130
- packageRoot,
131
- projectRoot,
132
- managerPath,
133
- getActivePackageFingerprint: () => activePackageFingerprint,
134
- });
135
-
136
- const emit = ({ command, data, flags, render, status = "success" }) => {
137
- const result = createRehearsalResult({
138
- command,
139
- status,
140
- data,
141
- startedAt: commandStartedAt,
142
- durationMs: Math.round((performance.now() - commandStartedMs) * 100) / 100,
143
- });
144
- if (flags.json) console.log(JSON.stringify(result, null, 2));
145
- else console.log(render(data, flags.verbosity));
146
- };
147
-
148
- const runSetup = async ({ flags, planOptions }) => {
149
- const plan =
150
- flags.setupPlan ??
151
- (await planRehearsalSetup({
152
- projectRoot,
153
- configPath: planOptions.configPath,
154
- target: flags.target,
155
- }));
156
- if (flags.write) await applyRehearsalSetup(plan);
157
- const result = summarizeRehearsalSetup(plan, {
158
- mode: flags.write ? "written" : "preview",
159
- });
160
- if (!flags.write) return result;
161
- const readiness = await runRehearsalDoctor(planOptions);
162
- const needsBaselinePolicy = readiness.checks.some(
163
- (check) => check.id === "sanitization-policy" && check.status === "fail",
164
- );
165
- return {
166
- ...result,
167
- readiness,
168
- nextAction: [
169
- `Review ${result.configurationPath}.`,
170
- readiness.state === "READY"
171
- ? "Next: run rehearsal explain to review the migration plan."
172
- : needsBaselinePolicy
173
- ? flags.guided
174
- ? "Next: choose Prepare the script to create a reviewable policy draft."
175
- : "Next: run rehearsal again and choose Prepare a reviewable baseline policy draft."
176
- : "Next: complete the remaining readiness items shown above.",
177
- ].join("\n"),
178
- };
179
- };
180
-
181
- const runBaselinePreparation = async ({ flags, planOptions }) => {
182
- const plan =
183
- flags.preparationPlan ??
184
- (await planBaselinePreparation({
185
- ...planOptions,
186
- recordsPath: flags.recordsPath,
187
- ledgerPath: flags.ledgerPath,
188
- }));
189
- if (flags.write) await applyBaselinePreparation(plan);
190
- const result = summarizeBaselinePreparation(plan, {
191
- mode: flags.write ? "written" : "preview",
192
- });
193
- return flags.guided && flags.write
194
- ? {
195
- ...result,
196
- nextAction:
197
- "Next: choose Review the script to classify every column interactively.",
198
- }
199
- : result;
200
- };
201
-
202
- const planRuntimeStackCleanup = async ({ flags, planOptions }) => {
203
- const topology = await loadRuntimeTopology(planOptions);
204
- const targets = [];
205
- for (const target of topology.targets) {
206
- targets.push({
207
- name: target.name,
208
- configPath: target.configPath,
209
- plan: await planRehearsalCleanup({
210
- projectRoot: topology.projectRoot,
211
- configPath: target.configPath,
212
- includeRuntime: flags.includeRuntime,
213
- includeImages: flags.includeImages && target.primary,
214
- }),
215
- });
216
- }
217
- if (targets.length === 1) return targets[0].plan;
218
- return {
219
- digest: createHash("sha256")
220
- .update(
221
- JSON.stringify(
222
- targets.map((target) => ({
223
- name: target.name,
224
- digest: target.plan.digest,
225
- })),
226
- ),
227
- )
228
- .digest("hex"),
229
- targets,
230
- };
231
- };
232
-
233
- const runCleanup = async ({ flags, planOptions }) => {
234
- const plan =
235
- flags.cleanupPlan ??
236
- (await planRuntimeStackCleanup({ flags, planOptions }));
237
- if (!flags.write) return { mode: "preview", plan };
238
- if (plan.targets) {
239
- if (flags.cleanupConfirmation !== plan.digest) {
240
- throw new Error(
241
- "Cleanup requires the exact --confirm-cleanup digest from a fresh preview. Nothing was removed.",
242
- );
243
- }
244
- for (const target of plan.targets) {
245
- const refreshed = await planRehearsalCleanup({
246
- projectRoot,
247
- configPath: target.configPath,
248
- includeRuntime: target.plan.runtime.included,
249
- includeImages: target.plan.images.requested,
250
- });
251
- if (refreshed.digest !== target.plan.digest) {
252
- throw new Error(
253
- `Cleanup targets changed for ${target.name} after the preview. Nothing was removed; preview the cleanup again.`,
254
- );
255
- }
256
- }
257
- const appliedTargets = [];
258
- for (const target of plan.targets) {
259
- appliedTargets.push({
260
- name: target.name,
261
- applied: await applyRehearsalCleanup({
262
- plan: target.plan,
263
- confirmation: target.plan.digest,
264
- projectRoot,
265
- configPath: target.configPath,
266
- removeRuntime: async () => {
267
- runManager({
268
- action: "discard",
269
- flags,
270
- configPath: target.configPath,
271
- targetName: target.name,
272
- });
273
- },
274
- }),
275
- });
276
- }
277
- return {
278
- mode: "written",
279
- plan,
280
- applied: { targets: appliedTargets },
281
- };
282
- }
283
- const applied = await applyRehearsalCleanup({
284
- plan,
285
- confirmation: flags.cleanupConfirmation,
286
- ...planOptions,
287
- removeRuntime: async () => {
288
- runManager({ action: "discard", flags });
289
- },
290
- });
291
- return { mode: "written", plan, applied };
292
- };
293
-
294
- const loadIdentityClaimPlan = async ({ flags, planOptions }) => {
295
- const loaded = await loadRehearsalConfig(planOptions);
296
- if (!loaded.paths.identityPolicy) {
297
- throw new Error("No config.identityPolicy is configured.");
298
- }
299
- if (!flags.identityName) {
300
- throw new Error("Choose a declared identity with --identity=<name>.");
301
- }
302
- const policy = validateIdentityPolicy(
303
- JSON.parse(await readFile(loaded.paths.identityPolicy, "utf8")),
304
- );
305
- return {
306
- loaded,
307
- plan: createIdentityClaimPlan({
308
- policy,
309
- name: flags.identityName,
310
- }),
311
- };
312
- };
313
-
314
- const usage = () => `Usage: rehearsal <command> [options]
315
-
316
- Commands:
317
- version Print the installed Rehearsal version
318
- guide Open the interactive, state-aware home screen
319
- setup [--target=] [--write] Preview or create safe first-run scaffolding
320
- init [--write] Preview or explicitly write safe starter config
321
- baseline prepare --records= --ledger= [--write] Create a fail-closed policy draft
322
- baseline create --records= --ledger= [--assets=] Create a baseline from safe local inputs
323
- privacy key [--write] Preview or create the owner-only pseudonym key
324
- source plan Preview exact, temporary source access
325
- source apply --confirm-source-access= Apply the reviewed source-access plan
326
- source retire [--confirm-source-retirement=] Preview or retire exact source access
327
- baseline refresh Replace only the baseline from a reviewed source
328
- refresh [--confirm-refresh=] Replace the database copy, reset locally, and remove old copies
329
- identity plan --identity= Preview an approved local identity association
330
- identity claim --identity= --confirm-identity= Apply the exact local association
331
- doctor Check whether Rehearsal is safe and ready
332
- support Print a safe, copy-ready support report
333
- explain Show the immutable execution plan
334
- run --dry-run Alias the exact explain plan without mutations
335
- run --confirm-candidates= Execute reset, migration, and verification locally
336
- open Start the runtime and keep the application open
337
- candidates Show the exact pending migration digest
338
- inspect baseline Show verified baseline provenance
339
- inspect migrations Classify represented, applied, and candidate migrations
340
- start Start an existing verified local runtime
341
- migrate --confirm-candidates= Apply the exact candidate suffix without resetting
342
- reset Restore and verify the immutable local baseline
343
- status Report the disposable local runtime state
344
- stop Stop only this project's local runtime
345
- discard Remove only this project's disposable runtime
346
- cleanup [--include-runtime] [--include-images] [--write] [--confirm-cleanup=]
347
- Preview or apply conservative disk cleanup
348
- verify Verify the current local Rehearsal runtime
349
-
350
- Options: --help, -h --version, -V --json --verbose --debug --plain
351
- --config=<path> --target=supabase|postgresql
352
- --confirm-source-access=<digest> --confirm-source-retirement=<digest>
353
- --confirm-refresh=<digest>`;
354
-
355
- const runRefreshWorkflow = createRefreshWorkflow({
356
- runRuntimeStack,
357
- prepareDependentTargets,
358
- topologyCommandEnvironment,
359
- });
360
-
361
- const runGuidedHome = createGuidedHome({
362
- projectRoot,
363
- topologyCandidateSummary,
364
- buildRefreshWorkflowPlan,
365
- planRuntimeStackCleanup,
366
- getLastGuidedDetails: () => lastGuidedDetails,
367
- });
368
-
369
- const executeCommand = async ({ command, flags, planOptions, guided }) => {
370
- if (command === "version" || flags.version) {
371
- if (flags.json) {
372
- console.log(
373
- JSON.stringify(
374
- { name: "@rehearsal-db/core", version: REHEARSAL_VERSION },
375
- null,
376
- 2,
377
- ),
378
- );
379
- } else console.log(REHEARSAL_VERSION);
380
- return;
381
- }
382
- if (command === "help" || flags.help) {
383
- console.log(usage());
384
- return;
385
- }
386
- if (command === "setup") {
387
- const data = await runSetup({ flags, planOptions });
388
- emit({ command, data, flags, render: renderSetup });
389
- return;
390
- }
391
- if (command === "init") {
392
- const data = await runRehearsalInit({ projectRoot, flags });
393
- emit({ command, data, flags, render: renderInit });
394
- return;
395
- }
396
- if (command === "baseline prepare") {
397
- const data = await runBaselinePreparation({ flags, planOptions });
398
- emit({
399
- command,
400
- data,
401
- flags,
402
- render: (result) => renderBaselinePreparation(result, flags),
403
- });
404
- return;
405
- }
406
- if (command === "baseline create") {
407
- await inspectBaselineInputFiles({
408
- ...planOptions,
409
- recordsPath: flags.recordsPath,
410
- ledgerPath: flags.ledgerPath,
411
- assetsPath: flags.assetsPath,
412
- });
413
- const data = await createSyntheticBaselineFromFiles({
414
- ...planOptions,
415
- recordsPath: flags.recordsPath,
416
- ledgerPath: flags.ledgerPath,
417
- assetsPath: flags.assetsPath,
418
- });
419
- emit({
420
- command,
421
- data,
422
- flags,
423
- render: (baseline) =>
424
- [
425
- `Activated synthetic baseline ${baseline.generationId}: ${formatCount(baseline.rowCount, "row")} across ${formatCount(baseline.tableCount, "table")}; ${formatCount(baseline.migrationCount, "migration")} through ${baseline.migrationCutoff}.`,
426
- "",
427
- flags.guided
428
- ? "Next: choose Run a rehearsal when you are ready."
429
- : "Next: run rehearsal doctor to check readiness.",
430
- ].join("\n"),
431
- });
432
- return;
433
- }
434
- if (command === "privacy key") {
435
- const { loaded } = await loadPreparationContext(planOptions);
436
- const data = flags.write
437
- ? {
438
- mode: "written",
439
- path: relative(loaded.projectRoot, loaded.paths.privacyKey),
440
- ...(await createPrivacyKey(loaded.paths.privacyKey)),
441
- }
442
- : {
443
- mode: "preview",
444
- path: relative(loaded.projectRoot, loaded.paths.privacyKey),
445
- };
446
- emit({
447
- command,
448
- data,
449
- flags,
450
- render: (result) =>
451
- result.mode === "preview"
452
- ? `PRIVACY KEY — PREVIEW\n\nWould create ${result.path} with owner-only permissions.\nNothing was written. Rerun with --write after reviewing the path.`
453
- : `Created owner-only privacy key at ${result.path}.\nFingerprint: ${result.fingerprint}\nThe key is excluded from source control and must not be shared.`,
454
- });
455
- return;
456
- }
457
- if (command === "source plan") {
458
- const { sourcePolicy } = await loadPreparationContext(planOptions);
459
- const data = createSourceAccessPlan({ policy: sourcePolicy });
460
- emit({ command, data, flags, render: renderSourceAccessPlan });
461
- return;
462
- }
463
- if (command === "source apply") {
464
- const data = await runSourceAccess({ flags, planOptions });
465
- emit({
466
- command,
467
- data,
468
- flags,
469
- render: (result) =>
470
- result.mode === "preview"
471
- ? renderSourceAccessPlan(result.plan)
472
- : [
473
- "SOURCE ACCESS — READY",
474
- `${result.receipt.accessMode === "external" ? "External" : "Temporary"} reader expires: ${result.receipt.expiresAt}`,
475
- result.receipt.accessMode === "external"
476
- ? "Rehearsal made no source-side changes."
477
- : "Rehearsal created only the reviewed temporary source access.",
478
- `Local credential: ${result.credentialFile}`,
479
- "",
480
- "Next: run rehearsal baseline refresh, then retire source access.",
481
- ].join("\n"),
482
- });
483
- return;
484
- }
485
- if (command === "source retire") {
486
- const data = await runSourceRetirement({ flags, planOptions });
487
- emit({ command, data, flags, render: renderSourceRetirement });
488
- return;
489
- }
490
- if (command === "baseline refresh") {
491
- const data = await runSourceBaselineRefresh({ planOptions });
492
- emit({
493
- command,
494
- data,
495
- flags,
496
- render: (result) =>
497
- [
498
- `Activated refreshed baseline ${result.generationId}.`,
499
- `${formatCount(result.manifest.rowCount, "sanitized row")} across ${formatCount(Object.keys(result.manifest.tableCounts).length, "table")}.`,
500
- `Source estimate: ${formatCount(result.estimate.rows, "row")}, ${formatBytes(result.estimate.bytes)}.`,
501
- "",
502
- "Next: run rehearsal source retire, then rehearsal doctor.",
503
- ].join("\n"),
504
- });
505
- return;
506
- }
507
- if (command === "refresh") {
508
- const data = await runRefreshWorkflow({ flags, planOptions });
509
- emit({ command, data, flags, render: renderRefreshWorkflow });
510
- return;
511
- }
512
- if (command === "identity plan" || command === "identity claim") {
513
- const { loaded, plan } = await loadIdentityClaimPlan({
514
- flags,
515
- planOptions,
516
- });
517
- if (command === "identity plan" || !flags.identityConfirmation) {
518
- emit({
519
- command,
520
- data: { mode: "preview", plan },
521
- flags,
522
- render: renderIdentityPlan,
523
- });
524
- return;
525
- }
526
- const runtimeEnvironment = parseEnv(
527
- await readFile(loaded.paths.applicationEnvironment, "utf8"),
528
- );
529
- if (!runtimeEnvironment.DATABASE_URL) {
530
- throw new Error("The local runtime environment has no DATABASE_URL.");
531
- }
532
- const result = await applyIdentityClaim({
533
- plan,
534
- confirmation: flags.identityConfirmation,
535
- connectionString: runtimeEnvironment.DATABASE_URL,
536
- storageTransfer: plan.identity.assets.some((asset) => asset.rewritePath)
537
- ? createSupabaseStorageTransfer({
538
- url: runtimeEnvironment.SUPABASE_URL,
539
- serviceRoleKey: runtimeEnvironment.SUPABASE_SERVICE_ROLE_KEY,
540
- })
541
- : undefined,
542
- });
543
- emit({
544
- command,
545
- data: { mode: "written", plan, result },
546
- flags,
547
- render: renderIdentityPlan,
548
- });
549
- return;
550
- }
551
- if (command === "doctor") {
552
- const data = await runRuntimeStackDoctor(planOptions);
553
- emit({
554
- command,
555
- data,
556
- flags,
557
- render: renderDoctor,
558
- status: data.state === "READY" ? "success" : "not_ready",
559
- });
560
- if (data.state !== "READY" && !guided) process.exitCode = 1;
561
- return;
562
- }
563
- if (command === "support") {
564
- const data = await collectRehearsalSupportReport(planOptions, {
565
- runDoctor: async (options) => {
566
- const report = await runRuntimeStackDoctor(options);
567
- const targetAliases = new Map();
568
- const aliasFor = (name) => {
569
- if (!targetAliases.has(name)) {
570
- targetAliases.set(name, `runtime-${targetAliases.size + 1}`);
571
- }
572
- return targetAliases.get(name);
573
- };
574
- return {
575
- ...report,
576
- checks: report.checks.map((check) => {
577
- const separator = check.id.indexOf(":");
578
- if (separator === -1) return check;
579
- const target = check.id.slice(0, separator);
580
- const alias = aliasFor(target);
581
- return {
582
- ...check,
583
- id: `${alias}:${check.id.slice(separator + 1)}`,
584
- label: check.label.replace(`${target}:`, `${alias}:`),
585
- };
586
- }),
587
- };
588
- },
589
- });
590
- emit({ command, data, flags, render: renderSupportReport });
591
- return;
592
- }
593
- if (command === "cleanup") {
594
- const data = await runCleanup({ flags, planOptions });
595
- emit({ command, data, flags, render: renderCleanup });
596
- return;
597
- }
598
- if (command === "explain" || (command === "run" && flags.dryRun)) {
599
- const data = await buildRuntimeStackPlan(planOptions);
600
- emit({ command, data, flags, render: renderPlan });
601
- return;
602
- }
603
- if (command === "inspect baseline") {
604
- const data = await inspectRehearsalBaseline(planOptions);
605
- emit({ command, data, flags, render: renderBaseline });
606
- return;
607
- }
608
- if (command === "inspect migrations") {
609
- const data = await inspectRehearsalMigrations(planOptions);
610
- emit({ command, data, flags, render: renderMigrations });
611
- return;
612
- }
613
- if (command === "candidates") {
614
- const { topology: _topology, ...data } =
615
- await topologyCandidateSummary(planOptions);
616
- emit({ command, data, flags, render: renderCandidates });
617
- return;
618
- }
619
- if (command === "open") {
620
- if (flags.dryRun) {
621
- throw new Error("--dry-run is supported only by rehearsal run.");
622
- }
623
- const data = await openRuntimeApplication({
624
- flags,
625
- planOptions,
626
- onReady: (ready) => {
627
- const lines = [
628
- `Application: ${ready.url}`,
629
- "The verified database runtime stays running and keeps your local changes.",
630
- guided
631
- ? "Press Ctrl+C to close the app and return here, or Ctrl+Z to exit Rehearsal."
632
- : "Press Ctrl+C or Ctrl+Z to close the app. Rehearsal will leave the database runtime running.",
633
- ];
634
- if (useStyledPrompts(flags)) {
635
- prompts.note(lines.join("\n"), "SANDBOX READY");
636
- } else if (!flags.json) {
637
- console.log(["", "SANDBOX READY", ...lines, ""].join("\n"));
638
- }
639
- },
640
- });
641
- if (guided && data.application.stoppedBy === "SIGTSTP") {
642
- flags.exitGuidedSession = true;
643
- }
644
- if (guided) {
645
- lastGuidedDetails = [
646
- data.started.output,
647
- data.verified.output,
648
- ...data.preparations.map((preparation) => preparation.output),
649
- ]
650
- .filter(Boolean)
651
- .join("\n");
652
- }
653
- emit({
654
- command,
655
- data,
656
- flags,
657
- render: (result) =>
658
- [
659
- "SANDBOX APP CLOSED",
660
- `Application stopped after ${result.application.stoppedBy}.`,
661
- "The database runtime and its local database and Storage changes were preserved.",
662
- "Run rehearsal open to return, rehearsal verify to check it, or rehearsal stop to stop the databases.",
663
- ].join("\n"),
664
- });
665
- return;
666
- }
667
- if (
668
- [
669
- "run",
670
- "start",
671
- "migrate",
672
- "reset",
673
- "status",
674
- "stop",
675
- "discard",
676
- "verify",
677
- ].includes(command)
678
- ) {
679
- if (flags.dryRun && command !== "run") {
680
- throw new Error("--dry-run is supported only by rehearsal run.");
681
- }
682
- if (
683
- !(await prepareCandidateConfirmation({ command, flags, planOptions }))
684
- ) {
685
- return;
686
- }
687
- const stack = await runRuntimeStack({ command, flags, planOptions });
688
- const { runtime, topology } = stack;
689
- const stackEnvironment = topologyCommandEnvironment(topology);
690
- const preparations = ["run", "reset", "migrate"].includes(command)
691
- ? prepareDependentTargets({
692
- topology,
693
- environment: stackEnvironment,
694
- })
695
- : [];
696
- let applicationProof;
697
- let dependentProofs = [];
698
- let httpProofResults = [];
699
- let applicationReadiness;
700
- if (command === "run") {
701
- const applicationConfig = topology.primary.config.application;
702
- const mappedApplicationEnvironment = Object.keys(
703
- applicationConfig.environmentVariables,
704
- ).length
705
- ? await buildApplicationEnvironment({
706
- files: topologyEnvironmentFiles(topology),
707
- mappings: applicationConfig.environmentVariables,
708
- })
709
- : {};
710
- const proofEnvironment = {
711
- ...stackEnvironment,
712
- ...mappedApplicationEnvironment,
713
- };
714
- const proofLabel =
715
- topology.targets.length > 1
716
- ? "project-owned dependent and application proofs"
717
- : "project-owned application proof";
718
- const proofSpinner = useStyledPrompts(flags) ? prompts.spinner() : null;
719
- if (proofSpinner) {
720
- proofSpinner.start(`Running the ${proofLabel}.`);
721
- } else if (isHumanTerminal(flags)) {
722
- console.log(
723
- `${terminalStyle(flags, "36", "→")} Running the ${proofLabel}.`,
724
- );
725
- }
726
- let applicationSession;
727
- try {
728
- if (applicationConfig.readiness) {
729
- applicationSession = await startApplicationSession({
730
- command: applicationConfig.startCommand,
731
- cwd: topology.projectRoot,
732
- files: topologyEnvironmentFiles(topology),
733
- mappings: applicationConfig.environmentVariables,
734
- readiness: applicationConfig.readiness,
735
- });
736
- applicationReadiness = applicationSession.ready;
737
- }
738
- ({ applicationProof, dependentProofs } = await proveRuntimeStack({
739
- topology,
740
- planOptions,
741
- environment: proofEnvironment,
742
- }));
743
- if (applicationConfig.httpProofs.length) {
744
- httpProofResults = await runHttpProofs({
745
- checks: applicationConfig.httpProofs,
746
- });
747
- }
748
- } catch (error) {
749
- if (proofSpinner) proofSpinner.stop("A project proof failed.");
750
- throw error;
751
- } finally {
752
- await applicationSession?.stop();
753
- }
754
- if (proofSpinner) {
755
- proofSpinner.stop("Project proofs passed.");
756
- } else if (isHumanTerminal(flags)) {
757
- console.log(
758
- `${terminalStyle(flags, "32", "✓")} Project proofs passed.`,
759
- );
760
- }
761
- }
762
- const data =
763
- command === "run"
764
- ? {
765
- runtime,
766
- preparations,
767
- dependentProofs,
768
- applicationProof,
769
- applicationReadiness,
770
- httpProofResults,
771
- }
772
- : preparations.length
773
- ? { ...runtime, preparations }
774
- : runtime;
775
- if (guided) {
776
- lastGuidedDetails = [
777
- runtime.output,
778
- ...preparations.map((preparation) => preparation.output),
779
- ...dependentProofs.map((proof) => proof.output),
780
- applicationProof?.output,
781
- ]
782
- .filter(Boolean)
783
- .join("\n");
784
- }
785
- emit({
786
- command,
787
- data,
788
- flags,
789
- render: (value) => {
790
- const runtimeResult = value.runtime ?? value;
791
- const nextAction = {
792
- run: "Next: run rehearsal open for hands-on testing, then rehearsal verify.",
793
- start:
794
- "Next: run rehearsal open for hands-on testing or rehearsal status.",
795
- migrate: "Next: run rehearsal verify to prove the current runtime.",
796
- reset: "Next: run rehearsal open or rehearsal verify.",
797
- status: "Next: run rehearsal verify, reset, stop, or discard.",
798
- stop: "Next: run rehearsal start when you want to resume.",
799
- discard:
800
- "The disposable runtime was removed; the immutable baseline remains.",
801
- verify:
802
- "Next: continue testing, reset to the baseline, or stop the runtime.",
803
- }[runtimeResult.action];
804
- if (guided) {
805
- const title =
806
- runtimeResult.action === "run"
807
- ? "REHEARSAL PASSED"
808
- : "ACTION COMPLETE";
809
- return [
810
- title,
811
- `✓ ${runtimeResult.action} completed in ${formatDuration(runtimeResult.durationMs)}`,
812
- ...(value.preparations ?? []).map(
813
- (preparation) =>
814
- `✓ ${preparation.target} preparation passed: ${preparation.command}`,
815
- ),
816
- ...(value.dependentProofs ?? []).map(
817
- (proof) => `✓ ${proof.target} proof passed: ${proof.command}`,
818
- ),
819
- value.applicationProof
820
- ? `✓ Application proof passed: ${value.applicationProof.command}`
821
- : null,
822
- value.applicationReadiness
823
- ? `✓ Application became ready at ${value.applicationReadiness.url}`
824
- : null,
825
- ...(value.httpProofResults ?? []).map(
826
- (proof) => `✓ ${proof.kind} HTTP proof passed: ${proof.name}`,
827
- ),
828
- "",
829
- "Technical output is available from Show details in the guide.",
830
- ]
831
- .filter(Boolean)
832
- .join("\n");
833
- }
834
- return [
835
- runtimeResult.output ||
836
- `Rehearsal ${runtimeResult.action} completed.`,
837
- ...(value.preparations ?? []).map(
838
- (preparation) =>
839
- `${preparation.target} preparation passed: ${preparation.command}`,
840
- ),
841
- ...(value.dependentProofs ?? []).map(
842
- (proof) => `${proof.target} proof passed: ${proof.command}`,
843
- ),
844
- value.applicationProof
845
- ? `Application proof passed: ${value.applicationProof.command}`
846
- : null,
847
- value.applicationReadiness
848
- ? `Application readiness passed: ${value.applicationReadiness.url}`
849
- : null,
850
- ...(value.httpProofResults ?? []).map(
851
- (proof) => `${proof.kind} HTTP proof passed: ${proof.name}`,
852
- ),
853
- nextAction ? "" : null,
854
- nextAction,
855
- ]
856
- .filter((entry) => entry !== null)
857
- .join("\n");
858
- },
859
- });
860
- return;
861
- }
862
- throw new Error(`Unknown Rehearsal command: ${command}.\n\n${usage()}`);
863
- };
864
-
865
- const main = async () => {
866
- const { flags, positionals } = parseArguments(process.argv.slice(2));
867
- const command = positionals.join(" ") || "help";
868
- const planOptions = {
869
- projectRoot,
870
- configPath: flags.configPath,
871
- };
872
- const wantsAutomaticGuide =
873
- positionals.length === 0 &&
874
- !flags.help &&
875
- !flags.json &&
876
- process.stdin.isTTY &&
877
- process.stdout.isTTY;
878
- const guided = command === "guide" || wantsAutomaticGuide;
879
- const mutating = commandMutatesProject({ command, flags, guided });
880
- const operation = mutating
881
- ? await acquireProjectOperation({ projectRoot, command })
882
- : null;
883
- if (operation) {
884
- activePackageFingerprint = createInstalledPackageFingerprint({
885
- packageRoot,
886
- });
887
- }
888
- try {
889
- if (!guided) {
890
- await executeCommand({ command, flags, planOptions, guided: false });
891
- return;
892
- }
893
- if (!process.stdin.isTTY || !process.stdout.isTTY) {
894
- throw new Error(
895
- "The guided home screen requires an interactive terminal. Run rehearsal --help to list scriptable commands.",
896
- );
897
- }
898
- flags.guided = true;
899
- const installExitShortcut = () =>
900
- installGuidedExitShortcut(flags, {
901
- beforeExit: () => operation?.releaseSync(),
902
- });
903
- let removeGuidedExitShortcut = installExitShortcut();
904
- if (useStyledPrompts(flags)) {
905
- prompts.intro("REHEARSAL · Safe local migration testing");
906
- }
907
- try {
908
- while (true) {
909
- resetGuidedFlags(flags);
910
- const selected = await runGuidedHome({ flags, planOptions });
911
- if (!selected) break;
912
- if (selected === "home") continue;
913
- const opensApplication = selected === "open";
914
- if (opensApplication) {
915
- removeGuidedExitShortcut();
916
- removeGuidedExitShortcut = null;
917
- }
918
- try {
919
- await executeCommand({
920
- command: selected,
921
- flags,
922
- planOptions,
923
- guided: true,
924
- });
925
- } finally {
926
- if (opensApplication) {
927
- removeGuidedExitShortcut = installExitShortcut();
928
- }
929
- }
930
- if (flags.exitGuidedSession) break;
931
- }
932
- } finally {
933
- removeGuidedExitShortcut?.();
934
- }
935
- if (useStyledPrompts(flags)) {
936
- prompts.outro("See you at the next rehearsal.");
937
- } else {
938
- console.log("See you at the next rehearsal.");
939
- }
940
- } finally {
941
- if (operation) {
942
- try {
943
- assertInstalledPackageFingerprint({
944
- packageRoot,
945
- expected: activePackageFingerprint,
946
- });
947
- } finally {
948
- activePackageFingerprint = null;
949
- await operation.release();
950
- }
951
- }
952
- }
953
- };
954
-
955
- try {
956
- await main();
957
- } catch (error) {
958
- const failure = normalizeRehearsalError(error, {
959
- expected: "a safe, versioned, local-only Rehearsal operation",
960
- actual: String(error?.message ?? error),
961
- refused: "No further Rehearsal action was performed.",
962
- suggestions: ["Run rehearsal doctor for actionable readiness checks."],
963
- });
964
- const wantsJson = process.argv.includes("--json");
965
- const debug = process.argv.includes("--debug");
966
- if (wantsJson)
967
- console.log(
968
- JSON.stringify(serializeRehearsalError(failure, { debug }), null, 2),
969
- );
970
- else console.error(renderHumanError(failure, { debug }));
971
- process.exitCode = failure.exitCode;
972
- }