@sixb/cli 0.1.26 → 0.2.1
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/dist/commands/agent.d.ts.map +1 -1
- 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.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/lib/command-line.d.ts +26 -1
- 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/hidden-prompt.d.ts +19 -0
- package/dist/lib/hidden-prompt.d.ts.map +1 -0
- package/dist/tui/app.d.ts +8 -0
- package/dist/tui/app.d.ts.map +1 -1
- package/dist/tui/computer.d.ts +5 -0
- package/dist/tui/computer.d.ts.map +1 -1
- package/dist/tui/context.d.ts +13 -0
- package/dist/tui/context.d.ts.map +1 -0
- package/dist/tui/format.d.ts +85 -0
- package/dist/tui/format.d.ts.map +1 -1
- package/dist/tui/index.d.ts.map +1 -1
- package/dist/tui/markdown.d.ts +18 -0
- package/dist/tui/markdown.d.ts.map +1 -0
- package/dist/tui/parts.d.ts +8 -0
- package/dist/tui/parts.d.ts.map +1 -1
- package/dist/tui/runner.d.ts +37 -14
- package/dist/tui/runner.d.ts.map +1 -1
- package/dist/tui/settings.d.ts +13 -1
- package/dist/tui/settings.d.ts.map +1 -1
- package/dist/tui/transcript.d.ts +1 -1
- package/dist/tui/transcript.d.ts.map +1 -1
- package/dist/tui/ui.d.ts +7 -0
- package/dist/tui/ui.d.ts.map +1 -1
- 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 -19
- package/src/commands/agent.ts +17 -10
- 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 -1
- package/src/commands/dev.ts +3 -0
- package/src/commands/env.ts +422 -0
- package/src/index.tsx +39 -1
- package/src/lib/command-line.ts +59 -1
- package/src/lib/deploy-release.ts +3 -0
- 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/hidden-prompt.ts +97 -0
- package/src/tui/app.tsx +315 -179
- package/src/tui/computer.ts +37 -0
- package/src/tui/context.tsx +149 -0
- package/src/tui/format.ts +218 -1
- package/src/tui/index.tsx +13 -2
- package/src/tui/markdown.ts +91 -0
- package/src/tui/parts.ts +23 -3
- package/src/tui/runner.ts +113 -30
- package/src/tui/settings.ts +54 -5
- package/src/tui/transcript.tsx +90 -8
- package/src/tui/ui.tsx +40 -11
- package/src/ui/deploy-screens.ts +12 -1
- package/src/ui/env-screens.ts +81 -0
- package/dist/tui/folders.d.ts +0 -7
- package/dist/tui/folders.d.ts.map +0 -1
- package/src/tui/folders.ts +0 -41
package/src/tui/app.tsx
CHANGED
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
decideAgentApproval,
|
|
16
16
|
type GetAgentThreadResponses,
|
|
17
17
|
getAgentThread,
|
|
18
|
+
getAgentThreadContext,
|
|
18
19
|
listAgentThreadApprovals,
|
|
19
20
|
listAgentThreadMessages,
|
|
20
21
|
listAgentThreadRuns,
|
|
@@ -26,12 +27,13 @@ import {
|
|
|
26
27
|
} from "@sixb/client"
|
|
27
28
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react"
|
|
28
29
|
import { Logo } from "./brand"
|
|
30
|
+
import { thisComputer } from "./computer"
|
|
29
31
|
import type { Connection } from "./connection"
|
|
30
|
-
import {
|
|
31
|
-
import { shortPath } from "./format"
|
|
32
|
+
import { ContextPanel } from "./context"
|
|
33
|
+
import { type ContextUse, contextStatus, fittedContextText, shortPath } from "./format"
|
|
32
34
|
import { Palette, type PaletteItem } from "./palette"
|
|
33
35
|
import { type LiveRun, liveRun, reduceLive, type ShownMessage, shownMessage } from "./parts"
|
|
34
|
-
import { type LocalRunner, owns
|
|
36
|
+
import { type LocalRunner, owns } from "./runner"
|
|
35
37
|
import {
|
|
36
38
|
APPROVAL_MODES,
|
|
37
39
|
type ApprovalMode,
|
|
@@ -41,13 +43,14 @@ import {
|
|
|
41
43
|
modelLabel,
|
|
42
44
|
placeLabel,
|
|
43
45
|
type ReasoningLevel,
|
|
46
|
+
rememberWebMessages,
|
|
44
47
|
type Settings,
|
|
45
48
|
saveSettings,
|
|
46
49
|
} from "./settings"
|
|
47
50
|
import { pickSlash, type SlashCommand, slashMatches } from "./slash"
|
|
48
51
|
import type { TuiColors } from "./theme"
|
|
49
52
|
import { APPROVAL_CHOICES, type Approval, type Run, Transcript, Working } from "./transcript"
|
|
50
|
-
import { BOLD, Composer, KeyHints, type StatusItem } from "./ui"
|
|
53
|
+
import { BOLD, Composer, ComposerDraft, KeyHints, type StatusItem } from "./ui"
|
|
51
54
|
|
|
52
55
|
type Thread = GetAgentThreadResponses[200]
|
|
53
56
|
type Screen = { readonly kind: "home" } | { readonly kind: "thread"; readonly threadId: string }
|
|
@@ -86,6 +89,7 @@ export function Workspace(props: WorkspaceProps) {
|
|
|
86
89
|
readonly tone: "info" | "error"
|
|
87
90
|
} | null>(null)
|
|
88
91
|
const [quitArmed, setQuitArmed] = useState(false)
|
|
92
|
+
const draft = useRef<(() => boolean) | null>(null)
|
|
89
93
|
|
|
90
94
|
const setSettings = useCallback((change: (current: Settings) => Settings) => {
|
|
91
95
|
setSettingsState((current) => {
|
|
@@ -124,17 +128,26 @@ export function Workspace(props: WorkspaceProps) {
|
|
|
124
128
|
}, 300)
|
|
125
129
|
})
|
|
126
130
|
|
|
127
|
-
// This folder's conversations run here whatever screen is open
|
|
128
|
-
//
|
|
131
|
+
// This folder's conversations run here whatever screen is open, while its session is: a message
|
|
132
|
+
// sent from the web app, a turn going on after approvals decided there, and those that queued
|
|
133
|
+
// while sixb was closed, which the session's first renewal lists.
|
|
129
134
|
const { runner } = props
|
|
130
135
|
useEffect(() => {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
136
|
+
if (!settings.continueFromWeb) return
|
|
137
|
+
runner.openSession()
|
|
138
|
+
return () => void runner.closeSession()
|
|
139
|
+
}, [settings.continueFromWeb, runner])
|
|
140
|
+
useEffect(
|
|
141
|
+
() => runner.onElsewhere(() => say("A message sent from elsewhere runs here")),
|
|
142
|
+
[runner, say]
|
|
143
|
+
)
|
|
144
|
+
useEffect(() => {
|
|
134
145
|
const socket = createAgentActivitySocket({
|
|
135
146
|
client: connection.client,
|
|
136
147
|
onActivity: (event) => {
|
|
137
|
-
if (event.status === "queued"
|
|
148
|
+
if (event.status === "queued" && event.runsOn === "computer") {
|
|
149
|
+
void runner.claimIfHere(event.threadId, event.runId)
|
|
150
|
+
}
|
|
138
151
|
},
|
|
139
152
|
})
|
|
140
153
|
return () => socket.close()
|
|
@@ -214,6 +227,8 @@ export function Workspace(props: WorkspaceProps) {
|
|
|
214
227
|
|
|
215
228
|
useKeyboard((key: KeyEvent) => {
|
|
216
229
|
if (key.ctrl && key.name === "c") {
|
|
230
|
+
// A draft goes first; ctrl+c on an empty composer quits.
|
|
231
|
+
if (draft.current?.()) return setQuitArmed(false)
|
|
217
232
|
if (quitArmed) return props.onExit()
|
|
218
233
|
setQuitArmed(true)
|
|
219
234
|
setTimeout(() => setQuitArmed(false), 2_000)
|
|
@@ -292,107 +307,124 @@ export function Workspace(props: WorkspaceProps) {
|
|
|
292
307
|
}
|
|
293
308
|
|
|
294
309
|
return (
|
|
295
|
-
<
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
310
|
+
<ComposerDraft.Provider value={draft}>
|
|
311
|
+
<box flexDirection="column" flexGrow={1} backgroundColor={colors.background}>
|
|
312
|
+
{screen.kind === "home" ? (
|
|
313
|
+
<Home
|
|
314
|
+
{...common}
|
|
315
|
+
onPlace={() =>
|
|
316
|
+
setSettings((current) => {
|
|
317
|
+
const place = current.place === "computer" ? "cloud" : "computer"
|
|
318
|
+
say(
|
|
319
|
+
place === "cloud"
|
|
320
|
+
? "New conversations run in the cloud"
|
|
321
|
+
: `New conversations run on ${placeLabel(place)}`
|
|
322
|
+
)
|
|
323
|
+
return { ...current, place }
|
|
324
|
+
})
|
|
325
|
+
}
|
|
326
|
+
onOpen={(threadId) => setScreen({ kind: "thread", threadId })}
|
|
327
|
+
/>
|
|
328
|
+
) : (
|
|
329
|
+
<ThreadView
|
|
330
|
+
key={screen.threadId}
|
|
331
|
+
{...common}
|
|
332
|
+
threadId={screen.threadId}
|
|
333
|
+
approval={approval}
|
|
334
|
+
onThreadRead={readApproval}
|
|
335
|
+
/>
|
|
336
|
+
)}
|
|
337
|
+
{notice || quitArmed ? (
|
|
338
|
+
<box
|
|
339
|
+
position="absolute"
|
|
340
|
+
right={2}
|
|
341
|
+
top={1}
|
|
342
|
+
backgroundColor={colors.surface}
|
|
343
|
+
paddingLeft={2}
|
|
344
|
+
paddingRight={2}
|
|
345
|
+
zIndex={5}
|
|
346
|
+
>
|
|
347
|
+
<text
|
|
348
|
+
fg={quitArmed ? colors.text : notice?.tone === "error" ? colors.red : colors.text}
|
|
349
|
+
>
|
|
350
|
+
{quitArmed ? "Press ctrl+c again to quit" : notice?.text}
|
|
351
|
+
</text>
|
|
352
|
+
</box>
|
|
353
|
+
) : null}
|
|
354
|
+
{dialog === "commands" ? (
|
|
355
|
+
<Palette
|
|
356
|
+
colors={colors}
|
|
357
|
+
title="Commands"
|
|
358
|
+
placeholder="Search"
|
|
359
|
+
onClose={() => setDialog(null)}
|
|
360
|
+
items={commandItems({
|
|
361
|
+
settings,
|
|
362
|
+
approvalMode,
|
|
363
|
+
models,
|
|
364
|
+
newConversation: () => setScreen({ kind: "home" }),
|
|
365
|
+
open: setDialog,
|
|
366
|
+
setPlace: (place) => setSettings((current) => ({ ...current, place })),
|
|
367
|
+
toggleContinueFromWeb: () =>
|
|
368
|
+
setSettings((current) => {
|
|
369
|
+
const continueFromWeb = !current.continueFromWeb
|
|
370
|
+
say(
|
|
371
|
+
continueFromWeb
|
|
372
|
+
? "Messages from the web run in this folder"
|
|
373
|
+
: "Messages from the web wait, in this folder, until you turn this back on"
|
|
374
|
+
)
|
|
375
|
+
void rememberWebMessages(runner.folder, continueFromWeb).catch(() =>
|
|
376
|
+
say("Could not keep this choice for next time", "error")
|
|
377
|
+
)
|
|
378
|
+
return { ...current, continueFromWeb }
|
|
379
|
+
}),
|
|
380
|
+
cycleEffort,
|
|
381
|
+
quit: props.onExit,
|
|
382
|
+
})}
|
|
383
|
+
/>
|
|
384
|
+
) : null}
|
|
385
|
+
{dialog === "threads" ? (
|
|
386
|
+
<ThreadsDialog
|
|
387
|
+
connection={connection}
|
|
388
|
+
colors={colors}
|
|
389
|
+
onClose={() => setDialog(null)}
|
|
390
|
+
onOpen={(threadId) => setScreen({ kind: "thread", threadId })}
|
|
391
|
+
/>
|
|
392
|
+
) : null}
|
|
393
|
+
{dialog === "models" ? (
|
|
394
|
+
<Palette
|
|
395
|
+
colors={colors}
|
|
396
|
+
title="Model"
|
|
397
|
+
placeholder="Search models"
|
|
398
|
+
onClose={() => setDialog(null)}
|
|
399
|
+
items={modelItems(models, settings, (model, reasoning) =>
|
|
400
|
+
setSettings((current) => {
|
|
401
|
+
const { model: _model, reasoning: _reasoning, ...rest } = current
|
|
402
|
+
return {
|
|
403
|
+
...rest,
|
|
404
|
+
...(model ? { model: { provider: model.provider, modelId: model.modelId } } : {}),
|
|
405
|
+
...(reasoning ? { reasoning } : {}),
|
|
406
|
+
}
|
|
407
|
+
})
|
|
408
|
+
)}
|
|
409
|
+
/>
|
|
410
|
+
) : null}
|
|
411
|
+
{dialog === "permissions" ? (
|
|
412
|
+
<Palette
|
|
413
|
+
colors={colors}
|
|
414
|
+
title="What can the agent do without asking?"
|
|
415
|
+
placeholder="Search"
|
|
416
|
+
onClose={() => setDialog(null)}
|
|
417
|
+
items={APPROVAL_MODES.map((entry) => ({
|
|
418
|
+
id: entry.mode,
|
|
419
|
+
label: entry.label,
|
|
420
|
+
detail: entry.description,
|
|
421
|
+
current: entry.mode === approvalMode,
|
|
422
|
+
run: () => chooseApproval(entry.mode),
|
|
423
|
+
}))}
|
|
424
|
+
/>
|
|
425
|
+
) : null}
|
|
426
|
+
</box>
|
|
427
|
+
</ComposerDraft.Provider>
|
|
396
428
|
)
|
|
397
429
|
}
|
|
398
430
|
|
|
@@ -427,8 +459,6 @@ function SlashMenu({
|
|
|
427
459
|
bottom={above}
|
|
428
460
|
zIndex={5}
|
|
429
461
|
backgroundColor={colors.surface}
|
|
430
|
-
paddingTop={1}
|
|
431
|
-
paddingBottom={1}
|
|
432
462
|
flexDirection="column"
|
|
433
463
|
>
|
|
434
464
|
{matches.map((command, index) => {
|
|
@@ -507,12 +537,22 @@ function Home(
|
|
|
507
537
|
["ctrl+p", "commands"],
|
|
508
538
|
]
|
|
509
539
|
const hintsWidth = hints.reduce((sum, [key, label]) => sum + key.length + label.length + 3, 0)
|
|
540
|
+
// Where it runs, beside the hints, in the room they leave.
|
|
541
|
+
const room = composerWidth - hintsWidth - 2
|
|
542
|
+
const where =
|
|
543
|
+
settings.place === "computer" ? shortPath(runner.folder, homedir(), room) : "Runs in the cloud"
|
|
510
544
|
const [sending, setSending] = useState(false)
|
|
511
545
|
const [typed, setTyped] = useState("")
|
|
512
546
|
const slash = useSlashMenu(props.slashCommands, typed)
|
|
513
|
-
// Which instance this is matters most when it isn't this computer's.
|
|
547
|
+
// Which instance this is matters most when it isn't this computer's: it reads brighter then.
|
|
514
548
|
const host = new URL(connection.apiUrl).host
|
|
515
549
|
const remote = !/^(localhost|127\.0\.0\.1|\[::1\])(:\d+)?$/.test(host)
|
|
550
|
+
const shownVersion = version.replace(/^sixb v/, "")
|
|
551
|
+
const instance = fitted(
|
|
552
|
+
[connection.project.id, host, ...(connection.user ? [connection.user.name] : [])],
|
|
553
|
+
width - shownVersion.length - 6
|
|
554
|
+
)
|
|
555
|
+
const instanceTones = remote ? [colors.text, colors.muted] : [colors.muted]
|
|
516
556
|
|
|
517
557
|
useKeyboard((key: KeyEvent) => {
|
|
518
558
|
if (props.dialogOpen) return
|
|
@@ -530,7 +570,12 @@ function Home(
|
|
|
530
570
|
client: connection.client,
|
|
531
571
|
body: {
|
|
532
572
|
title: clip(text.split("\n")[0]?.trim() || "Conversation", 72),
|
|
533
|
-
...(settings.place === "computer"
|
|
573
|
+
...(settings.place === "computer"
|
|
574
|
+
? {
|
|
575
|
+
runsOn: "computer" as const,
|
|
576
|
+
computer: { ...(await thisComputer()), folder: runner.folder },
|
|
577
|
+
}
|
|
578
|
+
: {}),
|
|
534
579
|
},
|
|
535
580
|
throwOnError: true,
|
|
536
581
|
})
|
|
@@ -554,10 +599,7 @@ function Home(
|
|
|
554
599
|
},
|
|
555
600
|
throwOnError: true,
|
|
556
601
|
})
|
|
557
|
-
if (created.thread.runsOn === "computer")
|
|
558
|
-
await rememberFolder(created.thread.id, runner.folder)
|
|
559
|
-
void runner.claim(posted.run.id)
|
|
560
|
-
}
|
|
602
|
+
if (created.thread.runsOn === "computer") void runner.claim(posted.run.id)
|
|
561
603
|
props.onOpen(created.thread.id)
|
|
562
604
|
return true
|
|
563
605
|
} catch (error) {
|
|
@@ -584,18 +626,9 @@ function Home(
|
|
|
584
626
|
onSubmit={send}
|
|
585
627
|
/>
|
|
586
628
|
<box flexDirection="row" justifyContent="space-between">
|
|
587
|
-
{
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
<span fg={colors.muted}>{` · ${host}`}</span>
|
|
591
|
-
</text>
|
|
592
|
-
) : (
|
|
593
|
-
<text fg={colors.faint} wrapMode="none">
|
|
594
|
-
{settings.place === "computer"
|
|
595
|
-
? shortPath(runner.folder, homedir(), composerWidth - hintsWidth - 2)
|
|
596
|
-
: "Runs in the cloud"}
|
|
597
|
-
</text>
|
|
598
|
-
)}
|
|
629
|
+
<text fg={colors.faint} wrapMode="none">
|
|
630
|
+
{where.length <= room ? where : ""}
|
|
631
|
+
</text>
|
|
599
632
|
<KeyHints colors={colors} items={hints} />
|
|
600
633
|
</box>
|
|
601
634
|
</box>
|
|
@@ -608,26 +641,25 @@ function Home(
|
|
|
608
641
|
paddingBottom={1}
|
|
609
642
|
>
|
|
610
643
|
<text wrapMode="none">
|
|
611
|
-
{
|
|
612
|
-
<span fg={colors.
|
|
613
|
-
{
|
|
614
|
-
? shortPath(runner.folder, homedir(), 48)
|
|
615
|
-
: "Runs in the cloud"}
|
|
644
|
+
{instance.map((item, index) => (
|
|
645
|
+
<span key={item} fg={instanceTones[index] ?? colors.faint}>
|
|
646
|
+
{index > 0 ? ` · ${item}` : item}
|
|
616
647
|
</span>
|
|
617
|
-
)
|
|
618
|
-
<>
|
|
619
|
-
<span fg={colors.muted}>{connection.project.id}</span>
|
|
620
|
-
<span fg={colors.faint}>{` · ${host}`}</span>
|
|
621
|
-
</>
|
|
622
|
-
)}
|
|
623
|
-
{connection.user ? <span fg={colors.faint}>{` · ${connection.user.name}`}</span> : null}
|
|
648
|
+
))}
|
|
624
649
|
</text>
|
|
625
|
-
<text fg={colors.faint}>{
|
|
650
|
+
<text fg={colors.faint}>{shownVersion}</text>
|
|
626
651
|
</box>
|
|
627
652
|
</box>
|
|
628
653
|
)
|
|
629
654
|
}
|
|
630
655
|
|
|
656
|
+
/** The first of `items` that fit in `room` columns joined by ` · `, the rest dropped. */
|
|
657
|
+
function fitted(items: readonly string[], room: number): string[] {
|
|
658
|
+
const kept = [...items]
|
|
659
|
+
while (kept.length > 1 && kept.join(" · ").length > room) kept.pop()
|
|
660
|
+
return kept
|
|
661
|
+
}
|
|
662
|
+
|
|
631
663
|
/** The model whose effort the person sets: the one chosen, else the project's default without tiers. */
|
|
632
664
|
function effortModel(
|
|
633
665
|
models: readonly LanguageModel[],
|
|
@@ -663,16 +695,54 @@ function ThreadView(
|
|
|
663
695
|
const [messages, setMessages] = useState<readonly ShownMessage[]>([])
|
|
664
696
|
const [runs, setRuns] = useState<readonly Run[]>([])
|
|
665
697
|
const [approvals, setApprovals] = useState<readonly Approval[]>([])
|
|
698
|
+
const [context, setContext] = useState<ContextUse | null>(null)
|
|
666
699
|
const [live, setLive] = useState<LiveRun | null>(null)
|
|
667
700
|
const [stopArmed, setStopArmed] = useState(false)
|
|
668
701
|
const [typed, setTyped] = useState("")
|
|
669
|
-
const
|
|
702
|
+
const [contextOpen, setContextOpen] = useState(false)
|
|
703
|
+
// A conversation adds what only it can show: what it uses of its model's context.
|
|
704
|
+
const slashCommands = useMemo(
|
|
705
|
+
() => [
|
|
706
|
+
...props.slashCommands,
|
|
707
|
+
{
|
|
708
|
+
name: "context",
|
|
709
|
+
description: "What the conversation uses of the model's context",
|
|
710
|
+
run: () => setContextOpen(true),
|
|
711
|
+
},
|
|
712
|
+
],
|
|
713
|
+
[props.slashCommands]
|
|
714
|
+
)
|
|
715
|
+
const slash = useSlashMenu(slashCommands, typed)
|
|
670
716
|
const scroll = useRef<ScrollBoxRenderable>(null)
|
|
671
717
|
|
|
672
718
|
const mine = thread !== null && owns(connection, thread)
|
|
673
719
|
const onComputer = thread?.runsOn === "computer"
|
|
674
720
|
|
|
675
721
|
const { onThreadRead } = props
|
|
722
|
+
// Measured against the model the next message goes to; without a choice, the latest turn's.
|
|
723
|
+
const metered = messageSelection(models, settings).model
|
|
724
|
+
const meteredProvider = metered?.provider
|
|
725
|
+
const meteredModelId = metered?.modelId
|
|
726
|
+
const readContext = useCallback(async () => {
|
|
727
|
+
const { data } = await getAgentThreadContext({
|
|
728
|
+
client,
|
|
729
|
+
path: { threadId },
|
|
730
|
+
query:
|
|
731
|
+
meteredProvider && meteredModelId
|
|
732
|
+
? { provider: meteredProvider, modelId: meteredModelId }
|
|
733
|
+
: {},
|
|
734
|
+
})
|
|
735
|
+
// A meter that cannot be read is left out.
|
|
736
|
+
setContext(data ?? null)
|
|
737
|
+
}, [client, threadId, meteredProvider, meteredModelId])
|
|
738
|
+
// Another model is measured at once, and `reload` stays the same: the streams it keeps open
|
|
739
|
+
// would replay their run from the start if it changed.
|
|
740
|
+
const readContextRef = useRef(readContext)
|
|
741
|
+
readContextRef.current = readContext
|
|
742
|
+
useEffect(() => {
|
|
743
|
+
void readContext()
|
|
744
|
+
}, [readContext])
|
|
745
|
+
|
|
676
746
|
const reload = useCallback(async () => {
|
|
677
747
|
const [threadResult, messageResult, runResult, approvalResult] = await Promise.all([
|
|
678
748
|
getAgentThread({ client, path: { threadId } }),
|
|
@@ -683,6 +753,7 @@ function ThreadView(
|
|
|
683
753
|
}),
|
|
684
754
|
listAgentThreadRuns({ client, path: { threadId }, query: { limit: "200", order: "asc" } }),
|
|
685
755
|
listAgentThreadApprovals({ client, path: { threadId }, query: { status: "pending" } }),
|
|
756
|
+
readContextRef.current(),
|
|
686
757
|
])
|
|
687
758
|
if (threadResult.data) {
|
|
688
759
|
setThread(threadResult.data)
|
|
@@ -698,32 +769,29 @@ function ThreadView(
|
|
|
698
769
|
|
|
699
770
|
const activeRunId = thread?.activeRunId ?? null
|
|
700
771
|
|
|
701
|
-
//
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
// Another of the owner's computers runs it: its folder here, if any, is where it worked before.
|
|
707
|
-
const otherComputer = thread !== null && !runsOnThisComputer(thread, props.computerId)
|
|
708
|
-
const here = workFolder === runner.folder && !otherComputer
|
|
772
|
+
// Where it runs: here, in another folder of this computer, or on another of its owner's. A thread
|
|
773
|
+
// from before folders were kept has none until it moves.
|
|
774
|
+
const place = thread?.computer
|
|
775
|
+
const otherComputer = place !== undefined && place.id !== props.computerId
|
|
776
|
+
const here = place?.id === props.computerId && place.folder === runner.folder
|
|
709
777
|
// This computer runs the conversation's turns when it is the owner's, and this its folder.
|
|
710
|
-
const runsHere =
|
|
778
|
+
const runsHere = thread !== null && runner.runsHere(thread, props.computerId)
|
|
711
779
|
// Only a queued turn: a running one is another sixb's, or one whose sixb closed, which the API
|
|
712
|
-
// ends interrupted rather than running its commands again.
|
|
780
|
+
// ends interrupted rather than running its commands again. One sent from elsewhere runs here
|
|
781
|
+
// only while messages from the web do; the turns this sixb asks for it claims itself.
|
|
713
782
|
const queued = runs.find((run) => run.id === activeRunId)?.status === "queued"
|
|
783
|
+
const { continueFromWeb } = props.settings
|
|
714
784
|
useEffect(() => {
|
|
715
|
-
if (activeRunId && runsHere && queued) void runner.claim(activeRunId)
|
|
716
|
-
}, [activeRunId, runsHere, queued, runner])
|
|
785
|
+
if (activeRunId && runsHere && queued && continueFromWeb) void runner.claim(activeRunId)
|
|
786
|
+
}, [activeRunId, runsHere, queued, continueFromWeb, runner])
|
|
717
787
|
// Its turns move to this computer, which alone claims them from now on, and to this folder.
|
|
718
788
|
const moveHere = async () => {
|
|
719
789
|
const { error } = await moveAgentThreadToComputer({
|
|
720
790
|
client,
|
|
721
791
|
path: { threadId },
|
|
722
|
-
body: {
|
|
792
|
+
body: { computer: { ...(await thisComputer()), folder: runner.folder } },
|
|
723
793
|
})
|
|
724
794
|
if (error) return props.say(errorText(error), "error")
|
|
725
|
-
await rememberFolder(threadId, runner.folder)
|
|
726
|
-
setWorkFolder(runner.folder)
|
|
727
795
|
void reload()
|
|
728
796
|
props.say("Its turns now run in this folder")
|
|
729
797
|
}
|
|
@@ -738,6 +806,9 @@ function ThreadView(
|
|
|
738
806
|
onApprovalActivity: (event) => {
|
|
739
807
|
if (event.threadId === threadId) void reload()
|
|
740
808
|
},
|
|
809
|
+
onThreadMoved: (event) => {
|
|
810
|
+
if (event.threadId === threadId) void reload()
|
|
811
|
+
},
|
|
741
812
|
})
|
|
742
813
|
return () => socket.close()
|
|
743
814
|
}, [client, threadId, reload])
|
|
@@ -753,7 +824,12 @@ function ThreadView(
|
|
|
753
824
|
setLive((current) =>
|
|
754
825
|
reduceLive(current?.runId === activeRunId ? current : liveRun(activeRunId), event)
|
|
755
826
|
)
|
|
756
|
-
|
|
827
|
+
// A compaction that ended changed what the conversation weighs: the meter reads it again.
|
|
828
|
+
if (
|
|
829
|
+
event.type === "agent.message.finalized" ||
|
|
830
|
+
event.type === "agent.run.finished" ||
|
|
831
|
+
event.type === "agent.compaction.completed"
|
|
832
|
+
)
|
|
757
833
|
void reload()
|
|
758
834
|
},
|
|
759
835
|
})
|
|
@@ -794,12 +870,14 @@ function ThreadView(
|
|
|
794
870
|
if (!pending || !option || deciding) return
|
|
795
871
|
setDeciding(true)
|
|
796
872
|
try {
|
|
797
|
-
const { error } = await decideAgentApproval({
|
|
873
|
+
const { data, error } = await decideAgentApproval({
|
|
798
874
|
client,
|
|
799
875
|
path: { threadId, approvalId: pending.id },
|
|
800
876
|
body: { decision: option.decision, ...(option.always ? { always: true as const } : {}) },
|
|
801
877
|
})
|
|
802
878
|
if (error) props.say(errorText(error), "error")
|
|
879
|
+
// Its last decision resumed the turn: decided here, it runs here.
|
|
880
|
+
if (data?.run && runsHere) void runner.claim(data.run.id)
|
|
803
881
|
const read = await reload()
|
|
804
882
|
// "Always" raised the mode there: the thread's wins over a choice still on its way.
|
|
805
883
|
if (read && option.always) onThreadRead(read, true)
|
|
@@ -809,7 +887,7 @@ function ThreadView(
|
|
|
809
887
|
}
|
|
810
888
|
|
|
811
889
|
useKeyboard((key: KeyEvent) => {
|
|
812
|
-
if (props.dialogOpen) return
|
|
890
|
+
if (props.dialogOpen || contextOpen) return
|
|
813
891
|
if (pending && !key.ctrl && !key.meta) {
|
|
814
892
|
const settled = Date.now() - shownAt.current > APPROVAL_GRACE_MS
|
|
815
893
|
if (key.name === "left" || key.name === "up") {
|
|
@@ -826,7 +904,7 @@ function ThreadView(
|
|
|
826
904
|
if (key.name === "up" && slash.move(-1)) return
|
|
827
905
|
if (key.name === "down" && slash.move(1)) return
|
|
828
906
|
if (key.name === "escape") return void stop()
|
|
829
|
-
if (key.ctrl && key.name === "f" && onComputer && mine && !here
|
|
907
|
+
if (key.ctrl && key.name === "f" && onComputer && mine && !here) {
|
|
830
908
|
return void moveHere()
|
|
831
909
|
}
|
|
832
910
|
if (key.name === "pageup") scroll.current?.scrollBy(-10)
|
|
@@ -872,6 +950,30 @@ function ThreadView(
|
|
|
872
950
|
[models]
|
|
873
951
|
)
|
|
874
952
|
const elsewhere = onComputer && thread && !mine
|
|
953
|
+
const placeStatus = props.status(onComputer ? placeLabel("computer") : placeLabel("cloud"))
|
|
954
|
+
// The context ends the status line in what room it leaves: the panel's border and padding, and
|
|
955
|
+
// the screen's, take nine columns.
|
|
956
|
+
const meter = context ? contextStatus(context) : undefined
|
|
957
|
+
const placeColumns = placeStatus.reduce(
|
|
958
|
+
(total, item, index) => total + item.text.length + (index > 0 ? 3 : 0),
|
|
959
|
+
0
|
|
960
|
+
)
|
|
961
|
+
const meterText = meter ? fittedContextText(meter, placeColumns, width - 9) : undefined
|
|
962
|
+
const statusLine: StatusItem[] =
|
|
963
|
+
meter && meterText
|
|
964
|
+
? [
|
|
965
|
+
...placeStatus,
|
|
966
|
+
{
|
|
967
|
+
text: meterText,
|
|
968
|
+
color:
|
|
969
|
+
meter.tone === "over"
|
|
970
|
+
? colors.red
|
|
971
|
+
: meter.tone === "near"
|
|
972
|
+
? colors.amber
|
|
973
|
+
: colors.muted,
|
|
974
|
+
},
|
|
975
|
+
]
|
|
976
|
+
: placeStatus
|
|
875
977
|
const runningSince = runs.find((run) => run.id === activeRunId)?.startedAt
|
|
876
978
|
|
|
877
979
|
return (
|
|
@@ -928,11 +1030,15 @@ function ThreadView(
|
|
|
928
1030
|
stopArmed
|
|
929
1031
|
? "Press esc again to stop"
|
|
930
1032
|
: live?.compacting
|
|
931
|
-
?
|
|
932
|
-
|
|
1033
|
+
? live.contextFull
|
|
1034
|
+
? "Context is full — condensing to continue"
|
|
1035
|
+
: "Condensing earlier turns"
|
|
1036
|
+
: activityLabel(runs, activeRunId, {
|
|
933
1037
|
onComputer,
|
|
934
1038
|
mine,
|
|
935
|
-
|
|
1039
|
+
here,
|
|
1040
|
+
continueFromWeb,
|
|
1041
|
+
runningHere: activeRunId !== null && runner.runs(activeRunId),
|
|
936
1042
|
})
|
|
937
1043
|
}
|
|
938
1044
|
/>
|
|
@@ -945,14 +1051,14 @@ function ThreadView(
|
|
|
945
1051
|
<text fg={colors.amber} paddingBottom={1}>
|
|
946
1052
|
{"This conversation runs on its owner's computer: you can read it here."}
|
|
947
1053
|
</text>
|
|
948
|
-
) : onComputer && mine &&
|
|
1054
|
+
) : onComputer && mine && !here ? (
|
|
949
1055
|
<text paddingBottom={1}>
|
|
950
1056
|
<span fg={colors.amber}>
|
|
951
|
-
{
|
|
952
|
-
? "It
|
|
953
|
-
:
|
|
954
|
-
? `It
|
|
955
|
-
:
|
|
1057
|
+
{!place
|
|
1058
|
+
? "It has no folder yet."
|
|
1059
|
+
: otherComputer
|
|
1060
|
+
? `It runs on ${clip(place.name, 40)}.`
|
|
1061
|
+
: `It works in ${shortPath(place.folder, homedir(), 48)}.`}
|
|
956
1062
|
</span>
|
|
957
1063
|
<span fg={colors.muted}>{" Its turns run there: "}</span>
|
|
958
1064
|
<span fg={colors.text}>ctrl+f</span>
|
|
@@ -962,11 +1068,11 @@ function ThreadView(
|
|
|
962
1068
|
<SlashMenu colors={colors} menu={slash} above={8} />
|
|
963
1069
|
<Composer
|
|
964
1070
|
colors={colors}
|
|
965
|
-
focused={!props.dialogOpen && !pending && !elsewhere}
|
|
1071
|
+
focused={!props.dialogOpen && !contextOpen && !pending && !elsewhere}
|
|
966
1072
|
onChange={setTyped}
|
|
967
1073
|
accent={pending ? colors.amber : undefined}
|
|
968
1074
|
placeholder={pending ? "Decide on the request above first" : "Ask anything…"}
|
|
969
|
-
status={
|
|
1075
|
+
status={statusLine}
|
|
970
1076
|
onSubmit={send}
|
|
971
1077
|
/>
|
|
972
1078
|
<box flexDirection="row" justifyContent="space-between" paddingTop={1}>
|
|
@@ -979,22 +1085,43 @@ function ThreadView(
|
|
|
979
1085
|
</text>
|
|
980
1086
|
</box>
|
|
981
1087
|
</box>
|
|
1088
|
+
{contextOpen ? (
|
|
1089
|
+
<ContextPanel
|
|
1090
|
+
colors={colors}
|
|
1091
|
+
context={context}
|
|
1092
|
+
{...(context?.model
|
|
1093
|
+
? { modelName: modelNames.get(`${context.model.provider}:${context.model.modelId}`) }
|
|
1094
|
+
: {})}
|
|
1095
|
+
onClose={() => setContextOpen(false)}
|
|
1096
|
+
/>
|
|
1097
|
+
) : null}
|
|
982
1098
|
</box>
|
|
983
1099
|
)
|
|
984
1100
|
}
|
|
985
1101
|
|
|
986
|
-
function
|
|
1102
|
+
export function activityLabel(
|
|
987
1103
|
runs: readonly Run[],
|
|
988
1104
|
runId: string | null,
|
|
989
|
-
where: {
|
|
1105
|
+
where: {
|
|
1106
|
+
readonly onComputer: boolean
|
|
1107
|
+
readonly mine: boolean
|
|
1108
|
+
readonly here: boolean
|
|
1109
|
+
readonly continueFromWeb: boolean
|
|
1110
|
+
readonly runningHere: boolean
|
|
1111
|
+
}
|
|
990
1112
|
): string {
|
|
991
1113
|
const run = runs.find((entry) => entry.id === runId)
|
|
992
1114
|
if (run?.status === "queued") {
|
|
993
|
-
|
|
1115
|
+
if (!where.onComputer) return "Starting"
|
|
1116
|
+
if (!where.mine) return "Waiting for its owner's computer"
|
|
1117
|
+
if (!where.here) return "Waiting for sixb in its folder"
|
|
1118
|
+
return where.continueFromWeb || where.runningHere
|
|
1119
|
+
? "Starting"
|
|
1120
|
+
: "Waiting: messages from the web are off"
|
|
994
1121
|
}
|
|
995
1122
|
// Yours, running, and not here: another sixb runs it, or one that closed, whose turn ends
|
|
996
1123
|
// interrupted once its lease lapses.
|
|
997
|
-
if (where.onComputer && where.mine && !where.
|
|
1124
|
+
if (where.onComputer && where.mine && !where.runningHere) return "Working in another sixb"
|
|
998
1125
|
return "Working"
|
|
999
1126
|
}
|
|
1000
1127
|
|
|
@@ -1044,6 +1171,8 @@ function commandItems(input: {
|
|
|
1044
1171
|
readonly newConversation: () => void
|
|
1045
1172
|
readonly open: (dialog: Dialog) => void
|
|
1046
1173
|
readonly setPlace: (place: Settings["place"]) => void
|
|
1174
|
+
/** Whether your messages from the web, or another device, run in this folder. */
|
|
1175
|
+
readonly toggleContinueFromWeb: () => void
|
|
1047
1176
|
readonly cycleEffort: () => void
|
|
1048
1177
|
readonly quit: () => void
|
|
1049
1178
|
}): PaletteItem[] {
|
|
@@ -1097,6 +1226,13 @@ function commandItems(input: {
|
|
|
1097
1226
|
keys: "tab",
|
|
1098
1227
|
run: () => input.setPlace(settings.place === "computer" ? "cloud" : "computer"),
|
|
1099
1228
|
},
|
|
1229
|
+
{
|
|
1230
|
+
id: "continue-from-web",
|
|
1231
|
+
group: "Agent",
|
|
1232
|
+
label: "Messages from the web",
|
|
1233
|
+
detail: settings.continueFromWeb ? "run here" : "off",
|
|
1234
|
+
run: input.toggleContinueFromWeb,
|
|
1235
|
+
},
|
|
1100
1236
|
{ id: "quit", group: "Sixb", label: "Quit", keys: "ctrl+c", run: input.quit },
|
|
1101
1237
|
]
|
|
1102
1238
|
}
|