dsh-zhihu-mini 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +30 -0
- package/NOTES.md +120 -0
- package/README.md +266 -2
- package/client.js +3654 -0
- package/cordis.patch.yml +11 -0
- package/icon.svg +14 -0
- package/index.js +1311 -0
- package/locale/en.json +100 -0
- package/locale/zh.json +100 -0
- package/package.json +69 -4
- package/qr.js +49 -0
- package/sanitize.js +366 -0
- package/store.js +347 -0
- package/trust.js +170 -0
- package/vendor/LICENSE.qrcode-generator +21 -0
- package/vendor/qrcode-generator.cjs +2297 -0
- package/zhihu.js +1040 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 dsh-zhihu-mini contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
Third-party attribution
|
|
26
|
+
|
|
27
|
+
The loopback trust-fence semantics in trust.js are adapted from the
|
|
28
|
+
dsh-bili-mini plugin (https://github.com/tuanzhanghao/dsh-bili-mini),
|
|
29
|
+
Copyright (c) tuanzhanghao, also released under the MIT License.
|
|
30
|
+
The icon is original artwork created for this project.
|
package/NOTES.md
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
# dsh-zhihu-mini — implementation notes
|
|
2
|
+
|
|
3
|
+
Internal notes for maintainers: architecture, contracts, and the deviation log against
|
|
4
|
+
`CONTRACT.md`. User-facing documentation lives in `README.md`.
|
|
5
|
+
|
|
6
|
+
## Layering
|
|
7
|
+
|
|
8
|
+
```
|
|
9
|
+
DSH Client (React, sidebar.panellist + main slot)
|
|
10
|
+
│ HTTP: /zhihu-mini/api/{hot,feed,search,question,login/status,login/cookie,panel}
|
|
11
|
+
│ SSE : /zhihu-mini/api/events (agent -> panel navigation)
|
|
12
|
+
▼
|
|
13
|
+
DSH Host (Node >= 20, ESM, zero dependencies)
|
|
14
|
+
│ trust fence -> route handler -> cache -> zhihu.js (fetch) -> api.zhihu.com
|
|
15
|
+
│ store.js (atomic JSON) under <package>/data/
|
|
16
|
+
▼
|
|
17
|
+
api.zhihu.com
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
- The panel is a React component registered into harness slots; there is no iframe and no
|
|
21
|
+
served HTML page.
|
|
22
|
+
- The client module registers a lazy factory through `window.__ModuleLoader__.load` and
|
|
23
|
+
takes React from `require('react')`. It imports no other DSH client package.
|
|
24
|
+
- Everything the Host registers is created inside `apply` under `ctx.effect` (routes, SSE
|
|
25
|
+
hub, tools) so uninstalling/disabling the plugin disposes it cleanly.
|
|
26
|
+
|
|
27
|
+
## Agent tools
|
|
28
|
+
|
|
29
|
+
`zhihu_panel`, `zhihu_hot`, `zhihu_feed`, `zhihu_search`, `zhihu_read`, `zhihu_open` —
|
|
30
|
+
registered with `ctx.tools.register` from `apply`. Each declares JSON-Schema parameters,
|
|
31
|
+
`timeoutMs`, `isConcurrencySafe`, `output.schema`, an `output.render` text projection and
|
|
32
|
+
a `presentCall` card. Tools work with the panel closed: they read the Host cache or fetch
|
|
33
|
+
fresh. `zhihu_open` reports `delivered:false` when no SSE subscriber is connected.
|
|
34
|
+
|
|
35
|
+
## Panel state / SSE
|
|
36
|
+
|
|
37
|
+
- The client debounces panel changes by 300 ms and `POST /api/panel` with a `PanelState`
|
|
38
|
+
snapshot; `selectionText` comes from the document selection inside answer bodies.
|
|
39
|
+
- `GET /api/events` is a plain Node `http` SSE stream: one `data:` line plus a blank line, a
|
|
40
|
+
`{"type":"ping"}` every 25 s, max 8 concurrent subscribers, cleanup on `close`.
|
|
41
|
+
- `zhihu_open` delivers `{"type":"open", view, questionId?, query?}` to every subscriber and
|
|
42
|
+
reports whether at least one delivery happened.
|
|
43
|
+
|
|
44
|
+
## Security model
|
|
45
|
+
|
|
46
|
+
- Every route passes the loopback trust fence (`trust.js`): loopback Host header, no
|
|
47
|
+
`Sec-Fetch-Site: cross-site`, same-origin `Origin`/`Referer` when present.
|
|
48
|
+
- Cookies live only in the Host data dir (`data/credentials.json`, atomic write, 0600 best-effort
|
|
49
|
+
on POSIX). The client never receives them.
|
|
50
|
+
- Answer HTML is sanitized on the Host with a tag/attribute allowlist; the client only ever
|
|
51
|
+
sees already-sanitized `contentHtml` plus a `contentText` projection.
|
|
52
|
+
- Error logging is redacted; no telemetry, no third-party relay.
|
|
53
|
+
|
|
54
|
+
## Scrolling ownership (regression note)
|
|
55
|
+
|
|
56
|
+
The harness gives a panel a fixed-height frame and clips it (its centre column is
|
|
57
|
+
`overflow: hidden`), so a panel that does not own a scroll container simply
|
|
58
|
+
overflows and the content below the fold is unreachable — the panel looked
|
|
59
|
+
non-scrollable. The root is now sized to that frame (`height/max-height: 100%`,
|
|
60
|
+
`min-height: 0`, `overflow: hidden`) and `.zhihu-mini-body` is the scroller
|
|
61
|
+
(`overflow-y: auto`). The header, tab row and account chip stay pinned, the reader
|
|
62
|
+
toolbar is `position: sticky; top: 0` so 返回 / 问 DSH stay reachable, and the toast
|
|
63
|
+
uses `position: sticky; bottom` so it stays inside the viewport.
|
|
64
|
+
|
|
65
|
+
Verified live over CDP: hot list body 642/1363 px (scrollable, scrollTop 0 → 400 with
|
|
66
|
+
the header still visible) and a 5-answer reader body 642/1281 px with the toolbar
|
|
67
|
+
pinned at its original offset after scrolling.
|
|
68
|
+
|
|
69
|
+
## Header layout + account sheet (regression note)
|
|
70
|
+
|
|
71
|
+
The tab row is a flex item of the panel column **and** a scroll container
|
|
72
|
+
(`overflow-x: auto`), which zeroes its automatic minimum height: the column
|
|
73
|
+
squeezed it to ~15px while the 32px tab buttons overflowed, so the underline cut
|
|
74
|
+
through the labels and the header looked broken. `flex: 0 0 auto; min-height: 33px`
|
|
75
|
+
pins the row; the header and the account chip are pinned the same way so a narrow
|
|
76
|
+
sidebar cannot compress them.
|
|
77
|
+
|
|
78
|
+
The account chip used to open the sign-in sheet as a replacement body, and a tab
|
|
79
|
+
click only changed `view` — the sheet stayed up, so the tabs looked dead. Now the
|
|
80
|
+
sheet closes on any tab click, the chip toggles it, and the sheet is an account
|
|
81
|
+
card: avatar, name, headline, 登录时间, 可用能力, 打开知乎主页 (from `url_token`),
|
|
82
|
+
关闭 and 退出. `/api/login/status` backfills `profileUrl` once for sessions stored
|
|
83
|
+
before that field existed.
|
|
84
|
+
|
|
85
|
+
## Reader restore guard (regression note)
|
|
86
|
+
|
|
87
|
+
The panel restores its view from the Host snapshot and, for `reader`, immediately
|
|
88
|
+
fetches that question. A snapshot holding an id Zhihu does not serve (a deleted
|
|
89
|
+
question, or a placeholder that leaked out of a test) therefore restored the whole
|
|
90
|
+
panel into "加载失败" with nothing but a retry — and, because the Host replayed the
|
|
91
|
+
snapshot on every SSE connect, it did so on every mount.
|
|
92
|
+
|
|
93
|
+
Three layers now prevent it:
|
|
94
|
+
|
|
95
|
+
1. `store.loadPanel()` refuses a snapshot the panel could not render: a `reader`
|
|
96
|
+
without an id of at least 8 digits, a `search` without a query, or an unknown
|
|
97
|
+
view degrade to `hot`.
|
|
98
|
+
2. The SSE opening frame replays `reader` only when this process served that
|
|
99
|
+
question recently (`questionCache`); otherwise it re-syncs to `hot`.
|
|
100
|
+
3. The client treats `not-found` specially: a question opened without a click
|
|
101
|
+
(restore, replayed command, refresh) falls back to the hot list with a toast,
|
|
102
|
+
and a clicked one shows "这个问题不存在或已被删除" with 返回热榜.
|
|
103
|
+
|
|
104
|
+
`tools/smoke-host.mjs` asserts layer 1 (placeholder snapshot → `hot`), and the
|
|
105
|
+
panel behaviour was verified live over CDP: mount → hot, real question → reader ok,
|
|
106
|
+
nonexistent id → hot + toast, no console errors.
|
|
107
|
+
|
|
108
|
+
The harness also sets `ZHIHU_MINI_DATA_DIR`; the data directory is resolved on
|
|
109
|
+
every use, so a test can never reset the real `data/` and sign the user out.
|
|
110
|
+
|
|
111
|
+
## Deviation log (against CONTRACT.md)
|
|
112
|
+
|
|
113
|
+
| Area | Contract | Delivered | Why |
|
|
114
|
+
|---|---|---|---|
|
|
115
|
+
| install step | run `plugin_manager install_bundle` | Installed through the same `pluginManager/installBundle` RPC the Electron app uses, invoked by the Team Lead over the authenticated bridge `POST /api/<ns>/<method>`; result `{stage:"enable", target:"dsh-zhihu-mini", enabled:true, application:"applied"}` | `plugin_manager` is not exposed in this session's tool list (call resolves to `tools.plugin_manager is not a function`), for the Lead as well. No profile file was hand-written by packaging. Details in `tools/e2e-report.md` §1. |
|
|
116
|
+
| bundle row | "insert row id zhihu-mini name dsh-zhihu-mini with config" | `id: zhihu-mini`, `name: 'dsh-zhihu-mini'`, `config: { feedSize: 20, cacheTtlMs: 60000 }` | Matches the task text, the panel id and the Host `Config` keys. |
|
|
117
|
+
| LICENSE / NOTES.md | contract assigns `plugin/NOTES.md` to packaging; no explicit LICENSE owner | both written by packaging | `package.json` declares MIT and lists LICENSE in `files`. |
|
|
118
|
+
| icon | original artwork, Zhihu blue | original SVG: gradient tile + speech bubble + three dots | No third-party artwork; literal colors are allowed for icon artwork only. |
|
|
119
|
+
|
|
120
|
+
(Update this table if the install or verification outcome changes.)
|
package/README.md
CHANGED
|
@@ -1,3 +1,267 @@
|
|
|
1
|
-
|
|
1
|
+
<div align="center">
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
<img src="./icon.svg" width="96" height="96" alt="ZhihuMini icon" />
|
|
4
|
+
|
|
5
|
+
# 知乎迷你 · ZhihuMini
|
|
6
|
+
|
|
7
|
+
**为 DeepSeek Harness 打造的知乎侧边栏**
|
|
8
|
+
|
|
9
|
+
热榜 · 推荐 · 搜索 · 问答阅读 · 面板状态 · Agent 工具 · 面板跳转 · 0 Token
|
|
10
|
+
|
|
11
|
+
</div>
|
|
12
|
+
|
|
13
|
+
不离开工作台,也能刷知乎。
|
|
14
|
+
|
|
15
|
+
> **非官方项目**:本项目是第三方插件,与知乎(北京智者天下科技有限公司)、DeepSeek、DSH 官方均无关联。
|
|
16
|
+
> 它只调用知乎公开的 Web 接口,不绕过登录、付费或风控,也不提供任何内容下载或破解能力。
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## 一眼看懂
|
|
21
|
+
|
|
22
|
+
```text
|
|
23
|
+
┌─ 知乎迷你 ───────────────────────────────────────────┐
|
|
24
|
+
│ 热榜 | 推荐 | 搜索 | 阅读 [刷新] [登录] │
|
|
25
|
+
│ │
|
|
26
|
+
│ ┌──────────────┐ ┌──────────────┐ │
|
|
27
|
+
│ │ 标题 │ │ 标题 │ │
|
|
28
|
+
│ │ 热度 · 回答数 │ │ 热度 · 回答数 │ │
|
|
29
|
+
│ └──────────────┘ └──────────────┘ │
|
|
30
|
+
│ │
|
|
31
|
+
│ 点卡片 → 阅读视图(问题 + 高赞回答) │
|
|
32
|
+
└──────────────────────────────────────────────────────┘
|
|
33
|
+
▲ SSE 面板状态 / 打开指令
|
|
34
|
+
│
|
|
35
|
+
DSH Agent(zhihu_panel / zhihu_hot / zhihu_read / zhihu_open …)
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
ZhihuMini 把知乎热榜、推荐流、搜索和问答阅读塞进 DSH 的侧边栏;
|
|
39
|
+
同时它把“你此刻在看什么”通过面板状态快照和 SSE 暴露给 DSH,
|
|
40
|
+
因此你可以直接对 DSH 说“总结一下我面板上这篇回答”,或者“帮我打开这个问题”。
|
|
41
|
+
|
|
42
|
+
## 简介
|
|
43
|
+
|
|
44
|
+
ZhihuMini 是一个面向 [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness) 的第三方侧边栏插件。
|
|
45
|
+
它注册在 DSH 的 `sidebar.panellist` 槽位,打开即可浏览热榜与推荐;点击卡片进入阅读视图,
|
|
46
|
+
渲染由 Host 侧白名单清洗过的回答正文。插件同时向同一份 Host 注册六个 Agent 工具,
|
|
47
|
+
让 DSH 能读取热榜、推荐、搜索、问题详情**以及当前面板状态**,并能通过 SSE 让面板跳转到指定视图。
|
|
48
|
+
|
|
49
|
+
整个插件运行在本地 DSH Host 中:登录 Cookie 只保存在本机,前端永远拿不到 Cookie 原文。
|
|
50
|
+
插件本身不调用任何 LLM API,浏览与阅读不消耗 DSH Token——只有当你**主动**让 DSH 讨论面板内容时,
|
|
51
|
+
才会消耗正常的对话 Token。
|
|
52
|
+
|
|
53
|
+
## 功能
|
|
54
|
+
|
|
55
|
+
| | 功能 | 说明 |
|
|
56
|
+
|---|---|---|
|
|
57
|
+
| 🔥 | 热榜 | 知乎热榜,卡片显示标题、热度、回答数 |
|
|
58
|
+
| ✨ | 推荐 | 推荐流,登录后为个性化推荐 |
|
|
59
|
+
| 🔍 | 搜索 | 关键词搜索问题/回答(需要登录) |
|
|
60
|
+
| 📖 | 阅读 | 问题详情 + 高赞回答,正文由 Host 清洗后渲染 |
|
|
61
|
+
| 🧠 | 面板状态 | 每次切换视图都会把当前状态(视图 / 问题 / 关键词 / 选中文本)上报给 Host |
|
|
62
|
+
| 🛠️ | Agent 工具 | 六个工具:`zhihu_panel` `zhihu_hot` `zhihu_feed` `zhihu_search` `zhihu_read` `zhihu_open` |
|
|
63
|
+
| 🧭 | 面板跳转 | `zhihu_open` 通过 SSE 让已打开的面板切到指定视图/问题 |
|
|
64
|
+
| 🔐 | 扫码登录 | 面板内直接出二维码,用知乎 App 扫一扫即可登录;也可粘贴 Cookie(整行 Cookie / 名称=值 / cURL 均可),凭据只存本机 |
|
|
65
|
+
| 💬 | 问 DSH | 阅读页一键把当前问题整理成提示词(复制到剪贴板或交给客户端机制) |
|
|
66
|
+
| 🌗 | 主题一致 | 只使用 `--dsw-alias-*` 主题变量,自动跟随明暗主题 |
|
|
67
|
+
|
|
68
|
+
## 安装
|
|
69
|
+
|
|
70
|
+
### 从 npm 安装(推荐)
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
dsh plugin --profile desktop add dsh-zhihu-mini
|
|
74
|
+
# 或者: dsh --profile web add dsh-zhihu-mini
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
桌面版也可以在 **插件 → 添加插件** 里直接输入包名 `dsh-zhihu-mini`。
|
|
78
|
+
安装后刷新页面(宿主代码变更需要完整重启一次),然后在侧边栏找到 **知乎迷你**。
|
|
79
|
+
|
|
80
|
+
### 从源码 / 本地目录安装(开发)
|
|
81
|
+
|
|
82
|
+
1. 确认 Node.js 20+(DSH 通常自带);
|
|
83
|
+
2. 在 DSH 会话中让 Agent 用 `plugin_manager` 的 `install_bundle` 安装本仓库的 `plugin` 目录:
|
|
84
|
+
|
|
85
|
+
```text
|
|
86
|
+
plugin_manager({ action: "install_bundle", target: "<repo>/plugin" })
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
3. 读取返回的 `application` / `warnings`:`applied` 表示已生效;`restart-required` 表示需要完整重启 DSH;
|
|
90
|
+
4. 刷新页面后在侧边栏找到 **知乎迷你**。
|
|
91
|
+
|
|
92
|
+
> 本包没有构建脚本、没有原生依赖、没有 `postinstall`;如果包管理器询问 `allowBuilds`,无需授权。
|
|
93
|
+
|
|
94
|
+
### 首次使用
|
|
95
|
+
|
|
96
|
+
热榜和推荐**无需登录**即可浏览。搜索与回答正文需要知乎登录:点面板右上角 **登录**,
|
|
97
|
+
用知乎 App 扫码,或粘贴浏览器里的 Cookie(详见下文)。
|
|
98
|
+
|
|
99
|
+
### 环境要求
|
|
100
|
+
|
|
101
|
+
- DSH 桌面版或 Web 版;
|
|
102
|
+
- Node.js 20+;
|
|
103
|
+
- 无需安装 npm 依赖,无需构建步骤;
|
|
104
|
+
- 能访问 `api.zhihu.com`(部分地区或网络环境可能不可达)。
|
|
105
|
+
|
|
106
|
+
## 使用
|
|
107
|
+
|
|
108
|
+
1. 在 DSH 侧边栏打开 **知乎迷你**;
|
|
109
|
+
2. **热榜** / **推荐** 直接浏览;点卡片进入 **阅读**;
|
|
110
|
+
3. 阅读视图顶部可看到问题标题、回答数、关注数;正文渲染清洗后的高赞回答;
|
|
111
|
+
4. 需要搜索时切到 **搜索** 标签,输入关键词回车(未登录会提示登录);
|
|
112
|
+
5. 点 **登录** → 优先点「用知乎 App 扫码登录」,用知乎 App 扫码确认;或按「或粘贴 Cookie」粘贴浏览器 Cookie(必须含 `z_c0`;`SESSIONID` 每个访客都有,不能证明已登录)。获取方法:浏览器登录 zhihu.com → F12 → Network → 任意 `api.zhihu.com` 请求 → Request Headers 里整行 Cookie,或右键 Copy as cURL;
|
|
113
|
+
6. 点 **退出** 删除本地 Cookie;
|
|
114
|
+
7. 阅读页的 **问 DSH** 会把当前问题整理成一段提示词:如果客户端提供了可用的用户消息入口就用它,否则复制到剪贴板并提示。
|
|
115
|
+
|
|
116
|
+
### 让 DSH 讨论面板内容
|
|
117
|
+
|
|
118
|
+
在对话里直接说:
|
|
119
|
+
|
|
120
|
+
- “我面板上现在是什么?” → DSH 调 `zhihu_panel`
|
|
121
|
+
- “总结一下我正在看的这个回答” → `zhihu_panel` 拿到 `selectionText` / `questionId`,再 `zhihu_read`
|
|
122
|
+
- “给我看看今天热榜前五” → `zhihu_hot`
|
|
123
|
+
- “打开热榜” / “打开问题 123456” → `zhihu_open`,面板收到 SSE 指令后跳转
|
|
124
|
+
|
|
125
|
+
### Agent 工具一览
|
|
126
|
+
|
|
127
|
+
| 工具 | 参数 | 返回 | 说明 |
|
|
128
|
+
|---|---|---|---|
|
|
129
|
+
| `zhihu_panel` | — | `{ view, questionId?, title?, query?, selectionText?, visibleItems?, loggedIn, updatedAt, hint }` | 用户此刻在面板上看到的内容 |
|
|
130
|
+
| `zhihu_hot` | `{ limit? }` | 热榜条目(标题 + 热度 + 回答数 + 链接) | 不需要登录 |
|
|
131
|
+
| `zhihu_feed` | `{ limit? }` | 推荐条目 | 登录后为个性化 |
|
|
132
|
+
| `zhihu_search` | `{ query, limit? }` | 搜索结果 | 需要登录 |
|
|
133
|
+
| `zhihu_read` | `{ questionId, answerLimit? }` | 问题元信息 + 高赞回答文本摘要 | |
|
|
134
|
+
| `zhihu_open` | `{ view, query?, questionId? }` | `{ delivered, view }` | 通过 SSE 驱动面板;没有面板连接时 `delivered:false` |
|
|
135
|
+
|
|
136
|
+
工具在面板关闭时也能用:它们读取 Host 缓存或现取。
|
|
137
|
+
|
|
138
|
+
## 数据与隐私
|
|
139
|
+
|
|
140
|
+
| 项目 | 实现 |
|
|
141
|
+
|---|---|
|
|
142
|
+
| Cookie 位置 | 仅本机插件数据目录(`$DSH_HOME/zhihu-mini/credentials.json`,通常是 `~/.dsh/zhihu-mini/`),不写前端 localStorage/sessionStorage |
|
|
143
|
+
| 前端可见性 | 前端只拿 `loggedIn` / 昵称 / 头像;永远拿不到 `z_c0` 等 Cookie 原文 |
|
|
144
|
+
| 权限 | POSIX 下数据目录 0700、Cookie 文件 0600(best-effort);Windows 交给用户目录 ACL |
|
|
145
|
+
| 网络范围 | 带 Cookie 的请求只发往 `*.zhihu.com` |
|
|
146
|
+
| 路由信任 | 所有 `/zhihu-mini` 路由校验回环 Host、拒绝跨站 `Sec-Fetch-Site`、校验同源 Origin/Referer |
|
|
147
|
+
| HTML 清洗 | 回答正文在 Host 侧白名单清洗(保留 p/br/strong/em/a/h1-h6/ul/ol/li/blockquote/code/pre/img/figure/figcaption/hr/table 等),去掉 script/style/on* |
|
|
148
|
+
| 日志 | 错误信息脱敏;不打印 Cookie |
|
|
149
|
+
| 退出登录 | 删除本地 Cookie 文件并清空缓存 |
|
|
150
|
+
| 遥测 | 无 |
|
|
151
|
+
|
|
152
|
+
> 路由信任栅栏只回答“请求是否来自本机页面”,不是身份认证。插件没有远程中转服务器,
|
|
153
|
+
> 所有请求只在本机 DSH Host 与知乎之间发生。
|
|
154
|
+
|
|
155
|
+
**发布前请确认凭据不在发布内容里**:`package.json` 的 `files` 白名单已排除数据目录,`npm pack` 里不会出现 `credentials.json`。
|
|
156
|
+
|
|
157
|
+
本地数据文件(`$DSH_HOME/zhihu-mini/`,按需创建;旧版的 `plugin/data/` 会在首次启动时自动迁移):
|
|
158
|
+
|
|
159
|
+
| 文件 | 内容 |
|
|
160
|
+
|---|---|
|
|
161
|
+
| `credentials.json` | Cookie 原文 + 解析后的 Cookie 映射 + 缓存的用户资料;**唯一保存 Cookie 的文件**,Best-effort 0600,任何路由都不会返回它 |
|
|
162
|
+
| `panel.json` | 最近一次面板快照(无密钥) |
|
|
163
|
+
| `cache.json` | 各缓存桶的最近响应(无密钥) |
|
|
164
|
+
|
|
165
|
+
状态放在 `$DSH_HOME` 而不是包目录,是因为插件安装后位于 `node_modules`,升级会替换整个目录——
|
|
166
|
+
放在里面等于每次更新都要重新登录。也可以用 `ZHIHU_MINI_DATA_DIR` 环境变量改到别处。
|
|
167
|
+
|
|
168
|
+
## 为什么是 0 Token
|
|
169
|
+
|
|
170
|
+
ZhihuMini 的浏览、刷新、搜索、阅读全部由本地 Host 直接请求知乎公开接口,不经过大模型:
|
|
171
|
+
|
|
172
|
+
- 不调用 LLM;
|
|
173
|
+
- 不需要 API Key;
|
|
174
|
+
- 不把阅读内容发送给任何模型服务;
|
|
175
|
+
- 只有你让 DSH 讨论面板内容时,才会像普通对话一样消耗上下文 Token。
|
|
176
|
+
|
|
177
|
+
## 面板状态与 SSE 协议
|
|
178
|
+
|
|
179
|
+
面板每次切换视图(300ms 防抖)都会 `POST /zhihu-mini/api/panel` 上报:
|
|
180
|
+
|
|
181
|
+
```ts
|
|
182
|
+
type PanelState = {
|
|
183
|
+
view: 'hot' | 'feed' | 'search' | 'reader'
|
|
184
|
+
query?: string
|
|
185
|
+
questionId?: string
|
|
186
|
+
title?: string
|
|
187
|
+
visibleItems?: { id: string, title: string }[]
|
|
188
|
+
selectionText?: string
|
|
189
|
+
answerId?: string
|
|
190
|
+
updatedAt: number
|
|
191
|
+
loggedIn?: boolean
|
|
192
|
+
}
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
Agent 工具 `zhihu_open` 通过 `GET /zhihu-mini/api/events`(SSE,`data: <json>`)下发:
|
|
196
|
+
|
|
197
|
+
```json
|
|
198
|
+
{ "type": "open", "view": "reader", "questionId": "123456" }
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
服务端每 25 秒发送 `{"type":"ping"}` 保活;最多 8 个并发订阅。
|
|
202
|
+
|
|
203
|
+
## 主要路由
|
|
204
|
+
|
|
205
|
+
所有路由都挂在 `/zhihu-mini` 前缀下:
|
|
206
|
+
|
|
207
|
+
| 方法 | 路径 | 说明 |
|
|
208
|
+
|---|---|---|
|
|
209
|
+
| GET | `/api/hot?limit=30&refresh=1` | 热榜 |
|
|
210
|
+
| GET | `/api/feed?limit=12&refresh=1` | 推荐 |
|
|
211
|
+
| GET | `/api/search?q=&offset=0&limit=20` | 搜索(需登录) |
|
|
212
|
+
| GET | `/api/question?id=&answerLimit=5` | 问题 + 回答 |
|
|
213
|
+
| GET | `/api/login/status` | 登录状态 |
|
|
214
|
+
| POST | `/api/login/cookie` | 保存并校验 Cookie |
|
|
215
|
+
| DELETE | `/api/login` | 退出 |
|
|
216
|
+
| GET | `/api/panel` | 读取面板状态 |
|
|
217
|
+
| POST | `/api/panel` | 上报面板状态 |
|
|
218
|
+
| GET | `/api/events` | SSE 指令流 |
|
|
219
|
+
|
|
220
|
+
登录相关接口在未登录时不返回 500,而是 HTTP 200 + `{ ok: false, code: 'login-required' }`,面板据此显示登录卡片。
|
|
221
|
+
|
|
222
|
+
## 已知限制
|
|
223
|
+
|
|
224
|
+
- 知乎接口、风控与 Cookie 有效期随时可能变化;失效时热榜/搜索会返回错误,需要重新登录;
|
|
225
|
+
- 搜索、个性化推荐与部分问题需要登录;匿名热榜通常可用;
|
|
226
|
+
- 正文以纯文本 + 白名单 HTML 呈现,不还原知乎的复杂组件(视频、公式、付费墙等不可见);
|
|
227
|
+
- 回答图片来自知乎 CDN,需要网络可访问;
|
|
228
|
+
- 面板状态是最近一次上报的快照,不是实时 DOM 镜像;
|
|
229
|
+
- 本插件不提供内容下载、去广告、DRM 或付费内容绕过。
|
|
230
|
+
|
|
231
|
+
## 项目结构
|
|
232
|
+
|
|
233
|
+
```text
|
|
234
|
+
plugin/
|
|
235
|
+
├── index.js Host 入口:路由、SSE、Agent 工具注册
|
|
236
|
+
├── zhihu.js 知乎接口封装(匿名 / Cookie 认证、x-zse-96 签名)
|
|
237
|
+
├── sanitize.js 白名单 HTML 清洗 + 纯文本投影
|
|
238
|
+
├── store.js 本地原子 JSON 持久化(登录、面板状态、缓存)
|
|
239
|
+
├── trust.js 回环信任栅栏
|
|
240
|
+
├── client.js 浏览器端 React 面板(ModuleLoader 工厂)
|
|
241
|
+
├── locale/zh.json 中文界面文案 + meta
|
|
242
|
+
├── locale/en.json 英文界面文案 + meta
|
|
243
|
+
├── icon.svg 图标(原创)
|
|
244
|
+
├── cordis.patch.yml bundle 补丁
|
|
245
|
+
├── package.json bundle 清单
|
|
246
|
+
├── NOTES.md 实现说明与偏差记录
|
|
247
|
+
└── LICENSE MIT
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
## 开发与验证
|
|
251
|
+
|
|
252
|
+
```bash
|
|
253
|
+
# 语法检查
|
|
254
|
+
npm run check --prefix plugin
|
|
255
|
+
|
|
256
|
+
# 静态 + 在线冒烟(在线部分需要 DSH 已启动并安装本插件)
|
|
257
|
+
bash tools/e2e.sh
|
|
258
|
+
bash tools/e2e.sh --static # 只做静态检查
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
## 致谢与许可
|
|
262
|
+
|
|
263
|
+
- 信任栅栏语义参考 [dsh-bili-mini](https://github.com/tuanzhanghao/dsh-bili-mini)(MIT,Copyright (c) tuanzhanghao);
|
|
264
|
+
- 图标为原创 SVG,无第三方素材;
|
|
265
|
+
- 本项目以 MIT 许可证发布,见 [LICENSE](./LICENSE)。
|
|
266
|
+
|
|
267
|
+
> 本项目不是知乎官方产品。使用前请阅读并遵守知乎的服务条款;抓取频率保持在人类浏览量级,不要用于批量采集。
|