File Writer

👤 nagilem 📦 v1.0.0 ⭐ 4.2 ⬇️ 944 下载
💻 开发编程 免费

📖 技能介绍

File Writer Skill

Quick Start

  • Base directory: /home/alfred/.openclaw/workspace/scratch. All paths relative to this (e.g., "notes.txt" or "subdir/log.md").
  • Sanitize: Reject if path contains '../', starts with '/', or has non-text extensions (allow only .txt, .md, .log, .json).
  • Primary tools: 'write' for saving, 'read' for checks/backups, 'exec' for mkdir -p (fallback to message if unavailable).
  • Mode: Write (default/overwrite with backup), append (if specified).

Step-by-Step Workflow

  1. Parse query: Extract rel_path (e.g., "subdir/notes.txt"), content, mode (write/append; infer from phrases like "update" = write).
    • If missing (e.g., "write that information"), use message to ask for rel_path/content.
  2. Sanitize: Validate rel_path (no escapes, safe extension). Compute full_path = base_dir + rel_path.
  3. Create subdirs if needed: Extract parent from rel_path; call 'exec'("mkdir -p [base_dir]/[parent]") or message: "Please run mkdir -p [full_parent] and confirm."
  4. Check existence (call 'read' on full_path):
    • If exists and write mode: Create backup (read content, find unique .bak.N path, 'write' to it).
    • Confirm overwrite/append: Use message ("Confirm [action] on [file]? Yes/No").
  5. Execute:
    • Write: 'write' full_path with content.
    • Append: 'read' existing, concatenate content, 'write' back.
  6. Handle errors: Reply with details; log via message ("Wrote [bytes] to [full_path] at [timestamp]").
  7. If tools fail, fallback: Message requesting user runs echo "[content]" > [full_path] or >> for append.

Safety Guidelines

  • Limits: Max 50k chars; reject binary/large.
  • Backups: Always for overwrites; increment .bak.N until unique (e.g., check with 'read').
  • Sensitive paths: If contains 'secret' or 'key', double-confirm.
  • No auto-mkdir if exec unavailable: Require user confirmation/action.
  • See references/safety.md for patterns.

Edge Cases

  • Empty content: Reject with "Content required."
  • Non-existent for append: Treat as write.
  • Existing .bak: Increment (e.g., .bak.1, .bak.2; use loop with 'read' to find next).
  • Invalid path: "Invalid: Must be relative text file in scratch."

    小葱技能站7w4.net发现了升级插件。

  • Large content: Reject or chunk (multiple writes if over limit).

Bundled Resources

  • scripts/backup_file.sh: Fallback Bash for creating backups if tools limited.
  • references/safety.md: Sanitization and confirmation patterns.

🤖 AI 评测

质量中等偏上。优点是文档清晰、流程完整、安全考虑周到、备份可靠。不足是功能较单一(仅支持文本文件、限定在特定目录)、依赖特定工具支持。日常使用足够,但复杂场景可能不够用。

📊 多维度评分

适应性4.3
规范性4.2
有效性4.3
可靠性4.2
可信度4.3

📁 包含文件 (4 个)

📄 SKILL.md 2.9 KB
📄 _meta.json 138 B
📄 references/safety.md 607 B
📄 scripts/backup_file.sh 436 B