#!/usr/bin/env node

// src/core/constants.ts
var VERSION = "0.4.180";
var APP_NAME = "ai-cli";
var CONFIG_DIR_NAME = ".aicli";
var CONFIG_FILE_NAME = "config.json";
var HISTORY_DIR_NAME = "history";
var PLUGINS_DIR_NAME = "plugins";
var SKILLS_DIR_NAME = "skills";
var CUSTOM_COMMANDS_DIR_NAME = "commands";
var CONTEXT_FILE_CANDIDATES = ["AICLI.md", "CLAUDE.md"];
var MEMORY_FILE_NAME = "memory.md";
var MEMORY_MAX_CHARS = 1e4;
var DEV_STATE_FILE_NAME = "dev-state.md";
var DEFAULT_MAX_TOKENS = 8192;
var DEFAULT_TEMPERATURE = 0.7;
var MAX_HISTORY_DAYS = 30;
var DEFAULT_MAX_TOOL_ROUNDS = 200;
var DEFAULT_MAX_TOOL_OUTPUT_CHARS_CAP = 5e5;
var MCP_TOOL_PREFIX = "mcp__";
var MCP_PROJECT_CONFIG_NAME = ".mcp.json";
var MCP_CONNECT_TIMEOUT = 3e4;
var MCP_CALL_TIMEOUT = 6e4;
var MCP_PROTOCOL_VERSION = "2024-11-05";
var PLAN_MODE_READONLY_TOOLS = /* @__PURE__ */ new Set([
  "read_file",
  "list_dir",
  "grep_files",
  "glob_files",
  "web_fetch",
  "google_search",
  "ask_user",
  // 允许：可向用户澄清需求
  "write_todos",
  // 允许：可输出任务列表作为实施计划
  "find_symbol",
  // C1 symbol index (read-only)
  "get_outline",
  // C1 symbol index (read-only)
  "find_references",
  // C1 symbol index (read-only)
  "search_code"
  // C2 semantic search (read-only)
]);
var PLAN_MODE_SYSTEM_ADDON = `# \u{1F50D} Plan Mode \u2014 Read-Only Planning Mode

You are currently in read-only planning (Plan) mode.

**Allowed tools**: read_file \xB7 list_dir \xB7 grep_files \xB7 glob_files \xB7 web_fetch \xB7 google_search \xB7 ask_user \xB7 write_todos
**Disabled tools**: bash \xB7 write_file \xB7 edit_file \xB7 run_interactive \xB7 save_last_response \xB7 save_memory and all MCP tools

**Your task**:
1. Use read-only tools to thoroughly analyze the codebase, file structure, and existing implementation
2. Use ask_user to clarify any ambiguous requirements with the user
3. Develop a detailed implementation plan (you may use write_todos to present the task list), including:
   - List of files to be modified or created
   - Specific changes for each file
   - Execution order and dependencies
   - Potential risks and considerations

**CRITICAL RULES**:
- Do NOT attempt to call bash, write_file, edit_file, or any disabled tool \u2014 they will fail silently.
- Do NOT write shell commands, SQL queries, or code in your text response as a substitute for tool calls \u2014 the user's system will misinterpret this as a pseudo-tool-call error.
- If the user asks you to run commands, test connections, or modify files, respond with: "This requires execution tools. Please type \`/plan execute\` to switch to execute mode, then I can perform these operations."
- Do NOT call write_todos repeatedly with the same content \u2014 call it once, then give a text response.
- Focus your analysis on reading files and producing actionable plans.

Once planning is complete, clearly inform the user: type \`/plan execute\` to begin executing the plan, or \`/plan exit\` to discard it.`;
var SUBAGENT_DEFAULT_MAX_ROUNDS = 15;
var SUBAGENT_MAX_ROUNDS_LIMIT = 30;
var SUBAGENT_ALLOWED_TOOLS = /* @__PURE__ */ new Set([
  "read_file",
  "write_file",
  "edit_file",
  "list_dir",
  "grep_files",
  "glob_files",
  "web_fetch",
  "google_search",
  "write_todos",
  "find_symbol",
  "get_outline",
  "find_references",
  "search_code"
]);
var CONTEXT_PRESSURE_THRESHOLD = 0.8;
var CONTEXT_WARNING_THRESHOLD = 0.6;
var TEST_TIMEOUT = 3e5;
var AGENTIC_BEHAVIOR_GUIDELINE = `# Important Behavioral Guidelines

**Respond appropriately to the user's intent \u2014 do NOT over-react**:
- For **greetings and casual chat** (e.g., "hello", "hi", "hey", "\u4F60\u597D", "what's up"): respond naturally with a friendly greeting. Do NOT use any tools. Do NOT explore directories, read files, or start any project work. Just chat.
- When the user asks you to "read", "understand", "review", "analyze", "examine", or "look at" files or a project, your task is only to **read and summarize**, then wait for the user's next instruction. Do not automatically start executing tasks described in the project.
- Only begin using write/execute tools when the user **explicitly requests** an action (e.g., "generate", "create", "modify", "run", "start", etc.).
- **Stop when the explicit task is done \u2014 do NOT autonomously test, verify, or run what you just created.** If the user asks "write/create/save file X", finish writing the file and STOP. Do not run it, do not test it, do not "verify it works" with bash/run_interactive. The user will run it themselves and tell you if anything is wrong. Only run/test when the user explicitly says "run", "test", "execute", "try it", "verify", "make sure it works", etc.
- **Do NOT retry the same failing command with variants.** If a command fails (exit code non-zero), report the failure to the user with a brief diagnosis and STOP. Do not loop through alternate shells, alternate quoting, alternate paths, or alternate Python invocations. The user can decide whether to retry.
- Project context files (CLAUDE.md, AICLI.md) provide background information about the project. They are NOT instructions to start working. Only use them as reference when the user asks a project-related question or task.
- If you are unsure about the user's intent, use the ask_user tool to confirm with the user, rather than assuming and executing on your own.
- **Do NOT abuse ask_user for redundant confirmations**: When the user has already given a clear, explicit instruction (e.g., "write lesson 142", "generate file X", "create the report"), execute it immediately. Do NOT ask "are you sure?" or request details that can be found in project documents. Repeatedly asking the user to confirm wastes their time and is extremely frustrating. Only use ask_user when critical information is genuinely missing and cannot be inferred from context files.`;
function buildUserIdentityPrompt(profile) {
  const lines = [];
  const displayName = profile.nickname || profile.name;
  if (displayName) {
    lines.push(`The user's name is **${profile.name || displayName}**${profile.nickname && profile.name ? ` (prefers to be called **${profile.nickname}**)` : ""}.`);
  }
  if (profile.role) {
    lines.push(`Role: ${profile.role}.`);
  }
  if (profile.bio) {
    lines.push(`About: ${profile.bio}`);
  }
  if (profile.interests && profile.interests.length > 0) {
    lines.push(`Interests & expertise: ${profile.interests.join(", ")}.`);
  }
  if (profile.locale) {
    lines.push(`Preferred language: ${profile.locale}. Please respond in this language unless the user explicitly uses another language.`);
  }
  if (profile.extra) {
    lines.push(`
${profile.extra}`);
  }
  if (lines.length === 0) return null;
  return `# Who You're Talking To

${lines.join("\n")}

Address the user personally and adapt your communication style to their background. This identity persists across all conversations and all AI providers.`;
}
var AUTHOR = "Jin Zhengdong";
var AUTHOR_EMAIL = "zhengdong.jin@gmail.com";
var DESCRIPTION = "Cross-platform REPL-style AI conversation tool with multi-provider and agentic tool calling support";
var REPO_URL = "https://github.com/jinzhengdong/ai-cli";

