Local File Manager Skill
This skill provides safe file I/O operations within the session's cwd. It is designed for roles that need to store outputs locally (no cloud sync).
Capabilities
- - Read file: Get contents of a text file
- Write file: Create or overwrite a file
- Append file: Add content to existing file
- List files: Directory listing with filtering
- Delete file: Remove a file (with safety checks)
- Copy/Move: Simple file operations
When to Use
Role needs to:
- - Save generated code/analysis to disk
- Read input documents (PDFs, text, etc.)
- Append logs or results
- Create output files in Markdown/JSON/CSV
Usage
CODEBLOCK0
Safety
- - Sandboxed to cwd: Cannot access files outside session's working directory
- Protected files: Cannot delete files starting with
. or in INLINECODE2 - Size limit: Max file size 10MB (configurable)
- Dry-run support:
--dry-run shows what would happen
Integration with Roles
In role config, enable this skill:
CODEBLOCK1
Then in the role's system prompt, guide usage:
CODEBLOCK2
Examples
Researcher saving analysis:
CODEBLOCK3
Developer saving code:
CODEBLOCK4
Automation appending log:
CODEBLOCK5
Error Handling
- - If file doesn't exist for read: returns error code 1
- If path is outside cwd: denied
- If write fails (permission): returns error
- All errors logged to INLINECODE4
Configuration
Environment variables:
- -
FILE_MANAGER_MAX_SIZE: Max file size in bytes (default 10485760) - INLINECODE6 : Path to operation log (default
~/.openclaw/logs/file-manager.log) - INLINECODE8 : Set to "1" to only simulate operations
本地文件管理器技能
该技能提供在会话当前工作目录(cwd)内的安全文件I/O操作。专为需要将输出本地存储(无云同步)的角色设计。
功能
- - 读取文件:获取文本文件内容
- 写入文件:创建或覆盖文件
- 追加文件:向现有文件添加内容
- 列出文件:带过滤功能的目录列表
- 删除文件:移除文件(含安全检查)
- 复制/移动:简单的文件操作
使用场景
角色需要:
- - 将生成的代码/分析结果保存到磁盘
- 读取输入文档(PDF、文本等)
- 追加日志或结果
- 创建Markdown/JSON/CSV格式的输出文件
使用方法
bash
读取文件
file-manager --action read --path output.md
写入内容(从标准输入或--content参数)
file-manager --action write --path result.json --content {status:done}
追加到文件
file-manager --action append --path log.txt --content Job completed at $(date)
列出目录中的文件
file-manager --action list --dir . --pattern *.md
创建目录
file-manager --action mkdir --dir reports
删除文件(需确认)
file-manager --action delete --path old_file.txt
安全性
- - 沙箱限制在cwd内:无法访问会话工作目录外的文件
- 受保护文件:无法删除以.开头或位于../路径的文件
- 大小限制:最大文件大小10MB(可配置)
- 预演支持:--dry-run参数可预览操作结果
与角色集成
在角色配置中启用此技能:
yaml
plugins:
allow:
- local-file-manager
- doc-parser
然后在角色的系统提示中指导使用:
完成分析后,将结果写入文件:
file-manager --action write --path summary.md --content $YOUR_MARKDOWN
示例
研究人员保存分析结果:
bash
file-manager --action write --path analysis_$(date +%Y%m%d).md \
--content # 分析\n\n## 摘要\n...
开发者保存代码:
bash
file-manager --action write --path src/main.py --content $CODE
自动化追加日志:
bash
file-manager --action append --path /var/log/automation.log \
--content [$(date)] 任务完成\n
错误处理
- - 读取不存在的文件:返回错误代码1
- 路径超出cwd范围:拒绝访问
- 写入失败(权限问题):返回错误
- 所有错误记录到~/.openclaw/logs/file-manager.log
配置
环境变量:
- - FILEMANAGERMAXSIZE:最大文件大小(字节,默认10485760)
- FILEMANAGERLOG:操作日志路径(默认~/.openclaw/logs/file-manager.log)
- FILEMANAGERDRYRUN:设置为1仅模拟操作