Skip to content

Commit dc985ff

Browse files
authored
fix(tui): fall back to local cwd when editor spawns in attach mode (anomalyco#30583)
1 parent a468680 commit dc985ff

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

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

‎packages/opencode/src/cli/cmd/tui/util/editor.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { defer } from "@/util/defer"
2+
import { existsSync } from "node:fs"
23
import { rm } from "node:fs/promises"
34
import { tmpdir } from "node:os"
45
import { join } from "node:path"
@@ -13,13 +14,17 @@ export async function open(opts: { value: string; renderer: CliRenderer; cwd?: s
1314
const filepath = join(tmpdir(), `${Date.now()}.md`)
1415
await using _ = defer(async () => rm(filepath, { force: true }))
1516

17+
// In attach mode the server's project directory may not exist locally.
18+
// Fall back to the local process cwd so the editor can still spawn.
19+
const cwd = opts.cwd && existsSync(opts.cwd) ? opts.cwd : process.cwd()
20+
1621
await Filesystem.write(filepath, opts.value)
1722
opts.renderer.suspend()
1823
opts.renderer.currentRenderBuffer.clear()
1924
try {
2025
const parts = editor.split(" ")
2126
const proc = Process.spawn([...parts, filepath], {
22-
cwd: opts.cwd,
27+
cwd,
2328
stdin: "inherit",
2429
stdout: "inherit",
2530
stderr: "inherit",

0 commit comments

Comments
 (0)