@sixb/cli 0.2.4 → 0.2.6

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 (63) hide show
  1. package/README.md +2 -0
  2. package/dist/commands/agent.d.ts.map +1 -1
  3. package/dist/commands/api.d.ts.map +1 -1
  4. package/dist/commands/app.d.ts.map +1 -1
  5. package/dist/commands/db-migrate.d.ts +2 -0
  6. package/dist/commands/db-migrate.d.ts.map +1 -1
  7. package/dist/commands/dev-runner.d.ts.map +1 -1
  8. package/dist/commands/run.d.ts +15 -0
  9. package/dist/commands/run.d.ts.map +1 -0
  10. package/dist/commands/worker-group.d.ts.map +1 -1
  11. package/dist/commands/worker.d.ts.map +1 -1
  12. package/dist/lib/command-line.d.ts +12 -2
  13. package/dist/lib/command-line.d.ts.map +1 -1
  14. package/dist/lib/deploy-source.d.ts +2 -0
  15. package/dist/lib/deploy-source.d.ts.map +1 -1
  16. package/dist/lib/role-lifecycle.d.ts +8 -1
  17. package/dist/lib/role-lifecycle.d.ts.map +1 -1
  18. package/dist/lib/runtime.d.ts +4 -2
  19. package/dist/lib/runtime.d.ts.map +1 -1
  20. package/dist/lib/storage-migration.d.ts +7 -0
  21. package/dist/lib/storage-migration.d.ts.map +1 -1
  22. package/dist/lib/worker-concurrency.d.ts.map +1 -1
  23. package/dist/lib/worker-registry.d.ts +4 -1
  24. package/dist/lib/worker-registry.d.ts.map +1 -1
  25. package/dist/runner/computer-connection.d.ts.map +1 -1
  26. package/dist/tui/app.d.ts +2 -0
  27. package/dist/tui/app.d.ts.map +1 -1
  28. package/dist/tui/format.d.ts +7 -2
  29. package/dist/tui/format.d.ts.map +1 -1
  30. package/dist/tui/moves.d.ts +62 -0
  31. package/dist/tui/moves.d.ts.map +1 -0
  32. package/dist/tui/parts.d.ts.map +1 -1
  33. package/dist/tui/settings.d.ts +2 -0
  34. package/dist/tui/settings.d.ts.map +1 -1
  35. package/dist/tui/transcript.d.ts +13 -6
  36. package/dist/tui/transcript.d.ts.map +1 -1
  37. package/dist/ui/screens.d.ts +8 -0
  38. package/dist/ui/screens.d.ts.map +1 -1
  39. package/package.json +22 -21
  40. package/src/commands/agent.ts +17 -5
  41. package/src/commands/api.ts +20 -10
  42. package/src/commands/app.ts +15 -7
  43. package/src/commands/db-migrate.ts +25 -1
  44. package/src/commands/dev-runner.ts +2 -1
  45. package/src/commands/run.ts +221 -0
  46. package/src/commands/worker-group.ts +36 -9
  47. package/src/commands/worker.ts +27 -9
  48. package/src/index.tsx +15 -1
  49. package/src/lib/command-line.ts +41 -5
  50. package/src/lib/deploy-source.ts +5 -0
  51. package/src/lib/role-lifecycle.ts +48 -8
  52. package/src/lib/runtime.ts +19 -3
  53. package/src/lib/storage-migration.ts +33 -1
  54. package/src/lib/worker-concurrency.ts +1 -0
  55. package/src/lib/worker-registry.ts +35 -5
  56. package/src/runner/computer-connection.ts +7 -1
  57. package/src/tui/app.tsx +191 -43
  58. package/src/tui/format.ts +132 -7
  59. package/src/tui/moves.ts +221 -0
  60. package/src/tui/parts.ts +7 -0
  61. package/src/tui/settings.ts +5 -0
  62. package/src/tui/transcript.tsx +54 -15
  63. package/src/ui/screens.ts +23 -0
