@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.
Files changed (90) hide show
  1. package/README.md +1 -1
  2. package/README.zh-CN.md +2 -0
  3. package/package.json +1 -1
  4. package/runtime/index.json +6 -6
  5. package/runtime/plugins/agent-pack/.codex-plugin/plugin.json +1 -1
  6. package/runtime/plugins/agent-pack/hooks/hooks.json +32 -0
  7. package/runtime/plugins/agent-pack/plugin.json +1 -1
  8. package/runtime/plugins/agent-pack/references/local-only.md +126 -0
  9. package/runtime/plugins/agent-pack/references/nudge.en.md +58 -0
  10. package/runtime/plugins/agent-pack/references/nudge.md +58 -0
  11. package/runtime/plugins/agent-pack/runtime/agent_pack_nudge.py +613 -0
  12. package/runtime/plugins/agent-pack/runtime/agenthelm.py +1271 -221
  13. package/runtime/plugins/agent-pack/runtime/agenthelm_runtime.py +114 -65
  14. package/runtime/plugins/agent-pack/runtime/i18n_agent_pack.py +78 -0
  15. package/runtime/plugins/agent-pack/runtime/local_only.py +1132 -0
  16. package/runtime/plugins/agent-pack/runtime/locale/en.json +569 -0
  17. package/runtime/plugins/agent-pack/runtime/mcp_server.py +25 -0
  18. package/runtime/plugins/agent-pack/runtime/nudge_text.py +127 -0
  19. package/runtime/plugins/agent-pack/runtime/user_settings.py +275 -0
  20. package/runtime/plugins/agent-pack/skills/agent-pack/SKILL.md +11 -1
  21. package/runtime/plugins/agents-init/.codex-plugin/plugin.json +1 -1
  22. package/runtime/plugins/agents-init/content.json +4 -4
  23. package/runtime/plugins/agents-init/plugin.json +1 -1
  24. package/runtime/plugins/agents-init/skills/agents-init/AGENT.template.md +141 -5
  25. package/runtime/plugins/agents-init/skills/agents-init/SKILL.md +41 -8
  26. package/runtime/plugins/agents-init/skills/agents-init/project.schema.json +408 -80
  27. package/runtime/plugins/agents-init/skills/agents-init/scripts/adopt.py +615 -0
  28. package/runtime/plugins/agents-init/skills/agents-init/scripts/baseline.py +221 -0
  29. package/runtime/plugins/agents-init/skills/agents-init/scripts/i18n_init.py +78 -0
  30. package/runtime/plugins/agents-init/skills/agents-init/scripts/init_project.py +748 -159
  31. package/runtime/plugins/agents-init/skills/agents-init/scripts/locale/en.json +289 -0
  32. package/runtime/plugins/agents-init/skills/agents-init/scripts/merge3.py +149 -0
  33. package/runtime/plugins/agents-init/skills/agents-init/scripts/regions.py +99 -0
  34. package/runtime/plugins/agents-init/skills/agents-init/scripts/scaffold.py +594 -90
  35. package/runtime/plugins/agents-init/skills/agents-init/skeleton.json +2 -0
  36. package/runtime/plugins/agents-init/skills/agents-init/skill.json +1 -1
  37. package/runtime/plugins/opinion-manager/.codex-plugin/plugin.json +1 -1
  38. package/runtime/plugins/opinion-manager/plugin.json +1 -1
  39. package/runtime/plugins/opinion-manager/references/inbox.en.md +48 -0
  40. package/runtime/plugins/opinion-manager/references/inbox.md +48 -0
  41. package/runtime/plugins/opinion-manager/runtime/context.py +31 -26
  42. package/runtime/plugins/opinion-manager/runtime/i18n_opinion.py +78 -0
  43. package/runtime/plugins/opinion-manager/runtime/inbox.py +398 -0
  44. package/runtime/plugins/opinion-manager/runtime/inbox_text.py +114 -0
  45. package/runtime/plugins/opinion-manager/runtime/lifecycle.py +45 -44
  46. package/runtime/plugins/opinion-manager/runtime/locale/en.json +193 -0
  47. package/runtime/plugins/opinion-manager/runtime/opinion_manager.py +55 -50
  48. package/runtime/plugins/opinion-manager/runtime/versioned.py +90 -85
  49. package/runtime/plugins/opinion-manager/skills/opinion-manager/SKILL.md +15 -2
  50. package/runtime/plugins/project-orchestrator/.codex-plugin/plugin.json +1 -1
  51. package/runtime/plugins/project-orchestrator/content.json +30 -3
  52. package/runtime/plugins/project-orchestrator/plugin.json +1 -1
  53. package/runtime/plugins/project-orchestrator/references/case-workspaces.md +9 -1
  54. package/runtime/plugins/project-orchestrator/references/case.schema.json +1 -0
  55. package/runtime/plugins/project-orchestrator/references/sop-interview.md +83 -0
  56. package/runtime/plugins/project-orchestrator/references/sop.md +156 -0
  57. package/runtime/plugins/project-orchestrator/runtime/assets.py +52 -57
  58. package/runtime/plugins/project-orchestrator/runtime/case.py +139 -80
  59. package/runtime/plugins/project-orchestrator/runtime/case_structure.py +71 -0
  60. package/runtime/plugins/project-orchestrator/runtime/case_workspace.py +47 -46
  61. package/runtime/plugins/project-orchestrator/runtime/i18n_orchestrator.py +78 -0
  62. package/runtime/plugins/project-orchestrator/runtime/locale/en.json +1450 -0
  63. package/runtime/plugins/project-orchestrator/runtime/memory.py +45 -45
  64. package/runtime/plugins/project-orchestrator/runtime/private_paths.py +119 -0
  65. package/runtime/plugins/project-orchestrator/runtime/project_base.py +37 -19
  66. package/runtime/plugins/project-orchestrator/runtime/project_cli.py +307 -195
  67. package/runtime/plugins/project-orchestrator/runtime/project_demo.py +130 -48
  68. package/runtime/plugins/project-orchestrator/runtime/project_maintain.py +328 -221
  69. package/runtime/plugins/project-orchestrator/runtime/project_menu.py +167 -89
  70. package/runtime/plugins/project-orchestrator/runtime/project_real.py +187 -105
  71. package/runtime/plugins/project-orchestrator/runtime/project_write.py +58 -55
  72. package/runtime/plugins/project-orchestrator/runtime/sop.py +1670 -0
  73. package/runtime/plugins/project-orchestrator/runtime/sop_structure.py +226 -0
  74. package/runtime/plugins/project-orchestrator/runtime/wf.py +74 -70
  75. package/runtime/plugins/project-orchestrator/skills/project-orchestrator/SKILL.md +22 -0
  76. package/runtime/plugins/project-orchestrator/sop-templates/blank/SOP.en.md +57 -0
  77. package/runtime/plugins/project-orchestrator/sop-templates/blank/SOP.md +57 -0
  78. package/runtime/plugins/project-orchestrator/sop-templates/knowledge-digest/SOP.en.md +77 -0
  79. package/runtime/plugins/project-orchestrator/sop-templates/knowledge-digest/SOP.md +77 -0
  80. package/runtime/plugins/project-orchestrator/sop-templates/knowledge-digest/templates/digest.en.md +11 -0
  81. package/runtime/plugins/project-orchestrator/sop-templates/knowledge-digest/templates/digest.md +11 -0
  82. package/runtime/plugins/project-orchestrator/sop-templates/video-to-transcript/SOP.en.md +87 -0
  83. package/runtime/plugins/project-orchestrator/sop-templates/video-to-transcript/SOP.md +87 -0
  84. package/runtime/plugins/project-orchestrator/sop-templates/weekly-review/SOP.en.md +75 -0
  85. package/runtime/plugins/project-orchestrator/sop-templates/weekly-review/SOP.md +75 -0
  86. package/runtime/plugins/project-orchestrator/sop-templates/weekly-review/templates/review.en.md +11 -0
  87. package/runtime/plugins/project-orchestrator/sop-templates/weekly-review/templates/review.md +12 -0
  88. package/runtime/plugins/project-orchestrator/templates/CASE.en.md +39 -0
  89. package/runtime/plugins/agents-init/skills/agents-init/scripts/test_init_project.py +0 -678
  90. package/runtime/plugins/agents-init/skills/agents-init/scripts/test_scaffold.py +0 -551
