dsh-git-ops
Verifieddsh-git-ops · v2.1.1 · MIT · Web UI
Structured git tools for your dsh agent: status, diff, log, and commit that run in the host process, not inside a sandbox whose environment strips HOME.
Install
dsh plugin add dsh-git-ops Confirm the layer applied with dsh --profile default --dump-config — see the install guide.
Source
Published to npm without a public repository. Inspect the package contents before installing.
Tags
Readme
dsh-git-ops
Structured git tools for the dsh agent: git_status / git_diff / git_log / git_commit.
为什么需要它
dsh 官方 90+ 工具里没有任何 git 集成——模型操作 git 只能裸敲 bash/pwsh,丢失结构化输出、审批粒度与状态面板。更糟的是 docs/DSH-SESSION-AUDIT-FINDINGS.md 记录的 D-3:dsh 的 run_code 沙箱按设计剥离 HOME/USERPROFILE,模型在会话里跑 git commit 直接 fatal(真实翻车案例 t8/s14、t27/s2)。
本插件在宿主进程里直接调 git,不经过沙箱,D-3 不适用;参数走 argv 数组,无 shell 注入面;双输出流各限 512 KiB,git log 狂奔也吃不掉模型上下文。
工具
| 工具 | 读/写 | 做什么 |
|---|---|---|
git_status |
读 | 分支 + 每文件暂存/工作区状态(porcelain v1 结构化解析) |
git_diff |
读 | 未暂存/已暂存 patch,-U 可调,64 KiB 截断保护 |
git_log |
读 | 最近 N 条提交(hash/作者/日期/主题),1-50 |
git_commit |
写 | 暂存指定路径 + 提交;无暂存内容时拒绝并说明原因;缺身份时原样转达 git 的提示 |
git_branch |
读写 | list/create/switch/delete;delete 走安全 -d(未合并分支 git 自动拒绝) |
git_stash |
读写 | list/push/pop,暂存恢复前始终可找回 |
git_show |
读 | 单提交的 stat + 完整 patch |
git_push |
写 | 配置门禁:默认不注册;allowPush: true 才出现 |
只读工具 isConcurrencySafe: true,git_commit 串行。
安装
本机环境是 Desktop(Electron,19387 端口)。推荐应用内「插件」页添加(无需退出应用); CLI 装载需要先完整退出 Desktop:
dsh plugin --profile desktop add dsh-git
# 本地 path 安装(开发时):
dsh plugin --profile desktop add E:\VSCodeSpace\Agent\DeepSeek\dsh-plugins\packages\dsh-git
# 装载核验:
dsh --profile desktop --dump-config | Select-String "dsh-git"
设计决定
inject = []:不声明任何必需服务。工具经ctx.inject(['tools'])挂载——没有工具注册表的宿主(CLI、headless)只是没有 git 工具,插件本体照常运行。工作目录经ctx.get('workingDirectory')机会式读取,缺失时退回会话头cwd。理由见PLUGIN-CONTRACT.md§4.1。- 不做浏览器半边:v1 是纯工具插件(对照官方
tool-session-query的形态),无面板、无 client 产物,CLI 与 Desktop 通用。 - 提交身份:直接依赖宿主环境的 git 配置(宿主进程不受沙箱环境剥离影响)。缺身份时把 git 自己的报错原样转给模型,附可操作的修复路径。
面板
Desktop/Web 的 Settings 里有「Git」页(浏览器半边,settings.section 槽位):显示最近会话所在仓库的分支、改动文件、最近 5 条提交,数据每次请求现算,中英文跟随界面语言。
配置(2.0)
<dsh-home>/plugin-data/dsh-git-ops/config.json:
{ "identity": { "name": "...", "email": "..." }, "allowPush": false }
identity:git_commit 以-c user.name/email传参,优先于全局 git 配置allowPush:git_push工具的注册门禁,默认关闭。宿主进程跑 git 不经沙箱审批层, 推送这类不可逆外联操作必须由宿主操作者显式打开
测试
pnpm test # 9 项:真实 ToolRuntime + 真实临时 git 仓库 + 面板路由,全程走 ctx.tools.execute