Append *content* to edit history for *doc_path*, capped at _MAX_HISTORY_PER_FILE.
(session: SessionState, doc_path: Path, content: str)
| 55 | |
| 56 | |
| 57 | def _save_history(session: SessionState, doc_path: Path, content: str) -> None: |
| 58 | """Append *content* to edit history for *doc_path*, capped at _MAX_HISTORY_PER_FILE.""" |
| 59 | history = session.registry.get("file_history") |
| 60 | if history is None: |
| 61 | history = {} |
| 62 | elif isinstance(history, str): |
| 63 | history = json.loads(history) |
| 64 | key = str(doc_path) |
| 65 | entry = history.setdefault(key, []) |
| 66 | entry.append(content) |
| 67 | # Trim to last N entries |
| 68 | if len(entry) > _MAX_HISTORY_PER_FILE: |
| 69 | del entry[: len(entry) - _MAX_HISTORY_PER_FILE] |
| 70 | session.registry["file_history"] = history # keep as native dict |
| 71 | |
| 72 | |
| 73 | async def handle_write_doc_file( |
no test coverage detected