| 99 | return loaded |
| 100 | |
| 101 | def load_directory(path, extensions=None, max_files=10): |
| 102 | default_exts = {".py",".js",".ts",".sh",".md",".json", |
| 103 | ".yaml",".yml",".toml",".txt",".html",".css", |
| 104 | ".c",".cpp",".h",".rs",".go"} |
| 105 | exts = set(extensions) if extensions else default_exts |
| 106 | p = Path(path).expanduser() |
| 107 | if not p.is_dir(): |
| 108 | warning(f"Not a directory: {path}") |
| 109 | return [] |
| 110 | files = sorted([ |
| 111 | f for f in p.rglob("*") |
| 112 | if f.is_file() |
| 113 | and f.suffix in exts |
| 114 | and not is_ignored(f) |
| 115 | ])[:max_files] |
| 116 | loaded = [] |
| 117 | for f in files: |
| 118 | r = load_file(str(f)) |
| 119 | if not r.startswith("[ERROR]"): |
| 120 | loaded.append(str(f)) |
| 121 | if loaded: |
| 122 | info(f"Loaded {len(loaded)} files from {path}") |
| 123 | return loaded |
| 124 | |
| 125 | def unload_file(path): |
| 126 | p = Path(path).expanduser().resolve() |