glossr 0.1.0__py3-none-any.whl
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.
- gloss/__init__.py +1 -0
- gloss/__main__.py +3 -0
- gloss/_workspace/CLAUDE.md +16 -0
- gloss/_workspace/prompts/align-transcript.md +25 -0
- gloss/_workspace/prompts/build-tree.md +18 -0
- gloss/_workspace/prompts/digest-lecture.md +49 -0
- gloss/_workspace/prompts/explain-slide.md +24 -0
- gloss/_workspace/prompts/pre-quiz.md +32 -0
- gloss/_workspace/prompts/qa-opening.md +12 -0
- gloss/_workspace/prompts/qa-rebuild.md +8 -0
- gloss/_workspace/prompts/qa-retrieval.md +14 -0
- gloss/_workspace/prompts/qa-system.md +11 -0
- gloss/_workspace/prompts/quiz-verify.md +11 -0
- gloss/_workspace/prompts/update-profile.md +41 -0
- gloss/cli.py +111 -0
- gloss/config.py +89 -0
- gloss/course_tools.py +508 -0
- gloss/digest.py +310 -0
- gloss/doctor.py +149 -0
- gloss/export.py +90 -0
- gloss/folders.py +244 -0
- gloss/i18n.py +91 -0
- gloss/ingest.py +92 -0
- gloss/jobs.py +134 -0
- gloss/mcp_server.py +65 -0
- gloss/profile.py +546 -0
- gloss/providers/__init__.py +4 -0
- gloss/providers/anthropic_api.py +163 -0
- gloss/providers/base.py +85 -0
- gloss/providers/claude_cli.py +198 -0
- gloss/quiz.py +399 -0
- gloss/schema.py +118 -0
- gloss/server.py +800 -0
- gloss/static/SOURCE_HASH +1 -0
- gloss/static/assets/KaTeX_AMS-Regular-BQhdFMY1.woff2 +0 -0
- gloss/static/assets/KaTeX_AMS-Regular-DMm9YOAa.woff +0 -0
- gloss/static/assets/KaTeX_AMS-Regular-DRggAlZN.ttf +0 -0
- gloss/static/assets/KaTeX_Caligraphic-Bold-ATXxdsX0.ttf +0 -0
- gloss/static/assets/KaTeX_Caligraphic-Bold-BEiXGLvX.woff +0 -0
- gloss/static/assets/KaTeX_Caligraphic-Bold-Dq_IR9rO.woff2 +0 -0
- gloss/static/assets/KaTeX_Caligraphic-Regular-CTRA-rTL.woff +0 -0
- gloss/static/assets/KaTeX_Caligraphic-Regular-Di6jR-x-.woff2 +0 -0
- gloss/static/assets/KaTeX_Caligraphic-Regular-wX97UBjC.ttf +0 -0
- gloss/static/assets/KaTeX_Fraktur-Bold-BdnERNNW.ttf +0 -0
- gloss/static/assets/KaTeX_Fraktur-Bold-BsDP51OF.woff +0 -0
- gloss/static/assets/KaTeX_Fraktur-Bold-CL6g_b3V.woff2 +0 -0
- gloss/static/assets/KaTeX_Fraktur-Regular-CB_wures.ttf +0 -0
- gloss/static/assets/KaTeX_Fraktur-Regular-CTYiF6lA.woff2 +0 -0
- gloss/static/assets/KaTeX_Fraktur-Regular-Dxdc4cR9.woff +0 -0
- gloss/static/assets/KaTeX_Main-Bold-Cx986IdX.woff2 +0 -0
- gloss/static/assets/KaTeX_Main-Bold-Jm3AIy58.woff +0 -0
- gloss/static/assets/KaTeX_Main-Bold-waoOVXN0.ttf +0 -0
- gloss/static/assets/KaTeX_Main-BoldItalic-DxDJ3AOS.woff2 +0 -0
- gloss/static/assets/KaTeX_Main-BoldItalic-DzxPMmG6.ttf +0 -0
- gloss/static/assets/KaTeX_Main-BoldItalic-SpSLRI95.woff +0 -0
- gloss/static/assets/KaTeX_Main-Italic-3WenGoN9.ttf +0 -0
- gloss/static/assets/KaTeX_Main-Italic-BMLOBm91.woff +0 -0
- gloss/static/assets/KaTeX_Main-Italic-NWA7e6Wa.woff2 +0 -0
- gloss/static/assets/KaTeX_Main-Regular-B22Nviop.woff2 +0 -0
- gloss/static/assets/KaTeX_Main-Regular-Dr94JaBh.woff +0 -0
- gloss/static/assets/KaTeX_Main-Regular-ypZvNtVU.ttf +0 -0
- gloss/static/assets/KaTeX_Math-BoldItalic-B3XSjfu4.ttf +0 -0
- gloss/static/assets/KaTeX_Math-BoldItalic-CZnvNsCZ.woff2 +0 -0
- gloss/static/assets/KaTeX_Math-BoldItalic-iY-2wyZ7.woff +0 -0
- gloss/static/assets/KaTeX_Math-Italic-DA0__PXp.woff +0 -0
- gloss/static/assets/KaTeX_Math-Italic-flOr_0UB.ttf +0 -0
- gloss/static/assets/KaTeX_Math-Italic-t53AETM-.woff2 +0 -0
- gloss/static/assets/KaTeX_SansSerif-Bold-CFMepnvq.ttf +0 -0
- gloss/static/assets/KaTeX_SansSerif-Bold-D1sUS0GD.woff2 +0 -0
- gloss/static/assets/KaTeX_SansSerif-Bold-DbIhKOiC.woff +0 -0
- gloss/static/assets/KaTeX_SansSerif-Italic-C3H0VqGB.woff2 +0 -0
- gloss/static/assets/KaTeX_SansSerif-Italic-DN2j7dab.woff +0 -0
- gloss/static/assets/KaTeX_SansSerif-Italic-YYjJ1zSn.ttf +0 -0
- gloss/static/assets/KaTeX_SansSerif-Regular-BNo7hRIc.ttf +0 -0
- gloss/static/assets/KaTeX_SansSerif-Regular-CS6fqUqJ.woff +0 -0
- gloss/static/assets/KaTeX_SansSerif-Regular-DDBCnlJ7.woff2 +0 -0
- gloss/static/assets/KaTeX_Script-Regular-C5JkGWo-.ttf +0 -0
- gloss/static/assets/KaTeX_Script-Regular-D3wIWfF6.woff2 +0 -0
- gloss/static/assets/KaTeX_Script-Regular-D5yQViql.woff +0 -0
- gloss/static/assets/KaTeX_Size1-Regular-C195tn64.woff +0 -0
- gloss/static/assets/KaTeX_Size1-Regular-Dbsnue_I.ttf +0 -0
- gloss/static/assets/KaTeX_Size1-Regular-mCD8mA8B.woff2 +0 -0
- gloss/static/assets/KaTeX_Size2-Regular-B7gKUWhC.ttf +0 -0
- gloss/static/assets/KaTeX_Size2-Regular-Dy4dx90m.woff2 +0 -0
- gloss/static/assets/KaTeX_Size2-Regular-oD1tc_U0.woff +0 -0
- gloss/static/assets/KaTeX_Size3-Regular-CTq5MqoE.woff +0 -0
- gloss/static/assets/KaTeX_Size3-Regular-DgpXs0kz.ttf +0 -0
- gloss/static/assets/KaTeX_Size4-Regular-BF-4gkZK.woff +0 -0
- gloss/static/assets/KaTeX_Size4-Regular-DWFBv043.ttf +0 -0
- gloss/static/assets/KaTeX_Size4-Regular-Dl5lxZxV.woff2 +0 -0
- gloss/static/assets/KaTeX_Typewriter-Regular-C0xS9mPB.woff +0 -0
- gloss/static/assets/KaTeX_Typewriter-Regular-CO6r4hn1.woff2 +0 -0
- gloss/static/assets/KaTeX_Typewriter-Regular-D3Ib7_Hf.ttf +0 -0
- gloss/static/assets/index-0B_we-15.js +302 -0
- gloss/static/assets/index-crKBFfcm.css +1 -0
- gloss/static/index.html +17 -0
- gloss/store.py +496 -0
- gloss/transcript.py +192 -0
- gloss/tutor.py +537 -0
- glossr-0.1.0.dist-info/METADATA +160 -0
- glossr-0.1.0.dist-info/RECORD +104 -0
- glossr-0.1.0.dist-info/WHEEL +4 -0
- glossr-0.1.0.dist-info/entry_points.txt +3 -0
- glossr-0.1.0.dist-info/licenses/LICENSE +21 -0
gloss/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Gloss: ask questions right on your lecture slides."""
|
gloss/__main__.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
Runtime role for Gloss. NOT developer instructions.
|
|
3
|
+
Calls run with --restricted, so this file is not auto-loaded: the backend reads it
|
|
4
|
+
and passes it with --append-system-prompt when a session is created (DESIGN.md §8).
|
|
5
|
+
-->
|
|
6
|
+
|
|
7
|
+
# 角色
|
|
8
|
+
|
|
9
|
+
你是 Gloss 里的助教。学生在看一份课件(PDF slides),你帮他们理解其中的某一页。
|
|
10
|
+
|
|
11
|
+
## 规则
|
|
12
|
+
|
|
13
|
+
- 以课件内容为准。课件没讲到、需要你补充的,明确说"课件之外补充"。不确定就说不确定,不要编。
|
|
14
|
+
- 学生只看得到你的回答正文。**不要提到文件、路径、工具、"我读取了图片"之类的过程**,直接回答。
|
|
15
|
+
- 用 Markdown。公式用 `$...$`(行内)和 `$$...$$`(独立成行)。
|
|
16
|
+
- 简洁。先给结论或直觉,再展开。不要客套开头和总结式结尾。
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
<!-- 把 transcript 对齐到每一页 slide(DESIGN.md §5.3)。输出受 JSON schema 约束。可用变量:{{course_title}} {{page_count}} {{slides}} {{last_segment}} {{segments}} {{feedback}} -->
|
|
2
|
+
下面是课件《{{course_title}}》(共 {{page_count}} 页)每一页的文字,以及老师讲课的 transcript。transcript 已切成段,每段开头是段落编号 `[段N]`(编号 0–{{last_segment}}),括号里是时间。请找出老师讲每一页时说的是哪几段。
|
|
3
|
+
|
|
4
|
+
所有内容都在这条消息里,不要使用任何工具。
|
|
5
|
+
|
|
6
|
+
## 做法
|
|
7
|
+
|
|
8
|
+
1. 先读每一页的文字,记住每页的核心内容。
|
|
9
|
+
2. 再按顺序读 transcript,判断每一段在讲哪一页的内容。依据是内容(概念、公式、例子),不是位置;"下一页""接下来""我们来看"之类的过渡语通常意味着换页。开场的课程通知、和课件无关的闲聊不属于任何一页。
|
|
10
|
+
3. 对每一页输出:
|
|
11
|
+
- `page`:页码(1–{{page_count}}),
|
|
12
|
+
- `topic`:老师在这几段里讲了什么(15 字以内,用来核对你的判断),
|
|
13
|
+
- `first`、`last`:对应的第一段和最后一段的段落编号(含两端)。注意是 `[段N]` 里的 N,不是页码。
|
|
14
|
+
4. 讲课一般按页顺序进行,范围通常随页码递增、互不重叠;老师回头讲前面的页时,以内容为准,把那几段算给讲的那一页。
|
|
15
|
+
5. 某一页老师基本没讲(比如标题页、一闪而过的页),就不要输出这一页。
|
|
16
|
+
|
|
17
|
+
{{feedback}}
|
|
18
|
+
|
|
19
|
+
## 每一页的文字
|
|
20
|
+
|
|
21
|
+
{{slides}}
|
|
22
|
+
|
|
23
|
+
## Transcript
|
|
24
|
+
|
|
25
|
+
{{segments}}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<!-- 生成整节课的思维导图(DESIGN.md §5.2)。输出受 JSON schema 约束。可用变量:{{course_title}} {{page_count}} {{slides}} {{language}} {{feedback}} -->
|
|
2
|
+
下面是一份课件(《{{course_title}}》,共 {{page_count}} 页)每一页从 PDF 抽取的文字。请把它整理成思维导图的结构。
|
|
3
|
+
|
|
4
|
+
所有内容都在这条消息里,不要使用任何工具。
|
|
5
|
+
|
|
6
|
+
## 要求
|
|
7
|
+
|
|
8
|
+
- `title`:这节课的标题,以课件内容为准(上面的文件名只是参考)。`subtitle`:课件里写明的课程名、第几讲之类的信息;课件里没有就留空字符串,不要用文件名。
|
|
9
|
+
- `children`:主题,按课件顺序排列。根据页数分成大约 3–9 个主题;每个主题最好是连续的一段页。
|
|
10
|
+
- 每个主题:`title` 简短(不超过 15 个字);`summary` 一句话说这一部分讲什么(不超过 30 个字);`slides` 是属于它的页码。
|
|
11
|
+
- **每一页恰好出现在一个主题里**,页码范围 1–{{page_count}},不能遗漏也不能重复。标题页放进第一个主题,结尾页(总结、Questions 之类)放进最后一个主题。
|
|
12
|
+
- 用{{language}}写标题和概述;课件里的专有名词保留原文。
|
|
13
|
+
|
|
14
|
+
{{feedback}}
|
|
15
|
+
|
|
16
|
+
## 每一页的文字
|
|
17
|
+
|
|
18
|
+
{{slides}}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
<!-- 一讲学完后的总结(DESIGN.md §15.3)。输入都在这条消息里,不用工具;输出受 JSON schema 约束。可用变量:{{lecture_title}} {{language}} {{outline}} {{threads}} {{notes}} {{quiz}} {{previous}} {{known_weak_points}} {{feedback}} -->
|
|
2
|
+
学生学完了《{{lecture_title}}》这一讲。下面是这一讲的结构、学生在各页上的全部提问(带编号)、笔记和测验作答。请把它们整理成一份学习总结。
|
|
3
|
+
|
|
4
|
+
**输出语言:{{language}}。** 这份说明是中文写的,但输出里所有给学生看的文字都必须用 {{language}}。提到学生的标记时用 {{language}} 的说法,不要照抄中文的"懂了 / 还没懂";上一次的总结里如果有不是 {{language}} 的文字,也改成 {{language}}。
|
|
5
|
+
|
|
6
|
+
所有内容都在这条消息里,不要使用任何工具。
|
|
7
|
+
|
|
8
|
+
## 要求
|
|
9
|
+
|
|
10
|
+
- **只根据下面的材料总结学生的学习情况**,不要补充课件之外的知识,也不要评价学生。
|
|
11
|
+
- 每条结论都要引用支撑它的问题编号(如 `T3`),放在 `threads` 里。没有问题能支撑的结论不要写。
|
|
12
|
+
- `covered`:这一讲讲了哪些主题(按结构里的主题),`summary` 一两句,`pages` 是页码。
|
|
13
|
+
- `questions`:学生的问题**按概念**归类(同一个概念在几页被问过就合成一条),`summary` 说学生具体想弄清什么。
|
|
14
|
+
- `weak`:学生还没弄懂的概念。依据包括:标了"还没懂"、反复追问同一点、问题本身暴露了误解、测验答错。`why` 用一句话说明依据。如果它和下面"已知的薄弱点"是同一个概念,`known` 写那个编号(如 `W3`),否则写 null。
|
|
15
|
+
- `understood`:学生已经弄懂的概念。依据只能是:标了"懂了"、测验答对、或者在后续追问里明显已经理解。**没问过不算弄懂。**
|
|
16
|
+
- `open`:学生问了但还没得到满意解答的问题(例如回答之后又追问、标了"还没懂"、或者没有回答)。
|
|
17
|
+
- `review`:建议复习的页(最多 5 页),`why` 一句话。
|
|
18
|
+
- 每一类都可以为空数组。宁缺毋滥。
|
|
19
|
+
- 用 {{language}} 写;专有名词保留原文;公式用 `$...$`。
|
|
20
|
+
|
|
21
|
+
## 这一讲的结构
|
|
22
|
+
|
|
23
|
+
{{outline}}
|
|
24
|
+
|
|
25
|
+
## 学生的问题
|
|
26
|
+
|
|
27
|
+
("新"表示上次总结之后才有的消息。助教的回答已截断,问题比回答更能说明学生卡在哪里。)
|
|
28
|
+
|
|
29
|
+
{{threads}}
|
|
30
|
+
|
|
31
|
+
## 学生的笔记
|
|
32
|
+
|
|
33
|
+
{{notes}}
|
|
34
|
+
|
|
35
|
+
## 测验作答
|
|
36
|
+
|
|
37
|
+
{{quiz}}
|
|
38
|
+
|
|
39
|
+
## 上一次的总结
|
|
40
|
+
|
|
41
|
+
(没有上一次就是"无"。有的话,在它的基础上更新:保留仍然成立的结论,根据新的消息修改。)
|
|
42
|
+
|
|
43
|
+
{{previous}}
|
|
44
|
+
|
|
45
|
+
## 已知的薄弱点(整门课的学习档案)
|
|
46
|
+
|
|
47
|
+
{{known_weak_points}}
|
|
48
|
+
|
|
49
|
+
{{feedback}}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
<!-- 讲解一页 slide。可用变量:{{course_title}} {{page}} {{page_count}} {{outline}} {{prev_text}} {{text}} {{next_text}} {{transcript}} {{language}} {{weak_points}}(学习档案里相关的薄弱点,没有时为空,整段不出现) -->
|
|
2
|
+
请为课件《{{course_title}}》的第 {{page}} / {{page_count}} 页写讲解。附图是这一页的原图。
|
|
3
|
+
|
|
4
|
+
## 整节课的结构
|
|
5
|
+
{{outline}}
|
|
6
|
+
|
|
7
|
+
## 上一页的文字
|
|
8
|
+
{{prev_text}}
|
|
9
|
+
|
|
10
|
+
## 这一页的文字(从 PDF 抽取,可能不完整,以图为准)
|
|
11
|
+
{{text}}
|
|
12
|
+
|
|
13
|
+
## 下一页的文字
|
|
14
|
+
{{next_text}}
|
|
15
|
+
|
|
16
|
+
## 老师讲这一页时说的话(transcript,可能没有)
|
|
17
|
+
{{transcript}}
|
|
18
|
+
{{weak_points}}
|
|
19
|
+
|
|
20
|
+
## 要求
|
|
21
|
+
- 用{{language}}。
|
|
22
|
+
- 如果这一页只是标题页、章节分隔页或目录,只用一两句话说明它在整节课里的位置,不要展开。
|
|
23
|
+
- 否则:先用一两句话说这一页要解决什么问题、和前一页怎么衔接;再逐个讲清楚页上的要点、公式(每个符号是什么意思)和图;最后指出最容易误解的地方。
|
|
24
|
+
- 不要逐字复述页面文字。不要写标题"讲解"。
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
<!-- 考前自测出题(DESIGN.md §13.5)。可以用 course tools 查材料;输出受 JSON schema 约束。可用变量:{{scope}} {{lectures}} {{profile}} {{count}} {{types}} {{focus}} {{language}} {{why_example}} {{feedback}} -->
|
|
2
|
+
学生要准备考试,请根据「{{scope}}」里的课件,以及学生学习时的提问和笔记,出一份考前自测,共 **{{count}} 道题**。
|
|
3
|
+
|
|
4
|
+
**输出语言:{{language}}。** 这份说明是中文写的,但输出里所有给学生看的文字(包括 `title`)都必须用 {{language}}。
|
|
5
|
+
|
|
6
|
+
## 范围内的讲次
|
|
7
|
+
|
|
8
|
+
{{lectures}}
|
|
9
|
+
|
|
10
|
+
## 学生卡住过的地方(按提问、追问、笔记加权排序)
|
|
11
|
+
|
|
12
|
+
{{profile}}
|
|
13
|
+
|
|
14
|
+
## 出题要求
|
|
15
|
+
|
|
16
|
+
- **侧重**:{{focus}}
|
|
17
|
+
- **题型**:只用这些:{{types}}。
|
|
18
|
+
- `mcq`:单选题,3–5 个选项,`answer` 是正确选项的字母(A、B、C…)。干扰项要像样,是学生真会犯的错误,不要一眼就能排除。**`stem` 只写题干,不要把选项写进题干;`options` 每项只写选项内容,不要加 "A." 之类的前缀**(界面会自动编号)。
|
|
19
|
+
- `short`:简答题,`options` 为空数组,`answer` 是参考答案的要点(2–4 句)。
|
|
20
|
+
- `derivation`:推导或计算题,`options` 为空数组,`answer` 写出关键步骤。
|
|
21
|
+
- **先计划再出题**:先定下每道题考哪个知识点,覆盖不同的讲次和主题,再逐题写。
|
|
22
|
+
- **每道题都要先用工具看过出处页**(`get_slide`;公式、图表多的页加 `image: true`),题目必须能根据课件回答,课件之外的内容不考。
|
|
23
|
+
- 学生问过的问题说明这里是难点,但**不要照抄学生问过的原话**,换个角度考同一个知识点(变一个条件、反过来问、和另一页的概念对比)。
|
|
24
|
+
- `sources`:出处,`lecture` 写讲次编号(如 `L2`),`page` 写页码。至少一个。
|
|
25
|
+
- `why`:一句话说为什么出这道题,直接对学生说,例如:{{why_example}}
|
|
26
|
+
- `explanation`:解析,说清为什么这是答案、常见的错误是什么。
|
|
27
|
+
- `topic`:知识点名称(不超过 15 个字)。`difficulty`:1 容易,2 中等,3 难。
|
|
28
|
+
- `title`:这份自测的标题。
|
|
29
|
+
- **所有给学生看的文字都用 {{language}}**:`title`、`stem`、`options`、`answer`、`explanation`、`why`、`topic`。专有名词保留原文。公式用 `$...$`。
|
|
30
|
+
- 题目之间不要重复。
|
|
31
|
+
|
|
32
|
+
{{feedback}}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<!-- 一页问答 session 的第一条消息(放在第一个问题前面)。可用变量:{{course_title}} {{page}} {{page_count}} {{text}} {{transcript}} {{explanation}} {{weak_points}}(学习档案里相关的薄弱点,没有时为空,整段不出现) -->
|
|
2
|
+
下面是课件《{{course_title}}》的第 {{page}} / {{page_count}} 页。附图里第一张是这一页的完整原图。
|
|
3
|
+
|
|
4
|
+
## 这一页的文字(从 PDF 抽取,以图为准)
|
|
5
|
+
{{text}}
|
|
6
|
+
|
|
7
|
+
## 老师讲这一页时说的话(transcript,可能没有)
|
|
8
|
+
{{transcript}}
|
|
9
|
+
|
|
10
|
+
## 学生已经看到的这一页讲解
|
|
11
|
+
{{explanation}}
|
|
12
|
+
{{weak_points}}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<!-- 追加在问答约定后面,开启"整门课检索"时使用(config: qa_retrieval)。可用变量:{{page_count}} -->
|
|
2
|
+
|
|
3
|
+
## 整门课的材料
|
|
4
|
+
|
|
5
|
+
当前目录里有整门课的材料,需要时可以查:
|
|
6
|
+
|
|
7
|
+
- `course.md`:全部 {{page_count}} 页的文字(每页一节,标题是"第 N 页"),以及老师讲每页时的 transcript(如果有)。
|
|
8
|
+
- `page-N.png`:第 N 页的原图(N = 1–{{page_count}})。
|
|
9
|
+
|
|
10
|
+
用法:
|
|
11
|
+
|
|
12
|
+
- 只有问题涉及**这一页以外**的内容时才去查(比如"这个符号前面在哪定义的"、"和第几页的方法有什么区别"、"后面还会讲吗")。只问这一页的问题,直接回答。
|
|
13
|
+
- 先用 Grep 在 `course.md` 里搜关键词定位页码,必要时再用 Read 看那一页的图。不要一页一页地读。
|
|
14
|
+
- 回答里引用别的页时写明"第 N 页",方便学生翻过去看。
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
<!-- 追加在角色设定后面,用于每一页的问答 session(DESIGN.md §7)。可用变量:{{language}} -->
|
|
2
|
+
|
|
3
|
+
## 问答约定
|
|
4
|
+
|
|
5
|
+
这个对话专门用于课件的**某一页**。学生会在这一页的图上框选区域提问,或者在讲解里选中一段文字提问;每个问题是一个独立的 thread。
|
|
6
|
+
|
|
7
|
+
- 每条学生消息开头有一个标签,例如 `[Thread #2 · 选区 x=0.15 y=0.72 w=0.66 h=0.21 · 新问题]`、`[Thread #3 · 讲解中选中的一段 · 新问题]` 或 `[Thread #2 · 追问]`。坐标是相对整页的比例(左上角为原点)。
|
|
8
|
+
- **只回答标签所指的那个 thread。** 学生在界面上每个 thread 是一个单独的对话框,只看得到这个 thread 自己的问答。
|
|
9
|
+
- 可以利用其他 thread 里已经讲过的内容,但回答必须能独立看懂;需要时简短复述,不要说"如上所述"、"在 Thread #1 里"。
|
|
10
|
+
- 框选的新问题会附上选区的裁剪图,以及选区覆盖到的文字(如果有);讲解里选中的问题会附上那段文字。学生说"这个"、"这里"时,指的就是选区或选中的文字。
|
|
11
|
+
- 回答不要带标签。用{{language}}回答,除非学生用别的语言提问。
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
<!-- 核对自测题的答案(DESIGN.md §13.5 第 4 步)。可以用 course tools 查材料;输出受 JSON schema 约束。可用变量:{{questions}} {{language}} -->
|
|
2
|
+
下面是根据课件出的自测题,每道题带标准答案和出处。请逐题核对**标准答案和课件内容是否一致**。
|
|
3
|
+
|
|
4
|
+
- 每道题都用工具看出处页(`get_slide`,需要时加 `image: true`),必要时用 `search_course` 查别处。
|
|
5
|
+
- `ok`:答案正确,并且能根据课件得出,就是 true。答案错误、选择题有不止一个正确选项、或者课件里找不到依据,就是 false。
|
|
6
|
+
- `reason`:`ok` 为 false 时,用{{language}}写一句话说明问题;为 true 时留空字符串。
|
|
7
|
+
- 只核对,不要改题。每道题都要给出结果,`n` 是题号。
|
|
8
|
+
|
|
9
|
+
## 题目
|
|
10
|
+
|
|
11
|
+
{{questions}}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
<!-- 更新整门课的学习档案(DESIGN.md §15.4.2 A)。输入都在这条消息里,不用工具;输出受 JSON schema 约束。可用变量:{{language}} {{current}} {{resolved}} {{findings}} {{pending}} {{limit}} -->
|
|
2
|
+
你在维护一个学生这门课的**学习档案**:按概念记录学生还没弄懂的地方(薄弱点)。下面是现在的档案,以及刚得到的新证据。请输出一组操作来更新档案。
|
|
3
|
+
|
|
4
|
+
**输出语言:{{language}}。** 新的或改过的 `concept`、`summary`、`reason` 都用 {{language}}。
|
|
5
|
+
|
|
6
|
+
所有内容都在这条消息里,不要使用任何工具。
|
|
7
|
+
|
|
8
|
+
## 现在的薄弱点
|
|
9
|
+
|
|
10
|
+
{{current}}
|
|
11
|
+
|
|
12
|
+
已经解决的(只列名称)。新证据如果又是这些概念,**用原来的编号**(attach,需要时用 status 改回 open),不要新建:
|
|
13
|
+
|
|
14
|
+
{{resolved}}
|
|
15
|
+
|
|
16
|
+
## 新证据:刚完成的一讲总结
|
|
17
|
+
|
|
18
|
+
(F 开头的编号。`weak` / `open` 说明学生还不会,`understood` 说明学生弄懂了。)
|
|
19
|
+
|
|
20
|
+
{{findings}}
|
|
21
|
+
|
|
22
|
+
## 新证据:还没归类的测验错题
|
|
23
|
+
|
|
24
|
+
(P 开头的编号。)
|
|
25
|
+
|
|
26
|
+
{{pending}}
|
|
27
|
+
|
|
28
|
+
## 可以用的操作
|
|
29
|
+
|
|
30
|
+
- `{"op": "add", "concept": "…", "summary": "…", "evidence": ["F1"]}`:新的薄弱点。只有新证据里出现了档案里**没有**的概念时才加。证据里至少要有一条说明学生不会的(`weak`、`open` 或测验错题)。编号由系统分配,不要自己写 `id`。
|
|
31
|
+
- `{"op": "attach", "id": "W3", "evidence": ["F2", "P1"]}`:新证据属于已有的薄弱点(同一个概念,哪怕在不同的讲次、说法不同)。
|
|
32
|
+
- `{"op": "status", "id": "W2", "to": "improving" | "resolved" | "open", "reason": "…", "evidence": ["F4"]}`:改状态。改成 `resolved` 必须有学生弄懂了的证据(`understood`)。
|
|
33
|
+
- `{"op": "merge", "from": "W5", "into": "W3", "reason": "…"}`:两条其实是同一个概念。
|
|
34
|
+
- `{"op": "edit", "id": "W3", "concept": "…", "summary": "…"}`:改名或者改写摘要,让它更准确。
|
|
35
|
+
|
|
36
|
+
## 要求
|
|
37
|
+
|
|
38
|
+
- **优先归到已有的薄弱点**(attach),不要为同一个概念再加一条。总结里写明"就是 Wn"的,一般就 attach 到那一条。
|
|
39
|
+
- 概念名要具体("多头注意力里每个头的维度"),不要太宽("注意力")。`summary` 一句话说学生具体卡在哪里。
|
|
40
|
+
- 没有新证据支撑的操作不要做。没有需要做的就输出空的 `ops`。
|
|
41
|
+
- {{limit}}
|
gloss/cli.py
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"""`gloss` command.
|
|
2
|
+
|
|
3
|
+
gloss start the app and open it in the browser
|
|
4
|
+
gloss doctor [--live] check that Gloss can run here
|
|
5
|
+
gloss export FILE write a course as Markdown
|
|
6
|
+
gloss mcp-serve (internal) course tools for claude, over stdio (DESIGN.md §13.4)
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import argparse
|
|
12
|
+
import socket
|
|
13
|
+
import sys
|
|
14
|
+
import threading
|
|
15
|
+
import time
|
|
16
|
+
import urllib.request
|
|
17
|
+
import webbrowser
|
|
18
|
+
from pathlib import Path
|
|
19
|
+
|
|
20
|
+
DEFAULT_PORT = 8765
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def free_port(start: int, tries: int = 20) -> int:
|
|
24
|
+
for port in range(start, start + tries):
|
|
25
|
+
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
|
26
|
+
try:
|
|
27
|
+
s.bind(("127.0.0.1", port))
|
|
28
|
+
return port
|
|
29
|
+
except OSError:
|
|
30
|
+
continue
|
|
31
|
+
raise SystemExit(f"no free port in {start}–{start + tries - 1}; pass --port")
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def open_when_ready(url: str, timeout: float = 30) -> None:
|
|
35
|
+
deadline = time.monotonic() + timeout
|
|
36
|
+
while time.monotonic() < deadline:
|
|
37
|
+
try:
|
|
38
|
+
urllib.request.urlopen(url + "api/health", timeout=2).close()
|
|
39
|
+
webbrowser.open(url)
|
|
40
|
+
return
|
|
41
|
+
except OSError:
|
|
42
|
+
time.sleep(0.3)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def serve(args: argparse.Namespace) -> int:
|
|
46
|
+
import uvicorn
|
|
47
|
+
|
|
48
|
+
from .config import Config
|
|
49
|
+
from .doctor import run_checks
|
|
50
|
+
from .server import create_app
|
|
51
|
+
|
|
52
|
+
cfg = Config.load()
|
|
53
|
+
problems = [c for c in run_checks(cfg) if c.status == "fail"]
|
|
54
|
+
for c in problems:
|
|
55
|
+
print(f" ✗ {c.name}: {c.detail}", file=sys.stderr)
|
|
56
|
+
if problems:
|
|
57
|
+
print(" (run `gloss doctor` for details; starting anyway)\n", file=sys.stderr)
|
|
58
|
+
|
|
59
|
+
port = args.port or free_port(DEFAULT_PORT)
|
|
60
|
+
url = f"http://127.0.0.1:{port}/"
|
|
61
|
+
print(f"Gloss is running at {url} (Ctrl+C to stop)", flush=True)
|
|
62
|
+
if not args.no_browser:
|
|
63
|
+
threading.Thread(target=open_when_ready, args=(url,), daemon=True).start()
|
|
64
|
+
uvicorn.run(create_app(cfg), host="127.0.0.1", port=port, log_level="warning")
|
|
65
|
+
return 0
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def export(args: argparse.Namespace) -> int:
|
|
69
|
+
from .config import app_dir
|
|
70
|
+
from .export import export_markdown
|
|
71
|
+
from .i18n import Prefs
|
|
72
|
+
from .store import Course
|
|
73
|
+
|
|
74
|
+
src = Path(args.file)
|
|
75
|
+
out = Path(args.output) if args.output else src.with_suffix(".md")
|
|
76
|
+
with Course.open(src) as c:
|
|
77
|
+
out.write_text(export_markdown(c, Prefs(app_dir() / "prefs.json").locale), encoding="utf-8")
|
|
78
|
+
print(f"wrote {out}")
|
|
79
|
+
return 0
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def main(argv: list[str] | None = None) -> None:
|
|
83
|
+
ap = argparse.ArgumentParser(prog="gloss", description="Ask questions right on your lecture slides.")
|
|
84
|
+
ap.add_argument("--port", type=int, help=f"port to listen on (default: first free from {DEFAULT_PORT})")
|
|
85
|
+
ap.add_argument("--no-browser", action="store_true", help="don't open the browser")
|
|
86
|
+
sub = ap.add_subparsers(dest="cmd")
|
|
87
|
+
d = sub.add_parser("doctor", help="check that Gloss can run here")
|
|
88
|
+
d.add_argument("--live", action="store_true", help="also send a tiny test prompt (uses a little quota)")
|
|
89
|
+
e = sub.add_parser("export", help="export a .gloss course as Markdown")
|
|
90
|
+
e.add_argument("file")
|
|
91
|
+
e.add_argument("-o", "--output", help="output path (default: next to the file, .md)")
|
|
92
|
+
m = sub.add_parser("mcp-serve", help="(internal) serve the course tools to claude over stdio")
|
|
93
|
+
m.add_argument("--library", required=True)
|
|
94
|
+
m.add_argument("--folder", default="")
|
|
95
|
+
m.add_argument("--only", help="comma-separated lecture labels or course ids")
|
|
96
|
+
args = ap.parse_args(argv)
|
|
97
|
+
|
|
98
|
+
if args.cmd == "mcp-serve":
|
|
99
|
+
from .mcp_server import serve as mcp_serve
|
|
100
|
+
mcp_serve(Path(args.library), args.folder, args.only.split(",") if args.only else None)
|
|
101
|
+
sys.exit(0)
|
|
102
|
+
if args.cmd == "doctor":
|
|
103
|
+
from .doctor import main as doctor_main
|
|
104
|
+
sys.exit(doctor_main(["--live"] if args.live else []))
|
|
105
|
+
if args.cmd == "export":
|
|
106
|
+
sys.exit(export(args))
|
|
107
|
+
sys.exit(serve(args))
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
if __name__ == "__main__":
|
|
111
|
+
main()
|
gloss/config.py
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"""App configuration (`config.toml`, see config.example.toml).
|
|
2
|
+
|
|
3
|
+
Two ways to run Gloss:
|
|
4
|
+
- From a git clone (`uv run gloss`): config.toml and claude_workspace/ live in the repo.
|
|
5
|
+
- Installed (`pip install`): config.toml and the runtime workspace live in ~/.gloss/
|
|
6
|
+
(override with GLOSS_HOME). The workspace is seeded from the copy bundled in the
|
|
7
|
+
package; files you edit there are never overwritten.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
import os
|
|
13
|
+
import shutil
|
|
14
|
+
import tomllib
|
|
15
|
+
from dataclasses import dataclass, field, fields
|
|
16
|
+
from pathlib import Path
|
|
17
|
+
|
|
18
|
+
PACKAGE_DIR = Path(__file__).resolve().parent
|
|
19
|
+
REPO_ROOT = PACKAGE_DIR.parents[1]
|
|
20
|
+
REPO_WORKSPACE = REPO_ROOT / "claude_workspace"
|
|
21
|
+
BUNDLED_WORKSPACE = PACKAGE_DIR / "_workspace" # only present in a built wheel
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def app_dir() -> Path:
|
|
25
|
+
"""Per-user app data (recent files list; config and workspace when installed). Not inside any .gloss."""
|
|
26
|
+
if env := os.environ.get("GLOSS_HOME"):
|
|
27
|
+
return Path(env)
|
|
28
|
+
return Path.home() / ".gloss"
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def in_repo() -> bool:
|
|
32
|
+
return (REPO_WORKSPACE / "CLAUDE.md").exists()
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def config_path() -> Path:
|
|
36
|
+
if env := os.environ.get("GLOSS_CONFIG"):
|
|
37
|
+
return Path(env)
|
|
38
|
+
return REPO_ROOT / "config.toml" if in_repo() else app_dir() / "config.toml"
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def default_workspace() -> Path:
|
|
42
|
+
if in_repo():
|
|
43
|
+
return REPO_WORKSPACE
|
|
44
|
+
ws = app_dir() / "workspace"
|
|
45
|
+
seed_workspace(BUNDLED_WORKSPACE, ws)
|
|
46
|
+
return ws
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def seed_workspace(src: Path, dst: Path) -> None:
|
|
50
|
+
"""Copy runtime prompts into `dst`, adding missing files only (user edits win)."""
|
|
51
|
+
if not src.exists():
|
|
52
|
+
return
|
|
53
|
+
for f in src.rglob("*.md"):
|
|
54
|
+
target = dst / f.relative_to(src)
|
|
55
|
+
if not target.exists():
|
|
56
|
+
target.parent.mkdir(parents=True, exist_ok=True)
|
|
57
|
+
shutil.copyfile(f, target)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
@dataclass
|
|
61
|
+
class Config:
|
|
62
|
+
provider: str = "claude_cli" # claude_cli (your Claude login) | anthropic_api (ANTHROPIC_API_KEY, `glossr[api]`)
|
|
63
|
+
model: str = "sonnet"
|
|
64
|
+
concurrency: int = 2 # global cap on simultaneous LLM calls
|
|
65
|
+
language: str | None = None # explanation / answer language; None follows the interface language (§9.3)
|
|
66
|
+
workspace: Path = field(default_factory=default_workspace)
|
|
67
|
+
library: Path = field(default_factory=lambda: Path.home() / "Gloss") # where new .gloss files go
|
|
68
|
+
claude_bin: str | None = None # default: found on PATH
|
|
69
|
+
timeout: float = 600 # seconds per call
|
|
70
|
+
qa_retrieval: bool = True # answers may search the whole course (Grep/Read in the course folder)
|
|
71
|
+
quiz_model: str | None = None # model for pre-quiz generation (§13.5); None = `model`
|
|
72
|
+
quiz_verify: bool = True # a second call checks every answer key against the slides
|
|
73
|
+
digest_model: str | None = None # model for lecture summaries (§15.3); None = `model`
|
|
74
|
+
use_profile: bool = True # mention relevant study-profile weak points in explanations and Q&A (§15.5)
|
|
75
|
+
|
|
76
|
+
@classmethod
|
|
77
|
+
def load(cls, path: Path | None = None) -> Config:
|
|
78
|
+
path = path or config_path()
|
|
79
|
+
if not path.exists():
|
|
80
|
+
return cls()
|
|
81
|
+
data = tomllib.loads(path.read_text())
|
|
82
|
+
known = {f.name for f in fields(cls)}
|
|
83
|
+
unknown = set(data) - known
|
|
84
|
+
if unknown:
|
|
85
|
+
raise ValueError(f"unknown config keys in {path}: {sorted(unknown)}")
|
|
86
|
+
for k in ("workspace", "library"):
|
|
87
|
+
if k in data:
|
|
88
|
+
data[k] = Path(data[k]).expanduser()
|
|
89
|
+
return cls(**data)
|