Final Phase 2 admin milestone. Board "New Article" runs through the M3 chained-cron checkpoint state machine (one stage/idea per tick, queue persisted before generate, lock released on every exit path) so generation survives Hostinger background-kill; retires the SSH-only do_action workaround (WP-CLI routes through the same entry). IA/perf: settings-backed board/ideas pagination + db 1.4.0 indexes. Folds guard P2s (--self-test + window doc). QA: APPROVE-WITH-P2-NOTES @f2a00d4+ delta APPROVE @0c8071f. Deferred (tracked): class-admin-page.php 353-line split + pagination Settings-UI fields. Agent-Session: phase2-admin-m4-20260614
104 lines
2.9 KiB
PHP
104 lines
2.9 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
/**
|
|
* WP-CLI commands for PRAutoBlogger.
|
|
*
|
|
* Registers custom wp-cli commands exposed to the plugin.
|
|
*/
|
|
class PRAutoBlogger_WP_CLI_Commands {
|
|
|
|
/**
|
|
* Register WP-CLI commands.
|
|
*
|
|
* Called on plugins_loaded hook.
|
|
*/
|
|
public static function register(): void {
|
|
if ( ! defined( 'WP_CLI' ) || ! WP_CLI ) {
|
|
return;
|
|
}
|
|
|
|
// Command: wp prautoblogger opik:eval
|
|
\WP_CLI::add_command(
|
|
'prautoblogger generate',
|
|
array( self::class, 'generate_command' ),
|
|
array(
|
|
'shortdesc' => 'Queue a new article generation run on chained-cron checkpoints',
|
|
)
|
|
);
|
|
|
|
\WP_CLI::add_command(
|
|
'prautoblogger opik:eval',
|
|
array( self::class, 'opik_eval_command' ),
|
|
array(
|
|
'shortdesc' => 'Run Opik evals on the frozen dataset',
|
|
'synopsis' => array(
|
|
array(
|
|
'type' => 'assoc',
|
|
'name' => 'limit',
|
|
'description' => 'Max items to run (0 = all)',
|
|
'optional' => true,
|
|
'default' => '0',
|
|
),
|
|
array(
|
|
'type' => 'flag',
|
|
'name' => 'dry-run',
|
|
'description' => 'Skip Opik API push; score locally only',
|
|
'optional' => true,
|
|
),
|
|
),
|
|
)
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Run eval on the frozen dataset.
|
|
*
|
|
* @param array $args Positional args (unused).
|
|
* @param array $assoc_args Associative args: limit, dry-run.
|
|
*
|
|
* @return void
|
|
*/
|
|
public static function opik_eval_command( array $args, array $assoc_args ): void {
|
|
// Check if Opik is enabled.
|
|
if ( empty( PRAUTOBLOGGER_OPIK_API_KEY ) || empty( PRAUTOBLOGGER_OPIK_WORKSPACE ) ) {
|
|
if ( ! isset( $assoc_args['dry-run'] ) ) {
|
|
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_echo -- CLI output
|
|
echo "Warning: Opik is not configured. Running with --dry-run only.\n";
|
|
$assoc_args['dry-run'] = true;
|
|
}
|
|
}
|
|
|
|
$limit = absint( $assoc_args['limit'] ?? 0 );
|
|
$dry_run = isset( $assoc_args['dry-run'] );
|
|
|
|
$runner = new PRAutoBlogger_Opik_Eval_Runner();
|
|
$result = $runner->run( $limit, $dry_run );
|
|
|
|
exit( $result['items_run'] > 0 ? 0 : 1 );
|
|
}
|
|
|
|
/**
|
|
* Queue a new article generation run on chained-cron checkpoints.
|
|
*
|
|
* Routes through PRAutoBlogger_Generation_Checkpoint_Runner::kick_off()
|
|
* (same path as the board "New Article" button). Does NOT execute
|
|
* synchronously -- check the board or Activity Log for progress.
|
|
* This retires the `do_action("prautoblogger_manual_generation")` workaround.
|
|
*
|
|
* ## OPTIONS
|
|
*
|
|
* ## EXAMPLES
|
|
*
|
|
* wp prautoblogger generate
|
|
*
|
|
* @param array $args Positional args (unused).
|
|
* @param array $assoc_args Associative args (unused).
|
|
* @return void
|
|
*/
|
|
public static function generate_command( array $args, array $assoc_args ): void {
|
|
PRAutoBlogger_Generation_Checkpoint_Runner::kick_off();
|
|
\WP_CLI::success( 'Generation queued on chained-cron checkpoints. Check the board or Activity Log for progress.' );
|
|
}
|
|
}
|