mirror of
https://github.com/anomalyco/opencode.git
synced 2026-07-17 12:56:41 +02:00
Compare commits
30 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 650e67f1df | |||
| e545bfef1f | |||
| af5f7d0887 | |||
| 314f7c56e7 | |||
| 58ca434c78 | |||
| 70f14cccd6 | |||
| 86df4073d1 | |||
| 69117fa453 | |||
| dc01071498 | |||
| 57b04d9eb7 | |||
| 07dbc30c63 | |||
| 1ae38c90a3 | |||
| 9609c1803e | |||
| 6e0e87fb2a | |||
| c875d11959 | |||
| 08a83b7337 | |||
| 79a4e35a74 | |||
| 40ed73af17 | |||
| 74da6b1bef | |||
| c35e1a03d1 | |||
| 92d4366a20 | |||
| 17a7c824b8 | |||
| 0befc5d602 | |||
| 8355ee2061 | |||
| 62fed8d2ce | |||
| 6fbe28619c | |||
| 156cc6cffe | |||
| bcd1dddcbe | |||
| 6eaaaffcdd | |||
| 766fa521ea |
@@ -48,3 +48,4 @@
|
||||
| 2025-08-12 | 176,307 (+7,010) | 171,876 (+3,923) | 348,183 (+10,933) |
|
||||
| 2025-08-13 | 182,997 (+6,690) | 177,182 (+5,306) | 360,179 (+11,996) |
|
||||
| 2025-08-14 | 189,063 (+6,066) | 179,741 (+2,559) | 368,804 (+8,625) |
|
||||
| 2025-08-15 | 193,608 (+4,545) | 181,792 (+2,051) | 375,400 (+6,596) |
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/package.json",
|
||||
"name": "@opencode/cloud-core",
|
||||
"version": "0.5.1",
|
||||
"version": "0.5.4",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"dependencies": {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@opencode/cloud-function",
|
||||
"version": "0.5.1",
|
||||
"version": "0.5.4",
|
||||
"$schema": "https://json.schemastore.org/package.json",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@opencode/cloud-web",
|
||||
"version": "0.5.1",
|
||||
"version": "0.5.4",
|
||||
"private": true,
|
||||
"description": "",
|
||||
"type": "module",
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@
|
||||
"scripts": {
|
||||
"dev": "bun run --conditions=development packages/opencode/src/index.ts",
|
||||
"typecheck": "bun run --filter='*' typecheck",
|
||||
"stainless": "./scripts/stainless",
|
||||
"generate": "(cd packages/sdk && ./js/script/generate.ts) && (cd packages/sdk/stainless && ./generate.ts)",
|
||||
"postinstall": "./script/hooks"
|
||||
},
|
||||
"workspaces": {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@opencode/function",
|
||||
"version": "0.5.1",
|
||||
"version": "0.5.4",
|
||||
"$schema": "https://json.schemastore.org/package.json",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/package.json",
|
||||
"version": "0.5.1",
|
||||
"version": "0.5.4",
|
||||
"name": "opencode",
|
||||
"type": "module",
|
||||
"private": true,
|
||||
|
||||
@@ -13,6 +13,7 @@ export namespace Agent {
|
||||
name: z.string(),
|
||||
description: z.string().optional(),
|
||||
mode: z.union([z.literal("subagent"), z.literal("primary"), z.literal("all")]),
|
||||
builtIn: z.boolean(),
|
||||
topP: z.number().optional(),
|
||||
temperature: z.number().optional(),
|
||||
permission: z.object({
|
||||
@@ -58,6 +59,7 @@ export namespace Agent {
|
||||
options: {},
|
||||
permission: agentPermission,
|
||||
mode: "subagent",
|
||||
builtIn: true,
|
||||
},
|
||||
build: {
|
||||
name: "build",
|
||||
@@ -65,6 +67,7 @@ export namespace Agent {
|
||||
options: {},
|
||||
permission: agentPermission,
|
||||
mode: "primary",
|
||||
builtIn: true,
|
||||
},
|
||||
plan: {
|
||||
name: "plan",
|
||||
@@ -76,6 +79,7 @@ export namespace Agent {
|
||||
patch: false,
|
||||
},
|
||||
mode: "primary",
|
||||
builtIn: true,
|
||||
},
|
||||
}
|
||||
for (const [key, value] of Object.entries(cfg.agent ?? {})) {
|
||||
@@ -91,6 +95,7 @@ export namespace Agent {
|
||||
permission: agentPermission,
|
||||
options: {},
|
||||
tools: {},
|
||||
builtIn: false,
|
||||
}
|
||||
const { model, prompt, tools, description, temperature, top_p, mode, permission, ...extra } = value
|
||||
item.options = {
|
||||
|
||||
@@ -188,13 +188,17 @@ export const GithubInstallCommand = cmd({
|
||||
const info = await $`git remote get-url origin`.quiet().nothrow().text()
|
||||
// match https or git pattern
|
||||
// ie. https://github.com/sst/opencode.git
|
||||
// ie. https://github.com/sst/opencode
|
||||
// ie. git@github.com:sst/opencode.git
|
||||
const parsed = info.match(/git@github\.com:(.*)\.git/) ?? info.match(/github\.com\/(.*)\.git/)
|
||||
// ie. git@github.com:sst/opencode
|
||||
// ie. ssh://git@github.com/sst/opencode.git
|
||||
// ie. ssh://git@github.com/sst/opencode
|
||||
const parsed = info.match(/^(?:(?:https?|ssh):\/\/)?(?:git@)?github\.com[:/]([^/]+)\/([^/.]+?)(?:\.git)?$/)
|
||||
if (!parsed) {
|
||||
prompts.log.error(`Could not find git repository. Please run this command from a git repository.`)
|
||||
throw new UI.CancelledError()
|
||||
}
|
||||
const [owner, repo] = parsed[1].split("/")
|
||||
const [, owner, repo] = parsed
|
||||
return { owner, repo, root: app.path.root }
|
||||
}
|
||||
|
||||
|
||||
@@ -105,10 +105,10 @@ export const RunCommand = cmd({
|
||||
return Agent.list().then((x) => x[0])
|
||||
})()
|
||||
|
||||
const { providerID, modelID } = await (() => {
|
||||
const { providerID, modelID } = await (async () => {
|
||||
if (args.model) return Provider.parseModel(args.model)
|
||||
if (agent.model) return agent.model
|
||||
return Provider.defaultModel()
|
||||
return await Provider.defaultModel()
|
||||
})()
|
||||
|
||||
function printEvent(color: string, type: string, title: string) {
|
||||
|
||||
@@ -127,6 +127,12 @@ export namespace Config {
|
||||
if (result.keybinds?.switch_mode_reverse && !result.keybinds.switch_agent_reverse) {
|
||||
result.keybinds.switch_agent_reverse = result.keybinds.switch_mode_reverse
|
||||
}
|
||||
if (result.keybinds?.switch_agent && !result.keybinds.agent_cycle) {
|
||||
result.keybinds.agent_cycle = result.keybinds.switch_agent
|
||||
}
|
||||
if (result.keybinds?.switch_agent_reverse && !result.keybinds.agent_cycle_reverse) {
|
||||
result.keybinds.agent_cycle_reverse = result.keybinds.switch_agent_reverse
|
||||
}
|
||||
|
||||
if (!result.username) {
|
||||
const os = await import("os")
|
||||
@@ -199,15 +205,12 @@ export namespace Config {
|
||||
.object({
|
||||
leader: z.string().optional().default("ctrl+x").describe("Leader key for keybind combinations"),
|
||||
app_help: z.string().optional().default("<leader>h").describe("Show help dialog"),
|
||||
switch_mode: z.string().optional().default("none").describe("@deprecated use switch_agent. Next mode"),
|
||||
switch_mode_reverse: z
|
||||
.string()
|
||||
.optional()
|
||||
.default("none")
|
||||
.describe("@deprecated use switch_agent_reverse. Previous mode"),
|
||||
switch_agent: z.string().optional().default("tab").describe("Next agent"),
|
||||
switch_agent_reverse: z.string().optional().default("shift+tab").describe("Previous agent"),
|
||||
app_exit: z.string().optional().default("ctrl+c,<leader>q").describe("Exit the application"),
|
||||
editor_open: z.string().optional().default("<leader>e").describe("Open external editor"),
|
||||
theme_list: z.string().optional().default("<leader>t").describe("List available themes"),
|
||||
project_init: z.string().optional().default("<leader>i").describe("Create/update AGENTS.md"),
|
||||
tool_details: z.string().optional().default("<leader>d").describe("Toggle tool details"),
|
||||
thinking_blocks: z.string().optional().default("<leader>b").describe("Toggle thinking blocks"),
|
||||
session_export: z.string().optional().default("<leader>x").describe("Export session to editor"),
|
||||
session_new: z.string().optional().default("<leader>n").describe("Create a new session"),
|
||||
session_list: z.string().optional().default("<leader>l").describe("List all sessions"),
|
||||
@@ -215,19 +218,12 @@ export namespace Config {
|
||||
session_unshare: z.string().optional().default("none").describe("Unshare current session"),
|
||||
session_interrupt: z.string().optional().default("esc").describe("Interrupt current session"),
|
||||
session_compact: z.string().optional().default("<leader>c").describe("Compact the session"),
|
||||
tool_details: z.string().optional().default("<leader>d").describe("Toggle tool details"),
|
||||
thinking_blocks: z.string().optional().default("<leader>b").describe("Toggle thinking blocks"),
|
||||
model_list: z.string().optional().default("<leader>m").describe("List available models"),
|
||||
theme_list: z.string().optional().default("<leader>t").describe("List available themes"),
|
||||
file_list: z.string().optional().default("<leader>f").describe("List files"),
|
||||
file_close: z.string().optional().default("esc").describe("Close file"),
|
||||
file_search: z.string().optional().default("<leader>/").describe("Search file"),
|
||||
file_diff_toggle: z.string().optional().default("<leader>v").describe("Split/unified diff"),
|
||||
project_init: z.string().optional().default("<leader>i").describe("Create/update AGENTS.md"),
|
||||
input_clear: z.string().optional().default("ctrl+c").describe("Clear input field"),
|
||||
input_paste: z.string().optional().default("ctrl+v").describe("Paste from clipboard"),
|
||||
input_submit: z.string().optional().default("enter").describe("Submit input"),
|
||||
input_newline: z.string().optional().default("shift+enter,ctrl+j").describe("Insert newline in input"),
|
||||
session_child_cycle: z.string().optional().default("ctrl+right").describe("Cycle to next child session"),
|
||||
session_child_cycle_reverse: z
|
||||
.string()
|
||||
.optional()
|
||||
.default("ctrl+left")
|
||||
.describe("Cycle to previous child session"),
|
||||
messages_page_up: z.string().optional().default("pgup").describe("Scroll messages up by one page"),
|
||||
messages_page_down: z.string().optional().default("pgdown").describe("Scroll messages down by one page"),
|
||||
messages_half_page_up: z.string().optional().default("ctrl+alt+u").describe("Scroll messages up by half page"),
|
||||
@@ -236,22 +232,52 @@ export namespace Config {
|
||||
.optional()
|
||||
.default("ctrl+alt+d")
|
||||
.describe("Scroll messages down by half page"),
|
||||
messages_previous: z.string().optional().default("ctrl+up").describe("Navigate to previous message"),
|
||||
messages_next: z.string().optional().default("ctrl+down").describe("Navigate to next message"),
|
||||
messages_first: z.string().optional().default("ctrl+g").describe("Navigate to first message"),
|
||||
messages_last: z.string().optional().default("ctrl+alt+g").describe("Navigate to last message"),
|
||||
messages_layout_toggle: z.string().optional().default("<leader>p").describe("Toggle layout"),
|
||||
messages_copy: z.string().optional().default("<leader>y").describe("Copy message"),
|
||||
messages_revert: z.string().optional().default("none").describe("@deprecated use messages_undo. Revert message"),
|
||||
messages_undo: z.string().optional().default("<leader>u").describe("Undo message"),
|
||||
messages_redo: z.string().optional().default("<leader>r").describe("Redo message"),
|
||||
app_exit: z.string().optional().default("ctrl+c,<leader>q").describe("Exit the application"),
|
||||
model_list: z.string().optional().default("<leader>m").describe("List available models"),
|
||||
model_cycle_recent: z.string().optional().default("f2").describe("Next recent model"),
|
||||
model_cycle_recent_reverse: z.string().optional().default("shift+f2").describe("Previous recent model"),
|
||||
agent_list: z.string().optional().default("<leader>a").describe("List agents"),
|
||||
agent_cycle: z.string().optional().default("tab").describe("Next agent"),
|
||||
agent_cycle_reverse: z.string().optional().default("shift+tab").describe("Previous agent"),
|
||||
input_clear: z.string().optional().default("ctrl+c").describe("Clear input field"),
|
||||
input_paste: z.string().optional().default("ctrl+v").describe("Paste from clipboard"),
|
||||
input_submit: z.string().optional().default("enter").describe("Submit input"),
|
||||
input_newline: z.string().optional().default("shift+enter,ctrl+j").describe("Insert newline in input"),
|
||||
// Deprecated commands
|
||||
switch_mode: z.string().optional().default("none").describe("@deprecated use agent_cycle. Next mode"),
|
||||
switch_mode_reverse: z
|
||||
.string()
|
||||
.optional()
|
||||
.default("none")
|
||||
.describe("@deprecated use agent_cycle_reverse. Previous mode"),
|
||||
switch_agent: z.string().optional().default("tab").describe("@deprecated use agent_cycle. Next agent"),
|
||||
switch_agent_reverse: z
|
||||
.string()
|
||||
.optional()
|
||||
.default("shift+tab")
|
||||
.describe("@deprecated use agent_cycle_reverse. Previous agent"),
|
||||
file_list: z.string().optional().default("none").describe("@deprecated Currently not available. List files"),
|
||||
file_close: z.string().optional().default("none").describe("@deprecated Close file"),
|
||||
file_search: z.string().optional().default("none").describe("@deprecated Search file"),
|
||||
file_diff_toggle: z.string().optional().default("none").describe("@deprecated Split/unified diff"),
|
||||
messages_previous: z.string().optional().default("none").describe("@deprecated Navigate to previous message"),
|
||||
messages_next: z.string().optional().default("none").describe("@deprecated Navigate to next message"),
|
||||
messages_layout_toggle: z.string().optional().default("none").describe("@deprecated Toggle layout"),
|
||||
messages_revert: z.string().optional().default("none").describe("@deprecated use messages_undo. Revert message"),
|
||||
})
|
||||
.strict()
|
||||
.openapi({
|
||||
ref: "KeybindsConfig",
|
||||
})
|
||||
|
||||
export const TUI = z.object({
|
||||
scroll_speed: z.number().min(1).optional().default(2).describe("TUI scroll speed"),
|
||||
})
|
||||
|
||||
export const Layout = z.enum(["auto", "stretch"]).openapi({
|
||||
ref: "LayoutConfig",
|
||||
})
|
||||
@@ -262,6 +288,7 @@ export namespace Config {
|
||||
$schema: z.string().optional().describe("JSON schema reference for configuration validation"),
|
||||
theme: z.string().optional().describe("Theme name to use for the interface"),
|
||||
keybinds: Keybinds.optional().describe("Custom keybind configurations"),
|
||||
tui: TUI.optional().describe("TUI specific settings"),
|
||||
plugin: z.string().array().optional(),
|
||||
snapshot: z.boolean().optional(),
|
||||
share: z
|
||||
|
||||
@@ -94,6 +94,7 @@ export const LANGUAGE_EXTENSIONS: Record<string, string> = {
|
||||
".yml": "yaml",
|
||||
".mjs": "javascript",
|
||||
".cjs": "javascript",
|
||||
".vue": "vue",
|
||||
".zig": "zig",
|
||||
".zon": "zig",
|
||||
} as const
|
||||
|
||||
@@ -65,6 +65,67 @@ export namespace LSPServer {
|
||||
},
|
||||
}
|
||||
|
||||
export const Vue: Info = {
|
||||
id: "vue",
|
||||
extensions: [".vue"],
|
||||
root: NearestRoot([
|
||||
"tsconfig.json",
|
||||
"jsconfig.json",
|
||||
"package.json",
|
||||
"pnpm-lock.yaml",
|
||||
"yarn.lock",
|
||||
"bun.lockb",
|
||||
"bun.lock",
|
||||
"vite.config.ts",
|
||||
"vite.config.js",
|
||||
"nuxt.config.ts",
|
||||
"nuxt.config.js",
|
||||
"vue.config.js",
|
||||
]),
|
||||
async spawn(_, root) {
|
||||
let binary = Bun.which("vue-language-server")
|
||||
const args: string[] = []
|
||||
if (!binary) {
|
||||
const js = path.join(
|
||||
Global.Path.bin,
|
||||
"node_modules",
|
||||
"@vue",
|
||||
"language-server",
|
||||
"bin",
|
||||
"vue-language-server.js",
|
||||
)
|
||||
if (!(await Bun.file(js).exists())) {
|
||||
await Bun.spawn([BunProc.which(), "install", "@vue/language-server"], {
|
||||
cwd: Global.Path.bin,
|
||||
env: {
|
||||
...process.env,
|
||||
BUN_BE_BUN: "1",
|
||||
},
|
||||
stdout: "pipe",
|
||||
stderr: "pipe",
|
||||
stdin: "pipe",
|
||||
}).exited
|
||||
}
|
||||
binary = BunProc.which()
|
||||
args.push("run", js)
|
||||
}
|
||||
args.push("--stdio")
|
||||
const proc = spawn(binary, args, {
|
||||
cwd: root,
|
||||
env: {
|
||||
...process.env,
|
||||
BUN_BE_BUN: "1",
|
||||
},
|
||||
})
|
||||
return {
|
||||
process: proc,
|
||||
initialization: {
|
||||
// Leave empty; the server will auto-detect workspace TypeScript.
|
||||
},
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
export const ESLint: Info = {
|
||||
id: "eslint",
|
||||
root: NearestRoot([
|
||||
@@ -81,7 +142,7 @@ export namespace LSPServer {
|
||||
".eslintrc.json",
|
||||
"package.json",
|
||||
]),
|
||||
extensions: [".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs", ".mts", ".cts"],
|
||||
extensions: [".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs", ".mts", ".cts", ".vue"],
|
||||
async spawn(app, root) {
|
||||
const eslint = await Bun.resolve("eslint", app.path.cwd).catch(() => {})
|
||||
if (!eslint) return
|
||||
|
||||
@@ -62,7 +62,7 @@ export namespace Permission {
|
||||
async (state) => {
|
||||
for (const pending of Object.values(state.pending)) {
|
||||
for (const item of Object.values(pending)) {
|
||||
item.reject(new RejectedError(item.info.sessionID, item.info.id, item.info.callID))
|
||||
item.reject(new RejectedError(item.info.sessionID, item.info.id, item.info.callID, item.info.metadata))
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -105,7 +105,7 @@ export namespace Permission {
|
||||
}).then((x) => x.status)
|
||||
) {
|
||||
case "deny":
|
||||
throw new RejectedError(info.sessionID, info.id, info.callID)
|
||||
throw new RejectedError(info.sessionID, info.id, info.callID, info.metadata)
|
||||
case "allow":
|
||||
return
|
||||
}
|
||||
@@ -131,7 +131,7 @@ export namespace Permission {
|
||||
if (!match) return
|
||||
delete pending[input.sessionID][input.permissionID]
|
||||
if (input.response === "reject") {
|
||||
match.reject(new RejectedError(input.sessionID, input.permissionID, match.info.callID))
|
||||
match.reject(new RejectedError(input.sessionID, input.permissionID, match.info.callID, match.info.metadata))
|
||||
return
|
||||
}
|
||||
match.resolve()
|
||||
@@ -156,6 +156,7 @@ export namespace Permission {
|
||||
public readonly sessionID: string,
|
||||
public readonly permissionID: string,
|
||||
public readonly toolCallID?: string,
|
||||
public readonly metadata?: Record<string, any>,
|
||||
) {
|
||||
super(`The user rejected permission to use this specific tool call. You may try again with different parameters.`)
|
||||
}
|
||||
|
||||
@@ -248,6 +248,34 @@ export namespace Server {
|
||||
return c.json(session)
|
||||
},
|
||||
)
|
||||
.get(
|
||||
"/session/:id/children",
|
||||
describeRoute({
|
||||
description: "Get a session's children",
|
||||
operationId: "session.children",
|
||||
responses: {
|
||||
200: {
|
||||
description: "List of children",
|
||||
content: {
|
||||
"application/json": {
|
||||
schema: resolver(Session.Info.array()),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
zValidator(
|
||||
"param",
|
||||
z.object({
|
||||
id: z.string(),
|
||||
}),
|
||||
),
|
||||
async (c) => {
|
||||
const sessionID = c.req.valid("param").id
|
||||
const session = await Session.children(sessionID)
|
||||
return c.json(session)
|
||||
},
|
||||
)
|
||||
.post(
|
||||
"/session",
|
||||
describeRoute({
|
||||
@@ -265,8 +293,18 @@ export namespace Server {
|
||||
},
|
||||
},
|
||||
}),
|
||||
zValidator(
|
||||
"json",
|
||||
z
|
||||
.object({
|
||||
parentID: z.string().optional(),
|
||||
title: z.string().optional(),
|
||||
})
|
||||
.optional(),
|
||||
),
|
||||
async (c) => {
|
||||
const session = await Session.create()
|
||||
const body = c.req.valid("json") ?? {}
|
||||
const session = await Session.create(body.parentID, body.title)
|
||||
return c.json(session)
|
||||
},
|
||||
)
|
||||
@@ -1099,7 +1137,7 @@ export namespace Server {
|
||||
.post(
|
||||
"/tui/execute-command",
|
||||
describeRoute({
|
||||
description: "Execute a TUI command (e.g. switch_agent)",
|
||||
description: "Execute a TUI command (e.g. agent_cycle)",
|
||||
operationId: "tui.executeCommand",
|
||||
responses: {
|
||||
200: {
|
||||
@@ -1120,6 +1158,32 @@ export namespace Server {
|
||||
),
|
||||
async (c) => c.json(await callTui(c)),
|
||||
)
|
||||
.post(
|
||||
"/tui/show-toast",
|
||||
describeRoute({
|
||||
description: "Show a toast notification in the TUI",
|
||||
operationId: "tui.showToast",
|
||||
responses: {
|
||||
200: {
|
||||
description: "Toast notification shown successfully",
|
||||
content: {
|
||||
"application/json": {
|
||||
schema: resolver(z.boolean()),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
zValidator(
|
||||
"json",
|
||||
z.object({
|
||||
title: z.string().optional(),
|
||||
message: z.string(),
|
||||
variant: z.enum(["info", "success", "warning", "error"]),
|
||||
}),
|
||||
),
|
||||
async (c) => c.json(await callTui(c)),
|
||||
)
|
||||
.route("/tui/control", TuiRoute)
|
||||
.put(
|
||||
"/auth/:id",
|
||||
|
||||
@@ -163,12 +163,12 @@ export namespace Session {
|
||||
},
|
||||
)
|
||||
|
||||
export async function create(parentID?: string) {
|
||||
export async function create(parentID?: string, title?: string) {
|
||||
const result: Info = {
|
||||
id: Identifier.descending("session"),
|
||||
version: Installation.VERSION,
|
||||
parentID,
|
||||
title: createDefaultTitle(!!parentID),
|
||||
title: title ?? createDefaultTitle(!!parentID),
|
||||
time: {
|
||||
created: Date.now(),
|
||||
updated: Date.now(),
|
||||
@@ -1056,20 +1056,28 @@ export namespace Session {
|
||||
}
|
||||
await updatePart(part)
|
||||
const app = App.info()
|
||||
const script = `
|
||||
[[ -f ~/.zshrc ]] && source ~/.zshrc >/dev/null 2>&1 || true
|
||||
[[ -f ~/.bashrc ]] && source ~/.bashrc >/dev/null 2>&1 || true
|
||||
eval "${input.command}"
|
||||
`
|
||||
const shell = process.env["SHELL"] ?? "bash"
|
||||
const isFish = shell.includes("fish")
|
||||
const args = isFish
|
||||
? ["-c", script] // fish with just -c
|
||||
: ["-c", "-l", script]
|
||||
const shellName = path.basename(shell)
|
||||
|
||||
const scripts: Record<string, string> = {
|
||||
nu: input.command,
|
||||
fish: `eval "${input.command}"`,
|
||||
}
|
||||
|
||||
const script =
|
||||
scripts[shellName] ??
|
||||
`[[ -f ~/.zshenv ]] && source ~/.zshenv >/dev/null 2>&1 || true
|
||||
[[ -f "\${ZDOTDIR:-$HOME}/.zshrc" ]] && source "\${ZDOTDIR:-$HOME}/.zshrc" >/dev/null 2>&1 || true
|
||||
[[ -f ~/.bashrc ]] && source ~/.bashrc >/dev/null 2>&1 || true
|
||||
eval "${input.command}"`
|
||||
|
||||
const isFishOrNu = shellName === "fish" || shellName === "nu"
|
||||
const args = isFishOrNu ? ["-c", script] : ["-c", "-l", script]
|
||||
|
||||
const proc = spawn(shell, args, {
|
||||
cwd: app.path.cwd,
|
||||
signal: abort.signal,
|
||||
stdio: ["ignore", "pipe", "pipe"],
|
||||
env: {
|
||||
...process.env,
|
||||
TERM: "dumb",
|
||||
@@ -1262,6 +1270,7 @@ export namespace Session {
|
||||
status: "error",
|
||||
input: value.input,
|
||||
error: (value.error as any).toString(),
|
||||
metadata: value.error instanceof Permission.RejectedError ? value.error.metadata : undefined,
|
||||
time: {
|
||||
start: match.state.time.start,
|
||||
end: Date.now(),
|
||||
|
||||
@@ -64,6 +64,7 @@ export namespace MessageV2 {
|
||||
status: z.literal("error"),
|
||||
input: z.record(z.any()),
|
||||
error: z.string(),
|
||||
metadata: z.record(z.any()).optional(),
|
||||
time: z.object({
|
||||
start: z.number(),
|
||||
end: z.number(),
|
||||
|
||||
@@ -23,11 +23,11 @@ export const TaskTool = Tool.define("task", async () => {
|
||||
subagent_type: z.string().describe("The type of specialized agent to use for this task"),
|
||||
}),
|
||||
async execute(params, ctx) {
|
||||
const session = await Session.create(ctx.sessionID)
|
||||
const msg = await Session.getMessage(ctx.sessionID, ctx.messageID)
|
||||
if (msg.info.role !== "assistant") throw new Error("Not an assistant message")
|
||||
const agent = await Agent.get(params.subagent_type)
|
||||
if (!agent) throw new Error(`Unknown agent type: ${params.subagent_type} is not a valid agent type`)
|
||||
const session = await Session.create(ctx.sessionID, params.description + ` (@${agent.name} subagent)`)
|
||||
const msg = await Session.getMessage(ctx.sessionID, ctx.messageID)
|
||||
if (msg.info.role !== "assistant") throw new Error("Not an assistant message")
|
||||
const messageID = Identifier.ascending("message")
|
||||
const parts: Record<string, MessageV2.ToolPart> = {}
|
||||
const unsub = Bus.subscribe(MessageV2.Event.PartUpdated, async (evt) => {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/package.json",
|
||||
"name": "@opencode-ai/plugin",
|
||||
"version": "0.5.1",
|
||||
"version": "0.5.4",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"typecheck": "tsc --noEmit"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
configured_endpoints: 36
|
||||
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/opencode%2Fopencode-a881262c7de4ab59bdfbfc6e30a23c47dee465d7270ffb867b760b0103aff8ed.yml
|
||||
openapi_spec_hash: 7dbb6f96f5c26a25c849e50298f58586
|
||||
config_hash: 8d85a768523cff92b85ef06c443d49fa
|
||||
configured_endpoints: 39
|
||||
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/opencode%2Fopencode-e4b6496e5f2c68fa8b3ea1b88e40041eaf5ce2652001344df80bf130675d1766.yml
|
||||
openapi_spec_hash: df474311dc9e4a89cd483bd8b8d971d8
|
||||
config_hash: eab3723c4c2232a6ba1821151259d6da
|
||||
|
||||
@@ -110,12 +110,14 @@ Response Types:
|
||||
|
||||
Methods:
|
||||
|
||||
- <code title="post /session">client.Session.<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go#SessionService.New">New</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>) (<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go">opencode</a>.<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go#Session">Session</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
|
||||
- <code title="post /session">client.Session.<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go#SessionService.New">New</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, body <a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go">opencode</a>.<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go#SessionNewParams">SessionNewParams</a>) (<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go">opencode</a>.<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go#Session">Session</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
|
||||
- <code title="patch /session/{id}">client.Session.<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go#SessionService.Update">Update</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, id <a href="https://pkg.go.dev/builtin#string">string</a>, body <a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go">opencode</a>.<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go#SessionUpdateParams">SessionUpdateParams</a>) (<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go">opencode</a>.<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go#Session">Session</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
|
||||
- <code title="get /session">client.Session.<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go#SessionService.List">List</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>) ([]<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go">opencode</a>.<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go#Session">Session</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
|
||||
- <code title="delete /session/{id}">client.Session.<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go#SessionService.Delete">Delete</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, id <a href="https://pkg.go.dev/builtin#string">string</a>) (<a href="https://pkg.go.dev/builtin#bool">bool</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
|
||||
- <code title="post /session/{id}/abort">client.Session.<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go#SessionService.Abort">Abort</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, id <a href="https://pkg.go.dev/builtin#string">string</a>) (<a href="https://pkg.go.dev/builtin#bool">bool</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
|
||||
- <code title="post /session/{id}/message">client.Session.<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go#SessionService.Chat">Chat</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, id <a href="https://pkg.go.dev/builtin#string">string</a>, body <a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go">opencode</a>.<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go#SessionChatParams">SessionChatParams</a>) (<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go">opencode</a>.<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go#AssistantMessage">AssistantMessage</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
|
||||
- <code title="get /session/{id}/children">client.Session.<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go#SessionService.Children">Children</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, id <a href="https://pkg.go.dev/builtin#string">string</a>) ([]<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go">opencode</a>.<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go#Session">Session</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
|
||||
- <code title="get /session/{id}">client.Session.<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go#SessionService.Get">Get</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, id <a href="https://pkg.go.dev/builtin#string">string</a>) (<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go">opencode</a>.<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go#Session">Session</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
|
||||
- <code title="post /session/{id}/init">client.Session.<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go#SessionService.Init">Init</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, id <a href="https://pkg.go.dev/builtin#string">string</a>, body <a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go">opencode</a>.<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go#SessionInitParams">SessionInitParams</a>) (<a href="https://pkg.go.dev/builtin#bool">bool</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
|
||||
- <code title="get /session/{id}/message/{messageID}">client.Session.<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go#SessionService.Message">Message</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, id <a href="https://pkg.go.dev/builtin#string">string</a>, messageID <a href="https://pkg.go.dev/builtin#string">string</a>) (<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go">opencode</a>.<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go#SessionMessageResponse">SessionMessageResponse</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
|
||||
- <code title="get /session/{id}/message">client.Session.<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go#SessionService.Messages">Messages</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, id <a href="https://pkg.go.dev/builtin#string">string</a>) ([]<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go">opencode</a>.<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go#SessionMessagesResponse">SessionMessagesResponse</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
|
||||
@@ -147,4 +149,5 @@ Methods:
|
||||
- <code title="post /tui/open-models">client.Tui.<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go#TuiService.OpenModels">OpenModels</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>) (<a href="https://pkg.go.dev/builtin#bool">bool</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
|
||||
- <code title="post /tui/open-sessions">client.Tui.<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go#TuiService.OpenSessions">OpenSessions</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>) (<a href="https://pkg.go.dev/builtin#bool">bool</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
|
||||
- <code title="post /tui/open-themes">client.Tui.<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go#TuiService.OpenThemes">OpenThemes</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>) (<a href="https://pkg.go.dev/builtin#bool">bool</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
|
||||
- <code title="post /tui/show-toast">client.Tui.<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go#TuiService.ShowToast">ShowToast</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, body <a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go">opencode</a>.<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go#TuiShowToastParams">TuiShowToastParams</a>) (<a href="https://pkg.go.dev/builtin#bool">bool</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
|
||||
- <code title="post /tui/submit-prompt">client.Tui.<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go#TuiService.SubmitPrompt">SubmitPrompt</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>) (<a href="https://pkg.go.dev/builtin#bool">bool</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
|
||||
|
||||
@@ -72,6 +72,7 @@ func (r *AppService) Providers(ctx context.Context, opts ...option.RequestOption
|
||||
}
|
||||
|
||||
type Agent struct {
|
||||
BuiltIn bool `json:"builtIn,required"`
|
||||
Mode AgentMode `json:"mode,required"`
|
||||
Name string `json:"name,required"`
|
||||
Options map[string]interface{} `json:"options,required"`
|
||||
@@ -87,6 +88,7 @@ type Agent struct {
|
||||
|
||||
// agentJSON contains the JSON metadata for the struct [Agent]
|
||||
type agentJSON struct {
|
||||
BuiltIn apijson.Field
|
||||
Mode apijson.Field
|
||||
Name apijson.Field
|
||||
Options apijson.Field
|
||||
|
||||
+100
-54
@@ -80,6 +80,8 @@ type Config struct {
|
||||
Snapshot bool `json:"snapshot"`
|
||||
// Theme name to use for the interface
|
||||
Theme string `json:"theme"`
|
||||
// TUI specific settings
|
||||
Tui ConfigTui `json:"tui"`
|
||||
// Custom username to display in conversations instead of system username
|
||||
Username string `json:"username"`
|
||||
JSON configJSON `json:"-"`
|
||||
@@ -108,6 +110,7 @@ type configJSON struct {
|
||||
SmallModel apijson.Field
|
||||
Snapshot apijson.Field
|
||||
Theme apijson.Field
|
||||
Tui apijson.Field
|
||||
Username apijson.Field
|
||||
raw string
|
||||
ExtraFields map[string]apijson.Field
|
||||
@@ -1654,20 +1657,48 @@ func (r ConfigShare) IsKnown() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// TUI specific settings
|
||||
type ConfigTui struct {
|
||||
// TUI scroll speed
|
||||
ScrollSpeed float64 `json:"scroll_speed,required"`
|
||||
JSON configTuiJSON `json:"-"`
|
||||
}
|
||||
|
||||
// configTuiJSON contains the JSON metadata for the struct [ConfigTui]
|
||||
type configTuiJSON struct {
|
||||
ScrollSpeed apijson.Field
|
||||
raw string
|
||||
ExtraFields map[string]apijson.Field
|
||||
}
|
||||
|
||||
func (r *ConfigTui) UnmarshalJSON(data []byte) (err error) {
|
||||
return apijson.UnmarshalRoot(data, r)
|
||||
}
|
||||
|
||||
func (r configTuiJSON) RawJSON() string {
|
||||
return r.raw
|
||||
}
|
||||
|
||||
type KeybindsConfig struct {
|
||||
// Next agent
|
||||
AgentCycle string `json:"agent_cycle,required"`
|
||||
// Previous agent
|
||||
AgentCycleReverse string `json:"agent_cycle_reverse,required"`
|
||||
// List agents
|
||||
AgentList string `json:"agent_list,required"`
|
||||
// Exit the application
|
||||
AppExit string `json:"app_exit,required"`
|
||||
// Show help dialog
|
||||
AppHelp string `json:"app_help,required"`
|
||||
// Open external editor
|
||||
EditorOpen string `json:"editor_open,required"`
|
||||
// Close file
|
||||
// @deprecated Close file
|
||||
FileClose string `json:"file_close,required"`
|
||||
// Split/unified diff
|
||||
// @deprecated Split/unified diff
|
||||
FileDiffToggle string `json:"file_diff_toggle,required"`
|
||||
// List files
|
||||
// @deprecated Currently not available. List files
|
||||
FileList string `json:"file_list,required"`
|
||||
// Search file
|
||||
// @deprecated Search file
|
||||
FileSearch string `json:"file_search,required"`
|
||||
// Clear input field
|
||||
InputClear string `json:"input_clear,required"`
|
||||
@@ -1689,15 +1720,15 @@ type KeybindsConfig struct {
|
||||
MessagesHalfPageUp string `json:"messages_half_page_up,required"`
|
||||
// Navigate to last message
|
||||
MessagesLast string `json:"messages_last,required"`
|
||||
// Toggle layout
|
||||
// @deprecated Toggle layout
|
||||
MessagesLayoutToggle string `json:"messages_layout_toggle,required"`
|
||||
// Navigate to next message
|
||||
// @deprecated Navigate to next message
|
||||
MessagesNext string `json:"messages_next,required"`
|
||||
// Scroll messages down by one page
|
||||
MessagesPageDown string `json:"messages_page_down,required"`
|
||||
// Scroll messages up by one page
|
||||
MessagesPageUp string `json:"messages_page_up,required"`
|
||||
// Navigate to previous message
|
||||
// @deprecated Navigate to previous message
|
||||
MessagesPrevious string `json:"messages_previous,required"`
|
||||
// Redo message
|
||||
MessagesRedo string `json:"messages_redo,required"`
|
||||
@@ -1705,10 +1736,18 @@ type KeybindsConfig struct {
|
||||
MessagesRevert string `json:"messages_revert,required"`
|
||||
// Undo message
|
||||
MessagesUndo string `json:"messages_undo,required"`
|
||||
// Next recent model
|
||||
ModelCycleRecent string `json:"model_cycle_recent,required"`
|
||||
// Previous recent model
|
||||
ModelCycleRecentReverse string `json:"model_cycle_recent_reverse,required"`
|
||||
// List available models
|
||||
ModelList string `json:"model_list,required"`
|
||||
// Create/update AGENTS.md
|
||||
ProjectInit string `json:"project_init,required"`
|
||||
// Cycle to next child session
|
||||
SessionChildCycle string `json:"session_child_cycle,required"`
|
||||
// Cycle to previous child session
|
||||
SessionChildCycleReverse string `json:"session_child_cycle_reverse,required"`
|
||||
// Compact the session
|
||||
SessionCompact string `json:"session_compact,required"`
|
||||
// Export session to editor
|
||||
@@ -1723,13 +1762,13 @@ type KeybindsConfig struct {
|
||||
SessionShare string `json:"session_share,required"`
|
||||
// Unshare current session
|
||||
SessionUnshare string `json:"session_unshare,required"`
|
||||
// Next agent
|
||||
// @deprecated use agent_cycle. Next agent
|
||||
SwitchAgent string `json:"switch_agent,required"`
|
||||
// Previous agent
|
||||
// @deprecated use agent_cycle_reverse. Previous agent
|
||||
SwitchAgentReverse string `json:"switch_agent_reverse,required"`
|
||||
// @deprecated use switch_agent. Next mode
|
||||
// @deprecated use agent_cycle. Next mode
|
||||
SwitchMode string `json:"switch_mode,required"`
|
||||
// @deprecated use switch_agent_reverse. Previous mode
|
||||
// @deprecated use agent_cycle_reverse. Previous mode
|
||||
SwitchModeReverse string `json:"switch_mode_reverse,required"`
|
||||
// List available themes
|
||||
ThemeList string `json:"theme_list,required"`
|
||||
@@ -1742,49 +1781,56 @@ type KeybindsConfig struct {
|
||||
|
||||
// keybindsConfigJSON contains the JSON metadata for the struct [KeybindsConfig]
|
||||
type keybindsConfigJSON struct {
|
||||
AppExit apijson.Field
|
||||
AppHelp apijson.Field
|
||||
EditorOpen apijson.Field
|
||||
FileClose apijson.Field
|
||||
FileDiffToggle apijson.Field
|
||||
FileList apijson.Field
|
||||
FileSearch apijson.Field
|
||||
InputClear apijson.Field
|
||||
InputNewline apijson.Field
|
||||
InputPaste apijson.Field
|
||||
InputSubmit apijson.Field
|
||||
Leader apijson.Field
|
||||
MessagesCopy apijson.Field
|
||||
MessagesFirst apijson.Field
|
||||
MessagesHalfPageDown apijson.Field
|
||||
MessagesHalfPageUp apijson.Field
|
||||
MessagesLast apijson.Field
|
||||
MessagesLayoutToggle apijson.Field
|
||||
MessagesNext apijson.Field
|
||||
MessagesPageDown apijson.Field
|
||||
MessagesPageUp apijson.Field
|
||||
MessagesPrevious apijson.Field
|
||||
MessagesRedo apijson.Field
|
||||
MessagesRevert apijson.Field
|
||||
MessagesUndo apijson.Field
|
||||
ModelList apijson.Field
|
||||
ProjectInit apijson.Field
|
||||
SessionCompact apijson.Field
|
||||
SessionExport apijson.Field
|
||||
SessionInterrupt apijson.Field
|
||||
SessionList apijson.Field
|
||||
SessionNew apijson.Field
|
||||
SessionShare apijson.Field
|
||||
SessionUnshare apijson.Field
|
||||
SwitchAgent apijson.Field
|
||||
SwitchAgentReverse apijson.Field
|
||||
SwitchMode apijson.Field
|
||||
SwitchModeReverse apijson.Field
|
||||
ThemeList apijson.Field
|
||||
ThinkingBlocks apijson.Field
|
||||
ToolDetails apijson.Field
|
||||
raw string
|
||||
ExtraFields map[string]apijson.Field
|
||||
AgentCycle apijson.Field
|
||||
AgentCycleReverse apijson.Field
|
||||
AgentList apijson.Field
|
||||
AppExit apijson.Field
|
||||
AppHelp apijson.Field
|
||||
EditorOpen apijson.Field
|
||||
FileClose apijson.Field
|
||||
FileDiffToggle apijson.Field
|
||||
FileList apijson.Field
|
||||
FileSearch apijson.Field
|
||||
InputClear apijson.Field
|
||||
InputNewline apijson.Field
|
||||
InputPaste apijson.Field
|
||||
InputSubmit apijson.Field
|
||||
Leader apijson.Field
|
||||
MessagesCopy apijson.Field
|
||||
MessagesFirst apijson.Field
|
||||
MessagesHalfPageDown apijson.Field
|
||||
MessagesHalfPageUp apijson.Field
|
||||
MessagesLast apijson.Field
|
||||
MessagesLayoutToggle apijson.Field
|
||||
MessagesNext apijson.Field
|
||||
MessagesPageDown apijson.Field
|
||||
MessagesPageUp apijson.Field
|
||||
MessagesPrevious apijson.Field
|
||||
MessagesRedo apijson.Field
|
||||
MessagesRevert apijson.Field
|
||||
MessagesUndo apijson.Field
|
||||
ModelCycleRecent apijson.Field
|
||||
ModelCycleRecentReverse apijson.Field
|
||||
ModelList apijson.Field
|
||||
ProjectInit apijson.Field
|
||||
SessionChildCycle apijson.Field
|
||||
SessionChildCycleReverse apijson.Field
|
||||
SessionCompact apijson.Field
|
||||
SessionExport apijson.Field
|
||||
SessionInterrupt apijson.Field
|
||||
SessionList apijson.Field
|
||||
SessionNew apijson.Field
|
||||
SessionShare apijson.Field
|
||||
SessionUnshare apijson.Field
|
||||
SwitchAgent apijson.Field
|
||||
SwitchAgentReverse apijson.Field
|
||||
SwitchMode apijson.Field
|
||||
SwitchModeReverse apijson.Field
|
||||
ThemeList apijson.Field
|
||||
ThinkingBlocks apijson.Field
|
||||
ToolDetails apijson.Field
|
||||
raw string
|
||||
ExtraFields map[string]apijson.Field
|
||||
}
|
||||
|
||||
func (r *KeybindsConfig) UnmarshalJSON(data []byte) (err error) {
|
||||
|
||||
+121
-123
@@ -54,13 +54,13 @@ type EventListResponse struct {
|
||||
// [EventListResponseEventMessageRemovedProperties],
|
||||
// [EventListResponseEventMessagePartUpdatedProperties],
|
||||
// [EventListResponseEventMessagePartRemovedProperties],
|
||||
// [EventListResponseEventStorageWriteProperties],
|
||||
// [EventListResponseEventFileEditedProperties], [interface{}], [Permission],
|
||||
// [EventListResponseEventStorageWriteProperties], [Permission],
|
||||
// [EventListResponseEventPermissionRepliedProperties],
|
||||
// [EventListResponseEventFileEditedProperties],
|
||||
// [EventListResponseEventSessionUpdatedProperties],
|
||||
// [EventListResponseEventSessionDeletedProperties],
|
||||
// [EventListResponseEventSessionIdleProperties],
|
||||
// [EventListResponseEventSessionErrorProperties],
|
||||
// [EventListResponseEventSessionErrorProperties], [interface{}],
|
||||
// [EventListResponseEventFileWatcherUpdatedProperties],
|
||||
// [EventListResponseEventIdeInstalledProperties].
|
||||
Properties interface{} `json:"properties,required"`
|
||||
@@ -100,12 +100,11 @@ func (r *EventListResponse) UnmarshalJSON(data []byte) (err error) {
|
||||
// [EventListResponseEventMessageUpdated], [EventListResponseEventMessageRemoved],
|
||||
// [EventListResponseEventMessagePartUpdated],
|
||||
// [EventListResponseEventMessagePartRemoved],
|
||||
// [EventListResponseEventStorageWrite], [EventListResponseEventFileEdited],
|
||||
// [EventListResponseEventServerConnected],
|
||||
// [EventListResponseEventPermissionUpdated],
|
||||
// [EventListResponseEventPermissionReplied],
|
||||
// [EventListResponseEventStorageWrite], [EventListResponseEventPermissionUpdated],
|
||||
// [EventListResponseEventPermissionReplied], [EventListResponseEventFileEdited],
|
||||
// [EventListResponseEventSessionUpdated], [EventListResponseEventSessionDeleted],
|
||||
// [EventListResponseEventSessionIdle], [EventListResponseEventSessionError],
|
||||
// [EventListResponseEventServerConnected],
|
||||
// [EventListResponseEventFileWatcherUpdated],
|
||||
// [EventListResponseEventIdeInstalled].
|
||||
func (r EventListResponse) AsUnion() EventListResponseUnion {
|
||||
@@ -117,12 +116,11 @@ func (r EventListResponse) AsUnion() EventListResponseUnion {
|
||||
// [EventListResponseEventMessageUpdated], [EventListResponseEventMessageRemoved],
|
||||
// [EventListResponseEventMessagePartUpdated],
|
||||
// [EventListResponseEventMessagePartRemoved],
|
||||
// [EventListResponseEventStorageWrite], [EventListResponseEventFileEdited],
|
||||
// [EventListResponseEventServerConnected],
|
||||
// [EventListResponseEventPermissionUpdated],
|
||||
// [EventListResponseEventPermissionReplied],
|
||||
// [EventListResponseEventStorageWrite], [EventListResponseEventPermissionUpdated],
|
||||
// [EventListResponseEventPermissionReplied], [EventListResponseEventFileEdited],
|
||||
// [EventListResponseEventSessionUpdated], [EventListResponseEventSessionDeleted],
|
||||
// [EventListResponseEventSessionIdle], [EventListResponseEventSessionError],
|
||||
// [EventListResponseEventServerConnected],
|
||||
// [EventListResponseEventFileWatcherUpdated] or
|
||||
// [EventListResponseEventIdeInstalled].
|
||||
type EventListResponseUnion interface {
|
||||
@@ -168,16 +166,6 @@ func init() {
|
||||
Type: reflect.TypeOf(EventListResponseEventStorageWrite{}),
|
||||
DiscriminatorValue: "storage.write",
|
||||
},
|
||||
apijson.UnionVariant{
|
||||
TypeFilter: gjson.JSON,
|
||||
Type: reflect.TypeOf(EventListResponseEventFileEdited{}),
|
||||
DiscriminatorValue: "file.edited",
|
||||
},
|
||||
apijson.UnionVariant{
|
||||
TypeFilter: gjson.JSON,
|
||||
Type: reflect.TypeOf(EventListResponseEventServerConnected{}),
|
||||
DiscriminatorValue: "server.connected",
|
||||
},
|
||||
apijson.UnionVariant{
|
||||
TypeFilter: gjson.JSON,
|
||||
Type: reflect.TypeOf(EventListResponseEventPermissionUpdated{}),
|
||||
@@ -188,6 +176,11 @@ func init() {
|
||||
Type: reflect.TypeOf(EventListResponseEventPermissionReplied{}),
|
||||
DiscriminatorValue: "permission.replied",
|
||||
},
|
||||
apijson.UnionVariant{
|
||||
TypeFilter: gjson.JSON,
|
||||
Type: reflect.TypeOf(EventListResponseEventFileEdited{}),
|
||||
DiscriminatorValue: "file.edited",
|
||||
},
|
||||
apijson.UnionVariant{
|
||||
TypeFilter: gjson.JSON,
|
||||
Type: reflect.TypeOf(EventListResponseEventSessionUpdated{}),
|
||||
@@ -208,6 +201,11 @@ func init() {
|
||||
Type: reflect.TypeOf(EventListResponseEventSessionError{}),
|
||||
DiscriminatorValue: "session.error",
|
||||
},
|
||||
apijson.UnionVariant{
|
||||
TypeFilter: gjson.JSON,
|
||||
Type: reflect.TypeOf(EventListResponseEventServerConnected{}),
|
||||
DiscriminatorValue: "server.connected",
|
||||
},
|
||||
apijson.UnionVariant{
|
||||
TypeFilter: gjson.JSON,
|
||||
Type: reflect.TypeOf(EventListResponseEventFileWatcherUpdated{}),
|
||||
@@ -651,105 +649,6 @@ func (r EventListResponseEventStorageWriteType) IsKnown() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
type EventListResponseEventFileEdited struct {
|
||||
Properties EventListResponseEventFileEditedProperties `json:"properties,required"`
|
||||
Type EventListResponseEventFileEditedType `json:"type,required"`
|
||||
JSON eventListResponseEventFileEditedJSON `json:"-"`
|
||||
}
|
||||
|
||||
// eventListResponseEventFileEditedJSON contains the JSON metadata for the struct
|
||||
// [EventListResponseEventFileEdited]
|
||||
type eventListResponseEventFileEditedJSON struct {
|
||||
Properties apijson.Field
|
||||
Type apijson.Field
|
||||
raw string
|
||||
ExtraFields map[string]apijson.Field
|
||||
}
|
||||
|
||||
func (r *EventListResponseEventFileEdited) UnmarshalJSON(data []byte) (err error) {
|
||||
return apijson.UnmarshalRoot(data, r)
|
||||
}
|
||||
|
||||
func (r eventListResponseEventFileEditedJSON) RawJSON() string {
|
||||
return r.raw
|
||||
}
|
||||
|
||||
func (r EventListResponseEventFileEdited) implementsEventListResponse() {}
|
||||
|
||||
type EventListResponseEventFileEditedProperties struct {
|
||||
File string `json:"file,required"`
|
||||
JSON eventListResponseEventFileEditedPropertiesJSON `json:"-"`
|
||||
}
|
||||
|
||||
// eventListResponseEventFileEditedPropertiesJSON contains the JSON metadata for
|
||||
// the struct [EventListResponseEventFileEditedProperties]
|
||||
type eventListResponseEventFileEditedPropertiesJSON struct {
|
||||
File apijson.Field
|
||||
raw string
|
||||
ExtraFields map[string]apijson.Field
|
||||
}
|
||||
|
||||
func (r *EventListResponseEventFileEditedProperties) UnmarshalJSON(data []byte) (err error) {
|
||||
return apijson.UnmarshalRoot(data, r)
|
||||
}
|
||||
|
||||
func (r eventListResponseEventFileEditedPropertiesJSON) RawJSON() string {
|
||||
return r.raw
|
||||
}
|
||||
|
||||
type EventListResponseEventFileEditedType string
|
||||
|
||||
const (
|
||||
EventListResponseEventFileEditedTypeFileEdited EventListResponseEventFileEditedType = "file.edited"
|
||||
)
|
||||
|
||||
func (r EventListResponseEventFileEditedType) IsKnown() bool {
|
||||
switch r {
|
||||
case EventListResponseEventFileEditedTypeFileEdited:
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
type EventListResponseEventServerConnected struct {
|
||||
Properties interface{} `json:"properties,required"`
|
||||
Type EventListResponseEventServerConnectedType `json:"type,required"`
|
||||
JSON eventListResponseEventServerConnectedJSON `json:"-"`
|
||||
}
|
||||
|
||||
// eventListResponseEventServerConnectedJSON contains the JSON metadata for the
|
||||
// struct [EventListResponseEventServerConnected]
|
||||
type eventListResponseEventServerConnectedJSON struct {
|
||||
Properties apijson.Field
|
||||
Type apijson.Field
|
||||
raw string
|
||||
ExtraFields map[string]apijson.Field
|
||||
}
|
||||
|
||||
func (r *EventListResponseEventServerConnected) UnmarshalJSON(data []byte) (err error) {
|
||||
return apijson.UnmarshalRoot(data, r)
|
||||
}
|
||||
|
||||
func (r eventListResponseEventServerConnectedJSON) RawJSON() string {
|
||||
return r.raw
|
||||
}
|
||||
|
||||
func (r EventListResponseEventServerConnected) implementsEventListResponse() {}
|
||||
|
||||
type EventListResponseEventServerConnectedType string
|
||||
|
||||
const (
|
||||
EventListResponseEventServerConnectedTypeServerConnected EventListResponseEventServerConnectedType = "server.connected"
|
||||
)
|
||||
|
||||
func (r EventListResponseEventServerConnectedType) IsKnown() bool {
|
||||
switch r {
|
||||
case EventListResponseEventServerConnectedTypeServerConnected:
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
type EventListResponseEventPermissionUpdated struct {
|
||||
Properties Permission `json:"properties,required"`
|
||||
Type EventListResponseEventPermissionUpdatedType `json:"type,required"`
|
||||
@@ -853,6 +752,66 @@ func (r EventListResponseEventPermissionRepliedType) IsKnown() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
type EventListResponseEventFileEdited struct {
|
||||
Properties EventListResponseEventFileEditedProperties `json:"properties,required"`
|
||||
Type EventListResponseEventFileEditedType `json:"type,required"`
|
||||
JSON eventListResponseEventFileEditedJSON `json:"-"`
|
||||
}
|
||||
|
||||
// eventListResponseEventFileEditedJSON contains the JSON metadata for the struct
|
||||
// [EventListResponseEventFileEdited]
|
||||
type eventListResponseEventFileEditedJSON struct {
|
||||
Properties apijson.Field
|
||||
Type apijson.Field
|
||||
raw string
|
||||
ExtraFields map[string]apijson.Field
|
||||
}
|
||||
|
||||
func (r *EventListResponseEventFileEdited) UnmarshalJSON(data []byte) (err error) {
|
||||
return apijson.UnmarshalRoot(data, r)
|
||||
}
|
||||
|
||||
func (r eventListResponseEventFileEditedJSON) RawJSON() string {
|
||||
return r.raw
|
||||
}
|
||||
|
||||
func (r EventListResponseEventFileEdited) implementsEventListResponse() {}
|
||||
|
||||
type EventListResponseEventFileEditedProperties struct {
|
||||
File string `json:"file,required"`
|
||||
JSON eventListResponseEventFileEditedPropertiesJSON `json:"-"`
|
||||
}
|
||||
|
||||
// eventListResponseEventFileEditedPropertiesJSON contains the JSON metadata for
|
||||
// the struct [EventListResponseEventFileEditedProperties]
|
||||
type eventListResponseEventFileEditedPropertiesJSON struct {
|
||||
File apijson.Field
|
||||
raw string
|
||||
ExtraFields map[string]apijson.Field
|
||||
}
|
||||
|
||||
func (r *EventListResponseEventFileEditedProperties) UnmarshalJSON(data []byte) (err error) {
|
||||
return apijson.UnmarshalRoot(data, r)
|
||||
}
|
||||
|
||||
func (r eventListResponseEventFileEditedPropertiesJSON) RawJSON() string {
|
||||
return r.raw
|
||||
}
|
||||
|
||||
type EventListResponseEventFileEditedType string
|
||||
|
||||
const (
|
||||
EventListResponseEventFileEditedTypeFileEdited EventListResponseEventFileEditedType = "file.edited"
|
||||
)
|
||||
|
||||
func (r EventListResponseEventFileEditedType) IsKnown() bool {
|
||||
switch r {
|
||||
case EventListResponseEventFileEditedTypeFileEdited:
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
type EventListResponseEventSessionUpdated struct {
|
||||
Properties EventListResponseEventSessionUpdatedProperties `json:"properties,required"`
|
||||
Type EventListResponseEventSessionUpdatedType `json:"type,required"`
|
||||
@@ -1229,6 +1188,45 @@ func (r EventListResponseEventSessionErrorType) IsKnown() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
type EventListResponseEventServerConnected struct {
|
||||
Properties interface{} `json:"properties,required"`
|
||||
Type EventListResponseEventServerConnectedType `json:"type,required"`
|
||||
JSON eventListResponseEventServerConnectedJSON `json:"-"`
|
||||
}
|
||||
|
||||
// eventListResponseEventServerConnectedJSON contains the JSON metadata for the
|
||||
// struct [EventListResponseEventServerConnected]
|
||||
type eventListResponseEventServerConnectedJSON struct {
|
||||
Properties apijson.Field
|
||||
Type apijson.Field
|
||||
raw string
|
||||
ExtraFields map[string]apijson.Field
|
||||
}
|
||||
|
||||
func (r *EventListResponseEventServerConnected) UnmarshalJSON(data []byte) (err error) {
|
||||
return apijson.UnmarshalRoot(data, r)
|
||||
}
|
||||
|
||||
func (r eventListResponseEventServerConnectedJSON) RawJSON() string {
|
||||
return r.raw
|
||||
}
|
||||
|
||||
func (r EventListResponseEventServerConnected) implementsEventListResponse() {}
|
||||
|
||||
type EventListResponseEventServerConnectedType string
|
||||
|
||||
const (
|
||||
EventListResponseEventServerConnectedTypeServerConnected EventListResponseEventServerConnectedType = "server.connected"
|
||||
)
|
||||
|
||||
func (r EventListResponseEventServerConnectedType) IsKnown() bool {
|
||||
switch r {
|
||||
case EventListResponseEventServerConnectedTypeServerConnected:
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
type EventListResponseEventFileWatcherUpdated struct {
|
||||
Properties EventListResponseEventFileWatcherUpdatedProperties `json:"properties,required"`
|
||||
Type EventListResponseEventFileWatcherUpdatedType `json:"type,required"`
|
||||
@@ -1376,21 +1374,21 @@ const (
|
||||
EventListResponseTypeMessagePartUpdated EventListResponseType = "message.part.updated"
|
||||
EventListResponseTypeMessagePartRemoved EventListResponseType = "message.part.removed"
|
||||
EventListResponseTypeStorageWrite EventListResponseType = "storage.write"
|
||||
EventListResponseTypeFileEdited EventListResponseType = "file.edited"
|
||||
EventListResponseTypeServerConnected EventListResponseType = "server.connected"
|
||||
EventListResponseTypePermissionUpdated EventListResponseType = "permission.updated"
|
||||
EventListResponseTypePermissionReplied EventListResponseType = "permission.replied"
|
||||
EventListResponseTypeFileEdited EventListResponseType = "file.edited"
|
||||
EventListResponseTypeSessionUpdated EventListResponseType = "session.updated"
|
||||
EventListResponseTypeSessionDeleted EventListResponseType = "session.deleted"
|
||||
EventListResponseTypeSessionIdle EventListResponseType = "session.idle"
|
||||
EventListResponseTypeSessionError EventListResponseType = "session.error"
|
||||
EventListResponseTypeServerConnected EventListResponseType = "server.connected"
|
||||
EventListResponseTypeFileWatcherUpdated EventListResponseType = "file.watcher.updated"
|
||||
EventListResponseTypeIdeInstalled EventListResponseType = "ide.installed"
|
||||
)
|
||||
|
||||
func (r EventListResponseType) IsKnown() bool {
|
||||
switch r {
|
||||
case EventListResponseTypeInstallationUpdated, EventListResponseTypeLspClientDiagnostics, EventListResponseTypeMessageUpdated, EventListResponseTypeMessageRemoved, EventListResponseTypeMessagePartUpdated, EventListResponseTypeMessagePartRemoved, EventListResponseTypeStorageWrite, EventListResponseTypeFileEdited, EventListResponseTypeServerConnected, EventListResponseTypePermissionUpdated, EventListResponseTypePermissionReplied, EventListResponseTypeSessionUpdated, EventListResponseTypeSessionDeleted, EventListResponseTypeSessionIdle, EventListResponseTypeSessionError, EventListResponseTypeFileWatcherUpdated, EventListResponseTypeIdeInstalled:
|
||||
case EventListResponseTypeInstallationUpdated, EventListResponseTypeLspClientDiagnostics, EventListResponseTypeMessageUpdated, EventListResponseTypeMessageRemoved, EventListResponseTypeMessagePartUpdated, EventListResponseTypeMessagePartRemoved, EventListResponseTypeStorageWrite, EventListResponseTypePermissionUpdated, EventListResponseTypePermissionReplied, EventListResponseTypeFileEdited, EventListResponseTypeSessionUpdated, EventListResponseTypeSessionDeleted, EventListResponseTypeSessionIdle, EventListResponseTypeSessionError, EventListResponseTypeServerConnected, EventListResponseTypeFileWatcherUpdated, EventListResponseTypeIdeInstalled:
|
||||
return true
|
||||
}
|
||||
return false
|
||||
|
||||
@@ -39,10 +39,10 @@ func NewSessionService(opts ...option.RequestOption) (r *SessionService) {
|
||||
}
|
||||
|
||||
// Create a new session
|
||||
func (r *SessionService) New(ctx context.Context, opts ...option.RequestOption) (res *Session, err error) {
|
||||
func (r *SessionService) New(ctx context.Context, body SessionNewParams, opts ...option.RequestOption) (res *Session, err error) {
|
||||
opts = append(r.Options[:], opts...)
|
||||
path := "session"
|
||||
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, nil, &res, opts...)
|
||||
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -102,6 +102,30 @@ func (r *SessionService) Chat(ctx context.Context, id string, body SessionChatPa
|
||||
return
|
||||
}
|
||||
|
||||
// Get a session's children
|
||||
func (r *SessionService) Children(ctx context.Context, id string, opts ...option.RequestOption) (res *[]Session, err error) {
|
||||
opts = append(r.Options[:], opts...)
|
||||
if id == "" {
|
||||
err = errors.New("missing required id parameter")
|
||||
return
|
||||
}
|
||||
path := fmt.Sprintf("session/%s/children", id)
|
||||
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
|
||||
return
|
||||
}
|
||||
|
||||
// Get session
|
||||
func (r *SessionService) Get(ctx context.Context, id string, opts ...option.RequestOption) (res *Session, err error) {
|
||||
opts = append(r.Options[:], opts...)
|
||||
if id == "" {
|
||||
err = errors.New("missing required id parameter")
|
||||
return
|
||||
}
|
||||
path := fmt.Sprintf("session/%s", id)
|
||||
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
|
||||
return
|
||||
}
|
||||
|
||||
// Analyze the app and create an AGENTS.md file
|
||||
func (r *SessionService) Init(ctx context.Context, id string, body SessionInitParams, opts ...option.RequestOption) (res *bool, err error) {
|
||||
opts = append(r.Options[:], opts...)
|
||||
@@ -2023,11 +2047,12 @@ func (r toolStateCompletedTimeJSON) RawJSON() string {
|
||||
}
|
||||
|
||||
type ToolStateError struct {
|
||||
Error string `json:"error,required"`
|
||||
Input map[string]interface{} `json:"input,required"`
|
||||
Status ToolStateErrorStatus `json:"status,required"`
|
||||
Time ToolStateErrorTime `json:"time,required"`
|
||||
JSON toolStateErrorJSON `json:"-"`
|
||||
Error string `json:"error,required"`
|
||||
Input map[string]interface{} `json:"input,required"`
|
||||
Status ToolStateErrorStatus `json:"status,required"`
|
||||
Time ToolStateErrorTime `json:"time,required"`
|
||||
Metadata map[string]interface{} `json:"metadata"`
|
||||
JSON toolStateErrorJSON `json:"-"`
|
||||
}
|
||||
|
||||
// toolStateErrorJSON contains the JSON metadata for the struct [ToolStateError]
|
||||
@@ -2036,6 +2061,7 @@ type toolStateErrorJSON struct {
|
||||
Input apijson.Field
|
||||
Status apijson.Field
|
||||
Time apijson.Field
|
||||
Metadata apijson.Field
|
||||
raw string
|
||||
ExtraFields map[string]apijson.Field
|
||||
}
|
||||
@@ -2298,6 +2324,15 @@ func (r sessionMessagesResponseJSON) RawJSON() string {
|
||||
return r.raw
|
||||
}
|
||||
|
||||
type SessionNewParams struct {
|
||||
ParentID param.Field[string] `json:"parentID"`
|
||||
Title param.Field[string] `json:"title"`
|
||||
}
|
||||
|
||||
func (r SessionNewParams) MarshalJSON() (data []byte, err error) {
|
||||
return apijson.MarshalRoot(r)
|
||||
}
|
||||
|
||||
type SessionUpdateParams struct {
|
||||
Title param.Field[string] `json:"title"`
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
"github.com/sst/opencode-sdk-go/option"
|
||||
)
|
||||
|
||||
func TestSessionNew(t *testing.T) {
|
||||
func TestSessionNewWithOptionalParams(t *testing.T) {
|
||||
t.Skip("skipped: tests are disabled for the time being")
|
||||
baseURL := "http://localhost:4010"
|
||||
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
|
||||
@@ -25,7 +25,10 @@ func TestSessionNew(t *testing.T) {
|
||||
client := opencode.NewClient(
|
||||
option.WithBaseURL(baseURL),
|
||||
)
|
||||
_, err := client.Session.New(context.TODO())
|
||||
_, err := client.Session.New(context.TODO(), opencode.SessionNewParams{
|
||||
ParentID: opencode.F("parentID"),
|
||||
Title: opencode.F("title"),
|
||||
})
|
||||
if err != nil {
|
||||
var apierr *opencode.Error
|
||||
if errors.As(err, &apierr) {
|
||||
@@ -174,6 +177,50 @@ func TestSessionChatWithOptionalParams(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSessionChildren(t *testing.T) {
|
||||
t.Skip("skipped: tests are disabled for the time being")
|
||||
baseURL := "http://localhost:4010"
|
||||
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
|
||||
baseURL = envURL
|
||||
}
|
||||
if !testutil.CheckTestServer(t, baseURL) {
|
||||
return
|
||||
}
|
||||
client := opencode.NewClient(
|
||||
option.WithBaseURL(baseURL),
|
||||
)
|
||||
_, err := client.Session.Children(context.TODO(), "id")
|
||||
if err != nil {
|
||||
var apierr *opencode.Error
|
||||
if errors.As(err, &apierr) {
|
||||
t.Log(string(apierr.DumpRequest(true)))
|
||||
}
|
||||
t.Fatalf("err should be nil: %s", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func TestSessionGet(t *testing.T) {
|
||||
t.Skip("skipped: tests are disabled for the time being")
|
||||
baseURL := "http://localhost:4010"
|
||||
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
|
||||
baseURL = envURL
|
||||
}
|
||||
if !testutil.CheckTestServer(t, baseURL) {
|
||||
return
|
||||
}
|
||||
client := opencode.NewClient(
|
||||
option.WithBaseURL(baseURL),
|
||||
)
|
||||
_, err := client.Session.Get(context.TODO(), "id")
|
||||
if err != nil {
|
||||
var apierr *opencode.Error
|
||||
if errors.As(err, &apierr) {
|
||||
t.Log(string(apierr.DumpRequest(true)))
|
||||
}
|
||||
t.Fatalf("err should be nil: %s", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func TestSessionInit(t *testing.T) {
|
||||
t.Skip("skipped: tests are disabled for the time being")
|
||||
baseURL := "http://localhost:4010"
|
||||
|
||||
+36
-1
@@ -47,7 +47,7 @@ func (r *TuiService) ClearPrompt(ctx context.Context, opts ...option.RequestOpti
|
||||
return
|
||||
}
|
||||
|
||||
// Execute a TUI command (e.g. switch_agent)
|
||||
// Execute a TUI command (e.g. agent_cycle)
|
||||
func (r *TuiService) ExecuteCommand(ctx context.Context, body TuiExecuteCommandParams, opts ...option.RequestOption) (res *bool, err error) {
|
||||
opts = append(r.Options[:], opts...)
|
||||
path := "tui/execute-command"
|
||||
@@ -87,6 +87,14 @@ func (r *TuiService) OpenThemes(ctx context.Context, opts ...option.RequestOptio
|
||||
return
|
||||
}
|
||||
|
||||
// Show a toast notification in the TUI
|
||||
func (r *TuiService) ShowToast(ctx context.Context, body TuiShowToastParams, opts ...option.RequestOption) (res *bool, err error) {
|
||||
opts = append(r.Options[:], opts...)
|
||||
path := "tui/show-toast"
|
||||
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
|
||||
return
|
||||
}
|
||||
|
||||
// Submit the prompt
|
||||
func (r *TuiService) SubmitPrompt(ctx context.Context, opts ...option.RequestOption) (res *bool, err error) {
|
||||
opts = append(r.Options[:], opts...)
|
||||
@@ -110,3 +118,30 @@ type TuiExecuteCommandParams struct {
|
||||
func (r TuiExecuteCommandParams) MarshalJSON() (data []byte, err error) {
|
||||
return apijson.MarshalRoot(r)
|
||||
}
|
||||
|
||||
type TuiShowToastParams struct {
|
||||
Message param.Field[string] `json:"message,required"`
|
||||
Variant param.Field[TuiShowToastParamsVariant] `json:"variant,required"`
|
||||
Title param.Field[string] `json:"title"`
|
||||
}
|
||||
|
||||
func (r TuiShowToastParams) MarshalJSON() (data []byte, err error) {
|
||||
return apijson.MarshalRoot(r)
|
||||
}
|
||||
|
||||
type TuiShowToastParamsVariant string
|
||||
|
||||
const (
|
||||
TuiShowToastParamsVariantInfo TuiShowToastParamsVariant = "info"
|
||||
TuiShowToastParamsVariantSuccess TuiShowToastParamsVariant = "success"
|
||||
TuiShowToastParamsVariantWarning TuiShowToastParamsVariant = "warning"
|
||||
TuiShowToastParamsVariantError TuiShowToastParamsVariant = "error"
|
||||
)
|
||||
|
||||
func (r TuiShowToastParamsVariant) IsKnown() bool {
|
||||
switch r {
|
||||
case TuiShowToastParamsVariantInfo, TuiShowToastParamsVariantSuccess, TuiShowToastParamsVariantWarning, TuiShowToastParamsVariantError:
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -171,6 +171,32 @@ func TestTuiOpenThemes(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestTuiShowToastWithOptionalParams(t *testing.T) {
|
||||
t.Skip("skipped: tests are disabled for the time being")
|
||||
baseURL := "http://localhost:4010"
|
||||
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
|
||||
baseURL = envURL
|
||||
}
|
||||
if !testutil.CheckTestServer(t, baseURL) {
|
||||
return
|
||||
}
|
||||
client := opencode.NewClient(
|
||||
option.WithBaseURL(baseURL),
|
||||
)
|
||||
_, err := client.Tui.ShowToast(context.TODO(), opencode.TuiShowToastParams{
|
||||
Message: opencode.F("message"),
|
||||
Variant: opencode.F(opencode.TuiShowToastParamsVariantInfo),
|
||||
Title: opencode.F("title"),
|
||||
})
|
||||
if err != nil {
|
||||
var apierr *opencode.Error
|
||||
if errors.As(err, &apierr) {
|
||||
t.Log(string(apierr.DumpRequest(true)))
|
||||
}
|
||||
t.Fatalf("err should be nil: %s", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func TestTuiSubmitPrompt(t *testing.T) {
|
||||
t.Skip("skipped: tests are disabled for the time being")
|
||||
baseURL := "http://localhost:4010"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/package.json",
|
||||
"name": "@opencode-ai/sdk",
|
||||
"version": "0.5.1",
|
||||
"version": "0.5.4",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"typecheck": "tsc --noEmit"
|
||||
|
||||
@@ -21,6 +21,8 @@ import type {
|
||||
SessionGetResponses,
|
||||
SessionUpdateData,
|
||||
SessionUpdateResponses,
|
||||
SessionChildrenData,
|
||||
SessionChildrenResponses,
|
||||
SessionInitData,
|
||||
SessionInitResponses,
|
||||
SessionAbortData,
|
||||
@@ -77,6 +79,8 @@ import type {
|
||||
TuiClearPromptResponses,
|
||||
TuiExecuteCommandData,
|
||||
TuiExecuteCommandResponses,
|
||||
TuiShowToastData,
|
||||
TuiShowToastResponses,
|
||||
AuthSetData,
|
||||
AuthSetResponses,
|
||||
AuthSetErrors,
|
||||
@@ -208,6 +212,10 @@ class Session extends _HeyApiClient {
|
||||
return (options?.client ?? this._client).post<SessionCreateResponses, SessionCreateErrors, ThrowOnError>({
|
||||
url: "/session",
|
||||
...options,
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
...options?.headers,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -245,6 +253,16 @@ class Session extends _HeyApiClient {
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a session's children
|
||||
*/
|
||||
public children<ThrowOnError extends boolean = false>(options: Options<SessionChildrenData, ThrowOnError>) {
|
||||
return (options.client ?? this._client).get<SessionChildrenResponses, unknown, ThrowOnError>({
|
||||
url: "/session/{id}/children",
|
||||
...options,
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Analyze the app and create an AGENTS.md file
|
||||
*/
|
||||
@@ -506,7 +524,7 @@ class Tui extends _HeyApiClient {
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute a TUI command (e.g. switch_agent)
|
||||
* Execute a TUI command (e.g. agent_cycle)
|
||||
*/
|
||||
public executeCommand<ThrowOnError extends boolean = false>(options?: Options<TuiExecuteCommandData, ThrowOnError>) {
|
||||
return (options?.client ?? this._client).post<TuiExecuteCommandResponses, unknown, ThrowOnError>({
|
||||
@@ -518,6 +536,20 @@ class Tui extends _HeyApiClient {
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Show a toast notification in the TUI
|
||||
*/
|
||||
public showToast<ThrowOnError extends boolean = false>(options?: Options<TuiShowToastData, ThrowOnError>) {
|
||||
return (options?.client ?? this._client).post<TuiShowToastResponses, unknown, ThrowOnError>({
|
||||
url: "/tui/show-toast",
|
||||
...options,
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
...options?.headers,
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
class Auth extends _HeyApiClient {
|
||||
|
||||
@@ -348,6 +348,9 @@ export type ToolStateError = {
|
||||
[key: string]: unknown
|
||||
}
|
||||
error: string
|
||||
metadata?: {
|
||||
[key: string]: unknown
|
||||
}
|
||||
time: {
|
||||
start: number
|
||||
end: number
|
||||
@@ -573,6 +576,15 @@ export type Config = {
|
||||
* Custom keybind configurations
|
||||
*/
|
||||
keybinds?: KeybindsConfig
|
||||
/**
|
||||
* TUI specific settings
|
||||
*/
|
||||
tui?: {
|
||||
/**
|
||||
* TUI scroll speed
|
||||
*/
|
||||
scroll_speed: number
|
||||
}
|
||||
plugin?: Array<string>
|
||||
snapshot?: boolean
|
||||
/**
|
||||
@@ -747,25 +759,29 @@ export type KeybindsConfig = {
|
||||
*/
|
||||
app_help: string
|
||||
/**
|
||||
* @deprecated use switch_agent. Next mode
|
||||
* Exit the application
|
||||
*/
|
||||
switch_mode: string
|
||||
/**
|
||||
* @deprecated use switch_agent_reverse. Previous mode
|
||||
*/
|
||||
switch_mode_reverse: string
|
||||
/**
|
||||
* Next agent
|
||||
*/
|
||||
switch_agent: string
|
||||
/**
|
||||
* Previous agent
|
||||
*/
|
||||
switch_agent_reverse: string
|
||||
app_exit: string
|
||||
/**
|
||||
* Open external editor
|
||||
*/
|
||||
editor_open: string
|
||||
/**
|
||||
* List available themes
|
||||
*/
|
||||
theme_list: string
|
||||
/**
|
||||
* Create/update AGENTS.md
|
||||
*/
|
||||
project_init: string
|
||||
/**
|
||||
* Toggle tool details
|
||||
*/
|
||||
tool_details: string
|
||||
/**
|
||||
* Toggle thinking blocks
|
||||
*/
|
||||
thinking_blocks: string
|
||||
/**
|
||||
* Export session to editor
|
||||
*/
|
||||
@@ -795,57 +811,13 @@ export type KeybindsConfig = {
|
||||
*/
|
||||
session_compact: string
|
||||
/**
|
||||
* Toggle tool details
|
||||
* Cycle to next child session
|
||||
*/
|
||||
tool_details: string
|
||||
session_child_cycle: string
|
||||
/**
|
||||
* Toggle thinking blocks
|
||||
* Cycle to previous child session
|
||||
*/
|
||||
thinking_blocks: string
|
||||
/**
|
||||
* List available models
|
||||
*/
|
||||
model_list: string
|
||||
/**
|
||||
* List available themes
|
||||
*/
|
||||
theme_list: string
|
||||
/**
|
||||
* List files
|
||||
*/
|
||||
file_list: string
|
||||
/**
|
||||
* Close file
|
||||
*/
|
||||
file_close: string
|
||||
/**
|
||||
* Search file
|
||||
*/
|
||||
file_search: string
|
||||
/**
|
||||
* Split/unified diff
|
||||
*/
|
||||
file_diff_toggle: string
|
||||
/**
|
||||
* Create/update AGENTS.md
|
||||
*/
|
||||
project_init: string
|
||||
/**
|
||||
* Clear input field
|
||||
*/
|
||||
input_clear: string
|
||||
/**
|
||||
* Paste from clipboard
|
||||
*/
|
||||
input_paste: string
|
||||
/**
|
||||
* Submit input
|
||||
*/
|
||||
input_submit: string
|
||||
/**
|
||||
* Insert newline in input
|
||||
*/
|
||||
input_newline: string
|
||||
session_child_cycle_reverse: string
|
||||
/**
|
||||
* Scroll messages up by one page
|
||||
*/
|
||||
@@ -862,14 +834,6 @@ export type KeybindsConfig = {
|
||||
* Scroll messages down by half page
|
||||
*/
|
||||
messages_half_page_down: string
|
||||
/**
|
||||
* Navigate to previous message
|
||||
*/
|
||||
messages_previous: string
|
||||
/**
|
||||
* Navigate to next message
|
||||
*/
|
||||
messages_next: string
|
||||
/**
|
||||
* Navigate to first message
|
||||
*/
|
||||
@@ -878,18 +842,10 @@ export type KeybindsConfig = {
|
||||
* Navigate to last message
|
||||
*/
|
||||
messages_last: string
|
||||
/**
|
||||
* Toggle layout
|
||||
*/
|
||||
messages_layout_toggle: string
|
||||
/**
|
||||
* Copy message
|
||||
*/
|
||||
messages_copy: string
|
||||
/**
|
||||
* @deprecated use messages_undo. Revert message
|
||||
*/
|
||||
messages_revert: string
|
||||
/**
|
||||
* Undo message
|
||||
*/
|
||||
@@ -899,9 +855,93 @@ export type KeybindsConfig = {
|
||||
*/
|
||||
messages_redo: string
|
||||
/**
|
||||
* Exit the application
|
||||
* List available models
|
||||
*/
|
||||
app_exit: string
|
||||
model_list: string
|
||||
/**
|
||||
* Next recent model
|
||||
*/
|
||||
model_cycle_recent: string
|
||||
/**
|
||||
* Previous recent model
|
||||
*/
|
||||
model_cycle_recent_reverse: string
|
||||
/**
|
||||
* List agents
|
||||
*/
|
||||
agent_list: string
|
||||
/**
|
||||
* Next agent
|
||||
*/
|
||||
agent_cycle: string
|
||||
/**
|
||||
* Previous agent
|
||||
*/
|
||||
agent_cycle_reverse: string
|
||||
/**
|
||||
* Clear input field
|
||||
*/
|
||||
input_clear: string
|
||||
/**
|
||||
* Paste from clipboard
|
||||
*/
|
||||
input_paste: string
|
||||
/**
|
||||
* Submit input
|
||||
*/
|
||||
input_submit: string
|
||||
/**
|
||||
* Insert newline in input
|
||||
*/
|
||||
input_newline: string
|
||||
/**
|
||||
* @deprecated use agent_cycle. Next mode
|
||||
*/
|
||||
switch_mode: string
|
||||
/**
|
||||
* @deprecated use agent_cycle_reverse. Previous mode
|
||||
*/
|
||||
switch_mode_reverse: string
|
||||
/**
|
||||
* @deprecated use agent_cycle. Next agent
|
||||
*/
|
||||
switch_agent: string
|
||||
/**
|
||||
* @deprecated use agent_cycle_reverse. Previous agent
|
||||
*/
|
||||
switch_agent_reverse: string
|
||||
/**
|
||||
* @deprecated Currently not available. List files
|
||||
*/
|
||||
file_list: string
|
||||
/**
|
||||
* @deprecated Close file
|
||||
*/
|
||||
file_close: string
|
||||
/**
|
||||
* @deprecated Search file
|
||||
*/
|
||||
file_search: string
|
||||
/**
|
||||
* @deprecated Split/unified diff
|
||||
*/
|
||||
file_diff_toggle: string
|
||||
/**
|
||||
* @deprecated Navigate to previous message
|
||||
*/
|
||||
messages_previous: string
|
||||
/**
|
||||
* @deprecated Navigate to next message
|
||||
*/
|
||||
messages_next: string
|
||||
/**
|
||||
* @deprecated Toggle layout
|
||||
*/
|
||||
messages_layout_toggle: string
|
||||
/**
|
||||
* @deprecated use messages_undo. Revert message
|
||||
*/
|
||||
messages_revert: string
|
||||
}
|
||||
|
||||
export type AgentConfig = {
|
||||
@@ -1083,6 +1123,7 @@ export type Agent = {
|
||||
name: string
|
||||
description?: string
|
||||
mode: "subagent" | "primary" | "all"
|
||||
builtIn: boolean
|
||||
topP?: number
|
||||
temperature?: number
|
||||
permission: {
|
||||
@@ -1215,7 +1256,10 @@ export type SessionListResponses = {
|
||||
export type SessionListResponse = SessionListResponses[keyof SessionListResponses]
|
||||
|
||||
export type SessionCreateData = {
|
||||
body?: never
|
||||
body?: {
|
||||
parentID?: string
|
||||
title?: string
|
||||
}
|
||||
path?: never
|
||||
query?: never
|
||||
url: "/session"
|
||||
@@ -1295,6 +1339,24 @@ export type SessionUpdateResponses = {
|
||||
|
||||
export type SessionUpdateResponse = SessionUpdateResponses[keyof SessionUpdateResponses]
|
||||
|
||||
export type SessionChildrenData = {
|
||||
body?: never
|
||||
path: {
|
||||
id: string
|
||||
}
|
||||
query?: never
|
||||
url: "/session/{id}/children"
|
||||
}
|
||||
|
||||
export type SessionChildrenResponses = {
|
||||
/**
|
||||
* List of children
|
||||
*/
|
||||
200: Array<Session>
|
||||
}
|
||||
|
||||
export type SessionChildrenResponse = SessionChildrenResponses[keyof SessionChildrenResponses]
|
||||
|
||||
export type SessionInitData = {
|
||||
body?: {
|
||||
messageID: string
|
||||
@@ -1887,6 +1949,26 @@ export type TuiExecuteCommandResponses = {
|
||||
|
||||
export type TuiExecuteCommandResponse = TuiExecuteCommandResponses[keyof TuiExecuteCommandResponses]
|
||||
|
||||
export type TuiShowToastData = {
|
||||
body?: {
|
||||
title?: string
|
||||
message: string
|
||||
variant: "info" | "success" | "warning" | "error"
|
||||
}
|
||||
path?: never
|
||||
query?: never
|
||||
url: "/tui/show-toast"
|
||||
}
|
||||
|
||||
export type TuiShowToastResponses = {
|
||||
/**
|
||||
* Toast notification shown successfully
|
||||
*/
|
||||
200: boolean
|
||||
}
|
||||
|
||||
export type TuiShowToastResponse = TuiShowToastResponses[keyof TuiShowToastResponses]
|
||||
|
||||
export type AuthSetData = {
|
||||
body?: Auth
|
||||
path: {
|
||||
|
||||
@@ -113,7 +113,9 @@ resources:
|
||||
toolStateError: ToolStateError
|
||||
|
||||
methods:
|
||||
get: get /session/{id}
|
||||
list: get /session
|
||||
children: get /session/{id}/children
|
||||
create: post /session
|
||||
delete: delete /session/{id}
|
||||
init: post /session/{id}/init
|
||||
@@ -146,6 +148,7 @@ resources:
|
||||
openThemes: post /tui/open-themes
|
||||
openModels: post /tui/open-models
|
||||
executeCommand: post /tui/execute-command
|
||||
showToast: post /tui/show-toast
|
||||
|
||||
settings:
|
||||
disable_mock_tests: true
|
||||
|
||||
@@ -50,6 +50,7 @@ type App struct {
|
||||
compactCancel context.CancelFunc
|
||||
IsLeaderSequence bool
|
||||
IsBashMode bool
|
||||
ScrollSpeed int
|
||||
}
|
||||
|
||||
func (a *App) Agent() *opencode.Agent {
|
||||
@@ -198,6 +199,7 @@ func New(
|
||||
InitialPrompt: initialPrompt,
|
||||
InitialAgent: initialAgent,
|
||||
InitialSession: initialSession,
|
||||
ScrollSpeed: int(configInfo.Tui.ScrollSpeed),
|
||||
}
|
||||
|
||||
return app, nil
|
||||
@@ -290,7 +292,7 @@ func (a *App) SwitchAgentReverse() (*App, tea.Cmd) {
|
||||
return a.cycleMode(false)
|
||||
}
|
||||
|
||||
func (a *App) CycleRecentModel() (*App, tea.Cmd) {
|
||||
func (a *App) cycleRecentModel(forward bool) (*App, tea.Cmd) {
|
||||
recentModels := a.State.RecentlyUsedModels
|
||||
if len(recentModels) > 5 {
|
||||
recentModels = recentModels[:5]
|
||||
@@ -299,15 +301,21 @@ func (a *App) CycleRecentModel() (*App, tea.Cmd) {
|
||||
return a, toast.NewInfoToast("Need at least 2 recent models to cycle")
|
||||
}
|
||||
nextIndex := 0
|
||||
prevIndex := 0
|
||||
for i, recentModel := range recentModels {
|
||||
if a.Provider != nil && a.Model != nil && recentModel.ProviderID == a.Provider.ID &&
|
||||
recentModel.ModelID == a.Model.ID {
|
||||
nextIndex = (i + 1) % len(recentModels)
|
||||
prevIndex = (i - 1 + len(recentModels)) % len(recentModels)
|
||||
break
|
||||
}
|
||||
}
|
||||
targetIndex := nextIndex
|
||||
if !forward {
|
||||
targetIndex = prevIndex
|
||||
}
|
||||
for range recentModels {
|
||||
currentRecentModel := recentModels[nextIndex%len(recentModels)]
|
||||
currentRecentModel := recentModels[targetIndex%len(recentModels)]
|
||||
provider, model := findModelByProviderAndModelID(
|
||||
a.Providers,
|
||||
currentRecentModel.ProviderID,
|
||||
@@ -327,8 +335,8 @@ func (a *App) CycleRecentModel() (*App, tea.Cmd) {
|
||||
)
|
||||
}
|
||||
recentModels = append(
|
||||
recentModels[:nextIndex%len(recentModels)],
|
||||
recentModels[nextIndex%len(recentModels)+1:]...)
|
||||
recentModels[:targetIndex%len(recentModels)],
|
||||
recentModels[targetIndex%len(recentModels)+1:]...)
|
||||
if len(recentModels) < 2 {
|
||||
a.State.RecentlyUsedModels = recentModels
|
||||
return a, tea.Sequence(
|
||||
@@ -341,6 +349,14 @@ func (a *App) CycleRecentModel() (*App, tea.Cmd) {
|
||||
return a, toast.NewErrorToast("Recent model not found")
|
||||
}
|
||||
|
||||
func (a *App) CycleRecentModel() (*App, tea.Cmd) {
|
||||
return a.cycleRecentModel(true)
|
||||
}
|
||||
|
||||
func (a *App) CycleRecentModelReverse() (*App, tea.Cmd) {
|
||||
return a.cycleRecentModel(false)
|
||||
}
|
||||
|
||||
func (a *App) SwitchToAgent(agentName string) (*App, tea.Cmd) {
|
||||
// Find the agent index by name
|
||||
for i, agent := range a.Agents {
|
||||
@@ -711,7 +727,7 @@ func (a *App) MarkProjectInitialized(ctx context.Context) error {
|
||||
}
|
||||
|
||||
func (a *App) CreateSession(ctx context.Context) (*opencode.Session, error) {
|
||||
session, err := a.Client.Session.New(ctx)
|
||||
session, err := a.Client.Session.New(ctx, opencode.SessionNewParams{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -28,15 +28,12 @@ type AgentModel struct {
|
||||
|
||||
type State struct {
|
||||
Theme string `toml:"theme"`
|
||||
ScrollSpeed *int `toml:"scroll_speed"`
|
||||
AgentModel map[string]AgentModel `toml:"agent_model"`
|
||||
Provider string `toml:"provider"`
|
||||
Model string `toml:"model"`
|
||||
Agent string `toml:"agent"`
|
||||
RecentlyUsedModels []ModelUsage `toml:"recently_used_models"`
|
||||
RecentlyUsedAgents []AgentUsage `toml:"recently_used_agents"`
|
||||
MessagesRight bool `toml:"messages_right"`
|
||||
SplitDiff bool `toml:"split_diff"`
|
||||
MessageHistory []Prompt `toml:"message_history"`
|
||||
ShowToolDetails *bool `toml:"show_tool_details"`
|
||||
ShowThinkingBlocks *bool `toml:"show_thinking_blocks"`
|
||||
|
||||
@@ -107,45 +107,52 @@ func (r CommandRegistry) Matches(msg tea.KeyPressMsg, leader bool) []Command {
|
||||
}
|
||||
|
||||
const (
|
||||
AppHelpCommand CommandName = "app_help"
|
||||
SwitchAgentCommand CommandName = "switch_agent"
|
||||
SwitchAgentReverseCommand CommandName = "switch_agent_reverse"
|
||||
EditorOpenCommand CommandName = "editor_open"
|
||||
SessionNewCommand CommandName = "session_new"
|
||||
SessionListCommand CommandName = "session_list"
|
||||
SessionShareCommand CommandName = "session_share"
|
||||
SessionUnshareCommand CommandName = "session_unshare"
|
||||
SessionInterruptCommand CommandName = "session_interrupt"
|
||||
SessionCompactCommand CommandName = "session_compact"
|
||||
SessionExportCommand CommandName = "session_export"
|
||||
ToolDetailsCommand CommandName = "tool_details"
|
||||
ThinkingBlocksCommand CommandName = "thinking_blocks"
|
||||
ModelListCommand CommandName = "model_list"
|
||||
AgentListCommand CommandName = "agent_list"
|
||||
ModelCycleRecentCommand CommandName = "model_cycle_recent"
|
||||
ThemeListCommand CommandName = "theme_list"
|
||||
FileListCommand CommandName = "file_list"
|
||||
FileCloseCommand CommandName = "file_close"
|
||||
FileSearchCommand CommandName = "file_search"
|
||||
FileDiffToggleCommand CommandName = "file_diff_toggle"
|
||||
ProjectInitCommand CommandName = "project_init"
|
||||
InputClearCommand CommandName = "input_clear"
|
||||
InputPasteCommand CommandName = "input_paste"
|
||||
InputSubmitCommand CommandName = "input_submit"
|
||||
InputNewlineCommand CommandName = "input_newline"
|
||||
MessagesPageUpCommand CommandName = "messages_page_up"
|
||||
MessagesPageDownCommand CommandName = "messages_page_down"
|
||||
MessagesHalfPageUpCommand CommandName = "messages_half_page_up"
|
||||
MessagesHalfPageDownCommand CommandName = "messages_half_page_down"
|
||||
MessagesPreviousCommand CommandName = "messages_previous"
|
||||
MessagesNextCommand CommandName = "messages_next"
|
||||
MessagesFirstCommand CommandName = "messages_first"
|
||||
MessagesLastCommand CommandName = "messages_last"
|
||||
MessagesLayoutToggleCommand CommandName = "messages_layout_toggle"
|
||||
MessagesCopyCommand CommandName = "messages_copy"
|
||||
MessagesUndoCommand CommandName = "messages_undo"
|
||||
MessagesRedoCommand CommandName = "messages_redo"
|
||||
AppExitCommand CommandName = "app_exit"
|
||||
|
||||
SessionChildCycleCommand CommandName = "session_child_cycle"
|
||||
SessionChildCycleReverseCommand CommandName = "session_child_cycle_reverse"
|
||||
ModelCycleRecentReverseCommand CommandName = "model_cycle_recent_reverse"
|
||||
AgentCycleCommand CommandName = "agent_cycle"
|
||||
AgentCycleReverseCommand CommandName = "agent_cycle_reverse"
|
||||
AppHelpCommand CommandName = "app_help"
|
||||
SwitchAgentCommand CommandName = "switch_agent"
|
||||
SwitchAgentReverseCommand CommandName = "switch_agent_reverse"
|
||||
EditorOpenCommand CommandName = "editor_open"
|
||||
SessionNewCommand CommandName = "session_new"
|
||||
SessionListCommand CommandName = "session_list"
|
||||
SessionNavigationCommand CommandName = "session_navigation"
|
||||
SessionShareCommand CommandName = "session_share"
|
||||
SessionUnshareCommand CommandName = "session_unshare"
|
||||
SessionInterruptCommand CommandName = "session_interrupt"
|
||||
SessionCompactCommand CommandName = "session_compact"
|
||||
SessionExportCommand CommandName = "session_export"
|
||||
ToolDetailsCommand CommandName = "tool_details"
|
||||
ThinkingBlocksCommand CommandName = "thinking_blocks"
|
||||
ModelListCommand CommandName = "model_list"
|
||||
AgentListCommand CommandName = "agent_list"
|
||||
ModelCycleRecentCommand CommandName = "model_cycle_recent"
|
||||
ThemeListCommand CommandName = "theme_list"
|
||||
FileListCommand CommandName = "file_list"
|
||||
FileCloseCommand CommandName = "file_close"
|
||||
FileSearchCommand CommandName = "file_search"
|
||||
FileDiffToggleCommand CommandName = "file_diff_toggle"
|
||||
ProjectInitCommand CommandName = "project_init"
|
||||
InputClearCommand CommandName = "input_clear"
|
||||
InputPasteCommand CommandName = "input_paste"
|
||||
InputSubmitCommand CommandName = "input_submit"
|
||||
InputNewlineCommand CommandName = "input_newline"
|
||||
MessagesPageUpCommand CommandName = "messages_page_up"
|
||||
MessagesPageDownCommand CommandName = "messages_page_down"
|
||||
MessagesHalfPageUpCommand CommandName = "messages_half_page_up"
|
||||
MessagesHalfPageDownCommand CommandName = "messages_half_page_down"
|
||||
MessagesPreviousCommand CommandName = "messages_previous"
|
||||
MessagesNextCommand CommandName = "messages_next"
|
||||
MessagesFirstCommand CommandName = "messages_first"
|
||||
MessagesLastCommand CommandName = "messages_last"
|
||||
MessagesLayoutToggleCommand CommandName = "messages_layout_toggle"
|
||||
MessagesCopyCommand CommandName = "messages_copy"
|
||||
MessagesUndoCommand CommandName = "messages_undo"
|
||||
MessagesRedoCommand CommandName = "messages_redo"
|
||||
AppExitCommand CommandName = "app_exit"
|
||||
)
|
||||
|
||||
func (k Command) Matches(msg tea.KeyPressMsg, leader bool) bool {
|
||||
@@ -184,16 +191,6 @@ func LoadFromConfig(config *opencode.Config) CommandRegistry {
|
||||
Keybindings: parseBindings("<leader>h"),
|
||||
Trigger: []string{"help"},
|
||||
},
|
||||
{
|
||||
Name: SwitchAgentCommand,
|
||||
Description: "next agent",
|
||||
Keybindings: parseBindings("tab"),
|
||||
},
|
||||
{
|
||||
Name: SwitchAgentReverseCommand,
|
||||
Description: "previous agent",
|
||||
Keybindings: parseBindings("shift+tab"),
|
||||
},
|
||||
{
|
||||
Name: EditorOpenCommand,
|
||||
Description: "open editor",
|
||||
@@ -218,6 +215,12 @@ func LoadFromConfig(config *opencode.Config) CommandRegistry {
|
||||
Keybindings: parseBindings("<leader>l"),
|
||||
Trigger: []string{"sessions", "resume", "continue"},
|
||||
},
|
||||
{
|
||||
Name: SessionNavigationCommand,
|
||||
Description: "jump to message",
|
||||
Keybindings: parseBindings("<leader>g"),
|
||||
Trigger: []string{"jump", "goto", "navigate"},
|
||||
},
|
||||
{
|
||||
Name: SessionShareCommand,
|
||||
Description: "share session",
|
||||
@@ -240,6 +243,16 @@ func LoadFromConfig(config *opencode.Config) CommandRegistry {
|
||||
Keybindings: parseBindings("<leader>c"),
|
||||
Trigger: []string{"compact", "summarize"},
|
||||
},
|
||||
{
|
||||
Name: SessionChildCycleCommand,
|
||||
Description: "cycle to next child session",
|
||||
Keybindings: parseBindings("ctrl+right"),
|
||||
},
|
||||
{
|
||||
Name: SessionChildCycleReverseCommand,
|
||||
Description: "cycle to previous child session",
|
||||
Keybindings: parseBindings("ctrl+left"),
|
||||
},
|
||||
{
|
||||
Name: ToolDetailsCommand,
|
||||
Description: "toggle tool details",
|
||||
@@ -258,6 +271,16 @@ func LoadFromConfig(config *opencode.Config) CommandRegistry {
|
||||
Keybindings: parseBindings("<leader>m"),
|
||||
Trigger: []string{"models"},
|
||||
},
|
||||
{
|
||||
Name: ModelCycleRecentCommand,
|
||||
Description: "next recent model",
|
||||
Keybindings: parseBindings("f2"),
|
||||
},
|
||||
{
|
||||
Name: ModelCycleRecentReverseCommand,
|
||||
Description: "previous recent model",
|
||||
Keybindings: parseBindings("shift+f2"),
|
||||
},
|
||||
{
|
||||
Name: AgentListCommand,
|
||||
Description: "list agents",
|
||||
@@ -265,9 +288,14 @@ func LoadFromConfig(config *opencode.Config) CommandRegistry {
|
||||
Trigger: []string{"agents"},
|
||||
},
|
||||
{
|
||||
Name: ModelCycleRecentCommand,
|
||||
Description: "cycle recent models",
|
||||
Keybindings: parseBindings("f2"),
|
||||
Name: AgentCycleCommand,
|
||||
Description: "next agent",
|
||||
Keybindings: parseBindings("tab"),
|
||||
},
|
||||
{
|
||||
Name: AgentCycleReverseCommand,
|
||||
Description: "previous agent",
|
||||
Keybindings: parseBindings("shift+tab"),
|
||||
},
|
||||
{
|
||||
Name: ThemeListCommand,
|
||||
@@ -275,27 +303,6 @@ func LoadFromConfig(config *opencode.Config) CommandRegistry {
|
||||
Keybindings: parseBindings("<leader>t"),
|
||||
Trigger: []string{"themes"},
|
||||
},
|
||||
// {
|
||||
// Name: FileListCommand,
|
||||
// Description: "list files",
|
||||
// Keybindings: parseBindings("<leader>f"),
|
||||
// Trigger: []string{"files"},
|
||||
// },
|
||||
{
|
||||
Name: FileCloseCommand,
|
||||
Description: "close file",
|
||||
Keybindings: parseBindings("esc"),
|
||||
},
|
||||
{
|
||||
Name: FileSearchCommand,
|
||||
Description: "search file",
|
||||
Keybindings: parseBindings("<leader>/"),
|
||||
},
|
||||
{
|
||||
Name: FileDiffToggleCommand,
|
||||
Description: "split/unified diff",
|
||||
Keybindings: parseBindings("<leader>v"),
|
||||
},
|
||||
{
|
||||
Name: ProjectInitCommand,
|
||||
Description: "create/update AGENTS.md",
|
||||
@@ -342,16 +349,7 @@ func LoadFromConfig(config *opencode.Config) CommandRegistry {
|
||||
Description: "half page down",
|
||||
Keybindings: parseBindings("ctrl+alt+d"),
|
||||
},
|
||||
{
|
||||
Name: MessagesPreviousCommand,
|
||||
Description: "previous message",
|
||||
Keybindings: parseBindings("ctrl+up"),
|
||||
},
|
||||
{
|
||||
Name: MessagesNextCommand,
|
||||
Description: "next message",
|
||||
Keybindings: parseBindings("ctrl+down"),
|
||||
},
|
||||
|
||||
{
|
||||
Name: MessagesFirstCommand,
|
||||
Description: "first message",
|
||||
@@ -362,11 +360,7 @@ func LoadFromConfig(config *opencode.Config) CommandRegistry {
|
||||
Description: "last message",
|
||||
Keybindings: parseBindings("ctrl+alt+g"),
|
||||
},
|
||||
{
|
||||
Name: MessagesLayoutToggleCommand,
|
||||
Description: "toggle layout",
|
||||
Keybindings: parseBindings("<leader>p"),
|
||||
},
|
||||
|
||||
{
|
||||
Name: MessagesCopyCommand,
|
||||
Description: "copy message",
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
"github.com/muesli/reflow/truncate"
|
||||
"github.com/sst/opencode-sdk-go"
|
||||
"github.com/sst/opencode/internal/app"
|
||||
"github.com/sst/opencode/internal/commands"
|
||||
"github.com/sst/opencode/internal/components/diff"
|
||||
"github.com/sst/opencode/internal/styles"
|
||||
"github.com/sst/opencode/internal/theme"
|
||||
@@ -211,6 +212,7 @@ func renderText(
|
||||
width int,
|
||||
extra string,
|
||||
isThinking bool,
|
||||
isQueued bool,
|
||||
fileParts []opencode.FilePart,
|
||||
agentParts []opencode.AgentPart,
|
||||
toolCalls ...opencode.ToolPart,
|
||||
@@ -331,6 +333,10 @@ func renderText(
|
||||
wrappedText := ansi.WordwrapWc(styledText, width-6, " ")
|
||||
wrappedText = strings.ReplaceAll(wrappedText, "\u2011", "-")
|
||||
content = base.Width(width - 6).Render(wrappedText)
|
||||
if isQueued {
|
||||
queuedStyle := styles.NewStyle().Background(t.Accent()).Foreground(t.BackgroundPanel()).Bold(true).Padding(0, 1)
|
||||
content = queuedStyle.Render("QUEUED") + "\n\n" + content
|
||||
}
|
||||
}
|
||||
|
||||
timestamp := ts.
|
||||
@@ -400,12 +406,16 @@ func renderText(
|
||||
|
||||
switch message.(type) {
|
||||
case opencode.UserMessage:
|
||||
borderColor := t.Secondary()
|
||||
if isQueued {
|
||||
borderColor = t.Accent()
|
||||
}
|
||||
return renderContentBlock(
|
||||
app,
|
||||
content,
|
||||
width,
|
||||
WithTextColor(t.Text()),
|
||||
WithBorderColor(t.Secondary()),
|
||||
WithBorderColor(borderColor),
|
||||
)
|
||||
case opencode.AssistantMessage:
|
||||
if isThinking {
|
||||
@@ -470,6 +480,8 @@ func renderToolDetails(
|
||||
backgroundColor := t.BackgroundPanel()
|
||||
borderColor := t.BackgroundPanel()
|
||||
defaultStyle := styles.NewStyle().Background(backgroundColor).Width(width - 6).Render
|
||||
baseStyle := styles.NewStyle().Background(backgroundColor).Foreground(t.Text()).Render
|
||||
mutedStyle := styles.NewStyle().Background(backgroundColor).Foreground(t.TextMuted()).Render
|
||||
|
||||
permissionContent := ""
|
||||
if permission.ID != "" {
|
||||
@@ -554,6 +566,17 @@ func renderToolDetails(
|
||||
title := renderToolTitle(toolCall, width)
|
||||
title = style.Render(title)
|
||||
content := title + "\n" + body
|
||||
|
||||
if toolCall.State.Status == opencode.ToolPartStateStatusError {
|
||||
errorStyle := styles.NewStyle().
|
||||
Background(backgroundColor).
|
||||
Foreground(t.Error()).
|
||||
Padding(1, 2).
|
||||
Width(width - 4)
|
||||
errorContent := errorStyle.Render(toolCall.State.Error)
|
||||
content += "\n" + errorContent
|
||||
}
|
||||
|
||||
if permissionContent != "" {
|
||||
permissionContent = styles.NewStyle().
|
||||
Background(backgroundColor).
|
||||
@@ -582,14 +605,15 @@ func renderToolDetails(
|
||||
}
|
||||
}
|
||||
case "bash":
|
||||
command := toolInputMap["command"].(string)
|
||||
body = fmt.Sprintf("```console\n$ %s\n", command)
|
||||
output := metadata["output"]
|
||||
if output != nil {
|
||||
body += ansi.Strip(fmt.Sprintf("%s", output))
|
||||
if command, ok := toolInputMap["command"].(string); ok {
|
||||
body = fmt.Sprintf("```console\n$ %s\n", command)
|
||||
output := metadata["output"]
|
||||
if output != nil {
|
||||
body += ansi.Strip(fmt.Sprintf("%s", output))
|
||||
}
|
||||
body += "```"
|
||||
body = util.ToMarkdown(body, width, backgroundColor)
|
||||
}
|
||||
body += "```"
|
||||
body = util.ToMarkdown(body, width, backgroundColor)
|
||||
case "webfetch":
|
||||
if format, ok := toolInputMap["format"].(string); ok && result != nil {
|
||||
body = *result
|
||||
@@ -633,6 +657,12 @@ func renderToolDetails(
|
||||
steps = append(steps, step)
|
||||
}
|
||||
body = strings.Join(steps, "\n")
|
||||
|
||||
body += "\n\n"
|
||||
body += baseStyle(app.Keybind(commands.SessionChildCycleCommand)) +
|
||||
mutedStyle(", ") +
|
||||
baseStyle(app.Keybind(commands.SessionChildCycleReverseCommand)) +
|
||||
mutedStyle(" navigate child sessions")
|
||||
}
|
||||
body = defaultStyle(body)
|
||||
default:
|
||||
@@ -652,11 +682,17 @@ func renderToolDetails(
|
||||
}
|
||||
|
||||
if error != "" {
|
||||
body = styles.NewStyle().
|
||||
errorContent := styles.NewStyle().
|
||||
Width(width - 6).
|
||||
Foreground(t.Error()).
|
||||
Background(backgroundColor).
|
||||
Render(error)
|
||||
|
||||
if body == "" {
|
||||
body = errorContent
|
||||
} else {
|
||||
body += "\n\n" + errorContent
|
||||
}
|
||||
}
|
||||
|
||||
if body == "" && error == "" && result != nil {
|
||||
|
||||
@@ -39,6 +39,7 @@ type MessagesComponent interface {
|
||||
CopyLastMessage() (tea.Model, tea.Cmd)
|
||||
UndoLastMessage() (tea.Model, tea.Cmd)
|
||||
RedoLastMessage() (tea.Model, tea.Cmd)
|
||||
ScrollToMessage(messageID string) (tea.Model, tea.Cmd)
|
||||
}
|
||||
|
||||
type messagesComponent struct {
|
||||
@@ -57,6 +58,7 @@ type messagesComponent struct {
|
||||
partCount int
|
||||
lineCount int
|
||||
selection *selection
|
||||
messagePositions map[string]int // map message ID to line position
|
||||
}
|
||||
|
||||
type selection struct {
|
||||
@@ -180,6 +182,8 @@ func (m *messagesComponent) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
m.tail = true
|
||||
return m, m.renderView()
|
||||
}
|
||||
case app.SessionSelectedMsg:
|
||||
m.viewport.GotoBottom()
|
||||
case app.MessageRevertedMsg:
|
||||
if msg.Session.ID == m.app.Session.ID {
|
||||
m.cache.Clear()
|
||||
@@ -226,6 +230,7 @@ func (m *messagesComponent) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
m.rendering = false
|
||||
m.clipboard = msg.clipboard
|
||||
m.loading = false
|
||||
m.messagePositions = msg.messagePositions
|
||||
m.tail = m.viewport.AtBottom()
|
||||
|
||||
// Preserve scroll across reflow
|
||||
@@ -254,11 +259,12 @@ func (m *messagesComponent) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
}
|
||||
|
||||
type renderCompleteMsg struct {
|
||||
viewport viewport.Model
|
||||
clipboard []string
|
||||
header string
|
||||
partCount int
|
||||
lineCount int
|
||||
viewport viewport.Model
|
||||
clipboard []string
|
||||
header string
|
||||
partCount int
|
||||
lineCount int
|
||||
messagePositions map[string]int
|
||||
}
|
||||
|
||||
func (m *messagesComponent) renderView() tea.Cmd {
|
||||
@@ -284,6 +290,7 @@ func (m *messagesComponent) renderView() tea.Cmd {
|
||||
blocks := make([]string, 0)
|
||||
partCount := 0
|
||||
lineCount := 0
|
||||
messagePositions := make(map[string]int) // Track message ID to line position
|
||||
|
||||
orphanedToolCalls := make([]opencode.ToolPart, 0)
|
||||
|
||||
@@ -306,6 +313,9 @@ func (m *messagesComponent) renderView() tea.Cmd {
|
||||
|
||||
switch casted := message.Info.(type) {
|
||||
case opencode.UserMessage:
|
||||
// Track the position of this user message
|
||||
messagePositions[casted.ID] = lineCount
|
||||
|
||||
if casted.ID == m.app.Session.Revert.MessageID {
|
||||
reverted = true
|
||||
revertedMessageCount = 1
|
||||
@@ -373,10 +383,8 @@ func (m *messagesComponent) renderView() tea.Cmd {
|
||||
)
|
||||
|
||||
author := m.app.Config.Username
|
||||
if casted.ID > lastAssistantMessage {
|
||||
author += " [queued]"
|
||||
}
|
||||
key := m.cache.GenerateKey(casted.ID, part.Text, width, files, author)
|
||||
isQueued := casted.ID > lastAssistantMessage
|
||||
key := m.cache.GenerateKey(casted.ID, part.Text, width, files, author, isQueued)
|
||||
content, cached = m.cache.Get(key)
|
||||
if !cached {
|
||||
content = renderText(
|
||||
@@ -388,6 +396,7 @@ func (m *messagesComponent) renderView() tea.Cmd {
|
||||
width,
|
||||
files,
|
||||
false,
|
||||
isQueued,
|
||||
fileParts,
|
||||
agentParts,
|
||||
)
|
||||
@@ -463,6 +472,7 @@ func (m *messagesComponent) renderView() tea.Cmd {
|
||||
width,
|
||||
"",
|
||||
false,
|
||||
false,
|
||||
[]opencode.FilePart{},
|
||||
[]opencode.AgentPart{},
|
||||
toolCallParts...,
|
||||
@@ -479,6 +489,7 @@ func (m *messagesComponent) renderView() tea.Cmd {
|
||||
width,
|
||||
"",
|
||||
false,
|
||||
false,
|
||||
[]opencode.FilePart{},
|
||||
[]opencode.AgentPart{},
|
||||
toolCallParts...,
|
||||
@@ -558,6 +569,7 @@ func (m *messagesComponent) renderView() tea.Cmd {
|
||||
width,
|
||||
"",
|
||||
true,
|
||||
false,
|
||||
[]opencode.FilePart{},
|
||||
[]opencode.AgentPart{},
|
||||
)
|
||||
@@ -591,6 +603,7 @@ func (m *messagesComponent) renderView() tea.Cmd {
|
||||
width,
|
||||
"",
|
||||
false,
|
||||
false,
|
||||
[]opencode.FilePart{},
|
||||
[]opencode.AgentPart{},
|
||||
)
|
||||
@@ -762,11 +775,12 @@ func (m *messagesComponent) renderView() tea.Cmd {
|
||||
}
|
||||
|
||||
return renderCompleteMsg{
|
||||
header: header,
|
||||
clipboard: clipboard,
|
||||
viewport: viewport,
|
||||
partCount: partCount,
|
||||
lineCount: lineCount,
|
||||
header: header,
|
||||
clipboard: clipboard,
|
||||
viewport: viewport,
|
||||
partCount: partCount,
|
||||
lineCount: lineCount,
|
||||
messagePositions: messagePositions,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -779,8 +793,17 @@ func (m *messagesComponent) renderHeader() string {
|
||||
headerWidth := m.width
|
||||
|
||||
t := theme.CurrentTheme()
|
||||
base := styles.NewStyle().Foreground(t.Text()).Background(t.Background()).Render
|
||||
muted := styles.NewStyle().Foreground(t.TextMuted()).Background(t.Background()).Render
|
||||
bgColor := t.Background()
|
||||
borderColor := t.BackgroundElement()
|
||||
|
||||
isChildSession := m.app.Session.ParentID != ""
|
||||
if isChildSession {
|
||||
bgColor = t.BackgroundElement()
|
||||
borderColor = t.Accent()
|
||||
}
|
||||
|
||||
base := styles.NewStyle().Foreground(t.Text()).Background(bgColor).Render
|
||||
muted := styles.NewStyle().Foreground(t.TextMuted()).Background(bgColor).Render
|
||||
|
||||
sessionInfo := ""
|
||||
tokens := float64(0)
|
||||
@@ -812,20 +835,44 @@ func (m *messagesComponent) renderHeader() string {
|
||||
sessionInfoText := formatTokensAndCost(tokens, contextWindow, cost, isSubscriptionModel)
|
||||
sessionInfo = styles.NewStyle().
|
||||
Foreground(t.TextMuted()).
|
||||
Background(t.Background()).
|
||||
Background(bgColor).
|
||||
Render(sessionInfoText)
|
||||
|
||||
shareEnabled := m.app.Config.Share != opencode.ConfigShareDisabled
|
||||
|
||||
navHint := ""
|
||||
if isChildSession {
|
||||
navHint = base(" "+m.app.Keybind(commands.SessionChildCycleReverseCommand)) + muted(" back")
|
||||
}
|
||||
|
||||
headerTextWidth := headerWidth
|
||||
if !shareEnabled {
|
||||
// +1 is to ensure there is always at least one space between header and session info
|
||||
headerTextWidth -= len(sessionInfoText) + 1
|
||||
if isChildSession {
|
||||
headerTextWidth -= lipgloss.Width(navHint)
|
||||
} else if !shareEnabled {
|
||||
headerTextWidth -= lipgloss.Width(sessionInfoText)
|
||||
}
|
||||
headerText := util.ToMarkdown(
|
||||
"# "+m.app.Session.Title,
|
||||
headerTextWidth,
|
||||
t.Background(),
|
||||
bgColor,
|
||||
)
|
||||
if isChildSession {
|
||||
headerText = layout.Render(
|
||||
layout.FlexOptions{
|
||||
Background: &bgColor,
|
||||
Direction: layout.Row,
|
||||
Justify: layout.JustifySpaceBetween,
|
||||
Align: layout.AlignStretch,
|
||||
Width: headerTextWidth,
|
||||
},
|
||||
layout.FlexItem{
|
||||
View: headerText,
|
||||
},
|
||||
layout.FlexItem{
|
||||
View: navHint,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
var items []layout.FlexItem
|
||||
if shareEnabled {
|
||||
@@ -838,10 +885,9 @@ func (m *messagesComponent) renderHeader() string {
|
||||
items = []layout.FlexItem{{View: headerText}, {View: sessionInfo}}
|
||||
}
|
||||
|
||||
background := t.Background()
|
||||
headerRow := layout.Render(
|
||||
layout.FlexOptions{
|
||||
Background: &background,
|
||||
Background: &bgColor,
|
||||
Direction: layout.Row,
|
||||
Justify: layout.JustifySpaceBetween,
|
||||
Align: layout.AlignStretch,
|
||||
@@ -857,14 +903,14 @@ func (m *messagesComponent) renderHeader() string {
|
||||
|
||||
header := strings.Join(headerLines, "\n")
|
||||
header = styles.NewStyle().
|
||||
Background(t.Background()).
|
||||
Background(bgColor).
|
||||
Width(headerWidth).
|
||||
PaddingLeft(2).
|
||||
PaddingRight(2).
|
||||
BorderLeft(true).
|
||||
BorderRight(true).
|
||||
BorderBackground(t.Background()).
|
||||
BorderForeground(t.BackgroundElement()).
|
||||
BorderForeground(borderColor).
|
||||
BorderStyle(lipgloss.ThickBorder()).
|
||||
Render(header)
|
||||
|
||||
@@ -911,7 +957,7 @@ func formatTokensAndCost(
|
||||
|
||||
formattedCost := fmt.Sprintf("$%.2f", cost)
|
||||
return fmt.Sprintf(
|
||||
"%s/%d%% (%s)",
|
||||
" %s/%d%% (%s)",
|
||||
formattedTokens,
|
||||
int(percentage),
|
||||
formattedCost,
|
||||
@@ -920,20 +966,22 @@ func formatTokensAndCost(
|
||||
|
||||
func (m *messagesComponent) View() string {
|
||||
t := theme.CurrentTheme()
|
||||
bgColor := t.Background()
|
||||
|
||||
if m.loading {
|
||||
return lipgloss.Place(
|
||||
m.width,
|
||||
m.height,
|
||||
lipgloss.Center,
|
||||
lipgloss.Center,
|
||||
styles.NewStyle().Background(t.Background()).Render(""),
|
||||
styles.WhitespaceStyle(t.Background()),
|
||||
styles.NewStyle().Background(bgColor).Render(""),
|
||||
styles.WhitespaceStyle(bgColor),
|
||||
)
|
||||
}
|
||||
|
||||
viewport := m.viewport.View()
|
||||
return styles.NewStyle().
|
||||
Background(t.Background()).
|
||||
Background(bgColor).
|
||||
Render(m.header + "\n" + viewport)
|
||||
}
|
||||
|
||||
@@ -1151,12 +1199,24 @@ func (m *messagesComponent) RedoLastMessage() (tea.Model, tea.Cmd) {
|
||||
}
|
||||
}
|
||||
|
||||
func (m *messagesComponent) ScrollToMessage(messageID string) (tea.Model, tea.Cmd) {
|
||||
if m.messagePositions == nil {
|
||||
return m, nil
|
||||
}
|
||||
|
||||
if position, exists := m.messagePositions[messageID]; exists {
|
||||
m.viewport.SetYOffset(position)
|
||||
m.tail = false // Stop auto-scrolling to bottom when manually navigating
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func NewMessagesComponent(app *app.App) MessagesComponent {
|
||||
vp := viewport.New()
|
||||
vp.KeyMap = viewport.KeyMap{}
|
||||
|
||||
if app.State.ScrollSpeed != nil && *app.State.ScrollSpeed > 0 {
|
||||
vp.MouseWheelDelta = *app.State.ScrollSpeed
|
||||
if app.ScrollSpeed > 0 {
|
||||
vp.MouseWheelDelta = app.ScrollSpeed
|
||||
} else {
|
||||
vp.MouseWheelDelta = 2
|
||||
}
|
||||
@@ -1179,5 +1239,6 @@ func NewMessagesComponent(app *app.App) MessagesComponent {
|
||||
showThinkingBlocks: showThinkingBlocks,
|
||||
cache: NewPartCache(),
|
||||
tail: true,
|
||||
messagePositions: make(map[string]int),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,20 +76,15 @@ func (a agentSelectItem) Render(
|
||||
|
||||
agentName := a.displayName
|
||||
|
||||
// For user agents and subagents, show description; for built-in, show mode
|
||||
// Determine if agent is built-in or custom using the agent's builtIn field
|
||||
var displayText string
|
||||
if a.description != "" && (a.mode == "all" || a.mode == "subagent") {
|
||||
// User agent or subagent with description
|
||||
displayText = a.description
|
||||
if a.agent.BuiltIn {
|
||||
displayText = "(built-in)"
|
||||
} else {
|
||||
// Built-in without description - show mode
|
||||
switch a.mode {
|
||||
case "primary":
|
||||
displayText = "(built-in)"
|
||||
case "all":
|
||||
if a.description != "" {
|
||||
displayText = a.description
|
||||
} else {
|
||||
displayText = "(user)"
|
||||
default:
|
||||
displayText = ""
|
||||
}
|
||||
}
|
||||
|
||||
@@ -206,23 +201,19 @@ func (a *agentDialog) calculateOptimalWidth(agents []agentSelectItem) int {
|
||||
for _, agent := range agents {
|
||||
// Calculate the width needed for this item: "AgentName - Description" (visual improvement)
|
||||
itemWidth := len(agent.displayName)
|
||||
if agent.description != "" && (agent.mode == "all" || agent.mode == "subagent") {
|
||||
// User agent or subagent - use description (capped to maxDescriptionLength)
|
||||
descLength := len(agent.description)
|
||||
if descLength > maxDescriptionLength {
|
||||
descLength = maxDescriptionLength
|
||||
}
|
||||
itemWidth += descLength + 3 // " - "
|
||||
|
||||
if agent.agent.BuiltIn {
|
||||
itemWidth += len("(built-in)") + 3 // " - "
|
||||
} else {
|
||||
// Built-in without description - use mode
|
||||
var modeText string
|
||||
switch agent.mode {
|
||||
case "primary":
|
||||
modeText = "(built-in)"
|
||||
case "all":
|
||||
modeText = "(user)"
|
||||
if agent.description != "" {
|
||||
descLength := len(agent.description)
|
||||
if descLength > maxDescriptionLength {
|
||||
descLength = maxDescriptionLength
|
||||
}
|
||||
itemWidth += descLength + 3 // " - "
|
||||
} else {
|
||||
itemWidth += len("(user)") + 3 // " - "
|
||||
}
|
||||
itemWidth += len(modeText) + 3 // " - "
|
||||
}
|
||||
|
||||
if itemWidth > maxWidth {
|
||||
|
||||
@@ -1,236 +0,0 @@
|
||||
package dialog
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
|
||||
tea "github.com/charmbracelet/bubbletea/v2"
|
||||
"github.com/sst/opencode/internal/completions"
|
||||
"github.com/sst/opencode/internal/components/list"
|
||||
"github.com/sst/opencode/internal/components/modal"
|
||||
"github.com/sst/opencode/internal/layout"
|
||||
"github.com/sst/opencode/internal/styles"
|
||||
"github.com/sst/opencode/internal/theme"
|
||||
"github.com/sst/opencode/internal/util"
|
||||
)
|
||||
|
||||
const (
|
||||
findDialogWidth = 76
|
||||
)
|
||||
|
||||
type FindSelectedMsg struct {
|
||||
FilePath string
|
||||
}
|
||||
|
||||
type FindDialogCloseMsg struct{}
|
||||
|
||||
type findInitialSuggestionsMsg struct {
|
||||
suggestions []completions.CompletionSuggestion
|
||||
}
|
||||
|
||||
type FindDialog interface {
|
||||
layout.Modal
|
||||
tea.Model
|
||||
tea.ViewModel
|
||||
SetWidth(width int)
|
||||
SetHeight(height int)
|
||||
IsEmpty() bool
|
||||
}
|
||||
|
||||
// findItem is a custom list item for file suggestions
|
||||
type findItem struct {
|
||||
suggestion completions.CompletionSuggestion
|
||||
}
|
||||
|
||||
func (f findItem) Render(
|
||||
selected bool,
|
||||
width int,
|
||||
baseStyle styles.Style,
|
||||
) string {
|
||||
t := theme.CurrentTheme()
|
||||
|
||||
itemStyle := baseStyle.
|
||||
Background(t.BackgroundPanel()).
|
||||
Foreground(t.TextMuted())
|
||||
|
||||
if selected {
|
||||
itemStyle = itemStyle.Foreground(t.Primary())
|
||||
}
|
||||
|
||||
return itemStyle.PaddingLeft(1).Render(f.suggestion.Display(itemStyle))
|
||||
}
|
||||
|
||||
func (f findItem) Selectable() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
type findDialogComponent struct {
|
||||
completionProvider completions.CompletionProvider
|
||||
allSuggestions []completions.CompletionSuggestion
|
||||
width, height int
|
||||
modal *modal.Modal
|
||||
searchDialog *SearchDialog
|
||||
dialogWidth int
|
||||
}
|
||||
|
||||
func (f *findDialogComponent) Init() tea.Cmd {
|
||||
return tea.Batch(
|
||||
f.loadInitialSuggestions(),
|
||||
f.searchDialog.Init(),
|
||||
)
|
||||
}
|
||||
|
||||
func (f *findDialogComponent) loadInitialSuggestions() tea.Cmd {
|
||||
return func() tea.Msg {
|
||||
items, err := f.completionProvider.GetChildEntries("")
|
||||
if err != nil {
|
||||
slog.Error("Failed to get initial completion items", "error", err)
|
||||
return findInitialSuggestionsMsg{suggestions: []completions.CompletionSuggestion{}}
|
||||
}
|
||||
return findInitialSuggestionsMsg{suggestions: items}
|
||||
}
|
||||
}
|
||||
|
||||
func (f *findDialogComponent) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
switch msg := msg.(type) {
|
||||
case findInitialSuggestionsMsg:
|
||||
// Handle initial suggestions setup
|
||||
f.allSuggestions = msg.suggestions
|
||||
|
||||
// Calculate dialog width
|
||||
f.dialogWidth = f.calculateDialogWidth()
|
||||
|
||||
// Initialize search dialog with calculated width
|
||||
f.searchDialog = NewSearchDialog("Search files...", 10)
|
||||
f.searchDialog.SetWidth(f.dialogWidth)
|
||||
|
||||
// Convert to list items
|
||||
items := make([]list.Item, len(f.allSuggestions))
|
||||
for i, suggestion := range f.allSuggestions {
|
||||
items[i] = findItem{suggestion: suggestion}
|
||||
}
|
||||
f.searchDialog.SetItems(items)
|
||||
|
||||
// Update modal with calculated width
|
||||
f.modal = modal.New(
|
||||
modal.WithTitle("Find Files"),
|
||||
modal.WithMaxWidth(f.dialogWidth+4),
|
||||
)
|
||||
|
||||
return f, f.searchDialog.Init()
|
||||
|
||||
case []completions.CompletionSuggestion:
|
||||
// Store suggestions and convert to findItem for the search dialog
|
||||
f.allSuggestions = msg
|
||||
items := make([]list.Item, len(msg))
|
||||
for i, suggestion := range msg {
|
||||
items[i] = findItem{suggestion: suggestion}
|
||||
}
|
||||
f.searchDialog.SetItems(items)
|
||||
return f, nil
|
||||
|
||||
case SearchSelectionMsg:
|
||||
// Handle selection from search dialog - now we can directly access the suggestion
|
||||
if item, ok := msg.Item.(findItem); ok {
|
||||
return f, f.selectFile(item.suggestion)
|
||||
}
|
||||
return f, nil
|
||||
|
||||
case SearchCancelledMsg:
|
||||
return f, f.Close()
|
||||
|
||||
case SearchQueryChangedMsg:
|
||||
// Update completion items based on search query
|
||||
return f, func() tea.Msg {
|
||||
items, err := f.completionProvider.GetChildEntries(msg.Query)
|
||||
if err != nil {
|
||||
slog.Error("Failed to get completion items", "error", err)
|
||||
return []completions.CompletionSuggestion{}
|
||||
}
|
||||
return items
|
||||
}
|
||||
|
||||
case tea.WindowSizeMsg:
|
||||
f.width = msg.Width
|
||||
f.height = msg.Height
|
||||
// Recalculate width based on new viewport size
|
||||
oldWidth := f.dialogWidth
|
||||
f.dialogWidth = f.calculateDialogWidth()
|
||||
if oldWidth != f.dialogWidth {
|
||||
f.searchDialog.SetWidth(f.dialogWidth)
|
||||
// Update modal max width too
|
||||
f.modal = modal.New(
|
||||
modal.WithTitle("Find Files"),
|
||||
modal.WithMaxWidth(f.dialogWidth+4),
|
||||
)
|
||||
}
|
||||
f.searchDialog.SetHeight(msg.Height)
|
||||
}
|
||||
|
||||
// Forward all other messages to the search dialog
|
||||
updatedDialog, cmd := f.searchDialog.Update(msg)
|
||||
f.searchDialog = updatedDialog.(*SearchDialog)
|
||||
return f, cmd
|
||||
}
|
||||
|
||||
func (f *findDialogComponent) View() string {
|
||||
return f.searchDialog.View()
|
||||
}
|
||||
|
||||
func (f *findDialogComponent) calculateDialogWidth() int {
|
||||
// Use fixed width unless viewport is smaller
|
||||
if f.width > 0 && f.width < findDialogWidth+10 {
|
||||
return f.width - 10
|
||||
}
|
||||
return findDialogWidth
|
||||
}
|
||||
|
||||
func (f *findDialogComponent) SetWidth(width int) {
|
||||
f.width = width
|
||||
f.searchDialog.SetWidth(f.dialogWidth)
|
||||
}
|
||||
|
||||
func (f *findDialogComponent) SetHeight(height int) {
|
||||
f.height = height
|
||||
}
|
||||
|
||||
func (f *findDialogComponent) IsEmpty() bool {
|
||||
return f.searchDialog.GetQuery() == ""
|
||||
}
|
||||
|
||||
func (f *findDialogComponent) selectFile(item completions.CompletionSuggestion) tea.Cmd {
|
||||
return tea.Sequence(
|
||||
f.Close(),
|
||||
util.CmdHandler(FindSelectedMsg{
|
||||
FilePath: item.Value,
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
func (f *findDialogComponent) Render(background string) string {
|
||||
return f.modal.Render(f.View(), background)
|
||||
}
|
||||
|
||||
func (f *findDialogComponent) Close() tea.Cmd {
|
||||
f.searchDialog.SetQuery("")
|
||||
f.searchDialog.Blur()
|
||||
return util.CmdHandler(modal.CloseModalMsg{})
|
||||
}
|
||||
|
||||
func NewFindDialog(completionProvider completions.CompletionProvider) FindDialog {
|
||||
component := &findDialogComponent{
|
||||
completionProvider: completionProvider,
|
||||
dialogWidth: findDialogWidth,
|
||||
allSuggestions: []completions.CompletionSuggestion{},
|
||||
}
|
||||
|
||||
// Create search dialog and modal with fixed width
|
||||
component.searchDialog = NewSearchDialog("Search files...", 10)
|
||||
component.searchDialog.SetWidth(findDialogWidth)
|
||||
|
||||
component.modal = modal.New(
|
||||
modal.WithTitle("Find Files"),
|
||||
modal.WithMaxWidth(findDialogWidth+4),
|
||||
)
|
||||
|
||||
return component
|
||||
}
|
||||
@@ -1,184 +0,0 @@
|
||||
package dialog
|
||||
|
||||
import (
|
||||
"github.com/charmbracelet/bubbles/v2/key"
|
||||
tea "github.com/charmbracelet/bubbletea/v2"
|
||||
"github.com/charmbracelet/lipgloss/v2"
|
||||
|
||||
"github.com/sst/opencode/internal/styles"
|
||||
"github.com/sst/opencode/internal/theme"
|
||||
"github.com/sst/opencode/internal/util"
|
||||
)
|
||||
|
||||
// InitDialogCmp is a component that asks the user if they want to initialize the project.
|
||||
type InitDialogCmp struct {
|
||||
width, height int
|
||||
selected int
|
||||
keys initDialogKeyMap
|
||||
}
|
||||
|
||||
// NewInitDialogCmp creates a new InitDialogCmp.
|
||||
func NewInitDialogCmp() InitDialogCmp {
|
||||
return InitDialogCmp{
|
||||
selected: 0,
|
||||
keys: initDialogKeyMap{},
|
||||
}
|
||||
}
|
||||
|
||||
type initDialogKeyMap struct {
|
||||
Tab key.Binding
|
||||
Left key.Binding
|
||||
Right key.Binding
|
||||
Enter key.Binding
|
||||
Escape key.Binding
|
||||
Y key.Binding
|
||||
N key.Binding
|
||||
}
|
||||
|
||||
// ShortHelp implements key.Map.
|
||||
func (k initDialogKeyMap) ShortHelp() []key.Binding {
|
||||
return []key.Binding{
|
||||
key.NewBinding(
|
||||
key.WithKeys("tab", "left", "right"),
|
||||
key.WithHelp("tab/←/→", "toggle selection"),
|
||||
),
|
||||
key.NewBinding(
|
||||
key.WithKeys("enter"),
|
||||
key.WithHelp("enter", "confirm"),
|
||||
),
|
||||
key.NewBinding(
|
||||
key.WithKeys("esc", "q"),
|
||||
key.WithHelp("esc/q", "cancel"),
|
||||
),
|
||||
key.NewBinding(
|
||||
key.WithKeys("y", "n"),
|
||||
key.WithHelp("y/n", "yes/no"),
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
// FullHelp implements key.Map.
|
||||
func (k initDialogKeyMap) FullHelp() [][]key.Binding {
|
||||
return [][]key.Binding{k.ShortHelp()}
|
||||
}
|
||||
|
||||
// Init implements tea.Model.
|
||||
func (m InitDialogCmp) Init() tea.Cmd {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Update implements tea.Model.
|
||||
func (m InitDialogCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
switch msg := msg.(type) {
|
||||
case tea.KeyMsg:
|
||||
switch {
|
||||
case key.Matches(msg, key.NewBinding(key.WithKeys("esc"))):
|
||||
return m, util.CmdHandler(CloseInitDialogMsg{Initialize: false})
|
||||
case key.Matches(msg, key.NewBinding(key.WithKeys("tab", "left", "right", "h", "l"))):
|
||||
m.selected = (m.selected + 1) % 2
|
||||
return m, nil
|
||||
case key.Matches(msg, key.NewBinding(key.WithKeys("enter"))):
|
||||
return m, util.CmdHandler(CloseInitDialogMsg{Initialize: m.selected == 0})
|
||||
case key.Matches(msg, key.NewBinding(key.WithKeys("y"))):
|
||||
return m, util.CmdHandler(CloseInitDialogMsg{Initialize: true})
|
||||
case key.Matches(msg, key.NewBinding(key.WithKeys("n"))):
|
||||
return m, util.CmdHandler(CloseInitDialogMsg{Initialize: false})
|
||||
}
|
||||
case tea.WindowSizeMsg:
|
||||
m.width = msg.Width
|
||||
m.height = msg.Height
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// View implements tea.Model.
|
||||
func (m InitDialogCmp) View() string {
|
||||
t := theme.CurrentTheme()
|
||||
baseStyle := styles.NewStyle().Foreground(t.Text())
|
||||
|
||||
// Calculate width needed for content
|
||||
maxWidth := 60 // Width for explanation text
|
||||
|
||||
title := baseStyle.
|
||||
Foreground(t.Primary()).
|
||||
Bold(true).
|
||||
Width(maxWidth).
|
||||
Padding(0, 1).
|
||||
Render("Initialize Project")
|
||||
|
||||
explanation := baseStyle.
|
||||
Foreground(t.Text()).
|
||||
Width(maxWidth).
|
||||
Padding(0, 1).
|
||||
Render("Initialization generates a new AGENTS.md file that contains information about your codebase, this file serves as memory for each project, you can freely add to it to help the agents be better at their job.")
|
||||
|
||||
question := baseStyle.
|
||||
Foreground(t.Text()).
|
||||
Width(maxWidth).
|
||||
Padding(1, 1).
|
||||
Render("Would you like to initialize this project?")
|
||||
|
||||
maxWidth = min(maxWidth, m.width-10)
|
||||
yesStyle := baseStyle
|
||||
noStyle := baseStyle
|
||||
|
||||
if m.selected == 0 {
|
||||
yesStyle = yesStyle.
|
||||
Background(t.Primary()).
|
||||
Foreground(t.Background()).
|
||||
Bold(true)
|
||||
noStyle = noStyle.
|
||||
Background(t.Background()).
|
||||
Foreground(t.Primary())
|
||||
} else {
|
||||
noStyle = noStyle.
|
||||
Background(t.Primary()).
|
||||
Foreground(t.Background()).
|
||||
Bold(true)
|
||||
yesStyle = yesStyle.
|
||||
Background(t.Background()).
|
||||
Foreground(t.Primary())
|
||||
}
|
||||
|
||||
yes := yesStyle.Padding(0, 3).Render("Yes")
|
||||
no := noStyle.Padding(0, 3).Render("No")
|
||||
|
||||
buttons := lipgloss.JoinHorizontal(lipgloss.Center, yes, baseStyle.Render(" "), no)
|
||||
buttons = baseStyle.
|
||||
Width(maxWidth).
|
||||
Padding(1, 0).
|
||||
Render(buttons)
|
||||
|
||||
content := lipgloss.JoinVertical(
|
||||
lipgloss.Left,
|
||||
title,
|
||||
baseStyle.Width(maxWidth).Render(""),
|
||||
explanation,
|
||||
question,
|
||||
buttons,
|
||||
baseStyle.Width(maxWidth).Render(""),
|
||||
)
|
||||
|
||||
return baseStyle.Padding(1, 2).
|
||||
Border(lipgloss.RoundedBorder()).
|
||||
BorderBackground(t.Background()).
|
||||
BorderForeground(t.TextMuted()).
|
||||
Width(lipgloss.Width(content) + 4).
|
||||
Render(content)
|
||||
}
|
||||
|
||||
// SetSize sets the size of the component.
|
||||
func (m *InitDialogCmp) SetSize(width, height int) {
|
||||
m.width = width
|
||||
m.height = height
|
||||
}
|
||||
|
||||
// CloseInitDialogMsg is a message that is sent when the init dialog is closed.
|
||||
type CloseInitDialogMsg struct {
|
||||
Initialize bool
|
||||
}
|
||||
|
||||
// ShowInitDialogMsg is a message that is sent to show the init dialog.
|
||||
type ShowInitDialogMsg struct {
|
||||
Show bool
|
||||
}
|
||||
@@ -0,0 +1,315 @@
|
||||
package dialog
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
tea "github.com/charmbracelet/bubbletea/v2"
|
||||
"github.com/charmbracelet/lipgloss/v2"
|
||||
"github.com/muesli/reflow/truncate"
|
||||
"github.com/sst/opencode-sdk-go"
|
||||
"github.com/sst/opencode/internal/app"
|
||||
"github.com/sst/opencode/internal/components/list"
|
||||
"github.com/sst/opencode/internal/components/modal"
|
||||
"github.com/sst/opencode/internal/layout"
|
||||
"github.com/sst/opencode/internal/styles"
|
||||
"github.com/sst/opencode/internal/theme"
|
||||
"github.com/sst/opencode/internal/util"
|
||||
)
|
||||
|
||||
// NavigationDialog interface for the session navigation dialog
|
||||
type NavigationDialog interface {
|
||||
layout.Modal
|
||||
}
|
||||
|
||||
// ScrollToMessageMsg is sent when a message should be scrolled to
|
||||
type ScrollToMessageMsg struct {
|
||||
MessageID string
|
||||
}
|
||||
|
||||
// RestoreToMessageMsg is sent when conversation should be restored to a specific message
|
||||
type RestoreToMessageMsg struct {
|
||||
MessageID string
|
||||
Index int
|
||||
}
|
||||
|
||||
// navigationItem represents a user message in the navigation list
|
||||
type navigationItem struct {
|
||||
messageID string
|
||||
content string
|
||||
timestamp time.Time
|
||||
index int // Index in the full message list
|
||||
toolCount int // Number of tools used in this message
|
||||
}
|
||||
|
||||
func (n navigationItem) Render(
|
||||
selected bool,
|
||||
width int,
|
||||
isFirstInViewport bool,
|
||||
baseStyle styles.Style,
|
||||
) string {
|
||||
t := theme.CurrentTheme()
|
||||
infoStyle := baseStyle.Background(t.BackgroundPanel()).Foreground(t.Info()).Render
|
||||
textStyle := baseStyle.Background(t.BackgroundPanel()).Foreground(t.Text()).Render
|
||||
|
||||
// Format timestamp - only apply color when not selected
|
||||
var timeStr string
|
||||
var timeVisualLen int
|
||||
if selected {
|
||||
timeStr = n.timestamp.Format("15:04") + " "
|
||||
timeVisualLen = lipgloss.Width(timeStr)
|
||||
} else {
|
||||
timeStr = infoStyle(n.timestamp.Format("15:04") + " ")
|
||||
timeVisualLen = lipgloss.Width(timeStr)
|
||||
}
|
||||
|
||||
// Tool count display (fixed width for alignment) - only apply color when not selected
|
||||
toolInfo := ""
|
||||
toolInfoVisualLen := 0
|
||||
if n.toolCount > 0 {
|
||||
toolInfoText := fmt.Sprintf("(%d tools)", n.toolCount)
|
||||
if selected {
|
||||
toolInfo = toolInfoText
|
||||
} else {
|
||||
toolInfo = infoStyle(toolInfoText)
|
||||
}
|
||||
toolInfoVisualLen = lipgloss.Width(toolInfo)
|
||||
}
|
||||
|
||||
// Calculate available space for content
|
||||
// Reserve space for: timestamp + space + toolInfo + padding + some buffer
|
||||
reservedSpace := timeVisualLen + 1 + toolInfoVisualLen + 4
|
||||
contentWidth := max(width-reservedSpace, 8)
|
||||
|
||||
truncatedContent := truncate.StringWithTail(
|
||||
strings.Split(n.content, "\n")[0],
|
||||
uint(contentWidth),
|
||||
"...",
|
||||
)
|
||||
|
||||
// Apply normal text color to content for non-selected items
|
||||
var styledContent string
|
||||
if selected {
|
||||
styledContent = truncatedContent
|
||||
} else {
|
||||
styledContent = textStyle(truncatedContent)
|
||||
}
|
||||
|
||||
// Create the line with proper spacing - content left-aligned, tools right-aligned
|
||||
var text string
|
||||
text = timeStr + styledContent
|
||||
if toolInfo != "" {
|
||||
bgColor := t.BackgroundPanel()
|
||||
if selected {
|
||||
bgColor = t.Primary()
|
||||
}
|
||||
text = layout.Render(
|
||||
layout.FlexOptions{
|
||||
Background: &bgColor,
|
||||
Direction: layout.Row,
|
||||
Justify: layout.JustifySpaceBetween,
|
||||
Align: layout.AlignStretch,
|
||||
Width: width - 2,
|
||||
},
|
||||
layout.FlexItem{
|
||||
View: text,
|
||||
},
|
||||
layout.FlexItem{
|
||||
View: toolInfo,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
var itemStyle styles.Style
|
||||
if selected {
|
||||
itemStyle = baseStyle.
|
||||
Background(t.Primary()).
|
||||
Foreground(t.BackgroundElement()).
|
||||
Width(width).
|
||||
PaddingLeft(1)
|
||||
} else {
|
||||
itemStyle = baseStyle.PaddingLeft(1)
|
||||
}
|
||||
|
||||
return itemStyle.Render(text)
|
||||
}
|
||||
|
||||
func (n navigationItem) Selectable() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
type navigationDialog struct {
|
||||
width int
|
||||
height int
|
||||
modal *modal.Modal
|
||||
list list.List[navigationItem]
|
||||
app *app.App
|
||||
}
|
||||
|
||||
func (n *navigationDialog) Init() tea.Cmd {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (n *navigationDialog) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
switch msg := msg.(type) {
|
||||
case tea.WindowSizeMsg:
|
||||
n.width = msg.Width
|
||||
n.height = msg.Height
|
||||
n.list.SetMaxWidth(layout.Current.Container.Width - 12)
|
||||
case tea.KeyPressMsg:
|
||||
switch msg.String() {
|
||||
case "up", "down":
|
||||
// Handle navigation and immediately scroll to selected message
|
||||
var cmd tea.Cmd
|
||||
listModel, cmd := n.list.Update(msg)
|
||||
n.list = listModel.(list.List[navigationItem])
|
||||
|
||||
// Get the newly selected item and scroll to it immediately
|
||||
if item, idx := n.list.GetSelectedItem(); idx >= 0 {
|
||||
return n, tea.Sequence(
|
||||
cmd,
|
||||
util.CmdHandler(ScrollToMessageMsg{MessageID: item.messageID}),
|
||||
)
|
||||
}
|
||||
return n, cmd
|
||||
case "r":
|
||||
// Restore conversation to selected message
|
||||
if item, idx := n.list.GetSelectedItem(); idx >= 0 {
|
||||
return n, tea.Sequence(
|
||||
util.CmdHandler(RestoreToMessageMsg{MessageID: item.messageID, Index: item.index}),
|
||||
util.CmdHandler(modal.CloseModalMsg{}),
|
||||
)
|
||||
}
|
||||
case "enter":
|
||||
// Keep Enter functionality for closing the modal
|
||||
if _, idx := n.list.GetSelectedItem(); idx >= 0 {
|
||||
return n, util.CmdHandler(modal.CloseModalMsg{})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var cmd tea.Cmd
|
||||
listModel, cmd := n.list.Update(msg)
|
||||
n.list = listModel.(list.List[navigationItem])
|
||||
return n, cmd
|
||||
}
|
||||
|
||||
func (n *navigationDialog) Render(background string) string {
|
||||
listView := n.list.View()
|
||||
|
||||
t := theme.CurrentTheme()
|
||||
keyStyle := styles.NewStyle().
|
||||
Foreground(t.Text()).
|
||||
Background(t.BackgroundPanel()).
|
||||
Bold(true).
|
||||
Render
|
||||
mutedStyle := styles.NewStyle().Foreground(t.TextMuted()).Background(t.BackgroundPanel()).Render
|
||||
|
||||
helpText := keyStyle(
|
||||
"↑/↓",
|
||||
) + mutedStyle(
|
||||
" jump ",
|
||||
) + keyStyle(
|
||||
"r",
|
||||
) + mutedStyle(
|
||||
" restore",
|
||||
)
|
||||
|
||||
bgColor := t.BackgroundPanel()
|
||||
helpView := styles.NewStyle().
|
||||
Background(bgColor).
|
||||
Width(layout.Current.Container.Width - 14).
|
||||
PaddingLeft(1).
|
||||
PaddingTop(1).
|
||||
Render(helpText)
|
||||
|
||||
content := strings.Join([]string{listView, helpView}, "\n")
|
||||
|
||||
return n.modal.Render(content, background)
|
||||
}
|
||||
|
||||
func (n *navigationDialog) Close() tea.Cmd {
|
||||
return nil
|
||||
}
|
||||
|
||||
// extractMessagePreview extracts a preview from message parts
|
||||
func extractMessagePreview(parts []opencode.PartUnion) string {
|
||||
for _, part := range parts {
|
||||
switch casted := part.(type) {
|
||||
case opencode.TextPart:
|
||||
text := strings.TrimSpace(casted.Text)
|
||||
if text != "" {
|
||||
return text
|
||||
}
|
||||
}
|
||||
}
|
||||
return "No text content"
|
||||
}
|
||||
|
||||
// countToolsInResponse counts tools in the assistant's response to a user message
|
||||
func countToolsInResponse(messages []app.Message, userMessageIndex int) int {
|
||||
count := 0
|
||||
// Look at subsequent messages to find the assistant's response
|
||||
for i := userMessageIndex + 1; i < len(messages); i++ {
|
||||
message := messages[i]
|
||||
// If we hit another user message, stop looking
|
||||
if _, isUser := message.Info.(opencode.UserMessage); isUser {
|
||||
break
|
||||
}
|
||||
// Count tools in this assistant message
|
||||
for _, part := range message.Parts {
|
||||
switch part.(type) {
|
||||
case opencode.ToolPart:
|
||||
count++
|
||||
}
|
||||
}
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
// NewNavigationDialog creates a new session navigation dialog
|
||||
func NewNavigationDialog(app *app.App) NavigationDialog {
|
||||
var items []navigationItem
|
||||
|
||||
// Filter to only user messages and extract relevant info
|
||||
for i, message := range app.Messages {
|
||||
if userMsg, ok := message.Info.(opencode.UserMessage); ok {
|
||||
preview := extractMessagePreview(message.Parts)
|
||||
toolCount := countToolsInResponse(app.Messages, i)
|
||||
|
||||
items = append(items, navigationItem{
|
||||
messageID: userMsg.ID,
|
||||
content: preview,
|
||||
timestamp: time.UnixMilli(int64(userMsg.Time.Created)),
|
||||
index: i,
|
||||
toolCount: toolCount,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
listComponent := list.NewListComponent(
|
||||
list.WithItems(items),
|
||||
list.WithMaxVisibleHeight[navigationItem](12),
|
||||
list.WithFallbackMessage[navigationItem]("No user messages in this session"),
|
||||
list.WithAlphaNumericKeys[navigationItem](true),
|
||||
list.WithRenderFunc(
|
||||
func(item navigationItem, selected bool, width int, baseStyle styles.Style) string {
|
||||
return item.Render(selected, width, false, baseStyle)
|
||||
},
|
||||
),
|
||||
list.WithSelectableFunc(func(item navigationItem) bool {
|
||||
return true
|
||||
}),
|
||||
)
|
||||
listComponent.SetMaxWidth(layout.Current.Container.Width - 12)
|
||||
|
||||
return &navigationDialog{
|
||||
list: listComponent,
|
||||
app: app,
|
||||
modal: modal.New(
|
||||
modal.WithTitle("Jump to Message"),
|
||||
modal.WithMaxWidth(layout.Current.Container.Width-8),
|
||||
),
|
||||
}
|
||||
}
|
||||
@@ -234,7 +234,10 @@ func (s *sessionDialog) Render(background string) string {
|
||||
t := theme.CurrentTheme()
|
||||
renameView := s.renameInput.View()
|
||||
|
||||
mutedStyle := styles.NewStyle().Foreground(t.TextMuted()).Background(t.BackgroundPanel()).Render
|
||||
mutedStyle := styles.NewStyle().
|
||||
Foreground(t.TextMuted()).
|
||||
Background(t.BackgroundPanel()).
|
||||
Render
|
||||
helpText := mutedStyle("Enter to confirm, Esc to cancel")
|
||||
helpText = styles.NewStyle().PaddingLeft(1).PaddingTop(1).Render(helpText)
|
||||
|
||||
@@ -245,11 +248,15 @@ func (s *sessionDialog) Render(background string) string {
|
||||
listView := s.list.View()
|
||||
|
||||
t := theme.CurrentTheme()
|
||||
keyStyle := styles.NewStyle().Foreground(t.Text()).Background(t.BackgroundPanel()).Render
|
||||
keyStyle := styles.NewStyle().
|
||||
Foreground(t.Text()).
|
||||
Background(t.BackgroundPanel()).
|
||||
Bold(true).
|
||||
Render
|
||||
mutedStyle := styles.NewStyle().Foreground(t.TextMuted()).Background(t.BackgroundPanel()).Render
|
||||
|
||||
leftHelp := keyStyle("n") + mutedStyle(" new session") + " " + keyStyle("r") + mutedStyle(" rename")
|
||||
rightHelp := keyStyle("x/del") + mutedStyle(" delete session")
|
||||
leftHelp := keyStyle("n") + mutedStyle(" new ") + keyStyle("r") + mutedStyle(" rename")
|
||||
rightHelp := keyStyle("x/del") + mutedStyle(" delete")
|
||||
|
||||
bgColor := t.BackgroundPanel()
|
||||
helpText := layout.Render(layout.FlexOptions{
|
||||
|
||||
@@ -1,281 +0,0 @@
|
||||
package fileviewer
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
tea "github.com/charmbracelet/bubbletea/v2"
|
||||
|
||||
"github.com/sst/opencode/internal/app"
|
||||
"github.com/sst/opencode/internal/commands"
|
||||
"github.com/sst/opencode/internal/components/dialog"
|
||||
"github.com/sst/opencode/internal/components/diff"
|
||||
"github.com/sst/opencode/internal/layout"
|
||||
"github.com/sst/opencode/internal/styles"
|
||||
"github.com/sst/opencode/internal/theme"
|
||||
"github.com/sst/opencode/internal/util"
|
||||
"github.com/sst/opencode/internal/viewport"
|
||||
)
|
||||
|
||||
type DiffStyle int
|
||||
|
||||
const (
|
||||
DiffStyleSplit DiffStyle = iota
|
||||
DiffStyleUnified
|
||||
)
|
||||
|
||||
type Model struct {
|
||||
app *app.App
|
||||
width, height int
|
||||
viewport viewport.Model
|
||||
filename *string
|
||||
content *string
|
||||
isDiff *bool
|
||||
diffStyle DiffStyle
|
||||
}
|
||||
|
||||
type fileRenderedMsg struct {
|
||||
content string
|
||||
}
|
||||
|
||||
func New(app *app.App) Model {
|
||||
vp := viewport.New()
|
||||
m := Model{
|
||||
app: app,
|
||||
viewport: vp,
|
||||
diffStyle: DiffStyleUnified,
|
||||
}
|
||||
if app.State.SplitDiff {
|
||||
m.diffStyle = DiffStyleSplit
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
func (m Model) Init() tea.Cmd {
|
||||
return m.viewport.Init()
|
||||
}
|
||||
|
||||
func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
|
||||
var cmds []tea.Cmd
|
||||
|
||||
switch msg := msg.(type) {
|
||||
case fileRenderedMsg:
|
||||
m.viewport.SetContent(msg.content)
|
||||
return m, util.CmdHandler(app.FileRenderedMsg{
|
||||
FilePath: *m.filename,
|
||||
})
|
||||
case dialog.ThemeSelectedMsg:
|
||||
return m, m.render()
|
||||
case tea.KeyMsg:
|
||||
switch msg.String() {
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
|
||||
vp, cmd := m.viewport.Update(msg)
|
||||
m.viewport = vp
|
||||
cmds = append(cmds, cmd)
|
||||
|
||||
return m, tea.Batch(cmds...)
|
||||
}
|
||||
|
||||
func (m Model) View() string {
|
||||
if !m.HasFile() {
|
||||
return ""
|
||||
}
|
||||
|
||||
header := *m.filename
|
||||
header = styles.NewStyle().
|
||||
Padding(1, 2).
|
||||
Width(m.width).
|
||||
Background(theme.CurrentTheme().BackgroundElement()).
|
||||
Foreground(theme.CurrentTheme().Text()).
|
||||
Render(header)
|
||||
|
||||
t := theme.CurrentTheme()
|
||||
|
||||
close := m.app.Key(commands.FileCloseCommand)
|
||||
diffToggle := m.app.Key(commands.FileDiffToggleCommand)
|
||||
if m.isDiff == nil || *m.isDiff == false {
|
||||
diffToggle = ""
|
||||
}
|
||||
layoutToggle := m.app.Key(commands.MessagesLayoutToggleCommand)
|
||||
|
||||
background := t.Background()
|
||||
footer := layout.Render(
|
||||
layout.FlexOptions{
|
||||
Background: &background,
|
||||
Direction: layout.Row,
|
||||
Justify: layout.JustifyCenter,
|
||||
Align: layout.AlignStretch,
|
||||
Width: m.width - 2,
|
||||
Gap: 5,
|
||||
},
|
||||
layout.FlexItem{
|
||||
View: close,
|
||||
},
|
||||
layout.FlexItem{
|
||||
View: layoutToggle,
|
||||
},
|
||||
layout.FlexItem{
|
||||
View: diffToggle,
|
||||
},
|
||||
)
|
||||
footer = styles.NewStyle().Background(t.Background()).Padding(0, 1).Render(footer)
|
||||
|
||||
return header + "\n" + m.viewport.View() + "\n" + footer
|
||||
}
|
||||
|
||||
func (m *Model) Clear() (Model, tea.Cmd) {
|
||||
m.filename = nil
|
||||
m.content = nil
|
||||
m.isDiff = nil
|
||||
return *m, m.render()
|
||||
}
|
||||
|
||||
func (m *Model) ToggleDiff() (Model, tea.Cmd) {
|
||||
switch m.diffStyle {
|
||||
case DiffStyleSplit:
|
||||
m.diffStyle = DiffStyleUnified
|
||||
default:
|
||||
m.diffStyle = DiffStyleSplit
|
||||
}
|
||||
return *m, m.render()
|
||||
}
|
||||
|
||||
func (m *Model) DiffStyle() DiffStyle {
|
||||
return m.diffStyle
|
||||
}
|
||||
|
||||
func (m Model) HasFile() bool {
|
||||
return m.filename != nil && m.content != nil
|
||||
}
|
||||
|
||||
func (m Model) Filename() string {
|
||||
if m.filename == nil {
|
||||
return ""
|
||||
}
|
||||
return *m.filename
|
||||
}
|
||||
|
||||
func (m *Model) SetSize(width, height int) (Model, tea.Cmd) {
|
||||
if m.width != width || m.height != height {
|
||||
m.width = width
|
||||
m.height = height
|
||||
m.viewport.SetWidth(width)
|
||||
m.viewport.SetHeight(height - 4)
|
||||
return *m, m.render()
|
||||
}
|
||||
return *m, nil
|
||||
}
|
||||
|
||||
func (m *Model) SetFile(filename string, content string, isDiff bool) (Model, tea.Cmd) {
|
||||
m.filename = &filename
|
||||
m.content = &content
|
||||
m.isDiff = &isDiff
|
||||
return *m, m.render()
|
||||
}
|
||||
|
||||
func (m *Model) render() tea.Cmd {
|
||||
if m.filename == nil || m.content == nil {
|
||||
m.viewport.SetContent("")
|
||||
return nil
|
||||
}
|
||||
|
||||
return func() tea.Msg {
|
||||
t := theme.CurrentTheme()
|
||||
var rendered string
|
||||
|
||||
if m.isDiff != nil && *m.isDiff {
|
||||
diffResult := ""
|
||||
var err error
|
||||
if m.diffStyle == DiffStyleSplit {
|
||||
diffResult, err = diff.FormatDiff(
|
||||
*m.filename,
|
||||
*m.content,
|
||||
diff.WithWidth(m.width),
|
||||
)
|
||||
} else if m.diffStyle == DiffStyleUnified {
|
||||
diffResult, err = diff.FormatUnifiedDiff(
|
||||
*m.filename,
|
||||
*m.content,
|
||||
diff.WithWidth(m.width),
|
||||
)
|
||||
}
|
||||
if err != nil {
|
||||
rendered = styles.NewStyle().
|
||||
Foreground(t.Error()).
|
||||
Render(fmt.Sprintf("Error rendering diff: %v", err))
|
||||
} else {
|
||||
rendered = strings.TrimRight(diffResult, "\n")
|
||||
}
|
||||
} else {
|
||||
rendered = util.RenderFile(
|
||||
*m.filename,
|
||||
*m.content,
|
||||
m.width,
|
||||
)
|
||||
}
|
||||
|
||||
rendered = styles.NewStyle().
|
||||
Width(m.width).
|
||||
Background(t.BackgroundPanel()).
|
||||
Render(rendered)
|
||||
|
||||
return fileRenderedMsg{
|
||||
content: rendered,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (m *Model) ScrollTo(line int) {
|
||||
m.viewport.SetYOffset(line)
|
||||
}
|
||||
|
||||
func (m *Model) ScrollToBottom() {
|
||||
m.viewport.GotoBottom()
|
||||
}
|
||||
|
||||
func (m *Model) ScrollToTop() {
|
||||
m.viewport.GotoTop()
|
||||
}
|
||||
|
||||
func (m *Model) PageUp() (Model, tea.Cmd) {
|
||||
m.viewport.ViewUp()
|
||||
return *m, nil
|
||||
}
|
||||
|
||||
func (m *Model) PageDown() (Model, tea.Cmd) {
|
||||
m.viewport.ViewDown()
|
||||
return *m, nil
|
||||
}
|
||||
|
||||
func (m *Model) HalfPageUp() (Model, tea.Cmd) {
|
||||
m.viewport.HalfViewUp()
|
||||
return *m, nil
|
||||
}
|
||||
|
||||
func (m *Model) HalfPageDown() (Model, tea.Cmd) {
|
||||
m.viewport.HalfViewDown()
|
||||
return *m, nil
|
||||
}
|
||||
|
||||
func (m Model) AtTop() bool {
|
||||
return m.viewport.AtTop()
|
||||
}
|
||||
|
||||
func (m Model) AtBottom() bool {
|
||||
return m.viewport.AtBottom()
|
||||
}
|
||||
|
||||
func (m Model) ScrollPercent() float64 {
|
||||
return m.viewport.ScrollPercent()
|
||||
}
|
||||
|
||||
func (m Model) TotalLineCount() int {
|
||||
return m.viewport.TotalLineCount()
|
||||
}
|
||||
|
||||
func (m Model) VisibleLineCount() int {
|
||||
return m.viewport.VisibleLineCount()
|
||||
}
|
||||
@@ -132,7 +132,7 @@ func (m *statusComponent) View() string {
|
||||
modeForeground = t.BackgroundPanel()
|
||||
}
|
||||
|
||||
command := m.app.Commands[commands.SwitchAgentCommand]
|
||||
command := m.app.Commands[commands.AgentCycleCommand]
|
||||
kb := command.Keybindings[0]
|
||||
key := kb.Key
|
||||
if kb.RequiresLeader {
|
||||
|
||||
+249
-101
@@ -23,7 +23,6 @@ import (
|
||||
"github.com/sst/opencode/internal/components/chat"
|
||||
cmdcomp "github.com/sst/opencode/internal/components/commands"
|
||||
"github.com/sst/opencode/internal/components/dialog"
|
||||
"github.com/sst/opencode/internal/components/fileviewer"
|
||||
"github.com/sst/opencode/internal/components/modal"
|
||||
"github.com/sst/opencode/internal/components/status"
|
||||
"github.com/sst/opencode/internal/components/toast"
|
||||
@@ -78,7 +77,6 @@ type Model struct {
|
||||
interruptKeyState InterruptKeyState
|
||||
exitKeyState ExitKeyState
|
||||
messagesRight bool
|
||||
fileViewer fileviewer.Model
|
||||
}
|
||||
|
||||
func (a Model) Init() tea.Cmd {
|
||||
@@ -94,13 +92,6 @@ func (a Model) Init() tea.Cmd {
|
||||
cmds = append(cmds, a.status.Init())
|
||||
cmds = append(cmds, a.completions.Init())
|
||||
cmds = append(cmds, a.toastManager.Init())
|
||||
cmds = append(cmds, a.fileViewer.Init())
|
||||
|
||||
// Check if we should show the init dialog
|
||||
cmds = append(cmds, func() tea.Msg {
|
||||
shouldShow := a.app.Info.Git && a.app.Info.Time.Initialized > 0
|
||||
return dialog.ShowInitDialogMsg{Show: shouldShow}
|
||||
})
|
||||
|
||||
return tea.Batch(cmds...)
|
||||
}
|
||||
@@ -400,11 +391,41 @@ func (a Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
return a, toast.NewErrorToast(msg.Error())
|
||||
case app.SendPrompt:
|
||||
a.showCompletionDialog = false
|
||||
a.app, cmd = a.app.SendPrompt(context.Background(), msg)
|
||||
cmds = append(cmds, cmd)
|
||||
// If we're in a child session, switch back to parent before sending prompt
|
||||
if a.app.Session.ParentID != "" {
|
||||
parentSession, err := a.app.Client.Session.Get(context.Background(), a.app.Session.ParentID)
|
||||
if err != nil {
|
||||
slog.Error("Failed to get parent session", "error", err)
|
||||
return a, toast.NewErrorToast("Failed to get parent session")
|
||||
}
|
||||
a.app.Session = parentSession
|
||||
a.app, cmd = a.app.SendPrompt(context.Background(), msg)
|
||||
cmds = append(cmds, tea.Sequence(
|
||||
util.CmdHandler(app.SessionSelectedMsg(parentSession)),
|
||||
cmd,
|
||||
))
|
||||
} else {
|
||||
a.app, cmd = a.app.SendPrompt(context.Background(), msg)
|
||||
cmds = append(cmds, cmd)
|
||||
}
|
||||
case app.SendShell:
|
||||
a.app, cmd = a.app.SendShell(context.Background(), msg.Command)
|
||||
cmds = append(cmds, cmd)
|
||||
// If we're in a child session, switch back to parent before sending prompt
|
||||
if a.app.Session.ParentID != "" {
|
||||
parentSession, err := a.app.Client.Session.Get(context.Background(), a.app.Session.ParentID)
|
||||
if err != nil {
|
||||
slog.Error("Failed to get parent session", "error", err)
|
||||
return a, toast.NewErrorToast("Failed to get parent session")
|
||||
}
|
||||
a.app.Session = parentSession
|
||||
a.app, cmd = a.app.SendShell(context.Background(), msg.Command)
|
||||
cmds = append(cmds, tea.Sequence(
|
||||
util.CmdHandler(app.SessionSelectedMsg(parentSession)),
|
||||
cmd,
|
||||
))
|
||||
} else {
|
||||
a.app, cmd = a.app.SendShell(context.Background(), msg.Command)
|
||||
cmds = append(cmds, cmd)
|
||||
}
|
||||
case app.SetEditorContentMsg:
|
||||
// Set the editor content without sending
|
||||
a.editor.SetValueWithAttachments(msg.Text)
|
||||
@@ -586,12 +607,6 @@ func (a Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
slog.Error("Server error", "name", err.Name, "message", err.Data.Message)
|
||||
return a, toast.NewErrorToast(err.Data.Message, toast.WithTitle(string(err.Name)))
|
||||
}
|
||||
case opencode.EventListResponseEventFileWatcherUpdated:
|
||||
if a.fileViewer.HasFile() {
|
||||
if a.fileViewer.Filename() == msg.Properties.File {
|
||||
return a.openFile(msg.Properties.File)
|
||||
}
|
||||
}
|
||||
case tea.WindowSizeMsg:
|
||||
msg.Height -= 2 // Make space for the status bar
|
||||
a.width, a.height = msg.Width, msg.Height
|
||||
@@ -616,7 +631,39 @@ func (a Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
return a, util.CmdHandler(app.SessionLoadedMsg{})
|
||||
case app.SessionCreatedMsg:
|
||||
a.app.Session = msg.Session
|
||||
return a, util.CmdHandler(app.SessionLoadedMsg{})
|
||||
case dialog.ScrollToMessageMsg:
|
||||
updated, cmd := a.messages.ScrollToMessage(msg.MessageID)
|
||||
a.messages = updated.(chat.MessagesComponent)
|
||||
cmds = append(cmds, cmd)
|
||||
case dialog.RestoreToMessageMsg:
|
||||
cmd := func() tea.Msg {
|
||||
// Find next user message after target
|
||||
var nextMessageID string
|
||||
for i := msg.Index + 1; i < len(a.app.Messages); i++ {
|
||||
if userMsg, ok := a.app.Messages[i].Info.(opencode.UserMessage); ok {
|
||||
nextMessageID = userMsg.ID
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
var response *opencode.Session
|
||||
var err error
|
||||
|
||||
if nextMessageID == "" {
|
||||
// Last message - use unrevert to restore full conversation
|
||||
response, err = a.app.Client.Session.Unrevert(context.Background(), a.app.Session.ID)
|
||||
} else {
|
||||
// Revert to next message to make target the last visible
|
||||
response, err = a.app.Client.Session.Revert(context.Background(), a.app.Session.ID,
|
||||
opencode.SessionRevertParams{MessageID: opencode.F(nextMessageID)})
|
||||
}
|
||||
|
||||
if err != nil || response == nil {
|
||||
return toast.NewErrorToast("Failed to restore to message")
|
||||
}
|
||||
return app.MessageRevertedMsg{Session: *response, Message: app.Message{}}
|
||||
}
|
||||
cmds = append(cmds, cmd)
|
||||
case app.MessageRevertedMsg:
|
||||
if msg.Session.ID == a.app.Session.ID {
|
||||
a.app.Session = &msg.Session
|
||||
@@ -653,8 +700,6 @@ func (a Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
// Reset exit key state after timeout
|
||||
a.exitKeyState = ExitKeyIdle
|
||||
a.editor.SetExitKeyInDebounce(false)
|
||||
case dialog.FindSelectedMsg:
|
||||
return a.openFile(msg.FilePath)
|
||||
case tea.PasteMsg, tea.ClipboardMsg:
|
||||
// Paste events: prioritize modal if active, otherwise editor
|
||||
if a.modal != nil {
|
||||
@@ -678,6 +723,9 @@ func (a Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
case "/tui/open-sessions":
|
||||
sessionDialog := dialog.NewSessionDialog(a.app)
|
||||
a.modal = sessionDialog
|
||||
case "/tui/open-navigation":
|
||||
navigationDialog := dialog.NewNavigationDialog(a.app)
|
||||
a.modal = navigationDialog
|
||||
case "/tui/open-themes":
|
||||
themeDialog := dialog.NewThemeDialog()
|
||||
a.modal = themeDialog
|
||||
@@ -722,6 +770,45 @@ func (a Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
updated, cmd := a.executeCommand(commands.Command(command))
|
||||
a = updated.(Model)
|
||||
cmds = append(cmds, cmd)
|
||||
case "/tui/show-toast":
|
||||
var body struct {
|
||||
Title string `json:"title,omitempty"`
|
||||
Message string `json:"message"`
|
||||
Variant string `json:"variant"`
|
||||
}
|
||||
json.Unmarshal((msg.Body), &body)
|
||||
|
||||
var toastCmd tea.Cmd
|
||||
switch body.Variant {
|
||||
case "info":
|
||||
if body.Title != "" {
|
||||
toastCmd = toast.NewInfoToast(body.Message, toast.WithTitle(body.Title))
|
||||
} else {
|
||||
toastCmd = toast.NewInfoToast(body.Message)
|
||||
}
|
||||
case "success":
|
||||
if body.Title != "" {
|
||||
toastCmd = toast.NewSuccessToast(body.Message, toast.WithTitle(body.Title))
|
||||
} else {
|
||||
toastCmd = toast.NewSuccessToast(body.Message)
|
||||
}
|
||||
case "warning":
|
||||
if body.Title != "" {
|
||||
toastCmd = toast.NewErrorToast(body.Message, toast.WithTitle(body.Title))
|
||||
} else {
|
||||
toastCmd = toast.NewErrorToast(body.Message)
|
||||
}
|
||||
case "error":
|
||||
if body.Title != "" {
|
||||
toastCmd = toast.NewErrorToast(body.Message, toast.WithTitle(body.Title))
|
||||
} else {
|
||||
toastCmd = toast.NewErrorToast(body.Message)
|
||||
}
|
||||
default:
|
||||
slog.Error("Invalid toast variant", "variant", body.Variant)
|
||||
return a, nil
|
||||
}
|
||||
cmds = append(cmds, toastCmd)
|
||||
|
||||
default:
|
||||
break
|
||||
@@ -753,10 +840,6 @@ func (a Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
cmds = append(cmds, cmd)
|
||||
}
|
||||
|
||||
fv, cmd := a.fileViewer.Update(msg)
|
||||
a.fileViewer = fv
|
||||
cmds = append(cmds, cmd)
|
||||
|
||||
return a, tea.Batch(cmds...)
|
||||
}
|
||||
|
||||
@@ -806,26 +889,6 @@ func (a Model) Cleanup() {
|
||||
a.status.Cleanup()
|
||||
}
|
||||
|
||||
func (a Model) openFile(filepath string) (tea.Model, tea.Cmd) {
|
||||
var cmd tea.Cmd
|
||||
response, err := a.app.Client.File.Read(
|
||||
context.Background(),
|
||||
opencode.FileReadParams{
|
||||
Path: opencode.F(filepath),
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
slog.Error("Failed to read file", "error", err)
|
||||
return a, toast.NewErrorToast("Failed to read file")
|
||||
}
|
||||
a.fileViewer, cmd = a.fileViewer.SetFile(
|
||||
filepath,
|
||||
response.Content,
|
||||
response.Type == "patch",
|
||||
)
|
||||
return a, cmd
|
||||
}
|
||||
|
||||
func (a Model) home() (string, int, int) {
|
||||
t := theme.CurrentTheme()
|
||||
effectiveWidth := a.width - 4
|
||||
@@ -1014,11 +1077,11 @@ func (a Model) executeCommand(command commands.Command) (tea.Model, tea.Cmd) {
|
||||
case commands.AppHelpCommand:
|
||||
helpDialog := dialog.NewHelpDialog(a.app)
|
||||
a.modal = helpDialog
|
||||
case commands.SwitchAgentCommand:
|
||||
case commands.AgentCycleCommand:
|
||||
updated, cmd := a.app.SwitchAgent()
|
||||
a.app = updated
|
||||
cmds = append(cmds, cmd)
|
||||
case commands.SwitchAgentReverseCommand:
|
||||
case commands.AgentCycleReverseCommand:
|
||||
updated, cmd := a.app.SwitchAgentReverse()
|
||||
a.app = updated
|
||||
cmds = append(cmds, cmd)
|
||||
@@ -1078,6 +1141,12 @@ func (a Model) executeCommand(command commands.Command) (tea.Model, tea.Cmd) {
|
||||
case commands.SessionListCommand:
|
||||
sessionDialog := dialog.NewSessionDialog(a.app)
|
||||
a.modal = sessionDialog
|
||||
case commands.SessionNavigationCommand:
|
||||
if a.app.Session.ID == "" {
|
||||
return a, toast.NewErrorToast("No active session")
|
||||
}
|
||||
navigationDialog := dialog.NewNavigationDialog(a.app)
|
||||
a.modal = navigationDialog
|
||||
case commands.SessionShareCommand:
|
||||
if a.app.Session.ID == "" {
|
||||
return a, nil
|
||||
@@ -1113,6 +1182,122 @@ func (a Model) executeCommand(command commands.Command) (tea.Model, tea.Cmd) {
|
||||
}
|
||||
// TODO: block until compaction is complete
|
||||
a.app.CompactSession(context.Background())
|
||||
case commands.SessionChildCycleCommand:
|
||||
if a.app.Session.ID == "" {
|
||||
return a, nil
|
||||
}
|
||||
cmds = append(cmds, func() tea.Msg {
|
||||
parentSessionID := a.app.Session.ID
|
||||
var parentSession *opencode.Session
|
||||
if a.app.Session.ParentID != "" {
|
||||
parentSessionID = a.app.Session.ParentID
|
||||
session, err := a.app.Client.Session.Get(context.Background(), parentSessionID)
|
||||
if err != nil {
|
||||
slog.Error("Failed to get parent session", "error", err)
|
||||
return toast.NewErrorToast("Failed to get parent session")
|
||||
}
|
||||
parentSession = session
|
||||
} else {
|
||||
parentSession = a.app.Session
|
||||
}
|
||||
|
||||
children, err := a.app.Client.Session.Children(context.Background(), parentSessionID)
|
||||
if err != nil {
|
||||
slog.Error("Failed to get session children", "error", err)
|
||||
return toast.NewErrorToast("Failed to get session children")
|
||||
}
|
||||
|
||||
// Reverse sort the children (newest first)
|
||||
slices.Reverse(*children)
|
||||
|
||||
// Create combined array: [parent, child1, child2, ...]
|
||||
sessions := []*opencode.Session{parentSession}
|
||||
for i := range *children {
|
||||
sessions = append(sessions, &(*children)[i])
|
||||
}
|
||||
|
||||
if len(sessions) == 1 {
|
||||
return toast.NewInfoToast("No child sessions available")
|
||||
}
|
||||
|
||||
// Find current session index in combined array
|
||||
currentIndex := -1
|
||||
for i, session := range sessions {
|
||||
if session.ID == a.app.Session.ID {
|
||||
currentIndex = i
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// If session not found, default to parent (shouldn't happen)
|
||||
if currentIndex == -1 {
|
||||
currentIndex = 0
|
||||
}
|
||||
|
||||
// Cycle to next session (parent or child)
|
||||
nextIndex := (currentIndex + 1) % len(sessions)
|
||||
nextSession := sessions[nextIndex]
|
||||
|
||||
return app.SessionSelectedMsg(nextSession)
|
||||
})
|
||||
case commands.SessionChildCycleReverseCommand:
|
||||
if a.app.Session.ID == "" {
|
||||
return a, nil
|
||||
}
|
||||
cmds = append(cmds, func() tea.Msg {
|
||||
parentSessionID := a.app.Session.ID
|
||||
var parentSession *opencode.Session
|
||||
if a.app.Session.ParentID != "" {
|
||||
parentSessionID = a.app.Session.ParentID
|
||||
session, err := a.app.Client.Session.Get(context.Background(), parentSessionID)
|
||||
if err != nil {
|
||||
slog.Error("Failed to get parent session", "error", err)
|
||||
return toast.NewErrorToast("Failed to get parent session")
|
||||
}
|
||||
parentSession = session
|
||||
} else {
|
||||
parentSession = a.app.Session
|
||||
}
|
||||
|
||||
children, err := a.app.Client.Session.Children(context.Background(), parentSessionID)
|
||||
if err != nil {
|
||||
slog.Error("Failed to get session children", "error", err)
|
||||
return toast.NewErrorToast("Failed to get session children")
|
||||
}
|
||||
|
||||
// Reverse sort the children (newest first)
|
||||
slices.Reverse(*children)
|
||||
|
||||
// Create combined array: [parent, child1, child2, ...]
|
||||
sessions := []*opencode.Session{parentSession}
|
||||
for i := range *children {
|
||||
sessions = append(sessions, &(*children)[i])
|
||||
}
|
||||
|
||||
if len(sessions) == 1 {
|
||||
return toast.NewInfoToast("No child sessions available")
|
||||
}
|
||||
|
||||
// Find current session index in combined array
|
||||
currentIndex := -1
|
||||
for i, session := range sessions {
|
||||
if session.ID == a.app.Session.ID {
|
||||
currentIndex = i
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// If session not found, default to parent (shouldn't happen)
|
||||
if currentIndex == -1 {
|
||||
currentIndex = 0
|
||||
}
|
||||
|
||||
// Cycle to previous session (parent or child)
|
||||
nextIndex := (currentIndex - 1 + len(sessions)) % len(sessions)
|
||||
nextSession := sessions[nextIndex]
|
||||
|
||||
return app.SessionSelectedMsg(nextSession)
|
||||
})
|
||||
case commands.SessionExportCommand:
|
||||
if a.app.Session.ID == "" {
|
||||
return a, toast.NewErrorToast("No active session to export.")
|
||||
@@ -1190,24 +1375,13 @@ func (a Model) executeCommand(command commands.Command) (tea.Model, tea.Cmd) {
|
||||
updated, cmd := a.app.CycleRecentModel()
|
||||
a.app = updated
|
||||
cmds = append(cmds, cmd)
|
||||
case commands.ModelCycleRecentReverseCommand:
|
||||
updated, cmd := a.app.CycleRecentModelReverse()
|
||||
a.app = updated
|
||||
cmds = append(cmds, cmd)
|
||||
case commands.ThemeListCommand:
|
||||
themeDialog := dialog.NewThemeDialog()
|
||||
a.modal = themeDialog
|
||||
// case commands.FileListCommand:
|
||||
// a.editor.Blur()
|
||||
// findDialog := dialog.NewFindDialog(a.fileProvider)
|
||||
// cmds = append(cmds, findDialog.Init())
|
||||
// a.modal = findDialog
|
||||
case commands.FileCloseCommand:
|
||||
a.fileViewer, cmd = a.fileViewer.Clear()
|
||||
cmds = append(cmds, cmd)
|
||||
case commands.FileDiffToggleCommand:
|
||||
a.fileViewer, cmd = a.fileViewer.ToggleDiff()
|
||||
cmds = append(cmds, cmd)
|
||||
a.app.State.SplitDiff = a.fileViewer.DiffStyle() == fileviewer.DiffStyleSplit
|
||||
cmds = append(cmds, a.app.SaveState())
|
||||
case commands.FileSearchCommand:
|
||||
return a, nil
|
||||
case commands.ProjectInitCommand:
|
||||
cmds = append(cmds, a.app.InitializeProject(context.Background()))
|
||||
case commands.InputClearCommand:
|
||||
@@ -1238,45 +1412,21 @@ func (a Model) executeCommand(command commands.Command) (tea.Model, tea.Cmd) {
|
||||
a.messages = updated.(chat.MessagesComponent)
|
||||
cmds = append(cmds, cmd)
|
||||
case commands.MessagesPageUpCommand:
|
||||
if a.fileViewer.HasFile() {
|
||||
a.fileViewer, cmd = a.fileViewer.PageUp()
|
||||
cmds = append(cmds, cmd)
|
||||
} else {
|
||||
updated, cmd := a.messages.PageUp()
|
||||
a.messages = updated.(chat.MessagesComponent)
|
||||
cmds = append(cmds, cmd)
|
||||
}
|
||||
updated, cmd := a.messages.PageUp()
|
||||
a.messages = updated.(chat.MessagesComponent)
|
||||
cmds = append(cmds, cmd)
|
||||
case commands.MessagesPageDownCommand:
|
||||
if a.fileViewer.HasFile() {
|
||||
a.fileViewer, cmd = a.fileViewer.PageDown()
|
||||
cmds = append(cmds, cmd)
|
||||
} else {
|
||||
updated, cmd := a.messages.PageDown()
|
||||
a.messages = updated.(chat.MessagesComponent)
|
||||
cmds = append(cmds, cmd)
|
||||
}
|
||||
updated, cmd := a.messages.PageDown()
|
||||
a.messages = updated.(chat.MessagesComponent)
|
||||
cmds = append(cmds, cmd)
|
||||
case commands.MessagesHalfPageUpCommand:
|
||||
if a.fileViewer.HasFile() {
|
||||
a.fileViewer, cmd = a.fileViewer.HalfPageUp()
|
||||
cmds = append(cmds, cmd)
|
||||
} else {
|
||||
updated, cmd := a.messages.HalfPageUp()
|
||||
a.messages = updated.(chat.MessagesComponent)
|
||||
cmds = append(cmds, cmd)
|
||||
}
|
||||
updated, cmd := a.messages.HalfPageUp()
|
||||
a.messages = updated.(chat.MessagesComponent)
|
||||
cmds = append(cmds, cmd)
|
||||
case commands.MessagesHalfPageDownCommand:
|
||||
if a.fileViewer.HasFile() {
|
||||
a.fileViewer, cmd = a.fileViewer.HalfPageDown()
|
||||
cmds = append(cmds, cmd)
|
||||
} else {
|
||||
updated, cmd := a.messages.HalfPageDown()
|
||||
a.messages = updated.(chat.MessagesComponent)
|
||||
cmds = append(cmds, cmd)
|
||||
}
|
||||
case commands.MessagesLayoutToggleCommand:
|
||||
a.messagesRight = !a.messagesRight
|
||||
a.app.State.MessagesRight = a.messagesRight
|
||||
cmds = append(cmds, a.app.SaveState())
|
||||
updated, cmd := a.messages.HalfPageDown()
|
||||
a.messages = updated.(chat.MessagesComponent)
|
||||
cmds = append(cmds, cmd)
|
||||
case commands.MessagesCopyCommand:
|
||||
updated, cmd := a.messages.CopyLastMessage()
|
||||
a.messages = updated.(chat.MessagesComponent)
|
||||
@@ -1326,8 +1476,6 @@ func NewModel(app *app.App) tea.Model {
|
||||
toastManager: toast.NewToastManager(),
|
||||
interruptKeyState: InterruptKeyIdle,
|
||||
exitKeyState: ExitKeyIdle,
|
||||
fileViewer: fileviewer.New(app),
|
||||
messagesRight: app.State.MessagesRight,
|
||||
}
|
||||
|
||||
return model
|
||||
|
||||
@@ -86,7 +86,7 @@ func Extension(path string) string {
|
||||
func ToMarkdown(content string, width int, backgroundColor compat.AdaptiveColor) string {
|
||||
r := styles.GetMarkdownRenderer(width-6, backgroundColor)
|
||||
content = strings.ReplaceAll(content, RootPath+"/", "")
|
||||
hyphenRegex := regexp.MustCompile(`-([^ ]|$)`)
|
||||
hyphenRegex := regexp.MustCompile(`-([^ \-|]|$)`)
|
||||
content = hyphenRegex.ReplaceAllString(content, "\u2011$1")
|
||||
rendered, _ := r.Render(content)
|
||||
lines := strings.Split(rendered, "\n")
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@opencode/web",
|
||||
"type": "module",
|
||||
"version": "0.5.1",
|
||||
"version": "0.5.4",
|
||||
"scripts": {
|
||||
"dev": "astro dev",
|
||||
"dev:remote": "sst shell --stage=dev --target=Web astro dev",
|
||||
|
||||
@@ -495,6 +495,10 @@ section.alternatives {
|
||||
text-align: left;
|
||||
gap: 0.5rem;
|
||||
|
||||
@media (max-width: 30rem) {
|
||||
gap: 0.3125rem;
|
||||
}
|
||||
|
||||
@media (max-width: 40rem) {
|
||||
text-align: left;
|
||||
}
|
||||
@@ -540,6 +544,10 @@ section.alternatives {
|
||||
font-weight: normal;
|
||||
font-size: 1rem;
|
||||
flex-shrink: 0;
|
||||
|
||||
@media (max-width: 30rem) {
|
||||
font-size: 0.75rem;
|
||||
}
|
||||
}
|
||||
|
||||
.command {
|
||||
@@ -554,7 +562,7 @@ section.alternatives {
|
||||
@media (max-width: 40rem) {
|
||||
justify-content: flex-start;
|
||||
}
|
||||
|
||||
|
||||
@media (max-width: 30rem) {
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
@@ -90,6 +90,13 @@ A general-purpose agent for researching complex questions, searching for code, a
|
||||
@general help me search for this function
|
||||
```
|
||||
|
||||
3. **Navigation between sessions**: When subagents create their own child sessions, you can navigate between the parent session and all child sessions using:
|
||||
|
||||
- **Ctrl+Right** (or your configured `session_child_cycle` keybind) to cycle forward through parent → child1 → child2 → ... → parent
|
||||
- **Ctrl+Left** (or your configured `session_child_cycle_reverse` keybind) to cycle backward through parent ← child1 ← child2 ← ... ← parent
|
||||
|
||||
This allows you to seamlessly switch between the main conversation and specialized subagent work.
|
||||
|
||||
---
|
||||
|
||||
## Configure
|
||||
|
||||
@@ -11,27 +11,22 @@ opencode has a list of keybinds that you can customize through the opencode conf
|
||||
"keybinds": {
|
||||
"leader": "ctrl+x",
|
||||
"app_help": "<leader>h",
|
||||
"switch_agent": "tab",
|
||||
|
||||
"app_exit": "ctrl+c,<leader>q",
|
||||
"editor_open": "<leader>e",
|
||||
|
||||
"session_new": "<leader>n",
|
||||
"session_list": "<leader>l",
|
||||
"session_share": "<leader>s",
|
||||
"session_unshare": "<leader>u",
|
||||
"session_interrupt": "esc",
|
||||
"session_compact": "<leader>c",
|
||||
|
||||
"tool_details": "<leader>d",
|
||||
"model_list": "<leader>m",
|
||||
"theme_list": "<leader>t",
|
||||
"project_init": "<leader>i",
|
||||
|
||||
"input_clear": "ctrl+c",
|
||||
"input_paste": "ctrl+v",
|
||||
"input_submit": "enter",
|
||||
"input_newline": "shift+enter,ctrl+j",
|
||||
|
||||
"tool_details": "<leader>d",
|
||||
"thinking_blocks": "<leader>b",
|
||||
"session_export": "<leader>x",
|
||||
"session_new": "<leader>n",
|
||||
"session_list": "<leader>l",
|
||||
"session_navigation": "<leader>g",
|
||||
"session_share": "<leader>s",
|
||||
"session_unshare": "none",
|
||||
"session_interrupt": "esc",
|
||||
"session_compact": "<leader>c",
|
||||
"session_child_cycle": "ctrl+right",
|
||||
"session_child_cycle_reverse": "ctrl+left",
|
||||
"messages_page_up": "pgup",
|
||||
"messages_page_down": "pgdown",
|
||||
"messages_half_page_up": "ctrl+alt+u",
|
||||
@@ -39,8 +34,18 @@ opencode has a list of keybinds that you can customize through the opencode conf
|
||||
"messages_first": "ctrl+g",
|
||||
"messages_last": "ctrl+alt+g",
|
||||
"messages_copy": "<leader>y",
|
||||
|
||||
"app_exit": "ctrl+c,<leader>q"
|
||||
"messages_undo": "<leader>u",
|
||||
"messages_redo": "<leader>r",
|
||||
"model_list": "<leader>m",
|
||||
"model_cycle_recent": "f2",
|
||||
"model_cycle_recent_reverse": "shift+f2",
|
||||
"agent_list": "<leader>a",
|
||||
"agent_cycle": "tab",
|
||||
"agent_cycle_reverse": "shift+tab",
|
||||
"input_clear": "ctrl+c",
|
||||
"input_paste": "ctrl+v",
|
||||
"input_submit": "enter",
|
||||
"input_newline": "shift+enter,ctrl+j"
|
||||
}
|
||||
}
|
||||
```
|
||||
@@ -65,7 +70,7 @@ You can disable a keybind by adding the key to your config with a value of "none
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"keybinds": {
|
||||
"session_compact": "none",
|
||||
"session_compact": "none"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
@@ -761,11 +761,11 @@ https://platform.openai.com/api-keys
|
||||
|
||||
---
|
||||
|
||||
### Zhipu AI
|
||||
### Z.AI
|
||||
|
||||
1. Head over to the [Zhipu API console](https://z.ai/manage-apikey/apikey-list), create an account, and click **Create a new API key**.
|
||||
1. Head over to the [Z.AI API console](https://z.ai/manage-apikey/apikey-list), create an account, and click **Create a new API key**.
|
||||
|
||||
2. Run `opencode auth login` and select **Zhipu AI**.
|
||||
2. Run `opencode auth login` and select **Z.AI**.
|
||||
|
||||
```bash
|
||||
$ opencode auth login
|
||||
@@ -773,12 +773,12 @@ https://platform.openai.com/api-keys
|
||||
┌ Add credential
|
||||
│
|
||||
◆ Select provider
|
||||
│ ● Zhipu AI
|
||||
│ ● Z.AI
|
||||
│ ...
|
||||
└
|
||||
```
|
||||
|
||||
3. Enter your Zhipu AI API key.
|
||||
3. Enter your Z.AI API key.
|
||||
|
||||
```bash
|
||||
$ opencode auth login
|
||||
@@ -786,7 +786,7 @@ https://platform.openai.com/api-keys
|
||||
┌ Add credential
|
||||
│
|
||||
◇ Select provider
|
||||
│ Zhipu AI
|
||||
│ Z.AI
|
||||
│
|
||||
◇ Enter your API key
|
||||
│ _
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"name": "opencode",
|
||||
"displayName": "opencode",
|
||||
"description": "opencode for VS Code",
|
||||
"version": "0.5.1",
|
||||
"version": "0.5.4",
|
||||
"publisher": "sst-dev",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
Reference in New Issue
Block a user