CEO ask #5 complete: browsable paginated run list + full input/output inspection per pipeline stage. ## What was built ### Generations list (prautoblogger-gen-history) Hidden admin page (options.php-parent, priority 14) showing all pipeline runs newest first, 20 per page. Each row: article title (linked to dossier when a post exists), start date, status chip, distinct model(s), settled cost, duration. Queries bounded (LIMIT/OFFSET) — no unbounded SELECT *. New files: - includes/admin/class-gen-history-query.php — paginated run list + per-run I/O queries - includes/admin/class-gen-history-page.php — hidden admin page + asset enqueue - assets/css/gen-history.css, assets/js/gen-history.js — table + drill-down UI - templates/admin/gen-history-page.php — HTML template ### Per-step input + output drill-down (Stage I/O) 'Stage I/O' toggle opens an AJAX-loaded inline panel. For each generation_log stage: - input_system: system-role message content from generation_log.request_json - input_user: last user-role message from request_json (rendered instruction) - output: model response from run_stages.meta_json.output - output_pruned: true when meta_json present but output key absent (retention prune) New AJAX endpoint: prautoblogger_gen_run_io (manage_options + nonce) New file: includes/ajax/class-gen-run-io-handler.php ### gen-log INPUT/OUTPUT coverage verified - INPUT: generation_log.request_json stores the chat body WITHOUT the Authorization header (Request_Recorder captures body after build_body(), before headers are added). System + user message content extracted and surfaced. - OUTPUT: run_stages.meta_json.output is the LLM response text (Run_Stage_State::done()). Image/log-only stages (image_a, image_b, llm_research, image_prompt_rewrite) have no run_stages row; output is null, NOT pruned. Pruned outputs are flagged honestly. ### Dossier as entry point Runs with a linked post show a 'Dossier' button deep-linking into the existing dossier (which renders full per-stage I/O with editorial context). Stage I/O is complementary — works for failed/orphan runs and provides the same data in a lighter inline UI. ### Stage-list-driven Stage labels via Stage_Display_Map::label() — Phase 2b curate/seo appear automatically. ### Dead prautoblogger_pipeline_history endpoint Not dead — it IS used by pipeline-settings.js for prompt version history (M3 feature). Left in place. No dangling endpoint. ## M3 P2 sweep - Removed dead data-preview-nonce and data-diff-nonce HTML attrs from pipeline-settings-prompt-panel.php (JS uses prabPipeline.*Nonce from wp_localize_script, not data-* attrs — confirmed by grep). - Removed 3 redundant wp_create_nonce() calls from class-pipeline-settings-renderer.php (preview_nonce, history_nonce, diff_nonce keys that fed the now-removed dead attrs). - Updated CONTEXT.md: added M3 + M4 terminology tables. - Updated ARCHITECTURE.md: added ajax/ section to file tree; M3/M4 design notes. - Updated INFORMATION-ARCHITECTURE.md: prautoblogger-gen-history entry. ## Security - manage_options cap + prautoblogger_gen_run_io nonce on the AJAX endpoint. - All output esc_html()/esc_url() server-side before JSON-encoding. - JS renders prompt/response text via textContent — never innerHTML. - No writes from history UI; request_json never contains auth headers. ## Version: v0.25.0 → v0.26.0 Agent-Session: pipeline-settings-m4
166 lines
5.5 KiB
PHP
166 lines
5.5 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
/**
|
|
* phpcs:ignore WordPress.Files.FileName.InvalidClassFileName -- class naming convention differs from WordPress standard
|
|
*
|
|
* Registers and renders the Generation History admin page (M4).
|
|
*
|
|
* What: A browsable, paginated list of all previous generation runs —
|
|
* newest first, 20 per page. Each row shows the article title (when
|
|
* a post was produced), date, final run status, models used, total
|
|
* cost, and duration. "View dossier" links into the existing Article
|
|
* Dossier for full per-stage I/O detail (the dossier already renders
|
|
* input AND output for every stage). For failed/orphan runs (no post)
|
|
* a "Stage I/O" link opens the inline drill-down panel.
|
|
*
|
|
* Uses the canonical options.php-parent hidden-page pattern so the
|
|
* hookname is stable at registration time and request time (same
|
|
* design as the Dossier page — see CONVENTIONS.md §Hidden Admin Pages).
|
|
*
|
|
* Visible entry points:
|
|
* - PRAutoBlogger board "Generation History" link (nav added in M4).
|
|
* - PRAutoBlogger → Pipeline → History link (nav added in M4).
|
|
* - Direct URL: admin.php?page=prautoblogger-gen-history
|
|
*
|
|
* SECURITY: manage_options cap on render. AJAX drill-down uses a separate
|
|
* nonce (prautoblogger_gen_run_io) gated in Gen_Run_IO_Handler. The
|
|
* history list itself is read-only GET — no state changes. Output
|
|
* escaped in template via esc_html() / esc_url().
|
|
*
|
|
* Triggered by: PRAutoBlogger::register_admin_hooks() on `admin_menu` (priority 14).
|
|
* Dependencies: PRAutoBlogger_Gen_History_Query (list data),
|
|
* PRAutoBlogger_Dossier_Page (dossier URL builder).
|
|
*
|
|
* @see admin/class-gen-history-query.php -- List query + per-run I/O.
|
|
* @see ajax/class-gen-run-io-handler.php -- Per-run stage I/O AJAX.
|
|
* @see admin/class-dossier-page.php -- Dossier deep-link target.
|
|
* @see templates/admin/gen-history-page.php -- HTML template.
|
|
* @see ARCHITECTURE.md -- Admin pages table.
|
|
* @see CONVENTIONS.md -- §Hidden Admin Pages.
|
|
*/
|
|
class PRAutoBlogger_Gen_History_Page {
|
|
|
|
/** Admin page slug. */
|
|
public const PAGE_SLUG = 'prautoblogger-gen-history';
|
|
|
|
/**
|
|
* Canonical hidden-page parent (same pattern as Dossier_Page).
|
|
* Resolves hookname to `admin_page_{slug}` at both registration
|
|
* and request time — no $submenu manipulation required.
|
|
*/
|
|
public const PARENT_SLUG = 'options.php';
|
|
|
|
/** Nonce action for the gen-run I/O AJAX. */
|
|
public const IO_NONCE_ACTION = 'prautoblogger_gen_run_io';
|
|
|
|
/**
|
|
* Register the history page as a hidden admin page.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function on_register_menu(): void {
|
|
add_submenu_page(
|
|
self::PARENT_SLUG,
|
|
__( 'Generation History', 'prautoblogger' ),
|
|
__( 'Generation History', 'prautoblogger' ),
|
|
'manage_options',
|
|
self::PAGE_SLUG,
|
|
array( $this, 'render_page' )
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Render the generation history list page.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function render_page(): void {
|
|
if ( ! current_user_can( 'manage_options' ) ) {
|
|
return;
|
|
}
|
|
|
|
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only list page.
|
|
$page = isset( $_GET['paged'] ) ? max( 1, (int) $_GET['paged'] ) : 1;
|
|
$per_page = PRAutoBlogger_Gen_History_Query::PAGE_SIZE;
|
|
|
|
$query = new PRAutoBlogger_Gen_History_Query();
|
|
$result = $query->get_page( $page, $per_page );
|
|
$rows = $result['rows'];
|
|
$total = $result['total'];
|
|
$pages = max( 1, (int) ceil( $total / $per_page ) );
|
|
|
|
$pagination = array(
|
|
'current' => $page,
|
|
'total' => $pages,
|
|
'count' => $total,
|
|
'base' => admin_url( 'admin.php?page=' . self::PAGE_SLUG ),
|
|
);
|
|
|
|
include PRAUTOBLOGGER_PLUGIN_DIR . 'templates/admin/gen-history-page.php';
|
|
}
|
|
|
|
/**
|
|
* Enqueue assets for the generation history page.
|
|
*
|
|
* @param string $hook_suffix Current admin page hook suffix.
|
|
* @return void
|
|
*/
|
|
public function on_enqueue_assets( string $hook_suffix ): void {
|
|
if ( 'admin_page_' . self::PAGE_SLUG !== $hook_suffix ) {
|
|
return;
|
|
}
|
|
|
|
wp_enqueue_style(
|
|
'prautoblogger-admin',
|
|
PRAUTOBLOGGER_PLUGIN_URL . 'assets/css/admin.css',
|
|
array(),
|
|
PRAUTOBLOGGER_VERSION
|
|
);
|
|
|
|
wp_enqueue_style(
|
|
'prautoblogger-gen-history',
|
|
PRAUTOBLOGGER_PLUGIN_URL . 'assets/css/gen-history.css',
|
|
array( 'prautoblogger-admin' ),
|
|
PRAUTOBLOGGER_VERSION
|
|
);
|
|
|
|
wp_enqueue_script(
|
|
'prautoblogger-gen-history',
|
|
PRAUTOBLOGGER_PLUGIN_URL . 'assets/js/gen-history.js',
|
|
array(),
|
|
PRAUTOBLOGGER_VERSION,
|
|
true
|
|
);
|
|
|
|
wp_localize_script(
|
|
'prautoblogger-gen-history',
|
|
'prabGenHistory',
|
|
array(
|
|
'ajaxUrl' => admin_url( 'admin-ajax.php' ),
|
|
'action' => 'prautoblogger_gen_run_io',
|
|
'nonce' => wp_create_nonce( self::IO_NONCE_ACTION ),
|
|
'strings' => array(
|
|
'loading' => __( 'Loading…', 'prautoblogger' ),
|
|
'error' => __( 'Failed to load stage I/O — try again.', 'prautoblogger' ),
|
|
'noStages' => __( 'No generation log entries for this run.', 'prautoblogger' ),
|
|
'pruned' => __( '[Output pruned by retention policy]', 'prautoblogger' ),
|
|
'noOutput' => __( '[No output stored for this stage]', 'prautoblogger' ),
|
|
'noInput' => __( '[No request payload stored for this stage]', 'prautoblogger' ),
|
|
),
|
|
)
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Build the URL to the generation history page.
|
|
*
|
|
* @param int $page Optional page number.
|
|
* @return string Admin URL.
|
|
*/
|
|
public static function url( int $page = 1 ): string {
|
|
$base = admin_url( 'admin.php?page=' . self::PAGE_SLUG );
|
|
return $page > 1 ? $base . '&paged=' . $page : $base;
|
|
}
|
|
}
|