From 64e375e96043e89f6a37d25fd7497e507db7c432 Mon Sep 17 00:00:00 2001 From: Farouk Adeleke Date: Sat, 31 Jan 2026 12:24:18 -0800 Subject: [PATCH] Fix config override bug by recreating LMs after load_state --- nanocode.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/nanocode.py b/nanocode.py index f735c70..e35fed0 100644 --- a/nanocode.py +++ b/nanocode.py @@ -53,13 +53,23 @@ def write_file(path: str, content: str) -> str: content: Content to write to the file Returns: - 'ok' on success + Status message with file stats """ - print(f"{MAGENTA}⏺ Creating file: {path}{RESET}") + is_new = not os.path.exists(path) + action = "Creating" if is_new else "Overwriting" + + # Auto-create parent directories + parent = os.path.dirname(path) + if parent: + os.makedirs(parent, exist_ok=True) with open(path, "w") as f: f.write(content) - return "ok" + + lines = content.count("\n") + (1 if content and not content.endswith("\n") else 0) + tokens = len(content) // 4 + print(f"{MAGENTA}⏺ {action} file: {path} ({lines} lines, ~{tokens:,} tokens){RESET}") + return f"ok: wrote {lines} lines ({tokens:,} tokens) to {path}" def edit_file(path: str, old: str, new: str, replace_all: bool = False) -> str: