/**
 * LCM (Lossless Context Memory) search and describe via platform IPC.
 */
import path from "path";
import { getContext } from "../client.js";
import { writeIpcFile, pollJsonFile, clearStaleResult } from "../ipc.js";
function groupFolder() {
    return process.env.NANOCLAW_GROUP_FOLDER ?? "";
}
function messagesDir(ipcDir) {
    return path.join(ipcDir, "messages");
}
export async function lcmSearch(pattern, ipcDir) {
    const dir = ipcDir ?? getContext().ipcDir;
    const resultFile = path.join(dir, "lcm-search-result.json");
    clearStaleResult(resultFile);
    writeIpcFile(messagesDir(dir), { type: "lcm-search", groupFolder: groupFolder(), pattern });
    return pollJsonFile(resultFile, (d) => d.done === true, 15000);
}
export async function lcmDescribe(id, ipcDir) {
    const dir = ipcDir ?? getContext().ipcDir;
    const resultFile = path.join(dir, "lcm-describe-result.json");
    clearStaleResult(resultFile);
    writeIpcFile(messagesDir(dir), { type: "lcm-describe", groupFolder: groupFolder(), id: id ?? null });
    return pollJsonFile(resultFile, (d) => d.done === true, 15000);
}
export async function lcmSemanticSearch(query, limit = 5, ipcDir) {
    const dir = ipcDir ?? getContext().ipcDir;
    const resultFile = path.join(dir, "lcm-semantic-search-result.json");
    clearStaleResult(resultFile);
    writeIpcFile(messagesDir(dir), { type: "lcm-semantic-search", groupFolder: groupFolder(), query, limit });
    return pollJsonFile(resultFile, (d) => d.done === true, 30000);
}
export async function lcmHybridSearch(query, limit = 5, ipcDir) {
    const dir = ipcDir ?? getContext().ipcDir;
    const resultFile = path.join(dir, "lcm-hybrid-search-result.json");
    clearStaleResult(resultFile);
    writeIpcFile(messagesDir(dir), { type: "lcm-hybrid-search", groupFolder: groupFolder(), query, limit });
    return pollJsonFile(resultFile, (d) => d.done === true, 30000);
}
//# sourceMappingURL=lcm.js.map