P1: Integrate fix_common_hamza into /api/analyze pipeline
- Standalone hamza-fix pass runs AFTER spelling, catches انت→أنت,
الان→الآن, ام→أم, انا→أنا in sentence context
- Works even when AraSpell is skipped (>300 chars)
P1: Split multi-word grammar diffs into individual suggestions
- Grammar corrections like 'الي المدرسه الاستاذ'→'إلى المدرسة الأستاذ'
now appear as 3 separate suggestions, not 1 merged block
- Users can accept/reject each correction individually
P2: Auto re-analyze after applying any suggestion (frontend)
- After applying single, alternative, or all suggestions,
editor automatically re-analyzes with 300ms delay
- Shows 'جار التحليل' without user needing to type anything
P3: Word truncation guard
- Reject spelling corrections that shorten valid words by 2+ chars
- Prevents الدمث→الدم (rare word truncation)
P3: CI/CD - regression tests on every push
- Added test job to GitHub Actions workflow
- Runs 120 tests before lint-and-validate
Added is_locked_by() to StageLocker that returns (start, end, owner).
Logs now show: locked by spelling[59:63] or locked by grammar[73:81]
This helps identify WHY punctuation marks get blocked.
fix(punctuation): allow pure punctuation changes through stage lock
BEFORE: Spelling locks 'بشدة' → punctuation can't add period after it
AFTER: If diff only adds/moves punctuation marks (Arabic text unchanged),
allow it through the lock even on locked ranges
Lock still blocks any diff that changes actual Arabic words.
feat(autocomplete): threshold=0.05 + max 3 suggestions
- Added self.threshold=0.05 — suggestions with score < 0.05 are filtered
- Changed default n from 5 to 3 everywhere (service, API, frontend)
- Threshold applied in _bigram_predict, _hybrid_predict, and GPT-2 fallback
fix(autocomplete): true context awareness - GPT-2 now adds own candidates + cache key uses 5 words
COMPLETELY INDEPENDENT from the correction pipeline. Zero interaction
with /api/analyze, StageLocker, OffsetMapper, PatchSet, or highlights.
Backend:
- src/nlp/autocomplete/ package (service, rules, init)
- HybridAutoComplete: lazy-loaded singleton, LRU cache, OOM fallback
- Bigram model from bayan10/AutoComplete (bigram_model_v4.pkl)
- GPT-2 from aubmindlab/aragpt2-base (optional, falls back to bigram)
- POST /api/autocomplete with {context, n} → {status, suggestions}
- /api/health now reports autocomplete status
Frontend:
- src/js/autocomplete.js — self-contained module
- Ghost text overlay (gray, semi-transparent, pointer-events:none)
- Dropdown with keyboard nav (↑/↓), TAB accept, ESC dismiss
- 400ms debounce, min 3 chars, cursor-aware context extraction
- CSS in components.css with dark/light theme support
59/59 existing pipeline tests passing
fix(critical): stop spelling from corrupting correct words + fix pronoun agreement + reject hallucinations
3 critical fixes:
1. IV PROTECTION: When both original AND correction are in-vocabulary (valid
Arabic words), ONLY accept the change if it's a known orthographic fix
(hamza whitelist or ه→ة). This blocks وكان→وكأن type corruption where
the model changes one correct word to a completely different correct word.
2. PRONOUN EXCLUSION: fix_subject_verb_agreement now excludes pronouns
(أنا, أنت, هو, etc.) from triggering plural verb agreement. Previously
it incorrectly changed أنا ذهبت → أنا ذهبتوا.
3. HALLUCINATION FILTER: Grammar diffs with Jaccard char similarity <0.3
are rejected (e.g. جالس→جاكسون). Prevents model hallucinations from
reaching the user.
Also adds [SPELLING] Accepted/Rejected debug logging for production tracing.
59/59 tests passing
fix: re-label grammar spelling fixes + handle prefix in hamza whitelist
S1 (P0): WordAligner now prefers ة over ه at word end when both IV
- araspell_rules.py _select_best_word: ه→ة preference for feminine nouns
S2 (P0): Gender preservation — reject corrections that drop feminine marker
- app.py _is_small_spelling_change: block بارده→بارد, منخفظه→منخفض
S3 (P1): Hamza whitelist — 50+ common Arabic hamza corrections
- araspell_rules.py HAMZA_WHITELIST + fix_common_hamza()
- Fixes: الي→إلى, انت→أنت, لان→لأن, امس→أمس, الايام→الأيام, etc.
G1 (P1): Verb-subject agreement for SVO word order
- grammar_rules.py fix_subject_verb_agreement()
- Handles: الطلاب ذهب→ذهبوا, الطالبات ذهب→ذهبن
P1 (P2): Punctuation model now only adds marks, no spelling/grammar changes
- punctuation_service.py _strip_non_punctuation_changes()
- Reverts PuncAra's baked-in spelling/grammar corrections, keeps only marks
S4 (P2): Mitigated by S1+S2+S3 — spelling now makes better corrections,
fewer bad locks blocking grammar
31/31 tests passing
fix: Deduplicate spelling/grammar overlap - grammar wins - When spelling and grammar both flag the same word position, keep only grammar suggestion - Prevents double-highlighting on conjugation errors like يعملوا
feat: Professional editor UI redesign - 3-column layout (docs | editor | sidebar) - Documents panel always visible on desktop - Import/export moved to left sidebar - Removed CTA button from nav - Replaced all emojis with SVG icons - Clean toolbar with separator - Mobile: docs stay as overlay sidebar
Grammar service:
- Add word count validation (reject if ratio < 0.5 or > 2.0)
- Add repetition detection (reject if 2+ consecutive repeated words)
- Add length check (reject if output > 2x input)
- Add character overlap check (reject if < 50% chars preserved)
Grammar diff in app.py:
- Break large replace blocks into individual word suggestions
- When word counts match, process EACH word pair separately
- Skip large blocks (>3 words) to prevent hallucination suggestions
- Each grammar suggestion now points to a single word, not entire sentence
- Keep spelling suggestions as-is (word-by-word, always correct)
- Build word-index map from corrected text back to original text
- Grammar diffs: spelling-corrected vs grammar-corrected (word-by-word)
- Map grammar positions back to original text via word-index map
- Skip grammar suggestions that overlap with spelling suggestions
- Remove broken unified diff approach that caused wrong alignments
fix: Rewrite suggestion system — unified diff eliminates text duplication - Instead of mapping grammar offsets back through OffsetMapper (broken), now: - Run full pipeline: spelling -> grammar -> punctuation - Do ONE clean diff: original_text vs final_text - Classify each change as spelling/grammar based on what spelling changed - Guarantees non-overlapping suggestions with correct offsets
fix: Handle N-to-M word replacements in analyze post-filter - Process each original word individually against corrected segment - Accept 1-to-1 small edits and 1-to-N word splits within multi-word blocks - Previously all multi-word blocks were silently rejected
fix: Relax analyze post-filters to show AraSpell corrections in editor - Allow 3 char edits (was 2), 50% ratio (was 40%) - Lower word-split threshold from 12 to 5 chars
feat: Add AraSpell spelling correction endpoint (POST /api/spelling) with lazy model loading - Extract AraSpell pipeline into src/nlp/spelling/ (araspell_rules.py + araspell_service.py) - Pre-download AraBERT encoder-decoder + checkpoint in Dockerfile - Lazy load on first request, contextual=False to save RAM - Update health check to report spelling status
- HF Spaces free tier blocks ALL outbound DNS - no external API calls possible
- Load summarization model locally with float16 (280MB vs 560MB)
- Install CPU-only PyTorch (~200MB vs ~2GB)
- Spelling/punctuation/autocomplete gracefully degrade (return input unchanged)
- Health check accurately reports model availability
fix: Add wait_for_model, debug endpoint, and better HF API error handling
- Add src/hf_inference.py: wrapper for HF Inference API calls
- Update app.py: USE_HF_API flag enables remote inference when HF_API_TOKEN is set
- All routes (summarize, spelling, grammar, punctuation, autocomplete, analyze) support HF API mode
- Health check returns HTTP 200 with all models=true in HF API mode
- No local model loading needed - saves 2GB+ RAM
- Backwards compatible: local models still work when HF_API_TOKEN is not set