/**
 * PlanMode tools — EnterPlanMode and ExitPlanMode.
 *
 * Plan mode restricts the agent to read-only tools (no Write, Edit,
 * MultiEdit, or Bash) and is used for planning before implementation.
 *
 * Exports two tool definitions and two executors, since this module
 * provides two logical tools.
 */

export const enterDefinition = {
  name: 'EnterPlanMode',
  description: 'Enter plan mode to explore the codebase and design an implementation approach before writing code. In plan mode, only read-only tools are available.',
  input_schema: {
    type: 'object',
    properties: {},
    required: []
  }
};

export const exitDefinition = {
  name: 'ExitPlanMode',
  description: 'Exit plan mode after the plan is ready for user approval. This signals that you have finished planning and are ready to implement.',
  input_schema: {
    type: 'object',
    properties: {},
    required: []
  }
};

export async function executeEnter(input, context) {
  if (context.planMode) {
    return { content: 'Already in plan mode.', is_error: false };
  }

  // Set plan mode in context
  if (context.setPlanMode && typeof context.setPlanMode === 'function') {
    context.setPlanMode(true);
  } else {
    context.planMode = true;
  }

  return {
    content: 'Entered plan mode. Write/Edit/Bash tools are now disabled. Use read-only tools to explore the codebase and design your approach.',
    is_error: false
  };
}

export async function executeExit(input, context) {
  if (!context.planMode) {
    return { content: 'Not currently in plan mode.', is_error: false };
  }

  if (context.setPlanMode && typeof context.setPlanMode === 'function') {
    context.setPlanMode(false);
  } else {
    context.planMode = false;
  }

  return {
    content: 'Exited plan mode. All tools are now available. Ready to implement.',
    is_error: false
  };
}
