@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.
- package/README.md +5 -5
- package/dist/commands/agent.d.ts +16 -0
- package/dist/commands/agent.d.ts.map +1 -0
- package/dist/commands/api.d.ts.map +1 -1
- package/dist/commands/check.d.ts.map +1 -1
- package/dist/commands/deploy.d.ts.map +1 -1
- package/dist/commands/dev-runner.d.ts +0 -1
- package/dist/commands/dev-runner.d.ts.map +1 -1
- package/dist/commands/dev.d.ts.map +1 -1
- package/dist/commands/env.d.ts +31 -0
- package/dist/commands/env.d.ts.map +1 -0
- package/dist/commands/worker-group.d.ts +0 -1
- package/dist/commands/worker-group.d.ts.map +1 -1
- package/dist/commands/worker.d.ts +0 -1
- package/dist/commands/worker.d.ts.map +1 -1
- package/dist/lib/command-line.d.ts +41 -6
- package/dist/lib/command-line.d.ts.map +1 -1
- package/dist/lib/deploy-release.d.ts +2 -0
- package/dist/lib/deploy-release.d.ts.map +1 -1
- package/dist/lib/deploy-source.d.ts +2 -0
- package/dist/lib/deploy-source.d.ts.map +1 -1
- package/dist/lib/env-config.d.ts +17 -0
- package/dist/lib/env-config.d.ts.map +1 -0
- package/dist/lib/env-file.d.ts +16 -0
- package/dist/lib/env-file.d.ts.map +1 -0
- package/dist/lib/github-ci.d.ts.map +1 -1
- package/dist/lib/hidden-prompt.d.ts +19 -0
- package/dist/lib/hidden-prompt.d.ts.map +1 -0
- package/dist/lib/runtime.d.ts +0 -1
- package/dist/lib/runtime.d.ts.map +1 -1
- package/dist/lib/worker-registry.d.ts +0 -1
- package/dist/lib/worker-registry.d.ts.map +1 -1
- package/dist/tui/app.d.ts +27 -0
- package/dist/tui/app.d.ts.map +1 -0
- package/dist/tui/brand.d.ts +7 -0
- package/dist/tui/brand.d.ts.map +1 -0
- package/dist/tui/computer.d.ts +8 -0
- package/dist/tui/computer.d.ts.map +1 -0
- package/dist/tui/connection.d.ts +45 -0
- package/dist/tui/connection.d.ts.map +1 -0
- package/dist/tui/context.d.ts +13 -0
- package/dist/tui/context.d.ts.map +1 -0
- package/dist/tui/format.d.ts +118 -0
- package/dist/tui/format.d.ts.map +1 -0
- package/dist/tui/index.d.ts +12 -0
- package/dist/tui/index.d.ts.map +1 -0
- package/dist/tui/markdown.d.ts +18 -0
- package/dist/tui/markdown.d.ts.map +1 -0
- package/dist/tui/palette.d.ts +25 -0
- package/dist/tui/palette.d.ts.map +1 -0
- package/dist/tui/parts.d.ts +74 -0
- package/dist/tui/parts.d.ts.map +1 -0
- package/dist/tui/runner.d.ts +75 -0
- package/dist/tui/runner.d.ts.map +1 -0
- package/dist/tui/settings.d.ts +56 -0
- package/dist/tui/settings.d.ts.map +1 -0
- package/dist/tui/slash.d.ts +14 -0
- package/dist/tui/slash.d.ts.map +1 -0
- package/dist/tui/theme.d.ts +39 -0
- package/dist/tui/theme.d.ts.map +1 -0
- package/dist/tui/transcript.d.ts +52 -0
- package/dist/tui/transcript.d.ts.map +1 -0
- package/dist/tui/ui.d.ts +42 -0
- package/dist/tui/ui.d.ts.map +1 -0
- package/dist/ui/deploy-screens.d.ts +3 -1
- package/dist/ui/deploy-screens.d.ts.map +1 -1
- package/dist/ui/env-screens.d.ts +37 -0
- package/dist/ui/env-screens.d.ts.map +1 -0
- package/package.json +19 -17
- package/src/commands/agent.ts +344 -0
- package/src/commands/api.ts +2 -1
- package/src/commands/check.ts +5 -1
- package/src/commands/deploy.ts +29 -3
- package/src/commands/dev-runner.ts +3 -5
- package/src/commands/dev.ts +3 -0
- package/src/commands/env.ts +422 -0
- package/src/commands/worker-group.ts +0 -4
- package/src/commands/worker.ts +0 -4
- package/src/index.tsx +95 -5
- package/src/lib/command-line.ts +111 -16
- package/src/lib/deploy-release.ts +3 -11
- package/src/lib/deploy-source.ts +10 -0
- package/src/lib/env-config.ts +96 -0
- package/src/lib/env-file.ts +104 -0
- package/src/lib/github-ci.ts +3 -1
- package/src/lib/hidden-prompt.ts +97 -0
- package/src/lib/runtime.ts +0 -2
- package/src/lib/worker-registry.ts +0 -2
- package/src/tui/app.tsx +1334 -0
- package/src/tui/brand.tsx +51 -0
- package/src/tui/computer.ts +91 -0
- package/src/tui/connection.ts +149 -0
- package/src/tui/context.tsx +149 -0
- package/src/tui/format.ts +477 -0
- package/src/tui/index.tsx +364 -0
- package/src/tui/markdown.ts +91 -0
- package/src/tui/palette.tsx +183 -0
- package/src/tui/parts.ts +274 -0
- package/src/tui/runner.ts +256 -0
- package/src/tui/settings.ts +176 -0
- package/src/tui/slash.ts +32 -0
- package/src/tui/theme.ts +111 -0
- package/src/tui/transcript.tsx +637 -0
- package/src/tui/ui.tsx +177 -0
- package/src/ui/deploy-screens.ts +12 -1
- package/src/ui/env-screens.ts +81 -0
- package/dist/lib/agent-turn-timeout.d.ts +0 -8
- package/dist/lib/agent-turn-timeout.d.ts.map +0 -1
- package/src/lib/agent-turn-timeout.ts +0 -46
|
@@ -0,0 +1,637 @@
|
|
|
1
|
+
/** @jsxImportSource @opentui/react */
|
|
2
|
+
import { CodeRenderable, type MarkdownOptions, type SyntaxStyle } from "@opentui/core"
|
|
3
|
+
import { useRenderer } from "@opentui/react"
|
|
4
|
+
import type { ListAgentThreadApprovalsResponses, ListAgentThreadRunsResponses } from "@sixb/client"
|
|
5
|
+
import { useEffect, useState } from "react"
|
|
6
|
+
import { duration, friendlyPath, plural, runFailureText, type ToolLine, toolLine } from "./format"
|
|
7
|
+
import { steadyMarkdown } from "./markdown"
|
|
8
|
+
import {
|
|
9
|
+
type ApprovalOutcome,
|
|
10
|
+
approvalOutcomes,
|
|
11
|
+
type LiveRun,
|
|
12
|
+
type Part,
|
|
13
|
+
type ShownMessage,
|
|
14
|
+
} from "./parts"
|
|
15
|
+
import { placeLabel } from "./settings"
|
|
16
|
+
import type { TuiColors } from "./theme"
|
|
17
|
+
import { BOLD, ITALIC, useNow, useSpinner } from "./ui"
|
|
18
|
+
|
|
19
|
+
export type Run = ListAgentThreadRunsResponses[200]["runs"][number]
|
|
20
|
+
export type Approval = ListAgentThreadApprovalsResponses[200]["approvals"][number]
|
|
21
|
+
|
|
22
|
+
/** How a turn's model is named under its answer: its catalog name, else its id. */
|
|
23
|
+
export type ModelNames = ReadonlyMap<string, string>
|
|
24
|
+
|
|
25
|
+
const TIER_NAMES = { light: "Light", standard: "Standard", heavy: "Heavy" } as const
|
|
26
|
+
|
|
27
|
+
export function Transcript({
|
|
28
|
+
colors,
|
|
29
|
+
syntax,
|
|
30
|
+
messages,
|
|
31
|
+
runs,
|
|
32
|
+
live,
|
|
33
|
+
approvals,
|
|
34
|
+
modelNames,
|
|
35
|
+
computerRuns,
|
|
36
|
+
width,
|
|
37
|
+
folder,
|
|
38
|
+
approvalChoice,
|
|
39
|
+
}: {
|
|
40
|
+
readonly colors: TuiColors
|
|
41
|
+
readonly syntax: SyntaxStyle
|
|
42
|
+
readonly messages: readonly ShownMessage[]
|
|
43
|
+
readonly runs: readonly Run[]
|
|
44
|
+
readonly live: LiveRun | null
|
|
45
|
+
readonly approvals: readonly Approval[]
|
|
46
|
+
readonly modelNames: ModelNames
|
|
47
|
+
/** Whether the thread's turns run on its owner's computer. */
|
|
48
|
+
readonly computerRuns: boolean
|
|
49
|
+
/** The terminal's width: rows that must stay one line are cut to it. */
|
|
50
|
+
readonly width: number
|
|
51
|
+
/** The folder a computer's turns work in: paths in it are shown relative to it. */
|
|
52
|
+
readonly folder?: string
|
|
53
|
+
/** The choice the first waiting call's card shows chosen. */
|
|
54
|
+
readonly approvalChoice: number
|
|
55
|
+
}) {
|
|
56
|
+
const runsById = new Map(runs.map((run) => [run.id, run]))
|
|
57
|
+
const outcomes = approvalOutcomes(messages)
|
|
58
|
+
// A resumed turn's trigger only says how its held calls ended, which their own lines show.
|
|
59
|
+
const shown = messages.filter((message) => message.role !== "user" || message.parts.length > 0)
|
|
60
|
+
// The live run shows its own answer until the stored one arrives, never both.
|
|
61
|
+
const liveShown =
|
|
62
|
+
live &&
|
|
63
|
+
!messages.some((message) => message.runId === live.runId && message.role === "assistant")
|
|
64
|
+
return (
|
|
65
|
+
<box flexDirection="column" gap={1}>
|
|
66
|
+
{shown.map((message, index) => {
|
|
67
|
+
if (message.role === "user")
|
|
68
|
+
return <UserMessage key={message.id} colors={colors} message={message} />
|
|
69
|
+
const next = shown[index + 1]
|
|
70
|
+
// A turn's meta goes under its last message: a resumed turn answers in several.
|
|
71
|
+
const lastOfRun = !next || next.runId !== message.runId
|
|
72
|
+
const run = message.runId ? runsById.get(message.runId) : undefined
|
|
73
|
+
return (
|
|
74
|
+
<box key={message.id} flexDirection="column" gap={1}>
|
|
75
|
+
{message.compaction ? (
|
|
76
|
+
<CompactionLine colors={colors} contextFull={message.compaction.contextFull} />
|
|
77
|
+
) : null}
|
|
78
|
+
<AgentParts
|
|
79
|
+
colors={colors}
|
|
80
|
+
syntax={syntax}
|
|
81
|
+
parts={message.parts}
|
|
82
|
+
outcomes={outcomes}
|
|
83
|
+
streaming={false}
|
|
84
|
+
width={width}
|
|
85
|
+
folder={folder}
|
|
86
|
+
/>
|
|
87
|
+
{lastOfRun && run && run.status !== "running" && run.status !== "queued" ? (
|
|
88
|
+
<RunMeta
|
|
89
|
+
colors={colors}
|
|
90
|
+
run={run}
|
|
91
|
+
modelNames={modelNames}
|
|
92
|
+
computerRuns={computerRuns}
|
|
93
|
+
waiting={approvals.some((approval) => approval.runId === run.id)}
|
|
94
|
+
/>
|
|
95
|
+
) : null}
|
|
96
|
+
</box>
|
|
97
|
+
)
|
|
98
|
+
})}
|
|
99
|
+
{liveShown && live ? (
|
|
100
|
+
<AgentParts
|
|
101
|
+
colors={colors}
|
|
102
|
+
syntax={syntax}
|
|
103
|
+
parts={live.parts}
|
|
104
|
+
outcomes={outcomes}
|
|
105
|
+
streaming={live.working}
|
|
106
|
+
width={width}
|
|
107
|
+
folder={folder}
|
|
108
|
+
/>
|
|
109
|
+
) : null}
|
|
110
|
+
{approvals.map((approval, index) => (
|
|
111
|
+
<ApprovalCard
|
|
112
|
+
key={approval.id}
|
|
113
|
+
colors={colors}
|
|
114
|
+
approval={approval}
|
|
115
|
+
{...(index === 0 ? { choice: approvalChoice } : {})}
|
|
116
|
+
/>
|
|
117
|
+
))}
|
|
118
|
+
</box>
|
|
119
|
+
)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** Its run condensed the conversation before answering, or to go on when the context was full. */
|
|
123
|
+
function CompactionLine({
|
|
124
|
+
colors,
|
|
125
|
+
contextFull,
|
|
126
|
+
}: {
|
|
127
|
+
readonly colors: TuiColors
|
|
128
|
+
readonly contextFull: boolean
|
|
129
|
+
}) {
|
|
130
|
+
return (
|
|
131
|
+
<text fg={contextFull ? colors.amber : colors.faint}>
|
|
132
|
+
{contextFull ? "◇ Context was full — condensed and continued" : "◇ Condensed conversation"}
|
|
133
|
+
</text>
|
|
134
|
+
)
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function UserMessage({
|
|
138
|
+
colors,
|
|
139
|
+
message,
|
|
140
|
+
}: {
|
|
141
|
+
readonly colors: TuiColors
|
|
142
|
+
readonly message: ShownMessage
|
|
143
|
+
}) {
|
|
144
|
+
return (
|
|
145
|
+
<box
|
|
146
|
+
border={["left"]}
|
|
147
|
+
borderStyle="heavy"
|
|
148
|
+
borderColor={colors.blue}
|
|
149
|
+
backgroundColor={colors.surface}
|
|
150
|
+
paddingLeft={2}
|
|
151
|
+
paddingRight={2}
|
|
152
|
+
paddingTop={1}
|
|
153
|
+
paddingBottom={1}
|
|
154
|
+
flexDirection="column"
|
|
155
|
+
>
|
|
156
|
+
{message.parts.map((part, index) =>
|
|
157
|
+
part.kind === "text" ? (
|
|
158
|
+
<text key={`${message.id}-${index}`} fg={colors.text}>
|
|
159
|
+
{part.text.trim()}
|
|
160
|
+
</text>
|
|
161
|
+
) : part.kind === "file" ? (
|
|
162
|
+
<text key={`${message.id}-${index}`}>
|
|
163
|
+
<span fg={colors.faint}>{"▱ "}</span>
|
|
164
|
+
<span fg={colors.muted}>{part.name}</span>
|
|
165
|
+
</text>
|
|
166
|
+
) : null
|
|
167
|
+
)}
|
|
168
|
+
</box>
|
|
169
|
+
)
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** The agent's side of a turn: what it said, what it thought, and every call it made. */
|
|
173
|
+
function AgentParts({
|
|
174
|
+
colors,
|
|
175
|
+
syntax,
|
|
176
|
+
parts,
|
|
177
|
+
outcomes,
|
|
178
|
+
streaming,
|
|
179
|
+
width,
|
|
180
|
+
folder,
|
|
181
|
+
}: {
|
|
182
|
+
readonly colors: TuiColors
|
|
183
|
+
readonly syntax: SyntaxStyle
|
|
184
|
+
readonly parts: readonly Part[]
|
|
185
|
+
/** How the transcript's held calls ended, by approval id. */
|
|
186
|
+
readonly outcomes: ReadonlyMap<string, ApprovalOutcome>
|
|
187
|
+
readonly streaming: boolean
|
|
188
|
+
readonly width: number
|
|
189
|
+
readonly folder?: string
|
|
190
|
+
}) {
|
|
191
|
+
return (
|
|
192
|
+
<box flexDirection="column" paddingLeft={3} paddingRight={2} gap={1}>
|
|
193
|
+
{parts.map((part, index) => {
|
|
194
|
+
const key = part.kind === "tool" ? part.id : `${part.kind}-${index}`
|
|
195
|
+
const last = index === parts.length - 1
|
|
196
|
+
switch (part.kind) {
|
|
197
|
+
case "text":
|
|
198
|
+
return (
|
|
199
|
+
<Answer
|
|
200
|
+
key={key}
|
|
201
|
+
colors={colors}
|
|
202
|
+
syntax={syntax}
|
|
203
|
+
text={part.text}
|
|
204
|
+
streaming={streaming && last}
|
|
205
|
+
/>
|
|
206
|
+
)
|
|
207
|
+
case "reasoning":
|
|
208
|
+
// A model that keeps its thinking to itself sends it without text: nothing to show.
|
|
209
|
+
if (!part.text.trim()) return null
|
|
210
|
+
return (
|
|
211
|
+
<Thought
|
|
212
|
+
key={key}
|
|
213
|
+
colors={colors}
|
|
214
|
+
text={part.text}
|
|
215
|
+
done={part.done || !streaming}
|
|
216
|
+
width={width}
|
|
217
|
+
/>
|
|
218
|
+
)
|
|
219
|
+
case "tool":
|
|
220
|
+
return (
|
|
221
|
+
<ToolRow
|
|
222
|
+
key={key}
|
|
223
|
+
colors={colors}
|
|
224
|
+
line={shownLine(toolLine(part, outcomes), folder)}
|
|
225
|
+
state={part.state}
|
|
226
|
+
width={width}
|
|
227
|
+
/>
|
|
228
|
+
)
|
|
229
|
+
default:
|
|
230
|
+
return (
|
|
231
|
+
<text key={key}>
|
|
232
|
+
<span fg={colors.faint}>{"▱ "}</span>
|
|
233
|
+
<span fg={colors.muted}>{part.name}</span>
|
|
234
|
+
</text>
|
|
235
|
+
)
|
|
236
|
+
}
|
|
237
|
+
})}
|
|
238
|
+
</box>
|
|
239
|
+
)
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* What the agent said, as markdown drawn the moment it is set: each top-level block on its own,
|
|
244
|
+
* where OpenTUI otherwise draws runs of them as raw markdown until highlighting conceals the
|
|
245
|
+
* markers, every time the text grows. While it streams, its unfinished end is steadied.
|
|
246
|
+
*/
|
|
247
|
+
function Answer({
|
|
248
|
+
colors,
|
|
249
|
+
syntax,
|
|
250
|
+
text,
|
|
251
|
+
streaming,
|
|
252
|
+
}: {
|
|
253
|
+
readonly colors: TuiColors
|
|
254
|
+
readonly syntax: SyntaxStyle
|
|
255
|
+
readonly text: string
|
|
256
|
+
readonly streaming: boolean
|
|
257
|
+
}) {
|
|
258
|
+
// Markdown created finished draws nothing until it is highlighted, and an answer is created
|
|
259
|
+
// finished whenever its stored message replaces the streamed one. Created streaming it is drawn
|
|
260
|
+
// at once, so a finished answer is finalized after its first frame.
|
|
261
|
+
const renderer = useRenderer()
|
|
262
|
+
const [drawn, setDrawn] = useState(false)
|
|
263
|
+
useEffect(() => {
|
|
264
|
+
const mark = () => setDrawn(true)
|
|
265
|
+
renderer.once("frame", mark)
|
|
266
|
+
return () => {
|
|
267
|
+
renderer.off("frame", mark)
|
|
268
|
+
}
|
|
269
|
+
}, [renderer])
|
|
270
|
+
|
|
271
|
+
return (
|
|
272
|
+
<markdown
|
|
273
|
+
content={streaming ? steadyMarkdown(text) : text.trim()}
|
|
274
|
+
syntaxStyle={syntax}
|
|
275
|
+
fg={colors.text}
|
|
276
|
+
conceal
|
|
277
|
+
internalBlockMode="top-level"
|
|
278
|
+
tableOptions={TABLES}
|
|
279
|
+
renderNode={drawCodeAtOnce}
|
|
280
|
+
streaming={streaming || !drawn}
|
|
281
|
+
/>
|
|
282
|
+
)
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/** Tables boxed, as the transcript has always drawn them. */
|
|
286
|
+
const TABLES: MarkdownOptions["tableOptions"] = { style: "grid" }
|
|
287
|
+
|
|
288
|
+
type RenderNode = NonNullable<MarkdownOptions["renderNode"]>
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* A code block drawn plain until it is highlighted, rather than left blank. Only code blocks: the
|
|
292
|
+
* rest keeps OpenTUI's own rendering.
|
|
293
|
+
*/
|
|
294
|
+
const drawCodeAtOnce = Object.assign<RenderNode, { codeBlockOnly: true }>(
|
|
295
|
+
(token, context) => {
|
|
296
|
+
if (token.type !== "code") return undefined
|
|
297
|
+
const code = context.defaultRender()
|
|
298
|
+
if (code instanceof CodeRenderable) code.drawUnstyledText = true
|
|
299
|
+
return code
|
|
300
|
+
},
|
|
301
|
+
{ codeBlockOnly: true }
|
|
302
|
+
)
|
|
303
|
+
|
|
304
|
+
function Thought({
|
|
305
|
+
colors,
|
|
306
|
+
text,
|
|
307
|
+
done,
|
|
308
|
+
width,
|
|
309
|
+
}: {
|
|
310
|
+
readonly colors: TuiColors
|
|
311
|
+
readonly text: string
|
|
312
|
+
readonly done: boolean
|
|
313
|
+
readonly width: number
|
|
314
|
+
}) {
|
|
315
|
+
const lines = text
|
|
316
|
+
.trim()
|
|
317
|
+
.split("\n")
|
|
318
|
+
.filter((line) => line.trim())
|
|
319
|
+
const room = Math.max(20, width - 14)
|
|
320
|
+
// Its first lines once done, its latest while it thinks; never more than a few.
|
|
321
|
+
const shown = done ? lines.slice(0, THOUGHT_LINES) : lines.slice(-THOUGHT_LINES)
|
|
322
|
+
const more = lines.length - shown.length
|
|
323
|
+
return (
|
|
324
|
+
<box border={["left"]} borderColor={colors.border} paddingLeft={2} flexDirection="column">
|
|
325
|
+
<text fg={colors.muted} attributes={ITALIC}>
|
|
326
|
+
{done ? "Thought" : "Thinking…"}
|
|
327
|
+
</text>
|
|
328
|
+
{shown.map((line, index) => (
|
|
329
|
+
<text key={`${index}-${line.slice(0, 8)}`} fg={colors.faint}>
|
|
330
|
+
{oneLine(line, room)}
|
|
331
|
+
</text>
|
|
332
|
+
))}
|
|
333
|
+
{done && more > 0 ? <text fg={colors.faint}>{`… ${plural(more, "more line")}`}</text> : null}
|
|
334
|
+
</box>
|
|
335
|
+
)
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
const THOUGHT_LINES = 4
|
|
339
|
+
|
|
340
|
+
/** A line cut to `room` columns, so it never wraps. */
|
|
341
|
+
function oneLine(text: string, room: number): string {
|
|
342
|
+
const flat = text.replace(/\s+/g, " ").trim()
|
|
343
|
+
return flat.length > room ? `${flat.slice(0, room - 1)}…` : flat
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
function ToolRow({
|
|
347
|
+
colors,
|
|
348
|
+
line,
|
|
349
|
+
state,
|
|
350
|
+
width,
|
|
351
|
+
}: {
|
|
352
|
+
readonly colors: TuiColors
|
|
353
|
+
readonly line: ToolLine
|
|
354
|
+
readonly width: number
|
|
355
|
+
readonly state: Extract<Part, { kind: "tool" }>["state"]
|
|
356
|
+
}) {
|
|
357
|
+
const spinner = useSpinner(state === "running")
|
|
358
|
+
const room = Math.max(20, width - 16)
|
|
359
|
+
const failed = line.failed || state === "error"
|
|
360
|
+
const tone = line.held ? colors.amber : failed ? colors.red : colors.faint
|
|
361
|
+
if (line.command !== undefined) {
|
|
362
|
+
return <CommandPanel colors={colors} line={line} running={state === "running"} room={room} />
|
|
363
|
+
}
|
|
364
|
+
const mark = state === "running" ? spinner : "●"
|
|
365
|
+
const markColor =
|
|
366
|
+
state === "running"
|
|
367
|
+
? colors.blue
|
|
368
|
+
: line.held
|
|
369
|
+
? colors.amber
|
|
370
|
+
: failed
|
|
371
|
+
? colors.red
|
|
372
|
+
: colors.green
|
|
373
|
+
return (
|
|
374
|
+
<box flexDirection="column">
|
|
375
|
+
<text>
|
|
376
|
+
<span fg={markColor}>{`${mark} `}</span>
|
|
377
|
+
<span fg={colors.text} attributes={BOLD}>
|
|
378
|
+
{line.verb}
|
|
379
|
+
</span>
|
|
380
|
+
<span fg={colors.muted}>
|
|
381
|
+
{line.detail
|
|
382
|
+
? ` ${oneLine(line.detail, room - line.verb.length - (line.note?.length ?? 0) - 6)}`
|
|
383
|
+
: ""}
|
|
384
|
+
</span>
|
|
385
|
+
{line.note ? <span fg={tone}>{` ${line.note}`}</span> : null}
|
|
386
|
+
</text>
|
|
387
|
+
{line.preview?.map((row, index) => (
|
|
388
|
+
<text key={`${index}-${row.slice(0, 12)}`}>
|
|
389
|
+
<span fg={colors.faint}>{index === 0 ? " ⎿ " : " "}</span>
|
|
390
|
+
<span fg={colors.faint}>{oneLine(row, room)}</span>
|
|
391
|
+
</text>
|
|
392
|
+
))}
|
|
393
|
+
</box>
|
|
394
|
+
)
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/** A shell command as its own panel: the command, what it printed, and how it ended. */
|
|
398
|
+
function CommandPanel({
|
|
399
|
+
colors,
|
|
400
|
+
line,
|
|
401
|
+
running,
|
|
402
|
+
room,
|
|
403
|
+
}: {
|
|
404
|
+
readonly colors: TuiColors
|
|
405
|
+
readonly line: ToolLine
|
|
406
|
+
readonly running: boolean
|
|
407
|
+
readonly room: number
|
|
408
|
+
}) {
|
|
409
|
+
const spinner = useSpinner(running)
|
|
410
|
+
const commandLines = (line.command ?? "").split("\n")
|
|
411
|
+
const shown = commandLines.slice(0, COMMAND_LINES)
|
|
412
|
+
const tone = line.held ? colors.amber : line.failed ? colors.red : colors.faint
|
|
413
|
+
const status = running ? spinner : (line.note ?? "")
|
|
414
|
+
return (
|
|
415
|
+
<box
|
|
416
|
+
backgroundColor={colors.surface}
|
|
417
|
+
paddingLeft={2}
|
|
418
|
+
paddingRight={2}
|
|
419
|
+
paddingTop={1}
|
|
420
|
+
paddingBottom={1}
|
|
421
|
+
flexDirection="column"
|
|
422
|
+
>
|
|
423
|
+
<box flexDirection="row" justifyContent="space-between">
|
|
424
|
+
<box flexDirection="column" flexShrink={1}>
|
|
425
|
+
{shown.map((row, index) => (
|
|
426
|
+
<text key={`${index}-${row.slice(0, 12)}`} wrapMode="none">
|
|
427
|
+
<span fg={colors.blue}>{index === 0 ? "$ " : " "}</span>
|
|
428
|
+
<span fg={colors.text}>{oneLine(row, room - status.length - 6)}</span>
|
|
429
|
+
</text>
|
|
430
|
+
))}
|
|
431
|
+
{commandLines.length > shown.length ? (
|
|
432
|
+
<text
|
|
433
|
+
fg={colors.faint}
|
|
434
|
+
>{` … ${plural(commandLines.length - shown.length, "more line")}`}</text>
|
|
435
|
+
) : null}
|
|
436
|
+
</box>
|
|
437
|
+
{status ? (
|
|
438
|
+
<text fg={running ? colors.blue : tone} flexShrink={0}>
|
|
439
|
+
{status}
|
|
440
|
+
</text>
|
|
441
|
+
) : null}
|
|
442
|
+
</box>
|
|
443
|
+
{line.preview && line.preview.length > 0 ? (
|
|
444
|
+
<box flexDirection="column" paddingTop={1}>
|
|
445
|
+
{line.preview.map((row, index) => (
|
|
446
|
+
<text key={`${index}-${row.slice(0, 12)}`} fg={colors.muted} wrapMode="none">
|
|
447
|
+
{oneLine(row, room - 4)}
|
|
448
|
+
</text>
|
|
449
|
+
))}
|
|
450
|
+
</box>
|
|
451
|
+
) : null}
|
|
452
|
+
</box>
|
|
453
|
+
)
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
const COMMAND_LINES = 3
|
|
457
|
+
|
|
458
|
+
/** Under a turn's answer: where it ran, on which model, and how long it took. */
|
|
459
|
+
function RunMeta({
|
|
460
|
+
colors,
|
|
461
|
+
run,
|
|
462
|
+
modelNames,
|
|
463
|
+
computerRuns,
|
|
464
|
+
waiting,
|
|
465
|
+
}: {
|
|
466
|
+
readonly colors: TuiColors
|
|
467
|
+
readonly run: Run
|
|
468
|
+
readonly modelNames: ModelNames
|
|
469
|
+
readonly computerRuns: boolean
|
|
470
|
+
/** One of its calls still waits for the person. */
|
|
471
|
+
readonly waiting: boolean
|
|
472
|
+
}) {
|
|
473
|
+
const model = run.model
|
|
474
|
+
? (modelNames.get(`${run.model.provider}:${run.model.modelId}`) ?? run.model.modelId)
|
|
475
|
+
: undefined
|
|
476
|
+
const took =
|
|
477
|
+
run.startedAt && run.completedAt
|
|
478
|
+
? duration(Date.parse(run.completedAt) - Date.parse(run.startedAt))
|
|
479
|
+
: undefined
|
|
480
|
+
const ended =
|
|
481
|
+
run.status === "cancelled"
|
|
482
|
+
? run.finishReason === "interrupted"
|
|
483
|
+
? "interrupted"
|
|
484
|
+
: "stopped"
|
|
485
|
+
: run.status === "failed"
|
|
486
|
+
? "failed"
|
|
487
|
+
: run.finishReason === "awaiting_approval" && waiting
|
|
488
|
+
? "waiting for you"
|
|
489
|
+
: undefined
|
|
490
|
+
const items = [run.tier ? TIER_NAMES[run.tier] : undefined, model, took].filter(
|
|
491
|
+
(item): item is string => Boolean(item)
|
|
492
|
+
)
|
|
493
|
+
return (
|
|
494
|
+
<text>
|
|
495
|
+
<span fg={colors.blue}>{" ▰ "}</span>
|
|
496
|
+
<span fg={colors.text}>{placeLabel(computerRuns ? "computer" : "cloud")}</span>
|
|
497
|
+
{items.map((item) => (
|
|
498
|
+
<span key={item} fg={colors.muted}>{` · ${item}`}</span>
|
|
499
|
+
))}
|
|
500
|
+
{ended ? (
|
|
501
|
+
<span fg={run.status === "failed" ? colors.red : colors.amber}>{` · ${ended}`}</span>
|
|
502
|
+
) : null}
|
|
503
|
+
{run.status === "failed" && run.error ? (
|
|
504
|
+
<span fg={colors.faint}>{` ${runFailureText(run.error)}`}</span>
|
|
505
|
+
) : null}
|
|
506
|
+
</text>
|
|
507
|
+
)
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
/** How a call waiting for the person can be decided, in the order the card offers them. */
|
|
511
|
+
export const APPROVAL_CHOICES = [
|
|
512
|
+
{ key: "y", label: "Allow", decision: "approve", always: false },
|
|
513
|
+
{ key: "a", label: "Always in this thread", decision: "approve", always: true },
|
|
514
|
+
{ key: "n", label: "Deny", decision: "deny", always: false },
|
|
515
|
+
] as const
|
|
516
|
+
|
|
517
|
+
/** A call waiting for the person: what it would do, and the choices that decide it. */
|
|
518
|
+
function ApprovalCard({
|
|
519
|
+
colors,
|
|
520
|
+
approval,
|
|
521
|
+
choice,
|
|
522
|
+
}: {
|
|
523
|
+
readonly colors: TuiColors
|
|
524
|
+
readonly approval: Approval
|
|
525
|
+
/** The choice enter would make; absent on a card that is not the one being decided. */
|
|
526
|
+
readonly choice?: number
|
|
527
|
+
}) {
|
|
528
|
+
const { call } = approval
|
|
529
|
+
const title =
|
|
530
|
+
call.kind === "action"
|
|
531
|
+
? `Run ${call.actionId}${call.subject.kind === "object" ? ` on ${call.subject.objectTypeId} ${call.subject.primaryId}` : ""}?`
|
|
532
|
+
: `Start the ${call.workflowId} workflow?`
|
|
533
|
+
const input = JSON.stringify(call.kind === "action" ? call.params : call.input)
|
|
534
|
+
const external = call.kind === "action" && call.effect === "external"
|
|
535
|
+
return (
|
|
536
|
+
<box
|
|
537
|
+
border={["left"]}
|
|
538
|
+
borderStyle="heavy"
|
|
539
|
+
borderColor={colors.amber}
|
|
540
|
+
backgroundColor={colors.surface}
|
|
541
|
+
paddingLeft={2}
|
|
542
|
+
paddingRight={2}
|
|
543
|
+
paddingTop={1}
|
|
544
|
+
paddingBottom={1}
|
|
545
|
+
marginLeft={3}
|
|
546
|
+
flexDirection="column"
|
|
547
|
+
>
|
|
548
|
+
<text>
|
|
549
|
+
<span fg={colors.amber}>{"? "}</span>
|
|
550
|
+
<span fg={colors.text} attributes={BOLD}>
|
|
551
|
+
{title}
|
|
552
|
+
</span>
|
|
553
|
+
{external ? <span fg={colors.muted}>{" reaches outside Sixb"}</span> : null}
|
|
554
|
+
</text>
|
|
555
|
+
{input && input !== "{}" ? (
|
|
556
|
+
<text fg={colors.faint}>{input.length > 220 ? `${input.slice(0, 217)}…` : input}</text>
|
|
557
|
+
) : null}
|
|
558
|
+
<box height={1} />
|
|
559
|
+
<text>
|
|
560
|
+
{APPROVAL_CHOICES.map((option, index) => {
|
|
561
|
+
const chosen = index === choice
|
|
562
|
+
return (
|
|
563
|
+
<span key={option.key}>
|
|
564
|
+
{index > 0 ? " " : ""}
|
|
565
|
+
<span fg={chosen ? colors.amber : colors.faint}>{chosen ? "▸ " : " "}</span>
|
|
566
|
+
<span fg={chosen ? colors.text : colors.muted} attributes={chosen ? BOLD : 0}>
|
|
567
|
+
{option.label}
|
|
568
|
+
</span>
|
|
569
|
+
<span fg={colors.faint}>{` ${option.key}`}</span>
|
|
570
|
+
</span>
|
|
571
|
+
)
|
|
572
|
+
})}
|
|
573
|
+
</text>
|
|
574
|
+
</box>
|
|
575
|
+
)
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
/** While a turn works: the spinner, how long, and how to stop it. */
|
|
579
|
+
export function Working({
|
|
580
|
+
colors,
|
|
581
|
+
since,
|
|
582
|
+
label,
|
|
583
|
+
stopping = false,
|
|
584
|
+
}: {
|
|
585
|
+
readonly colors: TuiColors
|
|
586
|
+
readonly since: number
|
|
587
|
+
readonly label: string
|
|
588
|
+
/** Waiting for a second esc: the hint is the label then. */
|
|
589
|
+
readonly stopping?: boolean
|
|
590
|
+
}) {
|
|
591
|
+
const now = useNow(120)
|
|
592
|
+
return (
|
|
593
|
+
<text>
|
|
594
|
+
<span>{" "}</span>
|
|
595
|
+
<Wave colors={colors} at={now} />
|
|
596
|
+
<span fg={colors.text}>{` ${label}`}</span>
|
|
597
|
+
<span fg={colors.faint}>{` ${duration(Math.max(0, now - since))}`}</span>
|
|
598
|
+
{stopping ? null : <span fg={colors.faint}>{" esc to stop"}</span>}
|
|
599
|
+
</text>
|
|
600
|
+
)
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
/** A call's line with its paths as the person reads them. */
|
|
604
|
+
function shownLine(line: ToolLine, folder?: string): ToolLine {
|
|
605
|
+
return {
|
|
606
|
+
...line,
|
|
607
|
+
detail: friendlyPath(line.detail, folder),
|
|
608
|
+
...(line.command === undefined ? {} : { command: friendlyPath(line.command, folder) }),
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
const WAVE_TILES = 4
|
|
613
|
+
|
|
614
|
+
/**
|
|
615
|
+
* The mosaic at work: a tile in each of its blues, the brightest moving along them, as the
|
|
616
|
+
* website's hero fills.
|
|
617
|
+
*/
|
|
618
|
+
function Wave({ colors, at }: { readonly colors: TuiColors; readonly at: number }) {
|
|
619
|
+
const lead = Math.floor(at / 120) % (WAVE_TILES * 2 - 2)
|
|
620
|
+
const position = lead < WAVE_TILES ? lead : WAVE_TILES * 2 - 2 - lead
|
|
621
|
+
return (
|
|
622
|
+
<>
|
|
623
|
+
{Array.from({ length: WAVE_TILES }, (_, index) => {
|
|
624
|
+
const distance = Math.abs(index - position)
|
|
625
|
+
const color =
|
|
626
|
+
distance === 0
|
|
627
|
+
? colors.blue
|
|
628
|
+
: (colors.water[Math.max(0, colors.water.length - 1 - distance)] ?? colors.faint)
|
|
629
|
+
return (
|
|
630
|
+
<span key={index} fg={distance > 2 ? colors.border : color}>
|
|
631
|
+
{distance === 0 ? "▰" : "▱"}
|
|
632
|
+
</span>
|
|
633
|
+
)
|
|
634
|
+
})}
|
|
635
|
+
</>
|
|
636
|
+
)
|
|
637
|
+
}
|