{
  "name": "Book Chapter Editor & Analyzer",
  "version": "1.0.0",
  "description": "AI-powered book chapter editing pipeline: critique, improve, humanize, and produce 3 polished versions with detailed statistics",
  "input_schema": {
    "type": "object",
    "properties": {
      "chapter_title": {
        "type": "string",
        "description": "Title of the chapter"
      },
      "chapter_content": {
        "type": "string",
        "description": "The full chapter text to edit"
      },
      "genre": {
        "type": "string",
        "enum": ["fiction", "non-fiction", "memoir", "self-help", "technical", "fantasy", "thriller", "romance", "literary"],
        "default": "fiction"
      },
      "target_audience": {
        "type": "string",
        "description": "Who is the target reader?",
        "default": "general adult readers"
      },
      "author_style_notes": {
        "type": "string",
        "description": "Notes about the author's preferred style",
        "default": ""
      },
      "focus_areas": {
        "type": "array",
        "description": "Areas to focus on during editing",
        "items": { "type": "string" },
        "default": ["pacing", "dialogue", "descriptions", "emotional impact"]
      }
    },
    "required": ["chapter_title", "chapter_content"]
  },
  "output_schema": {
    "type": "object",
    "properties": {
      "original_statistics": { "type": "object" },
      "critique": { "type": "object" },
      "versions": { "type": "array" },
      "comparison": { "type": "object" }
    }
  },
  "stages": [
    {
      "id": "log-start",
      "name": "Log Chapter Intake",
      "component_type": "logger",
      "config": {
        "message": "Starting book chapter editing pipeline",
        "level": "info",
        "data": {
          "title": "{{input.chapter_title}}",
          "genre": "{{input.genre}}"
        }
      },
      "depends_on": [],
      "position": { "x": 100, "y": 400 }
    },
    {
      "id": "analyze-original",
      "name": "Analyze Original Text",
      "component_type": "generator",
      "config": {
        "system_prompt": "You are a text analysis expert. Analyze text and output ONLY valid JSON with statistics. Calculate accurately.",
        "prompt": "Analyze this chapter and provide statistics:\n\nTitle: {{input.chapter_title}}\n\nContent:\n{{input.chapter_content}}\n\nOutput ONLY this JSON (calculate accurately):\n{\n  \"word_count\": <exact word count>,\n  \"character_count\": <character count with spaces>,\n  \"character_count_no_spaces\": <character count without spaces>,\n  \"sentence_count\": <number of sentences>,\n  \"paragraph_count\": <number of paragraphs>,\n  \"average_sentence_length\": <words per sentence>,\n  \"average_word_length\": <characters per word>,\n  \"dialogue_percentage\": <estimated % that is dialogue>,\n  \"reading_time_minutes\": <word_count / 238>,\n  \"flesch_kincaid_grade\": <estimated grade level 1-12+>,\n  \"flesch_reading_ease\": <score 0-100, higher = easier>,\n  \"reading_difficulty\": \"easy|moderate|challenging|difficult\",\n  \"vocabulary_complexity\": \"simple|moderate|advanced|literary\"\n}",
        "max_tokens": 500,
        "temperature": 0.1
      },
      "depends_on": ["log-start"],
      "position": { "x": 300, "y": 200 }
    },
    {
      "id": "parse-original-stats",
      "name": "Parse Original Stats",
      "component_type": "json_transform",
      "config": {
        "data": "{{upstream.analyze-original.content}}",
        "jmespath_expression": "@"
      },
      "depends_on": ["analyze-original"],
      "position": { "x": 500, "y": 200 }
    },
    {
      "id": "deep-critique",
      "name": "Deep Editorial Critique",
      "component_type": "generator",
      "config": {
        "system_prompt": "You are a senior book editor with 20+ years of experience. Provide thorough, constructive critique that helps authors improve. Be specific with examples from the text. Balance criticism with recognition of strengths.",
        "prompt": "Provide a comprehensive editorial critique of this {{input.genre}} chapter:\n\nTitle: {{input.chapter_title}}\nTarget Audience: {{input.target_audience}}\nFocus Areas: {{input.focus_areas}}\n\nChapter Content:\n{{input.chapter_content}}\n\nProvide detailed critique covering:\n\n1. OVERALL IMPRESSION (2-3 sentences)\n\n2. STRENGTHS (3-5 specific examples with quotes)\n\n3. AREAS FOR IMPROVEMENT:\n   - Pacing issues\n   - Dialogue effectiveness\n   - Description balance (too much/too little)\n   - Character voice consistency\n   - Emotional engagement\n   - Show vs tell opportunities\n   - Sentence variety\n   - Word choice/repetition\n\n4. STRUCTURAL NOTES:\n   - Opening hook effectiveness\n   - Chapter arc/flow\n   - Ending impact\n\n5. LINE-LEVEL ISSUES (5-10 specific examples with suggestions)\n\n6. PRIORITY FIXES (top 3 things to address first)\n\nBe specific and actionable.",
        "max_tokens": 2000,
        "temperature": 0.4
      },
      "depends_on": ["log-start"],
      "position": { "x": 300, "y": 400 }
    },
    {
      "id": "version-1-refined",
      "name": "Version 1: Refined Edit",
      "component_type": "generator",
      "config": {
        "system_prompt": "You are an expert book editor. Your task is to refine and improve the chapter while maintaining the author's voice. Make surgical edits - fix issues without over-writing. Preserve what works.",
        "prompt": "Create VERSION 1: REFINED EDIT of this chapter.\n\nOriginal Title: {{input.chapter_title}}\nGenre: {{input.genre}}\nAuthor Style Notes: {{input.author_style_notes}}\n\nEditorial Critique to Address:\n{{upstream.deep-critique.content}}\n\nOriginal Chapter:\n{{input.chapter_content}}\n\n---\n\nCREATE THE REFINED VERSION:\n- Fix grammatical and structural issues\n- Improve sentence flow and variety\n- Tighten prose (remove unnecessary words)\n- Enhance clarity without changing voice\n- Address the top priority fixes from the critique\n- Keep the author's original style and intent\n\nOutput the complete refined chapter:",
        "max_tokens": 4000,
        "temperature": 0.6
      },
      "depends_on": ["deep-critique"],
      "position": { "x": 550, "y": 300 }
    },
    {
      "id": "version-2-enhanced",
      "name": "Version 2: Enhanced Edit",
      "component_type": "generator",
      "config": {
        "system_prompt": "You are a developmental editor who enhances manuscripts. Go beyond basic editing to strengthen the writing significantly while respecting the core story and voice.",
        "prompt": "Create VERSION 2: ENHANCED EDIT of this chapter.\n\nOriginal Title: {{input.chapter_title}}\nGenre: {{input.genre}}\nTarget Audience: {{input.target_audience}}\n\nEditorial Critique:\n{{upstream.deep-critique.content}}\n\nOriginal Chapter:\n{{input.chapter_content}}\n\n---\n\nCREATE THE ENHANCED VERSION:\n- All refinements from Version 1, plus:\n- Strengthen emotional impact\n- Improve pacing and tension\n- Enhance descriptions (make them vivid but not purple)\n- Sharpen dialogue to reveal character\n- Better show-don't-tell execution\n- Improve transitions between scenes/paragraphs\n- Add sensory details where appropriate\n- Strengthen the chapter opening and closing\n\nOutput the complete enhanced chapter:",
        "max_tokens": 4000,
        "temperature": 0.7
      },
      "depends_on": ["deep-critique"],
      "position": { "x": 550, "y": 500 }
    },
    {
      "id": "version-3-humanized",
      "name": "Version 3: Humanized & Polished",
      "component_type": "generator",
      "config": {
        "system_prompt": "You are a master editor who specializes in making prose feel authentic and deeply human. Your edits make writing feel natural, relatable, and emotionally resonant - never artificial or over-written.",
        "prompt": "Create VERSION 3: HUMANIZED & POLISHED EDIT of this chapter.\n\nOriginal Title: {{input.chapter_title}}\nGenre: {{input.genre}}\nTarget Audience: {{input.target_audience}}\nAuthor Style Notes: {{input.author_style_notes}}\n\nOriginal Chapter:\n{{input.chapter_content}}\n\n---\n\nCREATE THE HUMANIZED VERSION:\n- Make the prose feel natural and authentic\n- Ensure dialogue sounds like real people talking\n- Add subtle human touches (small gestures, realistic reactions)\n- Balance literary quality with accessibility\n- Remove anything that feels forced or artificial\n- Ensure emotional beats feel earned, not manipulative\n- Make descriptions grounded and relatable\n- Vary rhythm to match content (fast for action, slower for reflection)\n- Ensure the reading experience flows effortlessly\n- Polish to publication-ready quality\n\nThis should feel like the best version of the author's own voice.\n\nOutput the complete humanized chapter:",
        "max_tokens": 4000,
        "temperature": 0.75
      },
      "depends_on": ["deep-critique"],
      "position": { "x": 550, "y": 700 }
    },
    {
      "id": "notes-version-1",
      "name": "Notes for Version 1",
      "component_type": "generator",
      "config": {
        "system_prompt": "You are an editor providing change notes. Be concise and specific about what was changed and why.",
        "prompt": "Compare the original chapter with Version 1 (Refined Edit) and provide editorial notes.\n\nOriginal:\n{{input.chapter_content}}\n\nVersion 1 (Refined):\n{{upstream.version-1-refined.content}}\n\nProvide concise notes:\n1. SUMMARY OF CHANGES (2-3 sentences)\n2. KEY EDITS MADE (bullet list, 5-8 items)\n3. WHAT WAS PRESERVED (2-3 points)\n4. RECOMMENDED FOR: (who should use this version)",
        "max_tokens": 600,
        "temperature": 0.3
      },
      "depends_on": ["version-1-refined"],
      "position": { "x": 800, "y": 300 }
    },
    {
      "id": "notes-version-2",
      "name": "Notes for Version 2",
      "component_type": "generator",
      "config": {
        "system_prompt": "You are an editor providing change notes. Be concise and specific about what was changed and why.",
        "prompt": "Compare the original chapter with Version 2 (Enhanced Edit) and provide editorial notes.\n\nOriginal:\n{{input.chapter_content}}\n\nVersion 2 (Enhanced):\n{{upstream.version-2-enhanced.content}}\n\nProvide concise notes:\n1. SUMMARY OF CHANGES (2-3 sentences)\n2. KEY ENHANCEMENTS MADE (bullet list, 5-8 items)\n3. WHAT WAS PRESERVED (2-3 points)\n4. RECOMMENDED FOR: (who should use this version)",
        "max_tokens": 600,
        "temperature": 0.3
      },
      "depends_on": ["version-2-enhanced"],
      "position": { "x": 800, "y": 500 }
    },
    {
      "id": "notes-version-3",
      "name": "Notes for Version 3",
      "component_type": "generator",
      "config": {
        "system_prompt": "You are an editor providing change notes. Be concise and specific about what was changed and why.",
        "prompt": "Compare the original chapter with Version 3 (Humanized & Polished) and provide editorial notes.\n\nOriginal:\n{{input.chapter_content}}\n\nVersion 3 (Humanized):\n{{upstream.version-3-humanized.content}}\n\nProvide concise notes:\n1. SUMMARY OF CHANGES (2-3 sentences)\n2. KEY HUMANIZATION EDITS (bullet list, 5-8 items)\n3. WHAT WAS PRESERVED (2-3 points)\n4. RECOMMENDED FOR: (who should use this version)",
        "max_tokens": 600,
        "temperature": 0.3
      },
      "depends_on": ["version-3-humanized"],
      "position": { "x": 800, "y": 700 }
    },
    {
      "id": "analyze-v1",
      "name": "Analyze Version 1",
      "component_type": "generator",
      "config": {
        "system_prompt": "You are a text analysis expert. Output ONLY valid JSON.",
        "prompt": "Analyze this text and output statistics:\n\n{{upstream.version-1-refined.content}}\n\nOutput ONLY this JSON:\n{\"word_count\": <number>, \"character_count\": <number>, \"sentence_count\": <number>, \"reading_time_minutes\": <word_count/238>, \"flesch_reading_ease\": <0-100>, \"reading_difficulty\": \"easy|moderate|challenging|difficult\"}",
        "max_tokens": 200,
        "temperature": 0.1
      },
      "depends_on": ["version-1-refined"],
      "position": { "x": 1050, "y": 300 }
    },
    {
      "id": "analyze-v2",
      "name": "Analyze Version 2",
      "component_type": "generator",
      "config": {
        "system_prompt": "You are a text analysis expert. Output ONLY valid JSON.",
        "prompt": "Analyze this text and output statistics:\n\n{{upstream.version-2-enhanced.content}}\n\nOutput ONLY this JSON:\n{\"word_count\": <number>, \"character_count\": <number>, \"sentence_count\": <number>, \"reading_time_minutes\": <word_count/238>, \"flesch_reading_ease\": <0-100>, \"reading_difficulty\": \"easy|moderate|challenging|difficult\"}",
        "max_tokens": 200,
        "temperature": 0.1
      },
      "depends_on": ["version-2-enhanced"],
      "position": { "x": 1050, "y": 500 }
    },
    {
      "id": "analyze-v3",
      "name": "Analyze Version 3",
      "component_type": "generator",
      "config": {
        "system_prompt": "You are a text analysis expert. Output ONLY valid JSON.",
        "prompt": "Analyze this text and output statistics:\n\n{{upstream.version-3-humanized.content}}\n\nOutput ONLY this JSON:\n{\"word_count\": <number>, \"character_count\": <number>, \"sentence_count\": <number>, \"reading_time_minutes\": <word_count/238>, \"flesch_reading_ease\": <0-100>, \"reading_difficulty\": \"easy|moderate|challenging|difficult\"}",
        "max_tokens": 200,
        "temperature": 0.1
      },
      "depends_on": ["version-3-humanized"],
      "position": { "x": 1050, "y": 700 }
    },
    {
      "id": "parse-v1-stats",
      "name": "Parse V1 Stats",
      "component_type": "json_transform",
      "config": {
        "data": "{{upstream.analyze-v1.content}}",
        "jmespath_expression": "@"
      },
      "depends_on": ["analyze-v1"],
      "position": { "x": 1250, "y": 300 }
    },
    {
      "id": "parse-v2-stats",
      "name": "Parse V2 Stats",
      "component_type": "json_transform",
      "config": {
        "data": "{{upstream.analyze-v2.content}}",
        "jmespath_expression": "@"
      },
      "depends_on": ["analyze-v2"],
      "position": { "x": 1250, "y": 500 }
    },
    {
      "id": "parse-v3-stats",
      "name": "Parse V3 Stats",
      "component_type": "json_transform",
      "config": {
        "data": "{{upstream.analyze-v3.content}}",
        "jmespath_expression": "@"
      },
      "depends_on": ["analyze-v3"],
      "position": { "x": 1250, "y": 700 }
    },
    {
      "id": "compile-output",
      "name": "Compile Final Output",
      "component_type": "json_transform",
      "config": {
        "data": {
          "title": "{{input.chapter_title}}",
          "genre": "{{input.genre}}",
          "original_stats": "{{upstream.parse-original-stats.result}}",
          "critique": "{{upstream.deep-critique.content}}",
          "v1_content": "{{upstream.version-1-refined.content}}",
          "v1_notes": "{{upstream.notes-version-1.content}}",
          "v1_stats": "{{upstream.parse-v1-stats.result}}",
          "v2_content": "{{upstream.version-2-enhanced.content}}",
          "v2_notes": "{{upstream.notes-version-2.content}}",
          "v2_stats": "{{upstream.parse-v2-stats.result}}",
          "v3_content": "{{upstream.version-3-humanized.content}}",
          "v3_notes": "{{upstream.notes-version-3.content}}",
          "v3_stats": "{{upstream.parse-v3-stats.result}}"
        },
        "jmespath_expression": "{ chapter_title: title, genre: genre, original_statistics: original_stats, editorial_critique: critique, versions: [ { version: `1`, name: 'Refined Edit', description: 'Clean, tightened prose with essential fixes', content: v1_content, editorial_notes: v1_notes, statistics: v1_stats }, { version: `2`, name: 'Enhanced Edit', description: 'Strengthened emotional impact and pacing', content: v2_content, editorial_notes: v2_notes, statistics: v2_stats }, { version: `3`, name: 'Humanized & Polished', description: 'Natural, authentic, publication-ready', content: v3_content, editorial_notes: v3_notes, statistics: v3_stats } ], statistics_comparison: { original: original_stats, version_1: v1_stats, version_2: v2_stats, version_3: v3_stats } }"
      },
      "depends_on": ["parse-original-stats", "deep-critique", "notes-version-1", "notes-version-2", "notes-version-3", "parse-v1-stats", "parse-v2-stats", "parse-v3-stats"],
      "position": { "x": 1450, "y": 500 }
    },
    {
      "id": "log-complete",
      "name": "Log Completion",
      "component_type": "logger",
      "config": {
        "message": "Book chapter editing complete",
        "level": "info",
        "data": {
          "title": "{{input.chapter_title}}",
          "versions_created": 3
        }
      },
      "depends_on": ["compile-output"],
      "position": { "x": 1650, "y": 500 }
    }
  ],
  "output_stage_id": "compile-output"
}
