File Browser Skill
Quick Start
Resolve all paths relative to WORKSPACE=/home/alfred/.openclaw/workspace. Sanitize inputs to prevent escapes or absolutes.
- - To list directory: exec("scripts/listfiles.sh", [relpath]) → JSON {success: bool, data: array of names, error: string}
- To read file: exec("scripts/readfile.sh", [relpath]) → JSON {success: bool, data: string (text content), error: string}
- Handle errors: For binary/large/non-text files, return error JSON.
Step-by-Step Workflow
- 1. Parse user query for action (list/read) and relative path.
- Call appropriate script with sanitized rel_path.
- Parse JSON output; respond to user with results or error message.
- If path invalid or outside workspace, reject immediately.
Safety Guidelines
- - Enforce read-only: No writes, deletes, or exec beyond scripts.
- Log accesses if verbose mode enabled.
- For large files (>10k chars), truncate or summarize.
Edge Cases
- - Empty path: Default to "." (workspace root).
- Binary file: Return error "Non-text file".
- See references/examples.md for more (if added).
Bundled Resources
- - scripts/listfiles.sh: Bash wrapper for ls.
- scripts/readfile.sh: Bash wrapper for cat with limits.
文件浏览器技能
快速开始
所有路径均相对于 WORKSPACE=/home/alfred/.openclaw/workspace 进行解析。对输入进行清理以防止路径逃逸或绝对路径。
- - 列出目录:exec(scripts/listfiles.sh, [relpath]) → JSON {success: bool, data: array of names, error: string}
- 读取文件:exec(scripts/readfile.sh, [relpath]) → JSON {success: bool, data: string (文本内容), error: string}
- 错误处理:对于二进制/大文件/非文本文件,返回错误JSON。
分步工作流程
- 1. 解析用户查询以获取操作(列出/读取)和相对路径。
- 使用清理后的rel_path调用相应脚本。
- 解析JSON输出;向用户返回结果或错误信息。
- 如果路径无效或超出工作区范围,立即拒绝。
安全指南
- - 强制只读:禁止写入、删除或执行脚本以外的操作。
- 如果启用详细模式,记录访问日志。
- 对于大文件(超过10k字符),进行截断或摘要处理。
边界情况
- - 空路径:默认为.(工作区根目录)。
- 二进制文件:返回错误非文本文件。
- 更多内容请参见 references/examples.md(如果已添加)。
捆绑资源
- - scripts/listfiles.sh:ls的Bash封装。
- scripts/readfile.sh:带限制的cat的Bash封装。