42 lines
1.3 KiB
Python
42 lines
1.3 KiB
Python
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() |