illusion-code 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (214) hide show
  1. illusion/__init__.py +24 -0
  2. illusion/__main__.py +15 -0
  3. illusion/_frontend/dist/index.mjs +39208 -0
  4. illusion/_frontend/package.json +27 -0
  5. illusion/_frontend/src/App.tsx +624 -0
  6. illusion/_frontend/src/components/CommandPicker.tsx +98 -0
  7. illusion/_frontend/src/components/Composer.tsx +55 -0
  8. illusion/_frontend/src/components/ComposerController.tsx +128 -0
  9. illusion/_frontend/src/components/ConversationView.tsx +750 -0
  10. illusion/_frontend/src/components/Footer.tsx +25 -0
  11. illusion/_frontend/src/components/MarkdownContent.tsx +537 -0
  12. illusion/_frontend/src/components/MarkdownTable.tsx +245 -0
  13. illusion/_frontend/src/components/ModalHost.tsx +425 -0
  14. illusion/_frontend/src/components/MultilineTextInput.tsx +250 -0
  15. illusion/_frontend/src/components/PromptInput.tsx +64 -0
  16. illusion/_frontend/src/components/SelectModal.tsx +78 -0
  17. illusion/_frontend/src/components/SidePanel.tsx +175 -0
  18. illusion/_frontend/src/components/Spinner.tsx +77 -0
  19. illusion/_frontend/src/components/StatusBar.tsx +142 -0
  20. illusion/_frontend/src/components/SwarmPanel.tsx +141 -0
  21. illusion/_frontend/src/components/TodoPanel.tsx +126 -0
  22. illusion/_frontend/src/components/ToolCallDisplay.tsx +202 -0
  23. illusion/_frontend/src/components/TranscriptPane.tsx +79 -0
  24. illusion/_frontend/src/components/WelcomeBanner.tsx +37 -0
  25. illusion/_frontend/src/hooks/useBackendSession.ts +468 -0
  26. illusion/_frontend/src/hooks/useTerminalSize.ts +9 -0
  27. illusion/_frontend/src/i18n.ts +78 -0
  28. illusion/_frontend/src/index.tsx +42 -0
  29. illusion/_frontend/src/theme/ThemeContext.tsx +19 -0
  30. illusion/_frontend/src/theme/builtinThemes.ts +89 -0
  31. illusion/_frontend/src/types.ts +110 -0
  32. illusion/_frontend/src/utils/markdown.ts +33 -0
  33. illusion/_frontend/src/utils/thinking.ts +191 -0
  34. illusion/_frontend/tsconfig.json +13 -0
  35. illusion/_web_dist/assets/index-BseIw-ik.css +10 -0
  36. illusion/_web_dist/assets/index-C_0ZWMuW.js +82 -0
  37. illusion/_web_dist/index.html +16 -0
  38. illusion/api/__init__.py +36 -0
  39. illusion/api/client.py +568 -0
  40. illusion/api/codex_client.py +563 -0
  41. illusion/api/compat.py +138 -0
  42. illusion/api/effort.py +128 -0
  43. illusion/api/errors.py +57 -0
  44. illusion/api/openai_client.py +819 -0
  45. illusion/api/provider.py +148 -0
  46. illusion/api/registry.py +479 -0
  47. illusion/api/usage.py +45 -0
  48. illusion/auth/__init__.py +50 -0
  49. illusion/auth/copilot.py +419 -0
  50. illusion/auth/external.py +612 -0
  51. illusion/auth/flows.py +58 -0
  52. illusion/auth/manager.py +214 -0
  53. illusion/auth/storage.py +372 -0
  54. illusion/bridge/__init__.py +38 -0
  55. illusion/bridge/manager.py +190 -0
  56. illusion/bridge/session_runner.py +84 -0
  57. illusion/bridge/types.py +113 -0
  58. illusion/bridge/work_secret.py +131 -0
  59. illusion/cli.py +1228 -0
  60. illusion/commands/__init__.py +32 -0
  61. illusion/commands/registry.py +1934 -0
  62. illusion/config/__init__.py +39 -0
  63. illusion/config/i18n.py +522 -0
  64. illusion/config/paths.py +259 -0
  65. illusion/config/settings.py +564 -0
  66. illusion/coordinator/__init__.py +41 -0
  67. illusion/coordinator/agent_definitions.py +1093 -0
  68. illusion/coordinator/coordinator_mode.py +127 -0
  69. illusion/engine/__init__.py +95 -0
  70. illusion/engine/cost_tracker.py +55 -0
  71. illusion/engine/messages.py +369 -0
  72. illusion/engine/query.py +632 -0
  73. illusion/engine/query_engine.py +343 -0
  74. illusion/engine/stream_events.py +169 -0
  75. illusion/hooks/__init__.py +67 -0
  76. illusion/hooks/events.py +43 -0
  77. illusion/hooks/executor.py +397 -0
  78. illusion/hooks/hot_reload.py +74 -0
  79. illusion/hooks/loader.py +133 -0
  80. illusion/hooks/schemas.py +121 -0
  81. illusion/hooks/types.py +86 -0
  82. illusion/mcp/__init__.py +104 -0
  83. illusion/mcp/client.py +377 -0
  84. illusion/mcp/config.py +140 -0
  85. illusion/mcp/types.py +175 -0
  86. illusion/memory/__init__.py +36 -0
  87. illusion/memory/manager.py +94 -0
  88. illusion/memory/memdir.py +58 -0
  89. illusion/memory/paths.py +57 -0
  90. illusion/memory/scan.py +120 -0
  91. illusion/memory/search.py +83 -0
  92. illusion/memory/types.py +43 -0
  93. illusion/output_styles/__init__.py +15 -0
  94. illusion/output_styles/loader.py +64 -0
  95. illusion/permissions/__init__.py +39 -0
  96. illusion/permissions/checker.py +174 -0
  97. illusion/permissions/modes.py +38 -0
  98. illusion/platforms.py +148 -0
  99. illusion/plugins/__init__.py +71 -0
  100. illusion/plugins/bundled/__init__.py +0 -0
  101. illusion/plugins/installer.py +59 -0
  102. illusion/plugins/loader.py +301 -0
  103. illusion/plugins/schemas.py +51 -0
  104. illusion/plugins/types.py +56 -0
  105. illusion/prompts/__init__.py +29 -0
  106. illusion/prompts/claudemd.py +74 -0
  107. illusion/prompts/context.py +187 -0
  108. illusion/prompts/environment.py +189 -0
  109. illusion/prompts/system_prompt.py +155 -0
  110. illusion/py.typed +0 -0
  111. illusion/sandbox/__init__.py +29 -0
  112. illusion/sandbox/adapter.py +174 -0
  113. illusion/services/__init__.py +59 -0
  114. illusion/services/compact/__init__.py +1015 -0
  115. illusion/services/cron.py +338 -0
  116. illusion/services/cron_scheduler.py +715 -0
  117. illusion/services/file_history.py +258 -0
  118. illusion/services/lsp/__init__.py +455 -0
  119. illusion/services/session_storage.py +237 -0
  120. illusion/services/token_estimation.py +72 -0
  121. illusion/skills/__init__.py +60 -0
  122. illusion/skills/bundled/__init__.py +110 -0
  123. illusion/skills/bundled/content/batch.md +86 -0
  124. illusion/skills/bundled/content/coding-guidelines.md +70 -0
  125. illusion/skills/bundled/content/debug.md +38 -0
  126. illusion/skills/bundled/content/loop.md +82 -0
  127. illusion/skills/bundled/content/remember.md +105 -0
  128. illusion/skills/bundled/content/simplify.md +53 -0
  129. illusion/skills/bundled/content/skillify.md +113 -0
  130. illusion/skills/bundled/content/stuck.md +54 -0
  131. illusion/skills/bundled/content/update-config.md +329 -0
  132. illusion/skills/bundled/content/verify.md +74 -0
  133. illusion/skills/loader.py +219 -0
  134. illusion/skills/registry.py +40 -0
  135. illusion/skills/types.py +24 -0
  136. illusion/state/__init__.py +18 -0
  137. illusion/state/app_state.py +67 -0
  138. illusion/state/store.py +93 -0
  139. illusion/swarm/__init__.py +71 -0
  140. illusion/swarm/agent_executor.py +857 -0
  141. illusion/swarm/in_process.py +259 -0
  142. illusion/swarm/subprocess_backend.py +136 -0
  143. illusion/swarm/team_helpers.py +123 -0
  144. illusion/swarm/types.py +159 -0
  145. illusion/swarm/worktree.py +347 -0
  146. illusion/tasks/__init__.py +33 -0
  147. illusion/tasks/local_agent_task.py +42 -0
  148. illusion/tasks/local_shell_task.py +27 -0
  149. illusion/tasks/manager.py +377 -0
  150. illusion/tasks/stop_task.py +21 -0
  151. illusion/tasks/types.py +88 -0
  152. illusion/tools/__init__.py +126 -0
  153. illusion/tools/agent_tool.py +388 -0
  154. illusion/tools/ask_user_question_tool.py +186 -0
  155. illusion/tools/base.py +149 -0
  156. illusion/tools/bash_tool.py +413 -0
  157. illusion/tools/config_tool.py +90 -0
  158. illusion/tools/cron_tool.py +473 -0
  159. illusion/tools/enter_plan_mode_tool.py +147 -0
  160. illusion/tools/enter_worktree_tool.py +188 -0
  161. illusion/tools/exit_plan_mode_tool.py +69 -0
  162. illusion/tools/exit_worktree_tool.py +225 -0
  163. illusion/tools/file_edit_tool.py +283 -0
  164. illusion/tools/file_read_tool.py +294 -0
  165. illusion/tools/file_write_tool.py +184 -0
  166. illusion/tools/glob_tool.py +165 -0
  167. illusion/tools/grep_tool.py +190 -0
  168. illusion/tools/list_mcp_resources_tool.py +80 -0
  169. illusion/tools/lsp_tool.py +333 -0
  170. illusion/tools/mcp_auth_tool.py +100 -0
  171. illusion/tools/mcp_tool.py +75 -0
  172. illusion/tools/notebook_edit_tool.py +242 -0
  173. illusion/tools/powershell_tool.py +334 -0
  174. illusion/tools/read_mcp_resource_tool.py +63 -0
  175. illusion/tools/repl_tool.py +100 -0
  176. illusion/tools/send_message_tool.py +112 -0
  177. illusion/tools/shell_common.py +187 -0
  178. illusion/tools/skill_tool.py +86 -0
  179. illusion/tools/sleep_tool.py +62 -0
  180. illusion/tools/structured_output_tool.py +58 -0
  181. illusion/tools/task_create_tool.py +98 -0
  182. illusion/tools/task_get_tool.py +94 -0
  183. illusion/tools/task_list_tool.py +94 -0
  184. illusion/tools/task_output_tool.py +55 -0
  185. illusion/tools/task_stop_tool.py +52 -0
  186. illusion/tools/task_update_tool.py +224 -0
  187. illusion/tools/team_create_tool.py +236 -0
  188. illusion/tools/team_delete_tool.py +104 -0
  189. illusion/tools/todo_write_tool.py +198 -0
  190. illusion/tools/tool_search_tool.py +156 -0
  191. illusion/tools/web_fetch_tool.py +264 -0
  192. illusion/tools/web_search_tool.py +186 -0
  193. illusion/ui/__init__.py +23 -0
  194. illusion/ui/app.py +258 -0
  195. illusion/ui/backend_host.py +1180 -0
  196. illusion/ui/input.py +86 -0
  197. illusion/ui/output.py +363 -0
  198. illusion/ui/permission_dialog.py +47 -0
  199. illusion/ui/permission_store.py +99 -0
  200. illusion/ui/protocol.py +384 -0
  201. illusion/ui/react_launcher.py +280 -0
  202. illusion/ui/runtime.py +787 -0
  203. illusion/ui/textual_app.py +603 -0
  204. illusion/ui/web/__init__.py +10 -0
  205. illusion/ui/web/server.py +87 -0
  206. illusion/ui/web/ws_host.py +1197 -0
  207. illusion/utils/__init__.py +0 -0
  208. illusion/utils/ripgrep.py +299 -0
  209. illusion/utils/shell.py +248 -0
  210. illusion_code-0.1.0.dist-info/METADATA +1159 -0
  211. illusion_code-0.1.0.dist-info/RECORD +214 -0
  212. illusion_code-0.1.0.dist-info/WHEEL +4 -0
  213. illusion_code-0.1.0.dist-info/entry_points.txt +2 -0
  214. illusion_code-0.1.0.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,39 @@
