Fix for chapter repeats.
This commit is contained in:
5
main.py
5
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
|
||||
|
||||
|
||||
@@ -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 = ""
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user