dsh-dpharness 0.3.5 → 0.4.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 +74 -2
- package/lib/client.js +300 -25
- package/lib/index.js +200 -5
- package/package.json +13 -2
package/README.md
CHANGED
|
@@ -3,6 +3,19 @@
|
|
|
3
3
|
在 DeepSeek Harness(dsh)里浏览、搜索 [dpharness.com](https://dpharness.com) 的 dsh 插件目录,
|
|
4
4
|
**并可直接一键安装**。
|
|
5
5
|
|
|
6
|
+
## 两个视图
|
|
7
|
+
|
|
8
|
+
面板(浮窗与页签共用同一套组件)顶部可在两个视图间切换:
|
|
9
|
+
|
|
10
|
+
| 视图 | 数据来源 | 回答的问题 |
|
|
11
|
+
|---|---|---|
|
|
12
|
+
| **严选推荐** | `GET /api/plugins`(全量目录) | 「我知道要什么,帮我找」——可搜索、可按 Star 排序 |
|
|
13
|
+
| **分类精选** | `GET /api/best`(月度策展,与站点 [/best](https://dpharness.com/best) 同一份数据) | 「我该装哪几个」——按大类 → 小类分组,每小类只留 2~3 个 |
|
|
14
|
+
|
|
15
|
+
分类精选视图刻意保留两项元数据:**小类内名次**与**上榜理由**(如「小类第 1 · 实装验证通过 · 周下载 12.8 万」)。
|
|
16
|
+
去掉它们,这份清单就只是又一个列表;它们的价值恰恰在于「为什么是它」可复核。
|
|
17
|
+
入榜门槛(站点侧规则):通过静态安装检查或 CI 实装验证 + 汉化完成;每月 1 日重算并公开淘汰原因。
|
|
18
|
+
|
|
6
19
|
## 三个入口
|
|
7
20
|
|
|
8
21
|
| 入口 | 位置 | 说明 |
|
|
@@ -47,37 +60,96 @@
|
|
|
47
60
|
- 目标包名过字符白名单校验;子进程环境会剥掉宿主的 safe-delete shim(否则 pnpm 清理临时文件被拦)。
|
|
48
61
|
- 失败时展示 pnpm 的错误码行(如 `[ERR_PNPM_FETCH_404] …`),而不是一堆进度日志。
|
|
49
62
|
|
|
63
|
+
## 安装漏斗与埋点
|
|
64
|
+
|
|
65
|
+
一次安装从「看见」到「真的生效」要跨 7 个环节,每步都有独立事件 —— 否则
|
|
66
|
+
「没成功」只能看到一个总数,看不出卡在哪。全部经本地 host 转发(站点端点不带 CORS 头),
|
|
67
|
+
`value` 形如 `action:k=v:…`,并**统一附加插件版本**(`v=`)。
|
|
68
|
+
|
|
69
|
+
| 事件 | 触发点 | 回答的问题 |
|
|
70
|
+
|---|---|---|
|
|
71
|
+
| `hello` | 插件被加载 | 有哪些版本在用(老版本发不出新事件,空值必须能和「没人做」区分) |
|
|
72
|
+
| `open` / `search` / `best_open` | 打开面板 / 搜索 / 切到分类精选 | 入口有没有用 |
|
|
73
|
+
| `install_ask` | 点「安装」(弹出确认框) | 有多少人真的动了安装的念头 |
|
|
74
|
+
| `install_cancel` | 确认框点取消 | 被确认框劝退的人(文案/门槛的优化对象) |
|
|
75
|
+
| `install` | 确认后开始安装 | 真正发起的安装 |
|
|
76
|
+
| `install_failed` | 安装失败(含 `via` 阶段与 `why` 原因) | 失败卡在哪一步 |
|
|
77
|
+
| `installed_market` / `installed_local` | 安装成功(热挂载 / 需重启) | 装成了多少 |
|
|
78
|
+
| `restart_click` | 点「立即重启」 | 需重启的那批里有多少人真的重启了 |
|
|
79
|
+
| `post_install` | **下一次加载时**回查 | 重启发生没发生、装的包进了加载清单没有 |
|
|
80
|
+
|
|
81
|
+
`why` 是**闭集枚举**(`busy` / `market_http` / `local_rejected` / `poll_unreachable` /
|
|
82
|
+
`cli_exit` / `timeout` / `restart_http`),不是错误原文 —— 原文含本地路径与包名,
|
|
83
|
+
既不可聚合也不该外发。
|
|
84
|
+
|
|
85
|
+
### 「安装成功之后」怎么验证
|
|
86
|
+
|
|
87
|
+
安装完成那一刻没有任何东西能证明结果:热挂载路径不重启,本地 CLI 路径要等重启才生效。
|
|
88
|
+
所以安装成功时只在 `localStorage` 留一张凭据(目标包名 / 阶段 / 时间),
|
|
89
|
+
**下次插件被加载时**由 host 回查两件事:
|
|
90
|
+
|
|
91
|
+
| 字段 | 来源 | 含义 |
|
|
92
|
+
|---|---|---|
|
|
93
|
+
| `restarted` | host 进程启动时间 vs 安装时间 | dsh 在安装之后**确实重启过** |
|
|
94
|
+
| `bundled` | profile `package.json` 的 `dsh.profile.bundles` | 该包**进了 dsh 的加载清单** |
|
|
95
|
+
|
|
96
|
+
两个字段都刻意做成三态:`1` / `0` / **不写**。不写表示「没查到」,
|
|
97
|
+
绝不用 `0` 兜底 —— 把「查不到」记成「没装上」会让整条漏斗的结论反过来。
|
|
98
|
+
|
|
99
|
+
> ⚠️ 已知边界:`bundled` 对 `via=market`(dshmarket 热挂载)不作为失败判据 ——
|
|
100
|
+
> 它有自己的挂载机制,是否写 profile 清单本插件未验证。看 `bundled` 请以 `via=local` 为准。
|
|
101
|
+
|
|
50
102
|
## HTTP 路由(host 侧)
|
|
51
103
|
|
|
52
104
|
| 路由 | 说明 |
|
|
53
105
|
|---|---|
|
|
54
106
|
| `GET /api/dpharness/search?q=&take=&sort=stars` | 目录查询,字段裁剪后返回,按 `q+take+sort` 缓存 5 分钟 |
|
|
107
|
+
| `GET /api/dpharness/best` | 分类精选榜单(站点 `/api/best` 的代理 + 字段裁剪),缓存 5 分钟 |
|
|
108
|
+
| `GET /api/dpharness/postinstall?pkg=&via=&at=` | 安装后回执(只读:进程启动时间 + profile 加载清单) |
|
|
55
109
|
| `POST /api/dpharness/event` | 埋点代理 → `dpharness.com/api/track/event` |
|
|
56
110
|
| `POST /api/dpharness/install` | `{ pkg }`,spawn `dsh plugin add`;返回 202 + 任务启动 |
|
|
57
111
|
| `GET /api/dpharness/install` | 安装任务进度与结果 |
|
|
58
112
|
| `GET /api/dpharness/meta` | 版本、profile、路由清单、缓存与安装状态 |
|
|
59
113
|
|
|
114
|
+
> ⚠️ 改 host 路由时注意:`parseQuery()` 是 search/best 专用的**白名单**解析器,
|
|
115
|
+
> 只输出 `q/take/sort`。新路由自定义参数请用 `readParams()` ——
|
|
116
|
+
> 复用 `parseQuery()` 会让参数**静默读成空串**(实测踩过)。
|
|
117
|
+
|
|
60
118
|
## 隐私
|
|
61
119
|
|
|
62
120
|
- **不采集搜索关键词原文**,只上报动作、关键词长度与命中数。
|
|
121
|
+
- **不上报错误原文**,失败原因只发闭集枚举。
|
|
63
122
|
- 复制/安装命令的上报口径与站点一致(`copy_install` 的 value 为整条命令),
|
|
64
123
|
来源靠 `path=/dsh-plugin` 区分。
|
|
124
|
+
- 回执查询只读本机 profile 的清单文件,结果仅两个布尔量。
|
|
65
125
|
- 浮窗与页签底部都有**匿名统计开关**,可随时关闭。
|
|
66
126
|
- 埋点经本地 host 转发(站点端点不带 CORS 头),失败静默忽略,绝不影响操作。
|
|
67
127
|
|
|
68
128
|
## 安装本插件
|
|
69
129
|
|
|
130
|
+
**官方命令(推荐)**:
|
|
131
|
+
|
|
70
132
|
```bash
|
|
71
|
-
dsh plugin --profile web add dsh-dpharness
|
|
133
|
+
dsh plugin --profile web add dsh-dpharness
|
|
72
134
|
```
|
|
73
135
|
|
|
74
136
|
> `--profile web` 是 dsh CLI 的**必需参数**,省略会直接报
|
|
75
137
|
> `required option '--profile <name>' not specified`。
|
|
76
138
|
> 任何来源给出的 `dsh plugin add <owner/repo>` 都不可用。
|
|
77
139
|
|
|
78
|
-
|
|
140
|
+
也可从 GitHub 源安装(等价,未依赖 npm 缓存时用):
|
|
141
|
+
|
|
142
|
+
```bash
|
|
143
|
+
dsh plugin --profile web add zhanghao3693/dsh-dpharness
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
开发用(改完立刻看效果,从本地目录装):`bash install.sh`,然后重启 dsh
|
|
79
147
|
(侧边栏「重启」按钮,或 `pkill -9 -f "bin/dsh web"` 让 launchd 拉起)。
|
|
80
148
|
|
|
149
|
+
> ⚠️ **`install.sh` 与官方命令不能混用**:官方安装会把它并入 profile 的 bundle 层,
|
|
150
|
+
> 而 `install.sh` 是往 profile 的 `cordis.patch.yml` 里插一段 `insert` ——
|
|
151
|
+
> 同一个 `id` 被插入两次会让 **dsh 启动硬失败**。切换前先清掉另一边。
|
|
152
|
+
|
|
81
153
|
## 卸载
|
|
82
154
|
|
|
83
155
|
从 `~/.dsh/profiles/web/cordis.patch.yml` 删掉含 `id: dpharness` 的 `insert` 块,然后:
|
package/lib/client.js
CHANGED
|
@@ -35,6 +35,33 @@ window.__ModuleLoader__.load({
|
|
|
35
35
|
".dph_desc{font-size:12px;line-height:1.6;color:var(--dsw-alias-label-secondary);margin:0}",
|
|
36
36
|
".dph_cmdRow{display:flex;align-items:center;gap:8px;flex-wrap:wrap}",
|
|
37
37
|
".dph_cmdWrap{display:flex;flex-direction:column;gap:4px}",
|
|
38
|
+
/* 视图切换(严选推荐 / 分类精选):复用既有 `.dph_seg`,
|
|
39
|
+
只加一层包裹让它铺满面板宽度。
|
|
40
|
+
⚠️ 不要重定义 .dph_seg / .dph_segBtn —— 排序与数量控件也在用它们,
|
|
41
|
+
重复定义会**覆盖既有样式**(2026-09-18 自己踩过:加了同名定义且排在后面,
|
|
42
|
+
把既有的两个控件改了观感)。用包裹层提高特异性即可。 */
|
|
43
|
+
".dph_segWrap{display:flex}",
|
|
44
|
+
".dph_segWrap .dph_seg{flex:1}",
|
|
45
|
+
".dph_segWrap .dph_segBtn{flex:1}",
|
|
46
|
+
/* 分类精选:大类(可折叠)→ 小类 → 条目
|
|
47
|
+
⚠️ `flex:none` 不可省(2026-09-18 实测踩到,用户截图暴露):
|
|
48
|
+
`.dph_panelBody` 是 `display:flex; flex-direction:column`,而本元素有
|
|
49
|
+
`overflow:hidden`(为了圆角)。规范规定 flex 子项的**自动最小高度只在
|
|
50
|
+
overflow:visible 时生效** —— 有了 overflow:hidden,最小高度变 0,
|
|
51
|
+
于是 9 个大类被**压扁成细线**、展开的那个也把卡片压没了(文字被裁掉)。
|
|
52
|
+
显式 `flex:none` 让它保持内容高度、由面板主体滚动。
|
|
53
|
+
(「严选推荐」视图没这个问题,因为 .dph_card 没有 overflow:hidden。) */
|
|
54
|
+
".dph_bestCat{flex:none;border:1px solid var(--dsw-alias-border-l2);border-radius:10px;background:var(--dsw-alias-bg-layer-1);overflow:hidden}",
|
|
55
|
+
".dph_bestCatHead{display:flex;align-items:baseline;justify-content:space-between;gap:8px;padding:8px 12px;cursor:pointer;list-style:none;font-size:13px;font-weight:600;color:var(--dsw-alias-label-primary)}",
|
|
56
|
+
".dph_bestCatHead::-webkit-details-marker{display:none}",
|
|
57
|
+
".dph_bestCatCount{font-size:10px;font-weight:400;color:var(--dsw-alias-label-tertiary)}",
|
|
58
|
+
".dph_bestSub{padding:0 10px 10px}",
|
|
59
|
+
".dph_bestSubHead{display:flex;align-items:baseline;gap:6px;padding:6px 2px 6px;flex-wrap:wrap}",
|
|
60
|
+
".dph_bestSubName{font-size:12px;font-weight:600;color:var(--dsw-alias-label-primary)}",
|
|
61
|
+
".dph_bestSubSum{font-size:10px;color:var(--dsw-alias-label-tertiary);overflow:hidden;text-overflow:ellipsis;white-space:nowrap;max-width:100%}",
|
|
62
|
+
".dph_bestItem{display:flex;flex-direction:column;gap:4px}",
|
|
63
|
+
".dph_bestRank{font-size:10px;font-weight:700;color:var(--dsw-alias-state-business-primary)}",
|
|
64
|
+
".dph_bestReason{font-size:10px;color:var(--dsw-alias-label-tertiary);padding-left:2px}",
|
|
38
65
|
".dph_cmd{flex:1;min-width:200px;box-sizing:border-box;background:var(--dsw-alias-bg-layer-3);border-radius:6px;padding:6px 10px;font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:12px;color:var(--dsw-alias-label-primary);overflow-x:auto;white-space:nowrap}",
|
|
39
66
|
".dph_cmdMissing{font-size:12px;color:var(--dsw-alias-label-tertiary)}",
|
|
40
67
|
".dph_notice{border:1px solid var(--dsw-alias-border-l2);border-radius:10px;padding:14px;font-size:13px;color:var(--dsw-alias-label-secondary)}",
|
|
@@ -111,6 +138,12 @@ window.__ModuleLoader__.load({
|
|
|
111
138
|
"label.untranslated": "未汉化",
|
|
112
139
|
"label.repoSource": "GitHub 源",
|
|
113
140
|
"hint.repoSource": "该插件未发布到 npm,走 GitHub 源安装(与站点详情页同口径)。",
|
|
141
|
+
"best.recommend": "严选推荐",
|
|
142
|
+
"best.picks": "分类精选",
|
|
143
|
+
"best.catCount": "{subs} 个小类 · {n} 个",
|
|
144
|
+
"best.month": "{m} 期 · 每小类 2~3 个",
|
|
145
|
+
"best.loading": "正在取当期榜单…",
|
|
146
|
+
"best.empty": "当期榜单还没有数据(每月 1 日重算)",
|
|
114
147
|
"footer.hint": "网页无法自动安装:复制命令到终端执行,装完重启 dsh 才会生效。命令里的 --profile web 不可省略。",
|
|
115
148
|
"telemetry.on": "匿名统计(不含搜索内容)",
|
|
116
149
|
"install.action": "安装",
|
|
@@ -150,6 +183,12 @@ window.__ModuleLoader__.load({
|
|
|
150
183
|
"label.untranslated": "Not translated",
|
|
151
184
|
"label.repoSource": "GitHub source",
|
|
152
185
|
"hint.repoSource": "Not published to npm — installs from the GitHub source (same rule as the site's detail page).",
|
|
186
|
+
"best.recommend": "Curated",
|
|
187
|
+
"best.picks": "By category",
|
|
188
|
+
"best.catCount": "{subs} groups · {n}",
|
|
189
|
+
"best.month": "{m} · 2-3 per group",
|
|
190
|
+
"best.loading": "Loading this month's picks…",
|
|
191
|
+
"best.empty": "No picks for the current month yet (recomputed on the 1st)",
|
|
153
192
|
"footer.hint": "A web page cannot install plugins: copy the command into a terminal, then restart dsh. The --profile web flag is mandatory.",
|
|
154
193
|
"telemetry.on": "Anonymous stats (no search text)",
|
|
155
194
|
"install.action": "Install",
|
|
@@ -172,6 +211,9 @@ window.__ModuleLoader__.load({
|
|
|
172
211
|
隐私口径:不发送搜索关键词原文,只发长度与命中数;可整体关闭。 */
|
|
173
212
|
const TEL_KEY = "dph-hub-telemetry";
|
|
174
213
|
const VID_KEY = "dph-hub-vid";
|
|
214
|
+
/* 安装成功但还没验证的凭据(见 reportPostInstall)。
|
|
215
|
+
只放本地,不上报:重启前没有任何东西可以验证它。 */
|
|
216
|
+
const PENDING_KEY = "dph-hub-pending";
|
|
175
217
|
let telemetryOn = true;
|
|
176
218
|
try {
|
|
177
219
|
telemetryOn = localStorage.getItem(TEL_KEY) !== "0";
|
|
@@ -205,6 +247,57 @@ window.__ModuleLoader__.load({
|
|
|
205
247
|
}
|
|
206
248
|
}
|
|
207
249
|
|
|
250
|
+
function rememberPending(entry) {
|
|
251
|
+
try {
|
|
252
|
+
localStorage.setItem(PENDING_KEY, JSON.stringify(entry));
|
|
253
|
+
} catch (error) {
|
|
254
|
+
/* 存不下就不存:宁可丢一条回执,也不能影响安装流程 */
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
function takePending() {
|
|
259
|
+
try {
|
|
260
|
+
const raw = localStorage.getItem(PENDING_KEY);
|
|
261
|
+
if (!raw) return null;
|
|
262
|
+
/* 取出来就清掉:上报失败不重试。
|
|
263
|
+
回执是统计用的,重复灌库的代价比丢一条大。 */
|
|
264
|
+
localStorage.removeItem(PENDING_KEY);
|
|
265
|
+
const parsed = JSON.parse(raw);
|
|
266
|
+
return parsed && typeof parsed.pkg === "string" && parsed.pkg ? parsed : null;
|
|
267
|
+
} catch (error) {
|
|
268
|
+
return null;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* 安装后的回执 —— 只有「插件再次被加载」时才知道结果。
|
|
274
|
+
*
|
|
275
|
+
* 两个判据都必须由 host 给出,客户端自报不成立:
|
|
276
|
+
* · restarted:重启前后是同一段 JS,它无法自证发生过重启;
|
|
277
|
+
* · bundled:profile 的加载清单在磁盘上,浏览器读不到。
|
|
278
|
+
* 查不到时**不传该字段**(host 端 value 里就缺这一项 = 未知),
|
|
279
|
+
* 绝不用 false 兜底 —— 那会把「没查到」记成一个具体的否定结论。
|
|
280
|
+
*/
|
|
281
|
+
function reportPostInstall() {
|
|
282
|
+
const pending = takePending();
|
|
283
|
+
if (!pending) return;
|
|
284
|
+
const query =
|
|
285
|
+
"pkg=" + encodeURIComponent(pending.pkg) +
|
|
286
|
+
"&via=" + encodeURIComponent(String(pending.via || "")) +
|
|
287
|
+
"&at=" + encodeURIComponent(String(pending.at || ""));
|
|
288
|
+
fetch("/api/dpharness/postinstall?" + query)
|
|
289
|
+
.then((response) => response.json())
|
|
290
|
+
.then((data) => {
|
|
291
|
+
if (!data || data.ok !== true) return;
|
|
292
|
+
const detail = { action: "post_install", via: String(pending.via || "unknown") };
|
|
293
|
+
if (typeof data.restarted === "boolean") detail.restarted = data.restarted;
|
|
294
|
+
if (typeof data.bundled === "boolean") detail.bundled = data.bundled;
|
|
295
|
+
if (typeof data.dep === "boolean") detail.dep = data.dep;
|
|
296
|
+
track("plugin_hub", detail);
|
|
297
|
+
})
|
|
298
|
+
.catch(() => {});
|
|
299
|
+
}
|
|
300
|
+
|
|
208
301
|
/* --------------------------------------------------------------- installer */
|
|
209
302
|
/* 两条路径,安全优先:
|
|
210
303
|
① 复用已装的 dshmarket 的同源 HTTP 路由(免重启热挂载、可回滚);
|
|
@@ -245,17 +338,19 @@ window.__ModuleLoader__.load({
|
|
|
245
338
|
return fallback + "(HTTP " + (result ? result.status : "?") + ")";
|
|
246
339
|
}
|
|
247
340
|
|
|
341
|
+
/* why 是**闭集枚举**,不是错误原文 —— 原文含本地路径与包名,既不可聚合也会
|
|
342
|
+
把用户环境信息带出去。分类只回答「卡在哪一步」,够用来定位了。 */
|
|
248
343
|
async function pollMarketInstall(deadline) {
|
|
249
344
|
while (Date.now() < deadline) {
|
|
250
345
|
await sleep(INSTALL_POLL_MS);
|
|
251
346
|
const status = await getJson(MARKET_STATUS);
|
|
252
|
-
if (status.status !== 200 || !status.data) return { ok: false, message: messageOf(status, "dshmarket status unavailable") };
|
|
347
|
+
if (status.status !== 200 || !status.data) return { ok: false, via: "market", why: "poll_unreachable", message: messageOf(status, "dshmarket status unavailable") };
|
|
253
348
|
if (status.data.active === false && status.data.busy === false) {
|
|
254
|
-
if (status.data.error) return { ok: false, message: String(status.data.error).slice(0, 200) };
|
|
349
|
+
if (status.data.error) return { ok: false, via: "market", why: "cli_error", message: String(status.data.error).slice(0, 200) };
|
|
255
350
|
return { ok: true, market: true };
|
|
256
351
|
}
|
|
257
352
|
}
|
|
258
|
-
return { ok: false, message: "timeout" };
|
|
353
|
+
return { ok: false, via: "market", why: "timeout", message: "timeout" };
|
|
259
354
|
}
|
|
260
355
|
|
|
261
356
|
async function pollLocalInstall(deadline) {
|
|
@@ -263,13 +358,13 @@ window.__ModuleLoader__.load({
|
|
|
263
358
|
await sleep(INSTALL_POLL_MS);
|
|
264
359
|
const status = await getJson(LOCAL_INSTALL);
|
|
265
360
|
const job = status.data && status.data.job;
|
|
266
|
-
if (status.status !== 200 || !job) return { ok: false, message: messageOf(status, "install status unavailable") };
|
|
361
|
+
if (status.status !== 200 || !job) return { ok: false, via: "local", why: "poll_unreachable", message: messageOf(status, "install status unavailable") };
|
|
267
362
|
if (job.active === false) {
|
|
268
363
|
if (job.code === 0) return { ok: true, market: false };
|
|
269
|
-
return { ok: false, message: String(job.error || job.tail || ("exit code " + job.code)).slice(0, 200) };
|
|
364
|
+
return { ok: false, via: "local", why: job.error === "timeout" ? "timeout" : "cli_exit", message: String(job.error || job.tail || ("exit code " + job.code)).slice(0, 200) };
|
|
270
365
|
}
|
|
271
366
|
}
|
|
272
|
-
return { ok: false, message: "timeout" };
|
|
367
|
+
return { ok: false, via: "local", why: "timeout", message: "timeout" };
|
|
273
368
|
}
|
|
274
369
|
|
|
275
370
|
async function runInstall(item, t) {
|
|
@@ -285,8 +380,14 @@ window.__ModuleLoader__.load({
|
|
|
285
380
|
if (market.status === 200) {
|
|
286
381
|
done = await pollMarketInstall(deadline);
|
|
287
382
|
} else if (market.status === 400 || market.status === 404 || market.status === 0) {
|
|
383
|
+
/* 不在 dshmarket 的 curated registry 里 —— 这是预期路径,降级到本地 CLI,
|
|
384
|
+
不是失败,所以这里不埋点。 */
|
|
288
385
|
done = null;
|
|
289
386
|
} else {
|
|
387
|
+
/* 409 = 有 agent 正在跑,dshmarket 拒绝抢插件文件。它和别的 HTTP 错误
|
|
388
|
+
处理方式相同(都不降级),但原因完全不同,必须分开统计。 */
|
|
389
|
+
const why = market.status === 409 ? "busy" : "market_http";
|
|
390
|
+
track("plugin_hub", { action: "install_failed", via: "market", why });
|
|
290
391
|
setHub({ install: { active: false, target, phase: "failed", message: messageOf(market, t("install.failed")) } });
|
|
291
392
|
return;
|
|
292
393
|
}
|
|
@@ -295,6 +396,11 @@ window.__ModuleLoader__.load({
|
|
|
295
396
|
setHub({ install: { active: true, target, phase: "local", message: t("install.local") } });
|
|
296
397
|
const local = await postJson(LOCAL_INSTALL, { pkg: target });
|
|
297
398
|
if (local.status !== 202) {
|
|
399
|
+
track("plugin_hub", {
|
|
400
|
+
action: "install_failed",
|
|
401
|
+
via: "local",
|
|
402
|
+
why: local.status === 409 ? "busy" : "local_rejected",
|
|
403
|
+
});
|
|
298
404
|
setHub({ install: { active: false, target, phase: "failed", message: messageOf(local, t("install.failed")) } });
|
|
299
405
|
return;
|
|
300
406
|
}
|
|
@@ -308,7 +414,20 @@ window.__ModuleLoader__.load({
|
|
|
308
414
|
message: done.ok ? t(done.market ? "install.okMarket" : "install.okLocal") : done.message,
|
|
309
415
|
},
|
|
310
416
|
});
|
|
311
|
-
if (done.ok)
|
|
417
|
+
if (done.ok) {
|
|
418
|
+
const via = done.market ? "market" : "local";
|
|
419
|
+
track("plugin_hub", { action: done.market ? "installed_market" : "installed_local" });
|
|
420
|
+
/* 留一张凭据给下一次加载。安装成功这一刻没有任何东西能验证结果:
|
|
421
|
+
热挂载路径没有重启,本地 CLI 路径要等重启才生效 —— 两者都只能在
|
|
422
|
+
「插件再次被加载」时由 host 回查(见 reportPostInstall)。 */
|
|
423
|
+
rememberPending({ pkg: target, via: via, at: Date.now() });
|
|
424
|
+
} else {
|
|
425
|
+
track("plugin_hub", {
|
|
426
|
+
action: "install_failed",
|
|
427
|
+
via: done.via || "local",
|
|
428
|
+
why: done.why || "unknown",
|
|
429
|
+
});
|
|
430
|
+
}
|
|
312
431
|
}
|
|
313
432
|
|
|
314
433
|
/** 仅在降级路径(改了 profile)后需要;/api/restart 由 dsh-restart 插件提供(POST)。 */
|
|
@@ -346,15 +465,20 @@ window.__ModuleLoader__.load({
|
|
|
346
465
|
const EDGE = 8;
|
|
347
466
|
const DRAG_THRESHOLD = 5;
|
|
348
467
|
/**
|
|
349
|
-
*
|
|
350
|
-
*
|
|
351
|
-
*
|
|
352
|
-
*
|
|
353
|
-
*
|
|
354
|
-
*
|
|
355
|
-
*
|
|
468
|
+
* 默认位置刻意**不贴右下角**,且要避开其它插件已占的那几个位置。
|
|
469
|
+
*
|
|
470
|
+
* 实测(1280×860 与 1280×900 两次量测,2026-09-17/18)右下角竖着排了三个
|
|
471
|
+
* **z-index 同为 2147483000** 的浮动按钮,DOM 靠后的会压住前面的:
|
|
472
|
+
* · `#dsh-check-updates-btn`(「检查更新」) bottom 16..48
|
|
473
|
+
* · `#mem-open`(dsh-mnemon 的「🧠 Memory」)bottom 56..96
|
|
474
|
+
* 故取 bottom:108(在两者之上)—— 108 这个数是量出来的,不是拍的:
|
|
475
|
+
* 曾经用 60,正好落在 mnemon 按钮的 56..96 里,导致胶囊被完全覆盖、
|
|
476
|
+
* **点不动**(playwright 报 `#mem-open … intercepts pointer events`)。
|
|
477
|
+
*
|
|
478
|
+
* 不用提高 z-index 去抢:那会让被压住的那个按钮反过来点不动(同样是别人的功能)。
|
|
479
|
+
* 位置冲突可以用位置解决;用户仍可拖动,位置会记住。
|
|
356
480
|
*/
|
|
357
|
-
const DEFAULT_POS = { right: 16, bottom:
|
|
481
|
+
const DEFAULT_POS = { right: 16, bottom: 108 };
|
|
358
482
|
|
|
359
483
|
function viewportSize() {
|
|
360
484
|
return {
|
|
@@ -524,6 +648,52 @@ window.__ModuleLoader__.load({
|
|
|
524
648
|
};
|
|
525
649
|
}
|
|
526
650
|
|
|
651
|
+
/**
|
|
652
|
+
* 「分类精选」榜单取数(站点 /best 的同源数据)。
|
|
653
|
+
*
|
|
654
|
+
* 按需拉取:只有用户切到该视图才请求,不拖慢默认打开速度。
|
|
655
|
+
* 拿到一次就不再重复请求(榜单每月 1 日才重算),手动刷新才重取。
|
|
656
|
+
*/
|
|
657
|
+
function useBest(t, enabled) {
|
|
658
|
+
const [reload, setReload] = react.useState(0);
|
|
659
|
+
const [state, setState] = react.useState({ loading: false, data: null, error: null });
|
|
660
|
+
const [copiedCmd, setCopiedCmd] = react.useState("");
|
|
661
|
+
const loaded = react.useRef(false);
|
|
662
|
+
|
|
663
|
+
react.useEffect(() => {
|
|
664
|
+
if (!enabled) return undefined;
|
|
665
|
+
if (loaded.current && reload === 0) return undefined;
|
|
666
|
+
loaded.current = true;
|
|
667
|
+
const controller = new AbortController();
|
|
668
|
+
const timer = setTimeout(() => controller.abort(), 20000);
|
|
669
|
+
setState((previous) => ({ loading: true, data: previous.data, error: null }));
|
|
670
|
+
fetch("/api/dpharness/best", { cache: "no-store", signal: controller.signal })
|
|
671
|
+
.then((response) => response.json().then((body) => ({ status: response.status, body })))
|
|
672
|
+
.then((result) => {
|
|
673
|
+
if (controller.signal.aborted) return;
|
|
674
|
+
if (result.status !== 200 || !result.body || result.body.ok !== true) {
|
|
675
|
+
throw new Error((result.body && result.body.error) || ("HTTP " + result.status));
|
|
676
|
+
}
|
|
677
|
+
setState({ loading: false, data: result.body, error: null });
|
|
678
|
+
track("plugin_hub", { action: "best_open", cats: (result.body.categories || []).length, total: result.body.total || 0 });
|
|
679
|
+
})
|
|
680
|
+
.catch((error) => {
|
|
681
|
+
if (controller.signal.aborted) return;
|
|
682
|
+
const message = error && error.name === "AbortError" ? "timeout" : String((error && error.message) || error);
|
|
683
|
+
setState((previous) => ({ loading: false, data: previous.data, error: message }));
|
|
684
|
+
})
|
|
685
|
+
.finally(() => clearTimeout(timer));
|
|
686
|
+
return () => clearTimeout(timer);
|
|
687
|
+
}, [enabled, reload]);
|
|
688
|
+
|
|
689
|
+
const markCopied = react.useCallback((text) => {
|
|
690
|
+
setCopiedCmd(text);
|
|
691
|
+
setTimeout(() => setCopiedCmd((current) => (current === text ? "" : current)), 2000);
|
|
692
|
+
}, []);
|
|
693
|
+
|
|
694
|
+
return { state, copiedCmd, markCopied, refresh: () => setReload((n) => n + 1) };
|
|
695
|
+
}
|
|
696
|
+
|
|
527
697
|
/* ------------------------------------------------------------ components */
|
|
528
698
|
function makeUi(t) {
|
|
529
699
|
function badge(label, kind) {
|
|
@@ -575,9 +745,16 @@ window.__ModuleLoader__.load({
|
|
|
575
745
|
disabled: restarting,
|
|
576
746
|
onClick: async () => {
|
|
577
747
|
setRestarting(true);
|
|
748
|
+
/* 点击即上报。结果不能在这里等 —— 成功的重启会掐断这个
|
|
749
|
+
请求,"重启成功"只能由下次加载时的 post_install 证明;
|
|
750
|
+
所以这里只记「谁按了」,不记「按了之后成没成」。 */
|
|
751
|
+
track("plugin_hub", { action: "restart_click", via: "local" });
|
|
578
752
|
const ok = await restartServer();
|
|
579
753
|
setRestarting(false);
|
|
580
|
-
if (!ok)
|
|
754
|
+
if (!ok) {
|
|
755
|
+
setRestartFailed(true);
|
|
756
|
+
track("plugin_hub", { action: "restart_failed", via: "local", why: "restart_http" });
|
|
757
|
+
}
|
|
581
758
|
},
|
|
582
759
|
}, t("install.restart"))
|
|
583
760
|
: null,
|
|
@@ -605,7 +782,18 @@ window.__ModuleLoader__.load({
|
|
|
605
782
|
runInstall(item, t);
|
|
606
783
|
},
|
|
607
784
|
}, t("install.confirm")),
|
|
608
|
-
h("button", {
|
|
785
|
+
h("button", {
|
|
786
|
+
className: "dph_btn",
|
|
787
|
+
key: "cancel",
|
|
788
|
+
type: "button",
|
|
789
|
+
onClick: () => {
|
|
790
|
+
setConfirming(false);
|
|
791
|
+
/* 取消单独记一次:只埋 install(确认后)的话,
|
|
792
|
+
「想装但被确认框劝退」的人会整段消失,
|
|
793
|
+
而他们恰恰是文案/门槛该优化的对象。 */
|
|
794
|
+
track("plugin_hub", { action: "install_cancel", via: "confirm" });
|
|
795
|
+
},
|
|
796
|
+
}, t("install.cancel")),
|
|
609
797
|
]);
|
|
610
798
|
}
|
|
611
799
|
|
|
@@ -616,12 +804,67 @@ window.__ModuleLoader__.load({
|
|
|
616
804
|
type: "button",
|
|
617
805
|
disabled: busyElsewhere,
|
|
618
806
|
title: busyElsewhere ? t("install.busy") : item.pkg,
|
|
619
|
-
onClick: () =>
|
|
807
|
+
onClick: () => {
|
|
808
|
+
setConfirming(true);
|
|
809
|
+
track("plugin_hub", { action: "install_ask", via: "confirm" });
|
|
810
|
+
},
|
|
620
811
|
}, busyElsewhere ? t("install.busy") : t("install.action")),
|
|
621
812
|
h("span", { className: "dph_instHint", key: "pkg" }, item.pkg),
|
|
622
813
|
]);
|
|
623
814
|
}
|
|
624
815
|
|
|
816
|
+
/**
|
|
817
|
+
* 「分类精选」视图:大类(可折叠)→ 小类 → 条目。
|
|
818
|
+
*
|
|
819
|
+
* 与「严选推荐」的区别:那边是**可搜索的全量目录**(按你的关键词找),
|
|
820
|
+
* 这边是**月度策展结果**(每小类只留 2~3 个),回答的是"按用途该装哪几个"。
|
|
821
|
+
* 所以渲染上刻意保留两项元数据:
|
|
822
|
+
* · rank —— 小类内名次,用户要知道"这是这个小类里最好的第几个";
|
|
823
|
+
* · reason —— 上榜理由(如"实装验证通过 · 周下载 12.8 万"),
|
|
824
|
+
* 这是"为什么是它"的依据,去掉就只是又一个列表。
|
|
825
|
+
*/
|
|
826
|
+
function renderBest(data, copiedCmd, onCopied) {
|
|
827
|
+
if (!data) return null;
|
|
828
|
+
const cats = Array.isArray(data.categories) ? data.categories : [];
|
|
829
|
+
return cats.map((cat, index) =>
|
|
830
|
+
h("details", { className: "dph_bestCat", key: cat.key || String(index), open: index === 0 }, [
|
|
831
|
+
h("summary", { className: "dph_bestCatHead", key: "head" }, [
|
|
832
|
+
h("span", { key: "name" }, cat.label),
|
|
833
|
+
h(
|
|
834
|
+
"span",
|
|
835
|
+
{ className: "dph_bestCatCount", key: "count" },
|
|
836
|
+
format(t("best.catCount"), { subs: (cat.subs || []).length, n: cat.count || 0 }),
|
|
837
|
+
),
|
|
838
|
+
]),
|
|
839
|
+
...(cat.subs || []).map((sub) =>
|
|
840
|
+
h("div", { className: "dph_bestSub", key: sub.key }, [
|
|
841
|
+
h("div", { className: "dph_bestSubHead", key: "subHead" }, [
|
|
842
|
+
h("span", { className: "dph_bestSubName", key: "n" }, sub.label),
|
|
843
|
+
sub.summary
|
|
844
|
+
? h("span", { className: "dph_bestSubSum", key: "s", title: sub.summary }, sub.summary)
|
|
845
|
+
: null,
|
|
846
|
+
]),
|
|
847
|
+
h(
|
|
848
|
+
"div",
|
|
849
|
+
{ className: "dph_list", key: "list" },
|
|
850
|
+
(sub.items || []).map((item) =>
|
|
851
|
+
h("div", { key: item.fullName, className: "dph_bestItem" }, [
|
|
852
|
+
item.rank
|
|
853
|
+
? h("div", { className: "dph_bestRank", key: "rank" }, "#" + item.rank)
|
|
854
|
+
: null,
|
|
855
|
+
renderCard(item, copiedCmd, onCopied, true),
|
|
856
|
+
item.reason
|
|
857
|
+
? h("div", { className: "dph_bestReason", key: "why" }, item.reason)
|
|
858
|
+
: null,
|
|
859
|
+
]),
|
|
860
|
+
),
|
|
861
|
+
),
|
|
862
|
+
]),
|
|
863
|
+
),
|
|
864
|
+
]),
|
|
865
|
+
);
|
|
866
|
+
}
|
|
867
|
+
|
|
625
868
|
function renderCard(item, copiedCmd, onCopied, compact) {
|
|
626
869
|
const title = item.nameZh || item.name || item.fullName || "";
|
|
627
870
|
const tags = tagsOf(item);
|
|
@@ -786,6 +1029,16 @@ window.__ModuleLoader__.load({
|
|
|
786
1029
|
const skipClickRef = react.useRef(false);
|
|
787
1030
|
const panelRef = react.useRef(null);
|
|
788
1031
|
const onDrag = makeDragHandlers(() => posRef.current, setPos, skipClickRef);
|
|
1032
|
+
/**
|
|
1033
|
+
* 面板内的两个视图:
|
|
1034
|
+
* search = 严选推荐(可搜索的全量目录)
|
|
1035
|
+
* best = 分类精选(站点 /best 的月度策展结果)
|
|
1036
|
+
* 放在同一入口里而不是再开一个入口:用户的意图都是"找该装哪个",
|
|
1037
|
+
* 分成两个入口只会让人不知道该点哪个。
|
|
1038
|
+
*/
|
|
1039
|
+
const [mode, setMode] = react.useState("search");
|
|
1040
|
+
const best = useBest(t, state.open && mode === "best");
|
|
1041
|
+
const bestData = best.state.data;
|
|
789
1042
|
|
|
790
1043
|
/**
|
|
791
1044
|
* 展开时按**面板实际尺寸**重新夹取位置。
|
|
@@ -864,16 +1117,31 @@ window.__ModuleLoader__.load({
|
|
|
864
1117
|
title: t("action.drag"),
|
|
865
1118
|
onPointerDown: onDrag,
|
|
866
1119
|
}, t("view.title")),
|
|
867
|
-
h("span", { className: "dph_sub", key: "sub" },
|
|
1120
|
+
h("span", { className: "dph_sub", key: "sub" }, mode === "best"
|
|
1121
|
+
? (bestData ? format(t("best.month"), { m: bestData.month || "" }) : "")
|
|
1122
|
+
: (data ? format(t("count.summary"), { n: data.count }) : "")),
|
|
868
1123
|
h("span", { className: "dph_spacer", key: "gap" }),
|
|
869
|
-
h("a", { className: "dph_btn", key: "site", href: SITE + "/plugins", target: "_blank", rel: "noopener noreferrer", onClick: () => track("plugin_hub", { action: "site_click", scope: "overlay" }) }, t("action.openSite")),
|
|
1124
|
+
h("a", { className: "dph_btn", key: "site", href: mode === "best" ? SITE + "/best" : SITE + "/plugins", target: "_blank", rel: "noopener noreferrer", onClick: () => track("plugin_hub", { action: "site_click", scope: mode === "best" ? "best" : "overlay" }) }, t("action.openSite")),
|
|
870
1125
|
h("button", { className: "dph_close", key: "close", type: "button", title: t("action.close"), "aria-label": t("action.close"), onClick: () => setHub({ open: false }) }, "×"),
|
|
871
1126
|
]),
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
1127
|
+
h("div", { className: "dph_segWrap", key: "seg" }, seg([
|
|
1128
|
+
{ value: "search", label: t("best.recommend") },
|
|
1129
|
+
{ value: "best", label: t("best.picks") },
|
|
1130
|
+
], mode, setMode)),
|
|
1131
|
+
...(mode === "search"
|
|
1132
|
+
? [
|
|
1133
|
+
controls(cat),
|
|
1134
|
+
cat.state.error ? h(Notice, { key: "error", kind: "bad", text: t("state.failed") + ":" + cat.state.error }) : null,
|
|
1135
|
+
cat.state.loading && cat.plugins.length === 0 ? h(Notice, { key: "loading", text: t("state.loading") }) : null,
|
|
1136
|
+
!cat.state.loading && !cat.state.error && cat.plugins.length === 0 ? h(Notice, { key: "empty", text: t("state.empty") }) : null,
|
|
1137
|
+
h("div", { className: "dph_panelBody", key: "body" }, cat.plugins.map((item) => renderCard(item, cat.copiedCmd, cat.markCopied, true))),
|
|
1138
|
+
]
|
|
1139
|
+
: [
|
|
1140
|
+
best.state.error ? h(Notice, { key: "berror", kind: "bad", text: t("state.failed") + ":" + best.state.error }) : null,
|
|
1141
|
+
best.state.loading && !bestData ? h(Notice, { key: "bloading", text: t("best.loading") }) : null,
|
|
1142
|
+
!best.state.loading && bestData && (bestData.total || 0) === 0 ? h(Notice, { key: "bempty", text: t("best.empty") }) : null,
|
|
1143
|
+
h("div", { className: "dph_panelBody", key: "bbody" }, renderBest(bestData, best.copiedCmd, best.markCopied)),
|
|
1144
|
+
]),
|
|
877
1145
|
h("div", { className: "dph_panelFoot", key: "foot" }, [
|
|
878
1146
|
telemetryToggle(),
|
|
879
1147
|
h("span", { key: "hint", className: "dph_footer" }, t("footer.hint")),
|
|
@@ -892,6 +1160,13 @@ window.__ModuleLoader__.load({
|
|
|
892
1160
|
const t = ctx.locale.bind(NS);
|
|
893
1161
|
const ui = makeUi(t);
|
|
894
1162
|
|
|
1163
|
+
/* 插件被加载 = 一次心跳。它同时是「在用哪个版本」的唯一来源:
|
|
1164
|
+
老版本发不出新事件,看板上的空值必须能和「真没人做」区分开。
|
|
1165
|
+
(版本号由 host 在转发时统一附加。) */
|
|
1166
|
+
track("plugin_hub", { action: "hello" });
|
|
1167
|
+
/* 上一次安装的回执要到这一刻才能取(见 reportPostInstall)。 */
|
|
1168
|
+
reportPostInstall();
|
|
1169
|
+
|
|
895
1170
|
ctx.slots.inject(
|
|
896
1171
|
"conversation.view",
|
|
897
1172
|
() =>
|
package/lib/index.js
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* dsh-dpharness — host half (v0.
|
|
2
|
+
* dsh-dpharness — host half (v0.4.2).
|
|
3
3
|
*
|
|
4
4
|
* Catalog routes, a write-only telemetry relay and a one-click installer:
|
|
5
5
|
*
|
|
6
6
|
* GET /api/dpharness/search?q=<kw>&take=<n>&sort=stars
|
|
7
7
|
* GET /api/dpharness/meta
|
|
8
|
+
* GET /api/dpharness/postinstall?pkg=<pkg>&via=<local|market>&at=<epochMs>
|
|
8
9
|
* POST /api/dpharness/event → relayed to https://dpharness.com/api/track/event
|
|
9
10
|
* POST /api/dpharness/install → spawns `dsh plugin --profile <p> add <pkg>`
|
|
10
11
|
* GET /api/dpharness/install → progress of the one in-flight install job
|
|
11
12
|
*
|
|
12
13
|
* The telemetry relay exists because the site's tracker sends no CORS headers,
|
|
13
14
|
* so the browser page served from 127.0.0.1:8787 cannot post to it directly.
|
|
15
|
+
* It also stamps every relayed event with the plugin version, which is the only
|
|
16
|
+
* way to tell "nobody did this" apart from "an old version could not report it".
|
|
14
17
|
*
|
|
15
18
|
* Privacy contract: the client never sends search keywords. Only event names,
|
|
16
19
|
* an opaque per-install visitor id, package names the user explicitly copied,
|
|
@@ -27,6 +30,8 @@
|
|
|
27
30
|
*/
|
|
28
31
|
|
|
29
32
|
import { spawn } from "node:child_process";
|
|
33
|
+
import fs from "node:fs";
|
|
34
|
+
import os from "node:os";
|
|
30
35
|
import path from "node:path";
|
|
31
36
|
|
|
32
37
|
export const name = "dpharness";
|
|
@@ -34,7 +39,16 @@ export const name = "dpharness";
|
|
|
34
39
|
/** The dsh web server service used to register HTTP routes. */
|
|
35
40
|
export const inject = ["webServer"];
|
|
36
41
|
|
|
37
|
-
export const VERSION = "0.
|
|
42
|
+
export const VERSION = "0.4.2";
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Wall-clock time this dsh process started.
|
|
46
|
+
*
|
|
47
|
+
* Needed to answer "did dsh restart since this install?" — and it has to come
|
|
48
|
+
* from the host, because the client is the same JS before and after a restart
|
|
49
|
+
* and therefore cannot prove a restart happened on its own.
|
|
50
|
+
*/
|
|
51
|
+
const STARTED_AT = Date.now() - Math.round(process.uptime() * 1000);
|
|
38
52
|
|
|
39
53
|
/**
|
|
40
54
|
* Profile used for installs.
|
|
@@ -51,6 +65,7 @@ const PROFILE = (() => {
|
|
|
51
65
|
})();
|
|
52
66
|
|
|
53
67
|
const UPSTREAM = "https://dpharness.com/api/plugins";
|
|
68
|
+
const BEST_UPSTREAM = "https://dpharness.com/api/best";
|
|
54
69
|
const SITE = "https://dpharness.com";
|
|
55
70
|
const TRACK = "https://dpharness.com/api/track/event";
|
|
56
71
|
const DEFAULT_TAKE = 30;
|
|
@@ -235,8 +250,48 @@ function jobView() {
|
|
|
235
250
|
};
|
|
236
251
|
}
|
|
237
252
|
|
|
253
|
+
/* ------------------------------------------------------- post-install evidence */
|
|
254
|
+
/**
|
|
255
|
+
* Read the profile's own manifest.
|
|
256
|
+
*
|
|
257
|
+
* Verified path (2026-09-21, this machine): `~/.dsh/profiles/<profile>/package.json`
|
|
258
|
+
* holds both `dependencies` (what was resolved) and `dsh.profile.bundles`
|
|
259
|
+
* (what dsh actually loads). The bundle list is the stronger signal — a package
|
|
260
|
+
* can sit in node_modules and still not be loaded.
|
|
261
|
+
*
|
|
262
|
+
* Returns null when the file is unreadable, and callers must propagate that as
|
|
263
|
+
* `null` (unknown) rather than `false` (no) — see buildTrackPayload's note on
|
|
264
|
+
* why "unknown" and "no" must stay distinguishable.
|
|
265
|
+
*
|
|
266
|
+
* No DSH_HOME override here on purpose: that variable is not something this
|
|
267
|
+
* plugin has verified dsh honours, and inventing an env knob would make the
|
|
268
|
+
* probe silently report "unknown" for anyone whose layout differs.
|
|
269
|
+
*/
|
|
270
|
+
function profileManifest() {
|
|
271
|
+
const dir = path.join(os.homedir(), ".dsh", "profiles", PROFILE);
|
|
272
|
+
try {
|
|
273
|
+
return JSON.parse(fs.readFileSync(path.join(dir, "package.json"), "utf8"));
|
|
274
|
+
} catch (error) {
|
|
275
|
+
return null;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/** { dep, bundled } — each true / false / null(unknown). */
|
|
280
|
+
export function pkgState(pkg, manifest = profileManifest()) {
|
|
281
|
+
if (manifest === null || typeof manifest !== "object") return { dep: null, bundled: null };
|
|
282
|
+
const deps = manifest.dependencies && typeof manifest.dependencies === "object" ? manifest.dependencies : null;
|
|
283
|
+
const profile = manifest.dsh && manifest.dsh.profile ? manifest.dsh.profile : null;
|
|
284
|
+
const bundles = profile && Array.isArray(profile.bundles) ? profile.bundles : null;
|
|
285
|
+
return {
|
|
286
|
+
dep: deps === null ? null : Object.prototype.hasOwnProperty.call(deps, pkg),
|
|
287
|
+
bundled: bundles === null ? null : bundles.includes(pkg),
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
|
|
238
291
|
/** key -> { at: epochMs, value: { count, plugins } } */
|
|
239
292
|
const cache = new Map();
|
|
293
|
+
/** /api/best 单键缓存(榜单每月只重算一次,5 分钟缓存足够) */
|
|
294
|
+
let bestCache = { at: 0, value: null };
|
|
240
295
|
let eventWindow = { startedAt: 0, count: 0 };
|
|
241
296
|
|
|
242
297
|
/**
|
|
@@ -411,6 +466,18 @@ function parseQuery(req) {
|
|
|
411
466
|
return params;
|
|
412
467
|
}
|
|
413
468
|
|
|
469
|
+
/**
|
|
470
|
+
* Raw query access for routes with their own parameter set.
|
|
471
|
+
*
|
|
472
|
+
* Do NOT reuse parseQuery() outside search/best: it is a **whitelist** and only
|
|
473
|
+
* emits q/take/sort, so any other parameter silently reads as empty
|
|
474
|
+
* (measured 2026-09-21 — the postinstall route got pkg="" from `?pkg=…` until
|
|
475
|
+
* it stopped sharing that helper).
|
|
476
|
+
*/
|
|
477
|
+
function readParams(req) {
|
|
478
|
+
return new URL(req.url || "/", "http://127.0.0.1").searchParams;
|
|
479
|
+
}
|
|
480
|
+
|
|
414
481
|
async function fetchCatalog(params) {
|
|
415
482
|
const key = params.toString();
|
|
416
483
|
const now = Date.now();
|
|
@@ -441,9 +508,59 @@ async function fetchCatalog(params) {
|
|
|
441
508
|
}
|
|
442
509
|
}
|
|
443
510
|
|
|
444
|
-
|
|
511
|
+
/**
|
|
512
|
+
* 「分类精选」榜单(站点 /api/best,2026-09-18 新增的只读接口)。
|
|
513
|
+
*
|
|
514
|
+
* 与 fetchCatalog 的关系:两者都是站点的策展/目录数据,**条目一律走同一个 slim()**,
|
|
515
|
+
* 否则卡片会出现两套字段口径(本站已经栽过一次:命令口径不一致)。
|
|
516
|
+
* 唯一补充是 `category`:上游 /api/best 只给大类 key 在分组结构里,
|
|
517
|
+
* 条目本身没有 Plugin.category,故把所在大类的 key 注入每条,卡片才能显示正确分类。
|
|
518
|
+
*/
|
|
519
|
+
async function fetchBest() {
|
|
445
520
|
const now = Date.now();
|
|
446
|
-
if (now -
|
|
521
|
+
if (bestCache.value && now - bestCache.at < CACHE_TTL_MS) {
|
|
522
|
+
return { ...bestCache.value, cached: true, fetchedAt: bestCache.at };
|
|
523
|
+
}
|
|
524
|
+
const controller = new AbortController();
|
|
525
|
+
const timer = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS);
|
|
526
|
+
try {
|
|
527
|
+
const response = await fetch(BEST_UPSTREAM, {
|
|
528
|
+
headers: { accept: "application/json", "user-agent": `dsh-dpharness/${VERSION}` },
|
|
529
|
+
signal: controller.signal,
|
|
530
|
+
});
|
|
531
|
+
if (!response.ok) throw new Error(`upstream HTTP ${response.status}`);
|
|
532
|
+
const body = await response.json();
|
|
533
|
+
const categories = (Array.isArray(body && body.categories) ? body.categories : []).map((cat) => ({
|
|
534
|
+
key: cat.key,
|
|
535
|
+
label: cat.label,
|
|
536
|
+
count: cat.count,
|
|
537
|
+
subs: (Array.isArray(cat.subs) ? cat.subs : []).map((sub) => ({
|
|
538
|
+
key: sub.key,
|
|
539
|
+
label: sub.label,
|
|
540
|
+
summary: sub.summary || "",
|
|
541
|
+
items: (Array.isArray(sub.items) ? sub.items : []).map((item) => ({
|
|
542
|
+
...slim({ ...item, category: cat.key }),
|
|
543
|
+
// 名次与上榜理由是「为什么是它」的依据,不能丢
|
|
544
|
+
rank: typeof item.rank === "number" ? item.rank : null,
|
|
545
|
+
reason: typeof item.reason === "string" ? item.reason : "",
|
|
546
|
+
})),
|
|
547
|
+
})),
|
|
548
|
+
}));
|
|
549
|
+
const value = {
|
|
550
|
+
month: body && typeof body.month === "string" ? body.month : null,
|
|
551
|
+
total: typeof (body && body.total) === "number" ? body.total : 0,
|
|
552
|
+
categories,
|
|
553
|
+
// rank 越靠前的越该被看见,这里按小类聚合但保持接口给的顺序(口径与页面一致)
|
|
554
|
+
};
|
|
555
|
+
bestCache = { at: Date.now(), value };
|
|
556
|
+
return { ...value, cached: false, fetchedAt: Date.now() };
|
|
557
|
+
} finally {
|
|
558
|
+
clearTimeout(timer);
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
function withinEventBudget() {
|
|
563
|
+
const now = Date.now(); if (now - eventWindow.startedAt > EVENT_WINDOW_MS) {
|
|
447
564
|
eventWindow = { startedAt: now, count: 0 };
|
|
448
565
|
}
|
|
449
566
|
eventWindow.count += 1;
|
|
@@ -489,7 +606,23 @@ function buildTrackPayload(input) {
|
|
|
489
606
|
const parts = [action];
|
|
490
607
|
if (Number.isFinite(detail.length)) parts.push("len=" + Number(detail.length));
|
|
491
608
|
if (Number.isFinite(detail.results)) parts.push("hits=" + Number(detail.results));
|
|
492
|
-
|
|
609
|
+
// `via` 记录动作发生在哪条路径上(footer/overlay/local/market);
|
|
610
|
+
// 旧版 open 事件用的字段名是 `scope`,保留兼容,避免同一含义两个键。
|
|
611
|
+
const via = detail.via || detail.scope;
|
|
612
|
+
if (via) parts.push("via=" + clean(via, 12));
|
|
613
|
+
// `why` 是**闭集枚举**(market_http / busy / timeout / cli_exit …),
|
|
614
|
+
// 不是错误原文:原文可能含本地路径与包名,既超长又不可聚合。
|
|
615
|
+
if (detail.why) parts.push("why=" + clean(detail.why, 24));
|
|
616
|
+
// 布尔量只在**明确知道**时才写入(调用方不传即省略)。
|
|
617
|
+
// 省略 = 未知,与 `=0`(明确为否)必须在数据层可区分 —— 否则「查不到」
|
|
618
|
+
// 会被统计成一个具体的否定结论。
|
|
619
|
+
for (const flag of ["restarted", "bundled", "dep"]) {
|
|
620
|
+
if (typeof detail[flag] === "boolean") parts.push(flag + "=" + (detail[flag] ? 1 : 0));
|
|
621
|
+
}
|
|
622
|
+
// 版本号由 host 统一附加(客户端读不到 package.json)。
|
|
623
|
+
// 这是「新埋点覆盖率」的唯一判据:老版本插件永远发不出新事件,
|
|
624
|
+
// 看板上的空值既可能是"没人做过"也可能是"老版本没上报",只有版本维能切开。
|
|
625
|
+
parts.push("v=" + VERSION);
|
|
493
626
|
value = parts.join(":").slice(0, 120);
|
|
494
627
|
}
|
|
495
628
|
|
|
@@ -504,6 +637,29 @@ function registerRoute(ctx, pathname, handler) {
|
|
|
504
637
|
}
|
|
505
638
|
|
|
506
639
|
export function apply(ctx) {
|
|
640
|
+
// 「分类精选」:站点 /best 专区的同源数据(月度策展,每小类 2~3 个)
|
|
641
|
+
registerRoute(ctx, "/api/dpharness/best", async (req, res) => {
|
|
642
|
+
if (req.method !== "GET") {
|
|
643
|
+
res.writeHead(405, { allow: "GET" });
|
|
644
|
+
res.end();
|
|
645
|
+
return;
|
|
646
|
+
}
|
|
647
|
+
try {
|
|
648
|
+
const result = await fetchBest();
|
|
649
|
+
sendJson(res, 200, {
|
|
650
|
+
ok: true,
|
|
651
|
+
source: `${SITE}/best`,
|
|
652
|
+
cached: result.cached,
|
|
653
|
+
fetchedAt: new Date(result.fetchedAt).toISOString(),
|
|
654
|
+
month: result.month,
|
|
655
|
+
total: result.total,
|
|
656
|
+
categories: result.categories,
|
|
657
|
+
});
|
|
658
|
+
} catch (error) {
|
|
659
|
+
sendJson(res, 502, { ok: false, error: String((error && error.message) || error) });
|
|
660
|
+
}
|
|
661
|
+
});
|
|
662
|
+
|
|
507
663
|
registerRoute(ctx, "/api/dpharness/search", async (req, res) => {
|
|
508
664
|
if (req.method !== "GET") {
|
|
509
665
|
res.writeHead(405, { allow: "GET" });
|
|
@@ -614,6 +770,42 @@ export function apply(ctx) {
|
|
|
614
770
|
sendJson(res, 202, { ok: true, target, profile: PROFILE, job: jobView() });
|
|
615
771
|
});
|
|
616
772
|
|
|
773
|
+
/**
|
|
774
|
+
* Post-install evidence for telemetry.
|
|
775
|
+
*
|
|
776
|
+
* The client leaves a pending marker when an install succeeds and asks here
|
|
777
|
+
* the next time the plugin is loaded. Both answers are computed host-side
|
|
778
|
+
* because neither can be self-reported: the client is the same JS before and
|
|
779
|
+
* after a restart, and it cannot see the profile's manifest.
|
|
780
|
+
*
|
|
781
|
+
* Read-only: no writes, no side effects, safe to call on every load.
|
|
782
|
+
*/
|
|
783
|
+
registerRoute(ctx, "/api/dpharness/postinstall", (req, res) => {
|
|
784
|
+
if (req.method !== "GET") {
|
|
785
|
+
res.writeHead(405, { allow: "GET" });
|
|
786
|
+
res.end();
|
|
787
|
+
return;
|
|
788
|
+
}
|
|
789
|
+
const params = readParams(req);
|
|
790
|
+
const pkg = String(params.get("pkg") || "").trim().slice(0, 214);
|
|
791
|
+
const via = String(params.get("via") || "").trim().slice(0, 12);
|
|
792
|
+
const at = Number(params.get("at"));
|
|
793
|
+
// restarted: true only when this process provably started after the install
|
|
794
|
+
// finished. null (not false) when the client sent no usable timestamp.
|
|
795
|
+
const restarted = Number.isFinite(at) && at > 0 ? STARTED_AT > at : null;
|
|
796
|
+
const state = TARGET_RE.test(pkg) ? pkgState(pkg) : { dep: null, bundled: null };
|
|
797
|
+
sendJson(res, 200, {
|
|
798
|
+
ok: true,
|
|
799
|
+
profile: PROFILE,
|
|
800
|
+
startedAt: STARTED_AT,
|
|
801
|
+
restarted,
|
|
802
|
+
pkg,
|
|
803
|
+
via,
|
|
804
|
+
dep: state.dep,
|
|
805
|
+
bundled: state.bundled,
|
|
806
|
+
});
|
|
807
|
+
});
|
|
808
|
+
|
|
617
809
|
registerRoute(ctx, "/api/dpharness/meta", (req, res) => {
|
|
618
810
|
if (req.method !== "GET") {
|
|
619
811
|
res.writeHead(405, { allow: "GET" });
|
|
@@ -628,10 +820,13 @@ export function apply(ctx) {
|
|
|
628
820
|
source: SITE,
|
|
629
821
|
upstream: UPSTREAM,
|
|
630
822
|
tracker: TRACK,
|
|
823
|
+
startedAt: STARTED_AT,
|
|
631
824
|
routes: [
|
|
632
825
|
"/api/dpharness/search",
|
|
826
|
+
"/api/dpharness/best",
|
|
633
827
|
"/api/dpharness/event",
|
|
634
828
|
"/api/dpharness/install",
|
|
829
|
+
"/api/dpharness/postinstall",
|
|
635
830
|
"/api/dpharness/meta",
|
|
636
831
|
],
|
|
637
832
|
events: Array.from(EVENT_ALLOWLIST),
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-dpharness",
|
|
3
|
-
"version": "0.3
|
|
4
|
-
"description": "Curated dpharness.com plugin catalog inside the DeepSeek Harness Web GUI: a conversation-view tab, a sidebar entry and a site-wide floating panel, with one-click install via dshmarket or the dsh CLI. Read-only catalog plus an opt-out telemetry relay.",
|
|
3
|
+
"version": "0.4.3",
|
|
4
|
+
"description": "Curated dpharness.com plugin catalog inside the DeepSeek Harness Web GUI: a conversation-view tab, a sidebar entry and a site-wide floating panel, with one-click install via dshmarket or the dsh CLI. Read-only catalog plus an opt-out telemetry relay covering the full install funnel.",
|
|
5
5
|
"author": "zhanghao3693 <zhanghao3693@qq.com>",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -30,6 +30,17 @@
|
|
|
30
30
|
},
|
|
31
31
|
"bundle": {
|
|
32
32
|
"patch": "./cordis.patch.yml"
|
|
33
|
+
},
|
|
34
|
+
"engines": {
|
|
35
|
+
"dsh": ">=0.1.0-rc.5"
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"peerDependencies": {
|
|
39
|
+
"@deepseek-ai/dsh": ">=0.1.0-rc.5"
|
|
40
|
+
},
|
|
41
|
+
"peerDependenciesMeta": {
|
|
42
|
+
"@deepseek-ai/dsh": {
|
|
43
|
+
"optional": true
|
|
33
44
|
}
|
|
34
45
|
},
|
|
35
46
|
"files": [
|