// Force strict mode and setup for ESM
"use strict";
import "./chunk-PSIHICBU.js";
import "./chunk-24YKA2DA.js";
import "./chunk-O4PICXES.js";
import "./chunk-TW522KN6.js";
import "./chunk-TI4GXJKO.js";
import "./chunk-AKBFRR6J.js";
import "./chunk-MLZQVCF3.js";
import "./chunk-EMVEDSVZ.js";
import "./chunk-EY6BDW7Y.js";
import "./chunk-HAQCNXSG.js";
import "./chunk-77WXWU44.js";
import "./chunk-GVWPJCXU.js";
import "./chunk-G5EEAVVW.js";
import "./chunk-J5VCSWPA.js";
import "./chunk-UWCTAVOD.js";
import "./chunk-W57YDFU5.js";
import "./chunk-OFEVLU4C.js";
import "./chunk-NQ3E7YLD.js";
import "./chunk-ODPVJ6JJ.js";
import "./chunk-UQRYJQBE.js";
import {
  ToolDisplayNames,
  ToolNames
} from "./chunk-6RQTH7UQ.js";
import {
  BaseDeclarativeTool,
  BaseToolInvocation
} from "./chunk-R2B65CAN.js";
import "./chunk-7YJIR2FX.js";
import "./chunk-OIL7KDWV.js";
import "./chunk-U2K6HDUJ.js";
import "./chunk-6NUSWV4M.js";
import "./chunk-HCSJIOLR.js";
import "./chunk-SZOEIL6S.js";
import "./chunk-5IFG2VC4.js";
import {
  createDebugLogger
} from "./chunk-ACBGEKB7.js";
import "./chunk-ZERZSAZL.js";
import "./chunk-QN5NZ3UQ.js";
import "./chunk-BR4QREVK.js";
import "./chunk-QWSRH265.js";
import {
  init_esbuild_shims
} from "./chunk-A4BMJM77.js";
import {
  __name
} from "./chunk-J2S4EL5Y.js";

