Commit Graph

18 Commits

Author SHA1 Message Date
peptiderepo
04b90e2e2d refactor(admin): extract filter field renderers (325 → 249 + 103 lines)
Move 7 content-filter settings field renderers into dedicated
Peptide_News_Admin_Filter_Field_Renderers class. Main field
renderers file drops from 325 to 249 lines with backward-
compatible one-liner proxies.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-16 22:43:50 +07:00
peptiderepo
159a36eeb7 refactor(analytics): split 365-line analytics into recording + reports
Extract 6 read-only reporting queries (top articles, click trends,
popular topics, device breakdown, source performance, CSV export) into
Peptide_News_Analytics_Reports (196 lines). Main class retains click
recording, daily stats aggregation, IP handling, and device detection
(186 lines). Backward-compatible proxies preserved.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-16 22:42:06 +07:00
peptiderepo
59d469ba0f refactor(rest): split 435-line REST API into router + articles handler
Extract article listing endpoint and source-suffix stripping into
Peptide_News_Rest_Articles (195 lines). Main REST API retains route
registration, analytics endpoint wrappers, AJAX delete handler, and
permission/validation helpers (210 lines).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-16 22:40:34 +07:00
peptiderepo
6060aa3ce1 refactor(filter): split 536-line content filter into orchestrator + rules
Extract keyword data, domain blocklists, and rule evaluation into
Peptide_News_Content_Filter_Rules (195 lines). Main class retains
orchestration, LLM classification, and stats (234 lines). Backward-
compatible proxies preserved on Peptide_News_Content_Filter.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-16 22:38:34 +07:00
peptiderepo
f57bf15b9b refactor(cost): split 550-line cost tracker into tracker + reporter
Extract read-only reporting queries (get_cost_summary, get_daily_costs,
get_recent_calls, ajax_get_cost_data) into Peptide_News_Cost_Reporter
(224 lines). Core tracker retains logging, budget enforcement, pricing,
table creation, and pruning (276 lines). Backward-compatible proxies
preserved on Peptide_News_Cost_Tracker.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-16 22:36:36 +07:00
peptiderepo
64e715372a refactor(fetcher): split 611-line fetcher into 3 focused files
Extract source-resolution and RSS-specific logic from the monolithic
Peptide_News_Fetcher:

- class-peptide-news-source-resolver.php (229 lines) — aggregator
  source detection, redirect resolution, title parsing, backfill
- class-peptide-news-rss-source.php (118 lines) — RSS/Atom feed
  fetching and SimplePie item processing
- class-peptide-news-fetcher.php (271 lines) — orchestrator with
  NewsAPI, storage, pruning, caching, and AI post-processing

Also consolidated duplicate clear_article_cache/invalidate_rest_api_cache
methods (they were identical) into a single clear_article_cache().

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-16 22:30:50 +07:00
peptiderepo
69cb00063f refactor(llm): split 694-line LLM class into 4 focused files
The monolithic Peptide_News_LLM class mixed HTTP transport, prompt
construction, batch orchestration, and AJAX handling. Split into:

- class-peptide-news-llm-client.php (199 lines) — OpenRouter HTTP
  transport with retry logic and response parsing
- class-peptide-news-llm-prompt-builder.php (142 lines) — keyword
  and summary prompt construction, article text fetching
- class-peptide-news-llm-ajax.php (87 lines) — bulk-generate AJAX
  handler
- class-peptide-news-llm.php (300 lines) — orchestrator with
  backward-compatible proxies for is_valid_model(), call_openrouter(),
  and call_openrouter_with_usage()

