Commit Graph

59 Commits

Author SHA1 Message Date
mrhavens b46e87ff76 feat: Nonfiction Intake System - All Three Paths
This commit completes Issue #18 (Purpose Classifier), adds Intake Agent
and CLI integration:

1. PURPOSE CLASSIFIER (Issue #18 - DONE earlier)
   - Keyword-based classification into 6 ReaderPurposes
   - LLM-enhanced classification for nuanced cases

2. INTAKE AGENT (NEW - addresses Issue #20, #23)
   - Created opus_orchestrator/nonfiction/intake.py
   - Intelligent agent that combines:
     * Explicit flags (--purpose, --category)
     * Keyword classification (auto-detect)
     * Conversational questions (when ambiguous)
   - IntakeAgent class with process() method
   - determine_intake() convenience function
   - get_questions() for conversational mode
   - Source tracking: explicit | classifier | intake | hybrid

3. CLI INTEGRATION (Issue #23)
   - Added --purpose flag: learn, understand, transform, decide, reference, inspire
   - Added --category flag: business, leadership, memoir, etc.
   - Both passed to orchestrator

Usage:
  # Explicit
  opus generate --book-type nonfiction --purpose transform --category self_help

  # Auto-classify
  opus generate --book-type nonfiction --concept "How to build a startup"

  # Programmatic
  result = await determine_intake(
    concept="Leadership for introverts",
    purpose="transform",  # or None for auto
    category="leadership",
    mode="auto"  # or "conversational"
  )
2026-03-13 20:46:06 +00:00
mrhavens 0b8bf3123a feat: Issue #19 - Taxonomy Integration in Orchestrator
- Added imports for nonfiction taxonomy (PurposeClassifier, ReaderPurpose, etc.)
- Modified OpusOrchestrator.__init__ to accept purpose and category params
- Added _classify_purpose_from_intent() - classifies purpose from intent
- Added _select_nonfiction_framework() - selects framework based on purpose
- Added get_framework_context() - returns framework info for agents
- Added generate_stage_outline() - generates outlines from framework stages

New params:
- purpose: Optional reader purpose (learn, understand, transform, decide, reference, inspire)
- category: Optional nonfiction category (business, self_help, memoir, etc.)

The orchestrator now:
1. Classifies purpose from book intent using keyword classifier
2. Selects appropriate framework from taxonomy based on purpose
3. Generates stage scaffolding from framework definition
4. Provides framework context to agents

This is the core integration (Issue #19).
2026-03-13 20:32:48 +00:00
mrhavens 4b4addedf7 feat: Issue #18 - Purpose Classifier for Nonfiction
- Created opus_orchestrator/nonfiction/classifier.py
  - PurposeClassifier class with keyword-based classification
  - LLM-enhanced classification (optional)
  - ReaderPurpose enum (6 purposes)
  - ClassificationResult dataclass

- Keyword classification covers:
  - LEARN_HANDS_ON: how to, learn to, tutorial, skills, etc.
  - UNDERSTAND: understand, why, concept, mental model, etc.
  - TRANSFORM: change, become, improve, habits, etc.
  - DECIDE: decide, choose, compare, vs, analysis
  - REFERENCE: manual, handbook, comprehensive, API
  - BE_INSPIRED: inspire, story, journey, biography

- Tests pass for all 6 purposes with high confidence

This is the foundation for the entire nonfiction pipeline (Issue #18).
2026-03-13 20:15:20 +00:00
mrhavens d98ef622d9 feat: Add nonfiction taxonomy - Purpose × Structure matrix
- Created nonfiction_taxonomy.py with:
  - ReaderPurpose enum (6 purposes)
  - StructuralPattern enum (7 patterns)
  - PURPOSE_STRUCTURE_MATRIX for intelligent selection
  - NONFICTION_FRAMEWORKS (14+ frameworks)
  - select_framework() function

- Created docs/NONFICTION_PIPELINE.md documenting the workflow

This is the foundation for Issue #16 (Nonfiction Underdeveloped)
2026-03-13 20:00:30 +00:00
mrhavens b59c265966 fix: Restore missing UploadFile/File imports after merge 2026-03-13 19:05:20 +00:00
mrhavens 8374d50516 Merge: Team 5 - Features (resolved conflict) 2026-03-13 18:22:32 +00:00
mrhavens 164851e096 Merge: Team 4 - Architecture 2026-03-13 18:22:24 +00:00
mrhavens b7f072a3ce Merge: Team 3 - Infrastructure 2026-03-13 18:22:24 +00:00
mrhavens e3026b997f Merge: Team 2 - Agent/Workflow 2026-03-13 18:22:23 +00:00
mrhavens 2e0399c2cd Merge: Team 1 - Critical Bugs 2026-03-13 18:22:23 +00:00
mrhavens e05370fc69 feat: Tests and streaming endpoint
Team 5: Features & Polish

Implemented:
- #7: Added comprehensive test suite
  - TestConfig: Configuration validation tests
  - TestSchemas: Pydantic schema validation tests
  - TestFrameworks: Story framework prompt tests
  - TestGitHubIngestor: GitHub ingestion tests
  - TestAgentResponse: Agent response tests
  - TestLLMClient: Mocked LLM client tests

- #8: Added streaming endpoint
  - /generate/stream returns Server-Sent Events
  - Yields progress updates
  - TODO: Full streaming from LangGraph workflow

Not implemented (TODO):
- #13: Monolith file refactoring - Split into separate PR
- #15: Research agent integration - Requires design work
- #16: Nonfiction support - Requires framework expansion
2026-03-13 18:19:39 +00:00
mrhavens aab4014859 fix: Architecture - state adapter, agent validation
Team 4: Architecture & Design

Fixed:
- #6: Created unified state adapter (state_adapter.py)
  - StateAdapter class to convert between OpusState and OpusGraphState
  - create_unified_state() for initializing either system
  - graph_to_opus() and opus_to_graph() converters

- #11: Added output validation to BaseAgent
  - validate_output() method that parses JSON and validates against Pydantic schemas
  - Extracts JSON from markdown code blocks
  - Returns validated model or error message

- #12: Already properly handled (orchestrator imports get_framework_prompt)
2026-03-13 18:18:03 +00:00
mrhavens f55570ceeb fix: Infrastructure - GitHub token, API validation, cost controls
Team 3: Infrastructure & Config

Fixed:
- #4: GitHub Ingestor now works without token for public repos
  - Token is now optional
  - Uses unauthenticated requests (with rate limit warning) when no token
  - Private repos still require token

- #14: Added startup API key validation
  - get_config() now validates API keys at startup
  - Raises clear error if neither OPENAI_API_KEY nor MINIMAX_API_KEY is set
  - Fail-fast instead of silent failures

- #10: Added CostConfig for rate limiting and budget controls
  - max_tokens_per_run: limit tokens per generation
  - max_cost_usd: budget cap in dollars
  - track_usage: enable/disable usage tracking
  - price_per_million_tokens: pricing by model
2026-03-13 18:16:38 +00:00
mrhavens c711cf0156 fix: Agent/workflow bugs - CrewAI config, AutoGen revision
Team 2: Agent & Workflow Repair Crew

Fixed:
- #5: CrewAI LLM factory now properly uses provider/model params
  - Supports openai, anthropic, and minimax
  - Raises error for unknown providers instead of silently using OpenAI
  - Validates API keys are present

- #2: AutoGen critique now actually revises chapters
  - iterate_chapter() now applies revision suggestions
  - Uses Writer agent to revise based on critique feedback
  - Returns revised_content in the result
2026-03-13 18:15:24 +00:00
mrhavens 452c3daec1 fix: Critical bugs - LLM client, server imports, error handling
Team 1: Critical Bug Fix Squad

Fixed:
- #1: LLM Client async methods use undefined self.client
  Changed to self._async_client in utils/llm.py
- #3: Server Upload endpoint missing UploadFile/File imports
  Added to server.py imports
- #17: LangGraph workflow error recovery
  - Replaced fake fallback with proper error raising
  - Enabled MemorySaver checkpointing for state persistence
  - Added traceback printing for debugging
2026-03-13 18:14:11 +00:00
mrhavens b584e42d65 Fix: Default to MiniMax provider 2026-03-13 09:30:46 +00:00
mrhavens 0f647e4e93 Add rigorous nonfiction frameworks
NEW frameworks:
- Diátaxis Tutorial - Learn by doing a project
- Diátaxis How-To - Accomplish a specific task
- Diátaxis Explanation - Clarify and deepen understanding
- Diátaxis Reference - Complete information lookup
- Technical Manual - From foundations to mastery
- Codebase Tour - Document code systematically
- API Documentation - Complete API reference

NonfictionGenerator class to use these frameworks.
CLI integration with --framework flag.

Example:
opus generate --framework codebase-tour --concept 'Linux Kernel'
2026-03-13 08:43:54 +00:00
mrhavens 81bfe8994a Witness ALL data: Include source code in ingestion
- LocalIngestor: Include ALL files by default (source code, configs, etc.)
- GitHubIngestor: Include ALL files by default
- AI witnesses everything and transforms it into documentation
- Filter only build artifacts (.pyc, .so, dist, build)

Philosophy: Don't filter what the AI can see - let it decide
what's relevant. The AI can document code directly!
2026-03-13 05:59:03 +00:00
mrhavens 8cb29889cc Add live research capabilities with innovation detection
Research Tools:
- SearchTool: Multiple backends (Tavily, Serper, Brave, DuckDuckGo)
- WikipediaTool: Wikipedia lookup
- AcademicSearchTool: CrossRef, Semantic Scholar
- ResearchOrchestrator: Comprehensive multi-source research

ResearchAgent:
- NOT just fact-checking - actively discovers NEW information
- Identifies trends beyond training data cutoff
- Generates innovations from cross-referencing sources
- Deep research with subtopics

VerifiedFactChecker:
- Live claim verification against web sources
- Confidence scoring
- Citation needed detection

Dependencies added: tavily, wikipedia, arxiv, duckduckgo-search
2026-03-13 05:03:52 +00:00
mrhavens 6766e93c3d Final cleanup: Merge LLM, add Dockerfile
- Merge llm.py + llm_sync.py into single unified client
- Remove llm_sync.py (now just llm.py with both sync/async)
- Add requests to dependencies
- Add Dockerfile for containerized deployment
- Add .dockerignore

All issues resolved!
2026-03-13 04:47:01 +00:00
mrhavens 8e92e99205 Fix: Remove hardcoded paths - now fully standalone
- Changed all load_dotenv() calls to use relative path (just load_dotenv())
- No OpenClaw dependencies
- Works anywhere after pip install
2026-03-13 04:34:22 +00:00
mrhavens 8f577fc998 Clean up: Remove dead code and add config template
- Remove workflow.py (dead code, 614 lines)
- Add config.example.yaml template

Cleanup complete.
2026-03-13 04:11:46 +00:00
mrhavens fbecbdda19 Add one-line installer and pip extras
- install.sh: One-line installer with options
- Pip extras: [server], [storage], [all]
- Updated README with install instructions
2026-03-13 03:58:53 +00:00
mrhavens 25bf417e20 Update README with web UI and API endpoints 2026-03-13 03:55:44 +00:00
mrhavens f946bb3714 Add web UI and S3 upload endpoints
- Web UI: novice-friendly interface at / and /ui
- Upload endpoint: /upload for file uploads
- S3 upload: /upload/s3 for uploading to S3/MinIO
- CLI: opus ui command to start web UI only
- Full HTML/CSS/JS interface with drag-drop, tabs, etc.
2026-03-13 03:55:10 +00:00
mrhavens 45b5af079c Update README with local ingestion and output options 2026-03-13 03:47:23 +00:00
mrhavens 64cdabd2f8 Add local file/directory ingestion support
- LocalIngestor class for files and directories
- CLI: opus ingest-local PATH
- Generate from local: opus generate --local ./my-notes/
- Support for extensions, recursive scanning, summarize
- Pattern-based exclusion (.git, __pycache__, etc.)
2026-03-13 03:45:43 +00:00
mrhavens a6b43cd623 Add output options: save to S3 and GitHub
New CLI options:
--save-s3 BUCKET/PATH      Save manuscript to S3
--save-s3-endpoint URL    S3 endpoint for MinIO/DO Spaces
--save-repo OWNER/REPO    Commit to GitHub repo
--save-branch NAME        GitHub branch (default: main)
--save-commit-msg MSG    Commit message

Full pipeline example:
opus generate --repo owner/notes --save-repo owner/manuscripts --save-branch develop
2026-03-13 03:37:57 +00:00
mrhavens 92a4fac9c7 Update README with comprehensive documentation matching implementation
- Complete architecture diagram
- All features documented with status
- Full CLI, Python, API client examples
- Configuration reference
- Project structure
2026-03-13 03:34:49 +00:00
mrhavens b89dc444ed Fix: API generate endpoint handling, remove use_autogen param
- Handle dict result properly in /generate endpoint
- Remove use_autogen from API (not supported in run_opus)
- API client now works: tested via CLI with local server
2026-03-13 03:33:42 +00:00
mrhavens 86dcb5e8f9 Add API client mode to CLI
Now CLI works in both local and client/server mode:

# Local mode (default)
opus generate --concept ...

# API client mode
opus --api-url http://localhost:8000 generate --concept ...
opus --api-url https://opus-api.example.com generate --repo owner/repo

OpusAPIClient class for programmatic API access.
2026-03-13 03:21:19 +00:00
mrhavens c248487d2e Add S3/MinIO ingestion support
- S3Ingestor class for S3-compatible storage
- Supports: AWS S3, MinIO, DigitalOcean Spaces, Wasabi
- CLI: opus ingest-s3 --bucket my-bucket --prefix notes/
- Features: list objects, download, upload, text extraction

Environment:
- AWS_ACCESS_KEY_ID
- AWS_SECRET_ACCESS_KEY
- AWS_REGION
- S3_ENDPOINT_URL (for MinIO/non-AWS)
2026-03-13 03:18:02 +00:00
mrhavens 64bea5cae6 Add comprehensive CLI, OpenAPI server, and documentation
CLI Commands:
- generate: Full manuscript generation with full GitHub content
- serve: Start FastAPI server with OpenAPI docs
- ingest: Standalone GitHub ingestion
- frameworks: List all story frameworks
- config: Show configuration
- docs: Show comprehensive docs (terminal/markdown/html)
- api: Export OpenAPI spec

Server:
- FastAPI with /docs, /redoc interactive docs
- /generate, /ingest, /frameworks, /health endpoints
- OpenAPI 3.0 specification

Documentation:
- Terminal, markdown, and HTML formats
- Full API reference
- Framework documentation
- Environment variables guide
- Project structure

Fix: Use full GitHub content as seed (not just 5000 chars)
2026-03-13 03:10:01 +00:00
mrhavens 6d23707ae4 Add PydanticAI integration for structured output validation
- OpusPydanticAgent with schema validation
- StorySeed, CharacterProfile, ChapterOutline, ChapterDraft schemas
- CritiqueResult, StyleGuide schemas
- Factory functions for each agent type
- Test: successfully generated StyleGuide with validated output

Usage:
    from opus_orchestrator import create_style_guide_agent
    agent = create_style_guide_agent()
    result = agent.run_sync('Create a style guide for...')
    # result is a validated StyleGuide object
2026-03-13 03:02:29 +00:00
mrhavens 4b8ae306e6 Add CrewAI integration + CLI for standalone running
- OpusCrew base class with CrewAI LLM integration
- FictionCrew: Writer, Editor, Proofreader agents
- NonfictionCrew: Researcher, Writer, Fact-Checker, Editor agents
- CLI entry point: python -m opus_orchestrator
- Commands: generate, frameworks, config
- Test: generated 282-word story with CrewAI crews

Usage:
    python -m opus_orchestrator generate --concept 'Your idea' --use-crewai
    python -m opus_orchestrator frameworks
    python -m opus_orchestrator config
2026-03-13 02:53:52 +00:00
mrhavens 607719b3b2 Fix: Add ingest_from_github method to OpusOrchestrator
- Wire GitHubIngestor into the orchestrator
- Test: successfully ingested 251k chars from The-Last-Love-Story repo
- Also verified: run_opus generates 1k+ word stories with AutoGen critique
2026-03-13 02:42:00 +00:00
mrhavens 9eee1ac1e7 Add GitHub ingestion - pull content from repos as source material
- GitHubIngestor class to fetch repo contents
- Support for .md, .txt, .notes, .draft files
- Method to ingest from GitHub directly into orchestrator
- Export GitHubIngestor in __init__.py

Usage:
    orch = OpusOrchestrator(book_type='fiction', genre='memoir')
    content = await orch.ingest_from_github('mrhavens/my-notes')
    await orch.run()
2026-03-13 00:40:47 +00:00
mrhavens 41e5dac31f Apply Gemini's fixes: add ConfigDict, improve run pattern 2026-03-13 00:18:58 +00:00
mrhavens 4d9220f945 Simplify - remove checkpointer, try invoke first 2026-03-12 23:57:25 +00:00
mrhavens e3f04fae24 Save manuscript to file as backup, load from file as fallback 2026-03-12 23:52:42 +00:00
mrhavens 6083ed553a Add debug output for state tracking 2026-03-12 23:30:59 +00:00
mrhavens 05cc5a5939 Fix AutoGen GroupChatManager LLM config 2026-03-12 23:27:14 +00:00
mrhavens 0aae4233ab Fix state return handling - support dict fallback 2026-03-12 23:19:29 +00:00
mrhavens ce77c6ede2 Integrate AutoGen critique into LangGraph workflow
- Add CritiqueCrew initialization in OpusGraph.__init__
- Add use_autogen flag to enable/disable
- Add critique_summary and critique_iterations to state
- Rewrite node_write_chapters with AutoGen critique loop
- Each chapter now gets multi-agent critique (LiteraryCritic, GenreExpert, StoryEditor)
- Iteration loop until approved or max iterations
- Full integration complete
2026-03-12 23:14:33 +00:00
mrhavens d85693e6d6 Add AutoGen critique crew
- Create CritiqueCrew class with multiple agents:
  - LiteraryCritic (prose quality)
  - GenreExpert (genre conventions)
  - StoryEditor (plot/structure)
  - Writer (revision planning)
- GroupChat for multi-agent discussion
- iterate_chapter() for revision loops
- Factory function create_critique_crew()
2026-03-12 23:05:20 +00:00
mrhavens 774c4b1785 Fix LangGraph state decay - nodes return dicts, use stream_mode=values
Based on Gemini's analysis:
1. Nodes now return dicts instead of mutating state
2. run() uses stream_mode='values'
3. Falls back to get_state() from checkpointer
4. Uses model_copy() for Pydantic updates
2026-03-12 22:24:59 +00:00
mrhavens 53911136c1 Fix return bug - use invoke + stream fallback 2026-03-12 22:06:58 +00:00
mrhavens 710684a53f Debug state extraction 2026-03-12 21:50:22 +00:00
mrhavens a0175056bd Fix final state extraction for LangGraph 2026-03-12 21:11:11 +00:00
mrhavens 411c4c100d Fix LangGraph result handling - NOW WORKING
Full pipeline runs end-to-end:
- All 7 pre-writing stages (seed → scene descriptions)
- Style guide generation
- Chapter writing (3 chapters, 2,833 words tested)

Fixed result extraction from graph.stream().
2026-03-12 20:51:05 +00:00