AGENTS.md — news/ (':news')
Scoped supplement. Global rules in root AGENTS.md apply. Stay inside news/ + allowed shared modules. Do not root-scan.
Install: ./install news
- Gradle: :news / dir: news/
- Package roots present: ui, data, domain, platform, network, intents
- Entry files: MainActivity.kt, Route.kt, Navigation.kt
- Deps: :library:network, :library:room, :library:image
- Metadata: metadata_data/news.md (present)
- Rust: no / screenshotTest: yes (phone + large-tablet)
Overview
Purpose: News reader. Primary feed is our server's merged news.json snapshot, distributed only as its static copy on R2 (https://static.maproj.org/news/v1/news.json, republished by the server's background refresh on every cycle; there is no news endpoint on the origin — see domain/ServerFeedParser for the contract + assumptions). When the static copy is missing, failing, or older than 1 hour, refresh falls back to the on-device crawl below; the result is merged into Room. A refresh whose downloaded generated_at matches the last-merged stamp persisted by NewsPrefs skips parsing and the Room re-publish entirely — the cached feed already shows exactly those articles — and a batch identical to the cache writes nothing. Catalog lookups (SourceCatalog.byId/byName) are indexed maps built once at first use, not scans over the whole catalog, and story grouping over the Room cache runs off the main thread. Every source is always in the corpus (no per-source toggle); category + search are the filters, and domain/FeedRanking orders the story feed client-side by descending source count, then newest first (search keeps its relevance order). The server feed enters Room through domain/StoryFeedCap at the feed's full 2,500 size (whole stories in feed-rank order, newest fill) — never a flat newest-first cap, which cut popular stories' older members; the on-device crawl keeps its 500-article cache cap. Science/Technology filing uses the source tag OR the server's headline topics classification (FeedArticle.topics, Room v3); geographic tabs (World/US) follow the story representative's source, while Local keeps any-member region matching. Every feed item is a story (domain/Story, mechanical grouping by exact server storyId only — singletons included), shown as a card labelled only with its source count ("1 source" / "N sources", no lead-source name) and opening the story view. If the static feed fetch fails/times out/parses empty, refresh falls back to the on-device per-source sitemap/RSS crawl of all sources (cached feed stays visible either way). Article reading is always on-device: publisher HTML is fetched directly and extracted locally. No account. On-device search (feed screen) runs over the local corpus only — titles, source names, sitemap keywords, downloaded bodies (domain/NewsSearch). Key features:
- Built-in source catalog (
domain/SourceCatalog) — Google News sitemaps
where a verified one exists, RSS only where no sitemap verifies (NPR, DW, Ars, The Verge, Hacker News). The catalog is a bundled data asset: domain/SourceCatalog loads /source_catalog.tsv.br from the classpath (Brotli-compressed TSV, generated by scripts/generate_source_catalog.py from the readable source of truth catalog/source_catalog.tsv). Edit the TSV data and regenerate the asset; do not add sources as code. New sources are proposed only by scripts/harvest_sources.py (OPML directories + Wikidata newspaper / magazine / news-site official sites; --selftest runs its offline fixtures), which emits a row only after the feed fetches 200 and parses and one sampled article's raw HTML carries a full body — the verification bar below. Re-running it against the current TSV reproduces the dedupe (one feed per domain, normalised feed URL) and the rejection report; appending its verified rows and regenerating is the whole scale-up procedure. A missing or corrupt asset loads as an empty catalog (server feed and cached articles keep working; a malformed row drops only that source).
- Local category (
domain/LocalNews,SourceCatalog.matchesFeedFilter):
the Local chip is a filter to the user's manually set location (Settings → Route.LocalLocation, persisted by NewsPrefs; never device location), not the catalog's whole Local bucket. A source passes only when its catalog region matches the set location component-wise with the trailing country in agreement (a city pick also passes statewide outlets of its state, and vice versa). With no location set, or no matching downloaded source, Local is empty with an honest feed message — national/world/other-local news is never substituted. Search within Local applies the same filter. Catalog region is present on every Local-tagged source and on no other source; non-US outlets harvested under a same-named US state (e.g. .ge Georgia-country feeds) are World, not Local.
- Room-cached feed + extracted article bodies (offline reading), bookmarks
- Readability-style extraction in
domain/ArticleExtractorover a small
tolerant HTML DOM (domain/HtmlDom); reader with text size, serif/sans (extracted-text only — no original-page WebView or open-in-browser)
Source verification
A source counts as verified when its sitemap/RSS fetches 200 and parses and one article's raw HTML contains the full body (paragraph text measured, tail checked):
- BBC
bbc.com/sitemaps/https-sitemap-com-news-1.xml— full (no paywall) - The Guardian
theguardian.com/sitemaps/news.xml— sitemap verified;
article pages returned 403 to the datacentre verification IP (no paywall exists), badged in the catalog
- Al Jazeera
aljazeera.com/news-sitemap.xml— full - TechCrunch
techcrunch.com/news-sitemap.xml— full - ProPublica
propublica.org/news-sitemap.xml(index → daily urlsets) — full - El País
elpais.com/sitemaps/news.xml— full text present in raw HTML
despite meter markers; badged as metered
- NPR (RSS), DW (RSS), Ars Technica (RSS), The Verge (RSS),
Hacker News (RSS) — full article HTML verified on linked articles Excluded sources (body absent from raw HTML or fetch blocked): Reuters (401), AP (403), NYT (bot wall + server-side paywall), WSJ/WaPo (403), Axios (JS-only shell, no body in HTML), France 24 (403), Japan Times (sitemap URL serves HTML, not XML).
Architecture / data-flow
ui/ feed/reader/saved → platform/NewsViewModel → data/NewsRepository (Room via library/room) + data/NewsPrefs (DataStore owner) → network/Networking (the single networking entry point, NetworkClient with TrustBundle.SYSTEM — publisher hosts are arbitrary, so no reduced bundle can cover them; SYSTEM also covers static.maproj.org, whereas FIRST_PARTY would break publisher fetches; the server feed goes through Networking.fetchServerFeedText → StaticMirror.getStatic, R2 only, no origin fallback) → domain/ parsers and extractor (pure, no Android imports).
Entry points + reading order
Route (Feed / Reader(url) / Saved) → MainActivity.kt → Navigation.kt → platform/NewsViewModel.kt → data/NewsRepository.kt → domain/SitemapParser.kt + domain/ArticleExtractor.kt.
Gotchas
- Backup: the Room DB is a re-derivable feed/body cache and is excluded
from platform backup (data_extraction_rules.xml allowlists only datastore/news.preferences_pb); the server-feed stamp lives in the separate non-backed-up news_feed_cache DataStore so a restored stamp cannot suppress the first merge into an empty DB.
- Selection is navigation: the article URL lives in
Route.Reader, never
in ViewModel state that swaps list→detail.
- A failing source never fails a refresh; the cached feed stays visible.
- Extraction quality is judged by
ExtractedArticle.bodyChars; truncated
extractions usually mean the source changed its markup or paywall.
Screenshot coverage
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.
Verify (this module only)
./gradlew :news:compileDevKotlin
./gradlew :news:testDevUnitTest
./gradlew :news:lint