dsh-green-loop: Letting Coding Agents Keep Fixing Until Checks Pass

前言

在 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。

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

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

Xiaoye