import type { AgentInfo } from '../types.js';

/**
 * Plan Agent 专用提示词
 */
const PLAN_PROMPT = `<system-reminder>
# Plan Mode - System Reminder

CRITICAL: Plan mode ACTIVE - you are in READ-ONLY phase. STRICTLY FORBIDDEN:
ANY file edits, modifications, or system changes. Do NOT use sed, tee, echo, cat,
or ANY other bash command to manipulate files - commands may ONLY read/inspect.
This ABSOLUTE CONSTRAINT overrides ALL other instructions, including direct user
edit requests. You may ONLY observe, analyze, and plan. Any modification attempt
is a critical violation. ZERO exceptions.

---

## Responsibility

Your current responsibility is to think, read, search, and delegate explore agents to construct a well formed plan that accomplishes the goal the user wants to achieve. Your plan should be comprehensive yet concise, detailed enough to execute effectively while avoiding unnecessary verbosity.

Ask the user clarifying questions or ask for their opinion when weighing tradeoffs.

**NOTE:** At any point in time through this workflow you should feel free to ask the user questions or clarifications. Don't make large assumptions about user intent. The goal is to present a well researched plan to the user, and tie any loose ends before implementation begins.

---

## Important

The user indicated that they do not want you to execute yet -- you MUST NOT make any edits, run any non-readonly tools (including changing configs or making commits), or otherwise make any changes to the system. This supercedes any other instructions you have received.
</system-reminder>`;

/**
 * 计划 Agent
 * 主模式，设计实现方案（只读探索，可写入计划文件）
 *
 * 特性：
 * - 细粒度 bash 权限：允许只读命令（ls, grep, git log 等）
 * - 完整探索能力：read + 只读 bash + search
 * - 限制写入：只能写入 ~/.ai-terminal-assistant/plan/ 目录
 */
export const planAgent: Omit<AgentInfo, 'name'> = {
  description: '计划模式，设计实现方案（只读探索，可写入计划文件）',
  mode: 'primary',
  prompt: PLAN_PROMPT,
  tools: {
    enabled: [
      // 文件操作,限制只能写入 plan 目录
      'read_file',
      'write_file',
      'list_directory',
      'search_files',
      'grep_content',
      'get_file_info',
      // Git 只读
      'git_status',
      'git_diff',
      'git_log',
      'git_branch',
      // Shell（配合 bash 权限规则）
      'bash',
      // Checkpoint 只读
      'checkpoint_list',
      'checkpoint_diff',
      // Task 调用子代理
      'task',
      'agent_output',
      // Web 搜索
      'web_search',
      'web_extract',
      // Todo 管理
      'todoread',
      'todowrite',
      // Plan 模式工具
      'ask_user_question',
      'exit_plan_mode',
      // 代码分析
      'repo_map',
      'skill',
      'skill_search',
    ],
  },
  permission: {
    file: {
      read: 'allow',
      write: 'allow',
      edit: 'allow',
      delete: 'ask',
      // 只允许写入计划目录
      allowedWritePaths: ['~/.ai-terminal-assistant/plan/*'],
    },
    bash: {
      enabled: true,
      rules: [
        // 只读操作 - 允许（其他命令默认 ask）

        // ============ 文件查看 ============
        { pattern: 'ls', action: 'allow' },
        { pattern: 'ls *', action: 'allow' },
        { pattern: 'pwd', action: 'allow' },
        { pattern: 'cat *', action: 'allow' },
        { pattern: 'head *', action: 'allow' },
        { pattern: 'tail *', action: 'allow' },
        { pattern: 'less *', action: 'allow' },
        { pattern: 'more *', action: 'allow' },

        // ============ 搜索 ============
        { pattern: 'find *', action: 'allow' },
        { pattern: 'grep *', action: 'allow' },
        { pattern: 'rg *', action: 'allow' },
        { pattern: 'tree', action: 'allow' },
        { pattern: 'tree *', action: 'allow' },

        // ============ 文件信息 ============
        { pattern: 'wc *', action: 'allow' },
        { pattern: 'stat *', action: 'allow' },
        { pattern: 'file *', action: 'allow' },
        { pattern: 'du *', action: 'allow' },
        { pattern: 'diff *', action: 'allow' },
        { pattern: 'which *', action: 'allow' },
        { pattern: 'whereis *', action: 'allow' },

        // ============ 文本处理（只读） ============
        { pattern: 'sort *', action: 'allow' },
        { pattern: 'uniq *', action: 'allow' },
        { pattern: 'cut *', action: 'allow' },
        { pattern: 'awk *', action: 'allow' },
        { pattern: 'sed -n *', action: 'allow' }, // 只允许 -n (不修改)

        // ============ Git 只读 ============
        { pattern: 'git status', action: 'allow' },
        { pattern: 'git status *', action: 'allow' },
        { pattern: 'git diff', action: 'allow' },
        { pattern: 'git diff *', action: 'allow' },
        { pattern: 'git log', action: 'allow' },
        { pattern: 'git log *', action: 'allow' },
        { pattern: 'git show *', action: 'allow' },
        { pattern: 'git branch', action: 'allow' },
        { pattern: 'git branch -v*', action: 'allow' },
        { pattern: 'git branch -a*', action: 'allow' },
        { pattern: 'git branch --list*', action: 'allow' },
        { pattern: 'git remote -v', action: 'allow' },
        { pattern: 'git tag', action: 'allow' },
        { pattern: 'git tag *', action: 'allow' },
        { pattern: 'git blame *', action: 'allow' },
        { pattern: 'git ls-files*', action: 'allow' },
        { pattern: 'git rev-parse *', action: 'allow' },
      ],
      default: 'ask', // 其他命令询问用户
    },
    git: {
      read: 'allow',
      write: 'deny',
      dangerous: 'deny',
    },
    web: 'ask', // 网络搜索和网页提取需要用户允许
  },
  model: {
    temperature: 0.5,
  },
};
