130f4ac080
- #3124: Session tools now merge SDK and file-backed sessions for SQLite backend - #3125: Cache priming fixed for OpenCode >=1.3.14 empty workspace - #3127: Activity-based progress detection prevents infinite compaction on Kimi/Minimax All 29 new tests pass, 4885 total tests passing.
30 lines
866 B
TypeScript
30 lines
866 B
TypeScript
import { existsSync, readdirSync } from "node:fs"
|
|
import { join } from "node:path"
|
|
import { MESSAGE_STORAGE } from "./opencode-storage-paths"
|
|
import { log } from "./logger"
|
|
|
|
export function getMessageDir(sessionID: string): string | null {
|
|
if (!sessionID.startsWith("ses_")) return null
|
|
if (/[/\\]|\.\./.test(sessionID)) 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
|
|
}
|