dsh-dpharness 0.4.1 → 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 +46 -0
- package/lib/client.js +118 -10
- package/lib/index.js +121 -3
- package/package.json +13 -2
package/README.md
CHANGED
|
@@ -60,22 +60,68 @@
|
|
|
60
60
|
- 目标包名过字符白名单校验;子进程环境会剥掉宿主的 safe-delete shim(否则 pnpm 清理临时文件被拦)。
|
|
61
61
|
- 失败时展示 pnpm 的错误码行(如 `[ERR_PNPM_FETCH_404] …`),而不是一堆进度日志。
|
|
62
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
|
+
|
|
63
102
|
## HTTP 路由(host 侧)
|
|
64
103
|
|
|
65
104
|
| 路由 | 说明 |
|
|
66
105
|
|---|---|
|
|
67
106
|
| `GET /api/dpharness/search?q=&take=&sort=stars` | 目录查询,字段裁剪后返回,按 `q+take+sort` 缓存 5 分钟 |
|
|
68
107
|
| `GET /api/dpharness/best` | 分类精选榜单(站点 `/api/best` 的代理 + 字段裁剪),缓存 5 分钟 |
|
|
108
|
+
| `GET /api/dpharness/postinstall?pkg=&via=&at=` | 安装后回执(只读:进程启动时间 + profile 加载清单) |
|
|
69
109
|
| `POST /api/dpharness/event` | 埋点代理 → `dpharness.com/api/track/event` |
|
|
70
110
|
| `POST /api/dpharness/install` | `{ pkg }`,spawn `dsh plugin add`;返回 202 + 任务启动 |
|
|
71
111
|
| `GET /api/dpharness/install` | 安装任务进度与结果 |
|
|
72
112
|
| `GET /api/dpharness/meta` | 版本、profile、路由清单、缓存与安装状态 |
|
|
73
113
|
|
|
114
|
+
> ⚠️ 改 host 路由时注意:`parseQuery()` 是 search/best 专用的**白名单**解析器,
|
|
115
|
+
> 只输出 `q/take/sort`。新路由自定义参数请用 `readParams()` ——
|
|
116
|
+
> 复用 `parseQuery()` 会让参数**静默读成空串**(实测踩过)。
|
|
117
|
+
|
|
74
118
|
## 隐私
|
|
75
119
|
|
|
76
120
|
- **不采集搜索关键词原文**,只上报动作、关键词长度与命中数。
|
|
121
|
+
- **不上报错误原文**,失败原因只发闭集枚举。
|
|
77
122
|
- 复制/安装命令的上报口径与站点一致(`copy_install` 的 value 为整条命令),
|
|
78
123
|
来源靠 `path=/dsh-plugin` 区分。
|
|
124
|
+
- 回执查询只读本机 profile 的清单文件,结果仅两个布尔量。
|
|
79
125
|
- 浮窗与页签底部都有**匿名统计开关**,可随时关闭。
|
|
80
126
|
- 埋点经本地 host 转发(站点端点不带 CORS 头),失败静默忽略,绝不影响操作。
|
|
81
127
|
|
package/lib/client.js
CHANGED
|
@@ -211,6 +211,9 @@ window.__ModuleLoader__.load({
|
|
|
211
211
|
隐私口径:不发送搜索关键词原文,只发长度与命中数;可整体关闭。 */
|
|
212
212
|
const TEL_KEY = "dph-hub-telemetry";
|
|
213
213
|
const VID_KEY = "dph-hub-vid";
|
|
214
|
+
/* 安装成功但还没验证的凭据(见 reportPostInstall)。
|
|
215
|
+
只放本地,不上报:重启前没有任何东西可以验证它。 */
|
|
216
|
+
const PENDING_KEY = "dph-hub-pending";
|
|
214
217
|
let telemetryOn = true;
|
|
215
218
|
try {
|
|
216
219
|
telemetryOn = localStorage.getItem(TEL_KEY) !== "0";
|
|
@@ -244,6 +247,57 @@ window.__ModuleLoader__.load({
|
|
|
244
247
|
}
|
|
245
248
|
}
|
|
246
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
|
+
|
|
247
301
|
/* --------------------------------------------------------------- installer */
|
|
248
302
|
/* 两条路径,安全优先:
|
|
249
303
|
① 复用已装的 dshmarket 的同源 HTTP 路由(免重启热挂载、可回滚);
|
|
@@ -284,17 +338,19 @@ window.__ModuleLoader__.load({
|
|
|
284
338
|
return fallback + "(HTTP " + (result ? result.status : "?") + ")";
|
|
285
339
|
}
|
|
286
340
|
|
|
341
|
+
/* why 是**闭集枚举**,不是错误原文 —— 原文含本地路径与包名,既不可聚合也会
|
|
342
|
+
把用户环境信息带出去。分类只回答「卡在哪一步」,够用来定位了。 */
|
|
287
343
|
async function pollMarketInstall(deadline) {
|
|
288
344
|
while (Date.now() < deadline) {
|
|
289
345
|
await sleep(INSTALL_POLL_MS);
|
|
290
346
|
const status = await getJson(MARKET_STATUS);
|
|
291
|
-
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") };
|
|
292
348
|
if (status.data.active === false && status.data.busy === false) {
|
|
293
|
-
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) };
|
|
294
350
|
return { ok: true, market: true };
|
|
295
351
|
}
|
|
296
352
|
}
|
|
297
|
-
return { ok: false, message: "timeout" };
|
|
353
|
+
return { ok: false, via: "market", why: "timeout", message: "timeout" };
|
|
298
354
|
}
|
|
299
355
|
|
|
300
356
|
async function pollLocalInstall(deadline) {
|
|
@@ -302,13 +358,13 @@ window.__ModuleLoader__.load({
|
|
|
302
358
|
await sleep(INSTALL_POLL_MS);
|
|
303
359
|
const status = await getJson(LOCAL_INSTALL);
|
|
304
360
|
const job = status.data && status.data.job;
|
|
305
|
-
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") };
|
|
306
362
|
if (job.active === false) {
|
|
307
363
|
if (job.code === 0) return { ok: true, market: false };
|
|
308
|
-
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) };
|
|
309
365
|
}
|
|
310
366
|
}
|
|
311
|
-
return { ok: false, message: "timeout" };
|
|
367
|
+
return { ok: false, via: "local", why: "timeout", message: "timeout" };
|
|
312
368
|
}
|
|
313
369
|
|
|
314
370
|
async function runInstall(item, t) {
|
|
@@ -324,8 +380,14 @@ window.__ModuleLoader__.load({
|
|
|
324
380
|
if (market.status === 200) {
|
|
325
381
|
done = await pollMarketInstall(deadline);
|
|
326
382
|
} else if (market.status === 400 || market.status === 404 || market.status === 0) {
|
|
383
|
+
/* 不在 dshmarket 的 curated registry 里 —— 这是预期路径,降级到本地 CLI,
|
|
384
|
+
不是失败,所以这里不埋点。 */
|
|
327
385
|
done = null;
|
|
328
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 });
|
|
329
391
|
setHub({ install: { active: false, target, phase: "failed", message: messageOf(market, t("install.failed")) } });
|
|
330
392
|
return;
|
|
331
393
|
}
|
|
@@ -334,6 +396,11 @@ window.__ModuleLoader__.load({
|
|
|
334
396
|
setHub({ install: { active: true, target, phase: "local", message: t("install.local") } });
|
|
335
397
|
const local = await postJson(LOCAL_INSTALL, { pkg: target });
|
|
336
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
|
+
});
|
|
337
404
|
setHub({ install: { active: false, target, phase: "failed", message: messageOf(local, t("install.failed")) } });
|
|
338
405
|
return;
|
|
339
406
|
}
|
|
@@ -347,7 +414,20 @@ window.__ModuleLoader__.load({
|
|
|
347
414
|
message: done.ok ? t(done.market ? "install.okMarket" : "install.okLocal") : done.message,
|
|
348
415
|
},
|
|
349
416
|
});
|
|
350
|
-
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
|
+
}
|
|
351
431
|
}
|
|
352
432
|
|
|
353
433
|
/** 仅在降级路径(改了 profile)后需要;/api/restart 由 dsh-restart 插件提供(POST)。 */
|
|
@@ -665,9 +745,16 @@ window.__ModuleLoader__.load({
|
|
|
665
745
|
disabled: restarting,
|
|
666
746
|
onClick: async () => {
|
|
667
747
|
setRestarting(true);
|
|
748
|
+
/* 点击即上报。结果不能在这里等 —— 成功的重启会掐断这个
|
|
749
|
+
请求,"重启成功"只能由下次加载时的 post_install 证明;
|
|
750
|
+
所以这里只记「谁按了」,不记「按了之后成没成」。 */
|
|
751
|
+
track("plugin_hub", { action: "restart_click", via: "local" });
|
|
668
752
|
const ok = await restartServer();
|
|
669
753
|
setRestarting(false);
|
|
670
|
-
if (!ok)
|
|
754
|
+
if (!ok) {
|
|
755
|
+
setRestartFailed(true);
|
|
756
|
+
track("plugin_hub", { action: "restart_failed", via: "local", why: "restart_http" });
|
|
757
|
+
}
|
|
671
758
|
},
|
|
672
759
|
}, t("install.restart"))
|
|
673
760
|
: null,
|
|
@@ -695,7 +782,18 @@ window.__ModuleLoader__.load({
|
|
|
695
782
|
runInstall(item, t);
|
|
696
783
|
},
|
|
697
784
|
}, t("install.confirm")),
|
|
698
|
-
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")),
|
|
699
797
|
]);
|
|
700
798
|
}
|
|
701
799
|
|
|
@@ -706,7 +804,10 @@ window.__ModuleLoader__.load({
|
|
|
706
804
|
type: "button",
|
|
707
805
|
disabled: busyElsewhere,
|
|
708
806
|
title: busyElsewhere ? t("install.busy") : item.pkg,
|
|
709
|
-
onClick: () =>
|
|
807
|
+
onClick: () => {
|
|
808
|
+
setConfirming(true);
|
|
809
|
+
track("plugin_hub", { action: "install_ask", via: "confirm" });
|
|
810
|
+
},
|
|
710
811
|
}, busyElsewhere ? t("install.busy") : t("install.action")),
|
|
711
812
|
h("span", { className: "dph_instHint", key: "pkg" }, item.pkg),
|
|
712
813
|
]);
|
|
@@ -1059,6 +1160,13 @@ window.__ModuleLoader__.load({
|
|
|
1059
1160
|
const t = ctx.locale.bind(NS);
|
|
1060
1161
|
const ui = makeUi(t);
|
|
1061
1162
|
|
|
1163
|
+
/* 插件被加载 = 一次心跳。它同时是「在用哪个版本」的唯一来源:
|
|
1164
|
+
老版本发不出新事件,看板上的空值必须能和「真没人做」区分开。
|
|
1165
|
+
(版本号由 host 在转发时统一附加。) */
|
|
1166
|
+
track("plugin_hub", { action: "hello" });
|
|
1167
|
+
/* 上一次安装的回执要到这一刻才能取(见 reportPostInstall)。 */
|
|
1168
|
+
reportPostInstall();
|
|
1169
|
+
|
|
1062
1170
|
ctx.slots.inject(
|
|
1063
1171
|
"conversation.view",
|
|
1064
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.4.
|
|
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.
|
|
@@ -236,6 +250,44 @@ function jobView() {
|
|
|
236
250
|
};
|
|
237
251
|
}
|
|
238
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
|
+
|
|
239
291
|
/** key -> { at: epochMs, value: { count, plugins } } */
|
|
240
292
|
const cache = new Map();
|
|
241
293
|
/** /api/best 单键缓存(榜单每月只重算一次,5 分钟缓存足够) */
|
|
@@ -414,6 +466,18 @@ function parseQuery(req) {
|
|
|
414
466
|
return params;
|
|
415
467
|
}
|
|
416
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
|
+
|
|
417
481
|
async function fetchCatalog(params) {
|
|
418
482
|
const key = params.toString();
|
|
419
483
|
const now = Date.now();
|
|
@@ -542,7 +606,23 @@ function buildTrackPayload(input) {
|
|
|
542
606
|
const parts = [action];
|
|
543
607
|
if (Number.isFinite(detail.length)) parts.push("len=" + Number(detail.length));
|
|
544
608
|
if (Number.isFinite(detail.results)) parts.push("hits=" + Number(detail.results));
|
|
545
|
-
|
|
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);
|
|
546
626
|
value = parts.join(":").slice(0, 120);
|
|
547
627
|
}
|
|
548
628
|
|
|
@@ -690,6 +770,42 @@ export function apply(ctx) {
|
|
|
690
770
|
sendJson(res, 202, { ok: true, target, profile: PROFILE, job: jobView() });
|
|
691
771
|
});
|
|
692
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
|
+
|
|
693
809
|
registerRoute(ctx, "/api/dpharness/meta", (req, res) => {
|
|
694
810
|
if (req.method !== "GET") {
|
|
695
811
|
res.writeHead(405, { allow: "GET" });
|
|
@@ -704,11 +820,13 @@ export function apply(ctx) {
|
|
|
704
820
|
source: SITE,
|
|
705
821
|
upstream: UPSTREAM,
|
|
706
822
|
tracker: TRACK,
|
|
823
|
+
startedAt: STARTED_AT,
|
|
707
824
|
routes: [
|
|
708
825
|
"/api/dpharness/search",
|
|
709
826
|
"/api/dpharness/best",
|
|
710
827
|
"/api/dpharness/event",
|
|
711
828
|
"/api/dpharness/install",
|
|
829
|
+
"/api/dpharness/postinstall",
|
|
712
830
|
"/api/dpharness/meta",
|
|
713
831
|
],
|
|
714
832
|
events: Array.from(EVENT_ALLOWLIST),
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-dpharness",
|
|
3
|
-
"version": "0.4.
|
|
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": [
|