cleanup-changes
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCleanup Changes Skill
清理更改 Skill
Both humans and agents typically go through a trial-and-error process when writing code, making numerous changes (including non-essential and unnecessary ones) to achieve their final goals. However, non-essential and unnecessary changes resulting from this trial-and-error process should not be included in the final code. Changes should be reviewed as needed, and unnecessary changes should be reversed to focus only on essential ones.
人类和 agent 在编写代码时通常会经历 trial-and-error 过程,通过进行大量更改(包括非必要和不必要的更改)来实现最终目标。然而,由这一 trial-and-error 过程产生的非必要和不必要更改不应包含在最终代码中。应根据需要审查各项更改,并撤销不必要的更改,只关注必要更改。
When to apply
何时应用
You should perform this skill when a user requests a cleanup of changes, or before creating a commit or pull request.
当用户请求清理更改,或在创建 commit 或 pull request 之前,应执行此 skill。
Steps
步骤
The following is the core of this skill; please follow the specified steps. Do not change the Git staging state unless explicitly instructed to do so by the user. Users may have staged their changes as a snapshot of the code in its last expected state.
以下是此 skill 的核心内容;请遵循指定步骤。除非用户明确指示,否则不要更改 Git staging state。用户可能已经 staged 其更改,以将代码保存为最后预期状态的快照。
1. Looking back on the trial-and-error process
1. 回顾 trial-and-error 过程
Reflect on the trial-and-error process of the task and distinguish between changes that were essentially necessary and changes that, despite being tried, ultimately proved ineffective and unnecessary.
You shouldn't make assumptions about whether a change is essentially necessary. For example, when fixing a bug, review the changes made when the bug was finally fixed, understand the essential and root cause of the bug, and then, based on that, determine whether each change is essentially necessary.
When determining whether each change is necessary, pay particular attention to bugs caused by multiple factors. Bugs can be caused by a single, simple cause, or by multiple factors. If it's caused by a single, simple cause, the last change made when the bug is fixed may be sufficient, and previous changes may be unnecessary. If it's a bug caused by multiple factors, the last change alone may not be enough, and some of the changes made during the trial-and-error process leading up to it may also be necessary. Carefully consider the underlying cause of the bug, including whether it's due to a single cause or multiple factors, and then determine which changes are necessary and which are not.
回顾任务的 trial-and-error 过程,区分本质上是必要的更改与虽然尝试过、但最终证明无效和不必要的更改。
你不应主观假定某项更改是否确有必要。例如,在修复 bug 时,应回顾 bug 最终修复时所做的更改,理解其关键因素和 root cause,然后据此判断每项更改是否确有必要。
判断每项更改是否必要时,应特别注意由多个因素引起的 bug。Bug 可能由单一简单原因引起,也可能由多个因素引起。如果由单一简单原因引起,修复 bug 时最后所做的更改可能已经足够,之前的更改则可能不必要。如果 bug 由多个因素引起,仅靠最后一项更改可能不够,而且在此前的 trial-and-error 过程中所做的某些更改也可能必要。仔细考虑 bug 的根本原因,包括它是由单一原因还是多个因素造成,然后判断哪些更改是必要的,哪些不是。
2. Undo unnecessary changes
2. 撤销不必要的更改
Revert any changes you determined were unnecessary in the previous step, leaving only the essential changes.
However, even if a change isn't strictly necessary, minor corrections to typos around the current change or small refactorings are acceptable. Generally, in coding, correcting typos found around a change or making small refactorings related to the current change are generally tolerated, even if they aren't strictly necessary.
撤销上一步中确定不必要的所有更改,仅保留必要更改。
不过,即使某项更改并非严格必要,也可以对当前更改附近出现的 typo 作小幅更正,或进行小幅 refactoring。通常在编码中,修正更改附近发现的 typo,或对与当前更改相关的内容进行小幅 refactoring,即使严格来说并非必要,也通常是可以接受的。