Extracted run_llm_task() helper to deduplicate the keyword/summary
processing blocks. All public API preserved — no test changes needed.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-16 22:22:45 +07:00
peptiderepo
0f3adf0c5d refactor(admin): split 1089-line admin class into 7 focused files (#7)
Addresses excessive line count in Peptide_News_Admin (1089 lines)
by extracting responsibilities into single-purpose classes:

- class-pn-admin-assets.php (88 lines): CSS/JS enqueuing
- class-pn-admin-menu.php (98 lines): Menu & submenu registration
- class-pn-admin-field-renderers.php (325 lines): 25+ field renderers (static)
- class-pn-admin-settings.php (289 lines): Settings registration & sanitization
- class-pn-admin-log-viewer.php (155 lines): Plugin log viewer UI & AJAX
- class-pn-admin-settings-page.php (214 lines): Settings page + manual buttons
- class-pn-admin-dashboard-pages.php (109 lines): Dashboard/articles/cost pages
- class-peptide-news-admin.php (143 lines): Thin orchestrator (delegator)

All files under 300 lines. Original public interface preserved exactly
so no consumer code or tests break. Updated ARCHITECTURE.md.

Co-authored-by: peptiderepo <peptiderepo@users.noreply.github.com>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-16 16:50:26 +07:00
Terence
b7da4f42b9 feat: add LLM cost tracking with budget enforcement and admin dashboard
- New Cost_Tracker class: logs every API call (model, tokens, cost), enforces
  monthly budgets with hard-stop mode, provides aggregated reporting
- New llm_costs database table with indexes on created_at, model, operation
- Modified LLM class: call_openrouter_with_usage() extracts token usage from
  OpenRouter responses; budget gate checks before each API call
- Admin settings: monthly budget (USD), enforcement mode (disabled/warn/hard-stop),
  cost log retention period
- Admin cost dashboard: budget progress bar, daily cost chart (Chart.js),
  per-model and per-operation breakdowns, recent API call log
- PHPUnit tests: 16 tests covering cost calculation, pricing lookups,
  budget enforcement logic, and model validation
- Updated ARCHITECTURE.md with new table schema, data flow, and key decisions
- Updated CONVENTIONS.md with "how to add cost tracking for a new operation"
- Version bump to 2.4.0

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 04:18:30 +07:00
peptiderepo
c885ebf98c fix: convert all PHP files from space indentation to tabs (PHPCS)
WordPress coding standards require tab indentation. All 12 PHP files
in includes/, admin/, and public/ were using 4-space indentation.
Converted to tabs to pass the Generic.WhiteSpace.DisallowSpaceIndent
PHPCS rule. Whitespace-only change — no logic modifications.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-12 17:03:55 +07:00
Terence Ong
b05913ed9a feat: add article delete functionality to admin UI
Add bulk and per-row article deletion with AJAX handler, confirmation
dialogs, and cascading cleanup of click analytics via foreign keys.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-11 21:22:33 +07:00
Terence Ong
6c57f6ca11 feat: add structured plugin logging system with admin log viewer
Introduces Peptide_News_Logger class with leveled logging (info, warning,
error, debug) to a custom DB table, auto-pruning at 2000 rows. Adds a
filterable, paginated log viewer to the admin settings page. Instruments
the LLM and Fetcher classes with structured log calls for fetch cycles,
AI processing, and error tracking. Version bumped to 2.1.0.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-07 15:58:51 +07:00
Terence Ong
ab56ec7e97 feat: add bulk AI summary generation button to admin
Adds a "Generate AI Summaries" button to the Peptide News settings page
that processes all articles missing summaries in batches of 50. The UI
loops automatically until every article has been summarized, showing
real-time progress. The admin batch overrides the per-cycle limit so it
isn't capped at 10 — the existing 120-second timeout guard still applies.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-07 14:59:18 +07:00
Terence Ong
1ae831e183 feat: remove AI thumbnails, rewrite frontend with React (v1.3.0)
Remove all AI thumbnail generation infrastructure (too expensive,
poor results) and rewrite the public-facing article feed as a React
SPA mounted via WordPress shortcode.

Changes:
- Remove thumbnail generation, OG scraping, and image download code
  from fetcher, LLM, and admin classes
- Replace server-rendered PHP templates with React component
  (PeptideNewsFeed.jsx) using WordPress-bundled React/ReactDOM
- Add Babel build pipeline for JSX transpilation
- Update REST API to serve ai_summary instead of thumbnail fields
- Redesign public CSS: clean card layout, loading skeletons,
  dark mode, responsive, no thumbnail imagery
- Remove dead admin settings (llm_image_model, thumbnail_fallback)
- Fix call_openrouter() visibility for Content Filter cross-class use
- Bump version to 1.3.0

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-07 09:45:12 +07:00
Terence Ong
5918a7d446 Fix missing thumbnails by resolving Google News redirect URLs before OG scraping
The OG image scraper was using Google News redirect URLs (source_url) directly,
which don't serve og:image tags. Added resolve_scrape_url() to follow redirects
(including meta-refresh and JS redirects) to reach the actual publisher page
before scraping. Also added a backfill AJAX endpoint and admin button to
re-scrape thumbnails for existing articles.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-06 19:32:09 +07:00
Terence Ong
18158a3b81 fix: resolve actual article source instead of showing aggregator domain
Google News RSS feeds report every article as coming from
"news.google.com" because the source was extracted from the feed URL
rather than the individual article. This adds a multi-strategy
resolver that extracts the real publisher name via:

1. SimplePie <source> element (Google News provides this)
2. Title suffix parsing ("Headline - Source" format)
3. HTTP HEAD redirect resolution as a fallback

Also adds a one-click "Fix Article Sources" backfill button on the
settings page to correct existing articles in the database.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-06 19:11:14 +07:00
Terence Ong
e6887e810f Add content filter to block ads, press releases, and promotional content
Two-tier filtering during article fetch: keyword/pattern rules as a fast
first pass, then optional LLM classification for borderline cases via
OpenRouter. Configurable sensitivity (strict/moderate/lenient), editable
keyword lists, blocked domain list, and admin stats display. Includes
30 unit tests covering domain blocking, title/body keywords, URL paths,
edge cases, and prompt structure.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-06 14:14:16 +07:00
peptiderepo
f672b4a670 feat: load LLM class dependency 2026-04-06 00:10:02 +07:00