feat: Pipeline Settings M1 — per-step model picker, system instructions, agent prompts (v0.23.0)

Adds a new 'Pipeline' wp-admin submenu page (prautoblogger-pipeline) with a
step rail covering all LLM stages: Research, Analysis, Writer, Editorial, Image.

Per-step panels surface:
- The existing PRAutoBlogger_OpenRouter_Model_Field picker (no new dropdown) with
  stage-accurate cost-preview for each step.
- System-instructions editor + agent-prompt editor(s) bound to the versioned
  prompt registry. Saving creates a new immutable version; reset-to-default
  available; active version number shown per panel.
- Step params read from PRAutoBlogger_Prompt_Registry::defs() (read-only in M1).

Writer panel marks inactive sub-stage prompts based on current pipeline mode.

No existing Settings sections changed — both surfaces edit the same wp_options
and prompts table. Decomposition of AI Models / Content / Sources tabs is M2.

get_stages_for_setting() extended: prautoblogger_research_model → [research,
llm_research] and prautoblogger_image_model → [image_a, image_b] for
cost-preview accuracy.

New files (4 classes + 1 CSS + 1 JS + 2 templates, all <=300 lines):
  includes/admin/class-pipeline-settings-page.php
  includes/admin/class-pipeline-settings-renderer.php
  includes/admin/class-pipeline-settings-save-handler.php
  includes/admin/class-pipeline-settings-step-map.php
  assets/css/pipeline-settings.css
  assets/js/pipeline-settings.js
  templates/admin/pipeline-settings-page.php
  templates/admin/pipeline-settings-prompt-panel.php

Modified:
  includes/admin/fields/class-open-router-model-field.php
  includes/class-prautoblogger.php
  prautoblogger.php (v0.23.0)
  ARCHITECTURE.md / INFORMATION-ARCHITECTURE.md / CHANGELOG.md

No new wp_options; uninstall unchanged.

Agent-Session: pipeline-settings-m1
This commit is contained in:
PRAutoBlogger Engineer
2026-06-22 13:04:08 +00:00
parent a2af04f2c4
commit e6550e1cbf
14 changed files with 1154 additions and 2 deletions

View File

@@ -866,6 +866,35 @@ Kept here for history. Until v0.8.2 the default image backend was FLUX.1 schnell
### #15: Optional Cloudflare AI Gateway in front of OpenRouter ### #15: Optional Cloudflare AI Gateway in front of OpenRouter
We already use Cloudflare for DNS/CDN on peptiderepo.com, so layering AI Gateway in front of OpenRouter is zero marginal infrastructure. It gives us response caching (meaningful for repeated classification/scoring calls), a unified cost/latency dashboard, rate limiting, and provider fallback — all of which we would otherwise have to build ourselves to satisfy the CTO cost-tracking rules. Kept as an opt-in URL setting (`prautoblogger_ai_gateway_base_url`) so the plugin still works unchanged out of the box and can be bypassed instantly if the gateway misbehaves. The gateway is a transparent OpenRouter-compatible proxy; no new provider class is needed, and the response parsing path (`usage`, `choices[0].message.content`) is unchanged. We already use Cloudflare for DNS/CDN on peptiderepo.com, so layering AI Gateway in front of OpenRouter is zero marginal infrastructure. It gives us response caching (meaningful for repeated classification/scoring calls), a unified cost/latency dashboard, rate limiting, and provider fallback — all of which we would otherwise have to build ourselves to satisfy the CTO cost-tracking rules. Kept as an opt-in URL setting (`prautoblogger_ai_gateway_base_url`) so the plugin still works unchanged out of the box and can be bypassed instantly if the gateway misbehaves. The gateway is a transparent OpenRouter-compatible proxy; no new provider class is needed, and the response parsing path (`usage`, `choices[0].message.content`) is unchanged.
### #25: Pipeline Settings page — per-step model, prompts, params (v0.23.0, M1)
**Scope (M1 — additive):** A new "Pipeline" wp-admin submenu page
(`prautoblogger-pipeline`, slug `prautoblogger_page_prautoblogger-pipeline`) that
surfaces per-step configuration for every LLM stage. The page is ADDITIVE — the
existing Settings sections (AI Models, Content, Sources) remain in place. Decomposition
into stage-exclusive panels is M2.
**Classes:** `PRAutoBlogger_Pipeline_Settings_Page` (registration + asset enqueue),
`PRAutoBlogger_Pipeline_Settings_Renderer` (view data assembly + template include),
`PRAutoBlogger_Pipeline_Settings_Save_Handler` (nonce + capability + sanitize + write),
`PRAutoBlogger_Pipeline_Settings_Step_Map` (canonical step definitions + key allowlists).
**Model picker reuse:** `PRAutoBlogger_OpenRouter_Model_Field::render()` is called
directly — no fork, no new dropdown. The stage map in `get_stages_for_setting()` was
extended to include `prautoblogger_research_model → [research, llm_research]` and
`prautoblogger_image_model → [image_a, image_b]` so cost-preview is stage-accurate.
**Prompt writes:** Saving a prompt creates a new immutable row in `wp_prautoblogger_prompts`
via `PRAutoBlogger_Prompt_Registry_Writer::create_version()` and activates it.
Only the keys listed in `PRAutoBlogger_Pipeline_Settings_Step_Map::allowed_prompt_keys()`
may be updated through this page (allowlist enforced in the save handler).
**Security:** `manage_options` capability check + nonce verification on every POST.
Prompt bodies are sanitized with `sanitize_textarea_field()`.
**No new options:** M1 adds no persistent `wp_option` keys. Uninstall unchanged.
--- ---
### #22: Pipeline v2 Phase 1 substrate (v0.18.0, db 1.2.0, June 2026) ### #22: Pipeline v2 Phase 1 substrate (v0.18.0, db 1.2.0, June 2026)

View File

