@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
|
@@ -25,8 +25,10 @@ from typing import Any
|
|
|
25
25
|
|
|
26
26
|
import assets
|
|
27
27
|
from project_base import DEFAULT_LAUNCHER, LAUNCHER_RE, EntryError
|
|
28
|
+
from i18n_orchestrator import _, N_ # noqa: E402
|
|
29
|
+
from i18n_orchestrator import _ # noqa: E402
|
|
28
30
|
|
|
29
|
-
CLIENT_LABEL = {"claude": "Claude Code", "codex": "Codex", "cursor": "Cursor", "legacy": "旧方式安装"}
|
|
31
|
+
CLIENT_LABEL = {"claude": "Claude Code", "codex": "Codex", "cursor": "Cursor", "legacy": N_("旧方式安装")}
|
|
30
32
|
|
|
31
33
|
|
|
32
34
|
def _iso(seconds: float | None) -> str:
|
|
@@ -43,39 +45,61 @@ def runtime_module(host: Any) -> Any:
|
|
|
43
45
|
|
|
44
46
|
# ---------------------------------------------------------------- check
|
|
45
47
|
|
|
46
|
-
SCAFFOLD_NEXT = {"add-skeleton": "按模板补上(只新建,不改已有文件)",
|
|
47
|
-
"profile": "把字段改为模板值(先备份,预览里有 diff)",
|
|
48
|
-
"repair-lock": "按实际版本修复内容锁(不涉及你的文件)",
|
|
49
|
-
"update-content": "逐文件选择保留或采用新模板",
|
|
50
|
-
"case-naming": "查看改名计划与受影响的引用(只给计划,不移动目录)"
|
|
48
|
+
SCAFFOLD_NEXT = {"add-skeleton": N_("按模板补上(只新建,不改已有文件)"),
|
|
49
|
+
"profile": N_("把字段改为模板值(先备份,预览里有 diff)"),
|
|
50
|
+
"repair-lock": N_("按实际版本修复内容锁(不涉及你的文件)"),
|
|
51
|
+
"update-content": N_("逐文件选择保留或采用新模板"),
|
|
52
|
+
"case-naming": N_("查看改名计划与受影响的引用(只给计划,不移动目录)"),
|
|
53
|
+
"update-region": N_("更新受管区块:运行 init_project.py --mode region(改过的区块逐个 --keep / --accept)")}
|
|
51
54
|
|
|
52
55
|
|
|
53
56
|
def _scaffold_findings(scaffold: dict | None, findings: list[dict], ok: list[str]) -> None:
|
|
54
57
|
if scaffold is None:
|
|
55
58
|
return
|
|
56
59
|
if scaffold.get("error"):
|
|
57
|
-
findings.append({"id": "scaffold-check", "level": "unavailable", "area": "脚手架", "title": "无法检查项目脚手架",
|
|
58
|
-
"reason": scaffold["error"], "impact": "只影响脚手架一致性提示", "next": []})
|
|
60
|
+
findings.append({"id": "scaffold-check", "level": "unavailable", "area": _("脚手架"), "title": _("无法检查项目脚手架"),
|
|
61
|
+
"reason": scaffold["error"], "impact": _("只影响脚手架一致性提示"), "next": []})
|
|
59
62
|
return
|
|
63
|
+
rows = {(row["level"], row["category"]): row for row in scaffold.get("categories", [])}
|
|
60
64
|
for item in scaffold["findings"]:
|
|
61
|
-
mark = "(稍后)" if item.get("deferred") else "(期望内容已变化)" if item.get("changed_since_decision") else ""
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
65
|
+
mark = _("(稍后)") if item.get("deferred") else _("(期望内容已变化)") if item.get("changed_since_decision") else ""
|
|
66
|
+
# 菜单只执行 FIXES 里的处理项;其余(如 update-region)只给出怎么处理的说明。
|
|
67
|
+
step = {"label": _(SCAFFOLD_NEXT.get(item["fix"], item["fix"])), "action": f"fix:{item['fix']}" if item["fix"] in FIXES else ""} \
|
|
68
|
+
if item["fix"] else {"label": _("这一项需要你自己处理"), "action": ""}
|
|
69
|
+
level = item.get("level", "suggest")
|
|
70
|
+
entry = {"id": item["id"], "level": level, "area": _("脚手架"), "title": item["title"] + mark,
|
|
71
|
+
"reason": item["reason"], "impact": _("脚手架和最新版不一致;不影响日常使用,"
|
|
72
|
+
"不想要的可以永久跳过(一次决定,所有机器生效)") if level != "must" else _("会影响使用,需要处理"),
|
|
73
|
+
"next": [step],
|
|
74
|
+
"decision": {"id": item["id"], "fingerprint": item["fingerprint"], "scope": "project"}}
|
|
75
|
+
row = rows.get((level, item.get("category")))
|
|
76
|
+
if row is not None and level != "must":
|
|
77
|
+
# 逐项明细保留在 findings 里(JSON 稳定);文本显示按 group 把同类项合并为一行。
|
|
78
|
+
entry["group"] = {"id": f"scaffold:{row['category']}", "label": row["label"], "count": row["count"]}
|
|
79
|
+
findings.append(entry)
|
|
68
80
|
for message in scaffold["decisions"]["errors"]:
|
|
69
|
-
findings.append({"id": "scaffold-decisions", "level": "unavailable", "area": "脚手架",
|
|
70
|
-
"title": "决定文件有问题", "reason": message, "impact": "已记录的决定暂时不生效", "next": []})
|
|
81
|
+
findings.append({"id": "scaffold-decisions", "level": "unavailable", "area": _("脚手架"),
|
|
82
|
+
"title": _("决定文件有问题"), "reason": message, "impact": _("已记录的决定暂时不生效"), "next": []})
|
|
71
83
|
if scaffold["decisions"]["conflict_copies"]:
|
|
72
|
-
findings.append({"id": "scaffold-decisions-conflict", "level": "suggest", "area": "脚手架",
|
|
73
|
-
"title": "同步服务留下了决定文件的冲突副本",
|
|
74
|
-
"reason": "、".join(scaffold["decisions"]["conflict_copies"]),
|
|
75
|
-
"impact": "另一台机器写入的决定可能没有生效",
|
|
76
|
-
"next": [{"label": "把其中的条目合并进 check-decisions.json 后删除副本", "action": ""}]})
|
|
84
|
+
findings.append({"id": "scaffold-decisions-conflict", "level": "suggest", "area": _("脚手架"),
|
|
85
|
+
"title": _("同步服务留下了决定文件的冲突副本"),
|
|
86
|
+
"reason": _("、").join(scaffold["decisions"]["conflict_copies"]),
|
|
87
|
+
"impact": _("另一台机器写入的决定可能没有生效"),
|
|
88
|
+
"next": [{"label": _("把其中的条目合并进 check-decisions.json 后删除副本"), "action": ""}]})
|
|
77
89
|
if not scaffold["findings"]:
|
|
78
|
-
ok.append("项目脚手架(与期望一致" + (
|
|
90
|
+
ok.append(_("项目脚手架(与期望一致") + (_(",{0} 项已跳过").format(len(scaffold['skipped'])) if scaffold["skipped"] else "") + _(")"))
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def _local_only_finding(item: dict) -> dict:
|
|
94
|
+
"""agent-pack 的 local-only 发现 -> 健康检查里的一项;选项里第一个带命令的对应 fix local-only。"""
|
|
95
|
+
steps, linked = [], False
|
|
96
|
+
for option in item.get("options") or []:
|
|
97
|
+
action = "fix:local-only" if option.get("command") and not linked else ""
|
|
98
|
+
linked = linked or bool(action)
|
|
99
|
+
steps.append({"label": option["label"], "action": action})
|
|
100
|
+
return {"id": item["id"], "level": "unavailable" if item.get("kind") == "error" else "suggest", "area": _("同步盘"),
|
|
101
|
+
"title": item["title"], "reason": item["reason"], "impact": item["impact"], "next": steps,
|
|
102
|
+
"decision": {"id": item["id"], "fingerprint": item["fingerprint"], "scope": "machine"}}
|
|
79
103
|
|
|
80
104
|
|
|
81
105
|
def check_updates(provider: Any, findings: list[dict], ok: list[str]) -> dict:
|
|
@@ -91,16 +115,18 @@ def check_updates(provider: Any, findings: list[dict], ok: list[str]) -> dict:
|
|
|
91
115
|
_scaffold_findings(scaffold, findings, ok)
|
|
92
116
|
for item in (machine["findings"] if machine else []):
|
|
93
117
|
if item["id"] == "local:sync-folder":
|
|
94
|
-
findings.append({"id": "sync-folder", "level": "suggest", "area": "环境", "title": item["title"],
|
|
118
|
+
findings.append({"id": "sync-folder", "level": "suggest", "area": _("环境"), "title": item["title"],
|
|
95
119
|
"reason": item["reason"], "impact": item["impact"],
|
|
96
|
-
"next": [{"label": "查看同步盘使用指引(只给方案,不改文件、不删内容)", "action": "fix:sync-folder"}],
|
|
120
|
+
"next": [{"label": _("查看同步盘使用指引(只给方案,不改文件、不删内容)"), "action": "fix:sync-folder"}],
|
|
97
121
|
"decision": {"id": item["id"], "fingerprint": item["fingerprint"], "scope": "machine"}})
|
|
122
|
+
elif item.get("fix") == "local-only" or item.get("kind") == "error":
|
|
123
|
+
findings.append(_local_only_finding(item))
|
|
98
124
|
try:
|
|
99
125
|
report = host.run_check(env, provider.root, offline=provider.offline)
|
|
100
126
|
except (host.CheckError, OSError, ValueError) as exc:
|
|
101
|
-
findings.append({"id": "update-check", "level": "unavailable", "area": "更新", "title": "无法检查更新",
|
|
102
|
-
"reason": str(exc), "impact": "不影响找资料、看进展等日常功能",
|
|
103
|
-
"next": [{"label": "联网后重新检查", "action": ""}]})
|
|
127
|
+
findings.append({"id": "update-check", "level": "unavailable", "area": _("更新"), "title": _("无法检查更新"),
|
|
128
|
+
"reason": str(exc), "impact": _("不影响找资料、看进展等日常功能"),
|
|
129
|
+
"next": [{"label": _("联网后重新检查"), "action": ""}]})
|
|
104
130
|
provider._report = None
|
|
105
131
|
_check_runtime(provider, env, None, findings, ok, machine)
|
|
106
132
|
return {"status": "offline", "cached_at": ""}
|
|
@@ -123,73 +149,75 @@ def _plugin_findings(provider: Any, env: Any, report: dict, findings: list[dict]
|
|
|
123
149
|
behind = [item for item in plugins if item["status"] == "behind"]
|
|
124
150
|
if behind:
|
|
125
151
|
breaking = [item for item in behind if item["breaking"]]
|
|
126
|
-
details = ";".join(
|
|
152
|
+
details = _(";").join(_("{0} {1} → {2}({3})").format(item['plugin'], item['version'], item['latest'], _(CLIENT_LABEL[item['client']]))
|
|
127
153
|
for item in behind)
|
|
128
|
-
findings.append({"id": "update-plugins", "level": "update", "area": "插件",
|
|
129
|
-
"title":
|
|
130
|
-
"reason": details, "impact": "只影响 AI 客户端里的插件;不更新也能继续使用本菜单",
|
|
131
|
-
"next": [{"label": "查看更新内容与迁移说明,再决定是否更新", "action": "fix:update-plugins"}]})
|
|
154
|
+
findings.append({"id": "update-plugins", "level": "update", "area": _("插件"),
|
|
155
|
+
"title": _("{0} 个插件有新版本").format(len(behind)) + (_("(含不兼容变更)") if breaking else ""),
|
|
156
|
+
"reason": details, "impact": _("只影响 AI 客户端里的插件;不更新也能继续使用本菜单"),
|
|
157
|
+
"next": [{"label": _("查看更新内容与迁移说明,再决定是否更新"), "action": "fix:update-plugins"}]})
|
|
132
158
|
elif plugins:
|
|
133
|
-
ok.append("客户端插件(最新)")
|
|
159
|
+
ok.append(_("客户端插件(最新)"))
|
|
134
160
|
if not plugins:
|
|
135
|
-
|
|
161
|
+
# Clients the user chose to ignore are not offered an install; an older host has no active_clients.
|
|
162
|
+
clients = host.active_clients(env) if hasattr(host, "active_clients") else host.detect_clients(env)
|
|
163
|
+
everything = host.detect_clients(env)
|
|
136
164
|
if clients:
|
|
137
|
-
findings.append({"id": "no-plugins", "level": "unavailable", "area": "插件",
|
|
138
|
-
"title": "AI 客户端里还没有安装 agenthelm 插件",
|
|
139
|
-
"reason": "检测到 " + "、".join(CLIENT_LABEL.get(c, c) for c in clients) + ",但没有市场安装",
|
|
140
|
-
"impact": "只影响 AI Agent 使用;本菜单不受影响",
|
|
141
|
-
"next": [{"label": "需要时运行 agenthelm install 预览安装", "action": ""}]})
|
|
142
|
-
|
|
143
|
-
findings.append({"id": "no-ai-client", "level": "unavailable", "area": "环境", "title": "本机没有 AI 客户端",
|
|
144
|
-
"reason": "没有找到 Claude Code、Codex 或 Cursor",
|
|
145
|
-
"impact": "本菜单的日常功能全部不受影响;只有“安装插件到客户端”不可用",
|
|
146
|
-
"next": [{"label": "需要时安装任一客户端,再运行 agenthelm install", "action": ""}]})
|
|
165
|
+
findings.append({"id": "no-plugins", "level": "unavailable", "area": _("插件"),
|
|
166
|
+
"title": _("AI 客户端里还没有安装 agenthelm 插件"),
|
|
167
|
+
"reason": _("检测到 ") + _("、").join(_(CLIENT_LABEL.get(c, c)) for c in clients) + _(",但没有市场安装"),
|
|
168
|
+
"impact": _("只影响 AI Agent 使用;本菜单不受影响"),
|
|
169
|
+
"next": [{"label": _("需要时运行 agenthelm install 预览安装"), "action": ""}]})
|
|
170
|
+
elif not everything: # clients that exist but are all ignored are no finding at all
|
|
171
|
+
findings.append({"id": "no-ai-client", "level": "unavailable", "area": _("环境"), "title": _("本机没有 AI 客户端"),
|
|
172
|
+
"reason": _("没有找到 Claude Code、Codex 或 Cursor"),
|
|
173
|
+
"impact": _("本菜单的日常功能全部不受影响;只有“安装插件到客户端”不可用"),
|
|
174
|
+
"next": [{"label": _("需要时安装任一客户端,再运行 agenthelm install"), "action": ""}]})
|
|
147
175
|
if report["summary"]["legacy_installs"]:
|
|
148
|
-
findings.append({"id": "legacy", "level": "suggest", "area": "插件", "title": "有旧方式安装待迁移",
|
|
149
|
-
"reason": "旧的复制 + 软链安装与市场安装并存会重复", "impact": "Agent 里可能看到重复的 Skill",
|
|
150
|
-
"next": [{"label": "运行 agenthelm migrate --install 预览迁移", "action": ""}]})
|
|
176
|
+
findings.append({"id": "legacy", "level": "suggest", "area": _("插件"), "title": _("有旧方式安装待迁移"),
|
|
177
|
+
"reason": _("旧的复制 + 软链安装与市场安装并存会重复"), "impact": _("Agent 里可能看到重复的 Skill"),
|
|
178
|
+
"next": [{"label": _("运行 agenthelm migrate --install 预览迁移"), "action": ""}]})
|
|
151
179
|
for issue in host.doctor(env, report)["issues"]:
|
|
152
180
|
if issue["issue"] in ("version-skew", "duplicate", "incomplete"):
|
|
153
|
-
findings.append({"id": f"doctor-{issue['issue']}", "level": "suggest", "area": "插件",
|
|
154
|
-
"title": {"version-skew": "各客户端插件版本不一致", "duplicate": "插件重复安装",
|
|
155
|
-
"incomplete": "插件没有装全"}[issue["issue"]],
|
|
156
|
-
"reason": issue["detail"], "impact": "只影响 AI Agent 使用",
|
|
157
|
-
"next": [{"label": "运行 agenthelm doctor 查看", "action": ""}]})
|
|
181
|
+
findings.append({"id": f"doctor-{issue['issue']}", "level": "suggest", "area": _("插件"),
|
|
182
|
+
"title": {"version-skew": _("各客户端插件版本不一致"), "duplicate": _("插件重复安装"),
|
|
183
|
+
"incomplete": _("插件没有装全")}[issue["issue"]],
|
|
184
|
+
"reason": issue["detail"], "impact": _("只影响 AI Agent 使用"),
|
|
185
|
+
"next": [{"label": _("运行 agenthelm doctor 查看"), "action": ""}]})
|
|
158
186
|
|
|
159
187
|
|
|
160
188
|
def _content_findings(report: dict, findings: list[dict], ok: list[str]) -> None:
|
|
161
189
|
updates = [item for item in report["content"] if item.get("status") in ("update-available", "conflict")]
|
|
162
190
|
for item in report["content"]:
|
|
163
191
|
if item.get("pack") is None:
|
|
164
|
-
findings.append({"id": "content-lock", "level": "suggest", "area": "项目模板", "title": "内容锁无法读取",
|
|
165
|
-
"reason": item.get("error", ""), "impact": "模板更新无法判断哪些文件改过",
|
|
166
|
-
"next": [{"label": "检查 .agents/moe.sakanano.agent-pack/content.lock.json", "action": ""}]})
|
|
192
|
+
findings.append({"id": "content-lock", "level": "suggest", "area": _("项目模板"), "title": _("内容锁无法读取"),
|
|
193
|
+
"reason": item.get("error", ""), "impact": _("模板更新无法判断哪些文件改过"),
|
|
194
|
+
"next": [{"label": _("检查 .agents/moe.sakanano.agent-pack/content.lock.json"), "action": ""}]})
|
|
167
195
|
if updates:
|
|
168
196
|
changed = sorted({path for item in updates for path in item["locally_changed"]})
|
|
169
|
-
findings.append({"id": "update-content", "level": "update", "area": "项目模板",
|
|
170
|
-
"title": "项目模板/样例有新版本",
|
|
171
|
-
"reason": ";".join(f"{item['pack']} {item['version']} → {item['latest']}" for item in updates)
|
|
172
|
-
+ (
|
|
173
|
-
"impact": "不更新不影响使用;更新时你改过的文件逐个选择保留或采用",
|
|
174
|
-
"next": [{"label": "查看影响并选择", "action": "fix:update-content"}]})
|
|
197
|
+
findings.append({"id": "update-content", "level": "update", "area": _("项目模板"),
|
|
198
|
+
"title": _("项目模板/样例有新版本"),
|
|
199
|
+
"reason": _(";").join(f"{item['pack']} {item['version']} → {item['latest']}" for item in updates)
|
|
200
|
+
+ (_(";你改过的:{0}").format(_('、').join(changed)) if changed else ""),
|
|
201
|
+
"impact": _("不更新不影响使用;更新时你改过的文件逐个选择保留或采用"),
|
|
202
|
+
"next": [{"label": _("查看影响并选择"), "action": "fix:update-content"}]})
|
|
175
203
|
elif report["content"]:
|
|
176
|
-
ok.append("项目模板(最新)")
|
|
204
|
+
ok.append(_("项目模板(最新)"))
|
|
177
205
|
|
|
178
206
|
|
|
179
207
|
def _opinion_findings(report: dict, findings: list[dict], ok: list[str]) -> None:
|
|
180
208
|
for item in report["opinion"]:
|
|
181
209
|
if item["status"] == "update-available":
|
|
182
|
-
refs = ";".join(f"{update['current']} → {update['available'][-1]}" for update in item["updates"])
|
|
183
|
-
findings.append({"id": "opinion-updates", "level": "update", "area": "个人规则",
|
|
184
|
-
"title": "行为规则模板有新版本", "reason": refs,
|
|
185
|
-
"impact": "工具升级不会自动采纳个人规则;当前规则继续有效",
|
|
186
|
-
"next": [{"label": "需要时在 Agent 会话中用 opinion-manager 预览后确认", "action": ""}]})
|
|
210
|
+
refs = _(";").join(f"{update['current']} → {update['available'][-1]}" for update in item["updates"])
|
|
211
|
+
findings.append({"id": "opinion-updates", "level": "update", "area": _("个人规则"),
|
|
212
|
+
"title": _("行为规则模板有新版本"), "reason": refs,
|
|
213
|
+
"impact": _("工具升级不会自动采纳个人规则;当前规则继续有效"),
|
|
214
|
+
"next": [{"label": _("需要时在 Agent 会话中用 opinion-manager 预览后确认"), "action": ""}]})
|
|
187
215
|
elif item["status"] in ("error", "unknown"):
|
|
188
|
-
findings.append({"id": "opinion-check", "level": "unavailable", "area": "个人规则",
|
|
189
|
-
"title": "行为规则版本无法检查", "reason": item.get("error", ""),
|
|
190
|
-
"impact": "只影响规则更新提示", "next": []})
|
|
216
|
+
findings.append({"id": "opinion-check", "level": "unavailable", "area": _("个人规则"),
|
|
217
|
+
"title": _("行为规则版本无法检查"), "reason": item.get("error", ""),
|
|
218
|
+
"impact": _("只影响规则更新提示"), "next": []})
|
|
191
219
|
else:
|
|
192
|
-
ok.append("行为规则(已是锁定的最新版本)")
|
|
220
|
+
ok.append(_("行为规则(已是锁定的最新版本)"))
|
|
193
221
|
|
|
194
222
|
|
|
195
223
|
def _check_runtime(provider: Any, env: Any, latest: dict | None, findings: list[dict], ok: list[str],
|
|
@@ -201,27 +229,27 @@ def _check_runtime(provider: Any, env: Any, latest: dict | None, findings: list[
|
|
|
201
229
|
if machine is not None and not machine["findings"]:
|
|
202
230
|
return # 用户已决定不提示这台机器的运行时(决定存在用户状态目录,不进项目)
|
|
203
231
|
text = runtime.missing_text(data, runtime.command_status()) if hasattr(runtime, "missing_text") else {
|
|
204
|
-
"reason":
|
|
205
|
-
"impact": "现在能用;换一台没有 AI 客户端的机器或客户端插件被移除时会打不开",
|
|
206
|
-
"label": "安装运行时(只写用户数据目录)"}
|
|
232
|
+
"reason": _("本次由 {0} 提供;装好运行时后,不依赖 AI 客户端与 npx 也能打开菜单").format(data['running_from']),
|
|
233
|
+
"impact": _("现在能用;换一台没有 AI 客户端的机器或客户端插件被移除时会打不开"),
|
|
234
|
+
"label": _("安装运行时(只写用户数据目录)")}
|
|
207
235
|
decision = ({"id": "local:runtime-missing", "fingerprint": "runtime-missing", "scope": "machine"}
|
|
208
236
|
if machine is not None else None)
|
|
209
|
-
findings.append({"id": "install-runtime", "level": "suggest", "area": "运行时", "title": "这台机器还没有安装用户级运行时",
|
|
237
|
+
findings.append({"id": "install-runtime", "level": "suggest", "area": _("运行时"), "title": _("这台机器还没有安装用户级运行时"),
|
|
210
238
|
"reason": text["reason"], "impact": text["impact"],
|
|
211
239
|
"next": [{"label": text["label"], "action": "fix:install-runtime"}],
|
|
212
240
|
**({"decision": decision} if decision else {})})
|
|
213
241
|
elif data["update_available"]:
|
|
214
|
-
findings.append({"id": "update-runtime", "level": "update", "area": "运行时", "title": "运行时有新版本",
|
|
215
|
-
"reason":
|
|
216
|
-
"impact": "不更新也能继续使用", "next": [{"label": "下载并切换(旧版本保留)", "action": "fix:update-runtime"}]})
|
|
242
|
+
findings.append({"id": "update-runtime", "level": "update", "area": _("运行时"), "title": _("运行时有新版本"),
|
|
243
|
+
"reason": _("当前 {0},最新 {1}").format(active['version'], data['latest_release']),
|
|
244
|
+
"impact": _("不更新也能继续使用"), "next": [{"label": _("下载并切换(旧版本保留)"), "action": "fix:update-runtime"}]})
|
|
217
245
|
else:
|
|
218
|
-
ok.append(
|
|
246
|
+
ok.append(_("运行时 {0}").format(active['version']))
|
|
219
247
|
|
|
220
248
|
|
|
221
249
|
# ---------------------------------------------------------------- plan
|
|
222
250
|
|
|
223
251
|
FIXES = ("rebuild-index", "update-plugins", "update-content", "install-runtime", "update-runtime", "add-entry",
|
|
224
|
-
"add-skeleton", "profile", "repair-lock", "case-naming", "sync-folder")
|
|
252
|
+
"add-skeleton", "profile", "repair-lock", "case-naming", "sync-folder", "local-only")
|
|
225
253
|
# 可以带目标的处理项:fix add-skeleton <路径…>、fix profile <字段…>
|
|
226
254
|
TARGETED = ("add-skeleton", "profile")
|
|
227
255
|
|
|
@@ -238,7 +266,7 @@ def available_ids(provider: Any) -> list[str]:
|
|
|
238
266
|
found = []
|
|
239
267
|
for finding in health["findings"]:
|
|
240
268
|
for step in finding["next"]:
|
|
241
|
-
verb,
|
|
269
|
+
verb, _sep, target = step["action"].partition(":")
|
|
242
270
|
if verb == "fix" and target in FIXES and target not in found:
|
|
243
271
|
found.append(target)
|
|
244
272
|
return found
|
|
@@ -249,7 +277,7 @@ def plan(provider: Any, ids: list[str], choices: dict[str, str]) -> dict:
|
|
|
249
277
|
chosen = ids or offered
|
|
250
278
|
unknown = [fix_id for fix_id in chosen if fix_id not in FIXES]
|
|
251
279
|
if unknown:
|
|
252
|
-
raise EntryError("没有这些处理项:" + "、".join(unknown), "not-found", ["可处理:" + ("、".join(offered) or "(无)")])
|
|
280
|
+
raise EntryError(_("没有这些处理项:") + _("、").join(unknown), "not-found", [_("可处理:") + (_("、").join(offered) or _("(无)"))])
|
|
253
281
|
steps = [_plan_step(provider, fix_id, choices) for fix_id in chosen]
|
|
254
282
|
return {"steps": steps, "simulated": False, "update_source": (provider._health or {}).get("update_source")}
|
|
255
283
|
|
|
@@ -263,21 +291,21 @@ def _step(fix_id: str, title: str, **values: Any) -> dict:
|
|
|
263
291
|
|
|
264
292
|
def _need_host(provider: Any, fix_id: str, title: str) -> dict | None:
|
|
265
293
|
if provider.host is None:
|
|
266
|
-
return _step(fix_id, title, blocked="当前运行方式没有携带 agent-pack:用 agenthelm 运行时打开后再处理")
|
|
294
|
+
return _step(fix_id, title, blocked=_("当前运行方式没有携带 agent-pack:用 agenthelm 运行时打开后再处理"))
|
|
267
295
|
return None
|
|
268
296
|
|
|
269
297
|
|
|
270
298
|
def _plan_step(provider: Any, fix_id: str, choices: dict[str, str]) -> dict:
|
|
271
299
|
if fix_id == "rebuild-index":
|
|
272
300
|
state_dir = provider.assets_project().state_dir()
|
|
273
|
-
return _step(fix_id, "重建资料索引", changes=["按当前文件重新登记资料、版本与引用"],
|
|
274
|
-
writes=[{"path": str(state_dir), "scope": "用户缓存(不改项目文件)"}],
|
|
275
|
-
recovery="不涉及项目文件;索引可随时再次重建", verify="重新读取索引状态")
|
|
301
|
+
return _step(fix_id, _("重建资料索引"), changes=[_("按当前文件重新登记资料、版本与引用")],
|
|
302
|
+
writes=[{"path": str(state_dir), "scope": _("用户缓存(不改项目文件)")}],
|
|
303
|
+
recovery=_("不涉及项目文件;索引可随时再次重建"), verify=_("重新读取索引状态"))
|
|
276
304
|
if fix_id == "add-entry":
|
|
277
305
|
return _plan_entry(provider, choices)
|
|
278
306
|
if fix_id in ("add-skeleton", "profile", "repair-lock"):
|
|
279
307
|
return _plan_scaffold(provider, fix_id, choices)
|
|
280
|
-
if fix_id in ("case-naming", "sync-folder"):
|
|
308
|
+
if fix_id in ("case-naming", "sync-folder", "local-only"):
|
|
281
309
|
return _plan_guidance(provider, fix_id)
|
|
282
310
|
blocked = _need_host(provider, fix_id, fix_id)
|
|
283
311
|
if blocked:
|
|
@@ -288,34 +316,51 @@ def _plan_step(provider: Any, fix_id: str, choices: dict[str, str]) -> dict:
|
|
|
288
316
|
return _plan_runtime(provider, env, fix_id)
|
|
289
317
|
report = getattr(provider, "_report", None)
|
|
290
318
|
if report is None and fix_id != "update-content":
|
|
291
|
-
return _step(fix_id, fix_id, blocked="版本信息不可用(离线且没有缓存):联网后重新检查")
|
|
319
|
+
return _step(fix_id, fix_id, blocked=_("版本信息不可用(离线且没有缓存):联网后重新检查"))
|
|
292
320
|
if fix_id == "update-plugins":
|
|
293
321
|
steps = host.update_steps(env, report, None, None, env.home, [], [], None, "plugins")
|
|
294
322
|
behind = [item for item in report["plugins"] if item["status"] == "behind"]
|
|
295
|
-
changes = [
|
|
323
|
+
changes = [_("{0} → {1}:{2}").format(item['plugin'], step['to'], step['summary']) for item in behind for step in item["steps"]]
|
|
296
324
|
actions = [action for item in behind for step in item["steps"] for action in step["actions"]]
|
|
297
325
|
blocked = next((step.blocked for step in steps if step.blocked), "") or \
|
|
298
|
-
("当前离线:需要联网,只能预览" if provider.offline else "")
|
|
299
|
-
return _step(fix_id, "更新客户端里的插件", network=True, changes=changes + [
|
|
300
|
-
writes=[{"path": step.description + (
|
|
301
|
-
"scope": "客户端插件目录"} for step in steps],
|
|
326
|
+
(_("当前离线:需要联网,只能预览") if provider.offline else "")
|
|
327
|
+
return _step(fix_id, _("更新客户端里的插件"), network=True, changes=changes + [_("需要的动作:{0}").format(a) for a in actions],
|
|
328
|
+
writes=[{"path": step.description + (_("({0})").format(' '.join(step.command)) if step.command else ""),
|
|
329
|
+
"scope": _("客户端插件目录")} for step in steps],
|
|
302
330
|
breaking=any(item["breaking"] for item in behind),
|
|
303
|
-
recovery="客户端保留旧版本缓存;需要时用客户端命令回到旧版本",
|
|
304
|
-
verify="重新检查各客户端已安装的版本", blocked=blocked)
|
|
331
|
+
recovery=_("客户端保留旧版本缓存;需要时用客户端命令回到旧版本"),
|
|
332
|
+
verify=_("重新检查各客户端已安装的版本"), blocked=blocked)
|
|
305
333
|
return _plan_content(provider, env, report, choices)
|
|
306
334
|
|
|
307
335
|
|
|
308
|
-
|
|
336
|
+
APPENDABLE = {"AGENTS.md", "CLAUDE.md"} # agents-init 可以在这两个文件末尾追加带标记的区块、保留原文
|
|
337
|
+
|
|
338
|
+
|
|
339
|
+
def _content_flags(append: list[str], confirm: list[str], merge: list[str] | None = None, pick: list[str] | None = None,
|
|
340
|
+
diff: list[str] | None = None) -> list[str]:
|
|
341
|
+
return [value for flag, paths in (("--append", append), ("--confirm-discard", confirm), ("--merge", merge or []),
|
|
342
|
+
("--pick", pick or []), ("--diff", diff or []))
|
|
343
|
+
for path in paths for value in (flag, path)]
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
def _choice_list(choices: dict[str, str], key: str) -> list[str]:
|
|
347
|
+
return [value for value in (choices.get(key) or "").split("\n") if value]
|
|
348
|
+
|
|
349
|
+
|
|
350
|
+
def _run_refresh(provider: Any, accept: list[str], keep: list[str], recovery: Path, *, apply: bool,
|
|
351
|
+
append: list[str] | None = None, confirm: list[str] | None = None, merge: list[str] | None = None,
|
|
352
|
+
pick: list[str] | None = None, diff: list[str] | None = None) -> dict:
|
|
309
353
|
"""agents-init 的 refresh:模板包版本没有更新、但有文件与当前模板不同(例如没有基线)时直接用它。"""
|
|
310
354
|
script = _init_script(provider)
|
|
311
355
|
if script is None:
|
|
312
|
-
raise EntryError("找不到支持刷新的 agents-init", "unavailable", ["更新插件或运行时后再试"])
|
|
356
|
+
raise EntryError(_("找不到支持刷新的 agents-init"), "unavailable", [_("更新插件或运行时后再试")])
|
|
313
357
|
command = [sys.executable, str(script), "--project", str(provider.root), "--mode", "refresh", "--output", "json"]
|
|
314
358
|
for path in accept:
|
|
315
359
|
command += ["--accept", path]
|
|
316
360
|
for path in keep:
|
|
317
361
|
command += ["--keep", path]
|
|
318
|
-
|
|
362
|
+
command += _content_flags(append or [], confirm or [], merge, pick, diff)
|
|
363
|
+
if apply or accept or append or merge:
|
|
319
364
|
command += ["--recovery-dir", str(recovery)]
|
|
320
365
|
if apply:
|
|
321
366
|
command.append("--apply")
|
|
@@ -323,17 +368,20 @@ def _run_refresh(provider: Any, accept: list[str], keep: list[str], recovery: Pa
|
|
|
323
368
|
try:
|
|
324
369
|
result = json.loads(completed.stdout)
|
|
325
370
|
except ValueError as exc:
|
|
326
|
-
raise EntryError("agents-init 没有返回结果:" + (completed.stderr or "").strip()[:200], "failed") from exc
|
|
371
|
+
raise EntryError(_("agents-init 没有返回结果:") + (completed.stderr or "").strip()[:200], "failed") from exc
|
|
327
372
|
if "files" not in result:
|
|
328
|
-
raise EntryError(str(result.get("error") or "agents-init 拒绝"), "failed")
|
|
373
|
+
raise EntryError(str(result.get("error") or _("agents-init 拒绝")), "failed")
|
|
329
374
|
return result
|
|
330
375
|
|
|
331
376
|
|
|
332
377
|
def _content_preview(provider: Any, env: Any, report: dict | None, accept: list[str], keep: list[str],
|
|
333
|
-
recovery: Path
|
|
378
|
+
recovery: Path, append: list[str], confirm: list[str],
|
|
379
|
+
merge: list[str] | None = None, pick: list[str] | None = None,
|
|
380
|
+
diff: list[str] | None = None) -> tuple[str, list[dict], str, bool]:
|
|
334
381
|
"""(说明, 文件计划, 阻塞原因, 是否走 refresh 直通路径)。"""
|
|
335
382
|
host = provider.host
|
|
336
|
-
steps = host.update_steps(env, report, provider.root, None, env.home, accept, keep, recovery, "content"
|
|
383
|
+
steps = host.update_steps(env, report, provider.root, None, env.home, accept, keep, recovery, "content",
|
|
384
|
+
content_flags=_content_flags(append, confirm, merge, pick, diff)) \
|
|
337
385
|
if report is not None else []
|
|
338
386
|
if steps:
|
|
339
387
|
step = steps[0]
|
|
@@ -341,24 +389,29 @@ def _content_preview(provider: Any, env: Any, report: dict | None, accept: list[
|
|
|
341
389
|
return step.description, [], step.blocked, False
|
|
342
390
|
preview = host.execute_steps([step], apply=False, recovery_root=None, child_env=env.child_environment())[0]
|
|
343
391
|
if preview.get("status") == "failed":
|
|
344
|
-
return step.description, [], preview.get("error", "预览失败"), False
|
|
392
|
+
return step.description, [], preview.get("error", _("预览失败")), False
|
|
345
393
|
return step.description, (preview.get("result") or {}).get("files") or [], "", False
|
|
346
394
|
try:
|
|
347
|
-
result = _run_refresh(provider, accept, keep, recovery, apply=False
|
|
395
|
+
result = _run_refresh(provider, accept, keep, recovery, apply=False, append=append, confirm=confirm,
|
|
396
|
+
merge=merge, pick=pick, diff=diff)
|
|
348
397
|
except EntryError as exc:
|
|
349
|
-
return "项目模板/样例", [], str(exc), True
|
|
398
|
+
return _("项目模板/样例"), [], str(exc), True
|
|
350
399
|
files = result.get("files") or []
|
|
351
400
|
if all(item["state"] in ("unchanged", "kept-by-decision") for item in files):
|
|
352
|
-
return "项目模板/样例", [], "没有需要更新的模板", True
|
|
353
|
-
return "按当前模板对比项目契约文件", files, "", True
|
|
401
|
+
return _("项目模板/样例"), [], _("没有需要更新的模板"), True
|
|
402
|
+
return _("按当前模板对比项目契约文件"), files, "", True
|
|
354
403
|
|
|
355
404
|
|
|
356
405
|
def _plan_content(provider: Any, env: Any, report: dict | None, choices: dict[str, str]) -> dict:
|
|
357
406
|
host = provider.host
|
|
358
407
|
accept = sorted(path for path, choice in choices.items() if choice == "accept")
|
|
359
|
-
|
|
408
|
+
merge, pick, diff = (_choice_list(choices, key) for key in ("_merge", "_pick", "_diff"))
|
|
409
|
+
keep = sorted(path for path, choice in choices.items() if choice == "keep" and path not in merge)
|
|
410
|
+
append = sorted(path for path, choice in choices.items() if choice == "append")
|
|
411
|
+
confirm = _choice_list(choices, "_confirm")
|
|
360
412
|
recovery = Path(choices.get("_recovery") or host.recovery_dir_for(env, "content"))
|
|
361
|
-
description, files, error, direct = _content_preview(provider, env, report, accept, keep, recovery
|
|
413
|
+
description, files, error, direct = _content_preview(provider, env, report, accept, keep, recovery, append, confirm,
|
|
414
|
+
merge, pick, diff)
|
|
362
415
|
if error:
|
|
363
416
|
return _step("update-content", description, blocked=error)
|
|
364
417
|
|
|
@@ -367,11 +420,14 @@ def _plan_content(provider: Any, env: Any, report: dict | None, choices: dict[st
|
|
|
367
420
|
|
|
368
421
|
step = _Step()
|
|
369
422
|
step.description = description
|
|
370
|
-
custom = [{"path": item["path"], "state": "你改过", "default": "keep"
|
|
371
|
-
|
|
423
|
+
custom = [{"path": item["path"], "state": _("你改过"), "default": "keep", "content": True,
|
|
424
|
+
"lost": item.get("lines_lost", 0), "append": item["path"] in APPENDABLE, "reason": item.get("reason")}
|
|
425
|
+
for item in files
|
|
426
|
+
if item["action"] != "merge" # 三方合并的文件已由 --merge 决定,不再是“保留/采用”的选择
|
|
427
|
+
and (item["state"] == "modified" or (item["path"] in choices and item["state"] in ("modified", "missing")))]
|
|
372
428
|
for item in files:
|
|
373
429
|
if item["state"] == "missing" and not any(entry["path"] == item["path"] for entry in custom):
|
|
374
|
-
custom.append({"path": item["path"], "state": "新文件(目前不存在)", "default": "keep"})
|
|
430
|
+
custom.append({"path": item["path"], "state": _("新文件(目前不存在)"), "default": "keep"})
|
|
375
431
|
effective = {item["path"]: choices.get(item["path"], item["default"]) for item in custom}
|
|
376
432
|
writes = []
|
|
377
433
|
for item in files:
|
|
@@ -380,56 +436,67 @@ def _plan_content(provider: Any, env: Any, report: dict | None, choices: dict[st
|
|
|
380
436
|
action = "replace" if effective.get(item["path"]) == "accept" else "keep"
|
|
381
437
|
if action == "skip":
|
|
382
438
|
action = "create" if effective.get(item["path"]) == "accept" else "keep"
|
|
383
|
-
if action in ("replace", "create"):
|
|
384
|
-
|
|
439
|
+
if action in ("replace", "create", "append", "merge"):
|
|
440
|
+
scope = {"replace": _("项目(先备份)"), "create": _("项目(新建)"), "append": _("项目(先备份,只追加区块)"),
|
|
441
|
+
"merge": _("项目(先备份,三方合并)")}[action]
|
|
442
|
+
writes.append({"path": item["path"], "scope": scope})
|
|
385
443
|
# 刷新总会把内容锁更新到新版本(保留的文件沿用旧基线),所以它总在写入范围里。
|
|
386
|
-
writes.append({"path": ".agents/moe.sakanano.agent-pack/content.lock.json", "scope": "项目(内容锁)"})
|
|
444
|
+
writes.append({"path": ".agents/moe.sakanano.agent-pack/content.lock.json", "scope": _("项目(内容锁)")})
|
|
445
|
+
diffs = {item["path"]: item["diff"] for item in files if item.get("diff")}
|
|
387
446
|
return _step("update-content", step.description, changes=[_content_change(item, effective) for item in files],
|
|
388
447
|
writes=writes, custom=custom, recovery=str(recovery),
|
|
389
|
-
verify="重新检查模板版本;保留的文件内容不变",
|
|
390
|
-
payload={"recovery": str(recovery), "files": files, "direct": direct
|
|
448
|
+
verify=_("重新检查模板版本;保留的文件内容不变"),
|
|
449
|
+
payload={"recovery": str(recovery), "files": files, "direct": direct, "diffs": diffs, "confirm": confirm,
|
|
450
|
+
"merge": merge, "pick": pick})
|
|
391
451
|
|
|
392
452
|
|
|
393
|
-
CONTENT_STATE = {"unchanged": "与新模板相同", "clean": "没改过", "modified": "你改过", "missing": "目前不存在",
|
|
394
|
-
"local-only": "只有你的改动,新模板没变"}
|
|
395
|
-
CONTENT_ACTION = {"keep": "保留", "replace": "换成新模板(先备份)", "create": "新建", "skip": "不新建",
|
|
396
|
-
"blocked": "需要你选择"}
|
|
453
|
+
CONTENT_STATE = {"unchanged": N_("与新模板相同"), "clean": N_("没改过"), "modified": N_("你改过"), "missing": N_("目前不存在"),
|
|
454
|
+
"local-only": N_("只有你的改动,新模板没变"), "kept-by-decision": N_("你已决定保留")}
|
|
455
|
+
CONTENT_ACTION = {"keep": N_("保留"), "replace": N_("换成新模板(先备份)"), "create": N_("新建"), "skip": N_("不新建"),
|
|
456
|
+
"blocked": N_("需要你选择"), "merge": N_("三方合并(先备份)"), "append": N_("保留原文,末尾追加带标记的区块(先备份)")}
|
|
397
457
|
|
|
398
458
|
|
|
399
459
|
def _content_change(item: dict, effective: dict[str, str]) -> str:
|
|
400
460
|
action = item["action"]
|
|
461
|
+
chosen = effective.get(item["path"], "keep")
|
|
401
462
|
if action in ("blocked", "skip"):
|
|
402
|
-
chosen = effective.get(item["path"], "keep")
|
|
403
463
|
action = ("replace" if action == "blocked" else "create") if chosen == "accept" else \
|
|
404
464
|
("keep" if action == "blocked" else "skip")
|
|
405
|
-
|
|
406
|
-
|
|
465
|
+
if chosen == "append" and item["state"] == "modified":
|
|
466
|
+
action = "append"
|
|
467
|
+
note = _("(保留则不含新模板的改动)") if item["state"] == "modified" and action == "keep" else ""
|
|
468
|
+
if item["state"] == "modified" and "local_lines" in item and action != "merge":
|
|
469
|
+
note += _("(本地 {0} 行,新模板 {1} 行;采用新模板会丢弃 {2} 行本地内容)").format(
|
|
470
|
+
item["local_lines"], item["template_lines"], item["lines_lost"])
|
|
471
|
+
if item.get("reason") == "no-baseline" and item["state"] == "modified":
|
|
472
|
+
note += _("(内容锁里没有它的基线,无法判断是你改过还是模板变了)")
|
|
473
|
+
return _("{0}:{1} → {2}{3}").format(item['path'], _(CONTENT_STATE.get(item['state'], item['state'])), _(CONTENT_ACTION.get(action, action)), note)
|
|
407
474
|
|
|
408
475
|
|
|
409
476
|
def _plan_runtime(provider: Any, env: Any, fix_id: str) -> dict:
|
|
410
477
|
runtime = runtime_module(provider.host)
|
|
411
478
|
host = provider.host
|
|
412
|
-
title = "安装用户级运行时" if fix_id == "install-runtime" else "更新用户级运行时"
|
|
479
|
+
title = _("安装用户级运行时") if fix_id == "install-runtime" else _("更新用户级运行时")
|
|
413
480
|
if fix_id == "install-runtime" and runtime.bundled_root() is not None:
|
|
414
|
-
root, origin = runtime.bundled_root(), "随附内容"
|
|
481
|
+
root, origin = runtime.bundled_root(), _("随附内容")
|
|
415
482
|
network = False
|
|
416
483
|
else:
|
|
417
484
|
if provider.offline:
|
|
418
|
-
return _step(fix_id, title, network=True, blocked="当前离线:需要下载发布包,只能预览;也可用 agenthelm runtime install --source <发布包>")
|
|
485
|
+
return _step(fix_id, title, network=True, blocked=_("当前离线:需要下载发布包,只能预览;也可用 agenthelm runtime install --source <发布包>"))
|
|
419
486
|
try:
|
|
420
|
-
latest,
|
|
487
|
+
latest, latest_origin = host.load_latest(env, None)
|
|
421
488
|
except (host.CheckError, OSError, ValueError) as exc:
|
|
422
|
-
return _step(fix_id, title, network=True, blocked=
|
|
489
|
+
return _step(fix_id, title, network=True, blocked=_("拿不到版本信息:{0}").format(exc))
|
|
423
490
|
version = runtime.release_version(latest)
|
|
424
|
-
return _step(fix_id, title, network=True, changes=[
|
|
425
|
-
writes=[{"path": str(runtime.runtimes_dir(env) / (version or "<最新版本>")), "scope": "用户数据目录(新版本)"},
|
|
426
|
-
{"path": str(runtime.current_link(env)), "scope": "切换当前版本"}],
|
|
427
|
-
recovery="旧版本保留;agenthelm runtime use <旧版本> --apply 切回", verify="重新读取当前运行时版本",
|
|
491
|
+
return _step(fix_id, title, network=True, changes=[_("下载发布包 {0} 并核对摘要").format(version or _('(最新)')), host.origin_line(latest_origin)],
|
|
492
|
+
writes=[{"path": str(runtime.runtimes_dir(env) / (version or _("<最新版本>"))), "scope": _("用户数据目录(新版本)")},
|
|
493
|
+
{"path": str(runtime.current_link(env)), "scope": _("切换当前版本")}],
|
|
494
|
+
recovery=_("旧版本保留;agenthelm runtime use <旧版本> --apply 切回"), verify=_("重新读取当前运行时版本"),
|
|
428
495
|
payload={"from_release": True})
|
|
429
496
|
planned = runtime.plan(env, root, origin)
|
|
430
|
-
return _step(fix_id, title, network=network, changes=[
|
|
431
|
-
writes=planned["writes"], recovery="旧版本保留;agenthelm runtime use <旧版本> --apply 切回",
|
|
432
|
-
verify="重新读取当前运行时版本", payload={"from_release": False, "plan": planned})
|
|
497
|
+
return _step(fix_id, title, network=network, changes=[_("运行时 {0}({1})").format(planned['version'], origin)],
|
|
498
|
+
writes=planned["writes"], recovery=_("旧版本保留;agenthelm runtime use <旧版本> --apply 切回"),
|
|
499
|
+
verify=_("重新读取当前运行时版本"), payload={"from_release": False, "plan": planned})
|
|
433
500
|
|
|
434
501
|
|
|
435
502
|
def _init_script(provider: Any) -> Path | None:
|
|
@@ -447,7 +514,7 @@ def _init_script(provider: Any) -> Path | None:
|
|
|
447
514
|
def _run_init(provider: Any, name: str, choices: dict[str, str], recovery: str, *, apply: bool) -> dict:
|
|
448
515
|
script = _init_script(provider)
|
|
449
516
|
if script is None:
|
|
450
|
-
raise EntryError("找不到支持生成入口的 agents-init", "unavailable", ["更新插件或运行时后再试"])
|
|
517
|
+
raise EntryError(_("找不到支持生成入口的 agents-init"), "unavailable", [_("更新插件或运行时后再试")])
|
|
451
518
|
command = [sys.executable, str(script), "--project", str(provider.root), "--mode", "entry",
|
|
452
519
|
"--entry-name", name, "--output", "json"]
|
|
453
520
|
if choices.get(name) in ("keep", "accept"):
|
|
@@ -462,7 +529,7 @@ def _run_init(provider: Any, name: str, choices: dict[str, str], recovery: str,
|
|
|
462
529
|
try:
|
|
463
530
|
return json.loads(completed.stdout)
|
|
464
531
|
except ValueError as exc:
|
|
465
|
-
raise EntryError("agents-init 没有返回结果:" + (completed.stderr or "").strip()[:200], "failed") from exc
|
|
532
|
+
raise EntryError(_("agents-init 没有返回结果:") + (completed.stderr or "").strip()[:200], "failed") from exc
|
|
466
533
|
|
|
467
534
|
|
|
468
535
|
def _recovery_dir(provider: Any, label: str) -> str:
|
|
@@ -475,8 +542,8 @@ def _recovery_dir(provider: Any, label: str) -> str:
|
|
|
475
542
|
def _plan_entry(provider: Any, choices: dict[str, str]) -> dict:
|
|
476
543
|
name = choices.get("entry-name") or provider.launcher() or DEFAULT_LAUNCHER
|
|
477
544
|
if not LAUNCHER_RE.fullmatch(name):
|
|
478
|
-
raise EntryError(
|
|
479
|
-
title =
|
|
545
|
+
raise EntryError(_("启动器名称不合法:{0}").format(name), "usage", [_("只能用字母、数字、. _ -,例如 menu、go")])
|
|
546
|
+
title = _("生成根目录启动器 ./{0}").format(name) if provider.launcher() != name else _("完善入口 ./{0}").format(name)
|
|
480
547
|
recovery = choices.get("_recovery") or _recovery_dir(provider, "entry")
|
|
481
548
|
try:
|
|
482
549
|
result = _run_init(provider, name, choices, recovery, apply=False)
|
|
@@ -486,23 +553,23 @@ def _plan_entry(provider: Any, choices: dict[str, str]) -> dict:
|
|
|
486
553
|
except EntryError as exc:
|
|
487
554
|
return _step("add-entry", title, blocked=str(exc))
|
|
488
555
|
if result.get("code"):
|
|
489
|
-
return _step("add-entry", title, blocked=result.get("error", "agents-init 拒绝"))
|
|
556
|
+
return _step("add-entry", title, blocked=result.get("error", _("agents-init 拒绝")))
|
|
490
557
|
entry = result.get("entry") or {}
|
|
491
|
-
custom = [{"path": name, "state": "已有同名文件(你的)", "default": "keep"}] \
|
|
558
|
+
custom = [{"path": name, "state": _("已有同名文件(你的)"), "default": "keep"}] \
|
|
492
559
|
if entry.get("action") in ("keep", "replace", "blocked") else []
|
|
493
560
|
readme = provider.root / "README.md"
|
|
494
561
|
has_section = readme.is_file() and "<!-- agenthelm:entry -->" in readme.read_text(encoding="utf-8", errors="replace")
|
|
495
562
|
if not has_section:
|
|
496
|
-
custom.append({"path": "README.md", "state": "可追加「怎样使用」一节(带标记)", "default": "keep"})
|
|
497
|
-
writes = [{"path": path, "scope": "项目"} for path in entry.get("writes", [])]
|
|
563
|
+
custom.append({"path": "README.md", "state": _("可追加「怎样使用」一节(带标记)"), "default": "keep"})
|
|
564
|
+
writes = [{"path": path, "scope": _("项目")} for path in entry.get("writes", [])]
|
|
498
565
|
return _step("add-entry", title, changes=entry.get("changes", []), writes=writes, custom=custom,
|
|
499
|
-
recovery=recovery if choices.get(name) == "accept" else "新增文件可直接删除;Profile 改动前后见预览",
|
|
500
|
-
verify=
|
|
566
|
+
recovery=recovery if choices.get(name) == "accept" else _("新增文件可直接删除;Profile 改动前后见预览"),
|
|
567
|
+
verify=_("重新读取 Profile 的 entry 段与 ./{0}").format(name), payload={"name": name, "recovery": recovery})
|
|
501
568
|
|
|
502
569
|
|
|
503
570
|
# ---------------------------------------------------------------- scaffold fixes
|
|
504
571
|
|
|
505
|
-
SCAFFOLD_TITLE = {"add-skeleton": "补上缺少的骨架文件", "profile": "修正 Profile 字段", "repair-lock": "修复内容锁版本"}
|
|
572
|
+
SCAFFOLD_TITLE = {"add-skeleton": N_("补上缺少的骨架文件"), "profile": N_("修正 Profile 字段"), "repair-lock": N_("修复内容锁版本")}
|
|
506
573
|
DECISIONS_FILE = ".agents/moe.sakanano.agent-pack/check-decisions.json"
|
|
507
574
|
|
|
508
575
|
|
|
@@ -514,14 +581,14 @@ def scaffold_module(provider: Any) -> Any | None:
|
|
|
514
581
|
def _preview_lines(text: str, limit: int = 30) -> str:
|
|
515
582
|
lines = text.splitlines()
|
|
516
583
|
shown = [f"+{line}" for line in lines[:limit]]
|
|
517
|
-
return "\n".join(shown + ([
|
|
584
|
+
return "\n".join(shown + ([_("... 还有 {0} 行").format(len(lines) - limit)] if len(lines) > limit else [])) or _("(空文件)")
|
|
518
585
|
|
|
519
586
|
|
|
520
587
|
def _plan_scaffold(provider: Any, fix_id: str, choices: dict[str, str]) -> dict:
|
|
521
|
-
title = SCAFFOLD_TITLE[fix_id]
|
|
588
|
+
title = _(SCAFFOLD_TITLE[fix_id])
|
|
522
589
|
module = scaffold_module(provider)
|
|
523
590
|
if module is None:
|
|
524
|
-
return _step(fix_id, title, blocked="需要带脚手架检查的 agents-init(更新插件或运行时后再试)")
|
|
591
|
+
return _step(fix_id, title, blocked=_("需要带脚手架检查的 agents-init(更新插件或运行时后再试)"))
|
|
525
592
|
root = provider.root
|
|
526
593
|
state_dir = provider.host.current_env().state_dir
|
|
527
594
|
wanted = [item for item in (choices.get("_targets") or "").split("\n") if item]
|
|
@@ -531,9 +598,9 @@ def _plan_scaffold(provider: Any, fix_id: str, choices: dict[str, str]) -> dict:
|
|
|
531
598
|
if result["blocked"]:
|
|
532
599
|
return _step(fix_id, title, blocked=result["blocked"])
|
|
533
600
|
return _step(fix_id, title, changes=result["changes"] + [result["diff"]] if result["diff"] else result["changes"],
|
|
534
|
-
writes=[{"path": ".agents/moe.sakanano.agent-pack/content.lock.json", "scope": "项目(内容锁)"}],
|
|
535
|
-
recovery="内容锁由工具生成;写入前再次核对内容未变,可用 git 或同步盘历史还原",
|
|
536
|
-
verify="重新检查:内容锁不再显示 0.0.0")
|
|
601
|
+
writes=[{"path": ".agents/moe.sakanano.agent-pack/content.lock.json", "scope": _("项目(内容锁)")}],
|
|
602
|
+
recovery=_("内容锁由工具生成;写入前再次核对内容未变,可用 git 或同步盘历史还原"),
|
|
603
|
+
verify=_("重新检查:内容锁不再显示 0.0.0"))
|
|
537
604
|
report = module.check(root, state_dir=state_dir, reprompt=True)
|
|
538
605
|
recovery = Path(choices.get("_recovery") or _recovery_dir(provider, fix_id))
|
|
539
606
|
if fix_id == "add-skeleton":
|
|
@@ -541,50 +608,50 @@ def _plan_scaffold(provider: Any, fix_id: str, choices: dict[str, str]) -> dict:
|
|
|
541
608
|
rows = [p for p in rows if not wanted or p in wanted]
|
|
542
609
|
unknown = [p for p in wanted if p not in {r["path"] for r in report["skeleton"]}]
|
|
543
610
|
if unknown:
|
|
544
|
-
raise EntryError("不在期望骨架清单里:" + "、".join(unknown), "usage")
|
|
611
|
+
raise EntryError(_("不在期望骨架清单里:") + _("、").join(unknown), "usage")
|
|
545
612
|
if not rows:
|
|
546
|
-
return _step(fix_id, title, blocked="没有缺少的骨架文件")
|
|
613
|
+
return _step(fix_id, title, blocked=_("没有缺少的骨架文件"))
|
|
547
614
|
ctx = module.Context(root)
|
|
548
|
-
custom = [{"path": p, "state": "缺少", "default": "accept", "options": True} for p in rows]
|
|
615
|
+
custom = [{"path": p, "state": _("缺少"), "default": "accept", "options": True} for p in rows]
|
|
549
616
|
decided = {p: choices.get(p, "accept") for p in rows}
|
|
550
617
|
accepted = [p for p, choice in decided.items() if choice == "accept"]
|
|
551
618
|
preview = module.add_skeleton(root, accepted, apply=False, state_dir=state_dir) if accepted else \
|
|
552
619
|
{"create": [], "unchanged": []}
|
|
553
|
-
writes = [{"path": item["path"], "scope": "项目(新建)"} for item in preview["create"]]
|
|
620
|
+
writes = [{"path": item["path"], "scope": _("项目(新建)")} for item in preview["create"]]
|
|
554
621
|
other = {p: c for p, c in decided.items() if c != "accept"}
|
|
555
622
|
if other:
|
|
556
|
-
writes.append({"path": DECISIONS_FILE, "scope": "项目(决定文件,随项目同步)"})
|
|
557
|
-
return _step(fix_id, title, changes=[
|
|
623
|
+
writes.append({"path": DECISIONS_FILE, "scope": _("项目(决定文件,随项目同步)")})
|
|
624
|
+
return _step(fix_id, title, changes=[_("{0}:{1}").format(p, {'accept': _('新建'), 'skip': _('永久跳过'), 'later': _('稍后')}[c])
|
|
558
625
|
for p, c in decided.items()],
|
|
559
626
|
writes=writes, custom=custom,
|
|
560
|
-
recovery="只新建文件,已有文件不会被改动;新建的可直接删除",
|
|
561
|
-
verify="重新检查:这些文件不再显示为缺少",
|
|
627
|
+
recovery=_("只新建文件,已有文件不会被改动;新建的可直接删除"),
|
|
628
|
+
verify=_("重新检查:这些文件不再显示为缺少"),
|
|
562
629
|
payload={"accepted": accepted, "decisions": other, "recovery": str(recovery),
|
|
563
630
|
"diffs": {p: _preview_lines(ctx.expected_text(p) or "") for p in rows}})
|
|
564
631
|
# profile
|
|
565
632
|
rows = {row["field"]: row for row in report["profile"] if row["state"] != "ok" and row["mode"] in ("default", "equal")}
|
|
566
633
|
unknown = [f for f in wanted if f not in rows]
|
|
567
634
|
if unknown:
|
|
568
|
-
raise EntryError("这些字段不需要或不能自动修复:" + "、".join(unknown), "usage")
|
|
635
|
+
raise EntryError(_("这些字段不需要或不能自动修复:") + _("、").join(unknown), "usage")
|
|
569
636
|
fields = [f for f in rows if not wanted or f in wanted]
|
|
570
637
|
if not fields:
|
|
571
|
-
return _step(fix_id, title, blocked="没有需要修正的 Profile 字段")
|
|
638
|
+
return _step(fix_id, title, blocked=_("没有需要修正的 Profile 字段"))
|
|
572
639
|
decided = {f: choices.get(f, "accept") for f in fields}
|
|
573
640
|
accepted = [f for f, choice in decided.items() if choice == "accept"]
|
|
574
641
|
diffs = {f: module.fix_profile(root, [f], apply=False, state_dir=state_dir)["diff"] for f in fields}
|
|
575
642
|
writes = []
|
|
576
643
|
if accepted:
|
|
577
|
-
writes.append({"path": ".agents/moe.sakanano.agent-pack/project.json", "scope": "项目(先备份)"})
|
|
644
|
+
writes.append({"path": ".agents/moe.sakanano.agent-pack/project.json", "scope": _("项目(先备份)")})
|
|
578
645
|
other = {f: c for f, c in decided.items() if c != "accept"}
|
|
579
646
|
if other:
|
|
580
|
-
writes.append({"path": DECISIONS_FILE, "scope": "项目(决定文件,随项目同步)"})
|
|
647
|
+
writes.append({"path": DECISIONS_FILE, "scope": _("项目(决定文件,随项目同步)")})
|
|
581
648
|
return _step(fix_id, title,
|
|
582
649
|
changes=[f"{f} → {json.dumps(rows[f]['expected'], ensure_ascii=False)}"
|
|
583
|
-
if decided[f] == "accept" else
|
|
650
|
+
if decided[f] == "accept" else _("{0}:{1}").format(f, {'skip': _('永久跳过'), 'later': _('稍后')}[decided[f]])
|
|
584
651
|
for f in fields],
|
|
585
|
-
writes=writes, custom=[{"path": f, "state": "缺少" if rows[f]["state"] == "missing" else "不符合",
|
|
652
|
+
writes=writes, custom=[{"path": f, "state": _("缺少") if rows[f]["state"] == "missing" else _("不符合"),
|
|
586
653
|
"default": "accept", "options": True} for f in fields],
|
|
587
|
-
recovery=str(recovery), verify="重新检查:这些字段不再显示为缺少或不符合",
|
|
654
|
+
recovery=str(recovery), verify=_("重新检查:这些字段不再显示为缺少或不符合"),
|
|
588
655
|
payload={"accepted": accepted, "decisions": other, "recovery": str(recovery), "diffs": diffs})
|
|
589
656
|
except Exception as exc: # noqa: BLE001 - init errors come from a separately loaded module copy
|
|
590
657
|
if isinstance(exc, EntryError):
|
|
@@ -592,62 +659,82 @@ def _plan_scaffold(provider: Any, fix_id: str, choices: dict[str, str]) -> dict:
|
|
|
592
659
|
return _step(fix_id, title, blocked=str(exc))
|
|
593
660
|
|
|
594
661
|
|
|
595
|
-
PLAN_ONLY = "只给方案,不会自动执行;按方案自己处理后重新检查"
|
|
662
|
+
PLAN_ONLY = N_("只给方案,不会自动执行;按方案自己处理后重新检查")
|
|
596
663
|
|
|
597
664
|
|
|
598
665
|
def _plan_guidance(provider: Any, fix_id: str) -> dict:
|
|
599
666
|
"""Plan-only items: they explain what to do and change nothing (no directory moves, no deletions)."""
|
|
600
667
|
if fix_id == "case-naming":
|
|
601
|
-
title = "Case 目录命名:改名计划"
|
|
668
|
+
title = _("Case 目录命名:改名计划")
|
|
602
669
|
module = scaffold_module(provider)
|
|
603
670
|
if module is None:
|
|
604
|
-
return _step(fix_id, title, blocked="需要带脚手架检查的 agents-init(更新插件或运行时后再试)")
|
|
671
|
+
return _step(fix_id, title, blocked=_("需要带脚手架检查的 agents-init(更新插件或运行时后再试)"))
|
|
605
672
|
try:
|
|
606
673
|
plan = module.case_naming_plan(provider.root)
|
|
607
674
|
except Exception as exc: # noqa: BLE001
|
|
608
675
|
return _step(fix_id, title, blocked=str(_entry_error(exc)))
|
|
609
676
|
if plan["error"]:
|
|
610
|
-
return _step(fix_id, title, blocked="Profile 的 work.case.directory_naming 无法使用:" + plan["error"])
|
|
677
|
+
return _step(fix_id, title, blocked=_("Profile 的 work.case.directory_naming 无法使用:") + plan["error"])
|
|
611
678
|
if not plan["renames"]:
|
|
612
|
-
return _step(fix_id, title, blocked="Case 目录命名与规则一致,没有需要改的")
|
|
679
|
+
return _step(fix_id, title, blocked=_("Case 目录命名与规则一致,没有需要改的"))
|
|
613
680
|
changes = []
|
|
614
681
|
for item in plan["renames"]:
|
|
615
|
-
line = f"{item['from']} → {item['to'] or '(需要你决定新名字)'}"
|
|
682
|
+
line = f"{item['from']} → {item['to'] or _('(需要你决定新名字)')}"
|
|
616
683
|
if item["references"]:
|
|
617
|
-
line +=
|
|
618
|
-
+ (
|
|
684
|
+
line += _(";被这些文件提到,改名后要同步:{0}").format(_('、').join(item['references'][:5])) \
|
|
685
|
+
+ (_(" 等 {0} 个").format(len(item['references'])) if len(item["references"]) > 5 else "")
|
|
619
686
|
if item["note"]:
|
|
620
|
-
line +=
|
|
687
|
+
line += _("({0})").format(item['note'])
|
|
621
688
|
changes.append(line)
|
|
622
689
|
if plan["declaration_hint"]:
|
|
623
690
|
hint = json.dumps(plan["declaration_hint"]["if_this_is_your_convention"], ensure_ascii=False)
|
|
624
|
-
changes.append("如果这些名字正是你的约定,不用改名:在 Profile 里声明它,之后按声明检查 → " + hint)
|
|
625
|
-
changes.append("每个 Case 的 CASE.md 里的 id 字段也要和新目录名保持一致")
|
|
626
|
-
return _step(fix_id, title, changes=changes, recovery="本处理项不移动、不改写任何文件",
|
|
627
|
-
verify="按计划改名并更新引用后,重新运行检查", blocked=PLAN_ONLY + "(不会移动目录)")
|
|
628
|
-
|
|
691
|
+
changes.append(_("如果这些名字正是你的约定,不用改名:在 Profile 里声明它,之后按声明检查 → ") + hint)
|
|
692
|
+
changes.append(_("每个 Case 的 CASE.md 里的 id 字段也要和新目录名保持一致"))
|
|
693
|
+
return _step(fix_id, title, changes=changes, recovery=_("本处理项不移动、不改写任何文件"),
|
|
694
|
+
verify=_("按计划改名并更新引用后,重新运行检查"), blocked=_(PLAN_ONLY) + _("(不会移动目录)"))
|
|
695
|
+
if fix_id == "local-only":
|
|
696
|
+
return _plan_local_only(provider)
|
|
697
|
+
title = _("同步盘使用指引")
|
|
629
698
|
host = provider.host
|
|
630
699
|
where = host.sync_folder(provider.root) if host is not None and hasattr(host, "sync_folder") else None
|
|
631
700
|
if where is None:
|
|
632
|
-
return _step(fix_id, title, blocked="项目不在同步盘里")
|
|
701
|
+
return _step(fix_id, title, blocked=_("项目不在同步盘里"))
|
|
633
702
|
changes = [
|
|
634
|
-
"随项目同步的:Profile、内容锁、决定文件(check-decisions.json)、所有项目文件",
|
|
635
|
-
"每台机器各一份的:用户级运行时(~/.local/share/agenthelm)、版本缓存、wf 的资料台账缓存(按项目绝对路径命名)、本机决定",
|
|
636
|
-
"所以:两台机器的 wf 结果可能不同——台账各自重建,且取决于各自装的 project-orchestrator 版本;"
|
|
637
|
-
"用 agenthelm check --fingerprint 对比两台机器的脚手架是否一致",
|
|
703
|
+
_("随项目同步的:Profile、内容锁、决定文件(check-decisions.json)、所有项目文件"),
|
|
704
|
+
_("每台机器各一份的:用户级运行时(~/.local/share/agenthelm)、版本缓存、wf 的资料台账缓存(按项目绝对路径命名)、本机决定"),
|
|
705
|
+
_("所以:两台机器的 wf 结果可能不同——台账各自重建,且取决于各自装的 project-orchestrator 版本;"
|
|
706
|
+
"用 agenthelm check --fingerprint 对比两台机器的脚手架是否一致"),
|
|
638
707
|
]
|
|
639
708
|
if where["rebuildable"]:
|
|
640
|
-
listed = "、".join(where["rebuildable"][:8])
|
|
641
|
-
changes.append(
|
|
642
|
-
changes.append(" ·
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
changes
|
|
649
|
-
|
|
650
|
-
|
|
709
|
+
listed = _("、").join(where["rebuildable"][:8])
|
|
710
|
+
changes.append(_("项目里有可重建目录:{0}。它们不需要同步,可以:").format(listed))
|
|
711
|
+
changes.append(_(" · 推荐:agenthelm local-only check 逐项查看,agenthelm local-only fix 把 .venv、node_modules 等"
|
|
712
|
+
"外置到本机(~/.local/share/agenthelm/local-only/…)并在原位置建软链接;yarn 经典版、bun、uv 实测可用,"
|
|
713
|
+
"npm 会把链接换回真实目录、pnpm 会安装失败,同步目录里请尽量避免它们"))
|
|
714
|
+
changes.append(_(" · 写进 .gitignore(版本管理忽略它们,不影响同步盘)"))
|
|
715
|
+
changes.append(_(" · 或在 {0} 的设置里把这些目录设为不同步(选择性同步)").format(where['service']))
|
|
716
|
+
changes.append(_("本工具不会替你移动、改名或删除任何内容"))
|
|
717
|
+
return _step(fix_id, title, changes=changes, recovery=_("本处理项不改任何文件"), verify=_("不涉及"),
|
|
718
|
+
blocked=_(PLAN_ONLY))
|
|
719
|
+
|
|
720
|
+
|
|
721
|
+
def _plan_local_only(provider: Any) -> dict:
|
|
722
|
+
"""只展示 agenthelm local-only fix 的预览:移动目录属于用户的同步盘内容,由它自带预览与回滚的命令执行。"""
|
|
723
|
+
title = _("本机专属目录:外置到本机")
|
|
724
|
+
host = provider.host
|
|
725
|
+
if host is None or not hasattr(host, "local_only_plan"):
|
|
726
|
+
return _step("local-only", title, blocked=_("需要带 local-only 的 agent-pack(更新插件或运行时后再试)"))
|
|
727
|
+
try:
|
|
728
|
+
plan = host.local_only_plan(host.current_env(), provider.root)
|
|
729
|
+
except Exception as exc: # noqa: BLE001 - LocalOnlyError 等:把原因原样给用户
|
|
730
|
+
return _step("local-only", title, blocked=str(exc))
|
|
731
|
+
changes = [step["detail"] for step in plan["steps"]] + [_("不处理:{0}").format(message) for message in plan["blocked"]]
|
|
732
|
+
if not plan["steps"]:
|
|
733
|
+
return _step("local-only", title, changes=changes,
|
|
734
|
+
blocked=_("没有可以自动处理的项;体积阈值等需要你选择,见 health 里各项给出的选项"))
|
|
735
|
+
changes.append(_("执行:agenthelm local-only fix --apply(先预览;移动失败整体撤销)"))
|
|
736
|
+
return _step("local-only", title, changes=changes, recovery=_("移动失败整体撤销;旧配置备份在 ~/.agent-pack/recovery/"),
|
|
737
|
+
verify=_("重新运行 health,或 agenthelm local-only check"), blocked=PLAN_ONLY + _("(这里只展示预览)"))
|
|
651
738
|
|
|
652
739
|
|
|
653
740
|
def record_decisions(provider: Any, items: dict[str, str], reason: str, *, prefix: str, apply: bool) -> list[str]:
|
|
@@ -670,18 +757,32 @@ def _entry_error(exc: Exception) -> EntryError:
|
|
|
670
757
|
return EntryError(str(exc), code)
|
|
671
758
|
|
|
672
759
|
|
|
760
|
+
def accept_current(provider: Any, reason: str, apply: bool) -> dict:
|
|
761
|
+
"""``fix --accept-current --reason …``: record every current scaffold difference as decided / keep (project decisions file)."""
|
|
762
|
+
module = scaffold_module(provider)
|
|
763
|
+
if module is None or not hasattr(module, "accept_current"):
|
|
764
|
+
raise EntryError(_("需要带「接受现状」的 agents-init(更新插件或运行时后再试)"), "unavailable")
|
|
765
|
+
env = provider.host.current_env()
|
|
766
|
+
try:
|
|
767
|
+
result = module.accept_current(provider.root, reason=reason, apply=apply, state_dir=env.state_dir)
|
|
768
|
+
except Exception as exc: # noqa: BLE001
|
|
769
|
+
raise _entry_error(exc) from exc
|
|
770
|
+
provider._health = None
|
|
771
|
+
return result
|
|
772
|
+
|
|
773
|
+
|
|
673
774
|
def decide_ids(provider: Any, skip: list[str], unskip: list[str], reason: str, apply: bool) -> dict:
|
|
674
775
|
"""``fix --skip <id> --reason …`` / ``--unskip <id>``: only decisions are written, never project files."""
|
|
675
776
|
module = scaffold_module(provider)
|
|
676
777
|
if module is None:
|
|
677
|
-
raise EntryError("需要带脚手架检查的 agents-init(更新插件或运行时后再试)", "unavailable")
|
|
778
|
+
raise EntryError(_("需要带脚手架检查的 agents-init(更新插件或运行时后再试)"), "unavailable")
|
|
678
779
|
health = provider._health or provider.health()
|
|
679
780
|
known = {f["decision"]["id"]: f["decision"] for f in health["findings"] if f.get("decision")}
|
|
680
781
|
env = provider.host.current_env()
|
|
681
782
|
results = []
|
|
682
783
|
for identifier in skip:
|
|
683
784
|
if identifier not in known:
|
|
684
|
-
raise EntryError(
|
|
785
|
+
raise EntryError(_("现在没有这个发现:{0}").format(identifier), "usage", [_("可跳过:") + (_("、").join(sorted(known)) or _("(无)"))])
|
|
685
786
|
item = known[identifier]
|
|
686
787
|
try:
|
|
687
788
|
results.append(module.decide(provider.root, identifier, "skip", reason=reason,
|
|
@@ -713,7 +814,7 @@ def apply(provider: Any, planned: dict, choices: dict[str, str]) -> dict:
|
|
|
713
814
|
fresh = _plan_step(provider, step["id"], effective)
|
|
714
815
|
if [w["path"] for w in fresh["writes"]] != [w["path"] for w in step["writes"]]:
|
|
715
816
|
results.append({"id": step["id"], "status": "skipped",
|
|
716
|
-
"detail": "预览之后情况有变化(写入范围不同),没有执行:请重新预览"})
|
|
817
|
+
"detail": _("预览之后情况有变化(写入范围不同),没有执行:请重新预览")})
|
|
717
818
|
continue
|
|
718
819
|
try:
|
|
719
820
|
results.append(_apply_step(provider, fresh, effective))
|
|
@@ -731,7 +832,7 @@ def _apply_scaffold(provider: Any, step: dict, choices: dict[str, str], base: di
|
|
|
731
832
|
payload = step["payload"]
|
|
732
833
|
if fix_id == "repair-lock":
|
|
733
834
|
result = module.repair_lock(provider.root, apply=True)
|
|
734
|
-
return {**base, "verify": "内容锁版本已修复" if result["applied"] else "没有需要修复的内容"}
|
|
835
|
+
return {**base, "verify": _("内容锁版本已修复") if result["applied"] else _("没有需要修复的内容")}
|
|
735
836
|
accepted = payload["accepted"]
|
|
736
837
|
written = []
|
|
737
838
|
if fix_id == "add-skeleton" and accepted:
|
|
@@ -744,9 +845,9 @@ def _apply_scaffold(provider: Any, step: dict, choices: dict[str, str], base: di
|
|
|
744
845
|
prefix = "skel" if fix_id == "add-skeleton" else "profile"
|
|
745
846
|
recorded = record_decisions(provider, payload["decisions"], choices.get("_reason", ""), prefix=prefix, apply=True)
|
|
746
847
|
return {**base, "written": written + ([DECISIONS_FILE] if recorded else []),
|
|
747
|
-
"verify": "重新检查:" + ("、".join(accepted) or "没有写入文件")
|
|
748
|
-
+ (
|
|
749
|
-
"recovery": payload["recovery"] if fix_id == "profile" and accepted else "只新建文件,无需备份"}
|
|
848
|
+
"verify": _("重新检查:") + (_("、").join(accepted) or _("没有写入文件"))
|
|
849
|
+
+ (_(";已记录决定:{0}").format(_('、').join(recorded)) if recorded else ""),
|
|
850
|
+
"recovery": payload["recovery"] if fix_id == "profile" and accepted else _("只新建文件,无需备份")}
|
|
750
851
|
|
|
751
852
|
|
|
752
853
|
def _apply_step(provider: Any, step: dict, choices: dict[str, str]) -> dict:
|
|
@@ -756,8 +857,7 @@ def _apply_step(provider: Any, step: dict, choices: dict[str, str]) -> dict:
|
|
|
756
857
|
if fix_id == "rebuild-index":
|
|
757
858
|
result = assets.rebuild(provider.assets_project(), force=True)
|
|
758
859
|
state = assets.status(provider.assets_project())
|
|
759
|
-
return {**base, "verify":
|
|
760
|
-
f"{result['file_count']} 个文件"}
|
|
860
|
+
return {**base, "verify": _("索引{0},{1} 个文件").format(_('最新') if state['status'] == 'fresh' else _('状态:') + state['status'], result['file_count'])}
|
|
761
861
|
if fix_id in ("add-skeleton", "profile", "repair-lock"):
|
|
762
862
|
try:
|
|
763
863
|
return _apply_scaffold(provider, step, choices, base)
|
|
@@ -767,10 +867,10 @@ def _apply_step(provider: Any, step: dict, choices: dict[str, str]) -> dict:
|
|
|
767
867
|
name = step["payload"]["name"]
|
|
768
868
|
result = _run_init(provider, name, choices, step["payload"]["recovery"], apply=True)
|
|
769
869
|
if not result.get("applied"):
|
|
770
|
-
raise EntryError("没有写入:" + str(result.get("hint") or result.get("error") or result.get("blocked")), "failed")
|
|
870
|
+
raise EntryError(_("没有写入:") + str(result.get("hint") or result.get("error") or result.get("blocked")), "failed")
|
|
771
871
|
launcher = provider.root / name
|
|
772
872
|
ready = launcher.is_file() and launcher.stat().st_mode & 0o111
|
|
773
|
-
return {**base, "verify":
|
|
873
|
+
return {**base, "verify": _("./{0} {1};Profile 已声明 entry").format(name, _('已就绪') if ready else _('未就绪'))}
|
|
774
874
|
host = provider.host
|
|
775
875
|
env = host.current_env()
|
|
776
876
|
if fix_id in ("install-runtime", "update-runtime"):
|
|
@@ -778,10 +878,11 @@ def _apply_step(provider: Any, step: dict, choices: dict[str, str]) -> dict:
|
|
|
778
878
|
if step["payload"].get("from_release"):
|
|
779
879
|
import tempfile
|
|
780
880
|
with tempfile.TemporaryDirectory(prefix="agenthelm-runtime-") as temporary:
|
|
781
|
-
latest,
|
|
881
|
+
latest, latest_origin = host.load_latest(env, None, max_age=0)
|
|
782
882
|
root = host.release_source(latest, Path(temporary))
|
|
783
|
-
planned = runtime.plan(env, root, "GitHub Release(已核对摘要)")
|
|
883
|
+
planned = runtime.plan(env, root, _("GitHub Release(已核对摘要)"))
|
|
784
884
|
result = runtime.apply(env, planned, root)
|
|
885
|
+
result = {**result, "verify": _("{0};{1}").format(result['verify'], host.origin_line(latest_origin))}
|
|
785
886
|
else:
|
|
786
887
|
planned = step["payload"]["plan"]
|
|
787
888
|
result = runtime.apply(env, planned, runtime.bundled_root())
|
|
@@ -795,27 +896,33 @@ def _apply_step(provider: Any, step: dict, choices: dict[str, str]) -> dict:
|
|
|
795
896
|
behind = [item for item in after["plugins"] if item["status"] == "behind"]
|
|
796
897
|
return {**base, "status": "failed" if failed else "applied",
|
|
797
898
|
"detail": failed[0].get("output", "") if failed else "",
|
|
798
|
-
"verify": "重新检查:" + ("全部为最新" if not behind else
|
|
899
|
+
"verify": _("重新检查:") + (_("全部为最新") if not behind else _("仍有 {0} 个落后").format(len(behind)))}
|
|
799
900
|
# update-content
|
|
800
901
|
custom = {item["path"] for item in step["custom"]}
|
|
801
|
-
|
|
902
|
+
merge, pick = _choice_list(choices, "_merge"), _choice_list(choices, "_pick")
|
|
903
|
+
keep = [path for path in custom if choices.get(path, "keep") == "keep" and path not in merge]
|
|
802
904
|
accept = [path for path in custom if choices.get(path) == "accept"]
|
|
905
|
+
append = [path for path in custom if choices.get(path) == "append"]
|
|
906
|
+
confirm = _choice_list(choices, "_confirm")
|
|
803
907
|
before = {path: _digest(provider.root / path) for path in keep}
|
|
804
908
|
recovery = Path(step["payload"]["recovery"])
|
|
805
909
|
if step["payload"].get("direct"):
|
|
806
|
-
result = _run_refresh(provider, accept, keep, recovery, apply=True
|
|
910
|
+
result = _run_refresh(provider, accept, keep, recovery, apply=True, append=append, confirm=confirm,
|
|
911
|
+
merge=merge, pick=pick)
|
|
807
912
|
if not result.get("applied"):
|
|
808
|
-
raise EntryError("模板更新没有执行:" + str(result.get("hint") or result), "failed")
|
|
913
|
+
raise EntryError(_("模板更新没有执行:") + str(result.get("hint") or result), "failed")
|
|
809
914
|
else:
|
|
810
|
-
steps = host.update_steps(env, provider._report, provider.root, None, env.home, accept, keep, recovery, "content"
|
|
915
|
+
steps = host.update_steps(env, provider._report, provider.root, None, env.home, accept, keep, recovery, "content",
|
|
916
|
+
content_flags=_content_flags(append, confirm, merge, pick))
|
|
811
917
|
outcome = host.execute_steps(steps, apply=True, recovery_root=None, child_env=env.child_environment())[0]
|
|
812
918
|
result = outcome.get("result") or {}
|
|
813
919
|
if outcome["status"] == "failed" or not result.get("applied"):
|
|
814
|
-
raise EntryError("模板更新没有执行:" + str(outcome.get("error") or result.get("hint") or result), "failed")
|
|
920
|
+
raise EntryError(_("模板更新没有执行:") + str(outcome.get("error") or result.get("hint") or result), "failed")
|
|
815
921
|
untouched = all(_digest(provider.root / path) == digest for path, digest in before.items())
|
|
816
|
-
return {**base, "kept": keep, "accepted": accept, "
|
|
817
|
-
"
|
|
818
|
-
|
|
922
|
+
return {**base, "kept": keep, "accepted": accept, "appended": append, "merged": merge,
|
|
923
|
+
"recovery": result.get("recovery") or _("没有替换文件,无需备份"),
|
|
924
|
+
"verify": _("重新读取:保留的文件") + (_("内容未变") if untouched else _("被改动了,请检查"))
|
|
925
|
+
+ _(";内容锁已更新到新版本")}
|
|
819
926
|
|
|
820
927
|
|
|
821
928
|
def _digest(path: Path) -> str | None:
|