summaryrefslogtreecommitdiff
path: root/src/agents/03-logs/vfs.py
diff options
context:
space:
mode:
authorCaptainJack2491 <jayrupnakawala@gmail.com>2025-11-16 20:18:23 +0000
committerCaptainJack2491 <jayrupnakawala@gmail.com>2025-11-16 20:18:23 +0000
commit66924c7d481032e999d12aa7bf1a803f8b7b4d4f (patch)
tree2c8001fcbdfd00e6785d363cfe98ebad13c14dfa /src/agents/03-logs/vfs.py
parent70557afb1e09fc99e9488b69322a76c50dc98554 (diff)
better structure. and works with groq too
Diffstat (limited to 'src/agents/03-logs/vfs.py')
-rw-r--r--src/agents/03-logs/vfs.py55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/agents/03-logs/vfs.py b/src/agents/03-logs/vfs.py
new file mode 100644
index 0000000..a521676
--- /dev/null
+++ b/src/agents/03-logs/vfs.py
@@ -0,0 +1,55 @@
+# vfs.py
+
+class VirtualFileSystem:
+ def __init__(self):
+ self.fs = {"/": {}}
+
+ def _get_path(self, path):
+ parts = path.strip("/").split("/")
+ node = self.fs["/"]
+ for part in parts:
+ if part == "":
+ continue
+ if part not in node:
+ return None
+ node = node[part]
+ return node
+
+ def list_files(self, path="."):
+ if path == ".":
+ path = "/"
+ node = self._get_path(path)
+ if node is None or not isinstance(node, dict):
+ return "Path not found or not a directory."
+ return list(node.keys())
+
+ def create_file(self, file_path, content):
+ parts = file_path.strip("/").split("/")
+ filename = parts.pop()
+ if not filename:
+ return "Invalid file path."
+
+ dir_path = "/" + "/".join(parts)
+ node = self._get_path(dir_path)
+
+ if node is None or not isinstance(node, dict):
+ # For simplicity, let's automatically create the directory if it doesn't exist.
+ node = self.fs["/"]
+ for part in parts:
+ if part == "":
+ continue
+ if part not in node:
+ node[part] = {}
+ node = node[part]
+
+ node[filename] = content
+ return f"File '{file_path}' created successfully."
+
+ def read_file(self, file_path):
+ node = self._get_path(file_path)
+ if node is None or isinstance(node, dict):
+ return "File not found or is a directory."
+ return node
+
+# For a single, shared instance of the VFS
+vfs_instance = VirtualFileSystem()