@@ -5,6 +5,27 @@ All notable changes to PRAutoBlogger will be documented in this file.
Format follows [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), Format follows [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project uses [Semantic Versioning](https://semver.org/). and this project uses [Semantic Versioning](https://semver.org/).
## [0.23.0] - 2026-06-22
### Added
- **Pipeline Settings (M1 — additive):** New "Pipeline" wp-admin submenu page
(`prautoblogger-pipeline`) with a step rail covering all LLM stages: Research,
Analysis, Writer, Editorial, Image. Per-step panels expose the existing model
picker (`PRAutoBlogger_OpenRouter_Model_Field`), system-instruction editor, and
agent-prompt editor(s) — all bound to the live versioned prompt registry
(`PRAutoBlogger_Prompt_Registry`). Saving a prompt creates a new immutable version;
reset-to-default available. Active version shown per panel. Writer panel marks
inactive sub-stage prompts. No existing Settings sections changed in M1 (both
surfaces edit the same options / prompts table).
- **`get_stages_for_setting()` extended:** `prautoblogger_research_model →
[research, llm_research]` and `prautoblogger_image_model → [image_a, image_b]`
added so cost-preview on the Pipeline page reflects stage-accurate historical
token usage.
- New files: `includes/admin/class-pipeline-settings-page.php`,
`class-pipeline-settings-renderer.php`, `class-pipeline-settings-save-handler.php`,
`class-pipeline-settings-step-map.php`; `assets/css/pipeline-settings.css`;
`assets/js/pipeline-settings.js`; `templates/admin/pipeline-settings-page.php`.
## [Unreleased - Internal] ## [Unreleased - Internal]
### Internal ### Internal

View File

@@ -11,6 +11,7 @@ Maintained per DoD v1.1.0 (same-PR update rule).
|------|-------|----------|---------| |------|-------|----------|---------|
| `prautoblogger-settings` | `PRAutoBlogger_Admin_Page` | `admin-page.php` | Main settings (schedule, models, budget, board limits) | | `prautoblogger-settings` | `PRAutoBlogger_Admin_Page` | `admin-page.php` | Main settings (schedule, models, budget, board limits) |
| `prautoblogger-board` | `PRAutoBlogger_Board_Page` | `board-page.php` | Kanban board: Generating / Failed / In Review / Published columns. New Article button (v0.21.0). | | `prautoblogger-board` | `PRAutoBlogger_Board_Page` | `board-page.php` | Kanban board: Generating / Failed / In Review / Published columns. New Article button (v0.21.0). |
| `prautoblogger-pipeline` | `PRAutoBlogger_Pipeline_Settings_Page` | `pipeline-settings-page.php` | Per-step pipeline config: model picker, system instructions, agent prompts, params (M1, v0.23.0). |
| `prautoblogger-articles` | `PRAutoBlogger_Articles_Page` | `articles-page.php` | Paginated list of all articles/runs | | `prautoblogger-articles` | `PRAutoBlogger_Articles_Page` | `articles-page.php` | Paginated list of all articles/runs |
| `prautoblogger-dossier` | `PRAutoBlogger_Dossier_Page` | `dossier-page.php` | Per-article generation log + stage edit/re-run (M3) | | `prautoblogger-dossier` | `PRAutoBlogger_Dossier_Page` | `dossier-page.php` | Per-article generation log + stage edit/re-run (M3) |
| `prautoblogger-ideas` | `PRAutoBlogger_Ideas_Browser` | `ideas-browser.php` | Analysis results browser with per-idea generation | | `prautoblogger-ideas` | `PRAutoBlogger_Ideas_Browser` | `ideas-browser.php` | Analysis results browser with per-idea generation |

View File

@@ -0,0 +1,181 @@
/**
* Pipeline Settings page styles.
*
* Design language: light mode, teal #1B8A92 accent, IBM Plex Mono for
* numerics/code, wp-admin card shadow pattern. Extends admin.css.
*
* @see admin/class-pipeline-settings-page.php — Enqueues this file.
*/
/* ── Layout ── */
.pab-pipeline-wrap { max-width: 1200px; }
.pab-pipeline-layout {
display: grid;
grid-template-columns: 200px 1fr;
gap: 0;
background: #fff;
border: 1px solid #e0e0e0;
border-radius: 6px;
box-shadow: 0 1px 4px rgba(0,0,0,.06);
margin-top: 16px;
overflow: hidden;
}
/* ── Step rail ── */
.pab-step-rail {
background: #f7f9fa;
border-right: 1px solid #e0e0e0;
padding: 8px 0;
}
.pab-step-btn {
display: flex;
align-items: center;
gap: 8px;
padding: 10px 14px;
text-decoration: none;
color: #3c434a;
font-size: 13px;
border-left: 3px solid transparent;
transition: background .12s, border-color .12s;
}
.pab-step-btn:hover {
background: #edf5f6;
color: #1B8A92;
border-left-color: #a8d8db;
}
.pab-step-btn--active {
background: #e6f4f5;
color: #1B8A92;
font-weight: 600;
border-left-color: #1B8A92;
}
.pab-step-num {
display: inline-flex;
align-items: center;
justify-content: center;
width: 22px;
height: 22px;
background: #1B8A92;
color: #fff;
border-radius: 50%;
font-size: 11px;
font-family: 'IBM Plex Mono', 'Courier New', monospace;
flex-shrink: 0;
}
.pab-step-btn:not(.pab-step-btn--active) .pab-step-num {
background: #c3cdd4;
}
.pab-step-icon { color: inherit; font-size: 16px !important; flex-shrink: 0; }
.pab-step-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* ── Step panel ── */
.pab-step-panel {
padding: 24px 28px;
overflow-y: auto;
}
.pab-panel-header { margin-bottom: 20px; border-bottom: 1px solid #e8ecef; padding-bottom: 14px; }
.pab-panel-header h2 { margin: 0 0 4px; font-size: 18px; color: #1d2327; }
.pab-panel-desc { margin: 4px 0 0; color: #646970; font-size: 13px; }
/* ── Sections ── */
.pab-section { margin-bottom: 28px; }
.pab-section:not(:last-child) { border-bottom: 1px solid #f0f0f1; padding-bottom: 24px; }
.pab-section-title {
font-size: 14px;
font-weight: 600;
color: #1d2327;
margin: 0 0 10px;
display: flex;
align-items: center;
gap: 8px;
}
/* ── Model picker section ── */
.pab-model-picker-wrap { margin-bottom: 10px; }
.pab-model-form { max-width: 520px; }
/* ── Prompt editors ── */
.pab-prompt-editor {
width: 100%;
font-family: 'IBM Plex Mono', 'Courier New', monospace;
font-size: 12px;
line-height: 1.6;
background: #fafbfc;
border: 1px solid #d0d5dd;
border-radius: 4px;
padding: 10px 12px;
resize: vertical;
box-sizing: border-box;
color: #1d2327;
}
.pab-prompt-editor:focus {
border-color: #1B8A92;
box-shadow: 0 0 0 2px rgba(27,138,146,.12);
outline: none;
}
.pab-prompt-form { max-width: 820px; }
.pab-prompt-actions { display: flex; gap: 8px; margin-top: 8px; align-items: center; }
.pab-btn-reset { color: #9b1c1c; border-color: #f5c6c6; }
.pab-btn-reset:hover { background: #fef2f2; border-color: #e53e3e; color: #9b1c1c; }
/* ── Params table ── */
.pab-params-table { border-collapse: collapse; font-size: 13px; }
.pab-params-table th, .pab-params-table td { text-align: left; padding: 4px 12px 4px 0; vertical-align: top; }
.pab-params-table th { color: #646970; font-weight: 500; min-width: 140px; }
.pab-mono {
font-family: 'IBM Plex Mono', 'Courier New', monospace;
font-size: 12px;
background: #f3f4f6;
padding: 2px 6px;
border-radius: 3px;
}
/* ── Badges ── */
.pab-version-badge {
display: inline-flex;
align-items: center;
background: #e6f4f5;
color: #1B8A92;
font-size: 11px;
font-family: 'IBM Plex Mono', 'Courier New', monospace;
font-weight: 600;
padding: 1px 6px;
border-radius: 10px;
border: 1px solid #b2e0e3;
}
.pab-badge { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; padding: 2px 8px; border-radius: 10px; font-weight: 500; }
.pab-badge-ok { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.pab-badge-warn { background: #fffbeb; color: #92400e; border: 1px solid #fcd34d; }
/* ── Global context note ── */
.pab-global-context-note {
display: flex;
align-items: center;
gap: 8px;
background: #f0f9fa;
border: 1px solid #b2e0e3;
border-radius: 4px;
padding: 8px 14px;
margin: 12px 0 0;
font-size: 13px;
color: #1d4f52;
}
/* ── Misc ── */
.pab-field-note { color: #646970; font-size: 12px; margin: 6px 0 10px; }
.pab-version-meta { color: #646970; font-size: 12px; margin: -4px 0 8px; }
.pab-inactive-note {
display: flex;
align-items: center;
gap: 6px;
color: #a18a2f;
background: #fffde7;
border: 1px solid #ffe082;
border-radius: 4px;
padding: 6px 12px;
font-size: 12px;
margin-bottom: 8px;
}

View File

@@ -0,0 +1,34 @@
/**
* Pipeline Settings page — step rail and prompt editor interactions.
*
* Responsibilities:
* - Confirm before resetting a prompt to default (redundant safety; the
* PHP onclick already handles it, but JS enhances UX).
* - Wire the model-picker hidden input so the save_model form picks up
* the newly selected model id from the popup.
*
* @see admin/class-pipeline-settings-page.php — Enqueues this script.
* @see assets/js/model-picker.js — Handles the picker popup.
*/
/* global jQuery */
( function ( $ ) {
'use strict';
$( function () {
// When the model picker JS selects a model, update the hidden
// 'model_id' input in the same .pab-model-form so the save form
// carries the chosen value on submit.
$( document ).on( 'prautoblogger:model_selected', function ( e, data ) {
var $form = $( '.pab-model-form' );
var $hidden = $form.find( 'input[name="model_id"]' );
if ( 0 === $hidden.length ) {
$hidden = $( '<input type="hidden" name="model_id" />' );
$form.append( $hidden );
}
$hidden.val( data.model_id || data.id || '' );
} );
} );
}( jQuery ) );

View File

@@ -0,0 +1,112 @@
<?php
declare(strict_types=1);
/**
* phpcs:ignore WordPress.Files.FileName.InvalidClassFileName -- class naming convention differs from WordPress standard
*
* Registers the Pipeline Settings wp-admin submenu page and its assets.
*
* What: Adds a "Pipeline" submenu under the PRAutoBlogger parent menu so
* operators can configure per-step model, system instructions, agent
* prompts, and parameters for every LLM stage in one place. This
* page is ADDITIVE in M1 — the existing Settings sections remain
* unchanged and both surfaces edit the same wp_options / prompts
* table. Decomposition of redundant tabs is M2.
* Who calls it: PRAutoBlogger::register_admin_hooks() via add_action
* ('admin_menu', ..., 13) and ('admin_enqueue_scripts', ...).
* Dependencies: PRAutoBlogger_Pipeline_Settings_Save_Handler (save),
* PRAutoBlogger_Pipeline_Settings_Renderer (render).
*
* @see admin/class-pipeline-settings-renderer.php — Step rail + panel HTML.
* @see admin/class-pipeline-settings-save-handler.php — nonce + save logic.
* @see admin/class-admin-page.php — Parent menu registration (priority 10).
* @see ARCHITECTURE.md — Admin pages table.
* @see INFORMATION-ARCHITECTURE.md — Admin page slug registry.
*/
class PRAutoBlogger_Pipeline_Settings_Page {
/** wp-admin page slug. */
public const PAGE_SLUG = 'prautoblogger-pipeline';
/** Nonce action for saving prompt edits on this page. */
public const NONCE_ACTION = 'prautoblogger_pipeline_save';
/** Nonce field name posted with the save form. */
public const NONCE_FIELD = 'prautoblogger_pipeline_nonce';
/**
* Register the Pipeline submenu page under the PRAutoBlogger parent menu.
*
* Priority 13 — after board (11), dossier (12). The parent slug must be
* registered at priority 10 by PRAutoBlogger_Admin_Page::on_register_menu()
* before any submenu can be attached.
*
* @return void
*/
public function on_register_menu(): void {
add_submenu_page(
'prautoblogger-settings',
__( 'Pipeline Settings', 'prautoblogger' ),
__( 'Pipeline', 'prautoblogger' ),
'manage_options',
self::PAGE_SLUG,
array( $this, 'render_page' )
);
}
/**
* Enqueue CSS / JS required by the Pipeline Settings page.
*
* Reuses the existing admin + model-picker asset pairs; adds a small
* pipeline-specific stylesheet and script.
*
* @param string $hook_suffix Current admin page hook suffix.
* @return void
*/
public function on_enqueue_assets( string $hook_suffix ): void {
if ( 'prautoblogger_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-model-picker', PRAUTOBLOGGER_PLUGIN_URL . 'assets/css/model-picker.css', array( 'prautoblogger-admin' ), PRAUTOBLOGGER_VERSION );
wp_enqueue_style( 'prautoblogger-pipeline', PRAUTOBLOGGER_PLUGIN_URL . 'assets/css/pipeline-settings.css', array( 'prautoblogger-admin' ), PRAUTOBLOGGER_VERSION );
wp_enqueue_script( 'prautoblogger-admin', PRAUTOBLOGGER_PLUGIN_URL . 'assets/js/admin.js', array( 'jquery' ), PRAUTOBLOGGER_VERSION, true );
wp_enqueue_script( 'prautoblogger-model-picker', PRAUTOBLOGGER_PLUGIN_URL . 'assets/js/model-picker.js', array( 'jquery', 'prautoblogger-admin' ), PRAUTOBLOGGER_VERSION, true );
wp_enqueue_script( 'prautoblogger-pipeline', PRAUTOBLOGGER_PLUGIN_URL . 'assets/js/pipeline-settings.js', array( 'jquery', 'prautoblogger-admin' ), PRAUTOBLOGGER_VERSION, true );
wp_localize_script(
'prautoblogger-admin',
'prautobloggerAdmin',
array(
'ajaxUrl' => admin_url( 'admin-ajax.php' ),
'adminUrl' => admin_url(),
'siteUrl' => home_url( '/' ),
'modelsNonce' => wp_create_nonce( 'prautoblogger_get_models' ),
'imageModels' => PRAutoBlogger_Settings_Fields_Extended::get_image_models(),
)
);
}
/**
* Render the Pipeline Settings page.
*
* Capability check first; then delegate to the save handler (processes
* POST before output starts) and the renderer (assembles view data and
* includes the template).
*
* @return void
*/
public function render_page(): void {
if ( ! current_user_can( 'manage_options' ) ) {
wp_die( esc_html__( 'You do not have permission to access this page.', 'prautoblogger' ) );
}
// Process any pending save before output begins.
$save_result = PRAutoBlogger_Pipeline_Settings_Save_Handler::maybe_process_save();
$renderer = new PRAutoBlogger_Pipeline_Settings_Renderer();
$renderer->render( $save_result );
}
}

View File

@@ -0,0 +1,139 @@
<?php
declare(strict_types=1);
/**
* phpcs:ignore WordPress.Files.FileName.InvalidClassFileName -- class naming convention differs from WordPress standard
*
* Assembles view data and renders the Pipeline Settings page template.
*
* What: Reads current option values, active prompt versions, and registry
* params, then passes a typed data structure to the pipeline-settings-
* page.php template. The renderer contains NO business logic — it only
* reads and shapes data for the view. All output is escaped by the
* template or by helper methods on this class.
* Who calls it: PRAutoBlogger_Pipeline_Settings_Page::render_page() after
* the save handler runs.
* Dependencies: PRAutoBlogger_Pipeline_Settings_Step_Map (step list),
* PRAutoBlogger_Prompt_Registry (active row, versions, defs),
* PRAutoBlogger_OpenRouter_Model_Field (model picker render),
* PRAutoBlogger_Cost_Reporter (monthly spend header).
*
* @see admin/class-pipeline-settings-step-map.php — Step + key definitions.
* @see admin/fields/class-open-router-model-field.php — Model picker component.
* @see core/class-prompt-registry.php — Registry read API.
* @see templates/admin/pipeline-settings-page.php — HTML template.
*/
class PRAutoBlogger_Pipeline_Settings_Renderer {
/**
* Build the view-data array and include the page template.
*
* @param array{status: string, message: string} $save_result Result from save handler.
* @return void
*/
public function render( array $save_result ): void {
$active_step = isset( $_GET['step'] ) ? sanitize_key( $_GET['step'] ) : 'research';
$steps = PRAutoBlogger_Pipeline_Settings_Step_Map::steps();
$step = PRAutoBlogger_Pipeline_Settings_Step_Map::find( $active_step ) ?? $steps[0];
$view = array(
'steps' => $steps,
'active_step' => $step,
'save_result' => $save_result,
'nonce_field' => PRAutoBlogger_Pipeline_Settings_Page::NONCE_FIELD,
'nonce_action' => PRAutoBlogger_Pipeline_Settings_Page::NONCE_ACTION,
'page_slug' => PRAutoBlogger_Pipeline_Settings_Page::PAGE_SLUG,
'step_data' => $this->build_step_data( $step ),
);
include PRAUTOBLOGGER_PLUGIN_DIR . 'templates/admin/pipeline-settings-page.php';
}
/**
* Assemble all data needed to render a single step panel.
*
* @param array<string, mixed> $step Step definition from Step_Map::steps().
* @return array<string, mixed> View data for the step panel.
*/
public function build_step_data( array $step ): array {
$defs = PRAutoBlogger_Prompt_Registry::defs();
$all_versions = PRAutoBlogger_Prompt_Registry_Writer::list_versions( $step['system_key'] ?? '' );
$active_versions_map = PRAutoBlogger_Prompt_Registry::active_versions();
// Model info.
$model_option = (string) ( $step['model_option'] ?? '' );
$model_value = '' !== $model_option ? (string) get_option( $model_option, '' ) : '';
// System prompt.
$system_key = (string) ( $step['system_key'] ?? '' );
$system_data = $this->build_prompt_panel_data( $system_key, $defs, $active_versions_map );
// Agent/user prompts.
$agent_panels = array();
foreach ( ( $step['agent_keys'] ?? array() ) as $key ) {
$agent_panels[ $key ] = $this->build_prompt_panel_data( $key, $defs, $active_versions_map );
}
// Params from the def for the system key (canonical params are on system).
$params = isset( $defs[ $system_key ] ) ? ( $defs[ $system_key ]['params'] ?? array() ) : array();
return array(
'step' => $step,
'model_option' => $model_option,
'model_value' => $model_value,
'system' => $system_data,
'agent_panels' => $agent_panels,
'params' => $params,
);
}
/**
* Build display data for a single prompt key's edit panel.
*
* @param string $key Registry key.
* @param array<string, array{body: string, model_option: ?string, params: array<string, mixed>}> $defs All defs.
* @param array<string, int> $active_versions_map key => active version.
* @return array<string, mixed>
*/
private function build_prompt_panel_data( string $key, array $defs, array $active_versions_map ): array {
if ( '' === $key ) {
return array();
}
$active_row = PRAutoBlogger_Prompt_Registry::get_active( $key );
$active_version = $active_versions_map[ $key ] ?? 0;
$body = null !== $active_row ? (string) $active_row['body'] : (string) PRAutoBlogger_Prompt_Registry::default_body( $key );
$default_body = (string) PRAutoBlogger_Prompt_Registry::default_body( $key );
$is_default = ( $body === $default_body );
$created_at = null !== $active_row ? (string) $active_row['created_at'] : '';
$author = null !== $active_row ? (string) $active_row['author'] : 'seed';
$versions = PRAutoBlogger_Prompt_Registry_Writer::list_versions( $key );
return array(
'key' => $key,
'body' => $body,
'default_body' => $default_body,
'is_default' => $is_default,
'active_version' => $active_version,
'created_at' => $created_at,
'author' => $author,
'version_count' => count( $versions ),
);
}
/**
* Render the model picker for a step using the existing field component.
*
* Public so the template can call it directly. Keeps markup generation
* in one place and avoids duplicating the picker rendering logic.
*
* @param string $model_option wp_option name (e.g. 'prautoblogger_writing_model').
* @param string $model_value Current model id stored in the option.
* @param array<string, mixed> $field_args Field args forwarded to the picker.
* @return void Side effect: outputs HTML.
*/
public function render_model_picker( string $model_option, string $model_value, array $field_args ): void {
PRAutoBlogger_OpenRouter_Model_Field::render( $model_option, $model_value, $field_args );
}
}

View File

@@ -0,0 +1,185 @@
<?php
declare(strict_types=1);
/**
* phpcs:ignore WordPress.Files.FileName.InvalidClassFileName -- class naming convention differs from WordPress standard
*
* Processes form submissions on the Pipeline Settings page.
*
* What: A stateless save handler for the Pipeline Settings page. On a valid
* POST it verifies the nonce, checks capabilities, sanitizes inputs,
* and either:
* - saves the model option via update_option(), or
* - creates a new immutable prompt version in the registry
* (PRAutoBlogger_Prompt_Registry_Writer::create_version()).
* Saving a prompt NEVER mutates the existing version — it creates a
* new one (the registry's core invariant). A "reset to default" POST
* creates a new version with the canonical default body.
* Prompt keys arrive as a slug-encoded form value that is matched
* against the allowlist; the raw POST value is never used as a key
* before allowlist validation.
* Returns a result array that render_page() passes to the template.
* Who calls it: PRAutoBlogger_Pipeline_Settings_Page::render_page() before
* any output is produced.
* Dependencies: PRAutoBlogger_Pipeline_Settings_Step_Map (key allowlists),
* PRAutoBlogger_Prompt_Registry_Writer (create_version),
* PRAutoBlogger_Prompt_Registry (default_body, flush_cache).
*
* @see admin/class-pipeline-settings-step-map.php — Allowed key definitions.
* @see core/class-prompt-registry-writer.php — Immutable version writes.
* @see core/class-prompt-registry.php — Read side + default_body.
*/
class PRAutoBlogger_Pipeline_Settings_Save_Handler {
/**
* Inspect the current request and process the save when it is a valid
* Pipeline Settings form submission.
*
* Side effects: may call update_option() or
* PRAutoBlogger_Prompt_Registry_Writer::create_version();
* returns error on nonce/cap failure.
*
* @return array{status: string, message: string} 'idle'|'saved'|'error'.
*/
public static function maybe_process_save(): array {
$idle = array( 'status' => 'idle', 'message' => '' );
if ( 'POST' !== $_SERVER['REQUEST_METHOD'] ) {
return $idle;
}
// phpcs:ignore WordPress.Security.NonceVerification.Missing
if ( empty( $_POST[ PRAutoBlogger_Pipeline_Settings_Page::NONCE_FIELD ] ) ) {
return $idle;
}
// Capability check.
if ( ! current_user_can( 'manage_options' ) ) {
return array( 'status' => 'error', 'message' => __( 'You do not have permission to save settings.', 'prautoblogger' ) );
}
// Nonce verification.
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
if ( ! wp_verify_nonce( wp_unslash( $_POST[ PRAutoBlogger_Pipeline_Settings_Page::NONCE_FIELD ] ), PRAutoBlogger_Pipeline_Settings_Page::NONCE_ACTION ) ) {
return array( 'status' => 'error', 'message' => __( 'Security check failed. Please reload and try again.', 'prautoblogger' ) );
}
$action = isset( $_POST['pipeline_action'] ) ? sanitize_key( $_POST['pipeline_action'] ) : '';
if ( 'save_model' === $action ) {
return self::handle_model_save();
}
if ( 'save_prompt' === $action || 'reset_prompt' === $action ) {
return self::handle_prompt_save( $action );
}
return $idle;
}
/**
* Persist a model selection for one step.
*
* Only the allowlisted model option names from Step_Map may be updated.
*
* @return array{status: string, message: string}
*/
private static function handle_model_save(): array {
$option_name = isset( $_POST['model_option'] ) ? sanitize_key( $_POST['model_option'] ) : '';
$model_id = isset( $_POST['model_id'] ) ? sanitize_text_field( wp_unslash( $_POST['model_id'] ) ) : '';
if ( ! in_array( $option_name, PRAutoBlogger_Pipeline_Settings_Step_Map::allowed_model_options(), true ) ) {
return array( 'status' => 'error', 'message' => __( 'Unknown model option.', 'prautoblogger' ) );
}
// For the image model, delegate to the same sanitizer logic as
// PRAutoBlogger_Settings_Sanitizer to derive + store provider consistently.
if ( 'prautoblogger_image_model' === $option_name ) {
$candidate = sanitize_text_field( $model_id );
$provider = PRAutoBlogger_Image_Model_Registry::provider_for( $candidate );
if ( '' !== $provider ) {
update_option( 'prautoblogger_image_provider', $provider );
update_option( $option_name, $candidate );
return array( 'status' => 'saved', 'message' => __( 'Model saved.', 'prautoblogger' ) );
}
return array( 'status' => 'error', 'message' => __( 'Image model not recognised. Selection unchanged.', 'prautoblogger' ) );
}
update_option( $option_name, sanitize_text_field( $model_id ) );
return array( 'status' => 'saved', 'message' => __( 'Model saved.', 'prautoblogger' ) );
}
/**
* Create a new prompt version (or reset to default) in the registry.
*
* The prompt key is received as a slug (dots replaced with hyphens in the
* form value). We match the slug against the allowlist by resolving each
* allowed key to its slug form — this avoids any reverse-parsing ambiguity
* for keys that contain underscores (e.g. content.single_pass).
*
* Prompt bodies are treated as privileged — only sanitize_textarea_field()
* is applied to strip any script injection, but content is not further
* mangled — the operator is intentionally writing LLM instructions.
*
* @param string $action 'save_prompt' or 'reset_prompt'.
* @return array{status: string, message: string}
*/
private static function handle_prompt_save( string $action ): array {
// The form sends the key with dots replaced by hyphens (HTML-safe slug).
$slug = isset( $_POST['prompt_key'] ) ? sanitize_key( wp_unslash( $_POST['prompt_key'] ) ) : '';
// Resolve slug back to the real registry key via allowlist lookup.
$prompt_key = self::resolve_key_from_slug( $slug );
if ( null === $prompt_key ) {
return array( 'status' => 'error', 'message' => __( 'Unknown prompt key.', 'prautoblogger' ) );
}
if ( 'reset_prompt' === $action ) {
$body = PRAutoBlogger_Prompt_Registry::default_body( $prompt_key );
if ( null === $body ) {
return array( 'status' => 'error', 'message' => __( 'No default found for this prompt key.', 'prautoblogger' ) );
}
$author = 'reset:pipeline-ui';
} else {
$raw_body = isset( $_POST['prompt_body'] ) ? wp_unslash( $_POST['prompt_body'] ) : '';
$body = sanitize_textarea_field( $raw_body );
$author = 'pipeline-ui:' . ( wp_get_current_user()->user_login ?? 'admin' );
}
$version = PRAutoBlogger_Prompt_Registry_Writer::create_version(
$prompt_key,
$body,
null,
null,
$author,
true
);
if ( 0 === $version ) {
return array( 'status' => 'error', 'message' => __( 'Failed to save prompt. Is the prompts table available?', 'prautoblogger' ) );
}
return array(
'status' => 'saved',
// translators: %1$s = prompt key, %2$d = new version number.
'message' => sprintf( __( 'Saved %1$s as version %2$d.', 'prautoblogger' ), esc_html( $prompt_key ), $version ),
);
}
/**
* Resolve a URL/form slug back to the canonical registry key.
*
* Each allowed key is converted to a slug (dots → hyphens, everything
* lowercased by sanitize_key) and compared against the submitted value.
* No string-reverse parsing — only allowlist membership determines a match.
*
* @param string $slug Slug as received from the form (after sanitize_key).
* @return string|null Canonical key, or null when not in the allowlist.
*/
private static function resolve_key_from_slug( string $slug ): ?string {
foreach ( PRAutoBlogger_Pipeline_Settings_Step_Map::allowed_prompt_keys() as $key ) {
if ( sanitize_key( str_replace( '.', '-', $key ) ) === $slug ) {
return $key;
}
}
return null;
}
}

View File

@@ -0,0 +1,142 @@
<?php
declare(strict_types=1);
/**
* phpcs:ignore WordPress.Files.FileName.InvalidClassFileName -- class naming convention differs from WordPress standard
*
* Canonical definition of every LLM pipeline step shown in Pipeline Settings.
*
* What: A single source of truth for step metadata: display name, icon,
* model option key, registry prompt keys (system + agent/user),
* and parameters sourced from PRAutoBlogger_Prompt_Registry::defs().
* Non-LLM steps (Scoring, Publish) are intentionally absent — they
* have no model/prompt config to surface.
* Who calls it: PRAutoBlogger_Pipeline_Settings_Renderer (step rail + panels),
* PRAutoBlogger_Pipeline_Settings_Save_Handler (key validation).
* Dependencies: PRAutoBlogger_Prompt_Registry::defs() for param snapshots.
*
* @see admin/class-pipeline-settings-renderer.php — Consumes step definitions.
* @see core/class-prompt-defaults.php — Canonical prompt bodies.
* @see core/class-prompt-defaults-editorial.php — Editor/research/image bodies.
*/
class PRAutoBlogger_Pipeline_Settings_Step_Map {
/**
* Ordered list of LLM step definitions for the Pipeline Settings UI.
*
* Each entry is an associative array with:
* id string Machine identifier (URL param / JS key).
* label string Display name shown in the step rail.
* icon string Dashicons class for the step button.
* model_option string|null wp_option that controls the model for this step.
* capability string 'text→text' or 'image_generation' — drives picker.
* system_key string|null Registry key for the system prompt.
* agent_keys string[] Registry keys for agent/user prompts (ordered).
* description string One-line note shown above the step panel.
*
* @return array<int, array<string, mixed>>
*/
public static function steps(): array {
return array(
array(
'id' => 'research',
'label' => __( 'Research', 'prautoblogger' ),
'icon' => 'dashicons-search',
'model_option' => 'prautoblogger_research_model',
'capability' => 'text→text',
'system_key' => 'research.system',
'agent_keys' => array(),
'description' => __( 'LLM deep-research call. The user-side research brief is a setting below, not a registry prompt.', 'prautoblogger' ),
),
array(
'id' => 'analysis',
'label' => __( 'Analysis', 'prautoblogger' ),
'icon' => 'dashicons-chart-bar',
'model_option' => 'prautoblogger_analysis_model',
'capability' => 'text→text',
'system_key' => 'analysis.system',
'agent_keys' => array( 'analysis.user' ),
'description' => __( 'Scores and selects ideas from research findings.', 'prautoblogger' ),
),
array(
'id' => 'writer',
'label' => __( 'Writer', 'prautoblogger' ),
'icon' => 'dashicons-edit',
'model_option' => 'prautoblogger_writing_model',
'capability' => 'text→text',
'system_key' => 'content.system',
'agent_keys' => array( 'content.single_pass', 'content.outline', 'content.draft', 'content.polish' ),
'description' => __( 'Generates article content. Active sub-stages depend on the Writing Pipeline mode setting.', 'prautoblogger' ),
),
array(
'id' => 'editorial',
'label' => __( 'Editorial', 'prautoblogger' ),
'icon' => 'dashicons-admin-comments',
'model_option' => 'prautoblogger_editor_model',
'capability' => 'text→text',
'system_key' => 'editor.system',
'agent_keys' => array( 'editor.review' ),
'description' => __( 'Single-pass editorial review — approves, revises, or rejects the draft.', 'prautoblogger' ),
),
array(
'id' => 'image',
'label' => __( 'Image', 'prautoblogger' ),
'icon' => 'dashicons-format-image',
'model_option' => 'prautoblogger_image_model',
'capability' => 'image_generation',
'system_key' => 'image.rewriter_system',
'agent_keys' => array( 'image.style_template' ),
'description' => __( 'Image prompt rewriter + diffusion generation. The rewriter LLM uses the Analysis model.', 'prautoblogger' ),
),
);
}
/**
* Return a single step definition by its id, or null when not found.
*
* @param string $step_id Machine identifier of the step.
* @return array<string, mixed>|null
*/
public static function find( string $step_id ): ?array {
foreach ( self::steps() as $step ) {
if ( $step['id'] === $step_id ) {
return $step;
}
}
return null;
}
/**
* All registry keys that the save handler is permitted to update via
* the Pipeline Settings page. Any submitted key not in this list is rejected.
*
* @return string[]
*/
public static function allowed_prompt_keys(): array {
$keys = array();
foreach ( self::steps() as $step ) {
if ( ! empty( $step['system_key'] ) ) {
$keys[] = $step['system_key'];
}
foreach ( ( $step['agent_keys'] ?? array() ) as $k ) {
$keys[] = $k;
}
}
return array_unique( $keys );
}
/**
* All model option names that the save handler may update.
*
* @return string[]
*/
public static function allowed_model_options(): array {
$opts = array();
foreach ( self::steps() as $step ) {
if ( ! empty( $step['model_option'] ) ) {
$opts[] = $step['model_option'];
}
}
return array_unique( $opts );
}
}

View File

@@ -141,6 +141,8 @@ class PRAutoBlogger_OpenRouter_Model_Field {
'prautoblogger_analysis_model' => array( 'analysis' ), 'prautoblogger_analysis_model' => array( 'analysis' ),
'prautoblogger_writing_model' => array( 'outline', 'draft', 'polish' ), 'prautoblogger_writing_model' => array( 'outline', 'draft', 'polish' ),
'prautoblogger_editor_model' => array( 'review' ), 'prautoblogger_editor_model' => array( 'review' ),
'prautoblogger_research_model' => array( 'research', 'llm_research' ),
'prautoblogger_image_model' => array( 'image_a', 'image_b' ),
); );
return $map[ $field_id ] ?? array(); return $map[ $field_id ] ?? array();
} }

View File

@@ -72,6 +72,11 @@ class PRAutoBlogger {
add_action( 'admin_menu', array( $board_page, 'on_register_menu' ), 11 ); add_action( 'admin_menu', array( $board_page, 'on_register_menu' ), 11 );
add_action( 'admin_enqueue_scripts', array( $board_page, 'on_enqueue_assets' ) ); add_action( 'admin_enqueue_scripts', array( $board_page, 'on_enqueue_assets' ) );
// Pipeline Settings: visible submenu, priority 13 (after dossier).
$pipeline_page = new PRAutoBlogger_Pipeline_Settings_Page();
add_action( 'admin_menu', array( $pipeline_page, 'on_register_menu' ), 13 );
add_action( 'admin_enqueue_scripts', array( $pipeline_page, 'on_enqueue_assets' ) );
// Dossier: link-accessed hidden submenu, priority 12 (after board). // Dossier: link-accessed hidden submenu, priority 12 (after board).
$dossier_page = new PRAutoBlogger_Dossier_Page(); $dossier_page = new PRAutoBlogger_Dossier_Page();
add_action( 'admin_menu', array( $dossier_page, 'on_register_menu' ), 12 ); add_action( 'admin_menu', array( $dossier_page, 'on_register_menu' ), 12 );

View File

@@ -9,7 +9,7 @@
* Plugin Name: PRAutoBlogger * Plugin Name: PRAutoBlogger
* Plugin URI: https://peptiderepo.com/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. * 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.22.0 * Version: 0.23.0
* Requires at least: 6.0 * Requires at least: 6.0
* Requires PHP: 7.4 * Requires PHP: 7.4
* Author: PeptideRepo * Author: PeptideRepo
@@ -35,7 +35,7 @@ if ( ! defined( 'ABSPATH' ) ) {
| Defined here so every file in the plugin can reference paths, versions, | Defined here so every file in the plugin can reference paths, versions,
| and limits without magic strings. | and limits without magic strings.
*/ */
define( 'PRAUTOBLOGGER_VERSION', '0.22.0' ); define( 'PRAUTOBLOGGER_VERSION', '0.23.0' );
define( 'PRAUTOBLOGGER_DB_VERSION', '1.4.0' ); define( 'PRAUTOBLOGGER_DB_VERSION', '1.4.0' );
define( 'PRAUTOBLOGGER_DEFAULT_RUN_CEILING_USD', 0.50 ); define( 'PRAUTOBLOGGER_DEFAULT_RUN_CEILING_USD', 0.50 );
define( 'PRAUTOBLOGGER_DEFAULT_REQUEST_JSON_RETENTION_DAYS', 14 ); define( 'PRAUTOBLOGGER_DEFAULT_REQUEST_JSON_RETENTION_DAYS', 14 );

View File

@@ -0,0 +1,194 @@
<?php
/**
* Pipeline Settings page template.
*
* Variables injected by PRAutoBlogger_Pipeline_Settings_Renderer::render():
* array $view['steps'] — ordered step definitions from Step_Map.
* array $view['active_step'] — the currently selected step definition.
* array $view['save_result'] — {status, message} from the save handler.
* string $view['nonce_field'] — nonce field name.
* string $view['nonce_action'] — nonce action string.
* string $view['page_slug'] — pipeline page slug.
* array $view['step_data'] — assembled view data for the active step.
*
* Prompt panels are rendered via the pipeline-settings-prompt-panel.php partial.
*
* @see admin/class-pipeline-settings-renderer.php — Provides $view.
* @see admin/class-pipeline-settings-page.php — Includes this template.
* @see templates/admin/pipeline-settings-prompt-panel.php — Prompt editor partial.
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
$steps = $view['steps'];
$active_step = $view['active_step'];
$save_result = $view['save_result'];
$nonce_field = $view['nonce_field'];
$nonce_action = $view['nonce_action'];
$page_slug = $view['page_slug'];
$step_data = $view['step_data'];
$base_url = admin_url( 'admin.php?page=' . rawurlencode( $page_slug ) );
$cost_reporter = new PRAutoBlogger_Cost_Reporter();
$monthly_spend = $cost_reporter->get_monthly_spend();
$budget = (float) get_option( 'prautoblogger_monthly_budget_usd', 50.00 );
?>
<div class="wrap ab-wrap pab-pipeline-wrap">
<div class="ab-header">
<div class="ab-header-left">
<span class="dashicons dashicons-networking ab-header-icon"></span>
<div>
<h1 class="ab-header-title"><?php esc_html_e( 'Pipeline Settings', 'prautoblogger' ); ?></h1>
<span class="ab-header-version">v<?php echo esc_html( PRAUTOBLOGGER_VERSION ); ?></span>
</div>
</div>
<div class="ab-header-actions">
<a href="<?php echo esc_url( admin_url( 'admin.php?page=prautoblogger-settings' ) ); ?>" class="ab-btn ab-btn-outline">
<?php esc_html_e( '← All Settings', 'prautoblogger' ); ?>
</a>
</div>
</div>
<div class="ab-stats-bar">
<div class="ab-stat">
<span class="ab-stat-label"><?php esc_html_e( 'Monthly Spend', 'prautoblogger' ); ?></span>
<span class="ab-stat-value">$<?php echo esc_html( number_format( $monthly_spend, 2 ) ); ?> <small>/ $<?php echo esc_html( number_format( $budget, 2 ) ); ?></small></span>
</div>
<div class="ab-stat">
<span class="ab-stat-label"><?php esc_html_e( 'Prompts Table', 'prautoblogger' ); ?></span>
<span class="ab-stat-value">
<?php if ( PRAutoBlogger_Prompt_Registry::is_available() ) : ?>
<span class="pab-badge pab-badge-ok"><?php esc_html_e( 'Available', 'prautoblogger' ); ?></span>
<?php else : ?>
<span class="pab-badge pab-badge-warn"><?php esc_html_e( 'Unavailable — using defaults', 'prautoblogger' ); ?></span>
<?php endif; ?>
</span>
</div>
</div>
<?php if ( 'saved' === $save_result['status'] ) : ?>
<div class="ab-save-notice notice notice-success is-dismissible">
<span class="dashicons dashicons-saved"></span> <?php echo esc_html( $save_result['message'] ); ?>
</div>
<?php elseif ( 'error' === $save_result['status'] ) : ?>
<div class="ab-save-notice notice notice-error is-dismissible">
<span class="dashicons dashicons-warning"></span> <?php echo esc_html( $save_result['message'] ); ?>
</div>
<?php endif; ?>
<?php
$niche = (string) get_option( 'prautoblogger_niche_description', '' );
$niche_preview = '' !== $niche ? mb_strimwidth( $niche, 0, 80, '…' ) : '';
?>
<div class="pab-global-context-note">
<span class="dashicons dashicons-info-outline"></span>
<?php if ( '' !== $niche_preview ) : ?>
<?php
printf(
/* translators: %s = truncated niche description */
esc_html__( 'Niche context (used by all stages): "%s"', 'prautoblogger' ),
esc_html( $niche_preview )
);
?>
<?php else : ?>
<?php esc_html_e( 'Niche description not set — edit in Settings → Content.', 'prautoblogger' ); ?>
<?php endif; ?>
</div>
<div class="pab-pipeline-layout">
<nav class="pab-step-rail" aria-label="<?php esc_attr_e( 'Pipeline steps', 'prautoblogger' ); ?>">
<?php foreach ( $steps as $i => $step ) : ?>
<?php $is_active = $step['id'] === $active_step['id']; ?>
<a href="<?php echo esc_url( add_query_arg( 'step', $step['id'], $base_url ) ); ?>"
class="pab-step-btn <?php echo $is_active ? 'pab-step-btn--active' : ''; ?>"
aria-current="<?php echo $is_active ? 'page' : 'false'; ?>">
<span class="pab-step-num"><?php echo esc_html( (string) ( $i + 1 ) ); ?></span>
<span class="dashicons <?php echo esc_attr( $step['icon'] ); ?> pab-step-icon"></span>
<span class="pab-step-label"><?php echo esc_html( $step['label'] ); ?></span>
</a>
<?php endforeach; ?>
</nav>
<div class="pab-step-panel">
<div class="pab-panel-header">
<h2><?php echo esc_html( $active_step['label'] ); ?></h2>
<?php if ( ! empty( $active_step['description'] ) ) : ?>
<p class="pab-panel-desc"><?php echo esc_html( $active_step['description'] ); ?></p>
<?php endif; ?>
</div>
<?php if ( ! empty( $step_data['model_option'] ) ) : ?>
<div class="pab-section">
<h3 class="pab-section-title"><?php esc_html_e( 'Model', 'prautoblogger' ); ?></h3>
<form method="post"
action="<?php echo esc_url( add_query_arg( 'step', $active_step['id'], $base_url ) ); ?>"
class="pab-model-form">
<?php wp_nonce_field( $nonce_action, $nonce_field ); ?>
<input type="hidden" name="pipeline_action" value="save_model" />
<input type="hidden" name="model_option" value="<?php echo esc_attr( $step_data['model_option'] ); ?>" />
<div class="pab-model-picker-wrap">
<?php
$renderer = new PRAutoBlogger_Pipeline_Settings_Renderer();
$renderer->render_model_picker(
$step_data['model_option'],
$step_data['model_value'],
array( 'capability' => $active_step['capability'] ?? 'text→text' )
);
?>
</div>
<p class="pab-field-note">
<?php esc_html_e( 'Changing the model here also updates the corresponding field in Settings → AI Models.', 'prautoblogger' ); ?>
</p>
<button type="submit" class="ab-btn ab-btn-secondary ab-btn-sm">
<?php esc_html_e( 'Save Model', 'prautoblogger' ); ?>
</button>
</form>
</div>
<?php endif; ?>
<?php if ( ! empty( $step_data['params'] ) ) : ?>
<div class="pab-section">
<h3 class="pab-section-title"><?php esc_html_e( 'Parameters', 'prautoblogger' ); ?></h3>
<table class="pab-params-table">
<?php foreach ( $step_data['params'] as $param_name => $param_value ) : ?>
<tr>
<th><?php echo esc_html( $param_name ); ?></th>
<td><code class="pab-mono"><?php echo is_array( $param_value ) ? esc_html( wp_json_encode( $param_value ) ) : esc_html( (string) $param_value ); ?></code></td>
</tr>
<?php endforeach; ?>
</table>
<p class="pab-field-note">
<?php esc_html_e( 'Parameters are defined in the prompt registry defaults. Editing params is a Phase 2b feature.', 'prautoblogger' ); ?>
</p>
</div>
<?php endif; ?>
<?php if ( ! empty( $step_data['system'] ) ) :
$panel = $step_data['system'];
$panel_title = __( 'System Instructions', 'prautoblogger' );
$step_id = $active_step['id'];
$is_writer = ( 'writer' === $step_id );
$writing_mode = (string) get_option( 'prautoblogger_writing_pipeline', 'multi_step' );
include PRAUTOBLOGGER_PLUGIN_DIR . 'templates/admin/pipeline-settings-prompt-panel.php';
endif; ?>
<?php foreach ( $step_data['agent_panels'] as $key => $panel ) :
$panel_title = sprintf(
/* translators: %s = registry key e.g. 'content.draft' */
__( 'Prompt: %s', 'prautoblogger' ),
$key
);
$step_id = $active_step['id'];
$is_writer = ( 'writer' === $step_id );
$writing_mode = (string) get_option( 'prautoblogger_writing_pipeline', 'multi_step' );
include PRAUTOBLOGGER_PLUGIN_DIR . 'templates/admin/pipeline-settings-prompt-panel.php';
endforeach; ?>
</div>
</div>
</div>

View File

@@ -0,0 +1,107 @@
<?php
/**
* Partial: Pipeline Settings — single prompt editor panel.
*
* Variables passed by pipeline-settings-page.php:
* array $panel — prompt panel data from Renderer::build_prompt_panel_data().
* string $nonce_action — nonce action string.
* string $nonce_field — nonce field name.
* string $step_id — active step id (for the form action URL).
* string $base_url — admin.php?page=prautoblogger-pipeline base URL.
* string $panel_title — human-readable title for this panel's h3.
* string $writing_mode — (optional) current writing pipeline mode for Writer step.
* bool $is_writer — whether this is the Writer step.
*
* @see templates/admin/pipeline-settings-page.php — Includes this partial.
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
$key = $panel['key'];
$css_key = str_replace( '.', '-', $key );
$form_key = str_replace( '.', '-', $key );
// Writer-step inactive detection.
$is_inactive = false;
if ( isset( $is_writer ) && $is_writer ) {
$writing_mode = isset( $writing_mode ) ? $writing_mode : (string) get_option( 'prautoblogger_writing_pipeline', 'multi_step' );
$single_pass_keys = array( 'content.single_pass' );
$multi_step_keys = array( 'content.outline', 'content.draft', 'content.polish' );
$is_inactive = ( 'single_pass' === $writing_mode && in_array( $key, $multi_step_keys, true ) )
|| ( 'multi_step' === $writing_mode && in_array( $key, $single_pass_keys, true ) );
}
?>
<div class="pab-section">
<h3 class="pab-section-title">
<?php echo esc_html( $panel_title ); ?>
<span class="pab-version-badge">
<?php
if ( $panel['active_version'] > 0 ) {
printf( esc_html__( 'v%d', 'prautoblogger' ), (int) $panel['active_version'] );
} else {
esc_html_e( 'default', 'prautoblogger' );
}
?>
</span>
<?php if ( $panel['is_default'] ) : ?>
<span class="pab-badge pab-badge-ok"><?php esc_html_e( 'Using default', 'prautoblogger' ); ?></span>
<?php endif; ?>
</h3>
<?php if ( $panel['version_count'] > 0 ) : ?>
<p class="pab-version-meta">
<?php
printf(
/* translators: 1: version count, 2: author, 3: date */
esc_html__( '%1$d version(s) stored. Active: by %2$s on %3$s.', 'prautoblogger' ),
(int) $panel['version_count'],
esc_html( $panel['author'] ),
esc_html( $panel['created_at'] )
);
?>
</p>
<?php endif; ?>
<?php if ( $is_inactive ) : ?>
<p class="pab-inactive-note">
<span class="dashicons dashicons-hidden"></span>
<?php
printf(
/* translators: %s = current writing mode */
esc_html__( 'Inactive in current mode (%s). Edit to prepare for mode switch.', 'prautoblogger' ),
esc_html( $writing_mode )
);
?>
</p>
<?php endif; ?>
<form method="post"
action="<?php echo esc_url( add_query_arg( 'step', $step_id, $base_url ) ); ?>"
class="pab-prompt-form">
<?php wp_nonce_field( $nonce_action, $nonce_field ); ?>
<input type="hidden" name="pipeline_action" value="save_prompt" />
<input type="hidden" name="prompt_key" value="<?php echo esc_attr( $form_key ); ?>" />
<textarea name="prompt_body"
id="pab-prompt-<?php echo esc_attr( $css_key ); ?>"
class="pab-prompt-editor"
rows="10"
spellcheck="false"><?php echo esc_textarea( $panel['body'] ); ?></textarea>
<div class="pab-prompt-actions">
<button type="submit" class="ab-btn ab-btn-secondary ab-btn-sm">
<?php esc_html_e( 'Save (creates new version)', 'prautoblogger' ); ?>
</button>
<?php if ( ! $panel['is_default'] ) : ?>
<button type="submit"
name="pipeline_action"
value="reset_prompt"
class="ab-btn ab-btn-outline ab-btn-sm pab-btn-reset"
onclick="return confirm('<?php esc_attr_e( 'Reset to factory default? This creates a new version.', 'prautoblogger' ); ?>');">
<?php esc_html_e( 'Reset to default', 'prautoblogger' ); ?>
</button>
<?php endif; ?>
</div>
</form>
</div>