1
+ """
2
+ 配置系统模块
3
+ ============
4
+
5
+ 本模块提供 IllusionCode 的配置管理、路径解析和 API 密钥处理功能。
6
+
7
+ 主要组件:
8
+ - Settings: 应用设置
9
+ - EnvConfig: 环境配置
10
+ - load_settings/save_settings: 设置加载/保存
11
+ - get_config_dir/get_data_dir/get_logs_dir: 目录路径获取
12
+
13
+ 使用示例:
14
+ >>> from illusion.config import load_settings, get_config_dir
15
+ >>> settings = load_settings()
16
+ >>> config_path = get_config_dir()
17
+ """
18
+
19
+ from illusion.config.paths import (
20
+ get_config_dir,
21
+ get_config_file_path,
22
+ get_data_dir,
23
+ get_logs_dir,
24
+ )
25
+ from illusion.config.settings import (
26
+ Settings,
27
+ load_settings,
28
+ save_settings,
29
+ )
30
+
31
+ __all__ = [
32
+ "Settings",
33
+ "get_config_dir",
34
+ "get_config_file_path",
35
+ "get_data_dir",
36
+ "get_logs_dir",
37
+ "load_settings",
38
+ "save_settings",
39
+ ]
@@ -0,0 +1,522 @@
1
+ """
2
+ 国际化消息模块
3
+ ==============
4
+
5
+ 本模块提供 CLI 输出的国际化(i18n)支持。
6
+ 根据 settings.json 中的 ui_language 字段返回对应语言的文本。
7
+
8
+ 使用示例:
9
+ >>> from illusion.config.i18n import t
10
+ >>> print(t("mcp_none"))
11
+ """
12
+
13
+ from __future__ import annotations
14
+
15
+ import re
16
+ from typing import Any
17
+
18
+ # i18n 消息表
19
+ MESSAGES: dict[str, dict[str, str]] = {
20
+ # --- auth ---
21
+ "select_provider": {"zh-CN": "选择提供商:", "en-US": "Select a provider:"},
22
+ "custom_provider": {"zh-CN": "自定义提供商", "en-US": "Custom provider"},
23
+ "anthropic_label": {"zh-CN": "Anthropic (Claude API)", "en-US": "Anthropic (Claude API)"},
24
+ "openai_label": {"zh-CN": "OpenAI / 兼容接口", "en-US": "OpenAI / compatible"},
25
+ "copilot_label": {"zh-CN": "GitHub Copilot", "en-US": "GitHub Copilot"},
26
+ "copilot_open_url": {"zh-CN": "请在浏览器中打开以下 URL 完成授权:", "en-US": "Open the following URL in your browser to authorize:"},
27
+ "copilot_enter_code": {"zh-CN": "并输入代码: {code}", "en-US": "and enter code: {code}"},
28
+ "copilot_waiting": {"zh-CN": "等待 GitHub 授权中...", "en-US": "Waiting for GitHub authorization..."},
29
+ "copilot_auth_success": {"zh-CN": "GitHub Copilot 授权成功 (用户: {user})", "en-US": "GitHub Copilot authorized (user: {user})"},
30
+ "copilot_no_subscription": {"zh-CN": "未订阅 GitHub Copilot,请先在 GitHub 上订阅", "en-US": "No GitHub Copilot subscription found, please subscribe on GitHub first"},
31
+ "copilot_not_authenticated": {"zh-CN": "未认证 GitHub Copilot,请先运行 'illusion auth login'", "en-US": "GitHub Copilot not authenticated, run 'illusion auth login' first"},
32
+ "copilot_device_expired": {"zh-CN": "设备码已过期,请重新运行登录", "en-US": "Device code expired, please retry login"},
33
+ "copilot_auth_denied": {"zh-CN": "授权被拒绝", "en-US": "Authorization denied"},
34
+ "codex_label": {"zh-CN": "OpenAI Codex (ChatGPT 订阅)", "en-US": "OpenAI Codex (ChatGPT subscription)"},
35
+ "codex_not_found": {"zh-CN": "未找到 Codex CLI 认证,请先安装 Codex CLI 并运行 'codex auth login'", "en-US": "Codex CLI auth not found, please install Codex CLI and run 'codex auth login' first"},
36
+ "codex_auth_success": {"zh-CN": "Codex 认证读取成功 (用户: {user})", "en-US": "Codex auth loaded successfully (user: {user})"},
37
+ "enter_number": {"zh-CN": "输入序号", "en-US": "Enter number"},
38
+ "invalid_selection": {"zh-CN": "无效选择", "en-US": "Invalid selection"},
39
+ "select_api_format": {"zh-CN": "选择 API 格式:", "en-US": "Select API format:"},
40
+ "enter_endpoint": {"zh-CN": "输入 API 端点", "en-US": "Enter API endpoint"},
41
+ "enter_api_key": {"zh-CN": "输入 API 密钥", "en-US": "Enter API key"},
42
+ "enter_model": {"zh-CN": "输入模型名称", "en-US": "Enter model name"},
43
+ "model_required": {"zh-CN": "模型名称不能为空", "en-US": "Model name cannot be empty"},
44
+ "endpoint_required": {"zh-CN": "端点不能为空", "en-US": "Endpoint cannot be empty"},
45
+ "api_key_required": {"zh-CN": "API 密钥不能为空", "en-US": "API key cannot be empty"},
46
+ "env_saved": {"zh-CN": "环境 {env_key} 已保存并激活", "en-US": "Environment {env_key} saved and activated"},
47
+ "no_envs": {"zh-CN": "未配置任何环境,请先运行 'illusion auth login'", "en-US": "No environments configured, run 'illusion auth login' first"},
48
+ "env_status_title": {"zh-CN": "环境认证状态:", "en-US": "Environment credential status:"},
49
+ "col_env": {"zh-CN": "环境", "en-US": "Env"},
50
+ "col_format": {"zh-CN": "格式", "en-US": "Format"},
51
+ "col_model": {"zh-CN": "模型", "en-US": "Model"},
52
+ "col_endpoint": {"zh-CN": "端点", "en-US": "Endpoint"},
53
+ "col_credential": {"zh-CN": "凭据", "en-US": "Credential"},
54
+ "configured": {"zh-CN": "已配置", "en-US": "configured"},
55
+ "missing": {"zh-CN": "未配置", "en-US": "missing"},
56
+ "active_mark": {"zh-CN": "← 当前", "en-US": "<-- active"},
57
+ "select_env_to_logout": {"zh-CN": "选择要清除凭据的环境:", "en-US": "Select environment to clear credentials:"},
58
+ "credential_cleared": {"zh-CN": "已清除环境 {env_key} 的凭据", "en-US": "Credentials cleared for {env_key}"},
59
+ "select_env_to_switch": {"zh-CN": "选择要切换的环境:", "en-US": "Select environment to switch to:"},
60
+ "switched_to": {"zh-CN": "已切换到环境 {env_key}", "en-US": "Switched to environment {env_key}"},
61
+ "env_not_found": {"zh-CN": "环境 {env_key} 不存在", "en-US": "Environment {env_key} not found"},
62
+ "select_language": {"zh-CN": "选择界面语言:", "en-US": "Select interface language:"},
63
+ "language_set": {"zh-CN": "界面语言已设置为: {lang}", "en-US": "Interface language set to: {lang}"},
64
+ "skip_default": {"zh-CN": "回车跳过,使用默认值", "en-US": "Press Enter to skip, use default"},
65
+ "model_added": {"zh-CN": "已向 {env_key} 添加模型 {model_key}: {model_name}", "en-US": "Added {model_key} to {env_key}: {model_name}"},
66
+ # --- 后端事件 ---
67
+ "task_stopped": {"zh-CN": "当前任务已停止。", "en-US": "Current task stopped."},
68
+ "no_active_task": {"zh-CN": "没有正在执行的任务", "en-US": "No active task to stop"},
69
+ "bg_agent_waiting": {"zh-CN": "等待后台代理完成", "en-US": "Waiting for background agent"},
70
+ "bg_agent_resuming": {"zh-CN": "后台代理已完成,继续执行", "en-US": "Background agent completed, resuming"},
71
+ "default_endpoint": {"zh-CN": "默认", "en-US": "default"},
72
+ # --- mcp ---
73
+ "mcp_none": {"zh-CN": "未配置 MCP 服务器", "en-US": "No MCP servers configured"},
74
+ "mcp_invalid_json": {"zh-CN": "无效 JSON: {exc}", "en-US": "Invalid JSON: {exc}"},
75
+ "mcp_invalid_config": {"zh-CN": "无效的 MCP 服务器配置: {exc}", "en-US": "Invalid MCP server config: {exc}"},
76
+ "mcp_added": {"zh-CN": "已添加 MCP 服务器: {name}", "en-US": "Added MCP server: {name}"},
77
+ "mcp_not_found": {"zh-CN": "未找到 MCP 服务器: {name}", "en-US": "MCP server not found: {name}"},
78
+ "mcp_removed": {"zh-CN": "已移除 MCP 服务器: {name}", "en-US": "Removed MCP server: {name}"},
79
+ # --- plugin ---
80
+ "plugin_none": {"zh-CN": "未安装插件", "en-US": "No plugins installed"},
81
+ "plugin_enabled": {"zh-CN": "启用", "en-US": "enabled"},
82
+ "plugin_disabled": {"zh-CN": "禁用", "en-US": "disabled"},
83
+ "plugin_installed": {"zh-CN": "已安装插件: {name}", "en-US": "Installed plugin: {name}"},
84
+ "plugin_uninstalled": {"zh-CN": "已卸载插件: {name}", "en-US": "Uninstalled plugin: {name}"},
85
+ # --- cron ---
86
+ "cron_already_running": {"zh-CN": "调度器已在运行", "en-US": "Cron scheduler is already running"},
87
+ "cron_started": {"zh-CN": "调度器已启动 (pid={pid})", "en-US": "Cron scheduler started (pid={pid})"},
88
+ "cron_stopped": {"zh-CN": "调度器已停止", "en-US": "Cron scheduler stopped"},
89
+ "cron_not_running": {"zh-CN": "调度器未在运行", "en-US": "Cron scheduler is not running"},
90
+ "cron_state_running": {"zh-CN": "运行中", "en-US": "running"},
91
+ "cron_state_stopped": {"zh-CN": "已停止", "en-US": "stopped"},
92
+ "cron_jobs_none": {"zh-CN": "未配置定时任务", "en-US": "No cron jobs configured"},
93
+ "cron_recurring": {"zh-CN": "周期", "en-US": "recurring"},
94
+ "cron_oneshot": {"zh-CN": "单次", "en-US": "one-shot"},
95
+ "cron_never": {"zh-CN": "从未", "en-US": "never"},
96
+ "cron_na": {"zh-CN": "无", "en-US": "n/a"},
97
+ "cron_errors": {"zh-CN": "错误: {n}", "en-US": "errors: {n}"},
98
+ "cron_prompt_label": {"zh-CN": "提示词", "en-US": "prompt"},
99
+ "cron_last_label": {"zh-CN": "上次", "en-US": "last"},
100
+ "cron_next_label": {"zh-CN": "下次", "en-US": "next"},
101
+ "cron_job_not_found": {"zh-CN": "未找到定时任务: {name}", "en-US": "Cron job not found: {name}"},
102
+ "cron_enabled": {"zh-CN": "已启用", "en-US": "enabled"},
103
+ "cron_disabled": {"zh-CN": "已禁用", "en-US": "disabled"},
104
+ "cron_job_state": {"zh-CN": "任务 '{name}' {state}", "en-US": "Job '{name}' {state}"},
105
+ "cron_no_prompt": {"zh-CN": "任务无提示词: {name}", "en-US": "Job has no prompt: {name}"},
106
+ "cron_running_job": {"zh-CN": "正在执行任务 '{name}'...", "en-US": "Running job '{name}'..."},
107
+ "cron_finished": {"zh-CN": "完成: {status} (rc={rc})", "en-US": "Finished: {status} (rc={rc})"},
108
+ "cron_output": {"zh-CN": "输出:", "en-US": "Output:"},
109
+ "cron_error": {"zh-CN": "错误:", "en-US": "Error:"},
110
+ "cron_no_history": {"zh-CN": "无执行历史", "en-US": "No execution history"},
111
+ "cron_no_log": {"zh-CN": "未找到调度器日志,请先运行: illusion cron start", "en-US": "No scheduler log found. Start with: illusion cron start"},
112
+ # --- session ---
113
+ "session_not_found_prev": {"zh-CN": "未找到之前的会话", "en-US": "No previous session found"},
114
+ "session_continuing": {"zh-CN": "继续会话: {summary}", "en-US": "Continuing session: {summary}"},
115
+ "session_no_saved": {"zh-CN": "未找到保存的会话", "en-US": "No saved sessions found"},
116
+ "session_saved_list": {"zh-CN": "已保存的会话:", "en-US": "Saved sessions:"},
117
+ "session_msg_count": {"zh-CN": "{n} 条消息", "en-US": "{n} msgs"},
118
+ "session_enter_id": {"zh-CN": "输入会话序号或 ID", "en-US": "Enter session number or ID"},
119
+ "session_not_found": {"zh-CN": "未找到会话: {id}", "en-US": "Session not found: {id}"},
120
+ "print_requires_prompt": {"zh-CN": "错误: -p/--print 需要提供提示词,例如 -p '你的提示词'", "en-US": "Error: -p/--print requires a prompt, e.g. -p 'your prompt'"},
121
+ # --- settings ---
122
+ "no_api_key": {"zh-CN": "未找到 API 密钥。请使用 'illusion auth login' 配置,或设置 ANTHROPIC_API_KEY / OPENAI_API_KEY 环境变量", "en-US": "No API key found. Run 'illusion auth login' or set ANTHROPIC_API_KEY / OPENAI_API_KEY environment variable"},
123
+ "no_auth": {"zh-CN": "未找到认证信息。请使用 'illusion auth login' 配置,或设置对应的环境变量", "en-US": "No credentials found. Run 'illusion auth login' or set the matching environment variable"},
124
+ # --- manager ---
125
+ "unknown_env": {"zh-CN": "未知环境: {env_key}", "en-US": "Unknown environment: {env_key}"},
126
+ "cannot_remove_active_env": {"zh-CN": "不能移除当前活动环境", "en-US": "Cannot remove the active environment"},
127
+ # --- model ---
128
+ "model_active": {"zh-CN": "当前模型:{model}", "en-US": "Active model: {model}"},
129
+ "model_active_detail": {"zh-CN": " 模型:{name}\n API 格式:{fmt}\n 基础 URL:{url}", "en-US": " model: {name}\n api_format: {fmt}\n base_url: {url}"},
130
+ "model_list_title": {"zh-CN": "模型列表:", "en-US": "Models:"},
131
+ "model_set_to": {"zh-CN": "模型已设置为 {ref}:{name}", "en-US": "Model set to {ref}: {name}"},
132
+ "model_unknown": {"zh-CN": "未知模型:{ref}。使用 /model list 查看可用模型。", "en-US": "Unknown model: {ref}. Use /model list to see available models."},
133
+ "model_usage": {"zh-CN": "用法:/model [show|set MODEL]", "en-US": "Usage: /model [show|set MODEL]"},
134
+ "model_env_model": {"zh-CN": "模型:{name}", "en-US": "model: {name}"},
135
+ "model_api_format": {"zh-CN": "API 格式:{fmt}", "en-US": "api_format: {fmt}"},
136
+ "model_base_url": {"zh-CN": "基础 URL:{url}", "en-US": "base_url: {url}"},
137
+ "model_default_url": {"zh-CN": "(默认)", "en-US": "(default)"},
138
+ # --- compact ---
139
+ "compact_warning_approaching": {"zh-CN": "上下文使用量:~{pct}% — 接近自动压缩阈值", "en-US": "Context usage: ~{pct}% — approaching auto-compact threshold"},
140
+ "compact_compacted": {"zh-CN": "已压缩上下文以释放空间", "en-US": "Context compacted to free up space"},
141
+ "compact_overflow_detected": {"zh-CN": "检测到上下文溢出,尝试响应式压缩…", "en-US": "Context overflow detected, attempting reactive compact..."},
142
+ "compact_reactive_success": {"zh-CN": "响应式压缩成功,正在重试请求…", "en-US": "Reactive compact succeeded, retrying request..."},
143
+ "compact_overflow_failed": {"zh-CN": "上下文溢出且响应式压缩失败:{error}", "en-US": "Context overflow and reactive compact failed: {error}"},
144
+ "compact_network_error": {"zh-CN": "网络错误:{error}。请检查网络连接后重试。", "en-US": "Network error: {error}. Check your internet connection and try again."},
145
+ "compact_api_error": {"zh-CN": "API 错误:{error}", "en-US": "API error: {error}"},
146
+ "compact_result": {"zh-CN": "已压缩对话:{before} → {after} 条消息(节省 ~{saved} tokens)。", "en-US": "Compacted conversation from {before} to {after} messages (saved ~{saved} tokens)."},
147
+ "compact_summary_prefix": {"zh-CN": "本会话从之前超出上下文限制的对话继续。以下摘要涵盖对话的早期部分。", "en-US": "This session is being continued from a previous conversation that ran out of context. The summary below covers the earlier portion of the conversation."},
148
+ "compact_recent_preserved": {"zh-CN": "最近的消息已原样保留。", "en-US": "Recent messages are preserved verbatim."},
149
+ "compact_suppress_followup": {"zh-CN": "\n从上次中断处继续对话,不要向用户提问。直接继续 — 不要确认摘要,不要复述进展,不要以「我继续」等开头。像中断从未发生一样继续上次的任务。", "en-US": "\nContinue the conversation from where it left off without asking the user any further questions. Resume directly — do not acknowledge the summary, do not recap what was happening, do not preface with \"I'll continue\" or similar. Pick up the last task as if the break never happened."},
150
+ "compact_conversation_start": {"zh-CN": "(对话开始)", "en-US": "(conversation start)"},
151
+ "permission_denied_stopped": {"zh-CN": "权限被拒绝,已终止当前操作({tool})。", "en-US": "Permission denied, stopped current operation ({tool})."},
152
+ }
153
+
154
+ # --- 命令描述翻译 ---
155
+ COMMAND_DESCRIPTIONS_ZH: dict[str, str] = {
156
+ "help": "显示可用命令及用法说明",
157
+ "exit": "退出 IllusionCode",
158
+ "clear": "清空当前对话并开启新会话",
159
+ "new": "开启新对话并重置任务 ID",
160
+ "version": "显示已安装版本",
161
+ "status": "显示会话状态",
162
+ "context": "显示系统提示词或管理上下文窗口",
163
+ "summary": "总结对话历史",
164
+ "compact": "压缩较早对话历史",
165
+ "memory": "查看和管理项目记忆",
166
+ "hooks": "显示已配置 hooks",
167
+ "resume": "恢复最近保存的会话",
168
+ "export": "导出当前转录",
169
+ "share": "创建可分享的转录快照",
170
+ "copy": "复制最新回复或指定文本",
171
+ "rewind": "移除最新对话轮次",
172
+ "files": "列出当前工作区文件",
173
+ "init": "初始化项目 IllusionCode 文件",
174
+ "bridge": "查看 bridge 辅助信息并创建 bridge 会话",
175
+ "login": "查看认证状态或保存 API Key",
176
+ "logout": "清除已保存 API Key",
177
+ "feedback": "保存 CLI 反馈到本地日志",
178
+ "skills": "列出或显示可用技能",
179
+ "config": "显示或更新配置",
180
+ "mcp": "显示 MCP 状态",
181
+ "plugin": "管理插件",
182
+ "reload-plugins": "重新加载当前工作区插件发现结果",
183
+ "permissions": "显示或更新权限模式",
184
+ "plan": "切换计划权限模式",
185
+ "thinking": "显示或更新思考模式",
186
+ "fast": "显示或更新快速模式",
187
+ "effort": "显示或更新推理强度",
188
+ "passes": "显示或更新推理轮数",
189
+ "turns": "显示或更新最大 agent 轮数",
190
+ "continue": "在中断后继续上一轮工具循环",
191
+ "model": "显示或更新默认模型",
192
+ "language": "显示或更新界面语言",
193
+ "output-style": "显示或更新输出风格",
194
+ "doctor": "显示环境诊断信息",
195
+ "diff": "显示 git diff 输出",
196
+ "branch": "显示 git 分支信息",
197
+ "commit": "显示状态或创建 git 提交",
198
+ "issue": "显示或更新项目 issue 上下文",
199
+ "pr_comments": "显示或更新项目 PR 评论上下文",
200
+ "privacy-settings": "显示本地隐私与存储设置",
201
+ "delete": "清理选定的会话",
202
+ "rules": "查看选定的规则",
203
+ }
204
+
205
+ # --- 斜杠命令输出翻译 ---
206
+
207
+ # 命令消息精确匹配表(英文 -> 中文)
208
+ _COMMAND_EXACT: dict[str, str] = {
209
+ # 通用
210
+ "Available commands:": "可用命令:",
211
+ "(empty)": "(空)",
212
+ "(no output)": "(无输出)",
213
+ "(no directories)": "(无目录)",
214
+ "(no matching files)": "(无匹配文件)",
215
+ "(no diff)": "(无差异)",
216
+ "(working tree clean)": "(工作区干净)",
217
+ # 会话
218
+ "Conversation cleared.": "对话已清空。",
219
+ "Started a new conversation session.": "已开启新对话。",
220
+ "No saved sessions found for this project.": "当前项目未找到已保存会话。",
221
+ "Nothing to copy.": "没有可复制的内容。",
222
+ "Deleted current session:": "已删除当前会话:",
223
+ # 记忆与 hooks
224
+ "No memory files.": "没有记忆文件。",
225
+ "No hooks configured.": "未配置 hooks。",
226
+ # 插件与技能
227
+ "No plugins discovered.": "未发现插件。",
228
+ "No skills available.": "没有可用技能。",
229
+ # 项目初始化
230
+ "Project already initialized for IllusionCode.": "项目已完成 IllusionCode 初始化。",
231
+ # Bridge
232
+ "No bridge sessions.": "没有 bridge 会话。",
233
+ # 认证
234
+ "Stored API key in ~/.illusion/settings.json": "API Key 已保存到 ~/.illusion/settings.json",
235
+ "Cleared stored API key.": "已清除已保存 API Key。",
236
+ # 反馈
237
+ "Usage: /feedback TEXT": "用法:/feedback 文本",
238
+ # 计划模式
239
+ "Plan mode enabled.": "计划模式已开启。",
240
+ "Plan mode disabled.": "计划模式已关闭。",
241
+ # 模型
242
+ "Usage: /model [show|set MODEL]": "用法:/model [show|set MODEL]",
243
+ "Model set to": "模型已切换为",
244
+ # 语言
245
+ "Available UI languages: zh-CN, en": "可用界面语言:zh-CN, en",
246
+ "Usage: /language [show|list|set zh-CN|set en]": "用法:/language [show|list|set zh-CN|set en]",
247
+ # 输出风格
248
+ "Usage: /output-style [show|list|set NAME]": "用法:/output-style [show|list|set NAME]",
249
+ # 诊断与隐私
250
+ "Doctor summary:": "诊断摘要:",
251
+ "Privacy settings:": "隐私设置:",
252
+ # Git
253
+ "Usage: /branch [show|list]": "用法:/branch [show|list]",
254
+ "Nothing to commit.": "没有可提交的改动。",
255
+ "Progress must be an integer between 0 and 100.": "进度必须是 0 到 100 之间的整数。",
256
+ "Nothing to continue (no pending tool results).": "没有待继续的内容(无待处理工具结果)。",
257
+ "Continuing pending tool loop...": "正在继续待处理的工具循环…",
258
+ # MCP
259
+ "HTTP/WS MCP auth supports bearer or header modes.": "HTTP/WS MCP 认证支持 bearer 或 header 模式。",
260
+ "stdio MCP auth supports bearer or env modes.": "stdio MCP 认证支持 bearer 或 env 模式。",
261
+ "No MCP servers configured.": "未配置 MCP 服务器。",
262
+ # Issue 与 PR 评论
263
+ "Cleared issue context.": "已清除 issue 上下文。",
264
+ "No issue context to clear.": "没有可清除的 issue 上下文。",
265
+ "Cleared PR comments context.": "已清除 PR 评论上下文。",
266
+ "No PR comments context to clear.": "没有可清除的 PR 评论上下文。",
267
+ # 上下文窗口
268
+ "Error: context window must be positive": "错误:上下文窗口必须为正数",
269
+ "Error: invalid number": "错误:无效的数字",
270
+ "Usage: /context [prompt|window|set N]": "用法:/context [prompt|window|set N]",
271
+ # 用法提示
272
+ "Usage: /summary [MAX_MESSAGES]": "用法:/summary [最大消息数]",
273
+ "Usage: /compact [PRESERVE_RECENT]": "用法:/compact [保留近期消息数]",
274
+ "Usage: /memory add TITLE :: CONTENT": "用法:/memory add 标题 :: 内容",
275
+ "Usage: /memory [list|show NAME|add TITLE :: CONTENT|remove NAME]": "用法:/memory [list|show 名称|add 标题 :: 内容|remove 名称]",
276
+ "Usage: /rewind [TURNS]": "用法:/rewind [轮数]",
277
+ "Usage: /config [show|set KEY VALUE]": "用法:/config [show|set 键 值]",
278
+ "Usage: /fast [show|on|off|toggle]": "用法:/fast [show|on|off|toggle]",
279
+ "Usage: /thinking [show|on|off|toggle]": "用法:/thinking [show|on|off|toggle]",
280
+ "Usage: /effort [show|low|medium|high|xhigh|max]": "用法:/effort [show|low|medium|high|xhigh|max]",
281
+ "Usage: /passes [show|COUNT]": "用法:/passes [数量]",
282
+ "Usage: /turns [show|COUNT]": "用法:/turns [数量]",
283
+ "Usage: /continue [COUNT]": "用法:/continue [数量]",
284
+ "Usage: /plan [on|off]": "用法:/plan [on|off]",
285
+ "Usage: /permissions [show|set MODE]": "用法:/permissions [show|set 模式]",
286
+ "Usage: /issue set TITLE :: BODY": "用法:/issue set 标题 :: 正文",
287
+ "Usage: /issue [show|set TITLE :: BODY|clear]": "用法:/issue [show|set 标题 :: 正文|clear]",
288
+ "Usage: /pr_comments add FILE[:LINE] :: COMMENT": "用法:/pr_comments add 文件[:行号] :: 评论",
289
+ "Usage: /pr_comments [show|add FILE[:LINE] :: COMMENT|clear]": "用法:/pr_comments [show|add 文件[:行号] :: 评论|clear]",
290
+ "Usage: /plugin [list|enable NAME|disable NAME|install PATH|uninstall NAME]":
291
+ "用法:/plugin [list|enable 名称|disable 名称|install 路径|uninstall 名称]",
292
+ "Usage: /bridge [show|encode API_BASE_URL TOKEN|decode SECRET|sdk API_BASE_URL SESSION_ID|spawn CMD|list|output SESSION_ID|stop SESSION_ID]":
293
+ "用法:/bridge [show|encode API_BASE_URL TOKEN|decode SECRET|sdk API_BASE_URL SESSION_ID|spawn CMD|list|output SESSION_ID|stop SESSION_ID]",
294
+ # 快速模式
295
+ "No conversation content to summarize.": "没有可总结的对话内容。",
296
+ # 删除与规则
297
+ "Saved sessions:": "已保存会话:",
298
+ "Use /resume <session_id> to restore a specific session.": "使用 /resume <会话ID> 恢复指定会话。",
299
+ # 登录
300
+ "Usage: /login API_KEY": "用法:/login API_KEY",
301
+ # Doctor
302
+ "- backend host: available": "- 后端宿主:可用",
303
+ "- network: enabled only for provider and explicit web/MCP calls": "- 网络:仅用于提供商和显式 web/MCP 调用",
304
+ "- storage: local files under ~/.illusion and project .illusion": "- 存储:本地文件位于 ~/.illusion 和项目 .illusion",
305
+ }
306
+
307
+ # 命令消息正则替换表(pattern, replacement)
308
+ # replacement 可以是字符串(含 \1 等反向引用)或 lambda(match) -> str
309
+ _COMMAND_SUBSTITUTIONS: list[tuple[str, str | Any]] = [
310
+ # 版本
311
+ (r"^IllusionCode (.+)$", r"IllusionCode 版本 \1"),
312
+ # 上下文窗口
313
+ (r"^Context window: (\d[\d,]*) tokens$", r"上下文窗口:\1 tokens"),
314
+ (r"^Context window set to (\d[\d,]*) tokens$", r"上下文窗口已设置为 \1 tokens"),
315
+ (r"^Context Window: (\d[\d,]*) tokens$", r"上下文窗口:\1 tokens"),
316
+ (r"^Estimated Used: ~(\d[\d,]*) tokens \((\d+)%\)$", r"预估已用:~\1 tokens(\2%)"),
317
+ (r"^Remaining: ~(\d[\d,]*) tokens$", r"剩余:~\1 tokens"),
318
+ (r"^Actual API Usage: input=(\d[\d,]*) output=(\d[\d,]*)$", r"实际 API 用量:input=\1 output=\2"),
319
+ # 模型
320
+ (r"^Model: (.+)$", r"模型:\1"),
321
+ (r"^Model set to (.+)\. Restart session to use it\.$", r"模型已设置为 \1。重启会话后生效。"),
322
+ (r"^Model set to (.+)\.$", r"模型已设置为 \1。"),
323
+ (r"^Unknown model: (.+)$", r"未知模型:\1"),
324
+ # 语言
325
+ (r"^UI language: (.+)$", r"界面语言:\1"),
326
+ (r"^UI language set to (.+)$", r"界面语言已设置为 \1"),
327
+ # 输出风格
328
+ (r"^Output style: (.+)$", r"输出风格:\1"),
329
+ (r"^Output style set to (.+)$", r"输出风格已设置为 \1"),
330
+ (r"^Unknown output style: (.+)$", r"未知输出风格:\1"),
331
+ # 快速模式
332
+ (r"^Fast mode: (on|off)$", r"快速模式:\1"),
333
+ (r"^Fast mode (enabled|disabled)\.$",
334
+ lambda m: f"快速模式{'已开启' if m.group(1) == 'enabled' else '已关闭'}。"),
335
+ # 思考模式
336
+ (r"^Thinking mode: (on|off)$", r"思考模式:\1"),
337
+ (r"^Thinking mode (enabled|disabled)\.$",
338
+ lambda m: f"思考模式{'已开启' if m.group(1) == 'enabled' else '已关闭'}。"),
339
+ # 推理强度
340
+ (r"^Reasoning effort: (.+)$", r"推理强度:\1"),
341
+ (r"^Reasoning effort set to (.+)\.$", r"推理强度已设置为 \1。"),
342
+ # 推理轮数
343
+ (r"^Passes: (.+)$", r"推理轮数:\1"),
344
+ (r"^Pass count set to (.+)\.$", r"推理轮数已设置为 \1。"),
345
+ # 最大轮数
346
+ (r"^Max turns set to (.+)\.$", r"最大轮数已设置为 \1。"),
347
+ # 权限
348
+ (r"^Permission mode set to (.+)$", r"权限模式已设置为 \1"),
349
+ (r"^Mode: (.+)$", r"模式:\1"),
350
+ # 会话
351
+ (r"^Session not found: (.+)$", r"未找到会话:\1"),
352
+ (r"^Restored (\d+) messages from session (.+)$", r"已从会话 \2 恢复 \1 条消息"),
353
+ (r"^Restored (\d+) messages from the latest session\.$", r"已从最近会话恢复 \1 条消息。"),
354
+ (r"^Exported transcript to (.+)$", r"已导出转录到 \1"),
355
+ (r"^Created shareable transcript snapshot at (.+)$", r"已创建可分享的转录快照:\1"),
356
+ (r"^Copied (\d+) characters to the clipboard\.$", r"已复制 \1 个字符到剪贴板。"),
357
+ (r"^Clipboard unavailable\. Saved copied text to (.+)$", r"剪贴板不可用,已保存到 \1"),
358
+ (r"^Rewound (\d+) turn\(s\); removed (\d+) message\(s\)\.$", r"已回退 \1 轮,移除 \2 条消息。"),
359
+ # 任务
360
+ (r"^Started task (.+)$", r"已启动任务 \1"),
361
+ (r"^Stopped task (.+)$", r"已停止任务 \1"),
362
+ (r"^No task found with ID: (.+)$", r"未找到任务 ID:\1"),
363
+ (r"^Updated task (.+) description$", r"已更新任务 \1 的描述"),
364
+ (r"^Updated task (.+) progress to (\d+)%$", r"已更新任务 \1 的进度为 \2%"),
365
+ (r"^Updated task (.+) note$", r"已更新任务 \1 的备注"),
366
+ (r"^Deleted (\d+) session file\(s\)\.$", r"已删除 \1 个会话文件。"),
367
+ (r"^Deleted session: (.+)$", r"已删除会话:\1"),
368
+ (r"^Deleted current session: (.+)$", r"已删除当前会话:\1"),
369
+ # Agent
370
+ (r"^No agent found with ID: (.+)$", r"未找到 agent ID:\1"),
371
+ # Bridge
372
+ (r"^Spawned bridge session (.+) pid=(\d+)$", r"已创建 bridge 会话 \1 进程 \2"),
373
+ (r"^Stopped bridge session (.+)$", r"已停止 bridge 会话 \1"),
374
+ # 插件
375
+ (r"^Enabled plugin '(.+)'\. Restart session to reload\.$", r"已启用插件「\1」,重启会话后生效。"),
376
+ (r"^Disabled plugin '(.+)'\. Restart session to reload\.$", r"已禁用插件「\1」,重启会话后生效。"),
377
+ (r"^Installed plugin to (.+)$", r"已安装插件到 \1"),
378
+ (r"^Uninstalled plugin '(.+)'$", r"已卸载插件「\1」"),
379
+ (r"^Plugin '(.+)' not found$", r"未找到插件「\1」"),
380
+ # 配置
381
+ (r"^Unknown config key: (.+)$", r"未知配置项:\1"),
382
+ (r"^Updated (.+)$", r"已更新 \1"),
383
+ # 记忆
384
+ (r"^Memory entry not found: (.+)$", r"未找到记忆条目:\1"),
385
+ (r"^Added memory entry (.+)$", r"已添加记忆条目 \1"),
386
+ (r"^Removed memory entry (.+)$", r"已移除记忆条目 \1"),
387
+ # MCP
388
+ (r"^Unknown MCP server: (.+)$", r"未知 MCP 服务器:\1"),
389
+ (r"^Server (.+) does not support auth updates$", r"服务器 \1 不支持认证更新"),
390
+ (r"^Saved MCP auth for (.+)\. Restart session to reconnect\.$", r"已保存 \1 的 MCP 认证,重启会话后重新连接。"),
391
+ # Issue 与 PR 评论
392
+ (r"^No issue context\. File path: (.+)$", r"无 issue 上下文。文件路径:\1"),
393
+ (r"^Saved issue context to (.+)$", r"已保存 issue 上下文到 \1"),
394
+ (r"^No PR comments context\. File path: (.+)$", r"无 PR 评论上下文。文件路径:\1"),
395
+ (r"^Added PR comment to (.+)$", r"已添加 PR 评论到 \1"),
396
+ # 反馈
397
+ (r"^Saved feedback to (.+)$", r"已保存反馈到 \1"),
398
+ # 初始化
399
+ (r"^Initialized project files:$", r"已初始化项目文件:"),
400
+ # 技能
401
+ (r"^Skill not found: (.+)$", r"未找到技能:\1"),
402
+ # 规则
403
+ (r"^No rules found in (.+)$", r"在 \1 中未找到规则"),
404
+ (r"^Rule not found: (.+)\. Use /rules to list available rules\.$", r"未找到规则:\1。使用 /rules 查看可用规则。"),
405
+ # 状态行(多行消息的逐行翻译)
406
+ (r"^Session stats:$", r"会话统计:"),
407
+ (r"^Messages: (\d+)$", r"消息数:\1"),
408
+ (r"^Usage: input=(\d+) output=(\d+)$", r"用量:输入=\1 输出=\2"),
409
+ (r"^Effort: (.+)$", r"推理强度:\1"),
410
+ (r"^Actual usage: input=(\d+) output=(\d+)$", r"实际用量:输入=\1 输出=\2"),
411
+ (r"^Estimated conversation tokens: (\d+)$", r"预估对话 token:\1"),
412
+ (r"^Input tokens: (\d+)$", r"输入 token:\1"),
413
+ (r"^Output tokens: (\d+)$", r"输出 token:\1"),
414
+ (r"^Total tokens: (\d+)$", r"总计 token:\1"),
415
+ (r"^Estimated cost: (.+)$", r"预估费用:\1"),
416
+ (r"^Max turns \(engine\): (.+)$", r"最大轮数(引擎):\1"),
417
+ (r"^Max turns \(config\): (.+)$", r"最大轮数(配置):\1"),
418
+ (r"^Memory directory: (.+)$", r"记忆目录:\1"),
419
+ (r"^Entrypoint: (.+)$", r"入口文件:\1"),
420
+ (r"^Compacted conversation from (\d+) messages to (\d+)\.$", r"已压缩对话:\1 条 → \2 条。"),
421
+ (r"^Compacted conversation from (\d+) to (\d+) messages \(saved ~(\d[\d,]*) tokens\)\.$", r"已压缩对话:\1 → \2 条消息(节省 ~\3 tokens)。"),
422
+ (r"^Current branch: (.+)$", r"当前分支:\1"),
423
+ (r"^Feedback log: (.+)$", r"反馈日志:\1"),
424
+ (r"^Auth status:$", r"认证状态:"),
425
+ (r"^Bridge summary:$", r"Bridge 摘要:"),
426
+ (r"^Reloaded plugins:$", r"已重新加载插件:"),
427
+ (r"^Available skills:$", r"可用技能:"),
428
+ (r"^Rules directory: (.+)$", r"规则目录:\1"),
429
+ # 前缀行(doctor, privacy-settings, bridge, login, stats, permissions 等)
430
+ (r"^- backend host: available$", r"- 后端宿主:可用"),
431
+ (r"^- network: enabled only for provider and explicit web/MCP calls$", r"- 网络:仅用于提供商和显式 web/MCP 调用"),
432
+ (r"^- storage: local files under ~\/\.illusion and project \.illusion$", r"- 存储:本地文件位于 ~/.illusion 和项目 .illusion"),
433
+ (r"^- messages: (\d+)$", r"- 消息数:\1"),
434
+ (r"^- estimated_tokens: (\d+)$", r"- 预估 token:\1"),
435
+ (r"^- tools: (\d+)$", r"- 工具数:\1"),
436
+ (r"^- memory_files: (\d+)$", r"- 记忆文件:\1"),
437
+ (r"^- background_tasks: (\d+)$", r"- 后台任务:\1"),
438
+ (r"^- output_style: (.+)$", r"- 输出风格:\1"),
439
+ (r"^- cwd: (.+)$", r"- 工作目录:\1"),
440
+ (r"^- sessions: (\d+)$", r"- 会话数:\1"),
441
+ (r"^- utilities: (.+)$", r"- 工具集:\1"),
442
+ (r"^- provider: (.+)$", r"- 提供商:\1"),
443
+ (r"^- auth_status: (.+)$", r"- 认证状态:\1"),
444
+ (r"^- base_url: (.+)$", r"- 基础 URL:\1"),
445
+ (r"^- model: (.+)$", r"- 模型:\1"),
446
+ (r"^- api_key: (.+)$", r"- API Key:\1"),
447
+ (r"^Allowed tools: (.+)$", r"允许的工具:\1"),
448
+ (r"^Denied tools: (.+)$", r"拒绝的工具:\1"),
449
+ (r"^- permission_mode: (.+)$", r"- 权限模式:\1"),
450
+ (r"^- ui_language: (.+)$", r"- 界面语言:\1"),
451
+ (r"^- memory_dir: (.+)$", r"- 记忆目录:\1"),
452
+ (r"^- plugin_count: (\d+)$", r"- 插件数:\1"),
453
+ (r"^- mcp_configured: (yes|no)$",
454
+ lambda m: f"- MCP 已配置:{'是' if m.group(1) == 'yes' else '否'}"),
455
+ (r"^- user_config_dir: (.+)$", r"- 用户配置目录:\1"),
456
+ (r"^- project_config_dir: (.+)$", r"- 项目配置目录:\1"),
457
+ (r"^- session_dir: (.+)$", r"- 会话目录:\1"),
458
+ (r"^- feedback_log: (.+)$", r"- 反馈日志:\1"),
459
+ (r"^- api_base_url: (.+)$", r"- API 基础 URL:\1"),
460
+ ]
461
+
462
+
463
+ def _get_lang() -> str:
464
+ """获取当前 ui_language,避免循环导入"""
465
+ from illusion.config.settings import load_settings
466
+ settings = load_settings()
467
+ return settings.ui_language or "en-US"
468
+
469
+
470
+ def t(key: str, **kwargs: Any) -> str:
471
+ """根据 ui_language 返回对应语言的文本
472
+
473
+ Args:
474
+ key: 消息键名
475
+ **kwargs: 格式化参数
476
+
477
+ Returns:
478
+ str: 对应语言的文本,未找到时返回 key 本身
479
+ """
480
+ lang = _get_lang()
481
+ msg = MESSAGES.get(key, {}).get(lang, MESSAGES.get(key, {}).get("en-US", key))
482
+ if kwargs:
483
+ return msg.format(**kwargs)
484
+ return msg
485
+
486
+
487
+ def _is_zh(locale: str) -> bool:
488
+ return locale.lower().startswith("zh")
489
+
490
+
491
+ def _translate_single_line(line: str) -> str:
492
+ """翻译单行命令消息(英文 -> 当前语言)"""
493
+ if line in _COMMAND_EXACT:
494
+ return _COMMAND_EXACT[line]
495
+ translated = line
496
+ for pattern_str, replacement in _COMMAND_SUBSTITUTIONS:
497
+ pattern = re.compile(pattern_str)
498
+ if callable(replacement):
499
+ translated = pattern.sub(replacement, translated)
500
+ else:
501
+ translated = pattern.sub(replacement, translated)
502
+ return translated
503
+
504
+
505
+ def translate_command_message(message: str, *, locale: str) -> str:
506
+ """翻译命令处理器输出的消息
507
+
508
+ 对于中文 locale,将英文输出翻译为中文;其他语言原样返回。
509
+ 支持多行消息:按行分割,逐行翻译,重新拼接。
510
+
511
+ Args:
512
+ message: 命令处理器的英文输出
513
+ locale: 当前 UI 语言
514
+
515
+ Returns:
516
+ str: 翻译后的消息
517
+ """
518
+ if not message or not _is_zh(locale):
519
+ return message
520
+ lines = message.split("\n")
521
+ translated_lines = [_translate_single_line(line) for line in lines]
522
+ return "\n".join(translated_lines)