π¦ ClawHub
File Writer
by @nagilem
Safely write or append text content to files ONLY in /home/alfred/.openclaw/workspace/scratch. Creates backups before overwriting ({filename}.bak, .bak.1, et...
TERMINAL
clawhub install scratch-file-writerπ About This Skill
name: file-writer description: Safely write or append text content to files ONLY in /home/alfred/.openclaw/workspace/scratch. Creates backups before overwriting ({filename}.bak, .bak.1, etc.). Creates subdirectories if needed. Triggers on queries like "update the script with the new feature" (infers update), "write that information to a file in your scratch area" (prompts for details), "write [content] to [rel_path]", "append [content] to [rel_path]". Restrict to relative paths; reject absolutes, ../ escapes, binary content, or non-text extensions. NOT for executing code, deleting, or writing outside scratch.
File Writer Skill
Quick Start
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 runmkdir -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.