@sixb/cli 0.1.25 → 0.2.0

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 (109) hide show
  1. package/README.md +5 -5
  2. package/dist/commands/agent.d.ts +16 -0
  3. package/dist/commands/agent.d.ts.map +1 -0
  4. package/dist/commands/api.d.ts.map +1 -1
  5. package/dist/commands/check.d.ts.map +1 -1
  6. package/dist/commands/deploy.d.ts.map +1 -1
  7. package/dist/commands/dev-runner.d.ts +0 -1
  8. package/dist/commands/dev-runner.d.ts.map +1 -1
  9. package/dist/commands/dev.d.ts.map +1 -1
  10. package/dist/commands/env.d.ts +31 -0
  11. package/dist/commands/env.d.ts.map +1 -0
  12. package/dist/commands/worker-group.d.ts +0 -1
  13. package/dist/commands/worker-group.d.ts.map +1 -1
  14. package/dist/commands/worker.d.ts +0 -1
  15. package/dist/commands/worker.d.ts.map +1 -1
  16. package/dist/lib/command-line.d.ts +41 -6
  17. package/dist/lib/command-line.d.ts.map +1 -1
  18. package/dist/lib/deploy-release.d.ts +2 -0
  19. package/dist/lib/deploy-release.d.ts.map +1 -1
  20. package/dist/lib/deploy-source.d.ts +2 -0
  21. package/dist/lib/deploy-source.d.ts.map +1 -1
  22. package/dist/lib/env-config.d.ts +17 -0
  23. package/dist/lib/env-config.d.ts.map +1 -0
  24. package/dist/lib/env-file.d.ts +16 -0
  25. package/dist/lib/env-file.d.ts.map +1 -0
  26. package/dist/lib/github-ci.d.ts.map +1 -1
  27. package/dist/lib/hidden-prompt.d.ts +19 -0
  28. package/dist/lib/hidden-prompt.d.ts.map +1 -0
  29. package/dist/lib/runtime.d.ts +0 -1
  30. package/dist/lib/runtime.d.ts.map +1 -1
  31. package/dist/lib/worker-registry.d.ts +0 -1
  32. package/dist/lib/worker-registry.d.ts.map +1 -1
  33. package/dist/tui/app.d.ts +27 -0
  34. package/dist/tui/app.d.ts.map +1 -0
  35. package/dist/tui/brand.d.ts +7 -0
  36. package/dist/tui/brand.d.ts.map +1 -0
  37. package/dist/tui/computer.d.ts +8 -0
  38. package/dist/tui/computer.d.ts.map +1 -0
  39. package/dist/tui/connection.d.ts +45 -0
  40. package/dist/tui/connection.d.ts.map +1 -0
  41. package/dist/tui/context.d.ts +13 -0
  42. package/dist/tui/context.d.ts.map +1 -0
  43. package/dist/tui/format.d.ts +118 -0
  44. package/dist/tui/format.d.ts.map +1 -0
  45. package/dist/tui/index.d.ts +12 -0
  46. package/dist/tui/index.d.ts.map +1 -0
  47. package/dist/tui/markdown.d.ts +18 -0
  48. package/dist/tui/markdown.d.ts.map +1 -0
  49. package/dist/tui/palette.d.ts +25 -0
  50. package/dist/tui/palette.d.ts.map +1 -0
  51. package/dist/tui/parts.d.ts +74 -0
  52. package/dist/tui/parts.d.ts.map +1 -0
  53. package/dist/tui/runner.d.ts +75 -0
  54. package/dist/tui/runner.d.ts.map +1 -0
  55. package/dist/tui/settings.d.ts +56 -0
  56. package/dist/tui/settings.d.ts.map +1 -0
  57. package/dist/tui/slash.d.ts +14 -0
  58. package/dist/tui/slash.d.ts.map +1 -0
  59. package/dist/tui/theme.d.ts +39 -0
  60. package/dist/tui/theme.d.ts.map +1 -0
  61. package/dist/tui/transcript.d.ts +52 -0
  62. package/dist/tui/transcript.d.ts.map +1 -0
  63. package/dist/tui/ui.d.ts +42 -0
  64. package/dist/tui/ui.d.ts.map +1 -0
  65. package/dist/ui/deploy-screens.d.ts +3 -1
  66. package/dist/ui/deploy-screens.d.ts.map +1 -1
  67. package/dist/ui/env-screens.d.ts +37 -0
  68. package/dist/ui/env-screens.d.ts.map +1 -0
  69. package/package.json +19 -17
  70. package/src/commands/agent.ts +344 -0
  71. package/src/commands/api.ts +2 -1
  72. package/src/commands/check.ts +5 -1
  73. package/src/commands/deploy.ts +29 -3
  74. package/src/commands/dev-runner.ts +3 -5
  75. package/src/commands/dev.ts +3 -0
  76. package/src/commands/env.ts +422 -0
  77. package/src/commands/worker-group.ts +0 -4
  78. package/src/commands/worker.ts +0 -4
  79. package/src/index.tsx +95 -5
  80. package/src/lib/command-line.ts +111 -16
  81. package/src/lib/deploy-release.ts +3 -11
  82. package/src/lib/deploy-source.ts +10 -0
  83. package/src/lib/env-config.ts +96 -0
  84. package/src/lib/env-file.ts +104 -0
  85. package/src/lib/github-ci.ts +3 -1
  86. package/src/lib/hidden-prompt.ts +97 -0
  87. package/src/lib/runtime.ts +0 -2
  88. package/src/lib/worker-registry.ts +0 -2
  89. package/src/tui/app.tsx +1334 -0
  90. package/src/tui/brand.tsx +51 -0
  91. package/src/tui/computer.ts +91 -0
  92. package/src/tui/connection.ts +149 -0
  93. package/src/tui/context.tsx +149 -0
  94. package/src/tui/format.ts +477 -0
  95. package/src/tui/index.tsx +364 -0
  96. package/src/tui/markdown.ts +91 -0
  97. package/src/tui/palette.tsx +183 -0
  98. package/src/tui/parts.ts +274 -0
  99. package/src/tui/runner.ts +256 -0
  100. package/src/tui/settings.ts +176 -0
  101. package/src/tui/slash.ts +32 -0
  102. package/src/tui/theme.ts +111 -0
  103. package/src/tui/transcript.tsx +637 -0
  104. package/src/tui/ui.tsx +177 -0
  105. package/src/ui/deploy-screens.ts +12 -1
  106. package/src/ui/env-screens.ts +81 -0
  107. package/dist/lib/agent-turn-timeout.d.ts +0 -8
  108. package/dist/lib/agent-turn-timeout.d.ts.map +0 -1
  109. package/src/lib/agent-turn-timeout.ts +0 -46
package/src/tui/ui.tsx ADDED
@@ -0,0 +1,177 @@
1
+ /** @jsxImportSource @opentui/react */
2
+ import { createTextAttributes, type KeyBinding, type TextareaRenderable } from "@opentui/core"
3
+ import { createContext, useContext, useEffect, useRef, useState } from "react"
4
+ import { SPINNER_FRAMES } from "../ui/theme"
5
+ import type { TuiColors } from "./theme"
6
+
7
+ export const BOLD = createTextAttributes({ bold: true })
8
+ export const ITALIC = createTextAttributes({ italic: true })
9
+
10
+ /** The rows the composer grows to as its text wraps or breaks; past them it scrolls. */
11
+ const COMPOSER_MAX_ROWS = 8
12
+
13
+ /** Enter sends; shift+enter or ctrl+j starts a new line. */
14
+ const COMPOSER_KEYS: KeyBinding[] = [
15
+ { name: "return", action: "submit" },
16
+ { name: "return", shift: true, action: "newline" },
17
+ { name: "return", meta: true, action: "newline" },
18
+ { name: "j", ctrl: true, action: "newline" },
19
+ ]
20
+
21
+ /**
22
+ * The focused composer's clear: ctrl+c empties a draft before it quits, and says whether there
23
+ * was one. The app's keys run before the composer's, so the app asks it.
24
+ */
25
+ export const ComposerDraft = createContext<{ current: (() => boolean) | null }>({ current: null })
26
+
27
+ /** One piece of the line under the composer, such as `This Mac` or `Ask first`. */
28
+ export interface StatusItem {
29
+ readonly text: string
30
+ readonly color: string
31
+ readonly bold?: boolean
32
+ }
33
+
34
+ /**
35
+ * Where a message is written: a panel with Sixb's blue bar, the line it will be sent with under
36
+ * it. `onSubmit` takes the text; the composer clears once it was taken.
37
+ */
38
+ export function Composer({
39
+ colors,
40
+ placeholder,
41
+ status,
42
+ focused,
43
+ accent,
44
+ allowEmpty = false,
45
+ onSubmit,
46
+ onChange,
47
+ }: {
48
+ readonly colors: TuiColors
49
+ readonly placeholder: string
50
+ readonly status: readonly StatusItem[]
51
+ readonly focused: boolean
52
+ /** The bar's color: blue, or amber while something waits on the person. */
53
+ readonly accent?: string
54
+ /** Enter sends an empty composer too, as a form's default does. */
55
+ readonly allowEmpty?: boolean
56
+ readonly onSubmit: (text: string) => boolean | Promise<boolean>
57
+ /** The text as it is typed. */
58
+ readonly onChange?: (text: string) => void
59
+ }) {
60
+ const input = useRef<TextareaRenderable>(null)
61
+ const [rows, setRows] = useState(1)
62
+ // Rows as the text wraps at the composer's width, not lines: a long line grows it too. Not
63
+ // virtualLineCount, which counts no more rows than the textarea already shows.
64
+ const fit = () => setRows(Math.max(1, input.current?.lineInfo.lineStartCols.length ?? 1))
65
+ const clear = () => {
66
+ input.current?.setText("")
67
+ setRows(1)
68
+ onChange?.("")
69
+ }
70
+
71
+ const draft = useContext(ComposerDraft)
72
+ useEffect(() => {
73
+ if (!focused) return
74
+ const clearDraft = () => {
75
+ if (!input.current?.plainText) return false
76
+ clear()
77
+ return true
78
+ }
79
+ draft.current = clearDraft
80
+ return () => {
81
+ if (draft.current === clearDraft) draft.current = null
82
+ }
83
+ })
84
+
85
+ return (
86
+ <box
87
+ border={["left"]}
88
+ borderStyle="heavy"
89
+ borderColor={accent ?? (focused ? colors.blue : colors.border)}
90
+ backgroundColor={colors.surface}
91
+ paddingLeft={2}
92
+ paddingRight={2}
93
+ paddingTop={1}
94
+ paddingBottom={1}
95
+ flexDirection="column"
96
+ flexShrink={0}
97
+ onSizeChange={fit}
98
+ >
99
+ <textarea
100
+ ref={input}
101
+ focused={focused}
102
+ placeholder={placeholder}
103
+ textColor={colors.text}
104
+ focusedTextColor={colors.text}
105
+ placeholderColor={colors.faint}
106
+ backgroundColor={colors.surface}
107
+ focusedBackgroundColor={colors.surface}
108
+ keyBindings={COMPOSER_KEYS}
109
+ height={Math.min(rows, COMPOSER_MAX_ROWS)}
110
+ onContentChange={() => {
111
+ fit()
112
+ onChange?.(input.current?.plainText ?? "")
113
+ }}
114
+ onSubmit={() => {
115
+ const text = input.current?.plainText.trim() ?? ""
116
+ if (!text && !allowEmpty) return
117
+ void Promise.resolve(onSubmit(text)).then((taken) => {
118
+ if (taken) clear()
119
+ })
120
+ }}
121
+ />
122
+ <box height={1} />
123
+ <text>
124
+ {status.map((item, index) => (
125
+ <span key={item.text}>
126
+ {index > 0 ? <span fg={colors.faint}>{" · "}</span> : null}
127
+ <span fg={item.color} attributes={item.bold ? BOLD : 0}>
128
+ {item.text}
129
+ </span>
130
+ </span>
131
+ ))}
132
+ </text>
133
+ </box>
134
+ )
135
+ }
136
+
137
+ /** Key hints: `tab where shift+tab permissions ctrl+p commands`. */
138
+ export function KeyHints({
139
+ colors,
140
+ items,
141
+ }: {
142
+ readonly colors: TuiColors
143
+ readonly items: readonly (readonly [key: string, label: string])[]
144
+ }) {
145
+ return (
146
+ <text wrapMode="none" flexShrink={0}>
147
+ {items.map(([key, label], index) => (
148
+ <span key={key}>
149
+ {index > 0 ? " " : ""}
150
+ <span fg={colors.text}>{key}</span>
151
+ <span fg={colors.muted}>{` ${label}`}</span>
152
+ </span>
153
+ ))}
154
+ </text>
155
+ )
156
+ }
157
+
158
+ export function useSpinner(active: boolean): string {
159
+ const [frame, setFrame] = useState(0)
160
+ useEffect(() => {
161
+ if (!active) return
162
+ const timer = setInterval(() => setFrame((value) => value + 1), 80)
163
+ return () => clearInterval(timer)
164
+ }, [active])
165
+ return SPINNER_FRAMES[frame % SPINNER_FRAMES.length] ?? "·"
166
+ }
167
+
168
+ /** Re-renders every `ms` while `active`, for a clock. */
169
+ export function useNow(ms: number, active = true): number {
170
+ const [now, setNow] = useState(Date.now())
171
+ useEffect(() => {
172
+ if (!active) return
173
+ const timer = setInterval(() => setNow(Date.now()), ms)
174
+ return () => clearInterval(timer)
175
+ }, [ms, active])
176
+ return now
177
+ }
@@ -31,6 +31,7 @@ export function deployReleaseView({
31
31
  configPath: string
32
32
  }): string {
33
33
  const steps = [
34
+ ...(release.steps.env ? [{ label: "env", commands: [release.steps.env] }] : []),
34
35
  { label: "build", commands: release.steps.build },
35
36
  { label: "before start", commands: release.steps.beforeStart },
36
37
  ]
@@ -105,9 +106,12 @@ export function deployStepLine(label: string, seconds: string): string {
105
106
  export function deployCompleteView({
106
107
  release,
107
108
  seconds,
109
+ keptEnv = false,
108
110
  }: {
109
111
  release: DeployRelease
110
112
  seconds?: number
113
+ /** The deploy couldn't update the server's `.env`, so this release runs on its current values. */
114
+ keptEnv?: boolean
111
115
  }): string {
112
116
  const urls = release.services.flatMap((service) =>
113
117
  service.http ? [{ label: service.name, value: service.http.publicOrigin }] : []
@@ -118,7 +122,14 @@ export function deployCompleteView({
118
122
  `${release.name} deployed`,
119
123
  seconds === undefined ? undefined : `${seconds.toFixed(1)}s`
120
124
  ),
121
- urls.length > 0 ? rows(urls) : null
125
+ urls.length > 0 ? rows(urls) : null,
126
+ keptEnv
127
+ ? marked(
128
+ tone.warn(glyph.warn),
129
+ "This release runs on the server's current .env, not on the latest values. Deploy again to update them.",
130
+ tone.muted
131
+ )
132
+ : null
122
133
  )
123
134
  }
124
135
 
@@ -0,0 +1,81 @@
1
+ import type { EnvName } from "@sixb/core/env"
2
+ import { header, headline, plural, screen, stack, table } from "./layout"
3
+ import { tone } from "./theme"
4
+
5
+ export function envPulledView(input: { readonly count: number; readonly env: EnvName }): string {
6
+ return screen(headline("ok", `Wrote ${plural(input.count, "variable")} to .env`, input.env))
7
+ }
8
+
9
+ /** What a pull says when it leaves `.env` as it was. A deploy watches its output for this. */
10
+ export const ENV_KEPT_MESSAGE = "Kept the current .env"
11
+
12
+ /** A deploy kept the server's `.env`, because the source was down or the commit has none. */
13
+ export function envKeptView(input: { readonly env: EnvName; readonly reason: string }): string {
14
+ return screen(stack(headline("warn", ENV_KEPT_MESSAGE, input.env), tone.muted(input.reason)))
15
+ }
16
+
17
+ export function envSetView(input: {
18
+ readonly name: string
19
+ readonly env: EnvName
20
+ readonly declared: boolean
21
+ }): string {
22
+ return screen(
23
+ stack(
24
+ headline("ok", `Set ${input.name}`, input.env),
25
+ input.declared ? null : tone.warn(`Add ${input.name} to sixb.env.ts so it's checked.`)
26
+ )
27
+ )
28
+ }
29
+
30
+ export function envInitView(input: {
31
+ readonly uploaded: readonly { readonly env: EnvName; readonly count: number }[]
32
+ readonly names: number
33
+ }): string {
34
+ const uploaded = input.uploaded.map(({ env, count }) => `${plural(count, "variable")} to ${env}`)
35
+ return screen(
36
+ stack(
37
+ headline("ok", `Uploaded ${uploaded.join(" and ")}`),
38
+ headline("ok", `Wrote sixb.env.ts with ${plural(input.names, "name")}`)
39
+ )
40
+ )
41
+ }
42
+
43
+ export interface EnvStatusRow {
44
+ readonly name: string
45
+ readonly dev: EnvStatusCell
46
+ readonly prod: EnvStatusCell
47
+ readonly declared: boolean
48
+ }
49
+
50
+ /** `set` has a value; `missing` must have one; `unneeded` needs none; `unknown` can't be read. */
51
+ export type EnvStatusCell = "set" | "missing" | "unneeded" | "unknown"
52
+
53
+ const CELLS: Readonly<Record<EnvStatusCell, () => string>> = {
54
+ set: () => tone.ok("✓"),
55
+ missing: () => tone.fail("✗ missing"),
56
+ unneeded: () => tone.faint("–"),
57
+ unknown: () => tone.faint("no access"),
58
+ }
59
+
60
+ export function envStatusView(input: {
61
+ readonly rows: readonly EnvStatusRow[]
62
+ readonly missing: number
63
+ }): string {
64
+ return screen(
65
+ header("env status"),
66
+ table(
67
+ ["", "dev", "prod", ""],
68
+ input.rows.map((row) => [
69
+ row.name,
70
+ CELLS[row.dev](),
71
+ CELLS[row.prod](),
72
+ row.declared ? "" : tone.muted("not in sixb.env.ts"),
73
+ ])
74
+ ),
75
+ input.missing > 0
76
+ ? headline("warn", `${plural(input.missing, "value")} missing`)
77
+ : input.rows.some((row) => row.dev === "unknown" || row.prod === "unknown")
78
+ ? headline("ok", "Everything sixb.env.ts requires is set where you have access")
79
+ : headline("ok", "Everything sixb.env.ts requires is set")
80
+ )
81
+ }
@@ -1,8 +0,0 @@
1
- /**
2
- * Resolve the agent turn timeout from the CLI flag or environment. `undefined` leaves the worker's
3
- * built-in default in authority.
4
- */
5
- export declare function resolveAgentTurnTimeoutMs(value: string | undefined): number | undefined;
6
- /** A duration such as `30s`, `10m`, or `1h` in milliseconds, or `null` when it is not one. */
7
- export declare function parseAgentTurnTimeoutMs(value: string): number | null;
8
- //# sourceMappingURL=agent-turn-timeout.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"agent-turn-timeout.d.ts","sourceRoot":"","sources":["../../src/lib/agent-turn-timeout.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAOvF;AAED,8FAA8F;AAC9F,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAkBpE"}
@@ -1,46 +0,0 @@
1
- const MAX_TIMER_DURATION_MS = 2_147_483_647
2
-
3
- /**
4
- * Resolve the agent turn timeout from the CLI flag or environment. `undefined` leaves the worker's
5
- * built-in default in authority.
6
- */
7
- export function resolveAgentTurnTimeoutMs(value: string | undefined): number | undefined {
8
- const configured = nonblank(value) ?? nonblank(process.env.SIXB_AGENT_TURN_TIMEOUT)
9
- if (configured === undefined) return undefined
10
-
11
- const timeoutMs = parseAgentTurnTimeoutMs(configured)
12
- if (timeoutMs === null) throw invalidAgentTurnTimeout(configured)
13
- return timeoutMs
14
- }
15
-
16
- /** A duration such as `30s`, `10m`, or `1h` in milliseconds, or `null` when it is not one. */
17
- export function parseAgentTurnTimeoutMs(value: string): number | null {
18
- const match = value.match(/^(\d+)(ms|s|m|h)$/)
19
- if (!match) return null
20
-
21
- const amount = Number(match[1])
22
- const unit = match[2] as "ms" | "s" | "m" | "h"
23
- const multipliers = {
24
- ms: 1,
25
- s: 1_000,
26
- m: 60_000,
27
- h: 60 * 60_000,
28
- } as const
29
- const timeoutMs = amount * multipliers[unit]
30
-
31
- if (!Number.isSafeInteger(timeoutMs) || timeoutMs <= 0 || timeoutMs > MAX_TIMER_DURATION_MS) {
32
- return null
33
- }
34
- return timeoutMs
35
- }
36
-
37
- function nonblank(value: string | undefined): string | undefined {
38
- return value?.trim() || undefined
39
- }
40
-
41
- function invalidAgentTurnTimeout(value: string): Error {
42
- return new Error(
43
- `[SixbCLI] Invalid agent turn timeout '${value}'. Use a positive duration like 30s, 10m, or 1h ` +
44
- "with --agent-turn-timeout or SIXB_AGENT_TURN_TIMEOUT."
45
- )
46
- }