#!/usr/bin/env python3
"""Generate Super Investor Cloning Intelligence System Proposal"""

import os
from docx import Document
from docx.shared import Inches, Pt, Cm, RGBColor, Emu
from docx.enum.text import WD_ALIGN_PARAGRAPH
from docx.enum.table import WD_TABLE_ALIGNMENT
from docx.enum.section import WD_ORIENT
from docx.oxml.ns import qn, nsdecls
from docx.oxml import parse_xml
import datetime

# Colors
NAVY = RGBColor(0x00, 0x2B, 0x5C)
GOLD = RGBColor(0xC5, 0x9E, 0x3C)
WHITE = RGBColor(0xFF, 0xFF, 0xFF)
DARK_GRAY = RGBColor(0x33, 0x33, 0x33)
LIGHT_GRAY = RGBColor(0xF5, 0xF5, 0xF5)
MED_GRAY = RGBColor(0x66, 0x66, 0x66)

doc = Document()

# ── Default font ──
style = doc.styles['Normal']
font = style.font
font.name = 'Calibri'
font.size = Pt(11)
font.color.rgb = DARK_GRAY

# ── Page margins ──
for section in doc.sections:
    section.top_margin = Cm(2.5)
    section.bottom_margin = Cm(2.5)
    section.left_margin = Cm(2.5)
    section.right_margin = Cm(2.5)

# ── Helpers ──
def add_page_break():
    doc.add_page_break()

def set_cell_shading(cell, color_hex):
    shading = parse_xml(f'<w:shd {nsdecls("w")} w:fill="{color_hex}"/>')
    cell._tc.get_or_add_tcPr().append(shading)

def add_heading_styled(text, level=1):
    h = doc.add_heading(text, level=level)
    for run in h.runs:
        run.font.color.rgb = NAVY
        run.font.name = 'Calibri'
        if level == 1:
            run.font.size = Pt(24)
        elif level == 2:
            run.font.size = Pt(18)
        elif level == 3:
            run.font.size = Pt(14)
    return h

def add_subheading(text):
    p = doc.add_paragraph()
    run = p.add_run(text)
    run.font.color.rgb = GOLD
    run.font.size = Pt(14)
    run.font.name = 'Calibri'
    run.bold = True
    return p

def add_body(text):
    p = doc.add_paragraph(text)
    p.style.font.name = 'Calibri'
    return p

def add_bullet(text, bold_prefix=None):
    p = doc.add_paragraph(style='List Bullet')
    if bold_prefix:
        run = p.add_run(bold_prefix)
        run.bold = True
        run.font.name = 'Calibri'
        run.font.size = Pt(11)
        p.add_run(text)
    else:
        p.add_run(text)
    for run in p.runs:
        run.font.name = 'Calibri'
        run.font.size = Pt(11)
    return p

def add_gold_divider():
    p = doc.add_paragraph()
    run = p.add_run('━' * 60)
    run.font.color.rgb = GOLD
    run.font.size = Pt(8)
    p.alignment = WD_ALIGN_PARAGRAPH.CENTER

def add_callout_box(text):
    """Add a highlighted callout paragraph"""
    p = doc.add_paragraph()
    p.paragraph_format.left_indent = Cm(1)
    p.paragraph_format.right_indent = Cm(1)
    run = p.add_run('▎ ')
    run.font.color.rgb = GOLD
    run.font.size = Pt(14)
    run = p.add_run(text)
    run.font.color.rgb = NAVY
    run.font.size = Pt(11)
    run.italic = True
    run.font.name = 'Calibri'
    return p

def make_table(headers, rows, col_widths=None):
    """Create a styled table"""
    table = doc.add_table(rows=1 + len(rows), cols=len(headers))
    table.alignment = WD_TABLE_ALIGNMENT.CENTER
    
    # Header row
    for i, header in enumerate(headers):
        cell = table.rows[0].cells[i]
        cell.text = ''
        p = cell.paragraphs[0]
        run = p.add_run(header)
        run.bold = True
        run.font.color.rgb = WHITE
        run.font.name = 'Calibri'
        run.font.size = Pt(10)
        set_cell_shading(cell, '002B5C')
    
    # Data rows
    for r_idx, row in enumerate(rows):
        for c_idx, val in enumerate(row):
            cell = table.rows[r_idx + 1].cells[c_idx]
            cell.text = ''
            p = cell.paragraphs[0]
            run = p.add_run(str(val))
            run.font.name = 'Calibri'
            run.font.size = Pt(9)
            run.font.color.rgb = DARK_GRAY
            if r_idx % 2 == 1:
                set_cell_shading(cell, 'F0F0F0')
    
    # Set column widths if provided
    if col_widths:
        for row in table.rows:
            for i, width in enumerate(col_widths):
                row.cells[i].width = Inches(width)
    
    return table

def add_page_numbers():
    """Add page numbers to footer"""
    for section in doc.sections:
        footer = section.footer
        footer.is_linked_to_previous = False
        p = footer.paragraphs[0]
        p.alignment = WD_ALIGN_PARAGRAPH.CENTER
        
        # Add page number field
        run = p.add_run()
        fldChar1 = parse_xml(f'<w:fldChar {nsdecls("w")} w:fldCharType="begin"/>')
        run._r.append(fldChar1)
        
        run2 = p.add_run()
        instrText = parse_xml(f'<w:instrText {nsdecls("w")} xml:space="preserve"> PAGE </w:instrText>')
        run2._r.append(instrText)
        
        run3 = p.add_run()
        fldChar2 = parse_xml(f'<w:fldChar {nsdecls("w")} w:fldCharType="end"/>')
        run3._r.append(fldChar2)
        
        for r in [run, run2, run3]:
            r.font.size = Pt(9)
            r.font.color.rgb = MED_GRAY
            r.font.name = 'Calibri'

# ══════════════════════════════════════════════════════════════
# COVER PAGE
# ══════════════════════════════════════════════════════════════

# Spacer
for _ in range(4):
    doc.add_paragraph()

# Title block
p = doc.add_paragraph()
p.alignment = WD_ALIGN_PARAGRAPH.CENTER
run = p.add_run('SUPER INVESTOR')
run.font.size = Pt(36)
run.font.color.rgb = NAVY
run.font.name = 'Calibri'
run.bold = True

p = doc.add_paragraph()
p.alignment = WD_ALIGN_PARAGRAPH.CENTER
run = p.add_run('CLONING INTELLIGENCE SYSTEM')
run.font.size = Pt(36)
run.font.color.rgb = NAVY
run.font.name = 'Calibri'
run.bold = True

add_gold_divider()

p = doc.add_paragraph()
p.alignment = WD_ALIGN_PARAGRAPH.CENTER
run = p.add_run('STRATEGIC PROPOSAL')
run.font.size = Pt(18)
run.font.color.rgb = GOLD
run.font.name = 'Calibri'

p = doc.add_paragraph()
p.alignment = WD_ALIGN_PARAGRAPH.CENTER
run = p.add_run('System Design, Architecture & Implementation Roadmap')
run.font.size = Pt(14)
run.font.color.rgb = MED_GRAY
run.font.name = 'Calibri'
run.italic = True

# Spacer
for _ in range(6):
    doc.add_paragraph()

# Footer info
p = doc.add_paragraph()
p.alignment = WD_ALIGN_PARAGRAPH.CENTER
run = p.add_run('Prepared for')
run.font.size = Pt(12)
run.font.color.rgb = MED_GRAY
run.font.name = 'Calibri'

p = doc.add_paragraph()
p.alignment = WD_ALIGN_PARAGRAPH.CENTER
run = p.add_run('JOE LYNCH')
run.font.size = Pt(20)
run.font.color.rgb = NAVY
run.font.name = 'Calibri'
run.bold = True

p = doc.add_paragraph()
p.alignment = WD_ALIGN_PARAGRAPH.CENTER
run = p.add_run('Managing Member, Tuckerton Group  |  JFL&KL Fund')
run.font.size = Pt(11)
run.font.color.rgb = MED_GRAY
run.font.name = 'Calibri'

for _ in range(2):
    doc.add_paragraph()

add_gold_divider()

p = doc.add_paragraph()
p.alignment = WD_ALIGN_PARAGRAPH.CENTER
run = p.add_run('Prepared by Rob Lobster 🦞  |  April 3, 2026')
run.font.size = Pt(11)
run.font.color.rgb = MED_GRAY
run.font.name = 'Calibri'

p = doc.add_paragraph()
p.alignment = WD_ALIGN_PARAGRAPH.CENTER
run = p.add_run('PROPOSAL — PENDING APPROVAL')
run.font.size = Pt(12)
run.font.color.rgb = GOLD
run.font.name = 'Calibri'
run.bold = True

p = doc.add_paragraph()
p.alignment = WD_ALIGN_PARAGRAPH.CENTER
run = p.add_run('CONFIDENTIAL')
run.font.size = Pt(10)
run.font.color.rgb = RGBColor(0xCC, 0x00, 0x00)
run.font.name = 'Calibri'
run.bold = True

add_page_break()

# ══════════════════════════════════════════════════════════════
# TABLE OF CONTENTS
# ══════════════════════════════════════════════════════════════

add_heading_styled('TABLE OF CONTENTS', 1)
add_gold_divider()

toc_items = [
    ('Executive Summary', ''),
    ('Section 1', 'Name the System'),
    ('Section 2', 'The Super Investor List'),
    ('Section 3', 'Data Collection Architecture'),
    ('Section 4', 'Investor Profile Structure'),
    ('Section 5', 'Nightly Intelligence Sweep'),
    ('Section 6', 'Cloning Strategy & Integration'),
    ('Implementation', 'Phased Rollout Plan'),
    ('Appendix', 'Cost Estimates & Technical Requirements'),
]

for prefix, title in toc_items:
    p = doc.add_paragraph()
    run = p.add_run(f'{prefix}')
    run.bold = True
    run.font.color.rgb = NAVY
    run.font.name = 'Calibri'
    run.font.size = Pt(12)
    if title:
        run = p.add_run(f'  —  {title}')
        run.font.color.rgb = DARK_GRAY
        run.font.name = 'Calibri'
        run.font.size = Pt(12)

