dsh-green-loop:讓編碼智能體在檢查通過前持續修復

前言

在 DeepSeek Harness(DSH)裏用編碼智能體改代碼時,常見情況是:模型認爲自己做完了,但本地測試、lint 或類型檢查仍失敗。人工再跑一遍命令、把報錯貼回去,既打斷節奏,也依賴人工複覈。dsh-green-loop 把工作流裏「回合結束 → 跑項目檢查 → 失敗則把輸出送回同一回合繼續修」做成可配置的循環,用命令退出碼做決定,而不是再讓模型審模型。

這是什麼

dsh-green-loop(npm 包名同名,當前版本 0.1.0)由 Algovate 維護,MIT 許可證,歸類爲工作流類 DSH 插件。一句話:在智能體每一輪停頓(turn-stopping)時自動執行你配置的測試 / lint / typecheck;失敗則 steer 同一回合並附上失敗輸出,直到檢查變綠、嘗試次數用盡、連續相同失敗被判定爲無進展,或你手動停止。

與手動質量門(如用戶執行 /gate)、網絡錯誤自動 continue 不同,Green Loop 的觸發是「已武裝且回合結束」,決策依據是你命令的退出碼,動作爲把失敗輸出 steer 給智能體。

核心功能

回合結束檢查與失敗轉向

武裝(Arm)後,每次智能體準備結束回合時,插件通過 ctx.shell 執行解析出的檢查命令(與 bash 工具同一執行邊界與沙箱)。非零退出、超時或基礎設施錯誤視爲失敗;插件生成有界的失敗報告並調用 agent.steer(...),同一回合繼續而不是直接收工。檢查通過則解除武裝,Composer 側 dock 顯示爲綠色。

Composer dock 與斜槓命令

安裝後會通過 dsh.client 掛上 Composer dock(Green Loop):

  • Arm:檢測檢查命令並武裝循環。
  • Run now:不武裝也可立即跑一次檢查。
  • Details:顯示命令、工作目錄、嘗試次數與最近輸出。

不依賴 dock 時,命令平面同樣可用:

/green status    show armed/running/attempts and the resolved command
/green start     arm; the check runs when the next turn stops
/green run       run the check now; failures are steered immediately
/green stop      disarm and abort a running check

檢查命令解析

若配置裏 command 非空,則優先生效;否則插件僅讀取工作區元數據 不執行任何命令 做自動檢測,例如:

項目信號 命令
package.json scripts.test + pnpm-lock.yaml pnpm test
package.json scripts.test + yarn.lock yarn test
package.json scripts.test + Bun lockfile bun run test
package.json scripts.test npm test
pyproject.toml / pytest.ini / tox.ini / tests/ pytest -q(有 lockfile 時可能帶 uv run / poetry run)
go.mod go test ./...
Cargo.toml cargo test
Makefile 含 test: make test

monorepo 或非標準佈局應在配置裏顯式寫 command。檢測到的命令會在執行前顯示在 dock 中。

停止條件

  • PASS:解除武裝,dock 變綠。
  • FAIL:steer 後繼續;下一輪停頓時再跑檢查。
  • No progress:stopOnRepeat 爲 true 時,兩次完全相同的失敗輸出會按 stalled 停止。
  • Attempt budget:單輪武裝週期內達到 maxAttempts 次檢查後解除武裝(紅色狀態)。

暴露給模型的工具

工具 作用
green_check 運行配置/檢測到的檢查,返回通過與否與輸出尾部;可在聲稱任務完成前探測。只讀,不會武裝或 steer。
green_status 報告 armed/running/attempts、解析出的命令與上次結果。

武裝與解除武裝僅由用戶決定(dock 或 /green),智能體沒有 arm 工具。

安裝與啓用

要求 DSH 0.2.2-rc.0 或更新、且仍在 0.2.x 線(package.json 中 engines.dsh 爲 >=0.2.2-0 <0.3.0)。Node 需 >=22.19。

官方安裝命令:

dsh plugin --profile <profile> add dsh-green-loop@0.1.0

也可在 Settings → Plugins 從本地 checkout 或發佈 tarball 安裝:

dsh plugin --profile <profile> add ./dsh-green-loop-0.1.0.tgz

包聲明瞭 dsh.bundle.patch,profile 會把它寫入 dsh.profile.bundles,patch 會插入 Host 行;客戶端 dock 經 dsh.client 掛載。

DSH 生態是「一切皆插件」;社區目錄 skillhub.cn 爲獨立站點,與 DeepSeek / 幻方無官方從屬關係。

典型用法

  1. 按上文命令爲指定 profile 安裝插件,打開編碼會話。
  2. 在 Composer 中查看 Green Loop dock,確認檢測到的檢查命令是否符合預期;不符合則在 profile 的 cordis.patch.yml 或 Settings → Plugins 表單中覆蓋配置。
  3. 點擊 Arm,讓智能體完成一輪修改;回合結束時自動跑檢查。
  4. 若失敗,同一回合會收到失敗輸出並繼續修;通過則循環自動解除。
  5. 隨時在 dock 停止,或執行 /green stop。

配置示例(字段均經 Schemastery 校驗,可在 profile 中覆蓋):

- id: green-loop
  name: dsh-green-loop
  config:
    command: ''             # explicit check; empty = detect from the project root
    timeoutMs: 180000       # one check, including preparation
    maxAttempts: 3          # checks in one armed cycle
    stopOnRepeat: true      # identical failure twice = no progress -> stop
    outputTailChars: 4000   # output kept for steering and the dock
    cwd: ''                 # override; relative resolves from the session cwd
    detect: true            # allow auto-detection when command is empty

適用場景與注意

適合:你希望本地 npm test、pytest、go test ./... 等成爲編碼智能體的硬門檻,且願意在失敗時多消耗模型步數換確定性驗證。

權限與安全:檢查與智能體共用 ctx.shell,以當前 DSH 進程的沙箱、工作目錄與環境執行;武裝後每回合結束會自動跑你信任的檢查命令——安裝前請閱讀 GitHub 倉庫 源碼與 SECURITY.md,只在你信任項目腳本的環境使用。默認 opt-in:未武裝且未顯式 /green run 或 green_check 時不會跑檢查。輸出僅保留 outputTailChars 用於 steer 與 dock;重啓後循環狀態不持久化。

成本:每次失敗會多走一步模型;maxAttempts 與重複失敗停止規則用於限制開銷。

維護者在 DSH 0.2.2-rc.3 Desktop 上做過 live 驗證(含 green_check 與武裝後 turn-stopping 跑 make test);刻意失敗的真實項目上的完整 steer 路徑 README 稱主要由 engine 測試覆蓋,詳見倉庫 docs/verification.md。

結尾

dsh-green-loop 把「檢查變綠才收工」編成可武裝的回合循環:退出碼驅動、失敗輸出 steer、Composer dock 與 /green 命令並存。目錄頁:https://www.skillhub.cn/plugins/Algovate/dsh-green-loop;源碼與文檔:https://github.com/Algovate/dsh-green-loop。

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

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

小夜