// @bun
import {
  addTask,
  init_checkpoint,
  loadTasks,
  saveCheckpoint,
  saveTasks,
  updateTaskStatus
} from "./chunk-n8kbhswc.js";
import {
  getAutoMemPath,
  init_paths
} from "./chunk-7rrkrej7.js";
import {
  __esm
} from "./chunk-hhsxm2yr.js";

// src/commands/checkpoint/checkpoint.ts
function serializeTaskTree(tasks, depth = 0) {
  const lines = [];
  for (const task of tasks) {
    const indent = "  ".repeat(depth);
    const icon = task.status === "completed" ? "\u2713" : task.status === "in_progress" ? "\u27F3" : task.status === "blocked" ? "\u2717" : "\u25CB";
    lines.push(`${indent}${icon} ${task.id}: ${task.title}`);
    if (task.children.length > 0) {
      lines.push(serializeTaskTree(task.children, depth + 1));
    }
  }
  return lines.join(`
`);
}
var call = async (args, context) => {
  const title = args?.trim() || "Untitled session";
  const now = new Date().toISOString();
  const data = {
    title,
    currentState: "Session checkpoint saved",
    keyFiles: [],
    recentErrors: "",
    nextSteps: "",
    taskSummary: "",
    timestamp: now
  };
  await saveCheckpoint(data);
  return {
    type: "text",
    value: `\u2713 Checkpoint saved: "${title}"
Location: ${getAutoMemPath()}checkpoint.md`
  };
}, taskCall = async (args, context) => {
  if (!args?.trim()) {
    const tasks = await loadTasks();
    if (tasks.length === 0) {
      return {
        type: "text",
        value: "No tasks tracked. Use: /task add <id> <title>"
      };
    }
    const lines = serializeTaskTree(tasks);
    return { type: "text", value: lines };
  }
  const parts = args.trim().split(/\s+/);
  const subcommand = parts[0];
  if (subcommand === "add") {
    const id = parts[1];
    const taskTitle = parts.slice(2).join(" ");
    if (!id || !taskTitle) {
      return {
        type: "text",
        value: "Usage: /task add <id> <title> [parentId]"
      };
    }
    const parentId = parts.length > 3 ? parts[parts.length - 1] : null;
    const tasks = await loadTasks();
    if (addTask(tasks, parentId, id, taskTitle)) {
      await saveTasks(tasks);
      return { type: "text", value: `\u2713 Task ${id} added: ${taskTitle}` };
    }
    return { type: "text", value: `\u2717 Parent task ${parentId} not found` };
  }
  if (subcommand === "done" || subcommand === "complete") {
    const taskId = parts[1];
    if (!taskId) {
      return { type: "text", value: "Usage: /task done <id>" };
    }
    const tasks = await loadTasks();
    if (updateTaskStatus(tasks, taskId, "completed")) {
      await saveTasks(tasks);
      return { type: "text", value: `\u2713 Task ${taskId} marked complete` };
    }
    return { type: "text", value: `\u2717 Task ${taskId} not found` };
  }
  if (subcommand === "start" || subcommand === "progress") {
    const taskId = parts[1];
    if (!taskId) {
      return { type: "text", value: "Usage: /task start <id>" };
    }
    const tasks = await loadTasks();
    if (updateTaskStatus(tasks, taskId, "in_progress")) {
      await saveTasks(tasks);
      return { type: "text", value: `\u2713 Task ${taskId} started` };
    }
    return { type: "text", value: `\u2717 Task ${taskId} not found` };
  }
  return {
    type: "text",
    value: `Usage:
  /task \u2014 show tasks
  /task add <id> <title> [parentId]
  /task done <id>
  /task start <id>`
  };
};
var init_checkpoint2 = __esm(() => {
  init_checkpoint();
  init_paths();
});

export { call, taskCall, init_checkpoint2 as init_checkpoint };

//# debugId=67780DE95E769C6264756E2164756E21
//# sourceMappingURL=chunk-8p7y66fr.js.map