add_page_break()

# ══════════════════════════════════════════════════════════════
# EXECUTIVE SUMMARY
# ══════════════════════════════════════════════════════════════

add_heading_styled('EXECUTIVE SUMMARY', 1)
add_gold_divider()

add_body(
    'This proposal outlines the design and implementation of a systematic intelligence platform '
    'that tracks, analyzes, and synthesizes the public investment activities of the world\'s greatest '
    'value investors — enabling Joe Lynch to make better-informed capital allocation decisions by '
    'standing on the shoulders of proven capital allocators.'
)

add_callout_box(
    '"The best thing a human being can do is to help another human being know more." — Charlie Munger'
)

add_body(
    'The core thesis is simple and battle-tested: the greatest investors in history have publicly '
    'disclosed portfolios (via SEC 13F filings), publish letters explaining their reasoning, and speak '
    'at conferences sharing their frameworks. This information is free. What\'s missing is a systematic '
    'way to collect, organize, cross-reference, and act on it.'
)

add_subheading('What This System Will Do')
add_bullet('Track 20+ proven super investors across all public disclosure channels', bold_prefix='Monitor: ')
add_bullet('Pull 13F filings, Form 4 insider transactions, 13D activist disclosures automatically', bold_prefix='Collect: ')
add_bullet('Build living profiles that evolve with each investor\'s moves and public statements', bold_prefix='Profile: ')
add_bullet('Use local AI (Qwen 2.5) for free nightly processing; cloud AI (Claude) for deep analysis only', bold_prefix='Analyze: ')
add_bullet('Identify convergence — when multiple great investors independently reach the same conclusion', bold_prefix='Converge: ')
add_bullet('Deliver a daily "Morning Intelligence Brief" integrated with Joe\'s existing workflow', bold_prefix='Deliver: ')

add_subheading('What This System Will NOT Do')
add_bullet('Make buy/sell decisions — Joe makes every call', bold_prefix='')
add_bullet('Replace fundamental analysis — this supplements, never substitutes', bold_prefix='')
add_bullet('Blindly clone positions without understanding the thesis', bold_prefix='')

add_subheading('Why Now')
add_body(
    'Joe\'s April 30, 2026 portfolio restructuring — moving from 14 positions plus $1.7M cash into a '
    'concentrated 29-stock portfolio across three buckets — creates the ideal moment to build this system. '
    'The infrastructure (Mac Mini M4, OpenClaw, Ollama with Qwen 2.5, Rob Lobster as AI chief of staff) '
    'is already in place. The knowledge gap is not "what to build" but "how to systematize what Joe already '
    'does manually."'
)

add_subheading('Estimated Costs')

make_table(
    ['Component', 'Monthly Cost', 'Notes'],
    [
        ['Local AI Processing (Qwen 2.5 via Ollama)', '$0', 'Runs on Mac Mini M4'],
        ['SEC EDGAR API', '$0', 'Free public API'],
        ['Alpha Vantage API (free tier)', '$0', '5 calls/min, 500/day'],
        ['Financial Modeling Prep (free tier)', '$0', '250 calls/day'],
        ['WhaleWisdom (free tier)', '$0', 'Basic 13F access'],
        ['Claude API (deep analysis only)', '~$5-15', 'Triggered only for significant events'],
        ['GuruFocus Premium (optional)', '$30', 'Guru portfolio tracking, 10yr data'],
        ['TOTAL', '$5-45/month', 'Mostly free infrastructure'],
    ],
    col_widths=[3.0, 1.5, 2.5]
)

add_page_break()

# ══════════════════════════════════════════════════════════════
# SECTION 1 — NAME THE SYSTEM
# ══════════════════════════════════════════════════════════════

add_heading_styled('SECTION 1 — NAME THE SYSTEM', 1)
add_gold_divider()

add_body(
    'A system this important deserves a name that reflects its purpose and philosophy. '
    'The name should evoke the intellectual tradition of Graham, Buffett, and Munger — not '
    'Silicon Valley. It should feel like something you\'d reference in a shareholder letter, '
    'not a pitch deck.'
)

add_subheading('Five Proposed Names')

# Name 1
p = doc.add_paragraph()
run = p.add_run('1. THE MARGIN OF SAFETY ENGINE')
run.bold = True
run.font.color.rgb = NAVY
run.font.size = Pt(13)
run.font.name = 'Calibri'
add_body(
    'Rationale: Direct homage to Seth Klarman\'s seminal work and Ben Graham\'s core principle. '
    'The "margin of safety" is the bedrock of value investing — and this system provides an '
    'additional margin of safety by cross-referencing your analysis against proven investors. '
    'The word "Engine" signals that this is systematic, not ad hoc.'
)

# Name 2
p = doc.add_paragraph()
run = p.add_run('2. THE ORACLE NETWORK')
run.bold = True
run.font.color.rgb = NAVY
run.font.size = Pt(13)
run.font.name = 'Calibri'
add_body(
    'Rationale: "Oracle" nods to Buffett\'s moniker, "The Oracle of Omaha." A "network" of oracles — '
    'multiple investors whose collective wisdom exceeds any individual. Clean, memorable, slightly grand.'
)

# Name 3
p = doc.add_paragraph()
run = p.add_run('3. CONVICTION LEDGER')
run.bold = True
run.font.color.rgb = NAVY
run.font.size = Pt(13)
run.font.name = 'Calibri'
add_body(
    'Rationale: "Conviction" is the language value investors use — high-conviction positions, '
    'conviction weighting. "Ledger" is classic, timeless, evokes both Ben Franklin and blockchain-era '
    'permanence. This is a running record of what the best investors believe most strongly.'
)

# Name 4
p = doc.add_paragraph()
run = p.add_run('4. THE MOAT MAP')
run.bold = True
run.font.color.rgb = NAVY
run.font.size = Pt(13)
run.font.name = 'Calibri'
add_body(
    'Rationale: Buffett\'s favorite metaphor — durable competitive advantages as "moats." '
    'A "map" of where the best investors are finding moats. Visual, intuitive, and uniquely '
    'Buffett-school. Works well as a dashboard name too.'
)

# Name 5
p = doc.add_paragraph()
run = p.add_run('5. SUPERINVESTOR INTELLIGENCE SYSTEM (SIS)')
run.bold = True
run.font.color.rgb = NAVY
run.font.size = Pt(13)
run.font.name = 'Calibri'
add_body(
    'Rationale: Direct, no-nonsense, says exactly what it is. "Superinvestor" comes straight from '
    'Buffett\'s famous 1984 Columbia speech "The Superinvestors of Graham-and-Doddsville." '
    'The acronym SIS is clean and functional.'
)

add_gold_divider()
add_subheading('★ RECOMMENDATION: THE MARGIN OF SAFETY ENGINE')

add_body(
    'Defense: This name operates on two levels. First, it\'s an immediate signal of philosophical '
    'alignment — anyone who knows value investing recognizes "margin of safety" as the foundational '
    'principle. Second, it describes exactly what the system provides: an additional margin of safety '
    'in your investment process by cross-referencing against the highest-conviction positions of '
    'proven allocators.'
)

add_body(
    'When you say "I ran it through the Margin of Safety Engine," that sentence communicates '
    'both what you did and why it matters. It\'s a name Seth Klarman would respect and Munger '
    'would find appropriately boring — which, from Munger, is the highest compliment.'
)

add_callout_box(
    'Working abbreviation: "MOSE" or simply "the Engine." Usage: "The Engine flagged convergence '
    'on Constellation Software across four tracked investors this quarter."'
)

add_page_break()

# ══════════════════════════════════════════════════════════════
# SECTION 2 — THE SUPER INVESTOR LIST
# ══════════════════════════════════════════════════════════════

add_heading_styled('SECTION 2 — THE SUPER INVESTOR LIST', 1)
add_gold_divider()

# ── 2A: SOURCING CANDIDATES ──
add_heading_styled('2A — Sourcing Candidates', 2)

add_body(
    'Super investors don\'t announce themselves. The best ones are often the quietest. '
    'Building a comprehensive roster requires mining multiple channels systematically.'
)

add_subheading('Primary Sources: SEC Filings')
add_bullet('13F filings on SEC EDGAR — any institutional investment manager with $100M+ in qualifying securities must file quarterly. This is the gold standard for portfolio tracking. Free, structured data, fully automatable.', bold_prefix='SEC EDGAR 13F: ')
add_bullet('Form 4 — insider transactions filed within 2 business days. Catches when a tracked investor\'s company insiders are buying/selling. Real-time signal.', bold_prefix='Form 4: ')
add_bullet('13D/13G — filed when an investor acquires 5%+ of a company. Activist positions, major stakes. Event-driven, high signal.', bold_prefix='13D/13G: ')

add_subheading('Non-13F Investors (International, Private, Sub-Threshold)')
add_body('Some of the best investors don\'t file 13F. How to track them:')
add_bullet('Fund annual/semi-annual reports (Terry Smith\'s Fundsmith publishes top holdings)', bold_prefix='Fund Reports: ')
add_bullet('SEDAR+ (Canada) for Prem Watsa/Fairfax, Francois Rochon/Giverny', bold_prefix='International Filings: ')
add_bullet('Companies House (UK) for UK-based managers', bold_prefix='UK Filings: ')
add_bullet('Annual shareholder letters often disclose full portfolios (Nomad Partnership letters, Fairfax Financial)', bold_prefix='Shareholder Letters: ')
add_bullet('Many international managers present at US conferences where holdings are discussed', bold_prefix='Conference Presentations: ')

add_subheading('Conferences & Events')
add_bullet('The premier event. 40,000+ investors. Side conversations, panel discussions, Buffett/Ajit/Greg Q&A reveal current thinking.', bold_prefix='Berkshire Hathaway Annual Meeting: ')
add_bullet('Invitation-only hedge fund conference. Managers present their best idea. Past picks have been spectacular.', bold_prefix='Ira Sohn Investment Conference: ')
add_bullet('Jim Grant\'s conference. Deep value, contrarian thinkers. Smaller, higher signal-to-noise.', bold_prefix='Grant\'s Interest Rate Observer Conference: ')
add_bullet('Exclusive gathering in Klosters, Switzerland. Attendees include Guy Spier, Mohnish Pabrai, and other Buffett disciples. Ideas shared freely.', bold_prefix='VALUEx Vail / VALUEx Klosters: ')
add_bullet('Pabrai\'s annual letters and Dakshana Foundation events often include investment discussions.', bold_prefix='Pabrai\'s Annual Meeting: ')
add_bullet('Google/Alphabet\'s exclusive investor event.', bold_prefix='Google Zeitgeist: ')
add_bullet('Robin Hood Investors Conference, Capitalize for Kids (Canada), Value Investing Congress', bold_prefix='Others: ')

add_subheading('YouTube Channels (Specific, Monitored)')
add_body('These channels regularly discuss super investor moves, philosophy, and provide transcripts of interviews:')

yt_channels = [
    ['The Swedish Investor', '~800K subs', 'Book summaries of Buffett, Munger, Lynch, etc. Gold mine for philosophy extraction.'],
    ['Investor Center', '~200K subs', 'Deep dives on super investor portfolios. Covers 13F changes quarterly.'],
    ['New Money', '~1.5M subs', 'Covers Buffett, Ackman, and macro events. High production value.'],
    ['Sven Carlin PhD', '~250K subs', 'European value investor. Independent analysis, covers international picks.'],
    ['Tobias Carlisle / The Acquirer\'s Podcast', '~100K subs', 'Interviews value managers. Deep value focus. Podcast transcripts available.'],
    ['Value After Hours', '~50K subs', 'Tobias Carlisle, Jake Taylor, Bill Brewster. Weekly roundtable.'],
    ['Graham Stephan', '~4.5M subs', 'Less deep value, but covers Buffett moves and reaches mainstream audience.'],
    ['The Plain Bagel', '~1M subs', 'Richard Coffin. Canadian value perspective. Clear analysis.'],
    ['Patrick Boyle', '~900K subs', 'Former hedge fund manager. Witty, data-driven market analysis.'],
    ['Aswath Damodaran', '~500K subs', 'NYU professor. Valuation masterclass. Not a "super investor" but essential for methodology.'],
    ['InvestorBridge / YAPSS', '~30K subs', 'Covers investor letters and conference presentations in detail.'],
    ['Compounding Quality', '~100K subs', 'Quality compounder focused. Akre/Dorsey style analysis.'],
]

make_table(
    ['Channel', 'Audience', 'Value to System'],
    yt_channels,
    col_widths=[2.0, 1.0, 4.0]
)

add_subheading('News & Research Platforms')
add_bullet('Premium investor research. Super investor portfolio tracking, screeners, 10+ year data. Best-in-class for 13F analysis. ($30/mo for Premium).', bold_prefix='GuruFocus: ')
add_bullet('Aggregates 13F data into easy-to-read format. Free tier covers basics. Tracks "guru" performance.', bold_prefix='WhaleWisdom: ')
add_bullet('Free 13F tracking, hedge fund analysis, aggregated super investor moves.', bold_prefix='HedgeFollow: ')
add_bullet('Founded by Joel Greenblatt. Members-only investment idea sharing. Extremely high quality. ($2,000+/yr but many ideas leak to public).', bold_prefix='Value Investors Club (VIC): ')
add_bullet('Invitation-only community for professional investors. Buy-side idea sharing.', bold_prefix='SumZero: ')
add_bullet('Monthly publication profiling super investors and their best ideas. ($349/yr). Edited by John Mihaljevic.', bold_prefix='The Manual of Ideas: ')
add_bullet('Tracks 13F filings and publishes analysis of super investor moves.', bold_prefix='Superinvestor Bulletin: ')
add_bullet('Premium articles often cover super investor positions. Joe already subscribes.', bold_prefix='Seeking Alpha: ')
add_bullet('Barron\'s (weekly investor profiles), WSJ (Heard on the Street), Bloomberg (terminal-level data if needed).', bold_prefix='Traditional Financial Media: ')
add_bullet('Free 13F aggregation, insider buying screeners, hedge fund analysis.', bold_prefix='Insider Monkey: ')
add_bullet('Aggregates 13F data, allows portfolio comparison, tracks historical changes.', bold_prefix='Dataroma: ')

add_subheading('Podcasts')
podcast_list = [
    ['We Study Billionaires (TIP)', 'The Investor\'s Podcast Network', 'Weekly deep dives on Buffett, Munger, super investor strategies. Transcripts available.'],
    ['The Acquirer\'s Podcast', 'Tobias Carlisle', 'Interviews with deep value managers. New ideas every episode.'],
    ['Capital Allocators', 'Ted Seides', 'Institutional investors, endowments, CIOs. Higher-level allocation thinking.'],
    ['Value After Hours', 'Carlisle / Taylor / Brewster', 'Weekly market discussion from value lens. Casual, insightful.'],
    ['Invest Like the Best', 'Patrick O\'Shaughnessy', 'Broad but frequently features value investors.'],
    ['Motley Fool Money', 'Various', 'Mainstream but covers major investor moves.'],
    ['Focused Compounding', 'Andrew Rosenblum & Geoff Gannon', 'Deep value, concentrated portfolios. Very aligned with Joe\'s style.'],
    ['The Business Brew', 'Bill Brewster', 'Long-form conversations with fund managers. Raw, unfiltered.'],
    ['Superinvestors Podcast', 'Jesse Felder', 'Directly profiles super investor strategies.'],
]

make_table(
    ['Podcast', 'Host', 'Relevance'],
    podcast_list,
    col_widths=[2.0, 1.5, 3.5]
)

add_subheading('Newsletters & Investor Letters')
add_bullet('Greenlight Capital (Einhorn) — quarterly letters, famous for detailed short/long theses', bold_prefix='')
add_bullet('Pershing Square (Ackman) — annual letter, conference presentations, highly detailed', bold_prefix='')
add_bullet('Fairfax Financial (Watsa) — annual letter, directly modeled on Buffett\'s style', bold_prefix='')
add_bullet('Baupost Group (Klarman) — annual letter, rarely leaked but invaluable when available', bold_prefix='')
add_bullet('Semper Augustus (Bloomstran) — annual letter, deep Berkshire analysis', bold_prefix='')
add_bullet('Giverny Capital (Rochon) — annual letter, 20+ year track record documented', bold_prefix='')
add_bullet('Himalaya Capital (Li Lu) — Columbia/Greenwald lectures, rare but profound', bold_prefix='')
add_bullet('Nomad Partnership (Sleep/Zakaria) — complete letter archive available online, foundational reading', bold_prefix='')
add_bullet('Pabrai Funds — annual letters and Dakshana charity event presentations', bold_prefix='')
add_bullet('Substack: Yet Another Value Blog (Andrew Walker), Kingswell (Alex Morris), The 10th Man, Verdad Capital', bold_prefix='')

add_subheading('Books & Interviews Revealing Philosophy')
add_bullet('"The Education of a Value Investor" by Guy Spier — reveals his entire process', bold_prefix='')
add_bullet('"The Dhandho Investor" by Mohnish Pabrai — concentrated value framework', bold_prefix='')
add_bullet('"Margin of Safety" by Seth Klarman — out of print, foundational', bold_prefix='')
add_bullet('"Richer, Wiser, Happier" by William Green — profiles Pabrai, Spier, Marks, Klarman, others', bold_prefix='')
add_bullet('"The Most Important Thing" by Howard Marks — cycle-based investing framework', bold_prefix='')
add_bullet('"100 Baggers" by Chris Mayer — quality compounder identification', bold_prefix='')
add_bullet('"Quality Investing" by Lawrence Cunningham — Akre/Dorsey school', bold_prefix='')
add_bullet('"Poor Charlie\'s Almanack" — Munger\'s mental models, the operating system of value investing', bold_prefix='')
add_bullet('Bruce Greenwald\'s "Value Investing" — Columbia B-School framework, Li Lu\'s intellectual home', bold_prefix='')

add_page_break()

# ── 2B: VETTING CRITERIA ──
add_heading_styled('2B — Vetting Criteria: The 100-Point Scoring Rubric', 2)

add_body(
    'Not every famous investor belongs in the Engine. We need a rigorous, repeatable scoring system '
    'that separates genuine super investors from media personalities, lucky streaks, and closet indexers.'
)

add_callout_box(
    '"In the short run, the market is a voting machine, but in the long run, it is a weighing machine." '
    '— Benjamin Graham. Our rubric is the weighing machine for investors themselves.'
)

rubric_rows = [
    ['Track Record', '25', 'Minimum 10 years. Must beat S&P 500 by 3%+ annualized net of fees. 25 pts for 10%+ alpha, 20 pts for 5-10%, 15 pts for 3-5%. Deduct 5 pts if track record is unaudited.'],
    ['Philosophy Alignment', '20', 'Must demonstrate Graham/Buffett/Munger principles: intrinsic value, margin of safety, circle of competence, long-term orientation. 20 pts for full alignment, 15 pts for partial (e.g., Ackman\'s activism adds wrinkle), 10 pts for adjacent (quality growth). Score 0 for momentum/quant-only.'],
    ['Concentration', '15', 'Top 5 positions should represent 40%+ of equity portfolio. 15 pts for concentrated (>50% in top 5), 10 pts for semi-concentrated (30-50%), 5 pts for diversified. Score 0 for 100+ position index-huggers.'],
    ['Skin in the Game', '15', 'Personal capital invested alongside LPs. 15 pts for majority of personal net worth in fund, 10 pts for significant co-invest, 5 pts for token. Score 0 if unknown or confirmed absent.'],
    ['Transparency', '10', 'Publishes letters, speaks at conferences, explains reasoning publicly. 10 pts for full transparency (Buffett, Pabrai), 7 pts for periodic (annual letter only), 3 pts for 13F-only.'],
    ['Cycle Consistency', '10', 'Performance across bull AND bear markets. 10 pts for strong in both (Marks excels here), 7 pts for strong in one, 3 pts for untested. Bonus: survived 2008 intact.'],
    ['Intellectual Honesty', '5', 'Publicly discusses mistakes, not just wins. 5 pts for openly discusses errors (Buffett on Dexter Shoe, Pabrai on Horsehead), 3 pts for acknowledges mistakes privately, 0 pts for revisionist history.'],
]

make_table(
    ['Criterion', 'Max Points', 'Scoring Guide'],
    rubric_rows,
    col_widths=[1.5, 0.8, 4.7]
)

add_body('')
add_body('Scoring Thresholds:')
add_bullet('TIER 1 admission (Undisputed Legend)', bold_prefix='85-100 points: ')
add_bullet('TIER 2 admission (Proven Performer)', bold_prefix='70-84 points: ')
add_bullet('TIER 3 admission (Emerging/Promising)', bold_prefix='55-69 points: ')
add_bullet('TIER 4 Watchlist — monitor but don\'t clone', bold_prefix='40-54 points: ')
add_bullet('Do not track', bold_prefix='Below 40: ')

add_page_break()

# ── 2C: THE ROSTER ──
add_heading_styled('2C — The Roster', 2)

add_callout_box(
    '"You\'re looking for a mispriced gamble. That\'s what investing is. And you have to know enough to know '
    'whether the gamble is mispriced." — Charlie Munger. The roster below represents investors who have '
    'demonstrated they know how to find mispriced gambles, consistently, for decades.'
)

# TIER 1
add_subheading('TIER 1 — Undisputed Legends (Score: 85-100)')

tier1 = [
    ['Warren Buffett', 'Berkshire Hathaway', '$300B+', 'Yes (CIK: 0001067983)', 'Buy wonderful companies at fair prices; hold forever. Owner-operator mindset, circle of competence, margin of safety.', '98'],
    ['Charlie Munger (Legacy)', 'DJCO / Berkshire', 'N/A', 'DJCO filed 13F', 'Latticework of mental models. "Invert, always invert." Quality over cheapness. Last portfolio: concentrated in BofA, Wells, US Bancorp.', '97'],
    ['Li Lu', 'Himalaya Capital', '~$6B', 'Yes', 'Munger\'s only outside manager. Deep research, extreme concentration, long holding periods. Heavily weighted in BYD, Micron, Bank of America.', '95'],
    ['Seth Klarman', 'Baupost Group', '~$27B', 'Yes', 'Author of "Margin of Safety." Risk-averse deep value. Willing to hold 30-40% cash. Looks for catalysts.', '96'],
    ['Howard Marks', 'Oaktree Capital', '~$190B', 'Yes', 'Cycle expert. "The Most Important Thing." Distressed debt and contrarian equity. Master of second-level thinking.', '90'],
]

make_table(
    ['Investor', 'Fund', 'AUM Est.', '13F Filer?', 'One-Line Philosophy', 'Score'],
    tier1,
    col_widths=[1.0, 1.0, 0.6, 0.8, 2.8, 0.5]
)

doc.add_paragraph()

# TIER 2
add_subheading('TIER 2 — Proven Performers (Score: 70-84)')

tier2_a = [
    ['Mohnish Pabrai', 'Pabrai Investment Funds', '~$600M', 'Yes', 'Shameless cloner. "Heads I win, tails I don\'t lose much." Concentrated, catalyst-driven deep value.', '84'],
    ['Chuck Akre', 'Akre Capital Management', '~$12B', 'Yes', 'Three-legged stool: extraordinary business, talented management, great reinvestors. Quality compounders.', '82'],
    ['Guy Spier', 'Aquamarine Capital', '~$250M', 'Yes', 'Buffett disciple. Checklist investing. Patient, avoids toxic environments. "The Education of a Value Investor."', '78'],
    ['Terry Smith', 'Fundsmith', '~$23B', 'No (UK)', 'Buy good companies, don\'t overpay, do nothing. Low turnover. Track via Fundsmith.co.uk annual reports.', '83'],
    ['Tom Gayner', 'Markel Group', '~$8B equity', 'Yes', 'Insurance float investor (Buffett model). Patient, diversified quality. 30+ year track record at Markel.', '80'],
    ['Nick Sleep & Qais Zakaria', 'Nomad Investment (closed)', 'N/A', 'No (closed 2014)', '"Scale economies shared" — identified Amazon, Costco, GEICO model early. Letters are open-source gold.', '88*'],
    ['Chris Bloomstran', 'Semper Augustus', '~$800M', 'Yes', 'Deep Berkshire analyst. Annual letter is 100+ pages of valuation work. Concentrated quality value.', '76'],
    ['Bill Ackman', 'Pershing Square', '~$18B', 'Yes', 'Activist value. Large, concentrated bets. High-profile wins (Chipotle, Hilton) and losses (Valeant). Transparent.', '74'],
]

make_table(
    ['Investor', 'Fund', 'AUM Est.', '13F?', 'Philosophy', 'Score'],
    tier2_a,
    col_widths=[1.0, 1.0, 0.6, 0.6, 2.8, 0.5]
)

doc.add_paragraph()

tier2_b = [
    ['David Einhorn', 'Greenlight Capital', '~$3.5B', 'Yes', 'Event-driven value. Famous short-seller (Lehman). Quarterly letters are masterclasses in forensic accounting.', '75'],
    ['Prem Watsa', 'Fairfax Financial', '~$50B assets', 'SEDAR (Canada)', '"The Canadian Buffett." Insurance holding company. Contrarian, macro-aware, long-term. Annual letter mirrors Buffett\'s.', '79'],
    ['Pat Dorsey', 'Dorsey Asset Management', '~$400M', 'Yes', 'Former Morningstar head of equity research. Wrote "The Little Book That Builds Wealth." Moat-focused investing.', '72'],
]

make_table(
    ['Investor', 'Fund', 'AUM Est.', '13F?', 'Philosophy', 'Score'],
    tier2_b,
    col_widths=[1.0, 1.0, 0.6, 0.6, 2.8, 0.5]
)

add_body('*Note: Nick Sleep scores 88 on philosophy/track record but the fund is closed. We track for intellectual framework, not live positions.')

doc.add_paragraph()

# TIER 3
add_subheading('TIER 3 — Emerging / High-Potential (Score: 55-69)')

tier3 = [
    ['Francois Rochon', 'Giverny Capital', '~$700M', 'Partial (SEDAR)', '20+ year track record beating S&P. Quality growth at reasonable prices. Canadian with US equity focus.', '68'],
    ['Bryan Lawrence', 'Oakcliff Capital', '~$350M', 'Yes', 'Concentrated value. Munger-influenced. Low turnover. 10-15 positions.', '64'],
    ['Jake Taylor', 'Author / Podcaster', 'N/A', 'No', 'Co-host Value After Hours. Author of "The Rebel Allocator." Thought leader, mental models focus.', '58'],
    ['Allan Mecham', 'Arlington Value Capital', '~$400M', 'Yes', '"The unknown Buffett of Salt Lake City." Extremely concentrated. Minimal public presence but stellar returns.', '67'],
    ['Thomas Russo', 'Gardner Russo & Quinn', '~$8B', 'Yes', '"The capacity to suffer" — holds global compounders (Nestlé, Berkshire) through volatility. 30+ year record.', '69'],
    ['Christopher Hohn', 'TCI Fund Management', '~$40B', 'Yes', 'Activist quality compounder. Concentrated. Huge positions in railroads, Visa, Google.', '65'],
]

make_table(
    ['Investor', 'Fund', 'AUM Est.', '13F?', 'Philosophy', 'Score'],
    tier3,
    col_widths=[1.0, 1.1, 0.6, 0.6, 2.8, 0.5]
)

doc.add_paragraph()

# TIER 4
add_subheading('TIER 4 — Watchlist (Score: 40-54)')

add_body(
    'These investors are on the radar but haven\'t yet met our threshold for active tracking. '
    'Sources for discovery include Value Investors Club, SumZero, Substack, and conference presentations.'
)

add_bullet('Various managers surfaced via Value Investors Club idea posts')
add_bullet('SumZero members who consistently post high-quality long ideas')
add_bullet('Substack writers: Yet Another Value Blog (Andrew Walker), Kingswell (Alex Morris)')
add_bullet('New fund managers who spin out from Tier 1/2 firms (e.g., former Baupost analysts)')
add_bullet('Berkshire Hathaway annual meeting "stock pitch" events')
add_bullet('International managers profiled in The Manual of Ideas')

add_callout_box(
    'The watchlist is dynamic. Tier 4 investors are promoted to Tier 3 when they accumulate sufficient '
    'track record and pass the scoring rubric. The system should surface promotion candidates quarterly.'
)

add_page_break()

# ══════════════════════════════════════════════════════════════
# SECTION 3 — DATA COLLECTION ARCHITECTURE
# ══════════════════════════════════════════════════════════════

add_heading_styled('SECTION 3 — DATA COLLECTION ARCHITECTURE', 1)
add_gold_divider()

add_body(
    'The system\'s value is directly proportional to the quality and timeliness of its data. '
    'This section maps every data source, its characteristics, and the automation strategy for each.'
)

add_callout_box(
    '"In God we trust; all others must bring data." — W. Edwards Deming. '
    'The Engine will be as good as the data pipeline feeding it.'
)

add_subheading('Data Source Matrix')

