name: opportunity_scan
description: "Crimson Leaf opportunity research -- Orion runs 4 targeted searches every hour: KDP charts, trending news, AI content market, and affiliate/review site opportunities."
debug: true
model: power
system: agent_prompt

agent_prompt:
  - "= identity.md"

sections:
  - agent
  - project
  - rag
  - message
  - instructions

steps:
  - type: tool
    action: get_portfolio_report
    output_key: portfolio_data

  # --- Search 1: Amazon KDP bestseller charts ---
  - type: tool
    capability: Tool_WebSearcher
    input: "Amazon KDP Kindle bestseller list romance fiction top 100 this week new releases"
    mode: research
    max_results: 8
    fetch_pages: 3
    optional: true
    output_key: kdp_trends

  # --- Search 2: Trending news topics with content potential ---
  - type: tool
    capability: Tool_WebSearcher
    input: "trending news topics viral stories this week content niche opportunities 2025"
    mode: news
    max_results: 8
    optional: true
    output_key: news_trends

  # --- Search 3: AI content and publishing market trends ---
  - type: tool
    capability: Tool_WebSearcher
    input: "AI content writing publishing trends 2025 self publishing income opportunities Substack newsletter"
    mode: research
    max_results: 8
    fetch_pages: 2
    optional: true
    output_key: ai_content_trends

  # --- Search 4: Amazon affiliate and review site opportunities ---
  - type: tool
    capability: Tool_WebSearcher
    input: "Amazon Associates affiliate review site high commission products niche 2025 best categories to review"
    mode: research
    max_results: 8
    fetch_pages: 3
    optional: true
    output_key: affiliate_trends

  - type: think
    max_tokens: 6000
    output_key: opportunity_analysis
    hint: |
      You are Orion, Director of Research at Crimson Leaf Holdings.
      You have four intelligence feeds below. Synthesize them into a ranked opportunity list.

      === PORTFOLIO (what CL already has) ===
      {portfolio_data}

      === KDP BESTSELLER SIGNALS ===
      {kdp_trends}
      (If empty: use your knowledge of current romance/fiction charts.)

      === NEWS AND VIRAL TRENDS ===
      {news_trends}
      (If empty: use your knowledge of current cultural moment.)

      === AI CONTENT AND PUBLISHING MARKET ===
      {ai_content_trends}

      === AMAZON AFFILIATE AND REVIEW SITE OPPORTUNITIES ===
      {affiliate_trends}
      (Note: Amazon Associates pays 1-10% commission on referred purchases. A review
      site publishing AI-written product reviews with affiliate links is a distinct
      revenue stream from book sales -- lower effort, passive income.)

      Evaluate every signal against what CL can actually BUILD today:
      - CL has AI writing workers (books, articles, reviews)
      - CL has web search capability
      - CL has Gitea for publishing content
      - CL does NOT yet have a website, storefront, or affiliate account

      Structure your analysis:

      ### BOOK / CONTENT OPPORTUNITIES
      Top 2 niches where CL should write books RIGHT NOW based on KDP charts or news trends.
      For each: niche, why now (cite a signal), estimated monthly revenue if in top 100.

      ### AFFILIATE / REVIEW SITE OPPORTUNITY
      Best product category for a CL review site (based on affiliate feed).
      Consider: commission rate, search volume, competition, how AI-written reviews compete.
      Be specific -- "kitchen gadgets under $30" beats "electronics".
      Flag if this requires a new company (Crimson Leaf Reviews) or fits under an existing one.

      ### PORTFOLIO GAPS
      What are our subsidiaries NOT doing that they should be doing this week?

      ### ACTION ITEMS
      Format: "David, [verb]: [specific action]"
      Include at least one action item about the affiliate opportunity if it looks viable.

      Be direct. Cite data from the feeds. Don't hedge.

  - type: think
    max_tokens: 600
    output_key: opportunity_1_content
    hint: |
      From the opportunity analysis above, extract the TOP BOOK/CONTENT opportunity.

      Write a market_intelligence task brief:
      - What the opportunity is (1-2 sentences, cite the signal)
      - Why now (timing -- what just happened in the market)
      - Research questions: What does the KDP top 100 look like in this niche?
        Who are the top 5 authors and what do they charge? What tropes are selling?
      - CL entry angle: which agent writes this, which project slug to use

      If no compelling book opportunity was found, output exactly: none
      Output ONLY the brief or the word none. No preamble.

  - type: think
    max_tokens: 600
    output_key: opportunity_2_content
    hint: |
      From the opportunity analysis above, extract the AFFILIATE/REVIEW SITE opportunity.

      Write an affiliate_intelligence task brief:
      - What the product category is and why it was selected
      - Amazon Associates commission rate for this category if found in the research
      - Key questions to answer: Who are the top review sites in this niche?
        What content gaps exist? How many articles needed for $500/month in commissions?
      - What Crimson Leaf would need to build: domain, content volume, affiliate account

      If no compelling affiliate opportunity was found, output exactly: none
      Output ONLY the brief or the word none. No preamble.

  - type: tool
    action: enqueue_strategy
    optional: true
    params:
      company_slug: "crimson_leaf"
      project_slug: "incubation"
      task_type: "market_intelligence"
      content: "{opportunity_1_content}"

  - type: tool
    action: enqueue_strategy
    optional: true
    params:
      company_slug: "crimson_leaf"
      project_slug: "incubation"
      task_type: "affiliate_intelligence"
      content: "{opportunity_2_content}"

  - type: think
    max_tokens: 100
    output_key: dispatch_summary
    hint: |
      Look at opportunity_1_content and opportunity_2_content above.
      If both are not "none": output "Commissioned 2 research tasks (market_intelligence + affiliate_intelligence)."
      If only opportunity_1_content is not "none": output "Commissioned 1 research task (book opportunity -- market_intelligence)."
      If only opportunity_2_content is not "none": output "Commissioned 1 research task (affiliate opportunity -- affiliate_intelligence)."
      If both are "none": output "No research tasks commissioned -- no new signals found."
      Output ONLY that sentence.

  - type: reply
    target: channel
    channel_name: "crimson_leaf:live-feed"
    hint: |
      Write a 4-6 line opportunity scan summary.

      Start with: "Opportunity scan complete. {dispatch_summary}"

      Then cover:
      - Top book/content signal (niche + why now, cite source if available)
      - Top affiliate/review site signal (category + commission rate if found)
      - One portfolio gap identified
      - One action item for David

      Be specific. Cite real data from the research. No filler.

adjudication:
  enabled: false
