-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
usr/ data dir #818
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: development
Are you sure you want to change the base?
usr/ data dir #818
Changes from 2 commits
19fce0a
dc597b4
2facfbe
3fac135
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,28 +17,19 @@ | |
|
|
||
| # Handle memory directory | ||
| memory/** | ||
| !memory/**/ | ||
|
|
||
| # Handle logs directory | ||
| logs/* | ||
|
|
||
| # Handle tmp and usr directory | ||
| tmp/* | ||
| usr/* | ||
| usr/ | ||
|
|
||
| # Handle knowledge directory | ||
| knowledge/** | ||
| !knowledge/**/ | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's ignore knowledge/custom for safety. |
||
| # Explicitly allow the default folder in knowledge | ||
| !knowledge/default/ | ||
| !knowledge/default/** | ||
|
|
||
| # Handle instruments directory | ||
| instruments/** | ||
| !instruments/**/ | ||
| # Explicitly allow the default folder in instruments | ||
| !instruments/default/ | ||
| !instruments/default/** | ||
|
|
||
| # Global rule to include .gitkeep files anywhere | ||
| !**/.gitkeep | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -139,7 +139,7 @@ def initialize( | |
| log_item.stream(progress="\nInitializing VectorDB") | ||
|
|
||
| em_dir = files.get_abs_path( | ||
| "memory/embeddings" | ||
| "tmp/memory/embeddings" | ||
| ) # just caching, no need to parameterize | ||
| db_dir = abs_db_dir(memory_subdir) | ||
|
|
||
|
|
@@ -333,6 +333,16 @@ def _preload_knowledge_folders( | |
| recursive=True, | ||
| ) | ||
|
|
||
| # load custom instruments descriptions | ||
| index = knowledge_import.load_knowledge( | ||
| log_item, | ||
| files.get_abs_path("usr/instruments/custom"), | ||
|
||
| index, | ||
| {"area": Memory.Area.INSTRUMENTS.value}, | ||
| filename_pattern="**/*.md", | ||
| recursive=True, | ||
| ) | ||
|
|
||
| return index | ||
|
|
||
| def get_document_by_id(self, id: str) -> Document | None: | ||
|
|
@@ -483,7 +493,7 @@ def get_timestamp(): | |
| def get_custom_knowledge_subdir_abs(agent: Agent) -> str: | ||
| for dir in agent.config.knowledge_subdirs: | ||
| if dir != "default": | ||
| return files.get_abs_path("knowledge", dir) | ||
| return files.get_abs_path("usr/knowledge", dir) | ||
| raise Exception("No custom knowledge subdir set") | ||
|
|
||
|
|
||
|
|
@@ -499,7 +509,7 @@ def abs_db_dir(memory_subdir: str) -> str: | |
|
|
||
| return files.get_abs_path(get_project_meta_folder(memory_subdir[9:]), "memory") | ||
| # standard subdirs | ||
| return files.get_abs_path("memory", memory_subdir) | ||
| return files.get_abs_path("usr/memory", memory_subdir) | ||
|
|
||
|
|
||
| def abs_knowledge_dir(knowledge_subdir: str, *sub_dirs: str) -> str: | ||
|
|
@@ -511,7 +521,9 @@ def abs_knowledge_dir(knowledge_subdir: str, *sub_dirs: str) -> str: | |
| get_project_meta_folder(knowledge_subdir[9:]), "knowledge", *sub_dirs | ||
| ) | ||
| # standard subdirs | ||
| return files.get_abs_path("knowledge", knowledge_subdir, *sub_dirs) | ||
| if knowledge_subdir == "default": | ||
| return files.get_abs_path("knowledge", *sub_dirs) | ||
| return files.get_abs_path("usr/knowledge", knowledge_subdir, *sub_dirs) | ||
|
|
||
|
|
||
| def get_memory_subdir_abs(agent: Agent) -> str: | ||
|
|
@@ -546,7 +558,7 @@ def get_existing_memory_subdirs() -> list[str]: | |
| ) | ||
|
|
||
| # Get subdirectories from memory folder | ||
| subdirs = files.get_subdirectories("memory", exclude="embeddings") | ||
| subdirs = files.get_subdirectories("usr/memory", exclude="embeddings") | ||
|
||
|
|
||
| project_subdirs = files.get_subdirectories(get_projects_parent_folder()) | ||
| for project_subdir in project_subdirs: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| import os | ||
| from python.helpers import files | ||
| from python.helpers.print_style import PrintStyle | ||
|
|
||
| def migrate_user_data() -> None: | ||
| """ | ||
| Migrate user data from /tmp and other locations to /usr. | ||
| """ | ||
|
|
||
| PrintStyle().print("Checking for data migration...") | ||
|
|
||
| # --- Migrate Directories ------------------------------------------------------- | ||
| # Move directories from tmp/ or other source locations to usr/ | ||
|
|
||
| _move_dir("tmp/chats", "usr/chats") | ||
| _move_dir("tmp/scheduler", "usr/scheduler") | ||
| _move_dir("tmp/uploads", "usr/uploads") | ||
| _move_dir("tmp/upload", "usr/upload") | ||
| _move_dir("tmp/downloads", "usr/downloads") | ||
| _move_dir("tmp/email", "usr/email") | ||
| _move_dir("knowledge/custom", "usr/knowledge/custom") | ||
|
||
| _move_dir("instruments/custom", "usr/instruments/custom") | ||
|
||
|
|
||
| # --- Migrate Files ------------------------------------------------------------- | ||
| # Move specific configuration files to usr/ | ||
|
|
||
| _move_file("tmp/settings.json", "usr/settings.json") | ||
| _move_file("tmp/secrets.env", "usr/secrets.env") | ||
| _move_file("tmp/default.env", "usr/default.env") | ||
|
||
|
|
||
| # --- Special Migration Cases --------------------------------------------------- | ||
|
|
||
| # Migrate Memory | ||
| _migrate_memory() | ||
|
|
||
| # Flatten default directories (knowledge/default -> knowledge/, etc.) | ||
| # We use _merge_dir_contents because we want to move the *contents* of default/ | ||
| # into the parent directory, not move the default directory itself. | ||
| _merge_dir_contents("knowledge/default", "knowledge") | ||
| _merge_dir_contents("instruments/default", "instruments") | ||
|
|
||
| # --- Cleanup ------------------------------------------------------------------- | ||
|
|
||
| # Remove obsolete directories after migration | ||
| _cleanup_obsolete() | ||
|
|
||
| PrintStyle().print("Migration check complete.") | ||
|
|
||
| # --- Helper Functions ---------------------------------------------------------- | ||
|
|
||
| def _move_dir(src: str, dst: str) -> None: | ||
| """ | ||
| Move a directory from src to dst if src exists and dst does not. | ||
| """ | ||
| if files.exists(src) and not files.exists(dst): | ||
| PrintStyle().print(f"Migrating {src} to {dst}...") | ||
| files.move_dir(src, dst) | ||
|
|
||
| def _move_file(src: str, dst: str) -> None: | ||
| """ | ||
| Move a file from src to dst if src exists and dst does not. | ||
| """ | ||
| if files.exists(src) and not files.exists(dst): | ||
| PrintStyle().print(f"Migrating {src} to {dst}...") | ||
| files.move_file(src, dst) | ||
|
|
||
| def _migrate_memory(base_path: str = "memory") -> None: | ||
| """ | ||
| Migrate memory subdirectories. | ||
| """ | ||
| subdirs = files.get_subdirectories(base_path) | ||
| for subdir in subdirs: | ||
| if subdir == "embeddings": | ||
| # Special case: Embeddings | ||
| _move_dir("memory/embeddings", "tmp/memory/embeddings") | ||
| else: | ||
| # Move other memory items to usr/memory | ||
| dst = f"usr/memory/{subdir}" | ||
| _move_dir(f"memory/{subdir}", dst) | ||
|
|
||
| def _merge_dir_contents(src_parent: str, dst_parent: str) -> None: | ||
| """ | ||
| Moves all subdirectories from src_parent to dst_parent. | ||
| Useful for flattening structures like 'knowledge/default/*' -> 'knowledge/*'. | ||
| """ | ||
| if not files.exists(src_parent): | ||
| return | ||
|
|
||
| # Iterate over subdirectories in the source parent | ||
| subdirs = files.get_subdirectories(src_parent) | ||
| for subdir in subdirs: | ||
| src = f"{src_parent}/{subdir}" | ||
| dst = f"{dst_parent}/{subdir}" | ||
|
|
||
| # Move the subdirectory if it doesn't exist in destination | ||
| _move_dir(src, dst) | ||
|
|
||
| def _cleanup_obsolete() -> None: | ||
| """ | ||
| Remove directories that are no longer needed. | ||
| """ | ||
| to_remove = [ | ||
| "knowledge/default", | ||
| "instruments/default", | ||
| "memory" | ||
| ] | ||
| for path in to_remove: | ||
| if files.exists(path): | ||
| PrintStyle().print(f"Removing {path}...") | ||
| files.delete_dir(path) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's keep all of these original folders here for safety, we don't want our devs to accidentaly upload their memory or files...