@rehearsal-db/core 0.1.0-beta.14 → 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 (162) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/README.md +1 -0
  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 +9 -3
  111. package/docs/index.md +1 -0
  112. package/docs/typescript.md +87 -0
  113. package/package.json +35 -29
  114. package/scripts/install/create_root_config.mjs +0 -19
  115. package/src/README.md +0 -17
  116. package/src/application/session.mjs +0 -435
  117. package/src/baseline/artifact.mjs +0 -684
  118. package/src/baseline/builder.mjs +0 -164
  119. package/src/baseline/input_discovery.mjs +0 -155
  120. package/src/baseline/policy_review.mjs +0 -92
  121. package/src/baseline/preparation.mjs +0 -323
  122. package/src/baseline/privacy_engine.mjs +0 -1399
  123. package/src/baseline/privacy_structured_json.mjs +0 -554
  124. package/src/baseline/sanitization_policy.mjs +0 -299
  125. package/src/baseline/schema_snapshot.mjs +0 -113
  126. package/src/cli/arguments.mjs +0 -126
  127. package/src/cli/guided.mjs +0 -814
  128. package/src/cli/init_command.mjs +0 -94
  129. package/src/cli/rehearsal.mjs +0 -972
  130. package/src/cli/renderers.mjs +0 -638
  131. package/src/cli/runtime_commands.mjs +0 -707
  132. package/src/cli/source_commands.mjs +0 -355
  133. package/src/cli/terminal.mjs +0 -275
  134. package/src/identity/claim.mjs +0 -1165
  135. package/src/identity/provider_configuration.mjs +0 -177
  136. package/src/identity/storage.mjs +0 -165
  137. package/src/project/configuration.mjs +0 -1337
  138. package/src/project/install_scaffold.mjs +0 -325
  139. package/src/project/setup.mjs +0 -474
  140. package/src/project/support_report.mjs +0 -105
  141. package/src/runtime/cleanup.mjs +0 -381
  142. package/src/runtime/migration_history.mjs +0 -220
  143. package/src/runtime/plan.mjs +0 -722
  144. package/src/runtime/policy.mjs +0 -438
  145. package/src/runtime/restore.mjs +0 -337
  146. package/src/runtime/service_environment.mjs +0 -82
  147. package/src/runtime/topology.mjs +0 -177
  148. package/src/shared/diagnostics.mjs +0 -207
  149. package/src/shared/node_runtime.mjs +0 -31
  150. package/src/shared/operation_guard.mjs +0 -162
  151. package/src/shared/process_environment.mjs +0 -68
  152. package/src/source/access.mjs +0 -798
  153. package/src/source/asset_transfer.mjs +0 -259
  154. package/src/source/baseline.mjs +0 -482
  155. package/src/source/external_reader.mjs +0 -368
  156. package/src/source/postgresql_access.mjs +0 -638
  157. package/src/source/privacy_paths.mjs +0 -38
  158. package/src/targets/postgresql.mjs +0 -808
  159. package/src/targets/supabase.mjs +0 -840
  160. package/src/targets/supabase_environment.mjs +0 -229
  161. package/src/targets/target.mjs +0 -66
  162. /package/{src/project → types}/configuration.d.mts +0 -0
