dsh-worktree-branch
开发工具 活跃维护

dsh-worktree-branch

Qcsj777/dsh-worktree-branch

在新建会话界面集成工作树与分支切换功能,采用类似 Codex 的交互方式,Git 操作全部在插件宿主侧执行,可快速列出、切换及创建 worktree 与分支,无需手动输入命令,切换流程更顺畅。

0
Stars 标星
0
Forks 分支
0
Watchers 关注
0
Open Issues
JavaScript
主要语言
MIT
开源协议
15 KB
仓库大小
1 个月前
最后推送
一键安装扩展 / 插件指令
dsh plugin --profile web add github:Qcsj777/dsh-worktree-branch
git clone https://github.com/Qcsj777/dsh-worktree-branch.git
git clone git@github.com:Qcsj777/dsh-worktree-branch.git
README.md main

dsh-worktree-branch

Codex-style Location / Branch switchers on the New Session screen of
DeepSeek Harness, for workspaces that are
git repositories.

在 DSH「新建会话」页给 git 工作区加一块 Codex 风格的「工作位置 / 分支」chip:
直接切 worktree、切分支、新建分支,git 事实与副作用全部由 Host 半执行
(写操作走该会话的沙箱策略)。

What it does

  • Detects whether the session's working directory is inside a git repository;
    renders nothing when it is not.
  • Shows the current branch (or the short hash when HEAD is detached), every
    local branch, and every linked worktree.
  • Actions: create a worktree, switch to another worktree, switch branch,
    create-and-switch branch.
  • Names are validated twice: a cheap local whitelist plus git check-ref-format.
  • Every git call strips inherited GIT_* selectors (GIT_DIR, GIT_WORK_TREE,
    GIT_INDEX_FILE, …) so a user shell cannot redirect the command to another
    repository; write operations (switch, switch -c, worktree add) are
    wrapped in the session's sandbox policy.

Install

From GitHub:

dsh plugin --profile desktop add github:Qcsj777/dsh-worktree-branch

As a local link during development:

// ~/.dsh/profiles/<profile>/package.json
"dependencies": {
  "dsh-worktree-branch": "link:D:/path/to/worktree-branch"
}

The package ships its own Cordis patch (cordis.patch.yml) that inserts the
host half with id worktree-branch. git must be on PATH.

How it works

Third-party bundles cannot add Remote namespaces, and a installed bundle's
client half cannot call its own host half through host.call, so the two halves
talk over same-origin HTTP:

GET  /worktree-branch/state?session=<id>&cwd=<path>
POST /worktree-branch/action  { sessionId, cwd, action, name?, path? }

action is one of create-worktree, use-worktree, switch-branch,
create-branch. The state payload is
{ repo, cwd, repoRoot, currentBranch, head, branches[], worktrees[], mainPath, atMain }.

  • Client half (client.js): registers the chip on
    conversation.hero.options, only on the New Session screen.
  • Host half (index.js): injects webServer, subprocess, sandbox,
    sandboxPolicy, worktrees, sessionController, sessions,
    workingDirectory; owns the routes above.

Non-goals

  • No network operations (no fetch/pull/push), no deletes, no merge/rebase.
  • Switching to another worktree changes that session's working directory —
    that is the feature, not a side effect. The switch itself does not move any
    files.

Development

node check.mjs   # self-check for git-parse.mjs

License

MIT