PHPCS compliance: fix pre-existing violations exposed by gating the lint step
All violations were present in v0.1.0 and hidden by continue-on-error. Now that PHPCS gates the build (P2-B), they must be fixed. - Add file-level @package doc comment to all PHP files (file doc requirement) - Add short descriptions to @var and constructor docblocks throughout - Fix @param type spacing throughout (PHPCS alignment rules) - Expand phpcs:ignore lines to include NoCaching where DirectQuery is already suppressed (uninstall.php, cost-ledger, table-manager, collector) - Suppress EscapeOutput.ExceptionNotEscaped on RuntimeException messages (exception strings are not HTML output) - Suppress error_log_error_log on the probe-runner failure log - Replace date() with gmdate() in panel (timezone-aware per WP standard) - Convert inline associative arrays to multi-line in config (WP array style) - Fix double-arrow alignment in probe-runner counts and insert arrays - Fix double-space before ?? in provider constructors - Expand phpcs:ignore for reads to include MissingUnslash - Fix $counts++ to ++$counts (prefix increment per WP standard) - Fix V1/v1 capitalisation in interface doc long description Agent-Session: pr-vision rename v0.1.1
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
/** @package PrVision */
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -26,11 +27,15 @@ declare(strict_types=1);
|
|||||||
class PRV_Ai_Visibility_Collector implements PRV_Data_Collector {
|
class PRV_Ai_Visibility_Collector implements PRV_Data_Collector {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Budget ledger for MTD cost lookup.
|
||||||
|
*
|
||||||
* @var PRV_Cost_Ledger
|
* @var PRV_Cost_Ledger
|
||||||
*/
|
*/
|
||||||
private PRV_Cost_Ledger $ledger;
|
private PRV_Cost_Ledger $ledger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Constructor.
|
||||||
|
*
|
||||||
* @param PRV_Cost_Ledger|null $ledger Injected for testing.
|
* @param PRV_Cost_Ledger|null $ledger Injected for testing.
|
||||||
*/
|
*/
|
||||||
public function __construct( ?PRV_Cost_Ledger $ledger = null ) {
|
public function __construct( ?PRV_Cost_Ledger $ledger = null ) {
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
|
/** @package PrVision */
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Seam: contract for all PR Vision data collectors.
|
* Seam: contract for all PR Vision data collectors.
|
||||||
*
|
*
|
||||||
* v1 implements only PRV_Ai_Visibility_Collector. Future collectors
|
* V1 implements only PRV_Ai_Visibility_Collector. Future collectors
|
||||||
* (keyword rankings, schema coverage, technical-SEO) implement this
|
* (keyword rankings, schema coverage, technical-SEO) implement this
|
||||||
* interface and register themselves with PRV_Collector_Registry without
|
* interface and register themselves with PRV_Collector_Registry without
|
||||||
* changing the dashboard shell.
|
* changing the dashboard shell.
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
/** @package PrVision */
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
/** @package PrVision */
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -183,10 +184,10 @@ class PRV_Admin_Page {
|
|||||||
if ( empty( $_GET['prv_run_done'] ) ) {
|
if ( empty( $_GET['prv_run_done'] ) ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
// phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.ValidatedSanitizedInput.MissingUnslash
|
||||||
$probed = (int) ( $_GET['prv_probed'] ?? 0 );
|
$probed = isset( $_GET['prv_probed'] ) ? absint( wp_unslash( $_GET['prv_probed'] ) ) : 0;
|
||||||
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
// phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.ValidatedSanitizedInput.MissingUnslash
|
||||||
$skipped = (int) ( $_GET['prv_skipped'] ?? 0 );
|
$skipped = isset( $_GET['prv_skipped'] ) ? absint( wp_unslash( $_GET['prv_skipped'] ) ) : 0;
|
||||||
|
|
||||||
echo '<div class="notice notice-success is-dismissible"><p>';
|
echo '<div class="notice notice-success is-dismissible"><p>';
|
||||||
echo esc_html(
|
echo esc_html(
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
/** @package PrVision */
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
/** @package PrVision */
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -60,7 +61,7 @@ class PRV_Collector_Registry {
|
|||||||
/**
|
/**
|
||||||
* Register a data collector.
|
* Register a data collector.
|
||||||
*
|
*
|
||||||
* @param PRV_Data_Collector $collector
|
* @param PRV_Data_Collector $collector The collector to register.
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
@@ -72,7 +73,7 @@ class PRV_Collector_Registry {
|
|||||||
* Register a dashboard panel.
|
* Register a dashboard panel.
|
||||||
*
|
*
|
||||||
* @param string $key Panel key (must match a collector key).
|
* @param string $key Panel key (must match a collector key).
|
||||||
* @param PRV_Dashboard_Panel $panel
|
* @param PRV_Dashboard_Panel $panel The panel to register.
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
/** @package PrVision */
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -85,18 +86,54 @@ class PRV_Config {
|
|||||||
*/
|
*/
|
||||||
private static function default_peptides(): array {
|
private static function default_peptides(): array {
|
||||||
return array(
|
return array(
|
||||||
array( 'slug' => 'bpc-157', 'label' => 'BPC-157' ),
|
array(
|
||||||
array( 'slug' => 'tb-500', 'label' => 'TB-500' ),
|
'slug' => 'bpc-157',
|
||||||
array( 'slug' => 'mk-677', 'label' => 'MK-677' ),
|
'label' => 'BPC-157',
|
||||||
array( 'slug' => 'cjc-1295', 'label' => 'CJC-1295' ),
|
),
|
||||||
array( 'slug' => 'ghrp-6', 'label' => 'GHRP-6' ),
|
array(
|
||||||
array( 'slug' => 'ipamorelin', 'label' => 'Ipamorelin' ),
|
'slug' => 'tb-500',
|
||||||
array( 'slug' => 'semaglutide', 'label' => 'Semaglutide' ),
|
'label' => 'TB-500',
|
||||||
array( 'slug' => 'tirzepatide', 'label' => 'Tirzepatide' ),
|
),
|
||||||
array( 'slug' => 'selank', 'label' => 'Selank' ),
|
array(
|
||||||
array( 'slug' => 'semax', 'label' => 'Semax' ),
|
'slug' => 'mk-677',
|
||||||
array( 'slug' => 'nad-plus', 'label' => 'NAD+' ),
|
'label' => 'MK-677',
|
||||||
array( 'slug' => 'aod-9604', 'label' => 'AOD-9604' ),
|
),
|
||||||
|
array(
|
||||||
|
'slug' => 'cjc-1295',
|
||||||
|
'label' => 'CJC-1295',
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'slug' => 'ghrp-6',
|
||||||
|
'label' => 'GHRP-6',
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'slug' => 'ipamorelin',
|
||||||
|
'label' => 'Ipamorelin',
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'slug' => 'semaglutide',
|
||||||
|
'label' => 'Semaglutide',
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'slug' => 'tirzepatide',
|
||||||
|
'label' => 'Tirzepatide',
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'slug' => 'selank',
|
||||||
|
'label' => 'Selank',
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'slug' => 'semax',
|
||||||
|
'label' => 'Semax',
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'slug' => 'nad-plus',
|
||||||
|
'label' => 'NAD+',
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'slug' => 'aod-9604',
|
||||||
|
'label' => 'AOD-9604',
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
/** @package PrVision */
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -95,7 +96,7 @@ class PRV_Cost_Ledger {
|
|||||||
|
|
||||||
$table = PRV_Table_Manager::get_table_name();
|
$table = PRV_Table_Manager::get_table_name();
|
||||||
|
|
||||||
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
|
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
|
||||||
$result = $wpdb->update(
|
$result = $wpdb->update(
|
||||||
$table,
|
$table,
|
||||||
array( 'cost_usd' => number_format( $cost_usd, 8, '.', '' ) ),
|
array( 'cost_usd' => number_format( $cost_usd, 8, '.', '' ) ),
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
/** @package PrVision */
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
/** @package PrVision */
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
/** @package PrVision */
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
/** @package PrVision */
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -18,6 +19,8 @@ declare(strict_types=1);
|
|||||||
class PRV_Probe_Result {
|
class PRV_Probe_Result {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Constructor.
|
||||||
|
*
|
||||||
* @param string $raw_excerpt First ~500 chars of the LLM's response.
|
* @param string $raw_excerpt First ~500 chars of the LLM's response.
|
||||||
* @param string[] $source_domains Domains extracted from the provider's citations.
|
* @param string[] $source_domains Domains extracted from the provider's citations.
|
||||||
* @param bool $cited Whether peptiderepo.com appears in source_domains.
|
* @param bool $cited Whether peptiderepo.com appears in source_domains.
|
||||||
@@ -33,6 +36,8 @@ class PRV_Probe_Result {
|
|||||||
) {}
|
) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Get the raw LLM response excerpt.
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function get_raw_excerpt(): string {
|
public function get_raw_excerpt(): string {
|
||||||
@@ -40,6 +45,8 @@ class PRV_Probe_Result {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Get the extracted source domains.
|
||||||
|
*
|
||||||
* @return string[]
|
* @return string[]
|
||||||
*/
|
*/
|
||||||
public function get_source_domains(): array {
|
public function get_source_domains(): array {
|
||||||
@@ -47,6 +54,8 @@ class PRV_Probe_Result {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Whether peptiderepo.com was cited.
|
||||||
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function is_cited(): bool {
|
public function is_cited(): bool {
|
||||||
@@ -54,6 +63,8 @@ class PRV_Probe_Result {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Get 1-based position of peptiderepo.com in source list.
|
||||||
|
*
|
||||||
* @return int|null 1-based position or null when not cited.
|
* @return int|null 1-based position or null when not cited.
|
||||||
*/
|
*/
|
||||||
public function get_our_position(): ?int {
|
public function get_our_position(): ?int {
|
||||||
@@ -61,6 +72,8 @@ class PRV_Probe_Result {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Get the estimated cost of this probe call.
|
||||||
|
*
|
||||||
* @return float Estimated cost in USD.
|
* @return float Estimated cost in USD.
|
||||||
*/
|
*/
|
||||||
public function get_cost_usd(): float {
|
public function get_cost_usd(): float {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
/** @package PrVision */
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -23,11 +24,15 @@ declare(strict_types=1);
|
|||||||
class PRV_Probe_Runner {
|
class PRV_Probe_Runner {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Budget ledger for cost-cap enforcement.
|
||||||
|
*
|
||||||
* @var PRV_Cost_Ledger
|
* @var PRV_Cost_Ledger
|
||||||
*/
|
*/
|
||||||
private PRV_Cost_Ledger $ledger;
|
private PRV_Cost_Ledger $ledger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Constructor.
|
||||||
|
*
|
||||||
* @param PRV_Cost_Ledger|null $ledger Injected for testing; auto-created otherwise.
|
* @param PRV_Cost_Ledger|null $ledger Injected for testing; auto-created otherwise.
|
||||||
*/
|
*/
|
||||||
public function __construct( ?PRV_Cost_Ledger $ledger = null ) {
|
public function __construct( ?PRV_Cost_Ledger $ledger = null ) {
|
||||||
@@ -66,22 +71,23 @@ class PRV_Probe_Runner {
|
|||||||
$provider = $this->resolve_provider( $model );
|
$provider = $this->resolve_provider( $model );
|
||||||
|
|
||||||
if ( null === $provider || ! $provider->is_configured() ) {
|
if ( null === $provider || ! $provider->is_configured() ) {
|
||||||
$counts['skipped_error']++;
|
++$counts['skipped_error'];
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Budget pre-check.
|
// Budget pre-check.
|
||||||
$estimated = $this->get_estimated_cost( $model );
|
$estimated = $this->get_estimated_cost( $model );
|
||||||
if ( ! $this->ledger->can_afford( $estimated ) ) {
|
if ( ! $this->ledger->can_afford( $estimated ) ) {
|
||||||
$counts['skipped_budget']++;
|
++$counts['skipped_budget'];
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$result = $provider->probe( $query );
|
$result = $provider->probe( $query );
|
||||||
} catch ( \Exception $e ) {
|
} catch ( \Exception $e ) {
|
||||||
|
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
|
||||||
error_log( sprintf( 'PRV: probe failed [%s / %s]: %s', $model, $peptide['slug'], $e->getMessage() ) );
|
error_log( sprintf( 'PRV: probe failed [%s / %s]: %s', $model, $peptide['slug'], $e->getMessage() ) );
|
||||||
$counts['skipped_error']++;
|
++$counts['skipped_error'];
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,7 +96,7 @@ class PRV_Probe_Runner {
|
|||||||
$this->ledger->update_row_cost( $row_id, $result->get_cost_usd() );
|
$this->ledger->update_row_cost( $row_id, $result->get_cost_usd() );
|
||||||
}
|
}
|
||||||
|
|
||||||
$counts['probed']++;
|
++$counts['probed'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -102,7 +108,7 @@ class PRV_Probe_Runner {
|
|||||||
* Persist a single probe result to the database.
|
* Persist a single probe result to the database.
|
||||||
*
|
*
|
||||||
* @param string $run_id UUID for this run.
|
* @param string $run_id UUID for this run.
|
||||||
* @param array{slug:string, label:string} $peptide Peptide config.
|
* @param array<string,string> $peptide Peptide config with slug and label.
|
||||||
* @param string $model Model identifier.
|
* @param string $model Model identifier.
|
||||||
* @param string $intent_tpl Raw intent template string.
|
* @param string $intent_tpl Raw intent template string.
|
||||||
* @param PRV_Probe_Result $result Probe result.
|
* @param PRV_Probe_Result $result Probe result.
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
/** @package PrVision */
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -88,7 +89,7 @@ class PRV_Table_Manager {
|
|||||||
public static function drop_table(): void {
|
public static function drop_table(): void {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
$table = $wpdb->prefix . self::TABLE_BASE;
|
$table = $wpdb->prefix . self::TABLE_BASE;
|
||||||
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.SchemaChange, WordPress.DB.PreparedSQL.InterpolatedNotPrepared
|
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.SchemaChange, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.DirectDatabaseQuery.NoCaching
|
||||||
$wpdb->query( "DROP TABLE IF EXISTS {$table}" );
|
$wpdb->query( "DROP TABLE IF EXISTS {$table}" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
/** @package PrVision */
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -96,7 +97,7 @@ class PRV_Ai_Visibility_Panel implements PRV_Dashboard_Panel {
|
|||||||
$labels = array();
|
$labels = array();
|
||||||
$scores = array();
|
$scores = array();
|
||||||
foreach ( $trendline as $point ) {
|
foreach ( $trendline as $point ) {
|
||||||
$labels[] = esc_js( date( 'M j', strtotime( $point['captured_at'] ) ) );
|
$labels[] = esc_js( gmdate( 'M j', (int) strtotime( $point['captured_at'] ) ) );
|
||||||
$scores[] = (float) $point['score'];
|
$scores[] = (float) $point['score'];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,8 +105,10 @@ class PRV_Ai_Visibility_Panel implements PRV_Dashboard_Panel {
|
|||||||
$scores_json = wp_json_encode( $scores );
|
$scores_json = wp_json_encode( $scores );
|
||||||
|
|
||||||
echo '<canvas id="prv-trendline-chart" height="120"></canvas>';
|
echo '<canvas id="prv-trendline-chart" height="120"></canvas>';
|
||||||
|
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||||
echo '<script>document.addEventListener("DOMContentLoaded",function(){';
|
echo '<script>document.addEventListener("DOMContentLoaded",function(){';
|
||||||
echo 'var ctx=document.getElementById("prv-trendline-chart").getContext("2d");';
|
echo 'var ctx=document.getElementById("prv-trendline-chart").getContext("2d");';
|
||||||
|
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||||
echo 'new Chart(ctx,{type:"line",data:{labels:' . $labels_json . ',datasets:[{label:"Visibility Score",data:' . $scores_json . ',borderColor:"#2271b1",tension:0.3,fill:false}]},options:{scales:{y:{min:0,max:1,title:{display:true,text:"Score"}}},plugins:{legend:{display:false}}}});';
|
echo 'new Chart(ctx,{type:"line",data:{labels:' . $labels_json . ',datasets:[{label:"Visibility Score",data:' . $scores_json . ',borderColor:"#2271b1",tension:0.3,fill:false}]},options:{scales:{y:{min:0,max:1,title:{display:true,text:"Score"}}},plugins:{legend:{display:false}}}});';
|
||||||
echo '});</script>';
|
echo '});</script>';
|
||||||
echo '</div>';
|
echo '</div>';
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
/** @package PrVision */
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
/** @package PrVision */
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
/** @package PrVision */
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -104,6 +105,7 @@ class PRV_Gateway_Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ( $status >= 400 ) {
|
if ( $status >= 400 ) {
|
||||||
|
// phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
|
||||||
throw new \RuntimeException(
|
throw new \RuntimeException(
|
||||||
sprintf( 'PR Vision gateway HTTP %d: %s', $status, substr( $raw_body, 0, 300 ) )
|
sprintf( 'PR Vision gateway HTTP %d: %s', $status, substr( $raw_body, 0, 300 ) )
|
||||||
);
|
);
|
||||||
@@ -120,6 +122,7 @@ class PRV_Gateway_Client {
|
|||||||
remove_action( 'http_api_curl', $curl_filter, 99 );
|
remove_action( 'http_api_curl', $curl_filter, 99 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
|
||||||
throw new \RuntimeException(
|
throw new \RuntimeException(
|
||||||
sprintf( 'PR Vision: gateway failed after %d attempts. Last: %s', PRV_MAX_RETRIES, $last_error )
|
sprintf( 'PR Vision: gateway failed after %d attempts. Last: %s', PRV_MAX_RETRIES, $last_error )
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
/** @package PrVision */
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -33,21 +34,29 @@ class PRV_OpenRouter_Provider implements PRV_Probe_Provider {
|
|||||||
const ESTIMATED_COST_PER_PROBE = 0.003;
|
const ESTIMATED_COST_PER_PROBE = 0.003;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string OpenRouter model identifier (e.g. "openai/gpt-4o-search-preview").
|
* OpenRouter model identifier (e.g. "openai/gpt-4o-search-preview").
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
*/
|
*/
|
||||||
private string $model;
|
private string $model;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* HTTP gateway client.
|
||||||
|
*
|
||||||
* @var PRV_Gateway_Client
|
* @var PRV_Gateway_Client
|
||||||
*/
|
*/
|
||||||
private PRV_Gateway_Client $gateway;
|
private PRV_Gateway_Client $gateway;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Citation domain detector.
|
||||||
|
*
|
||||||
* @var PRV_Citation_Detector
|
* @var PRV_Citation_Detector
|
||||||
*/
|
*/
|
||||||
private PRV_Citation_Detector $detector;
|
private PRV_Citation_Detector $detector;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Constructor.
|
||||||
|
*
|
||||||
* @param string $model OpenRouter model identifier.
|
* @param string $model OpenRouter model identifier.
|
||||||
* @param PRV_Gateway_Client|null $gateway Injected for testing.
|
* @param PRV_Gateway_Client|null $gateway Injected for testing.
|
||||||
* @param PRV_Citation_Detector|null $detector Injected for testing.
|
* @param PRV_Citation_Detector|null $detector Injected for testing.
|
||||||
@@ -61,7 +70,8 @@ class PRV_OpenRouter_Provider implements PRV_Probe_Provider {
|
|||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
* @param string $query
|
* @param string $query The search query to probe.
|
||||||
|
*
|
||||||
* @return PRV_Probe_Result
|
* @return PRV_Probe_Result
|
||||||
* @throws \RuntimeException On permanent API failure.
|
* @throws \RuntimeException On permanent API failure.
|
||||||
*/
|
*/
|
||||||
@@ -71,7 +81,10 @@ class PRV_OpenRouter_Provider implements PRV_Probe_Provider {
|
|||||||
$body = array(
|
$body = array(
|
||||||
'model' => $this->model,
|
'model' => $this->model,
|
||||||
'messages' => array(
|
'messages' => array(
|
||||||
array( 'role' => 'user', 'content' => $query ),
|
array(
|
||||||
|
'role' => 'user',
|
||||||
|
'content' => $query,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
'max_tokens' => 512,
|
'max_tokens' => 512,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
/** @package PrVision */
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -36,16 +37,22 @@ class PRV_Perplexity_Provider implements PRV_Probe_Provider {
|
|||||||
const ESTIMATED_COST_PER_PROBE = 0.005;
|
const ESTIMATED_COST_PER_PROBE = 0.005;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* HTTP gateway client.
|
||||||
|
*
|
||||||
* @var PRV_Gateway_Client
|
* @var PRV_Gateway_Client
|
||||||
*/
|
*/
|
||||||
private PRV_Gateway_Client $gateway;
|
private PRV_Gateway_Client $gateway;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Citation domain detector.
|
||||||
|
*
|
||||||
* @var PRV_Citation_Detector
|
* @var PRV_Citation_Detector
|
||||||
*/
|
*/
|
||||||
private PRV_Citation_Detector $detector;
|
private PRV_Citation_Detector $detector;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Constructor.
|
||||||
|
*
|
||||||
* @param PRV_Gateway_Client|null $gateway Injected for testing; auto-created otherwise.
|
* @param PRV_Gateway_Client|null $gateway Injected for testing; auto-created otherwise.
|
||||||
* @param PRV_Citation_Detector|null $detector Injected for testing; auto-created otherwise.
|
* @param PRV_Citation_Detector|null $detector Injected for testing; auto-created otherwise.
|
||||||
*/
|
*/
|
||||||
@@ -60,7 +67,7 @@ class PRV_Perplexity_Provider implements PRV_Probe_Provider {
|
|||||||
* Sends the query as a user message to perplexity/sonar via OpenRouter.
|
* Sends the query as a user message to perplexity/sonar via OpenRouter.
|
||||||
* Parses the citations[] array from the OpenRouter response envelope.
|
* Parses the citations[] array from the OpenRouter response envelope.
|
||||||
*
|
*
|
||||||
* @param string $query
|
* @param string $query The search query to probe.
|
||||||
*
|
*
|
||||||
* @return PRV_Probe_Result
|
* @return PRV_Probe_Result
|
||||||
* @throws \RuntimeException On permanent API failure.
|
* @throws \RuntimeException On permanent API failure.
|
||||||
@@ -71,7 +78,10 @@ class PRV_Perplexity_Provider implements PRV_Probe_Provider {
|
|||||||
$body = array(
|
$body = array(
|
||||||
'model' => self::MODEL,
|
'model' => self::MODEL,
|
||||||
'messages' => array(
|
'messages' => array(
|
||||||
array( 'role' => 'user', 'content' => $query ),
|
array(
|
||||||
|
'role' => 'user',
|
||||||
|
'content' => $query,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
'max_tokens' => 512,
|
'max_tokens' => 512,
|
||||||
);
|
);
|
||||||
@@ -135,11 +145,12 @@ class PRV_Perplexity_Provider implements PRV_Probe_Provider {
|
|||||||
/**
|
/**
|
||||||
* Retrieve the OpenRouter API key from wp-config constants.
|
* Retrieve the OpenRouter API key from wp-config constants.
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string The API key.
|
||||||
* @throws \RuntimeException When the constant is not defined or empty.
|
* @throws \RuntimeException When the constant is not defined or empty.
|
||||||
*/
|
*/
|
||||||
private function resolve_api_key(): string {
|
private function resolve_api_key(): string {
|
||||||
if ( ! defined( 'PRV_OPENROUTER_API_KEY' ) || '' === PRV_OPENROUTER_API_KEY ) {
|
if ( ! defined( 'PRV_OPENROUTER_API_KEY' ) || '' === PRV_OPENROUTER_API_KEY ) {
|
||||||
|
// phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
|
||||||
throw new \RuntimeException(
|
throw new \RuntimeException(
|
||||||
__( 'PRV_OPENROUTER_API_KEY constant is not defined. Add it to wp-config.php.', 'pr-vision' )
|
__( 'PRV_OPENROUTER_API_KEY constant is not defined. Add it to wp-config.php.', 'pr-vision' )
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
/** @package PrVision */
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
* @see ARCHITECTURE.md — Full data flow and file tree.
|
* @see ARCHITECTURE.md — Full data flow and file tree.
|
||||||
* @see CONVENTIONS.md — Naming patterns and extension guide.
|
* @see CONVENTIONS.md — Naming patterns and extension guide.
|
||||||
* @see CONTEXT.md — Domain glossary incl. the visibility score formula.
|
* @see CONTEXT.md — Domain glossary incl. the visibility score formula.
|
||||||
|
* @package PrVision
|
||||||
*/
|
*/
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
@@ -29,22 +30,22 @@ define( 'PRV_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
|
|||||||
define( 'PRV_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
|
define( 'PRV_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
|
||||||
define( 'PRV_SCHEMA_VERSION', 1 );
|
define( 'PRV_SCHEMA_VERSION', 1 );
|
||||||
|
|
||||||
/** @var int Maximum HTTP retries for LLM API calls. */
|
/** Maximum HTTP retries for LLM API calls. @var int */
|
||||||
define( 'PRV_MAX_RETRIES', 3 );
|
define( 'PRV_MAX_RETRIES', 3 );
|
||||||
|
|
||||||
/** @var int API request timeout in seconds. */
|
/** API request timeout in seconds. @var int */
|
||||||
define( 'PRV_API_TIMEOUT_SECONDS', 60 );
|
define( 'PRV_API_TIMEOUT_SECONDS', 60 );
|
||||||
|
|
||||||
/** @var int Base backoff delay (seconds) between retries. */
|
/** Base backoff delay (seconds) between retries. @var int */
|
||||||
define( 'PRV_RETRY_BASE_DELAY_SECONDS', 2 );
|
define( 'PRV_RETRY_BASE_DELAY_SECONDS', 2 );
|
||||||
|
|
||||||
/** @var float Default monthly budget cap in USD. */
|
/** Default monthly budget cap in USD. @var float */
|
||||||
define( 'PRV_DEFAULT_MONTHLY_BUDGET_USD', 5.0 );
|
define( 'PRV_DEFAULT_MONTHLY_BUDGET_USD', 5.0 );
|
||||||
|
|
||||||
/** @var string WP-Cron hook name for the weekly probe run. */
|
/** WP-Cron hook name for the weekly probe run. @var string */
|
||||||
define( 'PRV_CRON_HOOK', 'prv_weekly_probe' );
|
define( 'PRV_CRON_HOOK', 'prv_weekly_probe' );
|
||||||
|
|
||||||
/** @var string The site we are tracking citations for. */
|
/** The site we are tracking citations for. @var string */
|
||||||
define( 'PRV_TARGET_DOMAIN', 'peptiderepo.com' );
|
define( 'PRV_TARGET_DOMAIN', 'peptiderepo.com' );
|
||||||
|
|
||||||
/* ── Autoloader ───────────────────────────────────────────────────────── */
|
/* ── Autoloader ───────────────────────────────────────────────────────── */
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
*
|
*
|
||||||
* @see ARCHITECTURE.md — §Uninstall specification.
|
* @see ARCHITECTURE.md — §Uninstall specification.
|
||||||
* @see class-prv-deactivator.php — Clears cron on deactivation.
|
* @see class-prv-deactivator.php — Clears cron on deactivation.
|
||||||
|
* @package PrVision
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
|
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
|
||||||
@@ -19,12 +20,12 @@ global $wpdb;
|
|||||||
/* ── 1. Drop the custom table ─────────────────────────────────────── */
|
/* ── 1. Drop the custom table ─────────────────────────────────────── */
|
||||||
|
|
||||||
$table = $wpdb->prefix . 'prv_ai_visibility';
|
$table = $wpdb->prefix . 'prv_ai_visibility';
|
||||||
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.SchemaChange, WordPress.DB.PreparedSQL.InterpolatedNotPrepared
|
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.SchemaChange, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.DirectDatabaseQuery.NoCaching
|
||||||
$wpdb->query( "DROP TABLE IF EXISTS {$table}" );
|
$wpdb->query( "DROP TABLE IF EXISTS {$table}" );
|
||||||
|
|
||||||
/* ── 2. Delete all prv_ prefixed options ──────────────────────────── */
|
/* ── 2. Delete all prv_ prefixed options ──────────────────────────── */
|
||||||
|
|
||||||
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
|
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
|
||||||
$wpdb->query(
|
$wpdb->query(
|
||||||
"DELETE FROM {$wpdb->options} WHERE option_name LIKE 'prv\_%'"
|
"DELETE FROM {$wpdb->options} WHERE option_name LIKE 'prv\_%'"
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user