dsh-zju-lecture-note 2.2.7 → 2.2.8

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/docs/technical.md CHANGED
@@ -5,8 +5,9 @@
5
5
 
6
6
  ## 1. 仓库结构与数据流
7
7
 
8
- 本仓库既是插件的**能力核心**,也是 **dsh 原生插件包的发布源**:Python 核心、MCP 服务器、
9
- 讲义 Skill,以及 dsh 用的 `package.json` / `cordis.patch.yml` / `lib/` 都在这里。
8
+ 本仓库既是插件的**能力核心**,也同时是两种入口的发布源:**dsh 原生插件包**与 **Agent Plugins 1.0
9
+ 通用包**。Python 核心、MCP 服务器、讲义 Skill,以及 dsh 用的 `package.json` / `cordis.patch.yml` / `lib/`
10
+ 和通用入口用的根 `plugin.json` / `mcp.json` 都在这里。
10
11
 
11
12
  ```text
12
13
  dsh-zju-lecture-note/
@@ -18,8 +19,10 @@ dsh-zju-lecture-note/
18
19
  │ ├── client.js # 浏览器半边:设置页 + 左栏「智云讲义」入口
19
20
  │ ├── tools.js # 生成物:dsh 工具定义
20
21
  │ └── tools.schema.json # 生成物:工具定义快照(供测试比对)
21
- ├── .minimax-plugin/plugin.json # MiniMax Code(MCode)插件清单
22
- ├── zju-lecture.mcp.json # MCP 服务器定义(stdio → node ./server.mjs)
22
+ ├── plugin.json # Agent Plugins 1.0 通用入口清单(组件位置固定在 skills/ 与 mcp.json)
23
+ ├── mcp.json # Agent Plugins 1.0 的 MCP 配置(stdio → node ./server.mjs)
24
+ ├── .minimax-plugin/plugin.json # 历史打包脚本使用的清单(tools/build_plugin.py)
25
+ ├── zju-lecture.mcp.json # 历史打包脚本使用的 MCP 定义(带 description / timeout)
23
26
  ├── server.mjs # 启动器:解析 Python 解释器并拉起 MCP 服务
24
27
  ├── mcp_server.py # MCP stdio 服务器(JSON-RPC 2.0,隐私边界在这里)
25
28
  ├── zju_lecture/ # 核心库(纯标准库)
@@ -94,11 +97,13 @@ dsh-zju-lecture-note/
94
97
  2. 浏览器打开用户给的课堂链接(仅 `https://*.zju.edu.cn`);用户在页面里完成 SSO / 2FA。
95
98
  3. 插件每 1.5s 通过 CDP `Storage.getCookies` 读取 Cookie,只保留课堂主机与
96
99
  `.zju.edu.cn` 父域(`_token` 所在),排除其他 ZJU 子域与相似域名。
97
- 4. 检测到可解析的 `_token` 后,`save_session()` 只保存 Cookie 头:
98
- Windows 用 DPAPI(`CryptProtectData`,绑定当前用户),macOS / Linux 用 0600 文件;
99
- 不保存账号密码。
100
- 5. 关闭浏览器,`zju_login` 把 Cookie 放进本进程缓存;Agent 重试字幕一次。
101
- 6. 服务端仍返回 401/403 时,`_forget_cookie("session")` 删除登录态与专用 profile,
100
+ 4. 检测到可解析的 `_token` 后,`save_session()` 只保存 Cookie 头,并且**只交给平台凭据库**:
101
+ Windows DPAPI(`CryptProtectData`)、macOS 登录钥匙串、Linux Secret Service(`secret-tool`);
102
+ 三者都不可用或 `ZJU_LOGIN_STORAGE=memory` 时只留在进程内存,不写文件。不保存账号密码。
103
+ 2.2.7 及更早版本在 POSIX 写下的明文 `session.bin` 会在首次读取时迁移并覆写删除。
104
+ 5. 关闭浏览器并删除 `login-profile`(浏览器那份 Cookie 副本),`zju_login` 把 Cookie 放进本进程缓存;
105
+ Agent 重试字幕一次。
106
+ 6. 服务端仍返回 401/403 时,`_forget_cookie("session")` 删除凭据项、旧文件与专用 profile,
102
107
  下次 `zju_login` 从真正的登录页开始,而不是重放死 Cookie。
103
108
 
104
109
  `clear=true` 删除登录态与独立浏览器 profile;无图形界面、未安装浏览器或策略禁用远程调试时,
@@ -109,9 +114,26 @@ dsh-zju-lecture-note/
109
114
  | 形态 | 载体 | 依赖 |
110
115
  | :--- | :--- | :--- |
111
116
  | dsh 原生插件 | 仓库根目录的 npm 包(`package.json` + `cordis.patch.yml` + `lib/`) | pnpm 装 peer;Python 3.9+;Typst 由插件自举 |
112
- | 标准 MCP + Skill | `server.mjs` 拉起 stdio MCP Server | PATH 上的 `node`;Python 3.9+ |
113
- | MiniMax Code 插件包 | `tools/build_plugin.py` 产出的 `dist/*.zip` | 同上 |
114
- | 命令行 | `python -m zju_lecture.cli` | Python 3.9+;`pypdf` 仅 PDF 课件需要 |
117
+ | Agent Plugins 1.0 通用包 | 仓库根的 `plugin.json` + `mcp.json` + `skills/` + `server.mjs` | PATH 上的 `node`;Python 3.9+ |
118
+
119
+ 对外只有这两个入口。两种补充手段不算独立入口:只认裸 MCP 的宿主直接抄根 `mcp.json` 的
120
+ `mcpServers` 段(把 `./server.mjs` 换成绝对路径);命令行用 `python -m zju_lecture.cli`
121
+ (Python 3.9+,`pypdf` 仅 PDF 课件需要)。`tools/build_plugin.py` 产出的 `dist/*.zip` 是历史
122
+ 打包脚本的 staged 产物,只含它自己的清单,根 `plugin.json` / `mcp.json` 不会混进去。
123
+
124
+ **通用入口的工作目录**:Agent Plugins 1.0 规定 `cwd` 省略时客户端**必须**以插件根为子进程工作目录,
125
+ 而 `zju_lecture/paths.py` 的解析顺序是 绝对路径 → `ZJU_WORKSPACE` → `PWD` → cwd,所以相对输出路径
126
+ 会落进安装目录。根 `mcp.json` 不写死 `ZJU_WORKSPACE`(用户工作区无法静态预知),由用户给绝对路径
127
+ 或自行补 env;dsh 链路不受影响,bridge 按会话工作区传 `ZJU_WORKSPACE` 与 cwd。根 `mcp.json` 也不用
128
+ `${PLUGIN_ROOT}` / `${PLUGIN_DATA}` 占位符——部分客户端不展开它们,`./server.mjs` 配合默认 cwd
129
+ 才是跨客户端写法。
130
+
131
+ **清单 schema 是封闭的**:`plugin.schema.json` 与 `mcp.schema.json` 都是 `additionalProperties: false`。
132
+ 根 `plugin.json` 只有 `$schema` / `name` 必填,`author` 必须是对象、`repository` 必须是字符串,
133
+ 没有 `icon` / `category` / `skills` / `mcpServers` 字段(组件位置固定:Skill 从 `skills/` 的直接子目录
134
+ 发现,MCP 从根 `mcp.json` 读)。根 `mcp.json` 的 stdio 项只允许 `type` / `command` / `args` / `env` / `cwd`,
135
+ 旧 `zju-lecture.mcp.json` 里的 `schemaVersion` / `description` / `timeout` 在这份 schema 下非法,
136
+ 所以两份文件并存、各自服务自己的入口。`tests/test_agent_plugins.py` 离线守这些约束。
115
137
 
116
138
  **Typst 自举**(v2.1.0):`zju_lecture/deps.py` 把「本机没装 Typst」从静默失败变成一次可解释的准备:
117
139
 
@@ -184,6 +206,10 @@ PATH 上的 `python3` / `python` / `py -3`。
184
206
  - `main` 占的是整列页面,页首要用 `calc(20px + var(--dsh-frame-top-clearance, 0px))` 留出
185
207
  窗口标题栏的高度,否则 Windows 上第一行会被标题栏压住。
186
208
  - 面板页把标题渲染成 `h1`(`asPage`),设置弹窗里仍是 `h2`(弹窗自己提供标题)。
209
+ - 四枚预设(省 Token / 复习模式 / 投影讲义 / 全功能)只是 `PRESET_SPECS` 里的批量写入;
210
+ 不保存「当前预设」状态。高亮由 `matchingPreset(moduleState(value))` 按 6 个子开关实时比较
211
+ 得出,所以点预设与手动拨到同样位置完全等价;任一开关不同就不高亮。选中态用
212
+ `.zju-preset.is-active` 的渐变底色 + 过渡,`aria-pressed` 同步。
187
213
 
188
214
  ## 3. 工具与开关分层
189
215
 
@@ -196,14 +222,16 @@ v2.0.1 起,「字幕 → 讲义 → PDF」主链路与投影、填空笔记等
196
222
  | **字幕主链路** | `zju_parse_url` / `zju_fetch_transcript` / `zju_extract_courseware` / `zju_check_note` / `zju_write_note`(含自动 PDF) / `zju_login` / `zju_doctor` | 字幕接口(先匿名,401/403 自动用本机登录态)+ 一键登录窗口 + 本地文件 + 可选 Typst | 始终开启 |
197
223
  | **填空笔记** | `zju_build_study_notes` + `scholia-notes` Skill | 本机 Typst | 关闭(`enableStudyNotes`) |
198
224
  | **投影抓取** | `zju_fetch_slides` | 登录态 + 截图下载 + PDF 合成 | 关闭(`enableSlides`) |
199
- | **投影插图** | (`zju_fetch_slides` 的子开关) | 依赖投影抓取 | 关闭(`embedSlideImages`) |
225
+ | **投影来源** | (`slidesAsSource` 子开关) | 依赖投影抓取;写讲义前抓取并下载,把幻灯片内容与字幕对照写入 | 关闭 |
226
+ | **投影插图** | (`embedSlideImages` 子开关) | 依赖投影抓取;只决定是否插入 3–8 张关键页 | 关闭 |
200
227
  | **登录辅助** | `zju_get_video_url` / `zju_read_browser_cookie`;不影响字幕鉴权与 `zju_login` | 内存缓存 / `ZJU_COOKIE` / `ZJU_COOKIE_FILE` / 本机 Edge | 关闭(`enableLoginTools`) |
201
228
 
202
229
  - dsh 默认注册 **7** 个工具;`enableStudyNotes` +1、`enableSlides` +1、`enableLoginTools` +2,
203
- 全开 **11** 个。
230
+ 全开 **11** 个。`slidesAsSource` / `embedSlideImages` 都是投影的子开关,不新增工具。
204
231
  - **所有设置项都标 `.volatile()`**:dsh 只把 volatile 字段投影进配置表单,也只有这些字段能由
205
232
  设置页写入。2.2.7 起 `python` / `timeoutMs` / `registerSkill` 以及新增的 `typstPath` /
206
233
  `typstMirror` 也一并纳入,设置页才覆盖「工具、依赖、解释器」三层,而不是只有模块开关。
234
+ 2.2.8 增加 `slidesAsSource`(投影作为讲义来源),设置页共 12 个可写字段。
207
235
  - **`.volatile()` 字段是引用,不是布尔值**:dsh 把它们投影成 `{ get() }`,供插件在设置改动后
208
236
  读取新值。`lib/index.js` 的 `readSetting()` 统一解包;直接写 `config.enableSlides === true`
209
237
  会永远得到 `false`——2.1.1 修的「设置全开仍只有字幕」就是这个原因。新增设置项时务必走
@@ -223,8 +251,13 @@ v2.0.1 起,「字幕 → 讲义 → PDF」主链路与投影、填空笔记等
223
251
  - dsh 单独把 `zju_fetch_slides` / `zju_login` 的超时提高到 600s(下载截图 / 等待用户登录),
224
252
  其他工具仍用配置值。
225
253
  - 投影抓取与填空笔记互不依赖;登录辅助也与投影抓取解耦——投影工具会自己解析登录态。
226
- - 投影截图默认下载到 `<工作区>/ppt-assets/<sub_id>/`(已 gitignore),Agent 挑 **3–8 张**
227
- 关键页引用进讲义;接口没有文字层 / OCR,需要幻灯片原文时走 `zju_extract_courseware`。
254
+ - 投影有三个层次:`enableSlides` 只负责注册工具;`slidesAsSource` 决定是否把幻灯片作为
255
+ 讲义内容来源(写前必须抓取并下载一次);`embedSlideImages` 只决定是否插入 3–8 张关键页。
256
+ 两个子开关都关闭时,提示词仍要求写讲义前调用一次 `download=false` 核对清单,避免
257
+ 「打开了抓取开关但模型从不调用」。系统提示、Skill 附录和工具描述三处都写明顺序。
258
+ - 投影截图默认下载到 `<工作区>/ppt-assets/<sub_id>/`(已 gitignore);接口没有文字层 / OCR,
259
+ 需要幻灯片原文时走 `zju_extract_courseware`。模型不能读图时禁止臆造幻灯片文字,
260
+ 只在文末列截图索引。
228
261
  - 登录辅助默认关闭(dsh `enableLoginTools=false`),只影响视频直链与读 Cookie 工具,不影响字幕。
229
262
  `zju_login` 是核心工具,始终注册;字幕鉴权由字幕工具内部自动完成,不需模型先调读 Cookie 工具,
230
263
  也不新增工具或凭据参数。
@@ -243,13 +276,14 @@ v2.0.1 起,「字幕 → 讲义 → PDF」主链路与投影、填空笔记等
243
276
  | `ZJU_BACKUP_DIR` | `zju_check_note` / `zju_write_note` 的备份目录(默认系统临时目录) |
244
277
  | `ZJU_COOKIE` / `ZJU_COOKIE_FILE` | 显式本机登录态(优先级最高);存在且损坏时会挡住 `zju_login`,字幕仅在 HTTP 401/403 后自动使用 |
245
278
  | `ZJU_LOGIN_DIR` | `zju_login` 保存登录态与独立浏览器 profile 的目录(默认用户状态目录) |
279
+ | `ZJU_LOGIN_STORAGE` | `os`(默认,使用平台凭据库)/ `memory`(不落盘,仅进程内);没有可用凭据库时自动等价 `memory` |
246
280
  | `ZJU_BROWSER_BIN` | 指定登录窗口使用的浏览器可执行文件(默认 Edge → Chrome → Chromium) |
247
281
  | `ZJU_RENDER_PDF` | 默认 `0`(MCP);对应 dsh `renderPdf`(默认开) |
248
282
  | `ZJU_TYPST_AUTO_INSTALL` | 缺 Typst 时自动下载安装(默认 `1`;dsh 对应 `typstAutoInstall`) |
249
283
  | `ZJU_TYPST_BIN` | 指定已有 Typst 可执行文件(优先级最高;dsh 对应 `typstPath`) |
250
284
  | `ZJU_TYPST_MIRROR` | Typst 下载 URL 的镜像前缀,例如 `https://ghfast.top/`(dsh 对应 `typstMirror`) |
251
285
  | `ZJU_TYPST_CACHE` | 覆盖 Typst 缓存目录(默认用户缓存;测试与换盘时用) |
252
- | `ZJU_ENABLE_STUDY_NOTES` / `ZJU_ENABLE_SLIDES` / `ZJU_EMBED_SLIDES` / `ZJU_ENABLE_LOGIN_TOOLS` | 可选模块开关;最后一项只控制登录辅助工具,字幕鉴权不受影响 |
286
+ | `ZJU_ENABLE_STUDY_NOTES` / `ZJU_ENABLE_SLIDES` / `ZJU_SLIDES_SOURCE` / `ZJU_EMBED_SLIDES` / `ZJU_ENABLE_LOGIN_TOOLS` | 可选模块开关;`ZJU_SLIDES_SOURCE` 把投影作为讲义来源,`ZJU_EMBED_SLIDES` 只控制插图;最后一项只控制登录辅助工具,字幕鉴权不受影响 |
253
287
  | `ZJU_ALLOW_SENSITIVE_PATHS` | 显式关闭本地敏感路径保护(不推荐) |
254
288
 
255
289
  相对路径解析顺序:绝对路径 → `ZJU_WORKSPACE` → `PWD` → 服务进程 cwd;都找不到时,
@@ -483,10 +517,10 @@ python tools/check_note.py --fix 讲义.md # 自动修正机械问题
483
517
  依赖模块的镜像 URL 先由 `deps._redact_url()` 去掉 userinfo / query / fragment,
484
518
  bridge.js 转发 stderr 前再做一层 JS 脱敏(见 [SECURITY.md](../SECURITY.md) §7.4);
485
519
  7. 临时文件:只读打开优先;必须复制时连同 `-wal` / `-shm` 一起复制(刚登录的行可能还在 WAL 里),
486
- 权限 0600,读完覆写并删除;
487
- 8. 落盘:只有 `zju_login` 保存的登录态与独立浏览器 profile。登录态仅含 Cookie(不保存账号密码),
488
- Windows 为 DPAPI 密文;macOS / Linux 为 **0600 权限的明文文件**。
489
- `zju_login(clear=true)` 二者一起删除。CDP 只连接 `127.0.0.1` 随机端口,
520
+ 权限 0600,读完覆写并删除;读取前还会清理一小时前的残留副本(进程被强杀的可能遗留)。
521
+ 8. 落盘:登录态只写入平台凭据库(Windows DPAPI 密文文件 / macOS 钥匙串项 / Linux Secret Service 项,
522
+ 均为静态加密;无可用后端时只在内存)。独立浏览器 profile 在提取凭据后被删除。
523
+ `zju_login(clear=true)` 清除凭据项、旧明文文件与 profile。CDP 只连接 `127.0.0.1` 随机端口,
490
524
  端口与浏览器生命周期由工具管理;端口本身没有应用层认证,见 SECURITY.md 的已知边界。
491
525
 
492
526
  Cookie 不是正常工具参数:`zju_fetch_transcript` / `zju_fetch_slides` / `zju_get_video_url` 不接受 cookie 参数,
