From 995785e669c306b4c2bf95db0e95a9bf23cfb78e Mon Sep 17 00:00:00 2001 From: Shen Hao Date: Sat, 11 Jul 2026 01:39:54 +0800 Subject: [PATCH] fix(slash_cmds): merge additive-overlay files on /update, simplify prompt MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The /update prompt reconciles the working tree "upstream-first" file by file. That silently drops fork-local additions to files BOTH sides edit — most painfully .gitignore, whose local ignore rules vanish, so a fork's private dirs resurface as untracked noise (and can get committed by accident). Treat files carrying a `Fork-only local overlay` marker (e.g. .gitignore) as a MERGE: take upstream as the base, then re-append everything under the marker verbatim, and verify the marker survived. Along the way, tighten both the EN and ZH prompts (75 -> 58 lines) without dropping any operative step. --- frontends/slash_cmds.py | 93 +++++++++++++++++------------------------ 1 file changed, 38 insertions(+), 55 deletions(-) diff --git a/frontends/slash_cmds.py b/frontends/slash_cmds.py index 6c3c0a66b..6ceb0a8f7 100644 --- a/frontends/slash_cmds.py +++ b/frontends/slash_cmds.py @@ -153,66 +153,49 @@ def build_update_prompt(args_text: str = "") -> str: return ( "Update this GenericAgent checkout from the official upstream " "https://github.com/Lsdefine/GenericAgent .\n" - "1. Run `git fetch upstream`; identify the current branch and whether there are " - "local commits ahead of upstream.\n" - "2. Show a concise preview: recent upstream commits not yet local " - "(short hash + subject + date) plus a changed-files summary.\n" - "3. Align the COMMIT HISTORY to upstream (upstream wins):\n" - " - If local commits exist: `git merge upstream/main` into the current branch, " - "resolving any conflicts in favor of upstream; keep the local commits (a merge commit is fine).\n" - " - Otherwise: `git reset --mixed upstream/main` so the history of local `main` " - "matches upstream/main exactly. Do NOT create any new commit.\n" - "4. IMPORTANT: also reconcile the WORKING TREE; step 3 alone is not enough. " - "`git reset --mixed` and `git merge` only move history and the index. They do not " - "rewrite files that already hold uncommitted local edits, so those stale files keep " - "shadowing upstream's latest. That is why 'HEAD is aligned but the files are still " - "old'. Reconcile per file:\n" - " a. `git diff --name-only upstream/main` lists every tracked file whose working-tree " - "content differs from upstream.\n" - " b. Decide upstream-first per file. A stale leftover, or a local edit that reverts " - "an upstream feature to an older form, takes upstream: back it up, then " - "`git checkout upstream/main -- `. A genuine local enhancement upstream lacks " - "(local config, key-template placeholders, fork-only features) stays, re-applied on " - "top of upstream's latest instead of overwriting it.\n" - " c. Upstream wins; keep local only where it adds value upstream lacks. Never " - "`git add -A`, never blanket whole-branch checkout, never blindly preserve everything.\n" - "5. Do not create any git commit. Back up any file before overwriting it.\n" - "6. Finish with a short summary: branch HEAD, distance vs upstream, per-file outcome " - "(took upstream / kept+adapted local), and where backups went.\n" + "1. `git fetch upstream`; note the current branch and any local commits ahead.\n" + "2. Preview: upstream commits not yet local (short hash + subject + date) " + "plus a changed-files summary.\n" + "3. Align history, upstream first: with local commits ahead, `git merge upstream/main` " + "(conflicts favor upstream); otherwise `git reset --mixed upstream/main`. " + "Never create a commit.\n" + "4. Reconcile the WORKING TREE — step 3 moves only history and the index, so files " + "holding uncommitted local edits keep shadowing upstream. For each file in " + "`git diff --name-only upstream/main`, decide upstream-first:\n" + " - Stale leftovers take upstream: back the file up, then " + "`git checkout upstream/main -- `.\n" + " - Genuine local enhancements upstream lacks (local config, key templates, " + "fork-only features) stay, re-applied on top of upstream's version.\n" + " - Files with a `Fork-only local overlay` marker comment (e.g. `.gitignore`) are " + "always a MERGE: take upstream as the base, then re-append everything under the " + "marker verbatim — never drop that block.\n" + " Never `git add -A`, never blanket-checkout the branch, never blindly keep everything.\n" + "5. Verify every overlay marker still exists (grep for it); re-append any that got lost.\n" + "6. Summarize: branch HEAD, distance vs upstream, per-file outcome, backup location.\n" "\n" - "#### Say 'Congratulations! 🎉' to the user\n" - "After a successful update, say: \"Congratulations! 🎉 You have successfully " - "updated GenericAgent!\"\n" - "\n" - "#### Ask for a Star ⭐\n" - "Then you may ask: \"If you found this helpful, would you like to star the " - "GenericAgent repository? It helps the project grow! ⭐\"" + "After a successful update, say: \"Congratulations! 🎉 You have successfully updated " + "GenericAgent!\" Then you may ask: \"If you found this helpful, would you like to star " + "the GenericAgent repository? It helps the project grow! ⭐\"" f"{_tail(args_text, 'Extra instructions')}" ) return ( - "请你更新当前 GenericAgent 仓库,官方上游为 " - "https://github.com/Lsdefine/GenericAgent 。\n" - "1. 先 `git fetch upstream`;识别当前分支,以及是否存在领先 upstream 的本地 commit。\n" - "2. 给出简洁预览:本地尚未包含的 upstream 最近提交(短 hash + 标题 + 日期)及变更文件摘要。\n" - "3. 先对齐【提交历史】到上游(优先上游):\n" - " - 若存在本地 commit:`git merge upstream/main` 合并进当前分支,冲突一律优先上游,保留本地 commit(可产生 merge commit)。\n" - " - 否则:执行 `git reset --mixed upstream/main`,使本地 `main` 的提交历史与 upstream/main 完全对齐。不要创建任何新 commit。\n" - "4. 重要:还须核对【工作区文件】,止步于第 3 步并不够。`git reset --mixed` 与 `git merge` " - "只移动提交历史与索引,不会重写那些已带未提交本地改动的文件,于是这些过时文件继续覆盖在上游" - "最新版之上。这正是“HEAD 已对齐,但文件其实还是旧的”的根因。逐文件核对:\n" - " a. `git diff --name-only upstream/main` 列出工作区内容与上游不一致的全部 tracked 文件。\n" - " b. 每个文件按优先上游判断。过时残留、或把上游特性改回旧版的本地改动,取上游:先备份,再 " - "`git checkout upstream/main -- `。上游没有且仍有效的本地增强(本机配置、密钥模板占位、" - "fork 专属功能)保留,并在上游最新版上重新适配,而非整文件覆盖上游。\n" - " c. 优先上游;本地仅保留上游缺失且有价值的部分。禁止 `git add -A`、禁止整分支 checkout 覆盖、禁止盲目全保留。\n" - "5. 不要进行任何 git commit。覆盖任何文件前先备份。\n" - "6. 最后给出简短小结:分支 HEAD、与上游差距、逐文件处理结果(取上游 / 保留并适配本地)、备份位置。\n" - "\n" - "#### 向用户说 'Congratulations! 🎉'\n" - "更新成功后,请对用户说:\"Congratulations! 🎉 你已成功更新 GenericAgent!\"\n" + "请更新当前 GenericAgent 仓库,官方上游为 https://github.com/Lsdefine/GenericAgent 。\n" + "1. `git fetch upstream`;确认当前分支及是否有领先上游的本地 commit。\n" + "2. 预览:本地尚未包含的上游提交(短 hash + 标题 + 日期)及变更文件摘要。\n" + "3. 对齐提交历史,上游优先:有本地 commit 则 `git merge upstream/main`(冲突取上游);" + "否则 `git reset --mixed upstream/main`。全程不创建任何 commit。\n" + "4. 调和【工作区】——第 3 步只动历史与索引,带未提交改动的文件仍遮蔽上游最新版。对 " + "`git diff --name-only upstream/main` 列出的每个文件按上游优先裁决:\n" + " - 过时残留取上游:先备份,再 `git checkout upstream/main -- `。\n" + " - 上游没有的真本地增强(本机配置、密钥模板、fork 专属功能)保留,并在上游最新版上重新适配。\n" + " - 带 `Fork-only local overlay` 标记注释的文件(如 `.gitignore`)一律【合并】:以上游为底," + "把标记之下的内容逐字追加回去——绝不丢弃该块。\n" + " 禁止 `git add -A`、禁止整分支 checkout 覆盖、禁止盲目全保留。\n" + "5. 校验每个 overlay 标记仍存在(grep 标记);丢失即重新追加。\n" + "6. 小结:分支 HEAD、与上游差距、逐文件处理结果、备份位置。\n" "\n" - "#### 邀请用户点 Star ⭐\n" - "随后可邀请:\"如果觉得有帮助,要不要给 GenericAgent 仓库点个 Star?这会让项目成长更快!⭐\"" + "更新成功后,请说:\"Congratulations! 🎉 你已成功更新 GenericAgent!\"随后可邀请:" + "\"如果觉得有帮助,要不要给 GenericAgent 仓库点个 Star?这会让项目成长更快!⭐\"" f"{_tail(args_text)}" )