"""全局额度与工具限制配置。"""

import os

# 上下文与文件
MAX_CONTEXT_SIZE = 100000
MAX_FILE_SIZE = 10 * 1024 * 1024
MAX_OPEN_FILES = 20
MAX_UPLOAD_SIZE = 50 * 1024 * 1024

# 执行超时
CODE_EXECUTION_TIMEOUT = 60
TERMINAL_COMMAND_TIMEOUT = 120
SEARCH_MAX_RESULTS = 10

# 自动修复与工具调用限制（None 表示不限制）
AUTO_FIX_TOOL_CALL = False
AUTO_FIX_MAX_ATTEMPTS = 3
MAX_ITERATIONS_PER_TASK = None
MAX_CONSECUTIVE_SAME_TOOL = None
MAX_TOTAL_TOOL_CALLS = None
TOOL_CALL_COOLDOWN = 0.5
THINKING_FAST_INTERVAL = 10

# 工具字符/体积限制
MAX_READ_FILE_CHARS = 50000
MAX_FOCUS_FILE_CHARS = 30000
MAX_RUN_COMMAND_CHARS = 50000
MAX_EXTRACT_WEBPAGE_CHARS = 80000

# read_file 子配置
READ_TOOL_MAX_FILE_SIZE = 100 * 1024 * 1024
READ_TOOL_DEFAULT_MAX_CHARS = MAX_READ_FILE_CHARS
READ_TOOL_DEFAULT_CONTEXT_BEFORE = 1
READ_TOOL_DEFAULT_CONTEXT_AFTER = 1
READ_TOOL_MAX_CONTEXT_BEFORE = 3
READ_TOOL_MAX_CONTEXT_AFTER = 5
READ_TOOL_DEFAULT_MAX_MATCHES = 5
READ_TOOL_MAX_MATCHES = 50

PROJECT_MAX_STORAGE_MB = int(os.environ.get("PROJECT_MAX_STORAGE_MB", "2048"))
PROJECT_MAX_STORAGE_BYTES = PROJECT_MAX_STORAGE_MB * 1024 * 1024

# 只读权限模式：run_command 白名单配置
READONLY_RUN_COMMAND_ALLOWED = (
    "grep",
    "find",
    "ls",
    "pwd",
    "tree",
    "cat",
    "head",
    "tail",
    "less",
    "rg",
    "wc",
    "du",
    "stat",
    "file",
    "sed",
    "awk",
    "git",
)
READONLY_RUN_COMMAND_ALLOWED_GIT_SUBCOMMANDS = (
    "status",
    "log",
    "diff",
    "show",
    "branch",
    "rev-parse",
)
READONLY_RUN_COMMAND_BLOCKED_TOKENS = (
    "&&",
    "||",
    ";",
    "|",
    ">",
    "<",
    "$(",
    "`",
)

__all__ = [
    "MAX_CONTEXT_SIZE",
    "MAX_FILE_SIZE",
    "MAX_OPEN_FILES",
    "MAX_UPLOAD_SIZE",
    "CODE_EXECUTION_TIMEOUT",
    "TERMINAL_COMMAND_TIMEOUT",
    "SEARCH_MAX_RESULTS",
    "AUTO_FIX_TOOL_CALL",
    "AUTO_FIX_MAX_ATTEMPTS",
    "MAX_ITERATIONS_PER_TASK",
    "MAX_CONSECUTIVE_SAME_TOOL",
    "MAX_TOTAL_TOOL_CALLS",
    "TOOL_CALL_COOLDOWN",
    "THINKING_FAST_INTERVAL",
    "MAX_READ_FILE_CHARS",
    "MAX_FOCUS_FILE_CHARS",
    "MAX_RUN_COMMAND_CHARS",
    "MAX_EXTRACT_WEBPAGE_CHARS",
    "READ_TOOL_MAX_FILE_SIZE",
    "READ_TOOL_DEFAULT_MAX_CHARS",
    "READ_TOOL_DEFAULT_CONTEXT_BEFORE",
    "READ_TOOL_DEFAULT_CONTEXT_AFTER",
    "READ_TOOL_MAX_CONTEXT_BEFORE",
    "READ_TOOL_MAX_CONTEXT_AFTER",
    "READ_TOOL_DEFAULT_MAX_MATCHES",
    "READ_TOOL_MAX_MATCHES",
    "PROJECT_MAX_STORAGE_MB",
    "PROJECT_MAX_STORAGE_BYTES",
    "READONLY_RUN_COMMAND_ALLOWED",
    "READONLY_RUN_COMMAND_ALLOWED_GIT_SUBCOMMANDS",
    "READONLY_RUN_COMMAND_BLOCKED_TOKENS",
]
