From c9d5d634240886cd5db12ca9516e29c2ada87510 Mon Sep 17 00:00:00 2001 From: SXP-Simon Date: Thu, 26 Nov 2026 19:36:13 +0800 Subject: [PATCH] =?UTF-8?q?docs(crates/panache-mcp):=20=E5=9C=A8=E5=BB=BA?= =?UTF-8?q?=E7=A8=BF=E6=97=B6=E8=AF=B4=E6=98=8E=E6=AD=A3=E6=96=87=E6=8F=92?= =?UTF-8?q?=E5=9B=BE=E7=9A=84=E7=BA=BF=E7=A8=BF=E6=95=88=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 背景:用户希望保留正文中彩色示意图的颜色,但内嵌图在手写页上会画成线稿。 解决手段:在建稿工具的 Markdown 参数和指南里说明效果,颜色重要时先看小样,并保留原图在正文中的位置。 收益:用户可在交付前确认画面,也可从原稿中继续取得原图。 --- crates/panache-mcp/README.md | 2 + crates/panache-mcp/src/inputs.rs | 2 + .../panache-mcp/tests/inline_image_outline.py | 54 +++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 crates/panache-mcp/tests/inline_image_outline.py diff --git a/crates/panache-mcp/README.md b/crates/panache-mcp/README.md index e2c98e27..5d8d5c84 100644 --- a/crates/panache-mcp/README.md +++ b/crates/panache-mcp/README.md @@ -56,6 +56,8 @@ cargo build --locked --release -p panache-mcp 遇到手摆保护时,先告诉用户文字尚未修改、位置仍在原版。整节保存会重新排版,新版不会自动继承手摆。让用户选择保留现版,或允许重新排版后看预览。用户要求保持原位时,不能仅凭旧字形编号或相同的移动距离就声称位置已经恢复。明确同意重新排版后,可以按同一版本读全原文、保留其余内容,用相同版本号调用 `save_section` 并预览新版。若无法确保图片等内容能完整重存,应先告诉用户并保留原稿。 +稿件会原样保存嵌入的图片,正文里的插图会画成手绘线稿,无法保留原彩。颜色很重要时,请先看这一页的小样,别把插图改成整页底纸。 + 使用自己的纸张时,在第一次调用 `save_section` 时传入 `paper_path`,例如 `{"markdown":"第一题","paper_path":"C:/作业/南昌大学横线纸.jpg"}`。路径指向运行 MCP 的电脑上的图片。默认保留原照片,按识别到的横线投影字迹和插图。`paper` 返回排版尺寸、边距、行距、识线结果,投影时另有原照尺寸。可用 `preview_handwriting(view="paper")` 单独看底纸,或在导入时通过 `paper_guides` 指定参考线。需要校平底纸时传 `paper_mode="flatten"`。无可靠横线时保留底图,使用普通行距。纸张随稿件保存一次,后续追加、回查、预览和导出可在原图移动后继续使用。 如果照片是聊天附件,请先确认客户端能提供 MCP 进程可读的本机文件路径,必要时先把图片存到这台电脑。带视觉能力的模型可以查看客户端转交的预览图。客户端或模型只能处理文字时,可读取版面和像素测量,并请用户打开导出文件确认外观,再按反馈修改。 diff --git a/crates/panache-mcp/src/inputs.rs b/crates/panache-mcp/src/inputs.rs index 54638337..f4186424 100644 --- a/crates/panache-mcp/src/inputs.rs +++ b/crates/panache-mcp/src/inputs.rs @@ -108,6 +108,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)))