From 2afcf843dd2faf357e547e660426566f3bae0d55 Mon Sep 17 00:00:00 2001 From: 7000pctAUTO Date: Fri, 30 Jan 2026 11:56:13 +0000 Subject: [PATCH] Initial commit: Add shell-memory-cli project A CLI tool that learns from terminal command patterns to automate repetitive workflows. Features: - Command recording with tags and descriptions - Pattern detection for command sequences - Session recording and replay - Natural language script generation --- shell_memory/commands.py | 49 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 shell_memory/commands.py diff --git a/shell_memory/commands.py b/shell_memory/commands.py new file mode 100644 index 0000000..314d671 --- /dev/null +++ b/shell_memory/commands.py @@ -0,0 +1,49 @@ +"""Command recording and library management.""" + +from typing import List, Optional +from datetime import datetime + +from .models import Command +from .database import Database + + +class CommandLibrary: + """Manages the personal command library.""" + + def __init__(self, db: Database): + self.db = db + + def add(self, command: str, description: str = "", tags: Optional[List[str]] = None) -> Optional[int]: + cmd = Command( + command=command, + description=description, + tags=tags or [], + created_at=datetime.now(), + ) + return self.db.add_command(cmd) + + def list(self, limit: int = 50) -> List[Command]: + commands = self.db.get_all_commands() + return commands[:limit] + + def search(self, query: str, limit: int = 10) -> List[Command]: + return self.db.search_commands(query, limit) + + def get(self, command_id: int) -> Optional[Command]: + return self.db.get_command(command_id) + + def delete(self, command_id: int) -> bool: + return self.db.delete_command(command_id) + + def increment_usage(self, command_id: int): + self.db.update_command_usage(command_id) + + def find_similar(self, command: str, threshold: int = 60) -> List[tuple]: + from fuzzywuzzy import fuzz + all_commands = self.db.get_all_commands() + similar = [] + for cmd in all_commands: + ratio = fuzz.ratio(command.lower(), cmd.command.lower()) + if ratio >= threshold: + similar.append((cmd, ratio)) + return sorted(similar, key=lambda x: x[1], reverse=True) \ No newline at end of file