Modern Apps git
git clone https://git.maproj.org/Modern-Apps.git
translate ▾

Modern-Apps.git / news / AGENTS.md

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