@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.
- package/CHANGELOG.md +287 -1
- package/cli.js +76 -0
- package/extensions/agents/assistant/entry.py +111 -1
- package/extensions/agents/assistant/server.py +263 -197
- package/extensions/channels/acp_channel/entry.py +111 -1
- package/extensions/channels/acp_channel/module.md +23 -22
- package/extensions/channels/acp_channel/server.py +263 -197
- package/extensions/event_hub_bench/entry.py +107 -1
- package/extensions/services/backup/entry.py +408 -72
- package/extensions/services/backup/module.md +24 -22
- package/extensions/services/model_service/entry.py +255 -71
- package/extensions/services/model_service/module.md +21 -22
- package/extensions/services/watchdog/entry.py +344 -90
- package/extensions/services/watchdog/monitor.py +237 -21
- package/extensions/services/web/WEBSOCKET_STATUS.md +143 -0
- package/extensions/services/web/config_example.py +35 -0
- package/extensions/services/web/config_loader.py +110 -0
- package/extensions/services/web/entry.py +114 -26
- package/extensions/services/web/module.md +35 -24
- package/extensions/services/web/pairing.py +250 -0
- package/extensions/services/web/pairing_codes.jsonl +16 -0
- package/extensions/services/web/relay.py +643 -0
- package/extensions/services/web/relay_config.json5 +67 -0
- package/extensions/services/web/routes/routes_management_ws.py +127 -0
- package/extensions/services/web/routes/routes_rpc.py +89 -0
- package/extensions/services/web/routes/routes_test.py +61 -0
- package/extensions/services/web/server.py +445 -99
- package/extensions/services/web/static/css/style.css +138 -2
- package/extensions/services/web/static/index.html +295 -2
- package/extensions/services/web/static/js/app.js +1579 -5
- package/extensions/services/web/static/js/kernel-client-example.js +161 -0
- package/extensions/services/web/static/js/kernel-client.js +383 -0
- package/extensions/services/web/static/js/registry-tests.js +558 -0
- package/extensions/services/web/static/js/token-manager.js +175 -0
- package/extensions/services/web/static/pairing.html +248 -0
- package/extensions/services/web/static/test_registry.html +262 -0
- package/extensions/services/web/web_config.json5 +29 -0
- package/kernel/entry.py +120 -32
- package/kernel/event_hub.py +159 -16
- package/kernel/module.md +36 -33
- package/kernel/registry_store.py +70 -20
- package/kernel/rpc_router.py +134 -57
- package/kernel/server.py +292 -15
- package/kite_cli/__init__.py +3 -0
- package/kite_cli/__main__.py +5 -0
- package/kite_cli/commands/__init__.py +1 -0
- package/kite_cli/commands/clean.py +101 -0
- package/kite_cli/commands/doctor.py +35 -0
- package/kite_cli/commands/history.py +111 -0
- package/kite_cli/commands/info.py +96 -0
- package/kite_cli/commands/install.py +313 -0
- package/kite_cli/commands/list.py +143 -0
- package/kite_cli/commands/log.py +81 -0
- package/kite_cli/commands/rollback.py +88 -0
- package/kite_cli/commands/search.py +73 -0
- package/kite_cli/commands/uninstall.py +85 -0
- package/kite_cli/commands/update.py +118 -0
- package/kite_cli/core/__init__.py +1 -0
- package/kite_cli/core/checker.py +142 -0
- package/kite_cli/core/dependency.py +229 -0
- package/kite_cli/core/downloader.py +209 -0
- package/kite_cli/core/install_info.py +40 -0
- package/kite_cli/core/tool_installer.py +397 -0
- package/kite_cli/core/validator.py +78 -0
- package/kite_cli/main.py +289 -0
- package/kite_cli/utils/__init__.py +1 -0
- package/kite_cli/utils/i18n.py +252 -0
- package/kite_cli/utils/interactive.py +63 -0
- package/kite_cli/utils/operation_log.py +77 -0
- package/kite_cli/utils/paths.py +34 -0
- package/kite_cli/utils/version.py +308 -0
- package/launcher/count_lines.py +34 -0
- package/launcher/entry.py +905 -166
- package/launcher/logging_setup.py +104 -0
- package/launcher/module.md +37 -37
- package/launcher/process_manager.py +12 -1
- package/package.json +2 -1
- package/scripts/plan_manager.py +315 -0
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
"""依赖管理 - 安装 Python/npm/Kite 模块依赖"""
|
|
2
|
+
import subprocess
|
|
3
|
+
import sys
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from kite_cli.core.tool_installer import ToolInstaller
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class DependencyInstaller:
|
|
9
|
+
"""依赖安装器"""
|
|
10
|
+
|
|
11
|
+
@staticmethod
|
|
12
|
+
def install_python_deps(module_dir: Path, packages: list) -> bool:
|
|
13
|
+
"""安装 Python 依赖到模块内的 .venv"""
|
|
14
|
+
if not packages:
|
|
15
|
+
return True
|
|
16
|
+
|
|
17
|
+
# 确保 Python 和 pip 已安装
|
|
18
|
+
if not ToolInstaller.ensure_tool("python"):
|
|
19
|
+
print(" [Error] Python 未安装且自动安装失败")
|
|
20
|
+
return False
|
|
21
|
+
if not ToolInstaller.ensure_tool("pip"):
|
|
22
|
+
print(" [Error] pip 未安装且自动安装失败")
|
|
23
|
+
return False
|
|
24
|
+
|
|
25
|
+
print(f"[Install] 安装 Python 依赖: {', '.join(packages)}")
|
|
26
|
+
|
|
27
|
+
venv_dir = module_dir / ".venv"
|
|
28
|
+
|
|
29
|
+
try:
|
|
30
|
+
# 创建虚拟环境
|
|
31
|
+
if not venv_dir.exists():
|
|
32
|
+
print(" 创建虚拟环境...")
|
|
33
|
+
result = subprocess.run(
|
|
34
|
+
[sys.executable, "-m", "venv", str(venv_dir)],
|
|
35
|
+
capture_output=True,
|
|
36
|
+
text=True,
|
|
37
|
+
timeout=60
|
|
38
|
+
)
|
|
39
|
+
if result.returncode != 0:
|
|
40
|
+
print(f" [Error] 创建虚拟环境失败: {result.stderr}")
|
|
41
|
+
return False
|
|
42
|
+
|
|
43
|
+
# 确定 pip 路径
|
|
44
|
+
if sys.platform == "win32":
|
|
45
|
+
pip_path = venv_dir / "Scripts" / "pip.exe"
|
|
46
|
+
else:
|
|
47
|
+
pip_path = venv_dir / "bin" / "pip"
|
|
48
|
+
|
|
49
|
+
# 安装依赖
|
|
50
|
+
print(" 安装包...")
|
|
51
|
+
result = subprocess.run(
|
|
52
|
+
[str(pip_path), "install"] + packages,
|
|
53
|
+
capture_output=True,
|
|
54
|
+
text=True,
|
|
55
|
+
timeout=300
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
if result.returncode != 0:
|
|
59
|
+
print(f" [Error] 安装失败: {result.stderr}")
|
|
60
|
+
return False
|
|
61
|
+
|
|
62
|
+
print(" [Done] Python 依赖安装完成")
|
|
63
|
+
return True
|
|
64
|
+
|
|
65
|
+
except Exception as e:
|
|
66
|
+
print(f" [Error] 安装失败: {e}")
|
|
67
|
+
return False
|
|
68
|
+
|
|
69
|
+
@staticmethod
|
|
70
|
+
def install_npm_deps(module_dir: Path, packages: list) -> bool:
|
|
71
|
+
"""安装 npm 依赖到模块内的 node_modules"""
|
|
72
|
+
if not packages:
|
|
73
|
+
return True
|
|
74
|
+
|
|
75
|
+
# 确保 npm 已安装
|
|
76
|
+
if not ToolInstaller.ensure_tool("npm"):
|
|
77
|
+
print(" [Error] npm 未安装且自动安装失败")
|
|
78
|
+
return False
|
|
79
|
+
|
|
80
|
+
print(f"[Install] 安装 npm 依赖: {', '.join(packages)}")
|
|
81
|
+
|
|
82
|
+
try:
|
|
83
|
+
# 检查是否有 package.json
|
|
84
|
+
package_json = module_dir / "package.json"
|
|
85
|
+
if not package_json.exists():
|
|
86
|
+
# 创建基础 package.json
|
|
87
|
+
import json
|
|
88
|
+
with open(package_json, "w") as f:
|
|
89
|
+
json.dump({
|
|
90
|
+
"name": module_dir.name,
|
|
91
|
+
"version": "1.0.0",
|
|
92
|
+
"dependencies": {}
|
|
93
|
+
}, f, indent=2)
|
|
94
|
+
|
|
95
|
+
# 安装依赖
|
|
96
|
+
result = subprocess.run(
|
|
97
|
+
["npm", "install"] + packages,
|
|
98
|
+
cwd=str(module_dir),
|
|
99
|
+
capture_output=True,
|
|
100
|
+
text=True,
|
|
101
|
+
timeout=300
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
if result.returncode != 0:
|
|
105
|
+
print(f" [Error] 安装失败: {result.stderr}")
|
|
106
|
+
return False
|
|
107
|
+
|
|
108
|
+
print(" [Done] npm 依赖安装完成")
|
|
109
|
+
return True
|
|
110
|
+
|
|
111
|
+
except Exception as e:
|
|
112
|
+
print(f" [Error] 安装失败: {e}")
|
|
113
|
+
return False
|
|
114
|
+
|
|
115
|
+
@staticmethod
|
|
116
|
+
def install_git_deps(module_dir: Path, repos: list) -> bool:
|
|
117
|
+
"""安装 Git 依赖到模块内的 .git_deps"""
|
|
118
|
+
if not repos:
|
|
119
|
+
return True
|
|
120
|
+
|
|
121
|
+
# 确保 git 已安装
|
|
122
|
+
if not ToolInstaller.ensure_tool("git"):
|
|
123
|
+
print(" [Error] git 未安装且自动安装失败")
|
|
124
|
+
return False
|
|
125
|
+
|
|
126
|
+
print(f"[Install] 安装 Git 依赖: {', '.join(repos)}")
|
|
127
|
+
|
|
128
|
+
git_deps_dir = module_dir / ".git_deps"
|
|
129
|
+
git_deps_dir.mkdir(exist_ok=True)
|
|
130
|
+
|
|
131
|
+
try:
|
|
132
|
+
for repo_url in repos:
|
|
133
|
+
# 提取仓库名
|
|
134
|
+
repo_name = repo_url.rstrip('/').split('/')[-1]
|
|
135
|
+
if repo_name.endswith('.git'):
|
|
136
|
+
repo_name = repo_name[:-4]
|
|
137
|
+
|
|
138
|
+
target_dir = git_deps_dir / repo_name
|
|
139
|
+
|
|
140
|
+
# 如果已存在,跳过
|
|
141
|
+
if target_dir.exists():
|
|
142
|
+
print(f" [Skip] {repo_name} 已存在")
|
|
143
|
+
continue
|
|
144
|
+
|
|
145
|
+
print(f" 克隆 {repo_name}...")
|
|
146
|
+
result = subprocess.run(
|
|
147
|
+
["git", "clone", repo_url, str(target_dir)],
|
|
148
|
+
capture_output=True,
|
|
149
|
+
text=True,
|
|
150
|
+
timeout=120
|
|
151
|
+
)
|
|
152
|
+
|
|
153
|
+
if result.returncode != 0:
|
|
154
|
+
print(f" [Error] 克隆失败: {result.stderr}")
|
|
155
|
+
return False
|
|
156
|
+
|
|
157
|
+
print(" [Done] Git 依赖安装完成")
|
|
158
|
+
return True
|
|
159
|
+
|
|
160
|
+
except FileNotFoundError:
|
|
161
|
+
print(" [Error] git 命令未找到,请先安装 Git")
|
|
162
|
+
return False
|
|
163
|
+
except Exception as e:
|
|
164
|
+
print(f" [Error] 安装失败: {e}")
|
|
165
|
+
return False
|
|
166
|
+
|
|
167
|
+
@staticmethod
|
|
168
|
+
def install_kite_deps(modules: list, location: str) -> bool:
|
|
169
|
+
"""递归安装 Kite 模块依赖"""
|
|
170
|
+
if not modules:
|
|
171
|
+
return True
|
|
172
|
+
|
|
173
|
+
print(f"[Install] 安装 Kite 模块依赖: {', '.join(modules)}")
|
|
174
|
+
|
|
175
|
+
# 这里需要递归调用 kite install
|
|
176
|
+
# 为了避免循环导入,使用 subprocess
|
|
177
|
+
for module in modules:
|
|
178
|
+
print(f" 安装 {module}...")
|
|
179
|
+
try:
|
|
180
|
+
result = subprocess.run(
|
|
181
|
+
[sys.executable, "-m", "kite_cli", "install", module, "-l", location, "-y"],
|
|
182
|
+
capture_output=True,
|
|
183
|
+
text=True,
|
|
184
|
+
timeout=300
|
|
185
|
+
)
|
|
186
|
+
if result.returncode != 0:
|
|
187
|
+
print(f" [Error] 安装 {module} 失败")
|
|
188
|
+
return False
|
|
189
|
+
except Exception as e:
|
|
190
|
+
print(f" [Error] 安装 {module} 失败: {e}")
|
|
191
|
+
return False
|
|
192
|
+
|
|
193
|
+
print(" [Done] Kite 模块依赖安装完成")
|
|
194
|
+
return True
|
|
195
|
+
|
|
196
|
+
@classmethod
|
|
197
|
+
def install_all_deps(cls, module_dir: Path, module_data: dict, location: str, skip_deps: bool = False) -> bool:
|
|
198
|
+
"""安装所有依赖"""
|
|
199
|
+
if skip_deps:
|
|
200
|
+
print("[Warning] 跳过依赖安装 (--no-deps)")
|
|
201
|
+
return True
|
|
202
|
+
|
|
203
|
+
# 从 module.md 读取依赖
|
|
204
|
+
dependencies = module_data.get("dependencies", {})
|
|
205
|
+
if not dependencies:
|
|
206
|
+
print("[Info] 无依赖需要安装")
|
|
207
|
+
return True
|
|
208
|
+
|
|
209
|
+
# Python 依赖
|
|
210
|
+
python_deps = dependencies.get("python", [])
|
|
211
|
+
if python_deps and not cls.install_python_deps(module_dir, python_deps):
|
|
212
|
+
return False
|
|
213
|
+
|
|
214
|
+
# npm 依赖
|
|
215
|
+
npm_deps = dependencies.get("npm", [])
|
|
216
|
+
if npm_deps and not cls.install_npm_deps(module_dir, npm_deps):
|
|
217
|
+
return False
|
|
218
|
+
|
|
219
|
+
# Git 依赖
|
|
220
|
+
git_deps = dependencies.get("git", [])
|
|
221
|
+
if git_deps and not cls.install_git_deps(module_dir, git_deps):
|
|
222
|
+
return False
|
|
223
|
+
|
|
224
|
+
# Kite 模块依赖
|
|
225
|
+
kite_deps = dependencies.get("kite", [])
|
|
226
|
+
if kite_deps and not cls.install_kite_deps(kite_deps, location):
|
|
227
|
+
return False
|
|
228
|
+
|
|
229
|
+
return True
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
"""下载器 - 从各平台下载模块(改进版,带详细错误提示)"""
|
|
2
|
+
import subprocess
|
|
3
|
+
import tempfile
|
|
4
|
+
import shutil
|
|
5
|
+
import zipfile
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from typing import Optional, Tuple
|
|
8
|
+
from kite_cli.core.tool_installer import ToolInstaller
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class DownloadError(Exception):
|
|
12
|
+
"""下载错误"""
|
|
13
|
+
pass
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class Downloader:
|
|
17
|
+
"""从各平台下载模块"""
|
|
18
|
+
|
|
19
|
+
@staticmethod
|
|
20
|
+
def download_pypi(name: str, dest: Path, version: str = None) -> Tuple[Optional[Path], Optional[str]]:
|
|
21
|
+
"""
|
|
22
|
+
从 PyPI 下载包
|
|
23
|
+
Args:
|
|
24
|
+
name: 包名
|
|
25
|
+
dest: 目标目录
|
|
26
|
+
version: 版本号(可选),如 "1.2.0"
|
|
27
|
+
返回: (下载路径, 错误信息)
|
|
28
|
+
"""
|
|
29
|
+
# 确保 pip 已安装
|
|
30
|
+
if not ToolInstaller.ensure_tool("pip"):
|
|
31
|
+
return None, "pip 未安装且自动安装失败,请手动安装 Python 和 pip"
|
|
32
|
+
|
|
33
|
+
# 构建包名(带版本)
|
|
34
|
+
package_spec = f"{name}=={version}" if version else name
|
|
35
|
+
|
|
36
|
+
try:
|
|
37
|
+
dest.mkdir(parents=True, exist_ok=True)
|
|
38
|
+
result = subprocess.run(
|
|
39
|
+
["pip", "download", package_spec, "--dest", str(dest), "--no-deps"],
|
|
40
|
+
capture_output=True,
|
|
41
|
+
text=True,
|
|
42
|
+
timeout=60
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
if result.returncode != 0:
|
|
46
|
+
# pip 命令执行失败
|
|
47
|
+
error_msg = result.stderr.strip() if result.stderr else result.stdout.strip()
|
|
48
|
+
if "Could not find" in error_msg or "No matching distribution" in error_msg:
|
|
49
|
+
return None, f"PyPI 上未找到包 '{name}'"
|
|
50
|
+
elif "Network" in error_msg or "timeout" in error_msg.lower():
|
|
51
|
+
return None, f"网络错误: 无法连接到 PyPI"
|
|
52
|
+
else:
|
|
53
|
+
return None, f"pip 下载失败: {error_msg[:200]}"
|
|
54
|
+
|
|
55
|
+
# 查找下载的文件
|
|
56
|
+
files = list(dest.glob("*"))
|
|
57
|
+
if not files:
|
|
58
|
+
return None, "下载成功但未找到文件"
|
|
59
|
+
|
|
60
|
+
# 解压(.whl 或 .tar.gz)
|
|
61
|
+
downloaded_file = files[0]
|
|
62
|
+
extract_dir = dest / "extracted"
|
|
63
|
+
extract_dir.mkdir(exist_ok=True)
|
|
64
|
+
|
|
65
|
+
try:
|
|
66
|
+
# .whl 文件是 zip 格式
|
|
67
|
+
if downloaded_file.suffix == '.whl':
|
|
68
|
+
with zipfile.ZipFile(downloaded_file, 'r') as zip_ref:
|
|
69
|
+
zip_ref.extractall(extract_dir)
|
|
70
|
+
else:
|
|
71
|
+
shutil.unpack_archive(downloaded_file, extract_dir)
|
|
72
|
+
return extract_dir, None
|
|
73
|
+
except Exception as e:
|
|
74
|
+
return None, f"解压失败: {str(e)}"
|
|
75
|
+
|
|
76
|
+
except FileNotFoundError:
|
|
77
|
+
return None, "pip 命令未找到,请先安装 Python 和 pip"
|
|
78
|
+
except subprocess.TimeoutExpired:
|
|
79
|
+
return None, "下载超时(60秒),请检查网络连接"
|
|
80
|
+
except Exception as e:
|
|
81
|
+
return None, f"未知错误: {str(e)}"
|
|
82
|
+
|
|
83
|
+
@staticmethod
|
|
84
|
+
def download_npm(name: str, dest: Path, version: str = None) -> Tuple[Optional[Path], Optional[str]]:
|
|
85
|
+
"""
|
|
86
|
+
从 npm 下载包
|
|
87
|
+
Args:
|
|
88
|
+
name: 包名
|
|
89
|
+
dest: 目标目录
|
|
90
|
+
version: 版本号(可选),如 "1.2.0"
|
|
91
|
+
返回: (下载路径, 错误信息)
|
|
92
|
+
"""
|
|
93
|
+
# 确保 npm 已安装
|
|
94
|
+
if not ToolInstaller.ensure_tool("npm"):
|
|
95
|
+
return None, "npm 未安装且自动安装失败,请手动安装 Node.js 和 npm"
|
|
96
|
+
|
|
97
|
+
# 构建包名(带版本)
|
|
98
|
+
package_spec = f"{name}@{version}" if version else name
|
|
99
|
+
|
|
100
|
+
try:
|
|
101
|
+
dest.mkdir(parents=True, exist_ok=True)
|
|
102
|
+
result = subprocess.run(
|
|
103
|
+
["npm", "pack", package_spec, "--pack-destination", str(dest)],
|
|
104
|
+
capture_output=True,
|
|
105
|
+
text=True,
|
|
106
|
+
timeout=60
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
if result.returncode != 0:
|
|
110
|
+
error_msg = result.stderr.strip() if result.stderr else result.stdout.strip()
|
|
111
|
+
if "404" in error_msg or "Not Found" in error_msg:
|
|
112
|
+
return None, f"npm 上未找到包 '{name}'"
|
|
113
|
+
elif "network" in error_msg.lower() or "ETIMEDOUT" in error_msg:
|
|
114
|
+
return None, "网络错误: 无法连接到 npm registry"
|
|
115
|
+
else:
|
|
116
|
+
return None, f"npm 下载失败: {error_msg[:200]}"
|
|
117
|
+
|
|
118
|
+
# 查找 .tgz 文件
|
|
119
|
+
tgz_files = list(dest.glob("*.tgz"))
|
|
120
|
+
if not tgz_files:
|
|
121
|
+
return None, "下载成功但未找到 .tgz 文件"
|
|
122
|
+
|
|
123
|
+
tgz_file = tgz_files[0]
|
|
124
|
+
extract_dir = dest / "extracted"
|
|
125
|
+
extract_dir.mkdir(exist_ok=True)
|
|
126
|
+
|
|
127
|
+
try:
|
|
128
|
+
shutil.unpack_archive(tgz_file, extract_dir)
|
|
129
|
+
# npm pack 会创建 package/ 子目录
|
|
130
|
+
package_dir = extract_dir / "package"
|
|
131
|
+
if package_dir.exists():
|
|
132
|
+
return package_dir, None
|
|
133
|
+
return extract_dir, None
|
|
134
|
+
except Exception as e:
|
|
135
|
+
return None, f"解压失败: {str(e)}"
|
|
136
|
+
|
|
137
|
+
except FileNotFoundError:
|
|
138
|
+
return None, "npm 命令未找到,请先安装 Node.js 和 npm"
|
|
139
|
+
except subprocess.TimeoutExpired:
|
|
140
|
+
return None, "下载超时(60秒),请检查网络连接"
|
|
141
|
+
except Exception as e:
|
|
142
|
+
return None, f"未知错误: {str(e)}"
|
|
143
|
+
|
|
144
|
+
@staticmethod
|
|
145
|
+
def download_git(url: str, dest: Path) -> Tuple[Optional[Path], Optional[str]]:
|
|
146
|
+
"""
|
|
147
|
+
从 Git 克隆仓库
|
|
148
|
+
返回: (下载路径, 错误信息)
|
|
149
|
+
"""
|
|
150
|
+
# 确保 git 已安装
|
|
151
|
+
if not ToolInstaller.ensure_tool("git"):
|
|
152
|
+
return None, "git 未安装且自动安装失败,请手动安装 Git"
|
|
153
|
+
|
|
154
|
+
try:
|
|
155
|
+
dest.mkdir(parents=True, exist_ok=True)
|
|
156
|
+
clone_dir = dest / "repo"
|
|
157
|
+
result = subprocess.run(
|
|
158
|
+
["git", "clone", url, str(clone_dir)],
|
|
159
|
+
capture_output=True,
|
|
160
|
+
text=True,
|
|
161
|
+
timeout=120
|
|
162
|
+
)
|
|
163
|
+
|
|
164
|
+
if result.returncode != 0:
|
|
165
|
+
error_msg = result.stderr.strip() if result.stderr else result.stdout.strip()
|
|
166
|
+
if "not found" in error_msg.lower() or "does not exist" in error_msg.lower():
|
|
167
|
+
return None, f"Git 仓库不存在: {url}"
|
|
168
|
+
elif "Authentication failed" in error_msg or "Permission denied" in error_msg:
|
|
169
|
+
return None, "认证失败: 仓库可能是私有的或需要登录"
|
|
170
|
+
elif "network" in error_msg.lower() or "timeout" in error_msg.lower():
|
|
171
|
+
return None, "网络错误: 无法连接到 Git 服务器"
|
|
172
|
+
else:
|
|
173
|
+
return None, f"git clone 失败: {error_msg[:200]}"
|
|
174
|
+
|
|
175
|
+
if not clone_dir.exists():
|
|
176
|
+
return None, "克隆成功但目录不存在"
|
|
177
|
+
|
|
178
|
+
return clone_dir, None
|
|
179
|
+
|
|
180
|
+
except FileNotFoundError:
|
|
181
|
+
return None, "git 命令未找到,请先安装 Git"
|
|
182
|
+
except subprocess.TimeoutExpired:
|
|
183
|
+
return None, "克隆超时(120秒),仓库可能太大或网络太慢"
|
|
184
|
+
except Exception as e:
|
|
185
|
+
return None, f"未知错误: {str(e)}"
|
|
186
|
+
|
|
187
|
+
@staticmethod
|
|
188
|
+
def download_local(path: str, dest: Path) -> Tuple[Optional[Path], Optional[str]]:
|
|
189
|
+
"""
|
|
190
|
+
从本地路径复制
|
|
191
|
+
返回: (下载路径, 错误信息)
|
|
192
|
+
"""
|
|
193
|
+
try:
|
|
194
|
+
src = Path(path).resolve()
|
|
195
|
+
if not src.exists():
|
|
196
|
+
return None, f"本地路径不存在: {path}"
|
|
197
|
+
|
|
198
|
+
if not src.is_dir():
|
|
199
|
+
return None, f"路径不是目录: {path}"
|
|
200
|
+
|
|
201
|
+
dest.mkdir(parents=True, exist_ok=True)
|
|
202
|
+
copy_dir = dest / "local"
|
|
203
|
+
shutil.copytree(src, copy_dir)
|
|
204
|
+
return copy_dir, None
|
|
205
|
+
|
|
206
|
+
except PermissionError:
|
|
207
|
+
return None, f"权限不足: 无法读取 {path}"
|
|
208
|
+
except Exception as e:
|
|
209
|
+
return None, f"复制失败: {str(e)}"
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"""安装信息记录"""
|
|
2
|
+
import json
|
|
3
|
+
from datetime import datetime
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from kite_cli import __version__
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def record_install_info(module_dir: Path, source_info: dict, module_data: dict, location: str):
|
|
9
|
+
"""记录安装信息到 .kite_install.json"""
|
|
10
|
+
install_info = {
|
|
11
|
+
"name": module_data.get("name"),
|
|
12
|
+
"version": module_data.get("version", "unknown"),
|
|
13
|
+
"source": source_info,
|
|
14
|
+
"installed_at": datetime.utcnow().isoformat() + "Z",
|
|
15
|
+
"installed_by": f"kite-cli@{__version__}",
|
|
16
|
+
"location": location,
|
|
17
|
+
"dependencies": module_data.get("dependencies", {})
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
install_info_path = module_dir / ".kite_install.json"
|
|
21
|
+
try:
|
|
22
|
+
with open(install_info_path, "w", encoding="utf-8") as f:
|
|
23
|
+
json.dump(install_info, f, indent=2, ensure_ascii=False)
|
|
24
|
+
return True
|
|
25
|
+
except Exception as e:
|
|
26
|
+
print(f"[Warning] 记录安装信息失败: {e}")
|
|
27
|
+
return False
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def read_install_info(module_dir: Path) -> dict:
|
|
31
|
+
"""读取安装信息"""
|
|
32
|
+
install_info_path = module_dir / ".kite_install.json"
|
|
33
|
+
if not install_info_path.exists():
|
|
34
|
+
return None
|
|
35
|
+
|
|
36
|
+
try:
|
|
37
|
+
with open(install_info_path, encoding="utf-8") as f:
|
|
38
|
+
return json.load(f)
|
|
39
|
+
except Exception:
|
|
40
|
+
return None
|