@@ -554,7 +588,7 @@ python tools/privacy_scan.py --tarball dist/*.tgz # npm 发布产物
554
588
 
555
589
  ```bash
556
590
  python -m unittest discover -s tests -v # 全部回归测试(含插件形态与隐私测试)
557
- python tools/build_plugin.py --validate # 按插件规范校验 MCode 包结构
591
+ python tools/build_plugin.py --validate # 校验历史打包脚本的产物结构
558
592
  python tools/check_note.py 讲义.md # 讲义渲染规范检查
559
593
  python tools/privacy_scan.py # 工作区隐私扫描
560
594
  python tools/privacy_scan.py --history # 连同 git 历史一起扫
@@ -611,7 +645,7 @@ npm view dsh-zju-lecture-note version # 验证
611
645
 
612
646
  - `package.json` 的 `prepublishOnly` 已挂「全量测试 + 隐私扫描」,测试红了发不出去。
613
647
  - registry 必须是 `https://registry.npmjs.org/`:国内镜像只读,`npm publish` 会 403。
614
- - 版本号不能覆盖:每次发布前必须 bump(九处对齐,见下节)。
648
+ - 版本号不能覆盖:每次发布前必须 bump(十处对齐,见下节)。
615
649
  - 发布后用户安装:`dsh plugin --profile desktop add dsh-zju-lecture-note`。
616
650
 
617
651
  `files` 字段是逐文件枚举的运行时清单(`lib/`、`mcp_server.py`、`zju_lecture/*.py`、`skills/`、
@@ -621,14 +655,16 @@ npm view dsh-zju-lecture-note version # 验证
621
655
  dsh 按 `peerDependencies` 校验运行时版本。若升级 dsh 后插件被跳过,请检查
622
656
  `@deepseek-ai/dsh-*` 的 peer 范围,或按 dsh 提示使用 `dsh plugin allow-version` 做精确版本豁免。
623
657
 
624
- ### MCode 插件包
658
+ ### 历史打包脚本产物
625
659
 
626
660
  `python tools/build_plugin.py --install --zip`;运行时文件清单在 `PACKAGE_FILES` / `PACKAGE_DIRS`,
627
- 新增文档文件时记得同步,否则装好的包里会出现断链。
661
+ 新增文档文件时记得同步,否则装好的包里会出现断链。产物只经由这两个清单收集,
662
+ 根 `plugin.json` / `mcp.json` **不会**混进去(`validate_package()` 会断言),因此它与通用入口互不遮蔽。
663
+ 通用 agent 客户端一律走仓库根的 Agent Plugins 1.0 清单,不需要这个脚本。
628
664
 
629
665
  ### 版本号
630
666
 
631
- 版本在**九处**对齐:`package.json`、`pyproject.toml`、`mcp_server.SERVER_VERSION`、
667
+ 版本在**十处**对齐:`package.json`、`pyproject.toml`、`mcp_server.SERVER_VERSION`、根 `plugin.json`、
632
668
  `.minimax-plugin/plugin.json`、`adapters/claude_code/plugin.json`、四个 Skill manifest
633
669
  (由 `tools/build_skill_manifest.py` 生成)。`tests/test_settings_v227.py` 会断言。
634
670
 
@@ -679,8 +715,10 @@ PY
679
715
  并给出删除路径。
680
716
  - **git 历史**:历史中已有的个人路径/密钥不会因为当前文件干净而消失;
681
717
  用 `python tools/privacy_scan.py --history` 检查,必要时重写历史并轮换凭证。
682
- - **形态别选错**:`tools/build_plugin.py` 产出的是 **MCode 插件包**;装进 dsh 用的是本仓库根目录的
683
- npm 包(`dsh plugin ... add`)。两者是两套安装方式,不要混。
718
+ - **入口别选错**:装进 dsh 用的是本仓库根目录的 npm 包(`dsh plugin ... add`,包名或 `github:` 均可);
719
+ 通用 agent 客户端用的是同一份仓库根的 Agent Plugins 1.0 清单(`plugin.json` + `mcp.json` + `skills/`)。
720
+ dsh 的安装器与 loader 只读 `package.json`,根清单对它是惰性行李,两条安装路径互不影响。
721
+ `tools/build_plugin.py` 的 zip 是历史产物,不是这两个入口之一。
684
722
  - **字幕可能需登录,请遵守平台条款**:只抓本人有权访问的回放,一次一节课,不要批量抓取。
685
723
 
686
724
  ## 12. 上游与归属
package/lib/bridge.js CHANGED
@@ -31,6 +31,7 @@ const DEFAULT_MAX_WORKSPACES = 2;
31
31
  const SPAWN_SETTING_KEYS = [
32
32
  "python",
33
33
  "enableSlides",
34
+ "slidesAsSource",
34
35
  "embedSlideImages",
35
36
  "enableStudyNotes",
36
37
  "enableLoginTools",
@@ -141,6 +142,12 @@ export class ZjuBridge {
141
142
  * pre-1.5.1 default (enabled), matching the Python core's MCP default.
142
143
  */
143
144
  this.enableSlides = options.enableSlides !== false;
145
+ /**
146
+ * Projection as a note source: the agent must fetch/download the
147
+ * screenshots before writing. Independent of `embedSlideImages`, which
148
+ * only decides whether key pages are inserted into the Markdown.
149
+ */
150
+ this.slidesAsSource = this.enableSlides && options.slidesAsSource === true;
144
151
  this.embedSlideImages = this.enableSlides && options.embedSlideImages === true;
145
152
  /** Optional fill-in study-note workflow; default true for direct users. */
146
153
  this.enableStudyNotes = options.enableStudyNotes !== false;