// packages/core/src/tools/exitPlanMode.ts
init_esbuild_shims();
var debugLogger = createDebugLogger("EXIT_PLAN_MODE");
var exitPlanModeToolDescription = `Use this tool when you are in plan mode and have finished presenting your plan and are ready to code. This will prompt the user to exit plan mode.

## When to Use This Tool
IMPORTANT: Only use this tool when the task requires planning the implementation steps of a task that requires writing code. For research tasks where you're gathering information, searching files, reading files or in general trying to understand the codebase - do NOT use this tool.

## Before Using This Tool
Ensure your plan is complete and unambiguous:
- If you have unresolved questions about requirements or approach, use AskUserQuestion first (in earlier phases)
- Once your plan is finalized, use THIS tool to request approval

**Important:** Do NOT use AskUserQuestion to ask "Is this plan okay?" or "Should I proceed?" - that's exactly what THIS tool does. ExitPlanMode inherently requests user approval of your plan.

## Examples
1. Initial task: "Search for and understand the implementation of vim mode in the codebase" - Do not use the exit plan mode tool because you are not planning the implementation steps of a task.
2. Initial task: "Help me implement yank mode for vim" - Use the exit plan mode tool after you have finished planning the implementation steps of the task.
3. Initial task: "Add a new feature to handle user authentication" - If unsure about auth method (OAuth, JWT, etc.), use AskUserQuestion first, then use exit plan mode tool after clarifying the approach.
`;
var exitPlanModeToolSchemaData = {
  name: "exit_plan_mode",
  description: exitPlanModeToolDescription,
  parametersJsonSchema: {
    type: "object",
    properties: {
      plan: {
        type: "string",
        description: "The plan you came up with, that you want to run by the user for approval. Supports markdown. The plan should be pretty concise."
      }
    },
    required: ["plan"],
    additionalProperties: false,
    $schema: "http://json-schema.org/draft-07/schema#"
  }
};
var ExitPlanModeToolInvocation = class extends BaseToolInvocation {
  constructor(config, params) {
    super(params);
    this.config = config;
  }
  static {
    __name(this, "ExitPlanModeToolInvocation");
  }
  wasApproved = false;
  getDescription() {
    return "Plan:";
  }
  /**
   * Plan mode exit always requires user confirmation.
   */
  async getDefaultPermission() {
    return "ask";
  }
  async getConfirmationDetails(_abortSignal) {
    const prePlanMode = this.config.getPrePlanMode();
    const details = {
      type: "plan",
      title: "Would you like to proceed?",
      plan: this.params.plan,
      prePlanMode,
      onConfirm: /* @__PURE__ */ __name(async (outcome) => {
        switch (outcome) {
          case "restore_previous" /* RestorePrevious */:
            this.wasApproved = true;
            this.setApprovalModeSafely(prePlanMode);
            break;
          case "proceed_always" /* ProceedAlways */:
            this.wasApproved = true;
            this.setApprovalModeSafely("auto-edit" /* AUTO_EDIT */);
            break;
          case "proceed_once" /* ProceedOnce */:
            this.wasApproved = true;
            this.setApprovalModeSafely("default" /* DEFAULT */);
            break;
          case "cancel" /* Cancel */:
            this.wasApproved = false;
            this.setApprovalModeSafely("plan" /* PLAN */);
            break;
          default:
            this.wasApproved = true;
            this.setApprovalModeSafely("default" /* DEFAULT */);
            break;
        }
      }, "onConfirm")
    };
    return details;
  }
  setApprovalModeSafely(mode) {
    try {
      this.config.setApprovalMode(mode);
    } catch (error) {
      const errorMessage = error instanceof Error ? error.message : String(error);
      debugLogger.error(
        `[ExitPlanModeTool] Failed to set approval mode to "${mode}": ${errorMessage}`
      );
    }
  }
  async execute(_signal) {
    const { plan } = this.params;
    try {
      const isYolo = this.config.getApprovalMode() === "yolo" /* YOLO */;
      const effectivelyApproved = this.wasApproved || isYolo;
      if (!effectivelyApproved) {
        const rejectionMessage = "Plan execution was not approved. Remaining in plan mode.";
        return {
          llmContent: rejectionMessage,
          returnDisplay: rejectionMessage
        };
      }
      try {
        this.config.savePlan(plan);
      } catch (error) {
        debugLogger.warn(
          `[ExitPlanModeTool] Failed to save plan to disk: ${error instanceof Error ? error.message : String(error)}`
        );
      }
      const llmMessage = `User has approved your plan. You can now start coding. Start with updating your todo list if applicable.`;
      const displayMessage = "User approved the plan.";
      return {
        llmContent: llmMessage,
        returnDisplay: {
          type: "plan_summary",
          message: displayMessage,
          plan
        }
      };
    } catch (error) {
      const errorMessage = error instanceof Error ? error.message : String(error);
      debugLogger.error(
        `[ExitPlanModeTool] Error executing exit_plan_mode: ${errorMessage}`
      );
      const errorLlmContent = `Failed to present plan: ${errorMessage}`;
      return {
        llmContent: errorLlmContent,
        returnDisplay: `Error presenting plan: ${errorMessage}`
      };
    }
  }
};
var ExitPlanModeTool = class _ExitPlanModeTool extends BaseDeclarativeTool {
  constructor(config) {
    super(
      _ExitPlanModeTool.Name,
      ToolDisplayNames.EXIT_PLAN_MODE,
      exitPlanModeToolDescription,
      "think" /* Think */,
      exitPlanModeToolSchemaData.parametersJsonSchema,
      true,
      // isOutputMarkdown
      false,
      // canUpdateOutput
      true,
      // shouldDefer — only used when leaving plan mode
      false,
      // alwaysLoad
      "plan mode exit approve"
    );
    this.config = config;
  }
  static {
    __name(this, "ExitPlanModeTool");
  }
  static Name = ToolNames.EXIT_PLAN_MODE;
  validateToolParams(params) {
    if (!params.plan || typeof params.plan !== "string" || params.plan.trim() === "") {
      return 'Parameter "plan" must be a non-empty string.';
    }
    return null;
  }
  createInvocation(params) {
    return new ExitPlanModeToolInvocation(this.config, params);
  }
};
export {
  ExitPlanModeTool
};
/**
 * @license
 * Copyright 2025 Qwen
 * SPDX-License-Identifier: Apache-2.0
 */
