diff --git a/packages/tui/src/component/dialog-error-details.tsx b/packages/tui/src/component/dialog-error-details.tsx index 75e7b0055d3..411a0b9e58f 100644 --- a/packages/tui/src/component/dialog-error-details.tsx +++ b/packages/tui/src/component/dialog-error-details.tsx @@ -4,12 +4,19 @@ import { createEffect, createMemo, createSignal, onCleanup } from "solid-js" import { useConfig } from "../config" import { useClipboard } from "../context/clipboard" import { Keymap } from "../context/keymap" +import { useLocation } from "../context/location" +import { useRoute } from "../context/route" import { getScrollAcceleration } from "../util/scroll" import { useTheme } from "../context/theme" +import { emptyPrompt } from "../prompt/history" +import { useDialog } from "../ui/dialog" import { useToast } from "../ui/toast" -export function DialogErrorDetails(props: { title: string; error: string; onBack: () => void }) { +export function DialogErrorDetails(props: { title: string; error: string; context?: string; onBack: () => void }) { const clipboard = useClipboard() + const dialog = useDialog() + const location = useLocation() + const route = useRoute() const toast = useToast() const theme = useTheme("elevated") const overlayTheme = useTheme("overlay") @@ -49,11 +56,24 @@ export function DialogErrorDetails(props: { title: string; error: string; onBack .catch(toast.error) } + const investigate = () => { + route.navigate({ + type: "home", + location: location.ref, + prompt: { + ...emptyPrompt(), + text: `Investigate why this OpenCode component failed in the current project.\n\n${props.title}${props.context ? `\n${props.context}` : ""}\nError: ${props.error}\n\nInspect the relevant project and global OpenCode configuration, startup or loading behavior, required environment variables or credentials, dependencies, and logs. Identify the root cause and recommend a fix.`, + }, + }) + dialog.clear() + } + Keymap.createLayer(() => ({ mode: "modal", commands: [ { bind: "escape", title: "Back", group: "Dialog", run: props.onBack }, { bind: "c", title: "Copy details", group: "Dialog", run: copy }, + { bind: "i", title: "Investigate error", group: "Dialog", run: investigate }, ], })) @@ -95,13 +115,19 @@ export function DialogErrorDetails(props: { title: string; error: string; onBack - - + + {scrollable() ? "↑/↓" : ""} {scrollable() ? " scroll" : ""} + + + i + + investigate + {copied() ? "✓ copied" : "c"} diff --git a/packages/tui/src/component/dialog-mcp.tsx b/packages/tui/src/component/dialog-mcp.tsx index b2985fd3ac8..dfe07805d68 100644 --- a/packages/tui/src/component/dialog-mcp.tsx +++ b/packages/tui/src/component/dialog-mcp.tsx @@ -157,6 +157,9 @@ export function DialogMcp(props: { initialServer?: string; details?: boolean } = { setDetail(undefined) dialog.setSize("medium") diff --git a/packages/tui/src/feature-plugins/system/plugins.tsx b/packages/tui/src/feature-plugins/system/plugins.tsx index 501455496f0..f32d9f1c060 100644 --- a/packages/tui/src/feature-plugins/system/plugins.tsx +++ b/packages/tui/src/feature-plugins/system/plugins.tsx @@ -169,6 +169,7 @@ export function PluginsDialog(props: { { setDetail() dialog.setSize("medium") @@ -185,6 +186,11 @@ function label(entry: Entry, context: Plugin.Context) { return entry.plugin.id ?? source(entry.plugin, context) } +function pluginSource(entry: Entry, context: Plugin.Context) { + if (entry.runtime === "tui") return entry.target + return source(entry.plugin, context) +} + function source(plugin: PluginInfo, context: Plugin.Context) { if (plugin.source.type === "package") return plugin.source.package if (plugin.source.type === "local") return context.ui.format.path(plugin.source.path) diff --git a/packages/tui/src/routes/home.tsx b/packages/tui/src/routes/home.tsx index b2326f54d68..0180d9a5ffa 100644 --- a/packages/tui/src/routes/home.tsx +++ b/packages/tui/src/routes/home.tsx @@ -48,17 +48,18 @@ export function Home() { const bind = (r: PromptRef | undefined) => { setRef(r) promptRef.set(r) - if (once || !r) return - if (route.prompt) { - r.set(route.prompt) - once = true - return - } - if (!args.prompt) return + if (once || !r || route.prompt || !args.prompt) return r.set({ text: args.prompt, files: [], agents: [], pasted: [] }) once = true } + createEffect(() => { + const composer = ref() + const prompt = route.prompt + if (!composer || prompt?.text === undefined) return + untrack(() => composer.set(prompt)) + }) + // Wait for the model store to be ready before auto-submitting --prompt. createEffect(() => { const r = ref() diff --git a/packages/tui/test/app-lifecycle.test.tsx b/packages/tui/test/app-lifecycle.test.tsx index 9a7e7f0b0f7..0f4d881f66e 100644 --- a/packages/tui/test/app-lifecycle.test.tsx +++ b/packages/tui/test/app-lifecycle.test.tsx @@ -297,6 +297,76 @@ test("session startup prompt is submitted exactly once", async () => { } }) +test("error investigations repeatedly seed editable home drafts without creating sessions", async () => { + const setup = await createTestRenderer({ width: 100, height: 30, useThread: false, kittyKeyboard: true }) + setup.renderer.start() + const events = createEventStream() + const cwd = process.cwd() + const location = { directory: cwd, project: { id: "project", directory: cwd } } + let created = 0 + const calls = createFetch((url, request) => { + if (url.pathname === "/api/location") return json(location) + if (url.pathname === "/api/mcp") + return json({ + location, + data: [ + { name: "alpha", status: { status: "failed", error: "Alpha connection refused" } }, + { name: "beta", status: { status: "failed", error: "Beta initialization failed" } }, + ], + }) + if (url.pathname === "/api/session" && request.method === "POST") created++ + return undefined + }, events) + const server = Bun.serve({ port: 0, fetch: (request) => calls.fetch(request) }) + + try { + const { run } = await import("../src/app") + const task = Effect.runPromise( + run({ + app: { name: "test", version: "test", channel: "test" }, + server: { endpoint: { url: server.url.toString() } }, + config: { + get: async () => ({ animations: false, keybinds: { "mcp.list": "f6" } }), + update: async () => ({}), + }, + packages: { resolve: async () => undefined }, + args: {}, + terminalHandoff: async () => ({ renderer: setup.renderer, mode: "dark", complete: () => {} }), + log: () => {}, + }).pipe(Effect.provide(AppNodeBuilder.build(Global.node)), Effect.provide(FileSystem.layerNoop({}))), + ) + await setup.waitForFrame((frame) => frame.includes("commands")) + + setup.mockInput.pressKey("F6") + await setup.waitForFrame((frame) => frame.includes("MCP servers") && frame.includes("alpha")) + setup.mockInput.pressEnter() + await setup.waitForFrame((frame) => frame.includes("Alpha connection refused") && frame.includes("i investigate")) + setup.mockInput.pressKey("i") + await setup.waitForFrame((frame) => frame.includes("Alpha connection refused") && !frame.includes("i investigate")) + + setup.mockInput.pressKey("F6") + await setup.waitForFrame((frame) => frame.includes("MCP servers")) + setup.mockInput.pressArrow("down") + setup.mockInput.pressEnter() + await setup.waitForFrame((frame) => frame.includes("Beta initialization failed") && frame.includes("i investigate")) + setup.mockInput.pressKey("i") + const draft = await setup.waitForFrame( + (frame) => frame.includes("Beta initialization failed") && !frame.includes("i investigate"), + ) + + expect(draft).not.toContain("Alpha connection refused") + expect(created).toBe(0) + + setup.mockInput.pressKey("c", { ctrl: true }) + await setup.waitForFrame((frame) => !frame.includes("Beta initialization failed")) + setup.renderer.destroy() + await task + } finally { + if (!setup.renderer.isDestroyed) setup.renderer.destroy() + await server.stop() + } +}) + test("shows jump to latest after scrolling one line above the final message", async () => { const setup = await createTestRenderer({ width: 80, height: 20, useThread: false, kittyKeyboard: true }) setup.renderer.start() diff --git a/packages/tui/test/cli/tui/dialog-mcp.test.tsx b/packages/tui/test/cli/tui/dialog-mcp.test.tsx index 80960f6acbe..cffd0dcfc4b 100644 --- a/packages/tui/test/cli/tui/dialog-mcp.test.tsx +++ b/packages/tui/test/cli/tui/dialog-mcp.test.tsx @@ -7,7 +7,8 @@ import { ConfigProvider } from "../../../src/config" import { ClientProvider } from "../../../src/context/client" import { DataProvider, useData } from "../../../src/context/data" import { Keymap } from "../../../src/context/keymap" -import { LocationProvider } from "../../../src/context/location" +import { LocationProvider, useLocation } from "../../../src/context/location" +import { RouteProvider, useRoute } from "../../../src/context/route" import { ThemeProvider } from "../../../src/context/theme" import { DialogProvider, useDialog } from "../../../src/ui/dialog" import { ToastProvider } from "../../../src/ui/toast" @@ -32,19 +33,56 @@ test.each(["enter", "space"])("starts OAuth with %s for an MCP server requiring } }) -async function renderMcp() { +test("opens an investigation draft for a failed MCP server at its originating location", async () => { + const location = { directory: "/projects/example", workspaceID: "workspace_example" } + const fixture = await renderMcp({ failed: true, location }) + + try { + await fixture.app.waitForFrame((frame) => frame.includes("Failed !")) + fixture.app.mockInput.pressEnter() + await fixture.app.waitForFrame((frame) => frame.includes("i investigate")) + fixture.app.mockInput.pressKey("i") + await fixture.app.waitForFrame((frame) => !frame.includes("MCP server: linear")) + + expect(fixture.route.data.type).toBe("home") + if (fixture.route.data.type !== "home") throw new Error("Expected investigation to open a new session") + expect(fixture.route.data.location).toEqual(location) + expect(fixture.route.data.prompt?.text).toContain("OpenCode component failed in the current project") + expect(fixture.route.data.prompt?.text).toContain("MCP server: linear") + expect(fixture.route.data.prompt?.text).toContain("Status: failed") + expect(fixture.route.data.prompt?.text).toContain("Configuration: mcp.servers.linear") + expect(fixture.route.data.prompt?.text).toContain("Integration: mcp_linear") + expect(fixture.route.data.prompt?.text).toContain("MCP error -32000: Connection closed") + expect(fixture.route.data.prompt?.text).toContain("project and global OpenCode configuration") + expect(fixture.route.data.prompt?.text).not.toContain(location.directory) + } finally { + fixture.app.renderer.destroy() + } +}) + +async function renderMcp(options?: { failed?: boolean; location?: { directory: string; workspaceID?: string } }) { const events = createEventStream() let oauth = 0 let connect = 0 + let route!: ReturnType const calls = createFetch((url, request) => { const location = { - directory: process.cwd(), + ...(options?.location ?? { directory: process.cwd() }), project: { id: "proj_test", directory: process.cwd(), canonical: process.cwd() }, } + if (url.pathname === "/api/location") return json(location) if (url.pathname === "/api/mcp") return json({ location, - data: [{ name: "linear", status: { status: "needs_auth" }, integrationID: "mcp_linear" }], + data: [ + { + name: "linear", + status: options?.failed + ? { status: "failed", error: "MCP error -32000: Connection closed" } + : { status: "needs_auth" }, + integrationID: "mcp_linear", + }, + ], }) if (url.pathname === "/api/integration") return json({ @@ -84,10 +122,14 @@ async function renderMcp() { function Probe() { const data = useData() const dialog = useDialog() + const location = useLocation() + route = useRoute() onMount(() => { - void Promise.all([data.location.mcp.server.sync(), data.location.integration.sync()]).then(() => - dialog.replace(() => ), - ) + if (options?.location) location.set(options.location) + void Promise.all([ + data.location.mcp.server.sync(options?.location), + data.location.integration.sync(options?.location), + ]).then(() => dialog.replace(() => )) }) return null } @@ -98,17 +140,19 @@ async function renderMcp() { - - - - - - - - - - - + + + + + + + + + + + + + @@ -119,6 +163,9 @@ async function renderMcp() { app.renderer.start() return { app, + get route() { + return route + }, get oauth() { return oauth },