@@ -0,0 +1,289 @@
1
+ {
2
+ "无法读取中文模板:{0}": "Cannot read the Chinese template: {0}",
3
+ "中文模板缺少生成区块:": "The Chinese template is missing generated blocks: ",
4
+ "Plugin manifest 无法解析:{0}": "The Plugin manifest cannot be parsed: {0}",
5
+ "Plugin manifest 根节点必须是对象:{0}": "The root of the Plugin manifest must be an object: {0}",
6
+ "缺少 agents-init Plugin manifest:{0}": "The agents-init Plugin manifest is missing: {0}",
7
+ "Plugin manifest 必须声明 name=agents-init": "The Plugin manifest must declare name=agents-init",
8
+ "同包 Plugin manifest 必须声明 name={0}": "The companion Plugin manifest must declare name={0}",
9
+ "缺少必需的 project-orchestrator / agent-pack / opinion-manager 文件:": "Required project-orchestrator / agent-pack / opinion-manager files are missing: ",
10
+ "legacy profile 无法解析:{0}": "The legacy profile cannot be parsed: {0}",
11
+ "legacy profile 必须是 schema_version=1.0 的对象": "The legacy profile must be an object with schema_version=1.0",
12
+ "work 配置必须是对象": "The work configuration must be an object",
13
+ "task/case 配置必须是对象或 null": "The task/case configuration must be an object or null",
14
+ "{0} 不能为空": "{0} must not be empty",
15
+ "{0} 只能包含单行可打印文本": "{0} may contain only a single line of printable text",
16
+ "启动器名称不合法:{0}(只能用字母、数字、. _ -,且不能与骨架文件同名)": "Invalid launcher name: {0} (only letters, digits and . _ - are allowed, and it must not share a name with a skeleton file)",
17
+ "无法读取启动器模板:{0}": "Cannot read the launcher template: {0}",
18
+ "content lock 无法解析:{0}": "The content lock cannot be parsed: {0}",
19
+ "缺少 {0}": "{0} is missing",
20
+ "{0} 无法解析:{1}": "{0} cannot be parsed: {1}",
21
+ "{0} 根节点必须是对象": "The root of {0} must be an object",
22
+ "当前 agents-init 未声明可刷新的内容包": "The current agents-init declares no refreshable content pack",
23
+ "不是内容包跟踪的文件:": "Not a file tracked by the content pack: ",
24
+ "--mode entry 需要 --entry-name": "--mode entry needs --entry-name",
25
+ "项目已声明入口 ./{0};改名请同时修改 Profile 的 entry.launcher 与文件名": "The project already declares the entry ./{0}; to rename it, change both entry.launcher in the Profile and the file name",
26
+ "{0} 已存在且不是文件": "{0} already exists and is not a file",
27
+ "--mode entry 只接受启动器文件的 --accept / --keep:": "--mode entry accepts only --accept / --keep for the launcher file: ",
28
+ "新建启动器": "Create the launcher",
29
+ "用模板替换(先备份)": "Replace with the template (backed up first)",
30
+ "已是模板内容": "Already the template content",
31
+ "保留你的文件(不跟踪更新)": "Keep your file (not tracked for updates)",
32
+ "已存在同名文件,需要选择": "A file with the same name exists; a choice is needed",
33
+ "{0}:{1}": "{0}: {1}",
34
+ "Project Profile:加入 entry(api {0},launcher {1})": "Project Profile: add entry (api {0}, launcher {1})",
35
+ "README.md:": "README.md: ",
36
+ "新建并写入「怎样使用」": "Create it and write a how-to section (in the project file language)",
37
+ "追加「怎样使用」一节": "Append a how-to section (in the project file language)",
38
+ "add-skeleton:骨架路径;profile:字段;decide:发现 ID(可重复;省略则处理全部可处理项)": "add-skeleton: skeleton paths; profile: fields; decide: finding IDs (repeatable; omit to handle everything that can be handled)",
39
+ "decide:决定;unskip 撤销": "decide: the decision; unskip withdraws it",
40
+ "decide:期望指纹(缺省取该发现当前的指纹)": "decide: the expected fingerprint (by default the finding's current fingerprint)",
41
+ "check:忽略已记录的决定,重新评估全部发现": "check: ignore recorded decisions and re-evaluate every finding",
42
+ "机器本地决定的状态目录(缺省 $XDG_STATE_HOME 或 ~/.local/state)": "state directory for machine-local decisions (default $XDG_STATE_HOME or ~/.local/state)",
43
+ "根目录启动器文件名(init 缺省 {0};entry 模式必填)": "root launcher file name (default {0} for init; required in entry mode)",
44
+ "init:不生成根目录启动器": "init: do not create the root launcher",
45
+ "在已有 README.md 末尾追加「怎样使用」一节(带标记,只追加一次);init 时 README 不存在会直接新建": "append a how-to section (in the project file language) to the end of an existing README.md (marked, appended only once); init creates the README when it does not exist",
46
+ "refresh:用新模板替换这个本地已改动的文件": "refresh: replace this locally changed file with the new template",
47
+ "refresh:保留这个文件的本地内容": "refresh: keep this file's local content",
48
+ "新项目默认 case-workspace;既有项目只在显式选择后更改模式": "new projects default to case-workspace; existing projects change mode only when you choose it explicitly",
49
+ "agents-init Plugin 根目录(同级查找 project-orchestrator、agent-pack、opinion-manager),或含 plugins/ 的仓库根目录": "root of the agents-init Plugin (project-orchestrator, agent-pack and opinion-manager are looked up beside it), or a repository root that contains plugins/",
50
+ "README 里可以加上:\n": "You can add this to the README:\n",
51
+ "init/migrate 需要:": "init/migrate needs: ",
52
+ "Project Profile 无法解析": "The Project Profile cannot be parsed",
53
+ "检测到 v5 Project Profile({0}),请改用 --mode migrate": "A v5 Project Profile was found ({0}); use --mode migrate instead",
54
+ "Case root 必须是项目内明确相对目录": "The Case root must be an explicit relative directory inside the project",
55
+ "无法读取期望骨架清单:{0}": "Cannot read the expected skeleton list: {0}",
56
+ "期望骨架清单格式不对": "The expected skeleton list has a wrong format",
57
+ "拒绝符号链接:{0}": "Refusing a symbolic link: {0}",
58
+ "决定文件无法读取:{0}": "The decisions file cannot be read: {0}",
59
+ "决定文件不是合法 JSON:{0}": "The decisions file is not valid JSON: {0}",
60
+ "决定文件格式不对(需要 decisions 对象,decision 为 skip / keep / later)": "The decisions file has a wrong format (it needs a decisions object whose decision is skip / keep / later)",
61
+ "style 只能是 case-id / date-topic / custom": "style must be case-id / date-topic / custom",
62
+ "pattern 必须是字符串(正则,匹配整个目录名)": "pattern must be a string (a regular expression matching the whole directory name)",
63
+ "style 为 custom 时需要 pattern": "pattern is required when style is custom",
64
+ "pattern 不是合法正则:{0}": "pattern is not a valid regular expression: {0}",
65
+ "名称里没有日期或主题,需要你自己决定新名字": "The name has no date or topic; you need to decide the new name yourself",
66
+ "<匹配全部目录名的正则>": "<regular expression matching every directory name>",
67
+ "目录名是你的约定的话,在 Profile 里声明它(fix profile 不会替你写这一项),之后 check 按声明检查": "If the directory names are your own convention, declare it in the Profile (fix profile will not write this for you); check then follows the declaration",
68
+ "{0}:只有这台有({1})": "{0}: only on this machine ({1})",
69
+ "{0}:只有对方有({1})": "{0}: only on the other machine ({1})",
70
+ "{0}:期望清单版本不同——这台 {1},对方 {2}(先把两边的 agents-init 更新到同一版本)": "{0}: the expected-list versions differ — this machine {1}, the other {2} (update agents-init on both to the same version first)",
71
+ "{0}:这台 {1},对方 {2}": "{0}: this machine {1}, the other {2}",
72
+ "缺少脚手架文件 {0}": "Scaffold file {0} is missing",
73
+ "期望骨架清单里有,项目里没有": "It is in the expected skeleton list but not in the project",
74
+ "{0} 与当前模板不同": "{0} differs from the current template",
75
+ "内容锁里没有它的基线,无法判断是你改过还是模板变了": "The content lock has no baseline for it, so it cannot tell whether you changed it or the template changed",
76
+ "缺少": "missing",
77
+ "不符合期望": "does not match the expectation",
78
+ "Profile {0}:{1}": "Profile {0}: {1}",
79
+ "期望 {0}": "expected {0}",
80
+ "需要你自己填写": "you need to fill it in yourself",
81
+ "内容锁的模板版本未知(0.0.0)": "The template version in the content lock is unknown (0.0.0)",
82
+ "旧版本写入的占位版本": "A placeholder version written by an older release",
83
+ ";基线与当前模板一致,可自动修复": "; the baseline matches the current template, so it can be repaired automatically",
84
+ ";基线与当前模板不同,需要逐文件选择": "; the baseline differs from the current template, so each file needs a choice",
85
+ "Profile 的 work.case.directory_naming 无法使用": "The Profile's work.case.directory_naming cannot be used",
86
+ "、": ", ",
87
+ "Profile 声明的": "declared in the Profile",
88
+ "默认的 CASE-日期-序号-主题": "default CASE-date-sequence-topic",
89
+ "{0} 个 Case 目录的命名与{1}规则不符": "Case directories whose name does not match the {1} rule: {0}",
90
+ "例如 {0};规则 {1}": "For example {0}; rule {1}",
91
+ "不在期望骨架清单里:": "Not in the expected skeleton list: ",
92
+ "这些字段不需要或不能自动修复:": "These fields do not need or cannot be repaired automatically: ",
93
+ "Profile 刚被改过,请重新预览": "The Profile was just changed; preview again",
94
+ "项目没有内容锁": "The project has no content lock",
95
+ "内容锁里没有项目契约模板包": "The content lock has no project contract template pack",
96
+ "记录的基线与当前模板不同,无法确定真实版本:用 update-content 逐文件选择保留或采用": "The recorded baseline differs from the current template, so the real version cannot be determined: use update-content to choose per file whether to keep or adopt",
97
+ "模板版本 {0} → {1}": "Template version {0} → {1}",
98
+ "记录基线:{0}": "Record baseline: {0}",
99
+ "内容锁刚被改过,请重新预览": "The content lock was just changed; preview again",
100
+ "决定文件刚被别处改过(可能是另一台机器同步过来),请重新预览": "The decisions file was just changed elsewhere (possibly synced from another machine); preview again",
101
+ "决定只能是 skip / keep / later": "A decision must be skip / keep / later",
102
+ "现在没有这个发现:{0}(用 check 查看当前的发现 ID)": "No such finding right now: {0} (use check to see the current finding IDs)",
103
+ "没有关于 {0} 的决定": "There is no decision about {0}",
104
+ "--mode decide 需要且只需要一个 --target <发现 ID>": "--mode decide needs exactly one --target <finding ID>",
105
+ " [{0}] {1}:{2}": " [{0}] {1}: {2}",
106
+ "(修复:{0})": " (fix: {0})",
107
+ "(未写理由)": " (no reason given)",
108
+ " [已跳过 {0}] {1}": " [skipped {0}] {1}",
109
+ "脚手架与期望一致。": "The scaffold matches expectations.",
110
+ "{0} 项差异。": "Differences: {0}.",
111
+ "已执行": "Ran",
112
+ "预览": "Preview",
113
+ "(需要你决定)": " (you need to decide)",
114
+ ";被 {0} 个文件提到": "; mentioned in files: {0}",
115
+ "使用 agents-init v6 中文模板安全创建或迁移项目骨架。": "Create or migrate a project skeleton safely with the agents-init v6 Chinese templates.",
116
+ "init / migrate:项目文件语言(新建 Case 的小节名、README 追加的使用说明);auto 在 init 时取当前界面语言,migrate 时保持中文": "init / migrate: project file language (section names of new Cases, the how-to text appended to the README); auto uses the current interface language on init and keeps Chinese on migrate",
117
+ "--case-root 与 --memory-root 不能相同": "--case-root and --memory-root must differ",
118
+ "没有 AGENTS.md,将按模板新建": "There is no AGENTS.md; it will be created from the template",
119
+ "没有 CLAUDE.md,将新建一行 @AGENTS.md 的导入桩": "There is no CLAUDE.md; a one-line @AGENTS.md import stub will be created",
120
+ ".agent-doc/ 已存在:只补上缺少的 plan.md / progress.md / chat-summary.md": ".agent-doc/ already exists: only the missing plan.md / progress.md / chat-summary.md are added",
121
+ "检测到 v5 Project Profile,请改用 --mode migrate": "A v5 Project Profile was found; use --mode migrate instead",
122
+ "已有 v6 Project Profile,不是接管场景:用 check / refresh": "A v6 Project Profile already exists, so this is not an adoption case: use check / refresh",
123
+ "--claude-policy add-import 没有生效:CLAUDE.md 不存在,或已能读到 AGENTS.md,或是符号链接": "--claude-policy add-import had no effect: CLAUDE.md does not exist, already reaches AGENTS.md, or is a symbolic link",
124
+ "(开头)": "(start of file)",
125
+ "AGENTS.md 是符号链接或无法按 UTF-8 读取,保持原样": "AGENTS.md is a symbolic link or cannot be read as UTF-8; left as it is",
126
+ "docs/{0}/ 已存在": "docs/{0}/ already exists",
127
+ "docs/ 已存在:骨架只在里面新增 refs/README.md 与 drafts/,已有文件不动": "docs/ already exists: the skeleton only adds refs/README.md and drafts/ inside it; existing files stay untouched",
128
+ "其他客户端的指令文件不会被触碰:": "Instruction files of other clients are not touched: ",
129
+ "{0} 必须是项目内明确的相对目录:{1}": "{0} must be an explicit relative directory inside the project: {1}",
130
+ "{0} 不是项目里已有的目录:{1}": "{0} is not an existing directory in the project: {1}",
131
+ "{0} 已被同名文件占用:{1}": "{0} is already taken by a file of that name: {1}",
132
+ "--agents-policy {0} 没有生效:AGENTS.md 不存在、不可读,或已与模板一致": "--agents-policy {0} had no effect: AGENTS.md does not exist, cannot be read, or already equals the template",
133
+ "AGENT.RULES.md 不可读,无法移入规则章节": "AGENT.RULES.md cannot be read, so the rule sections cannot be moved into it",
134
+ "{0} 已存在:没有创建启动器。之后可用 --mode entry --entry-name <其他名称> 补上": "{0} already exists: no launcher was created. Add one later with --mode entry --entry-name <another name>",
135
+ "--route 格式为 <序号>=<{0}>:{1}": "--route must look like <number>=<{0}>: {1}",
136
+ "--route 序号不存在:{0}(先用 scan 查看章节序号)": "--route number does not exist: {0} (run scan first to see the section numbers)",
137
+ "AGENTS.md 与模板一致": "AGENTS.md equals the template",
138
+ "CLAUDE.md 是指向 AGENTS.md 的符号链接,Claude 读到的就是 AGENTS.md": "CLAUDE.md is a symbolic link to AGENTS.md, so Claude reads AGENTS.md",
139
+ "CLAUDE.md 是指向其他位置的符号链接,保持原样": "CLAUDE.md is a symbolic link to somewhere else; left as it is",
140
+ "CLAUDE.md 无法读取,保持原样": "CLAUDE.md cannot be read; left as it is",
141
+ "根目录已有 {0},是你的文件:不创建启动器,也不在 Profile 里声明 entry": "The project root already has {0}, which is your file: no launcher is created and no entry is declared in the Profile",
142
+ "{0} 个骨架路径已存在,原样保留(不覆盖)": "Skeleton paths that already exist and are kept as they are (never overwritten): {0}",
143
+ "{0} 个骨架路径的父目录是符号链接,跳过": "Skeleton paths with a symbolic-link parent, skipped: {0}",
144
+ "{0} 经过符号链接:{1}": "{0} passes through a symbolic link: {1}",
145
+ "(整个文件)": "(the whole file)",
146
+ "{0} 已存在,不会被覆盖:先改名或删除后再选择拆分": "{0} already exists and will not be overwritten: rename or remove it before choosing to split",
147
+ "{0} 不存在或不是普通文件": "{0} does not exist or is not a regular file",
148
+ "CLAUDE.md 与模板一致": "CLAUDE.md equals the template",
149
+ "{0}/ 已有 {1} 个没有 CASE.md 的条目({2}),它们是历史内容:Case 工具会忽略它们,新 Case 与它们并存": "{0}/ has entries without a CASE.md: {1} ({2}). They are history: the Case tools ignore them and new Cases live next to them",
150
+ "{0}/ 看起来是已有的工作容器({1} 个子目录),内容不动": "{0}/ looks like an existing work container (subdirectories: {1}); its content stays untouched",
151
+ "{0}/ 已有 {1} 个条目,格式未知:随包记忆工具会在这个目录里写自己的条目,建议分开": "{0}/ has entries in an unknown format: {1}. The bundled memory tool writes its own entries into this directory, so keeping them apart is recommended",
152
+ "换一个启动器名称": "Choose another launcher name",
153
+ "--entry-name <名称>": "--entry-name <name>",
154
+ "不要启动器": "No launcher",
155
+ "{0} 不是普通文件,拒绝改动": "{0} is not a regular file; refusing to change it",
156
+ "AGENTS.md 已有用户内容({0} 字节,{1} 个章节)": "AGENTS.md already has user content ({0} bytes, sections: {1})",
157
+ "章节去向只是关键词启发式的建议;opinion / sop 暂由 opinion-manager 与后续 SOP 机制处理,工具会先把它们放进 AGENT.USER.md 并标注待交接。": "The section destinations are only keyword-based suggestions. opinion / sop content is handled by opinion-manager and the upcoming SOP mechanism; the tool puts it into AGENT.USER.md first and marks it as pending hand-over.",
158
+ "CLAUDE.md 已导入 AGENTS.md,Claude 能读到项目契约": "CLAUDE.md already imports AGENTS.md, so Claude can read the project contract",
159
+ "CLAUDE.md 已有内容但没有导入 AGENTS.md:Claude Code 两者并存时只读 CLAUDE.md,AGENTS.md 里的项目契约不会加载": "CLAUDE.md has content but does not import AGENTS.md: when both exist Claude Code reads only CLAUDE.md, so the project contract in AGENTS.md is not loaded",
160
+ "{0}/ 已存在,里面的 {1} 个目录都有 CASE.md": "{0}/ already exists and every directory in it has a CASE.md (directories: {1})",
161
+ "{0}/ 已存在且为空": "{0}/ already exists and is empty",
162
+ "并存:新 Case 放进同一目录,历史条目不动": "Coexist: new Cases go into the same directory and the historical entries stay untouched",
163
+ "登记为额外资料根(work.assets.roots),之后可被查找,不改任何文件": "Register it as an extra asset root (work.assets.roots) so it can be searched; no file is changed",
164
+ "不登记": "Do not register",
165
+ "共用同一目录(记忆工具的索引可能把历史文件当作异常)": "Share the directory (the memory tool's index may treat the historical files as anomalies)",
166
+ "保持原样;之后项目契约不会出现在 AGENTS.md 里": "Leave it as it is; the project contract will not appear in AGENTS.md",
167
+ "原文不动,末尾追加带标记的项目契约区块(可随时撤回)": "Keep the original text and append a marked project-contract region at the end (can be withdrawn at any time)",
168
+ "按章节决定去向:留在 AGENTS.md,或移到 AGENT.RULES.md / AGENT.USER.md;并追加契约区块": "Decide per section: keep it in AGENTS.md or move it to AGENT.RULES.md / AGENT.USER.md; the contract region is appended as well",
169
+ "--agents-policy split --route <序号>=<agents|rules|user|opinion|sop>": "--agents-policy split --route <number>=<agents|rules|user|opinion|sop>",
170
+ "原文整体移到 AGENT.USER.md,AGENTS.md 换成模板(AGENTS.md 里会指向 AGENT.USER.md)": "Move the whole original to AGENT.USER.md and replace AGENTS.md with the template (AGENTS.md will point at AGENT.USER.md)",
171
+ "新 Case 改放到另一个目录(如 {0}/),{1}/ 完全不碰": "Put new Cases in another directory (for example {0}/) and leave {1}/ completely alone",
172
+ "记忆条目改放到 {0}/,{1}/ 不碰": "Put memory entries in {0}/ and leave {1}/ alone",
173
+ "保持原样": "Leave it as it is",
174
+ "原文不动,末尾追加带标记的 @AGENTS.md 导入区块(可随时撤回)": "Keep the original text and append a marked @AGENTS.md import region at the end (can be withdrawn at any time)",
175
+ "Scan(只读)": "Scan (read-only)",
176
+ "adopt:已有 AGENTS.md 怎么处理(缺省 keep,不改动)": "adopt: what to do with an existing AGENTS.md (default keep, no change)",
177
+ "adopt:已有 CLAUDE.md 没导入 AGENTS.md 时是否追加导入区块(缺省 keep)": "adopt: whether to append an import region when an existing CLAUDE.md does not import AGENTS.md (default keep)",
178
+ "adopt split:<章节序号>=<agents|rules|user|opinion|sop>,未指定的章节留在 AGENTS.md": "adopt split: <section number>=<agents|rules|user|opinion|sop>; sections not listed stay in AGENTS.md",
179
+ "adopt:把已有的工作容器目录登记到 work.assets.roots(只读登记,不动内容)": "adopt: register an existing work-container directory in work.assets.roots (registration only, content untouched)",
180
+ "adopt:新 Case 放的目录(缺省 cases)": "adopt: directory for new Cases (default cases)",
181
+ "adopt:记忆条目放的目录(缺省 memory)": "adopt: directory for memory entries (default memory)",
182
+ "(推荐)": " (recommended)",
183
+ "推荐选项:": "Recommended options: ",
184
+ "接管后检查:": "Check after adoption: ",
185
+ "一致": "consistent",
186
+ "仍有 ": "still has ",
187
+ "(区块 {0})": " (region {0})",
188
+ "区块正文不能包含区块标记": "A region body must not contain region markers",
189
+ "区块 ID 不合法:{0}": "Invalid region ID: {0}",
190
+ "区块内部有你的改动,需逐个选择:--accept <文件>#<ID> 用模板替换(先备份),或 --keep <文件>#<ID> 保留": "The region has your edits, so choose one by one: --accept <file>#<ID> replaces it with the template (backed up first), or --keep <file>#<ID> keeps it",
191
+ "不是需要处理的受管区块:": "Not a managed region that needs handling: ",
192
+ "同一区块不能同时 --accept 与 --keep:": "A region cannot be both --accept and --keep: ",
193
+ "区块被移除;若是有意移除,可永久跳过": "The region was removed; if that was intentional, skip it permanently",
194
+ "区块内部有你的改动,升级不会覆盖;--mode region 里选择保留或采用模板": "The region has your edits and upgrades never overwrite them; choose keep or accept the template in --mode region",
195
+ "{0} 里的受管区块 {1} 不见了": "Managed region {1} in {0} is gone",
196
+ "区块完好,可以更新(先备份)": "The region is intact and can be updated (backed up first)",
197
+ "{0} 里的受管区块 {1} 被改过": "Managed region {1} in {0} was edited",
198
+ "{0} 里的受管区块 {1} 有新版本": "Managed region {1} in {0} has a newer version",
199
+ "{0} 已存在:--accept {1} 用模板替换(先备份到恢复目录),或 --keep {2} 保留你的文件": "{0} already exists: --accept {1} replaces it with the template (backed up to the recovery folder first), or --keep {2} keeps your file",
200
+ "默认恢复目录 {0} 在项目目录内,请用 --recovery-dir 指定项目外的目录": "The default recovery folder {0} is inside the project; use --recovery-dir to name a folder outside the project",
201
+ "不是目录": "not a directory",
202
+ "恢复目录 {0} 无法创建或写入:{1}。项目文件没有改动;请检查权限,或用 --recovery-dir 指定其他项目外目录": "The recovery folder {0} cannot be created or written: {1}. No project file was changed; check the permissions, or use --recovery-dir to name another folder outside the project",
203
+ "被替换文件的原件已备份到:{0}": "Originals of the replaced files were backed up to: {0}",
204
+ "还原:把备份目录里的文件按相同的相对路径复制回项目目录(cp -p <备份目录>/<文件> <项目目录>/<文件>)。": "To restore: copy the files from the backup folder back to the project folder under the same relative paths (cp -p <backup>/<file> <project>/<file>).",
205
+ "改动已有文件前会先备份到 ~/.agent-pack/recovery/(也可用 --recovery-dir 指定项目外的目录)": "Existing files are backed up to ~/.agent-pack/recovery/ before they change (or use --recovery-dir to name a folder outside the project)",
206
+ "被替换文件的备份目录(必须在项目外);缺省 ~/.agent-pack/recovery/<UTC 时间>-agenthelm-<模式>/": "Backup folder for replaced files (must be outside the project); default ~/.agent-pack/recovery/<UTC time>-agenthelm-<mode>/",
207
+ "已经导入或带有这个区块,无需追加": "Already imported or already has this region; nothing to append",
208
+ "--diff 只用于查看,不能与 --apply 同用": "--diff is for viewing only and cannot be combined with --apply",
209
+ "refresh:保留 AGENTS.md / CLAUDE.md 的本地内容,只在末尾追加带标记的区块(先备份)": "refresh: keep the local content of AGENTS.md / CLAUDE.md and only append a marked region at the end (backed up first)",
210
+ "refresh:确认 --accept 会丢弃这个文件里的本地内容": "refresh: confirm that --accept discards the local content of this file",
211
+ "refresh:只查看这个文件与新模板的完整差异,不写入": "refresh: only show the full difference between this file and the new template; nothing is written",
212
+ "你改过这个文件,新模板也变了": "You changed this file and the new template changed too",
213
+ "只有 AGENTS.md 和 CLAUDE.md 可以追加受管区块:": "Only AGENTS.md and CLAUDE.md can take an appended managed region: ",
214
+ "没有本地改动,不需要追加区块:": "No local changes, so there is nothing to append: ",
215
+ "本地已改动的文件需逐个选择:--keep <文件> 保留你的版本(建议);--append <文件> 保留并追加带标记的区块(仅 AGENTS.md / CLAUDE.md);--accept <文件> 用新模板替换(先备份,会丢弃本地内容,需再加 --confirm-discard <文件>);--diff <文件> 先看差异": "Files you changed need a choice each: --keep <file> keeps your version (recommended); --append <file> keeps it and appends a marked region (AGENTS.md / CLAUDE.md only); --accept <file> replaces it with the new template (backed up first; drops your local content, so also add --confirm-discard <file>); --diff <file> shows the difference first",
216
+ "--accept 会丢弃本地内容:确认后追加 --confirm-discard <文件>": "--accept drops local content: add --confirm-discard <file> to confirm",
217
+ "内容锁里没有它的基线(早期版本初始化的项目),无法判断是你改过还是模板变了;建议先保留你的版本:--keep {0}": "The content lock has no baseline for it (a project initialized by an early version), so it cannot tell whether you changed it or the template did; keep your version first: --keep {0}",
218
+ "本地 {0} 行,新模板 {1} 行;采用新模板会新增 {2} 行、丢弃 {3} 行本地内容": "Local lines: {0}; new template lines: {1}. Taking the template adds lines: {2} and drops local content, lines: {3}",
219
+ "也可以保留你的内容并追加带标记的区块(原文不动):--append {0}": "Or keep your content and append a marked region (the original text stays): --append {0}",
220
+ "先看差异:--diff {0}": "See the difference first: --diff {0}",
221
+ "保留你的内容,末尾追加带标记的区块({0} 行,原文不动,先备份)": "Keeps your content and appends a marked region at the end (region lines: {0}; the original text stays; backed up first)",
222
+ "--accept 会丢弃 {0} 行本地内容;确认后追加 --confirm-discard {1}": "--accept drops local content (lines: {0}); add --confirm-discard {1} to confirm",
223
+ "{0} 里的受管区块 {1} 被你改过:用 --mode region 处理": "The managed region {1} in {0} was edited by you: handle it with --mode region",
224
+ "({0} 与新模板没有差异)": "({0} does not differ from the new template)",
225
+ "项目文件语言只能是 zh 或 en(用 --language 指定)": "The project file language can only be zh or en (use --language)",
226
+ "项目文件语言已经是 {0},没有需要改的。": "The project file language is already {0}; nothing to change.",
227
+ "refresh:内容包更新后按 Profile 重新渲染已跟踪的模板文件;entry:为已初始化的项目补上根目录启动器与 Profile 的 entry 段;check:只读,对比期望骨架清单;add-skeleton:按模板补上缺失的骨架文件;profile:把缺失或不符的受检字段改为模板值;repair-lock:修复内容锁的 0.0.0 版本;decide:记录或撤销对某个发现的决定;case-naming:只输出 Case 目录改名计划与受影响的引用,不移动任何目录;scan:只读,扫描已有内容与骨架的冲突并给出选项和推荐;adopt:接管非空目录(已有文件原样保留,只补骨架;改动已有文件须显式选择并备份);region:更新受管区块(--accept / --keep <文件>#<区块ID>);language:只把 Profile 的 language 设为 --language zh|en(项目文件语言;默认预览,先备份,不改写任何已有文件)": "refresh: re-render the tracked template files from the Profile after a content pack update; entry: add the root launcher and the Profile entry section to an initialized project; check: read-only, compare with the expected skeleton list; add-skeleton: create the missing skeleton files from the templates; profile: set missing or wrong checked fields to the template value; repair-lock: fix the 0.0.0 version in the content lock; decide: record or withdraw a decision about a finding; case-naming: only print the Case directory rename plan and the references it affects, never move a directory; scan: read-only, scan existing content for conflicts with the skeleton and give options and recommendations; adopt: adopt a non-empty directory (existing files are kept as they are and only the skeleton is added; changing existing files must be chosen explicitly and is backed up first); region: update managed regions (--accept / --keep <file>#<region ID>); language: only set the Profile's language to --language zh|en (the project file language; preview by default, backed up first, no existing file is rewritten)",
228
+ " [信息] Profile 中有 {0} 个 schema 未声明的字段(项目自有 {1}、疑似拼写错误 {2}、已被其他插件读取 {3};工具不读取、不比较):路径在 JSON 输出的 extras 里": " [info] Fields in the Profile that the schema does not declare: {0} (the project's own: {1}, suspected typos: {2}, read by another plugin: {3}; the tool does not read or compare them); the paths are in extras of the JSON output",
229
+ " [信息] {0}": " [info] {0}",
230
+ "Profile 的 {0} 是{1},schema 现在把它声明为 {2}:它按项目自定义处理,工具不读取、不检查,也不会改写你的值。三个选项:转换成 {2} 的写法(例如 {3});保留为项目自有字段(改名,如 {4});忽略(什么都不用做,不影响退出码)": "The Profile value {0} is a {1}, but the schema now declares it as {2}. It is treated as the project's own: the tool does not read or check it and never rewrites your value. Three options: convert it to the {2} form (for example {3}); keep it as a project-owned field (rename it, for example to {4}); or ignore it (nothing to do, and it does not affect the exit code)",
231
+ "work.case.directory_naming 是项目自己的文字,工具不检查目录命名,也没有改名计划": "work.case.directory_naming is the project's own text: the tool does not check directory names and has no rename plan",
232
+ "可用写法:{0} 或 {1};要保留原文字不改动:把它移到你自己的字段名下(如 work.case.project_directory_naming),再删掉这一项": "Valid forms: {0} or {1}. To keep your original text unchanged, move it under a field name of your own (for example work.case.project_directory_naming) and delete this one",
233
+ "decide / accept-current:理由(建议写,随项目同步)": "decide / accept-current: the reason (recommended; it travels with the project)",
234
+ "{0} 个缺失文件": "Missing files: {0}",
235
+ "{0} 个文件与当前模板不同": "Files that differ from the current template: {0}",
236
+ "{0} 个受管区块有差异": "Managed regions that differ: {0}",
237
+ "{0} 个 Profile 字段缺失或不符": "Profile fields missing or not as expected: {0}",
238
+ "{0} 项 Case 目录命名差异": "Case directory naming differences: {0}",
239
+ "{0} 项内容锁问题": "Content-lock issues: {0}",
240
+ "{0} 项其他差异": "Other differences: {0}",
241
+ "{0}:把当前 {1} 项脚手架差异记为已决定、保留现状": "{0}: record the current scaffold differences ({1}) as decided, keep as is",
242
+ "写入 {0}(随项目同步,理由:{1})": "Written to {0} (travels with the project; reason: {1})",
243
+ " 未包含(需要处理):[{0}] {1}": " Not included (needs handling): [{0}] {1}",
244
+ "AGENTS.md 没有隐私约定,Profile 已声明私有路径": "AGENTS.md has no privacy convention, but the Profile declares private paths",
245
+ "Profile 的 privacy.forbidden_default_reads 非空,但 AGENTS.md 没有写默认不读、先经用户确认的约定;update-content --append AGENTS.md 可以保留原文并补上": "The Profile's privacy.forbidden_default_reads is not empty, but AGENTS.md has no rule to not read by default and to ask the user first; update-content --append AGENTS.md keeps your text and adds it",
246
+ "AGENTS.md 写着未声明私有路径,Profile 已声明": "AGENTS.md says no private paths are declared, but the Profile declares them",
247
+ "Profile 的 privacy.forbidden_default_reads 已非空;update-content 刷新 AGENTS.md 的隐私约定(改过的文件用 --append)": "The Profile's privacy.forbidden_default_reads is no longer empty; update-content refreshes the privacy convention in AGENTS.md (use --append for a file you edited)",
248
+ "AGENTS.md 写着私有路径约定,Profile 的 privacy.forbidden_default_reads 为空": "AGENTS.md carries the private-path convention, but the Profile's privacy.forbidden_default_reads is empty",
249
+ "字段为空表示没有私有路径;update-content 刷新 AGENTS.md,或把路径写回该字段": "An empty field means no private paths; refresh AGENTS.md with update-content, or put the paths back in the field",
250
+ "{0}。{1}": "{0}. {1}",
251
+ "同一文件只能选一种处理(--accept / --keep / --append / --merge):": "Choose only one treatment per file (--accept / --keep / --append / --merge): ",
252
+ "找不到这个文件升级前的基线(旧版本包不在本机运行时缓存和本地 git tag 里,也没能从 GitHub Release 取得),无法三方合并;没有改动任何文件,请改用 --keep / --append / --accept 选择": "The baseline this file had before the upgrade cannot be found (the old content pack is in neither the local runtime cache nor a local git tag, and could not be fetched from the GitHub Release), so a three-way merge is not possible. Nothing was changed; choose --keep / --append / --accept instead",
253
+ "refresh:三方合并这个本地已改动的文件(用旧版本包还原基线,保留你的改动并带入新模板的变化;默认只预览,先备份)": "refresh: three-way merge this locally edited file (rebuild the baseline from the old content pack, keep your edits and bring in the new template's changes; preview by default, backed up first)",
254
+ "refresh --merge:逐块选择冲突,写法 <文件>#<冲突块序号>=mine|theirs|both(可重复)": "refresh --merge: resolve a conflict block, written <file>#<block number>=mine|theirs|both (repeatable)",
255
+ "没有需要合并的本地改动(文件没改过,或已与新模板一致):": "No local edits to merge (the file is unchanged or already matches the new template): ",
256
+ "内容锁里没有它的基线,无法三方合并;请改用 --keep / --append / --accept 选择": "The content lock has no baseline for it, so a three-way merge is not possible; choose --keep / --append / --accept instead",
257
+ "三方合并:新模板的变化已并入你的版本(自动合并 {0} 处,冲突 {1} 处均已选择;基线取自 {2});写入前先备份": "Three-way merge: the new template's changes are merged into your version (auto-merged hunks: {0}, conflict blocks all resolved: {1}; baseline from {2}); backed up before writing",
258
+ "有 {0} 处冲突需要你选择(第 {1} 块):--pick {2}#<序号>=mine|theirs|both(mine 保留你的、theirs 取新模板、both 两边都留)": "Conflict blocks to resolve: {0} (block numbers {1}): --pick {2}#<number>=mine|theirs|both (mine keeps yours, theirs takes the new template, both keeps both)",
259
+ "--pick 的写法是 <文件>#<冲突块序号>=mine|theirs|both:{0}": "--pick is written <file>#<block number>=mine|theirs|both: {0}",
260
+ "--pick 只能用于同时带 --merge 的文件:{0}": "--pick works only for a file that also has --merge: {0}",
261
+ "--pick 指向的冲突块不存在:{0}#{1}(先用 --merge {0} 查看冲突块序号)": "--pick names a conflict block that does not exist: {0}#{1} (run --merge {0} first to see the block numbers)",
262
+ "也可以三方合并(用旧版本包还原出升级前的基线,保留你的改动并带入新模板的变化):--merge {0}": "You can also run a three-way merge (rebuild the pre-upgrade baseline from the old content pack, keep your edits and bring in the new template's changes): --merge {0}",
263
+ "你的版本": "your version",
264
+ "基线": "baseline",
265
+ "新模板": "new template",
266
+ " 冲突块 {0}:": " Conflict block {0}:",
267
+ "写入 {0} 失败,临时文件已清理:{1}。已写好的文件与备份保持一致,排除原因后重新运行同一条命令即可继续": "Writing {0} failed and the temporary file was removed: {1}. Files already written and their backups stay consistent; fix the cause and rerun the same command to continue",
268
+ "{0}:{1} 是符号链接({2},指向 {3}),出于安全不跟随符号链接。可以用 {4} 另设一个真实目录,或确认链接目标无误后自行把它换成真实目录再重试": "{0}: {1} is a symbolic link ({2}, pointing to {3}); symbolic links are not followed for safety. Use {4} to choose a real directory elsewhere, or confirm the link target and replace it with a real directory yourself, then retry",
269
+ "绝对路径": "absolute path",
270
+ "相对路径": "relative path",
271
+ "check:退出码只看「需要处理」的发现(与 agenthelm check 一致);缺省「可选」差异也使退出码为 1": "check: the exit code looks only at findings that must be handled (same as agenthelm check); by default optional differences also give exit code 1",
272
+ "--required-only 只用于 --mode check": "--required-only applies only to --mode check",
273
+ "{0} 是指向 {1} 的符号链接,refresh 不跟随链接改写,不能用 --accept / --append / --merge;要保留请用 --keep {0},要让模板接管请先把它换成普通文件": "{0} is a symbolic link to {1}; refresh does not write through links, so --accept / --append / --merge cannot be used on it. Use --keep {0} to keep it, or replace it with a regular file first to let the template take over",
274
+ "{0} 是指向 {1} 的符号链接,refresh 不跟随链接改写,保留原样": "{0} is a symbolic link to {1}; refresh does not write through links and leaves it as it is",
275
+ "确认后用 --keep {0} 记为保留(之后不再追问);要让模板接管请先把它换成普通文件": "Once confirmed, record it with --keep {0} (it will not be asked about again); to let the template take over, replace it with a regular file first",
276
+ "已应用": "Applied",
277
+ "仅预览": "Dry-run",
278
+ "已阻塞": "Blocked",
279
+ "新建": "create",
280
+ "替换": "replace",
281
+ "保留": "preserve",
282
+ " 已阻塞 [{0}] {1}": " blocked [{0}] {1}",
283
+ " 说明:{0}": " note: {0}",
284
+ "{0}:入口 ./{1}": "{0}: entry ./{1}",
285
+ "{0}:{1}(来自 {2})": "{0}: {1} (from {2})",
286
+ "{0}:新建 {1},替换 {2},保留冲突 {3}": "{0}: {1} create, {2} replace, {3} preserved collisions",
287
+ " 跳过 {0}(父目录是符号链接)": " skip {0} (symlinked parent)",
288
+ " 退役 {0}(已升级进 {1})": " retire {0} (upgraded into {1})"
289
+ }
@@ -0,0 +1,149 @@
1
+ """三方合并(基线、用户版本、新模板):纯文本,不碰文件系统。
2
+
3
+ 粒度选按行(diff3)。用 v6.6.0 / v6.7.0 / v6.8.0 的 AGENTS.md 渲染结果作基线、当前模板作新版,对基线的每一行
4
+ 分别做“改写”和“其后插入”共 82 种单行用户改动,再加追加章节、改中间行、改标题下一行等场景:按行与“先按章节、
5
+ 冲突的章节再按行”两种粒度的冲突块数完全相同(7 对 7);真实模板两次发布之间只有两处改动,章节粒度没有带来收益,
6
+ 却多一层实现与一种更难解释的冲突范围,所以用更简单的按行。
7
+
8
+ 结果是片段列表:``Text`` 为已定的文本,``Conflict`` 为需要用户选择的一块(保留两边与基线)。
9
+ """
10
+ from __future__ import annotations
11
+
12
+ import difflib
13
+ from dataclasses import dataclass, field
14
+
15
+ MARK_MINE = "<<<<<<< "
16
+ MARK_BASE = "||||||| "
17
+ MARK_SPLIT = "======="
18
+ MARK_THEIRS = ">>>>>>> "
19
+
20
+
21
+ @dataclass
22
+ class Text:
23
+ lines: list[str]
24
+
25
+
26
+ @dataclass
27
+ class Conflict:
28
+ base: list[str]
29
+ mine: list[str]
30
+ theirs: list[str]
31
+ number: int = 0
32
+
33
+
34
+ @dataclass
35
+ class Merged:
36
+ parts: list[Text | Conflict] = field(default_factory=list)
37
+ auto_hunks: int = 0 # 两边都动过但自动合并成功的块数(含只有一边改动的块不计)
38
+
39
+ @property
40
+ def conflicts(self) -> list[Conflict]:
41
+ return [part for part in self.parts if isinstance(part, Conflict)]
42
+
43
+ def render(self, picks: dict[int, str] | None = None, labels: tuple[str, str, str] = ("mine", "base", "theirs")) -> str:
44
+ """合并后的文本;``picks`` 把冲突块编号映射到 mine / theirs / both,未选的块以标记保留两边。"""
45
+ picks = picks or {}
46
+ out: list[str] = []
47
+ for part in self.parts:
48
+ if isinstance(part, Text):
49
+ out += part.lines
50
+ continue
51
+ choice = picks.get(part.number)
52
+ if choice == "mine":
53
+ out += part.mine
54
+ elif choice == "theirs":
55
+ out += part.theirs
56
+ elif choice == "both":
57
+ out += part.mine + part.theirs
58
+ else:
59
+ out += [_line(MARK_MINE + labels[0]), *part.mine, _line(MARK_BASE + labels[1]), *part.base,
60
+ _line(MARK_SPLIT), *part.theirs, _line(MARK_THEIRS + labels[2])]
61
+ return "".join(out)
62
+
63
+ def unresolved(self, picks: dict[int, str] | None = None) -> list[Conflict]:
64
+ picks = picks or {}
65
+ return [item for item in self.conflicts if picks.get(item.number) not in ("mine", "theirs", "both")]
66
+
67
+
68
+ def _line(text: str) -> str:
69
+ return text + "\n"
70
+
71
+
72
+ def _changes(base: list, other: list) -> list[tuple[int, int, list]]:
73
+ matcher = difflib.SequenceMatcher(None, base, other, autojunk=False)
74
+ return [(i1, i2, other[j1:j2]) for tag, i1, i2, j1, j2 in matcher.get_opcodes() if tag != "equal"]
75
+
76
+
77
+ def _apply(base: list, start: int, end: int, changes: list[tuple[int, int, list]]) -> list:
78
+ out, position = [], start
79
+ for i1, i2, replacement in changes:
80
+ out += base[position:i1] + replacement
81
+ position = i2
82
+ return out + base[position:end]
83
+
84
+
85
+ def diff3(base: list, mine: list, theirs: list):
86
+ """三方合并通用实现:产出 ``("same", items)`` / ``("both", items)`` / ``("conflict", base, mine, theirs)``。
87
+
88
+ 两边的改动区间相交或首尾相接即视为同一组(与 git 一致,宁可多报冲突也不拼错);一组里只有一边改动时直接采用,
89
+ 两边改成同样内容时算一致。
90
+ """
91
+ left, right = _changes(base, mine), _changes(base, theirs)
92
+ out, position = [], 0
93
+ while left or right:
94
+ first = min((side[0] for side in (left, right) if side), key=lambda change: change[0])
95
+ start = first[0]
96
+ if start > position:
97
+ out.append(("same", base[position:start]))
98
+ end = max(first[1], start)
99
+ group_l: list = []
100
+ group_r: list = []
101
+ grew = True
102
+ while grew:
103
+ grew = False
104
+ for side, group in ((left, group_l), (right, group_r)):
105
+ while side and side[0][0] <= end:
106
+ change = side.pop(0)
107
+ group.append(change)
108
+ end = max(end, change[1])
109
+ grew = True
110
+ position = end
111
+ if group_l and not group_r:
112
+ out.append(("one", _apply(base, start, end, group_l)))
113
+ elif group_r and not group_l:
114
+ out.append(("one", _apply(base, start, end, group_r)))
115
+ else:
116
+ a, b = _apply(base, start, end, group_l), _apply(base, start, end, group_r)
117
+ out.append(("both", a) if a == b else ("conflict", base[start:end], a, b))
118
+ if position < len(base):
119
+ out.append(("same", base[position:]))
120
+ return out
121
+
122
+
123
+ def _flatten(items) -> list[str]:
124
+ return [line for item in items for line in (item if isinstance(item, list) else [item])]
125
+
126
+
127
+ def merge_lines(base: list[str], mine: list[str], theirs: list[str]) -> Merged:
128
+ result = Merged()
129
+ for kind, *payload in diff3(base, mine, theirs):
130
+ if kind == "conflict":
131
+ result.parts.append(Conflict(*payload))
132
+ continue
133
+ if kind == "both":
134
+ result.auto_hunks += 1
135
+ result.parts.append(Text(payload[0]))
136
+ return result
137
+
138
+
139
+ def merge_text(base: str, mine: str, theirs: str) -> Merged:
140
+ """合并三份文本;冲突块按出现顺序编号 1、2、3…"""
141
+ b, m, t = (text.splitlines(keepends=True) for text in (base, mine, theirs))
142
+ # 末行没有换行符时补齐,避免“最后一行有无换行”被当成改动。
143
+ for lines in (b, m, t):
144
+ if lines and not lines[-1].endswith("\n"):
145
+ lines[-1] += "\n"
146
+ merged = merge_lines(b, m, t)
147
+ for number, conflict in enumerate(merged.conflicts, 1):
148
+ conflict.number = number
149
+ return merged
@@ -0,0 +1,99 @@
1
+ #!/usr/bin/env python3
2
+ """受管区块(managed region):工具只拥有带标记的区块,文件里其余内容归用户。
3
+
4
+ 区块形如::
5
+
6
+ <!-- agenthelm:region claude-import sha=0123456789ab -->
7
+ @AGENTS.md
8
+ <!-- /agenthelm:region claude-import -->
9
+
10
+ ``sha`` 是区块正文的指纹。区块被改动(正文与指纹不符)视为用户编辑:升级时给出差异,由用户决定,
11
+ 区块之外的内容永远不被读取以外的方式触碰。本模块只处理文本,不读写文件;落盘、备份、决定记录由调用方负责。
12
+ """
13
+ from __future__ import annotations
14
+
15
+ import hashlib
16
+ import re
17
+ from dataclasses import dataclass
18
+
19
+ from i18n_init import _ # noqa: E402
20
+
21
+ ID_PATTERN = r"[a-z0-9][a-z0-9._-]{0,63}"
22
+ ID_RE = re.compile(rf"^{ID_PATTERN}$")
23
+ REGION_RE = re.compile(
24
+ rf"<!-- agenthelm:region (?P<id>{ID_PATTERN}) sha=(?P<sha>[0-9a-f]{{12}}) -->\n"
25
+ rf"(?P<body>.*?)"
26
+ rf"<!-- /agenthelm:region (?P=id) -->\n?",
27
+ re.DOTALL,
28
+ )
29
+
30
+
31
+ @dataclass(frozen=True)
32
+ class Region:
33
+ id: str
34
+ body: str
35
+ recorded: str # 标记里记录的正文指纹
36
+ start: int
37
+ end: int
38
+
39
+ @property
40
+ def digest(self) -> str:
41
+ return digest(self.body)
42
+
43
+ @property
44
+ def intact(self) -> bool:
45
+ """区块正文与标记里的指纹一致,即用户没有改过区块内部。"""
46
+ return self.digest == self.recorded
47
+
48
+
49
+ def normalize(body: str) -> str:
50
+ return body if body.endswith("\n") else body + "\n"
51
+
52
+
53
+ def digest(body: str) -> str:
54
+ return hashlib.sha256(normalize(body).encode("utf-8")).hexdigest()[:12]
55
+
56
+
57
+ def render(region_id: str, body: str) -> str:
58
+ if not ID_RE.fullmatch(region_id):
59
+ raise ValueError(_("区块 ID 不合法:{0}").format(region_id))
60
+ body = normalize(body)
61
+ if "<!-- agenthelm:region" in body or "<!-- /agenthelm:region" in body:
62
+ raise ValueError(_("区块正文不能包含区块标记"))
63
+ return f"<!-- agenthelm:region {region_id} sha={digest(body)} -->\n{body}<!-- /agenthelm:region {region_id} -->\n"
64
+
65
+
66
+ def find(text: str) -> list[Region]:
67
+ return [Region(m.group("id"), m.group("body"), m.group("sha"), m.start(), m.end()) for m in REGION_RE.finditer(text)]
68
+
69
+
70
+ def get(text: str, region_id: str) -> Region | None:
71
+ return next((region for region in find(text) if region.id == region_id), None)
72
+
73
+
74
+ def upsert(text: str, region_id: str, body: str, *, force: bool = False) -> tuple[str, str]:
75
+ """把区块写入文本,返回 (新文本, 状态)。
76
+
77
+ 状态:``inserted`` 追加到末尾;``unchanged`` 已是这个正文;``updated`` 区块完好,换成新正文;
78
+ ``modified`` 区块内部被用户改过,没有 ``force`` 时文本原样返回。
79
+ """
80
+ existing = get(text, region_id)
81
+ rendered = render(region_id, body)
82
+ if existing is None:
83
+ separator = "" if not text else ("\n" if text.endswith("\n") else "\n\n")
84
+ return text + separator + rendered, "inserted"
85
+ if existing.body == normalize(body) and existing.intact:
86
+ return text, "unchanged"
87
+ if not existing.intact and not force:
88
+ return text, "modified"
89
+ return text[:existing.start] + rendered + text[existing.end:], "updated"
90
+
91
+
92
+ def remove(text: str, region_id: str) -> tuple[str, bool]:
93
+ existing = get(text, region_id)
94
+ if existing is None:
95
+ return text, False
96
+ before = text[:existing.start].rstrip("\n")
97
+ after = text[existing.end:].lstrip("\n")
98
+ joined = before + ("\n\n" if before and after else "\n" if before else "") + after
99
+ return joined, True