GeezerVison is showing github.com — feat(tui): add heap snapshot functionality for TUI and server (#19028) · nathanhinish/opencode@15dc33d
File treeExpand file treeCollapse file tree Open diff view settings packages/opencode/src/cli/cmd/tui
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboard +15-3Lines changed: 15 additions & 3 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
| 1 | | -go through each PR merged since the last tag | | 1 | +create UPCOMING_CHANGELOG.md | | 2 | + | | 3 | +it should have sections | | 4 | + | | 5 | +``` | | 6 | +# TUI | | 7 | +
| | 8 | +# Desktop | 2 | 9 |
| 3 | | -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 | | 10 | +# Core | | 11 | +
| | 12 | +# Misc | | 13 | +``` | | 14 | + | | 15 | +go through each PR merged since the last tag | 4 | 16 |
| 5 | | -once that is done, read UPCOMING_CHANGELOG.md and group it into sections for better readability. make sure all PR references are preserved | | 17 | +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. |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/cli/cmd/tui/app.tsx +6-5Lines changed: 6 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -110,6 +110,7 @@ export function tui(input: { | 110 | 110 | url: string | 111 | 111 | args: Args | 112 | 112 | config: TuiConfig.Info | | 113 | + onSnapshot?: () => Promise<string[]> | 113 | 114 | directory?: string | 114 | 115 | fetch?: typeof fetch | 115 | 116 | headers?: RequestInit["headers"] | @@ -160,7 +161,7 @@ export function tui(input: { | 160 | 161 | <FrecencyProvider> | 161 | 162 | <PromptHistoryProvider> | 162 | 163 | <PromptRefProvider> | 163 | | - <App /> | | 164 | + <App onSnapshot={input.onSnapshot} /> | 164 | 165 | </PromptRefProvider> | 165 | 166 | </PromptHistoryProvider> | 166 | 167 | </FrecencyProvider> | @@ -201,7 +202,7 @@ export function tui(input: { | 201 | 202 | }) | 202 | 203 | } | 203 | 204 |
| 204 | | -function App() { | | 205 | +function App(props: { onSnapshot?: () => Promise<string[]> }) { | 205 | 206 | const route = useRoute() | 206 | 207 | const dimensions = useTerminalDimensions() | 207 | 208 | const renderer = useRenderer() | @@ -627,11 +628,11 @@ function App() { | 627 | 628 | title: "Write heap snapshot", | 628 | 629 | category: "System", | 629 | 630 | value: "app.heap_snapshot", | 630 | | - onSelect: (dialog) => { | 631 | | - const path = writeHeapSnapshot() | | 631 | + onSelect: async (dialog) => { | | 632 | + const files = await props.onSnapshot?.() | 632 | 633 | toast.show({ | 633 | 634 | variant: "info", | 634 | | - message: `Heap snapshot written to ${path}`, | | 635 | + message: `Heap snapshot written to ${files?.join(", ")}`, | 635 | 636 | duration: 5000, | 636 | 637 | }) | 637 | 638 | dialog.clear() | |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/cli/cmd/tui/thread.ts +6Lines changed: 6 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -14,6 +14,7 @@ import type { EventSource } from "./context/sdk" | 14 | 14 | import { win32DisableProcessedInput, win32InstallCtrlCGuard } from "./win32" | 15 | 15 | import { TuiConfig } from "@/config/tui" | 16 | 16 | import { Instance } from "@/project/instance" | | 17 | +import { writeHeapSnapshot } from "v8" | 17 | 18 |
| 18 | 19 | declare global { | 19 | 20 | const OPENCODE_WORKER_PATH: string | @@ -201,6 +202,11 @@ export const TuiThreadCommand = cmd({ | 201 | 202 | try { | 202 | 203 | await tui({ | 203 | 204 | url: transport.url, | | 205 | + async onSnapshot() { | | 206 | + const tui = writeHeapSnapshot("tui.heapsnapshot") | | 207 | + const server = await client.call("snapshot", undefined) | | 208 | + return [tui, server] | | 209 | + }, | 204 | 210 | config, | 205 | 211 | directory: cwd, | 206 | 212 | fetch: transport.fetch, | |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/cli/cmd/tui/worker.ts +5Lines changed: 5 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -10,6 +10,7 @@ import { GlobalBus } from "@/bus/global" | 10 | 10 | import { createOpencodeClient, type Event } from "@opencode-ai/sdk/v2" | 11 | 11 | import { Flag } from "@/flag/flag" | 12 | 12 | import { setTimeout as sleep } from "node:timers/promises" | | 13 | +import { writeHeapSnapshot } from "node:v8" | 13 | 14 |
| 14 | 15 | await Log.init({ | 15 | 16 | print: process.argv.includes("--print-logs"), | @@ -117,6 +118,10 @@ export const rpc = { | 117 | 118 | body, | 118 | 119 | } | 119 | 120 | }, | | 121 | + snapshot() { | | 122 | + const result = writeHeapSnapshot("server.heapsnapshot") | | 123 | + return result | | 124 | + }, | 120 | 125 | async server(input: { port: number; hostname: string; mdns?: boolean; cors?: string[] }) { | 121 | 126 | if (server) await server.stop(true) | 122 | 127 | server = await Server.listen(input) | |
|