diff --git a/crates/panache-mcp/README.md b/crates/panache-mcp/README.md index 8e382384..9c91becf 100644 --- a/crates/panache-mcp/README.md +++ b/crates/panache-mcp/README.md @@ -62,6 +62,8 @@ cargo build --locked --release -p panache-mcp 写作业时,客户端可直接传 `{"markdown":"第一题","style":{"homework":true}}`。纯文字、预设纸和照片底纸共用作业默认值:优先使用随包的李国夫手写体,字的大小和倾斜有轻微变化。指定字体会优先使用;想让字更整齐可加 `"relaxed_handwriting":false`。同一稿件的随机种子随稿保存。 +稿件会原样保存嵌入的图片,正文里的插图会画成手绘线稿,无法保留原彩。颜色很重要时,请先看这一页的小样,别把插图改成整页底纸。 + 使用自己的纸张时,在第一次调用 `save_section` 时传入 `paper_path`,例如 `{"markdown":"第一题","paper_path":"C:/作业/南昌大学横线纸.jpg"}`。路径指向运行 MCP 的电脑上的图片。默认保留原照片,按识别到的横线投影字迹和插图。`paper` 返回排版尺寸、边距、行距、识线结果,投影时另有原照尺寸。可用 `preview_handwriting(view="paper")` 单独看底纸,或在导入时通过 `paper_guides` 指定参考线。需要校平底纸时传 `paper_mode="flatten"`。无可靠横线时保留底图,使用普通行距。纸张随稿件保存一次,后续追加、回查、预览和导出可在原图移动后继续使用。 如果照片是聊天附件,先用客户端支持的文件传送功能,把照片交给 Panache。云端没有这项功能时,可在照片所在电脑连接桌面版再使用。复制手机或另一台电脑上的路径不能传照片。带视觉能力的模型可以查看客户端转交的预览图。客户端或模型只能处理文字时,可读取版面和像素测量,并请用户打开导出文件确认外观,再按反馈修改。 diff --git a/crates/panache-mcp/src/inputs.rs b/crates/panache-mcp/src/inputs.rs index 527f6d17..19c440f6 100644 --- a/crates/panache-mcp/src/inputs.rs +++ b/crates/panache-mcp/src/inputs.rs @@ -144,6 +144,8 @@ pub struct Save { /// Optional photo-space baselines overriding auto detection on import. Give 2..32 guides, first row 0, last row the last writable line; intermediate guides refine the fit. pub paper_guides: Option>, /// Original Markdown of just this section. A new section starts on a fresh page. + /// Embedded images remain intact in the source. Pages render them as hand-drawn outlines without their original colors. + /// If color matters, explain this and offer a preview. Keep the image in the text rather than using it as the paper. pub markdown: String, /// Omit to create a draft. Supply the returned ID to append or edit. pub draft_id: Option, diff --git a/crates/panache-mcp/tests/inline_image_outline.py b/crates/panache-mcp/tests/inline_image_outline.py new file mode 100644 index 00000000..0b0b7d32 --- /dev/null +++ b/crates/panache-mcp/tests/inline_image_outline.py @@ -0,0 +1,54 @@ +# /// script +# dependencies = ["mcp>=1.12,<2", "Pillow"] +# /// +"""Check the source bytes and rendered appearance of a colored inline illustration.""" + +import base64 +import io + +from PIL import Image, ImageDraw +import argparse +import asyncio +from pathlib import Path +from tempfile import TemporaryDirectory + +from mcp_client import call, isolated_session, open_db + + +async def run(binary, home): + async with isolated_session(binary, home) as (client, info): + tools = {t.name: t for t in (await client.list_tools()).tools} + assert ( + "hand-drawn outlines" + in tools["save_section"].inputSchema["properties"]["markdown"]["description"] + ) + picture = Image.new("RGB", (100, 75), "white") + ImageDraw.Draw(picture).rectangle((15, 10, 85, 65), fill="magenta", outline="navy", width=5) + buffer = io.BytesIO() + picture.save(buffer, format="PNG") + image_data = base64.b64encode(buffer.getvalue()).decode() + source = f"![示意图](data:image/png;base64,{image_data})" + key = ( + await call(client, "save_section", markdown=source, style={"seed": 31}) + ).structuredContent["draft_id"] + saved = ( + await call(client, "read_section", draft_id=key, view="source", section=1) + ).structuredContent + assert saved["markdown"] == source + preview = await call(client, "preview_handwriting", draft_id=key, view="image") + png = base64.b64decode(next(b.data for b in preview.content if b.type == "image")) + with Image.open(io.BytesIO(png)) as rendered: + colors = rendered.convert("RGB").getcolors(rendered.width * rendered.height) + assert sum(n for n, rgb in colors if rgb == (255, 0, 255)) == 0 + assert sum(n for n, rgb in colors if max(rgb) < 100) > 0 + with open_db(home) as db: + assert not db.execute("SELECT 1 FROM review_observations").fetchone() + print("Original PNG preserved; outline rendered without the original magenta.") + + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("binary", type=Path) + args = parser.parse_args() + with TemporaryDirectory() as temp: + asyncio.run(run(args.binary.resolve(), Path(temp)))