@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
|
@@ -11,6 +11,7 @@ import sys
|
|
|
11
11
|
from datetime import date, timedelta
|
|
12
12
|
from pathlib import Path
|
|
13
13
|
from typing import Any
|
|
14
|
+
from i18n_orchestrator import _ # noqa: E402
|
|
14
15
|
|
|
15
16
|
|
|
16
17
|
PROJECT_PROFILE = Path(".agents") / "moe.sakanano.agent-pack" / "project.json"
|
|
@@ -22,7 +23,6 @@ REQUIRED = ("schema_version", "id", "type", "status", "description", "created",
|
|
|
22
23
|
SUMMARY_SECTIONS = ("待确认假设", "未解决冲突", "Opinion 演化候选")
|
|
23
24
|
IDENTITY = re.compile(r"MEM-\d{8}-\d{3}-[a-z0-9]+(?:-[a-z0-9]+)*\Z")
|
|
24
25
|
SLUG = re.compile(r"[a-z0-9]+(?:-[a-z0-9]+)*\Z")
|
|
25
|
-
DUE_MARK = "可能过期"
|
|
26
26
|
|
|
27
27
|
|
|
28
28
|
class EntryError(ValueError):
|
|
@@ -35,10 +35,10 @@ def fail(message: str) -> None:
|
|
|
35
35
|
|
|
36
36
|
def confined(root: Path, relative: str | Path) -> Path:
|
|
37
37
|
if Path(relative).is_absolute() or ".." in Path(relative).parts:
|
|
38
|
-
fail(
|
|
38
|
+
fail(_("路径必须是项目内的相对路径:{0}").format(relative))
|
|
39
39
|
path = root / relative
|
|
40
40
|
if any(item.is_symlink() for item in (path, *path.parents) if root in (item, *item.parents)):
|
|
41
|
-
fail(
|
|
41
|
+
fail(_("拒绝使用符号链接:{0}").format(relative))
|
|
42
42
|
return path
|
|
43
43
|
|
|
44
44
|
|
|
@@ -46,13 +46,13 @@ def parse_date(value: str, label: str) -> date:
|
|
|
46
46
|
try:
|
|
47
47
|
return date.fromisoformat(value)
|
|
48
48
|
except (TypeError, ValueError):
|
|
49
|
-
fail(
|
|
49
|
+
fail(_("{0} 必须为 YYYY-MM-DD:{1!r}").format(label, value))
|
|
50
50
|
|
|
51
51
|
|
|
52
52
|
def read_json(path: Path) -> dict[str, Any]:
|
|
53
53
|
value = json.loads(path.read_text(encoding="utf-8"))
|
|
54
54
|
if not isinstance(value, dict):
|
|
55
|
-
fail(
|
|
55
|
+
fail(_("JSON 根节点必须是对象:{0}").format(path.name))
|
|
56
56
|
return value
|
|
57
57
|
|
|
58
58
|
|
|
@@ -60,7 +60,7 @@ def settings(args: argparse.Namespace) -> tuple[Path, Path, dict[str, Any]]:
|
|
|
60
60
|
"""解析项目根、记忆目录与参数;命令行优先,其次读取 Project Profile 的 memory 段。"""
|
|
61
61
|
project = args.project.resolve()
|
|
62
62
|
if not project.is_dir():
|
|
63
|
-
fail(
|
|
63
|
+
fail(_("项目目录不存在:{0}").format(project))
|
|
64
64
|
declared: dict[str, Any] = {}
|
|
65
65
|
profile = project / PROJECT_PROFILE
|
|
66
66
|
if profile.is_file():
|
|
@@ -74,7 +74,7 @@ def settings(args: argparse.Namespace) -> tuple[Path, Path, dict[str, Any]]:
|
|
|
74
74
|
def parse_entry(text: str) -> tuple[dict[str, Any], str]:
|
|
75
75
|
"""解析受限的 frontmatter:标量为 JSON 字符串,sources 为字符串列表。"""
|
|
76
76
|
if not text.startswith("---\n") or "\n---\n" not in text[4:]:
|
|
77
|
-
fail("缺少 frontmatter")
|
|
77
|
+
fail(_("缺少 frontmatter"))
|
|
78
78
|
header, body = text[4:].split("\n---\n", 1)
|
|
79
79
|
meta: dict[str, Any] = {}
|
|
80
80
|
current: str | None = None
|
|
@@ -84,16 +84,16 @@ def parse_entry(text: str) -> tuple[dict[str, Any], str]:
|
|
|
84
84
|
continue
|
|
85
85
|
key, separator, raw = line.partition(":")
|
|
86
86
|
if not separator or key != key.strip() or not key:
|
|
87
|
-
fail(
|
|
87
|
+
fail(_("无法解析的 frontmatter 行:{0!r}").format(line))
|
|
88
88
|
current = key
|
|
89
89
|
if key == "sources":
|
|
90
90
|
if raw.strip() not in ("", "[]"):
|
|
91
|
-
fail("sources 必须写成列表")
|
|
91
|
+
fail(_("sources 必须写成列表"))
|
|
92
92
|
meta["sources"] = []
|
|
93
93
|
else:
|
|
94
94
|
value = json.loads(raw.strip())
|
|
95
95
|
if not isinstance(value, str):
|
|
96
|
-
fail(
|
|
96
|
+
fail(_("{0} 必须是字符串").format(key))
|
|
97
97
|
meta[key] = value
|
|
98
98
|
return meta, body
|
|
99
99
|
|
|
@@ -143,7 +143,7 @@ def index_lines(entries: list[dict[str, Any]], policy: dict[str, Any], today: da
|
|
|
143
143
|
if meta.get("status") != "active":
|
|
144
144
|
continue
|
|
145
145
|
try:
|
|
146
|
-
mark =
|
|
146
|
+
mark = _("|可能过期") if is_due(meta, policy, today) else ""
|
|
147
147
|
except EntryError:
|
|
148
148
|
mark = ""
|
|
149
149
|
lines.append(f"- `{meta.get('id', entry['path'].stem)}`({meta.get('type', '?')}):{meta.get('description', '')}{mark}")
|
|
@@ -159,17 +159,17 @@ def check_entry(project: Path, entry: dict[str, Any], policy: dict[str, Any]) ->
|
|
|
159
159
|
|
|
160
160
|
for key in REQUIRED:
|
|
161
161
|
if not str(meta.get(key, "")).strip():
|
|
162
|
-
problem("missing-field",
|
|
162
|
+
problem("missing-field", _("缺少字段 {0}").format(key))
|
|
163
163
|
unknown = set(meta) - set(SCALARS) - {"sources"}
|
|
164
164
|
if unknown:
|
|
165
|
-
problem("unknown-field",
|
|
165
|
+
problem("unknown-field", _("未知字段:{0}").format(_('、').join(sorted(unknown))))
|
|
166
166
|
if meta.get("id") and (not IDENTITY.fullmatch(meta["id"]) or meta["id"] != entry["path"].stem):
|
|
167
|
-
problem("id-mismatch", "编号格式无效或与文件名不一致")
|
|
167
|
+
problem("id-mismatch", _("编号格式无效或与文件名不一致"))
|
|
168
168
|
types = tuple(policy.get("types", TYPES))
|
|
169
169
|
if meta.get("type") and meta["type"] not in types:
|
|
170
|
-
problem("invalid-type",
|
|
170
|
+
problem("invalid-type", _("type 必须为:{0}").format(_('、').join(types)))
|
|
171
171
|
if meta.get("status") and meta["status"] not in STATUSES:
|
|
172
|
-
problem("invalid-status",
|
|
172
|
+
problem("invalid-status", _("status 必须为:{0}").format(_('、').join(STATUSES)))
|
|
173
173
|
for key in ("created", "verified_at", "review_after"):
|
|
174
174
|
if meta.get(key):
|
|
175
175
|
try:
|
|
@@ -177,12 +177,12 @@ def check_entry(project: Path, entry: dict[str, Any], policy: dict[str, Any]) ->
|
|
|
177
177
|
except EntryError as exc:
|
|
178
178
|
problem("invalid-date", str(exc))
|
|
179
179
|
if meta.get("type") == "assumption" and meta.get("status") == "active" and not meta.get("review_after"):
|
|
180
|
-
problem("assumption-without-review", "未确认的假设必须设置 review_after")
|
|
180
|
+
problem("assumption-without-review", _("未确认的假设必须设置 review_after"))
|
|
181
181
|
if meta.get("status") == "active" and meta.get("promoted_to"):
|
|
182
|
-
problem("promoted-still-active", "已晋升的条目应当退役")
|
|
182
|
+
problem("promoted-still-active", _("已晋升的条目应当退役"))
|
|
183
183
|
limit = policy.get("index", {}).get("max_description_chars")
|
|
184
184
|
if limit and len(meta.get("description", "")) > int(limit):
|
|
185
|
-
problem("description-too-long",
|
|
185
|
+
problem("description-too-long", _("description 超过 {0} 字符").format(limit))
|
|
186
186
|
if meta.get("status") == "active":
|
|
187
187
|
for source in meta.get("sources", []):
|
|
188
188
|
try:
|
|
@@ -191,7 +191,7 @@ def check_entry(project: Path, entry: dict[str, Any], policy: dict[str, Any]) ->
|
|
|
191
191
|
problem("invalid-source", str(exc))
|
|
192
192
|
continue
|
|
193
193
|
if missing:
|
|
194
|
-
problem("missing-source",
|
|
194
|
+
problem("missing-source", _("来源路径不存在:{0}").format(source))
|
|
195
195
|
return found
|
|
196
196
|
|
|
197
197
|
|
|
@@ -200,14 +200,14 @@ def check_budgets(project: Path, lines: list[str], policy: dict[str, Any]) -> li
|
|
|
200
200
|
index = policy.get("index", {})
|
|
201
201
|
size = len("\n".join(lines).encode("utf-8"))
|
|
202
202
|
if index.get("max_lines") and len(lines) > int(index["max_lines"]):
|
|
203
|
-
found.append({"code": "index-too-long", "entry": "", "message":
|
|
203
|
+
found.append({"code": "index-too-long", "entry": "", "message": _("索引 {0} 行,超过 {1} 行").format(len(lines), index['max_lines'])})
|
|
204
204
|
if index.get("max_bytes") and size > int(index["max_bytes"]):
|
|
205
|
-
found.append({"code": "index-too-large", "entry": "", "message":
|
|
205
|
+
found.append({"code": "index-too-large", "entry": "", "message": _("索引 {0} 字节,超过 {1} 字节").format(size, index['max_bytes'])})
|
|
206
206
|
bundle = policy.get("startup_bundle", {})
|
|
207
207
|
if bundle.get("max_bytes") and bundle.get("files"):
|
|
208
208
|
total = sum(confined(project, item).stat().st_size for item in bundle["files"] if confined(project, item).is_file()) + size
|
|
209
209
|
if total > int(bundle["max_bytes"]):
|
|
210
|
-
found.append({"code": "startup-too-large", "entry": "", "message":
|
|
210
|
+
found.append({"code": "startup-too-large", "entry": "", "message": _("启动层合计 {0} 字节,超过 {1} 字节").format(total, bundle['max_bytes'])})
|
|
211
211
|
summary = policy.get("chat_summary", {})
|
|
212
212
|
path = confined(project, summary.get("path", ".agent-doc/chat-summary.md"))
|
|
213
213
|
if path.is_file():
|
|
@@ -216,9 +216,9 @@ def check_budgets(project: Path, lines: list[str], policy: dict[str, Any]) -> li
|
|
|
216
216
|
for section in summary.get("required_sections", SUMMARY_SECTIONS):
|
|
217
217
|
# 按前缀匹配,项目可以在固定小节名之后补充说明。
|
|
218
218
|
if not any(heading.startswith(section) for heading in headings):
|
|
219
|
-
found.append({"code": "summary-section-missing", "entry": path.name, "message":
|
|
219
|
+
found.append({"code": "summary-section-missing", "entry": path.name, "message": _("缺少小节:{0}").format(section)})
|
|
220
220
|
if summary.get("max_bytes") and len(text.encode("utf-8")) > int(summary["max_bytes"]):
|
|
221
|
-
found.append({"code": "summary-too-large", "entry": path.name, "message":
|
|
221
|
+
found.append({"code": "summary-too-large", "entry": path.name, "message": _("超过 {0} 字节").format(summary['max_bytes'])})
|
|
222
222
|
return found
|
|
223
223
|
|
|
224
224
|
|
|
@@ -229,7 +229,7 @@ def command_check(project: Path, root: Path, policy: dict[str, Any], today: date
|
|
|
229
229
|
problems.extend(check_entry(project, entry, policy))
|
|
230
230
|
identity = entry["meta"].get("id")
|
|
231
231
|
if identity in seen:
|
|
232
|
-
problems.append({"code": "duplicate-id", "entry": entry["path"].name, "message":
|
|
232
|
+
problems.append({"code": "duplicate-id", "entry": entry["path"].name, "message": _("与 {0} 编号重复").format(seen[identity])})
|
|
233
233
|
seen.setdefault(identity, entry["path"].name)
|
|
234
234
|
lines = index_lines(entries, policy, today)
|
|
235
235
|
problems.extend(check_budgets(project, lines, policy))
|
|
@@ -248,14 +248,14 @@ def command_check(project: Path, root: Path, policy: dict[str, Any], today: date
|
|
|
248
248
|
def command_create(args: argparse.Namespace, project: Path, root: Path, policy: dict[str, Any], today: date) -> dict[str, Any]:
|
|
249
249
|
types = tuple(policy.get("types", TYPES))
|
|
250
250
|
if args.type not in types:
|
|
251
|
-
fail(
|
|
251
|
+
fail(_("--type 必须为:{0}").format(_('、').join(types)))
|
|
252
252
|
if not args.slug or not SLUG.fullmatch(args.slug):
|
|
253
|
-
fail("--slug 只能包含小写字母、数字和连字符")
|
|
253
|
+
fail(_("--slug 只能包含小写字母、数字和连字符"))
|
|
254
254
|
if not args.description or not args.description.strip():
|
|
255
|
-
fail("--description 说明何时应当想起这条记忆,不能为空")
|
|
255
|
+
fail(_("--description 说明何时应当想起这条记忆,不能为空"))
|
|
256
256
|
body = confined(project, args.body_file).read_text(encoding="utf-8") if args.body_file else ""
|
|
257
257
|
if not body.strip():
|
|
258
|
-
fail("--body-file 必须提供非空正文")
|
|
258
|
+
fail(_("--body-file 必须提供非空正文"))
|
|
259
259
|
created = parse_date(args.date, "--date") if args.date else today
|
|
260
260
|
if args.review_after:
|
|
261
261
|
parse_date(args.review_after, "--review-after")
|
|
@@ -268,7 +268,7 @@ def command_create(args: argparse.Namespace, project: Path, root: Path, policy:
|
|
|
268
268
|
path = root / f"{identity}.md"
|
|
269
269
|
problems = check_entry(project, {"path": path, "meta": meta, "body": body}, policy)
|
|
270
270
|
if problems:
|
|
271
|
-
fail(";".join(item["message"] for item in problems))
|
|
271
|
+
fail(_(";").join(item["message"] for item in problems))
|
|
272
272
|
content = render_entry(meta, "\n" + body.strip() + "\n")
|
|
273
273
|
if args.apply:
|
|
274
274
|
root.mkdir(parents=True, exist_ok=True)
|
|
@@ -279,14 +279,14 @@ def command_create(args: argparse.Namespace, project: Path, root: Path, policy:
|
|
|
279
279
|
|
|
280
280
|
def command_update(args: argparse.Namespace, project: Path, root: Path, today: date) -> dict[str, Any]:
|
|
281
281
|
if not args.id:
|
|
282
|
-
fail(
|
|
282
|
+
fail(_("{0} 需要 --id").format(args.action))
|
|
283
283
|
path = root / f"{args.id}.md"
|
|
284
284
|
if not IDENTITY.fullmatch(args.id) or not path.is_file():
|
|
285
|
-
fail(
|
|
285
|
+
fail(_("找不到记忆条目:{0}").format(args.id))
|
|
286
286
|
meta, body = parse_entry(path.read_text(encoding="utf-8"))
|
|
287
287
|
if args.action == "retire":
|
|
288
288
|
if not args.reason and not args.promoted_to:
|
|
289
|
-
fail("retire 需要 --reason 或 --promoted-to")
|
|
289
|
+
fail(_("retire 需要 --reason 或 --promoted-to"))
|
|
290
290
|
meta["status"] = "retired"
|
|
291
291
|
meta["promoted_to"] = args.promoted_to or meta.get("promoted_to", "")
|
|
292
292
|
body = body.rstrip() + f"\n\n**退役**:{today.isoformat()},{args.reason or '已晋升到 ' + args.promoted_to}\n"
|
|
@@ -304,23 +304,23 @@ def command_update(args: argparse.Namespace, project: Path, root: Path, today: d
|
|
|
304
304
|
|
|
305
305
|
|
|
306
306
|
def build_parser() -> argparse.ArgumentParser:
|
|
307
|
-
parser = argparse.ArgumentParser(description="条目式项目记忆:生成索引、检查、创建、核实与退役")
|
|
307
|
+
parser = argparse.ArgumentParser(description=_("条目式项目记忆:生成索引、检查、创建、核实与退役"))
|
|
308
308
|
parser.add_argument("action", choices=("index", "list", "check", "create", "verify", "retire"))
|
|
309
309
|
parser.add_argument("--project", type=Path, default=Path.cwd())
|
|
310
|
-
parser.add_argument("--root", help="记忆目录,默认取 Project Profile 的 memory.root,再默认 memory")
|
|
311
|
-
parser.add_argument("--policy", help="项目自己的参数文件;未提供时不做体积与间隔检查")
|
|
312
|
-
parser.add_argument("--today", help="用于测试与回放的日期,YYYY-MM-DD")
|
|
310
|
+
parser.add_argument("--root", help=_("记忆目录,默认取 Project Profile 的 memory.root,再默认 memory"))
|
|
311
|
+
parser.add_argument("--policy", help=_("项目自己的参数文件;未提供时不做体积与间隔检查"))
|
|
312
|
+
parser.add_argument("--today", help=_("用于测试与回放的日期,YYYY-MM-DD"))
|
|
313
313
|
parser.add_argument("--output", choices=("json", "markdown"), default="markdown")
|
|
314
|
-
parser.add_argument("--apply", action="store_true", help="create、verify、retire 默认只预览")
|
|
314
|
+
parser.add_argument("--apply", action="store_true", help=_("create、verify、retire 默认只预览"))
|
|
315
315
|
parser.add_argument("--id")
|
|
316
316
|
parser.add_argument("--type")
|
|
317
317
|
parser.add_argument("--slug")
|
|
318
|
-
parser.add_argument("--description", help="一句话说明何时应当想起这条记忆")
|
|
319
|
-
parser.add_argument("--body-file", help="项目内的正文文件")
|
|
320
|
-
parser.add_argument("--source", action="append", default=[], help="项目内的来源路径,可重复")
|
|
321
|
-
parser.add_argument("--review-after", help="复核日期,YYYY-MM-DD")
|
|
318
|
+
parser.add_argument("--description", help=_("一句话说明何时应当想起这条记忆"))
|
|
319
|
+
parser.add_argument("--body-file", help=_("项目内的正文文件"))
|
|
320
|
+
parser.add_argument("--source", action="append", default=[], help=_("项目内的来源路径,可重复"))
|
|
321
|
+
parser.add_argument("--review-after", help=_("复核日期,YYYY-MM-DD"))
|
|
322
322
|
parser.add_argument("--supersedes")
|
|
323
|
-
parser.add_argument("--date", help="create 的创建日期,默认今天")
|
|
323
|
+
parser.add_argument("--date", help=_("create 的创建日期,默认今天"))
|
|
324
324
|
parser.add_argument("--reason")
|
|
325
325
|
parser.add_argument("--promoted-to")
|
|
326
326
|
return parser
|
|
@@ -330,7 +330,7 @@ def run(args: argparse.Namespace) -> tuple[int, str]:
|
|
|
330
330
|
project, root, policy = settings(args)
|
|
331
331
|
today = parse_date(args.today, "--today") if args.today else date.today()
|
|
332
332
|
if args.action == "index":
|
|
333
|
-
entries,
|
|
333
|
+
entries, _problems = load_entries(root)
|
|
334
334
|
lines = index_lines(entries, policy, today)
|
|
335
335
|
if args.output == "json":
|
|
336
336
|
return 0, json.dumps({"ok": True, "lines": lines}, ensure_ascii=False, indent=2) + "\n"
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"""私有目录:Profile 的 ``privacy.forbidden_default_reads`` 声明,缺省约定为项目根目录的 ``private/``。
|
|
2
|
+
|
|
3
|
+
约定(只有两条,其余照常):
|
|
4
|
+
- 读取前须经用户确认——Agent 默认不读,读之前向用户列出要读的路径;
|
|
5
|
+
- 内容默认不进入 git——目录里放一个 ``.gitignore``(``*`` 加 ``!.gitignore``),随项目走,不改项目根的 .gitignore。
|
|
6
|
+
|
|
7
|
+
用到私有目录的 Case 标为 ``sensitivity: private``。本模块只依赖标准库,不依赖 case.py / sop.py,三者可以互相调用。
|
|
8
|
+
资料索引(find)不做特殊处理:``private/`` 不是资料根时本来就不会被扫描。
|
|
9
|
+
"""
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
import json
|
|
13
|
+
import os
|
|
14
|
+
import re
|
|
15
|
+
import subprocess
|
|
16
|
+
from pathlib import Path
|
|
17
|
+
from typing import Any
|
|
18
|
+
|
|
19
|
+
PROFILE = Path(".agents/moe.sakanano.agent-pack/project.json")
|
|
20
|
+
CONVENTION = "private"
|
|
21
|
+
IGNORE_FILE = ".gitignore"
|
|
22
|
+
# 与 agents-init 新项目生成的 private/.gitignore 相同(tests/test_private_paths_sync.py 核对两处一致)。
|
|
23
|
+
IGNORE_TEXT = "# agenthelm: 本目录内容默认不进入 git;读取前须经用户确认。\n*\n!.gitignore\n"
|
|
24
|
+
GIT_TIMEOUT = 10
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def clean(value: Any) -> str | None:
|
|
28
|
+
"""Profile 里的一项规范成项目内相对路径(不带首尾斜杠);绝对路径、~、含 .. 的返回 None。"""
|
|
29
|
+
if not isinstance(value, str):
|
|
30
|
+
return None
|
|
31
|
+
text = value.strip()
|
|
32
|
+
if not text or text.startswith(("~", "/")) or re.match(r"^[A-Za-z]:[\\/]", text):
|
|
33
|
+
return None
|
|
34
|
+
normal = os.path.normpath(text)
|
|
35
|
+
if normal in (".", "") or normal.startswith("..") or Path(normal).is_absolute():
|
|
36
|
+
return None
|
|
37
|
+
return Path(normal).as_posix()
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def declared(project: Path) -> list[str]:
|
|
41
|
+
"""项目的私有路径:Profile 声明的 + 约定的 private/(目录存在时)。"""
|
|
42
|
+
found: list[str] = []
|
|
43
|
+
try:
|
|
44
|
+
data = json.loads((project / PROFILE).read_text(encoding="utf-8"))
|
|
45
|
+
except (OSError, ValueError):
|
|
46
|
+
data = {}
|
|
47
|
+
privacy = data.get("privacy") if isinstance(data, dict) else None
|
|
48
|
+
items = privacy.get("forbidden_default_reads") if isinstance(privacy, dict) else None
|
|
49
|
+
for value in items if isinstance(items, list) else []:
|
|
50
|
+
path = clean(value)
|
|
51
|
+
if path and path not in found:
|
|
52
|
+
found.append(path)
|
|
53
|
+
convention = project / CONVENTION
|
|
54
|
+
if CONVENTION not in found and convention.is_dir() and not convention.is_symlink():
|
|
55
|
+
found.append(CONVENTION)
|
|
56
|
+
return found
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def relative(project: Path, value: str | Path) -> str | None:
|
|
60
|
+
"""项目内的路径(相对或绝对)→ 项目相对路径;在项目外返回 None。"""
|
|
61
|
+
path = Path(str(value)).expanduser()
|
|
62
|
+
if path.is_absolute():
|
|
63
|
+
try:
|
|
64
|
+
return Path(os.path.normpath(path)).relative_to(Path(os.path.normpath(project.resolve()))).as_posix()
|
|
65
|
+
except ValueError:
|
|
66
|
+
try:
|
|
67
|
+
return path.resolve().relative_to(project.resolve()).as_posix()
|
|
68
|
+
except ValueError:
|
|
69
|
+
return None
|
|
70
|
+
return clean(str(value))
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def is_private(project: Path, value: str | Path, dirs: list[str] | None = None) -> bool:
|
|
74
|
+
rel = relative(project, value)
|
|
75
|
+
if rel is None:
|
|
76
|
+
return False
|
|
77
|
+
return any(rel == item or rel.startswith(item + "/") for item in (declared(project) if dirs is None else dirs))
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def mentions(text: str, dirs: list[str]) -> list[str]:
|
|
81
|
+
"""文本里把哪些私有路径当作路径用到了(``private/…``、``./private/…``)。目录要带斜杠;声明的是文件名(带扩展名)时按文件名匹配。"""
|
|
82
|
+
found = []
|
|
83
|
+
for item in dirs:
|
|
84
|
+
is_file = "." in item.rsplit("/", 1)[-1]
|
|
85
|
+
tail = r"(?:/|(?![\w\-]))" if is_file else "/"
|
|
86
|
+
if re.search(r"(?<![\w.\-/])(?:\./)?" + re.escape(item) + tail, text):
|
|
87
|
+
found.append(item)
|
|
88
|
+
return found
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def git_state(project: Path, directory: str) -> dict:
|
|
92
|
+
"""私有路径是否被 git 忽略、是否已有文件被跟踪。不在 git 仓库或没有 git 时 ignored 为 None。"""
|
|
93
|
+
result: dict[str, Any] = {"dir": directory, "exists": (project / directory).exists(), "ignored": None, "tracked": []}
|
|
94
|
+
probe = f"{directory}/.agenthelm-probe"
|
|
95
|
+
try:
|
|
96
|
+
checked = subprocess.run(["git", "-C", str(project), "check-ignore", "-q", "--", probe],
|
|
97
|
+
capture_output=True, check=False, timeout=GIT_TIMEOUT)
|
|
98
|
+
except (OSError, subprocess.TimeoutExpired):
|
|
99
|
+
return result
|
|
100
|
+
if checked.returncode not in (0, 1):
|
|
101
|
+
return result
|
|
102
|
+
result["ignored"] = checked.returncode == 0
|
|
103
|
+
try:
|
|
104
|
+
listed = subprocess.run(["git", "-C", str(project), "ls-files", "-z", "--", directory],
|
|
105
|
+
capture_output=True, check=False, timeout=GIT_TIMEOUT)
|
|
106
|
+
except (OSError, subprocess.TimeoutExpired):
|
|
107
|
+
return result
|
|
108
|
+
names = [item for item in listed.stdout.decode("utf-8", errors="replace").split("\0") if item]
|
|
109
|
+
result["tracked"] = [name for name in names if name != f"{directory}/{IGNORE_FILE}"]
|
|
110
|
+
return result
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def plan_ignore(project: Path, directory: str) -> list[dict]:
|
|
114
|
+
"""需要写入的 .gitignore(只在它不存在时创建;已有的从不修改)。"""
|
|
115
|
+
target = project / directory
|
|
116
|
+
if target.exists() and not target.is_dir():
|
|
117
|
+
return []
|
|
118
|
+
path = target / IGNORE_FILE
|
|
119
|
+
return [] if path.exists() else [{"path": path, "content": IGNORE_TEXT, "expect": None}]
|
|
@@ -9,6 +9,8 @@ import json
|
|
|
9
9
|
import re
|
|
10
10
|
from pathlib import Path
|
|
11
11
|
from typing import Any
|
|
12
|
+
from i18n_orchestrator import _ # noqa: E402
|
|
13
|
+
from i18n_orchestrator import _ # noqa: E402
|
|
12
14
|
|
|
13
15
|
# 运行时支持的项目入口接口版本范围;项目在 Profile 的 entry.api 声明自己需要的版本。
|
|
14
16
|
RUNTIME_API = (1, 1)
|
|
@@ -37,39 +39,39 @@ def find_profile_root(start: Path | None, explicit: bool) -> Path:
|
|
|
37
39
|
for candidate in candidates:
|
|
38
40
|
if (candidate / PROFILE).is_file():
|
|
39
41
|
return candidate
|
|
40
|
-
where = str(base) if explicit else
|
|
41
|
-
raise EntryError(
|
|
42
|
-
["到项目目录里运行,或用 --project <目录> 指定",
|
|
43
|
-
"新项目:用 agents-init 初始化(会生成项目入口)",
|
|
44
|
-
"只想看看效果:agenthelm project --demo study"])
|
|
42
|
+
where = str(base) if explicit else _("{0} 及其上级目录").format(base)
|
|
43
|
+
raise EntryError(_("{0}里没有 agenthelm 项目(缺少 {1})").format(where, PROFILE), "not-a-project",
|
|
44
|
+
[_("到项目目录里运行,或用 --project <目录> 指定"),
|
|
45
|
+
_("新项目:用 agents-init 初始化(会生成项目入口)"),
|
|
46
|
+
_("只想看看效果:agenthelm project --demo study")])
|
|
45
47
|
|
|
46
48
|
|
|
47
49
|
def read_profile(root: Path) -> dict:
|
|
48
50
|
path = root / PROFILE
|
|
49
51
|
if path.is_symlink():
|
|
50
|
-
raise EntryError(
|
|
52
|
+
raise EntryError(_("拒绝符号链接:{0}").format(PROFILE), "profile-invalid")
|
|
51
53
|
try:
|
|
52
54
|
data = json.loads(path.read_text(encoding="utf-8"))
|
|
53
55
|
except (OSError, UnicodeDecodeError, ValueError) as exc:
|
|
54
|
-
raise EntryError(
|
|
55
|
-
[
|
|
56
|
+
raise EntryError(_("Project Profile 无法解析:{0}").format(exc), "profile-invalid",
|
|
57
|
+
[_("检查 {0} 是否为合法 JSON").format(PROFILE)]) from exc
|
|
56
58
|
if not isinstance(data, dict):
|
|
57
|
-
raise EntryError("Project Profile 根节点必须是对象", "profile-invalid")
|
|
59
|
+
raise EntryError(_("Project Profile 根节点必须是对象"), "profile-invalid")
|
|
58
60
|
return data
|
|
59
61
|
|
|
60
62
|
|
|
61
63
|
def inside(root: Path, value: Any, label: str) -> Path:
|
|
62
64
|
"""A project-relative path that stays inside the project and passes no symlink."""
|
|
63
65
|
if not isinstance(value, str) or not value:
|
|
64
|
-
raise EntryError(
|
|
66
|
+
raise EntryError(_("{0} 必须是项目内相对路径").format(label), "profile-invalid")
|
|
65
67
|
relative = Path(value)
|
|
66
68
|
if relative.is_absolute() or ".." in relative.parts:
|
|
67
|
-
raise EntryError(
|
|
69
|
+
raise EntryError(_("{0} 必须是项目内相对路径:{1}").format(label, value), "profile-invalid")
|
|
68
70
|
current = root
|
|
69
71
|
for part in relative.parts:
|
|
70
72
|
current = current / part
|
|
71
73
|
if current.is_symlink():
|
|
72
|
-
raise EntryError(
|
|
74
|
+
raise EntryError(_("{0} 不能经过符号链接:{1}").format(label, value), "profile-invalid")
|
|
73
75
|
return root / relative
|
|
74
76
|
|
|
75
77
|
|
|
@@ -80,28 +82,44 @@ def entry_section(profile: dict) -> dict:
|
|
|
80
82
|
return {"declared": False, "api": 1, "launcher": None, "about": "", "guide": None, "tools": None,
|
|
81
83
|
"items": None, "where": [], "start": []}
|
|
82
84
|
if not isinstance(entry, dict):
|
|
83
|
-
raise EntryError("Profile 的 entry 必须是对象", "profile-invalid")
|
|
85
|
+
raise EntryError(_("Profile 的 entry 必须是对象"), "profile-invalid")
|
|
84
86
|
api = entry.get("api", 1)
|
|
85
87
|
if not isinstance(api, int) or isinstance(api, bool) or api < 1:
|
|
86
|
-
raise EntryError("entry.api 必须是正整数", "profile-invalid")
|
|
88
|
+
raise EntryError(_("entry.api 必须是正整数"), "profile-invalid")
|
|
87
89
|
launcher = entry.get("launcher")
|
|
88
90
|
if launcher is not None and (not isinstance(launcher, str) or not LAUNCHER_RE.fullmatch(launcher)):
|
|
89
|
-
raise EntryError("entry.launcher 只能是根目录下的文件名(字母、数字、. _ -)", "profile-invalid")
|
|
91
|
+
raise EntryError(_("entry.launcher 只能是根目录下的文件名(字母、数字、. _ -)"), "profile-invalid")
|
|
90
92
|
items = entry.get("items")
|
|
91
93
|
if items is not None:
|
|
92
94
|
command = items.get("command") if isinstance(items, dict) else None
|
|
93
95
|
if not (isinstance(command, list) and command and all(isinstance(part, str) and part for part in command)):
|
|
94
|
-
raise EntryError("entry.items.command 必须是非空的参数列表(不经过 shell)", "profile-invalid")
|
|
96
|
+
raise EntryError(_("entry.items.command 必须是非空的参数列表(不经过 shell)"), "profile-invalid")
|
|
95
97
|
status_map = items.get("status_map") or {}
|
|
96
98
|
if not isinstance(status_map, dict) or not all(value in GROUP_KEYS for value in status_map.values()):
|
|
97
|
-
raise EntryError("entry.items.status_map 的值只能是 " + " / ".join(GROUP_KEYS), "profile-invalid")
|
|
99
|
+
raise EntryError(_("entry.items.status_map 的值只能是 ") + " / ".join(GROUP_KEYS), "profile-invalid")
|
|
98
100
|
where = entry.get("where") or []
|
|
99
101
|
start = entry.get("start") or []
|
|
100
102
|
if not (isinstance(where, list) and all(isinstance(item, dict) and isinstance(item.get("label"), str)
|
|
101
103
|
and isinstance(item.get("path"), str) for item in where)):
|
|
102
|
-
raise EntryError("entry.where 必须是 {label, path} 列表", "profile-invalid")
|
|
104
|
+
raise EntryError(_("entry.where 必须是 {label, path} 列表"), "profile-invalid")
|
|
103
105
|
if not (isinstance(start, list) and all(isinstance(item, str) for item in start)):
|
|
104
|
-
raise EntryError("entry.start 必须是字符串列表", "profile-invalid")
|
|
106
|
+
raise EntryError(_("entry.start 必须是字符串列表"), "profile-invalid")
|
|
105
107
|
return {"declared": True, "api": api, "launcher": launcher, "about": str(entry.get("about") or ""),
|
|
106
108
|
"guide": entry.get("guide"), "tools": entry.get("tools"), "items": items,
|
|
107
109
|
"where": where, "start": start}
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
SOP_ERROR_CODES = {"usage": "usage", "invalid": "usage", "not-found": "not-found", "ambiguous": "ambiguous",
|
|
113
|
+
"conflict": "conflict", "unavailable": "unavailable", "failed": "failed"}
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def sop_call(argv: list[str], root: Path) -> tuple[int, dict, list[str]]:
|
|
117
|
+
"""在项目 ``root`` 上运行 sop.py 的子命令;真实与演示两种来源共用,错误转成入口的 EntryError。"""
|
|
118
|
+
import sop as sop_tool # noqa: PLC0415 - 只有用到 SOP 时才加载
|
|
119
|
+
|
|
120
|
+
try:
|
|
121
|
+
return sop_tool.execute([*argv, "--project", str(root)])
|
|
122
|
+
except sop_tool.SopError as exc:
|
|
123
|
+
raise EntryError(str(exc), SOP_ERROR_CODES.get(exc.code, "usage"), exc.next_steps) from exc
|
|
124
|
+
except SystemExit as exc:
|
|
125
|
+
raise EntryError(_("命令参数不正确,用 sop <子命令> --help 查看写法"), "usage") from exc
|