@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.
- package/README.md +21 -4
- package/dist/commands/api.d.ts.map +1 -1
- package/dist/commands/app.d.ts.map +1 -1
- package/dist/commands/build.d.ts.map +1 -1
- package/dist/commands/check.d.ts.map +1 -1
- package/dist/commands/db-migrate.d.ts.map +1 -1
- package/dist/commands/deploy.d.ts.map +1 -1
- package/dist/commands/desktop.d.ts +15 -0
- package/dist/commands/desktop.d.ts.map +1 -0
- package/dist/commands/dev-runner.d.ts +4 -0
- package/dist/commands/dev-runner.d.ts.map +1 -1
- package/dist/commands/dev.d.ts.map +1 -1
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/lake-check.d.ts.map +1 -1
- package/dist/commands/lake-cleanup.d.ts +2 -0
- package/dist/commands/lake-cleanup.d.ts.map +1 -1
- package/dist/commands/login.d.ts.map +1 -1
- package/dist/commands/logout.d.ts.map +1 -1
- package/dist/commands/orchestrator.d.ts.map +1 -1
- package/dist/commands/profile.d.ts.map +1 -1
- package/dist/commands/rules.d.ts.map +1 -1
- package/dist/commands/scheduler.d.ts.map +1 -1
- package/dist/commands/service-account.d.ts.map +1 -1
- package/dist/commands/status.d.ts.map +1 -1
- package/dist/commands/token.d.ts.map +1 -1
- package/dist/commands/typegen.d.ts.map +1 -1
- package/dist/commands/worker-group.d.ts +2 -0
- package/dist/commands/worker-group.d.ts.map +1 -1
- package/dist/commands/worker.d.ts +2 -0
- package/dist/commands/worker.d.ts.map +1 -1
- package/dist/lib/command-line.d.ts +22 -2
- package/dist/lib/command-line.d.ts.map +1 -1
- package/dist/lib/deploy-release.d.ts +3 -1
- package/dist/lib/deploy-release.d.ts.map +1 -1
- package/dist/lib/desktop.d.ts +26 -0
- package/dist/lib/desktop.d.ts.map +1 -0
- package/dist/lib/dev-messages.d.ts +43 -0
- package/dist/lib/dev-messages.d.ts.map +1 -0
- package/dist/lib/dev-supervisor.d.ts +27 -0
- package/dist/lib/dev-supervisor.d.ts.map +1 -1
- package/dist/lib/open-url.d.ts +3 -0
- package/dist/lib/open-url.d.ts.map +1 -0
- package/dist/lib/role-lifecycle.d.ts.map +1 -1
- package/dist/lib/runtime.d.ts +10 -0
- package/dist/lib/runtime.d.ts.map +1 -1
- package/dist/lib/worker-concurrency.d.ts +11 -0
- package/dist/lib/worker-concurrency.d.ts.map +1 -1
- package/dist/lib/worker-registry.d.ts +2 -0
- package/dist/lib/worker-registry.d.ts.map +1 -1
- package/dist/ui/deploy-screens.d.ts +48 -0
- package/dist/ui/deploy-screens.d.ts.map +1 -0
- package/dist/ui/index.d.ts +28 -233
- package/dist/ui/index.d.ts.map +1 -1
- package/dist/ui/layout.d.ts +65 -0
- package/dist/ui/layout.d.ts.map +1 -0
- package/dist/ui/live/ansi.d.ts +8 -0
- package/dist/ui/live/ansi.d.ts.map +1 -0
- package/dist/ui/live/can-run-live.d.ts +6 -0
- package/dist/ui/live/can-run-live.d.ts.map +1 -0
- package/dist/ui/live/components.d.ts +17 -0
- package/dist/ui/live/components.d.ts.map +1 -0
- package/dist/ui/live/deploy.d.ts +22 -0
- package/dist/ui/live/deploy.d.ts.map +1 -0
- package/dist/ui/live/dev.d.ts +47 -0
- package/dist/ui/live/dev.d.ts.map +1 -0
- package/dist/ui/live/prompt.d.ts +30 -0
- package/dist/ui/live/prompt.d.ts.map +1 -0
- package/dist/ui/live/session.d.ts +27 -0
- package/dist/ui/live/session.d.ts.map +1 -0
- package/dist/ui/screens.d.ts +136 -0
- package/dist/ui/screens.d.ts.map +1 -0
- package/dist/ui/theme.d.ts +58 -0
- package/dist/ui/theme.d.ts.map +1 -0
- package/package.json +21 -19
- package/src/commands/{api.tsx → api.ts} +18 -27
- package/src/commands/{app.tsx → app.ts} +14 -18
- package/src/commands/build.ts +70 -0
- package/src/commands/{check.tsx → check.ts} +74 -19
- package/src/commands/db-migrate.ts +32 -0
- package/src/commands/{deploy.tsx → deploy.ts} +109 -102
- package/src/commands/desktop.ts +71 -0
- package/src/commands/{dev-runner.tsx → dev-runner.ts} +67 -33
- package/src/commands/{init.tsx → init.ts} +19 -8
- package/src/commands/lake-check.ts +36 -0
- package/src/commands/{lake-cleanup.tsx → lake-cleanup.ts} +24 -8
- package/src/commands/{login.tsx → login.ts} +36 -30
- package/src/commands/{logout.tsx → logout.ts} +5 -5
- package/src/commands/{orchestrator.tsx → orchestrator.ts} +15 -28
- package/src/commands/{profile.tsx → profile.ts} +38 -19
- package/src/commands/{rules.tsx → rules.ts} +15 -24
- package/src/commands/{scheduler.tsx → scheduler.ts} +14 -27
- package/src/commands/{service-account.tsx → service-account.ts} +37 -39
- package/src/commands/{status.tsx → status.ts} +8 -8
- package/src/commands/{token.tsx → token.ts} +19 -20
- package/src/commands/typegen.ts +18 -0
- package/src/commands/{worker-group.tsx → worker-group.ts} +40 -29
- package/src/commands/{worker.tsx → worker.ts} +30 -22
- package/src/index.tsx +22 -1
- package/src/lib/command-line.ts +108 -57
- package/src/lib/deploy-release.ts +17 -1
- package/src/lib/desktop.ts +52 -0
- package/src/lib/dev-messages.ts +44 -0
- package/src/lib/dev-supervisor.ts +132 -12
- package/src/lib/open-url.ts +15 -0
- package/src/lib/role-lifecycle.ts +2 -3
- package/src/lib/runtime.ts +21 -0
- package/src/lib/worker-concurrency.ts +31 -0
- package/src/lib/worker-registry.ts +4 -0
- package/src/ui/README.md +54 -0
- package/src/ui/deploy-screens.ts +360 -0
- package/src/ui/index.ts +158 -0
- package/src/ui/layout.ts +245 -0
- package/src/ui/live/ansi.ts +103 -0
- package/src/ui/live/can-run-live.ts +9 -0
- package/src/ui/live/components.tsx +81 -0
- package/src/ui/live/deploy.tsx +170 -0
- package/src/ui/live/dev.tsx +522 -0
- package/src/ui/live/prompt.tsx +205 -0
- package/src/ui/live/session.ts +103 -0
- package/src/ui/screens.ts +490 -0
- package/src/ui/theme.ts +122 -0
- package/dist/lib/role-view.d.ts +0 -21
- package/dist/lib/role-view.d.ts.map +0 -1
- package/src/commands/build.tsx +0 -65
- package/src/commands/db-migrate.tsx +0 -30
- package/src/commands/lake-check.tsx +0 -20
- package/src/commands/typegen.tsx +0 -18
- package/src/lib/role-view.ts +0 -49
- package/src/ui/index.tsx +0 -1363
- /package/src/commands/{dev.tsx → dev.ts} +0 -0
|
@@ -0,0 +1,490 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CLI_EXAMPLES,
|
|
3
|
+
type CliHelp,
|
|
4
|
+
type CliHelpItem,
|
|
5
|
+
ROOT_HELP,
|
|
6
|
+
ROOT_HELP_GROUPS,
|
|
7
|
+
} from "../lib/command-line"
|
|
8
|
+
import {
|
|
9
|
+
commands,
|
|
10
|
+
contentWidth,
|
|
11
|
+
header,
|
|
12
|
+
headline,
|
|
13
|
+
hints,
|
|
14
|
+
marked,
|
|
15
|
+
pad,
|
|
16
|
+
paragraph,
|
|
17
|
+
plural,
|
|
18
|
+
quoted,
|
|
19
|
+
type Row,
|
|
20
|
+
rows,
|
|
21
|
+
type Status,
|
|
22
|
+
screen,
|
|
23
|
+
section,
|
|
24
|
+
stack,
|
|
25
|
+
table,
|
|
26
|
+
visibleWidth,
|
|
27
|
+
warnings as warningLines,
|
|
28
|
+
wrap,
|
|
29
|
+
} from "./layout"
|
|
30
|
+
import { colorLevel, glyph, paint, palette, tone } from "./theme"
|
|
31
|
+
|
|
32
|
+
export type KeyValueItem = { label: string; value: string }
|
|
33
|
+
|
|
34
|
+
const DOCS_URL = "https://docs.sixb.ai"
|
|
35
|
+
|
|
36
|
+
// Every screen reads top to bottom the same way: the `▰ sixb <command>` header, the details, then
|
|
37
|
+
// the outcome. A command that has one thing to say says it on one line instead.
|
|
38
|
+
|
|
39
|
+
// ─── Help ────────────────────────────────────────────────────────────────────
|
|
40
|
+
|
|
41
|
+
/** Past this, a command or option gets its own line and its description starts under it. */
|
|
42
|
+
const HELP_LABEL_COLUMN = 26
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Help reads by name: the command or option stands out, what it does stays quiet, and a default
|
|
46
|
+
* sits apart from the description so the eye can skip it. `column` lines several groups up on
|
|
47
|
+
* one column; without it, the column fits these items, up to `HELP_LABEL_COLUMN`.
|
|
48
|
+
*/
|
|
49
|
+
function helpRows(items: readonly CliHelpItem[], column?: number): string {
|
|
50
|
+
const width =
|
|
51
|
+
column ??
|
|
52
|
+
Math.min(HELP_LABEL_COLUMN, Math.max(...items.map((item) => visibleWidth(item.label))) + 2)
|
|
53
|
+
const room = Math.max(20, contentWidth() - width)
|
|
54
|
+
const hanging = " ".repeat(width)
|
|
55
|
+
return items
|
|
56
|
+
.map((item) => {
|
|
57
|
+
const match = /\s*\(default:?\s*([^)]*)\)$/.exec(item.value)
|
|
58
|
+
const summary = match ? item.value.slice(0, match.index) : item.value
|
|
59
|
+
const lines = wrap(summary, room).map((line) => tone.muted(line))
|
|
60
|
+
if (match) lines[lines.length - 1] += tone.faint(` default ${match[1]}`)
|
|
61
|
+
if (visibleWidth(item.label) + 2 > width) {
|
|
62
|
+
return [item.label, ...lines.map((line) => `${hanging}${line}`)].join("\n")
|
|
63
|
+
}
|
|
64
|
+
const [first = "", ...rest] = lines
|
|
65
|
+
return [`${pad(item.label, width)}${first}`, ...rest.map((line) => `${hanging}${line}`)].join(
|
|
66
|
+
"\n"
|
|
67
|
+
)
|
|
68
|
+
})
|
|
69
|
+
.join("\n")
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function versionView(version: string): string {
|
|
73
|
+
return `${version}\n`
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function helpView({ errorMessage }: { errorMessage?: string } = {}): string {
|
|
77
|
+
const column =
|
|
78
|
+
Math.max(
|
|
79
|
+
...ROOT_HELP_GROUPS.filter((group) => !group.compact).flatMap((group) =>
|
|
80
|
+
group.items.map((item) => visibleWidth(item.label))
|
|
81
|
+
)
|
|
82
|
+
) + 2
|
|
83
|
+
return screen(
|
|
84
|
+
header("", ROOT_HELP.summary),
|
|
85
|
+
errorMessage ? headline("fail", errorMessage) : null,
|
|
86
|
+
section("Usage", `${tone.faint("$")} ${ROOT_HELP.usage}`),
|
|
87
|
+
...ROOT_HELP_GROUPS.map((group) =>
|
|
88
|
+
section(
|
|
89
|
+
group.title,
|
|
90
|
+
group.compact
|
|
91
|
+
? // A family of commands that each have their own help: their names are enough here.
|
|
92
|
+
paragraph(group.items.map((item) => item.label.split(" ")[0]).join(" "))
|
|
93
|
+
: helpRows(group.items, column)
|
|
94
|
+
)
|
|
95
|
+
),
|
|
96
|
+
section("Options", helpRows(ROOT_HELP.options, column)),
|
|
97
|
+
section("Examples", commands(CLI_EXAMPLES)),
|
|
98
|
+
`${tone.muted("Run")} sixb <command> --help ${tone.muted("for its options.")} ${tone.muted("Docs")} ${tone.url(DOCS_URL)}`
|
|
99
|
+
)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export function commandHelpView({
|
|
103
|
+
help,
|
|
104
|
+
errorMessage,
|
|
105
|
+
}: {
|
|
106
|
+
help: CliHelp
|
|
107
|
+
errorMessage?: string
|
|
108
|
+
}): string {
|
|
109
|
+
return screen(
|
|
110
|
+
stack(header(help.path.join(" ")), tone.muted(help.summary)),
|
|
111
|
+
errorMessage ? headline("fail", errorMessage) : null,
|
|
112
|
+
section("Usage", `${tone.faint("$")} ${help.usage}`),
|
|
113
|
+
help.commands.length > 0 ? section("Commands", helpRows(help.commands)) : null,
|
|
114
|
+
help.options.length > 0 ? section("Options", helpRows(help.options)) : null
|
|
115
|
+
)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// ─── Results ─────────────────────────────────────────────────────────────────
|
|
119
|
+
|
|
120
|
+
export function errorView({
|
|
121
|
+
title,
|
|
122
|
+
message,
|
|
123
|
+
remediation,
|
|
124
|
+
details = [],
|
|
125
|
+
}: {
|
|
126
|
+
title?: string
|
|
127
|
+
message: string
|
|
128
|
+
/** What to do next. Rendered apart from the diagnosis, not appended to it. */
|
|
129
|
+
remediation?: string
|
|
130
|
+
details?: readonly string[]
|
|
131
|
+
}): string {
|
|
132
|
+
const width = contentWidth() - 2
|
|
133
|
+
// `[SixbCLI]` and its kin say which package spoke, which a log needs and a person reading a
|
|
134
|
+
// terminal does not. Piped output keeps it.
|
|
135
|
+
const shown = colorLevel() > 0 ? message.replace(/^\[Sixb[A-Za-z]*\]\s+/, "") : message
|
|
136
|
+
const titled = Boolean(title && title !== "Error")
|
|
137
|
+
return screen(
|
|
138
|
+
stack(
|
|
139
|
+
titled
|
|
140
|
+
? marked(tone.fail(glyph.fail), title ?? "", (line) =>
|
|
141
|
+
paint(line, { color: palette.red, bold: true })
|
|
142
|
+
)
|
|
143
|
+
: marked(tone.fail(glyph.fail), shown, tone.strong),
|
|
144
|
+
...(titled ? wrap(shown, width).map((line) => ` ${line}`) : [])
|
|
145
|
+
),
|
|
146
|
+
details.length > 0 ? quoted(details) : null,
|
|
147
|
+
remediation ? rows([{ label: "Try this", value: remediation }]) : null
|
|
148
|
+
)
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const TITLE_STATUS = { green: "ok", yellow: "warn", red: "fail" } as const
|
|
152
|
+
|
|
153
|
+
export function keyValueResultView({
|
|
154
|
+
title,
|
|
155
|
+
subtitle,
|
|
156
|
+
items,
|
|
157
|
+
titleColor = "green",
|
|
158
|
+
message,
|
|
159
|
+
}: {
|
|
160
|
+
title: string
|
|
161
|
+
subtitle?: string
|
|
162
|
+
items: readonly KeyValueItem[]
|
|
163
|
+
titleColor?: "green" | "yellow" | "red"
|
|
164
|
+
message?: string
|
|
165
|
+
}): string {
|
|
166
|
+
return screen(
|
|
167
|
+
header(undefined, subtitle),
|
|
168
|
+
rows(items),
|
|
169
|
+
headline(TITLE_STATUS[titleColor], title),
|
|
170
|
+
message ? paragraph(message, tone.muted) : null
|
|
171
|
+
)
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** A list. The header names the command, which already says what the list is. */
|
|
175
|
+
export function tableResultView({
|
|
176
|
+
subtitle,
|
|
177
|
+
headers,
|
|
178
|
+
rows: cells,
|
|
179
|
+
emptyMessage,
|
|
180
|
+
}: {
|
|
181
|
+
subtitle?: string
|
|
182
|
+
headers: readonly string[]
|
|
183
|
+
rows: readonly (readonly string[])[]
|
|
184
|
+
emptyMessage: string
|
|
185
|
+
}): string {
|
|
186
|
+
return screen(
|
|
187
|
+
header(undefined, subtitle),
|
|
188
|
+
cells.length > 0 ? table(headers, cells) : tone.muted(emptyMessage)
|
|
189
|
+
)
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export function secretResultView({
|
|
193
|
+
title,
|
|
194
|
+
subtitle,
|
|
195
|
+
items,
|
|
196
|
+
secretLabel = "Token",
|
|
197
|
+
secret,
|
|
198
|
+
message = "Store this token now. Sixb will not show it again.",
|
|
199
|
+
}: {
|
|
200
|
+
title: string
|
|
201
|
+
subtitle?: string
|
|
202
|
+
items: readonly KeyValueItem[]
|
|
203
|
+
secretLabel?: string
|
|
204
|
+
secret: string
|
|
205
|
+
message?: string
|
|
206
|
+
}): string {
|
|
207
|
+
return screen(
|
|
208
|
+
header(undefined, subtitle),
|
|
209
|
+
rows(items),
|
|
210
|
+
headline("ok", title),
|
|
211
|
+
stack(tone.muted(secretLabel), paint(secret, { color: palette.blue, bold: true })),
|
|
212
|
+
message ? marked(tone.warn(glyph.warn), message, tone.warn) : null
|
|
213
|
+
)
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// ─── Roles ───────────────────────────────────────────────────────────────────
|
|
217
|
+
|
|
218
|
+
const RUNNING = `${tone.blue(glyph.live)} ${tone.strong("running")}`
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* A long-running role, once started: what it serves, then the hint to stop it. Its logs follow
|
|
222
|
+
* underneath.
|
|
223
|
+
*/
|
|
224
|
+
export function roleView({
|
|
225
|
+
command,
|
|
226
|
+
name,
|
|
227
|
+
items,
|
|
228
|
+
storage,
|
|
229
|
+
warnings = [],
|
|
230
|
+
}: {
|
|
231
|
+
/** The command that started it, such as `api` or `worker-group`. */
|
|
232
|
+
command: string
|
|
233
|
+
name: string
|
|
234
|
+
items: readonly KeyValueItem[]
|
|
235
|
+
storage?: string | null
|
|
236
|
+
warnings?: readonly string[]
|
|
237
|
+
}): string {
|
|
238
|
+
return screen(
|
|
239
|
+
header(command, name, RUNNING),
|
|
240
|
+
rows([...items, ...(storage ? [{ label: "storage", value: storage }] : [])]),
|
|
241
|
+
warningLines(warnings),
|
|
242
|
+
hints([["ctrl+c", "stop"]])
|
|
243
|
+
)
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
export function workerItems(
|
|
247
|
+
workers: readonly { readonly type: string; readonly concurrency: number }[]
|
|
248
|
+
): KeyValueItem[] {
|
|
249
|
+
return workers.map((worker) => ({
|
|
250
|
+
label: worker.type,
|
|
251
|
+
value: `concurrency ${worker.concurrency}`,
|
|
252
|
+
}))
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
export function devView({
|
|
256
|
+
name,
|
|
257
|
+
apiUrl,
|
|
258
|
+
apiDocsUrl,
|
|
259
|
+
wsUrl,
|
|
260
|
+
appUrl,
|
|
261
|
+
workers = [],
|
|
262
|
+
warnings = [],
|
|
263
|
+
}: {
|
|
264
|
+
name: string
|
|
265
|
+
apiUrl: string
|
|
266
|
+
apiDocsUrl: string
|
|
267
|
+
wsUrl: string
|
|
268
|
+
/** `null` when the app could not start; a warning says why. */
|
|
269
|
+
appUrl: string | null
|
|
270
|
+
workers?: readonly { readonly type: string; readonly concurrency: number }[]
|
|
271
|
+
warnings?: readonly string[]
|
|
272
|
+
}): string {
|
|
273
|
+
return screen(
|
|
274
|
+
header("dev", name, `${tone.blue(glyph.live)} ${tone.strong("ready")}`),
|
|
275
|
+
rows([
|
|
276
|
+
{ label: "app", value: appUrl ?? "not running" },
|
|
277
|
+
{ label: "api", value: apiUrl },
|
|
278
|
+
{ label: "docs", value: apiDocsUrl },
|
|
279
|
+
{ label: "events", value: wsUrl },
|
|
280
|
+
...(workers.length > 0
|
|
281
|
+
? [
|
|
282
|
+
{
|
|
283
|
+
label: "workers",
|
|
284
|
+
value: workers.map((worker) => `${worker.type} ${worker.concurrency}`).join(" · "),
|
|
285
|
+
},
|
|
286
|
+
]
|
|
287
|
+
: []),
|
|
288
|
+
]),
|
|
289
|
+
warningLines(warnings),
|
|
290
|
+
hints([["ctrl+c", "stop"]])
|
|
291
|
+
)
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// ─── Project commands ────────────────────────────────────────────────────────
|
|
295
|
+
|
|
296
|
+
interface Probe {
|
|
297
|
+
ok: boolean
|
|
298
|
+
warning?: boolean
|
|
299
|
+
message?: string
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
export function checkView({
|
|
303
|
+
projectId,
|
|
304
|
+
storage,
|
|
305
|
+
timeseries,
|
|
306
|
+
broker,
|
|
307
|
+
queues,
|
|
308
|
+
projectValidation,
|
|
309
|
+
markings,
|
|
310
|
+
ontology,
|
|
311
|
+
warnings,
|
|
312
|
+
}: {
|
|
313
|
+
projectId: string
|
|
314
|
+
storage: Probe
|
|
315
|
+
timeseries: Probe
|
|
316
|
+
broker: Probe
|
|
317
|
+
queues: Probe
|
|
318
|
+
projectValidation?: Probe
|
|
319
|
+
/**
|
|
320
|
+
* The pipeline markings preflight: what SQL steps derive, checked against projections. A warning
|
|
321
|
+
* reports projections whose applied version adds markings the code no longer declares.
|
|
322
|
+
*/
|
|
323
|
+
markings?: Probe
|
|
324
|
+
ontology?: { enabled: boolean; source: string; errors: number; warnings: number }
|
|
325
|
+
warnings: readonly string[]
|
|
326
|
+
}): string {
|
|
327
|
+
const validation = projectValidation ?? { ok: true }
|
|
328
|
+
const ontologyOk = (ontology?.errors ?? 0) === 0
|
|
329
|
+
const markingsCheck = markings ?? { ok: true }
|
|
330
|
+
const healthy =
|
|
331
|
+
[storage, timeseries, broker, queues, validation, markingsCheck].every((row) => row.ok) &&
|
|
332
|
+
ontologyOk
|
|
333
|
+
|
|
334
|
+
// The message wins when there is one, pass or fail: a probe that succeeded still says which
|
|
335
|
+
// provider answered and whether its schema is current. A bare "ok" the mark already says.
|
|
336
|
+
const probe = (label: string, row: Probe): Row => ({
|
|
337
|
+
label,
|
|
338
|
+
status: !row.ok ? "fail" : row.warning ? "warn" : "ok",
|
|
339
|
+
value: (row.message ?? (row.ok ? "" : "failed")).replace(/^ok( · )?/, ""),
|
|
340
|
+
})
|
|
341
|
+
const problems = warnings.length
|
|
342
|
+
return screen(
|
|
343
|
+
header("check", projectId),
|
|
344
|
+
rows([
|
|
345
|
+
probe("Storage", storage),
|
|
346
|
+
probe("Timeseries", timeseries),
|
|
347
|
+
probe("Broker", broker),
|
|
348
|
+
probe("Queues", queues),
|
|
349
|
+
probe("Project", validation),
|
|
350
|
+
probe("Markings", markingsCheck),
|
|
351
|
+
...(ontology
|
|
352
|
+
? [
|
|
353
|
+
{
|
|
354
|
+
label: "Ontology",
|
|
355
|
+
status: (ontologyOk ? "ok" : "fail") as Status,
|
|
356
|
+
value: `${plural(ontology.errors, "error")} · ${plural(ontology.warnings, "warning")}`,
|
|
357
|
+
note: relativePath(ontology.source),
|
|
358
|
+
},
|
|
359
|
+
]
|
|
360
|
+
: []),
|
|
361
|
+
]),
|
|
362
|
+
warningLines(warnings),
|
|
363
|
+
healthy
|
|
364
|
+
? headline(
|
|
365
|
+
"ok",
|
|
366
|
+
`${projectId} is healthy`,
|
|
367
|
+
problems > 0 ? plural(problems, "warning") : undefined
|
|
368
|
+
)
|
|
369
|
+
: headline("fail", `${projectId} has issues`)
|
|
370
|
+
)
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
export function buildView({ outdir, seconds }: { outdir: string; seconds?: number }): string {
|
|
374
|
+
return screen(
|
|
375
|
+
headline(
|
|
376
|
+
"ok",
|
|
377
|
+
seconds === undefined ? "Built" : `Built in ${seconds.toFixed(1)}s`,
|
|
378
|
+
undefined,
|
|
379
|
+
relativePath(outdir)
|
|
380
|
+
)
|
|
381
|
+
)
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
export function typegenView({
|
|
385
|
+
path,
|
|
386
|
+
objectTypes,
|
|
387
|
+
skipped,
|
|
388
|
+
written,
|
|
389
|
+
}: {
|
|
390
|
+
path: string
|
|
391
|
+
objectTypes: number
|
|
392
|
+
skipped: boolean
|
|
393
|
+
written: boolean
|
|
394
|
+
}): string {
|
|
395
|
+
return screen(
|
|
396
|
+
headline(
|
|
397
|
+
skipped ? "idle" : "ok",
|
|
398
|
+
`Ontology types ${skipped ? "skipped" : written ? "generated" : "current"}`,
|
|
399
|
+
plural(objectTypes, "object type"),
|
|
400
|
+
relativePath(path)
|
|
401
|
+
)
|
|
402
|
+
)
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
export function dbMigrateView({
|
|
406
|
+
projectId,
|
|
407
|
+
status,
|
|
408
|
+
applied = [],
|
|
409
|
+
}: {
|
|
410
|
+
projectId: string
|
|
411
|
+
status: "migrated" | "current" | "skipped"
|
|
412
|
+
/** Migration step ids this run applied, named so the output can be checked. */
|
|
413
|
+
applied?: readonly string[]
|
|
414
|
+
}): string {
|
|
415
|
+
return screen(
|
|
416
|
+
stack(
|
|
417
|
+
headline("ok", "Database migrations complete", `${projectId} · storage ${status}`),
|
|
418
|
+
...applied.map((step) => ` ${tone.faint(glyph.rule)} ${tone.muted(step)}`)
|
|
419
|
+
)
|
|
420
|
+
)
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
export function lakeCheckView({
|
|
424
|
+
projectId,
|
|
425
|
+
warnings = [],
|
|
426
|
+
}: {
|
|
427
|
+
projectId: string
|
|
428
|
+
warnings?: readonly string[]
|
|
429
|
+
}): string {
|
|
430
|
+
return screen(headline("ok", "Lake definitions compatible", projectId), warningLines(warnings))
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
export interface LakeCleanupReport {
|
|
434
|
+
readonly dryRun: boolean
|
|
435
|
+
readonly expireOlderThan: string
|
|
436
|
+
readonly deleteOlderThan: string
|
|
437
|
+
readonly snapshots: number
|
|
438
|
+
readonly keptSnapshots?: number
|
|
439
|
+
readonly oldFiles: number
|
|
440
|
+
readonly orphanedFiles: number
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
export function lakeCleanupView({
|
|
444
|
+
projectId,
|
|
445
|
+
report,
|
|
446
|
+
}: {
|
|
447
|
+
projectId: string
|
|
448
|
+
report: LakeCleanupReport
|
|
449
|
+
}): string {
|
|
450
|
+
return screen(
|
|
451
|
+
header(report.dryRun ? "lake cleanup --dry-run" : "lake cleanup", projectId),
|
|
452
|
+
rows([
|
|
453
|
+
{ label: "Expire older than", value: report.expireOlderThan },
|
|
454
|
+
{ label: "Delete older than", value: report.deleteOlderThan },
|
|
455
|
+
{ label: "Snapshots", value: String(report.snapshots) },
|
|
456
|
+
...(report.keptSnapshots === undefined
|
|
457
|
+
? []
|
|
458
|
+
: [{ label: "Kept snapshots", value: String(report.keptSnapshots) }]),
|
|
459
|
+
{ label: "Old files", value: String(report.oldFiles) },
|
|
460
|
+
{ label: "Orphaned files", value: String(report.orphanedFiles) },
|
|
461
|
+
]),
|
|
462
|
+
headline(
|
|
463
|
+
"ok",
|
|
464
|
+
report.dryRun ? "Lake cleanup dry run complete" : "Lake cleanup complete",
|
|
465
|
+
report.dryRun ? "nothing was deleted" : undefined
|
|
466
|
+
)
|
|
467
|
+
)
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
export function initView({
|
|
471
|
+
name,
|
|
472
|
+
files,
|
|
473
|
+
commands: next,
|
|
474
|
+
}: {
|
|
475
|
+
name: string
|
|
476
|
+
files: readonly string[]
|
|
477
|
+
commands: readonly string[]
|
|
478
|
+
}): string {
|
|
479
|
+
return screen(
|
|
480
|
+
headline("ok", "Sixb initialized", `${name} · ${plural(files.length, "file")}`),
|
|
481
|
+
section("Next steps", commands(next))
|
|
482
|
+
)
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
/** A path under the working directory reads shorter relative to it. */
|
|
486
|
+
function relativePath(path: string): string {
|
|
487
|
+
const cwd = process.cwd()
|
|
488
|
+
if (path === cwd) return "."
|
|
489
|
+
return path.startsWith(`${cwd}/`) ? path.slice(cwd.length + 1) : path
|
|
490
|
+
}
|
package/src/ui/theme.ts
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The CLI's look, shared by the printed screens and the live ones.
|
|
3
|
+
*
|
|
4
|
+
* Sixb's colors: ink and paper, one blue for a live signal, and the "water" blues the mosaic fills
|
|
5
|
+
* with, palest first. Body text keeps the terminal's own foreground, so every screen reads on a
|
|
6
|
+
* dark or a light terminal; color marks status, never content.
|
|
7
|
+
*/
|
|
8
|
+
export const palette = {
|
|
9
|
+
blue: "#0a84ff",
|
|
10
|
+
water: ["#a6cbfb", "#6fb0fc", "#3d95fd", "#0a84ff"],
|
|
11
|
+
green: "#30d158",
|
|
12
|
+
amber: "#ff9f0a",
|
|
13
|
+
red: "#ff453a",
|
|
14
|
+
muted: "#8b919a",
|
|
15
|
+
faint: "#666b74",
|
|
16
|
+
} as const
|
|
17
|
+
|
|
18
|
+
export const glyph = {
|
|
19
|
+
/** The brand mark: the logo's slab, as one cell. A tile when it counts progress. */
|
|
20
|
+
mark: "▰",
|
|
21
|
+
tile: "▱",
|
|
22
|
+
ok: "✓",
|
|
23
|
+
fail: "✕",
|
|
24
|
+
warn: "▲",
|
|
25
|
+
live: "●",
|
|
26
|
+
idle: "○",
|
|
27
|
+
dot: "·",
|
|
28
|
+
arrow: "→",
|
|
29
|
+
prompt: "›",
|
|
30
|
+
restart: "↻",
|
|
31
|
+
rule: "│",
|
|
32
|
+
} as const
|
|
33
|
+
|
|
34
|
+
export const SPINNER_FRAMES = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"] as const
|
|
35
|
+
|
|
36
|
+
type ColorLevel = 0 | 1 | 2 | 3
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* How much color the terminal takes: none, the 16 named colors, the 256-color cube, or 24-bit.
|
|
40
|
+
* `NO_COLOR` and `FORCE_COLOR` win; a pipe or a dumb terminal gets none.
|
|
41
|
+
*/
|
|
42
|
+
export function colorLevel(stream: { readonly isTTY?: boolean } = process.stdout): ColorLevel {
|
|
43
|
+
if ("NO_COLOR" in process.env && process.env.NO_COLOR !== "") return 0
|
|
44
|
+
const forced = process.env.FORCE_COLOR
|
|
45
|
+
if (forced !== undefined && forced !== "") {
|
|
46
|
+
if (forced === "0" || forced === "false") return 0
|
|
47
|
+
return forced === "1" || forced === "true" ? (Math.max(1, detectedLevel()) as ColorLevel) : 3
|
|
48
|
+
}
|
|
49
|
+
if (!stream.isTTY || process.env.TERM === "dumb") return 0
|
|
50
|
+
return detectedLevel()
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function detectedLevel(): ColorLevel {
|
|
54
|
+
const colorterm = process.env.COLORTERM?.toLowerCase()
|
|
55
|
+
if (colorterm === "truecolor" || colorterm === "24bit") return 3
|
|
56
|
+
// Terminal.app reports neither, and draws 24-bit colors as noise.
|
|
57
|
+
if (process.env.TERM_PROGRAM === "Apple_Terminal") return 2
|
|
58
|
+
if (process.env.TERM_PROGRAM && process.env.TERM_PROGRAM !== "tmux") return 3
|
|
59
|
+
if (process.env.TERM?.includes("256")) return 2
|
|
60
|
+
return 1
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const NAMED: Record<string, number> = {
|
|
64
|
+
[palette.blue]: 34,
|
|
65
|
+
[palette.green]: 32,
|
|
66
|
+
[palette.amber]: 33,
|
|
67
|
+
[palette.red]: 31,
|
|
68
|
+
[palette.muted]: 90,
|
|
69
|
+
[palette.faint]: 90,
|
|
70
|
+
...Object.fromEntries(palette.water.map((hex) => [hex, 34])),
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function rgb(hex: string): [number, number, number] {
|
|
74
|
+
const value = Number.parseInt(hex.slice(1), 16)
|
|
75
|
+
return [(value >> 16) & 255, (value >> 8) & 255, value & 255]
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function cube(hex: string): number {
|
|
79
|
+
const [r, g, b] = rgb(hex).map((channel) => Math.round((channel / 255) * 5))
|
|
80
|
+
return 16 + 36 * (r ?? 0) + 6 * (g ?? 0) + (b ?? 0)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function foreground(hex: string, level: ColorLevel): string {
|
|
84
|
+
if (level === 3) return `38;2;${rgb(hex).join(";")}`
|
|
85
|
+
if (level === 2) return `38;5;${cube(hex)}`
|
|
86
|
+
return String(NAMED[hex] ?? 39)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export interface Paint {
|
|
90
|
+
readonly color?: string
|
|
91
|
+
readonly bold?: boolean
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Styles text for this terminal; the text comes back unchanged where color is off. */
|
|
95
|
+
export function paint(text: string, style: Paint, level: ColorLevel = colorLevel()): string {
|
|
96
|
+
if (level === 0 || text === "") return text
|
|
97
|
+
const codes: string[] = []
|
|
98
|
+
if (style.bold) codes.push("1")
|
|
99
|
+
if (style.color) codes.push(foreground(style.color, level))
|
|
100
|
+
return codes.length === 0 ? text : `\x1b[${codes.join(";")}m${text}\x1b[0m`
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export const tone = {
|
|
104
|
+
strong: (text: string) => paint(text, { bold: true }),
|
|
105
|
+
muted: (text: string) => paint(text, { color: palette.muted }),
|
|
106
|
+
faint: (text: string) => paint(text, { color: palette.faint }),
|
|
107
|
+
blue: (text: string) => paint(text, { color: palette.blue }),
|
|
108
|
+
ok: (text: string) => paint(text, { color: palette.green }),
|
|
109
|
+
warn: (text: string) => paint(text, { color: palette.amber }),
|
|
110
|
+
fail: (text: string) => paint(text, { color: palette.red }),
|
|
111
|
+
url: (text: string) => link(text, paint(text, { color: palette.blue })),
|
|
112
|
+
} as const
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Makes `text` open `url` on click (OSC 8). Terminals that know the sequence show only the text;
|
|
116
|
+
* Terminal.app and the Linux console do not, and get the text alone.
|
|
117
|
+
*/
|
|
118
|
+
function link(url: string, text: string): string {
|
|
119
|
+
if (colorLevel() === 0) return text
|
|
120
|
+
if (process.env.TERM_PROGRAM === "Apple_Terminal" || process.env.TERM === "linux") return text
|
|
121
|
+
return `\x1b]8;;${url}\x07${text}\x1b]8;;\x07`
|
|
122
|
+
}
|
package/dist/lib/role-view.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { RoleStartupPanel } from "../ui";
|
|
2
|
-
export interface RoleView {
|
|
3
|
-
startup(loading: {
|
|
4
|
-
readonly title: string;
|
|
5
|
-
readonly subtitle: string;
|
|
6
|
-
readonly status: string;
|
|
7
|
-
}): RoleStartupPanel;
|
|
8
|
-
error(error: unknown): Promise<void>;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* How a long-running role reports itself: the Ink panels in a terminal, plain lines in a log.
|
|
12
|
-
*
|
|
13
|
-
* Ink's layout engine keeps about 45 MB for the life of the process once it is imported. `app`
|
|
14
|
-
* runs under a supervisor and serves static files, so outside a terminal it never loads it.
|
|
15
|
-
*
|
|
16
|
-
* Call this before the role sets NODE_ENV. Bun compiles JSX for the mode the process started in,
|
|
17
|
-
* and React loaded after the change cannot run it: the panels then render nothing, or throw. Ink
|
|
18
|
-
* stays out of logs for a second reason: its error panel could come out empty there.
|
|
19
|
-
*/
|
|
20
|
-
export declare function loadRoleView(): Promise<RoleView>;
|
|
21
|
-
//# sourceMappingURL=role-view.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"role-view.d.ts","sourceRoot":"","sources":["../../src/lib/role-view.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,OAAO,CAAA;AAG7C,MAAM,WAAW,QAAQ;IACvB,OAAO,CAAC,OAAO,EAAE;QACf,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;QACtB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;QACzB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;KACxB,GAAG,gBAAgB,CAAA;IACpB,KAAK,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CACrC;AAED;;;;;;;;;GASG;AACH,wBAAsB,YAAY,IAAI,OAAO,CAAC,QAAQ,CAAC,CAMtD"}
|
package/src/commands/build.tsx
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { mkdir } from "node:fs/promises"
|
|
2
|
-
import { dirname, join, resolve } from "node:path"
|
|
3
|
-
import { createCustomApp } from "@sixb/app/server"
|
|
4
|
-
import { buildRuntime } from "../lib/build-runtime"
|
|
5
|
-
import { generateProjectTypes } from "../lib/typegen"
|
|
6
|
-
import { BuildView, ErrorView, renderStatic } from "../ui"
|
|
7
|
-
|
|
8
|
-
export interface BuildOptions {
|
|
9
|
-
entry?: string
|
|
10
|
-
outdir?: string
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export async function runBuild(options: BuildOptions = {}) {
|
|
14
|
-
const entry = resolve(options.entry ?? "sixb.config.ts")
|
|
15
|
-
const outdir = resolve(options.outdir ?? ".sixb/dist")
|
|
16
|
-
const projectRoot = dirname(entry)
|
|
17
|
-
|
|
18
|
-
await generateProjectTypes({ entry })
|
|
19
|
-
await mkdir(outdir, { recursive: true })
|
|
20
|
-
|
|
21
|
-
const result = await buildRuntime(entry, outdir)
|
|
22
|
-
|
|
23
|
-
if (!result.success) {
|
|
24
|
-
const details = result.logs.map(String)
|
|
25
|
-
await renderStatic(
|
|
26
|
-
<ErrorView title="Build failed" message="Compilation errors" details={details} />
|
|
27
|
-
)
|
|
28
|
-
process.exit(1)
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const customApp = await createCustomApp({
|
|
32
|
-
rootDir: projectRoot,
|
|
33
|
-
// Keep production build inputs separate from the files watched by `sixb dev`.
|
|
34
|
-
// Sharing `.sixb/generated` lets this command replace the dev app's injected
|
|
35
|
-
// API origin and HTML bundle, causing Bun to hot-reload a same-origin client.
|
|
36
|
-
generatedDir: join(".sixb", "build", "app"),
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
try {
|
|
40
|
-
const appResult = await customApp.build({
|
|
41
|
-
outdir: resolve(outdir, "app"),
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
if (!appResult.success) {
|
|
45
|
-
await renderStatic(
|
|
46
|
-
<ErrorView
|
|
47
|
-
title="App build failed"
|
|
48
|
-
message="Failed to build the app"
|
|
49
|
-
details={appResult.logs ?? []}
|
|
50
|
-
/>
|
|
51
|
-
)
|
|
52
|
-
process.exit(1)
|
|
53
|
-
}
|
|
54
|
-
} catch (error) {
|
|
55
|
-
// e.g. the app/globals.css Tailwind compile failed — surface the labeled
|
|
56
|
-
// message instead of an unhandled stack trace.
|
|
57
|
-
const message = error instanceof Error ? error.message : String(error)
|
|
58
|
-
await renderStatic(
|
|
59
|
-
<ErrorView title="App build failed" message="Failed to build the app" details={[message]} />
|
|
60
|
-
)
|
|
61
|
-
process.exit(1)
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
await renderStatic(<BuildView entry={entry} outdir={outdir} />)
|
|
65
|
-
}
|