New comparison feature.

This commit is contained in:
2026-02-04 21:21:57 -05:00
parent 48dca539cd
commit ca221f0fb3
5 changed files with 356 additions and 21 deletions

View File

@@ -367,4 +367,45 @@ def rewrite_chapter_task(run_id, project_path, book_folder, chap_num, instructio
return False
except Exception as e:
utils.log("ERROR", f"Rewrite task exception for run {run_id}/{book_folder}: {e}")
return False
@huey.task()
def refine_bible_task(project_path, instruction, source_type, selected_keys=None):
"""
Background task to refine the Bible.
Handles partial merging of selected keys into a temp base before refinement.
"""
try:
bible_path = os.path.join(project_path, "bible.json")
draft_path = os.path.join(project_path, "bible_draft.json")
base_bible = utils.load_json(bible_path)
if not base_bible: return False
# If refining from draft, load it
if source_type == 'draft' and os.path.exists(draft_path):
draft_bible = utils.load_json(draft_path)
# If user selected specific changes, merge them into the base
# This creates a "Proposed State" to refine further, WITHOUT modifying bible.json
if selected_keys and draft_bible:
base_bible = story.merge_selected_changes(base_bible, draft_bible, selected_keys)
elif draft_bible:
# If no specific keys but source is draft, assume we refine the whole draft
base_bible = draft_bible
ai.init_models()
# Run AI Refinement
new_bible = story.refine_bible(base_bible, instruction, project_path)
if new_bible:
# Save to draft file (Overwrite previous draft)
with open(draft_path, 'w') as f: json.dump(new_bible, f, indent=2)
return True
return False
except Exception as e:
utils.log("ERROR", f"Bible refinement task failed: {e}")
return False