From df7cee9524923a30c0235500b4e243690ee00e05 Mon Sep 17 00:00:00 2001 From: = <=> Date: Wed, 4 Feb 2026 22:10:19 -0500 Subject: [PATCH] Fixed refinement --- modules/web_app.py | 7 ++++++- modules/web_tasks.py | 7 ++++++- templates/bible_comparison.html | 2 +- templates/project.html | 36 ++++++++++++++++++++++++++++++--- templates/project_review.html | 8 +++++++- 5 files changed, 53 insertions(+), 7 deletions(-) diff --git a/modules/web_app.py b/modules/web_app.py index 8ffa11a..a3107db 100644 --- a/modules/web_app.py +++ b/modules/web_app.py @@ -397,6 +397,11 @@ def view_project(id): bible_path = os.path.join(proj.folder_path, "bible.json") bible_data = utils.load_json(bible_path) + # Check for active refinement or pending draft + draft_path = os.path.join(proj.folder_path, "bible_draft.json") + has_draft = os.path.exists(draft_path) + is_refining = os.path.exists(os.path.join(proj.folder_path, ".refining")) + # Load Personas for dropdown personas = {} if os.path.exists(config.PERSONAS_FILE): @@ -463,7 +468,7 @@ def view_project(id): 'type': f.split('.')[-1].upper() }) - return render_template('project.html', project=proj, bible=bible_data, runs=runs, active_run=latest_run, artifacts=artifacts, cover_image=cover_image, personas=personas, generated_books=generated_books, other_projects=other_projects, locked=locked) + return render_template('project.html', project=proj, bible=bible_data, runs=runs, active_run=latest_run, artifacts=artifacts, cover_image=cover_image, personas=personas, generated_books=generated_books, other_projects=other_projects, locked=locked, has_draft=has_draft, is_refining=is_refining) @app.route('/project//run', methods=['POST']) @login_required diff --git a/modules/web_tasks.py b/modules/web_tasks.py index c1288fe..6fcb849 100644 --- a/modules/web_tasks.py +++ b/modules/web_tasks.py @@ -378,6 +378,9 @@ def refine_bible_task(project_path, instruction, source_type, selected_keys=None try: bible_path = os.path.join(project_path, "bible.json") draft_path = os.path.join(project_path, "bible_draft.json") + lock_path = os.path.join(project_path, ".refining") + + with open(lock_path, 'w') as f: f.write("running") base_bible = utils.load_json(bible_path) if not base_bible: return False @@ -408,4 +411,6 @@ def refine_bible_task(project_path, instruction, source_type, selected_keys=None except Exception as e: utils.log("ERROR", f"Bible refinement task failed: {e}") - return False \ No newline at end of file + return False + finally: + if os.path.exists(lock_path): os.remove(lock_path) \ No newline at end of file diff --git a/templates/bible_comparison.html b/templates/bible_comparison.html index dbe82af..963db41 100644 --- a/templates/bible_comparison.html +++ b/templates/bible_comparison.html @@ -21,7 +21,7 @@
-
+ diff --git a/templates/project.html b/templates/project.html index dda85a0..ce887ba 100644 --- a/templates/project.html +++ b/templates/project.html @@ -299,6 +299,12 @@
World Bible & Characters
+ {% if is_refining %} + + Refining... + + {% endif %} + Full Review @@ -306,13 +312,37 @@ - + + {% if has_draft %} + + Review Draft + + {% elif is_refining %} + + {% else %} + + {% endif %} + {% endif %}
+ {% if has_draft %} +
+
+
+ + Draft Pending: You have an unreviewed Bible refinement waiting. +
+ Review Changes +
+
+ {% endif %} +
Project Metadata
diff --git a/templates/project_review.html b/templates/project_review.html index e179e84..2528c5e 100644 --- a/templates/project_review.html +++ b/templates/project_review.html @@ -12,7 +12,7 @@

The AI has generated your characters and plot structure. Review them below and refine if needed.

- +
@@ -121,6 +121,12 @@ function submitRefine(event) { }); }, 2000); } + }) + .catch(err => { + alert("Request failed: " + err); + const btn = form.querySelector('button[type="submit"]'); + btn.disabled = false; + btn.innerHTML = 'Refine with AI'; }); }