Skip to content

fix(editor): doc_find_text 返回的 matchIndex 归一成 1 基——差一归一补上回传方向(dev-board#369) - #703

Merged
zeweihan merged 1 commit into
masterfrom
fix/match-index-one-based-369
Sep 2, 2026
Merged

fix(editor): doc_find_text 返回的 matchIndex 归一成 1 基——差一归一补上回传方向(dev-board#369)#703
zeweihan merged 1 commit into
masterfrom
fix/match-index-one-based-369

Conversation

@zeweihan

@zeweihan zeweihan commented Sep 2, 2026

Copy link
Copy Markdown
Owner

背景

#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:回给模型前 oneBasedMatchIndexesmatches[].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
  • lowa-e2e 组 11 补四步钉 worker 事实(find_text_locations 0 起、只计可见匹配、按可见计数、越界拒绝且不动文档):479 passed, 0 failed(基线 475 -> 479)

🤖 Generated with Claude Code

@zeweihan
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
zeweihan force-pushed the fix/match-index-one-based-369 branch from 9205382 to f3d2743 Compare September 2, 2026 01:03
@zeweihan zeweihan changed the title fix(editor): matchIndex 全链路统一 1 基——第 N 处匹配不再差一(dev-board#369) fix(editor): doc_find_text 返回的 matchIndex 归一成 1 基——差一归一补上回传方向(dev-board#369) Sep 2, 2026
@zeweihan
zeweihan merged commit e91bf05 into master Sep 2, 2026
6 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 2, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant