fix(editor): doc_find_text 返回的 matchIndex 归一成 1 基——差一归一补上回传方向(dev-board#369) - #703
Merged
Conversation
zeweihan
enabled auto-merge (squash)
September 2, 2026 00:54
…rd#369) #701 已把 doc_replace_nth_match / doc_delete_match 的差一在后端下发前减 1 归一(worker 保持 0 基, 插件直接按 worker 契约调用)。但 worker 的 find_text_locations 返回的 matchIndex 同样 0 起, 只减一不加一就留下第二条差一路:模型从 doc_find_text 看到「第二个匹配 matchIndex=1」, 照传给 doc_replace_nth_match,减一后改的是第一个。 - DocumentEditTools.doc_find_text:回给模型前 oneBasedMatchIndexes 把 matches[].matchIndex 加 1, error / 非 JSON 原样透传;描述与 prompt 中英工具表写明「matchIndex 从 1 开始,可直接喂 doc_replace_nth_match」 - MatchIndexBaseTest 补四条:回传加 1、错误透传、描述与 prompt 口径 - lowa-e2e 组 11 补四步钉 worker 事实:find_text_locations 0 起、只计可见匹配(删除型修订 不在正文流、搜不到)、按可见计数、越界拒绝且不动文档;基线 475 -> 479 - ai-doc-bridge.md:归一必须两个方向都做;「只计可见匹配」靠页边模式成立 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
zeweihan
force-pushed
the
fix/match-index-one-based-369
branch
from
September 2, 2026 01:03
9205382 to
f3d2743
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
#701(dev-board#365)已把
doc_replace_nth_match/doc_delete_match的 matchIndex 差一在后端下发前减 1 归一,worker 保持 0 基(JAR/Web 插件经 PluginHostImpl 直接按 worker 契约调用)。本 PR 不改这个决定,只补它没盖到的另一个方向。问题
worker 的
find_text_locations返回的matchIndex同样是 0 起,doc_find_text原样回给模型。模型从查找结果看到「第二个匹配 matchIndex=1」,照着传给doc_replace_nth_match,后端减一后改的是第一个——修订模式下改错处,用户很可能直接接受。修法
DocumentEditTools.doc_find_text:回给模型前oneBasedMatchIndexes把matches[].matchIndex加 1;error / 非 JSON 原样透传。doc_find_text描述与 system_prompt 中英工具表写明「matchIndex 从 1 开始,可直接喂 doc_replace_nth_match」。ai-doc-bridge.md:归一必须两个方向都做;描述里「只计算用户可见的匹配」不是 worker 过滤出来的,靠页边模式成立(删除型修订文本不在正文流、搜不到)。验证
MatchIndexBaseTest补四条(回传加 1、错误透传、描述与 prompt 口径),修前 3 红、修后全绿;mvn test(JDK 21)2989 tests, 0 failures🤖 Generated with Claude Code