From 0ab7e7ef1d0d3b521787d3f6e43109d32bbc55eb Mon Sep 17 00:00:00 2001 From: Nelson Baptista Date: Thu, 7 May 2026 06:12:33 +0000 Subject: [PATCH] feat(config): align sources example, env docs, and secrets precedence notes - Add config/sources.example.json for new installs; document in ops README - Extend .env.example with WP_CATEGORY, QUEUE_MAX_DEPTH, and optional analytics/pipeline/writing-style vars - Fix secrets.js merge-order comment to match implementation - Validate sources.domain_filter_mode (strict|warn|log) at startup - Fix status-server test cleanup var HTTP_BODY_READ_TIMEOUT_MS - Replace nonexistent OPENAI_TIMEOUT_MS hint in incident runbook Paperclip-Agent: David Santos (id 0b1fcf92-5fe3-4ac0-9f29-df4ab72f5376) Paperclip-Issue: BIT-4294 Paperclip-Run: bc46f5b4-65d4-462a-8b56-e991c4aca0c1 --- .env.example | 28 ++++++++++++++++++++++++++++ config/sources.example.json | 19 +++++++++++++++++++ docs/runbooks/INCIDENT_RESPONSE.md | 2 +- docs/runbooks/README.md | 4 ++-- src/config/secrets.js | 9 ++++----- src/config/validator.js | 9 +++++++++ src/config/validator.test.js | 23 ++++++++++++++++++++++- src/http/status-server.test.js | 2 +- 8 files changed, 86 insertions(+), 10 deletions(-) create mode 100644 config/sources.example.json diff --git a/.env.example b/.env.example index c6435bd..03d1fee 100644 --- a/.env.example +++ b/.env.example @@ -13,6 +13,8 @@ ANTHROPIC_API_KEY= WP_URL=https://wp.newsproject.bitreport.pt WP_USER= WP_PASSWORD= +# Default category ID when using env-only site config (no config/sites/*.json) +WP_CATEGORY=1 # rest (default) | xmlrpc — per-site override: wp_transport in config/sites/*.json WP_TRANSPORT=rest @@ -71,6 +73,32 @@ ARTICLE_LOG_TRIM_AT_BYTES=2097152 # Optional: only publish to WordPress as "publish" during these local hours [start, end) in CRON_TIMEZONE; outside → draft. # PUBLISH_HOURS=8-20 +# Pipeline — max articles processed concurrently in listen/auto (memory + API pressure) +QUEUE_MAX_DEPTH=5 + +# Optional: persist RSS GUID dedupe store elsewhere (default: under data/) +# GUID_STORE_PATH= + +# Monitoring — optional webhook when pipeline stages fail (Slack-compatible JSON) +# PIPELINE_ALERT_WEBHOOK_URL= +# PIPELINE_ALERT_WEBHOOK_TIMEOUT_MS=4000 + +# Writing style — optional overrides (defaults come from config/writing-style.example.json) +# WRITING_STYLE_CONFIG_PATH= +# WRITING_TONE= +# AUDIENCE_LEVEL= + +# Analytics DB (optional — module loads only when used) +# ANALYTICS_DB_HOST=localhost +# ANALYTICS_DB_PORT=5432 +# ANALYTICS_DB_NAME=ai_news_analytics +# ANALYTICS_DB_USER=postgres +# ANALYTICS_DB_PASSWORD= +# ANALYTICS_DB_POOL_SIZE=10 +# ANALYTICS_ENGAGEMENT_RETENTION_DAYS= +# ANALYTICS_DAILY_METRICS_RETENTION_DAYS= +# ANALYTICS_BENCHMARKS_RETENTION_DAYS= + # Quality Scoring (article validation and metrics) # Minimum quality score for auto-approval (0-100, higher = stricter) QUALITY_MIN_SCORE=60 diff --git a/config/sources.example.json b/config/sources.example.json new file mode 100644 index 0000000..eed0ac9 --- /dev/null +++ b/config/sources.example.json @@ -0,0 +1,19 @@ +{ + "rss": [ + { + "name": "Example — BBC Technology", + "url": "https://feeds.bbci.co.uk/news/technology/rss.xml", + "category": "technology", + "lang": "en" + }, + { + "name": "Example — Guardian World", + "url": "https://www.theguardian.com/world/rss", + "category": "general", + "lang": "en" + } + ], + "keywords": ["example", "keyword-one", "keyword-two"], + "trusted_domains": ["bbc.co.uk", "theguardian.com"], + "domain_filter_mode": "strict" +} diff --git a/docs/runbooks/INCIDENT_RESPONSE.md b/docs/runbooks/INCIDENT_RESPONSE.md index 24fd7d8..acdddc5 100644 --- a/docs/runbooks/INCIDENT_RESPONSE.md +++ b/docs/runbooks/INCIDENT_RESPONSE.md @@ -244,7 +244,7 @@ pm2 logs ai-news-writer --grep "openai\|429\|timeout" --lines 50 # - Contact OpenAI for higher rate limit # If timeout: -# - Increase timeout in .env: OPENAI_TIMEOUT_MS +# - Increase backoff in .env: OPENAI_RETRY_BASE_MS (and optionally OPENAI_MAX_ATTEMPTS) # - Reduce prompt complexity ``` diff --git a/docs/runbooks/README.md b/docs/runbooks/README.md index 9be9ca1..1b68265 100644 --- a/docs/runbooks/README.md +++ b/docs/runbooks/README.md @@ -49,8 +49,8 @@ npm run wp:test | File | Purpose | |------|---------| -| `.env` | Secrets (OpenAI key, WP credentials, admin token) — never commit | -| `config/sources.json` | RSS feed URLs | +| `.env` | Secrets (OpenAI key, WP credentials, admin token) — never commit; see root `.env.example` | +| `config/sources.json` | RSS feed URLs (copy from `config/sources.example.json` for new installs) | | `config/social.json` | X / Twitter queries | | `config/sites/` | WordPress targets | | `ecosystem.config.cjs` | PM2 app definition | diff --git a/src/config/secrets.js b/src/config/secrets.js index a2c240d..4d8e66e 100644 --- a/src/config/secrets.js +++ b/src/config/secrets.js @@ -7,11 +7,10 @@ const audit = require('../logger/audit'); /** * Centralized secrets management — single source of truth for all sensitive data. * - * Load priority (highest to lowest): - * 1. /etc/ai-news-writer/secrets.env (injected by Gitea Actions / deployment tooling) - * 2. .env (local development) - * 3. process.env (already in environment, e.g., from PM2 env config) - * 4. Defaults (where safe to provide) + * Merge order (later assignments win — same key from a later source overrides earlier): + * 1. process.env (baseline: shell, PM2, CI, etc.) + * 2. /etc/ai-news-writer/secrets.env (production inject) + * 3. repo .env (local development; overrides system file when both exist) * * Usage: * const secrets = require('./config/secrets'); diff --git a/src/config/validator.js b/src/config/validator.js index 3215f8d..e236f84 100644 --- a/src/config/validator.js +++ b/src/config/validator.js @@ -104,6 +104,15 @@ function validateSources(sourcesConfig) { warnings.push('sources.trusted_domains: not configured'); } + if (sourcesConfig.domain_filter_mode !== undefined && sourcesConfig.domain_filter_mode !== null) { + const mode = sourcesConfig.domain_filter_mode; + if (typeof mode !== 'string' || !['strict', 'warn', 'log'].includes(mode)) { + errors.push( + `sources.domain_filter_mode: must be strict|warn|log (got ${typeof mode === 'string' ? JSON.stringify(mode) : typeof mode})` + ); + } + } + return { valid: errors.length === 0, errors, diff --git a/src/config/validator.test.js b/src/config/validator.test.js index 3ec5c8a..be04459 100644 --- a/src/config/validator.test.js +++ b/src/config/validator.test.js @@ -15,7 +15,8 @@ test('validateSources — valid config', () => { } ], keywords: ['football', 'basketball'], - trusted_domains: ['bbc.co.uk'] + trusted_domains: ['bbc.co.uk'], + domain_filter_mode: 'warn' }; const result = validateSources(config); @@ -23,6 +24,26 @@ test('validateSources — valid config', () => { assert.equal(result.errors.length, 0); }); +test('validateSources — invalid domain_filter_mode', () => { + const config = { + rss: [ + { + name: 'BBC Sport', + url: 'https://feeds.bbci.co.uk/sport/rss.xml', + category: 'sports', + lang: 'en' + } + ], + keywords: ['football'], + trusted_domains: ['bbc.co.uk'], + domain_filter_mode: 'relaxed' + }; + + const result = validateSources(config); + assert.equal(result.valid, false); + assert(result.errors.some((e) => e.includes('domain_filter_mode'))); +}); + test('validateSources — missing rss field', () => { const config = { keywords: ['football'], diff --git a/src/http/status-server.test.js b/src/http/status-server.test.js index 11e62aa..5f29692 100644 --- a/src/http/status-server.test.js +++ b/src/http/status-server.test.js @@ -69,7 +69,7 @@ describe('status-server', () => { delete process.env.OPENAI_API_KEY; delete process.env.AI_MODEL; delete process.env.CRON_TIMEZONE; - delete process.env.BODY_READ_TIMEOUT_MS; + delete process.env.HTTP_BODY_READ_TIMEOUT_MS; }); it('returns object with feature flags', () => {