feat: v0.2.1 — fix encryption, diverse multi-topic generation, UX fixes

- Rewrite encryption with "enc:" prefix to permanently eliminate
  the double-encryption bug on settings save
- Add one-time migration to clear legacy non-prefixed encrypted values
- Rewrite content analyzer prompts to request N distinct diverse topics
  across 5 categories (question, complaint, comparison, news, guide)
- Pass target_count*2 from pipeline to analyzer for headroom
- Add skip_dedup flag so manual Generate Now always produces content
- Generate Now button now sends force=1 to clear stale locks
- Rename OpenRouter provider files to PSR-4 convention (hyphenated)
- Switch default models to google/gemini-2.5-flash-lite
- Clean up reddit_debug log channel to standard 'reddit'
- Bump version to 0.2.1

Cost: ~$0.003/article with Gemini 2.0 Flash, ~34s pipeline.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
peptiderepo
2026-04-12 13:36:36 +07:00
parent 726b378a52
commit b5cbbef804
15 changed files with 509 additions and 67 deletions

View File

@@ -39,7 +39,11 @@ class PRAutoBlogger_Content_Analyzer {
*
* @return PRAutoBlogger_Analysis_Result[] Detected patterns.
*/
public function analyze_recent_data(): array {
/**
* @param int $target_idea_count How many distinct topic ideas the LLM should produce.
* Defaults to 6 so the scorer has enough to pick from.
*/
public function analyze_recent_data( int $target_idea_count = 6 ): array {
$source_items = $this->fetch_recent_source_data();
if ( empty( $source_items ) ) {
@@ -56,8 +60,8 @@ class PRAutoBlogger_Content_Analyzer {
// Include past performance data for self-improvement.
$performance_context = $this->get_performance_context();
$system_prompt = $this->build_system_prompt( $niche, $performance_context );
$user_prompt = $this->build_user_prompt( $summary );
$system_prompt = $this->build_system_prompt( $niche, $performance_context, $target_idea_count );
$user_prompt = $this->build_user_prompt( $summary, $target_idea_count );
$response = $this->llm->send_chat_completion(
[
@@ -66,8 +70,8 @@ class PRAutoBlogger_Content_Analyzer {
],
$model,
[
'temperature' => 0.3,
'max_tokens' => 4000,
'temperature' => 0.5,
'max_tokens' => 8000,
'response_format' => [ 'type' => 'json_object' ],
]
);
@@ -190,25 +194,33 @@ class PRAutoBlogger_Content_Analyzer {
*
* @return string
*/
private function build_system_prompt( string $niche, string $performance_context ): string {
private function build_system_prompt( string $niche, string $performance_context, int $target_count = 6 ): string {
$prompt = "You are a content strategist analyzing social media discussions to find article ideas for a blog";
if ( '' !== $niche ) {
$prompt .= " in the {$niche} niche";
}
$prompt .= ".\n\n";
$prompt .= "Analyze the provided social media posts and comments to identify:\n";
$prompt .= "IMPORTANT: You must identify exactly {$target_count} DISTINCT article ideas. ";
$prompt .= "Each idea must cover a substantially different topic — no two ideas should overlap ";
$prompt .= "in their main subject. Aim for diversity across these categories:\n";
$prompt .= "1. QUESTIONS: Recurring questions people ask (\"How do I...\", \"What is...\", \"Is it safe to...\")\n";
$prompt .= "2. COMPLAINTS: Pain points, frustrations, or problems people report\n";
$prompt .= "3. COMPARISONS: Product/method comparisons people discuss (\"X vs Y\", \"Which is better\")\n\n";
$prompt .= "3. COMPARISONS: Product/method comparisons people discuss (\"X vs Y\", \"Which is better\")\n";
$prompt .= "4. NEWS: Recent developments, rule changes, or trends people are discussing\n";
$prompt .= "5. GUIDES: How-to topics, best practices, or educational content people need\n\n";
$prompt .= "For each pattern found, provide:\n";
$prompt .= "- type: 'question', 'complaint', or 'comparison'\n";
$prompt .= "- topic: A clear, specific topic description\n";
$prompt .= "- summary: 1-2 sentence summary of the pattern\n";
$prompt .= "- frequency: How many of the provided posts relate to this pattern\n";
$prompt .= "- relevance_score: 0.0 to 1.0 indicating how relevant and article-worthy this topic is\n";
$prompt .= "- suggested_title: A compelling blog post title for this topic\n";
$prompt .= "Spread your {$target_count} ideas across multiple categories. ";
$prompt .= "Be specific — \"peptide dosing for BPC-157\" is better than \"peptide information\". ";
$prompt .= "Each idea should be narrow enough to be a single focused blog post.\n\n";
$prompt .= "For each idea, provide:\n";
$prompt .= "- type: 'question', 'complaint', 'comparison', 'news', or 'guide'\n";
$prompt .= "- topic: A clear, specific, narrow topic description\n";
$prompt .= "- summary: 1-2 sentence summary of why this topic matters\n";
$prompt .= "- frequency: How many of the provided posts relate to this topic\n";
$prompt .= "- relevance_score: 0.0 to 1.0 indicating how relevant and article-worthy this is\n";
$prompt .= "- suggested_title: A compelling, unique blog post title\n";
$prompt .= "- key_points: Array of 3-5 key points the article should cover\n";
$prompt .= "- target_keywords: Array of SEO keywords for this topic\n\n";
@@ -216,7 +228,7 @@ class PRAutoBlogger_Content_Analyzer {
$prompt .= $performance_context . "\n\n";
}
$prompt .= "Respond with valid JSON in this format:\n";
$prompt .= "Respond with valid JSON containing exactly {$target_count} patterns:\n";
$prompt .= '{"patterns": [{"type": "...", "topic": "...", "summary": "...", "frequency": N, "relevance_score": 0.X, "suggested_title": "...", "key_points": [...], "target_keywords": [...]}]}';
return $prompt;
@@ -229,8 +241,10 @@ class PRAutoBlogger_Content_Analyzer {
*
* @return string
*/
private function build_user_prompt( string $summary ): string {
return "Here are the recent social media posts and comments to analyze:\n\n" . $summary;
private function build_user_prompt( string $summary, int $target_count = 6 ): string {
return "Here are the recent social media posts and comments to analyze. "
. "Find {$target_count} distinct, diverse article ideas from this data:\n\n"
. $summary;
}
/**

View File

@@ -17,6 +17,19 @@ declare(strict_types=1);
*/
class PRAutoBlogger_Idea_Scorer {
/** @var bool Whether to skip the has_similar_post() check. */
private bool $skip_dedup = false;
/**
* @param bool $skip True to skip deduplication.
*
* @return $this
*/
public function set_skip_dedup( bool $skip ): self {
$this->skip_dedup = $skip;
return $this;
}
/**
* Score, deduplicate, and rank article ideas.
*
@@ -35,8 +48,13 @@ class PRAutoBlogger_Idea_Scorer {
continue;
}
// Skip if we've already published something very similar.
if ( $this->has_similar_post( $result->get_topic() ) ) {
// Skip if we've already published something very similar
// (unless dedup is disabled for manual runs).
if ( ! $this->skip_dedup && $this->has_similar_post( $result->get_topic() ) ) {
PRAutoBlogger_Logger::instance()->info(
sprintf( 'Skipping topic "%s" — similar post exists.', substr( $result->get_topic(), 0, 80 ) ),
'scorer'
);
continue;
}
@@ -136,6 +154,8 @@ class PRAutoBlogger_Idea_Scorer {
'question' => 'guide',
'complaint' => 'solution',
'comparison' => 'comparison',
'news' => 'news',
'guide' => 'guide',
];
return $map[ $analysis_type ] ?? 'article';
}

View File

@@ -28,6 +28,22 @@ class PRAutoBlogger_Pipeline_Runner {
*
* @throws \RuntimeException If budget is exceeded or critical step fails.
*/
/** @var bool Whether to skip duplicate-topic detection (used for manual runs). */
private bool $skip_dedup = false;
/**
* Allow manual runs to skip the has_similar_post() check so "Generate Now"
* always produces content even when a related article was recently published.
*
* @param bool $skip True to skip deduplication.
*
* @return $this
*/
public function set_skip_dedup( bool $skip ): self {
$this->skip_dedup = $skip;
return $this;
}
public function run(): array {
$cost_tracker = new PRAutoBlogger_Cost_Tracker();
@@ -49,12 +65,15 @@ class PRAutoBlogger_Pipeline_Runner {
$collector->collect_from_all_sources();
// Step 2: Analyze collected data for patterns.
// Pass a generous target so the LLM returns enough diverse ideas for
// scoring to pick from — ask for 2× the daily target so dedup has room.
$llm = new PRAutoBlogger_OpenRouter_Provider();
$analyzer = new PRAutoBlogger_Content_Analyzer( $llm, $cost_tracker );
$analysis = $analyzer->analyze_recent_data();
$analysis = $analyzer->analyze_recent_data( max( $target_count * 2, 6 ) );
// Step 3: Score and deduplicate ideas.
$scorer = new PRAutoBlogger_Idea_Scorer();
$scorer->set_skip_dedup( $this->skip_dedup );
$ideas = $scorer->score_and_rank( $analysis, $target_count );
if ( empty( $ideas ) ) {