252 Commits
Author SHA1 Message Date
Planner 67563bb6d0 feat: Phase 1 — Add test coverage, linting, and code quality tooling (c8, ESLint, Prettier)
Node tests / test (push) Has been cancelled
## Summary
- Install c8 (coverage), ESLint, and Prettier as devDependencies
- Add .eslintrc.json with Node.js/async-safe rules
- Add .prettierrc.json for code formatting consistency
- Add .nycrc.json with 80% coverage targets for statements/lines/functions, 75% for branches
- Update npm test script to use c8 for coverage reporting (generates HTML + text reports)
- Add lint, lint:fix, and format npm scripts

## Baseline Coverage
Initial run shows 26.4% line coverage, well below 80% target. Modules with 0% coverage:
- src/index.js (main entry point)
- src/crawler/* (RSS, scraper, X/Twitter crawlers)
- src/publisher/wordpress.js (WordPress integration)
- src/listener/* (RSS listener)
- src/writer/ai.js (AI news writing)

These are high-risk modules that need test expansion per BIT-2861.

Implements BIT-2837 Phase 1 per plan.
Paperclip-Run-Id: fb08becb-e019-4cb3-ae50-fb72a4b11745
2026-04-12 11:06:28 +00:00
Paperclip 3727e11129 feat(ui): editorial status and approve/reject actions on /ui
Node tests / test (push) Has been cancelled
- Persist editorial_status on new article log rows; add updateArticleStatus() with atomic rewrite
- Dashboard: badges, flash from ?flash=, POST /ui/articles/:id/approve|reject (ADMIN_TOKEN)
- Tests for article log; README documents endpoints and proxy note

Paperclip-Run: 5aeedb07-8f14-40bb-b737-79354c25d4c1
Paperclip-Task: ca360b61-1e05-47bc-ad3c-b1d78ce7d104
2026-04-09 21:55:32 +00:00
Paperclip 492918d861 feat: add PUBLISH_HOURS editorial window for WordPress status
Node tests / test (push) Has been cancelled
Parse PUBLISH_HOURS in the config loader, resolve post status against
CRON_TIMEZONE and the half-open hour window, and thread the result through
REST and XML-RPC publish paths. Expose publish_hours fields on GET /health,
document env vars, and add unit tests.

Paperclip-Agent: Miguel Teixeira (urlKey miguel-teixeira; id 0f722e1a-bc3e-4381-8d98-76fa3c7aea10)
Paperclip-Issue: BIT-1940
Paperclip-Run: 04613601-88af-4aaf-8a81-770dd9ff3c91
Made-with: Cursor
2026-04-09 21:51:06 +00:00
PaperclipandPaperclip 463163d24d docs(runbooks): add docs/runbooks/README.md ops index (BIT-1923)
Creates minimal docs/runbooks/README.md with links to deploy, PM2, 502 recovery,
verification commands, and config reference — all pointing back to root README.md
sections. No content duplication.

Paperclip-Issue: BIT-1923
Paperclip-Agent: patricia-santos
Co-Authored-By: Paperclip <[email protected]>
2026-04-09 21:24:06 +00:00
David Santos 628fbd4533 feat(health): wp_publish_by_transport counts on /health and ops page
Node tests / test (push) Has been cancelled
2026-03-25 04:47:15 +00:00
David Santos 5010e34a5f feat(wp): optional XML-RPC publish (wp.newPost) and credential test
Node tests / test (push) Has been cancelled
- Add wp-http-options.js (shared retries) and wp-transport.js (rest vs xmlrpc).
- publishToWordPress / testConnection branch on wp_transport site field or WP_TRANSPORT.
- xmlrpc-client: publishArticleXmlRpc, testConnectionXmlRpc, extractScalarParam.
- UI publishers table shows transport; wp:test JSON includes wp_transport.
- Tests: wp-transport + XML-RPC publish stub.

REST remains default; link fallback uses ?p=<id> for XML-RPC posts.

Made-with: Cursor
2026-03-25 04:34:19 +00:00
David Santos 495143690f feat(wp): XML-RPC connectivity probe (system.listMethods)
Node tests / test (push) Has been cancelled
Add xmlrpc-client with serializer/parser (fast-xml-parser), local stub tests,
and npm run wp:probe-xmlrpc for each configured site wp_url. Reuses WP retry
env and exports wpRetryOpts from wordpress.js. Optional OPS_CHECK_XMLRPC=1 in
ops-check.sh after wp:test. Publish path remains REST-only; probe validates
BIT-353 XML-RPC surface for hosts that disable or restrict REST.

Made-with: Cursor
2026-03-25 04:19:15 +00:00
David Santos 3daaf43088 refactor(config): single source for AUTO_CRON default
Node tests / test (push) Has been cancelled
- config/listen-defaults: DEFAULT_AUTO_CRON + resolveAutoCronExpression()
- index.js and status-server /health use resolver (no duplicated */30 string)
- rss-listener fallback uses same default (was */15; aligned with listen mode)
- listen-defaults.test.js

