start implementation on new architecture

This commit is contained in:
2024-11-01 09:56:30 +01:00
parent ee089e5be7
commit 2c1e134c6e
43 changed files with 2978 additions and 619 deletions

42
sia/delete_command.py Normal file
View File

@@ -0,0 +1,42 @@
from .command import Command
from .command_result import CommandResult
from .working_memory import WorkingMemory
class DeleteCommand(Command):
"""
Command to delete an entry from working memory.
Ensures proper cleanup of entry resources before removal.
Attributes:
id: Unique identifier of entry to delete
"""
def __init__(self, id: str):
"""
Initialize delete command.
Args:
id: Unique identifier of entry to delete
"""
self.id = id
def execute(self, memory: WorkingMemory) -> CommandResult:
"""
Delete the specified entry from working memory.
Performs cleanup on the entry before removal.
Args:
memory: WorkingMemory instance to delete entry from
Returns:
CommandResult: Success if entry was found and deleted,
failure with message if entry not found
"""
entry = memory.get_entry(self.id)
if entry is None:
return CommandResult.failure(f"Entry with id '{self.id}' not found")
# Perform cleanup before removing
entry.cleanup()
memory.remove_entry(self.id)
return CommandResult.success()