Pipeline v2 Phase 1, commit 2/4. Prompt_Registry (read) + Prompt_Registry_Writer (immutable create/activate/seed) over the new prompts table; canonical v1 bodies extracted verbatim into Prompt_Defaults(+Editorial) — single source for BOTH the seed migration (Migrate_Prompt_Seed_V0180, flag-gated, self-healing) and the in-code fallback, so a missing table renders byte-identical prompts and never fatals. Call sites swapped: Content_Prompts, Analysis_Prompts, Chief_Editor, LLM_Research_Provider. Includes the image-composer seam keys image.rewriter_system + image.style_template (composer PR consumes, must not add its own prompt storage). Pinning: Cost_Tracker::set_run_id() registers the process run context, ensures the runs ledger row, and pins active versions once per run; log_api_call/log_image_generation stamp prompt_version (run pins) + agent_role (stage map) on every generation_log row. Single-pass keeps stage 'draft' and stamps content.single_pass explicitly. Under-300 refactors: Content_Generator's four duplicated span/log blocks consolidated into execute_stage() (301 -> 224 lines, behavior identical); get_avg_tokens_for_stages body moved to Cost_Reporter with a delegating wrapper kept for API compatibility. Tests: byte-identical fallback renders (single_pass/outline/polish/ editor.system), token filling, key coverage incl. stage-map integrity. Agent-Session: pipeline-v2-phase1-engineer-20260612
60 lines
1.8 KiB
PHP
60 lines
1.8 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
/**
|
|
* phpcs:ignore WordPress.Files.FileName.InvalidClassFileName -- class naming convention differs from WordPress standard
|
|
*
|
|
* Per-PHP-process holder for the active pipeline run id.
|
|
*
|
|
* What: A process-scoped static slot recording which run this PHP request
|
|
* is executing, set whenever Cost_Tracker::set_run_id() is called
|
|
* (daily cron, manual generation, queued-article jobs, ideas
|
|
* browser). It lets components that are constructed without a run
|
|
* reference — the OpenRouter provider (cost-governor guard) and
|
|
* standalone Cost_Tracker instances (e.g. the image prompt
|
|
* rewriter's) — resolve the surrounding run for reservation and
|
|
* prompt-version stamping without threading a parameter through
|
|
* every constructor. Mirrors the Opik_Trace_Context precedent.
|
|
* Who triggers it: PRAutoBlogger_Cost_Tracker::set_run_id() (set);
|
|
* Cost_Governor + Cost_Tracker (read).
|
|
* Dependencies: none.
|
|
*
|
|
* @see core/class-cost-tracker.php — Sets the context on set_run_id().
|
|
* @see core/class-cost-governor.php — Reads it to guard LLM calls.
|
|
*/
|
|
class PRAutoBlogger_Run_Context {
|
|
|
|
/** @var string|null Active run id for this PHP process, or null. */
|
|
private static ?string $run_id = null;
|
|
|
|
/**
|
|
* Record the active run id for this process.
|
|
*
|
|
* @param string $run_id Pipeline run UUID.
|
|
* @return void
|
|
*/
|
|
public static function set_run_id( string $run_id ): void {
|
|
if ( '' !== $run_id ) {
|
|
self::$run_id = $run_id;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* The active run id for this process, or null outside any run.
|
|
*
|
|
* @return string|null
|
|
*/
|
|
public static function current_run_id(): ?string {
|
|
return self::$run_id;
|
|
}
|
|
|
|
/**
|
|
* Clear the context (tests / end of run).
|
|
*
|
|
* @return void
|
|
*/
|
|
public static function clear(): void {
|
|
self::$run_id = null;
|
|
}
|
|
}
|