From 15dc33d1a38f3beb30fdc1a2bd2a0f3dd124a3a8 Mon Sep 17 00:00:00 2001 From: Dax Date: Tue, 24 Mar 2026 18:20:11 -0400 Subject: feat(tui): add heap snapshot functionality for TUI and server (#19028) --- .opencode/command/changelog.md | 18 +++++++++++++++--- packages/opencode/src/cli/cmd/tui/app.tsx | 11 ++++++----- packages/opencode/src/cli/cmd/tui/thread.ts | 6 ++++++ packages/opencode/src/cli/cmd/tui/worker.ts | 5 +++++ 4 files changed, 32 insertions(+), 8 deletions(-) diff --git a/.opencode/command/changelog.md b/.opencode/command/changelog.md index 8a8e57d1b..7e066a20e 100644 --- a/.opencode/command/changelog.md +++ b/.opencode/command/changelog.md @@ -1,5 +1,17 @@ -go through each PR merged since the last tag +create UPCOMING_CHANGELOG.md + +it should have sections + +``` +# TUI + +# Desktop -for each PR spawn a subagent to summarize what the PR was about. focus on user facing changes. if it was entirely internal or code related you can ignore it. also skip docs updates. each subagent should append its summary to UPCOMING_CHANGELOG.md +# Core + +# Misc +``` + +go through each PR merged since the last tag -once that is done, read UPCOMING_CHANGELOG.md and group it into sections for better readability. make sure all PR references are preserved +for each PR spawn a subagent to summarize what the PR was about. focus on user facing changes. if it was entirely internal or code related you can ignore it. also skip docs updates. each subagent should append its summary to UPCOMING_CHANGELOG.md into the appropriate section. diff --git a/packages/opencode/src/cli/cmd/tui/app.tsx b/packages/opencode/src/cli/cmd/tui/app.tsx index 549c7c34a..8aabafd08 100644 --- a/packages/opencode/src/cli/cmd/tui/app.tsx +++ b/packages/opencode/src/cli/cmd/tui/app.tsx @@ -110,6 +110,7 @@ export function tui(input: { url: string args: Args config: TuiConfig.Info + onSnapshot?: () => Promise directory?: string fetch?: typeof fetch headers?: RequestInit["headers"] @@ -160,7 +161,7 @@ export function tui(input: { - + @@ -201,7 +202,7 @@ export function tui(input: { }) } -function App() { +function App(props: { onSnapshot?: () => Promise }) { const route = useRoute() const dimensions = useTerminalDimensions() const renderer = useRenderer() @@ -627,11 +628,11 @@ function App() { title: "Write heap snapshot", category: "System", value: "app.heap_snapshot", - onSelect: (dialog) => { - const path = writeHeapSnapshot() + onSelect: async (dialog) => { + const files = await props.onSnapshot?.() toast.show({ variant: "info", - message: `Heap snapshot written to ${path}`, + message: `Heap snapshot written to ${files?.join(", ")}`, duration: 5000, }) dialog.clear() diff --git a/packages/opencode/src/cli/cmd/tui/thread.ts b/packages/opencode/src/cli/cmd/tui/thread.ts index 6e787c7af..d984dc6f3 100644 --- a/packages/opencode/src/cli/cmd/tui/thread.ts +++ b/packages/opencode/src/cli/cmd/tui/thread.ts @@ -14,6 +14,7 @@ import type { EventSource } from "./context/sdk" import { win32DisableProcessedInput, win32InstallCtrlCGuard } from "./win32" import { TuiConfig } from "@/config/tui" import { Instance } from "@/project/instance" +import { writeHeapSnapshot } from "v8" declare global { const OPENCODE_WORKER_PATH: string @@ -201,6 +202,11 @@ export const TuiThreadCommand = cmd({ try { await tui({ url: transport.url, + async onSnapshot() { + const tui = writeHeapSnapshot("tui.heapsnapshot") + const server = await client.call("snapshot", undefined) + return [tui, server] + }, config, directory: cwd, fetch: transport.fetch, diff --git a/packages/opencode/src/cli/cmd/tui/worker.ts b/packages/opencode/src/cli/cmd/tui/worker.ts index 511182fe8..06cb179e9 100644 --- a/packages/opencode/src/cli/cmd/tui/worker.ts +++ b/packages/opencode/src/cli/cmd/tui/worker.ts @@ -10,6 +10,7 @@ import { GlobalBus } from "@/bus/global" import { createOpencodeClient, type Event } from "@opencode-ai/sdk/v2" import { Flag } from "@/flag/flag" import { setTimeout as sleep } from "node:timers/promises" +import { writeHeapSnapshot } from "node:v8" await Log.init({ print: process.argv.includes("--print-logs"), @@ -117,6 +118,10 @@ export const rpc = { body, } }, + snapshot() { + const result = writeHeapSnapshot("server.heapsnapshot") + return result + }, async server(input: { port: number; hostname: string; mdns?: boolean; cors?: string[] }) { if (server) await server.stop(true) server = await Server.listen(input) -- cgit v1.2.3