Add Record and SAPO RSS, Guardian world and BBC handball; cap noisy RSS via maxItems. Document Lusa/wire and ToS notes in AGGREGATOR_OPERATIONS. Paperclip-Agent: José Alves (urlKey jos-alves; id 11179220-3cec-4f0f-880d-2771ff64fce8) Paperclip-Issue: BIT-741 Paperclip-Run: ce6e2b51-1a3f-46f5-b479-2500427a0327 Made-with: Cursor
4.7 KiB
Internal news aggregator — operations & costs (BIT-709)
This runbook covers the self-hosted multi-source aggregator in writer-pipeline/ and how the bridge uses it for writer candidates.
Components
| Piece | Role |
|---|---|
| JSON store | writer-pipeline/var/aggregated-items.json (default path; override with AGGREGATOR_STORE_PATH) |
| Ingest config | writer-pipeline/config/{site}.sources.json (e.g. andebol.net.sources.json) |
| HTTP API | Fastify server (npm run aggregator → dist/aggregator-server.js) |
| Bridge integration | Set AGGREGATOR_URL (e.g. http://127.0.0.1:3310) so /writers/:id/candidates queries the aggregator before merging WordPress posts |
HTTP API (aggregator process)
| Method | Path | Purpose |
|---|---|---|
| GET | /health |
Liveness + resolved storePath |
| GET | /search?site=&limit=&q=&topic=&max_age_hours= |
Searchable listing: tokenized q matches title+summary; deduped store keyed by canonical URL at ingest |
| GET | /shortlist?site=&limit=&topic= |
Newest eligible items (no draft/skip) for one site |
| GET | /stats |
Total items, counts by site and by site:sourceFeedId |
| POST | /ingest?site= |
Run ingest for that site’s sources config and persist the store |
Environment:
AGGREGATOR_HOST(default127.0.0.1),AGGREGATOR_PORT(default3310)AGGREGATOR_CONFIG_DIR— directory of*.sources.jsonAGGREGATOR_STORE_PATH— JSON backing file
Bridge
AGGREGATOR_URL: base URL of the aggregator (no trailing slash required). If unset, candidates come only from WordPress (previous behaviour).GET /writers/:agentId/candidates: loads aggregated items forconfig.domain, maps them to the same candidate shape as WordPress rows, addssource_urlfor external URLs, then merges WordPress posts and ranks. Response includescandidate_source:aggregator|wordpress|mixed.GET /writers/:agentId/stats: when the aggregator is enabled, also callsGET /statsand returnsaggregator_total_itemsandaggregator_site_itemswhen available.
Data contract (per item)
Each aggregated item includes source (sourceFeedId, optional sourceKind), timestamps (publishedAt, ingestedAt), technical summary (summary + title), and original URL (url). Deduplication at ingest uses canonical URL → stable id (store.itemId).
Sources, copyright, and wire services (Lusa)
- Operational config:
writer-pipeline/config/andebol.net.sources.json. RSS feeds may setmaxItemsto limit how many recent entries are ingested per run (large highlight feeds such as SAPO). - Agência Lusa: a direct, machine-readable public Lusa wire feed suitable for unattended ingestion is not used here — public endpoints are often HTML/portal pages or require a commercial licence and contractual terms. Syndicated PT feeds (e.g. SAPO highlights) may credit Lusa or other agencies in bylines; that does not replace checking rights for republication. Editors must follow
docs/ANDEBOL_EDITORIAL_BRIEF.md(original rewrite, attribution, no verbatim copy). - Third-party RSS (Record, Guardian, BBC, etc.): use only as story leads; comply with each site’s terms of use and robots/API policy; English items are for triage only — andebol.net publishes European Portuguese (PT-PT) only.
Cost model (read-phase, LLM)
Structured read context for one item is built in writer-pipeline/src/token-metrics.ts (aggregatorReadContext). Reference input pricing used in metrics: USD 0.15 / 1M tokens (REF_INPUT_USD_PER_1M) — adjust when the production model changes.
Typical savings vs full-page fetch for the same shortlist are documented in docs/WRITER_PIPELINE_ANDEBOL.md (example ratio ~9× fewer tokens on the read path).
Suggested scheduling (self-hosted)
- Ingest —
POST /ingest?site=andebol.neton a timer (e.g. every 6–12 hours per feed stability), or runnode dist/run-cycle.jswhere you already use the pipeline. - Aggregator process —
systemdor PM2 keepingnpm run aggregatorup on the same host (or container) as the bridge; bridge reaches it via loopback or private network. - Bridge — ensure
AGGREGATOR_URLis set in the bridge environment alongside Redis/WordPress settings.
Verification
cd writer-pipeline && npm run build && npm test
cd ../bridge && npm run build
# With aggregator running:
curl -sS "http://127.0.0.1:3310/search?site=andebol.net&limit=5"
Related docs
docs/AGGREGATOR_ARCHITECTURE.md— long-term schema and phased plandocs/WRITER_PIPELINE_ANDEBOL.md— pipeline commands and metricsdocs/writer-tools.md— bridge writer API