@@ -0,0 +1,221 @@
1
+ import type { GetAgentThreadResponses, ListAgentThreadRunsResponses } from "@sixb/client"
2
+ import { computerName, computerNameInText } from "./settings"
3
+
4
+ // Where each turn ran, and the moves between them, by the rule the app's transcript follows
5
+ // (`packages/app/src/agent/moves.ts`) and the core tells the model by (`detectMovedMessages`). The
6
+ // app's helper is not on a surface the CLI imports: it belongs to the web chat, with its catalog
7
+ // of strings and its components. This keeps the same rule on every case (retries, a round trip
8
+ // with no turn, forks, a participant, a folder not shown) and the app's English words.
9
+ //
10
+ // Two differences, on purpose. This computer is named as the terminal names it everywhere ("This
11
+ // Mac"), not by its own name. And the terminal knows the names of this computer and of the one
12
+ // the conversation runs on now, not the list of every connected computer the app reads, so a move
13
+ // to another of the person's computers may read without that computer's name.
14
+
15
+ type Run = ListAgentThreadRunsResponses[200]["runs"][number]
16
+ type Thread = GetAgentThreadResponses[200]
17
+
18
+ /**
19
+ * Where a turn runs: the cloud, or a folder on one of its owner's computers. A computer's turn
20
+ * whose folder the reader isn't shown (someone else's conversation, or one from before folders
21
+ * were kept) is "computer".
22
+ */
23
+ export type TurnPlace = "cloud" | "computer" | { readonly id: string; readonly folder: string }
24
+
25
+ /** What places are named with, beyond what the runs hold. */
26
+ export interface PlaceNames {
27
+ /** Each computer's name, by id, where the reader knows it: runs keep only the id. */
28
+ readonly computerNames: ReadonlyMap<string, string>
29
+ /** This computer, named as a label ("This Mac") and lowercased in a sentence ("this Mac"). */
30
+ readonly thisComputerId: string
31
+ /** Whose computer it is, for someone they shared it with, who isn't shown its folders. */
32
+ readonly ownerName: string | null
33
+ }
34
+
35
+ /** The names the terminal knows: this computer's, the conversation's computer's, its owner's. */
36
+ export function placeNames(input: {
37
+ readonly thread: Pick<Thread, "computer" | "owner" | "ownerPrincipal"> | null
38
+ readonly computerId: string
39
+ readonly mine: boolean
40
+ }): PlaceNames {
41
+ const { thread, computerId, mine } = input
42
+
43
+ const computerNames = new Map<string, string>()
44
+ if (thread?.computer) computerNames.set(thread.computer.id, thread.computer.name)
45
+ computerNames.set(computerId, computerName())
46
+
47
+ const ownerName = thread && !mine ? (thread.owner.displayName ?? thread.ownerPrincipal.id) : null
48
+ return { computerNames, thisComputerId: computerId, ownerName }
49
+ }
50
+
51
+ export function runPlace(run: Run): TurnPlace {
52
+ if (run.runsOn !== "computer") return "cloud"
53
+ return run.computer ?? "computer"
54
+ }
55
+
56
+ function threadPlace(thread: Pick<Thread, "runsOn" | "computer">): TurnPlace {
57
+ if (thread.runsOn !== "computer") return "cloud"
58
+ return thread.computer ? { id: thread.computer.id, folder: thread.computer.folder } : "computer"
59
+ }
60
+
61
+ function samePlace(a: TurnPlace, b: TurnPlace): boolean {
62
+ if (typeof a === "string" || typeof b === "string") return a === b
63
+ return a.id === b.id && a.folder === b.folder
64
+ }
65
+
66
+ /** A folder by its name, as a place reads in running text. */
67
+ export function folderName(folder: string): string {
68
+ return folder.split("/").filter(Boolean).at(-1) ?? folder
69
+ }
70
+
71
+ /** A folder's path, a home folder written `~`: for two folders whose names are alike. */
72
+ function shownFolder(folder: string): string {
73
+ return folder.replace(/^\/(?:Users|home)\/[^/]+(?=\/|$)/, "~")
74
+ }
75
+
76
+ /** A folder by its name, on its computer when that's known. */
77
+ function folderPlace(names: PlaceNames, place: { readonly id: string; readonly folder: string }) {
78
+ const computer =
79
+ place.id === names.thisComputerId ? computerNameInText() : names.computerNames.get(place.id)
80
+ const folder = folderName(place.folder)
81
+ return computer ? `${folder} on ${computer}` : folder
82
+ }
83
+
84
+ /** A place under a turn's answer: `Cloud`, or its computer and folder. */
85
+ export function placeName(place: TurnPlace, names: PlaceNames): string {
86
+ if (place === "cloud") return "Cloud"
87
+ if (place === "computer") return names.ownerName ? `${names.ownerName}'s computer` : "Computer"
88
+
89
+ const computer = names.computerNames.get(place.id) ?? "Another computer"
90
+ return `${computer} · ${folderName(place.folder)}`
91
+ }
92
+
93
+ /** Where it went, and which files stay behind: `from` is unknown before any turn. */
94
+ export function movedLine(names: PlaceNames, from: TurnPlace | undefined, to: TurnPlace): string {
95
+ if (to === "cloud") {
96
+ return typeof from === "object"
97
+ ? `Moved to the cloud. The files in ${folderName(from.folder)} stay behind.`
98
+ : "Moved to the cloud. The computer's files stay behind."
99
+ }
100
+
101
+ if (to === "computer") {
102
+ if (from !== "cloud") return "Moved to another folder. Earlier files stay where they were."
103
+
104
+ const computer = names.ownerName ? `${names.ownerName}'s computer` : "the computer"
105
+ return `Moved to ${computer}. The cloud's files stay behind.`
106
+ }
107
+
108
+ if (from === "cloud") return `Moved to ${folderPlace(names, to)}. The cloud's files stay behind.`
109
+
110
+ // Another folder on the same computer: by their names, or their paths where the names are alike.
111
+ if (typeof from === "object" && from.id === to.id) {
112
+ const alike = folderName(from.folder) === folderName(to.folder)
113
+ const shown = alike ? shownFolder : folderName
114
+ const left = shown(from.folder)
115
+ return `Moved from ${left} to ${shown(to.folder)}. The files in ${left} stay behind.`
116
+ }
117
+ return `Moved to ${folderPlace(names, to)}. Earlier files stay where they were.`
118
+ }
119
+
120
+ /** Where a fork's first turn runs: a workspace of its own, apart from its source's. */
121
+ function continuedLine(names: PlaceNames, to: TurnPlace): string {
122
+ const files = "The original conversation's files stay with it."
123
+ if (to === "cloud") return `Continued in the cloud. ${files}`
124
+ if (to === "computer") {
125
+ const computer = names.ownerName ? `${names.ownerName}'s computer` : "the computer"
126
+ return `Continued on ${computer}. ${files}`
127
+ }
128
+ return `Continued in ${folderPlace(names, to)}. ${files}`
129
+ }
130
+
131
+ /**
132
+ * Every move of the conversation, by the shown message it follows: where a turn runs elsewhere
133
+ * than the turn before it, and where it runs now when no turn ran since it moved. Moving back
134
+ * before a turn ran is no move: the workspace is the one the last turn worked in. A fork's first
135
+ * turn starts in a workspace of its own.
136
+ */
137
+ export function transcriptMoves(input: {
138
+ readonly thread: Pick<Thread, "runsOn" | "computer" | "movedAt" | "createdAt"> | null
139
+ /** Oldest first, a resumed turn's trigger included. */
140
+ readonly messages: readonly {
141
+ readonly id: string
142
+ readonly role: "user" | "assistant"
143
+ readonly createdAt: string
144
+ }[]
145
+ /** The messages the transcript draws: a move line follows one of them. */
146
+ readonly shownIds: ReadonlySet<string>
147
+ /** Oldest first. */
148
+ readonly runs: readonly Run[]
149
+ readonly names: PlaceNames
150
+ }): ReadonlyMap<string, string> {
151
+ const { thread, messages, shownIds, runs, names } = input
152
+
153
+ // A retried turn runs again for the same message: its latest run is where it went.
154
+ const placeByTrigger = new Map<string, TurnPlace>()
155
+ for (const run of runs) {
156
+ if (run.kind === "conversation") placeByTrigger.set(run.triggerMessageId, runPlace(run))
157
+ }
158
+
159
+ const moves = new Map<string, string>()
160
+ let previous: TurnPlace | undefined
161
+ let lastShownId: string | null = null
162
+ // A fork's copies keep the time they were written, before the fork was: they ran in its source,
163
+ // so its first turn here starts elsewhere. A message written here with no run, such as one
164
+ // steering a turn, decides nothing.
165
+ let forked = false
166
+
167
+ for (const message of messages) {
168
+ const place = message.role === "user" ? placeByTrigger.get(message.id) : undefined
169
+ const copied = thread !== null && message.createdAt < thread.createdAt
170
+ if (message.role === "user" && copied && previous === undefined) forked = true
171
+
172
+ if (place !== undefined) {
173
+ const line =
174
+ previous === undefined
175
+ ? forked && continuedLine(names, place)
176
+ : !samePlace(previous, place) && movedLine(names, previous, place)
177
+ if (line && lastShownId !== null) moves.set(lastShownId, line)
178
+ previous = place
179
+ }
180
+
181
+ if (shownIds.has(message.id)) lastShownId = message.id
182
+ }
183
+
184
+ if (!thread) return moves
185
+ const current = threadPlace(thread)
186
+
187
+ // A fork no turn ran in yet continues after its last copy. Not by `movedAt`: a fork keeps its
188
+ // source's, which may predate some of the copies, or all of them. A conversation no turn ran in
189
+ // yet, and no fork, starts where it is.
190
+ if (previous === undefined) {
191
+ if (forked && lastShownId !== null) moves.set(lastShownId, continuedLine(names, current))
192
+ return moves
193
+ }
194
+
195
+ // Where it runs now, if no turn ran there since it moved: after the last message from before
196
+ // the move.
197
+ const movedAt = thread.movedAt
198
+ if (movedAt === undefined || samePlace(previous, current)) return moves
199
+
200
+ const afterId = messages
201
+ .filter((message) => message.createdAt <= movedAt && shownIds.has(message.id))
202
+ .at(-1)?.id
203
+ if (afterId) moves.set(afterId, movedLine(names, previous, current))
204
+ return moves
205
+ }
206
+
207
+ /**
208
+ * What a move says once done, by the transcript's rule: from where its last turn ran, the latest
209
+ * run of the latest message. Back there with no turn in between, nothing moved. `to` is the cloud,
210
+ * or the folder this `sixb` is open in.
211
+ */
212
+ export function movedNotice(names: PlaceNames, runs: readonly Run[], to: TurnPlace): string {
213
+ const destination = to === "cloud" ? "the cloud" : "this folder"
214
+ const lastRun = [...runs].reverse().find((run) => run.kind === "conversation")
215
+
216
+ if (!lastRun) return `Moved to ${destination}.`
217
+ if (samePlace(runPlace(lastRun), to)) {
218
+ return `Back in ${destination}. Nothing moved since its last reply.`
219
+ }
220
+ return movedLine(names, runPlace(lastRun), to)
221
+ }
package/src/tui/parts.ts CHANGED
@@ -169,6 +169,13 @@ export function reduceLive(state: LiveRun, event: AgentRunStreamEvent): LiveRun
169
169
  return { ...state, compacting: false, contextFull: false }
