dsh-zju-lecture-note 2.2.7 → 2.2.9
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/ATTRIBUTION.md +1 -1
- package/CHANGELOG.md +108 -2
- package/README.md +57 -25
- package/SECURITY.md +96 -51
- package/docs/technical.md +98 -40
- package/lib/bridge.js +12 -2
- package/lib/client.js +142 -36
- package/lib/index.js +130 -22
- package/lib/tools.js +14 -11
- package/lib/tools.schema.json +14 -11
- package/mcp.json +21 -0
- package/mcp_server.py +258 -43
- package/package.json +5 -2
- package/plugin.json +19 -0
- package/server.mjs +118 -0
- package/skills/scholia-notes.manifest.json +1 -1
- package/skills/zju-lecture-summarizer/SKILL.md +46 -9
- package/skills/zju-lecture-summarizer/SLIDES.md +58 -14
- package/skills/zju-lecture-summarizer-help/SKILL.md +2 -2
- package/skills/zju-lecture-summarizer-help.manifest.json +4 -4
- package/skills/zju-lecture-summarizer-login.manifest.json +1 -1
- package/skills/zju-lecture-summarizer.manifest.json +6 -6
- package/zju_lecture/__init__.py +6 -0
- package/zju_lecture/browser_login.py +176 -222
- package/zju_lecture/cli.py +24 -2
- package/zju_lecture/client.py +325 -116
- package/zju_lecture/cookies.py +43 -4
- package/zju_lecture/credential_store.py +621 -0
- package/zju_lecture/deps.py +16 -0
- package/zju_lecture/formatter.py +201 -3
- package/zju_lecture/handout.py +29 -3
- package/zju_lecture/slides.py +9 -7
- package/zju_lecture/study_notes.py +4 -0
package/mcp_server.py
CHANGED
|
@@ -27,6 +27,7 @@ import sys
|
|
|
27
27
|
import time
|
|
28
28
|
import traceback
|
|
29
29
|
from typing import Any, Dict, List, Optional, Tuple
|
|
30
|
+
from urllib.parse import unquote
|
|
30
31
|
|
|
31
32
|
CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
|
|
32
33
|
if CURRENT_DIR not in sys.path:
|
|
@@ -98,7 +99,7 @@ from zju_lecture.study_notes import (
|
|
|
98
99
|
)
|
|
99
100
|
|
|
100
101
|
SERVER_NAME = "zju-lecture-mcp"
|
|
101
|
-
SERVER_VERSION = "2.2.
|
|
102
|
+
SERVER_VERSION = "2.2.9"
|
|
102
103
|
DEFAULT_TENANT = "112"
|
|
103
104
|
DEFAULT_DOMAIN = "classroom.zju.edu.cn"
|
|
104
105
|
|
|
@@ -111,6 +112,10 @@ COOKIE_ENV = "ZJU_COOKIE"
|
|
|
111
112
|
COOKIE_FILE_ENV = "ZJU_COOKIE_FILE"
|
|
112
113
|
_MAX_COOKIE_FILE_BYTES = 64 * 1024
|
|
113
114
|
|
|
115
|
+
#: Sub-switch of the projection pipeline: use the screenshots as a *content
|
|
116
|
+
#: source* (read the slides, then write the note from transcript + slides).
|
|
117
|
+
#: Distinct from EMBED_SLIDES_ENV, which only controls Markdown illustrations.
|
|
118
|
+
SLIDES_SOURCE_ENV = "ZJU_SLIDES_SOURCE"
|
|
114
119
|
#: Sub-switch of the projection pipeline: download projected-slide screenshots
|
|
115
120
|
#: and reference them in the note. Off by default because it adds download
|
|
116
121
|
#: time and vision tokens.
|
|
@@ -202,6 +207,16 @@ def available_tools() -> List[Dict[str, Any]]:
|
|
|
202
207
|
return [tool for tool in TOOLS if tool["name"] not in hidden]
|
|
203
208
|
|
|
204
209
|
|
|
210
|
+
def slides_as_source_enabled() -> bool:
|
|
211
|
+
"""Whether the host asked to use projected slides as a note source.
|
|
212
|
+
|
|
213
|
+
This is independent of the illustration sub-switch: a note can be written
|
|
214
|
+
from the slides without embedding any screenshot, and it can embed key
|
|
215
|
+
pages without treating the slide text as a source.
|
|
216
|
+
"""
|
|
217
|
+
return str(os.environ.get(SLIDES_SOURCE_ENV, "")).strip().lower() in _TRUE_VALUES
|
|
218
|
+
|
|
219
|
+
|
|
205
220
|
def embed_slides_enabled() -> bool:
|
|
206
221
|
"""Whether the host asked for projected-slide images in the note.
|
|
207
222
|
|
|
@@ -215,15 +230,21 @@ def slide_image_mode_text() -> str:
|
|
|
215
230
|
"""One sentence describing the note-illustration mode for this process."""
|
|
216
231
|
if not slides_enabled():
|
|
217
232
|
return "投影抓取已关闭,讲义只使用字幕与本地课件。"
|
|
233
|
+
if slides_as_source_enabled():
|
|
234
|
+
return (
|
|
235
|
+
"投影作为讲义来源:开启。写讲义前必须先抓一次投影(整节课只抓一次)并下载截图,"
|
|
236
|
+
"把幻灯片上的定义、公式、图例、例题与字幕对照写进正文;"
|
|
237
|
+
"模型不能查看本地图片时,只在文末列截图索引,不要臆造幻灯片文字。"
|
|
238
|
+
)
|
|
218
239
|
if embed_slides_enabled():
|
|
219
240
|
return (
|
|
220
|
-
"
|
|
241
|
+
"讲义插图模式:开启。写讲义前抓一次投影(整节课只抓一次),"
|
|
221
242
|
"从返回的截图里挑 3–8 张关键页,按讲义所在目录的相对路径插入 Markdown;"
|
|
222
243
|
"模型不能查看本地图片时,只在文末列截图索引,不要臆造截图内容。"
|
|
223
244
|
)
|
|
224
245
|
return (
|
|
225
|
-
"
|
|
226
|
-
"
|
|
246
|
+
"投影只启用抓取:写讲义前可调用一次 zju_fetch_slides(download=false) 核对清单,"
|
|
247
|
+
"不下载、不插图、不把截图当作内容来源。"
|
|
227
248
|
)
|
|
228
249
|
|
|
229
250
|
|
|
@@ -239,8 +260,11 @@ def _pdf_mode_text() -> str:
|
|
|
239
260
|
def server_instructions() -> str:
|
|
240
261
|
"""MCP initialize instructions, reflecting the current feature gates."""
|
|
241
262
|
parts = [
|
|
242
|
-
"提供浙大智云课堂(classroom.zju.edu.cn
|
|
243
|
-
"
|
|
263
|
+
"提供浙大智云课堂(classroom.zju.edu.cn)与互动式课堂"
|
|
264
|
+
"(interactivemeta.cmc.zju.edu.cn)回放的语音字幕与课件文本提取。"
|
|
265
|
+
"两种回放链接(普通 query 与 #/replay hash 路由)都可以直接交给工具。"
|
|
266
|
+
"字幕先匿名请求;401/403 时自动使用本机登录态重试一次,无需开启登录辅助工具;"
|
|
267
|
+
"主站失败时工具会自动回退互动式课堂后端,不要自行更换主机。"
|
|
244
268
|
"本机没有可用登录态、或登录态已失效时,调用 zju_login(url=<这节课链接>) "
|
|
245
269
|
"打开独立登录窗口:用户只需在窗口里正常登录,窗口会自动关闭并把登录态安全保存在本机;"
|
|
246
270
|
"不要让用户打开开发者工具复制 Cookie,也不要索要 Cookie / 密码。",
|
|
@@ -260,6 +284,12 @@ def server_instructions() -> str:
|
|
|
260
284
|
parts.append(
|
|
261
285
|
"投影截图(可下载并合成 PDF)需要登录态(Cookie 需含 _token);"
|
|
262
286
|
"投影抓取可用 ZJU_ENABLE_SLIDES=0 关闭。"
|
|
287
|
+
+ (
|
|
288
|
+
"投影作为讲义来源已开启(ZJU_SLIDES_SOURCE=1):写讲义前先抓取一次并下载截图,"
|
|
289
|
+
"结合字幕与幻灯片内容写;不能看图时不要臆造幻灯片文字。"
|
|
290
|
+
if slides_as_source_enabled()
|
|
291
|
+
else ""
|
|
292
|
+
)
|
|
263
293
|
)
|
|
264
294
|
else:
|
|
265
295
|
parts.append(
|
|
@@ -450,14 +480,21 @@ def _cookie_failure_text(
|
|
|
450
480
|
TOOLS: List[Dict[str, Any]] = [
|
|
451
481
|
{
|
|
452
482
|
"name": "zju_parse_url",
|
|
453
|
-
"description":
|
|
483
|
+
"description": (
|
|
484
|
+
"解析浙大智云课堂 / 互动式课堂回放链接,提取 sub_id、course_id 与 tenant_code;"
|
|
485
|
+
"兼容 classroom.zju.edu.cn/livingroom?... 与 "
|
|
486
|
+
"interactivemeta.cmc.zju.edu.cn/#/replay?... 两种 URL。"
|
|
487
|
+
),
|
|
454
488
|
"inputSchema": {
|
|
455
489
|
"type": "object",
|
|
456
490
|
"additionalProperties": False,
|
|
457
491
|
"properties": {
|
|
458
492
|
"url": {
|
|
459
493
|
"type": "string",
|
|
460
|
-
"description":
|
|
494
|
+
"description": (
|
|
495
|
+
"回放 URL(classroom.zju.edu.cn/livingroom?... 或 "
|
|
496
|
+
"interactivemeta.cmc.zju.edu.cn/#/replay?...)或纯 sub_id 数字"
|
|
497
|
+
),
|
|
461
498
|
}
|
|
462
499
|
},
|
|
463
500
|
"required": ["url"],
|
|
@@ -466,8 +503,9 @@ TOOLS: List[Dict[str, Any]] = [
|
|
|
466
503
|
{
|
|
467
504
|
"name": "zju_fetch_transcript",
|
|
468
505
|
"description": (
|
|
469
|
-
"
|
|
470
|
-
"
|
|
506
|
+
"抓取智云课堂 / 互动式课堂某节课的语音识别字幕。先匿名;401/403 时自动用本机登录态"
|
|
507
|
+
"重试一次,并自动回退互动式课堂后端。登录态只能来自本机 Edge 或 ZJU_COOKIE_FILE,"
|
|
508
|
+
"不要传 Cookie。"
|
|
471
509
|
"默认 per_minute 带时间戳;长课用 chunked;同一节课只抓一次,"
|
|
472
510
|
"per_segment 仅在确实需要秒级时间戳时用。"
|
|
473
511
|
),
|
|
@@ -477,7 +515,9 @@ TOOLS: List[Dict[str, Any]] = [
|
|
|
477
515
|
"properties": {
|
|
478
516
|
"url_or_sub_id": {
|
|
479
517
|
"type": "string",
|
|
480
|
-
"description":
|
|
518
|
+
"description": (
|
|
519
|
+
"回放 URL(含互动式课堂 #/replay hash 链接)或 sub_id"
|
|
520
|
+
),
|
|
481
521
|
},
|
|
482
522
|
"tenant_code": {
|
|
483
523
|
"type": "string",
|
|
@@ -518,11 +558,16 @@ TOOLS: List[Dict[str, Any]] = [
|
|
|
518
558
|
{
|
|
519
559
|
"name": "zju_fetch_slides",
|
|
520
560
|
"description": (
|
|
521
|
-
"
|
|
522
|
-
"投影截图,不是文字层/OCR
|
|
523
|
-
"
|
|
561
|
+
"(投影模块)抓取智云课堂 / 互动式课堂投影 PPT 截图清单。search-ppt 返回的是"
|
|
562
|
+
"投影截图,不是文字层/OCR;主站为空时自动回退互动式课堂后端。"
|
|
563
|
+
"download=true 时下载截图并合成 PDF。"
|
|
564
|
+
"返回紧凑索引:截图目录/文件名模式、页时间轴、建议抽查页与引用示例。"
|
|
565
|
+
"当插件把投影作为讲义来源(slidesAsSource / ZJU_SLIDES_SOURCE=1)时,"
|
|
566
|
+
"写讲义前应调用一次并传 download=true, confirm=true;download 省略时"
|
|
567
|
+
"跟随 slidesAsSource / embedSlideImages(ZJU_SLIDES_SOURCE / ZJU_EMBED_SLIDES)。"
|
|
524
568
|
"需要登录态(Cookie 含 _token,由服务端本地解析,不接受也不回显 Cookie)。"
|
|
525
|
-
"抓不到时返回诊断,可降级为纯字幕总结。
|
|
569
|
+
"抓不到时返回诊断,可降级为纯字幕总结。"
|
|
570
|
+
"dsh 的 enableSlides(ZJU_ENABLE_SLIDES)关闭时本工具不注册。"
|
|
526
571
|
),
|
|
527
572
|
"inputSchema": {
|
|
528
573
|
"type": "object",
|
|
@@ -530,7 +575,9 @@ TOOLS: List[Dict[str, Any]] = [
|
|
|
530
575
|
"properties": {
|
|
531
576
|
"url_or_sub_id": {
|
|
532
577
|
"type": "string",
|
|
533
|
-
"description":
|
|
578
|
+
"description": (
|
|
579
|
+
"回放 URL(通常含 course_id,支持互动式课堂 hash 链接)或 sub_id"
|
|
580
|
+
),
|
|
534
581
|
},
|
|
535
582
|
"course_id": {
|
|
536
583
|
"type": "string",
|
|
@@ -548,7 +595,8 @@ TOOLS: List[Dict[str, Any]] = [
|
|
|
548
595
|
"type": "boolean",
|
|
549
596
|
"description": (
|
|
550
597
|
"是否下载截图到工作区并合成 PDF。省略时跟随插件设置"
|
|
551
|
-
"(
|
|
598
|
+
"(slidesAsSource 或 embedSlideImages 开启即下载;"
|
|
599
|
+
"环境变量 ZJU_SLIDES_SOURCE / ZJU_EMBED_SLIDES);"
|
|
552
600
|
"显式传 true/false 可覆盖。一节 1 小时的课通常有几十到几百张截图"
|
|
553
601
|
),
|
|
554
602
|
},
|
|
@@ -678,7 +726,7 @@ TOOLS: List[Dict[str, Any]] = [
|
|
|
678
726
|
{
|
|
679
727
|
"name": "zju_write_note",
|
|
680
728
|
"description": (
|
|
681
|
-
"写入讲义 Markdown
|
|
729
|
+
"写入讲义 Markdown(content 或 content_file 二选一):自动命名(知识总结-<日期>-<课程>-<主题>)、默认拒绝静默覆盖、"
|
|
682
730
|
"写前修正公式、写后返回规范检查,并按设置自动排版同名 PDF——"
|
|
683
731
|
"写文件、检查、出 PDF 一次完成。只写工作区内的 .md 文件。"
|
|
684
732
|
),
|
|
@@ -692,7 +740,14 @@ TOOLS: List[Dict[str, Any]] = [
|
|
|
692
740
|
},
|
|
693
741
|
"content": {
|
|
694
742
|
"type": "string",
|
|
695
|
-
"description": "讲义 Markdown
|
|
743
|
+
"description": "讲义 Markdown 全文(与 content_file 二选一)",
|
|
744
|
+
},
|
|
745
|
+
"content_file": {
|
|
746
|
+
"type": "string",
|
|
747
|
+
"description": (
|
|
748
|
+
"从工作区内的 Markdown 草稿读取讲义全文(与 content 二选一)。"
|
|
749
|
+
"长篇讲义建议先用 write 落盘,再传此路径,避免在 run_code 里重复粘贴。"
|
|
750
|
+
),
|
|
696
751
|
},
|
|
697
752
|
"name": {
|
|
698
753
|
"type": "string",
|
|
@@ -731,7 +786,7 @@ TOOLS: List[Dict[str, Any]] = [
|
|
|
731
786
|
"description": "写入后是否排版同名 PDF(默认跟随插件设置 renderPdf;显式 true/false 可覆盖)",
|
|
732
787
|
},
|
|
733
788
|
},
|
|
734
|
-
"required": ["sub_id"
|
|
789
|
+
"required": ["sub_id"],
|
|
735
790
|
},
|
|
736
791
|
},
|
|
737
792
|
{
|
|
@@ -1097,7 +1152,7 @@ _LOGIN_SOURCE_LABELS = {
|
|
|
1097
1152
|
"cache": "进程内缓存",
|
|
1098
1153
|
"env": "ZJU_COOKIE",
|
|
1099
1154
|
"file": "ZJU_COOKIE_FILE",
|
|
1100
|
-
"session": "zju_login
|
|
1155
|
+
"session": "zju_login 保存(加密)",
|
|
1101
1156
|
"edge": "本机 Edge",
|
|
1102
1157
|
}
|
|
1103
1158
|
|
|
@@ -1120,7 +1175,8 @@ def _login_status_text() -> List[str]:
|
|
|
1120
1175
|
lines.append(
|
|
1121
1176
|
" 本机保存的登录态: 存在"
|
|
1122
1177
|
f"({summary.get('cookie_count', 0)} 条 Cookie,"
|
|
1123
|
-
f"浏览器 {summary.get('browser') or '未知'}
|
|
1178
|
+
f"浏览器 {summary.get('browser') or '未知'},"
|
|
1179
|
+
f"存储 {summary.get('storage') or '未知'})"
|
|
1124
1180
|
)
|
|
1125
1181
|
return lines
|
|
1126
1182
|
action = COOKIE_FAILURE_ACTIONS.get(reason or "unknown", COOKIE_FAILURE_ACTIONS["unknown"])
|
|
@@ -1186,8 +1242,13 @@ def _doctor_report(install: bool, check_login: bool = False) -> str:
|
|
|
1186
1242
|
+ (f",保存于 {stamp}" if stamp else "")
|
|
1187
1243
|
+ ";不含账号密码)"
|
|
1188
1244
|
)
|
|
1245
|
+
lines.append(f" 存储: {summary.get('storage') or '未知'}")
|
|
1189
1246
|
else:
|
|
1190
1247
|
lines.append("本机登录态: 未保存(需要时调用 zju_login 打开独立登录窗口)")
|
|
1248
|
+
if summary.get("backend"):
|
|
1249
|
+
lines.append(
|
|
1250
|
+
f" 存储: {summary.get('storage') or summary.get('backend')}"
|
|
1251
|
+
)
|
|
1191
1252
|
login_ok, login_detail = login_available()
|
|
1192
1253
|
lines.append(
|
|
1193
1254
|
"登录窗口: " + ("可用(" + login_detail + ")" if login_ok else "不可用(" + login_detail + ")")
|
|
@@ -1212,10 +1273,80 @@ def _doctor_report(install: bool, check_login: bool = False) -> str:
|
|
|
1212
1273
|
return "\n".join(lines)
|
|
1213
1274
|
|
|
1214
1275
|
|
|
1276
|
+
_NOTE_IMAGE_RE = re.compile(
|
|
1277
|
+
r'!\[[^\]]*\]\(\s*([^)\s]+)(?:\s+"[^"]*")?\s*\)'
|
|
1278
|
+
)
|
|
1279
|
+
|
|
1280
|
+
|
|
1281
|
+
def _note_image_report(note_text: str, note_path: str) -> str:
|
|
1282
|
+
"""One compact line for the image references in a note.
|
|
1283
|
+
|
|
1284
|
+
The reading PDF silently turns a missing local image into an
|
|
1285
|
+
``#aside("图片未嵌入")`` placeholder; the agent should not have to glob
|
|
1286
|
+
every path to discover that. Remote images are counted separately because
|
|
1287
|
+
the PDF never downloads them.
|
|
1288
|
+
"""
|
|
1289
|
+
refs: List[str] = []
|
|
1290
|
+
in_fence = False
|
|
1291
|
+
for line in (note_text or "").splitlines():
|
|
1292
|
+
stripped = line.strip()
|
|
1293
|
+
if stripped.startswith(('```', "~~~")):
|
|
1294
|
+
in_fence = not in_fence
|
|
1295
|
+
continue
|
|
1296
|
+
if in_fence:
|
|
1297
|
+
continue
|
|
1298
|
+
refs.extend(_NOTE_IMAGE_RE.findall(line))
|
|
1299
|
+
if not refs:
|
|
1300
|
+
return ""
|
|
1301
|
+
note_dir = os.path.dirname(os.path.abspath(note_path))
|
|
1302
|
+
external = 0
|
|
1303
|
+
local = 0
|
|
1304
|
+
bad: List[str] = []
|
|
1305
|
+
for raw in refs:
|
|
1306
|
+
ref = str(raw or "").strip().strip("<>")
|
|
1307
|
+
if not ref:
|
|
1308
|
+
continue
|
|
1309
|
+
if ref.startswith(("http://", "https://")):
|
|
1310
|
+
external += 1
|
|
1311
|
+
continue
|
|
1312
|
+
if ref.startswith("data:"):
|
|
1313
|
+
continue
|
|
1314
|
+
local += 1
|
|
1315
|
+
candidate = os.path.abspath(os.path.join(note_dir, unquote(ref)))
|
|
1316
|
+
if not is_inside_workspace(candidate) or not os.path.isfile(candidate):
|
|
1317
|
+
bad.append(ref)
|
|
1318
|
+
parts = [f"{len(refs)} 张"]
|
|
1319
|
+
if external:
|
|
1320
|
+
parts.append(f"外链 {external} 张(PDF 不嵌入)")
|
|
1321
|
+
if bad:
|
|
1322
|
+
shown = ", ".join(bad[:5])
|
|
1323
|
+
if len(bad) > 5:
|
|
1324
|
+
shown += f" … 另有 {len(bad) - 5} 张"
|
|
1325
|
+
parts.append(f"缺失/不可用 {len(bad)} 张:{shown}")
|
|
1326
|
+
elif local:
|
|
1327
|
+
parts.append("本地文件全部存在")
|
|
1328
|
+
return "图片引用: " + " | ".join(parts)
|
|
1329
|
+
|
|
1330
|
+
|
|
1331
|
+
def _pdf_warning_lines(warnings: Optional[List[str]]) -> List[str]:
|
|
1332
|
+
cleaned = [
|
|
1333
|
+
" ".join(str(item).split())[:240]
|
|
1334
|
+
for item in (warnings or [])
|
|
1335
|
+
if str(item).strip()
|
|
1336
|
+
]
|
|
1337
|
+
if not cleaned:
|
|
1338
|
+
return []
|
|
1339
|
+
lines = ["PDF 提示:"]
|
|
1340
|
+
lines.extend(f"- {item}" for item in cleaned[:5])
|
|
1341
|
+
if len(cleaned) > 5:
|
|
1342
|
+
lines.append(f"- 另有 {len(cleaned) - 5} 条提示未展开")
|
|
1343
|
+
return lines
|
|
1344
|
+
|
|
1345
|
+
|
|
1215
1346
|
def _render_note_pdf(note_path: str, note_text: str) -> List[str]:
|
|
1216
1347
|
"""Typeset the written note into a reading PDF; never raises.
|
|
1217
1348
|
|
|
1218
|
-
Returns
|
|
1349
|
+
Returns a few short lines for the tool result. A missing Typst or a
|
|
1219
1350
|
rendering error must not turn a successful Markdown write into a failure:
|
|
1220
1351
|
the Markdown is the deliverable, the PDF is an enhancement.
|
|
1221
1352
|
"""
|
|
@@ -1236,7 +1367,9 @@ def _render_note_pdf(note_path: str, note_text: str) -> List[str]:
|
|
|
1236
1367
|
return [f"PDF 跳过: {exc}"]
|
|
1237
1368
|
if result.ok:
|
|
1238
1369
|
pages = f"({result.pages} 页)" if result.pages else ""
|
|
1239
|
-
|
|
1370
|
+
lines = [f"PDF: {result.pdf_path}{pages}"]
|
|
1371
|
+
lines.extend(_pdf_warning_lines(result.warnings))
|
|
1372
|
+
return lines
|
|
1240
1373
|
detail = ";".join(result.errors[:2]) or "未知原因"
|
|
1241
1374
|
if "找不到 typst" in detail:
|
|
1242
1375
|
# Keep the common "Typst is not installed" case to one short line:
|
|
@@ -1246,10 +1379,12 @@ def _render_note_pdf(note_path: str, note_text: str) -> List[str]:
|
|
|
1246
1379
|
detail = detail[:219] + "…"
|
|
1247
1380
|
# 这是「同一份讲义要不要再查一次」的唯一例外:上面报的是渲染错误,
|
|
1248
1381
|
# 不改文件永远好不了。给一句可执行的下一步,Agent 就不必自己猜。
|
|
1249
|
-
|
|
1382
|
+
lines = [
|
|
1250
1383
|
f"PDF 跳过: {detail}",
|
|
1251
1384
|
"Markdown 已写好;按上面的错误改掉对应公式后,调用 zju_check_note(pdf=true) 重排一次。",
|
|
1252
1385
|
]
|
|
1386
|
+
lines.extend(_pdf_warning_lines(result.warnings))
|
|
1387
|
+
return lines
|
|
1253
1388
|
|
|
1254
1389
|
|
|
1255
1390
|
def _patch_draft(arguments: Dict[str, Any]) -> str:
|
|
@@ -1539,6 +1674,12 @@ def _dispatch_tool(name: str, arguments: Dict[str, Any]) -> Any:
|
|
|
1539
1674
|
f"{REDACTOR.redact(result['profile_error'])}。"
|
|
1540
1675
|
"请先关闭该登录窗口,再重试清除。"
|
|
1541
1676
|
)
|
|
1677
|
+
if result.get("backend_error"):
|
|
1678
|
+
lines.append(
|
|
1679
|
+
"凭据库中的登录态未能清除:"
|
|
1680
|
+
f"{REDACTOR.redact(str(result['backend_error']))}。"
|
|
1681
|
+
"可在系统钥匙串/密钥环里手动删除后重试。"
|
|
1682
|
+
)
|
|
1542
1683
|
return "\n".join(lines)
|
|
1543
1684
|
|
|
1544
1685
|
timeout = arguments.get("timeout_seconds") or 300
|
|
@@ -1559,14 +1700,24 @@ def _dispatch_tool(name: str, arguments: Dict[str, Any]) -> Any:
|
|
|
1559
1700
|
]
|
|
1560
1701
|
if result.get("saved"):
|
|
1561
1702
|
lines.append(
|
|
1562
|
-
|
|
1563
|
-
"
|
|
1703
|
+
"- 保存: 已加密保存到 "
|
|
1704
|
+
f"{result.get('storage') or '系统凭据库'}(不含账号密码)"
|
|
1564
1705
|
)
|
|
1565
1706
|
else:
|
|
1566
1707
|
lines.append(
|
|
1567
1708
|
"- 保存: 未落盘("
|
|
1568
|
-
f"{
|
|
1569
|
-
|
|
1709
|
+
f"{result.get('storage') or '本机没有可用的加密凭据库'})"
|
|
1710
|
+
)
|
|
1711
|
+
advice = str(result.get("storage_advice") or "").strip()
|
|
1712
|
+
if advice:
|
|
1713
|
+
lines.append(f"- 说明: {REDACTOR.redact(advice)}")
|
|
1714
|
+
if result.get("save_error"):
|
|
1715
|
+
lines.append(f"- 保存失败原因: {REDACTOR.redact(result['save_error'])}")
|
|
1716
|
+
if result.get("profile_error"):
|
|
1717
|
+
lines.append(
|
|
1718
|
+
"- 独立登录窗口配置未能清理:"
|
|
1719
|
+
f"{REDACTOR.redact(str(result['profile_error']))};"
|
|
1720
|
+
"可运行 zju_login(clear=true) 重试。"
|
|
1570
1721
|
)
|
|
1571
1722
|
lines.append("现在可以重试字幕或投影抓取,不需要再操作浏览器。")
|
|
1572
1723
|
return "\n".join(lines)
|
|
@@ -1671,7 +1822,10 @@ def _dispatch_tool(name: str, arguments: Dict[str, Any]) -> Any:
|
|
|
1671
1822
|
course_id = str(arguments.get("course_id") or parsed.get("course_id") or "")
|
|
1672
1823
|
download_arg = arguments.get("download")
|
|
1673
1824
|
slide_images_enabled = embed_slides_enabled()
|
|
1674
|
-
|
|
1825
|
+
slides_as_source = slides_as_source_enabled()
|
|
1826
|
+
download = (
|
|
1827
|
+
slide_images_enabled or slides_as_source
|
|
1828
|
+
) if download_arg is None else bool(download_arg)
|
|
1675
1829
|
dedup_arg = arguments.get("dedup")
|
|
1676
1830
|
dedup = True if dedup_arg is None else bool(dedup_arg)
|
|
1677
1831
|
output_dir = str(arguments.get("output_dir") or "").strip()
|
|
@@ -1725,6 +1879,7 @@ def _dispatch_tool(name: str, arguments: Dict[str, Any]) -> Any:
|
|
|
1725
1879
|
pdf_path = ""
|
|
1726
1880
|
download_note = ""
|
|
1727
1881
|
note_example = ""
|
|
1882
|
+
pages: List[Dict[str, Any]] = []
|
|
1728
1883
|
if download:
|
|
1729
1884
|
target, target_error = artifact_dir(
|
|
1730
1885
|
output_dir,
|
|
@@ -1750,25 +1905,40 @@ def _dispatch_tool(name: str, arguments: Dict[str, Any]) -> Any:
|
|
|
1750
1905
|
pdf_path = written
|
|
1751
1906
|
download_note = (
|
|
1752
1907
|
f"下载 {summary.get('downloaded', 0)} 张,失败 {summary.get('failed', 0)} 张,"
|
|
1753
|
-
f"
|
|
1908
|
+
f"连续字节完全重复折叠 {summary.get('duplicates', 0)} 张(仅字节级去重);"
|
|
1754
1909
|
f"截图目录: {summary.get('images_dir')}"
|
|
1755
1910
|
)
|
|
1756
1911
|
if pdf_path:
|
|
1757
1912
|
download_note += f"\nPDF: {pdf_path}({len(pages)} 页)"
|
|
1758
1913
|
|
|
1759
|
-
|
|
1760
|
-
|
|
1914
|
+
index_slides = pages if (download and pages) else slides_data
|
|
1915
|
+
md = format_slides_as_markdown(
|
|
1916
|
+
index_slides,
|
|
1917
|
+
pdf_path=pdf_path,
|
|
1918
|
+
compact=True,
|
|
1919
|
+
download_attempted=download,
|
|
1920
|
+
)
|
|
1921
|
+
mode_text = "开启" if slide_images_enabled else (
|
|
1922
|
+
"关闭" if slides_as_source else "关闭(默认)"
|
|
1923
|
+
)
|
|
1924
|
+
source_text = "开启" if slides_as_source else "关闭(默认)"
|
|
1761
1925
|
lines = [
|
|
1762
|
-
f"=== 课堂投影 PPT 截图 (sub_id={sub_id}, 共 {len(
|
|
1926
|
+
f"=== 课堂投影 PPT 截图 (sub_id={sub_id}, 共 {len(index_slides)} 页) ===",
|
|
1927
|
+
f"投影作为讲义来源: {source_text}"
|
|
1928
|
+
"(dsh 设置 slidesAsSource / 环境变量 ZJU_SLIDES_SOURCE)",
|
|
1763
1929
|
f"讲义插图模式: {mode_text}"
|
|
1764
1930
|
"(dsh 设置 embedSlideImages / 环境变量 ZJU_EMBED_SLIDES)",
|
|
1765
1931
|
"说明: 智云接口返回的是投影画面截图,不是文字层;"
|
|
1766
|
-
"
|
|
1932
|
+
"未下载或模型不能看图时,不要臆造幻灯片文字,只用字幕与本地课件生成讲义。",
|
|
1767
1933
|
]
|
|
1768
|
-
if
|
|
1934
|
+
if slides_as_source and download:
|
|
1935
|
+
lines.append(
|
|
1936
|
+
"投影讲义模式:请结合截图内容与字幕写讲义;不能读图时只在文末列截图索引并说明。"
|
|
1937
|
+
)
|
|
1938
|
+
if download and not slide_images_enabled and not slides_as_source:
|
|
1769
1939
|
lines.append("本次按显式 download=true 执行。")
|
|
1770
|
-
elif slide_images_enabled and not download:
|
|
1771
|
-
lines.append("本次 download=false
|
|
1940
|
+
elif (slide_images_enabled or slides_as_source) and not download:
|
|
1941
|
+
lines.append("本次 download=false,未下载截图;投影模式通常应下载后阅读。")
|
|
1772
1942
|
if download_note:
|
|
1773
1943
|
lines.append(download_note)
|
|
1774
1944
|
if note_example:
|
|
@@ -1888,6 +2058,9 @@ def _dispatch_tool(name: str, arguments: Dict[str, Any]) -> Any:
|
|
|
1888
2058
|
report = format_report(
|
|
1889
2059
|
os.path.basename(file_path), check_markdown(note_text), max_samples
|
|
1890
2060
|
)
|
|
2061
|
+
image_line = _note_image_report(note_text, file_path)
|
|
2062
|
+
if image_line:
|
|
2063
|
+
report = image_line + "\n\n" + report
|
|
1891
2064
|
if applied:
|
|
1892
2065
|
applied_block = "\n".join(f"- {item}" for item in applied)
|
|
1893
2066
|
if backup_path:
|
|
@@ -1900,27 +2073,64 @@ def _dispatch_tool(name: str, arguments: Dict[str, Any]) -> Any:
|
|
|
1900
2073
|
if name == "zju_write_note":
|
|
1901
2074
|
sub_id = str(arguments.get("sub_id", "")).strip()
|
|
1902
2075
|
content = arguments.get("content")
|
|
2076
|
+
content_file = str(arguments.get("content_file") or "").strip()
|
|
1903
2077
|
if not sub_id:
|
|
1904
2078
|
raise ValueError("zju_write_note 需要 sub_id 参数")
|
|
2079
|
+
if content_file and isinstance(content, str) and content.strip():
|
|
2080
|
+
raise ValueError("zju_write_note 的 content 与 content_file 只能传一个")
|
|
2081
|
+
|
|
2082
|
+
source_path = ""
|
|
2083
|
+
if content_file:
|
|
2084
|
+
source_path, path_error = require_workspace_path(
|
|
2085
|
+
content_file, extensions=NOTE_EXTENSIONS, kind="讲义草稿"
|
|
2086
|
+
)
|
|
2087
|
+
if path_error:
|
|
2088
|
+
return f"错误: {path_error}"
|
|
2089
|
+
try:
|
|
2090
|
+
# UTF-8 is at most 4 bytes per character; this rejects a
|
|
2091
|
+
# pathological file before materialising it in memory.
|
|
2092
|
+
if os.path.getsize(source_path) > MAX_NOTE_CHARS * 4:
|
|
2093
|
+
return (
|
|
2094
|
+
f"错误: 讲义草稿超过 {MAX_NOTE_CHARS} 字符上限,"
|
|
2095
|
+
"请检查是否误传了别的内容。"
|
|
2096
|
+
)
|
|
2097
|
+
with open(source_path, "r", encoding="utf-8") as handle:
|
|
2098
|
+
content = handle.read()
|
|
2099
|
+
except UnicodeDecodeError:
|
|
2100
|
+
return f"错误: 讲义草稿不是 UTF-8 编码: {source_path}"
|
|
2101
|
+
except OSError as exc:
|
|
2102
|
+
return f"错误: 读取讲义草稿失败: {exc}"
|
|
2103
|
+
|
|
1905
2104
|
if not isinstance(content, str) or not content.strip():
|
|
1906
|
-
raise ValueError(
|
|
2105
|
+
raise ValueError(
|
|
2106
|
+
"zju_write_note 需要非空的 content 或 content_file 参数(讲义 Markdown 全文)"
|
|
2107
|
+
)
|
|
1907
2108
|
if len(content) > MAX_NOTE_CHARS:
|
|
1908
2109
|
return (
|
|
1909
2110
|
f"错误: 讲义内容 {len(content)} 字符,超过 {MAX_NOTE_CHARS} 字符上限;"
|
|
1910
2111
|
"请分批写入或检查是否误传了别的内容。"
|
|
1911
2112
|
)
|
|
1912
2113
|
|
|
2114
|
+
note_name = str(arguments.get("name") or "").strip()
|
|
2115
|
+
if not note_name and source_path:
|
|
2116
|
+
draft_stem = os.path.splitext(os.path.basename(source_path))[0]
|
|
2117
|
+
if draft_stem.startswith("知识总结"):
|
|
2118
|
+
note_name = draft_stem
|
|
1913
2119
|
target, target_error = note_target(
|
|
1914
2120
|
sub_id,
|
|
1915
2121
|
str(arguments.get("slug") or ""),
|
|
1916
2122
|
arguments.get("directory"),
|
|
1917
|
-
|
|
2123
|
+
note_name,
|
|
1918
2124
|
)
|
|
1919
2125
|
if target_error:
|
|
1920
2126
|
return f"错误: {target_error}"
|
|
1921
2127
|
|
|
1922
2128
|
overwrite = bool(arguments.get("overwrite"))
|
|
1923
|
-
|
|
2129
|
+
same_file = bool(source_path) and (
|
|
2130
|
+
os.path.normcase(os.path.realpath(target))
|
|
2131
|
+
== os.path.normcase(os.path.realpath(source_path))
|
|
2132
|
+
)
|
|
2133
|
+
already = os.path.exists(target) and not same_file
|
|
1924
2134
|
if already and not overwrite:
|
|
1925
2135
|
# Silent overwrite is how one lecture's note ate the previous one's:
|
|
1926
2136
|
# hand the decision back to the caller instead of guessing.
|
|
@@ -1940,7 +2150,7 @@ def _dispatch_tool(name: str, arguments: Dict[str, Any]) -> Any:
|
|
|
1940
2150
|
if arguments.get("fix", True):
|
|
1941
2151
|
fixed_text, applied = fix_markdown(content)
|
|
1942
2152
|
try:
|
|
1943
|
-
if already:
|
|
2153
|
+
if already or same_file:
|
|
1944
2154
|
backup_path = write_with_backup(target, fixed_text)
|
|
1945
2155
|
else:
|
|
1946
2156
|
backup_path = ""
|
|
@@ -1957,11 +2167,16 @@ def _dispatch_tool(name: str, arguments: Dict[str, Any]) -> Any:
|
|
|
1957
2167
|
f"路径: {target}",
|
|
1958
2168
|
f"字数: {len(fixed_text)} 字符",
|
|
1959
2169
|
]
|
|
1960
|
-
|
|
2170
|
+
image_line = _note_image_report(fixed_text, target)
|
|
2171
|
+
if image_line:
|
|
2172
|
+
header.append(image_line)
|
|
2173
|
+
if not note_name:
|
|
1961
2174
|
header.append(
|
|
1962
2175
|
"提示: 本次用的是回退文件名。建议下次传 name=知识总结-<上课日期>-<课程简称>-<本节主题>,"
|
|
1963
2176
|
"文件名带日期与内容更利于区分不同讲次。"
|
|
1964
2177
|
)
|
|
2178
|
+
if source_path:
|
|
2179
|
+
header.append(f"草稿来源: {source_path}")
|
|
1965
2180
|
if applied:
|
|
1966
2181
|
header.append("自动修复:")
|
|
1967
2182
|
header.extend(f"- {item}" for item in applied)
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-zju-lecture-note",
|
|
3
|
-
"version": "2.2.
|
|
4
|
-
"description": "浙大智云课堂回放讲义插件(DeepSeek Harness 原生插件):以「语音字幕 + 本地课件」为主链路,写完讲义自动排版同名 PDF;可选启用投影 PPT 截图抓取、基于 Typst scholia
|
|
3
|
+
"version": "2.2.9",
|
|
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",
|
package/plugin.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://agent-plugins.org/schemas/1.0.0/plugin.schema.json",
|
|
3
|
+
"name": "zju-lecture",
|
|
4
|
+
"version": "2.2.9",
|
|
5
|
+
"description": "浙大智云课堂回放讲义:语音字幕 + 本地课件 → 结构化讲义与 PDF(MCP + Agent Skills)",
|
|
6
|
+
"author": {
|
|
7
|
+
"name": "chenqianyu486"
|
|
8
|
+
},
|
|
9
|
+
"homepage": "https://github.com/chenqianyu486-sys/dsh-zju-lecture-note#readme",
|
|
10
|
+
"repository": "https://github.com/chenqianyu486-sys/dsh-zju-lecture-note",
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"keywords": [
|
|
13
|
+
"zju",
|
|
14
|
+
"lecture",
|
|
15
|
+
"mcp",
|
|
16
|
+
"agent-skill",
|
|
17
|
+
"typst"
|
|
18
|
+
]
|
|
19
|
+
}
|