@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
@@ -0,0 +1,522 @@
1
+ /** @jsxImportSource @opentui/react */
2
+ import { basename } from "node:path"
3
+ import type { KeyEvent } from "@opentui/core"
4
+ import { useKeyboard, useRenderer, useTerminalDimensions } from "@opentui/react"
5
+ import { useSyncExternalStore } from "react"
6
+ import {
7
+ DEV_STARTUP_STEPS,
8
+ type DevChildMessage,
9
+ type DevReadyView,
10
+ type DevStartupFailure,
11
+ } from "../../lib/dev-messages"
12
+ import type { DevControls, DevReporter } from "../../lib/dev-supervisor"
13
+ import { openUrl } from "../../lib/open-url"
14
+ import { MAX_COLUMNS, wrap } from "../layout"
15
+ import { errorView } from "../screens"
16
+ import { glyph, tone } from "../theme"
17
+ import { BOLD, Hints, Tiles, useSpinner, useTick } from "./components"
18
+ import { type LiveColors, startFooter } from "./session"
19
+
20
+ type Phase =
21
+ /** `restart` when a dev process came before this one. */
22
+ | { readonly kind: "starting"; readonly step: number; readonly restart: boolean }
23
+ | { readonly kind: "ready" }
24
+ | { readonly kind: "failed"; readonly error: DevStartupFailure }
25
+ | { readonly kind: "exited"; readonly code: number | null }
26
+ | { readonly kind: "stopping" }
27
+
28
+ export interface DevState {
29
+ readonly phase: Phase
30
+ readonly view: DevReadyView | null
31
+ /** Restarts since `sixb dev` began, by a source change or by hand. */
32
+ readonly restarts: number
33
+ readonly readySince: number | null
34
+ }
35
+
36
+ /** Rows the footer takes: the titled rule, a gap, three body rows, warnings, a gap, the keys. */
37
+ const FULL_ROWS = 7
38
+ /** Below this many terminal rows, the footer keeps to its titled rule and one line. */
39
+ const COMPACT_BELOW = 30
40
+ const COMPACT_ROWS = 2
41
+ const MAX_WARNINGS = 2
42
+
43
+ /**
44
+ * `sixb dev` in a terminal: a footer that outlives every restart, showing what the dev process
45
+ * serves and how it is doing, with the dev process's output scrolling above it.
46
+ */
47
+ export async function startDevFooter(options: {
48
+ readonly root: string
49
+ readonly controls: DevControls
50
+ }): Promise<DevReporter> {
51
+ let state: DevState = {
52
+ phase: { kind: "starting", step: 0, restart: false },
53
+ view: null,
54
+ restarts: 0,
55
+ readySince: null,
56
+ }
57
+ const listeners = new Set<() => void>()
58
+ const footer = await startFooter({ rows: FULL_ROWS })
59
+ let bootStartedAt = Date.now()
60
+
61
+ const set = (next: Partial<DevState>) => {
62
+ state = { ...state, ...next }
63
+ footer.resize(
64
+ isCompact(footer.renderer.terminalHeight) ? COMPACT_ROWS : FULL_ROWS + warningRows(state.view)
65
+ )
66
+ for (const listener of listeners) listener()
67
+ }
68
+ footer.renderer.on("resize", () => set({}))
69
+ set({})
70
+ const store = {
71
+ subscribe(listener: () => void) {
72
+ listeners.add(listener)
73
+ return () => listeners.delete(listener)
74
+ },
75
+ get: () => state,
76
+ }
77
+ // The footer's top rule names the session, so the scrollback opens with nothing but room under
78
+ // the prompt, and only once there is something to set apart. A space, not "": the scrollback
79
+ // drops empty lines.
80
+ let spaced = false
81
+ const print = (text: string) => {
82
+ if (!spaced) footer.print(" ")
83
+ spaced = true
84
+ footer.print(text)
85
+ }
86
+ const event = (mark: string, text: string) => print(` ${mark} ${text} ${tone.faint(clock())}`)
87
+
88
+ footer.render(
89
+ <DevFooter
90
+ store={store}
91
+ colors={footer.colors}
92
+ projectName={basename(options.root)}
93
+ controls={options.controls}
94
+ />
95
+ )
96
+
97
+ return {
98
+ output: "pipe",
99
+ line(text) {
100
+ print(text)
101
+ },
102
+ message(message: DevChildMessage) {
103
+ if (message.type === "status") {
104
+ set({
105
+ phase: {
106
+ kind: "starting",
107
+ step: DEV_STARTUP_STEPS.indexOf(message.step),
108
+ restart: state.phase.kind === "starting" && state.phase.restart,
109
+ },
110
+ })
111
+ } else if (message.type === "ready") {
112
+ const seconds = ((Date.now() - bootStartedAt) / 1000).toFixed(1)
113
+ const view = message.view ?? state.view
114
+ // The footer says it is ready. The scrollback records only what changed: a restart's
115
+ // ready line answers the change that started it.
116
+ if (state.restarts > 0) {
117
+ event(tone.blue(glyph.live), `${tone.strong("ready")} ${tone.muted(`in ${seconds}s`)}`)
118
+ }
119
+ set({ phase: { kind: "ready" }, view, readySince: Date.now() })
120
+ } else if (message.type === "startup-error") {
121
+ const error = message.error ?? { message: "The dev process failed to start." }
122
+ set({ phase: { kind: "failed", error } })
123
+ print(
124
+ errorView({
125
+ message: error.message,
126
+ ...(error.remediation ? { remediation: error.remediation } : {}),
127
+ }).replace(/^\n+|\n+$/g, "")
128
+ )
129
+ }
130
+ },
131
+ restarting(filename) {
132
+ bootStartedAt = Date.now()
133
+ set({
134
+ phase: { kind: "starting", step: 0, restart: true },
135
+ restarts: state.restarts + 1,
136
+ })
137
+ event(
138
+ tone.warn(glyph.restart),
139
+ filename ? `${filename} ${tone.muted("changed")}` : tone.muted("restart requested")
140
+ )
141
+ },
142
+ exited(code) {
143
+ // A failed start already said why it ended.
144
+ if (state.phase.kind === "failed") return
145
+ set({ phase: { kind: "exited", code } })
146
+ event(tone.fail(glyph.fail), tone.muted(`dev process exited (${code})`))
147
+ },
148
+ timedOut() {
149
+ set({
150
+ phase: {
151
+ kind: "failed",
152
+ error: { message: "Startup timed out.", remediation: "Edit a source file to retry." },
153
+ },
154
+ })
155
+ event(tone.fail(glyph.fail), "Startup timed out. Edit a source file to retry.")
156
+ },
157
+ error(text) {
158
+ event(tone.fail(glyph.fail), text)
159
+ },
160
+ stopping() {
161
+ set({ phase: { kind: "stopping" } })
162
+ },
163
+ async stop() {
164
+ const up = state.readySince
165
+ ? ` ${glyph.dot} up ${duration(Date.now() - state.readySince)}`
166
+ : ""
167
+ print(` ${tone.faint(glyph.idle)} ${tone.muted(`sixb dev stopped${up}`)}\n`)
168
+ await footer.stop()
169
+ },
170
+ }
171
+ }
172
+
173
+ function isCompact(terminalRows: number): boolean {
174
+ return terminalRows < COMPACT_BELOW
175
+ }
176
+
177
+ function warningRows(view: DevReadyView | null): number {
178
+ if (!view || view.warnings.length === 0) return 0
179
+ return (
180
+ Math.min(MAX_WARNINGS, view.warnings.length) + (view.warnings.length > MAX_WARNINGS ? 1 : 0)
181
+ )
182
+ }
183
+
184
+ /** The footer itself, drawn from the state the reporter keeps. */
185
+ export function DevFooter({
186
+ store,
187
+ colors,
188
+ projectName,
189
+ controls,
190
+ }: {
191
+ readonly store: { subscribe(listener: () => void): () => void; get(): DevState }
192
+ readonly colors: LiveColors
193
+ readonly projectName: string
194
+ readonly controls: DevControls
195
+ }) {
196
+ const state = useSyncExternalStore(store.subscribe, store.get)
197
+ // In split-footer mode the renderer's own size is the footer's; the terminal's is apart.
198
+ // Reading the dimensions hook re-renders this on a resize.
199
+ useTerminalDimensions()
200
+ const renderer = useRenderer()
201
+ const width = Math.min(renderer.terminalWidth, MAX_COLUMNS)
202
+ const compact = isCompact(renderer.terminalHeight)
203
+ const inner = Math.max(20, width - 6)
204
+ const appUrl = state.view?.appUrl ?? null
205
+ const docsUrl = state.view?.apiDocsUrl ?? null
206
+ const keys: (readonly [string, string])[] = [
207
+ ...(appUrl ? ([["o", compact ? "open" : "open app"]] as const) : []),
208
+ ...(docsUrl ? ([["d", compact ? "docs" : "api docs"]] as const) : []),
209
+ ["r", "restart"],
210
+ ["q", "quit"],
211
+ ]
212
+
213
+ useKeyboard((key: KeyEvent) => {
214
+ if ((key.ctrl && key.name === "c") || key.name === "q") controls.quit()
215
+ else if (key.name === "r") controls.restart()
216
+ else if (key.name === "o" && appUrl) void openUrl(appUrl)
217
+ else if (key.name === "d" && docsUrl) void openUrl(docsUrl)
218
+ })
219
+
220
+ const title = state.view?.name ?? projectName
221
+ if (compact) {
222
+ return (
223
+ <box flexDirection="column">
224
+ <TitleRule state={state} colors={colors} title={title} width={width} />
225
+ <box flexDirection="row" paddingLeft={3} width={width}>
226
+ <Summary state={state} colors={colors} width={Math.max(10, inner - 34)} />
227
+ <box flexGrow={1} />
228
+ <Hints colors={colors} items={keys} />
229
+ </box>
230
+ </box>
231
+ )
232
+ }
233
+ return (
234
+ <box flexDirection="column">
235
+ <TitleRule state={state} colors={colors} title={title} width={width} />
236
+ <box height={1} />
237
+ <box flexDirection="column" paddingLeft={3} height={3}>
238
+ <Body state={state} colors={colors} width={inner} />
239
+ </box>
240
+ <Warnings view={state.view} colors={colors} width={inner} />
241
+ <box height={1} />
242
+ <box paddingLeft={3}>
243
+ <Hints colors={colors} items={keys} />
244
+ </box>
245
+ </box>
246
+ )
247
+ }
248
+
249
+ interface Part {
250
+ readonly text: string
251
+ readonly fg: string
252
+ readonly bold?: boolean
253
+ }
254
+
255
+ /**
256
+ * The footer's top edge, which also names it and says how it stands:
257
+ *
258
+ * ── ▰ sixb dev · northline ──────────────── ● ready · up 4m · 2 restarts ──
259
+ */
260
+ function TitleRule({
261
+ state,
262
+ colors,
263
+ title,
264
+ width,
265
+ }: {
266
+ readonly state: DevState
267
+ readonly colors: LiveColors
268
+ readonly title: string
269
+ readonly width: number
270
+ }) {
271
+ const busy = state.phase.kind === "starting" || state.phase.kind === "stopping"
272
+ const spinner = useSpinner(busy)
273
+ useTick(5000)
274
+ const left: Part[] = [
275
+ { text: glyph.mark, fg: colors.blue },
276
+ { text: " sixb dev", fg: colors.text, bold: true },
277
+ { text: ` ${glyph.dot} ${title}`, fg: colors.muted },
278
+ ]
279
+ const right = statusParts(state, colors, spinner, Date.now())
280
+ const length = (parts: readonly Part[]) => parts.reduce((sum, part) => sum + part.text.length, 0)
281
+ const fill = Math.max(1, width - length(left) - length(right) - 8)
282
+ return (
283
+ <text>
284
+ <span fg={colors.faint}>{"── "}</span>
285
+ {left.map((part) => (
286
+ <span key={part.text} fg={part.fg} attributes={part.bold ? BOLD : 0}>
287
+ {part.text}
288
+ </span>
289
+ ))}
290
+ <span fg={colors.faint}>{` ${"─".repeat(fill)} `}</span>
291
+ {right.map((part, index) => (
292
+ <span key={`${index}:${part.text}`} fg={part.fg} attributes={part.bold ? BOLD : 0}>
293
+ {part.text}
294
+ </span>
295
+ ))}
296
+ <span fg={colors.faint}>{" ──"}</span>
297
+ </text>
298
+ )
299
+ }
300
+
301
+ function statusParts(state: DevState, colors: LiveColors, spinner: string, now: number): Part[] {
302
+ const phase = state.phase
303
+ switch (phase.kind) {
304
+ case "starting": {
305
+ const step = Math.max(0, phase.step)
306
+ // A restart keeps the last URLs on screen, so its progress lives up here.
307
+ return phase.restart
308
+ ? [
309
+ { text: spinner, fg: colors.amber },
310
+ { text: " restarting", fg: colors.text },
311
+ { text: ` ${glyph.dot} ${DEV_STARTUP_STEPS[step] ?? ""}`, fg: colors.muted },
312
+ ]
313
+ : [
314
+ { text: spinner, fg: colors.blue },
315
+ { text: " starting", fg: colors.text },
316
+ ]
317
+ }
318
+ case "ready":
319
+ return [
320
+ { text: glyph.live, fg: colors.blue },
321
+ { text: " ready", fg: colors.text, bold: true },
322
+ {
323
+ text: `${state.readySince ? ` ${glyph.dot} up ${duration(now - state.readySince)}` : ""}${
324
+ state.restarts > 0
325
+ ? ` ${glyph.dot} ${state.restarts} restart${state.restarts === 1 ? "" : "s"}`
326
+ : ""
327
+ }`,
328
+ fg: colors.muted,
329
+ },
330
+ ]
331
+ case "failed":
332
+ case "exited":
333
+ return [
334
+ {
335
+ text: `${glyph.fail} ${phase.kind === "failed" ? "failed" : "stopped"}`,
336
+ fg: colors.red,
337
+ bold: true,
338
+ },
339
+ { text: ` ${glyph.dot} waiting for a change`, fg: colors.muted },
340
+ ]
341
+ case "stopping":
342
+ return [
343
+ { text: spinner, fg: colors.muted },
344
+ { text: " stopping", fg: colors.muted },
345
+ ]
346
+ }
347
+ }
348
+
349
+ /** The one line a compact footer has for its state. */
350
+ function Summary({
351
+ state,
352
+ colors,
353
+ width,
354
+ }: {
355
+ readonly state: DevState
356
+ readonly colors: LiveColors
357
+ readonly width: number
358
+ }) {
359
+ const phase = state.phase
360
+ if (phase.kind === "failed") return <text fg={colors.red}>{fit(phase.error.message, width)}</text>
361
+ if (phase.kind === "starting" && !state.view) {
362
+ return <StartupProgress step={phase.step} colors={colors} />
363
+ }
364
+ return (
365
+ <text>
366
+ <span fg={colors.muted}>{"app "}</span>
367
+ <span fg={phase.kind === "ready" ? colors.blue : colors.muted}>
368
+ {fit(state.view?.appUrl ?? "not running", width - 4)}
369
+ </span>
370
+ </text>
371
+ )
372
+ }
373
+
374
+ function Body({
375
+ state,
376
+ colors,
377
+ width,
378
+ }: {
379
+ readonly state: DevState
380
+ readonly colors: LiveColors
381
+ readonly width: number
382
+ }) {
383
+ const phase = state.phase
384
+ if (phase.kind === "failed") {
385
+ const lines = wrap(phase.error.message, width)
386
+ const [first = "", second] = lines
387
+ return (
388
+ <>
389
+ <text fg={colors.red}>{first}</text>
390
+ <text fg={colors.red}>
391
+ {second ? (lines.length > 2 ? fit(`${second} …`, width) : second) : " "}
392
+ </text>
393
+ <text fg={colors.muted}>
394
+ {fit(phase.error.remediation ?? "Save a source file to retry, or press r.", width)}
395
+ </text>
396
+ </>
397
+ )
398
+ }
399
+ if (phase.kind === "exited") {
400
+ return (
401
+ <>
402
+ <text fg={colors.text}>{`The dev process exited (${phase.code}).`}</text>
403
+ <text fg={colors.muted}>
404
+ {fit("Its output is above. Save a source file to start it again, or press r.", width)}
405
+ </text>
406
+ <text> </text>
407
+ </>
408
+ )
409
+ }
410
+ if (state.view) {
411
+ return <Serving view={state.view} colors={colors} width={width} dim={phase.kind !== "ready"} />
412
+ }
413
+
414
+ return (
415
+ <>
416
+ <StartupProgress step={phase.kind === "starting" ? phase.step : 0} colors={colors} />
417
+ <text> </text>
418
+ <text> </text>
419
+ </>
420
+ )
421
+ }
422
+
423
+ /** The first start's progress: tiles filling as the steps pass, then the step running now. */
424
+ function StartupProgress({ step, colors }: { readonly step: number; readonly colors: LiveColors }) {
425
+ const current = Math.max(0, step)
426
+ return (
427
+ <text>
428
+ <Tiles colors={colors} filled={current + 1} total={DEV_STARTUP_STEPS.length + 1} />
429
+ <span fg={colors.text}>{` ${DEV_STARTUP_STEPS[current] ?? "Starting"}…`}</span>
430
+ </text>
431
+ )
432
+ }
433
+
434
+ function Serving({
435
+ view,
436
+ colors,
437
+ width,
438
+ dim,
439
+ }: {
440
+ readonly view: DevReadyView
441
+ readonly colors: LiveColors
442
+ readonly width: number
443
+ readonly dim: boolean
444
+ }) {
445
+ const value = dim ? colors.muted : colors.blue
446
+ const extras = ` docs ${pathOf(view.apiDocsUrl)} events ${pathOf(view.wsUrl)}`
447
+ const workers = view.workers.map((worker) => `${worker.type} ${worker.concurrency}`).join(" · ")
448
+ return (
449
+ <>
450
+ <text>
451
+ <span fg={colors.muted}>{"app "}</span>
452
+ {view.appUrl ? (
453
+ <span fg={value}>{view.appUrl}</span>
454
+ ) : (
455
+ <span fg={colors.faint}>not running</span>
456
+ )}
457
+ </text>
458
+ <text>
459
+ <span fg={colors.muted}>{"api "}</span>
460
+ <span fg={value}>{view.apiUrl}</span>
461
+ <span fg={colors.faint}>{fit(extras, Math.max(0, width - 9 - view.apiUrl.length))}</span>
462
+ </text>
463
+ <text>
464
+ <span fg={colors.muted}>{"workers "}</span>
465
+ <span fg={dim ? colors.muted : colors.text}>
466
+ {workers ? fit(workers, width - 9) : "none registered"}
467
+ </span>
468
+ </text>
469
+ </>
470
+ )
471
+ }
472
+
473
+ function Warnings({
474
+ view,
475
+ colors,
476
+ width,
477
+ }: {
478
+ readonly view: DevReadyView | null
479
+ readonly colors: LiveColors
480
+ readonly width: number
481
+ }) {
482
+ if (!view || view.warnings.length === 0) return null
483
+ const shown = view.warnings.slice(0, MAX_WARNINGS)
484
+ const more = view.warnings.length - shown.length
485
+ return (
486
+ <box flexDirection="column" paddingLeft={3}>
487
+ {shown.map((warning) => (
488
+ <text key={warning}>
489
+ <span fg={colors.amber}>{`${glyph.warn} `}</span>
490
+ <span fg={colors.muted}>{fit(warning, width - 2)}</span>
491
+ </text>
492
+ ))}
493
+ {more > 0 ? <text fg={colors.faint}>{` and ${more} more`}</text> : null}
494
+ </box>
495
+ )
496
+ }
497
+
498
+ function fit(text: string, width: number): string {
499
+ if (width <= 1) return ""
500
+ return text.length > width ? `${text.slice(0, width - 1)}…` : text
501
+ }
502
+
503
+ function pathOf(url: string): string {
504
+ try {
505
+ return new URL(url).pathname
506
+ } catch {
507
+ return url
508
+ }
509
+ }
510
+
511
+ function duration(ms: number): string {
512
+ const seconds = Math.floor(ms / 1000)
513
+ if (seconds < 60) return `${seconds}s`
514
+ const minutes = Math.floor(seconds / 60)
515
+ if (minutes < 60) return `${minutes}m`
516
+ const hours = Math.floor(minutes / 60)
517
+ return `${hours}h ${minutes % 60}m`
518
+ }
519
+
520
+ function clock(): string {
521
+ return new Date().toTimeString().slice(0, 8)
522
+ }