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 開發,希望測試文件和一次性產物不會留在項目裏,這個插件是一個實用的補充。

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

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

小夜