@sixb/cli 0.1.20 → 0.1.22

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 (130) hide show
  1. package/README.md +21 -4
  2. package/dist/commands/api.d.ts.map +1 -1
  3. package/dist/commands/app.d.ts.map +1 -1
  4. package/dist/commands/build.d.ts.map +1 -1
  5. package/dist/commands/check.d.ts.map +1 -1
  6. package/dist/commands/db-migrate.d.ts.map +1 -1
  7. package/dist/commands/deploy.d.ts.map +1 -1
  8. package/dist/commands/desktop.d.ts +15 -0
  9. package/dist/commands/desktop.d.ts.map +1 -0
  10. package/dist/commands/dev-runner.d.ts +4 -0
  11. package/dist/commands/dev-runner.d.ts.map +1 -1
  12. package/dist/commands/dev.d.ts.map +1 -1
  13. package/dist/commands/init.d.ts.map +1 -1
  14. package/dist/commands/lake-check.d.ts.map +1 -1
  15. package/dist/commands/lake-cleanup.d.ts +2 -0
  16. package/dist/commands/lake-cleanup.d.ts.map +1 -1
  17. package/dist/commands/login.d.ts.map +1 -1
  18. package/dist/commands/logout.d.ts.map +1 -1
  19. package/dist/commands/orchestrator.d.ts.map +1 -1
  20. package/dist/commands/profile.d.ts.map +1 -1
  21. package/dist/commands/rules.d.ts.map +1 -1
  22. package/dist/commands/scheduler.d.ts.map +1 -1
  23. package/dist/commands/service-account.d.ts.map +1 -1
  24. package/dist/commands/status.d.ts.map +1 -1
  25. package/dist/commands/token.d.ts.map +1 -1
  26. package/dist/commands/typegen.d.ts.map +1 -1
  27. package/dist/commands/worker-group.d.ts +2 -0
  28. package/dist/commands/worker-group.d.ts.map +1 -1
  29. package/dist/commands/worker.d.ts +2 -0
  30. package/dist/commands/worker.d.ts.map +1 -1
  31. package/dist/lib/command-line.d.ts +22 -2
  32. package/dist/lib/command-line.d.ts.map +1 -1
  33. package/dist/lib/deploy-release.d.ts +3 -1
  34. package/dist/lib/deploy-release.d.ts.map +1 -1
  35. package/dist/lib/desktop.d.ts +26 -0
  36. package/dist/lib/desktop.d.ts.map +1 -0
  37. package/dist/lib/dev-messages.d.ts +43 -0
  38. package/dist/lib/dev-messages.d.ts.map +1 -0
  39. package/dist/lib/dev-supervisor.d.ts +27 -0
  40. package/dist/lib/dev-supervisor.d.ts.map +1 -1
  41. package/dist/lib/open-url.d.ts +3 -0
  42. package/dist/lib/open-url.d.ts.map +1 -0
  43. package/dist/lib/role-lifecycle.d.ts.map +1 -1
  44. package/dist/lib/runtime.d.ts +10 -0
  45. package/dist/lib/runtime.d.ts.map +1 -1
  46. package/dist/lib/worker-concurrency.d.ts +11 -0
  47. package/dist/lib/worker-concurrency.d.ts.map +1 -1
  48. package/dist/lib/worker-registry.d.ts +2 -0
  49. package/dist/lib/worker-registry.d.ts.map +1 -1
  50. package/dist/ui/deploy-screens.d.ts +48 -0
  51. package/dist/ui/deploy-screens.d.ts.map +1 -0
  52. package/dist/ui/index.d.ts +28 -233
  53. package/dist/ui/index.d.ts.map +1 -1
  54. package/dist/ui/layout.d.ts +65 -0
  55. package/dist/ui/layout.d.ts.map +1 -0
  56. package/dist/ui/live/ansi.d.ts +8 -0
  57. package/dist/ui/live/ansi.d.ts.map +1 -0
  58. package/dist/ui/live/can-run-live.d.ts +6 -0
  59. package/dist/ui/live/can-run-live.d.ts.map +1 -0
  60. package/dist/ui/live/components.d.ts +17 -0
  61. package/dist/ui/live/components.d.ts.map +1 -0
  62. package/dist/ui/live/deploy.d.ts +22 -0
  63. package/dist/ui/live/deploy.d.ts.map +1 -0
  64. package/dist/ui/live/dev.d.ts +47 -0
  65. package/dist/ui/live/dev.d.ts.map +1 -0
  66. package/dist/ui/live/prompt.d.ts +30 -0
  67. package/dist/ui/live/prompt.d.ts.map +1 -0
  68. package/dist/ui/live/session.d.ts +27 -0
  69. package/dist/ui/live/session.d.ts.map +1 -0
  70. package/dist/ui/screens.d.ts +136 -0
  71. package/dist/ui/screens.d.ts.map +1 -0
  72. package/dist/ui/theme.d.ts +58 -0
  73. package/dist/ui/theme.d.ts.map +1 -0
  74. package/package.json +21 -19
  75. package/src/commands/{api.tsx → api.ts} +18 -27
  76. package/src/commands/{app.tsx → app.ts} +14 -18
  77. package/src/commands/build.ts +70 -0
  78. package/src/commands/{check.tsx → check.ts} +74 -19
  79. package/src/commands/db-migrate.ts +32 -0
  80. package/src/commands/{deploy.tsx → deploy.ts} +109 -102
  81. package/src/commands/desktop.ts +71 -0
  82. package/src/commands/{dev-runner.tsx → dev-runner.ts} +67 -33
  83. package/src/commands/{init.tsx → init.ts} +19 -8
  84. package/src/commands/lake-check.ts +36 -0
  85. package/src/commands/{lake-cleanup.tsx → lake-cleanup.ts} +24 -8
  86. package/src/commands/{login.tsx → login.ts} +36 -30
  87. package/src/commands/{logout.tsx → logout.ts} +5 -5
  88. package/src/commands/{orchestrator.tsx → orchestrator.ts} +15 -28
  89. package/src/commands/{profile.tsx → profile.ts} +38 -19
  90. package/src/commands/{rules.tsx → rules.ts} +15 -24
  91. package/src/commands/{scheduler.tsx → scheduler.ts} +14 -27
  92. package/src/commands/{service-account.tsx → service-account.ts} +37 -39
  93. package/src/commands/{status.tsx → status.ts} +8 -8
  94. package/src/commands/{token.tsx → token.ts} +19 -20
  95. package/src/commands/typegen.ts +18 -0
  96. package/src/commands/{worker-group.tsx → worker-group.ts} +40 -29
  97. package/src/commands/{worker.tsx → worker.ts} +30 -22
  98. package/src/index.tsx +22 -1
  99. package/src/lib/command-line.ts +108 -57
  100. package/src/lib/deploy-release.ts +17 -1
  101. package/src/lib/desktop.ts +52 -0
  102. package/src/lib/dev-messages.ts +44 -0
  103. package/src/lib/dev-supervisor.ts +132 -12
  104. package/src/lib/open-url.ts +15 -0
  105. package/src/lib/role-lifecycle.ts +2 -3
  106. package/src/lib/runtime.ts +21 -0
  107. package/src/lib/worker-concurrency.ts +31 -0
  108. package/src/lib/worker-registry.ts +4 -0
  109. package/src/ui/README.md +54 -0
  110. package/src/ui/deploy-screens.ts +360 -0
  111. package/src/ui/index.ts +158 -0
  112. package/src/ui/layout.ts +245 -0
  113. package/src/ui/live/ansi.ts +103 -0
  114. package/src/ui/live/can-run-live.ts +9 -0
  115. package/src/ui/live/components.tsx +81 -0
  116. package/src/ui/live/deploy.tsx +170 -0
  117. package/src/ui/live/dev.tsx +522 -0
  118. package/src/ui/live/prompt.tsx +205 -0
  119. package/src/ui/live/session.ts +103 -0
  120. package/src/ui/screens.ts +490 -0
  121. package/src/ui/theme.ts +122 -0
  122. package/dist/lib/role-view.d.ts +0 -21
  123. package/dist/lib/role-view.d.ts.map +0 -1
  124. package/src/commands/build.tsx +0 -65
  125. package/src/commands/db-migrate.tsx +0 -30
  126. package/src/commands/lake-check.tsx +0 -20
  127. package/src/commands/typegen.tsx +0 -18
  128. package/src/lib/role-view.ts +0 -49
  129. package/src/ui/index.tsx +0 -1363
  130. /package/src/commands/{dev.tsx → dev.ts} +0 -0
package/src/ui/index.tsx DELETED
@@ -1,1363 +0,0 @@
1
- import type {
2
- DeployAccessKey,
3
- DeployCheck,
4
- DeployCommand,
5
- DeployRelease,
6
- DeployStatus,
7
- } from "@sixb/core/deploy"
8
- import { Box, render, Text } from "ink"
9
- import type React from "react"
10
- import { useEffect, useMemo, useState } from "react"
11
- import { CLI_EXAMPLES, type CliHelp, ROOT_HELP } from "../lib/command-line"
12
- import { errorMessage, errorRemediation } from "../lib/errors"
13
-
14
- // ─── Primitives ──────────────────────────────────────────────────────────────
15
-
16
- export async function renderStatic(view: React.ReactNode) {
17
- const app = render(<Box flexDirection="column">{view}</Box>, { exitOnCtrlC: false })
18
- // Let ink paint, then tear down explicitly. useApp().exit() + waitUntilExit()
19
- // stopped resolving in ink v6, which caused callers (e.g. `sixb worker`) to
20
- // hang and never reach their `process.exit(1)`, masking failures with exit 0.
21
- await new Promise<void>((resolve) => setImmediate(resolve))
22
- app.unmount()
23
- }
24
-
25
- export function renderPersistent(view: React.ReactNode) {
26
- return render(view, { exitOnCtrlC: false })
27
- }
28
-
29
- /**
30
- * Renders a caught failure the one way the CLI renders failures, so a remediation carried on
31
- * the error reaches the terminal without each caller remembering to pass it through.
32
- */
33
- export async function renderCliError(
34
- error: unknown,
35
- options: { readonly title?: string; readonly details?: readonly string[] } = {}
36
- ): Promise<void> {
37
- await renderStatic(
38
- <ErrorView
39
- {...(options.title ? { title: options.title } : {})}
40
- message={errorMessage(error)}
41
- {...(errorRemediation(error) ? { remediation: errorRemediation(error) } : {})}
42
- {...(options.details ? { details: options.details } : {})}
43
- />
44
- )
45
- }
46
-
47
- // The entrypoint and the app role render through these rather than JSX of their own: a module
48
- // with JSX loads React as soon as it is evaluated, and `app` loads neither React nor Ink outside a
49
- // terminal.
50
-
51
- export async function renderVersion(version: string): Promise<void> {
52
- await renderStatic(<VersionView version={version} />)
53
- }
54
-
55
- /** Root or command help, after the usage error that led to it when there is one. */
56
- export async function renderHelp(help: CliHelp, usageError?: string): Promise<void> {
57
- await renderStatic(
58
- help.path.length === 0 ? (
59
- <HelpView errorMessage={usageError} />
60
- ) : (
61
- <CommandHelpView help={help} errorMessage={usageError} />
62
- )
63
- )
64
- }
65
-
66
- export interface RoleStartupPanel {
67
- started(view: {
68
- readonly title: string
69
- readonly name: string
70
- readonly serviceName: string
71
- readonly items: KeyValueItem[]
72
- }): void
73
- unmount(): void
74
- }
75
-
76
- /** A long-running role's loading panel, replaced by its started view. */
77
- export function renderRoleStartup(loading: {
78
- readonly title: string
79
- readonly subtitle: string
80
- readonly status: string
81
- }): RoleStartupPanel {
82
- const app = renderPersistent(<LoadingView {...loading} />)
83
- return {
84
- started(view) {
85
- app.rerender(<RoleView {...view} />)
86
- },
87
- unmount() {
88
- app.unmount()
89
- },
90
- }
91
- }
92
-
93
- function SectionTitle({ children }: { children: React.ReactNode }) {
94
- return (
95
- <Text color="cyan" bold>
96
- {children}
97
- </Text>
98
- )
99
- }
100
-
101
- function Spacer() {
102
- return <Text> </Text>
103
- }
104
-
105
- function padLabel(label: string, width: number) {
106
- if (label.length >= width) return `${label} `
107
- return label.padEnd(width, " ")
108
- }
109
-
110
- export type KeyValueItem = { label: string; value: string }
111
-
112
- function isUrl(value: string): boolean {
113
- return /^(https?|wss?):\/\//.test(value)
114
- }
115
-
116
- function KeyValueList({
117
- items,
118
- labelWidth,
119
- }: {
120
- items: readonly KeyValueItem[]
121
- labelWidth?: number
122
- }) {
123
- const resolvedWidth = Math.max(labelWidth ?? 0, ...items.map((item) => item.label.length))
124
-
125
- return (
126
- <Box flexDirection="column">
127
- {items.map((item) => (
128
- <Text key={`${item.label}:${item.value}`}>
129
- <Text dimColor>{padLabel(item.label, resolvedWidth + 2)}</Text>
130
- <Text color={isUrl(item.value) ? "cyan" : undefined}>{item.value}</Text>
131
- </Text>
132
- ))}
133
- </Box>
134
- )
135
- }
136
-
137
- function Table({
138
- headers,
139
- rows,
140
- }: {
141
- headers: readonly string[]
142
- rows: readonly (readonly string[])[]
143
- }) {
144
- const widths = headers.map((header, index) =>
145
- Math.max(header.length, ...rows.map((row) => row[index]?.length ?? 0))
146
- )
147
-
148
- return (
149
- <Box flexDirection="column">
150
- <Text>
151
- {headers.map((header, index) => (
152
- <Text key={`${index}:${header}`} bold>
153
- {header.padEnd(widths[index] ?? header.length)}
154
- {index === headers.length - 1 ? "" : " "}
155
- </Text>
156
- ))}
157
- </Text>
158
- <Text dimColor>{widths.map((width) => "-".repeat(width)).join(" ")}</Text>
159
- {rows.map((row, rowIndex) => (
160
- <Text key={`${rowIndex}:${row.join(":")}`}>
161
- {row.map((value, index) => (
162
- <Text key={`${index}:${value}`}>
163
- {value.padEnd(widths[index] ?? value.length)}
164
- {index === row.length - 1 ? "" : " "}
165
- </Text>
166
- ))}
167
- </Text>
168
- ))}
169
- </Box>
170
- )
171
- }
172
-
173
- function Panel({
174
- title,
175
- meta,
176
- borderColor = "gray",
177
- children,
178
- }: {
179
- title: string
180
- meta?: React.ReactNode
181
- borderColor?: string
182
- children: React.ReactNode
183
- }) {
184
- return (
185
- <Box flexDirection="column" borderStyle="round" borderColor={borderColor} paddingX={1}>
186
- <Box justifyContent="space-between">
187
- <Text bold>{title}</Text>
188
- {meta ? <Box>{meta}</Box> : null}
189
- </Box>
190
- <Spacer />
191
- {children}
192
- </Box>
193
- )
194
- }
195
-
196
- export function KeyValueResultView({
197
- title,
198
- subtitle,
199
- items,
200
- titleColor = "green",
201
- message,
202
- }: {
203
- title: string
204
- subtitle?: string
205
- items: readonly KeyValueItem[]
206
- titleColor?: string
207
- message?: string
208
- }) {
209
- return (
210
- <Box flexDirection="column">
211
- <Text color={titleColor} bold>
212
- {title}
213
- </Text>
214
- {subtitle ? <Text dimColor>{subtitle}</Text> : null}
215
- <Spacer />
216
- <KeyValueList items={items} />
217
- {message ? (
218
- <>
219
- <Spacer />
220
- <Text dimColor>{message}</Text>
221
- </>
222
- ) : null}
223
- </Box>
224
- )
225
- }
226
-
227
- export function TableResultView({
228
- title,
229
- subtitle,
230
- headers,
231
- rows,
232
- emptyMessage,
233
- }: {
234
- title: string
235
- subtitle?: string
236
- headers: readonly string[]
237
- rows: readonly (readonly string[])[]
238
- emptyMessage: string
239
- }) {
240
- return (
241
- <Box flexDirection="column">
242
- <Text color="green" bold>
243
- {title}
244
- </Text>
245
- {subtitle ? <Text dimColor>{subtitle}</Text> : null}
246
- <Spacer />
247
- {rows.length > 0 ? (
248
- <Table headers={headers} rows={rows} />
249
- ) : (
250
- <Text dimColor>{emptyMessage}</Text>
251
- )}
252
- </Box>
253
- )
254
- }
255
-
256
- export function SecretResultView({
257
- title,
258
- subtitle,
259
- items,
260
- secretLabel = "Token",
261
- secret,
262
- message = "Store this token now. Sixb will not show it again.",
263
- }: {
264
- title: string
265
- subtitle?: string
266
- items: readonly KeyValueItem[]
267
- secretLabel?: string
268
- secret: string
269
- message?: string
270
- }) {
271
- return (
272
- <Box flexDirection="column">
273
- <Text color="green" bold>
274
- {title}
275
- </Text>
276
- {subtitle ? <Text dimColor>{subtitle}</Text> : null}
277
- <Spacer />
278
- <KeyValueList items={items} />
279
- <Spacer />
280
- <Panel title={secretLabel} borderColor="yellow">
281
- <Text>{secret}</Text>
282
- </Panel>
283
- {message ? (
284
- <>
285
- <Spacer />
286
- <Text dimColor>{message}</Text>
287
- </>
288
- ) : null}
289
- </Box>
290
- )
291
- }
292
-
293
- function ServicePanel({ name, items }: { name: string; items: KeyValueItem[] }) {
294
- return (
295
- <Box flexDirection="column">
296
- <Text bold>{name}</Text>
297
- <KeyValueList items={items} labelWidth={10} />
298
- </Box>
299
- )
300
- }
301
-
302
- /**
303
- * What the role did to the storage schema at startup, worded the same way by every
304
- * role. Absent when there was nothing to report, so a runtime without migrators does
305
- * not grow a panel that says nothing.
306
- */
307
- function StoragePanel({ summary }: { summary?: string | null }) {
308
- if (!summary) return null
309
-
310
- return (
311
- <>
312
- <Spacer />
313
- <ServicePanel name="Storage" items={[{ label: "Schema", value: summary }]} />
314
- </>
315
- )
316
- }
317
-
318
- function BulletList({ items, dim = false }: { items: readonly string[]; dim?: boolean }) {
319
- return (
320
- <Box flexDirection="column">
321
- {items.map((item, index) => (
322
- <Text key={`${index}:${item}`} dimColor={dim}>
323
- - {item}
324
- </Text>
325
- ))}
326
- </Box>
327
- )
328
- }
329
-
330
- function Spinner({ label }: { label: string }) {
331
- const frames = useMemo(() => ["|", "/", "-", "\\"], [])
332
- const [index, setIndex] = useState(0)
333
-
334
- useEffect(() => {
335
- const timer = setInterval(() => {
336
- setIndex((current) => (current + 1) % frames.length)
337
- }, 80)
338
-
339
- return () => clearInterval(timer)
340
- }, [frames.length])
341
-
342
- return (
343
- <Text>
344
- <Text color="cyan">{frames[index]}</Text> {label}
345
- </Text>
346
- )
347
- }
348
-
349
- // ─── Views ───────────────────────────────────────────────────────────────────
350
-
351
- export function LoadingView({
352
- title,
353
- subtitle,
354
- status,
355
- }: {
356
- title: string
357
- subtitle?: string
358
- status: string
359
- }) {
360
- return (
361
- <Box flexDirection="column">
362
- <Text color="green" bold>
363
- {title}
364
- </Text>
365
- {subtitle ? <Text dimColor>{subtitle}</Text> : null}
366
- <Spacer />
367
- <Text dimColor>Booting services</Text>
368
- <Spinner label={status} />
369
- </Box>
370
- )
371
- }
372
-
373
- export function HelpView({ errorMessage }: { errorMessage?: string }) {
374
- return (
375
- <Box flexDirection="column">
376
- <Text color="cyan" bold>
377
- sixb
378
- </Text>
379
- <Text dimColor>Real-time digital twin framework</Text>
380
- {errorMessage ? (
381
- <>
382
- <Spacer />
383
- <Text color="red">{errorMessage}</Text>
384
- </>
385
- ) : null}
386
- <Spacer />
387
- <SectionTitle>Usage</SectionTitle>
388
- <Text> {ROOT_HELP.usage}</Text>
389
- <Spacer />
390
- <SectionTitle>Commands</SectionTitle>
391
- <KeyValueList labelWidth={22} items={ROOT_HELP.commands} />
392
- <Spacer />
393
- <SectionTitle>Options</SectionTitle>
394
- <KeyValueList labelWidth={22} items={ROOT_HELP.options} />
395
- <Spacer />
396
- <SectionTitle>Examples</SectionTitle>
397
- <BulletList dim items={CLI_EXAMPLES} />
398
- </Box>
399
- )
400
- }
401
-
402
- export function CommandHelpView({ help, errorMessage }: { help: CliHelp; errorMessage?: string }) {
403
- return (
404
- <Box flexDirection="column">
405
- <Text color="cyan" bold>
406
- {help.path.length > 0 ? help.path.join(" ") : "sixb"}
407
- </Text>
408
- <Text dimColor>{help.summary}</Text>
409
- {errorMessage ? (
410
- <>
411
- <Spacer />
412
- <Text color="red">{errorMessage}</Text>
413
- </>
414
- ) : null}
415
- <Spacer />
416
- <SectionTitle>Usage</SectionTitle>
417
- <Text> {help.usage}</Text>
418
- {help.commands.length > 0 ? (
419
- <>
420
- <Spacer />
421
- <SectionTitle>Commands</SectionTitle>
422
- <KeyValueList items={help.commands} />
423
- </>
424
- ) : null}
425
- {help.options.length > 0 ? (
426
- <>
427
- <Spacer />
428
- <SectionTitle>Options</SectionTitle>
429
- <KeyValueList items={help.options} />
430
- </>
431
- ) : null}
432
- </Box>
433
- )
434
- }
435
-
436
- export function VersionView({ version }: { version: string }) {
437
- return <Text>{version}</Text>
438
- }
439
-
440
- export function ErrorView({
441
- title = "Error",
442
- message,
443
- remediation,
444
- details = [],
445
- }: {
446
- title?: string
447
- message: string
448
- /** What to do next. Rendered apart from the diagnosis, not appended to it. */
449
- remediation?: string
450
- details?: readonly string[]
451
- }) {
452
- return (
453
- <Box flexDirection="column">
454
- <Text color="red" bold>
455
- {title}
456
- </Text>
457
- <Spacer />
458
- <Panel title="Failure" borderColor="red">
459
- <Text>{message}</Text>
460
- </Panel>
461
- {remediation ? (
462
- <>
463
- <Spacer />
464
- <SectionTitle>Try this</SectionTitle>
465
- <Text>{remediation}</Text>
466
- </>
467
- ) : null}
468
- {details.length > 0 ? (
469
- <>
470
- <Spacer />
471
- <SectionTitle>Details</SectionTitle>
472
- <BulletList items={details} />
473
- </>
474
- ) : null}
475
- </Box>
476
- )
477
- }
478
-
479
- export function DevView({
480
- name,
481
- apiUrl,
482
- apiDocsUrl,
483
- wsUrl,
484
- appUrl,
485
- workers = [],
486
- warnings = [],
487
- }: {
488
- name: string
489
- apiUrl: string
490
- apiDocsUrl: string
491
- wsUrl: string
492
- /** `null` when the app could not start; a warning says why. */
493
- appUrl: string | null
494
- workers?: readonly { readonly type: string; readonly concurrency: number }[]
495
- warnings?: readonly string[]
496
- }) {
497
- const serverItems: KeyValueItem[] = [
498
- { label: "API", value: apiUrl },
499
- { label: "API docs", value: apiDocsUrl },
500
- { label: "Events", value: wsUrl },
501
- ]
502
-
503
- return (
504
- <Box flexDirection="column">
505
- <Text bold>sixb dev</Text>
506
- <Text dimColor>{name}</Text>
507
- <Spacer />
508
- <ServicePanel name="App" items={[{ label: "URL", value: appUrl ?? "not running" }]} />
509
- <Spacer />
510
- <ServicePanel name="Server" items={serverItems} />
511
- {workers.length > 0 ? (
512
- <>
513
- <Spacer />
514
- <ServicePanel
515
- name="Workers"
516
- items={workers.map((worker) => ({
517
- label: worker.type,
518
- value: `running · concurrency ${worker.concurrency}`,
519
- }))}
520
- />
521
- </>
522
- ) : null}
523
- {warnings.length > 0 ? (
524
- <>
525
- <Spacer />
526
- <Text color="yellow" bold>
527
- Warnings
528
- </Text>
529
- <BulletList items={warnings} />
530
- </>
531
- ) : null}
532
- <Spacer />
533
- <Text dimColor>ctrl+c to stop</Text>
534
- </Box>
535
- )
536
- }
537
-
538
- export function WorkerView({
539
- name,
540
- workerId,
541
- concurrency,
542
- storage,
543
- warnings = [],
544
- }: {
545
- name: string
546
- workerId: string
547
- concurrency: number
548
- storage?: string | null
549
- warnings?: readonly string[]
550
- }) {
551
- return (
552
- <Box flexDirection="column">
553
- <Text color="green" bold>
554
- Sixb worker started
555
- </Text>
556
- <Text dimColor>{name}</Text>
557
- <Spacer />
558
- <ServicePanel
559
- name="Worker"
560
- items={[
561
- { label: "ID", value: workerId },
562
- { label: "Concurrency", value: String(concurrency) },
563
- ]}
564
- />
565
- <StoragePanel summary={storage} />
566
- {warnings.length > 0 ? (
567
- <>
568
- <Spacer />
569
- <SectionTitle>Warnings</SectionTitle>
570
- <BulletList items={warnings} />
571
- </>
572
- ) : null}
573
- <Spacer />
574
- <Text dimColor>Press Ctrl+C to stop</Text>
575
- </Box>
576
- )
577
- }
578
-
579
- export function WorkerGroupView({
580
- name,
581
- workers,
582
- storage,
583
- warnings = [],
584
- }: {
585
- name: string
586
- workers: readonly { readonly type: string; readonly concurrency: number }[]
587
- storage?: string | null
588
- warnings?: readonly string[]
589
- }) {
590
- return (
591
- <Box flexDirection="column">
592
- <Text color="green" bold>
593
- Sixb worker group started
594
- </Text>
595
- <Text dimColor>{name}</Text>
596
- <Spacer />
597
- <ServicePanel
598
- name="Workers"
599
- items={workers.map((worker) => ({
600
- label: worker.type,
601
- value: `running · concurrency ${worker.concurrency}`,
602
- }))}
603
- />
604
- <StoragePanel summary={storage} />
605
- {warnings.length > 0 ? (
606
- <>
607
- <Spacer />
608
- <SectionTitle>Warnings</SectionTitle>
609
- <BulletList items={warnings} />
610
- </>
611
- ) : null}
612
- <Spacer />
613
- <Text dimColor>Press Ctrl+C to stop</Text>
614
- </Box>
615
- )
616
- }
617
-
618
- export function RoleView({
619
- title,
620
- name,
621
- serviceName,
622
- items,
623
- storage,
624
- warnings = [],
625
- }: {
626
- title: string
627
- name: string
628
- serviceName: string
629
- items: KeyValueItem[]
630
- storage?: string | null
631
- warnings?: readonly string[]
632
- }) {
633
- return (
634
- <Box flexDirection="column">
635
- <Text color="green" bold>
636
- {title}
637
- </Text>
638
- <Text dimColor>{name}</Text>
639
- <Spacer />
640
- <ServicePanel name={serviceName} items={items} />
641
- <StoragePanel summary={storage} />
642
- {warnings.length > 0 ? (
643
- <>
644
- <Spacer />
645
- <SectionTitle>Warnings</SectionTitle>
646
- <BulletList items={warnings} />
647
- </>
648
- ) : null}
649
- <Spacer />
650
- <Text dimColor>Press Ctrl+C to stop</Text>
651
- </Box>
652
- )
653
- }
654
-
655
- export function CheckView({
656
- projectId,
657
- storage,
658
- timeseries,
659
- broker,
660
- queues,
661
- projectValidation,
662
- ontology,
663
- warnings,
664
- }: {
665
- projectId: string
666
- storage: { ok: boolean; message?: string }
667
- timeseries: { ok: boolean; message?: string }
668
- broker: { ok: boolean; message?: string }
669
- queues: { ok: boolean; message?: string }
670
- projectValidation?: { ok: boolean; message?: string }
671
- ontology?: { enabled: boolean; source: string; errors: number; warnings: number }
672
- warnings: readonly string[]
673
- }) {
674
- const validation = projectValidation ?? { ok: true, message: "ok" }
675
- const ontologyOk = (ontology?.errors ?? 0) === 0
676
- const allOk = [storage, timeseries, broker, queues, validation].every((row) => row.ok)
677
- const healthy = allOk && ontologyOk
678
-
679
- // The message wins when there is one, pass or fail: a probe that succeeded still says which
680
- // provider answered and whether its schema is current.
681
- function statusText(row: { ok: boolean; message?: string }): string {
682
- return row.message ?? (row.ok ? "ok" : "failed")
683
- }
684
-
685
- function statusColor(ok: boolean): string {
686
- return ok ? "green" : "red"
687
- }
688
-
689
- return (
690
- <Box flexDirection="column">
691
- <Text color={healthy ? "green" : "red"} bold>
692
- {healthy ? "Sixb is healthy" : "Sixb has issues"}
693
- </Text>
694
- <Text dimColor>{projectId}</Text>
695
- <Spacer />
696
- <SectionTitle>Providers</SectionTitle>
697
- <Box flexDirection="column">
698
- <Text>
699
- <Text dimColor>{padLabel("Storage", 14)}</Text>
700
- <Text color={statusColor(storage.ok)}>{statusText(storage)}</Text>
701
- </Text>
702
- <Text>
703
- <Text dimColor>{padLabel("Timeseries", 14)}</Text>
704
- <Text color={statusColor(timeseries.ok)}>{statusText(timeseries)}</Text>
705
- </Text>
706
- <Text>
707
- <Text dimColor>{padLabel("Broker", 14)}</Text>
708
- <Text color={statusColor(broker.ok)}>{statusText(broker)}</Text>
709
- </Text>
710
- <Text>
711
- <Text dimColor>{padLabel("Queues", 14)}</Text>
712
- <Text color={statusColor(queues.ok)}>{statusText(queues)}</Text>
713
- </Text>
714
- <Text>
715
- <Text dimColor>{padLabel("Project", 14)}</Text>
716
- <Text color={statusColor(validation.ok)}>{statusText(validation)}</Text>
717
- </Text>
718
- </Box>
719
- {ontology ? (
720
- <>
721
- <Spacer />
722
- <SectionTitle>Ontology</SectionTitle>
723
- <KeyValueList
724
- items={[
725
- { label: "Source", value: ontology.source },
726
- { label: "Errors", value: String(ontology.errors) },
727
- { label: "Warnings", value: String(ontology.warnings) },
728
- ]}
729
- />
730
- </>
731
- ) : null}
732
- {warnings.length > 0 ? (
733
- <>
734
- <Spacer />
735
- <SectionTitle>Warnings</SectionTitle>
736
- <BulletList items={warnings} />
737
- </>
738
- ) : null}
739
- </Box>
740
- )
741
- }
742
-
743
- export function BuildView({ entry, outdir }: { entry: string; outdir: string }) {
744
- return (
745
- <Box flexDirection="column">
746
- <Text color="green" bold>
747
- Built
748
- </Text>
749
- <Spacer />
750
- <KeyValueList
751
- items={[
752
- { label: "Entry", value: entry },
753
- { label: "Output", value: outdir },
754
- ]}
755
- />
756
- </Box>
757
- )
758
- }
759
-
760
- export function TypegenView({
761
- path,
762
- objectTypes,
763
- skipped,
764
- written,
765
- }: {
766
- path: string
767
- objectTypes: number
768
- skipped: boolean
769
- written: boolean
770
- }) {
771
- return (
772
- <Box flexDirection="column">
773
- <Text color="green" bold>
774
- Ontology types {skipped ? "skipped" : written ? "generated" : "current"}
775
- </Text>
776
- <Spacer />
777
- <KeyValueList
778
- items={[
779
- { label: "Output", value: path },
780
- { label: "Object types", value: String(objectTypes) },
781
- ]}
782
- />
783
- </Box>
784
- )
785
- }
786
-
787
- export function DbMigrateView({
788
- projectId,
789
- status,
790
- applied = [],
791
- }: {
792
- projectId: string
793
- status: "migrated" | "current" | "skipped"
794
- /** Migration step ids this run applied, named so the output can be checked. */
795
- applied?: readonly string[]
796
- }) {
797
- return (
798
- <Box flexDirection="column">
799
- <Text color="green" bold>
800
- Database migrations complete
801
- </Text>
802
- <Text dimColor>{projectId}</Text>
803
- <Spacer />
804
- <KeyValueList items={[{ label: "Storage", value: status }]} />
805
- {applied.length > 0 ? (
806
- <>
807
- <Spacer />
808
- <SectionTitle>Applied</SectionTitle>
809
- <BulletList items={applied} />
810
- </>
811
- ) : null}
812
- </Box>
813
- )
814
- }
815
-
816
- export function LakeCheckView({ projectId, status }: { projectId: string; status: "ok" }) {
817
- return (
818
- <Box flexDirection="column">
819
- <Text color="green" bold>
820
- Lake definitions compatible
821
- </Text>
822
- <Text dimColor>{projectId}</Text>
823
- <Spacer />
824
- <KeyValueList items={[{ label: "Lake", value: status }]} />
825
- </Box>
826
- )
827
- }
828
-
829
- export function DeployReleaseView({
830
- release,
831
- configPath,
832
- }: {
833
- release: DeployRelease
834
- configPath: string
835
- }) {
836
- const steps = [
837
- { label: "build", commands: release.steps.build },
838
- { label: "before start", commands: release.steps.beforeStart },
839
- ]
840
- const labelWidth =
841
- Math.max(
842
- ...release.services.map((service) => service.name.length),
843
- ...steps.map((step) => step.label.length)
844
- ) + 2
845
- const originWidth = Math.max(
846
- 0,
847
- ...release.services.map((service) => service.http?.publicOrigin.length ?? 0)
848
- )
849
- const origins = new Set(
850
- release.services.flatMap((service) => (service.http ? [service.http.publicOrigin] : []))
851
- )
852
- // The public origins already show beside their services; list only what the config set.
853
- const env = Object.entries(release.env).filter(
854
- ([key, value]) => !(key.endsWith("_PUBLIC_ORIGIN") && origins.has(value))
855
- )
856
-
857
- return (
858
- <Box flexDirection="column">
859
- <Text color="green" bold>
860
- {release.name} · dry run
861
- </Text>
862
- <Text dimColor>
863
- {release.target.kind} {release.target.location} · {configPath}
864
- </Text>
865
- <Spacer />
866
- <SectionTitle>Services</SectionTitle>
867
- {release.services.map((service) => (
868
- <Box key={service.name}>
869
- <Box width={labelWidth} flexShrink={0}>
870
- <Text bold>{service.name}</Text>
871
- </Box>
872
- <Box flexDirection="column">
873
- {service.http ? (
874
- <Text>
875
- <Text color="cyan">{padLabel(service.http.publicOrigin, originWidth + 2)}</Text>
876
- <Text dimColor>
877
- → {service.http.host}:{service.http.port}
878
- </Text>
879
- </Text>
880
- ) : (
881
- <Text dimColor>{describeDeployProcess(service)}</Text>
882
- )}
883
- <Text dimColor>{formatDeployCommand(service.command)}</Text>
884
- {Object.entries(service.env)
885
- .filter(([key, value]) => release.env[key] !== value)
886
- .map(([key, value]) => (
887
- <Text key={key} dimColor>
888
- {key}={value}
889
- </Text>
890
- ))}
891
- </Box>
892
- </Box>
893
- ))}
894
- <Spacer />
895
- <SectionTitle>Steps</SectionTitle>
896
- {steps.map((step) => (
897
- <Box key={step.label}>
898
- <Box width={labelWidth} flexShrink={0}>
899
- <Text bold>{step.label}</Text>
900
- </Box>
901
- <Text>{step.commands.map(formatDeployCommand).join(" → ")}</Text>
902
- </Box>
903
- ))}
904
- <Spacer />
905
- <SectionTitle>Environment</SectionTitle>
906
- {env.map(([key, value]) => (
907
- <Text key={key}>
908
- {key}={value}
909
- </Text>
910
- ))}
911
- {origins.size > 0 ? <Text dimColor>plus the public origins above</Text> : null}
912
- <Spacer />
913
- <Text dimColor>Nothing was deployed · --json prints the full release</Text>
914
- </Box>
915
- )
916
- }
917
-
918
- export interface DeployProgressState {
919
- readonly name: string
920
- readonly location: string
921
- readonly commit: string
922
- readonly ref: string
923
- readonly dirty: boolean
924
- readonly labels: readonly string[]
925
- /** How many steps have finished, in order. */
926
- readonly done: number
927
- readonly current: number | null
928
- /** The latest output lines, shown while a step runs and kept when one fails. */
929
- readonly output: readonly string[]
930
- readonly outcome: "running" | "done" | "failed"
931
- }
932
-
933
- export function DeployProgressView({ state }: { state: DeployProgressState }) {
934
- return (
935
- <Box flexDirection="column">
936
- <Text bold>
937
- {state.name} → {state.location}
938
- </Text>
939
- <Text dimColor>
940
- {state.commit.slice(0, 12)} · {state.ref}
941
- </Text>
942
- {state.dirty ? <Text color="yellow">Uncommitted changes are not deployed.</Text> : null}
943
- <Spacer />
944
- {state.labels.length === 0 ? (
945
- <Spinner label="Connecting…" />
946
- ) : (
947
- state.labels.map((label, index) => {
948
- if (index < state.done) {
949
- return (
950
- <Text key={`${index}:${label}`}>
951
- <Text color="green">✓</Text> {label}
952
- </Text>
953
- )
954
- }
955
- if (index === state.current && state.outcome === "failed") {
956
- return (
957
- <Text key={`${index}:${label}`} color="red">
958
- ✕ {label}
959
- </Text>
960
- )
961
- }
962
- if (index === state.current && state.outcome === "running") {
963
- return <Spinner key={`${index}:${label}`} label={label} />
964
- }
965
- return (
966
- <Text key={`${index}:${label}`} dimColor>
967
- · {label}
968
- </Text>
969
- )
970
- })
971
- )}
972
- {state.outcome === "running" && state.output.length > 0 ? (
973
- <Box flexDirection="column" marginTop={1} paddingLeft={2}>
974
- {state.output.slice(-6).map((line, index) => (
975
- <Text key={`${index}:${line}`} dimColor wrap="truncate-end">
976
- {line}
977
- </Text>
978
- ))}
979
- </Box>
980
- ) : null}
981
- </Box>
982
- )
983
- }
984
-
985
- export function DeployCompleteView({
986
- release,
987
- commit,
988
- ref,
989
- }: {
990
- release: DeployRelease
991
- commit: string
992
- ref: string
993
- }) {
994
- const urls = release.services.flatMap((service) =>
995
- service.http ? [{ label: service.name, value: service.http.publicOrigin }] : []
996
- )
997
- return (
998
- <Box flexDirection="column">
999
- <Spacer />
1000
- <Text color="green" bold>
1001
- {release.name} deployed
1002
- </Text>
1003
- <Text dimColor>
1004
- {commit.slice(0, 12)} · {ref} · {release.target.kind} {release.target.location}
1005
- </Text>
1006
- {urls.length > 0 ? (
1007
- <>
1008
- <Spacer />
1009
- <KeyValueList items={urls} />
1010
- </>
1011
- ) : null}
1012
- </Box>
1013
- )
1014
- }
1015
-
1016
- export function DeployStatusView({
1017
- name,
1018
- location,
1019
- status,
1020
- }: {
1021
- name: string
1022
- location: string
1023
- status: DeployStatus
1024
- }) {
1025
- if (!status.release) {
1026
- return (
1027
- <Box flexDirection="column">
1028
- <Text bold>{name}</Text>
1029
- <Text dimColor>Nothing is deployed on {location} yet. Run `sixb deploy`.</Text>
1030
- </Box>
1031
- )
1032
- }
1033
- const healthy =
1034
- status.running && status.processes.every((process) => process.status === "running")
1035
- return (
1036
- <Box flexDirection="column">
1037
- <Text color={healthy ? "green" : "yellow"} bold>
1038
- {name} {healthy ? "is running" : status.running ? "needs attention" : "is stopped"}
1039
- </Text>
1040
- <Text dimColor>
1041
- {status.release.commit.slice(0, 12)} · {status.release.ref} · deployed{" "}
1042
- {formatAge(status.release.deployedAt)} by {status.release.deployedBy} · {location}
1043
- </Text>
1044
- <Spacer />
1045
- {status.processes.length > 0 ? (
1046
- <Table
1047
- headers={["Service", "Status", "PID", "CPU", "Memory", "Restarts", "Up"]}
1048
- rows={status.processes.map((process) => [
1049
- process.instance === 0 ? process.service : `${process.service}#${process.instance}`,
1050
- process.status,
1051
- process.pid === undefined ? "-" : String(process.pid),
1052
- process.cpuPercent === undefined ? "-" : `${process.cpuPercent.toFixed(1)}%`,
1053
- process.memoryBytes === undefined ? "-" : formatBytes(process.memoryBytes),
1054
- String(process.restarts),
1055
- process.status === "running" && process.startedAt
1056
- ? formatAge(process.startedAt, "")
1057
- : "-",
1058
- ])}
1059
- />
1060
- ) : (
1061
- <Text dimColor>The supervisor is not running.</Text>
1062
- )}
1063
- {status.processes
1064
- .filter((process) => process.lastError)
1065
- .map((process) => (
1066
- <Text key={`${process.service}#${process.instance}`} color="yellow">
1067
- {process.service}: {process.lastError}
1068
- </Text>
1069
- ))}
1070
- </Box>
1071
- )
1072
- }
1073
-
1074
- const CHECK_MARKS = {
1075
- ok: { glyph: "✓", color: "green" },
1076
- fixable: { glyph: "●", color: "yellow" },
1077
- manual: { glyph: "○", color: "yellow" },
1078
- warning: { glyph: "!", color: "yellow" },
1079
- } as const satisfies Record<DeployCheck["status"], { glyph: string; color: string }>
1080
-
1081
- export function DeployChecksView({
1082
- name,
1083
- location,
1084
- checks,
1085
- }: {
1086
- name: string
1087
- location: string
1088
- checks: readonly DeployCheck[]
1089
- }) {
1090
- const blocking = checks.filter((check) => check.status === "fixable" || check.status === "manual")
1091
- const warnings = checks.filter((check) => check.status === "warning")
1092
- const labelWidth = Math.max(...checks.map((check) => check.label.length)) + 2
1093
- const next = blocking.some((check) => check.status === "fixable")
1094
- ? "Next: sixb deploy setup"
1095
- : blocking.length > 0
1096
- ? "Next: the steps above, then sixb deploy check"
1097
- : "Next: sixb deploy"
1098
-
1099
- return (
1100
- <Box flexDirection="column">
1101
- <Text color={blocking.length > 0 ? "yellow" : "green"} bold>
1102
- {name}{" "}
1103
- {blocking.length > 0
1104
- ? `· ${blocking.length} to fix before deploying`
1105
- : `is ready to deploy${warnings.length > 0 ? ` · ${warnings.length} to look at` : ""}`}
1106
- </Text>
1107
- <Text dimColor>{location}</Text>
1108
- <Spacer />
1109
- {checks.map((check) => (
1110
- <Box key={check.id}>
1111
- <Box width={2} flexShrink={0}>
1112
- <Text color={CHECK_MARKS[check.status].color}>{CHECK_MARKS[check.status].glyph}</Text>
1113
- </Box>
1114
- <Box width={labelWidth} flexShrink={0}>
1115
- <Text>{check.label}</Text>
1116
- </Box>
1117
- <Box flexDirection="column">
1118
- <Text dimColor>{check.detail}</Text>
1119
- {check.remedy ? <Text color="cyan">{check.remedy}</Text> : null}
1120
- </Box>
1121
- </Box>
1122
- ))}
1123
- <Spacer />
1124
- <Text dimColor>{next}</Text>
1125
- </Box>
1126
- )
1127
- }
1128
-
1129
- export function DeployCiView({
1130
- name,
1131
- repo,
1132
- environment,
1133
- branch,
1134
- credential,
1135
- secrets,
1136
- retired,
1137
- workflow,
1138
- token,
1139
- }: {
1140
- name: string
1141
- repo: string
1142
- environment: string
1143
- branch: string
1144
- credential: string
1145
- secrets: readonly string[]
1146
- retired: readonly DeployAccessKey[]
1147
- workflow: { readonly path: string; readonly state: "written" | "unchanged" | "kept" }
1148
- token: {
1149
- readonly name: string
1150
- readonly submodules: readonly {
1151
- readonly path: string
1152
- readonly url: string
1153
- readonly repo: string | null
1154
- }[]
1155
- } | null
1156
- }) {
1157
- const rows: { label: string; ok: boolean; detail: string; remedy?: string }[] = [
1158
- { label: "Key", ok: true, detail: credential },
1159
- { label: "Secrets", ok: true, detail: secrets.join(", ") },
1160
- {
1161
- label: "Older keys",
1162
- ok: true,
1163
- detail:
1164
- retired.length === 0
1165
- ? "none to revoke"
1166
- : `revoked ${retired.map((key) => key.fingerprint).join(", ")}`,
1167
- },
1168
- {
1169
- label: "Workflow",
1170
- ok: true,
1171
- detail: {
1172
- written: workflow.path,
1173
- unchanged: `${workflow.path} (unchanged)`,
1174
- kept: `${workflow.path} (yours, kept: it differs from what this command writes; delete it and run again to start over)`,
1175
- }[workflow.state],
1176
- },
1177
- ...(token
1178
- ? [
1179
- {
1180
- label: "Token",
1181
- ok: false,
1182
- detail: `${token.submodules.map((submodule) => submodule.path).join(", ")} ${token.submodules.length === 1 ? "is" : "are"} private, and CI cannot read ${token.submodules.length === 1 ? "it" : "them"} with its own token.`,
1183
- remedy: `Create a fine-grained token with Contents: read on ${token.submodules.map((submodule) => submodule.repo ?? submodule.url).join(", ")}, then run \`gh secret set ${token.name} --env ${environment} --repo ${repo}\`.`,
1184
- },
1185
- ]
1186
- : []),
1187
- ]
1188
- const labelWidth = Math.max(...rows.map((row) => row.label.length)) + 2
1189
- const next =
1190
- workflow.state === "written"
1191
- ? `Next: commit ${workflow.path} and push to ${branch}.`
1192
- : `Next: push to ${branch} to deploy.`
1193
-
1194
- return (
1195
- <Box flexDirection="column">
1196
- <Text color={token ? "yellow" : "green"} bold>
1197
- {name} deploys from GitHub Actions on every push to {branch}
1198
- </Text>
1199
- <Text dimColor>
1200
- {repo} · environment {environment}
1201
- </Text>
1202
- <Spacer />
1203
- {rows.map((row) => (
1204
- <Box key={row.label}>
1205
- <Box width={2} flexShrink={0}>
1206
- <Text color={row.ok ? "green" : "yellow"}>{row.ok ? "✓" : "○"}</Text>
1207
- </Box>
1208
- <Box width={labelWidth} flexShrink={0}>
1209
- <Text>{row.label}</Text>
1210
- </Box>
1211
- <Box flexDirection="column">
1212
- <Text dimColor>{row.detail}</Text>
1213
- {row.remedy ? <Text color="cyan">{row.remedy}</Text> : null}
1214
- </Box>
1215
- </Box>
1216
- ))}
1217
- <Spacer />
1218
- <Text dimColor>{next}</Text>
1219
- </Box>
1220
- )
1221
- }
1222
-
1223
- export function DeployAccessView({
1224
- title,
1225
- keys,
1226
- }: {
1227
- title: string
1228
- keys: readonly DeployAccessKey[]
1229
- }) {
1230
- // Two lines a key: a fingerprint and a long comment do not fit side by side in 80 columns.
1231
- return (
1232
- <Box flexDirection="column">
1233
- <Text color="green" bold>
1234
- {title}
1235
- </Text>
1236
- <Spacer />
1237
- {keys.length === 0 ? <Text dimColor>No keys.</Text> : null}
1238
- {keys.map((key) => (
1239
- <Box key={key.fingerprint} flexDirection="column">
1240
- <Text>
1241
- {key.comment || "(no comment)"}
1242
- {key.restricted ? <Text color="yellow"> restricted</Text> : null}
1243
- </Text>
1244
- <Text dimColor>
1245
- {" "}
1246
- {key.type} {key.fingerprint}
1247
- </Text>
1248
- </Box>
1249
- ))}
1250
- </Box>
1251
- )
1252
- }
1253
-
1254
- function formatAge(iso: string, suffix = " ago"): string {
1255
- const seconds = Math.max(0, Math.round((Date.now() - Date.parse(iso)) / 1000))
1256
- const age =
1257
- seconds < 60
1258
- ? `${seconds}s`
1259
- : seconds < 3600
1260
- ? `${Math.floor(seconds / 60)}m`
1261
- : seconds < 86_400
1262
- ? `${Math.floor(seconds / 3600)}h`
1263
- : `${Math.floor(seconds / 86_400)}d`
1264
- return `${age}${suffix}`
1265
- }
1266
-
1267
- function formatBytes(bytes: number): string {
1268
- if (bytes >= 1024 ** 3) return `${(bytes / 1024 ** 3).toFixed(1)}G`
1269
- if (bytes >= 1024 ** 2) return `${(bytes / 1024 ** 2).toFixed(1)}M`
1270
- return `${Math.round(bytes / 1024)}K`
1271
- }
1272
-
1273
- function describeDeployProcess(service: DeployRelease["services"][number]): string {
1274
- const count = `${service.instances} ${service.instances === 1 ? "process" : "processes"}`
1275
- if (service.kind === "script") return `project script · ${count}`
1276
- // `worker-group` without worker types runs every type the project registers work for.
1277
- const namesWorkerTypes = service.command.args[1] && !service.command.args[1].startsWith("-")
1278
- if (service.kind === "workers" && !namesWorkerTypes) {
1279
- return `${count} · every worker type the project registers`
1280
- }
1281
- return count
1282
- }
1283
-
1284
- function formatDeployCommand(command: DeployCommand): string {
1285
- return [command.program, ...command.args].join(" ")
1286
- }
1287
-
1288
- export interface LakeCleanupReport {
1289
- readonly dryRun: boolean
1290
- readonly expireOlderThan: string
1291
- readonly deleteOlderThan: string
1292
- readonly snapshots: number
1293
- readonly oldFiles: number
1294
- readonly orphanedFiles: number
1295
- }
1296
-
1297
- export function LakeCleanupView({
1298
- projectId,
1299
- report,
1300
- }: {
1301
- projectId: string
1302
- report: LakeCleanupReport
1303
- }) {
1304
- return (
1305
- <Box flexDirection="column">
1306
- <Text color="green" bold>
1307
- {report.dryRun ? "Lake cleanup dry run complete" : "Lake cleanup complete"}
1308
- </Text>
1309
- <Text dimColor>{projectId}</Text>
1310
- <Spacer />
1311
- <KeyValueList
1312
- items={[
1313
- { label: "Dry run", value: String(report.dryRun) },
1314
- { label: "Expire older than", value: report.expireOlderThan },
1315
- { label: "Delete older than", value: report.deleteOlderThan },
1316
- { label: "Snapshots", value: String(report.snapshots) },
1317
- { label: "Old files", value: String(report.oldFiles) },
1318
- { label: "Orphaned files", value: String(report.orphanedFiles) },
1319
- ]}
1320
- />
1321
- </Box>
1322
- )
1323
- }
1324
-
1325
- export function InitView({
1326
- name,
1327
- targetDir,
1328
- files,
1329
- commands,
1330
- }: {
1331
- name: string
1332
- targetDir: string
1333
- files: string[]
1334
- commands: readonly string[]
1335
- }) {
1336
- return (
1337
- <Box flexDirection="column">
1338
- <Text color="green" bold>
1339
- Sixb initialized
1340
- </Text>
1341
- <Text dimColor>{name}</Text>
1342
- <Text dimColor>{targetDir}</Text>
1343
- <Spacer />
1344
- <SectionTitle>Files</SectionTitle>
1345
- <BulletList items={files} />
1346
- <Spacer />
1347
- <SectionTitle>Next steps</SectionTitle>
1348
- <CommandList commands={commands} />
1349
- </Box>
1350
- )
1351
- }
1352
-
1353
- function CommandList({ commands }: { commands: readonly string[] }) {
1354
- return (
1355
- <Box flexDirection="column">
1356
- {commands.map((command) => (
1357
- <Text key={command} color="cyan">
1358
- {` ${command}`}
1359
- </Text>
1360
- ))}
1361
- </Box>
1362
- )
1363
- }