Files
oh-my-opencode/src/hooks/session-recovery/storage/text-part-injector.ts
T
YeonGyu-Kim 804895b24a feat(storage): gate JSON write operations on OpenCode beta, document degraded features
- Gate session-recovery writes: injectTextPart, prependThinkingPart, replaceEmptyTextParts, stripThinkingParts

- Gate context-window-recovery writes: truncateToolResult

- Add isSqliteBackend() checks with log warnings

- Create beta-degraded-features.md documentation
2026-02-16 16:13:40 +09:00

37 lines
938 B
TypeScript

import { existsSync, mkdirSync, writeFileSync } from "node:fs"
import { join } from "node:path"
import { PART_STORAGE } from "../constants"
import type { StoredTextPart } from "../types"
import { generatePartId } from "./part-id"
import { log, isSqliteBackend } from "../../../shared"
export function injectTextPart(sessionID: string, messageID: string, text: string): boolean {
if (isSqliteBackend()) {
log("[session-recovery] Disabled on SQLite backend: injectTextPart")
return false
}
const partDir = join(PART_STORAGE, messageID)
if (!existsSync(partDir)) {
mkdirSync(partDir, { recursive: true })
}
const partId = generatePartId()
const part: StoredTextPart = {
id: partId,
sessionID,
messageID,
type: "text",
text,
synthetic: true,
}
try {
writeFileSync(join(partDir, `${partId}.json`), JSON.stringify(part, null, 2))
return true
} catch {
return false
}
}