Blueprint v2.4-2.6: Style Rules UI, Lore RAG, Thread Tracking, Redo Book
v2.4 — Item 7: Refresh Style Guidelines - web/routes/admin.py: Added /admin/refresh-style-guidelines route (AJAX-aware) - templates/system_status.html: Added 'Refresh Style Rules' button with spinner v2.5 — Item 8: Lore & Location RAG-Lite - story/bible_tracker.py: Added update_lore_index() — extracts location/item descriptions from chapters into tracking_lore.json - story/writer.py: Reads chapter locations/key_items, builds LORE_CONTEXT block injected into the prompt (graceful degradation if no tags) - cli/engine.py: Loads tracking_lore.json on resume, calls update_lore_index after each chapter, saves tracking_lore.json v2.5 — Item 9: Structured Story State (Thread Tracking) - story/state.py (new): load_story_state, update_story_state (extracts active_threads, immediate_handoff, resolved_threads via model_logic), format_for_prompt (structured context replacing the prev_sum blob) - cli/engine.py: Loads story_state.json on resume, uses format_for_prompt as summary_ctx for write_chapter, updates state after each chapter accepted v2.6 — Item 10: Redo Book - templates/consistency_report.html: Added 'Redo Book' form with instruction input and confirmation dialog - web/routes/run.py: Added revise_book route — creates new Run, queues generate_book_task with user instruction as feedback Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -8,7 +8,7 @@ from core import config, utils
|
||||
from ai import models as ai_models
|
||||
from ai import setup as ai_setup
|
||||
from story import planner, writer as story_writer, editor as story_editor
|
||||
from story import style_persona, bible_tracker
|
||||
from story import style_persona, bible_tracker, state as story_state
|
||||
from marketing import assets as marketing_assets
|
||||
from export import exporter
|
||||
|
||||
@@ -92,8 +92,9 @@ def process_book(bp, folder, context="", resume=False, interactive=False):
|
||||
events_track_path = os.path.join(folder, "tracking_events.json")
|
||||
chars_track_path = os.path.join(folder, "tracking_characters.json")
|
||||
warn_track_path = os.path.join(folder, "tracking_warnings.json")
|
||||
lore_track_path = os.path.join(folder, "tracking_lore.json")
|
||||
|
||||
tracking = {"events": [], "characters": {}, "content_warnings": []}
|
||||
tracking = {"events": [], "characters": {}, "content_warnings": [], "lore": {}}
|
||||
if resume:
|
||||
if os.path.exists(events_track_path):
|
||||
tracking['events'] = utils.load_json(events_track_path)
|
||||
@@ -101,6 +102,11 @@ def process_book(bp, folder, context="", resume=False, interactive=False):
|
||||
tracking['characters'] = utils.load_json(chars_track_path)
|
||||
if os.path.exists(warn_track_path):
|
||||
tracking['content_warnings'] = utils.load_json(warn_track_path)
|
||||
if os.path.exists(lore_track_path):
|
||||
tracking['lore'] = utils.load_json(lore_track_path) or {}
|
||||
|
||||
# Load structured story state
|
||||
current_story_state = story_state.load_story_state(folder)
|
||||
|
||||
summary = "The story begins."
|
||||
if ms:
|
||||
@@ -148,7 +154,12 @@ def process_book(bp, folder, context="", resume=False, interactive=False):
|
||||
|
||||
while True:
|
||||
try:
|
||||
summary_ctx = summary[-8000:] if len(summary) > 8000 else summary
|
||||
# Build context: use structured state if available, fall back to summary blob
|
||||
structured_ctx = story_state.format_for_prompt(current_story_state, ch.get('beats', []))
|
||||
if structured_ctx:
|
||||
summary_ctx = structured_ctx
|
||||
else:
|
||||
summary_ctx = summary[-8000:] if len(summary) > 8000 else summary
|
||||
next_hint = chapters[i+1]['title'] if i + 1 < len(chapters) else ""
|
||||
txt = story_writer.write_chapter(ch, bp, folder, summary_ctx, tracking, prev_content, next_chapter_hint=next_hint)
|
||||
except Exception as e:
|
||||
@@ -218,6 +229,13 @@ def process_book(bp, folder, context="", resume=False, interactive=False):
|
||||
with open(chars_track_path, "w") as f: json.dump(tracking['characters'], f, indent=2)
|
||||
with open(warn_track_path, "w") as f: json.dump(tracking.get('content_warnings', []), f, indent=2)
|
||||
|
||||
# Update Lore Index (Item 8: RAG-Lite)
|
||||
tracking['lore'] = bible_tracker.update_lore_index(folder, txt, tracking.get('lore', {}))
|
||||
with open(lore_track_path, "w") as f: json.dump(tracking['lore'], f, indent=2)
|
||||
|
||||
# Update Structured Story State (Item 9: Thread Tracking)
|
||||
current_story_state = story_state.update_story_state(txt, ch['chapter_number'], current_story_state, folder)
|
||||
|
||||
# Dynamic Pacing Check (every other chapter)
|
||||
remaining = chapters[i+1:]
|
||||
if remaining and len(remaining) >= 2 and i % 2 == 1:
|
||||
|
||||
Reference in New Issue
Block a user