PR Vision v0.2.0: admin/settings interface + correctness fixes

Requirements 1-8 + all non-negotiables:

1. Model manager (CRUD): PRV_Model_Registry, prv_models v2 option, versioned
   idempotent migration from v0.1.x flat-string format, Settings page CRUD.

2. Per-model run-health: PRV_Model_Registry::update_health() after each run;
   health badges (Healthy/Retired?/Disabled/Unknown) in model table + dashboard.

3. Metric comparability: PRV_Config_Version stamps every run with config_version;
   save-bar warning on scoring-relevant changes; orphaned rows excluded by version.

4. Projected cost at save: PRV_Config::get_projected_cost(); over-cap warning;
   prv_last_run_truncated option + visible notice when cap hit mid-run.

5. Config surface: peptide set, intents, cadence (reschedules cron), budget cap;
   all validated + sanitized; next-run timestamp shown.

6. API-key three-state: not-defined / defined-ok / defined-failed; derived from
   ledger; never displays the key.

7. Run-lock: PRV_Run_Lock (transient); cron tick skips if locked; Run-now
   refuses with clear message; lock released in finally block.

8. Design fixes: dark-ink focus ring on bright fills; disabled-row full AA
   contrast (no opacity); toggle disabled on retired rows; save-bar-level
   warning (role=alert); chip text #B4BDC7 6.83:1 AA; keyboard-sortable headers
   (<button>+aria-sort); aria-live on Test chip; z-index:50 save-bar;
   run-now double-fire guard; @media print light overrides.

New: PRV_Upgrader (runs migrations on plugins_loaded, not just activation),
PRV_Config_Version, PRV_Run_Lock, PRV_Settings_Page, PRV_Settings_Renderer,
PRV_Model_Manager_Table, PRV_Model_Test_Ajax.

Tests: test-model-registry, test-run-lock, test-config-version,
       test-projected-cost, test-cron-reschedule (+ updated probe-runner,
       uninstall, bootstrap).

Schema: config_version INT column added via dbDelta (idempotent).
Uninstall: purges all v0.2 prv_* options + transients.
This commit is contained in:
peptiderepo
2026-06-14 06:43:54 +00:00
parent 401077fe45
commit 8274d54a5e
26 changed files with 2758 additions and 435 deletions

View File

@@ -14,11 +14,14 @@ declare(strict_types=1);
* schema version in the prv_schema_version option so future migrations can
* detect when an upgrade is needed without destructive ALTER TABLE.
*
* Who triggers: PRV_Activator::activate() on plugin activation.
* v0.2.0 adds config_version INT column (nullable; existing rows get NULL
* which is handled cleanly by scoring queries that filter by version).
*
* Who triggers: PRV_Upgrader::run() on every plugins_loaded call (idempotent).
* Dependencies: $wpdb global, dbDelta() (requires upgrade.php).
*
* @see class-prv-activator.php — Calls create_table() on activation.
* @see ARCHITECTURE.md — §Storage.
* @see class-prv-upgrader.php -- Calls create_table() on upgrade.
* @see ARCHITECTURE.md -- Section Storage.
* @package PrVision
*/
class PRV_Table_Manager {
@@ -28,11 +31,17 @@ class PRV_Table_Manager {
*/
const TABLE_BASE = 'prv_ai_visibility';
/**
* Current DB schema version.
*/
const SCHEMA_VERSION = 2;
/**
* Create or upgrade the AI-visibility table.
*
* Uses dbDelta to create or non-destructively alter the table.
* Records the schema version in an option afterwards.
* Safe to call on every plugins_loaded -- dbDelta is idempotent.
*
* Side effects: Writes to the database; sets prv_schema_version option.
*
@@ -45,22 +54,24 @@ class PRV_Table_Manager {
$charset_collate = $wpdb->get_charset_collate();
$sql = "CREATE TABLE {$table_name} (
id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
run_id VARCHAR(36) NOT NULL,
captured_at DATETIME NOT NULL,
peptide_slug VARCHAR(200) NOT NULL,
peptide_label VARCHAR(200) NOT NULL,
model VARCHAR(200) NOT NULL,
prompt_intent VARCHAR(200) NOT NULL,
cited TINYINT(1) NOT NULL DEFAULT 0,
our_position INT(11) NULL DEFAULT NULL,
source_domains LONGTEXT NOT NULL DEFAULT '',
raw_excerpt LONGTEXT NOT NULL DEFAULT '',
cost_usd DECIMAL(12,8) NOT NULL DEFAULT 0.00000000,
id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
run_id VARCHAR(36) NOT NULL,
captured_at DATETIME NOT NULL,
peptide_slug VARCHAR(200) NOT NULL,
peptide_label VARCHAR(200) NOT NULL,
model VARCHAR(200) NOT NULL,
prompt_intent VARCHAR(200) NOT NULL,
cited TINYINT(1) NOT NULL DEFAULT 0,
our_position INT(11) NULL DEFAULT NULL,
source_domains LONGTEXT NOT NULL DEFAULT '',
raw_excerpt LONGTEXT NOT NULL DEFAULT '',
cost_usd DECIMAL(12,8) NOT NULL DEFAULT 0.00000000,
config_version INT(11) NULL DEFAULT NULL,
PRIMARY KEY (id),
KEY run_id (run_id),
KEY peptide_slug (peptide_slug),
KEY captured_at (captured_at)
KEY captured_at (captured_at),
KEY config_version (config_version)
) {$charset_collate};";
if ( ! function_exists( 'dbDelta' ) ) {
@@ -69,7 +80,7 @@ class PRV_Table_Manager {
dbDelta( $sql );
update_option( 'prv_schema_version', PRV_SCHEMA_VERSION );
update_option( 'prv_schema_version', self::SCHEMA_VERSION );
}
/**
@@ -85,7 +96,7 @@ class PRV_Table_Manager {
/**
* Drop the AI-visibility table entirely.
*
* Called only from uninstall.php — never during normal deactivation.
* Called only from uninstall.php -- never during normal deactivation.
*
* Side effects: Permanently destroys all probe data.
*