/**
 * Scheduled task management via platform IPC.
 */
import fs from "fs";
import path from "path";
import { getContext } from "../client.js";
import { writeIpcFile } from "../ipc.js";
export async function listTasks() {
    const ctx = getContext();
    const file = path.join(ctx.ipcDir, "current_tasks.json");
    if (!fs.existsSync(file))
        return [];
    return JSON.parse(fs.readFileSync(file, "utf8"));
}
function groupFolder() {
    return process.env.NANOCLAW_GROUP_FOLDER ?? "";
}
function tasksDir(ipcDir) {
    return path.join(ipcDir, "tasks");
}
export async function scheduleTask(params, ipcDir) {
    const dir = ipcDir ?? getContext().ipcDir;
    writeIpcFile(tasksDir(dir), {
        type: "schedule_task",
        prompt: params.prompt,
        schedule_type: params.scheduleType,
        schedule_value: params.scheduleValue,
        context_mode: params.contextMode,
        targetJid: process.env.NANOCLAW_CHAT_JID,
        groupFolder: groupFolder(),
    });
}
export async function pauseTask(taskId, ipcDir) {
    const dir = ipcDir ?? getContext().ipcDir;
    writeIpcFile(tasksDir(dir), { type: "pause_task", id: taskId, groupFolder: groupFolder() });
}
export async function resumeTask(taskId, ipcDir) {
    const dir = ipcDir ?? getContext().ipcDir;
    writeIpcFile(tasksDir(dir), { type: "resume_task", id: taskId, groupFolder: groupFolder() });
}
export async function cancelTask(taskId, ipcDir) {
    const dir = ipcDir ?? getContext().ipcDir;
    writeIpcFile(tasksDir(dir), { type: "cancel_task", id: taskId, groupFolder: groupFolder() });
}
export async function updateTask(taskId, params, ipcDir) {
    const dir = ipcDir ?? getContext().ipcDir;
    writeIpcFile(tasksDir(dir), {
        type: "update_task",
        id: taskId,
        ...params,
        groupFolder: groupFolder(),
    });
}
//# sourceMappingURL=tasks.js.map