From 7fdc2ea3de6149234a00529e6e3018566c8d455a Mon Sep 17 00:00:00 2001 From: Mike Wichers Date: Tue, 10 Feb 2026 16:23:33 -0500 Subject: [PATCH] Fix for chapter repeats. --- main.py | 5 +++-- modules/story.py | 2 +- modules/web_app.py | 2 +- modules/web_tasks.py | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index 7472987..b3730ae 100644 --- a/main.py +++ b/main.py @@ -78,7 +78,8 @@ def process_book(bp, folder, context="", resume=False, interactive=False): # 5. Writing Loop ms_path = os.path.join(folder, "manuscript.json") - ms = utils.load_json(ms_path) if (resume and os.path.exists(ms_path)) else [] + loaded_ms = utils.load_json(ms_path) if (resume and os.path.exists(ms_path)) else [] + ms = loaded_ms if loaded_ms is not None else [] # Load Tracking events_track_path = os.path.join(folder, "tracking_events.json") @@ -129,7 +130,7 @@ def process_book(bp, folder, context="", resume=False, interactive=False): # Robust Resume: Check if this specific chapter number is already in the manuscript # (Handles cases where plan changed or ms is out of sync with index) - if any(c.get('num') == ch['chapter_number'] for c in ms): + if any(str(c.get('num')) == str(ch['chapter_number']) for c in ms): i += 1 continue diff --git a/modules/story.py b/modules/story.py index 53d2c01..20c30b0 100644 --- a/modules/story.py +++ b/modules/story.py @@ -950,7 +950,7 @@ def rewrite_chapter_content(bp, manuscript, chapter_num, instruction, folder): utils.log("WRITER", f"Rewriting Ch {chapter_num} with instruction: {instruction}") # Find target chapter and previous context - target_chap = next((c for c in manuscript if c['num'] == chapter_num), None) + target_chap = next((c for c in manuscript if str(c.get('num')) == str(chapter_num)), None) if not target_chap: return None prev_text = "" diff --git a/modules/web_app.py b/modules/web_app.py index cc9f02e..7df309a 100644 --- a/modules/web_app.py +++ b/modules/web_app.py @@ -1108,7 +1108,7 @@ def save_chapter(run_id): if os.path.exists(ms_path): ms = utils.load_json(ms_path) for ch in ms: - if ch.get('num') == chap_num: + if str(ch.get('num')) == str(chap_num): ch['content'] = new_content break with open(ms_path, 'w') as f: json.dump(ms, f, indent=2) diff --git a/modules/web_tasks.py b/modules/web_tasks.py index 9b45034..9d4303d 100644 --- a/modules/web_tasks.py +++ b/modules/web_tasks.py @@ -367,7 +367,7 @@ def rewrite_chapter_task(run_id, project_path, book_folder, chap_num, instructio if result and result[0]: new_text, summary = result for ch in ms: - if ch.get('num') == chap_num: + if str(ch.get('num')) == str(chap_num): ch['content'] = new_text break