dsh-workspace-tmp:为 DeepSeek Harness 提供工作区外的临时目录

前言

在用 DeepSeek Harness(DSH)写测试时,最容易忽略的“污染”往往不是改错了一行源码,而是留下了一堆一次性文件:test.tmp.ts、scratch.py、跑一次就忘的 fixture、抓下来的日志、生成到一半的数据。这些文件进了 git status,进了 code review,最后又没人敢删。如果放在工作区里,即使用了 .gitignore,本质上还是改了项目文件;如果放在别处,又难以让 Agent 知道“这是临时区,该用哪个工具”。

dsh-workspace-tmp 是为 DSH 提供工作区外临时目录的插件。它给 Agent 一个与工作区并列的临时目录,并注入一条常驻系统提示和一套工具,让 Agent 可以创建、写入、列举和清理该目录,同时默认在每轮结束后自动删除。

这是什么

dsh-workspace-tmp 是 DeepSeek Harness 的一个工作流插件,由维护者 xxiiiixx 开发。它为 Agent 提供一个位于工作区之外的临时目录,并通过系统提示告诉模型“这是临时区,什么该放进去、什么时候被删”。临时目录默认在每轮结束时自动清理,防止测试文件污染项目树。

核心功能

临时目录的位置

临时目录是工作区的“并列兄弟”,不是子目录。目录结构如下:

C:\Users\me\Desktop\插件\            ← 工作区(项目)
C:\Users\me\Desktop\tmp\插件-3f2a1c1\  ← 临时区
└── probe.test.ts
└── fixtures\…
└── .dsh-workspace-tmp.json           ← 归属标记

规则是 <工作区父目录>/<siblingDir>/<工作区名>-<会话短id>/。这样:

  • 永远不在项目里。即使工作区本身不是 Git 仓库,临时区也不会进入 git status。
  • 不需要 .gitignore。临时区不在仓库目录树内,插件不碰任何项目文件。
  • 多会话互不冲突。会话短 id 让并行会话各用各的目录;同名工作区在不同父目录下互不覆盖。
  • 删除安全。只有带 .dsh-workspace-tmp.json 归属标记的目录才会被删除;即使工作区本身叫 tmp,也不会误删。

清理时机

默认在每轮结束时删除,并顺带清理空掉的父目录。清理行为由 autoClean 控制:

autoClean 行为
"turn"(默认) 每轮结束即删。agent/turn-stopping 负责正常收尾,session/event 的 turn/end 兜底出错与中断的轮次
"session" 会话结束(agent/disposed)时删;同一轮的多个步骤之间还能复用同一个文件
"off" 不自动删;模型可用 action: "clean" 手动清,或由你决定何时处理

清理失败只会发出警告,不会把错误抛进轮次;删除是幂等的,目录本来就不存在时什么也不做。

系统提示与工具

插件向 Agent 注入一条系统提示段落(每轮稳定,不破坏 KV 缓存),告诉模型临时目录的位置、用途和清理规则。同时注册 workspace_tmp 工具,支持以下操作:

  • action: "create" — 建目录并预留路径
  • action: "write" — 写文件(自动建父目录)
  • action: "list" — 列举相对路径和字节数(最多 200 条)
  • action: "clean" — 立刻删除

系统提示示例:

## Scratch files stay out of the project tree

This session's temporary directory is `C:\Users\me\Desktop\tmp\插件-3f2a1c1`. It is a sibling of
the workspace, not a child, so it is never part of the project and never shows up in version control.

Use it for anything that only exists to try something out: test files you write to check behaviour,
fixtures and sample inputs, generated data, captured logs, benchmark probes, throwaway scripts,
build or conversion by-products.

- Write those files under the temporary directory. Do not create `test.tmp.ts`, `scratch.py`,
  sample output, or one-off fixtures next to project sources.
- `workspace_tmp` manages it: `action: "create"` … `action: "write"` … `action: "list"` … `action: "clean"`.
- The native write tools are fenced to the workspace by the file sandbox, so they may refuse a
  path outside it. `workspace_tmp` with `action: "write"` is the supported way to create a scratch
  file there; the native `read`/`bash` tools can still read and run it.
- It is deleted automatically when this turn ends, so nothing is left behind.
- If a scratch file must outlive the turn, say so to the user and ask where it belongs; do not
  move it into the project to keep it.
- Real project changes still go through the normal read/write/edit tools on the real files.
  Never copy a project file into the temporary directory to "edit" it there.

配置

插件提供两个可配置项,每个键都可省略。非法值会在加载时直接报错。

- id: workspace-tmp
  name: 'dsh-workspace-tmp'
  config:
    # 与工作区并列的目录名,默认 tmp
    siblingDir: tmp
    # turn(默认)| session | off
    autoClean: turn
键 默认 含义
siblingDir "tmp" 并列目录名;只接受单个目录名,含分隔符或为空会报错
autoClean "turn" 清理时机;也接受 true(=turn)、false(=off)

安装与启用

插件本体安装在 profile 的 node_modules 里,工作区里的源码仅用于维护。

从 GitHub 安装:

dsh plugin --profile desktop add github:xxiiiixx/dsh-workspace-tmp

从本地源码安装:

dsh plugin --profile desktop add "C:\path\to\dsh-workspace-tmp"

或在 设置 → 插件 → 添加 中选择该目录。

安装完成后按提示重启 Harness(提示 restart-required 时必须重启)。workspace-tmp 行由 cordis.patch.yml 自动插入,无需手工修改 profile。

维护工作区里的源码:

工作区里的 dsh-workspace-tmp/ 是维护副本,与已安装的副本相互独立:修改源码不会影响正在运行的插件,必须重新安装才生效。

dsh plugin --profile desktop remove dsh-workspace-tmp
dsh plugin --profile desktop add "C:\path\to\dsh-workspace-tmp"

典型用法

Agent 可以使用 workspace_tmp 工具在临时目录里创建测试文件、fixture 或其他一次性产物,而不会把文件留在项目目录中。示例调用:

{ "action": "create", "name": "cases" }                              // 建目录
{ "action": "write", "name": "cases/a.test.ts", "content": "…" }     // 写文件
{ "action": "list" }                                                // 查看内容
{ "action": "clean" }                                               // 清理

适用场景与注意

适合需要频繁创建测试文件、fixture、临时脚本、日志或生成数据的 Agent 场景。使用时需注意:

  • 临时区在工作区外,这意味着在 workspace-write 沙箱下的原生命令行工具看不到它;如需在沙箱内访问,需使用 workspace_tmp 的 list/write,或使用 danger-full-access。
  • 插件以当前 DSH 进程权限运行,安装前建议检查源码与许可证。
  • 插件以准则加工具的形式存在,不会拦截 Agent 的 write/edit 操作;如果需要硬拦截,需要通过 tools/pre-execute 等其他机制实现。

结尾

dsh-workspace-tmp 通过将临时文件放在工作区之外,并配合系统提示与自动清理,让 Agent 在测试时可以放心使用临时目录,而不用担心污染项目树。如果你正在用 DSH 做 Agent 开发,希望测试文件和一次性产物不会留在项目里,这个插件是一个实用的补充。

羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

Xiaoye