GeezerVison is showing github.com — split tui/server config (#13968) · cbarber/opencode@9d29d69
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/console/app/package.json +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 7 | 7 | "typecheck": "tsgo --noEmit", | 8 | 8 | "dev": "vite dev --host 0.0.0.0", | 9 | 9 | "dev:remote": "VITE_AUTH_URL=https://auth.dev.opencode.ai VITE_STRIPE_PUBLISHABLE_KEY=pk_test_51RtuLNE7fOCwHSD4mewwzFejyytjdGoSDK7CAvhbffwaZnPbNb2rwJICw6LTOXCmWO320fSNXvb5NzI08RZVkAxd00syfqrW7t bun sst shell --stage=dev bun dev", | 10 | | - "build": "bun ./script/generate-sitemap.ts && vite build && bun ../../opencode/script/schema.ts ./.output/public/config.json", | | 10 | + "build": "bun ./script/generate-sitemap.ts && vite build && bun ../../opencode/script/schema.ts ./.output/public/config.json ./.output/public/tui.json", | 11 | 11 | "start": "vite start" | 12 | 12 | }, | 13 | 13 | "dependencies": { | |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/script/schema.ts +53-37Lines changed: 53 additions & 37 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 2 | 2 |
| 3 | 3 | import { z } from "zod" | 4 | 4 | import { Config } from "../src/config/config" | | 5 | +import { TuiConfig } from "../src/config/tui" | | 6 | + | | 7 | +function generate(schema: z.ZodType) { | | 8 | + const result = z.toJSONSchema(schema, { | | 9 | + io: "input", // Generate input shape (treats optional().default() as not required) | | 10 | + /** | | 11 | + * We'll use the `default` values of the field as the only value in `examples`. | | 12 | + * This will ensure no docs are needed to be read, as the configuration is | | 13 | + * self-documenting. | | 14 | + * | | 15 | + * See https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-validation-00#rfc.section.9.5 | | 16 | + */ | | 17 | + override(ctx) { | | 18 | + const schema = ctx.jsonSchema | | 19 | + | | 20 | + // Preserve strictness: set additionalProperties: false for objects | | 21 | + if ( | | 22 | + schema && | | 23 | + typeof schema === "object" && | | 24 | + schema.type === "object" && | | 25 | + schema.additionalProperties === undefined | | 26 | + ) { | | 27 | + schema.additionalProperties = false | | 28 | + } | | 29 | + | | 30 | + // Add examples and default descriptions for string fields with defaults | | 31 | + if (schema && typeof schema === "object" && "type" in schema && schema.type === "string" && schema?.default) { | | 32 | + if (!schema.examples) { | | 33 | + schema.examples = [schema.default] | | 34 | + } | 5 | 35 |
| 6 | | -const file = process.argv[2] | 7 | | -console.log(file) | 8 | | - | 9 | | -const result = z.toJSONSchema(Config.Info, { | 10 | | - io: "input", // Generate input shape (treats optional().default() as not required) | 11 | | - /** | 12 | | - * We'll use the `default` values of the field as the only value in `examples`. | 13 | | - * This will ensure no docs are needed to be read, as the configuration is | 14 | | - * self-documenting. | 15 | | - * | 16 | | - * See https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-validation-00#rfc.section.9.5 | 17 | | - */ | 18 | | - override(ctx) { | 19 | | - const schema = ctx.jsonSchema | 20 | | - | 21 | | - // Preserve strictness: set additionalProperties: false for objects | 22 | | - if (schema && typeof schema === "object" && schema.type === "object" && schema.additionalProperties === undefined) { | 23 | | - schema.additionalProperties = false | 24 | | - } | 25 | | - | 26 | | - // Add examples and default descriptions for string fields with defaults | 27 | | - if (schema && typeof schema === "object" && "type" in schema && schema.type === "string" && schema?.default) { | 28 | | - if (!schema.examples) { | 29 | | - schema.examples = [schema.default] | | 36 | + schema.description = [schema.description || "", `default: \`${schema.default}\``] | | 37 | + .filter(Boolean) | | 38 | + .join("\n\n") | | 39 | + .trim() | 30 | 40 | } | | 41 | + }, | | 42 | + }) as Record<string, unknown> & { | | 43 | + allowComments?: boolean | | 44 | + allowTrailingCommas?: boolean | | 45 | + } | | 46 | + | | 47 | + // used for json lsps since config supports jsonc | | 48 | + result.allowComments = true | | 49 | + result.allowTrailingCommas = true | 31 | 50 |
| 32 | | - schema.description = [schema.description || "", `default: \`${schema.default}\``] | 33 | | - .filter(Boolean) | 34 | | - .join("\n\n") | 35 | | - .trim() | 36 | | - } | 37 | | - }, | 38 | | -}) as Record<string, unknown> & { | 39 | | - allowComments?: boolean | 40 | | - allowTrailingCommas?: boolean | | 51 | + return result | 41 | 52 | } | 42 | 53 |
| 43 | | -// used for json lsps since config supports jsonc | 44 | | -result.allowComments = true | 45 | | -result.allowTrailingCommas = true | | 54 | +const configFile = process.argv[2] | | 55 | +const tuiFile = process.argv[3] | 46 | 56 |
| 47 | | -await Bun.write(file, JSON.stringify(result, null, 2)) | | 57 | +console.log(configFile) | | 58 | +await Bun.write(configFile, JSON.stringify(generate(Config.Info), null, 2)) | | 59 | + | | 60 | +if (tuiFile) { | | 61 | + console.log(tuiFile) | | 62 | + await Bun.write(tuiFile, JSON.stringify(generate(TuiConfig.Info), null, 2)) | | 63 | +} |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/cli/cmd/tui/app.tsx +34-29Lines changed: 34 additions & 29 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -38,6 +38,8 @@ import { ArgsProvider, useArgs, type Args } from "./context/args" | 38 | 38 | import open from "open" | 39 | 39 | import { writeHeapSnapshot } from "v8" | 40 | 40 | import { PromptRefProvider, usePromptRef } from "./context/prompt" | | 41 | +import { TuiConfigProvider } from "./context/tui-config" | | 42 | +import { TuiConfig } from "@/config/tui" | 41 | 43 |
| 42 | 44 | async function getTerminalBackgroundColor(): Promise<"dark" | "light"> { | 43 | 45 | // can't set raw mode if not a TTY | @@ -104,6 +106,7 @@ import type { EventSource } from "./context/sdk" | 104 | 106 | export function tui(input: { | 105 | 107 | url: string | 106 | 108 | args: Args | | 109 | + config: TuiConfig.Info | 107 | 110 | directory?: string | 108 | 111 | fetch?: typeof fetch | 109 | 112 | headers?: RequestInit["headers"] | @@ -138,35 +141,37 @@ export function tui(input: { | 138 | 141 | <KVProvider> | 139 | 142 | <ToastProvider> | 140 | 143 | <RouteProvider> | 141 | | - <SDKProvider | 142 | | - url={input.url} | 143 | | - directory={input.directory} | 144 | | - fetch={input.fetch} | 145 | | - headers={input.headers} | 146 | | - events={input.events} | 147 | | - > | 148 | | - <SyncProvider> | 149 | | - <ThemeProvider mode={mode}> | 150 | | - <LocalProvider> | 151 | | - <KeybindProvider> | 152 | | - <PromptStashProvider> | 153 | | - <DialogProvider> | 154 | | - <CommandProvider> | 155 | | - <FrecencyProvider> | 156 | | - <PromptHistoryProvider> | 157 | | - <PromptRefProvider> | 158 | | - <App /> | 159 | | - </PromptRefProvider> | 160 | | - </PromptHistoryProvider> | 161 | | - </FrecencyProvider> | 162 | | - </CommandProvider> | 163 | | - </DialogProvider> | 164 | | - </PromptStashProvider> | 165 | | - </KeybindProvider> | 166 | | - </LocalProvider> | 167 | | - </ThemeProvider> | 168 | | - </SyncProvider> | 169 | | - </SDKProvider> | | 144 | + <TuiConfigProvider config={input.config}> | | 145 | + <SDKProvider | | 146 | + url={input.url} | | 147 | + directory={input.directory} | | 148 | + fetch={input.fetch} | | 149 | + headers={input.headers} | | 150 | + events={input.events} | | 151 | + > | | 152 | + <SyncProvider> | | 153 | + <ThemeProvider mode={mode}> | | 154 | + <LocalProvider> | | 155 | + <KeybindProvider> | | 156 | + <PromptStashProvider> | | 157 | + <DialogProvider> | | 158 | + <CommandProvider> | | 159 | + <FrecencyProvider> | | 160 | + <PromptHistoryProvider> | | 161 | + <PromptRefProvider> | | 162 | + <App /> | | 163 | + </PromptRefProvider> | | 164 | + </PromptHistoryProvider> | | 165 | + </FrecencyProvider> | | 166 | + </CommandProvider> | | 167 | + </DialogProvider> | | 168 | + </PromptStashProvider> | | 169 | + </KeybindProvider> | | 170 | + </LocalProvider> | | 171 | + </ThemeProvider> | | 172 | + </SyncProvider> | | 173 | + </SDKProvider> | | 174 | + </TuiConfigProvider> | 170 | 175 | </RouteProvider> | 171 | 176 | </ToastProvider> | 172 | 177 | </KVProvider> | |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/cli/cmd/tui/attach.ts +8Lines changed: 8 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -2,6 +2,9 @@ import { cmd } from "../cmd" | 2 | 2 | import { UI } from "@/cli/ui" | 3 | 3 | import { tui } from "./app" | 4 | 4 | import { win32DisableProcessedInput, win32InstallCtrlCGuard } from "./win32" | | 5 | +import { TuiConfig } from "@/config/tui" | | 6 | +import { Instance } from "@/project/instance" | | 7 | +import { existsSync } from "fs" | 5 | 8 |
| 6 | 9 | export const AttachCommand = cmd({ | 7 | 10 | command: "attach <url>", | @@ -63,8 +66,13 @@ export const AttachCommand = cmd({ | 63 | 66 | const auth = `Basic ${Buffer.from(`opencode:${password}`).toString("base64")}` | 64 | 67 | return { Authorization: auth } | 65 | 68 | })() | | 69 | + const config = await Instance.provide({ | | 70 | + directory: directory && existsSync(directory) ? directory : process.cwd(), | | 71 | + fn: () => TuiConfig.get(), | | 72 | + }) | 66 | 73 | await tui({ | 67 | 74 | url: args.url, | | 75 | + config, | 68 | 76 | args: { | 69 | 77 | continue: args.continue, | 70 | 78 | sessionID: args.session, | |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/cli/cmd/tui/component/dialog-command.tsx +2-3Lines changed: 2 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -10,8 +10,7 @@ import { | 10 | 10 | type ParentProps, | 11 | 11 | } from "solid-js" | 12 | 12 | import { useKeyboard } from "@opentui/solid" | 13 | | -import { useKeybind } from "@tui/context/keybind" | 14 | | -import type { KeybindsConfig } from "@opencode-ai/sdk/v2" | | 13 | +import { type KeybindKey, useKeybind } from "@tui/context/keybind" | 15 | 14 |
| 16 | 15 | type Context = ReturnType<typeof init> | 17 | 16 | const ctx = createContext<Context>() | @@ -22,7 +21,7 @@ export type Slash = { | 22 | 21 | } | 23 | 22 |
| 24 | 23 | export type CommandOption = DialogSelectOption<string> & { | 25 | | - keybind?: keyof KeybindsConfig | | 24 | + keybind?: KeybindKey | 26 | 25 | suggested?: boolean | 27 | 26 | slash?: Slash | 28 | 27 | hidden?: boolean | |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/cli/cmd/tui/component/tips.tsx +4-4Lines changed: 4 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -80,11 +80,11 @@ const TIPS = [ | 80 | 80 | "Switch to {highlight}Plan{/highlight} agent to get suggestions without making actual changes", | 81 | 81 | "Use {highlight}@agent-name{/highlight} in prompts to invoke specialized subagents", | 82 | 82 | "Press {highlight}Ctrl+X Right/Left{/highlight} to cycle through parent and child sessions", | 83 | | - "Create {highlight}opencode.json{/highlight} in project root for project-specific settings", | 84 | | - "Place settings in {highlight}~/.config/opencode/opencode.json{/highlight} for global config", | | 83 | + "Create {highlight}opencode.json{/highlight} for server settings and {highlight}tui.json{/highlight} for TUI settings", | | 84 | + "Place TUI settings in {highlight}~/.config/opencode/tui.json{/highlight} for global config", | 85 | 85 | "Add {highlight}$schema{/highlight} to your config for autocomplete in your editor", | 86 | 86 | "Configure {highlight}model{/highlight} in config to set your default model", | 87 | | - "Override any keybind in config via the {highlight}keybinds{/highlight} section", | | 87 | + "Override any keybind in {highlight}tui.json{/highlight} via the {highlight}keybinds{/highlight} section", | 88 | 88 | "Set any keybind to {highlight}none{/highlight} to disable it completely", | 89 | 89 | "Configure local or remote MCP servers in the {highlight}mcp{/highlight} config section", | 90 | 90 | "OpenCode auto-handles OAuth for remote MCP servers requiring auth", | @@ -140,7 +140,7 @@ const TIPS = [ | 140 | 140 | "Press {highlight}Ctrl+X G{/highlight} or {highlight}/timeline{/highlight} to jump to specific messages", | 141 | 141 | "Press {highlight}Ctrl+X H{/highlight} to toggle code block visibility in messages", | 142 | 142 | "Press {highlight}Ctrl+X S{/highlight} or {highlight}/status{/highlight} to see system status info", | 143 | | - "Enable {highlight}tui.scroll_acceleration{/highlight} for smooth macOS-style scrolling", | | 143 | + "Enable {highlight}scroll_acceleration{/highlight} in {highlight}tui.json{/highlight} for smooth macOS-style scrolling", | 144 | 144 | "Toggle username display in chat via command palette ({highlight}Ctrl+P{/highlight})", | 145 | 145 | "Run {highlight}docker run -it --rm ghcr.io/anomalyco/opencode{/highlight} for containerized use", | 146 | 146 | "Use {highlight}/connect{/highlight} with OpenCode Zen for curated, tested models", | |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/cli/cmd/tui/context/keybind.tsx +9-7Lines changed: 9 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | import { createMemo } from "solid-js" | 2 | | -import { useSync } from "@tui/context/sync" | 3 | 2 | import { Keybind } from "@/util/keybind" | 4 | 3 | import { pipe, mapValues } from "remeda" | 5 | | -import type { KeybindsConfig } from "@opencode-ai/sdk/v2" | | 4 | +import type { TuiConfig } from "@/config/tui" | 6 | 5 | import type { ParsedKey, Renderable } from "@opentui/core" | 7 | 6 | import { createStore } from "solid-js/store" | 8 | 7 | import { useKeyboard, useRenderer } from "@opentui/solid" | 9 | 8 | import { createSimpleContext } from "./helper" | | 9 | +import { useTuiConfig } from "./tui-config" | | 10 | + | | 11 | +export type KeybindKey = keyof NonNullable<TuiConfig.Info["keybinds"]> & string | 10 | 12 |
| 11 | 13 | export const { use: useKeybind, provider: KeybindProvider } = createSimpleContext({ | 12 | 14 | name: "Keybind", | 13 | 15 | init: () => { | 14 | | - const sync = useSync() | 15 | | - const keybinds = createMemo(() => { | | 16 | + const config = useTuiConfig() | | 17 | + const keybinds = createMemo<Record<string, Keybind.Info[]>>(() => { | 16 | 18 | return pipe( | 17 | | - sync.data.config.keybinds ?? {}, | | 19 | + (config.keybinds ?? {}) as Record<string, string>, | 18 | 20 | mapValues((value) => Keybind.parse(value)), | 19 | 21 | ) | 20 | 22 | }) | @@ -78,7 +80,7 @@ export const { use: useKeybind, provider: KeybindProvider } = createSimpleContex | 78 | 80 | } | 79 | 81 | return Keybind.fromParsedKey(evt, store.leader) | 80 | 82 | }, | 81 | | - match(key: keyof KeybindsConfig, evt: ParsedKey) { | | 83 | + match(key: KeybindKey, evt: ParsedKey) { | 82 | 84 | const keybind = keybinds()[key] | 83 | 85 | if (!keybind) return false | 84 | 86 | const parsed: Keybind.Info = result.parse(evt) | @@ -88,7 +90,7 @@ export const { use: useKeybind, provider: KeybindProvider } = createSimpleContex | 88 | 90 | } | 89 | 91 | } | 90 | 92 | }, | 91 | | - print(key: keyof KeybindsConfig) { | | 93 | + print(key: KeybindKey) { | 92 | 94 | const first = keybinds()[key]?.at(0) | 93 | 95 | if (!first) return "" | 94 | 96 | const result = Keybind.toString(first) | |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/cli/cmd/tui/context/theme.tsx +4-4Lines changed: 4 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | import { SyntaxStyle, RGBA, type TerminalColors } from "@opentui/core" | 2 | 2 | import path from "path" | 3 | 3 | import { createEffect, createMemo, onMount } from "solid-js" | 4 | | -import { useSync } from "@tui/context/sync" | 5 | 4 | import { createSimpleContext } from "./helper" | 6 | 5 | import { Glob } from "../../../../util/glob" | 7 | 6 | import aura from "./theme/aura.json" with { type: "json" } | @@ -42,6 +41,7 @@ import { useRenderer } from "@opentui/solid" | 42 | 41 | import { createStore, produce } from "solid-js/store" | 43 | 42 | import { Global } from "@/global" | 44 | 43 | import { Filesystem } from "@/util/filesystem" | | 44 | +import { useTuiConfig } from "./tui-config" | 45 | 45 |
| 46 | 46 | type ThemeColors = { | 47 | 47 | primary: RGBA | @@ -280,17 +280,17 @@ function ansiToRgba(code: number): RGBA { | 280 | 280 | export const { use: useTheme, provider: ThemeProvider } = createSimpleContext({ | 281 | 281 | name: "Theme", | 282 | 282 | init: (props: { mode: "dark" | "light" }) => { | 283 | | - const sync = useSync() | | 283 | + const config = useTuiConfig() | 284 | 284 | const kv = useKV() | 285 | 285 | const [store, setStore] = createStore({ | 286 | 286 | themes: DEFAULT_THEMES, | 287 | 287 | mode: kv.get("theme_mode", props.mode), | 288 | | - active: (sync.data.config.theme ?? kv.get("theme", "opencode")) as string, | | 288 | + active: (config.theme ?? kv.get("theme", "opencode")) as string, | 289 | 289 | ready: false, | 290 | 290 | }) | 291 | 291 |
| 292 | 292 | createEffect(() => { | 293 | | - const theme = sync.data.config.theme | | 293 | + const theme = config.theme | 294 | 294 | if (theme) setStore("active", theme) | 295 | 295 | }) | 296 | 296 |
| |
Collapse file Copy file name to clipboard +9Lines changed: 9 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +import { TuiConfig } from "@/config/tui" | | 2 | +import { createSimpleContext } from "./helper" | | 3 | + | | 4 | +export const { use: useTuiConfig, provider: TuiConfigProvider } = createSimpleContext({ | | 5 | + name: "TuiConfig", | | 6 | + init: (props: { config: TuiConfig.Info }) => { | | 7 | + return props.config | | 8 | + }, | | 9 | +}) |
|