← 返回 Skills 市场
ykaixu

File Writer

作者 YuKaiXu · GitHub ↗ · v1.0.0
cross-platform ✓ 安全检测通过
764
总下载
0
收藏
9
当前安装
1
版本数
在 OpenClaw 中安装
/install file-writer
功能描述
Safely write or update large files over 5000 bytes by reading, incrementally editing small sections, verifying each change, and using fallback recovery methods.
使用说明 (SKILL.md)

File Writer

Safe file writing strategy for large files to avoid truncation issues.

When to Use

  • Writing files larger than 5000 bytes
  • Updating existing files with significant changes
  • Modifying specific sections of large files
  • Previous write operations were truncated
  • Need to ensure file integrity

Problem Analysis

Why Files Get Truncated

Large file writes can fail due to:

  1. Tool limitations - write tool may have byte limits per operation
  2. Network limits - Large file transfers may be truncated during transmission
  3. System limits - OpenClaw may have size limits on single operations

Safe Size Thresholds

Operation Safe Size Risk Level
write new file \x3C 2000 bytes ✅ Safe
write new file 2000-5000 bytes ⚠️ Moderate
write new file > 5000 bytes ❌ High risk
edit modification \x3C 500 bytes ✅ Safe
edit modification 500-1000 bytes ⚠️ Moderate
edit modification > 1000 bytes ❌ High risk

Safe Writing Strategy

Step 1: Read Current State

Before making changes, read the current file state:

# Read the file to understand current structure
read /path/to/file.md

# For large files, read specific sections
read /path/to/file.md --offset 100 --limit 50

