Skip to main content

safe-file-writing

Safe ways to edit/overwrite files in Hermes Agent. Avoids file corruption from write_file on large files and Excel file locks.

来源信息

仓库
crimsonblazezero/Zero-Tools
最近来源活动
2026年8月3日 15:27
检测到的 SKILL.md 语言
英语
星标
0
分支
0

安装方式

默认使用会先检查来源的 Prompt;你也可以切换为直接命令,或下载本地副本。

检查来源文件

决定是否安装前,请先阅读 SKILL.md,以及 SkillsMP 当前展示的配套文件。

正在显示 SKILL.md

SKILL.md
来源说明 · 只读预览
name
safe-file-writing
description
Safe ways to edit/overwrite files in Hermes Agent. Avoids file corruption from write_file on large files and Excel file locks.
tags
["file","write","patch","safe-editing"]
# Safe File Writing ## ⚠️ Never Use write_file for Large Files When editing or overwriting scripts >400 lines, **always use `patch` instead of `write_file`**. `write_file` truncates long content silently, producing corrupt but compilable-looking files. ## Safe Editing Patterns ### Pattern 1: Patch Only (Preferred) ```bash # Only modify the exact lines you need to change patch --path scripts/weekly_report.py \ --old "old line" \ --new "new line" ``` ### Pattern 2: Import and Run When you need to generate output without risking the source file: ```python # Create a small wrapper script import sys sys.path.insert(0, 'scripts') from weekly_report import * # Use existing functions directly build_excel(wk_m, mo_m, fb_agg, wt, mt, 'output.xlsx') ``` ### Pattern 3: Backup First If you absolutely must rewrite: 1. Copy original first 2. Write new content 3. Verify compilation before deleting backup ## Excel File Locks `.xlsx` files locked by Excel → openpyxl raises PermissionError. **Fix:** Write to a new filename like `xxx_v19_new.xlsx`, never overwrite the open file.
在 GitHub 查看