Skip to content

fix(crates/panache-mcp): 改字前核对用户点名的文字 - #50

Merged
SXP-Simon merged 1 commit into
mainfrom
fix/mcp-glyph-target-text
Nov 25, 2026
Merged

SXP-Simon merged 1 commit into
mainfrom
fix/mcp-glyph-target-text

Conversation

@SXP-Simon

@SXP-Simon SXP-Simon commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

为什么改

用户说“把春字标红”。旧稿是“春 雨 Z”,0 号字是“春”。前面加上“明 日”后,0 号变成“明”,“春”移到 4 号。已有版本检查能拒绝旧版写入;如果调用者只把请求里的版本号改成最新,0 号仍然合法,就可能把“明”标红。#36 用真实 MCP 演示了这个场景。

现在怎么用

  1. 用 preview_handwriting(view="layout") 找到目标,沿用这次返回的稿件、节、页和版本。遇到版本冲突,重新找字。
  2. 用户明确点名文字时,在原来的 adjust_glyphs 请求中同时传编号和预期文字,例如 ids=[4], expected_texts=["春"]。服务在同一页的布局中核对编号对应的完整文字。任意一项不符,整批拒绝,修订保持原样;全部相符才保存。
  3. 稿件没变时,核对随原写入完成,无需额外调用。服务复用原有字形检查与版本事务,没有持续监听稿件或计算改动范围。

expected_texts 可省略,旧客户端和只按位置调图形的请求仍可使用。省略时,服务仍按编号选字。同页有两个“春”时,文字相同,仍要靠行、附近词或选区区分;如果选错了同名的字,文字核对本身分辨不了。

验证

模型实际怎么用

用 GPT-6 Luna low 和 GPT-6.1 Terra low 各跑两场独立的两轮对话,使用真实工具、隔离稿件。第一轮只让模型找“春”,第二轮让它标红。给模型的请求均未提到工具参数。最后独立读回稿件核对着色。

两轮之间的稿件状态 Luna Terra
稿件照旧 写前主动又查了一次布局,随后一次写成功 用之前查到的位置直接写成功,然后看了普通预览
另一个客户端先插入“明 日” 旧版本被拒,重查后用 4 号和“春”写成功 同样先被拒,重查后用 4 号和“春”写成功,再看预览

四场都主动传了 expected_texts=["春"],读回都只有“春”变红。“新版号配错字”由上面的固定回归单独覆盖。模型每种情况各跑了一次,不能由此推算今后的误改率或平均调用次数。

Rust fmt、MCP Clippy(警告按错误处理)、13 项 MCP 单元测试、目标文字专项 stdio 回归和完整 MCP stdio 冒烟测试均通过(长稿 61,197 字符、7 节)。

Summary by Sourcery

Protect glyph adjustments from targeting the wrong text by validating named targets against the latest layout before applying edits.

New Features:

  • Allow glyph adjustments to optionally verify that each selected ID matches its expected text before saving.

Bug Fixes:

  • Prevent edits from being applied to the wrong glyph when document changes shift glyph IDs and callers reuse updated revisions without re-locating targets.

Enhancements:

  • Clarify layout revision and named-text targeting guidance for MCP clients and document the all-or-nothing validation behavior.

Documentation:

  • Update MCP usage guidance and tool descriptions for selecting and validating named glyph targets.

Tests:

  • Add an MCP regression covering expected-text validation, revision conflicts, malformed target lists, atomic rejection, and successful out-of-order edits.

背景:稿件重排后,同一个编号可能指向另一个字。即使提交了最新版本号,单凭编号也可能误改用户没有点名的文字。

解决手段:引导调用者沿用查布局时的版本,并支持按编号顺序提供预期文字。沿用预览的文本映射,在写入前核对整组选字。补充真实 MCP 场景测试。

收益:文字与编号不符时整批保留原样,目标吻合时沿用原有保存流程,旧客户端与纯位置选区仍可使用。
@sourcery-ai

sourcery-ai Bot commented Nov 25, 2026

Copy link
Copy Markdown

Reviewer's Guide

API

Expose optional expected_texts in glyph-ID order and clarify that IDs belong to the exact layout revision, section, and page that returned them.

  • crates/panache-mcp/src/inputs.rs L223, L229-230
  • crates/panache-mcp/src/main.rs L512

Implementation

Resolve each glyph’s source text and reject the entire adjustment batch before saving if a requested glyph does not match its expected text.

  • crates/panache-mcp/src/engine.rs L15-19, L416
  • crates/panache-mcp/src/engine/adjustments.rs L1, L37-48, L102-107

Documentation

Document how to pair named glyph IDs with expected text, handle revision conflicts, and distinguish repeated occurrences by context or position.

  • crates/panache-mcp/README.md L112

Tests

Exercise stale revisions, text mismatches, invalid expected-text lists, unchanged state after rejection, and successful checks when IDs are supplied out of page order.

  • crates/panache-mcp/tests/smoke.py L171-208, L396

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@SXP-Simon
SXP-Simon marked this pull request as ready for review November 25, 2026 12:29
@sourcery-ai

sourcery-ai Bot commented Nov 25, 2026

Copy link
Copy Markdown

Sorry @SXP-Simon, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 4 days and 16 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@SXP-Simon
SXP-Simon merged commit 0f9501e into main Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant