dsh-zju-lecture-note 2.2.6 → 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/lib/tools.js CHANGED
@@ -1,5 +1,10 @@
1
1
  // 本文件由 tools/export_dsh_tools.py 自动生成,请勿手工编辑。
2
2
  // 数据源:mcp_server.py 的 TOOLS。
3
+ //
4
+ // 根级 additionalProperties 不在这里表达:dsh 的 defineTool 只接收
5
+ // 「属性名 -> schema」映射,没有根对象可以挂 strict。未知参数由
6
+ // mcp_server.handle_tool_call 在 dispatch 前强制拒绝("未知参数: …"),
7
+ // 两边不要各自维护一份白名单。
3
8
 
4
9
  export const ZJU_TOOLS = [
5
10
  {
@@ -55,7 +60,7 @@ export const ZJU_TOOLS = [
55
60
  },
56
61
  {
57
62
  "name": "zju_fetch_slides",
58
- "description": "(可选投影模块)抓取智云课堂投影 PPT 截图清单。search-ppt 返回的是投影截图,不是文字层/OCR;download=true 时下载截图并合成 PDF(省略时跟随 enableSlides / embedSlideImages,即 ZJU_ENABLE_SLIDES / ZJU_EMBED_SLIDES)。需要登录态(Cookie 含 _token,由服务端本地解析,不接受也不回显 Cookie)。抓不到时返回诊断,可降级为纯字幕总结。dsh 的 enableSlides 关闭时本工具不注册。",
63
+ "description": "(投影模块)抓取智云课堂投影 PPT 截图清单。search-ppt 返回的是投影截图,不是文字层/OCR;download=true 时下载截图并合成 PDF。当插件把投影作为讲义来源(slidesAsSource / ZJU_SLIDES_SOURCE=1)时,写讲义前应调用一次并传 download=true, confirm=true;download 省略时跟随 slidesAsSource / embedSlideImages(ZJU_SLIDES_SOURCE / ZJU_EMBED_SLIDES)。需要登录态(Cookie 含 _token,由服务端本地解析,不接受也不回显 Cookie)。抓不到时返回诊断,可降级为纯字幕总结。dsh 的 enableSlides(ZJU_ENABLE_SLIDES)关闭时本工具不注册。",
59
64
  "parameters": {
60
65
  "url_or_sub_id": {
61
66
  "description": "回放 URL(通常含 course_id)或 sub_id",
@@ -72,7 +77,7 @@ export const ZJU_TOOLS = [
72
77
  "type": "string"
73
78
  },
74
79
  "download": {
75
- "description": "是否下载截图到工作区并合成 PDF。省略时跟随插件设置(dsh 的 embedSlideImages / 环境变量 ZJU_EMBED_SLIDES,默认关闭);显式传 true/false 可覆盖。一节 1 小时的课通常有几十到几百张截图",
80
+ "description": "是否下载截图到工作区并合成 PDF。省略时跟随插件设置(slidesAsSource 或 embedSlideImages 开启即下载;环境变量 ZJU_SLIDES_SOURCE / ZJU_EMBED_SLIDES);显式传 true/false 可覆盖。一节 1 小时的课通常有几十到几百张截图",
76
81
  "type": "boolean"
77
82
  },
78
83
  "output_dir": {
@@ -83,6 +88,11 @@ export const ZJU_TOOLS = [
83
88
  "description": "是否折叠连续字节完全相同的截图(默认 true,只影响 PDF 页数,下载的原图都会保留)",
84
89
  "default": true,
85
90
  "type": "boolean"
91
+ },
92
+ "confirm": {
93
+ "description": "确认执行有副作用的操作(默认 false)。confirm=true 才批量下载截图(最多 2000 张)到工作区并合成 PDF;否则只返回清单,不写盘",
94
+ "default": false,
95
+ "type": "boolean"
86
96
  }
87
97
  }
88
98
  },
@@ -99,6 +109,11 @@ export const ZJU_TOOLS = [
99
109
  "description": "最多提取字符数(默认 10000 字符)",
100
110
  "default": 10000,
101
111
  "type": "integer"
112
+ },
113
+ "allow_outside_workspace": {
114
+ "description": "是否允许读取工作区之外的课件(默认 false)。显式设为 true 时仍拒绝凭据/浏览器数据/密钥文件,并在结果首行标注「已读取工作区外文件」",
115
+ "default": false,
116
+ "type": "boolean"
102
117
  }
103
118
  }
104
119
  },
@@ -124,7 +139,7 @@ export const ZJU_TOOLS = [
124
139
  },
125
140
  {
126
141
  "name": "zju_check_note",
127
- "description": "检查/修正已有讲义 Markdown 的公式与渲染规范(静态、不联网)。write_note 已自动检查,通常无需重复调用;只有手工改过文件时才用它修复。fix=true 自动修正机械问题并先备份;报告按问题类型聚合。pdf=true 时检查后重新排版一份同名 PDF。",
142
+ "description": "检查/修正已有讲义 Markdown 的公式与渲染规范(静态、不联网)。write_note 已自动检查,通常无需重复调用;只有手工改过文件时才用它修复。fix=true 自动修正机械问题并先备份;报告按问题类型聚合。pdf=true 时检查后重新排版一份同名 PDF。只处理工作区内的讲义。",
128
143
  "parameters": {
129
144
  "file_path": {
130
145
  "description": "讲义 Markdown 文件的绝对路径,或相对当前工作区的路径",
@@ -211,6 +226,11 @@ export const ZJU_TOOLS = [
211
226
  "description": "只清除本机保存的登录态与独立登录窗口配置,不打开窗口(默认 false)",
212
227
  "default": false,
213
228
  "type": "boolean"
229
+ },
230
+ "confirm": {
231
+ "description": "确认执行有副作用的操作(默认 false)。clear=true 时必须同时传 confirm=true 才会删除登录态与浏览器配置",
232
+ "default": false,
233
+ "type": "boolean"
214
234
  }
215
235
  }
216
236
  },
@@ -320,6 +340,11 @@ export const ZJU_TOOLS = [
320
340
  "description": "是否读取本机登录态检查可用性(默认否;不会回显凭据)",
321
341
  "default": false,
322
342
  "type": "boolean"
343
+ },
344
+ "confirm": {
345
+ "description": "确认执行有副作用的操作(默认 false)。install=true 时必须同时传 confirm=true 才会下载安装 Typst(约 20 MB)",
346
+ "default": false,
347
+ "type": "boolean"
323
348
  }
324
349
  }
325
350
  }
@@ -52,7 +52,7 @@
52
52
  },
