## Board 'New Article' button
- templates/admin/board-page.php: add #prab-board-generate-now button + status div
- includes/admin/class-board-page.php: inject generateNonce + i18n strings into prabBoard;
enqueue companion board-generate.js
- assets/js/board-generate.js: NEW – board button AJAX handler (fires
prautoblogger_generate_now, resets board backoff on success)
- assets/js/board.js: applySnapshot() re-enables button when no active runs
## Chained-cron checkpoint machine (retires SSH workaround)
- includes/core/class-generation-checkpoint-runner.php: NEW (295 lines)
Tick 1 (prautoblogger_gen_orchestrate): orchestrate_only() → persist queue → schedule Tick 2
Tick 2..N (prautoblogger_gen_tick): pop one idea → Article_Worker → reschedule or finalize
Budget/halt contract + lock release on all exit paths
- includes/class-executor.php: on_manual_generation() replaced with 1-line delegate to
Generation_Checkpoint_Runner::on_orchestrate_tick() (SSH workaround retired)
- includes/class-prautoblogger.php: register ORCHESTRATE_ACTION + GENERATE_ACTION hooks
- includes/core/class-pipeline-runner.php: expose orchestrate_only() public wrapper
- includes/core/class-pipeline-status.php: add write_initial() + write_error() helpers
## WP-CLI command
- includes/admin/class-wp-cli-commands.php: wp prautoblogger generate → kick_off()
## IA / perf pass (settings-backed pagination + DB indexes)
- includes/admin/class-board-data-provider.php: replace hardcoded posts_per_page=20 with
get_option('prautoblogger_board_column_limit', DEFAULT)
- includes/admin/class-board-gen-log-query.php: replace LIMIT 10/20 literals with settings-backed values
- includes/admin/class-ideas-browser-query.php: NEW – query helpers extracted from Ideas_Browser
(300-line rule split): query_ideas(), get_type_counts(), load_idea_data(),
find_post_by_run_id(), update_idea_stage()
- includes/admin/class-ideas-browser.php: delegates all query work to Ideas_Browser_Query
- includes/class-activator.php: set_default_options() adds board_column_limit + ideas_per_page
- includes/admin/class-admin-page.php: add new settings to numeric sanitization list
- prautoblogger.php: PRAUTOBLOGGER_DEFAULT_BOARD_COLUMN_LIMIT=20, PRAUTOBLOGGER_DEFAULT_IDEAS_PER_PAGE=30
- includes/class-schema-installer.php: indexes on generation_log + analysis_results (db 1.4.0)
- includes/class-pipeline-schema-installer.php: KEY started_at on runs table
## Guard P2s
- scripts/check-constants.php: --self-test mode + inline CONSTANTS_GUARD_WINDOW comment
- .github/workflows/ci.yml: check-constants-self-test step after main constants check
## PHPUnit test
- tests/unit/Core/GenerationCheckpointRunnerTest.php: NEW (227 lines)
4 tests: kick_off schedules+transient, empty-queue finalizes, halted-run aborts+cleanup,
multi-idea pops-one-and-reschedules
## Docs + version
- prautoblogger.php: Version 0.21.0, PRAUTOBLOGGER_DB_VERSION 1.4.0
- ARCHITECTURE.md: §25 Chained-Cron Checkpoint Generation Path
- CHANGELOG.md: v0.21.0 entry
- INFORMATION-ARCHITECTURE.md: NEW – admin pages, entry points, DB tables, options, CLI
- uninstall.php: purge prautoblogger_gen_orchestrate + prautoblogger_gen_tick cron hooks
Agent-Session: phase2-admin-m4-20260614
157 lines
7.7 KiB
PHP
157 lines
7.7 KiB
PHP
<?php
|
||
|
||
/**
|
||
* phpcs:ignore Generic.PHP.RequireStrictTypes.MissingDeclaration -- strict_types must precede docblock
|
||
*
|
||
* PRAutoBlogger — Automated Content Research & Publishing
|
||
*
|
||
* @wordpress-plugin
|
||
* Plugin Name: PRAutoBlogger
|
||
* Plugin URI: https://peptiderepo.com/prautoblogger
|
||
* Description: Monitors social media for trending topics, generates SEO-friendly blog posts using AI, and publishes them on a daily schedule with full cost tracking and self-improvement metrics.
|
||
* Version: 0.21.0
|
||
* Requires at least: 6.0
|
||
* Requires PHP: 7.4
|
||
* Author: PeptideRepo
|
||
* Author URI: https://peptiderepo.com
|
||
* License: GPL v2 or later
|
||
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
|
||
* Text Domain: prautoblogger
|
||
* Domain Path: /languages
|
||
*
|
||
* @see ARCHITECTURE.md — Full data flow and file tree
|
||
* @see CONVENTIONS.md — Naming patterns and extension guides
|
||
*/
|
||
declare(strict_types=1);
|
||
|
||
// Abort if called directly.
|
||
if ( ! defined( 'ABSPATH' ) ) {
|
||
exit;
|
||
}
|
||
/*
|
||
|--------------------------------------------------------------------------
|
||
| Plugin Constants
|
||
|--------------------------------------------------------------------------
|
||
| Defined here so every file in the plugin can reference paths, versions,
|
||
| and limits without magic strings.
|
||
*/
|
||
define( 'PRAUTOBLOGGER_VERSION', '0.21.0' );
|
||
define( 'PRAUTOBLOGGER_DB_VERSION', '1.4.0' );
|
||
define( 'PRAUTOBLOGGER_DEFAULT_RUN_CEILING_USD', 0.50 );
|
||
define( 'PRAUTOBLOGGER_DEFAULT_REQUEST_JSON_RETENTION_DAYS', 14 );
|
||
// Default max cards shown per board column and per ideas-browser page.
|
||
// Settings-backed (prautoblogger_board_column_limit, prautoblogger_ideas_per_page).
|
||
define( 'PRAUTOBLOGGER_DEFAULT_BOARD_COLUMN_LIMIT', 20 );
|
||
define( 'PRAUTOBLOGGER_DEFAULT_IDEAS_PER_PAGE', 30 );
|
||
// v0.18.1: ceiling on "thinking" tokens per reasoning-enabled LLM call. The
|
||
// request's completion budget (max_tokens) is RAISED by this amount so
|
||
// reasoning can never consume the visible-content budget and return an empty
|
||
// message (the 2026-06-11 empty-draft incident). SETTINGS-backed
|
||
// (prautoblogger_reasoning_max_tokens); 0 disables the cap (pure effort mode).
|
||
define( 'PRAUTOBLOGGER_DEFAULT_REASONING_MAX_TOKENS', 2048 );
|
||
define( 'PRAUTOBLOGGER_PLUGIN_FILE', __FILE__ );
|
||
define( 'PRAUTOBLOGGER_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
|
||
define( 'PRAUTOBLOGGER_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
|
||
define( 'PRAUTOBLOGGER_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
|
||
// API and retry limits — named constants instead of magic numbers.
|
||
define( 'PRAUTOBLOGGER_MAX_RETRIES', 3 );
|
||
define( 'PRAUTOBLOGGER_RETRY_BASE_DELAY_SECONDS', 2 );
|
||
define( 'PRAUTOBLOGGER_API_TIMEOUT_SECONDS', 180 );
|
||
define( 'PRAUTOBLOGGER_CACHE_TTL_SECONDS', 3600 );
|
||
// Default models for OpenRouter (user can override in settings).
|
||
define( 'PRAUTOBLOGGER_DEFAULT_ANALYSIS_MODEL', 'google/gemini-2.5-flash-lite' );
|
||
define( 'PRAUTOBLOGGER_DEFAULT_WRITING_MODEL', 'google/gemini-2.5-flash-lite' );
|
||
define( 'PRAUTOBLOGGER_DEFAULT_EDITOR_MODEL', 'google/gemini-2.5-flash-lite' );
|
||
// Image generation defaults.
|
||
// Default provider is Runware; OpenRouter (Gemini) remains as the alternate.
|
||
// Default model is FLUX.1 schnell via Runware (~$0.0006/image, ~2s). CEO
|
||
// decision 2026-04-21 after comic A/B: schnell's looser fidelity reads as
|
||
// editorial-cartoon style and is 65× cheaper than Nano Banana. Users can
|
||
// override via Settings → Images → Image Model.
|
||
define( 'PRAUTOBLOGGER_DEFAULT_IMAGE_PROVIDER', 'runware' );
|
||
define( 'PRAUTOBLOGGER_DEFAULT_IMAGE_MODEL', 'runware:100@1' );
|
||
// Default style suffix appended to every image-gen prompt. Updated
|
||
// 2026-04-18 v4: single-panel newspaper comic style. Caption is now
|
||
// inserted as HTML text below the image, NOT rendered inside it.
|
||
// Users may override via Settings → Images → Style Suffix.
|
||
define(
|
||
'PRAUTOBLOGGER_DEFAULT_IMAGE_STYLE_SUFFIX',
|
||
'Style: a single-panel newspaper comic in classic black ink on white paper, simple clean linework like The Far Side or B.C., slightly yellowed newsprint texture, hand-drawn crosshatching for shading, bold panel border, warm and humorous tone, visible in a newspaper comics section. IMPORTANT: Do not render any text, captions, speech bubbles, or words inside the image.'
|
||
);
|
||
// Default editorial-illustration prompt template for the image generator.
|
||
// Updated 2026-05-29 (v0.16.0): pivot from single-panel comic to text-free
|
||
// editorial scientific illustration. The {{ topic_summary }} token is filled
|
||
// at build time with a 1-2 sentence topic/mechanism description from the
|
||
// rewriter LLM; the rest is brand-locked. Replaces the old Style Suffix.
|
||
// Users may override via Settings -> Images -> Style Template. Per brief A5
|
||
// the template must contain exactly one {{ topic_summary }} token.
|
||
define(
|
||
'PRAUTOBLOGGER_DEFAULT_IMAGE_STYLE_TEMPLATE',
|
||
"Editorial scientific illustration, flat vector aesthetic, limited palette of\n" .
|
||
"teal (#1B8A92) and cream (#FAF6EE) with ink (#0D0D0D) line work and accents\n" .
|
||
"of orange (#FF8A3D) and lime (#7FD600). Subject: {{ topic_summary }}.\n" .
|
||
"Style reference: Quanta Magazine, The Pudding, scientific editorial illustration.\n" .
|
||
"Composition: clear focal point, balanced negative space, subtle textural detail.\n" .
|
||
'Mood: authoritative, clinical, calm. NO TEXT. NO PEOPLE. NO LOGOS. NO LABELS.'
|
||
);
|
||
// Opik observability (feature-flag gated).
|
||
// API credentials must be defined in wp-config.php constants:
|
||
// - PRAUTOBLOGGER_OPIK_API_KEY: API key for authentication
|
||
// - PRAUTOBLOGGER_OPIK_WORKSPACE: Opik workspace name (e.g. 'peptiderepo')
|
||
// - PRAUTOBLOGGER_OPIK_URL_OVERRIDE: Optional; defaults to https://www.comet.com/opik/api/
|
||
if ( ! defined( 'PRAUTOBLOGGER_OPIK_API_KEY' ) ) {
|
||
define( 'PRAUTOBLOGGER_OPIK_API_KEY', '' );
|
||
}
|
||
if ( ! defined( 'PRAUTOBLOGGER_OPIK_WORKSPACE' ) ) {
|
||
define( 'PRAUTOBLOGGER_OPIK_WORKSPACE', 'peptiderepo' );
|
||
}
|
||
if ( ! defined( 'PRAUTOBLOGGER_OPIK_URL_OVERRIDE' ) ) {
|
||
define( 'PRAUTOBLOGGER_OPIK_URL_OVERRIDE', 'https://www.comet.com/opik/api/' );
|
||
}
|
||
|
||
/*
|
||
|--------------------------------------------------------------------------
|
||
| Autoloader
|
||
|--------------------------------------------------------------------------
|
||
*/
|
||
require_once PRAUTOBLOGGER_PLUGIN_DIR . 'includes/class-autoloader.php';
|
||
PRAutoBlogger_Autoloader::register();
|
||
// The main orchestrator class is loaded explicitly because its CamelCase name
|
||
// (PRAutoBlogger) doesn't map cleanly to a filename via the autoloader's
|
||
// kebab-case convention (it would look for class-pr-auto-blogger.php).
|
||
require_once PRAUTOBLOGGER_PLUGIN_DIR . 'includes/class-db-migrations.php'; // Loaded explicitly: DB_Migrations -> class-d-b-migrations.php via autoloader
|
||
require_once PRAUTOBLOGGER_PLUGIN_DIR . 'includes/class-prautoblogger.php';
|
||
/*
|
||
|--------------------------------------------------------------------------
|
||
| Activation & Deactivation
|
||
|--------------------------------------------------------------------------
|
||
*/
|
||
register_activation_hook( __FILE__, array( 'PRAutoBlogger_Activator', 'activate' ) );
|
||
register_deactivation_hook( __FILE__, array( 'PRAutoBlogger_Deactivator', 'deactivate' ) );
|
||
/*
|
||
|--------------------------------------------------------------------------
|
||
| Boot the Plugin
|
||
|--------------------------------------------------------------------------
|
||
| The main orchestrator registers all hooks. Nothing else happens here —
|
||
| keep the bootstrap file minimal.
|
||
*/
|
||
/**
|
||
* Returns the singleton instance of the main plugin class.
|
||
*
|
||
* @return PRAutoBlogger
|
||
*/
|
||
function prautoblogger(): PRAutoBlogger {
|
||
static $instance = null;
|
||
if ( null === $instance ) {
|
||
$instance = new PRAutoBlogger();
|
||
}
|
||
return $instance;
|
||
}
|
||
// Initialize on plugins_loaded so all dependencies are available.
|
||
add_action(
|
||
'plugins_loaded',
|
||
static function (): void {
|
||
prautoblogger()->run();
|
||
}
|
||
);
|