170
170
  case "agent.ui.chunk":
171
171
  return reduceChunk(state, event.chunk)
172
+ case "agent.ui.steps": {
173
+ // The turn's finished steps, sent first to a reader who opened it late, replace what it
174
+ // rebuilt so far. What streams next opens a step of its own, even when its start was dropped.
175
+ let next: LiveRun = { ...state, working: true, parts: [], keys: [], step: 0, stepStart: 0 }
176
+ for (const chunk of event.chunks) next = reduceChunk(next, chunk)
177
+ return { ...next, step: next.step + 1, stepStart: next.parts.length }
178
+ }
172
179
  case "agent.message.finalized":
173
180
  return { ...state, finalized: true }
174
181
  case "agent.run.finished":
@@ -68,6 +68,11 @@ export function computerName(): string {
68
68
  return osType() === "Darwin" ? "This Mac" : "This computer"
69
69
  }
70
70
 
71
+ /** The same name inside a sentence, as in "Moved to sixb on this Mac." */
72
+ export function computerNameInText(): string {
73
+ return osType() === "Darwin" ? "this Mac" : "this computer"
74
+ }
75
+
71
76
  export function placeLabel(place: Place): string {
72
77
  return place === "computer" ? computerName() : "Cloud"
73
78
  }
@@ -1,10 +1,15 @@
1
1
  /** @jsxImportSource @opentui/react */
