import { runUserMessage } from "../runner";
import { loadSettings } from "../config";
import { checkExistingDaemon } from "../pid";

export async function clear(): Promise<void> {
  const existingPid = await checkExistingDaemon();
  if (!existingPid) {
    console.log("QwenClaw daemon is not running.");
  }

  // Clear the daemon state
  const { unlink } = await import("fs/promises");
  const { join } = await import("path");
  const QWEN_DIR = join(process.cwd(), ".qwen");
  const HEARTBEAT_DIR = join(QWEN_DIR, "qwenclaw");
  const STATE_FILE = join(HEARTBEAT_DIR, "state.json");
  const SESSION_FILE = join(HEARTBEAT_DIR, "session.json");

  await unlink(STATE_FILE).catch(() => {});
  await unlink(SESSION_FILE).catch(() => {});

  console.log("QwenClaw state cleared.");
}
