#!/usr/bin/env node
import { fileURLToPath as __fileURLToPath } from 'url';
import { dirname as __pathDirname } from 'path';
const __filename = __fileURLToPath(import.meta.url);
const __dirname = __pathDirname(__filename);
import { config as loadDotenv } from "dotenv";
loadDotenv({ override: true });
import { spawn, execSync, execFileSync } from "child_process";
import * as fs from "fs";
import * as path from "path";
import * as os from "os";
import { program } from "commander";
import { v4 as uuidv4 } from "uuid";
import chalk from "chalk";
import { initializeTracing, trace } from "../core/trace/index.js";
import {
  generateSessionSummary,
  formatSummaryMessage
} from "../hooks/session-summary.js";
import { sendNotification } from "../hooks/sms-notify.js";
const DEFAULT_SM_CONFIG = {
  defaultWorktree: false,
  defaultSandbox: false,
  defaultChrome: false,
  defaultTracing: true,
  defaultRemote: false,
  defaultNotifyOnDone: true,
  defaultWhatsApp: false
};
function getConfigPath() {
  return path.join(os.homedir(), ".stackmemory", "claude-sm.json");
}
function loadSMConfig() {
  try {
    const configPath = getConfigPath();
    if (fs.existsSync(configPath)) {
      const content = fs.readFileSync(configPath, "utf8");
      return { ...DEFAULT_SM_CONFIG, ...JSON.parse(content) };
    }
  } catch {
  }
  return { ...DEFAULT_SM_CONFIG };
}
function saveSMConfig(config) {
  const configPath = getConfigPath();
  const dir = path.dirname(configPath);
  if (!fs.existsSync(dir)) {
    fs.mkdirSync(dir, { recursive: true });
  }
  fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
}
class ClaudeSM {
  config;
  stackmemoryPath;
  worktreeScriptPath;
  claudeConfigDir;
  smConfig;
  constructor() {
    this.smConfig = loadSMConfig();
    this.config = {
      instanceId: this.generateInstanceId(),
      useSandbox: this.smConfig.defaultSandbox,
      useChrome: this.smConfig.defaultChrome,
      useWorktree: this.smConfig.defaultWorktree,
      useRemote: this.smConfig.defaultRemote,
      notifyOnDone: this.smConfig.defaultNotifyOnDone,
      useWhatsApp: this.smConfig.defaultWhatsApp,
      contextEnabled: true,
      tracingEnabled: this.smConfig.defaultTracing,
      verboseTracing: false,
      sessionStartTime: Date.now()
    };
    this.stackmemoryPath = this.findStackMemory();
    this.worktreeScriptPath = path.join(
      __dirname,
      "../../scripts/claude-worktree-manager.sh"
    );
    this.claudeConfigDir = path.join(os.homedir(), ".claude");
    if (!fs.existsSync(this.claudeConfigDir)) {
      fs.mkdirSync(this.claudeConfigDir, { recursive: true });
    }
  }
  generateInstanceId() {
    return uuidv4().substring(0, 8);
  }
  findStackMemory() {
    const possiblePaths = [
      path.join(os.homedir(), ".stackmemory", "bin", "stackmemory"),
      "/usr/local/bin/stackmemory",
      "/opt/homebrew/bin/stackmemory",
      "stackmemory"
      // Rely on PATH
    ];
    for (const smPath of possiblePaths) {
      try {
        execFileSync("which", [smPath], { stdio: "ignore" });
        return smPath;
      } catch {
      }
    }
    return "stackmemory";
  }
  isGitRepo() {
    try {
      execSync("git rev-parse --git-dir", { stdio: "ignore" });
      return true;
    } catch {
      return false;
    }
  }
  getCurrentBranch() {
    try {
      return execSync("git rev-parse --abbrev-ref HEAD", {
        encoding: "utf8"
      }).trim();
    } catch {
      return "main";
    }
  }
  hasUncommittedChanges() {
    try {
      const status = execSync("git status --porcelain", { encoding: "utf8" });
      return status.length > 0;
    } catch {
      return false;
    }
  }
  resolveClaudeBin() {
    if (this.config.claudeBin && this.config.claudeBin.trim()) {
      return this.config.claudeBin.trim();
    }
    const envBin = process.env["CLAUDE_BIN"];
    if (envBin && envBin.trim()) return envBin.trim();
    try {
      execSync("which claude", { stdio: "ignore" });
      return "claude";
    } catch {
    }
    return null;
  }
  setupWorktree() {
    if (!this.config.useWorktree || !this.isGitRepo()) {
      return null;
    }
    console.log(chalk.blue("\u{1F333} Setting up isolated worktree..."));
    const timestamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-").substring(0, 19);
    const branch = this.config.branch || `claude-${this.config.task || "work"}-${timestamp}-${this.config.instanceId}`;
    const repoName = path.basename(process.cwd());
    const worktreePath = path.join(
      path.dirname(process.cwd()),
      `${repoName}--${branch}`
    );
    try {
      const flags = [];
      if (this.config.useSandbox) flags.push("--sandbox");
      if (this.config.useChrome) flags.push("--chrome");
      const cmd = `git worktree add -b "${branch}" "${worktreePath}"`;
      execSync(cmd, { stdio: "inherit" });
      console.log(chalk.green(`\u2705 Worktree created: ${worktreePath}`));
      console.log(chalk.gray(`   Branch: ${branch}`));
      const configPath = path.join(worktreePath, ".claude-instance.json");
      const configData = {
        instanceId: this.config.instanceId,
        worktreePath,
        branch,
        task: this.config.task,
        sandboxEnabled: this.config.useSandbox,
        chromeEnabled: this.config.useChrome,
        created: (/* @__PURE__ */ new Date()).toISOString(),
        parentRepo: process.cwd()
      };
      fs.writeFileSync(configPath, JSON.stringify(configData, null, 2));
      const envFiles = [".env", ".env.local", ".mise.toml", ".tool-versions"];
      for (const file of envFiles) {
        const srcPath = path.join(process.cwd(), file);
        if (fs.existsSync(srcPath)) {
          fs.copyFileSync(srcPath, path.join(worktreePath, file));
        }
      }
      return worktreePath;
    } catch (err) {
      console.error(chalk.red("\u274C Failed to create worktree:"), err);
      return null;
    }
  }
  saveContext(message, metadata = {}) {
    if (!this.config.contextEnabled) return;
    try {
      const contextData = {
        message,
        metadata: {
          ...metadata,
          instanceId: this.config.instanceId,
          worktree: this.config.worktreePath,
          timestamp: (/* @__PURE__ */ new Date()).toISOString()
        }
      };
      const cmd = `${this.stackmemoryPath} context save --json '${JSON.stringify(contextData)}'`;
      execSync(cmd, { stdio: "ignore" });
    } catch {
    }
  }
  loadContext() {
    if (!this.config.contextEnabled) return;
    try {
      console.log(chalk.blue("\u{1F4DA} Loading previous context..."));
      const cmd = `${this.stackmemoryPath} context show`;
      const output = execSync(cmd, {
        encoding: "utf8",
        stdio: ["pipe", "pipe", "pipe"]
        // Capture stderr to suppress errors
      });
      const lines = output.trim().split("\n").filter((l) => l.trim());
      if (lines.length > 3) {
        console.log(chalk.gray("Context stack loaded"));
      }
    } catch {
    }
  }
  detectMultipleInstances() {
    try {
      const lockDir = path.join(process.cwd(), ".claude-worktree-locks");
      if (!fs.existsSync(lockDir)) return false;
      const locks = fs.readdirSync(lockDir).filter((f) => f.endsWith(".lock"));
      const activeLocks = locks.filter((lockFile) => {
        const lockPath = path.join(lockDir, lockFile);
        const lockData = JSON.parse(fs.readFileSync(lockPath, "utf8"));
        const lockAge = Date.now() - new Date(lockData.created).getTime();
        return lockAge < 24 * 60 * 60 * 1e3;
      });
      return activeLocks.length > 0;
    } catch {
      return false;
    }
  }
  suggestWorktreeMode() {
    if (this.hasUncommittedChanges()) {
      console.log(chalk.yellow("\u26A0\uFE0F  Uncommitted changes detected"));
      console.log(
        chalk.gray("   Consider using --worktree to work in isolation")
      );
    }
    if (this.detectMultipleInstances()) {
      console.log(chalk.yellow("\u26A0\uFE0F  Other Claude instances detected"));
      console.log(
        chalk.gray("   Using --worktree is recommended to avoid conflicts")
      );
    }
  }
  async startWhatsAppServices() {
    const WEBHOOK_PORT = 3456;
    console.log(chalk.cyan("Starting WhatsApp services..."));
    const webhookRunning = await fetch(
      `http://localhost:${WEBHOOK_PORT}/health`
    ).then((r) => r.ok).catch(() => false);
    if (!webhookRunning) {
      const webhookPath = path.join(__dirname, "../hooks/sms-webhook.js");
      const webhookProcess = spawn("node", [webhookPath], {
        detached: true,
        stdio: "ignore",
        env: { ...process.env, SMS_WEBHOOK_PORT: String(WEBHOOK_PORT) }
      });
      webhookProcess.unref();
      console.log(
        chalk.gray(`  Webhook server starting on port ${WEBHOOK_PORT}`)
      );
    } else {
      console.log(
        chalk.gray(`  Webhook already running on port ${WEBHOOK_PORT}`)
      );
    }
    const ngrokRunning = await fetch("http://localhost:4040/api/tunnels").then((r) => r.ok).catch(() => false);
    if (!ngrokRunning) {
      const ngrokProcess = spawn("ngrok", ["http", String(WEBHOOK_PORT)], {
        detached: true,
        stdio: "ignore"
      });
      ngrokProcess.unref();
      console.log(chalk.gray("  ngrok tunnel starting..."));
      await new Promise((resolve) => setTimeout(resolve, 3e3));
    }
    try {
      const tunnels = await fetch("http://localhost:4040/api/tunnels").then(
        (r) => r.json()
      );
      const publicUrl = tunnels?.tunnels?.[0]?.public_url;
      if (publicUrl) {
        const configDir = path.join(os.homedir(), ".stackmemory");
        const configPath = path.join(configDir, "ngrok-url.txt");
        if (!fs.existsSync(configDir)) {
          fs.mkdirSync(configDir, { recursive: true });
        }
        fs.writeFileSync(configPath, publicUrl);
        console.log(
          chalk.green(`  WhatsApp webhook: ${publicUrl}/sms/incoming`)
        );
      }
    } catch {
      console.log(
        chalk.yellow("  Waiting for ngrok... URL will be available shortly")
      );
    }
  }
  async sendDoneNotification(exitCode) {
    try {
      const context = {
        instanceId: this.config.instanceId,
        exitCode,
        sessionStartTime: this.config.sessionStartTime,
        worktreePath: this.config.worktreePath,
        branch: this.config.branch,
        task: this.config.task
      };
      const summary = await generateSessionSummary(context);
      const message = formatSummaryMessage(summary, this.config.instanceId);
      console.log(chalk.cyan("\nSending session summary via WhatsApp..."));
      let options = summary.suggestions.slice(0, 4).map((s) => ({
        key: s.key,
        label: s.label,
        action: s.action
      }));
      if (options.length < 2) {
        const defaults = [
          { key: "1", label: "Start new session", action: "claude-sm" },
          {
            key: "2",
            label: "View logs",
            action: "tail -30 ~/.claude/logs/*.log"
          }
        ];
        options = defaults.slice(0, 2 - options.length).concat(options);
        options.forEach((o, i) => o.key = String(i + 1));
      }
      const result = await sendNotification({
        type: "task_complete",
        title: `Claude Session ${this.config.instanceId}`,
        message,
        prompt: {
          type: "options",
          options
        }
      });
      if (result.success) {
        console.log(chalk.green("Notification sent successfully"));
      } else {
        console.log(
          chalk.yellow(`Notification not sent: ${result.error || "unknown"}`)
        );
      }
    } catch (error) {
      console.log(
        chalk.yellow(
          `Could not send notification: ${error instanceof Error ? error.message : "unknown"}`
        )
      );
    }
  }
  async run(args) {
    const claudeArgs = [];
    let i = 0;
    while (i < args.length) {
      const arg = args[i];
      switch (arg) {
        case "--worktree":
        case "-w":
          this.config.useWorktree = true;
          break;
        case "--no-worktree":
        case "-W":
          this.config.useWorktree = false;
          break;
        case "--remote":
        case "-r":
          this.config.useRemote = true;
          break;
        case "--no-remote":
          this.config.useRemote = false;
          break;
        case "--notify-done":
        case "-n":
          this.config.notifyOnDone = true;
          break;
        case "--no-notify-done":
          this.config.notifyOnDone = false;
          break;
        case "--whatsapp":
          this.config.useWhatsApp = true;
          this.config.notifyOnDone = true;
          break;
        case "--no-whatsapp":
          this.config.useWhatsApp = false;
          break;
        case "--sandbox":
        case "-s":
          this.config.useSandbox = true;
          claudeArgs.push("--sandbox");
          break;
        case "--chrome":
        case "-c":
          this.config.useChrome = true;
          claudeArgs.push("--chrome");
          break;
        case "--no-context":
          this.config.contextEnabled = false;
          break;
        case "--no-trace":
          this.config.tracingEnabled = false;
          break;
        case "--verbose-trace":
          this.config.verboseTracing = true;
          break;
        case "--branch":
        case "-b":
          i++;
          this.config.branch = args[i];
          break;
        case "--task":
        case "-t":
          i++;
          this.config.task = args[i];
          break;
        case "--claude-bin":
          i++;
          this.config.claudeBin = args[i];
          process.env["CLAUDE_BIN"] = this.config.claudeBin;
          break;
        case "--auto":
        case "-a":
          if (this.isGitRepo()) {
            this.config.useWorktree = this.hasUncommittedChanges() || this.detectMultipleInstances();
          }
          break;
        default:
          claudeArgs.push(arg);
      }
      i++;
    }
    if (this.config.tracingEnabled) {
      process.env["DEBUG_TRACE"] = "true";
      process.env["STACKMEMORY_DEBUG"] = "true";
      process.env["TRACE_OUTPUT"] = "file";
      process.env["TRACE_MASK_SENSITIVE"] = "true";
      if (this.config.verboseTracing) {
        process.env["TRACE_VERBOSITY"] = "full";
        process.env["TRACE_PARAMS"] = "true";
        process.env["TRACE_RESULTS"] = "true";
        process.env["TRACE_MEMORY"] = "true";
      } else {
        process.env["TRACE_VERBOSITY"] = "summary";
        process.env["TRACE_PARAMS"] = "true";
        process.env["TRACE_RESULTS"] = "false";
      }
      initializeTracing();
      trace.command(
        "claude-sm",
        {
          instanceId: this.config.instanceId,
          worktree: this.config.useWorktree,
          sandbox: this.config.useSandbox,
          task: this.config.task
        },
        async () => {
        }
      );
    }
    console.log(chalk.blue("\u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557"));
    console.log(chalk.blue("\u2551     Claude + StackMemory + Worktree   \u2551"));
    console.log(chalk.blue("\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D"));
    console.log();
    if (this.isGitRepo()) {
      const branch = this.getCurrentBranch();
      console.log(chalk.gray(`\u{1F4CD} Current branch: ${branch}`));
      if (!this.config.useWorktree) {
        this.suggestWorktreeMode();
      }
    }
    if (this.config.useWorktree) {
      const worktreePath = this.setupWorktree();
      if (worktreePath) {
        this.config.worktreePath = worktreePath;
        process.chdir(worktreePath);
        this.saveContext("Created worktree for Claude instance", {
          action: "worktree_created",
          path: worktreePath,
          branch: this.config.branch
        });
      }
    }
    this.loadContext();
    process.env["CLAUDE_INSTANCE_ID"] = this.config.instanceId;
    if (this.config.worktreePath) {
      process.env["CLAUDE_WORKTREE_PATH"] = this.config.worktreePath;
    }
    if (this.config.useRemote) {
      process.env["CLAUDE_REMOTE"] = "1";
    }
    console.log(chalk.gray(`\u{1F916} Instance ID: ${this.config.instanceId}`));
    console.log(chalk.gray(`\u{1F4C1} Working in: ${process.cwd()}`));
    if (this.config.useSandbox) {
      console.log(chalk.yellow("\u{1F512} Sandbox mode enabled"));
    }
    if (this.config.useRemote) {
      console.log(
        chalk.cyan("\u{1F4F1} Remote mode: WhatsApp notifications for all questions")
      );
    }
    if (this.config.useChrome) {
      console.log(chalk.yellow("\u{1F310} Chrome automation enabled"));
    }
    if (this.config.tracingEnabled) {
      console.log(
        chalk.gray(`\u{1F50D} Debug tracing enabled (logs to ~/.stackmemory/traces/)`)
      );
      if (this.config.verboseTracing) {
        console.log(
          chalk.gray(`   Verbose mode: capturing all execution details`)
        );
      }
    }
    if (this.config.useWhatsApp) {
      console.log(
        chalk.cyan("\u{1F4F1} WhatsApp mode: notifications + webhook enabled")
      );
      await this.startWhatsAppServices();
    }
    console.log();
    console.log(chalk.gray("Starting Claude..."));
    console.log(chalk.gray("\u2500".repeat(42)));
    const claudeBin = this.resolveClaudeBin();
    if (!claudeBin) {
      console.error(chalk.red("\u274C Claude CLI not found."));
      console.log(
        chalk.gray(
          "   Install Claude CLI or set an override:\n     export CLAUDE_BIN=/path/to/claude\n     claude-sm --help\n\n   Ensure PATH includes npm global bin (npm bin -g)."
        )
      );
      process.exit(1);
      return;
    }
    const claude = spawn(claudeBin, claudeArgs, {
      stdio: "inherit",
      env: process.env
    });
    claude.on("error", (err) => {
      console.error(chalk.red("\u274C Failed to launch Claude CLI."));
      if (err.code === "ENOENT") {
        console.error(
          chalk.gray("   Not found. Set CLAUDE_BIN or install claude on PATH.")
        );
      } else if (err.code === "EPERM" || err.code === "EACCES") {
        console.error(
          chalk.gray(
            "   Permission/sandbox issue. Try outside a sandbox or set CLAUDE_BIN."
          )
        );
      } else {
        console.error(chalk.gray(`   ${err.message}`));
      }
      process.exit(1);
    });
    claude.on("exit", async (code) => {
      this.saveContext("Claude session ended", {
        action: "session_end",
        exitCode: code
      });
      if (this.config.tracingEnabled) {
        const summary = trace.getExecutionSummary();
        console.log();
        console.log(chalk.gray("\u2500".repeat(42)));
        console.log(chalk.blue("Debug Trace Summary:"));
        console.log(chalk.gray(summary));
      }
      if (this.config.notifyOnDone || this.config.useRemote) {
        await this.sendDoneNotification(code);
      }
      if (this.config.worktreePath) {
        console.log();
        console.log(chalk.gray("\u2500".repeat(42)));
        console.log(chalk.blue("Session ended in worktree:"));
        console.log(chalk.gray(`  ${this.config.worktreePath}`));
        console.log();
        console.log(chalk.gray("To remove worktree: gd_claude"));
        console.log(chalk.gray("To merge to main: cwm"));
      }
      process.exit(code || 0);
    });
    process.on("SIGINT", () => {
      this.saveContext("Claude session interrupted", {
        action: "session_interrupt"
      });
      claude.kill("SIGINT");
    });
    process.on("SIGTERM", () => {
      this.saveContext("Claude session terminated", {
        action: "session_terminate"
      });
      claude.kill("SIGTERM");
    });
  }
}
program.name("claude-sm").description("Claude with StackMemory context and worktree isolation").version("1.0.0");
const configCmd = program.command("config").description("Manage claude-sm defaults");
configCmd.command("show").description("Show current default settings").action(() => {
  const config = loadSMConfig();
  console.log(chalk.blue("claude-sm defaults:"));
  console.log(
    `  defaultWorktree: ${config.defaultWorktree ? chalk.green("true") : chalk.gray("false")}`
  );
  console.log(
    `  defaultSandbox:  ${config.defaultSandbox ? chalk.green("true") : chalk.gray("false")}`
  );
  console.log(
    `  defaultChrome:   ${config.defaultChrome ? chalk.green("true") : chalk.gray("false")}`
  );
  console.log(
    `  defaultTracing:  ${config.defaultTracing ? chalk.green("true") : chalk.gray("false")}`
  );
  console.log(
    `  defaultRemote:   ${config.defaultRemote ? chalk.green("true") : chalk.gray("false")}`
  );
  console.log(
    `  defaultNotifyOnDone: ${config.defaultNotifyOnDone ? chalk.green("true") : chalk.gray("false")}`
  );
  console.log(
    `  defaultWhatsApp: ${config.defaultWhatsApp ? chalk.green("true") : chalk.gray("false")}`
  );
  console.log(chalk.gray(`
Config: ${getConfigPath()}`));
});
configCmd.command("set <key> <value>").description("Set a default (e.g., set worktree true)").action((key, value) => {
  const config = loadSMConfig();
  const boolValue = value === "true" || value === "1" || value === "on";
  const keyMap = {
    worktree: "defaultWorktree",
    sandbox: "defaultSandbox",
    chrome: "defaultChrome",
    tracing: "defaultTracing",
    remote: "defaultRemote",
    "notify-done": "defaultNotifyOnDone",
    notifyondone: "defaultNotifyOnDone",
    whatsapp: "defaultWhatsApp"
  };
  const configKey = keyMap[key];
  if (!configKey) {
    console.log(chalk.red(`Unknown key: ${key}`));
    console.log(
      chalk.gray(
        "Valid keys: worktree, sandbox, chrome, tracing, remote, notify-done, whatsapp"
      )
    );
    process.exit(1);
  }
  config[configKey] = boolValue;
  saveSMConfig(config);
  console.log(chalk.green(`Set ${key} = ${boolValue}`));
});
configCmd.command("worktree-on").description("Enable worktree mode by default").action(() => {
  const config = loadSMConfig();
  config.defaultWorktree = true;
  saveSMConfig(config);
  console.log(chalk.green("Worktree mode enabled by default"));
});
configCmd.command("worktree-off").description("Disable worktree mode by default").action(() => {
  const config = loadSMConfig();
  config.defaultWorktree = false;
  saveSMConfig(config);
  console.log(chalk.green("Worktree mode disabled by default"));
});
configCmd.command("remote-on").description("Enable remote mode by default (WhatsApp for all questions)").action(() => {
  const config = loadSMConfig();
  config.defaultRemote = true;
  saveSMConfig(config);
  console.log(chalk.green("Remote mode enabled by default"));
});
configCmd.command("remote-off").description("Disable remote mode by default").action(() => {
  const config = loadSMConfig();
  config.defaultRemote = false;
  saveSMConfig(config);
  console.log(chalk.green("Remote mode disabled by default"));
});
configCmd.command("notify-done-on").description("Enable WhatsApp notification when session ends (default)").action(() => {
  const config = loadSMConfig();
  config.defaultNotifyOnDone = true;
  saveSMConfig(config);
  console.log(chalk.green("Notify-on-done enabled by default"));
});
configCmd.command("notify-done-off").description("Disable notification when session ends").action(() => {
  const config = loadSMConfig();
  config.defaultNotifyOnDone = false;
  saveSMConfig(config);
  console.log(chalk.green("Notify-on-done disabled by default"));
});
configCmd.command("whatsapp-on").description("Enable WhatsApp mode by default (auto-starts webhook + ngrok)").action(() => {
  const config = loadSMConfig();
  config.defaultWhatsApp = true;
  config.defaultNotifyOnDone = true;
  saveSMConfig(config);
  console.log(chalk.green("WhatsApp mode enabled by default"));
  console.log(chalk.gray("Sessions will auto-start webhook and ngrok"));
});
configCmd.command("whatsapp-off").description("Disable WhatsApp mode by default").action(() => {
  const config = loadSMConfig();
  config.defaultWhatsApp = false;
  saveSMConfig(config);
  console.log(chalk.green("WhatsApp mode disabled by default"));
});
program.option("-w, --worktree", "Create isolated worktree for this instance").option("-W, --no-worktree", "Disable worktree (override default)").option("-r, --remote", "Enable remote mode (WhatsApp for all questions)").option("--no-remote", "Disable remote mode (override default)").option("-n, --notify-done", "Send WhatsApp notification when session ends").option("--no-notify-done", "Disable notification when session ends").option(
  "--whatsapp",
  "Enable WhatsApp mode (auto-start webhook + ngrok + notifications)"
).option("--no-whatsapp", "Disable WhatsApp mode (override default)").option("-s, --sandbox", "Enable sandbox mode (file/network restrictions)").option("-c, --chrome", "Enable Chrome automation").option("-a, --auto", "Automatically detect and apply best settings").option("-b, --branch <name>", "Specify branch name for worktree").option("-t, --task <desc>", "Task description for context").option("--claude-bin <path>", "Path to claude CLI (or use CLAUDE_BIN)").option("--no-context", "Disable StackMemory context integration").option("--no-trace", "Disable debug tracing (enabled by default)").option("--verbose-trace", "Enable verbose debug tracing with full details").helpOption("-h, --help", "Display help").allowUnknownOption(true).action(async (_options) => {
  const claudeSM = new ClaudeSM();
  const args = process.argv.slice(2);
  await claudeSM.run(args);
});
program.parse(process.argv);
//# sourceMappingURL=claude-sm.js.map