@@ -1,638 +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
- `Configuration: ${result.configurationPath} (${
274
- result.configurationAction === "create"
275
- ? result.mode === "written"
276
- ? "created"
277
- : "will create"
278
- : "existing"
279
- })`,
280
- ...(result.rootConfigGenerationSkipped
281
- ? [
282
- "Root config: not created because the existing supported configuration remains active.",
283
- ]
284
- : []),
285
- `Database: ${result.target === "postgresql" ? "PostgreSQL" : "Supabase"}`,
286
- `Runtime ID: ${result.projectId}`,
287
- `Application: ${result.applicationUrl}`,
288
- result.target === "postgresql"
289
- ? `Port: database ${result.ports.database}`
290
- : `Ports: API ${result.ports.api}, database ${result.ports.database}, Studio ${result.ports.studio}`,
291
- "",
292
- "Files",
293
- ...result.files.map(
294
- (file) => ` ${actionMarker[file.action]} ${file.action} ${file.path}`,
295
- ),
296
- "",
297
- "Safety boundaries",
298
- ...result.safety.map((barrier) => ` ✓ ${barrier}`),
299
- ...(result.readiness
300
- ? [
301
- "",
302
- `Readiness — ${result.readiness.state}`,
303
- ...summarizeSetupReadinessChecks(result.readiness),
304
- ]
305
- : []),
306
- "",
307
- result.nextAction,
308
- ].join("\n");
309
- };
310
-
311
- export const renderBaselinePreparation = (result, flags = {}) =>
312
- [
313
- `BASELINE POLICY — ${result.mode.toUpperCase()}`,
314
- `Destination: ${result.destination}`,
315
- `Records: ${formatCount(result.rowCount, "row")} from ${result.recordsPath}`,
316
- `Migrations: ${formatCount(result.migrationCount, "migration")} through ${result.migrationCutoff}`,
317
- "",
318
- "Detected shape (values are never printed)",
319
- ...result.tables.map(
320
- (table) =>
321
- ` ${terminalStyle(flags, "36", "→")} ${table.name}: ${formatCount(table.rowCount, "row")}; ${table.columns.join(", ")}`,
322
- ),
323
- "",
324
- "Every column is marked REVIEW REQUIRED for action, generated status, identity, and foreign key metadata.",
325
- "The draft cannot be activated until those decisions are completed.",
326
- "",
327
- result.nextAction,
328
- ].join("\n");
329
-
330
- export const renderBaselineInputInspection = (result, flags = {}) =>
331
- [
332
- "BASELINE INPUTS — READY",
333
- `Records: ${formatCount(result.rowCount, "row")} across ${formatCount(result.tables.length, "table")} from ${result.recordsPath}`,
334
- `Migrations: ${formatCount(result.migrationCount, "migration")} through ${result.migrationCutoff} from ${result.ledgerPath}`,
335
- result.assetsPath
336
- ? `Storage: ${formatCount(result.assetCount, "asset")} from ${result.assetsPath}`
337
- : "Storage: no asset manifest selected",
338
- "",
339
- "Detected tables (values are never printed)",
340
- ...result.tables.map(
341
- (table) =>
342
- ` ${terminalStyle(flags, "36", "→")} ${table.name}: ${formatCount(table.rowCount, "row")}`,
343
- ),
344
- "",
345
- "All inputs are project-local regular files and passed structural validation.",
346
- ].join("\n");
347
-
348
- export const renderSupportReport = (report) => {
349
- const toolLine = (label, tool) =>
350
- `${label}: ${tool.status === "available" ? tool.version : tool.status.replaceAll("_", " ")}`;
351
- return [
352
- "REHEARSAL SUPPORT REPORT",
353
- "",
354
- `Rehearsal: ${report.rehearsalVersion}`,
355
- `System: ${report.system.platform} ${report.system.architecture} (${report.system.release})`,
356
- `Node.js: ${report.system.node}`,
357
- toolLine("npm", report.tools.npm),
358
- toolLine("Supabase CLI", report.tools.supabase),
359
- toolLine("Docker client", report.tools.dockerClient),
360
- toolLine("Docker server", report.tools.dockerServer),
361
- "",
362
- `Readiness: ${report.readiness.state}`,
363
- ...report.readiness.checks.map((check) =>
364
- check.status === "pass"
365
- ? ` ✓ ${check.label}`
366
- : ` ✗ ${check.label}${check.remediation ? ` — ${check.remediation}` : ""}`,
367
- ),
368
- ...(report.readiness.quarantinedHostedVariableCount
369
- ? [
370
- ` ! ${formatCount(report.readiness.quarantinedHostedVariableCount, "ambient hosted variable")} detected and quarantined`,
371
- ]
372
- : []),
373
- "",
374
- "Privacy: no row values, credentials, project paths, migration SQL, or baseline identifiers are included.",
375
- "Review this report before sharing it.",
376
- `Report a reproducible issue: ${report.supportUrl}`,
377
- ].join("\n");
378
- };
379
-
380
- export const formatBytes = (bytes) => {
381
- if (!Number.isFinite(bytes) || bytes <= 0) return "0 B";
382
- const units = ["B", "KiB", "MiB", "GiB", "TiB"];
383
- const unit = Math.min(
384
- Math.floor(Math.log(bytes) / Math.log(1024)),
385
- units.length - 1,
386
- );
387
- const value = bytes / 1024 ** unit;
388
- return `${value >= 10 || unit === 0 ? value.toFixed(0) : value.toFixed(1)} ${units[unit]}`;
389
- };
390
-
391
- export const renderCleanup = (result) => {
392
- const plan = result.plan;
393
- if (plan.targets) {
394
- const selectedCount = plan.targets.reduce(
395
- (total, target) =>
396
- total +
397
- target.plan.baselines.removed.length +
398
- (target.plan.runtime.included && target.plan.runtime.detected ? 1 : 0) +
399
- target.plan.images.candidates.length,
400
- 0,
401
- );
402
- return [
403
- `REHEARSAL STACK CLEANUP — ${result.mode.toUpperCase()}`,
404
- ...plan.targets.flatMap((target) => [
405
- "",
406
- `${target.name} — ${target.plan.project}`,
407
- target.plan.baselines.available
408
- ? ` ${target.plan.baselines.removed.length ? "→" : "✓"} ${formatCount(target.plan.baselines.removed.length, "old baseline generation")} selected; keeping ${target.plan.baselines.retained.length}`
409
- : " ○ No active baseline found",
410
- !target.plan.runtime.detected
411
- ? " ✓ No runtime found"
412
- : target.plan.runtime.included
413
- ? ` → Runtime ${target.plan.projectId} selected`
414
- : ` ○ Runtime ${target.plan.projectId} preserved`,
415
- ...(target.plan.images.requested
416
- ? target.plan.images.inspected
417
- ? target.plan.images.candidates.length
418
- ? [
419
- ` → ${formatCount(target.plan.images.candidates.length, "older unused Supabase image")} selected`,
420
- ...target.plan.images.candidates.flatMap((image) =>
421
- image.tags.map((tag) => ` ${tag}`),
422
- ),
423
- ]
424
- : [" ✓ No older unused Supabase images found"]
425
- : [" ! Docker is unavailable; shared images were not inspected"]
426
- : []),
427
- ]),
428
- "",
429
- ...(result.mode === "preview"
430
- ? selectedCount
431
- ? [
432
- "Nothing has been removed.",
433
- `Combined cleanup set: ${plan.digest.slice(0, 12)}`,
434
- `Exact confirmation: --confirm-cleanup=${plan.digest}`,
435
- "Review every target above, then rerun with --write and this exact confirmation.",
436
- ]
437
- : ["Nothing has been removed, and nothing is currently selected."]
438
- : result.applied.targets.map(
439
- (target) =>
440
- `${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")}.`,
441
- )),
442
- ].join("\n");
443
- }
444
- const imageBytes = plan.images.candidates.reduce(
445
- (total, image) => total + image.bytes,
446
- 0,
447
- );
448
- const dockerImages = plan.docker.resources.find(
449
- (resource) => resource.Type === "Images",
450
- );
451
- const selectedCount =
452
- plan.baselines.removed.length +
453
- (plan.runtime.included && plan.runtime.detected ? 1 : 0) +
454
- plan.images.candidates.length;
455
- return [
456
- `REHEARSAL CLEANUP — ${result.mode.toUpperCase()}`,
457
- `Project: ${plan.project}`,
458
- ...(dockerImages
459
- ? [
460
- `Docker images: ${dockerImages.Size}; ${dockerImages.Reclaimable} reclaimable across Docker`,
461
- ]
462
- : ["Docker usage: unavailable"]),
463
- ...(plan.docker.disk
464
- ? [
465
- `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)`,
466
- ]
467
- : []),
468
- "",
469
- "Project-owned files",
470
- plan.baselines.available
471
- ? ` ${plan.baselines.removed.length ? "→" : "✓"} ${formatCount(plan.baselines.removed.length, "old baseline generation")} selected; keeping ${plan.baselines.retained.length}`
472
- : " ○ No active baseline found",
473
- "",
474
- "Disposable runtime",
475
- !plan.runtime.detected
476
- ? " ✓ No runtime found"
477
- : plan.runtime.included
478
- ? " → Current project runtime selected"
479
- : " ○ Current project runtime preserved (add --include-runtime to select it)",
480
- "",
481
- "Shared Docker images",
482
- !plan.images.requested
483
- ? " ○ Not inspected (add --include-images to inspect older unused Supabase images)"
484
- : !plan.images.inspected
485
- ? " ! Docker is unavailable; images could not be inspected"
486
- : plan.images.candidates.length
487
- ? ` → ${formatCount(plan.images.candidates.length, "older unused Supabase image")} selected; approximately ${formatBytes(imageBytes)}`
488
- : " ✓ No older unused Supabase images found",
489
- ...(plan.images.candidates.length
490
- ? plan.images.candidates.flatMap((image) =>
491
- image.tags.map((tag) => ` ${tag}`),
492
- )
493
- : []),
494
- "",
495
- ...(result.mode === "preview"
496
- ? selectedCount
497
- ? [
498
- "Nothing has been removed.",
499
- `Cleanup set: ${plan.digest.slice(0, 12)}`,
500
- `Exact confirmation: --confirm-cleanup=${plan.digest}`,
501
- "Review this list, then rerun the same command with --write and the exact confirmation above.",
502
- ]
503
- : [
504
- "Nothing has been removed, and nothing is currently selected.",
505
- "Use --include-runtime or --include-images only when you want those shared resources considered.",
506
- ]
507
- : [
508
- `Removed ${formatCount(result.applied.baselines.removed.length, "old baseline generation")}.`,
509
- result.applied.runtimeRemoved
510
- ? "Removed this project's disposable runtime and volumes."
511
- : "Preserved this project's disposable runtime.",
512
- `Removed ${formatCount(result.applied.imagesRemoved.length, "unused image tag")}.`,
513
- ]),
514
- ].join("\n");
515
- };
516
-
517
- export const renderSourceAccessPlan = (plan) =>
518
- [
519
- "SOURCE ACCESS — PREVIEW",
520
- "",
521
- `Target fingerprint: ${plan.review.targetFingerprint}`,
522
- plan.review.reader.mode === "managed"
523
- ? `Managed temporary reader: ${plan.review.reader.role} (${plan.review.reader.validForMinutes} minutes)`
524
- : `Externally managed reader: ${plan.review.reader.role} (maximum ${plan.review.reader.maximumValidForMinutes} minutes remaining)`,
525
- `Source changes by Rehearsal: ${plan.review.reader.sourceChanges ? "export views and temporary roles" : "none"}`,
526
- `Export schema: ${plan.review.exportSchema}`,
527
- ...plan.review.relations.map(
528
- (relation) =>
529
- ` → ${relation.source.schema}.${relation.source.table} → ${relation.view}: ${relation.columns.join(", ")} (${relation.rowScope.kind})`,
530
- ),
531
- ...(plan.review.assets.length
532
- ? plan.review.assets.map(
533
- (asset) =>
534
- ` → Storage ${asset.bucket}/${
535
- asset.prefix ??
536
- `[private prefix from ${asset.prefixEnvironmentVariable}]`
537
- } (${asset.rights})`,
538
- )
539
- : [" ○ No source assets declared"]),
540
- "",
541
- "Deny checks",
542
- ...plan.review.denyChecks.map((check) => ` ✓ ${check}`),
543
- "",
544
- "No source changes have been made.",
545
- `Exact confirmation: --confirm-source-access=${plan.digest}`,
546
- ].join("\n");
547
-
548
- export const renderRefreshWorkflow = ({
549
- mode,
550
- plan,
551
- refreshed,
552
- runtime,
553
- cleanup,
554
- }) =>
555
- [
556
- `DATABASE COPY REFRESH — ${mode.toUpperCase()}`,
557
- "",
558
- `Current baseline: ${plan.review.currentBaseline}`,
559
- `Source access expires: ${plan.review.source.readerExpiresAt}`,
560
- `Runtime targets reset: ${plan.review.runtimeTargets.join(", ")}`,
561
- `Baseline retention: ${formatCount(plan.review.retention.generations, "generation")}`,
562
- ...(plan.review.retention.removeAfterReplacement.length
563
- ? [
564
- "Old generations removed after success:",
565
- ...plan.review.retention.removeAfterReplacement.map(
566
- (generation) => ` → ${generation}`,
567
- ),
568
- ]
569
- : ["Old generations removed after success: none"]),
570
- "",
571
- ...plan.review.steps.map((step, index) => ` ${index + 1}. ${step}`),
572
- "",
573
- ...(mode === "preview"
574
- ? [
575
- "Nothing has changed. The current baseline and runtime remain intact.",
576
- `Exact confirmation: --confirm-refresh=${plan.digest}`,
577
- ]
578
- : [
579
- `Activated baseline: ${refreshed.generationId}`,
580
- `Runtime reset: ${runtime.targets?.length ?? 1} target(s)`,
581
- cleanup.state === "complete"
582
- ? `Cleanup complete: ${formatCount(cleanup.removed.length, "old generation")} removed.`
583
- : `Cleanup incomplete: ${formatCount(cleanup.remaining, "old generation")} still eligible. Run rehearsal cleanup.`,
584
- "",
585
- "Next: retire source access when no other refresh is needed, then run a rehearsal.",
586
- ]),
587
- ].join("\n");
588
-
589
- export const renderSourceRetirement = ({ mode, plan }) =>
590
- [
591
- `SOURCE ACCESS RETIREMENT — ${mode.toUpperCase()}`,
592
- `Target fingerprint: ${plan.review.targetFingerprint}`,
593
- `Reader: ${plan.review.readerRole}`,
594
- `Export schema: ${plan.review.exportSchema}`,
595
- ...(plan.review.accessMode === "managed"
596
- ? plan.review.views.map((view) => ` → remove view ${view}`)
597
- : [
598
- " → remove only Rehearsal's local credential and receipt",
599
- " ✓ preserve the provider-owned reader and export views",
600
- ]),
601
- "",
602
- ...(mode === "preview"
603
- ? [
604
- "Nothing has been removed.",
605
- `Exact confirmation: --confirm-source-retirement=${plan.digest}`,
606
- ]
607
- : [
608
- plan.review.accessMode === "managed"
609
- ? "The exact reader, export views, and local credential files were retired."
610
- : "Rehearsal's local credential and receipt were removed. Provider-owned database resources were preserved.",
611
- ]),
612
- ].join("\n");
613
-
614
- export const renderIdentityPlan = ({ mode, plan }) =>
615
- [
616
- `LOCAL IDENTITY — ${mode.toUpperCase()}`,
617
- `Identity: ${plan.review.name}`,
618
- `Matcher: ${plan.review.matcher.type}`,
619
- plan.review.matcher.type === "verified-email"
620
- ? `Providers: ${plan.review.matcher.providers.join(", ")}`
621
- : `Provider: ${plan.review.matcher.provider}`,
622
- plan.review.matcher.type === "verified-email"
623
- ? `Approved email receipt: ${plan.review.matcher.approvedEmailSha256}`
624
- : `Approved subject receipt: ${plan.review.matcher.approvedSubjectSha256}`,
625
- `Relational references: ${plan.review.references.length}`,
626
- `Nested JSON references: ${plan.review.jsonReferences.length}`,
627
- `Signup defaults: ${plan.review.signupDefaults.length}`,
628
- `Storage path references: ${plan.review.pathReferences.length}`,
629
- `Asset scopes: ${plan.review.assets.length}`,
630
- `Token hook assertion: ${plan.review.tokenHook ? "configured" : "not configured"}`,
631
- "",
632
- ...(mode === "preview"
633
- ? [
634
- "No local account was changed.",
635
- `Exact confirmation: --confirm-identity=${plan.digest}`,
636
- ]
637
- : ["The verified local identity now owns the declared copied graph."]),
638
- ].join("\n");