Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions packages/opencode/src/cli/cmd/tui/component/prompt/frecency.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import path from "path"
import { Global } from "@/global"
import { Filesystem } from "@/util/filesystem"
import { onMount } from "solid-js"
import { createStore } from "solid-js/store"
import { createSimpleContext } from "../../context/helper"
import { appendFile, writeFile } from "fs/promises"
import { appendFile } from "fs/promises"

function calculateFrecency(entry?: { frequency: number; lastOpen: number }): number {
if (!entry) return 0
Expand All @@ -20,7 +19,9 @@ export const { use: useFrecency, provider: FrecencyProvider } = createSimpleCont
init: () => {
const frecencyPath = path.join(Global.Path.state, "frecency.jsonl")
onMount(async () => {
const text = await Filesystem.readText(frecencyPath).catch(() => "")
const text = await Bun.file(frecencyPath)
.text()
.catch(() => "")
const lines = text
.split("\n")
.filter(Boolean)
Expand Down Expand Up @@ -54,7 +55,7 @@ export const { use: useFrecency, provider: FrecencyProvider } = createSimpleCont

if (sorted.length > 0) {
const content = sorted.map((entry) => JSON.stringify(entry)).join("\n") + "\n"
writeFile(frecencyPath, content).catch(() => {})
void Bun.write(frecencyPath, content)
}
})

Expand All @@ -77,7 +78,7 @@ export const { use: useFrecency, provider: FrecencyProvider } = createSimpleCont
.slice(0, MAX_FRECENCY_ENTRIES)
setStore("data", Object.fromEntries(sorted))
const content = sorted.map(([path, entry]) => JSON.stringify({ path, ...entry })).join("\n") + "\n"
writeFile(frecencyPath, content).catch(() => {})
void Bun.write(frecencyPath, content)
}
}

Expand Down
11 changes: 6 additions & 5 deletions packages/opencode/src/cli/cmd/tui/component/prompt/history.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import path from "path"
import { Global } from "@/global"
import { Filesystem } from "@/util/filesystem"
import { onMount } from "solid-js"
import { createStore, produce, unwrap } from "solid-js/store"
import { createSimpleContext } from "../../context/helper"
import { appendFile, writeFile } from "fs/promises"
import { appendFile } from "fs/promises"
import type { AgentPart, FilePart, TextPart } from "@opencode-ai/sdk/v2"

export type PromptInfo = {
Expand Down Expand Up @@ -32,7 +31,9 @@ export const { use: usePromptHistory, provider: PromptHistoryProvider } = create
init: () => {
const historyPath = path.join(Global.Path.state, "prompt-history.jsonl")
onMount(async () => {
const text = await Filesystem.readText(historyPath).catch(() => "")
const text = await Bun.file(historyPath)
.text()
.catch(() => "")
const lines = text
.split("\n")
.filter(Boolean)
Expand All @@ -51,7 +52,7 @@ export const { use: usePromptHistory, provider: PromptHistoryProvider } = create
// Rewrite file with only valid entries to self-heal corruption
if (lines.length > 0) {
const content = lines.map((line) => JSON.stringify(line)).join("\n") + "\n"
writeFile(historyPath, content).catch(() => {})
void Bun.write(historyPath, content)
}
})

Expand Down Expand Up @@ -97,7 +98,7 @@ export const { use: usePromptHistory, provider: PromptHistoryProvider } = create

if (trimmed) {
const content = store.history.map((line) => JSON.stringify(line)).join("\n") + "\n"
writeFile(historyPath, content).catch(() => {})
void Bun.write(historyPath, content)
return
}

Expand Down
15 changes: 8 additions & 7 deletions packages/opencode/src/cli/cmd/tui/component/prompt/stash.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import path from "path"
import { Global } from "@/global"
import { Filesystem } from "@/util/filesystem"
import { onMount } from "solid-js"
import { createStore, produce, unwrap } from "solid-js/store"
import { createSimpleContext } from "../../context/helper"
import { appendFile, writeFile } from "fs/promises"
import { appendFile } from "fs/promises"
import type { PromptInfo } from "./history"

export type StashEntry = {
Expand All @@ -20,7 +19,9 @@ export const { use: usePromptStash, provider: PromptStashProvider } = createSimp
init: () => {
const stashPath = path.join(Global.Path.state, "prompt-stash.jsonl")
onMount(async () => {
const text = await Filesystem.readText(stashPath).catch(() => "")
const text = await Bun.file(stashPath)
.text()
.catch(() => "")
const lines = text
.split("\n")
.filter(Boolean)
Expand All @@ -39,7 +40,7 @@ export const { use: usePromptStash, provider: PromptStashProvider } = createSimp
// Rewrite file with only valid entries to self-heal corruption
if (lines.length > 0) {
const content = lines.map((line) => JSON.stringify(line)).join("\n") + "\n"
writeFile(stashPath, content).catch(() => {})
void Bun.write(stashPath, content)
}
})

Expand All @@ -66,7 +67,7 @@ export const { use: usePromptStash, provider: PromptStashProvider } = createSimp

if (trimmed) {
const content = store.entries.map((line) => JSON.stringify(line)).join("\n") + "\n"
writeFile(stashPath, content).catch(() => {})
void Bun.write(stashPath, content)
return
}

Expand All @@ -82,7 +83,7 @@ export const { use: usePromptStash, provider: PromptStashProvider } = createSimp
)
const content =
store.entries.length > 0 ? store.entries.map((line) => JSON.stringify(line)).join("\n") + "\n" : ""
writeFile(stashPath, content).catch(() => {})
void Bun.write(stashPath, content)
return entry
},
remove(index: number) {
Expand All @@ -94,7 +95,7 @@ export const { use: usePromptStash, provider: PromptStashProvider } = createSimp
)
const content =
store.entries.length > 0 ? store.entries.map((line) => JSON.stringify(line)).join("\n") + "\n" : ""
writeFile(stashPath, content).catch(() => {})
void Bun.write(stashPath, content)
},
}
},
Expand Down
8 changes: 4 additions & 4 deletions packages/opencode/src/cli/cmd/tui/context/kv.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Global } from "@/global"
import { Filesystem } from "@/util/filesystem"
import { createSignal, type Setter } from "solid-js"
import { createStore } from "solid-js/store"
import { createSimpleContext } from "./helper"
Expand All @@ -12,9 +11,10 @@ export const { use: useKV, provider: KVProvider } = createSimpleContext({
const [store, setStore] = createStore<Record<string, any>>()
const filePath = path.join(Global.Path.state, "kv.json")

Filesystem.readJson(filePath)
Bun.file(filePath)
.json()
.then((x) => {
setStore(x)
if (typeof x === "object" && x !== null) setStore(x as Record<string, any>)
})
.catch(() => {})
.finally(() => {
Expand Down Expand Up @@ -44,7 +44,7 @@ export const { use: useKV, provider: KVProvider } = createSimpleContext({
},
set(key: string, value: any) {
setStore(key, value)
Filesystem.writeJson(filePath, store)
void Bun.write(filePath, JSON.stringify(store, null, 2))
},
}
return result
Expand Down
21 changes: 14 additions & 7 deletions packages/opencode/src/cli/cmd/tui/context/local.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { Provider } from "@/provider/provider"
import { useArgs } from "./args"
import { useSDK } from "./sdk"
import { RGBA } from "@opentui/core"
import { Filesystem } from "@/util/filesystem"

export const { use: useLocal, provider: LocalProvider } = createSimpleContext({
name: "Local",
Expand Down Expand Up @@ -131,14 +130,22 @@ export const { use: useLocal, provider: LocalProvider } = createSimpleContext({
return
}
state.pending = false
Filesystem.writeJson(filePath, {
recent: modelStore.recent,
favorite: modelStore.favorite,
variant: modelStore.variant,
})
void Bun.write(
filePath,
JSON.stringify(
{
recent: modelStore.recent,
favorite: modelStore.favorite,
variant: modelStore.variant,
},
null,
2,
),
)
}

Filesystem.readJson(filePath)
Bun.file(filePath)
.json()
.then((x: any) => {
if (Array.isArray(x.recent)) setModelStore("recent", x.recent)
if (Array.isArray(x.favorite)) setModelStore("favorite", x.favorite)
Expand Down
8 changes: 4 additions & 4 deletions packages/opencode/src/cli/cmd/tui/routes/session/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ import { Editor } from "../../util/editor"
import stripAnsi from "strip-ansi"
import { usePromptRef } from "../../context/prompt"
import { useExit } from "../../context/exit"
import { Filesystem } from "@/util/filesystem"
import { Global } from "@/global"
import { AppFileSystem } from "@opencode-ai/shared/filesystem"
import { PermissionPrompt } from "./permission"
import { QuestionPrompt } from "./question"
import { DialogExportOptions } from "../../ui/dialog-export-options"
Expand Down Expand Up @@ -916,12 +916,12 @@ export function Session() {
const filename = options.filename.trim()
const filepath = path.join(exportDir, filename)

await Filesystem.write(filepath, transcript)
await Bun.write(filepath, transcript)

// Open with EDITOR if available
const result = await Editor.open({ value: transcript, renderer })
if (result !== undefined) {
await Filesystem.write(filepath, result)
await Bun.write(filepath, result)
}

toast.show({ message: `Session exported to ${filename}`, variant: "success" })
Expand Down Expand Up @@ -2236,7 +2236,7 @@ function Skill(props: ToolProps<typeof SkillTool>) {
function Diagnostics(props: { diagnostics?: Record<string, Record<string, any>[]>; filePath: string }) {
const { theme } = useTheme()
const errors = createMemo(() => {
const normalized = Filesystem.normalizePath(props.filePath)
const normalized = AppFileSystem.normalizePath(props.filePath)
const arr = props.diagnostics?.[normalized] ?? []
return arr.filter((x) => x.severity === 1).slice(0, 3)
})
Expand Down
4 changes: 1 addition & 3 deletions packages/opencode/src/cli/cmd/tui/util/clipboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { lazy } from "../../../../util/lazy.js"
import { tmpdir } from "os"
import path from "path"
import fs from "fs/promises"
import { Filesystem } from "../../../../util/filesystem"
import { Process } from "../../../../util/process"
import { which } from "../../../../util/which"

Expand Down Expand Up @@ -58,8 +57,7 @@ export namespace Clipboard {
],
{ nothrow: true },
)
const buffer = await Filesystem.readBytes(tmpfile)
return { data: buffer.toString("base64"), mime: "image/png" }
return { data: Buffer.from(await Bun.file(tmpfile).arrayBuffer()).toString("base64"), mime: "image/png" }
} catch {
} finally {
await fs.rm(tmpfile, { force: true }).catch(() => {})
Expand Down
5 changes: 2 additions & 3 deletions packages/opencode/src/cli/cmd/tui/util/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { rm } from "node:fs/promises"
import { tmpdir } from "node:os"
import { join } from "node:path"
import { CliRenderer } from "@opentui/core"
import { Filesystem } from "@/util/filesystem"
import { Process } from "@/util/process"

export namespace Editor {
Expand All @@ -14,7 +13,7 @@ export namespace Editor {
const filepath = join(tmpdir(), `${Date.now()}.md`)
await using _ = defer(async () => rm(filepath, { force: true }))

await Filesystem.write(filepath, opts.value)
await Bun.write(filepath, opts.value)
opts.renderer.suspend()
opts.renderer.currentRenderBuffer.clear()
try {
Expand All @@ -26,7 +25,7 @@ export namespace Editor {
shell: process.platform === "win32",
})
await proc.exited
const content = await Filesystem.readText(filepath)
const content = await Bun.file(filepath).text()
return content || undefined
} finally {
opts.renderer.currentRenderBuffer.clear()
Expand Down
Loading