Modern-Apps.git
Publicgit clone https://git.maproj.org/Modern-Apps.gitModern-Apps.git / news / AGENTS.md
| 1 | # AGENTS.md — news/ (':news') |
| 2 | |
| 3 | > Scoped supplement. Global rules in root `AGENTS.md` apply. Stay inside `news/` + allowed shared modules. Do not root-scan. |
| 4 | |
| 5 | _Install: ./install news_ |
| 6 | - Gradle: :news / dir: news/ |
| 7 | - Package roots present: ui, data, domain, platform, network, intents |
| 8 | - Entry files: MainActivity.kt, Route.kt, Navigation.kt |
| 9 | - Deps: :library:network, :library:room, :library:image |
| 10 | - Metadata: metadata_data/news.md (present) |
| 11 | - Rust: no / screenshotTest: yes (phone + large-tablet) |
| 12 | |
| 13 | ## Overview |
| 14 | **Purpose:** News reader. Primary feed is our server's merged |
| 15 | `news.json` snapshot, distributed only as its static copy on R2 |
| 16 | (`https://static.maproj.org/news/v1/news.json`, republished by the |
| 17 | server's background refresh on every cycle; there is no news endpoint |
| 18 | on the origin — see `domain/ServerFeedParser` for the contract + |
| 19 | assumptions). When the static copy is missing, failing, or older |
| 20 | than 1 hour, refresh falls back to the on-device crawl below; the |
| 21 | result is merged into Room. A refresh whose downloaded `generated_at` |
| 22 | matches the last-merged stamp persisted by `NewsPrefs` skips parsing |
| 23 | and the Room re-publish entirely — the cached feed already shows |
| 24 | exactly those articles — and a batch identical to the cache writes |
| 25 | nothing. Catalog lookups (`SourceCatalog.byId`/`byName`) are indexed |
| 26 | maps built once at first use, not scans over the whole catalog, and |
| 27 | story grouping over the Room cache runs off the main thread. Every source is always in the |
| 28 | corpus (no per-source toggle); category + search are the filters, and |
| 29 | `domain/FeedRanking` orders the story feed client-side by descending |
| 30 | source count, then newest first (search keeps its relevance order). |
| 31 | The server feed enters Room through `domain/StoryFeedCap` at the |
| 32 | feed's full 2,500 size (whole stories in feed-rank order, newest |
| 33 | fill) — never a flat newest-first cap, which cut popular stories' |
| 34 | older members; the on-device crawl keeps its 500-article cache cap. |
| 35 | Science/Technology filing uses the source tag OR the server's |
| 36 | headline `topics` classification (`FeedArticle.topics`, Room v3); |
| 37 | geographic tabs (World/US) follow the story representative's |
| 38 | source, while Local keeps any-member region matching. |
| 39 | Every feed item is a story (`domain/Story`, mechanical grouping by |
| 40 | exact server `storyId` only — singletons included), shown as a card |
| 41 | labelled only with its source count ("1 source" / "N sources", no |
| 42 | lead-source name) and opening the story view. If the static feed fetch fails/times out/parses empty, refresh |
| 43 | falls back to the on-device per-source sitemap/RSS crawl of all sources |
| 44 | (cached feed stays visible either way). Article reading is always on-device: |
| 45 | publisher HTML is fetched directly and extracted locally. No account. |
| 46 | On-device search (feed screen) runs over the local corpus only — titles, |
| 47 | source names, sitemap keywords, downloaded bodies (`domain/NewsSearch`). |
| 48 | **Key features:** |
| 49 | - Built-in source catalog (`domain/SourceCatalog`) — Google News sitemaps |
| 50 | where a verified one exists, RSS only where no sitemap verifies (NPR, DW, |
| 51 | Ars, The Verge, Hacker News). The catalog is a bundled data asset: |
| 52 | `domain/SourceCatalog` loads `/source_catalog.tsv.br` from the |
| 53 | classpath (Brotli-compressed TSV, generated by |
| 54 | `scripts/generate_source_catalog.py` from the readable source of truth |
| 55 | `catalog/source_catalog.tsv`). Edit the TSV data and regenerate the |
| 56 | asset; do not add sources as code. New sources are proposed only by |
| 57 | `scripts/harvest_sources.py` (OPML directories + Wikidata newspaper / |
| 58 | magazine / news-site official sites; `--selftest` runs its offline |
| 59 | fixtures), which emits a row only after the feed fetches 200 and |
| 60 | parses and one sampled article's raw HTML carries a full body — the |
| 61 | verification bar below. Re-running it against the current TSV |
| 62 | reproduces the dedupe (one feed per domain, normalised feed URL) and |
| 63 | the rejection report; appending its verified rows and regenerating |
| 64 | is the whole scale-up procedure. A missing or corrupt asset loads |
| 65 | as an empty catalog (server feed and cached articles keep working; a |
| 66 | malformed row drops only that source). |
| 67 | - Local category (`domain/LocalNews`, `SourceCatalog.matchesFeedFilter`): |
| 68 | the Local chip is a filter to the user's manually set location |
| 69 | (Settings → `Route.LocalLocation`, persisted by `NewsPrefs`; never |
| 70 | device location), not the catalog's whole Local bucket. A source |
| 71 | passes only when its catalog `region` matches the set location |
| 72 | component-wise with the trailing country in agreement (a city pick |
| 73 | also passes statewide outlets of its state, and vice versa). With no |
| 74 | location set, or no matching downloaded source, Local is empty with |
| 75 | an honest feed message — national/world/other-local news is never |
| 76 | substituted. Search within Local applies the same filter. Catalog |
| 77 | `region` is present on every Local-tagged source and on no other |
| 78 | source; non-US outlets harvested under a same-named US state (e.g. |
| 79 | `.ge` Georgia-country feeds) are World, not Local. |
| 80 | - Room-cached feed + extracted article bodies (offline reading), bookmarks |
| 81 | - Readability-style extraction in `domain/ArticleExtractor` over a small |
| 82 | tolerant HTML DOM (`domain/HtmlDom`); reader with text size, serif/sans |
| 83 | (extracted-text only — no original-page WebView or open-in-browser) |
| 84 | |
| 85 | ## Source verification |
| 86 | A source counts as verified when its sitemap/RSS fetches 200 and parses |
| 87 | and one article's raw HTML contains the full body (paragraph text |
| 88 | measured, tail checked): |
| 89 | - BBC `bbc.com/sitemaps/https-sitemap-com-news-1.xml` — full (no paywall) |
| 90 | - The Guardian `theguardian.com/sitemaps/news.xml` — sitemap verified; |
| 91 | article pages returned 403 to the datacentre verification IP (no |
| 92 | paywall exists), badged in the catalog |
| 93 | - Al Jazeera `aljazeera.com/news-sitemap.xml` — full |
| 94 | - TechCrunch `techcrunch.com/news-sitemap.xml` — full |
| 95 | - ProPublica `propublica.org/news-sitemap.xml` (index → daily urlsets) — full |
| 96 | - El País `elpais.com/sitemaps/news.xml` — full text present in raw HTML |
| 97 | despite meter markers; badged as metered |
| 98 | - NPR (RSS), DW (RSS), Ars Technica (RSS), The Verge (RSS), |
| 99 | Hacker News (RSS) — full article HTML verified on linked articles |
| 100 | Excluded sources (body absent from raw HTML or fetch blocked): |
| 101 | Reuters (401), AP (403), NYT (bot wall + server-side paywall), WSJ/WaPo |
| 102 | (403), Axios (JS-only shell, no body in HTML), France 24 (403), |
| 103 | Japan Times (sitemap URL serves HTML, not XML). |
| 104 | |
| 105 | ## Architecture / data-flow |
| 106 | `ui/` feed/reader/saved → `platform/NewsViewModel` → |
| 107 | `data/NewsRepository` (Room via `library/room`) + `data/NewsPrefs` |
| 108 | (DataStore owner) → `network/Networking` (the single networking entry |
| 109 | point, `NetworkClient` with `TrustBundle.SYSTEM` — publisher hosts are |
| 110 | arbitrary, so no reduced bundle can cover them; SYSTEM also covers |
| 111 | static.maproj.org, whereas FIRST_PARTY would break |
| 112 | publisher fetches; the server feed goes through |
| 113 | `Networking.fetchServerFeedText` → `StaticMirror.getStatic`, R2 only, |
| 114 | no origin fallback) → `domain/` parsers and extractor (pure, no Android |
| 115 | imports). |
| 116 | |
| 117 | ## Entry points + reading order |
| 118 | `Route` (`Feed` / `Reader(url)` / `Saved`) → `MainActivity.kt` |
| 119 | → `Navigation.kt` → `platform/NewsViewModel.kt` → `data/NewsRepository.kt` |
| 120 | → `domain/SitemapParser.kt` + `domain/ArticleExtractor.kt`. |
| 121 | |
| 122 | ## Gotchas |
| 123 | - Backup: the Room DB is a re-derivable feed/body cache and is excluded |
| 124 | from platform backup (`data_extraction_rules.xml` allowlists only |
| 125 | `datastore/news.preferences_pb`); the server-feed stamp lives in the |
| 126 | separate non-backed-up `news_feed_cache` DataStore so a restored stamp |
| 127 | cannot suppress the first merge into an empty DB. |
| 128 | - Selection is navigation: the article URL lives in `Route.Reader`, never |
| 129 | in ViewModel state that swaps list→detail. |
| 130 | - A failing source never fails a refresh; the cached feed stays visible. |
| 131 | - Extraction quality is judged by `ExtractedArticle.bodyChars`; truncated |
| 132 | extractions usually mean the source changed its markup or paywall. |
| 133 | |
| 134 | ## Screenshot coverage |
| 135 | Every `Route` leaf (`Feed`/`Story`/`Reader`/`Saved`/`LocalLocation`/`Settings`) has a capture in `src/screenshotTest` named `<n>-<route-key>`; the fatal `RouteScreenshotCoverage` lint enforces it (no exemptions here). News has no dialogs — dialog UI, if added, must be a `Route` destination with `DialogPage()` metadata, not state in a screen. Convention: `docs/screenshot-coverage.md`. |
| 136 | |
| 137 | ## Verify (this module only) |
| 138 | ``` |
| 139 | ./gradlew :news:compileDevKotlin |
| 140 | ./gradlew :news:testDevUnitTest |
| 141 | ./gradlew :news:lint |
| 142 | ``` |