data_sources = [
    ['SEC EDGAR 13F', 'Portfolio holdings snapshot (long equity positions >$200K)', 'Quarterly (45 days after quarter-end)', 'EDGAR FULL-TEXT SEARCH API + sec-edgar-downloader (Python)', 'Fully Automated', '$0'],
    ['SEC Form 4', 'Insider buy/sell transactions at portfolio companies', 'Within 2 business days of transaction', 'EDGAR API, OpenInsider.com scraping', 'Fully Automated', '$0'],
    ['SEC 13D/13G', 'Activist stakes (5%+ ownership)', 'Within 10 days of crossing 5%', 'EDGAR API keyword monitoring', 'Fully Automated', '$0'],
    ['Shareholder Letters', 'Philosophy, reasoning, portfolio commentary', 'Annual/Quarterly', 'Fund websites, manual download, OCR if needed', 'Semi-Automated', '$0'],
    ['Conference Presentations', 'New ideas, updated theses', 'Annual (conference-specific)', 'YouTube transcripts, conference websites', 'Semi-Automated', '$0'],
    ['YouTube Channels', 'Investor analysis, interview transcripts, portfolio updates', 'Ongoing', 'YouTube API + Whisper transcription', 'Semi-Automated', '$0'],
    ['Alpha Vantage API', 'Stock prices, fundamentals, earnings', 'Daily', 'REST API (free tier: 5 calls/min)', 'Fully Automated', '$0'],
    ['Financial Modeling Prep', 'Financial statements, ratios, DCF data', 'Quarterly', 'REST API (free: 250 calls/day)', 'Fully Automated', '$0'],
    ['GuruFocus', '13F tracking, guru portfolios, 10-year financials, screeners', 'Quarterly (13F) + Daily (articles)', 'Web + API ($30/mo Premium)', 'Semi-Automated', '$30/mo'],
    ['WhaleWisdom', '13F aggregation, smart money flow, 13F comparisons', 'Quarterly', 'Web scraping + free tier API', 'Semi-Automated', '$0'],
    ['HedgeFollow', 'Hedge fund 13F tracking, top picks aggregation', 'Quarterly', 'Web scraping', 'Semi-Automated', '$0'],
    ['Insider Monkey', '13F tracking, insider buying, hedge fund sentiment', 'Quarterly + Daily articles', 'Web scraping', 'Semi-Automated', '$0'],
    ['Dataroma', '13F aggregation, "superinvestor" portfolios', 'Quarterly', 'Web scraping (no API)', 'Semi-Automated', '$0'],
    ['Podcast Transcripts', 'Investor commentary, new ideas, philosophy updates', 'Weekly', 'RSS feed + Whisper local transcription', 'Fully Automated', '$0'],
    ['SEDAR+ (Canada)', 'Canadian filer portfolios (Fairfax, Giverny)', 'Quarterly/Annual', 'SEDAR+ website, manual download', 'Manual Review', '$0'],
    ['Companies House (UK)', 'UK fund manager filings (Fundsmith)', 'Annual', 'Companies House API (free)', 'Semi-Automated', '$0'],
    ['Seeking Alpha', 'Articles on super investor moves, earnings analysis', 'Daily', 'RSS feed monitoring (Joe has Premium)', 'Semi-Automated', '$0*'],
]

make_table(
    ['Source', 'What It Provides', 'Frequency', 'Access Method', 'Automation Level', 'Cost'],
    data_sources,
    col_widths=[1.0, 1.3, 0.8, 1.5, 0.9, 0.5]
)

add_body('* Joe\'s existing Seeking Alpha Premium subscription')

add_subheading('Technical Implementation Details')

add_heading_styled('SEC EDGAR Pipeline (Primary Data Source)', 3)
add_body('The backbone of the system. Python-based, fully automated.')

add_bullet('sec-edgar-downloader — Python library for bulk downloading 13F, 13D, Form 4 filings', bold_prefix='Library: ')
add_bullet('Python script runs quarterly (triggered by cron or OpenClaw scheduler)', bold_prefix='Automation: ')
add_bullet('Parse 13F XML into structured JSON → SQLite database', bold_prefix='Processing: ')
add_bullet('Compare current quarter vs. previous quarter → generate "changes" report', bold_prefix='Diffing: ')
add_bullet('New positions, exited positions, increased/decreased positions', bold_prefix='Output: ')

add_body('Sample EDGAR API endpoint for 13F filings:')
p = doc.add_paragraph()
run = p.add_run('https://efts.sec.gov/LATEST/search-index?q="13F"&dateRange=custom&startdt=2026-01-01&forms=13F-HR')
run.font.name = 'Courier New'
run.font.size = Pt(9)
run.font.color.rgb = MED_GRAY

add_heading_styled('Local AI Processing Pipeline (Qwen 2.5 7B)', 3)
add_body('Joe\'s Mac Mini M4 running Ollama with Qwen 2.5 7B handles all initial processing:')

add_bullet('Ingest raw SEC filings, extract key changes, flag significant moves', bold_prefix='Parsing & Extraction: ')
add_bullet('Scan news headlines, YouTube transcripts, podcast summaries for investor names/companies', bold_prefix='News Filtering: ')
add_bullet('Parse shareholder letters to extract portfolio changes and reasoning', bold_prefix='Letter Analysis: ')
add_bullet('First-pass ranking of information by relevance/urgency', bold_prefix='Priority Scoring: ')
add_bullet('$0 marginal cost. Runs overnight. Mac Mini M4 handles 7B model easily.', bold_prefix='Cost: ')

add_heading_styled('Cloud AI Escalation (Claude via Rob Lobster)', 3)
add_body('Claude/Rob is invoked ONLY when Qwen flags something worth deep analysis:')

add_bullet('New position from Tier 1 investor in a company Joe doesn\'t own', bold_prefix='Trigger 1: ')
add_bullet('Convergence — 3+ tracked investors buying the same stock', bold_prefix='Trigger 2: ')
add_bullet('Major exit from a position Joe holds', bold_prefix='Trigger 3: ')
add_bullet('Activist filing (13D) from a tracked investor', bold_prefix='Trigger 4: ')
add_bullet('Estimated 2-5 Claude API calls per week = ~$0.50-2.00/week', bold_prefix='Cost: ')

add_page_break()

# ══════════════════════════════════════════════════════════════
# SECTION 4 — INVESTOR PROFILE STRUCTURE
# ══════════════════════════════════════════════════════════════

add_heading_styled('SECTION 4 — INVESTOR PROFILE STRUCTURE', 1)
add_gold_divider()

add_body(
    'Each tracked investor gets a "living profile" — a structured document that evolves over time '
    'as new filings, letters, interviews, and moves are recorded. Think of it as a permanent dossier '
    'on each investor\'s mind.'
)

add_callout_box(
    '"I insist on a lot of time being spent, almost every day, to just sit and think." — Warren Buffett. '
    'These profiles are designed to let you think alongside the best investors in the world.'
)

add_subheading('Profile Template: 11 Sections Per Investor')

# Section details
profile_sections = [
    ('1. Background & Origin Story', 
     'Where they came from, what shaped them, their path to investing. Li Lu\'s escape from China during '
     'Tiananmen Square. Pabrai\'s immigration from India with $100. Klarman\'s mentorship under Michael Price. '
     'This section matters because an investor\'s history predicts their behavior under stress.'),
    
    ('2. Philosophy In Their Own Words',
     'Direct quotes sourced from letters, interviews, and books. Not our interpretation — their actual words. '
     'Example for Munger: "All I want to know is where I\'m going to die, so I\'ll never go there." '
     'Example for Pabrai: "Heads I win, tails I don\'t lose much." Each quote tagged with source and date.'),
    
    ('3. Key Mental Models',
     'The frameworks they use to make decisions. Munger\'s latticework: psychology of misjudgment, '
     'inversion, circle of competence. Marks\'s second-level thinking and cycle positioning. '
     'Akre\'s three-legged stool (business quality, management talent, reinvestment runway). '
     'Mapped to our own decision-making checklist.'),
    
    ('4. Notable Wins AND Mistakes',
     'Wins: Buffett\'s Apple position, Li Lu\'s BYD, Pabrai\'s Fiat Chrysler, Ackman\'s Chipotle. '
     'Mistakes: Buffett\'s Dexter Shoe, Ackman\'s Valeant, Einhorn\'s long Brighthouse/short Tesla, '
     'Pabrai\'s Horsehead Holdings. The mistakes section is MORE valuable than wins — it reveals '
     'what to watch for and how they respond to being wrong.'),
    
    ('5. Current Portfolio (Most Recent 13F)',
     'Structured data from the most recent 13F filing. Top 10 positions with: company name, ticker, '
     'shares held, market value, % of portfolio, quarter-over-quarter change (new/increased/decreased/unchanged). '
     'Auto-updated every quarter when new 13F drops.'),
    
    ('6. Historical Portfolio Evolution',
     'Multi-year view of how the portfolio has changed. What\'s been held for 5+ years (highest conviction)? '
     'What was added and sold within 2 quarters (possible mistake or quick trade)? Average holding period. '
     'Turnover rate vs. benchmark. Tracks "conviction drift" — when an investor starts behaving differently.'),
    
    ('7. Concentration Patterns',
     'Herfindahl index of portfolio concentration over time. Is this investor getting more or less concentrated? '
     'Pabrai typically holds 5-10 positions. Klarman holds 20-30 but with 30% cash. Buffett\'s top 5 are 70%+ of portfolio. '
     'Pattern changes signal strategy shifts worth understanding.'),
    
    ('8. Sector Tendencies',
     'Heat map of sector allocation over time. Buffett: financials heavy, tech-avoiding (until Apple). '
     'Li Lu: financials + tech (BYD, Micron). Akre: financials + tech (Mastercard, Visa). '
     'Marks: credit/distressed primarily. Useful for understanding when an investor ventures OUTSIDE their '
     'typical sector — that signals high conviction.'),
    
    ('9. Buy/Sell Triggers',
     'What conditions cause this investor to act? Klarman buys catalysts + margin of safety. '
     'Buffett buys when "wonderful company available at fair price" or during market panics. '
     'Pabrai buys on "shameless cloning" + independent thesis. Einhorn buys on accounting anomalies. '
     'Understanding triggers helps predict WHEN they\'ll move, not just what they\'ll buy.'),
    
    ('10. Relationships to Other Tracked Investors',
     'The super investor network is real. Pabrai and Spier are best friends (both Buffett disciples). '
     'Li Lu was mentored by Munger. Bloomstran\'s deepest analysis is on Berkshire. Einhorn and Ackman '
     'have publicly clashed. These relationships create "information chains" — when Pabrai buys something '
     'Spier already owns, the signal is different than an independent discovery.'),
    
    ('11. Personal Characteristics Affecting Style',
     'Pabrai\'s immigrant mindset → extreme loss aversion → "tails I don\'t lose much." '
     'Marks\'s credit background → focus on cycles and downside protection. '
     'Ackman\'s personality → high-profile activism, willingness to fight publicly. '
     'Spier\'s move to Zurich → explicitly designed to reduce noise and improve decisions. '
     'These personal factors explain WHY they invest differently, which helps predict their behavior.'),
]

for title, description in profile_sections:
    p = doc.add_paragraph()
    run = p.add_run(title)
    run.bold = True
    run.font.color.rgb = NAVY
    run.font.size = Pt(12)
    run.font.name = 'Calibri'
    add_body(description)

add_subheading('Profile Storage & Format')
add_bullet('One Markdown file per investor in ~/workspace/projects/investing/profiles/', bold_prefix='File Structure: ')
add_bullet('JSON database (SQLite) for structured data (13F holdings, scores, metadata)', bold_prefix='Database: ')
add_bullet('Qwen 2.5 appends new information; Rob/Claude reviews and synthesizes quarterly', bold_prefix='Update Process: ')
add_bullet('Git-tracked for version history — every change to a profile is versioned', bold_prefix='Version Control: ')

add_page_break()

# ══════════════════════════════════════════════════════════════
# SECTION 5 — NIGHTLY INTELLIGENCE SWEEP
# ══════════════════════════════════════════════════════════════

add_heading_styled('SECTION 5 — NIGHTLY INTELLIGENCE SWEEP', 1)
add_gold_divider()

add_body(
    'The most valuable part of the system. While Joe sleeps, the Engine scans the information landscape '
    'for signals — new investor moves, public statements, news about portfolio companies, and emerging '
    'opportunities. By morning, a curated intelligence brief is ready.'
)

add_subheading('Architecture: Two-Tier AI Processing')

p = doc.add_paragraph()
run = p.add_run('TIER 1: Qwen 2.5 7B (Local — $0 Cost)')
run.bold = True
run.font.color.rgb = NAVY
run.font.size = Pt(13)
run.font.name = 'Calibri'

add_body('Runs on Mac Mini M4 via Ollama. Handles 90%+ of nightly processing:')

add_bullet('Check SEC EDGAR for new 13F, Form 4, 13D/13G filings from tracked investors (EDGAR RSS feed)', bold_prefix='Task 1 — Filing Check: ')
add_bullet('Scan Google News, Seeking Alpha RSS, Bloomberg RSS for mentions of tracked investors or their portfolio companies', bold_prefix='Task 2 — News Scan: ')
add_bullet('Check tracked YouTube channels for new videos mentioning super investors or their holdings', bold_prefix='Task 3 — YouTube Monitor: ')
add_bullet('Check podcast RSS feeds for new episodes featuring tracked investors', bold_prefix='Task 4 — Podcast Check: ')
add_bullet('Scan GuruFocus, WhaleWisdom, HedgeFollow for updated portfolio data', bold_prefix='Task 5 — Aggregator Scan: ')
add_bullet('Parse all collected data, score relevance (1-10), discard noise (score <4)', bold_prefix='Task 6 — Filter & Score: ')
add_bullet('Generate structured JSON summary of all findings for Claude review', bold_prefix='Task 7 — Summarize: ')

p = doc.add_paragraph()
run = p.add_run('TIER 2: Claude / Rob Lobster (Cloud — Triggered Only)')
run.bold = True
run.font.color.rgb = NAVY
run.font.size = Pt(13)
run.font.name = 'Calibri'

add_body('Invoked only when Qwen flags items scoring 7+ or matching specific triggers:')

add_bullet('New position from Tier 1 investor (any) or new concentrated position from Tier 2', bold_prefix='Trigger: ')
add_bullet('3+ tracked investors accumulating the same stock in the same quarter', bold_prefix='Convergence Alert: ')
add_bullet('Tracked investor exits a position Joe currently holds', bold_prefix='Exit Warning: ')
add_bullet('New 13D/13G activist filing from any tracked investor', bold_prefix='Activist Alert: ')
add_bullet('Tracked investor makes public statement contradicting their previous position', bold_prefix='Philosophy Shift: ')

add_body('Claude\'s role: synthesize context, write the analysis, connect to Joe\'s existing portfolio and thesis.')

add_subheading('The Morning Intelligence Brief')

add_callout_box(
    'Delivered daily by 6:30 AM ET as part of Joe\'s existing morning package via OpenClaw/Telegram. '
    'Designed to be read in 3-5 minutes with the first cup of coffee.'
)

add_body('FORMAT:')

p = doc.add_paragraph()
run = p.add_run('═══ MARGIN OF SAFETY ENGINE — MORNING BRIEF ═══')
run.font.name = 'Courier New'
run.font.size = Pt(10)
run.font.color.rgb = NAVY
run.bold = True

p = doc.add_paragraph()
run = p.add_run('Thursday, April 3, 2026  |  Market: S&P 500 closed 5,847 (+0.3%)')
run.font.name = 'Courier New'
run.font.size = Pt(9)
run.font.color.rgb = MED_GRAY

brief_sections = [
    '🔴 RED ALERTS (Immediate Attention)',
    '   → Li Lu filed 13F showing new 8% position in [Company X]',
    '   → This stock is in Joe\'s "Deep Dive" queue. Convergence score: HIGH.',
    '',
    '🟡 NOTABLE MOVES (Review When Convenient)',
    '   → Pabrai increased Micron position by 15% (now 22% of portfolio)',
    '   → Ackman\'s Pershing Square initiated new position in Brookfield Corp',
    '   → Terry Smith\'s Fundsmith annual report released — top holding changes noted',
    '',
    '🟢 BACKGROUND INTELLIGENCE (FYI)',
    '   → New Swedish Investor video: "How Li Lu Thinks About Investing"',
    '   → Einhorn\'s quarterly letter leaked on ValueWalk — summary attached',
    '   → Seeking Alpha article on Buffett\'s Berkshire concentration in Apple',
    '',
    '📊 CONVERGENCE DASHBOARD SNAPSHOT',
    '   → 4 tracked investors hold Constellation Software (CSU.TO)',
    '   → 3 tracked investors hold Brookfield Asset Management',
    '   → 3 tracked investors recently added to financial sector',
    '',
    '📅 UPCOMING',
    '   → Berkshire 13F due: ~May 15 (Q1 2026 holdings)',
    '   → Pabrai annual meeting: July (date TBD)',
    '   → Next 13F filing window opens: August 14',
    '',
    '═══════════════════════════════════════════════',
    'Sources scanned: 47 | Items processed: 312 | Escalated to Claude: 3',
    'Processing cost: $0.00 (local) + $0.12 (Claude) = $0.12 total',
]

for line in brief_sections:
    p = doc.add_paragraph()
    run = p.add_run(line)
    run.font.name = 'Courier New'
    run.font.size = Pt(9)
    if line.startswith('🔴'):
        run.font.color.rgb = RGBColor(0xCC, 0x00, 0x00)
        run.bold = True
    elif line.startswith('🟡'):
        run.font.color.rgb = GOLD
        run.bold = True
    elif line.startswith('🟢'):
        run.font.color.rgb = RGBColor(0x00, 0x80, 0x00)
        run.bold = True
    elif line.startswith('📊') or line.startswith('📅'):
        run.font.color.rgb = NAVY
        run.bold = True
    else:
        run.font.color.rgb = DARK_GRAY

add_subheading('Nightly Schedule')

schedule_rows = [
    ['12:00 AM', 'SEC EDGAR filing check', 'Qwen 2.5', '~2 min'],
    ['12:05 AM', 'News headline scan (Google News, SA, Bloomberg RSS)', 'Qwen 2.5', '~5 min'],
    ['12:15 AM', 'YouTube channel check (new videos from tracked channels)', 'Qwen 2.5', '~3 min'],
    ['12:20 AM', 'Podcast RSS feed check', 'Qwen 2.5', '~2 min'],
    ['12:25 AM', 'Aggregator scan (GuruFocus, WhaleWisdom, HedgeFollow)', 'Qwen 2.5', '~5 min'],
    ['12:35 AM', 'Relevance scoring and filtering', 'Qwen 2.5', '~3 min'],
    ['12:40 AM', 'Claude escalation (if triggers met)', 'Claude API', '~2-5 min'],
    ['12:50 AM', 'Brief generation and formatting', 'Qwen 2.5', '~2 min'],
    ['1:00 AM', 'Brief staged for morning delivery', 'OpenClaw', 'Instant'],
    ['6:30 AM', 'Brief delivered to Joe via Telegram', 'OpenClaw', 'Instant'],
]

make_table(
    ['Time (ET)', 'Task', 'Processor', 'Duration'],
    schedule_rows,
    col_widths=[1.0, 3.0, 1.2, 0.8]
)

add_subheading('Cost Estimate: Nightly Sweep')

make_table(
    ['Component', 'Daily Cost', 'Monthly Cost', 'Annual Cost'],
    [
        ['Qwen 2.5 processing (electricity only)', '$0.01', '$0.30', '$3.65'],
        ['Claude API (avg 3 escalations/week)', '$0.05', '$1.50', '$18.00'],
        ['SEC EDGAR API', '$0.00', '$0.00', '$0.00'],
        ['YouTube Data API (free tier)', '$0.00', '$0.00', '$0.00'],
        ['TOTAL', '$0.06', '$1.80', '$21.65'],
    ],
    col_widths=[2.5, 1.2, 1.2, 1.2]
)

add_callout_box(
    'Total annual operating cost of the nightly sweep: approximately $22. '
    'Less than the price of one month of a typical investment newsletter. '
    'The system pays for itself if it surfaces even one good idea per year.'
)

add_page_break()

# ══════════════════════════════════════════════════════════════
# SECTION 6 — CLONING STRATEGY & INTEGRATION
# ══════════════════════════════════════════════════════════════

add_heading_styled('SECTION 6 — CLONING STRATEGY & INTEGRATION', 1)
add_gold_divider()

add_body(
    'Cloning is not copying. It\'s using the disclosed positions of proven investors as an '
    'idea generation and thesis validation tool. The goal is to find high-conviction ideas '
    'that align with YOUR investment philosophy, then do your own work.'
)

add_callout_box(
    '"If you\'re going to copy somebody, you might as well copy the best." — Mohnish Pabrai. '
    'Pabrai has been explicit: shameless cloning is a legitimate and powerful strategy when '
    'combined with independent analysis.'
)

add_subheading('Convergence Scoring')

