@rehearsal-db/core 0.1.0-beta.13 → 0.1.0-beta.15

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 (169) hide show
  1. package/CHANGELOG.md +93 -0
  2. package/README.md +4 -1
  3. package/dist/package.json +100 -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_engine.d.mts +162 -0
  21. package/dist/src/baseline/privacy_engine.mjs +1162 -0
  22. package/dist/src/baseline/privacy_structured_json.d.mts +66 -0
  23. package/dist/src/baseline/privacy_structured_json.mjs +464 -0
  24. package/dist/src/baseline/sanitization_policy.d.mts +69 -0
  25. package/dist/src/baseline/sanitization_policy.mjs +227 -0
  26. package/dist/src/baseline/schema_snapshot.d.mts +19 -0
  27. package/dist/src/baseline/schema_snapshot.mjs +79 -0
  28. package/dist/src/cli/arguments.d.mts +43 -0
  29. package/dist/src/cli/arguments.mjs +135 -0
  30. package/dist/src/cli/guided.d.mts +51 -0
  31. package/dist/src/cli/guided.mjs +713 -0
  32. package/dist/src/cli/init_command.d.mts +21 -0
  33. package/dist/src/cli/init_command.mjs +90 -0
  34. package/dist/src/cli/project_commands.d.mts +157 -0
  35. package/dist/src/cli/project_commands.mjs +183 -0
  36. package/dist/src/cli/rehearsal.d.mts +7 -0
  37. package/dist/src/cli/rehearsal.mjs +706 -0
  38. package/dist/src/cli/renderers.d.mts +299 -0
  39. package/dist/src/cli/renderers.mjs +554 -0
  40. package/dist/src/cli/runtime_commands.d.mts +265 -0
  41. package/dist/src/cli/runtime_commands.mjs +599 -0
  42. package/dist/src/cli/source_commands.d.mts +432 -0
  43. package/dist/src/cli/source_commands.mjs +299 -0
  44. package/dist/src/cli/terminal.d.mts +59 -0
  45. package/dist/src/cli/terminal.mjs +230 -0
  46. package/dist/src/identity/claim.d.mts +144 -0
  47. package/dist/src/identity/claim.mjs +947 -0
  48. package/dist/src/identity/provider_configuration.d.mts +37 -0
  49. package/dist/src/identity/provider_configuration.mjs +132 -0
  50. package/dist/src/identity/storage.d.mts +21 -0
  51. package/dist/src/identity/storage.mjs +122 -0
  52. package/dist/src/index.d.mts +4 -0
  53. package/dist/src/index.mjs +3 -0
  54. package/dist/src/project/configuration.d.mts +181 -0
  55. package/dist/src/project/configuration.mjs +958 -0
  56. package/dist/src/project/install_scaffold.d.mts +42 -0
  57. package/dist/src/project/install_scaffold.mjs +263 -0
  58. package/dist/src/project/setup.d.mts +87 -0
  59. package/dist/src/project/setup.mjs +414 -0
  60. package/dist/src/project/support_report.d.mts +88 -0
  61. package/dist/src/project/support_report.mjs +83 -0
  62. package/dist/src/runtime/cleanup.d.mts +85 -0
  63. package/dist/src/runtime/cleanup.mjs +311 -0
  64. package/dist/src/runtime/migration_history.d.mts +51 -0
  65. package/dist/src/runtime/migration_history.mjs +170 -0
  66. package/dist/src/runtime/plan.d.mts +134 -0
  67. package/dist/src/runtime/plan.mjs +636 -0
  68. package/dist/src/runtime/policy.d.mts +66 -0
  69. package/dist/src/runtime/policy.mjs +369 -0
  70. package/dist/src/runtime/restore.d.mts +22 -0
  71. package/dist/src/runtime/restore.mjs +276 -0
  72. package/dist/src/runtime/service_environment.d.mts +11 -0
  73. package/dist/src/runtime/service_environment.mjs +58 -0
  74. package/dist/src/runtime/topology.d.mts +51 -0
  75. package/dist/src/runtime/topology.mjs +128 -0
  76. package/dist/src/shared/diagnostics.d.mts +97 -0
  77. package/dist/src/shared/diagnostics.mjs +170 -0
  78. package/dist/src/shared/human_output.d.mts +2 -0
  79. package/{src → dist/src}/shared/human_output.mjs +1 -3
  80. package/dist/src/shared/node_runtime.d.mts +14 -0
  81. package/dist/src/shared/node_runtime.mjs +25 -0
  82. package/dist/src/shared/operation_guard.d.mts +22 -0
  83. package/dist/src/shared/operation_guard.mjs +150 -0
  84. package/dist/src/shared/process_environment.d.mts +15 -0
  85. package/dist/src/shared/process_environment.mjs +50 -0
  86. package/dist/src/source/access.d.mts +165 -0
  87. package/dist/src/source/access.mjs +602 -0
  88. package/dist/src/source/asset_transfer.d.mts +27 -0
  89. package/dist/src/source/asset_transfer.mjs +202 -0
  90. package/dist/src/source/baseline.d.mts +66 -0
  91. package/dist/src/source/baseline.mjs +372 -0
  92. package/dist/src/source/external_reader.d.mts +42 -0
  93. package/dist/src/source/external_reader.mjs +278 -0
  94. package/dist/src/source/postgresql_access.d.mts +86 -0
  95. package/dist/src/source/postgresql_access.mjs +454 -0
  96. package/dist/src/source/privacy_paths.d.mts +10 -0
  97. package/dist/src/source/privacy_paths.mjs +27 -0
  98. package/dist/src/targets/driver.d.mts +2 -0
  99. package/dist/src/targets/driver.mjs +13 -0
  100. package/dist/src/targets/postgresql.d.mts +5 -0
  101. package/dist/src/targets/postgresql.mjs +641 -0
  102. package/dist/src/targets/supabase.d.mts +8 -0
  103. package/dist/src/targets/supabase.mjs +659 -0
  104. package/dist/src/targets/supabase_environment.d.mts +49 -0
  105. package/dist/src/targets/supabase_environment.mjs +162 -0
  106. package/dist/src/targets/target.d.mts +33 -0
  107. package/dist/src/targets/target.mjs +39 -0
  108. package/docs/README.md +1 -0
  109. package/docs/architecture.md +17 -9
  110. package/docs/configuration.md +49 -8
  111. package/docs/getting-started.md +28 -0
  112. package/docs/index.md +1 -0
  113. package/docs/production-source.md +43 -7
  114. package/docs/releasing.md +5 -3
  115. package/docs/roadmap.md +3 -2
  116. package/docs/sanitization.md +415 -14
  117. package/docs/standalone-workflow.md +12 -6
  118. package/docs/troubleshooting.md +5 -1
  119. package/docs/tutorial.md +5 -0
  120. package/docs/typescript.md +87 -0
  121. package/package.json +35 -29
  122. package/scripts/install/create_root_config.mjs +0 -36
  123. package/src/README.md +0 -17
  124. package/src/application/session.mjs +0 -435
  125. package/src/baseline/artifact.mjs +0 -684
  126. package/src/baseline/builder.mjs +0 -164
  127. package/src/baseline/input_discovery.mjs +0 -155
  128. package/src/baseline/policy_review.mjs +0 -92
  129. package/src/baseline/preparation.mjs +0 -323
  130. package/src/baseline/privacy_engine.mjs +0 -952
  131. package/src/baseline/sanitization_policy.mjs +0 -299
  132. package/src/baseline/schema_snapshot.mjs +0 -113
  133. package/src/cli/arguments.mjs +0 -126
  134. package/src/cli/guided.mjs +0 -814
  135. package/src/cli/init_command.mjs +0 -94
  136. package/src/cli/rehearsal.mjs +0 -970
  137. package/src/cli/renderers.mjs +0 -626
  138. package/src/cli/runtime_commands.mjs +0 -707
  139. package/src/cli/source_commands.mjs +0 -347
  140. package/src/cli/terminal.mjs +0 -275
  141. package/src/identity/claim.mjs +0 -1163
  142. package/src/identity/provider_configuration.mjs +0 -177
  143. package/src/identity/storage.mjs +0 -165
  144. package/src/project/configuration.mjs +0 -1337
  145. package/src/project/install_scaffold.mjs +0 -291
  146. package/src/project/setup.mjs +0 -466
  147. package/src/project/support_report.mjs +0 -105
  148. package/src/runtime/cleanup.mjs +0 -381
  149. package/src/runtime/migration_history.mjs +0 -220
  150. package/src/runtime/plan.mjs +0 -722
  151. package/src/runtime/policy.mjs +0 -438
  152. package/src/runtime/restore.mjs +0 -337
  153. package/src/runtime/service_environment.mjs +0 -82
  154. package/src/runtime/topology.mjs +0 -177
  155. package/src/shared/diagnostics.mjs +0 -207
  156. package/src/shared/node_runtime.mjs +0 -31
  157. package/src/shared/operation_guard.mjs +0 -162
  158. package/src/shared/process_environment.mjs +0 -68
  159. package/src/source/access.mjs +0 -753
  160. package/src/source/asset_transfer.mjs +0 -207
  161. package/src/source/baseline.mjs +0 -482
  162. package/src/source/external_reader.mjs +0 -255
  163. package/src/source/postgresql_access.mjs +0 -581
  164. package/src/source/privacy_paths.mjs +0 -38
  165. package/src/targets/postgresql.mjs +0 -808
  166. package/src/targets/supabase.mjs +0 -840
  167. package/src/targets/supabase_environment.mjs +0 -229
  168. package/src/targets/target.mjs +0 -66
  169. /package/{src/project → types}/configuration.d.mts +0 -0
@@ -1,626 +0,0 @@
1
- /**
2
- * Human-readable CLI output. These functions are intentionally pure so the
3
- * command and guided workflow modules can focus on orchestration.
4
- */
5
-
6
- import { formatCount } from "../shared/human_output.mjs";
7
- import { terminalStyle } from "./terminal.mjs";
8
-
9
- export const renderPlan = (plan, verbosity) => {
10
- if (plan.targets) {
11
- return [
12
- "REHEARSAL STACK PLAN",
13
- "",
14
- ...plan.targets.flatMap((target) => [
15
- `${target.name} — ${target.plan.config.project}`,
16
- ` ✓ ${target.plan.environment.kind}`,
17
- ...(target.plan.environment.authenticationProviders.length
18
- ? [
19
- ` ✓ External identity providers ${target.plan.environment.authenticationProviders.join(", ")}`,
20
- ...(target.plan.environment.authenticationCallback
21
- ? [
22
- ` → Register callback ${target.plan.environment.authenticationCallback}`,
23
- ]
24
- : []),
25
- ]
26
- : []),
27
- ` ✓ baseline ${target.plan.baseline.generationId}`,
28
- ` ✓ ${formatCount(target.plan.baseline.tableCount, "table")}; ${formatCount(target.plan.baseline.rowCount, "row")}`,
29
- ...(target.plan.migrations.candidates.length
30
- ? target.plan.migrations.candidates.map(
31
- (migration) => ` → ${migration.filename}`,
32
- )
33
- : [" ✓ No candidate migrations"]),
34
- "",
35
- ]),
36
- `Combined candidate digest: ${plan.migrations.candidateSha256}`,
37
- "",
38
- "Execution plan",
39
- ...plan.execution.map((step, index) => ` ${index + 1}. ${step}`),
40
- ...(verbosity === "normal"
41
- ? []
42
- : [
43
- "",
44
- ...plan.targets.flatMap((target) =>
45
- target.plan.environment.barriers.map(
46
- (barrier) => ` ✓ ${target.name}: ${barrier}`,
47
- ),
48
- ),
49
- ]),
50
- "",
51
- plan.guarantee,
52
- "",
53
- plan.migrations.candidateCount
54
- ? "Next: run rehearsal run to review and confirm this exact cross-target migration set."
55
- : "Next: run rehearsal run to verify the runtime stack and project proofs.",
56
- ].join("\n");
57
- }
58
- const candidates = plan.migrations.candidates.length
59
- ? plan.migrations.candidates
60
- .map((entry) => ` → ${entry.filename} (${entry.sha256.slice(0, 12)})`)
61
- .join("\n")
62
- : " ✓ No candidate migrations";
63
- const verbose =
64
- verbosity === "normal"
65
- ? []
66
- : [
67
- "",
68
- "Safety barriers",
69
- ...plan.environment.barriers.map((barrier) => ` ✓ ${barrier}`),
70
- ` ✓ Candidate digest: ${plan.migrations.candidateSha256}`,
71
- ];
72
- return [
73
- "REHEARSAL PLAN",
74
- "",
75
- "Environment",
76
- ` ✓ ${plan.environment.kind}`,
77
- ` ✓ Hosted access ${plan.environment.hostedAccess}`,
78
- ` ✓ Hosted target configuration ${plan.environment.outboundNetwork}`,
79
- ...(plan.environment.authenticationProviders.length
80
- ? [
81
- ` ✓ External identity providers ${plan.environment.authenticationProviders.join(", ")}`,
82
- ...(plan.environment.authenticationCallback
83
- ? [
84
- ` → Register callback ${plan.environment.authenticationCallback}`,
85
- ]
86
- : []),
87
- ]
88
- : []),
89
- "",
90
- "Baseline",
91
- ` ✓ ${plan.baseline.generationId}`,
92
- ` ✓ ${formatCount(plan.baseline.tableCount, "table")}; ${formatCount(plan.baseline.rowCount, "row")}`,
93
- ` ✓ ${plan.baseline.verification}`,
94
- "",
95
- "Migrations",
96
- ` ✓ ${plan.migrations.representedCount} represented by baseline`,
97
- candidates,
98
- "",
99
- "Execution plan",
100
- ...plan.execution.map((step, index) => ` ${index + 1}. ${step}`),
101
- ...verbose,
102
- "",
103
- plan.guarantee,
104
- "",
105
- plan.migrations.candidateCount
106
- ? "Next: run rehearsal run to review and confirm this exact candidate set."
107
- : "Next: run rehearsal run to verify the baseline and application proof.",
108
- ].join("\n");
109
- };
110
-
111
- export const renderDoctor = (doctor, verbosity) => {
112
- const lines = doctor.checks.map((check) => {
113
- const marker = check.status === "pass" ? "✓" : "✗";
114
- const detail =
115
- verbosity === "normal" && check.status === "pass"
116
- ? ""
117
- : ` — ${check.detail}`;
118
- return `${marker} ${check.label}${detail}`;
119
- });
120
- for (const check of doctor.checks.filter(
121
- (entry) => entry.status === "fail",
122
- )) {
123
- if (check.remediation) lines.push(` Try: ${check.remediation}`);
124
- }
125
- if (doctor.ambientHostedVariables?.presentButQuarantined.length) {
126
- lines.push(
127
- `! ${doctor.ambientHostedVariables.presentButQuarantined.length} ambient hosted credential variables detected and quarantined.`,
128
- );
129
- }
130
- return [
131
- ...lines,
132
- "",
133
- doctor.state,
134
- "",
135
- doctor.state === "READY"
136
- ? "Next: run rehearsal explain to review the migration plan."
137
- : "Next: fix the items above, then run rehearsal doctor again.",
138
- ].join("\n");
139
- };
140
-
141
- export const renderBaseline = (baseline) =>
142
- [
143
- "REHEARSAL BASELINE",
144
- `Rehearsal: ${baseline.rehearsalVersion}`,
145
- `Generation: ${baseline.generationId}`,
146
- `Created: ${baseline.createdAt ?? "unknown"}`,
147
- `Format: ${baseline.formatVersion}`,
148
- `Tables: ${baseline.tableCount}`,
149
- `Rows: ${baseline.rowCount}`,
150
- `Migrations: ${baseline.migrationCount} through ${baseline.migrationCutoff}`,
151
- `Data SHA-256: ${baseline.dataSha256}`,
152
- `Sanitization policy SHA-256: ${baseline.sanitizationPolicySha256}`,
153
- `Verification: ${baseline.verification}`,
154
- "Source rows and sensitive values are never printed by inspect.",
155
- ].join("\n");
156
-
157
- export const renderMigrations = (inspection, verbosity) => {
158
- const entries = inspection.migrations.map((migration) => {
159
- const digest = verbosity === "normal" ? "" : ` (${migration.sha256})`;
160
- return `${migration.status.padEnd(28)} ${migration.filename}${digest}`;
161
- });
162
- return [
163
- "REHEARSAL MIGRATIONS",
164
- `Baseline: ${inspection.baselineGenerationId} through ${inspection.baselineCutoff}`,
165
- `Candidate digest: ${inspection.candidateSha256}`,
166
- "",
167
- ...entries,
168
- ].join("\n");
169
- };
170
-
171
- export const renderCandidates = (summary, verbosity) =>
172
- [
173
- "REHEARSAL CANDIDATES",
174
- ...(summary.targets?.length > 1
175
- ? summary.targets.flatMap((target) => [
176
- "",
177
- `${target.name} — baseline ${target.baselineGenerationId}`,
178
- ...(target.candidates.length
179
- ? target.candidates.map((migration) =>
180
- verbosity === "normal"
181
- ? ` → ${migration.filename}`
182
- : ` → ${migration.filename} (${migration.sha256})`,
183
- )
184
- : [" ✓ No candidate migrations"]),
185
- ])
186
- : [
187
- `Baseline: ${summary.baselineGenerationId}`,
188
- ...(summary.candidates.length
189
- ? summary.candidates.map((migration) =>
190
- verbosity === "normal"
191
- ? ` → ${migration.filename}`
192
- : ` → ${migration.filename} (${migration.sha256})`,
193
- )
194
- : [" ✓ No candidate migrations"]),
195
- ]),
196
- "",
197
- `${summary.targets?.length > 1 ? "Combined candidate digest" : "Candidate digest"}: ${summary.candidateSha256}`,
198
- `${summary.targets?.length > 1 ? "Pending across all targets" : "Pending"}: ${summary.candidateCount}`,
199
- "",
200
- summary.candidateCount
201
- ? "Next: run rehearsal run for a guided confirmation, or pass the full digest in automation."
202
- : "Next: run rehearsal run to verify the baseline and application proof.",
203
- ].join("\n");
204
-
205
- export const renderInit = (result) =>
206
- [
207
- `REHEARSAL INIT — ${result.mode.toUpperCase()}`,
208
- `Destination: ${result.destination}`,
209
- `Detected package manager: ${result.detected.packageManager}`,
210
- `Detected Supabase config: ${result.detected.hasSupabaseConfig ? "yes" : "no"}`,
211
- `Detected migrations: ${result.detected.hasMigrations ? "yes" : "no"}`,
212
- ...(result.availableOptions?.length
213
- ? [
214
- "",
215
- "AVAILABLE BUT NOT ENABLED",
216
- ...result.availableOptions.map(
217
- (option) => ` → ${option.path}: ${option.summary}`,
218
- ),
219
- ]
220
- : []),
221
- ...(result.source ? ["", result.source] : []),
222
- result.nextAction,
223
- ].join("\n");
224
-
225
- const summarizeSetupReadinessChecks = (readiness) => {
226
- const failures = readiness.checks.filter((check) => check.status === "fail");
227
- const policyMissing = failures.some(
228
- (check) =>
229
- check.id === "sanitization-policy" &&
230
- /ENOENT|no such file/iu.test(check.detail),
231
- );
232
- const baselineMissing = failures.some(
233
- (check) =>
234
- check.id === "baseline" && /ENOENT|no such file/iu.test(check.detail),
235
- );
236
- const hidden = new Set([
237
- ...(policyMissing ? ["sanitization-policy"] : []),
238
- ...(baselineMissing
239
- ? ["baseline", "baseline-permissions", "migration-history"]
240
- : []),
241
- ]);
242
- if (
243
- policyMissing &&
244
- failures.some(
245
- (check) =>
246
- check.id === "paths" && /sanitization-policy/iu.test(check.detail),
247
- )
248
- ) {
249
- hidden.add("paths");
250
- }
251
- const passed = readiness.checks.filter(
252
- (check) => check.status === "pass",
253
- ).length;
254
- return [
255
- ...(passed ? [` ✓ ${passed} environment and safety checks passed`] : []),
256
- ...failures
257
- .filter((check) => !hidden.has(check.id))
258
- .map((check) => ` ○ ${check.label}: ${check.detail}`),
259
- ...(policyMissing
260
- ? [" ○ Baseline policy: not created yet (next guided step)"]
261
- : []),
262
- ...(baselineMissing
263
- ? [" ○ Verified baseline: not created yet (after policy review)"]
264
- : []),
265
- ];
266
- };
267
-
268
- export const renderSetup = (result) => {
269
- const actionMarker = { create: "+", update: "~", unchanged: "=" };
270
- return [
271
- `REHEARSAL SETUP — ${result.mode.toUpperCase()}`,
272
- `Project: ${result.project}`,
273
- `Database: ${result.target === "postgresql" ? "PostgreSQL" : "Supabase"}`,
274
- `Runtime ID: ${result.projectId}`,
275
- `Application: ${result.applicationUrl}`,
276
- result.target === "postgresql"
277
- ? `Port: database ${result.ports.database}`
278
- : `Ports: API ${result.ports.api}, database ${result.ports.database}, Studio ${result.ports.studio}`,
279
- "",
280
- "Files",
281
- ...result.files.map(
282
- (file) => ` ${actionMarker[file.action]} ${file.action} ${file.path}`,
283
- ),
284
- "",
285
- "Safety boundaries",
286
- ...result.safety.map((barrier) => ` ✓ ${barrier}`),
287
- ...(result.readiness
288
- ? [
289
- "",
290
- `Readiness — ${result.readiness.state}`,
291
- ...summarizeSetupReadinessChecks(result.readiness),
292
- ]
293
- : []),
294
- "",
295
- result.nextAction,
296
- ].join("\n");
297
- };
298
-
299
- export const renderBaselinePreparation = (result, flags = {}) =>
300
- [
301
- `BASELINE POLICY — ${result.mode.toUpperCase()}`,
302
- `Destination: ${result.destination}`,
303
- `Records: ${formatCount(result.rowCount, "row")} from ${result.recordsPath}`,
304
- `Migrations: ${formatCount(result.migrationCount, "migration")} through ${result.migrationCutoff}`,
305
- "",
306
- "Detected shape (values are never printed)",
307
- ...result.tables.map(
308
- (table) =>
309
- ` ${terminalStyle(flags, "36", "→")} ${table.name}: ${formatCount(table.rowCount, "row")}; ${table.columns.join(", ")}`,
310
- ),
311
- "",
312
- "Every column is marked REVIEW REQUIRED for action, generated status, identity, and foreign key metadata.",
313
- "The draft cannot be activated until those decisions are completed.",
314
- "",
315
- result.nextAction,
316
- ].join("\n");
317
-
318
- export const renderBaselineInputInspection = (result, flags = {}) =>
319
- [
320
- "BASELINE INPUTS — READY",
321
- `Records: ${formatCount(result.rowCount, "row")} across ${formatCount(result.tables.length, "table")} from ${result.recordsPath}`,
322
- `Migrations: ${formatCount(result.migrationCount, "migration")} through ${result.migrationCutoff} from ${result.ledgerPath}`,
323
- result.assetsPath
324
- ? `Storage: ${formatCount(result.assetCount, "asset")} from ${result.assetsPath}`
325
- : "Storage: no asset manifest selected",
326
- "",
327
- "Detected tables (values are never printed)",
328
- ...result.tables.map(
329
- (table) =>
330
- ` ${terminalStyle(flags, "36", "→")} ${table.name}: ${formatCount(table.rowCount, "row")}`,
331
- ),
332
- "",
333
- "All inputs are project-local regular files and passed structural validation.",
334
- ].join("\n");
335
-
336
- export const renderSupportReport = (report) => {
337
- const toolLine = (label, tool) =>
338
- `${label}: ${tool.status === "available" ? tool.version : tool.status.replaceAll("_", " ")}`;
339
- return [
340
- "REHEARSAL SUPPORT REPORT",
341
- "",
342
- `Rehearsal: ${report.rehearsalVersion}`,
343
- `System: ${report.system.platform} ${report.system.architecture} (${report.system.release})`,
344
- `Node.js: ${report.system.node}`,
345
- toolLine("npm", report.tools.npm),
346
- toolLine("Supabase CLI", report.tools.supabase),
347
- toolLine("Docker client", report.tools.dockerClient),
348
- toolLine("Docker server", report.tools.dockerServer),
349
- "",
350
- `Readiness: ${report.readiness.state}`,
351
- ...report.readiness.checks.map((check) =>
352
- check.status === "pass"
353
- ? ` ✓ ${check.label}`
354
- : ` ✗ ${check.label}${check.remediation ? ` — ${check.remediation}` : ""}`,
355
- ),
356
- ...(report.readiness.quarantinedHostedVariableCount
357
- ? [
358
- ` ! ${formatCount(report.readiness.quarantinedHostedVariableCount, "ambient hosted variable")} detected and quarantined`,
359
- ]
360
- : []),
361
- "",
362
- "Privacy: no row values, credentials, project paths, migration SQL, or baseline identifiers are included.",
363
- "Review this report before sharing it.",
364
- `Report a reproducible issue: ${report.supportUrl}`,
365
- ].join("\n");
366
- };
367
-
368
- export const formatBytes = (bytes) => {
369
- if (!Number.isFinite(bytes) || bytes <= 0) return "0 B";
370
- const units = ["B", "KiB", "MiB", "GiB", "TiB"];
371
- const unit = Math.min(
372
- Math.floor(Math.log(bytes) / Math.log(1024)),
373
- units.length - 1,
374
- );
375
- const value = bytes / 1024 ** unit;
376
- return `${value >= 10 || unit === 0 ? value.toFixed(0) : value.toFixed(1)} ${units[unit]}`;
377
- };
378
-
379
- export const renderCleanup = (result) => {
380
- const plan = result.plan;
381
- if (plan.targets) {
382
- const selectedCount = plan.targets.reduce(
383
- (total, target) =>
384
- total +
385
- target.plan.baselines.removed.length +
386
- (target.plan.runtime.included && target.plan.runtime.detected ? 1 : 0) +
387
- target.plan.images.candidates.length,
388
- 0,
389
- );
390
- return [
391
- `REHEARSAL STACK CLEANUP — ${result.mode.toUpperCase()}`,
392
- ...plan.targets.flatMap((target) => [
393
- "",
394
- `${target.name} — ${target.plan.project}`,
395
- target.plan.baselines.available
396
- ? ` ${target.plan.baselines.removed.length ? "→" : "✓"} ${formatCount(target.plan.baselines.removed.length, "old baseline generation")} selected; keeping ${target.plan.baselines.retained.length}`
397
- : " ○ No active baseline found",
398
- !target.plan.runtime.detected
399
- ? " ✓ No runtime found"
400
- : target.plan.runtime.included
401
- ? ` → Runtime ${target.plan.projectId} selected`
402
- : ` ○ Runtime ${target.plan.projectId} preserved`,
403
- ...(target.plan.images.requested
404
- ? target.plan.images.inspected
405
- ? target.plan.images.candidates.length
406
- ? [
407
- ` → ${formatCount(target.plan.images.candidates.length, "older unused Supabase image")} selected`,
408
- ...target.plan.images.candidates.flatMap((image) =>
409
- image.tags.map((tag) => ` ${tag}`),
410
- ),
411
- ]
412
- : [" ✓ No older unused Supabase images found"]
413
- : [" ! Docker is unavailable; shared images were not inspected"]
414
- : []),
415
- ]),
416
- "",
417
- ...(result.mode === "preview"
418
- ? selectedCount
419
- ? [
420
- "Nothing has been removed.",
421
- `Combined cleanup set: ${plan.digest.slice(0, 12)}`,
422
- `Exact confirmation: --confirm-cleanup=${plan.digest}`,
423
- "Review every target above, then rerun with --write and this exact confirmation.",
424
- ]
425
- : ["Nothing has been removed, and nothing is currently selected."]
426
- : result.applied.targets.map(
427
- (target) =>
428
- `${target.name}: removed ${formatCount(target.applied.baselines.removed.length, "old baseline generation")}; runtime ${target.applied.runtimeRemoved ? "removed" : "preserved"}; removed ${formatCount(target.applied.imagesRemoved.length, "unused image tag")}.`,
429
- )),
430
- ].join("\n");
431
- }
432
- const imageBytes = plan.images.candidates.reduce(
433
- (total, image) => total + image.bytes,
434
- 0,
435
- );
436
- const dockerImages = plan.docker.resources.find(
437
- (resource) => resource.Type === "Images",
438
- );
439
- const selectedCount =
440
- plan.baselines.removed.length +
441
- (plan.runtime.included && plan.runtime.detected ? 1 : 0) +
442
- plan.images.candidates.length;
443
- return [
444
- `REHEARSAL CLEANUP — ${result.mode.toUpperCase()}`,
445
- `Project: ${plan.project}`,
446
- ...(dockerImages
447
- ? [
448
- `Docker images: ${dockerImages.Size}; ${dockerImages.Reclaimable} reclaimable across Docker`,
449
- ]
450
- : ["Docker usage: unavailable"]),
451
- ...(plan.docker.disk
452
- ? [
453
- `Container disk: ${formatBytes(plan.docker.disk.usedBytes)} used of ${formatBytes(plan.docker.disk.totalBytes)}; ${formatBytes(plan.docker.disk.availableBytes)} free (${plan.docker.disk.usedPercent}% used)`,
454
- ]
455
- : []),
456
- "",
457
- "Project-owned files",
458
- plan.baselines.available
459
- ? ` ${plan.baselines.removed.length ? "→" : "✓"} ${formatCount(plan.baselines.removed.length, "old baseline generation")} selected; keeping ${plan.baselines.retained.length}`
460
- : " ○ No active baseline found",
461
- "",
462
- "Disposable runtime",
463
- !plan.runtime.detected
464
- ? " ✓ No runtime found"
465
- : plan.runtime.included
466
- ? " → Current project runtime selected"
467
- : " ○ Current project runtime preserved (add --include-runtime to select it)",
468
- "",
469
- "Shared Docker images",
470
- !plan.images.requested
471
- ? " ○ Not inspected (add --include-images to inspect older unused Supabase images)"
472
- : !plan.images.inspected
473
- ? " ! Docker is unavailable; images could not be inspected"
474
- : plan.images.candidates.length
475
- ? ` → ${formatCount(plan.images.candidates.length, "older unused Supabase image")} selected; approximately ${formatBytes(imageBytes)}`
476
- : " ✓ No older unused Supabase images found",
477
- ...(plan.images.candidates.length
478
- ? plan.images.candidates.flatMap((image) =>
479
- image.tags.map((tag) => ` ${tag}`),
480
- )
481
- : []),
482
- "",
483
- ...(result.mode === "preview"
484
- ? selectedCount
485
- ? [
486
- "Nothing has been removed.",
487
- `Cleanup set: ${plan.digest.slice(0, 12)}`,
488
- `Exact confirmation: --confirm-cleanup=${plan.digest}`,
489
- "Review this list, then rerun the same command with --write and the exact confirmation above.",
490
- ]
491
- : [
492
- "Nothing has been removed, and nothing is currently selected.",
493
- "Use --include-runtime or --include-images only when you want those shared resources considered.",
494
- ]
495
- : [
496
- `Removed ${formatCount(result.applied.baselines.removed.length, "old baseline generation")}.`,
497
- result.applied.runtimeRemoved
498
- ? "Removed this project's disposable runtime and volumes."
499
- : "Preserved this project's disposable runtime.",
500
- `Removed ${formatCount(result.applied.imagesRemoved.length, "unused image tag")}.`,
501
- ]),
502
- ].join("\n");
503
- };
504
-
505
- export const renderSourceAccessPlan = (plan) =>
506
- [
507
- "SOURCE ACCESS — PREVIEW",
508
- "",
509
- `Target fingerprint: ${plan.review.targetFingerprint}`,
510
- plan.review.reader.mode === "managed"
511
- ? `Managed temporary reader: ${plan.review.reader.role} (${plan.review.reader.validForMinutes} minutes)`
512
- : `Externally managed reader: ${plan.review.reader.role} (maximum ${plan.review.reader.maximumValidForMinutes} minutes remaining)`,
513
- `Source changes by Rehearsal: ${plan.review.reader.sourceChanges ? "export views and temporary roles" : "none"}`,
514
- `Export schema: ${plan.review.exportSchema}`,
515
- ...plan.review.relations.map(
516
- (relation) =>
517
- ` → ${relation.source.schema}.${relation.source.table} → ${relation.view}: ${relation.columns.join(", ")} (${relation.rowScope.kind})`,
518
- ),
519
- ...(plan.review.assets.length
520
- ? plan.review.assets.map(
521
- (asset) =>
522
- ` → Storage ${asset.bucket}/${
523
- asset.prefix ??
524
- `[private prefix from ${asset.prefixEnvironmentVariable}]`
525
- } (${asset.rights})`,
526
- )
527
- : [" ○ No source assets declared"]),
528
- "",
529
- "Deny checks",
530
- ...plan.review.denyChecks.map((check) => ` ✓ ${check}`),
531
- "",
532
- "No source changes have been made.",
533
- `Exact confirmation: --confirm-source-access=${plan.digest}`,
534
- ].join("\n");
535
-
536
- export const renderRefreshWorkflow = ({
537
- mode,
538
- plan,
539
- refreshed,
540
- runtime,
541
- cleanup,
542
- }) =>
543
- [
544
- `DATABASE COPY REFRESH — ${mode.toUpperCase()}`,
545
- "",
546
- `Current baseline: ${plan.review.currentBaseline}`,
547
- `Source access expires: ${plan.review.source.readerExpiresAt}`,
548
- `Runtime targets reset: ${plan.review.runtimeTargets.join(", ")}`,
549
- `Baseline retention: ${formatCount(plan.review.retention.generations, "generation")}`,
550
- ...(plan.review.retention.removeAfterReplacement.length
551
- ? [
552
- "Old generations removed after success:",
553
- ...plan.review.retention.removeAfterReplacement.map(
554
- (generation) => ` → ${generation}`,
555
- ),
556
- ]
557
- : ["Old generations removed after success: none"]),
558
- "",
559
- ...plan.review.steps.map((step, index) => ` ${index + 1}. ${step}`),
560
- "",
561
- ...(mode === "preview"
562
- ? [
563
- "Nothing has changed. The current baseline and runtime remain intact.",
564
- `Exact confirmation: --confirm-refresh=${plan.digest}`,
565
- ]
566
- : [
567
- `Activated baseline: ${refreshed.generationId}`,
568
- `Runtime reset: ${runtime.targets?.length ?? 1} target(s)`,
569
- cleanup.state === "complete"
570
- ? `Cleanup complete: ${formatCount(cleanup.removed.length, "old generation")} removed.`
571
- : `Cleanup incomplete: ${formatCount(cleanup.remaining, "old generation")} still eligible. Run rehearsal cleanup.`,
572
- "",
573
- "Next: retire source access when no other refresh is needed, then run a rehearsal.",
574
- ]),
575
- ].join("\n");
576
-
577
- export const renderSourceRetirement = ({ mode, plan }) =>
578
- [
579
- `SOURCE ACCESS RETIREMENT — ${mode.toUpperCase()}`,
580
- `Target fingerprint: ${plan.review.targetFingerprint}`,
581
- `Reader: ${plan.review.readerRole}`,
582
- `Export schema: ${plan.review.exportSchema}`,
583
- ...(plan.review.accessMode === "managed"
584
- ? plan.review.views.map((view) => ` → remove view ${view}`)
585
- : [
586
- " → remove only Rehearsal's local credential and receipt",
587
- " ✓ preserve the provider-owned reader and export views",
588
- ]),
589
- "",
590
- ...(mode === "preview"
591
- ? [
592
- "Nothing has been removed.",
593
- `Exact confirmation: --confirm-source-retirement=${plan.digest}`,
594
- ]
595
- : [
596
- plan.review.accessMode === "managed"
597
- ? "The exact reader, export views, and local credential files were retired."
598
- : "Rehearsal's local credential and receipt were removed. Provider-owned database resources were preserved.",
599
- ]),
600
- ].join("\n");
601
-
602
- export const renderIdentityPlan = ({ mode, plan }) =>
603
- [
604
- `LOCAL IDENTITY — ${mode.toUpperCase()}`,
605
- `Identity: ${plan.review.name}`,
606
- `Matcher: ${plan.review.matcher.type}`,
607
- plan.review.matcher.type === "verified-email"
608
- ? `Providers: ${plan.review.matcher.providers.join(", ")}`
609
- : `Provider: ${plan.review.matcher.provider}`,
610
- plan.review.matcher.type === "verified-email"
611
- ? `Approved email receipt: ${plan.review.matcher.approvedEmailSha256}`
612
- : `Approved subject receipt: ${plan.review.matcher.approvedSubjectSha256}`,
613
- `Relational references: ${plan.review.references.length}`,
614
- `Nested JSON references: ${plan.review.jsonReferences.length}`,
615
- `Signup defaults: ${plan.review.signupDefaults.length}`,
616
- `Storage path references: ${plan.review.pathReferences.length}`,
617
- `Asset scopes: ${plan.review.assets.length}`,
618
- `Token hook assertion: ${plan.review.tokenHook ? "configured" : "not configured"}`,
619
- "",
620
- ...(mode === "preview"
621
- ? [
622
- "No local account was changed.",
623
- `Exact confirmation: --confirm-identity=${plan.digest}`,
624
- ]
625
- : ["The verified local identity now owns the declared copied graph."]),
626
- ].join("\n");