@wwwfz/dsh-agent-bridge 0.0.0-stage → 0.8.3
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/README.md +194 -3
- package/cordis.patch.yml +4 -0
- package/package.json +40 -6
- package/src/assets.js +348 -0
- package/src/catalog.js +605 -0
- package/src/client.js +310 -0
- package/src/config.js +88 -0
- package/src/export.js +12 -0
- package/src/index.js +136 -0
- package/src/project-archive.js +145 -0
- package/src/projects.js +980 -0
- package/src/session-import.js +93 -0
- package/src/watch.js +309 -0
- package/web/Geist-OFL.txt +93 -0
- package/web/agent-icons/NOTICE.md +19 -0
- package/web/agent-icons/antigravity.svg +76 -0
- package/web/agent-icons/claude.svg +3 -0
- package/web/agent-icons/codex.png +0 -0
- package/web/agent-icons/copilot.svg +1 -0
- package/web/agent-icons/dsh.svg +58 -0
- package/web/agent-icons/gemini.png +0 -0
- package/web/agent-icons/licenses/copilot.txt +21 -0
- package/web/agent-icons/licenses/dsh.txt +21 -0
- package/web/agent-icons/licenses/gemini.txt +202 -0
- package/web/agent-icons/licenses/opencode.txt +21 -0
- package/web/agent-icons/licenses/qoder-notice.txt +18 -0
- package/web/agent-icons/licenses/qoder.txt +22 -0
- package/web/agent-icons/licenses/qwen.txt +203 -0
- package/web/agent-icons/opencode.png +0 -0
- package/web/agent-icons/qoder.svg +4 -0
- package/web/agent-icons/qwen.svg +5 -0
- package/web/agent-icons/trae.png +0 -0
- package/web/agent-icons/workbuddy.svg +29 -0
- package/web/geist-latin-wght-normal.woff2 +0 -0
- package/web/panel.css +502 -0
- package/web/panel.html +246 -0
- package/web/panel.js +1559 -0
- package/web/project-context.js +25 -0
package/README.md
CHANGED
|
@@ -1,3 +1,194 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
# Agent Bridge
|
|
4
|
+
|
|
5
|
+
**浏览本机其他 Agent 的项目、记忆和 Skills,在原工作目录继续开发。**
|
|
6
|
+
|
|
7
|
+
[](https://github.com/wfz2006/dsh-agent-bridge/tree/v0.8.2)
|
|
8
|
+
[](https://awesome-dsh-plugin.com/)
|
|
9
|
+
[](https://www.npmjs.com/package/@wwwfz/dsh-agent-bridge)
|
|
10
|
+
[](#卸载与构建)
|
|
11
|
+
|
|
12
|
+
[npm 安装](https://www.npmjs.com/package/@wwwfz/dsh-agent-bridge) · [最新公开安装包](https://github.com/wfz2006/dsh-agent-bridge/releases/latest/download/dsh-agent-bridge.tgz) · [v0.8.2 更新](#v082-更新) · [快速开始](#快速开始) · [界面](#界面) · [支持来源](#支持来源) · [介绍页](https://wfz2006.github.io/dsh-agent-bridge/)
|
|
13
|
+
|
|
14
|
+
<a href="https://wfz2006.github.io/dsh-agent-bridge/"><img src="docs/screenshots/v0.8.2/01-recent-conversations.png" width="920" alt="Agent Bridge:项目列表与继续旧对话"></a>
|
|
15
|
+
|
|
16
|
+
</div>
|
|
17
|
+
|
|
18
|
+
## 功能
|
|
19
|
+
|
|
20
|
+
| 查找项目 | 选择上下文 | 原地接续 |
|
|
21
|
+
| :--- | :--- | :--- |
|
|
22
|
+
| 按 Agent、项目名、路径和状态筛选;置顶常用项目,归档不再使用的项目。 | 勾选项目记忆、Skills 和近期会话,先预览再交接。 | 在原工作目录创建 DSH 会话,并填入可编辑的交接草稿。 |
|
|
23
|
+
|
|
24
|
+
| 导出交接 | 多 Agent 来源 | 本机只读 |
|
|
25
|
+
| :--- | :--- | :--- |
|
|
26
|
+
| 导出 Markdown 交接,或导出 DSH 会话记录。 | Codex、Claude Code、Copilot、OpenCode、Qoder、WorkBuddy、Gemini CLI、Qwen Code、Antigravity、TRAE。 | 通过本机已认证的 DSH Host 读取,源文件与 Agent 数据库只读访问。 |
|
|
27
|
+
|
|
28
|
+
## v0.8.2 更新
|
|
29
|
+
|
|
30
|
+
- **继续旧对话放到首屏**:直接显示最近几条来源对话,预览用户与助手的文字后再迁入一条新的 DSH 原生会话。
|
|
31
|
+
- **项目资料按用途分组**:上次做到哪、项目约定、会话中提到的 Skills 和其他笔记分开显示;全局资料默认折叠且不自动勾选,每个项目的选择会独立保留。
|
|
32
|
+
- **真实数据更可靠**:自动发现 Codex `.jsonl.zst` 会话及索引中仍指向旧路径的压缩记录,大型历史按流式方式读取;运行环境包装信息不会覆盖同一消息里的真实提问。
|
|
33
|
+
- **权限和失败恢复更明确**:面板仅接受本机 DSH 所有者身份。草稿初始化失败时会归档空白会话并复用同一会话重试;已有草稿保持原样,可打开原会话手动恢复。
|
|
34
|
+
|
|
35
|
+
## 界面
|
|
36
|
+
|
|
37
|
+
| 继续旧对话 | 用项目资料开新对话 |
|
|
38
|
+
| :---: | :---: |
|
|
39
|
+
| <img src="docs/screenshots/v0.8.2/02-conversation-preview.png" width="440" alt="继续旧对话预览"> | <img src="docs/screenshots/v0.8.2/03-project-materials.png" width="440" alt="项目资料分组"> |
|
|
40
|
+
| 选一条最近对话,核对消息后迁入并继续。 | 资料按进度、项目约定和 Skills 分组,全局资料库默认折叠。 |
|
|
41
|
+
|
|
42
|
+
| 交接草稿预览 | 黑色主题 |
|
|
43
|
+
| :---: | :---: |
|
|
44
|
+
| <img src="docs/screenshots/v0.8.2/04-draft-preview.png" width="440" alt="交接草稿预览"> | <img src="docs/screenshots/v0.8.2/06-black-theme.png" width="440" alt="黑色主题"> |
|
|
45
|
+
| 核对记忆、Skills 和来源,打开新对话或导出 Markdown。 | 蓝、白、黑三套主题,选择会记住。 |
|
|
46
|
+
|
|
47
|
+
<details>
|
|
48
|
+
<summary>更多界面:项目归档、全局资料库和 Agent 图标</summary>
|
|
49
|
+
|
|
50
|
+
| 项目归档 | 全局资料库 |
|
|
51
|
+
| --- | --- |
|
|
52
|
+
|  |  |
|
|
53
|
+
|
|
54
|
+
[Agent 图标](docs/screenshots/v0.5.1/01-agent-icons.png)
|
|
55
|
+
|
|
56
|
+
</details>
|
|
57
|
+
|
|
58
|
+
## 快速开始
|
|
59
|
+
|
|
60
|
+
**方式一:npm(推荐)**
|
|
61
|
+
|
|
62
|
+
```sh
|
|
63
|
+
dsh plugin --profile web add @wwwfz/dsh-agent-bridge
|
|
64
|
+
dsh web
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
**方式二:离线安装包**
|
|
68
|
+
|
|
69
|
+
1. 下载 [最新公开安装包](https://github.com/wfz2006/dsh-agent-bridge/releases/latest/download/dsh-agent-bridge.tgz),或从 [v0.8.2 源码](https://github.com/wfz2006/dsh-agent-bridge/tree/v0.8.2) 运行 `npm pack` 构建。
|
|
70
|
+
2. 打开 **DSH Desktop → 插件 → 安装插件**,选择这个文件。
|
|
71
|
+
3. **完全退出 DSH 后再打开**,侧栏会出现 **Agent 工作接续**。
|
|
72
|
+
|
|
73
|
+
<details>
|
|
74
|
+
<summary>DSH Web 离线安装</summary>
|
|
75
|
+
|
|
76
|
+
在安装包所在目录运行:
|
|
77
|
+
|
|
78
|
+
```sh
|
|
79
|
+
dsh plugin --profile web add ./dsh-agent-bridge.tgz
|
|
80
|
+
dsh web
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
</details>
|
|
84
|
+
|
|
85
|
+
发行包只依赖 DSH 的运行时。v0.8.2 在 Windows 的官方 DSH Desktop 0.2.2-rc.3 验收;原生会话入口依赖对应的 DSH 客户端服务。macOS 和 Linux 的数据路径规则有测试覆盖,桌面运行时的实机验收以 Windows 为准。[DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness)
|
|
86
|
+
|
|
87
|
+
## 使用
|
|
88
|
+
|
|
89
|
+
1. 打开 **Agent 工作接续**,按项目名、路径、Agent 或目录状态筛选。按 `/` 定位搜索框;不同 Git worktree 会独立显示。
|
|
90
|
+
2. 要接着聊,直接在 **继续旧对话** 里选一条最近对话,或用 **查看全部对话** 搜索。核对消息后点 **迁入并继续**。
|
|
91
|
+
3. 要从现有资料开始一段新对话,展开 **用项目资料开新对话**。按进度、项目约定和 Skills 等用途挑选资料。**全局资料库** 默认折叠,也不会自动勾选;展开 **接续清单** 可核对选中内容或加入近期对话摘录。点 **预览草稿** 后可以打开新对话或导出。
|
|
92
|
+
|
|
93
|
+
> 当前项目离开筛选结果时,右侧会提示重新选择。搜索后按 `↓` 聚焦第一项,按 `Enter` 打开第一项。每个项目的资料勾选和近期会话选项会单独保存,切换项目或重启 DSH 后仍可继续。
|
|
94
|
+
|
|
95
|
+
项目详情右上角可置顶常用项目。成功在 DSH 打开交接草稿或迁入原会话的项目会进入「最近接续」,最多显示五个符合当前筛选的非置顶项目。
|
|
96
|
+
|
|
97
|
+
右上角可切换蓝色、白色或黑色主题,插件会记住选择。Agent 筛选菜单支持方向键、回车和按字母查找;已适配的 Agent 名称旁显示随包提供的官方图标([图标来源](web/agent-icons/NOTICE.md))。
|
|
98
|
+
|
|
99
|
+
面板打开时会自动监听 Agent 索引、会话和当前项目资料的文件变化,并在后台定时复扫。正在查看或导出资料时,列表会在关闭预览后更新;**刷新来源** 可立即复扫。
|
|
100
|
+
|
|
101
|
+
### 继续旧对话
|
|
102
|
+
|
|
103
|
+
在提供原生会话存储服务的 DSH 中打开一个项目,首屏会显示最近三条可供预览的来源对话。点击其中一条即可查看用户和助手的消息。选择 **迁入并继续** 后,DSH 会在原目录创建一条包含这些历史消息的新会话,输入下一句即可继续。
|
|
104
|
+
|
|
105
|
+
迁入保留可读取的文字、顺序和消息角色。工具调用与结果、附件、隐藏推理和运行状态仍由原 Agent 保存。Codex 的 `.jsonl.zst` 会话、索引中尚未更新的压缩路径和大型历史都会参与发现;大型历史采用流式读取,按文字预算保留近期问答并在预览中标记截取。此功能在 Windows DSH Desktop 0.2.2-rc.3 验证。
|
|
106
|
+
|
|
107
|
+
DSH 未能填入交接草稿时,尚未使用的空白会话会自动归档,重试会复用同一会话;如果会话已有草稿,插件不会覆盖它,可以直接打开原会话并手动补入交接资料。
|
|
108
|
+
|
|
109
|
+
### 整理项目
|
|
110
|
+
|
|
111
|
+
项目详情右上角可归档单个项目。批量整理时,先按 Agent、项目名或「离线」缩小范围,再点「整理」,勾选项目或全选当前结果,点「归档所选」。归档项目移入「已归档」,可查看资料、恢复项目,或撤销刚才的操作。
|
|
112
|
+
|
|
113
|
+
归档状态保存在 `agent-bridge.json` 所在目录的 `agent-bridge-archive.sqlite`,实时扫描和重启后仍保留。原工作目录、记忆、Skills 和会话记录继续留在各自的来源中。
|
|
114
|
+
|
|
115
|
+
### 读取方式
|
|
116
|
+
|
|
117
|
+
项目原有的 `.agents/skills` 和 `.dsh/skills` 由 DSH 原生发现。其他 Agent 的 Skill 以 `SKILL.md` 正文摘录和原路径带入,DSH 可在需要时读取同目录资源;导入预览会标记截取内容。插件通过本机已认证的 DSH Host 读取资料,面板、静态资源和 API 都要求 DSH 所有者身份;源文件与 Agent 数据库按只读方式访问。发送之后,当前会话所选的模型会收到草稿。
|
|
118
|
+
|
|
119
|
+
## 导出交接
|
|
120
|
+
|
|
121
|
+
- **导出 Markdown**:在 **用项目资料开新对话** 中勾选资料,打开 **预览草稿 → 导出 Markdown**。文件包含已选记忆、Skill 说明、来源和已选会话摘录。
|
|
122
|
+
- **导出 DSH 会话**:用面板右上方的 **导出 DSH 会话** 选择本机 DSH 会话。文件包含原工作目录和最近的用户与助手消息;较长的会话会标记截取。
|
|
123
|
+
|
|
124
|
+
把下载的 Markdown 放进接收项目的 `.agent-bridge/handoffs/`,刷新后即可从「上次做到哪」中选用。原工作目录不可访问时,仍可导出尚可读取的归档资料。
|
|
125
|
+
|
|
126
|
+
## 支持来源
|
|
127
|
+
|
|
128
|
+
| 来源 | 可读内容 |
|
|
129
|
+
| --- | --- |
|
|
130
|
+
| Codex、Claude Code、OpenCode、Qoder、WorkBuddy、Gemini CLI、Qwen Code | 可识别的本地工作目录和会话,以及会话中有记录的 Skill 使用 |
|
|
131
|
+
| Antigravity | 本地工作区信息和可关联的 CLI 提示记录 |
|
|
132
|
+
| VS Code 系列中的 Copilot | 可识别的工作区和工作区会话 |
|
|
133
|
+
| TRAE | 本地工作区元数据,以及可选 AgentsView 归档中的会话 |
|
|
134
|
+
| 记忆与 Skills | 项目内共享笔记与交接、相关 Agent 的可读 Markdown、共享和手动配置的 Skill 目录 |
|
|
135
|
+
| Agent Workspace Manager / AgentsView | 可选来源。读取 WorkspaceHub 项目档案与共享 Markdown、已有会话归档 |
|
|
136
|
+
|
|
137
|
+
插件会从当前用户的标准数据目录查找来源,也会识别 `CODEX_HOME`、`CLAUDE_CONFIG_DIR`、`XDG_DATA_HOME`、`XDG_CONFIG_HOME`、`OPENCODE_DB` 和 `OPENCODE_CONFIG_DIR`。用 **本机来源** 查看发现情况。加密、服务端或未知格式的记忆可先导出为 Markdown。[Codex 配置实现](https://github.com/openai/codex/blob/main/codex-rs/core/src/config/mod.rs) · [Claude Code 配置](https://code.claude.com/docs/en/settings) · [OpenCode 数据存放位置](https://opencode.ai/docs/cli/providers/#storage)
|
|
138
|
+
|
|
139
|
+
## 在项目里存放共享记忆
|
|
140
|
+
|
|
141
|
+
在已发现的项目目录下放入 Markdown,刷新后即可查看并导入。
|
|
142
|
+
|
|
143
|
+
```text
|
|
144
|
+
my-project/
|
|
145
|
+
.agent-bridge/
|
|
146
|
+
memory/
|
|
147
|
+
current-state.md
|
|
148
|
+
handoffs/
|
|
149
|
+
latest-handoff.md
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
`current-state.md` 可记录当前目标、分支状态与待办。`latest-handoff.md` 可记录已完成事项、验证结果和下一步。两个目录的第一层 Markdown 会显示在项目的「记忆」页。也可把这两份文件与项目一起交给其他开发者。
|
|
153
|
+
|
|
154
|
+
## 自定义来源
|
|
155
|
+
|
|
156
|
+
<details>
|
|
157
|
+
<summary>配置 agent-bridge.json</summary>
|
|
158
|
+
|
|
159
|
+
通常安装后即可扫描。需要指定自定义数据位置时,在 DSH 主目录创建 `agent-bridge.json`。Windows 默认目录为 `%USERPROFILE%\.dsh`,macOS 和 Linux 默认为 `~/.dsh`。自定义主目录由 `DSH_HOME` 决定,也可通过 `DSH_AGENT_BRIDGE_CONFIG` 指定配置文件的完整路径。点击 **刷新来源** 重读配置。
|
|
160
|
+
|
|
161
|
+
```json
|
|
162
|
+
{
|
|
163
|
+
"projectRoots": ["~/projects/example"],
|
|
164
|
+
"agentRoots": {
|
|
165
|
+
"opencode": ["~/agent-data/opencode"],
|
|
166
|
+
"claude": ["~/agent-data/claude"]
|
|
167
|
+
},
|
|
168
|
+
"skillRoots": ["~/shared/skills"],
|
|
169
|
+
"opencodeSkillRoots": ["~/agent-config/opencode"],
|
|
170
|
+
"memoryExports": {
|
|
171
|
+
"~/projects/example": ["~/exports/example/current-state.md"]
|
|
172
|
+
},
|
|
173
|
+
"workspaceHubRoots": ["~/workspace-manager-data/workspacehub"],
|
|
174
|
+
"archiveFiles": ["~/workspace-manager-data/sessions.db"]
|
|
175
|
+
}
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
只需填写你使用的项。相对路径从配置文件所在目录计算,`~` 指当前用户目录。配置里的 `agentRoots` 替换对应 Agent 的自动路径,填写空数组可跳过该 Agent。OpenCode 路径可以是数据目录或会话数据库文件。记忆导出接受 Markdown 文件或包含 Markdown 的目录,并与指定项目的原工作目录匹配。自定义 AgentsView 数据目录也可通过 `AGENTSVIEW_DATA_DIR` 传入。
|
|
179
|
+
|
|
180
|
+
</details>
|
|
181
|
+
|
|
182
|
+
## 卸载与构建
|
|
183
|
+
|
|
184
|
+
Desktop 在插件管理页卸载 **dsh-agent-bridge**;Web 版运行:
|
|
185
|
+
|
|
186
|
+
```sh
|
|
187
|
+
dsh plugin --profile web remove dsh-agent-bridge
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
从源码运行 `npm test` 和 `npm pack`。项目没有第三方 npm 依赖,安装包包含插件代码、界面和本说明。
|
|
191
|
+
|
|
192
|
+
<div align="center">
|
|
193
|
+
<sub>为 <a href="https://github.com/deepseek-ai/deepseek-harness">DeepSeek Harness</a> 制作 · <a href="https://wfz2006.github.io/dsh-agent-bridge/">介绍页</a> · <a href="https://github.com/wfz2006/dsh-agent-bridge/issues">问题反馈</a></sub>
|
|
194
|
+
</div>
|
package/cordis.patch.yml
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,40 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@wwwfz/dsh-agent-bridge",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@wwwfz/dsh-agent-bridge",
|
|
3
|
+
"version": "0.8.3",
|
|
4
|
+
"description": "Standalone DeepSeek Harness plugin for live local agent discovery, context import, and Markdown handoff export.",
|
|
5
|
+
"keywords": ["dsh", "dsh-plugin", "deepseek-harness", "agent", "handoff", "skills"],
|
|
6
|
+
"repository": { "type": "git", "url": "git+https://github.com/wfz2006/dsh-agent-bridge.git" },
|
|
7
|
+
"homepage": "https://wfz2006.github.io/dsh-agent-bridge/",
|
|
8
|
+
"bugs": { "url": "https://github.com/wfz2006/dsh-agent-bridge/issues" },
|
|
9
|
+
"publishConfig": { "access": "public" },
|
|
10
|
+
"type": "module",
|
|
11
|
+
"main": "./src/index.js",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": "./src/index.js",
|
|
14
|
+
"./client": "./src/client.js",
|
|
15
|
+
"./cordis.patch.yml": "./cordis.patch.yml",
|
|
16
|
+
"./package.json": "./package.json"
|
|
17
|
+
},
|
|
18
|
+
"files": ["src", "web", "cordis.patch.yml", "README.md"],
|
|
19
|
+
"engines": { "node": ">=22.13" },
|
|
20
|
+
"scripts": {
|
|
21
|
+
"test": "node --disable-warning=ExperimentalWarning --test",
|
|
22
|
+
"pack:local": "npm pack --pack-destination ."
|
|
23
|
+
},
|
|
24
|
+
"dsh": {
|
|
25
|
+
"bundle": { "patch": "./cordis.patch.yml" },
|
|
26
|
+
"client": {
|
|
27
|
+
"platform": "web",
|
|
28
|
+
"inject": [
|
|
29
|
+
"@deepseek-ai/dsh-client-locale",
|
|
30
|
+
"@deepseek-ai/dsh-client-ui-renderer",
|
|
31
|
+
"@deepseek-ai/dsh-client-ui-layout",
|
|
32
|
+
"@deepseek-ai/dsh-client-ui-sidebar",
|
|
33
|
+
"@deepseek-ai/dsh-client-ui-workspace",
|
|
34
|
+
"@deepseek-ai/dsh-client-ui-conversation",
|
|
35
|
+
"@deepseek-ai/dsh-api-session-controller",
|
|
36
|
+
"@deepseek-ai/dsh-api-workspace-controller"
|
|
37
|
+
]
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
package/src/assets.js
ADDED
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
import { constants } from 'node:fs';
|
|
2
|
+
import { lstat, open, readdir, realpath } from 'node:fs/promises';
|
|
3
|
+
import { homedir } from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
|
|
6
|
+
const MAX_ASSET_BYTES = 96 * 1024;
|
|
7
|
+
const MAX_ASSETS_PER_ROOT = 320;
|
|
8
|
+
const proof = Symbol('asset location');
|
|
9
|
+
const sensitiveName = /(?:^|[._ -])(?:api[-_ ]?keys?|access[-_ ]?tokens?|auth|credentials?|passwords?|secrets?|oauth)(?:[._ -]|$)/i;
|
|
10
|
+
const hubFolders = ['决策', '经验', '资料', '交接', '笔记'];
|
|
11
|
+
const agentHomes = {
|
|
12
|
+
antigravity: ['.gemini/antigravity', '.gemini/antigravity-cli'],
|
|
13
|
+
claude: ['.claude'],
|
|
14
|
+
codex: ['.codex'],
|
|
15
|
+
dsh: ['.dsh'],
|
|
16
|
+
gemini: ['.gemini'],
|
|
17
|
+
opencode: ['.local/share/opencode'],
|
|
18
|
+
qoder: ['.qoder-cn', '.qoder'],
|
|
19
|
+
qwen: ['.qwen'],
|
|
20
|
+
reasonix: ['.reasonix'],
|
|
21
|
+
trae: ['.trae-cn', '.trae'],
|
|
22
|
+
workbuddy: ['.workbuddy'],
|
|
23
|
+
};
|
|
24
|
+
const projectAgentFolders = {
|
|
25
|
+
'.agent': 'antigravity',
|
|
26
|
+
'.claude': 'claude',
|
|
27
|
+
'.codex': 'codex',
|
|
28
|
+
'.dsh': 'dsh',
|
|
29
|
+
'.gemini': 'gemini',
|
|
30
|
+
'.opencode': 'opencode',
|
|
31
|
+
'.qoder': 'qoder',
|
|
32
|
+
'.qwen': 'qwen',
|
|
33
|
+
'.trae': 'trae',
|
|
34
|
+
'.workbuddy': 'workbuddy',
|
|
35
|
+
};
|
|
36
|
+
const projectInstructions = {
|
|
37
|
+
'AGENTS.md': 'shared',
|
|
38
|
+
'CLAUDE.md': 'claude',
|
|
39
|
+
'GEMINI.md': 'gemini',
|
|
40
|
+
'QWEN.md': 'qwen',
|
|
41
|
+
'MEMORY.md': 'shared',
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
function canonicalKey(file) {
|
|
45
|
+
const normalized = path.normalize(file);
|
|
46
|
+
return process.platform === 'win32' ? normalized.toLowerCase() : normalized;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function inside(root, file) {
|
|
50
|
+
const relative = path.relative(canonicalKey(root), canonicalKey(file));
|
|
51
|
+
return relative !== '..' && !relative.startsWith(`..${path.sep}`) && !path.isAbsolute(relative);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function sameFile(first, second) {
|
|
55
|
+
return first.dev === second.dev && first.ino === second.ino;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async function directory(file) {
|
|
59
|
+
if (typeof file !== 'string' || !path.isAbsolute(file) || file === path.parse(file).root) return null;
|
|
60
|
+
try {
|
|
61
|
+
const resolved = await realpath(file);
|
|
62
|
+
return (await lstat(resolved)).isDirectory() ? resolved : null;
|
|
63
|
+
} catch {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async function children(root, child = '.') {
|
|
69
|
+
try {
|
|
70
|
+
const target = await realpath(path.join(root, child));
|
|
71
|
+
if (!inside(root, target)) return [];
|
|
72
|
+
const entries = await readdir(target, { withFileTypes: true });
|
|
73
|
+
return entries.sort((a, b) => a.name.localeCompare(b.name)).slice(0, MAX_ASSETS_PER_ROOT);
|
|
74
|
+
} catch {
|
|
75
|
+
return [];
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async function located(file, root) {
|
|
80
|
+
const resolved = await realpath(file);
|
|
81
|
+
if (!inside(root, resolved) || canonicalKey(file) !== canonicalKey(resolved)) {
|
|
82
|
+
throw new Error('Asset path changed or is outside its source root');
|
|
83
|
+
}
|
|
84
|
+
const info = await lstat(file, { bigint: true });
|
|
85
|
+
if (!info.isFile() || info.nlink > 1n) throw new Error('Asset is not a regular, unlinked file');
|
|
86
|
+
return info;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
async function recordAsset(root, file, meta) {
|
|
90
|
+
try {
|
|
91
|
+
const info = await located(file, root);
|
|
92
|
+
const revision = `${info.ino}:${info.mtimeNs}:${info.size}`;
|
|
93
|
+
return { ...meta, file, revision, [proof]: { root, file, info } };
|
|
94
|
+
} catch {
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export async function readAsset(item) {
|
|
100
|
+
const source = item?.[proof];
|
|
101
|
+
if (!source || source.file !== item.file) throw new Error('Asset source is unavailable');
|
|
102
|
+
const current = await located(source.file, source.root);
|
|
103
|
+
if (!sameFile(source.info, current)) throw new Error('Asset changed since discovery');
|
|
104
|
+
const handle = await open(source.file, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0));
|
|
105
|
+
try {
|
|
106
|
+
const opened = await handle.stat({ bigint: true });
|
|
107
|
+
const confirmed = await located(source.file, source.root);
|
|
108
|
+
if (!sameFile(current, opened) || !sameFile(opened, confirmed)) throw new Error('Asset changed while opening');
|
|
109
|
+
const bytes = Buffer.alloc(MAX_ASSET_BYTES + 1);
|
|
110
|
+
let length = 0;
|
|
111
|
+
while (length < bytes.length) {
|
|
112
|
+
const { bytesRead } = await handle.read(bytes, length, bytes.length - length, length);
|
|
113
|
+
if (bytesRead === 0) break;
|
|
114
|
+
length += bytesRead;
|
|
115
|
+
}
|
|
116
|
+
const completed = await handle.stat({ bigint: true });
|
|
117
|
+
if (opened.size !== completed.size || opened.mtimeNs !== completed.mtimeNs || opened.ctimeNs !== completed.ctimeNs) {
|
|
118
|
+
throw new Error('Asset changed while reading');
|
|
119
|
+
}
|
|
120
|
+
const truncated = length > MAX_ASSET_BYTES;
|
|
121
|
+
const text = new TextDecoder('utf-8', { fatal: true }).decode(bytes.subarray(0, Math.min(length, MAX_ASSET_BYTES)), {
|
|
122
|
+
stream: truncated,
|
|
123
|
+
});
|
|
124
|
+
if (text.includes('\0')) throw new Error('Asset is not UTF-8 text');
|
|
125
|
+
return { text, truncated };
|
|
126
|
+
} finally {
|
|
127
|
+
await handle.close();
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function agentId(value) {
|
|
132
|
+
const label = String(value).toLowerCase().trim();
|
|
133
|
+
if (label.startsWith('open-code')) return 'opencode';
|
|
134
|
+
return Object.keys(agentHomes).find((agent) => label.startsWith(agent))
|
|
135
|
+
?? (label.startsWith('deepseek') ? 'dsh' : label);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function noteName(name) {
|
|
139
|
+
return !name.startsWith('.') && /\.md$/i.test(name) && !sensitiveName.test(name);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
async function addNote(items, root, relative, agent, scope, detail) {
|
|
143
|
+
if (!noteName(path.basename(relative))) return;
|
|
144
|
+
const note = await recordAsset(root, path.join(root, relative), {
|
|
145
|
+
agent, scope, detail, name: path.basename(relative, path.extname(relative)),
|
|
146
|
+
});
|
|
147
|
+
if (note) items.push(note);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
async function notesIn(items, root, folder, agent, scope, detail) {
|
|
151
|
+
const entries = await children(root, folder);
|
|
152
|
+
await Promise.all(entries.filter((entry) => entry.isFile() && noteName(entry.name)).map((entry) => (
|
|
153
|
+
addNote(items, root, path.join(folder, entry.name), agent, scope, detail)
|
|
154
|
+
)));
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function registryPaths(text) {
|
|
158
|
+
return [...text.matchAll(/^(?:canonicalPath:|\s+path:)[ \t]+([^\r\n]+)$/gm)].map((match) => {
|
|
159
|
+
const value = match[1].trim();
|
|
160
|
+
if (value.startsWith("'") && value.endsWith("'")) return value.slice(1, -1).replaceAll("''", "'");
|
|
161
|
+
if (value.startsWith('"') && value.endsWith('"')) {
|
|
162
|
+
try { return JSON.parse(value); } catch { return ''; }
|
|
163
|
+
}
|
|
164
|
+
return value;
|
|
165
|
+
}).filter((value) => typeof value === 'string' && path.isAbsolute(value));
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
async function hubNotes(items, root, cwd, projectIds) {
|
|
169
|
+
for (const id of projectIds.filter((value) => /^P\d{3,}$/.test(value))) {
|
|
170
|
+
const folder = path.join('项目档案', id);
|
|
171
|
+
const record = await recordAsset(root, path.join(root, folder, 'project.yaml'), {});
|
|
172
|
+
if (!record) continue;
|
|
173
|
+
try {
|
|
174
|
+
const { text, truncated } = await readAsset(record);
|
|
175
|
+
if (truncated) continue;
|
|
176
|
+
const directories = await Promise.all(registryPaths(text).map(directory));
|
|
177
|
+
if (!directories.some((directory) => directory && canonicalKey(directory) === canonicalKey(cwd))) continue;
|
|
178
|
+
} catch {
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
await Promise.all(['.', ...hubFolders].map((subfolder) => (
|
|
182
|
+
notesIn(items, root, path.join(folder, subfolder), 'workspacehub', 'shared', `${id} · ${subfolder === '.' ? '项目记忆' : subfolder}`)
|
|
183
|
+
)));
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
async function exportedNotes(items, cwd, memoryExports) {
|
|
188
|
+
await Promise.all(Object.entries(memoryExports ?? {}).map(async ([workspace, paths]) => {
|
|
189
|
+
const projectRoot = await directory(workspace);
|
|
190
|
+
if (!projectRoot || canonicalKey(projectRoot) !== canonicalKey(cwd)) return;
|
|
191
|
+
await Promise.all(paths.map(async (source) => {
|
|
192
|
+
if (typeof source !== 'string' || !path.isAbsolute(source)) return;
|
|
193
|
+
const folder = await directory(source);
|
|
194
|
+
if (folder) {
|
|
195
|
+
await notesIn(items, folder, '.', 'export', 'project', '配置的记忆导出');
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
const parent = await directory(path.dirname(source));
|
|
199
|
+
if (parent) await addNote(items, parent, path.basename(source), 'export', 'project', '配置的记忆导出');
|
|
200
|
+
}));
|
|
201
|
+
}));
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
async function nativeNotes(items, root, cwd, agent) {
|
|
205
|
+
const globalFolders = {
|
|
206
|
+
antigravity: ['knowledge'], claude: ['agent-memory'],
|
|
207
|
+
codex: ['memories', 'memories_v2', 'memories/extensions/ad_hoc/notes', 'memories_v2/extensions/ad_hoc/notes'],
|
|
208
|
+
dsh: ['diary'], opencode: ['memory'], qoder: ['memory', 'qoder-knowledge'], reasonix: ['memory/global'],
|
|
209
|
+
trae: ['memory'], workbuddy: ['memory'],
|
|
210
|
+
};
|
|
211
|
+
for (const folder of globalFolders[agent] ?? []) {
|
|
212
|
+
await notesIn(items, root, folder, agent, 'agent', '智能体记忆');
|
|
213
|
+
if (agent === 'claude' || agent === 'antigravity') {
|
|
214
|
+
const buckets = await children(root, folder);
|
|
215
|
+
await Promise.all(buckets.filter((entry) => entry.isDirectory() && !entry.name.startsWith('.')).map((entry) => (
|
|
216
|
+
notesIn(items, root, path.join(folder, entry.name, agent === 'antigravity' ? 'artifacts' : ''), agent, 'agent', entry.name)
|
|
217
|
+
)));
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
const instructionFiles = {
|
|
221
|
+
claude: ['CLAUDE.md'], codex: ['AGENTS.md'], dsh: ['AGENTS.md'], gemini: ['GEMINI.md'],
|
|
222
|
+
opencode: ['AGENTS.md', 'MEMORY.md'], qwen: ['QWEN.md'], workbuddy: ['USER.md', 'SOUL.md', 'MEMORY.md'],
|
|
223
|
+
};
|
|
224
|
+
await Promise.all((instructionFiles[agent] ?? []).map((name) => addNote(items, root, name, agent, 'agent', '用户指引')));
|
|
225
|
+
if (cwd && ['claude', 'qoder', 'qwen'].includes(agent)) {
|
|
226
|
+
const slug = cwd.replace(/[^\p{L}\p{N}]/gu, '-');
|
|
227
|
+
const asciiSlug = cwd.replace(/[^a-zA-Z0-9]/g, '-');
|
|
228
|
+
for (const name of new Set([slug, asciiSlug, slug.toLowerCase()])) {
|
|
229
|
+
await notesIn(items, root, path.join('projects', name, 'memory'), agent, 'project', '原生工作区记忆');
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
async function skillFolder(items, root, relative, agent, scope, linkedRoots, detail, includeSystem = true) {
|
|
235
|
+
const entries = await children(root, relative);
|
|
236
|
+
for (const entry of entries) {
|
|
237
|
+
if ((!entry.isDirectory() && !entry.isSymbolicLink()) || (entry.name.startsWith('.') && entry.name !== '.system')) continue;
|
|
238
|
+
const child = path.join(relative, entry.name);
|
|
239
|
+
if (entry.name === '.system' && includeSystem && entry.isDirectory()) {
|
|
240
|
+
await skillFolder(items, root, child, agent, scope, linkedRoots, detail, false);
|
|
241
|
+
continue;
|
|
242
|
+
}
|
|
243
|
+
const target = await directory(path.join(root, child));
|
|
244
|
+
const boundary = target && [root, ...linkedRoots].find((candidate) => inside(candidate, target));
|
|
245
|
+
if (!boundary) continue;
|
|
246
|
+
const item = await recordAsset(boundary, path.join(target, 'SKILL.md'), { name: entry.name, agent, scope, detail });
|
|
247
|
+
if (item) items.push(item);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
async function cachedPluginSkills(items, root, agent) {
|
|
252
|
+
const cache = 'plugins/cache';
|
|
253
|
+
for (const market of (await children(root, cache)).filter((entry) => entry.isDirectory() && !entry.name.startsWith('.'))) {
|
|
254
|
+
const marketFolder = path.join(cache, market.name);
|
|
255
|
+
const packages = (await children(root, marketFolder)).filter((entry) => entry.isDirectory() && !entry.name.startsWith('.'));
|
|
256
|
+
await Promise.all(packages.map(async (plugin) => {
|
|
257
|
+
const packageFolder = path.join(marketFolder, plugin.name);
|
|
258
|
+
const versions = (await children(root, packageFolder)).filter((entry) => entry.isDirectory() && !entry.name.startsWith('.'));
|
|
259
|
+
versions.sort((a, b) => b.name.localeCompare(a.name, undefined, { numeric: true }));
|
|
260
|
+
for (const version of versions) {
|
|
261
|
+
const found = [];
|
|
262
|
+
await skillFolder(found, root, path.join(packageFolder, version.name, 'skills'), agent, 'agent', [], `${plugin.name} · ${version.name} · 本地缓存`);
|
|
263
|
+
if (found.length) {
|
|
264
|
+
items.push(...found);
|
|
265
|
+
break;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}));
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
function unique(items) {
|
|
273
|
+
const indexed = new Map();
|
|
274
|
+
for (const item of items) {
|
|
275
|
+
const key = `${item.agent}:${item.scope}:${canonicalKey(item.file)}`;
|
|
276
|
+
if (!indexed.has(key)) indexed.set(key, item);
|
|
277
|
+
}
|
|
278
|
+
return [...indexed.values()].sort((a, b) => a.agent.localeCompare(b.agent) || a.name.localeCompare(b.name));
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
export async function listProjectAssets(project, config = {}) {
|
|
282
|
+
const home = config.home ?? homedir();
|
|
283
|
+
const cwd = await directory(project.cwd);
|
|
284
|
+
const hubs = (await Promise.all((config.workspaceHubRoots ?? []).map(directory))).filter(Boolean);
|
|
285
|
+
const sharedCandidates = [
|
|
286
|
+
path.join(home, '.agents/skills'), path.join(home, '.config/skillshare/skills'),
|
|
287
|
+
path.join(home, '.skillshare/skills'), path.join(home, 'AppData/Roaming/skillshare/skills'),
|
|
288
|
+
...(config.skillRoots ?? []), ...hubs.map((root) => path.join(root, 'skills/source')),
|
|
289
|
+
];
|
|
290
|
+
const sharedRoots = [...new Set((await Promise.all(sharedCandidates.map(directory))).filter(Boolean))];
|
|
291
|
+
const agents = new Set((project.agents ?? []).map(agentId));
|
|
292
|
+
const configured = Object.entries(config.agentRoots ?? {});
|
|
293
|
+
const memories = [];
|
|
294
|
+
const skills = [];
|
|
295
|
+
|
|
296
|
+
if (cwd) {
|
|
297
|
+
const instructions = Object.entries(projectInstructions).map(([file, agent]) => addNote(memories, cwd, file, agent, 'project', '项目指引'));
|
|
298
|
+
const folders = Object.entries(projectAgentFolders).map(async ([folder, agent]) => {
|
|
299
|
+
await Promise.all([
|
|
300
|
+
notesIn(memories, cwd, path.join(folder, 'memory'), agent, 'project', '项目记忆'),
|
|
301
|
+
...Object.entries(projectInstructions).filter(([, owner]) => owner === agent).map(([file]) => (
|
|
302
|
+
addNote(memories, cwd, path.join(folder, file), agent, 'project', '项目指引')
|
|
303
|
+
)),
|
|
304
|
+
skillFolder(skills, cwd, path.join(folder, 'skills'), agent, 'project', sharedRoots, '项目 Skill'),
|
|
305
|
+
]);
|
|
306
|
+
});
|
|
307
|
+
await Promise.all([
|
|
308
|
+
...instructions, ...folders,
|
|
309
|
+
notesIn(memories, cwd, '.agent-bridge/memory', 'shared', 'project', '项目共享记忆'),
|
|
310
|
+
notesIn(memories, cwd, '.agent-bridge/handoffs', 'shared', 'project', '项目交接'),
|
|
311
|
+
...hubs.map((root) => hubNotes(memories, root, cwd, project.projectIds ?? [])),
|
|
312
|
+
exportedNotes(memories, cwd, config.memoryExports),
|
|
313
|
+
...['.agents/skills', '.skillshare/skills', 'skills'].map((folder) => (
|
|
314
|
+
skillFolder(skills, cwd, folder, 'shared', 'project', sharedRoots, '项目 Skill')
|
|
315
|
+
)),
|
|
316
|
+
]);
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
await Promise.all([
|
|
320
|
+
...sharedRoots.map((root) => skillFolder(skills, root, '.', 'shared', 'shared', sharedRoots, '共享 Skill')),
|
|
321
|
+
...[...agents].map(async (agent) => {
|
|
322
|
+
const overrides = configured.filter(([name]) => agentId(name) === agent);
|
|
323
|
+
const candidates = overrides.length
|
|
324
|
+
? overrides.flatMap(([, roots]) => roots)
|
|
325
|
+
: (agentHomes[agent] ?? []).map((folder) => path.join(home, folder));
|
|
326
|
+
const roots = [...new Set((await Promise.all(candidates.map(directory))).filter(Boolean))];
|
|
327
|
+
if (agent === 'opencode') {
|
|
328
|
+
const configDirs = config.opencodeSkillRoots ?? [path.join(home, '.config/opencode')];
|
|
329
|
+
const configRoots = (await Promise.all(configDirs.map(directory))).filter(Boolean);
|
|
330
|
+
const memoryRoots = [...new Set([...roots, ...configRoots])];
|
|
331
|
+
const skillRoots = config.opencodeSkillRoots === undefined ? memoryRoots : [...new Set(configRoots)];
|
|
332
|
+
await Promise.all([
|
|
333
|
+
...memoryRoots.map((root) => nativeNotes(memories, root, cwd, agent)),
|
|
334
|
+
...skillRoots.flatMap((root) => ['skills', 'skill'].map((folder) => (
|
|
335
|
+
skillFolder(skills, root, folder, agent, 'agent', sharedRoots, '智能体 Skill')
|
|
336
|
+
))),
|
|
337
|
+
]);
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
await Promise.all(roots.flatMap((root) => [
|
|
341
|
+
nativeNotes(memories, root, cwd, agent),
|
|
342
|
+
skillFolder(skills, root, 'skills', agent, 'agent', sharedRoots, '智能体 Skill'),
|
|
343
|
+
...(['claude', 'codex'].includes(agent) ? [cachedPluginSkills(skills, root, agent)] : []),
|
|
344
|
+
]));
|
|
345
|
+
}),
|
|
346
|
+
]);
|
|
347
|
+
return { memories: unique(memories), skills: unique(skills) };
|
|
348
|
+
}
|