Building a full Git panel inside an AI chat: a DeepSeek Harness plugin
Foreword: This is a record of a "first time." The first time writing a DeepSeek Harness (DSH) plugin, the first time exploring its plugin injection mechanism, and the first time moving a complete Git graphical panel into an AI conversation tool. If there are any misunderstandings, feel free to comment below.
1. Why build yet another wheel?
I've written VSCode plugins before, and I'm fairly familiar with the whole extension.ts + activate() + various Contribution Points approach. Recently I've been heavily using DSH, and one thing has become increasingly awkward: the Git code management interface doesn't suit my taste.
DSH currently takes up the most of my working hours, but there are still scenarios where I have to open VSCode to operate Git. I really like VSCode's current UI, but this means I have to open two applications in the same working directory and switch between them, which feels very disjointed.
So I first looked for existing plugins. There are some that work and are very well implemented, but none of them quite fit my preferences.
After thinking about it, rather than settling for a compromise, I decided to build my own, and also figure out how DSH plugins actually work. That led to @wagq/dsh-git: a plugin that adds a Git icon to the DSH conversation title bar, which opens a full source code management panel.
Here's the finished product:
2. How DSH plugins differ from VSCode plugins
Approaching with VSCode habits, I found the core difference: DSH plugins are split into two halves.
| VSCode plugin | DSH plugin | |
|---|---|---|
| Runtime | One Extension Host process | host side (Node.js) + client side (browser React), two codebases |
| UI entry | Contribution Points declare commands/views | slots.inject pushes components into reserved "slots" in the conversation UI |
| Backend | Node APIs run directly in Extension Host | host side registers HTTP routes, browser side calls via fetch |
This "dual-end" structure is the premise for everything:
- The host side runs in DSH's Node process, can access the file system, execute
gitcommands, and access session services. But it cannot directly manipulate the browser DOM. - The client side is React code injected into the browser, can render UI and respond to clicks, but cannot touch the file system.
- The two sides communicate via a local HTTP API. I registered
/wagq-git/api/*routes on the host side, and the client side calls them with fetch.
It's like writing a small front-end/back-end separated app, except the "backend" is a plugin module loaded by DSH, and the "frontend" is a component injected into the conversation UI.
3. Overall architecture: three layers
The plugin is assembled from three parts, corresponding to several key fields in package.json:
{
"main": "./dist/index.js", // host entry
"exports": {
".": "./dist/index.js", // host side
"./client": "./dist/client.js" // client side
},
"dsh": {
"bundle": { "patch": "./cordis.patch.yml" },
"client": {
"platform": "web",
"inject": [
"@deepseek-ai/dsh-client-ui-layout",
"@deepseek-ai/dsh-client-ui-conversation"
]
}
}
}
- Bundle patch layer:
cordis.patch.ymlinserts the host module into DSH's Cordis dependency injection container.
- insert:
- id: wagq-dsh-git
name: '@wagq/dsh-git'
A small pitfall here: name must be the package name, not a relative path. DSH resolves it via the profile's node_modules (or an installation fallback directory); using a local path causes loading to fail.
- Host side:
inject = ['webServer'], register a full set of routes after the web service is ready. - Client side:
inject = ['slots'], register a Git button in the session title bar's utilities slot.
4. Host side: wrapping Git into an HTTP API
4.1 Executing git: always use argument arrays, never concatenate shell strings
This is my first rule on the host side. All git operations go through execFile, with arguments as an array:
export function git(cwd: string, args: string[]): Promise<GitResult> {
return run('git', gitArgs(cwd, args), {
cwd,
windowsHide: true,
timeout: GIT_TIMEOUT_MS,
maxBuffer: MAX_BUFFER,
encoding: 'utf8',
env: {
...process.env,
GIT_TERMINAL_PROMPT: '0', // never pop password prompts in non-interactive environments
GIT_OPTIONAL_LOCKS: '0',
GIT_PAGER: 'cat', // disable pager, otherwise it hangs without a TTY
LC_ALL: 'C.UTF-8',
LANG: 'C.UTF-8',
},
})
}
function gitArgs(cwd: string, args: string[]): string[] {
// core.quotepath=false makes Chinese paths display normally, instead of octal escapes like \350\257...
return ['-C', cwd, '--no-pager', '-c', 'core.quotepath=false', ...args]
}
Why be so strict? Because filenames and branch names can contain spaces, quotes, or even &. Once concatenated into a shell string, these characters can change the command itself. Using an argument array ensures git receives exactly the arguments you intend.
The only exception is the terminal tab. There the user types commands directly, and needs pipes, redirection, and &&, so that route deliberately uses a shell. This is a design trade-off, not an oversight.
Also, I increased maxBuffer to 64MB. git log --all can easily output several MB in a large repository; the default value would blow up.
4.2 Commit graph: computing lane layout myself
The lane-based commit graph in the "Graph" tab is modeled after VSCode's Git Graph. The host side only emits flat commit nodes (including parents); the actual lane arrangement is computed on the client side. The algorithm uses the classic "first free lane" strategy. The key point is that lanes are not compressed. A branch line keeps its column across the entire window, and doesn't jump horizontally when another branch ends:
export function layoutGraph(commits: CommitNode[]): GraphRow[] {
const lanes: Array<{ sha: string | null; color: string }> = []
for (const commit of commits) {
// Prefer claiming a lane that is waiting for this commit, otherwise find the first empty one
let lane = lanes.findIndex((entry) => entry.sha === commit.sha)
const fromTop = lane !== -1
if (lane === -1) {
lane = lanes.findIndex((entry) => entry.sha === null)
if (lane === -1) { lane = lanes.length; lanes.push({ sha: null, color: laneColor(lane) }) }
lanes[lane].color = laneColor(lane)
}
// ... first parent inherits this lane, extra parents (merge) open new lanes
}
}
Each row's line segments (upper half, lower half, merge curves) are output explicitly, and the first row doesn't draw a line from nowhere above the node.
4.3 Security guardrails on the routing layer
All host routes are under the /wagq-git prefix and have two checks:
isLoopbackHost: only accepts localhost requests, guarding against DNS rebinding.isTrustedRequest: state-changing POST requests additionally checkOrigin/Sec-Fetch-Site, rejecting cross-site requests.
Path-based APIs (file browsing, reading file content) first run realpath and then verify "must still be within the repository root", preventing .. traversal from reading files outside the repo.
5. Client side: a React modal
5.1 Injecting the button
The client side is restrained: it registers a button in the title bar's utilities slot.
ctx.slots.inject('conversation.session.header.utilities', () =>
ctx.slots.register(
{ name: SLOT, id: 'wagq-dsh-git', order: 30,
inject: ((sessionId?: string) => ({ sessionId })) as ... },
(props) => GitHeaderButton({ sessionId: props?.sessionId }),
),
)
After getting sessionId, it calls /api/sessions to resolve the working directory for that session. So even if the slot doesn't provide cwd directly, the modal lands on the correct repository.
5.2 The modal's three tabs
- Changes: lists changes grouped, click a file to see diff, hover shows quick buttons for stage/unstage/discard,
Ctrl+Enterto commit, with optional amend. - Graph: commit graph + commit details, right-click to copy hash, revert, reset, rebase (destructive operations show confirmation first).
- Terminal: command line rooted at the repository directory, shows output, exit code, and elapsed time.
5.3 Side-by-side diff
The diff has both side-by-side and inline views, defaulting to side-by-side: left old, right new. This is the most core experience point I brought over from VSCode:
When parsing a patch, I split by hunk into lines, then pair +/- into left and right columns. Untracked files are invisible to git diff, so I use git diff --no-index to compare against an empty file and get hunks in the same shape. Patches over 600,000 characters are truncated and marked tooLarge, to avoid freezing the browser.
6. Highlight feature: using the current session's model to generate commit messages
This is my favorite feature. Below the commit box there's a ✦ Generate commit message button. Clicking it sends the current staged diff to the model used by this session, asks it to write a commit message, and auto-fills it in.
Why emphasize "the current session's model"? Because I want the generated message's style to stay consistent with the conversation. If you're discussing requirements in Chinese with a model, the commit message should also be in Chinese. There's a priority when resolving the model:
// 1. The session's current agent model
const agent = agents?.get?.(sessionId)
const route = agent?.model?.current?.()
// 2. Deployment default model
const fallback = ctx.get('agentDefaultModel')?.currentSelection?.()
// 3. If neither, throw a clear error
Only the diff is sent, with a patch limit of 12,000 characters; no full file content is ever transmitted. If the model has no API key configured or is rate-limited, the button shows a clear reason rather than leaving the user staring at an empty box.
Pitfall record: I initially put the system message inside the messages array, and the model refused to output text. After debugging, I found this adapter treats system as a top-level option, and putting it in messages gets silently dropped. Fixing it was simple:
const baseOptions = { messages, system: SYSTEM_PROMPT, maxTokens: MAX_TOKENS }
7. Build and debug
Uses esbuild for bundling, with several scripts in package.json:
{
"build": "node scripts/build.mjs",
"typecheck": "tsc -p tsconfig.json --noEmit && tsc -p tsconfig.client.json --noEmit",
"smoke": "node scripts/smoke.mjs",
"preview": "node scripts/preview.mjs"
}
During development, mount the local directory with link mode, run build after editing source, and refresh the page to see the effect:
dsh plugin --profile web add "link:D:/code/dsh plugin/dsh-wa-git"
Host and client have separate tsconfigs for type checking, because the Cordis contexts they can access are completely different. Instead of augmenting @deepseek-ai/cordis types, I defined local structural types (host-context.ts / client/context.ts), sufficient and clean.
8. Final words
From "disliking existing tools" to "building my own," the biggest gain isn't the panel itself, but thoroughly understanding DSH's plugin mechanism: dual-end + slot injection + local HTTP API. Looking back, it has a lot in common with VSCode plugins: both insert things into host extension points, but DSH splits front and back ends more thoroughly.
This plugin now covers the majority of my daily Git operations: viewing changes, writing commits (including AI-assisted ones), viewing commit graphs, managing branches and remotes, resolving conflicts, and running commands. It lets me write code in DSH without leaving the conversation window just to commit.
Top 1 from juejin.cn, machine-translated. The original thread is authoritative.
Splitting host and client into two halves is a sound approach; the plugin's structure becomes clear right away. And only sending the diff rather than the full text for commit messages is considerate.