@yangzhe1991/dsh-code-review 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +63 -0
- package/README.zh.md +63 -0
- package/cordis.patch.yml +6 -0
- package/lib/client.js +1416 -0
- package/lib/client.js.map +7 -0
- package/lib/index.js +7 -0
- package/lib/index.js.map +7 -0
- package/lib/types/client/index.d.ts +6 -0
- package/lib/types/index.d.ts +2 -0
- package/package.json +70 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Phil Yang (yangzhe1991)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# dsh-code-review
|
|
2
|
+
|
|
3
|
+
[English](README.md) | [中文](README.zh.md)
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@yangzhe1991/dsh-code-review)
|
|
6
|
+
[](https://www.npmjs.com/package/@yangzhe1991/dsh-code-review)
|
|
7
|
+
[](LICENSE)
|
|
8
|
+
[](https://github.com/topics/dsh-plugin)
|
|
9
|
+
|
|
10
|
+
**dsh-code-review** is a browser plugin for the [DSH (DeepSeek Harness)](https://github.com/deepseek-ai/deepseek-harness) web UI that turns **git diff output** in a conversation into a one-click **code review page in its own browser tab** — a two-column, human-friendly view (old file on the left, new file on the right, both with **line numbers**), free from the chat window's width/height limits.
|
|
11
|
+
|
|
12
|
+
The conversation itself stays untouched: when a git diff shows up, a small **"open in new tab"** button appears on the block (a markdown diff code block, or the bash tool row that produced the diff — even while collapsed). One click opens the review page.
|
|
13
|
+
|
|
14
|
+
## Features
|
|
15
|
+
|
|
16
|
+
- ⬅️➡️ **Two-column side-by-side view** — the old file on the left, the new file on the right, each with its own line numbers, exactly like a GitHub split review.
|
|
17
|
+
- 🟥🟩 **Add/remove coloring** — deleted lines get a red background, added lines green; a consecutive delete-then-add block is paired row-by-row into a single "changed" row (the GitHub alignment).
|
|
18
|
+
- 🔎 **Inline character-level highlight** — when only a few characters change on a line, exactly those characters get a stronger red/green background (common prefix/suffix trimmed).
|
|
19
|
+
- 💡 **Basic syntax highlighting** — keywords, strings, comments, and numbers are colored using the official shiki theme variables (language inferred from the file extension; unknown languages just skip syntax coloring).
|
|
20
|
+
- 🧷 **Hunk-aware** — every `@@` hunk header is kept as a separator row with its original section name; multiple files in one diff are split into per-file sections with a status badge (modified / new file / deleted / renamed / binary).
|
|
21
|
+
- 🗂️ **File navigation sidebar** — every file is listed on the left; click to jump.
|
|
22
|
+
- 📊 **Stats bar** — `+N −M · F files` in a sticky top bar, with a "copy raw diff" button and a collapsible raw-text section at the bottom.
|
|
23
|
+
- 🎨 **Theme-matched** — the page inherits the DSH theme colors at open time, so light/dark mode stays consistent.
|
|
24
|
+
- 📜 **Full-page scrolling** — no height caps; thousands of lines scroll naturally, and long lines wrap.
|
|
25
|
+
- 💬 **Inline comments** — hover any line number and click to add a comment right on that line (like GitHub reviews). Comments accumulate with a per-line count badge; when done, submit them all at once — as **Looks Good To Me ✓** or **plain comments** — and they are written into the DSH composer as `file:line — comment` lines, ready to send to the agent.
|
|
26
|
+
|
|
27
|
+
### Where the button appears
|
|
28
|
+
|
|
29
|
+
1. **Markdown code blocks** in assistant messages — a ```` ```diff ```` / ```` ```patch ```` fence, or any code block whose content looks like a git diff (e.g. pasted inside a `text` fence). The block is **collapsed by default** (just the title row + buttons), with an "expand/collapse" toggle if you want to read the raw text inline.
|
|
30
|
+
2. **Bash tool rows** — when the agent runs `git diff` in a bash tool, the button is added to the tool row (visible even while the row is collapsed; detected from the conversation data, since a collapsed row has no output in the DOM). The terminal card in the details panel gets one too.
|
|
31
|
+
|
|
32
|
+
Streaming output is handled gracefully: the button only appears once the content has been stable for ~1 second, so half-streamed diffs never produce a broken page.
|
|
33
|
+
|
|
34
|
+
## Install (30 seconds)
|
|
35
|
+
|
|
36
|
+
```sh
|
|
37
|
+
dsh plugin --profile web add @yangzhe1991/dsh-code-review
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Restart the Web GUI (`Ctrl+C` the `dsh web` process and run it again) and refresh the browser tab. (`dsh plugin` runs `pnpm add` and auto-appends the bundle to `dsh.profile.bundles`.)
|
|
41
|
+
|
|
42
|
+
For local development, install from a path instead — the `link:` spec keeps a live symlink so edits take effect after a rebuild + restart:
|
|
43
|
+
|
|
44
|
+
```sh
|
|
45
|
+
dsh plugin --profile web add link:/path/to/@yangzhe1991/dsh-code-review
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## How it works
|
|
49
|
+
|
|
50
|
+
The plugin registers a root-scope `shell.overlay` seat that renders nothing and watches the whole document with a `MutationObserver`. For every `.md-code-block` and `[data-terminal]` element it runs a stability-debounced check; candidates get a small button appended to the block's banner/header (never replacing official nodes, so React's reconciliation stays safe). Collapsed bash tool rows are handled from the data layer: a session-scope seat subscribes to the conversation snapshot and records settled bash results that look like a diff.
|
|
51
|
+
|
|
52
|
+
Clicking the button synchronously builds a self-contained HTML page (inline styles + inherited theme variables + the two-column content, all HTML-escaped) and opens it via a **Blob URL** — no server route needed, and the synchronous `window.open` inside the click gesture is not popup-blocked. The parser is a pure module (`src/client/diff-parse.ts`, unit-tested in `test/parse.test.mjs`) and supports: multi-file diffs, hunks with line-number tracking, delete/add pairing into changed rows (uneven counts degrade to single-side rows), `` markers, new/deleted/renamed/binary files, bare patches without a `diff --git` header, and commit-message prefixes (`git show` output).
|
|
53
|
+
|
|
54
|
+
## Development
|
|
55
|
+
|
|
56
|
+
```sh
|
|
57
|
+
npm install
|
|
58
|
+
npm run build # esbuild → lib/index.js (host half) + lib/client.js (browser half)
|
|
59
|
+
node test/parse.test.mjs # parser + standalone HTML unit tests
|
|
60
|
+
node test/client-smoke.test.mjs # bundle smoke test (mock __ModuleLoader__)
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Browser-side changes only need a rebuild; the host serves `lib/` live, so a hard refresh (⌘+Shift+R) picks them up. Profile-level changes (package name/bundles) require restarting `dsh web`.
|
package/README.zh.md
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# dsh-code-review
|
|
2
|
+
|
|
3
|
+
[English](README.md) | [中文](README.zh.md)
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@yangzhe1991/dsh-code-review)
|
|
6
|
+
[](https://www.npmjs.com/package/@yangzhe1991/dsh-code-review)
|
|
7
|
+
[](LICENSE)
|
|
8
|
+
[](https://github.com/topics/dsh-plugin)
|
|
9
|
+
|
|
10
|
+
**dsh-code-review** 是 [DSH (DeepSeek Harness)](https://github.com/deepseek-ai/deepseek-harness) Web UI 的浏览器插件:把对话里的 **git diff 输出**变成一键打开的**独立标签页 Code Review 页面** —— 双列、对人类友好的视图(左侧旧文件、右侧新文件,两侧都带**行号**),完全不受聊天窗口宽度/高度限制。
|
|
11
|
+
|
|
12
|
+
聊天窗口本身保持原样:只要出现 git diff,对应块(markdown diff 代码块、或产生 diff 的 bash 工具行——折叠状态也显示)上就自动出现一个**「在新标签页打开」**小按钮,点一下即打开审查页。
|
|
13
|
+
|
|
14
|
+
## 功能
|
|
15
|
+
|
|
16
|
+
- ⬅️➡️ **双列并排视图** —— 旧文件在左、新文件在右,两侧各自带行号,类似 GitHub 的 split review。
|
|
17
|
+
- 🟥🟩 **增删配色** —— 删除行红底、新增行绿底;连续「删除块 + 新增块」逐行配对成同一行的「变更」(GitHub 对齐方式)。
|
|
18
|
+
- 🔎 **行内字符级高亮** —— 同一行只改几个字符时,精确高亮那几个字符(更深一档的红/绿背景,公共前后缀剥离)。
|
|
19
|
+
- 💡 **基础语法高亮** —— 关键字、字符串、注释、数字着色,颜色复用官方 shiki 主题变量(按文件扩展名推断语言,未知语言自动跳过)。
|
|
20
|
+
- 🧷 **hunk 感知** —— 每个 `@@` hunk 头保留为分隔行(含 section 名);一个 diff 里的多个文件拆成独立文件段,带状态徽章(修改 / 新增文件 / 删除文件 / 重命名 / 二进制)。
|
|
21
|
+
- 🗂️ **文件导航侧栏** —— 左侧列出所有文件,点击跳转。
|
|
22
|
+
- 📊 **统计条** —— 顶部吸顶显示 `+N −M · F 个文件`,带「复制原始 diff」按钮,页面底部有可折叠的原始文本区。
|
|
23
|
+
- 🎨 **主题一致** —— 打开时继承 DSH 当前主题色,深浅色模式自动跟随。
|
|
24
|
+
- 📜 **整页滚动** —— 无高度限制,几千行自然滚动,超长行折行显示。
|
|
25
|
+
- 💬 **行内评论** —— 悬停任意行号点击即可在该行提评论(类似 GitHub review),行号旁显示评论数徽章;攒齐后一次性提交 —— 可选 **Looks Good To Me ✓** 或**纯评论**,提交后自动写入 DSH 对话框(`文件名:行号 — 评论` 逐条列出),直接发给 agent。
|
|
26
|
+
|
|
27
|
+
### 按钮出现的位置
|
|
28
|
+
|
|
29
|
+
1. **assistant 消息里的 markdown 代码块** —— ```` ```diff ```` / ```` ```patch ```` 语言标签,或内容形似 git diff 的任意代码块(比如贴在 `text` 围栏里)。代码块**默认折叠**(只留标题行 + 按钮),带「展开/收起」开关,想看原始文本就内联展开。
|
|
30
|
+
2. **bash 工具行** —— agent 在 bash 工具里跑 `git diff` 后,按钮加在工具行上(折叠状态也可见;折叠行 DOM 里没有输出内容,从会话数据层检测)。详情面板里的终端卡片同样支持。
|
|
31
|
+
|
|
32
|
+
流式输出有专门处理:内容稳定约 1 秒后按钮才出现,半截 diff 不会产生残缺页面。
|
|
33
|
+
|
|
34
|
+
## 安装(30 秒)
|
|
35
|
+
|
|
36
|
+
```sh
|
|
37
|
+
dsh plugin --profile web add @yangzhe1991/dsh-code-review
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
重启 Web GUI(`Ctrl+C` 停掉 `dsh web` 再重新运行)并刷新浏览器标签页。(`dsh plugin` 会执行 `pnpm add` 并自动把 bundle 追加进 `dsh.profile.bundles`。)
|
|
41
|
+
|
|
42
|
+
本地开发用路径安装 —— `link:` 规范保持实时软链,改完代码重新构建 + 重启即可生效:
|
|
43
|
+
|
|
44
|
+
```sh
|
|
45
|
+
dsh plugin --profile web add link:/path/to/@yangzhe1991/dsh-code-review
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## 工作原理
|
|
49
|
+
|
|
50
|
+
插件注册一个 root 作用域的 `shell.overlay` 席位,自身渲染 null,用 `MutationObserver` 监听全文档。对每个 `.md-code-block` 和 `[data-terminal]` 元素做「稳定去抖」检测,候选块会在官方 banner/header 上追加一个小按钮(只追加、不改写官方节点,React 协调安全)。折叠的 bash 工具行走数据层:session 作用域组件订阅会话快照,把输出形似 diff 的已落地 bash 结果记录进文本表,扫描器给对应工具行加按钮。
|
|
51
|
+
|
|
52
|
+
点击按钮时,**在用户手势内同步**构建自包含 HTML 页面(内联样式 + 继承的主题变量 + 双列内容,全部 HTML 转义),通过 **Blob URL** 打开 —— 不依赖服务器任何路由,同步调用的 `window.open` 也不会被弹窗拦截。解析器是纯模块(`src/client/diff-parse.ts`,`test/parse.test.mjs` 有单测),支持:多文件 diff、带行号跟踪的 hunk、删除/新增配对成变更行(数量不等时多出的行退化为单侧行)、`` 标记、新增/删除/重命名/二进制文件、无 `diff --git` 头的裸 patch、`git show` 的提交说明前缀。
|
|
53
|
+
|
|
54
|
+
## 开发
|
|
55
|
+
|
|
56
|
+
```sh
|
|
57
|
+
npm install
|
|
58
|
+
npm run build # esbuild → lib/index.js(node 半)+ lib/client.js(浏览器半)
|
|
59
|
+
node test/parse.test.mjs # 解析器 + 独立页 HTML 单测
|
|
60
|
+
node test/client-smoke.test.mjs # bundle 冒烟测试(mock __ModuleLoader__)
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
浏览器侧改动只需重新构建;宿主实时读 `lib/`,硬刷新(⌘+Shift+R)即可生效。profile 级改动(包名/bundles)需要重启 `dsh web`。
|