Made-with: Cursor
2026-03-25 04:04:30 +00:00
David Santos 2b14db7304 feat(health): expose listen_auto_cron (AUTO_CRON)
Node tests / test (push) Has been cancelled
Same default as src/index.js listen mode (*/30 * * * *). Shown on /health,
ops landing RSS line, and verify-deploy.sh.

Made-with: Cursor
2026-03-25 03:52:52 +00:00
David Santos 0780e68279 fix(ui): 415 for non-form Content-Type on POST /ui/*
Node tests / test (push) Has been cancelled
Admin saves parse the body as URLSearchParams (x-www-form-urlencoded).
Reject application/json, multipart, etc. before collectBody; log WARN.
Add ui-form-post helper + tests; README note.

Made-with: Cursor
2026-03-25 03:41:14 +00:00
David Santos 953ea7d482 fix(ui): timeout reading POST bodies + /health field
Node tests / test (push) Has been cancelled
- body-read-timeout: parse HTTP_BODY_READ_TIMEOUT_MS (default 120s; 0 = no limit)
- collectBody: destroy socket and reject on timeout; warn log
- /health: http_body_read_timeout_ms (null when unlimited)
- verify-deploy + .env.example; unit tests for parser

Made-with: Cursor
2026-03-25 03:29:11 +00:00
David Santos 7211716e40 fix(http): reject TRACE/TRACK/CONNECT; 405 for wrong methods on ops routes
Node tests / test (push) Has been cancelled
- Block TRACE, TRACK, CONNECT before any handler (Allow: GET, HEAD, POST)
- /health and / landing: only GET/HEAD; otherwise 405 with correct Allow
- HEAD / and /dashboard supported (same as /health pattern)
- security-headers: writeMethodNotAllowed helper + unit test
- Ops HTML endpoint list updated

Made-with: Cursor
2026-03-25 03:16:25 +00:00
David Santos bd27b446a5 feat(tools): deploy-lxc.sh for git pull + npm ci + PM2 reload
Node tests / test (push) Has been cancelled
- tools/deploy-lxc.sh: ff-only pull, production npm ci, pm2 startOrReload
  ecosystem.config.cjs --update-env; optional --with-ops-check
- package.json: npm run deploy:lxc
- README: commands table + deploy section note

Made-with: Cursor
2026-03-25 03:03:09 +00:00
David Santos 7f941e3cf7 chore(pm2): auto DEPLOY_REVISION from git in ecosystem
Node tests / test (push) Has been cancelled
When DEPLOY_REVISION/GIT_REVISION are unset, ecosystem.config.cjs runs
git rev-parse --short HEAD at pm2 start so /health deploy_revision matches
the checkout. Documented in README and .env.example.

Made-with: Cursor
2026-03-25 02:50:38 +00:00
David Santos 20b94eadf9 feat(http): security headers, deploy_revision on /health
Node tests / test (push) Has been cancelled
- security-headers: mergeResponseHeaders (nosniff + referrer-policy)
- status-server + ui-handlers: all responses use merged headers
- /health: Cache-Control no-store; deploy_revision from DEPLOY_REVISION or GIT_REVISION
- verify-deploy + .env.example: document deploy revision envs
- security-headers.test.js

Made-with: Cursor
2026-03-25 02:37:54 +00:00
David Santos c29b05e6a3 feat(store): bound article JSONL growth + /health size
Node tests / test (push) Has been cancelled
- article-log: trim oldest lines when file exceeds ARTICLE_LOG_TRIM_AT_BYTES
  and line count > ARTICLE_LOG_MAX_LINES (defaults 2MiB / 10000)
- Optional ARTICLE_LOG_PATH (absolute or relative to repo root)
- getArticleLogPath(), getArticleLogHealthFields(); LOG_FILE getter kept
- /health: article_log_bytes; verify-deploy echoes it
- test: trim behaviour with temp log path

Made-with: Cursor
2026-03-25 02:24:37 +00:00
David Santos 5ef4fd9605 feat(listen): CRON_TIMEZONE (IANA) + idle HTTP close on shutdown
Node tests / test (push) Has been cancelled
- util/iana-timezone: shared Intl validation for node-cron + /health
- rss-listener: pass timezone into cron.schedule when valid; warn if invalid
- status-server: rss_cron_timezone on /health (null when unset/invalid)
- HTTP close(): closeIdleConnections() when available (Node 18+)
- verify-deploy + .env.example: document CRON_TIMEZONE
- tests: iana-timezone.test.js

Made-with: Cursor
2026-03-25 01:58:06 +00:00
David Santos ee05af933a feat(ops): process diagnostics, /health pid+node, cron option
Node tests / test (push) Has been cancelled
- runtime/process-diagnostics: log unhandledRejection; uncaughtException + exit 1
- index: install once at startup (all CLI modes)
- status-server /health: pid, node_version
- verify-deploy: print pid and node version
- rss-listener: explicit recoverMissedExecutions: false (default; documented in code)

Made-with: Cursor
2026-03-25 01:38:47 +00:00
David Santos 2b4725424b fix(rss): no-overlap cron ticks + overlap counter in /health
Node tests / test (push) Has been cancelled
Long-running auto mode (detect → write → WP) could overlap the next cron
fire and stack work. Skip overlapping runs with a warn log; expose
rss_listener_overlap_skips in listen-state for /health and verify-deploy.

Made-with: Cursor
2026-03-25 01:25:44 +00:00
David Santos 451853b03e feat(http): inbound timeouts, /health exposure, PM2 kill_timeout
Node tests / test (push) Has been cancelled
- status-server: set requestTimeout/headersTimeout (defaults 120s/125s; env
  HTTP_REQUEST_TIMEOUT_MS / HTTP_HEADERS_TIMEOUT_MS; auto-fix headers ≤ request)
- /health + verify-deploy: echo http_*_timeout_ms for ops
- ecosystem.config.cjs: kill_timeout 15s for graceful SIGTERM path
- .env.example: document timeout vars

Made-with: Cursor
2026-03-25 01:12:44 +00:00
David Santos 632c3177ce fix(listen): graceful shutdown on SIGTERM and SIGINT
Node tests / test (push) Has been cancelled
PM2 and systemd send SIGTERM on stop/restart; only handling SIGINT left
cron and HTTP listening after process exit. Consolidate shutdown: guard
re-entry, stop cron, clear rss_listener_active, close HTTP server.

Made-with: Cursor
2026-03-25 00:57:48 +00:00
David Santos 82f905d730 test(ops): listen-state unit tests; ops-check runs npm test
Node tests / test (push) Has been cancelled
Add src/runtime/listen-state.test.js (fresh module load per case).
ops-check.sh runs npm test before rss:test. verify-deploy.sh prints RSS
tick fields when present. README ops:check row updated.

Made-with: Cursor
2026-03-25 00:42:49 +00:00
David Santos d13a1706c7 feat(health): expose RSS listener last cron tick on /health
Node tests / test (push) Has been cancelled
Record each listener iteration in listen-state; JSON adds
rss_listener_last_tick_at, rss_listener_last_tick_ok,
rss_listener_last_tick_error. Ops HTML shows tick summary when listener
is active.

Made-with: Cursor
2026-03-25 00:29:01 +00:00
David Santos c87d221995 feat(x): retry recent-search via http-retry; add Gitea Actions test job
Node tests / test (push) Has been cancelled
X API v2 search uses axiosGetWithRetry (429, 502–504, transient network).
New env: X_HTTP_MAX_ATTEMPTS (default 3), X_RETRY_BASE_MS (default 1000ms).

Add .gitea/workflows/test.yml to run npm ci && npm test on push/PR.

Made-with: Cursor
2026-03-25 00:14:50 +00:00
David Santos 11350b2f3e feat(rss): use shared http-retry for feed GET; add unit tests
RSS fetch uses axiosGetWithRetry + parseString so transient policy matches
WP/scraper. New env: RSS_HTTP_MAX_ATTEMPTS, RSS_RETRY_BASE_MS.

Add http-retry policy tests; fix npm test to discover *.test.js via find.

Made-with: Cursor
2026-03-25 00:01:37 +00:00
David Santos aef941f367 refactor: centralize HTTP retry in util/http-retry
Extract shared transient-error detection and exponential backoff for
axios GET/POST. WordPress publisher and article scraper now call
axiosGetWithRetry / axiosPostWithRetry with existing env knobs unchanged.

Made-with: Cursor
2026-03-24 23:43:44 +00:00
David Santos 07880405d3 feat(scraper): retry article GET on transient HTTP/network errors
Align with WP/OpenAI: 429 and 5xx gateway, common socket errors, timeout
message. Env SCRAPER_HTTP_MAX_ATTEMPTS and SCRAPER_RETRY_BASE_MS.

Made-with: Cursor
2026-03-24 23:30:03 +00:00
David Santos 8f2ad454e9 feat(ui): simple admin pages /ui for titles, sources, social, theme
- Append generated article metadata to data/article-index.jsonl for listing
- HTML UI: /ui, /ui/sources, /ui/social, /ui/publishers, /ui/theme
- Saves require ADMIN_TOKEN; optional Bearer for future API use
- GET /api/ui/articles JSON; config/ui-theme.example.json for accents
- README and .env.example document access control expectations

Made-with: Cursor
2026-03-24 23:17:53 +00:00
David Santos 77024a71d4 feat(http): expose OpenAI config flags on /health and ops page
Add openai_api_key_configured and ai_model to JSON; show on landing HTML.

Made-with: Cursor
2026-03-24 23:10:01 +00:00
David Santos 8e239cbe3d fix(listen): keep HTTP up if RSS listener fails; document NPM 502
- loadSources/loadSocial: tolerate invalid JSON (log + safe fallback)
- runAutoMode: catch listener startup errors so the status server stays
  bound for probes and NPM debugging
- /health + ops page: rss_listener_active flag for degraded state
- README: 502 checklist (PM2, port, NPM upstream, firewall, curl from NPM)

Made-with: Cursor
2026-03-24 23:06:05 +00:00
David Santos 574e6a5ddd feat(ai): retry OpenAI chat completions on transient errors
chatCompletionWithRetry for generateArticle and detectTopics; env
OPENAI_MAX_ATTEMPTS and OPENAI_RETRY_BASE_MS.

Made-with: Cursor
2026-03-24 22:55:45 +00:00
David Santos fa0818ff7c feat(http): ops landing page at / and /dashboard for listen mode
Adds a read-only HTML page (PT) explaining where to open the service,
which endpoints exist, and that the editorial dashboard is still
out of scope. Reuses existing config probes for RSS/X/WP flags.
Documents HTTP surface in README.

Made-with: Cursor
2026-03-24 22:53:22 +00:00
David Santos 34faf38911 feat(wp): configurable retries for all REST calls
Add axiosGetWithRetry; use for tag search, tag create, and users/me.
WP_HTTP_MAX_ATTEMPTS and WP_RETRY_BASE_MS env vars (documented).
Guard tag search when response body is not an array.

Made-with: Cursor
2026-03-24 22:41:42 +00:00
David Santos ee330c8319 fix(wp): retry REST post create on transient failures
Up to 3 attempts with exponential backoff for 429, 502-504, and common
network errors before surfacing publish failure.

Made-with: Cursor
2026-03-24 22:29:30 +00:00
David Santos 63dbe77249 refactor(crawler): centralize RSS+X merge in merge-sources.js
fetchMergedSourceArticles used by manual write and rss-listener; single
log line on X aggregate failure.

Made-with: Cursor
2026-03-24 22:17:26 +00:00
David Santos c5e197d707 feat(write): merge optional X tweets into manual write sources
Align manual mode with listen: RSS + social.json recent search, sorted by
time. Skip HTTP scrape for source=x (tweet text stays in summary).

Made-with: Cursor
2026-03-24 22:05:16 +00:00
David Santos 86421a202a feat(http): extend /health with listen feature flags
Expose rss_feed_count, x_queries_configured, x_listening, and
wp_credentials_configured (no secrets, no network) for NPM/ops probes.

Made-with: Cursor
2026-03-24 21:53:42 +00:00
David Santos 560ad9716f feat(x): optional X API v2 recent search in listen mode
- config/social.example.json + loadSocialConfig; social.json gitignored.
- fetchXAsArticles merges tweets with RSS before keyword filter.
- x:test / npm run x:test probes queries + bearer token.

Made-with: Cursor
2026-03-24 21:41:35 +00:00
David Santos d31e158b84 feat(crawler): bounded RSS concurrency + env HTTP tuning
fetchAllFeeds processes feeds in chunks (RSS_FETCH_CONCURRENCY, default 3).
RSS timeout and User-Agent from env; scraper shares HTTP_USER_AGENT and
SCRAPER_TIMEOUT_MS. Document in .env.example and README.

Made-with: Cursor
2026-03-24 21:27:28 +00:00
David Santos 2ebab7e2bc docs(tools): clarify ops-check wp:test preconditions
Made-with: Cursor
2026-03-24 21:15:01 +00:00
David Santos d6b819cf28 feat(tools): add ops:check for post-clone smoke tests
Runs rss:test always; wp:test only when WP env or real site JSON exists.
Document in README commands table and LXC deploy steps.

Made-with: Cursor
2026-03-24 21:14:54 +00:00
David Santos 3b35420053 fix(config): replace dead RSS feeds in default sources
Reuters (deprecated host), A Bola 404, and malformed UEFA XML broke
rss:test and reduced crawler yield. Use Guardian + RTP Notícias feeds
verified with rss-parser; refresh trusted_domains.

Made-with: Cursor
2026-03-24 21:02:35 +00:00
David Santos 8b71437c8d feat(rss): retries + rss:test feed probe
- fetchFeed: up to 3 attempts with exponential backoff (500ms base).
- fetchFeedWithResult for structured outcomes; rss:test prints JSON per feed.

Made-with: Cursor
2026-03-24 20:48:26 +00:00
David Santos c80d44dfda feat(cli): wp:test validates all site configs
When multiple config/sites/*.json exist, probe each via REST users/me;
aggregate { ok, sites } on stdout. Incomplete site files fail fast.

Made-with: Cursor
2026-03-24 20:35:31 +00:00
David Santos bd23f10250 feat(cli): add wp:test for WordPress REST credential check
Uses existing testConnection (users/me). Exits non-zero on failure;
prints one-line JSON on success for scripting.

Made-with: Cursor
2026-03-24 20:23:58 +00:00
David Santos f68b5cda7f feat(tools): add verify-deploy.sh for LXC/NPM smoke tests
Validates /health returns ok + mode listen with non-zero exit on failure.
Document npm run verify:deploy in README.

Made-with: Cursor
2026-03-24 20:12:46 +00:00
David Santos cd84efe0b8 chore(deploy): add PM2 ecosystem.config.cjs for listen mode
Single command `pm2 start ecosystem.config.cjs` avoids forgetting `-- listen`.
Document npm script, README deploy path, and Proxmox post-create hints.

Made-with: Cursor
2026-03-24 20:01:22 +00:00
David Santos 6e70fbe1b3 feat(http): enrich /health with version, mode, and HEAD support
Helps ops verify NPM/LXC deployments are running listen mode and the
expected package version, not a one-shot write process.

Made-with: Cursor
2026-03-24 19:59:45 +00:00
David Santos 297649b5f9 docs(deploy): clarify LXC is manual on Proxmox; fix PM2 echo in script
README explains that CT 223 is not created by the repo alone, adds
verification commands and a PT note for NPM/IP alignment. Proxmox helper
echo now matches the full pm2 listen command. CLI usage text documents
the HTTP surface in listen mode.

Made-with: Cursor
2026-03-24 19:48:16 +00:00
David Santos d6248c3f8b fix(deploy): serve HTTP on PORT in listen mode for NPM proxy
The domain pointed at :3200 had no listener: the app was CLI-only and
default PM2 start ran write mode (exits). Listen mode now starts a small
HTTP server on HOST:PORT (defaults 0.0.0.0:3200) with / and /health.
README and Proxmox script document pm2 "listen" and LXC verification.

Ref: BIT-353 board feedback on ainews.bitreport.pt.
Made-with: Cursor
2026-03-24 19:30:55 +00:00