@sakanano-moe/agenthelm 6.8.0 → 6.11.0-rc.2
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/README.md +1 -1
- package/README.zh-CN.md +2 -0
- package/package.json +1 -1
- package/runtime/index.json +6 -6
- package/runtime/plugins/agent-pack/.codex-plugin/plugin.json +1 -1
- package/runtime/plugins/agent-pack/hooks/hooks.json +32 -0
- package/runtime/plugins/agent-pack/plugin.json +1 -1
- package/runtime/plugins/agent-pack/references/local-only.md +126 -0
- package/runtime/plugins/agent-pack/references/nudge.en.md +58 -0
- package/runtime/plugins/agent-pack/references/nudge.md +58 -0
- package/runtime/plugins/agent-pack/runtime/agent_pack_nudge.py +613 -0
- package/runtime/plugins/agent-pack/runtime/agenthelm.py +1271 -221
- package/runtime/plugins/agent-pack/runtime/agenthelm_runtime.py +114 -65
- package/runtime/plugins/agent-pack/runtime/i18n_agent_pack.py +78 -0
- package/runtime/plugins/agent-pack/runtime/local_only.py +1132 -0
- package/runtime/plugins/agent-pack/runtime/locale/en.json +569 -0
- package/runtime/plugins/agent-pack/runtime/mcp_server.py +25 -0
- package/runtime/plugins/agent-pack/runtime/nudge_text.py +127 -0
- package/runtime/plugins/agent-pack/runtime/user_settings.py +275 -0
- package/runtime/plugins/agent-pack/skills/agent-pack/SKILL.md +11 -1
- package/runtime/plugins/agents-init/.codex-plugin/plugin.json +1 -1
- package/runtime/plugins/agents-init/content.json +4 -4
- package/runtime/plugins/agents-init/plugin.json +1 -1
- package/runtime/plugins/agents-init/skills/agents-init/AGENT.template.md +141 -5
- package/runtime/plugins/agents-init/skills/agents-init/SKILL.md +41 -8
- package/runtime/plugins/agents-init/skills/agents-init/project.schema.json +408 -80
- package/runtime/plugins/agents-init/skills/agents-init/scripts/adopt.py +615 -0
- package/runtime/plugins/agents-init/skills/agents-init/scripts/baseline.py +221 -0
- package/runtime/plugins/agents-init/skills/agents-init/scripts/i18n_init.py +78 -0
- package/runtime/plugins/agents-init/skills/agents-init/scripts/init_project.py +748 -159
- package/runtime/plugins/agents-init/skills/agents-init/scripts/locale/en.json +289 -0
- package/runtime/plugins/agents-init/skills/agents-init/scripts/merge3.py +149 -0
- package/runtime/plugins/agents-init/skills/agents-init/scripts/regions.py +99 -0
- package/runtime/plugins/agents-init/skills/agents-init/scripts/scaffold.py +594 -90
- package/runtime/plugins/agents-init/skills/agents-init/skeleton.json +2 -0
- package/runtime/plugins/agents-init/skills/agents-init/skill.json +1 -1
- package/runtime/plugins/opinion-manager/.codex-plugin/plugin.json +1 -1
- package/runtime/plugins/opinion-manager/plugin.json +1 -1
- package/runtime/plugins/opinion-manager/references/inbox.en.md +48 -0
- package/runtime/plugins/opinion-manager/references/inbox.md +48 -0
- package/runtime/plugins/opinion-manager/runtime/context.py +31 -26
- package/runtime/plugins/opinion-manager/runtime/i18n_opinion.py +78 -0
- package/runtime/plugins/opinion-manager/runtime/inbox.py +398 -0
- package/runtime/plugins/opinion-manager/runtime/inbox_text.py +114 -0
- package/runtime/plugins/opinion-manager/runtime/lifecycle.py +45 -44
- package/runtime/plugins/opinion-manager/runtime/locale/en.json +193 -0
- package/runtime/plugins/opinion-manager/runtime/opinion_manager.py +55 -50
- package/runtime/plugins/opinion-manager/runtime/versioned.py +90 -85
- package/runtime/plugins/opinion-manager/skills/opinion-manager/SKILL.md +15 -2
- package/runtime/plugins/project-orchestrator/.codex-plugin/plugin.json +1 -1
- package/runtime/plugins/project-orchestrator/content.json +30 -3
- package/runtime/plugins/project-orchestrator/plugin.json +1 -1
- package/runtime/plugins/project-orchestrator/references/case-workspaces.md +9 -1
- package/runtime/plugins/project-orchestrator/references/case.schema.json +1 -0
- package/runtime/plugins/project-orchestrator/references/sop-interview.md +83 -0
- package/runtime/plugins/project-orchestrator/references/sop.md +156 -0
- package/runtime/plugins/project-orchestrator/runtime/assets.py +52 -57
- package/runtime/plugins/project-orchestrator/runtime/case.py +139 -80
- package/runtime/plugins/project-orchestrator/runtime/case_structure.py +71 -0
- package/runtime/plugins/project-orchestrator/runtime/case_workspace.py +47 -46
- package/runtime/plugins/project-orchestrator/runtime/i18n_orchestrator.py +78 -0
- package/runtime/plugins/project-orchestrator/runtime/locale/en.json +1450 -0
- package/runtime/plugins/project-orchestrator/runtime/memory.py +45 -45
- package/runtime/plugins/project-orchestrator/runtime/private_paths.py +119 -0
- package/runtime/plugins/project-orchestrator/runtime/project_base.py +37 -19
- package/runtime/plugins/project-orchestrator/runtime/project_cli.py +307 -195
- package/runtime/plugins/project-orchestrator/runtime/project_demo.py +130 -48
- package/runtime/plugins/project-orchestrator/runtime/project_maintain.py +328 -221
- package/runtime/plugins/project-orchestrator/runtime/project_menu.py +167 -89
- package/runtime/plugins/project-orchestrator/runtime/project_real.py +187 -105
- package/runtime/plugins/project-orchestrator/runtime/project_write.py +58 -55
- package/runtime/plugins/project-orchestrator/runtime/sop.py +1670 -0
- package/runtime/plugins/project-orchestrator/runtime/sop_structure.py +226 -0
- package/runtime/plugins/project-orchestrator/runtime/wf.py +74 -70
- package/runtime/plugins/project-orchestrator/skills/project-orchestrator/SKILL.md +22 -0
- package/runtime/plugins/project-orchestrator/sop-templates/blank/SOP.en.md +57 -0
- package/runtime/plugins/project-orchestrator/sop-templates/blank/SOP.md +57 -0
- package/runtime/plugins/project-orchestrator/sop-templates/knowledge-digest/SOP.en.md +77 -0
- package/runtime/plugins/project-orchestrator/sop-templates/knowledge-digest/SOP.md +77 -0
- package/runtime/plugins/project-orchestrator/sop-templates/knowledge-digest/templates/digest.en.md +11 -0
- package/runtime/plugins/project-orchestrator/sop-templates/knowledge-digest/templates/digest.md +11 -0
- package/runtime/plugins/project-orchestrator/sop-templates/video-to-transcript/SOP.en.md +87 -0
- package/runtime/plugins/project-orchestrator/sop-templates/video-to-transcript/SOP.md +87 -0
- package/runtime/plugins/project-orchestrator/sop-templates/weekly-review/SOP.en.md +75 -0
- package/runtime/plugins/project-orchestrator/sop-templates/weekly-review/SOP.md +75 -0
- package/runtime/plugins/project-orchestrator/sop-templates/weekly-review/templates/review.en.md +11 -0
- package/runtime/plugins/project-orchestrator/sop-templates/weekly-review/templates/review.md +12 -0
- package/runtime/plugins/project-orchestrator/templates/CASE.en.md +39 -0
- package/runtime/plugins/agents-init/skills/agents-init/scripts/test_init_project.py +0 -678
- package/runtime/plugins/agents-init/skills/agents-init/scripts/test_scaffold.py +0 -551
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
agenthelm/runtimes/<发布版本>/ index.json、plugins/<插件>/、bin/agenthelm、runtime.json
|
|
6
6
|
agenthelm/current -> runtimes/<发布版本>
|
|
7
|
+
候选版带后缀(6.11.0-rc.2),正式版不带(6.11.0),两者不会共用目录
|
|
7
8
|
|
|
8
9
|
项目根启动器先找 ``current/bin/agenthelm``,所以装好后打开菜单不联网、不经过 npx。
|
|
9
10
|
同一版本装好后不再改写;新版本装在旁边并切换 ``current``,旧版本保留,可用 ``use`` 切回。
|
|
@@ -17,18 +18,20 @@ import argparse
|
|
|
17
18
|
import hashlib
|
|
18
19
|
import json
|
|
19
20
|
import os
|
|
21
|
+
import re
|
|
20
22
|
import shutil
|
|
21
23
|
import sys
|
|
22
24
|
import tempfile
|
|
23
25
|
from datetime import UTC, datetime
|
|
24
26
|
from pathlib import Path
|
|
25
27
|
from typing import Any
|
|
28
|
+
from i18n_agent_pack import _ # noqa: E402
|
|
26
29
|
|
|
27
30
|
PLUGINS = ("agent-pack", "agents-init", "opinion-manager", "project-orchestrator")
|
|
28
31
|
SKIP_PARTS = {"tests", "__pycache__", ".DS_Store", "node_modules"}
|
|
29
32
|
MANIFEST = "runtime.json"
|
|
30
33
|
SHIM = """#!/bin/sh
|
|
31
|
-
# agenthelm
|
|
34
|
+
# agenthelm runtime {version} (generated by agenthelm runtime install). Needs only Python 3.11+, no AI client.
|
|
32
35
|
self=$0
|
|
33
36
|
while [ -L "$self" ]; do # a command link (--link-bin) points here; follow it to the runtime
|
|
34
37
|
link=$(readlink "$self")
|
|
@@ -42,15 +45,19 @@ for candidate in "${{AGENTHELM_PYTHON:-}}" python3 python; do
|
|
|
42
45
|
exec "$candidate" "$here/plugins/agent-pack/runtime/agenthelm.py" "$@"
|
|
43
46
|
fi
|
|
44
47
|
done
|
|
45
|
-
|
|
48
|
+
case "${{AGENTHELM_LANG:-${{LC_ALL:-${{LANG:-}}}}}}" in
|
|
49
|
+
zh*) echo "agenthelm 需要 Python 3.11 或更高版本:安装后重试,或设置 AGENTHELM_PYTHON。" >&2 ;;
|
|
50
|
+
*) echo "agenthelm needs Python 3.11 or newer: install it and retry, or set AGENTHELM_PYTHON." >&2 ;;
|
|
51
|
+
esac
|
|
46
52
|
exit 3
|
|
47
53
|
"""
|
|
48
54
|
|
|
49
55
|
|
|
50
56
|
class RuntimeInstallError(Exception):
|
|
51
|
-
def __init__(self, message: str, next_steps: list[str] | None = None) -> None:
|
|
57
|
+
def __init__(self, message: str, next_steps: list[str] | None = None, *, download: bool = False) -> None:
|
|
52
58
|
super().__init__(message)
|
|
53
59
|
self.next_steps = next_steps or []
|
|
60
|
+
self.download = download
|
|
54
61
|
|
|
55
62
|
|
|
56
63
|
# ---------------------------------------------------------------- locations
|
|
@@ -108,21 +115,51 @@ def _shipped_files(root: Path) -> list[Path]:
|
|
|
108
115
|
return files
|
|
109
116
|
|
|
110
117
|
|
|
118
|
+
_PRERELEASE = r"\d+\.\d+\.\d+-[0-9A-Za-z][0-9A-Za-z.-]*"
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def release_label(root: Path, version: str) -> str:
|
|
122
|
+
"""The directory name for this content: ``version``, plus ``-rc.N`` when the source says it is a candidate.
|
|
123
|
+
|
|
124
|
+
index.json carries the release version without the pre-release suffix, so the suffix comes from where the
|
|
125
|
+
content was delivered: the npm package version (root is <package>/runtime), or the tag in the release
|
|
126
|
+
tarball's top directory ``agenthelm-v<version>-rc.N`` (also what a local .tar.gz of it unpacks to). A
|
|
127
|
+
plain checkout carries no such name and keeps the release version.
|
|
128
|
+
"""
|
|
129
|
+
candidates = []
|
|
130
|
+
package = root.parent / "package.json"
|
|
131
|
+
if root.name == "runtime" and package.is_file():
|
|
132
|
+
try:
|
|
133
|
+
data = json.loads(package.read_text(encoding="utf-8"))
|
|
134
|
+
except (OSError, ValueError):
|
|
135
|
+
data = {}
|
|
136
|
+
if isinstance(data, dict) and data.get("name") == "@sakanano-moe/agenthelm":
|
|
137
|
+
candidates.append(str(data.get("version") or ""))
|
|
138
|
+
matched = re.fullmatch(rf"agenthelm-v?({_PRERELEASE})", root.name)
|
|
139
|
+
if matched:
|
|
140
|
+
candidates.append(matched.group(1))
|
|
141
|
+
for candidate in candidates:
|
|
142
|
+
if candidate.startswith(version + "-") and re.fullmatch(_PRERELEASE, candidate):
|
|
143
|
+
return candidate
|
|
144
|
+
return version
|
|
145
|
+
|
|
146
|
+
|
|
111
147
|
def describe(root: Path) -> dict:
|
|
112
148
|
if not _is_release_root(root):
|
|
113
|
-
raise RuntimeInstallError(
|
|
114
|
-
["--source 指向仓库检出、解压后的发布包目录或 .tar.gz 发布包"])
|
|
149
|
+
raise RuntimeInstallError(_("{0} 不是 agenthelm 发布内容(缺少 index.json 或 plugins/<插件>)").format(root),
|
|
150
|
+
[_("--source 指向仓库检出、解压后的发布包目录或 .tar.gz 发布包")])
|
|
115
151
|
index = json.loads((root / "index.json").read_text(encoding="utf-8"))
|
|
116
152
|
version = str(index.get("plugin", {}).get("version") or "")
|
|
117
153
|
if not version:
|
|
118
|
-
raise RuntimeInstallError(
|
|
154
|
+
raise RuntimeInstallError(_("{0}/index.json 没有发布版本号").format(root))
|
|
119
155
|
digest = hashlib.sha256()
|
|
120
156
|
files = _shipped_files(root)
|
|
121
157
|
for relative in files:
|
|
122
158
|
digest.update(relative.as_posix().encode("utf-8") + b"\0" + (root / relative).read_bytes() + b"\0")
|
|
123
159
|
plugins = {name: json.loads((root / "plugins" / name / "plugin.json").read_text(encoding="utf-8")).get("version")
|
|
124
160
|
for name in PLUGINS}
|
|
125
|
-
return {"version": version, "
|
|
161
|
+
return {"version": release_label(root, version), "release_version": version, "plugins": plugins,
|
|
162
|
+
"digest": digest.hexdigest(), "files": len(files)}
|
|
126
163
|
|
|
127
164
|
|
|
128
165
|
def _read_manifest(directory: Path) -> dict | None:
|
|
@@ -165,14 +202,14 @@ def command_status() -> dict:
|
|
|
165
202
|
def missing_text(data: dict, commands: dict) -> dict:
|
|
166
203
|
"""Wording for “no user-level runtime installed”: says which commands work, instead of leaving “wf: not found” unexplained."""
|
|
167
204
|
def state(name: str) -> str:
|
|
168
|
-
return
|
|
205
|
+
return _("{0} 在 PATH 上({1})").format(name, commands[name]) if commands.get(name) else _("终端里的 {0} 命令目前不可用").format(name)
|
|
169
206
|
return {
|
|
170
|
-
"reason":
|
|
171
|
-
"impact": "项目根目录的 ./menu 会通过客户端插件兜底,所以现在能用;"
|
|
207
|
+
"reason": _("本次由 {0} 提供;{1},{2}。").format(data['running_from'], state('agenthelm'), state('wf')),
|
|
208
|
+
"impact": _("项目根目录的 ./menu 会通过客户端插件兜底,所以现在能用;"
|
|
172
209
|
"没有 AI 客户端或客户端插件被移除时打不开。wf 是单独的查找命令,运行时不会提供它:"
|
|
173
|
-
"用 ./menu find 词 或 agenthelm project find 词 代替",
|
|
174
|
-
"label": "安装运行时(agenthelm runtime install --apply,只写用户数据目录);"
|
|
175
|
-
"要在终端直接输入 agenthelm 时加 --link-bin ~/.local/bin(只链接 agenthelm,不含 wf)",
|
|
210
|
+
"用 ./menu find 词 或 agenthelm project find 词 代替"),
|
|
211
|
+
"label": _("安装运行时(agenthelm runtime install --apply,只写用户数据目录);"
|
|
212
|
+
"要在终端直接输入 agenthelm 时加 --link-bin ~/.local/bin(只链接 agenthelm,不含 wf)"),
|
|
176
213
|
}
|
|
177
214
|
|
|
178
215
|
|
|
@@ -186,8 +223,11 @@ def report(env: Any, latest: dict | None = None) -> dict:
|
|
|
186
223
|
|
|
187
224
|
def _newer(candidate: str, existing: str) -> bool:
|
|
188
225
|
def key(value: str) -> tuple:
|
|
189
|
-
|
|
190
|
-
|
|
226
|
+
core, _dash, pre = value.partition("-")
|
|
227
|
+
numbers = tuple(int(part) if part.isdigit() else 0 for part in core.split("."))
|
|
228
|
+
# 6.11.0-rc.2 sorts before 6.11.0 and after 6.11.0-rc.1.
|
|
229
|
+
order = tuple((0, int(part), "") if part.isdigit() else (1, 0, part) for part in pre.split(".")) if pre else ()
|
|
230
|
+
return numbers, (0, order) if pre else (1, ())
|
|
191
231
|
return key(candidate) > key(existing)
|
|
192
232
|
|
|
193
233
|
|
|
@@ -199,15 +239,16 @@ def plan(env: Any, root: Path, origin: str, *, link_bin: Path | None = None) ->
|
|
|
199
239
|
existing = _read_manifest(target)
|
|
200
240
|
active = current(env)
|
|
201
241
|
if existing and existing.get("digest") != info["digest"]:
|
|
202
|
-
raise RuntimeInstallError(
|
|
203
|
-
[
|
|
204
|
-
"确认要换掉时先手动移走该目录(例如移到 ~/.agent-pack/recovery/),再重新安装"
|
|
242
|
+
raise RuntimeInstallError(_("运行时 {0} 已安装,但内容与来源不同(来源:{1})").format(info['version'], origin),
|
|
243
|
+
[_("已装:{0};同一版本不会被改写").format(target),
|
|
244
|
+
_("确认要换掉时先手动移走该目录(例如移到 ~/.agent-pack/recovery/),再重新安装"),
|
|
245
|
+
_("候选版(-rc.N)与正式版内容不同时,用发布包或 npm 包安装会得到带后缀的目录;从仓库检出安装分不出后缀,需要先移走旧目录")])
|
|
205
246
|
writes = []
|
|
206
247
|
if not existing:
|
|
207
|
-
writes.append({"path": str(target), "scope": "用户数据目录(新版本,旧版本保留)"})
|
|
248
|
+
writes.append({"path": str(target), "scope": _("用户数据目录(新版本,旧版本保留)")})
|
|
208
249
|
switch = not active or active.get("version") != info["version"]
|
|
209
250
|
if switch:
|
|
210
|
-
writes.append({"path": str(current_link(env)), "scope":
|
|
251
|
+
writes.append({"path": str(current_link(env)), "scope": _("切换当前版本 → {0}").format(info['version'])})
|
|
211
252
|
link = None
|
|
212
253
|
if link_bin is not None:
|
|
213
254
|
link = link_bin.expanduser() / "agenthelm"
|
|
@@ -215,9 +256,9 @@ def plan(env: Any, root: Path, origin: str, *, link_bin: Path | None = None) ->
|
|
|
215
256
|
if link.is_symlink() and Path(os.readlink(link)) == expected:
|
|
216
257
|
link = None
|
|
217
258
|
elif link.exists() or link.is_symlink():
|
|
218
|
-
raise RuntimeInstallError(
|
|
259
|
+
raise RuntimeInstallError(_("{0} 已存在且不是本运行时的链接,不会覆盖").format(link), [_("换一个 --link-bin 目录,或手动处理该文件")])
|
|
219
260
|
else:
|
|
220
|
-
writes.append({"path": str(link), "scope": "命令链接(指向当前运行时)"})
|
|
261
|
+
writes.append({"path": str(link), "scope": _("命令链接(指向当前运行时)")})
|
|
221
262
|
return {"version": info["version"], "plugins": info["plugins"], "digest": info["digest"], "source": origin,
|
|
222
263
|
"target": str(target), "install": not existing, "switch": switch,
|
|
223
264
|
"previous": active.get("version") if active else None, "link": str(link) if link else None,
|
|
@@ -237,7 +278,7 @@ def apply(env: Any, planned: dict, root: Path) -> dict:
|
|
|
237
278
|
shutil.copy2(root / relative, destination)
|
|
238
279
|
shutil.copy2(root / "index.json", staging / "index.json")
|
|
239
280
|
if describe(staging)["digest"] != planned["digest"]:
|
|
240
|
-
raise RuntimeInstallError("复制后的内容与来源摘要不一致,已放弃安装")
|
|
281
|
+
raise RuntimeInstallError(_("复制后的内容与来源摘要不一致,已放弃安装"))
|
|
241
282
|
shim = staging / "bin" / "agenthelm"
|
|
242
283
|
shim.parent.mkdir()
|
|
243
284
|
shim.write_text(SHIM.format(version=planned["version"]), encoding="utf-8")
|
|
@@ -260,8 +301,8 @@ def apply(env: Any, planned: dict, root: Path) -> dict:
|
|
|
260
301
|
shim = current_link(env) / "bin" / "agenthelm"
|
|
261
302
|
verified = bool(active and active["version"] == planned["version"] and os.access(shim, os.X_OK))
|
|
262
303
|
return {"ok": verified, "version": planned["version"], "current": active,
|
|
263
|
-
"verify": (
|
|
264
|
-
else "回读不一致:请运行 agenthelm runtime status 查看"),
|
|
304
|
+
"verify": (_("重新读取:当前运行时 {0},命令 {1}").format(planned['version'], shim) if verified
|
|
305
|
+
else _("回读不一致:请运行 agenthelm runtime status 查看")),
|
|
265
306
|
"rollback": f"agenthelm runtime use {planned['previous']} --apply" if planned["previous"]
|
|
266
307
|
and planned["previous"] != planned["version"] else None}
|
|
267
308
|
|
|
@@ -276,10 +317,13 @@ def _switch(env: Any, target: Path) -> None:
|
|
|
276
317
|
|
|
277
318
|
|
|
278
319
|
def use(env: Any, version: str, *, apply_change: bool) -> dict:
|
|
320
|
+
if not version or version in {".", ".."} or "/" in version or "\\" in version or "\0" in version:
|
|
321
|
+
raise RuntimeInstallError(_("版本号必须是单个目录名(不能含路径分隔符或 ..):{0}").format(version),
|
|
322
|
+
[_("agenthelm runtime status 可以看到已安装的版本")])
|
|
279
323
|
target = runtimes_dir(env) / version
|
|
280
324
|
if not _read_manifest(target):
|
|
281
|
-
versions = "、".join(item["version"] for item in installed(env)) or "(无)"
|
|
282
|
-
raise RuntimeInstallError(
|
|
325
|
+
versions = _("、").join(item["version"] for item in installed(env)) or _("(无)")
|
|
326
|
+
raise RuntimeInstallError(_("没有安装运行时 {0}").format(version), [_("已安装:{0}").format(versions)])
|
|
283
327
|
active = current(env)
|
|
284
328
|
result = {"version": version, "previous": active.get("version") if active else None, "applied": False}
|
|
285
329
|
if apply_change:
|
|
@@ -291,7 +335,8 @@ def use(env: Any, version: str, *, apply_change: bool) -> dict:
|
|
|
291
335
|
|
|
292
336
|
# ---------------------------------------------------------------- sources
|
|
293
337
|
|
|
294
|
-
def resolve_source(host: Any, env: Any, args: argparse.Namespace, workdir: Path, *, prefer_release: bool) -> tuple[Path, str]:
|
|
338
|
+
def resolve_source(host: Any, env: Any, args: argparse.Namespace, workdir: Path, *, prefer_release: bool) -> tuple[Path, str, str | None]:
|
|
339
|
+
"""Return (root, origin text, version-source line); the line is None unless latest.json was consulted."""
|
|
295
340
|
if args.source is not None:
|
|
296
341
|
source = args.source.expanduser().resolve()
|
|
297
342
|
if source.is_file():
|
|
@@ -300,45 +345,45 @@ def resolve_source(host: Any, env: Any, args: argparse.Namespace, workdir: Path,
|
|
|
300
345
|
host._safe_extract(source, extracted)
|
|
301
346
|
roots = [path for path in extracted.iterdir() if path.is_dir()]
|
|
302
347
|
if len(roots) != 1:
|
|
303
|
-
raise RuntimeInstallError("发布包结构不符合预期")
|
|
304
|
-
return roots[0],
|
|
305
|
-
return source,
|
|
348
|
+
raise RuntimeInstallError(_("发布包结构不符合预期"))
|
|
349
|
+
return roots[0], _("本地发布包 {0}").format(source.name), None
|
|
350
|
+
return source, _("本地目录 {0}").format(source), None
|
|
306
351
|
bundled = bundled_root()
|
|
307
352
|
if bundled is not None and not prefer_release and not args.from_release:
|
|
308
|
-
return bundled,
|
|
353
|
+
return bundled, _("随附内容({0})").format(running_from(env)), None
|
|
309
354
|
try:
|
|
310
|
-
latest,
|
|
311
|
-
return host.release_source(latest, workdir), "GitHub Release(已核对摘要)"
|
|
355
|
+
latest, latest_origin = host.load_latest(env, args.latest, max_age=0)
|
|
356
|
+
return host.release_source(latest, workdir), _("GitHub Release(已核对摘要)"), host.origin_line(latest_origin)
|
|
312
357
|
except (host.CheckError, OSError, ValueError) as exc:
|
|
313
|
-
raise RuntimeInstallError(
|
|
314
|
-
["离线时用 --source 指向发布包(.tar.gz)或仓库检出",
|
|
315
|
-
"下载地址见 https://github.com/lc4t/agenthelm/releases"]) from exc
|
|
358
|
+
raise RuntimeInstallError(_("无法下载发布包:{0}").format(exc),
|
|
359
|
+
[_("离线时用 --source 指向发布包(.tar.gz)或仓库检出"),
|
|
360
|
+
_("下载地址见 https://github.com/lc4t/agenthelm/releases")], download=True) from exc
|
|
316
361
|
|
|
317
362
|
|
|
318
363
|
# ---------------------------------------------------------------- command line
|
|
319
364
|
|
|
320
365
|
def parser() -> argparse.ArgumentParser:
|
|
321
|
-
result = argparse.ArgumentParser(prog="agenthelm runtime", description=
|
|
366
|
+
result = argparse.ArgumentParser(prog="agenthelm runtime", description=_("agenthelm 用户级运行时:把四个插件的确定性工具装进用户数据目录,日常只需要 Python 3.11+。"))
|
|
322
367
|
sub = result.add_subparsers(dest="action", required=True)
|
|
323
|
-
for name, text in (("status", "当前运行时、已装版本与可用更新"),
|
|
324
|
-
("install", "安装运行时(默认用本命令随附的内容;默认预览)"),
|
|
325
|
-
("update", "联网安装最新发布版本并切换(默认预览)"),
|
|
326
|
-
("use", "切换到已安装的某个版本(默认预览)")):
|
|
368
|
+
for name, text in (("status", _("当前运行时、已装版本与可用更新")),
|
|
369
|
+
("install", _("安装运行时(默认用本命令随附的内容;默认预览)")),
|
|
370
|
+
("update", _("联网安装最新发布版本并切换(默认预览)")),
|
|
371
|
+
("use", _("切换到已安装的某个版本(默认预览)"))):
|
|
327
372
|
command = sub.add_parser(name, help=text)
|
|
328
373
|
command.add_argument("--output", choices=("text", "json"), default="text")
|
|
329
374
|
command.add_argument("--home", type=Path, help=argparse.SUPPRESS)
|
|
330
|
-
command.add_argument("--latest", help="latest.json 的 URL 或本地路径")
|
|
375
|
+
command.add_argument("--latest", help=_("latest.json 的 URL 或本地路径"))
|
|
331
376
|
if name == "use":
|
|
332
377
|
command.add_argument("version")
|
|
333
378
|
if name in ("install", "update"):
|
|
334
|
-
command.add_argument("--source", type=Path, help="本地目录或 .tar.gz 发布包(离线安装)")
|
|
335
|
-
command.add_argument("--link-bin", type=Path, help="在这个目录建 agenthelm 命令链接(例如 ~/.local/bin)")
|
|
379
|
+
command.add_argument("--source", type=Path, help=_("本地目录或 .tar.gz 发布包(离线安装)"))
|
|
380
|
+
command.add_argument("--link-bin", type=Path, help=_("在这个目录建 agenthelm 命令链接(例如 ~/.local/bin)"))
|
|
336
381
|
if name == "install":
|
|
337
|
-
command.add_argument("--from-release", action="store_true", help="联网下载发布包,而不用随附内容")
|
|
382
|
+
command.add_argument("--from-release", action="store_true", help=_("联网下载发布包,而不用随附内容"))
|
|
338
383
|
if name != "status":
|
|
339
384
|
command.add_argument("--apply", action="store_true")
|
|
340
385
|
if name == "status":
|
|
341
|
-
command.add_argument("--offline", action="store_true", help="只用缓存的版本信息")
|
|
386
|
+
command.add_argument("--offline", action="store_true", help=_("只用缓存的版本信息"))
|
|
342
387
|
return result
|
|
343
388
|
|
|
344
389
|
|
|
@@ -353,55 +398,59 @@ def main(argv: list[str], host: Any) -> int:
|
|
|
353
398
|
args = parser().parse_args(argv)
|
|
354
399
|
env = host.current_env(args.home)
|
|
355
400
|
if sys.platform == "win32":
|
|
356
|
-
print("agenthelm runtime 目前只支持 macOS 与 Linux。", file=sys.stderr)
|
|
401
|
+
print(_("agenthelm runtime 目前只支持 macOS 与 Linux。"), file=sys.stderr)
|
|
357
402
|
return 4
|
|
358
403
|
try:
|
|
359
404
|
if args.action == "status":
|
|
360
405
|
try:
|
|
361
|
-
latest,
|
|
406
|
+
latest, latest_origin = host.load_latest(env, args.latest, offline=args.offline)
|
|
362
407
|
except (host.CheckError, OSError, ValueError):
|
|
363
|
-
latest = None
|
|
408
|
+
latest, latest_origin = None, None
|
|
364
409
|
data = report(env, latest)
|
|
365
410
|
active = data["current"]
|
|
366
|
-
lines = [
|
|
367
|
-
|
|
368
|
-
|
|
411
|
+
lines = [_("当前运行时:{0}({1})").format(active['version'], active['path']) if active else _("当前运行时:未安装"),
|
|
412
|
+
_("已安装:{0}").format(_('、').join(item['version'] for item in data['installed']) or _('(无)')),
|
|
413
|
+
_("本次命令来自:{0}").format(data['running_from'])]
|
|
414
|
+
if latest_origin is not None:
|
|
415
|
+
lines.append(host.origin_line(latest_origin))
|
|
369
416
|
if data["update_available"]:
|
|
370
|
-
lines.append(
|
|
417
|
+
lines.append(_("有新版本 {0}:agenthelm runtime update 预览").format(data['latest_release']))
|
|
371
418
|
if not active:
|
|
372
|
-
lines.append("安装:agenthelm runtime install(预览)→ 加 --apply 执行")
|
|
419
|
+
lines.append(_("安装:agenthelm runtime install(预览)→ 加 --apply 执行"))
|
|
373
420
|
_print({"ok": True, **data}, args.output, lines)
|
|
374
421
|
return 0
|
|
375
422
|
if args.action == "use":
|
|
376
423
|
result = use(env, args.version, apply_change=args.apply)
|
|
377
|
-
lines = [
|
|
424
|
+
lines = [_("{0}:{1} → {2}").format(_('已切换') if result['applied'] else _('将切换'), result['previous'], result['version'])]
|
|
378
425
|
if not args.apply:
|
|
379
|
-
lines.append("以上为预览;加 --apply 执行。")
|
|
426
|
+
lines.append(_("以上为预览;加 --apply 执行。"))
|
|
380
427
|
_print({"ok": True, **result}, args.output, lines)
|
|
381
428
|
return 0
|
|
382
429
|
with tempfile.TemporaryDirectory(prefix="agenthelm-runtime-") as temporary:
|
|
383
|
-
root, origin = resolve_source(host, env, args, Path(temporary), prefer_release=args.action == "update")
|
|
430
|
+
root, origin, source_line = resolve_source(host, env, args, Path(temporary), prefer_release=args.action == "update")
|
|
384
431
|
planned = plan(env, root, origin, link_bin=args.link_bin)
|
|
385
|
-
lines = [
|
|
386
|
-
|
|
432
|
+
lines = [_("运行时 {0}(来源:{1})").format(planned['version'], origin)]
|
|
433
|
+
if source_line:
|
|
434
|
+
lines.append(source_line)
|
|
435
|
+
lines += [_(" 将写入:{0}({1})").format(item['path'], item['scope']) for item in planned["writes"]] or [_(" 已是当前版本,无需改动。")]
|
|
387
436
|
if not args.apply or planned["action"] == "none" and not planned["link"]:
|
|
388
437
|
if args.apply is False and planned["writes"]:
|
|
389
|
-
lines.append("以上为预览;加 --apply 执行。")
|
|
438
|
+
lines.append(_("以上为预览;加 --apply 执行。"))
|
|
390
439
|
_print({"ok": True, "applied": False, "plan": planned}, args.output, lines)
|
|
391
440
|
return 0
|
|
392
441
|
result = apply(env, planned, root)
|
|
393
442
|
lines.append((" " + result["verify"]))
|
|
394
443
|
if result["rollback"]:
|
|
395
|
-
lines.append(
|
|
444
|
+
lines.append(_(" 回到旧版本:{0}").format(result['rollback']))
|
|
396
445
|
if not os.environ.get("PATH", "").count(str(current_link(env) / "bin")) and not planned["link"]:
|
|
397
|
-
lines.append(
|
|
446
|
+
lines.append(_(" 直接用命令:把 {0} 加入 PATH,或重新运行并加 --link-bin ~/.local/bin").format(current_link(env) / 'bin'))
|
|
398
447
|
_print({"ok": result["ok"], "applied": True, "plan": planned, **result}, args.output, lines)
|
|
399
448
|
return 0 if result["ok"] else 6
|
|
400
449
|
except RuntimeInstallError as exc:
|
|
401
450
|
if args.output == "json":
|
|
402
451
|
print(json.dumps({"ok": False, "error": str(exc), "next": exc.next_steps}, ensure_ascii=False, indent=2))
|
|
403
452
|
else:
|
|
404
|
-
print(
|
|
453
|
+
print(_("出错:{0}").format(exc), file=sys.stderr)
|
|
405
454
|
for step in exc.next_steps:
|
|
406
455
|
print(f" · {step}", file=sys.stderr)
|
|
407
|
-
return 4 if
|
|
456
|
+
return 4 if exc.download else 2
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"""运行时文案的多语言:源语言是中文,``_("中文原文")`` 在中文下原样返回,在英文下查 ``locale/en.json``。
|
|
2
|
+
|
|
3
|
+
语言按这个顺序决定:调用方指定(如 ``nudge.language``)→ 环境变量 ``AGENTHELM_LANG`` → 用户配置
|
|
4
|
+
``~/.config/agenthelm/config.json`` 的 ``language`` → 系统 locale(``LC_ALL``、``LC_MESSAGES``、``LANG``)→ 英文。
|
|
5
|
+
``auto``、空值和 C/POSIX 视为未指定;中文 locale 用中文,其他语言的 locale 暂用英文。
|
|
6
|
+
没有英文译文的文案原样输出(中文),测试守住译文完整。四个插件各带一份相同的本模块(模块名不同,以免
|
|
7
|
+
同一进程里互相覆盖),``tests/test_i18n_parity.py`` 守住它们行为一致。模块级常量里的文案用 ``N_`` 标记
|
|
8
|
+
(原样返回,仅供提取),使用处再调用 ``_``,这样语言在运行时而不是导入时决定。
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import json
|
|
14
|
+
import os
|
|
15
|
+
from pathlib import Path
|
|
16
|
+
from typing import Mapping
|
|
17
|
+
|
|
18
|
+
LANGUAGES = ("zh", "en")
|
|
19
|
+
DEFAULT_LANGUAGE = "en"
|
|
20
|
+
LOCALE_DIR = Path(__file__).resolve().parent / "locale"
|
|
21
|
+
_catalogs: dict[str, dict[str, str]] = {}
|
|
22
|
+
_configured: dict[str, tuple[tuple, str | None]] = {}
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def normalize(value: object) -> str | None:
|
|
26
|
+
text = str(value or "").strip().lower().replace("_", "-")
|
|
27
|
+
if not text or text in ("auto", "c", "posix") or text.startswith(("c.", "posix.")):
|
|
28
|
+
return None
|
|
29
|
+
return "zh" if text.startswith("zh") else "en"
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def configured_language(environ: Mapping[str, str]) -> str | None:
|
|
33
|
+
"""用户配置里的 language;按文件修改时间缓存,读不了就当没有。"""
|
|
34
|
+
base = environ.get("XDG_CONFIG_HOME") or (str(Path(environ["HOME"]) / ".config") if environ.get("HOME") else "")
|
|
35
|
+
if not base:
|
|
36
|
+
return None
|
|
37
|
+
path = Path(base) / "agenthelm" / "config.json"
|
|
38
|
+
try:
|
|
39
|
+
info = path.stat()
|
|
40
|
+
signature = (info.st_mtime_ns, info.st_size)
|
|
41
|
+
cached = _configured.get(str(path))
|
|
42
|
+
if cached and cached[0] == signature:
|
|
43
|
+
return cached[1]
|
|
44
|
+
data = json.loads(path.read_text(encoding="utf-8"))
|
|
45
|
+
value = normalize(data.get("language")) if isinstance(data, dict) else None
|
|
46
|
+
except (OSError, ValueError):
|
|
47
|
+
return None
|
|
48
|
+
_configured[str(path)] = (signature, value)
|
|
49
|
+
return value
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def resolve_language(requested: str | None = None, environ: Mapping[str, str] | None = None) -> str:
|
|
53
|
+
environ = os.environ if environ is None else environ
|
|
54
|
+
for candidate in (requested, environ.get("AGENTHELM_LANG"), configured_language(environ),
|
|
55
|
+
environ.get("LC_ALL"), environ.get("LC_MESSAGES"), environ.get("LANG")):
|
|
56
|
+
language = normalize(candidate)
|
|
57
|
+
if language:
|
|
58
|
+
return language
|
|
59
|
+
return DEFAULT_LANGUAGE
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def catalog(language: str) -> dict[str, str]:
|
|
63
|
+
if language not in _catalogs:
|
|
64
|
+
try:
|
|
65
|
+
data = json.loads((LOCALE_DIR / f"{language}.json").read_text(encoding="utf-8"))
|
|
66
|
+
except (OSError, ValueError):
|
|
67
|
+
data = {}
|
|
68
|
+
_catalogs[language] = data if isinstance(data, dict) else {}
|
|
69
|
+
return _catalogs[language]
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def _(message: str) -> str:
|
|
73
|
+
language = resolve_language()
|
|
74
|
+
return message if language == "zh" else catalog(language).get(message, message)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def N_(message: str) -> str:
|
|
78
|
+
return message
|