MANGAYOMI_DIFF.md
docs/parity/MANGAYOMI_DIFF.md
1# Mangayomi Parity and Yokan Product-Difference Plan2## Commits from June 1, 2026 to September 4, 2026 (HEAD `f400d528`, v0.9.2)34---56## 1. Scope and Ground Truth78The current project is [Yokan](https://github.com/Schnitzel5/yokan). The historical upstream reference for this comparison is Mangayomi (`/Users/duongph/Projects/mangayomi`), an open-source multiplatform manga, anime, and novel application built with Flutter, Rust, and Isar.910This document provides a decision-ready comparison and engineering delivery plan analyzing all upstream developments between **June 1, 2026** and **September 4, 2026** (commits up to `f400d528`, Release v0.9.2, encompassing 631 commits across PR #700 through PR #973).1112### Definition of Parity13**Parity** means functional, behavioral, and reliability parity in user-observable application features:141. Discovering, browsing, and reading/watching manga, anime, and novels across multi-source ecosystems.152. Extension ecosystem breadth (JavaScript, Mihon APK, LnReader, and newly introduced Aidoku WASM extensions).163. Data integrity: transactional backups, encryption, non-destructive merging, and automated recovery.174. Robust networking: Cloudflare anti-bot bypass, custom DNS over HTTPS (DoH), and rate-limit mitigation.185. Large-screen and form-factor adaptation: full Android TV Leanback support with 10-foot D-pad navigation.196. Downloader resilience: per-source concurrency serialization, queue reordering, and stall watchdog protection.2021Parity does **not** mean replicating Flutter/Dart code patterns, Riverpod state models, or Isar database idioms inside Yokan. Yokan must maintain its native Kotlin Multiplatform (KMP) / Compose Multiplatform architecture, its native Room database, and its unified cross-media scope (manga, anime, novels, Together sync, desktop MPV playback).2223### Ground Truth Standards24Every claim in this document is derived from:25- Direct git log and code analysis of the upstream repository at `/Users/duongph/Projects/mangayomi`.26- Direct audit of the current Yokan repository at `/Users/duongph/Projects/yokan`.27- A route, entity, or stub in Yokan represents *design intent*, not verified functional parity. Concrete behavioral tests are required before any capability is marked as complete.2829---3031## 2. Current Architecture Baseline: Mangayomi vs. Yokan3233| Architectural Seam | Upstream Mangayomi (Flutter / Rust) | Current Yokan (Kotlin Multiplatform / Compose) |34|---|---|---|35| **UI Framework** | Flutter 3.x with custom widgets and Riverpod state management | Compose Multiplatform (Android, Desktop JVM, iOS, Wasm) |36| **Persistence** | Isar Database + Hive preferences with `DbWriteQueue` (`1908e11a`) | Room KMP with SQLite backing; `YokanDatabaseSnapshot` serialization |37| **Extension Runtimes** | - QuickJS (JavaScript)<br>- M-Extension-Server (Mihon APK bridge)<br>- LnReader JS isolate<br>- **Aidoku Native Rust WASM runtime** (`2694bc03`) | - QuickJS JVM / Android (`DbSourceCodeLanguage.JavaScript`)<br>- Mihon Extension Server (`DbSourceCodeLanguage.Mihon`)<br>- LnReader bridge (`DbSourceCodeLanguage.LnReader`)<br>- *No Aidoku runtime* |38| **Android TV Support** | Dedicated Leanback launcher, D-pad focus engine, TV shell, centered menus, display scaling (`8b6a2e63`, `9bea3398`) | Android mobile manifest only; no Leanback banner, no D-pad focus engine, no TV-specific UI |39| **Downloader** | Serialized per-source downloader with queue reordering, rate limiting, and stall watchdogs (`c0bf2844`, `be04cffc`) | `DownloadService.kt` with basic concurrent queue; no reordering, no per-source locking |40| **Backup & Restore** | Encrypted archives (AES-GCM), merge/replace modes, rollback, duplicate source tools (`3542a72a`, `420db07b`) | Unencrypted JSON/GZIP snapshot import/export; no password support, no transactional rollback |41| **Networking & Bypass** | FlareSolverr/Byparr proxy (`bbbe89cd`), custom DoH picker (`67a499b6`), native TLS root bundling (`63938ee0`) | OkHttp (Android/Desktop), Darwin (iOS), Ktor (Wasm); WebView challenge interception; no DoH picker or FlareSolverr |4243---4445## 3. Comprehensive Feature-Difference Matrix4647### Status Vocabulary48- **Present**: Yokan has a functional, verified implementation matching or exceeding Mangayomi.49- **Partial**: Yokan has an existing model, service contract, or basic UI, but lacks recent upstream enhancements or edge-case handling.50- **Unsupported**: The feature exists in upstream Mangayomi (post-June 1, 2026) but is entirely absent from Yokan.51- **Platform-specific**: The capability is inherently tied to a specific host OS (e.g., Android TV Leanback, iOS UIScene, desktop windowing).5253---5455### 3.1. Aidoku Extensions Support (Rust / WASM Ecosystem)5657*Upstream Commits: `bf1222ee`, `2694bc03`, `888cfa44`, `52dc298f`, `b4795dab` (PR #968, #969, #973)*5859| Feature / Upstream Capability | Yokan Status | Upstream Reference | Detailed Gap & Architectural Decision for Yokan |60|---|---|---|---|61| **Aidoku `.aidx` Package Ingestion** | **Unsupported** | `bf1222ee`, `lib/src/rust/` | Mangayomi unpacks `.aidx` archives containing `source.json` metadata and compiled WebAssembly (`main.wasm`). Yokan currently only supports JS and Mihon APK server. |62| **Native Rust WASM Runtime Bridge** | **Unsupported** | `2694bc03`, `flutter_rust_bridge` | Mangayomi embeds a Rust WASM runtime (Wasmer/Wasmtime) executing Aidoku bytecode via FFI. Yokan needs a KMP-compatible WASM host (Chicory for pure JVM/Android or a Rust C-interop dynamic library). |63| **Aidoku Host Standard Library ABI** | **Unsupported** | `2694bc03` | Mangayomi implements the full Aidoku host function environment: HTTP requests (`std::net`), JSON parser, HTML/DOM query parser, secure key-value store, and crypto. Yokan must provide matching KMP host imports. |64| **WASM Memory Disposal & Lifecycle** | **Unsupported** | `b4795dab` | Overrides `AidokuSource.dispose()` to explicitly free WASM instance memory and avoid native memory leaks during multi-source browsing. |6566---6768### 3.2. Backup, Restore, Security & Data Integrity6970*Upstream Commits: `3542a72a`, `2d8105f3`, `420db07b`, `9bd852fb`, `a84e504c`, `26b11440`, `ddd7ea75`, `d3f63599`, `b505b8e2`, `1fe3d8c8` (PR #880, #888, #894, #901, #905)*7172| Feature / Upstream Capability | Yokan Status | Upstream Reference | Detailed Gap & Architectural Decision for Yokan |73|---|---|---|---|74| **Password-Protected Encrypted Backups** | **Unsupported** | `420db07b`, `9bd852fb`, `a84e504c` | Mangayomi encrypts `.backup` zip archives using AES-256-GCM with a user-supplied password, storing salt/IV in archive headers. Yokan's `BackupRestoreService.kt` only outputs unencrypted raw JSON/GZIP. |75| **Transactional Restore & Rollback** | **Unsupported** | `3542a72a`, `2d8105f3` | If restore encounters corrupted data or disk failure mid-way, Mangayomi rolls back to the pre-restore state without data loss. Yokan writes directly into Room tables without rollback staging. |76| **Merge vs. Replace Import Policy** | **Unsupported** | `3542a72a`, `6f6a1983` | Users can choose between **Replace** (wipe library and install backup) and **Merge** (add missing titles, update chapters, retain existing non-conflicting items). Yokan currently performs unconditional overwrite. |77| **Duplicate Source Resolution** | **Unsupported** | `3542a72a` | Identifies when backup entries reference sources with conflicting IDs, URLs, or languages, providing an interactive mapping UI before persisting. |78| **Onboarding Restore with Source Guidance** | **Unsupported** | `d3f63599`, `b505b8e2`, `ddd7ea75` | First-run onboarding allows restoring directly from a backup and asks whether required sources should be automatically installed. Cancelling cleanly returns to onboarding. |79| **Post-Restore Sync Queue Flush** | **Partial** | `1fe3d8c8`, `8563b2b3` | Mangayomi immediately pushes restored library records to the sync server while acquiring a lock to prevent auto-sync races. Yokan's outbox does not handle full-state restore sync coordination. |8081---8283### 3.3. Android TV & Leanback Subsystem8485*Upstream Commits: `e0f7cfb2`, `5a9c3022`, `f2add477`, `853586f0`, `34caae85`, `8b6a2e63`, `e635cbba`, `4275f6ae`, `9feecd8e`, `4d256e75`, `2d60983f`, `799ce442`, `560b56ab`, `fe2b2295`, `07ee61cf`, `9bea3398`, `4acbe7ce`, `0cbfecc8`, `93b56b8d`, `1af5903d`, `bf36e3cc`, `165c5fc2`, `dc89fcfb`, `0b756a75`, `a1241acf`, `57f79a97`, `73299005` (PR #729, #799, #802, #813, #821, #860, #929, #938)*8687| Feature / Upstream Capability | Yokan Status | Upstream Reference | Detailed Gap & Architectural Decision for Yokan |88|---|---|---|---|89| **Android TV / Leanback Manifest Discovery** | **Platform-specific / Unsupported** | `e0f7cfb2`, `5a9c3022`, `f2add477` | Declares `LEANBACK_LAUNCHER` intent filter, `android.software.leanback` (optional), `android.hardware.touchscreen` (optional), and Leanback banner asset `icon_red_tv_2`. Yokan has no Leanback manifest entries. |90| **Runtime Form-Factor Detection (`isTv`)** | **Unsupported** | `34caae85` | Detects TV hardware using `UiModeManager.currentModeType == Configuration.UI_MODE_TYPE_TELEVISION` and provides global `isTv` state to switch layouts dynamically. |91| **Dedicated TV D-Pad Focus Model** | **Unsupported** | `8b6a2e63`, `9feecd8e`, `93b56b8d` | Implements D-pad directional focus navigation across all screens, prominent focus rings, glow elevation, automatic card scroll-into-view, and trap-free text entry for TV virtual keyboards. |92| **10-Foot TV Video Player Interface** | **Unsupported** | `e635cbba`, `fe2b2295` | Large TV-optimized player overlay with D-pad scrub controls, visual focus cues on audio/subtitle selectors, and quick-access player settings sheet formatted for remotes. |93| **Adaptable Universal UI Scale Engine** | **Unsupported** | `9bea3398`, `dc89fcfb`, `165c5fc2` | Global UI scaling factor slider (1.0x to 1.5x) affecting padding, fonts, and card dimensions, benefiting Android TV, desktop monitors, and accessibility users. |94| **TV-Specific Onboarding & Screen Suppression** | **Unsupported** | `07ee61cf`, `73299005`, `0b756a75` | Auto-defaults to dark mode, suppresses mobile-only update dialogs, hides the Downloads tab on TV, and presents a simplified D-pad first-run wizard. |95| **TV Live Memory Readout** | **Unsupported** | `57f79a97` | Lightweight diagnostic HUD monitoring live heap memory to identify OOM risks on RAM-constrained TV devices (e.g. 1.5GB Google TV sticks). |9697---9899### 3.4. Download Engine, Concurrency & Queue Resilience100101*Upstream Commits: `be04cffc`, `d11a91d9`, `dfb90d46`, `c59d6067`, `c0bf2844`, `6d7fa99d`, `61bf2cc1`, `478ded9f`, `acf32b3c`, `0f682f7a`, `d0768fc6`, `075cac81`, `265531f3`, `1f6fba4f`, `2a0225df`, `84e374cd` (PR #514, #746, #789, #815, #824)*102103| Feature / Upstream Capability | Yokan Status | Upstream Reference | Detailed Gap & Architectural Decision for Yokan |104|---|---|---|---|105| **Interactive Download Queue Reordering** | **Unsupported** | `be04cffc`, `d11a91d9`, `dfb90d46` | Allows drag-and-drop reordering of pending downloads; persists queue order to storage and coordinates with the worker gate. Yokan's queue is FIFO-only. |106| **Per-Source Serialization** | **Unsupported** | `c0bf2844` | Enforces that downloads from the same source domain execute sequentially (1 at a time) to prevent Cloudflare bans and HTTP 429 rate limits, even when global concurrency is high. |107| **Configurable Concurrency & Rate Limiting** | **Partial** | `c59d6067` | User settings to set global concurrent download slots (1–5) and delay intervals between chapter/page requests. Yokan lacks user-configurable download concurrency controls. |108| **Stall Watchdog & Connection Timeout** | **Unsupported** | `6d7fa99d`, `61bf2cc1`, `acf32b3c` | Socket read and connection watchdog that aborts stalled network streams (30s) and marks the task as failed with an actionable retry rather than hanging the UI indefinitely. |109| **Atomic File Cleanup on Cancellation/Crash** | **Partial** | `478ded9f`, `d0768fc6` | Erases partial and temporary download chunks when a task is cancelled, preventing corrupt files from being marked as completed upon app restart. |110| **Bulk Chapter Deletion UI** | **Partial** | `2a0225df`, `84e374cd` | One-tap button on title details to delete all downloaded chapters or select specific ranges to free storage. |111112---113114### 3.5. Version Comparison, Repository Ingestion & Deduplication115116*Upstream Commits: `ed4f411b`, `f9e04d51`, `c907312e`, `fe215117`*117118| Feature / Upstream Capability | Yokan Status | Upstream Reference | Detailed Gap & Architectural Decision for Yokan |119|---|---|---|---|120| **SemVer Version Comparison with Pre-Releases** | **Partial** | `ed4f411b` | Robust semantic version comparator supporting alphabetic suffixes (`1.0.0-beta.1`, `1.4b` vs `1.4.0`). Yokan's `compareSourceVersions` extracts only digits, leading to incorrect update notifications. |121| **Repository URL Deduplication & Normalization** | **Unsupported** | `f9e04d51` | Normalizes repository URLs (trailing slashes, HTTP/HTTPS, mirrors) to prevent duplicate repositories from polluting the source catalog. |122| **Dual Mihon Proto & JSON Repository Support** | **Partial** | `c907312e` | Mangayomi parses both Mihon repository `index.json` and compiled `index.proto` binary formats. Yokan currently only parses JSON repository indexes. |123124---125126### 3.6. Network Resilience, Cloudflare Bypass & Security127128*Upstream Commits: `bbbe89cd`, `67a499b6`, `ef345e99`, `56ba0d8e`, `63938ee0`, `8cafbc04` (PR #704, #709, #732, #760, #920)*129130| Feature / Upstream Capability | Yokan Status | Upstream Reference | Detailed Gap & Architectural Decision for Yokan |131|---|---|---|---|132| **Cloudflare Bypass Proxy (FlareSolverr / Byparr)** | **Unsupported** | `bbbe89cd` (PR #709) | Integrates FlareSolverr / Byparr HTTP proxy for resolving Cloudflare Turnstile and anti-bot challenges headlessly on Desktop, Android TV, and environments without active WebViews. |133| **Custom DNS over HTTPS (DoH) Picker** | **Unsupported** | `67a499b6` (PR #704) | Built-in DoH endpoint picker (Cloudflare, Google, AdGuard, Mullvad, custom endpoint) to bypass ISP-level DNS blocking of manga/anime domains. |134| **AES-GCM Extension Decryption Bridge** | **Unsupported** | `ef345e99`, `56ba0d8e` (PR #732, #760) | Exposes AES-GCM and AES-CBC hardware-accelerated decryption primitives to extension runtimes for decoding scrambled video streams and encrypted image packs. |135| **Bundled TLS Root Certificates** | **Partial** | `63938ee0`, `af240098` | Bundles Mozilla CA roots via WebPKI/Rustls to ensure HTTPS connections succeed on older Android devices with outdated system trust stores. |136137---138139### 3.7. Reader, Image Pipeline & Chapter Management140141*Upstream Commits: `f1170d47`, `4af383cb`, `96f1830a`, `2a2c3622`, `71a266e5`, `45ec2d1c`, `d11b3bb3`, `303d7ca7`, `7fa285d9`, `a3193109`, `cad6b9df`, `55c14021`, `c4075e2c` (PR #790, #794, #890, #895, #899, #948, #950, #967)*142143| Feature / Upstream Capability | Yokan Status | Upstream Reference | Detailed Gap & Architectural Decision for Yokan |144|---|---|---|---|145| **Missing-Chapter Gap Detection** | **Unsupported** | `f1170d47`, `4af383cb` | Scans chapter sequences and displays a discreet notice (e.g., *"1 missing chapter between Ch. 4 and Ch. 6"*); correctly differentiates unnumbered specials/prologues from missing chapters. |146| **Decimal & Season Chapter Identity** | **Partial** | `96f1830a`, `2a2c3622`, `71a266e5` | Preserves decimal chapter numbers (`12.5`) through deduplication and includes season tags in chapter identity to prevent chapter clobbering across seasons. |147| **Tiling Engine & Subsampling Image Decoder** | **Unsupported** | `45ec2d1c`, `d11b3bb3`, `303d7ca7` | Native subsampling image decoder for ultra-high-resolution webtoons, slicing giant bitmaps into render tiles to eliminate OOM crashes on Desktop and mobile. |148| **Sliding-Window Memory Eviction** | **Partial** | `7fa285d9` | Active memory manager in continuous reader that evicts pages outside a window of `current ± 3` pages while prefetching upcoming pages. |149| **Chapter Hash in Cache Filename** | **Unsupported** | `a3193109` | Incorporates a chapter hash into disk cache filenames to eliminate image cache collisions across chapters that share identical image names (e.g. `001.jpg`). |150| **Global Page Number Toggle** | **Partial** | `cad6b9df` (PR #790) | Central reader setting to toggle page number overlays globally across all reading modes. |151152---153154### 3.8. Browse, Library Organization & Migration155156*Upstream Commits: `d432bb39`, `453fe450`, `7a796bb4`, `f70ef3b5`, `7f7ca6bb`, `f8097009`, `675a9711`, `e63a857a`, `ad57e701`, `e386fcd9` (PR #623, #780, #803, #819, #825, #863, #868, #901)*157158| Feature / Upstream Capability | Yokan Status | Upstream Reference | Detailed Gap & Architectural Decision for Yokan |159|---|---|---|---|160| **Saved Searches per Source** | **Unsupported** | `d432bb39` | Users can bookmark complex filter/query configurations per source for 1-tap re-execution. |161| **Source Badges on Library Covers** | **Unsupported** | `453fe450` | Optional visual pill/badge on library cover cards indicating the hosting source name. |162| **Persistent Update-Errors Screen with Migration** | **Unsupported** | `7a796bb4`, `f70ef3b5` | Gathers all titles that failed during library updates into a dedicated review screen with a 1-tap "Migrate to New Source" shortcut. |163| **Cancellable Library Updates** | **Partial** | `7f7ca6bb` (PR #819) | Stop button in the updates UI that safely terminates active background source queries and commits partial progress. |164| **Selective / Range Migration** | **Partial** | `f8097009` (PR #780) | Multi-select checkboxes and range-selection tools allowing users to migrate subsets of titles from a deprecated source. |165| **Virtual Local Folders & Metadata Editing** | **Partial** | `675a9711`, `e63a857a` | Links custom external directories as virtual local sources without moving files; includes in-app comic metadata editor (`ComicInfo.xml`). |166| **Multi-Step First-Run Onboarding** | **Partial** | `e386fcd9`, `69dde42c` | Smooth initial wizard selecting reading interests (Manga/Anime/Novels), importing backups, or pre-installing recommended community repositories. |167168---169170### 3.9. Media, Anime Trackers & Archive Formats171172*Upstream Commits: `2b8a99f3`, `912b5337`, `3e034683`, `59a233bc`, `25a387dd`, `3efb6199`, `495fba52`, `f400d528`, `9ae1fd55`, `ea971047`, `e4a76f16` (PR #862, #865, #913, #940)*173174| Feature / Upstream Capability | Yokan Status | Upstream Reference | Detailed Gap & Architectural Decision for Yokan |175|---|---|---|---|176| **AniList Franchise Graph & Watch-Order Walk** | **Partial** | `2b8a99f3`, `912b5337`, `3e034683` | Traverses AniList GraphQL relation graphs (`PREQUEL`, `SEQUEL`, `PARENT`, `SIDE_STORY`) to build true chronological franchise timelines for anime. |177| **Tracker Account Identity in Settings** | **Unsupported** | `25a387dd`, `3efb6199` | Displays signed-in username, avatar, and token expiration state in tracker configuration screens (MAL, AniList, Kitsu, SIMKL). |178| **Torrent Infohash Normalization** | **Partial** | `f400d528` | Normalizes hex vs base32 infohashes, v1 vs v2 hybrid metadata, and extracts magnet display names reliably. |179| **RAR / CBR Archive Extraction** | **Unsupported** | `9ae1fd55` | Support for uncompressed and compressed RAR5 archives in local comic reader via native unrar/Rust bridge. |180| **iOS UIScene Adoption & Dark/Tinted Icons** | **Platform-specific** | `ea971047`, `e4a76f16`, `1070d5f1` | Adopts modern iOS 18 UIScene lifecycle, system Picture-in-Picture enhancements, and tinted alternate app icons. |181182---183184## 4. Technical Architecture Roadmap for Yokan185186To incorporate these upstream capabilities without duplicating Flutter technical debt, Yokan must follow these design guidelines within its Kotlin Multiplatform (KMP) architecture:187188### 4.1. Backup Security & Transactional Engine189- **Encryption Scheme**: Use standard AES-256-GCM. Derive a 256-bit encryption key using PBKDF2 with HMAC-SHA256 (100,000 iterations) and a 16-byte cryptographically secure random salt.190- **Archive Format**: Store metadata in a standard `.yokanbk` ZIP container. When encrypted, prefix the ZIP with a 32-byte header: `[Magic: "YOKAN_ENC"] [Salt: 16B] [IV: 12B] [AuthTag: 16B]`, followed by the ciphertext.191- **Transactional Staging**: Before applying any backup, execute all DB writes inside a single `roomDatabase.useWriterConnection { ... }` transaction or stage tables. If any deserialization error occurs, abort the transaction and restore pre-existing state.192- **Merge Mode**: When user selects "Merge", perform `INSERT OR IGNORE` on titles/chapters and reconcile progress timestamps by keeping the maximum reading progress (`max(existing.lastPage, backup.lastPage)`).193194### 4.2. Android TV & Compose Leanback Subsystem195- **Runtime TV Gate**: In `androidMain`, provide `isTvMode: Boolean` via `LocalTvMode` composition local, checking `uiModeManager.currentModeType == Configuration.UI_MODE_TYPE_TELEVISION`.196- **D-Pad Focus Engine**: Build a shared Compose modifier `Modifier.tvFocusable(onSelect: () -> Unit)` that adds:197 - Focused border highlight (`MaterialTheme.colorScheme.primary`).198 - Scale transform (`1.05f` on focus with spring animation).199 - Proper D-pad directional traversal (`FocusRequester.findChild`).200 - Key event listener capturing `Key.DirectionCenter` and `Key.Enter`.201- **TV Video Player Controls**: Create `TvVideoPlayerControls.kt` with a large D-pad scrub bar, 10-second skip buttons, and centered focusable dialogue sheets for audio/subtitle selection.202- **Leanback Discovery**: Add Android TV manifest entries in `composeApp/src/androidMain/AndroidManifest.xml` with `android.intent.category.LEANBACK_LAUNCHER`.203204### 4.3. Download Queue Serialization & Watchdog205- **Per-Source Mutex Gate**: Inside `DownloadCoordinator`, maintain a `ConcurrentHashMap<String, Mutex>()` keyed by source ID. A download task must acquire the source's lock before dispatching network requests, guaranteeing single-flight requests per source even if global concurrency is 3.206- **Queue Reordering**: Store an explicit `queuePosition: Int` column in the `downloads` Room table. Expose `reorderQueue(fromIndex: Int, toIndex: Int)` via `DownloadService` and update UI using `LazyColumn` with drag-and-drop reordering.207- **Stall Watchdog**: Wrap download stream reading in a coroutine timeout watchdog:208 ```kotlin209 withTimeout(30_000L) {210 source.read(buffer, count)211 }212 ```213 If reading yields 0 bytes for 30 seconds, cancel the connection, delete the partial `.tmp` file, and emit a `DownloadState.Stalled(retryable = true)` event.214215### 4.4. FlareSolverr & DoH Network Architecture216- **FlareSolverr Integration**: Add an optional `FlareSolverrService` implementing a simple HTTP client to `POST /v1` on the user's configured FlareSolverr endpoint (`http://localhost:8191/v1`). If a source request receives HTTP 403 / 503 with Cloudflare signatures, delegate the URL resolution to FlareSolverr to obtain fresh session cookies and user-agent.217- **Custom DoH Resolver**: In `commonMain` or platform HTTP clients (OkHttp / Ktor), configure custom DoH providers by passing an OkHttp `DnsOverHttps.Builder()` configured with user-selected URLs (Cloudflare `1.1.1.1`, Google `8.8.8.8`, AdGuard, or custom).218219### 4.5. Aidoku WASM Runtime Strategy220- **JVM / Desktop / Android Runtime**: Leverage **Chicory** (zero-native-dependency pure JVM WebAssembly interpreter) or compile a minimal Rust host library (`libyokan_aidoku_wasm`) providing a lightweight C-ABI via JNI/C-interop.221- **Aidoku ABI Shim**: Implement Aidoku's standard imports:222 - `aidoku_http_request(request_id)`: Maps to Yokan's shared OkHttp/Ktor network client.223 - `aidoku_json_parse()`: Maps to `kotlinx.serialization.json`.224 - `aidoku_html_query()`: Maps to a Kotlin HTML DOM parser (e.g. `ksoup`).225 - `aidoku_defaults_get/set()`: Maps to Yokan's per-source preference store.226- **Package Unpacker**: Ingest `.aidx` files, validate `source.json` metadata, extract `main.wasm`, and instantiate the module in an isolated runtime instance with clean `close()` disposal.227228---229230## 5. Phased Implementation Roadmap231232```mermaid233gantt234 title Yokan Mangayomi Parity Implementation Roadmap235 dateFormat YYYY-MM-DD236 section Phase P0: Core Integrity & Reliability237 Backup Encryption (AES-GCM) & Rollback :p0_1, 2026-09-07, 7d238 Download Queue Reordering & Per-Source Lock :p0_2, 2026-09-14, 7d239 SemVer Comparator & Repo Deduplication :p0_3, 2026-09-21, 5d240 section Phase P1: Networking & Reader Fidelity241 Chapter Gap Detection & Decimal Sorting :p1_1, 2026-09-28, 6d242 FlareSolverr Proxy & Custom DoH Picker :p1_2, 2026-10-04, 7d243 Sliding-Window Memory Eviction & Hash Cache:p1_3, 2026-10-11, 6d244 section Phase P2: Android TV & Leanback245 Leanback Manifest & Runtime TV Detection :p2_1, 2026-10-18, 5d246 TV D-Pad Focus Engine & Navigation Shell :p2_2, 2026-10-23, 8d247 10-Foot Video Player Overlay & Scaling :p2_3, 2026-10-31, 7d248 section Phase P3: Advanced Ecosystem & Media249 AniList Graph Walk & Tracker Accounts :p3_1, 2026-11-07, 7d250 Persistent Update Errors & Saved Searches :p3_2, 2026-11-14, 7d251 Aidoku WASM Host Runtime (Experimental) :p3_3, 2026-11-21, 14d252```253254### Detailed Phase Specifications255256#### Phase P0: Core Integrity & Reliability (Target: Weeks 1–3)257- **Deliverables**:258 1. Password-protected backup encryption (`AES-256-GCM`), transactional database restore with automatic rollback, and Merge vs. Replace import options.259 2. Download coordinator overhaul: drag-and-drop queue reordering, per-source download serialization, and socket stall watchdog.260 3. Strict SemVer comparator supporting pre-releases and alphanumeric suffixes; repository URL normalization and deduplication.261- **Acceptance Criteria**:262 - Restoring a corrupted or password-protected backup never crashes or leaves partial data in Room.263 - Concurrent downloads against the same source never fire in parallel.264 - Queue reordering updates persistent DB order and is maintained across app restarts.265266#### Phase P1: Networking & Reader Fidelity (Target: Weeks 4–6)267- **Deliverables**:268 1. Missing-chapter gap detector in chapter lists, handling decimal chapters (`12.5`) and unnumbered specials without false positives.269 2. FlareSolverr / Byparr anti-bot proxy client settings and custom DoH DNS resolver integration.270 3. Continuous reader sliding-window memory eviction (`current ± 3` pages) and chapter-hashed disk cache keys.271 4. Global reader page number overlay toggle.272- **Acceptance Criteria**:273 - Webtoon continuous reader does not exceed 150MB heap usage over 50 continuous pages.274 - Cloudflare-protected sources pass via FlareSolverr proxy on Desktop and Android without webview.275 - Chapter gaps display the exact number of missing chapters.276277#### Phase P2: Android TV & Leanback Subsystem (Target: Weeks 7–9)278- **Deliverables**:279 1. Android TV Leanback launcher declarations, banner asset, and runtime `isTvMode` detection.280 2. Compose D-pad focus system (`tvFocusable`), high-contrast focus rings, and scroll-into-view behavior.281 3. Dedicated 10-foot TV video player controls, subtitle/audio quick menus, and adaptable UI scale slider.282 4. Suppression of touch-only and mobile-specific dialogs on TV.283- **Acceptance Criteria**:284 - Yokan can be installed and launched from Android TV / Google TV home screens.285 - Complete navigation of library, browse, and anime playback is possible using only a hardware D-pad remote without touch or mouse emulation.286287#### Phase P3: Advanced Ecosystem & Media Features (Target: Weeks 10–13)288- **Deliverables**:289 1. AniList franchise relations graph traversal for automated anime watch-order reconstruction.290 2. Tracker account profiles (avatar, username, expiry) in tracker settings.291 3. Persistent update errors screen with 1-tap migration action; per-source saved searches.292 4. Aidoku WASM extension runtime prototype executing `.aidx` packages.293- **Acceptance Criteria**:294 - Failed library updates accumulate in a triage screen allowing single or bulk migration.295 - Complex franchise watch orders (e.g. *Monogatari*, *Fate*) match AniList canonical relations.296297---298299## 6. Capability-Gate Checklist300301Before any PR claiming Mangayomi parity is merged, it must pass the following verifiable criteria:302303- [ ] **Backup**: Encrypted `.yokanbk` archives decrypt accurately with the correct password and reject incorrect passwords with an explicit auth error before writing to SQLite.304- [ ] **Rollback**: Simulating an out-of-disk error at 50% restore reverts the database to its exact pre-restore snapshot.305- [ ] **Downloader**: Starting 5 concurrent downloads from Source A results in exactly 1 active HTTP connection to Source A at any given millisecond.306- [ ] **Stall Watchdog**: An uncompleted HTTP socket stream aborted by network disconnect terminates within 30 seconds and transitions to `DownloadState.Failed(retryable = true)`.307- [ ] **Version Comparator**: Test suite confirms `1.0.0-beta.1 < 1.0.0`, `1.4b < 1.4.0`, `2.1.0 > 2.0.9`, and `1.0.0+1 == 1.0.0`.308- [ ] **Android TV**: Tested on Android TV emulator (API 34) with D-pad navigation; no touch interactions required; no crashes on text inputs.309- [ ] **Cache Keys**: Disk cache files use `SHA256(sourceId + "/" + mangaId + "/" + chapterId + "/" + pageUrl)` to avoid namespace collisions.310- [ ] **Cloudflare Proxy**: Desktop JVM correctly consumes FlareSolverr session cookies when anti-bot challenge is triggered.311312---313314## 7. What Not to Copy from Upstream3153161. **Do not introduce Riverpod or Flutter reactive patterns**: Retain standard Compose state models (`StateFlow`, `collectAsStateWithLifecycle`, MVI viewmodels).3172. **Do not use non-transactional database writes**: Mangayomi had to build a custom `DbWriteQueue` (`1908e11a`) and resolve nested transaction panics in Isar (`26b11440`). Yokan uses Room KMP, which natively provides robust SQLite transactions (`withTransaction`); always use Room's transactional primitives.3183. **Do not drop desktop and iOS compatibility for Android TV**: Android TV features must remain gated behind platform capability checks (`isTvMode`) in `androidMain` or shared conditional modifiers. Never leak Android Leanback classes into `commonMain`.3194. **Do not abandon anime and novel first-class status**: Mangayomi's recent TV features heavily favored anime over manga. Yokan must maintain its balanced three-media paradigm (Manga, Anime, Novels) across mobile, desktop, and TV form factors.320321---322323## 8. Measurable Completion Gates324325- [ ] `MANGAYOMI_DIFF.md` adopted as the authoritative roadmap for upstream parity.326- [ ] Automated test suite verifies `SemVerComparatorTest` covering all Mangayomi edge-case fixtures (`ed4f411b`).327- [ ] Automated test suite verifies `BackupEncryptionTest` (AES-256-GCM round-trip with wrong password rejection).328- [ ] Automated test suite verifies `DownloadSourceSerializationTest` ensuring single-flight requests per source host.329- [ ] Android TV build flavor or unified APK tested and verified on physical Android TV / Google TV hardware.330- [ ] Chapter gap detection test verifies missing chapter counts across integer, decimal, and special chapter sets.331