Load a file into working memory. Reads from disk if content is not provided. Also stores in long-term memory (embeddings) if available.
(self, path: str, content: str = None)
| 451 | # ── MemoryManager-compatible file API ──────────────────────────────────── |
| 452 | |
| 453 | def load_file(self, path: str, content: str = None) -> bool: |
| 454 | """ |
| 455 | Load a file into working memory. |
| 456 | Reads from disk if content is not provided. |
| 457 | Also stores in long-term memory (embeddings) if available. |
| 458 | """ |
| 459 | p = Path(path).expanduser() |
| 460 | if content is None: |
| 461 | if not p.exists(): |
| 462 | p = Path(os.getcwd()) / path |
| 463 | if not p.exists(): |
| 464 | return False |
| 465 | try: |
| 466 | content = p.read_text(encoding='utf-8', errors='replace') |
| 467 | except Exception: |
| 468 | return False |
| 469 | key = str(p.resolve()) |
| 470 | tokens = estimate_tokens(content, key) |
| 471 | self.working.add(key, content, tokens) |
| 472 | # Long-term indexing deferred — store_file chunks the content and |
| 473 | # calls the embedding server, which is too heavy during a file write |
| 474 | # (causes OOM on memory-constrained devices). Long-term indexing |
| 475 | # happens lazily on read_file or via /index command instead. |
| 476 | return True |
| 477 | |
| 478 | def unload_file(self, path: str): |
| 479 | """Remove a file from working memory.""" |