@sixb/cli 0.1.26 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/dist/commands/agent.d.ts.map +1 -1
  2. package/dist/commands/api.d.ts.map +1 -1
  3. package/dist/commands/check.d.ts.map +1 -1
  4. package/dist/commands/deploy.d.ts.map +1 -1
  5. package/dist/commands/dev-runner.d.ts.map +1 -1
  6. package/dist/commands/dev.d.ts.map +1 -1
  7. package/dist/commands/env.d.ts +31 -0
  8. package/dist/commands/env.d.ts.map +1 -0
  9. package/dist/lib/command-line.d.ts +26 -1
  10. package/dist/lib/command-line.d.ts.map +1 -1
  11. package/dist/lib/deploy-release.d.ts +2 -0
  12. package/dist/lib/deploy-release.d.ts.map +1 -1
  13. package/dist/lib/deploy-source.d.ts +2 -0
  14. package/dist/lib/deploy-source.d.ts.map +1 -1
  15. package/dist/lib/env-config.d.ts +17 -0
  16. package/dist/lib/env-config.d.ts.map +1 -0
  17. package/dist/lib/env-file.d.ts +16 -0
  18. package/dist/lib/env-file.d.ts.map +1 -0
  19. package/dist/lib/hidden-prompt.d.ts +19 -0
  20. package/dist/lib/hidden-prompt.d.ts.map +1 -0
  21. package/dist/tui/app.d.ts +8 -0
  22. package/dist/tui/app.d.ts.map +1 -1
  23. package/dist/tui/computer.d.ts +5 -0
  24. package/dist/tui/computer.d.ts.map +1 -1
  25. package/dist/tui/context.d.ts +13 -0
  26. package/dist/tui/context.d.ts.map +1 -0
  27. package/dist/tui/format.d.ts +85 -0
  28. package/dist/tui/format.d.ts.map +1 -1
  29. package/dist/tui/index.d.ts.map +1 -1
  30. package/dist/tui/markdown.d.ts +18 -0
  31. package/dist/tui/markdown.d.ts.map +1 -0
  32. package/dist/tui/parts.d.ts +8 -0
  33. package/dist/tui/parts.d.ts.map +1 -1
  34. package/dist/tui/runner.d.ts +37 -14
  35. package/dist/tui/runner.d.ts.map +1 -1
  36. package/dist/tui/settings.d.ts +13 -1
  37. package/dist/tui/settings.d.ts.map +1 -1
  38. package/dist/tui/transcript.d.ts +1 -1
  39. package/dist/tui/transcript.d.ts.map +1 -1
  40. package/dist/tui/ui.d.ts +7 -0
  41. package/dist/tui/ui.d.ts.map +1 -1
  42. package/dist/ui/deploy-screens.d.ts +3 -1
  43. package/dist/ui/deploy-screens.d.ts.map +1 -1
  44. package/dist/ui/env-screens.d.ts +37 -0
  45. package/dist/ui/env-screens.d.ts.map +1 -0
  46. package/package.json +19 -19
  47. package/src/commands/agent.ts +17 -10
  48. package/src/commands/api.ts +2 -1
  49. package/src/commands/check.ts +5 -1
  50. package/src/commands/deploy.ts +29 -3
  51. package/src/commands/dev-runner.ts +3 -1
  52. package/src/commands/dev.ts +3 -0
  53. package/src/commands/env.ts +422 -0
  54. package/src/index.tsx +39 -1
  55. package/src/lib/command-line.ts +59 -1
  56. package/src/lib/deploy-release.ts +3 -0
  57. package/src/lib/deploy-source.ts +10 -0
  58. package/src/lib/env-config.ts +96 -0
  59. package/src/lib/env-file.ts +104 -0
  60. package/src/lib/hidden-prompt.ts +97 -0
  61. package/src/tui/app.tsx +315 -179
  62. package/src/tui/computer.ts +37 -0
  63. package/src/tui/context.tsx +149 -0
  64. package/src/tui/format.ts +218 -1
  65. package/src/tui/index.tsx +13 -2
  66. package/src/tui/markdown.ts +91 -0
  67. package/src/tui/parts.ts +23 -3
  68. package/src/tui/runner.ts +113 -30
  69. package/src/tui/settings.ts +54 -5
  70. package/src/tui/transcript.tsx +90 -8
  71. package/src/tui/ui.tsx +40 -11
  72. package/src/ui/deploy-screens.ts +12 -1
  73. package/src/ui/env-screens.ts +81 -0
  74. package/dist/tui/folders.d.ts +0 -7
  75. package/dist/tui/folders.d.ts.map +0 -1
  76. 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 { conversationsIn, folderOf, rememberFolder } from "./folders"
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, runsOnThisComputer } from "./runner"
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: a message sent from the web app,
128
- // or a turn going on after approvals decided there, and those that queued while sixb was closed.
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
- void conversationsIn(runner.folder).then((threadIds) => {
132
- for (const threadId of threadIds) void runner.claimIfHere(threadId)
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") void runner.claimIfHere(event.threadId, event.runId)
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
- <box flexDirection="column" flexGrow={1} backgroundColor={colors.background}>
296
- {screen.kind === "home" ? (
297
- <Home
298
- {...common}
299
- onPlace={() =>
300
- setSettings((current) => {
301
- const place = current.place === "computer" ? "cloud" : "computer"
302
- say(
303
- place === "cloud"
304
- ? "New conversations run in the cloud"
305
- : `New conversations run on ${placeLabel(place)}`
306
- )
307
- return { ...current, place }
308
- })
309
- }
310
- onOpen={(threadId) => setScreen({ kind: "thread", threadId })}
311
- />
312
- ) : (
313
- <ThreadView
314
- key={screen.threadId}
315
- {...common}
316
- threadId={screen.threadId}
317
- approval={approval}
318
- onThreadRead={readApproval}
319
- />
320
- )}
321
- {notice || quitArmed ? (
322
- <box
323
- position="absolute"
324
- right={2}
325
- top={1}
326
- backgroundColor={colors.surface}
327
- paddingLeft={2}
328
- paddingRight={2}
329
- zIndex={5}
330
- >
331
- <text fg={quitArmed ? colors.text : notice?.tone === "error" ? colors.red : colors.text}>
332
- {quitArmed ? "Press ctrl+c again to quit" : notice?.text}
333
- </text>
334
- </box>
335
- ) : null}
336
- {dialog === "commands" ? (
337
- <Palette
338
- colors={colors}
339
- title="Commands"
340
- placeholder="Search"
341
- onClose={() => setDialog(null)}
342
- items={commandItems({
343
- settings,
344
- approvalMode,
345
- models,
346
- newConversation: () => setScreen({ kind: "home" }),
347
- open: setDialog,
348
- setPlace: (place) => setSettings((current) => ({ ...current, place })),
349
- cycleEffort,
350
- quit: props.onExit,
351
- })}
352
- />
353
- ) : null}
354
- {dialog === "threads" ? (
355
- <ThreadsDialog
356
- connection={connection}
357
- colors={colors}
358
- onClose={() => setDialog(null)}
359
- onOpen={(threadId) => setScreen({ kind: "thread", threadId })}
360
- />
361
- ) : null}
362
- {dialog === "models" ? (
363
- <Palette
364
- colors={colors}
365
- title="Model"
366
- placeholder="Search models"
367
- onClose={() => setDialog(null)}
368
- items={modelItems(models, settings, (model, reasoning) =>
369
- setSettings((current) => {
370
- const { model: _model, reasoning: _reasoning, ...rest } = current
371
- return {
372
- ...rest,
373
- ...(model ? { model: { provider: model.provider, modelId: model.modelId } } : {}),
374
- ...(reasoning ? { reasoning } : {}),
375
- }
376
- })
377
- )}
378
- />
379
- ) : null}
380
- {dialog === "permissions" ? (
381
- <Palette
382
- colors={colors}
383
- title="What can the agent do without asking?"
384
- placeholder="Search"
385
- onClose={() => setDialog(null)}
386
- items={APPROVAL_MODES.map((entry) => ({
387
- id: entry.mode,
388
- label: entry.label,
389
- detail: entry.description,
390
- current: entry.mode === approvalMode,
391
- run: () => chooseApproval(entry.mode),
392
- }))}
393
- />
394
- ) : null}
395
- </box>
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" ? { runsOn: "computer" as const } : {}),
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
- {remote ? (
588
- <text wrapMode="none">
589
- <span fg={colors.text}>{connection.project.id}</span>
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
- {remote ? (
612
- <span fg={colors.muted}>
613
- {settings.place === "computer"
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}>{version.replace(/^sixb v/, "")}</text>
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 slash = useSlashMenu(props.slashCommands, typed)
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
- // The folder its turns work in on this computer; null until read.
702
- const [workFolder, setWorkFolder] = useState<string | undefined | null>(null)
703
- useEffect(() => {
704
- void folderOf(threadId).then(setWorkFolder)
705
- }, [threadId])
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 = onComputer && mine && here
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: { computerId: props.computerId },
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
- if (event.type === "agent.message.finalized" || event.type === "agent.run.finished")
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 && workFolder !== null) {
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
- ? "Condensing earlier turns"
932
- : queuedLabel(runs, activeRunId, {
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
- runsHere: activeRunId !== null && runner.runs(activeRunId),
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 && workFolder !== null && !here ? (
1054
+ ) : onComputer && mine && !here ? (
949
1055
  <text paddingBottom={1}>
950
1056
  <span fg={colors.amber}>
951
- {otherComputer
952
- ? "It works on another computer."
953
- : workFolder
954
- ? `It works in ${shortPath(workFolder, homedir(), 48)}.`
955
- : "It started on another computer."}
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={props.status(onComputer ? placeLabel("computer") : placeLabel("cloud"))}
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 queuedLabel(
1102
+ export function activityLabel(
987
1103
  runs: readonly Run[],
988
1104
  runId: string | null,
989
- where: { readonly onComputer: boolean; readonly mine: boolean; readonly runsHere: boolean }
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
- return where.onComputer && !where.mine ? "Waiting for its owner's computer" : "Starting"
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.runsHere) return "Working in another sixb"
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
  }