add_body(
    'The most powerful signal in the system. When multiple independent super investors — each with '
    'their own research teams, information sources, and analytical frameworks — independently arrive '
    'at the same conclusion, the probability of that thesis being correct increases dramatically.'
)

add_body('Convergence Score Calculation:')

conv_rows = [
    ['1 Tier 1 investor holds position', '+20 points', 'High baseline credibility'],
    ['1 Tier 2 investor holds position', '+10 points', 'Proven but less weight'],
    ['1 Tier 3 investor holds position', '+5 points', 'Emerging signal'],
    ['Position is top 5 for the investor', '+10 bonus', 'High conviction'],
    ['Position is NEW this quarter', '+15 bonus', 'Active decision signal'],
    ['Position was INCREASED this quarter', '+5 bonus', 'Doubling down'],
    ['Investor has discussed thesis publicly', '+10 bonus', 'Reasoning is transparent'],
    ['Position aligns with Joe\'s existing bucket strategy', '+10 bonus', 'Portfolio fit'],
]

make_table(
    ['Signal', 'Points', 'Rationale'],
    conv_rows,
    col_widths=[2.5, 1.0, 3.5]
)

add_body('')
add_body('Convergence Thresholds:')
add_bullet('Strong Buy Signal — multiple high-conviction indicators across multiple investors', bold_prefix='80+ points: ')
add_bullet('Research Priority — worthy of immediate deep dive', bold_prefix='60-79 points: ')
add_bullet('Watchlist — monitor for additional signals', bold_prefix='40-59 points: ')
add_bullet('Background — note but don\'t prioritize', bold_prefix='Below 40: ')

add_subheading('Timing Adjustment: The 13F Staleness Problem')

add_body(
    '13F filings are reported as of quarter-end but not due until 45 days later. By the time you see '
    'Buffett\'s March 31 portfolio, it\'s already May 15. The stock may have moved significantly.'
)

add_body('Mitigation Strategies:')
add_bullet('If the stock has risen 20%+ since quarter-end, the 13F signal is stale. Wait for a pullback or move on.', bold_prefix='Price Gap Analysis: ')
add_bullet('Form 4 filings are near real-time. If insiders at the target company are also buying, signal strengthens.', bold_prefix='Form 4 Cross-Reference: ')
add_bullet('Monitor news for hints of activity before 13F drops. Buffett\'s Berkshire occasionally files for confidential treatment, suggesting active accumulation.', bold_prefix='News Leading Indicators: ')
add_bullet('If an investor discussed the thesis at a conference 2 months ago but the 13F confirms the position, the thesis is still valid even if the price moved.', bold_prefix='Thesis Durability: ')
add_bullet('For true long-term positions (Buffett\'s Apple, Li Lu\'s BYD), a 10-20% price move since quarter-end is noise over a 10-year horizon.', bold_prefix='Value Investor Timeframe: ')

add_subheading('Style Bucketing')

add_body(
    'Not all super investors are the same. Cloning strategy must account for style differences. '
    'This maps directly to Joe\'s existing three-bucket portfolio structure.'
)

style_rows = [
    ['Deep Value', 'Klarman, Einhorn, Pabrai', 'Cheap on metrics, often ugly businesses, catalyst-dependent', 'Opportunistic Value (5-7yr bucket)'],
    ['Quality Compounders', 'Akre, Dorsey, Terry Smith, Tom Gayner', 'Great businesses at fair prices, long runways, high ROIC', 'Core Forever Holdings (40yr bucket)'],
    ['Special Situations', 'Ackman (activist), Marks (distressed)', 'Event-driven, turnarounds, distressed debt', 'Opportunistic Value (selective)'],
    ['Growth at Reasonable Price', 'Li Lu, Rochon, Thomas Russo', 'Growing businesses with moats, willing to pay fair price', 'Core Forever or 20-Year Innovation'],
    ['Insurance Float Model', 'Buffett, Gayner, Watsa', 'Use insurance float to invest. Unique structure.', 'Study model; buy the holdcos directly'],
]

make_table(
    ['Style Bucket', 'Primary Practitioners', 'Characteristics', 'Maps to Joe\'s Bucket'],
    style_rows,
    col_widths=[1.2, 1.5, 2.3, 2.0]
)

add_subheading('The Conviction Overlap Dashboard (Concept)')

add_body(
    'A visual tool showing which stocks appear across multiple tracked investor portfolios. '
    'This will be built as an interactive HTML dashboard (Joe\'s preferred format for analysis tools).'
)

add_body('Dashboard Elements:')
add_bullet('Stock names on Y-axis, investor names on X-axis. Cell color intensity = position size as % of portfolio. Hovering shows dollar value and quarter-over-quarter change.', bold_prefix='Heat Map: ')
add_bullet('Stocks sorted by convergence score. The stock held by the most investors with the highest conviction rises to the top.', bold_prefix='Convergence Leaderboard: ')
add_bullet('Major changes this quarter — new positions, exits, size changes — color-coded by direction.', bold_prefix='Movement Tracker: ')
add_bullet('Overlay Joe\'s current positions to instantly see alignment and gaps.', bold_prefix='Joe\'s Portfolio Overlay: ')
add_bullet('For each stock, the dashboard links to the full analysis: who holds it, why, how long, and any public commentary on the thesis.', bold_prefix='Drill-Down: ')

add_subheading('What NOT to Blindly Clone')

add_body(
    'The Engine must enforce discipline about what signals to ignore. Not every super investor move '
    'is relevant to Joe\'s situation.'
)

add_bullet('Buffett manages $300B+. He CANNOT buy small-caps even if he wants to. His universe is limited to mega-caps. Joe\'s ~$1.9M portfolio can buy things Buffett can\'t touch — this is an advantage, not a limitation.', bold_prefix='Position Sizing Mismatch: ')
add_bullet('Institutional investors face different tax situations (tax-exempt endowments, offshore structures, loss harvesting at scale). A move that\'s tax-optimal for Baupost may be tax-inefficient for Joe\'s IRA/taxable mix.', bold_prefix='Tax Situation Differences: ')
add_bullet('Ackman\'s activist positions require board seats and public campaigns. Joe can\'t replicate the catalyst. Marks\'s distressed debt positions require institutional minimums and illiquidity tolerance.', bold_prefix='Institutional Constraints: ')
add_bullet('Some positions are hedges, pairs trades, or part of a broader strategy invisible in 13F data. Klarman\'s portfolio includes options not fully visible in 13F.', bold_prefix='Hedging/Derivatives: ')
add_bullet('By the time you see it, the investor may have already sold. Cross-reference with subsequent Form 4s and news.', bold_prefix='Stale Positions: ')

add_callout_box(
    'Golden Rule: Clone the IDEA, not the position. If Li Lu buys Company X, your job is to understand '
    'WHY and decide if the thesis applies to YOUR situation — not to buy the same number of shares.'
)

add_subheading('Integration with Joe\'s April 30 Portfolio Restructuring')

add_body(
    'Joe\'s planned April 30, 2026 restructuring — moving from 14 positions + $1.7M cash into a '
    'concentrated 29-stock portfolio across three buckets — is the perfect first application of the Engine.'
)

add_bullet('Run convergence analysis on Joe\'s proposed 29 stocks. How many are held by tracked super investors? At what conviction level?', bold_prefix='Pre-Restructuring Validation: ')
add_bullet('Identify stocks NOT on Joe\'s list that score 60+ on convergence. Are there better opportunities in the Engine\'s data?', bold_prefix='Gap Analysis: ')
add_bullet('Cross-reference Joe\'s proposed allocation with super investor concentration patterns. Is Joe overweight in a sector where the super investors are underweight?', bold_prefix='Allocation Check: ')
add_bullet('For each stock in the final portfolio, document which super investors hold it and their thesis. This creates a "thesis file" for each position that can be monitored over time.', bold_prefix='Thesis Documentation: ')
add_bullet('After April 30, the Engine monitors all positions for super investor activity. If Buffett exits a stock Joe holds, the Engine flags it immediately.', bold_prefix='Post-Restructuring Monitoring: ')

add_page_break()

# ══════════════════════════════════════════════════════════════
# IMPLEMENTATION PHASES
# ══════════════════════════════════════════════════════════════

add_heading_styled('IMPLEMENTATION ROADMAP', 1)
add_gold_divider()

add_callout_box(
    'Phased approach. Build the foundation first, expand systematically. Each phase delivers '
    'standalone value — even Phase 1 alone would improve Joe\'s process.'
)

# Phase 1
add_subheading('Phase 1: Foundation (Weeks 1-2)')
add_body('Goal: SEC EDGAR pipeline for core investors + first weekly report')

phase1_rows = [
    ['Build SEC EDGAR scraper', 'Python script using sec-edgar-downloader', '2 days', 'Rob + coding agent'],
    ['Set up SQLite database', 'Schema for investors, filings, holdings, changes', '1 day', 'Rob + coding agent'],
    ['Configure 5 core investors', 'Buffett, Li Lu, Pabrai, Akre, Klarman', '1 day', 'Rob'],
    ['Historical 13F backfill', 'Load last 8 quarters of 13F data for each', '2 days', 'Automated'],
    ['Build diff engine', 'Quarter-over-quarter change detection', '2 days', 'Rob + coding agent'],
    ['Generate first weekly report', 'Markdown report of current holdings + changes', '1 day', 'Rob'],
    ['Investor profile templates', 'Create Markdown templates for 5 core investors', '2 days', 'Rob'],
]

make_table(
    ['Task', 'Details', 'Est. Time', 'Owner'],
    phase1_rows,
    col_widths=[1.8, 2.5, 0.8, 1.2]
)

add_body('Phase 1 Deliverable: Weekly email/Telegram report showing what 5 core investors own and what changed.')

# Phase 2
doc.add_paragraph()
add_subheading('Phase 2: Expansion (Weeks 3-4)')
add_body('Goal: Full roster tracking + Form 4/13D + living profiles')

