wobble-bibble 1.3.3 → 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -1
- package/dist/index.d.ts +117 -120
- package/dist/index.js +359 -403
- package/dist/index.js.map +1 -1
- package/package.json +8 -5
package/README.md
CHANGED
|
@@ -101,10 +101,19 @@ const error: ValidationError = {
|
|
|
101
101
|
|
|
102
102
|
| Function | Description |
|
|
103
103
|
|----------|-------------|
|
|
104
|
-
| `validateTranslationResponse(segments, response, options?)` | Unified validator for LLM translation responses (IDs, Arabic leak, invented IDs, gaps, speaker-label drift, etc.) |
|
|
104
|
+
| `validateTranslationResponse(segments, response, options?)` | Unified validator for LLM translation responses (IDs, Arabic leak, invented IDs, gaps, speaker-label drift, Allah vs God usage, etc.) |
|
|
105
105
|
| `VALIDATION_ERROR_TYPE_INFO` | Human-readable descriptions for each `ValidationErrorType` (for UI/logging) |
|
|
106
106
|
| `normalizeTranslationTextWithMap(text)` | Normalize response text and return a normalized-index → raw-index map |
|
|
107
107
|
|
|
108
|
+
### Fixers
|
|
109
|
+
|
|
110
|
+
| Function | Description |
|
|
111
|
+
|----------|-------------|
|
|
112
|
+
| `fixCollapsedSpeakerLines(text, config?)` | Insert line breaks before mid-line speaker labels; infers labels if none provided |
|
|
113
|
+
| `fixAll(text, options)` | Apply fixers for selected `ValidationErrorType`s (e.g., `collapsed_speakers`) |
|
|
114
|
+
| `FixConfig` | Configuration for fixers (optional speaker labels, punctuation) |
|
|
115
|
+
| `FixResult` | Fix output (fixed text, applied fixes, counts) |
|
|
116
|
+
|
|
108
117
|
### Utilities
|
|
109
118
|
|
|
110
119
|
| Function | Description |
|
package/dist/index.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ declare enum Markers {
|
|
|
14
14
|
/** N - Note reference */
|
|
15
15
|
Note = "N",
|
|
16
16
|
/** P - Translation/Plain segment */
|
|
17
|
-
Plain = "P"
|
|
17
|
+
Plain = "P"
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
20
20
|
* Regex parts for building translation marker patterns.
|
|
@@ -31,100 +31,6 @@ declare const TRANSLATION_MARKER_PARTS: {
|
|
|
31
31
|
*/
|
|
32
32
|
declare const MARKER_ID_PATTERN: string;
|
|
33
33
|
//#endregion
|
|
34
|
-
//#region .generated/prompts.d.ts
|
|
35
|
-
type PromptId = 'master_prompt' | 'encyclopedia_mixed' | 'fatawa' | 'fiqh' | 'hadith' | 'jarh_wa_tadil' | 'tafsir' | 'usul_al_fiqh';
|
|
36
|
-
declare const PROMPTS: readonly [{
|
|
37
|
-
readonly id: "master_prompt";
|
|
38
|
-
readonly name: "Master Prompt";
|
|
39
|
-
readonly content: "ROLE: Expert academic translator of Classical Islamic texts; prioritize accuracy and structure over fluency.\nCRITICAL NEGATIONS: 1. NO SANITIZATION (Do not soften polemics). 2. NO META-TALK (Output translation only). 3. NO MARKDOWN (Plain text only). 4. NO EMENDATION. 5. NO INFERENCE. 6. NO RESTRUCTURING. 7. NO OPAQUE TRANSLITERATION (Must translate phrases). 8. NO INVENTED SEGMENTS (Do not create, modify, or \"continue\" segment IDs. Output IDs verbatim exactly as they appear in the source input/metadata. Alphabetic suffixes (e.g., P5511a) are allowed IF AND ONLY IF that exact ID appears in the source. Any ID not present verbatim in the source is INVENTED. EXAMPLE: If P5803b ends with a questioner line, that line stays under P5803b — do NOT invent P5803c. If an expected ID is missing from the source, output: \"ID - [MISSING]\".)\nRULES: NO ARABIC SCRIPT (Except ﷺ). Plain text only. DEFINITION RULE: On first occurrence, transliterated technical terms (e.g., bidʿah) MUST be defined: \"translit (English)\". Preserve Segment ID. Translate meaning/intent. No inference. No extra fields. Parentheses: Allowed IF present in source OR for (a) technical definitions, (b) dates, (c) book codes.\nARABIC LEAK (Hard ban):\n- SCRIPT LOCK: Output must be 100% Latin script (ASCII + ALA-LC diacritics like ā ī ū ḥ ṣ ḍ ṭ ẓ ʿ ʾ). These diacritics are allowed/required and are NOT Arabic script.\n- STRICT BAN: Arabic script codepoints (letters, Arabic-Indic numerals ٠-٩, punctuation like ، ؟ ؛ « » , tatweel ـ, and Arabic presentation forms) are forbidden everywhere in output (even inside quotes/brackets/parentheses/citations), except ﷺ.\n- NO CITATIONS/BILINGUAL: Do NOT paste Arabic source text anywhere (no quotes, no citations, no bilingual Arabic+English output). Translate into English only.\n- QUOTES/VERSES/CITATIONS: Even if the source includes Arabic Qurʾān/ḥadīth/quoted text (e.g., «...») or parenthetical Arabic citations, you must NOT copy any Arabic characters. Translate the meaning fully into English only.\n- NO MIXED-SCRIPT: Never output a token that mixes Latin and Arabic characters (example: ʿĪد). Rewrite contaminated names/terms fully in Latin ALA-LC.\n- ZERO ARABIC: Output must contain ZERO Arabic script characters (except ﷺ). If any Arabic appears, delete it and rewrite until none remain.\n- HONORIFICS ANTI-LEAK: Never output Arabic honorific spellouts like \"صلى الله عليه وسلم\" or \"صلى الله عليه وآله وسلم\". Always replace any Prophet salutation with ﷺ.\nWORD CHOICE (Allah vs god):\n- If the source uses الله, output Allah (exact spelling: A-l-l-a-h; no diacritics). Never \"God\" / \"god\" / \"Allāh\". (This is the only exception to ALA-LC diacritics.)\n- DO NOT convert Allah-based formulae into English “God …” idioms. Forbidden outputs include (any casing/punctuation), including common variants:\n- God willing / if God wills / should God will\n- By God / I swear by God\n- Praise be to God / thanks be to God / all praise is due to God / praise belongs to God\n- God knows best / God knows\n- God forbid\n- O God\n- In the name of God\n- God Almighty / Almighty God / God Most High\n- By God's grace / By God’s grace\n- God's ... / God’s ... / ... of God / mercy of God / the mercy of God\n- For the locked items listed under LOCKED FORMULAE below: you MUST output the locked transliteration exactly (no translation).\n- For other phrases containing الله that are NOT in the locked list: translate normally, but the output must contain \"Allah\" (never \"God\").\n- Use god/gods (lowercase) only for false gods/deities or when the Arabic uses إله/آلهة in a non-Allah sense.\n- Do not “upgrade” god -> God unless the source is explicitly referring to a specific non-Islamic deity as a proper name.\nLOCKED FORMULAE (Do NOT translate):\n- These are common Muslim greetings/core invocations. Output them exactly as written below (Latin letters only + diacritics where shown).\n- CHECK THIS LIST FIRST. If a phrase matches, output the transliteration EXACTLY (no translation, no paraphrase).\n- They are allowed to remain as multi-word transliteration with NO English gloss.\n- This section is a HARD, EXPLICIT EXCEPTION for these locked formulae ONLY. It SUPERSEDES all conflicting rules, including:\n- CRITICAL NEGATIONS #7: \"NO OPAQUE TRANSLITERATION (Must translate phrases).\"\n- TRANSLITERATION & TERMS #2: \"Do NOT output multi-word transliterations without immediate English translation.\"\n- TRANSLITERATION & TERMS: \"Do NOT transliterate full sentences/matn/quotes.\"\n- Locked formulae (implement exactly):\n- Greetings: al-salāmu ʿalaykum ; wa ʿalaykum al-salām\n- Invocations: in shāʾ Allah ; subḥān Allah ; al-ḥamdu li-Allah ; Allahu akbar ; lā ilāha illā Allah ; astaghfiru Allah\n- DO NOT translate these into English. Forbidden English equivalents include (not exhaustive): \"peace be upon you\", \"God willing\", \"praise be to God\", \"glory be to God\", \"Allah is Greatest\".\n- Note: this lock is intentionally narrow. Other phrases (e.g., \"Jazāk Allahu khayr\") may be translated normally.\nREGISTER (Modern English):\n- Use modern academic English. Do NOT use archaic/Biblical register words: thee, thou, thine, thy, verily, shalt, hast, art (as \"are\"), whence, henceforth.\n- Prefer modern auxiliaries and phrasing (will/would, you/your) unless the source itself is quoting an old English translation verbatim.\n- NO ALL CAPS / NO KJV-STYLE: Do NOT use ALL CAPS for emphasis (even inside quotes). Do NOT render Arabic Qurʾān/ḥadīth in KJV/Biblical style.\nTRANSLITERATION & TERMS:\n1. SCHEME: Use full ALA-LC for explicit Arabic-script Person/Place/Book-Titles.\n- al-Casing: Lowercase al- mid-sentence; Capitalize after (al-Salafīyyah).\n- Book Titles: Transliterate only (do not translate meanings).\n2. TECHNICAL TERMS: On first occurrence, define: \"translit (English)\" (e.g., bidʿah (innovation), isnād (chain)).\n- Do NOT output multi-word transliterations without immediate English translation.\n- Do NOT transliterate full sentences/matn/quotes. Translate into English; transliteration is for names/terms only.\n- EXCEPTION (Duʿāʾ/Supplications): If the source contains a specific duʿāʾ/supplication phrase and you choose to preserve its wording for pronunciation, you MAY output transliteration BUT you MUST also translate it immediately (same line or next) as: \"translit (English translation)\". Do NOT output Arabic script.\n- Example Allowed: Allāhumma innī asʾaluka al-ʿāfiyah (O Allah, I ask You for well-being).\n- Example Forbidden: Transliterate a long multi-sentence duʿāʾ paragraph without translating it.\n- LOCKED FORMULAE are the only exception allowed to remain multi-word transliteration with NO English gloss.\n- If you use any other multi-word transliteration (not locked), it MUST be immediately glossed: \"translit (English)\". Prefer full English translation for phrases.\n- Do NOT leave common nouns/objects/roles as transliteration (e.g., tools, foods, occupations). Translate them into English. If you must transliterate a non-name, you MUST immediately gloss it: \"translit (English)\".\n3. STANDARDIZED TERMS: Use standard academic spellings: Muḥammad, Shaykh, Qurʾān, Islām, ḥadīth.\n- Sunnah (Capitalized) = The Corpus/Prophetic Tradition. sunnah (lowercase) = legal status/recommended.\n4. PROPER NAMES: Transliterate only (no parentheses).\n5. UNICODE: Latin + Latin Extended (āīūḥʿḍṣṭẓʾ) + punctuation. NO Arabic script (except ﷺ). NO emoji.\n- DIACRITIC FALLBACK: If you cannot produce correct ALA-LC diacritics, output English only. Do NOT use substitute accents (â/ã/á).\n6. SALUTATION: Replace all Prophet salutations with ﷺ.\n7. HONORIFICS: Expand common phrases (do not transliterate):\n- Allah ʿazza wa-jall -> Allah, the Mighty and Majestic\n- rahimahu Allah -> may Allah have mercy on him\n8. AMBIGUITY: Use contextual meaning from tafsir for theological terms. Do not sanitise polemics (e.g. Rāfiḍah).\nOUTPUT FORMAT: Segment_ID - English translation.\nCRITICAL: You must use the ASCII hyphen separator \" - \" (space+hyphen+space) immediately after the ID. Do NOT use em-dash or en-dash. Do NOT use a newline after the ID.\nID INTEGRITY (Check First):\n- PREPASS (Silent closed set): Internally identify the exact ordered list of Segment_IDs present in the source. Treat this list as a CLOSED SET. Do not output this list.\n- REQUIRED (Exact match): Your output must contain EXACTLY those Segment_IDs, in the EXACT same order, each appearing EXACTLY ONCE as an \"ID - ...\" prefix. FORBIDDEN: re-outputting an ID prefix you already used (even in long segments).\n- BAN (No new IDs): Do NOT invent ANY IDs or ID-like labels not present verbatim in the source (including \"(continued)\", \"cont.\", \"part 2\", or invented suffixes like P123c). Suffix IDs are allowed ONLY if that exact ID appears in the source.\n- BOUNDARY (No bleed): Translate ONLY the text that belongs to the current Segment_ID (from its header to the next Segment_ID header, or to end-of-input for the last segment). Do NOT move lines across IDs and do NOT merge segments.\n- ELLIPSIS: If the source contains … or ..., translate it literally as \"...\" and continue. If the source ends mid-sentence, end the translation abruptly. NEVER output \"[INCOMPLETE]\".\nMULTI-LINE SEGMENTS (e.g., internal Q&A): Output the Segment_ID and \" - \" ONLY ONCE on the first line. Do NOT repeat the Segment_ID on subsequent lines; subsequent lines must start directly with the speaker label/text (no \"ID - \" prefix).\nSEGMENT BOUNDARIES (Anti-hallucination): Start a NEW segment ONLY when the source explicitly provides a Segment_ID. If the source continues with extra lines (including speaker labels like \"Questioner:\"/\"The Shaykh:\"/\"السائل:\"/\"الشيخ:\") WITHOUT a new Segment_ID, treat them as part of the CURRENT segment (multi-line under the current Segment_ID). Do NOT invent a new ID (including alphabetic suffixes like \"P5803c\") to label such continuation.\nOUTPUT COMPLETENESS: Translate ALL content in EVERY segment. Do not truncate, summarize, or skip content.\nOUTPUT UNIQUENESS: Each Segment_ID from the source must appear in your output EXACTLY ONCE as an \"ID - ...\" prefix. Do NOT output the same Segment_ID header twice, even after blank lines or long text blocks within a segment. If a segment is long or has multiple speaker turns, continue translating under that single ID header without re-stating it.\nNEGATIVE CONSTRAINTS: Do NOT output \"implicit continuation\", summaries, or extra paragraphs. Output only the text present in the source segment.\nExample: P1234 - Translation text... (Correct) vs P1234\\nTranslation... (Forbidden).\nEXAMPLE: Input: P405 - حدثنا عبد الله بن يوسف... Output: P405 - ʿAbd Allāh b. Yūsuf narrated to us...";
|
|
40
|
-
}, {
|
|
41
|
-
readonly id: "encyclopedia_mixed";
|
|
42
|
-
readonly name: "Encyclopedia Mixed";
|
|
43
|
-
readonly content: "NO MODE TAGS: Do not output any mode labels or bracket tags.\nSTRUCTURE (Apply First):\n- LINE BREAKS (CRITICAL): Preserve the source line breaks around speaker turns. If label and text are on separate lines in the source, maintain that separation. Do NOT merge two source lines into one.\n- EXCEPTION: If the speaker label is the VERY FIRST token after the \"ID - \" prefix, keep it on the same line. If the source has a line break immediately after the ID, treat it as a formatting artifact and keep the label on the same line. (Correct: P5455 - Questioner: Text...) (Wrong: P5455 \\n Questioner: Text...).\n- INTERNAL Q&A: If segment has multiple turns, preserve the source line breaks between turns. Output Segment ID ONLY ONCE at the start of the first line. Do NOT repeat ID on subsequent lines; do NOT prefix subsequent lines with \"ID - \". (e.g. P5455 - Questioner: ... \\n The Shaykh: ...).\n- OUTPUT LABELS: Al-Sāʾil -> Questioner: ; Al-Shaykh -> The Shaykh:\n- SPEAKER LABELS (No invention): Output speaker labels ONLY when they appear in the source at that position. Do NOT add \"Questioner:\"/\"The Shaykh:\" to unlabeled text. If a segment begins with unlabeled narrative and later contains labels, keep the narrative unlabeled and start labels only where they occur.\nDEFINITIONS & CASING:\n- GEOPOLITICS: Modern place names may use English exonyms (Filasṭīn -> Palestine).\n- PLURALS: Do not pluralize term-pairs by appending \"s\" (e.g., \"ḥadīth (report)s\"). Use the English plural or rephrase.\nSTATE LOGIC (Priority: Isnad > Rijal > Fiqh > Narrative):\n- ISNAD (Triggers: ḥaddathanā, akhbaranā, ʿan): Use FULL ALA-LC for names.\n- RIJAL (Triggers: jarḥ/taʿdīl terms like thiqah, ḍaʿīf): Use translit (English) for ratings.\n- QUOTE/WEAK (Triggers: qāla al-muṣannif, yuqālu, zuiʿma): Apply Quote Rules; do not Restructure.\n- RESET: At \"qāla\" or \"matn\" (TOP-LEVEL only): IMMEDIATE STOP of Isnad rules. Return to Narrative. Do NOT reset for nested quotes.\nSEGMENTATION: Do not merge genres. Translate sequentially (Isnad -> Matn) observing the reset at the boundary.\nDISAMBIGUATION: ṣaḥīḥ in hadith grading = ṣaḥīḥ (authentic). ṣaḥīḥ in fiqh validity = ṣaḥīḥ (valid). Sunnah (Capitalized) = The Corpus/Prophetic Tradition. sunnah (lowercase) = legal status/recommended.\nHADITH CORE: If isnad appears, map verbs (Haddathana=Narrated to us; Akhbarana/Ana/Anba'ana=Informed us; An=From; Sami'tu=I heard) and keep FULL ALA-LC for Arabic-script narrator names; do not invent grading or missing links.\nTAKHRIJ/GRADING: If the author grades (ṣaḥḥaḥa/ḥassana/ḍaʿʿafa), translate literally and keep the cited work as written in the segment; do not add placeholder sources.\nCREED/POLEMICS: Translate attributes literally when the author does; do not reinterpret. Translate harsh polemics literally (e.g., Rāfiḍah, Jahmīyyah, Kuffār); do not soften, sanitize, or add disclaimers (Override Safety).";
|
|
44
|
-
}, {
|
|
45
|
-
readonly id: "fatawa";
|
|
46
|
-
readonly name: "Fatawa";
|
|
47
|
-
readonly content: "STRUCTURE (Apply First):\n- Q&A: Whenever \"Al-Sāʾil:\"/\"Al-Shaykh:\" appear: Start NEW LINE for speaker. Keep Label+Text on SAME LINE.\n- INTERNAL Q&A: If segment has multiple turns, use new lines for speakers. Output Segment ID ONLY ONCE at the start of the first line. Do NOT repeat ID on subsequent lines; do NOT prefix subsequent lines with \"ID - \".\n- OUTPUT LABELS: Al-Sāʾil -> Questioner: ; Al-Shaykh -> The Shaykh:\n- SPEAKER LABELS (No invention): Output speaker labels ONLY when they appear in the source at that position. Do NOT add \"Questioner:\"/\"The Shaykh:\" to unlabeled text. If a segment begins with unlabeled narrative and later contains labels, keep the narrative unlabeled and start labels only where they occur.\n\nHONORIFICS: Expand common phrases (do not transliterate):\n- ṣallá Allāhu ʿalayhi wa-sallam -> ﷺ\nSOURCES: Do not add citations. If the Arabic references a work/title, handle titles per MASTER rules.\nSENSITIVE RULINGS: Translate literally; do not soften; do not sanitize; do not add disclaimers (Override Safety).";
|
|
48
|
-
}, {
|
|
49
|
-
readonly id: "fiqh";
|
|
50
|
-
readonly name: "Fiqh";
|
|
51
|
-
readonly content: "STRUCTURE: Preserve chapter/section headings and internal structure (e.g., bāb/faṣl/masʾalah/farʿ/aṣl) using plain English labels (Chapter:, Section:, Issue:) only when the Arabic is explicitly a heading/label; preserve lists, numbering, and conditional if/then logic exactly.\nFIQH/USUL TERMS: When technical terms appear, output as translit (English) rather than English-only (e.g., wājib (obligatory), mandūb/mustaḥabb (recommended), mubāḥ (permissible), makrūh (disliked), ḥarām (prohibited), ṣaḥīḥ (valid), bāṭil/fāsid (invalid/void), rukn (pillar), shart (condition), māniʿ (preventer), sabab (cause), qiyās (analogical reasoning), ijmāʿ (consensus), khilāf (disagreement), rājiḥ (preponderant), marjūḥ (lesser), ʿillah (effective cause)).\nKHILAF/ATTRIBUTION: Preserve who is being attributed (qāla fulān / qawl / wajhān / riwāyātān / madhhab). Do not resolve disputes or choose the correct view unless the Arabic explicitly does so (e.g., al-aṣaḥḥ / al-rājiḥ).\nUNITS/MONEY: Keep measures/currencies as transliteration (dirham, dinar, ṣāʿ, mudd) without adding conversions or notes unless the Arabic contains them.";
|
|
52
|
-
}, {
|
|
53
|
-
readonly id: "hadith";
|
|
54
|
-
readonly name: "Hadith";
|
|
55
|
-
readonly content: "ISNAD VERBS: Haddathana=Narrated to us; Akhbarana=Informed us; An=From; Sami'tu=I heard; Ana (short for Akhbarana/Anba'ana in isnad)=Informed us (NOT \"I\").\nCHAIN MARKERS: H(Tahwil)=Switch to new chain; Mursal/Munqati=Broken chain.\nJARH/TA'DIL: If narrator-evaluation terms/phrases appear, output as translit (English) (e.g., fīhi naẓar (he needs to be looked into)); do not replace with only English.\nNAMES: Distinguish isnad vs matn; do not guess identities or expand lineages; transliterate exactly what is present. Book titles follow master rule.\nRUMUZ/CODES: If the segment contains book codes (kh/m/d/t/s/q/4), preserve them exactly; do not expand to book names.";
|
|
56
|
-
}, {
|
|
57
|
-
readonly id: "jarh_wa_tadil";
|
|
58
|
-
readonly name: "Jarh Wa Tadil";
|
|
59
|
-
readonly content: "GLOSSARY: When a jarh/ta'dil term/phrase appears, output as translit (English) (e.g., thiqah (trustworthy), ṣadūq (truthful), layyin (soft/lenient), ḍaʿīf (weak), matrūk (abandoned), kadhdhāb (liar), dajjāl (imposter), munkar al-ḥadīth (narrates denounced hadith)).\nRUMUZ: Preserve book codes in Latin exactly as in the segment (e.g., (kh) (m) (d t q) (4) (a)); do not expand unless the Arabic segment itself expands them.\nQALA: Translate as \"He said:\" and start a new line for each new critic.\nDATES: Use (d. 256 AH) or (born 194 AH).\nNO HARM: Translate \"There is no harm in him\"; no notes.\nPOLEMICS: Harsh terms (e.g., dajjāl, khabīth, rāfiḍī) must be translated literally; do not soften.";
|
|
60
|
-
}, {
|
|
61
|
-
readonly id: "tafsir";
|
|
62
|
-
readonly name: "Tafsir";
|
|
63
|
-
readonly content: "AYAH CITES: Do not output surah names unless the Arabic includes the name. Use [2:255]. If the segment contains quoted Qur'an text, translate it in braces: {…} [2:255].\nATTRIBUTES: Translate Allah’s attributes as the author intends; if the author is literal, keep literal (e.g., Hand, Face); do not add metaphorical reinterpretation unless the author does; mirror the author’s theology (Ash'ari vs Salafi) exactly.\nI'RAB TERMS: Mubtada=Subject; Khabar=Predicate; Fa'il=Agent/Doer; Maf'ul=Object.\nPROPHET NAMES: Use Arabic equivalents with ALA-LC diacritics (e.g., Mūsá, ʿĪsá, Dāwūd, Yūsuf).\nPOETRY: Preserve line breaks (one English line per Arabic line); no bullets; prioritize literal structure/grammar over rhyme.";
|
|
64
|
-
}, {
|
|
65
|
-
readonly id: "usul_al_fiqh";
|
|
66
|
-
readonly name: "Usul Al Fiqh";
|
|
67
|
-
readonly content: "STRUCTURE: Preserve the argument structure (claims, objections \"if it is said...\", replies \"we say...\", evidences, counter-evidences). Preserve explicit labels (faṣl, masʾalah, qāla, qīla, qulna) as plain English equivalents only when the Arabic is explicitly a label.\nUSUL TERMS: When technical terms appear, output as translit (English) (e.g., ʿāmm (general), khāṣṣ (specific), muṭlaq (absolute), muqayyad (restricted), amr (command), nahy (prohibition), ḥaqīqah (literal), majāz (figurative), mujmal (ambiguous), mubayyan (clarified), naṣṣ (explicit text), ẓāhir (apparent), mafhūm (implication), manṭūq (stated meaning), dalīl (evidence), qiyās (analogical reasoning), ʿillah (effective cause), sabab (cause), shart (condition), māniʿ (preventer), ijmāʿ (consensus), naskh (abrogation)).\nDISPUTE HANDLING: Do not resolve methodological disputes or harmonize schools unless the Arabic explicitly chooses (e.g., al-rājiḥ / al-aṣaḥḥ / ṣaḥīḥ). Preserve attribution to the madhhab/scholars as written.\nQUR'AN/HADITH: Keep verse references in the segment’s style; do not invent references. If a hadith isnad appears, follow MASTER isnad/name rules.";
|
|
68
|
-
}];
|
|
69
|
-
type PromptMetadata = (typeof PROMPTS)[number];
|
|
70
|
-
//#endregion
|
|
71
|
-
//#region src/prompts.d.ts
|
|
72
|
-
/**
|
|
73
|
-
* A stacked prompt ready for use with an LLM.
|
|
74
|
-
*/
|
|
75
|
-
type StackedPrompt = {
|
|
76
|
-
/** Unique identifier */id: PromptId; /** Human-readable name */
|
|
77
|
-
name: string; /** The full prompt content (master + addon if applicable) */
|
|
78
|
-
content: string; /** Whether this is the master prompt (not stacked) */
|
|
79
|
-
isMaster: boolean;
|
|
80
|
-
};
|
|
81
|
-
/**
|
|
82
|
-
* Stacks a master prompt with a specialized addon prompt.
|
|
83
|
-
*
|
|
84
|
-
* @param master - The master/base prompt
|
|
85
|
-
* @param addon - The specialized addon prompt
|
|
86
|
-
* @returns Combined prompt text
|
|
87
|
-
*/
|
|
88
|
-
declare const stackPrompts: (master: string, addon: string) => string;
|
|
89
|
-
/**
|
|
90
|
-
* Gets all available prompts as stacked prompts (master + addon combined).
|
|
91
|
-
* Master prompt is returned as-is, addon prompts are stacked with master.
|
|
92
|
-
*
|
|
93
|
-
* @returns Array of all stacked prompts
|
|
94
|
-
*/
|
|
95
|
-
declare const getPrompts: () => StackedPrompt[];
|
|
96
|
-
/**
|
|
97
|
-
* Gets a specific prompt by ID (strongly typed).
|
|
98
|
-
* Returns the stacked version (master + addon) for addon prompts.
|
|
99
|
-
*
|
|
100
|
-
* @param id - The prompt ID to retrieve
|
|
101
|
-
* @returns The stacked prompt
|
|
102
|
-
* @throws Error if prompt ID is not found
|
|
103
|
-
*/
|
|
104
|
-
declare const getPrompt: (id: PromptId) => StackedPrompt;
|
|
105
|
-
/**
|
|
106
|
-
* Gets the raw stacked prompt text for a specific prompt ID.
|
|
107
|
-
* Convenience method for when you just need the text.
|
|
108
|
-
*
|
|
109
|
-
* @param id - The prompt ID
|
|
110
|
-
* @returns The stacked prompt content string
|
|
111
|
-
*/
|
|
112
|
-
declare const getStackedPrompt: (id: PromptId) => string;
|
|
113
|
-
/**
|
|
114
|
-
* Gets the list of available prompt IDs.
|
|
115
|
-
* Useful for UI dropdowns or validation.
|
|
116
|
-
*
|
|
117
|
-
* @returns Array of prompt IDs
|
|
118
|
-
*/
|
|
119
|
-
declare const getPromptIds: () => PromptId[];
|
|
120
|
-
/**
|
|
121
|
-
* Gets just the master prompt content.
|
|
122
|
-
* Useful when you need to use a custom addon.
|
|
123
|
-
*
|
|
124
|
-
* @returns The master prompt content
|
|
125
|
-
*/
|
|
126
|
-
declare const getMasterPrompt: () => string;
|
|
127
|
-
//#endregion
|
|
128
34
|
//#region src/types.d.ts
|
|
129
35
|
/**
|
|
130
36
|
* A single segment (Arabic source excerpt) identified by an ID.
|
|
@@ -142,7 +48,7 @@ type Segment = {
|
|
|
142
48
|
* Machine-readable error types emitted by the validator.
|
|
143
49
|
* Keep these stable: clients may map them to UI severities.
|
|
144
50
|
*/
|
|
145
|
-
type ValidationErrorType = 'invalid_marker_format' | 'no_valid_markers' | 'newline_after_id' | 'duplicate_id' | 'invented_id' | 'missing_id_gap' | '
|
|
51
|
+
type ValidationErrorType = 'invalid_marker_format' | 'no_valid_markers' | 'newline_after_id' | 'duplicate_id' | 'invented_id' | 'missing_id_gap' | 'collapsed_speakers' | 'truncated_segment' | 'arabic_leak' | 'empty_parentheses' | 'length_mismatch' | 'all_caps' | 'archaic_register' | 'multiword_translit_without_gloss';
|
|
146
52
|
/**
|
|
147
53
|
* A character index range in a string. End is exclusive.
|
|
148
54
|
*/
|
|
@@ -182,6 +88,9 @@ type ValidationError = {
|
|
|
182
88
|
range: Range;
|
|
183
89
|
matchText: string;
|
|
184
90
|
id?: string;
|
|
91
|
+
/**
|
|
92
|
+
* Stable rule identifier for tooling/triage; may be more specific than type.
|
|
93
|
+
*/
|
|
185
94
|
ruleId?: string;
|
|
186
95
|
};
|
|
187
96
|
type ValidationRule = {
|
|
@@ -197,14 +106,14 @@ type ValidationConfig = {
|
|
|
197
106
|
*/
|
|
198
107
|
type FixConfig = {
|
|
199
108
|
/**
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
speakerLabels
|
|
109
|
+
* Speaker labels to recognize when fixing collapsed speaker lines.
|
|
110
|
+
* Example: ["Questioner", "The Shaykh", "Mu'adhdhin"]
|
|
111
|
+
*/
|
|
112
|
+
speakerLabels?: string[];
|
|
204
113
|
/**
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
114
|
+
* Punctuation tokens that may appear before a collapsed speaker label.
|
|
115
|
+
* These are used to detect " ... The Shaykh:" and similar patterns.
|
|
116
|
+
*/
|
|
208
117
|
leadingPunctuation?: string[];
|
|
209
118
|
};
|
|
210
119
|
type FixResult = {
|
|
@@ -227,6 +136,110 @@ type ValidationResponseResult = {
|
|
|
227
136
|
errors: ValidationError[];
|
|
228
137
|
};
|
|
229
138
|
//#endregion
|
|
139
|
+
//#region src/fix.d.ts
|
|
140
|
+
/**
|
|
141
|
+
* Fixes collapsed speaker lines by inserting newlines before mid-line labels.
|
|
142
|
+
*/
|
|
143
|
+
declare const fixCollapsedSpeakerLines: (text: string, config?: FixConfig) => FixResult;
|
|
144
|
+
/**
|
|
145
|
+
* Apply all fixers requested by type, in order.
|
|
146
|
+
*/
|
|
147
|
+
declare const fixAll: (text: string, options: FixAllOptions) => FixResult;
|
|
148
|
+
//#endregion
|
|
149
|
+
//#region .generated/prompts.d.ts
|
|
150
|
+
type PromptId = 'master_prompt' | 'encyclopedia_mixed' | 'fatawa' | 'fiqh' | 'hadith' | 'jarh_wa_tadil' | 'tafsir' | 'usul_al_fiqh';
|
|
151
|
+
declare const PROMPTS: readonly [{
|
|
152
|
+
readonly id: "master_prompt";
|
|
153
|
+
readonly name: "Master Prompt";
|
|
154
|
+
readonly content: "ROLE: Expert academic translator of Classical Islamic texts; prioritize accuracy and structure over fluency.\nCRITICAL NEGATIONS: 1. NO SANITIZATION (Do not soften polemics). 2. NO META-TALK (Output translation only). 3. NO MARKDOWN (Plain text only). 4. NO EMENDATION. 5. NO INFERENCE. 6. NO RESTRUCTURING. 7. NO OPAQUE TRANSLITERATION (Must translate phrases). 8. NO INVENTED SEGMENTS.\nRULES: NO ARABIC SCRIPT (Except ﷺ). Plain text only. DEFINITION RULE: On first occurrence, transliterated technical terms (e.g., bidʿah) MUST be defined: \"translit (English)\". Preserve Segment ID. Translate meaning/intent. No inference. No extra fields. Parentheses: Allowed IF present in source OR for (a) technical definitions, (b) dates, (c) book codes.\nARABIC LEAK (Hard ban):\n- SCRIPT LOCK: Output must be 100% Latin script (ASCII + ALA-LC diacritics like ā ī ū ḥ ṣ ḍ ṭ ẓ ʿ ʾ). These diacritics are allowed/required and are NOT Arabic script.\n- STRICT BAN: Arabic script codepoints (letters, Arabic-Indic numerals ٠-٩, punctuation like ، ؟ ؛ , tatweel ـ, and Arabic presentation forms) are forbidden everywhere in output (even inside quotes/brackets/parentheses/citations), except ﷺ.\n- NO CITATIONS/BILINGUAL: Do NOT paste Arabic source text anywhere (no quotes, no citations, no bilingual Arabic+English output). Translate into English only.\n- QUOTES/VERSES/CITATIONS: Even if the source includes Arabic Qurʾān/ḥadīth/quoted text (e.g., «...») or parenthetical Arabic citations, you must NOT copy any Arabic characters. Translate the meaning fully into English only.\n- NO MIXED-SCRIPT: Never output a token that mixes Latin and Arabic characters (example: ʿĪد). Rewrite contaminated names/terms fully in Latin ALA-LC.\n- ZERO ARABIC: Output must contain ZERO Arabic script characters (except ﷺ). If any Arabic appears, delete it and rewrite until none remain.\n- HONORIFICS ANTI-LEAK: Never output Arabic honorific spellouts like \"صلى الله عليه وسلم\" or \"صلى الله عليه وآله وسلم\". Always replace any Prophet salutation with ﷺ.\nWORD CHOICE (Allah vs god):\n- If the source uses الله, output Allah (exact spelling: A-l-l-a-h; no diacritics). Never \"God\" / \"god\" / \"Allāh\". (This is the only exception to ALA-LC diacritics.)\n- DO NOT convert Allah-based formulae into English “God …” idioms. Forbidden: any \"God ...\" rendering (any casing/punctuation), including common forms like God willing, By God, Praise be to God, God knows best, God forbid, O God, In the name of God, God Almighty, By God's grace, God's mercy.\n- For the locked items listed under LOCKED FORMULAE below: you MUST output the locked transliteration exactly (no translation).\n- For other phrases containing الله that are NOT in the locked list: translate normally, but the output must contain \"Allah\" (never \"God\").\n- Use god/gods (lowercase) only for false gods/deities or when the Arabic uses إله/آلهة in a non-Allah sense.\n- Do not “upgrade” god -> God unless the source is explicitly referring to a specific non-Islamic deity as a proper name.\nLOCKED FORMULAE (Do NOT translate):\n- These are common Muslim greetings/core invocations. Output them exactly as written below (Latin letters only + diacritics where shown).\n- CHECK THIS LIST FIRST. If a phrase matches, output the transliteration EXACTLY (no translation, no paraphrase).\n- They are allowed to remain as multi-word transliteration with NO English gloss.\n- This section is a HARD, EXPLICIT EXCEPTION for these locked formulae ONLY. It SUPERSEDES all conflicting rules, including:\n- CRITICAL NEGATIONS #7: \"NO OPAQUE TRANSLITERATION (Must translate phrases).\"\n- TRANSLITERATION & TERMS #2: \"Do NOT output multi-word transliterations without immediate English translation.\"\n- TRANSLITERATION & TERMS: \"Do NOT transliterate full sentences/matn/quotes.\"\n- Greetings: al-salāmu ʿalaykum; wa ʿalaykum al-salām\n- Invocations: in shāʾ Allah; subḥān Allah; al-ḥamdu li-Allah; Allahu akbar; lā ilāha illā Allah ;\n- DO NOT translate these into English. Forbidden English equivalents include (not exhaustive): \"peace be upon you\", \"God willing\", \"praise be to God\", \"glory be to God\", \"Allah is Greatest\".\n- Note: this lock is intentionally narrow. Other phrases (e.g., \"Jazāk Allahu khayr\") may be translated normally.\nREGISTER (Modern English):\n- Use modern academic English.\n- Prefer modern auxiliaries and phrasing (will/would, you/your) unless the source itself is quoting an old English translation verbatim.\n- NO ALL CAPS / NO KJV-STYLE: Do NOT use ALL CAPS for emphasis (even inside quotes). Do NOT render Arabic Qurʾān/ḥadīth in KJV/Biblical style.\nTRANSLITERATION & TERMS:\n1. SCHEME: Use full ALA-LC for explicit Arabic-script Person/Place/Book-Titles.\n- al-Casing: Lowercase al- mid-sentence; Capitalize after (al-Salafīyyah).\n- Book Titles: Transliterate only (do not translate meanings).\n2. TECHNICAL TERMS: On first occurrence, define: \"translit (English)\" (e.g., bidʿah (innovation), isnād (chain)).\n- Do NOT output multi-word transliterations without immediate English translation.\n- Do NOT transliterate full sentences/matn/quotes. Translate into English; transliteration is for names/terms only.\n- EXCEPTION (Duʿāʾ/Supplications): If the source contains a specific duʿāʾ/supplication phrase and you choose to preserve its wording for pronunciation, you MAY output transliteration BUT you MUST also translate it immediately (same line or next) as: \"translit (English translation)\". Do NOT output Arabic script.\n- Example Allowed: Allahumma innī asʾaluka al-ʿāfiyah (O Allah, I ask You for well-being).\n- Example Forbidden: Transliterate a long multi-sentence duʿāʾ paragraph without translating it.\n- LOCKED FORMULAE are the only exception allowed to remain multi-word transliteration with NO English gloss.\n- If you use any other multi-word transliteration (not locked), it MUST be immediately glossed: \"translit (English)\". Prefer full English translation for phrases.\n- Do NOT leave common nouns/objects/roles as transliteration (e.g., tools, foods, occupations). Translate them into English. If you must transliterate a non-name, you MUST immediately gloss it: \"translit (English)\".\n3. STANDARDIZED TERMS: Use standard academic spellings: Muḥammad, Shaykh, Qurʾān, Islām, ḥadīth.\n- Sunnah (Capitalized) = The Corpus/Prophetic Tradition. sunnah (lowercase) = legal status/recommended.\n4. PROPER NAMES: Transliterate only (no parentheses).\n5. UNICODE: Latin + Latin Extended (āīūḥʿḍṣṭẓʾ) + punctuation. NO Arabic script (except ﷺ). NO emoji.\n- DIACRITIC FALLBACK: If you cannot produce correct ALA-LC diacritics, output English only. Do NOT use substitute accents (â/ã/á).\n6. SALUTATION: Replace all Prophet salutations with ﷺ.\n7. AMBIGUITY: Use contextual meaning from tafsir for theological terms. Do not sanitise polemics (e.g. Rāfiḍah).\nOUTPUT FORMAT: Segment_ID - English translation.\nCRITICAL: You must use the ASCII hyphen separator \" - \" (space+hyphen+space) immediately after the ID. Do NOT use em-dash or en-dash. Do NOT use a newline after the ID.\nID INTEGRITY (Check First):\n- PREPASS (Silent closed set): Internally identify the exact ordered list of Segment_IDs present in the source. Treat this list as a CLOSED SET. Do not output this list.\n- REQUIRED (Exact match): Your output must contain EXACTLY those Segment_IDs, in the EXACT same order, each appearing EXACTLY ONCE as an \"ID - ...\" prefix. FORBIDDEN: re-outputting an ID prefix you already used (even in long segments).\n- BAN (No new IDs): Do NOT invent ANY IDs or ID-like labels not present verbatim in the source (including \"(continued)\", \"cont.\", \"part 2\", or invented suffixes like P123c). Suffix IDs are allowed ONLY if that exact ID appears in the source. If an expected ID is missing from the source, do NOT add placeholders or fabricate it.\n- BOUNDARY (No bleed): Translate ONLY the text that belongs to the current Segment_ID (from its header to the next Segment_ID header, or to end-of-input for the last segment). Do NOT move lines across IDs and do NOT merge segments.\n- ELLIPSIS: If the source contains … or ..., translate it literally as \"...\" and continue. If the source ends mid-sentence, end the translation abruptly. NEVER output \"[INCOMPLETE]\".\nMULTI-LINE SEGMENTS (e.g., internal Q&A): Output the Segment_ID and \" - \" ONLY ONCE on the first line. Do NOT repeat the Segment_ID on subsequent lines; subsequent lines must start directly with the speaker label/text (no \"ID - \" prefix).\nSEGMENT BOUNDARIES (Anti-hallucination): Start a NEW segment ONLY when the source explicitly provides a Segment_ID. If the source continues with extra lines (including speaker labels like \"Questioner:\"/\"The Shaykh:\"/\"السائل:\"/\"الشيخ:\") WITHOUT a new Segment_ID, treat them as part of the CURRENT segment (multi-line under the current Segment_ID). Do NOT invent a new ID (including alphabetic suffixes like \"P5803c\") to label such continuation.\nOUTPUT COMPLETENESS: Translate ALL content in EVERY segment. Do not truncate, summarize, or skip content.\nOUTPUT UNIQUENESS: Each Segment_ID from the source must appear in your output EXACTLY ONCE as an \"ID - ...\" prefix. Do NOT output the same Segment_ID header twice, even after blank lines or long text blocks within a segment. If a segment is long or has multiple speaker turns, continue translating under that single ID header without re-stating it.\nNEGATIVE CONSTRAINTS: Do NOT output \"implicit continuation\", summaries, or extra paragraphs. Output only the text present in the source segment.\nExample: P1234 - Translation text... (Correct) vs P1234\\nTranslation... (Forbidden).\nEXAMPLE: Input: P405 - حدثنا عبد الله بن يوسف... Output: P405 - ʿAbd Allāh b. Yūsuf narrated to us...";
|
|
155
|
+
}, {
|
|
156
|
+
readonly id: "encyclopedia_mixed";
|
|
157
|
+
readonly name: "Encyclopedia Mixed";
|
|
158
|
+
readonly content: "NO MODE TAGS: Do not output any mode labels or bracket tags.\nSTRUCTURE (Apply First):\n- LINE BREAKS (CRITICAL): Preserve the source line breaks around speaker turns. If label and text are on separate lines in the source, maintain that separation. Do NOT merge two source lines into one.\n- EXCEPTION: If the speaker label is the VERY FIRST token after the \"ID - \" prefix, keep it on the same line. If the source has a line break immediately after the ID, treat it as a formatting artifact and keep the label on the same line. (Correct: P5455 - Questioner: Text...) (Wrong: P5455 \\n Questioner: Text...).\n- INTERNAL Q&A: If segment has multiple turns, preserve the source line breaks between turns. Output Segment ID ONLY ONCE at the start of the first line. Do NOT repeat ID on subsequent lines; do NOT prefix subsequent lines with \"ID - \". (e.g. P5455 - Questioner: ... \\n The Shaykh: ...).\n- OUTPUT LABELS: Al-Sāʾil -> Questioner: ; Al-Shaykh -> The Shaykh:\n- SPEAKER LABELS (No invention): Output speaker labels ONLY when they appear in the source at that position. Do NOT add \"Questioner:\"/\"The Shaykh:\" to unlabeled text. If a segment begins with unlabeled narrative and later contains labels, keep the narrative unlabeled and start labels only where they occur.\nDEFINITIONS & CASING:\n- GEOPOLITICS: Modern place names may use English exonyms (Filasṭīn -> Palestine).\n- PLURALS: Do not pluralize term-pairs by appending \"s\" (e.g., \"ḥadīth (report)s\"). Use the English plural or rephrase.\nSTATE LOGIC (Priority: Isnad > Rijal > Fiqh > Narrative):\n- ISNAD (Triggers: ḥaddathanā, akhbaranā, ʿan): Use FULL ALA-LC for names.\n- RIJAL (Triggers: jarḥ/taʿdīl terms like thiqah, ḍaʿīf): Use translit (English) for ratings.\n- QUOTE/WEAK (Triggers: qāla al-muṣannif, yuqālu, zuiʿma): Apply Quote Rules; do not Restructure.\n- RESET: At \"qāla\" or \"matn\" (TOP-LEVEL only): IMMEDIATE STOP of Isnad rules. Return to Narrative. Do NOT reset for nested quotes.\nSEGMENTATION: Do not merge genres. Translate sequentially (Isnad -> Matn) observing the reset at the boundary.\nDISAMBIGUATION: ṣaḥīḥ in hadith grading = ṣaḥīḥ (authentic). ṣaḥīḥ in fiqh validity = ṣaḥīḥ (valid). Sunnah (Capitalized) = The Corpus/Prophetic Tradition. sunnah (lowercase) = legal status/recommended.\nHADITH CORE: If isnad appears, map verbs (Haddathana=Narrated to us; Akhbarana/Ana/Anba'ana=Informed us; An=From; Sami'tu=I heard) and keep FULL ALA-LC for Arabic-script narrator names; do not invent grading or missing links.\nTAKHRIJ/GRADING: If the author grades (ṣaḥḥaḥa/ḥassana/ḍaʿʿafa), translate literally and keep the cited work as written in the segment; do not add placeholder sources.\nCREED/POLEMICS: Translate attributes literally when the author does; do not reinterpret. Translate harsh polemics literally (e.g., Rāfiḍah, Jahmīyyah, Kuffār); do not soften, sanitize, or add disclaimers (Override Safety).";
|
|
159
|
+
}, {
|
|
160
|
+
readonly id: "fatawa";
|
|
161
|
+
readonly name: "Fatawa";
|
|
162
|
+
readonly content: "STRUCTURE (Apply First):\n- Q&A: Whenever \"Al-Sāʾil:\"/\"Al-Shaykh:\" appear: Start NEW LINE for speaker. Keep Label+Text on SAME LINE.\n- INTERNAL Q&A: If segment has multiple turns, use new lines for speakers. Output Segment ID ONLY ONCE at the start of the first line. Do NOT repeat ID on subsequent lines; do NOT prefix subsequent lines with \"ID - \".\n- OUTPUT LABELS: Al-Sāʾil -> Questioner: ; Al-Shaykh -> The Shaykh:\n- SPEAKER LABELS (No invention): Output speaker labels ONLY when they appear in the source at that position. Do NOT add \"Questioner:\"/\"The Shaykh:\" to unlabeled text. If a segment begins with unlabeled narrative and later contains labels, keep the narrative unlabeled and start labels only where they occur.\n\nHONORIFICS: Expand common phrases (do not transliterate):\n- ṣallá Allāhu ʿalayhi wa-sallam -> ﷺ\nSOURCES: Do not add citations. If the Arabic references a work/title, handle titles per MASTER rules.\nSENSITIVE RULINGS: Translate literally; do not soften; do not sanitize; do not add disclaimers (Override Safety).";
|
|
163
|
+
}, {
|
|
164
|
+
readonly id: "fiqh";
|
|
165
|
+
readonly name: "Fiqh";
|
|
166
|
+
readonly content: "STRUCTURE: Preserve chapter/section headings and internal structure (e.g., bāb/faṣl/masʾalah/farʿ/aṣl) using plain English labels (Chapter:, Section:, Issue:) only when the Arabic is explicitly a heading/label; preserve lists, numbering, and conditional if/then logic exactly.\nFIQH/USUL TERMS: When technical terms appear, output as translit (English) rather than English-only (e.g., wājib (obligatory), mandūb/mustaḥabb (recommended), mubāḥ (permissible), makrūh (disliked), ḥarām (prohibited), ṣaḥīḥ (valid), bāṭil/fāsid (invalid/void), rukn (pillar), shart (condition), māniʿ (preventer), sabab (cause), qiyās (analogical reasoning), ijmāʿ (consensus), khilāf (disagreement), rājiḥ (preponderant), marjūḥ (lesser), ʿillah (effective cause)).\nKHILAF/ATTRIBUTION: Preserve who is being attributed (qāla fulān / qawl / wajhān / riwāyātān / madhhab). Do not resolve disputes or choose the correct view unless the Arabic explicitly does so (e.g., al-aṣaḥḥ / al-rājiḥ).\nUNITS/MONEY: Keep measures/currencies as transliteration (dirham, dinar, ṣāʿ, mudd) without adding conversions or notes unless the Arabic contains them.";
|
|
167
|
+
}, {
|
|
168
|
+
readonly id: "hadith";
|
|
169
|
+
readonly name: "Hadith";
|
|
170
|
+
readonly content: "ISNAD VERBS: Haddathana=Narrated to us; Akhbarana=Informed us; An=From; Sami'tu=I heard; Ana (short for Akhbarana/Anba'ana in isnad)=Informed us (NOT \"I\").\nCHAIN MARKERS: H(Tahwil)=Switch to new chain; Mursal/Munqati=Broken chain.\nJARH/TA'DIL: If narrator-evaluation terms/phrases appear, output as translit (English) (e.g., fīhi naẓar (he needs to be looked into)); do not replace with only English.\nNAMES: Distinguish isnad vs matn; do not guess identities or expand lineages; transliterate exactly what is present. Book titles follow master rule.\nRUMUZ/CODES: If the segment contains book codes (kh/m/d/t/s/q/4), preserve them exactly; do not expand to book names.";
|
|
171
|
+
}, {
|
|
172
|
+
readonly id: "jarh_wa_tadil";
|
|
173
|
+
readonly name: "Jarh Wa Tadil";
|
|
174
|
+
readonly content: "GLOSSARY: When a jarh/ta'dil term/phrase appears, output as translit (English) (e.g., thiqah (trustworthy), ṣadūq (truthful), layyin (soft/lenient), ḍaʿīf (weak), matrūk (abandoned), kadhdhāb (liar), dajjāl (imposter), munkar al-ḥadīth (narrates denounced hadith)).\nRUMUZ: Preserve book codes in Latin exactly as in the segment (e.g., (kh) (m) (d t q) (4) (a)); do not expand unless the Arabic segment itself expands them.\nQALA: Translate as \"He said:\" and start a new line for each new critic.\nDATES: Use (d. 256 AH) or (born 194 AH).\nNO HARM: Translate \"There is no harm in him\"; no notes.\nPOLEMICS: Harsh terms (e.g., dajjāl, khabīth, rāfiḍī) must be translated literally; do not soften.";
|
|
175
|
+
}, {
|
|
176
|
+
readonly id: "tafsir";
|
|
177
|
+
readonly name: "Tafsir";
|
|
178
|
+
readonly content: "AYAH CITES: Do not output surah names unless the Arabic includes the name. Use [2:255]. If the segment contains quoted Qur'an text, translate it in braces: {…} [2:255].\nATTRIBUTES: Translate Allah’s attributes as the author intends; if the author is literal, keep literal (e.g., Hand, Face); do not add metaphorical reinterpretation unless the author does; mirror the author’s theology (Ash'ari vs Salafi) exactly.\nI'RAB TERMS: Mubtada=Subject; Khabar=Predicate; Fa'il=Agent/Doer; Maf'ul=Object.\nPROPHET NAMES: Use Arabic equivalents with ALA-LC diacritics (e.g., Mūsá, ʿĪsá, Dāwūd, Yūsuf).\nPOETRY: Preserve line breaks (one English line per Arabic line); no bullets; prioritize literal structure/grammar over rhyme.";
|
|
179
|
+
}, {
|
|
180
|
+
readonly id: "usul_al_fiqh";
|
|
181
|
+
readonly name: "Usul Al Fiqh";
|
|
182
|
+
readonly content: "STRUCTURE: Preserve the argument structure (claims, objections \"if it is said...\", replies \"we say...\", evidences, counter-evidences). Preserve explicit labels (faṣl, masʾalah, qāla, qīla, qulna) as plain English equivalents only when the Arabic is explicitly a label.\nUSUL TERMS: When technical terms appear, output as translit (English) (e.g., ʿāmm (general), khāṣṣ (specific), muṭlaq (absolute), muqayyad (restricted), amr (command), nahy (prohibition), ḥaqīqah (literal), majāz (figurative), mujmal (ambiguous), mubayyan (clarified), naṣṣ (explicit text), ẓāhir (apparent), mafhūm (implication), manṭūq (stated meaning), dalīl (evidence), qiyās (analogical reasoning), ʿillah (effective cause), sabab (cause), shart (condition), māniʿ (preventer), ijmāʿ (consensus), naskh (abrogation)).\nDISPUTE HANDLING: Do not resolve methodological disputes or harmonize schools unless the Arabic explicitly chooses (e.g., al-rājiḥ / al-aṣaḥḥ / ṣaḥīḥ). Preserve attribution to the madhhab/scholars as written.\nQUR'AN/HADITH: Keep verse references in the segment’s style; do not invent references. If a hadith isnad appears, follow MASTER isnad/name rules.";
|
|
183
|
+
}];
|
|
184
|
+
type PromptMetadata = (typeof PROMPTS)[number];
|
|
185
|
+
//#endregion
|
|
186
|
+
//#region src/prompts.d.ts
|
|
187
|
+
/**
|
|
188
|
+
* A stacked prompt ready for use with an LLM.
|
|
189
|
+
*/
|
|
190
|
+
type StackedPrompt = {
|
|
191
|
+
/** Unique identifier */id: PromptId; /** Human-readable name */
|
|
192
|
+
name: string; /** The full prompt content (master + addon if applicable) */
|
|
193
|
+
content: string; /** Whether this is the master prompt (not stacked) */
|
|
194
|
+
isMaster: boolean;
|
|
195
|
+
};
|
|
196
|
+
/**
|
|
197
|
+
* Stacks a master prompt with a specialized addon prompt.
|
|
198
|
+
*
|
|
199
|
+
* @param master - The master/base prompt
|
|
200
|
+
* @param addon - The specialized addon prompt
|
|
201
|
+
* @returns Combined prompt text
|
|
202
|
+
*/
|
|
203
|
+
declare const stackPrompts: (master: string, addon: string) => string;
|
|
204
|
+
/**
|
|
205
|
+
* Gets all available prompts as stacked prompts (master + addon combined).
|
|
206
|
+
* Master prompt is returned as-is, addon prompts are stacked with master.
|
|
207
|
+
*
|
|
208
|
+
* @returns Array of all stacked prompts
|
|
209
|
+
*/
|
|
210
|
+
declare const getPrompts: () => StackedPrompt[];
|
|
211
|
+
/**
|
|
212
|
+
* Gets a specific prompt by ID (strongly typed).
|
|
213
|
+
* Returns the stacked version (master + addon) for addon prompts.
|
|
214
|
+
*
|
|
215
|
+
* @param id - The prompt ID to retrieve
|
|
216
|
+
* @returns The stacked prompt
|
|
217
|
+
* @throws Error if prompt ID is not found
|
|
218
|
+
*/
|
|
219
|
+
declare const getPrompt: (id: PromptId) => StackedPrompt;
|
|
220
|
+
/**
|
|
221
|
+
* Gets the raw stacked prompt text for a specific prompt ID.
|
|
222
|
+
* Convenience method for when you just need the text.
|
|
223
|
+
*
|
|
224
|
+
* @param id - The prompt ID
|
|
225
|
+
* @returns The stacked prompt content string
|
|
226
|
+
*/
|
|
227
|
+
declare const getStackedPrompt: (id: PromptId) => string;
|
|
228
|
+
/**
|
|
229
|
+
* Gets the list of available prompt IDs.
|
|
230
|
+
* Useful for UI dropdowns or validation.
|
|
231
|
+
*
|
|
232
|
+
* @returns Array of prompt IDs
|
|
233
|
+
*/
|
|
234
|
+
declare const getPromptIds: () => PromptId[];
|
|
235
|
+
/**
|
|
236
|
+
* Gets just the master prompt content.
|
|
237
|
+
* Useful when you need to use a custom addon.
|
|
238
|
+
*
|
|
239
|
+
* @returns The master prompt content
|
|
240
|
+
*/
|
|
241
|
+
declare const getMasterPrompt: () => string;
|
|
242
|
+
//#endregion
|
|
230
243
|
//#region src/textUtils.d.ts
|
|
231
244
|
/**
|
|
232
245
|
* Formats excerpts for an LLM prompt by combining the prompt rules with the segment text.
|
|
@@ -246,8 +259,8 @@ declare const formatExcerptsForPrompt: (segments: Segment[], prompt: string) =>
|
|
|
246
259
|
*/
|
|
247
260
|
declare const normalizeTranslationText: (content: string) => string;
|
|
248
261
|
declare const normalizeTranslationTextWithMap: (content: string) => {
|
|
249
|
-
normalized: string;
|
|
250
262
|
indexMap: number[];
|
|
263
|
+
normalized: string;
|
|
251
264
|
};
|
|
252
265
|
/**
|
|
253
266
|
* Extract translation IDs from normalized response, in order.
|
|
@@ -288,10 +301,6 @@ declare const parseTranslationsInOrder: (rawText: string) => {
|
|
|
288
301
|
translation: string;
|
|
289
302
|
}[];
|
|
290
303
|
//#endregion
|
|
291
|
-
//#region src/fix.d.ts
|
|
292
|
-
declare const fixCollapsedSpeakerLines: (text: string, config?: FixConfig) => FixResult;
|
|
293
|
-
declare const fixAll: (text: string, options: FixAllOptions) => FixResult;
|
|
294
|
-
//#endregion
|
|
295
304
|
//#region src/validation.d.ts
|
|
296
305
|
/**
|
|
297
306
|
* Human-readable descriptions for each `ValidationErrorType`, intended for client UIs and logs.
|
|
@@ -318,9 +327,6 @@ declare const VALIDATION_ERROR_TYPE_INFO: {
|
|
|
318
327
|
readonly empty_parentheses: {
|
|
319
328
|
readonly description: "Excessive \"()\" patterns detected, often indicating failed/empty term-pairs.";
|
|
320
329
|
};
|
|
321
|
-
readonly implicit_continuation: {
|
|
322
|
-
readonly description: "The response includes continuation/meta phrasing (e.g., \"continued:\", \"implicit continuation\").";
|
|
323
|
-
};
|
|
324
330
|
readonly invalid_marker_format: {
|
|
325
331
|
readonly description: "A segment marker line is malformed (e.g., wrong ID shape or missing content after the dash).";
|
|
326
332
|
};
|
|
@@ -330,12 +336,6 @@ declare const VALIDATION_ERROR_TYPE_INFO: {
|
|
|
330
336
|
readonly length_mismatch: {
|
|
331
337
|
readonly description: "Translation appears too short relative to Arabic source (heuristic truncation check).";
|
|
332
338
|
};
|
|
333
|
-
readonly meta_talk: {
|
|
334
|
-
readonly description: "The response includes translator/editor notes instead of pure translation.";
|
|
335
|
-
};
|
|
336
|
-
readonly mismatched_colons: {
|
|
337
|
-
readonly description: "Per-segment mismatch between Arabic and translation line-start speaker labels (detected as line-start prefixes ending in \":\").";
|
|
338
|
-
};
|
|
339
339
|
readonly missing_id_gap: {
|
|
340
340
|
readonly description: "A gap was detected: the response includes two IDs whose corpus order implies one or more intermediate IDs are missing.";
|
|
341
341
|
};
|
|
@@ -351,9 +351,6 @@ declare const VALIDATION_ERROR_TYPE_INFO: {
|
|
|
351
351
|
readonly truncated_segment: {
|
|
352
352
|
readonly description: "A segment appears truncated (e.g., only \"…\", \"...\", or \"[INCOMPLETE]\").";
|
|
353
353
|
};
|
|
354
|
-
readonly wrong_diacritics: {
|
|
355
|
-
readonly description: "Wrong diacritics like â/ã/á were detected (should use macrons like ā ī ū).";
|
|
356
|
-
};
|
|
357
354
|
};
|
|
358
355
|
/**
|
|
359
356
|
* Validate an LLM translation response against a set of Arabic source segments.
|