From 3083c4ff70e3236a35e9385f42d43e084ef9e5fe Mon Sep 17 00:00:00 2001 From: SXP-Simon Date: Thu, 26 Nov 2026 19:36:09 +0800 Subject: [PATCH] =?UTF-8?q?feat(crates/panache-mcp):=20=E6=8C=89=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E7=94=A8=E9=80=94=E5=B1=95=E7=A4=BA=E5=B0=8F=E6=A0=B7?= =?UTF-8?q?=E5=B9=B6=E6=B2=BF=E7=94=A8=E9=80=89=E4=B8=AD=E7=9A=84=E7=89=88?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 背景:用户只说想做手写作业时可能还没选用途,明确说要打印时则已经做了选择。 解决手段:首次连接时直接利用已有材料,用途不清才举打印、练习纸和透明字迹三种例子;允许用日常语言修改小样,按认可的版号导出。 收益:明确需求可以直接开始,改过多版后仍能拿到自己选的那版。 --- README.md | 2 + README.zh-CN.md | 2 + crates/panache-mcp/README.md | 4 +- crates/panache-mcp/src/main.rs | 2 + .../panache-mcp/tests/onboarding_preview.py | 69 +++++++++++++++++++ 5 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 crates/panache-mcp/tests/onboarding_preview.py diff --git a/README.md b/README.md index 9393d0a0..ff735e85 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,8 @@ The Windows, macOS, and Linux desktop packages include a local MCP server. Open For the photo, give the client a file path accessible on the computer running Panache. A client that passes images to its model can inspect the finished page and review a selected area. In a text-only client, ask for the measurements and open the exported PDF locally to judge the appearance. [MCP tools and configuration](crates/panache-mcp/README.md) +For text alone, paste the passage and say whether you want a printable page, writing on your worksheet, or transparent ink for a poster. + | Process state diagram | Resource allocation table | | --- | --- | | [![Process state diagram](assets/examples/process-states-60b3a1d31f00.webp)](assets/examples/process-states-60b3a1d31f00.webp) | [![Resource allocation table](assets/examples/bankers-algorithm-40bcfd843ae0.webp)](assets/examples/bankers-algorithm-40bcfd843ae0.webp) | diff --git a/README.zh-CN.md b/README.zh-CN.md index 9d35d1ab..74e7ece1 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -30,6 +30,8 @@ Windows、macOS 和 Linux 桌面版随附本地 MCP 服务。在 **应用设置 请提供运行 Panache 的电脑能读取的照片路径。能向模型传递图片的客户端可以检查成品、放大复盘选区。在纯文字客户端中,可让 AI 说明测量结果,再打开导出的本地 PDF 看实际效果。[MCP 工具与配置说明](crates/panache-mcp/README.md) +只有文字也可以开始。贴上正文,说清是要打印、填进练习纸,还是只取透明字迹贴进海报。 + | 进程状态转换图 | 资源分配表 | | --- | --- | | [![进程状态转换图](assets/examples/process-states-60b3a1d31f00.webp)](assets/examples/process-states-60b3a1d31f00.webp) | [![资源分配表](assets/examples/bankers-algorithm-40bcfd843ae0.webp)](assets/examples/bankers-algorithm-40bcfd843ae0.webp) | diff --git a/crates/panache-mcp/README.md b/crates/panache-mcp/README.md index e2c98e27..b163b3c9 100644 --- a/crates/panache-mcp/README.md +++ b/crates/panache-mcp/README.md @@ -46,7 +46,9 @@ cargo build --locked --release -p panache-mcp ## 写稿、预览和复查 -第一次可以直接说:「把‘西湖春早,柳色正新。’排成一页手写稿,用默认纸张,先让我看一眼。」客户端会用 `save_section` 建稿,再把返回的 `draft_id` 和 `revision` 交给 `preview_handwriting`。满意后可以说「把刚才那一版导出成 PDF」。导出工具返回本机文件路径。 +只有一句「帮我做一份手写作业」时,先贴要写的内容。想打印,就用普通纸样做 PDF;想填在老师发的练习纸上,就用那张纸的照片;想把字放进海报,就用透明字迹,解开 ZIP 后取出 PNG。已经说清「用这段话做打印版」就可以直接开始。 + +可以先说「用这段话给我看第一页」,看过后说「字大一点」,再说「就用这一版」。客户端按同一稿件的版本号取预览和导出。查看小样使用 `preview_handwriting(view="image")`,无需创建检查单。 试验性的 `replace_section_text` 可按当前稿件版本替换已有节中的一整行,无需重传节内图片。整节的各块须用空行分隔,每块须为单行正文或已验证的独立内嵌图片。默认模式下,所有正文行只允许字母(含汉字)、数字和行内普通半角空格。即使只想改「春天」,另一段的「踏青真好。」也会因含句号触发下面的重试提示。 diff --git a/crates/panache-mcp/src/main.rs b/crates/panache-mcp/src/main.rs index 81a4b5aa..e365b988 100644 --- a/crates/panache-mcp/src/main.rs +++ b/crates/panache-mcp/src/main.rs @@ -273,6 +273,8 @@ impl ServerHandler for Panache { fn get_info(&self) -> rmcp::model::ServerConfig { use rmcp::model::{Implementation, ServerCapabilities, ServerConfig}; let instructions = concat!( + "When someone only asks for handwriting help, use the text or photo already supplied. If the outcome is unclear, offer only relevant examples: a printable page, writing on their own sheet, or just the ink to paste elsewhere. Ask one short question, inviting them to paste missing text in the same turn. Skip this choice for a clear request. ", + "For an undecided layout show one page with view=image. Invite a concrete change such as larger writing or lighter ink. After feedback show the revised page and export the version the user chose. ", "If a required area of a photo is outside the frame, or blur, occlusion or perspective prevents locating it, identify that area before drafting. ", "Ask for a photo clearly showing it or permission to fill only visible areas; wait before saving or trial placement. If partial work was requested, proceed there. ", "For looser, less uniform homework or lab handwriting (字稍微草一点), inspect describe_controls(group=variation). For requested crossed-out mistakes (涂改痕迹), inspect group=strike. ", diff --git a/crates/panache-mcp/tests/onboarding_preview.py b/crates/panache-mcp/tests/onboarding_preview.py new file mode 100644 index 00000000..100bc1b7 --- /dev/null +++ b/crates/panache-mcp/tests/onboarding_preview.py @@ -0,0 +1,69 @@ +# /// script +# dependencies = ["mcp>=1.12,<2", "Pillow"] +# /// +"""Replay a selected preview and compare it with the exported PDF using Poppler.""" + +import argparse +import asyncio +import base64 +import io +import subprocess +from pathlib import Path +from tempfile import TemporaryDirectory + +from PIL import Image +from mcp_client import call, isolated_session, open_db + + +async def run(binary, home): + async with isolated_session(binary, home) as (client, info): + for phrase in ( + "a printable page", + "their own sheet", + "ink to paste", + "one short question", + "Skip this choice for a clear request", + "larger writing or lighter ink", + "export the version the user chose", + ): + assert phrase in info.instructions + saved = await call( + client, "save_section", markdown="观察记录:树上的鸟。", style={"seed": 31} + ) + key = {"draft_id": saved.structuredContent["draft_id"]} + images = [] + for rev, size in ((1, None), (2, 48), (3, 24)): + if size is not None: + await call( + client, + "tune_handwriting", + **key, + expected_revision=rev - 1, + changes={"font_size": size}, + ) + result = await call(client, "preview_handwriting", **key, revision=rev, view="image") + data = next(block.data for block in result.content if block.type == "image") + with Image.open(io.BytesIO(base64.b64decode(data))) as image: + images.append(image.convert("RGB").tobytes()) + exported = await call(client, "export_handwriting", **key, revision=2, format="pdf") + assert exported.structuredContent["revision"] == 2 + subprocess.run( + ["pdfimages", "-png", exported.structuredContent["path"], str(home / "page")], + check=True, + ) + with Image.open(home / "page-000.png") as image: + pixels = image.convert("RGB").tobytes() + assert len(set(images)) == 3 and pixels == images[1] + with open_db(home) as db: + assert not db.execute("SELECT 1 FROM review_observations").fetchone() + print( + "Handshake includes the three choices; PDF matches selected r2 only; zero review records." + ) + + +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)))