@sixb/cli 0.1.25 → 0.1.26
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/dev-runner.d.ts +0 -1
- package/dist/commands/dev-runner.d.ts.map +1 -1
- 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 +16 -6
- package/dist/lib/command-line.d.ts.map +1 -1
- package/dist/lib/deploy-release.d.ts.map +1 -1
- package/dist/lib/github-ci.d.ts.map +1 -1
- 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 +19 -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 +3 -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/folders.d.ts +7 -0
- package/dist/tui/folders.d.ts.map +1 -0
- package/dist/tui/format.d.ts +33 -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/palette.d.ts +25 -0
- package/dist/tui/palette.d.ts.map +1 -0
- package/dist/tui/parts.d.ts +66 -0
- package/dist/tui/parts.d.ts.map +1 -0
- package/dist/tui/runner.d.ts +52 -0
- package/dist/tui/runner.d.ts.map +1 -0
- package/dist/tui/settings.d.ts +44 -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 +35 -0
- package/dist/tui/ui.d.ts.map +1 -0
- package/package.json +17 -15
- package/src/commands/agent.ts +337 -0
- package/src/commands/dev-runner.ts +0 -4
- package/src/commands/worker-group.ts +0 -4
- package/src/commands/worker.ts +0 -4
- package/src/index.tsx +57 -5
- package/src/lib/command-line.ts +52 -15
- package/src/lib/deploy-release.ts +0 -11
- package/src/lib/github-ci.ts +3 -1
- package/src/lib/runtime.ts +0 -2
- package/src/lib/worker-registry.ts +0 -2
- package/src/tui/app.tsx +1198 -0
- package/src/tui/brand.tsx +51 -0
- package/src/tui/computer.ts +54 -0
- package/src/tui/connection.ts +149 -0
- package/src/tui/folders.ts +41 -0
- package/src/tui/format.ts +260 -0
- package/src/tui/index.tsx +353 -0
- package/src/tui/palette.tsx +183 -0
- package/src/tui/parts.ts +254 -0
- package/src/tui/runner.ts +173 -0
- package/src/tui/settings.ts +127 -0
- package/src/tui/slash.ts +32 -0
- package/src/tui/theme.ts +111 -0
- package/src/tui/transcript.tsx +555 -0
- package/src/tui/ui.tsx +148 -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,555 @@
|
|
|
1
|
+
/** @jsxImportSource @opentui/react */
|
|
2
|
+
import type { SyntaxStyle } from "@opentui/core"
|
|
3
|
+
import type { ListAgentThreadApprovalsResponses, ListAgentThreadRunsResponses } from "@sixb/client"
|
|
4
|
+
import { duration, friendlyPath, plural, type ToolLine, toolLine } from "./format"
|
|
5
|
+
import {
|
|
6
|
+
type ApprovalOutcome,
|
|
7
|
+
approvalOutcomes,
|
|
8
|
+
type LiveRun,
|
|
9
|
+
type Part,
|
|
10
|
+
type ShownMessage,
|
|
11
|
+
} from "./parts"
|
|
12
|
+
import { placeLabel } from "./settings"
|
|
13
|
+
import type { TuiColors } from "./theme"
|
|
14
|
+
import { BOLD, ITALIC, useNow, useSpinner } from "./ui"
|
|
15
|
+
|
|
16
|
+
export type Run = ListAgentThreadRunsResponses[200]["runs"][number]
|
|
17
|
+
export type Approval = ListAgentThreadApprovalsResponses[200]["approvals"][number]
|
|
18
|
+
|
|
19
|
+
/** How a turn's model is named under its answer: its catalog name, else its id. */
|
|
20
|
+
export type ModelNames = ReadonlyMap<string, string>
|
|
21
|
+
|
|
22
|
+
const TIER_NAMES = { light: "Light", standard: "Standard", heavy: "Heavy" } as const
|
|
23
|
+
|
|
24
|
+
export function Transcript({
|
|
25
|
+
colors,
|
|
26
|
+
syntax,
|
|
27
|
+
messages,
|
|
28
|
+
runs,
|
|
29
|
+
live,
|
|
30
|
+
approvals,
|
|
31
|
+
modelNames,
|
|
32
|
+
computerRuns,
|
|
33
|
+
width,
|
|
34
|
+
folder,
|
|
35
|
+
approvalChoice,
|
|
36
|
+
}: {
|
|
37
|
+
readonly colors: TuiColors
|
|
38
|
+
readonly syntax: SyntaxStyle
|
|
39
|
+
readonly messages: readonly ShownMessage[]
|
|
40
|
+
readonly runs: readonly Run[]
|
|
41
|
+
readonly live: LiveRun | null
|
|
42
|
+
readonly approvals: readonly Approval[]
|
|
43
|
+
readonly modelNames: ModelNames
|
|
44
|
+
/** Whether the thread's turns run on its owner's computer. */
|
|
45
|
+
readonly computerRuns: boolean
|
|
46
|
+
/** The terminal's width: rows that must stay one line are cut to it. */
|
|
47
|
+
readonly width: number
|
|
48
|
+
/** The folder a computer's turns work in: paths in it are shown relative to it. */
|
|
49
|
+
readonly folder?: string
|
|
50
|
+
/** The choice the first waiting call's card shows chosen. */
|
|
51
|
+
readonly approvalChoice: number
|
|
52
|
+
}) {
|
|
53
|
+
const runsById = new Map(runs.map((run) => [run.id, run]))
|
|
54
|
+
const outcomes = approvalOutcomes(messages)
|
|
55
|
+
// A resumed turn's trigger only says how its held calls ended, which their own lines show.
|
|
56
|
+
const shown = messages.filter((message) => message.role !== "user" || message.parts.length > 0)
|
|
57
|
+
// The live run shows its own answer until the stored one arrives, never both.
|
|
58
|
+
const liveShown =
|
|
59
|
+
live &&
|
|
60
|
+
!messages.some((message) => message.runId === live.runId && message.role === "assistant")
|
|
61
|
+
return (
|
|
62
|
+
<box flexDirection="column" gap={1}>
|
|
63
|
+
{shown.map((message, index) => {
|
|
64
|
+
if (message.role === "user")
|
|
65
|
+
return <UserMessage key={message.id} colors={colors} message={message} />
|
|
66
|
+
const next = shown[index + 1]
|
|
67
|
+
// A turn's meta goes under its last message: a resumed turn answers in several.
|
|
68
|
+
const lastOfRun = !next || next.runId !== message.runId
|
|
69
|
+
const run = message.runId ? runsById.get(message.runId) : undefined
|
|
70
|
+
return (
|
|
71
|
+
<box key={message.id} flexDirection="column" gap={1}>
|
|
72
|
+
<AgentParts
|
|
73
|
+
colors={colors}
|
|
74
|
+
syntax={syntax}
|
|
75
|
+
parts={message.parts}
|
|
76
|
+
outcomes={outcomes}
|
|
77
|
+
streaming={false}
|
|
78
|
+
width={width}
|
|
79
|
+
folder={folder}
|
|
80
|
+
/>
|
|
81
|
+
{lastOfRun && run && run.status !== "running" && run.status !== "queued" ? (
|
|
82
|
+
<RunMeta
|
|
83
|
+
colors={colors}
|
|
84
|
+
run={run}
|
|
85
|
+
modelNames={modelNames}
|
|
86
|
+
computerRuns={computerRuns}
|
|
87
|
+
waiting={approvals.some((approval) => approval.runId === run.id)}
|
|
88
|
+
/>
|
|
89
|
+
) : null}
|
|
90
|
+
</box>
|
|
91
|
+
)
|
|
92
|
+
})}
|
|
93
|
+
{liveShown && live ? (
|
|
94
|
+
<AgentParts
|
|
95
|
+
colors={colors}
|
|
96
|
+
syntax={syntax}
|
|
97
|
+
parts={live.parts}
|
|
98
|
+
outcomes={outcomes}
|
|
99
|
+
streaming={live.working}
|
|
100
|
+
width={width}
|
|
101
|
+
folder={folder}
|
|
102
|
+
/>
|
|
103
|
+
) : null}
|
|
104
|
+
{approvals.map((approval, index) => (
|
|
105
|
+
<ApprovalCard
|
|
106
|
+
key={approval.id}
|
|
107
|
+
colors={colors}
|
|
108
|
+
approval={approval}
|
|
109
|
+
{...(index === 0 ? { choice: approvalChoice } : {})}
|
|
110
|
+
/>
|
|
111
|
+
))}
|
|
112
|
+
</box>
|
|
113
|
+
)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function UserMessage({
|
|
117
|
+
colors,
|
|
118
|
+
message,
|
|
119
|
+
}: {
|
|
120
|
+
readonly colors: TuiColors
|
|
121
|
+
readonly message: ShownMessage
|
|
122
|
+
}) {
|
|
123
|
+
return (
|
|
124
|
+
<box
|
|
125
|
+
border={["left"]}
|
|
126
|
+
borderStyle="heavy"
|
|
127
|
+
borderColor={colors.blue}
|
|
128
|
+
backgroundColor={colors.surface}
|
|
129
|
+
paddingLeft={2}
|
|
130
|
+
paddingRight={2}
|
|
131
|
+
paddingTop={1}
|
|
132
|
+
paddingBottom={1}
|
|
133
|
+
flexDirection="column"
|
|
134
|
+
>
|
|
135
|
+
{message.parts.map((part, index) =>
|
|
136
|
+
part.kind === "text" ? (
|
|
137
|
+
<text key={`${message.id}-${index}`} fg={colors.text}>
|
|
138
|
+
{part.text.trim()}
|
|
139
|
+
</text>
|
|
140
|
+
) : part.kind === "file" ? (
|
|
141
|
+
<text key={`${message.id}-${index}`}>
|
|
142
|
+
<span fg={colors.faint}>{"▱ "}</span>
|
|
143
|
+
<span fg={colors.muted}>{part.name}</span>
|
|
144
|
+
</text>
|
|
145
|
+
) : null
|
|
146
|
+
)}
|
|
147
|
+
</box>
|
|
148
|
+
)
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** The agent's side of a turn: what it said, what it thought, and every call it made. */
|
|
152
|
+
function AgentParts({
|
|
153
|
+
colors,
|
|
154
|
+
syntax,
|
|
155
|
+
parts,
|
|
156
|
+
outcomes,
|
|
157
|
+
streaming,
|
|
158
|
+
width,
|
|
159
|
+
folder,
|
|
160
|
+
}: {
|
|
161
|
+
readonly colors: TuiColors
|
|
162
|
+
readonly syntax: SyntaxStyle
|
|
163
|
+
readonly parts: readonly Part[]
|
|
164
|
+
/** How the transcript's held calls ended, by approval id. */
|
|
165
|
+
readonly outcomes: ReadonlyMap<string, ApprovalOutcome>
|
|
166
|
+
readonly streaming: boolean
|
|
167
|
+
readonly width: number
|
|
168
|
+
readonly folder?: string
|
|
169
|
+
}) {
|
|
170
|
+
return (
|
|
171
|
+
<box flexDirection="column" paddingLeft={3} paddingRight={2} gap={1}>
|
|
172
|
+
{parts.map((part, index) => {
|
|
173
|
+
const key = part.kind === "tool" ? part.id : `${part.kind}-${index}`
|
|
174
|
+
const last = index === parts.length - 1
|
|
175
|
+
switch (part.kind) {
|
|
176
|
+
case "text":
|
|
177
|
+
return (
|
|
178
|
+
<markdown
|
|
179
|
+
key={key}
|
|
180
|
+
content={part.text.trim()}
|
|
181
|
+
syntaxStyle={syntax}
|
|
182
|
+
fg={colors.text}
|
|
183
|
+
conceal
|
|
184
|
+
streaming={streaming && last}
|
|
185
|
+
/>
|
|
186
|
+
)
|
|
187
|
+
case "reasoning":
|
|
188
|
+
// A model that keeps its thinking to itself sends it without text: nothing to show.
|
|
189
|
+
if (!part.text.trim()) return null
|
|
190
|
+
return (
|
|
191
|
+
<Thought
|
|
192
|
+
key={key}
|
|
193
|
+
colors={colors}
|
|
194
|
+
text={part.text}
|
|
195
|
+
done={part.done || !streaming}
|
|
196
|
+
width={width}
|
|
197
|
+
/>
|
|
198
|
+
)
|
|
199
|
+
case "tool":
|
|
200
|
+
return (
|
|
201
|
+
<ToolRow
|
|
202
|
+
key={key}
|
|
203
|
+
colors={colors}
|
|
204
|
+
line={shownLine(toolLine(part, outcomes), folder)}
|
|
205
|
+
state={part.state}
|
|
206
|
+
width={width}
|
|
207
|
+
/>
|
|
208
|
+
)
|
|
209
|
+
default:
|
|
210
|
+
return (
|
|
211
|
+
<text key={key}>
|
|
212
|
+
<span fg={colors.faint}>{"▱ "}</span>
|
|
213
|
+
<span fg={colors.muted}>{part.name}</span>
|
|
214
|
+
</text>
|
|
215
|
+
)
|
|
216
|
+
}
|
|
217
|
+
})}
|
|
218
|
+
</box>
|
|
219
|
+
)
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function Thought({
|
|
223
|
+
colors,
|
|
224
|
+
text,
|
|
225
|
+
done,
|
|
226
|
+
width,
|
|
227
|
+
}: {
|
|
228
|
+
readonly colors: TuiColors
|
|
229
|
+
readonly text: string
|
|
230
|
+
readonly done: boolean
|
|
231
|
+
readonly width: number
|
|
232
|
+
}) {
|
|
233
|
+
const lines = text
|
|
234
|
+
.trim()
|
|
235
|
+
.split("\n")
|
|
236
|
+
.filter((line) => line.trim())
|
|
237
|
+
const room = Math.max(20, width - 14)
|
|
238
|
+
// Its first lines once done, its latest while it thinks; never more than a few.
|
|
239
|
+
const shown = done ? lines.slice(0, THOUGHT_LINES) : lines.slice(-THOUGHT_LINES)
|
|
240
|
+
const more = lines.length - shown.length
|
|
241
|
+
return (
|
|
242
|
+
<box border={["left"]} borderColor={colors.border} paddingLeft={2} flexDirection="column">
|
|
243
|
+
<text fg={colors.muted} attributes={ITALIC}>
|
|
244
|
+
{done ? "Thought" : "Thinking…"}
|
|
245
|
+
</text>
|
|
246
|
+
{shown.map((line, index) => (
|
|
247
|
+
<text key={`${index}-${line.slice(0, 8)}`} fg={colors.faint}>
|
|
248
|
+
{oneLine(line, room)}
|
|
249
|
+
</text>
|
|
250
|
+
))}
|
|
251
|
+
{done && more > 0 ? <text fg={colors.faint}>{`… ${plural(more, "more line")}`}</text> : null}
|
|
252
|
+
</box>
|
|
253
|
+
)
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
const THOUGHT_LINES = 4
|
|
257
|
+
|
|
258
|
+
/** A line cut to `room` columns, so it never wraps. */
|
|
259
|
+
function oneLine(text: string, room: number): string {
|
|
260
|
+
const flat = text.replace(/\s+/g, " ").trim()
|
|
261
|
+
return flat.length > room ? `${flat.slice(0, room - 1)}…` : flat
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
function ToolRow({
|
|
265
|
+
colors,
|
|
266
|
+
line,
|
|
267
|
+
state,
|
|
268
|
+
width,
|
|
269
|
+
}: {
|
|
270
|
+
readonly colors: TuiColors
|
|
271
|
+
readonly line: ToolLine
|
|
272
|
+
readonly width: number
|
|
273
|
+
readonly state: Extract<Part, { kind: "tool" }>["state"]
|
|
274
|
+
}) {
|
|
275
|
+
const spinner = useSpinner(state === "running")
|
|
276
|
+
const room = Math.max(20, width - 16)
|
|
277
|
+
const failed = line.failed || state === "error"
|
|
278
|
+
const tone = line.held ? colors.amber : failed ? colors.red : colors.faint
|
|
279
|
+
if (line.command !== undefined) {
|
|
280
|
+
return <CommandPanel colors={colors} line={line} running={state === "running"} room={room} />
|
|
281
|
+
}
|
|
282
|
+
const mark = state === "running" ? spinner : "●"
|
|
283
|
+
const markColor =
|
|
284
|
+
state === "running"
|
|
285
|
+
? colors.blue
|
|
286
|
+
: line.held
|
|
287
|
+
? colors.amber
|
|
288
|
+
: failed
|
|
289
|
+
? colors.red
|
|
290
|
+
: colors.green
|
|
291
|
+
return (
|
|
292
|
+
<box flexDirection="column">
|
|
293
|
+
<text>
|
|
294
|
+
<span fg={markColor}>{`${mark} `}</span>
|
|
295
|
+
<span fg={colors.text} attributes={BOLD}>
|
|
296
|
+
{line.verb}
|
|
297
|
+
</span>
|
|
298
|
+
<span fg={colors.muted}>
|
|
299
|
+
{line.detail
|
|
300
|
+
? ` ${oneLine(line.detail, room - line.verb.length - (line.note?.length ?? 0) - 6)}`
|
|
301
|
+
: ""}
|
|
302
|
+
</span>
|
|
303
|
+
{line.note ? <span fg={tone}>{` ${line.note}`}</span> : null}
|
|
304
|
+
</text>
|
|
305
|
+
{line.preview?.map((row, index) => (
|
|
306
|
+
<text key={`${index}-${row.slice(0, 12)}`}>
|
|
307
|
+
<span fg={colors.faint}>{index === 0 ? " ⎿ " : " "}</span>
|
|
308
|
+
<span fg={colors.faint}>{oneLine(row, room)}</span>
|
|
309
|
+
</text>
|
|
310
|
+
))}
|
|
311
|
+
</box>
|
|
312
|
+
)
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/** A shell command as its own panel: the command, what it printed, and how it ended. */
|
|
316
|
+
function CommandPanel({
|
|
317
|
+
colors,
|
|
318
|
+
line,
|
|
319
|
+
running,
|
|
320
|
+
room,
|
|
321
|
+
}: {
|
|
322
|
+
readonly colors: TuiColors
|
|
323
|
+
readonly line: ToolLine
|
|
324
|
+
readonly running: boolean
|
|
325
|
+
readonly room: number
|
|
326
|
+
}) {
|
|
327
|
+
const spinner = useSpinner(running)
|
|
328
|
+
const commandLines = (line.command ?? "").split("\n")
|
|
329
|
+
const shown = commandLines.slice(0, COMMAND_LINES)
|
|
330
|
+
const tone = line.held ? colors.amber : line.failed ? colors.red : colors.faint
|
|
331
|
+
const status = running ? spinner : (line.note ?? "")
|
|
332
|
+
return (
|
|
333
|
+
<box
|
|
334
|
+
backgroundColor={colors.surface}
|
|
335
|
+
paddingLeft={2}
|
|
336
|
+
paddingRight={2}
|
|
337
|
+
paddingTop={1}
|
|
338
|
+
paddingBottom={1}
|
|
339
|
+
flexDirection="column"
|
|
340
|
+
>
|
|
341
|
+
<box flexDirection="row" justifyContent="space-between">
|
|
342
|
+
<box flexDirection="column" flexShrink={1}>
|
|
343
|
+
{shown.map((row, index) => (
|
|
344
|
+
<text key={`${index}-${row.slice(0, 12)}`} wrapMode="none">
|
|
345
|
+
<span fg={colors.blue}>{index === 0 ? "$ " : " "}</span>
|
|
346
|
+
<span fg={colors.text}>{oneLine(row, room - status.length - 6)}</span>
|
|
347
|
+
</text>
|
|
348
|
+
))}
|
|
349
|
+
{commandLines.length > shown.length ? (
|
|
350
|
+
<text
|
|
351
|
+
fg={colors.faint}
|
|
352
|
+
>{` … ${plural(commandLines.length - shown.length, "more line")}`}</text>
|
|
353
|
+
) : null}
|
|
354
|
+
</box>
|
|
355
|
+
{status ? (
|
|
356
|
+
<text fg={running ? colors.blue : tone} flexShrink={0}>
|
|
357
|
+
{status}
|
|
358
|
+
</text>
|
|
359
|
+
) : null}
|
|
360
|
+
</box>
|
|
361
|
+
{line.preview && line.preview.length > 0 ? (
|
|
362
|
+
<box flexDirection="column" paddingTop={1}>
|
|
363
|
+
{line.preview.map((row, index) => (
|
|
364
|
+
<text key={`${index}-${row.slice(0, 12)}`} fg={colors.muted} wrapMode="none">
|
|
365
|
+
{oneLine(row, room - 4)}
|
|
366
|
+
</text>
|
|
367
|
+
))}
|
|
368
|
+
</box>
|
|
369
|
+
) : null}
|
|
370
|
+
</box>
|
|
371
|
+
)
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
const COMMAND_LINES = 3
|
|
375
|
+
|
|
376
|
+
/** Under a turn's answer: where it ran, on which model, and how long it took. */
|
|
377
|
+
function RunMeta({
|
|
378
|
+
colors,
|
|
379
|
+
run,
|
|
380
|
+
modelNames,
|
|
381
|
+
computerRuns,
|
|
382
|
+
waiting,
|
|
383
|
+
}: {
|
|
384
|
+
readonly colors: TuiColors
|
|
385
|
+
readonly run: Run
|
|
386
|
+
readonly modelNames: ModelNames
|
|
387
|
+
readonly computerRuns: boolean
|
|
388
|
+
/** One of its calls still waits for the person. */
|
|
389
|
+
readonly waiting: boolean
|
|
390
|
+
}) {
|
|
391
|
+
const model = run.model
|
|
392
|
+
? (modelNames.get(`${run.model.provider}:${run.model.modelId}`) ?? run.model.modelId)
|
|
393
|
+
: undefined
|
|
394
|
+
const took =
|
|
395
|
+
run.startedAt && run.completedAt
|
|
396
|
+
? duration(Date.parse(run.completedAt) - Date.parse(run.startedAt))
|
|
397
|
+
: undefined
|
|
398
|
+
const ended =
|
|
399
|
+
run.status === "cancelled"
|
|
400
|
+
? run.finishReason === "interrupted"
|
|
401
|
+
? "interrupted"
|
|
402
|
+
: "stopped"
|
|
403
|
+
: run.status === "failed"
|
|
404
|
+
? "failed"
|
|
405
|
+
: run.finishReason === "awaiting_approval" && waiting
|
|
406
|
+
? "waiting for you"
|
|
407
|
+
: undefined
|
|
408
|
+
const items = [run.tier ? TIER_NAMES[run.tier] : undefined, model, took].filter(
|
|
409
|
+
(item): item is string => Boolean(item)
|
|
410
|
+
)
|
|
411
|
+
return (
|
|
412
|
+
<text>
|
|
413
|
+
<span fg={colors.blue}>{" ▰ "}</span>
|
|
414
|
+
<span fg={colors.text}>{placeLabel(computerRuns ? "computer" : "cloud")}</span>
|
|
415
|
+
{items.map((item) => (
|
|
416
|
+
<span key={item} fg={colors.muted}>{` · ${item}`}</span>
|
|
417
|
+
))}
|
|
418
|
+
{ended ? (
|
|
419
|
+
<span fg={run.status === "failed" ? colors.red : colors.amber}>{` · ${ended}`}</span>
|
|
420
|
+
) : null}
|
|
421
|
+
{run.status === "failed" && run.error ? (
|
|
422
|
+
<span fg={colors.faint}>{` ${run.error.message}`}</span>
|
|
423
|
+
) : null}
|
|
424
|
+
</text>
|
|
425
|
+
)
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
/** How a call waiting for the person can be decided, in the order the card offers them. */
|
|
429
|
+
export const APPROVAL_CHOICES = [
|
|
430
|
+
{ key: "y", label: "Allow", decision: "approve", always: false },
|
|
431
|
+
{ key: "a", label: "Always in this thread", decision: "approve", always: true },
|
|
432
|
+
{ key: "n", label: "Deny", decision: "deny", always: false },
|
|
433
|
+
] as const
|
|
434
|
+
|
|
435
|
+
/** A call waiting for the person: what it would do, and the choices that decide it. */
|
|
436
|
+
function ApprovalCard({
|
|
437
|
+
colors,
|
|
438
|
+
approval,
|
|
439
|
+
choice,
|
|
440
|
+
}: {
|
|
441
|
+
readonly colors: TuiColors
|
|
442
|
+
readonly approval: Approval
|
|
443
|
+
/** The choice enter would make; absent on a card that is not the one being decided. */
|
|
444
|
+
readonly choice?: number
|
|
445
|
+
}) {
|
|
446
|
+
const { call } = approval
|
|
447
|
+
const title =
|
|
448
|
+
call.kind === "action"
|
|
449
|
+
? `Run ${call.actionId}${call.subject.kind === "object" ? ` on ${call.subject.objectTypeId} ${call.subject.primaryId}` : ""}?`
|
|
450
|
+
: `Start the ${call.workflowId} workflow?`
|
|
451
|
+
const input = JSON.stringify(call.kind === "action" ? call.params : call.input)
|
|
452
|
+
const external = call.kind === "action" && call.effect === "external"
|
|
453
|
+
return (
|
|
454
|
+
<box
|
|
455
|
+
border={["left"]}
|
|
456
|
+
borderStyle="heavy"
|
|
457
|
+
borderColor={colors.amber}
|
|
458
|
+
backgroundColor={colors.surface}
|
|
459
|
+
paddingLeft={2}
|
|
460
|
+
paddingRight={2}
|
|
461
|
+
paddingTop={1}
|
|
462
|
+
paddingBottom={1}
|
|
463
|
+
marginLeft={3}
|
|
464
|
+
flexDirection="column"
|
|
465
|
+
>
|
|
466
|
+
<text>
|
|
467
|
+
<span fg={colors.amber}>{"? "}</span>
|
|
468
|
+
<span fg={colors.text} attributes={BOLD}>
|
|
469
|
+
{title}
|
|
470
|
+
</span>
|
|
471
|
+
{external ? <span fg={colors.muted}>{" reaches outside Sixb"}</span> : null}
|
|
472
|
+
</text>
|
|
473
|
+
{input && input !== "{}" ? (
|
|
474
|
+
<text fg={colors.faint}>{input.length > 220 ? `${input.slice(0, 217)}…` : input}</text>
|
|
475
|
+
) : null}
|
|
476
|
+
<box height={1} />
|
|
477
|
+
<text>
|
|
478
|
+
{APPROVAL_CHOICES.map((option, index) => {
|
|
479
|
+
const chosen = index === choice
|
|
480
|
+
return (
|
|
481
|
+
<span key={option.key}>
|
|
482
|
+
{index > 0 ? " " : ""}
|
|
483
|
+
<span fg={chosen ? colors.amber : colors.faint}>{chosen ? "▸ " : " "}</span>
|
|
484
|
+
<span fg={chosen ? colors.text : colors.muted} attributes={chosen ? BOLD : 0}>
|
|
485
|
+
{option.label}
|
|
486
|
+
</span>
|
|
487
|
+
<span fg={colors.faint}>{` ${option.key}`}</span>
|
|
488
|
+
</span>
|
|
489
|
+
)
|
|
490
|
+
})}
|
|
491
|
+
</text>
|
|
492
|
+
</box>
|
|
493
|
+
)
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
/** While a turn works: the spinner, how long, and how to stop it. */
|
|
497
|
+
export function Working({
|
|
498
|
+
colors,
|
|
499
|
+
since,
|
|
500
|
+
label,
|
|
501
|
+
stopping = false,
|
|
502
|
+
}: {
|
|
503
|
+
readonly colors: TuiColors
|
|
504
|
+
readonly since: number
|
|
505
|
+
readonly label: string
|
|
506
|
+
/** Waiting for a second esc: the hint is the label then. */
|
|
507
|
+
readonly stopping?: boolean
|
|
508
|
+
}) {
|
|
509
|
+
const now = useNow(120)
|
|
510
|
+
return (
|
|
511
|
+
<text>
|
|
512
|
+
<span>{" "}</span>
|
|
513
|
+
<Wave colors={colors} at={now} />
|
|
514
|
+
<span fg={colors.text}>{` ${label}`}</span>
|
|
515
|
+
<span fg={colors.faint}>{` ${duration(Math.max(0, now - since))}`}</span>
|
|
516
|
+
{stopping ? null : <span fg={colors.faint}>{" esc to stop"}</span>}
|
|
517
|
+
</text>
|
|
518
|
+
)
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
/** A call's line with its paths as the person reads them. */
|
|
522
|
+
function shownLine(line: ToolLine, folder?: string): ToolLine {
|
|
523
|
+
return {
|
|
524
|
+
...line,
|
|
525
|
+
detail: friendlyPath(line.detail, folder),
|
|
526
|
+
...(line.command === undefined ? {} : { command: friendlyPath(line.command, folder) }),
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
const WAVE_TILES = 4
|
|
531
|
+
|
|
532
|
+
/**
|
|
533
|
+
* The mosaic at work: a tile in each of its blues, the brightest moving along them, as the
|
|
534
|
+
* website's hero fills.
|
|
535
|
+
*/
|
|
536
|
+
function Wave({ colors, at }: { readonly colors: TuiColors; readonly at: number }) {
|
|
537
|
+
const lead = Math.floor(at / 120) % (WAVE_TILES * 2 - 2)
|
|
538
|
+
const position = lead < WAVE_TILES ? lead : WAVE_TILES * 2 - 2 - lead
|
|
539
|
+
return (
|
|
540
|
+
<>
|
|
541
|
+
{Array.from({ length: WAVE_TILES }, (_, index) => {
|
|
542
|
+
const distance = Math.abs(index - position)
|
|
543
|
+
const color =
|
|
544
|
+
distance === 0
|
|
545
|
+
? colors.blue
|
|
546
|
+
: (colors.water[Math.max(0, colors.water.length - 1 - distance)] ?? colors.faint)
|
|
547
|
+
return (
|
|
548
|
+
<span key={index} fg={distance > 2 ? colors.border : color}>
|
|
549
|
+
{distance === 0 ? "▰" : "▱"}
|
|
550
|
+
</span>
|
|
551
|
+
)
|
|
552
|
+
})}
|
|
553
|
+
</>
|
|
554
|
+
)
|
|
555
|
+
}
|
package/src/tui/ui.tsx
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/** @jsxImportSource @opentui/react */
|
|
2
|
+
import { createTextAttributes, type KeyBinding, type TextareaRenderable } from "@opentui/core"
|
|
3
|
+
import { 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
|
+
/** Enter sends; shift+enter or ctrl+j starts a new line. */
|
|
11
|
+
const COMPOSER_KEYS: KeyBinding[] = [
|
|
12
|
+
{ name: "return", action: "submit" },
|
|
13
|
+
{ name: "return", shift: true, action: "newline" },
|
|
14
|
+
{ name: "return", meta: true, action: "newline" },
|
|
15
|
+
{ name: "j", ctrl: true, action: "newline" },
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
/** One piece of the line under the composer, such as `This Mac` or `Ask first`. */
|
|
19
|
+
export interface StatusItem {
|
|
20
|
+
readonly text: string
|
|
21
|
+
readonly color: string
|
|
22
|
+
readonly bold?: boolean
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Where a message is written: a panel with Sixb's blue bar, the line it will be sent with under
|
|
27
|
+
* it. `onSubmit` takes the text; the composer clears once it was taken.
|
|
28
|
+
*/
|
|
29
|
+
export function Composer({
|
|
30
|
+
colors,
|
|
31
|
+
placeholder,
|
|
32
|
+
status,
|
|
33
|
+
focused,
|
|
34
|
+
accent,
|
|
35
|
+
allowEmpty = false,
|
|
36
|
+
onSubmit,
|
|
37
|
+
onChange,
|
|
38
|
+
}: {
|
|
39
|
+
readonly colors: TuiColors
|
|
40
|
+
readonly placeholder: string
|
|
41
|
+
readonly status: readonly StatusItem[]
|
|
42
|
+
readonly focused: boolean
|
|
43
|
+
/** The bar's color: blue, or amber while something waits on the person. */
|
|
44
|
+
readonly accent?: string
|
|
45
|
+
/** Enter sends an empty composer too, as a form's default does. */
|
|
46
|
+
readonly allowEmpty?: boolean
|
|
47
|
+
readonly onSubmit: (text: string) => boolean | Promise<boolean>
|
|
48
|
+
/** The text as it is typed. */
|
|
49
|
+
readonly onChange?: (text: string) => void
|
|
50
|
+
}) {
|
|
51
|
+
const input = useRef<TextareaRenderable>(null)
|
|
52
|
+
const [lines, setLines] = useState(1)
|
|
53
|
+
return (
|
|
54
|
+
<box
|
|
55
|
+
border={["left"]}
|
|
56
|
+
borderStyle="heavy"
|
|
57
|
+
borderColor={accent ?? (focused ? colors.blue : colors.border)}
|
|
58
|
+
backgroundColor={colors.surface}
|
|
59
|
+
paddingLeft={2}
|
|
60
|
+
paddingRight={2}
|
|
61
|
+
paddingTop={1}
|
|
62
|
+
paddingBottom={1}
|
|
63
|
+
flexDirection="column"
|
|
64
|
+
flexShrink={0}
|
|
65
|
+
>
|
|
66
|
+
<textarea
|
|
67
|
+
ref={input}
|
|
68
|
+
focused={focused}
|
|
69
|
+
placeholder={placeholder}
|
|
70
|
+
textColor={colors.text}
|
|
71
|
+
focusedTextColor={colors.text}
|
|
72
|
+
placeholderColor={colors.faint}
|
|
73
|
+
backgroundColor={colors.surface}
|
|
74
|
+
focusedBackgroundColor={colors.surface}
|
|
75
|
+
keyBindings={COMPOSER_KEYS}
|
|
76
|
+
height={Math.min(lines, 8)}
|
|
77
|
+
onContentChange={() => {
|
|
78
|
+
const text = input.current?.plainText ?? ""
|
|
79
|
+
setLines(Math.max(1, input.current?.lineCount ?? text.split("\n").length))
|
|
80
|
+
onChange?.(text)
|
|
81
|
+
}}
|
|
82
|
+
onSubmit={() => {
|
|
83
|
+
const text = input.current?.plainText.trim() ?? ""
|
|
84
|
+
if (!text && !allowEmpty) return
|
|
85
|
+
void Promise.resolve(onSubmit(text)).then((taken) => {
|
|
86
|
+
if (!taken) return
|
|
87
|
+
input.current?.setText("")
|
|
88
|
+
setLines(1)
|
|
89
|
+
onChange?.("")
|
|
90
|
+
})
|
|
91
|
+
}}
|
|
92
|
+
/>
|
|
93
|
+
<box height={1} />
|
|
94
|
+
<text>
|
|
95
|
+
{status.map((item, index) => (
|
|
96
|
+
<span key={item.text}>
|
|
97
|
+
{index > 0 ? <span fg={colors.faint}>{" · "}</span> : null}
|
|
98
|
+
<span fg={item.color} attributes={item.bold ? BOLD : 0}>
|
|
99
|
+
{item.text}
|
|
100
|
+
</span>
|
|
101
|
+
</span>
|
|
102
|
+
))}
|
|
103
|
+
</text>
|
|
104
|
+
</box>
|
|
105
|
+
)
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** Key hints: `tab where shift+tab permissions ctrl+p commands`. */
|
|
109
|
+
export function KeyHints({
|
|
110
|
+
colors,
|
|
111
|
+
items,
|
|
112
|
+
}: {
|
|
113
|
+
readonly colors: TuiColors
|
|
114
|
+
readonly items: readonly (readonly [key: string, label: string])[]
|
|
115
|
+
}) {
|
|
116
|
+
return (
|
|
117
|
+
<text>
|
|
118
|
+
{items.map(([key, label], index) => (
|
|
119
|
+
<span key={key}>
|
|
120
|
+
{index > 0 ? " " : ""}
|
|
121
|
+
<span fg={colors.text}>{key}</span>
|
|
122
|
+
<span fg={colors.muted}>{` ${label}`}</span>
|
|
123
|
+
</span>
|
|
124
|
+
))}
|
|
125
|
+
</text>
|
|
126
|
+
)
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export function useSpinner(active: boolean): string {
|
|
130
|
+
const [frame, setFrame] = useState(0)
|
|
131
|
+
useEffect(() => {
|
|
132
|
+
if (!active) return
|
|
133
|
+
const timer = setInterval(() => setFrame((value) => value + 1), 80)
|
|
134
|
+
return () => clearInterval(timer)
|
|
135
|
+
}, [active])
|
|
136
|
+
return SPINNER_FRAMES[frame % SPINNER_FRAMES.length] ?? "·"
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** Re-renders every `ms` while `active`, for a clock. */
|
|
140
|
+
export function useNow(ms: number, active = true): number {
|
|
141
|
+
const [now, setNow] = useState(Date.now())
|
|
142
|
+
useEffect(() => {
|
|
143
|
+
if (!active) return
|
|
144
|
+
const timer = setInterval(() => setNow(Date.now()), ms)
|
|
145
|
+
return () => clearInterval(timer)
|
|
146
|
+
}, [ms, active])
|
|
147
|
+
return now
|
|
148
|
+
}
|
|
@@ -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
|