@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/runner.ts
CHANGED
|
@@ -1,15 +1,24 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto"
|
|
1
2
|
import { homedir, tmpdir } from "node:os"
|
|
2
3
|
import { dirname, join } from "node:path"
|
|
3
4
|
import { ComputerRunner } from "@sixb/agent"
|
|
4
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
type GetAgentThreadResponses,
|
|
7
|
+
getAgentRun,
|
|
8
|
+
getAgentThread,
|
|
9
|
+
holdAgentComputerSession,
|
|
10
|
+
releaseAgentComputerSession,
|
|
11
|
+
} from "@sixb/client"
|
|
12
|
+
import type { ConversationAgentRunRecord } from "@sixb/core/storage"
|
|
5
13
|
import { LocalSandboxFactory } from "@sixb/sandboxes-local"
|
|
6
14
|
import { resolveConfigPath } from "../lib/profiles"
|
|
7
|
-
import { thisComputerId } from "./computer"
|
|
15
|
+
import { thisComputer, thisComputerId } from "./computer"
|
|
8
16
|
import type { Connection } from "./connection"
|
|
9
|
-
import { folderOf } from "./folders"
|
|
10
17
|
|
|
11
18
|
/** How long a closed terminal waits for a turn running here to record its end. */
|
|
12
19
|
const HANG_UP_WAIT_MS = 10_000
|
|
20
|
+
/** How often an open `sixb` renews its session, which lapses a minute after its last renewal. */
|
|
21
|
+
const SESSION_RENEW_MS = 20_000
|
|
13
22
|
|
|
14
23
|
/**
|
|
15
24
|
* What the agent's commands never read on this computer, whatever the folder: the CLI's own
|
|
@@ -21,7 +30,9 @@ export function deniedPaths(): readonly string[] {
|
|
|
21
30
|
|
|
22
31
|
/**
|
|
23
32
|
* This computer as a runner: it claims its owner's turns from the project and runs them in the
|
|
24
|
-
* folder `sixb` was opened in, one at a time per turn, each until it ends or is stopped.
|
|
33
|
+
* folder `sixb` was opened in, one at a time per turn, each until it ends or is stopped. While its
|
|
34
|
+
* session is open, the project knows `sixb` is open here, and the turns sent from elsewhere to the
|
|
35
|
+
* conversations of this folder run here too.
|
|
25
36
|
*/
|
|
26
37
|
export class LocalRunner {
|
|
27
38
|
private readonly runner: ComputerRunner
|
|
@@ -29,16 +40,22 @@ export class LocalRunner {
|
|
|
29
40
|
string,
|
|
30
41
|
{ readonly stop: AbortController; readonly done: Promise<boolean> }
|
|
31
42
|
>()
|
|
43
|
+
private readonly elsewhereListeners = new Set<(run: ConversationAgentRunRecord) => void>()
|
|
44
|
+
private session: { readonly id: string; readonly timer: ReturnType<typeof setInterval> } | null =
|
|
45
|
+
null
|
|
46
|
+
/** The session's last call: its release follows a renewal, which would open it again. */
|
|
47
|
+
private lastCall: Promise<void> = Promise.resolve()
|
|
32
48
|
|
|
33
49
|
constructor(
|
|
34
50
|
private readonly connection: Connection,
|
|
51
|
+
/** The folder `sixb` was opened in: its real path, as the project keeps it. */
|
|
35
52
|
readonly folder: string,
|
|
36
53
|
private readonly onFailure: (error: unknown) => void
|
|
37
54
|
) {
|
|
38
55
|
this.runner = new ComputerRunner({
|
|
39
56
|
apiUrl: connection.apiUrl,
|
|
40
57
|
authorization: () => connection.authorization(),
|
|
41
|
-
|
|
58
|
+
computer: thisComputer,
|
|
42
59
|
folder,
|
|
43
60
|
runFilesRoot: join(tmpdir(), "sixb-agent"),
|
|
44
61
|
onFailure,
|
|
@@ -56,6 +73,12 @@ export class LocalRunner {
|
|
|
56
73
|
})
|
|
57
74
|
}
|
|
58
75
|
|
|
76
|
+
/** Hear each turn sent from elsewhere as it starts to run here. Returns the unsubscribe. */
|
|
77
|
+
onElsewhere(listener: (run: ConversationAgentRunRecord) => void): () => void {
|
|
78
|
+
this.elsewhereListeners.add(listener)
|
|
79
|
+
return () => this.elsewhereListeners.delete(listener)
|
|
80
|
+
}
|
|
81
|
+
|
|
59
82
|
/** Whether this computer runs `runId` now. */
|
|
60
83
|
runs(runId: string): boolean {
|
|
61
84
|
return this.running.has(runId)
|
|
@@ -65,12 +88,12 @@ export class LocalRunner {
|
|
|
65
88
|
* Claim a queued turn and run it, unless this computer runs it already. Resolves once the turn
|
|
66
89
|
* ended here: false when it was not this computer's to run, or could not be claimed.
|
|
67
90
|
*/
|
|
68
|
-
claim(runId: string): Promise<boolean> {
|
|
91
|
+
claim(runId: string, onClaimed?: (run: ConversationAgentRunRecord) => void): Promise<boolean> {
|
|
69
92
|
const running = this.running.get(runId)
|
|
70
93
|
if (running) return running.done
|
|
71
94
|
const stop = new AbortController()
|
|
72
95
|
const done = this.runner
|
|
73
|
-
.runTurn(runId, stop.signal)
|
|
96
|
+
.runTurn(runId, stop.signal, onClaimed)
|
|
74
97
|
.catch((error: unknown) => {
|
|
75
98
|
this.onFailure(error)
|
|
76
99
|
return false
|
|
@@ -81,21 +104,81 @@ export class LocalRunner {
|
|
|
81
104
|
}
|
|
82
105
|
|
|
83
106
|
/**
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
|
|
107
|
+
* Hold this `sixb`'s session while it is open: the conversations of this folder read as online,
|
|
108
|
+
* and the turns waiting for them are claimed. Idempotent.
|
|
109
|
+
*/
|
|
110
|
+
openSession(): void {
|
|
111
|
+
if (this.session) return
|
|
112
|
+
const id = `cs_${randomUUID()}`
|
|
113
|
+
const hold = async () => {
|
|
114
|
+
const { data, error } = await holdAgentComputerSession({
|
|
115
|
+
client: this.connection.client,
|
|
116
|
+
path: { sessionId: id },
|
|
117
|
+
body: { computer: { ...(await thisComputer()), folder: this.folder } },
|
|
118
|
+
})
|
|
119
|
+
if (error) throw error
|
|
120
|
+
// Closed meanwhile, with the setting or by quitting: what waits keeps waiting.
|
|
121
|
+
if (this.session?.id !== id) return
|
|
122
|
+
for (const runId of data?.waiting ?? []) void this.claimElsewhere(runId)
|
|
123
|
+
}
|
|
124
|
+
// A missed renewal is retried at the next; the session lasts three of them.
|
|
125
|
+
const renew = () => {
|
|
126
|
+
this.lastCall = hold().catch((error: unknown) =>
|
|
127
|
+
console.error("[SixbCLI] Session renewal failed.", error)
|
|
128
|
+
)
|
|
129
|
+
}
|
|
130
|
+
this.session = { id, timer: setInterval(renew, SESSION_RENEW_MS) }
|
|
131
|
+
renew()
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** Close the session: the conversations of this folder read as offline at once. */
|
|
135
|
+
async closeSession(): Promise<void> {
|
|
136
|
+
const session = this.session
|
|
137
|
+
if (session) {
|
|
138
|
+
this.session = null
|
|
139
|
+
clearInterval(session.timer)
|
|
140
|
+
// Whoever closes it next waits for this one, as quitting does after the screen let go.
|
|
141
|
+
this.lastCall = this.lastCall
|
|
142
|
+
.then(() =>
|
|
143
|
+
releaseAgentComputerSession({
|
|
144
|
+
client: this.connection.client,
|
|
145
|
+
path: { sessionId: session.id },
|
|
146
|
+
})
|
|
147
|
+
)
|
|
148
|
+
.then(
|
|
149
|
+
() => {},
|
|
150
|
+
() => {}
|
|
151
|
+
)
|
|
152
|
+
}
|
|
153
|
+
await this.lastCall
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Claim a turn sent from elsewhere when this computer runs its conversation: its owner's, on this
|
|
158
|
+
* computer and in this folder, and still queued, while the session is open. A running turn is
|
|
159
|
+
* another sixb's, or one whose sixb closed, which the API ends interrupted: claiming it again
|
|
160
|
+
* would run its commands twice.
|
|
87
161
|
*/
|
|
88
162
|
async claimIfHere(threadId: string, runId?: string): Promise<void> {
|
|
89
|
-
if (
|
|
163
|
+
if (!this.session || (runId && this.running.has(runId))) return
|
|
90
164
|
const { client } = this.connection
|
|
91
165
|
const { data: thread } = await getAgentThread({ client, path: { threadId } })
|
|
92
|
-
if (thread
|
|
93
|
-
if (!runsOnThisComputer(thread, await thisComputerId())) return
|
|
166
|
+
if (!thread || !this.runsHere(thread, await thisComputerId())) return
|
|
94
167
|
|
|
95
168
|
const turn = runId ?? thread.activeRunId
|
|
96
169
|
if (!turn) return
|
|
97
170
|
const { data: run } = await getAgentRun({ client, path: { runId: turn } })
|
|
98
|
-
if (run?.status === "queued") void this.
|
|
171
|
+
if (run?.status === "queued" && this.session) void this.claimElsewhere(turn)
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** Whether this `sixb` runs `thread`'s turns: its owner's, on this computer, in this folder. */
|
|
175
|
+
runsHere(thread: GetAgentThreadResponses[200], computerId: string): boolean {
|
|
176
|
+
return (
|
|
177
|
+
thread.runsOn === "computer" &&
|
|
178
|
+
owns(this.connection, thread) &&
|
|
179
|
+
thread.computer?.id === computerId &&
|
|
180
|
+
thread.computer.folder === this.folder
|
|
181
|
+
)
|
|
99
182
|
}
|
|
100
183
|
|
|
101
184
|
/** After a stop was asked for: the turn hears it now, not at its next lease renewal. */
|
|
@@ -108,13 +191,23 @@ export class LocalRunner {
|
|
|
108
191
|
return this.running.size > 0
|
|
109
192
|
}
|
|
110
193
|
|
|
111
|
-
/**
|
|
194
|
+
/**
|
|
195
|
+
* Stop every turn this computer runs, each ending interrupted with its end recorded, and close
|
|
196
|
+
* the session.
|
|
197
|
+
*/
|
|
112
198
|
async stop(): Promise<void> {
|
|
113
199
|
const running = [...this.running.values()]
|
|
114
200
|
for (const { stop } of running) stop.abort()
|
|
115
|
-
await Promise.allSettled(running.map(({ done }) => done))
|
|
201
|
+
await Promise.allSettled([...running.map(({ done }) => done), this.closeSession()])
|
|
116
202
|
await this.runner.drain()
|
|
117
203
|
}
|
|
204
|
+
|
|
205
|
+
/** A turn this computer already runs joins that run, and is no news. */
|
|
206
|
+
private claimElsewhere(runId: string): Promise<boolean> {
|
|
207
|
+
return this.claim(runId, (run) => {
|
|
208
|
+
for (const listener of this.elsewhereListeners) listener(run)
|
|
209
|
+
})
|
|
210
|
+
}
|
|
118
211
|
}
|
|
119
212
|
|
|
120
213
|
/** Whether the person signed in owns `thread`: with sign-in off, the system owns what it starts. */
|
|
@@ -128,29 +221,19 @@ export function owns(
|
|
|
128
221
|
: owner.type === "system"
|
|
129
222
|
}
|
|
130
223
|
|
|
131
|
-
/**
|
|
132
|
-
* Whether this computer runs a computer's thread: the one it runs on. A thread none claimed a turn
|
|
133
|
-
* of yet runs on the first that does, the one it started on.
|
|
134
|
-
*/
|
|
135
|
-
export function runsOnThisComputer(
|
|
136
|
-
thread: Pick<GetAgentThreadResponses[200], "computerId">,
|
|
137
|
-
computerId: string
|
|
138
|
-
): boolean {
|
|
139
|
-
return thread.computerId === undefined || thread.computerId === computerId
|
|
140
|
-
}
|
|
141
|
-
|
|
142
224
|
/**
|
|
143
225
|
* A closed terminal, or a kill, ends sixb as quitting does: the turns running here stop, each
|
|
144
226
|
* ending interrupted with its end recorded, instead of renewing their lease from a process nobody
|
|
145
|
-
* sees. Then `exit`, after a bounded wait. Returns the removal of the
|
|
227
|
+
* sees, and the session closes. Then `exit`, after a bounded wait. Returns the removal of the
|
|
228
|
+
* handlers.
|
|
146
229
|
*/
|
|
147
230
|
export function stopOnHangUp(
|
|
148
|
-
runner: () => Pick<LocalRunner, "
|
|
231
|
+
runner: () => Pick<LocalRunner, "stop"> | null,
|
|
149
232
|
exit: (signal: "SIGHUP" | "SIGTERM") => void
|
|
150
233
|
): () => void {
|
|
151
234
|
const hangUp = (signal: "SIGHUP" | "SIGTERM") => {
|
|
152
235
|
const running = runner()
|
|
153
|
-
if (!running
|
|
236
|
+
if (!running) return exit(signal)
|
|
154
237
|
|
|
155
238
|
let timer: ReturnType<typeof setTimeout> | undefined
|
|
156
239
|
const waited = new Promise<void>((resolve) => {
|
package/src/tui/settings.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { readFile, writeFile } from "node:fs/promises"
|
|
1
|
+
import { readFile, rename, writeFile } from "node:fs/promises"
|
|
2
2
|
import { type as osType } from "node:os"
|
|
3
3
|
import { dirname, join } from "node:path"
|
|
4
4
|
import type { ListModelsResponses } from "@sixb/client"
|
|
@@ -18,9 +18,19 @@ export interface Settings {
|
|
|
18
18
|
/** A model the person picked; absent follows the project: Auto with tiers, else its default. */
|
|
19
19
|
readonly model?: { readonly provider: string; readonly modelId: string }
|
|
20
20
|
readonly reasoning?: ReasoningLevel
|
|
21
|
+
/**
|
|
22
|
+
* Whether your messages from the web, or another device, run in this folder: while it is on,
|
|
23
|
+
* `sixb` tells the project it is open here, and runs the turns sent to its conversations here.
|
|
24
|
+
* Kept per folder, apart from the settings every `sixb` rewrites: see {@link rememberWebMessages}.
|
|
25
|
+
*/
|
|
26
|
+
readonly continueFromWeb: boolean
|
|
21
27
|
}
|
|
22
28
|
|
|
23
|
-
export const DEFAULT_SETTINGS: Settings = {
|
|
29
|
+
export const DEFAULT_SETTINGS: Settings = {
|
|
30
|
+
place: "computer",
|
|
31
|
+
approvalMode: "manual",
|
|
32
|
+
continueFromWeb: true,
|
|
33
|
+
}
|
|
24
34
|
|
|
25
35
|
export const APPROVAL_MODES: readonly {
|
|
26
36
|
readonly mode: ApprovalMode
|
|
@@ -60,7 +70,44 @@ export function placeLabel(place: Place): string {
|
|
|
60
70
|
|
|
61
71
|
const SETTINGS_FILE = () => join(dirname(resolveConfigPath()), "tui.json")
|
|
62
72
|
|
|
63
|
-
|
|
73
|
+
/** The folders where the person turned off messages from the web. */
|
|
74
|
+
const WEB_MESSAGES_OFF_FILE = () => join(dirname(resolveConfigPath()), "web-messages-off.json")
|
|
75
|
+
|
|
76
|
+
async function foldersWithWebMessagesOff(): Promise<readonly string[]> {
|
|
77
|
+
const text = await readFile(WEB_MESSAGES_OFF_FILE(), "utf8").catch((error: unknown) => {
|
|
78
|
+
if ((error as NodeJS.ErrnoException).code === "ENOENT") return "[]"
|
|
79
|
+
throw error
|
|
80
|
+
})
|
|
81
|
+
const stored: unknown = JSON.parse(text)
|
|
82
|
+
if (!Array.isArray(stored)) throw new Error("[SixbCLI] Unreadable web-messages-off.json.")
|
|
83
|
+
return stored.filter((folder): folder is string => typeof folder === "string")
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** On unless turned off in `folder`. A choice it can't read stays off rather than run turns here. */
|
|
87
|
+
async function webMessagesOnIn(folder: string): Promise<boolean> {
|
|
88
|
+
return foldersWithWebMessagesOff().then(
|
|
89
|
+
(folders) => !folders.includes(folder),
|
|
90
|
+
() => false
|
|
91
|
+
)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Keep the choice for this folder alone. Reads the file first, as another `sixb` may have written
|
|
96
|
+
* it, and refuses one it can't read rather than lose the other folders' choices. Written whole, so
|
|
97
|
+
* no reader ever finds half of it.
|
|
98
|
+
*/
|
|
99
|
+
export async function rememberWebMessages(folder: string, on: boolean): Promise<void> {
|
|
100
|
+
const others = (await foldersWithWebMessagesOff()).filter((other) => other !== folder)
|
|
101
|
+
const path = WEB_MESSAGES_OFF_FILE()
|
|
102
|
+
const written = `${path}.${process.pid}`
|
|
103
|
+
await writeFile(written, `${JSON.stringify(on ? others : [...others, folder], null, 2)}\n`, {
|
|
104
|
+
mode: 0o600,
|
|
105
|
+
})
|
|
106
|
+
await rename(written, path)
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export async function loadSettings(folder: string): Promise<Settings> {
|
|
110
|
+
const continueFromWeb = await webMessagesOnIn(folder)
|
|
64
111
|
try {
|
|
65
112
|
const stored = JSON.parse(await readFile(SETTINGS_FILE(), "utf8")) as Partial<Settings>
|
|
66
113
|
return {
|
|
@@ -70,14 +117,16 @@ export async function loadSettings(): Promise<Settings> {
|
|
|
70
117
|
: DEFAULT_SETTINGS.approvalMode,
|
|
71
118
|
...(stored.model?.provider && stored.model.modelId ? { model: stored.model } : {}),
|
|
72
119
|
...(stored.reasoning ? { reasoning: stored.reasoning } : {}),
|
|
120
|
+
continueFromWeb,
|
|
73
121
|
}
|
|
74
122
|
} catch {
|
|
75
|
-
return DEFAULT_SETTINGS
|
|
123
|
+
return { ...DEFAULT_SETTINGS, continueFromWeb }
|
|
76
124
|
}
|
|
77
125
|
}
|
|
78
126
|
|
|
79
127
|
export async function saveSettings(settings: Settings): Promise<void> {
|
|
80
|
-
|
|
128
|
+
const { continueFromWeb: _perFolder, ...shared } = settings
|
|
129
|
+
await writeFile(SETTINGS_FILE(), `${JSON.stringify(shared, null, 2)}\n`, { mode: 0o600 }).catch(
|
|
81
130
|
() => {}
|
|
82
131
|
)
|
|
83
132
|
}
|
package/src/tui/transcript.tsx
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
/** @jsxImportSource @opentui/react */
|
|
2
|
-
import type
|
|
2
|
+
import { CodeRenderable, type MarkdownOptions, type SyntaxStyle } from "@opentui/core"
|
|
3
|
+
import { useRenderer } from "@opentui/react"
|
|
3
4
|
import type { ListAgentThreadApprovalsResponses, ListAgentThreadRunsResponses } from "@sixb/client"
|
|
4
|
-
import {
|
|
5
|
+
import { useEffect, useState } from "react"
|
|
6
|
+
import { duration, friendlyPath, plural, runFailureText, type ToolLine, toolLine } from "./format"
|
|
7
|
+
import { steadyMarkdown } from "./markdown"
|
|
5
8
|
import {
|
|
6
9
|
type ApprovalOutcome,
|
|
7
10
|
approvalOutcomes,
|
|
@@ -69,6 +72,9 @@ export function Transcript({
|
|
|
69
72
|
const run = message.runId ? runsById.get(message.runId) : undefined
|
|
70
73
|
return (
|
|
71
74
|
<box key={message.id} flexDirection="column" gap={1}>
|
|
75
|
+
{message.compaction ? (
|
|
76
|
+
<CompactionLine colors={colors} contextFull={message.compaction.contextFull} />
|
|
77
|
+
) : null}
|
|
72
78
|
<AgentParts
|
|
73
79
|
colors={colors}
|
|
74
80
|
syntax={syntax}
|
|
@@ -113,6 +119,21 @@ export function Transcript({
|
|
|
113
119
|
)
|
|
114
120
|
}
|
|
115
121
|
|
|
122
|
+
/** Its run condensed the conversation before answering, or to go on when the context was full. */
|
|
123
|
+
function CompactionLine({
|
|
124
|
+
colors,
|
|
125
|
+
contextFull,
|
|
126
|
+
}: {
|
|
127
|
+
readonly colors: TuiColors
|
|
128
|
+
readonly contextFull: boolean
|
|
129
|
+
}) {
|
|
130
|
+
return (
|
|
131
|
+
<text fg={contextFull ? colors.amber : colors.faint}>
|
|
132
|
+
{contextFull ? "◇ Context was full — condensed and continued" : "◇ Condensed conversation"}
|
|
133
|
+
</text>
|
|
134
|
+
)
|
|
135
|
+
}
|
|
136
|
+
|
|
116
137
|
function UserMessage({
|
|
117
138
|
colors,
|
|
118
139
|
message,
|
|
@@ -175,12 +196,11 @@ function AgentParts({
|
|
|
175
196
|
switch (part.kind) {
|
|
176
197
|
case "text":
|
|
177
198
|
return (
|
|
178
|
-
<
|
|
199
|
+
<Answer
|
|
179
200
|
key={key}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
conceal
|
|
201
|
+
colors={colors}
|
|
202
|
+
syntax={syntax}
|
|
203
|
+
text={part.text}
|
|
184
204
|
streaming={streaming && last}
|
|
185
205
|
/>
|
|
186
206
|
)
|
|
@@ -219,6 +239,68 @@ function AgentParts({
|
|
|
219
239
|
)
|
|
220
240
|
}
|
|
221
241
|
|
|
242
|
+
/**
|
|
243
|
+
* What the agent said, as markdown drawn the moment it is set: each top-level block on its own,
|
|
244
|
+
* where OpenTUI otherwise draws runs of them as raw markdown until highlighting conceals the
|
|
245
|
+
* markers, every time the text grows. While it streams, its unfinished end is steadied.
|
|
246
|
+
*/
|
|
247
|
+
function Answer({
|
|
248
|
+
colors,
|
|
249
|
+
syntax,
|
|
250
|
+
text,
|
|
251
|
+
streaming,
|
|
252
|
+
}: {
|
|
253
|
+
readonly colors: TuiColors
|
|
254
|
+
readonly syntax: SyntaxStyle
|
|
255
|
+
readonly text: string
|
|
256
|
+
readonly streaming: boolean
|
|
257
|
+
}) {
|
|
258
|
+
// Markdown created finished draws nothing until it is highlighted, and an answer is created
|
|
259
|
+
// finished whenever its stored message replaces the streamed one. Created streaming it is drawn
|
|
260
|
+
// at once, so a finished answer is finalized after its first frame.
|
|
261
|
+
const renderer = useRenderer()
|
|
262
|
+
const [drawn, setDrawn] = useState(false)
|
|
263
|
+
useEffect(() => {
|
|
264
|
+
const mark = () => setDrawn(true)
|
|
265
|
+
renderer.once("frame", mark)
|
|
266
|
+
return () => {
|
|
267
|
+
renderer.off("frame", mark)
|
|
268
|
+
}
|
|
269
|
+
}, [renderer])
|
|
270
|
+
|
|
271
|
+
return (
|
|
272
|
+
<markdown
|
|
273
|
+
content={streaming ? steadyMarkdown(text) : text.trim()}
|
|
274
|
+
syntaxStyle={syntax}
|
|
275
|
+
fg={colors.text}
|
|
276
|
+
conceal
|
|
277
|
+
internalBlockMode="top-level"
|
|
278
|
+
tableOptions={TABLES}
|
|
279
|
+
renderNode={drawCodeAtOnce}
|
|
280
|
+
streaming={streaming || !drawn}
|
|
281
|
+
/>
|
|
282
|
+
)
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/** Tables boxed, as the transcript has always drawn them. */
|
|
286
|
+
const TABLES: MarkdownOptions["tableOptions"] = { style: "grid" }
|
|
287
|
+
|
|
288
|
+
type RenderNode = NonNullable<MarkdownOptions["renderNode"]>
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* A code block drawn plain until it is highlighted, rather than left blank. Only code blocks: the
|
|
292
|
+
* rest keeps OpenTUI's own rendering.
|
|
293
|
+
*/
|
|
294
|
+
const drawCodeAtOnce = Object.assign<RenderNode, { codeBlockOnly: true }>(
|
|
295
|
+
(token, context) => {
|
|
296
|
+
if (token.type !== "code") return undefined
|
|
297
|
+
const code = context.defaultRender()
|
|
298
|
+
if (code instanceof CodeRenderable) code.drawUnstyledText = true
|
|
299
|
+
return code
|
|
300
|
+
},
|
|
301
|
+
{ codeBlockOnly: true }
|
|
302
|
+
)
|
|
303
|
+
|
|
222
304
|
function Thought({
|
|
223
305
|
colors,
|
|
224
306
|
text,
|
|
@@ -419,7 +501,7 @@ function RunMeta({
|
|
|
419
501
|
<span fg={run.status === "failed" ? colors.red : colors.amber}>{` · ${ended}`}</span>
|
|
420
502
|
) : null}
|
|
421
503
|
{run.status === "failed" && run.error ? (
|
|
422
|
-
<span fg={colors.faint}>{` ${run.error
|
|
504
|
+
<span fg={colors.faint}>{` ${runFailureText(run.error)}`}</span>
|
|
423
505
|
) : null}
|
|
424
506
|
</text>
|
|
425
507
|
)
|
package/src/tui/ui.tsx
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
/** @jsxImportSource @opentui/react */
|
|
2
2
|
import { createTextAttributes, type KeyBinding, type TextareaRenderable } from "@opentui/core"
|
|
3
|
-
import { useEffect, useRef, useState } from "react"
|
|
3
|
+
import { createContext, useContext, useEffect, useRef, useState } from "react"
|
|
4
4
|
import { SPINNER_FRAMES } from "../ui/theme"
|
|
5
5
|
import type { TuiColors } from "./theme"
|
|
6
6
|
|
|
7
7
|
export const BOLD = createTextAttributes({ bold: true })
|
|
8
8
|
export const ITALIC = createTextAttributes({ italic: true })
|
|
9
9
|
|
|
10
|
+
/** The rows the composer grows to as its text wraps or breaks; past them it scrolls. */
|
|
11
|
+
const COMPOSER_MAX_ROWS = 8
|
|
12
|
+
|
|
10
13
|
/** Enter sends; shift+enter or ctrl+j starts a new line. */
|
|
11
14
|
const COMPOSER_KEYS: KeyBinding[] = [
|
|
12
15
|
{ name: "return", action: "submit" },
|
|
@@ -15,6 +18,12 @@ const COMPOSER_KEYS: KeyBinding[] = [
|
|
|
15
18
|
{ name: "j", ctrl: true, action: "newline" },
|
|
16
19
|
]
|
|
17
20
|
|
|
21
|
+
/**
|
|
22
|
+
* The focused composer's clear: ctrl+c empties a draft before it quits, and says whether there
|
|
23
|
+
* was one. The app's keys run before the composer's, so the app asks it.
|
|
24
|
+
*/
|
|
25
|
+
export const ComposerDraft = createContext<{ current: (() => boolean) | null }>({ current: null })
|
|
26
|
+
|
|
18
27
|
/** One piece of the line under the composer, such as `This Mac` or `Ask first`. */
|
|
19
28
|
export interface StatusItem {
|
|
20
29
|
readonly text: string
|
|
@@ -49,7 +58,30 @@ export function Composer({
|
|
|
49
58
|
readonly onChange?: (text: string) => void
|
|
50
59
|
}) {
|
|
51
60
|
const input = useRef<TextareaRenderable>(null)
|
|
52
|
-
const [
|
|
61
|
+
const [rows, setRows] = useState(1)
|
|
62
|
+
// Rows as the text wraps at the composer's width, not lines: a long line grows it too. Not
|
|
63
|
+
// virtualLineCount, which counts no more rows than the textarea already shows.
|
|
64
|
+
const fit = () => setRows(Math.max(1, input.current?.lineInfo.lineStartCols.length ?? 1))
|
|
65
|
+
const clear = () => {
|
|
66
|
+
input.current?.setText("")
|
|
67
|
+
setRows(1)
|
|
68
|
+
onChange?.("")
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const draft = useContext(ComposerDraft)
|
|
72
|
+
useEffect(() => {
|
|
73
|
+
if (!focused) return
|
|
74
|
+
const clearDraft = () => {
|
|
75
|
+
if (!input.current?.plainText) return false
|
|
76
|
+
clear()
|
|
77
|
+
return true
|
|
78
|
+
}
|
|
79
|
+
draft.current = clearDraft
|
|
80
|
+
return () => {
|
|
81
|
+
if (draft.current === clearDraft) draft.current = null
|
|
82
|
+
}
|
|
83
|
+
})
|
|
84
|
+
|
|
53
85
|
return (
|
|
54
86
|
<box
|
|
55
87
|
border={["left"]}
|
|
@@ -62,6 +94,7 @@ export function Composer({
|
|
|
62
94
|
paddingBottom={1}
|
|
63
95
|
flexDirection="column"
|
|
64
96
|
flexShrink={0}
|
|
97
|
+
onSizeChange={fit}
|
|
65
98
|
>
|
|
66
99
|
<textarea
|
|
67
100
|
ref={input}
|
|
@@ -73,20 +106,16 @@ export function Composer({
|
|
|
73
106
|
backgroundColor={colors.surface}
|
|
74
107
|
focusedBackgroundColor={colors.surface}
|
|
75
108
|
keyBindings={COMPOSER_KEYS}
|
|
76
|
-
height={Math.min(
|
|
109
|
+
height={Math.min(rows, COMPOSER_MAX_ROWS)}
|
|
77
110
|
onContentChange={() => {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
onChange?.(text)
|
|
111
|
+
fit()
|
|
112
|
+
onChange?.(input.current?.plainText ?? "")
|
|
81
113
|
}}
|
|
82
114
|
onSubmit={() => {
|
|
83
115
|
const text = input.current?.plainText.trim() ?? ""
|
|
84
116
|
if (!text && !allowEmpty) return
|
|
85
117
|
void Promise.resolve(onSubmit(text)).then((taken) => {
|
|
86
|
-
if (
|
|
87
|
-
input.current?.setText("")
|
|
88
|
-
setLines(1)
|
|
89
|
-
onChange?.("")
|
|
118
|
+
if (taken) clear()
|
|
90
119
|
})
|
|
91
120
|
}}
|
|
92
121
|
/>
|
|
@@ -114,7 +143,7 @@ export function KeyHints({
|
|
|
114
143
|
readonly items: readonly (readonly [key: string, label: string])[]
|
|
115
144
|
}) {
|
|
116
145
|
return (
|
|
117
|
-
<text>
|
|
146
|
+
<text wrapMode="none" flexShrink={0}>
|
|
118
147
|
{items.map(([key, label], index) => (
|
|
119
148
|
<span key={key}>
|
|
120
149
|
{index > 0 ? " " : ""}
|
package/src/ui/deploy-screens.ts
CHANGED
|
@@ -31,6 +31,7 @@ export function deployReleaseView({
|
|
|
31
31
|
configPath: string
|
|
32
32
|
}): string {
|
|
33
33
|
const steps = [
|
|
34
|
+
...(release.steps.env ? [{ label: "env", commands: [release.steps.env] }] : []),
|
|
34
35
|
{ label: "build", commands: release.steps.build },
|
|
35
36
|
{ label: "before start", commands: release.steps.beforeStart },
|
|
36
37
|
]
|
|
@@ -105,9 +106,12 @@ export function deployStepLine(label: string, seconds: string): string {
|
|
|
105
106
|
export function deployCompleteView({
|
|
106
107
|
release,
|
|
107
108
|
seconds,
|
|
109
|
+
keptEnv = false,
|
|
108
110
|
}: {
|
|
109
111
|
release: DeployRelease
|
|
110
112
|
seconds?: number
|
|
113
|
+
/** The deploy couldn't update the server's `.env`, so this release runs on its current values. */
|
|
114
|
+
keptEnv?: boolean
|
|
111
115
|
}): string {
|
|
112
116
|
const urls = release.services.flatMap((service) =>
|
|
113
117
|
service.http ? [{ label: service.name, value: service.http.publicOrigin }] : []
|
|
@@ -118,7 +122,14 @@ export function deployCompleteView({
|
|
|
118
122
|
`${release.name} deployed`,
|
|
119
123
|
seconds === undefined ? undefined : `${seconds.toFixed(1)}s`
|
|
120
124
|
),
|
|
121
|
-
urls.length > 0 ? rows(urls) : null
|
|
125
|
+
urls.length > 0 ? rows(urls) : null,
|
|
126
|
+
keptEnv
|
|
127
|
+
? marked(
|
|
128
|
+
tone.warn(glyph.warn),
|
|
129
|
+
"This release runs on the server's current .env, not on the latest values. Deploy again to update them.",
|
|
130
|
+
tone.muted
|
|
131
|
+
)
|
|
132
|
+
: null
|
|
122
133
|
)
|
|
123
134
|
}
|
|
124
135
|
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { EnvName } from "@sixb/core/env"
|
|
2
|
+
import { header, headline, plural, screen, stack, table } from "./layout"
|
|
3
|
+
import { tone } from "./theme"
|
|
4
|
+
|
|
5
|
+
export function envPulledView(input: { readonly count: number; readonly env: EnvName }): string {
|
|
6
|
+
return screen(headline("ok", `Wrote ${plural(input.count, "variable")} to .env`, input.env))
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/** What a pull says when it leaves `.env` as it was. A deploy watches its output for this. */
|
|
10
|
+
export const ENV_KEPT_MESSAGE = "Kept the current .env"
|
|
11
|
+
|
|
12
|
+
/** A deploy kept the server's `.env`, because the source was down or the commit has none. */
|
|
13
|
+
export function envKeptView(input: { readonly env: EnvName; readonly reason: string }): string {
|
|
14
|
+
return screen(stack(headline("warn", ENV_KEPT_MESSAGE, input.env), tone.muted(input.reason)))
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function envSetView(input: {
|
|
18
|
+
readonly name: string
|
|
19
|
+
readonly env: EnvName
|
|
20
|
+
readonly declared: boolean
|
|
21
|
+
}): string {
|
|
22
|
+
return screen(
|
|
23
|
+
stack(
|
|
24
|
+
headline("ok", `Set ${input.name}`, input.env),
|
|
25
|
+
input.declared ? null : tone.warn(`Add ${input.name} to sixb.env.ts so it's checked.`)
|
|
26
|
+
)
|
|
27
|
+
)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function envInitView(input: {
|
|
31
|
+
readonly uploaded: readonly { readonly env: EnvName; readonly count: number }[]
|
|
32
|
+
readonly names: number
|
|
33
|
+
}): string {
|
|
34
|
+
const uploaded = input.uploaded.map(({ env, count }) => `${plural(count, "variable")} to ${env}`)
|
|
35
|
+
return screen(
|
|
36
|
+
stack(
|
|
37
|
+
headline("ok", `Uploaded ${uploaded.join(" and ")}`),
|
|
38
|
+
headline("ok", `Wrote sixb.env.ts with ${plural(input.names, "name")}`)
|
|
39
|
+
)
|
|
40
|
+
)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface EnvStatusRow {
|
|
44
|
+
readonly name: string
|
|
45
|
+
readonly dev: EnvStatusCell
|
|
46
|
+
readonly prod: EnvStatusCell
|
|
47
|
+
readonly declared: boolean
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** `set` has a value; `missing` must have one; `unneeded` needs none; `unknown` can't be read. */
|
|
51
|
+
export type EnvStatusCell = "set" | "missing" | "unneeded" | "unknown"
|
|
52
|
+
|
|
53
|
+
const CELLS: Readonly<Record<EnvStatusCell, () => string>> = {
|
|
54
|
+
set: () => tone.ok("✓"),
|
|
55
|
+
missing: () => tone.fail("✗ missing"),
|
|
56
|
+
unneeded: () => tone.faint("–"),
|
|
57
|
+
unknown: () => tone.faint("no access"),
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function envStatusView(input: {
|
|
61
|
+
readonly rows: readonly EnvStatusRow[]
|
|
62
|
+
readonly missing: number
|
|
63
|
+
}): string {
|
|
64
|
+
return screen(
|
|
65
|
+
header("env status"),
|
|
66
|
+
table(
|
|
67
|
+
["", "dev", "prod", ""],
|
|
68
|
+
input.rows.map((row) => [
|
|
69
|
+
row.name,
|
|
70
|
+
CELLS[row.dev](),
|
|
71
|
+
CELLS[row.prod](),
|
|
72
|
+
row.declared ? "" : tone.muted("not in sixb.env.ts"),
|
|
73
|
+
])
|
|
74
|
+
),
|
|
75
|
+
input.missing > 0
|
|
76
|
+
? headline("warn", `${plural(input.missing, "value")} missing`)
|
|
77
|
+
: input.rows.some((row) => row.dev === "unknown" || row.prod === "unknown")
|
|
78
|
+
? headline("ok", "Everything sixb.env.ts requires is set where you have access")
|
|
79
|
+
: headline("ok", "Everything sixb.env.ts requires is set")
|
|
80
|
+
)
|
|
81
|
+
}
|