MCPcopy Create free account
hub / github.com/Ishabdullah/Codey-v2 / load_file

Method load_file

core/memory_v2.py:453–476  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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."""

Callers 10

handle_commandFunction · 0.80
replFunction · 0.80
load_fileFunction · 0.80
run_agentFunction · 0.80
setUpMethod · 0.80
setUpMethod · 0.80

Calls 3

estimate_tokensFunction · 0.90
existsMethod · 0.80
addMethod · 0.45

Tested by 6

setUpMethod · 0.64
setUpMethod · 0.64