Skip to content

Commit 48f1d53

Browse files
committed
fix: prevent libopentui.so extraction to /tmp on serve/headless mode
Three changes to fix issue anomalyco#20043 where opencode serve extracts libopentui.so (~4.2MB) to /tmp on every startup: 1. Made @opentui/keymap/extras import lazy (dynamic import) in tui.ts. Native TUI library is now only loaded when TUI config is actually initialized, not during static module evaluation. This prevents extraction entirely in serve/headless mode. 2. Set BUN_TMPDIR=~/.cache/opencode/bun-runtime in the npm wrapper script, redirecting native library extraction from /tmp to a stable cache directory to avoid polluting shared temp space. 3. Added BUN_TMPDIR=/var/lib/opencode-bun-tmp in Dockerfile for container deployments.
1 parent 67ee715 commit 48f1d53

3 files changed

Lines changed: 7 additions & 1 deletion

File tree

‎packages/opencode/Dockerfile‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ FROM alpine AS base
44
# On ephemeral containers, the cache is not useful
55
ARG BUN_RUNTIME_TRANSPILER_CACHE_PATH=0
66
ENV BUN_RUNTIME_TRANSPILER_CACHE_PATH=${BUN_RUNTIME_TRANSPILER_CACHE_PATH}
7+
# Prevent extraction of bundled native libs into shared /tmp
8+
ARG BUN_TMPDIR=/var/lib/opencode-bun-tmp
9+
ENV BUN_TMPDIR=${BUN_TMPDIR}
710
RUN apk add libgcc libstdc++ ripgrep
811

912
FROM base AS build-amd64

‎packages/opencode/bin/opencode‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ const os = require("os")
88
const forwardedSignals = ["SIGINT", "SIGTERM", "SIGHUP"]
99

1010
function run(target) {
11+
const bunTmpDir = process.env.BUN_TMPDIR || path.join(os.homedir(), ".cache", "opencode", "bun-runtime")
12+
fs.mkdirSync(bunTmpDir, { recursive: true })
1113
const child = childProcess.spawn(target, process.argv.slice(2), {
1214
stdio: "inherit",
15+
env: { ...process.env, BUN_TMPDIR: bunTmpDir },
1316
})
1417

1518
child.on("error", (error) => {

‎packages/opencode/src/cli/cmd/tui/config/tui.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
export * as TuiConfig from "./tui"
22

3-
import { createBindingLookup } from "@opentui/keymap/extras"
43
import { mergeDeep, unique } from "remeda"
54
import { Context, Effect, Fiber, Layer, Schema } from "effect"
65
import { ConfigParse } from "@/config/parse"
@@ -195,6 +194,7 @@ const loadState = Effect.fn("TuiConfig.loadState")(function* (ctx: { directory:
195194
keybinds.input_undo ??= unique(["ctrl+z", ...(typeof inputUndo === "string" ? inputUndo.split(",") : [])]).join(",")
196195
}
197196
const parsedKeybinds = TuiKeybind.parse(keybinds)
197+
const { createBindingLookup } = yield* Effect.promise(() => import("@opentui/keymap/extras"))
198198
const result: Resolved = {
199199
...acc.result,
200200
keybinds: createBindingLookup(TuiKeybind.toBindingConfig(parsedKeybinds), {

0 commit comments

Comments
 (0)