@sixb/cli 0.1.21 → 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 +18 -3
- 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.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 +2 -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 -244
- 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 +19 -18
- 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} +27 -18
- 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} +17 -12
- 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 +4 -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 -33
- package/src/commands/typegen.tsx +0 -18
- package/src/lib/role-view.ts +0 -49
- package/src/ui/index.tsx +0 -1398
- /package/src/commands/{dev.tsx → dev.ts} +0 -0
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/** @jsxImportSource @opentui/react */
|
|
2
|
+
import type { KeyEvent, PasteEvent } from "@opentui/core"
|
|
3
|
+
import { useKeyboard, usePaste } from "@opentui/react"
|
|
4
|
+
import { type ReactNode, useRef, useState } from "react"
|
|
5
|
+
import { glyph, tone } from "../theme"
|
|
6
|
+
import { BOLD, Hints } from "./components"
|
|
7
|
+
import { type LiveColors, startFooter } from "./session"
|
|
8
|
+
|
|
9
|
+
/** Thrown when the person answering a prompt backs out with esc or ctrl+c. */
|
|
10
|
+
export class PromptCancelledError extends Error {
|
|
11
|
+
constructor() {
|
|
12
|
+
super("[SixbCLI] Cancelled.")
|
|
13
|
+
this.name = "PromptCancelledError"
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Asks for one line of text, in a footer under the command. The answer stays in the scrollback
|
|
19
|
+
* the way it was asked: `✓ Project directory acme-ops`.
|
|
20
|
+
*/
|
|
21
|
+
export async function promptText(options: {
|
|
22
|
+
readonly command: string
|
|
23
|
+
readonly label: string
|
|
24
|
+
/** What Enter accepts when nothing was typed. */
|
|
25
|
+
readonly defaultValue?: string
|
|
26
|
+
readonly hint?: string
|
|
27
|
+
/** A message for an answer that will not do; `null` when it will. */
|
|
28
|
+
readonly validate?: (value: string) => string | null
|
|
29
|
+
}): Promise<string> {
|
|
30
|
+
const value = await ask<string>(4, options.command, (colors, resolve, reject) => (
|
|
31
|
+
<TextPrompt options={options} colors={colors} onSubmit={resolve} onCancel={reject} />
|
|
32
|
+
))
|
|
33
|
+
answered(options.label, value)
|
|
34
|
+
return value
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface Choice<T> {
|
|
38
|
+
readonly label: string
|
|
39
|
+
readonly value: T
|
|
40
|
+
readonly detail?: string
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Asks for one of a few choices, picked with the arrow keys. */
|
|
44
|
+
export async function promptSelect<T>(options: {
|
|
45
|
+
readonly command: string
|
|
46
|
+
readonly label: string
|
|
47
|
+
readonly choices: readonly Choice<T>[]
|
|
48
|
+
readonly initial?: number
|
|
49
|
+
}): Promise<T> {
|
|
50
|
+
const rows = Math.min(options.choices.length, 8) + 4
|
|
51
|
+
const choice = await ask<Choice<T>>(rows, options.command, (colors, resolve, reject) => (
|
|
52
|
+
<SelectPrompt options={options} colors={colors} onSubmit={resolve} onCancel={reject} />
|
|
53
|
+
))
|
|
54
|
+
answered(options.label, choice.label)
|
|
55
|
+
return choice.value
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async function ask<T>(
|
|
59
|
+
rows: number,
|
|
60
|
+
command: string,
|
|
61
|
+
build: (colors: LiveColors, resolve: (value: T) => void, reject: () => void) => ReactNode
|
|
62
|
+
): Promise<T> {
|
|
63
|
+
const footer = await startFooter({ rows: rows + 1 })
|
|
64
|
+
footer.print(`\n ${tone.blue(glyph.mark)} ${tone.strong(`sixb ${command}`)}\n`)
|
|
65
|
+
try {
|
|
66
|
+
return await new Promise<T>((resolve, reject) => {
|
|
67
|
+
footer.render(build(footer.colors, resolve, () => reject(new PromptCancelledError())))
|
|
68
|
+
})
|
|
69
|
+
} finally {
|
|
70
|
+
await footer.stop()
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** The answer, left in the scrollback the way it was asked. */
|
|
75
|
+
function answered(label: string, value: string): void {
|
|
76
|
+
process.stdout.write(` ${tone.ok(glyph.ok)} ${tone.muted(label)} ${value}\n`)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function TextPrompt({
|
|
80
|
+
options,
|
|
81
|
+
colors,
|
|
82
|
+
onSubmit,
|
|
83
|
+
onCancel,
|
|
84
|
+
}: {
|
|
85
|
+
readonly options: Parameters<typeof promptText>[0]
|
|
86
|
+
readonly colors: LiveColors
|
|
87
|
+
readonly onSubmit: (value: string) => void
|
|
88
|
+
readonly onCancel: () => void
|
|
89
|
+
}) {
|
|
90
|
+
const [value, setValue] = useState("")
|
|
91
|
+
const [error, setError] = useState<string | null>(null)
|
|
92
|
+
const current = useRef("")
|
|
93
|
+
current.current = value
|
|
94
|
+
|
|
95
|
+
const insert = (text: string) => {
|
|
96
|
+
const clean = text.replace(/[\x00-\x1f\x7f]/g, "")
|
|
97
|
+
if (!clean) return
|
|
98
|
+
setValue((previous) => previous + clean)
|
|
99
|
+
setError(null)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
useKeyboard((key: KeyEvent) => {
|
|
103
|
+
if ((key.ctrl && key.name === "c") || key.name === "escape") return onCancel()
|
|
104
|
+
if (key.name === "return") {
|
|
105
|
+
const answer = current.current.trim() || options.defaultValue || ""
|
|
106
|
+
const problem = answer ? (options.validate?.(answer) ?? null) : "An answer is required."
|
|
107
|
+
if (problem) return setError(problem)
|
|
108
|
+
return onSubmit(answer)
|
|
109
|
+
}
|
|
110
|
+
if (key.name === "backspace") return setValue((previous) => previous.slice(0, -1))
|
|
111
|
+
if (key.ctrl && key.name === "u") return setValue("")
|
|
112
|
+
if (!key.ctrl && !key.meta && key.sequence && key.sequence.length === 1) insert(key.sequence)
|
|
113
|
+
})
|
|
114
|
+
usePaste((event: PasteEvent) => insert(new TextDecoder().decode(event.bytes)))
|
|
115
|
+
|
|
116
|
+
const empty = value.length === 0
|
|
117
|
+
return (
|
|
118
|
+
<box flexDirection="column" paddingLeft={2}>
|
|
119
|
+
<text>
|
|
120
|
+
<span fg={colors.blue}>{`${glyph.prompt} `}</span>
|
|
121
|
+
<span fg={colors.text} attributes={BOLD}>
|
|
122
|
+
{options.label}
|
|
123
|
+
</span>
|
|
124
|
+
<span fg={colors.muted}>{" "}</span>
|
|
125
|
+
{empty && options.defaultValue ? (
|
|
126
|
+
<span fg={colors.faint}>{options.defaultValue}</span>
|
|
127
|
+
) : (
|
|
128
|
+
<span fg={colors.text}>{value}</span>
|
|
129
|
+
)}
|
|
130
|
+
<span fg={colors.blue}>▏</span>
|
|
131
|
+
</text>
|
|
132
|
+
<text fg={error ? colors.red : colors.muted}>{` ${error ?? options.hint ?? ""}`}</text>
|
|
133
|
+
<box height={1} />
|
|
134
|
+
<Hints
|
|
135
|
+
colors={colors}
|
|
136
|
+
items={[
|
|
137
|
+
["enter", empty && options.defaultValue ? "accept" : "continue"],
|
|
138
|
+
["esc", "cancel"],
|
|
139
|
+
]}
|
|
140
|
+
/>
|
|
141
|
+
</box>
|
|
142
|
+
)
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function SelectPrompt<T>({
|
|
146
|
+
options,
|
|
147
|
+
colors,
|
|
148
|
+
onSubmit,
|
|
149
|
+
onCancel,
|
|
150
|
+
}: {
|
|
151
|
+
readonly options: Parameters<typeof promptSelect<T>>[0]
|
|
152
|
+
readonly colors: LiveColors
|
|
153
|
+
readonly onSubmit: (choice: Choice<T>) => void
|
|
154
|
+
readonly onCancel: () => void
|
|
155
|
+
}) {
|
|
156
|
+
const [selected, setSelected] = useState(options.initial ?? 0)
|
|
157
|
+
const count = options.choices.length
|
|
158
|
+
const visible = Math.min(count, 8)
|
|
159
|
+
const first = Math.min(Math.max(0, selected - visible + 1), Math.max(0, count - visible))
|
|
160
|
+
|
|
161
|
+
useKeyboard((key: KeyEvent) => {
|
|
162
|
+
if ((key.ctrl && key.name === "c") || key.name === "escape") return onCancel()
|
|
163
|
+
if (key.name === "up" || key.name === "k") setSelected((index) => (index - 1 + count) % count)
|
|
164
|
+
else if (key.name === "down" || key.name === "j") setSelected((index) => (index + 1) % count)
|
|
165
|
+
else if (key.name === "return") {
|
|
166
|
+
const choice = options.choices[selected]
|
|
167
|
+
if (choice) onSubmit(choice)
|
|
168
|
+
}
|
|
169
|
+
})
|
|
170
|
+
|
|
171
|
+
const labelWidth = Math.max(...options.choices.map((choice) => choice.label.length)) + 2
|
|
172
|
+
return (
|
|
173
|
+
<box flexDirection="column" paddingLeft={2}>
|
|
174
|
+
<text>
|
|
175
|
+
<span fg={colors.blue}>{`${glyph.prompt} `}</span>
|
|
176
|
+
<span fg={colors.text} attributes={BOLD}>
|
|
177
|
+
{options.label}
|
|
178
|
+
</span>
|
|
179
|
+
</text>
|
|
180
|
+
{options.choices.slice(first, first + visible).map((choice, offset) => {
|
|
181
|
+
const active = first + offset === selected
|
|
182
|
+
return (
|
|
183
|
+
<text key={choice.label}>
|
|
184
|
+
<span fg={active ? colors.blue : colors.faint}>
|
|
185
|
+
{active ? ` ${glyph.mark} ` : ` ${glyph.tile} `}
|
|
186
|
+
</span>
|
|
187
|
+
<span fg={active ? colors.text : colors.muted} attributes={active ? BOLD : 0}>
|
|
188
|
+
{choice.label.padEnd(labelWidth)}
|
|
189
|
+
</span>
|
|
190
|
+
<span fg={colors.faint}>{choice.detail ?? ""}</span>
|
|
191
|
+
</text>
|
|
192
|
+
)
|
|
193
|
+
})}
|
|
194
|
+
<box height={1} />
|
|
195
|
+
<Hints
|
|
196
|
+
colors={colors}
|
|
197
|
+
items={[
|
|
198
|
+
["↑↓", "choose"],
|
|
199
|
+
["enter", "select"],
|
|
200
|
+
["esc", "cancel"],
|
|
201
|
+
]}
|
|
202
|
+
/>
|
|
203
|
+
</box>
|
|
204
|
+
)
|
|
205
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { format } from "node:util"
|
|
2
|
+
import { type CliRenderer, createCliRenderer, TextRenderable } from "@opentui/core"
|
|
3
|
+
import { createRoot } from "@opentui/react"
|
|
4
|
+
import type { ReactNode } from "react"
|
|
5
|
+
import { palette } from "../theme"
|
|
6
|
+
import { ansiToStyledText } from "./ansi"
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The live screens draw a footer pinned to the bottom of the terminal while output scrolls above
|
|
10
|
+
* it (OpenTUI's split-footer mode). Nothing leaves the main screen: when the footer goes, what
|
|
11
|
+
* scrolled past stays in the scrollback like any other command's output.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/** Sixb's palette, plus the terminal's foreground: OpenTUI needs a color for plain text. */
|
|
15
|
+
export type LiveColors = typeof palette & { readonly text: string }
|
|
16
|
+
|
|
17
|
+
export interface Footer {
|
|
18
|
+
readonly colors: LiveColors
|
|
19
|
+
readonly renderer: CliRenderer
|
|
20
|
+
render(node: ReactNode): void
|
|
21
|
+
/** Writes text, which may carry SGR colors, into the scrollback above the footer. */
|
|
22
|
+
print(text: string): void
|
|
23
|
+
/** How many rows the footer takes; it never takes more than the terminal has. */
|
|
24
|
+
resize(rows: number): void
|
|
25
|
+
/** Removes the footer and gives the terminal back. */
|
|
26
|
+
stop(): Promise<void>
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export async function startFooter(options: { readonly rows: number }): Promise<Footer> {
|
|
30
|
+
const renderer = await createCliRenderer({
|
|
31
|
+
screenMode: "split-footer",
|
|
32
|
+
footerHeight: options.rows,
|
|
33
|
+
externalOutputMode: "capture-stdout",
|
|
34
|
+
exitOnCtrlC: false,
|
|
35
|
+
clearOnShutdown: true,
|
|
36
|
+
})
|
|
37
|
+
const mode = await renderer.waitForThemeMode(150).catch(() => null)
|
|
38
|
+
const colors: LiveColors = {
|
|
39
|
+
...palette,
|
|
40
|
+
text: mode === "light" ? "#17181c" : "#eceef2",
|
|
41
|
+
}
|
|
42
|
+
const root = createRoot(renderer)
|
|
43
|
+
|
|
44
|
+
const print = (text: string) => {
|
|
45
|
+
const body = text.replace(/\n+$/, "")
|
|
46
|
+
if (renderer.isDestroyed) {
|
|
47
|
+
process.stdout.write(`${body}\n`)
|
|
48
|
+
return
|
|
49
|
+
}
|
|
50
|
+
renderer.writeToScrollback((context) => {
|
|
51
|
+
const height = body
|
|
52
|
+
.split("\n")
|
|
53
|
+
.reduce(
|
|
54
|
+
(rows, line) =>
|
|
55
|
+
rows + Math.max(1, Math.ceil(Bun.stringWidth(line) / Math.max(1, context.width))),
|
|
56
|
+
0
|
|
57
|
+
)
|
|
58
|
+
const node = new TextRenderable(context.renderContext, {
|
|
59
|
+
content: ansiToStyledText(body, colors.text),
|
|
60
|
+
width: context.width,
|
|
61
|
+
height,
|
|
62
|
+
wrapMode: "char",
|
|
63
|
+
})
|
|
64
|
+
return {
|
|
65
|
+
root: node,
|
|
66
|
+
width: context.width,
|
|
67
|
+
height,
|
|
68
|
+
startOnNewLine: true,
|
|
69
|
+
trailingNewline: true,
|
|
70
|
+
}
|
|
71
|
+
})
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Bun's console writes past `process.stdout.write`, so it would draw over the footer.
|
|
75
|
+
const methods = ["log", "info", "warn", "error", "debug"] as const
|
|
76
|
+
const originals = methods.map((method) => console[method])
|
|
77
|
+
for (const method of methods) {
|
|
78
|
+
console[method] = (...args: unknown[]) => print(format(...args))
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
let stopped: Promise<void> | null = null
|
|
82
|
+
return {
|
|
83
|
+
colors,
|
|
84
|
+
renderer,
|
|
85
|
+
render: (node) => root.render(node),
|
|
86
|
+
print,
|
|
87
|
+
resize(rows) {
|
|
88
|
+
renderer.footerHeight = Math.max(1, Math.min(rows, renderer.terminalHeight - 1))
|
|
89
|
+
},
|
|
90
|
+
stop() {
|
|
91
|
+
stopped ??= (async () => {
|
|
92
|
+
methods.forEach((method, index) => {
|
|
93
|
+
console[method] = originals[index] as (typeof console)[typeof method]
|
|
94
|
+
})
|
|
95
|
+
root.unmount()
|
|
96
|
+
renderer.destroy()
|
|
97
|
+
// What prints next would race the footer being cleared without this.
|
|
98
|
+
await renderer.closed
|
|
99
|
+
})()
|
|
100
|
+
return stopped
|
|
101
|
+
},
|
|
102
|
+
}
|
|
103
|
+
}
|