Purpose:

  • Understand file structure
  • Identify exact text to replace `- Determine modification points

Step 2: Use Edit Tool for Precise Modifications

For small to medium changes, use edit tool:

Use `edit` tool with:
- `oldText`: Exact text to replace (must match exactly)
- `newText`: New text to replace with
- `file_path`: Path to the file

Best Practices:

  • Keep modifications under 500 bytes
  • Match oldText exactly (including whitespace)
  • Use unique text markers for large sections
  • Verify oldText exists before editing

Step 3: Verify Results

After each modification, verify the result:

# Check file line count
wc -l /path/to/file.md

# Read modified section
read /path/to/file.md --offset \x3Cstart> --limit \x3Clines>

# Verify file ends correctly
read /path/to/file.md --offset -10

Success Criteria:

  • File size increased as expected
  • Modified section contains new content
  • File ends correctly (not truncated)
  • No syntax errors (for code files)

Step 4: Repeat Until Complete

For large multi-section updates:

  1. Modify one section at a time
  2. Verify each modification
  3. Proceed to next section
  4. Repeat until all changes complete

Fallback Strategies

Strategy 1: Split Large Writes

If write tool fails for large content:

Split content into chunks:

1. Write first chunk (header + section 1)
2. Verify and append section 2
3. Verify and append section 3
4. Continue until complete

Strategy 2: Use Unique Markers

For complex modifications, use unique markers:

In source file:
\x3C!-- SECTION_START: configuration -->
[existing content]
\x3C!-- SECTION_END: configuration -->

Edit operation:
oldText: "\x3C!-- SECTION_START: configuration -->\
[existing content]\
\x3C!-- SECTION_END: configuration -->"
newText: "\x3C!-- SECTION_START: configuration -->\
[new content]\
\x3C!-- SECTION_END: configuration -->"

Strategy 3: Incremental Build

For creating new large files:

1. Create file with basic structure
2. Add sections one by one using edit
3. Verify after each addition
4. Final verification

Strategy 4: Backup and Restore

For critical file modifications:

# Create backup before modification
cp /path/to/file.md /path/to/file.md.backup

# Attempt modification
# ... (write or edit operation)

# If modification fails, restore
cp /path/to/file.md.backup /path/to/file.md

Error Recovery

Edit Tool Fails

Symptom: "Could not find exact text in file"

Causes:

  • oldText doesn't match exactly
  • Whitespace differences (spaces vs tabs)
  • File already modified
  • Text doesn't exist in file

Solutions:

  1. Re-read the file to get exact content
  2. Use unique markers for large sections
  3. Match whitespace exactly (copy from file read)
  4. Use smaller oldText for more precise matching

Write Tool Truncates

Symptom: File ends abruptly or is incomplete

Solutions:

  1. Use edit tool instead of write
  2. Split content into smaller chunks
  3. Write incrementally (section by section)
  4. Verify file size after each operation

File Corruption

Symptom: File has syntax errors or invalid content

Solutions:

  1. Restore from backup
  2. Re-read and re-verify
  3. Use incremental build strategy
  4. Validate syntax after each modification

Examples

Example 1: Adding Section to Large File

Step 1: Read file to find insertion point
read /path/to/large-file.md --offset 50 --limit 10

Step 2: Use edit to add new section
edit:
  file_path: /path/to/large-file.md
  oldText: "## Existing Section\
\
Content here"
  newText: "## Existing Section\
\
Content here\
\
## New Section\
\
New content"

Step 3: Verify
read /path/to/large-file.md --offset 50 --limit 20

Example 2: Creating Large New File

Step 1: Create basic structure
write:
  file_path: /path/to/new-file.md
  content: "# Title\
\
## Section 1\
\
Content 1"

Step 2: Add sections incrementally
edit:
  file_path: /path/to/new-file.md
  oldText: "Content 1"
  newText: "Content 1\
\
## Section 2\
\
Content 2"

Step 3: Verify
wc -l /path/to/new-file.md

Example 3: Replacing Large Section

Step 1: Read file to find exact text
read /path/to/file.md

Step 2: Use unique markers
edit:
  file_path: /path/to/file.md
  oldText: "\x3C!-- START: old-section -->\
[old content]\
\x3C!-- END: old-section -->"
  newText: "\x3C!-- START: old-section -->\
[new content]\
\x3C!-- END: old-section -->"

Step 3: Verify
read /path/to/file.md | grep "new content"

Best Practices

  1. Always read before editing - Understand current state
  2. Use edit for modifications - More precise than write
  3. Keep changes small - Under 500 bytes per edit
  4. Verify after each operation - Don't batch operations
  5. Use unique markers - For complex modifications
  6. Create backups - For critical files
  7. Handle errors gracefully - Provide recovery strategies
  8. Test incrementally - Verify each step

Decision Tree

Need to write/update file?
├─ New file?
│  ├─ \x3C 2000 bytes?
│  │  └─ Use write tool
│  └─ > 2000 bytes?
│     └─ Use incremental build strategy
└─ Existing file?
   ├─ Small change (\x3C 500 bytes)?
   │  └─ Use edit tool
   ├─ Medium change (500-1000 bytes)?
   │  └─ Use edit with unique markers
   └─ Large change (> 1000 bytes)?
      └─ Use incremental edit strategy

Quick Reference

Task Tool Strategy
Create small file write Direct write
Create large file write + edit Incremental build
Small modification edit Direct edit
Medium modification edit Edit with markers
Large modification edit Incremental edit
Replace section edit Unique markers
Append content edit Edit end of file
安全使用建议
This skill is internally consistent and appears to do what it says, but it grants the agent the ability to read and write arbitrary files (including recommended use of cp/backups). Before installing or enabling it: (1) confirm what the agent-provided commands like read/edit/write map to in your runtime and ensure they enforce OS file permissions; (2) restrict the agent's filesystem access (or sandbox it) so it cannot touch sensitive system or credential files; (3) test the strategy on non-sensitive files first; (4) require backups and logging for any production file changes; and (5) consider adding a wrapper or policy that limits allowed target paths and enforces review for destructive changes.
功能分析
Type: OpenClaw Skill Name: file-writer Version: 1.0.0 The skill bundle describes a safe strategy for an AI agent to write and edit large files, using internal OpenClaw tools (`write`, `edit`) and standard shell commands (`read`, `cp`, `wc`, `grep`) for verification and backup. The instructions in SKILL.md are procedural, focusing on robust file operations and error recovery. There is no evidence of malicious intent, such as data exfiltration, unauthorized command execution, persistence mechanisms, or prompt injection designed to subvert the agent for harmful purposes. All described actions are directly related to the stated goal of safe file manipulation.
能力评估
Purpose & Capability
Name/description (safe file writes for large files) match the SKILL.md: the instructions describe reading, chunking, editing, verifying, backing up and restoring files. There are no unrelated env vars, binaries, or installs requested.
Instruction Scope
The runtime instructions explicitly tell the agent to read, edit, write and copy arbitrary file paths and to run checks (e.g., cp, wc, read with offsets). Those actions are appropriate for a file-writer skill, but they give broad file-system read/write capability — which is powerful and should be constrained by runtime permissions and deployed agent policy.
Install Mechanism
No install spec and no code files — the skill is instruction-only so nothing is downloaded or written to disk by an installer.
Credentials
The skill requires no environment variables, credentials, or config paths beyond normal file paths, which is proportionate to its stated purpose.
Persistence & Privilege
always is false and there is no indication the skill requests persistent or elevated platform privileges; autonomous invocation is allowed by default but not combined with other risk signals here.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install file-writer
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /file-writer 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.0.0
Initial release - Safe file writing strategy for large files with step-by-step approach, fallback strategies, and error recovery
元数据
Slug file-writer
版本 1.0.0
许可证
累计安装 11
当前安装数 9
历史版本数 1
常见问题

File Writer 是什么?

Safely write or update large files over 5000 bytes by reading, incrementally editing small sections, verifying each change, and using fallback recovery methods. 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 764 次。

如何安装 File Writer?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install file-writer」即可一键安装,无需额外配置。

File Writer 是免费的吗?

是的,File Writer 完全免费(开源免费),可自由下载、安装和使用。

File Writer 支持哪些平台?

File Writer 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 File Writer?

由 YuKaiXu(@ykaixu)开发并维护,当前版本 v1.0.0。

💬 留言讨论