@@ -197,11 +204,13 @@ export class ZjuBridge {
197
204
  * @returns {boolean} whether anything actually changed
198
205
  */
199
206
  configure(options = {}) {
207
+ const enableSlides = options.enableSlides !== false;
200
208
  const next = {
201
209
  python: options.python || "",
202
210
  timeoutMs: options.timeoutMs || 120000,
203
- enableSlides: options.enableSlides !== false,
204
- embedSlideImages: options.embedSlideImages === true,
211
+ enableSlides,
212
+ slidesAsSource: enableSlides && options.slidesAsSource === true,
213
+ embedSlideImages: enableSlides && options.embedSlideImages === true,
205
214
  enableStudyNotes: options.enableStudyNotes !== false,
206
215
  enableLoginTools: options.enableLoginTools !== false,
207
216
  renderPdf: options.renderPdf === true,
@@ -324,6 +333,7 @@ export class ZjuBridge {
324
333
  // The plugin setting is authoritative for its own Python child; the
325
334
  // env vars remain the switches for plain MCP hosts.
326
335
  ZJU_ENABLE_SLIDES: this.enableSlides ? "1" : "0",
336
+ ZJU_SLIDES_SOURCE: this.slidesAsSource ? "1" : "0",
327
337
  ZJU_EMBED_SLIDES: this.embedSlideImages ? "1" : "0",
328
338
  ZJU_ENABLE_STUDY_NOTES: this.enableStudyNotes ? "1" : "0",
329
339
  ZJU_ENABLE_LOGIN_TOOLS: this.enableLoginTools ? "1" : "0",
package/lib/client.js CHANGED
@@ -17,6 +17,7 @@
17
17
  * - `renderPdf` auto-typeset the written note into a reading PDF
18
18
  * - `enableStudyNotes` fill-in study notes (+ scholia-notes Skill)
19
19
  * - `enableSlides` projected-slide capture
20
+ * - `slidesAsSource` read the captured slides as a note source
20
21
  * - `embedSlideImages` reference those screenshots in the note
21
22
  * - `enableLoginTools` video URL / Edge-cookie helpers
22
23
  * - `typstAutoInstall` install Typst on first use
@@ -52,6 +53,94 @@ window.__ModuleLoader__.load({
52
53
  'dsh-zju-lecture-note',
53
54
  ]
54
55
 
56
+ /**
57
+ * Presets are only bulk writes over the same switches the page edits.
58
+ *
59
+ * Nothing stores a "selected preset" id: the highlight below is derived by
60
+ * comparing the live config with these exact values. That is what makes
61
+ * "clicked a preset" and "set the same switches by hand" identical — both
62
+ * for the agent's prompt and for the highlighted button.
63
+ */
64
+ const PRESET_SPECS = [
65
+ {
66
+ id: 'token',
67
+ nameKey: 'presetToken',
68
+ hintKey: 'presetTokenHint',
69
+ values: {
70
+ renderPdf: true,
71
+ enableStudyNotes: false,
72
+ enableSlides: false,
73
+ slidesAsSource: false,
74
+ embedSlideImages: false,
75
+ enableLoginTools: false,
76
+ },
77
+ },
78
+ {
79
+ id: 'study',
80
+ nameKey: 'presetStudy',
81
+ hintKey: 'presetStudyHint',
82
+ values: {
83
+ renderPdf: true,
84
+ enableStudyNotes: true,
85
+ enableSlides: false,
86
+ slidesAsSource: false,
87
+ embedSlideImages: false,
88
+ enableLoginTools: false,
89
+ },
90
+ },
91
+ {
92
+ id: 'slides',
93
+ nameKey: 'presetSlides',
94
+ hintKey: 'presetSlidesHint',
95
+ values: {
96
+ renderPdf: true,
97
+ enableStudyNotes: false,
98
+ enableSlides: true,
99
+ slidesAsSource: true,
100
+ embedSlideImages: true,
101
+ enableLoginTools: false,
102
+ },
103
+ },
104
+ {
105
+ id: 'full',
106
+ nameKey: 'presetFull',
107
+ hintKey: 'presetFullHint',
108
+ values: {
109
+ renderPdf: true,
110
+ enableStudyNotes: true,
111
+ enableSlides: true,
112
+ slidesAsSource: true,
113
+ embedSlideImages: true,
114
+ enableLoginTools: true,
115
+ },
116
+ },
117
+ ]
118
+
119
+ /**
120
+ * The same normalisation the Host and Python core apply: a missing
121
+ * `renderPdf` means on, optional modules mean off, and the projection
122
+ * sub-switches are inert unless `enableSlides` is on.
123
+ */
124
+ function moduleState(value) {
125
+ const enableSlides = value?.enableSlides === true
126
+ return {
127
+ renderPdf: value?.renderPdf !== false,
128
+ enableStudyNotes: value?.enableStudyNotes === true,
129
+ enableSlides,
130
+ slidesAsSource: enableSlides && value?.slidesAsSource === true,
131
+ embedSlideImages: enableSlides && value?.embedSlideImages === true,
132
+ enableLoginTools: value?.enableLoginTools === true,
133
+ }
134
+ }
135
+
136
+ /** The preset whose switch values exactly match the current config. */
137
+ function matchingPreset(value) {
138
+ const state = moduleState(value)
139
+ return PRESET_SPECS.find((preset) => (
140
+ Object.keys(preset.values).every((key) => state[key] === preset.values[key])
141
+ )) || null
142
+ }
143
+
55
144
  const en = {
56
145
  sectionTitle: 'ZJU classroom lecture notes',
57
146
  panelLabel: 'ZJU notes',
@@ -70,9 +159,11 @@ window.__ModuleLoader__.load({
70
159
  presetsTitle: 'Presets',
71
160
  presetToken: 'Token saver',
72
161
  presetStudy: 'Study mode',
162
+ presetSlides: 'Slide notes',
73
163
  presetFull: 'Everything',
74
164
  presetTokenHint: 'PDF only',
75
165
  presetStudyHint: 'PDF + fill-in notes',
166
+ presetSlidesHint: 'Transcript + slides · no fill-in PDF',
76
167
  presetFullHint: 'All modules',
77
168
  coreTitle: 'Core pipeline',
78
169
  coreBadge: 'Always on',
@@ -103,6 +194,8 @@ window.__ModuleLoader__.load({
103
194
  slidesBadge: 'Needs login',
104
195
  slidesTitle2: 'Capture projected slides',
105
196
  slidesHint: 'Registers zju_fetch_slides. The transcript path is unaffected.',
197
+ sourceTitle: 'Write notes from projected slides',
198
+ sourceHint: 'Fetch and read the screenshots before writing; weave slide content into the note alongside the transcript.',
106
199
  imagesTitle: 'Reference screenshots in notes',
107
200
  imagesHint: 'Only when capture is on; adds download time and vision tokens.',
108
201
  dependency: 'Turn on capture first.',
@@ -148,9 +241,11 @@ window.__ModuleLoader__.load({
148
241
  presetsTitle: '一键配置',
149
242
  presetToken: '省 Token',
150
243
  presetStudy: '复习模式',
244
+ presetSlides: '投影讲义',
151
245
  presetFull: '全功能',
152
246
  presetTokenHint: '仅 PDF',
153
247
  presetStudyHint: 'PDF + 填空笔记',
248
+ presetSlidesHint: '字幕+投影 · 不做填空 PDF',
154
249
  presetFullHint: '全部模块',
155
250
  coreTitle: '核心链路',
156
251
  coreBadge: '始终开启',
@@ -181,6 +276,8 @@ window.__ModuleLoader__.load({
181
276
  slidesBadge: '需登录',
182
277
  slidesTitle2: '抓取投影截图',
183
278
  slidesHint: '注册 zju_fetch_slides;字幕链路不受影响。',
279
+ sourceTitle: '依据投影截图写讲义',
280
+ sourceHint: '写讲义前先抓取并阅读截图,把幻灯片内容与字幕一起写进讲义。',
184
281
  imagesTitle: '把截图引用进讲义',
185
282
  imagesHint: '仅在投影抓取开启时生效;增加下载时间与视觉 token。',
186
283
  dependency: '请先开启投影抓取。',
@@ -224,10 +321,13 @@ window.__ModuleLoader__.load({
224
321
  '.zju-arrow{font-size:12px;line-height:1;color:var(--dsw-alias-label-tertiary)}',
225
322
  '.zju-presets{display:flex;align-items:center;gap:8px;flex-wrap:wrap}',
226
323
  '.zju-presets-label{font-size:12px;color:var(--dsw-alias-label-secondary);margin-right:2px}',
227
- '.zju-preset{display:inline-flex;flex-direction:column;align-items:flex-start;gap:1px;padding:6px 10px;border:1px solid var(--dsw-alias-border-l2);border-radius:8px;background:transparent;cursor:pointer;font:inherit;color:var(--dsw-alias-label-primary);text-align:left}',
228
- '.zju-preset:hover:not(:disabled){border-color:color-mix(in srgb,var(--dsw-alias-brand-primary) 45%,var(--dsw-alias-border-l2));background:color-mix(in srgb,var(--dsw-alias-brand-primary) 5%,transparent)}',
324
+ '.zju-preset{display:inline-flex;flex-direction:column;align-items:flex-start;gap:1px;padding:6px 10px;border:1px solid var(--dsw-alias-border-l2);border-radius:8px;background-color:transparent;background-image:none;cursor:pointer;font:inherit;color:var(--dsw-alias-label-primary);text-align:left;transition:background-color .18s ease,border-color .18s ease,box-shadow .18s ease,color .18s ease,transform .18s ease}',
325
+ '.zju-preset:hover:not(:disabled){border-color:color-mix(in srgb,var(--dsw-alias-brand-primary) 45%,var(--dsw-alias-border-l2));background-color:color-mix(in srgb,var(--dsw-alias-brand-primary) 5%,transparent)}',
229
326
  '.zju-preset:disabled{opacity:.5;cursor:default}',
230
327
  '.zju-preset:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:2px}',
328
+ '.zju-preset.is-active{border-color:color-mix(in srgb,var(--dsw-alias-brand-primary) 55%,transparent);background-image:linear-gradient(135deg,color-mix(in srgb,var(--dsw-alias-brand-primary) 15%,transparent) 0%,color-mix(in srgb,var(--dsw-alias-brand-primary) 5%,transparent) 58%,color-mix(in srgb,var(--dsw-alias-brand-primary) 12%,transparent) 100%);box-shadow:0 0 0 1px color-mix(in srgb,var(--dsw-alias-brand-primary) 16%,transparent),0 5px 16px -11px color-mix(in srgb,var(--dsw-alias-brand-primary) 70%,transparent)}',
329
+ '.zju-preset.is-active .zju-preset-name{color:var(--dsw-alias-brand-primary);font-weight:600}',
330
+ '.zju-preset.is-active .zju-preset-hint{color:color-mix(in srgb,var(--dsw-alias-brand-primary) 68%,var(--dsw-alias-label-secondary))}',
231
331
  '.zju-preset-name{font-size:12px;line-height:17px;font-weight:500}',
232
332
  '.zju-preset-hint{font-size:10px;line-height:14px;color:var(--dsw-alias-label-tertiary)}',
233
333
  '.zju-groups{display:flex;flex-direction:column;border-top:1px solid color-mix(in srgb,var(--dsw-alias-label-tertiary) 26%,transparent)}',
@@ -515,8 +615,8 @@ window.__ModuleLoader__.load({
515
615
  return [state, run]
516
616
  }
517
617
 
518
- function Row({ t, title, hint, checked, disabled, onChange }) {
519
- return h('div', { className: 'zju-row' },
618
+ function Row({ t, title, hint, checked, disabled, onChange, child = false }) {
619
+ return h('div', { className: child ? 'zju-row is-child' : 'zju-row' },
520
620
  h('div', { className: 'zju-copy' },
521
621
  h('div', { className: 'zju-row-title' }, t(title)),
522
622
  h('div', { className: 'zju-row-hint' }, t(hint)),
@@ -579,7 +679,9 @@ window.__ModuleLoader__.load({
579
679
  const typstAutoInstall = value.typstAutoInstall !== false
580
680
  const enableStudyNotes = value.enableStudyNotes === true
581
681
  const enableLoginTools = value.enableLoginTools === true
682
+ const slidesAsSource = enableSlides && value.slidesAsSource === true
582
683
  const embedSlideImages = enableSlides && value.embedSlideImages === true
684
+ const activePreset = snapshot.status === 'ready' ? matchingPreset(value) : null
583
685
  const registerSkill = value.registerSkill !== false
584
686
  const python = typeof value.python === 'string' ? value.python : ''
585
687
  const typstPath = typeof value.typstPath === 'string' ? value.typstPath : ''
@@ -610,14 +712,9 @@ window.__ModuleLoader__.load({
610
712
 
611
713
  const update = (field, next) => runSave(() => settings.setField(field, next))
612
714
 
613
- const applyPreset = (preset) => runSave(async () => {
614
- const sets = preset === 'token'
615
- ? [['renderPdf', true], ['enableStudyNotes', false], ['enableSlides', false], ['embedSlideImages', false], ['enableLoginTools', false]]
616
- : preset === 'study'
617
- ? [['renderPdf', true], ['enableStudyNotes', true], ['enableSlides', false], ['embedSlideImages', false], ['enableLoginTools', false]]
618
- : [['renderPdf', true], ['enableStudyNotes', true], ['enableSlides', true], ['embedSlideImages', true], ['enableLoginTools', true]]
619
- return settings.setFields(sets)
620
- })
715
+ const applyPreset = (preset) => runSave(async () => (
716
+ settings.setFields(Object.entries(preset.values))
717
+ ))
621
718
 
622
719
  return h('div', { className: 'zju-settings-page', 'data-zju-settings': 'pipeline' },
623
720
  h('style', { 'data-plugin': '@plugin/dsh-zju-lecture-note' }, CSS),
@@ -644,18 +741,21 @@ window.__ModuleLoader__.load({
644
741
  note ? h('div', { className: 'zju-note', role: 'status' }, note) : null,
645
742
  h('div', { className: 'zju-presets' },
646
743
  h('span', { className: 'zju-presets-label' }, t('presetsTitle')),
647
- h('button', { type: 'button', className: 'zju-preset', disabled, onClick: () => applyPreset('token') },
648
- h('span', { className: 'zju-preset-name' }, t('presetToken')),
649
- h('span', { className: 'zju-preset-hint' }, t('presetTokenHint')),
650
- ),
651
- h('button', { type: 'button', className: 'zju-preset', disabled, onClick: () => applyPreset('study') },
652
- h('span', { className: 'zju-preset-name' }, t('presetStudy')),
653
- h('span', { className: 'zju-preset-hint' }, t('presetStudyHint')),
654
- ),
655
- h('button', { type: 'button', className: 'zju-preset', disabled, onClick: () => applyPreset('full') },
656
- h('span', { className: 'zju-preset-name' }, t('presetFull')),
657
- h('span', { className: 'zju-preset-hint' }, t('presetFullHint')),
658
- ),
744
+ PRESET_SPECS.map((preset) => {
745
+ const active = activePreset?.id === preset.id
746
+ return h('button', {
747
+ key: preset.id,
748
+ type: 'button',
749
+ className: active ? 'zju-preset is-active' : 'zju-preset',
750
+ 'data-preset': preset.id,
751
+ 'aria-pressed': active ? 'true' : 'false',
752
+ disabled,
753
+ onClick: () => applyPreset(preset),
754
+ },
755
+ h('span', { className: 'zju-preset-name' }, t(preset.nameKey)),
756
+ h('span', { className: 'zju-preset-hint' }, t(preset.hintKey)),
757
+ )
758
+ }),
659
759
  ),
660
760
  h('div', { className: 'zju-groups' },
661
761
  h(Group, {
@@ -747,18 +847,24 @@ window.__ModuleLoader__.load({
747
847
  disabled,
748
848
  onChange: (next) => update('enableSlides', next),
749
849
  }),
750
- h('div', { className: 'zju-row is-child' },
751
- h('div', { className: 'zju-copy' },
752
- h('div', { className: 'zju-row-title' }, t('imagesTitle')),
753
- h('div', { className: 'zju-row-hint' }, enableSlides ? t('imagesHint') : t('dependency')),
754
- ),
755
- h(Toggle, {
756
- checked: embedSlideImages,
757
- disabled: disabled || !enableSlides,
758
- label: t('imagesTitle'),
759
- onChange: (next) => update('embedSlideImages', next),
760
- }),
761
- ),
850
+ h(Row, {
851
+ t,
852
+ title: 'sourceTitle',
853
+ hint: enableSlides ? 'sourceHint' : 'dependency',
854
+ checked: slidesAsSource,
855
+ disabled: disabled || !enableSlides,
856
+ child: true,
857
+ onChange: (next) => update('slidesAsSource', next),
858
+ }),
859
+ h(Row, {
860
+ t,
861
+ title: 'imagesTitle',
862
+ hint: enableSlides ? 'imagesHint' : 'dependency',
863
+ checked: embedSlideImages,
864
+ disabled: disabled || !enableSlides,
865
+ child: true,
866
+ onChange: (next) => update('embedSlideImages', next),
867
+ }),
762
868
  ),
763
869
  h(Group, {
764
870
  title: t('loginTitle'),