Add clear command functionality to message handler

- Implemented handling of the `/clear` command to clear specific branches or entire trees based on message replies.
- Added tests for various scenarios of the clear command, including clearing branches, handling unknown replies, and clearing entire trees.
- Enhanced `TreeQueueManager` with methods to cancel branches and remove subtrees, ensuring proper state management in the session store.
- Updated `SessionStore` and `TreeRepository` to support removal of node mappings and trees, improving data integrity during clear operations.
This commit is contained in:
Alishahryar1
2026-02-16 16:23:26 -08:00
parent e4ae59511e
commit 6abcdb4017
8 changed files with 537 additions and 49 deletions
+16
View File
@@ -288,6 +288,22 @@ class SessionStore:
self._node_to_tree[node_id] = root_id
self._schedule_save()
def remove_node_mappings(self, node_ids: List[str]) -> None:
"""Remove node IDs from the node-to-tree mapping."""
with self._lock:
for nid in node_ids:
self._node_to_tree.pop(nid, None)
self._schedule_save()
def remove_tree(self, root_id: str) -> None:
"""Remove a tree and all its node mappings from the store."""
with self._lock:
tree_data = self._trees.pop(root_id, None)
if tree_data:
for node_id in tree_data.get("nodes", {}).keys():
self._node_to_tree.pop(node_id, None)
self._schedule_save()
def get_all_trees(self) -> Dict[str, dict]:
"""Get all stored trees (public accessor)."""
with self._lock: