diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ea1959c..215def3e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - MCP 调参兼容直接指定控件或按控件组提交。 - 可用 `PANACHE_MCP_PRESERVE_REVIEWS=1` 在改稿和打印期间保留原有检查记录。 - MCP 在多节稿件的逐页复盘中提示节号和节内页码,方便从中断处继续核对。 +- MCP 照片复盘区分边缘过锐与阴影、墨色偏淡,提示如何在同一区域核对小幅柔化。 - MCP 可按稿件版本、节号和页码只读找回已存的整页复盘;缺少记录时明确返回空结果。 - MCP 客户端指南增加只翻旧检查记录的工具选择和调用示例。 - MCP 查旧检查单时可按新增原文定位上一版,并按该版实际排版查询指定节的末页。 diff --git a/crates/panache-mcp/README.md b/crates/panache-mcp/README.md index 78535f34..fb6955b4 100644 --- a/crates/panache-mcp/README.md +++ b/crates/panache-mcp/README.md @@ -116,7 +116,9 @@ cargo build --locked --release -p panache-mcp 作业表可用正文横线设置参考线,将同一页的课程、姓名等字块分别定位。若侧栏印字自下往上读,将原字块的左上、右上、右下、左下四角依次投到侧栏的左下、左上、右上、右下。复查时按栏核对读向、印字和留给老师的评分区。`changed_pixels_outside_reference` 也会计入正文参考区外有意填写的表头和侧栏,应结合这些栏位解读。 -如果字像贴在照片上,在照片整页复查的 `photo_appearance` 中取 `preview_arguments` 再调用一次 `preview_handwriting`。有页内文字基线样本时,这组参数会给出该版本一处字迹附近的原像素底纸和成品裁图;也可以自己圈选。对照邻近印字或横线的边缘清晰度、墨色深浅,再看字号与可写空间是否相称。用 `describe_controls` 指定稿件、版本和 `ink`、`layout` 或 `typography` 参数组可查当前值。正文的柔化和粗细以投影前纸面像素为单位,透明度用百分比。仅修改墨迹组参数时会保留已完成的单字移位和透视调整;更换字体、字号或参考线后应在新版本重新检查选区。改一版后,对同一选区加入 `compare_revision` 比较。只有文字结果的客户端可转述测量,请用户看图判断观感。 +如果字像贴在照片上,先分清是墨迹边缘过锐,还是纸面光照、阴影或墨色对比造成的观感。例如,纸面右侧有阴影,但用户认为笔画已经合适,就保留原样。如果用户明确指出笔画边缘过锐,或原尺寸成品裁图中的笔画边缘确实比附近可比的实拍印字或横线更锐,可以小幅柔化试一版。比如用户说“只改第一行,第二行保留”,用 `preview_handwriting(view=layout)` 找到第一行对应的字,再用 `adjust_glyphs` 的 `softness` 只调这些字。只有用户要调整整份稿子时,才用 `tune_handwriting` 的 `ink_softness`。用户要求保留墨迹时,直接沿用原版。 + +需要核对时,照片整页复盘的 `photo_appearance.preview_arguments` 可直接交给 `preview_handwriting`。有页内文字基线样本时,会返回字迹附近的原尺寸底纸和成品裁图,也可以自己圈选。试调后在新版本沿用原选区,用 `compare_revision` 指向旧版本,对照底纸、改前和改后三张实际裁图:底纸用来看原有阴影和印记,两张成品用来看细笔是否糊掉、对比度是否下降。如果用户点名第二行要保留,也对照第二行的改前和改后。效果变差或拿不准就保留原版。只有文字回执时,把用户观察到的情况说清楚,例如“你觉得边缘已经合适”;还需要目视判断时,请用户看裁图。字号与可写空间是否相称可另查 `layout` 或 `typography` 组。正文的柔化和粗细以投影前纸面像素为单位,透明度用百分比;只改墨迹组参数会保留已有的单字移位和透视调整。更换字体、字号或参考线后,应在新版本重新检查选区。 `tune_handwriting(font_path=…)` 会把本机 TTF/OTF 随稿保存。可用返回的字体标识在同一稿内切回该字体。墨迹组的 `transparent_background` 控制原尺寸 PNG 预览和 ZIP,PDF 保留纸张。透明稿复盘会把墨迹放回底纸,方便判断实际可读性。 diff --git a/crates/panache-mcp/src/review.rs b/crates/panache-mcp/src/review.rs index 50646d8a..c7ad33a6 100644 --- a/crates/panache-mcp/src/review.rs +++ b/crates/panache-mcp/src/review.rs @@ -307,9 +307,10 @@ pub fn page( metadata["next_step"] = json!(next); if draft.paper.is_some() { let mut appearance = json!({ - "inspect":"Compare the strokes with nearby photographed marks for edge softness, contrast and size, and with the available writing space for letter size. Baseline offsets only measure placement. If images are unavailable, ask the user to inspect the crop before judging appearance.", + "inspect":"Compare contrast and size with photographed marks. Check letter size against writing space. Baselines measure placement only. Without images, credit the user's observations; ask the user to inspect the crop if visual evidence is needed.", + "ink_edge_guidance":"Keep ink if requested or suitable. Only soften if the user reports overly sharp strokes or a native crop shows sharper stroke edges than comparable nearby marks. Shadow or faint ink alone is insufficient. For selected words or lines, get their glyph IDs from layout and use adjust_glyphs softness. For the whole draft, use tune_handwriting ink_softness. Start small.", "controls":"describe_controls with draft_id, revision and group: ink (ink #RRGGBB, ink_opacity %, ink_softness and ink_thickness in paper-space px); layout (font_size in paper-space px); typography (font).", - "after_edit":"Review the edited revision. Use the same region with compare_revision for paper/before/after crops. If text reflowed onto different pages, inspect each revision separately." + "after_edit":"Use compare_revision for paper/before/after crops of the same region. Also compare any area the user explicitly asked to preserve. Check fine strokes and contrast; keep the original if worse or unsure. After page reflow inspect each revision separately." }); if let Some(region) = detail_region(baselines, (w, h), params.font_size) { appearance["preview_arguments"] = json!({ diff --git a/crates/panache-mcp/tests/context_metrics.py b/crates/panache-mcp/tests/context_metrics.py index 69dcf66a..c142da7a 100644 --- a/crates/panache-mcp/tests/context_metrics.py +++ b/crates/panache-mcp/tests/context_metrics.py @@ -17,9 +17,12 @@ from mcp_client import call +def json_size(value): + return len(json.dumps(value, ensure_ascii=False, separators=(",", ":")).encode()) + + def size(result): - wire = result.model_dump(mode="json", by_alias=True, exclude_unset=True) - return len(json.dumps(wire, ensure_ascii=False, separators=(",", ":")).encode()) + return json_size(result.model_dump(mode="json", by_alias=True, exclude_unset=True)) async def run(command): @@ -35,9 +38,8 @@ async def run(command): tools = await c.list_tools() names = {t.name for t in tools.tools} metrics = {"tools": len(names), "tools_list_bytes": size(tools)} - data = base64.b64encode( - (Path(__file__).parent / "fixtures" / "ruled.png").read_bytes() - ).decode() + paper = Path(__file__).resolve().parent / "fixtures" / "ruled.png" + data = base64.b64encode(paper.read_bytes()).decode() md = "排版试稿\n![纸张](data:image/png;base64," + data + ")\n复查结尾。" draft = ( await call( @@ -81,6 +83,26 @@ async def run(command): metrics["layout_image_blocks"] = sum( b.type == "image" for b in layout.content ) + if "annotate_review" in names: + plain = await call(c, "preview_handwriting", **key, view="review") + metrics["plain_review_bytes"] = size(plain) + photo = await call( + c, "save_section", markdown="春风又绿江南岸。", paper_path=str(paper), + style={"font": "志莽行书.ttf", "seed": 42}, + ) + photo_id = photo.structuredContent["draft_id"] + review = await call( + c, "preview_handwriting", draft_id=photo_id, revision=1, view="review", + ) + metrics["photo_review_bytes"] = size(review) + if "photo_appearance" in review.structuredContent: + metrics["photo_appearance_bytes"] = json_size(review.structuredContent["photo_appearance"]) + await call(c, "save_section", draft_id=photo_id, expected_revision=1, markdown="第二节") + archive = await call( + c, "read_section", draft_id=photo_id, view="review", + review_id=review.structuredContent["review_id"], + ) + metrics["archived_photo_review_bytes"] = size(archive) print(json.dumps(metrics, ensure_ascii=False)) diff --git a/crates/panache-mcp/tests/review_comparison.py b/crates/panache-mcp/tests/review_comparison.py index 4e67e5c1..3ffbd6b5 100644 --- a/crates/panache-mcp/tests/review_comparison.py +++ b/crates/panache-mcp/tests/review_comparison.py @@ -2,6 +2,7 @@ import base64 import io +import json import sqlite3 import struct import zlib @@ -42,6 +43,12 @@ def chunk(tag, data): ] +def assert_no_photo_guidance(receipt): + texts = [part.text for part in receipt.content if part.type == "text"] + for text in [json.dumps(receipt.structuredContent), *texts]: + assert "photo_appearance" not in text and "ink_edge_guidance" not in text + + async def unruled_artwork(client, directory, call): path = directory / "unruled.png" paper = Image.new("RGB", (1100, 640), "#eee5d8") @@ -59,14 +66,30 @@ async def unruled_artwork(client, directory, call): {"row": 0, "left": [100, 180], "right": [650, 170]}, {"row": 5, "left": [70, 450], "right": [700, 440]}, ]) - whole = (await call(client, "preview_handwriting", **key, view="review")).structuredContent + receipt = await call(client, "preview_handwriting", **key, view="review") + whole = receipt.structuredContent appearance = whole["photo_appearance"] + assert json.loads(receipt.content[0].text.splitlines()[0])["photo_appearance"] == appearance + guidance = appearance["ink_edge_guidance"] + assert sum(part.text.count(guidance) for part in receipt.content if part.type == "text") == 1 + assert all(term in guidance for term in ( + "Keep ink if requested or suitable", + "user reports overly sharp strokes", "native crop", "sharper stroke edges", + "comparable nearby marks", "Shadow or faint ink alone is insufficient", + "get their glyph IDs from layout", "adjust_glyphs softness", + "For the whole draft, use tune_handwriting ink_softness", + )) + assert "ask the user to inspect the crop" in appearance["inspect"] + assert "credit the user's observations" in appearance["inspect"] + assert "compare any area the user explicitly asked to preserve" in appearance["after_edit"] + assert all(term in appearance["after_edit"] for term in ( + "compare_revision", "same region", "fine strokes and contrast", "keep the original if worse or unsure", + )) args = appearance["preview_arguments"] assert args["revision"] == 2 and args["draft_id"] == key["draft_id"] assert "ink_softness" in appearance["controls"] - archived = await call(client, "read_section", **key, view="review", review_id=whole["review_id"]) - assert "photo_appearance" not in archived.structuredContent["evidence"] crop = await call(client, "preview_handwriting", **args) + assert_no_photo_guidance(crop) x, y, w, h = crop.structuredContent["crop_bounds"] assert crop.structuredContent["crop_image_size"] == [w, h] and max(w, h) <= 900 assert crop.structuredContent["after"]["region"]["ink_pixels"] > 0 @@ -100,6 +123,17 @@ def images(result): assert ImageStat.Stat(new_delta).sum[0] < ImageStat.Stat(old_delta).sum[0] finished = after + # The stored revision now predates all three edits. A separate connection observes any commit. + with closing(sqlite3.connect(directory / "drafts.sqlite3")) as db: + version = db.execute("PRAGMA data_version").fetchone() + archived = await call(client, "read_section", **key, view="review", review_id=whole["review_id"]) + assert db.execute("PRAGMA data_version").fetchone() == version + record = archived.structuredContent + assert record["review_id"] == whole["review_id"] and record["revision"] == 2 + assert record["evidence"] == whole["evidence"] + assert all(item.type == "text" for item in archived.content) + assert_no_photo_guidance(archived) + async def check_filtered_history(client, call, draft_id): key = {"draft_id": draft_id} @@ -388,7 +422,7 @@ async def incompatible(draft_id, before, after, reason): preset = (await call(client, "save_section", markdown="字", style={"seed": 13})).structuredContent preset_id = preset["draft_id"] plain = await call(client, "preview_handwriting", draft_id=preset_id, view="review") - assert "photo_appearance" not in plain.structuredContent + assert_no_photo_guidance(plain) await call(client, "tune_handwriting", draft_id=preset_id, expected_revision=1, changes={"paper": "grid"}) await incompatible(preset_id, 1, 2, "different_reference_paper") await call(client, "tune_handwriting", draft_id=preset_id, expected_revision=2, changes={"width": 800})