53
53
  {
54
54
  "name": "zju_fetch_slides",
55
- "description": "(可选投影模块)抓取智云课堂投影 PPT 截图清单。search-ppt 返回的是投影截图,不是文字层/OCR;download=true 时下载截图并合成 PDF(省略时跟随 enableSlides / embedSlideImages,即 ZJU_ENABLE_SLIDES / ZJU_EMBED_SLIDES)。需要登录态(Cookie 含 _token,由服务端本地解析,不接受也不回显 Cookie)。抓不到时返回诊断,可降级为纯字幕总结。dsh 的 enableSlides 关闭时本工具不注册。",
55
+ "description": "(投影模块)抓取智云课堂投影 PPT 截图清单。search-ppt 返回的是投影截图,不是文字层/OCR;download=true 时下载截图并合成 PDF。当插件把投影作为讲义来源(slidesAsSource / ZJU_SLIDES_SOURCE=1)时,写讲义前应调用一次并传 download=true, confirm=true;download 省略时跟随 slidesAsSource / embedSlideImages(ZJU_SLIDES_SOURCE / ZJU_EMBED_SLIDES)。需要登录态(Cookie 含 _token,由服务端本地解析,不接受也不回显 Cookie)。抓不到时返回诊断,可降级为纯字幕总结。dsh 的 enableSlides(ZJU_ENABLE_SLIDES)关闭时本工具不注册。",
56
56
  "parameters": {
57
57
  "url_or_sub_id": {
58
58
  "description": "回放 URL(通常含 course_id)或 sub_id",
@@ -69,7 +69,7 @@
69
69
  "type": "string"
70
70
  },
71
71
  "download": {
72
- "description": "是否下载截图到工作区并合成 PDF。省略时跟随插件设置(dsh 的 embedSlideImages / 环境变量 ZJU_EMBED_SLIDES,默认关闭);显式传 true/false 可覆盖。一节 1 小时的课通常有几十到几百张截图",
72
+ "description": "是否下载截图到工作区并合成 PDF。省略时跟随插件设置(slidesAsSource 或 embedSlideImages 开启即下载;环境变量 ZJU_SLIDES_SOURCE / ZJU_EMBED_SLIDES);显式传 true/false 可覆盖。一节 1 小时的课通常有几十到几百张截图",
73
73
  "type": "boolean"
74
74
  },
75
75
  "output_dir": {
@@ -80,6 +80,11 @@
80
80
  "description": "是否折叠连续字节完全相同的截图(默认 true,只影响 PDF 页数,下载的原图都会保留)",
81
81
  "default": true,
82
82
  "type": "boolean"
83
+ },
84
+ "confirm": {
85
+ "description": "确认执行有副作用的操作(默认 false)。confirm=true 才批量下载截图(最多 2000 张)到工作区并合成 PDF;否则只返回清单,不写盘",
86
+ "default": false,
87
+ "type": "boolean"
83
88
  }
84
89
  }
85
90
  },
@@ -96,6 +101,11 @@
96
101
  "description": "最多提取字符数(默认 10000 字符)",
97
102
  "default": 10000,
98
103
  "type": "integer"
104
+ },
105
+ "allow_outside_workspace": {
106
+ "description": "是否允许读取工作区之外的课件(默认 false)。显式设为 true 时仍拒绝凭据/浏览器数据/密钥文件,并在结果首行标注「已读取工作区外文件」",
107
+ "default": false,
108
+ "type": "boolean"
99
109
  }
100
110
  }
101
111
  },
@@ -121,7 +131,7 @@
121
131
  },
