Fix config override bug by recreating LMs after load_state
This commit is contained in:
16
nanocode.py
16
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:
|
||||
|
||||
Reference in New Issue
Block a user