@sixb/cli 0.1.25 → 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.
- package/README.md +5 -5
- package/dist/commands/agent.d.ts +16 -0
- package/dist/commands/agent.d.ts.map +1 -0
- package/dist/commands/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 +0 -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/commands/worker-group.d.ts +0 -1
- package/dist/commands/worker-group.d.ts.map +1 -1
- package/dist/commands/worker.d.ts +0 -1
- package/dist/commands/worker.d.ts.map +1 -1
- package/dist/lib/command-line.d.ts +41 -6
- 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/github-ci.d.ts.map +1 -1
- package/dist/lib/hidden-prompt.d.ts +19 -0
- package/dist/lib/hidden-prompt.d.ts.map +1 -0
- package/dist/lib/runtime.d.ts +0 -1
- package/dist/lib/runtime.d.ts.map +1 -1
- package/dist/lib/worker-registry.d.ts +0 -1
- package/dist/lib/worker-registry.d.ts.map +1 -1
- package/dist/tui/app.d.ts +27 -0
- package/dist/tui/app.d.ts.map +1 -0
- package/dist/tui/brand.d.ts +7 -0
- package/dist/tui/brand.d.ts.map +1 -0
- package/dist/tui/computer.d.ts +8 -0
- package/dist/tui/computer.d.ts.map +1 -0
- package/dist/tui/connection.d.ts +45 -0
- package/dist/tui/connection.d.ts.map +1 -0
- package/dist/tui/context.d.ts +13 -0
- package/dist/tui/context.d.ts.map +1 -0
- package/dist/tui/format.d.ts +118 -0
- package/dist/tui/format.d.ts.map +1 -0
- package/dist/tui/index.d.ts +12 -0
- package/dist/tui/index.d.ts.map +1 -0
- package/dist/tui/markdown.d.ts +18 -0
- package/dist/tui/markdown.d.ts.map +1 -0
- package/dist/tui/palette.d.ts +25 -0
- package/dist/tui/palette.d.ts.map +1 -0
- package/dist/tui/parts.d.ts +74 -0
- package/dist/tui/parts.d.ts.map +1 -0
- package/dist/tui/runner.d.ts +75 -0
- package/dist/tui/runner.d.ts.map +1 -0
- package/dist/tui/settings.d.ts +56 -0
- package/dist/tui/settings.d.ts.map +1 -0
- package/dist/tui/slash.d.ts +14 -0
- package/dist/tui/slash.d.ts.map +1 -0
- package/dist/tui/theme.d.ts +39 -0
- package/dist/tui/theme.d.ts.map +1 -0
- package/dist/tui/transcript.d.ts +52 -0
- package/dist/tui/transcript.d.ts.map +1 -0
- package/dist/tui/ui.d.ts +42 -0
- package/dist/tui/ui.d.ts.map +1 -0
- 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 -17
- package/src/commands/agent.ts +344 -0
- 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 -5
- package/src/commands/dev.ts +3 -0
- package/src/commands/env.ts +422 -0
- package/src/commands/worker-group.ts +0 -4
- package/src/commands/worker.ts +0 -4
- package/src/index.tsx +95 -5
- package/src/lib/command-line.ts +111 -16
- package/src/lib/deploy-release.ts +3 -11
- 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/github-ci.ts +3 -1
- package/src/lib/hidden-prompt.ts +97 -0
- package/src/lib/runtime.ts +0 -2
- package/src/lib/worker-registry.ts +0 -2
- package/src/tui/app.tsx +1334 -0
- package/src/tui/brand.tsx +51 -0
- package/src/tui/computer.ts +91 -0
- package/src/tui/connection.ts +149 -0
- package/src/tui/context.tsx +149 -0
- package/src/tui/format.ts +477 -0
- package/src/tui/index.tsx +364 -0
- package/src/tui/markdown.ts +91 -0
- package/src/tui/palette.tsx +183 -0
- package/src/tui/parts.ts +274 -0
- package/src/tui/runner.ts +256 -0
- package/src/tui/settings.ts +176 -0
- package/src/tui/slash.ts +32 -0
- package/src/tui/theme.ts +111 -0
- package/src/tui/transcript.tsx +637 -0
- package/src/tui/ui.tsx +177 -0
- package/src/ui/deploy-screens.ts +12 -1
- package/src/ui/env-screens.ts +81 -0
- package/dist/lib/agent-turn-timeout.d.ts +0 -8
- package/dist/lib/agent-turn-timeout.d.ts.map +0 -1
- package/src/lib/agent-turn-timeout.ts +0 -46
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/** @jsxImportSource @opentui/react */
|
|
2
|
+
import type { TuiColors } from "./theme"
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Sixb's name, set in half blocks at one weight: every stroke a single pixel, so stems and bars
|
|
6
|
+
* match and the letters read as type, with the corners cut round and the `x`'s diagonals in pairs
|
|
7
|
+
* of pixels, so they read as lines. Eight pixels tall, the `i`'s dot
|
|
8
|
+
* and the `b`'s ascender above an x-height of five.
|
|
9
|
+
*/
|
|
10
|
+
const WORDMARK = [
|
|
11
|
+
" ▄ █ ",
|
|
12
|
+
" ▄▄▄▄▄▄ ▄ ▄▄ ▄▄ █▄▄▄▄ ",
|
|
13
|
+
"▀▄▄▄▄▄ █ ▀█▄█▀ █ ▀▄",
|
|
14
|
+
"▄▄▄▄▄▄▀ █ ▄█▀ ▀█▄ █▄▄▄▄▀ ",
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
const WIDTH = Math.max(...WORDMARK.map((row) => row.length))
|
|
18
|
+
|
|
19
|
+
/** The wordmark in Sixb's blues, palest to deepest across the name, as the website's hero fills. */
|
|
20
|
+
export function Logo({ colors }: { readonly colors: TuiColors }) {
|
|
21
|
+
const blues = colors.wordmark
|
|
22
|
+
const tint = (column: number) =>
|
|
23
|
+
blues[Math.min(blues.length - 1, Math.floor((column / WIDTH) * blues.length))] ?? colors.blue
|
|
24
|
+
// One text, not a row each: a column of rows drew one row past its own box.
|
|
25
|
+
return (
|
|
26
|
+
<text wrapMode="none" flexShrink={0}>
|
|
27
|
+
{WORDMARK.flatMap((row, index) => [
|
|
28
|
+
...runs(row).map((run) => (
|
|
29
|
+
<span key={`${index}-${run.start}`} fg={tint(run.start)}>
|
|
30
|
+
{run.text}
|
|
31
|
+
</span>
|
|
32
|
+
)),
|
|
33
|
+
index < WORDMARK.length - 1 ? <span key={`${index}-break`}>{"\n"}</span> : null,
|
|
34
|
+
])}
|
|
35
|
+
</text>
|
|
36
|
+
)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** A row cut where its color steps: one span per stretch of a single blue. */
|
|
40
|
+
function runs(row: string): { readonly start: number; readonly text: string }[] {
|
|
41
|
+
const steps = 4
|
|
42
|
+
const out: { start: number; text: string }[] = []
|
|
43
|
+
for (let start = 0; start < row.length; ) {
|
|
44
|
+
const step = Math.floor((start / WIDTH) * steps)
|
|
45
|
+
let end = start
|
|
46
|
+
while (end < row.length && Math.floor((end / WIDTH) * steps) === step) end += 1
|
|
47
|
+
out.push({ start, text: row.slice(start, end) })
|
|
48
|
+
start = end
|
|
49
|
+
}
|
|
50
|
+
return out
|
|
51
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto"
|
|
2
|
+
import { mkdir, readFile, writeFile } from "node:fs/promises"
|
|
3
|
+
import { hostname, type as osType } from "node:os"
|
|
4
|
+
import { dirname, join } from "node:path"
|
|
5
|
+
import { CONTROL_CHARACTER } from "@sixb/core/internal/agent-run-storage-provider"
|
|
6
|
+
import { resolveConfigPath } from "../lib/profiles"
|
|
7
|
+
|
|
8
|
+
// This computer's id, which every claim of a turn names: a conversation that runs on its owner's
|
|
9
|
+
// computer runs on one of them, and only that one claims its turns. Kept beside the CLI's sign-in,
|
|
10
|
+
// which the agent's commands never read. Not a secret: it tells your own computers apart.
|
|
11
|
+
|
|
12
|
+
const COMPUTER_FILE = () => join(dirname(resolveConfigPath()), "computer.json")
|
|
13
|
+
|
|
14
|
+
const named = new Map<string, Promise<string>>()
|
|
15
|
+
|
|
16
|
+
/** This computer's id: named once, the first time `sixb` runs here, and kept. */
|
|
17
|
+
export function thisComputerId(): Promise<string> {
|
|
18
|
+
const path = COMPUTER_FILE()
|
|
19
|
+
let id = named.get(path)
|
|
20
|
+
if (!id) {
|
|
21
|
+
id = readOrName(path)
|
|
22
|
+
named.set(path, id)
|
|
23
|
+
// A failure is not kept: the next call tries again.
|
|
24
|
+
id.catch(() => named.delete(path))
|
|
25
|
+
}
|
|
26
|
+
return id
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** This computer: its id, and what its owner calls it, as the web shows where a thread runs. */
|
|
30
|
+
export async function thisComputer(): Promise<{ readonly id: string; readonly name: string }> {
|
|
31
|
+
const [id, name] = await Promise.all([thisComputerId(), thisComputerName()])
|
|
32
|
+
return { id, name }
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
let computerName: Promise<string> | undefined
|
|
36
|
+
|
|
37
|
+
/** The name its owner gave the computer: its Mac name, else its host name. */
|
|
38
|
+
function thisComputerName(): Promise<string> {
|
|
39
|
+
computerName ??= readComputerName().then((name) =>
|
|
40
|
+
// Shown back as written: no control characters, and short.
|
|
41
|
+
(name.replace(new RegExp(CONTROL_CHARACTER, "g"), "").trim() || "This computer").slice(0, 120)
|
|
42
|
+
)
|
|
43
|
+
return computerName
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async function readComputerName(): Promise<string> {
|
|
47
|
+
if (osType() === "Darwin") {
|
|
48
|
+
try {
|
|
49
|
+
const scutil = Bun.spawn(["scutil", "--get", "ComputerName"], {
|
|
50
|
+
stdout: "pipe",
|
|
51
|
+
stderr: "ignore",
|
|
52
|
+
})
|
|
53
|
+
const timer = setTimeout(() => scutil.kill(), 2_000)
|
|
54
|
+
const name = await new Response(scutil.stdout).text()
|
|
55
|
+
clearTimeout(timer)
|
|
56
|
+
if ((await scutil.exited) === 0 && name.trim()) return name
|
|
57
|
+
} catch {
|
|
58
|
+
// Not every Mac answers: its host name stands in.
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return hostname().replace(/\.local$/, "")
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async function readOrName(path: string): Promise<string> {
|
|
65
|
+
const stored = await read(path)
|
|
66
|
+
if (stored) return stored
|
|
67
|
+
|
|
68
|
+
const id = `cmp_${randomUUID()}`
|
|
69
|
+
await mkdir(dirname(path), { recursive: true, mode: 0o700 })
|
|
70
|
+
try {
|
|
71
|
+
await writeFile(path, `${JSON.stringify({ id }, null, 2)}\n`, { mode: 0o600, flag: "wx" })
|
|
72
|
+
return id
|
|
73
|
+
} catch (error) {
|
|
74
|
+
// Another sixb named this computer first: its name is the one.
|
|
75
|
+
const raced = await read(path)
|
|
76
|
+
if (raced) return raced
|
|
77
|
+
throw new Error(
|
|
78
|
+
`[SixbCLI] Could not keep this computer's id in ${path}: remove the file, and sixb names the computer again.`,
|
|
79
|
+
{ cause: error }
|
|
80
|
+
)
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
async function read(path: string): Promise<string | undefined> {
|
|
85
|
+
try {
|
|
86
|
+
const stored = JSON.parse(await readFile(path, "utf8")) as { readonly id?: unknown }
|
|
87
|
+
return typeof stored.id === "string" && stored.id.trim() ? stored.id : undefined
|
|
88
|
+
} catch {
|
|
89
|
+
return undefined
|
|
90
|
+
}
|
|
91
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { hostname } from "node:os"
|
|
2
|
+
import {
|
|
3
|
+
createSixbClient,
|
|
4
|
+
getAuthSession,
|
|
5
|
+
getProjectInfo,
|
|
6
|
+
getSixbSessionAccessToken,
|
|
7
|
+
type SixbClient,
|
|
8
|
+
type SixbSessionTokens,
|
|
9
|
+
startSixbDeviceLogin,
|
|
10
|
+
} from "@sixb/client"
|
|
11
|
+
import { normalizeApiUrl } from "../lib/api-client"
|
|
12
|
+
import {
|
|
13
|
+
profileSessionStore,
|
|
14
|
+
type ResolvedProfile,
|
|
15
|
+
resolveProfile,
|
|
16
|
+
updateConfig,
|
|
17
|
+
} from "../lib/profiles"
|
|
18
|
+
|
|
19
|
+
/** A project the app talks to, as the person signed in to it. */
|
|
20
|
+
export interface Connection {
|
|
21
|
+
readonly apiUrl: string
|
|
22
|
+
readonly client: SixbClient
|
|
23
|
+
readonly project: { readonly id: string; readonly timeZone: string; readonly locale: string }
|
|
24
|
+
/** Who is signed in; absent where the project runs without sign-in. */
|
|
25
|
+
readonly user?: { readonly id: string; readonly email: string; readonly name: string }
|
|
26
|
+
/** The person's own credential, as an `Authorization` header, read fresh for each use. */
|
|
27
|
+
authorization(): Promise<string>
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Why the app cannot connect yet, and where it would. */
|
|
31
|
+
export interface SignedOut {
|
|
32
|
+
readonly apiUrl: string
|
|
33
|
+
readonly profile?: string
|
|
34
|
+
readonly reason: "signed-out" | "session-ended" | "unreachable"
|
|
35
|
+
readonly message?: string
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Connect as the CLI's current profile, as every `sixb` command does. */
|
|
39
|
+
export async function connect(input: {
|
|
40
|
+
readonly apiUrl?: string
|
|
41
|
+
readonly profile?: string
|
|
42
|
+
readonly token?: string
|
|
43
|
+
}): Promise<Connection | SignedOut> {
|
|
44
|
+
let resolved: ResolvedProfile
|
|
45
|
+
try {
|
|
46
|
+
resolved = await resolveProfile(input)
|
|
47
|
+
} catch (error) {
|
|
48
|
+
return { apiUrl: input.apiUrl ?? "", reason: "session-ended", message: errorText(error) }
|
|
49
|
+
}
|
|
50
|
+
const profile = resolved.profile
|
|
51
|
+
const viaSession = resolved.tokenSource === "session" && profile !== undefined
|
|
52
|
+
const client = createSixbClient({
|
|
53
|
+
baseUrl: resolved.apiUrl,
|
|
54
|
+
auth: viaSession
|
|
55
|
+
? { kind: "session", store: profileSessionStore(profile) }
|
|
56
|
+
: resolved.token
|
|
57
|
+
? { kind: "bearer", token: resolved.token }
|
|
58
|
+
: { kind: "none" },
|
|
59
|
+
})
|
|
60
|
+
const authorization = viaSession
|
|
61
|
+
? async () => {
|
|
62
|
+
const token = await getSixbSessionAccessToken({
|
|
63
|
+
baseUrl: resolved.apiUrl,
|
|
64
|
+
store: profileSessionStore(profile),
|
|
65
|
+
})
|
|
66
|
+
return token ? `Bearer ${token}` : ""
|
|
67
|
+
}
|
|
68
|
+
: async () => (resolved.token ? `Bearer ${resolved.token}` : "")
|
|
69
|
+
|
|
70
|
+
try {
|
|
71
|
+
const [project, session] = await Promise.all([
|
|
72
|
+
getProjectInfo({ client, throwOnError: true }),
|
|
73
|
+
getAuthSession({ client, throwOnError: true }),
|
|
74
|
+
])
|
|
75
|
+
const signedIn = session.data.authenticated ? session.data.user : undefined
|
|
76
|
+
if (!session.data.authenticated && session.data.authEnabled) {
|
|
77
|
+
return {
|
|
78
|
+
apiUrl: resolved.apiUrl,
|
|
79
|
+
...(profile === undefined ? {} : { profile }),
|
|
80
|
+
reason: "signed-out",
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
apiUrl: resolved.apiUrl,
|
|
85
|
+
client,
|
|
86
|
+
project: project.data,
|
|
87
|
+
...(signedIn
|
|
88
|
+
? {
|
|
89
|
+
user: {
|
|
90
|
+
id: signedIn.id,
|
|
91
|
+
email: signedIn.email,
|
|
92
|
+
name: signedIn.displayName ?? signedIn.email,
|
|
93
|
+
},
|
|
94
|
+
}
|
|
95
|
+
: {}),
|
|
96
|
+
authorization,
|
|
97
|
+
}
|
|
98
|
+
} catch (error) {
|
|
99
|
+
const status = (error as { status?: unknown }).status
|
|
100
|
+
return {
|
|
101
|
+
apiUrl: resolved.apiUrl,
|
|
102
|
+
...(profile === undefined ? {} : { profile }),
|
|
103
|
+
reason: status === 401 || status === 403 ? "signed-out" : "unreachable",
|
|
104
|
+
message: errorText(error),
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** A sign-in in progress: show the code, open the page, then wait for the person to approve it. */
|
|
110
|
+
export interface PendingSignIn {
|
|
111
|
+
readonly apiUrl: string
|
|
112
|
+
readonly userCode: string
|
|
113
|
+
readonly url: string
|
|
114
|
+
complete(signal: AbortSignal): Promise<void>
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Sign this computer in to `apiUrl` with the device flow, as `sixb login` does, and keep the
|
|
119
|
+
* session on a profile named after the project.
|
|
120
|
+
*/
|
|
121
|
+
export async function startSignIn(apiUrl: string): Promise<PendingSignIn> {
|
|
122
|
+
const baseUrl = normalizeApiUrl(apiUrl)
|
|
123
|
+
const login = await startSixbDeviceLogin({ baseUrl, clientName: `sixb on ${hostname()}` })
|
|
124
|
+
return {
|
|
125
|
+
apiUrl: baseUrl,
|
|
126
|
+
userCode: login.userCode,
|
|
127
|
+
url: login.verificationUriComplete,
|
|
128
|
+
async complete(signal) {
|
|
129
|
+
const session: SixbSessionTokens = await login.complete({ signal })
|
|
130
|
+
const client = createSixbClient({
|
|
131
|
+
baseUrl,
|
|
132
|
+
auth: { kind: "bearer", token: session.accessToken },
|
|
133
|
+
})
|
|
134
|
+
const { data: project } = await getProjectInfo({ client, throwOnError: true })
|
|
135
|
+
await updateConfig((config) => ({
|
|
136
|
+
version: 1,
|
|
137
|
+
currentProfile: project.id,
|
|
138
|
+
profiles: {
|
|
139
|
+
...config.profiles,
|
|
140
|
+
[project.id]: { apiUrl: baseUrl, projectId: project.id, session },
|
|
141
|
+
},
|
|
142
|
+
}))
|
|
143
|
+
},
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function errorText(error: unknown): string {
|
|
148
|
+
return error instanceof Error ? error.message : String(error)
|
|
149
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/** @jsxImportSource @opentui/react */
|
|
2
|
+
import { type KeyEvent, RGBA } from "@opentui/core"
|
|
3
|
+
import { useKeyboard, useTerminalDimensions } from "@opentui/react"
|
|
4
|
+
import { glyph } from "../ui/theme"
|
|
5
|
+
import { type ContextUse, contextBreakdown } from "./format"
|
|
6
|
+
import type { TuiColors } from "./theme"
|
|
7
|
+
import { BOLD } from "./ui"
|
|
8
|
+
|
|
9
|
+
/** What the room kept for the model's answer reads as, in the bar and its row. */
|
|
10
|
+
const RESERVED_TILE = "╌"
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* `/context`: what the conversation uses of its model's window, part by part. Opens centered over
|
|
14
|
+
* the screen like the palettes; esc or enter closes it.
|
|
15
|
+
*/
|
|
16
|
+
export function ContextPanel({
|
|
17
|
+
colors,
|
|
18
|
+
context,
|
|
19
|
+
modelName,
|
|
20
|
+
onClose,
|
|
21
|
+
}: {
|
|
22
|
+
readonly colors: TuiColors
|
|
23
|
+
readonly context: ContextUse | null
|
|
24
|
+
readonly modelName?: string
|
|
25
|
+
readonly onClose: () => void
|
|
26
|
+
}) {
|
|
27
|
+
const { width, height } = useTerminalDimensions()
|
|
28
|
+
useKeyboard((key: KeyEvent) => {
|
|
29
|
+
if (key.name === "escape" || key.name === "return" || (key.ctrl && key.name === "c")) {
|
|
30
|
+
onClose()
|
|
31
|
+
}
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
const boxWidth = Math.min(64, width - 4)
|
|
35
|
+
const inner = boxWidth - 6
|
|
36
|
+
// A row: its label, its tokens and share in 12 columns, then its share's tiles.
|
|
37
|
+
const labelColumns = Math.min(24, Math.max(12, inner - 12 - 12))
|
|
38
|
+
const rowTiles = Math.max(0, inner - labelColumns - 12)
|
|
39
|
+
const breakdown = context ? contextBreakdown(context, { bar: inner, row: rowTiles }) : undefined
|
|
40
|
+
const toneColor =
|
|
41
|
+
breakdown?.tone === "over"
|
|
42
|
+
? colors.red
|
|
43
|
+
: breakdown?.tone === "near"
|
|
44
|
+
? colors.amber
|
|
45
|
+
: colors.blue
|
|
46
|
+
|
|
47
|
+
const lines = breakdown ? breakdown.rows.length + breakdown.notes.length + 7 : 2
|
|
48
|
+
return (
|
|
49
|
+
<>
|
|
50
|
+
<box
|
|
51
|
+
position="absolute"
|
|
52
|
+
left={0}
|
|
53
|
+
top={0}
|
|
54
|
+
width={width}
|
|
55
|
+
height={height}
|
|
56
|
+
backgroundColor={RGBA.fromValues(0, 0, 0, 0.45)}
|
|
57
|
+
zIndex={9}
|
|
58
|
+
/>
|
|
59
|
+
<box
|
|
60
|
+
position="absolute"
|
|
61
|
+
left={Math.floor((width - boxWidth) / 2)}
|
|
62
|
+
top={Math.max(1, Math.floor((height - lines - 4) / 3))}
|
|
63
|
+
width={boxWidth}
|
|
64
|
+
backgroundColor={colors.surface}
|
|
65
|
+
flexDirection="column"
|
|
66
|
+
paddingTop={1}
|
|
67
|
+
paddingBottom={1}
|
|
68
|
+
paddingLeft={3}
|
|
69
|
+
paddingRight={3}
|
|
70
|
+
zIndex={10}
|
|
71
|
+
>
|
|
72
|
+
<box flexDirection="row" justifyContent="space-between">
|
|
73
|
+
<text fg={colors.text} attributes={BOLD}>
|
|
74
|
+
Context
|
|
75
|
+
</text>
|
|
76
|
+
<text fg={colors.faint}>esc</text>
|
|
77
|
+
</box>
|
|
78
|
+
{breakdown ? (
|
|
79
|
+
<>
|
|
80
|
+
<box flexDirection="row" justifyContent="space-between" paddingTop={1}>
|
|
81
|
+
<text wrapMode="none" flexShrink={1}>
|
|
82
|
+
<span fg={colors.text}>{breakdown.headline}</span>
|
|
83
|
+
{modelName ? <span fg={colors.faint}>{` · ${modelName}`}</span> : null}
|
|
84
|
+
</text>
|
|
85
|
+
<text fg={breakdown.tone === "quiet" ? colors.muted : toneColor} flexShrink={0}>
|
|
86
|
+
{breakdown.share}
|
|
87
|
+
</text>
|
|
88
|
+
</box>
|
|
89
|
+
<text wrapMode="none">
|
|
90
|
+
<span fg={toneColor}>{glyph.mark.repeat(breakdown.bar.used)}</span>
|
|
91
|
+
<span fg={colors.faint}>{glyph.tile.repeat(breakdown.bar.free)}</span>
|
|
92
|
+
<span fg={colors.faint}>{RESERVED_TILE.repeat(breakdown.bar.reserved)}</span>
|
|
93
|
+
</text>
|
|
94
|
+
{breakdown.warning ? (
|
|
95
|
+
<text wrapMode="none" fg={toneColor}>
|
|
96
|
+
{fit(breakdown.warning, inner)}
|
|
97
|
+
</text>
|
|
98
|
+
) : null}
|
|
99
|
+
<box flexDirection="column" paddingTop={1}>
|
|
100
|
+
{breakdown.rows.map((row) => (
|
|
101
|
+
<box key={row.label} flexDirection="row">
|
|
102
|
+
<text
|
|
103
|
+
wrapMode="none"
|
|
104
|
+
width={labelColumns}
|
|
105
|
+
fg={row.kind === "part" ? colors.text : colors.muted}
|
|
106
|
+
>
|
|
107
|
+
{fit(row.label, labelColumns - 1)}
|
|
108
|
+
</text>
|
|
109
|
+
<text wrapMode="none" width={12} fg={colors.muted}>
|
|
110
|
+
{`${row.tokens.padStart(5)} ${(row.share ?? "").padStart(4)} `}
|
|
111
|
+
</text>
|
|
112
|
+
<text wrapMode="none" fg={colors.faint}>
|
|
113
|
+
{row.kind === "free"
|
|
114
|
+
? glyph.tile
|
|
115
|
+
: row.kind === "reserved"
|
|
116
|
+
? RESERVED_TILE
|
|
117
|
+
: ""}
|
|
118
|
+
<span fg={colors.muted}>
|
|
119
|
+
{glyph.mark.repeat(Math.min(row.tiles, rowTiles))}
|
|
120
|
+
</span>
|
|
121
|
+
</text>
|
|
122
|
+
</box>
|
|
123
|
+
))}
|
|
124
|
+
</box>
|
|
125
|
+
{breakdown.notes.length > 0 ? (
|
|
126
|
+
<box flexDirection="column" paddingTop={1}>
|
|
127
|
+
{breakdown.notes.map((note) => (
|
|
128
|
+
<text key={note} wrapMode="none" fg={colors.muted}>
|
|
129
|
+
{fit(note, inner)}
|
|
130
|
+
</text>
|
|
131
|
+
))}
|
|
132
|
+
</box>
|
|
133
|
+
) : null}
|
|
134
|
+
</>
|
|
135
|
+
) : (
|
|
136
|
+
<text fg={colors.muted} paddingTop={1}>
|
|
137
|
+
Nothing yet: the context is measured after the first answer.
|
|
138
|
+
</text>
|
|
139
|
+
)}
|
|
140
|
+
</box>
|
|
141
|
+
</>
|
|
142
|
+
)
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** Text cut to `room` columns, with an ellipsis. */
|
|
146
|
+
function fit(text: string, room: number): string {
|
|
147
|
+
if (text.length <= room) return text
|
|
148
|
+
return room <= 1 ? "" : `${text.slice(0, room - 1)}…`
|
|
149
|
+
}
|