Add atomic writes, magic string constants, unit tests, type hints, and fix navigation

- save_json() now writes to a temp file then uses os.replace() for atomic writes
- Replace hardcoded "batch_data", "history_tree", "prompt_history", "sequence_number"
  strings with constants (KEY_BATCH_DATA, etc.) across all modules
- Add 29 unit tests for history_tree, utils, and json_loader
- Add type hints to public functions in utils.py, json_loader.py, history_tree.py
- Remove ALLOWED_BASE_DIR restriction that blocked navigating outside app CWD
- Fix path text input not updating on navigation by using session state key
- Add unpin button () for removing pinned folders

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-02-02 12:44:31 +01:00
parent 326ae25ab2
commit b02bf124fb
15 changed files with 368 additions and 124 deletions

View File

@@ -1,7 +1,7 @@
import streamlit as st
import json
import copy
from utils import save_json, get_file_mtime
from utils import save_json, get_file_mtime, KEY_HISTORY_TREE, KEY_PROMPT_HISTORY
def render_raw_editor(data, file_path):
st.subheader(f"💻 Raw Editor: {file_path.name}")
@@ -20,8 +20,8 @@ def render_raw_editor(data, file_path):
if hide_history:
display_data = copy.deepcopy(data)
# Safely remove heavy keys for the view only
if "history_tree" in display_data: del display_data["history_tree"]
if "prompt_history" in display_data: del display_data["prompt_history"]
if KEY_HISTORY_TREE in display_data: del display_data[KEY_HISTORY_TREE]
if KEY_PROMPT_HISTORY in display_data: del display_data[KEY_PROMPT_HISTORY]
else:
display_data = data
@@ -51,10 +51,10 @@ def render_raw_editor(data, file_path):
# 2. If we were in Safe Mode, we must merge the hidden history back in
if hide_history:
if "history_tree" in data:
input_data["history_tree"] = data["history_tree"]
if "prompt_history" in data:
input_data["prompt_history"] = data["prompt_history"]
if KEY_HISTORY_TREE in data:
input_data[KEY_HISTORY_TREE] = data[KEY_HISTORY_TREE]
if KEY_PROMPT_HISTORY in data:
input_data[KEY_PROMPT_HISTORY] = data[KEY_PROMPT_HISTORY]
# 3. Save to Disk
save_json(file_path, input_data)