@agentunion/kite 1.3.1 → 1.4.0

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 (78) hide show
  1. package/CHANGELOG.md +287 -1
  2. package/cli.js +76 -0
  3. package/extensions/agents/assistant/entry.py +111 -1
  4. package/extensions/agents/assistant/server.py +263 -197
  5. package/extensions/channels/acp_channel/entry.py +111 -1
  6. package/extensions/channels/acp_channel/module.md +23 -22
  7. package/extensions/channels/acp_channel/server.py +263 -197
  8. package/extensions/event_hub_bench/entry.py +107 -1
  9. package/extensions/services/backup/entry.py +408 -72
  10. package/extensions/services/backup/module.md +24 -22
  11. package/extensions/services/model_service/entry.py +255 -71
  12. package/extensions/services/model_service/module.md +21 -22
  13. package/extensions/services/watchdog/entry.py +344 -90
  14. package/extensions/services/watchdog/monitor.py +237 -21
  15. package/extensions/services/web/WEBSOCKET_STATUS.md +143 -0
  16. package/extensions/services/web/config_example.py +35 -0
  17. package/extensions/services/web/config_loader.py +110 -0
  18. package/extensions/services/web/entry.py +114 -26
  19. package/extensions/services/web/module.md +35 -24
  20. package/extensions/services/web/pairing.py +250 -0
  21. package/extensions/services/web/pairing_codes.jsonl +16 -0
  22. package/extensions/services/web/relay.py +643 -0
  23. package/extensions/services/web/relay_config.json5 +67 -0
  24. package/extensions/services/web/routes/routes_management_ws.py +127 -0
  25. package/extensions/services/web/routes/routes_rpc.py +89 -0
  26. package/extensions/services/web/routes/routes_test.py +61 -0
  27. package/extensions/services/web/server.py +445 -99
  28. package/extensions/services/web/static/css/style.css +138 -2
  29. package/extensions/services/web/static/index.html +295 -2
  30. package/extensions/services/web/static/js/app.js +1579 -5
  31. package/extensions/services/web/static/js/kernel-client-example.js +161 -0
  32. package/extensions/services/web/static/js/kernel-client.js +383 -0
  33. package/extensions/services/web/static/js/registry-tests.js +558 -0
  34. package/extensions/services/web/static/js/token-manager.js +175 -0
  35. package/extensions/services/web/static/pairing.html +248 -0
  36. package/extensions/services/web/static/test_registry.html +262 -0
  37. package/extensions/services/web/web_config.json5 +29 -0
  38. package/kernel/entry.py +120 -32
  39. package/kernel/event_hub.py +159 -16
  40. package/kernel/module.md +36 -33
  41. package/kernel/registry_store.py +70 -20
  42. package/kernel/rpc_router.py +134 -57
  43. package/kernel/server.py +292 -15
  44. package/kite_cli/__init__.py +3 -0
  45. package/kite_cli/__main__.py +5 -0
  46. package/kite_cli/commands/__init__.py +1 -0
  47. package/kite_cli/commands/clean.py +101 -0
  48. package/kite_cli/commands/doctor.py +35 -0
  49. package/kite_cli/commands/history.py +111 -0
  50. package/kite_cli/commands/info.py +96 -0
  51. package/kite_cli/commands/install.py +313 -0
  52. package/kite_cli/commands/list.py +143 -0
  53. package/kite_cli/commands/log.py +81 -0
  54. package/kite_cli/commands/rollback.py +88 -0
  55. package/kite_cli/commands/search.py +73 -0
  56. package/kite_cli/commands/uninstall.py +85 -0
  57. package/kite_cli/commands/update.py +118 -0
  58. package/kite_cli/core/__init__.py +1 -0
  59. package/kite_cli/core/checker.py +142 -0
  60. package/kite_cli/core/dependency.py +229 -0
  61. package/kite_cli/core/downloader.py +209 -0
  62. package/kite_cli/core/install_info.py +40 -0
  63. package/kite_cli/core/tool_installer.py +397 -0
  64. package/kite_cli/core/validator.py +78 -0
  65. package/kite_cli/main.py +289 -0
  66. package/kite_cli/utils/__init__.py +1 -0
  67. package/kite_cli/utils/i18n.py +252 -0
  68. package/kite_cli/utils/interactive.py +63 -0
  69. package/kite_cli/utils/operation_log.py +77 -0
  70. package/kite_cli/utils/paths.py +34 -0
  71. package/kite_cli/utils/version.py +308 -0
  72. package/launcher/count_lines.py +34 -0
  73. package/launcher/entry.py +905 -166
  74. package/launcher/logging_setup.py +104 -0
  75. package/launcher/module.md +37 -37
  76. package/launcher/process_manager.py +12 -1
  77. package/package.json +2 -1
  78. package/scripts/plan_manager.py +315 -0