2
2
  import { CodeRenderable, type MarkdownOptions, type SyntaxStyle } from "@opentui/core"
3
3
  import { useRenderer } from "@opentui/react"
4
- import type { ListAgentThreadApprovalsResponses, ListAgentThreadRunsResponses } from "@sixb/client"
5
- import { useEffect, useState } from "react"
4
+ import type {
5
+ GetAgentThreadResponses,
6
+ ListAgentThreadApprovalsResponses,
7
+ ListAgentThreadRunsResponses,
8
+ } from "@sixb/client"
9
+ import { Fragment, type ReactNode, useEffect, useState } from "react"
6
10
  import { duration, friendlyPath, plural, runFailureText, type ToolLine, toolLine } from "./format"
7
11
  import { steadyMarkdown } from "./markdown"
12
+ import { type PlaceNames, placeName, runPlace, transcriptMoves } from "./moves"
8
13
  import {
9
14
  type ApprovalOutcome,
10
15
  approvalOutcomes,
@@ -12,7 +17,6 @@ import {
12
17
  type Part,
13
18
  type ShownMessage,
14
19
  } from "./parts"
15
- import { placeLabel } from "./settings"
16
20
  import type { TuiColors } from "./theme"
17
21
  import { BOLD, ITALIC, useNow, useSpinner } from "./ui"
18
22
 
@@ -32,7 +36,8 @@ export function Transcript({
32
36
  live,
33
37
  approvals,
34
38
  modelNames,
35
- computerRuns,
39
+ thread,
40
+ names,
36
41
  width,
37
42
  folder,
38
43
  approvalChoice,
@@ -44,8 +49,16 @@ export function Transcript({
44
49
  readonly live: LiveRun | null
45
50
  readonly approvals: readonly Approval[]
46
51
  readonly modelNames: ModelNames
47
- /** Whether the thread's turns run on its owner's computer. */
48
- readonly computerRuns: boolean
52
+ /**
53
+ * Where the conversation runs now, when it last moved, and when it began: a fork's copies
54
+ * predate it.
55
+ */
56
+ readonly thread: Pick<
57
+ GetAgentThreadResponses[200],
58
+ "runsOn" | "computer" | "movedAt" | "createdAt"
59
+ > | null
60
+ /** The computers' and owner's names its places are written with. */
61
+ readonly names: PlaceNames
49
62
  /** The terminal's width: rows that must stay one line are cut to it. */
50
63
  readonly width: number
51
64
  /** The folder a computer's turns work in: paths in it are shown relative to it. */
@@ -61,17 +74,39 @@ export function Transcript({
61
74
  const liveShown =
62
75
  live &&
63
76
  !messages.some((message) => message.runId === live.runId && message.role === "assistant")
77
+
78
+ // Each turn says where it ran, and a line marks every move between two of them.
79
+ const moves = transcriptMoves({
80
+ thread,
81
+ messages,
82
+ shownIds: new Set(shown.map((message) => message.id)),
83
+ runs,
84
+ names,
85
+ })
86
+ const withMove = (message: ShownMessage, body: ReactNode) => {
87
+ const moved = moves.get(message.id)
88
+ return (
89
+ <Fragment key={message.id}>
90
+ {body}
91
+ {moved ? <text fg={colors.faint}>{`◇ ${moved}`}</text> : null}
92
+ </Fragment>
93
+ )
94
+ }
95
+
64
96
  return (
65
97
  <box flexDirection="column" gap={1}>
66
98
  {shown.map((message, index) => {
67
- if (message.role === "user")
68
- return <UserMessage key={message.id} colors={colors} message={message} />
99
+ if (message.role === "user") {
100
+ return withMove(message, <UserMessage colors={colors} message={message} />)
101
+ }
102
+
69
103
  const next = shown[index + 1]
70
104
  // A turn's meta goes under its last message: a resumed turn answers in several.
71
105
  const lastOfRun = !next || next.runId !== message.runId
72
106
  const run = message.runId ? runsById.get(message.runId) : undefined
73
- return (
74
- <box key={message.id} flexDirection="column" gap={1}>
107
+ return withMove(
108
+ message,
109
+ <box flexDirection="column" gap={1}>
75
110
  {message.compaction ? (
76
111
  <CompactionLine colors={colors} contextFull={message.compaction.contextFull} />
77
112
  ) : null}
@@ -89,7 +124,7 @@ export function Transcript({
89
124
  colors={colors}
90
125
  run={run}
91
126
  modelNames={modelNames}
92
- computerRuns={computerRuns}
127
+ place={placeName(runPlace(run), names)}
93
128
  waiting={approvals.some((approval) => approval.runId === run.id)}
94
129
  />
95
130
  ) : null}
@@ -221,7 +256,7 @@ function AgentParts({
221
256
  <ToolRow
222
257
  key={key}
223
258
  colors={colors}
224
- line={shownLine(toolLine(part, outcomes), folder)}
259
+ line={shownLine(toolLine(part, outcomes, folder), folder)}
225
260
  state={part.state}
226
261
  width={width}
227
262
  />
@@ -467,13 +502,14 @@ function RunMeta({
467
502
  colors,
468
503
  run,
469
504
  modelNames,
470
- computerRuns,
505
+ place,
471
506
  waiting,
472
507
  }: {
473
508
  readonly colors: TuiColors
474
509
  readonly run: Run
475
510
  readonly modelNames: ModelNames
476
- readonly computerRuns: boolean
511
+ /** Where it ran: `Cloud`, or a folder and its computer. */
512
+ readonly place: string
477
513
  /** One of its calls still waits for the person. */
478
514
  readonly waiting: boolean
479
515
  }) {
@@ -500,7 +536,7 @@ function RunMeta({
500
536
  return (
501
537
  <text>
502
538
  <span fg={colors.blue}>{" ▰ "}</span>
503
- <span fg={colors.text}>{placeLabel(computerRuns ? "computer" : "cloud")}</span>
539
+ <span fg={colors.text}>{place}</span>
504
540
  {items.map((item) => (
505
541
  <span key={item} fg={colors.muted}>{` · ${item}`}</span>
506
542
  ))}
@@ -613,6 +649,9 @@ function shownLine(line: ToolLine, folder?: string): ToolLine {
613
649
  ...line,
614
650
  detail: friendlyPath(line.detail, folder),
615
651
  ...(line.command === undefined ? {} : { command: friendlyPath(line.command, folder) }),
652
+ ...(line.paths && line.preview
653
+ ? { preview: line.preview.map((row) => friendlyPath(row, folder)) }
654
+ : {}),
616
655
  }
617
656
  }
618
657
 
package/src/ui/screens.ts CHANGED
@@ -421,6 +421,29 @@ export function dbMigrateView({
421
421
  )
422
422
  }
423
423
 
424
+ export function dbMigrateCheckView({
425
+ projectId,
426
+ pending,
427
+ }: {
428
+ projectId: string
429
+ /** The storage adapters with migrations to apply. */
430
+ pending: readonly { readonly adapterId: string; readonly reason?: string }[]
431
+ }): string {
432
+ if (pending.length === 0) {
433
+ return screen(headline("ok", "No database migrations pending", projectId))
434
+ }
435
+
436
+ return screen(
437
+ stack(
438
+ headline("warn", "Database migrations pending", projectId),
439
+ ...pending.map(
440
+ (status) =>
441
+ ` ${tone.faint(glyph.rule)} ${tone.muted(`${status.adapterId}: ${status.reason ?? ""}`)}`
442
+ )
443
+ )
444
+ )
445
+ }
446
+
424
447
  export function lakeCheckView({
425
448
  projectId,
426
449
  warnings = [],