Skip to content
dsh.fish
Bundle

dsh-code-collector

Code collector for DeepSeek Harness: a composer-side panel that gathers every code block the model produced in the current session, with by-language / by-file views, version history, live search, one-click copy, download-all, and click-to-jump back to the exact turn.

Source
bycall
License
MIT
Updated
Updated 2 hours ago

Readme

# dsh-code-collector

DeepSeek Harness(dsh)会话代码收集器插件:把当前会话里**模型产出的全部代码块**汇总到一个面板——按语言或按文件分组、同一文件的多次迭代合并为**版本历史**、实时搜索过滤、一键复制/全部复制/下载合并 Markdown,点击任意条目**直接跳转到产出该代码的回合**。

> 背景:dsh 长会话(尤其让 AI 改代码的场景)会散落大量代码块,想回头找某段代码、对比某个文件的修改版本,只能手动翻聊天记录。本插件把"会话内所有代码"变成可检索、可分组、可复制的资源清单。

## 功能

| 能力 | 说明 |
| --- | --- |
| **收集按钮** | 输入框右侧(`conversation.input.right` 插槽)常驻按钮,实时显示当前会话代码块总数徽标;**Alt+Shift+C** 快捷开关面板(避开生态内 Ctrl+Alt+C 占用)。 |
| **双视图** | **按语言**(色点 + 语言名 + 条数/总行数)与**按文件**(同名文件聚合,AI 迭代修改同一文件时自动形成**版本历史**,显示最新版,可展开查看/复制/跳转任意历史版本);视图偏好按浏览器记忆(localStorage)。 |
| **实时搜索** | 面板内搜索框,按**文件名 / 语言 / 代码内容**实时过滤,大小写不敏感;无匹配时明确提示。 |
| **代码提取** | 遍历会话快照全部 assistant 节点:显式 `code` 块(language/filename 多字段防御)+ text 块内 ```fence``` 代码段,均被收集;语言名自动归一化(Python/TypeScript/Shell…)。 |
| **批量操作** | 单条复制、复制全部(带文件名头注释)、下载全部为单个 Markdown(`session-code.md`,按 `---` 分隔)。 |
| **点击跳转** | 点击条目/版本 → 平滑滚动到该回合第一条消息并高亮(复用 `data-chat-anchor-key` 语义锚点机制)。 |
| **i18n** | 中英双语词典(跟随 dsh 语言环境)。 |

## 安装

```bash
# npm 源(推荐,市场内一键安装体验一致)
dsh plugin --profile web add dsh-code-collector

# 或本地目录源
dsh plugin --profile web add file:/Users/bycall/Documents/GitHub/dsh-code-collector
```

然后在 `~/.dsh/profiles/web/package.json` 的 `dsh.profile.bundles` 数组中加入 `"dsh-code-collector"`,重启 DSH.app(或硬刷新浏览器窗口)生效。

## 卸载

```bash
dsh plugin --profile web remove dsh-code-collector
```

## 工作原理

- **插槽注册**(客户端):通过 `ctx.slots` 注册会话级插槽 `conversation.input.right`(id `code-collector-btn`)。
- **数据来源**:插槽组件拿到会话快照,读取 `snapshot.chat.order` / `snapshot.chat.nodes`(assistant 节点的 `data.blocks`:`code` 块直接取 `language/filename/code`;`text` 块用围栏正则 ```` ```lang\n…\n``` ```` 提取代码段;`location.turn.turn` 定位所属回合)。
- **文件版本历史**:同名文件的代码块按回合升序排列,最新版默认展示,展开后可见全部历史版本(回合号 + 行数 + 最新标记),任意版本可复制或跳转。
- **搜索**:文件名 / 语言标签 / 代码内容三路包含匹配。
- **跳转机制**:每条消息行 DOM 带 `data-chat-anchor-key="<Context key>"`,跳转 = 找到该行 → `scrollIntoView` + 高亮。

## 目录结构

```
dsh-code-collector/
├── package.json          # dsh.bundle.patch + dsh.client + exports["./client"]
├── cordis.patch.yml      # bundle 挂载声明
├── lib/
│   ├── index.js          # 服务端挂载入口(UI-only,空实现)
│   └── client.js         # 全部功能(client bundle,单文件自包含)
├── test/
│   └── smoke.cjs         # 冒烟测试(factory/slot/提取/分组/搜索断言)
├── release/
│   └── dshmarket-submission.yml
├── README.md
└── LICENSE               # MIT
```

## 验证

```bash
npm run verify            # node --check(client/index)+ 冒烟测试
# 等价于:node test/smoke.cjs   # ALL CHECKS PASSED
npm pack --dry-run         # 检查发布到 npm 的文件清单
```

CI 在每次 push / PR 时于 Node 18/20/22 上自动跑 `npm run verify`。

## License

MIT

Install

dsh plugin --profile web add github:bycall/dsh-code-collector#1a0d032a724ba19bbdd8dc82de026f706ed46d6d

Profile: web

Source