Skip to content

Commit 4692552

Browse files
anandgupta42claude
andcommitted
fix: address PR review feedback
- URL-encode session IDs in viewer URLs for safety - Use `127.0.0.1` instead of `localhost` to match server bind address - Replace manual `Bun.spawn` platform logic with existing `open` package - Use `variant: "warning"` for error toasts instead of `"info"` Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
1 parent 9094fee commit 4692552

1 file changed

Lines changed: 10 additions & 15 deletions

File tree

  • packages/opencode/src/cli/cmd/tui

‎packages/opencode/src/cli/cmd/tui/app.tsx‎

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import { Tracer } from "@/altimate/observability/tracing"
3232
import { renderTraceViewer } from "@/altimate/observability/viewer"
3333
import { DialogTraceList } from "./component/dialog-trace-list"
3434
import fsAsync from "fs/promises"
35-
import fsSync from "fs"
3635

3736
// altimate_change start - shared trace viewer server
3837
let traceViewerServer: ReturnType<typeof Bun.serve> | undefined
@@ -47,8 +46,9 @@ function getTraceViewerUrl(sessionID: string): string {
4746
// Extract session ID from path: /view/<sessionID> or /api/<sessionID>
4847
const parts = url.pathname.split("/").filter(Boolean)
4948
const action = parts[0] // "view" or "api"
50-
const sid = parts[1]
51-
if (!sid) return new Response("Usage: /view/<sessionID>", { status: 400 })
49+
const encodedSid = parts[1]
50+
if (!encodedSid) return new Response("Usage: /view/<sessionID>", { status: 400 })
51+
const sid = decodeURIComponent(encodedSid)
5252

5353
const safeId = sid.replace(/[/\\.:]/g, "_")
5454
const traceFile = `${tracesDir}/${safeId}.json`
@@ -67,15 +67,15 @@ function getTraceViewerUrl(sessionID: string): string {
6767
// Serve HTML viewer
6868
try {
6969
const trace = JSON.parse(await fsAsync.readFile(traceFile, "utf-8"))
70-
const html = renderTraceViewer(trace, { live: true, apiPath: "/api/" + sid })
70+
const html = renderTraceViewer(trace, { live: true, apiPath: "/api/" + encodeURIComponent(sid) })
7171
return new Response(html, { headers: { "Content-Type": "text/html; charset=utf-8" } })
7272
} catch {
7373
return new Response("Trace not found. Try again after the agent responds.", { status: 404 })
7474
}
7575
},
7676
})
7777
}
78-
return `http://localhost:${traceViewerServer.port}/view/${sessionID}`
78+
return `http://127.0.0.1:${traceViewerServer.port}/view/${encodeURIComponent(sessionID)}`
7979
}
8080

8181
// altimate_change end — renderInlineViewer removed, now using renderTraceViewer from viewer.ts
@@ -268,26 +268,21 @@ function App() {
268268
const promptRef = usePromptRef()
269269

270270
// altimate_change start - shared trace viewer helper
271-
function openTraceInBrowser(sessionID: string) {
271+
async function openTraceInBrowser(sessionID: string) {
272272
try {
273273
// Check if trace file exists on disk before opening browser
274274
const safeId = sessionID.replace(/[/\\.:]/g, "_")
275275
const traceFile = `${Tracer.getTracesDir()}/${safeId}.json`
276-
if (!fsSync.existsSync(traceFile)) {
276+
const exists = await fsAsync.access(traceFile).then(() => true).catch(() => false)
277+
if (!exists) {
277278
toast.show({ variant: "warning", message: "Trace not available yet — send a prompt first", duration: 4000 })
278279
return
279280
}
280281
const url = getTraceViewerUrl(sessionID)
281-
const openArgs =
282-
process.platform === "darwin"
283-
? ["open", url]
284-
: process.platform === "win32"
285-
? ["cmd", "/c", "start", url]
286-
: ["xdg-open", url]
287-
Bun.spawn(openArgs, { stdout: "ignore", stderr: "ignore" })
282+
await open(url)
288283
toast.show({ variant: "info", message: `Trace viewer: ${url}`, duration: 6000 })
289284
} catch {
290-
toast.show({ variant: "info", message: `Trace files: ${Tracer.getTracesDir()}`, duration: 8000 })
285+
toast.show({ variant: "warning", message: `Failed to open browser. Trace files: ${Tracer.getTracesDir()}`, duration: 8000 })
291286
}
292287
}
293288
// altimate_change end

0 commit comments

Comments
 (0)