122
132
  {
123
133
  "name": "zju_check_note",
124
- "description": "检查/修正已有讲义 Markdown 的公式与渲染规范(静态、不联网)。write_note 已自动检查,通常无需重复调用;只有手工改过文件时才用它修复。fix=true 自动修正机械问题并先备份;报告按问题类型聚合。pdf=true 时检查后重新排版一份同名 PDF。",
134
+ "description": "检查/修正已有讲义 Markdown 的公式与渲染规范(静态、不联网)。write_note 已自动检查,通常无需重复调用;只有手工改过文件时才用它修复。fix=true 自动修正机械问题并先备份;报告按问题类型聚合。pdf=true 时检查后重新排版一份同名 PDF。只处理工作区内的讲义。",
125
135
  "parameters": {
126
136
  "file_path": {
127
137
  "description": "讲义 Markdown 文件的绝对路径,或相对当前工作区的路径",
@@ -208,6 +218,11 @@
208
218
  "description": "只清除本机保存的登录态与独立登录窗口配置,不打开窗口(默认 false)",
209
219
  "default": false,
210
220
  "type": "boolean"
221
+ },
222
+ "confirm": {
223
+ "description": "确认执行有副作用的操作(默认 false)。clear=true 时必须同时传 confirm=true 才会删除登录态与浏览器配置",
224
+ "default": false,
225
+ "type": "boolean"
211
226
  }
212
227
  }
213
228
  },
@@ -317,6 +332,11 @@
317
332
  "description": "是否读取本机登录态检查可用性(默认否;不会回显凭据)",
318
333
  "default": false,
319
334
  "type": "boolean"
335
+ },
336
+ "confirm": {
337
+ "description": "确认执行有副作用的操作(默认 false)。install=true 时必须同时传 confirm=true 才会下载安装 Typst(约 20 MB)",
338
+ "default": false,
339
+ "type": "boolean"
320
340
  }
321
341
  }
322
342
  }
package/mcp.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "$schema": "https://agent-plugins.org/schemas/1.0.0/mcp.schema.json",
3
+ "mcpServers": {
4
+ "zju-lecture": {
5
+ "type": "stdio",
6
+ "command": "node",
7
+ "args": [
8
+ "./server.mjs"
9
+ ],
10
+ "env": {
11
+ "ZJU_ENABLE_SLIDES": "0",
12
+ "ZJU_SLIDES_SOURCE": "0",
13
+ "ZJU_EMBED_SLIDES": "0",
14
+ "ZJU_ENABLE_STUDY_NOTES": "0",
15
+ "ZJU_ENABLE_LOGIN_TOOLS": "0",
16
+ "ZJU_RENDER_PDF": "0",
17
+ "ZJU_TYPST_AUTO_INSTALL": "1"
18
+ }
19
+ }
20
+ }
21
+ }
package/mcp_server.py CHANGED
@@ -64,6 +64,7 @@ from zju_lecture.paths import (
64
64
  is_inside_workspace,
65
65
  note_target,
66
66
  primary_workspace,
67
+ require_workspace_path,
67
68
  resolve_path,
68
69
  )
