Note: This skill requires access to ~/.openclaw/openclaw.json (to read agents.defaults.workspace) and the sessions_list tool (to get current session ID). It is NOT enabled by default (always: false). Users must explicitly enable it in their config.
Workspace Temp Skill
Purpose
Ensure all temporary/cached files go to <workspace>/temp/<session_id>/, never pollute the workspace root.
Required Permissions
This skill requires the following access:
| Resource | Purpose | Justification |
|---|
| INLINECODE5 | Read agents.defaults.workspace configuration | Required to determine the workspace path where temp/ directory will be created. Read-only access to single config file. |
| INLINECODE7 tool |
Get current session ID | Required to create isolated temp directories per session (prevents file conflicts between concurrent sessions). |
| External file system | Read user-specified files | Required when user asks to process files from outside the workspace. Files are only read and copied to temp directory. |
Note: The sessions_list tool and external file access are runtime capabilities documented here for transparency.
Security & Privacy
Skill Safety Guarantees
This skill operates under strict safety constraints:
- - No Code Execution: Does not execute arbitrary code, shell commands, or external programs
- Isolated Write Scope: All write operations restricted to
<workspace>/temp/<session_id>/ only - Read-Only External Access: External files are only read and copied, never modified in place
- Temporary Only: Files are designed to be deleted; no permanent storage outside workspace
User Privacy & Security Notes
⚠️ Sensitive Data: Files processed through this skill may temporarily contain sensitive data in the temp directory. Avoid processing files with passwords, keys, or secrets.
⚠️ Behavioral Guarantee: The promise not to modify pre-existing workspace files is a best-effort guarantee, not technical enforcement. The instruction guides the agent but cannot prevent all edge cases.
How It Works
- 1. Read
~/.openclaw/openclaw.json to get INLINECODE11 - Get current session unique ID via INLINECODE12
- Use
<workspace>/temp/<session_id>/ as the temp directory - Auto-create the directory if it doesn't exist
File Classification Rules
🔒 Original Files (Existing Before Skill Installation)
Definition: All files and directories in the workspace root at the time this skill is installed.
These files remain unchanged:
- - AGENTS.md, SOUL.md, USER.md, TOOLS.md
- MEMORY.md, HEARTBEAT.md, IDENTITY.md
- memory/ directory and its contents
- .git/ directory
- Any files existing before installation
Additional Note: Files manually added to the workspace root by the user after installation will also not be modified or deleted by this skill. However, users are encouraged to follow the principle: "Non-temporary files go in the root directory, temporary files go in temp/."
🗑️ Temporary Files (Must Go to temp/)
Definition: Files read from or downloaded from outside the workspace.
These files must go to temp/:
- - Files read from user-specified external locations
- Downloaded files
- Intermediate files during conversion/processing
Not Temporary Files:
- - Files generated by OpenClaw itself (e.g., session logs, internal caches)
- Files explicitly requested by the user to be saved to the workspace
Dynamic Temp Directory Resolution
CODEBLOCK0
Example:
- - If workspace is INLINECODE14
- If session ID is INLINECODE15
- Then temp dir is INLINECODE16
Procedures
Step 1: Get Temp Directory
Always determine temp dir dynamically:
CODEBLOCK1
Error Handling Principles:
- - If
temp/ or <session_id>/ directory cannot be created (e.g., insufficient permissions, disk full), a clear error message must be provided - Never fall back to writing files to the workspace root directory
- Operation terminates; retry after user resolves the issue
Step 2: Handle External Files
- 1. Copy files to INLINECODE19
- Read/process from temp
- Optionally clean up after processing
Step 3: Handle Downloads
- 1. Download directly to INLINECODE20
- Optionally clean up after processing
Step 4: Handle Generated Files
- 1. Write to INLINECODE21
- Delete after use
Examples
User says: "Read the report.txt from my desktop"
- - ❌ Wrong: Read desktop path directly
- ✅ Correct:
1. Read
~/.openclaw/openclaw.json to get workspace
2. Copy to
<workspace>/temp/<session_id>/report.txt
3. Read content from temp
User says: "Download this image"
- - ❌ Wrong: Download to workspace root
- ✅ Correct: Download to INLINECODE24
User says: "Convert this PDF"
- - ❌ Wrong: Generate intermediate files in root directory
- ✅ Correct: Generate in
<workspace>/temp/<session_id>/, clean up after conversion
Cleanup Policy
When the user explicitly requests cleanup assistance (e.g., "Check my temp directory", "Clean up temp files"), evaluate the following conditions and offer appropriate actions:
Cleanup Triggers & Actions
| Trigger | Condition | Action | User Options |
|---|
| Large Directory | Temp directory > 500MB | Alert: "Your temp directory is using X GB. Clean up?" | "Clean up" (delete) / "Keep" / "I'll do it myself" (provide path) |
| Old Files |
Files older than 7 days | Alert: "Found X files older than 7 days. Clean up?" | Same as above |
|
Session Residuals | Current session temp not empty | Alert: "This session created X temporary files. Keep or clean up?" | Same as above |
|
Status Check | User asks for temp status | Report: size, file count, oldest files, then offer cleanup | Same as above |
Cleanup Scope
- - Skill-Initiated: Intermediate files should be deleted immediately after use
- Session-End: Current session's
<session_id>/ directory should be cleaned when session ends - Manual: Users can clear any subdirectory under
temp/ at any time - Safety:
temp/ only contains temporary files; cleanup never affects original workspace files
Important: Do NOT proactively interrupt users with cleanup reminders. Only check and offer cleanup when explicitly requested.
Notes
- - Temp directory follows workspace configuration and adapts automatically
- If workspace changes, temp directory follows automatically
- Always use absolute paths to avoid ambiguity
- Never touch original files existing before installation
- This skill is NOT enabled by default - users must explicitly enable it in INLINECODE29
注意: 此技能需要访问 ~/.openclaw/openclaw.json(读取 agents.defaults.workspace)以及 sessions_list 工具(获取当前会话 ID)。默认情况下未启用(always: false)。用户必须在其配置中显式启用。
工作区临时文件技能
目的
确保所有临时/缓存文件都存放到 /temp// 目录下,绝不污染工作区根目录。
所需权限
此技能需要以下访问权限:
| 资源 | 用途 | 理由 |
|---|
| ~/.openclaw/openclaw.json | 读取 agents.defaults.workspace 配置 | 需要确定工作区路径,以便在其中创建 temp/ 目录。仅对单个配置文件进行只读访问。 |
| sessions_list 工具 |
获取当前会话 ID | 需要为每个会话创建隔离的临时目录(防止并发会话之间的文件冲突)。 |
| 外部文件系统 | 读取用户指定的文件 | 当用户要求处理工作区外部的文件时需要。文件仅被读取并复制到临时目录。 |
注意: sessions_list 工具和外部文件访问是运行时能力,此处列出仅为透明公开。
安全与隐私
技能安全保障
此技能在严格的安全约束下运行:
- - 不执行代码: 不执行任意代码、Shell 命令或外部程序
- 隔离写入范围: 所有写入操作仅限于 /temp//
- 只读外部访问: 外部文件仅被读取和复制,绝不原地修改
- 仅限临时: 文件设计为可删除;在工作区外无永久存储
用户隐私与安全说明
⚠️ 敏感数据: 通过此技能处理的文件可能临时包含敏感数据于临时目录中。避免处理包含密码、密钥或机密的文件。
⚠️ 行为保证: 不修改预先存在的工作区文件的承诺是尽力而为的保证,而非技术强制。指令引导代理,但无法防止所有边缘情况。
工作原理
- 1. 读取 ~/.openclaw/openclaw.json 获取 agents.defaults.workspace
- 通过 sessionslist 获取当前会话唯一 ID
- 使用 /temp/id>/ 作为临时目录
- 如果目录不存在则自动创建
文件分类规则
🔒 原始文件(技能安装前已存在)
定义: 技能安装时工作区根目录中的所有文件和目录。
这些文件保持不变:
- - AGENTS.md、SOUL.md、USER.md、TOOLS.md
- MEMORY.md、HEARTBEAT.md、IDENTITY.md
- memory/ 目录及其内容
- .git/ 目录
- 安装前已存在的任何文件
附加说明: 安装后用户手动添加到工作区根目录的文件也不会被此技能修改或删除。但鼓励用户遵循原则:非临时文件放在根目录,临时文件放在 temp/。
🗑️ 临时文件(必须放入 temp/)
定义: 从工作区外部读取或下载的文件。
这些文件必须放入 temp/:
- - 从用户指定的外部位置读取的文件
- 下载的文件
- 转换/处理过程中的中间文件
非临时文件:
- - OpenClaw 自身生成的文件(例如会话日志、内部缓存)
- 用户明确要求保存到工作区的文件
动态临时目录解析
- 1. 读取 ~/.openclaw/openclaw.json
- 提取 agents.defaults.workspace
- 通过 sessionslist 获取当前会话 ID
- 临时目录 = /temp/id>/
示例:
- - 如果工作区是 E:/OpenClaw/workspace
- 如果会话 ID 是 abc123
- 那么临时目录是 E:/OpenClaw/workspace/temp/abc123/
操作流程
步骤 1:获取临时目录
始终动态确定临时目录:
javascript
// 伪代码
const config = readFile(~/.openclaw/openclaw.json);
const workspace = config.agents.defaults.workspace;
// 通过 sessions_list 工具获取当前会话 ID
const sessions = sessions_list();
const currentSession = sessions.find(s => s.key.includes(main));
const sessionId = currentSession ? currentSession.sessionId : generateFallbackId();
const tempDir = path.join(workspace, temp, sessionId);
// 错误处理:确保目录创建成功
try {
ensureDirExists(tempDir);
} catch (error) {
throw new Error(创建临时目录失败:${tempDir}。原因:${error.message}。请检查权限或磁盘空间。);
}
错误处理原则:
- - 如果无法创建 temp/ 或 / 目录(例如权限不足、磁盘已满),必须提供清晰的错误信息
- 绝不回退到向工作区根目录写入文件
- 操作终止;待用户解决问题后重试
步骤 2:处理外部文件
- 1. 将文件复制到 /temp//
- 从临时目录读取/处理
- 处理完成后可选择清理
步骤 3:处理下载
- 1. 直接下载到 /temp//
- 处理完成后可选择清理
步骤 4:处理生成的文件
- 1. 写入 /temp//
- 使用后删除
示例
用户说:读取我桌面上的 report.txt
1. 读取 ~/.openclaw/openclaw.json 获取工作区
2. 复制到
/temp//report.txt
3. 从临时目录读取内容
用户说:下载这张图片
- - ❌ 错误:下载到工作区根目录
- ✅ 正确:下载到 /temp//image.jpg
用户说:转换这个 PDF
- - ❌ 错误:在根目录生成中间文件
- ✅ 正确:在 /temp// 中生成,转换后清理
清理策略
当用户明确请求清理帮助时(例如检查我的临时目录、清理临时文件),评估以下条件并提供适当操作:
清理触发条件与操作
| 触发条件 | 条件 | 操作 | 用户选项 |
|---|
| 目录过大 | 临时目录 > 500MB | 提醒:您的临时目录使用了 X GB。是否清理? | 清理(删除)/ 保留 / 我自己来(提供路径) |
| 文件过旧 |
文件超过 7 天 | 提醒:发现 X 个超过 7 天的文件。是否清理? | 同上 |
| 会话残留 | 当前会话临时目录非空 | 提醒:此会话创建了 X 个临时文件。保留还是清理? | 同上 |
| 状态检查 | 用户询问临时目录状态 | 报告:大小、文件数量、最旧文件,然后提供清理选项 | 同上 |
清理范围
- - 技能发起: 中间文件应在使用后立即删除
- 会话结束: 当前会话的 / 目录应在会话结束时清理
- 手动: 用户可以随时清除 temp/ 下的任何子目录
- 安全: temp/ 仅包含临时文件;清理绝不会影响原始工作区文件
重要: 不要主动用清理提醒打断用户。仅在用户明确请求时进行检查并提供清理。
注意事项
- - 临时目录遵循工作区配置并自动适应
- 如果工作区发生变化,临时目录会自动跟随
- 始终使用绝对路径以避免歧义
- 绝不触碰安装前已存在的原始文件
- 此技能默认未启用——用户必须在 ~/.openclaw/openclaw.json 中显式启用