export {
  VERSION,
  APP_NAME,
  CONFIG_DIR_NAME,
  CONFIG_FILE_NAME,
  HISTORY_DIR_NAME,
  PLUGINS_DIR_NAME,
  SKILLS_DIR_NAME,
  CUSTOM_COMMANDS_DIR_NAME,
  CONTEXT_FILE_CANDIDATES,
  MEMORY_FILE_NAME,
  MEMORY_MAX_CHARS,
  DEV_STATE_FILE_NAME,
  DEFAULT_MAX_TOKENS,
  DEFAULT_TEMPERATURE,
  MAX_HISTORY_DAYS,
  DEFAULT_MAX_TOOL_ROUNDS,
  DEFAULT_MAX_TOOL_OUTPUT_CHARS_CAP,
  MCP_TOOL_PREFIX,
  MCP_PROJECT_CONFIG_NAME,
  MCP_CONNECT_TIMEOUT,
  MCP_CALL_TIMEOUT,
  MCP_PROTOCOL_VERSION,
  PLAN_MODE_READONLY_TOOLS,
  PLAN_MODE_SYSTEM_ADDON,
  SUBAGENT_DEFAULT_MAX_ROUNDS,
  SUBAGENT_MAX_ROUNDS_LIMIT,
  SUBAGENT_ALLOWED_TOOLS,
  CONTEXT_PRESSURE_THRESHOLD,
  CONTEXT_WARNING_THRESHOLD,
  TEST_TIMEOUT,
  AGENTIC_BEHAVIOR_GUIDELINE,
  buildUserIdentityPrompt,
  AUTHOR,
  AUTHOR_EMAIL,
  DESCRIPTION,
  REPO_URL
};