phase2_rows = [
    ['Expand to full roster', 'Add all Tier 1-3 investors (20+ total)', '2 days', 'Rob'],
    ['Add Form 4 tracking', 'Insider transaction monitoring for portfolio companies', '2 days', 'Rob + coding agent'],
    ['Add 13D/13G tracking', 'Activist stake monitoring', '1 day', 'Rob + coding agent'],
    ['Build investor profiles', 'Populate all 11 sections for Tier 1 investors', '5 days', 'Rob'],
    ['Convergence scoring v1', 'Basic overlap analysis across all tracked investors', '2 days', 'Rob + coding agent'],
    ['Integration testing', 'Full pipeline test: filing → parse → database → report', '1 day', 'Rob'],
]

make_table(
    ['Task', 'Details', 'Est. Time', 'Owner'],
    phase2_rows,
    col_widths=[1.8, 2.5, 0.8, 1.2]
)

add_body('Phase 2 Deliverable: Comprehensive portfolio tracking for 20+ investors with convergence analysis.')

# Phase 3
doc.add_paragraph()
add_subheading('Phase 3: Intelligence (Month 2)')
add_body('Goal: Nightly sweep + news/YouTube monitoring + convergence dashboard')

phase3_rows = [
    ['Nightly sweep automation', 'Cron job running Qwen 2.5 pipeline', '3 days', 'Rob + coding agent'],
    ['News monitoring', 'RSS feed integration + Qwen filtering', '2 days', 'Rob + coding agent'],
    ['YouTube channel monitoring', 'YouTube API + transcript extraction', '2 days', 'Rob + coding agent'],
    ['Morning Intelligence Brief', 'Automated daily brief generation + Telegram delivery', '2 days', 'Rob'],
    ['Convergence dashboard', 'Interactive HTML dashboard with heat map', '3 days', 'Rob + coding agent'],
    ['Claude escalation logic', 'Trigger-based Claude API calls for deep analysis', '2 days', 'Rob'],
    ['Podcast monitoring', 'RSS + Whisper transcription pipeline', '2 days', 'Rob + coding agent'],
]

make_table(
    ['Task', 'Details', 'Est. Time', 'Owner'],
    phase3_rows,
    col_widths=[1.8, 2.5, 0.8, 1.2]
)

add_body('Phase 3 Deliverable: Fully automated nightly intelligence sweep with morning brief delivery.')

# Phase 4
doc.add_paragraph()
add_subheading('Phase 4: Full Platform (Month 3)')
add_body('Goal: Historical analysis, cloning recommendations, full intelligence platform')

phase4_rows = [
    ['Historical performance tracking', 'Backtest: what if you cloned each investor for 10 years?', '3 days', 'Rob + coding agent'],
    ['Cloning recommendation engine', 'Automated buy/watch/ignore scoring for convergence signals', '3 days', 'Rob + coding agent'],
    ['International filing integration', 'SEDAR+ for Canadian, Companies House for UK managers', '2 days', 'Rob + coding agent'],
    ['Portfolio integration', 'Overlay Joe\'s actual portfolio on dashboard', '2 days', 'Rob + coding agent'],
    ['Shareholder letter archive', 'Searchable database of investor letters with key quotes tagged', '3 days', 'Rob'],
    ['System documentation', 'Full user guide + maintenance procedures', '2 days', 'Rob'],
    ['Quarterly review process', 'Template for quarterly Engine review + investor rescoring', '1 day', 'Rob'],
]

make_table(
    ['Task', 'Details', 'Est. Time', 'Owner'],
    phase4_rows,
    col_widths=[1.8, 2.5, 0.8, 1.2]
)

add_body('Phase 4 Deliverable: Complete intelligence platform with historical analysis, recommendations, and full documentation.')

add_page_break()

# ══════════════════════════════════════════════════════════════
# APPENDIX
# ══════════════════════════════════════════════════════════════

add_heading_styled('APPENDIX — COST ESTIMATES & TECHNICAL REQUIREMENTS', 1)
add_gold_divider()

add_subheading('Total Cost Summary')

cost_rows = [
    ['SEC EDGAR API', 'Free', '$0', '$0'],
    ['Alpha Vantage (free tier)', 'Free', '$0', '$0'],
    ['Financial Modeling Prep (free tier)', 'Free', '$0', '$0'],
    ['WhaleWisdom (free tier)', 'Free', '$0', '$0'],
    ['HedgeFollow', 'Free', '$0', '$0'],
    ['Dataroma', 'Free', '$0', '$0'],
    ['Insider Monkey (free tier)', 'Free', '$0', '$0'],
    ['Qwen 2.5 local processing', 'Free (electricity)', '$0.30', '$3.65'],
    ['Claude API (escalation only)', 'Pay per use', '$1.50-10', '$18-120'],
    ['YouTube Data API (free tier)', 'Free', '$0', '$0'],
    ['GuruFocus Premium (optional)', '$30/month', '$30', '$360'],
    ['TOTAL (without GuruFocus)', '', '$1.80-10.30', '$21.65-123.65'],
    ['TOTAL (with GuruFocus)', '', '$31.80-40.30', '$381.65-483.65'],
]

make_table(
    ['Service', 'Tier', 'Monthly Est.', 'Annual Est.'],
    cost_rows,
    col_widths=[2.5, 1.5, 1.2, 1.2]
)

add_callout_box(
    'Recommended: Start without GuruFocus. The free data sources cover 80% of what we need. '
    'Add GuruFocus Premium ($30/mo) in Phase 3 if the free sources prove insufficient. '
    'Total Year 1 cost: approximately $22-124 depending on Claude usage.'
)

add_subheading('Technical Requirements')

add_body('All requirements are ALREADY MET by Joe\'s current infrastructure:')

tech_rows = [
    ['Mac Mini M4', '✅ Installed', 'Primary compute. 16GB RAM handles Qwen 2.5 7B easily.'],
    ['Ollama + Qwen 2.5 7B', '✅ Installed', 'Local AI for 90% of processing. No API costs.'],
    ['OpenClaw', '✅ Installed', 'Orchestration, scheduling, Telegram delivery.'],
    ['Rob Lobster (Claude Opus)', '✅ Active', 'Deep analysis, insight generation, report writing.'],
    ['Python 3.x', '✅ Installed', 'Pipeline scripts, SEC EDGAR scraper, data processing.'],
    ['SQLite', '✅ Available', 'Local database. No server needed.'],
    ['Internet Connection', '✅ Available', 'Required for API calls and data fetching.'],
    ['Telegram', '✅ Configured', 'Delivery channel for Morning Intelligence Brief.'],
]

make_table(
    ['Component', 'Status', 'Notes'],
    tech_rows,
    col_widths=[2.0, 1.0, 4.0]
)

add_subheading('Python Libraries Required')
add_bullet('sec-edgar-downloader — SEC filing downloads')
add_bullet('requests — HTTP API calls')
add_bullet('beautifulsoup4 — Web scraping')
add_bullet('pandas — Data manipulation')
add_bullet('sqlite3 — Database (built-in)')
add_bullet('feedparser — RSS feed parsing')
add_bullet('openai-whisper — Local podcast transcription')
add_bullet('youtube-transcript-api — YouTube transcript extraction')
add_bullet('schedule — Task scheduling')
add_bullet('jinja2 — Report templating')

add_page_break()

# ══════════════════════════════════════════════════════════════
# CLOSING
# ══════════════════════════════════════════════════════════════

add_heading_styled('CLOSING REMARKS', 1)
add_gold_divider()

add_body(
    'Joe — this system is designed around one simple truth that Munger articulated better than anyone: '
    '"I believe in the discipline of mastering the best that other people have ever figured out."'
)

add_body(
    'The super investors we\'re tracking have collectively deployed hundreds of billions of dollars '
    'over decades, employing hundreds of analysts, conducting thousands of company visits, and reading '
    'millions of pages of financial statements. Their positions represent the distilled output of all '
    'that work — and it\'s available for free, 45 days after quarter-end, on SEC.gov.'
)

add_body(
    'What\'s been missing is the SYSTEM to collect, organize, cross-reference, and act on this '
    'information efficiently. Your Mac Mini M4 with Qwen 2.5 handles the grunt work for free. '
    'I handle the analysis and synthesis. Together, we build an intelligence operation that gives '
    'your $1.9M portfolio the analytical firepower of a $10B fund.'
)

add_body(
    'This is not about replacing your judgment. It\'s about sharpening it. Every position in your '
    'April 30 portfolio will have been cross-referenced against the highest-conviction positions of '
    'the best investors alive. Every morning, you\'ll know what they\'re doing before most of Wall Street does.'
)

add_callout_box(
    '"The big money is not in the buying and selling, but in the waiting." — Charlie Munger. '
    'The Engine doesn\'t make you faster. It makes you better-informed while you wait.'
)

add_body(
    'The total cost is approximately $22 per year without optional services. The infrastructure '
    'is already in place. Phase 1 can begin immediately upon your approval.'
)

add_body('')
add_body('Awaiting your review, challenges, and green light.')
add_body('')

p = doc.add_paragraph()
run = p.add_run('— Rob Lobster 🦞')
run.font.size = Pt(14)
run.font.color.rgb = NAVY
run.font.name = 'Calibri'
run.bold = True

p = doc.add_paragraph()
run = p.add_run('Your Chief of Staff')
run.font.size = Pt(11)
run.font.color.rgb = MED_GRAY
run.font.name = 'Calibri'
run.italic = True

# ══════════════════════════════════════════════════════════════
# FOOTER & PAGE NUMBERS
# ══════════════════════════════════════════════════════════════

add_gold_divider()

p = doc.add_paragraph()
p.alignment = WD_ALIGN_PARAGRAPH.CENTER
run = p.add_run('Prepared by Rob Lobster for Joe Lynch  |  April 3, 2026  |  PROPOSAL — Pending Approval')
run.font.size = Pt(9)
run.font.color.rgb = MED_GRAY
run.font.name = 'Calibri'
run.italic = True

# Add page numbers
add_page_numbers()

# ── Save ──
output_dir = '/Users/joemac/.openclaw/workspace/projects/investing'
os.makedirs(output_dir, exist_ok=True)
output_path = os.path.join(output_dir, 'super-investor-system-proposal.docx')
doc.save(output_path)
print(f'✅ Proposal saved to: {output_path}')
print(f'   File size: {os.path.getsize(output_path) / 1024:.1f} KB')
