dsh-learning-assistant 0.0.2 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/README.md +41 -7
  2. package/assets/collect/README.md +55 -0
  3. package/assets/skills/course-inbox-sync.md +182 -0
  4. package/assets/skills/course-material-digest.md +173 -0
  5. package/assets/skills/one-to-one-tutor.md +320 -0
  6. package/assets/tools/pdf/pdf-render.ps1 +30 -0
  7. package/assets/tools/pptx-digest.py +99 -0
  8. package/assets/tools/pptx-map.py +98 -0
  9. package/assets/tools/pptx-media.py +101 -0
  10. package/assets/tools/qq-group-msg.py +258 -0
  11. package/assets/tools/qq-group-sync.py +265 -0
  12. package/docs//345/215/217/344/275/234/345/274/200/345/217/221.md +18 -10
  13. package/lib/client.js +110 -0
  14. package/lib/{index.d.mts → index.d.ts} +3 -1
  15. package/lib/index.js +392 -0
  16. package/package.json +8 -7
  17. package/src/client/settings.tsx +6 -4
  18. package/src/index.ts +36 -11
  19. package/src/practice/learn/api.mjs +393 -0
  20. package/src/practice/learn/cli.mjs +175 -0
  21. package/src/practice/learn/curriculum.mjs +292 -0
  22. package/src/practice/learn/handoff.mjs +73 -0
  23. package/src/practice/learn/jsonschema.mjs +171 -0
  24. package/src/practice/learn/mapping.mjs +90 -0
  25. package/src/practice/learn/progress.mjs +247 -0
  26. package/src/practice/learn/schema/curriculum.schema.json +88 -0
  27. package/src/practice/learn/schema/handoff.schema.json +56 -0
  28. package/src/practice/learn/schema/node-practice-map.schema.json +28 -0
  29. package/src/practice/learn/schema/progress.schema.json +66 -0
  30. package/src/practice/learn/schemas.mjs +53 -0
  31. package/src/practice/learn/store.mjs +247 -0
  32. package/src/practice/public/app.js +883 -0
  33. package/src/practice/public/index.html +19 -0
  34. package/src/practice/public/ink.js +349 -0
  35. package/src/practice/public/learn.css +20 -0
  36. package/src/practice/public/learn.js +329 -0
  37. package/src/practice/public/style.css +326 -0
  38. package/src/practice/public/vendor/katex/contrib/auto-render.min.js +1 -0
  39. package/src/practice/public/vendor/katex/fonts/KaTeX_AMS-Regular.woff2 +0 -0
  40. package/src/practice/public/vendor/katex/fonts/KaTeX_Caligraphic-Bold.woff2 +0 -0
  41. package/src/practice/public/vendor/katex/fonts/KaTeX_Caligraphic-Regular.woff2 +0 -0
  42. package/src/practice/public/vendor/katex/fonts/KaTeX_Fraktur-Bold.woff2 +0 -0
  43. package/src/practice/public/vendor/katex/fonts/KaTeX_Fraktur-Regular.woff2 +0 -0
  44. package/src/practice/public/vendor/katex/fonts/KaTeX_Main-Bold.woff2 +0 -0
  45. package/src/practice/public/vendor/katex/fonts/KaTeX_Main-BoldItalic.woff2 +0 -0
  46. package/src/practice/public/vendor/katex/fonts/KaTeX_Main-Italic.woff2 +0 -0
  47. package/src/practice/public/vendor/katex/fonts/KaTeX_Main-Regular.woff2 +0 -0
  48. package/src/practice/public/vendor/katex/fonts/KaTeX_Math-BoldItalic.woff2 +0 -0
  49. package/src/practice/public/vendor/katex/fonts/KaTeX_Math-Italic.woff2 +0 -0
  50. package/src/practice/public/vendor/katex/fonts/KaTeX_SansSerif-Bold.woff2 +0 -0
  51. package/src/practice/public/vendor/katex/fonts/KaTeX_SansSerif-Italic.woff2 +0 -0
  52. package/src/practice/public/vendor/katex/fonts/KaTeX_SansSerif-Regular.woff2 +0 -0
  53. package/src/practice/public/vendor/katex/fonts/KaTeX_Script-Regular.woff2 +0 -0
  54. package/src/practice/public/vendor/katex/fonts/KaTeX_Size1-Regular.woff2 +0 -0
  55. package/src/practice/public/vendor/katex/fonts/KaTeX_Size2-Regular.woff2 +0 -0
  56. package/src/practice/public/vendor/katex/fonts/KaTeX_Size3-Regular.woff2 +0 -0
  57. package/src/practice/public/vendor/katex/fonts/KaTeX_Size4-Regular.woff2 +0 -0
  58. package/src/practice/public/vendor/katex/fonts/KaTeX_Typewriter-Regular.woff2 +0 -0
  59. package/src/practice/public/vendor/katex/katex.min.css +1 -0
  60. package/src/practice/public/vendor/katex/katex.min.js +1 -0
  61. package/src/practice//346/234/215/345/212/241.mjs +443 -0
  62. package/src/practice//346/240/241/351/252/214/351/242/230/347/233/256.mjs +114 -0
  63. package/src/practice//347/255/211/345/276/205/346/217/220/344/272/244.mjs +100 -0
  64. package/src/practice-service.ts +99 -0
  65. package/src/practice-tool.ts +91 -0
  66. package/src/skills.ts +156 -0
  67. package/lib/client.d.mts +0 -10
  68. package/lib/client.mjs +0 -87
  69. package/lib/index.mjs +0 -29
@@ -0,0 +1,19 @@
1
+ <!doctype html>
2
+ <html lang="zh-CN">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1">
6
+ <title>练习台</title>
7
+ <link rel="stylesheet" href="./vendor/katex/katex.min.css">
8
+ <link rel="stylesheet" href="./style.css">
9
+ <link rel="stylesheet" href="./learn.css">
10
+ </head>
11
+ <body>
12
+ <div id="app"></div>
13
+ <script src="./vendor/katex/katex.min.js"></script>
14
+ <script src="./vendor/katex/contrib/auto-render.min.js"></script>
15
+ <script src="./ink.js"></script>
16
+ <script src="./app.js"></script>
17
+ <script src="./learn.js"></script>
18
+ </body>
19
+ </html>
@@ -0,0 +1,349 @@
1
+ /* 白板笔迹组件(填空题 / 大题手写作答)
2
+ *
3
+ * 设计要点(为「智能体读图批改」服务,不是为了好看):
4
+ * 1. 坐标存成**固定逻辑坐标**(逻辑宽恒为 1000,x/y 同倍率缩放),
5
+ * 所以窗口变宽、画布加高都不会让已经写好的笔迹变形;
6
+ * 2. 导出 PNG 固定 1400px 宽、纯白底、纯黑墨,避免暗色主题把字吃进背景,
7
+ * 也避免读图时被自动降采样糊掉上下标;
8
+ * 3. 一题一块画布 → 落盘一题一个文件,智能体不用在整页图里找题。
9
+ *
10
+ * 工具:笔(三档粗细)+ 橡皮擦。橡皮擦按「整笔擦」工作——
11
+ * 点/划到哪一笔就整笔消失,这样改错别字比像素级擦干净得多。
12
+ *
13
+ * 对外:window.InkPad.create({ height, placeholder, onChange, growable })
14
+ * 返回 { el, isEmpty(), strokeCount(), toPNG(), clear(), grow(px), relayout() }
15
+ */
16
+ (() => {
17
+ 'use strict';
18
+
19
+ const LOGIC_W = 1000; // 逻辑坐标宽度,所有点都按这个尺度存
20
+ const PEN_SIZES = [2.0, 3.2, 4.6]; // CSS 像素(细 / 中 / 粗),存盘时换算成逻辑单位
21
+ const EXPORT_WIDTH = 1400; // 导出宽度:够看清上下标,又不至于大到读图变慢
22
+ const MIN_STEP = 1.6; // 逻辑坐标最小采样间距,去掉抖动点
23
+ const ERASER_CSS = 13; // 橡皮擦半径(CSS 像素)
24
+
25
+ const mk = (tag, cls, text) => {
26
+ const n = document.createElement(tag);
27
+ if (cls) n.className = cls;
28
+ if (text != null) n.textContent = text;
29
+ return n;
30
+ };
31
+
32
+ /* ---------- 光标:笔尖 / 橡皮 ----------
33
+ * 用内联 SVG 做光标(不是系统十字线)。热点放在笔尖上,
34
+ * 所以落笔位置和看到的笔尖重合,不会有偏移感。
35
+ */
36
+ const PEN_SVG = `<svg xmlns="http://www.w3.org/2000/svg" width="26" height="26" viewBox="0 0 26 26">
37
+ <path d="M3 23 4.6 17.2 16.9 4.9a2.5 2.5 0 0 1 3.5 3.5L8.1 20.7 3 23Z"
38
+ fill="#ffffff" stroke="#15181c" stroke-width="1.6" stroke-linejoin="round"/>
39
+ <path d="M15.4 6.4 19 10" stroke="#15181c" stroke-width="1.6" stroke-linecap="round"/>
40
+ </svg>`;
41
+
42
+ const ERASER_SVG = `<svg xmlns="http://www.w3.org/2000/svg" width="26" height="26" viewBox="0 0 26 26">
43
+ <g transform="rotate(-45 13 13)">
44
+ <rect x="6.5" y="7.5" width="13" height="11" rx="2" fill="#ffffff" stroke="#15181c" stroke-width="1.6"/>
45
+ <rect x="6.5" y="7.5" width="13" height="4" rx="2" fill="#cfd8e3" stroke="#15181c" stroke-width="1.4"/>
46
+ </g>
47
+ </svg>`;
48
+
49
+ const cursorOf = (svg, hx, hy, fallback) =>
50
+ `url("data:image/svg+xml;charset=utf-8,${encodeURIComponent(svg)}") ${hx} ${hy}, ${fallback}`;
51
+
52
+ // 笔尖热点 (3,23);橡皮热点取正中
53
+ const PEN_CURSOR = cursorOf(PEN_SVG, 3, 23, 'crosshair');
54
+ const ERASER_CURSOR = cursorOf(ERASER_SVG, 13, 13, 'cell');
55
+
56
+ function create(opts) {
57
+ const o = Object.assign(
58
+ { height: 180, placeholder: '在这里手写作答', onChange: null, growable: false },
59
+ opts || {}
60
+ );
61
+
62
+ const wrap = mk('div', 'inkpad');
63
+ const tools = mk('div', 'inkpad-tools');
64
+ const stage = mk('div', 'inkpad-stage');
65
+ const canvas = mk('canvas');
66
+ const hint = mk('div', 'inkpad-hint', o.placeholder);
67
+
68
+ const status = mk('span', 'inkpad-status', '空');
69
+ const eraserBtn = mk('button', 'inkpad-btn inkpad-eraser', '橡皮擦');
70
+ const growBtn = mk('button', 'inkpad-btn', '加高');
71
+ [eraserBtn, growBtn].forEach((b) => { b.type = 'button'; });
72
+ eraserBtn.title = '擦掉整笔:点或划过要删掉的笔迹';
73
+ growBtn.title = '题目较长时可以多写几行';
74
+
75
+ const sizeBtns = PEN_SIZES.map((px, i) => {
76
+ const b = mk('button', 'inkpad-btn inkpad-size', '');
77
+ b.type = 'button';
78
+ b.title = ['细笔', '中笔', '粗笔'][i];
79
+ b.dataset.pen = String(i);
80
+ const dot = mk('i');
81
+ dot.style.width = dot.style.height = Math.round(px + 2) + 'px';
82
+ b.appendChild(dot);
83
+ return b;
84
+ });
85
+
86
+ const group = mk('div', 'inkpad-group');
87
+ sizeBtns.forEach((b) => group.appendChild(b));
88
+
89
+ tools.append(group, mk('span', 'inkpad-sep'), eraserBtn);
90
+ if (o.growable) tools.append(growBtn);
91
+ tools.append(status);
92
+ stage.appendChild(canvas);
93
+ stage.appendChild(hint);
94
+ wrap.append(tools, stage);
95
+
96
+ // 笔迹:{ size: 逻辑单位笔宽, pts: [{x, y, p}] },x/y 都是逻辑坐标
97
+ let strokes = [];
98
+ let cur = null;
99
+ let penIdx = 1;
100
+ let mode = 'pen'; // 'pen' | 'eraser'
101
+ let erasing = false;
102
+ let cssW = 1; // 当前画布 CSS 宽度
103
+ let height = o.height; // 当前画布 CSS 高度(可增长)
104
+ let dpr = 1;
105
+
106
+ const penCss = () => PEN_SIZES[penIdx];
107
+ // CSS 像素 → 逻辑单位
108
+ const toLogic = (px) => (px * LOGIC_W) / Math.max(1, cssW);
109
+
110
+ /* ---------- 绘制 ---------- */
111
+
112
+ function paint(ctx, w, h) {
113
+ // 必须先清空再重画。否则「擦掉一笔」只是不再画它,旧像素还留在画布上,
114
+ // 看起来就像橡皮擦没生效。(重设 canvas.width 也能清屏,但那条路只在 layout 里走。)
115
+ ctx.clearRect(0, 0, w, h);
116
+ ctx.save();
117
+ ctx.lineCap = 'round';
118
+ ctx.lineJoin = 'round';
119
+ ctx.strokeStyle = '#111';
120
+ ctx.fillStyle = '#111';
121
+ const k = w / LOGIC_W; // 逻辑单位 → 目标像素
122
+ for (const s of strokes) {
123
+ const pts = s.pts;
124
+ if (!pts.length) continue;
125
+ const base = s.size * k;
126
+ if (pts.length === 1) {
127
+ const p = pts[0];
128
+ ctx.beginPath();
129
+ ctx.arc(p.x * k, p.y * k, Math.max(0.6, (base * (0.6 + p.p * 0.6)) / 2), 0, Math.PI * 2);
130
+ ctx.fill();
131
+ continue;
132
+ }
133
+ for (let i = 1; i < pts.length; i++) {
134
+ const a = pts[i - 1];
135
+ const b = pts[i];
136
+ ctx.beginPath();
137
+ ctx.lineWidth = Math.max(0.6, base * (0.6 + ((a.p + b.p) / 2) * 0.6));
138
+ ctx.moveTo(a.x * k, a.y * k);
139
+ ctx.lineTo(b.x * k, b.y * k);
140
+ ctx.stroke();
141
+ }
142
+ }
143
+ ctx.restore();
144
+ }
145
+
146
+ function redraw() { paint(canvas.getContext('2d'), canvas.width, canvas.height); }
147
+
148
+ /* ---------- 尺寸 ---------- */
149
+
150
+ function layout() {
151
+ const r = stage.getBoundingClientRect();
152
+ cssW = Math.max(1, Math.round(r.width));
153
+ dpr = Math.min(2.5, window.devicePixelRatio || 1);
154
+ canvas.style.width = cssW + 'px';
155
+ canvas.style.height = height + 'px';
156
+ canvas.width = Math.round(cssW * dpr);
157
+ canvas.height = Math.round(height * dpr);
158
+ redraw();
159
+ }
160
+
161
+ /* ---------- 状态 ---------- */
162
+
163
+ function applyCursor() {
164
+ canvas.style.cursor = mode === 'eraser' ? ERASER_CURSOR : PEN_CURSOR;
165
+ wrap.classList.toggle('eraser', mode === 'eraser');
166
+ }
167
+
168
+ function refreshState() {
169
+ const n = strokes.length;
170
+ status.textContent = n ? `${n} 笔` : '空';
171
+ eraserBtn.disabled = !n && mode !== 'eraser';
172
+ eraserBtn.classList.toggle('on', mode === 'eraser');
173
+ hint.style.display = n ? 'none' : '';
174
+ sizeBtns.forEach((b, i) => b.classList.toggle('on', i === penIdx && mode === 'pen'));
175
+ if (typeof o.onChange === 'function') o.onChange(n);
176
+ }
177
+
178
+ function setMode(next) {
179
+ mode = next;
180
+ // 换回笔时保留原来选的粗细;切橡皮时取消进行中的笔画
181
+ cur = null;
182
+ erasing = false;
183
+ applyCursor();
184
+ refreshState();
185
+ }
186
+
187
+ /* ---------- 手写事件 ---------- */
188
+
189
+ function posOf(ev) {
190
+ const r = canvas.getBoundingClientRect();
191
+ let p = ev.pressure;
192
+ // 鼠标、部分数位笔报 0 或恒定值:给个中值,笔迹不至于细成一条
193
+ if (!p || p <= 0) p = 0.5;
194
+ return {
195
+ // x、y 都除以宽度:两轴同倍率,画布比例变了也不走形
196
+ x: ((ev.clientX - r.left) / Math.max(1, r.width)) * LOGIC_W,
197
+ y: ((ev.clientY - r.top) / Math.max(1, r.width)) * LOGIC_W,
198
+ p: Math.min(1, p),
199
+ };
200
+ }
201
+
202
+ // 点到线段距离:橡皮擦判断「擦到这一笔没有」
203
+ function distToSeg(p, a, b) {
204
+ const dx = b.x - a.x;
205
+ const dy = b.y - a.y;
206
+ const len2 = dx * dx + dy * dy;
207
+ if (len2 === 0) return Math.hypot(p.x - a.x, p.y - a.y);
208
+ let t = ((p.x - a.x) * dx + (p.y - a.y) * dy) / len2;
209
+ t = t < 0 ? 0 : t > 1 ? 1 : t;
210
+ return Math.hypot(p.x - (a.x + t * dx), p.y - (a.y + t * dy));
211
+ }
212
+
213
+ function eraseAt(p) {
214
+ const r = toLogic(ERASER_CSS);
215
+ const before = strokes.length;
216
+ strokes = strokes.filter((s) => {
217
+ const pts = s.pts;
218
+ if (!pts.length) return false;
219
+ // 笔画本身有粗细,命中半径再加上半个笔宽,擦起来才跟手感一致
220
+ const pad = s.size / 2;
221
+ if (pts.length === 1) return Math.hypot(p.x - pts[0].x, p.y - pts[0].y) > r + pad;
222
+ for (let i = 1; i < pts.length; i++) {
223
+ if (distToSeg(p, pts[i - 1], pts[i]) <= r + pad) return false;
224
+ }
225
+ return true;
226
+ });
227
+ if (strokes.length !== before) {
228
+ refreshState();
229
+ redraw();
230
+ }
231
+ }
232
+
233
+ function down(ev) {
234
+ if (ev.pointerType === 'mouse' && ev.button !== 0) return;
235
+ ev.preventDefault();
236
+ try { canvas.setPointerCapture(ev.pointerId); } catch { /* 某些合成事件没有 pointerId */ }
237
+
238
+ if (mode === 'eraser') {
239
+ erasing = true;
240
+ eraseAt(posOf(ev));
241
+ return;
242
+ }
243
+
244
+ cur = { size: toLogic(penCss()), pts: [posOf(ev)] };
245
+ strokes.push(cur);
246
+ refreshState();
247
+ redraw();
248
+ }
249
+
250
+ function move(ev) {
251
+ if (mode === 'eraser') {
252
+ if (!erasing) return;
253
+ ev.preventDefault();
254
+ const list = ev.getCoalescedEvents ? ev.getCoalescedEvents() : [];
255
+ for (const e of (list.length ? list : [ev])) eraseAt(posOf(e));
256
+ return;
257
+ }
258
+ if (!cur) return;
259
+ ev.preventDefault();
260
+ // 数位板采样率高,把一帧内的 coalesced 事件全取出来,转折才不丢
261
+ const list = ev.getCoalescedEvents ? ev.getCoalescedEvents() : [];
262
+ const batch = list.length ? list : [ev];
263
+ const pts = cur.pts;
264
+ for (const e of batch) {
265
+ const p = posOf(e);
266
+ const last = pts[pts.length - 1];
267
+ if (Math.abs(p.x - last.x) + Math.abs(p.y - last.y) < MIN_STEP) continue;
268
+ pts.push(p);
269
+ }
270
+ redraw();
271
+ }
272
+
273
+ function up(ev) {
274
+ try { canvas.releasePointerCapture(ev.pointerId); } catch { /* 已释放 */ }
275
+ erasing = false;
276
+ if (cur) {
277
+ cur = null;
278
+ refreshState();
279
+ }
280
+ }
281
+
282
+ canvas.addEventListener('pointerdown', down);
283
+ canvas.addEventListener('pointermove', move);
284
+ canvas.addEventListener('pointerup', up);
285
+ canvas.addEventListener('pointercancel', up);
286
+ canvas.addEventListener('pointerleave', up);
287
+ canvas.addEventListener('touchstart', (e) => e.preventDefault(), { passive: false });
288
+
289
+ eraserBtn.addEventListener('click', () => setMode(mode === 'eraser' ? 'pen' : 'eraser'));
290
+ sizeBtns.forEach((b, i) => b.addEventListener('click', () => {
291
+ penIdx = i;
292
+ // 正在用橡皮时点笔粗,顺手切回笔
293
+ if (mode !== 'pen') { mode = 'pen'; applyCursor(); }
294
+ refreshState();
295
+ }));
296
+ growBtn.addEventListener('click', () => grow(160));
297
+
298
+ /* ---------- 加高(笔迹用逻辑坐标,所以已写的不会拉伸) ---------- */
299
+
300
+ function grow(px) {
301
+ height += Math.max(60, Number(px) || 160);
302
+ layout();
303
+ }
304
+
305
+ /* ---------- 导出 ---------- */
306
+
307
+ function toPNG() {
308
+ const w = EXPORT_WIDTH;
309
+ // 逻辑高 = height/cssW*LOGIC_W;按导出宽度等比换算成像素
310
+ const h = Math.max(100, Math.round(EXPORT_WIDTH * (height / Math.max(1, cssW))));
311
+ const off = document.createElement('canvas');
312
+ off.width = w;
313
+ off.height = h;
314
+ const ctx = off.getContext('2d');
315
+ ctx.fillStyle = '#ffffff';
316
+ ctx.fillRect(0, 0, w, h);
317
+ paint(ctx, w, h);
318
+ return off.toDataURL('image/png');
319
+ }
320
+
321
+ if (window.ResizeObserver) {
322
+ let raf = 0;
323
+ const ro = new ResizeObserver(() => {
324
+ cancelAnimationFrame(raf);
325
+ raf = requestAnimationFrame(layout);
326
+ });
327
+ ro.observe(stage);
328
+ } else {
329
+ window.addEventListener('resize', layout);
330
+ }
331
+
332
+ applyCursor();
333
+ layout();
334
+ refreshState();
335
+
336
+ return {
337
+ el: wrap,
338
+ canvas,
339
+ isEmpty: () => strokes.length === 0,
340
+ strokeCount: () => strokes.length,
341
+ clear: () => { strokes = []; cur = null; refreshState(); redraw(); },
342
+ grow,
343
+ toPNG,
344
+ relayout: layout,
345
+ };
346
+ }
347
+
348
+ window.InkPad = { create };
349
+ })();
@@ -0,0 +1,20 @@
1
+ /* 学习助手页面的少量补充样式。不改 style.css,避免影响练习台既有外观。 */
2
+
3
+ .badge.warn { background: var(--warn-soft); color: var(--warn); }
4
+
5
+ /* 学习路线:每个节点左侧一条竖线,直观表示「按先修顺序推进」 */
6
+ .learn-roadmap { position: relative; margin-top: 8px; }
7
+ .learn-roadmap .card { margin-left: 0; }
8
+
9
+ /* 课程页里材料摘录的滚动区域 */
10
+ .learn-material pre {
11
+ font-family: ui-monospace, SFMono-Regular, Consolas, "Courier New", monospace;
12
+ font-size: 12.5px;
13
+ line-height: 1.6;
14
+ }
15
+
16
+ /* 状态徽章在路线图里对齐 */
17
+ .learn-node-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
18
+
19
+ /* 学习助手入口按钮在首页顶栏 */
20
+ .learn-entry { margin-left: auto; }