Skip to content

match_options: anchor-lookup-failure hint + schema description honesty (enumerate supported Unicode range) #150

Description

@kiki830621

Problem

From verify of #115 (DA P2 #4 + DA P2 #5):
「Discoverability 為零:MCP text not found error 沒提示有 math_script_insensitive flag,使用者照樣放棄。」
「Schema description 過度承諾:『xᵢ/xi 等視為等價』沒寫支援邊界,LLM caller 會 generalize 到 xᵦ/xβ 結果 0-match。」
— Source: team:devils-advocate (P2 each)
Verify report: #115 (comment)

Type

DX / docs honesty

Strategy

1. Anchor lookup failure hint

當 anchor lookup 失敗、且 match_options.math_script_insensitive 未啟用、且 needle 含 Unicode subscript / superscript:

func anchorNotFoundError(needle: String, tool: String, hadFlag: Bool) -> String {
    let baseMsg = "Error: \(tool): text '\(needle)' not found"
    if !hadFlag && containsMathScriptChars(needle) {
        return baseMsg + ". Hint: needle contains Unicode subscript/superscript chars (e.g., ₀ ₁ ⁱ); try match_options.math_script_insensitive: true."
    }
    return baseMsg
}

2. Schema description 列舉支援邊界

"description": "true 時 anchor 比對忽略 Unicode 數學上下標差異。
  支援範圍:
  - 數字下標 U+2080..U+2089 (₀..₉) ↔ 0..9
  - 數字上標 U+2070, U+2074..U+2079 (⁰ ⁴..⁹) ↔ 0..9
  - 字母下標 U+2090..U+2094, U+2095..U+209C 中 17 個字母 ↔ ASCII
  - Greek subscripts U+1D66..U+1D6A (ᵦᵧᵨᵩᵪ) ↔ βγρφχ  (隨 issue #P1L 補上)
  - Combining macron U+0304 (X̄) — 隨 issue #P1L 補上
  其他 Unicode 變體(vulgar fractions, mathematical alphanumerics 等)不在範圍。
  完整 mapping 見 ooxml-swift InsertLocation.swift mathScriptVariantMap。"

Test

  • needle 含 但 flag off → error message 含 hint
  • needle 純 ASCII 但 not found → error message 不含 hint(避免 false hint spam)
  • Schema fetch test 驗證 description contains "支援範圍" / "完整 mapping 見"

Related

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions