|
|
@@ -1,10 +1,12 @@
|
|
|
import path from "path"
|
|
|
import { Global } from "@/global"
|
|
|
-import { Filesystem } from "@/util/filesystem"
|
|
|
+import { AppRuntime } from "@/effect/app-runtime"
|
|
|
+import { AppFileSystem } from "@opencode-ai/shared/filesystem"
|
|
|
+import { Effect } from "effect"
|
|
|
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 = {
|
|
|
@@ -19,8 +21,22 @@ export const { use: usePromptStash, provider: PromptStashProvider } = createSimp
|
|
|
name: "PromptStash",
|
|
|
init: () => {
|
|
|
const stashPath = path.join(Global.Path.state, "prompt-stash.jsonl")
|
|
|
+ const read = () =>
|
|
|
+ AppRuntime.runPromise(
|
|
|
+ Effect.gen(function* () {
|
|
|
+ const fs = yield* AppFileSystem.Service
|
|
|
+ return yield* fs.readFileString(stashPath)
|
|
|
+ }),
|
|
|
+ )
|
|
|
+ const write = (content: string) =>
|
|
|
+ AppRuntime.runPromise(
|
|
|
+ Effect.gen(function* () {
|
|
|
+ const fs = yield* AppFileSystem.Service
|
|
|
+ yield* fs.writeWithDirs(stashPath, content)
|
|
|
+ }),
|
|
|
+ )
|
|
|
onMount(async () => {
|
|
|
- const text = await Filesystem.readText(stashPath).catch(() => "")
|
|
|
+ const text = await read().catch(() => "")
|
|
|
const lines = text
|
|
|
.split("\n")
|
|
|
.filter(Boolean)
|
|
|
@@ -39,7 +55,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(() => {})
|
|
|
+ write(content).catch(() => {})
|
|
|
}
|
|
|
})
|
|
|
|
|
|
@@ -66,7 +82,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(() => {})
|
|
|
+ write(content).catch(() => {})
|
|
|
return
|
|
|
}
|
|
|
|
|
|
@@ -82,7 +98,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(() => {})
|
|
|
+ write(content).catch(() => {})
|
|
|
return entry
|
|
|
},
|
|
|
remove(index: number) {
|
|
|
@@ -94,7 +110,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(() => {})
|
|
|
+ write(content).catch(() => {})
|
|
|
},
|
|
|
}
|
|
|
},
|