69
70
  from zju_lecture.formatter import (
@@ -76,6 +77,7 @@ from zju_lecture.formatter import (
76
77
  transcript_quality,
77
78
  )
78
79
  from zju_lecture.security import (
80
+ COURSEWARE_EXTENSIONS,
79
81
  NOTE_EXTENSIONS,
80
82
  REDACTOR,
81
83
  LocalFileError,
@@ -96,7 +98,7 @@ from zju_lecture.study_notes import (
96
98
  )
97
99
 
98
100
  SERVER_NAME = "zju-lecture-mcp"
99
- SERVER_VERSION = "2.2.6"
101
+ SERVER_VERSION = "2.2.8"
100
102
  DEFAULT_TENANT = "112"
101
103
  DEFAULT_DOMAIN = "classroom.zju.edu.cn"
102
104
 
@@ -109,6 +111,10 @@ COOKIE_ENV = "ZJU_COOKIE"
109
111
  COOKIE_FILE_ENV = "ZJU_COOKIE_FILE"
110
112
  _MAX_COOKIE_FILE_BYTES = 64 * 1024
111
113
 
114
+ #: Sub-switch of the projection pipeline: use the screenshots as a *content
115
+ #: source* (read the slides, then write the note from transcript + slides).
116
+ #: Distinct from EMBED_SLIDES_ENV, which only controls Markdown illustrations.
117
+ SLIDES_SOURCE_ENV = "ZJU_SLIDES_SOURCE"
112
118
  #: Sub-switch of the projection pipeline: download projected-slide screenshots
113
119
  #: and reference them in the note. Off by default because it adds download
114
120
  #: time and vision tokens.
@@ -200,6 +206,16 @@ def available_tools() -> List[Dict[str, Any]]:
200
206
  return [tool for tool in TOOLS if tool["name"] not in hidden]
201
207
 
202
208
 
209
+ def slides_as_source_enabled() -> bool:
210
+ """Whether the host asked to use projected slides as a note source.
211
+
212
+ This is independent of the illustration sub-switch: a note can be written
213
+ from the slides without embedding any screenshot, and it can embed key
214
+ pages without treating the slide text as a source.
215
+ """
216
+ return str(os.environ.get(SLIDES_SOURCE_ENV, "")).strip().lower() in _TRUE_VALUES
217
+
218
+
203
219
  def embed_slides_enabled() -> bool:
204
220
  """Whether the host asked for projected-slide images in the note.
205
221
 
@@ -213,15 +229,21 @@ def slide_image_mode_text() -> str:
213
229
  """One sentence describing the note-illustration mode for this process."""
214
230
  if not slides_enabled():
215
231
  return "投影抓取已关闭,讲义只使用字幕与本地课件。"
232
+ if slides_as_source_enabled():
233
+ return (
234
+ "投影作为讲义来源:开启。写讲义前必须先抓一次投影(整节课只抓一次)并下载截图,"
235
+ "把幻灯片上的定义、公式、图例、例题与字幕对照写进正文;"
236
+ "模型不能查看本地图片时,只在文末列截图索引,不要臆造幻灯片文字。"
237
+ )
216
238
  if embed_slides_enabled():
217
239
  return (
218
- "讲义插图模式:开启。写讲义前默认抓一次投影(整节课只抓一次),"
240
+ "讲义插图模式:开启。写讲义前抓一次投影(整节课只抓一次),"
219
241
  "从返回的截图里挑 3–8 张关键页,按讲义所在目录的相对路径插入 Markdown;"
220
242
  "模型不能查看本地图片时,只在文末列截图索引,不要臆造截图内容。"
221
243
  )
222
244
  return (
223
- "讲义插图模式:关闭(默认,节省下载时间与 token)。"
224
- "用户明确要求插图时再调用 zju_fetch_slides(download=true)。"
245
+ "投影只启用抓取:写讲义前可调用一次 zju_fetch_slides(download=false) 核对清单,"
246
+ "不下载、不插图、不把截图当作内容来源。"
225
247
  )
226
248
 
227
249
 
@@ -258,6 +280,12 @@ def server_instructions() -> str:
258
280
  parts.append(
259
281
  "投影截图(可下载并合成 PDF)需要登录态(Cookie 需含 _token);"
260
282
  "投影抓取可用 ZJU_ENABLE_SLIDES=0 关闭。"
283
+ + (
284
+ "投影作为讲义来源已开启(ZJU_SLIDES_SOURCE=1):写讲义前先抓取一次并下载截图,"
285
+ "结合字幕与幻灯片内容写;不能看图时不要臆造幻灯片文字。"
286
+ if slides_as_source_enabled()
287
+ else ""
288
+ )
261
289
  )
262
290
  else:
263
291
  parts.append(
@@ -516,11 +544,14 @@ TOOLS: List[Dict[str, Any]] = [
516
544
  {
517
545
  "name": "zju_fetch_slides",
518
546
  "description": (
519
- "(可选投影模块)抓取智云课堂投影 PPT 截图清单。search-ppt 返回的是"
520
- "投影截图,不是文字层/OCR;download=true 时下载截图并合成 PDF(省略时跟随 "
521
- "enableSlides / embedSlideImages,即 ZJU_ENABLE_SLIDES / ZJU_EMBED_SLIDES)。"
547
+ "(投影模块)抓取智云课堂投影 PPT 截图清单。search-ppt 返回的是"
548
+ "投影截图,不是文字层/OCR;download=true 时下载截图并合成 PDF。"
549
+ "当插件把投影作为讲义来源(slidesAsSource / ZJU_SLIDES_SOURCE=1)时,"
550
+ "写讲义前应调用一次并传 download=true, confirm=true;download 省略时"
551
+ "跟随 slidesAsSource / embedSlideImages(ZJU_SLIDES_SOURCE / ZJU_EMBED_SLIDES)。"
522
552
  "需要登录态(Cookie 含 _token,由服务端本地解析,不接受也不回显 Cookie)。"
523
- "抓不到时返回诊断,可降级为纯字幕总结。dsh 的 enableSlides 关闭时本工具不注册。"
553
+ "抓不到时返回诊断,可降级为纯字幕总结。"
554
+ "dsh 的 enableSlides(ZJU_ENABLE_SLIDES)关闭时本工具不注册。"
524
555
  ),
525
556
  "inputSchema": {
526
557
  "type": "object",
@@ -546,7 +577,8 @@ TOOLS: List[Dict[str, Any]] = [
546
577
  "type": "boolean",
547
578
  "description": (
548
579
  "是否下载截图到工作区并合成 PDF。省略时跟随插件设置"
549
- "(dsh 的 embedSlideImages / 环境变量 ZJU_EMBED_SLIDES,默认关闭);"
580
+ "(slidesAsSource 或 embedSlideImages 开启即下载;"
581
+ "环境变量 ZJU_SLIDES_SOURCE / ZJU_EMBED_SLIDES);"
550
582
  "显式传 true/false 可覆盖。一节 1 小时的课通常有几十到几百张截图"
551
583
  ),
552
584
  },
@@ -565,6 +597,14 @@ TOOLS: List[Dict[str, Any]] = [
565
597
  ),
566
598
  "default": True,
567
599
  },
600
+ "confirm": {
601
+ "type": "boolean",
602
+ "description": (
603
+ "确认执行有副作用的操作(默认 false)。confirm=true 才批量下载截图"
604
+ "(最多 2000 张)到工作区并合成 PDF;否则只返回清单,不写盘"
605
+ ),
606
+ "default": False,
607
+ },
568
608
  },
569
609
  "required": ["url_or_sub_id"],
570
610
  },
@@ -590,6 +630,15 @@ TOOLS: List[Dict[str, Any]] = [
590
630
  "description": "最多提取字符数(默认 10000 字符)",
591
631
  "default": 10000,
592
632
  },
633
+ "allow_outside_workspace": {
634
+ "type": "boolean",
635
+ "description": (
636
+ "是否允许读取工作区之外的课件(默认 false)。"
637
+ "显式设为 true 时仍拒绝凭据/浏览器数据/密钥文件,"
638
+ "并在结果首行标注「已读取工作区外文件」"
639
+ ),
640
+ "default": False,
641
+ },
593
642
  },
594
643
  "required": ["file_path"],
595
644
  },
@@ -627,7 +676,7 @@ TOOLS: List[Dict[str, Any]] = [
627
676
  "检查/修正已有讲义 Markdown 的公式与渲染规范(静态、不联网)。"
628
677
  "write_note 已自动检查,通常无需重复调用;只有手工改过文件时才用它修复。"
629
678
  "fix=true 自动修正机械问题并先备份;报告按问题类型聚合。"
630
- "pdf=true 时检查后重新排版一份同名 PDF。"
679
+ "pdf=true 时检查后重新排版一份同名 PDF。只处理工作区内的讲义。"
631
680
  ),
632
681
  "inputSchema": {
633
682
  "type": "object",
@@ -744,6 +793,14 @@ TOOLS: List[Dict[str, Any]] = [
744
793
  "description": "只清除本机保存的登录态与独立登录窗口配置,不打开窗口(默认 false)",
745
794
  "default": False,
746
795
  },
796
+ "confirm": {
797
+ "type": "boolean",
798
+ "description": (
799
+ "确认执行有副作用的操作(默认 false)。clear=true 时必须同时传 "
800
+ "confirm=true 才会删除登录态与浏览器配置"
801
+ ),
802
+ "default": False,
803
+ },
747
804
  },
748
805
  },
749
806
  },
@@ -883,6 +940,14 @@ TOOLS: List[Dict[str, Any]] = [
883
940
  "description": "是否读取本机登录态检查可用性(默认否;不会回显凭据)",
884
941
  "default": False,
885
942
  },
943
+ "confirm": {
944
+ "type": "boolean",
945
+ "description": (
946
+ "确认执行有副作用的操作(默认 false)。install=true 时必须同时传 "
947
+ "confirm=true 才会下载安装 Typst(约 20 MB)"
948
+ ),
949
+ "default": False,
950
+ },
886
951
  },
887
952
  },
888
953
  },
@@ -1062,7 +1127,7 @@ _LOGIN_SOURCE_LABELS = {
1062
1127
  "cache": "进程内缓存",
1063
1128
  "env": "ZJU_COOKIE",
1064
1129
  "file": "ZJU_COOKIE_FILE",
1065
- "session": "zju_login 安全保存",
1130
+ "session": "zju_login 保存(加密)",
1066
1131
  "edge": "本机 Edge",
1067
1132
  }
1068
1133
 
@@ -1085,7 +1150,8 @@ def _login_status_text() -> List[str]:
1085
1150
  lines.append(
1086
1151
  " 本机保存的登录态: 存在"
1087
1152
  f"({summary.get('cookie_count', 0)} 条 Cookie,"
1088
- f"浏览器 {summary.get('browser') or '未知'})"
1153
+ f"浏览器 {summary.get('browser') or '未知'},"
1154
+ f"存储 {summary.get('storage') or '未知'})"
1089
1155
  )
1090
1156
  return lines
1091
1157
  action = COOKIE_FAILURE_ACTIONS.get(reason or "unknown", COOKIE_FAILURE_ACTIONS["unknown"])
@@ -1151,8 +1217,13 @@ def _doctor_report(install: bool, check_login: bool = False) -> str:
1151
1217
  + (f",保存于 {stamp}" if stamp else "")
1152
1218
  + ";不含账号密码)"
1153
1219
  )
1220
+ lines.append(f" 存储: {summary.get('storage') or '未知'}")
1154
1221
  else:
1155
1222
  lines.append("本机登录态: 未保存(需要时调用 zju_login 打开独立登录窗口)")
1223
+ if summary.get("backend"):
1224
+ lines.append(
1225
+ f" 存储: {summary.get('storage') or summary.get('backend')}"
1226
+ )
1156
1227
  login_ok, login_detail = login_available()
1157
1228
  lines.append(
1158
1229
  "登录窗口: " + ("可用(" + login_detail + ")" if login_ok else "不可用(" + login_detail + ")")
@@ -1226,13 +1297,11 @@ def _patch_draft(arguments: Dict[str, Any]) -> str:
1226
1297
  if not isinstance(raw_edits, list) or not raw_edits:
1227
1298
  return "错误: mode=patch 需要非空的 edits(每项 {old, new})"
1228
1299
 
1229
- resolved, tried = resolve_path(draft_path)
1230
- if resolved is None:
1231
- return f"错误: 找不到填空底稿: {draft_path}{describe_attempts(tried)}"
1232
- try:
1233
- resolved = guard_local_file(resolved, NOTE_EXTENSIONS, kind="填空底稿")
1234
- except LocalFileError as exc:
1235
- return f"错误: {exc}"
1300
+ resolved, path_error = require_workspace_path(
1301
+ draft_path, extensions=NOTE_EXTENSIONS, kind="填空底稿", write=True
1302
+ )
1303
+ if path_error:
1304
+ return f"错误: {path_error}"
1236
1305
  try:
1237
1306
  with open(resolved, "r", encoding="utf-8") as handle:
1238
1307
  draft_text = handle.read()
@@ -1472,7 +1541,13 @@ def _dispatch_tool(name: str, arguments: Dict[str, Any]) -> Any:
1472
1541
  _ensure_tool_enabled(name)
1473
1542
 
1474
1543
  if name == "zju_doctor":
1475
- return _doctor_report(bool(arguments.get("install")), bool(arguments.get("login")))
1544
+ install = bool(arguments.get("install"))
1545
+ if install and arguments.get("confirm") is not True:
1546
+ return (
1547
+ "该操作会下载并安装 Typst(约 20 MB,按固定 SHA256 校验);"
1548
+ "确认后以 confirm=true 重试。只想查看依赖状态时不要传 install=true。"
1549
+ )
1550
+ return _doctor_report(install, bool(arguments.get("login")))
1476
1551
 
1477
1552
  if name == "zju_parse_url":
1478
1553
  parsed = parse_lecture_url(str(arguments.get("url", "")))
@@ -1480,6 +1555,11 @@ def _dispatch_tool(name: str, arguments: Dict[str, Any]) -> Any:
1480
1555
 
1481
1556
  if name == "zju_login":
1482
1557
  if arguments.get("clear"):
1558
+ if arguments.get("confirm") is not True:
1559
+ return (
1560
+ "该操作会删除本机保存的登录态与独立登录窗口的浏览器配置;"
1561
+ "确认后以 confirm=true 重试。只想登录时不要传 clear=true。"
1562
+ )
1483
1563
  result = clear_session(delete_profile=True)
1484
1564
  _COOKIE_CACHE.pop(DEFAULT_DOMAIN, None)
1485
1565
  lines = [
@@ -1495,6 +1575,12 @@ def _dispatch_tool(name: str, arguments: Dict[str, Any]) -> Any:
1495
1575
  f"{REDACTOR.redact(result['profile_error'])}。"
1496
1576
  "请先关闭该登录窗口,再重试清除。"
1497
1577
  )
1578
+ if result.get("backend_error"):
1579
+ lines.append(
1580
+ "凭据库中的登录态未能清除:"
1581
+ f"{REDACTOR.redact(str(result['backend_error']))}。"
1582
+ "可在系统钥匙串/密钥环里手动删除后重试。"
1583
+ )
1498
1584
  return "\n".join(lines)
1499
1585
 
1500
1586
  timeout = arguments.get("timeout_seconds") or 300
@@ -1515,14 +1601,24 @@ def _dispatch_tool(name: str, arguments: Dict[str, Any]) -> Any:
1515
1601
  ]
1516
1602
  if result.get("saved"):
1517
1603
  lines.append(
1518
- f"- 保存: 已安全保存到 {result['saved_path']}"
1519
- "(仅当前系统用户可解密;不包含账号密码)"
1604
+ "- 保存: 已加密保存到 "
1605
+ f"{result.get('storage') or '系统凭据库'}(不含账号密码)"
1520
1606
  )
1521
1607
  else:
1522
1608
  lines.append(
1523
1609
  "- 保存: 未落盘("
1524
- f"{REDACTOR.redact(result.get('save_error') or '未知原因')});"
1525
- "本次会话仍可用,但重启后需要重新登录"
1610
+ f"{result.get('storage') or '本机没有可用的加密凭据库'})"
1611
+ )
1612
+ advice = str(result.get("storage_advice") or "").strip()
1613
+ if advice:
1614
+ lines.append(f"- 说明: {REDACTOR.redact(advice)}")
1615
+ if result.get("save_error"):
1616
+ lines.append(f"- 保存失败原因: {REDACTOR.redact(result['save_error'])}")
1617
+ if result.get("profile_error"):
1618
+ lines.append(
1619
+ "- 独立登录窗口配置未能清理:"
1620
+ f"{REDACTOR.redact(str(result['profile_error']))};"
1621
+ "可运行 zju_login(clear=true) 重试。"
1526
1622
  )
1527
1623
  lines.append("现在可以重试字幕或投影抓取,不需要再操作浏览器。")
1528
1624
  return "\n".join(lines)
@@ -1627,11 +1723,20 @@ def _dispatch_tool(name: str, arguments: Dict[str, Any]) -> Any:
1627
1723
  course_id = str(arguments.get("course_id") or parsed.get("course_id") or "")
1628
1724
  download_arg = arguments.get("download")
1629
1725
  slide_images_enabled = embed_slides_enabled()
1630
- download = slide_images_enabled if download_arg is None else bool(download_arg)
1726
+ slides_as_source = slides_as_source_enabled()
1727
+ download = (
1728
+ slide_images_enabled or slides_as_source
1729
+ ) if download_arg is None else bool(download_arg)
1631
1730
  dedup_arg = arguments.get("dedup")
1632
1731
  dedup = True if dedup_arg is None else bool(dedup_arg)
1633
1732
  output_dir = str(arguments.get("output_dir") or "").strip()
1634
1733
 
1734
+ if download and arguments.get("confirm") is not True:
1735
+ return (
1736
+ "该操作会把投影截图(最多 2000 张)下载到工作区并合成 PDF;"
1737
+ "确认后以 confirm=true 重试。只想查看截图清单时传 download=false。"
1738
+ )
1739
+
1635
1740
  cookie, cookie_error, source, reason = _resolve_cookie()
1636
1741
  if not cookie:
1637
1742
  return _cookie_failure_text(
@@ -1707,18 +1812,27 @@ def _dispatch_tool(name: str, arguments: Dict[str, Any]) -> Any:
1707
1812
  download_note += f"\nPDF: {pdf_path}({len(pages)} 页)"
1708
1813
 
1709
1814
  md = format_slides_as_markdown(slides_data, pdf_path=pdf_path)
1710
- mode_text = "开启" if slide_images_enabled else "关闭(默认)"
1815
+ mode_text = "开启" if slide_images_enabled else (
1816
+ "关闭" if slides_as_source else "关闭(默认)"
1817
+ )
1818
+ source_text = "开启" if slides_as_source else "关闭(默认)"
1711
1819
  lines = [
1712
1820
  f"=== 课堂投影 PPT 截图 (sub_id={sub_id}, 共 {len(slides_data)} 页) ===",
1821
+ f"投影作为讲义来源: {source_text}"
1822
+ "(dsh 设置 slidesAsSource / 环境变量 ZJU_SLIDES_SOURCE)",
1713
1823
  f"讲义插图模式: {mode_text}"
1714
1824
  "(dsh 设置 embedSlideImages / 环境变量 ZJU_EMBED_SLIDES)",
1715
1825
  "说明: 智云接口返回的是投影画面截图,不是文字层;"
1716
- "未下载或模型不能看图时,请只用字幕与本地课件生成讲义。",
1826
+ "未下载或模型不能看图时,不要臆造幻灯片文字,只用字幕与本地课件生成讲义。",
1717
1827
  ]
1718
- if download and not slide_images_enabled:
1828
+ if slides_as_source and download:
1829
+ lines.append(
1830
+ "投影讲义模式:请结合截图内容与字幕写讲义;不能读图时只在文末列截图索引并说明。"
1831
+ )
1832
+ if download and not slide_images_enabled and not slides_as_source:
1719
1833
  lines.append("本次按显式 download=true 执行。")
1720
- elif slide_images_enabled and not download:
1721
- lines.append("本次 download=false,未下载截图。")
1834
+ elif (slide_images_enabled or slides_as_source) and not download:
1835
+ lines.append("本次 download=false,未下载截图;投影模式通常应下载后阅读。")
1722
1836
  if download_note:
1723
1837
  lines.append(download_note)
1724
1838
  if note_example:
@@ -1743,15 +1857,32 @@ def _dispatch_tool(name: str, arguments: Dict[str, Any]) -> Any:
1743
1857
  if name == "zju_extract_courseware":
1744
1858
  file_path = str(arguments.get("file_path", ""))
1745
1859
  max_chars = arguments.get("max_chars") or 10000
1746
- resolved, tried = resolve_path(file_path)
1747
- if resolved is None:
1748
- return f"错误: 找不到课件文件: {file_path}{describe_attempts(tried)}"
1860
+ allow_outside = arguments.get("allow_outside_workspace") is True
1861
+ outside_note = ""
1862
+ if allow_outside:
1863
+ # 显式开关:仍然走同一套扩展名/凭据防护,只是不要求在工作区内。
1864
+ resolved, tried = resolve_path(file_path)
1865
+ if resolved is None:
1866
+ return f"错误: 找不到课件文件: {file_path}{describe_attempts(tried)}"
1867
+ try:
1868
+ resolved = guard_local_file(resolved, COURSEWARE_EXTENSIONS, kind="课件文件")
1869
+ except LocalFileError as exc:
1870
+ return f"错误: {exc}"
1871
+ if not is_inside_workspace(resolved):
1872
+ outside_note = f"已读取工作区外文件: {resolved}\n"
1873
+ else:
1874
+ resolved, path_error = require_workspace_path(
1875
+ file_path, extensions=COURSEWARE_EXTENSIONS, kind="课件文件"
1876
+ )
1877
+ if path_error:
1878
+ return f"错误: {path_error}"
1749
1879
  try:
1750
1880
  text = extract_courseware_text(resolved, max_chars)
1751
1881
  except CoursewareError as exc:
1752
1882
  return f"错误: {exc}"
1753
1883
  return (
1754
- f"=== 课件文件提取成功 ({os.path.basename(resolved)}) ===\n"
1884
+ outside_note
1885
+ + f"=== 课件文件提取成功 ({os.path.basename(resolved)}) ===\n"
1755
1886
  f"提取字数: {len(text)} 字符\n\n"
1756
1887
  f"{text}"
1757
1888
  )
@@ -1787,14 +1918,12 @@ def _dispatch_tool(name: str, arguments: Dict[str, Any]) -> Any:
1787
1918
  file_path = str(arguments.get("file_path", "")).strip()
1788
1919
  if not file_path:
1789
1920
  raise ValueError("zju_check_note 需要 file_path 参数")
1790
- resolved, tried = resolve_path(file_path)
1791
- if resolved is None:
1792
- return f"错误: 找不到讲义文件: {file_path}{describe_attempts(tried)}"
1793
- file_path = resolved
1794
- try:
1795
- file_path = guard_local_file(file_path, NOTE_EXTENSIONS, kind="讲义文件")
1796
- except LocalFileError as exc:
1797
- return f"错误: {exc}"
1921
+ wants_fix = arguments.get("fix") is True
1922
+ file_path, path_error = require_workspace_path(
1923
+ file_path, extensions=NOTE_EXTENSIONS, kind="讲义文件", write=wants_fix
1924
+ )
1925
+ if path_error:
1926
+ return f"错误: {path_error}"
1798
1927
  try:
1799
1928
  with open(file_path, "r", encoding="utf-8") as handle:
1800
1929
  note_text = handle.read()
@@ -1806,7 +1935,7 @@ def _dispatch_tool(name: str, arguments: Dict[str, Any]) -> Any:
1806
1935
  max_samples = _clamped_max_samples(arguments.get("max_samples"), 3)
1807
1936
  applied = []
1808
1937
  backup_path = ""
1809
- if arguments.get("fix"):
1938
+ if wants_fix:
1810
1939
  fixed_text, applied = fix_markdown(note_text)
1811
1940
  if fixed_text != note_text:
1812
1941
  try:
@@ -1937,7 +2066,19 @@ def _dispatch_tool(name: str, arguments: Dict[str, Any]) -> Any:
1937
2066
 
1938
2067
 
1939
2068
  def handle_tool_call(name: str, arguments: Dict[str, Any]) -> Any:
1940
- """Execute a tool and redact secrets from whatever it returns."""
2069
+ """Execute a tool and redact secrets from whatever it returns.
2070
+
2071
+ Before dispatch, every key must be declared in the tool's inputSchema.
2072
+ dsh 0.2.x does not close the root object, so an undeclared ``cookie`` /
2073
+ ``token`` field reaches the Python side and would already have been written
2074
+ to the host's call log. Refusing the call keeps the failure local.
2075
+ """
2076
+ tool = next((item for item in TOOLS if item["name"] == name), None)
2077
+ if tool is not None and isinstance(arguments, dict):
2078
+ allowed = set((tool["inputSchema"].get("properties") or {}).keys())
2079
+ unknown = sorted(key for key in arguments if key not in allowed)
2080
+ if unknown:
2081
+ raise ValueError("未知参数: " + ", ".join(unknown))
1941
2082
  return REDACTOR.redact(_dispatch_tool(name, arguments))
1942
2083
 
1943
2084
 
@@ -2010,6 +2151,7 @@ def handle_request(message: Dict[str, Any]) -> Optional[Dict[str, Any]]:
2010
2151
  SlidesDisabledError,
2011
2152
  StudyNotesDisabledError,
2012
2153
  LoginToolsDisabledError,
2154
+ ValueError,
2013
2155
  ) as exc:
2014
2156
  message_text = REDACTOR.redact(str(exc))
2015
2157
  _log(f"{tool_name}: {message_text}")
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dsh-zju-lecture-note",
3
- "version": "2.2.6",
4
- "description": "浙大智云课堂回放讲义插件(DeepSeek Harness 原生插件):以「语音字幕 + 本地课件」为主链路,写完讲义自动排版同名 PDF;可选启用投影 PPT 截图抓取、基于 Typst scholia 模板排版的填空式学习笔记与登录辅助工具;一键登录窗口让用户正常登录后自动安全保存登录态(Windows DPAPI),不回显、不进入对话、不保存密码",
3
+ "version": "2.2.8",
4
+ "description": "浙大智云课堂回放讲义插件(DeepSeek Harness 原生插件):以「语音字幕 + 本地课件」为主链路,写完讲义自动排版同名 PDF;可选启用投影 PPT 截图抓取、基于 Typst scholia 模板排版的填空式学习笔记与登录辅助工具;一键登录窗口让用户正常登录后把登录态加密保存到平台凭据库(Windows DPAPI / macOS 钥匙串 / Linux 密钥环,无可用凭据库时不落盘),不回显、不进入对话、不保存密码",
5
5
  "license": "MIT",
6
6
  "author": "chenqianyu486",
7
7
  "icon": "icon.png",
@@ -37,6 +37,9 @@
37
37
  "files": [
38
38
  "cordis.patch.yml",
39
39
  "lib",
40
+ "plugin.json",
41
+ "mcp.json",
42
+ "server.mjs",
40
43
  "mcp_server.py",
41
44
  "zju_lecture/*.py",
42
45
  "zju_lecture/cacert.pem",