File Change Tracker
Mandatory before the first file-changing action in a new edit batch.
This is a safety skill.
If the task will create a file, create a script, create a README, edit content, overwrite a file, apply a patch, rename or move files, delete files, change config, update docs, refactor code, or run a command that generates files, stop first, decide the target paths, and run pre before making any file change.
Mandatory not to make any file change first and try to protect it later.
Mandatory not to skip this skill just because the task looks small, easy, or easy to recreate.
Mandatory not to run pre before every incremental change inside the same batch.
Mandatory to run pre once at batch start, then perform the file changes, then run post when the batch is complete.
Trigger rule
Use this skill as soon as the plan includes any file-changing action.
The trigger is the planned file change, not the implementation mechanism.
Do not wait for a git-specific task, a large task, or a risky task.
If any file will be created, edited, overwritten, patched, renamed, moved, deleted, or generated, this skill applies.
Do not use it for
Do not use it for read-only inspection, explanation-only tasks, search, grep, listing files, or diff-only review.
What this skill does
This skill adds a lightweight local protection layer around file changes.
The current helper implementation uses local git to record recovery points, scope checks to explicit paths, and provide rollback guidance.
Before the first file-changing action, it creates or records a recovery point for the explicit target paths of the task.
After the task finishes, it records the result when needed, shows recent commits, and tells the user that rollback is available.
Each pre call opens a distinct file change session under .git/.guarded-edit/sessions/, so overlapping edit batches do not overwrite each other's state.
When to use it
Mandatory for tasks such as:
- - editing existing files
- creating new files such as a script, helper, config file, README, doc, or prompt
- deleting, renaming, or moving files
- refactoring across a known file set
- changing configuration files
- applying patches to known paths
- running shell commands that mutate a known file set
- generating code or other files into known paths
Do not use it for read-only inspection, explanation-only tasks, search, grep, or diff-only review.
Scope rule
This version is path-explicit.
Before the first file-changing action, gather the files or directories that are expected to change and pass them to pre.
If the target paths are not fixed yet, decide them first, then run pre before any write, apply_patch, overwrite, rename, move, delete, or file-creating shell command.
The helper will then scope its status checks, staging, and commits to those target paths instead of the whole workspace.
If the target path set grows later, Mandatory not to keep editing silently.
Run a new pre with the expanded path list before touching those newly added paths.
Mandatory exclusion rule
File Change Tracker uses a dedicated gitignore-style exclusion file instead of embedding default patterns in SKILL.md.
The active exclusion file is always:
- 1. INLINECODE12
Mandatory not to include target paths that match the active exclusion rules.
Any path that does not match the active exclusion rules may be included in the file change scope, subject to explicit task intent.
This lets the user control ignored paths by editing a single file that lives next to SKILL.md, instead of editing the skill text itself.
Index safety rule
This helper is intentionally conservative about the index.
If the declared target paths already contain staged changes, pre and post must fail instead of trying to restage those paths.
This avoids flattening hunk-level staging or otherwise rewriting the user's existing staged state for the guarded files.
Resolve, commit, or stash those staged changes first, then start a clean file change batch on those target paths.
Required workflow
1. Before the first file-changing action
Run:
CODEBLOCK0
Examples:
CODEBLOCK1
2. Perform the changes
Change only the declared target paths for this file change batch.
3. Validate if needed
Run tests, linters, type checks, or a focused sanity check when the task warrants it.
4. After the changes finish
Run:
CODEBLOCK2
If another file change batch was started before this one finished, select the intended session explicitly.
When multiple open sessions exist, post and rollback-help fail instead of guessing.
CODEBLOCK3
5. Report back to the user
INLINECODE18 should keep PRE and POST visible, and also include the most recent 3 to 5 path-scoped records. PRE, POST, and the recent records should all be rendered as id + comment so the user does not have to infer meaning from a bare SHA.
Always tell the user:
- - what the PRE snapshot is, shown as id + comment
- what the POST snapshot is or why it was not created, shown as id + comment
- what repo was used by the current helper implementation
- what target paths were protected
- the current session id
- the current session comment
- whether the current session is still open or already closed
- the most recent 3 to 5 saved sessions, with session id and comment shown together
- the most recent 3 to 5 path-scoped commit records, shown as id + comment
- that rollback is supported
- the safest rollback command for this task
- the active exclusion file
Reporting template
CODEBLOCK4
If a POST commit exists and the user may prefer a history-preserving rollback, also mention:
CODEBLOCK5
Behavior rules
- - Mandatory to initialize a local git repository automatically if the current helper implementation needs one and the current directory is not already one.
- Mandatory to set repo-local
user.name and user.email if git identity is missing for the current helper implementation. - Mandatory to respect
.gitignore and {baseDir}/guarded-edit.ignore. - Mandatory to scope checks, staging, and commits to the explicit target paths from
pre. - Mandatory to keep each file change batch in its own saved session under
.git/.guarded-edit/sessions/. - Mandatory for
post and rollback-help to require --session <session-id> instead of guessing when more than one file change session is still open. - Mandatory to fail if a declared target path is excluded by
{baseDir}/guarded-edit.ignore. - Non-ignored new files, generated artifacts, binaries, and accidentally placed sensitive files inside the declared target paths may also be included in the snapshot.
- Never push unless the user explicitly asked.
- Never rewrite history unless the user explicitly asked.
- Never hide failures.
- If PRE fails, stop risky changes and tell the user.
- If the target paths already have staged changes, fail instead of rewriting the target-path index state.
- If no PRE snapshot exists for the current file change session, do not run POST silently.
- INLINECODE30 uses the stored path set from
pre. It should not silently widen scope. - INLINECODE32 must prefer path-scoped restore guidance over whole-repo hard reset guidance.
- Commands shown to the user should be shell-safe.
Commit policy
PRE step
- - If the repo already has a clean
HEAD for the declared target paths, reuse it as the recovery point. - If the declared target paths already have unstaged or untracked changes and no staged changes in those paths, commit those paths as a PRE snapshot.
- If the declared target paths already have staged changes, fail and ask the user to resolve that index state first.
- If there is no
HEAD yet, create an initial anchor commit when needed.
POST step
- - Only run POST after a valid PRE snapshot for the same file change session exists.
- Mark the file change session closed after
post, even when no POST commit was needed. - If the declared target paths produced new unstaged or untracked changes and no staged changes in those paths, commit them as a POST snapshot.
- If the declared target paths already have staged changes, fail and ask the user to resolve that index state first.
- If nothing changed in the declared target paths after the task, report that no POST commit was needed.
This keeps history useful without creating unnecessary empty commits and avoids sweeping unrelated workspace changes into the guarded snapshot.
Preferred commands
CODEBLOCK6
Exclusion file
The exclusion file is:
CODEBLOCK7
Users can edit this file directly to control what File Change Tracker must exclude.
Use gitignore-style patterns.
Later matching patterns win, and ! can re-include a path inside the exclusion file.
Fallback manual commands
If the helper script is unavailable, use a conservative manual flow:
CODEBLOCK8
文件变更追踪器
在新编辑批次中执行首次文件变更操作前必须使用。
这是一项安全技能。
如果任务将创建文件、创建脚本、创建README、编辑内容、覆盖文件、应用补丁、重命名或移动文件、删除文件、更改配置、更新文档、重构代码,或运行生成文件的命令,请先停止,确定目标路径,并在进行任何文件变更前运行pre。
不得先进行文件变更再试图事后保护。
不得因为任务看起来很小、很简单或易于重新创建而跳过此技能。
不得在同一批次内的每次增量变更前都运行pre。
必须在批次开始时运行一次pre,然后执行文件变更,批次完成后运行post。
触发规则
一旦计划包含任何文件变更操作,立即使用此技能。
触发条件是计划中的文件变更,而非实现机制。
不要等待特定的git任务、大型任务或高风险任务。
如果任何文件将被创建、编辑、覆盖、打补丁、重命名、移动、删除或生成,此技能适用。
不适用场景
不适用于只读检查、仅解释任务、搜索、grep、列出文件或仅diff审查。
此技能的作用
此技能为文件变更添加了一个轻量级的本地保护层。
当前的辅助实现使用本地git记录恢复点,将范围检查限定在显式路径,并提供回滚指导。
在首次文件变更操作前,它为任务的显式目标路径创建或记录一个恢复点。
任务完成后,在需要时记录结果,显示最近的提交,并告知用户回滚可用。
每次pre调用都会在.git/.guarded-edit/sessions/下打开一个独立的文件变更会话,因此重叠的编辑批次不会互相覆盖状态。
何时使用
以下任务必须使用:
- - 编辑现有文件
- 创建新文件,如脚本、辅助工具、配置文件、README、文档或提示
- 删除、重命名或移动文件
- 跨已知文件集重构
- 更改配置文件
- 对已知路径应用补丁
- 运行会修改已知文件集的shell命令
- 将代码或其他文件生成到已知路径
不适用于只读检查、仅解释任务、搜索、grep或仅diff审查。
范围规则
此版本是路径显式的。
在首次文件变更操作前,收集预期会变更的文件或目录,并将其传递给pre。
如果目标路径尚未确定,请先确定,然后在任何write、apply_patch、覆盖、重命名、移动、删除或创建文件的shell命令之前运行pre。
然后辅助工具将把其状态检查、暂存和提交的范围限定在这些目标路径上,而非整个工作空间。
如果目标路径集后来扩大,不得默默继续编辑。
在触及这些新增路径之前,使用扩展后的路径列表运行一个新的pre。
强制排除规则
文件变更追踪器使用专用的gitignore风格排除文件,而非在SKILL.md中嵌入默认模式。
活动的排除文件始终是:
- 1. {baseDir}/guarded-edit.ignore
不得包含与活动排除规则匹配的目标路径。
任何与活动排除规则不匹配的路径都可以包含在文件变更范围内,但需服从显式的任务意图。
这允许用户通过编辑位于SKILL.md旁边的单个文件来控制忽略的路径,而无需编辑技能文本本身。
索引安全规则
此辅助工具对索引有意采取保守态度。
如果声明的目标路径已包含暂存的变更,pre和post必须失败,而不是尝试重新暂存这些路径。
这避免了扁平化hunk级别的暂存或以其他方式重写用户对这些受保护文件已有的暂存状态。
请先解决、提交或贮藏这些暂存的变更,然后在这些目标路径上开始一个干净的文件变更批次。
必需的工作流程
1. 首次文件变更操作前
运行:
bash
{baseDir}/scripts/helper.sh pre <简短原因> -- <路径> [<路径> ...]
示例:
bash
{baseDir}/scripts/helper.sh pre 修复登录验证 -- src/auth/login.ts src/auth/schema.ts
{baseDir}/scripts/helper.sh pre 创建新闻脚本和文档 -- scripts/news_hotspot.py scripts/README.md
{baseDir}/scripts/helper.sh pre 更新技能元数据 -- SKILL.md README.md README.user.md
{baseDir}/scripts/helper.sh pre 重新生成解析器输出 -- src/parser generated/
2. 执行变更
仅更改此文件变更批次声明的目标路径。
3. 必要时进行验证
当任务需要时,运行测试、linter、类型检查或针对性的健全性检查。
4. 变更完成后
运行:
bash
{baseDir}/scripts/helper.sh post <简短原因>
{baseDir}/scripts/helper.sh report 5
{baseDir}/scripts/helper.sh rollback-help
如果在此批次完成前开始了另一个文件变更批次,请显式选择目标会话。
当存在多个打开的会话时,post和rollback-help将失败而不是猜测。
bash
{baseDir}/scripts/helper.sh sessions 5
{baseDir}/scripts/helper.sh post <简短原因> --session <会话id>
{baseDir}/scripts/helper.sh rollback-help --session <会话id>
5. 向用户报告
report应保持PRE和POST可见,并包含最近3到5条路径范围的记录。PRE、POST和最近的记录都应呈现为id + 注释,以便用户不必从裸SHA中推断含义。
始终告知用户:
- - PRE快照是什么,显示为id + 注释
- POST快照是什么或为何未创建,显示为id + 注释
- 当前辅助实现使用了哪个仓库
- 哪些目标路径受到保护
- 当前会话id
- 当前会话注释
- 当前会话是仍打开还是已关闭
- 最近3到5个已保存的会话,同时显示会话id和注释
- 最近3到5条路径范围的提交记录,显示为id + 注释
- 支持回滚
- 此任务最安全的回滚命令
- 活动的排除文件
报告模板
text
已完成本次修改,并已做文件变更保护。
仓库: <仓库根目录>
当前会话:
- - id: <会话id>
- 状态: <打开或关闭>
- 注释: <会话注释>
保护路径:
PRE 快照:
sha> 主题>
POST 快照: sha 或 none> 主题 或 原因>
最近 5 次记录:
- - <主题1>
- <主题2>
- <主题3>
- <主题4>
- <主题5>
最近会话:
<会话输出,包含会话id + 会话注释 + pre/post摘要>
支持回退。
如需回到本次修改前,优先使用 rollback-help 输出的按路径 restore 命令,例如:
git restore --source= --staged --worktree --pathspec-from-file=<会话路径文件> --pathspec-file-nul
如需查看还能恢复到哪里,可用:
git reflog -n 10
如果存在POST提交且用户可能更喜欢保留历史的回滚,也请提及:
bash
git revert
行为规则
- - 如果当前辅助实现需要本地git仓库而当前目录还不是,则必须自动初始化一个。
- 如果当前辅助实现缺少git身份信息,则必须设置仓库本地的user.name和user.email。
- 必须尊重.gitignore和{baseDir}/guarded-edit.ignore。
- 必须将检查、暂存和提交的范围限定在pre中的显式目标路径。
- 必须将每个文件变更批次保存在.git/.guarded-edit/sessions/下各自的会话中。
- 当有多个文件变更会话仍打开时,post和rollback-help必须要求--session <会话id>而不是猜测。
- 如果声明的目标路径被{baseDir}/guarded-edit.ignore排除,则必须失败。
- 声明的目标路径内未被忽略的新文件、生成的工件、二进制文件和意外放置的敏感文件也可能包含在快照中。
- 除非用户明确要求,否则绝不推送。
- 除非用户明确要求,否则绝不重写历史。
- 绝不隐藏失败。
- 如果PRE失败,停止有风险的变更并告知用户。
- 如果目标路径已有暂存的变更,则失败而不是重写目标路径的索引状态。
- 如果当前文件变更会话没有PRE快照,则不要默默运行POST。
- post使用来自pre存储的路径集。不应默默扩大范围。
- rollback-help必须优先提供路径范围的恢复指导,而非整个仓库的硬重置指导。
- 向用户显示的命令应是shell安全的。
提交策略
PRE步骤
- - 如果仓库对声明的目标路径已有干净的HEAD,则将其重用为恢复点。
- 如果