mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-16 13:05:14 +03:00
feat(tui): investigate errors in a new session
This commit is contained in:
committed by
GitHub
Unverified
parent
37a6ba893e
commit
3d7ba38965
@@ -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
|
||||
</text>
|
||||
</scrollbox>
|
||||
</box>
|
||||
<box flexDirection="row" justifyContent="space-between" paddingLeft={2} paddingRight={2}>
|
||||
<text>
|
||||
<box flexDirection="row" gap={3} paddingLeft={2} paddingRight={2}>
|
||||
<text flexGrow={1}>
|
||||
<span style={{ fg: theme.text.default }}>
|
||||
<b>{scrollable() ? "↑/↓" : ""}</b>
|
||||
</span>
|
||||
<span style={{ fg: theme.text.subdued }}>{scrollable() ? " scroll" : ""}</span>
|
||||
</text>
|
||||
<text onMouseUp={investigate}>
|
||||
<span style={{ fg: theme.text.default }}>
|
||||
<b>i</b>
|
||||
</span>
|
||||
<span style={{ fg: theme.text.subdued }}> investigate</span>
|
||||
</text>
|
||||
<text onMouseUp={copy}>
|
||||
<span style={{ fg: copied() ? theme.text.feedback.success.default : theme.text.default }}>
|
||||
<b>{copied() ? "✓ copied" : "c"}</b>
|
||||
|
||||
@@ -157,6 +157,9 @@ export function DialogMcp(props: { initialServer?: string; details?: boolean } =
|
||||
<DialogErrorDetails
|
||||
title={`MCP server: ${server().name}`}
|
||||
error={statusError(server().status) ?? "Unknown MCP connection error"}
|
||||
context={`Status: failed\nConfiguration: mcp.servers.${server().name}${
|
||||
server().integrationID ? `\nIntegration: ${server().integrationID}` : ""
|
||||
}`}
|
||||
onBack={() => {
|
||||
setDetail(undefined)
|
||||
dialog.setSize("medium")
|
||||
|
||||
@@ -169,6 +169,7 @@ export function PluginsDialog(props: {
|
||||
<DialogErrorDetails
|
||||
title={`${entry().runtime === "tui" ? "TUI" : "Server"} plugin: ${label(entry(), props.context)}`}
|
||||
error={pluginError(entry()) ?? "Unknown plugin error"}
|
||||
context={`Status: failed\nRuntime: ${entry().runtime}\nSource: ${pluginSource(entry(), props.context)}`}
|
||||
onBack={() => {
|
||||
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)
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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<typeof useRoute>
|
||||
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(() => <DialogMcp />),
|
||||
)
|
||||
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(() => <DialogMcp />))
|
||||
})
|
||||
return null
|
||||
}
|
||||
@@ -98,17 +140,19 @@ async function renderMcp() {
|
||||
<ConfigProvider config={createTuiResolvedConfig()}>
|
||||
<Keymap.Provider>
|
||||
<ToastProvider>
|
||||
<ClientProvider api={createApi(calls.fetch)}>
|
||||
<DataProvider>
|
||||
<LocationProvider>
|
||||
<ThemeProvider mode="dark" source={emptyThemeSource}>
|
||||
<DialogProvider>
|
||||
<Probe />
|
||||
</DialogProvider>
|
||||
</ThemeProvider>
|
||||
</LocationProvider>
|
||||
</DataProvider>
|
||||
</ClientProvider>
|
||||
<RouteProvider initialRoute={{ type: "session", sessionID: "ses_existing" }}>
|
||||
<ClientProvider api={createApi(calls.fetch)}>
|
||||
<DataProvider>
|
||||
<LocationProvider>
|
||||
<ThemeProvider mode="dark" source={emptyThemeSource}>
|
||||
<DialogProvider>
|
||||
<Probe />
|
||||
</DialogProvider>
|
||||
</ThemeProvider>
|
||||
</LocationProvider>
|
||||
</DataProvider>
|
||||
</ClientProvider>
|
||||
</RouteProvider>
|
||||
</ToastProvider>
|
||||
</Keymap.Provider>
|
||||
</ConfigProvider>
|
||||
@@ -119,6 +163,9 @@ async function renderMcp() {
|
||||
app.renderer.start()
|
||||
return {
|
||||
app,
|
||||
get route() {
|
||||
return route
|
||||
},
|
||||
get oauth() {
|
||||
return oauth
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user