@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,176 @@
|
|
|
1
|
+
import { readFile, rename, writeFile } from "node:fs/promises"
|
|
2
|
+
import { type as osType } from "node:os"
|
|
3
|
+
import { dirname, join } from "node:path"
|
|
4
|
+
import type { ListModelsResponses } from "@sixb/client"
|
|
5
|
+
import { resolveConfigPath } from "../lib/profiles"
|
|
6
|
+
|
|
7
|
+
export type ApprovalMode = "manual" | "accept-edits" | "auto"
|
|
8
|
+
export type Place = "computer" | "cloud"
|
|
9
|
+
export type LanguageModel = ListModelsResponses[200]["language"][number]
|
|
10
|
+
export type ReasoningLevel = LanguageModel["reasoningLevels"][number]
|
|
11
|
+
|
|
12
|
+
/** What the next message is sent with. Remembered between sessions, per computer. */
|
|
13
|
+
export interface Settings {
|
|
14
|
+
/** Where a new conversation runs; a conversation keeps where it started. */
|
|
15
|
+
readonly place: Place
|
|
16
|
+
/** The mode a new conversation starts in; in a conversation, the thread's applies. */
|
|
17
|
+
readonly approvalMode: ApprovalMode
|
|
18
|
+
/** A model the person picked; absent follows the project: Auto with tiers, else its default. */
|
|
19
|
+
readonly model?: { readonly provider: string; readonly modelId: string }
|
|
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
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const DEFAULT_SETTINGS: Settings = {
|
|
30
|
+
place: "computer",
|
|
31
|
+
approvalMode: "manual",
|
|
32
|
+
continueFromWeb: true,
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export const APPROVAL_MODES: readonly {
|
|
36
|
+
readonly mode: ApprovalMode
|
|
37
|
+
readonly label: string
|
|
38
|
+
readonly description: string
|
|
39
|
+
}[] = [
|
|
40
|
+
{
|
|
41
|
+
mode: "manual",
|
|
42
|
+
label: "Ask first",
|
|
43
|
+
description: "Checks with you before each action or workflow.",
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
mode: "accept-edits",
|
|
47
|
+
label: "Allow edits",
|
|
48
|
+
description:
|
|
49
|
+
"Changes your data on its own. Asks before reaching other systems or starting workflows.",
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
mode: "auto",
|
|
53
|
+
label: "Full access",
|
|
54
|
+
description: "Runs every action and workflow without asking.",
|
|
55
|
+
},
|
|
56
|
+
]
|
|
57
|
+
|
|
58
|
+
export function approvalLabel(mode: ApprovalMode): string {
|
|
59
|
+
return APPROVAL_MODES.find((entry) => entry.mode === mode)?.label ?? mode
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** What this computer is called where the person picks where a conversation runs. */
|
|
63
|
+
export function computerName(): string {
|
|
64
|
+
return osType() === "Darwin" ? "This Mac" : "This computer"
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function placeLabel(place: Place): string {
|
|
68
|
+
return place === "computer" ? computerName() : "Cloud"
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const SETTINGS_FILE = () => join(dirname(resolveConfigPath()), "tui.json")
|
|
72
|
+
|
|
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)
|
|
111
|
+
try {
|
|
112
|
+
const stored = JSON.parse(await readFile(SETTINGS_FILE(), "utf8")) as Partial<Settings>
|
|
113
|
+
return {
|
|
114
|
+
place: stored.place === "cloud" ? "cloud" : "computer",
|
|
115
|
+
approvalMode: APPROVAL_MODES.some((entry) => entry.mode === stored.approvalMode)
|
|
116
|
+
? (stored.approvalMode as ApprovalMode)
|
|
117
|
+
: DEFAULT_SETTINGS.approvalMode,
|
|
118
|
+
...(stored.model?.provider && stored.model.modelId ? { model: stored.model } : {}),
|
|
119
|
+
...(stored.reasoning ? { reasoning: stored.reasoning } : {}),
|
|
120
|
+
continueFromWeb,
|
|
121
|
+
}
|
|
122
|
+
} catch {
|
|
123
|
+
return { ...DEFAULT_SETTINGS, continueFromWeb }
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export async function saveSettings(settings: Settings): Promise<void> {
|
|
128
|
+
const { continueFromWeb: _perFolder, ...shared } = settings
|
|
129
|
+
await writeFile(SETTINGS_FILE(), `${JSON.stringify(shared, null, 2)}\n`, { mode: 0o600 }).catch(
|
|
130
|
+
() => {}
|
|
131
|
+
)
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** The model the next message runs on, as the composer names it. */
|
|
135
|
+
export function modelLabel(
|
|
136
|
+
models: readonly LanguageModel[],
|
|
137
|
+
settings: Settings
|
|
138
|
+
): { readonly name: string; readonly reasoning?: string } {
|
|
139
|
+
const chosen = settings.model
|
|
140
|
+
? models.find(
|
|
141
|
+
(model) =>
|
|
142
|
+
model.provider === settings.model?.provider && model.modelId === settings.model.modelId
|
|
143
|
+
)
|
|
144
|
+
: undefined
|
|
145
|
+
const tiers = models.some((model) => model.tier !== undefined)
|
|
146
|
+
const model =
|
|
147
|
+
chosen ?? (tiers ? undefined : (models.find((entry) => entry.isDefault) ?? models[0]))
|
|
148
|
+
const reasoning =
|
|
149
|
+
settings.reasoning && model?.reasoningLevels.includes(settings.reasoning)
|
|
150
|
+
? settings.reasoning
|
|
151
|
+
: undefined
|
|
152
|
+
return { name: model?.name ?? "Auto", ...(reasoning ? { reasoning } : {}) }
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** What a message asks the server for: only what the person chose. */
|
|
156
|
+
export function messageSelection(
|
|
157
|
+
models: readonly LanguageModel[],
|
|
158
|
+
settings: Settings
|
|
159
|
+
): { readonly model?: { provider: string; modelId: string }; readonly reasoning?: ReasoningLevel } {
|
|
160
|
+
const chosen = settings.model
|
|
161
|
+
? models.find(
|
|
162
|
+
(model) =>
|
|
163
|
+
model.provider === settings.model?.provider && model.modelId === settings.model.modelId
|
|
164
|
+
)
|
|
165
|
+
: undefined
|
|
166
|
+
const tiers = models.some((model) => model.tier !== undefined)
|
|
167
|
+
const reasoningModel = chosen ?? (tiers ? undefined : models.find((entry) => entry.isDefault))
|
|
168
|
+
const reasoning =
|
|
169
|
+
settings.reasoning && reasoningModel?.reasoningLevels.includes(settings.reasoning)
|
|
170
|
+
? settings.reasoning
|
|
171
|
+
: undefined
|
|
172
|
+
return {
|
|
173
|
+
...(chosen ? { model: { provider: chosen.provider, modelId: chosen.modelId } } : {}),
|
|
174
|
+
...(reasoning ? { reasoning } : {}),
|
|
175
|
+
}
|
|
176
|
+
}
|
package/src/tui/slash.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// Commands typed in the composer: `/model`, `/new`. A message that names one runs it instead of
|
|
2
|
+
// reaching the agent.
|
|
3
|
+
|
|
4
|
+
/** A command typed in the composer, as `/model`. */
|
|
5
|
+
export interface SlashCommand {
|
|
6
|
+
readonly name: string
|
|
7
|
+
readonly description: string
|
|
8
|
+
run(): void
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** The commands a composer's text starts to name: all of them for a lone `/`. */
|
|
12
|
+
export function slashMatches(
|
|
13
|
+
commands: readonly SlashCommand[],
|
|
14
|
+
text: string
|
|
15
|
+
): readonly SlashCommand[] {
|
|
16
|
+
if (!text.startsWith("/") || /\s/.test(text)) return []
|
|
17
|
+
const typed = text.slice(1).toLowerCase()
|
|
18
|
+
return commands.filter((command) => command.name.startsWith(typed))
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The command a message runs when it is sent: the one chosen in the menu its text opens, the first
|
|
23
|
+
* when none was. Undefined for anything else, which is sent to the agent.
|
|
24
|
+
*/
|
|
25
|
+
export function pickSlash(
|
|
26
|
+
commands: readonly SlashCommand[],
|
|
27
|
+
text: string,
|
|
28
|
+
chosen = 0
|
|
29
|
+
): SlashCommand | undefined {
|
|
30
|
+
const matches = slashMatches(commands, text.trim())
|
|
31
|
+
return matches[Math.min(chosen, matches.length - 1)]
|
|
32
|
+
}
|
package/src/tui/theme.ts
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { palette } from "../ui/theme"
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The full-screen app's colors. It paints no background of its own: the terminal's shows through,
|
|
5
|
+
* and panels are the terminal's background with a little of its foreground mixed in, so they sit
|
|
6
|
+
* right on any theme. Blue is for what is live or chosen, amber for what waits on you.
|
|
7
|
+
*/
|
|
8
|
+
export interface TuiColors {
|
|
9
|
+
/** Always the terminal's own. */
|
|
10
|
+
readonly background: string
|
|
11
|
+
/** Panels: the composer, a user's message, a dialog. */
|
|
12
|
+
readonly surface: string
|
|
13
|
+
/** A panel's selected row. */
|
|
14
|
+
readonly raised: string
|
|
15
|
+
readonly border: string
|
|
16
|
+
readonly text: string
|
|
17
|
+
readonly muted: string
|
|
18
|
+
readonly faint: string
|
|
19
|
+
readonly blue: string
|
|
20
|
+
readonly water: readonly string[]
|
|
21
|
+
/** The wordmark's blues, palest first, deep enough to read on this background. */
|
|
22
|
+
readonly wordmark: readonly string[]
|
|
23
|
+
/** Inline code in the agent's answers. */
|
|
24
|
+
readonly code: string
|
|
25
|
+
readonly green: string
|
|
26
|
+
readonly amber: string
|
|
27
|
+
readonly red: string
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** What the terminal says its own colors are, when it answers. */
|
|
31
|
+
export interface TerminalColors {
|
|
32
|
+
readonly background: string
|
|
33
|
+
readonly foreground: string
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const night: TuiColors = {
|
|
37
|
+
background: "transparent",
|
|
38
|
+
surface: "#1a1c20",
|
|
39
|
+
raised: "#24272d",
|
|
40
|
+
border: "#2b2e35",
|
|
41
|
+
text: "#eceef2",
|
|
42
|
+
muted: "#8b919a",
|
|
43
|
+
faint: "#5a6069",
|
|
44
|
+
blue: palette.blue,
|
|
45
|
+
water: palette.water,
|
|
46
|
+
wordmark: palette.water.slice(1),
|
|
47
|
+
code: "#8fbefc",
|
|
48
|
+
green: palette.green,
|
|
49
|
+
amber: palette.amber,
|
|
50
|
+
red: palette.red,
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const day: TuiColors = {
|
|
54
|
+
background: "transparent",
|
|
55
|
+
surface: "#f2f4f7",
|
|
56
|
+
raised: "#e6e9ef",
|
|
57
|
+
border: "#dfe3e9",
|
|
58
|
+
text: "#17181c",
|
|
59
|
+
muted: "#626873",
|
|
60
|
+
faint: "#9aa0a9",
|
|
61
|
+
blue: "#007aff",
|
|
62
|
+
water: ["#a6cbfb", "#6fb0fc", "#3d95fd", "#007aff"],
|
|
63
|
+
wordmark: ["#2f8bf5", "#0a74e8", "#0062cc"],
|
|
64
|
+
code: "#0062cc",
|
|
65
|
+
green: "#1f9d48",
|
|
66
|
+
amber: "#c77700",
|
|
67
|
+
red: "#e5332a",
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* The colors for this terminal: from its own background and foreground when it reports them, else
|
|
72
|
+
* Sixb's night or day colors for the mode it reports.
|
|
73
|
+
*/
|
|
74
|
+
export function tuiColors(
|
|
75
|
+
mode: "light" | "dark" | null,
|
|
76
|
+
terminal: TerminalColors | null = null
|
|
77
|
+
): TuiColors {
|
|
78
|
+
if (!terminal) return mode === "light" ? day : night
|
|
79
|
+
const { background, foreground } = terminal
|
|
80
|
+
const dark = luminance(background) < 0.5
|
|
81
|
+
const base = dark ? night : day
|
|
82
|
+
return {
|
|
83
|
+
...base,
|
|
84
|
+
surface: mix(background, foreground, dark ? 0.07 : 0.05),
|
|
85
|
+
raised: mix(background, foreground, dark ? 0.13 : 0.1),
|
|
86
|
+
border: mix(background, foreground, dark ? 0.18 : 0.14),
|
|
87
|
+
text: foreground,
|
|
88
|
+
muted: mix(background, foreground, 0.6),
|
|
89
|
+
faint: mix(background, foreground, 0.38),
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** `amount` of `to` mixed into `from`, both `#rrggbb`. */
|
|
94
|
+
export function mix(from: string, to: string, amount: number): string {
|
|
95
|
+
const a = channels(from)
|
|
96
|
+
const b = channels(to)
|
|
97
|
+
return `#${a
|
|
98
|
+
.map((value, index) => Math.round(value + ((b[index] ?? value) - value) * amount))
|
|
99
|
+
.map((value) => value.toString(16).padStart(2, "0"))
|
|
100
|
+
.join("")}`
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function luminance(hex: string): number {
|
|
104
|
+
const [r = 0, g = 0, b = 0] = channels(hex)
|
|
105
|
+
return (0.2126 * r + 0.7152 * g + 0.0722 * b) / 255
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function channels(hex: string): number[] {
|
|
109
|
+
const value = hex.replace("#", "").slice(0, 6).padEnd(6, "0")
|
|
110
|
+
return [0, 2, 4].map((offset) => Number.parseInt(value.slice(offset, offset + 2), 16) || 0)
|
|
111
|
+
}
|