question-workbench-mcp 0.3.5 → 0.4.1

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/client.js CHANGED
@@ -17,7 +17,7 @@ window.__ModuleLoader__.load({
17
17
  copy: '复制提示', copied: '已复制', copyFail: '复制失败,请手动选择文本',
18
18
  print: '打印', exportHtml: '导出讲义', exportHint: '已导出讲义 HTML:用浏览器打开后按 Ctrl+P 可预览 A4 分页并打印。', exportFail: '导出失败:', preview: '预览', hidePreview: '关闭预览', includeImg: '打印含原图', optimize: '优化原图(裁剪·去阴影·增强)', optimizing: '正在优化图片…', optimizeFail: '部分图片优化失败,已使用原图', showPrompt: '查看将发送的提示', printFail: '打印调用失败,请改用系统打印(Ctrl+P)', printHint: '已调用打印;若没有出现打印对话框或预览,请点「导出讲义」,用浏览器打开后按 Ctrl+P 预览并打印',
19
19
  fail: '发送失败:', noSession: '当前会话不可用,请先打开一个会话',
20
- sendAsk: '发送', notesLabel: '解答 / 解析', notesPlaceholder: '把模型的思路、解答或总结粘贴到这里;会打印在题目之后', autoFilled: '已自动填入模型回复', waiting: '已发送,等待模型回复后自动填入…', autoFail: '未自动获取到回复,可用「从剪贴板粘贴」手动补充', saved: '文字自动保存在本机浏览器(按会话)', diagramNote: '图形以原图为准:打印默认附原图,文本里的「图形」一行仅作排版提示。', limit: '最多 12 张,单张 ≤15MB',
20
+ sendAsk: '发送', notesLabel: '解答 / 解析', notesPlaceholder: '把模型的思路、解答或总结粘贴到这里;会打印在题目之后', autoFilled: '已自动填入模型回复', waiting: '已发送,等待模型回复后自动填入…', autoFail: '未自动获取到回复,可用「从剪贴板粘贴」手动补充', saved: '文字自动保存在本机浏览器(按会话)', mathRule: '数学公式照原样用教材符号书写:∠ △ ∵ ∴ ⊥ ∥ ²、S₁、x²、√3、π;不要用 $ 包裹,也不要写 LaTeX 命令,讲义会自动把这些符号渲染成公式。', diagramNote: '图形以原图为准:打印默认附原图,文本里的「图形」一行仅作排版提示。', limit: '最多 12 张,单张 ≤15MB',
21
21
  src: '已核对题目:\n', rule: '以下内容已由用户对照原图人工核对,直接作为已知条件使用;不要重新质疑,也不要补充未确认的关系。\n\n',
22
22
  rec: '只做识别,严格输出两段,不要解释或额外分节:\n【题目】逐字转录印刷文字,保留题号、选项、符号和公式;看不清写[待核实:简短原因],不要猜。\n【图形】每张图一行,≤25字,只写可见关键元素,例如:图1 三角形ABC,P在内部,BM、CN交于P。\n【待确认】最多3条、每条≤15字;没有写“无”。',
23
23
  askA: '只给思路,不要完整计算:①考点1行 ②关键思路3-5步。≤200字。',
@@ -38,7 +38,7 @@ window.__ModuleLoader__.load({
38
38
  copy: 'Copy prompt', copied: 'Copied', copyFail: 'Copy failed; select the text manually',
39
39
  print: 'Print', exportHtml: 'Export worksheet', exportHint: 'Worksheet exported. Open it in a browser and press Ctrl+P to preview A4 pages and print.', exportFail: 'Export failed: ', preview: 'Preview', hidePreview: 'Hide preview', includeImg: 'Include photos in print', optimize: 'Clean up photos (crop, shadows, contrast)', optimizing: 'Cleaning up photos…', optimizeFail: 'Some photos could not be cleaned; originals used', showPrompt: 'Show prompt to be sent', printFail: 'Print call failed; use Ctrl+P instead', printHint: 'Print dialog opened; press Ctrl+P if it did not appear',
40
40
  fail: 'Send failed: ', noSession: 'No usable session; open a conversation first',
41
- sendAsk: 'Send', notesLabel: 'Solution', notesPlaceholder: 'Paste the reasoning or solution here; it prints after the question', autoFilled: 'Model reply filled in automatically', waiting: 'Sent. Waiting for the reply to fill in…', autoFail: 'No reply captured; use "Paste from clipboard"', saved: 'Text is saved in this browser per session', diagramNote: 'The original photo is the diagram source; printing includes it by default. The one-line diagram note is for layout only.', limit: 'Up to 12 photos, 15 MB each',
41
+ sendAsk: 'Send', notesLabel: 'Solution', notesPlaceholder: 'Paste the reasoning or solution here; it prints after the question', autoFilled: 'Model reply filled in automatically', waiting: 'Sent. Waiting for the reply to fill in…', autoFail: 'No reply captured; use "Paste from clipboard"', saved: 'Text is saved in this browser per session', mathRule: 'Write formulas with normal textbook symbols (∠ △ ∵ ∴ ⊥ ∥ ², S₁, x², √3, π). Do not wrap them in $ or use LaTeX commands; the worksheet renders these symbols automatically.', diagramNote: 'The original photo is the diagram source; printing includes it by default. The one-line diagram note is for layout only.', limit: 'Up to 12 photos, 15 MB each',
42
42
  src: 'Checked question:\n', rule: 'The user checked the following against the photos; use it as given. Do not re-question it or add unconfirmed relations.\n\n',
43
43
  rec: 'Transcribe only. Output exactly two sections, no extra explanation:\n[Question] literal printed text, keeping numbering, symbols and formulas; write [verify: short reason] instead of guessing.\n[Diagram] one line per figure, ≤25 words, only visible key elements, e.g. Fig.1 triangle ABC, P inside, BM and CN meet at P.\n[Checks] at most 3 items, ≤15 words each; write "none" if none.',
44
44
  askA: 'Reasoning only: 1 line of key concepts, then 3-5 steps. ≤200 words.',
@@ -274,7 +274,7 @@ window.__ModuleLoader__.load({
274
274
  if (!photos.length) { say(t.needPhoto, true); return; }
275
275
  const extra = text.trim() ? t.optional + ':\n' + text.trim() + '\n\n' : '';
276
276
  const since = lastSeq();
277
- const ok = await send(extra + t.rec);
277
+ const ok = await send(t.context + '\n\n' + extra + t.rec + '\n' + t.mathRule);
278
278
  if (!ok) return;
279
279
  waitRef.current = { kind: 'text', since };
280
280
  if (timerRef.current) clearTimeout(timerRef.current);
@@ -282,7 +282,7 @@ window.__ModuleLoader__.load({
282
282
  say(t.waiting);
283
283
  setStep(2);
284
284
  }
285
- function askPrompt(ask) { return t.src + text.trim() + '\n\n' + t.rule + ask; }
285
+ function askPrompt(ask) { return t.src + text.trim() + '\n\n' + t.rule + t.mathRule + '\n\n' + ask; }
286
286
  async function doAsk(ask) {
287
287
  if (!text.trim()) { say(t.needText, true); return; }
288
288
  const full = ask === t.askF;
package/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  /** Host half: the Client owns the worksheet UI; the Host also exposes the workbook as agent tools. */
2
2
  import fs from 'node:fs';
3
3
  import path from 'node:path';
4
+ import { latexify } from './lib/katex-unicode.mjs';
4
5
 
5
6
  const PROMPTS = {
6
7
  zh: {
@@ -24,6 +25,7 @@ const PROMPTS = {
24
25
  };
25
26
 
26
27
  const MODES = ['recognition', 'analysis', 'solution', 'summary', 'full'];
28
+ const MATH_RULE = '数学公式照原样用教材符号书写:∠ △ ∵ ∴ ⊥ ∥ ²、S₁、x²、√3、π;不要用 $ 包裹,也不要写 LaTeX 命令,讲义会自动把这些符号渲染成公式。';
27
29
  const MIME = { '.png': 'image/png', '.jpg': 'image/jpeg', '.jpeg': 'image/jpeg', '.webp': 'image/webp', '.gif': 'image/gif' };
28
30
 
29
31
  const escape = (v) => String(v).replace(/[&<>"']/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c]));
@@ -40,7 +42,7 @@ export function buildPrompt(mode, text, language) {
40
42
  const lang = language === 'en' ? 'en' : 'zh';
41
43
  const body = text && String(text).trim();
42
44
  if (mode !== 'recognition' && !body) throw new Error('text is required for mode ' + mode);
43
- return PROMPTS[lang][mode].replace('{text}', body || '');
45
+ return PROMPTS[lang][mode].replace('{text}', body || '') + '\n\n' + MATH_RULE;
44
46
  }
45
47
 
46
48
  export function buildWorksheet(options = {}) {
@@ -54,9 +56,14 @@ export function buildWorksheet(options = {}) {
54
56
  if (!MIME[ext]) throw new Error('unsupported image type: ' + p);
55
57
  return { name: path.basename(p), data: `data:${MIME[ext]};base64,${fs.readFileSync(p).toString('base64')}` };
56
58
  });
57
- const lines = (v) => marked(v).split('\n').map((l) => `<div>${l || '&nbsp;'}</div>`).join('');
59
+ const lines = (v) => marked(latexify(v));
60
+ const KATEX = 'https://cdn.jsdelivr.net/npm/katex@0.16.11/dist';
61
+ const katexHead = '<link rel="stylesheet" href="' + KATEX + '/katex.min.css">'
62
+ + '<script defer src="' + KATEX + '/katex.min.js"></script>'
63
+ + '<script defer src="' + KATEX + '/contrib/auto-render.min.js" onload="renderMathInElement(document.body,{delimiters:[{left:\'$$\',right:\'$$\',display:true},{left:\'$\',right:\'$\',display:false},{left:\'\\\\[\',right:\'\\\\]\',display:true},{left:\'\\\\(\',right:\'\\\\)\',display:false}],throwOnError:false,errorColor:\'#b42318\'})"></script>';
58
64
  const html = '<!doctype html><html><head><meta charset="utf-8"><title>' + escape(title) + '</title>'
59
- + '<style>@page{size:A4;margin:16mm}body{font:12pt/1.7 system-ui,sans-serif;color:#161616}h1{font-size:18pt}h2{font-size:13pt;margin-top:16px;border-bottom:1px solid #999}section{white-space:pre-wrap;overflow-wrap:anywhere}figure{break-inside:avoid;margin:14px 0}figure img{max-width:100%;max-height:235mm;object-fit:contain}figcaption{font-size:9pt;color:#666}.bad{color:#b42318;background:#fff0ec}</style></head><body>'
65
+ + '<style>@page{size:A4;margin:16mm}body{font:12pt/1.75 system-ui,"Microsoft YaHei",sans-serif;color:#161616}h1{font-size:18pt}h2{font-size:13pt;margin-top:16px;border-bottom:1px solid #999}section{white-space:pre-wrap;overflow-wrap:anywhere}figure{break-inside:avoid;margin:14px 0}figure img{max-width:100%;max-height:235mm;object-fit:contain}figcaption{font-size:9pt;color:#666}.bad{color:#b42318;background:#fff0ec}.katex{font-size:1.05em}.katex-display{margin:.6em 0;overflow-x:auto;overflow-y:hidden}</style>'
66
+ + katexHead + '</head><body>'
60
67
  + '<h1>' + escape(title) + '</h1>'
61
68
  + (options.grade ? '<p>' + escape(options.grade) + '</p>' : '')
62
69
  + '<section>' + lines(text) + '</section>'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "question-workbench-mcp",
3
- "version": "0.3.5",
3
+ "version": "0.4.1",
4
4
  "description": "Question workbench: photos in, checked text, reasoning or solutions, A4 worksheet out. One package, two installs: a DeepSeek Harness bundle (UI + agent tools) and an MCP stdio server for Codex, WorkBuddy and other MCP clients.",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/server.js CHANGED
@@ -5,6 +5,7 @@ import readline from 'node:readline';
5
5
  import fs from 'node:fs';
6
6
  import path from 'node:path';
7
7
  import os from 'node:os';
8
+ import { latexify } from './lib/katex-unicode.mjs';
8
9
 
9
10
  const VERSION = (() => {
10
11
  try { return JSON.parse(fs.readFileSync(new URL('./package.json', import.meta.url), 'utf8')).version; } catch { return '0.0.0'; }
@@ -35,6 +36,7 @@ const PROMPTS = {
35
36
  };
36
37
 
37
38
  const MODES = ['recognition', 'analysis', 'solution', 'summary', 'full'];
39
+ const MATH_RULE = '数学公式照原样用教材符号书写:∠ △ ∵ ∴ ⊥ ∥ ²、S₁、x²、√3、π;不要用 $ 包裹,也不要写 LaTeX 命令,讲义会自动把这些符号渲染成公式。';
38
40
 
39
41
  const TOOLS = [
40
42
  {
@@ -106,11 +108,16 @@ const marker = /([待核实[^]\n]{0,160}]|\[verify[^\]\n]{0,160}\])/gi;
106
108
  const marked = v => esc(v).replace(marker, '<b class="bad">$1</b>');
107
109
 
108
110
  function worksheet(t, state) {
109
- const lines = v => marked(v).split('\n').map(l => `<div>${l || '&nbsp;'}</div>`).join('');
111
+ const lines = v => marked(latexify(v));
110
112
  const figures = (state.images || []).map((img) => `<figure><img src="${img.data}" alt="${esc(img.name)}"><figcaption>${esc(img.name)}</figcaption></figure>`).join('');
111
113
  const notes = state.notes ? `<h2>${esc(t.labelSolution)}</h2><section>${lines(state.notes)}</section>` : '';
114
+ const KATEX = 'https://cdn.jsdelivr.net/npm/katex@0.16.11/dist';
115
+ const katexHead = '<link rel="stylesheet" href="' + KATEX + '/katex.min.css">'
116
+ + '<script defer src="' + KATEX + '/katex.min.js"></script>'
117
+ + '<script defer src="' + KATEX + '/contrib/auto-render.min.js" onload="renderMathInElement(document.body,{delimiters:[{left:\'$$\',right:\'$$\',display:true},{left:\'$\',right:\'$\',display:false},{left:\'\\\\[\',right:\'\\\\]\',display:true},{left:\'\\\\(\',right:\'\\\\)\',display:false}],throwOnError:false,errorColor:\'#b42318\'})"></script>';
112
118
  return '<!doctype html><html><head><meta charset="utf-8"><title>' + esc(state.title) + '</title>'
113
- + '<style>@page{size:A4;margin:16mm}body{font:12pt/1.7 system-ui,sans-serif;color:#161616}h1{font-size:18pt}h2{font-size:13pt;margin-top:16px;border-bottom:1px solid #999}section{white-space:pre-wrap;overflow-wrap:anywhere}figure{break-inside:avoid;margin:14px 0}figure img{max-width:100%;max-height:235mm;object-fit:contain}figcaption{font-size:9pt;color:#666}.bad{color:#b42318;background:#fff0ec}</style></head><body>'
119
+ + '<style>@page{size:A4;margin:16mm}body{font:12pt/1.75 system-ui,"Microsoft YaHei",sans-serif;color:#161616}h1{font-size:18pt}h2{font-size:13pt;margin-top:16px;border-bottom:1px solid #999}section{white-space:pre-wrap;overflow-wrap:anywhere}figure{break-inside:avoid;margin:14px 0}figure img{max-width:100%;max-height:235mm;object-fit:contain}figcaption{font-size:9pt;color:#666}.bad{color:#b42318;background:#fff0ec}.katex{font-size:1.05em}.katex-display{margin:.6em 0;overflow-x:auto;overflow-y:hidden}</style>'
120
+ + katexHead + '</head><body>'
114
121
  + '<h1>' + esc(state.title) + '</h1>'
115
122
  + (state.grade ? '<p>' + esc(state.grade) + '</p>' : '')
116
123
  + '<section>' + lines(state.text || '') + '</section>'
@@ -131,7 +138,7 @@ function callTool(name, args = {}) {
131
138
  const lang = args.language === 'en' ? 'en' : 'zh';
132
139
  const text = typeof args.text === 'string' ? args.text.trim() : '';
133
140
  if (mode !== 'recognition' && !text) throw new Error('text is required for mode ' + mode);
134
- return PROMPTS[lang][mode].replace('{text}', text);
141
+ return PROMPTS[lang][mode].replace('{text}', text) + '\n\n' + MATH_RULE;
135
142
  }
136
143
  if (name === 'build_worksheet') {
137
144
  const lang = args.language === 'en' ? 'en' : 'zh';