2026-02-14 17:41:40 +09:00
|
|
|
import { existsSync, readdirSync } from "node:fs"
|
|
|
|
|
import { join } from "node:path"
|
2026-02-14 17:50:08 +09:00
|
|
|
import { getOpenCodeStorageDir } from "./data-path"
|
2026-02-14 18:16:18 +09:00
|
|
|
import { isSqliteBackend } from "./opencode-storage-detection"
|
2026-02-14 18:53:58 +09:00
|
|
|
import { log } from "./logger"
|
2026-02-14 17:50:08 +09:00
|
|
|
|
|
|
|
|
const MESSAGE_STORAGE = join(getOpenCodeStorageDir(), "message")
|
2026-02-14 17:41:40 +09:00
|
|
|
|
|
|
|
|
export function getMessageDir(sessionID: string): string | null {
|
2026-02-14 17:50:08 +09:00
|
|
|
if (!sessionID.startsWith("ses_")) return null
|
2026-02-14 18:16:18 +09:00
|
|
|
if (isSqliteBackend()) return null
|
2026-02-14 17:41:40 +09:00
|
|
|
if (!existsSync(MESSAGE_STORAGE)) return null
|
|
|
|
|
|
|
|
|
|
const directPath = join(MESSAGE_STORAGE, sessionID)
|
|
|
|
|
if (existsSync(directPath)) {
|
|
|
|
|
return directPath
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
for (const dir of readdirSync(MESSAGE_STORAGE)) {
|
|
|
|
|
const sessionPath = join(MESSAGE_STORAGE, dir, sessionID)
|
|
|
|
|
if (existsSync(sessionPath)) {
|
|
|
|
|
return sessionPath
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-02-14 18:53:58 +09:00
|
|
|
} catch (error) {
|
|
|
|
|
log(`Error reading message directory: ${error}`)
|
|
|
|
|
return null
|
|
|
|
|
}
|
2026-02-14 17:41:40 +09:00
|
|
|
|
|
|
|
|
return null
|
|
|
|
|
}
|