@@ -0,0 +1,289 @@
1
+ #!/usr/bin/env python3
2
+ """Kite CLI 主入口"""
3
+ import sys
4
+ import argparse
5
+ from kite_cli import __version__
6
+ from kite_cli.utils.i18n import t
7
+
8
+
9
+ KNOWN_COMMANDS = ["install", "uninstall", "update", "list", "search", "info", "log", "rollback", "clean", "doctor", "history"]
10
+
11
+
12
+ class SilentArgumentParser(argparse.ArgumentParser):
13
+ """覆盖默认错误处理,输出友好提示"""
14
+ def error(self, message):
15
+ cmd = self.prog.replace("kite ", "").strip()
16
+ if cmd == "kite":
17
+ # 顶层命令错误
18
+ bad = sys.argv[1] if len(sys.argv) > 1 else ""
19
+ print(t('error_unknown_command', cmd=bad))
20
+ print(t('run_help'))
21
+ else:
22
+ # 子命令参数错误
23
+ bad_args = [a for a in sys.argv[2:] if a.startswith("-") and a not in self._option_string_actions]
24
+ if bad_args:
25
+ print(t('error_invalid_args', args=' '.join(bad_args)))
26
+ else:
27
+ print(f"{t('error_invalid_args', args='')}: {message}")
28
+ print(t('run_cmd_help', cmd=cmd))
29
+ sys.exit(1)
30
+
31
+ HELP_TEXT = f"""
32
+ Kite CLI v{__version__} — 模块安装管理工具
33
+
34
+ 用法:
35
+ kite <命令> [参数] [选项]
36
+
37
+ 命令:
38
+ install <source> 安装模块
39
+ uninstall <name> 卸载模块
40
+ update <name> 更新模块(使用安装时记录的来源)
41
+ list 列出已安装的模块
42
+ search <keyword> 搜索可用模块
43
+ info <name> 显示模块详细信息
44
+ log 查看操作日志
45
+ history 查看最近安装的模块
46
+ rollback 回滚最后一次操作
47
+ clean 清理临时文件和缓存
48
+ doctor 检查下载工具状态
49
+
50
+ 全局选项:
51
+ -h, -H, --help 显示此帮助信息
52
+ -v, -V, --version 显示版本号
53
+
54
+ 安装位置 (-l):
55
+ dev 开发环境,安装到 {{KITE_PROJECT}}/extensions/
56
+ local 本地实例,安装到 {{KITE_INSTANCE_DIR}}/extensions/
57
+ global 全局共享,安装到 {{KITE_MODULES}}(默认 ~/.kite/modules/)
58
+
59
+ 来源平台 (-f):
60
+ pypi 从 PyPI 下载(pip download)
61
+ npm 从 npm 下载(npm pack)
62
+ git 从 Git 仓库克隆
63
+ local 从本地路径复制
64
+
65
+ 详细用法:
66
+
67
+ kite install <source> [选项]
68
+ -l, --location <dev|local|global> 安装位置(未指定则交互选择)
69
+ -f, --from <pypi|npm|git|local> 指定平台(未指定则自动检测所有平台)
70
+ -y, --yes 跳过确认提示
71
+ --no-deps 不安装依赖
72
+
73
+ <source> 可以是:
74
+ - 模块名(如 watchdog-plus)
75
+ - 模块名@版本(如 requests@2.28.0)
76
+ - Git URL(如 https://github.com/user/mod.git)
77
+ - 本地路径(如 ./my-module 或 .)
78
+ - 省略(在模块目录下自动安装当前目录)
79
+
80
+ 示例:
81
+ kite install # 在模块目录下安装当前目录
82
+ kite install watchdog-plus # 自动搜索所有平台
83
+ kite install requests@2.28.0 # 安装指定版本
84
+ kite install watchdog-plus -l global # 安装到全局
85
+ kite install watchdog-plus -f pypi -l global # 指定平台和位置
86
+ kite install https://github.com/user/mod.git -f git
87
+ kite install ./my-module -f local -l dev
88
+ kite install . -l global # 安装当前目录到全局
89
+
90
+ kite uninstall <name> [选项]
91
+ -l, --location <dev|local|global> 指定位置(未指定则自动查找)
92
+ --all 卸载所有位置的同名模块
93
+ -y, --yes 跳过确认提示
94
+
95
+ 示例:
96
+ kite uninstall watchdog-plus
97
+ kite uninstall watchdog-plus -l global
98
+ kite uninstall watchdog-plus --all
99
+
100
+ kite update <name> [选项]
101
+ -l, --location <dev|local|global> 指定位置
102
+ --to <version> 更新到指定版本
103
+ --all 更新所有已安装模块
104
+ -y, --yes 跳过确认提示
105
+
106
+ 示例:
107
+ kite update watchdog-plus
108
+ kite update watchdog-plus --to 2.0.0
109
+ kite update --all
110
+
111
+ kite list [选项]
112
+ -l, --location <dev|local|global> 只显示指定位置
113
+ --all 显示所有位置(默认)
114
+ -v, --verbose 显示详细信息(路径、来源)
115
+
116
+ 示例:
117
+ kite list
118
+ kite list -l global -v
119
+
120
+ kite search <keyword> [选项]
121
+ -f, --from <pypi|npm|git> 只在指定平台搜索
122
+
123
+ 示例:
124
+ kite search watchdog
125
+ kite search backup -f pypi
126
+
127
+ kite info <name> [选项]
128
+ -l, --location <dev|local|global> 指定位置
129
+
130
+ 示例:
131
+ kite info watchdog-plus
132
+ """
133
+
134
+
135
+ def print_help():
136
+ print(HELP_TEXT)
137
+
138
+
139
+ def main():
140
+ # 手动处理 -H / -h / --help / -V / --version,在 argparse 之前
141
+ if len(sys.argv) > 1 and sys.argv[1] in ("-H", "-h", "--help", "help"):
142
+ print_help()
143
+ return 0
144
+
145
+ if len(sys.argv) > 1 and sys.argv[1] in ("-V", "-v", "--version", "version"):
146
+ print(f"kite-cli {__version__}")
147
+ return 0
148
+
149
+ parser = SilentArgumentParser(
150
+ prog="kite",
151
+ description="Kite 模块安装管理工具",
152
+ add_help=False # 禁用默认 help,使用自定义
153
+ )
154
+
155
+ parser.add_argument("-h", "-H", "--help", action="store_true", help="显示帮助信息")
156
+ parser.add_argument("-v", "-V", "--version", action="store_true", help="显示版本号")
157
+
158
+ subparsers = parser.add_subparsers(dest="command", parser_class=SilentArgumentParser)
159
+
160
+ # install 命令
161
+ install_parser = subparsers.add_parser("install", help="安装模块", add_help=True)
162
+ install_parser.add_argument("source", nargs="?", help="模块名或下载源(省略则安装当前目录)")
163
+ install_parser.add_argument("-l", "--location", choices=["dev", "local", "global"], help="安装位置")
164
+ install_parser.add_argument("-f", "--from", dest="from_platform", choices=["pypi", "npm", "git", "local"], help="指定平台")
165
+ install_parser.add_argument("-y", "--yes", action="store_true", help="跳过确认")
166
+ install_parser.add_argument("--no-deps", action="store_true", help="不安装依赖")
167
+
168
+ # uninstall 命令
169
+ uninstall_parser = subparsers.add_parser("uninstall", help="卸载模块", add_help=True)
170
+ uninstall_parser.add_argument("name", help="模块名")
171
+ uninstall_parser.add_argument("-l", "--location", choices=["dev", "local", "global"], help="安装位置")
172
+ uninstall_parser.add_argument("--all", action="store_true", help="卸载所有位置")
173
+ uninstall_parser.add_argument("-y", "--yes", action="store_true", help="跳过确认")
174
+
175
+ # list 命令
176
+ list_parser = subparsers.add_parser("list", help="列出已安装模块", add_help=True)
177
+ list_parser.add_argument("-l", "--location", choices=["dev", "local", "global"], help="筛选位置")
178
+ list_parser.add_argument("--all", action="store_true", help="所有位置")
179
+ list_parser.add_argument("-v", "--verbose", action="store_true", help="详细信息")
180
+
181
+ # search 命令
182
+ search_parser = subparsers.add_parser("search", help="搜索可用模块", add_help=True)
183
+ search_parser.add_argument("keyword", help="搜索关键词")
184
+ search_parser.add_argument("-f", "--from", dest="from_platform", choices=["pypi", "npm", "git"], help="指定平台")
185
+
186
+ # update 命令
187
+ update_parser = subparsers.add_parser("update", help="更新模块", add_help=True)
188
+ update_parser.add_argument("name", nargs="?", help="模块名")
189
+ update_parser.add_argument("-l", "--location", choices=["dev", "local", "global"], help="安装位置")
190
+ update_parser.add_argument("--to", dest="to_version", help="更新到指定版本")
191
+ update_parser.add_argument("--all", action="store_true", help="更新所有模块")
192
+ update_parser.add_argument("-y", "--yes", action="store_true", help="跳过确认")
193
+
194
+ # info 命令
195
+ info_parser = subparsers.add_parser("info", help="显示模块详细信息", add_help=True)
196
+ info_parser.add_argument("name", help="模块名")
197
+ info_parser.add_argument("-l", "--location", choices=["dev", "local", "global"], help="指定位置")
198
+
199
+ # log 命令
200
+ log_parser = subparsers.add_parser("log", help="查看操作日志", add_help=True)
201
+ log_parser.add_argument("-n", "--limit", type=int, default=20, help="显示条数(默认 20)")
202
+ log_parser.add_argument("--path", action="store_true", help="显示日志文件路径")
203
+
204
+ # history 命令
205
+ history_parser = subparsers.add_parser("history", help="查看最近安装的模块", add_help=True)
206
+ history_parser.add_argument("-n", "--limit", type=int, default=6, help="显示条数(默认 6)")
207
+ history_parser.add_argument("--all", action="store_true", help="显示所有记录(包括已卸载)")
208
+
209
+ # rollback 命令
210
+ rollback_parser = subparsers.add_parser("rollback", help="回滚最后一次操作", add_help=True)
211
+ rollback_parser.add_argument("-y", "--yes", action="store_true", help="跳过确认")
212
+
213
+ # clean 命令
214
+ clean_parser = subparsers.add_parser("clean", help="清理临时文件和缓存", add_help=True)
215
+ clean_parser.add_argument("--all", action="store_true", help="清理所有模块依赖环境")
216
+ clean_parser.add_argument("-y", "--yes", action="store_true", help="跳过确认")
217
+
218
+ # doctor 命令
219
+ doctor_parser = subparsers.add_parser("doctor", help="检查下载工具状态", add_help=True)
220
+
221
+ args, unknown = parser.parse_known_args()
222
+
223
+ # 处理全局 --help / --version
224
+ if args.help:
225
+ print_help()
226
+ return 0
227
+ if args.version:
228
+ print(f"kite-cli {__version__}")
229
+ return 0
230
+
231
+ # 没有命令 → 显示帮助
232
+ if not args.command:
233
+ # 如果有未知参数,说明用户输入了非法命令
234
+ if unknown:
235
+ bad = " ".join(unknown)
236
+ print(f"错误: 未知命令或参数 '{bad}'")
237
+ print(f"运行 'kite -h' 查看可用命令")
238
+ return 1
239
+ print_help()
240
+ return 0
241
+
242
+ # 子命令有未识别参数
243
+ if unknown:
244
+ bad = " ".join(unknown)
245
+ print(f"错误: 无效参数 '{bad}'")
246
+ print(f"运行 'kite {args.command} --help' 查看用法")
247
+ return 1
248
+
249
+ # 路由到具体命令
250
+ if args.command == "install":
251
+ from kite_cli.commands.install import run_install
252
+ return run_install(args)
253
+ elif args.command == "uninstall":
254
+ from kite_cli.commands.uninstall import run_uninstall
255
+ return run_uninstall(args)
256
+ elif args.command == "list":
257
+ from kite_cli.commands.list import run_list
258
+ return run_list(args)
259
+ elif args.command == "search":
260
+ from kite_cli.commands.search import run_search
261
+ return run_search(args)
262
+ elif args.command == "update":
263
+ from kite_cli.commands.update import run_update
264
+ return run_update(args)
265
+ elif args.command == "info":
266
+ from kite_cli.commands.info import run_info
267
+ return run_info(args)
268
+ elif args.command == "log":
269
+ from kite_cli.commands.log import run_log
270
+ return run_log(args)
271
+ elif args.command == "history":
272
+ from kite_cli.commands.history import run_history
273
+ return run_history(args)
274
+ elif args.command == "rollback":
275
+ from kite_cli.commands.rollback import run_rollback
276
+ return run_rollback(args)
277
+ elif args.command == "clean":
278
+ from kite_cli.commands.clean import run_clean
279
+ return run_clean(args)
280
+ elif args.command == "doctor":
281
+ from kite_cli.commands.doctor import run_doctor
282
+ return run_doctor(args)
283
+ else:
284
+ print(f"未知命令: {args.command}")
285
+ return 1
286
+
287
+
288
+ if __name__ == "__main__":
289
+ sys.exit(main())
@@ -0,0 +1 @@
1
+ """工具函数模块"""
@@ -0,0 +1,252 @@
1
+ """国际化支持 - 根据系统语言自动切换"""
2
+ import os
3
+ import locale
4
+
5
+
6
+ def get_system_language():
7
+ """获取系统语言"""
8
+ try:
9
+ # 尝试从环境变量获取
10
+ lang = os.environ.get('LANG', '')
11
+ if lang:
12
+ return lang.split('.')[0].split('_')[0].lower()
13
+
14
+ # 尝试从 locale 获取
15
+ lang, _ = locale.getdefaultlocale()
16
+ if lang:
17
+ return lang.split('_')[0].lower()
18
+ except Exception:
19
+ pass
20
+
21
+ return 'en'
22
+
23
+
24
+ # 当前语言
25
+ CURRENT_LANG = get_system_language()
26
+
27
+
28
+ # 翻译字典
29
+ TRANSLATIONS = {
30
+ 'en': {
31
+ 'help_title': 'Kite CLI v{version} — Module Installation Manager',
32
+ 'usage': 'Usage',
33
+ 'commands': 'Commands',
34
+ 'global_options': 'Global Options',
35
+ 'install_locations': 'Install Locations',
36
+ 'source_platforms': 'Source Platforms',
37
+ 'detailed_usage': 'Detailed Usage',
38
+ 'examples': 'Examples',
39
+ 'show_help': 'Show this help message',
40
+ 'show_version': 'Show version number',
41
+ 'error_unknown_command': "Error: Unknown command '{cmd}'",
42
+ 'error_invalid_args': "Error: Invalid argument '{args}'",
43
+ 'run_help': "Run 'kite -h' to see available commands",
44
+ 'run_cmd_help': "Run 'kite {cmd} --help' for usage",
45
+ 'searching_module': '[Search] Searching for module: {name}',
46
+ 'module_not_found': '[Error] Module not found: {name}',
47
+ 'select_source': '[Select] Selected source: {platform} - {name}',
48
+ 'downloading': '[Download] Downloading...',
49
+ 'download_complete': '[Done] Download complete: {path}',
50
+ 'download_failed': '[Error] Download failed',
51
+ 'validating': '[Validate] Validating module.md...',
52
+ 'validation_failed': '[Error] Validation failed: {error}',
53
+ 'validation_passed': '[Done] Validation passed: {name} v{version}',
54
+ 'installing_deps': '[Install] Installing dependencies...',
55
+ 'deps_failed': '[Error] Dependency installation failed',
56
+ 'installing_to': '[Install] Installing to: {path}',
57
+ 'install_complete': '[Done] Installation complete!',
58
+ 'restart_hint': '[Info] Restart Kite to load the new module: python main.py',
59
+ 'uninstalling': '[Uninstall] Uninstalling module: {name}',
60
+ 'uninstalled': '[Done] Uninstalled: {location} - {path}',
61
+ 'uninstall_complete': '[Done] Uninstall complete! Uninstalled {count} location(s)',
62
+ 'uninstall_none': '[Error] No modules uninstalled',
63
+ 'installed_modules': '[List] Installed modules:',
64
+ 'total_modules': 'Total {count} module(s)',
65
+ 'no_modules': ' (No installed modules)',
66
+ 'location_dev': 'Development',
67
+ 'location_local': 'Local Instance',
68
+ 'location_global': 'Global Shared',
69
+ 'module_info': '[Info] Module info: {name}',
70
+ 'searching_for': '[Search] Searching for: {keyword}',
71
+ 'found_results': 'Found {count} result(s)',
72
+ 'no_results': ' No modules found',
73
+ 'updating_module': '[Update] Updating module: {name}',
74
+ 'reinstalling': '[Install] Reinstalling {name}...',
75
+ 'skip_deps_warning': '[Warning] Skipping dependency installation (--no-deps)',
76
+ 'no_deps': '[Info] No dependencies to install',
77
+ 'reserved_name_error': "[Error] Cannot install '{name}' as a module",
78
+ 'reserved_name_hint': "[Info] '{name}' is a reserved name for Kite framework",
79
+ 'update_framework_hint': "[Info] To update Kite framework, use: npm update -g @kite/cli",
80
+ 'category_kernel': 'Kernel Modules',
81
+ 'category_builtin': 'Built-in Modules',
82
+ 'category_external': 'External Modules',
83
+ 'type_kernel': 'Kernel',
84
+ 'type_infrastructure': 'Infrastructure',
85
+ 'type_channel': 'Channel',
86
+ 'type_agent': 'Agent',
87
+ 'type_service': 'Service',
88
+ 'type_tool': 'Tool',
89
+ 'stats_breakdown': 'Kernel: {kernel} | Built-in: {builtin} | External: {external}',
90
+ 'info_location_dev': 'Development Environment',
91
+ 'info_location_local': 'Local Instance',
92
+ 'info_location_global': 'Global Shared',
93
+ 'info_path': 'Path',
94
+ 'info_name': 'Name',
95
+ 'info_display_name': 'Display Name',
96
+ 'info_version': 'Version',
97
+ 'info_type': 'Type',
98
+ 'info_runtime': 'Runtime',
99
+ 'info_entry': 'Entry',
100
+ 'info_state': 'State',
101
+ 'info_dependencies': 'Dependencies',
102
+ 'info_install_info': 'Installation Info',
103
+ 'info_source': 'Source',
104
+ 'info_package': 'Package',
105
+ 'info_url': 'URL',
106
+ 'info_installed_at': 'Installed At',
107
+ 'info_no_module_md': '[Warning] module.md not found',
108
+ 'info_parse_failed': '[Warning] Failed to parse module.md',
109
+ 'search_pypi': 'PyPI',
110
+ 'search_npm': 'npm',
111
+ 'search_git': 'Git / GitHub',
112
+ 'search_latest_version': 'Latest Version',
113
+ 'search_available_versions': 'Available Versions',
114
+ 'search_version': 'Version',
115
+ 'update_not_implemented': '[Warning] Update all modules feature not implemented yet',
116
+ 'update_specify_name': '[Error] Please specify module name',
117
+ 'update_not_found': '[Error] Module not found: {name}',
118
+ 'update_no_install_info': '[Error] Installation info not found, cannot update',
119
+ 'update_manual_reinstall': '[Info] Please reinstall manually: kite install {name} -l {location}',
120
+ 'update_incomplete_info': '[Error] Installation info incomplete, cannot update',
121
+ 'update_local_no_auto': '[Error] Locally installed modules cannot be auto-updated',
122
+ 'update_unknown_source': '[Error] Unknown source type: {type}',
123
+ 'update_confirm': 'Confirm update {name} (source: {source})?',
124
+ 'update_cancelled': '[Cancelled] Cancelled',
125
+ 'update_failed': '[Error] Update failed: {error}',
126
+ 'tool_installing': '[Install] {tool} not installed, installing...',
127
+ 'tool_install_success': '[Done] {tool} installed successfully',
128
+ 'tool_install_failed': '[Error] {tool} installation failed',
129
+ 'tool_manual_install': '[Info] Please install {tool} manually',
130
+ 'tool_install_url': '[Info] Visit: {url}',
131
+ 'tool_install_cmd': '[Info] Or use: {cmd}',
132
+ },
133
+ 'zh': {
134
+ 'help_title': 'Kite CLI v{version} — 模块安装管理工具',
135
+ 'usage': '用法',
136
+ 'commands': '命令',
137
+ 'global_options': '全局选项',
138
+ 'install_locations': '安装位置',
139
+ 'source_platforms': '来源平台',
140
+ 'detailed_usage': '详细用法',
141
+ 'examples': '示例',
142
+ 'show_help': '显示此帮助信息',
143
+ 'show_version': '显示版本号',
144
+ 'error_unknown_command': "错误: 未知命令 '{cmd}'",
145
+ 'error_invalid_args': "错误: 无效参数 '{args}'",
146
+ 'run_help': "运行 'kite -h' 查看可用命令",
147
+ 'run_cmd_help': "运行 'kite {cmd} --help' 查看用法",
148
+ 'searching_module': '[搜索] 正在搜索模块: {name}',
149
+ 'module_not_found': '[错误] 未找到模块: {name}',
150
+ 'select_source': '[选择] 选择来源: {platform} - {name}',
151
+ 'downloading': '[下载] 正在下载...',
152
+ 'download_complete': '[完成] 下载完成: {path}',
153
+ 'download_failed': '[错误] 下载失败',
154
+ 'validating': '[验证] 验证 module.md...',
155
+ 'validation_failed': '[错误] 验证失败: {error}',
156
+ 'validation_passed': '[完成] 验证通过: {name} v{version}',
157
+ 'installing_deps': '[安装] 安装依赖...',
158
+ 'deps_failed': '[错误] 依赖安装失败',
159
+ 'installing_to': '[安装] 安装到: {path}',
160
+ 'install_complete': '[完成] 安装完成!',
161
+ 'restart_hint': '[提示] 重启 Kite 以加载新模块: python main.py',
162
+ 'uninstalling': '[卸载] 卸载模块: {name}',
163
+ 'uninstalled': '[完成] 已卸载: {location} - {path}',
164
+ 'uninstall_complete': '[完成] 卸载完成!共卸载 {count} 个位置',
165
+ 'uninstall_none': '[错误] 未卸载任何模块',
166
+ 'installed_modules': '[列表] 已安装的模块:',
167
+ 'total_modules': '共 {count} 个模块',
168
+ 'no_modules': ' (无已安装模块)',
169
+ 'location_dev': '开发环境',
170
+ 'location_local': '本地实例',
171
+ 'location_global': '全局共享',
172
+ 'module_info': '[信息] 模块信息: {name}',
173
+ 'searching_for': '[搜索] 搜索模块: {keyword}',
174
+ 'found_results': '共找到 {count} 个结果',
175
+ 'no_results': ' 未找到相关模块',
176
+ 'updating_module': '[更新] 更新模块: {name}',
177
+ 'reinstalling': '[安装] 重新安装 {name}...',
178
+ 'skip_deps_warning': '[警告] 跳过依赖安装 (--no-deps)',
179
+ 'no_deps': '[提示] 无依赖需要安装',
180
+ 'reserved_name_error': "[错误] 不能将 '{name}' 作为模块安装",
181
+ 'reserved_name_hint': "[提示] '{name}' 是 Kite 框架的保留名称",
182
+ 'update_framework_hint': "[提示] 如需更新 Kite 框架,请使用: npm update -g @kite/cli",
183
+ 'category_kernel': '内核模块',
184
+ 'category_builtin': '内置模块',
185
+ 'category_external': '外置模块',
186
+ 'type_kernel': '核心',
187
+ 'type_infrastructure': '基础',
188
+ 'type_channel': '通道',
189
+ 'type_agent': '代理',
190
+ 'type_service': '服务',
191
+ 'type_tool': '工具',
192
+ 'stats_breakdown': '内核: {kernel} | 内置: {builtin} | 外置: {external}',
193
+ 'info_location_dev': '开发环境',
194
+ 'info_location_local': '本地实例',
195
+ 'info_location_global': '全局共享',
196
+ 'info_path': '路径',
197
+ 'info_name': '名称',
198
+ 'info_display_name': '显示名',
199
+ 'info_version': '版本',
200
+ 'info_type': '类型',
201
+ 'info_runtime': '运行时',
202
+ 'info_entry': '入口',
203
+ 'info_state': '状态',
204
+ 'info_dependencies': '依赖',
205
+ 'info_install_info': '安装信息',
206
+ 'info_source': '来源',
207
+ 'info_package': '包名',
208
+ 'info_url': 'URL',
209
+ 'info_installed_at': '安装时间',
210
+ 'info_no_module_md': '[警告] 未找到 module.md',
211
+ 'info_parse_failed': '[警告] 无法解析 module.md',
212
+ 'search_pypi': 'PyPI',
213
+ 'search_npm': 'npm',
214
+ 'search_git': 'Git / GitHub',
215
+ 'search_latest_version': '最新版本',
216
+ 'search_available_versions': '可用版本',
217
+ 'search_version': '版本',
218
+ 'update_not_implemented': '[警告] 更新所有模块功能尚未实现',
219
+ 'update_specify_name': '[错误] 请指定模块名',
220
+ 'update_not_found': '[错误] 未找到模块: {name}',
221
+ 'update_no_install_info': '[错误] 未找到安装信息,无法更新',
222
+ 'update_manual_reinstall': '[提示] 请手动重新安装: kite install {name} -l {location}',
223
+ 'update_incomplete_info': '[错误] 安装信息不完整,无法更新',
224
+ 'update_local_no_auto': '[错误] 本地安装的模块无法自动更新',
225
+ 'update_unknown_source': '[错误] 未知的来源类型: {type}',
226
+ 'update_confirm': '确认更新 {name} (来源: {source})?',
227
+ 'update_cancelled': '[取消] 已取消',
228
+ 'update_failed': '[错误] 更新失败: {error}',
229
+ 'tool_installing': '[安装] {tool} 未安装,正在安装...',
230
+ 'tool_install_success': '[完成] {tool} 安装成功',
231
+ 'tool_install_failed': '[错误] {tool} 安装失败',
232
+ 'tool_manual_install': '[提示] 请手动安装 {tool}',
233
+ 'tool_install_url': '[提示] 访问: {url}',
234
+ 'tool_install_cmd': '[提示] 或使用: {cmd}',
235
+ }
236
+ }
237
+
238
+
239
+ def t(key, **kwargs):
240
+ """翻译函数"""
241
+ lang = CURRENT_LANG if CURRENT_LANG in TRANSLATIONS else 'en'
242
+ text = TRANSLATIONS[lang].get(key, TRANSLATIONS['en'].get(key, key))
243
+ if kwargs:
244
+ return text.format(**kwargs)
245
+ return text
246
+
247
+
248
+ def set_language(lang):
249
+ """手动设置语言"""
250
+ global CURRENT_LANG
251
+ if lang in TRANSLATIONS:
252
+ CURRENT_LANG = lang
@@ -0,0 +1,63 @@
1
+ """交互式问答工具"""
2
+
3
+
4
+ def select_source(candidates: list) -> dict:
5
+ """让用户选择来源"""
6
+ print("\n找到多个来源:")
7
+ for i, candidate in enumerate(candidates, 1):
8
+ platform = candidate["platform"]
9
+ name = candidate.get("name", "")
10
+ version = candidate.get("latest", candidate.get("version", ""))
11
+ desc = candidate.get("description", "")
12
+
13
+ if platform == "pypi":
14
+ print(f" [{i}] PyPI: {name} v{version}")
15
+ elif platform == "npm":
16
+ print(f" [{i}] npm: {name} v{version}")
17
+ elif platform == "git":
18
+ full_name = candidate.get("full_name", name)
19
+ print(f" [{i}] Git: {full_name}")
20
+ if desc:
21
+ print(f" {desc}")
22
+ elif platform == "local":
23
+ print(f" [{i}] 本地: {candidate.get('path', '')}")
24
+
25
+ while True:
26
+ try:
27
+ choice = input("\n? 选择来源 [1]: ").strip() or "1"
28
+ index = int(choice) - 1
29
+ if 0 <= index < len(candidates):
30
+ return candidates[index]
31
+ print("无效选择,请重试")
32
+ except (ValueError, KeyboardInterrupt):
33
+ return None
34
+
35
+
36
+ def select_location() -> str:
37
+ """让用户选择安装位置"""
38
+ print("\n? 选择安装位置:")
39
+ print(" [1] 开发环境 (Kite/extensions/) — 用于模块开发")
40
+ print(" [2] 本地实例 (~/.kite/workspace/Kite/extensions/) — 当前实例专用")
41
+ print(" [3] 全局共享 (~/.kite/modules/) — 所有实例共享")
42
+
43
+ while True:
44
+ try:
45
+ choice = input("\n选择 [3]: ").strip() or "3"
46
+ if choice == "1":
47
+ return "dev"
48
+ elif choice == "2":
49
+ return "local"
50
+ elif choice == "3":
51
+ return "global"
52
+ print("无效选择,请重试")
53
+ except KeyboardInterrupt:
54
+ return None
55
+
56
+
57
+ def confirm_action(message: str) -> bool:
58
+ """确认操作"""
59
+ try:
60
+ answer = input(f"{message} [y/N]: ").strip().lower()
61
+ return answer in ("y", "yes")
62
+ except KeyboardInterrupt:
63
+ return False