oh-my-opencode/src/shared/opencode-message-dir.ts
YeonGyu-Kim 1a744424ab fix: address all Cubic P2 review issues
- session-utils: log SDK errors instead of silent swallow
- opencode-message-dir: fix indentation, improve error log format
- storage: use session.list for sessionExists (handles empty sessions)
- storage.test: use resetStorageClient for proper SDK client cleanup
- todo-sync: add content-based fallback for id-less todo removal
2026-02-16 16:13:40 +09:00

30 lines
917 B
TypeScript

import { existsSync, readdirSync } from "node:fs"
import { join } from "node:path"
import { MESSAGE_STORAGE } from "./opencode-storage-paths"
import { isSqliteBackend } from "./opencode-storage-detection"
import { log } from "./logger"
export function getMessageDir(sessionID: string): string | null {
if (!sessionID.startsWith("ses_")) return null
if (isSqliteBackend()) return null
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
}
}
} catch (error) {
log("[opencode-message-dir] Failed to scan message directories", { sessionID, error: String(error) })
return null
}
return null
}